Remove src/common from default header file path
[mech_eap.git] / wpa_supplicant / sme.c
index 60d0fa9..b4fe000 100644 (file)
@@ -15,9 +15,9 @@
 #include "includes.h"
 
 #include "common.h"
-#include "ieee802_11_defs.h"
+#include "common/ieee802_11_defs.h"
 #include "eapol_supp/eapol_supp_sm.h"
-#include "wpa_common.h"
+#include "common/wpa_common.h"
 #include "wpa.h"
 #include "pmksa_cache.h"
 #include "config.h"
@@ -26,6 +26,7 @@
 #include "wpas_glue.h"
 #include "wps_supplicant.h"
 #include "notify.h"
+#include "blacklist.h"
 #include "sme.h"
 
 void sme_authenticate(struct wpa_supplicant *wpa_s,
@@ -58,6 +59,10 @@ void sme_authenticate(struct wpa_supplicant *wpa_s,
        params.ssid = ie + 2;
        params.ssid_len = ie[1];
 
+       if (wpa_s->sme.ssid_len != params.ssid_len ||
+           os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0)
+               wpa_s->sme.prev_bssid_set = 0;
+
        wpa_s->sme.freq = params.freq;
        os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len);
        wpa_s->sme.ssid_len = params.ssid_len;
@@ -311,6 +316,8 @@ void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data)
 #endif /* CONFIG_IEEE80211R */
        params.mode = ssid->mode;
        params.mgmt_frame_protection = wpa_s->sme.mfp;
+       if (wpa_s->sme.prev_bssid_set)
+               params.prev_bssid = wpa_s->sme.prev_bssid;
 
        wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
                " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
@@ -357,12 +364,40 @@ void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
                            union wpa_event_data *data)
 {
        int bssid_changed;
+       int timeout = 5000;
 
-       wpa_printf(MSG_DEBUG, "SME: Association failed: status code %d",
+       wpa_printf(MSG_DEBUG, "SME: Association with " MACSTR " failed: "
+                  "status code %d", MAC2STR(wpa_s->pending_bssid),
                   data->assoc_reject.status_code);
 
-       wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
        bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
+
+       /*
+        * For now, unconditionally terminate the previous authentication. In
+        * theory, this should not be needed, but mac80211 gets quite confused
+        * if the authentication is left pending.. Some roaming cases might
+        * benefit from using the previous authentication, so this could be
+        * optimized in the future.
+        */
+       if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid,
+                                  WLAN_REASON_DEAUTH_LEAVING) < 0) {
+               wpa_msg(wpa_s, MSG_INFO,
+                       "Deauth request to the driver failed");
+       }
+       wpa_s->sme.prev_bssid_set = 0;
+
+       if (wpa_blacklist_add(wpa_s, wpa_s->pending_bssid) == 0) {
+               struct wpa_blacklist *b;
+               b = wpa_blacklist_get(wpa_s, wpa_s->pending_bssid);
+               if (b && b->count < 3) {
+                       /*
+                        * Speed up next attempt if there could be other APs
+                        * that could accept association.
+                        */
+                       timeout = 100;
+               }
+       }
+       wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
        os_memset(wpa_s->bssid, 0, ETH_ALEN);
        os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
        if (bssid_changed)
@@ -372,7 +407,8 @@ void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
         * TODO: if more than one possible AP is available in scan results,
         * could try the other ones before requesting a new scan.
         */
-       wpa_supplicant_req_scan(wpa_s, 5, 0);
+       wpa_supplicant_req_scan(wpa_s, timeout / 1000,
+                               1000 * (timeout % 1000));
 }