2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "common/gas_server.h"
32 #include "crypto/random.h"
33 #include "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
38 #include "gas_query.h"
39 #include "p2p_supplicant.h"
45 #include "offchannel.h"
46 #include "interworking.h"
50 #include "dpp_supplicant.h"
53 #ifndef CONFIG_NO_SCAN_PROCESSING
54 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
55 int new_scan
, int own_request
);
56 #endif /* CONFIG_NO_SCAN_PROCESSING */
59 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
61 struct os_reltime now
;
63 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
67 if (ssid
->disabled_until
.sec
> now
.sec
)
68 return ssid
->disabled_until
.sec
- now
.sec
;
70 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
76 #ifndef CONFIG_NO_SCAN_PROCESSING
78 * wpas_reenabled_network_time - Time until first network is re-enabled
79 * @wpa_s: Pointer to wpa_supplicant data
80 * Returns: If all enabled networks are temporarily disabled, returns the time
81 * (in sec) until the first network is re-enabled. Otherwise returns 0.
83 * This function is used in case all enabled networks are temporarily disabled,
84 * in which case it returns the time (in sec) that the first network will be
85 * re-enabled. The function assumes that at least one network is enabled.
87 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
89 struct wpa_ssid
*ssid
;
90 int disabled_for
, res
= 0;
92 #ifdef CONFIG_INTERWORKING
93 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
96 #endif /* CONFIG_INTERWORKING */
98 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
102 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
106 if (!res
|| disabled_for
< res
)
112 #endif /* CONFIG_NO_SCAN_PROCESSING */
115 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
117 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
119 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
122 wpa_dbg(wpa_s
, MSG_DEBUG
,
123 "Try to associate due to network getting re-enabled");
124 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
125 wpa_supplicant_cancel_sched_scan(wpa_s
);
126 wpa_supplicant_req_scan(wpa_s
, 0, 0);
131 static struct wpa_bss
* wpa_supplicant_get_new_bss(
132 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
134 struct wpa_bss
*bss
= NULL
;
135 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
137 if (ssid
->ssid_len
> 0)
138 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
140 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
146 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
148 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
151 wpa_supplicant_update_scan_results(wpa_s
);
153 /* Get the BSS from the new scan results */
154 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
158 wpa_s
->current_bss
= bss
;
162 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
164 struct wpa_ssid
*ssid
, *old_ssid
;
165 u8 drv_ssid
[SSID_MAX_LEN
];
169 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
170 wpa_supplicant_update_current_bss(wpa_s
);
172 if (wpa_s
->current_ssid
->ssid_len
== 0)
173 return 0; /* current profile still in use */
174 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
176 wpa_msg(wpa_s
, MSG_INFO
,
177 "Failed to read SSID from driver");
178 return 0; /* try to use current profile */
182 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
183 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
185 return 0; /* current profile still in use */
187 wpa_msg(wpa_s
, MSG_DEBUG
,
188 "Driver-initiated BSS selection changed the SSID to %s",
189 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
190 /* continue selecting a new network profile */
193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
195 ssid
= wpa_supplicant_get_ssid(wpa_s
);
197 wpa_msg(wpa_s
, MSG_INFO
,
198 "No network configuration found for the current AP");
202 if (wpas_network_disabled(wpa_s
, ssid
)) {
203 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
207 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
208 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
209 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
213 res
= wpas_temp_disabled(wpa_s
, ssid
);
215 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
216 "disabled for %d second(s)", res
);
220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
222 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
224 size_t wpa_ie_len
= sizeof(wpa_ie
);
225 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
226 wpa_ie
, &wpa_ie_len
) < 0)
227 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
229 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
232 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
233 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
234 old_ssid
= wpa_s
->current_ssid
;
235 wpa_s
->current_ssid
= ssid
;
237 wpa_supplicant_update_current_bss(wpa_s
);
239 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
240 wpa_supplicant_initiate_eapol(wpa_s
);
241 if (old_ssid
!= wpa_s
->current_ssid
)
242 wpas_notify_network_changed(wpa_s
);
248 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
250 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
252 if (wpa_s
->countermeasures
) {
253 wpa_s
->countermeasures
= 0;
254 wpa_drv_set_countermeasures(wpa_s
, 0);
255 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
258 * It is possible that the device is sched scanning, which means
259 * that a connection attempt will be done only when we receive
260 * scan results. However, in this case, it would be preferable
261 * to scan and connect immediately, so cancel the sched_scan and
262 * issue a regular scan flow.
264 wpa_supplicant_cancel_sched_scan(wpa_s
);
265 wpa_supplicant_req_scan(wpa_s
, 0, 0);
270 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
274 wnm_bss_keep_alive_deinit(wpa_s
);
276 #ifdef CONFIG_IBSS_RSN
277 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
278 wpa_s
->ibss_rsn
= NULL
;
279 #endif /* CONFIG_IBSS_RSN */
282 wpa_supplicant_ap_deinit(wpa_s
);
283 #endif /* CONFIG_AP */
286 /* Clear possibly configured frame filters */
287 wpa_drv_configure_frame_filters(wpa_s
, 0);
288 #endif /* CONFIG_HS20 */
290 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
293 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
294 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
295 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
296 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
297 sme_clear_on_disassoc(wpa_s
);
298 wpa_s
->current_bss
= NULL
;
299 wpa_s
->assoc_freq
= 0;
302 wpas_notify_bssid_changed(wpa_s
);
304 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
305 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
306 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
307 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
308 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
)
309 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
310 wpa_s
->ap_ies_from_associnfo
= 0;
311 wpa_s
->current_ssid
= NULL
;
312 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
315 wpas_rrm_reset(wpa_s
);
316 wpa_s
->wnmsleep_used
= 0;
318 #ifdef CONFIG_TESTING_OPTIONS
319 wpa_s
->last_tk_alg
= WPA_ALG_NONE
;
320 os_memset(wpa_s
->last_tk
, 0, sizeof(wpa_s
->last_tk
));
321 #endif /* CONFIG_TESTING_OPTIONS */
325 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
327 struct wpa_ie_data ie
;
331 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
335 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
336 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
337 ie
.pmkid
+ i
* PMKID_LEN
,
338 NULL
, NULL
, 0, NULL
);
339 if (pmksa_set
== 0) {
340 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
345 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
346 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
350 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
351 union wpa_event_data
*data
)
354 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
358 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
359 " index=%d preauth=%d",
360 MAC2STR(data
->pmkid_candidate
.bssid
),
361 data
->pmkid_candidate
.index
,
362 data
->pmkid_candidate
.preauth
);
364 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
365 data
->pmkid_candidate
.index
,
366 data
->pmkid_candidate
.preauth
);
370 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
372 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
373 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
376 #ifdef IEEE8021X_EAPOL
377 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
378 wpa_s
->current_ssid
&&
379 !(wpa_s
->current_ssid
->eapol_flags
&
380 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
381 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
382 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
383 * plaintext or static WEP keys). */
386 #endif /* IEEE8021X_EAPOL */
393 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
394 * @wpa_s: pointer to wpa_supplicant data
395 * @ssid: Configuration data for the network
396 * Returns: 0 on success, -1 on failure
398 * This function is called when starting authentication with a network that is
399 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
401 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
402 struct wpa_ssid
*ssid
)
404 #ifdef IEEE8021X_EAPOL
406 int aka
= 0, sim
= 0;
408 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
409 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
412 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
416 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
417 while (eap
->vendor
!= EAP_VENDOR_IETF
||
418 eap
->method
!= EAP_TYPE_NONE
) {
419 if (eap
->vendor
== EAP_VENDOR_IETF
) {
420 if (eap
->method
== EAP_TYPE_SIM
)
422 else if (eap
->method
== EAP_TYPE_AKA
||
423 eap
->method
== EAP_TYPE_AKA_PRIME
)
430 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
432 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
433 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
438 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
439 "use SIM, but neither EAP-SIM nor EAP-AKA are "
444 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
445 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
447 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
448 if (wpa_s
->scard
== NULL
) {
449 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
453 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
454 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
455 #endif /* PCSC_FUNCS */
456 #endif /* IEEE8021X_EAPOL */
462 #ifndef CONFIG_NO_SCAN_PROCESSING
464 static int has_wep_key(struct wpa_ssid
*ssid
)
468 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
469 if (ssid
->wep_key_len
[i
])
477 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
478 struct wpa_ssid
*ssid
)
482 if (ssid
->mixed_cell
)
486 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
488 #endif /* CONFIG_WPS */
491 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
)
493 #endif /* CONFIG_OWE */
495 if (has_wep_key(ssid
))
498 #ifdef IEEE8021X_EAPOL
499 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
500 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
501 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
503 #endif /* IEEE8021X_EAPOL */
505 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
508 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
511 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
517 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
518 struct wpa_ssid
*ssid
,
519 struct wpa_bss
*bss
, int debug_print
)
521 struct wpa_ie_data ie
;
523 const u8
*rsn_ie
, *wpa_ie
;
527 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
531 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
532 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
533 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
534 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
535 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
537 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
538 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
541 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
543 wpa_dbg(wpa_s
, MSG_DEBUG
,
544 " skip RSN IE - parse failed");
549 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
552 wpa_dbg(wpa_s
, MSG_DEBUG
,
553 " selected based on TSN in RSN IE");
557 if (!(ie
.proto
& ssid
->proto
)) {
559 wpa_dbg(wpa_s
, MSG_DEBUG
,
560 " skip RSN IE - proto mismatch");
564 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
566 wpa_dbg(wpa_s
, MSG_DEBUG
,
567 " skip RSN IE - PTK cipher mismatch");
571 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
573 wpa_dbg(wpa_s
, MSG_DEBUG
,
574 " skip RSN IE - GTK cipher mismatch");
578 if (ssid
->group_mgmt_cipher
&&
579 !(ie
.mgmt_group_cipher
& ssid
->group_mgmt_cipher
)) {
581 wpa_dbg(wpa_s
, MSG_DEBUG
,
582 " skip RSN IE - group mgmt cipher mismatch");
586 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
588 wpa_dbg(wpa_s
, MSG_DEBUG
,
589 " skip RSN IE - key mgmt mismatch");
593 #ifdef CONFIG_IEEE80211W
594 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
595 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
596 MGMT_FRAME_PROTECTION_REQUIRED
) {
598 wpa_dbg(wpa_s
, MSG_DEBUG
,
599 " skip RSN IE - no mgmt frame protection");
602 #endif /* CONFIG_IEEE80211W */
603 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
604 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
605 NO_MGMT_FRAME_PROTECTION
) {
607 wpa_dbg(wpa_s
, MSG_DEBUG
,
608 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
612 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
613 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
614 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
615 NO_MGMT_FRAME_PROTECTION
) {
617 wpa_dbg(wpa_s
, MSG_DEBUG
,
618 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
621 #endif /* CONFIG_MBO */
624 wpa_dbg(wpa_s
, MSG_DEBUG
,
625 " selected based on RSN IE");
629 #ifdef CONFIG_IEEE80211W
630 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
&&
631 (!(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) || ssid
->owe_only
)) {
633 wpa_dbg(wpa_s
, MSG_DEBUG
,
634 " skip - MFP Required but network not MFP Capable");
637 #endif /* CONFIG_IEEE80211W */
639 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
640 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
643 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
645 wpa_dbg(wpa_s
, MSG_DEBUG
,
646 " skip WPA IE - parse failed");
651 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
654 wpa_dbg(wpa_s
, MSG_DEBUG
,
655 " selected based on TSN in WPA IE");
659 if (!(ie
.proto
& ssid
->proto
)) {
661 wpa_dbg(wpa_s
, MSG_DEBUG
,
662 " skip WPA IE - proto mismatch");
666 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
668 wpa_dbg(wpa_s
, MSG_DEBUG
,
669 " skip WPA IE - PTK cipher mismatch");
673 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
675 wpa_dbg(wpa_s
, MSG_DEBUG
,
676 " skip WPA IE - GTK cipher mismatch");
680 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
682 wpa_dbg(wpa_s
, MSG_DEBUG
,
683 " skip WPA IE - key mgmt mismatch");
688 wpa_dbg(wpa_s
, MSG_DEBUG
,
689 " selected based on WPA IE");
693 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
696 wpa_dbg(wpa_s
, MSG_DEBUG
,
697 " allow for non-WPA IEEE 802.1X");
702 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) && !ssid
->owe_only
&&
703 !wpa_ie
&& !rsn_ie
) {
705 wpa_dbg(wpa_s
, MSG_DEBUG
,
706 " allow in OWE transition mode");
709 #endif /* CONFIG_OWE */
711 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
712 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
714 wpa_dbg(wpa_s
, MSG_DEBUG
,
715 " skip - no WPA/RSN proto match");
719 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
720 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
722 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
726 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
728 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
733 wpa_dbg(wpa_s
, MSG_DEBUG
,
734 " reject due to mismatch with WPA/WPA2");
740 static int freq_allowed(int *freqs
, int freq
)
747 for (i
= 0; freqs
[i
]; i
++)
748 if (freqs
[i
] == freq
)
754 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
757 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
758 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
763 return 1; /* Cannot do matching without knowing band */
765 modes
= wpa_s
->hw
.modes
;
768 * The driver does not provide any additional information
769 * about the utilized hardware, so allow the connection attempt
775 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
776 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
777 int freq
= modes
[i
].channels
[j
].freq
;
778 if (freq
== bss
->freq
) {
780 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
781 break; /* do not allow 802.11b replace
792 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
793 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
797 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
798 int flagged
= !!(rate_ie
[j
] & 0x80);
799 int r
= (rate_ie
[j
] & 0x7f) * 5;
802 * IEEE Std 802.11n-2009 7.3.2.2:
803 * The new BSS Membership selector value is encoded
804 * like a legacy basic rate, but it is not a rate and
805 * only indicates if the BSS members are required to
806 * support the mandatory features of Clause 20 [HT PHY]
807 * in order to join the BSS.
809 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
810 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
811 if (!ht_supported(mode
)) {
813 wpa_dbg(wpa_s
, MSG_DEBUG
,
814 " hardware does not support HT PHY");
820 /* There's also a VHT selector for 802.11ac */
821 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
822 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
823 if (!vht_supported(mode
)) {
825 wpa_dbg(wpa_s
, MSG_DEBUG
,
826 " hardware does not support VHT PHY");
835 /* check for legacy basic rates */
836 for (k
= 0; k
< mode
->num_rates
; k
++) {
837 if (mode
->rates
[k
] == r
)
840 if (k
== mode
->num_rates
) {
842 * IEEE Std 802.11-2007 7.3.2.2 demands that in
843 * order to join a BSS all required rates
844 * have to be supported by the hardware.
847 wpa_dbg(wpa_s
, MSG_DEBUG
,
848 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
850 bss
->freq
, mode
->mode
, mode
->num_rates
);
861 * Test whether BSS is in an ESS.
862 * This is done differently in DMG (60 GHz) and non-DMG bands
864 static int bss_is_ess(struct wpa_bss
*bss
)
866 if (bss_is_dmg(bss
)) {
867 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
868 IEEE80211_CAP_DMG_AP
;
871 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
876 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
880 for (i
= 0; i
< ETH_ALEN
; i
++) {
881 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
888 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
892 for (i
= 0; i
< num
; i
++) {
893 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
894 const u8
*m
= a
+ ETH_ALEN
;
896 if (match_mac_mask(a
, addr
, m
))
903 static void owe_trans_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
904 const u8
**ret_ssid
, size_t *ret_ssid_len
)
907 const u8
*owe
, *pos
, *end
, *bssid
;
909 struct wpa_bss
*open_bss
;
911 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
912 if (!owe
|| !wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
916 end
= owe
+ 2 + owe
[1];
918 if (end
- pos
< ETH_ALEN
+ 1)
923 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
926 /* Match the profile SSID against the OWE transition mode SSID on the
928 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: transition mode BSSID: " MACSTR
929 " SSID: %s", MAC2STR(bssid
), wpa_ssid_txt(pos
, ssid_len
));
931 *ret_ssid_len
= ssid_len
;
933 if (bss
->ssid_len
> 0)
936 open_bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
939 if (ssid_len
!= open_bss
->ssid_len
||
940 os_memcmp(pos
, open_bss
->ssid
, ssid_len
) != 0) {
941 wpa_dbg(wpa_s
, MSG_DEBUG
,
942 "OWE: transition mode SSID mismatch: %s",
943 wpa_ssid_txt(open_bss
->ssid
, open_bss
->ssid_len
));
947 owe
= wpa_bss_get_vendor_ie(open_bss
, OWE_IE_VENDOR_TYPE
);
948 if (!owe
|| wpa_bss_get_ie(open_bss
, WLAN_EID_RSN
)) {
949 wpa_dbg(wpa_s
, MSG_DEBUG
,
950 "OWE: transition mode open BSS unexpected info");
955 end
= owe
+ 2 + owe
[1];
957 if (end
- pos
< ETH_ALEN
+ 1)
959 if (os_memcmp(pos
, bss
->bssid
, ETH_ALEN
) != 0) {
960 wpa_dbg(wpa_s
, MSG_DEBUG
,
961 "OWE: transition mode BSSID mismatch: " MACSTR
,
967 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
969 wpa_dbg(wpa_s
, MSG_DEBUG
, "OWE: learned transition mode OWE SSID: %s",
970 wpa_ssid_txt(pos
, ssid_len
));
971 os_memcpy(bss
->ssid
, pos
, ssid_len
);
972 bss
->ssid_len
= ssid_len
;
973 #endif /* CONFIG_OWE */
977 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
978 int i
, struct wpa_bss
*bss
,
979 struct wpa_ssid
*group
,
980 int only_first_ssid
, int debug_print
)
982 u8 wpa_ie_len
, rsn_ie_len
;
984 struct wpa_blacklist
*e
;
986 struct wpa_ssid
*ssid
;
989 const u8
*assoc_disallow
;
990 #endif /* CONFIG_MBO */
991 const u8
*match_ssid
;
992 size_t match_ssid_len
;
994 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
995 wpa_ie_len
= ie
? ie
[1] : 0;
997 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
998 rsn_ie_len
= ie
? ie
[1] : 0;
1000 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1004 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
1005 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
1006 i
, MAC2STR(bss
->bssid
),
1007 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1008 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
1010 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
1012 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
1013 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
1015 osen
? " osen=1" : "");
1018 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
1021 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
1023 * When only a single network is enabled, we can
1024 * trigger blacklisting on the first failure. This
1025 * should not be done with multiple enabled networks to
1026 * avoid getting forced to move into a worse ESS on
1027 * single error if there are no other BSSes of the
1032 if (e
->count
> limit
) {
1034 wpa_dbg(wpa_s
, MSG_DEBUG
,
1035 " skip - blacklisted (count=%d limit=%d)",
1042 match_ssid
= bss
->ssid
;
1043 match_ssid_len
= bss
->ssid_len
;
1044 owe_trans_ssid(wpa_s
, bss
, &match_ssid
, &match_ssid_len
);
1046 if (match_ssid_len
== 0) {
1048 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
1052 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
1054 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
1058 if (disallowed_ssid(wpa_s
, match_ssid
, match_ssid_len
)) {
1060 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
1064 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
1066 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
1067 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
1070 if (wpas_network_disabled(wpa_s
, ssid
)) {
1072 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
1076 res
= wpas_temp_disabled(wpa_s
, ssid
);
1079 wpa_dbg(wpa_s
, MSG_DEBUG
,
1080 " skip - disabled temporarily for %d second(s)",
1086 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
1088 wpa_dbg(wpa_s
, MSG_DEBUG
,
1089 " skip - blacklisted (WPS)");
1093 if (wpa
&& ssid
->ssid_len
== 0 &&
1094 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1097 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1098 /* Only allow wildcard SSID match if an AP
1099 * advertises active WPS operation that matches
1102 if (ssid
->ssid_len
== 0 &&
1103 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
1106 #endif /* CONFIG_WPS */
1108 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1109 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1113 (match_ssid_len
!= ssid
->ssid_len
||
1114 os_memcmp(match_ssid
, ssid
->ssid
, match_ssid_len
) != 0)) {
1116 wpa_dbg(wpa_s
, MSG_DEBUG
,
1117 " skip - SSID mismatch");
1121 if (ssid
->bssid_set
&&
1122 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1124 wpa_dbg(wpa_s
, MSG_DEBUG
,
1125 " skip - BSSID mismatch");
1129 /* check blacklist */
1130 if (ssid
->num_bssid_blacklist
&&
1131 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1132 ssid
->num_bssid_blacklist
)) {
1134 wpa_dbg(wpa_s
, MSG_DEBUG
,
1135 " skip - BSSID blacklisted");
1139 /* if there is a whitelist, only accept those APs */
1140 if (ssid
->num_bssid_whitelist
&&
1141 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1142 ssid
->num_bssid_whitelist
)) {
1144 wpa_dbg(wpa_s
, MSG_DEBUG
,
1145 " skip - BSSID not in whitelist");
1149 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1153 if (!osen
&& !wpa
&&
1154 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1155 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1156 !(ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1157 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1159 wpa_dbg(wpa_s
, MSG_DEBUG
,
1160 " skip - non-WPA network not allowed");
1164 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1165 has_wep_key(ssid
)) {
1167 wpa_dbg(wpa_s
, MSG_DEBUG
,
1168 " skip - ignore WPA/WPA2 AP for WEP network block");
1172 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1174 wpa_dbg(wpa_s
, MSG_DEBUG
,
1175 " skip - non-OSEN network not allowed");
1179 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1181 wpa_dbg(wpa_s
, MSG_DEBUG
,
1182 " skip - privacy mismatch");
1186 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1187 !bss_is_pbss(bss
)) {
1189 wpa_dbg(wpa_s
, MSG_DEBUG
,
1190 " skip - not ESS, PBSS, or MBSS");
1194 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1196 wpa_dbg(wpa_s
, MSG_DEBUG
,
1197 " skip - PBSS mismatch (ssid %d bss %d)",
1198 ssid
->pbss
, bss_is_pbss(bss
));
1202 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1204 wpa_dbg(wpa_s
, MSG_DEBUG
,
1205 " skip - frequency not allowed");
1210 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1211 ssid
->frequency
!= bss
->freq
) {
1213 wpa_dbg(wpa_s
, MSG_DEBUG
,
1214 " skip - frequency not allowed (mesh)");
1217 #endif /* CONFIG_MESH */
1219 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1221 wpa_dbg(wpa_s
, MSG_DEBUG
,
1222 " skip - rate sets do not match");
1226 #ifndef CONFIG_IBSS_RSN
1227 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1228 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1229 WPA_KEY_MGMT_WPA_NONE
))) {
1231 wpa_dbg(wpa_s
, MSG_DEBUG
,
1232 " skip - IBSS RSN not supported in the build");
1235 #endif /* !CONFIG_IBSS_RSN */
1238 if (ssid
->p2p_group
&&
1239 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1240 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1242 wpa_dbg(wpa_s
, MSG_DEBUG
,
1243 " skip - no P2P IE seen");
1247 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1248 struct wpabuf
*p2p_ie
;
1249 u8 dev_addr
[ETH_ALEN
];
1251 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1254 wpa_dbg(wpa_s
, MSG_DEBUG
,
1255 " skip - no P2P element");
1258 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1259 bss
, P2P_IE_VENDOR_TYPE
);
1260 if (p2p_ie
== NULL
) {
1262 wpa_dbg(wpa_s
, MSG_DEBUG
,
1263 " skip - could not fetch P2P element");
1267 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1268 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1271 wpa_dbg(wpa_s
, MSG_DEBUG
,
1272 " skip - no matching GO P2P Device Address in P2P element");
1273 wpabuf_free(p2p_ie
);
1276 wpabuf_free(p2p_ie
);
1280 * TODO: skip the AP if its P2P IE has Group Formation
1281 * bit set in the P2P Group Capability Bitmap and we
1282 * are not in Group Formation with that device.
1284 #endif /* CONFIG_P2P */
1286 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1288 struct os_reltime diff
;
1290 os_reltime_sub(&wpa_s
->scan_min_time
,
1291 &bss
->last_update
, &diff
);
1293 wpa_dbg(wpa_s
, MSG_DEBUG
,
1294 " skip - scan result not recent enough (%u.%06u seconds too old)",
1295 (unsigned int) diff
.sec
,
1296 (unsigned int) diff
.usec
);
1300 #ifdef CONFIG_TESTING_OPTIONS
1301 if (wpa_s
->ignore_assoc_disallow
)
1302 goto skip_assoc_disallow
;
1303 #endif /* CONFIG_TESTING_OPTIONS */
1304 assoc_disallow
= wpas_mbo_get_bss_attr(
1305 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1306 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1308 wpa_dbg(wpa_s
, MSG_DEBUG
,
1309 " skip - MBO association disallowed (reason %u)",
1314 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1316 wpa_dbg(wpa_s
, MSG_DEBUG
,
1317 " skip - MBO retry delay has not passed yet");
1320 #ifdef CONFIG_TESTING_OPTIONS
1321 skip_assoc_disallow
:
1322 #endif /* CONFIG_TESTING_OPTIONS */
1323 #endif /* CONFIG_MBO */
1326 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
1327 !wpa_sm_pmksa_exists(wpa_s
->wpa
, bss
->bssid
, ssid
) &&
1328 (!ssid
->dpp_connector
||
1329 !ssid
->dpp_netaccesskey
||
1330 !ssid
->dpp_csign
)) {
1332 wpa_dbg(wpa_s
, MSG_DEBUG
,
1333 " skip - no PMKSA entry for DPP");
1336 #endif /* CONFIG_DPP */
1338 /* Matching configuration found */
1342 /* No matching configuration found */
1347 static struct wpa_bss
*
1348 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1349 struct wpa_ssid
*group
,
1350 struct wpa_ssid
**selected_ssid
,
1351 int only_first_ssid
)
1355 if (wpa_s
->current_ssid
) {
1356 struct wpa_ssid
*ssid
;
1358 wpa_dbg(wpa_s
, MSG_DEBUG
,
1359 "Scan results matching the currently selected network");
1360 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1361 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1363 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1364 only_first_ssid
, 0);
1365 if (ssid
!= wpa_s
->current_ssid
)
1367 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1368 " freq=%d level=%d snr=%d est_throughput=%u",
1369 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1370 bss
->snr
, bss
->est_throughput
);
1374 if (only_first_ssid
)
1375 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1378 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1381 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1382 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1383 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1384 only_first_ssid
, 1);
1385 if (!*selected_ssid
)
1387 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1389 MAC2STR(bss
->bssid
),
1390 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1398 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1399 struct wpa_ssid
**selected_ssid
)
1401 struct wpa_bss
*selected
= NULL
;
1403 struct wpa_ssid
*next_ssid
= NULL
;
1404 struct wpa_ssid
*ssid
;
1406 if (wpa_s
->last_scan_res
== NULL
||
1407 wpa_s
->last_scan_res_used
== 0)
1408 return NULL
; /* no scan results from last update */
1410 if (wpa_s
->next_ssid
) {
1411 /* check that next_ssid is still valid */
1412 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1413 if (ssid
== wpa_s
->next_ssid
)
1417 wpa_s
->next_ssid
= NULL
;
1420 while (selected
== NULL
) {
1421 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1422 if (next_ssid
&& next_ssid
->priority
==
1423 wpa_s
->conf
->pssid
[prio
]->priority
) {
1424 selected
= wpa_supplicant_select_bss(
1425 wpa_s
, next_ssid
, selected_ssid
, 1);
1429 selected
= wpa_supplicant_select_bss(
1430 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1436 if (selected
== NULL
&& wpa_s
->blacklist
&&
1437 !wpa_s
->countermeasures
) {
1438 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1439 "blacklist and try again");
1440 wpa_blacklist_clear(wpa_s
);
1441 wpa_s
->blacklist_cleared
++;
1442 } else if (selected
== NULL
)
1446 ssid
= *selected_ssid
;
1447 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1448 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1449 const char *field_name
, *txt
= NULL
;
1451 wpa_dbg(wpa_s
, MSG_DEBUG
,
1452 "PSK/passphrase not yet available for the selected network");
1454 wpas_notify_network_request(wpa_s
, ssid
,
1455 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1457 field_name
= wpa_supplicant_ctrl_req_to_string(
1458 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1459 if (field_name
== NULL
)
1462 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1471 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1472 int timeout_sec
, int timeout_usec
)
1474 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1476 * No networks are enabled; short-circuit request so
1477 * we don't wait timeout seconds before transitioning
1478 * to INACTIVE state.
1480 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1481 "since there are no enabled networks");
1482 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1486 wpa_s
->scan_for_connection
= 1;
1487 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1491 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1492 struct wpa_bss
*selected
,
1493 struct wpa_ssid
*ssid
)
1495 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1496 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1497 "PBC session overlap");
1498 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1500 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1501 wpa_s
->p2p_in_provisioning
) {
1502 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1506 #endif /* CONFIG_P2P */
1509 wpas_wps_pbc_overlap(wpa_s
);
1510 wpas_wps_cancel(wpa_s
);
1511 #endif /* CONFIG_WPS */
1515 wpa_msg(wpa_s
, MSG_DEBUG
,
1516 "Considering connect request: reassociate: %d selected: "
1517 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1518 " wpa_state: %s ssid=%p current_ssid=%p",
1519 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1520 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1521 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1522 ssid
, wpa_s
->current_ssid
);
1525 * Do not trigger new association unless the BSSID has changed or if
1526 * reassociation is requested. If we are in process of associating with
1527 * the selected BSSID, do not trigger new attempt.
1529 if (wpa_s
->reassociate
||
1530 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1531 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1532 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1533 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1534 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1536 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1537 ssid
!= wpa_s
->current_ssid
)))) {
1538 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1539 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1542 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1543 MAC2STR(selected
->bssid
));
1544 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1546 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1547 "connect with the selected AP");
1554 static struct wpa_ssid
*
1555 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1558 struct wpa_ssid
*ssid
;
1560 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1561 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1563 if (wpas_network_disabled(wpa_s
, ssid
))
1565 #ifndef CONFIG_IBSS_RSN
1566 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1567 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1568 WPA_KEY_MGMT_WPA_NONE
))) {
1569 wpa_msg(wpa_s
, MSG_INFO
,
1570 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1571 wpa_ssid_txt(ssid
->ssid
,
1575 #endif /* !CONFIG_IBSS_RSN */
1576 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1577 ssid
->mode
== IEEE80211_MODE_AP
||
1578 ssid
->mode
== IEEE80211_MODE_MESH
)
1586 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1587 * on BSS added and BSS changed events */
1588 static void wpa_supplicant_rsn_preauth_scan_results(
1589 struct wpa_supplicant
*wpa_s
)
1591 struct wpa_bss
*bss
;
1593 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1596 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1597 const u8
*ssid
, *rsn
;
1599 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1603 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1607 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1613 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1614 struct wpa_bss
*selected
,
1615 struct wpa_ssid
*ssid
)
1617 struct wpa_bss
*current_bss
= NULL
;
1618 #ifndef CONFIG_NO_ROAMING
1621 int cur_est
, sel_est
;
1622 #endif /* CONFIG_NO_ROAMING */
1624 if (wpa_s
->reassociate
)
1625 return 1; /* explicit request to reassociate */
1626 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1627 return 1; /* we are not associated; continue */
1628 if (wpa_s
->current_ssid
== NULL
)
1629 return 1; /* unknown current SSID */
1630 if (wpa_s
->current_ssid
!= ssid
)
1631 return 1; /* different network block */
1633 if (wpas_driver_bss_selection(wpa_s
))
1634 return 0; /* Driver-based roaming */
1636 if (wpa_s
->current_ssid
->ssid
)
1637 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1638 wpa_s
->current_ssid
->ssid
,
1639 wpa_s
->current_ssid
->ssid_len
);
1641 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1644 return 1; /* current BSS not seen in scan results */
1646 if (current_bss
== selected
)
1649 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1650 return 1; /* current BSS not seen in the last scan */
1652 #ifndef CONFIG_NO_ROAMING
1653 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1654 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1655 " freq=%d level=%d snr=%d est_throughput=%u",
1656 MAC2STR(current_bss
->bssid
),
1657 current_bss
->freq
, current_bss
->level
,
1658 current_bss
->snr
, current_bss
->est_throughput
);
1659 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1660 " freq=%d level=%d snr=%d est_throughput=%u",
1661 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1662 selected
->snr
, selected
->est_throughput
);
1664 if (wpa_s
->current_ssid
->bssid_set
&&
1665 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1667 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1668 "has preferred BSSID");
1672 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1673 wpa_dbg(wpa_s
, MSG_DEBUG
,
1674 "Allow reassociation - selected BSS has better estimated throughput");
1678 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1680 if (current_bss
->level
< 0 &&
1681 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1682 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1687 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1688 wpa_dbg(wpa_s
, MSG_DEBUG
,
1689 "Skip roam - Current BSS has better estimated throughput");
1693 cur_est
= current_bss
->est_throughput
;
1694 sel_est
= selected
->est_throughput
;
1696 if (current_bss
->level
< 0) {
1697 if (current_bss
->level
< -85)
1699 else if (current_bss
->level
< -80)
1701 else if (current_bss
->level
< -75)
1703 else if (current_bss
->level
< -70)
1707 if (cur_est
> sel_est
* 1.5)
1709 else if (cur_est
> sel_est
* 1.2)
1711 else if (cur_est
> sel_est
* 1.1)
1713 else if (cur_est
> sel_est
)
1719 /* Make it easier to move to 5 GHz band */
1720 if (sel_est
> cur_est
* 1.5)
1722 else if (sel_est
> cur_est
* 1.2)
1724 else if (sel_est
> cur_est
* 1.1)
1727 if (min_diff
> reduce
)
1732 diff
= abs(current_bss
->level
- selected
->level
);
1733 if (diff
< min_diff
) {
1734 wpa_dbg(wpa_s
, MSG_DEBUG
,
1735 "Skip roam - too small difference in signal level (%d < %d)",
1740 wpa_dbg(wpa_s
, MSG_DEBUG
,
1741 "Allow reassociation due to difference in signal level (%d >= %d)",
1744 #else /* CONFIG_NO_ROAMING */
1746 #endif /* CONFIG_NO_ROAMING */
1751 * Return a negative value if no scan results could be fetched or if scan
1752 * results should not be shared with other virtual interfaces.
1753 * Return 0 if scan results were fetched and may be shared with other
1755 * Return 1 if scan results may be shared with other virtual interfaces but may
1756 * not trigger any operations.
1757 * Return 2 if the interface was removed and cannot be used.
1759 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1760 union wpa_event_data
*data
,
1761 int own_request
, int update_only
)
1763 struct wpa_scan_results
*scan_res
= NULL
;
1766 #ifndef CONFIG_NO_RANDOM_POOL
1768 #endif /* CONFIG_NO_RANDOM_POOL */
1771 if (wpa_s
->ap_iface
)
1773 #endif /* CONFIG_AP */
1775 wpa_supplicant_notify_scanning(wpa_s
, 0);
1777 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1778 data
? &data
->scan_info
:
1780 if (scan_res
== NULL
) {
1781 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1782 wpa_s
->scan_res_handler
== scan_only_handler
)
1786 if (data
&& data
->scan_info
.external_scan
)
1788 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1790 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1792 goto scan_work_done
;
1795 #ifndef CONFIG_NO_RANDOM_POOL
1796 num
= scan_res
->num
;
1799 for (i
= 0; i
< num
; i
++) {
1801 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1802 buf
[0] = res
->bssid
[5];
1803 buf
[1] = res
->qual
& 0xff;
1804 buf
[2] = res
->noise
& 0xff;
1805 buf
[3] = res
->level
& 0xff;
1806 buf
[4] = res
->tsf
& 0xff;
1807 random_add_randomness(buf
, sizeof(buf
));
1809 #endif /* CONFIG_NO_RANDOM_POOL */
1813 goto scan_work_done
;
1816 if (own_request
&& wpa_s
->scan_res_handler
&&
1817 !(data
&& data
->scan_info
.external_scan
)) {
1818 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1819 struct wpa_scan_results
*scan_res
);
1821 scan_res_handler
= wpa_s
->scan_res_handler
;
1822 wpa_s
->scan_res_handler
= NULL
;
1823 scan_res_handler(wpa_s
, scan_res
);
1825 goto scan_work_done
;
1829 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1831 if (wpa_s
->ap_iface
->scan_cb
)
1832 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1833 #endif /* CONFIG_AP */
1834 goto scan_work_done
;
1837 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1838 wpa_s
->own_scan_running
,
1839 data
? data
->scan_info
.external_scan
: 0);
1840 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1841 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1842 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1843 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1844 wpa_s
->manual_scan_id
);
1845 wpa_s
->manual_scan_use_id
= 0;
1847 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1849 wpas_notify_scan_results(wpa_s
);
1851 wpas_notify_scan_done(wpa_s
, 1);
1853 if (data
&& data
->scan_info
.external_scan
) {
1854 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1855 wpa_scan_results_free(scan_res
);
1859 if (wnm_scan_process(wpa_s
, 1) > 0)
1860 goto scan_work_done
;
1862 if (sme_proc_obss_scan(wpa_s
) > 0)
1863 goto scan_work_done
;
1866 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1867 goto scan_work_done
;
1869 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1870 goto scan_work_done
;
1872 if (autoscan_notify_scan(wpa_s
, scan_res
))
1873 goto scan_work_done
;
1875 if (wpa_s
->disconnected
) {
1876 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1877 goto scan_work_done
;
1880 if (!wpas_driver_bss_selection(wpa_s
) &&
1881 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1882 goto scan_work_done
;
1884 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1886 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1887 wpa_s
->wpa_state
< WPA_COMPLETED
)
1888 goto scan_work_done
;
1890 wpa_scan_results_free(scan_res
);
1892 if (own_request
&& wpa_s
->scan_work
) {
1893 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1894 wpa_s
->scan_work
= NULL
;
1895 radio_work_done(work
);
1898 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1901 wpa_scan_results_free(scan_res
);
1902 if (own_request
&& wpa_s
->scan_work
) {
1903 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1904 wpa_s
->scan_work
= NULL
;
1905 radio_work_done(work
);
1911 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1912 int new_scan
, int own_request
)
1914 struct wpa_bss
*selected
;
1915 struct wpa_ssid
*ssid
= NULL
;
1916 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1918 if (time_to_reenable
> 0) {
1919 wpa_dbg(wpa_s
, MSG_DEBUG
,
1920 "Postpone network selection by %d seconds since all networks are disabled",
1922 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1923 eloop_register_timeout(time_to_reenable
, 0,
1924 wpas_network_reenabled
, wpa_s
, NULL
);
1928 if (wpa_s
->p2p_mgmt
)
1929 return 0; /* no normal connection on p2p_mgmt interface */
1931 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1935 wpa_msg(wpa_s
, MSG_INFO
,
1936 "Avoiding join because we already joined a mesh group");
1939 #endif /* CONFIG_MESH */
1943 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1946 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1950 if (ssid
!= wpa_s
->current_ssid
&&
1951 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1952 wpa_s
->own_disconnect_req
= 1;
1953 wpa_supplicant_deauthenticate(
1954 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1957 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1958 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1962 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1964 * Do not allow other virtual radios to trigger operations based
1965 * on these scan results since we do not want them to start
1966 * other associations at the same time.
1970 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1971 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1973 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1974 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1976 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1977 } else if (own_request
) {
1979 * No SSID found. If SCAN results are as a result of
1980 * own scan request and not due to a scan request on
1981 * another shared interface, try another scan.
1983 int timeout_sec
= wpa_s
->scan_interval
;
1984 int timeout_usec
= 0;
1988 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1994 if (wpa_s
->p2p_in_provisioning
||
1995 wpa_s
->show_group_started
||
1996 wpa_s
->p2p_in_invitation
) {
1998 * Use shorter wait during P2P Provisioning
1999 * state and during P2P join-a-group operation
2000 * to speed up group formation.
2003 timeout_usec
= 250000;
2004 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2008 #endif /* CONFIG_P2P */
2009 #ifdef CONFIG_INTERWORKING
2010 if (wpa_s
->conf
->auto_interworking
&&
2011 wpa_s
->conf
->interworking
&&
2012 wpa_s
->conf
->cred
) {
2013 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
2014 "start ANQP fetch since no matching "
2016 wpa_s
->network_select
= 1;
2017 wpa_s
->auto_network_select
= 1;
2018 interworking_start_fetch_anqp(wpa_s
);
2021 #endif /* CONFIG_INTERWORKING */
2023 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
2024 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
2026 timeout_usec
= 500000;
2027 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2031 #endif /* CONFIG_WPS */
2032 if (wpa_supplicant_req_sched_scan(wpa_s
))
2033 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
2036 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2037 WPA_EVENT_NETWORK_NOT_FOUND
);
2044 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
2045 union wpa_event_data
*data
)
2047 struct wpa_supplicant
*ifs
;
2050 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
2053 * Interface may have been removed, so must not dereference
2061 * If no scan results could be fetched, then no need to
2062 * notify those interfaces that did not actually request
2063 * this scan. Similarly, if scan results started a new operation on this
2064 * interface, do not notify other interfaces to avoid concurrent
2065 * operations during a connection attempt.
2071 * Check other interfaces to see if they share the same radio. If
2072 * so, they get updated with this same scan info.
2074 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2077 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
2078 "sibling", ifs
->ifname
);
2079 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
2089 #endif /* CONFIG_NO_SCAN_PROCESSING */
2092 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
2094 #ifdef CONFIG_NO_SCAN_PROCESSING
2096 #else /* CONFIG_NO_SCAN_PROCESSING */
2097 struct os_reltime now
;
2099 wpa_s
->ignore_post_flush_scan_res
= 0;
2101 if (wpa_s
->last_scan_res_used
== 0)
2104 os_get_reltime(&now
);
2105 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
2106 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
2110 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
2111 #endif /* CONFIG_NO_SCAN_PROCESSING */
2116 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
2118 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2120 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2123 if (!wpa_s
->no_keep_alive
) {
2124 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2125 MAC2STR(wpa_s
->bssid
));
2126 /* TODO: could skip this if normal data traffic has been sent */
2127 /* TODO: Consider using some more appropriate data frame for
2130 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2135 if (wpa_s
->sme
.bss_max_idle_period
) {
2137 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2140 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2141 wnm_bss_keep_alive
, wpa_s
, NULL
);
2143 #endif /* CONFIG_SME */
2147 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2148 const u8
*ies
, size_t ies_len
)
2150 struct ieee802_11_elems elems
;
2155 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2159 if (elems
.bss_max_idle_period
) {
2161 wpa_s
->sme
.bss_max_idle_period
=
2162 WPA_GET_LE16(elems
.bss_max_idle_period
);
2163 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2164 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2165 (elems
.bss_max_idle_period
[2] & 0x01) ?
2166 " (protected keep-live required)" : "");
2167 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2168 wpa_s
->sme
.bss_max_idle_period
= 1;
2169 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2170 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2171 /* msec times 1000 */
2172 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2175 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2176 wnm_bss_keep_alive
, wpa_s
,
2180 #endif /* CONFIG_SME */
2183 #endif /* CONFIG_WNM */
2186 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2189 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2190 #endif /* CONFIG_WNM */
2194 #ifdef CONFIG_INTERWORKING
2196 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2201 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2202 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2204 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2211 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2212 const u8
*ies
, size_t ies_len
)
2214 struct ieee802_11_elems elems
;
2219 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2222 if (elems
.qos_map_set
) {
2223 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2224 elems
.qos_map_set_len
);
2228 #endif /* CONFIG_INTERWORKING */
2232 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2233 const u8
*ie
, size_t ie_len
)
2235 struct mb_ies_info mb_ies
;
2237 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2240 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2242 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2247 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2252 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2253 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2254 (unsigned int) len
);
2255 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2256 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2264 if (mb_ies
.nof_ies
> 0) {
2265 wpabuf_free(wpa_s
->received_mb_ies
);
2266 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2272 #endif /* CONFIG_FST */
2275 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2276 union wpa_event_data
*data
)
2278 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2280 #ifdef CONFIG_IEEE80211R
2282 #endif /* CONFIG_IEEE80211R */
2284 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2285 if (data
->assoc_info
.req_ies
)
2286 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2287 data
->assoc_info
.req_ies_len
);
2288 if (data
->assoc_info
.resp_ies
) {
2289 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2290 data
->assoc_info
.resp_ies_len
);
2292 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2293 data
->assoc_info
.resp_ies_len
);
2294 #endif /* CONFIG_TDLS */
2296 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2297 data
->assoc_info
.resp_ies_len
);
2298 #endif /* CONFIG_WNM */
2299 #ifdef CONFIG_INTERWORKING
2300 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2301 data
->assoc_info
.resp_ies_len
);
2302 #endif /* CONFIG_INTERWORKING */
2304 if (data
->assoc_info
.beacon_ies
)
2305 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2306 data
->assoc_info
.beacon_ies
,
2307 data
->assoc_info
.beacon_ies_len
);
2308 if (data
->assoc_info
.freq
)
2309 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2310 data
->assoc_info
.freq
);
2312 p
= data
->assoc_info
.req_ies
;
2313 l
= data
->assoc_info
.req_ies_len
;
2315 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2316 while (p
&& l
>= 2) {
2319 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2323 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2324 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2325 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2326 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2327 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2328 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2331 wpa_find_assoc_pmkid(wpa_s
);
2337 if (!found
&& data
->assoc_info
.req_ies
)
2338 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2342 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2343 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2344 (!data
->assoc_info
.resp_frame
||
2345 fils_process_assoc_resp(wpa_s
->wpa
,
2346 data
->assoc_info
.resp_frame
,
2347 data
->assoc_info
.resp_frame_len
) < 0)) {
2348 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2351 #endif /* CONFIG_SME */
2353 /* Additional processing for FILS when SME is in driver */
2354 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2355 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2356 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2357 #endif /* CONFIG_FILS */
2360 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2361 (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2362 owe_process_assoc_resp(wpa_s
->wpa
, bssid
,
2363 data
->assoc_info
.resp_ies
,
2364 data
->assoc_info
.resp_ies_len
) < 0)) {
2365 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2368 #endif /* CONFIG_OWE */
2370 #ifdef CONFIG_IEEE80211R
2372 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2373 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2374 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2375 data
->assoc_info
.resp_ies
,
2376 data
->assoc_info
.resp_ies_len
,
2378 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2379 "Reassociation Response failed");
2380 wpa_supplicant_deauthenticate(
2381 wpa_s
, WLAN_REASON_INVALID_IE
);
2386 p
= data
->assoc_info
.resp_ies
;
2387 l
= data
->assoc_info
.resp_ies_len
;
2389 #ifdef CONFIG_WPS_STRICT
2390 if (p
&& wpa_s
->current_ssid
&&
2391 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2393 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2395 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2396 "include WPS IE in (Re)Association Response");
2400 if (wps_validate_assoc_resp(wps
) < 0) {
2402 wpa_supplicant_deauthenticate(
2403 wpa_s
, WLAN_REASON_INVALID_IE
);
2408 #endif /* CONFIG_WPS_STRICT */
2410 /* Go through the IEs and make a copy of the MDIE, if present. */
2411 while (p
&& l
>= 2) {
2414 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2418 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2419 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2420 wpa_s
->sme
.ft_used
= 1;
2421 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2422 MOBILITY_DOMAIN_ID_LEN
);
2428 #endif /* CONFIG_SME */
2430 /* Process FT when SME is in the driver */
2431 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2432 wpa_ft_is_completed(wpa_s
->wpa
)) {
2433 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2434 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2435 data
->assoc_info
.resp_ies
,
2436 data
->assoc_info
.resp_ies_len
,
2438 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2439 "Reassociation Response failed");
2440 wpa_supplicant_deauthenticate(
2441 wpa_s
, WLAN_REASON_INVALID_IE
);
2444 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2447 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2448 data
->assoc_info
.resp_ies_len
);
2449 #endif /* CONFIG_IEEE80211R */
2451 /* WPA/RSN IE from Beacon/ProbeResp */
2452 p
= data
->assoc_info
.beacon_ies
;
2453 l
= data
->assoc_info
.beacon_ies_len
;
2455 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2457 wpa_found
= rsn_found
= 0;
2458 while (p
&& l
>= 2) {
2461 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2466 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2467 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2469 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2473 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2475 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2482 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2483 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2484 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2485 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2486 if (wpa_found
|| rsn_found
)
2487 wpa_s
->ap_ies_from_associnfo
= 1;
2489 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2490 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2491 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2493 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2494 wpa_supplicant_update_scan_results(wpa_s
);
2497 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2503 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2505 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2507 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2510 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2513 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2514 WPA_IE_VENDOR_TYPE
);
2515 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2517 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2518 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2519 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2520 bss_rsn
? 2 + bss_rsn
[1] : 0))
2527 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2528 union wpa_event_data
*data
)
2531 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2532 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2533 const u8
*ieprb
, *iebcn
;
2535 wpabuf_free(wpa_s
->received_mb_ies
);
2536 wpa_s
->received_mb_ies
= NULL
;
2539 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2540 wpa_printf(MSG_DEBUG
,
2541 "FST: MB IEs updated from Association Response frame");
2546 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2547 wpa_printf(MSG_DEBUG
,
2548 "FST: MB IEs updated from association event Beacon IEs");
2555 ieprb
= (const u8
*) (bss
+ 1);
2556 iebcn
= ieprb
+ bss
->ie_len
;
2558 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2559 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2560 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2561 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2562 #endif /* CONFIG_FST */
2566 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2567 union wpa_event_data
*data
)
2570 int ft_completed
, already_authorized
;
2574 if (wpa_s
->ap_iface
) {
2577 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2578 data
->assoc_info
.addr
,
2579 data
->assoc_info
.req_ies
,
2580 data
->assoc_info
.req_ies_len
,
2581 data
->assoc_info
.reassoc
);
2584 #endif /* CONFIG_AP */
2586 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2588 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2589 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2592 * FILS authentication can share the same mechanism to mark the
2593 * connection fully authenticated, so set ft_completed also based on
2597 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2599 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2600 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2601 wpa_supplicant_deauthenticate(
2602 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2606 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2607 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2608 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2609 MACSTR
, MAC2STR(bssid
));
2611 random_add_randomness(bssid
, ETH_ALEN
);
2612 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2613 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2614 wpas_notify_bssid_changed(wpa_s
);
2616 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2617 wpa_clear_keys(wpa_s
, bssid
);
2619 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2620 wpa_supplicant_deauthenticate(
2621 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2626 if (wpa_s
->conf
->ap_scan
== 1 &&
2627 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2628 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2629 wpa_msg(wpa_s
, MSG_WARNING
,
2630 "WPA/RSN IEs not updated");
2633 wpas_fst_update_mb_assoc(wpa_s
, data
);
2636 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2637 wpa_s
->sme
.prev_bssid_set
= 1;
2638 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2639 #endif /* CONFIG_SME */
2641 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2642 if (wpa_s
->current_ssid
) {
2643 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2644 * initialized before association, but for other modes,
2645 * initialize PC/SC here, if the current configuration needs
2646 * smartcard or SIM/USIM. */
2647 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2649 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2651 l2_packet_notify_auth_start(wpa_s
->l2
);
2653 already_authorized
= data
&& data
->assoc_info
.authorized
;
2656 * Set portEnabled first to FALSE in order to get EAP state machine out
2657 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2658 * state machine may transit to AUTHENTICATING state based on obsolete
2659 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2660 * AUTHENTICATED without ever giving chance to EAP state machine to
2663 if (!ft_completed
&& !already_authorized
) {
2664 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2665 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2667 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2668 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
||
2669 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2671 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2672 /* 802.1X::portControl = Auto */
2673 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2674 wpa_s
->eapol_received
= 0;
2675 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2676 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2677 (wpa_s
->current_ssid
&&
2678 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2679 if (wpa_s
->current_ssid
&&
2680 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2682 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2684 * Set the key after having received joined-IBSS event
2687 wpa_supplicant_set_wpa_none_key(wpa_s
,
2688 wpa_s
->current_ssid
);
2690 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2691 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2692 } else if (!ft_completed
) {
2693 /* Timeout for receiving the first EAPOL packet */
2694 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2696 wpa_supplicant_cancel_scan(wpa_s
);
2698 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2699 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2701 * We are done; the driver will take care of RSN 4-way
2704 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2705 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2706 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2707 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2708 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2709 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2711 * The driver will take care of RSN 4-way handshake, so we need
2712 * to allow EAPOL supplicant to complete its work without
2713 * waiting for WPA supplicant.
2715 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2716 } else if (ft_completed
) {
2718 * FT protocol completed - make sure EAPOL state machine ends
2719 * up in authenticated.
2721 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2722 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2723 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2724 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2727 wpa_s
->last_eapol_matches_bssid
= 0;
2729 if (wpa_s
->pending_eapol_rx
) {
2730 struct os_reltime now
, age
;
2731 os_get_reltime(&now
);
2732 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2733 if (age
.sec
== 0 && age
.usec
< 200000 &&
2734 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2736 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2737 "frame that was received just before "
2738 "association notification");
2739 wpa_supplicant_rx_eapol(
2740 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2741 wpabuf_head(wpa_s
->pending_eapol_rx
),
2742 wpabuf_len(wpa_s
->pending_eapol_rx
));
2744 wpabuf_free(wpa_s
->pending_eapol_rx
);
2745 wpa_s
->pending_eapol_rx
= NULL
;
2748 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2749 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2750 wpa_s
->current_ssid
&&
2751 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2752 /* Set static WEP keys again */
2753 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2756 #ifdef CONFIG_IBSS_RSN
2757 if (wpa_s
->current_ssid
&&
2758 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2759 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2760 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2761 wpa_s
->ibss_rsn
== NULL
) {
2762 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2763 if (!wpa_s
->ibss_rsn
) {
2764 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2765 wpa_supplicant_deauthenticate(
2766 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2770 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2772 #endif /* CONFIG_IBSS_RSN */
2774 wpas_wps_notify_assoc(wpa_s
, bssid
);
2777 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2778 data
->assoc_info
.resp_ies_len
,
2779 &data
->assoc_info
.wmm_params
);
2781 if (wpa_s
->reassoc_same_bss
)
2782 wmm_ac_restore_tspecs(wpa_s
);
2786 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2787 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2788 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2791 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2793 #endif /* CONFIG_FILS */
2797 static int disconnect_reason_recoverable(u16 reason_code
)
2799 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2800 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2801 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2805 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2807 int locally_generated
)
2811 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2813 * At least Host AP driver and a Prism3 card seemed to be
2814 * generating streams of disconnected events when configuring
2815 * IBSS for WPA-None. Ignore them for now.
2820 bssid
= wpa_s
->bssid
;
2821 if (is_zero_ether_addr(bssid
))
2822 bssid
= wpa_s
->pending_bssid
;
2824 if (!is_zero_ether_addr(bssid
) ||
2825 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2826 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2828 MAC2STR(bssid
), reason_code
,
2829 locally_generated
? " locally_generated=1" : "");
2834 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2835 int locally_generated
)
2837 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2838 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2839 return 0; /* Not in 4-way handshake with PSK */
2842 * It looks like connection was lost while trying to go through PSK
2843 * 4-way handshake. Filter out known disconnection cases that are caused
2844 * by something else than PSK mismatch to avoid confusing reports.
2847 if (locally_generated
) {
2848 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2856 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2858 int locally_generated
)
2862 u8 prev_pending_bssid
[ETH_ALEN
];
2863 struct wpa_bss
*fast_reconnect
= NULL
;
2864 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2865 struct wpa_ssid
*last_ssid
;
2866 struct wpa_bss
*curr
= NULL
;
2868 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2869 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2871 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2873 * At least Host AP driver and a Prism3 card seemed to be
2874 * generating streams of disconnected events when configuring
2875 * IBSS for WPA-None. Ignore them for now.
2877 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2878 "IBSS/WPA-None mode");
2882 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2883 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2886 * Remove the inactive AP (which is probably out of range) from
2887 * the BSS list after marking disassociation. In particular
2888 * mac80211-based drivers use the
2889 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2890 * locally generated disconnection events for cases where the
2891 * AP does not reply anymore.
2893 curr
= wpa_s
->current_bss
;
2895 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2896 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2897 "pre-shared key may be incorrect");
2898 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2899 return; /* P2P group removed */
2900 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2902 if (!wpa_s
->disconnected
&&
2903 (!wpa_s
->auto_reconnect_disabled
||
2904 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2905 wpas_wps_searching(wpa_s
) ||
2906 wpas_wps_reenable_networks_pending(wpa_s
))) {
2907 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2908 "reconnect (wps=%d/%d wpa_state=%d)",
2909 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2910 wpas_wps_searching(wpa_s
),
2912 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2913 wpa_s
->current_ssid
&&
2914 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2915 !locally_generated
&&
2916 disconnect_reason_recoverable(reason_code
)) {
2918 * It looks like the AP has dropped association with
2919 * us, but could allow us to get back in. Try to
2920 * reconnect to the same BSS without full scan to save
2921 * time for some common cases.
2923 fast_reconnect
= wpa_s
->current_bss
;
2924 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2925 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2926 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2928 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2931 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2932 "try to re-connect");
2933 wpa_s
->reassociate
= 0;
2934 wpa_s
->disconnected
= 1;
2936 wpa_supplicant_cancel_sched_scan(wpa_s
);
2938 bssid
= wpa_s
->bssid
;
2939 if (is_zero_ether_addr(bssid
))
2940 bssid
= wpa_s
->pending_bssid
;
2941 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2942 wpas_connection_failed(wpa_s
, bssid
);
2943 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2944 if (locally_generated
)
2945 wpa_s
->disconnect_reason
= -reason_code
;
2947 wpa_s
->disconnect_reason
= reason_code
;
2948 wpas_notify_disconnect_reason(wpa_s
);
2949 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2950 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2951 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2953 last_ssid
= wpa_s
->current_ssid
;
2954 wpa_supplicant_mark_disassoc(wpa_s
);
2957 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2959 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2960 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2961 wpa_s
->current_ssid
= last_ssid
;
2964 if (fast_reconnect
&&
2965 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2966 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2967 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2968 fast_reconnect
->ssid_len
) &&
2969 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2970 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2971 #ifndef CONFIG_NO_SCAN_PROCESSING
2972 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2973 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2974 fast_reconnect_ssid
) < 0) {
2975 /* Recover through full scan */
2976 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2978 #endif /* CONFIG_NO_SCAN_PROCESSING */
2979 } else if (fast_reconnect
) {
2981 * Could not reconnect to the same BSS due to network being
2982 * disabled. Use a new scan to match the alternative behavior
2983 * above, i.e., to continue automatic reconnection attempt in a
2984 * way that enforces disabled network rules.
2986 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2991 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2992 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2994 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2996 if (!wpa_s
->pending_mic_error_report
)
2999 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
3000 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
3001 wpa_s
->pending_mic_error_report
= 0;
3003 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3007 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
3008 union wpa_event_data
*data
)
3011 struct os_reltime t
;
3013 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
3014 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
3016 if ((wpa_s
->last_michael_mic_error
.sec
&&
3017 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
3018 wpa_s
->pending_mic_error_report
) {
3019 if (wpa_s
->pending_mic_error_report
) {
3021 * Send the pending MIC error report immediately since
3022 * we are going to start countermeasures and AP better
3025 wpa_sm_key_request(wpa_s
->wpa
, 1,
3026 wpa_s
->pending_mic_error_pairwise
);
3029 /* Send the new MIC error report immediately since we are going
3030 * to start countermeasures and AP better do the same.
3032 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3034 /* initialize countermeasures */
3035 wpa_s
->countermeasures
= 1;
3037 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
3039 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
3042 * Need to wait for completion of request frame. We do not get
3043 * any callback for the message completion, so just wait a
3044 * short while and hope for the best. */
3047 wpa_drv_set_countermeasures(wpa_s
, 1);
3048 wpa_supplicant_deauthenticate(wpa_s
,
3049 WLAN_REASON_MICHAEL_MIC_FAILURE
);
3050 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
3052 eloop_register_timeout(60, 0,
3053 wpa_supplicant_stop_countermeasures
,
3055 /* TODO: mark the AP rejected for 60 second. STA is
3056 * allowed to associate with another AP.. */
3058 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
3059 if (wpa_s
->mic_errors_seen
) {
3061 * Reduce the effectiveness of Michael MIC error
3062 * reports as a means for attacking against TKIP if
3063 * more than one MIC failure is noticed with the same
3064 * PTK. We delay the transmission of the reports by a
3065 * random time between 0 and 60 seconds in order to
3066 * force the attacker wait 60 seconds before getting
3067 * the information on whether a frame resulted in a MIC
3073 if (os_get_random(rval
, sizeof(rval
)) < 0)
3074 sec
= os_random() % 60;
3076 sec
= WPA_GET_BE32(rval
) % 60;
3077 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
3078 "report %d seconds", sec
);
3079 wpa_s
->pending_mic_error_report
= 1;
3080 wpa_s
->pending_mic_error_pairwise
= pairwise
;
3081 eloop_cancel_timeout(
3082 wpa_supplicant_delayed_mic_error_report
,
3084 eloop_register_timeout(
3085 sec
, os_random() % 1000000,
3086 wpa_supplicant_delayed_mic_error_report
,
3089 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3091 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3092 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
3093 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
3095 wpa_s
->last_michael_mic_error
= t
;
3096 wpa_s
->mic_errors_seen
++;
3100 #ifdef CONFIG_TERMINATE_ONLASTIF
3101 static int any_interfaces(struct wpa_supplicant
*head
)
3103 struct wpa_supplicant
*wpa_s
;
3105 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
3106 if (!wpa_s
->interface_removed
)
3110 #endif /* CONFIG_TERMINATE_ONLASTIF */
3114 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
3115 union wpa_event_data
*data
)
3117 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
3120 switch (data
->interface_status
.ievent
) {
3121 case EVENT_INTERFACE_ADDED
:
3122 if (!wpa_s
->interface_removed
)
3124 wpa_s
->interface_removed
= 0;
3125 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3126 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3127 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3128 "driver after interface was added");
3132 if (!wpa_s
->global
->p2p
&&
3133 !wpa_s
->global
->p2p_disabled
&&
3134 !wpa_s
->conf
->p2p_disabled
&&
3136 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3137 wpas_p2p_add_p2pdev_interface(
3138 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3139 wpa_printf(MSG_INFO
,
3140 "P2P: Failed to enable P2P Device interface");
3141 /* Try to continue without. P2P will be disabled. */
3143 #endif /* CONFIG_P2P */
3146 case EVENT_INTERFACE_REMOVED
:
3147 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3148 wpa_s
->interface_removed
= 1;
3149 wpa_supplicant_mark_disassoc(wpa_s
);
3150 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3151 l2_packet_deinit(wpa_s
->l2
);
3155 if (wpa_s
->global
->p2p
&&
3156 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3158 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3159 wpa_dbg(wpa_s
, MSG_DEBUG
,
3160 "Removing P2P Device interface");
3161 wpa_supplicant_remove_iface(
3162 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3164 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3166 #endif /* CONFIG_P2P */
3168 #ifdef CONFIG_MATCH_IFACE
3169 if (wpa_s
->matched
) {
3170 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3173 #endif /* CONFIG_MATCH_IFACE */
3175 #ifdef CONFIG_TERMINATE_ONLASTIF
3176 /* check if last interface */
3177 if (!any_interfaces(wpa_s
->global
->ifaces
))
3179 #endif /* CONFIG_TERMINATE_ONLASTIF */
3186 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3187 union wpa_event_data
*data
)
3191 switch (data
->tdls
.oper
) {
3192 case TDLS_REQUEST_SETUP
:
3193 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3194 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3195 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3197 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3199 case TDLS_REQUEST_TEARDOWN
:
3200 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3201 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3202 data
->tdls
.reason_code
);
3204 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3207 case TDLS_REQUEST_DISCOVER
:
3208 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3213 #endif /* CONFIG_TDLS */
3217 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3218 union wpa_event_data
*data
)
3222 switch (data
->wnm
.oper
) {
3223 case WNM_OPER_SLEEP
:
3224 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3225 "(action=%d, intval=%d)",
3226 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3227 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3228 data
->wnm
.sleep_intval
, NULL
);
3232 #endif /* CONFIG_WNM */
3235 #ifdef CONFIG_IEEE80211R
3237 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3238 union wpa_event_data
*data
)
3243 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3244 data
->ft_ies
.ies_len
,
3245 data
->ft_ies
.ft_action
,
3246 data
->ft_ies
.target_ap
,
3247 data
->ft_ies
.ric_ies
,
3248 data
->ft_ies
.ric_ies_len
) < 0) {
3249 /* TODO: prevent MLME/driver from trying to associate? */
3252 #endif /* CONFIG_IEEE80211R */
3255 #ifdef CONFIG_IBSS_RSN
3256 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3257 union wpa_event_data
*data
)
3259 struct wpa_ssid
*ssid
;
3260 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3264 ssid
= wpa_s
->current_ssid
;
3267 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3270 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3274 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3275 union wpa_event_data
*data
)
3277 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3282 /* check if the ssid is correctly configured as IBSS/RSN */
3283 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3286 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3287 data
->rx_mgmt
.frame_len
);
3289 #endif /* CONFIG_IBSS_RSN */
3292 #ifdef CONFIG_IEEE80211R
3293 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3296 const u8
*sta_addr
, *target_ap_addr
;
3299 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3300 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3301 return; /* only SME case supported for now */
3302 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3305 return; /* Only FT Action Response is supported for now */
3306 sta_addr
= data
+ 1;
3307 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3308 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3309 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3310 MACSTR
" TargetAP " MACSTR
" status %u",
3311 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3313 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3314 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3315 " in FT Action Response", MAC2STR(sta_addr
));
3320 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3321 "failure (status code %d)", status
);
3322 /* TODO: report error to FT code(?) */
3326 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3327 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3328 target_ap_addr
, NULL
, 0) < 0)
3333 struct wpa_bss
*bss
;
3334 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3336 wpa_s
->sme
.freq
= bss
->freq
;
3337 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3338 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3341 #endif /* CONFIG_SME */
3343 #endif /* CONFIG_IEEE80211R */
3346 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3347 struct unprot_deauth
*e
)
3349 #ifdef CONFIG_IEEE80211W
3350 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3351 "dropped: " MACSTR
" -> " MACSTR
3352 " (reason code %u)",
3353 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3354 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3355 #endif /* CONFIG_IEEE80211W */
3359 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3360 struct unprot_disassoc
*e
)
3362 #ifdef CONFIG_IEEE80211W
3363 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3364 "dropped: " MACSTR
" -> " MACSTR
3365 " (reason code %u)",
3366 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3367 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3368 #endif /* CONFIG_IEEE80211W */
3372 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3373 u16 reason_code
, int locally_generated
,
3374 const u8
*ie
, size_t ie_len
, int deauth
)
3377 if (wpa_s
->ap_iface
&& addr
) {
3378 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3382 if (wpa_s
->ap_iface
) {
3383 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3386 #endif /* CONFIG_AP */
3388 if (!locally_generated
)
3389 wpa_s
->own_disconnect_req
= 0;
3391 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3393 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3394 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3395 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3396 eapol_sm_failed(wpa_s
->eapol
))) &&
3397 !wpa_s
->eap_expected_failure
))
3398 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3401 if (deauth
&& reason_code
> 0) {
3402 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3403 locally_generated
) > 0) {
3405 * The interface was removed, so cannot continue
3406 * processing any additional operations after this.
3411 #endif /* CONFIG_P2P */
3413 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3418 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3419 struct disassoc_info
*info
)
3421 u16 reason_code
= 0;
3422 int locally_generated
= 0;
3423 const u8
*addr
= NULL
;
3424 const u8
*ie
= NULL
;
3427 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3432 ie_len
= info
->ie_len
;
3433 reason_code
= info
->reason_code
;
3434 locally_generated
= info
->locally_generated
;
3435 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3436 locally_generated
? " (locally generated)" : "");
3438 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3440 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3445 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3446 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3450 if (wpa_s
->ap_iface
) {
3451 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3454 #endif /* CONFIG_AP */
3458 wpas_p2p_disassoc_notif(
3459 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3462 #endif /* CONFIG_P2P */
3464 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3465 sme_event_disassoc(wpa_s
, info
);
3467 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3472 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3473 struct deauth_info
*info
)
3475 u16 reason_code
= 0;
3476 int locally_generated
= 0;
3477 const u8
*addr
= NULL
;
3478 const u8
*ie
= NULL
;
3481 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3486 ie_len
= info
->ie_len
;
3487 reason_code
= info
->reason_code
;
3488 locally_generated
= info
->locally_generated
;
3489 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3491 locally_generated
? " (locally generated)" : "");
3493 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3496 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3500 wpa_reset_ft_completed(wpa_s
->wpa
);
3502 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3503 locally_generated
, ie
, ie_len
, 1);
3507 static const char * reg_init_str(enum reg_change_initiator init
)
3510 case REGDOM_SET_BY_CORE
:
3512 case REGDOM_SET_BY_USER
:
3514 case REGDOM_SET_BY_DRIVER
:
3516 case REGDOM_SET_BY_COUNTRY_IE
:
3517 return "COUNTRY_IE";
3518 case REGDOM_BEACON_HINT
:
3519 return "BEACON_HINT";
3525 static const char * reg_type_str(enum reg_type type
)
3528 case REGDOM_TYPE_UNKNOWN
:
3530 case REGDOM_TYPE_COUNTRY
:
3532 case REGDOM_TYPE_WORLD
:
3534 case REGDOM_TYPE_CUSTOM_WORLD
:
3535 return "CUSTOM_WORLD";
3536 case REGDOM_TYPE_INTERSECTION
:
3537 return "INTERSECTION";
3543 static void wpa_supplicant_update_channel_list(
3544 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3546 struct wpa_supplicant
*ifs
;
3550 * To allow backwards compatibility with higher level layers that
3551 * assumed the REGDOM_CHANGE event is sent over the initially added
3552 * interface. Find the highest parent of this interface and use it to
3555 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3558 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3559 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3560 info
->alpha2
[0] ? " alpha2=" : "",
3561 info
->alpha2
[0] ? info
->alpha2
: "");
3563 if (wpa_s
->drv_priv
== NULL
)
3564 return; /* Ignore event during drv initialization */
3566 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3568 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3570 free_hw_features(ifs
);
3571 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3572 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3574 /* Restart PNO/sched_scan with updated channel list */
3577 wpas_start_pno(ifs
);
3578 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3579 wpa_dbg(ifs
, MSG_DEBUG
,
3580 "Channel list changed - restart sched_scan");
3581 wpas_scan_restart_sched_scan(ifs
);
3585 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3589 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3590 const u8
*frame
, size_t len
, int freq
,
3593 const struct ieee80211_mgmt
*mgmt
;
3598 if (len
< IEEE80211_HDRLEN
+ 2)
3601 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3602 payload
= frame
+ IEEE80211_HDRLEN
;
3603 category
= *payload
++;
3604 plen
= len
- IEEE80211_HDRLEN
- 1;
3606 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3607 " Category=%u DataLen=%d freq=%d MHz",
3608 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3610 if (category
== WLAN_ACTION_WMM
) {
3611 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3615 #ifdef CONFIG_IEEE80211R
3616 if (category
== WLAN_ACTION_FT
) {
3617 ft_rx_action(wpa_s
, payload
, plen
);
3620 #endif /* CONFIG_IEEE80211R */
3622 #ifdef CONFIG_IEEE80211W
3624 if (category
== WLAN_ACTION_SA_QUERY
) {
3625 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3628 #endif /* CONFIG_SME */
3629 #endif /* CONFIG_IEEE80211W */
3632 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3633 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3636 #endif /* CONFIG_WNM */
3639 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3640 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3641 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3642 mgmt
->u
.action
.category
,
3643 payload
, plen
, freq
) == 0)
3645 #endif /* CONFIG_GAS */
3647 #ifdef CONFIG_GAS_SERVER
3648 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3649 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3650 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3651 mgmt
->u
.action
.category
,
3652 payload
, plen
, freq
) == 0)
3654 #endif /* CONFIG_GAS_SERVER */
3657 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3658 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3659 wpa_dbg(wpa_s
, MSG_DEBUG
,
3660 "TDLS: Received Discovery Response from " MACSTR
,
3664 #endif /* CONFIG_TDLS */
3666 #ifdef CONFIG_INTERWORKING
3667 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3668 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3669 const u8
*pos
= payload
+ 1;
3670 size_t qlen
= plen
- 1;
3671 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3672 MACSTR
, MAC2STR(mgmt
->sa
));
3673 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3674 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3675 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3676 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3679 #endif /* CONFIG_INTERWORKING */
3681 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3682 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3683 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3690 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3691 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3692 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3696 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3697 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3698 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3699 payload
+ 1, plen
- 1,
3705 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3706 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3709 #endif /* CONFIG_FST */
3712 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3713 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3714 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3715 payload
[4] == DPP_OUI_TYPE
) {
3718 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3721 #endif /* CONFIG_DPP */
3723 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3724 category
, payload
, plen
, freq
);
3726 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3730 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3731 union wpa_event_data
*event
)
3733 struct wpa_freq_range_list
*list
;
3736 list
= &event
->freq_range
;
3739 str
= freq_range_list_str(list
);
3740 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3744 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3745 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3748 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3751 * The update channel flow will also take care of moving a GO
3752 * from the unsafe frequency if needed.
3754 wpas_p2p_update_channel_list(wpa_s
,
3755 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3757 #endif /* CONFIG_P2P */
3763 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3764 union wpa_event_data
*data
)
3766 wpa_dbg(wpa_s
, MSG_DEBUG
,
3767 "Connection authorized by device, previous state %d",
3769 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3770 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3771 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3772 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3773 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3775 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3776 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3777 data
->assoc_info
.ptk_kck_len
,
3778 data
->assoc_info
.ptk_kek
,
3779 data
->assoc_info
.ptk_kek_len
);
3781 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3782 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3783 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3785 /* Update ERP next sequence number */
3786 eapol_sm_update_erp_next_seq_num(
3787 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3789 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3790 /* Add the new PMK and PMKID to the PMKSA cache */
3791 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3792 data
->assoc_info
.fils_pmk
,
3793 data
->assoc_info
.fils_pmk_len
,
3794 data
->assoc_info
.fils_pmkid
,
3795 wpa_s
->bssid
, fils_cache_id
);
3796 } else if (data
->assoc_info
.fils_pmkid
) {
3797 /* Update the current PMKSA used for this connection */
3798 pmksa_cache_set_current(wpa_s
->wpa
,
3799 data
->assoc_info
.fils_pmkid
,
3800 NULL
, NULL
, 0, NULL
);
3803 #endif /* CONFIG_FILS */
3807 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3808 union wpa_event_data
*data
)
3810 struct wpa_supplicant
*wpa_s
= ctx
;
3813 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3814 event
!= EVENT_INTERFACE_ENABLED
&&
3815 event
!= EVENT_INTERFACE_STATUS
&&
3816 event
!= EVENT_SCAN_RESULTS
&&
3817 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3818 wpa_dbg(wpa_s
, MSG_DEBUG
,
3819 "Ignore event %s (%d) while interface is disabled",
3820 event_to_string(event
), event
);
3824 #ifndef CONFIG_NO_STDOUT_DEBUG
3826 int level
= MSG_DEBUG
;
3828 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3829 const struct ieee80211_hdr
*hdr
;
3831 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3832 fc
= le_to_host16(hdr
->frame_control
);
3833 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3834 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3835 level
= MSG_EXCESSIVE
;
3838 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3839 event_to_string(event
), event
);
3841 #endif /* CONFIG_NO_STDOUT_DEBUG */
3846 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3847 data
->auth
.ies_len
))
3848 wpa_printf(MSG_DEBUG
,
3849 "FST: MB IEs updated from auth IE");
3850 #endif /* CONFIG_FST */
3851 sme_event_auth(wpa_s
, data
);
3854 #ifdef CONFIG_TESTING_OPTIONS
3855 if (wpa_s
->ignore_auth_resp
) {
3856 wpa_printf(MSG_INFO
,
3857 "EVENT_ASSOC - ignore_auth_resp active!");
3860 if (wpa_s
->testing_resend_assoc
) {
3861 wpa_printf(MSG_INFO
,
3862 "EVENT_DEAUTH - testing_resend_assoc");
3865 #endif /* CONFIG_TESTING_OPTIONS */
3866 wpa_supplicant_event_assoc(wpa_s
, data
);
3868 (data
->assoc_info
.authorized
||
3869 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
3870 wpa_fils_is_completed(wpa_s
->wpa
))))
3871 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3873 wpa_msg(wpa_s
, MSG_INFO
,
3874 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3875 data
->assoc_info
.subnet_status
);
3878 case EVENT_DISASSOC
:
3879 wpas_event_disassoc(wpa_s
,
3880 data
? &data
->disassoc_info
: NULL
);
3883 #ifdef CONFIG_TESTING_OPTIONS
3884 if (wpa_s
->ignore_auth_resp
) {
3885 wpa_printf(MSG_INFO
,
3886 "EVENT_DEAUTH - ignore_auth_resp active!");
3889 if (wpa_s
->testing_resend_assoc
) {
3890 wpa_printf(MSG_INFO
,
3891 "EVENT_DEAUTH - testing_resend_assoc");
3894 #endif /* CONFIG_TESTING_OPTIONS */
3895 wpas_event_deauth(wpa_s
,
3896 data
? &data
->deauth_info
: NULL
);
3898 case EVENT_MICHAEL_MIC_FAILURE
:
3899 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3901 #ifndef CONFIG_NO_SCAN_PROCESSING
3902 case EVENT_SCAN_STARTED
:
3903 if (wpa_s
->own_scan_requested
||
3904 (data
&& !data
->scan_info
.external_scan
)) {
3905 struct os_reltime diff
;
3907 os_get_reltime(&wpa_s
->scan_start_time
);
3908 os_reltime_sub(&wpa_s
->scan_start_time
,
3909 &wpa_s
->scan_trigger_time
, &diff
);
3910 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3911 diff
.sec
, diff
.usec
);
3912 wpa_s
->own_scan_requested
= 0;
3913 wpa_s
->own_scan_running
= 1;
3914 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3915 wpa_s
->manual_scan_use_id
) {
3916 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3917 WPA_EVENT_SCAN_STARTED
"id=%u",
3918 wpa_s
->manual_scan_id
);
3920 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3921 WPA_EVENT_SCAN_STARTED
);
3924 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3925 wpa_s
->radio
->external_scan_running
= 1;
3926 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3929 case EVENT_SCAN_RESULTS
:
3930 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3931 wpa_s
->scan_res_handler
= NULL
;
3932 wpa_s
->own_scan_running
= 0;
3933 wpa_s
->radio
->external_scan_running
= 0;
3934 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3938 if (!(data
&& data
->scan_info
.external_scan
) &&
3939 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3940 struct os_reltime now
, diff
;
3941 os_get_reltime(&now
);
3942 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3943 wpa_s
->scan_start_time
.sec
= 0;
3944 wpa_s
->scan_start_time
.usec
= 0;
3945 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3946 diff
.sec
, diff
.usec
);
3948 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3949 break; /* interface may have been removed */
3950 if (!(data
&& data
->scan_info
.external_scan
))
3951 wpa_s
->own_scan_running
= 0;
3952 if (data
&& data
->scan_info
.nl_scan_event
)
3953 wpa_s
->radio
->external_scan_running
= 0;
3954 radio_work_check_next(wpa_s
);
3956 #endif /* CONFIG_NO_SCAN_PROCESSING */
3957 case EVENT_ASSOCINFO
:
3958 wpa_supplicant_event_associnfo(wpa_s
, data
);
3960 case EVENT_INTERFACE_STATUS
:
3961 wpa_supplicant_event_interface_status(wpa_s
, data
);
3963 case EVENT_PMKID_CANDIDATE
:
3964 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3968 wpa_supplicant_event_tdls(wpa_s
, data
);
3970 #endif /* CONFIG_TDLS */
3973 wpa_supplicant_event_wnm(wpa_s
, data
);
3975 #endif /* CONFIG_WNM */
3976 #ifdef CONFIG_IEEE80211R
3977 case EVENT_FT_RESPONSE
:
3978 wpa_supplicant_event_ft_response(wpa_s
, data
);
3980 #endif /* CONFIG_IEEE80211R */
3981 #ifdef CONFIG_IBSS_RSN
3982 case EVENT_IBSS_RSN_START
:
3983 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3985 #endif /* CONFIG_IBSS_RSN */
3986 case EVENT_ASSOC_REJECT
:
3987 if (data
->assoc_reject
.bssid
)
3988 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3989 "bssid=" MACSTR
" status_code=%u%s%s%s",
3990 MAC2STR(data
->assoc_reject
.bssid
),
3991 data
->assoc_reject
.status_code
,
3992 data
->assoc_reject
.timed_out
? " timeout" : "",
3993 data
->assoc_reject
.timeout_reason
? "=" : "",
3994 data
->assoc_reject
.timeout_reason
?
3995 data
->assoc_reject
.timeout_reason
: "");
3997 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3998 "status_code=%u%s%s%s",
3999 data
->assoc_reject
.status_code
,
4000 data
->assoc_reject
.timed_out
? " timeout" : "",
4001 data
->assoc_reject
.timeout_reason
? "=" : "",
4002 data
->assoc_reject
.timeout_reason
?
4003 data
->assoc_reject
.timeout_reason
: "");
4004 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
4005 wpas_notify_assoc_status_code(wpa_s
);
4008 if (data
->assoc_reject
.status_code
==
4009 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
4010 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
4011 wpa_s
->current_ssid
&&
4012 wpa_s
->current_ssid
->owe_group
== 0 &&
4013 wpa_s
->last_owe_group
!= 21) {
4014 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4015 struct wpa_bss
*bss
= wpa_s
->current_bss
;
4017 wpa_printf(MSG_DEBUG
,
4018 "OWE: Try next supported DH group");
4019 wpas_connect_work_done(wpa_s
);
4020 wpa_supplicant_mark_disassoc(wpa_s
);
4021 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4024 #endif /* CONFIG_OWE */
4026 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4027 sme_event_assoc_reject(wpa_s
, data
);
4029 const u8
*bssid
= data
->assoc_reject
.bssid
;
4032 /* Update ERP next sequence number */
4033 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
)
4034 eapol_sm_update_erp_next_seq_num(
4036 data
->assoc_reject
.fils_erp_next_seq_num
);
4037 #endif /* CONFIG_FILS */
4039 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
4040 bssid
= wpa_s
->pending_bssid
;
4041 wpas_connection_failed(wpa_s
, bssid
);
4042 wpa_supplicant_mark_disassoc(wpa_s
);
4045 case EVENT_AUTH_TIMED_OUT
:
4046 /* It is possible to get this event from earlier connection */
4047 if (wpa_s
->current_ssid
&&
4048 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4049 wpa_dbg(wpa_s
, MSG_DEBUG
,
4050 "Ignore AUTH_TIMED_OUT in mesh configuration");
4053 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4054 sme_event_auth_timed_out(wpa_s
, data
);
4056 case EVENT_ASSOC_TIMED_OUT
:
4057 /* It is possible to get this event from earlier connection */
4058 if (wpa_s
->current_ssid
&&
4059 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
4060 wpa_dbg(wpa_s
, MSG_DEBUG
,
4061 "Ignore ASSOC_TIMED_OUT in mesh configuration");
4064 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
4065 sme_event_assoc_timed_out(wpa_s
, data
);
4067 case EVENT_TX_STATUS
:
4068 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
4069 " type=%d stype=%d",
4070 MAC2STR(data
->tx_status
.dst
),
4071 data
->tx_status
.type
, data
->tx_status
.stype
);
4073 if (wpa_s
->ap_iface
== NULL
) {
4074 #ifdef CONFIG_OFFCHANNEL
4075 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4076 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
4077 offchannel_send_action_tx_status(
4078 wpa_s
, data
->tx_status
.dst
,
4079 data
->tx_status
.data
,
4080 data
->tx_status
.data_len
,
4081 data
->tx_status
.ack
?
4082 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4083 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4084 #endif /* CONFIG_OFFCHANNEL */
4087 #endif /* CONFIG_AP */
4088 #ifdef CONFIG_OFFCHANNEL
4089 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
4090 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
4092 * Catch TX status events for Action frames we sent via group
4093 * interface in GO mode, or via standalone AP interface.
4094 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
4095 * except when the primary interface is used as a GO interface
4096 * (for drivers which do not have group interface concurrency)
4098 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
4099 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
4100 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
4101 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
4102 offchannel_send_action_tx_status(
4103 wpa_s
->p2pdev
, data
->tx_status
.dst
,
4104 data
->tx_status
.data
,
4105 data
->tx_status
.data_len
,
4106 data
->tx_status
.ack
?
4107 OFFCHANNEL_SEND_ACTION_SUCCESS
:
4108 OFFCHANNEL_SEND_ACTION_NO_ACK
);
4111 #endif /* CONFIG_OFFCHANNEL */
4113 switch (data
->tx_status
.type
) {
4114 case WLAN_FC_TYPE_MGMT
:
4115 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
4116 data
->tx_status
.data_len
,
4117 data
->tx_status
.stype
,
4118 data
->tx_status
.ack
);
4120 case WLAN_FC_TYPE_DATA
:
4121 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
4122 data
->tx_status
.data
,
4123 data
->tx_status
.data_len
,
4124 data
->tx_status
.ack
);
4127 #endif /* CONFIG_AP */
4130 case EVENT_EAPOL_TX_STATUS
:
4131 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
4132 data
->eapol_tx_status
.data
,
4133 data
->eapol_tx_status
.data_len
,
4134 data
->eapol_tx_status
.ack
);
4136 case EVENT_DRIVER_CLIENT_POLL_OK
:
4137 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4139 case EVENT_RX_FROM_UNKNOWN
:
4140 if (wpa_s
->ap_iface
== NULL
)
4142 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4143 data
->rx_from_unknown
.wds
);
4145 case EVENT_CH_SWITCH
:
4146 if (!data
|| !wpa_s
->current_ssid
)
4149 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4150 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4151 data
->ch_switch
.freq
,
4152 data
->ch_switch
.ht_enabled
,
4153 data
->ch_switch
.ch_offset
,
4154 channel_width_to_string(data
->ch_switch
.ch_width
),
4155 data
->ch_switch
.cf1
,
4156 data
->ch_switch
.cf2
);
4158 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4159 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4161 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4162 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4163 wpa_s
->current_ssid
->mode
==
4164 WPAS_MODE_P2P_GROUP_FORMATION
) {
4165 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4166 data
->ch_switch
.ht_enabled
,
4167 data
->ch_switch
.ch_offset
,
4168 data
->ch_switch
.ch_width
,
4169 data
->ch_switch
.cf1
,
4170 data
->ch_switch
.cf2
);
4173 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4176 case EVENT_DFS_RADAR_DETECTED
:
4178 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
4180 case EVENT_DFS_CAC_STARTED
:
4182 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4184 case EVENT_DFS_CAC_FINISHED
:
4186 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4188 case EVENT_DFS_CAC_ABORTED
:
4190 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4192 case EVENT_DFS_NOP_FINISHED
:
4194 wpas_event_dfs_cac_nop_finished(wpa_s
,
4197 #endif /* NEED_AP_MLME */
4198 #endif /* CONFIG_AP */
4199 case EVENT_RX_MGMT
: {
4201 const struct ieee80211_mgmt
*mgmt
;
4203 #ifdef CONFIG_TESTING_OPTIONS
4204 if (wpa_s
->ext_mgmt_frame_handling
) {
4205 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4206 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4207 char *hex
= os_malloc(hex_len
);
4209 wpa_snprintf_hex(hex
, hex_len
,
4210 rx
->frame
, rx
->frame_len
);
4211 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4212 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4218 #endif /* CONFIG_TESTING_OPTIONS */
4220 mgmt
= (const struct ieee80211_mgmt
*)
4221 data
->rx_mgmt
.frame
;
4222 fc
= le_to_host16(mgmt
->frame_control
);
4223 stype
= WLAN_FC_GET_STYPE(fc
);
4226 if (wpa_s
->ap_iface
== NULL
) {
4227 #endif /* CONFIG_AP */
4229 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4230 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4231 const u8
*src
= mgmt
->sa
;
4235 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4236 ie_len
= data
->rx_mgmt
.frame_len
-
4238 wpas_p2p_probe_req_rx(
4239 wpa_s
, src
, mgmt
->da
,
4240 mgmt
->bssid
, ie
, ie_len
,
4242 data
->rx_mgmt
.ssi_signal
);
4245 #endif /* CONFIG_P2P */
4246 #ifdef CONFIG_IBSS_RSN
4247 if (wpa_s
->current_ssid
&&
4248 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4249 stype
== WLAN_FC_STYPE_AUTH
&&
4250 data
->rx_mgmt
.frame_len
>= 30) {
4251 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4254 #endif /* CONFIG_IBSS_RSN */
4256 if (stype
== WLAN_FC_STYPE_ACTION
) {
4257 wpas_event_rx_mgmt_action(
4258 wpa_s
, data
->rx_mgmt
.frame
,
4259 data
->rx_mgmt
.frame_len
,
4261 data
->rx_mgmt
.ssi_signal
);
4266 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4271 if (stype
== WLAN_FC_STYPE_AUTH
&&
4272 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
4273 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
)) {
4274 sme_external_auth_mgmt_rx(
4275 wpa_s
, data
->rx_mgmt
.frame
,
4276 data
->rx_mgmt
.frame_len
);
4279 #endif /* CONFIG_SAE */
4280 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4281 "management frame in non-AP mode");
4286 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4287 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4291 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4292 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4294 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4295 mgmt
->bssid
, ie
, ie_len
,
4296 data
->rx_mgmt
.ssi_signal
);
4299 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4300 #endif /* CONFIG_AP */
4303 case EVENT_RX_PROBE_REQ
:
4304 if (data
->rx_probe_req
.sa
== NULL
||
4305 data
->rx_probe_req
.ie
== NULL
)
4308 if (wpa_s
->ap_iface
) {
4309 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4310 data
->rx_probe_req
.sa
,
4311 data
->rx_probe_req
.da
,
4312 data
->rx_probe_req
.bssid
,
4313 data
->rx_probe_req
.ie
,
4314 data
->rx_probe_req
.ie_len
,
4315 data
->rx_probe_req
.ssi_signal
);
4318 #endif /* CONFIG_AP */
4319 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4320 data
->rx_probe_req
.da
,
4321 data
->rx_probe_req
.bssid
,
4322 data
->rx_probe_req
.ie
,
4323 data
->rx_probe_req
.ie_len
,
4325 data
->rx_probe_req
.ssi_signal
);
4327 case EVENT_REMAIN_ON_CHANNEL
:
4328 #ifdef CONFIG_OFFCHANNEL
4329 offchannel_remain_on_channel_cb(
4330 wpa_s
, data
->remain_on_channel
.freq
,
4331 data
->remain_on_channel
.duration
);
4332 #endif /* CONFIG_OFFCHANNEL */
4333 wpas_p2p_remain_on_channel_cb(
4334 wpa_s
, data
->remain_on_channel
.freq
,
4335 data
->remain_on_channel
.duration
);
4337 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4338 #ifdef CONFIG_OFFCHANNEL
4339 offchannel_cancel_remain_on_channel_cb(
4340 wpa_s
, data
->remain_on_channel
.freq
);
4341 #endif /* CONFIG_OFFCHANNEL */
4342 wpas_p2p_cancel_remain_on_channel_cb(
4343 wpa_s
, data
->remain_on_channel
.freq
);
4345 wpas_dpp_cancel_remain_on_channel_cb(
4346 wpa_s
, data
->remain_on_channel
.freq
);
4347 #endif /* CONFIG_DPP */
4349 case EVENT_EAPOL_RX
:
4350 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4351 data
->eapol_rx
.data
,
4352 data
->eapol_rx
.data_len
);
4354 case EVENT_SIGNAL_CHANGE
:
4355 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4356 "above=%d signal=%d noise=%d txrate=%d",
4357 data
->signal_change
.above_threshold
,
4358 data
->signal_change
.current_signal
,
4359 data
->signal_change
.current_noise
,
4360 data
->signal_change
.current_txrate
);
4361 wpa_bss_update_level(wpa_s
->current_bss
,
4362 data
->signal_change
.current_signal
);
4363 bgscan_notify_signal_change(
4364 wpa_s
, data
->signal_change
.above_threshold
,
4365 data
->signal_change
.current_signal
,
4366 data
->signal_change
.current_noise
,
4367 data
->signal_change
.current_txrate
);
4369 case EVENT_INTERFACE_ENABLED
:
4370 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4371 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4372 wpa_supplicant_update_mac_addr(wpa_s
);
4373 if (wpa_s
->p2p_mgmt
) {
4374 wpa_supplicant_set_state(wpa_s
,
4380 if (!wpa_s
->ap_iface
) {
4381 wpa_supplicant_set_state(wpa_s
,
4383 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4384 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4386 wpa_supplicant_set_state(wpa_s
,
4388 #else /* CONFIG_AP */
4389 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4390 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4391 #endif /* CONFIG_AP */
4394 case EVENT_INTERFACE_DISABLED
:
4395 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4397 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4398 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4399 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4401 * Mark interface disabled if this happens to end up not
4402 * being removed as a separate P2P group interface.
4404 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4406 * The interface was externally disabled. Remove
4407 * it assuming an external entity will start a
4408 * new session if needed.
4410 if (wpa_s
->current_ssid
&&
4411 wpa_s
->current_ssid
->p2p_group
)
4412 wpas_p2p_interface_unavailable(wpa_s
);
4414 wpas_p2p_disconnect(wpa_s
);
4416 * wpa_s instance may have been freed, so must not use
4421 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4422 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4423 /* This radio work will be cancelled, so clear P2P
4426 p2p_stop_find(wpa_s
->global
->p2p
);
4428 #endif /* CONFIG_P2P */
4430 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4432 * Indicate disconnection to keep ctrl_iface events
4435 wpa_supplicant_event_disassoc(
4436 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4438 wpa_supplicant_mark_disassoc(wpa_s
);
4439 wpa_bss_flush(wpa_s
);
4440 radio_remove_works(wpa_s
, NULL
, 0);
4442 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4444 case EVENT_CHANNEL_LIST_CHANGED
:
4445 wpa_supplicant_update_channel_list(
4446 wpa_s
, &data
->channel_list_changed
);
4448 case EVENT_INTERFACE_UNAVAILABLE
:
4449 wpas_p2p_interface_unavailable(wpa_s
);
4451 case EVENT_BEST_CHANNEL
:
4452 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4454 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4455 data
->best_chan
.freq_overall
);
4456 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4457 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4458 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4459 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4460 data
->best_chan
.freq_5
,
4461 data
->best_chan
.freq_overall
);
4463 case EVENT_UNPROT_DEAUTH
:
4464 wpa_supplicant_event_unprot_deauth(wpa_s
,
4465 &data
->unprot_deauth
);
4467 case EVENT_UNPROT_DISASSOC
:
4468 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4469 &data
->unprot_disassoc
);
4471 case EVENT_STATION_LOW_ACK
:
4473 if (wpa_s
->ap_iface
&& data
)
4474 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4475 data
->low_ack
.addr
);
4476 #endif /* CONFIG_AP */
4479 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4480 data
->low_ack
.addr
);
4481 #endif /* CONFIG_TDLS */
4483 case EVENT_IBSS_PEER_LOST
:
4484 #ifdef CONFIG_IBSS_RSN
4485 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4486 #endif /* CONFIG_IBSS_RSN */
4488 case EVENT_DRIVER_GTK_REKEY
:
4489 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4490 wpa_s
->bssid
, ETH_ALEN
))
4494 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4495 data
->driver_gtk_rekey
.replay_ctr
);
4497 case EVENT_SCHED_SCAN_STOPPED
:
4498 wpa_s
->sched_scanning
= 0;
4499 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4500 wpa_supplicant_notify_scanning(wpa_s
, 0);
4502 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4506 * If the driver stopped scanning without being requested to,
4507 * request a new scan to continue scanning for networks.
4509 if (!wpa_s
->sched_scan_stop_req
&&
4510 wpa_s
->wpa_state
== WPA_SCANNING
) {
4511 wpa_dbg(wpa_s
, MSG_DEBUG
,
4512 "Restart scanning after unexpected sched_scan stop event");
4513 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4517 wpa_s
->sched_scan_stop_req
= 0;
4520 * Start a new sched scan to continue searching for more SSIDs
4521 * either if timed out or PNO schedule scan is pending.
4523 if (wpa_s
->sched_scan_timed_out
) {
4524 wpa_supplicant_req_sched_scan(wpa_s
);
4525 } else if (wpa_s
->pno_sched_pending
) {
4526 wpa_s
->pno_sched_pending
= 0;
4527 wpas_start_pno(wpa_s
);
4528 } else if (resched
) {
4529 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4533 case EVENT_WPS_BUTTON_PUSHED
:
4535 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4536 #endif /* CONFIG_WPS */
4538 case EVENT_AVOID_FREQUENCIES
:
4539 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4541 case EVENT_CONNECT_FAILED_REASON
:
4543 if (!wpa_s
->ap_iface
|| !data
)
4545 hostapd_event_connect_failed_reason(
4546 wpa_s
->ap_iface
->bss
[0],
4547 data
->connect_failed_reason
.addr
,
4548 data
->connect_failed_reason
.code
);
4549 #endif /* CONFIG_AP */
4551 case EVENT_NEW_PEER_CANDIDATE
:
4553 if (!wpa_s
->ifmsh
|| !data
)
4555 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4556 data
->mesh_peer
.ies
,
4557 data
->mesh_peer
.ie_len
);
4558 #endif /* CONFIG_MESH */
4562 if (!wpa_s
->ap_iface
)
4564 hostapd_event_get_survey(wpa_s
->ap_iface
,
4565 &data
->survey_results
);
4566 #endif /* CONFIG_AP */
4568 case EVENT_ACS_CHANNEL_SELECTED
:
4571 if (!wpa_s
->ap_iface
)
4573 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4574 &data
->acs_selected_channels
);
4575 #endif /* CONFIG_ACS */
4576 #endif /* CONFIG_AP */
4578 case EVENT_P2P_LO_STOP
:
4580 wpa_s
->p2p_lo_started
= 0;
4581 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4582 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4583 data
->p2p_lo_stop
.reason_code
);
4584 #endif /* CONFIG_P2P */
4586 case EVENT_BEACON_LOSS
:
4587 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4589 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4590 bgscan_notify_beacon_loss(wpa_s
);
4592 case EVENT_EXTERNAL_AUTH
:
4594 if (!wpa_s
->current_ssid
) {
4595 wpa_printf(MSG_DEBUG
, "SAE: current_ssid is NULL");
4598 sme_external_auth_trigger(wpa_s
, data
);
4599 #endif /* CONFIG_SAE */
4602 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4608 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4609 union wpa_event_data
*data
)
4611 struct wpa_supplicant
*wpa_s
;
4613 if (event
!= EVENT_INTERFACE_STATUS
)
4616 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4617 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4618 unsigned int ifindex
;
4620 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4621 if (ifindex
!= data
->interface_status
.ifindex
) {
4622 wpa_dbg(wpa_s
, MSG_DEBUG
,
4623 "interface status ifindex %d mismatch (%d)",
4624 ifindex
, data
->interface_status
.ifindex
);
4628 #ifdef CONFIG_MATCH_IFACE
4629 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4630 struct wpa_interface
*wpa_i
;
4632 wpa_i
= wpa_supplicant_match_iface(
4633 ctx
, data
->interface_status
.ifname
);
4636 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4641 #endif /* CONFIG_MATCH_IFACE */
4644 wpa_supplicant_event(wpa_s
, event
, data
);