From 992189991ca99e89208a1bad4cb4305e115dd66f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 26 Jun 2012 19:52:46 +0300 Subject: [PATCH] Start autoscan for first connection attempt Use wpa_supplicant_set_state() to initialize state to DISCONNECT so that autoscan gets initialized properly. This needs a change in autoscan_init() to avoid extra scan request that would postpone the first scan request when an interface is added. Signed-hostap: Jouni Malinen --- wpa_supplicant/autoscan.c | 4 +++- wpa_supplicant/autoscan.h | 4 ++-- wpa_supplicant/ctrl_iface.c | 2 +- wpa_supplicant/dbus/dbus_new_handlers.c | 2 +- wpa_supplicant/wpa_supplicant.c | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/wpa_supplicant/autoscan.c b/wpa_supplicant/autoscan.c index bac8df67f..d0c040a37 100644 --- a/wpa_supplicant/autoscan.c +++ b/wpa_supplicant/autoscan.c @@ -43,7 +43,7 @@ static void request_scan(struct wpa_supplicant *wpa_s) } -int autoscan_init(struct wpa_supplicant *wpa_s) +int autoscan_init(struct wpa_supplicant *wpa_s, int req_scan) { const char *name = wpa_s->conf->autoscan; const char *params; @@ -88,6 +88,8 @@ int autoscan_init(struct wpa_supplicant *wpa_s) wpa_printf(MSG_DEBUG, "autoscan: Initialized module '%s' with " "parameters '%s'", ops->name, params); + if (!req_scan) + return 0; /* * Cancelling existing scan requests, if any. diff --git a/wpa_supplicant/autoscan.h b/wpa_supplicant/autoscan.h index e2fde8ecb..e2a765221 100644 --- a/wpa_supplicant/autoscan.h +++ b/wpa_supplicant/autoscan.h @@ -22,14 +22,14 @@ struct autoscan_ops { #ifdef CONFIG_AUTOSCAN -int autoscan_init(struct wpa_supplicant *wpa_s); +int autoscan_init(struct wpa_supplicant *wpa_s, int req_scan); void autoscan_deinit(struct wpa_supplicant *wpa_s); int autoscan_notify_scan(struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res); #else /* CONFIG_AUTOSCAN */ -static inline int autoscan_init(struct wpa_supplicant *wpa_s) +static inline int autoscan_init(struct wpa_supplicant *wpa_s, int req_scan) { return 0; } diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 5bd155958..612e258d0 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -3890,7 +3890,7 @@ static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s, if (wpa_s->conf->autoscan == NULL) autoscan_deinit(wpa_s); else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) - autoscan_init(wpa_s); + autoscan_init(wpa_s, 1); return 0; } diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index 4ac6716d0..eb902f6bc 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1841,7 +1841,7 @@ DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message, os_free(wpa_s->conf->autoscan); wpa_s->conf->autoscan = tmp; if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) - autoscan_init(wpa_s); + autoscan_init(wpa_s, 1); } } else if (arg != NULL && os_strlen(arg) == 0) { os_free(wpa_s->conf->autoscan); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index a0432083b..78118d450 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -574,7 +574,7 @@ static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s) { - if (autoscan_init(wpa_s)) + if (autoscan_init(wpa_s, 0)) wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan"); } @@ -694,7 +694,7 @@ void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s) wpa_s->mgmt_group_cipher = 0; wpa_s->key_mgmt = 0; if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) - wpa_s->wpa_state = WPA_DISCONNECTED; + wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); if (wpa_s->wpa_state != old_state) wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); @@ -2826,6 +2826,7 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global, global->ifaces = wpa_s; wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname); + wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); return wpa_s; }