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
| WPA_PROTO_OSEN
)) && 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
) &&
559 !(ssid
->proto
& WPA_PROTO_OSEN
)) {
561 wpa_dbg(wpa_s
, MSG_DEBUG
,
562 " skip RSN IE - proto mismatch");
566 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
568 wpa_dbg(wpa_s
, MSG_DEBUG
,
569 " skip RSN IE - PTK cipher mismatch");
573 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
575 wpa_dbg(wpa_s
, MSG_DEBUG
,
576 " skip RSN IE - GTK cipher mismatch");
580 if (ssid
->group_mgmt_cipher
&&
581 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
583 wpa_dbg(wpa_s
, MSG_DEBUG
,
584 " skip RSN IE - group mgmt cipher mismatch");
588 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
590 wpa_dbg(wpa_s
, MSG_DEBUG
,
591 " skip RSN IE - key mgmt mismatch");
595 #ifdef CONFIG_IEEE80211W
596 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
597 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
598 MGMT_FRAME_PROTECTION_REQUIRED
) {
600 wpa_dbg(wpa_s
, MSG_DEBUG
,
601 " skip RSN IE - no mgmt frame protection");
604 #endif /* CONFIG_IEEE80211W */
605 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
606 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
607 NO_MGMT_FRAME_PROTECTION
) {
609 wpa_dbg(wpa_s
, MSG_DEBUG
,
610 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
614 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
615 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
616 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
617 NO_MGMT_FRAME_PROTECTION
) {
619 wpa_dbg(wpa_s
, MSG_DEBUG
,
620 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
623 #endif /* CONFIG_MBO */
626 wpa_dbg(wpa_s
, MSG_DEBUG
,
627 " selected based on RSN IE");
631 #ifdef CONFIG_IEEE80211W
632 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
633 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
635 wpa_dbg(wpa_s
, MSG_DEBUG
,
636 " skip - MFP Required but network not MFP Capable");
639 #endif /* CONFIG_IEEE80211W */
641 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
642 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
645 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
647 wpa_dbg(wpa_s
, MSG_DEBUG
,
648 " skip WPA IE - parse failed");
653 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
656 wpa_dbg(wpa_s
, MSG_DEBUG
,
657 " selected based on TSN in WPA IE");
661 if (!(ie
.proto
& ssid
->proto
)) {
663 wpa_dbg(wpa_s
, MSG_DEBUG
,
664 " skip WPA IE - proto mismatch");
668 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
670 wpa_dbg(wpa_s
, MSG_DEBUG
,
671 " skip WPA IE - PTK cipher mismatch");
675 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
677 wpa_dbg(wpa_s
, MSG_DEBUG
,
678 " skip WPA IE - GTK cipher mismatch");
682 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
684 wpa_dbg(wpa_s
, MSG_DEBUG
,
685 " skip WPA IE - key mgmt mismatch");
690 wpa_dbg(wpa_s
, MSG_DEBUG
,
691 " selected based on WPA IE");
695 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
698 wpa_dbg(wpa_s
, MSG_DEBUG
,
699 " allow for non-WPA IEEE 802.1X");
704 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
705 !wpa_ie
&& !rsn_ie
) {
707 wpa_dbg(wpa_s
, MSG_DEBUG
,
708 " allow in OWE transition mode");
711 #endif /* CONFIG_OWE */
713 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
714 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
716 wpa_dbg(wpa_s
, MSG_DEBUG
,
717 " skip - no WPA/RSN proto match");
721 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
722 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
724 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
728 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
730 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
735 wpa_dbg(wpa_s
, MSG_DEBUG
,
736 " reject due to mismatch with WPA/WPA2");
742 static int freq_allowed(int *freqs
, int freq
)
749 for (i
= 0; freqs
[i
]; i
++)
750 if (freqs
[i
] == freq
)
756 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
759 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
760 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
765 return 1; /* Cannot do matching without knowing band */
767 modes
= wpa_s
->hw
.modes
;
770 * The driver does not provide any additional information
771 * about the utilized hardware, so allow the connection attempt
777 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
778 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
779 int freq
= modes
[i
].channels
[j
].freq
;
780 if (freq
== bss
->freq
) {
782 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
783 break; /* do not allow 802.11b replace
794 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
795 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
799 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
800 int flagged
= !!(rate_ie
[j
] & 0x80);
801 int r
= (rate_ie
[j
] & 0x7f) * 5;
804 * IEEE Std 802.11n-2009 7.3.2.2:
805 * The new BSS Membership selector value is encoded
806 * like a legacy basic rate, but it is not a rate and
807 * only indicates if the BSS members are required to
808 * support the mandatory features of Clause 20 [HT PHY]
809 * in order to join the BSS.
811 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
812 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
813 if (!ht_supported(mode
)) {
815 wpa_dbg(wpa_s
, MSG_DEBUG
,
816 " hardware does not support HT PHY");
822 /* There's also a VHT selector for 802.11ac */
823 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
824 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
825 if (!vht_supported(mode
)) {
827 wpa_dbg(wpa_s
, MSG_DEBUG
,
828 " hardware does not support VHT PHY");
837 /* check for legacy basic rates */
838 for (k
= 0; k
< mode
->num_rates
; k
++) {
839 if (mode
->rates
[k
] == r
)
842 if (k
== mode
->num_rates
) {
844 * IEEE Std 802.11-2007 7.3.2.2 demands that in
845 * order to join a BSS all required rates
846 * have to be supported by the hardware.
849 wpa_dbg(wpa_s
, MSG_DEBUG
,
850 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
852 bss
->freq
, mode
->mode
, mode
->num_rates
);
863 * Test whether BSS is in an ESS.
864 * This is done differently in DMG (60 GHz) and non-DMG bands
866 static int bss_is_ess(struct wpa_bss
*bss
)
868 if (bss_is_dmg(bss
)) {
869 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
870 IEEE80211_CAP_DMG_AP
;
873 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
878 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
882 for (i
= 0; i
< ETH_ALEN
; i
++) {
883 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
890 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
894 for (i
= 0; i
< num
; i
++) {
895 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
896 const u8
*m
= a
+ ETH_ALEN
;
898 if (match_mac_mask(a
, addr
, m
))
905 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
906 const u8
**ret_ssid
, size_t *ret_ssid_len
)
909 const u8
*owe
, *pos
, *end
, *bssid
;
911 struct wpa_bss
*open_bss
;
913 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
914 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
918 end
= owe
+ 2 + owe
[1];
920 if (end
- pos
< ETH_ALEN
+ 1)
925 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
928 /* Match the profile SSID against the OWE transition mode SSID on the
930 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
931 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
933 *ret_ssid_len
= ssid_len
;
935 if (bss
->ssid_len
> 0)
938 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
941 if (ssid_len
!= open_bss
->ssid_len
||
942 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
943 wpa_dbg(wpa_s
, MSG_DEBUG
,
944 "OWE: transition mode SSID mismatch: %s",
945 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
949 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
950 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
951 wpa_dbg(wpa_s
, MSG_DEBUG
,
952 "OWE: transition mode open BSS unexpected info");
957 end
= owe
+ 2 + owe
[1];
959 if (end
- pos
< ETH_ALEN
+ 1)
961 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
962 wpa_dbg(wpa_s
, MSG_DEBUG
,
963 "OWE: transition mode BSSID mismatch: " MACSTR
,
969 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
971 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
972 wpa_ssid_txt(pos
, ssid_len
));
973 os_memcpy(bss
->ssid
, pos
, ssid_len
);
974 bss
->ssid_len
= ssid_len
;
975 #endif /* CONFIG_OWE */
979 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
980 int i
, struct wpa_bss
*bss
,
981 struct wpa_ssid
*group
,
982 int only_first_ssid
, int debug_print
)
984 u8 wpa_ie_len
, rsn_ie_len
;
986 struct wpa_blacklist
*e
;
988 struct wpa_ssid
*ssid
;
989 int osen
, rsn_osen
= 0;
991 const u8
*assoc_disallow
;
992 #endif /* CONFIG_MBO */
993 const u8
*match_ssid
;
994 size_t match_ssid_len
;
995 struct wpa_ie_data data
;
997 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
998 wpa_ie_len
= ie
? ie
[1] : 0;
1000 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1001 rsn_ie_len
= ie
? ie
[1] : 0;
1002 if (ie
&& wpa_parse_wpa_ie_rsn(ie
, 2 + ie
[1], &data
) == 0 &&
1003 (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
))
1006 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1010 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1011 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1012 i
, MAC2STR(bss
->bssid
),
1013 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1014 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1016 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1018 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1019 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1021 osen
? " osen=1" : "");
1024 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1027 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1029 * When only a single network is enabled, we can
1030 * trigger blacklisting on the first failure. This
1031 * should not be done with multiple enabled networks to
1032 * avoid getting forced to move into a worse ESS on
1033 * single error if there are no other BSSes of the
1038 if (e
->count
> limit
) {
1040 wpa_dbg(wpa_s
, MSG_DEBUG
,
1041 " skip - blacklisted (count=%d limit=%d)",
1048 match_ssid
= bss
->ssid
;
1049 match_ssid_len
= bss
->ssid_len
;
1050 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1052 if (match_ssid_len
== 0) {
1054 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1058 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1060 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1064 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1066 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1070 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1072 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1073 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1076 if (wpas_network_disabled(wpa_s
, ssid
)) {
1078 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1082 res
= wpas_temp_disabled(wpa_s
, ssid
);
1085 wpa_dbg(wpa_s
, MSG_DEBUG
,
1086 " skip - disabled temporarily for %d second(s)",
1092 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1094 wpa_dbg(wpa_s
, MSG_DEBUG
,
1095 " skip - blacklisted (WPS)");
1099 if (wpa
&& ssid
->ssid_len
== 0 &&
1100 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1103 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1104 /* Only allow wildcard SSID match if an AP
1105 * advertises active WPS operation that matches
1108 if (ssid
->ssid_len
== 0 &&
1109 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1112 #endif /* CONFIG_WPS */
1114 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1115 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1119 (match_ssid_len
!= ssid
->ssid_len
||
1120 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1122 wpa_dbg(wpa_s
, MSG_DEBUG
,
1123 " skip - SSID mismatch");
1127 if (ssid
->bssid_set
&&
1128 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1130 wpa_dbg(wpa_s
, MSG_DEBUG
,
1131 " skip - BSSID mismatch");
1135 /* check blacklist */
1136 if (ssid
->num_bssid_blacklist
&&
1137 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1138 ssid
->num_bssid_blacklist
)) {
1140 wpa_dbg(wpa_s
, MSG_DEBUG
,
1141 " skip - BSSID blacklisted");
1145 /* if there is a whitelist, only accept those APs */
1146 if (ssid
->num_bssid_whitelist
&&
1147 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1148 ssid
->num_bssid_whitelist
)) {
1150 wpa_dbg(wpa_s
, MSG_DEBUG
,
1151 " skip - BSSID not in whitelist");
1155 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1159 if (!osen
&& !wpa
&&
1160 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1161 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1162 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1163 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1165 wpa_dbg(wpa_s
, MSG_DEBUG
,
1166 " skip - non-WPA network not allowed");
1170 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1171 has_wep_key(ssid
)) {
1173 wpa_dbg(wpa_s
, MSG_DEBUG
,
1174 " skip - ignore WPA/WPA2 AP for WEP network block");
1178 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
&&
1181 wpa_dbg(wpa_s
, MSG_DEBUG
,
1182 " skip - non-OSEN network not allowed");
1186 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1188 wpa_dbg(wpa_s
, MSG_DEBUG
,
1189 " skip - privacy mismatch");
1193 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1194 !bss_is_pbss(bss
)) {
1196 wpa_dbg(wpa_s
, MSG_DEBUG
,
1197 " skip - not ESS, PBSS, or MBSS");
1201 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1203 wpa_dbg(wpa_s
, MSG_DEBUG
,
1204 " skip - PBSS mismatch (ssid %d bss %d)",
1205 ssid
->pbss
, bss_is_pbss(bss
));
1209 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1211 wpa_dbg(wpa_s
, MSG_DEBUG
,
1212 " skip - frequency not allowed");
1217 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1218 ssid
->frequency
!= bss
->freq
) {
1220 wpa_dbg(wpa_s
, MSG_DEBUG
,
1221 " skip - frequency not allowed (mesh)");
1224 #endif /* CONFIG_MESH */
1226 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1228 wpa_dbg(wpa_s
, MSG_DEBUG
,
1229 " skip - rate sets do not match");
1233 #ifndef CONFIG_IBSS_RSN
1234 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1235 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1236 WPA_KEY_MGMT_WPA_NONE
))) {
1238 wpa_dbg(wpa_s
, MSG_DEBUG
,
1239 " skip - IBSS RSN not supported in the build");
1242 #endif /* !CONFIG_IBSS_RSN */
1245 if (ssid
->p2p_group
&&
1246 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1247 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1249 wpa_dbg(wpa_s
, MSG_DEBUG
,
1250 " skip - no P2P IE seen");
1254 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1255 struct wpabuf
*p2p_ie
;
1256 u8 dev_addr
[ETH_ALEN
];
1258 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1261 wpa_dbg(wpa_s
, MSG_DEBUG
,
1262 " skip - no P2P element");
1265 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1266 bss
, P2P_IE_VENDOR_TYPE
);
1267 if (p2p_ie
== NULL
) {
1269 wpa_dbg(wpa_s
, MSG_DEBUG
,
1270 " skip - could not fetch P2P element");
1274 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1275 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1278 wpa_dbg(wpa_s
, MSG_DEBUG
,
1279 " skip - no matching GO P2P Device Address in P2P element");
1280 wpabuf_free(p2p_ie
);
1283 wpabuf_free(p2p_ie
);
1287 * TODO: skip the AP if its P2P IE has Group Formation
1288 * bit set in the P2P Group Capability Bitmap and we
1289 * are not in Group Formation with that device.
1291 #endif /* CONFIG_P2P */
1293 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1295 struct os_reltime diff
;
1297 os_reltime_sub(&wpa_s
->scan_min_time
,
1298 &bss
->last_update
, &diff
);
1300 wpa_dbg(wpa_s
, MSG_DEBUG
,
1301 " skip - scan result not recent enough (%u.%06u seconds too old)",
1302 (unsigned int) diff
.sec
,
1303 (unsigned int) diff
.usec
);
1307 #ifdef CONFIG_TESTING_OPTIONS
1308 if (wpa_s
->ignore_assoc_disallow
)
1309 goto skip_assoc_disallow
;
1310 #endif /* CONFIG_TESTING_OPTIONS */
1311 assoc_disallow
= wpas_mbo_get_bss_attr(
1312 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1313 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1315 wpa_dbg(wpa_s
, MSG_DEBUG
,
1316 " skip - MBO association disallowed (reason %u)",
1321 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1323 wpa_dbg(wpa_s
, MSG_DEBUG
,
1324 " skip - MBO retry delay has not passed yet");
1327 #ifdef CONFIG_TESTING_OPTIONS
1328 skip_assoc_disallow
:
1329 #endif /* CONFIG_TESTING_OPTIONS */
1330 #endif /* CONFIG_MBO */
1333 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1334 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1335 (!ssid
->dpp_connector
||
1336 !ssid
->dpp_netaccesskey
||
1337 !ssid
->dpp_csign
)) {
1339 wpa_dbg(wpa_s
, MSG_DEBUG
,
1340 " skip - no PMKSA entry for DPP");
1343 #endif /* CONFIG_DPP */
1345 /* Matching configuration found */
1349 /* No matching configuration found */
1354 static struct wpa_bss
*
1355 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1356 struct wpa_ssid
*group
,
1357 struct wpa_ssid
**selected_ssid
,
1358 int only_first_ssid
)
1362 if (wpa_s
->current_ssid
) {
1363 struct wpa_ssid
*ssid
;
1365 wpa_dbg(wpa_s
, MSG_DEBUG
,
1366 "Scan results matching the currently selected network");
1367 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1368 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1370 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1371 only_first_ssid
, 0);
1372 if (ssid
!= wpa_s
->current_ssid
)
1374 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1375 " freq=%d level=%d snr=%d est_throughput=%u",
1376 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1377 bss
->snr
, bss
->est_throughput
);
1381 if (only_first_ssid
)
1382 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1385 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1388 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1389 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1390 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1391 only_first_ssid
, 1);
1392 if (!*selected_ssid
)
1394 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1396 MAC2STR(bss
->bssid
),
1397 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1405 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1406 struct wpa_ssid
**selected_ssid
)
1408 struct wpa_bss
*selected
= NULL
;
1410 struct wpa_ssid
*next_ssid
= NULL
;
1411 struct wpa_ssid
*ssid
;
1413 if (wpa_s
->last_scan_res
== NULL
||
1414 wpa_s
->last_scan_res_used
== 0)
1415 return NULL
; /* no scan results from last update */
1417 if (wpa_s
->next_ssid
) {
1418 /* check that next_ssid is still valid */
1419 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1420 if (ssid
== wpa_s
->next_ssid
)
1424 wpa_s
->next_ssid
= NULL
;
1427 while (selected
== NULL
) {
1428 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1429 if (next_ssid
&& next_ssid
->priority
==
1430 wpa_s
->conf
->pssid
[prio
]->priority
) {
1431 selected
= wpa_supplicant_select_bss(
1432 wpa_s
, next_ssid
, selected_ssid
, 1);
1436 selected
= wpa_supplicant_select_bss(
1437 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1443 if (selected
== NULL
&& wpa_s
->blacklist
&&
1444 !wpa_s
->countermeasures
) {
1445 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1446 "blacklist and try again");
1447 wpa_blacklist_clear(wpa_s
);
1448 wpa_s
->blacklist_cleared
++;
1449 } else if (selected
== NULL
)
1453 ssid
= *selected_ssid
;
1454 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1455 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1456 const char *field_name
, *txt
= NULL
;
1458 wpa_dbg(wpa_s
, MSG_DEBUG
,
1459 "PSK/passphrase not yet available for the selected network");
1461 wpas_notify_network_request(wpa_s
, ssid
,
1462 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1464 field_name
= wpa_supplicant_ctrl_req_to_string(
1465 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1466 if (field_name
== NULL
)
1469 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1478 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1479 int timeout_sec
, int timeout_usec
)
1481 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1483 * No networks are enabled; short-circuit request so
1484 * we don't wait timeout seconds before transitioning
1485 * to INACTIVE state.
1487 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1488 "since there are no enabled networks");
1489 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1493 wpa_s
->scan_for_connection
= 1;
1494 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1498 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1499 struct wpa_bss
*selected
,
1500 struct wpa_ssid
*ssid
)
1502 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1503 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1504 "PBC session overlap");
1505 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1507 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1508 wpa_s
->p2p_in_provisioning
) {
1509 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1513 #endif /* CONFIG_P2P */
1516 wpas_wps_pbc_overlap(wpa_s
);
1517 wpas_wps_cancel(wpa_s
);
1518 #endif /* CONFIG_WPS */
1522 wpa_msg(wpa_s
, MSG_DEBUG
,
1523 "Considering connect request: reassociate: %d selected: "
1524 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1525 " wpa_state: %s ssid=%p current_ssid=%p",
1526 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1527 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1528 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1529 ssid
, wpa_s
->current_ssid
);
1532 * Do not trigger new association unless the BSSID has changed or if
1533 * reassociation is requested. If we are in process of associating with
1534 * the selected BSSID, do not trigger new attempt.
1536 if (wpa_s
->reassociate
||
1537 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1538 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1539 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1540 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1541 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1543 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1544 ssid
!= wpa_s
->current_ssid
)))) {
1545 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1546 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1549 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1550 MAC2STR(selected
->bssid
));
1551 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1553 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1554 "connect with the selected AP");
1561 static struct wpa_ssid
*
1562 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1565 struct wpa_ssid
*ssid
;
1567 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1568 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1570 if (wpas_network_disabled(wpa_s
, ssid
))
1572 #ifndef CONFIG_IBSS_RSN
1573 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1574 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1575 WPA_KEY_MGMT_WPA_NONE
))) {
1576 wpa_msg(wpa_s
, MSG_INFO
,
1577 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1578 wpa_ssid_txt(ssid
->ssid
,
1582 #endif /* !CONFIG_IBSS_RSN */
1583 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1584 ssid
->mode
== IEEE80211_MODE_AP
||
1585 ssid
->mode
== IEEE80211_MODE_MESH
)
1593 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1594 * on BSS added and BSS changed events */
1595 static void wpa_supplicant_rsn_preauth_scan_results(
1596 struct wpa_supplicant
*wpa_s
)
1598 struct wpa_bss
*bss
;
1600 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1603 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1604 const u8
*ssid
, *rsn
;
1606 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1610 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1614 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1620 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1621 struct wpa_bss
*selected
,
1622 struct wpa_ssid
*ssid
)
1624 struct wpa_bss
*current_bss
= NULL
;
1625 #ifndef CONFIG_NO_ROAMING
1628 int cur_est
, sel_est
;
1629 #endif /* CONFIG_NO_ROAMING */
1631 if (wpa_s
->reassociate
)
1632 return 1; /* explicit request to reassociate */
1633 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1634 return 1; /* we are not associated; continue */
1635 if (wpa_s
->current_ssid
== NULL
)
1636 return 1; /* unknown current SSID */
1637 if (wpa_s
->current_ssid
!= ssid
)
1638 return 1; /* different network block */
1640 if (wpas_driver_bss_selection(wpa_s
))
1641 return 0; /* Driver-based roaming */
1643 if (wpa_s
->current_ssid
->ssid
)
1644 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1645 wpa_s
->current_ssid
->ssid
,
1646 wpa_s
->current_ssid
->ssid_len
);
1648 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1651 return 1; /* current BSS not seen in scan results */
1653 if (current_bss
== selected
)
1656 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1657 return 1; /* current BSS not seen in the last scan */
1659 #ifndef CONFIG_NO_ROAMING
1660 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1661 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1662 " freq=%d level=%d snr=%d est_throughput=%u",
1663 MAC2STR(current_bss
->bssid
),
1664 current_bss
->freq
, current_bss
->level
,
1665 current_bss
->snr
, current_bss
->est_throughput
);
1666 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1667 " freq=%d level=%d snr=%d est_throughput=%u",
1668 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1669 selected
->snr
, selected
->est_throughput
);
1671 if (wpa_s
->current_ssid
->bssid_set
&&
1672 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1674 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1675 "has preferred BSSID");
1679 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1680 wpa_dbg(wpa_s
, MSG_DEBUG
,
1681 "Allow reassociation - selected BSS has better estimated throughput");
1685 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1687 if (current_bss
->level
< 0 &&
1688 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1689 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1694 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1695 wpa_dbg(wpa_s
, MSG_DEBUG
,
1696 "Skip roam - Current BSS has better estimated throughput");
1700 cur_est
= current_bss
->est_throughput
;
1701 sel_est
= selected
->est_throughput
;
1703 if (current_bss
->level
< 0) {
1704 if (current_bss
->level
< -85)
1706 else if (current_bss
->level
< -80)
1708 else if (current_bss
->level
< -75)
1710 else if (current_bss
->level
< -70)
1714 if (cur_est
> sel_est
* 1.5)
1716 else if (cur_est
> sel_est
* 1.2)
1718 else if (cur_est
> sel_est
* 1.1)
1720 else if (cur_est
> sel_est
)
1726 /* Make it easier to move to 5 GHz band */
1727 if (sel_est
> cur_est
* 1.5)
1729 else if (sel_est
> cur_est
* 1.2)
1731 else if (sel_est
> cur_est
* 1.1)
1734 if (min_diff
> reduce
)
1739 diff
= abs(current_bss
->level
- selected
->level
);
1740 if (diff
< min_diff
) {
1741 wpa_dbg(wpa_s
, MSG_DEBUG
,
1742 "Skip roam - too small difference in signal level (%d < %d)",
1747 wpa_dbg(wpa_s
, MSG_DEBUG
,
1748 "Allow reassociation due to difference in signal level (%d >= %d)",
1751 #else /* CONFIG_NO_ROAMING */
1753 #endif /* CONFIG_NO_ROAMING */
1758 * Return a negative value if no scan results could be fetched or if scan
1759 * results should not be shared with other virtual interfaces.
1760 * Return 0 if scan results were fetched and may be shared with other
1762 * Return 1 if scan results may be shared with other virtual interfaces but may
1763 * not trigger any operations.
1764 * Return 2 if the interface was removed and cannot be used.
1766 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1767 union wpa_event_data
*data
,
1768 int own_request
, int update_only
)
1770 struct wpa_scan_results
*scan_res
= NULL
;
1773 #ifndef CONFIG_NO_RANDOM_POOL
1775 #endif /* CONFIG_NO_RANDOM_POOL */
1778 if (wpa_s
->ap_iface
)
1780 #endif /* CONFIG_AP */
1782 wpa_supplicant_notify_scanning(wpa_s
, 0);
1784 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1785 data
? &data
->scan_info
:
1787 if (scan_res
== NULL
) {
1788 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1789 wpa_s
->scan_res_handler
== scan_only_handler
)
1793 if (data
&& data
->scan_info
.external_scan
)
1795 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1797 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1799 goto scan_work_done
;
1802 #ifndef CONFIG_NO_RANDOM_POOL
1803 num
= scan_res
->num
;
1806 for (i
= 0; i
< num
; i
++) {
1808 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1809 buf
[0] = res
->bssid
[5];
1810 buf
[1] = res
->qual
& 0xff;
1811 buf
[2] = res
->noise
& 0xff;
1812 buf
[3] = res
->level
& 0xff;
1813 buf
[4] = res
->tsf
& 0xff;
1814 random_add_randomness(buf
, sizeof(buf
));
1816 #endif /* CONFIG_NO_RANDOM_POOL */
1820 goto scan_work_done
;
1823 if (own_request
&& wpa_s
->scan_res_handler
&&
1824 !(data
&& data
->scan_info
.external_scan
)) {
1825 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1826 struct wpa_scan_results
*scan_res
);
1828 scan_res_handler
= wpa_s
->scan_res_handler
;
1829 wpa_s
->scan_res_handler
= NULL
;
1830 scan_res_handler(wpa_s
, scan_res
);
1832 goto scan_work_done
;
1836 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1838 if (wpa_s
->ap_iface
->scan_cb
)
1839 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1840 #endif /* CONFIG_AP */
1841 goto scan_work_done
;
1844 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1845 wpa_s
->own_scan_running
,
1846 data
? data
->scan_info
.external_scan
: 0);
1847 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1848 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1849 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1850 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1851 wpa_s
->manual_scan_id
);
1852 wpa_s
->manual_scan_use_id
= 0;
1854 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1856 wpas_notify_scan_results(wpa_s
);
1858 wpas_notify_scan_done(wpa_s
, 1);
1860 if (data
&& data
->scan_info
.external_scan
) {
1861 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1862 wpa_scan_results_free(scan_res
);
1866 if (wnm_scan_process(wpa_s
, 1) > 0)
1867 goto scan_work_done
;
1869 if (sme_proc_obss_scan(wpa_s
) > 0)
1870 goto scan_work_done
;
1873 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1874 goto scan_work_done
;
1876 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1877 goto scan_work_done
;
1879 if (autoscan_notify_scan(wpa_s
, scan_res
))
1880 goto scan_work_done
;
1882 if (wpa_s
->disconnected
) {
1883 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1884 goto scan_work_done
;
1887 if (!wpas_driver_bss_selection(wpa_s
) &&
1888 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1889 goto scan_work_done
;
1891 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1893 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1894 wpa_s
->wpa_state
< WPA_COMPLETED
)
1895 goto scan_work_done
;
1897 wpa_scan_results_free(scan_res
);
1899 if (own_request
&& wpa_s
->scan_work
) {
1900 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1901 wpa_s
->scan_work
= NULL
;
1902 radio_work_done(work
);
1905 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1908 wpa_scan_results_free(scan_res
);
1909 if (own_request
&& wpa_s
->scan_work
) {
1910 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1911 wpa_s
->scan_work
= NULL
;
1912 radio_work_done(work
);
1918 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1919 int new_scan
, int own_request
)
1921 struct wpa_bss
*selected
;
1922 struct wpa_ssid
*ssid
= NULL
;
1923 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1925 if (time_to_reenable
> 0) {
1926 wpa_dbg(wpa_s
, MSG_DEBUG
,
1927 "Postpone network selection by %d seconds since all networks are disabled",
1929 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1930 eloop_register_timeout(time_to_reenable
, 0,
1931 wpas_network_reenabled
, wpa_s
, NULL
);
1935 if (wpa_s
->p2p_mgmt
)
1936 return 0; /* no normal connection on p2p_mgmt interface */
1938 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1942 wpa_msg(wpa_s
, MSG_INFO
,
1943 "Avoiding join because we already joined a mesh group");
1946 #endif /* CONFIG_MESH */
1950 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1953 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1957 if (ssid
!= wpa_s
->current_ssid
&&
1958 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1959 wpa_s
->own_disconnect_req
= 1;
1960 wpa_supplicant_deauthenticate(
1961 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1964 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1965 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1969 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1971 * Do not allow other virtual radios to trigger operations based
1972 * on these scan results since we do not want them to start
1973 * other associations at the same time.
1977 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1978 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1980 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1981 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1983 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1984 } else if (own_request
) {
1986 * No SSID found. If SCAN results are as a result of
1987 * own scan request and not due to a scan request on
1988 * another shared interface, try another scan.
1990 int timeout_sec
= wpa_s
->scan_interval
;
1991 int timeout_usec
= 0;
1995 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
2001 if (wpa_s
->p2p_in_provisioning
||
2002 wpa_s
->show_group_started
||
2003 wpa_s
->p2p_in_invitation
) {
2005 * Use shorter wait during P2P Provisioning
2006 * state and during P2P join-a-group operation
2007 * to speed up group formation.
2010 timeout_usec
= 250000;
2011 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2015 #endif /* CONFIG_P2P */
2016 #ifdef CONFIG_INTERWORKING
2017 if (wpa_s
->conf
->auto_interworking
&&
2018 wpa_s
->conf
->interworking
&&
2019 wpa_s
->conf
->cred
) {
2020 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2021 "start ANQP fetch since no matching "
2023 wpa_s
->network_select
= 1;
2024 wpa_s
->auto_network_select
= 1;
2025 interworking_start_fetch_anqp(wpa_s
);
2028 #endif /* CONFIG_INTERWORKING */
2030 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2031 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2033 timeout_usec
= 500000;
2034 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2038 #endif /* CONFIG_WPS */
2039 if (wpa_supplicant_req_sched_scan(wpa_s
))
2040 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2043 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2044 WPA_EVENT_NETWORK_NOT_FOUND
);
2051 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2052 union wpa_event_data
*data
)
2054 struct wpa_supplicant
*ifs
;
2057 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2060 * Interface may have been removed, so must not dereference
2068 * If no scan results could be fetched, then no need to
2069 * notify those interfaces that did not actually request
2070 * this scan. Similarly, if scan results started a new operation on this
2071 * interface, do not notify other interfaces to avoid concurrent
2072 * operations during a connection attempt.
2078 * Check other interfaces to see if they share the same radio. If
2079 * so, they get updated with this same scan info.
2081 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2084 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2085 "sibling", ifs
->ifname
);
2086 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2096 #endif /* CONFIG_NO_SCAN_PROCESSING */
2099 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2101 #ifdef CONFIG_NO_SCAN_PROCESSING
2103 #else /* CONFIG_NO_SCAN_PROCESSING */
2104 struct os_reltime now
;
2106 wpa_s
->ignore_post_flush_scan_res
= 0;
2108 if (wpa_s
->last_scan_res_used
== 0)
2111 os_get_reltime(&now
);
2112 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2113 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2117 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2118 #endif /* CONFIG_NO_SCAN_PROCESSING */
2123 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2125 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2127 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2130 if (!wpa_s
->no_keep_alive
) {
2131 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2132 MAC2STR(wpa_s
->bssid
));
2133 /* TODO: could skip this if normal data traffic has been sent */
2134 /* TODO: Consider using some more appropriate data frame for
2137 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2142 if (wpa_s
->sme
.bss_max_idle_period
) {
2144 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2147 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2148 wnm_bss_keep_alive
, wpa_s
, NULL
);
2150 #endif /* CONFIG_SME */
2154 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2155 const u8
*ies
, size_t ies_len
)
2157 struct ieee802_11_elems elems
;
2162 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2166 if (elems
.bss_max_idle_period
) {
2168 wpa_s
->sme
.bss_max_idle_period
=
2169 WPA_GET_LE16(elems
.bss_max_idle_period
);
2170 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2171 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2172 (elems
.bss_max_idle_period
[2] & 0x01) ?
2173 " (protected keep-live required)" : "");
2174 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2175 wpa_s
->sme
.bss_max_idle_period
= 1;
2176 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2177 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2178 /* msec times 1000 */
2179 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2182 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2183 wnm_bss_keep_alive
, wpa_s
,
2187 #endif /* CONFIG_SME */
2190 #endif /* CONFIG_WNM */
2193 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2196 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2197 #endif /* CONFIG_WNM */
2201 #ifdef CONFIG_INTERWORKING
2203 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2208 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2209 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2211 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2218 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2219 const u8
*ies
, size_t ies_len
)
2221 struct ieee802_11_elems elems
;
2226 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2229 if (elems
.qos_map_set
) {
2230 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2231 elems
.qos_map_set_len
);
2235 #endif /* CONFIG_INTERWORKING */
2239 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2240 const u8
*ie
, size_t ie_len
)
2242 struct mb_ies_info mb_ies
;
2244 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2247 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2249 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2254 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2259 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2260 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2261 (unsigned int) len
);
2262 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2263 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2271 if (mb_ies
.nof_ies
> 0) {
2272 wpabuf_free(wpa_s
->received_mb_ies
);
2273 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2279 #endif /* CONFIG_FST */
2282 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2283 union wpa_event_data
*data
)
2285 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2287 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2289 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2291 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2292 if (data
->assoc_info
.req_ies
)
2293 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2294 data
->assoc_info
.req_ies_len
);
2295 if (data
->assoc_info
.resp_ies
) {
2296 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2297 data
->assoc_info
.resp_ies_len
);
2299 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2300 data
->assoc_info
.resp_ies_len
);
2301 #endif /* CONFIG_TDLS */
2303 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2304 data
->assoc_info
.resp_ies_len
);
2305 #endif /* CONFIG_WNM */
2306 #ifdef CONFIG_INTERWORKING
2307 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2308 data
->assoc_info
.resp_ies_len
);
2309 #endif /* CONFIG_INTERWORKING */
2310 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2311 get_ie(data
->assoc_info
.resp_ies
,
2312 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2313 wpa_s
->ieee80211ac
= 1;
2315 if (data
->assoc_info
.beacon_ies
)
2316 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2317 data
->assoc_info
.beacon_ies
,
2318 data
->assoc_info
.beacon_ies_len
);
2319 if (data
->assoc_info
.freq
)
2320 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2321 data
->assoc_info
.freq
);
2323 p
= data
->assoc_info
.req_ies
;
2324 l
= data
->assoc_info
.req_ies_len
;
2326 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2327 while (p
&& l
>= 2) {
2330 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2334 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2335 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2336 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2337 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2338 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2339 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2342 wpa_find_assoc_pmkid(wpa_s
);
2348 if (!found
&& data
->assoc_info
.req_ies
)
2349 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2353 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2354 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2355 (!data
->assoc_info
.resp_frame
||
2356 fils_process_assoc_resp(wpa_s
->wpa
,
2357 data
->assoc_info
.resp_frame
,
2358 data
->assoc_info
.resp_frame_len
) < 0)) {
2359 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2362 #endif /* CONFIG_SME */
2364 /* Additional processing for FILS when SME is in driver */
2365 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2366 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2367 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2368 #endif /* CONFIG_FILS */
2371 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2372 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2373 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2374 data
->assoc_info
.resp_ies
,
2375 data
->assoc_info
.resp_ies_len
) < 0)) {
2376 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2379 #endif /* CONFIG_OWE */
2381 #ifdef CONFIG_IEEE80211R
2383 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2384 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2385 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2386 data
->assoc_info
.resp_ies
,
2387 data
->assoc_info
.resp_ies_len
,
2389 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2390 "Reassociation Response failed");
2391 wpa_supplicant_deauthenticate(
2392 wpa_s
, WLAN_REASON_INVALID_IE
);
2397 p
= data
->assoc_info
.resp_ies
;
2398 l
= data
->assoc_info
.resp_ies_len
;
2400 #ifdef CONFIG_WPS_STRICT
2401 if (p
&& wpa_s
->current_ssid
&&
2402 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2404 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2406 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2407 "include WPS IE in (Re)Association Response");
2411 if (wps_validate_assoc_resp(wps
) < 0) {
2413 wpa_supplicant_deauthenticate(
2414 wpa_s
, WLAN_REASON_INVALID_IE
);
2419 #endif /* CONFIG_WPS_STRICT */
2421 /* Go through the IEs and make a copy of the MDIE, if present. */
2422 while (p
&& l
>= 2) {
2425 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2429 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2430 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2431 wpa_s
->sme
.ft_used
= 1;
2432 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2433 MOBILITY_DOMAIN_ID_LEN
);
2439 #endif /* CONFIG_SME */
2441 /* Process FT when SME is in the driver */
2442 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2443 wpa_ft_is_completed(wpa_s
->wpa
)) {
2444 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2445 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2446 data
->assoc_info
.resp_ies
,
2447 data
->assoc_info
.resp_ies_len
,
2449 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2450 "Reassociation Response failed");
2451 wpa_supplicant_deauthenticate(
2452 wpa_s
, WLAN_REASON_INVALID_IE
);
2455 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2458 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2459 data
->assoc_info
.resp_ies_len
);
2460 #endif /* CONFIG_IEEE80211R */
2462 /* WPA/RSN IE from Beacon/ProbeResp */
2463 p
= data
->assoc_info
.beacon_ies
;
2464 l
= data
->assoc_info
.beacon_ies_len
;
2466 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2468 wpa_found
= rsn_found
= 0;
2469 while (p
&& l
>= 2) {
2472 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2477 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2478 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2480 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2484 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2486 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2493 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2494 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2495 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2496 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2497 if (wpa_found
|| rsn_found
)
2498 wpa_s
->ap_ies_from_associnfo
= 1;
2500 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2501 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2502 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2504 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2505 wpa_supplicant_update_scan_results(wpa_s
);
2508 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2514 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2516 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2518 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2521 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2524 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2525 WPA_IE_VENDOR_TYPE
);
2526 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2528 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2529 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2530 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2531 bss_rsn
? 2 + bss_rsn
[1] : 0))
2538 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2539 union wpa_event_data
*data
)
2542 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2543 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2544 const u8
*ieprb
, *iebcn
;
2546 wpabuf_free(wpa_s
->received_mb_ies
);
2547 wpa_s
->received_mb_ies
= NULL
;
2550 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2551 wpa_printf(MSG_DEBUG
,
2552 "FST: MB IEs updated from Association Response frame");
2557 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2558 wpa_printf(MSG_DEBUG
,
2559 "FST: MB IEs updated from association event Beacon IEs");
2566 ieprb
= (const u8
*) (bss
+ 1);
2567 iebcn
= ieprb
+ bss
->ie_len
;
2569 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2570 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2571 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2572 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2573 #endif /* CONFIG_FST */
2577 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2578 union wpa_event_data
*data
)
2581 int ft_completed
, already_authorized
;
2585 if (wpa_s
->ap_iface
) {
2588 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2589 data
->assoc_info
.addr
,
2590 data
->assoc_info
.req_ies
,
2591 data
->assoc_info
.req_ies_len
,
2592 data
->assoc_info
.reassoc
);
2595 #endif /* CONFIG_AP */
2597 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2599 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2600 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2603 * FILS authentication can share the same mechanism to mark the
2604 * connection fully authenticated, so set ft_completed also based on
2608 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2610 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2611 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2612 wpa_supplicant_deauthenticate(
2613 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2617 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2618 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2619 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2620 MACSTR
, MAC2STR(bssid
));
2622 random_add_randomness(bssid
, ETH_ALEN
);
2623 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2624 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2625 wpas_notify_bssid_changed(wpa_s
);
2627 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2628 wpa_clear_keys(wpa_s
, bssid
);
2630 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2631 wpa_supplicant_deauthenticate(
2632 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2637 if (wpa_s
->conf
->ap_scan
== 1 &&
2638 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2639 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2640 wpa_msg(wpa_s
, MSG_WARNING
,
2641 "WPA/RSN IEs not updated");
2644 wpas_fst_update_mb_assoc(wpa_s
, data
);
2647 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2648 wpa_s
->sme
.prev_bssid_set
= 1;
2649 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2650 #endif /* CONFIG_SME */
2652 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2653 if (wpa_s
->current_ssid
) {
2654 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2655 * initialized before association, but for other modes,
2656 * initialize PC/SC here, if the current configuration needs
2657 * smartcard or SIM/USIM. */
2658 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2660 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2662 l2_packet_notify_auth_start(wpa_s
->l2
);
2664 already_authorized
= data
&& data
->assoc_info
.authorized
;
2667 * Set portEnabled first to FALSE in order to get EAP state machine out
2668 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2669 * state machine may transit to AUTHENTICATING state based on obsolete
2670 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2671 * AUTHENTICATED without ever giving chance to EAP state machine to
2674 if (!ft_completed
&& !already_authorized
) {
2675 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2676 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2678 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2679 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2680 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2682 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2683 /* 802.1X::portControl = Auto */
2684 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2685 wpa_s
->eapol_received
= 0;
2686 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2687 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2688 (wpa_s
->current_ssid
&&
2689 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2690 if (wpa_s
->current_ssid
&&
2691 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2693 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2695 * Set the key after having received joined-IBSS event
2698 wpa_supplicant_set_wpa_none_key(wpa_s
,
2699 wpa_s
->current_ssid
);
2701 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2702 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2703 } else if (!ft_completed
) {
2704 /* Timeout for receiving the first EAPOL packet */
2705 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2707 wpa_supplicant_cancel_scan(wpa_s
);
2709 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2710 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2712 * We are done; the driver will take care of RSN 4-way
2715 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2716 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2717 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2718 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2719 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2720 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2722 * The driver will take care of RSN 4-way handshake, so we need
2723 * to allow EAPOL supplicant to complete its work without
2724 * waiting for WPA supplicant.
2726 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2727 } else if (ft_completed
) {
2729 * FT protocol completed - make sure EAPOL state machine ends
2730 * up in authenticated.
2732 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2733 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2734 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2735 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2738 wpa_s
->last_eapol_matches_bssid
= 0;
2740 if (wpa_s
->pending_eapol_rx
) {
2741 struct os_reltime now
, age
;
2742 os_get_reltime(&now
);
2743 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2744 if (age
.sec
== 0 && age
.usec
< 200000 &&
2745 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2747 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2748 "frame that was received just before "
2749 "association notification");
2750 wpa_supplicant_rx_eapol(
2751 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2752 wpabuf_head(wpa_s
->pending_eapol_rx
),
2753 wpabuf_len(wpa_s
->pending_eapol_rx
));
2755 wpabuf_free(wpa_s
->pending_eapol_rx
);
2756 wpa_s
->pending_eapol_rx
= NULL
;
2759 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2760 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2761 wpa_s
->current_ssid
&&
2762 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2763 /* Set static WEP keys again */
2764 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2767 #ifdef CONFIG_IBSS_RSN
2768 if (wpa_s
->current_ssid
&&
2769 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2770 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2771 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2772 wpa_s
->ibss_rsn
== NULL
) {
2773 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2774 if (!wpa_s
->ibss_rsn
) {
2775 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2776 wpa_supplicant_deauthenticate(
2777 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2781 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2783 #endif /* CONFIG_IBSS_RSN */
2785 wpas_wps_notify_assoc(wpa_s
, bssid
);
2788 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2789 data
->assoc_info
.resp_ies_len
,
2790 &data
->assoc_info
.wmm_params
);
2792 if (wpa_s
->reassoc_same_bss
)
2793 wmm_ac_restore_tspecs(wpa_s
);
2797 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2798 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2799 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2802 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2804 #endif /* CONFIG_FILS */
2808 static int disconnect_reason_recoverable(u16 reason_code
)
2810 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2811 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2812 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2816 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2818 int locally_generated
)
2822 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2824 * At least Host AP driver and a Prism3 card seemed to be
2825 * generating streams of disconnected events when configuring
2826 * IBSS for WPA-None. Ignore them for now.
2831 bssid
= wpa_s
->bssid
;
2832 if (is_zero_ether_addr(bssid
))
2833 bssid
= wpa_s
->pending_bssid
;
2835 if (!is_zero_ether_addr(bssid
) ||
2836 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2837 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2839 MAC2STR(bssid
), reason_code
,
2840 locally_generated
? " locally_generated=1" : "");
2845 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2846 int locally_generated
)
2848 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2849 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2850 return 0; /* Not in 4-way handshake with PSK */
2853 * It looks like connection was lost while trying to go through PSK
2854 * 4-way handshake. Filter out known disconnection cases that are caused
2855 * by something else than PSK mismatch to avoid confusing reports.
2858 if (locally_generated
) {
2859 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2867 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2869 int locally_generated
)
2873 u8 prev_pending_bssid
[ETH_ALEN
];
2874 struct wpa_bss
*fast_reconnect
= NULL
;
2875 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2876 struct wpa_ssid
*last_ssid
;
2877 struct wpa_bss
*curr
= NULL
;
2879 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2880 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2882 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2884 * At least Host AP driver and a Prism3 card seemed to be
2885 * generating streams of disconnected events when configuring
2886 * IBSS for WPA-None. Ignore them for now.
2888 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2889 "IBSS/WPA-None mode");
2893 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2894 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2897 * Remove the inactive AP (which is probably out of range) from
2898 * the BSS list after marking disassociation. In particular
2899 * mac80211-based drivers use the
2900 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2901 * locally generated disconnection events for cases where the
2902 * AP does not reply anymore.
2904 curr
= wpa_s
->current_bss
;
2906 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2907 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2908 "pre-shared key may be incorrect");
2909 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2910 return; /* P2P group removed */
2911 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2913 if (!wpa_s
->disconnected
&&
2914 (!wpa_s
->auto_reconnect_disabled
||
2915 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2916 wpas_wps_searching(wpa_s
) ||
2917 wpas_wps_reenable_networks_pending(wpa_s
))) {
2918 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2919 "reconnect (wps=%d/%d wpa_state=%d)",
2920 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2921 wpas_wps_searching(wpa_s
),
2923 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2924 wpa_s
->current_ssid
&&
2925 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2926 !locally_generated
&&
2927 disconnect_reason_recoverable(reason_code
)) {
2929 * It looks like the AP has dropped association with
2930 * us, but could allow us to get back in. Try to
2931 * reconnect to the same BSS without full scan to save
2932 * time for some common cases.
2934 fast_reconnect
= wpa_s
->current_bss
;
2935 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2936 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2937 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2939 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2942 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2943 "try to re-connect");
2944 wpa_s
->reassociate
= 0;
2945 wpa_s
->disconnected
= 1;
2947 wpa_supplicant_cancel_sched_scan(wpa_s
);
2949 bssid
= wpa_s
->bssid
;
2950 if (is_zero_ether_addr(bssid
))
2951 bssid
= wpa_s
->pending_bssid
;
2952 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2953 wpas_connection_failed(wpa_s
, bssid
);
2954 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2955 if (locally_generated
)
2956 wpa_s
->disconnect_reason
= -reason_code
;
2958 wpa_s
->disconnect_reason
= reason_code
;
2959 wpas_notify_disconnect_reason(wpa_s
);
2960 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2961 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2962 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2964 last_ssid
= wpa_s
->current_ssid
;
2965 wpa_supplicant_mark_disassoc(wpa_s
);
2968 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2970 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2971 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2972 wpa_s
->current_ssid
= last_ssid
;
2975 if (fast_reconnect
&&
2976 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2977 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2978 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2979 fast_reconnect
->ssid_len
) &&
2980 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2981 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2982 #ifndef CONFIG_NO_SCAN_PROCESSING
2983 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2984 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2985 fast_reconnect_ssid
) < 0) {
2986 /* Recover through full scan */
2987 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2989 #endif /* CONFIG_NO_SCAN_PROCESSING */
2990 } else if (fast_reconnect
) {
2992 * Could not reconnect to the same BSS due to network being
2993 * disabled. Use a new scan to match the alternative behavior
2994 * above, i.e., to continue automatic reconnection attempt in a
2995 * way that enforces disabled network rules.
2997 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3002 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3003 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
3005 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3007 if (!wpa_s
->pending_mic_error_report
)
3010 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3011 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3012 wpa_s
->pending_mic_error_report
= 0;
3014 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3018 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3019 union wpa_event_data
*data
)
3022 struct os_reltime t
;
3024 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3025 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3027 if ((wpa_s
->last_michael_mic_error
.sec
&&
3028 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3029 wpa_s
->pending_mic_error_report
) {
3030 if (wpa_s
->pending_mic_error_report
) {
3032 * Send the pending MIC error report immediately since
3033 * we are going to start countermeasures and AP better
3036 wpa_sm_key_request(wpa_s
->wpa
, 1,
3037 wpa_s
->pending_mic_error_pairwise
);
3040 /* Send the new MIC error report immediately since we are going
3041 * to start countermeasures and AP better do the same.
3043 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3045 /* initialize countermeasures */
3046 wpa_s
->countermeasures
= 1;
3048 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3050 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3053 * Need to wait for completion of request frame. We do not get
3054 * any callback for the message completion, so just wait a
3055 * short while and hope for the best. */
3058 wpa_drv_set_countermeasures(wpa_s
, 1);
3059 wpa_supplicant_deauthenticate(wpa_s
,
3060 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3061 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3063 eloop_register_timeout(60, 0,
3064 wpa_supplicant_stop_countermeasures
,
3066 /* TODO: mark the AP rejected for 60 second. STA is
3067 * allowed to associate with another AP.. */
3069 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3070 if (wpa_s
->mic_errors_seen
) {
3072 * Reduce the effectiveness of Michael MIC error
3073 * reports as a means for attacking against TKIP if
3074 * more than one MIC failure is noticed with the same
3075 * PTK. We delay the transmission of the reports by a
3076 * random time between 0 and 60 seconds in order to
3077 * force the attacker wait 60 seconds before getting
3078 * the information on whether a frame resulted in a MIC
3084 if (os_get_random(rval
, sizeof(rval
)) < 0)
3085 sec
= os_random() % 60;
3087 sec
= WPA_GET_BE32(rval
) % 60;
3088 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3089 "report %d seconds", sec
);
3090 wpa_s
->pending_mic_error_report
= 1;
3091 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3092 eloop_cancel_timeout(
3093 wpa_supplicant_delayed_mic_error_report
,
3095 eloop_register_timeout(
3096 sec
, os_random() % 1000000,
3097 wpa_supplicant_delayed_mic_error_report
,
3100 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3102 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3103 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3104 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3106 wpa_s
->last_michael_mic_error
= t
;
3107 wpa_s
->mic_errors_seen
++;
3111 #ifdef CONFIG_TERMINATE_ONLASTIF
3112 static int any_interfaces(struct wpa_supplicant
*head
)
3114 struct wpa_supplicant
*wpa_s
;
3116 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3117 if (!wpa_s
->interface_removed
)
3121 #endif /* CONFIG_TERMINATE_ONLASTIF */
3125 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3126 union wpa_event_data
*data
)
3128 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3131 switch (data
->interface_status
.ievent
) {
3132 case EVENT_INTERFACE_ADDED
:
3133 if (!wpa_s
->interface_removed
)
3135 wpa_s
->interface_removed
= 0;
3136 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3137 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3138 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3139 "driver after interface was added");
3143 if (!wpa_s
->global
->p2p
&&
3144 !wpa_s
->global
->p2p_disabled
&&
3145 !wpa_s
->conf
->p2p_disabled
&&
3147 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3148 wpas_p2p_add_p2pdev_interface(
3149 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3150 wpa_printf(MSG_INFO
,
3151 "P2P: Failed to enable P2P Device interface");
3152 /* Try to continue without. P2P will be disabled. */
3154 #endif /* CONFIG_P2P */
3157 case EVENT_INTERFACE_REMOVED
:
3158 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3159 wpa_s
->interface_removed
= 1;
3160 wpa_supplicant_mark_disassoc(wpa_s
);
3161 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3162 l2_packet_deinit(wpa_s
->l2
);
3166 if (wpa_s
->global
->p2p
&&
3167 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3169 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3170 wpa_dbg(wpa_s
, MSG_DEBUG
,
3171 "Removing P2P Device interface");
3172 wpa_supplicant_remove_iface(
3173 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3175 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3177 #endif /* CONFIG_P2P */
3179 #ifdef CONFIG_MATCH_IFACE
3180 if (wpa_s
->matched
) {
3181 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3184 #endif /* CONFIG_MATCH_IFACE */
3186 #ifdef CONFIG_TERMINATE_ONLASTIF
3187 /* check if last interface */
3188 if (!any_interfaces(wpa_s
->global
->ifaces
))
3190 #endif /* CONFIG_TERMINATE_ONLASTIF */
3197 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3198 union wpa_event_data
*data
)
3202 switch (data
->tdls
.oper
) {
3203 case TDLS_REQUEST_SETUP
:
3204 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3205 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3206 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3208 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3210 case TDLS_REQUEST_TEARDOWN
:
3211 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3212 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3213 data
->tdls
.reason_code
);
3215 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3218 case TDLS_REQUEST_DISCOVER
:
3219 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3224 #endif /* CONFIG_TDLS */
3228 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3229 union wpa_event_data
*data
)
3233 switch (data
->wnm
.oper
) {
3234 case WNM_OPER_SLEEP
:
3235 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3236 "(action=%d, intval=%d)",
3237 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3238 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3239 data
->wnm
.sleep_intval
, NULL
);
3243 #endif /* CONFIG_WNM */
3246 #ifdef CONFIG_IEEE80211R
3248 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3249 union wpa_event_data
*data
)
3254 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3255 data
->ft_ies
.ies_len
,
3256 data
->ft_ies
.ft_action
,
3257 data
->ft_ies
.target_ap
,
3258 data
->ft_ies
.ric_ies
,
3259 data
->ft_ies
.ric_ies_len
) < 0) {
3260 /* TODO: prevent MLME/driver from trying to associate? */
3263 #endif /* CONFIG_IEEE80211R */
3266 #ifdef CONFIG_IBSS_RSN
3267 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3268 union wpa_event_data
*data
)
3270 struct wpa_ssid
*ssid
;
3271 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3275 ssid
= wpa_s
->current_ssid
;
3278 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3281 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3285 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3286 union wpa_event_data
*data
)
3288 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3293 /* check if the ssid is correctly configured as IBSS/RSN */
3294 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3297 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3298 data
->rx_mgmt
.frame_len
);
3300 #endif /* CONFIG_IBSS_RSN */
3303 #ifdef CONFIG_IEEE80211R
3304 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3307 const u8
*sta_addr
, *target_ap_addr
;
3310 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3311 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3312 return; /* only SME case supported for now */
3313 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3316 return; /* Only FT Action Response is supported for now */
3317 sta_addr
= data
+ 1;
3318 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3319 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3320 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3321 MACSTR
" TargetAP " MACSTR
" status %u",
3322 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3324 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3325 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3326 " in FT Action Response", MAC2STR(sta_addr
));
3331 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3332 "failure (status code %d)", status
);
3333 /* TODO: report error to FT code(?) */
3337 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3338 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3339 target_ap_addr
, NULL
, 0) < 0)
3344 struct wpa_bss
*bss
;
3345 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3347 wpa_s
->sme
.freq
= bss
->freq
;
3348 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3349 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3352 #endif /* CONFIG_SME */
3354 #endif /* CONFIG_IEEE80211R */
3357 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3358 struct unprot_deauth
*e
)
3360 #ifdef CONFIG_IEEE80211W
3361 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3362 "dropped: " MACSTR
" -> " MACSTR
3363 " (reason code %u)",
3364 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3365 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3366 #endif /* CONFIG_IEEE80211W */
3370 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3371 struct unprot_disassoc
*e
)
3373 #ifdef CONFIG_IEEE80211W
3374 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3375 "dropped: " MACSTR
" -> " MACSTR
3376 " (reason code %u)",
3377 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3378 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3379 #endif /* CONFIG_IEEE80211W */
3383 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3384 u16 reason_code
, int locally_generated
,
3385 const u8
*ie
, size_t ie_len
, int deauth
)
3388 if (wpa_s
->ap_iface
&& addr
) {
3389 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3393 if (wpa_s
->ap_iface
) {
3394 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3397 #endif /* CONFIG_AP */
3399 if (!locally_generated
)
3400 wpa_s
->own_disconnect_req
= 0;
3402 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3404 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3405 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3406 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3407 eapol_sm_failed(wpa_s
->eapol
))) &&
3408 !wpa_s
->eap_expected_failure
))
3409 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3412 if (deauth
&& reason_code
> 0) {
3413 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3414 locally_generated
) > 0) {
3416 * The interface was removed, so cannot continue
3417 * processing any additional operations after this.
3422 #endif /* CONFIG_P2P */
3424 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3429 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3430 struct disassoc_info
*info
)
3432 u16 reason_code
= 0;
3433 int locally_generated
= 0;
3434 const u8
*addr
= NULL
;
3435 const u8
*ie
= NULL
;
3438 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3443 ie_len
= info
->ie_len
;
3444 reason_code
= info
->reason_code
;
3445 locally_generated
= info
->locally_generated
;
3446 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3447 locally_generated
? " (locally generated)" : "");
3449 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3451 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3456 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3457 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3461 if (wpa_s
->ap_iface
) {
3462 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3465 #endif /* CONFIG_AP */
3469 wpas_p2p_disassoc_notif(
3470 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3473 #endif /* CONFIG_P2P */
3475 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3476 sme_event_disassoc(wpa_s
, info
);
3478 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3483 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3484 struct deauth_info
*info
)
3486 u16 reason_code
= 0;
3487 int locally_generated
= 0;
3488 const u8
*addr
= NULL
;
3489 const u8
*ie
= NULL
;
3492 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3497 ie_len
= info
->ie_len
;
3498 reason_code
= info
->reason_code
;
3499 locally_generated
= info
->locally_generated
;
3500 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3502 locally_generated
? " (locally generated)" : "");
3504 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3507 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3511 wpa_reset_ft_completed(wpa_s
->wpa
);
3513 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3514 locally_generated
, ie
, ie_len
, 1);
3518 static const char * reg_init_str(enum reg_change_initiator init
)
3521 case REGDOM_SET_BY_CORE
:
3523 case REGDOM_SET_BY_USER
:
3525 case REGDOM_SET_BY_DRIVER
:
3527 case REGDOM_SET_BY_COUNTRY_IE
:
3528 return "COUNTRY_IE";
3529 case REGDOM_BEACON_HINT
:
3530 return "BEACON_HINT";
3536 static const char * reg_type_str(enum reg_type type
)
3539 case REGDOM_TYPE_UNKNOWN
:
3541 case REGDOM_TYPE_COUNTRY
:
3543 case REGDOM_TYPE_WORLD
:
3545 case REGDOM_TYPE_CUSTOM_WORLD
:
3546 return "CUSTOM_WORLD";
3547 case REGDOM_TYPE_INTERSECTION
:
3548 return "INTERSECTION";
3554 static void wpa_supplicant_update_channel_list(
3555 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3557 struct wpa_supplicant
*ifs
;
3561 * To allow backwards compatibility with higher level layers that
3562 * assumed the REGDOM_CHANGE event is sent over the initially added
3563 * interface. Find the highest parent of this interface and use it to
3566 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3569 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3570 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3571 info
->alpha2
[0] ? " alpha2=" : "",
3572 info
->alpha2
[0] ? info
->alpha2
: "");
3574 if (wpa_s
->drv_priv
== NULL
)
3575 return; /* Ignore event during drv initialization */
3577 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3579 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3581 free_hw_features(ifs
);
3582 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3583 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3585 /* Restart PNO/sched_scan with updated channel list */
3588 wpas_start_pno(ifs
);
3589 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3590 wpa_dbg(ifs
, MSG_DEBUG
,
3591 "Channel list changed - restart sched_scan");
3592 wpas_scan_restart_sched_scan(ifs
);
3596 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3600 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3601 const u8
*frame
, size_t len
, int freq
,
3604 const struct ieee80211_mgmt
*mgmt
;
3609 if (len
< IEEE80211_HDRLEN
+ 2)
3612 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3613 payload
= frame
+ IEEE80211_HDRLEN
;
3614 category
= *payload
++;
3615 plen
= len
- IEEE80211_HDRLEN
- 1;
3617 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3618 " Category=%u DataLen=%d freq=%d MHz",
3619 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3621 if (category
== WLAN_ACTION_WMM
) {
3622 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3626 #ifdef CONFIG_IEEE80211R
3627 if (category
== WLAN_ACTION_FT
) {
3628 ft_rx_action(wpa_s
, payload
, plen
);
3631 #endif /* CONFIG_IEEE80211R */
3633 #ifdef CONFIG_IEEE80211W
3635 if (category
== WLAN_ACTION_SA_QUERY
) {
3636 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3639 #endif /* CONFIG_SME */
3640 #endif /* CONFIG_IEEE80211W */
3643 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3644 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3647 #endif /* CONFIG_WNM */
3650 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3651 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3652 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3653 mgmt
->u
.action
.category
,
3654 payload
, plen
, freq
) == 0)
3656 #endif /* CONFIG_GAS */
3658 #ifdef CONFIG_GAS_SERVER
3659 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3660 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3661 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3662 mgmt
->u
.action
.category
,
3663 payload
, plen
, freq
) == 0)
3665 #endif /* CONFIG_GAS_SERVER */
3668 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3669 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3670 wpa_dbg(wpa_s
, MSG_DEBUG
,
3671 "TDLS: Received Discovery Response from " MACSTR
,
3675 #endif /* CONFIG_TDLS */
3677 #ifdef CONFIG_INTERWORKING
3678 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3679 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3680 const u8
*pos
= payload
+ 1;
3681 size_t qlen
= plen
- 1;
3682 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3683 MACSTR
, MAC2STR(mgmt
->sa
));
3684 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3685 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3686 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3687 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3690 #endif /* CONFIG_INTERWORKING */
3692 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3693 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3694 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3701 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3702 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3703 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3707 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3708 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3709 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3710 payload
+ 1, plen
- 1,
3716 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3717 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3720 #endif /* CONFIG_FST */
3723 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3724 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3725 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3726 payload
[4] == DPP_OUI_TYPE
) {
3729 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3732 #endif /* CONFIG_DPP */
3734 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3735 category
, payload
, plen
, freq
);
3737 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3741 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3742 union wpa_event_data
*event
)
3744 struct wpa_freq_range_list
*list
;
3747 list
= &event
->freq_range
;
3750 str
= freq_range_list_str(list
);
3751 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3755 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3756 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3759 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3762 * The update channel flow will also take care of moving a GO
3763 * from the unsafe frequency if needed.
3765 wpas_p2p_update_channel_list(wpa_s
,
3766 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3768 #endif /* CONFIG_P2P */
3774 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
3776 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3777 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3778 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3779 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3780 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3785 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
3791 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
3792 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
3794 for (j
= 0; j
< mode
->num_channels
; j
++) {
3795 const struct hostapd_channel_data
*chan
;
3797 chan
= &mode
->channels
[j
];
3798 if (chan
->freq
== freq
)
3799 return chan
->dfs_cac_ms
;
3807 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
3808 struct dfs_event
*radar
)
3810 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3811 if (wpa_s
->ap_iface
) {
3812 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
3814 #endif /* NEED_AP_MLME && CONFIG_AP */
3816 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
3818 cac_time
/= 1000; /* convert from ms to sec */
3820 cac_time
= 10 * 60; /* max timeout: 10 minutes */
3822 /* Restart auth timeout: CAC time added to initial timeout */
3823 wpas_auth_timeout_restart(wpa_s
, cac_time
);
3828 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
3829 struct dfs_event
*radar
)
3831 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3832 if (wpa_s
->ap_iface
) {
3833 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
3835 #endif /* NEED_AP_MLME && CONFIG_AP */
3837 /* Restart auth timeout with original value after CAC is
3839 wpas_auth_timeout_restart(wpa_s
, 0);
3844 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
3845 struct dfs_event
*radar
)
3847 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3848 if (wpa_s
->ap_iface
) {
3849 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
3851 #endif /* NEED_AP_MLME && CONFIG_AP */
3853 /* Restart auth timeout with original value after CAC is
3855 wpas_auth_timeout_restart(wpa_s
, 0);
3860 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3861 union wpa_event_data
*data
)
3863 wpa_dbg(wpa_s
, MSG_DEBUG
,
3864 "Connection authorized by device, previous state %d",
3867 wpa_supplicant_event_port_authorized(wpa_s
);
3869 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3870 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3871 data
->assoc_info
.ptk_kck_len
,
3872 data
->assoc_info
.ptk_kek
,
3873 data
->assoc_info
.ptk_kek_len
);
3875 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3876 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3877 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3879 /* Update ERP next sequence number */
3880 eapol_sm_update_erp_next_seq_num(
3881 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3883 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3884 /* Add the new PMK and PMKID to the PMKSA cache */
3885 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3886 data
->assoc_info
.fils_pmk
,
3887 data
->assoc_info
.fils_pmk_len
,
3888 data
->assoc_info
.fils_pmkid
,
3889 wpa_s
->bssid
, fils_cache_id
);
3890 } else if (data
->assoc_info
.fils_pmkid
) {
3891 /* Update the current PMKSA used for this connection */
3892 pmksa_cache_set_current(wpa_s
->wpa
,
3893 data
->assoc_info
.fils_pmkid
,
3894 NULL
, NULL
, 0, NULL
, 0);
3897 #endif /* CONFIG_FILS */
3901 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
3902 union wpa_event_data
*data
)
3904 const u8
*bssid
= data
->assoc_reject
.bssid
;
3906 if (!bssid
|| is_zero_ether_addr(bssid
))
3907 bssid
= wpa_s
->pending_bssid
;
3909 if (data
->assoc_reject
.bssid
)
3910 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3911 "bssid=" MACSTR
" status_code=%u%s%s%s",
3912 MAC2STR(data
->assoc_reject
.bssid
),
3913 data
->assoc_reject
.status_code
,
3914 data
->assoc_reject
.timed_out
? " timeout" : "",
3915 data
->assoc_reject
.timeout_reason
? "=" : "",
3916 data
->assoc_reject
.timeout_reason
?
3917 data
->assoc_reject
.timeout_reason
: "");
3919 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3920 "status_code=%u%s%s%s",
3921 data
->assoc_reject
.status_code
,
3922 data
->assoc_reject
.timed_out
? " timeout" : "",
3923 data
->assoc_reject
.timeout_reason
? "=" : "",
3924 data
->assoc_reject
.timeout_reason
?
3925 data
->assoc_reject
.timeout_reason
: "");
3926 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3927 wpas_notify_assoc_status_code(wpa_s
);
3930 if (data
->assoc_reject
.status_code
==
3931 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
3932 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
3933 wpa_s
->current_ssid
&&
3934 wpa_s
->current_ssid
->owe_group
== 0 &&
3935 wpa_s
->last_owe_group
!= 21) {
3936 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3937 struct wpa_bss
*bss
= wpa_s
->current_bss
;
3940 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
3942 wpas_connection_failed(wpa_s
, bssid
);
3943 wpa_supplicant_mark_disassoc(wpa_s
);
3947 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
3948 wpas_connect_work_done(wpa_s
);
3949 wpa_supplicant_mark_disassoc(wpa_s
);
3950 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3953 #endif /* CONFIG_OWE */
3955 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
3956 sme_event_assoc_reject(wpa_s
, data
);
3960 /* Driver-based SME cases */
3963 if (wpa_s
->current_ssid
&&
3964 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
3965 !data
->assoc_reject
.timed_out
) {
3966 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
3967 wpa_sm_aborted_cached(wpa_s
->wpa
);
3968 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
3970 #endif /* CONFIG_SAE */
3973 /* Update ERP next sequence number */
3974 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3975 eapol_sm_update_erp_next_seq_num(
3977 data
->assoc_reject
.fils_erp_next_seq_num
);
3978 fils_connection_failure(wpa_s
);
3980 #endif /* CONFIG_FILS */
3982 wpas_connection_failed(wpa_s
, bssid
);
3983 wpa_supplicant_mark_disassoc(wpa_s
);
3987 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3988 union wpa_event_data
*data
)
3990 struct wpa_supplicant
*wpa_s
= ctx
;
3993 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3994 event
!= EVENT_INTERFACE_ENABLED
&&
3995 event
!= EVENT_INTERFACE_STATUS
&&
3996 event
!= EVENT_SCAN_RESULTS
&&
3997 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3998 wpa_dbg(wpa_s
, MSG_DEBUG
,
3999 "Ignore event %s (%d) while interface is disabled",
4000 event_to_string(event
), event
);
4004 #ifndef CONFIG_NO_STDOUT_DEBUG
4006 int level
= MSG_DEBUG
;
4008 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
4009 const struct ieee80211_hdr
*hdr
;
4011 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4012 fc
= le_to_host16(hdr
->frame_control
);
4013 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4014 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4015 level
= MSG_EXCESSIVE
;
4018 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4019 event_to_string(event
), event
);
4021 #endif /* CONFIG_NO_STDOUT_DEBUG */
4026 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4027 data
->auth
.ies_len
))
4028 wpa_printf(MSG_DEBUG
,
4029 "FST: MB IEs updated from auth IE");
4030 #endif /* CONFIG_FST */
4031 sme_event_auth(wpa_s
, data
);
4034 #ifdef CONFIG_TESTING_OPTIONS
4035 if (wpa_s
->ignore_auth_resp
) {
4036 wpa_printf(MSG_INFO
,
4037 "EVENT_ASSOC - ignore_auth_resp active!");
4040 if (wpa_s
->testing_resend_assoc
) {
4041 wpa_printf(MSG_INFO
,
4042 "EVENT_DEAUTH - testing_resend_assoc");
4045 #endif /* CONFIG_TESTING_OPTIONS */
4046 wpa_supplicant_event_assoc(wpa_s
, data
);
4048 (data
->assoc_info
.authorized
||
4049 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4050 wpa_fils_is_completed(wpa_s
->wpa
))))
4051 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4053 wpa_msg(wpa_s
, MSG_INFO
,
4054 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4055 data
->assoc_info
.subnet_status
);
4058 case EVENT_DISASSOC
:
4059 wpas_event_disassoc(wpa_s
,
4060 data
? &data
->disassoc_info
: NULL
);
4063 #ifdef CONFIG_TESTING_OPTIONS
4064 if (wpa_s
->ignore_auth_resp
) {
4065 wpa_printf(MSG_INFO
,
4066 "EVENT_DEAUTH - ignore_auth_resp active!");
4069 if (wpa_s
->testing_resend_assoc
) {
4070 wpa_printf(MSG_INFO
,
4071 "EVENT_DEAUTH - testing_resend_assoc");
4074 #endif /* CONFIG_TESTING_OPTIONS */
4075 wpas_event_deauth(wpa_s
,
4076 data
? &data
->deauth_info
: NULL
);
4078 case EVENT_MICHAEL_MIC_FAILURE
:
4079 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4081 #ifndef CONFIG_NO_SCAN_PROCESSING
4082 case EVENT_SCAN_STARTED
:
4083 if (wpa_s
->own_scan_requested
||
4084 (data
&& !data
->scan_info
.external_scan
)) {
4085 struct os_reltime diff
;
4087 os_get_reltime(&wpa_s
->scan_start_time
);
4088 os_reltime_sub(&wpa_s
->scan_start_time
,
4089 &wpa_s
->scan_trigger_time
, &diff
);
4090 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4091 diff
.sec
, diff
.usec
);
4092 wpa_s
->own_scan_requested
= 0;
4093 wpa_s
->own_scan_running
= 1;
4094 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4095 wpa_s
->manual_scan_use_id
) {
4096 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4097 WPA_EVENT_SCAN_STARTED
"id=%u",
4098 wpa_s
->manual_scan_id
);
4100 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4101 WPA_EVENT_SCAN_STARTED
);
4104 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4105 wpa_s
->radio
->external_scan_running
= 1;
4106 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4109 case EVENT_SCAN_RESULTS
:
4110 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4111 wpa_s
->scan_res_handler
= NULL
;
4112 wpa_s
->own_scan_running
= 0;
4113 wpa_s
->radio
->external_scan_running
= 0;
4114 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4118 if (!(data
&& data
->scan_info
.external_scan
) &&
4119 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4120 struct os_reltime now
, diff
;
4121 os_get_reltime(&now
);
4122 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4123 wpa_s
->scan_start_time
.sec
= 0;
4124 wpa_s
->scan_start_time
.usec
= 0;
4125 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4126 diff
.sec
, diff
.usec
);
4128 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4129 break; /* interface may have been removed */
4130 if (!(data
&& data
->scan_info
.external_scan
))
4131 wpa_s
->own_scan_running
= 0;
4132 if (data
&& data
->scan_info
.nl_scan_event
)
4133 wpa_s
->radio
->external_scan_running
= 0;
4134 radio_work_check_next(wpa_s
);
4136 #endif /* CONFIG_NO_SCAN_PROCESSING */
4137 case EVENT_ASSOCINFO
:
4138 wpa_supplicant_event_associnfo(wpa_s
, data
);
4140 case EVENT_INTERFACE_STATUS
:
4141 wpa_supplicant_event_interface_status(wpa_s
, data
);
4143 case EVENT_PMKID_CANDIDATE
:
4144 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4148 wpa_supplicant_event_tdls(wpa_s
, data
);
4150 #endif /* CONFIG_TDLS */
4153 wpa_supplicant_event_wnm(wpa_s
, data
);
4155 #endif /* CONFIG_WNM */
4156 #ifdef CONFIG_IEEE80211R
4157 case EVENT_FT_RESPONSE
:
4158 wpa_supplicant_event_ft_response(wpa_s
, data
);
4160 #endif /* CONFIG_IEEE80211R */
4161 #ifdef CONFIG_IBSS_RSN
4162 case EVENT_IBSS_RSN_START
:
4163 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4165 #endif /* CONFIG_IBSS_RSN */
4166 case EVENT_ASSOC_REJECT
:
4167 wpas_event_assoc_reject(wpa_s
, data
);
4169 case EVENT_AUTH_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 AUTH_TIMED_OUT in mesh configuration");
4177 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4178 sme_event_auth_timed_out(wpa_s
, data
);
4180 case EVENT_ASSOC_TIMED_OUT
:
4181 /* It is possible to get this event from earlier connection */
4182 if (wpa_s
->current_ssid
&&
4183 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4184 wpa_dbg(wpa_s
, MSG_DEBUG
,
4185 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4188 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4189 sme_event_assoc_timed_out(wpa_s
, data
);
4191 case EVENT_TX_STATUS
:
4192 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4193 " type=%d stype=%d",
4194 MAC2STR(data
->tx_status
.dst
),
4195 data
->tx_status
.type
, data
->tx_status
.stype
);
4197 if (wpa_s
->ap_iface
== NULL
) {
4198 #ifdef CONFIG_OFFCHANNEL
4199 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4200 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4201 offchannel_send_action_tx_status(
4202 wpa_s
, data
->tx_status
.dst
,
4203 data
->tx_status
.data
,
4204 data
->tx_status
.data_len
,
4205 data
->tx_status
.ack
?
4206 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4207 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4208 #endif /* CONFIG_OFFCHANNEL */
4211 #endif /* CONFIG_AP */
4212 #ifdef CONFIG_OFFCHANNEL
4213 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4214 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4216 * Catch TX status events for Action frames we sent via group
4217 * interface in GO mode, or via standalone AP interface.
4218 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4219 * except when the primary interface is used as a GO interface
4220 * (for drivers which do not have group interface concurrency)
4222 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4223 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4224 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4225 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4226 offchannel_send_action_tx_status(
4227 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4228 data
->tx_status
.data
,
4229 data
->tx_status
.data_len
,
4230 data
->tx_status
.ack
?
4231 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4232 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4235 #endif /* CONFIG_OFFCHANNEL */
4237 switch (data
->tx_status
.type
) {
4238 case WLAN_FC_TYPE_MGMT
:
4239 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4240 data
->tx_status
.data_len
,
4241 data
->tx_status
.stype
,
4242 data
->tx_status
.ack
);
4244 case WLAN_FC_TYPE_DATA
:
4245 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4246 data
->tx_status
.data
,
4247 data
->tx_status
.data_len
,
4248 data
->tx_status
.ack
);
4251 #endif /* CONFIG_AP */
4254 case EVENT_EAPOL_TX_STATUS
:
4255 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4256 data
->eapol_tx_status
.data
,
4257 data
->eapol_tx_status
.data_len
,
4258 data
->eapol_tx_status
.ack
);
4260 case EVENT_DRIVER_CLIENT_POLL_OK
:
4261 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4263 case EVENT_RX_FROM_UNKNOWN
:
4264 if (wpa_s
->ap_iface
== NULL
)
4266 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4267 data
->rx_from_unknown
.wds
);
4269 #endif /* CONFIG_AP */
4270 case EVENT_CH_SWITCH
:
4271 if (!data
|| !wpa_s
->current_ssid
)
4274 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4275 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4276 data
->ch_switch
.freq
,
4277 data
->ch_switch
.ht_enabled
,
4278 data
->ch_switch
.ch_offset
,
4279 channel_width_to_string(data
->ch_switch
.ch_width
),
4280 data
->ch_switch
.cf1
,
4281 data
->ch_switch
.cf2
);
4283 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4284 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4287 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4288 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4289 wpa_s
->current_ssid
->mode
==
4290 WPAS_MODE_P2P_GROUP_FORMATION
) {
4291 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4292 data
->ch_switch
.ht_enabled
,
4293 data
->ch_switch
.ch_offset
,
4294 data
->ch_switch
.ch_width
,
4295 data
->ch_switch
.cf1
,
4296 data
->ch_switch
.cf2
);
4298 #endif /* CONFIG_AP */
4300 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4304 case EVENT_DFS_RADAR_DETECTED
:
4306 wpas_ap_event_dfs_radar_detected(wpa_s
,
4309 case EVENT_DFS_NOP_FINISHED
:
4311 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4314 #endif /* NEED_AP_MLME */
4315 #endif /* CONFIG_AP */
4316 case EVENT_DFS_CAC_STARTED
:
4318 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4320 case EVENT_DFS_CAC_FINISHED
:
4322 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4324 case EVENT_DFS_CAC_ABORTED
:
4326 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4328 case EVENT_RX_MGMT
: {
4330 const struct ieee80211_mgmt
*mgmt
;
4332 #ifdef CONFIG_TESTING_OPTIONS
4333 if (wpa_s
->ext_mgmt_frame_handling
) {
4334 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4335 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4336 char *hex
= os_malloc(hex_len
);
4338 wpa_snprintf_hex(hex
, hex_len
,
4339 rx
->frame
, rx
->frame_len
);
4340 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4341 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4347 #endif /* CONFIG_TESTING_OPTIONS */
4349 mgmt
= (const struct ieee80211_mgmt
*)
4350 data
->rx_mgmt
.frame
;
4351 fc
= le_to_host16(mgmt
->frame_control
);
4352 stype
= WLAN_FC_GET_STYPE(fc
);
4355 if (wpa_s
->ap_iface
== NULL
) {
4356 #endif /* CONFIG_AP */
4358 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4359 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4360 const u8
*src
= mgmt
->sa
;
4364 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4365 ie_len
= data
->rx_mgmt
.frame_len
-
4367 wpas_p2p_probe_req_rx(
4368 wpa_s
, src
, mgmt
->da
,
4369 mgmt
->bssid
, ie
, ie_len
,
4371 data
->rx_mgmt
.ssi_signal
);
4374 #endif /* CONFIG_P2P */
4375 #ifdef CONFIG_IBSS_RSN
4376 if (wpa_s
->current_ssid
&&
4377 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4378 stype
== WLAN_FC_STYPE_AUTH
&&
4379 data
->rx_mgmt
.frame_len
>= 30) {
4380 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4383 #endif /* CONFIG_IBSS_RSN */
4385 if (stype
== WLAN_FC_STYPE_ACTION
) {
4386 wpas_event_rx_mgmt_action(
4387 wpa_s
, data
->rx_mgmt
.frame
,
4388 data
->rx_mgmt
.frame_len
,
4390 data
->rx_mgmt
.ssi_signal
);
4395 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4400 if (stype
== WLAN_FC_STYPE_AUTH
&&
4401 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4402 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4403 sme_external_auth_mgmt_rx(
4404 wpa_s
, data
->rx_mgmt
.frame
,
4405 data
->rx_mgmt
.frame_len
);
4408 #endif /* CONFIG_SAE */
4409 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4410 "management frame in non-AP mode");
4415 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4416 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4420 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4421 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4423 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4424 mgmt
->bssid
, ie
, ie_len
,
4425 data
->rx_mgmt
.ssi_signal
);
4428 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4429 #endif /* CONFIG_AP */
4432 case EVENT_RX_PROBE_REQ
:
4433 if (data
->rx_probe_req
.sa
== NULL
||
4434 data
->rx_probe_req
.ie
== NULL
)
4437 if (wpa_s
->ap_iface
) {
4438 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4439 data
->rx_probe_req
.sa
,
4440 data
->rx_probe_req
.da
,
4441 data
->rx_probe_req
.bssid
,
4442 data
->rx_probe_req
.ie
,
4443 data
->rx_probe_req
.ie_len
,
4444 data
->rx_probe_req
.ssi_signal
);
4447 #endif /* CONFIG_AP */
4448 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4449 data
->rx_probe_req
.da
,
4450 data
->rx_probe_req
.bssid
,
4451 data
->rx_probe_req
.ie
,
4452 data
->rx_probe_req
.ie_len
,
4454 data
->rx_probe_req
.ssi_signal
);
4456 case EVENT_REMAIN_ON_CHANNEL
:
4457 #ifdef CONFIG_OFFCHANNEL
4458 offchannel_remain_on_channel_cb(
4459 wpa_s
, data
->remain_on_channel
.freq
,
4460 data
->remain_on_channel
.duration
);
4461 #endif /* CONFIG_OFFCHANNEL */
4462 wpas_p2p_remain_on_channel_cb(
4463 wpa_s
, data
->remain_on_channel
.freq
,
4464 data
->remain_on_channel
.duration
);
4466 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4467 #ifdef CONFIG_OFFCHANNEL
4468 offchannel_cancel_remain_on_channel_cb(
4469 wpa_s
, data
->remain_on_channel
.freq
);
4470 #endif /* CONFIG_OFFCHANNEL */
4471 wpas_p2p_cancel_remain_on_channel_cb(
4472 wpa_s
, data
->remain_on_channel
.freq
);
4474 wpas_dpp_cancel_remain_on_channel_cb(
4475 wpa_s
, data
->remain_on_channel
.freq
);
4476 #endif /* CONFIG_DPP */
4478 case EVENT_EAPOL_RX
:
4479 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4480 data
->eapol_rx
.data
,
4481 data
->eapol_rx
.data_len
);
4483 case EVENT_SIGNAL_CHANGE
:
4484 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4485 "above=%d signal=%d noise=%d txrate=%d",
4486 data
->signal_change
.above_threshold
,
4487 data
->signal_change
.current_signal
,
4488 data
->signal_change
.current_noise
,
4489 data
->signal_change
.current_txrate
);
4490 wpa_bss_update_level(wpa_s
->current_bss
,
4491 data
->signal_change
.current_signal
);
4492 bgscan_notify_signal_change(
4493 wpa_s
, data
->signal_change
.above_threshold
,
4494 data
->signal_change
.current_signal
,
4495 data
->signal_change
.current_noise
,
4496 data
->signal_change
.current_txrate
);
4498 case EVENT_INTERFACE_MAC_CHANGED
:
4499 wpa_supplicant_update_mac_addr(wpa_s
);
4501 case EVENT_INTERFACE_ENABLED
:
4502 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4503 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4504 wpa_supplicant_update_mac_addr(wpa_s
);
4505 if (wpa_s
->p2p_mgmt
) {
4506 wpa_supplicant_set_state(wpa_s
,
4512 if (!wpa_s
->ap_iface
) {
4513 wpa_supplicant_set_state(wpa_s
,
4515 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4516 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4518 wpa_supplicant_set_state(wpa_s
,
4520 #else /* CONFIG_AP */
4521 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4522 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4523 #endif /* CONFIG_AP */
4526 case EVENT_INTERFACE_DISABLED
:
4527 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4529 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4530 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4531 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4533 * Mark interface disabled if this happens to end up not
4534 * being removed as a separate P2P group interface.
4536 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4538 * The interface was externally disabled. Remove
4539 * it assuming an external entity will start a
4540 * new session if needed.
4542 if (wpa_s
->current_ssid
&&
4543 wpa_s
->current_ssid
->p2p_group
)
4544 wpas_p2p_interface_unavailable(wpa_s
);
4546 wpas_p2p_disconnect(wpa_s
);
4548 * wpa_s instance may have been freed, so must not use
4553 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4554 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4555 /* This radio work will be cancelled, so clear P2P
4558 p2p_stop_find(wpa_s
->global
->p2p
);
4560 #endif /* CONFIG_P2P */
4562 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4564 * Indicate disconnection to keep ctrl_iface events
4567 wpa_supplicant_event_disassoc(
4568 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4570 wpa_supplicant_mark_disassoc(wpa_s
);
4571 wpa_bss_flush(wpa_s
);
4572 radio_remove_works(wpa_s
, NULL
, 0);
4574 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4576 case EVENT_CHANNEL_LIST_CHANGED
:
4577 wpa_supplicant_update_channel_list(
4578 wpa_s
, &data
->channel_list_changed
);
4580 case EVENT_INTERFACE_UNAVAILABLE
:
4581 wpas_p2p_interface_unavailable(wpa_s
);
4583 case EVENT_BEST_CHANNEL
:
4584 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4586 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4587 data
->best_chan
.freq_overall
);
4588 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4589 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4590 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4591 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4592 data
->best_chan
.freq_5
,
4593 data
->best_chan
.freq_overall
);
4595 case EVENT_UNPROT_DEAUTH
:
4596 wpa_supplicant_event_unprot_deauth(wpa_s
,
4597 &data
->unprot_deauth
);
4599 case EVENT_UNPROT_DISASSOC
:
4600 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4601 &data
->unprot_disassoc
);
4603 case EVENT_STATION_LOW_ACK
:
4605 if (wpa_s
->ap_iface
&& data
)
4606 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4607 data
->low_ack
.addr
);
4608 #endif /* CONFIG_AP */
4611 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4612 data
->low_ack
.addr
);
4613 #endif /* CONFIG_TDLS */
4615 case EVENT_IBSS_PEER_LOST
:
4616 #ifdef CONFIG_IBSS_RSN
4617 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4618 #endif /* CONFIG_IBSS_RSN */
4620 case EVENT_DRIVER_GTK_REKEY
:
4621 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4622 wpa_s
->bssid
, ETH_ALEN
))
4626 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4627 data
->driver_gtk_rekey
.replay_ctr
);
4629 case EVENT_SCHED_SCAN_STOPPED
:
4630 wpa_s
->sched_scanning
= 0;
4631 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4632 wpa_supplicant_notify_scanning(wpa_s
, 0);
4634 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4638 * If the driver stopped scanning without being requested to,
4639 * request a new scan to continue scanning for networks.
4641 if (!wpa_s
->sched_scan_stop_req
&&
4642 wpa_s
->wpa_state
== WPA_SCANNING
) {
4643 wpa_dbg(wpa_s
, MSG_DEBUG
,
4644 "Restart scanning after unexpected sched_scan stop event");
4645 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4649 wpa_s
->sched_scan_stop_req
= 0;
4652 * Start a new sched scan to continue searching for more SSIDs
4653 * either if timed out or PNO schedule scan is pending.
4655 if (wpa_s
->sched_scan_timed_out
) {
4656 wpa_supplicant_req_sched_scan(wpa_s
);
4657 } else if (wpa_s
->pno_sched_pending
) {
4658 wpa_s
->pno_sched_pending
= 0;
4659 wpas_start_pno(wpa_s
);
4660 } else if (resched
) {
4661 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4665 case EVENT_WPS_BUTTON_PUSHED
:
4667 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4668 #endif /* CONFIG_WPS */
4670 case EVENT_AVOID_FREQUENCIES
:
4671 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4673 case EVENT_CONNECT_FAILED_REASON
:
4675 if (!wpa_s
->ap_iface
|| !data
)
4677 hostapd_event_connect_failed_reason(
4678 wpa_s
->ap_iface
->bss
[0],
4679 data
->connect_failed_reason
.addr
,
4680 data
->connect_failed_reason
.code
);
4681 #endif /* CONFIG_AP */
4683 case EVENT_NEW_PEER_CANDIDATE
:
4685 if (!wpa_s
->ifmsh
|| !data
)
4687 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4688 data
->mesh_peer
.ies
,
4689 data
->mesh_peer
.ie_len
);
4690 #endif /* CONFIG_MESH */
4694 if (!wpa_s
->ap_iface
)
4696 hostapd_event_get_survey(wpa_s
->ap_iface
,
4697 &data
->survey_results
);
4698 #endif /* CONFIG_AP */
4700 case EVENT_ACS_CHANNEL_SELECTED
:
4703 if (!wpa_s
->ap_iface
)
4705 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4706 &data
->acs_selected_channels
);
4707 #endif /* CONFIG_ACS */
4708 #endif /* CONFIG_AP */
4710 case EVENT_P2P_LO_STOP
:
4712 wpa_s
->p2p_lo_started
= 0;
4713 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4714 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4715 data
->p2p_lo_stop
.reason_code
);
4716 #endif /* CONFIG_P2P */
4718 case EVENT_BEACON_LOSS
:
4719 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4721 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4722 bgscan_notify_beacon_loss(wpa_s
);
4724 case EVENT_EXTERNAL_AUTH
:
4726 if (!wpa_s
->current_ssid
) {
4727 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4730 sme_external_auth_trigger(wpa_s
, data
);
4731 #endif /* CONFIG_SAE */
4733 case EVENT_PORT_AUTHORIZED
:
4734 wpa_supplicant_event_port_authorized(wpa_s
);
4736 case EVENT_STATION_OPMODE_CHANGED
:
4738 if (!wpa_s
->ap_iface
|| !data
)
4741 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
4742 data
->sta_opmode
.addr
,
4743 data
->sta_opmode
.smps_mode
,
4744 data
->sta_opmode
.chan_width
,
4745 data
->sta_opmode
.rx_nss
);
4746 #endif /* CONFIG_AP */
4749 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4755 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4756 union wpa_event_data
*data
)
4758 struct wpa_supplicant
*wpa_s
;
4760 if (event
!= EVENT_INTERFACE_STATUS
)
4763 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4764 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4765 unsigned int ifindex
;
4767 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4768 if (ifindex
!= data
->interface_status
.ifindex
) {
4769 wpa_dbg(wpa_s
, MSG_DEBUG
,
4770 "interface status ifindex %d mismatch (%d)",
4771 ifindex
, data
->interface_status
.ifindex
);
4775 #ifdef CONFIG_MATCH_IFACE
4776 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4777 struct wpa_interface
*wpa_i
;
4779 wpa_i
= wpa_supplicant_match_iface(
4780 ctx
, data
->interface_status
.ifname
);
4783 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4788 #endif /* CONFIG_MATCH_IFACE */
4791 wpa_supplicant_event(wpa_s
, event
, data
);