2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2017, 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 "crypto/random.h"
33 #include "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
38 #include "gas_query.h"
39 #include "p2p_supplicant.h"
45 #include "offchannel.h"
46 #include "interworking.h"
50 #include "dpp_supplicant.h"
53 #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
56 #ifndef CONFIG_NO_SCAN_PROCESSING
57 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
58 int new_scan
, int own_request
);
59 #endif /* CONFIG_NO_SCAN_PROCESSING */
62 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
64 struct os_reltime now
;
66 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
70 if (ssid
->disabled_until
.sec
> now
.sec
)
71 return ssid
->disabled_until
.sec
- now
.sec
;
73 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
79 #ifndef CONFIG_NO_SCAN_PROCESSING
81 * wpas_reenabled_network_time - Time until first network is re-enabled
82 * @wpa_s: Pointer to wpa_supplicant data
83 * Returns: If all enabled networks are temporarily disabled, returns the time
84 * (in sec) until the first network is re-enabled. Otherwise returns 0.
86 * This function is used in case all enabled networks are temporarily disabled,
87 * in which case it returns the time (in sec) that the first network will be
88 * re-enabled. The function assumes that at least one network is enabled.
90 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
92 struct wpa_ssid
*ssid
;
93 int disabled_for
, res
= 0;
95 #ifdef CONFIG_INTERWORKING
96 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
99 #endif /* CONFIG_INTERWORKING */
101 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
105 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
109 if (!res
|| disabled_for
< res
)
115 #endif /* CONFIG_NO_SCAN_PROCESSING */
118 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
120 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
122 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
125 wpa_dbg(wpa_s
, MSG_DEBUG
,
126 "Try to associate due to network getting re-enabled");
127 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
128 wpa_supplicant_cancel_sched_scan(wpa_s
);
129 wpa_supplicant_req_scan(wpa_s
, 0, 0);
134 static struct wpa_bss
* wpa_supplicant_get_new_bss(
135 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
137 struct wpa_bss
*bss
= NULL
;
138 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
140 if (ssid
->ssid_len
> 0)
141 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
143 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
149 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
151 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
154 wpa_supplicant_update_scan_results(wpa_s
);
156 /* Get the BSS from the new scan results */
157 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
161 wpa_s
->current_bss
= bss
;
165 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
167 struct wpa_ssid
*ssid
, *old_ssid
;
168 u8 drv_ssid
[SSID_MAX_LEN
];
172 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
173 wpa_supplicant_update_current_bss(wpa_s
);
175 if (wpa_s
->current_ssid
->ssid_len
== 0)
176 return 0; /* current profile still in use */
177 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
179 wpa_msg(wpa_s
, MSG_INFO
,
180 "Failed to read SSID from driver");
181 return 0; /* try to use current profile */
185 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
186 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
188 return 0; /* current profile still in use */
190 wpa_msg(wpa_s
, MSG_DEBUG
,
191 "Driver-initiated BSS selection changed the SSID to %s",
192 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
193 /* continue selecting a new network profile */
196 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
198 ssid
= wpa_supplicant_get_ssid(wpa_s
);
200 wpa_msg(wpa_s
, MSG_INFO
,
201 "No network configuration found for the current AP");
205 if (wpas_network_disabled(wpa_s
, ssid
)) {
206 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
210 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
211 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
212 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
216 res
= wpas_temp_disabled(wpa_s
, ssid
);
218 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
219 "disabled for %d second(s)", res
);
223 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
225 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
227 size_t wpa_ie_len
= sizeof(wpa_ie
);
228 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
229 wpa_ie
, &wpa_ie_len
) < 0)
230 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
232 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
235 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
236 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
237 old_ssid
= wpa_s
->current_ssid
;
238 wpa_s
->current_ssid
= ssid
;
240 wpa_supplicant_update_current_bss(wpa_s
);
242 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
243 wpa_supplicant_initiate_eapol(wpa_s
);
244 if (old_ssid
!= wpa_s
->current_ssid
)
245 wpas_notify_network_changed(wpa_s
);
251 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
253 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
255 if (wpa_s
->countermeasures
) {
256 wpa_s
->countermeasures
= 0;
257 wpa_drv_set_countermeasures(wpa_s
, 0);
258 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
261 * It is possible that the device is sched scanning, which means
262 * that a connection attempt will be done only when we receive
263 * scan results. However, in this case, it would be preferable
264 * to scan and connect immediately, so cancel the sched_scan and
265 * issue a regular scan flow.
267 wpa_supplicant_cancel_sched_scan(wpa_s
);
268 wpa_supplicant_req_scan(wpa_s
, 0, 0);
273 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
277 wnm_bss_keep_alive_deinit(wpa_s
);
279 #ifdef CONFIG_IBSS_RSN
280 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
281 wpa_s
->ibss_rsn
= NULL
;
282 #endif /* CONFIG_IBSS_RSN */
285 wpa_supplicant_ap_deinit(wpa_s
);
286 #endif /* CONFIG_AP */
289 /* Clear possibly configured frame filters */
290 wpa_drv_configure_frame_filters(wpa_s
, 0);
291 #endif /* CONFIG_HS20 */
293 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
296 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
297 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
298 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
299 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
300 sme_clear_on_disassoc(wpa_s
);
301 wpa_s
->current_bss
= NULL
;
302 wpa_s
->assoc_freq
= 0;
305 wpas_notify_bssid_changed(wpa_s
);
307 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
308 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
309 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
310 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
311 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
)
312 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
313 wpa_s
->ap_ies_from_associnfo
= 0;
314 wpa_s
->current_ssid
= NULL
;
315 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
318 wpas_rrm_reset(wpa_s
);
319 wpa_s
->wnmsleep_used
= 0;
320 wnm_clear_coloc_intf_reporting(wpa_s
);
322 #ifdef CONFIG_TESTING_OPTIONS
323 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
324 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
325 #endif /* CONFIG_TESTING_OPTIONS */
326 wpa_s
->ieee80211ac
= 0;
328 if (wpa_s
->enabled_4addr_mode
&& wpa_drv_set_4addr_mode(wpa_s
, 0) == 0)
329 wpa_s
->enabled_4addr_mode
= 0;
333 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
335 struct wpa_ie_data ie
;
339 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
343 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
344 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
345 ie
.pmkid
+ i
* PMKID_LEN
,
346 NULL
, NULL
, 0, NULL
, 0);
347 if (pmksa_set
== 0) {
348 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
353 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
354 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
358 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
359 union wpa_event_data
*data
)
362 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
366 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
367 " index=%d preauth=%d",
368 MAC2STR(data
->pmkid_candidate
.bssid
),
369 data
->pmkid_candidate
.index
,
370 data
->pmkid_candidate
.preauth
);
372 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
373 data
->pmkid_candidate
.index
,
374 data
->pmkid_candidate
.preauth
);
378 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
380 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
381 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
384 #ifdef IEEE8021X_EAPOL
385 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
386 wpa_s
->current_ssid
&&
387 !(wpa_s
->current_ssid
->eapol_flags
&
388 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
389 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
390 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
391 * plaintext or static WEP keys). */
394 #endif /* IEEE8021X_EAPOL */
401 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
402 * @wpa_s: pointer to wpa_supplicant data
403 * @ssid: Configuration data for the network
404 * Returns: 0 on success, -1 on failure
406 * This function is called when starting authentication with a network that is
407 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
409 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
410 struct wpa_ssid
*ssid
)
412 #ifdef IEEE8021X_EAPOL
414 int aka
= 0, sim
= 0;
416 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
417 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
420 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
424 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
425 while (eap
->vendor
!= EAP_VENDOR_IETF
||
426 eap
->method
!= EAP_TYPE_NONE
) {
427 if (eap
->vendor
== EAP_VENDOR_IETF
) {
428 if (eap
->method
== EAP_TYPE_SIM
)
430 else if (eap
->method
== EAP_TYPE_AKA
||
431 eap
->method
== EAP_TYPE_AKA_PRIME
)
438 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
440 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
441 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
446 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
447 "use SIM, but neither EAP-SIM nor EAP-AKA are "
452 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
453 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
455 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
456 if (wpa_s
->scard
== NULL
) {
457 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
461 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
462 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
463 #endif /* PCSC_FUNCS */
464 #endif /* IEEE8021X_EAPOL */
470 #ifndef CONFIG_NO_SCAN_PROCESSING
472 static int has_wep_key(struct wpa_ssid
*ssid
)
476 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
477 if (ssid
->wep_key_len
[i
])
485 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
486 struct wpa_ssid
*ssid
)
490 if (ssid
->mixed_cell
)
494 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
496 #endif /* CONFIG_WPS */
499 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
501 #endif /* CONFIG_OWE */
503 if (has_wep_key(ssid
))
506 #ifdef IEEE8021X_EAPOL
507 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
508 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
509 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
511 #endif /* IEEE8021X_EAPOL */
513 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
516 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
519 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
525 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
526 struct wpa_ssid
*ssid
,
527 struct wpa_bss
*bss
, int debug_print
)
529 struct wpa_ie_data ie
;
531 const u8
*rsn_ie
, *wpa_ie
;
535 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
539 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
540 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
541 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
542 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
543 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
545 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
546 while ((ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)) && rsn_ie
) {
549 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
551 wpa_dbg(wpa_s
, MSG_DEBUG
,
552 " skip RSN IE - parse failed");
557 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
560 wpa_dbg(wpa_s
, MSG_DEBUG
,
561 " selected based on TSN in RSN IE");
565 if (!(ie
.proto
& ssid
->proto
) &&
566 !(ssid
->proto
& WPA_PROTO_OSEN
)) {
568 wpa_dbg(wpa_s
, MSG_DEBUG
,
569 " skip RSN IE - proto mismatch");
573 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
575 wpa_dbg(wpa_s
, MSG_DEBUG
,
576 " skip RSN IE - PTK cipher mismatch");
580 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
582 wpa_dbg(wpa_s
, MSG_DEBUG
,
583 " skip RSN IE - GTK cipher mismatch");
587 if (ssid
->group_mgmt_cipher
&&
588 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
590 wpa_dbg(wpa_s
, MSG_DEBUG
,
591 " skip RSN IE - group mgmt cipher mismatch");
595 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
597 wpa_dbg(wpa_s
, MSG_DEBUG
,
598 " skip RSN IE - key mgmt mismatch");
602 #ifdef CONFIG_IEEE80211W
603 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
604 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
605 MGMT_FRAME_PROTECTION_REQUIRED
) {
607 wpa_dbg(wpa_s
, MSG_DEBUG
,
608 " skip RSN IE - no mgmt frame protection");
611 #endif /* CONFIG_IEEE80211W */
612 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
613 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
614 NO_MGMT_FRAME_PROTECTION
) {
616 wpa_dbg(wpa_s
, MSG_DEBUG
,
617 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
621 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
622 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
623 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
624 NO_MGMT_FRAME_PROTECTION
) {
626 wpa_dbg(wpa_s
, MSG_DEBUG
,
627 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
630 #endif /* CONFIG_MBO */
633 wpa_dbg(wpa_s
, MSG_DEBUG
,
634 " selected based on RSN IE");
638 #ifdef CONFIG_IEEE80211W
639 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
640 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
642 wpa_dbg(wpa_s
, MSG_DEBUG
,
643 " skip - MFP Required but network not MFP Capable");
646 #endif /* CONFIG_IEEE80211W */
648 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
649 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
652 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
654 wpa_dbg(wpa_s
, MSG_DEBUG
,
655 " skip WPA IE - parse failed");
660 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
663 wpa_dbg(wpa_s
, MSG_DEBUG
,
664 " selected based on TSN in WPA IE");
668 if (!(ie
.proto
& ssid
->proto
)) {
670 wpa_dbg(wpa_s
, MSG_DEBUG
,
671 " skip WPA IE - proto mismatch");
675 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
677 wpa_dbg(wpa_s
, MSG_DEBUG
,
678 " skip WPA IE - PTK cipher mismatch");
682 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
684 wpa_dbg(wpa_s
, MSG_DEBUG
,
685 " skip WPA IE - GTK cipher mismatch");
689 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
691 wpa_dbg(wpa_s
, MSG_DEBUG
,
692 " skip WPA IE - key mgmt mismatch");
697 wpa_dbg(wpa_s
, MSG_DEBUG
,
698 " selected based on WPA IE");
702 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
705 wpa_dbg(wpa_s
, MSG_DEBUG
,
706 " allow for non-WPA IEEE 802.1X");
711 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
712 !wpa_ie
&& !rsn_ie
) {
713 if (wpa_s
->owe_transition_select
&&
714 wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
) &&
715 ssid
->owe_transition_bss_select_count
+ 1 <=
716 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
) {
717 ssid
->owe_transition_bss_select_count
++;
719 wpa_dbg(wpa_s
, MSG_DEBUG
,
720 " skip OWE transition BSS (selection count %d does not exceed %d)",
721 ssid
->owe_transition_bss_select_count
,
722 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
);
723 wpa_s
->owe_transition_search
= 1;
727 wpa_dbg(wpa_s
, MSG_DEBUG
,
728 " allow in OWE transition mode");
731 #endif /* CONFIG_OWE */
733 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
734 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
736 wpa_dbg(wpa_s
, MSG_DEBUG
,
737 " skip - no WPA/RSN proto match");
741 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
742 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
744 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
748 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
750 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
755 wpa_dbg(wpa_s
, MSG_DEBUG
,
756 " reject due to mismatch with WPA/WPA2");
762 static int freq_allowed(int *freqs
, int freq
)
769 for (i
= 0; freqs
[i
]; i
++)
770 if (freqs
[i
] == freq
)
776 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
779 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
780 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
785 return 1; /* Cannot do matching without knowing band */
787 modes
= wpa_s
->hw
.modes
;
790 * The driver does not provide any additional information
791 * about the utilized hardware, so allow the connection attempt
797 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
798 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
799 int freq
= modes
[i
].channels
[j
].freq
;
800 if (freq
== bss
->freq
) {
802 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
803 break; /* do not allow 802.11b replace
814 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
815 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
819 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
820 int flagged
= !!(rate_ie
[j
] & 0x80);
821 int r
= (rate_ie
[j
] & 0x7f) * 5;
824 * IEEE Std 802.11n-2009 7.3.2.2:
825 * The new BSS Membership selector value is encoded
826 * like a legacy basic rate, but it is not a rate and
827 * only indicates if the BSS members are required to
828 * support the mandatory features of Clause 20 [HT PHY]
829 * in order to join the BSS.
831 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
832 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
833 if (!ht_supported(mode
)) {
835 wpa_dbg(wpa_s
, MSG_DEBUG
,
836 " hardware does not support HT PHY");
842 /* There's also a VHT selector for 802.11ac */
843 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
844 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
845 if (!vht_supported(mode
)) {
847 wpa_dbg(wpa_s
, MSG_DEBUG
,
848 " hardware does not support VHT PHY");
857 /* check for legacy basic rates */
858 for (k
= 0; k
< mode
->num_rates
; k
++) {
859 if (mode
->rates
[k
] == r
)
862 if (k
== mode
->num_rates
) {
864 * IEEE Std 802.11-2007 7.3.2.2 demands that in
865 * order to join a BSS all required rates
866 * have to be supported by the hardware.
869 wpa_dbg(wpa_s
, MSG_DEBUG
,
870 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
872 bss
->freq
, mode
->mode
, mode
->num_rates
);
883 * Test whether BSS is in an ESS.
884 * This is done differently in DMG (60 GHz) and non-DMG bands
886 static int bss_is_ess(struct wpa_bss
*bss
)
888 if (bss_is_dmg(bss
)) {
889 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
890 IEEE80211_CAP_DMG_AP
;
893 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
898 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
902 for (i
= 0; i
< ETH_ALEN
; i
++) {
903 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
910 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
914 for (i
= 0; i
< num
; i
++) {
915 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
916 const u8
*m
= a
+ ETH_ALEN
;
918 if (match_mac_mask(a
, addr
, m
))
925 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
926 const u8
**ret_ssid
, size_t *ret_ssid_len
)
929 const u8
*owe
, *pos
, *end
, *bssid
;
931 struct wpa_bss
*open_bss
;
933 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
934 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
938 end
= owe
+ 2 + owe
[1];
940 if (end
- pos
< ETH_ALEN
+ 1)
945 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
948 /* Match the profile SSID against the OWE transition mode SSID on the
950 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
951 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
953 *ret_ssid_len
= ssid_len
;
955 if (bss
->ssid_len
> 0)
958 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
961 if (ssid_len
!= open_bss
->ssid_len
||
962 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
963 wpa_dbg(wpa_s
, MSG_DEBUG
,
964 "OWE: transition mode SSID mismatch: %s",
965 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
969 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
970 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
971 wpa_dbg(wpa_s
, MSG_DEBUG
,
972 "OWE: transition mode open BSS unexpected info");
977 end
= owe
+ 2 + owe
[1];
979 if (end
- pos
< ETH_ALEN
+ 1)
981 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
982 wpa_dbg(wpa_s
, MSG_DEBUG
,
983 "OWE: transition mode BSSID mismatch: " MACSTR
,
989 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
991 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
992 wpa_ssid_txt(pos
, ssid_len
));
993 os_memcpy(bss
->ssid
, pos
, ssid_len
);
994 bss
->ssid_len
= ssid_len
;
995 #endif /* CONFIG_OWE */
999 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
1000 int i
, struct wpa_bss
*bss
,
1001 struct wpa_ssid
*group
,
1002 int only_first_ssid
, int debug_print
)
1004 u8 wpa_ie_len
, rsn_ie_len
;
1006 struct wpa_blacklist
*e
;
1008 struct wpa_ssid
*ssid
;
1009 int osen
, rsn_osen
= 0;
1011 const u8
*assoc_disallow
;
1012 #endif /* CONFIG_MBO */
1013 const u8
*match_ssid
;
1014 size_t match_ssid_len
;
1015 struct wpa_ie_data data
;
1017 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1018 wpa_ie_len
= ie
? ie
[1] : 0;
1020 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1021 rsn_ie_len
= ie
? ie
[1] : 0;
1022 if (ie
&& wpa_parse_wpa_ie_rsn(ie
, 2 + ie
[1], &data
) == 0 &&
1023 (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
))
1026 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1030 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1031 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1032 i
, MAC2STR(bss
->bssid
),
1033 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1034 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1036 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1038 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1039 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1041 osen
? " osen=1" : "");
1044 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1047 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1049 * When only a single network is enabled, we can
1050 * trigger blacklisting on the first failure. This
1051 * should not be done with multiple enabled networks to
1052 * avoid getting forced to move into a worse ESS on
1053 * single error if there are no other BSSes of the
1058 if (e
->count
> limit
) {
1060 wpa_dbg(wpa_s
, MSG_DEBUG
,
1061 " skip - blacklisted (count=%d limit=%d)",
1068 match_ssid
= bss
->ssid
;
1069 match_ssid_len
= bss
->ssid_len
;
1070 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1072 if (match_ssid_len
== 0) {
1074 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1078 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1080 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1084 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1086 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1090 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1092 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1093 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1096 if (wpas_network_disabled(wpa_s
, ssid
)) {
1098 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1102 res
= wpas_temp_disabled(wpa_s
, ssid
);
1105 wpa_dbg(wpa_s
, MSG_DEBUG
,
1106 " skip - disabled temporarily for %d second(s)",
1112 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1114 wpa_dbg(wpa_s
, MSG_DEBUG
,
1115 " skip - blacklisted (WPS)");
1119 if (wpa
&& ssid
->ssid_len
== 0 &&
1120 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1123 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1124 /* Only allow wildcard SSID match if an AP
1125 * advertises active WPS operation that matches
1128 if (ssid
->ssid_len
== 0 &&
1129 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1132 #endif /* CONFIG_WPS */
1134 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1135 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1139 (match_ssid_len
!= ssid
->ssid_len
||
1140 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1142 wpa_dbg(wpa_s
, MSG_DEBUG
,
1143 " skip - SSID mismatch");
1147 if (ssid
->bssid_set
&&
1148 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1150 wpa_dbg(wpa_s
, MSG_DEBUG
,
1151 " skip - BSSID mismatch");
1155 /* check blacklist */
1156 if (ssid
->num_bssid_blacklist
&&
1157 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1158 ssid
->num_bssid_blacklist
)) {
1160 wpa_dbg(wpa_s
, MSG_DEBUG
,
1161 " skip - BSSID blacklisted");
1165 /* if there is a whitelist, only accept those APs */
1166 if (ssid
->num_bssid_whitelist
&&
1167 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1168 ssid
->num_bssid_whitelist
)) {
1170 wpa_dbg(wpa_s
, MSG_DEBUG
,
1171 " skip - BSSID not in whitelist");
1175 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1179 if (!osen
&& !wpa
&&
1180 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1181 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1182 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1183 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1185 wpa_dbg(wpa_s
, MSG_DEBUG
,
1186 " skip - non-WPA network not allowed");
1190 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1191 has_wep_key(ssid
)) {
1193 wpa_dbg(wpa_s
, MSG_DEBUG
,
1194 " skip - ignore WPA/WPA2 AP for WEP network block");
1198 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
&&
1201 wpa_dbg(wpa_s
, MSG_DEBUG
,
1202 " skip - non-OSEN network not allowed");
1206 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1208 wpa_dbg(wpa_s
, MSG_DEBUG
,
1209 " skip - privacy mismatch");
1213 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1214 !bss_is_pbss(bss
)) {
1216 wpa_dbg(wpa_s
, MSG_DEBUG
,
1217 " skip - not ESS, PBSS, or MBSS");
1221 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1223 wpa_dbg(wpa_s
, MSG_DEBUG
,
1224 " skip - PBSS mismatch (ssid %d bss %d)",
1225 ssid
->pbss
, bss_is_pbss(bss
));
1229 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1231 wpa_dbg(wpa_s
, MSG_DEBUG
,
1232 " skip - frequency not allowed");
1237 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1238 ssid
->frequency
!= bss
->freq
) {
1240 wpa_dbg(wpa_s
, MSG_DEBUG
,
1241 " skip - frequency not allowed (mesh)");
1244 #endif /* CONFIG_MESH */
1246 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1248 wpa_dbg(wpa_s
, MSG_DEBUG
,
1249 " skip - rate sets do not match");
1253 #ifndef CONFIG_IBSS_RSN
1254 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1255 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1256 WPA_KEY_MGMT_WPA_NONE
))) {
1258 wpa_dbg(wpa_s
, MSG_DEBUG
,
1259 " skip - IBSS RSN not supported in the build");
1262 #endif /* !CONFIG_IBSS_RSN */
1265 if (ssid
->p2p_group
&&
1266 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1267 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1269 wpa_dbg(wpa_s
, MSG_DEBUG
,
1270 " skip - no P2P IE seen");
1274 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1275 struct wpabuf
*p2p_ie
;
1276 u8 dev_addr
[ETH_ALEN
];
1278 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1281 wpa_dbg(wpa_s
, MSG_DEBUG
,
1282 " skip - no P2P element");
1285 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1286 bss
, P2P_IE_VENDOR_TYPE
);
1287 if (p2p_ie
== NULL
) {
1289 wpa_dbg(wpa_s
, MSG_DEBUG
,
1290 " skip - could not fetch P2P element");
1294 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1295 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1298 wpa_dbg(wpa_s
, MSG_DEBUG
,
1299 " skip - no matching GO P2P Device Address in P2P element");
1300 wpabuf_free(p2p_ie
);
1303 wpabuf_free(p2p_ie
);
1307 * TODO: skip the AP if its P2P IE has Group Formation
1308 * bit set in the P2P Group Capability Bitmap and we
1309 * are not in Group Formation with that device.
1311 #endif /* CONFIG_P2P */
1313 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1315 struct os_reltime diff
;
1317 os_reltime_sub(&wpa_s
->scan_min_time
,
1318 &bss
->last_update
, &diff
);
1320 wpa_dbg(wpa_s
, MSG_DEBUG
,
1321 " skip - scan result not recent enough (%u.%06u seconds too old)",
1322 (unsigned int) diff
.sec
,
1323 (unsigned int) diff
.usec
);
1327 #ifdef CONFIG_TESTING_OPTIONS
1328 if (wpa_s
->ignore_assoc_disallow
)
1329 goto skip_assoc_disallow
;
1330 #endif /* CONFIG_TESTING_OPTIONS */
1331 assoc_disallow
= wpas_mbo_get_bss_attr(
1332 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1333 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1335 wpa_dbg(wpa_s
, MSG_DEBUG
,
1336 " skip - MBO association disallowed (reason %u)",
1341 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1343 wpa_dbg(wpa_s
, MSG_DEBUG
,
1344 " skip - MBO retry delay has not passed yet");
1347 #ifdef CONFIG_TESTING_OPTIONS
1348 skip_assoc_disallow
:
1349 #endif /* CONFIG_TESTING_OPTIONS */
1350 #endif /* CONFIG_MBO */
1353 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1354 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1355 (!ssid
->dpp_connector
||
1356 !ssid
->dpp_netaccesskey
||
1357 !ssid
->dpp_csign
)) {
1359 wpa_dbg(wpa_s
, MSG_DEBUG
,
1360 " skip - no PMKSA entry for DPP");
1363 #endif /* CONFIG_DPP */
1365 /* Matching configuration found */
1369 /* No matching configuration found */
1374 static struct wpa_bss
*
1375 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1376 struct wpa_ssid
*group
,
1377 struct wpa_ssid
**selected_ssid
,
1378 int only_first_ssid
)
1382 if (wpa_s
->current_ssid
) {
1383 struct wpa_ssid
*ssid
;
1385 wpa_dbg(wpa_s
, MSG_DEBUG
,
1386 "Scan results matching the currently selected network");
1387 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1388 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1390 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1391 only_first_ssid
, 0);
1392 if (ssid
!= wpa_s
->current_ssid
)
1394 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1395 " freq=%d level=%d snr=%d est_throughput=%u",
1396 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1397 bss
->snr
, bss
->est_throughput
);
1401 if (only_first_ssid
)
1402 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1405 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1408 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1409 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1411 wpa_s
->owe_transition_select
= 1;
1412 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1413 only_first_ssid
, 1);
1414 wpa_s
->owe_transition_select
= 0;
1415 if (!*selected_ssid
)
1417 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1419 MAC2STR(bss
->bssid
),
1420 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1428 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1429 struct wpa_ssid
**selected_ssid
)
1431 struct wpa_bss
*selected
= NULL
;
1433 struct wpa_ssid
*next_ssid
= NULL
;
1434 struct wpa_ssid
*ssid
;
1436 if (wpa_s
->last_scan_res
== NULL
||
1437 wpa_s
->last_scan_res_used
== 0)
1438 return NULL
; /* no scan results from last update */
1440 if (wpa_s
->next_ssid
) {
1441 /* check that next_ssid is still valid */
1442 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1443 if (ssid
== wpa_s
->next_ssid
)
1447 wpa_s
->next_ssid
= NULL
;
1450 while (selected
== NULL
) {
1451 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1452 if (next_ssid
&& next_ssid
->priority
==
1453 wpa_s
->conf
->pssid
[prio
]->priority
) {
1454 selected
= wpa_supplicant_select_bss(
1455 wpa_s
, next_ssid
, selected_ssid
, 1);
1459 selected
= wpa_supplicant_select_bss(
1460 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1466 if (selected
== NULL
&& wpa_s
->blacklist
&&
1467 !wpa_s
->countermeasures
) {
1468 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1469 "blacklist and try again");
1470 wpa_blacklist_clear(wpa_s
);
1471 wpa_s
->blacklist_cleared
++;
1472 } else if (selected
== NULL
)
1476 ssid
= *selected_ssid
;
1477 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1478 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1479 const char *field_name
, *txt
= NULL
;
1481 wpa_dbg(wpa_s
, MSG_DEBUG
,
1482 "PSK/passphrase not yet available for the selected network");
1484 wpas_notify_network_request(wpa_s
, ssid
,
1485 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1487 field_name
= wpa_supplicant_ctrl_req_to_string(
1488 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1489 if (field_name
== NULL
)
1492 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1501 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1502 int timeout_sec
, int timeout_usec
)
1504 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1506 * No networks are enabled; short-circuit request so
1507 * we don't wait timeout seconds before transitioning
1508 * to INACTIVE state.
1510 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1511 "since there are no enabled networks");
1512 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1516 wpa_s
->scan_for_connection
= 1;
1517 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1521 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1522 struct wpa_bss
*selected
,
1523 struct wpa_ssid
*ssid
)
1525 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1526 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1527 "PBC session overlap");
1528 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1530 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1531 wpa_s
->p2p_in_provisioning
) {
1532 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1536 #endif /* CONFIG_P2P */
1539 wpas_wps_pbc_overlap(wpa_s
);
1540 wpas_wps_cancel(wpa_s
);
1541 #endif /* CONFIG_WPS */
1545 wpa_msg(wpa_s
, MSG_DEBUG
,
1546 "Considering connect request: reassociate: %d selected: "
1547 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1548 " wpa_state: %s ssid=%p current_ssid=%p",
1549 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1550 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1551 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1552 ssid
, wpa_s
->current_ssid
);
1555 * Do not trigger new association unless the BSSID has changed or if
1556 * reassociation is requested. If we are in process of associating with
1557 * the selected BSSID, do not trigger new attempt.
1559 if (wpa_s
->reassociate
||
1560 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1561 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1562 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1563 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1564 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1566 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1567 ssid
!= wpa_s
->current_ssid
)))) {
1568 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1569 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1572 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1573 MAC2STR(selected
->bssid
));
1574 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1576 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1577 "connect with the selected AP");
1584 static struct wpa_ssid
*
1585 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1588 struct wpa_ssid
*ssid
;
1590 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1591 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1593 if (wpas_network_disabled(wpa_s
, ssid
))
1595 #ifndef CONFIG_IBSS_RSN
1596 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1597 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1598 WPA_KEY_MGMT_WPA_NONE
))) {
1599 wpa_msg(wpa_s
, MSG_INFO
,
1600 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1601 wpa_ssid_txt(ssid
->ssid
,
1605 #endif /* !CONFIG_IBSS_RSN */
1606 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1607 ssid
->mode
== IEEE80211_MODE_AP
||
1608 ssid
->mode
== IEEE80211_MODE_MESH
)
1616 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1617 * on BSS added and BSS changed events */
1618 static void wpa_supplicant_rsn_preauth_scan_results(
1619 struct wpa_supplicant
*wpa_s
)
1621 struct wpa_bss
*bss
;
1623 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1626 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1627 const u8
*ssid
, *rsn
;
1629 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1633 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1637 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1643 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1644 struct wpa_bss
*selected
,
1645 struct wpa_ssid
*ssid
)
1647 struct wpa_bss
*current_bss
= NULL
;
1648 #ifndef CONFIG_NO_ROAMING
1651 int cur_est
, sel_est
;
1652 #endif /* CONFIG_NO_ROAMING */
1654 if (wpa_s
->reassociate
)
1655 return 1; /* explicit request to reassociate */
1656 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1657 return 1; /* we are not associated; continue */
1658 if (wpa_s
->current_ssid
== NULL
)
1659 return 1; /* unknown current SSID */
1660 if (wpa_s
->current_ssid
!= ssid
)
1661 return 1; /* different network block */
1663 if (wpas_driver_bss_selection(wpa_s
))
1664 return 0; /* Driver-based roaming */
1666 if (wpa_s
->current_ssid
->ssid
)
1667 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1668 wpa_s
->current_ssid
->ssid
,
1669 wpa_s
->current_ssid
->ssid_len
);
1671 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1674 return 1; /* current BSS not seen in scan results */
1676 if (current_bss
== selected
)
1679 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1680 return 1; /* current BSS not seen in the last scan */
1682 #ifndef CONFIG_NO_ROAMING
1683 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1684 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1685 " freq=%d level=%d snr=%d est_throughput=%u",
1686 MAC2STR(current_bss
->bssid
),
1687 current_bss
->freq
, current_bss
->level
,
1688 current_bss
->snr
, current_bss
->est_throughput
);
1689 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1690 " freq=%d level=%d snr=%d est_throughput=%u",
1691 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1692 selected
->snr
, selected
->est_throughput
);
1694 if (wpa_s
->current_ssid
->bssid_set
&&
1695 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1697 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1698 "has preferred BSSID");
1702 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1703 wpa_dbg(wpa_s
, MSG_DEBUG
,
1704 "Allow reassociation - selected BSS has better estimated throughput");
1708 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1710 if (current_bss
->level
< 0 &&
1711 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1712 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1717 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1718 wpa_dbg(wpa_s
, MSG_DEBUG
,
1719 "Skip roam - Current BSS has better estimated throughput");
1723 cur_est
= current_bss
->est_throughput
;
1724 sel_est
= selected
->est_throughput
;
1726 if (current_bss
->level
< 0) {
1727 if (current_bss
->level
< -85)
1729 else if (current_bss
->level
< -80)
1731 else if (current_bss
->level
< -75)
1733 else if (current_bss
->level
< -70)
1737 if (cur_est
> sel_est
* 1.5)
1739 else if (cur_est
> sel_est
* 1.2)
1741 else if (cur_est
> sel_est
* 1.1)
1743 else if (cur_est
> sel_est
)
1749 /* Make it easier to move to 5 GHz band */
1750 if (sel_est
> cur_est
* 1.5)
1752 else if (sel_est
> cur_est
* 1.2)
1754 else if (sel_est
> cur_est
* 1.1)
1757 if (min_diff
> reduce
)
1762 diff
= abs(current_bss
->level
- selected
->level
);
1763 if (diff
< min_diff
) {
1764 wpa_dbg(wpa_s
, MSG_DEBUG
,
1765 "Skip roam - too small difference in signal level (%d < %d)",
1770 wpa_dbg(wpa_s
, MSG_DEBUG
,
1771 "Allow reassociation due to difference in signal level (%d >= %d)",
1774 #else /* CONFIG_NO_ROAMING */
1776 #endif /* CONFIG_NO_ROAMING */
1781 * Return a negative value if no scan results could be fetched or if scan
1782 * results should not be shared with other virtual interfaces.
1783 * Return 0 if scan results were fetched and may be shared with other
1785 * Return 1 if scan results may be shared with other virtual interfaces but may
1786 * not trigger any operations.
1787 * Return 2 if the interface was removed and cannot be used.
1789 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1790 union wpa_event_data
*data
,
1791 int own_request
, int update_only
)
1793 struct wpa_scan_results
*scan_res
= NULL
;
1796 #ifndef CONFIG_NO_RANDOM_POOL
1798 #endif /* CONFIG_NO_RANDOM_POOL */
1801 if (wpa_s
->ap_iface
)
1803 #endif /* CONFIG_AP */
1805 wpa_supplicant_notify_scanning(wpa_s
, 0);
1807 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1808 data
? &data
->scan_info
:
1810 if (scan_res
== NULL
) {
1811 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1812 wpa_s
->scan_res_handler
== scan_only_handler
)
1816 if (data
&& data
->scan_info
.external_scan
)
1818 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1820 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1822 goto scan_work_done
;
1825 #ifndef CONFIG_NO_RANDOM_POOL
1826 num
= scan_res
->num
;
1829 for (i
= 0; i
< num
; i
++) {
1831 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1832 buf
[0] = res
->bssid
[5];
1833 buf
[1] = res
->qual
& 0xff;
1834 buf
[2] = res
->noise
& 0xff;
1835 buf
[3] = res
->level
& 0xff;
1836 buf
[4] = res
->tsf
& 0xff;
1837 random_add_randomness(buf
, sizeof(buf
));
1839 #endif /* CONFIG_NO_RANDOM_POOL */
1843 goto scan_work_done
;
1846 if (own_request
&& wpa_s
->scan_res_handler
&&
1847 !(data
&& data
->scan_info
.external_scan
)) {
1848 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1849 struct wpa_scan_results
*scan_res
);
1851 scan_res_handler
= wpa_s
->scan_res_handler
;
1852 wpa_s
->scan_res_handler
= NULL
;
1853 scan_res_handler(wpa_s
, scan_res
);
1855 goto scan_work_done
;
1859 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1861 if (wpa_s
->ap_iface
->scan_cb
)
1862 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1863 #endif /* CONFIG_AP */
1864 goto scan_work_done
;
1867 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1868 wpa_s
->own_scan_running
,
1869 data
? data
->scan_info
.external_scan
: 0);
1870 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1871 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1872 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1873 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1874 wpa_s
->manual_scan_id
);
1875 wpa_s
->manual_scan_use_id
= 0;
1877 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1879 wpas_notify_scan_results(wpa_s
);
1881 wpas_notify_scan_done(wpa_s
, 1);
1883 if (data
&& data
->scan_info
.external_scan
) {
1884 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1885 wpa_scan_results_free(scan_res
);
1889 if (wnm_scan_process(wpa_s
, 1) > 0)
1890 goto scan_work_done
;
1892 if (sme_proc_obss_scan(wpa_s
) > 0)
1893 goto scan_work_done
;
1896 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1897 goto scan_work_done
;
1899 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1900 goto scan_work_done
;
1902 if (autoscan_notify_scan(wpa_s
, scan_res
))
1903 goto scan_work_done
;
1905 if (wpa_s
->disconnected
) {
1906 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1907 goto scan_work_done
;
1910 if (!wpas_driver_bss_selection(wpa_s
) &&
1911 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1912 goto scan_work_done
;
1914 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1916 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1917 wpa_s
->wpa_state
< WPA_COMPLETED
)
1918 goto scan_work_done
;
1920 wpa_scan_results_free(scan_res
);
1922 if (own_request
&& wpa_s
->scan_work
) {
1923 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1924 wpa_s
->scan_work
= NULL
;
1925 radio_work_done(work
);
1928 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1931 wpa_scan_results_free(scan_res
);
1932 if (own_request
&& wpa_s
->scan_work
) {
1933 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1934 wpa_s
->scan_work
= NULL
;
1935 radio_work_done(work
);
1941 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1942 int new_scan
, int own_request
)
1944 struct wpa_bss
*selected
;
1945 struct wpa_ssid
*ssid
= NULL
;
1946 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1948 if (time_to_reenable
> 0) {
1949 wpa_dbg(wpa_s
, MSG_DEBUG
,
1950 "Postpone network selection by %d seconds since all networks are disabled",
1952 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1953 eloop_register_timeout(time_to_reenable
, 0,
1954 wpas_network_reenabled
, wpa_s
, NULL
);
1958 if (wpa_s
->p2p_mgmt
)
1959 return 0; /* no normal connection on p2p_mgmt interface */
1961 wpa_s
->owe_transition_search
= 0;
1962 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1966 wpa_msg(wpa_s
, MSG_INFO
,
1967 "Avoiding join because we already joined a mesh group");
1970 #endif /* CONFIG_MESH */
1974 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1977 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1981 if (ssid
!= wpa_s
->current_ssid
&&
1982 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1983 wpa_s
->own_disconnect_req
= 1;
1984 wpa_supplicant_deauthenticate(
1985 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1988 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1989 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1993 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1995 * Do not allow other virtual radios to trigger operations based
1996 * on these scan results since we do not want them to start
1997 * other associations at the same time.
2001 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
2002 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
2004 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
2005 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
2007 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2008 } else if (own_request
) {
2010 * No SSID found. If SCAN results are as a result of
2011 * own scan request and not due to a scan request on
2012 * another shared interface, try another scan.
2014 int timeout_sec
= wpa_s
->scan_interval
;
2015 int timeout_usec
= 0;
2019 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
2025 if (wpa_s
->p2p_in_provisioning
||
2026 wpa_s
->show_group_started
||
2027 wpa_s
->p2p_in_invitation
) {
2029 * Use shorter wait during P2P Provisioning
2030 * state and during P2P join-a-group operation
2031 * to speed up group formation.
2034 timeout_usec
= 250000;
2035 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2039 #endif /* CONFIG_P2P */
2040 #ifdef CONFIG_INTERWORKING
2041 if (wpa_s
->conf
->auto_interworking
&&
2042 wpa_s
->conf
->interworking
&&
2043 wpa_s
->conf
->cred
) {
2044 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2045 "start ANQP fetch since no matching "
2047 wpa_s
->network_select
= 1;
2048 wpa_s
->auto_network_select
= 1;
2049 interworking_start_fetch_anqp(wpa_s
);
2052 #endif /* CONFIG_INTERWORKING */
2054 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2055 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2057 timeout_usec
= 500000;
2058 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2062 #endif /* CONFIG_WPS */
2064 if (wpa_s
->owe_transition_search
) {
2065 wpa_dbg(wpa_s
, MSG_DEBUG
,
2066 "OWE: Use shorter wait during transition mode search");
2068 timeout_usec
= 500000;
2069 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2073 #endif /* CONFIG_OWE */
2074 if (wpa_supplicant_req_sched_scan(wpa_s
))
2075 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2078 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2079 WPA_EVENT_NETWORK_NOT_FOUND
);
2086 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2087 union wpa_event_data
*data
)
2089 struct wpa_supplicant
*ifs
;
2092 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2095 * Interface may have been removed, so must not dereference
2103 * If no scan results could be fetched, then no need to
2104 * notify those interfaces that did not actually request
2105 * this scan. Similarly, if scan results started a new operation on this
2106 * interface, do not notify other interfaces to avoid concurrent
2107 * operations during a connection attempt.
2113 * Check other interfaces to see if they share the same radio. If
2114 * so, they get updated with this same scan info.
2116 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2119 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2120 "sibling", ifs
->ifname
);
2121 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2131 #endif /* CONFIG_NO_SCAN_PROCESSING */
2134 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2136 #ifdef CONFIG_NO_SCAN_PROCESSING
2138 #else /* CONFIG_NO_SCAN_PROCESSING */
2139 struct os_reltime now
;
2141 wpa_s
->ignore_post_flush_scan_res
= 0;
2143 if (wpa_s
->last_scan_res_used
== 0)
2146 os_get_reltime(&now
);
2147 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2148 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2152 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2153 #endif /* CONFIG_NO_SCAN_PROCESSING */
2158 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2160 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2162 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2165 if (!wpa_s
->no_keep_alive
) {
2166 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2167 MAC2STR(wpa_s
->bssid
));
2168 /* TODO: could skip this if normal data traffic has been sent */
2169 /* TODO: Consider using some more appropriate data frame for
2172 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2177 if (wpa_s
->sme
.bss_max_idle_period
) {
2179 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2182 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2183 wnm_bss_keep_alive
, wpa_s
, NULL
);
2185 #endif /* CONFIG_SME */
2189 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2190 const u8
*ies
, size_t ies_len
)
2192 struct ieee802_11_elems elems
;
2197 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2201 if (elems
.bss_max_idle_period
) {
2203 wpa_s
->sme
.bss_max_idle_period
=
2204 WPA_GET_LE16(elems
.bss_max_idle_period
);
2205 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2206 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2207 (elems
.bss_max_idle_period
[2] & 0x01) ?
2208 " (protected keep-live required)" : "");
2209 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2210 wpa_s
->sme
.bss_max_idle_period
= 1;
2211 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2212 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2213 /* msec times 1000 */
2214 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2217 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2218 wnm_bss_keep_alive
, wpa_s
,
2222 #endif /* CONFIG_SME */
2225 #endif /* CONFIG_WNM */
2228 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2231 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2232 #endif /* CONFIG_WNM */
2236 #ifdef CONFIG_INTERWORKING
2238 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2243 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2244 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2246 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2253 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2254 const u8
*ies
, size_t ies_len
)
2256 struct ieee802_11_elems elems
;
2261 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2264 if (elems
.qos_map_set
) {
2265 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2266 elems
.qos_map_set_len
);
2270 #endif /* CONFIG_INTERWORKING */
2273 static void multi_ap_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2274 const u8
*ies
, size_t ies_len
)
2276 struct ieee802_11_elems elems
;
2277 const u8
*map_sub_elem
, *pos
;
2280 if (!wpa_s
->current_ssid
||
2281 !wpa_s
->current_ssid
->multi_ap_backhaul_sta
||
2283 ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2286 if (!elems
.multi_ap
|| elems
.multi_ap_len
< 7) {
2287 wpa_printf(MSG_INFO
, "AP doesn't support Multi-AP protocol");
2291 pos
= elems
.multi_ap
+ 4;
2292 len
= elems
.multi_ap_len
- 4;
2294 map_sub_elem
= get_ie(pos
, len
, MULTI_AP_SUB_ELEM_TYPE
);
2295 if (!map_sub_elem
|| map_sub_elem
[1] < 1) {
2296 wpa_printf(MSG_INFO
, "invalid Multi-AP sub elem type");
2300 if (!(map_sub_elem
[2] & MULTI_AP_BACKHAUL_BSS
)) {
2301 wpa_printf(MSG_INFO
, "AP doesn't support backhaul BSS");
2305 if (wpa_drv_set_4addr_mode(wpa_s
, 1) < 0) {
2306 wpa_printf(MSG_ERROR
, "Failed to set 4addr mode");
2309 wpa_s
->enabled_4addr_mode
= 1;
2313 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2318 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2319 const u8
*ie
, size_t ie_len
)
2321 struct mb_ies_info mb_ies
;
2323 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2326 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2328 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2333 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2338 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2339 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2340 (unsigned int) len
);
2341 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2342 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2350 if (mb_ies
.nof_ies
> 0) {
2351 wpabuf_free(wpa_s
->received_mb_ies
);
2352 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2358 #endif /* CONFIG_FST */
2361 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2362 union wpa_event_data
*data
)
2364 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2366 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2368 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2370 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2371 if (data
->assoc_info
.req_ies
)
2372 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2373 data
->assoc_info
.req_ies_len
);
2374 if (data
->assoc_info
.resp_ies
) {
2375 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2376 data
->assoc_info
.resp_ies_len
);
2378 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2379 data
->assoc_info
.resp_ies_len
);
2380 #endif /* CONFIG_TDLS */
2382 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2383 data
->assoc_info
.resp_ies_len
);
2384 #endif /* CONFIG_WNM */
2385 #ifdef CONFIG_INTERWORKING
2386 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2387 data
->assoc_info
.resp_ies_len
);
2388 #endif /* CONFIG_INTERWORKING */
2389 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2390 get_ie(data
->assoc_info
.resp_ies
,
2391 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2392 wpa_s
->ieee80211ac
= 1;
2394 multi_ap_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2395 data
->assoc_info
.resp_ies_len
);
2397 if (data
->assoc_info
.beacon_ies
)
2398 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2399 data
->assoc_info
.beacon_ies
,
2400 data
->assoc_info
.beacon_ies_len
);
2401 if (data
->assoc_info
.freq
)
2402 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2403 data
->assoc_info
.freq
);
2405 p
= data
->assoc_info
.req_ies
;
2406 l
= data
->assoc_info
.req_ies_len
;
2408 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2409 while (p
&& l
>= 2) {
2412 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2416 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2417 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2418 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2419 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2420 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2421 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2424 wpa_find_assoc_pmkid(wpa_s
);
2430 if (!found
&& data
->assoc_info
.req_ies
)
2431 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2435 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2436 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2437 (!data
->assoc_info
.resp_frame
||
2438 fils_process_assoc_resp(wpa_s
->wpa
,
2439 data
->assoc_info
.resp_frame
,
2440 data
->assoc_info
.resp_frame_len
) < 0)) {
2441 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2444 #endif /* CONFIG_SME */
2446 /* Additional processing for FILS when SME is in driver */
2447 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2448 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2449 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2450 #endif /* CONFIG_FILS */
2453 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2454 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2455 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2456 data
->assoc_info
.resp_ies
,
2457 data
->assoc_info
.resp_ies_len
) < 0)) {
2458 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2461 #endif /* CONFIG_OWE */
2463 #ifdef CONFIG_IEEE80211R
2465 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2466 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2467 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2468 data
->assoc_info
.resp_ies
,
2469 data
->assoc_info
.resp_ies_len
,
2471 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2472 "Reassociation Response failed");
2473 wpa_supplicant_deauthenticate(
2474 wpa_s
, WLAN_REASON_INVALID_IE
);
2479 p
= data
->assoc_info
.resp_ies
;
2480 l
= data
->assoc_info
.resp_ies_len
;
2482 #ifdef CONFIG_WPS_STRICT
2483 if (p
&& wpa_s
->current_ssid
&&
2484 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2486 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2488 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2489 "include WPS IE in (Re)Association Response");
2493 if (wps_validate_assoc_resp(wps
) < 0) {
2495 wpa_supplicant_deauthenticate(
2496 wpa_s
, WLAN_REASON_INVALID_IE
);
2501 #endif /* CONFIG_WPS_STRICT */
2503 /* Go through the IEs and make a copy of the MDIE, if present. */
2504 while (p
&& l
>= 2) {
2507 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2511 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2512 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2513 wpa_s
->sme
.ft_used
= 1;
2514 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2515 MOBILITY_DOMAIN_ID_LEN
);
2521 #endif /* CONFIG_SME */
2523 /* Process FT when SME is in the driver */
2524 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2525 wpa_ft_is_completed(wpa_s
->wpa
)) {
2526 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2527 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2528 data
->assoc_info
.resp_ies
,
2529 data
->assoc_info
.resp_ies_len
,
2531 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2532 "Reassociation Response failed");
2533 wpa_supplicant_deauthenticate(
2534 wpa_s
, WLAN_REASON_INVALID_IE
);
2537 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2540 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2541 data
->assoc_info
.resp_ies_len
);
2542 #endif /* CONFIG_IEEE80211R */
2544 /* WPA/RSN IE from Beacon/ProbeResp */
2545 p
= data
->assoc_info
.beacon_ies
;
2546 l
= data
->assoc_info
.beacon_ies_len
;
2548 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2550 wpa_found
= rsn_found
= 0;
2551 while (p
&& l
>= 2) {
2554 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2559 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2560 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2562 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2566 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2568 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2575 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2576 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2577 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2578 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2579 if (wpa_found
|| rsn_found
)
2580 wpa_s
->ap_ies_from_associnfo
= 1;
2582 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2583 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2584 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2586 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2587 wpa_supplicant_update_scan_results(wpa_s
);
2590 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2596 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2598 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2600 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2603 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2606 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2607 WPA_IE_VENDOR_TYPE
);
2608 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2610 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2611 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2612 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2613 bss_rsn
? 2 + bss_rsn
[1] : 0))
2620 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2621 union wpa_event_data
*data
)
2624 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2625 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2626 const u8
*ieprb
, *iebcn
;
2628 wpabuf_free(wpa_s
->received_mb_ies
);
2629 wpa_s
->received_mb_ies
= NULL
;
2632 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2633 wpa_printf(MSG_DEBUG
,
2634 "FST: MB IEs updated from Association Response frame");
2639 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2640 wpa_printf(MSG_DEBUG
,
2641 "FST: MB IEs updated from association event Beacon IEs");
2648 ieprb
= (const u8
*) (bss
+ 1);
2649 iebcn
= ieprb
+ bss
->ie_len
;
2651 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2652 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2653 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2654 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2655 #endif /* CONFIG_FST */
2659 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2660 union wpa_event_data
*data
)
2663 int ft_completed
, already_authorized
;
2667 if (wpa_s
->ap_iface
) {
2670 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2671 data
->assoc_info
.addr
,
2672 data
->assoc_info
.req_ies
,
2673 data
->assoc_info
.req_ies_len
,
2674 data
->assoc_info
.reassoc
);
2677 #endif /* CONFIG_AP */
2679 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2681 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2682 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2685 * FILS authentication can share the same mechanism to mark the
2686 * connection fully authenticated, so set ft_completed also based on
2690 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2692 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2693 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2694 wpa_supplicant_deauthenticate(
2695 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2699 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2700 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2701 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2702 MACSTR
, MAC2STR(bssid
));
2704 random_add_randomness(bssid
, ETH_ALEN
);
2705 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2706 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2707 wpas_notify_bssid_changed(wpa_s
);
2709 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2710 wpa_clear_keys(wpa_s
, bssid
);
2712 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2713 wpa_supplicant_deauthenticate(
2714 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2719 if (wpa_s
->conf
->ap_scan
== 1 &&
2720 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2721 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2722 wpa_msg(wpa_s
, MSG_WARNING
,
2723 "WPA/RSN IEs not updated");
2726 wpas_fst_update_mb_assoc(wpa_s
, data
);
2729 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2730 wpa_s
->sme
.prev_bssid_set
= 1;
2731 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2732 #endif /* CONFIG_SME */
2734 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2735 if (wpa_s
->current_ssid
) {
2736 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2737 * initialized before association, but for other modes,
2738 * initialize PC/SC here, if the current configuration needs
2739 * smartcard or SIM/USIM. */
2740 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2742 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2744 l2_packet_notify_auth_start(wpa_s
->l2
);
2746 already_authorized
= data
&& data
->assoc_info
.authorized
;
2749 * Set portEnabled first to FALSE in order to get EAP state machine out
2750 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2751 * state machine may transit to AUTHENTICATING state based on obsolete
2752 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2753 * AUTHENTICATED without ever giving chance to EAP state machine to
2756 if (!ft_completed
&& !already_authorized
) {
2757 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2758 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2760 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2761 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2762 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2764 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2765 /* 802.1X::portControl = Auto */
2766 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2767 wpa_s
->eapol_received
= 0;
2768 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2769 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2770 (wpa_s
->current_ssid
&&
2771 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2772 if (wpa_s
->current_ssid
&&
2773 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2775 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2777 * Set the key after having received joined-IBSS event
2780 wpa_supplicant_set_wpa_none_key(wpa_s
,
2781 wpa_s
->current_ssid
);
2783 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2784 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2785 } else if (!ft_completed
) {
2786 /* Timeout for receiving the first EAPOL packet */
2787 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2789 wpa_supplicant_cancel_scan(wpa_s
);
2791 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2792 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2794 * We are done; the driver will take care of RSN 4-way
2797 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2798 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2799 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2800 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2801 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2802 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2804 * The driver will take care of RSN 4-way handshake, so we need
2805 * to allow EAPOL supplicant to complete its work without
2806 * waiting for WPA supplicant.
2808 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2809 } else if (ft_completed
) {
2811 * FT protocol completed - make sure EAPOL state machine ends
2812 * up in authenticated.
2814 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2815 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2816 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2817 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2820 wpa_s
->last_eapol_matches_bssid
= 0;
2822 if (wpa_s
->pending_eapol_rx
) {
2823 struct os_reltime now
, age
;
2824 os_get_reltime(&now
);
2825 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2826 if (age
.sec
== 0 && age
.usec
< 200000 &&
2827 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2829 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2830 "frame that was received just before "
2831 "association notification");
2832 wpa_supplicant_rx_eapol(
2833 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2834 wpabuf_head(wpa_s
->pending_eapol_rx
),
2835 wpabuf_len(wpa_s
->pending_eapol_rx
));
2837 wpabuf_free(wpa_s
->pending_eapol_rx
);
2838 wpa_s
->pending_eapol_rx
= NULL
;
2841 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2842 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2843 wpa_s
->current_ssid
&&
2844 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2845 /* Set static WEP keys again */
2846 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2849 #ifdef CONFIG_IBSS_RSN
2850 if (wpa_s
->current_ssid
&&
2851 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2852 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2853 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2854 wpa_s
->ibss_rsn
== NULL
) {
2855 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2856 if (!wpa_s
->ibss_rsn
) {
2857 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2858 wpa_supplicant_deauthenticate(
2859 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2863 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2865 #endif /* CONFIG_IBSS_RSN */
2867 wpas_wps_notify_assoc(wpa_s
, bssid
);
2870 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2871 data
->assoc_info
.resp_ies_len
,
2872 &data
->assoc_info
.wmm_params
);
2874 if (wpa_s
->reassoc_same_bss
)
2875 wmm_ac_restore_tspecs(wpa_s
);
2879 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2880 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2881 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2884 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2886 #endif /* CONFIG_FILS */
2890 static int disconnect_reason_recoverable(u16 reason_code
)
2892 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2893 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2894 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2898 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2900 int locally_generated
)
2904 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2906 * At least Host AP driver and a Prism3 card seemed to be
2907 * generating streams of disconnected events when configuring
2908 * IBSS for WPA-None. Ignore them for now.
2913 bssid
= wpa_s
->bssid
;
2914 if (is_zero_ether_addr(bssid
))
2915 bssid
= wpa_s
->pending_bssid
;
2917 if (!is_zero_ether_addr(bssid
) ||
2918 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2919 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2921 MAC2STR(bssid
), reason_code
,
2922 locally_generated
? " locally_generated=1" : "");
2927 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2928 int locally_generated
)
2930 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2931 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2932 return 0; /* Not in 4-way handshake with PSK */
2935 * It looks like connection was lost while trying to go through PSK
2936 * 4-way handshake. Filter out known disconnection cases that are caused
2937 * by something else than PSK mismatch to avoid confusing reports.
2940 if (locally_generated
) {
2941 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2949 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2951 int locally_generated
)
2955 u8 prev_pending_bssid
[ETH_ALEN
];
2956 struct wpa_bss
*fast_reconnect
= NULL
;
2957 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2958 struct wpa_ssid
*last_ssid
;
2959 struct wpa_bss
*curr
= NULL
;
2961 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2962 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2964 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2966 * At least Host AP driver and a Prism3 card seemed to be
2967 * generating streams of disconnected events when configuring
2968 * IBSS for WPA-None. Ignore them for now.
2970 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2971 "IBSS/WPA-None mode");
2975 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2976 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2979 * Remove the inactive AP (which is probably out of range) from
2980 * the BSS list after marking disassociation. In particular
2981 * mac80211-based drivers use the
2982 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2983 * locally generated disconnection events for cases where the
2984 * AP does not reply anymore.
2986 curr
= wpa_s
->current_bss
;
2988 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2989 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2990 "pre-shared key may be incorrect");
2991 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2992 return; /* P2P group removed */
2993 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2995 if (!wpa_s
->disconnected
&&
2996 (!wpa_s
->auto_reconnect_disabled
||
2997 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2998 wpas_wps_searching(wpa_s
) ||
2999 wpas_wps_reenable_networks_pending(wpa_s
))) {
3000 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
3001 "reconnect (wps=%d/%d wpa_state=%d)",
3002 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
3003 wpas_wps_searching(wpa_s
),
3005 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
3006 wpa_s
->current_ssid
&&
3007 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
3008 !locally_generated
&&
3009 disconnect_reason_recoverable(reason_code
)) {
3011 * It looks like the AP has dropped association with
3012 * us, but could allow us to get back in. Try to
3013 * reconnect to the same BSS without full scan to save
3014 * time for some common cases.
3016 fast_reconnect
= wpa_s
->current_bss
;
3017 fast_reconnect_ssid
= wpa_s
->current_ssid
;
3018 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
3019 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3021 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
3024 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
3025 "try to re-connect");
3026 wpa_s
->reassociate
= 0;
3027 wpa_s
->disconnected
= 1;
3029 wpa_supplicant_cancel_sched_scan(wpa_s
);
3031 bssid
= wpa_s
->bssid
;
3032 if (is_zero_ether_addr(bssid
))
3033 bssid
= wpa_s
->pending_bssid
;
3034 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3035 wpas_connection_failed(wpa_s
, bssid
);
3036 wpa_sm_notify_disassoc(wpa_s
->wpa
);
3037 if (locally_generated
)
3038 wpa_s
->disconnect_reason
= -reason_code
;
3040 wpa_s
->disconnect_reason
= reason_code
;
3041 wpas_notify_disconnect_reason(wpa_s
);
3042 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
3043 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
3044 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
3046 last_ssid
= wpa_s
->current_ssid
;
3047 wpa_supplicant_mark_disassoc(wpa_s
);
3050 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
3052 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
3053 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
3054 wpa_s
->current_ssid
= last_ssid
;
3057 if (fast_reconnect
&&
3058 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
3059 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
3060 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
3061 fast_reconnect
->ssid_len
) &&
3062 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
3063 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
3064 #ifndef CONFIG_NO_SCAN_PROCESSING
3065 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
3066 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
3067 fast_reconnect_ssid
) < 0) {
3068 /* Recover through full scan */
3069 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3071 #endif /* CONFIG_NO_SCAN_PROCESSING */
3072 } else if (fast_reconnect
) {
3074 * Could not reconnect to the same BSS due to network being
3075 * disabled. Use a new scan to match the alternative behavior
3076 * above, i.e., to continue automatic reconnection attempt in a
3077 * way that enforces disabled network rules.
3079 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3084 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3085 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
3087 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3089 if (!wpa_s
->pending_mic_error_report
)
3092 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3093 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3094 wpa_s
->pending_mic_error_report
= 0;
3096 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3100 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3101 union wpa_event_data
*data
)
3104 struct os_reltime t
;
3106 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3107 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3109 if ((wpa_s
->last_michael_mic_error
.sec
&&
3110 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3111 wpa_s
->pending_mic_error_report
) {
3112 if (wpa_s
->pending_mic_error_report
) {
3114 * Send the pending MIC error report immediately since
3115 * we are going to start countermeasures and AP better
3118 wpa_sm_key_request(wpa_s
->wpa
, 1,
3119 wpa_s
->pending_mic_error_pairwise
);
3122 /* Send the new MIC error report immediately since we are going
3123 * to start countermeasures and AP better do the same.
3125 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3127 /* initialize countermeasures */
3128 wpa_s
->countermeasures
= 1;
3130 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3132 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3135 * Need to wait for completion of request frame. We do not get
3136 * any callback for the message completion, so just wait a
3137 * short while and hope for the best. */
3140 wpa_drv_set_countermeasures(wpa_s
, 1);
3141 wpa_supplicant_deauthenticate(wpa_s
,
3142 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3143 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3145 eloop_register_timeout(60, 0,
3146 wpa_supplicant_stop_countermeasures
,
3148 /* TODO: mark the AP rejected for 60 second. STA is
3149 * allowed to associate with another AP.. */
3151 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3152 if (wpa_s
->mic_errors_seen
) {
3154 * Reduce the effectiveness of Michael MIC error
3155 * reports as a means for attacking against TKIP if
3156 * more than one MIC failure is noticed with the same
3157 * PTK. We delay the transmission of the reports by a
3158 * random time between 0 and 60 seconds in order to
3159 * force the attacker wait 60 seconds before getting
3160 * the information on whether a frame resulted in a MIC
3166 if (os_get_random(rval
, sizeof(rval
)) < 0)
3167 sec
= os_random() % 60;
3169 sec
= WPA_GET_BE32(rval
) % 60;
3170 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3171 "report %d seconds", sec
);
3172 wpa_s
->pending_mic_error_report
= 1;
3173 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3174 eloop_cancel_timeout(
3175 wpa_supplicant_delayed_mic_error_report
,
3177 eloop_register_timeout(
3178 sec
, os_random() % 1000000,
3179 wpa_supplicant_delayed_mic_error_report
,
3182 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3184 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3185 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3186 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3188 wpa_s
->last_michael_mic_error
= t
;
3189 wpa_s
->mic_errors_seen
++;
3193 #ifdef CONFIG_TERMINATE_ONLASTIF
3194 static int any_interfaces(struct wpa_supplicant
*head
)
3196 struct wpa_supplicant
*wpa_s
;
3198 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3199 if (!wpa_s
->interface_removed
)
3203 #endif /* CONFIG_TERMINATE_ONLASTIF */
3207 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3208 union wpa_event_data
*data
)
3210 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3213 switch (data
->interface_status
.ievent
) {
3214 case EVENT_INTERFACE_ADDED
:
3215 if (!wpa_s
->interface_removed
)
3217 wpa_s
->interface_removed
= 0;
3218 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3219 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3220 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3221 "driver after interface was added");
3225 if (!wpa_s
->global
->p2p
&&
3226 !wpa_s
->global
->p2p_disabled
&&
3227 !wpa_s
->conf
->p2p_disabled
&&
3229 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3230 wpas_p2p_add_p2pdev_interface(
3231 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3232 wpa_printf(MSG_INFO
,
3233 "P2P: Failed to enable P2P Device interface");
3234 /* Try to continue without. P2P will be disabled. */
3236 #endif /* CONFIG_P2P */
3239 case EVENT_INTERFACE_REMOVED
:
3240 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3241 wpa_s
->interface_removed
= 1;
3242 wpa_supplicant_mark_disassoc(wpa_s
);
3243 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3244 l2_packet_deinit(wpa_s
->l2
);
3248 if (wpa_s
->global
->p2p
&&
3249 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3251 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3252 wpa_dbg(wpa_s
, MSG_DEBUG
,
3253 "Removing P2P Device interface");
3254 wpa_supplicant_remove_iface(
3255 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3257 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3259 #endif /* CONFIG_P2P */
3261 #ifdef CONFIG_MATCH_IFACE
3262 if (wpa_s
->matched
) {
3263 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3266 #endif /* CONFIG_MATCH_IFACE */
3268 #ifdef CONFIG_TERMINATE_ONLASTIF
3269 /* check if last interface */
3270 if (!any_interfaces(wpa_s
->global
->ifaces
))
3272 #endif /* CONFIG_TERMINATE_ONLASTIF */
3279 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3280 union wpa_event_data
*data
)
3284 switch (data
->tdls
.oper
) {
3285 case TDLS_REQUEST_SETUP
:
3286 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3287 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3288 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3290 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3292 case TDLS_REQUEST_TEARDOWN
:
3293 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3294 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3295 data
->tdls
.reason_code
);
3297 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3300 case TDLS_REQUEST_DISCOVER
:
3301 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3306 #endif /* CONFIG_TDLS */
3310 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3311 union wpa_event_data
*data
)
3315 switch (data
->wnm
.oper
) {
3316 case WNM_OPER_SLEEP
:
3317 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3318 "(action=%d, intval=%d)",
3319 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3320 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3321 data
->wnm
.sleep_intval
, NULL
);
3325 #endif /* CONFIG_WNM */
3328 #ifdef CONFIG_IEEE80211R
3330 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3331 union wpa_event_data
*data
)
3336 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3337 data
->ft_ies
.ies_len
,
3338 data
->ft_ies
.ft_action
,
3339 data
->ft_ies
.target_ap
,
3340 data
->ft_ies
.ric_ies
,
3341 data
->ft_ies
.ric_ies_len
) < 0) {
3342 /* TODO: prevent MLME/driver from trying to associate? */
3345 #endif /* CONFIG_IEEE80211R */
3348 #ifdef CONFIG_IBSS_RSN
3349 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3350 union wpa_event_data
*data
)
3352 struct wpa_ssid
*ssid
;
3353 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3357 ssid
= wpa_s
->current_ssid
;
3360 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3363 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3367 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3368 union wpa_event_data
*data
)
3370 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3375 /* check if the ssid is correctly configured as IBSS/RSN */
3376 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3379 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3380 data
->rx_mgmt
.frame_len
);
3382 #endif /* CONFIG_IBSS_RSN */
3385 #ifdef CONFIG_IEEE80211R
3386 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3389 const u8
*sta_addr
, *target_ap_addr
;
3392 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3393 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3394 return; /* only SME case supported for now */
3395 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3398 return; /* Only FT Action Response is supported for now */
3399 sta_addr
= data
+ 1;
3400 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3401 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3402 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3403 MACSTR
" TargetAP " MACSTR
" status %u",
3404 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3406 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3407 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3408 " in FT Action Response", MAC2STR(sta_addr
));
3413 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3414 "failure (status code %d)", status
);
3415 /* TODO: report error to FT code(?) */
3419 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3420 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3421 target_ap_addr
, NULL
, 0) < 0)
3426 struct wpa_bss
*bss
;
3427 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3429 wpa_s
->sme
.freq
= bss
->freq
;
3430 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3431 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3434 #endif /* CONFIG_SME */
3436 #endif /* CONFIG_IEEE80211R */
3439 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3440 struct unprot_deauth
*e
)
3442 #ifdef CONFIG_IEEE80211W
3443 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3444 "dropped: " MACSTR
" -> " MACSTR
3445 " (reason code %u)",
3446 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3447 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3448 #endif /* CONFIG_IEEE80211W */
3452 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3453 struct unprot_disassoc
*e
)
3455 #ifdef CONFIG_IEEE80211W
3456 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3457 "dropped: " MACSTR
" -> " MACSTR
3458 " (reason code %u)",
3459 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3460 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3461 #endif /* CONFIG_IEEE80211W */
3465 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3466 u16 reason_code
, int locally_generated
,
3467 const u8
*ie
, size_t ie_len
, int deauth
)
3470 if (wpa_s
->ap_iface
&& addr
) {
3471 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3475 if (wpa_s
->ap_iface
) {
3476 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3479 #endif /* CONFIG_AP */
3481 if (!locally_generated
)
3482 wpa_s
->own_disconnect_req
= 0;
3484 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3486 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3487 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3488 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3489 eapol_sm_failed(wpa_s
->eapol
))) &&
3490 !wpa_s
->eap_expected_failure
))
3491 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3494 if (deauth
&& reason_code
> 0) {
3495 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3496 locally_generated
) > 0) {
3498 * The interface was removed, so cannot continue
3499 * processing any additional operations after this.
3504 #endif /* CONFIG_P2P */
3506 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3511 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3512 struct disassoc_info
*info
)
3514 u16 reason_code
= 0;
3515 int locally_generated
= 0;
3516 const u8
*addr
= NULL
;
3517 const u8
*ie
= NULL
;
3520 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3525 ie_len
= info
->ie_len
;
3526 reason_code
= info
->reason_code
;
3527 locally_generated
= info
->locally_generated
;
3528 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3529 locally_generated
? " (locally generated)" : "");
3531 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3533 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3538 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3539 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3543 if (wpa_s
->ap_iface
) {
3544 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3547 #endif /* CONFIG_AP */
3551 wpas_p2p_disassoc_notif(
3552 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3555 #endif /* CONFIG_P2P */
3557 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3558 sme_event_disassoc(wpa_s
, info
);
3560 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3565 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3566 struct deauth_info
*info
)
3568 u16 reason_code
= 0;
3569 int locally_generated
= 0;
3570 const u8
*addr
= NULL
;
3571 const u8
*ie
= NULL
;
3574 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3579 ie_len
= info
->ie_len
;
3580 reason_code
= info
->reason_code
;
3581 locally_generated
= info
->locally_generated
;
3582 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3584 locally_generated
? " (locally generated)" : "");
3586 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3589 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3593 wpa_reset_ft_completed(wpa_s
->wpa
);
3595 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3596 locally_generated
, ie
, ie_len
, 1);
3600 static const char * reg_init_str(enum reg_change_initiator init
)
3603 case REGDOM_SET_BY_CORE
:
3605 case REGDOM_SET_BY_USER
:
3607 case REGDOM_SET_BY_DRIVER
:
3609 case REGDOM_SET_BY_COUNTRY_IE
:
3610 return "COUNTRY_IE";
3611 case REGDOM_BEACON_HINT
:
3612 return "BEACON_HINT";
3618 static const char * reg_type_str(enum reg_type type
)
3621 case REGDOM_TYPE_UNKNOWN
:
3623 case REGDOM_TYPE_COUNTRY
:
3625 case REGDOM_TYPE_WORLD
:
3627 case REGDOM_TYPE_CUSTOM_WORLD
:
3628 return "CUSTOM_WORLD";
3629 case REGDOM_TYPE_INTERSECTION
:
3630 return "INTERSECTION";
3636 void wpa_supplicant_update_channel_list(struct wpa_supplicant
*wpa_s
,
3637 struct channel_list_changed
*info
)
3639 struct wpa_supplicant
*ifs
;
3643 * To allow backwards compatibility with higher level layers that
3644 * assumed the REGDOM_CHANGE event is sent over the initially added
3645 * interface. Find the highest parent of this interface and use it to
3648 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3652 wpa_msg(ifs
, MSG_INFO
,
3653 WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3654 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3655 info
->alpha2
[0] ? " alpha2=" : "",
3656 info
->alpha2
[0] ? info
->alpha2
: "");
3659 if (wpa_s
->drv_priv
== NULL
)
3660 return; /* Ignore event during drv initialization */
3662 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3664 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3666 free_hw_features(ifs
);
3667 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3668 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3670 /* Restart PNO/sched_scan with updated channel list */
3673 wpas_start_pno(ifs
);
3674 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3675 wpa_dbg(ifs
, MSG_DEBUG
,
3676 "Channel list changed - restart sched_scan");
3677 wpas_scan_restart_sched_scan(ifs
);
3681 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3685 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3686 const u8
*frame
, size_t len
, int freq
,
3689 const struct ieee80211_mgmt
*mgmt
;
3694 if (len
< IEEE80211_HDRLEN
+ 2)
3697 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3698 payload
= frame
+ IEEE80211_HDRLEN
;
3699 category
= *payload
++;
3700 plen
= len
- IEEE80211_HDRLEN
- 1;
3702 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3703 " Category=%u DataLen=%d freq=%d MHz",
3704 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3706 if (category
== WLAN_ACTION_WMM
) {
3707 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3711 #ifdef CONFIG_IEEE80211R
3712 if (category
== WLAN_ACTION_FT
) {
3713 ft_rx_action(wpa_s
, payload
, plen
);
3716 #endif /* CONFIG_IEEE80211R */
3718 #ifdef CONFIG_IEEE80211W
3720 if (category
== WLAN_ACTION_SA_QUERY
) {
3721 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3724 #endif /* CONFIG_SME */
3725 #endif /* CONFIG_IEEE80211W */
3728 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3729 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3732 #endif /* CONFIG_WNM */
3735 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3736 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3737 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3738 mgmt
->u
.action
.category
,
3739 payload
, plen
, freq
) == 0)
3741 #endif /* CONFIG_GAS */
3743 #ifdef CONFIG_GAS_SERVER
3744 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3745 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3746 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3747 mgmt
->u
.action
.category
,
3748 payload
, plen
, freq
) == 0)
3750 #endif /* CONFIG_GAS_SERVER */
3753 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3754 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3755 wpa_dbg(wpa_s
, MSG_DEBUG
,
3756 "TDLS: Received Discovery Response from " MACSTR
,
3760 #endif /* CONFIG_TDLS */
3762 #ifdef CONFIG_INTERWORKING
3763 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3764 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3765 const u8
*pos
= payload
+ 1;
3766 size_t qlen
= plen
- 1;
3767 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3768 MACSTR
, MAC2STR(mgmt
->sa
));
3769 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3770 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3771 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3772 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3775 #endif /* CONFIG_INTERWORKING */
3777 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3778 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3779 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3786 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3787 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3788 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3792 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3793 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3794 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3795 payload
+ 1, plen
- 1,
3801 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3802 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3805 #endif /* CONFIG_FST */
3808 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3809 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3810 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3811 payload
[4] == DPP_OUI_TYPE
) {
3814 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3817 #endif /* CONFIG_DPP */
3819 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3820 category
, payload
, plen
, freq
);
3822 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3826 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3827 union wpa_event_data
*event
)
3829 struct wpa_freq_range_list
*list
;
3832 list
= &event
->freq_range
;
3835 str
= freq_range_list_str(list
);
3836 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3840 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3841 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3844 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3847 * The update channel flow will also take care of moving a GO
3848 * from the unsafe frequency if needed.
3850 wpas_p2p_update_channel_list(wpa_s
,
3851 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3853 #endif /* CONFIG_P2P */
3859 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
3861 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3862 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3863 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3864 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3865 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3870 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
3876 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
3877 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
3879 for (j
= 0; j
< mode
->num_channels
; j
++) {
3880 const struct hostapd_channel_data
*chan
;
3882 chan
= &mode
->channels
[j
];
3883 if (chan
->freq
== freq
)
3884 return chan
->dfs_cac_ms
;
3892 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
3893 struct dfs_event
*radar
)
3895 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3896 if (wpa_s
->ap_iface
) {
3897 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
3899 #endif /* NEED_AP_MLME && CONFIG_AP */
3901 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
3903 cac_time
/= 1000; /* convert from ms to sec */
3905 cac_time
= 10 * 60; /* max timeout: 10 minutes */
3907 /* Restart auth timeout: CAC time added to initial timeout */
3908 wpas_auth_timeout_restart(wpa_s
, cac_time
);
3913 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
3914 struct dfs_event
*radar
)
3916 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3917 if (wpa_s
->ap_iface
) {
3918 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
3920 #endif /* NEED_AP_MLME && CONFIG_AP */
3922 /* Restart auth timeout with original value after CAC is
3924 wpas_auth_timeout_restart(wpa_s
, 0);
3929 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
3930 struct dfs_event
*radar
)
3932 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3933 if (wpa_s
->ap_iface
) {
3934 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
3936 #endif /* NEED_AP_MLME && CONFIG_AP */
3938 /* Restart auth timeout with original value after CAC is
3940 wpas_auth_timeout_restart(wpa_s
, 0);
3945 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3946 union wpa_event_data
*data
)
3948 wpa_dbg(wpa_s
, MSG_DEBUG
,
3949 "Connection authorized by device, previous state %d",
3952 wpa_supplicant_event_port_authorized(wpa_s
);
3954 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3955 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3956 data
->assoc_info
.ptk_kck_len
,
3957 data
->assoc_info
.ptk_kek
,
3958 data
->assoc_info
.ptk_kek_len
);
3960 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3961 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3962 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3964 /* Update ERP next sequence number */
3965 eapol_sm_update_erp_next_seq_num(
3966 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3968 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3969 /* Add the new PMK and PMKID to the PMKSA cache */
3970 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3971 data
->assoc_info
.fils_pmk
,
3972 data
->assoc_info
.fils_pmk_len
,
3973 data
->assoc_info
.fils_pmkid
,
3974 wpa_s
->bssid
, fils_cache_id
);
3975 } else if (data
->assoc_info
.fils_pmkid
) {
3976 /* Update the current PMKSA used for this connection */
3977 pmksa_cache_set_current(wpa_s
->wpa
,
3978 data
->assoc_info
.fils_pmkid
,
3979 NULL
, NULL
, 0, NULL
, 0);
3982 #endif /* CONFIG_FILS */
3986 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
3987 union wpa_event_data
*data
)
3989 const u8
*bssid
= data
->assoc_reject
.bssid
;
3991 if (!bssid
|| is_zero_ether_addr(bssid
))
3992 bssid
= wpa_s
->pending_bssid
;
3994 if (data
->assoc_reject
.bssid
)
3995 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3996 "bssid=" MACSTR
" status_code=%u%s%s%s",
3997 MAC2STR(data
->assoc_reject
.bssid
),
3998 data
->assoc_reject
.status_code
,
3999 data
->assoc_reject
.timed_out
? " timeout" : "",
4000 data
->assoc_reject
.timeout_reason
? "=" : "",
4001 data
->assoc_reject
.timeout_reason
?
4002 data
->assoc_reject
.timeout_reason
: "");
4004 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
4005 "status_code=%u%s%s%s",
4006 data
->assoc_reject
.status_code
,
4007 data
->assoc_reject
.timed_out
? " timeout" : "",
4008 data
->assoc_reject
.timeout_reason
? "=" : "",
4009 data
->assoc_reject
.timeout_reason
?
4010 data
->assoc_reject
.timeout_reason
: "");
4011 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
4012 wpas_notify_assoc_status_code(wpa_s
);
4015 if (data
->assoc_reject
.status_code
==
4016 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
4017 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
4018 wpa_s
->current_ssid
&&
4019 wpa_s
->current_ssid
->owe_group
== 0 &&
4020 wpa_s
->last_owe_group
!= 21) {
4021 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4022 struct wpa_bss
*bss
= wpa_s
->current_bss
;
4025 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
4027 wpas_connection_failed(wpa_s
, bssid
);
4028 wpa_supplicant_mark_disassoc(wpa_s
);
4032 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
4033 wpas_connect_work_done(wpa_s
);
4034 wpa_supplicant_mark_disassoc(wpa_s
);
4035 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4038 #endif /* CONFIG_OWE */
4040 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
4041 sme_event_assoc_reject(wpa_s
, data
);
4045 /* Driver-based SME cases */
4048 if (wpa_s
->current_ssid
&&
4049 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
4050 !data
->assoc_reject
.timed_out
) {
4051 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
4052 wpa_sm_aborted_cached(wpa_s
->wpa
);
4053 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4055 #endif /* CONFIG_SAE */
4058 if (wpa_s
->current_ssid
&&
4059 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_DPP
&&
4060 !data
->assoc_reject
.timed_out
) {
4061 wpa_dbg(wpa_s
, MSG_DEBUG
, "DPP: Drop PMKSA cache entry");
4062 wpa_sm_aborted_cached(wpa_s
->wpa
);
4063 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4065 #endif /* CONFIG_DPP */
4068 /* Update ERP next sequence number */
4069 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4070 eapol_sm_update_erp_next_seq_num(
4072 data
->assoc_reject
.fils_erp_next_seq_num
);
4073 fils_connection_failure(wpa_s
);
4075 #endif /* CONFIG_FILS */
4077 wpas_connection_failed(wpa_s
, bssid
);
4078 wpa_supplicant_mark_disassoc(wpa_s
);
4082 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
4083 union wpa_event_data
*data
)
4085 struct wpa_supplicant
*wpa_s
= ctx
;
4087 #ifndef CONFIG_NO_STDOUT_DEBUG
4088 int level
= MSG_DEBUG
;
4089 #endif /* CONFIG_NO_STDOUT_DEBUG */
4091 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
4092 event
!= EVENT_INTERFACE_ENABLED
&&
4093 event
!= EVENT_INTERFACE_STATUS
&&
4094 event
!= EVENT_SCAN_RESULTS
&&
4095 event
!= EVENT_SCHED_SCAN_STOPPED
) {
4096 wpa_dbg(wpa_s
, MSG_DEBUG
,
4097 "Ignore event %s (%d) while interface is disabled",
4098 event_to_string(event
), event
);
4102 #ifndef CONFIG_NO_STDOUT_DEBUG
4103 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
4104 const struct ieee80211_hdr
*hdr
;
4106 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4107 fc
= le_to_host16(hdr
->frame_control
);
4108 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4109 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4110 level
= MSG_EXCESSIVE
;
4113 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4114 event_to_string(event
), event
);
4115 #endif /* CONFIG_NO_STDOUT_DEBUG */
4120 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4121 data
->auth
.ies_len
))
4122 wpa_printf(MSG_DEBUG
,
4123 "FST: MB IEs updated from auth IE");
4124 #endif /* CONFIG_FST */
4125 sme_event_auth(wpa_s
, data
);
4128 #ifdef CONFIG_TESTING_OPTIONS
4129 if (wpa_s
->ignore_auth_resp
) {
4130 wpa_printf(MSG_INFO
,
4131 "EVENT_ASSOC - ignore_auth_resp active!");
4134 if (wpa_s
->testing_resend_assoc
) {
4135 wpa_printf(MSG_INFO
,
4136 "EVENT_DEAUTH - testing_resend_assoc");
4139 #endif /* CONFIG_TESTING_OPTIONS */
4140 wpa_supplicant_event_assoc(wpa_s
, data
);
4141 wpa_s
->assoc_status_code
= WLAN_STATUS_SUCCESS
;
4143 (data
->assoc_info
.authorized
||
4144 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4145 wpa_fils_is_completed(wpa_s
->wpa
))))
4146 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4148 wpa_msg(wpa_s
, MSG_INFO
,
4149 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4150 data
->assoc_info
.subnet_status
);
4153 case EVENT_DISASSOC
:
4154 wpas_event_disassoc(wpa_s
,
4155 data
? &data
->disassoc_info
: NULL
);
4158 #ifdef CONFIG_TESTING_OPTIONS
4159 if (wpa_s
->ignore_auth_resp
) {
4160 wpa_printf(MSG_INFO
,
4161 "EVENT_DEAUTH - ignore_auth_resp active!");
4164 if (wpa_s
->testing_resend_assoc
) {
4165 wpa_printf(MSG_INFO
,
4166 "EVENT_DEAUTH - testing_resend_assoc");
4169 #endif /* CONFIG_TESTING_OPTIONS */
4170 wpas_event_deauth(wpa_s
,
4171 data
? &data
->deauth_info
: NULL
);
4173 case EVENT_MICHAEL_MIC_FAILURE
:
4174 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4176 #ifndef CONFIG_NO_SCAN_PROCESSING
4177 case EVENT_SCAN_STARTED
:
4178 if (wpa_s
->own_scan_requested
||
4179 (data
&& !data
->scan_info
.external_scan
)) {
4180 struct os_reltime diff
;
4182 os_get_reltime(&wpa_s
->scan_start_time
);
4183 os_reltime_sub(&wpa_s
->scan_start_time
,
4184 &wpa_s
->scan_trigger_time
, &diff
);
4185 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4186 diff
.sec
, diff
.usec
);
4187 wpa_s
->own_scan_requested
= 0;
4188 wpa_s
->own_scan_running
= 1;
4189 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4190 wpa_s
->manual_scan_use_id
) {
4191 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4192 WPA_EVENT_SCAN_STARTED
"id=%u",
4193 wpa_s
->manual_scan_id
);
4195 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4196 WPA_EVENT_SCAN_STARTED
);
4199 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4200 wpa_s
->radio
->external_scan_running
= 1;
4201 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4204 case EVENT_SCAN_RESULTS
:
4205 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4206 wpa_s
->scan_res_handler
= NULL
;
4207 wpa_s
->own_scan_running
= 0;
4208 wpa_s
->radio
->external_scan_running
= 0;
4209 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4213 if (!(data
&& data
->scan_info
.external_scan
) &&
4214 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4215 struct os_reltime now
, diff
;
4216 os_get_reltime(&now
);
4217 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4218 wpa_s
->scan_start_time
.sec
= 0;
4219 wpa_s
->scan_start_time
.usec
= 0;
4220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4221 diff
.sec
, diff
.usec
);
4223 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4224 break; /* interface may have been removed */
4225 if (!(data
&& data
->scan_info
.external_scan
))
4226 wpa_s
->own_scan_running
= 0;
4227 if (data
&& data
->scan_info
.nl_scan_event
)
4228 wpa_s
->radio
->external_scan_running
= 0;
4229 radio_work_check_next(wpa_s
);
4231 #endif /* CONFIG_NO_SCAN_PROCESSING */
4232 case EVENT_ASSOCINFO
:
4233 wpa_supplicant_event_associnfo(wpa_s
, data
);
4235 case EVENT_INTERFACE_STATUS
:
4236 wpa_supplicant_event_interface_status(wpa_s
, data
);
4238 case EVENT_PMKID_CANDIDATE
:
4239 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4243 wpa_supplicant_event_tdls(wpa_s
, data
);
4245 #endif /* CONFIG_TDLS */
4248 wpa_supplicant_event_wnm(wpa_s
, data
);
4250 #endif /* CONFIG_WNM */
4251 #ifdef CONFIG_IEEE80211R
4252 case EVENT_FT_RESPONSE
:
4253 wpa_supplicant_event_ft_response(wpa_s
, data
);
4255 #endif /* CONFIG_IEEE80211R */
4256 #ifdef CONFIG_IBSS_RSN
4257 case EVENT_IBSS_RSN_START
:
4258 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4260 #endif /* CONFIG_IBSS_RSN */
4261 case EVENT_ASSOC_REJECT
:
4262 wpas_event_assoc_reject(wpa_s
, data
);
4264 case EVENT_AUTH_TIMED_OUT
:
4265 /* It is possible to get this event from earlier connection */
4266 if (wpa_s
->current_ssid
&&
4267 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4268 wpa_dbg(wpa_s
, MSG_DEBUG
,
4269 "Ignore AUTH_TIMED_OUT in mesh configuration");
4272 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4273 sme_event_auth_timed_out(wpa_s
, data
);
4275 case EVENT_ASSOC_TIMED_OUT
:
4276 /* It is possible to get this event from earlier connection */
4277 if (wpa_s
->current_ssid
&&
4278 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4279 wpa_dbg(wpa_s
, MSG_DEBUG
,
4280 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4283 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4284 sme_event_assoc_timed_out(wpa_s
, data
);
4286 case EVENT_TX_STATUS
:
4287 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4288 " type=%d stype=%d",
4289 MAC2STR(data
->tx_status
.dst
),
4290 data
->tx_status
.type
, data
->tx_status
.stype
);
4292 if (wpa_s
->ap_iface
== NULL
) {
4293 #ifdef CONFIG_OFFCHANNEL
4294 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4295 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4296 offchannel_send_action_tx_status(
4297 wpa_s
, data
->tx_status
.dst
,
4298 data
->tx_status
.data
,
4299 data
->tx_status
.data_len
,
4300 data
->tx_status
.ack
?
4301 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4302 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4303 #endif /* CONFIG_OFFCHANNEL */
4306 #endif /* CONFIG_AP */
4307 #ifdef CONFIG_OFFCHANNEL
4308 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4309 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4311 * Catch TX status events for Action frames we sent via group
4312 * interface in GO mode, or via standalone AP interface.
4313 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4314 * except when the primary interface is used as a GO interface
4315 * (for drivers which do not have group interface concurrency)
4317 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4318 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4319 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4320 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4321 offchannel_send_action_tx_status(
4322 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4323 data
->tx_status
.data
,
4324 data
->tx_status
.data_len
,
4325 data
->tx_status
.ack
?
4326 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4327 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4330 #endif /* CONFIG_OFFCHANNEL */
4332 switch (data
->tx_status
.type
) {
4333 case WLAN_FC_TYPE_MGMT
:
4334 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4335 data
->tx_status
.data_len
,
4336 data
->tx_status
.stype
,
4337 data
->tx_status
.ack
);
4339 case WLAN_FC_TYPE_DATA
:
4340 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4341 data
->tx_status
.data
,
4342 data
->tx_status
.data_len
,
4343 data
->tx_status
.ack
);
4346 #endif /* CONFIG_AP */
4349 case EVENT_EAPOL_TX_STATUS
:
4350 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4351 data
->eapol_tx_status
.data
,
4352 data
->eapol_tx_status
.data_len
,
4353 data
->eapol_tx_status
.ack
);
4355 case EVENT_DRIVER_CLIENT_POLL_OK
:
4356 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4358 case EVENT_RX_FROM_UNKNOWN
:
4359 if (wpa_s
->ap_iface
== NULL
)
4361 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4362 data
->rx_from_unknown
.wds
);
4364 #endif /* CONFIG_AP */
4365 case EVENT_CH_SWITCH
:
4366 if (!data
|| !wpa_s
->current_ssid
)
4369 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4370 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4371 data
->ch_switch
.freq
,
4372 data
->ch_switch
.ht_enabled
,
4373 data
->ch_switch
.ch_offset
,
4374 channel_width_to_string(data
->ch_switch
.ch_width
),
4375 data
->ch_switch
.cf1
,
4376 data
->ch_switch
.cf2
);
4378 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4379 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4382 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4383 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4384 wpa_s
->current_ssid
->mode
==
4385 WPAS_MODE_P2P_GROUP_FORMATION
) {
4386 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4387 data
->ch_switch
.ht_enabled
,
4388 data
->ch_switch
.ch_offset
,
4389 data
->ch_switch
.ch_width
,
4390 data
->ch_switch
.cf1
,
4391 data
->ch_switch
.cf2
);
4393 #endif /* CONFIG_AP */
4395 #ifdef CONFIG_IEEE80211W
4396 sme_event_ch_switch(wpa_s
);
4397 #endif /* CONFIG_IEEE80211W */
4398 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4399 wnm_clear_coloc_intf_reporting(wpa_s
);
4403 case EVENT_DFS_RADAR_DETECTED
:
4405 wpas_ap_event_dfs_radar_detected(wpa_s
,
4408 case EVENT_DFS_NOP_FINISHED
:
4410 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4413 #endif /* NEED_AP_MLME */
4414 #endif /* CONFIG_AP */
4415 case EVENT_DFS_CAC_STARTED
:
4417 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4419 case EVENT_DFS_CAC_FINISHED
:
4421 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4423 case EVENT_DFS_CAC_ABORTED
:
4425 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4427 case EVENT_RX_MGMT
: {
4429 const struct ieee80211_mgmt
*mgmt
;
4431 #ifdef CONFIG_TESTING_OPTIONS
4432 if (wpa_s
->ext_mgmt_frame_handling
) {
4433 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4434 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4435 char *hex
= os_malloc(hex_len
);
4437 wpa_snprintf_hex(hex
, hex_len
,
4438 rx
->frame
, rx
->frame_len
);
4439 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4440 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4446 #endif /* CONFIG_TESTING_OPTIONS */
4448 mgmt
= (const struct ieee80211_mgmt
*)
4449 data
->rx_mgmt
.frame
;
4450 fc
= le_to_host16(mgmt
->frame_control
);
4451 stype
= WLAN_FC_GET_STYPE(fc
);
4454 if (wpa_s
->ap_iface
== NULL
) {
4455 #endif /* CONFIG_AP */
4457 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4458 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4459 const u8
*src
= mgmt
->sa
;
4463 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4464 ie_len
= data
->rx_mgmt
.frame_len
-
4466 wpas_p2p_probe_req_rx(
4467 wpa_s
, src
, mgmt
->da
,
4468 mgmt
->bssid
, ie
, ie_len
,
4470 data
->rx_mgmt
.ssi_signal
);
4473 #endif /* CONFIG_P2P */
4474 #ifdef CONFIG_IBSS_RSN
4475 if (wpa_s
->current_ssid
&&
4476 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4477 stype
== WLAN_FC_STYPE_AUTH
&&
4478 data
->rx_mgmt
.frame_len
>= 30) {
4479 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4482 #endif /* CONFIG_IBSS_RSN */
4484 if (stype
== WLAN_FC_STYPE_ACTION
) {
4485 wpas_event_rx_mgmt_action(
4486 wpa_s
, data
->rx_mgmt
.frame
,
4487 data
->rx_mgmt
.frame_len
,
4489 data
->rx_mgmt
.ssi_signal
);
4494 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4499 if (stype
== WLAN_FC_STYPE_AUTH
&&
4500 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4501 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4502 sme_external_auth_mgmt_rx(
4503 wpa_s
, data
->rx_mgmt
.frame
,
4504 data
->rx_mgmt
.frame_len
);
4507 #endif /* CONFIG_SAE */
4508 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4509 "management frame in non-AP mode");
4514 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4515 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4519 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4520 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4522 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4523 mgmt
->bssid
, ie
, ie_len
,
4524 data
->rx_mgmt
.ssi_signal
);
4527 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4528 #endif /* CONFIG_AP */
4531 case EVENT_RX_PROBE_REQ
:
4532 if (data
->rx_probe_req
.sa
== NULL
||
4533 data
->rx_probe_req
.ie
== NULL
)
4536 if (wpa_s
->ap_iface
) {
4537 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4538 data
->rx_probe_req
.sa
,
4539 data
->rx_probe_req
.da
,
4540 data
->rx_probe_req
.bssid
,
4541 data
->rx_probe_req
.ie
,
4542 data
->rx_probe_req
.ie_len
,
4543 data
->rx_probe_req
.ssi_signal
);
4546 #endif /* CONFIG_AP */
4547 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4548 data
->rx_probe_req
.da
,
4549 data
->rx_probe_req
.bssid
,
4550 data
->rx_probe_req
.ie
,
4551 data
->rx_probe_req
.ie_len
,
4553 data
->rx_probe_req
.ssi_signal
);
4555 case EVENT_REMAIN_ON_CHANNEL
:
4556 #ifdef CONFIG_OFFCHANNEL
4557 offchannel_remain_on_channel_cb(
4558 wpa_s
, data
->remain_on_channel
.freq
,
4559 data
->remain_on_channel
.duration
);
4560 #endif /* CONFIG_OFFCHANNEL */
4561 wpas_p2p_remain_on_channel_cb(
4562 wpa_s
, data
->remain_on_channel
.freq
,
4563 data
->remain_on_channel
.duration
);
4565 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4566 #ifdef CONFIG_OFFCHANNEL
4567 offchannel_cancel_remain_on_channel_cb(
4568 wpa_s
, data
->remain_on_channel
.freq
);
4569 #endif /* CONFIG_OFFCHANNEL */
4570 wpas_p2p_cancel_remain_on_channel_cb(
4571 wpa_s
, data
->remain_on_channel
.freq
);
4573 wpas_dpp_cancel_remain_on_channel_cb(
4574 wpa_s
, data
->remain_on_channel
.freq
);
4575 #endif /* CONFIG_DPP */
4577 case EVENT_EAPOL_RX
:
4578 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4579 data
->eapol_rx
.data
,
4580 data
->eapol_rx
.data_len
);
4582 case EVENT_SIGNAL_CHANGE
:
4583 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4584 "above=%d signal=%d noise=%d txrate=%d",
4585 data
->signal_change
.above_threshold
,
4586 data
->signal_change
.current_signal
,
4587 data
->signal_change
.current_noise
,
4588 data
->signal_change
.current_txrate
);
4589 wpa_bss_update_level(wpa_s
->current_bss
,
4590 data
->signal_change
.current_signal
);
4591 bgscan_notify_signal_change(
4592 wpa_s
, data
->signal_change
.above_threshold
,
4593 data
->signal_change
.current_signal
,
4594 data
->signal_change
.current_noise
,
4595 data
->signal_change
.current_txrate
);
4597 case EVENT_INTERFACE_MAC_CHANGED
:
4598 wpa_supplicant_update_mac_addr(wpa_s
);
4600 case EVENT_INTERFACE_ENABLED
:
4601 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4602 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4603 wpa_supplicant_update_mac_addr(wpa_s
);
4604 if (wpa_s
->p2p_mgmt
) {
4605 wpa_supplicant_set_state(wpa_s
,
4611 if (!wpa_s
->ap_iface
) {
4612 wpa_supplicant_set_state(wpa_s
,
4614 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4615 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4617 wpa_supplicant_set_state(wpa_s
,
4619 #else /* CONFIG_AP */
4620 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4621 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4622 #endif /* CONFIG_AP */
4625 case EVENT_INTERFACE_DISABLED
:
4626 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4628 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4629 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4630 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4632 * Mark interface disabled if this happens to end up not
4633 * being removed as a separate P2P group interface.
4635 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4637 * The interface was externally disabled. Remove
4638 * it assuming an external entity will start a
4639 * new session if needed.
4641 if (wpa_s
->current_ssid
&&
4642 wpa_s
->current_ssid
->p2p_group
)
4643 wpas_p2p_interface_unavailable(wpa_s
);
4645 wpas_p2p_disconnect(wpa_s
);
4647 * wpa_s instance may have been freed, so must not use
4652 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4653 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4654 /* This radio work will be cancelled, so clear P2P
4657 p2p_stop_find(wpa_s
->global
->p2p
);
4659 #endif /* CONFIG_P2P */
4661 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4663 * Indicate disconnection to keep ctrl_iface events
4666 wpa_supplicant_event_disassoc(
4667 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4669 wpa_supplicant_mark_disassoc(wpa_s
);
4670 wpa_bss_flush(wpa_s
);
4671 radio_remove_works(wpa_s
, NULL
, 0);
4673 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4675 case EVENT_CHANNEL_LIST_CHANGED
:
4676 wpa_supplicant_update_channel_list(
4677 wpa_s
, &data
->channel_list_changed
);
4679 case EVENT_INTERFACE_UNAVAILABLE
:
4680 wpas_p2p_interface_unavailable(wpa_s
);
4682 case EVENT_BEST_CHANNEL
:
4683 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4685 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4686 data
->best_chan
.freq_overall
);
4687 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4688 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4689 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4690 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4691 data
->best_chan
.freq_5
,
4692 data
->best_chan
.freq_overall
);
4694 case EVENT_UNPROT_DEAUTH
:
4695 wpa_supplicant_event_unprot_deauth(wpa_s
,
4696 &data
->unprot_deauth
);
4698 case EVENT_UNPROT_DISASSOC
:
4699 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4700 &data
->unprot_disassoc
);
4702 case EVENT_STATION_LOW_ACK
:
4704 if (wpa_s
->ap_iface
&& data
)
4705 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4706 data
->low_ack
.addr
);
4707 #endif /* CONFIG_AP */
4710 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4711 data
->low_ack
.addr
);
4712 #endif /* CONFIG_TDLS */
4714 case EVENT_IBSS_PEER_LOST
:
4715 #ifdef CONFIG_IBSS_RSN
4716 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4717 #endif /* CONFIG_IBSS_RSN */
4719 case EVENT_DRIVER_GTK_REKEY
:
4720 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4721 wpa_s
->bssid
, ETH_ALEN
))
4725 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4726 data
->driver_gtk_rekey
.replay_ctr
);
4728 case EVENT_SCHED_SCAN_STOPPED
:
4729 wpa_s
->sched_scanning
= 0;
4730 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4731 wpa_supplicant_notify_scanning(wpa_s
, 0);
4733 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4737 * If the driver stopped scanning without being requested to,
4738 * request a new scan to continue scanning for networks.
4740 if (!wpa_s
->sched_scan_stop_req
&&
4741 wpa_s
->wpa_state
== WPA_SCANNING
) {
4742 wpa_dbg(wpa_s
, MSG_DEBUG
,
4743 "Restart scanning after unexpected sched_scan stop event");
4744 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4748 wpa_s
->sched_scan_stop_req
= 0;
4751 * Start a new sched scan to continue searching for more SSIDs
4752 * either if timed out or PNO schedule scan is pending.
4754 if (wpa_s
->sched_scan_timed_out
) {
4755 wpa_supplicant_req_sched_scan(wpa_s
);
4756 } else if (wpa_s
->pno_sched_pending
) {
4757 wpa_s
->pno_sched_pending
= 0;
4758 wpas_start_pno(wpa_s
);
4759 } else if (resched
) {
4760 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4764 case EVENT_WPS_BUTTON_PUSHED
:
4766 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4767 #endif /* CONFIG_WPS */
4769 case EVENT_AVOID_FREQUENCIES
:
4770 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4772 case EVENT_CONNECT_FAILED_REASON
:
4774 if (!wpa_s
->ap_iface
|| !data
)
4776 hostapd_event_connect_failed_reason(
4777 wpa_s
->ap_iface
->bss
[0],
4778 data
->connect_failed_reason
.addr
,
4779 data
->connect_failed_reason
.code
);
4780 #endif /* CONFIG_AP */
4782 case EVENT_NEW_PEER_CANDIDATE
:
4784 if (!wpa_s
->ifmsh
|| !data
)
4786 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4787 data
->mesh_peer
.ies
,
4788 data
->mesh_peer
.ie_len
);
4789 #endif /* CONFIG_MESH */
4793 if (!wpa_s
->ap_iface
)
4795 hostapd_event_get_survey(wpa_s
->ap_iface
,
4796 &data
->survey_results
);
4797 #endif /* CONFIG_AP */
4799 case EVENT_ACS_CHANNEL_SELECTED
:
4802 if (!wpa_s
->ap_iface
)
4804 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4805 &data
->acs_selected_channels
);
4806 #endif /* CONFIG_ACS */
4807 #endif /* CONFIG_AP */
4809 case EVENT_P2P_LO_STOP
:
4811 wpa_s
->p2p_lo_started
= 0;
4812 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4813 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4814 data
->p2p_lo_stop
.reason_code
);
4815 #endif /* CONFIG_P2P */
4817 case EVENT_BEACON_LOSS
:
4818 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4820 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4821 bgscan_notify_beacon_loss(wpa_s
);
4823 case EVENT_EXTERNAL_AUTH
:
4825 if (!wpa_s
->current_ssid
) {
4826 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4829 sme_external_auth_trigger(wpa_s
, data
);
4830 #endif /* CONFIG_SAE */
4832 case EVENT_PORT_AUTHORIZED
:
4833 wpa_supplicant_event_port_authorized(wpa_s
);
4835 case EVENT_STATION_OPMODE_CHANGED
:
4837 if (!wpa_s
->ap_iface
|| !data
)
4840 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
4841 data
->sta_opmode
.addr
,
4842 data
->sta_opmode
.smps_mode
,
4843 data
->sta_opmode
.chan_width
,
4844 data
->sta_opmode
.rx_nss
);
4845 #endif /* CONFIG_AP */
4848 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4854 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4855 union wpa_event_data
*data
)
4857 struct wpa_supplicant
*wpa_s
;
4859 if (event
!= EVENT_INTERFACE_STATUS
)
4862 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4863 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4864 unsigned int ifindex
;
4866 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4867 if (ifindex
!= data
->interface_status
.ifindex
) {
4868 wpa_dbg(wpa_s
, MSG_DEBUG
,
4869 "interface status ifindex %d mismatch (%d)",
4870 ifindex
, data
->interface_status
.ifindex
);
4874 #ifdef CONFIG_MATCH_IFACE
4875 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4876 struct wpa_interface
*wpa_i
;
4878 wpa_i
= wpa_supplicant_match_iface(
4879 ctx
, data
->interface_status
.ifname
);
4882 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4887 #endif /* CONFIG_MATCH_IFACE */
4890 wpa_supplicant_event(wpa_s
, event
, data
);