[PATCHv2] wpa_supplicant: Implement fast-associate on SelectNetwork

Paul Stewart pstew
Tue Jan 15 18:28:09 PST 2013


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 at chromium.org>
---
 wpa_supplicant/events.c           |   43 +++++++++++++++++++++++++++++++++++++
 wpa_supplicant/wpa_supplicant.c   |    4 ++-
 wpa_supplicant/wpa_supplicant_i.h |    2 +
 3 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 983f670..0dd2d4d 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1308,6 +1308,49 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_NO_SCAN_PROCESSING */
 
 
+int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s,
+				  struct wpa_ssid *ssid)
+{
+#ifdef CONFIG_NO_SCAN_PROCESSING
+	return -1;
+#else /* CONFIG_NO_SCAN_PROCESSING */
+	struct wpa_bss *selected_bss;
+	struct wpa_ssid *selected_ssid = NULL;
+	struct os_time now;
+
+	if (wpa_s->last_scan_res_used <= 0) {
+		return -1;
+	}
+
+	os_get_time(&now);
+	if (now.sec - wpa_s->last_scan.sec <= 5) {
+		wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
+		return -1;
+	}
+
+	selected_bss = wpa_supplicant_pick_network(wpa_s, &selected_ssid);
+
+	if (!selected_bss) {
+		wpa_dbg(wpa_s, MSG_DEBUG, "Fast associate: no suitable bss");
+		return -1;
+	}
+
+	if (selected_ssid != ssid) {
+		wpa_dbg(wpa_s, MSG_DEBUG, "Fast associate: ssid mismatch?!");
+		return -1;
+	}
+
+	if (wpa_supplicant_connect(wpa_s, selected_bss, ssid) < 0) {
+		wpa_dbg(wpa_s, MSG_DEBUG, "Fast associate: Connect failed");
+		return -1;
+	}
+
+	wpa_dbg(wpa_s, MSG_DEBUG, "Fast associate: Successful connect!");
+
+	return 0;
+#endif /* CONFIG_NO_SCAN_PROCESSING */
+}
+
 #ifdef CONFIG_WNM
 
 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 64f5c1b..cf086ab 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -1875,7 +1875,9 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
 	wpa_s->connect_without_scan = NULL;
 	wpa_s->disconnected = 0;
 	wpa_s->reassociate = 1;
-	wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
+
+	if (!ssid || wpa_supplicant_fast_associate(wpa_s, ssid) != 0)
+		wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
 
 	if (ssid)
 		wpas_notify_network_selected(wpa_s, ssid);
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index ecbdedf..6b4e832 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -786,6 +786,8 @@ void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx);
 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx);
 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s);
 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s);
+int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s,
+				  struct wpa_ssid *ssid);
 
 /* eap_register.c */
 int eap_register_methods(void);
-- 
1.7.7.3




More information about the Hostap mailing list