From 14f34a73031e2878101be473d8416f7c09d37833 Mon Sep 17 00:00:00 2001 From: Avraham Stern Date: Mon, 5 Sep 2016 17:32:59 +0300 Subject: [PATCH] Continue scanning if sched_scan stops unexpectedly When scheduled scan stops without the interface request (for example, driver stopped it unexpectedly), start a regular scan to continue scanning for networks and avoid being left with no scan at all. Signed-off-by: Avraham Stern --- wpa_supplicant/events.c | 14 ++++++++++++++ wpa_supplicant/scan.c | 6 ++++++ wpa_supplicant/wpa_supplicant_i.h | 1 + 3 files changed, 21 insertions(+) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 018cd5f1e..abe3b4767 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -4065,6 +4065,20 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) break; + /* + * If the driver stopped scanning without being requested to, + * request a new scan to continue scanning for networks. + */ + if (!wpa_s->sched_scan_stop_req && + wpa_s->wpa_state == WPA_SCANNING) { + wpa_dbg(wpa_s, MSG_DEBUG, + "Restart scanning after unexpected sched_scan stop event"); + wpa_supplicant_req_scan(wpa_s, 1, 0); + break; + } + + wpa_s->sched_scan_stop_req = 0; + /* * Start a new sched scan to continue searching for more SSIDs * either if timed out or PNO schedule scan is pending. diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 60e7b68b5..5f84b216c 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -1256,6 +1256,8 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s) if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload) return -1; + wpa_s->sched_scan_stop_req = 0; + if (wpa_s->sched_scanning) { wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning"); return 0; @@ -1554,6 +1556,9 @@ void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s) if (!wpa_s->sched_scanning) return; + if (wpa_s->sched_scanning) + wpa_s->sched_scan_stop_req = 1; + wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan"); eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL); wpa_supplicant_stop_sched_scan(wpa_s); @@ -2530,6 +2535,7 @@ int wpas_stop_pno(struct wpa_supplicant *wpa_s) return 0; ret = wpa_supplicant_stop_sched_scan(wpa_s); + wpa_s->sched_scan_stop_req = 1; wpa_s->pno = 0; wpa_s->pno_sched_pending = 0; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 5d8ac811e..ef9273d09 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -574,6 +574,7 @@ struct wpa_supplicant { struct wpa_radio_work *scan_work; int scanning; int sched_scanning; + unsigned int sched_scan_stop_req:1; int new_connection; int eapol_received; /* number of EAPOL packets received after the