From 4115303bbe77ff0db40b489af92f47fc5ea2c9ad Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 25 Nov 2012 15:55:32 +0200 Subject: [PATCH] Document wpa_s->scan_req Use an enum with documented values to make it easier to understand how wpa_s->scan_req is used. Signed-hostap: Jouni Malinen --- wpa_supplicant/autoscan.c | 2 +- wpa_supplicant/ctrl_iface.c | 4 ++-- wpa_supplicant/dbus/dbus_new_handlers.c | 2 +- wpa_supplicant/dbus/dbus_old_handlers.c | 2 +- wpa_supplicant/interworking.c | 2 +- wpa_supplicant/scan.c | 15 ++++++------ wpa_supplicant/wpa_supplicant.c | 4 ++-- wpa_supplicant/wpa_supplicant_i.h | 32 +++++++++++++++++++++++-- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/wpa_supplicant/autoscan.c b/wpa_supplicant/autoscan.c index d0c040a37..a2cf7a5ef 100644 --- a/wpa_supplicant/autoscan.c +++ b/wpa_supplicant/autoscan.c @@ -36,7 +36,7 @@ static const struct autoscan_ops * autoscan_modules[] = { static void request_scan(struct wpa_supplicant *wpa_s) { - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; if (wpa_supplicant_req_sched_scan(wpa_s)) wpa_supplicant_req_scan(wpa_s, wpa_s->scan_interval, 0); diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 8b84b4098..f47495d57 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -5094,14 +5094,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, ((wpa_s->wpa_state <= WPA_SCANNING) || (wpa_s->wpa_state == WPA_COMPLETED))) { wpa_s->normal_scans = 0; - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_supplicant_req_scan(wpa_s, 0, 0); } else if (wpa_s->sched_scanning) { wpa_printf(MSG_DEBUG, "Stop ongoing " "sched_scan to allow requested " "full scan to proceed"); wpa_supplicant_cancel_sched_scan(wpa_s); - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_supplicant_req_scan(wpa_s, 0, 0); } else { wpa_printf(MSG_DEBUG, "Ongoing scan action - " diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index 72d1dfa22..a0b7479bf 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1313,7 +1313,7 @@ DBusMessage * wpas_dbus_handler_scan(DBusMessage *message, } else if (params.freqs && params.freqs[0]) { wpa_supplicant_trigger_scan(wpa_s, ¶ms); } else { - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_supplicant_req_scan(wpa_s, 0, 0); } } else if (!os_strcmp(type, "active")) { diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c b/wpa_supplicant/dbus/dbus_old_handlers.c index e217a7279..68e551524 100644 --- a/wpa_supplicant/dbus/dbus_old_handlers.c +++ b/wpa_supplicant/dbus/dbus_old_handlers.c @@ -331,7 +331,7 @@ DBusMessage * wpas_dbus_global_set_debugparams(DBusMessage *message, DBusMessage * wpas_dbus_iface_scan(DBusMessage *message, struct wpa_supplicant *wpa_s) { - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_supplicant_req_scan(wpa_s, 0, 0); return wpas_dbus_new_success_reply(message); } diff --git a/wpa_supplicant/interworking.c b/wpa_supplicant/interworking.c index 320807ef3..cfe56ea99 100644 --- a/wpa_supplicant/interworking.c +++ b/wpa_supplicant/interworking.c @@ -1964,7 +1964,7 @@ int interworking_select(struct wpa_supplicant *wpa_s, int auto_select) wpa_printf(MSG_DEBUG, "Interworking: Start scan for network " "selection"); wpa_s->scan_res_handler = interworking_scan_res_handler; - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_supplicant_req_scan(wpa_s, 0, 0); return 0; diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index e7f2e7125..82c5b7863 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -505,7 +505,8 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) { struct wpa_supplicant *wpa_s = eloop_ctx; struct wpa_ssid *ssid; - int scan_req = 0, ret; + enum scan_req_type scan_req = NORMAL_SCAN_REQ; + int ret; struct wpabuf *extra_ie = NULL; struct wpa_driver_scan_params params; struct wpa_driver_scan_params *scan_params; @@ -517,14 +518,14 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) return; } - if (wpa_s->disconnected && !wpa_s->scan_req) { + if (wpa_s->disconnected && wpa_s->scan_req == NORMAL_SCAN_REQ) { wpa_dbg(wpa_s, MSG_DEBUG, "Disconnected - do not scan"); wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); return; } if (!wpa_supplicant_enabled_networks(wpa_s) && - !wpa_s->scan_req) { + wpa_s->scan_req == NORMAL_SCAN_REQ) { wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan"); wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); #ifdef CONFIG_P2P @@ -572,7 +573,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) } scan_req = wpa_s->scan_req; - wpa_s->scan_req = 0; + wpa_s->scan_req = NORMAL_SCAN_REQ; os_memset(¶ms, 0, sizeof(params)); @@ -589,7 +590,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) goto scan; } - if (scan_req != 2 && wpa_s->connect_without_scan) { + if (scan_req != MANUAL_SCAN_REQ && wpa_s->connect_without_scan) { for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { if (ssid == wpa_s->connect_without_scan) break; @@ -627,7 +628,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) } } - if (scan_req != 2 && wpa_s->conf->ap_scan == 2) { + if (scan_req != MANUAL_SCAN_REQ && wpa_s->conf->ap_scan == 2) { wpa_s->connect_without_scan = NULL; wpa_s->prev_scan_wildcard = 0; wpa_supplicant_assoc_try(wpa_s, ssid); @@ -762,7 +763,7 @@ scan: * station interface when we are not configured to prefer station * connection and a concurrent operation is already in process. */ - if (wpa_s->scan_for_connection && !scan_req && + if (wpa_s->scan_for_connection && scan_req == NORMAL_SCAN_REQ && !scan_params->freqs && !params.freqs && wpas_is_p2p_prioritized(wpa_s) && !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT) && diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index e77edb50d..a5bd58ae5 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -1322,7 +1322,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { /* Use ap_scan==1 style network selection to find the network */ - wpa_s->scan_req = 2; + wpa_s->scan_req = MANUAL_SCAN_REQ; wpa_s->reassociate = 1; wpa_supplicant_req_scan(wpa_s, 0, 0); return; @@ -2413,7 +2413,7 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void) wpa_s = os_zalloc(sizeof(*wpa_s)); if (wpa_s == NULL) return NULL; - wpa_s->scan_req = 1; + wpa_s->scan_req = INITIAL_SCAN_REQ; wpa_s->scan_interval = 5; wpa_s->new_connection = 1; wpa_s->parent = wpa_s; diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 7fa5a88fd..071944d2b 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -397,8 +397,36 @@ struct wpa_supplicant { struct wpa_blacklist *blacklist; - int scan_req; /* manual scan request; this forces a scan even if there - * are no enabled networks in the configuration */ + /** + * scan_req - Type of the scan request + */ + enum scan_req_type { + /** + * NORMAL_SCAN_REQ - Normal scan request + * + * This is used for scans initiated by wpa_supplicant to find an + * AP for a connection. + */ + NORMAL_SCAN_REQ, + + /** + * INITIAL_SCAN_REQ - Initial scan request + * + * This is used for the first scan on an interface to force at + * least one scan to be run even if the configuration does not + * include any enabled networks. + */ + INITIAL_SCAN_REQ, + + /** + * MANUAL_SCAN_REQ - Manual scan request + * + * This is used for scans where the user request a scan or + * a specific wpa_supplicant operation (e.g., WPS) requires scan + * to be run. + */ + MANUAL_SCAN_REQ + } scan_req; 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 */