2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "common/gas_server.h"
32 #include "crypto/random.h"
33 #include "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
38 #include "gas_query.h"
39 #include "p2p_supplicant.h"
45 #include "offchannel.h"
46 #include "interworking.h"
50 #include "dpp_supplicant.h"
53 #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
56 #ifndef CONFIG_NO_SCAN_PROCESSING
57 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
58 int new_scan
, int own_request
);
59 #endif /* CONFIG_NO_SCAN_PROCESSING */
62 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
64 struct os_reltime now
;
66 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
70 if (ssid
->disabled_until
.sec
> now
.sec
)
71 return ssid
->disabled_until
.sec
- now
.sec
;
73 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
79 #ifndef CONFIG_NO_SCAN_PROCESSING
81 * wpas_reenabled_network_time - Time until first network is re-enabled
82 * @wpa_s: Pointer to wpa_supplicant data
83 * Returns: If all enabled networks are temporarily disabled, returns the time
84 * (in sec) until the first network is re-enabled. Otherwise returns 0.
86 * This function is used in case all enabled networks are temporarily disabled,
87 * in which case it returns the time (in sec) that the first network will be
88 * re-enabled. The function assumes that at least one network is enabled.
90 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
92 struct wpa_ssid
*ssid
;
93 int disabled_for
, res
= 0;
95 #ifdef CONFIG_INTERWORKING
96 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
99 #endif /* CONFIG_INTERWORKING */
101 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
105 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
109 if (!res
|| disabled_for
< res
)
115 #endif /* CONFIG_NO_SCAN_PROCESSING */
118 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
120 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
122 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
125 wpa_dbg(wpa_s
, MSG_DEBUG
,
126 "Try to associate due to network getting re-enabled");
127 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
128 wpa_supplicant_cancel_sched_scan(wpa_s
);
129 wpa_supplicant_req_scan(wpa_s
, 0, 0);
134 static struct wpa_bss
* wpa_supplicant_get_new_bss(
135 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
137 struct wpa_bss
*bss
= NULL
;
138 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
140 if (ssid
->ssid_len
> 0)
141 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
143 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
149 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
151 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
154 wpa_supplicant_update_scan_results(wpa_s
);
156 /* Get the BSS from the new scan results */
157 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
161 wpa_s
->current_bss
= bss
;
165 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
167 struct wpa_ssid
*ssid
, *old_ssid
;
168 u8 drv_ssid
[SSID_MAX_LEN
];
172 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
173 wpa_supplicant_update_current_bss(wpa_s
);
175 if (wpa_s
->current_ssid
->ssid_len
== 0)
176 return 0; /* current profile still in use */
177 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
179 wpa_msg(wpa_s
, MSG_INFO
,
180 "Failed to read SSID from driver");
181 return 0; /* try to use current profile */
185 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
186 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
188 return 0; /* current profile still in use */
190 wpa_msg(wpa_s
, MSG_DEBUG
,
191 "Driver-initiated BSS selection changed the SSID to %s",
192 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
193 /* continue selecting a new network profile */
196 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
198 ssid
= wpa_supplicant_get_ssid(wpa_s
);
200 wpa_msg(wpa_s
, MSG_INFO
,
201 "No network configuration found for the current AP");
205 if (wpas_network_disabled(wpa_s
, ssid
)) {
206 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
210 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
211 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
212 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
216 res
= wpas_temp_disabled(wpa_s
, ssid
);
218 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
219 "disabled for %d second(s)", res
);
223 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
225 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
227 size_t wpa_ie_len
= sizeof(wpa_ie
);
228 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
229 wpa_ie
, &wpa_ie_len
) < 0)
230 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
232 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
235 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
236 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
237 old_ssid
= wpa_s
->current_ssid
;
238 wpa_s
->current_ssid
= ssid
;
240 wpa_supplicant_update_current_bss(wpa_s
);
242 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
243 wpa_supplicant_initiate_eapol(wpa_s
);
244 if (old_ssid
!= wpa_s
->current_ssid
)
245 wpas_notify_network_changed(wpa_s
);
251 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
253 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
255 if (wpa_s
->countermeasures
) {
256 wpa_s
->countermeasures
= 0;
257 wpa_drv_set_countermeasures(wpa_s
, 0);
258 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
261 * It is possible that the device is sched scanning, which means
262 * that a connection attempt will be done only when we receive
263 * scan results. However, in this case, it would be preferable
264 * to scan and connect immediately, so cancel the sched_scan and
265 * issue a regular scan flow.
267 wpa_supplicant_cancel_sched_scan(wpa_s
);
268 wpa_supplicant_req_scan(wpa_s
, 0, 0);
273 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
277 wnm_bss_keep_alive_deinit(wpa_s
);
279 #ifdef CONFIG_IBSS_RSN
280 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
281 wpa_s
->ibss_rsn
= NULL
;
282 #endif /* CONFIG_IBSS_RSN */
285 wpa_supplicant_ap_deinit(wpa_s
);
286 #endif /* CONFIG_AP */
289 /* Clear possibly configured frame filters */
290 wpa_drv_configure_frame_filters(wpa_s
, 0);
291 #endif /* CONFIG_HS20 */
293 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
296 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
297 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
298 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
299 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
300 sme_clear_on_disassoc(wpa_s
);
301 wpa_s
->current_bss
= NULL
;
302 wpa_s
->assoc_freq
= 0;
305 wpas_notify_bssid_changed(wpa_s
);
307 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
308 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
309 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
310 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
311 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
)
312 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
313 wpa_s
->ap_ies_from_associnfo
= 0;
314 wpa_s
->current_ssid
= NULL
;
315 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
318 wpas_rrm_reset(wpa_s
);
319 wpa_s
->wnmsleep_used
= 0;
320 wnm_clear_coloc_intf_reporting(wpa_s
);
322 #ifdef CONFIG_TESTING_OPTIONS
323 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
324 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
325 #endif /* CONFIG_TESTING_OPTIONS */
326 wpa_s
->ieee80211ac
= 0;
330 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
332 struct wpa_ie_data ie
;
336 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
340 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
341 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
342 ie
.pmkid
+ i
* PMKID_LEN
,
343 NULL
, NULL
, 0, NULL
, 0);
344 if (pmksa_set
== 0) {
345 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
350 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
351 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
355 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
356 union wpa_event_data
*data
)
359 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
363 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
364 " index=%d preauth=%d",
365 MAC2STR(data
->pmkid_candidate
.bssid
),
366 data
->pmkid_candidate
.index
,
367 data
->pmkid_candidate
.preauth
);
369 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
370 data
->pmkid_candidate
.index
,
371 data
->pmkid_candidate
.preauth
);
375 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
377 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
378 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
381 #ifdef IEEE8021X_EAPOL
382 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
383 wpa_s
->current_ssid
&&
384 !(wpa_s
->current_ssid
->eapol_flags
&
385 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
386 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
387 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
388 * plaintext or static WEP keys). */
391 #endif /* IEEE8021X_EAPOL */
398 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
399 * @wpa_s: pointer to wpa_supplicant data
400 * @ssid: Configuration data for the network
401 * Returns: 0 on success, -1 on failure
403 * This function is called when starting authentication with a network that is
404 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
406 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
407 struct wpa_ssid
*ssid
)
409 #ifdef IEEE8021X_EAPOL
411 int aka
= 0, sim
= 0;
413 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
414 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
417 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
421 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
422 while (eap
->vendor
!= EAP_VENDOR_IETF
||
423 eap
->method
!= EAP_TYPE_NONE
) {
424 if (eap
->vendor
== EAP_VENDOR_IETF
) {
425 if (eap
->method
== EAP_TYPE_SIM
)
427 else if (eap
->method
== EAP_TYPE_AKA
||
428 eap
->method
== EAP_TYPE_AKA_PRIME
)
435 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
437 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
438 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
443 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
444 "use SIM, but neither EAP-SIM nor EAP-AKA are "
449 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
450 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
452 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
453 if (wpa_s
->scard
== NULL
) {
454 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
458 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
459 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
460 #endif /* PCSC_FUNCS */
461 #endif /* IEEE8021X_EAPOL */
467 #ifndef CONFIG_NO_SCAN_PROCESSING
469 static int has_wep_key(struct wpa_ssid
*ssid
)
473 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
474 if (ssid
->wep_key_len
[i
])
482 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
483 struct wpa_ssid
*ssid
)
487 if (ssid
->mixed_cell
)
491 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
493 #endif /* CONFIG_WPS */
496 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
498 #endif /* CONFIG_OWE */
500 if (has_wep_key(ssid
))
503 #ifdef IEEE8021X_EAPOL
504 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
505 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
506 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
508 #endif /* IEEE8021X_EAPOL */
510 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
513 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
516 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
522 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
523 struct wpa_ssid
*ssid
,
524 struct wpa_bss
*bss
, int debug_print
)
526 struct wpa_ie_data ie
;
528 const u8
*rsn_ie
, *wpa_ie
;
532 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
536 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
537 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
538 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
539 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
540 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
542 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
543 while ((ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)) && rsn_ie
) {
546 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
548 wpa_dbg(wpa_s
, MSG_DEBUG
,
549 " skip RSN IE - parse failed");
554 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
557 wpa_dbg(wpa_s
, MSG_DEBUG
,
558 " selected based on TSN in RSN IE");
562 if (!(ie
.proto
& ssid
->proto
) &&
563 !(ssid
->proto
& WPA_PROTO_OSEN
)) {
565 wpa_dbg(wpa_s
, MSG_DEBUG
,
566 " skip RSN IE - proto mismatch");
570 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
572 wpa_dbg(wpa_s
, MSG_DEBUG
,
573 " skip RSN IE - PTK cipher mismatch");
577 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
579 wpa_dbg(wpa_s
, MSG_DEBUG
,
580 " skip RSN IE - GTK cipher mismatch");
584 if (ssid
->group_mgmt_cipher
&&
585 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
587 wpa_dbg(wpa_s
, MSG_DEBUG
,
588 " skip RSN IE - group mgmt cipher mismatch");
592 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
594 wpa_dbg(wpa_s
, MSG_DEBUG
,
595 " skip RSN IE - key mgmt mismatch");
599 #ifdef CONFIG_IEEE80211W
600 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
601 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
602 MGMT_FRAME_PROTECTION_REQUIRED
) {
604 wpa_dbg(wpa_s
, MSG_DEBUG
,
605 " skip RSN IE - no mgmt frame protection");
608 #endif /* CONFIG_IEEE80211W */
609 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
610 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
611 NO_MGMT_FRAME_PROTECTION
) {
613 wpa_dbg(wpa_s
, MSG_DEBUG
,
614 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
618 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
619 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
620 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
621 NO_MGMT_FRAME_PROTECTION
) {
623 wpa_dbg(wpa_s
, MSG_DEBUG
,
624 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
627 #endif /* CONFIG_MBO */
630 wpa_dbg(wpa_s
, MSG_DEBUG
,
631 " selected based on RSN IE");
635 #ifdef CONFIG_IEEE80211W
636 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
637 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
639 wpa_dbg(wpa_s
, MSG_DEBUG
,
640 " skip - MFP Required but network not MFP Capable");
643 #endif /* CONFIG_IEEE80211W */
645 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
646 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
649 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
651 wpa_dbg(wpa_s
, MSG_DEBUG
,
652 " skip WPA IE - parse failed");
657 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
660 wpa_dbg(wpa_s
, MSG_DEBUG
,
661 " selected based on TSN in WPA IE");
665 if (!(ie
.proto
& ssid
->proto
)) {
667 wpa_dbg(wpa_s
, MSG_DEBUG
,
668 " skip WPA IE - proto mismatch");
672 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
674 wpa_dbg(wpa_s
, MSG_DEBUG
,
675 " skip WPA IE - PTK cipher mismatch");
679 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
681 wpa_dbg(wpa_s
, MSG_DEBUG
,
682 " skip WPA IE - GTK cipher mismatch");
686 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
688 wpa_dbg(wpa_s
, MSG_DEBUG
,
689 " skip WPA IE - key mgmt mismatch");
694 wpa_dbg(wpa_s
, MSG_DEBUG
,
695 " selected based on WPA IE");
699 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
702 wpa_dbg(wpa_s
, MSG_DEBUG
,
703 " allow for non-WPA IEEE 802.1X");
708 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
709 !wpa_ie
&& !rsn_ie
) {
710 if (wpa_s
->owe_transition_select
&&
711 wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
) &&
712 ssid
->owe_transition_bss_select_count
+ 1 <=
713 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
) {
714 ssid
->owe_transition_bss_select_count
++;
716 wpa_dbg(wpa_s
, MSG_DEBUG
,
717 " skip OWE transition BSS (selection count %d does not exceed %d)",
718 ssid
->owe_transition_bss_select_count
,
719 MAX_OWE_TRANSITION_BSS_SELECT_COUNT
);
720 wpa_s
->owe_transition_search
= 1;
724 wpa_dbg(wpa_s
, MSG_DEBUG
,
725 " allow in OWE transition mode");
728 #endif /* CONFIG_OWE */
730 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
731 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
733 wpa_dbg(wpa_s
, MSG_DEBUG
,
734 " skip - no WPA/RSN proto match");
738 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
739 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
741 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
745 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
747 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
752 wpa_dbg(wpa_s
, MSG_DEBUG
,
753 " reject due to mismatch with WPA/WPA2");
759 static int freq_allowed(int *freqs
, int freq
)
766 for (i
= 0; freqs
[i
]; i
++)
767 if (freqs
[i
] == freq
)
773 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
776 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
777 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
782 return 1; /* Cannot do matching without knowing band */
784 modes
= wpa_s
->hw
.modes
;
787 * The driver does not provide any additional information
788 * about the utilized hardware, so allow the connection attempt
794 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
795 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
796 int freq
= modes
[i
].channels
[j
].freq
;
797 if (freq
== bss
->freq
) {
799 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
800 break; /* do not allow 802.11b replace
811 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
812 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
816 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
817 int flagged
= !!(rate_ie
[j
] & 0x80);
818 int r
= (rate_ie
[j
] & 0x7f) * 5;
821 * IEEE Std 802.11n-2009 7.3.2.2:
822 * The new BSS Membership selector value is encoded
823 * like a legacy basic rate, but it is not a rate and
824 * only indicates if the BSS members are required to
825 * support the mandatory features of Clause 20 [HT PHY]
826 * in order to join the BSS.
828 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
829 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
830 if (!ht_supported(mode
)) {
832 wpa_dbg(wpa_s
, MSG_DEBUG
,
833 " hardware does not support HT PHY");
839 /* There's also a VHT selector for 802.11ac */
840 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
841 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
842 if (!vht_supported(mode
)) {
844 wpa_dbg(wpa_s
, MSG_DEBUG
,
845 " hardware does not support VHT PHY");
854 /* check for legacy basic rates */
855 for (k
= 0; k
< mode
->num_rates
; k
++) {
856 if (mode
->rates
[k
] == r
)
859 if (k
== mode
->num_rates
) {
861 * IEEE Std 802.11-2007 7.3.2.2 demands that in
862 * order to join a BSS all required rates
863 * have to be supported by the hardware.
866 wpa_dbg(wpa_s
, MSG_DEBUG
,
867 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
869 bss
->freq
, mode
->mode
, mode
->num_rates
);
880 * Test whether BSS is in an ESS.
881 * This is done differently in DMG (60 GHz) and non-DMG bands
883 static int bss_is_ess(struct wpa_bss
*bss
)
885 if (bss_is_dmg(bss
)) {
886 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
887 IEEE80211_CAP_DMG_AP
;
890 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
895 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
899 for (i
= 0; i
< ETH_ALEN
; i
++) {
900 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
907 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
911 for (i
= 0; i
< num
; i
++) {
912 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
913 const u8
*m
= a
+ ETH_ALEN
;
915 if (match_mac_mask(a
, addr
, m
))
922 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
923 const u8
**ret_ssid
, size_t *ret_ssid_len
)
926 const u8
*owe
, *pos
, *end
, *bssid
;
928 struct wpa_bss
*open_bss
;
930 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
931 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
935 end
= owe
+ 2 + owe
[1];
937 if (end
- pos
< ETH_ALEN
+ 1)
942 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
945 /* Match the profile SSID against the OWE transition mode SSID on the
947 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
948 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
950 *ret_ssid_len
= ssid_len
;
952 if (bss
->ssid_len
> 0)
955 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
958 if (ssid_len
!= open_bss
->ssid_len
||
959 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
960 wpa_dbg(wpa_s
, MSG_DEBUG
,
961 "OWE: transition mode SSID mismatch: %s",
962 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
966 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
967 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
968 wpa_dbg(wpa_s
, MSG_DEBUG
,
969 "OWE: transition mode open BSS unexpected info");
974 end
= owe
+ 2 + owe
[1];
976 if (end
- pos
< ETH_ALEN
+ 1)
978 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
979 wpa_dbg(wpa_s
, MSG_DEBUG
,
980 "OWE: transition mode BSSID mismatch: " MACSTR
,
986 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
988 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
989 wpa_ssid_txt(pos
, ssid_len
));
990 os_memcpy(bss
->ssid
, pos
, ssid_len
);
991 bss
->ssid_len
= ssid_len
;
992 #endif /* CONFIG_OWE */
996 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
997 int i
, struct wpa_bss
*bss
,
998 struct wpa_ssid
*group
,
999 int only_first_ssid
, int debug_print
)
1001 u8 wpa_ie_len
, rsn_ie_len
;
1003 struct wpa_blacklist
*e
;
1005 struct wpa_ssid
*ssid
;
1006 int osen
, rsn_osen
= 0;
1008 const u8
*assoc_disallow
;
1009 #endif /* CONFIG_MBO */
1010 const u8
*match_ssid
;
1011 size_t match_ssid_len
;
1012 struct wpa_ie_data data
;
1014 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1015 wpa_ie_len
= ie
? ie
[1] : 0;
1017 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1018 rsn_ie_len
= ie
? ie
[1] : 0;
1019 if (ie
&& wpa_parse_wpa_ie_rsn(ie
, 2 + ie
[1], &data
) == 0 &&
1020 (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
))
1023 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1027 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1028 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1029 i
, MAC2STR(bss
->bssid
),
1030 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1031 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1033 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1035 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1036 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1038 osen
? " osen=1" : "");
1041 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1044 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1046 * When only a single network is enabled, we can
1047 * trigger blacklisting on the first failure. This
1048 * should not be done with multiple enabled networks to
1049 * avoid getting forced to move into a worse ESS on
1050 * single error if there are no other BSSes of the
1055 if (e
->count
> limit
) {
1057 wpa_dbg(wpa_s
, MSG_DEBUG
,
1058 " skip - blacklisted (count=%d limit=%d)",
1065 match_ssid
= bss
->ssid
;
1066 match_ssid_len
= bss
->ssid_len
;
1067 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1069 if (match_ssid_len
== 0) {
1071 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1075 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1077 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1081 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1083 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1087 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1089 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1090 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1093 if (wpas_network_disabled(wpa_s
, ssid
)) {
1095 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1099 res
= wpas_temp_disabled(wpa_s
, ssid
);
1102 wpa_dbg(wpa_s
, MSG_DEBUG
,
1103 " skip - disabled temporarily for %d second(s)",
1109 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1111 wpa_dbg(wpa_s
, MSG_DEBUG
,
1112 " skip - blacklisted (WPS)");
1116 if (wpa
&& ssid
->ssid_len
== 0 &&
1117 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1120 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1121 /* Only allow wildcard SSID match if an AP
1122 * advertises active WPS operation that matches
1125 if (ssid
->ssid_len
== 0 &&
1126 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1129 #endif /* CONFIG_WPS */
1131 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1132 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1136 (match_ssid_len
!= ssid
->ssid_len
||
1137 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1139 wpa_dbg(wpa_s
, MSG_DEBUG
,
1140 " skip - SSID mismatch");
1144 if (ssid
->bssid_set
&&
1145 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1147 wpa_dbg(wpa_s
, MSG_DEBUG
,
1148 " skip - BSSID mismatch");
1152 /* check blacklist */
1153 if (ssid
->num_bssid_blacklist
&&
1154 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1155 ssid
->num_bssid_blacklist
)) {
1157 wpa_dbg(wpa_s
, MSG_DEBUG
,
1158 " skip - BSSID blacklisted");
1162 /* if there is a whitelist, only accept those APs */
1163 if (ssid
->num_bssid_whitelist
&&
1164 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1165 ssid
->num_bssid_whitelist
)) {
1167 wpa_dbg(wpa_s
, MSG_DEBUG
,
1168 " skip - BSSID not in whitelist");
1172 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1176 if (!osen
&& !wpa
&&
1177 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1178 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1179 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1180 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1182 wpa_dbg(wpa_s
, MSG_DEBUG
,
1183 " skip - non-WPA network not allowed");
1187 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1188 has_wep_key(ssid
)) {
1190 wpa_dbg(wpa_s
, MSG_DEBUG
,
1191 " skip - ignore WPA/WPA2 AP for WEP network block");
1195 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
&&
1198 wpa_dbg(wpa_s
, MSG_DEBUG
,
1199 " skip - non-OSEN network not allowed");
1203 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1205 wpa_dbg(wpa_s
, MSG_DEBUG
,
1206 " skip - privacy mismatch");
1210 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1211 !bss_is_pbss(bss
)) {
1213 wpa_dbg(wpa_s
, MSG_DEBUG
,
1214 " skip - not ESS, PBSS, or MBSS");
1218 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1220 wpa_dbg(wpa_s
, MSG_DEBUG
,
1221 " skip - PBSS mismatch (ssid %d bss %d)",
1222 ssid
->pbss
, bss_is_pbss(bss
));
1226 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1228 wpa_dbg(wpa_s
, MSG_DEBUG
,
1229 " skip - frequency not allowed");
1234 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1235 ssid
->frequency
!= bss
->freq
) {
1237 wpa_dbg(wpa_s
, MSG_DEBUG
,
1238 " skip - frequency not allowed (mesh)");
1241 #endif /* CONFIG_MESH */
1243 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1245 wpa_dbg(wpa_s
, MSG_DEBUG
,
1246 " skip - rate sets do not match");
1250 #ifndef CONFIG_IBSS_RSN
1251 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1252 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1253 WPA_KEY_MGMT_WPA_NONE
))) {
1255 wpa_dbg(wpa_s
, MSG_DEBUG
,
1256 " skip - IBSS RSN not supported in the build");
1259 #endif /* !CONFIG_IBSS_RSN */
1262 if (ssid
->p2p_group
&&
1263 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1264 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1266 wpa_dbg(wpa_s
, MSG_DEBUG
,
1267 " skip - no P2P IE seen");
1271 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1272 struct wpabuf
*p2p_ie
;
1273 u8 dev_addr
[ETH_ALEN
];
1275 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1278 wpa_dbg(wpa_s
, MSG_DEBUG
,
1279 " skip - no P2P element");
1282 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1283 bss
, P2P_IE_VENDOR_TYPE
);
1284 if (p2p_ie
== NULL
) {
1286 wpa_dbg(wpa_s
, MSG_DEBUG
,
1287 " skip - could not fetch P2P element");
1291 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1292 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1295 wpa_dbg(wpa_s
, MSG_DEBUG
,
1296 " skip - no matching GO P2P Device Address in P2P element");
1297 wpabuf_free(p2p_ie
);
1300 wpabuf_free(p2p_ie
);
1304 * TODO: skip the AP if its P2P IE has Group Formation
1305 * bit set in the P2P Group Capability Bitmap and we
1306 * are not in Group Formation with that device.
1308 #endif /* CONFIG_P2P */
1310 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1312 struct os_reltime diff
;
1314 os_reltime_sub(&wpa_s
->scan_min_time
,
1315 &bss
->last_update
, &diff
);
1317 wpa_dbg(wpa_s
, MSG_DEBUG
,
1318 " skip - scan result not recent enough (%u.%06u seconds too old)",
1319 (unsigned int) diff
.sec
,
1320 (unsigned int) diff
.usec
);
1324 #ifdef CONFIG_TESTING_OPTIONS
1325 if (wpa_s
->ignore_assoc_disallow
)
1326 goto skip_assoc_disallow
;
1327 #endif /* CONFIG_TESTING_OPTIONS */
1328 assoc_disallow
= wpas_mbo_get_bss_attr(
1329 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1330 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1332 wpa_dbg(wpa_s
, MSG_DEBUG
,
1333 " skip - MBO association disallowed (reason %u)",
1338 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1340 wpa_dbg(wpa_s
, MSG_DEBUG
,
1341 " skip - MBO retry delay has not passed yet");
1344 #ifdef CONFIG_TESTING_OPTIONS
1345 skip_assoc_disallow
:
1346 #endif /* CONFIG_TESTING_OPTIONS */
1347 #endif /* CONFIG_MBO */
1350 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1351 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1352 (!ssid
->dpp_connector
||
1353 !ssid
->dpp_netaccesskey
||
1354 !ssid
->dpp_csign
)) {
1356 wpa_dbg(wpa_s
, MSG_DEBUG
,
1357 " skip - no PMKSA entry for DPP");
1360 #endif /* CONFIG_DPP */
1362 /* Matching configuration found */
1366 /* No matching configuration found */
1371 static struct wpa_bss
*
1372 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1373 struct wpa_ssid
*group
,
1374 struct wpa_ssid
**selected_ssid
,
1375 int only_first_ssid
)
1379 if (wpa_s
->current_ssid
) {
1380 struct wpa_ssid
*ssid
;
1382 wpa_dbg(wpa_s
, MSG_DEBUG
,
1383 "Scan results matching the currently selected network");
1384 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1385 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1387 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1388 only_first_ssid
, 0);
1389 if (ssid
!= wpa_s
->current_ssid
)
1391 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1392 " freq=%d level=%d snr=%d est_throughput=%u",
1393 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1394 bss
->snr
, bss
->est_throughput
);
1398 if (only_first_ssid
)
1399 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1402 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1405 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1406 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1408 wpa_s
->owe_transition_select
= 1;
1409 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1410 only_first_ssid
, 1);
1411 wpa_s
->owe_transition_select
= 0;
1412 if (!*selected_ssid
)
1414 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1416 MAC2STR(bss
->bssid
),
1417 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1425 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1426 struct wpa_ssid
**selected_ssid
)
1428 struct wpa_bss
*selected
= NULL
;
1430 struct wpa_ssid
*next_ssid
= NULL
;
1431 struct wpa_ssid
*ssid
;
1433 if (wpa_s
->last_scan_res
== NULL
||
1434 wpa_s
->last_scan_res_used
== 0)
1435 return NULL
; /* no scan results from last update */
1437 if (wpa_s
->next_ssid
) {
1438 /* check that next_ssid is still valid */
1439 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1440 if (ssid
== wpa_s
->next_ssid
)
1444 wpa_s
->next_ssid
= NULL
;
1447 while (selected
== NULL
) {
1448 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1449 if (next_ssid
&& next_ssid
->priority
==
1450 wpa_s
->conf
->pssid
[prio
]->priority
) {
1451 selected
= wpa_supplicant_select_bss(
1452 wpa_s
, next_ssid
, selected_ssid
, 1);
1456 selected
= wpa_supplicant_select_bss(
1457 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1463 if (selected
== NULL
&& wpa_s
->blacklist
&&
1464 !wpa_s
->countermeasures
) {
1465 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1466 "blacklist and try again");
1467 wpa_blacklist_clear(wpa_s
);
1468 wpa_s
->blacklist_cleared
++;
1469 } else if (selected
== NULL
)
1473 ssid
= *selected_ssid
;
1474 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1475 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1476 const char *field_name
, *txt
= NULL
;
1478 wpa_dbg(wpa_s
, MSG_DEBUG
,
1479 "PSK/passphrase not yet available for the selected network");
1481 wpas_notify_network_request(wpa_s
, ssid
,
1482 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1484 field_name
= wpa_supplicant_ctrl_req_to_string(
1485 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1486 if (field_name
== NULL
)
1489 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1498 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1499 int timeout_sec
, int timeout_usec
)
1501 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1503 * No networks are enabled; short-circuit request so
1504 * we don't wait timeout seconds before transitioning
1505 * to INACTIVE state.
1507 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1508 "since there are no enabled networks");
1509 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1513 wpa_s
->scan_for_connection
= 1;
1514 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1518 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1519 struct wpa_bss
*selected
,
1520 struct wpa_ssid
*ssid
)
1522 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1523 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1524 "PBC session overlap");
1525 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1527 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1528 wpa_s
->p2p_in_provisioning
) {
1529 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1533 #endif /* CONFIG_P2P */
1536 wpas_wps_pbc_overlap(wpa_s
);
1537 wpas_wps_cancel(wpa_s
);
1538 #endif /* CONFIG_WPS */
1542 wpa_msg(wpa_s
, MSG_DEBUG
,
1543 "Considering connect request: reassociate: %d selected: "
1544 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1545 " wpa_state: %s ssid=%p current_ssid=%p",
1546 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1547 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1548 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1549 ssid
, wpa_s
->current_ssid
);
1552 * Do not trigger new association unless the BSSID has changed or if
1553 * reassociation is requested. If we are in process of associating with
1554 * the selected BSSID, do not trigger new attempt.
1556 if (wpa_s
->reassociate
||
1557 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1558 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1559 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1560 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1561 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1563 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1564 ssid
!= wpa_s
->current_ssid
)))) {
1565 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1566 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1569 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1570 MAC2STR(selected
->bssid
));
1571 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1573 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1574 "connect with the selected AP");
1581 static struct wpa_ssid
*
1582 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1585 struct wpa_ssid
*ssid
;
1587 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1588 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1590 if (wpas_network_disabled(wpa_s
, ssid
))
1592 #ifndef CONFIG_IBSS_RSN
1593 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1594 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1595 WPA_KEY_MGMT_WPA_NONE
))) {
1596 wpa_msg(wpa_s
, MSG_INFO
,
1597 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1598 wpa_ssid_txt(ssid
->ssid
,
1602 #endif /* !CONFIG_IBSS_RSN */
1603 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1604 ssid
->mode
== IEEE80211_MODE_AP
||
1605 ssid
->mode
== IEEE80211_MODE_MESH
)
1613 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1614 * on BSS added and BSS changed events */
1615 static void wpa_supplicant_rsn_preauth_scan_results(
1616 struct wpa_supplicant
*wpa_s
)
1618 struct wpa_bss
*bss
;
1620 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1623 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1624 const u8
*ssid
, *rsn
;
1626 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1630 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1634 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1640 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1641 struct wpa_bss
*selected
,
1642 struct wpa_ssid
*ssid
)
1644 struct wpa_bss
*current_bss
= NULL
;
1645 #ifndef CONFIG_NO_ROAMING
1648 int cur_est
, sel_est
;
1649 #endif /* CONFIG_NO_ROAMING */
1651 if (wpa_s
->reassociate
)
1652 return 1; /* explicit request to reassociate */
1653 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1654 return 1; /* we are not associated; continue */
1655 if (wpa_s
->current_ssid
== NULL
)
1656 return 1; /* unknown current SSID */
1657 if (wpa_s
->current_ssid
!= ssid
)
1658 return 1; /* different network block */
1660 if (wpas_driver_bss_selection(wpa_s
))
1661 return 0; /* Driver-based roaming */
1663 if (wpa_s
->current_ssid
->ssid
)
1664 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1665 wpa_s
->current_ssid
->ssid
,
1666 wpa_s
->current_ssid
->ssid_len
);
1668 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1671 return 1; /* current BSS not seen in scan results */
1673 if (current_bss
== selected
)
1676 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1677 return 1; /* current BSS not seen in the last scan */
1679 #ifndef CONFIG_NO_ROAMING
1680 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1681 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1682 " freq=%d level=%d snr=%d est_throughput=%u",
1683 MAC2STR(current_bss
->bssid
),
1684 current_bss
->freq
, current_bss
->level
,
1685 current_bss
->snr
, current_bss
->est_throughput
);
1686 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1687 " freq=%d level=%d snr=%d est_throughput=%u",
1688 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1689 selected
->snr
, selected
->est_throughput
);
1691 if (wpa_s
->current_ssid
->bssid_set
&&
1692 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1694 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1695 "has preferred BSSID");
1699 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1700 wpa_dbg(wpa_s
, MSG_DEBUG
,
1701 "Allow reassociation - selected BSS has better estimated throughput");
1705 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1707 if (current_bss
->level
< 0 &&
1708 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1709 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1714 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1715 wpa_dbg(wpa_s
, MSG_DEBUG
,
1716 "Skip roam - Current BSS has better estimated throughput");
1720 cur_est
= current_bss
->est_throughput
;
1721 sel_est
= selected
->est_throughput
;
1723 if (current_bss
->level
< 0) {
1724 if (current_bss
->level
< -85)
1726 else if (current_bss
->level
< -80)
1728 else if (current_bss
->level
< -75)
1730 else if (current_bss
->level
< -70)
1734 if (cur_est
> sel_est
* 1.5)
1736 else if (cur_est
> sel_est
* 1.2)
1738 else if (cur_est
> sel_est
* 1.1)
1740 else if (cur_est
> sel_est
)
1746 /* Make it easier to move to 5 GHz band */
1747 if (sel_est
> cur_est
* 1.5)
1749 else if (sel_est
> cur_est
* 1.2)
1751 else if (sel_est
> cur_est
* 1.1)
1754 if (min_diff
> reduce
)
1759 diff
= abs(current_bss
->level
- selected
->level
);
1760 if (diff
< min_diff
) {
1761 wpa_dbg(wpa_s
, MSG_DEBUG
,
1762 "Skip roam - too small difference in signal level (%d < %d)",
1767 wpa_dbg(wpa_s
, MSG_DEBUG
,
1768 "Allow reassociation due to difference in signal level (%d >= %d)",
1771 #else /* CONFIG_NO_ROAMING */
1773 #endif /* CONFIG_NO_ROAMING */
1778 * Return a negative value if no scan results could be fetched or if scan
1779 * results should not be shared with other virtual interfaces.
1780 * Return 0 if scan results were fetched and may be shared with other
1782 * Return 1 if scan results may be shared with other virtual interfaces but may
1783 * not trigger any operations.
1784 * Return 2 if the interface was removed and cannot be used.
1786 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1787 union wpa_event_data
*data
,
1788 int own_request
, int update_only
)
1790 struct wpa_scan_results
*scan_res
= NULL
;
1793 #ifndef CONFIG_NO_RANDOM_POOL
1795 #endif /* CONFIG_NO_RANDOM_POOL */
1798 if (wpa_s
->ap_iface
)
1800 #endif /* CONFIG_AP */
1802 wpa_supplicant_notify_scanning(wpa_s
, 0);
1804 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1805 data
? &data
->scan_info
:
1807 if (scan_res
== NULL
) {
1808 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1809 wpa_s
->scan_res_handler
== scan_only_handler
)
1813 if (data
&& data
->scan_info
.external_scan
)
1815 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1817 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1819 goto scan_work_done
;
1822 #ifndef CONFIG_NO_RANDOM_POOL
1823 num
= scan_res
->num
;
1826 for (i
= 0; i
< num
; i
++) {
1828 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1829 buf
[0] = res
->bssid
[5];
1830 buf
[1] = res
->qual
& 0xff;
1831 buf
[2] = res
->noise
& 0xff;
1832 buf
[3] = res
->level
& 0xff;
1833 buf
[4] = res
->tsf
& 0xff;
1834 random_add_randomness(buf
, sizeof(buf
));
1836 #endif /* CONFIG_NO_RANDOM_POOL */
1840 goto scan_work_done
;
1843 if (own_request
&& wpa_s
->scan_res_handler
&&
1844 !(data
&& data
->scan_info
.external_scan
)) {
1845 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1846 struct wpa_scan_results
*scan_res
);
1848 scan_res_handler
= wpa_s
->scan_res_handler
;
1849 wpa_s
->scan_res_handler
= NULL
;
1850 scan_res_handler(wpa_s
, scan_res
);
1852 goto scan_work_done
;
1856 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1858 if (wpa_s
->ap_iface
->scan_cb
)
1859 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1860 #endif /* CONFIG_AP */
1861 goto scan_work_done
;
1864 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1865 wpa_s
->own_scan_running
,
1866 data
? data
->scan_info
.external_scan
: 0);
1867 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1868 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1869 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1870 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1871 wpa_s
->manual_scan_id
);
1872 wpa_s
->manual_scan_use_id
= 0;
1874 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1876 wpas_notify_scan_results(wpa_s
);
1878 wpas_notify_scan_done(wpa_s
, 1);
1880 if (data
&& data
->scan_info
.external_scan
) {
1881 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1882 wpa_scan_results_free(scan_res
);
1886 if (wnm_scan_process(wpa_s
, 1) > 0)
1887 goto scan_work_done
;
1889 if (sme_proc_obss_scan(wpa_s
) > 0)
1890 goto scan_work_done
;
1893 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1894 goto scan_work_done
;
1896 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1897 goto scan_work_done
;
1899 if (autoscan_notify_scan(wpa_s
, scan_res
))
1900 goto scan_work_done
;
1902 if (wpa_s
->disconnected
) {
1903 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1904 goto scan_work_done
;
1907 if (!wpas_driver_bss_selection(wpa_s
) &&
1908 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1909 goto scan_work_done
;
1911 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1913 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1914 wpa_s
->wpa_state
< WPA_COMPLETED
)
1915 goto scan_work_done
;
1917 wpa_scan_results_free(scan_res
);
1919 if (own_request
&& wpa_s
->scan_work
) {
1920 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1921 wpa_s
->scan_work
= NULL
;
1922 radio_work_done(work
);
1925 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1928 wpa_scan_results_free(scan_res
);
1929 if (own_request
&& wpa_s
->scan_work
) {
1930 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1931 wpa_s
->scan_work
= NULL
;
1932 radio_work_done(work
);
1938 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1939 int new_scan
, int own_request
)
1941 struct wpa_bss
*selected
;
1942 struct wpa_ssid
*ssid
= NULL
;
1943 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1945 if (time_to_reenable
> 0) {
1946 wpa_dbg(wpa_s
, MSG_DEBUG
,
1947 "Postpone network selection by %d seconds since all networks are disabled",
1949 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1950 eloop_register_timeout(time_to_reenable
, 0,
1951 wpas_network_reenabled
, wpa_s
, NULL
);
1955 if (wpa_s
->p2p_mgmt
)
1956 return 0; /* no normal connection on p2p_mgmt interface */
1958 wpa_s
->owe_transition_search
= 0;
1959 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1963 wpa_msg(wpa_s
, MSG_INFO
,
1964 "Avoiding join because we already joined a mesh group");
1967 #endif /* CONFIG_MESH */
1971 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1974 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1978 if (ssid
!= wpa_s
->current_ssid
&&
1979 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1980 wpa_s
->own_disconnect_req
= 1;
1981 wpa_supplicant_deauthenticate(
1982 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1985 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1986 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1990 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1992 * Do not allow other virtual radios to trigger operations based
1993 * on these scan results since we do not want them to start
1994 * other associations at the same time.
1998 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1999 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
2001 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
2002 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
2004 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
2005 } else if (own_request
) {
2007 * No SSID found. If SCAN results are as a result of
2008 * own scan request and not due to a scan request on
2009 * another shared interface, try another scan.
2011 int timeout_sec
= wpa_s
->scan_interval
;
2012 int timeout_usec
= 0;
2016 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
2022 if (wpa_s
->p2p_in_provisioning
||
2023 wpa_s
->show_group_started
||
2024 wpa_s
->p2p_in_invitation
) {
2026 * Use shorter wait during P2P Provisioning
2027 * state and during P2P join-a-group operation
2028 * to speed up group formation.
2031 timeout_usec
= 250000;
2032 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2036 #endif /* CONFIG_P2P */
2037 #ifdef CONFIG_INTERWORKING
2038 if (wpa_s
->conf
->auto_interworking
&&
2039 wpa_s
->conf
->interworking
&&
2040 wpa_s
->conf
->cred
) {
2041 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2042 "start ANQP fetch since no matching "
2044 wpa_s
->network_select
= 1;
2045 wpa_s
->auto_network_select
= 1;
2046 interworking_start_fetch_anqp(wpa_s
);
2049 #endif /* CONFIG_INTERWORKING */
2051 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2052 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2054 timeout_usec
= 500000;
2055 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2059 #endif /* CONFIG_WPS */
2061 if (wpa_s
->owe_transition_search
) {
2062 wpa_dbg(wpa_s
, MSG_DEBUG
,
2063 "OWE: Use shorter wait during transition mode search");
2065 timeout_usec
= 500000;
2066 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2070 #endif /* CONFIG_OWE */
2071 if (wpa_supplicant_req_sched_scan(wpa_s
))
2072 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2075 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2076 WPA_EVENT_NETWORK_NOT_FOUND
);
2083 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2084 union wpa_event_data
*data
)
2086 struct wpa_supplicant
*ifs
;
2089 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2092 * Interface may have been removed, so must not dereference
2100 * If no scan results could be fetched, then no need to
2101 * notify those interfaces that did not actually request
2102 * this scan. Similarly, if scan results started a new operation on this
2103 * interface, do not notify other interfaces to avoid concurrent
2104 * operations during a connection attempt.
2110 * Check other interfaces to see if they share the same radio. If
2111 * so, they get updated with this same scan info.
2113 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2116 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2117 "sibling", ifs
->ifname
);
2118 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2128 #endif /* CONFIG_NO_SCAN_PROCESSING */
2131 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2133 #ifdef CONFIG_NO_SCAN_PROCESSING
2135 #else /* CONFIG_NO_SCAN_PROCESSING */
2136 struct os_reltime now
;
2138 wpa_s
->ignore_post_flush_scan_res
= 0;
2140 if (wpa_s
->last_scan_res_used
== 0)
2143 os_get_reltime(&now
);
2144 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2145 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2149 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2150 #endif /* CONFIG_NO_SCAN_PROCESSING */
2155 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2157 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2159 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2162 if (!wpa_s
->no_keep_alive
) {
2163 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2164 MAC2STR(wpa_s
->bssid
));
2165 /* TODO: could skip this if normal data traffic has been sent */
2166 /* TODO: Consider using some more appropriate data frame for
2169 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2174 if (wpa_s
->sme
.bss_max_idle_period
) {
2176 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2179 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2180 wnm_bss_keep_alive
, wpa_s
, NULL
);
2182 #endif /* CONFIG_SME */
2186 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2187 const u8
*ies
, size_t ies_len
)
2189 struct ieee802_11_elems elems
;
2194 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2198 if (elems
.bss_max_idle_period
) {
2200 wpa_s
->sme
.bss_max_idle_period
=
2201 WPA_GET_LE16(elems
.bss_max_idle_period
);
2202 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2203 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2204 (elems
.bss_max_idle_period
[2] & 0x01) ?
2205 " (protected keep-live required)" : "");
2206 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2207 wpa_s
->sme
.bss_max_idle_period
= 1;
2208 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2209 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2210 /* msec times 1000 */
2211 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2214 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2215 wnm_bss_keep_alive
, wpa_s
,
2219 #endif /* CONFIG_SME */
2222 #endif /* CONFIG_WNM */
2225 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2228 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2229 #endif /* CONFIG_WNM */
2233 #ifdef CONFIG_INTERWORKING
2235 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2240 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2241 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2243 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2250 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2251 const u8
*ies
, size_t ies_len
)
2253 struct ieee802_11_elems elems
;
2258 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2261 if (elems
.qos_map_set
) {
2262 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2263 elems
.qos_map_set_len
);
2267 #endif /* CONFIG_INTERWORKING */
2271 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2272 const u8
*ie
, size_t ie_len
)
2274 struct mb_ies_info mb_ies
;
2276 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2279 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2281 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2286 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2291 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2292 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2293 (unsigned int) len
);
2294 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2295 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2303 if (mb_ies
.nof_ies
> 0) {
2304 wpabuf_free(wpa_s
->received_mb_ies
);
2305 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2311 #endif /* CONFIG_FST */
2314 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2315 union wpa_event_data
*data
)
2317 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2319 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE)
2321 #endif /* CONFIG_IEEE80211R || CONFIG_OWE */
2323 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2324 if (data
->assoc_info
.req_ies
)
2325 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2326 data
->assoc_info
.req_ies_len
);
2327 if (data
->assoc_info
.resp_ies
) {
2328 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2329 data
->assoc_info
.resp_ies_len
);
2331 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2332 data
->assoc_info
.resp_ies_len
);
2333 #endif /* CONFIG_TDLS */
2335 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2336 data
->assoc_info
.resp_ies_len
);
2337 #endif /* CONFIG_WNM */
2338 #ifdef CONFIG_INTERWORKING
2339 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2340 data
->assoc_info
.resp_ies_len
);
2341 #endif /* CONFIG_INTERWORKING */
2342 if (wpa_s
->hw_capab
== CAPAB_VHT
&&
2343 get_ie(data
->assoc_info
.resp_ies
,
2344 data
->assoc_info
.resp_ies_len
, WLAN_EID_VHT_CAP
))
2345 wpa_s
->ieee80211ac
= 1;
2347 if (data
->assoc_info
.beacon_ies
)
2348 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2349 data
->assoc_info
.beacon_ies
,
2350 data
->assoc_info
.beacon_ies_len
);
2351 if (data
->assoc_info
.freq
)
2352 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2353 data
->assoc_info
.freq
);
2355 p
= data
->assoc_info
.req_ies
;
2356 l
= data
->assoc_info
.req_ies_len
;
2358 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2359 while (p
&& l
>= 2) {
2362 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2366 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2367 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2368 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2369 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2370 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2371 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2374 wpa_find_assoc_pmkid(wpa_s
);
2380 if (!found
&& data
->assoc_info
.req_ies
)
2381 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2385 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2386 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2387 (!data
->assoc_info
.resp_frame
||
2388 fils_process_assoc_resp(wpa_s
->wpa
,
2389 data
->assoc_info
.resp_frame
,
2390 data
->assoc_info
.resp_frame_len
) < 0)) {
2391 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2394 #endif /* CONFIG_SME */
2396 /* Additional processing for FILS when SME is in driver */
2397 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2398 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2399 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2400 #endif /* CONFIG_FILS */
2403 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2404 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2405 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2406 data
->assoc_info
.resp_ies
,
2407 data
->assoc_info
.resp_ies_len
) < 0)) {
2408 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2411 #endif /* CONFIG_OWE */
2413 #ifdef CONFIG_IEEE80211R
2415 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2416 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2417 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2418 data
->assoc_info
.resp_ies
,
2419 data
->assoc_info
.resp_ies_len
,
2421 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2422 "Reassociation Response failed");
2423 wpa_supplicant_deauthenticate(
2424 wpa_s
, WLAN_REASON_INVALID_IE
);
2429 p
= data
->assoc_info
.resp_ies
;
2430 l
= data
->assoc_info
.resp_ies_len
;
2432 #ifdef CONFIG_WPS_STRICT
2433 if (p
&& wpa_s
->current_ssid
&&
2434 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2436 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2438 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2439 "include WPS IE in (Re)Association Response");
2443 if (wps_validate_assoc_resp(wps
) < 0) {
2445 wpa_supplicant_deauthenticate(
2446 wpa_s
, WLAN_REASON_INVALID_IE
);
2451 #endif /* CONFIG_WPS_STRICT */
2453 /* Go through the IEs and make a copy of the MDIE, if present. */
2454 while (p
&& l
>= 2) {
2457 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2461 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2462 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2463 wpa_s
->sme
.ft_used
= 1;
2464 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2465 MOBILITY_DOMAIN_ID_LEN
);
2471 #endif /* CONFIG_SME */
2473 /* Process FT when SME is in the driver */
2474 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2475 wpa_ft_is_completed(wpa_s
->wpa
)) {
2476 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2477 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2478 data
->assoc_info
.resp_ies
,
2479 data
->assoc_info
.resp_ies_len
,
2481 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2482 "Reassociation Response failed");
2483 wpa_supplicant_deauthenticate(
2484 wpa_s
, WLAN_REASON_INVALID_IE
);
2487 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2490 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2491 data
->assoc_info
.resp_ies_len
);
2492 #endif /* CONFIG_IEEE80211R */
2494 /* WPA/RSN IE from Beacon/ProbeResp */
2495 p
= data
->assoc_info
.beacon_ies
;
2496 l
= data
->assoc_info
.beacon_ies_len
;
2498 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2500 wpa_found
= rsn_found
= 0;
2501 while (p
&& l
>= 2) {
2504 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2509 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2510 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2512 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2516 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2518 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2525 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2526 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2527 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2528 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2529 if (wpa_found
|| rsn_found
)
2530 wpa_s
->ap_ies_from_associnfo
= 1;
2532 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2533 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2534 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2536 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2537 wpa_supplicant_update_scan_results(wpa_s
);
2540 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2546 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2548 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2550 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2553 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2556 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2557 WPA_IE_VENDOR_TYPE
);
2558 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2560 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2561 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2562 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2563 bss_rsn
? 2 + bss_rsn
[1] : 0))
2570 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2571 union wpa_event_data
*data
)
2574 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2575 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2576 const u8
*ieprb
, *iebcn
;
2578 wpabuf_free(wpa_s
->received_mb_ies
);
2579 wpa_s
->received_mb_ies
= NULL
;
2582 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2583 wpa_printf(MSG_DEBUG
,
2584 "FST: MB IEs updated from Association Response frame");
2589 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2590 wpa_printf(MSG_DEBUG
,
2591 "FST: MB IEs updated from association event Beacon IEs");
2598 ieprb
= (const u8
*) (bss
+ 1);
2599 iebcn
= ieprb
+ bss
->ie_len
;
2601 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2602 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2603 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2604 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2605 #endif /* CONFIG_FST */
2609 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2610 union wpa_event_data
*data
)
2613 int ft_completed
, already_authorized
;
2617 if (wpa_s
->ap_iface
) {
2620 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2621 data
->assoc_info
.addr
,
2622 data
->assoc_info
.req_ies
,
2623 data
->assoc_info
.req_ies_len
,
2624 data
->assoc_info
.reassoc
);
2627 #endif /* CONFIG_AP */
2629 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2631 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2632 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2635 * FILS authentication can share the same mechanism to mark the
2636 * connection fully authenticated, so set ft_completed also based on
2640 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2642 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2643 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2644 wpa_supplicant_deauthenticate(
2645 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2649 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2650 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2651 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2652 MACSTR
, MAC2STR(bssid
));
2654 random_add_randomness(bssid
, ETH_ALEN
);
2655 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2656 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2657 wpas_notify_bssid_changed(wpa_s
);
2659 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2660 wpa_clear_keys(wpa_s
, bssid
);
2662 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2663 wpa_supplicant_deauthenticate(
2664 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2669 if (wpa_s
->conf
->ap_scan
== 1 &&
2670 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2671 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2672 wpa_msg(wpa_s
, MSG_WARNING
,
2673 "WPA/RSN IEs not updated");
2676 wpas_fst_update_mb_assoc(wpa_s
, data
);
2679 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2680 wpa_s
->sme
.prev_bssid_set
= 1;
2681 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2682 #endif /* CONFIG_SME */
2684 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2685 if (wpa_s
->current_ssid
) {
2686 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2687 * initialized before association, but for other modes,
2688 * initialize PC/SC here, if the current configuration needs
2689 * smartcard or SIM/USIM. */
2690 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2692 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2694 l2_packet_notify_auth_start(wpa_s
->l2
);
2696 already_authorized
= data
&& data
->assoc_info
.authorized
;
2699 * Set portEnabled first to FALSE in order to get EAP state machine out
2700 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2701 * state machine may transit to AUTHENTICATING state based on obsolete
2702 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2703 * AUTHENTICATED without ever giving chance to EAP state machine to
2706 if (!ft_completed
&& !already_authorized
) {
2707 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2708 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2710 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2711 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2712 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2714 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2715 /* 802.1X::portControl = Auto */
2716 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2717 wpa_s
->eapol_received
= 0;
2718 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2719 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2720 (wpa_s
->current_ssid
&&
2721 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2722 if (wpa_s
->current_ssid
&&
2723 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2725 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2727 * Set the key after having received joined-IBSS event
2730 wpa_supplicant_set_wpa_none_key(wpa_s
,
2731 wpa_s
->current_ssid
);
2733 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2734 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2735 } else if (!ft_completed
) {
2736 /* Timeout for receiving the first EAPOL packet */
2737 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2739 wpa_supplicant_cancel_scan(wpa_s
);
2741 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2742 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2744 * We are done; the driver will take care of RSN 4-way
2747 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2748 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2749 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2750 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2751 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2752 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2754 * The driver will take care of RSN 4-way handshake, so we need
2755 * to allow EAPOL supplicant to complete its work without
2756 * waiting for WPA supplicant.
2758 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2759 } else if (ft_completed
) {
2761 * FT protocol completed - make sure EAPOL state machine ends
2762 * up in authenticated.
2764 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2765 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2766 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2767 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2770 wpa_s
->last_eapol_matches_bssid
= 0;
2772 if (wpa_s
->pending_eapol_rx
) {
2773 struct os_reltime now
, age
;
2774 os_get_reltime(&now
);
2775 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2776 if (age
.sec
== 0 && age
.usec
< 200000 &&
2777 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2779 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2780 "frame that was received just before "
2781 "association notification");
2782 wpa_supplicant_rx_eapol(
2783 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2784 wpabuf_head(wpa_s
->pending_eapol_rx
),
2785 wpabuf_len(wpa_s
->pending_eapol_rx
));
2787 wpabuf_free(wpa_s
->pending_eapol_rx
);
2788 wpa_s
->pending_eapol_rx
= NULL
;
2791 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2792 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2793 wpa_s
->current_ssid
&&
2794 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2795 /* Set static WEP keys again */
2796 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2799 #ifdef CONFIG_IBSS_RSN
2800 if (wpa_s
->current_ssid
&&
2801 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2802 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2803 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2804 wpa_s
->ibss_rsn
== NULL
) {
2805 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2806 if (!wpa_s
->ibss_rsn
) {
2807 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2808 wpa_supplicant_deauthenticate(
2809 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2813 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2815 #endif /* CONFIG_IBSS_RSN */
2817 wpas_wps_notify_assoc(wpa_s
, bssid
);
2820 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2821 data
->assoc_info
.resp_ies_len
,
2822 &data
->assoc_info
.wmm_params
);
2824 if (wpa_s
->reassoc_same_bss
)
2825 wmm_ac_restore_tspecs(wpa_s
);
2829 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2830 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2831 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2834 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2836 #endif /* CONFIG_FILS */
2840 static int disconnect_reason_recoverable(u16 reason_code
)
2842 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2843 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2844 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2848 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2850 int locally_generated
)
2854 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2856 * At least Host AP driver and a Prism3 card seemed to be
2857 * generating streams of disconnected events when configuring
2858 * IBSS for WPA-None. Ignore them for now.
2863 bssid
= wpa_s
->bssid
;
2864 if (is_zero_ether_addr(bssid
))
2865 bssid
= wpa_s
->pending_bssid
;
2867 if (!is_zero_ether_addr(bssid
) ||
2868 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2869 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2871 MAC2STR(bssid
), reason_code
,
2872 locally_generated
? " locally_generated=1" : "");
2877 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2878 int locally_generated
)
2880 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2881 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2882 return 0; /* Not in 4-way handshake with PSK */
2885 * It looks like connection was lost while trying to go through PSK
2886 * 4-way handshake. Filter out known disconnection cases that are caused
2887 * by something else than PSK mismatch to avoid confusing reports.
2890 if (locally_generated
) {
2891 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2899 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2901 int locally_generated
)
2905 u8 prev_pending_bssid
[ETH_ALEN
];
2906 struct wpa_bss
*fast_reconnect
= NULL
;
2907 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2908 struct wpa_ssid
*last_ssid
;
2909 struct wpa_bss
*curr
= NULL
;
2911 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2912 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2914 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2916 * At least Host AP driver and a Prism3 card seemed to be
2917 * generating streams of disconnected events when configuring
2918 * IBSS for WPA-None. Ignore them for now.
2920 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2921 "IBSS/WPA-None mode");
2925 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2926 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2929 * Remove the inactive AP (which is probably out of range) from
2930 * the BSS list after marking disassociation. In particular
2931 * mac80211-based drivers use the
2932 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2933 * locally generated disconnection events for cases where the
2934 * AP does not reply anymore.
2936 curr
= wpa_s
->current_bss
;
2938 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2939 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2940 "pre-shared key may be incorrect");
2941 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2942 return; /* P2P group removed */
2943 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2945 if (!wpa_s
->disconnected
&&
2946 (!wpa_s
->auto_reconnect_disabled
||
2947 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2948 wpas_wps_searching(wpa_s
) ||
2949 wpas_wps_reenable_networks_pending(wpa_s
))) {
2950 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2951 "reconnect (wps=%d/%d wpa_state=%d)",
2952 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2953 wpas_wps_searching(wpa_s
),
2955 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2956 wpa_s
->current_ssid
&&
2957 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2958 !locally_generated
&&
2959 disconnect_reason_recoverable(reason_code
)) {
2961 * It looks like the AP has dropped association with
2962 * us, but could allow us to get back in. Try to
2963 * reconnect to the same BSS without full scan to save
2964 * time for some common cases.
2966 fast_reconnect
= wpa_s
->current_bss
;
2967 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2968 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2969 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2971 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2974 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2975 "try to re-connect");
2976 wpa_s
->reassociate
= 0;
2977 wpa_s
->disconnected
= 1;
2979 wpa_supplicant_cancel_sched_scan(wpa_s
);
2981 bssid
= wpa_s
->bssid
;
2982 if (is_zero_ether_addr(bssid
))
2983 bssid
= wpa_s
->pending_bssid
;
2984 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2985 wpas_connection_failed(wpa_s
, bssid
);
2986 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2987 if (locally_generated
)
2988 wpa_s
->disconnect_reason
= -reason_code
;
2990 wpa_s
->disconnect_reason
= reason_code
;
2991 wpas_notify_disconnect_reason(wpa_s
);
2992 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2993 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2994 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2996 last_ssid
= wpa_s
->current_ssid
;
2997 wpa_supplicant_mark_disassoc(wpa_s
);
3000 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
3002 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
3003 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
3004 wpa_s
->current_ssid
= last_ssid
;
3007 if (fast_reconnect
&&
3008 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
3009 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
3010 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
3011 fast_reconnect
->ssid_len
) &&
3012 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
3013 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
3014 #ifndef CONFIG_NO_SCAN_PROCESSING
3015 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
3016 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
3017 fast_reconnect_ssid
) < 0) {
3018 /* Recover through full scan */
3019 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3021 #endif /* CONFIG_NO_SCAN_PROCESSING */
3022 } else if (fast_reconnect
) {
3024 * Could not reconnect to the same BSS due to network being
3025 * disabled. Use a new scan to match the alternative behavior
3026 * above, i.e., to continue automatic reconnection attempt in a
3027 * way that enforces disabled network rules.
3029 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
3034 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3035 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
3037 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3039 if (!wpa_s
->pending_mic_error_report
)
3042 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3043 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3044 wpa_s
->pending_mic_error_report
= 0;
3046 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3050 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3051 union wpa_event_data
*data
)
3054 struct os_reltime t
;
3056 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3057 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3059 if ((wpa_s
->last_michael_mic_error
.sec
&&
3060 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3061 wpa_s
->pending_mic_error_report
) {
3062 if (wpa_s
->pending_mic_error_report
) {
3064 * Send the pending MIC error report immediately since
3065 * we are going to start countermeasures and AP better
3068 wpa_sm_key_request(wpa_s
->wpa
, 1,
3069 wpa_s
->pending_mic_error_pairwise
);
3072 /* Send the new MIC error report immediately since we are going
3073 * to start countermeasures and AP better do the same.
3075 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3077 /* initialize countermeasures */
3078 wpa_s
->countermeasures
= 1;
3080 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3082 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3085 * Need to wait for completion of request frame. We do not get
3086 * any callback for the message completion, so just wait a
3087 * short while and hope for the best. */
3090 wpa_drv_set_countermeasures(wpa_s
, 1);
3091 wpa_supplicant_deauthenticate(wpa_s
,
3092 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3093 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3095 eloop_register_timeout(60, 0,
3096 wpa_supplicant_stop_countermeasures
,
3098 /* TODO: mark the AP rejected for 60 second. STA is
3099 * allowed to associate with another AP.. */
3101 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3102 if (wpa_s
->mic_errors_seen
) {
3104 * Reduce the effectiveness of Michael MIC error
3105 * reports as a means for attacking against TKIP if
3106 * more than one MIC failure is noticed with the same
3107 * PTK. We delay the transmission of the reports by a
3108 * random time between 0 and 60 seconds in order to
3109 * force the attacker wait 60 seconds before getting
3110 * the information on whether a frame resulted in a MIC
3116 if (os_get_random(rval
, sizeof(rval
)) < 0)
3117 sec
= os_random() % 60;
3119 sec
= WPA_GET_BE32(rval
) % 60;
3120 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3121 "report %d seconds", sec
);
3122 wpa_s
->pending_mic_error_report
= 1;
3123 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3124 eloop_cancel_timeout(
3125 wpa_supplicant_delayed_mic_error_report
,
3127 eloop_register_timeout(
3128 sec
, os_random() % 1000000,
3129 wpa_supplicant_delayed_mic_error_report
,
3132 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3134 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3135 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3136 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3138 wpa_s
->last_michael_mic_error
= t
;
3139 wpa_s
->mic_errors_seen
++;
3143 #ifdef CONFIG_TERMINATE_ONLASTIF
3144 static int any_interfaces(struct wpa_supplicant
*head
)
3146 struct wpa_supplicant
*wpa_s
;
3148 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3149 if (!wpa_s
->interface_removed
)
3153 #endif /* CONFIG_TERMINATE_ONLASTIF */
3157 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3158 union wpa_event_data
*data
)
3160 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3163 switch (data
->interface_status
.ievent
) {
3164 case EVENT_INTERFACE_ADDED
:
3165 if (!wpa_s
->interface_removed
)
3167 wpa_s
->interface_removed
= 0;
3168 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3169 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3170 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3171 "driver after interface was added");
3175 if (!wpa_s
->global
->p2p
&&
3176 !wpa_s
->global
->p2p_disabled
&&
3177 !wpa_s
->conf
->p2p_disabled
&&
3179 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3180 wpas_p2p_add_p2pdev_interface(
3181 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3182 wpa_printf(MSG_INFO
,
3183 "P2P: Failed to enable P2P Device interface");
3184 /* Try to continue without. P2P will be disabled. */
3186 #endif /* CONFIG_P2P */
3189 case EVENT_INTERFACE_REMOVED
:
3190 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3191 wpa_s
->interface_removed
= 1;
3192 wpa_supplicant_mark_disassoc(wpa_s
);
3193 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3194 l2_packet_deinit(wpa_s
->l2
);
3198 if (wpa_s
->global
->p2p
&&
3199 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3201 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3202 wpa_dbg(wpa_s
, MSG_DEBUG
,
3203 "Removing P2P Device interface");
3204 wpa_supplicant_remove_iface(
3205 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3207 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3209 #endif /* CONFIG_P2P */
3211 #ifdef CONFIG_MATCH_IFACE
3212 if (wpa_s
->matched
) {
3213 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3216 #endif /* CONFIG_MATCH_IFACE */
3218 #ifdef CONFIG_TERMINATE_ONLASTIF
3219 /* check if last interface */
3220 if (!any_interfaces(wpa_s
->global
->ifaces
))
3222 #endif /* CONFIG_TERMINATE_ONLASTIF */
3229 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3230 union wpa_event_data
*data
)
3234 switch (data
->tdls
.oper
) {
3235 case TDLS_REQUEST_SETUP
:
3236 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3237 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3238 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3240 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3242 case TDLS_REQUEST_TEARDOWN
:
3243 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3244 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3245 data
->tdls
.reason_code
);
3247 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3250 case TDLS_REQUEST_DISCOVER
:
3251 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3256 #endif /* CONFIG_TDLS */
3260 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3261 union wpa_event_data
*data
)
3265 switch (data
->wnm
.oper
) {
3266 case WNM_OPER_SLEEP
:
3267 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3268 "(action=%d, intval=%d)",
3269 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3270 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3271 data
->wnm
.sleep_intval
, NULL
);
3275 #endif /* CONFIG_WNM */
3278 #ifdef CONFIG_IEEE80211R
3280 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3281 union wpa_event_data
*data
)
3286 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3287 data
->ft_ies
.ies_len
,
3288 data
->ft_ies
.ft_action
,
3289 data
->ft_ies
.target_ap
,
3290 data
->ft_ies
.ric_ies
,
3291 data
->ft_ies
.ric_ies_len
) < 0) {
3292 /* TODO: prevent MLME/driver from trying to associate? */
3295 #endif /* CONFIG_IEEE80211R */
3298 #ifdef CONFIG_IBSS_RSN
3299 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3300 union wpa_event_data
*data
)
3302 struct wpa_ssid
*ssid
;
3303 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3307 ssid
= wpa_s
->current_ssid
;
3310 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3313 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3317 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3318 union wpa_event_data
*data
)
3320 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3325 /* check if the ssid is correctly configured as IBSS/RSN */
3326 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3329 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3330 data
->rx_mgmt
.frame_len
);
3332 #endif /* CONFIG_IBSS_RSN */
3335 #ifdef CONFIG_IEEE80211R
3336 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3339 const u8
*sta_addr
, *target_ap_addr
;
3342 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3343 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3344 return; /* only SME case supported for now */
3345 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3348 return; /* Only FT Action Response is supported for now */
3349 sta_addr
= data
+ 1;
3350 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3351 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3352 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3353 MACSTR
" TargetAP " MACSTR
" status %u",
3354 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3356 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3357 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3358 " in FT Action Response", MAC2STR(sta_addr
));
3363 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3364 "failure (status code %d)", status
);
3365 /* TODO: report error to FT code(?) */
3369 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3370 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3371 target_ap_addr
, NULL
, 0) < 0)
3376 struct wpa_bss
*bss
;
3377 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3379 wpa_s
->sme
.freq
= bss
->freq
;
3380 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3381 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3384 #endif /* CONFIG_SME */
3386 #endif /* CONFIG_IEEE80211R */
3389 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3390 struct unprot_deauth
*e
)
3392 #ifdef CONFIG_IEEE80211W
3393 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3394 "dropped: " MACSTR
" -> " MACSTR
3395 " (reason code %u)",
3396 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3397 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3398 #endif /* CONFIG_IEEE80211W */
3402 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3403 struct unprot_disassoc
*e
)
3405 #ifdef CONFIG_IEEE80211W
3406 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3407 "dropped: " MACSTR
" -> " MACSTR
3408 " (reason code %u)",
3409 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3410 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3411 #endif /* CONFIG_IEEE80211W */
3415 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3416 u16 reason_code
, int locally_generated
,
3417 const u8
*ie
, size_t ie_len
, int deauth
)
3420 if (wpa_s
->ap_iface
&& addr
) {
3421 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3425 if (wpa_s
->ap_iface
) {
3426 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3429 #endif /* CONFIG_AP */
3431 if (!locally_generated
)
3432 wpa_s
->own_disconnect_req
= 0;
3434 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3436 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3437 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3438 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3439 eapol_sm_failed(wpa_s
->eapol
))) &&
3440 !wpa_s
->eap_expected_failure
))
3441 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3444 if (deauth
&& reason_code
> 0) {
3445 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3446 locally_generated
) > 0) {
3448 * The interface was removed, so cannot continue
3449 * processing any additional operations after this.
3454 #endif /* CONFIG_P2P */
3456 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3461 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3462 struct disassoc_info
*info
)
3464 u16 reason_code
= 0;
3465 int locally_generated
= 0;
3466 const u8
*addr
= NULL
;
3467 const u8
*ie
= NULL
;
3470 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3475 ie_len
= info
->ie_len
;
3476 reason_code
= info
->reason_code
;
3477 locally_generated
= info
->locally_generated
;
3478 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3479 locally_generated
? " (locally generated)" : "");
3481 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3483 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3488 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3489 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3493 if (wpa_s
->ap_iface
) {
3494 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3497 #endif /* CONFIG_AP */
3501 wpas_p2p_disassoc_notif(
3502 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3505 #endif /* CONFIG_P2P */
3507 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3508 sme_event_disassoc(wpa_s
, info
);
3510 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3515 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3516 struct deauth_info
*info
)
3518 u16 reason_code
= 0;
3519 int locally_generated
= 0;
3520 const u8
*addr
= NULL
;
3521 const u8
*ie
= NULL
;
3524 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3529 ie_len
= info
->ie_len
;
3530 reason_code
= info
->reason_code
;
3531 locally_generated
= info
->locally_generated
;
3532 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3534 locally_generated
? " (locally generated)" : "");
3536 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3539 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3543 wpa_reset_ft_completed(wpa_s
->wpa
);
3545 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3546 locally_generated
, ie
, ie_len
, 1);
3550 static const char * reg_init_str(enum reg_change_initiator init
)
3553 case REGDOM_SET_BY_CORE
:
3555 case REGDOM_SET_BY_USER
:
3557 case REGDOM_SET_BY_DRIVER
:
3559 case REGDOM_SET_BY_COUNTRY_IE
:
3560 return "COUNTRY_IE";
3561 case REGDOM_BEACON_HINT
:
3562 return "BEACON_HINT";
3568 static const char * reg_type_str(enum reg_type type
)
3571 case REGDOM_TYPE_UNKNOWN
:
3573 case REGDOM_TYPE_COUNTRY
:
3575 case REGDOM_TYPE_WORLD
:
3577 case REGDOM_TYPE_CUSTOM_WORLD
:
3578 return "CUSTOM_WORLD";
3579 case REGDOM_TYPE_INTERSECTION
:
3580 return "INTERSECTION";
3586 static void wpa_supplicant_update_channel_list(
3587 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3589 struct wpa_supplicant
*ifs
;
3593 * To allow backwards compatibility with higher level layers that
3594 * assumed the REGDOM_CHANGE event is sent over the initially added
3595 * interface. Find the highest parent of this interface and use it to
3598 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3601 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3602 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3603 info
->alpha2
[0] ? " alpha2=" : "",
3604 info
->alpha2
[0] ? info
->alpha2
: "");
3606 if (wpa_s
->drv_priv
== NULL
)
3607 return; /* Ignore event during drv initialization */
3609 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3611 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3613 free_hw_features(ifs
);
3614 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3615 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3617 /* Restart PNO/sched_scan with updated channel list */
3620 wpas_start_pno(ifs
);
3621 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3622 wpa_dbg(ifs
, MSG_DEBUG
,
3623 "Channel list changed - restart sched_scan");
3624 wpas_scan_restart_sched_scan(ifs
);
3628 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3632 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3633 const u8
*frame
, size_t len
, int freq
,
3636 const struct ieee80211_mgmt
*mgmt
;
3641 if (len
< IEEE80211_HDRLEN
+ 2)
3644 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3645 payload
= frame
+ IEEE80211_HDRLEN
;
3646 category
= *payload
++;
3647 plen
= len
- IEEE80211_HDRLEN
- 1;
3649 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3650 " Category=%u DataLen=%d freq=%d MHz",
3651 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3653 if (category
== WLAN_ACTION_WMM
) {
3654 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3658 #ifdef CONFIG_IEEE80211R
3659 if (category
== WLAN_ACTION_FT
) {
3660 ft_rx_action(wpa_s
, payload
, plen
);
3663 #endif /* CONFIG_IEEE80211R */
3665 #ifdef CONFIG_IEEE80211W
3667 if (category
== WLAN_ACTION_SA_QUERY
) {
3668 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3671 #endif /* CONFIG_SME */
3672 #endif /* CONFIG_IEEE80211W */
3675 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3676 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3679 #endif /* CONFIG_WNM */
3682 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3683 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3684 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3685 mgmt
->u
.action
.category
,
3686 payload
, plen
, freq
) == 0)
3688 #endif /* CONFIG_GAS */
3690 #ifdef CONFIG_GAS_SERVER
3691 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3692 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3693 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3694 mgmt
->u
.action
.category
,
3695 payload
, plen
, freq
) == 0)
3697 #endif /* CONFIG_GAS_SERVER */
3700 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3701 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3702 wpa_dbg(wpa_s
, MSG_DEBUG
,
3703 "TDLS: Received Discovery Response from " MACSTR
,
3707 #endif /* CONFIG_TDLS */
3709 #ifdef CONFIG_INTERWORKING
3710 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3711 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3712 const u8
*pos
= payload
+ 1;
3713 size_t qlen
= plen
- 1;
3714 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3715 MACSTR
, MAC2STR(mgmt
->sa
));
3716 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3717 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3718 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3719 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3722 #endif /* CONFIG_INTERWORKING */
3724 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3725 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3726 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3733 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3734 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3735 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3739 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3740 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3741 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3742 payload
+ 1, plen
- 1,
3748 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3749 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3752 #endif /* CONFIG_FST */
3755 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3756 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3757 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3758 payload
[4] == DPP_OUI_TYPE
) {
3761 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3764 #endif /* CONFIG_DPP */
3766 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3767 category
, payload
, plen
, freq
);
3769 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3773 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3774 union wpa_event_data
*event
)
3776 struct wpa_freq_range_list
*list
;
3779 list
= &event
->freq_range
;
3782 str
= freq_range_list_str(list
);
3783 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3787 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3788 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3791 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3794 * The update channel flow will also take care of moving a GO
3795 * from the unsafe frequency if needed.
3797 wpas_p2p_update_channel_list(wpa_s
,
3798 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3800 #endif /* CONFIG_P2P */
3806 static void wpa_supplicant_event_port_authorized(struct wpa_supplicant
*wpa_s
)
3808 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3809 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3810 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3811 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3812 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3817 static unsigned int wpas_event_cac_ms(const struct wpa_supplicant
*wpa_s
,
3823 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
3824 const struct hostapd_hw_modes
*mode
= &wpa_s
->hw
.modes
[i
];
3826 for (j
= 0; j
< mode
->num_channels
; j
++) {
3827 const struct hostapd_channel_data
*chan
;
3829 chan
= &mode
->channels
[j
];
3830 if (chan
->freq
== freq
)
3831 return chan
->dfs_cac_ms
;
3839 static void wpas_event_dfs_cac_started(struct wpa_supplicant
*wpa_s
,
3840 struct dfs_event
*radar
)
3842 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3843 if (wpa_s
->ap_iface
) {
3844 wpas_ap_event_dfs_cac_started(wpa_s
, radar
);
3846 #endif /* NEED_AP_MLME && CONFIG_AP */
3848 unsigned int cac_time
= wpas_event_cac_ms(wpa_s
, radar
->freq
);
3850 cac_time
/= 1000; /* convert from ms to sec */
3852 cac_time
= 10 * 60; /* max timeout: 10 minutes */
3854 /* Restart auth timeout: CAC time added to initial timeout */
3855 wpas_auth_timeout_restart(wpa_s
, cac_time
);
3860 static void wpas_event_dfs_cac_finished(struct wpa_supplicant
*wpa_s
,
3861 struct dfs_event
*radar
)
3863 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3864 if (wpa_s
->ap_iface
) {
3865 wpas_ap_event_dfs_cac_finished(wpa_s
, radar
);
3867 #endif /* NEED_AP_MLME && CONFIG_AP */
3869 /* Restart auth timeout with original value after CAC is
3871 wpas_auth_timeout_restart(wpa_s
, 0);
3876 static void wpas_event_dfs_cac_aborted(struct wpa_supplicant
*wpa_s
,
3877 struct dfs_event
*radar
)
3879 #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
3880 if (wpa_s
->ap_iface
) {
3881 wpas_ap_event_dfs_cac_aborted(wpa_s
, radar
);
3883 #endif /* NEED_AP_MLME && CONFIG_AP */
3885 /* Restart auth timeout with original value after CAC is
3887 wpas_auth_timeout_restart(wpa_s
, 0);
3892 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3893 union wpa_event_data
*data
)
3895 wpa_dbg(wpa_s
, MSG_DEBUG
,
3896 "Connection authorized by device, previous state %d",
3899 wpa_supplicant_event_port_authorized(wpa_s
);
3901 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3902 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3903 data
->assoc_info
.ptk_kck_len
,
3904 data
->assoc_info
.ptk_kek
,
3905 data
->assoc_info
.ptk_kek_len
);
3907 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3908 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3909 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3911 /* Update ERP next sequence number */
3912 eapol_sm_update_erp_next_seq_num(
3913 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3915 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3916 /* Add the new PMK and PMKID to the PMKSA cache */
3917 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3918 data
->assoc_info
.fils_pmk
,
3919 data
->assoc_info
.fils_pmk_len
,
3920 data
->assoc_info
.fils_pmkid
,
3921 wpa_s
->bssid
, fils_cache_id
);
3922 } else if (data
->assoc_info
.fils_pmkid
) {
3923 /* Update the current PMKSA used for this connection */
3924 pmksa_cache_set_current(wpa_s
->wpa
,
3925 data
->assoc_info
.fils_pmkid
,
3926 NULL
, NULL
, 0, NULL
, 0);
3929 #endif /* CONFIG_FILS */
3933 static void wpas_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
3934 union wpa_event_data
*data
)
3936 const u8
*bssid
= data
->assoc_reject
.bssid
;
3938 if (!bssid
|| is_zero_ether_addr(bssid
))
3939 bssid
= wpa_s
->pending_bssid
;
3941 if (data
->assoc_reject
.bssid
)
3942 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3943 "bssid=" MACSTR
" status_code=%u%s%s%s",
3944 MAC2STR(data
->assoc_reject
.bssid
),
3945 data
->assoc_reject
.status_code
,
3946 data
->assoc_reject
.timed_out
? " timeout" : "",
3947 data
->assoc_reject
.timeout_reason
? "=" : "",
3948 data
->assoc_reject
.timeout_reason
?
3949 data
->assoc_reject
.timeout_reason
: "");
3951 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3952 "status_code=%u%s%s%s",
3953 data
->assoc_reject
.status_code
,
3954 data
->assoc_reject
.timed_out
? " timeout" : "",
3955 data
->assoc_reject
.timeout_reason
? "=" : "",
3956 data
->assoc_reject
.timeout_reason
?
3957 data
->assoc_reject
.timeout_reason
: "");
3958 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3959 wpas_notify_assoc_status_code(wpa_s
);
3962 if (data
->assoc_reject
.status_code
==
3963 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
3964 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
3965 wpa_s
->current_ssid
&&
3966 wpa_s
->current_ssid
->owe_group
== 0 &&
3967 wpa_s
->last_owe_group
!= 21) {
3968 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3969 struct wpa_bss
*bss
= wpa_s
->current_bss
;
3972 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
3974 wpas_connection_failed(wpa_s
, bssid
);
3975 wpa_supplicant_mark_disassoc(wpa_s
);
3979 wpa_printf(MSG_DEBUG
, "OWE: Try next supported DH group");
3980 wpas_connect_work_done(wpa_s
);
3981 wpa_supplicant_mark_disassoc(wpa_s
);
3982 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3985 #endif /* CONFIG_OWE */
3987 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
3988 sme_event_assoc_reject(wpa_s
, data
);
3992 /* Driver-based SME cases */
3995 if (wpa_s
->current_ssid
&&
3996 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
) &&
3997 !data
->assoc_reject
.timed_out
) {
3998 wpa_dbg(wpa_s
, MSG_DEBUG
, "SAE: Drop PMKSA cache entry");
3999 wpa_sm_aborted_cached(wpa_s
->wpa
);
4000 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4002 #endif /* CONFIG_SAE */
4005 if (wpa_s
->current_ssid
&&
4006 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_DPP
&&
4007 !data
->assoc_reject
.timed_out
) {
4008 wpa_dbg(wpa_s
, MSG_DEBUG
, "DPP: Drop PMKSA cache entry");
4009 wpa_sm_aborted_cached(wpa_s
->wpa
);
4010 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
4012 #endif /* CONFIG_DPP */
4015 /* Update ERP next sequence number */
4016 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
4017 eapol_sm_update_erp_next_seq_num(
4019 data
->assoc_reject
.fils_erp_next_seq_num
);
4020 fils_connection_failure(wpa_s
);
4022 #endif /* CONFIG_FILS */
4024 wpas_connection_failed(wpa_s
, bssid
);
4025 wpa_supplicant_mark_disassoc(wpa_s
);
4029 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
4030 union wpa_event_data
*data
)
4032 struct wpa_supplicant
*wpa_s
= ctx
;
4034 #ifndef CONFIG_NO_STDOUT_DEBUG
4035 int level
= MSG_DEBUG
;
4036 #endif /* CONFIG_NO_STDOUT_DEBUG */
4038 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
4039 event
!= EVENT_INTERFACE_ENABLED
&&
4040 event
!= EVENT_INTERFACE_STATUS
&&
4041 event
!= EVENT_SCAN_RESULTS
&&
4042 event
!= EVENT_SCHED_SCAN_STOPPED
) {
4043 wpa_dbg(wpa_s
, MSG_DEBUG
,
4044 "Ignore event %s (%d) while interface is disabled",
4045 event_to_string(event
), event
);
4049 #ifndef CONFIG_NO_STDOUT_DEBUG
4050 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
4051 const struct ieee80211_hdr
*hdr
;
4053 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
4054 fc
= le_to_host16(hdr
->frame_control
);
4055 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
4056 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
4057 level
= MSG_EXCESSIVE
;
4060 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
4061 event_to_string(event
), event
);
4062 #endif /* CONFIG_NO_STDOUT_DEBUG */
4067 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
4068 data
->auth
.ies_len
))
4069 wpa_printf(MSG_DEBUG
,
4070 "FST: MB IEs updated from auth IE");
4071 #endif /* CONFIG_FST */
4072 sme_event_auth(wpa_s
, data
);
4075 #ifdef CONFIG_TESTING_OPTIONS
4076 if (wpa_s
->ignore_auth_resp
) {
4077 wpa_printf(MSG_INFO
,
4078 "EVENT_ASSOC - ignore_auth_resp active!");
4081 if (wpa_s
->testing_resend_assoc
) {
4082 wpa_printf(MSG_INFO
,
4083 "EVENT_DEAUTH - testing_resend_assoc");
4086 #endif /* CONFIG_TESTING_OPTIONS */
4087 wpa_supplicant_event_assoc(wpa_s
, data
);
4088 wpa_s
->assoc_status_code
= WLAN_STATUS_SUCCESS
;
4090 (data
->assoc_info
.authorized
||
4091 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4092 wpa_fils_is_completed(wpa_s
->wpa
))))
4093 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
4095 wpa_msg(wpa_s
, MSG_INFO
,
4096 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
4097 data
->assoc_info
.subnet_status
);
4100 case EVENT_DISASSOC
:
4101 wpas_event_disassoc(wpa_s
,
4102 data
? &data
->disassoc_info
: NULL
);
4105 #ifdef CONFIG_TESTING_OPTIONS
4106 if (wpa_s
->ignore_auth_resp
) {
4107 wpa_printf(MSG_INFO
,
4108 "EVENT_DEAUTH - ignore_auth_resp active!");
4111 if (wpa_s
->testing_resend_assoc
) {
4112 wpa_printf(MSG_INFO
,
4113 "EVENT_DEAUTH - testing_resend_assoc");
4116 #endif /* CONFIG_TESTING_OPTIONS */
4117 wpas_event_deauth(wpa_s
,
4118 data
? &data
->deauth_info
: NULL
);
4120 case EVENT_MICHAEL_MIC_FAILURE
:
4121 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
4123 #ifndef CONFIG_NO_SCAN_PROCESSING
4124 case EVENT_SCAN_STARTED
:
4125 if (wpa_s
->own_scan_requested
||
4126 (data
&& !data
->scan_info
.external_scan
)) {
4127 struct os_reltime diff
;
4129 os_get_reltime(&wpa_s
->scan_start_time
);
4130 os_reltime_sub(&wpa_s
->scan_start_time
,
4131 &wpa_s
->scan_trigger_time
, &diff
);
4132 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
4133 diff
.sec
, diff
.usec
);
4134 wpa_s
->own_scan_requested
= 0;
4135 wpa_s
->own_scan_running
= 1;
4136 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
4137 wpa_s
->manual_scan_use_id
) {
4138 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4139 WPA_EVENT_SCAN_STARTED
"id=%u",
4140 wpa_s
->manual_scan_id
);
4142 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
4143 WPA_EVENT_SCAN_STARTED
);
4146 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
4147 wpa_s
->radio
->external_scan_running
= 1;
4148 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
4151 case EVENT_SCAN_RESULTS
:
4152 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4153 wpa_s
->scan_res_handler
= NULL
;
4154 wpa_s
->own_scan_running
= 0;
4155 wpa_s
->radio
->external_scan_running
= 0;
4156 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
4160 if (!(data
&& data
->scan_info
.external_scan
) &&
4161 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
4162 struct os_reltime now
, diff
;
4163 os_get_reltime(&now
);
4164 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
4165 wpa_s
->scan_start_time
.sec
= 0;
4166 wpa_s
->scan_start_time
.usec
= 0;
4167 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
4168 diff
.sec
, diff
.usec
);
4170 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
4171 break; /* interface may have been removed */
4172 if (!(data
&& data
->scan_info
.external_scan
))
4173 wpa_s
->own_scan_running
= 0;
4174 if (data
&& data
->scan_info
.nl_scan_event
)
4175 wpa_s
->radio
->external_scan_running
= 0;
4176 radio_work_check_next(wpa_s
);
4178 #endif /* CONFIG_NO_SCAN_PROCESSING */
4179 case EVENT_ASSOCINFO
:
4180 wpa_supplicant_event_associnfo(wpa_s
, data
);
4182 case EVENT_INTERFACE_STATUS
:
4183 wpa_supplicant_event_interface_status(wpa_s
, data
);
4185 case EVENT_PMKID_CANDIDATE
:
4186 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
4190 wpa_supplicant_event_tdls(wpa_s
, data
);
4192 #endif /* CONFIG_TDLS */
4195 wpa_supplicant_event_wnm(wpa_s
, data
);
4197 #endif /* CONFIG_WNM */
4198 #ifdef CONFIG_IEEE80211R
4199 case EVENT_FT_RESPONSE
:
4200 wpa_supplicant_event_ft_response(wpa_s
, data
);
4202 #endif /* CONFIG_IEEE80211R */
4203 #ifdef CONFIG_IBSS_RSN
4204 case EVENT_IBSS_RSN_START
:
4205 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
4207 #endif /* CONFIG_IBSS_RSN */
4208 case EVENT_ASSOC_REJECT
:
4209 wpas_event_assoc_reject(wpa_s
, data
);
4211 case EVENT_AUTH_TIMED_OUT
:
4212 /* It is possible to get this event from earlier connection */
4213 if (wpa_s
->current_ssid
&&
4214 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4215 wpa_dbg(wpa_s
, MSG_DEBUG
,
4216 "Ignore AUTH_TIMED_OUT in mesh configuration");
4219 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4220 sme_event_auth_timed_out(wpa_s
, data
);
4222 case EVENT_ASSOC_TIMED_OUT
:
4223 /* It is possible to get this event from earlier connection */
4224 if (wpa_s
->current_ssid
&&
4225 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4226 wpa_dbg(wpa_s
, MSG_DEBUG
,
4227 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4230 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4231 sme_event_assoc_timed_out(wpa_s
, data
);
4233 case EVENT_TX_STATUS
:
4234 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4235 " type=%d stype=%d",
4236 MAC2STR(data
->tx_status
.dst
),
4237 data
->tx_status
.type
, data
->tx_status
.stype
);
4239 if (wpa_s
->ap_iface
== NULL
) {
4240 #ifdef CONFIG_OFFCHANNEL
4241 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4242 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4243 offchannel_send_action_tx_status(
4244 wpa_s
, data
->tx_status
.dst
,
4245 data
->tx_status
.data
,
4246 data
->tx_status
.data_len
,
4247 data
->tx_status
.ack
?
4248 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4249 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4250 #endif /* CONFIG_OFFCHANNEL */
4253 #endif /* CONFIG_AP */
4254 #ifdef CONFIG_OFFCHANNEL
4255 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4256 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4258 * Catch TX status events for Action frames we sent via group
4259 * interface in GO mode, or via standalone AP interface.
4260 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4261 * except when the primary interface is used as a GO interface
4262 * (for drivers which do not have group interface concurrency)
4264 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4265 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4266 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4267 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4268 offchannel_send_action_tx_status(
4269 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4270 data
->tx_status
.data
,
4271 data
->tx_status
.data_len
,
4272 data
->tx_status
.ack
?
4273 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4274 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4277 #endif /* CONFIG_OFFCHANNEL */
4279 switch (data
->tx_status
.type
) {
4280 case WLAN_FC_TYPE_MGMT
:
4281 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4282 data
->tx_status
.data_len
,
4283 data
->tx_status
.stype
,
4284 data
->tx_status
.ack
);
4286 case WLAN_FC_TYPE_DATA
:
4287 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4288 data
->tx_status
.data
,
4289 data
->tx_status
.data_len
,
4290 data
->tx_status
.ack
);
4293 #endif /* CONFIG_AP */
4296 case EVENT_EAPOL_TX_STATUS
:
4297 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4298 data
->eapol_tx_status
.data
,
4299 data
->eapol_tx_status
.data_len
,
4300 data
->eapol_tx_status
.ack
);
4302 case EVENT_DRIVER_CLIENT_POLL_OK
:
4303 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4305 case EVENT_RX_FROM_UNKNOWN
:
4306 if (wpa_s
->ap_iface
== NULL
)
4308 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4309 data
->rx_from_unknown
.wds
);
4311 #endif /* CONFIG_AP */
4312 case EVENT_CH_SWITCH
:
4313 if (!data
|| !wpa_s
->current_ssid
)
4316 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4317 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4318 data
->ch_switch
.freq
,
4319 data
->ch_switch
.ht_enabled
,
4320 data
->ch_switch
.ch_offset
,
4321 channel_width_to_string(data
->ch_switch
.ch_width
),
4322 data
->ch_switch
.cf1
,
4323 data
->ch_switch
.cf2
);
4325 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4326 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4329 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4330 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4331 wpa_s
->current_ssid
->mode
==
4332 WPAS_MODE_P2P_GROUP_FORMATION
) {
4333 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4334 data
->ch_switch
.ht_enabled
,
4335 data
->ch_switch
.ch_offset
,
4336 data
->ch_switch
.ch_width
,
4337 data
->ch_switch
.cf1
,
4338 data
->ch_switch
.cf2
);
4340 #endif /* CONFIG_AP */
4342 #ifdef CONFIG_IEEE80211W
4343 sme_event_ch_switch(wpa_s
);
4344 #endif /* CONFIG_IEEE80211W */
4345 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4346 wnm_clear_coloc_intf_reporting(wpa_s
);
4350 case EVENT_DFS_RADAR_DETECTED
:
4352 wpas_ap_event_dfs_radar_detected(wpa_s
,
4355 case EVENT_DFS_NOP_FINISHED
:
4357 wpas_ap_event_dfs_cac_nop_finished(wpa_s
,
4360 #endif /* NEED_AP_MLME */
4361 #endif /* CONFIG_AP */
4362 case EVENT_DFS_CAC_STARTED
:
4364 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4366 case EVENT_DFS_CAC_FINISHED
:
4368 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4370 case EVENT_DFS_CAC_ABORTED
:
4372 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4374 case EVENT_RX_MGMT
: {
4376 const struct ieee80211_mgmt
*mgmt
;
4378 #ifdef CONFIG_TESTING_OPTIONS
4379 if (wpa_s
->ext_mgmt_frame_handling
) {
4380 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4381 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4382 char *hex
= os_malloc(hex_len
);
4384 wpa_snprintf_hex(hex
, hex_len
,
4385 rx
->frame
, rx
->frame_len
);
4386 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4387 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4393 #endif /* CONFIG_TESTING_OPTIONS */
4395 mgmt
= (const struct ieee80211_mgmt
*)
4396 data
->rx_mgmt
.frame
;
4397 fc
= le_to_host16(mgmt
->frame_control
);
4398 stype
= WLAN_FC_GET_STYPE(fc
);
4401 if (wpa_s
->ap_iface
== NULL
) {
4402 #endif /* CONFIG_AP */
4404 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4405 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4406 const u8
*src
= mgmt
->sa
;
4410 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4411 ie_len
= data
->rx_mgmt
.frame_len
-
4413 wpas_p2p_probe_req_rx(
4414 wpa_s
, src
, mgmt
->da
,
4415 mgmt
->bssid
, ie
, ie_len
,
4417 data
->rx_mgmt
.ssi_signal
);
4420 #endif /* CONFIG_P2P */
4421 #ifdef CONFIG_IBSS_RSN
4422 if (wpa_s
->current_ssid
&&
4423 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4424 stype
== WLAN_FC_STYPE_AUTH
&&
4425 data
->rx_mgmt
.frame_len
>= 30) {
4426 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4429 #endif /* CONFIG_IBSS_RSN */
4431 if (stype
== WLAN_FC_STYPE_ACTION
) {
4432 wpas_event_rx_mgmt_action(
4433 wpa_s
, data
->rx_mgmt
.frame
,
4434 data
->rx_mgmt
.frame_len
,
4436 data
->rx_mgmt
.ssi_signal
);
4441 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4446 if (stype
== WLAN_FC_STYPE_AUTH
&&
4447 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4448 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4449 sme_external_auth_mgmt_rx(
4450 wpa_s
, data
->rx_mgmt
.frame
,
4451 data
->rx_mgmt
.frame_len
);
4454 #endif /* CONFIG_SAE */
4455 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4456 "management frame in non-AP mode");
4461 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4462 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4466 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4467 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4469 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4470 mgmt
->bssid
, ie
, ie_len
,
4471 data
->rx_mgmt
.ssi_signal
);
4474 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4475 #endif /* CONFIG_AP */
4478 case EVENT_RX_PROBE_REQ
:
4479 if (data
->rx_probe_req
.sa
== NULL
||
4480 data
->rx_probe_req
.ie
== NULL
)
4483 if (wpa_s
->ap_iface
) {
4484 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4485 data
->rx_probe_req
.sa
,
4486 data
->rx_probe_req
.da
,
4487 data
->rx_probe_req
.bssid
,
4488 data
->rx_probe_req
.ie
,
4489 data
->rx_probe_req
.ie_len
,
4490 data
->rx_probe_req
.ssi_signal
);
4493 #endif /* CONFIG_AP */
4494 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4495 data
->rx_probe_req
.da
,
4496 data
->rx_probe_req
.bssid
,
4497 data
->rx_probe_req
.ie
,
4498 data
->rx_probe_req
.ie_len
,
4500 data
->rx_probe_req
.ssi_signal
);
4502 case EVENT_REMAIN_ON_CHANNEL
:
4503 #ifdef CONFIG_OFFCHANNEL
4504 offchannel_remain_on_channel_cb(
4505 wpa_s
, data
->remain_on_channel
.freq
,
4506 data
->remain_on_channel
.duration
);
4507 #endif /* CONFIG_OFFCHANNEL */
4508 wpas_p2p_remain_on_channel_cb(
4509 wpa_s
, data
->remain_on_channel
.freq
,
4510 data
->remain_on_channel
.duration
);
4512 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4513 #ifdef CONFIG_OFFCHANNEL
4514 offchannel_cancel_remain_on_channel_cb(
4515 wpa_s
, data
->remain_on_channel
.freq
);
4516 #endif /* CONFIG_OFFCHANNEL */
4517 wpas_p2p_cancel_remain_on_channel_cb(
4518 wpa_s
, data
->remain_on_channel
.freq
);
4520 wpas_dpp_cancel_remain_on_channel_cb(
4521 wpa_s
, data
->remain_on_channel
.freq
);
4522 #endif /* CONFIG_DPP */
4524 case EVENT_EAPOL_RX
:
4525 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4526 data
->eapol_rx
.data
,
4527 data
->eapol_rx
.data_len
);
4529 case EVENT_SIGNAL_CHANGE
:
4530 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4531 "above=%d signal=%d noise=%d txrate=%d",
4532 data
->signal_change
.above_threshold
,
4533 data
->signal_change
.current_signal
,
4534 data
->signal_change
.current_noise
,
4535 data
->signal_change
.current_txrate
);
4536 wpa_bss_update_level(wpa_s
->current_bss
,
4537 data
->signal_change
.current_signal
);
4538 bgscan_notify_signal_change(
4539 wpa_s
, data
->signal_change
.above_threshold
,
4540 data
->signal_change
.current_signal
,
4541 data
->signal_change
.current_noise
,
4542 data
->signal_change
.current_txrate
);
4544 case EVENT_INTERFACE_MAC_CHANGED
:
4545 wpa_supplicant_update_mac_addr(wpa_s
);
4547 case EVENT_INTERFACE_ENABLED
:
4548 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4549 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4550 wpa_supplicant_update_mac_addr(wpa_s
);
4551 if (wpa_s
->p2p_mgmt
) {
4552 wpa_supplicant_set_state(wpa_s
,
4558 if (!wpa_s
->ap_iface
) {
4559 wpa_supplicant_set_state(wpa_s
,
4561 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4562 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4564 wpa_supplicant_set_state(wpa_s
,
4566 #else /* CONFIG_AP */
4567 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4568 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4569 #endif /* CONFIG_AP */
4572 case EVENT_INTERFACE_DISABLED
:
4573 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4575 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4576 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4577 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4579 * Mark interface disabled if this happens to end up not
4580 * being removed as a separate P2P group interface.
4582 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4584 * The interface was externally disabled. Remove
4585 * it assuming an external entity will start a
4586 * new session if needed.
4588 if (wpa_s
->current_ssid
&&
4589 wpa_s
->current_ssid
->p2p_group
)
4590 wpas_p2p_interface_unavailable(wpa_s
);
4592 wpas_p2p_disconnect(wpa_s
);
4594 * wpa_s instance may have been freed, so must not use
4599 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4600 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4601 /* This radio work will be cancelled, so clear P2P
4604 p2p_stop_find(wpa_s
->global
->p2p
);
4606 #endif /* CONFIG_P2P */
4608 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4610 * Indicate disconnection to keep ctrl_iface events
4613 wpa_supplicant_event_disassoc(
4614 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4616 wpa_supplicant_mark_disassoc(wpa_s
);
4617 wpa_bss_flush(wpa_s
);
4618 radio_remove_works(wpa_s
, NULL
, 0);
4620 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4622 case EVENT_CHANNEL_LIST_CHANGED
:
4623 wpa_supplicant_update_channel_list(
4624 wpa_s
, &data
->channel_list_changed
);
4626 case EVENT_INTERFACE_UNAVAILABLE
:
4627 wpas_p2p_interface_unavailable(wpa_s
);
4629 case EVENT_BEST_CHANNEL
:
4630 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4632 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4633 data
->best_chan
.freq_overall
);
4634 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4635 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4636 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4637 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4638 data
->best_chan
.freq_5
,
4639 data
->best_chan
.freq_overall
);
4641 case EVENT_UNPROT_DEAUTH
:
4642 wpa_supplicant_event_unprot_deauth(wpa_s
,
4643 &data
->unprot_deauth
);
4645 case EVENT_UNPROT_DISASSOC
:
4646 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4647 &data
->unprot_disassoc
);
4649 case EVENT_STATION_LOW_ACK
:
4651 if (wpa_s
->ap_iface
&& data
)
4652 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4653 data
->low_ack
.addr
);
4654 #endif /* CONFIG_AP */
4657 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4658 data
->low_ack
.addr
);
4659 #endif /* CONFIG_TDLS */
4661 case EVENT_IBSS_PEER_LOST
:
4662 #ifdef CONFIG_IBSS_RSN
4663 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4664 #endif /* CONFIG_IBSS_RSN */
4666 case EVENT_DRIVER_GTK_REKEY
:
4667 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4668 wpa_s
->bssid
, ETH_ALEN
))
4672 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4673 data
->driver_gtk_rekey
.replay_ctr
);
4675 case EVENT_SCHED_SCAN_STOPPED
:
4676 wpa_s
->sched_scanning
= 0;
4677 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4678 wpa_supplicant_notify_scanning(wpa_s
, 0);
4680 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4684 * If the driver stopped scanning without being requested to,
4685 * request a new scan to continue scanning for networks.
4687 if (!wpa_s
->sched_scan_stop_req
&&
4688 wpa_s
->wpa_state
== WPA_SCANNING
) {
4689 wpa_dbg(wpa_s
, MSG_DEBUG
,
4690 "Restart scanning after unexpected sched_scan stop event");
4691 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4695 wpa_s
->sched_scan_stop_req
= 0;
4698 * Start a new sched scan to continue searching for more SSIDs
4699 * either if timed out or PNO schedule scan is pending.
4701 if (wpa_s
->sched_scan_timed_out
) {
4702 wpa_supplicant_req_sched_scan(wpa_s
);
4703 } else if (wpa_s
->pno_sched_pending
) {
4704 wpa_s
->pno_sched_pending
= 0;
4705 wpas_start_pno(wpa_s
);
4706 } else if (resched
) {
4707 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4711 case EVENT_WPS_BUTTON_PUSHED
:
4713 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4714 #endif /* CONFIG_WPS */
4716 case EVENT_AVOID_FREQUENCIES
:
4717 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4719 case EVENT_CONNECT_FAILED_REASON
:
4721 if (!wpa_s
->ap_iface
|| !data
)
4723 hostapd_event_connect_failed_reason(
4724 wpa_s
->ap_iface
->bss
[0],
4725 data
->connect_failed_reason
.addr
,
4726 data
->connect_failed_reason
.code
);
4727 #endif /* CONFIG_AP */
4729 case EVENT_NEW_PEER_CANDIDATE
:
4731 if (!wpa_s
->ifmsh
|| !data
)
4733 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4734 data
->mesh_peer
.ies
,
4735 data
->mesh_peer
.ie_len
);
4736 #endif /* CONFIG_MESH */
4740 if (!wpa_s
->ap_iface
)
4742 hostapd_event_get_survey(wpa_s
->ap_iface
,
4743 &data
->survey_results
);
4744 #endif /* CONFIG_AP */
4746 case EVENT_ACS_CHANNEL_SELECTED
:
4749 if (!wpa_s
->ap_iface
)
4751 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4752 &data
->acs_selected_channels
);
4753 #endif /* CONFIG_ACS */
4754 #endif /* CONFIG_AP */
4756 case EVENT_P2P_LO_STOP
:
4758 wpa_s
->p2p_lo_started
= 0;
4759 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4760 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4761 data
->p2p_lo_stop
.reason_code
);
4762 #endif /* CONFIG_P2P */
4764 case EVENT_BEACON_LOSS
:
4765 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4767 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4768 bgscan_notify_beacon_loss(wpa_s
);
4770 case EVENT_EXTERNAL_AUTH
:
4772 if (!wpa_s
->current_ssid
) {
4773 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4776 sme_external_auth_trigger(wpa_s
, data
);
4777 #endif /* CONFIG_SAE */
4779 case EVENT_PORT_AUTHORIZED
:
4780 wpa_supplicant_event_port_authorized(wpa_s
);
4782 case EVENT_STATION_OPMODE_CHANGED
:
4784 if (!wpa_s
->ap_iface
|| !data
)
4787 hostapd_event_sta_opmode_changed(wpa_s
->ap_iface
->bss
[0],
4788 data
->sta_opmode
.addr
,
4789 data
->sta_opmode
.smps_mode
,
4790 data
->sta_opmode
.chan_width
,
4791 data
->sta_opmode
.rx_nss
);
4792 #endif /* CONFIG_AP */
4795 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4801 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4802 union wpa_event_data
*data
)
4804 struct wpa_supplicant
*wpa_s
;
4806 if (event
!= EVENT_INTERFACE_STATUS
)
4809 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4810 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4811 unsigned int ifindex
;
4813 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4814 if (ifindex
!= data
->interface_status
.ifindex
) {
4815 wpa_dbg(wpa_s
, MSG_DEBUG
,
4816 "interface status ifindex %d mismatch (%d)",
4817 ifindex
, data
->interface_status
.ifindex
);
4821 #ifdef CONFIG_MATCH_IFACE
4822 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4823 struct wpa_interface
*wpa_i
;
4825 wpa_i
= wpa_supplicant_match_iface(
4826 ctx
, data
->interface_status
.ifname
);
4829 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4834 #endif /* CONFIG_MATCH_IFACE */
4837 wpa_supplicant_event(wpa_s
, event
, data
);