[PATCH v3] Fix scan retry after a failure

Kalle Valo kalle.valo at canonical.com
Thu Feb 17 05:47:48 EST 2011


With broadcom's "wl" driver the first scan always fails. (Apparently it also
doesn't send scan results ready signals, but let's forget it for now.) With
connman's five minute scan interval it meant that it would take five minutes
from boot until a wireless connection was established.

The reason is that currently wpasupplicant doesn't handle scan retries
and it goes directly to INACTIVE state:

14:23:09 wpa_supplicant[1046]: Scan timeout - try to get results
14:23:09 wpa_supplicant[1046]: Failed to get scan results
14:23:09 wpa_supplicant[1046]: Failed to get scan results - try scanning again
14:23:09 wpa_supplicant[1046]: State: SCANNING -> INACTIVE

Instead of going to INACTIVE set wpa_s->scan_req to make it explicit
that this is a requested scan and fix check in wpa_supplicant_req_new_scan().

This is based on Michael Terry's patch for wpasupplicant 0.6.x reported here:

http://w1.fi/bugz/show_bug.cgi?id=374
---
 wpa_supplicant/events.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 3cb6387..369e178 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -661,11 +661,12 @@ wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
 					int timeout_sec, int timeout_usec)
 {
-	if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
+	if (!wpa_supplicant_enabled_networks(wpa_s->conf) &&
+	    !wpa_s->scan_req) {
 		/*
-		 * No networks are enabled; short-circuit request so
-		 * we don't wait timeout seconds before transitioning
-		 * to INACTIVE state.
+		 * No networks are enabled nor explicit scan requests are
+		 * made; short-circuit request so we don't wait timeout
+		 * seconds before transitioning to INACTIVE state.
 		 */
 		wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
 		return;
@@ -859,8 +860,14 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 	if (scan_res == NULL) {
 		if (wpa_s->conf->ap_scan == 2 || ap)
 			return -1;
+
 		wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
 			"scanning again");
+
+		if (wpa_s->scan_runs == 1)
+			/* try rescan only on the first attempt */
+			wpa_s->scan_req = 1;
+
 		wpa_supplicant_req_new_scan(wpa_s, 1, 0);
 		return -1;
 	}



More information about the HostAP mailing list