From 17a4734dc4d28ef070dfa227b422ed84794f48c5 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 11 Apr 2010 19:06:42 +0300 Subject: [PATCH] Optimize post-WPS scan based on channel used during provisioning Scan only the frequency that was used during provisioning during the first five scans for the connection. This speeds up connection in the most likely case where the AP remains on the same channel. If the AP is not found after these initial scans, all channels will be scanned. --- wpa_supplicant/scan.c | 13 +++++++++++++ wpa_supplicant/wpa_supplicant.c | 1 + wpa_supplicant/wpa_supplicant_i.h | 3 +++ wpa_supplicant/wps_supplicant.c | 2 ++ 4 files changed, 19 insertions(+) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index e2d95b3d1..1a9eba690 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -386,6 +386,19 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) } #ifdef CONFIG_WPS + if (params.freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) { + /* + * Optimize post-provisioning scan based on channel used + * during provisioning. + */ + wpa_printf(MSG_DEBUG, "WPS: Scan only frequency %u MHz that " + "was used during provisioning", wpa_s->wps_freq); + params.freqs = os_zalloc(2 * sizeof(int)); + if (params.freqs) + params.freqs[0] = wpa_s->wps_freq; + wpa_s->after_wps--; + } + if (wps) { wps_ie = wps_build_probe_req_ie(wps == 2, &wpa_s->wps->dev, wpa_s->wps->uuid, req_type); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 0eba4a0b7..15ca6dbda 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -542,6 +542,7 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_s->new_connection = 0; wpa_s->reassociated_connection = 1; wpa_drv_set_operstate(wpa_s, 1); + wpa_s->after_wps = 0; } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING || state == WPA_ASSOCIATED) { wpa_s->new_connection = 1; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index ba5345129..84d642cf6 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -425,6 +425,9 @@ struct wpa_supplicant { struct wpa_ssid *bgscan_ssid; const struct bgscan_ops *bgscan; void *bgscan_priv; + + int after_wps; + unsigned int wps_freq; }; diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index fa0123aeb..ba94d330b 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -72,6 +72,8 @@ int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s) "try to associate with the received credential"); wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); + wpa_s->after_wps = 5; + wpa_s->wps_freq = wpa_s->assoc_freq; wpa_s->reassociate = 1; wpa_supplicant_req_scan(wpa_s, 0, 0); return 1;