[PATCH v2] Fix scan retry after a failure

Kalle Valo kalle.valo at canonical.com
Fri Oct 15 07:14:47 EDT 2010


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 85dcfb2..c071d3a 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -700,11 +700,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;
@@ -891,8 +892,14 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 	if (scan_res == NULL) {
 		if (wpa_s->conf->ap_scan == 2 || ap)
 			return;
+
+		if (wpa_s->scan_runs != 1)
+			/* only try rescan on first attempt */
+			return;
+
 		wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
 			   "scanning again");
+		wpa_s->scan_req = 1;
 		wpa_supplicant_req_new_scan(wpa_s, 1, 0);
 		return;
 	}



More information about the HostAP mailing list