Track whether scan was started by us or an external program

This can be used to improve scan behavior in cases external programs
request scans directly from the driver.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-12-26 17:33:26 +02:00
parent 18ae237783
commit a5f40eff18
8 changed files with 37 additions and 2 deletions

View file

@ -54,6 +54,8 @@ extern "C" {
#define WPA_EVENT_TEMP_DISABLED "CTRL-EVENT-SSID-TEMP-DISABLED " #define WPA_EVENT_TEMP_DISABLED "CTRL-EVENT-SSID-TEMP-DISABLED "
/** Temporarily disabled network block re-enabled */ /** Temporarily disabled network block re-enabled */
#define WPA_EVENT_REENABLED "CTRL-EVENT-SSID-REENABLED " #define WPA_EVENT_REENABLED "CTRL-EVENT-SSID-REENABLED "
/** New scan started */
#define WPA_EVENT_SCAN_STARTED "CTRL-EVENT-SCAN-STARTED "
/** New scan results available */ /** New scan results available */
#define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS " #define WPA_EVENT_SCAN_RESULTS "CTRL-EVENT-SCAN-RESULTS "
/** wpa_supplicant state change */ /** wpa_supplicant state change */

View file

@ -3385,7 +3385,17 @@ enum wpa_event_type {
* survey entry for one frequency. The survey data can be os_malloc()'d * 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. * 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
}; };

View file

@ -85,6 +85,7 @@ const char * event_to_string(enum wpa_event_type event)
E2S(DFS_CAC_ABORTED); E2S(DFS_CAC_ABORTED);
E2S(DFS_NOP_FINISHED); E2S(DFS_NOP_FINISHED);
E2S(SURVEY); E2S(SURVEY);
E2S(SCAN_STARTED);
} }
return "UNKNOWN"; return "UNKNOWN";

View file

@ -2702,6 +2702,7 @@ static void do_process_drv_event(struct i802_bss *bss, int cmd,
case NL80211_CMD_TRIGGER_SCAN: case NL80211_CMD_TRIGGER_SCAN:
wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger"); wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger");
drv->scan_state = SCAN_STARTED; drv->scan_state = SCAN_STARTED;
wpa_supplicant_event(drv->ctx, EVENT_SCAN_STARTED, NULL);
break; break;
case NL80211_CMD_START_SCHED_SCAN: case NL80211_CMD_START_SCHED_SCAN:
wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started");

View file

@ -1265,7 +1265,8 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
return 0; 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); wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
wpas_notify_scan_results(wpa_s); 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); wpa_supplicant_event_michael_mic_failure(wpa_s, data);
break; break;
#ifndef CONFIG_NO_SCAN_PROCESSING #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: case EVENT_SCAN_RESULTS:
wpa_supplicant_event_scan_results(wpa_s, data); 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 && if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
wpa_s->wpa_state != WPA_ASSOCIATING) wpa_s->wpa_state != WPA_ASSOCIATING)
wpas_p2p_continue_after_scan(wpa_s); wpas_p2p_continue_after_scan(wpa_s);

View file

@ -319,6 +319,7 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
} else { } else {
os_get_reltime(&wpa_s->scan_trigger_time); os_get_reltime(&wpa_s->scan_trigger_time);
wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
wpa_s->own_scan_requested = 1;
} }
return ret; return ret;
@ -4031,6 +4032,7 @@ static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq)
if (!ret) { if (!ret) {
os_get_reltime(&wpa_s->scan_trigger_time); os_get_reltime(&wpa_s->scan_trigger_time);
wpa_s->scan_res_handler = wpas_p2p_scan_res_join; wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
wpa_s->own_scan_requested = 1;
} }
wpabuf_free(ies); wpabuf_free(ies);

View file

@ -163,6 +163,7 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
os_get_reltime(&wpa_s->scan_trigger_time); os_get_reltime(&wpa_s->scan_trigger_time);
wpa_s->scan_runs++; wpa_s->scan_runs++;
wpa_s->normal_scans++; wpa_s->normal_scans++;
wpa_s->own_scan_requested = 1;
} }
return ret; return ret;

View file

@ -483,6 +483,9 @@ struct wpa_supplicant {
int *next_scan_freqs; int *next_scan_freqs;
int *manual_scan_freqs; int *manual_scan_freqs;
unsigned int manual_scan_passive:1; 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 scan_interval; /* time in sec between scans to find suitable AP */
int normal_scans; /* normal scans run before sched_scan */ int normal_scans; /* normal scans run before sched_scan */
int scan_for_connection; /* whether the scan request was triggered for int scan_for_connection; /* whether the scan request was triggered for