2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 #ifndef CONFIG_NO_SCAN_PROCESSING
48 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
50 #endif /* CONFIG_NO_SCAN_PROCESSING */
53 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
71 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
73 struct wpa_ssid *ssid, *old_ssid;
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
81 ssid = wpa_supplicant_get_ssid(wpa_s);
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
88 if (wpas_network_disabled(wpa_s, ssid)) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
93 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
99 res = wpas_temp_disabled(wpa_s, ssid);
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
110 size_t wpa_ie_len = sizeof(wpa_ie);
111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
131 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
133 struct wpa_supplicant *wpa_s = eloop_ctx;
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
144 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
148 wnm_bss_keep_alive_deinit(wpa_s);
150 #ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153 #endif /* CONFIG_IBSS_RSN */
156 wpa_supplicant_ap_deinit(wpa_s);
157 #endif /* CONFIG_AP */
159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
167 wpa_s->sme.prev_bssid_set = 0;
168 #endif /* CONFIG_SME */
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171 #endif /* CONFIG_P2P */
172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
174 #ifdef CONFIG_IEEE80211R
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178 #endif /* CONFIG_SME */
179 #endif /* CONFIG_IEEE80211R */
182 wpas_notify_bssid_changed(wpa_s);
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
189 wpa_s->current_ssid = NULL;
190 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
195 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
197 struct wpa_ie_data ie;
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
220 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
240 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
246 #ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
256 #endif /* IEEE8021X_EAPOL */
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
271 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
274 #ifdef IEEE8021X_EAPOL
276 int aka = 0, sim = 0, type;
278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
281 if (ssid->eap.eap_methods == NULL) {
285 struct eap_method_type *eap = ssid->eap.eap_methods;
286 while (eap->vendor != EAP_VENDOR_IETF ||
287 eap->method != EAP_TYPE_NONE) {
288 if (eap->vendor == EAP_VENDOR_IETF) {
289 if (eap->method == EAP_TYPE_SIM)
291 else if (eap->method == EAP_TYPE_AKA ||
292 eap->method == EAP_TYPE_AKA_PRIME)
299 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
302 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
307 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
308 "use SIM, but neither EAP-SIM nor EAP-AKA are "
313 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
314 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
316 type = SCARD_TRY_BOTH;
318 type = SCARD_USIM_ONLY;
320 type = SCARD_GSM_SIM_ONLY;
322 wpa_s->scard = scard_init(type, NULL);
323 if (wpa_s->scard == NULL) {
324 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
328 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
329 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
330 #endif /* PCSC_FUNCS */
331 #endif /* IEEE8021X_EAPOL */
337 #ifndef CONFIG_NO_SCAN_PROCESSING
339 static int has_wep_key(struct wpa_ssid *ssid)
343 for (i = 0; i < NUM_WEP_KEYS; i++) {
344 if (ssid->wep_key_len[i])
352 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
353 struct wpa_ssid *ssid)
357 if (ssid->mixed_cell)
361 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
363 #endif /* CONFIG_WPS */
365 if (has_wep_key(ssid))
368 #ifdef IEEE8021X_EAPOL
369 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
370 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
371 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
373 #endif /* IEEE8021X_EAPOL */
375 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
378 if (bss->caps & IEEE80211_CAP_PRIVACY)
384 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
385 struct wpa_ssid *ssid,
388 struct wpa_ie_data ie;
390 const u8 *rsn_ie, *wpa_ie;
394 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
398 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
399 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
400 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
401 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
402 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
404 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
405 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
408 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
409 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
415 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
417 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
422 if (!(ie.proto & ssid->proto)) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
428 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
429 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
434 if (!(ie.group_cipher & ssid->group_cipher)) {
435 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
440 if (!(ie.key_mgmt & ssid->key_mgmt)) {
441 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
446 #ifdef CONFIG_IEEE80211W
447 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
448 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
449 wpa_s->conf->pmf : ssid->ieee80211w) ==
450 MGMT_FRAME_PROTECTION_REQUIRED) {
451 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
455 #endif /* CONFIG_IEEE80211W */
457 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
461 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
462 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
465 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
472 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
474 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
479 if (!(ie.proto & ssid->proto)) {
480 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
485 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
486 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
491 if (!(ie.group_cipher & ssid->group_cipher)) {
492 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
497 if (!(ie.key_mgmt & ssid->key_mgmt)) {
498 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
503 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
507 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
509 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
513 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
514 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
519 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
520 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
524 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
531 static int freq_allowed(int *freqs, int freq)
538 for (i = 0; freqs[i]; i++)
539 if (freqs[i] == freq)
545 static int ht_supported(const struct hostapd_hw_modes *mode)
547 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
549 * The driver did not indicate whether it supports HT. Assume
550 * it does to avoid connection issues.
556 * IEEE Std 802.11n-2009 20.1.1:
557 * An HT non-AP STA shall support all EQM rates for one spatial stream.
559 return mode->mcs_set[0] == 0xff;
563 static int vht_supported(const struct hostapd_hw_modes *mode)
565 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
567 * The driver did not indicate whether it supports VHT. Assume
568 * it does to avoid connection issues.
574 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
575 * TODO: Verify if this complies with the standard
577 return (mode->vht_mcs_set[0] & 0x3) != 3;
581 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
583 const struct hostapd_hw_modes *mode = NULL, *modes;
584 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
589 return 1; /* Cannot do matching without knowing band */
591 modes = wpa_s->hw.modes;
594 * The driver does not provide any additional information
595 * about the utilized hardware, so allow the connection attempt
601 for (i = 0; i < wpa_s->hw.num_modes; i++) {
602 for (j = 0; j < modes[i].num_channels; j++) {
603 int freq = modes[i].channels[j].freq;
604 if (freq == bss->freq) {
606 mode->mode == HOSTAPD_MODE_IEEE80211G)
607 break; /* do not allow 802.11b replace
618 for (i = 0; i < (int) sizeof(scan_ie); i++) {
619 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
623 for (j = 2; j < rate_ie[1] + 2; j++) {
624 int flagged = !!(rate_ie[j] & 0x80);
625 int r = (rate_ie[j] & 0x7f) * 5;
628 * IEEE Std 802.11n-2009 7.3.2.2:
629 * The new BSS Membership selector value is encoded
630 * like a legacy basic rate, but it is not a rate and
631 * only indicates if the BSS members are required to
632 * support the mandatory features of Clause 20 [HT PHY]
633 * in order to join the BSS.
635 if (flagged && ((rate_ie[j] & 0x7f) ==
636 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
637 if (!ht_supported(mode)) {
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " hardware does not support "
646 /* There's also a VHT selector for 802.11ac */
647 if (flagged && ((rate_ie[j] & 0x7f) ==
648 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
649 if (!vht_supported(mode)) {
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " hardware does not support "
661 /* check for legacy basic rates */
662 for (k = 0; k < mode->num_rates; k++) {
663 if (mode->rates[k] == r)
666 if (k == mode->num_rates) {
668 * IEEE Std 802.11-2007 7.3.2.2 demands that in
669 * order to join a BSS all required rates
670 * have to be supported by the hardware.
672 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
673 "not support required rate %d.%d Mbps",
684 static int bss_is_dmg(struct wpa_bss *bss)
686 return bss->freq > 45000;
691 * Test whether BSS is in an ESS.
692 * This is done differently in DMG (60 GHz) and non-DMG bands
694 static int bss_is_ess(struct wpa_bss *bss)
696 if (bss_is_dmg(bss)) {
697 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
698 IEEE80211_CAP_DMG_AP;
701 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
706 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
707 int i, struct wpa_bss *bss,
708 struct wpa_ssid *group)
710 u8 wpa_ie_len, rsn_ie_len;
712 struct wpa_blacklist *e;
714 struct wpa_ssid *ssid;
716 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
717 wpa_ie_len = ie ? ie[1] : 0;
719 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
720 rsn_ie_len = ie ? ie[1] : 0;
722 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
723 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
724 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
725 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
726 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
728 e = wpa_blacklist_get(wpa_s, bss->bssid);
731 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
733 * When only a single network is enabled, we can
734 * trigger blacklisting on the first failure. This
735 * should not be done with multiple enabled networks to
736 * avoid getting forced to move into a worse ESS on
737 * single error if there are no other BSSes of the
742 if (e->count > limit) {
743 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
744 "(count=%d limit=%d)", e->count, limit);
749 if (bss->ssid_len == 0) {
750 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
754 if (disallowed_bssid(wpa_s, bss->bssid)) {
755 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
759 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
760 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
764 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
766 for (ssid = group; ssid; ssid = ssid->pnext) {
767 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
770 if (wpas_network_disabled(wpa_s, ssid)) {
771 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
775 res = wpas_temp_disabled(wpa_s, ssid);
777 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
778 "temporarily for %d second(s)", res);
783 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
784 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
789 if (wpa && ssid->ssid_len == 0 &&
790 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
793 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
794 /* Only allow wildcard SSID match if an AP
795 * advertises active WPS operation that matches
798 if (ssid->ssid_len == 0 &&
799 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
802 #endif /* CONFIG_WPS */
804 if (ssid->bssid_set && ssid->ssid_len == 0 &&
805 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
809 (bss->ssid_len != ssid->ssid_len ||
810 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
811 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
815 if (ssid->bssid_set &&
816 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
817 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
821 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
825 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
826 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
827 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
828 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
833 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
835 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
839 if (!wpa_supplicant_match_privacy(bss, ssid)) {
840 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
845 if (!bss_is_ess(bss)) {
846 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
850 if (!freq_allowed(ssid->freq_list, bss->freq)) {
851 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
856 if (!rate_match(wpa_s, bss)) {
857 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
864 * TODO: skip the AP if its P2P IE has Group Formation
865 * bit set in the P2P Group Capability Bitmap and we
866 * are not in Group Formation with that device.
868 #endif /* CONFIG_P2P */
870 /* Matching configuration found */
874 /* No matching configuration found */
879 static struct wpa_bss *
880 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
881 struct wpa_ssid *group,
882 struct wpa_ssid **selected_ssid)
886 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
889 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
890 struct wpa_bss *bss = wpa_s->last_scan_res[i];
891 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
894 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
897 wpa_ssid_txt(bss->ssid, bss->ssid_len));
905 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
906 struct wpa_ssid **selected_ssid)
908 struct wpa_bss *selected = NULL;
911 if (wpa_s->last_scan_res == NULL ||
912 wpa_s->last_scan_res_used == 0)
913 return NULL; /* no scan results from last update */
915 while (selected == NULL) {
916 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
917 selected = wpa_supplicant_select_bss(
918 wpa_s, wpa_s->conf->pssid[prio],
924 if (selected == NULL && wpa_s->blacklist &&
925 !wpa_s->countermeasures) {
926 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
927 "blacklist and try again");
928 wpa_blacklist_clear(wpa_s);
929 wpa_s->blacklist_cleared++;
930 } else if (selected == NULL)
938 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
939 int timeout_sec, int timeout_usec)
941 if (!wpa_supplicant_enabled_networks(wpa_s)) {
943 * No networks are enabled; short-circuit request so
944 * we don't wait timeout seconds before transitioning
947 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
948 "since there are no enabled networks");
949 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
951 wpa_s->sta_scan_pending = 0;
952 #endif /* CONFIG_P2P */
956 wpa_s->scan_for_connection = 1;
957 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
961 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
962 struct wpa_bss *selected,
963 struct wpa_ssid *ssid)
965 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
966 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
967 "PBC session overlap");
969 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
971 #endif /* CONFIG_P2P */
974 wpas_wps_cancel(wpa_s);
975 #endif /* CONFIG_WPS */
979 wpa_msg(wpa_s, MSG_DEBUG,
980 "Considering connect request: reassociate: %d selected: "
981 MACSTR " bssid: " MACSTR " pending: " MACSTR
982 " wpa_state: %s ssid=%p current_ssid=%p",
983 wpa_s->reassociate, MAC2STR(selected->bssid),
984 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
985 wpa_supplicant_state_txt(wpa_s->wpa_state),
986 ssid, wpa_s->current_ssid);
989 * Do not trigger new association unless the BSSID has changed or if
990 * reassociation is requested. If we are in process of associating with
991 * the selected BSSID, do not trigger new attempt.
993 if (wpa_s->reassociate ||
994 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
995 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
996 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
997 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
998 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1000 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1001 ssid != wpa_s->current_ssid)))) {
1002 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1003 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1006 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1007 MAC2STR(selected->bssid));
1008 wpa_supplicant_associate(wpa_s, selected, ssid);
1010 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1011 "connect with the selected AP");
1018 static struct wpa_ssid *
1019 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1022 struct wpa_ssid *ssid;
1024 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1025 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1027 if (wpas_network_disabled(wpa_s, ssid))
1029 if (ssid->mode == IEEE80211_MODE_IBSS ||
1030 ssid->mode == IEEE80211_MODE_AP)
1038 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1039 * on BSS added and BSS changed events */
1040 static void wpa_supplicant_rsn_preauth_scan_results(
1041 struct wpa_supplicant *wpa_s)
1043 struct wpa_bss *bss;
1045 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1048 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1049 const u8 *ssid, *rsn;
1051 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1055 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1059 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1065 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1066 struct wpa_bss *selected,
1067 struct wpa_ssid *ssid)
1069 struct wpa_bss *current_bss = NULL;
1072 if (wpa_s->reassociate)
1073 return 1; /* explicit request to reassociate */
1074 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1075 return 1; /* we are not associated; continue */
1076 if (wpa_s->current_ssid == NULL)
1077 return 1; /* unknown current SSID */
1078 if (wpa_s->current_ssid != ssid)
1079 return 1; /* different network block */
1081 if (wpas_driver_bss_selection(wpa_s))
1082 return 0; /* Driver-based roaming */
1084 if (wpa_s->current_ssid->ssid)
1085 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1086 wpa_s->current_ssid->ssid,
1087 wpa_s->current_ssid->ssid_len);
1089 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1092 return 1; /* current BSS not seen in scan results */
1094 if (current_bss == selected)
1097 if (selected->last_update_idx > current_bss->last_update_idx)
1098 return 1; /* current BSS not seen in the last scan */
1100 #ifndef CONFIG_NO_ROAMING
1101 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1102 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1103 MAC2STR(current_bss->bssid), current_bss->level);
1104 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1105 MAC2STR(selected->bssid), selected->level);
1107 if (wpa_s->current_ssid->bssid_set &&
1108 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1110 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1111 "has preferred BSSID");
1115 if (current_bss->level < 0 && current_bss->level > selected->level) {
1116 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1122 if (current_bss->level < 0) {
1123 if (current_bss->level < -85)
1125 else if (current_bss->level < -80)
1127 else if (current_bss->level < -75)
1129 else if (current_bss->level < -70)
1134 if (abs(current_bss->level - selected->level) < min_diff) {
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1141 #else /* CONFIG_NO_ROAMING */
1143 #endif /* CONFIG_NO_ROAMING */
1147 /* Return != 0 if no scan results could be fetched or if scan results should not
1148 * be shared with other virtual interfaces. */
1149 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1150 union wpa_event_data *data,
1153 struct wpa_scan_results *scan_res;
1155 #ifndef CONFIG_NO_RANDOM_POOL
1157 #endif /* CONFIG_NO_RANDOM_POOL */
1160 if (wpa_s->ap_iface)
1162 #endif /* CONFIG_AP */
1164 wpa_supplicant_notify_scanning(wpa_s, 0);
1167 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1168 !wpa_s->global->p2p_disabled &&
1169 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1170 !wpa_s->scan_res_handler) {
1171 wpa_s->global->p2p_cb_on_scan_complete = 0;
1172 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1173 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1174 "stopped scan processing");
1175 wpa_s->sta_scan_pending = 1;
1176 wpa_supplicant_req_scan(wpa_s, 5, 0);
1180 wpa_s->sta_scan_pending = 0;
1181 #endif /* CONFIG_P2P */
1183 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1184 data ? &data->scan_info :
1186 if (scan_res == NULL) {
1187 if (wpa_s->conf->ap_scan == 2 || ap ||
1188 wpa_s->scan_res_handler == scan_only_handler)
1192 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1194 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1198 #ifndef CONFIG_NO_RANDOM_POOL
1199 num = scan_res->num;
1202 for (i = 0; i < num; i++) {
1204 struct wpa_scan_res *res = scan_res->res[i];
1205 buf[0] = res->bssid[5];
1206 buf[1] = res->qual & 0xff;
1207 buf[2] = res->noise & 0xff;
1208 buf[3] = res->level & 0xff;
1209 buf[4] = res->tsf & 0xff;
1210 random_add_randomness(buf, sizeof(buf));
1212 #endif /* CONFIG_NO_RANDOM_POOL */
1214 if (own_request && wpa_s->scan_res_handler) {
1215 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1216 struct wpa_scan_results *scan_res);
1218 scan_res_handler = wpa_s->scan_res_handler;
1219 wpa_s->scan_res_handler = NULL;
1220 scan_res_handler(wpa_s, scan_res);
1222 wpa_scan_results_free(scan_res);
1227 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1229 if (wpa_s->ap_iface->scan_cb)
1230 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1231 #endif /* CONFIG_AP */
1232 wpa_scan_results_free(scan_res);
1236 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1237 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1238 wpas_notify_scan_results(wpa_s);
1240 wpas_notify_scan_done(wpa_s, 1);
1242 if (sme_proc_obss_scan(wpa_s) > 0) {
1243 wpa_scan_results_free(scan_res);
1247 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1248 wpa_scan_results_free(scan_res);
1252 if (autoscan_notify_scan(wpa_s, scan_res)) {
1253 wpa_scan_results_free(scan_res);
1257 if (wpa_s->disconnected) {
1258 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1259 wpa_scan_results_free(scan_res);
1263 if (!wpas_driver_bss_selection(wpa_s) &&
1264 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1265 wpa_scan_results_free(scan_res);
1269 wpas_wps_update_ap_info(wpa_s, scan_res);
1271 wpa_scan_results_free(scan_res);
1273 return wpas_select_network_from_last_scan(wpa_s, 1);
1277 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1280 struct wpa_bss *selected;
1281 struct wpa_ssid *ssid = NULL;
1283 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1287 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1290 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1294 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1295 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1299 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1301 * Do not notify other virtual radios of scan results since we do not
1302 * want them to start other associations at the same time.
1306 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1307 ssid = wpa_supplicant_pick_new_network(wpa_s);
1309 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1310 wpa_supplicant_associate(wpa_s, NULL, ssid);
1312 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1314 int timeout_sec = wpa_s->scan_interval;
1315 int timeout_usec = 0;
1317 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1320 if (wpa_s->p2p_in_provisioning) {
1322 * Use shorter wait during P2P Provisioning
1323 * state to speed up group formation.
1326 timeout_usec = 250000;
1327 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1331 #endif /* CONFIG_P2P */
1332 #ifdef CONFIG_INTERWORKING
1333 if (wpa_s->conf->auto_interworking &&
1334 wpa_s->conf->interworking &&
1335 wpa_s->conf->cred) {
1336 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1337 "start ANQP fetch since no matching "
1339 wpa_s->network_select = 1;
1340 wpa_s->auto_network_select = 1;
1341 interworking_start_fetch_anqp(wpa_s);
1344 #endif /* CONFIG_INTERWORKING */
1345 if (wpa_supplicant_req_sched_scan(wpa_s))
1346 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1354 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1355 union wpa_event_data *data)
1357 const char *rn, *rn2;
1358 struct wpa_supplicant *ifs;
1360 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1362 * If no scan results could be fetched, then no need to
1363 * notify those interfaces that did not actually request
1364 * this scan. Similarly, if scan results started a new operation on this
1365 * interface, do not notify other interfaces to avoid concurrent
1366 * operations during a connection attempt.
1372 * Check other interfaces to see if they have the same radio-name. If
1373 * so, they get updated with this same scan info.
1375 if (!wpa_s->driver->get_radio_name)
1378 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1379 if (rn == NULL || rn[0] == '\0')
1382 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1383 "sharing same radio (%s) in event_scan_results", rn);
1385 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1386 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1389 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1390 if (rn2 && os_strcmp(rn, rn2) == 0) {
1391 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1392 "sibling", ifs->ifname);
1393 _wpa_supplicant_event_scan_results(ifs, data, 0);
1398 #endif /* CONFIG_NO_SCAN_PROCESSING */
1401 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1403 #ifdef CONFIG_NO_SCAN_PROCESSING
1405 #else /* CONFIG_NO_SCAN_PROCESSING */
1408 if (wpa_s->last_scan_res_used <= 0)
1412 if (now.sec - wpa_s->last_scan.sec > 5) {
1413 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1417 return wpas_select_network_from_last_scan(wpa_s, 0);
1418 #endif /* CONFIG_NO_SCAN_PROCESSING */
1423 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1425 struct wpa_supplicant *wpa_s = eloop_ctx;
1427 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1430 if (!wpa_s->no_keep_alive) {
1431 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1432 MAC2STR(wpa_s->bssid));
1433 /* TODO: could skip this if normal data traffic has been sent */
1434 /* TODO: Consider using some more appropriate data frame for
1437 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1442 if (wpa_s->sme.bss_max_idle_period) {
1444 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1447 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1448 wnm_bss_keep_alive, wpa_s, NULL);
1450 #endif /* CONFIG_SME */
1454 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1455 const u8 *ies, size_t ies_len)
1457 struct ieee802_11_elems elems;
1462 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1466 if (elems.bss_max_idle_period) {
1468 wpa_s->sme.bss_max_idle_period =
1469 WPA_GET_LE16(elems.bss_max_idle_period);
1470 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1471 "TU)%s", wpa_s->sme.bss_max_idle_period,
1472 (elems.bss_max_idle_period[2] & 0x01) ?
1473 " (protected keep-live required)" : "");
1474 if (wpa_s->sme.bss_max_idle_period == 0)
1475 wpa_s->sme.bss_max_idle_period = 1;
1476 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1477 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1478 /* msec times 1000 */
1479 msec = wpa_s->sme.bss_max_idle_period * 1024;
1482 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1483 wnm_bss_keep_alive, wpa_s,
1487 #endif /* CONFIG_SME */
1490 #endif /* CONFIG_WNM */
1493 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1496 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1497 #endif /* CONFIG_WNM */
1501 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1502 union wpa_event_data *data)
1504 int l, len, found = 0, wpa_found, rsn_found;
1506 #ifdef CONFIG_IEEE80211R
1508 #endif /* CONFIG_IEEE80211R */
1510 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1511 if (data->assoc_info.req_ies)
1512 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1513 data->assoc_info.req_ies_len);
1514 if (data->assoc_info.resp_ies) {
1515 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1516 data->assoc_info.resp_ies_len);
1518 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1519 data->assoc_info.resp_ies_len);
1520 #endif /* CONFIG_TDLS */
1522 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1523 data->assoc_info.resp_ies_len);
1524 #endif /* CONFIG_WNM */
1526 if (data->assoc_info.beacon_ies)
1527 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1528 data->assoc_info.beacon_ies,
1529 data->assoc_info.beacon_ies_len);
1530 if (data->assoc_info.freq)
1531 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1532 data->assoc_info.freq);
1534 p = data->assoc_info.req_ies;
1535 l = data->assoc_info.req_ies_len;
1537 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1538 while (p && l >= 2) {
1541 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1545 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1546 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1547 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1548 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1551 wpa_find_assoc_pmkid(wpa_s);
1557 if (!found && data->assoc_info.req_ies)
1558 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1560 #ifdef CONFIG_IEEE80211R
1562 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1563 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1564 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1565 data->assoc_info.resp_ies,
1566 data->assoc_info.resp_ies_len,
1568 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1569 "Reassociation Response failed");
1570 wpa_supplicant_deauthenticate(
1571 wpa_s, WLAN_REASON_INVALID_IE);
1576 p = data->assoc_info.resp_ies;
1577 l = data->assoc_info.resp_ies_len;
1579 #ifdef CONFIG_WPS_STRICT
1580 if (p && wpa_s->current_ssid &&
1581 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1583 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1585 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1586 "include WPS IE in (Re)Association Response");
1590 if (wps_validate_assoc_resp(wps) < 0) {
1592 wpa_supplicant_deauthenticate(
1593 wpa_s, WLAN_REASON_INVALID_IE);
1598 #endif /* CONFIG_WPS_STRICT */
1600 /* Go through the IEs and make a copy of the MDIE, if present. */
1601 while (p && l >= 2) {
1604 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1608 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1609 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1610 wpa_s->sme.ft_used = 1;
1611 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1612 MOBILITY_DOMAIN_ID_LEN);
1618 #endif /* CONFIG_SME */
1620 /* Process FT when SME is in the driver */
1621 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1622 wpa_ft_is_completed(wpa_s->wpa)) {
1623 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1624 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1625 data->assoc_info.resp_ies,
1626 data->assoc_info.resp_ies_len,
1628 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1629 "Reassociation Response failed");
1630 wpa_supplicant_deauthenticate(
1631 wpa_s, WLAN_REASON_INVALID_IE);
1634 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1637 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1638 data->assoc_info.resp_ies_len);
1639 #endif /* CONFIG_IEEE80211R */
1641 /* WPA/RSN IE from Beacon/ProbeResp */
1642 p = data->assoc_info.beacon_ies;
1643 l = data->assoc_info.beacon_ies_len;
1645 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1647 wpa_found = rsn_found = 0;
1648 while (p && l >= 2) {
1651 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1656 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1657 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1659 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1663 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1665 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1672 if (!wpa_found && data->assoc_info.beacon_ies)
1673 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1674 if (!rsn_found && data->assoc_info.beacon_ies)
1675 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1676 if (wpa_found || rsn_found)
1677 wpa_s->ap_ies_from_associnfo = 1;
1679 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1680 wpa_s->assoc_freq != data->assoc_info.freq) {
1681 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1683 wpa_s->assoc_freq, data->assoc_info.freq);
1684 wpa_supplicant_update_scan_results(wpa_s);
1687 wpa_s->assoc_freq = data->assoc_info.freq;
1693 static struct wpa_bss * wpa_supplicant_get_new_bss(
1694 struct wpa_supplicant *wpa_s, const u8 *bssid)
1696 struct wpa_bss *bss = NULL;
1697 struct wpa_ssid *ssid = wpa_s->current_ssid;
1699 if (ssid->ssid_len > 0)
1700 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1702 bss = wpa_bss_get_bssid(wpa_s, bssid);
1708 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1710 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1712 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1715 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1718 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1719 WPA_IE_VENDOR_TYPE);
1720 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1722 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1723 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1724 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1725 bss_rsn ? 2 + bss_rsn[1] : 0))
1732 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1733 union wpa_event_data *data)
1739 if (wpa_s->ap_iface) {
1740 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1741 data->assoc_info.addr,
1742 data->assoc_info.req_ies,
1743 data->assoc_info.req_ies_len,
1744 data->assoc_info.reassoc);
1747 #endif /* CONFIG_AP */
1749 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1750 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1753 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1754 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1755 wpa_supplicant_deauthenticate(
1756 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1760 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1761 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1762 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1763 MACSTR, MAC2STR(bssid));
1764 random_add_randomness(bssid, ETH_ALEN);
1765 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1766 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1767 wpas_notify_bssid_changed(wpa_s);
1769 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1770 wpa_clear_keys(wpa_s, bssid);
1772 if (wpa_supplicant_select_config(wpa_s) < 0) {
1773 wpa_supplicant_deauthenticate(
1774 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1777 if (wpa_s->current_ssid) {
1778 struct wpa_bss *bss = NULL;
1780 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1782 wpa_supplicant_update_scan_results(wpa_s);
1784 /* Get the BSS from the new scan results */
1785 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1789 wpa_s->current_bss = bss;
1792 if (wpa_s->conf->ap_scan == 1 &&
1793 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1794 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1795 wpa_msg(wpa_s, MSG_WARNING,
1796 "WPA/RSN IEs not updated");
1801 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1802 wpa_s->sme.prev_bssid_set = 1;
1803 #endif /* CONFIG_SME */
1805 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1806 if (wpa_s->current_ssid) {
1807 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1808 * initialized before association, but for other modes,
1809 * initialize PC/SC here, if the current configuration needs
1810 * smartcard or SIM/USIM. */
1811 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1813 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1815 l2_packet_notify_auth_start(wpa_s->l2);
1818 * Set portEnabled first to FALSE in order to get EAP state machine out
1819 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1820 * state machine may transit to AUTHENTICATING state based on obsolete
1821 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1822 * AUTHENTICATED without ever giving chance to EAP state machine to
1825 if (!ft_completed) {
1826 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1827 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1829 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1830 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1831 /* 802.1X::portControl = Auto */
1832 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1833 wpa_s->eapol_received = 0;
1834 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1835 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1836 (wpa_s->current_ssid &&
1837 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1838 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1840 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1842 * Set the key after having received joined-IBSS event
1845 wpa_supplicant_set_wpa_none_key(wpa_s,
1846 wpa_s->current_ssid);
1848 wpa_supplicant_cancel_auth_timeout(wpa_s);
1849 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1850 } else if (!ft_completed) {
1851 /* Timeout for receiving the first EAPOL packet */
1852 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1854 wpa_supplicant_cancel_scan(wpa_s);
1856 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1857 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1859 * We are done; the driver will take care of RSN 4-way
1862 wpa_supplicant_cancel_auth_timeout(wpa_s);
1863 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1864 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1865 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1866 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1867 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1869 * The driver will take care of RSN 4-way handshake, so we need
1870 * to allow EAPOL supplicant to complete its work without
1871 * waiting for WPA supplicant.
1873 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1874 } else if (ft_completed) {
1876 * FT protocol completed - make sure EAPOL state machine ends
1877 * up in authenticated.
1879 wpa_supplicant_cancel_auth_timeout(wpa_s);
1880 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1881 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1882 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1885 wpa_s->last_eapol_matches_bssid = 0;
1887 if (wpa_s->pending_eapol_rx) {
1888 struct os_time now, age;
1890 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1891 if (age.sec == 0 && age.usec < 100000 &&
1892 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1894 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1895 "frame that was received just before "
1896 "association notification");
1897 wpa_supplicant_rx_eapol(
1898 wpa_s, wpa_s->pending_eapol_rx_src,
1899 wpabuf_head(wpa_s->pending_eapol_rx),
1900 wpabuf_len(wpa_s->pending_eapol_rx));
1902 wpabuf_free(wpa_s->pending_eapol_rx);
1903 wpa_s->pending_eapol_rx = NULL;
1906 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1907 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1908 wpa_s->current_ssid &&
1909 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1910 /* Set static WEP keys again */
1911 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1914 #ifdef CONFIG_IBSS_RSN
1915 if (wpa_s->current_ssid &&
1916 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1917 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1918 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1919 wpa_s->ibss_rsn == NULL) {
1920 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1921 if (!wpa_s->ibss_rsn) {
1922 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1923 wpa_supplicant_deauthenticate(
1924 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1928 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1930 #endif /* CONFIG_IBSS_RSN */
1932 wpas_wps_notify_assoc(wpa_s, bssid);
1936 static int disconnect_reason_recoverable(u16 reason_code)
1938 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1939 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1940 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1944 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1946 int locally_generated)
1950 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1952 * At least Host AP driver and a Prism3 card seemed to be
1953 * generating streams of disconnected events when configuring
1954 * IBSS for WPA-None. Ignore them for now.
1959 bssid = wpa_s->bssid;
1960 if (is_zero_ether_addr(bssid))
1961 bssid = wpa_s->pending_bssid;
1963 if (!is_zero_ether_addr(bssid) ||
1964 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1965 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1967 MAC2STR(bssid), reason_code,
1968 locally_generated ? " locally_generated=1" : "");
1973 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1974 int locally_generated)
1976 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1977 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1978 return 0; /* Not in 4-way handshake with PSK */
1981 * It looks like connection was lost while trying to go through PSK
1982 * 4-way handshake. Filter out known disconnection cases that are caused
1983 * by something else than PSK mismatch to avoid confusing reports.
1986 if (locally_generated) {
1987 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1995 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1997 int locally_generated)
2001 u8 prev_pending_bssid[ETH_ALEN];
2002 struct wpa_bss *fast_reconnect = NULL;
2003 #ifndef CONFIG_NO_SCAN_PROCESSING
2004 struct wpa_ssid *fast_reconnect_ssid = NULL;
2005 #endif /* CONFIG_NO_SCAN_PROCESSING */
2006 struct wpa_ssid *last_ssid;
2008 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2009 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2011 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2013 * At least Host AP driver and a Prism3 card seemed to be
2014 * generating streams of disconnected events when configuring
2015 * IBSS for WPA-None. Ignore them for now.
2017 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2018 "IBSS/WPA-None mode");
2022 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2023 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2024 "pre-shared key may be incorrect");
2025 wpas_auth_failed(wpa_s);
2027 if (!wpa_s->disconnected &&
2028 (!wpa_s->auto_reconnect_disabled ||
2029 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
2030 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2031 "reconnect (wps=%d wpa_state=%d)",
2032 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2034 if (wpa_s->wpa_state == WPA_COMPLETED &&
2035 wpa_s->current_ssid &&
2036 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2037 !locally_generated &&
2038 disconnect_reason_recoverable(reason_code)) {
2040 * It looks like the AP has dropped association with
2041 * us, but could allow us to get back in. Try to
2042 * reconnect to the same BSS without full scan to save
2043 * time for some common cases.
2045 fast_reconnect = wpa_s->current_bss;
2046 #ifndef CONFIG_NO_SCAN_PROCESSING
2047 fast_reconnect_ssid = wpa_s->current_ssid;
2048 #endif /* CONFIG_NO_SCAN_PROCESSING */
2049 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2050 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2052 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2055 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2056 "try to re-connect");
2057 wpa_s->reassociate = 0;
2058 wpa_s->disconnected = 1;
2059 wpa_supplicant_cancel_sched_scan(wpa_s);
2061 bssid = wpa_s->bssid;
2062 if (is_zero_ether_addr(bssid))
2063 bssid = wpa_s->pending_bssid;
2064 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2065 wpas_connection_failed(wpa_s, bssid);
2066 wpa_sm_notify_disassoc(wpa_s->wpa);
2067 if (locally_generated)
2068 wpa_s->disconnect_reason = -reason_code;
2070 wpa_s->disconnect_reason = reason_code;
2071 wpas_notify_disconnect_reason(wpa_s);
2072 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2073 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2074 wpa_s->keys_cleared = 0;
2075 wpa_clear_keys(wpa_s, wpa_s->bssid);
2077 last_ssid = wpa_s->current_ssid;
2078 wpa_supplicant_mark_disassoc(wpa_s);
2080 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2081 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2082 wpa_s->current_ssid = last_ssid;
2085 if (fast_reconnect) {
2086 #ifndef CONFIG_NO_SCAN_PROCESSING
2087 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2088 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2089 fast_reconnect_ssid) < 0) {
2090 /* Recover through full scan */
2091 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2093 #endif /* CONFIG_NO_SCAN_PROCESSING */
2098 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2099 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2101 struct wpa_supplicant *wpa_s = eloop_ctx;
2103 if (!wpa_s->pending_mic_error_report)
2106 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2107 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2108 wpa_s->pending_mic_error_report = 0;
2110 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2114 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2115 union wpa_event_data *data)
2120 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2121 pairwise = (data && data->michael_mic_failure.unicast);
2123 if ((wpa_s->last_michael_mic_error &&
2124 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2125 wpa_s->pending_mic_error_report) {
2126 if (wpa_s->pending_mic_error_report) {
2128 * Send the pending MIC error report immediately since
2129 * we are going to start countermeasures and AP better
2132 wpa_sm_key_request(wpa_s->wpa, 1,
2133 wpa_s->pending_mic_error_pairwise);
2136 /* Send the new MIC error report immediately since we are going
2137 * to start countermeasures and AP better do the same.
2139 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2141 /* initialize countermeasures */
2142 wpa_s->countermeasures = 1;
2144 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2146 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2149 * Need to wait for completion of request frame. We do not get
2150 * any callback for the message completion, so just wait a
2151 * short while and hope for the best. */
2154 wpa_drv_set_countermeasures(wpa_s, 1);
2155 wpa_supplicant_deauthenticate(wpa_s,
2156 WLAN_REASON_MICHAEL_MIC_FAILURE);
2157 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2159 eloop_register_timeout(60, 0,
2160 wpa_supplicant_stop_countermeasures,
2162 /* TODO: mark the AP rejected for 60 second. STA is
2163 * allowed to associate with another AP.. */
2165 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2166 if (wpa_s->mic_errors_seen) {
2168 * Reduce the effectiveness of Michael MIC error
2169 * reports as a means for attacking against TKIP if
2170 * more than one MIC failure is noticed with the same
2171 * PTK. We delay the transmission of the reports by a
2172 * random time between 0 and 60 seconds in order to
2173 * force the attacker wait 60 seconds before getting
2174 * the information on whether a frame resulted in a MIC
2180 if (os_get_random(rval, sizeof(rval)) < 0)
2181 sec = os_random() % 60;
2183 sec = WPA_GET_BE32(rval) % 60;
2184 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2185 "report %d seconds", sec);
2186 wpa_s->pending_mic_error_report = 1;
2187 wpa_s->pending_mic_error_pairwise = pairwise;
2188 eloop_cancel_timeout(
2189 wpa_supplicant_delayed_mic_error_report,
2191 eloop_register_timeout(
2192 sec, os_random() % 1000000,
2193 wpa_supplicant_delayed_mic_error_report,
2196 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2198 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2199 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2200 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2202 wpa_s->last_michael_mic_error = t.sec;
2203 wpa_s->mic_errors_seen++;
2207 #ifdef CONFIG_TERMINATE_ONLASTIF
2208 static int any_interfaces(struct wpa_supplicant *head)
2210 struct wpa_supplicant *wpa_s;
2212 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2213 if (!wpa_s->interface_removed)
2217 #endif /* CONFIG_TERMINATE_ONLASTIF */
2221 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2222 union wpa_event_data *data)
2224 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2227 switch (data->interface_status.ievent) {
2228 case EVENT_INTERFACE_ADDED:
2229 if (!wpa_s->interface_removed)
2231 wpa_s->interface_removed = 0;
2232 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2233 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2234 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2235 "driver after interface was added");
2237 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2239 case EVENT_INTERFACE_REMOVED:
2240 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2241 wpa_s->interface_removed = 1;
2242 wpa_supplicant_mark_disassoc(wpa_s);
2243 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2244 l2_packet_deinit(wpa_s->l2);
2246 #ifdef CONFIG_IBSS_RSN
2247 ibss_rsn_deinit(wpa_s->ibss_rsn);
2248 wpa_s->ibss_rsn = NULL;
2249 #endif /* CONFIG_IBSS_RSN */
2250 #ifdef CONFIG_TERMINATE_ONLASTIF
2251 /* check if last interface */
2252 if (!any_interfaces(wpa_s->global->ifaces))
2254 #endif /* CONFIG_TERMINATE_ONLASTIF */
2260 #ifdef CONFIG_PEERKEY
2262 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2263 union wpa_event_data *data)
2267 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2269 #endif /* CONFIG_PEERKEY */
2273 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2274 union wpa_event_data *data)
2278 switch (data->tdls.oper) {
2279 case TDLS_REQUEST_SETUP:
2280 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2281 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2282 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2284 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2286 case TDLS_REQUEST_TEARDOWN:
2287 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2288 data->tdls.reason_code);
2292 #endif /* CONFIG_TDLS */
2296 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2297 union wpa_event_data *data)
2301 switch (data->wnm.oper) {
2302 case WNM_OPER_SLEEP:
2303 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2304 "(action=%d, intval=%d)",
2305 data->wnm.sleep_action, data->wnm.sleep_intval);
2306 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2307 data->wnm.sleep_intval, NULL);
2311 #endif /* CONFIG_WNM */
2314 #ifdef CONFIG_IEEE80211R
2316 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2317 union wpa_event_data *data)
2322 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2323 data->ft_ies.ies_len,
2324 data->ft_ies.ft_action,
2325 data->ft_ies.target_ap,
2326 data->ft_ies.ric_ies,
2327 data->ft_ies.ric_ies_len) < 0) {
2328 /* TODO: prevent MLME/driver from trying to associate? */
2331 #endif /* CONFIG_IEEE80211R */
2334 #ifdef CONFIG_IBSS_RSN
2335 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2336 union wpa_event_data *data)
2338 struct wpa_ssid *ssid;
2339 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2343 ssid = wpa_s->current_ssid;
2346 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2349 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2353 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2354 union wpa_event_data *data)
2356 struct wpa_ssid *ssid = wpa_s->current_ssid;
2361 /* check if the ssid is correctly configured as IBSS/RSN */
2362 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2365 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2366 data->rx_mgmt.frame_len);
2368 #endif /* CONFIG_IBSS_RSN */
2371 #ifdef CONFIG_IEEE80211R
2372 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2375 const u8 *sta_addr, *target_ap_addr;
2378 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2379 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2380 return; /* only SME case supported for now */
2381 if (len < 1 + 2 * ETH_ALEN + 2)
2384 return; /* Only FT Action Response is supported for now */
2385 sta_addr = data + 1;
2386 target_ap_addr = data + 1 + ETH_ALEN;
2387 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2388 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2389 MACSTR " TargetAP " MACSTR " status %u",
2390 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2392 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2393 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2394 " in FT Action Response", MAC2STR(sta_addr));
2399 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2400 "failure (status code %d)", status);
2401 /* TODO: report error to FT code(?) */
2405 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2406 len - (1 + 2 * ETH_ALEN + 2), 1,
2407 target_ap_addr, NULL, 0) < 0)
2412 struct wpa_bss *bss;
2413 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2415 wpa_s->sme.freq = bss->freq;
2416 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2417 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2420 #endif /* CONFIG_SME */
2422 #endif /* CONFIG_IEEE80211R */
2425 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2426 struct unprot_deauth *e)
2428 #ifdef CONFIG_IEEE80211W
2429 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2430 "dropped: " MACSTR " -> " MACSTR
2431 " (reason code %u)",
2432 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2433 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2434 #endif /* CONFIG_IEEE80211W */
2438 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2439 struct unprot_disassoc *e)
2441 #ifdef CONFIG_IEEE80211W
2442 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2443 "dropped: " MACSTR " -> " MACSTR
2444 " (reason code %u)",
2445 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2446 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2447 #endif /* CONFIG_IEEE80211W */
2451 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2452 u16 reason_code, int locally_generated,
2453 const u8 *ie, size_t ie_len, int deauth)
2456 if (wpa_s->ap_iface && addr) {
2457 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2461 if (wpa_s->ap_iface) {
2462 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2465 #endif /* CONFIG_AP */
2467 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2469 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2470 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2471 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2472 eapol_sm_failed(wpa_s->eapol)))
2473 wpas_auth_failed(wpa_s);
2476 if (deauth && reason_code > 0) {
2477 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2478 locally_generated) > 0) {
2480 * The interface was removed, so cannot continue
2481 * processing any additional operations after this.
2486 #endif /* CONFIG_P2P */
2488 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2493 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2494 struct disassoc_info *info)
2496 u16 reason_code = 0;
2497 int locally_generated = 0;
2498 const u8 *addr = NULL;
2499 const u8 *ie = NULL;
2502 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2507 ie_len = info->ie_len;
2508 reason_code = info->reason_code;
2509 locally_generated = info->locally_generated;
2510 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2511 locally_generated ? " (locally generated)" : "");
2513 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2515 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2520 if (wpa_s->ap_iface && info && info->addr) {
2521 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2525 if (wpa_s->ap_iface) {
2526 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2529 #endif /* CONFIG_AP */
2533 wpas_p2p_disassoc_notif(
2534 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2537 #endif /* CONFIG_P2P */
2539 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2540 sme_event_disassoc(wpa_s, info);
2542 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2547 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2548 struct deauth_info *info)
2550 u16 reason_code = 0;
2551 int locally_generated = 0;
2552 const u8 *addr = NULL;
2553 const u8 *ie = NULL;
2556 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2561 ie_len = info->ie_len;
2562 reason_code = info->reason_code;
2563 locally_generated = info->locally_generated;
2564 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2566 locally_generated ? " (locally generated)" : "");
2568 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2571 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2575 wpa_reset_ft_completed(wpa_s->wpa);
2577 wpas_event_disconnect(wpa_s, addr, reason_code,
2578 locally_generated, ie, ie_len, 1);
2582 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2583 union wpa_event_data *data)
2585 struct wpa_supplicant *wpa_s = ctx;
2587 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2588 event != EVENT_INTERFACE_ENABLED &&
2589 event != EVENT_INTERFACE_STATUS &&
2590 event != EVENT_SCHED_SCAN_STOPPED) {
2591 wpa_dbg(wpa_s, MSG_DEBUG,
2592 "Ignore event %s (%d) while interface is disabled",
2593 event_to_string(event), event);
2597 #ifndef CONFIG_NO_STDOUT_DEBUG
2599 int level = MSG_DEBUG;
2601 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2602 const struct ieee80211_hdr *hdr;
2604 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2605 fc = le_to_host16(hdr->frame_control);
2606 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2607 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2608 level = MSG_EXCESSIVE;
2611 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2612 event_to_string(event), event);
2614 #endif /* CONFIG_NO_STDOUT_DEBUG */
2618 sme_event_auth(wpa_s, data);
2621 wpa_supplicant_event_assoc(wpa_s, data);
2623 case EVENT_DISASSOC:
2624 wpas_event_disassoc(wpa_s,
2625 data ? &data->disassoc_info : NULL);
2628 wpas_event_deauth(wpa_s,
2629 data ? &data->deauth_info : NULL);
2631 case EVENT_MICHAEL_MIC_FAILURE:
2632 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2634 #ifndef CONFIG_NO_SCAN_PROCESSING
2635 case EVENT_SCAN_RESULTS:
2636 wpa_supplicant_event_scan_results(wpa_s, data);
2637 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2638 wpa_s->wpa_state != WPA_ASSOCIATING)
2639 wpas_p2p_continue_after_scan(wpa_s);
2641 #endif /* CONFIG_NO_SCAN_PROCESSING */
2642 case EVENT_ASSOCINFO:
2643 wpa_supplicant_event_associnfo(wpa_s, data);
2645 case EVENT_INTERFACE_STATUS:
2646 wpa_supplicant_event_interface_status(wpa_s, data);
2648 case EVENT_PMKID_CANDIDATE:
2649 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2651 #ifdef CONFIG_PEERKEY
2652 case EVENT_STKSTART:
2653 wpa_supplicant_event_stkstart(wpa_s, data);
2655 #endif /* CONFIG_PEERKEY */
2658 wpa_supplicant_event_tdls(wpa_s, data);
2660 #endif /* CONFIG_TDLS */
2663 wpa_supplicant_event_wnm(wpa_s, data);
2665 #endif /* CONFIG_WNM */
2666 #ifdef CONFIG_IEEE80211R
2667 case EVENT_FT_RESPONSE:
2668 wpa_supplicant_event_ft_response(wpa_s, data);
2670 #endif /* CONFIG_IEEE80211R */
2671 #ifdef CONFIG_IBSS_RSN
2672 case EVENT_IBSS_RSN_START:
2673 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2675 #endif /* CONFIG_IBSS_RSN */
2676 case EVENT_ASSOC_REJECT:
2677 if (data->assoc_reject.bssid)
2678 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2679 "bssid=" MACSTR " status_code=%u",
2680 MAC2STR(data->assoc_reject.bssid),
2681 data->assoc_reject.status_code);
2683 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2685 data->assoc_reject.status_code);
2686 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2687 sme_event_assoc_reject(wpa_s, data);
2689 const u8 *bssid = data->assoc_reject.bssid;
2690 if (bssid == NULL || is_zero_ether_addr(bssid))
2691 bssid = wpa_s->pending_bssid;
2692 wpas_connection_failed(wpa_s, bssid);
2693 wpa_supplicant_mark_disassoc(wpa_s);
2696 case EVENT_AUTH_TIMED_OUT:
2697 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2698 sme_event_auth_timed_out(wpa_s, data);
2700 case EVENT_ASSOC_TIMED_OUT:
2701 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2702 sme_event_assoc_timed_out(wpa_s, data);
2704 case EVENT_TX_STATUS:
2705 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2706 " type=%d stype=%d",
2707 MAC2STR(data->tx_status.dst),
2708 data->tx_status.type, data->tx_status.stype);
2710 if (wpa_s->ap_iface == NULL) {
2711 #ifdef CONFIG_OFFCHANNEL
2712 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2713 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2714 offchannel_send_action_tx_status(
2715 wpa_s, data->tx_status.dst,
2716 data->tx_status.data,
2717 data->tx_status.data_len,
2718 data->tx_status.ack ?
2719 OFFCHANNEL_SEND_ACTION_SUCCESS :
2720 OFFCHANNEL_SEND_ACTION_NO_ACK);
2721 #endif /* CONFIG_OFFCHANNEL */
2724 #endif /* CONFIG_AP */
2725 #ifdef CONFIG_OFFCHANNEL
2726 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2727 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2729 * Catch TX status events for Action frames we sent via group
2730 * interface in GO mode.
2732 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2733 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2734 os_memcmp(wpa_s->parent->pending_action_dst,
2735 data->tx_status.dst, ETH_ALEN) == 0) {
2736 offchannel_send_action_tx_status(
2737 wpa_s->parent, data->tx_status.dst,
2738 data->tx_status.data,
2739 data->tx_status.data_len,
2740 data->tx_status.ack ?
2741 OFFCHANNEL_SEND_ACTION_SUCCESS :
2742 OFFCHANNEL_SEND_ACTION_NO_ACK);
2745 #endif /* CONFIG_OFFCHANNEL */
2747 switch (data->tx_status.type) {
2748 case WLAN_FC_TYPE_MGMT:
2749 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2750 data->tx_status.data_len,
2751 data->tx_status.stype,
2752 data->tx_status.ack);
2754 case WLAN_FC_TYPE_DATA:
2755 ap_tx_status(wpa_s, data->tx_status.dst,
2756 data->tx_status.data,
2757 data->tx_status.data_len,
2758 data->tx_status.ack);
2761 #endif /* CONFIG_AP */
2764 case EVENT_EAPOL_TX_STATUS:
2765 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2766 data->eapol_tx_status.data,
2767 data->eapol_tx_status.data_len,
2768 data->eapol_tx_status.ack);
2770 case EVENT_DRIVER_CLIENT_POLL_OK:
2771 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2773 case EVENT_RX_FROM_UNKNOWN:
2774 if (wpa_s->ap_iface == NULL)
2776 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2777 data->rx_from_unknown.wds);
2779 case EVENT_CH_SWITCH:
2782 if (!wpa_s->ap_iface) {
2783 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2784 "event in non-AP mode");
2788 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2789 data->ch_switch.ht_enabled,
2790 data->ch_switch.ch_offset);
2792 #endif /* CONFIG_AP */
2793 #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
2794 case EVENT_RX_MGMT: {
2796 const struct ieee80211_mgmt *mgmt;
2798 mgmt = (const struct ieee80211_mgmt *)
2799 data->rx_mgmt.frame;
2800 fc = le_to_host16(mgmt->frame_control);
2801 stype = WLAN_FC_GET_STYPE(fc);
2804 if (wpa_s->ap_iface == NULL) {
2805 #endif /* CONFIG_AP */
2807 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2808 data->rx_mgmt.frame_len > 24) {
2809 const u8 *src = mgmt->sa;
2810 const u8 *ie = mgmt->u.probe_req.variable;
2811 size_t ie_len = data->rx_mgmt.frame_len -
2812 (mgmt->u.probe_req.variable -
2813 data->rx_mgmt.frame);
2814 wpas_p2p_probe_req_rx(
2815 wpa_s, src, mgmt->da,
2816 mgmt->bssid, ie, ie_len,
2817 data->rx_mgmt.ssi_signal);
2820 #endif /* CONFIG_P2P */
2821 #ifdef CONFIG_IBSS_RSN
2822 if (stype == WLAN_FC_STYPE_AUTH &&
2823 data->rx_mgmt.frame_len >= 30) {
2824 wpa_supplicant_event_ibss_auth(wpa_s, data);
2827 #endif /* CONFIG_IBSS_RSN */
2828 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2829 "management frame in non-AP mode");
2834 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2835 data->rx_mgmt.frame_len > 24) {
2836 const u8 *ie = mgmt->u.probe_req.variable;
2837 size_t ie_len = data->rx_mgmt.frame_len -
2838 (mgmt->u.probe_req.variable -
2839 data->rx_mgmt.frame);
2841 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2842 mgmt->bssid, ie, ie_len,
2843 data->rx_mgmt.ssi_signal);
2846 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2847 #endif /* CONFIG_AP */
2850 #endif /* CONFIG_AP || CONFIG_IBSS_RSN */
2851 case EVENT_RX_ACTION:
2852 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2853 " Category=%u DataLen=%d freq=%d MHz",
2854 MAC2STR(data->rx_action.sa),
2855 data->rx_action.category, (int) data->rx_action.len,
2856 data->rx_action.freq);
2857 #ifdef CONFIG_IEEE80211R
2858 if (data->rx_action.category == WLAN_ACTION_FT) {
2859 ft_rx_action(wpa_s, data->rx_action.data,
2860 data->rx_action.len);
2863 #endif /* CONFIG_IEEE80211R */
2864 #ifdef CONFIG_IEEE80211W
2866 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2867 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2868 data->rx_action.data,
2869 data->rx_action.len);
2872 #endif /* CONFIG_SME */
2873 #endif /* CONFIG_IEEE80211W */
2875 if (data->rx_action.category == WLAN_ACTION_WNM) {
2876 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2879 #endif /* CONFIG_WNM */
2881 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2882 gas_query_rx(wpa_s->gas, data->rx_action.da,
2883 data->rx_action.sa, data->rx_action.bssid,
2884 data->rx_action.data, data->rx_action.len,
2885 data->rx_action.freq) == 0)
2887 #endif /* CONFIG_GAS */
2889 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2890 data->rx_action.len >= 4 &&
2891 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2892 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2893 "Response from " MACSTR,
2894 MAC2STR(data->rx_action.sa));
2897 #endif /* CONFIG_TDLS */
2899 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2901 data->rx_action.bssid,
2902 data->rx_action.category,
2903 data->rx_action.data,
2904 data->rx_action.len, data->rx_action.freq);
2905 #endif /* CONFIG_P2P */
2907 case EVENT_RX_PROBE_REQ:
2908 if (data->rx_probe_req.sa == NULL ||
2909 data->rx_probe_req.ie == NULL)
2912 if (wpa_s->ap_iface) {
2913 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2914 data->rx_probe_req.sa,
2915 data->rx_probe_req.da,
2916 data->rx_probe_req.bssid,
2917 data->rx_probe_req.ie,
2918 data->rx_probe_req.ie_len,
2919 data->rx_probe_req.ssi_signal);
2922 #endif /* CONFIG_AP */
2924 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2925 data->rx_probe_req.da,
2926 data->rx_probe_req.bssid,
2927 data->rx_probe_req.ie,
2928 data->rx_probe_req.ie_len,
2929 data->rx_probe_req.ssi_signal);
2930 #endif /* CONFIG_P2P */
2932 case EVENT_REMAIN_ON_CHANNEL:
2933 #ifdef CONFIG_OFFCHANNEL
2934 offchannel_remain_on_channel_cb(
2935 wpa_s, data->remain_on_channel.freq,
2936 data->remain_on_channel.duration);
2937 #endif /* CONFIG_OFFCHANNEL */
2939 wpas_p2p_remain_on_channel_cb(
2940 wpa_s, data->remain_on_channel.freq,
2941 data->remain_on_channel.duration);
2942 #endif /* CONFIG_P2P */
2944 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2945 #ifdef CONFIG_OFFCHANNEL
2946 offchannel_cancel_remain_on_channel_cb(
2947 wpa_s, data->remain_on_channel.freq);
2948 #endif /* CONFIG_OFFCHANNEL */
2950 wpas_p2p_cancel_remain_on_channel_cb(
2951 wpa_s, data->remain_on_channel.freq);
2952 #endif /* CONFIG_P2P */
2955 case EVENT_P2P_DEV_FOUND: {
2956 struct p2p_peer_info peer_info;
2958 os_memset(&peer_info, 0, sizeof(peer_info));
2959 if (data->p2p_dev_found.dev_addr)
2960 os_memcpy(peer_info.p2p_device_addr,
2961 data->p2p_dev_found.dev_addr, ETH_ALEN);
2962 if (data->p2p_dev_found.pri_dev_type)
2963 os_memcpy(peer_info.pri_dev_type,
2964 data->p2p_dev_found.pri_dev_type,
2965 sizeof(peer_info.pri_dev_type));
2966 if (data->p2p_dev_found.dev_name)
2967 os_strlcpy(peer_info.device_name,
2968 data->p2p_dev_found.dev_name,
2969 sizeof(peer_info.device_name));
2970 peer_info.config_methods = data->p2p_dev_found.config_methods;
2971 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2972 peer_info.group_capab = data->p2p_dev_found.group_capab;
2975 * FIX: new_device=1 is not necessarily correct. We should
2976 * maintain a P2P peer database in wpa_supplicant and update
2977 * this information based on whether the peer is truly new.
2979 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2982 case EVENT_P2P_GO_NEG_REQ_RX:
2983 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2984 data->p2p_go_neg_req_rx.dev_passwd_id);
2986 case EVENT_P2P_GO_NEG_COMPLETED:
2987 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2989 case EVENT_P2P_PROV_DISC_REQUEST:
2990 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2991 data->p2p_prov_disc_req.config_methods,
2992 data->p2p_prov_disc_req.dev_addr,
2993 data->p2p_prov_disc_req.pri_dev_type,
2994 data->p2p_prov_disc_req.dev_name,
2995 data->p2p_prov_disc_req.supp_config_methods,
2996 data->p2p_prov_disc_req.dev_capab,
2997 data->p2p_prov_disc_req.group_capab,
3000 case EVENT_P2P_PROV_DISC_RESPONSE:
3001 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3002 data->p2p_prov_disc_resp.config_methods);
3004 case EVENT_P2P_SD_REQUEST:
3005 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3006 data->p2p_sd_req.sa,
3007 data->p2p_sd_req.dialog_token,
3008 data->p2p_sd_req.update_indic,
3009 data->p2p_sd_req.tlvs,
3010 data->p2p_sd_req.tlvs_len);
3012 case EVENT_P2P_SD_RESPONSE:
3013 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3014 data->p2p_sd_resp.update_indic,
3015 data->p2p_sd_resp.tlvs,
3016 data->p2p_sd_resp.tlvs_len);
3018 #endif /* CONFIG_P2P */
3019 case EVENT_EAPOL_RX:
3020 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3021 data->eapol_rx.data,
3022 data->eapol_rx.data_len);
3024 case EVENT_SIGNAL_CHANGE:
3025 bgscan_notify_signal_change(
3026 wpa_s, data->signal_change.above_threshold,
3027 data->signal_change.current_signal,
3028 data->signal_change.current_noise,
3029 data->signal_change.current_txrate);
3031 case EVENT_INTERFACE_ENABLED:
3032 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3033 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3034 wpa_supplicant_update_mac_addr(wpa_s);
3036 if (!wpa_s->ap_iface) {
3037 wpa_supplicant_set_state(wpa_s,
3039 wpa_supplicant_req_scan(wpa_s, 0, 0);
3041 wpa_supplicant_set_state(wpa_s,
3043 #else /* CONFIG_AP */
3044 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3045 wpa_supplicant_req_scan(wpa_s, 0, 0);
3046 #endif /* CONFIG_AP */
3049 case EVENT_INTERFACE_DISABLED:
3050 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3051 wpa_supplicant_mark_disassoc(wpa_s);
3052 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3054 case EVENT_CHANNEL_LIST_CHANGED:
3055 if (wpa_s->drv_priv == NULL)
3056 break; /* Ignore event during drv initialization */
3058 free_hw_features(wpa_s);
3059 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
3060 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3063 wpas_p2p_update_channel_list(wpa_s);
3064 #endif /* CONFIG_P2P */
3066 case EVENT_INTERFACE_UNAVAILABLE:
3068 wpas_p2p_interface_unavailable(wpa_s);
3069 #endif /* CONFIG_P2P */
3071 case EVENT_BEST_CHANNEL:
3072 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3074 data->best_chan.freq_24, data->best_chan.freq_5,
3075 data->best_chan.freq_overall);
3076 wpa_s->best_24_freq = data->best_chan.freq_24;
3077 wpa_s->best_5_freq = data->best_chan.freq_5;
3078 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3080 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3081 data->best_chan.freq_5,
3082 data->best_chan.freq_overall);
3083 #endif /* CONFIG_P2P */
3085 case EVENT_UNPROT_DEAUTH:
3086 wpa_supplicant_event_unprot_deauth(wpa_s,
3087 &data->unprot_deauth);
3089 case EVENT_UNPROT_DISASSOC:
3090 wpa_supplicant_event_unprot_disassoc(wpa_s,
3091 &data->unprot_disassoc);
3093 case EVENT_STATION_LOW_ACK:
3095 if (wpa_s->ap_iface && data)
3096 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3097 data->low_ack.addr);
3098 #endif /* CONFIG_AP */
3101 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3102 #endif /* CONFIG_TDLS */
3104 case EVENT_IBSS_PEER_LOST:
3105 #ifdef CONFIG_IBSS_RSN
3106 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3107 #endif /* CONFIG_IBSS_RSN */
3109 case EVENT_DRIVER_GTK_REKEY:
3110 if (os_memcmp(data->driver_gtk_rekey.bssid,
3111 wpa_s->bssid, ETH_ALEN))
3115 wpa_sm_update_replay_ctr(wpa_s->wpa,
3116 data->driver_gtk_rekey.replay_ctr);
3118 case EVENT_SCHED_SCAN_STOPPED:
3119 wpa_s->sched_scanning = 0;
3120 wpa_supplicant_notify_scanning(wpa_s, 0);
3122 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3126 * If we timed out, start a new sched scan to continue
3127 * searching for more SSIDs.
3129 if (wpa_s->sched_scan_timed_out)
3130 wpa_supplicant_req_sched_scan(wpa_s);
3132 case EVENT_WPS_BUTTON_PUSHED:
3134 wpas_wps_start_pbc(wpa_s, NULL, 0);
3135 #endif /* CONFIG_WPS */
3137 case EVENT_CONNECT_FAILED_REASON:
3139 if (!wpa_s->ap_iface || !data)
3141 hostapd_event_connect_failed_reason(
3142 wpa_s->ap_iface->bss[0],
3143 data->connect_failed_reason.addr,
3144 data->connect_failed_reason.code);
3145 #endif /* CONFIG_AP */
3148 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);