From b3aa456b3e8f77ad495283e955855301b4695dd3 Mon Sep 17 00:00:00 2001 From: Eyal Shapira Date: Sun, 29 Jan 2012 17:39:08 +0200 Subject: [PATCH] Interleave wildcard and specific SSID scans when max_ssids=1 For drivers limited to scan a single SSID at a time, this prevents waiting too long for a wildcard scan in case there are several scan_ssid networks in the configuration. Signed-hostap: Eyal Shapira --- wpa_supplicant/scan.c | 34 +++++++++++++++++++++++-------- wpa_supplicant/wpa_supplicant.c | 2 ++ wpa_supplicant/wpa_supplicant_i.h | 3 +++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 513589208..cceee616f 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -530,6 +530,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) if (scan_req != 2 && wpa_s->conf->ap_scan == 2) { wpa_s->connect_without_scan = NULL; + wpa_s->prev_scan_wildcard = 0; wpa_supplicant_assoc_try(wpa_s, ssid); return; } else if (wpa_s->conf->ap_scan == 2) { @@ -578,15 +579,32 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) int_array_sort_unique(params.freqs); } - if (ssid) { - wpa_s->prev_scan_ssid = ssid; - if (max_ssids > 1) { - wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in " - "the scan request"); - params.num_ssids++; + if (ssid && max_ssids == 1) { + /* + * If the driver is limited to 1 SSID at a time interleave + * wildcard SSID scans with specific SSID scans to avoid + * waiting a long time for a wildcard scan. + */ + if (!wpa_s->prev_scan_wildcard) { + params.ssids[0].ssid = NULL; + params.ssids[0].ssid_len = 0; + wpa_s->prev_scan_wildcard = 1; + wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for " + "wildcard SSID (Interleave with specific)"); + } else { + wpa_s->prev_scan_ssid = ssid; + wpa_s->prev_scan_wildcard = 0; + wpa_dbg(wpa_s, MSG_DEBUG, + "Starting AP scan for specific SSID: %s", + wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); } - wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for specific " - "SSID(s)"); + } else if (ssid) { + /* max_ssids > 1 */ + + wpa_s->prev_scan_ssid = ssid; + wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in " + "the scan request"); + params.num_ssids++; } else { wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; params.num_ssids++; diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index e79011ff3..90363fed7 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -2137,6 +2137,8 @@ int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s) wpa_drv_flush_pmkid(wpa_s); wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; + wpa_s->prev_scan_wildcard = 0; + if (wpa_supplicant_enabled_networks(wpa_s->conf)) { if (wpa_supplicant_delayed_sched_scan(wpa_s, interface_count, 100000)) diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 3e3b23de2..8ae2500e4 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -285,6 +285,9 @@ struct wpa_supplicant { void *drv_priv; /* private data used by driver_ops */ void *global_drv_priv; + /* previous scan was wildcard when interleaving between + * wildcard scans and specific SSID scan when max_ssids=1 */ + int prev_scan_wildcard; struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID; * NULL = not yet initialized (start * with wildcard SSID)