[RFC 3/3] scan: Properly cancel scans.

greearb at candelatech.com greearb
Mon May 12 22:27:52 PDT 2014


From: Ben Greear <greearb at candelatech.com>

You need to remove work items as well as cancel events.
Also, reorder some freq selection logic.

Signed-off-by: Ben Greear <greearb at candelatech.com>
---
 wpa_supplicant/events.c |   21 ++++++------------
 wpa_supplicant/scan.c   |   51 +++++++++++++++++++++++++++++++++-------------
 wpa_supplicant/scan.h   |    1 +
 3 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 4f95acc..4181058 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1114,7 +1114,7 @@ int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
 
 		if (num_assoc_reqs >= wpa_s->conf->max_assoc_per_scan) {
 			wpa_dbg(wpa_s, MSG_DEBUG,
-				"Deferring association attempt, reqs: %i, max: %i",
+				"Deferring association attempt, reqs: %i, max: %i (connect)",
 				num_assoc_reqs, wpa_s->conf->max_assoc_per_scan);
 			return 0;
 		}
@@ -1363,16 +1363,17 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 	 */
 	if (wpa_s->conf->min_scan_gap &&
 	    eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL)) {
-		/* Min gap will be applied as needed */
-		wpa_dbg(wpa_s, MSG_DEBUG, "Re-requesting scan to apply min-gap/scan-on-freq");
 		/* To temporarily work around ath10k bug, only cancel existing
 		 * if we are configured to allow concurrent associations.
 		 */
 		if (wpa_s->conf->concurrent_assoc_ok) {
+			/* Min gap will be applied as needed */
+			wpa_dbg(wpa_s, MSG_DEBUG, "Re-requesting scan to apply min-gap/scan-on-freq");
+
 			/* Cancel any existing scan request */
 			wpa_supplicant_cancel_scan(wpa_s);
+			wpa_supplicant_req_scan(wpa_s, 1, 0);
 		}
-		wpa_supplicant_req_scan(wpa_s, 1, 0);
 	}
 
 	if (!wpa_s->own_scan_running && wpa_s->external_scan_running) {
@@ -1403,21 +1404,13 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 
 	wpa_scan_results_free(scan_res);
 
-	if (wpa_s->scan_work) {
-		struct wpa_radio_work *work = wpa_s->scan_work;
-		wpa_s->scan_work = NULL;
-		radio_work_done(work);
-	}
+	wpa_remove_scan_work(wpa_s, "scan-results");
 
 	return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
 
 scan_work_done:
 	wpa_scan_results_free(scan_res);
-	if (wpa_s->scan_work) {
-		struct wpa_radio_work *work = wpa_s->scan_work;
-		wpa_s->scan_work = NULL;
-		radio_work_done(work);
-	}
+	wpa_remove_scan_work(wpa_s, "scan-rsults-done");
 	return ret;
 }
 
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index ec0d991..59aa074 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -154,6 +154,8 @@ static void wpas_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
 		}
 		wpa_supplicant_notify_scanning(wpa_s, 0);
 		wpas_notify_scan_done(wpa_s, 0);
+                wpa_dbg(wpa_s, MSG_DEBUG, "trigger-scan-cb, deinit, work: %p",
+                        wpa_s->scan_work);
 		wpa_s->scan_work = NULL;
 		return;
 	}
@@ -178,6 +180,8 @@ static void wpas_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
 	wpa_s->own_scan_requested = 1;
 	wpa_s->clear_driver_scan_cache = 0;
 	wpa_s->scan_work = work;
+        wpa_dbg(wpa_s, MSG_DEBUG, "trigger-scan-cb, assign work: %p",
+                wpa_s->scan_work);
 }
 
 
@@ -197,6 +201,8 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
 		return -1;
 	}
 
+        wpa_dbg(wpa_s, MSG_DEBUG, "trigger-scan, freqs: %p  can-scan-one: %i",
+                params->freqs, params->can_scan_one);
 	ctx = wpa_scan_clone_params(params);
 	if (ctx == NULL)
 		return -1;
@@ -210,6 +216,16 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
 	return 0;
 }
 
