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;
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 wpa_s->scard = scard_init((!sim && aka) ? SCARD_USIM_ONLY :
317 SCARD_TRY_BOTH, NULL);
318 if (wpa_s->scard == NULL) {
319 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
323 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
324 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
325 #endif /* PCSC_FUNCS */
326 #endif /* IEEE8021X_EAPOL */
332 #ifndef CONFIG_NO_SCAN_PROCESSING
334 static int has_wep_key(struct wpa_ssid *ssid)
338 for (i = 0; i < NUM_WEP_KEYS; i++) {
339 if (ssid->wep_key_len[i])
347 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
348 struct wpa_ssid *ssid)
352 if (ssid->mixed_cell)
356 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
358 #endif /* CONFIG_WPS */
360 if (has_wep_key(ssid))
363 #ifdef IEEE8021X_EAPOL
364 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
365 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
368 #endif /* IEEE8021X_EAPOL */
370 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
373 if (bss->caps & IEEE80211_CAP_PRIVACY)
379 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
380 struct wpa_ssid *ssid,
383 struct wpa_ie_data ie;
385 const u8 *rsn_ie, *wpa_ie;
389 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
393 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
394 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
395 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
396 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
397 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
399 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
400 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
403 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
410 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
412 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
417 if (!(ie.proto & ssid->proto)) {
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
423 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
429 if (!(ie.group_cipher & ssid->group_cipher)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
435 if (!(ie.key_mgmt & ssid->key_mgmt)) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
441 #ifdef CONFIG_IEEE80211W
442 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
443 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
444 wpa_s->conf->pmf : ssid->ieee80211w) ==
445 MGMT_FRAME_PROTECTION_REQUIRED) {
446 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
450 #endif /* CONFIG_IEEE80211W */
452 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
456 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
457 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
460 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
467 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
469 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
474 if (!(ie.proto & ssid->proto)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
480 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
486 if (!(ie.group_cipher & ssid->group_cipher)) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
492 if (!(ie.key_mgmt & ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
498 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
502 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
504 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
508 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
509 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
514 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
519 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
526 static int freq_allowed(int *freqs, int freq)
533 for (i = 0; freqs[i]; i++)
534 if (freqs[i] == freq)
540 static int ht_supported(const struct hostapd_hw_modes *mode)
542 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
544 * The driver did not indicate whether it supports HT. Assume
545 * it does to avoid connection issues.
551 * IEEE Std 802.11n-2009 20.1.1:
552 * An HT non-AP STA shall support all EQM rates for one spatial stream.
554 return mode->mcs_set[0] == 0xff;
558 static int vht_supported(const struct hostapd_hw_modes *mode)
560 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
562 * The driver did not indicate whether it supports VHT. Assume
563 * it does to avoid connection issues.
569 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
570 * TODO: Verify if this complies with the standard
572 return (mode->vht_mcs_set[0] & 0x3) != 3;
576 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
578 const struct hostapd_hw_modes *mode = NULL, *modes;
579 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
584 return 1; /* Cannot do matching without knowing band */
586 modes = wpa_s->hw.modes;
589 * The driver does not provide any additional information
590 * about the utilized hardware, so allow the connection attempt
596 for (i = 0; i < wpa_s->hw.num_modes; i++) {
597 for (j = 0; j < modes[i].num_channels; j++) {
598 int freq = modes[i].channels[j].freq;
599 if (freq == bss->freq) {
601 mode->mode == HOSTAPD_MODE_IEEE80211G)
602 break; /* do not allow 802.11b replace
613 for (i = 0; i < (int) sizeof(scan_ie); i++) {
614 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
618 for (j = 2; j < rate_ie[1] + 2; j++) {
619 int flagged = !!(rate_ie[j] & 0x80);
620 int r = (rate_ie[j] & 0x7f) * 5;
623 * IEEE Std 802.11n-2009 7.3.2.2:
624 * The new BSS Membership selector value is encoded
625 * like a legacy basic rate, but it is not a rate and
626 * only indicates if the BSS members are required to
627 * support the mandatory features of Clause 20 [HT PHY]
628 * in order to join the BSS.
630 if (flagged && ((rate_ie[j] & 0x7f) ==
631 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
632 if (!ht_supported(mode)) {
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " hardware does not support "
641 /* There's also a VHT selector for 802.11ac */
642 if (flagged && ((rate_ie[j] & 0x7f) ==
643 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
644 if (!vht_supported(mode)) {
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " hardware does not support "
656 /* check for legacy basic rates */
657 for (k = 0; k < mode->num_rates; k++) {
658 if (mode->rates[k] == r)
661 if (k == mode->num_rates) {
663 * IEEE Std 802.11-2007 7.3.2.2 demands that in
664 * order to join a BSS all required rates
665 * have to be supported by the hardware.
667 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
668 "not support required rate %d.%d Mbps",
679 static int bss_is_dmg(struct wpa_bss *bss)
681 return bss->freq > 45000;
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
689 static int bss_is_ess(struct wpa_bss *bss)
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
701 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
702 int i, struct wpa_bss *bss,
703 struct wpa_ssid *group)
705 u8 wpa_ie_len, rsn_ie_len;
707 struct wpa_blacklist *e;
709 struct wpa_ssid *ssid;
711 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
712 wpa_ie_len = ie ? ie[1] : 0;
714 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
715 rsn_ie_len = ie ? ie[1] : 0;
717 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
718 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
719 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
720 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
721 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
722 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
723 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
726 e = wpa_blacklist_get(wpa_s, bss->bssid);
729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
731 * When only a single network is enabled, we can
732 * trigger blacklisting on the first failure. This
733 * should not be done with multiple enabled networks to
734 * avoid getting forced to move into a worse ESS on
735 * single error if there are no other BSSes of the
740 if (e->count > limit) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
742 "(count=%d limit=%d)", e->count, limit);
747 if (bss->ssid_len == 0) {
748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
752 if (disallowed_bssid(wpa_s, bss->bssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
764 for (ssid = group; ssid; ssid = ssid->pnext) {
765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
768 if (wpas_network_disabled(wpa_s, ssid)) {
769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
773 res = wpas_temp_disabled(wpa_s, ssid);
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
776 "temporarily for %d second(s)", res);
781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
787 if (wpa && ssid->ssid_len == 0 &&
788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
792 /* Only allow wildcard SSID match if an AP
793 * advertises active WPS operation that matches
796 if (ssid->ssid_len == 0 &&
797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
800 #endif /* CONFIG_WPS */
802 if (ssid->bssid_set && ssid->ssid_len == 0 &&
803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
807 (bss->ssid_len != ssid->ssid_len ||
808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
813 if (ssid->bssid_set &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
837 if (!wpa_supplicant_match_privacy(bss, ssid)) {
838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
843 if (!bss_is_ess(bss)) {
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
848 if (!freq_allowed(ssid->freq_list, bss->freq)) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
854 if (!rate_match(wpa_s, bss)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
861 if (ssid->p2p_group &&
862 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
863 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
869 * TODO: skip the AP if its P2P IE has Group Formation
870 * bit set in the P2P Group Capability Bitmap and we
871 * are not in Group Formation with that device.
873 #endif /* CONFIG_P2P */
875 /* Matching configuration found */
879 /* No matching configuration found */
884 static struct wpa_bss *
885 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
886 struct wpa_ssid *group,
887 struct wpa_ssid **selected_ssid)
891 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
894 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
895 struct wpa_bss *bss = wpa_s->last_scan_res[i];
896 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
899 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
902 wpa_ssid_txt(bss->ssid, bss->ssid_len));
910 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
911 struct wpa_ssid **selected_ssid)
913 struct wpa_bss *selected = NULL;
916 if (wpa_s->last_scan_res == NULL ||
917 wpa_s->last_scan_res_used == 0)
918 return NULL; /* no scan results from last update */
920 while (selected == NULL) {
921 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
922 selected = wpa_supplicant_select_bss(
923 wpa_s, wpa_s->conf->pssid[prio],
929 if (selected == NULL && wpa_s->blacklist &&
930 !wpa_s->countermeasures) {
931 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
932 "blacklist and try again");
933 wpa_blacklist_clear(wpa_s);
934 wpa_s->blacklist_cleared++;
935 } else if (selected == NULL)
943 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
944 int timeout_sec, int timeout_usec)
946 if (!wpa_supplicant_enabled_networks(wpa_s)) {
948 * No networks are enabled; short-circuit request so
949 * we don't wait timeout seconds before transitioning
952 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
953 "since there are no enabled networks");
954 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
956 wpa_s->sta_scan_pending = 0;
957 #endif /* CONFIG_P2P */
961 wpa_s->scan_for_connection = 1;
962 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
966 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
967 struct wpa_bss *selected,
968 struct wpa_ssid *ssid)
970 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
971 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
972 "PBC session overlap");
974 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
976 #endif /* CONFIG_P2P */
979 wpas_wps_cancel(wpa_s);
980 #endif /* CONFIG_WPS */
984 wpa_msg(wpa_s, MSG_DEBUG,
985 "Considering connect request: reassociate: %d selected: "
986 MACSTR " bssid: " MACSTR " pending: " MACSTR
987 " wpa_state: %s ssid=%p current_ssid=%p",
988 wpa_s->reassociate, MAC2STR(selected->bssid),
989 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
990 wpa_supplicant_state_txt(wpa_s->wpa_state),
991 ssid, wpa_s->current_ssid);
994 * Do not trigger new association unless the BSSID has changed or if
995 * reassociation is requested. If we are in process of associating with
996 * the selected BSSID, do not trigger new attempt.
998 if (wpa_s->reassociate ||
999 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1000 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1001 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1002 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1003 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1005 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1006 ssid != wpa_s->current_ssid)))) {
1007 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1008 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1011 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1012 MAC2STR(selected->bssid));
1013 wpa_supplicant_associate(wpa_s, selected, ssid);
1015 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1016 "connect with the selected AP");
1023 static struct wpa_ssid *
1024 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1027 struct wpa_ssid *ssid;
1029 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1030 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1032 if (wpas_network_disabled(wpa_s, ssid))
1034 if (ssid->mode == IEEE80211_MODE_IBSS ||
1035 ssid->mode == IEEE80211_MODE_AP)
1043 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1044 * on BSS added and BSS changed events */
1045 static void wpa_supplicant_rsn_preauth_scan_results(
1046 struct wpa_supplicant *wpa_s)
1048 struct wpa_bss *bss;
1050 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1053 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1054 const u8 *ssid, *rsn;
1056 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1060 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1064 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1070 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1071 struct wpa_bss *selected,
1072 struct wpa_ssid *ssid)
1074 struct wpa_bss *current_bss = NULL;
1077 if (wpa_s->reassociate)
1078 return 1; /* explicit request to reassociate */
1079 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1080 return 1; /* we are not associated; continue */
1081 if (wpa_s->current_ssid == NULL)
1082 return 1; /* unknown current SSID */
1083 if (wpa_s->current_ssid != ssid)
1084 return 1; /* different network block */
1086 if (wpas_driver_bss_selection(wpa_s))
1087 return 0; /* Driver-based roaming */
1089 if (wpa_s->current_ssid->ssid)
1090 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1091 wpa_s->current_ssid->ssid,
1092 wpa_s->current_ssid->ssid_len);
1094 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1097 return 1; /* current BSS not seen in scan results */
1099 if (current_bss == selected)
1102 if (selected->last_update_idx > current_bss->last_update_idx)
1103 return 1; /* current BSS not seen in the last scan */
1105 #ifndef CONFIG_NO_ROAMING
1106 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1107 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1108 MAC2STR(current_bss->bssid), current_bss->level);
1109 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1110 MAC2STR(selected->bssid), selected->level);
1112 if (wpa_s->current_ssid->bssid_set &&
1113 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1115 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1116 "has preferred BSSID");
1120 if (current_bss->level < 0 && current_bss->level > selected->level) {
1121 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1127 if (current_bss->level < 0) {
1128 if (current_bss->level < -85)
1130 else if (current_bss->level < -80)
1132 else if (current_bss->level < -75)
1134 else if (current_bss->level < -70)
1139 if (abs(current_bss->level - selected->level) < min_diff) {
1140 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1146 #else /* CONFIG_NO_ROAMING */
1148 #endif /* CONFIG_NO_ROAMING */
1152 /* Return != 0 if no scan results could be fetched or if scan results should not
1153 * be shared with other virtual interfaces. */
1154 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1155 union wpa_event_data *data,
1158 struct wpa_scan_results *scan_res;
1160 #ifndef CONFIG_NO_RANDOM_POOL
1162 #endif /* CONFIG_NO_RANDOM_POOL */
1165 if (wpa_s->ap_iface)
1167 #endif /* CONFIG_AP */
1169 wpa_supplicant_notify_scanning(wpa_s, 0);
1172 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1173 !wpa_s->global->p2p_disabled &&
1174 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1175 !wpa_s->scan_res_handler) {
1176 wpa_s->global->p2p_cb_on_scan_complete = 0;
1177 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1178 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1179 "stopped scan processing");
1180 wpa_s->sta_scan_pending = 1;
1181 wpa_supplicant_req_scan(wpa_s, 5, 0);
1185 wpa_s->sta_scan_pending = 0;
1186 #endif /* CONFIG_P2P */
1188 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1189 data ? &data->scan_info :
1191 if (scan_res == NULL) {
1192 if (wpa_s->conf->ap_scan == 2 || ap ||
1193 wpa_s->scan_res_handler == scan_only_handler)
1197 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1199 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1203 #ifndef CONFIG_NO_RANDOM_POOL
1204 num = scan_res->num;
1207 for (i = 0; i < num; i++) {
1209 struct wpa_scan_res *res = scan_res->res[i];
1210 buf[0] = res->bssid[5];
1211 buf[1] = res->qual & 0xff;
1212 buf[2] = res->noise & 0xff;
1213 buf[3] = res->level & 0xff;
1214 buf[4] = res->tsf & 0xff;
1215 random_add_randomness(buf, sizeof(buf));
1217 #endif /* CONFIG_NO_RANDOM_POOL */
1219 if (own_request && wpa_s->scan_res_handler) {
1220 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1221 struct wpa_scan_results *scan_res);
1223 scan_res_handler = wpa_s->scan_res_handler;
1224 wpa_s->scan_res_handler = NULL;
1225 scan_res_handler(wpa_s, scan_res);
1227 wpa_scan_results_free(scan_res);
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1234 if (wpa_s->ap_iface->scan_cb)
1235 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1236 #endif /* CONFIG_AP */
1237 wpa_scan_results_free(scan_res);
1241 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1242 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1243 wpas_notify_scan_results(wpa_s);
1245 wpas_notify_scan_done(wpa_s, 1);
1247 if (sme_proc_obss_scan(wpa_s) > 0) {
1248 wpa_scan_results_free(scan_res);
1252 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1253 wpa_scan_results_free(scan_res);
1257 if (autoscan_notify_scan(wpa_s, scan_res)) {
1258 wpa_scan_results_free(scan_res);
1262 if (wpa_s->disconnected) {
1263 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1264 wpa_scan_results_free(scan_res);
1268 if (!wpas_driver_bss_selection(wpa_s) &&
1269 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1270 wpa_scan_results_free(scan_res);
1274 wpas_wps_update_ap_info(wpa_s, scan_res);
1276 wpa_scan_results_free(scan_res);
1278 return wpas_select_network_from_last_scan(wpa_s, 1);
1282 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1285 struct wpa_bss *selected;
1286 struct wpa_ssid *ssid = NULL;
1288 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1292 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1295 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1299 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1300 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1304 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1306 * Do not notify other virtual radios of scan results since we do not
1307 * want them to start other associations at the same time.
1311 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1312 ssid = wpa_supplicant_pick_new_network(wpa_s);
1314 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1315 wpa_supplicant_associate(wpa_s, NULL, ssid);
1317 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1319 int timeout_sec = wpa_s->scan_interval;
1320 int timeout_usec = 0;
1322 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1325 if (wpa_s->p2p_in_provisioning) {
1327 * Use shorter wait during P2P Provisioning
1328 * state to speed up group formation.
1331 timeout_usec = 250000;
1332 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1336 #endif /* CONFIG_P2P */
1337 #ifdef CONFIG_INTERWORKING
1338 if (wpa_s->conf->auto_interworking &&
1339 wpa_s->conf->interworking &&
1340 wpa_s->conf->cred) {
1341 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1342 "start ANQP fetch since no matching "
1344 wpa_s->network_select = 1;
1345 wpa_s->auto_network_select = 1;
1346 interworking_start_fetch_anqp(wpa_s);
1349 #endif /* CONFIG_INTERWORKING */
1350 if (wpa_supplicant_req_sched_scan(wpa_s))
1351 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1359 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1360 union wpa_event_data *data)
1362 const char *rn, *rn2;
1363 struct wpa_supplicant *ifs;
1365 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1367 * If no scan results could be fetched, then no need to
1368 * notify those interfaces that did not actually request
1369 * this scan. Similarly, if scan results started a new operation on this
1370 * interface, do not notify other interfaces to avoid concurrent
1371 * operations during a connection attempt.
1377 * Check other interfaces to see if they have the same radio-name. If
1378 * so, they get updated with this same scan info.
1380 if (!wpa_s->driver->get_radio_name)
1383 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1384 if (rn == NULL || rn[0] == '\0')
1387 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1388 "sharing same radio (%s) in event_scan_results", rn);
1390 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1391 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1394 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1395 if (rn2 && os_strcmp(rn, rn2) == 0) {
1396 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1397 "sibling", ifs->ifname);
1398 _wpa_supplicant_event_scan_results(ifs, data, 0);
1403 #endif /* CONFIG_NO_SCAN_PROCESSING */
1406 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1408 #ifdef CONFIG_NO_SCAN_PROCESSING
1410 #else /* CONFIG_NO_SCAN_PROCESSING */
1413 if (wpa_s->last_scan_res_used <= 0)
1417 if (now.sec - wpa_s->last_scan.sec > 5) {
1418 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1422 return wpas_select_network_from_last_scan(wpa_s, 0);
1423 #endif /* CONFIG_NO_SCAN_PROCESSING */
1428 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1430 struct wpa_supplicant *wpa_s = eloop_ctx;
1432 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1435 if (!wpa_s->no_keep_alive) {
1436 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1437 MAC2STR(wpa_s->bssid));
1438 /* TODO: could skip this if normal data traffic has been sent */
1439 /* TODO: Consider using some more appropriate data frame for
1442 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1447 if (wpa_s->sme.bss_max_idle_period) {
1449 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1452 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1453 wnm_bss_keep_alive, wpa_s, NULL);
1455 #endif /* CONFIG_SME */
1459 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1460 const u8 *ies, size_t ies_len)
1462 struct ieee802_11_elems elems;
1467 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1471 if (elems.bss_max_idle_period) {
1473 wpa_s->sme.bss_max_idle_period =
1474 WPA_GET_LE16(elems.bss_max_idle_period);
1475 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1476 "TU)%s", wpa_s->sme.bss_max_idle_period,
1477 (elems.bss_max_idle_period[2] & 0x01) ?
1478 " (protected keep-live required)" : "");
1479 if (wpa_s->sme.bss_max_idle_period == 0)
1480 wpa_s->sme.bss_max_idle_period = 1;
1481 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1482 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1483 /* msec times 1000 */
1484 msec = wpa_s->sme.bss_max_idle_period * 1024;
1487 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1488 wnm_bss_keep_alive, wpa_s,
1492 #endif /* CONFIG_SME */
1495 #endif /* CONFIG_WNM */
1498 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1501 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1502 #endif /* CONFIG_WNM */
1506 #ifdef CONFIG_INTERWORKING
1508 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1513 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1514 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1516 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1523 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1524 const u8 *ies, size_t ies_len)
1526 struct ieee802_11_elems elems;
1531 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1534 if (elems.qos_map_set) {
1535 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1536 elems.qos_map_set_len);
1540 #endif /* CONFIG_INTERWORKING */
1543 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1544 union wpa_event_data *data)
1546 int l, len, found = 0, wpa_found, rsn_found;
1548 #ifdef CONFIG_IEEE80211R
1550 #endif /* CONFIG_IEEE80211R */
1552 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1553 if (data->assoc_info.req_ies)
1554 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1555 data->assoc_info.req_ies_len);
1556 if (data->assoc_info.resp_ies) {
1557 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1558 data->assoc_info.resp_ies_len);
1560 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1561 data->assoc_info.resp_ies_len);
1562 #endif /* CONFIG_TDLS */
1564 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1565 data->assoc_info.resp_ies_len);
1566 #endif /* CONFIG_WNM */
1567 #ifdef CONFIG_INTERWORKING
1568 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1569 data->assoc_info.resp_ies_len);
1570 #endif /* CONFIG_INTERWORKING */
1572 if (data->assoc_info.beacon_ies)
1573 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1574 data->assoc_info.beacon_ies,
1575 data->assoc_info.beacon_ies_len);
1576 if (data->assoc_info.freq)
1577 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1578 data->assoc_info.freq);
1580 p = data->assoc_info.req_ies;
1581 l = data->assoc_info.req_ies_len;
1583 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1584 while (p && l >= 2) {
1587 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1591 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1592 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1593 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1594 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1597 wpa_find_assoc_pmkid(wpa_s);
1603 if (!found && data->assoc_info.req_ies)
1604 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1606 #ifdef CONFIG_IEEE80211R
1608 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1609 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1610 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1611 data->assoc_info.resp_ies,
1612 data->assoc_info.resp_ies_len,
1614 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1615 "Reassociation Response failed");
1616 wpa_supplicant_deauthenticate(
1617 wpa_s, WLAN_REASON_INVALID_IE);
1622 p = data->assoc_info.resp_ies;
1623 l = data->assoc_info.resp_ies_len;
1625 #ifdef CONFIG_WPS_STRICT
1626 if (p && wpa_s->current_ssid &&
1627 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1629 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1631 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1632 "include WPS IE in (Re)Association Response");
1636 if (wps_validate_assoc_resp(wps) < 0) {
1638 wpa_supplicant_deauthenticate(
1639 wpa_s, WLAN_REASON_INVALID_IE);
1644 #endif /* CONFIG_WPS_STRICT */
1646 /* Go through the IEs and make a copy of the MDIE, if present. */
1647 while (p && l >= 2) {
1650 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1654 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1655 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1656 wpa_s->sme.ft_used = 1;
1657 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1658 MOBILITY_DOMAIN_ID_LEN);
1664 #endif /* CONFIG_SME */
1666 /* Process FT when SME is in the driver */
1667 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1668 wpa_ft_is_completed(wpa_s->wpa)) {
1669 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1670 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1671 data->assoc_info.resp_ies,
1672 data->assoc_info.resp_ies_len,
1674 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1675 "Reassociation Response failed");
1676 wpa_supplicant_deauthenticate(
1677 wpa_s, WLAN_REASON_INVALID_IE);
1680 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1683 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1684 data->assoc_info.resp_ies_len);
1685 #endif /* CONFIG_IEEE80211R */
1687 /* WPA/RSN IE from Beacon/ProbeResp */
1688 p = data->assoc_info.beacon_ies;
1689 l = data->assoc_info.beacon_ies_len;
1691 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1693 wpa_found = rsn_found = 0;
1694 while (p && l >= 2) {
1697 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1702 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1703 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1705 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1709 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1711 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1718 if (!wpa_found && data->assoc_info.beacon_ies)
1719 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1720 if (!rsn_found && data->assoc_info.beacon_ies)
1721 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1722 if (wpa_found || rsn_found)
1723 wpa_s->ap_ies_from_associnfo = 1;
1725 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1726 wpa_s->assoc_freq != data->assoc_info.freq) {
1727 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1729 wpa_s->assoc_freq, data->assoc_info.freq);
1730 wpa_supplicant_update_scan_results(wpa_s);
1733 wpa_s->assoc_freq = data->assoc_info.freq;
1739 static struct wpa_bss * wpa_supplicant_get_new_bss(
1740 struct wpa_supplicant *wpa_s, const u8 *bssid)
1742 struct wpa_bss *bss = NULL;
1743 struct wpa_ssid *ssid = wpa_s->current_ssid;
1745 if (ssid->ssid_len > 0)
1746 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1748 bss = wpa_bss_get_bssid(wpa_s, bssid);
1754 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1756 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1758 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1761 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1764 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1765 WPA_IE_VENDOR_TYPE);
1766 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1768 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1769 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1770 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1771 bss_rsn ? 2 + bss_rsn[1] : 0))
1778 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1779 union wpa_event_data *data)
1785 if (wpa_s->ap_iface) {
1786 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1787 data->assoc_info.addr,
1788 data->assoc_info.req_ies,
1789 data->assoc_info.req_ies_len,
1790 data->assoc_info.reassoc);
1793 #endif /* CONFIG_AP */
1795 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1796 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1799 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1800 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1801 wpa_supplicant_deauthenticate(
1802 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1806 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1807 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1808 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1809 MACSTR, MAC2STR(bssid));
1810 random_add_randomness(bssid, ETH_ALEN);
1811 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1812 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1813 wpas_notify_bssid_changed(wpa_s);
1815 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1816 wpa_clear_keys(wpa_s, bssid);
1818 if (wpa_supplicant_select_config(wpa_s) < 0) {
1819 wpa_supplicant_deauthenticate(
1820 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1823 if (wpa_s->current_ssid) {
1824 struct wpa_bss *bss = NULL;
1826 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1828 wpa_supplicant_update_scan_results(wpa_s);
1830 /* Get the BSS from the new scan results */
1831 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1835 wpa_s->current_bss = bss;
1838 if (wpa_s->conf->ap_scan == 1 &&
1839 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1840 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1841 wpa_msg(wpa_s, MSG_WARNING,
1842 "WPA/RSN IEs not updated");
1847 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1848 wpa_s->sme.prev_bssid_set = 1;
1849 #endif /* CONFIG_SME */
1851 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1852 if (wpa_s->current_ssid) {
1853 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1854 * initialized before association, but for other modes,
1855 * initialize PC/SC here, if the current configuration needs
1856 * smartcard or SIM/USIM. */
1857 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1859 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1861 l2_packet_notify_auth_start(wpa_s->l2);
1864 * Set portEnabled first to FALSE in order to get EAP state machine out
1865 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1866 * state machine may transit to AUTHENTICATING state based on obsolete
1867 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1868 * AUTHENTICATED without ever giving chance to EAP state machine to
1871 if (!ft_completed) {
1872 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1873 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1875 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1876 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1877 /* 802.1X::portControl = Auto */
1878 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1879 wpa_s->eapol_received = 0;
1880 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1881 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1882 (wpa_s->current_ssid &&
1883 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1884 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1886 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1888 * Set the key after having received joined-IBSS event
1891 wpa_supplicant_set_wpa_none_key(wpa_s,
1892 wpa_s->current_ssid);
1894 wpa_supplicant_cancel_auth_timeout(wpa_s);
1895 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1896 } else if (!ft_completed) {
1897 /* Timeout for receiving the first EAPOL packet */
1898 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1900 wpa_supplicant_cancel_scan(wpa_s);
1902 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1903 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1905 * We are done; the driver will take care of RSN 4-way
1908 wpa_supplicant_cancel_auth_timeout(wpa_s);
1909 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1910 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1911 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1912 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1913 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1915 * The driver will take care of RSN 4-way handshake, so we need
1916 * to allow EAPOL supplicant to complete its work without
1917 * waiting for WPA supplicant.
1919 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1920 } else if (ft_completed) {
1922 * FT protocol completed - make sure EAPOL state machine ends
1923 * up in authenticated.
1925 wpa_supplicant_cancel_auth_timeout(wpa_s);
1926 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1927 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1928 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1931 wpa_s->last_eapol_matches_bssid = 0;
1933 if (wpa_s->pending_eapol_rx) {
1934 struct os_time now, age;
1936 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1937 if (age.sec == 0 && age.usec < 100000 &&
1938 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1940 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1941 "frame that was received just before "
1942 "association notification");
1943 wpa_supplicant_rx_eapol(
1944 wpa_s, wpa_s->pending_eapol_rx_src,
1945 wpabuf_head(wpa_s->pending_eapol_rx),
1946 wpabuf_len(wpa_s->pending_eapol_rx));
1948 wpabuf_free(wpa_s->pending_eapol_rx);
1949 wpa_s->pending_eapol_rx = NULL;
1952 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1953 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1954 wpa_s->current_ssid &&
1955 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1956 /* Set static WEP keys again */
1957 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1960 #ifdef CONFIG_IBSS_RSN
1961 if (wpa_s->current_ssid &&
1962 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1963 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1964 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1965 wpa_s->ibss_rsn == NULL) {
1966 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1967 if (!wpa_s->ibss_rsn) {
1968 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1969 wpa_supplicant_deauthenticate(
1970 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1974 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1976 #endif /* CONFIG_IBSS_RSN */
1978 wpas_wps_notify_assoc(wpa_s, bssid);
1982 static int disconnect_reason_recoverable(u16 reason_code)
1984 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1985 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1986 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1990 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1992 int locally_generated)
1996 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1998 * At least Host AP driver and a Prism3 card seemed to be
1999 * generating streams of disconnected events when configuring
2000 * IBSS for WPA-None. Ignore them for now.
2005 bssid = wpa_s->bssid;
2006 if (is_zero_ether_addr(bssid))
2007 bssid = wpa_s->pending_bssid;
2009 if (!is_zero_ether_addr(bssid) ||
2010 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2011 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2013 MAC2STR(bssid), reason_code,
2014 locally_generated ? " locally_generated=1" : "");
2019 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2020 int locally_generated)
2022 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2023 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2024 return 0; /* Not in 4-way handshake with PSK */
2027 * It looks like connection was lost while trying to go through PSK
2028 * 4-way handshake. Filter out known disconnection cases that are caused
2029 * by something else than PSK mismatch to avoid confusing reports.
2032 if (locally_generated) {
2033 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2041 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2043 int locally_generated)
2047 u8 prev_pending_bssid[ETH_ALEN];
2048 struct wpa_bss *fast_reconnect = NULL;
2049 #ifndef CONFIG_NO_SCAN_PROCESSING
2050 struct wpa_ssid *fast_reconnect_ssid = NULL;
2051 #endif /* CONFIG_NO_SCAN_PROCESSING */
2052 struct wpa_ssid *last_ssid;
2054 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2055 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2057 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2059 * At least Host AP driver and a Prism3 card seemed to be
2060 * generating streams of disconnected events when configuring
2061 * IBSS for WPA-None. Ignore them for now.
2063 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2064 "IBSS/WPA-None mode");
2068 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2069 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2070 "pre-shared key may be incorrect");
2071 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2072 return; /* P2P group removed */
2073 wpas_auth_failed(wpa_s);
2075 if (!wpa_s->disconnected &&
2076 (!wpa_s->auto_reconnect_disabled ||
2077 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
2078 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2079 "reconnect (wps=%d wpa_state=%d)",
2080 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2082 if (wpa_s->wpa_state == WPA_COMPLETED &&
2083 wpa_s->current_ssid &&
2084 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2085 !locally_generated &&
2086 disconnect_reason_recoverable(reason_code)) {
2088 * It looks like the AP has dropped association with
2089 * us, but could allow us to get back in. Try to
2090 * reconnect to the same BSS without full scan to save
2091 * time for some common cases.
2093 fast_reconnect = wpa_s->current_bss;
2094 #ifndef CONFIG_NO_SCAN_PROCESSING
2095 fast_reconnect_ssid = wpa_s->current_ssid;
2096 #endif /* CONFIG_NO_SCAN_PROCESSING */
2097 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2098 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2100 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2103 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2104 "try to re-connect");
2105 wpa_s->reassociate = 0;
2106 wpa_s->disconnected = 1;
2107 wpa_supplicant_cancel_sched_scan(wpa_s);
2109 bssid = wpa_s->bssid;
2110 if (is_zero_ether_addr(bssid))
2111 bssid = wpa_s->pending_bssid;
2112 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2113 wpas_connection_failed(wpa_s, bssid);
2114 wpa_sm_notify_disassoc(wpa_s->wpa);
2115 if (locally_generated)
2116 wpa_s->disconnect_reason = -reason_code;
2118 wpa_s->disconnect_reason = reason_code;
2119 wpas_notify_disconnect_reason(wpa_s);
2120 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2121 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2122 wpa_s->keys_cleared = 0;
2123 wpa_clear_keys(wpa_s, wpa_s->bssid);
2125 last_ssid = wpa_s->current_ssid;
2126 wpa_supplicant_mark_disassoc(wpa_s);
2128 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2129 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2130 wpa_s->current_ssid = last_ssid;
2133 if (fast_reconnect) {
2134 #ifndef CONFIG_NO_SCAN_PROCESSING
2135 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2136 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2137 fast_reconnect_ssid) < 0) {
2138 /* Recover through full scan */
2139 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2141 #endif /* CONFIG_NO_SCAN_PROCESSING */
2146 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2147 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2149 struct wpa_supplicant *wpa_s = eloop_ctx;
2151 if (!wpa_s->pending_mic_error_report)
2154 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2155 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2156 wpa_s->pending_mic_error_report = 0;
2158 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2162 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2163 union wpa_event_data *data)
2168 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2169 pairwise = (data && data->michael_mic_failure.unicast);
2171 if ((wpa_s->last_michael_mic_error &&
2172 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2173 wpa_s->pending_mic_error_report) {
2174 if (wpa_s->pending_mic_error_report) {
2176 * Send the pending MIC error report immediately since
2177 * we are going to start countermeasures and AP better
2180 wpa_sm_key_request(wpa_s->wpa, 1,
2181 wpa_s->pending_mic_error_pairwise);
2184 /* Send the new MIC error report immediately since we are going
2185 * to start countermeasures and AP better do the same.
2187 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2189 /* initialize countermeasures */
2190 wpa_s->countermeasures = 1;
2192 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2194 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2197 * Need to wait for completion of request frame. We do not get
2198 * any callback for the message completion, so just wait a
2199 * short while and hope for the best. */
2202 wpa_drv_set_countermeasures(wpa_s, 1);
2203 wpa_supplicant_deauthenticate(wpa_s,
2204 WLAN_REASON_MICHAEL_MIC_FAILURE);
2205 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2207 eloop_register_timeout(60, 0,
2208 wpa_supplicant_stop_countermeasures,
2210 /* TODO: mark the AP rejected for 60 second. STA is
2211 * allowed to associate with another AP.. */
2213 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2214 if (wpa_s->mic_errors_seen) {
2216 * Reduce the effectiveness of Michael MIC error
2217 * reports as a means for attacking against TKIP if
2218 * more than one MIC failure is noticed with the same
2219 * PTK. We delay the transmission of the reports by a
2220 * random time between 0 and 60 seconds in order to
2221 * force the attacker wait 60 seconds before getting
2222 * the information on whether a frame resulted in a MIC
2228 if (os_get_random(rval, sizeof(rval)) < 0)
2229 sec = os_random() % 60;
2231 sec = WPA_GET_BE32(rval) % 60;
2232 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2233 "report %d seconds", sec);
2234 wpa_s->pending_mic_error_report = 1;
2235 wpa_s->pending_mic_error_pairwise = pairwise;
2236 eloop_cancel_timeout(
2237 wpa_supplicant_delayed_mic_error_report,
2239 eloop_register_timeout(
2240 sec, os_random() % 1000000,
2241 wpa_supplicant_delayed_mic_error_report,
2244 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2246 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2247 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2248 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2250 wpa_s->last_michael_mic_error = t.sec;
2251 wpa_s->mic_errors_seen++;
2255 #ifdef CONFIG_TERMINATE_ONLASTIF
2256 static int any_interfaces(struct wpa_supplicant *head)
2258 struct wpa_supplicant *wpa_s;
2260 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2261 if (!wpa_s->interface_removed)
2265 #endif /* CONFIG_TERMINATE_ONLASTIF */
2269 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2270 union wpa_event_data *data)
2272 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2275 switch (data->interface_status.ievent) {
2276 case EVENT_INTERFACE_ADDED:
2277 if (!wpa_s->interface_removed)
2279 wpa_s->interface_removed = 0;
2280 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2281 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2282 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2283 "driver after interface was added");
2285 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2287 case EVENT_INTERFACE_REMOVED:
2288 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2289 wpa_s->interface_removed = 1;
2290 wpa_supplicant_mark_disassoc(wpa_s);
2291 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2292 l2_packet_deinit(wpa_s->l2);
2294 #ifdef CONFIG_IBSS_RSN
2295 ibss_rsn_deinit(wpa_s->ibss_rsn);
2296 wpa_s->ibss_rsn = NULL;
2297 #endif /* CONFIG_IBSS_RSN */
2298 #ifdef CONFIG_TERMINATE_ONLASTIF
2299 /* check if last interface */
2300 if (!any_interfaces(wpa_s->global->ifaces))
2302 #endif /* CONFIG_TERMINATE_ONLASTIF */
2308 #ifdef CONFIG_PEERKEY
2310 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2311 union wpa_event_data *data)
2315 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2317 #endif /* CONFIG_PEERKEY */
2321 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2322 union wpa_event_data *data)
2326 switch (data->tdls.oper) {
2327 case TDLS_REQUEST_SETUP:
2328 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2329 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2330 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2332 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2334 case TDLS_REQUEST_TEARDOWN:
2335 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2336 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2337 data->tdls.reason_code);
2339 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2344 #endif /* CONFIG_TDLS */
2348 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2349 union wpa_event_data *data)
2353 switch (data->wnm.oper) {
2354 case WNM_OPER_SLEEP:
2355 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2356 "(action=%d, intval=%d)",
2357 data->wnm.sleep_action, data->wnm.sleep_intval);
2358 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2359 data->wnm.sleep_intval, NULL);
2363 #endif /* CONFIG_WNM */
2366 #ifdef CONFIG_IEEE80211R
2368 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2369 union wpa_event_data *data)
2374 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2375 data->ft_ies.ies_len,
2376 data->ft_ies.ft_action,
2377 data->ft_ies.target_ap,
2378 data->ft_ies.ric_ies,
2379 data->ft_ies.ric_ies_len) < 0) {
2380 /* TODO: prevent MLME/driver from trying to associate? */
2383 #endif /* CONFIG_IEEE80211R */
2386 #ifdef CONFIG_IBSS_RSN
2387 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2388 union wpa_event_data *data)
2390 struct wpa_ssid *ssid;
2391 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2395 ssid = wpa_s->current_ssid;
2398 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2401 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2405 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2406 union wpa_event_data *data)
2408 struct wpa_ssid *ssid = wpa_s->current_ssid;
2413 /* check if the ssid is correctly configured as IBSS/RSN */
2414 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2417 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2418 data->rx_mgmt.frame_len);
2420 #endif /* CONFIG_IBSS_RSN */
2423 #ifdef CONFIG_IEEE80211R
2424 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2427 const u8 *sta_addr, *target_ap_addr;
2430 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2431 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2432 return; /* only SME case supported for now */
2433 if (len < 1 + 2 * ETH_ALEN + 2)
2436 return; /* Only FT Action Response is supported for now */
2437 sta_addr = data + 1;
2438 target_ap_addr = data + 1 + ETH_ALEN;
2439 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2440 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2441 MACSTR " TargetAP " MACSTR " status %u",
2442 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2444 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2445 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2446 " in FT Action Response", MAC2STR(sta_addr));
2451 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2452 "failure (status code %d)", status);
2453 /* TODO: report error to FT code(?) */
2457 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2458 len - (1 + 2 * ETH_ALEN + 2), 1,
2459 target_ap_addr, NULL, 0) < 0)
2464 struct wpa_bss *bss;
2465 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2467 wpa_s->sme.freq = bss->freq;
2468 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2469 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2472 #endif /* CONFIG_SME */
2474 #endif /* CONFIG_IEEE80211R */
2477 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2478 struct unprot_deauth *e)
2480 #ifdef CONFIG_IEEE80211W
2481 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2482 "dropped: " MACSTR " -> " MACSTR
2483 " (reason code %u)",
2484 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2485 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2486 #endif /* CONFIG_IEEE80211W */
2490 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2491 struct unprot_disassoc *e)
2493 #ifdef CONFIG_IEEE80211W
2494 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2495 "dropped: " MACSTR " -> " MACSTR
2496 " (reason code %u)",
2497 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2498 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2499 #endif /* CONFIG_IEEE80211W */
2503 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2504 u16 reason_code, int locally_generated,
2505 const u8 *ie, size_t ie_len, int deauth)
2508 if (wpa_s->ap_iface && addr) {
2509 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2513 if (wpa_s->ap_iface) {
2514 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2517 #endif /* CONFIG_AP */
2519 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2521 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2522 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2523 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2524 eapol_sm_failed(wpa_s->eapol)))
2525 wpas_auth_failed(wpa_s);
2528 if (deauth && reason_code > 0) {
2529 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2530 locally_generated) > 0) {
2532 * The interface was removed, so cannot continue
2533 * processing any additional operations after this.
2538 #endif /* CONFIG_P2P */
2540 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2545 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2546 struct disassoc_info *info)
2548 u16 reason_code = 0;
2549 int locally_generated = 0;
2550 const u8 *addr = NULL;
2551 const u8 *ie = NULL;
2554 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2559 ie_len = info->ie_len;
2560 reason_code = info->reason_code;
2561 locally_generated = info->locally_generated;
2562 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2563 locally_generated ? " (locally generated)" : "");
2565 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2567 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2572 if (wpa_s->ap_iface && info && info->addr) {
2573 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2577 if (wpa_s->ap_iface) {
2578 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2581 #endif /* CONFIG_AP */
2585 wpas_p2p_disassoc_notif(
2586 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2589 #endif /* CONFIG_P2P */
2591 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2592 sme_event_disassoc(wpa_s, info);
2594 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2599 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2600 struct deauth_info *info)
2602 u16 reason_code = 0;
2603 int locally_generated = 0;
2604 const u8 *addr = NULL;
2605 const u8 *ie = NULL;
2608 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2613 ie_len = info->ie_len;
2614 reason_code = info->reason_code;
2615 locally_generated = info->locally_generated;
2616 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2618 locally_generated ? " (locally generated)" : "");
2620 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2623 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2627 wpa_reset_ft_completed(wpa_s->wpa);
2629 wpas_event_disconnect(wpa_s, addr, reason_code,
2630 locally_generated, ie, ie_len, 1);
2634 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2635 union wpa_event_data *data)
2637 struct wpa_supplicant *wpa_s = ctx;
2639 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2640 event != EVENT_INTERFACE_ENABLED &&
2641 event != EVENT_INTERFACE_STATUS &&
2642 event != EVENT_SCHED_SCAN_STOPPED) {
2643 wpa_dbg(wpa_s, MSG_DEBUG,
2644 "Ignore event %s (%d) while interface is disabled",
2645 event_to_string(event), event);
2649 #ifndef CONFIG_NO_STDOUT_DEBUG
2651 int level = MSG_DEBUG;
2653 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2654 const struct ieee80211_hdr *hdr;
2656 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2657 fc = le_to_host16(hdr->frame_control);
2658 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2659 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2660 level = MSG_EXCESSIVE;
2663 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2664 event_to_string(event), event);
2666 #endif /* CONFIG_NO_STDOUT_DEBUG */
2670 sme_event_auth(wpa_s, data);
2673 wpa_supplicant_event_assoc(wpa_s, data);
2675 case EVENT_DISASSOC:
2676 wpas_event_disassoc(wpa_s,
2677 data ? &data->disassoc_info : NULL);
2680 wpas_event_deauth(wpa_s,
2681 data ? &data->deauth_info : NULL);
2683 case EVENT_MICHAEL_MIC_FAILURE:
2684 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2686 #ifndef CONFIG_NO_SCAN_PROCESSING
2687 case EVENT_SCAN_RESULTS:
2688 wpa_supplicant_event_scan_results(wpa_s, data);
2689 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2690 wpa_s->wpa_state != WPA_ASSOCIATING)
2691 wpas_p2p_continue_after_scan(wpa_s);
2693 #endif /* CONFIG_NO_SCAN_PROCESSING */
2694 case EVENT_ASSOCINFO:
2695 wpa_supplicant_event_associnfo(wpa_s, data);
2697 case EVENT_INTERFACE_STATUS:
2698 wpa_supplicant_event_interface_status(wpa_s, data);
2700 case EVENT_PMKID_CANDIDATE:
2701 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2703 #ifdef CONFIG_PEERKEY
2704 case EVENT_STKSTART:
2705 wpa_supplicant_event_stkstart(wpa_s, data);
2707 #endif /* CONFIG_PEERKEY */
2710 wpa_supplicant_event_tdls(wpa_s, data);
2712 #endif /* CONFIG_TDLS */
2715 wpa_supplicant_event_wnm(wpa_s, data);
2717 #endif /* CONFIG_WNM */
2718 #ifdef CONFIG_IEEE80211R
2719 case EVENT_FT_RESPONSE:
2720 wpa_supplicant_event_ft_response(wpa_s, data);
2722 #endif /* CONFIG_IEEE80211R */
2723 #ifdef CONFIG_IBSS_RSN
2724 case EVENT_IBSS_RSN_START:
2725 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2727 #endif /* CONFIG_IBSS_RSN */
2728 case EVENT_ASSOC_REJECT:
2729 if (data->assoc_reject.bssid)
2730 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2731 "bssid=" MACSTR " status_code=%u",
2732 MAC2STR(data->assoc_reject.bssid),
2733 data->assoc_reject.status_code);
2735 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2737 data->assoc_reject.status_code);
2738 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2739 sme_event_assoc_reject(wpa_s, data);
2741 const u8 *bssid = data->assoc_reject.bssid;
2742 if (bssid == NULL || is_zero_ether_addr(bssid))
2743 bssid = wpa_s->pending_bssid;
2744 wpas_connection_failed(wpa_s, bssid);
2745 wpa_supplicant_mark_disassoc(wpa_s);
2748 case EVENT_AUTH_TIMED_OUT:
2749 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2750 sme_event_auth_timed_out(wpa_s, data);
2752 case EVENT_ASSOC_TIMED_OUT:
2753 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2754 sme_event_assoc_timed_out(wpa_s, data);
2756 case EVENT_TX_STATUS:
2757 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2758 " type=%d stype=%d",
2759 MAC2STR(data->tx_status.dst),
2760 data->tx_status.type, data->tx_status.stype);
2762 if (wpa_s->ap_iface == NULL) {
2763 #ifdef CONFIG_OFFCHANNEL
2764 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2765 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2766 offchannel_send_action_tx_status(
2767 wpa_s, data->tx_status.dst,
2768 data->tx_status.data,
2769 data->tx_status.data_len,
2770 data->tx_status.ack ?
2771 OFFCHANNEL_SEND_ACTION_SUCCESS :
2772 OFFCHANNEL_SEND_ACTION_NO_ACK);
2773 #endif /* CONFIG_OFFCHANNEL */
2776 #endif /* CONFIG_AP */
2777 #ifdef CONFIG_OFFCHANNEL
2778 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2779 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2781 * Catch TX status events for Action frames we sent via group
2782 * interface in GO mode.
2784 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2785 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2786 os_memcmp(wpa_s->parent->pending_action_dst,
2787 data->tx_status.dst, ETH_ALEN) == 0) {
2788 offchannel_send_action_tx_status(
2789 wpa_s->parent, data->tx_status.dst,
2790 data->tx_status.data,
2791 data->tx_status.data_len,
2792 data->tx_status.ack ?
2793 OFFCHANNEL_SEND_ACTION_SUCCESS :
2794 OFFCHANNEL_SEND_ACTION_NO_ACK);
2797 #endif /* CONFIG_OFFCHANNEL */
2799 switch (data->tx_status.type) {
2800 case WLAN_FC_TYPE_MGMT:
2801 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2802 data->tx_status.data_len,
2803 data->tx_status.stype,
2804 data->tx_status.ack);
2806 case WLAN_FC_TYPE_DATA:
2807 ap_tx_status(wpa_s, data->tx_status.dst,
2808 data->tx_status.data,
2809 data->tx_status.data_len,
2810 data->tx_status.ack);
2813 #endif /* CONFIG_AP */
2816 case EVENT_EAPOL_TX_STATUS:
2817 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2818 data->eapol_tx_status.data,
2819 data->eapol_tx_status.data_len,
2820 data->eapol_tx_status.ack);
2822 case EVENT_DRIVER_CLIENT_POLL_OK:
2823 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2825 case EVENT_RX_FROM_UNKNOWN:
2826 if (wpa_s->ap_iface == NULL)
2828 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2829 data->rx_from_unknown.wds);
2831 case EVENT_CH_SWITCH:
2834 if (!wpa_s->ap_iface) {
2835 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2836 "event in non-AP mode");
2840 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2841 data->ch_switch.ht_enabled,
2842 data->ch_switch.ch_offset);
2844 #endif /* CONFIG_AP */
2845 #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
2846 case EVENT_RX_MGMT: {
2848 const struct ieee80211_mgmt *mgmt;
2850 mgmt = (const struct ieee80211_mgmt *)
2851 data->rx_mgmt.frame;
2852 fc = le_to_host16(mgmt->frame_control);
2853 stype = WLAN_FC_GET_STYPE(fc);
2856 if (wpa_s->ap_iface == NULL) {
2857 #endif /* CONFIG_AP */
2859 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2860 data->rx_mgmt.frame_len > 24) {
2861 const u8 *src = mgmt->sa;
2862 const u8 *ie = mgmt->u.probe_req.variable;
2863 size_t ie_len = data->rx_mgmt.frame_len -
2864 (mgmt->u.probe_req.variable -
2865 data->rx_mgmt.frame);
2866 wpas_p2p_probe_req_rx(
2867 wpa_s, src, mgmt->da,
2868 mgmt->bssid, ie, ie_len,
2869 data->rx_mgmt.ssi_signal);
2872 #endif /* CONFIG_P2P */
2873 #ifdef CONFIG_IBSS_RSN
2874 if (stype == WLAN_FC_STYPE_AUTH &&
2875 data->rx_mgmt.frame_len >= 30) {
2876 wpa_supplicant_event_ibss_auth(wpa_s, data);
2879 #endif /* CONFIG_IBSS_RSN */
2880 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2881 "management frame in non-AP mode");
2886 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2887 data->rx_mgmt.frame_len > 24) {
2888 const u8 *ie = mgmt->u.probe_req.variable;
2889 size_t ie_len = data->rx_mgmt.frame_len -
2890 (mgmt->u.probe_req.variable -
2891 data->rx_mgmt.frame);
2893 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2894 mgmt->bssid, ie, ie_len,
2895 data->rx_mgmt.ssi_signal);
2898 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2899 #endif /* CONFIG_AP */
2902 #endif /* CONFIG_AP || CONFIG_IBSS_RSN */
2903 case EVENT_RX_ACTION:
2904 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2905 " Category=%u DataLen=%d freq=%d MHz",
2906 MAC2STR(data->rx_action.sa),
2907 data->rx_action.category, (int) data->rx_action.len,
2908 data->rx_action.freq);
2909 #ifdef CONFIG_IEEE80211R
2910 if (data->rx_action.category == WLAN_ACTION_FT) {
2911 ft_rx_action(wpa_s, data->rx_action.data,
2912 data->rx_action.len);
2915 #endif /* CONFIG_IEEE80211R */
2916 #ifdef CONFIG_IEEE80211W
2918 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2919 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2920 data->rx_action.data,
2921 data->rx_action.len);
2924 #endif /* CONFIG_SME */
2925 #endif /* CONFIG_IEEE80211W */
2927 if (data->rx_action.category == WLAN_ACTION_WNM) {
2928 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2931 #endif /* CONFIG_WNM */
2933 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2934 gas_query_rx(wpa_s->gas, data->rx_action.da,
2935 data->rx_action.sa, data->rx_action.bssid,
2936 data->rx_action.data, data->rx_action.len,
2937 data->rx_action.freq) == 0)
2939 #endif /* CONFIG_GAS */
2941 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2942 data->rx_action.len >= 4 &&
2943 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2944 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2945 "Response from " MACSTR,
2946 MAC2STR(data->rx_action.sa));
2949 #endif /* CONFIG_TDLS */
2950 #ifdef CONFIG_INTERWORKING
2951 if (data->rx_action.category == WLAN_ACTION_QOS &&
2952 data->rx_action.len >= 1 &&
2953 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
2954 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2955 MACSTR, MAC2STR(data->rx_action.sa));
2956 if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
2958 wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
2959 data->rx_action.len - 1);
2962 #endif /* CONFIG_INTERWORKING */
2964 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2966 data->rx_action.bssid,
2967 data->rx_action.category,
2968 data->rx_action.data,
2969 data->rx_action.len, data->rx_action.freq);
2970 #endif /* CONFIG_P2P */
2972 case EVENT_RX_PROBE_REQ:
2973 if (data->rx_probe_req.sa == NULL ||
2974 data->rx_probe_req.ie == NULL)
2977 if (wpa_s->ap_iface) {
2978 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2979 data->rx_probe_req.sa,
2980 data->rx_probe_req.da,
2981 data->rx_probe_req.bssid,
2982 data->rx_probe_req.ie,
2983 data->rx_probe_req.ie_len,
2984 data->rx_probe_req.ssi_signal);
2987 #endif /* CONFIG_AP */
2989 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2990 data->rx_probe_req.da,
2991 data->rx_probe_req.bssid,
2992 data->rx_probe_req.ie,
2993 data->rx_probe_req.ie_len,
2994 data->rx_probe_req.ssi_signal);
2995 #endif /* CONFIG_P2P */
2997 case EVENT_REMAIN_ON_CHANNEL:
2998 #ifdef CONFIG_OFFCHANNEL
2999 offchannel_remain_on_channel_cb(
3000 wpa_s, data->remain_on_channel.freq,
3001 data->remain_on_channel.duration);
3002 #endif /* CONFIG_OFFCHANNEL */
3004 wpas_p2p_remain_on_channel_cb(
3005 wpa_s, data->remain_on_channel.freq,
3006 data->remain_on_channel.duration);
3007 #endif /* CONFIG_P2P */
3009 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3010 #ifdef CONFIG_OFFCHANNEL
3011 offchannel_cancel_remain_on_channel_cb(
3012 wpa_s, data->remain_on_channel.freq);
3013 #endif /* CONFIG_OFFCHANNEL */
3015 wpas_p2p_cancel_remain_on_channel_cb(
3016 wpa_s, data->remain_on_channel.freq);
3017 #endif /* CONFIG_P2P */
3020 case EVENT_P2P_DEV_FOUND: {
3021 struct p2p_peer_info peer_info;
3023 os_memset(&peer_info, 0, sizeof(peer_info));
3024 if (data->p2p_dev_found.dev_addr)
3025 os_memcpy(peer_info.p2p_device_addr,
3026 data->p2p_dev_found.dev_addr, ETH_ALEN);
3027 if (data->p2p_dev_found.pri_dev_type)
3028 os_memcpy(peer_info.pri_dev_type,
3029 data->p2p_dev_found.pri_dev_type,
3030 sizeof(peer_info.pri_dev_type));
3031 if (data->p2p_dev_found.dev_name)
3032 os_strlcpy(peer_info.device_name,
3033 data->p2p_dev_found.dev_name,
3034 sizeof(peer_info.device_name));
3035 peer_info.config_methods = data->p2p_dev_found.config_methods;
3036 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3037 peer_info.group_capab = data->p2p_dev_found.group_capab;
3040 * FIX: new_device=1 is not necessarily correct. We should
3041 * maintain a P2P peer database in wpa_supplicant and update
3042 * this information based on whether the peer is truly new.
3044 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3047 case EVENT_P2P_GO_NEG_REQ_RX:
3048 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3049 data->p2p_go_neg_req_rx.dev_passwd_id);
3051 case EVENT_P2P_GO_NEG_COMPLETED:
3052 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3054 case EVENT_P2P_PROV_DISC_REQUEST:
3055 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3056 data->p2p_prov_disc_req.config_methods,
3057 data->p2p_prov_disc_req.dev_addr,
3058 data->p2p_prov_disc_req.pri_dev_type,
3059 data->p2p_prov_disc_req.dev_name,
3060 data->p2p_prov_disc_req.supp_config_methods,
3061 data->p2p_prov_disc_req.dev_capab,
3062 data->p2p_prov_disc_req.group_capab,
3065 case EVENT_P2P_PROV_DISC_RESPONSE:
3066 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3067 data->p2p_prov_disc_resp.config_methods);
3069 case EVENT_P2P_SD_REQUEST:
3070 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3071 data->p2p_sd_req.sa,
3072 data->p2p_sd_req.dialog_token,
3073 data->p2p_sd_req.update_indic,
3074 data->p2p_sd_req.tlvs,
3075 data->p2p_sd_req.tlvs_len);
3077 case EVENT_P2P_SD_RESPONSE:
3078 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3079 data->p2p_sd_resp.update_indic,
3080 data->p2p_sd_resp.tlvs,
3081 data->p2p_sd_resp.tlvs_len);
3083 #endif /* CONFIG_P2P */
3084 case EVENT_EAPOL_RX:
3085 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3086 data->eapol_rx.data,
3087 data->eapol_rx.data_len);
3089 case EVENT_SIGNAL_CHANGE:
3090 bgscan_notify_signal_change(
3091 wpa_s, data->signal_change.above_threshold,
3092 data->signal_change.current_signal,
3093 data->signal_change.current_noise,
3094 data->signal_change.current_txrate);
3096 case EVENT_INTERFACE_ENABLED:
3097 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3098 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3099 wpa_supplicant_update_mac_addr(wpa_s);
3101 if (!wpa_s->ap_iface) {
3102 wpa_supplicant_set_state(wpa_s,
3104 wpa_supplicant_req_scan(wpa_s, 0, 0);
3106 wpa_supplicant_set_state(wpa_s,
3108 #else /* CONFIG_AP */
3109 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3110 wpa_supplicant_req_scan(wpa_s, 0, 0);
3111 #endif /* CONFIG_AP */
3114 case EVENT_INTERFACE_DISABLED:
3115 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3116 wpa_supplicant_mark_disassoc(wpa_s);
3117 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3119 case EVENT_CHANNEL_LIST_CHANGED:
3120 if (wpa_s->drv_priv == NULL)
3121 break; /* Ignore event during drv initialization */
3123 free_hw_features(wpa_s);
3124 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
3125 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3128 wpas_p2p_update_channel_list(wpa_s);
3129 #endif /* CONFIG_P2P */
3131 case EVENT_INTERFACE_UNAVAILABLE:
3133 wpas_p2p_interface_unavailable(wpa_s);
3134 #endif /* CONFIG_P2P */
3136 case EVENT_BEST_CHANNEL:
3137 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3139 data->best_chan.freq_24, data->best_chan.freq_5,
3140 data->best_chan.freq_overall);
3141 wpa_s->best_24_freq = data->best_chan.freq_24;
3142 wpa_s->best_5_freq = data->best_chan.freq_5;
3143 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3145 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3146 data->best_chan.freq_5,
3147 data->best_chan.freq_overall);
3148 #endif /* CONFIG_P2P */
3150 case EVENT_UNPROT_DEAUTH:
3151 wpa_supplicant_event_unprot_deauth(wpa_s,
3152 &data->unprot_deauth);
3154 case EVENT_UNPROT_DISASSOC:
3155 wpa_supplicant_event_unprot_disassoc(wpa_s,
3156 &data->unprot_disassoc);
3158 case EVENT_STATION_LOW_ACK:
3160 if (wpa_s->ap_iface && data)
3161 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3162 data->low_ack.addr);
3163 #endif /* CONFIG_AP */
3166 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3167 #endif /* CONFIG_TDLS */
3169 case EVENT_IBSS_PEER_LOST:
3170 #ifdef CONFIG_IBSS_RSN
3171 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3172 #endif /* CONFIG_IBSS_RSN */
3174 case EVENT_DRIVER_GTK_REKEY:
3175 if (os_memcmp(data->driver_gtk_rekey.bssid,
3176 wpa_s->bssid, ETH_ALEN))
3180 wpa_sm_update_replay_ctr(wpa_s->wpa,
3181 data->driver_gtk_rekey.replay_ctr);
3183 case EVENT_SCHED_SCAN_STOPPED:
3184 wpa_s->sched_scanning = 0;
3185 wpa_supplicant_notify_scanning(wpa_s, 0);
3187 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3191 * If we timed out, start a new sched scan to continue
3192 * searching for more SSIDs.
3194 if (wpa_s->sched_scan_timed_out)
3195 wpa_supplicant_req_sched_scan(wpa_s);
3197 case EVENT_WPS_BUTTON_PUSHED:
3199 wpas_wps_start_pbc(wpa_s, NULL, 0);
3200 #endif /* CONFIG_WPS */
3202 case EVENT_CONNECT_FAILED_REASON:
3204 if (!wpa_s->ap_iface || !data)
3206 hostapd_event_connect_failed_reason(
3207 wpa_s->ap_iface->bss[0],
3208 data->connect_failed_reason.addr,
3209 data->connect_failed_reason.code);
3210 #endif /* CONFIG_AP */
3213 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);