2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "common/gas_server.h"
32 #include "common/dpp.h"
33 #include "crypto/random.h"
34 #include "blacklist.h"
35 #include "wpas_glue.h"
36 #include "wps_supplicant.h"
39 #include "gas_query.h"
40 #include "p2p_supplicant.h"
46 #include "offchannel.h"
47 #include "interworking.h"
51 #include "dpp_supplicant.h"
54 #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
57 #ifndef CONFIG_NO_SCAN_PROCESSING
58 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
59 int new_scan
, int own_request
);
60 #endif /* CONFIG_NO_SCAN_PROCESSING */
63 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
65 struct os_reltime now
;
67 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
71 if (ssid
->disabled_until
.sec
> now
.sec
)
72 return ssid
->disabled_until
.sec
- now
.sec
;
74 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
80 #ifndef CONFIG_NO_SCAN_PROCESSING
82 * wpas_reenabled_network_time - Time until first network is re-enabled
83 * @wpa_s: Pointer to wpa_supplicant data
84 * Returns: If all enabled networks are temporarily disabled, returns the time
85 * (in sec) until the first network is re-enabled. Otherwise returns 0.
87 * This function is used in case all enabled networks are temporarily disabled,
88 * in which case it returns the time (in sec) that the first network will be
89 * re-enabled. The function assumes that at least one network is enabled.
91 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
93 struct wpa_ssid
*ssid
;
94 int disabled_for
, res
= 0;
96 #ifdef CONFIG_INTERWORKING
97 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
100 #endif /* CONFIG_INTERWORKING */
102 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
106 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
110 if (!res
|| disabled_for
< res
)
116 #endif /* CONFIG_NO_SCAN_PROCESSING */
119 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
121 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
123 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
126 wpa_dbg(wpa_s
, MSG_DEBUG
,
127 "Try to associate due to network getting re-enabled");
128 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
129 wpa_supplicant_cancel_sched_scan(wpa_s
);
130 wpa_supplicant_req_scan(wpa_s
, 0, 0);
135 static struct wpa_bss
* wpa_supplicant_get_new_bss(
136 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
138 struct wpa_bss
*bss
= NULL
;
139 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
141 if (ssid
->ssid_len
> 0)
142 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
144 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
150 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
152 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
155 wpa_supplicant_update_scan_results(wpa_s
);
157 /* Get the BSS from the new scan results */
158 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
162 wpa_s
->current_bss
= bss
;
166 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
168 struct wpa_ssid
*ssid
, *old_ssid
;
169 u8 drv_ssid
[SSID_MAX_LEN
];
173 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
174 wpa_supplicant_update_current_bss(wpa_s
);
176 if (wpa_s
->current_ssid
->ssid_len
== 0)
177 return 0; /* current profile still in use */
178 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
180 wpa_msg(wpa_s
, MSG_INFO
,
181 "Failed to read SSID from driver");
182 return 0; /* try to use current profile */
186 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
187 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
189 return 0; /* current profile still in use */
191 wpa_msg(wpa_s
, MSG_DEBUG
,
192 "Driver-initiated BSS selection changed the SSID to %s",
193 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
194 /* continue selecting a new network profile */
197 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
199 ssid
= wpa_supplicant_get_ssid(wpa_s
);
201 wpa_msg(wpa_s
, MSG_INFO
,
202 "No network configuration found for the current AP");
206 if (wpas_network_disabled(wpa_s
, ssid
)) {
207 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
211 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
212 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
213 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
217 res
= wpas_temp_disabled(wpa_s
, ssid
);
219 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
220 "disabled for %d second(s)", res
);
224 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
226 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
228 size_t wpa_ie_len
= sizeof(wpa_ie
);
229 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
230 wpa_ie
, &wpa_ie_len
) < 0)
231 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
233 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
236 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
237 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
238 old_ssid
= wpa_s
->current_ssid
;
239 wpa_s
->current_ssid
= ssid
;
241 wpa_supplicant_update_current_bss(wpa_s
);
243 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
244 wpa_supplicant_initiate_eapol(wpa_s
);
245 if (old_ssid
!= wpa_s
->current_ssid
)
246 wpas_notify_network_changed(wpa_s
);
252 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
254 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
256 if (wpa_s
->countermeasures
) {
257 wpa_s
->countermeasures
= 0;
258 wpa_drv_set_countermeasures(wpa_s
, 0);
259 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
262 * It is possible that the device is sched scanning, which means
263 * that a connection attempt will be done only when we receive
264 * scan results. However, in this case, it would be preferable
265 * to scan and connect immediately, so cancel the sched_scan and
266 * issue a regular scan flow.
268 wpa_supplicant_cancel_sched_scan(wpa_s
);
269 wpa_supplicant_req_scan(wpa_s
, 0, 0);
274 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
278 wnm_bss_keep_alive_deinit(wpa_s
);
280 #ifdef CONFIG_IBSS_RSN
281 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
282 wpa_s
->ibss_rsn
= NULL
;
283 #endif /* CONFIG_IBSS_RSN */
286 wpa_supplicant_ap_deinit(wpa_s
);
287 #endif /* CONFIG_AP */
290 /* Clear possibly configured frame filters */
291 wpa_drv_configure_frame_filters(wpa_s
, 0);
292 #endif /* CONFIG_HS20 */
294 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
297 if (os_reltime_initialized(&wpa_s
->session_start
)) {
298 os_reltime_age(&wpa_s
->session_start
, &wpa_s
->session_length
);
299 wpa_s
->session_start
.sec
= 0;
300 wpa_s
->session_start
.usec
= 0;
301 wpas_notify_session_length(wpa_s
);
304 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
305 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
306 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
307 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
308 sme_clear_on_disassoc(wpa_s
);
309 wpa_s
->current_bss
= NULL
;
310 wpa_s
->assoc_freq
= 0;
313 wpas_notify_bssid_changed(wpa_s
);
315 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
316 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
317 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
318 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
319 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
|| wpa_s
->drv_authorized_port
)
320 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
321 wpa_s
->drv_authorized_port
= 0;
322 wpa_s
->ap_ies_from_associnfo
= 0;
323 wpa_s
->current_ssid
= NULL
;
324 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
327 wpas_rrm_reset(wpa_s
);
328 wpa_s
->wnmsleep_used
= 0;
329 wnm_clear_coloc_intf_reporting(wpa_s
);
331 #ifdef CONFIG_TESTING_OPTIONS
332 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
333 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
334 #endif /* CONFIG_TESTING_OPTIONS */
335 wpa_s
->ieee80211ac
= 0;
337 if (wpa_s
->enabled_4addr_mode
&& wpa_drv_set_4addr_mode(wpa_s
, 0) == 0)
338 wpa_s
->enabled_4addr_mode
= 0;
342 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
344 struct wpa_ie_data ie
;
348 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
352 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
353 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
354 ie
.pmkid
+ i
* PMKID_LEN
,
355 NULL
, NULL
, 0, NULL
, 0);
356 if (pmksa_set
== 0) {
357 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
362 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
363 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
367 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
368 union wpa_event_data
*data
)
371 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
375 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
376 " index=%d preauth=%d",
377 MAC2STR(data
->pmkid_candidate
.bssid
),
378 data
->pmkid_candidate
.index
,
379 data
->pmkid_candidate
.preauth
);
381 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
382 data
->pmkid_candidate
.index
,
383 data
->pmkid_candidate
.preauth
);
387 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
389 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
390 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
393 #ifdef IEEE8021X_EAPOL
394 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
395 wpa_s
->current_ssid
&&
396 !(wpa_s
->current_ssid
->eapol_flags
&
397 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
398 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
399 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
400 * plaintext or static WEP keys). */
403 #endif /* IEEE8021X_EAPOL */
410 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
411 * @wpa_s: pointer to wpa_supplicant data
412 * @ssid: Configuration data for the network
413 * Returns: 0 on success, -1 on failure
415 * This function is called when starting authentication with a network that is
416 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
418 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
419 struct wpa_ssid
*ssid
)
421 #ifdef IEEE8021X_EAPOL
423 int aka
= 0, sim
= 0;
425 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
426 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
429 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
433 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
434 while (eap
->vendor
!= EAP_VENDOR_IETF
||
435 eap
->method
!= EAP_TYPE_NONE
) {
436 if (eap
->vendor
== EAP_VENDOR_IETF
) {
437 if (eap
->method
== EAP_TYPE_SIM
)
439 else if (eap
->method
== EAP_TYPE_AKA
||
440 eap
->method
== EAP_TYPE_AKA_PRIME
)
447 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
449 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
450 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
455 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
456 "use SIM, but neither EAP-SIM nor EAP-AKA are "
461 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
462 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
464 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
465 if (wpa_s
->scard
== NULL
) {
466 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
470 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
471 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
472 #endif /* PCSC_FUNCS */
473 #endif /* IEEE8021X_EAPOL */
479 #ifndef CONFIG_NO_SCAN_PROCESSING
481 static int has_wep_key(struct wpa_ssid
*ssid
)
485 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
486 if (ssid
->wep_key_len
[i
])
494 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
495 struct wpa_ssid
*ssid
)
499 if (ssid
->mixed_cell
)
503 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
505 #endif /* CONFIG_WPS */
508 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
510 #endif /* CONFIG_OWE */
512 if (has_wep_key(ssid
))
515 #ifdef IEEE8021X_EAPOL
516 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
517 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
518 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
520 #endif /* IEEE8021X_EAPOL */
522 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
525 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
528 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
534 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
535 struct wpa_ssid
*ssid
,
536 struct wpa_bss
*bss
, int debug_print
)
538 struct wpa_ie_data ie
;
540 const u8
*rsn_ie
, *wpa_ie
;
544 const u8
*oce_capa_attr
;
545 #endif /* CONFIG_MBO */
547 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
551 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
552 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
553 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
554 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
555 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
557 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
558 while ((ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)) && rsn_ie
) {
561 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
563 wpa_dbg(wpa_s
, MSG_DEBUG
,
564 " skip RSN IE - parse failed");
567 if (!ie
.has_pairwise
)
568 ie
.pairwise_cipher
= wpa_default_rsn_cipher(bss
->freq
);
570 ie
.group_cipher
= wpa_default_rsn_cipher(bss
->freq
);
573 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
576 wpa_dbg(wpa_s
, MSG_DEBUG
,
577 " selected based on TSN in RSN IE");
581 if (!(ie
.proto
& ssid
->proto
) &&
582 !(ssid
->proto
& WPA_PROTO_OSEN
)) {
584 wpa_dbg(wpa_s
, MSG_DEBUG
,
585 " skip RSN IE - proto mismatch");
589 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
591 wpa_dbg(wpa_s
, MSG_DEBUG
,
592 " skip RSN IE - PTK cipher mismatch");
596 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
598 wpa_dbg(wpa_s
, MSG_DEBUG
,
599 " skip RSN IE - GTK cipher mismatch");
603 if (ssid
->group_mgmt_cipher
&&
604 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
606 wpa_dbg(wpa_s
, MSG_DEBUG
,
607 " skip RSN IE - group mgmt cipher mismatch");
611 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
613 wpa_dbg(wpa_s
, MSG_DEBUG
,
614 " skip RSN IE - key mgmt mismatch");
618 #ifdef CONFIG_IEEE80211W
619 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
620 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
621 MGMT_FRAME_PROTECTION_REQUIRED
) {
623 wpa_dbg(wpa_s
, MSG_DEBUG
,
624 " skip RSN IE - no mgmt frame protection");
627 #endif /* CONFIG_IEEE80211W */
628 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
629 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
630 NO_MGMT_FRAME_PROTECTION
) {
632 wpa_dbg(wpa_s
, MSG_DEBUG
,
633 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
637 oce_capa_attr
= wpas_mbo_get_bss_attr(bss
,
638 OCE_ATTR_ID_CAPA_IND
);
639 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
640 (wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) ||
641 (oce_capa_attr
&& oce_capa_attr
[1] >= 1 &&
642 !(oce_capa_attr
[2] & OCE_IS_STA_CFON
))) &&
643 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
644 NO_MGMT_FRAME_PROTECTION
) {
646 wpa_dbg(wpa_s
, MSG_DEBUG
,
647 " skip RSN IE - no mgmt frame protection enabled on MBO/OCE AP");
650 #endif /* CONFIG_MBO */
653 wpa_dbg(wpa_s
, MSG_DEBUG
,
654 " selected based on RSN IE");
658 #ifdef CONFIG_IEEE80211W
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");
666 #endif /* CONFIG_IEEE80211W */
668 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
669 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
672 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
674 wpa_dbg(wpa_s
, MSG_DEBUG
,
675 " 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");
688 if (!(ie
.proto
& ssid
->proto
)) {
690 wpa_dbg(wpa_s
, MSG_DEBUG
,
691 " skip WPA IE - proto mismatch");
695 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
697 wpa_dbg(wpa_s
, MSG_DEBUG
,
698 " skip WPA IE - PTK cipher mismatch");
702 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
704 wpa_dbg(wpa_s
, MSG_DEBUG
,
705 " skip WPA IE - GTK cipher mismatch");
709 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
711 wpa_dbg(wpa_s
, MSG_DEBUG
,
712 " skip WPA IE - key mgmt mismatch");
717 wpa_dbg(wpa_s
, MSG_DEBUG
,
718 " selected based on WPA IE");
722 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
725 wpa_dbg(wpa_s
, MSG_DEBUG
,
726 " allow for non-WPA IEEE 802.1X");
731 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
732 !wpa_ie
&& !rsn_ie
) {
733 if (wpa_s
->owe_transition_select
&&
734 wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
) &&
735 ssid
->owe_transition_bss_select_count
+ 1 <=
736 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
) {
737 ssid
->owe_transition_bss_select_count
++;
739 wpa_dbg(wpa_s
, MSG_DEBUG
,
740 " skip OWE transition BSS (selection count %d does not exceed %d)",
741 ssid
->owe_transition_bss_select_count
,
742 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
);
743 wpa_s
->owe_transition_search
= 1;
747 wpa_dbg(wpa_s
, MSG_DEBUG
,
748 " allow in OWE transition mode");
751 #endif /* CONFIG_OWE */
753 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
754 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
756 wpa_dbg(wpa_s
, MSG_DEBUG
,
757 " skip - no WPA/RSN proto match");
761 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
762 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
764 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
768 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
770 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
775 wpa_dbg(wpa_s
, MSG_DEBUG
,
776 " reject due to mismatch with WPA/WPA2");
782 static int freq_allowed(int *freqs
, int freq
)
789 for (i
= 0; freqs
[i
]; i
++)
790 if (freqs
[i
] == freq
)
796 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
799 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
800 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
805 return 1; /* Cannot do matching without knowing band */
807 modes
= wpa_s
->hw
.modes
;
810 * The driver does not provide any additional information
811 * about the utilized hardware, so allow the connection attempt
817 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
818 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
819 int freq
= modes
[i
].channels
[j
].freq
;
820 if (freq
== bss
->freq
) {
822 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
823 break; /* do not allow 802.11b replace
834 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
835 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
839 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
840 int flagged
= !!(rate_ie
[j
] & 0x80);
841 int r
= (rate_ie
[j
] & 0x7f) * 5;
844 * IEEE Std 802.11n-2009 7.3.2.2:
845 * The new BSS Membership selector value is encoded
846 * like a legacy basic rate, but it is not a rate and
847 * only indicates if the BSS members are required to
848 * support the mandatory features of Clause 20 [HT PHY]
849 * in order to join the BSS.
851 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
852 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
853 if (!ht_supported(mode
)) {
855 wpa_dbg(wpa_s
, MSG_DEBUG
,
856 " hardware does not support HT PHY");
862 /* There's also a VHT selector for 802.11ac */
863 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
864 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
865 if (!vht_supported(mode
)) {
867 wpa_dbg(wpa_s
, MSG_DEBUG
,
868 " hardware does not support VHT PHY");
877 /* check for legacy basic rates */
878 for (k
= 0; k
< mode
->num_rates
; k
++) {
879 if (mode
->rates
[k
] == r
)
882 if (k
== mode
->num_rates
) {
884 * IEEE Std 802.11-2007 7.3.2.2 demands that in
885 * order to join a BSS all required rates
886 * have to be supported by the hardware.
889 wpa_dbg(wpa_s
, MSG_DEBUG
,
890 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
892 bss
->freq
, mode
->mode
, mode
->num_rates
);
903 * Test whether BSS is in an ESS.
904 * This is done differently in DMG (60 GHz) and non-DMG bands
906 static int bss_is_ess(struct wpa_bss
*bss
)
908 if (bss_is_dmg(bss
)) {
909 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
910 IEEE80211_CAP_DMG_AP
;
913 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
918 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
922 for (i
= 0; i
< ETH_ALEN
; i
++) {
923 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
930 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
934 for (i
= 0; i
< num
; i
++) {
935 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
936 const u8
*m
= a
+ ETH_ALEN
;
938 if (match_mac_mask(a
, addr
, m
))
945 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
946 const u8
**ret_ssid
, size_t *ret_ssid_len
)
949 const u8
*owe
, *pos
, *end
, *bssid
;
951 struct wpa_bss
*open_bss
;
953 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
954 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
958 end
= owe
+ 2 + owe
[1];
960 if (end
- pos
< ETH_ALEN
+ 1)
965 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
968 /* Match the profile SSID against the OWE transition mode SSID on the
970 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
971 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
973 *ret_ssid_len
= ssid_len
;
975 if (bss
->ssid_len
> 0)
978 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
981 if (ssid_len
!= open_bss
->ssid_len
||
982 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
983 wpa_dbg(wpa_s
, MSG_DEBUG
,
984 "OWE: transition mode SSID mismatch: %s",
985 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
989 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
990 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
991 wpa_dbg(wpa_s
, MSG_DEBUG
,
992 "OWE: transition mode open BSS unexpected info");
997 end
= owe
+ 2 + owe
[1];
999 if (end
- pos
< ETH_ALEN
+ 1)
1001 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
1002 wpa_dbg(wpa_s
, MSG_DEBUG
,
1003 "OWE: transition mode BSSID mismatch: " MACSTR
,
1009 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
1011 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
1012 wpa_ssid_txt(pos
, ssid_len
));
1013 os_memcpy(bss
->ssid
, pos
, ssid_len
);
1014 bss
->ssid_len
= ssid_len
;
1015 #endif /* CONFIG_OWE */
1019 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
1020 int i
, struct wpa_bss
*bss
,
1021 struct wpa_ssid
*group
,
1022 int only_first_ssid
, int debug_print
)
1024 u8 wpa_ie_len
, rsn_ie_len
;
1026 struct wpa_blacklist
*e
;
1028 struct wpa_ssid
*ssid
;
1029 int osen
, rsn_osen
= 0;
1031 const u8
*assoc_disallow
;
1032 #endif /* CONFIG_MBO */
1033 const u8
*match_ssid
;
1034 size_t match_ssid_len
;
1035 struct wpa_ie_data data
;
1037 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1038 wpa_ie_len
= ie
? ie
[1] : 0;
1040 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1041 rsn_ie_len
= ie
? ie
[1] : 0;
1042 if (ie
&& wpa_parse_wpa_ie_rsn(ie
, 2 + ie
[1], &data
) == 0 &&
1043 (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
))
1046 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1050 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1051 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1052 i
, MAC2STR(bss
->bssid
),
1053 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1054 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1056 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1058 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1059 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1061 osen
? " osen=1" : "");
1064 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1067 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1069 * When only a single network is enabled, we can
1070 * trigger blacklisting on the first failure. This
1071 * should not be done with multiple enabled networks to
1072 * avoid getting forced to move into a worse ESS on
1073 * single error if there are no other BSSes of the
1078 if (e
->count
> limit
) {
1080 wpa_dbg(wpa_s
, MSG_DEBUG
,
1081 " skip - blacklisted (count=%d limit=%d)",
1088 match_ssid
= bss
->ssid
;
1089 match_ssid_len
= bss
->ssid_len
;
1090 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1092 if (match_ssid_len
== 0) {
1094 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1098 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1100 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1104 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1106 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1110 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1112 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1113 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1116 if (wpas_network_disabled(wpa_s
, ssid
)) {
1118 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1122 res
= wpas_temp_disabled(wpa_s
, ssid
);
1125 wpa_dbg(wpa_s
, MSG_DEBUG
,
1126 " skip - disabled temporarily for %d second(s)",
1132 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1134 wpa_dbg(wpa_s
, MSG_DEBUG
,
1135 " skip - blacklisted (WPS)");
1139 if (wpa
&& ssid
->ssid_len
== 0 &&
1140 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1143 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1144 /* Only allow wildcard SSID match if an AP
1145 * advertises active WPS operation that matches
1148 if (ssid
->ssid_len
== 0 &&
1149 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1152 #endif /* CONFIG_WPS */
1154 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1155 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1159 (match_ssid_len
!= ssid
->ssid_len
||
1160 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1162 wpa_dbg(wpa_s
, MSG_DEBUG
,
1163 " skip - SSID mismatch");
1167 if (ssid
->bssid_set
&&
1168 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1170 wpa_dbg(wpa_s
, MSG_DEBUG
,
1171 " skip - BSSID mismatch");
1175 /* check blacklist */
1176 if (ssid
->num_bssid_blacklist
&&
1177 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1178 ssid
->num_bssid_blacklist
)) {
1180 wpa_dbg(wpa_s
, MSG_DEBUG
,
1181 " skip - BSSID blacklisted");
1185 /* if there is a whitelist, only accept those APs */
1186 if (ssid
->num_bssid_whitelist
&&
1187 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1188 ssid
->num_bssid_whitelist
)) {
1190 wpa_dbg(wpa_s
, MSG_DEBUG
,
1191 " skip - BSSID not in whitelist");
1195 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1199 if (!osen
&& !wpa
&&
1200 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1201 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1202 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1203 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1205 wpa_dbg(wpa_s
, MSG_DEBUG
,
1206 " skip - non-WPA network not allowed");
1210 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1211 has_wep_key(ssid
)) {
1213 wpa_dbg(wpa_s
, MSG_DEBUG
,
1214 " skip - ignore WPA/WPA2 AP for WEP network block");
1218 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
&&
1221 wpa_dbg(wpa_s
, MSG_DEBUG
,
1222 " skip - non-OSEN network not allowed");
1226 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1228 wpa_dbg(wpa_s
, MSG_DEBUG
,
1229 " skip - privacy mismatch");
1233 if (ssid
->mode
!= WPAS_MODE_MESH
&& !bss_is_ess(bss
) &&
1234 !bss_is_pbss(bss
)) {
1236 wpa_dbg(wpa_s
, MSG_DEBUG
,
1237 " skip - not ESS, PBSS, or MBSS");
1241 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1243 wpa_dbg(wpa_s
, MSG_DEBUG
,
1244 " skip - PBSS mismatch (ssid %d bss %d)",
1245 ssid
->pbss
, bss_is_pbss(bss
));
1249 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1251 wpa_dbg(wpa_s
, MSG_DEBUG
,
1252 " skip - frequency not allowed");
1257 if (ssid
->mode
== WPAS_MODE_MESH
&& ssid
->frequency
> 0 &&
1258 ssid
->frequency
!= bss
->freq
) {
1260 wpa_dbg(wpa_s
, MSG_DEBUG
,
1261 " skip - frequency not allowed (mesh)");
1264 #endif /* CONFIG_MESH */
1266 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1268 wpa_dbg(wpa_s
, MSG_DEBUG
,
1269 " skip - rate sets do not match");
1273 #ifndef CONFIG_IBSS_RSN
1274 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1275 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1276 WPA_KEY_MGMT_WPA_NONE
))) {
1278 wpa_dbg(wpa_s
, MSG_DEBUG
,
1279 " skip - IBSS RSN not supported in the build");
1282 #endif /* !CONFIG_IBSS_RSN */
1285 if (ssid
->p2p_group
&&
1286 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1287 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1289 wpa_dbg(wpa_s
, MSG_DEBUG
,
1290 " skip - no P2P IE seen");
1294 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1295 struct wpabuf
*p2p_ie
;
1296 u8 dev_addr
[ETH_ALEN
];
1298 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1301 wpa_dbg(wpa_s
, MSG_DEBUG
,
1302 " skip - no P2P element");
1305 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1306 bss
, P2P_IE_VENDOR_TYPE
);
1307 if (p2p_ie
== NULL
) {
1309 wpa_dbg(wpa_s
, MSG_DEBUG
,
1310 " skip - could not fetch P2P element");
1314 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1315 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1318 wpa_dbg(wpa_s
, MSG_DEBUG
,
1319 " skip - no matching GO P2P Device Address in P2P element");
1320 wpabuf_free(p2p_ie
);
1323 wpabuf_free(p2p_ie
);
1327 * TODO: skip the AP if its P2P IE has Group Formation
1328 * bit set in the P2P Group Capability Bitmap and we
1329 * are not in Group Formation with that device.
1331 #endif /* CONFIG_P2P */
1333 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1335 struct os_reltime diff
;
1337 os_reltime_sub(&wpa_s
->scan_min_time
,
1338 &bss
->last_update
, &diff
);
1340 wpa_dbg(wpa_s
, MSG_DEBUG
,
1341 " skip - scan result not recent enough (%u.%06u seconds too old)",
1342 (unsigned int) diff
.sec
,
1343 (unsigned int) diff
.usec
);
1347 #ifdef CONFIG_TESTING_OPTIONS
1348 if (wpa_s
->ignore_assoc_disallow
)
1349 goto skip_assoc_disallow
;
1350 #endif /* CONFIG_TESTING_OPTIONS */
1351 assoc_disallow
= wpas_mbo_get_bss_attr(
1352 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1353 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1355 wpa_dbg(wpa_s
, MSG_DEBUG
,
1356 " skip - MBO association disallowed (reason %u)",
1361 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
)) {
1363 wpa_dbg(wpa_s
, MSG_DEBUG
,
1364 " skip - AP temporarily disallowed");
1367 #ifdef CONFIG_TESTING_OPTIONS
1368 skip_assoc_disallow
:
1369 #endif /* CONFIG_TESTING_OPTIONS */
1370 #endif /* CONFIG_MBO */
1373 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1374 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1375 (!ssid
->dpp_connector
||
1376 !ssid
->dpp_netaccesskey
||
1377 !ssid
->dpp_csign
)) {
1379 wpa_dbg(wpa_s
, MSG_DEBUG
,
1380 " skip - no PMKSA entry for DPP");
1383 #endif /* CONFIG_DPP */
1385 /* Matching configuration found */
1389 /* No matching configuration found */
1394 static struct wpa_bss
*
1395 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1396 struct wpa_ssid
*group
,
1397 struct wpa_ssid
**selected_ssid
,
1398 int only_first_ssid
)
1402 if (wpa_s
->current_ssid
) {
1403 struct wpa_ssid
*ssid
;
1405 wpa_dbg(wpa_s
, MSG_DEBUG
,
1406 "Scan results matching the currently selected network");
1407 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1408 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1410 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1411 only_first_ssid
, 0);
1412 if (ssid
!= wpa_s
->current_ssid
)
1414 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1415 " freq=%d level=%d snr=%d est_throughput=%u",
1416 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1417 bss
->snr
, bss
->est_throughput
);
1421 if (only_first_ssid
)
1422 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1425 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1428 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1429 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1431 wpa_s
->owe_transition_select
= 1;
1432 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1433 only_first_ssid
, 1);
1434 wpa_s
->owe_transition_select
= 0;
1435 if (!*selected_ssid
)
1437 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1439 MAC2STR(bss
->bssid
),
1440 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1448 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1449 struct wpa_ssid
**selected_ssid
)
1451 struct wpa_bss
*selected
= NULL
;
1453 struct wpa_ssid
*next_ssid
= NULL
;
1454 struct wpa_ssid
*ssid
;
1456 if (wpa_s
->last_scan_res
== NULL
||
1457 wpa_s
->last_scan_res_used
== 0)
1458 return NULL
; /* no scan results from last update */
1460 if (wpa_s
->next_ssid
) {
1461 /* check that next_ssid is still valid */
1462 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1463 if (ssid
== wpa_s
->next_ssid
)
1467 wpa_s
->next_ssid
= NULL
;
1470 while (selected
== NULL
) {
1471 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1472 if (next_ssid
&& next_ssid
->priority
==
1473 wpa_s
->conf
->pssid
[prio
]->priority
) {
1474 selected
= wpa_supplicant_select_bss(
1475 wpa_s
, next_ssid
, selected_ssid
, 1);
1479 selected
= wpa_supplicant_select_bss(
1480 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1486 if (selected
== NULL
&& wpa_s
->blacklist
&&
1487 !wpa_s
->countermeasures
) {
1488 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1489 "blacklist and try again");
1490 wpa_blacklist_clear(wpa_s
);
1491 wpa_s
->blacklist_cleared
++;
1492 } else if (selected
== NULL
)
1496 ssid
= *selected_ssid
;
1497 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1498 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1499 const char *field_name
, *txt
= NULL
;
1501 wpa_dbg(wpa_s
, MSG_DEBUG
,
1502 "PSK/passphrase not yet available for the selected network");
1504 wpas_notify_network_request(wpa_s
, ssid
,
1505 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1507 field_name
= wpa_supplicant_ctrl_req_to_string(
1508 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1509 if (field_name
== NULL
)
1512 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1521 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1522 int timeout_sec
, int timeout_usec
)
1524 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1526 * No networks are enabled; short-circuit request so
1527 * we don't wait timeout seconds before transitioning
1528 * to INACTIVE state.
1530 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1531 "since there are no enabled networks");
1532 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1536 wpa_s
->scan_for_connection
= 1;
1537 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1541 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1542 struct wpa_bss
*selected
,
1543 struct wpa_ssid
*ssid
)
1545 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1546 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1547 "PBC session overlap");
1548 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1550 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1551 wpa_s
->p2p_in_provisioning
) {
1552 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1556 #endif /* CONFIG_P2P */
1559 wpas_wps_pbc_overlap(wpa_s
);
1560 wpas_wps_cancel(wpa_s
);
1561 #endif /* CONFIG_WPS */
1565 wpa_msg(wpa_s
, MSG_DEBUG
,
1566 "Considering connect request: reassociate: %d selected: "
1567 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1568 " wpa_state: %s ssid=%p current_ssid=%p",
1569 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1570 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1571 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1572 ssid
, wpa_s
->current_ssid
);
1575 * Do not trigger new association unless the BSSID has changed or if
1576 * reassociation is requested. If we are in process of associating with
1577 * the selected BSSID, do not trigger new attempt.
1579 if (wpa_s
->reassociate
||
1580 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1581 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1582 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1583 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1584 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1586 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1587 ssid
!= wpa_s
->current_ssid
)))) {
1588 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1589 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1592 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1593 MAC2STR(selected
->bssid
));
1594 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1596 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1597 "connect with the selected AP");
1604 static struct wpa_ssid
*
1605 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1608 struct wpa_ssid
*ssid
;
1610 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1611 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1613 if (wpas_network_disabled(wpa_s
, ssid
))
1615 #ifndef CONFIG_IBSS_RSN
1616 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1617 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1618 WPA_KEY_MGMT_WPA_NONE
))) {
1619 wpa_msg(wpa_s
, MSG_INFO
,
1620 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1621 wpa_ssid_txt(ssid
->ssid
,
1625 #endif /* !CONFIG_IBSS_RSN */
1626 if (ssid
->mode
== WPAS_MODE_IBSS
||
1627 ssid
->mode
== WPAS_MODE_AP
||
1628 ssid
->mode
== WPAS_MODE_MESH
)
1636 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1637 * on BSS added and BSS changed events */
1638 static void wpa_supplicant_rsn_preauth_scan_results(
1639 struct wpa_supplicant
*wpa_s
)
1641 struct wpa_bss
*bss
;
1643 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1646 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1647 const u8
*ssid
, *rsn
;
1649 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1653 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1657 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1663 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1664 struct wpa_bss
*selected
,
1665 struct wpa_ssid
*ssid
)
1667 struct wpa_bss
*current_bss
= NULL
;
1668 #ifndef CONFIG_NO_ROAMING
1671 int cur_est
, sel_est
;
1672 #endif /* CONFIG_NO_ROAMING */
1674 if (wpa_s
->reassociate
)
1675 return 1; /* explicit request to reassociate */
1676 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1677 return 1; /* we are not associated; continue */
1678 if (wpa_s
->current_ssid
== NULL
)
1679 return 1; /* unknown current SSID */
1680 if (wpa_s
->current_ssid
!= ssid
)
1681 return 1; /* different network block */
1683 if (wpas_driver_bss_selection(wpa_s
))
1684 return 0; /* Driver-based roaming */
1686 if (wpa_s
->current_ssid
->ssid
)
1687 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1688 wpa_s
->current_ssid
->ssid
,
1689 wpa_s
->current_ssid
->ssid_len
);
1691 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1694 return 1; /* current BSS not seen in scan results */
1696 if (current_bss
== selected
)
1699 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1700 return 1; /* current BSS not seen in the last scan */
1702 #ifndef CONFIG_NO_ROAMING
1703 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1704 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1705 " freq=%d level=%d snr=%d est_throughput=%u",
1706 MAC2STR(current_bss
->bssid
),
1707 current_bss
->freq
, current_bss
->level
,
1708 current_bss
->snr
, current_bss
->est_throughput
);
1709 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1710 " freq=%d level=%d snr=%d est_throughput=%u",
1711 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1712 selected
->snr
, selected
->est_throughput
);
1714 if (wpa_s
->current_ssid
->bssid_set
&&
1715 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1717 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1718 "has preferred BSSID");
1722 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1723 wpa_dbg(wpa_s
, MSG_DEBUG
,
1724 "Allow reassociation - selected BSS has better estimated throughput");
1728 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1730 if (current_bss
->level
< 0 &&
1731 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1732 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1737 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1738 wpa_dbg(wpa_s
, MSG_DEBUG
,
1739 "Skip roam - Current BSS has better estimated throughput");
1743 cur_est
= current_bss
->est_throughput
;
1744 sel_est
= selected
->est_throughput
;
1746 if (current_bss
->level
< 0) {
1747 if (current_bss
->level
< -85)
1749 else if (current_bss
->level
< -80)
1751 else if (current_bss
->level
< -75)
1753 else if (current_bss
->level
< -70)
1757 if (cur_est
> sel_est
* 1.5)
1759 else if (cur_est
> sel_est
* 1.2)
1761 else if (cur_est
> sel_est
* 1.1)
1763 else if (cur_est
> sel_est
)
1769 /* Make it easier to move to 5 GHz band */
1770 if (sel_est
> cur_est
* 1.5)
1772 else if (sel_est
> cur_est
* 1.2)
1774 else if (sel_est
> cur_est
* 1.1)
1777 if (min_diff
> reduce
)
1782 diff
= abs(current_bss
->level
- selected
->level
);
1783 if (diff
< min_diff
) {
1784 wpa_dbg(wpa_s
, MSG_DEBUG
,
1785 "Skip roam - too small difference in signal level (%d < %d)",
1790 wpa_dbg(wpa_s
, MSG_DEBUG
,
1791 "Allow reassociation due to difference in signal level (%d >= %d)",
1794 #else /* CONFIG_NO_ROAMING */
1796 #endif /* CONFIG_NO_ROAMING */
1801 * Return a negative value if no scan results could be fetched or if scan
1802 * results should not be shared with other virtual interfaces.
1803 * Return 0 if scan results were fetched and may be shared with other
1805 * Return 1 if scan results may be shared with other virtual interfaces but may
1806 * not trigger any operations.
1807 * Return 2 if the interface was removed and cannot be used.
1809 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1810 union wpa_event_data
*data
,
1811 int own_request
, int update_only
)
1813 struct wpa_scan_results
*scan_res
= NULL
;
1816 #ifndef CONFIG_NO_RANDOM_POOL
1818 #endif /* CONFIG_NO_RANDOM_POOL */
1821 if (wpa_s
->ap_iface
)
1823 #endif /* CONFIG_AP */
1825 wpa_supplicant_notify_scanning(wpa_s
, 0);
1827 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1828 data
? &data
->scan_info
:
1830 if (scan_res
== NULL
) {
1831 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1832 wpa_s
->scan_res_handler
== scan_only_handler
)
1836 if (data
&& data
->scan_info
.external_scan
)
1838 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1840 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1842 goto scan_work_done
;
1845 #ifndef CONFIG_NO_RANDOM_POOL
1846 num
= scan_res
->num
;
1849 for (i
= 0; i
< num
; i
++) {
1851 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1852 buf
[0] = res
->bssid
[5];
1853 buf
[1] = res
->qual
& 0xff;
1854 buf
[2] = res
->noise
& 0xff;
1855 buf
[3] = res
->level
& 0xff;
1856 buf
[4] = res
->tsf
& 0xff;
1857 random_add_randomness(buf
, sizeof(buf
));
1859 #endif /* CONFIG_NO_RANDOM_POOL */
1863 goto scan_work_done
;
1866 if (own_request
&& wpa_s
->scan_res_handler
&&
1867 !(data
&& data
->scan_info
.external_scan
)) {
1868 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1869 struct wpa_scan_results
*scan_res
);
1871 scan_res_handler
= wpa_s
->scan_res_handler
;
1872 wpa_s
->scan_res_handler
= NULL
;
1873 scan_res_handler(wpa_s
, scan_res
);
1875 goto scan_work_done
;
1879 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1881 if (wpa_s
->ap_iface
->scan_cb
)
1882 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1883 #endif /* CONFIG_AP */
1884 goto scan_work_done
;
1887 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1888 wpa_s
->own_scan_running
,
1889 data
? data
->scan_info
.external_scan
: 0);
1890 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1891 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1892 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1893 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1894 wpa_s
->manual_scan_id
);
1895 wpa_s
->manual_scan_use_id
= 0;
1897 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1899 wpas_notify_scan_results(wpa_s
);
1901 wpas_notify_scan_done(wpa_s
, 1);
1903 if (data
&& data
->scan_info
.external_scan
) {
1904 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1905 wpa_scan_results_free(scan_res
);
1909 if (wnm_scan_process(wpa_s
, 1) > 0)
1910 goto scan_work_done
;
1912 if (sme_proc_obss_scan(wpa_s
) > 0)
1913 goto scan_work_done
;
1915 if (own_request
&& data
&&
1916 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1917 goto scan_work_done
;
1919 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1920 goto scan_work_done
;
1922 if (autoscan_notify_scan(wpa_s
, scan_res
))
1923 goto scan_work_done
;
1925 if (wpa_s
->disconnected
) {
1926 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1927 goto scan_work_done
;
1930 if (!wpas_driver_bss_selection(wpa_s
) &&
1931 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1932 goto scan_work_done
;
1934 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1936 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1937 wpa_s
->wpa_state
< WPA_COMPLETED
)
1938 goto scan_work_done
;
1940 wpa_scan_results_free(scan_res
);
1942 if (own_request
&& wpa_s
->scan_work
) {
1943 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1944 wpa_s
->scan_work
= NULL
;
1945 radio_work_done(work
);
1948 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1951 wpa_scan_results_free(scan_res
);
1952 if (own_request
&& wpa_s
->scan_work
) {
1953 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1954 wpa_s
->scan_work
= NULL
;
1955 radio_work_done(work
);
1961 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1962 int new_scan
, int own_request
)
1964 struct wpa_bss
*selected
;
1965 struct wpa_ssid
*ssid
= NULL
;
1966 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1968 if (time_to_reenable
> 0) {
1969 wpa_dbg(wpa_s
, MSG_DEBUG
,
1970 "Postpone network selection by %d seconds since all networks are disabled",
1972 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1973 eloop_register_timeout(time_to_reenable
, 0,
1974 wpas_network_reenabled
, wpa_s
, NULL
);
1978 if (wpa_s
->p2p_mgmt
)
1979 return 0; /* no normal connection on p2p_mgmt interface */
1981 wpa_s
->owe_transition_search
= 0;
1982 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1986 wpa_msg(wpa_s
, MSG_INFO
,
1987 "Avoiding join because we already joined a mesh group");
1990 #endif /* CONFIG_MESH */
1994 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1997 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2001 if (ssid
!= wpa_s
->current_ssid
&&
2002 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2003 wpa_s
->own_disconnect_req
= 1;
2004 wpa_supplicant_deauthenticate(
2005 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2008 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
2009 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
2013 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2015 * Do not allow other virtual radios to trigger operations based
2016 * on these scan results since we do not want them to start
2017 * other associations at the same time.
2021 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
2022 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
2024 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
2025 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
2027 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2028 } else if (own_request
) {
2030 * No SSID found. If SCAN results are as a result of
2031 * own scan request and not due to a scan request on
2032 * another shared interface, try another scan.
2034 int timeout_sec
= wpa_s
->scan_interval
;
2035 int timeout_usec
= 0;
2039 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
2045 if (wpa_s
->p2p_in_provisioning
||
2046 wpa_s
->show_group_started
||
2047 wpa_s
->p2p_in_invitation
) {
2049 * Use shorter wait during P2P Provisioning
2050 * state and during P2P join-a-group operation
2051 * to speed up group formation.
2054 timeout_usec
= 250000;
2055 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2059 #endif /* CONFIG_P2P */
2060 #ifdef CONFIG_INTERWORKING
2061 if (wpa_s
->conf
->auto_interworking
&&
2062 wpa_s
->conf
->interworking
&&
2063 wpa_s
->conf
->cred
) {
2064 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2065 "start ANQP fetch since no matching "
2067 wpa_s
->network_select
= 1;
2068 wpa_s
->auto_network_select
= 1;
2069 interworking_start_fetch_anqp(wpa_s
);
2072 #endif /* CONFIG_INTERWORKING */
2074 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2075 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2077 timeout_usec
= 500000;
2078 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2082 #endif /* CONFIG_WPS */
2084 if (wpa_s
->owe_transition_search
) {
2085 wpa_dbg(wpa_s
, MSG_DEBUG
,
2086 "OWE: Use shorter wait during transition mode search");
2088 timeout_usec
= 500000;
2089 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2093 #endif /* CONFIG_OWE */
2094 if (wpa_supplicant_req_sched_scan(wpa_s
))
2095 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2098 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2099 WPA_EVENT_NETWORK_NOT_FOUND
);
2106 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2107 union wpa_event_data
*data
)
2109 struct wpa_supplicant
*ifs
;
2112 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2115 * Interface may have been removed, so must not dereference
2123 * If no scan results could be fetched, then no need to
2124 * notify those interfaces that did not actually request
2125 * this scan. Similarly, if scan results started a new operation on this
2126 * interface, do not notify other interfaces to avoid concurrent
2127 * operations during a connection attempt.
2133 * Check other interfaces to see if they share the same radio. If
2134 * so, they get updated with this same scan info.
2136 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2139 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2140 "sibling", ifs
->ifname
);
2141 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2151 #endif /* CONFIG_NO_SCAN_PROCESSING */
2154 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2156 #ifdef CONFIG_NO_SCAN_PROCESSING
2158 #else /* CONFIG_NO_SCAN_PROCESSING */
2159 struct os_reltime now
;
2161 wpa_s
->ignore_post_flush_scan_res
= 0;
2163 if (wpa_s
->last_scan_res_used
== 0)
2166 os_get_reltime(&now
);
2167 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2168 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2172 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2173 #endif /* CONFIG_NO_SCAN_PROCESSING */
2178 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2180 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2182 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2185 if (!wpa_s
->no_keep_alive
) {
2186 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2187 MAC2STR(wpa_s
->bssid
));
2188 /* TODO: could skip this if normal data traffic has been sent */
2189 /* TODO: Consider using some more appropriate data frame for
2192 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2197 if (wpa_s
->sme
.bss_max_idle_period
) {
2199 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2202 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2203 wnm_bss_keep_alive
, wpa_s
, NULL
);
2205 #endif /* CONFIG_SME */
2209 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2210 const u8
*ies
, size_t ies_len
)
2212 struct ieee802_11_elems elems
;
2217 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2221 if (elems
.bss_max_idle_period
) {
2223 wpa_s
->sme
.bss_max_idle_period
=
2224 WPA_GET_LE16(elems
.bss_max_idle_period
);
2225 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2226 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2227 (elems
.bss_max_idle_period
[2] & 0x01) ?
2228 " (protected keep-live required)" : "");
2229 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2230 wpa_s
->sme
.bss_max_idle_period
= 1;
2231 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2232 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2233 /* msec times 1000 */
2234 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2237 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2238 wnm_bss_keep_alive
, wpa_s
,
2242 #endif /* CONFIG_SME */
2245 #endif /* CONFIG_WNM */
2248 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2251 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2252 #endif /* CONFIG_WNM */
2256 #ifdef CONFIG_INTERWORKING
2258 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2263 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2264 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2266 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2273 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2274 const u8
*ies
, size_t ies_len
)
2276 struct ieee802_11_elems elems
;
2281 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2284 if (elems
.qos_map_set
) {
2285 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2286 elems
.qos_map_set_len
);
2290 #endif /* CONFIG_INTERWORKING */
2293 static void multi_ap_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2294 const u8
*ies
, size_t ies_len
)
2296 struct ieee802_11_elems elems
;
2297 const u8
*map_sub_elem
, *pos
;
2300 if (!wpa_s
->current_ssid
||
2301 !wpa_s
->current_ssid
->multi_ap_backhaul_sta
||
2303 ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2306 if (!elems
.multi_ap
|| elems
.multi_ap_len
< 7) {
2307 wpa_printf(MSG_INFO
, "AP doesn't support Multi-AP protocol");
2311 pos
= elems
.multi_ap
+ 4;
2312 len
= elems
.multi_ap_len
- 4;
2314 map_sub_elem
= get_ie(pos
, len
, MULTI_AP_SUB_ELEM_TYPE
);
2315 if (!map_sub_elem
|| map_sub_elem
[1] < 1) {
2316 wpa_printf(MSG_INFO
, "invalid Multi-AP sub elem type");
2320 if (!(map_sub_elem
[2] & MULTI_AP_BACKHAUL_BSS
)) {
2321 if ((map_sub_elem
[2] & MULTI_AP_FRONTHAUL_BSS
) &&
2322 wpa_s
->current_ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
2323 wpa_printf(MSG_INFO
,
2324 "WPS active, accepting fronthaul-only BSS");
2325 /* Don't set 4addr mode in this case, so just return */
2328 wpa_printf(MSG_INFO
, "AP doesn't support backhaul BSS");
2332 if (wpa_drv_set_4addr_mode(wpa_s
, 1) < 0) {
2333 wpa_printf(MSG_ERROR
, "Failed to set 4addr mode");
2336 wpa_s
->enabled_4addr_mode
= 1;
2340 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2345 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2346 const u8
*ie
, size_t ie_len
)
2348 struct mb_ies_info mb_ies
;
2350 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2353 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2355 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2360 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2365 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2366 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2367 (unsigned int) len
);
2368 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2369 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2377 if (mb_ies
.nof_ies
> 0) {
2378 wpabuf_free(wpa_s
->received_mb_ies
);
2379 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2385 #endif /* CONFIG_FST */
2388 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2389 union wpa_event_data
*data
)
2391 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2393 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2395 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2397 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2398 if (data
->assoc_info
.req_ies
)
2399 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2400 data
->assoc_info
.req_ies_len
);
2401 if (data
->assoc_info
.resp_ies
) {
2402 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2403 data
->assoc_info
.resp_ies_len
);
2405 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2406 data
->assoc_info
.resp_ies_len
);
2407 #endif /* CONFIG_TDLS */
2409 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2410 data
->assoc_info
.resp_ies_len
);
2411 #endif /* CONFIG_WNM */
2412 #ifdef CONFIG_INTERWORKING
2413 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2414 data
->assoc_info
.resp_ies_len
);
2415 #endif /* CONFIG_INTERWORKING */
2416 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2417 get_ie(data
->assoc_info
.resp_ies
,
2418 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2419 wpa_s
->ieee80211ac
= 1;
2421 multi_ap_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2422 data
->assoc_info
.resp_ies_len
);
2424 if (data
->assoc_info
.beacon_ies
)
2425 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2426 data
->assoc_info
.beacon_ies
,
2427 data
->assoc_info
.beacon_ies_len
);
2428 if (data
->assoc_info
.freq
)
2429 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2430 data
->assoc_info
.freq
);
2432 wpa_s
->connection_set
= 0;
2433 if (data
->assoc_info
.req_ies
&& data
->assoc_info
.resp_ies
) {
2434 struct ieee802_11_elems req_elems
, resp_elems
;
2436 if (ieee802_11_parse_elems(data
->assoc_info
.req_ies
,
2437 data
->assoc_info
.req_ies_len
,
2438 &req_elems
, 0) != ParseFailed
&&
2439 ieee802_11_parse_elems(data
->assoc_info
.resp_ies
,
2440 data
->assoc_info
.resp_ies_len
,
2441 &resp_elems
, 0) != ParseFailed
) {
2442 wpa_s
->connection_set
= 1;
2443 wpa_s
->connection_ht
= req_elems
.ht_capabilities
&&
2444 resp_elems
.ht_capabilities
;
2445 wpa_s
->connection_vht
= req_elems
.vht_capabilities
&&
2446 resp_elems
.vht_capabilities
;
2447 wpa_s
->connection_he
= req_elems
.he_capabilities
&&
2448 resp_elems
.he_capabilities
;
2452 p
= data
->assoc_info
.req_ies
;
2453 l
= data
->assoc_info
.req_ies_len
;
2455 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2456 while (p
&& l
>= 2) {
2459 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2463 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2464 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2465 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2466 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2467 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2468 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2471 wpa_find_assoc_pmkid(wpa_s
);
2477 if (!found
&& data
->assoc_info
.req_ies
)
2478 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2482 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2483 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2484 (!data
->assoc_info
.resp_frame
||
2485 fils_process_assoc_resp(wpa_s
->wpa
,
2486 data
->assoc_info
.resp_frame
,
2487 data
->assoc_info
.resp_frame_len
) < 0)) {
2488 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2491 #endif /* CONFIG_SME */
2493 /* Additional processing for FILS when SME is in driver */
2494 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2495 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2496 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2497 #endif /* CONFIG_FILS */
2500 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2501 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2502 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2503 data
->assoc_info
.resp_ies
,
2504 data
->assoc_info
.resp_ies_len
) < 0)) {
2505 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2508 #endif /* CONFIG_OWE */
2511 wpa_sm_set_dpp_z(wpa_s
->wpa
, NULL
);
2512 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
&& wpa_s
->dpp_pfs
) {
2513 struct ieee802_11_elems elems
;
2515 if (ieee802_11_parse_elems(data
->assoc_info
.resp_ies
,
2516 data
->assoc_info
.resp_ies_len
,
2517 &elems
, 0) == ParseFailed
||
2520 if (dpp_pfs_process(wpa_s
->dpp_pfs
, elems
.owe_dh
,
2521 elems
.owe_dh_len
) < 0) {
2522 wpa_supplicant_deauthenticate(wpa_s
,
2523 WLAN_REASON_UNSPECIFIED
);
2527 wpa_sm_set_dpp_z(wpa_s
->wpa
, wpa_s
->dpp_pfs
->secret
);
2530 #endif /* CONFIG_DPP2 */
2532 #ifdef CONFIG_IEEE80211R
2534 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2535 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2536 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2537 data
->assoc_info
.resp_ies
,
2538 data
->assoc_info
.resp_ies_len
,
2540 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2541 "Reassociation Response failed");
2542 wpa_supplicant_deauthenticate(
2543 wpa_s
, WLAN_REASON_INVALID_IE
);
2548 p
= data
->assoc_info
.resp_ies
;
2549 l
= data
->assoc_info
.resp_ies_len
;
2551 #ifdef CONFIG_WPS_STRICT
2552 if (p
&& wpa_s
->current_ssid
&&
2553 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2555 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2557 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2558 "include WPS IE in (Re)Association Response");
2562 if (wps_validate_assoc_resp(wps
) < 0) {
2564 wpa_supplicant_deauthenticate(
2565 wpa_s
, WLAN_REASON_INVALID_IE
);
2570 #endif /* CONFIG_WPS_STRICT */
2572 /* Go through the IEs and make a copy of the MDIE, if present. */
2573 while (p
&& l
>= 2) {
2576 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2580 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2581 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2582 wpa_s
->sme
.ft_used
= 1;
2583 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2584 MOBILITY_DOMAIN_ID_LEN
);
2590 #endif /* CONFIG_SME */
2592 /* Process FT when SME is in the driver */
2593 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2594 wpa_ft_is_completed(wpa_s
->wpa
)) {
2595 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2596 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2597 data
->assoc_info
.resp_ies
,
2598 data
->assoc_info
.resp_ies_len
,
2600 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2601 "Reassociation Response failed");
2602 wpa_supplicant_deauthenticate(
2603 wpa_s
, WLAN_REASON_INVALID_IE
);
2606 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2609 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2610 data
->assoc_info
.resp_ies_len
);
2611 #endif /* CONFIG_IEEE80211R */
2613 /* WPA/RSN IE from Beacon/ProbeResp */
2614 p
= data
->assoc_info
.beacon_ies
;
2615 l
= data
->assoc_info
.beacon_ies_len
;
2617 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2619 wpa_found
= rsn_found
= 0;
2620 while (p
&& l
>= 2) {
2623 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2628 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2629 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2631 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2635 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2637 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2644 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2645 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2646 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2647 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2648 if (wpa_found
|| rsn_found
)
2649 wpa_s
->ap_ies_from_associnfo
= 1;
2651 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2652 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2653 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2655 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2656 wpa_supplicant_update_scan_results(wpa_s
);
2659 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2665 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2667 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2669 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2672 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2675 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2676 WPA_IE_VENDOR_TYPE
);
2677 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2679 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2680 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2681 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2682 bss_rsn
? 2 + bss_rsn
[1] : 0))
2689 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2690 union wpa_event_data
*data
)
2693 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2694 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2695 const u8
*ieprb
, *iebcn
;
2697 wpabuf_free(wpa_s
->received_mb_ies
);
2698 wpa_s
->received_mb_ies
= NULL
;
2701 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2702 wpa_printf(MSG_DEBUG
,
2703 "FST: MB IEs updated from Association Response frame");
2708 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2709 wpa_printf(MSG_DEBUG
,
2710 "FST: MB IEs updated from association event Beacon IEs");
2717 ieprb
= (const u8
*) (bss
+ 1);
2718 iebcn
= ieprb
+ bss
->ie_len
;
2720 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2721 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2722 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2723 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2724 #endif /* CONFIG_FST */
2728 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2729 union wpa_event_data
*data
)
2732 int ft_completed
, already_authorized
;
2736 if (wpa_s
->ap_iface
) {
2739 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2740 data
->assoc_info
.addr
,
2741 data
->assoc_info
.req_ies
,
2742 data
->assoc_info
.req_ies_len
,
2743 data
->assoc_info
.reassoc
);
2746 #endif /* CONFIG_AP */
2748 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2750 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2751 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2754 * FILS authentication can share the same mechanism to mark the
2755 * connection fully authenticated, so set ft_completed also based on
2759 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2761 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2762 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2763 wpa_supplicant_deauthenticate(
2764 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2768 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2769 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2770 if (os_reltime_initialized(&wpa_s
->session_start
)) {
2771 os_reltime_age(&wpa_s
->session_start
,
2772 &wpa_s
->session_length
);
2773 wpa_s
->session_start
.sec
= 0;
2774 wpa_s
->session_start
.usec
= 0;
2775 wpas_notify_session_length(wpa_s
);
2777 wpas_notify_auth_changed(wpa_s
);
2778 os_get_reltime(&wpa_s
->session_start
);
2780 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2781 MACSTR
, MAC2STR(bssid
));
2783 random_add_randomness(bssid
, ETH_ALEN
);
2784 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2785 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2786 wpas_notify_bssid_changed(wpa_s
);
2788 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2789 wpa_clear_keys(wpa_s
, bssid
);
2791 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2792 wpa_supplicant_deauthenticate(
2793 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2798 if (wpa_s
->conf
->ap_scan
== 1 &&
2799 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2800 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2801 wpa_msg(wpa_s
, MSG_WARNING
,
2802 "WPA/RSN IEs not updated");
2805 wpas_fst_update_mb_assoc(wpa_s
, data
);
2808 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2809 wpa_s
->sme
.prev_bssid_set
= 1;
2810 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2811 #endif /* CONFIG_SME */
2813 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2814 if (wpa_s
->current_ssid
) {
2815 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2816 * initialized before association, but for other modes,
2817 * initialize PC/SC here, if the current configuration needs
2818 * smartcard or SIM/USIM. */
2819 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2821 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2823 l2_packet_notify_auth_start(wpa_s
->l2
);
2825 already_authorized
= data
&& data
->assoc_info
.authorized
;
2828 * Set portEnabled first to FALSE in order to get EAP state machine out
2829 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2830 * state machine may transit to AUTHENTICATING state based on obsolete
2831 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2832 * AUTHENTICATED without ever giving chance to EAP state machine to
2835 if (!ft_completed
&& !already_authorized
) {
2836 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2837 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2839 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2840 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2841 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2842 already_authorized
|| wpa_s
->drv_authorized_port
)
2843 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2844 /* 802.1X::portControl = Auto */
2845 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2846 wpa_s
->eapol_received
= 0;
2847 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2848 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2849 (wpa_s
->current_ssid
&&
2850 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
)) {
2851 if (wpa_s
->current_ssid
&&
2852 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2854 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2856 * Set the key after having received joined-IBSS event
2859 wpa_supplicant_set_wpa_none_key(wpa_s
,
2860 wpa_s
->current_ssid
);
2862 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2863 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2864 } else if (!ft_completed
) {
2865 /* Timeout for receiving the first EAPOL packet */
2866 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2868 wpa_supplicant_cancel_scan(wpa_s
);
2872 * FT protocol completed - make sure EAPOL state machine ends
2873 * up in authenticated.
2875 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2876 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2877 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2878 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2879 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK
) &&
2880 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2882 * We are done; the driver will take care of RSN 4-way
2885 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2886 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2887 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2888 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2889 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X
) &&
2890 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2892 * The driver will take care of RSN 4-way handshake, so we need
2893 * to allow EAPOL supplicant to complete its work without
2894 * waiting for WPA supplicant.
2896 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2899 wpa_s
->last_eapol_matches_bssid
= 0;
2901 if (wpa_s
->pending_eapol_rx
) {
2902 struct os_reltime now
, age
;
2903 os_get_reltime(&now
);
2904 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2905 if (age
.sec
== 0 && age
.usec
< 200000 &&
2906 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2908 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2909 "frame that was received just before "
2910 "association notification");
2911 wpa_supplicant_rx_eapol(
2912 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2913 wpabuf_head(wpa_s
->pending_eapol_rx
),
2914 wpabuf_len(wpa_s
->pending_eapol_rx
));
2916 wpabuf_free(wpa_s
->pending_eapol_rx
);
2917 wpa_s
->pending_eapol_rx
= NULL
;
2920 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2921 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2922 wpa_s
->current_ssid
&&
2923 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2924 /* Set static WEP keys again */
2925 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2928 #ifdef CONFIG_IBSS_RSN
2929 if (wpa_s
->current_ssid
&&
2930 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2931 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2932 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2933 wpa_s
->ibss_rsn
== NULL
) {
2934 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2935 if (!wpa_s
->ibss_rsn
) {
2936 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2937 wpa_supplicant_deauthenticate(
2938 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2942 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2944 #endif /* CONFIG_IBSS_RSN */
2946 wpas_wps_notify_assoc(wpa_s
, bssid
);
2949 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2950 data
->assoc_info
.resp_ies_len
,
2951 &data
->assoc_info
.wmm_params
);
2953 if (wpa_s
->reassoc_same_bss
)
2954 wmm_ac_restore_tspecs(wpa_s
);
2958 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2959 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2960 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2963 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2965 #endif /* CONFIG_FILS */
2969 static int disconnect_reason_recoverable(u16 reason_code
)
2971 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2972 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2973 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2977 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2979 int locally_generated
)
2983 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2985 * At least Host AP driver and a Prism3 card seemed to be
2986 * generating streams of disconnected events when configuring
2987 * IBSS for WPA-None. Ignore them for now.
2992 bssid
= wpa_s
->bssid
;
2993 if (is_zero_ether_addr(bssid
))
2994 bssid
= wpa_s
->pending_bssid
;
2996 if (!is_zero_ether_addr(bssid
) ||
2997 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2998 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
3000 MAC2STR(bssid
), reason_code
,
3001 locally_generated
? " locally_generated=1" : "");
3006 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
3007 int locally_generated
)
3009 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
3010 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
3011 return 0; /* Not in 4-way handshake with PSK */
3014 * It looks like connection was lost while trying to go through PSK
3015 * 4-way handshake. Filter out known disconnection cases that are caused
3016 * by something else than PSK mismatch to avoid confusing reports.
3019 if (locally_generated
) {
3020 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
3028 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
3030 int locally_generated
)
3034 u8 prev_pending_bssid
[ETH_ALEN
];
3035 struct wpa_bss
*fast_reconnect
= NULL
;
3036 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
3037 struct wpa_ssid
*last_ssid
;
3038 struct wpa_bss
*curr
= NULL
;
3040 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
3041 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
3043 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
3045 * At least Host AP driver and a Prism3 card seemed to be
3046 * generating streams of disconnected events when configuring
3047 * IBSS for WPA-None. Ignore them for now.
3049 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
3050 "IBSS/WPA-None mode");
3054 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
3055 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
3058 * Remove the inactive AP (which is probably out of range) from
3059 * the BSS list after marking disassociation. In particular
3060 * mac80211-based drivers use the
3061 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
3062 * locally generated disconnection events for cases where the
3063 * AP does not reply anymore.
3065 curr
= wpa_s
->current_bss
;
3067 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
3068 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
3069 "pre-shared key may be incorrect");
3070 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
3071 return; /* P2P group removed */
3072 wpas_auth_failed(wpa_s
, "WRONG_KEY");
3074 if (!wpa_s
->disconnected
&&
3075 (!wpa_s
->auto_reconnect_disabled
||
3076 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
3077 wpas_wps_searching(wpa_s
) ||
3078 wpas_wps_reenable_networks_pending(wpa_s
))) {
3079 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
3080 "reconnect (wps=%d/%d wpa_state=%d)",
3081 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
3082 wpas_wps_searching(wpa_s
),
3084 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
3085 wpa_s
->current_ssid
&&
3086 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
3087 !locally_generated
&&
3088 disconnect_reason_recoverable(reason_code
)) {
3090 * It looks like the AP has dropped association with
3091 * us, but could allow us to get back in. Try to
3092 * reconnect to the same BSS without full scan to save
3093 * time for some common cases.
3095 fast_reconnect
= wpa_s
->current_bss
;
3096 fast_reconnect_ssid
= wpa_s
->current_ssid
;
3097 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
3098 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3100 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
3103 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
3104 "try to re-connect");
3105 wpa_s
->reassociate
= 0;
3106 wpa_s
->disconnected
= 1;
3108 wpa_supplicant_cancel_sched_scan(wpa_s
);
3110 bssid
= wpa_s
->bssid
;
3111 if (is_zero_ether_addr(bssid
))
3112 bssid
= wpa_s
->pending_bssid
;
3113 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3114 wpas_connection_failed(wpa_s
, bssid
);
3115 wpa_sm_notify_disassoc(wpa_s
->wpa
);
3116 if (locally_generated
)
3117 wpa_s
->disconnect_reason
= -reason_code
;
3119 wpa_s
->disconnect_reason
= reason_code
;
3120 wpas_notify_disconnect_reason(wpa_s
);
3121 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
3122 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
3123 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
3125 last_ssid
= wpa_s
->current_ssid
;
3126 wpa_supplicant_mark_disassoc(wpa_s
);
3129 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
3131 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
3132 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
3133 wpa_s
->current_ssid
= last_ssid
;
3136 if (fast_reconnect
&&
3137 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
3138 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
3139 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
3140 fast_reconnect
->ssid_len
) &&
3141 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
3142 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
)) {
3143 #ifndef CONFIG_NO_SCAN_PROCESSING
3144 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
3145 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
3146 fast_reconnect_ssid
) < 0) {
3147 /* Recover through full scan */
3148 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3150 #endif /* CONFIG_NO_SCAN_PROCESSING */
3151 } else if (fast_reconnect
) {
3153 * Could not reconnect to the same BSS due to network being
3154 * disabled. Use a new scan to match the alternative behavior
3155 * above, i.e., to continue automatic reconnection attempt in a
3156 * way that enforces disabled network rules.
3158 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3163 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3164 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
3166 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3168 if (!wpa_s
->pending_mic_error_report
)
3171 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3172 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3173 wpa_s
->pending_mic_error_report
= 0;
3175 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3179 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3180 union wpa_event_data
*data
)
3183 struct os_reltime t
;
3185 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3186 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3188 if ((wpa_s
->last_michael_mic_error
.sec
&&
3189 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3190 wpa_s
->pending_mic_error_report
) {
3191 if (wpa_s
->pending_mic_error_report
) {
3193 * Send the pending MIC error report immediately since
3194 * we are going to start countermeasures and AP better
3197 wpa_sm_key_request(wpa_s
->wpa
, 1,
3198 wpa_s
->pending_mic_error_pairwise
);
3201 /* Send the new MIC error report immediately since we are going
3202 * to start countermeasures and AP better do the same.
3204 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3206 /* initialize countermeasures */
3207 wpa_s
->countermeasures
= 1;
3209 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3211 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3214 * Need to wait for completion of request frame. We do not get
3215 * any callback for the message completion, so just wait a
3216 * short while and hope for the best. */
3219 wpa_drv_set_countermeasures(wpa_s
, 1);
3220 wpa_supplicant_deauthenticate(wpa_s
,
3221 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3222 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3224 eloop_register_timeout(60, 0,
3225 wpa_supplicant_stop_countermeasures
,
3227 /* TODO: mark the AP rejected for 60 second. STA is
3228 * allowed to associate with another AP.. */
3230 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3231 if (wpa_s
->mic_errors_seen
) {
3233 * Reduce the effectiveness of Michael MIC error
3234 * reports as a means for attacking against TKIP if
3235 * more than one MIC failure is noticed with the same
3236 * PTK. We delay the transmission of the reports by a
3237 * random time between 0 and 60 seconds in order to
3238 * force the attacker wait 60 seconds before getting
3239 * the information on whether a frame resulted in a MIC
3245 if (os_get_random(rval
, sizeof(rval
)) < 0)
3246 sec
= os_random() % 60;
3248 sec
= WPA_GET_BE32(rval
) % 60;
3249 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3250 "report %d seconds", sec
);
3251 wpa_s
->pending_mic_error_report
= 1;
3252 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3253 eloop_cancel_timeout(
3254 wpa_supplicant_delayed_mic_error_report
,
3256 eloop_register_timeout(
3257 sec
, os_random() % 1000000,
3258 wpa_supplicant_delayed_mic_error_report
,
3261 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3263 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3264 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3265 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3267 wpa_s
->last_michael_mic_error
= t
;
3268 wpa_s
->mic_errors_seen
++;
3272 #ifdef CONFIG_TERMINATE_ONLASTIF
3273 static int any_interfaces(struct wpa_supplicant
*head
)
3275 struct wpa_supplicant
*wpa_s
;
3277 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3278 if (!wpa_s
->interface_removed
)
3282 #endif /* CONFIG_TERMINATE_ONLASTIF */
3286 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3287 union wpa_event_data
*data
)
3289 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3292 switch (data
->interface_status
.ievent
) {
3293 case EVENT_INTERFACE_ADDED
:
3294 if (!wpa_s
->interface_removed
)
3296 wpa_s
->interface_removed
= 0;
3297 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3298 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3299 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3300 "driver after interface was added");
3304 if (!wpa_s
->global
->p2p
&&
3305 !wpa_s
->global
->p2p_disabled
&&
3306 !wpa_s
->conf
->p2p_disabled
&&
3308 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3309 wpas_p2p_add_p2pdev_interface(
3310 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3311 wpa_printf(MSG_INFO
,
3312 "P2P: Failed to enable P2P Device interface");
3313 /* Try to continue without. P2P will be disabled. */
3315 #endif /* CONFIG_P2P */
3318 case EVENT_INTERFACE_REMOVED
:
3319 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3320 wpa_s
->interface_removed
= 1;
3321 wpa_supplicant_mark_disassoc(wpa_s
);
3322 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3323 l2_packet_deinit(wpa_s
->l2
);
3327 if (wpa_s
->global
->p2p
&&
3328 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3330 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3331 wpa_dbg(wpa_s
, MSG_DEBUG
,
3332 "Removing P2P Device interface");
3333 wpa_supplicant_remove_iface(
3334 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3336 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3338 #endif /* CONFIG_P2P */
3340 #ifdef CONFIG_MATCH_IFACE
3341 if (wpa_s
->matched
) {
3342 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3345 #endif /* CONFIG_MATCH_IFACE */
3347 #ifdef CONFIG_TERMINATE_ONLASTIF
3348 /* check if last interface */
3349 if (!any_interfaces(wpa_s
->global
->ifaces
))
3351 #endif /* CONFIG_TERMINATE_ONLASTIF */
3358 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3359 union wpa_event_data
*data
)
3363 switch (data
->tdls
.oper
) {
3364 case TDLS_REQUEST_SETUP
:
3365 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3366 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3367 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3369 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3371 case TDLS_REQUEST_TEARDOWN
:
3372 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3373 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3374 data
->tdls
.reason_code
);
3376 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3379 case TDLS_REQUEST_DISCOVER
:
3380 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3385 #endif /* CONFIG_TDLS */
3389 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3390 union wpa_event_data
*data
)
3394 switch (data
->wnm
.oper
) {
3395 case WNM_OPER_SLEEP
:
3396 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3397 "(action=%d, intval=%d)",
3398 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3399 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3400 data
->wnm
.sleep_intval
, NULL
);
3404 #endif /* CONFIG_WNM */
3407 #ifdef CONFIG_IEEE80211R
3409 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3410 union wpa_event_data
*data
)
3415 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3416 data
->ft_ies
.ies_len
,
3417 data
->ft_ies
.ft_action
,
3418 data
->ft_ies
.target_ap
,
3419 data
->ft_ies
.ric_ies
,
3420 data
->ft_ies
.ric_ies_len
) < 0) {
3421 /* TODO: prevent MLME/driver from trying to associate? */
3424 #endif /* CONFIG_IEEE80211R */
3427 #ifdef CONFIG_IBSS_RSN
3428 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3429 union wpa_event_data
*data
)
3431 struct wpa_ssid
*ssid
;
3432 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3436 ssid
= wpa_s
->current_ssid
;
3439 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3442 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3446 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3447 union wpa_event_data
*data
)
3449 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3454 /* check if the ssid is correctly configured as IBSS/RSN */
3455 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3458 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3459 data
->rx_mgmt
.frame_len
);
3461 #endif /* CONFIG_IBSS_RSN */
3464 #ifdef CONFIG_IEEE80211R
3465 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3468 const u8
*sta_addr
, *target_ap_addr
;
3471 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3472 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3473 return; /* only SME case supported for now */
3474 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3477 return; /* Only FT Action Response is supported for now */
3478 sta_addr
= data
+ 1;
3479 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3480 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3481 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3482 MACSTR
" TargetAP " MACSTR
" status %u",
3483 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3485 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3486 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3487 " in FT Action Response", MAC2STR(sta_addr
));
3492 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3493 "failure (status code %d)", status
);
3494 /* TODO: report error to FT code(?) */
3498 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3499 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3500 target_ap_addr
, NULL
, 0) < 0)
3505 struct wpa_bss
*bss
;
3506 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3508 wpa_s
->sme
.freq
= bss
->freq
;
3509 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3510 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3513 #endif /* CONFIG_SME */
3515 #endif /* CONFIG_IEEE80211R */
3518 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3519 struct unprot_deauth
*e
)
3521 #ifdef CONFIG_IEEE80211W
3522 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3523 "dropped: " MACSTR
" -> " MACSTR
3524 " (reason code %u)",
3525 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3526 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3527 #endif /* CONFIG_IEEE80211W */
3531 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3532 struct unprot_disassoc
*e
)
3534 #ifdef CONFIG_IEEE80211W
3535 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3536 "dropped: " MACSTR
" -> " MACSTR
3537 " (reason code %u)",
3538 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3539 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3540 #endif /* CONFIG_IEEE80211W */
3544 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3545 u16 reason_code
, int locally_generated
,
3546 const u8
*ie
, size_t ie_len
, int deauth
)
3549 if (wpa_s
->ap_iface
&& addr
) {
3550 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3554 if (wpa_s
->ap_iface
) {
3555 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3558 #endif /* CONFIG_AP */
3560 if (!locally_generated
)
3561 wpa_s
->own_disconnect_req
= 0;
3563 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3565 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3566 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3567 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3568 eapol_sm_failed(wpa_s
->eapol
))) &&
3569 !wpa_s
->eap_expected_failure
))
3570 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3573 if (deauth
&& reason_code
> 0) {
3574 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3575 locally_generated
) > 0) {
3577 * The interface was removed, so cannot continue
3578 * processing any additional operations after this.
3583 #endif /* CONFIG_P2P */
3585 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3590 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3591 struct disassoc_info
*info
)
3593 u16 reason_code
= 0;
3594 int locally_generated
= 0;
3595 const u8
*addr
= NULL
;
3596 const u8
*ie
= NULL
;
3599 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3604 ie_len
= info
->ie_len
;
3605 reason_code
= info
->reason_code
;
3606 locally_generated
= info
->locally_generated
;
3607 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u (%s)%s", reason_code
,
3608 reason2str(reason_code
),
3609 locally_generated
? " locally_generated=1" : "");
3611 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3613 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3618 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3619 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3623 if (wpa_s
->ap_iface
) {
3624 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3627 #endif /* CONFIG_AP */
3631 wpas_p2p_disassoc_notif(
3632 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3635 #endif /* CONFIG_P2P */
3637 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3638 sme_event_disassoc(wpa_s
, info
);
3640 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3645 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3646 struct deauth_info
*info
)
3648 u16 reason_code
= 0;
3649 int locally_generated
= 0;
3650 const u8
*addr
= NULL
;
3651 const u8
*ie
= NULL
;
3654 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3659 ie_len
= info
->ie_len
;
3660 reason_code
= info
->reason_code
;
3661 locally_generated
= info
->locally_generated
;
3662 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u (%s)%s",
3663 reason_code
, reason2str(reason_code
),
3664 locally_generated
? " locally_generated=1" : "");
3666 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3669 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3673 wpa_reset_ft_completed(wpa_s
->wpa
);
3675 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3676 locally_generated
, ie
, ie_len
, 1);
3680 static const char * reg_init_str(enum reg_change_initiator init
)
3683 case REGDOM_SET_BY_CORE
:
3685 case REGDOM_SET_BY_USER
:
3687 case REGDOM_SET_BY_DRIVER
:
3689 case REGDOM_SET_BY_COUNTRY_IE
:
3690 return "COUNTRY_IE";
3691 case REGDOM_BEACON_HINT
:
3692 return "BEACON_HINT";
3698 static const char * reg_type_str(enum reg_type type
)
3701 case REGDOM_TYPE_UNKNOWN
:
3703 case REGDOM_TYPE_COUNTRY
:
3705 case REGDOM_TYPE_WORLD
:
3707 case REGDOM_TYPE_CUSTOM_WORLD
:
3708 return "CUSTOM_WORLD";
3709 case REGDOM_TYPE_INTERSECTION
:
3710 return "INTERSECTION";
3716 void wpa_supplicant_update_channel_list(struct wpa_supplicant
*wpa_s
,
3717 struct channel_list_changed
*info
)
3719 struct wpa_supplicant
*ifs
;
3723 * To allow backwards compatibility with higher level layers that
3724 * assumed the REGDOM_CHANGE event is sent over the initially added
3725 * interface. Find the highest parent of this interface and use it to
3728 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3732 wpa_msg(ifs
, MSG_INFO
,
3733 WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3734 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3735 info
->alpha2
[0] ? " alpha2=" : "",
3736 info
->alpha2
[0] ? info
->alpha2
: "");
3739 if (wpa_s
->drv_priv
== NULL
)
3740 return; /* Ignore event during drv initialization */
3742 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3744 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3746 free_hw_features(ifs
);
3747 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3748 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3750 /* Restart PNO/sched_scan with updated channel list */
3753 wpas_start_pno(ifs
);
3754 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3755 wpa_dbg(ifs
, MSG_DEBUG
,
3756 "Channel list changed - restart sched_scan");
3757 wpas_scan_restart_sched_scan(ifs
);
3761 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3765 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3766 const u8
*frame
, size_t len
, int freq
,
3769 const struct ieee80211_mgmt
*mgmt
;
3774 if (len
< IEEE80211_HDRLEN
+ 2)
3777 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3778 payload
= frame
+ IEEE80211_HDRLEN
;
3779 category
= *payload
++;
3780 plen
= len
- IEEE80211_HDRLEN
- 1;
3782 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3783 " Category=%u DataLen=%d freq=%d MHz",
3784 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3786 if (category
== WLAN_ACTION_WMM
) {
3787 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3791 #ifdef CONFIG_IEEE80211R
3792 if (category
== WLAN_ACTION_FT
) {
3793 ft_rx_action(wpa_s
, payload
, plen
);
3796 #endif /* CONFIG_IEEE80211R */
3798 #ifdef CONFIG_IEEE80211W
3800 if (category
== WLAN_ACTION_SA_QUERY
) {
3801 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3804 #endif /* CONFIG_SME */
3805 #endif /* CONFIG_IEEE80211W */
3808 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3809 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3812 #endif /* CONFIG_WNM */
3815 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3816 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3817 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3818 mgmt
->u
.action
.category
,
3819 payload
, plen
, freq
) == 0)
3821 #endif /* CONFIG_GAS */
3823 #ifdef CONFIG_GAS_SERVER
3824 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3825 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3826 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3827 mgmt
->u
.action
.category
,
3828 payload
, plen
, freq
) == 0)
3830 #endif /* CONFIG_GAS_SERVER */
3833 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3834 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3835 wpa_dbg(wpa_s
, MSG_DEBUG
,
3836 "TDLS: Received Discovery Response from " MACSTR
,
3840 #endif /* CONFIG_TDLS */
3842 #ifdef CONFIG_INTERWORKING
3843 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3844 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3845 const u8
*pos
= payload
+ 1;
3846 size_t qlen
= plen
- 1;
3847 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3848 MACSTR
, MAC2STR(mgmt
->sa
));
3849 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3850 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3851 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3852 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3855 #endif /* CONFIG_INTERWORKING */
3857 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3858 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3859 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3866 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3867 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3868 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3872 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3873 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3874 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3875 payload
+ 1, plen
- 1,
3881 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3882 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3885 #endif /* CONFIG_FST */
3888 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3889 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3890 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3891 payload
[4] == DPP_OUI_TYPE
) {
3894 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3897 #endif /* CONFIG_DPP */
3899 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3900 category
, payload
, plen
, freq
);
3902 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3906 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3907 union wpa_event_data
*event
)
3909 struct wpa_freq_range_list
*list
;
3912 list
= &event
->freq_range
;
3915 str
= freq_range_list_str(list
);
3916 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3920 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3921 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3924 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3927 * The update channel flow will also take care of moving a GO
3928 * from the unsafe frequency if needed.
3930 wpas_p2p_update_channel_list(wpa_s
,
3931 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3933 #endif /* CONFIG_P2P */
3939 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
3941 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3942 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3943 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3944 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3945 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3946 wpa_s
->drv_authorized_port
= 1;
3951 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
3957 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
3958 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
3960 for (j
= 0; j
< mode
->num_channels
; j
++) {
3961 const struct hostapd_channel_data
*chan
;
3963 chan
= &mode
->channels
[j
];
3964 if (chan
->freq
== freq
)
3965 return chan
->dfs_cac_ms
;
3973 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
3974 struct dfs_event
*radar
)
3976 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3977 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
3978 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
3980 #endif /* NEED_AP_MLME && CONFIG_AP */
3982 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
3984 cac_time
/= 1000; /* convert from ms to sec */
3986 cac_time
= 10 * 60; /* max timeout: 10 minutes */
3988 /* Restart auth timeout: CAC time added to initial timeout */
3989 wpas_auth_timeout_restart(wpa_s
, cac_time
);
3994 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
3995 struct dfs_event
*radar
)
3997 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3998 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
3999 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
4001 #endif /* NEED_AP_MLME && CONFIG_AP */
4003 /* Restart auth timeout with original value after CAC is
4005 wpas_auth_timeout_restart(wpa_s
, 0);
4010 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
4011 struct dfs_event
*radar
)
4013 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
4014 if (wpa_s
->ap_iface
|| wpa_s
->ifmsh
) {
4015 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
4017 #endif /* NEED_AP_MLME && CONFIG_AP */
4019 /* Restart auth timeout with original value after CAC is
4021 wpas_auth_timeout_restart(wpa_s
, 0);
4026 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
4027 union wpa_event_data
*data
)
4029 wpa_dbg(wpa_s
, MSG_DEBUG
,
4030 "Connection authorized by device, previous state %d",
4033 wpa_supplicant_event_port_authorized(wpa_s
);
4035 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
4036 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
4037 data
->assoc_info
.ptk_kck_len
,
4038 data
->assoc_info
.ptk_kek
,
4039 data
->assoc_info
.ptk_kek_len
);
4041 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4042 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
4043 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
4045 /* Update ERP next sequence number */
4046 eapol_sm_update_erp_next_seq_num(
4047 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
4049 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
4050 /* Add the new PMK and PMKID to the PMKSA cache */
4051 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
4052 data
->assoc_info
.fils_pmk
,
4053 data
->assoc_info
.fils_pmk_len
,
4054 data
->assoc_info
.fils_pmkid
,
4055 wpa_s
->bssid
, fils_cache_id
);
4056 } else if (data
->assoc_info
.fils_pmkid
) {
4057 /* Update the current PMKSA used for this connection */
4058 pmksa_cache_set_current(wpa_s
->wpa
,
4059 data
->assoc_info
.fils_pmkid
,
4060 NULL
, NULL
, 0, NULL
, 0);
4063 #endif /* CONFIG_FILS */
4067 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
4068 union wpa_event_data
*data
)
4070 const u8
*bssid
= data
->assoc_reject
.bssid
;
4072 struct wpa_bss
*reject_bss
;
4073 #endif /* CONFIG_MBO */
4075 if (!bssid
|| is_zero_ether_addr(bssid
))
4076 bssid
= wpa_s
->pending_bssid
;
4078 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4079 reject_bss
= wpa_s
->current_bss
;
4081 reject_bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4082 #endif /* CONFIG_MBO */
4084 if (data
->assoc_reject
.bssid
)
4085 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
4086 "bssid=" MACSTR
" status_code=%u%s%s%s",
4087 MAC2STR(data
->assoc_reject
.bssid
),
4088 data
->assoc_reject
.status_code
,
4089 data
->assoc_reject
.timed_out
? " timeout" : "",
4090 data
->assoc_reject
.timeout_reason
? "=" : "",
4091 data
->assoc_reject
.timeout_reason
?
4092 data
->assoc_reject
.timeout_reason
: "");
4094 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
4095 "status_code=%u%s%s%s",
4096 data
->assoc_reject
.status_code
,
4097 data
->assoc_reject
.timed_out
? " timeout" : "",
4098 data
->assoc_reject
.timeout_reason
? "=" : "",
4099 data
->assoc_reject
.timeout_reason
?
4100 data
->assoc_reject
.timeout_reason
: "");
4101 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
4102 wpas_notify_assoc_status_code(wpa_s
);
4105 if (data
->assoc_reject
.status_code
==
4106 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
4107 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
4108 wpa_s
->current_ssid
&&
4109 wpa_s
->current_ssid
->owe_group
== 0 &&
4110 wpa_s
->last_owe_group
!= 21) {
4111 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4112 struct wpa_bss
*bss
= wpa_s
->current_bss
;
4115 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
4117 wpas_connection_failed(wpa_s
, bssid
);
4118 wpa_supplicant_mark_disassoc(wpa_s
);
4122 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
4123 wpas_connect_work_done(wpa_s
);
4124 wpa_supplicant_mark_disassoc(wpa_s
);
4125 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4128 #endif /* CONFIG_OWE */
4131 if (data
->assoc_reject
.status_code
==
4132 WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS
&&
4133 reject_bss
&& data
->assoc_reject
.resp_ies
) {
4136 rssi_rej
= mbo_get_attr_from_ies(
4137 data
->assoc_reject
.resp_ies
,
4138 data
->assoc_reject
.resp_ies_len
,
4139 OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT
);
4140 if (rssi_rej
&& rssi_rej
[1] == 2) {
4141 wpa_printf(MSG_DEBUG
,
4142 "OCE: RSSI-based association rejection from "
4143 MACSTR
" (Delta RSSI: %u, Retry Delay: %u)",
4144 MAC2STR(reject_bss
->bssid
),
4145 rssi_rej
[2], rssi_rej
[3]);
4146 wpa_bss_tmp_disallow(wpa_s
,
4149 rssi_rej
[2] + reject_bss
->level
);
4152 #endif /* CONFIG_MBO */
4154 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
4155 sme_event_assoc_reject(wpa_s
, data
);
4159 /* Driver-based SME cases */
4162 if (wpa_s
->current_ssid
&&
4163 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
4164 !data
->assoc_reject
.timed_out
) {
4165 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
4166 wpa_sm_aborted_cached(wpa_s
->wpa
);
4167 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4169 #endif /* CONFIG_SAE */
4172 if (wpa_s
->current_ssid
&&
4173 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_DPP
&&
4174 !data
->assoc_reject
.timed_out
) {
4175 wpa_dbg(wpa_s
, MSG_DEBUG
, "DPP: Drop PMKSA cache entry");
4176 wpa_sm_aborted_cached(wpa_s
->wpa
);
4177 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4179 #endif /* CONFIG_DPP */
4182 /* Update ERP next sequence number */
4183 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4184 eapol_sm_update_erp_next_seq_num(
4186 data
->assoc_reject
.fils_erp_next_seq_num
);
4187 fils_connection_failure(wpa_s
);
4189 #endif /* CONFIG_FILS */
4191 wpas_connection_failed(wpa_s
, bssid
);
4192 wpa_supplicant_mark_disassoc(wpa_s
);
4196 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
4197 union wpa_event_data
*data
)
4199 struct wpa_supplicant
*wpa_s
= ctx
;
4201 #ifndef CONFIG_NO_STDOUT_DEBUG
4202 int level
= MSG_DEBUG
;
4203 #endif /* CONFIG_NO_STDOUT_DEBUG */
4205 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
4206 event
!= EVENT_INTERFACE_ENABLED
&&
4207 event
!= EVENT_INTERFACE_STATUS
&&
4208 event
!= EVENT_SCAN_RESULTS
&&
4209 event
!= EVENT_SCHED_SCAN_STOPPED
) {
4210 wpa_dbg(wpa_s
, MSG_DEBUG
,
4211 "Ignore event %s (%d) while interface is disabled",
4212 event_to_string(event
), event
);
4216 #ifndef CONFIG_NO_STDOUT_DEBUG
4217 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
4218 const struct ieee80211_hdr
*hdr
;
4220 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4221 fc
= le_to_host16(hdr
->frame_control
);
4222 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4223 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4224 level
= MSG_EXCESSIVE
;
4227 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4228 event_to_string(event
), event
);
4229 #endif /* CONFIG_NO_STDOUT_DEBUG */
4234 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4235 data
->auth
.ies_len
))
4236 wpa_printf(MSG_DEBUG
,
4237 "FST: MB IEs updated from auth IE");
4238 #endif /* CONFIG_FST */
4239 sme_event_auth(wpa_s
, data
);
4240 wpa_s
->auth_status_code
= data
->auth
.status_code
;
4241 wpas_notify_auth_status_code(wpa_s
);
4244 #ifdef CONFIG_TESTING_OPTIONS
4245 if (wpa_s
->ignore_auth_resp
) {
4246 wpa_printf(MSG_INFO
,
4247 "EVENT_ASSOC - ignore_auth_resp active!");
4250 if (wpa_s
->testing_resend_assoc
) {
4251 wpa_printf(MSG_INFO
,
4252 "EVENT_DEAUTH - testing_resend_assoc");
4255 #endif /* CONFIG_TESTING_OPTIONS */
4256 wpa_supplicant_event_assoc(wpa_s
, data
);
4257 wpa_s
->assoc_status_code
= WLAN_STATUS_SUCCESS
;
4259 (data
->assoc_info
.authorized
||
4260 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4261 wpa_fils_is_completed(wpa_s
->wpa
))))
4262 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4264 wpa_msg(wpa_s
, MSG_INFO
,
4265 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4266 data
->assoc_info
.subnet_status
);
4269 case EVENT_DISASSOC
:
4270 wpas_event_disassoc(wpa_s
,
4271 data
? &data
->disassoc_info
: NULL
);
4274 #ifdef CONFIG_TESTING_OPTIONS
4275 if (wpa_s
->ignore_auth_resp
) {
4276 wpa_printf(MSG_INFO
,
4277 "EVENT_DEAUTH - ignore_auth_resp active!");
4280 if (wpa_s
->testing_resend_assoc
) {
4281 wpa_printf(MSG_INFO
,
4282 "EVENT_DEAUTH - testing_resend_assoc");
4285 #endif /* CONFIG_TESTING_OPTIONS */
4286 wpas_event_deauth(wpa_s
,
4287 data
? &data
->deauth_info
: NULL
);
4289 case EVENT_MICHAEL_MIC_FAILURE
:
4290 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4292 #ifndef CONFIG_NO_SCAN_PROCESSING
4293 case EVENT_SCAN_STARTED
:
4294 if (wpa_s
->own_scan_requested
||
4295 (data
&& !data
->scan_info
.external_scan
)) {
4296 struct os_reltime diff
;
4298 os_get_reltime(&wpa_s
->scan_start_time
);
4299 os_reltime_sub(&wpa_s
->scan_start_time
,
4300 &wpa_s
->scan_trigger_time
, &diff
);
4301 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4302 diff
.sec
, diff
.usec
);
4303 wpa_s
->own_scan_requested
= 0;
4304 wpa_s
->own_scan_running
= 1;
4305 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4306 wpa_s
->manual_scan_use_id
) {
4307 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4308 WPA_EVENT_SCAN_STARTED
"id=%u",
4309 wpa_s
->manual_scan_id
);
4311 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4312 WPA_EVENT_SCAN_STARTED
);
4315 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4316 wpa_s
->radio
->external_scan_running
= 1;
4317 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4320 case EVENT_SCAN_RESULTS
:
4321 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4322 wpa_s
->scan_res_handler
= NULL
;
4323 wpa_s
->own_scan_running
= 0;
4324 wpa_s
->radio
->external_scan_running
= 0;
4325 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4329 if (!(data
&& data
->scan_info
.external_scan
) &&
4330 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4331 struct os_reltime now
, diff
;
4332 os_get_reltime(&now
);
4333 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4334 wpa_s
->scan_start_time
.sec
= 0;
4335 wpa_s
->scan_start_time
.usec
= 0;
4336 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4337 diff
.sec
, diff
.usec
);
4339 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4340 break; /* interface may have been removed */
4341 if (!(data
&& data
->scan_info
.external_scan
))
4342 wpa_s
->own_scan_running
= 0;
4343 if (data
&& data
->scan_info
.nl_scan_event
)
4344 wpa_s
->radio
->external_scan_running
= 0;
4345 radio_work_check_next(wpa_s
);
4347 #endif /* CONFIG_NO_SCAN_PROCESSING */
4348 case EVENT_ASSOCINFO
:
4349 wpa_supplicant_event_associnfo(wpa_s
, data
);
4351 case EVENT_INTERFACE_STATUS
:
4352 wpa_supplicant_event_interface_status(wpa_s
, data
);
4354 case EVENT_PMKID_CANDIDATE
:
4355 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4359 wpa_supplicant_event_tdls(wpa_s
, data
);
4361 #endif /* CONFIG_TDLS */
4364 wpa_supplicant_event_wnm(wpa_s
, data
);
4366 #endif /* CONFIG_WNM */
4367 #ifdef CONFIG_IEEE80211R
4368 case EVENT_FT_RESPONSE
:
4369 wpa_supplicant_event_ft_response(wpa_s
, data
);
4371 #endif /* CONFIG_IEEE80211R */
4372 #ifdef CONFIG_IBSS_RSN
4373 case EVENT_IBSS_RSN_START
:
4374 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4376 #endif /* CONFIG_IBSS_RSN */
4377 case EVENT_ASSOC_REJECT
:
4378 wpas_event_assoc_reject(wpa_s
, data
);
4380 case EVENT_AUTH_TIMED_OUT
:
4381 /* It is possible to get this event from earlier connection */
4382 if (wpa_s
->current_ssid
&&
4383 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4384 wpa_dbg(wpa_s
, MSG_DEBUG
,
4385 "Ignore AUTH_TIMED_OUT in mesh configuration");
4388 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4389 sme_event_auth_timed_out(wpa_s
, data
);
4391 case EVENT_ASSOC_TIMED_OUT
:
4392 /* It is possible to get this event from earlier connection */
4393 if (wpa_s
->current_ssid
&&
4394 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4395 wpa_dbg(wpa_s
, MSG_DEBUG
,
4396 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4399 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4400 sme_event_assoc_timed_out(wpa_s
, data
);
4402 case EVENT_TX_STATUS
:
4403 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4404 " type=%d stype=%d",
4405 MAC2STR(data
->tx_status
.dst
),
4406 data
->tx_status
.type
, data
->tx_status
.stype
);
4408 if (wpa_s
->ap_iface
== NULL
) {
4409 #ifdef CONFIG_OFFCHANNEL
4410 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4411 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4412 offchannel_send_action_tx_status(
4413 wpa_s
, data
->tx_status
.dst
,
4414 data
->tx_status
.data
,
4415 data
->tx_status
.data_len
,
4416 data
->tx_status
.ack
?
4417 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4418 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4419 #endif /* CONFIG_OFFCHANNEL */
4422 #endif /* CONFIG_AP */
4423 #ifdef CONFIG_OFFCHANNEL
4424 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4425 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4427 * Catch TX status events for Action frames we sent via group
4428 * interface in GO mode, or via standalone AP interface.
4429 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4430 * except when the primary interface is used as a GO interface
4431 * (for drivers which do not have group interface concurrency)
4433 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4434 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4435 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4436 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4437 offchannel_send_action_tx_status(
4438 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4439 data
->tx_status
.data
,
4440 data
->tx_status
.data_len
,
4441 data
->tx_status
.ack
?
4442 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4443 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4446 #endif /* CONFIG_OFFCHANNEL */
4448 switch (data
->tx_status
.type
) {
4449 case WLAN_FC_TYPE_MGMT
:
4450 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4451 data
->tx_status
.data_len
,
4452 data
->tx_status
.stype
,
4453 data
->tx_status
.ack
);
4455 case WLAN_FC_TYPE_DATA
:
4456 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4457 data
->tx_status
.data
,
4458 data
->tx_status
.data_len
,
4459 data
->tx_status
.ack
);
4462 #endif /* CONFIG_AP */
4465 case EVENT_EAPOL_TX_STATUS
:
4466 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4467 data
->eapol_tx_status
.data
,
4468 data
->eapol_tx_status
.data_len
,
4469 data
->eapol_tx_status
.ack
);
4471 case EVENT_DRIVER_CLIENT_POLL_OK
:
4472 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4474 case EVENT_RX_FROM_UNKNOWN
:
4475 if (wpa_s
->ap_iface
== NULL
)
4477 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4478 data
->rx_from_unknown
.wds
);
4480 #endif /* CONFIG_AP */
4482 case EVENT_CH_SWITCH_STARTED
:
4483 case EVENT_CH_SWITCH
:
4484 if (!data
|| !wpa_s
->current_ssid
)
4487 wpa_msg(wpa_s
, MSG_INFO
,
4488 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4489 event
== EVENT_CH_SWITCH
? WPA_EVENT_CHANNEL_SWITCH
:
4490 WPA_EVENT_CHANNEL_SWITCH_STARTED
,
4491 data
->ch_switch
.freq
,
4492 data
->ch_switch
.ht_enabled
,
4493 data
->ch_switch
.ch_offset
,
4494 channel_width_to_string(data
->ch_switch
.ch_width
),
4495 data
->ch_switch
.cf1
,
4496 data
->ch_switch
.cf2
);
4497 if (event
== EVENT_CH_SWITCH_STARTED
)
4500 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4501 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4504 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4505 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4506 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
||
4507 wpa_s
->current_ssid
->mode
==
4508 WPAS_MODE_P2P_GROUP_FORMATION
) {
4509 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4510 data
->ch_switch
.ht_enabled
,
4511 data
->ch_switch
.ch_offset
,
4512 data
->ch_switch
.ch_width
,
4513 data
->ch_switch
.cf1
,
4514 data
->ch_switch
.cf2
,
4517 #endif /* CONFIG_AP */
4519 #ifdef CONFIG_IEEE80211W
4520 sme_event_ch_switch(wpa_s
);
4521 #endif /* CONFIG_IEEE80211W */
4522 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4523 wnm_clear_coloc_intf_reporting(wpa_s
);
4527 case EVENT_DFS_RADAR_DETECTED
:
4529 wpas_ap_event_dfs_radar_detected(wpa_s
,
4532 case EVENT_DFS_NOP_FINISHED
:
4534 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4537 #endif /* NEED_AP_MLME */
4538 #endif /* CONFIG_AP */
4539 case EVENT_DFS_CAC_STARTED
:
4541 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4543 case EVENT_DFS_CAC_FINISHED
:
4545 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4547 case EVENT_DFS_CAC_ABORTED
:
4549 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4551 case EVENT_RX_MGMT
: {
4553 const struct ieee80211_mgmt
*mgmt
;
4555 #ifdef CONFIG_TESTING_OPTIONS
4556 if (wpa_s
->ext_mgmt_frame_handling
) {
4557 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4558 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4559 char *hex
= os_malloc(hex_len
);
4561 wpa_snprintf_hex(hex
, hex_len
,
4562 rx
->frame
, rx
->frame_len
);
4563 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4564 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4570 #endif /* CONFIG_TESTING_OPTIONS */
4572 mgmt
= (const struct ieee80211_mgmt
*)
4573 data
->rx_mgmt
.frame
;
4574 fc
= le_to_host16(mgmt
->frame_control
);
4575 stype
= WLAN_FC_GET_STYPE(fc
);
4578 if (wpa_s
->ap_iface
== NULL
) {
4579 #endif /* CONFIG_AP */
4581 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4582 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4583 const u8
*src
= mgmt
->sa
;
4587 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4588 ie_len
= data
->rx_mgmt
.frame_len
-
4590 wpas_p2p_probe_req_rx(
4591 wpa_s
, src
, mgmt
->da
,
4592 mgmt
->bssid
, ie
, ie_len
,
4594 data
->rx_mgmt
.ssi_signal
);
4597 #endif /* CONFIG_P2P */
4598 #ifdef CONFIG_IBSS_RSN
4599 if (wpa_s
->current_ssid
&&
4600 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4601 stype
== WLAN_FC_STYPE_AUTH
&&
4602 data
->rx_mgmt
.frame_len
>= 30) {
4603 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4606 #endif /* CONFIG_IBSS_RSN */
4608 if (stype
== WLAN_FC_STYPE_ACTION
) {
4609 wpas_event_rx_mgmt_action(
4610 wpa_s
, data
->rx_mgmt
.frame
,
4611 data
->rx_mgmt
.frame_len
,
4613 data
->rx_mgmt
.ssi_signal
);
4618 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4623 if (stype
== WLAN_FC_STYPE_AUTH
&&
4624 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4625 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4626 sme_external_auth_mgmt_rx(
4627 wpa_s
, data
->rx_mgmt
.frame
,
4628 data
->rx_mgmt
.frame_len
);
4631 #endif /* CONFIG_SAE */
4632 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4633 "management frame in non-AP mode");
4638 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4639 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4643 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4644 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4646 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4647 mgmt
->bssid
, ie
, ie_len
,
4648 data
->rx_mgmt
.ssi_signal
);
4651 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4652 #endif /* CONFIG_AP */
4655 case EVENT_RX_PROBE_REQ
:
4656 if (data
->rx_probe_req
.sa
== NULL
||
4657 data
->rx_probe_req
.ie
== NULL
)
4660 if (wpa_s
->ap_iface
) {
4661 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4662 data
->rx_probe_req
.sa
,
4663 data
->rx_probe_req
.da
,
4664 data
->rx_probe_req
.bssid
,
4665 data
->rx_probe_req
.ie
,
4666 data
->rx_probe_req
.ie_len
,
4667 data
->rx_probe_req
.ssi_signal
);
4670 #endif /* CONFIG_AP */
4671 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4672 data
->rx_probe_req
.da
,
4673 data
->rx_probe_req
.bssid
,
4674 data
->rx_probe_req
.ie
,
4675 data
->rx_probe_req
.ie_len
,
4677 data
->rx_probe_req
.ssi_signal
);
4679 case EVENT_REMAIN_ON_CHANNEL
:
4680 #ifdef CONFIG_OFFCHANNEL
4681 offchannel_remain_on_channel_cb(
4682 wpa_s
, data
->remain_on_channel
.freq
,
4683 data
->remain_on_channel
.duration
);
4684 #endif /* CONFIG_OFFCHANNEL */
4685 wpas_p2p_remain_on_channel_cb(
4686 wpa_s
, data
->remain_on_channel
.freq
,
4687 data
->remain_on_channel
.duration
);
4689 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4690 #ifdef CONFIG_OFFCHANNEL
4691 offchannel_cancel_remain_on_channel_cb(
4692 wpa_s
, data
->remain_on_channel
.freq
);
4693 #endif /* CONFIG_OFFCHANNEL */
4694 wpas_p2p_cancel_remain_on_channel_cb(
4695 wpa_s
, data
->remain_on_channel
.freq
);
4697 wpas_dpp_cancel_remain_on_channel_cb(
4698 wpa_s
, data
->remain_on_channel
.freq
);
4699 #endif /* CONFIG_DPP */
4701 case EVENT_EAPOL_RX
:
4702 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4703 data
->eapol_rx
.data
,
4704 data
->eapol_rx
.data_len
);
4706 case EVENT_SIGNAL_CHANGE
:
4707 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4708 "above=%d signal=%d noise=%d txrate=%d",
4709 data
->signal_change
.above_threshold
,
4710 data
->signal_change
.current_signal
,
4711 data
->signal_change
.current_noise
,
4712 data
->signal_change
.current_txrate
);
4713 wpa_bss_update_level(wpa_s
->current_bss
,
4714 data
->signal_change
.current_signal
);
4715 bgscan_notify_signal_change(
4716 wpa_s
, data
->signal_change
.above_threshold
,
4717 data
->signal_change
.current_signal
,
4718 data
->signal_change
.current_noise
,
4719 data
->signal_change
.current_txrate
);
4721 case EVENT_INTERFACE_MAC_CHANGED
:
4722 wpa_supplicant_update_mac_addr(wpa_s
);
4724 case EVENT_INTERFACE_ENABLED
:
4725 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4726 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4727 wpa_supplicant_update_mac_addr(wpa_s
);
4728 wpa_supplicant_set_default_scan_ies(wpa_s
);
4729 if (wpa_s
->p2p_mgmt
) {
4730 wpa_supplicant_set_state(wpa_s
,
4736 if (!wpa_s
->ap_iface
) {
4737 wpa_supplicant_set_state(wpa_s
,
4739 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4740 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4742 wpa_supplicant_set_state(wpa_s
,
4744 #else /* CONFIG_AP */
4745 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4746 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4747 #endif /* CONFIG_AP */
4750 case EVENT_INTERFACE_DISABLED
:
4751 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4753 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4754 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4755 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4757 * Mark interface disabled if this happens to end up not
4758 * being removed as a separate P2P group interface.
4760 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4762 * The interface was externally disabled. Remove
4763 * it assuming an external entity will start a
4764 * new session if needed.
4766 if (wpa_s
->current_ssid
&&
4767 wpa_s
->current_ssid
->p2p_group
)
4768 wpas_p2p_interface_unavailable(wpa_s
);
4770 wpas_p2p_disconnect(wpa_s
);
4772 * wpa_s instance may have been freed, so must not use
4777 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4778 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4779 /* This radio work will be cancelled, so clear P2P
4782 p2p_stop_find(wpa_s
->global
->p2p
);
4784 #endif /* CONFIG_P2P */
4786 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4788 * Indicate disconnection to keep ctrl_iface events
4791 wpa_supplicant_event_disassoc(
4792 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4794 wpa_supplicant_mark_disassoc(wpa_s
);
4795 wpa_bss_flush(wpa_s
);
4796 radio_remove_works(wpa_s
, NULL
, 0);
4798 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4800 case EVENT_CHANNEL_LIST_CHANGED
:
4801 wpa_supplicant_update_channel_list(
4802 wpa_s
, &data
->channel_list_changed
);
4804 case EVENT_INTERFACE_UNAVAILABLE
:
4805 wpas_p2p_interface_unavailable(wpa_s
);
4807 case EVENT_BEST_CHANNEL
:
4808 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4810 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4811 data
->best_chan
.freq_overall
);
4812 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4813 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4814 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4815 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4816 data
->best_chan
.freq_5
,
4817 data
->best_chan
.freq_overall
);
4819 case EVENT_UNPROT_DEAUTH
:
4820 wpa_supplicant_event_unprot_deauth(wpa_s
,
4821 &data
->unprot_deauth
);
4823 case EVENT_UNPROT_DISASSOC
:
4824 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4825 &data
->unprot_disassoc
);
4827 case EVENT_STATION_LOW_ACK
:
4829 if (wpa_s
->ap_iface
&& data
)
4830 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4831 data
->low_ack
.addr
);
4832 #endif /* CONFIG_AP */
4835 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4836 data
->low_ack
.addr
);
4837 #endif /* CONFIG_TDLS */
4839 case EVENT_IBSS_PEER_LOST
:
4840 #ifdef CONFIG_IBSS_RSN
4841 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4842 #endif /* CONFIG_IBSS_RSN */
4844 case EVENT_DRIVER_GTK_REKEY
:
4845 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4846 wpa_s
->bssid
, ETH_ALEN
))
4850 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4851 data
->driver_gtk_rekey
.replay_ctr
);
4853 case EVENT_SCHED_SCAN_STOPPED
:
4854 wpa_s
->sched_scanning
= 0;
4855 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4856 wpa_supplicant_notify_scanning(wpa_s
, 0);
4858 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4862 * If the driver stopped scanning without being requested to,
4863 * request a new scan to continue scanning for networks.
4865 if (!wpa_s
->sched_scan_stop_req
&&
4866 wpa_s
->wpa_state
== WPA_SCANNING
) {
4867 wpa_dbg(wpa_s
, MSG_DEBUG
,
4868 "Restart scanning after unexpected sched_scan stop event");
4869 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4873 wpa_s
->sched_scan_stop_req
= 0;
4876 * Start a new sched scan to continue searching for more SSIDs
4877 * either if timed out or PNO schedule scan is pending.
4879 if (wpa_s
->sched_scan_timed_out
) {
4880 wpa_supplicant_req_sched_scan(wpa_s
);
4881 } else if (wpa_s
->pno_sched_pending
) {
4882 wpa_s
->pno_sched_pending
= 0;
4883 wpas_start_pno(wpa_s
);
4884 } else if (resched
) {
4885 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4889 case EVENT_WPS_BUTTON_PUSHED
:
4891 wpas_wps_start_pbc(wpa_s
, NULL
, 0, 0);
4892 #endif /* CONFIG_WPS */
4894 case EVENT_AVOID_FREQUENCIES
:
4895 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4897 case EVENT_CONNECT_FAILED_REASON
:
4899 if (!wpa_s
->ap_iface
|| !data
)
4901 hostapd_event_connect_failed_reason(
4902 wpa_s
->ap_iface
->bss
[0],
4903 data
->connect_failed_reason
.addr
,
4904 data
->connect_failed_reason
.code
);
4905 #endif /* CONFIG_AP */
4907 case EVENT_NEW_PEER_CANDIDATE
:
4909 if (!wpa_s
->ifmsh
|| !data
)
4911 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4912 data
->mesh_peer
.ies
,
4913 data
->mesh_peer
.ie_len
);
4914 #endif /* CONFIG_MESH */
4918 if (!wpa_s
->ap_iface
)
4920 hostapd_event_get_survey(wpa_s
->ap_iface
,
4921 &data
->survey_results
);
4922 #endif /* CONFIG_AP */
4924 case EVENT_ACS_CHANNEL_SELECTED
:
4927 if (!wpa_s
->ap_iface
)
4929 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4930 &data
->acs_selected_channels
);
4931 #endif /* CONFIG_ACS */
4932 #endif /* CONFIG_AP */
4934 case EVENT_P2P_LO_STOP
:
4936 wpa_s
->p2p_lo_started
= 0;
4937 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4938 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4939 data
->p2p_lo_stop
.reason_code
);
4940 #endif /* CONFIG_P2P */
4942 case EVENT_BEACON_LOSS
:
4943 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4945 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4946 bgscan_notify_beacon_loss(wpa_s
);
4948 case EVENT_EXTERNAL_AUTH
:
4950 if (!wpa_s
->current_ssid
) {
4951 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4954 sme_external_auth_trigger(wpa_s
, data
);
4955 #endif /* CONFIG_SAE */
4957 case EVENT_PORT_AUTHORIZED
:
4958 wpa_supplicant_event_port_authorized(wpa_s
);
4960 case EVENT_STATION_OPMODE_CHANGED
:
4962 if (!wpa_s
->ap_iface
|| !data
)
4965 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
4966 data
->sta_opmode
.addr
,
4967 data
->sta_opmode
.smps_mode
,
4968 data
->sta_opmode
.chan_width
,
4969 data
->sta_opmode
.rx_nss
);
4970 #endif /* CONFIG_AP */
4973 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4979 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4980 union wpa_event_data
*data
)
4982 struct wpa_supplicant
*wpa_s
;
4984 if (event
!= EVENT_INTERFACE_STATUS
)
4987 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4988 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4989 unsigned int ifindex
;
4991 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4992 if (ifindex
!= data
->interface_status
.ifindex
) {
4993 wpa_dbg(wpa_s
, MSG_DEBUG
,
4994 "interface status ifindex %d mismatch (%d)",
4995 ifindex
, data
->interface_status
.ifindex
);
4999 #ifdef CONFIG_MATCH_IFACE
5000 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
5001 struct wpa_interface
*wpa_i
;
5003 wpa_i
= wpa_supplicant_match_iface(
5004 ctx
, data
->interface_status
.ifname
);
5007 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
5012 #endif /* CONFIG_MATCH_IFACE */
5015 wpa_supplicant_event(wpa_s
, event
, data
);