]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Use normal scan before sched_scan if that can speed up connection
authorJouni Malinen <jouni@qca.qualcomm.com>
Mon, 28 Nov 2011 16:36:36 +0000 (18:36 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 28 Nov 2011 16:36:36 +0000 (18:36 +0200)
When normal scan can speed up operations, use that for the first three
scan runs before starting the sched_scan to allow user space sleep more.
We do this only if the normal scan has functionality that is suitable
for this or if the sched_scan does not have better support for multiple
SSIDs.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

wpa_supplicant/ctrl_iface.c
wpa_supplicant/scan.c
wpa_supplicant/wpa_supplicant_i.h
wpa_supplicant/wps_supplicant.c

index 2b512426d59ed86867c6fe7ad1436ef889f71478..722c94ff544427c1ff73da5fd091fa2820bbfc43 100644 (file)
@@ -3335,6 +3335,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strcmp(buf, "LOGOFF") == 0) {
                eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
        } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
+               wpa_s->normal_scans = 0;
                if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
                        reply_len = -1;
                else {
@@ -3343,6 +3344,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        wpa_supplicant_req_scan(wpa_s, 0, 0);
                }
        } else if (os_strcmp(buf, "RECONNECT") == 0) {
+               wpa_s->normal_scans = 0;
                if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
                        reply_len = -1;
                else if (wpa_s->disconnected) {
@@ -3584,6 +3586,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                wpa_supplicant_deauthenticate(wpa_s,
                                              WLAN_REASON_DEAUTH_LEAVING);
        } else if (os_strcmp(buf, "SCAN") == 0) {
+               wpa_s->normal_scans = 0;
                if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
                        reply_len = -1;
                else {
index f5645c8a044710d4fe0688aca2bc64d8711f5257..675c4467f72dab250b12056bf96d0a16855246f8 100644 (file)
@@ -203,8 +203,10 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
        if (ret) {
                wpa_supplicant_notify_scanning(wpa_s, 0);
                wpas_notify_scan_done(wpa_s, 0);
-       } else
+       } else {
                wpa_s->scan_runs++;
+               wpa_s->normal_scans++;
+       }
 
        return ret;
 }
@@ -702,6 +704,7 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
        int ret;
        unsigned int max_sched_scan_ssids;
        int wildcard = 0;
+       int need_ssids;
 
        if (!wpa_s->sched_scan_supported)
                return -1;
@@ -718,6 +721,33 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
                return 0;
        }
 
+       need_ssids = 0;
+       for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
+               if (!ssid->disabled && !ssid->scan_ssid) {
+                       /* Use wildcard SSID to find this network */
+                       wildcard = 1;
+               } else if (!ssid->disabled && ssid->ssid_len)
+                       need_ssids++;
+       }
+       if (wildcard)
+               need_ssids++;
+
+       if (wpa_s->normal_scans < 3 &&
+           (need_ssids <= wpa_s->max_scan_ssids ||
+            wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) {
+               /*
+                * When normal scan can speed up operations, use that for the
+                * first operations before starting the sched_scan to allow
+                * user space sleep more. We do this only if the normal scan
+                * has functionality that is suitable for this or if the
+                * sched_scan does not have better support for multiple SSIDs.
+                */
+               wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of "
+                       "sched_scan for initial scans (normal_scans=%d)",
+                       wpa_s->normal_scans);
+               return -1;
+       }
+
        os_memset(&params, 0, sizeof(params));
 
        /* If we can't allocate space for the filters, we just don't filter */
@@ -729,14 +759,6 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s)
            wpa_s->wpa_state == WPA_INACTIVE)
                wpa_supplicant_set_state(wpa_s, WPA_SCANNING);
 
-       for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
-               if (!ssid->disabled && !ssid->scan_ssid) {
-                       /* Use wildcard SSID to find this network */
-                       wildcard = 1;
-                       break;
-               }
-       }
-
        /* Find the starting point from which to continue scanning */
        ssid = wpa_s->conf->ssid;
        if (wpa_s->prev_sched_ssid) {
index 25abffd68c10f1fcae9c456868ff0419345d103b..9afdceef0fb91e850b287fd92892f1ae48457ab9 100644 (file)
@@ -337,6 +337,7 @@ struct wpa_supplicant {
        int scan_runs; /* number of scan runs since WPS was started */
        int *next_scan_freqs;
        int scan_interval; /* time in sec between scans to find suitable AP */
+       int normal_scans; /* normal scans run before sched_scan */
 
        unsigned int drv_flags;
        int max_scan_ssids;
index c1e5e44b4ebe13fb770afe204a9f2112e7d1b6eb..89694525b738fd979004346fd85b43c100ecfa84 100644 (file)
@@ -88,6 +88,7 @@ int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
                }
                wpa_s->after_wps = 5;
                wpa_s->wps_freq = wpa_s->assoc_freq;
+               wpa_s->normal_scans = 0;
                wpa_s->reassociate = 1;
                wpa_supplicant_req_scan(wpa_s, 0, 0);
                return 1;
@@ -814,6 +815,7 @@ static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
        wpa_s->disconnected = 0;
        wpa_s->reassociate = 1;
        wpa_s->scan_runs = 0;
+       wpa_s->normal_scans = 0;
        wpa_s->wps_success = 0;
        wpa_s->blacklist_cleared = 0;
        wpa_supplicant_req_scan(wpa_s, 0, 0);