hostapd: Fix crash when scan fails

When scan failed, the wpa_driver_nl80211_scan method tried
to recursively call itself, but it passed in the wrong argument
for the void*, and so then it crashed accessing bad memory.

With this fix, hostapd still will not retry the scan later, but
at least it will exit cleanly and won't polute the file system
with core files.

Signed-off-by: Ben Greear <greearb@candelatech.com>
nl80211: Do not use void pointer for driver_ops used internally

This allows some more pointer type validation at compile time.

Signed-hostap: Jouni Malinen <j@w1.fi>
Fix compilation with PMKSA caching support disabled

Commit 6aaac006af7fd39d618c6546939bed9f0f0cea37 modified the
pmksa_cache_init() prototype, but forgot to update the empty wrapper
function which is used when PMKSA caching is not included in the build.

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop_none: Fix compilation

eloop.h API had been changed without updating eloop_none.c to match.

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop_none: Use struct dl_list for timeouts

This merges commit eaa3f04b97f7bf3ffb91fe0acb2bb6bcb8f566fe changes from
eloop.c into eloop_none.c.

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop_none: Update sample to be closer to the current eloop.c

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop_win: Use struct dl_list for timeouts

This merges commit eaa3f04b97f7bf3ffb91fe0acb2bb6bcb8f566fe changes from
eloop.c into eloop_win.c.

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop_win: Update to be closer to the current eloop.c

Some fixes had were made only in eloop.c.

Signed-hostap: Jouni Malinen <j@w1.fi>
eloop: Add a timer cancel that returns the remaining time

This new cancel timer will give back the remaining time if it was
pending.

Signed-hostap: Pontus Fuchs <pontus.fuchs@gmail.com>
Update scan interval gracefully

When the scan interval is changed the new interval is effective
after the old interval timer fires off one last time. This can cause
an unacceptable long delay when updating the interval.

Change this behaviour to use MIN(left of old interval, new interval)
for the scan interval following the interval change.

Signed-hostap: Pontus Fuchs <pontus.fuchs@gmail.com>
wpa_supplicant: Implement fast-associate on SelectNetwork

If scan results are available when we perform a SelectNetwork, use
them to make an associate decision.  This can save an entire scan
interval-worth of time in situations where something external to
wpa_supplicant (like a connection manager) has just previously
requested a scan before calling SelectNetwork.

Signed-hostap: Paul Stewart <pstew@chromium.org>
Make wpas_select_network_from_last_scan() static

Addition of wpa_supplicant_fast_associate() made it unnecessary to call
wpas_select_network_from_last_scan() directly from other files.

Signed-hostap: Jouni Malinen <j@w1.fi>
Add driver for OpenBSD net80211 layer

Very basic support for OpenBSD.  No support for scanning yet, so this needs
ap_scan=0 and expects that the user has configured the interface manually
using ifconfig(8).

Signed-hostap: Mark Kettenis <kettenis@openbsd.org>
wpa_supplicant: Fix access to the freed memory when removing all networks

Commit 59ff6653aad1c228cb2e9ccfe02b9dd4e6fc7901 fixed this issue for
'removing a network', and we also need to take care of 'removing all
networks'.

Signed-hostap: Jaewan Kim <jaewan at google.com>
P2P: Fix Action frame processing if Interworking is enabled

GAS server used the same public_action_cb mechanism as P2P to process
Action frames. This ended up overriding P2P processing of Action frames
while running an AP/GO interface with a build that enables Interworking
(e.g., for Hotspot 2.0) and a driver that uses hostapd for AP mode
SME/MLME. Fix this by adding a separate callback registration for the
GAS server. This should really be cleaned up by supporting arbitrary
number of callback handlers, but for now, this addresses the regression
with a minimal change.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
P2P: Fix P2P-GROUP-STARTED event for p2p_connect-join

Commit 50178335bff450829729c91c8af798a1d3a7b408 introduced a regression
for P2P-GROUP-STARTED event indication during p2p_connect-join when
using a separate P2P group interface. wpa_s->global->p2p_group_formation
was already set in that case to point to the group interface and this
commit changed this to point to incorrect interface. Fix this by setting
p2p_group_formation here only in case a separate group interface is not
used.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
TDLS: Use existing peer entry if available when processing discovery

Peer entries were getting added on every discover request from the peer,
thus resulting in multiple entries with the same MAC address. Ensures
that a check is done for the presence of the peer entry and reuse the
existing entry instead of adding a new one.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
TDLS: Move existing-entry check into wpa_tdls_add_peer()

There is no need to have this check copied to each caller since this
needs to be done for every case when a new peer is being added.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
TDLS: Remove link, if any, on an implicit set up request

If an implicit TDLS set up request is obtained on an existing link or an
to be established link, the previous link was not removed. This commit
disables the existing link on a new set up request. Also,
wpa_tdls_reneg() function was invoking wpa_tdls_start() on an already
existing peer for the case of internal setup, which is incorrect. Thus
the invocation of wpa_tdls_start() is removed in wpa_tdls_reneg() and
also this function is renamed to wps_tdls_remove() as it does not
renegotiation rather shall remove the link (if any) for the case of
external setup.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
TDLS: Fix MIC calculation for teardown frame to depend on reason code

The reason code used for calculating the MIC should correspond to the
reason code with which the teardown frame is sent, as the receiver shall
use the one obtained in the frame for validating the MIC.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>