From 9796a86c2382eab4a9c1bb4c03ea4944051d78ea Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 25 Nov 2012 16:30:30 +0200 Subject: [PATCH] Use a shared function for requesting a new connection Both the ctrl_iface and D-Bus interface use similar functionality to request a new connection. Combine these to a single function to avoid need to maintain duplicated implementation. Signed-hostap: Jouni Malinen --- wpa_supplicant/ctrl_iface.c | 20 ++++---------------- wpa_supplicant/dbus/dbus_new_handlers.c | 8 +------- wpa_supplicant/wpa_supplicant.c | 19 +++++++++++++++++++ wpa_supplicant/wpa_supplicant_i.h | 1 + 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 328d382fa..2de847490 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -4781,27 +4781,15 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, } else if (os_strcmp(buf, "LOGOFF") == 0) { eapol_sm_notify_logoff(wpa_s->eapol, TRUE); } else if (os_strcmp(buf, "REASSOCIATE") == 0) { - wpa_s->normal_scans = 0; - wpa_supplicant_reinit_autoscan(wpa_s); if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) reply_len = -1; - else { - wpa_s->extra_blacklist_count = 0; - wpa_s->disconnected = 0; - wpa_s->reassociate = 1; - wpa_supplicant_req_scan(wpa_s, 0, 0); - } + else + wpas_request_connection(wpa_s); } else if (os_strcmp(buf, "RECONNECT") == 0) { - wpa_s->normal_scans = 0; - wpa_supplicant_reinit_autoscan(wpa_s); if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) reply_len = -1; - else if (wpa_s->disconnected) { - wpa_s->extra_blacklist_count = 0; - wpa_s->disconnected = 0; - wpa_s->reassociate = 1; - wpa_supplicant_req_scan(wpa_s, 0, 0); - } + else if (wpa_s->disconnected) + wpas_request_connection(wpa_s); #ifdef IEEE8021X_EAPOL } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) { if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8)) diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index ce736678b..7d1572902 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -1455,13 +1455,7 @@ DBusMessage * wpas_dbus_handler_reassociate(DBusMessage *message, struct wpa_supplicant *wpa_s) { if (wpa_s->current_ssid != NULL) { - wpa_s->extra_blacklist_count = 0; - wpa_s->normal_scans = 0; - wpa_supplicant_reinit_autoscan(wpa_s); - wpa_s->disconnected = 0; - wpa_s->reassociate = 1; - wpa_supplicant_req_scan(wpa_s, 0, 0); - + wpas_request_connection(wpa_s); return NULL; } diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 901057e9f..784a47142 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -3716,3 +3716,22 @@ int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid, return 0; } + + +/** + * wpas_request_connection - Request a new connection + * @wpa_s: Pointer to the network interface + * + * This function is used to request a new connection to be found. It will mark + * the interface to allow reassociation and request a new scan to find a + * suitable network to connect to. + */ +void wpas_request_connection(struct wpa_supplicant *wpa_s) +{ + wpa_s->normal_scans = 0; + wpa_supplicant_reinit_autoscan(wpa_s); + wpa_s->extra_blacklist_count = 0; + wpa_s->disconnected = 0; + wpa_s->reassociate = 1; + wpa_supplicant_req_scan(wpa_s, 0, 0); +} diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 83eeb9c0b..a92d0c1f4 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -754,6 +754,7 @@ void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s, int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid); int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid, size_t ssid_len); +void wpas_request_connection(struct wpa_supplicant *wpa_s); /** * wpa_supplicant_ctrl_iface_ctrl_rsp_handle - Handle a control response