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",
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" : "");
723 e = wpa_blacklist_get(wpa_s, bss->bssid);
726 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
728 * When only a single network is enabled, we can
729 * trigger blacklisting on the first failure. This
730 * should not be done with multiple enabled networks to
731 * avoid getting forced to move into a worse ESS on
732 * single error if there are no other BSSes of the
737 if (e->count > limit) {
738 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
739 "(count=%d limit=%d)", e->count, limit);
744 if (bss->ssid_len == 0) {
745 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
749 if (disallowed_bssid(wpa_s, bss->bssid)) {
750 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
754 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
755 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
759 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
761 for (ssid = group; ssid; ssid = ssid->pnext) {
762 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
765 if (wpas_network_disabled(wpa_s, ssid)) {
766 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
770 res = wpas_temp_disabled(wpa_s, ssid);
772 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
773 "temporarily for %d second(s)", res);
778 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
779 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
784 if (wpa && ssid->ssid_len == 0 &&
785 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
788 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
789 /* Only allow wildcard SSID match if an AP
790 * advertises active WPS operation that matches
793 if (ssid->ssid_len == 0 &&
794 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
797 #endif /* CONFIG_WPS */
799 if (ssid->bssid_set && ssid->ssid_len == 0 &&
800 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
804 (bss->ssid_len != ssid->ssid_len ||
805 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
806 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
810 if (ssid->bssid_set &&
811 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
812 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
816 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
820 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
821 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
822 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
823 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
828 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
830 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
834 if (!wpa_supplicant_match_privacy(bss, ssid)) {
835 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
840 if (!bss_is_ess(bss)) {
841 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
845 if (!freq_allowed(ssid->freq_list, bss->freq)) {
846 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
851 if (!rate_match(wpa_s, bss)) {
852 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
859 * TODO: skip the AP if its P2P IE has Group Formation
860 * bit set in the P2P Group Capability Bitmap and we
861 * are not in Group Formation with that device.
863 #endif /* CONFIG_P2P */
865 /* Matching configuration found */
869 /* No matching configuration found */
874 static struct wpa_bss *
875 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
876 struct wpa_ssid *group,
877 struct wpa_ssid **selected_ssid)
881 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
884 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
885 struct wpa_bss *bss = wpa_s->last_scan_res[i];
886 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
889 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
892 wpa_ssid_txt(bss->ssid, bss->ssid_len));
900 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
901 struct wpa_ssid **selected_ssid)
903 struct wpa_bss *selected = NULL;
906 if (wpa_s->last_scan_res == NULL ||
907 wpa_s->last_scan_res_used == 0)
908 return NULL; /* no scan results from last update */
910 while (selected == NULL) {
911 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
912 selected = wpa_supplicant_select_bss(
913 wpa_s, wpa_s->conf->pssid[prio],
919 if (selected == NULL && wpa_s->blacklist &&
920 !wpa_s->countermeasures) {
921 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
922 "blacklist and try again");
923 wpa_blacklist_clear(wpa_s);
924 wpa_s->blacklist_cleared++;
925 } else if (selected == NULL)
933 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
934 int timeout_sec, int timeout_usec)
936 if (!wpa_supplicant_enabled_networks(wpa_s)) {
938 * No networks are enabled; short-circuit request so
939 * we don't wait timeout seconds before transitioning
942 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
943 "since there are no enabled networks");
944 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
946 wpa_s->sta_scan_pending = 0;
947 #endif /* CONFIG_P2P */
951 wpa_s->scan_for_connection = 1;
952 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
956 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
957 struct wpa_bss *selected,
958 struct wpa_ssid *ssid)
960 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
961 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
962 "PBC session overlap");
964 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
966 #endif /* CONFIG_P2P */
969 wpas_wps_cancel(wpa_s);
970 #endif /* CONFIG_WPS */
974 wpa_msg(wpa_s, MSG_DEBUG,
975 "Considering connect request: reassociate: %d selected: "
976 MACSTR " bssid: " MACSTR " pending: " MACSTR
977 " wpa_state: %s ssid=%p current_ssid=%p",
978 wpa_s->reassociate, MAC2STR(selected->bssid),
979 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
980 wpa_supplicant_state_txt(wpa_s->wpa_state),
981 ssid, wpa_s->current_ssid);
984 * Do not trigger new association unless the BSSID has changed or if
985 * reassociation is requested. If we are in process of associating with
986 * the selected BSSID, do not trigger new attempt.
988 if (wpa_s->reassociate ||
989 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
990 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
991 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
992 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
993 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
995 (is_zero_ether_addr(wpa_s->pending_bssid) &&
996 ssid != wpa_s->current_ssid)))) {
997 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
998 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1001 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1002 MAC2STR(selected->bssid));
1003 wpa_supplicant_associate(wpa_s, selected, ssid);
1005 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1006 "connect with the selected AP");
1013 static struct wpa_ssid *
1014 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1017 struct wpa_ssid *ssid;
1019 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1020 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1022 if (wpas_network_disabled(wpa_s, ssid))
1024 if (ssid->mode == IEEE80211_MODE_IBSS ||
1025 ssid->mode == IEEE80211_MODE_AP)
1033 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1034 * on BSS added and BSS changed events */
1035 static void wpa_supplicant_rsn_preauth_scan_results(
1036 struct wpa_supplicant *wpa_s)
1038 struct wpa_bss *bss;
1040 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1043 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1044 const u8 *ssid, *rsn;
1046 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1050 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1054 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1060 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1061 struct wpa_bss *selected,
1062 struct wpa_ssid *ssid)
1064 struct wpa_bss *current_bss = NULL;
1067 if (wpa_s->reassociate)
1068 return 1; /* explicit request to reassociate */
1069 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1070 return 1; /* we are not associated; continue */
1071 if (wpa_s->current_ssid == NULL)
1072 return 1; /* unknown current SSID */
1073 if (wpa_s->current_ssid != ssid)
1074 return 1; /* different network block */
1076 if (wpas_driver_bss_selection(wpa_s))
1077 return 0; /* Driver-based roaming */
1079 if (wpa_s->current_ssid->ssid)
1080 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1081 wpa_s->current_ssid->ssid,
1082 wpa_s->current_ssid->ssid_len);
1084 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1087 return 1; /* current BSS not seen in scan results */
1089 if (current_bss == selected)
1092 if (selected->last_update_idx > current_bss->last_update_idx)
1093 return 1; /* current BSS not seen in the last scan */
1095 #ifndef CONFIG_NO_ROAMING
1096 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1097 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1098 MAC2STR(current_bss->bssid), current_bss->level);
1099 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1100 MAC2STR(selected->bssid), selected->level);
1102 if (wpa_s->current_ssid->bssid_set &&
1103 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1105 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1106 "has preferred BSSID");
1110 if (current_bss->level < 0 && current_bss->level > selected->level) {
1111 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1117 if (current_bss->level < 0) {
1118 if (current_bss->level < -85)
1120 else if (current_bss->level < -80)
1122 else if (current_bss->level < -75)
1124 else if (current_bss->level < -70)
1129 if (abs(current_bss->level - selected->level) < min_diff) {
1130 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1136 #else /* CONFIG_NO_ROAMING */
1138 #endif /* CONFIG_NO_ROAMING */
1142 /* Return != 0 if no scan results could be fetched or if scan results should not
1143 * be shared with other virtual interfaces. */
1144 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1145 union wpa_event_data *data,
1148 struct wpa_scan_results *scan_res;
1150 #ifndef CONFIG_NO_RANDOM_POOL
1152 #endif /* CONFIG_NO_RANDOM_POOL */
1155 if (wpa_s->ap_iface)
1157 #endif /* CONFIG_AP */
1159 wpa_supplicant_notify_scanning(wpa_s, 0);
1162 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1163 !wpa_s->global->p2p_disabled &&
1164 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1165 !wpa_s->scan_res_handler) {
1166 wpa_s->global->p2p_cb_on_scan_complete = 0;
1167 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1168 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1169 "stopped scan processing");
1170 wpa_s->sta_scan_pending = 1;
1171 wpa_supplicant_req_scan(wpa_s, 5, 0);
1175 wpa_s->sta_scan_pending = 0;
1176 #endif /* CONFIG_P2P */
1178 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1179 data ? &data->scan_info :
1181 if (scan_res == NULL) {
1182 if (wpa_s->conf->ap_scan == 2 || ap ||
1183 wpa_s->scan_res_handler == scan_only_handler)
1187 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1189 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1193 #ifndef CONFIG_NO_RANDOM_POOL
1194 num = scan_res->num;
1197 for (i = 0; i < num; i++) {
1199 struct wpa_scan_res *res = scan_res->res[i];
1200 buf[0] = res->bssid[5];
1201 buf[1] = res->qual & 0xff;
1202 buf[2] = res->noise & 0xff;
1203 buf[3] = res->level & 0xff;
1204 buf[4] = res->tsf & 0xff;
1205 random_add_randomness(buf, sizeof(buf));
1207 #endif /* CONFIG_NO_RANDOM_POOL */
1209 if (own_request && wpa_s->scan_res_handler) {
1210 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1211 struct wpa_scan_results *scan_res);
1213 scan_res_handler = wpa_s->scan_res_handler;
1214 wpa_s->scan_res_handler = NULL;
1215 scan_res_handler(wpa_s, scan_res);
1217 wpa_scan_results_free(scan_res);
1222 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1224 if (wpa_s->ap_iface->scan_cb)
1225 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1226 #endif /* CONFIG_AP */
1227 wpa_scan_results_free(scan_res);
1231 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1232 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1233 wpas_notify_scan_results(wpa_s);
1235 wpas_notify_scan_done(wpa_s, 1);
1237 if (sme_proc_obss_scan(wpa_s) > 0) {
1238 wpa_scan_results_free(scan_res);
1242 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1243 wpa_scan_results_free(scan_res);
1247 if (autoscan_notify_scan(wpa_s, scan_res)) {
1248 wpa_scan_results_free(scan_res);
1252 if (wpa_s->disconnected) {
1253 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1254 wpa_scan_results_free(scan_res);
1258 if (!wpas_driver_bss_selection(wpa_s) &&
1259 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1260 wpa_scan_results_free(scan_res);
1264 wpas_wps_update_ap_info(wpa_s, scan_res);
1266 wpa_scan_results_free(scan_res);
1268 return wpas_select_network_from_last_scan(wpa_s, 1);
1272 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1275 struct wpa_bss *selected;
1276 struct wpa_ssid *ssid = NULL;
1278 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1282 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1285 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1289 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1290 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1294 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1296 * Do not notify other virtual radios of scan results since we do not
1297 * want them to start other associations at the same time.
1301 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1302 ssid = wpa_supplicant_pick_new_network(wpa_s);
1304 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1305 wpa_supplicant_associate(wpa_s, NULL, ssid);
1307 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1309 int timeout_sec = wpa_s->scan_interval;
1310 int timeout_usec = 0;
1312 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1315 if (wpa_s->p2p_in_provisioning) {
1317 * Use shorter wait during P2P Provisioning
1318 * state to speed up group formation.
1321 timeout_usec = 250000;
1322 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1326 #endif /* CONFIG_P2P */
1327 #ifdef CONFIG_INTERWORKING
1328 if (wpa_s->conf->auto_interworking &&
1329 wpa_s->conf->interworking &&
1330 wpa_s->conf->cred) {
1331 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1332 "start ANQP fetch since no matching "
1334 wpa_s->network_select = 1;
1335 wpa_s->auto_network_select = 1;
1336 interworking_start_fetch_anqp(wpa_s);
1339 #endif /* CONFIG_INTERWORKING */
1340 if (wpa_supplicant_req_sched_scan(wpa_s))
1341 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1349 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1350 union wpa_event_data *data)
1352 const char *rn, *rn2;
1353 struct wpa_supplicant *ifs;
1355 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1357 * If no scan results could be fetched, then no need to
1358 * notify those interfaces that did not actually request
1359 * this scan. Similarly, if scan results started a new operation on this
1360 * interface, do not notify other interfaces to avoid concurrent
1361 * operations during a connection attempt.
1367 * Check other interfaces to see if they have the same radio-name. If
1368 * so, they get updated with this same scan info.
1370 if (!wpa_s->driver->get_radio_name)
1373 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1374 if (rn == NULL || rn[0] == '\0')
1377 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1378 "sharing same radio (%s) in event_scan_results", rn);
1380 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1381 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1384 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1385 if (rn2 && os_strcmp(rn, rn2) == 0) {
1386 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1387 "sibling", ifs->ifname);
1388 _wpa_supplicant_event_scan_results(ifs, data, 0);
1393 #endif /* CONFIG_NO_SCAN_PROCESSING */
1396 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1398 #ifdef CONFIG_NO_SCAN_PROCESSING
1400 #else /* CONFIG_NO_SCAN_PROCESSING */
1403 if (wpa_s->last_scan_res_used <= 0)
1407 if (now.sec - wpa_s->last_scan.sec > 5) {
1408 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1412 return wpas_select_network_from_last_scan(wpa_s, 0);
1413 #endif /* CONFIG_NO_SCAN_PROCESSING */
1418 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1420 struct wpa_supplicant *wpa_s = eloop_ctx;
1422 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1425 if (!wpa_s->no_keep_alive) {
1426 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1427 MAC2STR(wpa_s->bssid));
1428 /* TODO: could skip this if normal data traffic has been sent */
1429 /* TODO: Consider using some more appropriate data frame for
1432 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1437 if (wpa_s->sme.bss_max_idle_period) {
1439 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1442 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1443 wnm_bss_keep_alive, wpa_s, NULL);
1445 #endif /* CONFIG_SME */
1449 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1450 const u8 *ies, size_t ies_len)
1452 struct ieee802_11_elems elems;
1457 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1461 if (elems.bss_max_idle_period) {
1463 wpa_s->sme.bss_max_idle_period =
1464 WPA_GET_LE16(elems.bss_max_idle_period);
1465 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1466 "TU)%s", wpa_s->sme.bss_max_idle_period,
1467 (elems.bss_max_idle_period[2] & 0x01) ?
1468 " (protected keep-live required)" : "");
1469 if (wpa_s->sme.bss_max_idle_period == 0)
1470 wpa_s->sme.bss_max_idle_period = 1;
1471 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1472 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1473 /* msec times 1000 */
1474 msec = wpa_s->sme.bss_max_idle_period * 1024;
1477 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1478 wnm_bss_keep_alive, wpa_s,
1482 #endif /* CONFIG_SME */
1485 #endif /* CONFIG_WNM */
1488 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1491 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1492 #endif /* CONFIG_WNM */
1496 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1497 union wpa_event_data *data)
1499 int l, len, found = 0, wpa_found, rsn_found;
1501 #ifdef CONFIG_IEEE80211R
1503 #endif /* CONFIG_IEEE80211R */
1505 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1506 if (data->assoc_info.req_ies)
1507 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1508 data->assoc_info.req_ies_len);
1509 if (data->assoc_info.resp_ies) {
1510 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1511 data->assoc_info.resp_ies_len);
1513 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1514 data->assoc_info.resp_ies_len);
1515 #endif /* CONFIG_TDLS */
1517 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1518 data->assoc_info.resp_ies_len);
1519 #endif /* CONFIG_WNM */
1521 if (data->assoc_info.beacon_ies)
1522 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1523 data->assoc_info.beacon_ies,
1524 data->assoc_info.beacon_ies_len);
1525 if (data->assoc_info.freq)
1526 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1527 data->assoc_info.freq);
1529 p = data->assoc_info.req_ies;
1530 l = data->assoc_info.req_ies_len;
1532 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1533 while (p && l >= 2) {
1536 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1540 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1541 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1542 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1543 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1546 wpa_find_assoc_pmkid(wpa_s);
1552 if (!found && data->assoc_info.req_ies)
1553 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1555 #ifdef CONFIG_IEEE80211R
1557 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1558 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1559 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1560 data->assoc_info.resp_ies,
1561 data->assoc_info.resp_ies_len,
1563 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1564 "Reassociation Response failed");
1565 wpa_supplicant_deauthenticate(
1566 wpa_s, WLAN_REASON_INVALID_IE);
1571 p = data->assoc_info.resp_ies;
1572 l = data->assoc_info.resp_ies_len;
1574 #ifdef CONFIG_WPS_STRICT
1575 if (p && wpa_s->current_ssid &&
1576 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1578 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1580 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1581 "include WPS IE in (Re)Association Response");
1585 if (wps_validate_assoc_resp(wps) < 0) {
1587 wpa_supplicant_deauthenticate(
1588 wpa_s, WLAN_REASON_INVALID_IE);
1593 #endif /* CONFIG_WPS_STRICT */
1595 /* Go through the IEs and make a copy of the MDIE, if present. */
1596 while (p && l >= 2) {
1599 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1603 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1604 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1605 wpa_s->sme.ft_used = 1;
1606 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1607 MOBILITY_DOMAIN_ID_LEN);
1613 #endif /* CONFIG_SME */
1615 /* Process FT when SME is in the driver */
1616 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1617 wpa_ft_is_completed(wpa_s->wpa)) {
1618 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1619 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1620 data->assoc_info.resp_ies,
1621 data->assoc_info.resp_ies_len,
1623 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1624 "Reassociation Response failed");
1625 wpa_supplicant_deauthenticate(
1626 wpa_s, WLAN_REASON_INVALID_IE);
1629 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1632 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1633 data->assoc_info.resp_ies_len);
1634 #endif /* CONFIG_IEEE80211R */
1636 /* WPA/RSN IE from Beacon/ProbeResp */
1637 p = data->assoc_info.beacon_ies;
1638 l = data->assoc_info.beacon_ies_len;
1640 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1642 wpa_found = rsn_found = 0;
1643 while (p && l >= 2) {
1646 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1651 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1652 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1654 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1658 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1660 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1667 if (!wpa_found && data->assoc_info.beacon_ies)
1668 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1669 if (!rsn_found && data->assoc_info.beacon_ies)
1670 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1671 if (wpa_found || rsn_found)
1672 wpa_s->ap_ies_from_associnfo = 1;
1674 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1675 wpa_s->assoc_freq != data->assoc_info.freq) {
1676 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1678 wpa_s->assoc_freq, data->assoc_info.freq);
1679 wpa_supplicant_update_scan_results(wpa_s);
1682 wpa_s->assoc_freq = data->assoc_info.freq;
1688 static struct wpa_bss * wpa_supplicant_get_new_bss(
1689 struct wpa_supplicant *wpa_s, const u8 *bssid)
1691 struct wpa_bss *bss = NULL;
1692 struct wpa_ssid *ssid = wpa_s->current_ssid;
1694 if (ssid->ssid_len > 0)
1695 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1697 bss = wpa_bss_get_bssid(wpa_s, bssid);
1703 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1705 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1707 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1710 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1713 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1714 WPA_IE_VENDOR_TYPE);
1715 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1717 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1718 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1719 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1720 bss_rsn ? 2 + bss_rsn[1] : 0))
1727 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1728 union wpa_event_data *data)
1734 if (wpa_s->ap_iface) {
1735 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1736 data->assoc_info.addr,
1737 data->assoc_info.req_ies,
1738 data->assoc_info.req_ies_len,
1739 data->assoc_info.reassoc);
1742 #endif /* CONFIG_AP */
1744 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1745 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1748 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1749 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1750 wpa_supplicant_deauthenticate(
1751 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1755 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1756 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1757 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1758 MACSTR, MAC2STR(bssid));
1759 random_add_randomness(bssid, ETH_ALEN);
1760 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1761 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1762 wpas_notify_bssid_changed(wpa_s);
1764 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1765 wpa_clear_keys(wpa_s, bssid);
1767 if (wpa_supplicant_select_config(wpa_s) < 0) {
1768 wpa_supplicant_deauthenticate(
1769 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1772 if (wpa_s->current_ssid) {
1773 struct wpa_bss *bss = NULL;
1775 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1777 wpa_supplicant_update_scan_results(wpa_s);
1779 /* Get the BSS from the new scan results */
1780 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1784 wpa_s->current_bss = bss;
1787 if (wpa_s->conf->ap_scan == 1 &&
1788 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1789 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1790 wpa_msg(wpa_s, MSG_WARNING,
1791 "WPA/RSN IEs not updated");
1796 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1797 wpa_s->sme.prev_bssid_set = 1;
1798 #endif /* CONFIG_SME */
1800 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1801 if (wpa_s->current_ssid) {
1802 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1803 * initialized before association, but for other modes,
1804 * initialize PC/SC here, if the current configuration needs
1805 * smartcard or SIM/USIM. */
1806 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1808 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1810 l2_packet_notify_auth_start(wpa_s->l2);
1813 * Set portEnabled first to FALSE in order to get EAP state machine out
1814 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1815 * state machine may transit to AUTHENTICATING state based on obsolete
1816 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1817 * AUTHENTICATED without ever giving chance to EAP state machine to
1820 if (!ft_completed) {
1821 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1822 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1824 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1825 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1826 /* 802.1X::portControl = Auto */
1827 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1828 wpa_s->eapol_received = 0;
1829 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1830 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1831 (wpa_s->current_ssid &&
1832 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1833 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1835 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1837 * Set the key after having received joined-IBSS event
1840 wpa_supplicant_set_wpa_none_key(wpa_s,
1841 wpa_s->current_ssid);
1843 wpa_supplicant_cancel_auth_timeout(wpa_s);
1844 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1845 } else if (!ft_completed) {
1846 /* Timeout for receiving the first EAPOL packet */
1847 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1849 wpa_supplicant_cancel_scan(wpa_s);
1851 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1852 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1854 * We are done; the driver will take care of RSN 4-way
1857 wpa_supplicant_cancel_auth_timeout(wpa_s);
1858 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1859 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1860 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1861 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1862 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1864 * The driver will take care of RSN 4-way handshake, so we need
1865 * to allow EAPOL supplicant to complete its work without
1866 * waiting for WPA supplicant.
1868 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1869 } else if (ft_completed) {
1871 * FT protocol completed - make sure EAPOL state machine ends
1872 * up in authenticated.
1874 wpa_supplicant_cancel_auth_timeout(wpa_s);
1875 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1876 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1877 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1880 wpa_s->last_eapol_matches_bssid = 0;
1882 if (wpa_s->pending_eapol_rx) {
1883 struct os_time now, age;
1885 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1886 if (age.sec == 0 && age.usec < 100000 &&
1887 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1889 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1890 "frame that was received just before "
1891 "association notification");
1892 wpa_supplicant_rx_eapol(
1893 wpa_s, wpa_s->pending_eapol_rx_src,
1894 wpabuf_head(wpa_s->pending_eapol_rx),
1895 wpabuf_len(wpa_s->pending_eapol_rx));
1897 wpabuf_free(wpa_s->pending_eapol_rx);
1898 wpa_s->pending_eapol_rx = NULL;
1901 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1902 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1903 wpa_s->current_ssid &&
1904 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1905 /* Set static WEP keys again */
1906 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1909 #ifdef CONFIG_IBSS_RSN
1910 if (wpa_s->current_ssid &&
1911 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1912 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1913 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1914 wpa_s->ibss_rsn == NULL) {
1915 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1916 if (!wpa_s->ibss_rsn) {
1917 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1918 wpa_supplicant_deauthenticate(
1919 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1923 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1925 #endif /* CONFIG_IBSS_RSN */
1927 wpas_wps_notify_assoc(wpa_s, bssid);
1931 static int disconnect_reason_recoverable(u16 reason_code)
1933 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1934 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1935 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1939 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1941 int locally_generated)
1945 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1947 * At least Host AP driver and a Prism3 card seemed to be
1948 * generating streams of disconnected events when configuring
1949 * IBSS for WPA-None. Ignore them for now.
1954 bssid = wpa_s->bssid;
1955 if (is_zero_ether_addr(bssid))
1956 bssid = wpa_s->pending_bssid;
1958 if (!is_zero_ether_addr(bssid) ||
1959 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1960 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1962 MAC2STR(bssid), reason_code,
1963 locally_generated ? " locally_generated=1" : "");
1968 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1969 int locally_generated)
1971 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1972 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1973 return 0; /* Not in 4-way handshake with PSK */
1976 * It looks like connection was lost while trying to go through PSK
1977 * 4-way handshake. Filter out known disconnection cases that are caused
1978 * by something else than PSK mismatch to avoid confusing reports.
1981 if (locally_generated) {
1982 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1990 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1992 int locally_generated)
1996 u8 prev_pending_bssid[ETH_ALEN];
1997 struct wpa_bss *fast_reconnect = NULL;
1998 #ifndef CONFIG_NO_SCAN_PROCESSING
1999 struct wpa_ssid *fast_reconnect_ssid = NULL;
2000 #endif /* CONFIG_NO_SCAN_PROCESSING */
2001 struct wpa_ssid *last_ssid;
2003 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2004 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2006 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2008 * At least Host AP driver and a Prism3 card seemed to be
2009 * generating streams of disconnected events when configuring
2010 * IBSS for WPA-None. Ignore them for now.
2012 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2013 "IBSS/WPA-None mode");
2017 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2018 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2019 "pre-shared key may be incorrect");
2020 wpas_auth_failed(wpa_s);
2022 if (!wpa_s->disconnected &&
2023 (!wpa_s->auto_reconnect_disabled ||
2024 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
2025 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2026 "reconnect (wps=%d wpa_state=%d)",
2027 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2029 if (wpa_s->wpa_state == WPA_COMPLETED &&
2030 wpa_s->current_ssid &&
2031 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2032 !locally_generated &&
2033 disconnect_reason_recoverable(reason_code)) {
2035 * It looks like the AP has dropped association with
2036 * us, but could allow us to get back in. Try to
2037 * reconnect to the same BSS without full scan to save
2038 * time for some common cases.
2040 fast_reconnect = wpa_s->current_bss;
2041 #ifndef CONFIG_NO_SCAN_PROCESSING
2042 fast_reconnect_ssid = wpa_s->current_ssid;
2043 #endif /* CONFIG_NO_SCAN_PROCESSING */
2044 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2045 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2047 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2050 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2051 "try to re-connect");
2052 wpa_s->reassociate = 0;
2053 wpa_s->disconnected = 1;
2054 wpa_supplicant_cancel_sched_scan(wpa_s);
2056 bssid = wpa_s->bssid;
2057 if (is_zero_ether_addr(bssid))
2058 bssid = wpa_s->pending_bssid;
2059 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2060 wpas_connection_failed(wpa_s, bssid);
2061 wpa_sm_notify_disassoc(wpa_s->wpa);
2062 if (locally_generated)
2063 wpa_s->disconnect_reason = -reason_code;
2065 wpa_s->disconnect_reason = reason_code;
2066 wpas_notify_disconnect_reason(wpa_s);
2067 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2068 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2069 wpa_s->keys_cleared = 0;
2070 wpa_clear_keys(wpa_s, wpa_s->bssid);
2072 last_ssid = wpa_s->current_ssid;
2073 wpa_supplicant_mark_disassoc(wpa_s);
2075 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2076 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2077 wpa_s->current_ssid = last_ssid;
2080 if (fast_reconnect) {
2081 #ifndef CONFIG_NO_SCAN_PROCESSING
2082 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2083 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2084 fast_reconnect_ssid) < 0) {
2085 /* Recover through full scan */
2086 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2088 #endif /* CONFIG_NO_SCAN_PROCESSING */
2093 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2094 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2096 struct wpa_supplicant *wpa_s = eloop_ctx;
2098 if (!wpa_s->pending_mic_error_report)
2101 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2102 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2103 wpa_s->pending_mic_error_report = 0;
2105 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2109 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2110 union wpa_event_data *data)
2115 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2116 pairwise = (data && data->michael_mic_failure.unicast);
2118 if ((wpa_s->last_michael_mic_error &&
2119 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2120 wpa_s->pending_mic_error_report) {
2121 if (wpa_s->pending_mic_error_report) {
2123 * Send the pending MIC error report immediately since
2124 * we are going to start countermeasures and AP better
2127 wpa_sm_key_request(wpa_s->wpa, 1,
2128 wpa_s->pending_mic_error_pairwise);
2131 /* Send the new MIC error report immediately since we are going
2132 * to start countermeasures and AP better do the same.
2134 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2136 /* initialize countermeasures */
2137 wpa_s->countermeasures = 1;
2139 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2141 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2144 * Need to wait for completion of request frame. We do not get
2145 * any callback for the message completion, so just wait a
2146 * short while and hope for the best. */
2149 wpa_drv_set_countermeasures(wpa_s, 1);
2150 wpa_supplicant_deauthenticate(wpa_s,
2151 WLAN_REASON_MICHAEL_MIC_FAILURE);
2152 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2154 eloop_register_timeout(60, 0,
2155 wpa_supplicant_stop_countermeasures,
2157 /* TODO: mark the AP rejected for 60 second. STA is
2158 * allowed to associate with another AP.. */
2160 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2161 if (wpa_s->mic_errors_seen) {
2163 * Reduce the effectiveness of Michael MIC error
2164 * reports as a means for attacking against TKIP if
2165 * more than one MIC failure is noticed with the same
2166 * PTK. We delay the transmission of the reports by a
2167 * random time between 0 and 60 seconds in order to
2168 * force the attacker wait 60 seconds before getting
2169 * the information on whether a frame resulted in a MIC
2175 if (os_get_random(rval, sizeof(rval)) < 0)
2176 sec = os_random() % 60;
2178 sec = WPA_GET_BE32(rval) % 60;
2179 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2180 "report %d seconds", sec);
2181 wpa_s->pending_mic_error_report = 1;
2182 wpa_s->pending_mic_error_pairwise = pairwise;
2183 eloop_cancel_timeout(
2184 wpa_supplicant_delayed_mic_error_report,
2186 eloop_register_timeout(
2187 sec, os_random() % 1000000,
2188 wpa_supplicant_delayed_mic_error_report,
2191 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2193 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2194 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2195 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2197 wpa_s->last_michael_mic_error = t.sec;
2198 wpa_s->mic_errors_seen++;
2202 #ifdef CONFIG_TERMINATE_ONLASTIF
2203 static int any_interfaces(struct wpa_supplicant *head)
2205 struct wpa_supplicant *wpa_s;
2207 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2208 if (!wpa_s->interface_removed)
2212 #endif /* CONFIG_TERMINATE_ONLASTIF */
2216 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2217 union wpa_event_data *data)
2219 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2222 switch (data->interface_status.ievent) {
2223 case EVENT_INTERFACE_ADDED:
2224 if (!wpa_s->interface_removed)
2226 wpa_s->interface_removed = 0;
2227 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2228 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2229 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2230 "driver after interface was added");
2232 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2234 case EVENT_INTERFACE_REMOVED:
2235 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2236 wpa_s->interface_removed = 1;
2237 wpa_supplicant_mark_disassoc(wpa_s);
2238 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2239 l2_packet_deinit(wpa_s->l2);
2241 #ifdef CONFIG_IBSS_RSN
2242 ibss_rsn_deinit(wpa_s->ibss_rsn);
2243 wpa_s->ibss_rsn = NULL;
2244 #endif /* CONFIG_IBSS_RSN */
2245 #ifdef CONFIG_TERMINATE_ONLASTIF
2246 /* check if last interface */
2247 if (!any_interfaces(wpa_s->global->ifaces))
2249 #endif /* CONFIG_TERMINATE_ONLASTIF */
2255 #ifdef CONFIG_PEERKEY
2257 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2258 union wpa_event_data *data)
2262 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2264 #endif /* CONFIG_PEERKEY */
2268 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2269 union wpa_event_data *data)
2273 switch (data->tdls.oper) {
2274 case TDLS_REQUEST_SETUP:
2275 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2276 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2277 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2279 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2281 case TDLS_REQUEST_TEARDOWN:
2282 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2283 data->tdls.reason_code);
2287 #endif /* CONFIG_TDLS */
2291 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2292 union wpa_event_data *data)
2296 switch (data->wnm.oper) {
2297 case WNM_OPER_SLEEP:
2298 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2299 "(action=%d, intval=%d)",
2300 data->wnm.sleep_action, data->wnm.sleep_intval);
2301 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2302 data->wnm.sleep_intval, NULL);
2306 #endif /* CONFIG_WNM */
2309 #ifdef CONFIG_IEEE80211R
2311 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2312 union wpa_event_data *data)
2317 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2318 data->ft_ies.ies_len,
2319 data->ft_ies.ft_action,
2320 data->ft_ies.target_ap,
2321 data->ft_ies.ric_ies,
2322 data->ft_ies.ric_ies_len) < 0) {
2323 /* TODO: prevent MLME/driver from trying to associate? */
2326 #endif /* CONFIG_IEEE80211R */
2329 #ifdef CONFIG_IBSS_RSN
2330 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2331 union wpa_event_data *data)
2333 struct wpa_ssid *ssid;
2334 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2338 ssid = wpa_s->current_ssid;
2341 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2344 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2348 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2349 union wpa_event_data *data)
2351 struct wpa_ssid *ssid = wpa_s->current_ssid;
2356 /* check if the ssid is correctly configured as IBSS/RSN */
2357 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2360 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2361 data->rx_mgmt.frame_len);
2363 #endif /* CONFIG_IBSS_RSN */
2366 #ifdef CONFIG_IEEE80211R
2367 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2370 const u8 *sta_addr, *target_ap_addr;
2373 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2374 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2375 return; /* only SME case supported for now */
2376 if (len < 1 + 2 * ETH_ALEN + 2)
2379 return; /* Only FT Action Response is supported for now */
2380 sta_addr = data + 1;
2381 target_ap_addr = data + 1 + ETH_ALEN;
2382 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2383 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2384 MACSTR " TargetAP " MACSTR " status %u",
2385 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2387 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2388 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2389 " in FT Action Response", MAC2STR(sta_addr));
2394 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2395 "failure (status code %d)", status);
2396 /* TODO: report error to FT code(?) */
2400 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2401 len - (1 + 2 * ETH_ALEN + 2), 1,
2402 target_ap_addr, NULL, 0) < 0)
2407 struct wpa_bss *bss;
2408 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2410 wpa_s->sme.freq = bss->freq;
2411 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2412 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2415 #endif /* CONFIG_SME */
2417 #endif /* CONFIG_IEEE80211R */
2420 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2421 struct unprot_deauth *e)
2423 #ifdef CONFIG_IEEE80211W
2424 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2425 "dropped: " MACSTR " -> " MACSTR
2426 " (reason code %u)",
2427 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2428 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2429 #endif /* CONFIG_IEEE80211W */
2433 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2434 struct unprot_disassoc *e)
2436 #ifdef CONFIG_IEEE80211W
2437 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2438 "dropped: " MACSTR " -> " MACSTR
2439 " (reason code %u)",
2440 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2441 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2442 #endif /* CONFIG_IEEE80211W */
2446 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2447 u16 reason_code, int locally_generated,
2448 const u8 *ie, size_t ie_len, int deauth)
2451 if (wpa_s->ap_iface && addr) {
2452 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2456 if (wpa_s->ap_iface) {
2457 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2460 #endif /* CONFIG_AP */
2462 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2464 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2465 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2466 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2467 eapol_sm_failed(wpa_s->eapol)))
2468 wpas_auth_failed(wpa_s);
2471 if (deauth && reason_code > 0) {
2472 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2473 locally_generated) > 0) {
2475 * The interface was removed, so cannot continue
2476 * processing any additional operations after this.
2481 #endif /* CONFIG_P2P */
2483 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2488 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2489 struct disassoc_info *info)
2491 u16 reason_code = 0;
2492 int locally_generated = 0;
2493 const u8 *addr = NULL;
2494 const u8 *ie = NULL;
2497 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2502 ie_len = info->ie_len;
2503 reason_code = info->reason_code;
2504 locally_generated = info->locally_generated;
2505 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2506 locally_generated ? " (locally generated)" : "");
2508 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2510 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2515 if (wpa_s->ap_iface && info && info->addr) {
2516 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2520 if (wpa_s->ap_iface) {
2521 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2524 #endif /* CONFIG_AP */
2528 wpas_p2p_disassoc_notif(
2529 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2532 #endif /* CONFIG_P2P */
2534 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2535 sme_event_disassoc(wpa_s, info);
2537 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2542 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2543 struct deauth_info *info)
2545 u16 reason_code = 0;
2546 int locally_generated = 0;
2547 const u8 *addr = NULL;
2548 const u8 *ie = NULL;
2551 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2556 ie_len = info->ie_len;
2557 reason_code = info->reason_code;
2558 locally_generated = info->locally_generated;
2559 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2561 locally_generated ? " (locally generated)" : "");
2563 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2566 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2570 wpa_reset_ft_completed(wpa_s->wpa);
2572 wpas_event_disconnect(wpa_s, addr, reason_code,
2573 locally_generated, ie, ie_len, 1);
2577 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2578 union wpa_event_data *data)
2580 struct wpa_supplicant *wpa_s = ctx;
2582 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2583 event != EVENT_INTERFACE_ENABLED &&
2584 event != EVENT_INTERFACE_STATUS &&
2585 event != EVENT_SCHED_SCAN_STOPPED) {
2586 wpa_dbg(wpa_s, MSG_DEBUG,
2587 "Ignore event %s (%d) while interface is disabled",
2588 event_to_string(event), event);
2592 #ifndef CONFIG_NO_STDOUT_DEBUG
2594 int level = MSG_DEBUG;
2596 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2597 const struct ieee80211_hdr *hdr;
2599 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2600 fc = le_to_host16(hdr->frame_control);
2601 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2602 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2603 level = MSG_EXCESSIVE;
2606 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2607 event_to_string(event), event);
2609 #endif /* CONFIG_NO_STDOUT_DEBUG */
2613 sme_event_auth(wpa_s, data);
2616 wpa_supplicant_event_assoc(wpa_s, data);
2618 case EVENT_DISASSOC:
2619 wpas_event_disassoc(wpa_s,
2620 data ? &data->disassoc_info : NULL);
2623 wpas_event_deauth(wpa_s,
2624 data ? &data->deauth_info : NULL);
2626 case EVENT_MICHAEL_MIC_FAILURE:
2627 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2629 #ifndef CONFIG_NO_SCAN_PROCESSING
2630 case EVENT_SCAN_RESULTS:
2631 wpa_supplicant_event_scan_results(wpa_s, data);
2632 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2633 wpa_s->wpa_state != WPA_ASSOCIATING)
2634 wpas_p2p_continue_after_scan(wpa_s);
2636 #endif /* CONFIG_NO_SCAN_PROCESSING */
2637 case EVENT_ASSOCINFO:
2638 wpa_supplicant_event_associnfo(wpa_s, data);
2640 case EVENT_INTERFACE_STATUS:
2641 wpa_supplicant_event_interface_status(wpa_s, data);
2643 case EVENT_PMKID_CANDIDATE:
2644 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2646 #ifdef CONFIG_PEERKEY
2647 case EVENT_STKSTART:
2648 wpa_supplicant_event_stkstart(wpa_s, data);
2650 #endif /* CONFIG_PEERKEY */
2653 wpa_supplicant_event_tdls(wpa_s, data);
2655 #endif /* CONFIG_TDLS */
2658 wpa_supplicant_event_wnm(wpa_s, data);
2660 #endif /* CONFIG_WNM */
2661 #ifdef CONFIG_IEEE80211R
2662 case EVENT_FT_RESPONSE:
2663 wpa_supplicant_event_ft_response(wpa_s, data);
2665 #endif /* CONFIG_IEEE80211R */
2666 #ifdef CONFIG_IBSS_RSN
2667 case EVENT_IBSS_RSN_START:
2668 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2670 #endif /* CONFIG_IBSS_RSN */
2671 case EVENT_ASSOC_REJECT:
2672 if (data->assoc_reject.bssid)
2673 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2674 "bssid=" MACSTR " status_code=%u",
2675 MAC2STR(data->assoc_reject.bssid),
2676 data->assoc_reject.status_code);
2678 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2680 data->assoc_reject.status_code);
2681 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2682 sme_event_assoc_reject(wpa_s, data);
2684 const u8 *bssid = data->assoc_reject.bssid;
2685 if (bssid == NULL || is_zero_ether_addr(bssid))
2686 bssid = wpa_s->pending_bssid;
2687 wpas_connection_failed(wpa_s, bssid);
2688 wpa_supplicant_mark_disassoc(wpa_s);
2691 case EVENT_AUTH_TIMED_OUT:
2692 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2693 sme_event_auth_timed_out(wpa_s, data);
2695 case EVENT_ASSOC_TIMED_OUT:
2696 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2697 sme_event_assoc_timed_out(wpa_s, data);
2699 case EVENT_TX_STATUS:
2700 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2701 " type=%d stype=%d",
2702 MAC2STR(data->tx_status.dst),
2703 data->tx_status.type, data->tx_status.stype);
2705 if (wpa_s->ap_iface == NULL) {
2706 #ifdef CONFIG_OFFCHANNEL
2707 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2708 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2709 offchannel_send_action_tx_status(
2710 wpa_s, data->tx_status.dst,
2711 data->tx_status.data,
2712 data->tx_status.data_len,
2713 data->tx_status.ack ?
2714 OFFCHANNEL_SEND_ACTION_SUCCESS :
2715 OFFCHANNEL_SEND_ACTION_NO_ACK);
2716 #endif /* CONFIG_OFFCHANNEL */
2719 #endif /* CONFIG_AP */
2720 #ifdef CONFIG_OFFCHANNEL
2721 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2722 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2724 * Catch TX status events for Action frames we sent via group
2725 * interface in GO mode.
2727 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2728 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2729 os_memcmp(wpa_s->parent->pending_action_dst,
2730 data->tx_status.dst, ETH_ALEN) == 0) {
2731 offchannel_send_action_tx_status(
2732 wpa_s->parent, data->tx_status.dst,
2733 data->tx_status.data,
2734 data->tx_status.data_len,
2735 data->tx_status.ack ?
2736 OFFCHANNEL_SEND_ACTION_SUCCESS :
2737 OFFCHANNEL_SEND_ACTION_NO_ACK);
2740 #endif /* CONFIG_OFFCHANNEL */
2742 switch (data->tx_status.type) {
2743 case WLAN_FC_TYPE_MGMT:
2744 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2745 data->tx_status.data_len,
2746 data->tx_status.stype,
2747 data->tx_status.ack);
2749 case WLAN_FC_TYPE_DATA:
2750 ap_tx_status(wpa_s, data->tx_status.dst,
2751 data->tx_status.data,
2752 data->tx_status.data_len,
2753 data->tx_status.ack);
2756 #endif /* CONFIG_AP */
2759 case EVENT_EAPOL_TX_STATUS:
2760 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2761 data->eapol_tx_status.data,
2762 data->eapol_tx_status.data_len,
2763 data->eapol_tx_status.ack);
2765 case EVENT_DRIVER_CLIENT_POLL_OK:
2766 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2768 case EVENT_RX_FROM_UNKNOWN:
2769 if (wpa_s->ap_iface == NULL)
2771 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2772 data->rx_from_unknown.wds);
2774 case EVENT_CH_SWITCH:
2777 if (!wpa_s->ap_iface) {
2778 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2779 "event in non-AP mode");
2783 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2784 data->ch_switch.ht_enabled,
2785 data->ch_switch.ch_offset);
2787 #endif /* CONFIG_AP */
2788 #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
2789 case EVENT_RX_MGMT: {
2791 const struct ieee80211_mgmt *mgmt;
2793 mgmt = (const struct ieee80211_mgmt *)
2794 data->rx_mgmt.frame;
2795 fc = le_to_host16(mgmt->frame_control);
2796 stype = WLAN_FC_GET_STYPE(fc);
2799 if (wpa_s->ap_iface == NULL) {
2800 #endif /* CONFIG_AP */
2802 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2803 data->rx_mgmt.frame_len > 24) {
2804 const u8 *src = mgmt->sa;
2805 const u8 *ie = mgmt->u.probe_req.variable;
2806 size_t ie_len = data->rx_mgmt.frame_len -
2807 (mgmt->u.probe_req.variable -
2808 data->rx_mgmt.frame);
2809 wpas_p2p_probe_req_rx(
2810 wpa_s, src, mgmt->da,
2811 mgmt->bssid, ie, ie_len,
2812 data->rx_mgmt.ssi_signal);
2815 #endif /* CONFIG_P2P */
2816 #ifdef CONFIG_IBSS_RSN
2817 if (stype == WLAN_FC_STYPE_AUTH &&
2818 data->rx_mgmt.frame_len >= 30) {
2819 wpa_supplicant_event_ibss_auth(wpa_s, data);
2822 #endif /* CONFIG_IBSS_RSN */
2823 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2824 "management frame in non-AP mode");
2829 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2830 data->rx_mgmt.frame_len > 24) {
2831 const u8 *ie = mgmt->u.probe_req.variable;
2832 size_t ie_len = data->rx_mgmt.frame_len -
2833 (mgmt->u.probe_req.variable -
2834 data->rx_mgmt.frame);
2836 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2837 mgmt->bssid, ie, ie_len,
2838 data->rx_mgmt.ssi_signal);
2841 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2842 #endif /* CONFIG_AP */
2845 #endif /* CONFIG_AP || CONFIG_IBSS_RSN */
2846 case EVENT_RX_ACTION:
2847 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2848 " Category=%u DataLen=%d freq=%d MHz",
2849 MAC2STR(data->rx_action.sa),
2850 data->rx_action.category, (int) data->rx_action.len,
2851 data->rx_action.freq);
2852 #ifdef CONFIG_IEEE80211R
2853 if (data->rx_action.category == WLAN_ACTION_FT) {
2854 ft_rx_action(wpa_s, data->rx_action.data,
2855 data->rx_action.len);
2858 #endif /* CONFIG_IEEE80211R */
2859 #ifdef CONFIG_IEEE80211W
2861 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2862 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2863 data->rx_action.data,
2864 data->rx_action.len);
2867 #endif /* CONFIG_SME */
2868 #endif /* CONFIG_IEEE80211W */
2870 if (data->rx_action.category == WLAN_ACTION_WNM) {
2871 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2874 #endif /* CONFIG_WNM */
2876 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2877 gas_query_rx(wpa_s->gas, data->rx_action.da,
2878 data->rx_action.sa, data->rx_action.bssid,
2879 data->rx_action.data, data->rx_action.len,
2880 data->rx_action.freq) == 0)
2882 #endif /* CONFIG_GAS */
2884 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2885 data->rx_action.len >= 4 &&
2886 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2887 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2888 "Response from " MACSTR,
2889 MAC2STR(data->rx_action.sa));
2892 #endif /* CONFIG_TDLS */
2894 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2896 data->rx_action.bssid,
2897 data->rx_action.category,
2898 data->rx_action.data,
2899 data->rx_action.len, data->rx_action.freq);
2900 #endif /* CONFIG_P2P */
2902 case EVENT_RX_PROBE_REQ:
2903 if (data->rx_probe_req.sa == NULL ||
2904 data->rx_probe_req.ie == NULL)
2907 if (wpa_s->ap_iface) {
2908 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2909 data->rx_probe_req.sa,
2910 data->rx_probe_req.da,
2911 data->rx_probe_req.bssid,
2912 data->rx_probe_req.ie,
2913 data->rx_probe_req.ie_len,
2914 data->rx_probe_req.ssi_signal);
2917 #endif /* CONFIG_AP */
2919 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2920 data->rx_probe_req.da,
2921 data->rx_probe_req.bssid,
2922 data->rx_probe_req.ie,
2923 data->rx_probe_req.ie_len,
2924 data->rx_probe_req.ssi_signal);
2925 #endif /* CONFIG_P2P */
2927 case EVENT_REMAIN_ON_CHANNEL:
2928 #ifdef CONFIG_OFFCHANNEL
2929 offchannel_remain_on_channel_cb(
2930 wpa_s, data->remain_on_channel.freq,
2931 data->remain_on_channel.duration);
2932 #endif /* CONFIG_OFFCHANNEL */
2934 wpas_p2p_remain_on_channel_cb(
2935 wpa_s, data->remain_on_channel.freq,
2936 data->remain_on_channel.duration);
2937 #endif /* CONFIG_P2P */
2939 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2940 #ifdef CONFIG_OFFCHANNEL
2941 offchannel_cancel_remain_on_channel_cb(
2942 wpa_s, data->remain_on_channel.freq);
2943 #endif /* CONFIG_OFFCHANNEL */
2945 wpas_p2p_cancel_remain_on_channel_cb(
2946 wpa_s, data->remain_on_channel.freq);
2947 #endif /* CONFIG_P2P */
2950 case EVENT_P2P_DEV_FOUND: {
2951 struct p2p_peer_info peer_info;
2953 os_memset(&peer_info, 0, sizeof(peer_info));
2954 if (data->p2p_dev_found.dev_addr)
2955 os_memcpy(peer_info.p2p_device_addr,
2956 data->p2p_dev_found.dev_addr, ETH_ALEN);
2957 if (data->p2p_dev_found.pri_dev_type)
2958 os_memcpy(peer_info.pri_dev_type,
2959 data->p2p_dev_found.pri_dev_type,
2960 sizeof(peer_info.pri_dev_type));
2961 if (data->p2p_dev_found.dev_name)
2962 os_strlcpy(peer_info.device_name,
2963 data->p2p_dev_found.dev_name,
2964 sizeof(peer_info.device_name));
2965 peer_info.config_methods = data->p2p_dev_found.config_methods;
2966 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2967 peer_info.group_capab = data->p2p_dev_found.group_capab;
2970 * FIX: new_device=1 is not necessarily correct. We should
2971 * maintain a P2P peer database in wpa_supplicant and update
2972 * this information based on whether the peer is truly new.
2974 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2977 case EVENT_P2P_GO_NEG_REQ_RX:
2978 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2979 data->p2p_go_neg_req_rx.dev_passwd_id);
2981 case EVENT_P2P_GO_NEG_COMPLETED:
2982 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2984 case EVENT_P2P_PROV_DISC_REQUEST:
2985 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2986 data->p2p_prov_disc_req.config_methods,
2987 data->p2p_prov_disc_req.dev_addr,
2988 data->p2p_prov_disc_req.pri_dev_type,
2989 data->p2p_prov_disc_req.dev_name,
2990 data->p2p_prov_disc_req.supp_config_methods,
2991 data->p2p_prov_disc_req.dev_capab,
2992 data->p2p_prov_disc_req.group_capab,
2995 case EVENT_P2P_PROV_DISC_RESPONSE:
2996 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2997 data->p2p_prov_disc_resp.config_methods);
2999 case EVENT_P2P_SD_REQUEST:
3000 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3001 data->p2p_sd_req.sa,
3002 data->p2p_sd_req.dialog_token,
3003 data->p2p_sd_req.update_indic,
3004 data->p2p_sd_req.tlvs,
3005 data->p2p_sd_req.tlvs_len);
3007 case EVENT_P2P_SD_RESPONSE:
3008 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3009 data->p2p_sd_resp.update_indic,
3010 data->p2p_sd_resp.tlvs,
3011 data->p2p_sd_resp.tlvs_len);
3013 #endif /* CONFIG_P2P */
3014 case EVENT_EAPOL_RX:
3015 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3016 data->eapol_rx.data,
3017 data->eapol_rx.data_len);
3019 case EVENT_SIGNAL_CHANGE:
3020 bgscan_notify_signal_change(
3021 wpa_s, data->signal_change.above_threshold,
3022 data->signal_change.current_signal,
3023 data->signal_change.current_noise,
3024 data->signal_change.current_txrate);
3026 case EVENT_INTERFACE_ENABLED:
3027 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3028 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3029 wpa_supplicant_update_mac_addr(wpa_s);
3031 if (!wpa_s->ap_iface) {
3032 wpa_supplicant_set_state(wpa_s,
3034 wpa_supplicant_req_scan(wpa_s, 0, 0);
3036 wpa_supplicant_set_state(wpa_s,
3038 #else /* CONFIG_AP */
3039 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3040 wpa_supplicant_req_scan(wpa_s, 0, 0);
3041 #endif /* CONFIG_AP */
3044 case EVENT_INTERFACE_DISABLED:
3045 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3046 wpa_supplicant_mark_disassoc(wpa_s);
3047 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3049 case EVENT_CHANNEL_LIST_CHANGED:
3050 if (wpa_s->drv_priv == NULL)
3051 break; /* Ignore event during drv initialization */
3053 free_hw_features(wpa_s);
3054 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
3055 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3058 wpas_p2p_update_channel_list(wpa_s);
3059 #endif /* CONFIG_P2P */
3061 case EVENT_INTERFACE_UNAVAILABLE:
3063 wpas_p2p_interface_unavailable(wpa_s);
3064 #endif /* CONFIG_P2P */
3066 case EVENT_BEST_CHANNEL:
3067 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3069 data->best_chan.freq_24, data->best_chan.freq_5,
3070 data->best_chan.freq_overall);
3071 wpa_s->best_24_freq = data->best_chan.freq_24;
3072 wpa_s->best_5_freq = data->best_chan.freq_5;
3073 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3075 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3076 data->best_chan.freq_5,
3077 data->best_chan.freq_overall);
3078 #endif /* CONFIG_P2P */
3080 case EVENT_UNPROT_DEAUTH:
3081 wpa_supplicant_event_unprot_deauth(wpa_s,
3082 &data->unprot_deauth);
3084 case EVENT_UNPROT_DISASSOC:
3085 wpa_supplicant_event_unprot_disassoc(wpa_s,
3086 &data->unprot_disassoc);
3088 case EVENT_STATION_LOW_ACK:
3090 if (wpa_s->ap_iface && data)
3091 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3092 data->low_ack.addr);
3093 #endif /* CONFIG_AP */
3096 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3097 #endif /* CONFIG_TDLS */
3099 case EVENT_IBSS_PEER_LOST:
3100 #ifdef CONFIG_IBSS_RSN
3101 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3102 #endif /* CONFIG_IBSS_RSN */
3104 case EVENT_DRIVER_GTK_REKEY:
3105 if (os_memcmp(data->driver_gtk_rekey.bssid,
3106 wpa_s->bssid, ETH_ALEN))
3110 wpa_sm_update_replay_ctr(wpa_s->wpa,
3111 data->driver_gtk_rekey.replay_ctr);
3113 case EVENT_SCHED_SCAN_STOPPED:
3114 wpa_s->sched_scanning = 0;
3115 wpa_supplicant_notify_scanning(wpa_s, 0);
3117 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3121 * If we timed out, start a new sched scan to continue
3122 * searching for more SSIDs.
3124 if (wpa_s->sched_scan_timed_out)
3125 wpa_supplicant_req_sched_scan(wpa_s);
3127 case EVENT_WPS_BUTTON_PUSHED:
3129 wpas_wps_start_pbc(wpa_s, NULL, 0);
3130 #endif /* CONFIG_WPS */
3132 case EVENT_CONNECT_FAILED_REASON:
3134 if (!wpa_s->ap_iface || !data)
3136 hostapd_event_connect_failed_reason(
3137 wpa_s->ap_iface->bss[0],
3138 data->connect_failed_reason.addr,
3139 data->connect_failed_reason.code);
3140 #endif /* CONFIG_AP */
3143 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);