diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 2b512426d..722c94ff5 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -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 { diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index f5645c8a0..675c4467f 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -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(¶ms, 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) { diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 25abffd68..9afdceef0 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -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; diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c index c1e5e44b4..89694525b 100644 --- a/wpa_supplicant/wps_supplicant.c +++ b/wpa_supplicant/wps_supplicant.c @@ -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);