+void wpa_remove_scan_work(struct wpa_supplicant *wpa_s, const char* dbg)
+{
+	if (wpa_s->scan_work) {
+		struct wpa_radio_work *work = wpa_s->scan_work;
+                wpa_dbg(wpa_s, MSG_DEBUG, "Remove scan work, work: %p dbg: %s",
+                        work, dbg);
+		wpa_s->scan_work = NULL;
+		radio_work_done(work);
+	}
+}
 
 static void
 wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx)
@@ -539,12 +555,16 @@ static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s,
 		return; /* unknown what channels the driver supports */
 	if (params->freqs)
 		return; /* already using a limited channel set */
-	if (wpa_s->setband == WPA_SETBAND_5G)
+	if (wpa_s->setband == WPA_SETBAND_5G) {
+		wpa_dbg(wpa_s, MSG_DEBUG, "Scan only 5G channels.");
 		wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A,
 					    params);
-	else if (wpa_s->setband == WPA_SETBAND_2G)
+        }
+	else if (wpa_s->setband == WPA_SETBAND_2G) {
+		wpa_dbg(wpa_s, MSG_DEBUG, "Scan only 2G channels.");
 		wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G,
 					    params);
+        }
 }
 
 
@@ -836,14 +856,6 @@ ssid_list_set:
 	} else
 		os_free(wpa_s->next_scan_freqs);
 	wpa_s->next_scan_freqs = NULL;
-	wpa_setband_scan_freqs(wpa_s, &params);
-
-	/* See if user specified frequencies. If so, scan only those. */
-	if (wpa_s->conf->freq_list && !params.freqs) {
-		wpa_dbg(wpa_s, MSG_DEBUG,
-			"Optimize scan based on conf->freq_list");
-		int_array_concat(&params.freqs, wpa_s->conf->freq_list);
-	}
 
 	/* Use current associated channel? */
 	if (wpa_s->conf->scan_cur_freq && !params.freqs) {
@@ -863,6 +875,15 @@ ssid_list_set:
 		}
 	}
 
+	/* See if user specified frequencies. If so, scan only those. */
+	if (wpa_s->conf->freq_list && !params.freqs) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"Optimize scan based on conf->freq_list");
+		int_array_concat(&params.freqs, wpa_s->conf->freq_list);
+	}
+
+	wpa_setband_scan_freqs(wpa_s, &params);
+
 	params.filter_ssids = wpa_supplicant_build_filter_ssids(
 		wpa_s->conf, &params.num_filter_ssids);
 	if (extra_ie) {
@@ -1282,6 +1303,9 @@ void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s)
 {
 	wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request");
 	eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL);
+
+        radio_remove_works(wpa_s, "scan", 0);
+	wpa_remove_scan_work(wpa_s, "cancel-scan");
 }
 
 
@@ -1811,11 +1835,8 @@ void scan_only_handler(struct wpa_supplicant *wpa_s,
 	}
 	wpas_notify_scan_results(wpa_s);
 	wpas_notify_scan_done(wpa_s, 1);
-	if (wpa_s->scan_work) {
-		struct wpa_radio_work *work = wpa_s->scan_work;
-		wpa_s->scan_work = NULL;
-		radio_work_done(work);
-	}
+
+	wpa_remove_scan_work(wpa_s, "scan-only-handler");
 }
 
 
diff --git a/wpa_supplicant/scan.h b/wpa_supplicant/scan.h
index 4fe10e8..e1ce429 100644
--- a/wpa_supplicant/scan.h
+++ b/wpa_supplicant/scan.h
@@ -49,6 +49,7 @@ wpa_scan_clone_params(const struct wpa_driver_scan_params *src);
 void wpa_scan_free_params(struct wpa_driver_scan_params *params);
 int wpas_start_pno(struct wpa_supplicant *wpa_s);
 int wpas_stop_pno(struct wpa_supplicant *wpa_s);
+void wpa_remove_scan_work(struct wpa_supplicant *wpa_s, const char* dbg);
 
 void int_array_concat(int **res, const int *a);
 
-- 
1.7.3.4




More information about the Hostap mailing list