2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2019, 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"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "common/gas_server.h"
32 #include "common/dpp.h"
33 #include "crypto/random.h"
34 #include "blacklist.h"
35 #include "wpas_glue.h"
36 #include "wps_supplicant.h"
39 #include "gas_query.h"
40 #include "p2p_supplicant.h"
46 #include "offchannel.h"
47 #include "interworking.h"
51 #include "dpp_supplicant.h"
54 #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57 #ifndef CONFIG_NO_SCAN_PROCESSING
58 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
59 int new_scan, int own_request);
60 #endif /* CONFIG_NO_SCAN_PROCESSING */
63 int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
65 struct os_reltime now;
67 if (ssid == NULL || ssid->disabled_until.sec == 0)
71 if (ssid->disabled_until.sec > now.sec)
72 return ssid->disabled_until.sec - now.sec;
74 wpas_clear_temp_disabled(wpa_s, ssid, 0);
80 #ifndef CONFIG_NO_SCAN_PROCESSING
82 * wpas_reenabled_network_time - Time until first network is re-enabled
83 * @wpa_s: Pointer to wpa_supplicant data
84 * Returns: If all enabled networks are temporarily disabled, returns the time
85 * (in sec) until the first network is re-enabled. Otherwise returns 0.
87 * This function is used in case all enabled networks are temporarily disabled,
88 * in which case it returns the time (in sec) that the first network will be
89 * re-enabled. The function assumes that at least one network is enabled.
91 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
93 struct wpa_ssid *ssid;
94 int disabled_for, res = 0;
96 #ifdef CONFIG_INTERWORKING
97 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
100 #endif /* CONFIG_INTERWORKING */
102 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
106 disabled_for = wpas_temp_disabled(wpa_s, ssid);
110 if (!res || disabled_for < res)
116 #endif /* CONFIG_NO_SCAN_PROCESSING */
119 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
121 struct wpa_supplicant *wpa_s = eloop_ctx;
123 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
126 wpa_dbg(wpa_s, MSG_DEBUG,
127 "Try to associate due to network getting re-enabled");
128 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
129 wpa_supplicant_cancel_sched_scan(wpa_s);
130 wpa_supplicant_req_scan(wpa_s, 0, 0);
135 static struct wpa_bss * wpa_supplicant_get_new_bss(
136 struct wpa_supplicant *wpa_s, const u8 *bssid)
138 struct wpa_bss *bss = NULL;
139 struct wpa_ssid *ssid = wpa_s->current_ssid;
141 if (ssid->ssid_len > 0)
142 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
144 bss = wpa_bss_get_bssid(wpa_s, bssid);
150 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
152 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155 wpa_supplicant_update_scan_results(wpa_s);
157 /* Get the BSS from the new scan results */
158 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
162 wpa_s->current_bss = bss;
166 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
168 struct wpa_ssid *ssid, *old_ssid;
169 u8 drv_ssid[SSID_MAX_LEN];
173 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
174 wpa_supplicant_update_current_bss(wpa_s);
176 if (wpa_s->current_ssid->ssid_len == 0)
177 return 0; /* current profile still in use */
178 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
180 wpa_msg(wpa_s, MSG_INFO,
181 "Failed to read SSID from driver");
182 return 0; /* try to use current profile */
186 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
187 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
189 return 0; /* current profile still in use */
191 wpa_msg(wpa_s, MSG_DEBUG,
192 "Driver-initiated BSS selection changed the SSID to %s",
193 wpa_ssid_txt(drv_ssid, drv_ssid_len));
194 /* continue selecting a new network profile */
197 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
199 ssid = wpa_supplicant_get_ssid(wpa_s);
201 wpa_msg(wpa_s, MSG_INFO,
202 "No network configuration found for the current AP");
206 if (wpas_network_disabled(wpa_s, ssid)) {
207 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
211 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
212 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
217 res = wpas_temp_disabled(wpa_s, ssid);
219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
220 "disabled for %d second(s)", res);
224 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
226 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
228 size_t wpa_ie_len = sizeof(wpa_ie);
229 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
230 wpa_ie, &wpa_ie_len) < 0)
231 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
233 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
236 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
237 eapol_sm_invalidate_cached_session(wpa_s->eapol);
238 old_ssid = wpa_s->current_ssid;
239 wpa_s->current_ssid = ssid;
241 wpa_supplicant_update_current_bss(wpa_s);
243 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
244 wpa_supplicant_initiate_eapol(wpa_s);
245 if (old_ssid != wpa_s->current_ssid)
246 wpas_notify_network_changed(wpa_s);
252 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
254 struct wpa_supplicant *wpa_s = eloop_ctx;
256 if (wpa_s->countermeasures) {
257 wpa_s->countermeasures = 0;
258 wpa_drv_set_countermeasures(wpa_s, 0);
259 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
262 * It is possible that the device is sched scanning, which means
263 * that a connection attempt will be done only when we receive
264 * scan results. However, in this case, it would be preferable
265 * to scan and connect immediately, so cancel the sched_scan and
266 * issue a regular scan flow.
268 wpa_supplicant_cancel_sched_scan(wpa_s);
269 wpa_supplicant_req_scan(wpa_s, 0, 0);
274 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
278 wnm_bss_keep_alive_deinit(wpa_s);
280 #ifdef CONFIG_IBSS_RSN
281 ibss_rsn_deinit(wpa_s->ibss_rsn);
282 wpa_s->ibss_rsn = NULL;
283 #endif /* CONFIG_IBSS_RSN */
286 wpa_supplicant_ap_deinit(wpa_s);
287 #endif /* CONFIG_AP */
290 /* Clear possibly configured frame filters */
291 wpa_drv_configure_frame_filters(wpa_s, 0);
292 #endif /* CONFIG_HS20 */
294 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
297 if (os_reltime_initialized(&wpa_s->session_start)) {
298 os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
299 wpa_s->session_start.sec = 0;
300 wpa_s->session_start.usec = 0;
301 wpas_notify_session_length(wpa_s);
304 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
305 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
306 os_memset(wpa_s->bssid, 0, ETH_ALEN);
307 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
308 sme_clear_on_disassoc(wpa_s);
309 wpa_s->current_bss = NULL;
310 wpa_s->assoc_freq = 0;
313 wpas_notify_bssid_changed(wpa_s);
315 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
316 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
317 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
318 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
319 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)
320 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
321 wpa_s->ap_ies_from_associnfo = 0;
322 wpa_s->current_ssid = NULL;
323 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
326 wpas_rrm_reset(wpa_s);
327 wpa_s->wnmsleep_used = 0;
328 wnm_clear_coloc_intf_reporting(wpa_s);
330 #ifdef CONFIG_TESTING_OPTIONS
331 wpa_s->last_tk_alg = WPA_ALG_NONE;
332 os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
333 #endif /* CONFIG_TESTING_OPTIONS */
334 wpa_s->ieee80211ac = 0;
336 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
337 wpa_s->enabled_4addr_mode = 0;
341 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
343 struct wpa_ie_data ie;
347 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
351 for (i = 0; i < ie.num_pmkid; i++) {
352 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
353 ie.pmkid + i * PMKID_LEN,
354 NULL, NULL, 0, NULL, 0);
355 if (pmksa_set == 0) {
356 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
361 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
362 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
366 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
367 union wpa_event_data *data)
370 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
374 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
375 " index=%d preauth=%d",
376 MAC2STR(data->pmkid_candidate.bssid),
377 data->pmkid_candidate.index,
378 data->pmkid_candidate.preauth);
380 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
381 data->pmkid_candidate.index,
382 data->pmkid_candidate.preauth);
386 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
388 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
389 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
392 #ifdef IEEE8021X_EAPOL
393 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
394 wpa_s->current_ssid &&
395 !(wpa_s->current_ssid->eapol_flags &
396 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
397 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
398 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
399 * plaintext or static WEP keys). */
402 #endif /* IEEE8021X_EAPOL */
409 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
410 * @wpa_s: pointer to wpa_supplicant data
411 * @ssid: Configuration data for the network
412 * Returns: 0 on success, -1 on failure
414 * This function is called when starting authentication with a network that is
415 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
417 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
418 struct wpa_ssid *ssid)
420 #ifdef IEEE8021X_EAPOL
422 int aka = 0, sim = 0;
424 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
425 wpa_s->scard != NULL || wpa_s->conf->external_sim)
428 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
432 struct eap_method_type *eap = ssid->eap.eap_methods;
433 while (eap->vendor != EAP_VENDOR_IETF ||
434 eap->method != EAP_TYPE_NONE) {
435 if (eap->vendor == EAP_VENDOR_IETF) {
436 if (eap->method == EAP_TYPE_SIM)
438 else if (eap->method == EAP_TYPE_AKA ||
439 eap->method == EAP_TYPE_AKA_PRIME)
446 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
448 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
449 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
454 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
455 "use SIM, but neither EAP-SIM nor EAP-AKA are "
460 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
461 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
463 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
464 if (wpa_s->scard == NULL) {
465 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
469 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
470 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
471 #endif /* PCSC_FUNCS */
472 #endif /* IEEE8021X_EAPOL */
478 #ifndef CONFIG_NO_SCAN_PROCESSING
480 static int has_wep_key(struct wpa_ssid *ssid)
484 for (i = 0; i < NUM_WEP_KEYS; i++) {
485 if (ssid->wep_key_len[i])
493 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
494 struct wpa_ssid *ssid)
498 if (ssid->mixed_cell)
502 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
504 #endif /* CONFIG_WPS */
507 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
509 #endif /* CONFIG_OWE */
511 if (has_wep_key(ssid))
514 #ifdef IEEE8021X_EAPOL
515 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
516 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
517 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
519 #endif /* IEEE8021X_EAPOL */
521 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
524 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
527 if (bss->caps & IEEE80211_CAP_PRIVACY)
533 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
534 struct wpa_ssid *ssid,
535 struct wpa_bss *bss, int debug_print)
537 struct wpa_ie_data ie;
539 const u8 *rsn_ie, *wpa_ie;
543 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
547 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
548 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
549 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
550 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
551 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
553 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
554 while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
557 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
559 wpa_dbg(wpa_s, MSG_DEBUG,
560 " skip RSN IE - parse failed");
563 if (!ie.has_pairwise)
564 ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
566 ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
569 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
572 wpa_dbg(wpa_s, MSG_DEBUG,
573 " selected based on TSN in RSN IE");
577 if (!(ie.proto & ssid->proto) &&
578 !(ssid->proto & WPA_PROTO_OSEN)) {
580 wpa_dbg(wpa_s, MSG_DEBUG,
581 " skip RSN IE - proto mismatch");
585 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
587 wpa_dbg(wpa_s, MSG_DEBUG,
588 " skip RSN IE - PTK cipher mismatch");
592 if (!(ie.group_cipher & ssid->group_cipher)) {
594 wpa_dbg(wpa_s, MSG_DEBUG,
595 " skip RSN IE - GTK cipher mismatch");
599 if (ssid->group_mgmt_cipher &&
600 !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
602 wpa_dbg(wpa_s, MSG_DEBUG,
603 " skip RSN IE - group mgmt cipher mismatch");
607 if (!(ie.key_mgmt & ssid->key_mgmt)) {
609 wpa_dbg(wpa_s, MSG_DEBUG,
610 " skip RSN IE - key mgmt mismatch");
614 #ifdef CONFIG_IEEE80211W
615 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
616 wpas_get_ssid_pmf(wpa_s, ssid) ==
617 MGMT_FRAME_PROTECTION_REQUIRED) {
619 wpa_dbg(wpa_s, MSG_DEBUG,
620 " skip RSN IE - no mgmt frame protection");
623 #endif /* CONFIG_IEEE80211W */
624 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
625 wpas_get_ssid_pmf(wpa_s, ssid) ==
626 NO_MGMT_FRAME_PROTECTION) {
628 wpa_dbg(wpa_s, MSG_DEBUG,
629 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
633 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
634 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
635 wpas_get_ssid_pmf(wpa_s, ssid) !=
636 NO_MGMT_FRAME_PROTECTION) {
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
642 #endif /* CONFIG_MBO */
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " selected based on RSN IE");
650 #ifdef CONFIG_IEEE80211W
651 if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
652 (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
654 wpa_dbg(wpa_s, MSG_DEBUG,
655 " skip - MFP Required but network not MFP Capable");
658 #endif /* CONFIG_IEEE80211W */
660 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
661 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
664 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
666 wpa_dbg(wpa_s, MSG_DEBUG,
667 " skip WPA IE - parse failed");
672 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
675 wpa_dbg(wpa_s, MSG_DEBUG,
676 " selected based on TSN in WPA IE");
680 if (!(ie.proto & ssid->proto)) {
682 wpa_dbg(wpa_s, MSG_DEBUG,
683 " skip WPA IE - proto mismatch");
687 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
689 wpa_dbg(wpa_s, MSG_DEBUG,
690 " skip WPA IE - PTK cipher mismatch");
694 if (!(ie.group_cipher & ssid->group_cipher)) {
696 wpa_dbg(wpa_s, MSG_DEBUG,
697 " skip WPA IE - GTK cipher mismatch");
701 if (!(ie.key_mgmt & ssid->key_mgmt)) {
703 wpa_dbg(wpa_s, MSG_DEBUG,
704 " skip WPA IE - key mgmt mismatch");
709 wpa_dbg(wpa_s, MSG_DEBUG,
710 " selected based on WPA IE");
714 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
717 wpa_dbg(wpa_s, MSG_DEBUG,
718 " allow for non-WPA IEEE 802.1X");
723 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
724 !wpa_ie && !rsn_ie) {
725 if (wpa_s->owe_transition_select &&
726 wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
727 ssid->owe_transition_bss_select_count + 1 <=
728 MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
729 ssid->owe_transition_bss_select_count++;
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " skip OWE transition BSS (selection count %d does not exceed %d)",
733 ssid->owe_transition_bss_select_count,
734 MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
735 wpa_s->owe_transition_search = 1;
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " allow in OWE transition mode");
743 #endif /* CONFIG_OWE */
745 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
746 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
748 wpa_dbg(wpa_s, MSG_DEBUG,
749 " skip - no WPA/RSN proto match");
753 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
754 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
756 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
760 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
762 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
767 wpa_dbg(wpa_s, MSG_DEBUG,
768 " reject due to mismatch with WPA/WPA2");
774 static int freq_allowed(int *freqs, int freq)
781 for (i = 0; freqs[i]; i++)
782 if (freqs[i] == freq)
788 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
791 const struct hostapd_hw_modes *mode = NULL, *modes;
792 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
797 return 1; /* Cannot do matching without knowing band */
799 modes = wpa_s->hw.modes;
802 * The driver does not provide any additional information
803 * about the utilized hardware, so allow the connection attempt
809 for (i = 0; i < wpa_s->hw.num_modes; i++) {
810 for (j = 0; j < modes[i].num_channels; j++) {
811 int freq = modes[i].channels[j].freq;
812 if (freq == bss->freq) {
814 mode->mode == HOSTAPD_MODE_IEEE80211G)
815 break; /* do not allow 802.11b replace
826 for (i = 0; i < (int) sizeof(scan_ie); i++) {
827 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
831 for (j = 2; j < rate_ie[1] + 2; j++) {
832 int flagged = !!(rate_ie[j] & 0x80);
833 int r = (rate_ie[j] & 0x7f) * 5;
836 * IEEE Std 802.11n-2009 7.3.2.2:
837 * The new BSS Membership selector value is encoded
838 * like a legacy basic rate, but it is not a rate and
839 * only indicates if the BSS members are required to
840 * support the mandatory features of Clause 20 [HT PHY]
841 * in order to join the BSS.
843 if (flagged && ((rate_ie[j] & 0x7f) ==
844 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
845 if (!ht_supported(mode)) {
847 wpa_dbg(wpa_s, MSG_DEBUG,
848 " hardware does not support HT PHY");
854 /* There's also a VHT selector for 802.11ac */
855 if (flagged && ((rate_ie[j] & 0x7f) ==
856 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
857 if (!vht_supported(mode)) {
859 wpa_dbg(wpa_s, MSG_DEBUG,
860 " hardware does not support VHT PHY");
869 /* check for legacy basic rates */
870 for (k = 0; k < mode->num_rates; k++) {
871 if (mode->rates[k] == r)
874 if (k == mode->num_rates) {
876 * IEEE Std 802.11-2007 7.3.2.2 demands that in
877 * order to join a BSS all required rates
878 * have to be supported by the hardware.
881 wpa_dbg(wpa_s, MSG_DEBUG,
882 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
884 bss->freq, mode->mode, mode->num_rates);
895 * Test whether BSS is in an ESS.
896 * This is done differently in DMG (60 GHz) and non-DMG bands
898 static int bss_is_ess(struct wpa_bss *bss)
900 if (bss_is_dmg(bss)) {
901 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
902 IEEE80211_CAP_DMG_AP;
905 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
910 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
914 for (i = 0; i < ETH_ALEN; i++) {
915 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
922 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
926 for (i = 0; i < num; i++) {
927 const u8 *a = list + i * ETH_ALEN * 2;
928 const u8 *m = a + ETH_ALEN;
930 if (match_mac_mask(a, addr, m))
937 static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
938 const u8 **ret_ssid, size_t *ret_ssid_len)
941 const u8 *owe, *pos, *end, *bssid;
943 struct wpa_bss *open_bss;
945 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
946 if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
950 end = owe + 2 + owe[1];
952 if (end - pos < ETH_ALEN + 1)
957 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
960 /* Match the profile SSID against the OWE transition mode SSID on the
962 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
963 " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
965 *ret_ssid_len = ssid_len;
967 if (bss->ssid_len > 0)
970 open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
973 if (ssid_len != open_bss->ssid_len ||
974 os_memcmp(pos, open_bss->ssid, ssid_len) != 0) {
975 wpa_dbg(wpa_s, MSG_DEBUG,
976 "OWE: transition mode SSID mismatch: %s",
977 wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len));
981 owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE);
982 if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) {
983 wpa_dbg(wpa_s, MSG_DEBUG,
984 "OWE: transition mode open BSS unexpected info");
989 end = owe + 2 + owe[1];
991 if (end - pos < ETH_ALEN + 1)
993 if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) {
994 wpa_dbg(wpa_s, MSG_DEBUG,
995 "OWE: transition mode BSSID mismatch: " MACSTR,
1001 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
1003 wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s",
1004 wpa_ssid_txt(pos, ssid_len));
1005 os_memcpy(bss->ssid, pos, ssid_len);
1006 bss->ssid_len = ssid_len;
1007 #endif /* CONFIG_OWE */
1011 struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1012 int i, struct wpa_bss *bss,
1013 struct wpa_ssid *group,
1014 int only_first_ssid, int debug_print)
1016 u8 wpa_ie_len, rsn_ie_len;
1018 struct wpa_blacklist *e;
1020 struct wpa_ssid *ssid;
1021 int osen, rsn_osen = 0;
1023 const u8 *assoc_disallow;
1024 #endif /* CONFIG_MBO */
1025 const u8 *match_ssid;
1026 size_t match_ssid_len;
1027 struct wpa_ie_data data;
1029 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1030 wpa_ie_len = ie ? ie[1] : 0;
1032 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1033 rsn_ie_len = ie ? ie[1] : 0;
1034 if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1035 (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1038 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1042 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1043 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1044 i, MAC2STR(bss->bssid),
1045 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1046 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1048 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1050 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1051 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1053 osen ? " osen=1" : "");
1056 e = wpa_blacklist_get(wpa_s, bss->bssid);
1059 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
1061 * When only a single network is enabled, we can
1062 * trigger blacklisting on the first failure. This
1063 * should not be done with multiple enabled networks to
1064 * avoid getting forced to move into a worse ESS on
1065 * single error if there are no other BSSes of the
1070 if (e->count > limit) {
1072 wpa_dbg(wpa_s, MSG_DEBUG,
1073 " skip - blacklisted (count=%d limit=%d)",
1080 match_ssid = bss->ssid;
1081 match_ssid_len = bss->ssid_len;
1082 owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1084 if (match_ssid_len == 0) {
1086 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
1090 if (disallowed_bssid(wpa_s, bss->bssid)) {
1092 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
1096 if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
1098 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
1102 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
1104 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
1105 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
1108 if (wpas_network_disabled(wpa_s, ssid)) {
1110 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
1114 res = wpas_temp_disabled(wpa_s, ssid);
1117 wpa_dbg(wpa_s, MSG_DEBUG,
1118 " skip - disabled temporarily for %d second(s)",
1124 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
1126 wpa_dbg(wpa_s, MSG_DEBUG,
1127 " skip - blacklisted (WPS)");
1131 if (wpa && ssid->ssid_len == 0 &&
1132 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1135 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1136 /* Only allow wildcard SSID match if an AP
1137 * advertises active WPS operation that matches
1140 if (ssid->ssid_len == 0 &&
1141 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1144 #endif /* CONFIG_WPS */
1146 if (ssid->bssid_set && ssid->ssid_len == 0 &&
1147 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
1151 (match_ssid_len != ssid->ssid_len ||
1152 os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1154 wpa_dbg(wpa_s, MSG_DEBUG,
1155 " skip - SSID mismatch");
1159 if (ssid->bssid_set &&
1160 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
1162 wpa_dbg(wpa_s, MSG_DEBUG,
1163 " skip - BSSID mismatch");
1167 /* check blacklist */
1168 if (ssid->num_bssid_blacklist &&
1169 addr_in_list(bss->bssid, ssid->bssid_blacklist,
1170 ssid->num_bssid_blacklist)) {
1172 wpa_dbg(wpa_s, MSG_DEBUG,
1173 " skip - BSSID blacklisted");
1177 /* if there is a whitelist, only accept those APs */
1178 if (ssid->num_bssid_whitelist &&
1179 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
1180 ssid->num_bssid_whitelist)) {
1182 wpa_dbg(wpa_s, MSG_DEBUG,
1183 " skip - BSSID not in whitelist");
1187 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss,
1191 if (!osen && !wpa &&
1192 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1193 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1194 !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1195 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1197 wpa_dbg(wpa_s, MSG_DEBUG,
1198 " skip - non-WPA network not allowed");
1202 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
1203 has_wep_key(ssid)) {
1205 wpa_dbg(wpa_s, MSG_DEBUG,
1206 " skip - ignore WPA/WPA2 AP for WEP network block");
1210 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen &&
1213 wpa_dbg(wpa_s, MSG_DEBUG,
1214 " skip - non-OSEN network not allowed");
1218 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1220 wpa_dbg(wpa_s, MSG_DEBUG,
1221 " skip - privacy mismatch");
1225 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
1226 !bss_is_pbss(bss)) {
1228 wpa_dbg(wpa_s, MSG_DEBUG,
1229 " skip - not ESS, PBSS, or MBSS");
1233 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1235 wpa_dbg(wpa_s, MSG_DEBUG,
1236 " skip - PBSS mismatch (ssid %d bss %d)",
1237 ssid->pbss, bss_is_pbss(bss));
1241 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1243 wpa_dbg(wpa_s, MSG_DEBUG,
1244 " skip - frequency not allowed");
1249 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
1250 ssid->frequency != bss->freq) {
1252 wpa_dbg(wpa_s, MSG_DEBUG,
1253 " skip - frequency not allowed (mesh)");
1256 #endif /* CONFIG_MESH */
1258 if (!rate_match(wpa_s, bss, debug_print)) {
1260 wpa_dbg(wpa_s, MSG_DEBUG,
1261 " skip - rate sets do not match");
1265 #ifndef CONFIG_IBSS_RSN
1266 if (ssid->mode == WPAS_MODE_IBSS &&
1267 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1268 WPA_KEY_MGMT_WPA_NONE))) {
1270 wpa_dbg(wpa_s, MSG_DEBUG,
1271 " skip - IBSS RSN not supported in the build");
1274 #endif /* !CONFIG_IBSS_RSN */
1277 if (ssid->p2p_group &&
1278 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1279 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1281 wpa_dbg(wpa_s, MSG_DEBUG,
1282 " skip - no P2P IE seen");
1286 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1287 struct wpabuf *p2p_ie;
1288 u8 dev_addr[ETH_ALEN];
1290 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1293 wpa_dbg(wpa_s, MSG_DEBUG,
1294 " skip - no P2P element");
1297 p2p_ie = wpa_bss_get_vendor_ie_multi(
1298 bss, P2P_IE_VENDOR_TYPE);
1299 if (p2p_ie == NULL) {
1301 wpa_dbg(wpa_s, MSG_DEBUG,
1302 " skip - could not fetch P2P element");
1306 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1307 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1310 wpa_dbg(wpa_s, MSG_DEBUG,
1311 " skip - no matching GO P2P Device Address in P2P element");
1312 wpabuf_free(p2p_ie);
1315 wpabuf_free(p2p_ie);
1319 * TODO: skip the AP if its P2P IE has Group Formation
1320 * bit set in the P2P Group Capability Bitmap and we
1321 * are not in Group Formation with that device.
1323 #endif /* CONFIG_P2P */
1325 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1327 struct os_reltime diff;
1329 os_reltime_sub(&wpa_s->scan_min_time,
1330 &bss->last_update, &diff);
1332 wpa_dbg(wpa_s, MSG_DEBUG,
1333 " skip - scan result not recent enough (%u.%06u seconds too old)",
1334 (unsigned int) diff.sec,
1335 (unsigned int) diff.usec);
1339 #ifdef CONFIG_TESTING_OPTIONS
1340 if (wpa_s->ignore_assoc_disallow)
1341 goto skip_assoc_disallow;
1342 #endif /* CONFIG_TESTING_OPTIONS */
1343 assoc_disallow = wpas_mbo_get_bss_attr(
1344 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1345 if (assoc_disallow && assoc_disallow[1] >= 1) {
1347 wpa_dbg(wpa_s, MSG_DEBUG,
1348 " skip - MBO association disallowed (reason %u)",
1353 if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1355 wpa_dbg(wpa_s, MSG_DEBUG,
1356 " skip - AP temporarily disallowed");
1359 #ifdef CONFIG_TESTING_OPTIONS
1360 skip_assoc_disallow:
1361 #endif /* CONFIG_TESTING_OPTIONS */
1362 #endif /* CONFIG_MBO */
1365 if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1366 !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) &&
1367 (!ssid->dpp_connector ||
1368 !ssid->dpp_netaccesskey ||
1369 !ssid->dpp_csign)) {
1371 wpa_dbg(wpa_s, MSG_DEBUG,
1372 " skip - no PMKSA entry for DPP");
1375 #endif /* CONFIG_DPP */
1377 /* Matching configuration found */
1381 /* No matching configuration found */
1386 static struct wpa_bss *
1387 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1388 struct wpa_ssid *group,
1389 struct wpa_ssid **selected_ssid,
1390 int only_first_ssid)
1394 if (wpa_s->current_ssid) {
1395 struct wpa_ssid *ssid;
1397 wpa_dbg(wpa_s, MSG_DEBUG,
1398 "Scan results matching the currently selected network");
1399 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1400 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1402 ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1403 only_first_ssid, 0);
1404 if (ssid != wpa_s->current_ssid)
1406 wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1407 " freq=%d level=%d snr=%d est_throughput=%u",
1408 i, MAC2STR(bss->bssid), bss->freq, bss->level,
1409 bss->snr, bss->est_throughput);
1413 if (only_first_ssid)
1414 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1420 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1421 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1423 wpa_s->owe_transition_select = 1;
1424 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1425 only_first_ssid, 1);
1426 wpa_s->owe_transition_select = 0;
1427 if (!*selected_ssid)
1429 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1431 MAC2STR(bss->bssid),
1432 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1440 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1441 struct wpa_ssid **selected_ssid)
1443 struct wpa_bss *selected = NULL;
1445 struct wpa_ssid *next_ssid = NULL;
1446 struct wpa_ssid *ssid;
1448 if (wpa_s->last_scan_res == NULL ||
1449 wpa_s->last_scan_res_used == 0)
1450 return NULL; /* no scan results from last update */
1452 if (wpa_s->next_ssid) {
1453 /* check that next_ssid is still valid */
1454 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1455 if (ssid == wpa_s->next_ssid)
1459 wpa_s->next_ssid = NULL;
1462 while (selected == NULL) {
1463 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1464 if (next_ssid && next_ssid->priority ==
1465 wpa_s->conf->pssid[prio]->priority) {
1466 selected = wpa_supplicant_select_bss(
1467 wpa_s, next_ssid, selected_ssid, 1);
1471 selected = wpa_supplicant_select_bss(
1472 wpa_s, wpa_s->conf->pssid[prio],
1478 if (selected == NULL && wpa_s->blacklist &&
1479 !wpa_s->countermeasures) {
1480 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1481 "blacklist and try again");
1482 wpa_blacklist_clear(wpa_s);
1483 wpa_s->blacklist_cleared++;
1484 } else if (selected == NULL)
1488 ssid = *selected_ssid;
1489 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1490 !ssid->passphrase && !ssid->ext_psk) {
1491 const char *field_name, *txt = NULL;
1493 wpa_dbg(wpa_s, MSG_DEBUG,
1494 "PSK/passphrase not yet available for the selected network");
1496 wpas_notify_network_request(wpa_s, ssid,
1497 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1499 field_name = wpa_supplicant_ctrl_req_to_string(
1500 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1501 if (field_name == NULL)
1504 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1513 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1514 int timeout_sec, int timeout_usec)
1516 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1518 * No networks are enabled; short-circuit request so
1519 * we don't wait timeout seconds before transitioning
1520 * to INACTIVE state.
1522 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1523 "since there are no enabled networks");
1524 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1528 wpa_s->scan_for_connection = 1;
1529 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1533 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1534 struct wpa_bss *selected,
1535 struct wpa_ssid *ssid)
1537 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1538 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1539 "PBC session overlap");
1540 wpas_notify_wps_event_pbc_overlap(wpa_s);
1542 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1543 wpa_s->p2p_in_provisioning) {
1544 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1548 #endif /* CONFIG_P2P */
1551 wpas_wps_pbc_overlap(wpa_s);
1552 wpas_wps_cancel(wpa_s);
1553 #endif /* CONFIG_WPS */
1557 wpa_msg(wpa_s, MSG_DEBUG,
1558 "Considering connect request: reassociate: %d selected: "
1559 MACSTR " bssid: " MACSTR " pending: " MACSTR
1560 " wpa_state: %s ssid=%p current_ssid=%p",
1561 wpa_s->reassociate, MAC2STR(selected->bssid),
1562 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1563 wpa_supplicant_state_txt(wpa_s->wpa_state),
1564 ssid, wpa_s->current_ssid);
1567 * Do not trigger new association unless the BSSID has changed or if
1568 * reassociation is requested. If we are in process of associating with
1569 * the selected BSSID, do not trigger new attempt.
1571 if (wpa_s->reassociate ||
1572 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1573 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1574 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1575 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1576 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1578 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1579 ssid != wpa_s->current_ssid)))) {
1580 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1581 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1584 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1585 MAC2STR(selected->bssid));
1586 wpa_supplicant_associate(wpa_s, selected, ssid);
1588 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1589 "connect with the selected AP");
1596 static struct wpa_ssid *
1597 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1600 struct wpa_ssid *ssid;
1602 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1603 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1605 if (wpas_network_disabled(wpa_s, ssid))
1607 #ifndef CONFIG_IBSS_RSN
1608 if (ssid->mode == WPAS_MODE_IBSS &&
1609 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
1610 WPA_KEY_MGMT_WPA_NONE))) {
1611 wpa_msg(wpa_s, MSG_INFO,
1612 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1613 wpa_ssid_txt(ssid->ssid,
1617 #endif /* !CONFIG_IBSS_RSN */
1618 if (ssid->mode == IEEE80211_MODE_IBSS ||
1619 ssid->mode == IEEE80211_MODE_AP ||
1620 ssid->mode == IEEE80211_MODE_MESH)
1628 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1629 * on BSS added and BSS changed events */
1630 static void wpa_supplicant_rsn_preauth_scan_results(
1631 struct wpa_supplicant *wpa_s)
1633 struct wpa_bss *bss;
1635 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1638 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1639 const u8 *ssid, *rsn;
1641 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1645 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1649 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1655 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1656 struct wpa_bss *selected,
1657 struct wpa_ssid *ssid)
1659 struct wpa_bss *current_bss = NULL;
1660 #ifndef CONFIG_NO_ROAMING
1663 int cur_est, sel_est;
1664 #endif /* CONFIG_NO_ROAMING */
1666 if (wpa_s->reassociate)
1667 return 1; /* explicit request to reassociate */
1668 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1669 return 1; /* we are not associated; continue */
1670 if (wpa_s->current_ssid == NULL)
1671 return 1; /* unknown current SSID */
1672 if (wpa_s->current_ssid != ssid)
1673 return 1; /* different network block */
1675 if (wpas_driver_bss_selection(wpa_s))
1676 return 0; /* Driver-based roaming */
1678 if (wpa_s->current_ssid->ssid)
1679 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1680 wpa_s->current_ssid->ssid,
1681 wpa_s->current_ssid->ssid_len);
1683 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1686 return 1; /* current BSS not seen in scan results */
1688 if (current_bss == selected)
1691 if (selected->last_update_idx > current_bss->last_update_idx)
1692 return 1; /* current BSS not seen in the last scan */
1694 #ifndef CONFIG_NO_ROAMING
1695 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1696 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1697 " freq=%d level=%d snr=%d est_throughput=%u",
1698 MAC2STR(current_bss->bssid),
1699 current_bss->freq, current_bss->level,
1700 current_bss->snr, current_bss->est_throughput);
1701 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1702 " freq=%d level=%d snr=%d est_throughput=%u",
1703 MAC2STR(selected->bssid), selected->freq, selected->level,
1704 selected->snr, selected->est_throughput);
1706 if (wpa_s->current_ssid->bssid_set &&
1707 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1709 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1710 "has preferred BSSID");
1714 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1715 wpa_dbg(wpa_s, MSG_DEBUG,
1716 "Allow reassociation - selected BSS has better estimated throughput");
1720 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1722 if (current_bss->level < 0 &&
1723 current_bss->level > selected->level + to_5ghz * 2) {
1724 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1729 if (current_bss->est_throughput > selected->est_throughput + 5000) {
1730 wpa_dbg(wpa_s, MSG_DEBUG,
1731 "Skip roam - Current BSS has better estimated throughput");
1735 cur_est = current_bss->est_throughput;
1736 sel_est = selected->est_throughput;
1738 if (current_bss->level < 0) {
1739 if (current_bss->level < -85)
1741 else if (current_bss->level < -80)
1743 else if (current_bss->level < -75)
1745 else if (current_bss->level < -70)
1749 if (cur_est > sel_est * 1.5)
1751 else if (cur_est > sel_est * 1.2)
1753 else if (cur_est > sel_est * 1.1)
1755 else if (cur_est > sel_est)
1761 /* Make it easier to move to 5 GHz band */
1762 if (sel_est > cur_est * 1.5)
1764 else if (sel_est > cur_est * 1.2)
1766 else if (sel_est > cur_est * 1.1)
1769 if (min_diff > reduce)
1774 diff = abs(current_bss->level - selected->level);
1775 if (diff < min_diff) {
1776 wpa_dbg(wpa_s, MSG_DEBUG,
1777 "Skip roam - too small difference in signal level (%d < %d)",
1782 wpa_dbg(wpa_s, MSG_DEBUG,
1783 "Allow reassociation due to difference in signal level (%d >= %d)",
1786 #else /* CONFIG_NO_ROAMING */
1788 #endif /* CONFIG_NO_ROAMING */
1793 * Return a negative value if no scan results could be fetched or if scan
1794 * results should not be shared with other virtual interfaces.
1795 * Return 0 if scan results were fetched and may be shared with other
1797 * Return 1 if scan results may be shared with other virtual interfaces but may
1798 * not trigger any operations.
1799 * Return 2 if the interface was removed and cannot be used.
1801 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1802 union wpa_event_data *data,
1803 int own_request, int update_only)
1805 struct wpa_scan_results *scan_res = NULL;
1808 #ifndef CONFIG_NO_RANDOM_POOL
1810 #endif /* CONFIG_NO_RANDOM_POOL */
1813 if (wpa_s->ap_iface)
1815 #endif /* CONFIG_AP */
1817 wpa_supplicant_notify_scanning(wpa_s, 0);
1819 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1820 data ? &data->scan_info :
1822 if (scan_res == NULL) {
1823 if (wpa_s->conf->ap_scan == 2 || ap ||
1824 wpa_s->scan_res_handler == scan_only_handler)
1828 if (data && data->scan_info.external_scan)
1830 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1832 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1834 goto scan_work_done;
1837 #ifndef CONFIG_NO_RANDOM_POOL
1838 num = scan_res->num;
1841 for (i = 0; i < num; i++) {
1843 struct wpa_scan_res *res = scan_res->res[i];
1844 buf[0] = res->bssid[5];
1845 buf[1] = res->qual & 0xff;
1846 buf[2] = res->noise & 0xff;
1847 buf[3] = res->level & 0xff;
1848 buf[4] = res->tsf & 0xff;
1849 random_add_randomness(buf, sizeof(buf));
1851 #endif /* CONFIG_NO_RANDOM_POOL */
1855 goto scan_work_done;
1858 if (own_request && wpa_s->scan_res_handler &&
1859 !(data && data->scan_info.external_scan)) {
1860 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1861 struct wpa_scan_results *scan_res);
1863 scan_res_handler = wpa_s->scan_res_handler;
1864 wpa_s->scan_res_handler = NULL;
1865 scan_res_handler(wpa_s, scan_res);
1867 goto scan_work_done;
1871 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1873 if (wpa_s->ap_iface->scan_cb)
1874 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1875 #endif /* CONFIG_AP */
1876 goto scan_work_done;
1879 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1880 wpa_s->own_scan_running,
1881 data ? data->scan_info.external_scan : 0);
1882 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1883 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1884 own_request && !(data && data->scan_info.external_scan)) {
1885 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1886 wpa_s->manual_scan_id);
1887 wpa_s->manual_scan_use_id = 0;
1889 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1891 wpas_notify_scan_results(wpa_s);
1893 wpas_notify_scan_done(wpa_s, 1);
1895 if (data && data->scan_info.external_scan) {
1896 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1897 wpa_scan_results_free(scan_res);
1901 if (wnm_scan_process(wpa_s, 1) > 0)
1902 goto scan_work_done;
1904 if (sme_proc_obss_scan(wpa_s) > 0)
1905 goto scan_work_done;
1907 if (own_request && data &&
1908 wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
1909 goto scan_work_done;
1911 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1912 goto scan_work_done;
1914 if (autoscan_notify_scan(wpa_s, scan_res))
1915 goto scan_work_done;
1917 if (wpa_s->disconnected) {
1918 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1919 goto scan_work_done;
1922 if (!wpas_driver_bss_selection(wpa_s) &&
1923 bgscan_notify_scan(wpa_s, scan_res) == 1)
1924 goto scan_work_done;
1926 wpas_wps_update_ap_info(wpa_s, scan_res);
1928 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1929 wpa_s->wpa_state < WPA_COMPLETED)
1930 goto scan_work_done;
1932 wpa_scan_results_free(scan_res);
1934 if (own_request && wpa_s->scan_work) {
1935 struct wpa_radio_work *work = wpa_s->scan_work;
1936 wpa_s->scan_work = NULL;
1937 radio_work_done(work);
1940 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1943 wpa_scan_results_free(scan_res);
1944 if (own_request && wpa_s->scan_work) {
1945 struct wpa_radio_work *work = wpa_s->scan_work;
1946 wpa_s->scan_work = NULL;
1947 radio_work_done(work);
1953 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1954 int new_scan, int own_request)
1956 struct wpa_bss *selected;
1957 struct wpa_ssid *ssid = NULL;
1958 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1960 if (time_to_reenable > 0) {
1961 wpa_dbg(wpa_s, MSG_DEBUG,
1962 "Postpone network selection by %d seconds since all networks are disabled",
1964 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1965 eloop_register_timeout(time_to_reenable, 0,
1966 wpas_network_reenabled, wpa_s, NULL);
1970 if (wpa_s->p2p_mgmt)
1971 return 0; /* no normal connection on p2p_mgmt interface */
1973 wpa_s->owe_transition_search = 0;
1974 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1978 wpa_msg(wpa_s, MSG_INFO,
1979 "Avoiding join because we already joined a mesh group");
1982 #endif /* CONFIG_MESH */
1986 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1989 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1993 if (ssid != wpa_s->current_ssid &&
1994 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1995 wpa_s->own_disconnect_req = 1;
1996 wpa_supplicant_deauthenticate(
1997 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2000 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
2005 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2007 * Do not allow other virtual radios to trigger operations based
2008 * on these scan results since we do not want them to start
2009 * other associations at the same time.
2013 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2014 ssid = wpa_supplicant_pick_new_network(wpa_s);
2016 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2017 wpa_supplicant_associate(wpa_s, NULL, ssid);
2019 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2020 } else if (own_request) {
2022 * No SSID found. If SCAN results are as a result of
2023 * own scan request and not due to a scan request on
2024 * another shared interface, try another scan.
2026 int timeout_sec = wpa_s->scan_interval;
2027 int timeout_usec = 0;
2031 res = wpas_p2p_scan_no_go_seen(wpa_s);
2037 if (wpa_s->p2p_in_provisioning ||
2038 wpa_s->show_group_started ||
2039 wpa_s->p2p_in_invitation) {
2041 * Use shorter wait during P2P Provisioning
2042 * state and during P2P join-a-group operation
2043 * to speed up group formation.
2046 timeout_usec = 250000;
2047 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2051 #endif /* CONFIG_P2P */
2052 #ifdef CONFIG_INTERWORKING
2053 if (wpa_s->conf->auto_interworking &&
2054 wpa_s->conf->interworking &&
2055 wpa_s->conf->cred) {
2056 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2057 "start ANQP fetch since no matching "
2059 wpa_s->network_select = 1;
2060 wpa_s->auto_network_select = 1;
2061 interworking_start_fetch_anqp(wpa_s);
2064 #endif /* CONFIG_INTERWORKING */
2066 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2067 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2069 timeout_usec = 500000;
2070 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2074 #endif /* CONFIG_WPS */
2076 if (wpa_s->owe_transition_search) {
2077 wpa_dbg(wpa_s, MSG_DEBUG,
2078 "OWE: Use shorter wait during transition mode search");
2080 timeout_usec = 500000;
2081 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2085 #endif /* CONFIG_OWE */
2086 if (wpa_supplicant_req_sched_scan(wpa_s))
2087 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2090 wpa_msg_ctrl(wpa_s, MSG_INFO,
2091 WPA_EVENT_NETWORK_NOT_FOUND);
2098 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2099 union wpa_event_data *data)
2101 struct wpa_supplicant *ifs;
2104 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
2107 * Interface may have been removed, so must not dereference
2115 * If no scan results could be fetched, then no need to
2116 * notify those interfaces that did not actually request
2117 * this scan. Similarly, if scan results started a new operation on this
2118 * interface, do not notify other interfaces to avoid concurrent
2119 * operations during a connection attempt.
2125 * Check other interfaces to see if they share the same radio. If
2126 * so, they get updated with this same scan info.
2128 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2131 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2132 "sibling", ifs->ifname);
2133 res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2143 #endif /* CONFIG_NO_SCAN_PROCESSING */
2146 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2148 #ifdef CONFIG_NO_SCAN_PROCESSING
2150 #else /* CONFIG_NO_SCAN_PROCESSING */
2151 struct os_reltime now;
2153 wpa_s->ignore_post_flush_scan_res = 0;
2155 if (wpa_s->last_scan_res_used == 0)
2158 os_get_reltime(&now);
2159 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
2160 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2164 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
2165 #endif /* CONFIG_NO_SCAN_PROCESSING */
2170 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2172 struct wpa_supplicant *wpa_s = eloop_ctx;
2174 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2177 if (!wpa_s->no_keep_alive) {
2178 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2179 MAC2STR(wpa_s->bssid));
2180 /* TODO: could skip this if normal data traffic has been sent */
2181 /* TODO: Consider using some more appropriate data frame for
2184 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2189 if (wpa_s->sme.bss_max_idle_period) {
2191 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2194 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2195 wnm_bss_keep_alive, wpa_s, NULL);
2197 #endif /* CONFIG_SME */
2201 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2202 const u8 *ies, size_t ies_len)
2204 struct ieee802_11_elems elems;
2209 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2213 if (elems.bss_max_idle_period) {
2215 wpa_s->sme.bss_max_idle_period =
2216 WPA_GET_LE16(elems.bss_max_idle_period);
2217 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2218 "TU)%s", wpa_s->sme.bss_max_idle_period,
2219 (elems.bss_max_idle_period[2] & 0x01) ?
2220 " (protected keep-live required)" : "");
2221 if (wpa_s->sme.bss_max_idle_period == 0)
2222 wpa_s->sme.bss_max_idle_period = 1;
2223 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2224 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2225 /* msec times 1000 */
2226 msec = wpa_s->sme.bss_max_idle_period * 1024;
2229 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2230 wnm_bss_keep_alive, wpa_s,
2234 #endif /* CONFIG_SME */
2237 #endif /* CONFIG_WNM */
2240 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2243 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2244 #endif /* CONFIG_WNM */
2248 #ifdef CONFIG_INTERWORKING
2250 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
2255 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
2256 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
2258 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
2265 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
2266 const u8 *ies, size_t ies_len)
2268 struct ieee802_11_elems elems;
2273 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2276 if (elems.qos_map_set) {
2277 wpas_qos_map_set(wpa_s, elems.qos_map_set,
2278 elems.qos_map_set_len);
2282 #endif /* CONFIG_INTERWORKING */
2285 static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
2286 const u8 *ies, size_t ies_len)
2288 struct ieee802_11_elems elems;
2289 const u8 *map_sub_elem, *pos;
2292 if (!wpa_s->current_ssid ||
2293 !wpa_s->current_ssid->multi_ap_backhaul_sta ||
2295 ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2298 if (!elems.multi_ap || elems.multi_ap_len < 7) {
2299 wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol");
2303 pos = elems.multi_ap + 4;
2304 len = elems.multi_ap_len - 4;
2306 map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE);
2307 if (!map_sub_elem || map_sub_elem[1] < 1) {
2308 wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type");
2312 if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) {
2313 if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) &&
2314 wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2315 wpa_printf(MSG_INFO,
2316 "WPS active, accepting fronthaul-only BSS");
2317 /* Don't set 4addr mode in this case, so just return */
2320 wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
2324 if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
2325 wpa_printf(MSG_ERROR, "Failed to set 4addr mode");
2328 wpa_s->enabled_4addr_mode = 1;
2332 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2337 static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
2338 const u8 *ie, size_t ie_len)
2340 struct mb_ies_info mb_ies;
2342 if (!ie || !ie_len || !wpa_s->fst)
2345 os_memset(&mb_ies, 0, sizeof(mb_ies));
2347 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
2352 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
2357 if (ie[0] == WLAN_EID_MULTI_BAND) {
2358 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
2359 (unsigned int) len);
2360 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
2361 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
2369 if (mb_ies.nof_ies > 0) {
2370 wpabuf_free(wpa_s->received_mb_ies);
2371 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2377 #endif /* CONFIG_FST */
2380 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
2381 union wpa_event_data *data)
2383 int l, len, found = 0, wpa_found, rsn_found;
2385 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2387 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2389 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
2390 if (data->assoc_info.req_ies)
2391 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
2392 data->assoc_info.req_ies_len);
2393 if (data->assoc_info.resp_ies) {
2394 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
2395 data->assoc_info.resp_ies_len);
2397 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
2398 data->assoc_info.resp_ies_len);
2399 #endif /* CONFIG_TDLS */
2401 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2402 data->assoc_info.resp_ies_len);
2403 #endif /* CONFIG_WNM */
2404 #ifdef CONFIG_INTERWORKING
2405 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2406 data->assoc_info.resp_ies_len);
2407 #endif /* CONFIG_INTERWORKING */
2408 if (wpa_s->hw_capab == CAPAB_VHT &&
2409 get_ie(data->assoc_info.resp_ies,
2410 data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
2411 wpa_s->ieee80211ac = 1;
2413 multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
2414 data->assoc_info.resp_ies_len);
2416 if (data->assoc_info.beacon_ies)
2417 wpa_hexdump(MSG_DEBUG, "beacon_ies",
2418 data->assoc_info.beacon_ies,
2419 data->assoc_info.beacon_ies_len);
2420 if (data->assoc_info.freq)
2421 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
2422 data->assoc_info.freq);
2424 wpa_s->connection_set = 0;
2425 if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
2426 struct ieee802_11_elems req_elems, resp_elems;
2428 if (ieee802_11_parse_elems(data->assoc_info.req_ies,
2429 data->assoc_info.req_ies_len,
2430 &req_elems, 0) != ParseFailed &&
2431 ieee802_11_parse_elems(data->assoc_info.resp_ies,
2432 data->assoc_info.resp_ies_len,
2433 &resp_elems, 0) != ParseFailed) {
2434 wpa_s->connection_set = 1;
2435 wpa_s->connection_ht = req_elems.ht_capabilities &&
2436 resp_elems.ht_capabilities;
2437 wpa_s->connection_vht = req_elems.vht_capabilities &&
2438 resp_elems.vht_capabilities;
2439 wpa_s->connection_he = req_elems.he_capabilities &&
2440 resp_elems.he_capabilities;
2444 p = data->assoc_info.req_ies;
2445 l = data->assoc_info.req_ies_len;
2447 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2448 while (p && l >= 2) {
2451 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2455 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2456 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2457 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2458 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2459 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2460 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2463 wpa_find_assoc_pmkid(wpa_s);
2469 if (!found && data->assoc_info.req_ies)
2470 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2474 if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
2475 wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) &&
2476 (!data->assoc_info.resp_frame ||
2477 fils_process_assoc_resp(wpa_s->wpa,
2478 data->assoc_info.resp_frame,
2479 data->assoc_info.resp_frame_len) < 0)) {
2480 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2483 #endif /* CONFIG_SME */
2485 /* Additional processing for FILS when SME is in driver */
2486 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
2487 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2488 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
2489 #endif /* CONFIG_FILS */
2492 if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
2493 (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2494 owe_process_assoc_resp(wpa_s->wpa, bssid,
2495 data->assoc_info.resp_ies,
2496 data->assoc_info.resp_ies_len) < 0)) {
2497 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
2500 #endif /* CONFIG_OWE */
2503 wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
2504 if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) {
2505 struct ieee802_11_elems elems;
2507 if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
2508 data->assoc_info.resp_ies_len,
2509 &elems, 0) == ParseFailed ||
2512 if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
2513 elems.owe_dh_len) < 0) {
2514 wpa_supplicant_deauthenticate(wpa_s,
2515 WLAN_REASON_UNSPECIFIED);
2519 wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
2522 #endif /* CONFIG_DPP2 */
2524 #ifdef CONFIG_IEEE80211R
2526 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
2527 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2528 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2529 data->assoc_info.resp_ies,
2530 data->assoc_info.resp_ies_len,
2532 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2533 "Reassociation Response failed");
2534 wpa_supplicant_deauthenticate(
2535 wpa_s, WLAN_REASON_INVALID_IE);
2540 p = data->assoc_info.resp_ies;
2541 l = data->assoc_info.resp_ies_len;
2543 #ifdef CONFIG_WPS_STRICT
2544 if (p && wpa_s->current_ssid &&
2545 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2547 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2549 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2550 "include WPS IE in (Re)Association Response");
2554 if (wps_validate_assoc_resp(wps) < 0) {
2556 wpa_supplicant_deauthenticate(
2557 wpa_s, WLAN_REASON_INVALID_IE);
2562 #endif /* CONFIG_WPS_STRICT */
2564 /* Go through the IEs and make a copy of the MDIE, if present. */
2565 while (p && l >= 2) {
2568 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2572 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2573 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2574 wpa_s->sme.ft_used = 1;
2575 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2576 MOBILITY_DOMAIN_ID_LEN);
2582 #endif /* CONFIG_SME */
2584 /* Process FT when SME is in the driver */
2585 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2586 wpa_ft_is_completed(wpa_s->wpa)) {
2587 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2588 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2589 data->assoc_info.resp_ies,
2590 data->assoc_info.resp_ies_len,
2592 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2593 "Reassociation Response failed");
2594 wpa_supplicant_deauthenticate(
2595 wpa_s, WLAN_REASON_INVALID_IE);
2598 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2601 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2602 data->assoc_info.resp_ies_len);
2603 #endif /* CONFIG_IEEE80211R */
2605 /* WPA/RSN IE from Beacon/ProbeResp */
2606 p = data->assoc_info.beacon_ies;
2607 l = data->assoc_info.beacon_ies_len;
2609 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2611 wpa_found = rsn_found = 0;
2612 while (p && l >= 2) {
2615 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2620 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2621 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2623 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2627 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2629 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2636 if (!wpa_found && data->assoc_info.beacon_ies)
2637 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2638 if (!rsn_found && data->assoc_info.beacon_ies)
2639 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2640 if (wpa_found || rsn_found)
2641 wpa_s->ap_ies_from_associnfo = 1;
2643 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2644 wpa_s->assoc_freq != data->assoc_info.freq) {
2645 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2647 wpa_s->assoc_freq, data->assoc_info.freq);
2648 wpa_supplicant_update_scan_results(wpa_s);
2651 wpa_s->assoc_freq = data->assoc_info.freq;
2657 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2659 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2661 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2664 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2667 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2668 WPA_IE_VENDOR_TYPE);
2669 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2671 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2672 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2673 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2674 bss_rsn ? 2 + bss_rsn[1] : 0))
2681 static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2682 union wpa_event_data *data)
2685 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2686 struct wpa_bss *bss = wpa_s->current_bss;
2687 const u8 *ieprb, *iebcn;
2689 wpabuf_free(wpa_s->received_mb_ies);
2690 wpa_s->received_mb_ies = NULL;
2693 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2694 wpa_printf(MSG_DEBUG,
2695 "FST: MB IEs updated from Association Response frame");
2700 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2701 wpa_printf(MSG_DEBUG,
2702 "FST: MB IEs updated from association event Beacon IEs");
2709 ieprb = (const u8 *) (bss + 1);
2710 iebcn = ieprb + bss->ie_len;
2712 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2713 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2714 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2715 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2716 #endif /* CONFIG_FST */
2720 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2721 union wpa_event_data *data)
2724 int ft_completed, already_authorized;
2728 if (wpa_s->ap_iface) {
2731 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2732 data->assoc_info.addr,
2733 data->assoc_info.req_ies,
2734 data->assoc_info.req_ies_len,
2735 data->assoc_info.reassoc);
2738 #endif /* CONFIG_AP */
2740 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2742 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2743 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2746 * FILS authentication can share the same mechanism to mark the
2747 * connection fully authenticated, so set ft_completed also based on
2751 ft_completed = wpa_fils_is_completed(wpa_s->wpa);
2753 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2754 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2755 wpa_supplicant_deauthenticate(
2756 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2760 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2761 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2762 if (os_reltime_initialized(&wpa_s->session_start)) {
2763 os_reltime_age(&wpa_s->session_start,
2764 &wpa_s->session_length);
2765 wpa_s->session_start.sec = 0;
2766 wpa_s->session_start.usec = 0;
2767 wpas_notify_session_length(wpa_s);
2769 wpas_notify_auth_changed(wpa_s);
2770 os_get_reltime(&wpa_s->session_start);
2772 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2773 MACSTR, MAC2STR(bssid));
2775 random_add_randomness(bssid, ETH_ALEN);
2776 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2777 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2778 wpas_notify_bssid_changed(wpa_s);
2780 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2781 wpa_clear_keys(wpa_s, bssid);
2783 if (wpa_supplicant_select_config(wpa_s) < 0) {
2784 wpa_supplicant_deauthenticate(
2785 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2790 if (wpa_s->conf->ap_scan == 1 &&
2791 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2792 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2793 wpa_msg(wpa_s, MSG_WARNING,
2794 "WPA/RSN IEs not updated");
2797 wpas_fst_update_mb_assoc(wpa_s, data);
2800 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2801 wpa_s->sme.prev_bssid_set = 1;
2802 wpa_s->sme.last_unprot_disconnect.sec = 0;
2803 #endif /* CONFIG_SME */
2805 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2806 if (wpa_s->current_ssid) {
2807 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2808 * initialized before association, but for other modes,
2809 * initialize PC/SC here, if the current configuration needs
2810 * smartcard or SIM/USIM. */
2811 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2813 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2815 l2_packet_notify_auth_start(wpa_s->l2);
2817 already_authorized = data && data->assoc_info.authorized;
2820 * Set portEnabled first to FALSE in order to get EAP state machine out
2821 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2822 * state machine may transit to AUTHENTICATING state based on obsolete
2823 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2824 * AUTHENTICATED without ever giving chance to EAP state machine to
2827 if (!ft_completed && !already_authorized) {
2828 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2829 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2831 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2832 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
2833 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
2835 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2836 /* 802.1X::portControl = Auto */
2837 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2838 wpa_s->eapol_received = 0;
2839 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2840 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2841 (wpa_s->current_ssid &&
2842 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2843 if (wpa_s->current_ssid &&
2844 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2846 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2848 * Set the key after having received joined-IBSS event
2851 wpa_supplicant_set_wpa_none_key(wpa_s,
2852 wpa_s->current_ssid);
2854 wpa_supplicant_cancel_auth_timeout(wpa_s);
2855 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2856 } else if (!ft_completed) {
2857 /* Timeout for receiving the first EAPOL packet */
2858 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2860 wpa_supplicant_cancel_scan(wpa_s);
2864 * FT protocol completed - make sure EAPOL state machine ends
2865 * up in authenticated.
2867 wpa_supplicant_cancel_auth_timeout(wpa_s);
2868 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2869 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2870 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2871 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
2872 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2874 * We are done; the driver will take care of RSN 4-way
2877 wpa_supplicant_cancel_auth_timeout(wpa_s);
2878 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2879 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2880 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2881 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
2882 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2884 * The driver will take care of RSN 4-way handshake, so we need
2885 * to allow EAPOL supplicant to complete its work without
2886 * waiting for WPA supplicant.
2888 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2891 wpa_s->last_eapol_matches_bssid = 0;
2893 if (wpa_s->pending_eapol_rx) {
2894 struct os_reltime now, age;
2895 os_get_reltime(&now);
2896 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2897 if (age.sec == 0 && age.usec < 200000 &&
2898 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2900 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2901 "frame that was received just before "
2902 "association notification");
2903 wpa_supplicant_rx_eapol(
2904 wpa_s, wpa_s->pending_eapol_rx_src,
2905 wpabuf_head(wpa_s->pending_eapol_rx),
2906 wpabuf_len(wpa_s->pending_eapol_rx));
2908 wpabuf_free(wpa_s->pending_eapol_rx);
2909 wpa_s->pending_eapol_rx = NULL;
2912 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2913 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2914 wpa_s->current_ssid &&
2915 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2916 /* Set static WEP keys again */
2917 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2920 #ifdef CONFIG_IBSS_RSN
2921 if (wpa_s->current_ssid &&
2922 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2923 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2924 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2925 wpa_s->ibss_rsn == NULL) {
2926 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
2927 if (!wpa_s->ibss_rsn) {
2928 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2929 wpa_supplicant_deauthenticate(
2930 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2934 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2936 #endif /* CONFIG_IBSS_RSN */
2938 wpas_wps_notify_assoc(wpa_s, bssid);
2941 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2942 data->assoc_info.resp_ies_len,
2943 &data->assoc_info.wmm_params);
2945 if (wpa_s->reassoc_same_bss)
2946 wmm_ac_restore_tspecs(wpa_s);
2950 if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
2951 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
2952 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
2955 wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
2957 #endif /* CONFIG_FILS */
2961 static int disconnect_reason_recoverable(u16 reason_code)
2963 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2964 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2965 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2969 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2971 int locally_generated)
2975 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2977 * At least Host AP driver and a Prism3 card seemed to be
2978 * generating streams of disconnected events when configuring
2979 * IBSS for WPA-None. Ignore them for now.
2984 bssid = wpa_s->bssid;
2985 if (is_zero_ether_addr(bssid))
2986 bssid = wpa_s->pending_bssid;
2988 if (!is_zero_ether_addr(bssid) ||
2989 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2990 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2992 MAC2STR(bssid), reason_code,
2993 locally_generated ? " locally_generated=1" : "");
2998 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2999 int locally_generated)
3001 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
3002 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
3003 return 0; /* Not in 4-way handshake with PSK */
3006 * It looks like connection was lost while trying to go through PSK
3007 * 4-way handshake. Filter out known disconnection cases that are caused
3008 * by something else than PSK mismatch to avoid confusing reports.
3011 if (locally_generated) {
3012 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
3020 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
3022 int locally_generated)
3026 u8 prev_pending_bssid[ETH_ALEN];
3027 struct wpa_bss *fast_reconnect = NULL;
3028 struct wpa_ssid *fast_reconnect_ssid = NULL;
3029 struct wpa_ssid *last_ssid;
3030 struct wpa_bss *curr = NULL;
3032 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
3033 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
3035 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3037 * At least Host AP driver and a Prism3 card seemed to be
3038 * generating streams of disconnected events when configuring
3039 * IBSS for WPA-None. Ignore them for now.
3041 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
3042 "IBSS/WPA-None mode");
3046 if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
3047 reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
3050 * Remove the inactive AP (which is probably out of range) from
3051 * the BSS list after marking disassociation. In particular
3052 * mac80211-based drivers use the
3053 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3054 * locally generated disconnection events for cases where the
3055 * AP does not reply anymore.
3057 curr = wpa_s->current_bss;
3059 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
3060 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
3061 "pre-shared key may be incorrect");
3062 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
3063 return; /* P2P group removed */
3064 wpas_auth_failed(wpa_s, "WRONG_KEY");
3066 if (!wpa_s->disconnected &&
3067 (!wpa_s->auto_reconnect_disabled ||
3068 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
3069 wpas_wps_searching(wpa_s) ||
3070 wpas_wps_reenable_networks_pending(wpa_s))) {
3071 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
3072 "reconnect (wps=%d/%d wpa_state=%d)",
3073 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
3074 wpas_wps_searching(wpa_s),
3076 if (wpa_s->wpa_state == WPA_COMPLETED &&
3077 wpa_s->current_ssid &&
3078 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
3079 !locally_generated &&
3080 disconnect_reason_recoverable(reason_code)) {
3082 * It looks like the AP has dropped association with
3083 * us, but could allow us to get back in. Try to
3084 * reconnect to the same BSS without full scan to save
3085 * time for some common cases.
3087 fast_reconnect = wpa_s->current_bss;
3088 fast_reconnect_ssid = wpa_s->current_ssid;
3089 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
3090 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3092 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
3095 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
3096 "try to re-connect");
3097 wpa_s->reassociate = 0;
3098 wpa_s->disconnected = 1;
3100 wpa_supplicant_cancel_sched_scan(wpa_s);
3102 bssid = wpa_s->bssid;
3103 if (is_zero_ether_addr(bssid))
3104 bssid = wpa_s->pending_bssid;
3105 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3106 wpas_connection_failed(wpa_s, bssid);
3107 wpa_sm_notify_disassoc(wpa_s->wpa);
3108 if (locally_generated)
3109 wpa_s->disconnect_reason = -reason_code;
3111 wpa_s->disconnect_reason = reason_code;
3112 wpas_notify_disconnect_reason(wpa_s);
3113 if (wpa_supplicant_dynamic_keys(wpa_s)) {
3114 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
3115 wpa_clear_keys(wpa_s, wpa_s->bssid);
3117 last_ssid = wpa_s->current_ssid;
3118 wpa_supplicant_mark_disassoc(wpa_s);
3121 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
3123 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
3124 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
3125 wpa_s->current_ssid = last_ssid;
3128 if (fast_reconnect &&
3129 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
3130 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
3131 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
3132 fast_reconnect->ssid_len) &&
3133 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
3134 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
3135 #ifndef CONFIG_NO_SCAN_PROCESSING
3136 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
3137 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
3138 fast_reconnect_ssid) < 0) {
3139 /* Recover through full scan */
3140 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3142 #endif /* CONFIG_NO_SCAN_PROCESSING */
3143 } else if (fast_reconnect) {
3145 * Could not reconnect to the same BSS due to network being
3146 * disabled. Use a new scan to match the alternative behavior
3147 * above, i.e., to continue automatic reconnection attempt in a
3148 * way that enforces disabled network rules.
3150 wpa_supplicant_req_scan(wpa_s, 0, 100000);
3155 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3156 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
3158 struct wpa_supplicant *wpa_s = eloop_ctx;
3160 if (!wpa_s->pending_mic_error_report)
3163 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
3164 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
3165 wpa_s->pending_mic_error_report = 0;
3167 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3171 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
3172 union wpa_event_data *data)
3175 struct os_reltime t;
3177 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
3178 pairwise = (data && data->michael_mic_failure.unicast);
3180 if ((wpa_s->last_michael_mic_error.sec &&
3181 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
3182 wpa_s->pending_mic_error_report) {
3183 if (wpa_s->pending_mic_error_report) {
3185 * Send the pending MIC error report immediately since
3186 * we are going to start countermeasures and AP better
3189 wpa_sm_key_request(wpa_s->wpa, 1,
3190 wpa_s->pending_mic_error_pairwise);
3193 /* Send the new MIC error report immediately since we are going
3194 * to start countermeasures and AP better do the same.
3196 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3198 /* initialize countermeasures */
3199 wpa_s->countermeasures = 1;
3201 wpa_blacklist_add(wpa_s, wpa_s->bssid);
3203 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
3206 * Need to wait for completion of request frame. We do not get
3207 * any callback for the message completion, so just wait a
3208 * short while and hope for the best. */
3211 wpa_drv_set_countermeasures(wpa_s, 1);
3212 wpa_supplicant_deauthenticate(wpa_s,
3213 WLAN_REASON_MICHAEL_MIC_FAILURE);
3214 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
3216 eloop_register_timeout(60, 0,
3217 wpa_supplicant_stop_countermeasures,
3219 /* TODO: mark the AP rejected for 60 second. STA is
3220 * allowed to associate with another AP.. */
3222 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3223 if (wpa_s->mic_errors_seen) {
3225 * Reduce the effectiveness of Michael MIC error
3226 * reports as a means for attacking against TKIP if
3227 * more than one MIC failure is noticed with the same
3228 * PTK. We delay the transmission of the reports by a
3229 * random time between 0 and 60 seconds in order to
3230 * force the attacker wait 60 seconds before getting
3231 * the information on whether a frame resulted in a MIC
3237 if (os_get_random(rval, sizeof(rval)) < 0)
3238 sec = os_random() % 60;
3240 sec = WPA_GET_BE32(rval) % 60;
3241 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
3242 "report %d seconds", sec);
3243 wpa_s->pending_mic_error_report = 1;
3244 wpa_s->pending_mic_error_pairwise = pairwise;
3245 eloop_cancel_timeout(
3246 wpa_supplicant_delayed_mic_error_report,
3248 eloop_register_timeout(
3249 sec, os_random() % 1000000,
3250 wpa_supplicant_delayed_mic_error_report,
3253 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3255 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3256 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
3257 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3259 wpa_s->last_michael_mic_error = t;
3260 wpa_s->mic_errors_seen++;
3264 #ifdef CONFIG_TERMINATE_ONLASTIF
3265 static int any_interfaces(struct wpa_supplicant *head)
3267 struct wpa_supplicant *wpa_s;
3269 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
3270 if (!wpa_s->interface_removed)
3274 #endif /* CONFIG_TERMINATE_ONLASTIF */
3278 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
3279 union wpa_event_data *data)
3281 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
3284 switch (data->interface_status.ievent) {
3285 case EVENT_INTERFACE_ADDED:
3286 if (!wpa_s->interface_removed)
3288 wpa_s->interface_removed = 0;
3289 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
3290 if (wpa_supplicant_driver_init(wpa_s) < 0) {
3291 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
3292 "driver after interface was added");
3296 if (!wpa_s->global->p2p &&
3297 !wpa_s->global->p2p_disabled &&
3298 !wpa_s->conf->p2p_disabled &&
3300 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
3301 wpas_p2p_add_p2pdev_interface(
3302 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
3303 wpa_printf(MSG_INFO,
3304 "P2P: Failed to enable P2P Device interface");
3305 /* Try to continue without. P2P will be disabled. */
3307 #endif /* CONFIG_P2P */
3310 case EVENT_INTERFACE_REMOVED:
3311 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
3312 wpa_s->interface_removed = 1;
3313 wpa_supplicant_mark_disassoc(wpa_s);
3314 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3315 l2_packet_deinit(wpa_s->l2);
3319 if (wpa_s->global->p2p &&
3320 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
3322 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
3323 wpa_dbg(wpa_s, MSG_DEBUG,
3324 "Removing P2P Device interface");
3325 wpa_supplicant_remove_iface(
3326 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
3328 wpa_s->global->p2p_init_wpa_s = NULL;
3330 #endif /* CONFIG_P2P */
3332 #ifdef CONFIG_MATCH_IFACE
3333 if (wpa_s->matched) {
3334 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
3337 #endif /* CONFIG_MATCH_IFACE */
3339 #ifdef CONFIG_TERMINATE_ONLASTIF
3340 /* check if last interface */
3341 if (!any_interfaces(wpa_s->global->ifaces))
3343 #endif /* CONFIG_TERMINATE_ONLASTIF */
3350 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
3351 union wpa_event_data *data)
3355 switch (data->tdls.oper) {
3356 case TDLS_REQUEST_SETUP:
3357 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
3358 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3359 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
3361 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
3363 case TDLS_REQUEST_TEARDOWN:
3364 if (wpa_tdls_is_external_setup(wpa_s->wpa))
3365 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
3366 data->tdls.reason_code);
3368 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
3371 case TDLS_REQUEST_DISCOVER:
3372 wpa_tdls_send_discovery_request(wpa_s->wpa,
3377 #endif /* CONFIG_TDLS */
3381 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
3382 union wpa_event_data *data)
3386 switch (data->wnm.oper) {
3387 case WNM_OPER_SLEEP:
3388 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
3389 "(action=%d, intval=%d)",
3390 data->wnm.sleep_action, data->wnm.sleep_intval);
3391 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
3392 data->wnm.sleep_intval, NULL);
3396 #endif /* CONFIG_WNM */
3399 #ifdef CONFIG_IEEE80211R
3401 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
3402 union wpa_event_data *data)
3407 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
3408 data->ft_ies.ies_len,
3409 data->ft_ies.ft_action,
3410 data->ft_ies.target_ap,
3411 data->ft_ies.ric_ies,
3412 data->ft_ies.ric_ies_len) < 0) {
3413 /* TODO: prevent MLME/driver from trying to associate? */
3416 #endif /* CONFIG_IEEE80211R */
3419 #ifdef CONFIG_IBSS_RSN
3420 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
3421 union wpa_event_data *data)
3423 struct wpa_ssid *ssid;
3424 if (wpa_s->wpa_state < WPA_ASSOCIATED)
3428 ssid = wpa_s->current_ssid;
3431 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3434 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
3438 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
3439 union wpa_event_data *data)
3441 struct wpa_ssid *ssid = wpa_s->current_ssid;
3446 /* check if the ssid is correctly configured as IBSS/RSN */
3447 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
3450 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
3451 data->rx_mgmt.frame_len);
3453 #endif /* CONFIG_IBSS_RSN */
3456 #ifdef CONFIG_IEEE80211R
3457 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
3460 const u8 *sta_addr, *target_ap_addr;
3463 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
3464 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3465 return; /* only SME case supported for now */
3466 if (len < 1 + 2 * ETH_ALEN + 2)
3469 return; /* Only FT Action Response is supported for now */
3470 sta_addr = data + 1;
3471 target_ap_addr = data + 1 + ETH_ALEN;
3472 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
3473 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
3474 MACSTR " TargetAP " MACSTR " status %u",
3475 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
3477 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
3478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
3479 " in FT Action Response", MAC2STR(sta_addr));
3484 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
3485 "failure (status code %d)", status);
3486 /* TODO: report error to FT code(?) */
3490 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
3491 len - (1 + 2 * ETH_ALEN + 2), 1,
3492 target_ap_addr, NULL, 0) < 0)
3497 struct wpa_bss *bss;
3498 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
3500 wpa_s->sme.freq = bss->freq;
3501 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
3502 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
3505 #endif /* CONFIG_SME */
3507 #endif /* CONFIG_IEEE80211R */
3510 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
3511 struct unprot_deauth *e)
3513 #ifdef CONFIG_IEEE80211W
3514 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
3515 "dropped: " MACSTR " -> " MACSTR
3516 " (reason code %u)",
3517 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3518 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3519 #endif /* CONFIG_IEEE80211W */
3523 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
3524 struct unprot_disassoc *e)
3526 #ifdef CONFIG_IEEE80211W
3527 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
3528 "dropped: " MACSTR " -> " MACSTR
3529 " (reason code %u)",
3530 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
3531 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
3532 #endif /* CONFIG_IEEE80211W */
3536 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
3537 u16 reason_code, int locally_generated,
3538 const u8 *ie, size_t ie_len, int deauth)
3541 if (wpa_s->ap_iface && addr) {
3542 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3546 if (wpa_s->ap_iface) {
3547 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3550 #endif /* CONFIG_AP */
3552 if (!locally_generated)
3553 wpa_s->own_disconnect_req = 0;
3555 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3557 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3558 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3559 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3560 eapol_sm_failed(wpa_s->eapol))) &&
3561 !wpa_s->eap_expected_failure))
3562 wpas_auth_failed(wpa_s, "AUTH_FAILED");
3565 if (deauth && reason_code > 0) {
3566 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3567 locally_generated) > 0) {
3569 * The interface was removed, so cannot continue
3570 * processing any additional operations after this.
3575 #endif /* CONFIG_P2P */
3577 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3582 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3583 struct disassoc_info *info)
3585 u16 reason_code = 0;
3586 int locally_generated = 0;
3587 const u8 *addr = NULL;
3588 const u8 *ie = NULL;
3591 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3596 ie_len = info->ie_len;
3597 reason_code = info->reason_code;
3598 locally_generated = info->locally_generated;
3599 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3600 locally_generated ? " (locally generated)" : "");
3602 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3604 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3609 if (wpa_s->ap_iface && info && info->addr) {
3610 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3614 if (wpa_s->ap_iface) {
3615 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3618 #endif /* CONFIG_AP */
3622 wpas_p2p_disassoc_notif(
3623 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3626 #endif /* CONFIG_P2P */
3628 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3629 sme_event_disassoc(wpa_s, info);
3631 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3636 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3637 struct deauth_info *info)
3639 u16 reason_code = 0;
3640 int locally_generated = 0;
3641 const u8 *addr = NULL;
3642 const u8 *ie = NULL;
3645 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3650 ie_len = info->ie_len;
3651 reason_code = info->reason_code;
3652 locally_generated = info->locally_generated;
3653 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3655 locally_generated ? " (locally generated)" : "");
3657 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3660 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3664 wpa_reset_ft_completed(wpa_s->wpa);
3666 wpas_event_disconnect(wpa_s, addr, reason_code,
3667 locally_generated, ie, ie_len, 1);
3671 static const char * reg_init_str(enum reg_change_initiator init)
3674 case REGDOM_SET_BY_CORE:
3676 case REGDOM_SET_BY_USER:
3678 case REGDOM_SET_BY_DRIVER:
3680 case REGDOM_SET_BY_COUNTRY_IE:
3681 return "COUNTRY_IE";
3682 case REGDOM_BEACON_HINT:
3683 return "BEACON_HINT";
3689 static const char * reg_type_str(enum reg_type type)
3692 case REGDOM_TYPE_UNKNOWN:
3694 case REGDOM_TYPE_COUNTRY:
3696 case REGDOM_TYPE_WORLD:
3698 case REGDOM_TYPE_CUSTOM_WORLD:
3699 return "CUSTOM_WORLD";
3700 case REGDOM_TYPE_INTERSECTION:
3701 return "INTERSECTION";
3707 void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
3708 struct channel_list_changed *info)
3710 struct wpa_supplicant *ifs;
3714 * To allow backwards compatibility with higher level layers that
3715 * assumed the REGDOM_CHANGE event is sent over the initially added
3716 * interface. Find the highest parent of this interface and use it to
3719 for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
3723 wpa_msg(ifs, MSG_INFO,
3724 WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3725 reg_init_str(info->initiator), reg_type_str(info->type),
3726 info->alpha2[0] ? " alpha2=" : "",
3727 info->alpha2[0] ? info->alpha2 : "");
3730 if (wpa_s->drv_priv == NULL)
3731 return; /* Ignore event during drv initialization */
3733 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3735 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3737 free_hw_features(ifs);
3738 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3739 ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
3741 /* Restart PNO/sched_scan with updated channel list */
3744 wpas_start_pno(ifs);
3745 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
3746 wpa_dbg(ifs, MSG_DEBUG,
3747 "Channel list changed - restart sched_scan");
3748 wpas_scan_restart_sched_scan(ifs);
3752 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3756 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3757 const u8 *frame, size_t len, int freq,
3760 const struct ieee80211_mgmt *mgmt;
3765 if (len < IEEE80211_HDRLEN + 2)
3768 mgmt = (const struct ieee80211_mgmt *) frame;
3769 payload = frame + IEEE80211_HDRLEN;
3770 category = *payload++;
3771 plen = len - IEEE80211_HDRLEN - 1;
3773 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3774 " Category=%u DataLen=%d freq=%d MHz",
3775 MAC2STR(mgmt->sa), category, (int) plen, freq);
3777 if (category == WLAN_ACTION_WMM) {
3778 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3782 #ifdef CONFIG_IEEE80211R
3783 if (category == WLAN_ACTION_FT) {
3784 ft_rx_action(wpa_s, payload, plen);
3787 #endif /* CONFIG_IEEE80211R */
3789 #ifdef CONFIG_IEEE80211W
3791 if (category == WLAN_ACTION_SA_QUERY) {
3792 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3795 #endif /* CONFIG_SME */
3796 #endif /* CONFIG_IEEE80211W */
3799 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3800 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3803 #endif /* CONFIG_WNM */
3806 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3807 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3808 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3809 mgmt->u.action.category,
3810 payload, plen, freq) == 0)
3812 #endif /* CONFIG_GAS */
3814 #ifdef CONFIG_GAS_SERVER
3815 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3816 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3817 gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
3818 mgmt->u.action.category,
3819 payload, plen, freq) == 0)
3821 #endif /* CONFIG_GAS_SERVER */
3824 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3825 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3826 wpa_dbg(wpa_s, MSG_DEBUG,
3827 "TDLS: Received Discovery Response from " MACSTR,
3831 #endif /* CONFIG_TDLS */
3833 #ifdef CONFIG_INTERWORKING
3834 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3835 payload[0] == QOS_QOS_MAP_CONFIG) {
3836 const u8 *pos = payload + 1;
3837 size_t qlen = plen - 1;
3838 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3839 MACSTR, MAC2STR(mgmt->sa));
3840 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3841 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3842 pos[1] <= qlen - 2 && pos[1] >= 16)
3843 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3846 #endif /* CONFIG_INTERWORKING */
3848 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3849 payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
3850 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
3857 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3858 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3859 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3863 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3864 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3865 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3866 payload + 1, plen - 1,
3872 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3873 fst_rx_action(wpa_s->fst, mgmt, len);
3876 #endif /* CONFIG_FST */
3879 if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
3880 payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
3881 WPA_GET_BE24(&payload[1]) == OUI_WFA &&
3882 payload[4] == DPP_OUI_TYPE) {
3885 wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
3888 #endif /* CONFIG_DPP */
3890 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3891 category, payload, plen, freq);
3893 mesh_mpm_action_rx(wpa_s, mgmt, len);
3897 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3898 union wpa_event_data *event)
3900 struct wpa_freq_range_list *list;
3903 list = &event->freq_range;
3906 str = freq_range_list_str(list);
3907 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3911 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3912 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3915 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3918 * The update channel flow will also take care of moving a GO
3919 * from the unsafe frequency if needed.
3921 wpas_p2p_update_channel_list(wpa_s,
3922 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3924 #endif /* CONFIG_P2P */
3930 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
3932 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3933 wpa_supplicant_cancel_auth_timeout(wpa_s);
3934 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3935 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3936 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3941 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
3947 for (i = 0; i < wpa_s->hw.num_modes; i++) {
3948 const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
3950 for (j = 0; j < mode->num_channels; j++) {
3951 const struct hostapd_channel_data *chan;
3953 chan = &mode->channels[j];
3954 if (chan->freq == freq)
3955 return chan->dfs_cac_ms;
3963 static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
3964 struct dfs_event *radar)
3966 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3967 if (wpa_s->ap_iface || wpa_s->ifmsh) {
3968 wpas_ap_event_dfs_cac_started(wpa_s, radar);
3970 #endif /* NEED_AP_MLME && CONFIG_AP */
3972 unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
3974 cac_time /= 1000; /* convert from ms to sec */
3976 cac_time = 10 * 60; /* max timeout: 10 minutes */
3978 /* Restart auth timeout: CAC time added to initial timeout */
3979 wpas_auth_timeout_restart(wpa_s, cac_time);
3984 static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
3985 struct dfs_event *radar)
3987 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3988 if (wpa_s->ap_iface || wpa_s->ifmsh) {
3989 wpas_ap_event_dfs_cac_finished(wpa_s, radar);
3991 #endif /* NEED_AP_MLME && CONFIG_AP */
3993 /* Restart auth timeout with original value after CAC is
3995 wpas_auth_timeout_restart(wpa_s, 0);
4000 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
4001 struct dfs_event *radar)
4003 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4004 if (wpa_s->ap_iface || wpa_s->ifmsh) {
4005 wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
4007 #endif /* NEED_AP_MLME && CONFIG_AP */
4009 /* Restart auth timeout with original value after CAC is
4011 wpas_auth_timeout_restart(wpa_s, 0);
4016 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
4017 union wpa_event_data *data)
4019 wpa_dbg(wpa_s, MSG_DEBUG,
4020 "Connection authorized by device, previous state %d",
4023 wpa_supplicant_event_port_authorized(wpa_s);
4025 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
4026 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
4027 data->assoc_info.ptk_kck_len,
4028 data->assoc_info.ptk_kek,
4029 data->assoc_info.ptk_kek_len);
4031 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4032 struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
4033 const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4035 /* Update ERP next sequence number */
4036 eapol_sm_update_erp_next_seq_num(
4037 wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
4039 if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
4040 /* Add the new PMK and PMKID to the PMKSA cache */
4041 wpa_sm_pmksa_cache_add(wpa_s->wpa,
4042 data->assoc_info.fils_pmk,
4043 data->assoc_info.fils_pmk_len,
4044 data->assoc_info.fils_pmkid,
4045 wpa_s->bssid, fils_cache_id);
4046 } else if (data->assoc_info.fils_pmkid) {
4047 /* Update the current PMKSA used for this connection */
4048 pmksa_cache_set_current(wpa_s->wpa,
4049 data->assoc_info.fils_pmkid,
4050 NULL, NULL, 0, NULL, 0);
4053 #endif /* CONFIG_FILS */
4057 static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
4058 union wpa_event_data *data)
4060 const u8 *bssid = data->assoc_reject.bssid;
4062 if (!bssid || is_zero_ether_addr(bssid))
4063 bssid = wpa_s->pending_bssid;
4065 if (data->assoc_reject.bssid)
4066 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4067 "bssid=" MACSTR " status_code=%u%s%s%s",
4068 MAC2STR(data->assoc_reject.bssid),
4069 data->assoc_reject.status_code,
4070 data->assoc_reject.timed_out ? " timeout" : "",
4071 data->assoc_reject.timeout_reason ? "=" : "",
4072 data->assoc_reject.timeout_reason ?
4073 data->assoc_reject.timeout_reason : "");
4075 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
4076 "status_code=%u%s%s%s",
4077 data->assoc_reject.status_code,
4078 data->assoc_reject.timed_out ? " timeout" : "",
4079 data->assoc_reject.timeout_reason ? "=" : "",
4080 data->assoc_reject.timeout_reason ?
4081 data->assoc_reject.timeout_reason : "");
4082 wpa_s->assoc_status_code = data->assoc_reject.status_code;
4083 wpas_notify_assoc_status_code(wpa_s);
4086 if (data->assoc_reject.status_code ==
4087 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
4088 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
4089 wpa_s->current_ssid &&
4090 wpa_s->current_ssid->owe_group == 0 &&
4091 wpa_s->last_owe_group != 21) {
4092 struct wpa_ssid *ssid = wpa_s->current_ssid;
4093 struct wpa_bss *bss = wpa_s->current_bss;
4096 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
4098 wpas_connection_failed(wpa_s, bssid);
4099 wpa_supplicant_mark_disassoc(wpa_s);
4103 wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
4104 wpas_connect_work_done(wpa_s);
4105 wpa_supplicant_mark_disassoc(wpa_s);
4106 wpa_supplicant_connect(wpa_s, bss, ssid);
4109 #endif /* CONFIG_OWE */
4112 if (data->assoc_reject.status_code ==
4113 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
4114 wpa_s->current_bss && data->assoc_reject.bssid &&
4115 data->assoc_reject.resp_ies) {
4118 rssi_rej = mbo_get_attr_from_ies(
4119 data->assoc_reject.resp_ies,
4120 data->assoc_reject.resp_ies_len,
4121 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
4122 if (rssi_rej && rssi_rej[1] == 2) {
4123 wpa_printf(MSG_DEBUG,
4124 "OCE: RSSI-based association rejection from "
4125 MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
4126 MAC2STR(data->assoc_reject.bssid),
4127 rssi_rej[2], rssi_rej[3]);
4128 wpa_bss_tmp_disallow(wpa_s,
4129 data->assoc_reject.bssid,
4132 wpa_s->current_bss->level);
4135 #endif /* CONFIG_MBO */
4137 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
4138 sme_event_assoc_reject(wpa_s, data);
4142 /* Driver-based SME cases */
4145 if (wpa_s->current_ssid &&
4146 wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
4147 !data->assoc_reject.timed_out) {
4148 wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
4149 wpa_sm_aborted_cached(wpa_s->wpa);
4150 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4152 #endif /* CONFIG_SAE */
4155 if (wpa_s->current_ssid &&
4156 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
4157 !data->assoc_reject.timed_out) {
4158 wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
4159 wpa_sm_aborted_cached(wpa_s->wpa);
4160 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
4162 #endif /* CONFIG_DPP */
4165 /* Update ERP next sequence number */
4166 if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
4167 eapol_sm_update_erp_next_seq_num(
4169 data->assoc_reject.fils_erp_next_seq_num);
4170 fils_connection_failure(wpa_s);
4172 #endif /* CONFIG_FILS */
4174 wpas_connection_failed(wpa_s, bssid);
4175 wpa_supplicant_mark_disassoc(wpa_s);
4179 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
4180 union wpa_event_data *data)
4182 struct wpa_supplicant *wpa_s = ctx;
4184 #ifndef CONFIG_NO_STDOUT_DEBUG
4185 int level = MSG_DEBUG;
4186 #endif /* CONFIG_NO_STDOUT_DEBUG */
4188 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
4189 event != EVENT_INTERFACE_ENABLED &&
4190 event != EVENT_INTERFACE_STATUS &&
4191 event != EVENT_SCAN_RESULTS &&
4192 event != EVENT_SCHED_SCAN_STOPPED) {
4193 wpa_dbg(wpa_s, MSG_DEBUG,
4194 "Ignore event %s (%d) while interface is disabled",
4195 event_to_string(event), event);
4199 #ifndef CONFIG_NO_STDOUT_DEBUG
4200 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
4201 const struct ieee80211_hdr *hdr;
4203 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
4204 fc = le_to_host16(hdr->frame_control);
4205 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
4206 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
4207 level = MSG_EXCESSIVE;
4210 wpa_dbg(wpa_s, level, "Event %s (%d) received",
4211 event_to_string(event), event);
4212 #endif /* CONFIG_NO_STDOUT_DEBUG */
4217 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
4218 data->auth.ies_len))
4219 wpa_printf(MSG_DEBUG,
4220 "FST: MB IEs updated from auth IE");
4221 #endif /* CONFIG_FST */
4222 sme_event_auth(wpa_s, data);
4223 wpa_s->auth_status_code = data->auth.status_code;
4224 wpas_notify_auth_status_code(wpa_s);
4227 #ifdef CONFIG_TESTING_OPTIONS
4228 if (wpa_s->ignore_auth_resp) {
4229 wpa_printf(MSG_INFO,
4230 "EVENT_ASSOC - ignore_auth_resp active!");
4233 if (wpa_s->testing_resend_assoc) {
4234 wpa_printf(MSG_INFO,
4235 "EVENT_DEAUTH - testing_resend_assoc");
4238 #endif /* CONFIG_TESTING_OPTIONS */
4239 wpa_supplicant_event_assoc(wpa_s, data);
4240 wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
4242 (data->assoc_info.authorized ||
4243 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4244 wpa_fils_is_completed(wpa_s->wpa))))
4245 wpa_supplicant_event_assoc_auth(wpa_s, data);
4247 wpa_msg(wpa_s, MSG_INFO,
4248 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
4249 data->assoc_info.subnet_status);
4252 case EVENT_DISASSOC:
4253 wpas_event_disassoc(wpa_s,
4254 data ? &data->disassoc_info : NULL);
4257 #ifdef CONFIG_TESTING_OPTIONS
4258 if (wpa_s->ignore_auth_resp) {
4259 wpa_printf(MSG_INFO,
4260 "EVENT_DEAUTH - ignore_auth_resp active!");
4263 if (wpa_s->testing_resend_assoc) {
4264 wpa_printf(MSG_INFO,
4265 "EVENT_DEAUTH - testing_resend_assoc");
4268 #endif /* CONFIG_TESTING_OPTIONS */
4269 wpas_event_deauth(wpa_s,
4270 data ? &data->deauth_info : NULL);
4272 case EVENT_MICHAEL_MIC_FAILURE:
4273 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
4275 #ifndef CONFIG_NO_SCAN_PROCESSING
4276 case EVENT_SCAN_STARTED:
4277 if (wpa_s->own_scan_requested ||
4278 (data && !data->scan_info.external_scan)) {
4279 struct os_reltime diff;
4281 os_get_reltime(&wpa_s->scan_start_time);
4282 os_reltime_sub(&wpa_s->scan_start_time,
4283 &wpa_s->scan_trigger_time, &diff);
4284 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
4285 diff.sec, diff.usec);
4286 wpa_s->own_scan_requested = 0;
4287 wpa_s->own_scan_running = 1;
4288 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
4289 wpa_s->manual_scan_use_id) {
4290 wpa_msg_ctrl(wpa_s, MSG_INFO,
4291 WPA_EVENT_SCAN_STARTED "id=%u",
4292 wpa_s->manual_scan_id);
4294 wpa_msg_ctrl(wpa_s, MSG_INFO,
4295 WPA_EVENT_SCAN_STARTED);
4298 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
4299 wpa_s->radio->external_scan_running = 1;
4300 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
4303 case EVENT_SCAN_RESULTS:
4304 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4305 wpa_s->scan_res_handler = NULL;
4306 wpa_s->own_scan_running = 0;
4307 wpa_s->radio->external_scan_running = 0;
4308 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
4312 if (!(data && data->scan_info.external_scan) &&
4313 os_reltime_initialized(&wpa_s->scan_start_time)) {
4314 struct os_reltime now, diff;
4315 os_get_reltime(&now);
4316 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
4317 wpa_s->scan_start_time.sec = 0;
4318 wpa_s->scan_start_time.usec = 0;
4319 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
4320 diff.sec, diff.usec);
4322 if (wpa_supplicant_event_scan_results(wpa_s, data))
4323 break; /* interface may have been removed */
4324 if (!(data && data->scan_info.external_scan))
4325 wpa_s->own_scan_running = 0;
4326 if (data && data->scan_info.nl_scan_event)
4327 wpa_s->radio->external_scan_running = 0;
4328 radio_work_check_next(wpa_s);
4330 #endif /* CONFIG_NO_SCAN_PROCESSING */
4331 case EVENT_ASSOCINFO:
4332 wpa_supplicant_event_associnfo(wpa_s, data);
4334 case EVENT_INTERFACE_STATUS:
4335 wpa_supplicant_event_interface_status(wpa_s, data);
4337 case EVENT_PMKID_CANDIDATE:
4338 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
4342 wpa_supplicant_event_tdls(wpa_s, data);
4344 #endif /* CONFIG_TDLS */
4347 wpa_supplicant_event_wnm(wpa_s, data);
4349 #endif /* CONFIG_WNM */
4350 #ifdef CONFIG_IEEE80211R
4351 case EVENT_FT_RESPONSE:
4352 wpa_supplicant_event_ft_response(wpa_s, data);
4354 #endif /* CONFIG_IEEE80211R */
4355 #ifdef CONFIG_IBSS_RSN
4356 case EVENT_IBSS_RSN_START:
4357 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
4359 #endif /* CONFIG_IBSS_RSN */
4360 case EVENT_ASSOC_REJECT:
4361 wpas_event_assoc_reject(wpa_s, data);
4363 case EVENT_AUTH_TIMED_OUT:
4364 /* It is possible to get this event from earlier connection */
4365 if (wpa_s->current_ssid &&
4366 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4367 wpa_dbg(wpa_s, MSG_DEBUG,
4368 "Ignore AUTH_TIMED_OUT in mesh configuration");
4371 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4372 sme_event_auth_timed_out(wpa_s, data);
4374 case EVENT_ASSOC_TIMED_OUT:
4375 /* It is possible to get this event from earlier connection */
4376 if (wpa_s->current_ssid &&
4377 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
4378 wpa_dbg(wpa_s, MSG_DEBUG,
4379 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4382 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
4383 sme_event_assoc_timed_out(wpa_s, data);
4385 case EVENT_TX_STATUS:
4386 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
4387 " type=%d stype=%d",
4388 MAC2STR(data->tx_status.dst),
4389 data->tx_status.type, data->tx_status.stype);
4391 if (wpa_s->ap_iface == NULL) {
4392 #ifdef CONFIG_OFFCHANNEL
4393 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4394 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
4395 offchannel_send_action_tx_status(
4396 wpa_s, data->tx_status.dst,
4397 data->tx_status.data,
4398 data->tx_status.data_len,
4399 data->tx_status.ack ?
4400 OFFCHANNEL_SEND_ACTION_SUCCESS :
4401 OFFCHANNEL_SEND_ACTION_NO_ACK);
4402 #endif /* CONFIG_OFFCHANNEL */
4405 #endif /* CONFIG_AP */
4406 #ifdef CONFIG_OFFCHANNEL
4407 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
4408 MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
4410 * Catch TX status events for Action frames we sent via group
4411 * interface in GO mode, or via standalone AP interface.
4412 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4413 * except when the primary interface is used as a GO interface
4414 * (for drivers which do not have group interface concurrency)
4416 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
4417 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
4418 os_memcmp(wpa_s->p2pdev->pending_action_dst,
4419 data->tx_status.dst, ETH_ALEN) == 0) {
4420 offchannel_send_action_tx_status(
4421 wpa_s->p2pdev, data->tx_status.dst,
4422 data->tx_status.data,
4423 data->tx_status.data_len,
4424 data->tx_status.ack ?
4425 OFFCHANNEL_SEND_ACTION_SUCCESS :
4426 OFFCHANNEL_SEND_ACTION_NO_ACK);
4429 #endif /* CONFIG_OFFCHANNEL */
4431 switch (data->tx_status.type) {
4432 case WLAN_FC_TYPE_MGMT:
4433 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
4434 data->tx_status.data_len,
4435 data->tx_status.stype,
4436 data->tx_status.ack);
4438 case WLAN_FC_TYPE_DATA:
4439 ap_tx_status(wpa_s, data->tx_status.dst,
4440 data->tx_status.data,
4441 data->tx_status.data_len,
4442 data->tx_status.ack);
4445 #endif /* CONFIG_AP */
4448 case EVENT_EAPOL_TX_STATUS:
4449 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
4450 data->eapol_tx_status.data,
4451 data->eapol_tx_status.data_len,
4452 data->eapol_tx_status.ack);
4454 case EVENT_DRIVER_CLIENT_POLL_OK:
4455 ap_client_poll_ok(wpa_s, data->client_poll.addr);
4457 case EVENT_RX_FROM_UNKNOWN:
4458 if (wpa_s->ap_iface == NULL)
4460 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
4461 data->rx_from_unknown.wds);
4463 #endif /* CONFIG_AP */
4464 case EVENT_CH_SWITCH:
4465 if (!data || !wpa_s->current_ssid)
4468 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
4469 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4470 data->ch_switch.freq,
4471 data->ch_switch.ht_enabled,
4472 data->ch_switch.ch_offset,
4473 channel_width_to_string(data->ch_switch.ch_width),
4474 data->ch_switch.cf1,
4475 data->ch_switch.cf2);
4477 wpa_s->assoc_freq = data->ch_switch.freq;
4478 wpa_s->current_ssid->frequency = data->ch_switch.freq;
4481 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
4482 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
4483 wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
4484 wpa_s->current_ssid->mode ==
4485 WPAS_MODE_P2P_GROUP_FORMATION) {
4486 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
4487 data->ch_switch.ht_enabled,
4488 data->ch_switch.ch_offset,
4489 data->ch_switch.ch_width,
4490 data->ch_switch.cf1,
4491 data->ch_switch.cf2);
4493 #endif /* CONFIG_AP */
4495 #ifdef CONFIG_IEEE80211W
4496 sme_event_ch_switch(wpa_s);
4497 #endif /* CONFIG_IEEE80211W */
4498 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
4499 wnm_clear_coloc_intf_reporting(wpa_s);
4503 case EVENT_DFS_RADAR_DETECTED:
4505 wpas_ap_event_dfs_radar_detected(wpa_s,
4508 case EVENT_DFS_NOP_FINISHED:
4510 wpas_ap_event_dfs_cac_nop_finished(wpa_s,
4513 #endif /* NEED_AP_MLME */
4514 #endif /* CONFIG_AP */
4515 case EVENT_DFS_CAC_STARTED:
4517 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
4519 case EVENT_DFS_CAC_FINISHED:
4521 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
4523 case EVENT_DFS_CAC_ABORTED:
4525 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
4527 case EVENT_RX_MGMT: {
4529 const struct ieee80211_mgmt *mgmt;
4531 #ifdef CONFIG_TESTING_OPTIONS
4532 if (wpa_s->ext_mgmt_frame_handling) {
4533 struct rx_mgmt *rx = &data->rx_mgmt;
4534 size_t hex_len = 2 * rx->frame_len + 1;
4535 char *hex = os_malloc(hex_len);
4537 wpa_snprintf_hex(hex, hex_len,
4538 rx->frame, rx->frame_len);
4539 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4540 rx->freq, rx->datarate, rx->ssi_signal,
4546 #endif /* CONFIG_TESTING_OPTIONS */
4548 mgmt = (const struct ieee80211_mgmt *)
4549 data->rx_mgmt.frame;
4550 fc = le_to_host16(mgmt->frame_control);
4551 stype = WLAN_FC_GET_STYPE(fc);
4554 if (wpa_s->ap_iface == NULL) {
4555 #endif /* CONFIG_AP */
4557 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
4558 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4559 const u8 *src = mgmt->sa;
4563 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4564 ie_len = data->rx_mgmt.frame_len -
4566 wpas_p2p_probe_req_rx(
4567 wpa_s, src, mgmt->da,
4568 mgmt->bssid, ie, ie_len,
4570 data->rx_mgmt.ssi_signal);
4573 #endif /* CONFIG_P2P */
4574 #ifdef CONFIG_IBSS_RSN
4575 if (wpa_s->current_ssid &&
4576 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4577 stype == WLAN_FC_STYPE_AUTH &&
4578 data->rx_mgmt.frame_len >= 30) {
4579 wpa_supplicant_event_ibss_auth(wpa_s, data);
4582 #endif /* CONFIG_IBSS_RSN */
4584 if (stype == WLAN_FC_STYPE_ACTION) {
4585 wpas_event_rx_mgmt_action(
4586 wpa_s, data->rx_mgmt.frame,
4587 data->rx_mgmt.frame_len,
4589 data->rx_mgmt.ssi_signal);
4594 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
4599 if (stype == WLAN_FC_STYPE_AUTH &&
4600 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4601 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4602 sme_external_auth_mgmt_rx(
4603 wpa_s, data->rx_mgmt.frame,
4604 data->rx_mgmt.frame_len);
4607 #endif /* CONFIG_SAE */
4608 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
4609 "management frame in non-AP mode");
4614 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
4615 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
4619 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
4620 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
4622 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
4623 mgmt->bssid, ie, ie_len,
4624 data->rx_mgmt.ssi_signal);
4627 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
4628 #endif /* CONFIG_AP */
4631 case EVENT_RX_PROBE_REQ:
4632 if (data->rx_probe_req.sa == NULL ||
4633 data->rx_probe_req.ie == NULL)
4636 if (wpa_s->ap_iface) {
4637 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
4638 data->rx_probe_req.sa,
4639 data->rx_probe_req.da,
4640 data->rx_probe_req.bssid,
4641 data->rx_probe_req.ie,
4642 data->rx_probe_req.ie_len,
4643 data->rx_probe_req.ssi_signal);
4646 #endif /* CONFIG_AP */
4647 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
4648 data->rx_probe_req.da,
4649 data->rx_probe_req.bssid,
4650 data->rx_probe_req.ie,
4651 data->rx_probe_req.ie_len,
4653 data->rx_probe_req.ssi_signal);
4655 case EVENT_REMAIN_ON_CHANNEL:
4656 #ifdef CONFIG_OFFCHANNEL
4657 offchannel_remain_on_channel_cb(
4658 wpa_s, data->remain_on_channel.freq,
4659 data->remain_on_channel.duration);
4660 #endif /* CONFIG_OFFCHANNEL */
4661 wpas_p2p_remain_on_channel_cb(
4662 wpa_s, data->remain_on_channel.freq,
4663 data->remain_on_channel.duration);
4665 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
4666 #ifdef CONFIG_OFFCHANNEL
4667 offchannel_cancel_remain_on_channel_cb(
4668 wpa_s, data->remain_on_channel.freq);
4669 #endif /* CONFIG_OFFCHANNEL */
4670 wpas_p2p_cancel_remain_on_channel_cb(
4671 wpa_s, data->remain_on_channel.freq);
4673 wpas_dpp_cancel_remain_on_channel_cb(
4674 wpa_s, data->remain_on_channel.freq);
4675 #endif /* CONFIG_DPP */
4677 case EVENT_EAPOL_RX:
4678 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
4679 data->eapol_rx.data,
4680 data->eapol_rx.data_len);
4682 case EVENT_SIGNAL_CHANGE:
4683 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
4684 "above=%d signal=%d noise=%d txrate=%d",
4685 data->signal_change.above_threshold,
4686 data->signal_change.current_signal,
4687 data->signal_change.current_noise,
4688 data->signal_change.current_txrate);
4689 wpa_bss_update_level(wpa_s->current_bss,
4690 data->signal_change.current_signal);
4691 bgscan_notify_signal_change(
4692 wpa_s, data->signal_change.above_threshold,
4693 data->signal_change.current_signal,
4694 data->signal_change.current_noise,
4695 data->signal_change.current_txrate);
4697 case EVENT_INTERFACE_MAC_CHANGED:
4698 wpa_supplicant_update_mac_addr(wpa_s);
4700 case EVENT_INTERFACE_ENABLED:
4701 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
4702 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4703 wpa_supplicant_update_mac_addr(wpa_s);
4704 if (wpa_s->p2p_mgmt) {
4705 wpa_supplicant_set_state(wpa_s,
4711 if (!wpa_s->ap_iface) {
4712 wpa_supplicant_set_state(wpa_s,
4714 wpa_s->scan_req = NORMAL_SCAN_REQ;
4715 wpa_supplicant_req_scan(wpa_s, 0, 0);
4717 wpa_supplicant_set_state(wpa_s,
4719 #else /* CONFIG_AP */
4720 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4721 wpa_supplicant_req_scan(wpa_s, 0, 0);
4722 #endif /* CONFIG_AP */
4725 case EVENT_INTERFACE_DISABLED:
4726 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
4728 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
4729 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
4730 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
4732 * Mark interface disabled if this happens to end up not
4733 * being removed as a separate P2P group interface.
4735 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4737 * The interface was externally disabled. Remove
4738 * it assuming an external entity will start a
4739 * new session if needed.
4741 if (wpa_s->current_ssid &&
4742 wpa_s->current_ssid->p2p_group)
4743 wpas_p2p_interface_unavailable(wpa_s);
4745 wpas_p2p_disconnect(wpa_s);
4747 * wpa_s instance may have been freed, so must not use
4752 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
4753 p2p_in_progress(wpa_s->global->p2p) > 1) {
4754 /* This radio work will be cancelled, so clear P2P
4757 p2p_stop_find(wpa_s->global->p2p);
4759 #endif /* CONFIG_P2P */
4761 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4763 * Indicate disconnection to keep ctrl_iface events
4766 wpa_supplicant_event_disassoc(
4767 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
4769 wpa_supplicant_mark_disassoc(wpa_s);
4770 wpa_bss_flush(wpa_s);
4771 radio_remove_works(wpa_s, NULL, 0);
4773 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4775 case EVENT_CHANNEL_LIST_CHANGED:
4776 wpa_supplicant_update_channel_list(
4777 wpa_s, &data->channel_list_changed);
4779 case EVENT_INTERFACE_UNAVAILABLE:
4780 wpas_p2p_interface_unavailable(wpa_s);
4782 case EVENT_BEST_CHANNEL:
4783 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
4785 data->best_chan.freq_24, data->best_chan.freq_5,
4786 data->best_chan.freq_overall);
4787 wpa_s->best_24_freq = data->best_chan.freq_24;
4788 wpa_s->best_5_freq = data->best_chan.freq_5;
4789 wpa_s->best_overall_freq = data->best_chan.freq_overall;
4790 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
4791 data->best_chan.freq_5,
4792 data->best_chan.freq_overall);
4794 case EVENT_UNPROT_DEAUTH:
4795 wpa_supplicant_event_unprot_deauth(wpa_s,
4796 &data->unprot_deauth);
4798 case EVENT_UNPROT_DISASSOC:
4799 wpa_supplicant_event_unprot_disassoc(wpa_s,
4800 &data->unprot_disassoc);
4802 case EVENT_STATION_LOW_ACK:
4804 if (wpa_s->ap_iface && data)
4805 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
4806 data->low_ack.addr);
4807 #endif /* CONFIG_AP */
4810 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
4811 data->low_ack.addr);
4812 #endif /* CONFIG_TDLS */
4814 case EVENT_IBSS_PEER_LOST:
4815 #ifdef CONFIG_IBSS_RSN
4816 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
4817 #endif /* CONFIG_IBSS_RSN */
4819 case EVENT_DRIVER_GTK_REKEY:
4820 if (os_memcmp(data->driver_gtk_rekey.bssid,
4821 wpa_s->bssid, ETH_ALEN))
4825 wpa_sm_update_replay_ctr(wpa_s->wpa,
4826 data->driver_gtk_rekey.replay_ctr);
4828 case EVENT_SCHED_SCAN_STOPPED:
4829 wpa_s->sched_scanning = 0;
4830 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
4831 wpa_supplicant_notify_scanning(wpa_s, 0);
4833 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4837 * If the driver stopped scanning without being requested to,
4838 * request a new scan to continue scanning for networks.
4840 if (!wpa_s->sched_scan_stop_req &&
4841 wpa_s->wpa_state == WPA_SCANNING) {
4842 wpa_dbg(wpa_s, MSG_DEBUG,
4843 "Restart scanning after unexpected sched_scan stop event");
4844 wpa_supplicant_req_scan(wpa_s, 1, 0);
4848 wpa_s->sched_scan_stop_req = 0;
4851 * Start a new sched scan to continue searching for more SSIDs
4852 * either if timed out or PNO schedule scan is pending.
4854 if (wpa_s->sched_scan_timed_out) {
4855 wpa_supplicant_req_sched_scan(wpa_s);
4856 } else if (wpa_s->pno_sched_pending) {
4857 wpa_s->pno_sched_pending = 0;
4858 wpas_start_pno(wpa_s);
4859 } else if (resched) {
4860 wpa_supplicant_req_scan(wpa_s, 0, 0);
4864 case EVENT_WPS_BUTTON_PUSHED:
4866 wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
4867 #endif /* CONFIG_WPS */
4869 case EVENT_AVOID_FREQUENCIES:
4870 wpa_supplicant_notify_avoid_freq(wpa_s, data);
4872 case EVENT_CONNECT_FAILED_REASON:
4874 if (!wpa_s->ap_iface || !data)
4876 hostapd_event_connect_failed_reason(
4877 wpa_s->ap_iface->bss[0],
4878 data->connect_failed_reason.addr,
4879 data->connect_failed_reason.code);
4880 #endif /* CONFIG_AP */
4882 case EVENT_NEW_PEER_CANDIDATE:
4884 if (!wpa_s->ifmsh || !data)
4886 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4887 data->mesh_peer.ies,
4888 data->mesh_peer.ie_len);
4889 #endif /* CONFIG_MESH */
4893 if (!wpa_s->ap_iface)
4895 hostapd_event_get_survey(wpa_s->ap_iface,
4896 &data->survey_results);
4897 #endif /* CONFIG_AP */
4899 case EVENT_ACS_CHANNEL_SELECTED:
4902 if (!wpa_s->ap_iface)
4904 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4905 &data->acs_selected_channels);
4906 #endif /* CONFIG_ACS */
4907 #endif /* CONFIG_AP */
4909 case EVENT_P2P_LO_STOP:
4911 wpa_s->p2p_lo_started = 0;
4912 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
4913 P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
4914 data->p2p_lo_stop.reason_code);
4915 #endif /* CONFIG_P2P */
4917 case EVENT_BEACON_LOSS:
4918 if (!wpa_s->current_bss || !wpa_s->current_ssid)
4920 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
4921 bgscan_notify_beacon_loss(wpa_s);
4923 case EVENT_EXTERNAL_AUTH:
4925 if (!wpa_s->current_ssid) {
4926 wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
4929 sme_external_auth_trigger(wpa_s, data);
4930 #endif /* CONFIG_SAE */
4932 case EVENT_PORT_AUTHORIZED:
4933 wpa_supplicant_event_port_authorized(wpa_s);
4935 case EVENT_STATION_OPMODE_CHANGED:
4937 if (!wpa_s->ap_iface || !data)
4940 hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
4941 data->sta_opmode.addr,
4942 data->sta_opmode.smps_mode,
4943 data->sta_opmode.chan_width,
4944 data->sta_opmode.rx_nss);
4945 #endif /* CONFIG_AP */
4948 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4954 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4955 union wpa_event_data *data)
4957 struct wpa_supplicant *wpa_s;
4959 if (event != EVENT_INTERFACE_STATUS)
4962 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4963 if (wpa_s && wpa_s->driver->get_ifindex) {
4964 unsigned int ifindex;
4966 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4967 if (ifindex != data->interface_status.ifindex) {
4968 wpa_dbg(wpa_s, MSG_DEBUG,
4969 "interface status ifindex %d mismatch (%d)",
4970 ifindex, data->interface_status.ifindex);
4974 #ifdef CONFIG_MATCH_IFACE
4975 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4976 struct wpa_interface *wpa_i;
4978 wpa_i = wpa_supplicant_match_iface(
4979 ctx, data->interface_status.ifname);
4982 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4987 #endif /* CONFIG_MATCH_IFACE */
4990 wpa_supplicant_event(wpa_s, event, data);