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 */
192 if ((wpa_s
->current_ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
193 wpa_s
->current_bss
&&
194 (wpa_s
->current_bss
->flags
& WPA_BSS_OWE_TRANSITION
) &&
195 drv_ssid_len
== wpa_s
->current_bss
->ssid_len
&&
196 os_memcmp(drv_ssid
, wpa_s
->current_bss
->ssid
,
198 return 0; /* current profile still in use */
199 #endif /* CONFIG_OWE */
201 wpa_msg(wpa_s
, MSG_DEBUG
,
202 "Driver-initiated BSS selection changed the SSID to %s",
203 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
204 /* continue selecting a new network profile */
207 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
209 ssid
= wpa_supplicant_get_ssid(wpa_s
);
211 wpa_msg(wpa_s
, MSG_INFO
,
212 "No network configuration found for the current AP");
216 if (wpas_network_disabled(wpa_s
, ssid
)) {
217 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
221 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
222 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
223 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
227 res
= wpas_temp_disabled(wpa_s
, ssid
);
229 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
230 "disabled for %d second(s)", res
);
234 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
236 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
238 size_t wpa_ie_len
= sizeof(wpa_ie
);
239 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
240 wpa_ie
, &wpa_ie_len
) < 0)
241 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
243 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
246 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
247 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
248 old_ssid
= wpa_s
->current_ssid
;
249 wpa_s
->current_ssid
= ssid
;
251 wpa_supplicant_update_current_bss(wpa_s
);
253 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
254 wpa_supplicant_initiate_eapol(wpa_s
);
255 if (old_ssid
!= wpa_s
->current_ssid
)
256 wpas_notify_network_changed(wpa_s
);
262 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
264 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
266 if (wpa_s
->countermeasures
) {
267 wpa_s
->countermeasures
= 0;
268 wpa_drv_set_countermeasures(wpa_s
, 0);
269 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
272 * It is possible that the device is sched scanning, which means
273 * that a connection attempt will be done only when we receive
274 * scan results. However, in this case, it would be preferable
275 * to scan and connect immediately, so cancel the sched_scan and
276 * issue a regular scan flow.
278 wpa_supplicant_cancel_sched_scan(wpa_s
);
279 wpa_supplicant_req_scan(wpa_s
, 0, 0);
284 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
288 wnm_bss_keep_alive_deinit(wpa_s
);
290 #ifdef CONFIG_IBSS_RSN
291 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
292 wpa_s
->ibss_rsn
= NULL
;
293 #endif /* CONFIG_IBSS_RSN */
296 wpa_supplicant_ap_deinit(wpa_s
);
297 #endif /* CONFIG_AP */
300 /* Clear possibly configured frame filters */
301 wpa_drv_configure_frame_filters(wpa_s
, 0);
302 #endif /* CONFIG_HS20 */
304 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
307 if (os_reltime_initialized(&wpa_s
->session_start
)) {
308 os_reltime_age(&wpa_s
->session_start
, &wpa_s
->session_length
);
309 wpa_s
->session_start
.sec
= 0;
310 wpa_s
->session_start
.usec
= 0;
311 wpas_notify_session_length(wpa_s
);
314 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
315 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
316 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
317 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
318 sme_clear_on_disassoc(wpa_s
);
319 wpa_s
->current_bss
= NULL
;
320 wpa_s
->assoc_freq
= 0;
323 wpas_notify_bssid_changed(wpa_s
);
325 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
326 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
327 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
328 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
329 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
|| wpa_s
->drv_authorized_port
)
330 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
331 wpa_s
->drv_authorized_port
= 0;
332 wpa_s
->ap_ies_from_associnfo
= 0;
333 wpa_s
->current_ssid
= NULL
;
334 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
337 wpas_rrm_reset(wpa_s
);
338 wpa_s
->wnmsleep_used
= 0;
339 wnm_clear_coloc_intf_reporting(wpa_s
);
340 wpa_s
->disable_mbo_oce
= 0;
342 #ifdef CONFIG_TESTING_OPTIONS
343 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
344 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
345 #endif /* CONFIG_TESTING_OPTIONS */
346 wpa_s
->ieee80211ac
= 0;
348 if (wpa_s
->enabled_4addr_mode
&& wpa_drv_set_4addr_mode(wpa_s
, 0) == 0)
349 wpa_s
->enabled_4addr_mode
= 0;
353 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
355 struct wpa_ie_data ie
;
359 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
363 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
364 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
365 ie
.pmkid
+ i
* PMKID_LEN
,
366 NULL
, NULL
, 0, NULL
, 0);
367 if (pmksa_set
== 0) {
368 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
373 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
374 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
378 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
379 union wpa_event_data
*data
)
382 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
386 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
387 " index=%d preauth=%d",
388 MAC2STR(data
->pmkid_candidate
.bssid
),
389 data
->pmkid_candidate
.index
,
390 data
->pmkid_candidate
.preauth
);
392 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
393 data
->pmkid_candidate
.index
,
394 data
->pmkid_candidate
.preauth
);
398 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
400 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
401 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
404 #ifdef IEEE8021X_EAPOL
405 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
406 wpa_s
->current_ssid
&&
407 !(wpa_s
->current_ssid
->eapol_flags
&
408 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
409 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
410 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
411 * plaintext or static WEP keys). */
414 #endif /* IEEE8021X_EAPOL */
421 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
422 * @wpa_s: pointer to wpa_supplicant data
423 * @ssid: Configuration data for the network
424 * Returns: 0 on success, -1 on failure
426 * This function is called when starting authentication with a network that is
427 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
429 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
430 struct wpa_ssid
*ssid
)
432 #ifdef IEEE8021X_EAPOL
434 int aka
= 0, sim
= 0;
436 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
437 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
440 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
444 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
445 while (eap
->vendor
!= EAP_VENDOR_IETF
||
446 eap
->method
!= EAP_TYPE_NONE
) {
447 if (eap
->vendor
== EAP_VENDOR_IETF
) {
448 if (eap
->method
== EAP_TYPE_SIM
)
450 else if (eap
->method
== EAP_TYPE_AKA
||
451 eap
->method
== EAP_TYPE_AKA_PRIME
)
458 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
460 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
461 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
466 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
467 "use SIM, but neither EAP-SIM nor EAP-AKA are "
472 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
473 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
475 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
476 if (wpa_s
->scard
== NULL
) {
477 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
481 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
482 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
483 #endif /* PCSC_FUNCS */
484 #endif /* IEEE8021X_EAPOL */
490 #ifndef CONFIG_NO_SCAN_PROCESSING
493 static int has_wep_key(struct wpa_ssid
*ssid
)
497 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
498 if (ssid
->wep_key_len
[i
])
504 #endif /* CONFIG_WEP */
507 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
508 struct wpa_ssid
*ssid
)
512 if (ssid
->mixed_cell
)
516 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
518 #endif /* CONFIG_WPS */
521 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
523 #endif /* CONFIG_OWE */
526 if (has_wep_key(ssid
))
528 #endif /* CONFIG_WEP */
530 #ifdef IEEE8021X_EAPOL
531 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
532 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
533 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
535 #endif /* IEEE8021X_EAPOL */
537 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
540 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
543 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
549 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
550 struct wpa_ssid
*ssid
,
551 struct wpa_bss
*bss
, int debug_print
)
553 struct wpa_ie_data ie
;
555 const u8
*rsn_ie
, *wpa_ie
;
559 #endif /* CONFIG_WEP */
561 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
566 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
567 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
568 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
569 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
570 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
571 #endif /* CONFIG_WEP */
573 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
574 while ((ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)) && rsn_ie
) {
577 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
579 wpa_dbg(wpa_s
, MSG_DEBUG
,
580 " skip RSN IE - parse failed");
583 if (!ie
.has_pairwise
)
584 ie
.pairwise_cipher
= wpa_default_rsn_cipher(bss
->freq
);
586 ie
.group_cipher
= wpa_default_rsn_cipher(bss
->freq
);
590 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
593 wpa_dbg(wpa_s
, MSG_DEBUG
,
594 " selected based on TSN in RSN IE");
597 #endif /* CONFIG_WEP */
599 if (!(ie
.proto
& ssid
->proto
) &&
600 !(ssid
->proto
& WPA_PROTO_OSEN
)) {
602 wpa_dbg(wpa_s
, MSG_DEBUG
,
603 " skip RSN IE - proto mismatch");
607 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
609 wpa_dbg(wpa_s
, MSG_DEBUG
,
610 " skip RSN IE - PTK cipher mismatch");
614 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
616 wpa_dbg(wpa_s
, MSG_DEBUG
,
617 " skip RSN IE - GTK cipher mismatch");
621 if (ssid
->group_mgmt_cipher
&&
622 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
624 wpa_dbg(wpa_s
, MSG_DEBUG
,
625 " skip RSN IE - group mgmt cipher mismatch");
629 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
631 wpa_dbg(wpa_s
, MSG_DEBUG
,
632 " skip RSN IE - key mgmt mismatch");
636 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
637 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
638 MGMT_FRAME_PROTECTION_REQUIRED
) {
640 wpa_dbg(wpa_s
, MSG_DEBUG
,
641 " skip RSN IE - no mgmt frame protection");
644 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
645 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
646 NO_MGMT_FRAME_PROTECTION
) {
648 wpa_dbg(wpa_s
, MSG_DEBUG
,
649 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
654 wpa_dbg(wpa_s
, MSG_DEBUG
,
655 " selected based on RSN IE");
659 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
660 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
662 wpa_dbg(wpa_s
, MSG_DEBUG
,
663 " skip - MFP Required but network not MFP Capable");
667 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
668 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
671 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
673 wpa_dbg(wpa_s
, MSG_DEBUG
,
674 " skip WPA IE - parse failed");
680 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
683 wpa_dbg(wpa_s
, MSG_DEBUG
,
684 " selected based on TSN in WPA IE");
687 #endif /* CONFIG_WEP */
689 if (!(ie
.proto
& ssid
->proto
)) {
691 wpa_dbg(wpa_s
, MSG_DEBUG
,
692 " skip WPA IE - proto mismatch");
696 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
698 wpa_dbg(wpa_s
, MSG_DEBUG
,
699 " skip WPA IE - PTK cipher mismatch");
703 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
705 wpa_dbg(wpa_s
, MSG_DEBUG
,
706 " skip WPA IE - GTK cipher mismatch");
710 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
712 wpa_dbg(wpa_s
, MSG_DEBUG
,
713 " skip WPA IE - key mgmt mismatch");
718 wpa_dbg(wpa_s
, MSG_DEBUG
,
719 " selected based on WPA IE");
723 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
726 wpa_dbg(wpa_s
, MSG_DEBUG
,
727 " allow for non-WPA IEEE 802.1X");
732 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
733 !wpa_ie
&& !rsn_ie
) {
734 if (wpa_s
->owe_transition_select
&&
735 wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
) &&
736 ssid
->owe_transition_bss_select_count
+ 1 <=
737 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
) {
738 ssid
->owe_transition_bss_select_count
++;
740 wpa_dbg(wpa_s
, MSG_DEBUG
,
741 " skip OWE transition BSS (selection count %d does not exceed %d)",
742 ssid
->owe_transition_bss_select_count
,
743 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
);
744 wpa_s
->owe_transition_search
= 1;
748 wpa_dbg(wpa_s
, MSG_DEBUG
,
749 " allow in OWE transition mode");
752 #endif /* CONFIG_OWE */
754 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
755 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
757 wpa_dbg(wpa_s
, MSG_DEBUG
,
758 " skip - no WPA/RSN proto match");
762 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
763 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
765 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
769 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
771 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
776 wpa_dbg(wpa_s
, MSG_DEBUG
,
777 " reject due to mismatch with WPA/WPA2");
783 static int freq_allowed(int *freqs
, int freq
)
790 for (i
= 0; freqs
[i
]; i
++)
791 if (freqs
[i
] == freq
)
797 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
798 struct wpa_bss
*bss
, int debug_print
)
800 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
801 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
806 return 1; /* Cannot do matching without knowing band */
808 modes
= wpa_s
->hw
.modes
;
811 * The driver does not provide any additional information
812 * about the utilized hardware, so allow the connection attempt
818 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
819 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
820 int freq
= modes
[i
].channels
[j
].freq
;
821 if (freq
== bss
->freq
) {
823 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
824 break; /* do not allow 802.11b replace
835 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
836 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
840 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
841 int flagged
= !!(rate_ie
[j
] & 0x80);
842 int r
= (rate_ie
[j
] & 0x7f) * 5;
845 * IEEE Std 802.11n-2009 7.3.2.2:
846 * The new BSS Membership selector value is encoded
847 * like a legacy basic rate, but it is not a rate and
848 * only indicates if the BSS members are required to
849 * support the mandatory features of Clause 20 [HT PHY]
850 * in order to join the BSS.
852 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
853 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
854 if (!ht_supported(mode
)) {
856 wpa_dbg(wpa_s
, MSG_DEBUG
,
857 " hardware does not support HT PHY");
863 /* There's also a VHT selector for 802.11ac */
864 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
865 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
866 if (!vht_supported(mode
)) {
868 wpa_dbg(wpa_s
, MSG_DEBUG
,
869 " hardware does not support VHT PHY");
876 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
877 BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY
)) {
878 if (wpa_s
->conf
->sae_pwe
== 0 &&
879 !ssid
->sae_password_id
&&
880 wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
882 wpa_dbg(wpa_s
, MSG_DEBUG
,
883 " SAE H2E disabled");
884 #ifdef CONFIG_TESTING_OPTIONS
885 if (wpa_s
->ignore_sae_h2e_only
) {
886 wpa_dbg(wpa_s
, MSG_DEBUG
,
887 "TESTING: Ignore SAE H2E requirement mismatch");
890 #endif /* CONFIG_TESTING_OPTIONS */
895 #endif /* CONFIG_SAE */
900 /* check for legacy basic rates */
901 for (k
= 0; k
< mode
->num_rates
; k
++) {
902 if (mode
->rates
[k
] == r
)
905 if (k
== mode
->num_rates
) {
907 * IEEE Std 802.11-2007 7.3.2.2 demands that in
908 * order to join a BSS all required rates
909 * have to be supported by the hardware.
912 wpa_dbg(wpa_s
, MSG_DEBUG
,
913 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
915 bss
->freq
, mode
->mode
, mode
->num_rates
);
926 * Test whether BSS is in an ESS.
927 * This is done differently in DMG (60 GHz) and non-DMG bands
929 static int bss_is_ess(struct wpa_bss
*bss
)
931 if (bss_is_dmg(bss
)) {
932 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
933 IEEE80211_CAP_DMG_AP
;
936 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
941 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
945 for (i
= 0; i
< ETH_ALEN
; i
++) {
946 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
953 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
957 for (i
= 0; i
< num
; i
++) {
958 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
959 const u8
*m
= a
+ ETH_ALEN
;
961 if (match_mac_mask(a
, addr
, m
))
968 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
969 const u8
**ret_ssid
, size_t *ret_ssid_len
)
972 const u8
*owe
, *pos
, *end
, *bssid
;
974 struct wpa_bss
*open_bss
;
976 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
977 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
981 end
= owe
+ 2 + owe
[1];
983 if (end
- pos
< ETH_ALEN
+ 1)
988 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
991 /* Match the profile SSID against the OWE transition mode SSID on the
993 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
994 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
996 *ret_ssid_len
= ssid_len
;
998 if (!(bss
->flags
& WPA_BSS_OWE_TRANSITION
)) {
999 struct wpa_ssid
*ssid
;
1001 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1002 if (wpas_network_disabled(wpa_s
, ssid
))
1004 if (ssid
->ssid_len
== ssid_len
&&
1005 os_memcmp(ssid
->ssid
, pos
, ssid_len
) == 0) {
1006 /* OWE BSS in transition mode for a currently
1007 * enabled OWE network. */
1008 wpa_dbg(wpa_s
, MSG_DEBUG
,
1009 "OWE: transition mode OWE SSID for active OWE profile");
1010 bss
->flags
|= WPA_BSS_OWE_TRANSITION
;
1016 if (bss
->ssid_len
> 0)
1019 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
1022 if (ssid_len
!= open_bss
->ssid_len
||
1023 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
1024 wpa_dbg(wpa_s
, MSG_DEBUG
,
1025 "OWE: transition mode SSID mismatch: %s",
1026 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
1030 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
1031 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
1032 wpa_dbg(wpa_s
, MSG_DEBUG
,
1033 "OWE: transition mode open BSS unexpected info");
1038 end
= owe
+ 2 + owe
[1];
1040 if (end
- pos
< ETH_ALEN
+ 1)
1042 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
1043 wpa_dbg(wpa_s
, MSG_DEBUG
,
1044 "OWE: transition mode BSSID mismatch: " MACSTR
,
1050 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
1052 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
1053 wpa_ssid_txt(pos
, ssid_len
));
1054 os_memcpy(bss
->ssid
, pos
, ssid_len
);
1055 bss
->ssid_len
= ssid_len
;
1056 bss
->flags
|= WPA_BSS_OWE_TRANSITION
;
1057 #endif /* CONFIG_OWE */
1061 static int disabled_freq(struct wpa_supplicant
*wpa_s
, int freq
)
1065 if (!wpa_s
->hw
.modes
|| !wpa_s
->hw
.num_modes
)
1068 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
1069 struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[j
];
1071 for (i
= 0; i
< mode
->num_channels
; i
++) {
1072 struct hostapd_channel_data
*chan
= &mode
->channels
[i
];
1074 if (chan
->freq
== freq
)
1075 return !!(chan
->flag
& HOSTAPD_CHAN_DISABLED
);
1083 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
1084 int i
, struct wpa_bss
*bss
,
1085 struct wpa_ssid
*group
,
1086 int only_first_ssid
, int debug_print
)
1088 u8 wpa_ie_len
, rsn_ie_len
;
1090 struct wpa_blacklist
*e
;
1092 struct wpa_ssid
*ssid
;
1093 int osen
, rsn_osen
= 0;
1095 const u8
*assoc_disallow
;
1096 #endif /* CONFIG_MBO */
1097 const u8
*match_ssid
;
1098 size_t match_ssid_len
;
1099 struct wpa_ie_data data
;
1101 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1102 wpa_ie_len
= ie
? ie
[1] : 0;
1104 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1105 rsn_ie_len
= ie
? ie
[1] : 0;
1106 if (ie
&& wpa_parse_wpa_ie_rsn(ie
, 2 + ie
[1], &data
) == 0 &&
1107 (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
))
1110 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1114 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1115 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1116 i
, MAC2STR(bss
->bssid
),
1117 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1118 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1120 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1122 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1123 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1125 osen
? " osen=1" : "");
1128 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1131 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1133 * When only a single network is enabled, we can
1134 * trigger blacklisting on the first failure. This
1135 * should not be done with multiple enabled networks to
1136 * avoid getting forced to move into a worse ESS on
1137 * single error if there are no other BSSes of the
1142 if (e
->count
> limit
) {
1144 wpa_dbg(wpa_s
, MSG_DEBUG
,
1145 " skip - blacklisted (count=%d limit=%d)",
1152 match_ssid
= bss
->ssid
;
1153 match_ssid_len
= bss
->ssid_len
;
1154 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1156 if (match_ssid_len
== 0) {
1158 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1162 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1164 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1168 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1170 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1174 if (disabled_freq(wpa_s
, bss
->freq
)) {
1176 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - channel disabled");
1180 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1182 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1183 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1186 if (wpas_network_disabled(wpa_s
, ssid
)) {
1188 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1192 res
= wpas_temp_disabled(wpa_s
, ssid
);
1195 wpa_dbg(wpa_s
, MSG_DEBUG
,
1196 " skip - disabled temporarily for %d second(s)",
1202 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1204 wpa_dbg(wpa_s
, MSG_DEBUG
,
1205 " skip - blacklisted (WPS)");
1209 if (wpa
&& ssid
->ssid_len
== 0 &&
1210 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1213 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1214 /* Only allow wildcard SSID match if an AP
1215 * advertises active WPS operation that matches
1218 if (ssid
->ssid_len
== 0 &&
1219 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1222 #endif /* CONFIG_WPS */
1224 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1225 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1229 (match_ssid_len
!= ssid
->ssid_len
||
1230 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1232 wpa_dbg(wpa_s
, MSG_DEBUG
,
1233 " skip - SSID mismatch");
1237 if (ssid
->bssid_set
&&
1238 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1240 wpa_dbg(wpa_s
, MSG_DEBUG
,
1241 " skip - BSSID mismatch");
1245 /* check blacklist */
1246 if (ssid
->num_bssid_blacklist
&&
1247 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1248 ssid
->num_bssid_blacklist
)) {
1250 wpa_dbg(wpa_s
, MSG_DEBUG
,
1251 " skip - BSSID blacklisted");
1255 /* if there is a whitelist, only accept those APs */
1256 if (ssid
->num_bssid_whitelist
&&
1257 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1258 ssid
->num_bssid_whitelist
)) {
1260 wpa_dbg(wpa_s
, MSG_DEBUG
,
1261 " skip - BSSID not in whitelist");
1265 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1269 if (!osen
&& !wpa
&&
1270 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1271 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1272 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1273 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1275 wpa_dbg(wpa_s
, MSG_DEBUG
,
1276 " skip - non-WPA network not allowed");
1281 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1282 has_wep_key(ssid
)) {
1284 wpa_dbg(wpa_s
, MSG_DEBUG
,
1285 " skip - ignore WPA/WPA2 AP for WEP network block");
1288 #endif /* CONFIG_WEP */
1290 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
&&
1293 wpa_dbg(wpa_s
, MSG_DEBUG
,
1294 " skip - non-OSEN network not allowed");
1298 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1300 wpa_dbg(wpa_s
, MSG_DEBUG
,
1301 " skip - privacy mismatch");
1305 if (ssid
->mode
!= WPAS_MODE_MESH
&& !bss_is_ess(bss
) &&
1306 !bss_is_pbss(bss
)) {
1308 wpa_dbg(wpa_s
, MSG_DEBUG
,
1309 " skip - not ESS, PBSS, or MBSS");
1313 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1315 wpa_dbg(wpa_s
, MSG_DEBUG
,
1316 " skip - PBSS mismatch (ssid %d bss %d)",
1317 ssid
->pbss
, bss_is_pbss(bss
));
1321 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1323 wpa_dbg(wpa_s
, MSG_DEBUG
,
1324 " skip - frequency not allowed");
1329 if (ssid
->mode
== WPAS_MODE_MESH
&& ssid
->frequency
> 0 &&
1330 ssid
->frequency
!= bss
->freq
) {
1332 wpa_dbg(wpa_s
, MSG_DEBUG
,
1333 " skip - frequency not allowed (mesh)");
1336 #endif /* CONFIG_MESH */
1338 if (!rate_match(wpa_s
, ssid
, bss
, debug_print
)) {
1340 wpa_dbg(wpa_s
, MSG_DEBUG
,
1341 " skip - rate sets do not match");
1346 if ((wpa_s
->conf
->sae_pwe
== 1 || ssid
->sae_password_id
) &&
1347 wpa_s
->conf
->sae_pwe
!= 3 &&
1348 wpa_key_mgmt_sae(ssid
->key_mgmt
) &&
1349 (!(ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSNX
)) ||
1351 !(ie
[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E
)))) {
1353 wpa_dbg(wpa_s
, MSG_DEBUG
,
1354 " skip - SAE H2E required, but not supported by the AP");
1357 #endif /* CONFIG_SAE */
1359 #ifndef CONFIG_IBSS_RSN
1360 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1361 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1362 WPA_KEY_MGMT_WPA_NONE
))) {
1364 wpa_dbg(wpa_s
, MSG_DEBUG
,
1365 " skip - IBSS RSN not supported in the build");
1368 #endif /* !CONFIG_IBSS_RSN */
1371 if (ssid
->p2p_group
&&
1372 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1373 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1375 wpa_dbg(wpa_s
, MSG_DEBUG
,
1376 " skip - no P2P IE seen");
1380 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1381 struct wpabuf
*p2p_ie
;
1382 u8 dev_addr
[ETH_ALEN
];
1384 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1387 wpa_dbg(wpa_s
, MSG_DEBUG
,
1388 " skip - no P2P element");
1391 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1392 bss
, P2P_IE_VENDOR_TYPE
);
1393 if (p2p_ie
== NULL
) {
1395 wpa_dbg(wpa_s
, MSG_DEBUG
,
1396 " skip - could not fetch P2P element");
1400 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1401 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1404 wpa_dbg(wpa_s
, MSG_DEBUG
,
1405 " skip - no matching GO P2P Device Address in P2P element");
1406 wpabuf_free(p2p_ie
);
1409 wpabuf_free(p2p_ie
);
1413 * TODO: skip the AP if its P2P IE has Group Formation
1414 * bit set in the P2P Group Capability Bitmap and we
1415 * are not in Group Formation with that device.
1417 #endif /* CONFIG_P2P */
1419 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1421 struct os_reltime diff
;
1423 os_reltime_sub(&wpa_s
->scan_min_time
,
1424 &bss
->last_update
, &diff
);
1426 wpa_dbg(wpa_s
, MSG_DEBUG
,
1427 " skip - scan result not recent enough (%u.%06u seconds too old)",
1428 (unsigned int) diff
.sec
,
1429 (unsigned int) diff
.usec
);
1433 #ifdef CONFIG_TESTING_OPTIONS
1434 if (wpa_s
->ignore_assoc_disallow
)
1435 goto skip_assoc_disallow
;
1436 #endif /* CONFIG_TESTING_OPTIONS */
1437 assoc_disallow
= wpas_mbo_get_bss_attr(
1438 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1439 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1441 wpa_dbg(wpa_s
, MSG_DEBUG
,
1442 " skip - MBO association disallowed (reason %u)",
1447 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
)) {
1449 wpa_dbg(wpa_s
, MSG_DEBUG
,
1450 " skip - AP temporarily disallowed");
1453 #ifdef CONFIG_TESTING_OPTIONS
1454 skip_assoc_disallow
:
1455 #endif /* CONFIG_TESTING_OPTIONS */
1456 #endif /* CONFIG_MBO */
1459 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1460 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1461 (!ssid
->dpp_connector
||
1462 !ssid
->dpp_netaccesskey
||
1463 !ssid
->dpp_csign
)) {
1465 wpa_dbg(wpa_s
, MSG_DEBUG
,
1466 " skip - no PMKSA entry for DPP");
1469 #endif /* CONFIG_DPP */
1471 /* Matching configuration found */
1475 /* No matching configuration found */
1480 static struct wpa_bss
*
1481 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1482 struct wpa_ssid
*group
,
1483 struct wpa_ssid
**selected_ssid
,
1484 int only_first_ssid
)
1488 if (wpa_s
->current_ssid
) {
1489 struct wpa_ssid
*ssid
;
1491 wpa_dbg(wpa_s
, MSG_DEBUG
,
1492 "Scan results matching the currently selected network");
1493 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1494 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1496 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1497 only_first_ssid
, 0);
1498 if (ssid
!= wpa_s
->current_ssid
)
1500 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1501 " freq=%d level=%d snr=%d est_throughput=%u",
1502 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1503 bss
->snr
, bss
->est_throughput
);
1507 if (only_first_ssid
)
1508 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1511 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1514 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1515 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1517 wpa_s
->owe_transition_select
= 1;
1518 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1519 only_first_ssid
, 1);
1520 wpa_s
->owe_transition_select
= 0;
1521 if (!*selected_ssid
)
1523 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected %sBSS " MACSTR
1525 bss
== wpa_s
->current_bss
? "current ": "",
1526 MAC2STR(bss
->bssid
),
1527 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1535 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1536 struct wpa_ssid
**selected_ssid
)
1538 struct wpa_bss
*selected
= NULL
;
1540 struct wpa_ssid
*next_ssid
= NULL
;
1541 struct wpa_ssid
*ssid
;
1543 if (wpa_s
->last_scan_res
== NULL
||
1544 wpa_s
->last_scan_res_used
== 0)
1545 return NULL
; /* no scan results from last update */
1547 if (wpa_s
->next_ssid
) {
1548 /* check that next_ssid is still valid */
1549 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1550 if (ssid
== wpa_s
->next_ssid
)
1554 wpa_s
->next_ssid
= NULL
;
1557 while (selected
== NULL
) {
1558 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1559 if (next_ssid
&& next_ssid
->priority
==
1560 wpa_s
->conf
->pssid
[prio
]->priority
) {
1561 selected
= wpa_supplicant_select_bss(
1562 wpa_s
, next_ssid
, selected_ssid
, 1);
1566 selected
= wpa_supplicant_select_bss(
1567 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1573 if (selected
== NULL
&& wpa_s
->blacklist
&&
1574 !wpa_s
->countermeasures
) {
1575 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1576 "blacklist and try again");
1577 wpa_blacklist_clear(wpa_s
);
1578 wpa_s
->blacklist_cleared
++;
1579 } else if (selected
== NULL
)
1583 ssid
= *selected_ssid
;
1584 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1585 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1586 const char *field_name
, *txt
= NULL
;
1588 wpa_dbg(wpa_s
, MSG_DEBUG
,
1589 "PSK/passphrase not yet available for the selected network");
1591 wpas_notify_network_request(wpa_s
, ssid
,
1592 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1594 field_name
= wpa_supplicant_ctrl_req_to_string(
1595 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1596 if (field_name
== NULL
)
1599 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1608 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1609 int timeout_sec
, int timeout_usec
)
1611 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1613 * No networks are enabled; short-circuit request so
1614 * we don't wait timeout seconds before transitioning
1615 * to INACTIVE state.
1617 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1618 "since there are no enabled networks");
1619 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1623 wpa_s
->scan_for_connection
= 1;
1624 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1628 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1629 struct wpa_bss
*selected
,
1630 struct wpa_ssid
*ssid
)
1632 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1633 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1634 "PBC session overlap");
1635 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1637 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1638 wpa_s
->p2p_in_provisioning
) {
1639 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1643 #endif /* CONFIG_P2P */
1646 wpas_wps_pbc_overlap(wpa_s
);
1647 wpas_wps_cancel(wpa_s
);
1648 #endif /* CONFIG_WPS */
1652 wpa_msg(wpa_s
, MSG_DEBUG
,
1653 "Considering connect request: reassociate: %d selected: "
1654 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1655 " wpa_state: %s ssid=%p current_ssid=%p",
1656 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1657 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1658 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1659 ssid
, wpa_s
->current_ssid
);
1662 * Do not trigger new association unless the BSSID has changed or if
1663 * reassociation is requested. If we are in process of associating with
1664 * the selected BSSID, do not trigger new attempt.
1666 if (wpa_s
->reassociate
||
1667 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1668 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1669 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1670 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1671 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1673 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1674 ssid
!= wpa_s
->current_ssid
)))) {
1675 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1676 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1679 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1680 MAC2STR(selected
->bssid
));
1681 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1683 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1684 "connect with the selected AP");
1691 static struct wpa_ssid
*
1692 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1695 struct wpa_ssid
*ssid
;
1697 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1698 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1700 if (wpas_network_disabled(wpa_s
, ssid
))
1702 #ifndef CONFIG_IBSS_RSN
1703 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1704 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1705 WPA_KEY_MGMT_WPA_NONE
))) {
1706 wpa_msg(wpa_s
, MSG_INFO
,
1707 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1708 wpa_ssid_txt(ssid
->ssid
,
1712 #endif /* !CONFIG_IBSS_RSN */
1713 if (ssid
->mode
== WPAS_MODE_IBSS
||
1714 ssid
->mode
== WPAS_MODE_AP
||
1715 ssid
->mode
== WPAS_MODE_MESH
)
1723 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1724 * on BSS added and BSS changed events */
1725 static void wpa_supplicant_rsn_preauth_scan_results(
1726 struct wpa_supplicant
*wpa_s
)
1728 struct wpa_bss
*bss
;
1730 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1733 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1734 const u8
*ssid
, *rsn
;
1736 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1740 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1744 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1750 #ifndef CONFIG_NO_ROAMING
1752 static int wpas_get_snr_signal_info(u32 frequency
, int avg_signal
, int noise
)
1754 if (noise
== WPA_INVALID_NOISE
)
1755 noise
= IS_5GHZ(frequency
) ? DEFAULT_NOISE_FLOOR_5GHZ
:
1756 DEFAULT_NOISE_FLOOR_2GHZ
;
1757 return avg_signal
- noise
;
1762 wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant
*wpa_s
,
1763 const struct wpa_bss
*bss
, int snr
)
1765 int rate
= wpa_bss_get_max_rate(bss
);
1766 const u8
*ies
= (const void *) (bss
+ 1);
1767 size_t ie_len
= bss
->ie_len
? bss
->ie_len
: bss
->beacon_ie_len
;
1769 return wpas_get_est_tpt(wpa_s
, ies
, ie_len
, rate
, snr
);
1772 #endif /* CONFIG_NO_ROAMING */
1775 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1776 struct wpa_bss
*selected
,
1777 struct wpa_ssid
*ssid
)
1779 struct wpa_bss
*current_bss
= NULL
;
1780 #ifndef CONFIG_NO_ROAMING
1784 unsigned int cur_est
, sel_est
;
1785 struct wpa_signal_info si
;
1787 #endif /* CONFIG_NO_ROAMING */
1789 if (wpa_s
->reassociate
)
1790 return 1; /* explicit request to reassociate */
1791 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1792 return 1; /* we are not associated; continue */
1793 if (wpa_s
->current_ssid
== NULL
)
1794 return 1; /* unknown current SSID */
1795 if (wpa_s
->current_ssid
!= ssid
)
1796 return 1; /* different network block */
1798 if (wpas_driver_bss_selection(wpa_s
))
1799 return 0; /* Driver-based roaming */
1801 if (wpa_s
->current_ssid
->ssid
)
1802 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1803 wpa_s
->current_ssid
->ssid
,
1804 wpa_s
->current_ssid
->ssid_len
);
1806 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1809 return 1; /* current BSS not seen in scan results */
1811 if (current_bss
== selected
)
1814 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1815 return 1; /* current BSS not seen in the last scan */
1817 #ifndef CONFIG_NO_ROAMING
1818 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1819 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1820 " freq=%d level=%d snr=%d est_throughput=%u",
1821 MAC2STR(current_bss
->bssid
),
1822 current_bss
->freq
, current_bss
->level
,
1823 current_bss
->snr
, current_bss
->est_throughput
);
1824 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1825 " freq=%d level=%d snr=%d est_throughput=%u",
1826 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1827 selected
->snr
, selected
->est_throughput
);
1829 if (wpa_s
->current_ssid
->bssid_set
&&
1830 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1832 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1833 "has preferred BSSID");
1837 cur_level
= current_bss
->level
;
1838 cur_est
= current_bss
->est_throughput
;
1839 sel_est
= selected
->est_throughput
;
1842 * Try to poll the signal from the driver since this will allow to get
1843 * more accurate values. In some cases, there can be big differences
1844 * between the RSSI of the Probe Response frames of the AP we are
1845 * associated with and the Beacon frames we hear from the same AP after
1846 * association. This can happen, e.g., when there are two antennas that
1847 * hear the AP very differently. If the driver chooses to hear the
1848 * Probe Response frames during the scan on the "bad" antenna because
1849 * it wants to save power, but knows to choose the other antenna after
1850 * association, we will hear our AP with a low RSSI as part of the
1851 * scan even when we can hear it decently on the other antenna. To cope
1852 * with this, ask the driver to teach us how it hears the AP. Also, the
1853 * scan results may be a bit old, since we can very quickly get fresh
1854 * information about our currently associated AP.
1856 if (wpa_drv_signal_poll(wpa_s
, &si
) == 0 &&
1857 (si
.avg_beacon_signal
|| si
.avg_signal
)) {
1858 cur_level
= si
.avg_beacon_signal
? si
.avg_beacon_signal
:
1860 cur_snr
= wpas_get_snr_signal_info(si
.frequency
, cur_level
,
1863 cur_est
= wpas_get_est_throughput_from_bss_snr(wpa_s
,
1866 wpa_dbg(wpa_s
, MSG_DEBUG
,
1867 "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
1868 cur_level
, cur_snr
, cur_est
);
1871 if (sel_est
> cur_est
+ 5000) {
1872 wpa_dbg(wpa_s
, MSG_DEBUG
,
1873 "Allow reassociation - selected BSS has better estimated throughput");
1877 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1879 if (cur_level
< 0 && cur_level
> selected
->level
+ to_5ghz
* 2 &&
1880 sel_est
< cur_est
* 1.2) {
1881 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1886 if (cur_est
> sel_est
+ 5000) {
1887 wpa_dbg(wpa_s
, MSG_DEBUG
,
1888 "Skip roam - Current BSS has better estimated throughput");
1892 if (cur_snr
> GREAT_SNR
) {
1893 wpa_dbg(wpa_s
, MSG_DEBUG
,
1894 "Skip roam - Current BSS has good SNR (%u > %u)",
1895 cur_snr
, GREAT_SNR
);
1899 if (cur_level
< -85) /* ..-86 dBm */
1901 else if (cur_level
< -80) /* -85..-81 dBm */
1903 else if (cur_level
< -75) /* -80..-76 dBm */
1905 else if (cur_level
< -70) /* -75..-71 dBm */
1907 else if (cur_level
< 0) /* -70..-1 dBm */
1909 else /* unspecified units (not in dBm) */
1912 if (cur_est
> sel_est
* 1.5)
1914 else if (cur_est
> sel_est
* 1.2)
1916 else if (cur_est
> sel_est
* 1.1)
1918 else if (cur_est
> sel_est
)
1920 else if (sel_est
> cur_est
* 1.5)
1922 else if (sel_est
> cur_est
* 1.2)
1924 else if (sel_est
> cur_est
* 1.1)
1926 else if (sel_est
> cur_est
)
1931 diff
= selected
->level
- cur_level
;
1932 if (diff
< min_diff
) {
1933 wpa_dbg(wpa_s
, MSG_DEBUG
,
1934 "Skip roam - too small difference in signal level (%d < %d)",
1939 wpa_dbg(wpa_s
, MSG_DEBUG
,
1940 "Allow reassociation due to difference in signal level (%d >= %d)",
1943 #else /* CONFIG_NO_ROAMING */
1945 #endif /* CONFIG_NO_ROAMING */
1950 * Return a negative value if no scan results could be fetched or if scan
1951 * results should not be shared with other virtual interfaces.
1952 * Return 0 if scan results were fetched and may be shared with other
1954 * Return 1 if scan results may be shared with other virtual interfaces but may
1955 * not trigger any operations.
1956 * Return 2 if the interface was removed and cannot be used.
1958 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1959 union wpa_event_data
*data
,
1960 int own_request
, int update_only
)
1962 struct wpa_scan_results
*scan_res
= NULL
;
1965 #ifndef CONFIG_NO_RANDOM_POOL
1967 #endif /* CONFIG_NO_RANDOM_POOL */
1970 if (wpa_s
->ap_iface
)
1972 #endif /* CONFIG_AP */
1974 wpa_supplicant_notify_scanning(wpa_s
, 0);
1976 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1977 data
? &data
->scan_info
:
1979 if (scan_res
== NULL
) {
1980 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1981 wpa_s
->scan_res_handler
== scan_only_handler
)
1985 if (data
&& data
->scan_info
.external_scan
)
1987 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1989 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1991 goto scan_work_done
;
1994 #ifndef CONFIG_NO_RANDOM_POOL
1995 num
= scan_res
->num
;
1998 for (i
= 0; i
< num
; i
++) {
2000 struct wpa_scan_res
*res
= scan_res
->res
[i
];
2001 buf
[0] = res
->bssid
[5];
2002 buf
[1] = res
->qual
& 0xff;
2003 buf
[2] = res
->noise
& 0xff;
2004 buf
[3] = res
->level
& 0xff;
2005 buf
[4] = res
->tsf
& 0xff;
2006 random_add_randomness(buf
, sizeof(buf
));
2008 #endif /* CONFIG_NO_RANDOM_POOL */
2012 goto scan_work_done
;
2015 if (own_request
&& wpa_s
->scan_res_handler
&&
2016 !(data
&& data
->scan_info
.external_scan
)) {
2017 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
2018 struct wpa_scan_results
*scan_res
);
2020 scan_res_handler
= wpa_s
->scan_res_handler
;
2021 wpa_s
->scan_res_handler
= NULL
;
2022 scan_res_handler(wpa_s
, scan_res
);
2024 goto scan_work_done
;
2028 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
2030 if (wpa_s
->ap_iface
->scan_cb
)
2031 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
2032 #endif /* CONFIG_AP */
2033 goto scan_work_done
;
2036 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
2037 wpa_s
->own_scan_running
,
2038 data
? data
->scan_info
.external_scan
: 0);
2039 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
2040 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
2041 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
2042 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
2043 wpa_s
->manual_scan_id
);
2044 wpa_s
->manual_scan_use_id
= 0;
2046 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
2048 wpas_notify_scan_results(wpa_s
);
2050 wpas_notify_scan_done(wpa_s
, 1);
2052 if (data
&& data
->scan_info
.external_scan
) {
2053 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
2054 wpa_scan_results_free(scan_res
);
2058 if (wnm_scan_process(wpa_s
, 1) > 0)
2059 goto scan_work_done
;
2061 if (sme_proc_obss_scan(wpa_s
, scan_res
) > 0)
2062 goto scan_work_done
;
2064 if (own_request
&& data
&&
2065 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
2066 goto scan_work_done
;
2068 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
2069 goto scan_work_done
;
2071 if (autoscan_notify_scan(wpa_s
, scan_res
))
2072 goto scan_work_done
;
2074 if (wpa_s
->disconnected
) {
2075 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2076 goto scan_work_done
;
2079 if (!wpas_driver_bss_selection(wpa_s
) &&
2080 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
2081 goto scan_work_done
;
2083 wpas_wps_update_ap_info(wpa_s
, scan_res
);
2085 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2086 wpa_s
->wpa_state
< WPA_COMPLETED
)
2087 goto scan_work_done
;
2089 wpa_scan_results_free(scan_res
);
2091 if (own_request
&& wpa_s
->scan_work
) {
2092 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
2093 wpa_s
->scan_work
= NULL
;
2094 radio_work_done(work
);
2097 os_free(wpa_s
->last_scan_freqs
);
2098 wpa_s
->last_scan_freqs
= NULL
;
2099 wpa_s
->num_last_scan_freqs
= 0;
2100 if (own_request
&& data
&&
2101 data
->scan_info
.freqs
&& data
->scan_info
.num_freqs
) {
2102 wpa_s
->last_scan_freqs
= os_malloc(sizeof(int) *
2103 data
->scan_info
.num_freqs
);
2104 if (wpa_s
->last_scan_freqs
) {
2105 os_memcpy(wpa_s
->last_scan_freqs
,
2106 data
->scan_info
.freqs
,
2107 sizeof(int) * data
->scan_info
.num_freqs
);
2108 wpa_s
->num_last_scan_freqs
= data
->scan_info
.num_freqs
;
2112 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
2115 wpa_scan_results_free(scan_res
);
2116 if (own_request
&& wpa_s
->scan_work
) {
2117 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
2118 wpa_s
->scan_work
= NULL
;
2119 radio_work_done(work
);
2125 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
2126 int new_scan
, int own_request
)
2128 struct wpa_bss
*selected
;
2129 struct wpa_ssid
*ssid
= NULL
;
2130 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
2132 if (time_to_reenable
> 0) {
2133 wpa_dbg(wpa_s
, MSG_DEBUG
,
2134 "Postpone network selection by %d seconds since all networks are disabled",
2136 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2137 eloop_register_timeout(time_to_reenable
, 0,
2138 wpas_network_reenabled
, wpa_s
, NULL
);
2142 if (wpa_s
->p2p_mgmt
)
2143 return 0; /* no normal connection on p2p_mgmt interface */
2145 wpa_s
->owe_transition_search
= 0;
2146 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
2150 wpa_msg(wpa_s
, MSG_INFO
,
2151 "Avoiding join because we already joined a mesh group");
2154 #endif /* CONFIG_MESH */
2158 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
2161 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2165 wpa_s
->suitable_network
++;
2167 if (ssid
!= wpa_s
->current_ssid
&&
2168 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2169 wpa_s
->own_disconnect_req
= 1;
2170 wpa_supplicant_deauthenticate(
2171 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2174 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
2175 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
2179 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2181 * Do not allow other virtual radios to trigger operations based
2182 * on these scan results since we do not want them to start
2183 * other associations at the same time.
2187 wpa_s
->no_suitable_network
++;
2188 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
2189 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
2191 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
2192 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
2194 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2195 } else if (own_request
) {
2197 * No SSID found. If SCAN results are as a result of
2198 * own scan request and not due to a scan request on
2199 * another shared interface, try another scan.
2201 int timeout_sec
= wpa_s
->scan_interval
;
2202 int timeout_usec
= 0;
2206 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
2212 if (wpa_s
->p2p_in_provisioning
||
2213 wpa_s
->show_group_started
||
2214 wpa_s
->p2p_in_invitation
) {
2216 * Use shorter wait during P2P Provisioning
2217 * state and during P2P join-a-group operation
2218 * to speed up group formation.
2221 timeout_usec
= 250000;
2222 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2226 #endif /* CONFIG_P2P */
2227 #ifdef CONFIG_INTERWORKING
2228 if (wpa_s
->conf
->auto_interworking
&&
2229 wpa_s
->conf
->interworking
&&
2230 wpa_s
->conf
->cred
) {
2231 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2232 "start ANQP fetch since no matching "
2234 wpa_s
->network_select
= 1;
2235 wpa_s
->auto_network_select
= 1;
2236 interworking_start_fetch_anqp(wpa_s
);
2239 #endif /* CONFIG_INTERWORKING */
2241 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2242 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2244 timeout_usec
= 500000;
2245 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2249 #endif /* CONFIG_WPS */
2251 if (wpa_s
->owe_transition_search
) {
2252 wpa_dbg(wpa_s
, MSG_DEBUG
,
2253 "OWE: Use shorter wait during transition mode search");
2255 timeout_usec
= 500000;
2256 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2260 #endif /* CONFIG_OWE */
2261 if (wpa_supplicant_req_sched_scan(wpa_s
))
2262 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2265 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2266 WPA_EVENT_NETWORK_NOT_FOUND
);
2273 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2274 union wpa_event_data
*data
)
2276 struct wpa_supplicant
*ifs
;
2279 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2282 * Interface may have been removed, so must not dereference
2290 * If no scan results could be fetched, then no need to
2291 * notify those interfaces that did not actually request
2292 * this scan. Similarly, if scan results started a new operation on this
2293 * interface, do not notify other interfaces to avoid concurrent
2294 * operations during a connection attempt.
2300 * Check other interfaces to see if they share the same radio. If
2301 * so, they get updated with this same scan info.
2303 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2306 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2307 "sibling", ifs
->ifname
);
2308 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2318 #endif /* CONFIG_NO_SCAN_PROCESSING */
2321 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2323 #ifdef CONFIG_NO_SCAN_PROCESSING
2325 #else /* CONFIG_NO_SCAN_PROCESSING */
2326 struct os_reltime now
;
2328 wpa_s
->ignore_post_flush_scan_res
= 0;
2330 if (wpa_s
->last_scan_res_used
== 0)
2333 os_get_reltime(&now
);
2334 if (os_reltime_expired(&now
, &wpa_s
->last_scan
,
2335 SCAN_RES_VALID_FOR_CONNECT
)) {
2336 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2340 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2341 #endif /* CONFIG_NO_SCAN_PROCESSING */
2346 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2348 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2350 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2353 if (!wpa_s
->no_keep_alive
) {
2354 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2355 MAC2STR(wpa_s
->bssid
));
2356 /* TODO: could skip this if normal data traffic has been sent */
2357 /* TODO: Consider using some more appropriate data frame for
2360 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2365 if (wpa_s
->sme
.bss_max_idle_period
) {
2367 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2370 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2371 wnm_bss_keep_alive
, wpa_s
, NULL
);
2373 #endif /* CONFIG_SME */
2377 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2378 const u8
*ies
, size_t ies_len
)
2380 struct ieee802_11_elems elems
;
2385 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2389 if (elems
.bss_max_idle_period
) {
2391 wpa_s
->sme
.bss_max_idle_period
=
2392 WPA_GET_LE16(elems
.bss_max_idle_period
);
2393 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2394 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2395 (elems
.bss_max_idle_period
[2] & 0x01) ?
2396 " (protected keep-live required)" : "");
2397 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2398 wpa_s
->sme
.bss_max_idle_period
= 1;
2399 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2400 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2401 /* msec times 1000 */
2402 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2405 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2406 wnm_bss_keep_alive
, wpa_s
,
2410 #endif /* CONFIG_SME */
2413 #endif /* CONFIG_WNM */
2416 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2419 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2420 #endif /* CONFIG_WNM */
2424 #ifdef CONFIG_INTERWORKING
2426 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2431 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2432 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2434 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2441 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2442 const u8
*ies
, size_t ies_len
)
2444 struct ieee802_11_elems elems
;
2449 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2452 if (elems
.qos_map_set
) {
2453 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2454 elems
.qos_map_set_len
);
2458 #endif /* CONFIG_INTERWORKING */
2461 static void multi_ap_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2462 const u8
*ies
, size_t ies_len
)
2464 struct ieee802_11_elems elems
;
2465 const u8
*map_sub_elem
, *pos
;
2468 wpa_s
->multi_ap_ie
= 0;
2471 ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
||
2472 !elems
.multi_ap
|| elems
.multi_ap_len
< 7)
2475 pos
= elems
.multi_ap
+ 4;
2476 len
= elems
.multi_ap_len
- 4;
2478 map_sub_elem
= get_ie(pos
, len
, MULTI_AP_SUB_ELEM_TYPE
);
2479 if (!map_sub_elem
|| map_sub_elem
[1] < 1)
2482 wpa_s
->multi_ap_backhaul
= !!(map_sub_elem
[2] & MULTI_AP_BACKHAUL_BSS
);
2483 wpa_s
->multi_ap_fronthaul
= !!(map_sub_elem
[2] &
2484 MULTI_AP_FRONTHAUL_BSS
);
2485 wpa_s
->multi_ap_ie
= 1;
2489 static void multi_ap_set_4addr_mode(struct wpa_supplicant
*wpa_s
)
2491 if (!wpa_s
->current_ssid
||
2492 !wpa_s
->current_ssid
->multi_ap_backhaul_sta
)
2495 if (!wpa_s
->multi_ap_ie
) {
2496 wpa_printf(MSG_INFO
,
2497 "AP does not include valid Multi-AP element");
2501 if (!wpa_s
->multi_ap_backhaul
) {
2502 if (wpa_s
->multi_ap_fronthaul
&&
2503 wpa_s
->current_ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
2504 wpa_printf(MSG_INFO
,
2505 "WPS active, accepting fronthaul-only BSS");
2506 /* Don't set 4addr mode in this case, so just return */
2509 wpa_printf(MSG_INFO
, "AP doesn't support backhaul BSS");
2513 if (wpa_drv_set_4addr_mode(wpa_s
, 1) < 0) {
2514 wpa_printf(MSG_ERROR
, "Failed to set 4addr mode");
2517 wpa_s
->enabled_4addr_mode
= 1;
2521 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2526 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2527 const u8
*ie
, size_t ie_len
)
2529 struct mb_ies_info mb_ies
;
2531 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2534 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2536 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2541 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2546 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2547 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2548 (unsigned int) len
);
2549 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2550 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2558 if (mb_ies
.nof_ies
> 0) {
2559 wpabuf_free(wpa_s
->received_mb_ies
);
2560 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2566 #endif /* CONFIG_FST */
2569 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2570 union wpa_event_data
*data
)
2572 int l
, len
, found
= 0, found_x
= 0, wpa_found
, rsn_found
;
2574 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2576 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2578 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2579 if (data
->assoc_info
.req_ies
)
2580 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2581 data
->assoc_info
.req_ies_len
);
2582 if (data
->assoc_info
.resp_ies
) {
2583 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2584 data
->assoc_info
.resp_ies_len
);
2586 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2587 data
->assoc_info
.resp_ies_len
);
2588 #endif /* CONFIG_TDLS */
2590 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2591 data
->assoc_info
.resp_ies_len
);
2592 #endif /* CONFIG_WNM */
2593 #ifdef CONFIG_INTERWORKING
2594 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2595 data
->assoc_info
.resp_ies_len
);
2596 #endif /* CONFIG_INTERWORKING */
2597 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2598 get_ie(data
->assoc_info
.resp_ies
,
2599 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2600 wpa_s
->ieee80211ac
= 1;
2602 multi_ap_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2603 data
->assoc_info
.resp_ies_len
);
2605 if (data
->assoc_info
.beacon_ies
)
2606 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2607 data
->assoc_info
.beacon_ies
,
2608 data
->assoc_info
.beacon_ies_len
);
2609 if (data
->assoc_info
.freq
)
2610 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2611 data
->assoc_info
.freq
);
2613 wpa_s
->connection_set
= 0;
2614 if (data
->assoc_info
.req_ies
&& data
->assoc_info
.resp_ies
) {
2615 struct ieee802_11_elems req_elems
, resp_elems
;
2617 if (ieee802_11_parse_elems(data
->assoc_info
.req_ies
,
2618 data
->assoc_info
.req_ies_len
,
2619 &req_elems
, 0) != ParseFailed
&&
2620 ieee802_11_parse_elems(data
->assoc_info
.resp_ies
,
2621 data
->assoc_info
.resp_ies_len
,
2622 &resp_elems
, 0) != ParseFailed
) {
2623 wpa_s
->connection_set
= 1;
2624 wpa_s
->connection_ht
= req_elems
.ht_capabilities
&&
2625 resp_elems
.ht_capabilities
;
2626 /* Do not include subset of VHT on 2.4 GHz vendor
2627 * extension in consideration for reporting VHT
2629 wpa_s
->connection_vht
= req_elems
.vht_capabilities
&&
2630 resp_elems
.vht_capabilities
&&
2631 (!data
->assoc_info
.freq
||
2632 wpas_freq_to_band(data
->assoc_info
.freq
) !=
2634 wpa_s
->connection_he
= req_elems
.he_capabilities
&&
2635 resp_elems
.he_capabilities
;
2639 p
= data
->assoc_info
.req_ies
;
2640 l
= data
->assoc_info
.req_ies_len
;
2642 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2643 while (p
&& l
>= 2) {
2646 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2651 ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2652 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2653 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2654 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2655 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2))) {
2656 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2659 wpa_find_assoc_pmkid(wpa_s
);
2661 if (!found_x
&& p
[0] == WLAN_EID_RSNX
) {
2662 if (wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
, p
, len
))
2669 if (!found
&& data
->assoc_info
.req_ies
)
2670 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2671 if (!found_x
&& data
->assoc_info
.req_ies
)
2672 wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
, NULL
, 0);
2676 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2677 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2678 (!data
->assoc_info
.resp_frame
||
2679 fils_process_assoc_resp(wpa_s
->wpa
,
2680 data
->assoc_info
.resp_frame
,
2681 data
->assoc_info
.resp_frame_len
) < 0)) {
2682 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2685 #endif /* CONFIG_SME */
2687 /* Additional processing for FILS when SME is in driver */
2688 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2689 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2690 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2691 #endif /* CONFIG_FILS */
2694 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2695 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2696 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2697 data
->assoc_info
.resp_ies
,
2698 data
->assoc_info
.resp_ies_len
) < 0)) {
2699 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2702 #endif /* CONFIG_OWE */
2705 wpa_sm_set_dpp_z(wpa_s
->wpa
, NULL
);
2706 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
&& wpa_s
->dpp_pfs
) {
2707 struct ieee802_11_elems elems
;
2709 if (ieee802_11_parse_elems(data
->assoc_info
.resp_ies
,
2710 data
->assoc_info
.resp_ies_len
,
2711 &elems
, 0) == ParseFailed
||
2714 if (dpp_pfs_process(wpa_s
->dpp_pfs
, elems
.owe_dh
,
2715 elems
.owe_dh_len
) < 0) {
2716 wpa_supplicant_deauthenticate(wpa_s
,
2717 WLAN_REASON_UNSPECIFIED
);
2721 wpa_sm_set_dpp_z(wpa_s
->wpa
, wpa_s
->dpp_pfs
->secret
);
2724 #endif /* CONFIG_DPP2 */
2726 #ifdef CONFIG_IEEE80211R
2728 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2729 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2730 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2731 data
->assoc_info
.resp_ies
,
2732 data
->assoc_info
.resp_ies_len
,
2734 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2735 "Reassociation Response failed");
2736 wpa_supplicant_deauthenticate(
2737 wpa_s
, WLAN_REASON_INVALID_IE
);
2742 p
= data
->assoc_info
.resp_ies
;
2743 l
= data
->assoc_info
.resp_ies_len
;
2745 #ifdef CONFIG_WPS_STRICT
2746 if (p
&& wpa_s
->current_ssid
&&
2747 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2749 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2751 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2752 "include WPS IE in (Re)Association Response");
2756 if (wps_validate_assoc_resp(wps
) < 0) {
2758 wpa_supplicant_deauthenticate(
2759 wpa_s
, WLAN_REASON_INVALID_IE
);
2764 #endif /* CONFIG_WPS_STRICT */
2766 /* Go through the IEs and make a copy of the MDIE, if present. */
2767 while (p
&& l
>= 2) {
2770 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2774 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2775 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2776 wpa_s
->sme
.ft_used
= 1;
2777 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2778 MOBILITY_DOMAIN_ID_LEN
);
2784 #endif /* CONFIG_SME */
2786 /* Process FT when SME is in the driver */
2787 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2788 wpa_ft_is_completed(wpa_s
->wpa
)) {
2789 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2790 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2791 data
->assoc_info
.resp_ies
,
2792 data
->assoc_info
.resp_ies_len
,
2794 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2795 "Reassociation Response failed");
2796 wpa_supplicant_deauthenticate(
2797 wpa_s
, WLAN_REASON_INVALID_IE
);
2800 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2803 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2804 data
->assoc_info
.resp_ies_len
);
2805 #endif /* CONFIG_IEEE80211R */
2807 /* WPA/RSN IE from Beacon/ProbeResp */
2808 p
= data
->assoc_info
.beacon_ies
;
2809 l
= data
->assoc_info
.beacon_ies_len
;
2811 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2813 wpa_found
= rsn_found
= 0;
2814 while (p
&& l
>= 2) {
2817 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2822 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2823 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2825 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2829 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2831 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2834 if (p
[0] == WLAN_EID_RSNX
&& p
[1] >= 1)
2835 wpa_sm_set_ap_rsnxe(wpa_s
->wpa
, p
, len
);
2841 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2842 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2843 if (!rsn_found
&& data
->assoc_info
.beacon_ies
) {
2844 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2845 wpa_sm_set_ap_rsnxe(wpa_s
->wpa
, NULL
, 0);
2847 if (wpa_found
|| rsn_found
)
2848 wpa_s
->ap_ies_from_associnfo
= 1;
2850 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2851 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2852 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2854 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2855 wpa_supplicant_update_scan_results(wpa_s
);
2858 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2864 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2866 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
, *bss_rsnx
= NULL
;
2868 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2871 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2874 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2875 WPA_IE_VENDOR_TYPE
);
2876 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2877 bss_rsnx
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSNX
);
2879 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2880 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2881 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2882 bss_rsn
? 2 + bss_rsn
[1] : 0) ||
2883 wpa_sm_set_ap_rsnxe(wpa_s
->wpa
, bss_rsnx
,
2884 bss_rsnx
? 2 + bss_rsnx
[1] : 0))
2891 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2892 union wpa_event_data
*data
)
2895 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2896 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2897 const u8
*ieprb
, *iebcn
;
2899 wpabuf_free(wpa_s
->received_mb_ies
);
2900 wpa_s
->received_mb_ies
= NULL
;
2903 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2904 wpa_printf(MSG_DEBUG
,
2905 "FST: MB IEs updated from Association Response frame");
2910 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2911 wpa_printf(MSG_DEBUG
,
2912 "FST: MB IEs updated from association event Beacon IEs");
2919 ieprb
= (const u8
*) (bss
+ 1);
2920 iebcn
= ieprb
+ bss
->ie_len
;
2922 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2923 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2924 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2925 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2926 #endif /* CONFIG_FST */
2930 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2931 union wpa_event_data
*data
)
2934 int ft_completed
, already_authorized
;
2936 #if defined(CONFIG_FILS) || defined(CONFIG_MBO)
2937 struct wpa_bss
*bss
;
2938 #endif /* CONFIG_FILS || CONFIG_MBO */
2941 if (wpa_s
->ap_iface
) {
2944 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2945 data
->assoc_info
.addr
,
2946 data
->assoc_info
.req_ies
,
2947 data
->assoc_info
.req_ies_len
,
2948 data
->assoc_info
.reassoc
);
2951 #endif /* CONFIG_AP */
2953 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2954 wpa_s
->own_reconnect_req
= 0;
2956 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2957 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2960 * FILS authentication can share the same mechanism to mark the
2961 * connection fully authenticated, so set ft_completed also based on
2965 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2967 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2968 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2969 wpa_supplicant_deauthenticate(
2970 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2974 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2975 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2976 if (os_reltime_initialized(&wpa_s
->session_start
)) {
2977 os_reltime_age(&wpa_s
->session_start
,
2978 &wpa_s
->session_length
);
2979 wpa_s
->session_start
.sec
= 0;
2980 wpa_s
->session_start
.usec
= 0;
2981 wpas_notify_session_length(wpa_s
);
2983 wpas_notify_auth_changed(wpa_s
);
2984 os_get_reltime(&wpa_s
->session_start
);
2986 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2987 MACSTR
, MAC2STR(bssid
));
2989 random_add_randomness(bssid
, ETH_ALEN
);
2990 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2991 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2992 wpas_notify_bssid_changed(wpa_s
);
2994 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2995 wpa_clear_keys(wpa_s
, bssid
);
2997 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2998 wpa_supplicant_deauthenticate(
2999 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3004 multi_ap_set_4addr_mode(wpa_s
);
3006 if (wpa_s
->conf
->ap_scan
== 1 &&
3007 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
3008 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
3009 wpa_msg(wpa_s
, MSG_WARNING
,
3010 "WPA/RSN IEs not updated");
3013 wpas_fst_update_mb_assoc(wpa_s
, data
);
3016 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
3017 wpa_s
->sme
.prev_bssid_set
= 1;
3018 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
3019 #endif /* CONFIG_SME */
3021 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
3022 if (wpa_s
->current_ssid
) {
3023 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
3024 * initialized before association, but for other modes,
3025 * initialize PC/SC here, if the current configuration needs
3026 * smartcard or SIM/USIM. */
3027 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
3029 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
3031 l2_packet_notify_auth_start(wpa_s
->l2
);
3033 already_authorized
= data
&& data
->assoc_info
.authorized
;
3036 * Set portEnabled first to FALSE in order to get EAP state machine out
3037 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
3038 * state machine may transit to AUTHENTICATING state based on obsolete
3039 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
3040 * AUTHENTICATED without ever giving chance to EAP state machine to
3043 if (!ft_completed
&& !already_authorized
) {
3044 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
3045 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
3047 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
3048 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
3049 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
3050 already_authorized
|| wpa_s
->drv_authorized_port
)
3051 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
3052 /* 802.1X::portControl = Auto */
3053 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
3054 wpa_s
->eapol_received
= 0;
3055 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
3056 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
3057 (wpa_s
->current_ssid
&&
3058 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
)) {
3059 if (wpa_s
->current_ssid
&&
3060 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
3062 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
3064 * Set the key after having received joined-IBSS event
3067 wpa_supplicant_set_wpa_none_key(wpa_s
,
3068 wpa_s
->current_ssid
);
3070 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3071 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3072 } else if (!ft_completed
) {
3073 /* Timeout for receiving the first EAPOL packet */
3074 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
3076 wpa_supplicant_cancel_scan(wpa_s
);
3080 * FT protocol completed - make sure EAPOL state machine ends
3081 * up in authenticated.
3083 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3084 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3085 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3086 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3087 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK
) &&
3088 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
3090 * We are done; the driver will take care of RSN 4-way
3093 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3094 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3095 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3096 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3097 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X
) &&
3098 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
3100 * The driver will take care of RSN 4-way handshake, so we need
3101 * to allow EAPOL supplicant to complete its work without
3102 * waiting for WPA supplicant.
3104 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3107 wpa_s
->last_eapol_matches_bssid
= 0;
3109 #ifdef CONFIG_TESTING_OPTIONS
3110 if (wpa_s
->rsne_override_eapol
) {
3111 wpa_printf(MSG_DEBUG
,
3112 "TESTING: RSNE EAPOL-Key msg 2/4 override");
3113 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
,
3114 wpabuf_head(wpa_s
->rsne_override_eapol
),
3115 wpabuf_len(wpa_s
->rsne_override_eapol
));
3117 if (wpa_s
->rsnxe_override_eapol
) {
3118 wpa_printf(MSG_DEBUG
,
3119 "TESTING: RSNXE EAPOL-Key msg 2/4 override");
3120 wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
,
3121 wpabuf_head(wpa_s
->rsnxe_override_eapol
),
3122 wpabuf_len(wpa_s
->rsnxe_override_eapol
));
3124 #endif /* CONFIG_TESTING_OPTIONS */
3126 if (wpa_s
->pending_eapol_rx
) {
3127 struct os_reltime now
, age
;
3128 os_get_reltime(&now
);
3129 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
3130 if (age
.sec
== 0 && age
.usec
< 200000 &&
3131 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
3133 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
3134 "frame that was received just before "
3135 "association notification");
3136 wpa_supplicant_rx_eapol(
3137 wpa_s
, wpa_s
->pending_eapol_rx_src
,
3138 wpabuf_head(wpa_s
->pending_eapol_rx
),
3139 wpabuf_len(wpa_s
->pending_eapol_rx
));
3141 wpabuf_free(wpa_s
->pending_eapol_rx
);
3142 wpa_s
->pending_eapol_rx
= NULL
;
3146 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
3147 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
3148 wpa_s
->current_ssid
&&
3149 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
3150 /* Set static WEP keys again */
3151 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
3153 #endif /* CONFIG_WEP */
3155 #ifdef CONFIG_IBSS_RSN
3156 if (wpa_s
->current_ssid
&&
3157 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
3158 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3159 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
3160 wpa_s
->ibss_rsn
== NULL
) {
3161 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
3162 if (!wpa_s
->ibss_rsn
) {
3163 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
3164 wpa_supplicant_deauthenticate(
3165 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3169 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
3171 #endif /* CONFIG_IBSS_RSN */
3173 wpas_wps_notify_assoc(wpa_s
, bssid
);
3176 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
3177 data
->assoc_info
.resp_ies_len
,
3178 &data
->assoc_info
.wmm_params
);
3180 if (wpa_s
->reassoc_same_bss
)
3181 wmm_ac_restore_tspecs(wpa_s
);
3184 #if defined(CONFIG_FILS) || defined(CONFIG_MBO)
3185 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3186 #endif /* CONFIG_FILS || CONFIG_MBO */
3188 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
3189 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3192 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
3194 #endif /* CONFIG_FILS */
3197 wpas_mbo_check_pmf(wpa_s
, bss
, wpa_s
->current_ssid
);
3198 #endif /* CONFIG_MBO */
3202 static int disconnect_reason_recoverable(u16 reason_code
)
3204 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
3205 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
3206 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
3210 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
3212 int locally_generated
)
3216 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
3218 * At least Host AP driver and a Prism3 card seemed to be
3219 * generating streams of disconnected events when configuring
3220 * IBSS for WPA-None. Ignore them for now.
3225 bssid
= wpa_s
->bssid
;
3226 if (is_zero_ether_addr(bssid
))
3227 bssid
= wpa_s
->pending_bssid
;
3229 if (!is_zero_ether_addr(bssid
) ||
3230 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
3231 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
3233 MAC2STR(bssid
), reason_code
,
3234 locally_generated
? " locally_generated=1" : "");
3239 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
3240 int locally_generated
)
3242 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
3243 !wpa_s
->new_connection
||
3244 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
3245 wpa_key_mgmt_sae(wpa_s
->key_mgmt
))
3246 return 0; /* Not in initial 4-way handshake with PSK */
3249 * It looks like connection was lost while trying to go through PSK
3250 * 4-way handshake. Filter out known disconnection cases that are caused
3251 * by something else than PSK mismatch to avoid confusing reports.
3254 if (locally_generated
) {
3255 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
3263 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
3265 int locally_generated
)
3269 u8 prev_pending_bssid
[ETH_ALEN
];
3270 struct wpa_bss
*fast_reconnect
= NULL
;
3271 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
3272 struct wpa_ssid
*last_ssid
;
3273 struct wpa_bss
*curr
= NULL
;
3275 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
3276 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
3278 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
3280 * At least Host AP driver and a Prism3 card seemed to be
3281 * generating streams of disconnected events when configuring
3282 * IBSS for WPA-None. Ignore them for now.
3284 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
3285 "IBSS/WPA-None mode");
3289 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
3290 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
3293 * Remove the inactive AP (which is probably out of range) from
3294 * the BSS list after marking disassociation. In particular
3295 * mac80211-based drivers use the
3296 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3297 * locally generated disconnection events for cases where the
3298 * AP does not reply anymore.
3300 curr
= wpa_s
->current_bss
;
3302 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
3303 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
3304 "pre-shared key may be incorrect");
3305 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
3306 return; /* P2P group removed */
3307 wpas_auth_failed(wpa_s
, "WRONG_KEY");
3309 wpas_dpp_send_conn_status_result(wpa_s
,
3310 DPP_STATUS_AUTH_FAILURE
);
3311 #endif /* CONFIG_DPP2 */
3313 if (!wpa_s
->disconnected
&&
3314 (!wpa_s
->auto_reconnect_disabled
||
3315 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
3316 wpas_wps_searching(wpa_s
) ||
3317 wpas_wps_reenable_networks_pending(wpa_s
))) {
3318 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
3319 "reconnect (wps=%d/%d wpa_state=%d)",
3320 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
3321 wpas_wps_searching(wpa_s
),
3323 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
3324 wpa_s
->current_ssid
&&
3325 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
3326 (wpa_s
->own_reconnect_req
||
3327 (!locally_generated
&&
3328 disconnect_reason_recoverable(reason_code
)))) {
3330 * It looks like the AP has dropped association with
3331 * us, but could allow us to get back in. This is also
3332 * triggered for cases where local reconnection request
3333 * is used to force reassociation with the same BSS.
3334 * Try to reconnect to the same BSS without a full scan
3335 * to save time for some common cases.
3337 fast_reconnect
= wpa_s
->current_bss
;
3338 fast_reconnect_ssid
= wpa_s
->current_ssid
;
3339 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
) {
3340 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3342 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
3346 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
3347 "try to re-connect");
3348 wpa_s
->reassociate
= 0;
3349 wpa_s
->disconnected
= 1;
3351 wpa_supplicant_cancel_sched_scan(wpa_s
);
3353 bssid
= wpa_s
->bssid
;
3354 if (is_zero_ether_addr(bssid
))
3355 bssid
= wpa_s
->pending_bssid
;
3356 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3357 wpas_connection_failed(wpa_s
, bssid
);
3358 wpa_sm_notify_disassoc(wpa_s
->wpa
);
3359 if (locally_generated
)
3360 wpa_s
->disconnect_reason
= -reason_code
;
3362 wpa_s
->disconnect_reason
= reason_code
;
3363 wpas_notify_disconnect_reason(wpa_s
);
3364 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
3365 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
3366 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
3368 last_ssid
= wpa_s
->current_ssid
;
3369 wpa_supplicant_mark_disassoc(wpa_s
);
3372 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
3374 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
3375 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
3376 wpa_s
->current_ssid
= last_ssid
;
3379 if (fast_reconnect
&&
3380 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
3381 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
3382 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
3383 fast_reconnect
->ssid_len
) &&
3384 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
3385 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
)) {
3386 #ifndef CONFIG_NO_SCAN_PROCESSING
3387 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
3388 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
3389 fast_reconnect_ssid
) < 0) {
3390 /* Recover through full scan */
3391 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3393 #endif /* CONFIG_NO_SCAN_PROCESSING */
3394 } else if (fast_reconnect
) {
3396 * Could not reconnect to the same BSS due to network being
3397 * disabled. Use a new scan to match the alternative behavior
3398 * above, i.e., to continue automatic reconnection attempt in a
3399 * way that enforces disabled network rules.
3401 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3406 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3407 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
3409 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3411 if (!wpa_s
->pending_mic_error_report
)
3414 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3415 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3416 wpa_s
->pending_mic_error_report
= 0;
3418 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3422 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3423 union wpa_event_data
*data
)
3426 struct os_reltime t
;
3428 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3429 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3431 if ((wpa_s
->last_michael_mic_error
.sec
&&
3432 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3433 wpa_s
->pending_mic_error_report
) {
3434 if (wpa_s
->pending_mic_error_report
) {
3436 * Send the pending MIC error report immediately since
3437 * we are going to start countermeasures and AP better
3440 wpa_sm_key_request(wpa_s
->wpa
, 1,
3441 wpa_s
->pending_mic_error_pairwise
);
3444 /* Send the new MIC error report immediately since we are going
3445 * to start countermeasures and AP better do the same.
3447 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3449 /* initialize countermeasures */
3450 wpa_s
->countermeasures
= 1;
3452 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3454 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3457 * Need to wait for completion of request frame. We do not get
3458 * any callback for the message completion, so just wait a
3459 * short while and hope for the best. */
3462 wpa_drv_set_countermeasures(wpa_s
, 1);
3463 wpa_supplicant_deauthenticate(wpa_s
,
3464 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3465 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3467 eloop_register_timeout(60, 0,
3468 wpa_supplicant_stop_countermeasures
,
3470 /* TODO: mark the AP rejected for 60 second. STA is
3471 * allowed to associate with another AP.. */
3473 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3474 if (wpa_s
->mic_errors_seen
) {
3476 * Reduce the effectiveness of Michael MIC error
3477 * reports as a means for attacking against TKIP if
3478 * more than one MIC failure is noticed with the same
3479 * PTK. We delay the transmission of the reports by a
3480 * random time between 0 and 60 seconds in order to
3481 * force the attacker wait 60 seconds before getting
3482 * the information on whether a frame resulted in a MIC
3488 if (os_get_random(rval
, sizeof(rval
)) < 0)
3489 sec
= os_random() % 60;
3491 sec
= WPA_GET_BE32(rval
) % 60;
3492 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3493 "report %d seconds", sec
);
3494 wpa_s
->pending_mic_error_report
= 1;
3495 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3496 eloop_cancel_timeout(
3497 wpa_supplicant_delayed_mic_error_report
,
3499 eloop_register_timeout(
3500 sec
, os_random() % 1000000,
3501 wpa_supplicant_delayed_mic_error_report
,
3504 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3506 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3507 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3508 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3510 wpa_s
->last_michael_mic_error
= t
;
3511 wpa_s
->mic_errors_seen
++;
3515 #ifdef CONFIG_TERMINATE_ONLASTIF
3516 static int any_interfaces(struct wpa_supplicant
*head
)
3518 struct wpa_supplicant
*wpa_s
;
3520 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3521 if (!wpa_s
->interface_removed
)
3525 #endif /* CONFIG_TERMINATE_ONLASTIF */
3529 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3530 union wpa_event_data
*data
)
3532 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3535 switch (data
->interface_status
.ievent
) {
3536 case EVENT_INTERFACE_ADDED
:
3537 if (!wpa_s
->interface_removed
)
3539 wpa_s
->interface_removed
= 0;
3540 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3541 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3542 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3543 "driver after interface was added");
3547 if (!wpa_s
->global
->p2p
&&
3548 !wpa_s
->global
->p2p_disabled
&&
3549 !wpa_s
->conf
->p2p_disabled
&&
3551 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3552 wpas_p2p_add_p2pdev_interface(
3553 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3554 wpa_printf(MSG_INFO
,
3555 "P2P: Failed to enable P2P Device interface");
3556 /* Try to continue without. P2P will be disabled. */
3558 #endif /* CONFIG_P2P */
3561 case EVENT_INTERFACE_REMOVED
:
3562 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3563 wpa_s
->interface_removed
= 1;
3564 wpa_supplicant_mark_disassoc(wpa_s
);
3565 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3566 l2_packet_deinit(wpa_s
->l2
);
3570 if (wpa_s
->global
->p2p
&&
3571 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3573 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3574 wpa_dbg(wpa_s
, MSG_DEBUG
,
3575 "Removing P2P Device interface");
3576 wpa_supplicant_remove_iface(
3577 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3579 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3581 #endif /* CONFIG_P2P */
3583 #ifdef CONFIG_MATCH_IFACE
3584 if (wpa_s
->matched
) {
3585 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3588 #endif /* CONFIG_MATCH_IFACE */
3590 #ifdef CONFIG_TERMINATE_ONLASTIF
3591 /* check if last interface */
3592 if (!any_interfaces(wpa_s
->global
->ifaces
))
3594 #endif /* CONFIG_TERMINATE_ONLASTIF */
3601 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3602 union wpa_event_data
*data
)
3606 switch (data
->tdls
.oper
) {
3607 case TDLS_REQUEST_SETUP
:
3608 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3609 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3610 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3612 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3614 case TDLS_REQUEST_TEARDOWN
:
3615 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3616 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3617 data
->tdls
.reason_code
);
3619 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3622 case TDLS_REQUEST_DISCOVER
:
3623 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3628 #endif /* CONFIG_TDLS */
3632 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3633 union wpa_event_data
*data
)
3637 switch (data
->wnm
.oper
) {
3638 case WNM_OPER_SLEEP
:
3639 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3640 "(action=%d, intval=%d)",
3641 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3642 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3643 data
->wnm
.sleep_intval
, NULL
);
3647 #endif /* CONFIG_WNM */
3650 #ifdef CONFIG_IEEE80211R
3652 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3653 union wpa_event_data
*data
)
3658 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3659 data
->ft_ies
.ies_len
,
3660 data
->ft_ies
.ft_action
,
3661 data
->ft_ies
.target_ap
,
3662 data
->ft_ies
.ric_ies
,
3663 data
->ft_ies
.ric_ies_len
) < 0) {
3664 /* TODO: prevent MLME/driver from trying to associate? */
3667 #endif /* CONFIG_IEEE80211R */
3670 #ifdef CONFIG_IBSS_RSN
3671 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3672 union wpa_event_data
*data
)
3674 struct wpa_ssid
*ssid
;
3675 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3679 ssid
= wpa_s
->current_ssid
;
3682 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3685 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3689 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3690 union wpa_event_data
*data
)
3692 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3697 /* check if the ssid is correctly configured as IBSS/RSN */
3698 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3701 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3702 data
->rx_mgmt
.frame_len
);
3704 #endif /* CONFIG_IBSS_RSN */
3707 #ifdef CONFIG_IEEE80211R
3708 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3711 const u8
*sta_addr
, *target_ap_addr
;
3714 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3715 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3716 return; /* only SME case supported for now */
3717 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3720 return; /* Only FT Action Response is supported for now */
3721 sta_addr
= data
+ 1;
3722 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3723 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3724 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3725 MACSTR
" TargetAP " MACSTR
" status %u",
3726 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3728 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3729 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3730 " in FT Action Response", MAC2STR(sta_addr
));
3735 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3736 "failure (status code %d)", status
);
3737 /* TODO: report error to FT code(?) */
3741 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3742 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3743 target_ap_addr
, NULL
, 0) < 0)
3748 struct wpa_bss
*bss
;
3749 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3751 wpa_s
->sme
.freq
= bss
->freq
;
3752 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3753 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3756 #endif /* CONFIG_SME */
3758 #endif /* CONFIG_IEEE80211R */
3761 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3762 struct unprot_deauth
*e
)
3764 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3765 "dropped: " MACSTR
" -> " MACSTR
3766 " (reason code %u)",
3767 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3768 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3772 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3773 struct unprot_disassoc
*e
)
3775 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3776 "dropped: " MACSTR
" -> " MACSTR
3777 " (reason code %u)",
3778 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3779 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3783 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3784 u16 reason_code
, int locally_generated
,
3785 const u8
*ie
, size_t ie_len
, int deauth
)
3788 if (wpa_s
->ap_iface
&& addr
) {
3789 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3793 if (wpa_s
->ap_iface
) {
3794 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3797 #endif /* CONFIG_AP */
3799 if (!locally_generated
)
3800 wpa_s
->own_disconnect_req
= 0;
3802 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3804 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3805 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3806 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3807 eapol_sm_failed(wpa_s
->eapol
))) &&
3808 !wpa_s
->eap_expected_failure
))
3809 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3812 if (deauth
&& reason_code
> 0) {
3813 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3814 locally_generated
) > 0) {
3816 * The interface was removed, so cannot continue
3817 * processing any additional operations after this.
3822 #endif /* CONFIG_P2P */
3824 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3829 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3830 struct disassoc_info
*info
)
3832 u16 reason_code
= 0;
3833 int locally_generated
= 0;
3834 const u8
*addr
= NULL
;
3835 const u8
*ie
= NULL
;
3838 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3843 ie_len
= info
->ie_len
;
3844 reason_code
= info
->reason_code
;
3845 locally_generated
= info
->locally_generated
;
3846 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u (%s)%s", reason_code
,
3847 reason2str(reason_code
),
3848 locally_generated
? " locally_generated=1" : "");
3850 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3852 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3857 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3858 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3862 if (wpa_s
->ap_iface
) {
3863 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3866 #endif /* CONFIG_AP */
3870 wpas_p2p_disassoc_notif(
3871 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3874 #endif /* CONFIG_P2P */
3876 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3877 sme_event_disassoc(wpa_s
, info
);
3879 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3884 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3885 struct deauth_info
*info
)
3887 u16 reason_code
= 0;
3888 int locally_generated
= 0;
3889 const u8
*addr
= NULL
;
3890 const u8
*ie
= NULL
;
3893 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3898 ie_len
= info
->ie_len
;
3899 reason_code
= info
->reason_code
;
3900 locally_generated
= info
->locally_generated
;
3901 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u (%s)%s",
3902 reason_code
, reason2str(reason_code
),
3903 locally_generated
? " locally_generated=1" : "");
3905 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3908 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3912 wpa_reset_ft_completed(wpa_s
->wpa
);
3914 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3915 locally_generated
, ie
, ie_len
, 1);
3919 static const char * reg_init_str(enum reg_change_initiator init
)
3922 case REGDOM_SET_BY_CORE
:
3924 case REGDOM_SET_BY_USER
:
3926 case REGDOM_SET_BY_DRIVER
:
3928 case REGDOM_SET_BY_COUNTRY_IE
:
3929 return "COUNTRY_IE";
3930 case REGDOM_BEACON_HINT
:
3931 return "BEACON_HINT";
3937 static const char * reg_type_str(enum reg_type type
)
3940 case REGDOM_TYPE_UNKNOWN
:
3942 case REGDOM_TYPE_COUNTRY
:
3944 case REGDOM_TYPE_WORLD
:
3946 case REGDOM_TYPE_CUSTOM_WORLD
:
3947 return "CUSTOM_WORLD";
3948 case REGDOM_TYPE_INTERSECTION
:
3949 return "INTERSECTION";
3955 void wpa_supplicant_update_channel_list(struct wpa_supplicant
*wpa_s
,
3956 struct channel_list_changed
*info
)
3958 struct wpa_supplicant
*ifs
;
3962 * To allow backwards compatibility with higher level layers that
3963 * assumed the REGDOM_CHANGE event is sent over the initially added
3964 * interface. Find the highest parent of this interface and use it to
3967 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3971 wpa_msg(ifs
, MSG_INFO
,
3972 WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3973 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3974 info
->alpha2
[0] ? " alpha2=" : "",
3975 info
->alpha2
[0] ? info
->alpha2
: "");
3978 if (wpa_s
->drv_priv
== NULL
)
3979 return; /* Ignore event during drv initialization */
3981 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3983 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3985 free_hw_features(ifs
);
3986 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3987 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3989 /* Restart PNO/sched_scan with updated channel list */
3992 wpas_start_pno(ifs
);
3993 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3994 wpa_dbg(ifs
, MSG_DEBUG
,
3995 "Channel list changed - restart sched_scan");
3996 wpas_scan_restart_sched_scan(ifs
);
4000 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
4004 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
4005 const u8
*frame
, size_t len
, int freq
,
4008 const struct ieee80211_mgmt
*mgmt
;
4013 if (len
< IEEE80211_HDRLEN
+ 2)
4016 mgmt
= (const struct ieee80211_mgmt
*) frame
;
4017 payload
= frame
+ IEEE80211_HDRLEN
;
4018 category
= *payload
++;
4019 plen
= len
- IEEE80211_HDRLEN
- 1;
4021 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
4022 " Category=%u DataLen=%d freq=%d MHz",
4023 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
4025 if (category
== WLAN_ACTION_WMM
) {
4026 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
4030 #ifdef CONFIG_IEEE80211R
4031 if (category
== WLAN_ACTION_FT
) {
4032 ft_rx_action(wpa_s
, payload
, plen
);
4035 #endif /* CONFIG_IEEE80211R */
4038 if (category
== WLAN_ACTION_SA_QUERY
) {
4039 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
4042 #endif /* CONFIG_SME */
4045 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
4046 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
4049 #endif /* CONFIG_WNM */
4052 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
4053 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
4054 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
4055 mgmt
->u
.action
.category
,
4056 payload
, plen
, freq
) == 0)
4058 #endif /* CONFIG_GAS */
4060 #ifdef CONFIG_GAS_SERVER
4061 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
4062 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
4063 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
4064 mgmt
->u
.action
.category
,
4065 payload
, plen
, freq
) == 0)
4067 #endif /* CONFIG_GAS_SERVER */
4070 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
4071 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
4072 wpa_dbg(wpa_s
, MSG_DEBUG
,
4073 "TDLS: Received Discovery Response from " MACSTR
,
4077 #endif /* CONFIG_TDLS */
4079 #ifdef CONFIG_INTERWORKING
4080 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
4081 payload
[0] == QOS_QOS_MAP_CONFIG
) {
4082 const u8
*pos
= payload
+ 1;
4083 size_t qlen
= plen
- 1;
4084 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
4085 MACSTR
, MAC2STR(mgmt
->sa
));
4086 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
4087 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
4088 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
4089 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
4092 #endif /* CONFIG_INTERWORKING */
4094 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4095 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
4096 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
4103 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4104 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
4105 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
4109 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
4110 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
4111 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
4112 payload
+ 1, plen
- 1,
4118 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
4119 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
4122 #endif /* CONFIG_FST */
4125 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
4126 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
4127 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
4128 payload
[4] == DPP_OUI_TYPE
) {
4131 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
4134 #endif /* CONFIG_DPP */
4136 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
4137 category
, payload
, plen
, freq
);
4139 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
4143 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
4144 union wpa_event_data
*event
)
4146 struct wpa_freq_range_list
*list
;
4149 list
= &event
->freq_range
;
4152 str
= freq_range_list_str(list
);
4153 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
4157 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
4158 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
4161 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
4164 * The update channel flow will also take care of moving a GO
4165 * from the unsafe frequency if needed.
4167 wpas_p2p_update_channel_list(wpa_s
,
4168 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
4170 #endif /* CONFIG_P2P */
4176 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
4178 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
4179 wpa_supplicant_cancel_auth_timeout(wpa_s
);
4180 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
4181 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
4182 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
4183 wpa_s
->drv_authorized_port
= 1;
4188 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
4194 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4195 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
4197 for (j
= 0; j
< mode
->num_channels
; j
++) {
4198 const struct hostapd_channel_data
*chan
;
4200 chan
= &mode
->channels
[j
];
4201 if (chan
->freq
== freq
)
4202 return chan
->dfs_cac_ms
;
4210 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
4211 struct dfs_event
*radar
)
4213 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4214 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
4215 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
4217 #endif /* NEED_AP_MLME && CONFIG_AP */
4219 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
4221 cac_time
/= 1000; /* convert from ms to sec */
4223 cac_time
= 10 * 60; /* max timeout: 10 minutes */
4225 /* Restart auth timeout: CAC time added to initial timeout */
4226 wpas_auth_timeout_restart(wpa_s
, cac_time
);
4231 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
4232 struct dfs_event
*radar
)
4234 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4235 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
4236 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
4238 #endif /* NEED_AP_MLME && CONFIG_AP */
4240 /* Restart auth timeout with original value after CAC is
4242 wpas_auth_timeout_restart(wpa_s
, 0);
4247 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
4248 struct dfs_event
*radar
)
4250 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4251 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
4252 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
4254 #endif /* NEED_AP_MLME && CONFIG_AP */
4256 /* Restart auth timeout with original value after CAC is
4258 wpas_auth_timeout_restart(wpa_s
, 0);
4263 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
4264 union wpa_event_data
*data
)
4266 wpa_dbg(wpa_s
, MSG_DEBUG
,
4267 "Connection authorized by device, previous state %d",
4270 wpa_supplicant_event_port_authorized(wpa_s
);
4272 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
4273 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
4274 data
->assoc_info
.ptk_kck_len
,
4275 data
->assoc_info
.ptk_kek
,
4276 data
->assoc_info
.ptk_kek_len
);
4278 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4279 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
4280 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
4282 /* Update ERP next sequence number */
4283 eapol_sm_update_erp_next_seq_num(
4284 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
4286 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
4287 /* Add the new PMK and PMKID to the PMKSA cache */
4288 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
4289 data
->assoc_info
.fils_pmk
,
4290 data
->assoc_info
.fils_pmk_len
,
4291 data
->assoc_info
.fils_pmkid
,
4292 wpa_s
->bssid
, fils_cache_id
);
4293 } else if (data
->assoc_info
.fils_pmkid
) {
4294 /* Update the current PMKSA used for this connection */
4295 pmksa_cache_set_current(wpa_s
->wpa
,
4296 data
->assoc_info
.fils_pmkid
,
4297 NULL
, NULL
, 0, NULL
, 0);
4300 #endif /* CONFIG_FILS */
4304 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
4305 union wpa_event_data
*data
)
4307 const u8
*bssid
= data
->assoc_reject
.bssid
;
4309 struct wpa_bss
*reject_bss
;
4310 #endif /* CONFIG_MBO */
4312 if (!bssid
|| is_zero_ether_addr(bssid
))
4313 bssid
= wpa_s
->pending_bssid
;
4315 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4316 reject_bss
= wpa_s
->current_bss
;
4318 reject_bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4319 #endif /* CONFIG_MBO */
4321 if (data
->assoc_reject
.bssid
)
4322 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
4323 "bssid=" MACSTR
" status_code=%u%s%s%s",
4324 MAC2STR(data
->assoc_reject
.bssid
),
4325 data
->assoc_reject
.status_code
,
4326 data
->assoc_reject
.timed_out
? " timeout" : "",
4327 data
->assoc_reject
.timeout_reason
? "=" : "",
4328 data
->assoc_reject
.timeout_reason
?
4329 data
->assoc_reject
.timeout_reason
: "");
4331 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
4332 "status_code=%u%s%s%s",
4333 data
->assoc_reject
.status_code
,
4334 data
->assoc_reject
.timed_out
? " timeout" : "",
4335 data
->assoc_reject
.timeout_reason
? "=" : "",
4336 data
->assoc_reject
.timeout_reason
?
4337 data
->assoc_reject
.timeout_reason
: "");
4338 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
4339 wpas_notify_assoc_status_code(wpa_s
);
4342 if (data
->assoc_reject
.status_code
==
4343 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
4344 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
4345 wpa_s
->current_ssid
&&
4346 wpa_s
->current_ssid
->owe_group
== 0 &&
4347 wpa_s
->last_owe_group
!= 21) {
4348 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4349 struct wpa_bss
*bss
= wpa_s
->current_bss
;
4352 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
4354 wpas_connection_failed(wpa_s
, bssid
);
4355 wpa_supplicant_mark_disassoc(wpa_s
);
4359 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
4360 wpas_connect_work_done(wpa_s
);
4361 wpa_supplicant_mark_disassoc(wpa_s
);
4362 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4365 #endif /* CONFIG_OWE */
4368 if (data
->assoc_reject
.status_code
==
4369 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
4370 reject_bss
&& data
->assoc_reject
.resp_ies
) {
4373 rssi_rej
= mbo_get_attr_from_ies(
4374 data
->assoc_reject
.resp_ies
,
4375 data
->assoc_reject
.resp_ies_len
,
4376 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT
);
4377 if (rssi_rej
&& rssi_rej
[1] == 2) {
4378 wpa_printf(MSG_DEBUG
,
4379 "OCE: RSSI-based association rejection from "
4380 MACSTR
" (Delta RSSI: %u, Retry Delay: %u)",
4381 MAC2STR(reject_bss
->bssid
),
4382 rssi_rej
[2], rssi_rej
[3]);
4383 wpa_bss_tmp_disallow(wpa_s
,
4386 rssi_rej
[2] + reject_bss
->level
);
4389 #endif /* CONFIG_MBO */
4391 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
4392 sme_event_assoc_reject(wpa_s
, data
);
4396 /* Driver-based SME cases */
4399 if (wpa_s
->current_ssid
&&
4400 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
4401 !data
->assoc_reject
.timed_out
) {
4402 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
4403 wpa_sm_aborted_cached(wpa_s
->wpa
);
4404 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4406 #endif /* CONFIG_SAE */
4409 if (wpa_s
->current_ssid
&&
4410 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_DPP
&&
4411 !data
->assoc_reject
.timed_out
) {
4412 wpa_dbg(wpa_s
, MSG_DEBUG
, "DPP: Drop PMKSA cache entry");
4413 wpa_sm_aborted_cached(wpa_s
->wpa
);
4414 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4416 #endif /* CONFIG_DPP */
4419 /* Update ERP next sequence number */
4420 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4421 eapol_sm_update_erp_next_seq_num(
4423 data
->assoc_reject
.fils_erp_next_seq_num
);
4424 fils_connection_failure(wpa_s
);
4426 #endif /* CONFIG_FILS */
4428 wpas_connection_failed(wpa_s
, bssid
);
4429 wpa_supplicant_mark_disassoc(wpa_s
);
4433 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
4434 union wpa_event_data
*data
)
4436 struct wpa_supplicant
*wpa_s
= ctx
;
4438 struct os_reltime age
, clear_at
;
4439 #ifndef CONFIG_NO_STDOUT_DEBUG
4440 int level
= MSG_DEBUG
;
4441 #endif /* CONFIG_NO_STDOUT_DEBUG */
4443 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
4444 event
!= EVENT_INTERFACE_ENABLED
&&
4445 event
!= EVENT_INTERFACE_STATUS
&&
4446 event
!= EVENT_SCAN_RESULTS
&&
4447 event
!= EVENT_SCHED_SCAN_STOPPED
) {
4448 wpa_dbg(wpa_s
, MSG_DEBUG
,
4449 "Ignore event %s (%d) while interface is disabled",
4450 event_to_string(event
), event
);
4454 #ifndef CONFIG_NO_STDOUT_DEBUG
4455 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
4456 const struct ieee80211_hdr
*hdr
;
4458 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4459 fc
= le_to_host16(hdr
->frame_control
);
4460 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4461 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4462 level
= MSG_EXCESSIVE
;
4465 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4466 event_to_string(event
), event
);
4467 #endif /* CONFIG_NO_STDOUT_DEBUG */
4472 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4473 data
->auth
.ies_len
))
4474 wpa_printf(MSG_DEBUG
,
4475 "FST: MB IEs updated from auth IE");
4476 #endif /* CONFIG_FST */
4477 sme_event_auth(wpa_s
, data
);
4478 wpa_s
->auth_status_code
= data
->auth
.status_code
;
4479 wpas_notify_auth_status_code(wpa_s
);
4482 #ifdef CONFIG_TESTING_OPTIONS
4483 if (wpa_s
->ignore_auth_resp
) {
4484 wpa_printf(MSG_INFO
,
4485 "EVENT_ASSOC - ignore_auth_resp active!");
4488 if (wpa_s
->testing_resend_assoc
) {
4489 wpa_printf(MSG_INFO
,
4490 "EVENT_DEAUTH - testing_resend_assoc");
4493 #endif /* CONFIG_TESTING_OPTIONS */
4494 wpa_supplicant_event_assoc(wpa_s
, data
);
4495 wpa_s
->assoc_status_code
= WLAN_STATUS_SUCCESS
;
4497 (data
->assoc_info
.authorized
||
4498 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4499 wpa_fils_is_completed(wpa_s
->wpa
))))
4500 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4502 wpa_msg(wpa_s
, MSG_INFO
,
4503 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4504 data
->assoc_info
.subnet_status
);
4507 case EVENT_DISASSOC
:
4508 wpas_event_disassoc(wpa_s
,
4509 data
? &data
->disassoc_info
: NULL
);
4512 #ifdef CONFIG_TESTING_OPTIONS
4513 if (wpa_s
->ignore_auth_resp
) {
4514 wpa_printf(MSG_INFO
,
4515 "EVENT_DEAUTH - ignore_auth_resp active!");
4518 if (wpa_s
->testing_resend_assoc
) {
4519 wpa_printf(MSG_INFO
,
4520 "EVENT_DEAUTH - testing_resend_assoc");
4523 #endif /* CONFIG_TESTING_OPTIONS */
4524 wpas_event_deauth(wpa_s
,
4525 data
? &data
->deauth_info
: NULL
);
4527 case EVENT_MICHAEL_MIC_FAILURE
:
4528 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4530 #ifndef CONFIG_NO_SCAN_PROCESSING
4531 case EVENT_SCAN_STARTED
:
4532 if (wpa_s
->own_scan_requested
||
4533 (data
&& !data
->scan_info
.external_scan
)) {
4534 struct os_reltime diff
;
4536 os_get_reltime(&wpa_s
->scan_start_time
);
4537 os_reltime_sub(&wpa_s
->scan_start_time
,
4538 &wpa_s
->scan_trigger_time
, &diff
);
4539 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4540 diff
.sec
, diff
.usec
);
4541 wpa_s
->own_scan_requested
= 0;
4542 wpa_s
->own_scan_running
= 1;
4543 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4544 wpa_s
->manual_scan_use_id
) {
4545 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4546 WPA_EVENT_SCAN_STARTED
"id=%u",
4547 wpa_s
->manual_scan_id
);
4549 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4550 WPA_EVENT_SCAN_STARTED
);
4553 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4554 wpa_s
->radio
->external_scan_running
= 1;
4555 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4558 case EVENT_SCAN_RESULTS
:
4559 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4560 wpa_s
->scan_res_handler
= NULL
;
4561 wpa_s
->own_scan_running
= 0;
4562 wpa_s
->radio
->external_scan_running
= 0;
4563 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4567 if (!(data
&& data
->scan_info
.external_scan
) &&
4568 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4569 struct os_reltime now
, diff
;
4570 os_get_reltime(&now
);
4571 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4572 wpa_s
->scan_start_time
.sec
= 0;
4573 wpa_s
->scan_start_time
.usec
= 0;
4574 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4575 diff
.sec
, diff
.usec
);
4577 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4578 break; /* interface may have been removed */
4579 if (!(data
&& data
->scan_info
.external_scan
))
4580 wpa_s
->own_scan_running
= 0;
4581 if (data
&& data
->scan_info
.nl_scan_event
)
4582 wpa_s
->radio
->external_scan_running
= 0;
4583 radio_work_check_next(wpa_s
);
4585 #endif /* CONFIG_NO_SCAN_PROCESSING */
4586 case EVENT_ASSOCINFO
:
4587 wpa_supplicant_event_associnfo(wpa_s
, data
);
4589 case EVENT_INTERFACE_STATUS
:
4590 wpa_supplicant_event_interface_status(wpa_s
, data
);
4592 case EVENT_PMKID_CANDIDATE
:
4593 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4597 wpa_supplicant_event_tdls(wpa_s
, data
);
4599 #endif /* CONFIG_TDLS */
4602 wpa_supplicant_event_wnm(wpa_s
, data
);
4604 #endif /* CONFIG_WNM */
4605 #ifdef CONFIG_IEEE80211R
4606 case EVENT_FT_RESPONSE
:
4607 wpa_supplicant_event_ft_response(wpa_s
, data
);
4609 #endif /* CONFIG_IEEE80211R */
4610 #ifdef CONFIG_IBSS_RSN
4611 case EVENT_IBSS_RSN_START
:
4612 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4614 #endif /* CONFIG_IBSS_RSN */
4615 case EVENT_ASSOC_REJECT
:
4616 wpas_event_assoc_reject(wpa_s
, data
);
4618 case EVENT_AUTH_TIMED_OUT
:
4619 /* It is possible to get this event from earlier connection */
4620 if (wpa_s
->current_ssid
&&
4621 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4622 wpa_dbg(wpa_s
, MSG_DEBUG
,
4623 "Ignore AUTH_TIMED_OUT in mesh configuration");
4626 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4627 sme_event_auth_timed_out(wpa_s
, data
);
4629 case EVENT_ASSOC_TIMED_OUT
:
4630 /* It is possible to get this event from earlier connection */
4631 if (wpa_s
->current_ssid
&&
4632 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4633 wpa_dbg(wpa_s
, MSG_DEBUG
,
4634 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4637 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4638 sme_event_assoc_timed_out(wpa_s
, data
);
4640 case EVENT_TX_STATUS
:
4641 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4642 " type=%d stype=%d",
4643 MAC2STR(data
->tx_status
.dst
),
4644 data
->tx_status
.type
, data
->tx_status
.stype
);
4646 if (wpa_s
->ap_iface
== NULL
) {
4647 #ifdef CONFIG_OFFCHANNEL
4648 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4649 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4650 offchannel_send_action_tx_status(
4651 wpa_s
, data
->tx_status
.dst
,
4652 data
->tx_status
.data
,
4653 data
->tx_status
.data_len
,
4654 data
->tx_status
.ack
?
4655 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4656 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4657 #endif /* CONFIG_OFFCHANNEL */
4660 #endif /* CONFIG_AP */
4661 #ifdef CONFIG_OFFCHANNEL
4662 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4663 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4665 * Catch TX status events for Action frames we sent via group
4666 * interface in GO mode, or via standalone AP interface.
4667 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4668 * except when the primary interface is used as a GO interface
4669 * (for drivers which do not have group interface concurrency)
4671 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4672 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4673 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4674 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4675 offchannel_send_action_tx_status(
4676 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4677 data
->tx_status
.data
,
4678 data
->tx_status
.data_len
,
4679 data
->tx_status
.ack
?
4680 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4681 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4684 #endif /* CONFIG_OFFCHANNEL */
4686 switch (data
->tx_status
.type
) {
4687 case WLAN_FC_TYPE_MGMT
:
4688 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4689 data
->tx_status
.data_len
,
4690 data
->tx_status
.stype
,
4691 data
->tx_status
.ack
);
4693 case WLAN_FC_TYPE_DATA
:
4694 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4695 data
->tx_status
.data
,
4696 data
->tx_status
.data_len
,
4697 data
->tx_status
.ack
);
4700 #endif /* CONFIG_AP */
4703 case EVENT_EAPOL_TX_STATUS
:
4704 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4705 data
->eapol_tx_status
.data
,
4706 data
->eapol_tx_status
.data_len
,
4707 data
->eapol_tx_status
.ack
);
4709 case EVENT_DRIVER_CLIENT_POLL_OK
:
4710 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4712 case EVENT_RX_FROM_UNKNOWN
:
4713 if (wpa_s
->ap_iface
== NULL
)
4715 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4716 data
->rx_from_unknown
.wds
);
4718 #endif /* CONFIG_AP */
4720 case EVENT_CH_SWITCH_STARTED
:
4721 case EVENT_CH_SWITCH
:
4722 if (!data
|| !wpa_s
->current_ssid
)
4725 wpa_msg(wpa_s
, MSG_INFO
,
4726 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4727 event
== EVENT_CH_SWITCH
? WPA_EVENT_CHANNEL_SWITCH
:
4728 WPA_EVENT_CHANNEL_SWITCH_STARTED
,
4729 data
->ch_switch
.freq
,
4730 data
->ch_switch
.ht_enabled
,
4731 data
->ch_switch
.ch_offset
,
4732 channel_width_to_string(data
->ch_switch
.ch_width
),
4733 data
->ch_switch
.cf1
,
4734 data
->ch_switch
.cf2
);
4735 if (event
== EVENT_CH_SWITCH_STARTED
)
4738 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4739 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4742 switch (data
->ch_switch
.ch_offset
) {
4744 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
4747 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
4750 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
4753 #endif /* CONFIG_SME */
4756 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4757 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4758 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
||
4759 wpa_s
->current_ssid
->mode
==
4760 WPAS_MODE_P2P_GROUP_FORMATION
) {
4761 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4762 data
->ch_switch
.ht_enabled
,
4763 data
->ch_switch
.ch_offset
,
4764 data
->ch_switch
.ch_width
,
4765 data
->ch_switch
.cf1
,
4766 data
->ch_switch
.cf2
,
4769 #endif /* CONFIG_AP */
4771 sme_event_ch_switch(wpa_s
);
4772 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4773 wnm_clear_coloc_intf_reporting(wpa_s
);
4777 case EVENT_DFS_RADAR_DETECTED
:
4779 wpas_ap_event_dfs_radar_detected(wpa_s
,
4782 case EVENT_DFS_NOP_FINISHED
:
4784 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4787 #endif /* NEED_AP_MLME */
4788 #endif /* CONFIG_AP */
4789 case EVENT_DFS_CAC_STARTED
:
4791 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4793 case EVENT_DFS_CAC_FINISHED
:
4795 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4797 case EVENT_DFS_CAC_ABORTED
:
4799 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4801 case EVENT_RX_MGMT
: {
4803 const struct ieee80211_mgmt
*mgmt
;
4805 #ifdef CONFIG_TESTING_OPTIONS
4806 if (wpa_s
->ext_mgmt_frame_handling
) {
4807 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4808 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4809 char *hex
= os_malloc(hex_len
);
4811 wpa_snprintf_hex(hex
, hex_len
,
4812 rx
->frame
, rx
->frame_len
);
4813 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4814 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4820 #endif /* CONFIG_TESTING_OPTIONS */
4822 mgmt
= (const struct ieee80211_mgmt
*)
4823 data
->rx_mgmt
.frame
;
4824 fc
= le_to_host16(mgmt
->frame_control
);
4825 stype
= WLAN_FC_GET_STYPE(fc
);
4828 if (wpa_s
->ap_iface
== NULL
) {
4829 #endif /* CONFIG_AP */
4831 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4832 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4833 const u8
*src
= mgmt
->sa
;
4837 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4838 ie_len
= data
->rx_mgmt
.frame_len
-
4840 wpas_p2p_probe_req_rx(
4841 wpa_s
, src
, mgmt
->da
,
4842 mgmt
->bssid
, ie
, ie_len
,
4844 data
->rx_mgmt
.ssi_signal
);
4847 #endif /* CONFIG_P2P */
4848 #ifdef CONFIG_IBSS_RSN
4849 if (wpa_s
->current_ssid
&&
4850 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4851 stype
== WLAN_FC_STYPE_AUTH
&&
4852 data
->rx_mgmt
.frame_len
>= 30) {
4853 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4856 #endif /* CONFIG_IBSS_RSN */
4858 if (stype
== WLAN_FC_STYPE_ACTION
) {
4859 wpas_event_rx_mgmt_action(
4860 wpa_s
, data
->rx_mgmt
.frame
,
4861 data
->rx_mgmt
.frame_len
,
4863 data
->rx_mgmt
.ssi_signal
);
4868 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4873 if (stype
== WLAN_FC_STYPE_AUTH
&&
4874 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4875 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4876 sme_external_auth_mgmt_rx(
4877 wpa_s
, data
->rx_mgmt
.frame
,
4878 data
->rx_mgmt
.frame_len
);
4881 #endif /* CONFIG_SAE */
4882 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4883 "management frame in non-AP mode");
4888 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4889 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4893 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4894 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4896 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4897 mgmt
->bssid
, ie
, ie_len
,
4898 data
->rx_mgmt
.ssi_signal
);
4901 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4902 #endif /* CONFIG_AP */
4905 case EVENT_RX_PROBE_REQ
:
4906 if (data
->rx_probe_req
.sa
== NULL
||
4907 data
->rx_probe_req
.ie
== NULL
)
4910 if (wpa_s
->ap_iface
) {
4911 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4912 data
->rx_probe_req
.sa
,
4913 data
->rx_probe_req
.da
,
4914 data
->rx_probe_req
.bssid
,
4915 data
->rx_probe_req
.ie
,
4916 data
->rx_probe_req
.ie_len
,
4917 data
->rx_probe_req
.ssi_signal
);
4920 #endif /* CONFIG_AP */
4921 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4922 data
->rx_probe_req
.da
,
4923 data
->rx_probe_req
.bssid
,
4924 data
->rx_probe_req
.ie
,
4925 data
->rx_probe_req
.ie_len
,
4927 data
->rx_probe_req
.ssi_signal
);
4929 case EVENT_REMAIN_ON_CHANNEL
:
4930 #ifdef CONFIG_OFFCHANNEL
4931 offchannel_remain_on_channel_cb(
4932 wpa_s
, data
->remain_on_channel
.freq
,
4933 data
->remain_on_channel
.duration
);
4934 #endif /* CONFIG_OFFCHANNEL */
4935 wpas_p2p_remain_on_channel_cb(
4936 wpa_s
, data
->remain_on_channel
.freq
,
4937 data
->remain_on_channel
.duration
);
4939 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4940 #ifdef CONFIG_OFFCHANNEL
4941 offchannel_cancel_remain_on_channel_cb(
4942 wpa_s
, data
->remain_on_channel
.freq
);
4943 #endif /* CONFIG_OFFCHANNEL */
4944 wpas_p2p_cancel_remain_on_channel_cb(
4945 wpa_s
, data
->remain_on_channel
.freq
);
4947 wpas_dpp_cancel_remain_on_channel_cb(
4948 wpa_s
, data
->remain_on_channel
.freq
);
4949 #endif /* CONFIG_DPP */
4951 case EVENT_EAPOL_RX
:
4952 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4953 data
->eapol_rx
.data
,
4954 data
->eapol_rx
.data_len
);
4956 case EVENT_SIGNAL_CHANGE
:
4957 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4958 "above=%d signal=%d noise=%d txrate=%d",
4959 data
->signal_change
.above_threshold
,
4960 data
->signal_change
.current_signal
,
4961 data
->signal_change
.current_noise
,
4962 data
->signal_change
.current_txrate
);
4963 wpa_bss_update_level(wpa_s
->current_bss
,
4964 data
->signal_change
.current_signal
);
4965 bgscan_notify_signal_change(
4966 wpa_s
, data
->signal_change
.above_threshold
,
4967 data
->signal_change
.current_signal
,
4968 data
->signal_change
.current_noise
,
4969 data
->signal_change
.current_txrate
);
4971 case EVENT_INTERFACE_MAC_CHANGED
:
4972 wpa_supplicant_update_mac_addr(wpa_s
);
4974 case EVENT_INTERFACE_ENABLED
:
4975 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4976 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4977 eloop_cancel_timeout(wpas_clear_disabled_interface
,
4979 wpa_supplicant_update_mac_addr(wpa_s
);
4980 wpa_supplicant_set_default_scan_ies(wpa_s
);
4981 if (wpa_s
->p2p_mgmt
) {
4982 wpa_supplicant_set_state(wpa_s
,
4988 if (!wpa_s
->ap_iface
) {
4989 wpa_supplicant_set_state(wpa_s
,
4991 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4992 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4994 wpa_supplicant_set_state(wpa_s
,
4996 #else /* CONFIG_AP */
4997 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4998 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4999 #endif /* CONFIG_AP */
5002 case EVENT_INTERFACE_DISABLED
:
5003 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
5005 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
5006 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
5007 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
5009 * Mark interface disabled if this happens to end up not
5010 * being removed as a separate P2P group interface.
5012 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
5014 * The interface was externally disabled. Remove
5015 * it assuming an external entity will start a
5016 * new session if needed.
5018 if (wpa_s
->current_ssid
&&
5019 wpa_s
->current_ssid
->p2p_group
)
5020 wpas_p2p_interface_unavailable(wpa_s
);
5022 wpas_p2p_disconnect(wpa_s
);
5024 * wpa_s instance may have been freed, so must not use
5029 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
5030 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
5031 /* This radio work will be cancelled, so clear P2P
5034 p2p_stop_find(wpa_s
->global
->p2p
);
5036 #endif /* CONFIG_P2P */
5038 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
5040 * Indicate disconnection to keep ctrl_iface events
5043 wpa_supplicant_event_disassoc(
5044 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
5046 wpa_supplicant_mark_disassoc(wpa_s
);
5047 os_reltime_age(&wpa_s
->last_scan
, &age
);
5048 if (age
.sec
>= SCAN_RES_VALID_FOR_CONNECT
) {
5049 clear_at
.sec
= SCAN_RES_VALID_FOR_CONNECT
;
5052 struct os_reltime tmp
;
5054 tmp
.sec
= SCAN_RES_VALID_FOR_CONNECT
;
5056 os_reltime_sub(&tmp
, &age
, &clear_at
);
5058 eloop_register_timeout(clear_at
.sec
, clear_at
.usec
,
5059 wpas_clear_disabled_interface
,
5061 radio_remove_works(wpa_s
, NULL
, 0);
5063 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
5065 case EVENT_CHANNEL_LIST_CHANGED
:
5066 wpa_supplicant_update_channel_list(
5067 wpa_s
, &data
->channel_list_changed
);
5069 case EVENT_INTERFACE_UNAVAILABLE
:
5070 wpas_p2p_interface_unavailable(wpa_s
);
5072 case EVENT_BEST_CHANNEL
:
5073 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
5075 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
5076 data
->best_chan
.freq_overall
);
5077 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
5078 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
5079 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
5080 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
5081 data
->best_chan
.freq_5
,
5082 data
->best_chan
.freq_overall
);
5084 case EVENT_UNPROT_DEAUTH
:
5085 wpa_supplicant_event_unprot_deauth(wpa_s
,
5086 &data
->unprot_deauth
);
5088 case EVENT_UNPROT_DISASSOC
:
5089 wpa_supplicant_event_unprot_disassoc(wpa_s
,
5090 &data
->unprot_disassoc
);
5092 case EVENT_STATION_LOW_ACK
:
5094 if (wpa_s
->ap_iface
&& data
)
5095 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
5096 data
->low_ack
.addr
);
5097 #endif /* CONFIG_AP */
5100 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
5101 data
->low_ack
.addr
);
5102 #endif /* CONFIG_TDLS */
5104 case EVENT_IBSS_PEER_LOST
:
5105 #ifdef CONFIG_IBSS_RSN
5106 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
5107 #endif /* CONFIG_IBSS_RSN */
5109 case EVENT_DRIVER_GTK_REKEY
:
5110 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
5111 wpa_s
->bssid
, ETH_ALEN
))
5115 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
5116 data
->driver_gtk_rekey
.replay_ctr
);
5118 case EVENT_SCHED_SCAN_STOPPED
:
5119 wpa_s
->sched_scanning
= 0;
5120 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
5121 wpa_supplicant_notify_scanning(wpa_s
, 0);
5123 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5127 * If the driver stopped scanning without being requested to,
5128 * request a new scan to continue scanning for networks.
5130 if (!wpa_s
->sched_scan_stop_req
&&
5131 wpa_s
->wpa_state
== WPA_SCANNING
) {
5132 wpa_dbg(wpa_s
, MSG_DEBUG
,
5133 "Restart scanning after unexpected sched_scan stop event");
5134 wpa_supplicant_req_scan(wpa_s
, 1, 0);
5138 wpa_s
->sched_scan_stop_req
= 0;
5141 * Start a new sched scan to continue searching for more SSIDs
5142 * either if timed out or PNO schedule scan is pending.
5144 if (wpa_s
->sched_scan_timed_out
) {
5145 wpa_supplicant_req_sched_scan(wpa_s
);
5146 } else if (wpa_s
->pno_sched_pending
) {
5147 wpa_s
->pno_sched_pending
= 0;
5148 wpas_start_pno(wpa_s
);
5149 } else if (resched
) {
5150 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5154 case EVENT_WPS_BUTTON_PUSHED
:
5156 wpas_wps_start_pbc(wpa_s
, NULL
, 0, 0);
5157 #endif /* CONFIG_WPS */
5159 case EVENT_AVOID_FREQUENCIES
:
5160 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
5162 case EVENT_CONNECT_FAILED_REASON
:
5164 if (!wpa_s
->ap_iface
|| !data
)
5166 hostapd_event_connect_failed_reason(
5167 wpa_s
->ap_iface
->bss
[0],
5168 data
->connect_failed_reason
.addr
,
5169 data
->connect_failed_reason
.code
);
5170 #endif /* CONFIG_AP */
5172 case EVENT_NEW_PEER_CANDIDATE
:
5174 if (!wpa_s
->ifmsh
|| !data
)
5176 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
5177 data
->mesh_peer
.ies
,
5178 data
->mesh_peer
.ie_len
);
5179 #endif /* CONFIG_MESH */
5183 if (!wpa_s
->ap_iface
)
5185 hostapd_event_get_survey(wpa_s
->ap_iface
,
5186 &data
->survey_results
);
5187 #endif /* CONFIG_AP */
5189 case EVENT_ACS_CHANNEL_SELECTED
:
5192 if (!wpa_s
->ap_iface
)
5194 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
5195 &data
->acs_selected_channels
);
5196 #endif /* CONFIG_ACS */
5197 #endif /* CONFIG_AP */
5199 case EVENT_P2P_LO_STOP
:
5201 wpa_s
->p2p_lo_started
= 0;
5202 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
5203 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
5204 data
->p2p_lo_stop
.reason_code
);
5205 #endif /* CONFIG_P2P */
5207 case EVENT_BEACON_LOSS
:
5208 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
5210 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
5211 bgscan_notify_beacon_loss(wpa_s
);
5213 case EVENT_EXTERNAL_AUTH
:
5215 if (!wpa_s
->current_ssid
) {
5216 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
5219 sme_external_auth_trigger(wpa_s
, data
);
5220 #endif /* CONFIG_SAE */
5222 case EVENT_PORT_AUTHORIZED
:
5223 wpa_supplicant_event_port_authorized(wpa_s
);
5225 case EVENT_STATION_OPMODE_CHANGED
:
5227 if (!wpa_s
->ap_iface
|| !data
)
5230 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
5231 data
->sta_opmode
.addr
,
5232 data
->sta_opmode
.smps_mode
,
5233 data
->sta_opmode
.chan_width
,
5234 data
->sta_opmode
.rx_nss
);
5235 #endif /* CONFIG_AP */
5238 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
5244 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
5245 union wpa_event_data
*data
)
5247 struct wpa_supplicant
*wpa_s
;
5249 if (event
!= EVENT_INTERFACE_STATUS
)
5252 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
5253 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
5254 unsigned int ifindex
;
5256 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
5257 if (ifindex
!= data
->interface_status
.ifindex
) {
5258 wpa_dbg(wpa_s
, MSG_DEBUG
,
5259 "interface status ifindex %d mismatch (%d)",
5260 ifindex
, data
->interface_status
.ifindex
);
5264 #ifdef CONFIG_MATCH_IFACE
5265 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
5266 struct wpa_interface
*wpa_i
;
5268 wpa_i
= wpa_supplicant_match_iface(
5269 ctx
, data
->interface_status
.ifname
);
5272 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
5277 #endif /* CONFIG_MATCH_IFACE */
5280 wpa_supplicant_event(wpa_s
, event
, data
);