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 #ifndef CONFIG_NO_SCAN_PROCESSING
54 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
55 int new_scan
, int own_request
);
56 #endif /* CONFIG_NO_SCAN_PROCESSING */
59 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
61 struct os_reltime now
;
63 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
67 if (ssid
->disabled_until
.sec
> now
.sec
)
68 return ssid
->disabled_until
.sec
- now
.sec
;
70 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
76 #ifndef CONFIG_NO_SCAN_PROCESSING
78 * wpas_reenabled_network_time - Time until first network is re-enabled
79 * @wpa_s: Pointer to wpa_supplicant data
80 * Returns: If all enabled networks are temporarily disabled, returns the time
81 * (in sec) until the first network is re-enabled. Otherwise returns 0.
83 * This function is used in case all enabled networks are temporarily disabled,
84 * in which case it returns the time (in sec) that the first network will be
85 * re-enabled. The function assumes that at least one network is enabled.
87 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
89 struct wpa_ssid
*ssid
;
90 int disabled_for
, res
= 0;
92 #ifdef CONFIG_INTERWORKING
93 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
96 #endif /* CONFIG_INTERWORKING */
98 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
102 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
106 if (!res
|| disabled_for
< res
)
112 #endif /* CONFIG_NO_SCAN_PROCESSING */
115 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
117 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
119 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
122 wpa_dbg(wpa_s
, MSG_DEBUG
,
123 "Try to associate due to network getting re-enabled");
124 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
125 wpa_supplicant_cancel_sched_scan(wpa_s
);
126 wpa_supplicant_req_scan(wpa_s
, 0, 0);
131 static struct wpa_bss
* wpa_supplicant_get_new_bss(
132 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
134 struct wpa_bss
*bss
= NULL
;
135 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
137 if (ssid
->ssid_len
> 0)
138 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
140 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
146 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
148 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
151 wpa_supplicant_update_scan_results(wpa_s
);
153 /* Get the BSS from the new scan results */
154 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
158 wpa_s
->current_bss
= bss
;
162 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
164 struct wpa_ssid
*ssid
, *old_ssid
;
165 u8 drv_ssid
[SSID_MAX_LEN
];
169 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
170 wpa_supplicant_update_current_bss(wpa_s
);
172 if (wpa_s
->current_ssid
->ssid_len
== 0)
173 return 0; /* current profile still in use */
174 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
176 wpa_msg(wpa_s
, MSG_INFO
,
177 "Failed to read SSID from driver");
178 return 0; /* try to use current profile */
182 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
183 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
185 return 0; /* current profile still in use */
187 wpa_msg(wpa_s
, MSG_DEBUG
,
188 "Driver-initiated BSS selection changed the SSID to %s",
189 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
190 /* continue selecting a new network profile */
193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
195 ssid
= wpa_supplicant_get_ssid(wpa_s
);
197 wpa_msg(wpa_s
, MSG_INFO
,
198 "No network configuration found for the current AP");
202 if (wpas_network_disabled(wpa_s
, ssid
)) {
203 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
207 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
208 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
209 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
213 res
= wpas_temp_disabled(wpa_s
, ssid
);
215 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
216 "disabled for %d second(s)", res
);
220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
222 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
224 size_t wpa_ie_len
= sizeof(wpa_ie
);
225 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
226 wpa_ie
, &wpa_ie_len
) < 0)
227 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
229 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
232 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
233 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
234 old_ssid
= wpa_s
->current_ssid
;
235 wpa_s
->current_ssid
= ssid
;
237 wpa_supplicant_update_current_bss(wpa_s
);
239 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
240 wpa_supplicant_initiate_eapol(wpa_s
);
241 if (old_ssid
!= wpa_s
->current_ssid
)
242 wpas_notify_network_changed(wpa_s
);
248 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
250 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
252 if (wpa_s
->countermeasures
) {
253 wpa_s
->countermeasures
= 0;
254 wpa_drv_set_countermeasures(wpa_s
, 0);
255 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
258 * It is possible that the device is sched scanning, which means
259 * that a connection attempt will be done only when we receive
260 * scan results. However, in this case, it would be preferable
261 * to scan and connect immediately, so cancel the sched_scan and
262 * issue a regular scan flow.
264 wpa_supplicant_cancel_sched_scan(wpa_s
);
265 wpa_supplicant_req_scan(wpa_s
, 0, 0);
270 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
274 wnm_bss_keep_alive_deinit(wpa_s
);
276 #ifdef CONFIG_IBSS_RSN
277 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
278 wpa_s
->ibss_rsn
= NULL
;
279 #endif /* CONFIG_IBSS_RSN */
282 wpa_supplicant_ap_deinit(wpa_s
);
283 #endif /* CONFIG_AP */
286 /* Clear possibly configured frame filters */
287 wpa_drv_configure_frame_filters(wpa_s
, 0);
288 #endif /* CONFIG_HS20 */
290 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
293 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
294 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
295 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
296 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
297 sme_clear_on_disassoc(wpa_s
);
298 wpa_s
->current_bss
= NULL
;
299 wpa_s
->assoc_freq
= 0;
302 wpas_notify_bssid_changed(wpa_s
);
304 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
305 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
306 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
307 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
308 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
)
309 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
310 wpa_s
->ap_ies_from_associnfo
= 0;
311 wpa_s
->current_ssid
= NULL
;
312 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
315 wpas_rrm_reset(wpa_s
);
316 wpa_s
->wnmsleep_used
= 0;
318 #ifdef CONFIG_TESTING_OPTIONS
319 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
320 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
321 #endif /* CONFIG_TESTING_OPTIONS */
322 wpa_s
->ieee80211ac
= 0;
326 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
328 struct wpa_ie_data ie
;
332 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
336 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
337 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
338 ie
.pmkid
+ i
* PMKID_LEN
,
339 NULL
, NULL
, 0, NULL
, 0);
340 if (pmksa_set
== 0) {
341 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
346 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
347 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
351 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
352 union wpa_event_data
*data
)
355 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
359 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
360 " index=%d preauth=%d",
361 MAC2STR(data
->pmkid_candidate
.bssid
),
362 data
->pmkid_candidate
.index
,
363 data
->pmkid_candidate
.preauth
);
365 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
366 data
->pmkid_candidate
.index
,
367 data
->pmkid_candidate
.preauth
);
371 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
373 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
374 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
377 #ifdef IEEE8021X_EAPOL
378 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
379 wpa_s
->current_ssid
&&
380 !(wpa_s
->current_ssid
->eapol_flags
&
381 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
382 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
383 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
384 * plaintext or static WEP keys). */
387 #endif /* IEEE8021X_EAPOL */
394 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
395 * @wpa_s: pointer to wpa_supplicant data
396 * @ssid: Configuration data for the network
397 * Returns: 0 on success, -1 on failure
399 * This function is called when starting authentication with a network that is
400 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
402 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
403 struct wpa_ssid
*ssid
)
405 #ifdef IEEE8021X_EAPOL
407 int aka
= 0, sim
= 0;
409 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
410 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
413 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
417 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
418 while (eap
->vendor
!= EAP_VENDOR_IETF
||
419 eap
->method
!= EAP_TYPE_NONE
) {
420 if (eap
->vendor
== EAP_VENDOR_IETF
) {
421 if (eap
->method
== EAP_TYPE_SIM
)
423 else if (eap
->method
== EAP_TYPE_AKA
||
424 eap
->method
== EAP_TYPE_AKA_PRIME
)
431 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
433 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
434 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
439 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
440 "use SIM, but neither EAP-SIM nor EAP-AKA are "
445 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
446 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
448 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
449 if (wpa_s
->scard
== NULL
) {
450 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
454 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
455 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
456 #endif /* PCSC_FUNCS */
457 #endif /* IEEE8021X_EAPOL */
463 #ifndef CONFIG_NO_SCAN_PROCESSING
465 static int has_wep_key(struct wpa_ssid
*ssid
)
469 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
470 if (ssid
->wep_key_len
[i
])
478 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
479 struct wpa_ssid
*ssid
)
483 if (ssid
->mixed_cell
)
487 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
489 #endif /* CONFIG_WPS */
492 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
494 #endif /* CONFIG_OWE */
496 if (has_wep_key(ssid
))
499 #ifdef IEEE8021X_EAPOL
500 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
501 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
502 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
504 #endif /* IEEE8021X_EAPOL */
506 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
509 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
512 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
518 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
519 struct wpa_ssid
*ssid
,
520 struct wpa_bss
*bss
, int debug_print
)
522 struct wpa_ie_data ie
;
524 const u8
*rsn_ie
, *wpa_ie
;
528 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
532 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
533 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
534 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
535 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
536 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
538 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
539 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
542 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
544 wpa_dbg(wpa_s
, MSG_DEBUG
,
545 " skip RSN IE - parse failed");
550 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
553 wpa_dbg(wpa_s
, MSG_DEBUG
,
554 " selected based on TSN in RSN IE");
558 if (!(ie
.proto
& ssid
->proto
)) {
560 wpa_dbg(wpa_s
, MSG_DEBUG
,
561 " skip RSN IE - proto mismatch");
565 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
567 wpa_dbg(wpa_s
, MSG_DEBUG
,
568 " skip RSN IE - PTK cipher mismatch");
572 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
574 wpa_dbg(wpa_s
, MSG_DEBUG
,
575 " skip RSN IE - GTK cipher mismatch");
579 if (ssid
->group_mgmt_cipher
&&
580 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
582 wpa_dbg(wpa_s
, MSG_DEBUG
,
583 " skip RSN IE - group mgmt cipher mismatch");
587 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
589 wpa_dbg(wpa_s
, MSG_DEBUG
,
590 " skip RSN IE - key mgmt mismatch");
594 #ifdef CONFIG_IEEE80211W
595 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
596 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
597 MGMT_FRAME_PROTECTION_REQUIRED
) {
599 wpa_dbg(wpa_s
, MSG_DEBUG
,
600 " skip RSN IE - no mgmt frame protection");
603 #endif /* CONFIG_IEEE80211W */
604 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
605 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
606 NO_MGMT_FRAME_PROTECTION
) {
608 wpa_dbg(wpa_s
, MSG_DEBUG
,
609 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
613 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
614 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
615 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
616 NO_MGMT_FRAME_PROTECTION
) {
618 wpa_dbg(wpa_s
, MSG_DEBUG
,
619 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
622 #endif /* CONFIG_MBO */
625 wpa_dbg(wpa_s
, MSG_DEBUG
,
626 " selected based on RSN IE");
630 #ifdef CONFIG_IEEE80211W
631 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
632 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
634 wpa_dbg(wpa_s
, MSG_DEBUG
,
635 " skip - MFP Required but network not MFP Capable");
638 #endif /* CONFIG_IEEE80211W */
640 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
641 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
644 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
646 wpa_dbg(wpa_s
, MSG_DEBUG
,
647 " skip WPA IE - parse failed");
652 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
655 wpa_dbg(wpa_s
, MSG_DEBUG
,
656 " selected based on TSN in WPA IE");
660 if (!(ie
.proto
& ssid
->proto
)) {
662 wpa_dbg(wpa_s
, MSG_DEBUG
,
663 " skip WPA IE - proto mismatch");
667 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
669 wpa_dbg(wpa_s
, MSG_DEBUG
,
670 " skip WPA IE - PTK cipher mismatch");
674 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
676 wpa_dbg(wpa_s
, MSG_DEBUG
,
677 " skip WPA IE - GTK cipher mismatch");
681 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
683 wpa_dbg(wpa_s
, MSG_DEBUG
,
684 " skip WPA IE - key mgmt mismatch");
689 wpa_dbg(wpa_s
, MSG_DEBUG
,
690 " selected based on WPA IE");
694 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
697 wpa_dbg(wpa_s
, MSG_DEBUG
,
698 " allow for non-WPA IEEE 802.1X");
703 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
704 !wpa_ie
&& !rsn_ie
) {
706 wpa_dbg(wpa_s
, MSG_DEBUG
,
707 " allow in OWE transition mode");
710 #endif /* CONFIG_OWE */
712 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
713 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
715 wpa_dbg(wpa_s
, MSG_DEBUG
,
716 " skip - no WPA/RSN proto match");
720 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
721 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
723 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
727 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
729 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
734 wpa_dbg(wpa_s
, MSG_DEBUG
,
735 " reject due to mismatch with WPA/WPA2");
741 static int freq_allowed(int *freqs
, int freq
)
748 for (i
= 0; freqs
[i
]; i
++)
749 if (freqs
[i
] == freq
)
755 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
758 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
759 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
764 return 1; /* Cannot do matching without knowing band */
766 modes
= wpa_s
->hw
.modes
;
769 * The driver does not provide any additional information
770 * about the utilized hardware, so allow the connection attempt
776 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
777 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
778 int freq
= modes
[i
].channels
[j
].freq
;
779 if (freq
== bss
->freq
) {
781 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
782 break; /* do not allow 802.11b replace
793 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
794 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
798 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
799 int flagged
= !!(rate_ie
[j
] & 0x80);
800 int r
= (rate_ie
[j
] & 0x7f) * 5;
803 * IEEE Std 802.11n-2009 7.3.2.2:
804 * The new BSS Membership selector value is encoded
805 * like a legacy basic rate, but it is not a rate and
806 * only indicates if the BSS members are required to
807 * support the mandatory features of Clause 20 [HT PHY]
808 * in order to join the BSS.
810 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
811 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
812 if (!ht_supported(mode
)) {
814 wpa_dbg(wpa_s
, MSG_DEBUG
,
815 " hardware does not support HT PHY");
821 /* There's also a VHT selector for 802.11ac */
822 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
823 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
824 if (!vht_supported(mode
)) {
826 wpa_dbg(wpa_s
, MSG_DEBUG
,
827 " hardware does not support VHT PHY");
836 /* check for legacy basic rates */
837 for (k
= 0; k
< mode
->num_rates
; k
++) {
838 if (mode
->rates
[k
] == r
)
841 if (k
== mode
->num_rates
) {
843 * IEEE Std 802.11-2007 7.3.2.2 demands that in
844 * order to join a BSS all required rates
845 * have to be supported by the hardware.
848 wpa_dbg(wpa_s
, MSG_DEBUG
,
849 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
851 bss
->freq
, mode
->mode
, mode
->num_rates
);
862 * Test whether BSS is in an ESS.
863 * This is done differently in DMG (60 GHz) and non-DMG bands
865 static int bss_is_ess(struct wpa_bss
*bss
)
867 if (bss_is_dmg(bss
)) {
868 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
869 IEEE80211_CAP_DMG_AP
;
872 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
877 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
881 for (i
= 0; i
< ETH_ALEN
; i
++) {
882 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
889 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
893 for (i
= 0; i
< num
; i
++) {
894 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
895 const u8
*m
= a
+ ETH_ALEN
;
897 if (match_mac_mask(a
, addr
, m
))
904 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
905 const u8
**ret_ssid
, size_t *ret_ssid_len
)
908 const u8
*owe
, *pos
, *end
, *bssid
;
910 struct wpa_bss
*open_bss
;
912 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
913 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
917 end
= owe
+ 2 + owe
[1];
919 if (end
- pos
< ETH_ALEN
+ 1)
924 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
927 /* Match the profile SSID against the OWE transition mode SSID on the
929 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
930 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
932 *ret_ssid_len
= ssid_len
;
934 if (bss
->ssid_len
> 0)
937 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
940 if (ssid_len
!= open_bss
->ssid_len
||
941 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
942 wpa_dbg(wpa_s
, MSG_DEBUG
,
943 "OWE: transition mode SSID mismatch: %s",
944 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
948 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
949 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
950 wpa_dbg(wpa_s
, MSG_DEBUG
,
951 "OWE: transition mode open BSS unexpected info");
956 end
= owe
+ 2 + owe
[1];
958 if (end
- pos
< ETH_ALEN
+ 1)
960 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
961 wpa_dbg(wpa_s
, MSG_DEBUG
,
962 "OWE: transition mode BSSID mismatch: " MACSTR
,
968 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
970 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
971 wpa_ssid_txt(pos
, ssid_len
));
972 os_memcpy(bss
->ssid
, pos
, ssid_len
);
973 bss
->ssid_len
= ssid_len
;
974 #endif /* CONFIG_OWE */
978 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
979 int i
, struct wpa_bss
*bss
,
980 struct wpa_ssid
*group
,
981 int only_first_ssid
, int debug_print
)
983 u8 wpa_ie_len
, rsn_ie_len
;
985 struct wpa_blacklist
*e
;
987 struct wpa_ssid
*ssid
;
990 const u8
*assoc_disallow
;
991 #endif /* CONFIG_MBO */
992 const u8
*match_ssid
;
993 size_t match_ssid_len
;
995 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
996 wpa_ie_len
= ie
? ie
[1] : 0;
998 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
999 rsn_ie_len
= ie
? ie
[1] : 0;
1001 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1005 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1006 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1007 i
, MAC2STR(bss
->bssid
),
1008 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1009 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1011 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1013 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1014 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1016 osen
? " osen=1" : "");
1019 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1022 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1024 * When only a single network is enabled, we can
1025 * trigger blacklisting on the first failure. This
1026 * should not be done with multiple enabled networks to
1027 * avoid getting forced to move into a worse ESS on
1028 * single error if there are no other BSSes of the
1033 if (e
->count
> limit
) {
1035 wpa_dbg(wpa_s
, MSG_DEBUG
,
1036 " skip - blacklisted (count=%d limit=%d)",
1043 match_ssid
= bss
->ssid
;
1044 match_ssid_len
= bss
->ssid_len
;
1045 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1047 if (match_ssid_len
== 0) {
1049 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1053 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1055 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1059 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1061 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1065 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1067 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1068 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1071 if (wpas_network_disabled(wpa_s
, ssid
)) {
1073 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1077 res
= wpas_temp_disabled(wpa_s
, ssid
);
1080 wpa_dbg(wpa_s
, MSG_DEBUG
,
1081 " skip - disabled temporarily for %d second(s)",
1087 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1089 wpa_dbg(wpa_s
, MSG_DEBUG
,
1090 " skip - blacklisted (WPS)");
1094 if (wpa
&& ssid
->ssid_len
== 0 &&
1095 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1098 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1099 /* Only allow wildcard SSID match if an AP
1100 * advertises active WPS operation that matches
1103 if (ssid
->ssid_len
== 0 &&
1104 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1107 #endif /* CONFIG_WPS */
1109 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1110 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1114 (match_ssid_len
!= ssid
->ssid_len
||
1115 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1117 wpa_dbg(wpa_s
, MSG_DEBUG
,
1118 " skip - SSID mismatch");
1122 if (ssid
->bssid_set
&&
1123 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1125 wpa_dbg(wpa_s
, MSG_DEBUG
,
1126 " skip - BSSID mismatch");
1130 /* check blacklist */
1131 if (ssid
->num_bssid_blacklist
&&
1132 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1133 ssid
->num_bssid_blacklist
)) {
1135 wpa_dbg(wpa_s
, MSG_DEBUG
,
1136 " skip - BSSID blacklisted");
1140 /* if there is a whitelist, only accept those APs */
1141 if (ssid
->num_bssid_whitelist
&&
1142 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1143 ssid
->num_bssid_whitelist
)) {
1145 wpa_dbg(wpa_s
, MSG_DEBUG
,
1146 " skip - BSSID not in whitelist");
1150 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1154 if (!osen
&& !wpa
&&
1155 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1156 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1157 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1158 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1160 wpa_dbg(wpa_s
, MSG_DEBUG
,
1161 " skip - non-WPA network not allowed");
1165 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1166 has_wep_key(ssid
)) {
1168 wpa_dbg(wpa_s
, MSG_DEBUG
,
1169 " skip - ignore WPA/WPA2 AP for WEP network block");
1173 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1175 wpa_dbg(wpa_s
, MSG_DEBUG
,
1176 " skip - non-OSEN network not allowed");
1180 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1182 wpa_dbg(wpa_s
, MSG_DEBUG
,
1183 " skip - privacy mismatch");
1187 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1188 !bss_is_pbss(bss
)) {
1190 wpa_dbg(wpa_s
, MSG_DEBUG
,
1191 " skip - not ESS, PBSS, or MBSS");
1195 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1197 wpa_dbg(wpa_s
, MSG_DEBUG
,
1198 " skip - PBSS mismatch (ssid %d bss %d)",
1199 ssid
->pbss
, bss_is_pbss(bss
));
1203 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1205 wpa_dbg(wpa_s
, MSG_DEBUG
,
1206 " skip - frequency not allowed");
1211 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1212 ssid
->frequency
!= bss
->freq
) {
1214 wpa_dbg(wpa_s
, MSG_DEBUG
,
1215 " skip - frequency not allowed (mesh)");
1218 #endif /* CONFIG_MESH */
1220 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1222 wpa_dbg(wpa_s
, MSG_DEBUG
,
1223 " skip - rate sets do not match");
1227 #ifndef CONFIG_IBSS_RSN
1228 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1229 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1230 WPA_KEY_MGMT_WPA_NONE
))) {
1232 wpa_dbg(wpa_s
, MSG_DEBUG
,
1233 " skip - IBSS RSN not supported in the build");
1236 #endif /* !CONFIG_IBSS_RSN */
1239 if (ssid
->p2p_group
&&
1240 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1241 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1243 wpa_dbg(wpa_s
, MSG_DEBUG
,
1244 " skip - no P2P IE seen");
1248 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1249 struct wpabuf
*p2p_ie
;
1250 u8 dev_addr
[ETH_ALEN
];
1252 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1255 wpa_dbg(wpa_s
, MSG_DEBUG
,
1256 " skip - no P2P element");
1259 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1260 bss
, P2P_IE_VENDOR_TYPE
);
1261 if (p2p_ie
== NULL
) {
1263 wpa_dbg(wpa_s
, MSG_DEBUG
,
1264 " skip - could not fetch P2P element");
1268 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1269 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1272 wpa_dbg(wpa_s
, MSG_DEBUG
,
1273 " skip - no matching GO P2P Device Address in P2P element");
1274 wpabuf_free(p2p_ie
);
1277 wpabuf_free(p2p_ie
);
1281 * TODO: skip the AP if its P2P IE has Group Formation
1282 * bit set in the P2P Group Capability Bitmap and we
1283 * are not in Group Formation with that device.
1285 #endif /* CONFIG_P2P */
1287 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1289 struct os_reltime diff
;
1291 os_reltime_sub(&wpa_s
->scan_min_time
,
1292 &bss
->last_update
, &diff
);
1294 wpa_dbg(wpa_s
, MSG_DEBUG
,
1295 " skip - scan result not recent enough (%u.%06u seconds too old)",
1296 (unsigned int) diff
.sec
,
1297 (unsigned int) diff
.usec
);
1301 #ifdef CONFIG_TESTING_OPTIONS
1302 if (wpa_s
->ignore_assoc_disallow
)
1303 goto skip_assoc_disallow
;
1304 #endif /* CONFIG_TESTING_OPTIONS */
1305 assoc_disallow
= wpas_mbo_get_bss_attr(
1306 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1307 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1309 wpa_dbg(wpa_s
, MSG_DEBUG
,
1310 " skip - MBO association disallowed (reason %u)",
1315 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1317 wpa_dbg(wpa_s
, MSG_DEBUG
,
1318 " skip - MBO retry delay has not passed yet");
1321 #ifdef CONFIG_TESTING_OPTIONS
1322 skip_assoc_disallow
:
1323 #endif /* CONFIG_TESTING_OPTIONS */
1324 #endif /* CONFIG_MBO */
1327 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1328 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1329 (!ssid
->dpp_connector
||
1330 !ssid
->dpp_netaccesskey
||
1331 !ssid
->dpp_csign
)) {
1333 wpa_dbg(wpa_s
, MSG_DEBUG
,
1334 " skip - no PMKSA entry for DPP");
1337 #endif /* CONFIG_DPP */
1339 /* Matching configuration found */
1343 /* No matching configuration found */
1348 static struct wpa_bss
*
1349 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1350 struct wpa_ssid
*group
,
1351 struct wpa_ssid
**selected_ssid
,
1352 int only_first_ssid
)
1356 if (wpa_s
->current_ssid
) {
1357 struct wpa_ssid
*ssid
;
1359 wpa_dbg(wpa_s
, MSG_DEBUG
,
1360 "Scan results matching the currently selected network");
1361 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1362 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1364 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1365 only_first_ssid
, 0);
1366 if (ssid
!= wpa_s
->current_ssid
)
1368 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1369 " freq=%d level=%d snr=%d est_throughput=%u",
1370 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1371 bss
->snr
, bss
->est_throughput
);
1375 if (only_first_ssid
)
1376 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1379 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1382 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1383 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1384 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1385 only_first_ssid
, 1);
1386 if (!*selected_ssid
)
1388 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1390 MAC2STR(bss
->bssid
),
1391 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1399 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1400 struct wpa_ssid
**selected_ssid
)
1402 struct wpa_bss
*selected
= NULL
;
1404 struct wpa_ssid
*next_ssid
= NULL
;
1405 struct wpa_ssid
*ssid
;
1407 if (wpa_s
->last_scan_res
== NULL
||
1408 wpa_s
->last_scan_res_used
== 0)
1409 return NULL
; /* no scan results from last update */
1411 if (wpa_s
->next_ssid
) {
1412 /* check that next_ssid is still valid */
1413 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1414 if (ssid
== wpa_s
->next_ssid
)
1418 wpa_s
->next_ssid
= NULL
;
1421 while (selected
== NULL
) {
1422 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1423 if (next_ssid
&& next_ssid
->priority
==
1424 wpa_s
->conf
->pssid
[prio
]->priority
) {
1425 selected
= wpa_supplicant_select_bss(
1426 wpa_s
, next_ssid
, selected_ssid
, 1);
1430 selected
= wpa_supplicant_select_bss(
1431 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1437 if (selected
== NULL
&& wpa_s
->blacklist
&&
1438 !wpa_s
->countermeasures
) {
1439 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1440 "blacklist and try again");
1441 wpa_blacklist_clear(wpa_s
);
1442 wpa_s
->blacklist_cleared
++;
1443 } else if (selected
== NULL
)
1447 ssid
= *selected_ssid
;
1448 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1449 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1450 const char *field_name
, *txt
= NULL
;
1452 wpa_dbg(wpa_s
, MSG_DEBUG
,
1453 "PSK/passphrase not yet available for the selected network");
1455 wpas_notify_network_request(wpa_s
, ssid
,
1456 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1458 field_name
= wpa_supplicant_ctrl_req_to_string(
1459 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1460 if (field_name
== NULL
)
1463 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1472 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1473 int timeout_sec
, int timeout_usec
)
1475 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1477 * No networks are enabled; short-circuit request so
1478 * we don't wait timeout seconds before transitioning
1479 * to INACTIVE state.
1481 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1482 "since there are no enabled networks");
1483 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1487 wpa_s
->scan_for_connection
= 1;
1488 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1492 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1493 struct wpa_bss
*selected
,
1494 struct wpa_ssid
*ssid
)
1496 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1497 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1498 "PBC session overlap");
1499 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1501 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1502 wpa_s
->p2p_in_provisioning
) {
1503 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1507 #endif /* CONFIG_P2P */
1510 wpas_wps_pbc_overlap(wpa_s
);
1511 wpas_wps_cancel(wpa_s
);
1512 #endif /* CONFIG_WPS */
1516 wpa_msg(wpa_s
, MSG_DEBUG
,
1517 "Considering connect request: reassociate: %d selected: "
1518 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1519 " wpa_state: %s ssid=%p current_ssid=%p",
1520 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1521 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1522 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1523 ssid
, wpa_s
->current_ssid
);
1526 * Do not trigger new association unless the BSSID has changed or if
1527 * reassociation is requested. If we are in process of associating with
1528 * the selected BSSID, do not trigger new attempt.
1530 if (wpa_s
->reassociate
||
1531 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1532 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1533 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1534 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1535 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1537 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1538 ssid
!= wpa_s
->current_ssid
)))) {
1539 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1540 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1543 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1544 MAC2STR(selected
->bssid
));
1545 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1547 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1548 "connect with the selected AP");
1555 static struct wpa_ssid
*
1556 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1559 struct wpa_ssid
*ssid
;
1561 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1562 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1564 if (wpas_network_disabled(wpa_s
, ssid
))
1566 #ifndef CONFIG_IBSS_RSN
1567 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1568 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1569 WPA_KEY_MGMT_WPA_NONE
))) {
1570 wpa_msg(wpa_s
, MSG_INFO
,
1571 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1572 wpa_ssid_txt(ssid
->ssid
,
1576 #endif /* !CONFIG_IBSS_RSN */
1577 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1578 ssid
->mode
== IEEE80211_MODE_AP
||
1579 ssid
->mode
== IEEE80211_MODE_MESH
)
1587 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1588 * on BSS added and BSS changed events */
1589 static void wpa_supplicant_rsn_preauth_scan_results(
1590 struct wpa_supplicant
*wpa_s
)
1592 struct wpa_bss
*bss
;
1594 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1597 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1598 const u8
*ssid
, *rsn
;
1600 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1604 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1608 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1614 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1615 struct wpa_bss
*selected
,
1616 struct wpa_ssid
*ssid
)
1618 struct wpa_bss
*current_bss
= NULL
;
1619 #ifndef CONFIG_NO_ROAMING
1622 int cur_est
, sel_est
;
1623 #endif /* CONFIG_NO_ROAMING */
1625 if (wpa_s
->reassociate
)
1626 return 1; /* explicit request to reassociate */
1627 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1628 return 1; /* we are not associated; continue */
1629 if (wpa_s
->current_ssid
== NULL
)
1630 return 1; /* unknown current SSID */
1631 if (wpa_s
->current_ssid
!= ssid
)
1632 return 1; /* different network block */
1634 if (wpas_driver_bss_selection(wpa_s
))
1635 return 0; /* Driver-based roaming */
1637 if (wpa_s
->current_ssid
->ssid
)
1638 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1639 wpa_s
->current_ssid
->ssid
,
1640 wpa_s
->current_ssid
->ssid_len
);
1642 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1645 return 1; /* current BSS not seen in scan results */
1647 if (current_bss
== selected
)
1650 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1651 return 1; /* current BSS not seen in the last scan */
1653 #ifndef CONFIG_NO_ROAMING
1654 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1655 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1656 " freq=%d level=%d snr=%d est_throughput=%u",
1657 MAC2STR(current_bss
->bssid
),
1658 current_bss
->freq
, current_bss
->level
,
1659 current_bss
->snr
, current_bss
->est_throughput
);
1660 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1661 " freq=%d level=%d snr=%d est_throughput=%u",
1662 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1663 selected
->snr
, selected
->est_throughput
);
1665 if (wpa_s
->current_ssid
->bssid_set
&&
1666 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1668 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1669 "has preferred BSSID");
1673 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1674 wpa_dbg(wpa_s
, MSG_DEBUG
,
1675 "Allow reassociation - selected BSS has better estimated throughput");
1679 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1681 if (current_bss
->level
< 0 &&
1682 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1683 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1688 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1689 wpa_dbg(wpa_s
, MSG_DEBUG
,
1690 "Skip roam - Current BSS has better estimated throughput");
1694 cur_est
= current_bss
->est_throughput
;
1695 sel_est
= selected
->est_throughput
;
1697 if (current_bss
->level
< 0) {
1698 if (current_bss
->level
< -85)
1700 else if (current_bss
->level
< -80)
1702 else if (current_bss
->level
< -75)
1704 else if (current_bss
->level
< -70)
1708 if (cur_est
> sel_est
* 1.5)
1710 else if (cur_est
> sel_est
* 1.2)
1712 else if (cur_est
> sel_est
* 1.1)
1714 else if (cur_est
> sel_est
)
1720 /* Make it easier to move to 5 GHz band */
1721 if (sel_est
> cur_est
* 1.5)
1723 else if (sel_est
> cur_est
* 1.2)
1725 else if (sel_est
> cur_est
* 1.1)
1728 if (min_diff
> reduce
)
1733 diff
= abs(current_bss
->level
- selected
->level
);
1734 if (diff
< min_diff
) {
1735 wpa_dbg(wpa_s
, MSG_DEBUG
,
1736 "Skip roam - too small difference in signal level (%d < %d)",
1741 wpa_dbg(wpa_s
, MSG_DEBUG
,
1742 "Allow reassociation due to difference in signal level (%d >= %d)",
1745 #else /* CONFIG_NO_ROAMING */
1747 #endif /* CONFIG_NO_ROAMING */
1752 * Return a negative value if no scan results could be fetched or if scan
1753 * results should not be shared with other virtual interfaces.
1754 * Return 0 if scan results were fetched and may be shared with other
1756 * Return 1 if scan results may be shared with other virtual interfaces but may
1757 * not trigger any operations.
1758 * Return 2 if the interface was removed and cannot be used.
1760 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1761 union wpa_event_data
*data
,
1762 int own_request
, int update_only
)
1764 struct wpa_scan_results
*scan_res
= NULL
;
1767 #ifndef CONFIG_NO_RANDOM_POOL
1769 #endif /* CONFIG_NO_RANDOM_POOL */
1772 if (wpa_s
->ap_iface
)
1774 #endif /* CONFIG_AP */
1776 wpa_supplicant_notify_scanning(wpa_s
, 0);
1778 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1779 data
? &data
->scan_info
:
1781 if (scan_res
== NULL
) {
1782 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1783 wpa_s
->scan_res_handler
== scan_only_handler
)
1787 if (data
&& data
->scan_info
.external_scan
)
1789 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1791 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1793 goto scan_work_done
;
1796 #ifndef CONFIG_NO_RANDOM_POOL
1797 num
= scan_res
->num
;
1800 for (i
= 0; i
< num
; i
++) {
1802 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1803 buf
[0] = res
->bssid
[5];
1804 buf
[1] = res
->qual
& 0xff;
1805 buf
[2] = res
->noise
& 0xff;
1806 buf
[3] = res
->level
& 0xff;
1807 buf
[4] = res
->tsf
& 0xff;
1808 random_add_randomness(buf
, sizeof(buf
));
1810 #endif /* CONFIG_NO_RANDOM_POOL */
1814 goto scan_work_done
;
1817 if (own_request
&& wpa_s
->scan_res_handler
&&
1818 !(data
&& data
->scan_info
.external_scan
)) {
1819 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1820 struct wpa_scan_results
*scan_res
);
1822 scan_res_handler
= wpa_s
->scan_res_handler
;
1823 wpa_s
->scan_res_handler
= NULL
;
1824 scan_res_handler(wpa_s
, scan_res
);
1826 goto scan_work_done
;
1830 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1832 if (wpa_s
->ap_iface
->scan_cb
)
1833 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1834 #endif /* CONFIG_AP */
1835 goto scan_work_done
;
1838 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1839 wpa_s
->own_scan_running
,
1840 data
? data
->scan_info
.external_scan
: 0);
1841 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1842 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1843 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1844 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1845 wpa_s
->manual_scan_id
);
1846 wpa_s
->manual_scan_use_id
= 0;
1848 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1850 wpas_notify_scan_results(wpa_s
);
1852 wpas_notify_scan_done(wpa_s
, 1);
1854 if (data
&& data
->scan_info
.external_scan
) {
1855 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1856 wpa_scan_results_free(scan_res
);
1860 if (wnm_scan_process(wpa_s
, 1) > 0)
1861 goto scan_work_done
;
1863 if (sme_proc_obss_scan(wpa_s
) > 0)
1864 goto scan_work_done
;
1867 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1868 goto scan_work_done
;
1870 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1871 goto scan_work_done
;
1873 if (autoscan_notify_scan(wpa_s
, scan_res
))
1874 goto scan_work_done
;
1876 if (wpa_s
->disconnected
) {
1877 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1878 goto scan_work_done
;
1881 if (!wpas_driver_bss_selection(wpa_s
) &&
1882 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1883 goto scan_work_done
;
1885 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1887 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1888 wpa_s
->wpa_state
< WPA_COMPLETED
)
1889 goto scan_work_done
;
1891 wpa_scan_results_free(scan_res
);
1893 if (own_request
&& wpa_s
->scan_work
) {
1894 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1895 wpa_s
->scan_work
= NULL
;
1896 radio_work_done(work
);
1899 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1902 wpa_scan_results_free(scan_res
);
1903 if (own_request
&& wpa_s
->scan_work
) {
1904 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1905 wpa_s
->scan_work
= NULL
;
1906 radio_work_done(work
);
1912 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1913 int new_scan
, int own_request
)
1915 struct wpa_bss
*selected
;
1916 struct wpa_ssid
*ssid
= NULL
;
1917 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1919 if (time_to_reenable
> 0) {
1920 wpa_dbg(wpa_s
, MSG_DEBUG
,
1921 "Postpone network selection by %d seconds since all networks are disabled",
1923 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1924 eloop_register_timeout(time_to_reenable
, 0,
1925 wpas_network_reenabled
, wpa_s
, NULL
);
1929 if (wpa_s
->p2p_mgmt
)
1930 return 0; /* no normal connection on p2p_mgmt interface */
1932 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1936 wpa_msg(wpa_s
, MSG_INFO
,
1937 "Avoiding join because we already joined a mesh group");
1940 #endif /* CONFIG_MESH */
1944 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1947 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1951 if (ssid
!= wpa_s
->current_ssid
&&
1952 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1953 wpa_s
->own_disconnect_req
= 1;
1954 wpa_supplicant_deauthenticate(
1955 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1958 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1959 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1963 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1965 * Do not allow other virtual radios to trigger operations based
1966 * on these scan results since we do not want them to start
1967 * other associations at the same time.
1971 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1972 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1974 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1975 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1977 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1978 } else if (own_request
) {
1980 * No SSID found. If SCAN results are as a result of
1981 * own scan request and not due to a scan request on
1982 * another shared interface, try another scan.
1984 int timeout_sec
= wpa_s
->scan_interval
;
1985 int timeout_usec
= 0;
1989 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1995 if (wpa_s
->p2p_in_provisioning
||
1996 wpa_s
->show_group_started
||
1997 wpa_s
->p2p_in_invitation
) {
1999 * Use shorter wait during P2P Provisioning
2000 * state and during P2P join-a-group operation
2001 * to speed up group formation.
2004 timeout_usec
= 250000;
2005 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2009 #endif /* CONFIG_P2P */
2010 #ifdef CONFIG_INTERWORKING
2011 if (wpa_s
->conf
->auto_interworking
&&
2012 wpa_s
->conf
->interworking
&&
2013 wpa_s
->conf
->cred
) {
2014 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2015 "start ANQP fetch since no matching "
2017 wpa_s
->network_select
= 1;
2018 wpa_s
->auto_network_select
= 1;
2019 interworking_start_fetch_anqp(wpa_s
);
2022 #endif /* CONFIG_INTERWORKING */
2024 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2025 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2027 timeout_usec
= 500000;
2028 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2032 #endif /* CONFIG_WPS */
2033 if (wpa_supplicant_req_sched_scan(wpa_s
))
2034 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2037 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2038 WPA_EVENT_NETWORK_NOT_FOUND
);
2045 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2046 union wpa_event_data
*data
)
2048 struct wpa_supplicant
*ifs
;
2051 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2054 * Interface may have been removed, so must not dereference
2062 * If no scan results could be fetched, then no need to
2063 * notify those interfaces that did not actually request
2064 * this scan. Similarly, if scan results started a new operation on this
2065 * interface, do not notify other interfaces to avoid concurrent
2066 * operations during a connection attempt.
2072 * Check other interfaces to see if they share the same radio. If
2073 * so, they get updated with this same scan info.
2075 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2078 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2079 "sibling", ifs
->ifname
);
2080 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2090 #endif /* CONFIG_NO_SCAN_PROCESSING */
2093 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2095 #ifdef CONFIG_NO_SCAN_PROCESSING
2097 #else /* CONFIG_NO_SCAN_PROCESSING */
2098 struct os_reltime now
;
2100 wpa_s
->ignore_post_flush_scan_res
= 0;
2102 if (wpa_s
->last_scan_res_used
== 0)
2105 os_get_reltime(&now
);
2106 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2107 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2111 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2112 #endif /* CONFIG_NO_SCAN_PROCESSING */
2117 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2119 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2121 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2124 if (!wpa_s
->no_keep_alive
) {
2125 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2126 MAC2STR(wpa_s
->bssid
));
2127 /* TODO: could skip this if normal data traffic has been sent */
2128 /* TODO: Consider using some more appropriate data frame for
2131 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2136 if (wpa_s
->sme
.bss_max_idle_period
) {
2138 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2141 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2142 wnm_bss_keep_alive
, wpa_s
, NULL
);
2144 #endif /* CONFIG_SME */
2148 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2149 const u8
*ies
, size_t ies_len
)
2151 struct ieee802_11_elems elems
;
2156 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2160 if (elems
.bss_max_idle_period
) {
2162 wpa_s
->sme
.bss_max_idle_period
=
2163 WPA_GET_LE16(elems
.bss_max_idle_period
);
2164 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2165 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2166 (elems
.bss_max_idle_period
[2] & 0x01) ?
2167 " (protected keep-live required)" : "");
2168 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2169 wpa_s
->sme
.bss_max_idle_period
= 1;
2170 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2171 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2172 /* msec times 1000 */
2173 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2176 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2177 wnm_bss_keep_alive
, wpa_s
,
2181 #endif /* CONFIG_SME */
2184 #endif /* CONFIG_WNM */
2187 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2190 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2191 #endif /* CONFIG_WNM */
2195 #ifdef CONFIG_INTERWORKING
2197 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2202 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2203 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2205 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2212 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2213 const u8
*ies
, size_t ies_len
)
2215 struct ieee802_11_elems elems
;
2220 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2223 if (elems
.qos_map_set
) {
2224 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2225 elems
.qos_map_set_len
);
2229 #endif /* CONFIG_INTERWORKING */
2233 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2234 const u8
*ie
, size_t ie_len
)
2236 struct mb_ies_info mb_ies
;
2238 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2241 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2243 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2248 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2253 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2254 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2255 (unsigned int) len
);
2256 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2257 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2265 if (mb_ies
.nof_ies
> 0) {
2266 wpabuf_free(wpa_s
->received_mb_ies
);
2267 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2273 #endif /* CONFIG_FST */
2276 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2277 union wpa_event_data
*data
)
2279 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2281 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2283 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2285 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2286 if (data
->assoc_info
.req_ies
)
2287 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2288 data
->assoc_info
.req_ies_len
);
2289 if (data
->assoc_info
.resp_ies
) {
2290 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2291 data
->assoc_info
.resp_ies_len
);
2293 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2294 data
->assoc_info
.resp_ies_len
);
2295 #endif /* CONFIG_TDLS */
2297 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2298 data
->assoc_info
.resp_ies_len
);
2299 #endif /* CONFIG_WNM */
2300 #ifdef CONFIG_INTERWORKING
2301 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2302 data
->assoc_info
.resp_ies_len
);
2303 #endif /* CONFIG_INTERWORKING */
2304 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2305 get_ie(data
->assoc_info
.resp_ies
,
2306 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2307 wpa_s
->ieee80211ac
= 1;
2309 if (data
->assoc_info
.beacon_ies
)
2310 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2311 data
->assoc_info
.beacon_ies
,
2312 data
->assoc_info
.beacon_ies_len
);
2313 if (data
->assoc_info
.freq
)
2314 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2315 data
->assoc_info
.freq
);
2317 p
= data
->assoc_info
.req_ies
;
2318 l
= data
->assoc_info
.req_ies_len
;
2320 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2321 while (p
&& l
>= 2) {
2324 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2328 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2329 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2330 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2331 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2332 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2333 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2336 wpa_find_assoc_pmkid(wpa_s
);
2342 if (!found
&& data
->assoc_info
.req_ies
)
2343 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2347 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2348 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2349 (!data
->assoc_info
.resp_frame
||
2350 fils_process_assoc_resp(wpa_s
->wpa
,
2351 data
->assoc_info
.resp_frame
,
2352 data
->assoc_info
.resp_frame_len
) < 0)) {
2353 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2356 #endif /* CONFIG_SME */
2358 /* Additional processing for FILS when SME is in driver */
2359 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2360 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2361 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2362 #endif /* CONFIG_FILS */
2365 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2366 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2367 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2368 data
->assoc_info
.resp_ies
,
2369 data
->assoc_info
.resp_ies_len
) < 0)) {
2370 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2373 #endif /* CONFIG_OWE */
2375 #ifdef CONFIG_IEEE80211R
2377 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2378 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2379 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2380 data
->assoc_info
.resp_ies
,
2381 data
->assoc_info
.resp_ies_len
,
2383 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2384 "Reassociation Response failed");
2385 wpa_supplicant_deauthenticate(
2386 wpa_s
, WLAN_REASON_INVALID_IE
);
2391 p
= data
->assoc_info
.resp_ies
;
2392 l
= data
->assoc_info
.resp_ies_len
;
2394 #ifdef CONFIG_WPS_STRICT
2395 if (p
&& wpa_s
->current_ssid
&&
2396 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2398 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2400 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2401 "include WPS IE in (Re)Association Response");
2405 if (wps_validate_assoc_resp(wps
) < 0) {
2407 wpa_supplicant_deauthenticate(
2408 wpa_s
, WLAN_REASON_INVALID_IE
);
2413 #endif /* CONFIG_WPS_STRICT */
2415 /* Go through the IEs and make a copy of the MDIE, if present. */
2416 while (p
&& l
>= 2) {
2419 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2423 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2424 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2425 wpa_s
->sme
.ft_used
= 1;
2426 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2427 MOBILITY_DOMAIN_ID_LEN
);
2433 #endif /* CONFIG_SME */
2435 /* Process FT when SME is in the driver */
2436 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2437 wpa_ft_is_completed(wpa_s
->wpa
)) {
2438 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2439 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2440 data
->assoc_info
.resp_ies
,
2441 data
->assoc_info
.resp_ies_len
,
2443 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2444 "Reassociation Response failed");
2445 wpa_supplicant_deauthenticate(
2446 wpa_s
, WLAN_REASON_INVALID_IE
);
2449 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2452 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2453 data
->assoc_info
.resp_ies_len
);
2454 #endif /* CONFIG_IEEE80211R */
2456 /* WPA/RSN IE from Beacon/ProbeResp */
2457 p
= data
->assoc_info
.beacon_ies
;
2458 l
= data
->assoc_info
.beacon_ies_len
;
2460 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2462 wpa_found
= rsn_found
= 0;
2463 while (p
&& l
>= 2) {
2466 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2471 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2472 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2474 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2478 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2480 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2487 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2488 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2489 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2490 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2491 if (wpa_found
|| rsn_found
)
2492 wpa_s
->ap_ies_from_associnfo
= 1;
2494 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2495 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2496 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2498 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2499 wpa_supplicant_update_scan_results(wpa_s
);
2502 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2508 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2510 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2512 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2515 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2518 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2519 WPA_IE_VENDOR_TYPE
);
2520 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2522 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2523 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2524 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2525 bss_rsn
? 2 + bss_rsn
[1] : 0))
2532 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2533 union wpa_event_data
*data
)
2536 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2537 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2538 const u8
*ieprb
, *iebcn
;
2540 wpabuf_free(wpa_s
->received_mb_ies
);
2541 wpa_s
->received_mb_ies
= NULL
;
2544 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2545 wpa_printf(MSG_DEBUG
,
2546 "FST: MB IEs updated from Association Response frame");
2551 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2552 wpa_printf(MSG_DEBUG
,
2553 "FST: MB IEs updated from association event Beacon IEs");
2560 ieprb
= (const u8
*) (bss
+ 1);
2561 iebcn
= ieprb
+ bss
->ie_len
;
2563 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2564 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2565 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2566 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2567 #endif /* CONFIG_FST */
2571 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2572 union wpa_event_data
*data
)
2575 int ft_completed
, already_authorized
;
2579 if (wpa_s
->ap_iface
) {
2582 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2583 data
->assoc_info
.addr
,
2584 data
->assoc_info
.req_ies
,
2585 data
->assoc_info
.req_ies_len
,
2586 data
->assoc_info
.reassoc
);
2589 #endif /* CONFIG_AP */
2591 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2593 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2594 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2597 * FILS authentication can share the same mechanism to mark the
2598 * connection fully authenticated, so set ft_completed also based on
2602 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2604 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2605 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2606 wpa_supplicant_deauthenticate(
2607 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2611 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2612 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2613 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2614 MACSTR
, MAC2STR(bssid
));
2616 random_add_randomness(bssid
, ETH_ALEN
);
2617 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2618 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2619 wpas_notify_bssid_changed(wpa_s
);
2621 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2622 wpa_clear_keys(wpa_s
, bssid
);
2624 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2625 wpa_supplicant_deauthenticate(
2626 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2631 if (wpa_s
->conf
->ap_scan
== 1 &&
2632 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2633 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2634 wpa_msg(wpa_s
, MSG_WARNING
,
2635 "WPA/RSN IEs not updated");
2638 wpas_fst_update_mb_assoc(wpa_s
, data
);
2641 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2642 wpa_s
->sme
.prev_bssid_set
= 1;
2643 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2644 #endif /* CONFIG_SME */
2646 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2647 if (wpa_s
->current_ssid
) {
2648 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2649 * initialized before association, but for other modes,
2650 * initialize PC/SC here, if the current configuration needs
2651 * smartcard or SIM/USIM. */
2652 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2654 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2656 l2_packet_notify_auth_start(wpa_s
->l2
);
2658 already_authorized
= data
&& data
->assoc_info
.authorized
;
2661 * Set portEnabled first to FALSE in order to get EAP state machine out
2662 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2663 * state machine may transit to AUTHENTICATING state based on obsolete
2664 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2665 * AUTHENTICATED without ever giving chance to EAP state machine to
2668 if (!ft_completed
&& !already_authorized
) {
2669 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2670 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2672 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2673 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2674 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2676 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2677 /* 802.1X::portControl = Auto */
2678 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2679 wpa_s
->eapol_received
= 0;
2680 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2681 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2682 (wpa_s
->current_ssid
&&
2683 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2684 if (wpa_s
->current_ssid
&&
2685 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2687 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2689 * Set the key after having received joined-IBSS event
2692 wpa_supplicant_set_wpa_none_key(wpa_s
,
2693 wpa_s
->current_ssid
);
2695 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2696 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2697 } else if (!ft_completed
) {
2698 /* Timeout for receiving the first EAPOL packet */
2699 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2701 wpa_supplicant_cancel_scan(wpa_s
);
2703 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2704 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2706 * We are done; the driver will take care of RSN 4-way
2709 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2710 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2711 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2712 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2713 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2714 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2716 * The driver will take care of RSN 4-way handshake, so we need
2717 * to allow EAPOL supplicant to complete its work without
2718 * waiting for WPA supplicant.
2720 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2721 } else if (ft_completed
) {
2723 * FT protocol completed - make sure EAPOL state machine ends
2724 * up in authenticated.
2726 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2727 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2728 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2729 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2732 wpa_s
->last_eapol_matches_bssid
= 0;
2734 if (wpa_s
->pending_eapol_rx
) {
2735 struct os_reltime now
, age
;
2736 os_get_reltime(&now
);
2737 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2738 if (age
.sec
== 0 && age
.usec
< 200000 &&
2739 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2741 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2742 "frame that was received just before "
2743 "association notification");
2744 wpa_supplicant_rx_eapol(
2745 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2746 wpabuf_head(wpa_s
->pending_eapol_rx
),
2747 wpabuf_len(wpa_s
->pending_eapol_rx
));
2749 wpabuf_free(wpa_s
->pending_eapol_rx
);
2750 wpa_s
->pending_eapol_rx
= NULL
;
2753 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2754 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2755 wpa_s
->current_ssid
&&
2756 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2757 /* Set static WEP keys again */
2758 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2761 #ifdef CONFIG_IBSS_RSN
2762 if (wpa_s
->current_ssid
&&
2763 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2764 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2765 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2766 wpa_s
->ibss_rsn
== NULL
) {
2767 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2768 if (!wpa_s
->ibss_rsn
) {
2769 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2770 wpa_supplicant_deauthenticate(
2771 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2775 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2777 #endif /* CONFIG_IBSS_RSN */
2779 wpas_wps_notify_assoc(wpa_s
, bssid
);
2782 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2783 data
->assoc_info
.resp_ies_len
,
2784 &data
->assoc_info
.wmm_params
);
2786 if (wpa_s
->reassoc_same_bss
)
2787 wmm_ac_restore_tspecs(wpa_s
);
2791 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2792 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2793 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2796 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2798 #endif /* CONFIG_FILS */
2802 static int disconnect_reason_recoverable(u16 reason_code
)
2804 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2805 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2806 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2810 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2812 int locally_generated
)
2816 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2818 * At least Host AP driver and a Prism3 card seemed to be
2819 * generating streams of disconnected events when configuring
2820 * IBSS for WPA-None. Ignore them for now.
2825 bssid
= wpa_s
->bssid
;
2826 if (is_zero_ether_addr(bssid
))
2827 bssid
= wpa_s
->pending_bssid
;
2829 if (!is_zero_ether_addr(bssid
) ||
2830 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2831 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2833 MAC2STR(bssid
), reason_code
,
2834 locally_generated
? " locally_generated=1" : "");
2839 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2840 int locally_generated
)
2842 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2843 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2844 return 0; /* Not in 4-way handshake with PSK */
2847 * It looks like connection was lost while trying to go through PSK
2848 * 4-way handshake. Filter out known disconnection cases that are caused
2849 * by something else than PSK mismatch to avoid confusing reports.
2852 if (locally_generated
) {
2853 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2861 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2863 int locally_generated
)
2867 u8 prev_pending_bssid
[ETH_ALEN
];
2868 struct wpa_bss
*fast_reconnect
= NULL
;
2869 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2870 struct wpa_ssid
*last_ssid
;
2871 struct wpa_bss
*curr
= NULL
;
2873 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2874 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2876 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2878 * At least Host AP driver and a Prism3 card seemed to be
2879 * generating streams of disconnected events when configuring
2880 * IBSS for WPA-None. Ignore them for now.
2882 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2883 "IBSS/WPA-None mode");
2887 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2888 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2891 * Remove the inactive AP (which is probably out of range) from
2892 * the BSS list after marking disassociation. In particular
2893 * mac80211-based drivers use the
2894 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2895 * locally generated disconnection events for cases where the
2896 * AP does not reply anymore.
2898 curr
= wpa_s
->current_bss
;
2900 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2901 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2902 "pre-shared key may be incorrect");
2903 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2904 return; /* P2P group removed */
2905 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2907 if (!wpa_s
->disconnected
&&
2908 (!wpa_s
->auto_reconnect_disabled
||
2909 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2910 wpas_wps_searching(wpa_s
) ||
2911 wpas_wps_reenable_networks_pending(wpa_s
))) {
2912 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2913 "reconnect (wps=%d/%d wpa_state=%d)",
2914 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2915 wpas_wps_searching(wpa_s
),
2917 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2918 wpa_s
->current_ssid
&&
2919 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2920 !locally_generated
&&
2921 disconnect_reason_recoverable(reason_code
)) {
2923 * It looks like the AP has dropped association with
2924 * us, but could allow us to get back in. Try to
2925 * reconnect to the same BSS without full scan to save
2926 * time for some common cases.
2928 fast_reconnect
= wpa_s
->current_bss
;
2929 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2930 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2931 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2933 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2936 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2937 "try to re-connect");
2938 wpa_s
->reassociate
= 0;
2939 wpa_s
->disconnected
= 1;
2941 wpa_supplicant_cancel_sched_scan(wpa_s
);
2943 bssid
= wpa_s
->bssid
;
2944 if (is_zero_ether_addr(bssid
))
2945 bssid
= wpa_s
->pending_bssid
;
2946 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2947 wpas_connection_failed(wpa_s
, bssid
);
2948 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2949 if (locally_generated
)
2950 wpa_s
->disconnect_reason
= -reason_code
;
2952 wpa_s
->disconnect_reason
= reason_code
;
2953 wpas_notify_disconnect_reason(wpa_s
);
2954 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2955 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2956 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2958 last_ssid
= wpa_s
->current_ssid
;
2959 wpa_supplicant_mark_disassoc(wpa_s
);
2962 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2964 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2965 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2966 wpa_s
->current_ssid
= last_ssid
;
2969 if (fast_reconnect
&&
2970 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2971 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2972 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2973 fast_reconnect
->ssid_len
) &&
2974 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2975 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2976 #ifndef CONFIG_NO_SCAN_PROCESSING
2977 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2978 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2979 fast_reconnect_ssid
) < 0) {
2980 /* Recover through full scan */
2981 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2983 #endif /* CONFIG_NO_SCAN_PROCESSING */
2984 } else if (fast_reconnect
) {
2986 * Could not reconnect to the same BSS due to network being
2987 * disabled. Use a new scan to match the alternative behavior
2988 * above, i.e., to continue automatic reconnection attempt in a
2989 * way that enforces disabled network rules.
2991 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2996 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2997 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2999 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3001 if (!wpa_s
->pending_mic_error_report
)
3004 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3005 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3006 wpa_s
->pending_mic_error_report
= 0;
3008 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3012 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3013 union wpa_event_data
*data
)
3016 struct os_reltime t
;
3018 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3019 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3021 if ((wpa_s
->last_michael_mic_error
.sec
&&
3022 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3023 wpa_s
->pending_mic_error_report
) {
3024 if (wpa_s
->pending_mic_error_report
) {
3026 * Send the pending MIC error report immediately since
3027 * we are going to start countermeasures and AP better
3030 wpa_sm_key_request(wpa_s
->wpa
, 1,
3031 wpa_s
->pending_mic_error_pairwise
);
3034 /* Send the new MIC error report immediately since we are going
3035 * to start countermeasures and AP better do the same.
3037 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3039 /* initialize countermeasures */
3040 wpa_s
->countermeasures
= 1;
3042 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3044 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3047 * Need to wait for completion of request frame. We do not get
3048 * any callback for the message completion, so just wait a
3049 * short while and hope for the best. */
3052 wpa_drv_set_countermeasures(wpa_s
, 1);
3053 wpa_supplicant_deauthenticate(wpa_s
,
3054 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3055 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3057 eloop_register_timeout(60, 0,
3058 wpa_supplicant_stop_countermeasures
,
3060 /* TODO: mark the AP rejected for 60 second. STA is
3061 * allowed to associate with another AP.. */
3063 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3064 if (wpa_s
->mic_errors_seen
) {
3066 * Reduce the effectiveness of Michael MIC error
3067 * reports as a means for attacking against TKIP if
3068 * more than one MIC failure is noticed with the same
3069 * PTK. We delay the transmission of the reports by a
3070 * random time between 0 and 60 seconds in order to
3071 * force the attacker wait 60 seconds before getting
3072 * the information on whether a frame resulted in a MIC
3078 if (os_get_random(rval
, sizeof(rval
)) < 0)
3079 sec
= os_random() % 60;
3081 sec
= WPA_GET_BE32(rval
) % 60;
3082 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3083 "report %d seconds", sec
);
3084 wpa_s
->pending_mic_error_report
= 1;
3085 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3086 eloop_cancel_timeout(
3087 wpa_supplicant_delayed_mic_error_report
,
3089 eloop_register_timeout(
3090 sec
, os_random() % 1000000,
3091 wpa_supplicant_delayed_mic_error_report
,
3094 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3096 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3097 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3098 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3100 wpa_s
->last_michael_mic_error
= t
;
3101 wpa_s
->mic_errors_seen
++;
3105 #ifdef CONFIG_TERMINATE_ONLASTIF
3106 static int any_interfaces(struct wpa_supplicant
*head
)
3108 struct wpa_supplicant
*wpa_s
;
3110 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3111 if (!wpa_s
->interface_removed
)
3115 #endif /* CONFIG_TERMINATE_ONLASTIF */
3119 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3120 union wpa_event_data
*data
)
3122 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3125 switch (data
->interface_status
.ievent
) {
3126 case EVENT_INTERFACE_ADDED
:
3127 if (!wpa_s
->interface_removed
)
3129 wpa_s
->interface_removed
= 0;
3130 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3131 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3132 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3133 "driver after interface was added");
3137 if (!wpa_s
->global
->p2p
&&
3138 !wpa_s
->global
->p2p_disabled
&&
3139 !wpa_s
->conf
->p2p_disabled
&&
3141 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3142 wpas_p2p_add_p2pdev_interface(
3143 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3144 wpa_printf(MSG_INFO
,
3145 "P2P: Failed to enable P2P Device interface");
3146 /* Try to continue without. P2P will be disabled. */
3148 #endif /* CONFIG_P2P */
3151 case EVENT_INTERFACE_REMOVED
:
3152 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3153 wpa_s
->interface_removed
= 1;
3154 wpa_supplicant_mark_disassoc(wpa_s
);
3155 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3156 l2_packet_deinit(wpa_s
->l2
);
3160 if (wpa_s
->global
->p2p
&&
3161 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3163 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3164 wpa_dbg(wpa_s
, MSG_DEBUG
,
3165 "Removing P2P Device interface");
3166 wpa_supplicant_remove_iface(
3167 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3169 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3171 #endif /* CONFIG_P2P */
3173 #ifdef CONFIG_MATCH_IFACE
3174 if (wpa_s
->matched
) {
3175 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3178 #endif /* CONFIG_MATCH_IFACE */
3180 #ifdef CONFIG_TERMINATE_ONLASTIF
3181 /* check if last interface */
3182 if (!any_interfaces(wpa_s
->global
->ifaces
))
3184 #endif /* CONFIG_TERMINATE_ONLASTIF */
3191 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3192 union wpa_event_data
*data
)
3196 switch (data
->tdls
.oper
) {
3197 case TDLS_REQUEST_SETUP
:
3198 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3199 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3200 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3202 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3204 case TDLS_REQUEST_TEARDOWN
:
3205 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3206 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3207 data
->tdls
.reason_code
);
3209 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3212 case TDLS_REQUEST_DISCOVER
:
3213 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3218 #endif /* CONFIG_TDLS */
3222 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3223 union wpa_event_data
*data
)
3227 switch (data
->wnm
.oper
) {
3228 case WNM_OPER_SLEEP
:
3229 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3230 "(action=%d, intval=%d)",
3231 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3232 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3233 data
->wnm
.sleep_intval
, NULL
);
3237 #endif /* CONFIG_WNM */
3240 #ifdef CONFIG_IEEE80211R
3242 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3243 union wpa_event_data
*data
)
3248 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3249 data
->ft_ies
.ies_len
,
3250 data
->ft_ies
.ft_action
,
3251 data
->ft_ies
.target_ap
,
3252 data
->ft_ies
.ric_ies
,
3253 data
->ft_ies
.ric_ies_len
) < 0) {
3254 /* TODO: prevent MLME/driver from trying to associate? */
3257 #endif /* CONFIG_IEEE80211R */
3260 #ifdef CONFIG_IBSS_RSN
3261 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3262 union wpa_event_data
*data
)
3264 struct wpa_ssid
*ssid
;
3265 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3269 ssid
= wpa_s
->current_ssid
;
3272 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3275 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3279 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3280 union wpa_event_data
*data
)
3282 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3287 /* check if the ssid is correctly configured as IBSS/RSN */
3288 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3291 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3292 data
->rx_mgmt
.frame_len
);
3294 #endif /* CONFIG_IBSS_RSN */
3297 #ifdef CONFIG_IEEE80211R
3298 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3301 const u8
*sta_addr
, *target_ap_addr
;
3304 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3305 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3306 return; /* only SME case supported for now */
3307 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3310 return; /* Only FT Action Response is supported for now */
3311 sta_addr
= data
+ 1;
3312 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3313 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3314 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3315 MACSTR
" TargetAP " MACSTR
" status %u",
3316 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3318 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3319 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3320 " in FT Action Response", MAC2STR(sta_addr
));
3325 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3326 "failure (status code %d)", status
);
3327 /* TODO: report error to FT code(?) */
3331 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3332 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3333 target_ap_addr
, NULL
, 0) < 0)
3338 struct wpa_bss
*bss
;
3339 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3341 wpa_s
->sme
.freq
= bss
->freq
;
3342 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3343 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3346 #endif /* CONFIG_SME */
3348 #endif /* CONFIG_IEEE80211R */
3351 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3352 struct unprot_deauth
*e
)
3354 #ifdef CONFIG_IEEE80211W
3355 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3356 "dropped: " MACSTR
" -> " MACSTR
3357 " (reason code %u)",
3358 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3359 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3360 #endif /* CONFIG_IEEE80211W */
3364 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3365 struct unprot_disassoc
*e
)
3367 #ifdef CONFIG_IEEE80211W
3368 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3369 "dropped: " MACSTR
" -> " MACSTR
3370 " (reason code %u)",
3371 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3372 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3373 #endif /* CONFIG_IEEE80211W */
3377 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3378 u16 reason_code
, int locally_generated
,
3379 const u8
*ie
, size_t ie_len
, int deauth
)
3382 if (wpa_s
->ap_iface
&& addr
) {
3383 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3387 if (wpa_s
->ap_iface
) {
3388 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3391 #endif /* CONFIG_AP */
3393 if (!locally_generated
)
3394 wpa_s
->own_disconnect_req
= 0;
3396 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3398 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3399 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3400 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3401 eapol_sm_failed(wpa_s
->eapol
))) &&
3402 !wpa_s
->eap_expected_failure
))
3403 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3406 if (deauth
&& reason_code
> 0) {
3407 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3408 locally_generated
) > 0) {
3410 * The interface was removed, so cannot continue
3411 * processing any additional operations after this.
3416 #endif /* CONFIG_P2P */
3418 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3423 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3424 struct disassoc_info
*info
)
3426 u16 reason_code
= 0;
3427 int locally_generated
= 0;
3428 const u8
*addr
= NULL
;
3429 const u8
*ie
= NULL
;
3432 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3437 ie_len
= info
->ie_len
;
3438 reason_code
= info
->reason_code
;
3439 locally_generated
= info
->locally_generated
;
3440 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3441 locally_generated
? " (locally generated)" : "");
3443 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3445 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3450 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3451 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3455 if (wpa_s
->ap_iface
) {
3456 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3459 #endif /* CONFIG_AP */
3463 wpas_p2p_disassoc_notif(
3464 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3467 #endif /* CONFIG_P2P */
3469 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3470 sme_event_disassoc(wpa_s
, info
);
3472 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3477 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3478 struct deauth_info
*info
)
3480 u16 reason_code
= 0;
3481 int locally_generated
= 0;
3482 const u8
*addr
= NULL
;
3483 const u8
*ie
= NULL
;
3486 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3491 ie_len
= info
->ie_len
;
3492 reason_code
= info
->reason_code
;
3493 locally_generated
= info
->locally_generated
;
3494 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3496 locally_generated
? " (locally generated)" : "");
3498 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3501 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3505 wpa_reset_ft_completed(wpa_s
->wpa
);
3507 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3508 locally_generated
, ie
, ie_len
, 1);
3512 static const char * reg_init_str(enum reg_change_initiator init
)
3515 case REGDOM_SET_BY_CORE
:
3517 case REGDOM_SET_BY_USER
:
3519 case REGDOM_SET_BY_DRIVER
:
3521 case REGDOM_SET_BY_COUNTRY_IE
:
3522 return "COUNTRY_IE";
3523 case REGDOM_BEACON_HINT
:
3524 return "BEACON_HINT";
3530 static const char * reg_type_str(enum reg_type type
)
3533 case REGDOM_TYPE_UNKNOWN
:
3535 case REGDOM_TYPE_COUNTRY
:
3537 case REGDOM_TYPE_WORLD
:
3539 case REGDOM_TYPE_CUSTOM_WORLD
:
3540 return "CUSTOM_WORLD";
3541 case REGDOM_TYPE_INTERSECTION
:
3542 return "INTERSECTION";
3548 static void wpa_supplicant_update_channel_list(
3549 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3551 struct wpa_supplicant
*ifs
;
3555 * To allow backwards compatibility with higher level layers that
3556 * assumed the REGDOM_CHANGE event is sent over the initially added
3557 * interface. Find the highest parent of this interface and use it to
3560 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3563 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3564 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3565 info
->alpha2
[0] ? " alpha2=" : "",
3566 info
->alpha2
[0] ? info
->alpha2
: "");
3568 if (wpa_s
->drv_priv
== NULL
)
3569 return; /* Ignore event during drv initialization */
3571 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3573 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3575 free_hw_features(ifs
);
3576 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3577 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3579 /* Restart PNO/sched_scan with updated channel list */
3582 wpas_start_pno(ifs
);
3583 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3584 wpa_dbg(ifs
, MSG_DEBUG
,
3585 "Channel list changed - restart sched_scan");
3586 wpas_scan_restart_sched_scan(ifs
);
3590 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3594 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3595 const u8
*frame
, size_t len
, int freq
,
3598 const struct ieee80211_mgmt
*mgmt
;
3603 if (len
< IEEE80211_HDRLEN
+ 2)
3606 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3607 payload
= frame
+ IEEE80211_HDRLEN
;
3608 category
= *payload
++;
3609 plen
= len
- IEEE80211_HDRLEN
- 1;
3611 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3612 " Category=%u DataLen=%d freq=%d MHz",
3613 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3615 if (category
== WLAN_ACTION_WMM
) {
3616 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3620 #ifdef CONFIG_IEEE80211R
3621 if (category
== WLAN_ACTION_FT
) {
3622 ft_rx_action(wpa_s
, payload
, plen
);
3625 #endif /* CONFIG_IEEE80211R */
3627 #ifdef CONFIG_IEEE80211W
3629 if (category
== WLAN_ACTION_SA_QUERY
) {
3630 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3633 #endif /* CONFIG_SME */
3634 #endif /* CONFIG_IEEE80211W */
3637 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3638 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3641 #endif /* CONFIG_WNM */
3644 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3645 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3646 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3647 mgmt
->u
.action
.category
,
3648 payload
, plen
, freq
) == 0)
3650 #endif /* CONFIG_GAS */
3652 #ifdef CONFIG_GAS_SERVER
3653 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3654 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3655 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3656 mgmt
->u
.action
.category
,
3657 payload
, plen
, freq
) == 0)
3659 #endif /* CONFIG_GAS_SERVER */
3662 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3663 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3664 wpa_dbg(wpa_s
, MSG_DEBUG
,
3665 "TDLS: Received Discovery Response from " MACSTR
,
3669 #endif /* CONFIG_TDLS */
3671 #ifdef CONFIG_INTERWORKING
3672 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3673 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3674 const u8
*pos
= payload
+ 1;
3675 size_t qlen
= plen
- 1;
3676 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3677 MACSTR
, MAC2STR(mgmt
->sa
));
3678 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3679 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3680 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3681 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3684 #endif /* CONFIG_INTERWORKING */
3686 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3687 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3688 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3695 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3696 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3697 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3701 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3702 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3703 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3704 payload
+ 1, plen
- 1,
3710 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3711 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3714 #endif /* CONFIG_FST */
3717 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3718 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3719 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3720 payload
[4] == DPP_OUI_TYPE
) {
3723 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3726 #endif /* CONFIG_DPP */
3728 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3729 category
, payload
, plen
, freq
);
3731 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3735 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3736 union wpa_event_data
*event
)
3738 struct wpa_freq_range_list
*list
;
3741 list
= &event
->freq_range
;
3744 str
= freq_range_list_str(list
);
3745 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3749 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3750 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3753 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3756 * The update channel flow will also take care of moving a GO
3757 * from the unsafe frequency if needed.
3759 wpas_p2p_update_channel_list(wpa_s
,
3760 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3762 #endif /* CONFIG_P2P */
3768 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
3770 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3771 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3772 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3773 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3774 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3779 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
3785 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
3786 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
3788 for (j
= 0; j
< mode
->num_channels
; j
++) {
3789 const struct hostapd_channel_data
*chan
;
3791 chan
= &mode
->channels
[j
];
3792 if (chan
->freq
== freq
)
3793 return chan
->dfs_cac_ms
;
3801 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
3802 struct dfs_event
*radar
)
3804 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3805 if (wpa_s
->ap_iface
) {
3806 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
3808 #endif /* NEED_AP_MLME && CONFIG_AP */
3810 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
3812 cac_time
/= 1000; /* convert from ms to sec */
3814 cac_time
= 10 * 60; /* max timeout: 10 minutes */
3816 /* Restart auth timeout: CAC time added to initial timeout */
3817 wpas_auth_timeout_restart(wpa_s
, cac_time
);
3822 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
3823 struct dfs_event
*radar
)
3825 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3826 if (wpa_s
->ap_iface
) {
3827 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
3829 #endif /* NEED_AP_MLME && CONFIG_AP */
3831 /* Restart auth timeout with original value after CAC is
3833 wpas_auth_timeout_restart(wpa_s
, 0);
3838 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
3839 struct dfs_event
*radar
)
3841 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3842 if (wpa_s
->ap_iface
) {
3843 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
3845 #endif /* NEED_AP_MLME && CONFIG_AP */
3847 /* Restart auth timeout with original value after CAC is
3849 wpas_auth_timeout_restart(wpa_s
, 0);
3854 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3855 union wpa_event_data
*data
)
3857 wpa_dbg(wpa_s
, MSG_DEBUG
,
3858 "Connection authorized by device, previous state %d",
3861 wpa_supplicant_event_port_authorized(wpa_s
);
3863 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3864 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3865 data
->assoc_info
.ptk_kck_len
,
3866 data
->assoc_info
.ptk_kek
,
3867 data
->assoc_info
.ptk_kek_len
);
3869 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3870 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3871 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3873 /* Update ERP next sequence number */
3874 eapol_sm_update_erp_next_seq_num(
3875 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3877 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3878 /* Add the new PMK and PMKID to the PMKSA cache */
3879 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3880 data
->assoc_info
.fils_pmk
,
3881 data
->assoc_info
.fils_pmk_len
,
3882 data
->assoc_info
.fils_pmkid
,
3883 wpa_s
->bssid
, fils_cache_id
);
3884 } else if (data
->assoc_info
.fils_pmkid
) {
3885 /* Update the current PMKSA used for this connection */
3886 pmksa_cache_set_current(wpa_s
->wpa
,
3887 data
->assoc_info
.fils_pmkid
,
3888 NULL
, NULL
, 0, NULL
, 0);
3891 #endif /* CONFIG_FILS */
3895 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
3896 union wpa_event_data
*data
)
3898 const u8
*bssid
= data
->assoc_reject
.bssid
;
3900 if (!bssid
|| is_zero_ether_addr(bssid
))
3901 bssid
= wpa_s
->pending_bssid
;
3903 if (data
->assoc_reject
.bssid
)
3904 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3905 "bssid=" MACSTR
" status_code=%u%s%s%s",
3906 MAC2STR(data
->assoc_reject
.bssid
),
3907 data
->assoc_reject
.status_code
,
3908 data
->assoc_reject
.timed_out
? " timeout" : "",
3909 data
->assoc_reject
.timeout_reason
? "=" : "",
3910 data
->assoc_reject
.timeout_reason
?
3911 data
->assoc_reject
.timeout_reason
: "");
3913 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3914 "status_code=%u%s%s%s",
3915 data
->assoc_reject
.status_code
,
3916 data
->assoc_reject
.timed_out
? " timeout" : "",
3917 data
->assoc_reject
.timeout_reason
? "=" : "",
3918 data
->assoc_reject
.timeout_reason
?
3919 data
->assoc_reject
.timeout_reason
: "");
3920 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3921 wpas_notify_assoc_status_code(wpa_s
);
3924 if (data
->assoc_reject
.status_code
==
3925 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
3926 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
3927 wpa_s
->current_ssid
&&
3928 wpa_s
->current_ssid
->owe_group
== 0 &&
3929 wpa_s
->last_owe_group
!= 21) {
3930 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3931 struct wpa_bss
*bss
= wpa_s
->current_bss
;
3934 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
3938 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
3939 wpas_connect_work_done(wpa_s
);
3940 wpa_supplicant_mark_disassoc(wpa_s
);
3941 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3944 #endif /* CONFIG_OWE */
3946 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
3947 sme_event_assoc_reject(wpa_s
, data
);
3951 /* Driver-based SME cases */
3954 if (wpa_s
->current_ssid
&&
3955 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
3956 !data
->assoc_reject
.timed_out
) {
3957 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
3958 wpa_sm_aborted_cached(wpa_s
->wpa
);
3959 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
3961 #endif /* CONFIG_SAE */
3964 /* Update ERP next sequence number */
3965 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
)
3966 eapol_sm_update_erp_next_seq_num(
3968 data
->assoc_reject
.fils_erp_next_seq_num
);
3969 #endif /* CONFIG_FILS */
3971 wpas_connection_failed(wpa_s
, bssid
);
3972 wpa_supplicant_mark_disassoc(wpa_s
);
3976 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3977 union wpa_event_data
*data
)
3979 struct wpa_supplicant
*wpa_s
= ctx
;
3982 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3983 event
!= EVENT_INTERFACE_ENABLED
&&
3984 event
!= EVENT_INTERFACE_STATUS
&&
3985 event
!= EVENT_SCAN_RESULTS
&&
3986 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3987 wpa_dbg(wpa_s
, MSG_DEBUG
,
3988 "Ignore event %s (%d) while interface is disabled",
3989 event_to_string(event
), event
);
3993 #ifndef CONFIG_NO_STDOUT_DEBUG
3995 int level
= MSG_DEBUG
;
3997 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3998 const struct ieee80211_hdr
*hdr
;
4000 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4001 fc
= le_to_host16(hdr
->frame_control
);
4002 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4003 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4004 level
= MSG_EXCESSIVE
;
4007 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4008 event_to_string(event
), event
);
4010 #endif /* CONFIG_NO_STDOUT_DEBUG */
4015 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4016 data
->auth
.ies_len
))
4017 wpa_printf(MSG_DEBUG
,
4018 "FST: MB IEs updated from auth IE");
4019 #endif /* CONFIG_FST */
4020 sme_event_auth(wpa_s
, data
);
4023 #ifdef CONFIG_TESTING_OPTIONS
4024 if (wpa_s
->ignore_auth_resp
) {
4025 wpa_printf(MSG_INFO
,
4026 "EVENT_ASSOC - ignore_auth_resp active!");
4029 if (wpa_s
->testing_resend_assoc
) {
4030 wpa_printf(MSG_INFO
,
4031 "EVENT_DEAUTH - testing_resend_assoc");
4034 #endif /* CONFIG_TESTING_OPTIONS */
4035 wpa_supplicant_event_assoc(wpa_s
, data
);
4037 (data
->assoc_info
.authorized
||
4038 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4039 wpa_fils_is_completed(wpa_s
->wpa
))))
4040 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4042 wpa_msg(wpa_s
, MSG_INFO
,
4043 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4044 data
->assoc_info
.subnet_status
);
4047 case EVENT_DISASSOC
:
4048 wpas_event_disassoc(wpa_s
,
4049 data
? &data
->disassoc_info
: NULL
);
4052 #ifdef CONFIG_TESTING_OPTIONS
4053 if (wpa_s
->ignore_auth_resp
) {
4054 wpa_printf(MSG_INFO
,
4055 "EVENT_DEAUTH - ignore_auth_resp active!");
4058 if (wpa_s
->testing_resend_assoc
) {
4059 wpa_printf(MSG_INFO
,
4060 "EVENT_DEAUTH - testing_resend_assoc");
4063 #endif /* CONFIG_TESTING_OPTIONS */
4064 wpas_event_deauth(wpa_s
,
4065 data
? &data
->deauth_info
: NULL
);
4067 case EVENT_MICHAEL_MIC_FAILURE
:
4068 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4070 #ifndef CONFIG_NO_SCAN_PROCESSING
4071 case EVENT_SCAN_STARTED
:
4072 if (wpa_s
->own_scan_requested
||
4073 (data
&& !data
->scan_info
.external_scan
)) {
4074 struct os_reltime diff
;
4076 os_get_reltime(&wpa_s
->scan_start_time
);
4077 os_reltime_sub(&wpa_s
->scan_start_time
,
4078 &wpa_s
->scan_trigger_time
, &diff
);
4079 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4080 diff
.sec
, diff
.usec
);
4081 wpa_s
->own_scan_requested
= 0;
4082 wpa_s
->own_scan_running
= 1;
4083 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4084 wpa_s
->manual_scan_use_id
) {
4085 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4086 WPA_EVENT_SCAN_STARTED
"id=%u",
4087 wpa_s
->manual_scan_id
);
4089 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4090 WPA_EVENT_SCAN_STARTED
);
4093 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4094 wpa_s
->radio
->external_scan_running
= 1;
4095 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4098 case EVENT_SCAN_RESULTS
:
4099 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4100 wpa_s
->scan_res_handler
= NULL
;
4101 wpa_s
->own_scan_running
= 0;
4102 wpa_s
->radio
->external_scan_running
= 0;
4103 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4107 if (!(data
&& data
->scan_info
.external_scan
) &&
4108 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4109 struct os_reltime now
, diff
;
4110 os_get_reltime(&now
);
4111 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4112 wpa_s
->scan_start_time
.sec
= 0;
4113 wpa_s
->scan_start_time
.usec
= 0;
4114 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4115 diff
.sec
, diff
.usec
);
4117 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4118 break; /* interface may have been removed */
4119 if (!(data
&& data
->scan_info
.external_scan
))
4120 wpa_s
->own_scan_running
= 0;
4121 if (data
&& data
->scan_info
.nl_scan_event
)
4122 wpa_s
->radio
->external_scan_running
= 0;
4123 radio_work_check_next(wpa_s
);
4125 #endif /* CONFIG_NO_SCAN_PROCESSING */
4126 case EVENT_ASSOCINFO
:
4127 wpa_supplicant_event_associnfo(wpa_s
, data
);
4129 case EVENT_INTERFACE_STATUS
:
4130 wpa_supplicant_event_interface_status(wpa_s
, data
);
4132 case EVENT_PMKID_CANDIDATE
:
4133 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4137 wpa_supplicant_event_tdls(wpa_s
, data
);
4139 #endif /* CONFIG_TDLS */
4142 wpa_supplicant_event_wnm(wpa_s
, data
);
4144 #endif /* CONFIG_WNM */
4145 #ifdef CONFIG_IEEE80211R
4146 case EVENT_FT_RESPONSE
:
4147 wpa_supplicant_event_ft_response(wpa_s
, data
);
4149 #endif /* CONFIG_IEEE80211R */
4150 #ifdef CONFIG_IBSS_RSN
4151 case EVENT_IBSS_RSN_START
:
4152 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4154 #endif /* CONFIG_IBSS_RSN */
4155 case EVENT_ASSOC_REJECT
:
4156 wpas_event_assoc_reject(wpa_s
, data
);
4158 case EVENT_AUTH_TIMED_OUT
:
4159 /* It is possible to get this event from earlier connection */
4160 if (wpa_s
->current_ssid
&&
4161 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4162 wpa_dbg(wpa_s
, MSG_DEBUG
,
4163 "Ignore AUTH_TIMED_OUT in mesh configuration");
4166 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4167 sme_event_auth_timed_out(wpa_s
, data
);
4169 case EVENT_ASSOC_TIMED_OUT
:
4170 /* It is possible to get this event from earlier connection */
4171 if (wpa_s
->current_ssid
&&
4172 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4173 wpa_dbg(wpa_s
, MSG_DEBUG
,
4174 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4177 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4178 sme_event_assoc_timed_out(wpa_s
, data
);
4180 case EVENT_TX_STATUS
:
4181 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4182 " type=%d stype=%d",
4183 MAC2STR(data
->tx_status
.dst
),
4184 data
->tx_status
.type
, data
->tx_status
.stype
);
4186 if (wpa_s
->ap_iface
== NULL
) {
4187 #ifdef CONFIG_OFFCHANNEL
4188 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4189 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4190 offchannel_send_action_tx_status(
4191 wpa_s
, data
->tx_status
.dst
,
4192 data
->tx_status
.data
,
4193 data
->tx_status
.data_len
,
4194 data
->tx_status
.ack
?
4195 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4196 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4197 #endif /* CONFIG_OFFCHANNEL */
4200 #endif /* CONFIG_AP */
4201 #ifdef CONFIG_OFFCHANNEL
4202 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4203 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4205 * Catch TX status events for Action frames we sent via group
4206 * interface in GO mode, or via standalone AP interface.
4207 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4208 * except when the primary interface is used as a GO interface
4209 * (for drivers which do not have group interface concurrency)
4211 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4212 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4213 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4214 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4215 offchannel_send_action_tx_status(
4216 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4217 data
->tx_status
.data
,
4218 data
->tx_status
.data_len
,
4219 data
->tx_status
.ack
?
4220 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4221 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4224 #endif /* CONFIG_OFFCHANNEL */
4226 switch (data
->tx_status
.type
) {
4227 case WLAN_FC_TYPE_MGMT
:
4228 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4229 data
->tx_status
.data_len
,
4230 data
->tx_status
.stype
,
4231 data
->tx_status
.ack
);
4233 case WLAN_FC_TYPE_DATA
:
4234 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4235 data
->tx_status
.data
,
4236 data
->tx_status
.data_len
,
4237 data
->tx_status
.ack
);
4240 #endif /* CONFIG_AP */
4243 case EVENT_EAPOL_TX_STATUS
:
4244 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4245 data
->eapol_tx_status
.data
,
4246 data
->eapol_tx_status
.data_len
,
4247 data
->eapol_tx_status
.ack
);
4249 case EVENT_DRIVER_CLIENT_POLL_OK
:
4250 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4252 case EVENT_RX_FROM_UNKNOWN
:
4253 if (wpa_s
->ap_iface
== NULL
)
4255 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4256 data
->rx_from_unknown
.wds
);
4258 #endif /* CONFIG_AP */
4259 case EVENT_CH_SWITCH
:
4260 if (!data
|| !wpa_s
->current_ssid
)
4263 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4264 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4265 data
->ch_switch
.freq
,
4266 data
->ch_switch
.ht_enabled
,
4267 data
->ch_switch
.ch_offset
,
4268 channel_width_to_string(data
->ch_switch
.ch_width
),
4269 data
->ch_switch
.cf1
,
4270 data
->ch_switch
.cf2
);
4272 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4273 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4276 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4277 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4278 wpa_s
->current_ssid
->mode
==
4279 WPAS_MODE_P2P_GROUP_FORMATION
) {
4280 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4281 data
->ch_switch
.ht_enabled
,
4282 data
->ch_switch
.ch_offset
,
4283 data
->ch_switch
.ch_width
,
4284 data
->ch_switch
.cf1
,
4285 data
->ch_switch
.cf2
);
4287 #endif /* CONFIG_AP */
4289 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4293 case EVENT_DFS_RADAR_DETECTED
:
4295 wpas_ap_event_dfs_radar_detected(wpa_s
,
4298 case EVENT_DFS_NOP_FINISHED
:
4300 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4303 #endif /* NEED_AP_MLME */
4304 #endif /* CONFIG_AP */
4305 case EVENT_DFS_CAC_STARTED
:
4307 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4309 case EVENT_DFS_CAC_FINISHED
:
4311 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4313 case EVENT_DFS_CAC_ABORTED
:
4315 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4317 case EVENT_RX_MGMT
: {
4319 const struct ieee80211_mgmt
*mgmt
;
4321 #ifdef CONFIG_TESTING_OPTIONS
4322 if (wpa_s
->ext_mgmt_frame_handling
) {
4323 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4324 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4325 char *hex
= os_malloc(hex_len
);
4327 wpa_snprintf_hex(hex
, hex_len
,
4328 rx
->frame
, rx
->frame_len
);
4329 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4330 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4336 #endif /* CONFIG_TESTING_OPTIONS */
4338 mgmt
= (const struct ieee80211_mgmt
*)
4339 data
->rx_mgmt
.frame
;
4340 fc
= le_to_host16(mgmt
->frame_control
);
4341 stype
= WLAN_FC_GET_STYPE(fc
);
4344 if (wpa_s
->ap_iface
== NULL
) {
4345 #endif /* CONFIG_AP */
4347 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4348 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4349 const u8
*src
= mgmt
->sa
;
4353 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4354 ie_len
= data
->rx_mgmt
.frame_len
-
4356 wpas_p2p_probe_req_rx(
4357 wpa_s
, src
, mgmt
->da
,
4358 mgmt
->bssid
, ie
, ie_len
,
4360 data
->rx_mgmt
.ssi_signal
);
4363 #endif /* CONFIG_P2P */
4364 #ifdef CONFIG_IBSS_RSN
4365 if (wpa_s
->current_ssid
&&
4366 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4367 stype
== WLAN_FC_STYPE_AUTH
&&
4368 data
->rx_mgmt
.frame_len
>= 30) {
4369 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4372 #endif /* CONFIG_IBSS_RSN */
4374 if (stype
== WLAN_FC_STYPE_ACTION
) {
4375 wpas_event_rx_mgmt_action(
4376 wpa_s
, data
->rx_mgmt
.frame
,
4377 data
->rx_mgmt
.frame_len
,
4379 data
->rx_mgmt
.ssi_signal
);
4384 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4389 if (stype
== WLAN_FC_STYPE_AUTH
&&
4390 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4391 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4392 sme_external_auth_mgmt_rx(
4393 wpa_s
, data
->rx_mgmt
.frame
,
4394 data
->rx_mgmt
.frame_len
);
4397 #endif /* CONFIG_SAE */
4398 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4399 "management frame in non-AP mode");
4404 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4405 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4409 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4410 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4412 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4413 mgmt
->bssid
, ie
, ie_len
,
4414 data
->rx_mgmt
.ssi_signal
);
4417 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4418 #endif /* CONFIG_AP */
4421 case EVENT_RX_PROBE_REQ
:
4422 if (data
->rx_probe_req
.sa
== NULL
||
4423 data
->rx_probe_req
.ie
== NULL
)
4426 if (wpa_s
->ap_iface
) {
4427 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4428 data
->rx_probe_req
.sa
,
4429 data
->rx_probe_req
.da
,
4430 data
->rx_probe_req
.bssid
,
4431 data
->rx_probe_req
.ie
,
4432 data
->rx_probe_req
.ie_len
,
4433 data
->rx_probe_req
.ssi_signal
);
4436 #endif /* CONFIG_AP */
4437 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4438 data
->rx_probe_req
.da
,
4439 data
->rx_probe_req
.bssid
,
4440 data
->rx_probe_req
.ie
,
4441 data
->rx_probe_req
.ie_len
,
4443 data
->rx_probe_req
.ssi_signal
);
4445 case EVENT_REMAIN_ON_CHANNEL
:
4446 #ifdef CONFIG_OFFCHANNEL
4447 offchannel_remain_on_channel_cb(
4448 wpa_s
, data
->remain_on_channel
.freq
,
4449 data
->remain_on_channel
.duration
);
4450 #endif /* CONFIG_OFFCHANNEL */
4451 wpas_p2p_remain_on_channel_cb(
4452 wpa_s
, data
->remain_on_channel
.freq
,
4453 data
->remain_on_channel
.duration
);
4455 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4456 #ifdef CONFIG_OFFCHANNEL
4457 offchannel_cancel_remain_on_channel_cb(
4458 wpa_s
, data
->remain_on_channel
.freq
);
4459 #endif /* CONFIG_OFFCHANNEL */
4460 wpas_p2p_cancel_remain_on_channel_cb(
4461 wpa_s
, data
->remain_on_channel
.freq
);
4463 wpas_dpp_cancel_remain_on_channel_cb(
4464 wpa_s
, data
->remain_on_channel
.freq
);
4465 #endif /* CONFIG_DPP */
4467 case EVENT_EAPOL_RX
:
4468 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4469 data
->eapol_rx
.data
,
4470 data
->eapol_rx
.data_len
);
4472 case EVENT_SIGNAL_CHANGE
:
4473 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4474 "above=%d signal=%d noise=%d txrate=%d",
4475 data
->signal_change
.above_threshold
,
4476 data
->signal_change
.current_signal
,
4477 data
->signal_change
.current_noise
,
4478 data
->signal_change
.current_txrate
);
4479 wpa_bss_update_level(wpa_s
->current_bss
,
4480 data
->signal_change
.current_signal
);
4481 bgscan_notify_signal_change(
4482 wpa_s
, data
->signal_change
.above_threshold
,
4483 data
->signal_change
.current_signal
,
4484 data
->signal_change
.current_noise
,
4485 data
->signal_change
.current_txrate
);
4487 case EVENT_INTERFACE_MAC_CHANGED
:
4488 wpa_supplicant_update_mac_addr(wpa_s
);
4490 case EVENT_INTERFACE_ENABLED
:
4491 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4492 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4493 wpa_supplicant_update_mac_addr(wpa_s
);
4494 if (wpa_s
->p2p_mgmt
) {
4495 wpa_supplicant_set_state(wpa_s
,
4501 if (!wpa_s
->ap_iface
) {
4502 wpa_supplicant_set_state(wpa_s
,
4504 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4505 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4507 wpa_supplicant_set_state(wpa_s
,
4509 #else /* CONFIG_AP */
4510 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4511 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4512 #endif /* CONFIG_AP */
4515 case EVENT_INTERFACE_DISABLED
:
4516 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4518 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4519 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4520 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4522 * Mark interface disabled if this happens to end up not
4523 * being removed as a separate P2P group interface.
4525 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4527 * The interface was externally disabled. Remove
4528 * it assuming an external entity will start a
4529 * new session if needed.
4531 if (wpa_s
->current_ssid
&&
4532 wpa_s
->current_ssid
->p2p_group
)
4533 wpas_p2p_interface_unavailable(wpa_s
);
4535 wpas_p2p_disconnect(wpa_s
);
4537 * wpa_s instance may have been freed, so must not use
4542 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4543 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4544 /* This radio work will be cancelled, so clear P2P
4547 p2p_stop_find(wpa_s
->global
->p2p
);
4549 #endif /* CONFIG_P2P */
4551 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4553 * Indicate disconnection to keep ctrl_iface events
4556 wpa_supplicant_event_disassoc(
4557 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4559 wpa_supplicant_mark_disassoc(wpa_s
);
4560 wpa_bss_flush(wpa_s
);
4561 radio_remove_works(wpa_s
, NULL
, 0);
4563 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4565 case EVENT_CHANNEL_LIST_CHANGED
:
4566 wpa_supplicant_update_channel_list(
4567 wpa_s
, &data
->channel_list_changed
);
4569 case EVENT_INTERFACE_UNAVAILABLE
:
4570 wpas_p2p_interface_unavailable(wpa_s
);
4572 case EVENT_BEST_CHANNEL
:
4573 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4575 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4576 data
->best_chan
.freq_overall
);
4577 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4578 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4579 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4580 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4581 data
->best_chan
.freq_5
,
4582 data
->best_chan
.freq_overall
);
4584 case EVENT_UNPROT_DEAUTH
:
4585 wpa_supplicant_event_unprot_deauth(wpa_s
,
4586 &data
->unprot_deauth
);
4588 case EVENT_UNPROT_DISASSOC
:
4589 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4590 &data
->unprot_disassoc
);
4592 case EVENT_STATION_LOW_ACK
:
4594 if (wpa_s
->ap_iface
&& data
)
4595 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4596 data
->low_ack
.addr
);
4597 #endif /* CONFIG_AP */
4600 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4601 data
->low_ack
.addr
);
4602 #endif /* CONFIG_TDLS */
4604 case EVENT_IBSS_PEER_LOST
:
4605 #ifdef CONFIG_IBSS_RSN
4606 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4607 #endif /* CONFIG_IBSS_RSN */
4609 case EVENT_DRIVER_GTK_REKEY
:
4610 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4611 wpa_s
->bssid
, ETH_ALEN
))
4615 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4616 data
->driver_gtk_rekey
.replay_ctr
);
4618 case EVENT_SCHED_SCAN_STOPPED
:
4619 wpa_s
->sched_scanning
= 0;
4620 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4621 wpa_supplicant_notify_scanning(wpa_s
, 0);
4623 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4627 * If the driver stopped scanning without being requested to,
4628 * request a new scan to continue scanning for networks.
4630 if (!wpa_s
->sched_scan_stop_req
&&
4631 wpa_s
->wpa_state
== WPA_SCANNING
) {
4632 wpa_dbg(wpa_s
, MSG_DEBUG
,
4633 "Restart scanning after unexpected sched_scan stop event");
4634 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4638 wpa_s
->sched_scan_stop_req
= 0;
4641 * Start a new sched scan to continue searching for more SSIDs
4642 * either if timed out or PNO schedule scan is pending.
4644 if (wpa_s
->sched_scan_timed_out
) {
4645 wpa_supplicant_req_sched_scan(wpa_s
);
4646 } else if (wpa_s
->pno_sched_pending
) {
4647 wpa_s
->pno_sched_pending
= 0;
4648 wpas_start_pno(wpa_s
);
4649 } else if (resched
) {
4650 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4654 case EVENT_WPS_BUTTON_PUSHED
:
4656 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4657 #endif /* CONFIG_WPS */
4659 case EVENT_AVOID_FREQUENCIES
:
4660 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4662 case EVENT_CONNECT_FAILED_REASON
:
4664 if (!wpa_s
->ap_iface
|| !data
)
4666 hostapd_event_connect_failed_reason(
4667 wpa_s
->ap_iface
->bss
[0],
4668 data
->connect_failed_reason
.addr
,
4669 data
->connect_failed_reason
.code
);
4670 #endif /* CONFIG_AP */
4672 case EVENT_NEW_PEER_CANDIDATE
:
4674 if (!wpa_s
->ifmsh
|| !data
)
4676 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4677 data
->mesh_peer
.ies
,
4678 data
->mesh_peer
.ie_len
);
4679 #endif /* CONFIG_MESH */
4683 if (!wpa_s
->ap_iface
)
4685 hostapd_event_get_survey(wpa_s
->ap_iface
,
4686 &data
->survey_results
);
4687 #endif /* CONFIG_AP */
4689 case EVENT_ACS_CHANNEL_SELECTED
:
4692 if (!wpa_s
->ap_iface
)
4694 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4695 &data
->acs_selected_channels
);
4696 #endif /* CONFIG_ACS */
4697 #endif /* CONFIG_AP */
4699 case EVENT_P2P_LO_STOP
:
4701 wpa_s
->p2p_lo_started
= 0;
4702 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4703 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4704 data
->p2p_lo_stop
.reason_code
);
4705 #endif /* CONFIG_P2P */
4707 case EVENT_BEACON_LOSS
:
4708 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4710 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4711 bgscan_notify_beacon_loss(wpa_s
);
4713 case EVENT_EXTERNAL_AUTH
:
4715 if (!wpa_s
->current_ssid
) {
4716 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4719 sme_external_auth_trigger(wpa_s
, data
);
4720 #endif /* CONFIG_SAE */
4722 case EVENT_PORT_AUTHORIZED
:
4723 wpa_supplicant_event_port_authorized(wpa_s
);
4725 case EVENT_STATION_OPMODE_CHANGED
:
4727 if (!wpa_s
->ap_iface
|| !data
)
4730 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
4731 data
->sta_opmode
.addr
,
4732 data
->sta_opmode
.smps_mode
,
4733 data
->sta_opmode
.chan_width
,
4734 data
->sta_opmode
.rx_nss
);
4735 #endif /* CONFIG_AP */
4738 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4744 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4745 union wpa_event_data
*data
)
4747 struct wpa_supplicant
*wpa_s
;
4749 if (event
!= EVENT_INTERFACE_STATUS
)
4752 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4753 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4754 unsigned int ifindex
;
4756 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4757 if (ifindex
!= data
->interface_status
.ifindex
) {
4758 wpa_dbg(wpa_s
, MSG_DEBUG
,
4759 "interface status ifindex %d mismatch (%d)",
4760 ifindex
, data
->interface_status
.ifindex
);
4764 #ifdef CONFIG_MATCH_IFACE
4765 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4766 struct wpa_interface
*wpa_i
;
4768 wpa_i
= wpa_supplicant_match_iface(
4769 ctx
, data
->interface_status
.ifname
);
4772 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4777 #endif /* CONFIG_MATCH_IFACE */
4780 wpa_supplicant_event(wpa_s
, event
, data
);