2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, 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"
50 #ifndef CONFIG_NO_SCAN_PROCESSING
51 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
52 int new_scan, int own_request);
53 #endif /* CONFIG_NO_SCAN_PROCESSING */
56 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
59 struct os_reltime now;
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
65 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
74 static struct wpa_bss * wpa_supplicant_get_new_bss(
75 struct wpa_supplicant *wpa_s, const u8 *bssid)
77 struct wpa_bss *bss = NULL;
78 struct wpa_ssid *ssid = wpa_s->current_ssid;
80 if (ssid->ssid_len > 0)
81 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
83 bss = wpa_bss_get_bssid(wpa_s, bssid);
89 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
91 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
94 wpa_supplicant_update_scan_results(wpa_s);
96 /* Get the BSS from the new scan results */
97 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
101 wpa_s->current_bss = bss;
105 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
107 struct wpa_ssid *ssid, *old_ssid;
110 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
111 wpa_supplicant_update_current_bss(wpa_s);
115 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
117 ssid = wpa_supplicant_get_ssid(wpa_s);
119 wpa_msg(wpa_s, MSG_INFO,
120 "No network configuration found for the current AP");
124 if (wpas_network_disabled(wpa_s, ssid)) {
125 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
129 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
130 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
131 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
135 res = wpas_temp_disabled(wpa_s, ssid);
137 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
138 "disabled for %d second(s)", res);
142 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
144 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
146 size_t wpa_ie_len = sizeof(wpa_ie);
147 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
148 wpa_ie, &wpa_ie_len) < 0)
149 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
151 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
154 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
155 eapol_sm_invalidate_cached_session(wpa_s->eapol);
156 old_ssid = wpa_s->current_ssid;
157 wpa_s->current_ssid = ssid;
159 wpa_supplicant_update_current_bss(wpa_s);
161 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
162 wpa_supplicant_initiate_eapol(wpa_s);
163 if (old_ssid != wpa_s->current_ssid)
164 wpas_notify_network_changed(wpa_s);
170 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
172 struct wpa_supplicant *wpa_s = eloop_ctx;
174 if (wpa_s->countermeasures) {
175 wpa_s->countermeasures = 0;
176 wpa_drv_set_countermeasures(wpa_s, 0);
177 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
178 wpa_supplicant_req_scan(wpa_s, 0, 0);
183 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
187 wnm_bss_keep_alive_deinit(wpa_s);
189 #ifdef CONFIG_IBSS_RSN
190 ibss_rsn_deinit(wpa_s->ibss_rsn);
191 wpa_s->ibss_rsn = NULL;
192 #endif /* CONFIG_IBSS_RSN */
195 wpa_supplicant_ap_deinit(wpa_s);
196 #endif /* CONFIG_AP */
198 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
201 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
202 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
203 os_memset(wpa_s->bssid, 0, ETH_ALEN);
204 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
205 sme_clear_on_disassoc(wpa_s);
207 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
208 #endif /* CONFIG_P2P */
209 wpa_s->current_bss = NULL;
210 wpa_s->assoc_freq = 0;
213 wpas_notify_bssid_changed(wpa_s);
215 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
216 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
217 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
218 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
219 wpa_s->ap_ies_from_associnfo = 0;
220 wpa_s->current_ssid = NULL;
221 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
224 wpas_rrm_reset(wpa_s);
228 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
230 struct wpa_ie_data ie;
234 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
238 for (i = 0; i < ie.num_pmkid; i++) {
239 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
240 ie.pmkid + i * PMKID_LEN,
242 if (pmksa_set == 0) {
243 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
248 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
249 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
253 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
254 union wpa_event_data *data)
257 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
261 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
262 " index=%d preauth=%d",
263 MAC2STR(data->pmkid_candidate.bssid),
264 data->pmkid_candidate.index,
265 data->pmkid_candidate.preauth);
267 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
268 data->pmkid_candidate.index,
269 data->pmkid_candidate.preauth);
273 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
275 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
276 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
279 #ifdef IEEE8021X_EAPOL
280 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
281 wpa_s->current_ssid &&
282 !(wpa_s->current_ssid->eapol_flags &
283 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
284 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
285 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
286 * plaintext or static WEP keys). */
289 #endif /* IEEE8021X_EAPOL */
296 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
297 * @wpa_s: pointer to wpa_supplicant data
298 * @ssid: Configuration data for the network
299 * Returns: 0 on success, -1 on failure
301 * This function is called when starting authentication with a network that is
302 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
304 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
305 struct wpa_ssid *ssid)
307 #ifdef IEEE8021X_EAPOL
309 int aka = 0, sim = 0;
311 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
312 wpa_s->scard != NULL || wpa_s->conf->external_sim)
315 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
319 struct eap_method_type *eap = ssid->eap.eap_methods;
320 while (eap->vendor != EAP_VENDOR_IETF ||
321 eap->method != EAP_TYPE_NONE) {
322 if (eap->vendor == EAP_VENDOR_IETF) {
323 if (eap->method == EAP_TYPE_SIM)
325 else if (eap->method == EAP_TYPE_AKA ||
326 eap->method == EAP_TYPE_AKA_PRIME)
333 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
335 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
336 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
341 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
342 "use SIM, but neither EAP-SIM nor EAP-AKA are "
347 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
348 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
350 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
351 if (wpa_s->scard == NULL) {
352 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
356 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
357 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
358 #endif /* PCSC_FUNCS */
359 #endif /* IEEE8021X_EAPOL */
365 #ifndef CONFIG_NO_SCAN_PROCESSING
367 static int has_wep_key(struct wpa_ssid *ssid)
371 for (i = 0; i < NUM_WEP_KEYS; i++) {
372 if (ssid->wep_key_len[i])
380 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
381 struct wpa_ssid *ssid)
385 if (ssid->mixed_cell)
389 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
391 #endif /* CONFIG_WPS */
393 if (has_wep_key(ssid))
396 #ifdef IEEE8021X_EAPOL
397 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
398 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
399 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
401 #endif /* IEEE8021X_EAPOL */
403 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
406 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
409 if (bss->caps & IEEE80211_CAP_PRIVACY)
415 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
416 struct wpa_ssid *ssid,
419 struct wpa_ie_data ie;
421 const u8 *rsn_ie, *wpa_ie;
425 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
429 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
430 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
431 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
432 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
433 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
435 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
436 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
439 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
446 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
448 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
453 if (!(ie.proto & ssid->proto)) {
454 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
459 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
460 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
465 if (!(ie.group_cipher & ssid->group_cipher)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
471 if (!(ie.key_mgmt & ssid->key_mgmt)) {
472 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
477 #ifdef CONFIG_IEEE80211W
478 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
479 wpas_get_ssid_pmf(wpa_s, ssid) ==
480 MGMT_FRAME_PROTECTION_REQUIRED) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
485 #endif /* CONFIG_IEEE80211W */
487 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
491 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
492 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
495 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
502 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
504 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
509 if (!(ie.proto & ssid->proto)) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
515 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
516 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
521 if (!(ie.group_cipher & ssid->group_cipher)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
527 if (!(ie.key_mgmt & ssid->key_mgmt)) {
528 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
533 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
537 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
539 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
543 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
544 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
545 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
549 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
550 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
551 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
555 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
560 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
567 static int freq_allowed(int *freqs, int freq)
574 for (i = 0; freqs[i]; i++)
575 if (freqs[i] == freq)
581 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
583 const struct hostapd_hw_modes *mode = NULL, *modes;
584 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
589 return 1; /* Cannot do matching without knowing band */
591 modes = wpa_s->hw.modes;
594 * The driver does not provide any additional information
595 * about the utilized hardware, so allow the connection attempt
601 for (i = 0; i < wpa_s->hw.num_modes; i++) {
602 for (j = 0; j < modes[i].num_channels; j++) {
603 int freq = modes[i].channels[j].freq;
604 if (freq == bss->freq) {
606 mode->mode == HOSTAPD_MODE_IEEE80211G)
607 break; /* do not allow 802.11b replace
618 for (i = 0; i < (int) sizeof(scan_ie); i++) {
619 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
623 for (j = 2; j < rate_ie[1] + 2; j++) {
624 int flagged = !!(rate_ie[j] & 0x80);
625 int r = (rate_ie[j] & 0x7f) * 5;
628 * IEEE Std 802.11n-2009 7.3.2.2:
629 * The new BSS Membership selector value is encoded
630 * like a legacy basic rate, but it is not a rate and
631 * only indicates if the BSS members are required to
632 * support the mandatory features of Clause 20 [HT PHY]
633 * in order to join the BSS.
635 if (flagged && ((rate_ie[j] & 0x7f) ==
636 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
637 if (!ht_supported(mode)) {
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " hardware does not support "
646 /* There's also a VHT selector for 802.11ac */
647 if (flagged && ((rate_ie[j] & 0x7f) ==
648 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
649 if (!vht_supported(mode)) {
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " hardware does not support "
661 /* check for legacy basic rates */
662 for (k = 0; k < mode->num_rates; k++) {
663 if (mode->rates[k] == r)
666 if (k == mode->num_rates) {
668 * IEEE Std 802.11-2007 7.3.2.2 demands that in
669 * order to join a BSS all required rates
670 * have to be supported by the hardware.
672 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
673 "not support required rate %d.%d Mbps",
685 * Test whether BSS is in an ESS.
686 * This is done differently in DMG (60 GHz) and non-DMG bands
688 static int bss_is_ess(struct wpa_bss *bss)
690 if (bss_is_dmg(bss)) {
691 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
692 IEEE80211_CAP_DMG_AP;
695 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
700 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
704 for (i = 0; i < ETH_ALEN; i++) {
705 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
712 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
716 for (i = 0; i < num; i++) {
717 const u8 *a = list + i * ETH_ALEN * 2;
718 const u8 *m = a + ETH_ALEN;
720 if (match_mac_mask(a, addr, m))
727 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
728 int i, struct wpa_bss *bss,
729 struct wpa_ssid *group,
732 u8 wpa_ie_len, rsn_ie_len;
734 struct wpa_blacklist *e;
736 struct wpa_ssid *ssid;
739 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
740 wpa_ie_len = ie ? ie[1] : 0;
742 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
743 rsn_ie_len = ie ? ie[1] : 0;
745 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
748 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
749 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
750 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
751 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
752 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
753 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
754 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
756 osen ? " osen=1" : "");
758 e = wpa_blacklist_get(wpa_s, bss->bssid);
761 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
763 * When only a single network is enabled, we can
764 * trigger blacklisting on the first failure. This
765 * should not be done with multiple enabled networks to
766 * avoid getting forced to move into a worse ESS on
767 * single error if there are no other BSSes of the
772 if (e->count > limit) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
774 "(count=%d limit=%d)", e->count, limit);
779 if (bss->ssid_len == 0) {
780 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
784 if (disallowed_bssid(wpa_s, bss->bssid)) {
785 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
789 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
794 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
796 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
797 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
800 if (wpas_network_disabled(wpa_s, ssid)) {
801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
805 res = wpas_temp_disabled(wpa_s, ssid);
807 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
808 "temporarily for %d second(s)", res);
813 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
814 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
819 if (wpa && ssid->ssid_len == 0 &&
820 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
823 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
824 /* Only allow wildcard SSID match if an AP
825 * advertises active WPS operation that matches
828 if (ssid->ssid_len == 0 &&
829 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
832 #endif /* CONFIG_WPS */
834 if (ssid->bssid_set && ssid->ssid_len == 0 &&
835 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
839 (bss->ssid_len != ssid->ssid_len ||
840 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
841 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
845 if (ssid->bssid_set &&
846 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
847 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
851 /* check blacklist */
852 if (ssid->num_bssid_blacklist &&
853 addr_in_list(bss->bssid, ssid->bssid_blacklist,
854 ssid->num_bssid_blacklist)) {
855 wpa_dbg(wpa_s, MSG_DEBUG,
856 " skip - BSSID blacklisted");
860 /* if there is a whitelist, only accept those APs */
861 if (ssid->num_bssid_whitelist &&
862 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
863 ssid->num_bssid_whitelist)) {
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip - BSSID not in whitelist");
869 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
873 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
874 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
875 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
876 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
881 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
887 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
888 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
893 if (!wpa_supplicant_match_privacy(bss, ssid)) {
894 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
899 if (!bss_is_ess(bss)) {
900 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
904 if (!freq_allowed(ssid->freq_list, bss->freq)) {
905 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
910 if (!rate_match(wpa_s, bss)) {
911 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
917 if (ssid->p2p_group &&
918 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
919 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
920 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
924 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
925 struct wpabuf *p2p_ie;
926 u8 dev_addr[ETH_ALEN];
928 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
933 p2p_ie = wpa_bss_get_vendor_ie_multi(
934 bss, P2P_IE_VENDOR_TYPE);
935 if (p2p_ie == NULL) {
936 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
940 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
941 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
943 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
951 * TODO: skip the AP if its P2P IE has Group Formation
952 * bit set in the P2P Group Capability Bitmap and we
953 * are not in Group Formation with that device.
955 #endif /* CONFIG_P2P */
957 /* Matching configuration found */
961 /* No matching configuration found */
966 static struct wpa_bss *
967 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
968 struct wpa_ssid *group,
969 struct wpa_ssid **selected_ssid,
975 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
978 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
981 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
982 struct wpa_bss *bss = wpa_s->last_scan_res[i];
983 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
987 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
990 wpa_ssid_txt(bss->ssid, bss->ssid_len));
998 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
999 struct wpa_ssid **selected_ssid)
1001 struct wpa_bss *selected = NULL;
1003 struct wpa_ssid *next_ssid = NULL;
1005 if (wpa_s->last_scan_res == NULL ||
1006 wpa_s->last_scan_res_used == 0)
1007 return NULL; /* no scan results from last update */
1009 if (wpa_s->next_ssid) {
1010 struct wpa_ssid *ssid;
1012 /* check that next_ssid is still valid */
1013 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1014 if (ssid == wpa_s->next_ssid)
1018 wpa_s->next_ssid = NULL;
1021 while (selected == NULL) {
1022 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1023 if (next_ssid && next_ssid->priority ==
1024 wpa_s->conf->pssid[prio]->priority) {
1025 selected = wpa_supplicant_select_bss(
1026 wpa_s, next_ssid, selected_ssid, 1);
1030 selected = wpa_supplicant_select_bss(
1031 wpa_s, wpa_s->conf->pssid[prio],
1037 if (selected == NULL && wpa_s->blacklist &&
1038 !wpa_s->countermeasures) {
1039 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1040 "blacklist and try again");
1041 wpa_blacklist_clear(wpa_s);
1042 wpa_s->blacklist_cleared++;
1043 } else if (selected == NULL)
1051 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1052 int timeout_sec, int timeout_usec)
1054 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1056 * No networks are enabled; short-circuit request so
1057 * we don't wait timeout seconds before transitioning
1058 * to INACTIVE state.
1060 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1061 "since there are no enabled networks");
1062 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1066 wpa_s->scan_for_connection = 1;
1067 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1071 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1072 struct wpa_bss *selected,
1073 struct wpa_ssid *ssid)
1075 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1076 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1077 "PBC session overlap");
1079 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1080 wpa_s->p2p_in_provisioning) {
1081 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1085 #endif /* CONFIG_P2P */
1088 wpas_wps_cancel(wpa_s);
1089 #endif /* CONFIG_WPS */
1093 wpa_msg(wpa_s, MSG_DEBUG,
1094 "Considering connect request: reassociate: %d selected: "
1095 MACSTR " bssid: " MACSTR " pending: " MACSTR
1096 " wpa_state: %s ssid=%p current_ssid=%p",
1097 wpa_s->reassociate, MAC2STR(selected->bssid),
1098 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1099 wpa_supplicant_state_txt(wpa_s->wpa_state),
1100 ssid, wpa_s->current_ssid);
1103 * Do not trigger new association unless the BSSID has changed or if
1104 * reassociation is requested. If we are in process of associating with
1105 * the selected BSSID, do not trigger new attempt.
1107 if (wpa_s->reassociate ||
1108 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1109 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1110 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1111 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1112 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1114 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1115 ssid != wpa_s->current_ssid)))) {
1116 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1117 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1120 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1121 MAC2STR(selected->bssid));
1122 wpa_supplicant_associate(wpa_s, selected, ssid);
1124 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1125 "connect with the selected AP");
1132 static struct wpa_ssid *
1133 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1136 struct wpa_ssid *ssid;
1138 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1139 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1141 if (wpas_network_disabled(wpa_s, ssid))
1143 if (ssid->mode == IEEE80211_MODE_IBSS ||
1144 ssid->mode == IEEE80211_MODE_AP ||
1145 ssid->mode == IEEE80211_MODE_MESH)
1153 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1154 * on BSS added and BSS changed events */
1155 static void wpa_supplicant_rsn_preauth_scan_results(
1156 struct wpa_supplicant *wpa_s)
1158 struct wpa_bss *bss;
1160 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1163 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1164 const u8 *ssid, *rsn;
1166 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1170 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1174 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1180 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1181 struct wpa_bss *selected,
1182 struct wpa_ssid *ssid)
1184 struct wpa_bss *current_bss = NULL;
1187 if (wpa_s->reassociate)
1188 return 1; /* explicit request to reassociate */
1189 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1190 return 1; /* we are not associated; continue */
1191 if (wpa_s->current_ssid == NULL)
1192 return 1; /* unknown current SSID */
1193 if (wpa_s->current_ssid != ssid)
1194 return 1; /* different network block */
1196 if (wpas_driver_bss_selection(wpa_s))
1197 return 0; /* Driver-based roaming */
1199 if (wpa_s->current_ssid->ssid)
1200 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1201 wpa_s->current_ssid->ssid,
1202 wpa_s->current_ssid->ssid_len);
1204 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1207 return 1; /* current BSS not seen in scan results */
1209 if (current_bss == selected)
1212 if (selected->last_update_idx > current_bss->last_update_idx)
1213 return 1; /* current BSS not seen in the last scan */
1215 #ifndef CONFIG_NO_ROAMING
1216 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1217 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1218 MAC2STR(current_bss->bssid), current_bss->level);
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1220 MAC2STR(selected->bssid), selected->level);
1222 if (wpa_s->current_ssid->bssid_set &&
1223 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1226 "has preferred BSSID");
1230 if (current_bss->level < 0 && current_bss->level > selected->level) {
1231 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1237 if (current_bss->level < 0) {
1238 if (current_bss->level < -85)
1240 else if (current_bss->level < -80)
1242 else if (current_bss->level < -75)
1244 else if (current_bss->level < -70)
1249 if (abs(current_bss->level - selected->level) < min_diff) {
1250 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1256 #else /* CONFIG_NO_ROAMING */
1258 #endif /* CONFIG_NO_ROAMING */
1262 /* Return != 0 if no scan results could be fetched or if scan results should not
1263 * be shared with other virtual interfaces. */
1264 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1265 union wpa_event_data *data,
1268 struct wpa_scan_results *scan_res = NULL;
1271 #ifndef CONFIG_NO_RANDOM_POOL
1273 #endif /* CONFIG_NO_RANDOM_POOL */
1276 if (wpa_s->ap_iface)
1278 #endif /* CONFIG_AP */
1280 wpa_supplicant_notify_scanning(wpa_s, 0);
1282 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1283 data ? &data->scan_info :
1285 if (scan_res == NULL) {
1286 if (wpa_s->conf->ap_scan == 2 || ap ||
1287 wpa_s->scan_res_handler == scan_only_handler)
1291 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1293 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1295 goto scan_work_done;
1298 #ifndef CONFIG_NO_RANDOM_POOL
1299 num = scan_res->num;
1302 for (i = 0; i < num; i++) {
1304 struct wpa_scan_res *res = scan_res->res[i];
1305 buf[0] = res->bssid[5];
1306 buf[1] = res->qual & 0xff;
1307 buf[2] = res->noise & 0xff;
1308 buf[3] = res->level & 0xff;
1309 buf[4] = res->tsf & 0xff;
1310 random_add_randomness(buf, sizeof(buf));
1312 #endif /* CONFIG_NO_RANDOM_POOL */
1314 if (own_request && wpa_s->scan_res_handler &&
1315 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1316 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1317 struct wpa_scan_results *scan_res);
1319 scan_res_handler = wpa_s->scan_res_handler;
1320 wpa_s->scan_res_handler = NULL;
1321 scan_res_handler(wpa_s, scan_res);
1323 goto scan_work_done;
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1329 if (wpa_s->ap_iface->scan_cb)
1330 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1331 #endif /* CONFIG_AP */
1332 goto scan_work_done;
1335 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1336 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1337 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1338 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1339 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1340 wpa_s->manual_scan_id);
1341 wpa_s->manual_scan_use_id = 0;
1343 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1345 wpas_notify_scan_results(wpa_s);
1347 wpas_notify_scan_done(wpa_s, 1);
1349 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1350 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1351 wpa_scan_results_free(scan_res);
1355 if (wnm_scan_process(wpa_s, 1) > 0)
1356 goto scan_work_done;
1358 if (sme_proc_obss_scan(wpa_s) > 0)
1359 goto scan_work_done;
1361 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1362 goto scan_work_done;
1364 if (autoscan_notify_scan(wpa_s, scan_res))
1365 goto scan_work_done;
1367 if (wpa_s->disconnected) {
1368 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1369 goto scan_work_done;
1372 if (!wpas_driver_bss_selection(wpa_s) &&
1373 bgscan_notify_scan(wpa_s, scan_res) == 1)
1374 goto scan_work_done;
1376 wpas_wps_update_ap_info(wpa_s, scan_res);
1378 wpa_scan_results_free(scan_res);
1380 if (wpa_s->scan_work) {
1381 struct wpa_radio_work *work = wpa_s->scan_work;
1382 wpa_s->scan_work = NULL;
1383 radio_work_done(work);
1386 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1389 wpa_scan_results_free(scan_res);
1390 if (wpa_s->scan_work) {
1391 struct wpa_radio_work *work = wpa_s->scan_work;
1392 wpa_s->scan_work = NULL;
1393 radio_work_done(work);
1399 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1400 int new_scan, int own_request)
1402 struct wpa_bss *selected;
1403 struct wpa_ssid *ssid = NULL;
1405 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1409 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1412 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1416 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1421 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1423 * Do not notify other virtual radios of scan results since we do not
1424 * want them to start other associations at the same time.
1430 wpa_msg(wpa_s, MSG_INFO,
1431 "Avoiding join because we already joined a mesh group");
1434 #endif /* CONFIG_MESH */
1435 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1436 ssid = wpa_supplicant_pick_new_network(wpa_s);
1438 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1439 wpa_supplicant_associate(wpa_s, NULL, ssid);
1441 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1442 } else if (own_request) {
1444 * No SSID found. If SCAN results are as a result of
1445 * own scan request and not due to a scan request on
1446 * another shared interface, try another scan.
1448 int timeout_sec = wpa_s->scan_interval;
1449 int timeout_usec = 0;
1451 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1454 if (wpa_s->p2p_in_provisioning ||
1455 wpa_s->show_group_started ||
1456 wpa_s->p2p_in_invitation) {
1458 * Use shorter wait during P2P Provisioning
1459 * state and during P2P join-a-group operation
1460 * to speed up group formation.
1463 timeout_usec = 250000;
1464 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1468 #endif /* CONFIG_P2P */
1469 #ifdef CONFIG_INTERWORKING
1470 if (wpa_s->conf->auto_interworking &&
1471 wpa_s->conf->interworking &&
1472 wpa_s->conf->cred) {
1473 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1474 "start ANQP fetch since no matching "
1476 wpa_s->network_select = 1;
1477 wpa_s->auto_network_select = 1;
1478 interworking_start_fetch_anqp(wpa_s);
1481 #endif /* CONFIG_INTERWORKING */
1483 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1484 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1486 timeout_usec = 500000;
1487 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1491 #endif /* CONFIG_WPS */
1492 if (wpa_supplicant_req_sched_scan(wpa_s))
1493 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1501 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1502 union wpa_event_data *data)
1504 struct wpa_supplicant *ifs;
1506 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1508 * If no scan results could be fetched, then no need to
1509 * notify those interfaces that did not actually request
1510 * this scan. Similarly, if scan results started a new operation on this
1511 * interface, do not notify other interfaces to avoid concurrent
1512 * operations during a connection attempt.
1518 * Check other interfaces to see if they share the same radio. If
1519 * so, they get updated with this same scan info.
1521 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1524 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1525 "sibling", ifs->ifname);
1526 _wpa_supplicant_event_scan_results(ifs, data, 0);
1531 #endif /* CONFIG_NO_SCAN_PROCESSING */
1534 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1536 #ifdef CONFIG_NO_SCAN_PROCESSING
1538 #else /* CONFIG_NO_SCAN_PROCESSING */
1539 struct os_reltime now;
1541 if (wpa_s->last_scan_res_used <= 0)
1544 os_get_reltime(&now);
1545 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1546 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1550 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1551 #endif /* CONFIG_NO_SCAN_PROCESSING */
1556 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1558 struct wpa_supplicant *wpa_s = eloop_ctx;
1560 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1563 if (!wpa_s->no_keep_alive) {
1564 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1565 MAC2STR(wpa_s->bssid));
1566 /* TODO: could skip this if normal data traffic has been sent */
1567 /* TODO: Consider using some more appropriate data frame for
1570 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1575 if (wpa_s->sme.bss_max_idle_period) {
1577 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1580 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1581 wnm_bss_keep_alive, wpa_s, NULL);
1583 #endif /* CONFIG_SME */
1587 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1588 const u8 *ies, size_t ies_len)
1590 struct ieee802_11_elems elems;
1595 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1599 if (elems.bss_max_idle_period) {
1601 wpa_s->sme.bss_max_idle_period =
1602 WPA_GET_LE16(elems.bss_max_idle_period);
1603 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1604 "TU)%s", wpa_s->sme.bss_max_idle_period,
1605 (elems.bss_max_idle_period[2] & 0x01) ?
1606 " (protected keep-live required)" : "");
1607 if (wpa_s->sme.bss_max_idle_period == 0)
1608 wpa_s->sme.bss_max_idle_period = 1;
1609 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1610 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1611 /* msec times 1000 */
1612 msec = wpa_s->sme.bss_max_idle_period * 1024;
1615 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1616 wnm_bss_keep_alive, wpa_s,
1620 #endif /* CONFIG_SME */
1623 #endif /* CONFIG_WNM */
1626 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1629 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1630 #endif /* CONFIG_WNM */
1634 #ifdef CONFIG_INTERWORKING
1636 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1641 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1642 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1644 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1651 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1652 const u8 *ies, size_t ies_len)
1654 struct ieee802_11_elems elems;
1659 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1662 if (elems.qos_map_set) {
1663 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1664 elems.qos_map_set_len);
1668 #endif /* CONFIG_INTERWORKING */
1671 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1672 union wpa_event_data *data)
1674 int l, len, found = 0, wpa_found, rsn_found;
1676 #ifdef CONFIG_IEEE80211R
1678 #endif /* CONFIG_IEEE80211R */
1680 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1681 if (data->assoc_info.req_ies)
1682 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1683 data->assoc_info.req_ies_len);
1684 if (data->assoc_info.resp_ies) {
1685 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1686 data->assoc_info.resp_ies_len);
1688 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1689 data->assoc_info.resp_ies_len);
1690 #endif /* CONFIG_TDLS */
1692 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1693 data->assoc_info.resp_ies_len);
1694 #endif /* CONFIG_WNM */
1695 #ifdef CONFIG_INTERWORKING
1696 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1697 data->assoc_info.resp_ies_len);
1698 #endif /* CONFIG_INTERWORKING */
1700 if (data->assoc_info.beacon_ies)
1701 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1702 data->assoc_info.beacon_ies,
1703 data->assoc_info.beacon_ies_len);
1704 if (data->assoc_info.freq)
1705 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1706 data->assoc_info.freq);
1708 p = data->assoc_info.req_ies;
1709 l = data->assoc_info.req_ies_len;
1711 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1712 while (p && l >= 2) {
1715 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1719 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1720 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1721 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1722 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1725 wpa_find_assoc_pmkid(wpa_s);
1731 if (!found && data->assoc_info.req_ies)
1732 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1734 #ifdef CONFIG_IEEE80211R
1736 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1737 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1738 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1739 data->assoc_info.resp_ies,
1740 data->assoc_info.resp_ies_len,
1742 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1743 "Reassociation Response failed");
1744 wpa_supplicant_deauthenticate(
1745 wpa_s, WLAN_REASON_INVALID_IE);
1750 p = data->assoc_info.resp_ies;
1751 l = data->assoc_info.resp_ies_len;
1753 #ifdef CONFIG_WPS_STRICT
1754 if (p && wpa_s->current_ssid &&
1755 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1757 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1759 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1760 "include WPS IE in (Re)Association Response");
1764 if (wps_validate_assoc_resp(wps) < 0) {
1766 wpa_supplicant_deauthenticate(
1767 wpa_s, WLAN_REASON_INVALID_IE);
1772 #endif /* CONFIG_WPS_STRICT */
1774 /* Go through the IEs and make a copy of the MDIE, if present. */
1775 while (p && l >= 2) {
1778 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1782 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1783 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1784 wpa_s->sme.ft_used = 1;
1785 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1786 MOBILITY_DOMAIN_ID_LEN);
1792 #endif /* CONFIG_SME */
1794 /* Process FT when SME is in the driver */
1795 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1796 wpa_ft_is_completed(wpa_s->wpa)) {
1797 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1798 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1799 data->assoc_info.resp_ies,
1800 data->assoc_info.resp_ies_len,
1802 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1803 "Reassociation Response failed");
1804 wpa_supplicant_deauthenticate(
1805 wpa_s, WLAN_REASON_INVALID_IE);
1808 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1811 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1812 data->assoc_info.resp_ies_len);
1813 #endif /* CONFIG_IEEE80211R */
1815 /* WPA/RSN IE from Beacon/ProbeResp */
1816 p = data->assoc_info.beacon_ies;
1817 l = data->assoc_info.beacon_ies_len;
1819 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1821 wpa_found = rsn_found = 0;
1822 while (p && l >= 2) {
1825 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1830 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1831 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1833 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1837 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1839 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1846 if (!wpa_found && data->assoc_info.beacon_ies)
1847 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1848 if (!rsn_found && data->assoc_info.beacon_ies)
1849 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1850 if (wpa_found || rsn_found)
1851 wpa_s->ap_ies_from_associnfo = 1;
1853 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1854 wpa_s->assoc_freq != data->assoc_info.freq) {
1855 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1857 wpa_s->assoc_freq, data->assoc_info.freq);
1858 wpa_supplicant_update_scan_results(wpa_s);
1861 wpa_s->assoc_freq = data->assoc_info.freq;
1867 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1869 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1871 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1874 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1877 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1878 WPA_IE_VENDOR_TYPE);
1879 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1881 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1882 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1883 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1884 bss_rsn ? 2 + bss_rsn[1] : 0))
1891 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1892 union wpa_event_data *data)
1898 if (wpa_s->ap_iface) {
1901 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1902 data->assoc_info.addr,
1903 data->assoc_info.req_ies,
1904 data->assoc_info.req_ies_len,
1905 data->assoc_info.reassoc);
1908 #endif /* CONFIG_AP */
1910 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1911 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1914 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1915 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1916 wpa_supplicant_deauthenticate(
1917 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1921 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1922 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1923 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1924 MACSTR, MAC2STR(bssid));
1925 random_add_randomness(bssid, ETH_ALEN);
1926 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1927 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1928 wpas_notify_bssid_changed(wpa_s);
1930 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1931 wpa_clear_keys(wpa_s, bssid);
1933 if (wpa_supplicant_select_config(wpa_s) < 0) {
1934 wpa_supplicant_deauthenticate(
1935 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1939 if (wpa_s->conf->ap_scan == 1 &&
1940 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1941 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1942 wpa_msg(wpa_s, MSG_WARNING,
1943 "WPA/RSN IEs not updated");
1948 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1949 wpa_s->sme.prev_bssid_set = 1;
1950 wpa_s->sme.last_unprot_disconnect.sec = 0;
1951 #endif /* CONFIG_SME */
1953 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1954 if (wpa_s->current_ssid) {
1955 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1956 * initialized before association, but for other modes,
1957 * initialize PC/SC here, if the current configuration needs
1958 * smartcard or SIM/USIM. */
1959 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1961 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1963 l2_packet_notify_auth_start(wpa_s->l2);
1966 * Set portEnabled first to FALSE in order to get EAP state machine out
1967 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1968 * state machine may transit to AUTHENTICATING state based on obsolete
1969 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1970 * AUTHENTICATED without ever giving chance to EAP state machine to
1973 if (!ft_completed) {
1974 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1975 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1977 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1978 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1979 /* 802.1X::portControl = Auto */
1980 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1981 wpa_s->eapol_received = 0;
1982 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1983 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1984 (wpa_s->current_ssid &&
1985 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1986 if (wpa_s->current_ssid &&
1987 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1989 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1991 * Set the key after having received joined-IBSS event
1994 wpa_supplicant_set_wpa_none_key(wpa_s,
1995 wpa_s->current_ssid);
1997 wpa_supplicant_cancel_auth_timeout(wpa_s);
1998 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1999 } else if (!ft_completed) {
2000 /* Timeout for receiving the first EAPOL packet */
2001 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2003 wpa_supplicant_cancel_scan(wpa_s);
2005 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2006 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2008 * We are done; the driver will take care of RSN 4-way
2011 wpa_supplicant_cancel_auth_timeout(wpa_s);
2012 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2013 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2014 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2015 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2016 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2018 * The driver will take care of RSN 4-way handshake, so we need
2019 * to allow EAPOL supplicant to complete its work without
2020 * waiting for WPA supplicant.
2022 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2023 } else if (ft_completed) {
2025 * FT protocol completed - make sure EAPOL state machine ends
2026 * up in authenticated.
2028 wpa_supplicant_cancel_auth_timeout(wpa_s);
2029 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2030 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2031 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2034 wpa_s->last_eapol_matches_bssid = 0;
2036 if (wpa_s->pending_eapol_rx) {
2037 struct os_reltime now, age;
2038 os_get_reltime(&now);
2039 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2040 if (age.sec == 0 && age.usec < 100000 &&
2041 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2043 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2044 "frame that was received just before "
2045 "association notification");
2046 wpa_supplicant_rx_eapol(
2047 wpa_s, wpa_s->pending_eapol_rx_src,
2048 wpabuf_head(wpa_s->pending_eapol_rx),
2049 wpabuf_len(wpa_s->pending_eapol_rx));
2051 wpabuf_free(wpa_s->pending_eapol_rx);
2052 wpa_s->pending_eapol_rx = NULL;
2055 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2056 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2057 wpa_s->current_ssid &&
2058 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2059 /* Set static WEP keys again */
2060 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2063 #ifdef CONFIG_IBSS_RSN
2064 if (wpa_s->current_ssid &&
2065 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2066 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2067 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2068 wpa_s->ibss_rsn == NULL) {
2069 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2070 if (!wpa_s->ibss_rsn) {
2071 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2072 wpa_supplicant_deauthenticate(
2073 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2077 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2079 #endif /* CONFIG_IBSS_RSN */
2081 wpas_wps_notify_assoc(wpa_s, bssid);
2084 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2085 data->assoc_info.resp_ies_len,
2086 &data->assoc_info.wmm_params);
2088 if (wpa_s->reassoc_same_bss)
2089 wmm_ac_restore_tspecs(wpa_s);
2094 static int disconnect_reason_recoverable(u16 reason_code)
2096 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2097 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2098 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2102 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2104 int locally_generated)
2108 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2110 * At least Host AP driver and a Prism3 card seemed to be
2111 * generating streams of disconnected events when configuring
2112 * IBSS for WPA-None. Ignore them for now.
2117 bssid = wpa_s->bssid;
2118 if (is_zero_ether_addr(bssid))
2119 bssid = wpa_s->pending_bssid;
2121 if (!is_zero_ether_addr(bssid) ||
2122 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2123 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2125 MAC2STR(bssid), reason_code,
2126 locally_generated ? " locally_generated=1" : "");
2131 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2132 int locally_generated)
2134 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2135 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2136 return 0; /* Not in 4-way handshake with PSK */
2139 * It looks like connection was lost while trying to go through PSK
2140 * 4-way handshake. Filter out known disconnection cases that are caused
2141 * by something else than PSK mismatch to avoid confusing reports.
2144 if (locally_generated) {
2145 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2153 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2155 int locally_generated)
2159 u8 prev_pending_bssid[ETH_ALEN];
2160 struct wpa_bss *fast_reconnect = NULL;
2161 struct wpa_ssid *fast_reconnect_ssid = NULL;
2162 struct wpa_ssid *last_ssid;
2164 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2165 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2167 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2169 * At least Host AP driver and a Prism3 card seemed to be
2170 * generating streams of disconnected events when configuring
2171 * IBSS for WPA-None. Ignore them for now.
2173 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2174 "IBSS/WPA-None mode");
2178 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2179 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2180 "pre-shared key may be incorrect");
2181 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2182 return; /* P2P group removed */
2183 wpas_auth_failed(wpa_s, "WRONG_KEY");
2185 if (!wpa_s->disconnected &&
2186 (!wpa_s->auto_reconnect_disabled ||
2187 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2188 wpas_wps_searching(wpa_s))) {
2189 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2190 "reconnect (wps=%d/%d wpa_state=%d)",
2191 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2192 wpas_wps_searching(wpa_s),
2194 if (wpa_s->wpa_state == WPA_COMPLETED &&
2195 wpa_s->current_ssid &&
2196 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2197 !locally_generated &&
2198 disconnect_reason_recoverable(reason_code)) {
2200 * It looks like the AP has dropped association with
2201 * us, but could allow us to get back in. Try to
2202 * reconnect to the same BSS without full scan to save
2203 * time for some common cases.
2205 fast_reconnect = wpa_s->current_bss;
2206 fast_reconnect_ssid = wpa_s->current_ssid;
2207 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2208 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2210 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2213 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2214 "try to re-connect");
2215 wpa_s->reassociate = 0;
2216 wpa_s->disconnected = 1;
2217 wpa_supplicant_cancel_sched_scan(wpa_s);
2219 bssid = wpa_s->bssid;
2220 if (is_zero_ether_addr(bssid))
2221 bssid = wpa_s->pending_bssid;
2222 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2223 wpas_connection_failed(wpa_s, bssid);
2224 wpa_sm_notify_disassoc(wpa_s->wpa);
2225 if (locally_generated)
2226 wpa_s->disconnect_reason = -reason_code;
2228 wpa_s->disconnect_reason = reason_code;
2229 wpas_notify_disconnect_reason(wpa_s);
2230 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2231 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2232 wpa_clear_keys(wpa_s, wpa_s->bssid);
2234 last_ssid = wpa_s->current_ssid;
2235 wpa_supplicant_mark_disassoc(wpa_s);
2237 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2238 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2239 wpa_s->current_ssid = last_ssid;
2242 if (fast_reconnect &&
2243 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2244 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2245 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2246 fast_reconnect->ssid_len) &&
2247 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2248 #ifndef CONFIG_NO_SCAN_PROCESSING
2249 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2250 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2251 fast_reconnect_ssid) < 0) {
2252 /* Recover through full scan */
2253 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2255 #endif /* CONFIG_NO_SCAN_PROCESSING */
2256 } else if (fast_reconnect) {
2258 * Could not reconnect to the same BSS due to network being
2259 * disabled. Use a new scan to match the alternative behavior
2260 * above, i.e., to continue automatic reconnection attempt in a
2261 * way that enforces disabled network rules.
2263 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2268 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2269 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2271 struct wpa_supplicant *wpa_s = eloop_ctx;
2273 if (!wpa_s->pending_mic_error_report)
2276 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2277 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2278 wpa_s->pending_mic_error_report = 0;
2280 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2284 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2285 union wpa_event_data *data)
2288 struct os_reltime t;
2290 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2291 pairwise = (data && data->michael_mic_failure.unicast);
2293 if ((wpa_s->last_michael_mic_error.sec &&
2294 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2295 wpa_s->pending_mic_error_report) {
2296 if (wpa_s->pending_mic_error_report) {
2298 * Send the pending MIC error report immediately since
2299 * we are going to start countermeasures and AP better
2302 wpa_sm_key_request(wpa_s->wpa, 1,
2303 wpa_s->pending_mic_error_pairwise);
2306 /* Send the new MIC error report immediately since we are going
2307 * to start countermeasures and AP better do the same.
2309 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2311 /* initialize countermeasures */
2312 wpa_s->countermeasures = 1;
2314 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2316 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2319 * Need to wait for completion of request frame. We do not get
2320 * any callback for the message completion, so just wait a
2321 * short while and hope for the best. */
2324 wpa_drv_set_countermeasures(wpa_s, 1);
2325 wpa_supplicant_deauthenticate(wpa_s,
2326 WLAN_REASON_MICHAEL_MIC_FAILURE);
2327 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2329 eloop_register_timeout(60, 0,
2330 wpa_supplicant_stop_countermeasures,
2332 /* TODO: mark the AP rejected for 60 second. STA is
2333 * allowed to associate with another AP.. */
2335 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2336 if (wpa_s->mic_errors_seen) {
2338 * Reduce the effectiveness of Michael MIC error
2339 * reports as a means for attacking against TKIP if
2340 * more than one MIC failure is noticed with the same
2341 * PTK. We delay the transmission of the reports by a
2342 * random time between 0 and 60 seconds in order to
2343 * force the attacker wait 60 seconds before getting
2344 * the information on whether a frame resulted in a MIC
2350 if (os_get_random(rval, sizeof(rval)) < 0)
2351 sec = os_random() % 60;
2353 sec = WPA_GET_BE32(rval) % 60;
2354 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2355 "report %d seconds", sec);
2356 wpa_s->pending_mic_error_report = 1;
2357 wpa_s->pending_mic_error_pairwise = pairwise;
2358 eloop_cancel_timeout(
2359 wpa_supplicant_delayed_mic_error_report,
2361 eloop_register_timeout(
2362 sec, os_random() % 1000000,
2363 wpa_supplicant_delayed_mic_error_report,
2366 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2368 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2369 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2370 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2372 wpa_s->last_michael_mic_error = t;
2373 wpa_s->mic_errors_seen++;
2377 #ifdef CONFIG_TERMINATE_ONLASTIF
2378 static int any_interfaces(struct wpa_supplicant *head)
2380 struct wpa_supplicant *wpa_s;
2382 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2383 if (!wpa_s->interface_removed)
2387 #endif /* CONFIG_TERMINATE_ONLASTIF */
2391 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2392 union wpa_event_data *data)
2394 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2397 switch (data->interface_status.ievent) {
2398 case EVENT_INTERFACE_ADDED:
2399 if (!wpa_s->interface_removed)
2401 wpa_s->interface_removed = 0;
2402 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2403 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2404 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2405 "driver after interface was added");
2408 case EVENT_INTERFACE_REMOVED:
2409 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2410 wpa_s->interface_removed = 1;
2411 wpa_supplicant_mark_disassoc(wpa_s);
2412 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2413 l2_packet_deinit(wpa_s->l2);
2415 #ifdef CONFIG_TERMINATE_ONLASTIF
2416 /* check if last interface */
2417 if (!any_interfaces(wpa_s->global->ifaces))
2419 #endif /* CONFIG_TERMINATE_ONLASTIF */
2425 #ifdef CONFIG_PEERKEY
2427 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2428 union wpa_event_data *data)
2432 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2434 #endif /* CONFIG_PEERKEY */
2438 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2439 union wpa_event_data *data)
2443 switch (data->tdls.oper) {
2444 case TDLS_REQUEST_SETUP:
2445 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2446 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2447 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2449 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2451 case TDLS_REQUEST_TEARDOWN:
2452 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2453 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2454 data->tdls.reason_code);
2456 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2461 #endif /* CONFIG_TDLS */
2465 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2466 union wpa_event_data *data)
2470 switch (data->wnm.oper) {
2471 case WNM_OPER_SLEEP:
2472 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2473 "(action=%d, intval=%d)",
2474 data->wnm.sleep_action, data->wnm.sleep_intval);
2475 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2476 data->wnm.sleep_intval, NULL);
2480 #endif /* CONFIG_WNM */
2483 #ifdef CONFIG_IEEE80211R
2485 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2486 union wpa_event_data *data)
2491 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2492 data->ft_ies.ies_len,
2493 data->ft_ies.ft_action,
2494 data->ft_ies.target_ap,
2495 data->ft_ies.ric_ies,
2496 data->ft_ies.ric_ies_len) < 0) {
2497 /* TODO: prevent MLME/driver from trying to associate? */
2500 #endif /* CONFIG_IEEE80211R */
2503 #ifdef CONFIG_IBSS_RSN
2504 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2505 union wpa_event_data *data)
2507 struct wpa_ssid *ssid;
2508 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2512 ssid = wpa_s->current_ssid;
2515 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2518 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2522 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2523 union wpa_event_data *data)
2525 struct wpa_ssid *ssid = wpa_s->current_ssid;
2530 /* check if the ssid is correctly configured as IBSS/RSN */
2531 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2534 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2535 data->rx_mgmt.frame_len);
2537 #endif /* CONFIG_IBSS_RSN */
2540 #ifdef CONFIG_IEEE80211R
2541 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2544 const u8 *sta_addr, *target_ap_addr;
2547 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2548 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2549 return; /* only SME case supported for now */
2550 if (len < 1 + 2 * ETH_ALEN + 2)
2553 return; /* Only FT Action Response is supported for now */
2554 sta_addr = data + 1;
2555 target_ap_addr = data + 1 + ETH_ALEN;
2556 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2557 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2558 MACSTR " TargetAP " MACSTR " status %u",
2559 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2561 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2562 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2563 " in FT Action Response", MAC2STR(sta_addr));
2568 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2569 "failure (status code %d)", status);
2570 /* TODO: report error to FT code(?) */
2574 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2575 len - (1 + 2 * ETH_ALEN + 2), 1,
2576 target_ap_addr, NULL, 0) < 0)
2581 struct wpa_bss *bss;
2582 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2584 wpa_s->sme.freq = bss->freq;
2585 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2586 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2589 #endif /* CONFIG_SME */
2591 #endif /* CONFIG_IEEE80211R */
2594 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2595 struct unprot_deauth *e)
2597 #ifdef CONFIG_IEEE80211W
2598 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2599 "dropped: " MACSTR " -> " MACSTR
2600 " (reason code %u)",
2601 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2602 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2603 #endif /* CONFIG_IEEE80211W */
2607 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2608 struct unprot_disassoc *e)
2610 #ifdef CONFIG_IEEE80211W
2611 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2612 "dropped: " MACSTR " -> " MACSTR
2613 " (reason code %u)",
2614 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2615 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2616 #endif /* CONFIG_IEEE80211W */
2620 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2621 u16 reason_code, int locally_generated,
2622 const u8 *ie, size_t ie_len, int deauth)
2625 if (wpa_s->ap_iface && addr) {
2626 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2630 if (wpa_s->ap_iface) {
2631 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2634 #endif /* CONFIG_AP */
2636 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2638 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2639 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2640 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2641 eapol_sm_failed(wpa_s->eapol))) &&
2642 !wpa_s->eap_expected_failure))
2643 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2646 if (deauth && reason_code > 0) {
2647 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2648 locally_generated) > 0) {
2650 * The interface was removed, so cannot continue
2651 * processing any additional operations after this.
2656 #endif /* CONFIG_P2P */
2658 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2663 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2664 struct disassoc_info *info)
2666 u16 reason_code = 0;
2667 int locally_generated = 0;
2668 const u8 *addr = NULL;
2669 const u8 *ie = NULL;
2672 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2677 ie_len = info->ie_len;
2678 reason_code = info->reason_code;
2679 locally_generated = info->locally_generated;
2680 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2681 locally_generated ? " (locally generated)" : "");
2683 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2685 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2690 if (wpa_s->ap_iface && info && info->addr) {
2691 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2695 if (wpa_s->ap_iface) {
2696 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2699 #endif /* CONFIG_AP */
2703 wpas_p2p_disassoc_notif(
2704 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2707 #endif /* CONFIG_P2P */
2709 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2710 sme_event_disassoc(wpa_s, info);
2712 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2717 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2718 struct deauth_info *info)
2720 u16 reason_code = 0;
2721 int locally_generated = 0;
2722 const u8 *addr = NULL;
2723 const u8 *ie = NULL;
2726 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2731 ie_len = info->ie_len;
2732 reason_code = info->reason_code;
2733 locally_generated = info->locally_generated;
2734 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2736 locally_generated ? " (locally generated)" : "");
2738 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2741 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2745 wpa_reset_ft_completed(wpa_s->wpa);
2747 wpas_event_disconnect(wpa_s, addr, reason_code,
2748 locally_generated, ie, ie_len, 1);
2752 static const char * reg_init_str(enum reg_change_initiator init)
2755 case REGDOM_SET_BY_CORE:
2757 case REGDOM_SET_BY_USER:
2759 case REGDOM_SET_BY_DRIVER:
2761 case REGDOM_SET_BY_COUNTRY_IE:
2762 return "COUNTRY_IE";
2763 case REGDOM_BEACON_HINT:
2764 return "BEACON_HINT";
2770 static const char * reg_type_str(enum reg_type type)
2773 case REGDOM_TYPE_UNKNOWN:
2775 case REGDOM_TYPE_COUNTRY:
2777 case REGDOM_TYPE_WORLD:
2779 case REGDOM_TYPE_CUSTOM_WORLD:
2780 return "CUSTOM_WORLD";
2781 case REGDOM_TYPE_INTERSECTION:
2782 return "INTERSECTION";
2788 static void wpa_supplicant_update_channel_list(
2789 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2791 struct wpa_supplicant *ifs;
2793 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2794 reg_init_str(info->initiator), reg_type_str(info->type),
2795 info->alpha2[0] ? " alpha2=" : "",
2796 info->alpha2[0] ? info->alpha2 : "");
2798 if (wpa_s->drv_priv == NULL)
2799 return; /* Ignore event during drv initialization */
2801 free_hw_features(wpa_s);
2802 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2803 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2805 wpas_p2p_update_channel_list(wpa_s);
2808 * Check other interfaces to see if they share the same radio. If
2809 * so, they get updated with this same hw mode info.
2811 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2814 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2816 free_hw_features(ifs);
2817 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2818 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2824 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2825 const u8 *frame, size_t len, int freq,
2828 const struct ieee80211_mgmt *mgmt;
2833 if (len < IEEE80211_HDRLEN + 2)
2836 mgmt = (const struct ieee80211_mgmt *) frame;
2837 payload = frame + IEEE80211_HDRLEN;
2838 category = *payload++;
2839 plen = len - IEEE80211_HDRLEN - 1;
2841 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2842 " Category=%u DataLen=%d freq=%d MHz",
2843 MAC2STR(mgmt->sa), category, (int) plen, freq);
2845 if (category == WLAN_ACTION_WMM) {
2846 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2850 #ifdef CONFIG_IEEE80211R
2851 if (category == WLAN_ACTION_FT) {
2852 ft_rx_action(wpa_s, payload, plen);
2855 #endif /* CONFIG_IEEE80211R */
2857 #ifdef CONFIG_IEEE80211W
2859 if (category == WLAN_ACTION_SA_QUERY) {
2860 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2863 #endif /* CONFIG_SME */
2864 #endif /* CONFIG_IEEE80211W */
2867 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2868 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2871 #endif /* CONFIG_WNM */
2874 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2875 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2876 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2877 mgmt->u.action.category,
2878 payload, plen, freq) == 0)
2880 #endif /* CONFIG_GAS */
2883 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2884 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2885 wpa_dbg(wpa_s, MSG_DEBUG,
2886 "TDLS: Received Discovery Response from " MACSTR,
2890 #endif /* CONFIG_TDLS */
2892 #ifdef CONFIG_INTERWORKING
2893 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2894 payload[0] == QOS_QOS_MAP_CONFIG) {
2895 const u8 *pos = payload + 1;
2896 size_t qlen = plen - 1;
2897 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2898 MACSTR, MAC2STR(mgmt->sa));
2899 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2900 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2901 pos[1] <= qlen - 2 && pos[1] >= 16)
2902 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2905 #endif /* CONFIG_INTERWORKING */
2907 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2908 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2909 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2913 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2914 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2915 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2916 payload + 1, plen - 1,
2921 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2922 category, payload, plen, freq);
2924 mesh_mpm_action_rx(wpa_s, mgmt, len);
2928 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2929 union wpa_event_data *event)
2932 struct wpa_supplicant *ifs;
2933 #endif /* CONFIG_P2P */
2934 struct wpa_freq_range_list *list;
2937 list = &event->freq_range;
2940 str = freq_range_list_str(list);
2941 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2945 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2946 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2949 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2950 wpas_p2p_update_channel_list(wpa_s);
2953 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2955 if (!ifs->current_ssid ||
2956 !ifs->current_ssid->p2p_group ||
2957 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2958 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2961 freq = ifs->current_ssid->frequency;
2962 if (!freq_range_list_includes(list, freq)) {
2963 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2968 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2970 /* TODO: Consider using CSA or removing the group within
2972 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2974 #endif /* CONFIG_P2P */
2980 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2981 union wpa_event_data *data)
2983 wpa_dbg(wpa_s, MSG_DEBUG,
2984 "Connection authorized by device, previous state %d",
2986 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
2987 wpa_supplicant_cancel_auth_timeout(wpa_s);
2988 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2989 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2990 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2992 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
2993 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
2994 data->assoc_info.ptk_kck_len,
2995 data->assoc_info.ptk_kek,
2996 data->assoc_info.ptk_kek_len);
3000 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3001 union wpa_event_data *data)
3003 struct wpa_supplicant *wpa_s = ctx;
3005 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3006 event != EVENT_INTERFACE_ENABLED &&
3007 event != EVENT_INTERFACE_STATUS &&
3008 event != EVENT_SCHED_SCAN_STOPPED) {
3009 wpa_dbg(wpa_s, MSG_DEBUG,
3010 "Ignore event %s (%d) while interface is disabled",
3011 event_to_string(event), event);
3015 #ifndef CONFIG_NO_STDOUT_DEBUG
3017 int level = MSG_DEBUG;
3019 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3020 const struct ieee80211_hdr *hdr;
3022 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3023 fc = le_to_host16(hdr->frame_control);
3024 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3025 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3026 level = MSG_EXCESSIVE;
3029 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3030 event_to_string(event), event);
3032 #endif /* CONFIG_NO_STDOUT_DEBUG */
3036 sme_event_auth(wpa_s, data);
3039 wpa_supplicant_event_assoc(wpa_s, data);
3040 if (data && data->assoc_info.authorized)
3041 wpa_supplicant_event_assoc_auth(wpa_s, data);
3043 case EVENT_DISASSOC:
3044 wpas_event_disassoc(wpa_s,
3045 data ? &data->disassoc_info : NULL);
3048 wpas_event_deauth(wpa_s,
3049 data ? &data->deauth_info : NULL);
3051 case EVENT_MICHAEL_MIC_FAILURE:
3052 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3054 #ifndef CONFIG_NO_SCAN_PROCESSING
3055 case EVENT_SCAN_STARTED:
3056 os_get_reltime(&wpa_s->scan_start_time);
3057 if (wpa_s->own_scan_requested) {
3058 struct os_reltime diff;
3060 os_reltime_sub(&wpa_s->scan_start_time,
3061 &wpa_s->scan_trigger_time, &diff);
3062 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3063 diff.sec, diff.usec);
3064 wpa_s->own_scan_requested = 0;
3065 wpa_s->own_scan_running = 1;
3066 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3067 wpa_s->manual_scan_use_id) {
3068 wpa_msg_ctrl(wpa_s, MSG_INFO,
3069 WPA_EVENT_SCAN_STARTED "id=%u",
3070 wpa_s->manual_scan_id);
3072 wpa_msg_ctrl(wpa_s, MSG_INFO,
3073 WPA_EVENT_SCAN_STARTED);
3076 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3077 wpa_s->radio->external_scan_running = 1;
3078 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3081 case EVENT_SCAN_RESULTS:
3082 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3083 struct os_reltime now, diff;
3084 os_get_reltime(&now);
3085 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3086 wpa_s->scan_start_time.sec = 0;
3087 wpa_s->scan_start_time.usec = 0;
3088 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3089 diff.sec, diff.usec);
3091 wpa_supplicant_event_scan_results(wpa_s, data);
3092 wpa_s->own_scan_running = 0;
3093 wpa_s->radio->external_scan_running = 0;
3094 radio_work_check_next(wpa_s);
3096 #endif /* CONFIG_NO_SCAN_PROCESSING */
3097 case EVENT_ASSOCINFO:
3098 wpa_supplicant_event_associnfo(wpa_s, data);
3100 case EVENT_INTERFACE_STATUS:
3101 wpa_supplicant_event_interface_status(wpa_s, data);
3103 case EVENT_PMKID_CANDIDATE:
3104 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3106 #ifdef CONFIG_PEERKEY
3107 case EVENT_STKSTART:
3108 wpa_supplicant_event_stkstart(wpa_s, data);
3110 #endif /* CONFIG_PEERKEY */
3113 wpa_supplicant_event_tdls(wpa_s, data);
3115 #endif /* CONFIG_TDLS */
3118 wpa_supplicant_event_wnm(wpa_s, data);
3120 #endif /* CONFIG_WNM */
3121 #ifdef CONFIG_IEEE80211R
3122 case EVENT_FT_RESPONSE:
3123 wpa_supplicant_event_ft_response(wpa_s, data);
3125 #endif /* CONFIG_IEEE80211R */
3126 #ifdef CONFIG_IBSS_RSN
3127 case EVENT_IBSS_RSN_START:
3128 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3130 #endif /* CONFIG_IBSS_RSN */
3131 case EVENT_ASSOC_REJECT:
3132 if (data->assoc_reject.bssid)
3133 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3134 "bssid=" MACSTR " status_code=%u",
3135 MAC2STR(data->assoc_reject.bssid),
3136 data->assoc_reject.status_code);
3138 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3140 data->assoc_reject.status_code);
3141 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3142 sme_event_assoc_reject(wpa_s, data);
3144 const u8 *bssid = data->assoc_reject.bssid;
3145 if (bssid == NULL || is_zero_ether_addr(bssid))
3146 bssid = wpa_s->pending_bssid;
3147 wpas_connection_failed(wpa_s, bssid);
3148 wpa_supplicant_mark_disassoc(wpa_s);
3151 case EVENT_AUTH_TIMED_OUT:
3152 /* It is possible to get this event from earlier connection */
3153 if (wpa_s->current_ssid &&
3154 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3155 wpa_dbg(wpa_s, MSG_DEBUG,
3156 "Ignore AUTH_TIMED_OUT in mesh configuration");
3159 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3160 sme_event_auth_timed_out(wpa_s, data);
3162 case EVENT_ASSOC_TIMED_OUT:
3163 /* It is possible to get this event from earlier connection */
3164 if (wpa_s->current_ssid &&
3165 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3166 wpa_dbg(wpa_s, MSG_DEBUG,
3167 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3170 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3171 sme_event_assoc_timed_out(wpa_s, data);
3173 case EVENT_TX_STATUS:
3174 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3175 " type=%d stype=%d",
3176 MAC2STR(data->tx_status.dst),
3177 data->tx_status.type, data->tx_status.stype);
3179 if (wpa_s->ap_iface == NULL) {
3180 #ifdef CONFIG_OFFCHANNEL
3181 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3182 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3183 offchannel_send_action_tx_status(
3184 wpa_s, data->tx_status.dst,
3185 data->tx_status.data,
3186 data->tx_status.data_len,
3187 data->tx_status.ack ?
3188 OFFCHANNEL_SEND_ACTION_SUCCESS :
3189 OFFCHANNEL_SEND_ACTION_NO_ACK);
3190 #endif /* CONFIG_OFFCHANNEL */
3193 #endif /* CONFIG_AP */
3194 #ifdef CONFIG_OFFCHANNEL
3195 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3196 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3198 * Catch TX status events for Action frames we sent via group
3199 * interface in GO mode.
3201 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3202 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3203 os_memcmp(wpa_s->parent->pending_action_dst,
3204 data->tx_status.dst, ETH_ALEN) == 0) {
3205 offchannel_send_action_tx_status(
3206 wpa_s->parent, data->tx_status.dst,
3207 data->tx_status.data,
3208 data->tx_status.data_len,
3209 data->tx_status.ack ?
3210 OFFCHANNEL_SEND_ACTION_SUCCESS :
3211 OFFCHANNEL_SEND_ACTION_NO_ACK);
3214 #endif /* CONFIG_OFFCHANNEL */
3216 switch (data->tx_status.type) {
3217 case WLAN_FC_TYPE_MGMT:
3218 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3219 data->tx_status.data_len,
3220 data->tx_status.stype,
3221 data->tx_status.ack);
3223 case WLAN_FC_TYPE_DATA:
3224 ap_tx_status(wpa_s, data->tx_status.dst,
3225 data->tx_status.data,
3226 data->tx_status.data_len,
3227 data->tx_status.ack);
3230 #endif /* CONFIG_AP */
3233 case EVENT_EAPOL_TX_STATUS:
3234 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3235 data->eapol_tx_status.data,
3236 data->eapol_tx_status.data_len,
3237 data->eapol_tx_status.ack);
3239 case EVENT_DRIVER_CLIENT_POLL_OK:
3240 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3242 case EVENT_RX_FROM_UNKNOWN:
3243 if (wpa_s->ap_iface == NULL)
3245 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3246 data->rx_from_unknown.wds);
3248 case EVENT_CH_SWITCH:
3251 if (!wpa_s->ap_iface) {
3252 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3253 "event in non-AP mode");
3257 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3258 data->ch_switch.ht_enabled,
3259 data->ch_switch.ch_offset,
3260 data->ch_switch.ch_width,
3261 data->ch_switch.cf1,
3262 data->ch_switch.cf2);
3264 #endif /* CONFIG_AP */
3265 case EVENT_RX_MGMT: {
3267 const struct ieee80211_mgmt *mgmt;
3269 #ifdef CONFIG_TESTING_OPTIONS
3270 if (wpa_s->ext_mgmt_frame_handling) {
3271 struct rx_mgmt *rx = &data->rx_mgmt;
3272 size_t hex_len = 2 * rx->frame_len + 1;
3273 char *hex = os_malloc(hex_len);
3275 wpa_snprintf_hex(hex, hex_len,
3276 rx->frame, rx->frame_len);
3277 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3278 rx->freq, rx->datarate, rx->ssi_signal,
3284 #endif /* CONFIG_TESTING_OPTIONS */
3286 mgmt = (const struct ieee80211_mgmt *)
3287 data->rx_mgmt.frame;
3288 fc = le_to_host16(mgmt->frame_control);
3289 stype = WLAN_FC_GET_STYPE(fc);
3292 if (wpa_s->ap_iface == NULL) {
3293 #endif /* CONFIG_AP */
3295 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3296 data->rx_mgmt.frame_len > 24) {
3297 const u8 *src = mgmt->sa;
3298 const u8 *ie = mgmt->u.probe_req.variable;
3299 size_t ie_len = data->rx_mgmt.frame_len -
3300 (mgmt->u.probe_req.variable -
3301 data->rx_mgmt.frame);
3302 wpas_p2p_probe_req_rx(
3303 wpa_s, src, mgmt->da,
3304 mgmt->bssid, ie, ie_len,
3305 data->rx_mgmt.ssi_signal);
3308 #endif /* CONFIG_P2P */
3309 #ifdef CONFIG_IBSS_RSN
3310 if (wpa_s->current_ssid &&
3311 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3312 stype == WLAN_FC_STYPE_AUTH &&
3313 data->rx_mgmt.frame_len >= 30) {
3314 wpa_supplicant_event_ibss_auth(wpa_s, data);
3317 #endif /* CONFIG_IBSS_RSN */
3319 if (stype == WLAN_FC_STYPE_ACTION) {
3320 wpas_event_rx_mgmt_action(
3321 wpa_s, data->rx_mgmt.frame,
3322 data->rx_mgmt.frame_len,
3324 data->rx_mgmt.ssi_signal);
3329 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3333 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3334 "management frame in non-AP mode");
3339 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3340 data->rx_mgmt.frame_len > 24) {
3341 const u8 *ie = mgmt->u.probe_req.variable;
3342 size_t ie_len = data->rx_mgmt.frame_len -
3343 (mgmt->u.probe_req.variable -
3344 data->rx_mgmt.frame);
3346 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3347 mgmt->bssid, ie, ie_len,
3348 data->rx_mgmt.ssi_signal);
3351 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3352 #endif /* CONFIG_AP */
3355 case EVENT_RX_PROBE_REQ:
3356 if (data->rx_probe_req.sa == NULL ||
3357 data->rx_probe_req.ie == NULL)
3360 if (wpa_s->ap_iface) {
3361 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3362 data->rx_probe_req.sa,
3363 data->rx_probe_req.da,
3364 data->rx_probe_req.bssid,
3365 data->rx_probe_req.ie,
3366 data->rx_probe_req.ie_len,
3367 data->rx_probe_req.ssi_signal);
3370 #endif /* CONFIG_AP */
3371 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3372 data->rx_probe_req.da,
3373 data->rx_probe_req.bssid,
3374 data->rx_probe_req.ie,
3375 data->rx_probe_req.ie_len,
3376 data->rx_probe_req.ssi_signal);
3378 case EVENT_REMAIN_ON_CHANNEL:
3379 #ifdef CONFIG_OFFCHANNEL
3380 offchannel_remain_on_channel_cb(
3381 wpa_s, data->remain_on_channel.freq,
3382 data->remain_on_channel.duration);
3383 #endif /* CONFIG_OFFCHANNEL */
3384 wpas_p2p_remain_on_channel_cb(
3385 wpa_s, data->remain_on_channel.freq,
3386 data->remain_on_channel.duration);
3388 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3389 #ifdef CONFIG_OFFCHANNEL
3390 offchannel_cancel_remain_on_channel_cb(
3391 wpa_s, data->remain_on_channel.freq);
3392 #endif /* CONFIG_OFFCHANNEL */
3393 wpas_p2p_cancel_remain_on_channel_cb(
3394 wpa_s, data->remain_on_channel.freq);
3396 case EVENT_EAPOL_RX:
3397 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3398 data->eapol_rx.data,
3399 data->eapol_rx.data_len);
3401 case EVENT_SIGNAL_CHANGE:
3402 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3403 "above=%d signal=%d noise=%d txrate=%d",
3404 data->signal_change.above_threshold,
3405 data->signal_change.current_signal,
3406 data->signal_change.current_noise,
3407 data->signal_change.current_txrate);
3408 bgscan_notify_signal_change(
3409 wpa_s, data->signal_change.above_threshold,
3410 data->signal_change.current_signal,
3411 data->signal_change.current_noise,
3412 data->signal_change.current_txrate);
3414 case EVENT_INTERFACE_ENABLED:
3415 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3416 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3417 wpa_supplicant_update_mac_addr(wpa_s);
3418 if (wpa_s->p2p_mgmt) {
3419 wpa_supplicant_set_state(wpa_s,
3425 if (!wpa_s->ap_iface) {
3426 wpa_supplicant_set_state(wpa_s,
3428 wpa_s->scan_req = NORMAL_SCAN_REQ;
3429 wpa_supplicant_req_scan(wpa_s, 0, 0);
3431 wpa_supplicant_set_state(wpa_s,
3433 #else /* CONFIG_AP */
3434 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3435 wpa_supplicant_req_scan(wpa_s, 0, 0);
3436 #endif /* CONFIG_AP */
3439 case EVENT_INTERFACE_DISABLED:
3440 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3442 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3443 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3444 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3446 * Mark interface disabled if this happens to end up not
3447 * being removed as a separate P2P group interface.
3449 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3451 * The interface was externally disabled. Remove
3452 * it assuming an external entity will start a
3453 * new session if needed.
3455 if (wpa_s->current_ssid &&
3456 wpa_s->current_ssid->p2p_group)
3457 wpas_p2p_interface_unavailable(wpa_s);
3459 wpas_p2p_disconnect(wpa_s);
3461 * wpa_s instance may have been freed, so must not use
3466 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3467 p2p_in_progress(wpa_s->global->p2p) > 1) {
3468 /* This radio work will be cancelled, so clear P2P
3471 p2p_stop_find(wpa_s->global->p2p);
3473 #endif /* CONFIG_P2P */
3475 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3477 * Indicate disconnection to keep ctrl_iface events
3480 wpa_supplicant_event_disassoc(
3481 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3483 wpa_supplicant_mark_disassoc(wpa_s);
3484 radio_remove_works(wpa_s, NULL, 0);
3486 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3488 case EVENT_CHANNEL_LIST_CHANGED:
3489 wpa_supplicant_update_channel_list(
3490 wpa_s, &data->channel_list_changed);
3492 case EVENT_INTERFACE_UNAVAILABLE:
3493 wpas_p2p_interface_unavailable(wpa_s);
3495 case EVENT_BEST_CHANNEL:
3496 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3498 data->best_chan.freq_24, data->best_chan.freq_5,
3499 data->best_chan.freq_overall);
3500 wpa_s->best_24_freq = data->best_chan.freq_24;
3501 wpa_s->best_5_freq = data->best_chan.freq_5;
3502 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3503 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3504 data->best_chan.freq_5,
3505 data->best_chan.freq_overall);
3507 case EVENT_UNPROT_DEAUTH:
3508 wpa_supplicant_event_unprot_deauth(wpa_s,
3509 &data->unprot_deauth);
3511 case EVENT_UNPROT_DISASSOC:
3512 wpa_supplicant_event_unprot_disassoc(wpa_s,
3513 &data->unprot_disassoc);
3515 case EVENT_STATION_LOW_ACK:
3517 if (wpa_s->ap_iface && data)
3518 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3519 data->low_ack.addr);
3520 #endif /* CONFIG_AP */
3523 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3524 data->low_ack.addr);
3525 #endif /* CONFIG_TDLS */
3527 case EVENT_IBSS_PEER_LOST:
3528 #ifdef CONFIG_IBSS_RSN
3529 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3530 #endif /* CONFIG_IBSS_RSN */
3532 case EVENT_DRIVER_GTK_REKEY:
3533 if (os_memcmp(data->driver_gtk_rekey.bssid,
3534 wpa_s->bssid, ETH_ALEN))
3538 wpa_sm_update_replay_ctr(wpa_s->wpa,
3539 data->driver_gtk_rekey.replay_ctr);
3541 case EVENT_SCHED_SCAN_STOPPED:
3543 wpa_s->sched_scanning = 0;
3544 wpa_supplicant_notify_scanning(wpa_s, 0);
3546 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3550 * Start a new sched scan to continue searching for more SSIDs
3551 * either if timed out or PNO schedule scan is pending.
3553 if (wpa_s->sched_scan_timed_out) {
3554 wpa_supplicant_req_sched_scan(wpa_s);
3555 } else if (wpa_s->pno_sched_pending) {
3556 wpa_s->pno_sched_pending = 0;
3557 wpas_start_pno(wpa_s);
3561 case EVENT_WPS_BUTTON_PUSHED:
3563 wpas_wps_start_pbc(wpa_s, NULL, 0);
3564 #endif /* CONFIG_WPS */
3566 case EVENT_AVOID_FREQUENCIES:
3567 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3569 case EVENT_CONNECT_FAILED_REASON:
3571 if (!wpa_s->ap_iface || !data)
3573 hostapd_event_connect_failed_reason(
3574 wpa_s->ap_iface->bss[0],
3575 data->connect_failed_reason.addr,
3576 data->connect_failed_reason.code);
3577 #endif /* CONFIG_AP */
3579 case EVENT_NEW_PEER_CANDIDATE:
3581 if (!wpa_s->ifmsh || !data)
3583 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3584 data->mesh_peer.ies,
3585 data->mesh_peer.ie_len);
3586 #endif /* CONFIG_MESH */
3589 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);