From 1e7fb4f1b7cdf16705cfcc1fd171807a9f8e3a56 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 31 Dec 2011 13:17:20 +0200 Subject: [PATCH] WPS: Use single channel scan if AP channel already known If the BSSID of the AP is specified in the WPS command, the target AP is likely already in the BSS table and its operating channel is known. Use this information to speed up connection by only scanning the known channel. Signed-hostap: Jouni Malinen --- wpa_supplicant/scan.c | 10 ++++++++++ wpa_supplicant/wpa_supplicant_i.h | 1 + wpa_supplicant/wps_supplicant.c | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 4abc9dada..16f2bbf05 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -344,6 +344,16 @@ static void wpa_supplicant_optimize_freqs( wpa_s->after_wps--; } + if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq) + { + /* Optimize provisioning scan based on already known channel */ + wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz", + wpa_s->wps_freq); + params->freqs = os_zalloc(2 * sizeof(int)); + if (params->freqs) + params->freqs[0] = wpa_s->wps_freq; + wpa_s->known_wps_freq = 0; /* only do this once */ + } #endif /* CONFIG_WPS */ } diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 5469129f3..3e3b23de2 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -495,6 +495,7 @@ struct wpa_supplicant { struct wpa_ssid *connect_without_scan; int after_wps; + int known_wps_freq; unsigned int wps_freq; int wps_fragment_size; int auto_reconnect_disabled; diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index 870aff5b8..fcf6c3d02 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -790,9 +790,19 @@ static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s, static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s, - struct wpa_ssid *selected) + struct wpa_ssid *selected, const u8 *bssid) { struct wpa_ssid *ssid; + struct wpa_bss *bss; + + wpa_s->known_wps_freq = 0; + if (bssid) { + bss = wpa_bss_get_bssid(wpa_s, bssid); + if (bss && bss->freq > 0) { + wpa_s->known_wps_freq = 1; + wpa_s->wps_freq = bss->freq; + } + } if (wpa_s->current_ssid) wpa_supplicant_deauthenticate( @@ -853,7 +863,7 @@ int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, ssid->eap.fragment_size = wpa_s->wps_fragment_size; eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, wpa_s, NULL); - wpas_wps_reassoc(wpa_s, ssid); + wpas_wps_reassoc(wpa_s, ssid, bssid); return 0; } @@ -896,7 +906,7 @@ int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, ssid->eap.fragment_size = wpa_s->wps_fragment_size; eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, wpa_s, NULL); - wpas_wps_reassoc(wpa_s, ssid); + wpas_wps_reassoc(wpa_s, ssid, bssid); return rpin; } @@ -1016,7 +1026,7 @@ int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid, ssid->eap.fragment_size = wpa_s->wps_fragment_size; eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, wpa_s, NULL); - wpas_wps_reassoc(wpa_s, ssid); + wpas_wps_reassoc(wpa_s, ssid, bssid); return 0; }