diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h index 7e066ce59..1c9588164 100644 --- a/src/common/wpa_ctrl.h +++ b/src/common/wpa_ctrl.h @@ -54,6 +54,8 @@ extern "C" { #define WPA_EVENT_TEMP_DISABLED "CTRL-EVENT-SSID-TEMP-DISABLED " /** Temporarily disabled network block re-enabled */ #define WPA_EVENT_REENABLED "CTRL-EVENT-SSID-REENABLED " +/** New scan started */ +#define WPA_EVENT_SCAN_STARTED "CTRL-EVENT-SCAN-STARTED " /** New scan results available */ #define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS " /** wpa_supplicant state change */ diff --git a/src/drivers/driver.h b/src/drivers/driver.h index 4f50077f9..3832a4189 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -3385,7 +3385,17 @@ enum wpa_event_type { * survey entry for one frequency. The survey data can be os_malloc()'d * and then os_free()'d, so the event callback must only copy data. */ - EVENT_SURVEY + EVENT_SURVEY, + + /** + * EVENT_SCAN_STARTED - Scan started + * + * This indicates that driver has started a scan operation either based + * on a request from wpa_supplicant/hostapd or from another application. + * EVENT_SCAN_RESULTS is used to indicate when the scan has been + * completed (either successfully or by getting cancelled). + */ + EVENT_SCAN_STARTED }; diff --git a/src/drivers/driver_common.c b/src/drivers/driver_common.c index 8d1d22eb8..8a6b438a1 100644 --- a/src/drivers/driver_common.c +++ b/src/drivers/driver_common.c @@ -85,6 +85,7 @@ const char * event_to_string(enum wpa_event_type event) E2S(DFS_CAC_ABORTED); E2S(DFS_NOP_FINISHED); E2S(SURVEY); + E2S(SCAN_STARTED); } return "UNKNOWN"; diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index e47291cc5..a782c11f7 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -2702,6 +2702,7 @@ static void do_process_drv_event(struct i802_bss *bss, int cmd, case NL80211_CMD_TRIGGER_SCAN: wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger"); drv->scan_state = SCAN_STARTED; + wpa_supplicant_event(drv->ctx, EVENT_SCAN_STARTED, NULL); break; case NL80211_CMD_START_SCHED_SCAN: wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index eeb27e30e..740309d09 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -1265,7 +1265,8 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, return 0; } - wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); + wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", + wpa_s->own_scan_running, wpa_s->external_scan_running); wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); wpas_notify_scan_results(wpa_s); @@ -2736,8 +2737,22 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, wpa_supplicant_event_michael_mic_failure(wpa_s, data); break; #ifndef CONFIG_NO_SCAN_PROCESSING + case EVENT_SCAN_STARTED: + if (wpa_s->own_scan_requested) { + wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan"); + wpa_s->own_scan_requested = 0; + wpa_s->own_scan_running = 1; + wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); + } else { + wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); + wpa_s->external_scan_running = 1; + wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); + } + break; case EVENT_SCAN_RESULTS: wpa_supplicant_event_scan_results(wpa_s, data); + wpa_s->own_scan_running = 0; + wpa_s->external_scan_running = 0; if (wpa_s->wpa_state != WPA_AUTHENTICATING && wpa_s->wpa_state != WPA_ASSOCIATING) wpas_p2p_continue_after_scan(wpa_s); diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 117e4936b..b4b3da267 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -319,6 +319,7 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, } else { os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; + wpa_s->own_scan_requested = 1; } return ret; @@ -4031,6 +4032,7 @@ static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq) if (!ret) { os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_res_handler = wpas_p2p_scan_res_join; + wpa_s->own_scan_requested = 1; } wpabuf_free(ies); diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index d96345226..3fcd61699 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -163,6 +163,7 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s, os_get_reltime(&wpa_s->scan_trigger_time); wpa_s->scan_runs++; wpa_s->normal_scans++; + wpa_s->own_scan_requested = 1; } return ret; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index ebe30e4ef..960008e8d 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -483,6 +483,9 @@ struct wpa_supplicant { int *next_scan_freqs; int *manual_scan_freqs; unsigned int manual_scan_passive:1; + unsigned int own_scan_requested:1; + unsigned int own_scan_running:1; + unsigned int external_scan_running:1; int scan_interval; /* time in sec between scans to find suitable AP */ int normal_scans; /* normal scans run before sched_scan */ int scan_for_connection; /* whether the scan request was triggered for