diff mbox

[4/8] wpa_supplicant: Disconnect before trying to switch to a different network

Message ID 1449744969-14895-4-git-send-email-ilan.peer@intel.com
State Accepted
Headers show

Commit Message

Ilan Peer Dec. 10, 2015, 10:56 a.m. UTC
From: Ayala Beker <ayala.beker@intel.com>

Currently, when wpa_supplicant receives bgscan results
with a preferred netwrok, it connects to that network without
disconnecting from the previous one. This might result in an
inconsistent state of upper layers.

Fix this by disconnecting from the current AP before connecting to
the new one.

Signed-off-by: Ayala Beker <ayala.beker@intel.com>
---
 wpa_supplicant/events.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox

Patch

diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index a7b053d..192b666 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1574,6 +1574,13 @@  static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
 			return 0;
 		}
 
+		if (ssid != wpa_s->current_ssid &&
+		    wpa_s->wpa_state >= WPA_AUTHENTICATING) {
+			wpa_s->own_disconnect_req = 1;
+			wpa_supplicant_deauthenticate(wpa_s,
+						      WLAN_REASON_DEAUTH_LEAVING);
+		}
+
 		if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
 			wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
 			return -1;