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/dpp.h"
32 #include "common/gas_server.h"
33 #include "crypto/random.h"
34 #include "blacklist.h"
35 #include "wpas_glue.h"
36 #include "wps_supplicant.h"
39 #include "gas_query.h"
40 #include "p2p_supplicant.h"
46 #include "offchannel.h"
47 #include "interworking.h"
51 #include "dpp_supplicant.h"
54 #ifndef CONFIG_NO_SCAN_PROCESSING
55 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
56 int new_scan
, int own_request
);
57 #endif /* CONFIG_NO_SCAN_PROCESSING */
60 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
62 struct os_reltime now
;
64 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
68 if (ssid
->disabled_until
.sec
> now
.sec
)
69 return ssid
->disabled_until
.sec
- now
.sec
;
71 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
77 #ifndef CONFIG_NO_SCAN_PROCESSING
79 * wpas_reenabled_network_time - Time until first network is re-enabled
80 * @wpa_s: Pointer to wpa_supplicant data
81 * Returns: If all enabled networks are temporarily disabled, returns the time
82 * (in sec) until the first network is re-enabled. Otherwise returns 0.
84 * This function is used in case all enabled networks are temporarily disabled,
85 * in which case it returns the time (in sec) that the first network will be
86 * re-enabled. The function assumes that at least one network is enabled.
88 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
90 struct wpa_ssid
*ssid
;
91 int disabled_for
, res
= 0;
93 #ifdef CONFIG_INTERWORKING
94 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
97 #endif /* CONFIG_INTERWORKING */
99 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
103 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
107 if (!res
|| disabled_for
< res
)
113 #endif /* CONFIG_NO_SCAN_PROCESSING */
116 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
118 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
120 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
123 wpa_dbg(wpa_s
, MSG_DEBUG
,
124 "Try to associate due to network getting re-enabled");
125 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
126 wpa_supplicant_cancel_sched_scan(wpa_s
);
127 wpa_supplicant_req_scan(wpa_s
, 0, 0);
132 static struct wpa_bss
* wpa_supplicant_get_new_bss(
133 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
135 struct wpa_bss
*bss
= NULL
;
136 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
138 if (ssid
->ssid_len
> 0)
139 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
141 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
147 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
149 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
152 wpa_supplicant_update_scan_results(wpa_s
);
154 /* Get the BSS from the new scan results */
155 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
159 wpa_s
->current_bss
= bss
;
163 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
165 struct wpa_ssid
*ssid
, *old_ssid
;
166 u8 drv_ssid
[SSID_MAX_LEN
];
170 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
171 wpa_supplicant_update_current_bss(wpa_s
);
173 if (wpa_s
->current_ssid
->ssid_len
== 0)
174 return 0; /* current profile still in use */
175 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
177 wpa_msg(wpa_s
, MSG_INFO
,
178 "Failed to read SSID from driver");
179 return 0; /* try to use current profile */
183 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
184 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
186 return 0; /* current profile still in use */
188 wpa_msg(wpa_s
, MSG_DEBUG
,
189 "Driver-initiated BSS selection changed the SSID to %s",
190 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
191 /* continue selecting a new network profile */
194 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
196 ssid
= wpa_supplicant_get_ssid(wpa_s
);
198 wpa_msg(wpa_s
, MSG_INFO
,
199 "No network configuration found for the current AP");
203 if (wpas_network_disabled(wpa_s
, ssid
)) {
204 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
208 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
209 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
210 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
214 res
= wpas_temp_disabled(wpa_s
, ssid
);
216 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
217 "disabled for %d second(s)", res
);
221 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
223 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
225 size_t wpa_ie_len
= sizeof(wpa_ie
);
226 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
227 wpa_ie
, &wpa_ie_len
) < 0)
228 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
230 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
233 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
234 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
235 old_ssid
= wpa_s
->current_ssid
;
236 wpa_s
->current_ssid
= ssid
;
238 wpa_supplicant_update_current_bss(wpa_s
);
240 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
241 wpa_supplicant_initiate_eapol(wpa_s
);
242 if (old_ssid
!= wpa_s
->current_ssid
)
243 wpas_notify_network_changed(wpa_s
);
249 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
251 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
253 if (wpa_s
->countermeasures
) {
254 wpa_s
->countermeasures
= 0;
255 wpa_drv_set_countermeasures(wpa_s
, 0);
256 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
259 * It is possible that the device is sched scanning, which means
260 * that a connection attempt will be done only when we receive
261 * scan results. However, in this case, it would be preferable
262 * to scan and connect immediately, so cancel the sched_scan and
263 * issue a regular scan flow.
265 wpa_supplicant_cancel_sched_scan(wpa_s
);
266 wpa_supplicant_req_scan(wpa_s
, 0, 0);
271 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
275 wnm_bss_keep_alive_deinit(wpa_s
);
277 #ifdef CONFIG_IBSS_RSN
278 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
279 wpa_s
->ibss_rsn
= NULL
;
280 #endif /* CONFIG_IBSS_RSN */
283 wpa_supplicant_ap_deinit(wpa_s
);
284 #endif /* CONFIG_AP */
287 /* Clear possibly configured frame filters */
288 wpa_drv_configure_frame_filters(wpa_s
, 0);
289 #endif /* CONFIG_HS20 */
291 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
294 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
295 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
296 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
297 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
298 sme_clear_on_disassoc(wpa_s
);
299 wpa_s
->current_bss
= NULL
;
300 wpa_s
->assoc_freq
= 0;
303 wpas_notify_bssid_changed(wpa_s
);
305 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
306 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
307 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
308 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
)
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;
320 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
322 struct wpa_ie_data ie
;
326 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
330 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
331 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
332 ie
.pmkid
+ i
* PMKID_LEN
,
333 NULL
, NULL
, 0, NULL
);
334 if (pmksa_set
== 0) {
335 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
340 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
341 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
345 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
346 union wpa_event_data
*data
)
349 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
353 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
354 " index=%d preauth=%d",
355 MAC2STR(data
->pmkid_candidate
.bssid
),
356 data
->pmkid_candidate
.index
,
357 data
->pmkid_candidate
.preauth
);
359 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
360 data
->pmkid_candidate
.index
,
361 data
->pmkid_candidate
.preauth
);
365 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
367 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
368 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
371 #ifdef IEEE8021X_EAPOL
372 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
373 wpa_s
->current_ssid
&&
374 !(wpa_s
->current_ssid
->eapol_flags
&
375 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
376 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
377 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
378 * plaintext or static WEP keys). */
381 #endif /* IEEE8021X_EAPOL */
388 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
389 * @wpa_s: pointer to wpa_supplicant data
390 * @ssid: Configuration data for the network
391 * Returns: 0 on success, -1 on failure
393 * This function is called when starting authentication with a network that is
394 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
396 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
397 struct wpa_ssid
*ssid
)
399 #ifdef IEEE8021X_EAPOL
401 int aka
= 0, sim
= 0;
403 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
404 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
407 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
411 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
412 while (eap
->vendor
!= EAP_VENDOR_IETF
||
413 eap
->method
!= EAP_TYPE_NONE
) {
414 if (eap
->vendor
== EAP_VENDOR_IETF
) {
415 if (eap
->method
== EAP_TYPE_SIM
)
417 else if (eap
->method
== EAP_TYPE_AKA
||
418 eap
->method
== EAP_TYPE_AKA_PRIME
)
425 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
427 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
428 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
433 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
434 "use SIM, but neither EAP-SIM nor EAP-AKA are "
439 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
440 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
442 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
443 if (wpa_s
->scard
== NULL
) {
444 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
448 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
449 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
450 #endif /* PCSC_FUNCS */
451 #endif /* IEEE8021X_EAPOL */
457 #ifndef CONFIG_NO_SCAN_PROCESSING
459 static int has_wep_key(struct wpa_ssid
*ssid
)
463 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
464 if (ssid
->wep_key_len
[i
])
472 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
473 struct wpa_ssid
*ssid
)
477 if (ssid
->mixed_cell
)
481 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
483 #endif /* CONFIG_WPS */
485 if (has_wep_key(ssid
))
488 #ifdef IEEE8021X_EAPOL
489 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
490 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
491 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
493 #endif /* IEEE8021X_EAPOL */
495 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
498 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
501 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
507 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
508 struct wpa_ssid
*ssid
,
509 struct wpa_bss
*bss
, int debug_print
)
511 struct wpa_ie_data ie
;
513 const u8
*rsn_ie
, *wpa_ie
;
517 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
521 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
522 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
523 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
524 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
525 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
527 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
528 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
531 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
533 wpa_dbg(wpa_s
, MSG_DEBUG
,
534 " skip RSN IE - parse failed");
539 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
542 wpa_dbg(wpa_s
, MSG_DEBUG
,
543 " selected based on TSN in RSN IE");
547 if (!(ie
.proto
& ssid
->proto
)) {
549 wpa_dbg(wpa_s
, MSG_DEBUG
,
550 " skip RSN IE - proto mismatch");
554 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
556 wpa_dbg(wpa_s
, MSG_DEBUG
,
557 " skip RSN IE - PTK cipher mismatch");
561 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
563 wpa_dbg(wpa_s
, MSG_DEBUG
,
564 " skip RSN IE - GTK cipher mismatch");
568 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
570 wpa_dbg(wpa_s
, MSG_DEBUG
,
571 " skip RSN IE - key mgmt mismatch");
575 #ifdef CONFIG_IEEE80211W
576 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
577 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
578 MGMT_FRAME_PROTECTION_REQUIRED
) {
580 wpa_dbg(wpa_s
, MSG_DEBUG
,
581 " skip RSN IE - no mgmt frame protection");
584 #endif /* CONFIG_IEEE80211W */
585 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
586 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
587 NO_MGMT_FRAME_PROTECTION
) {
589 wpa_dbg(wpa_s
, MSG_DEBUG
,
590 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
594 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
595 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
596 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
597 NO_MGMT_FRAME_PROTECTION
) {
599 wpa_dbg(wpa_s
, MSG_DEBUG
,
600 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
603 #endif /* CONFIG_MBO */
606 wpa_dbg(wpa_s
, MSG_DEBUG
,
607 " selected based on RSN IE");
611 #ifdef CONFIG_IEEE80211W
612 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
614 wpa_dbg(wpa_s
, MSG_DEBUG
,
615 " skip - MFP Required but network not MFP Capable");
618 #endif /* CONFIG_IEEE80211W */
620 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
621 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
624 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
626 wpa_dbg(wpa_s
, MSG_DEBUG
,
627 " skip WPA IE - parse failed");
632 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
635 wpa_dbg(wpa_s
, MSG_DEBUG
,
636 " selected based on TSN in WPA IE");
640 if (!(ie
.proto
& ssid
->proto
)) {
642 wpa_dbg(wpa_s
, MSG_DEBUG
,
643 " skip WPA IE - proto mismatch");
647 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
649 wpa_dbg(wpa_s
, MSG_DEBUG
,
650 " skip WPA IE - PTK cipher mismatch");
654 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
656 wpa_dbg(wpa_s
, MSG_DEBUG
,
657 " skip WPA IE - GTK cipher mismatch");
661 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
663 wpa_dbg(wpa_s
, MSG_DEBUG
,
664 " skip WPA IE - key mgmt mismatch");
669 wpa_dbg(wpa_s
, MSG_DEBUG
,
670 " selected based on WPA IE");
674 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
677 wpa_dbg(wpa_s
, MSG_DEBUG
,
678 " allow for non-WPA IEEE 802.1X");
682 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
683 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
685 wpa_dbg(wpa_s
, MSG_DEBUG
,
686 " skip - no WPA/RSN proto match");
690 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
691 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
693 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
697 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
699 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
704 wpa_dbg(wpa_s
, MSG_DEBUG
,
705 " reject due to mismatch with WPA/WPA2");
711 static int freq_allowed(int *freqs
, int freq
)
718 for (i
= 0; freqs
[i
]; i
++)
719 if (freqs
[i
] == freq
)
725 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
728 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
729 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
734 return 1; /* Cannot do matching without knowing band */
736 modes
= wpa_s
->hw
.modes
;
739 * The driver does not provide any additional information
740 * about the utilized hardware, so allow the connection attempt
746 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
747 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
748 int freq
= modes
[i
].channels
[j
].freq
;
749 if (freq
== bss
->freq
) {
751 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
752 break; /* do not allow 802.11b replace
763 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
764 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
768 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
769 int flagged
= !!(rate_ie
[j
] & 0x80);
770 int r
= (rate_ie
[j
] & 0x7f) * 5;
773 * IEEE Std 802.11n-2009 7.3.2.2:
774 * The new BSS Membership selector value is encoded
775 * like a legacy basic rate, but it is not a rate and
776 * only indicates if the BSS members are required to
777 * support the mandatory features of Clause 20 [HT PHY]
778 * in order to join the BSS.
780 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
781 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
782 if (!ht_supported(mode
)) {
784 wpa_dbg(wpa_s
, MSG_DEBUG
,
785 " hardware does not support HT PHY");
791 /* There's also a VHT selector for 802.11ac */
792 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
793 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
794 if (!vht_supported(mode
)) {
796 wpa_dbg(wpa_s
, MSG_DEBUG
,
797 " hardware does not support VHT PHY");
806 /* check for legacy basic rates */
807 for (k
= 0; k
< mode
->num_rates
; k
++) {
808 if (mode
->rates
[k
] == r
)
811 if (k
== mode
->num_rates
) {
813 * IEEE Std 802.11-2007 7.3.2.2 demands that in
814 * order to join a BSS all required rates
815 * have to be supported by the hardware.
818 wpa_dbg(wpa_s
, MSG_DEBUG
,
819 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
821 bss
->freq
, mode
->mode
, mode
->num_rates
);
832 * Test whether BSS is in an ESS.
833 * This is done differently in DMG (60 GHz) and non-DMG bands
835 static int bss_is_ess(struct wpa_bss
*bss
)
837 if (bss_is_dmg(bss
)) {
838 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
839 IEEE80211_CAP_DMG_AP
;
842 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
847 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
851 for (i
= 0; i
< ETH_ALEN
; i
++) {
852 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
859 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
863 for (i
= 0; i
< num
; i
++) {
864 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
865 const u8
*m
= a
+ ETH_ALEN
;
867 if (match_mac_mask(a
, addr
, m
))
874 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
875 int i
, struct wpa_bss
*bss
,
876 struct wpa_ssid
*group
,
877 int only_first_ssid
, int debug_print
)
879 u8 wpa_ie_len
, rsn_ie_len
;
881 struct wpa_blacklist
*e
;
883 struct wpa_ssid
*ssid
;
886 const u8
*assoc_disallow
;
887 #endif /* CONFIG_MBO */
889 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
890 wpa_ie_len
= ie
? ie
[1] : 0;
892 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
893 rsn_ie_len
= ie
? ie
[1] : 0;
895 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
899 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
900 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
901 i
, MAC2STR(bss
->bssid
),
902 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
903 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
905 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
907 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
908 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
910 osen
? " osen=1" : "");
913 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
916 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
918 * When only a single network is enabled, we can
919 * trigger blacklisting on the first failure. This
920 * should not be done with multiple enabled networks to
921 * avoid getting forced to move into a worse ESS on
922 * single error if there are no other BSSes of the
927 if (e
->count
> limit
) {
929 wpa_dbg(wpa_s
, MSG_DEBUG
,
930 " skip - blacklisted (count=%d limit=%d)",
937 if (bss
->ssid_len
== 0) {
939 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
943 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
945 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
949 if (disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
951 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
955 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
957 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
958 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
961 if (wpas_network_disabled(wpa_s
, ssid
)) {
963 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
967 res
= wpas_temp_disabled(wpa_s
, ssid
);
970 wpa_dbg(wpa_s
, MSG_DEBUG
,
971 " skip - disabled temporarily for %d second(s)",
977 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
979 wpa_dbg(wpa_s
, MSG_DEBUG
,
980 " skip - blacklisted (WPS)");
984 if (wpa
&& ssid
->ssid_len
== 0 &&
985 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
988 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
989 /* Only allow wildcard SSID match if an AP
990 * advertises active WPS operation that matches
993 if (ssid
->ssid_len
== 0 &&
994 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
997 #endif /* CONFIG_WPS */
999 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1000 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1004 (bss
->ssid_len
!= ssid
->ssid_len
||
1005 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
1007 wpa_dbg(wpa_s
, MSG_DEBUG
,
1008 " skip - SSID mismatch");
1012 if (ssid
->bssid_set
&&
1013 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1015 wpa_dbg(wpa_s
, MSG_DEBUG
,
1016 " skip - BSSID mismatch");
1020 /* check blacklist */
1021 if (ssid
->num_bssid_blacklist
&&
1022 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1023 ssid
->num_bssid_blacklist
)) {
1025 wpa_dbg(wpa_s
, MSG_DEBUG
,
1026 " skip - BSSID blacklisted");
1030 /* if there is a whitelist, only accept those APs */
1031 if (ssid
->num_bssid_whitelist
&&
1032 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1033 ssid
->num_bssid_whitelist
)) {
1035 wpa_dbg(wpa_s
, MSG_DEBUG
,
1036 " skip - BSSID not in whitelist");
1040 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1044 if (!osen
&& !wpa
&&
1045 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1046 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1047 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1049 wpa_dbg(wpa_s
, MSG_DEBUG
,
1050 " skip - non-WPA network not allowed");
1054 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1055 has_wep_key(ssid
)) {
1057 wpa_dbg(wpa_s
, MSG_DEBUG
,
1058 " skip - ignore WPA/WPA2 AP for WEP network block");
1062 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1064 wpa_dbg(wpa_s
, MSG_DEBUG
,
1065 " skip - non-OSEN network not allowed");
1069 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1071 wpa_dbg(wpa_s
, MSG_DEBUG
,
1072 " skip - privacy mismatch");
1076 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1077 !bss_is_pbss(bss
)) {
1079 wpa_dbg(wpa_s
, MSG_DEBUG
,
1080 " skip - not ESS, PBSS, or MBSS");
1084 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1086 wpa_dbg(wpa_s
, MSG_DEBUG
,
1087 " skip - PBSS mismatch (ssid %d bss %d)",
1088 ssid
->pbss
, bss_is_pbss(bss
));
1092 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1094 wpa_dbg(wpa_s
, MSG_DEBUG
,
1095 " skip - frequency not allowed");
1100 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1101 ssid
->frequency
!= bss
->freq
) {
1103 wpa_dbg(wpa_s
, MSG_DEBUG
,
1104 " skip - frequency not allowed (mesh)");
1107 #endif /* CONFIG_MESH */
1109 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1111 wpa_dbg(wpa_s
, MSG_DEBUG
,
1112 " skip - rate sets do not match");
1116 #ifndef CONFIG_IBSS_RSN
1117 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1118 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1119 WPA_KEY_MGMT_WPA_NONE
))) {
1121 wpa_dbg(wpa_s
, MSG_DEBUG
,
1122 " skip - IBSS RSN not supported in the build");
1125 #endif /* !CONFIG_IBSS_RSN */
1128 if (ssid
->p2p_group
&&
1129 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1130 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1132 wpa_dbg(wpa_s
, MSG_DEBUG
,
1133 " skip - no P2P IE seen");
1137 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1138 struct wpabuf
*p2p_ie
;
1139 u8 dev_addr
[ETH_ALEN
];
1141 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1144 wpa_dbg(wpa_s
, MSG_DEBUG
,
1145 " skip - no P2P element");
1148 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1149 bss
, P2P_IE_VENDOR_TYPE
);
1150 if (p2p_ie
== NULL
) {
1152 wpa_dbg(wpa_s
, MSG_DEBUG
,
1153 " skip - could not fetch P2P element");
1157 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1158 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1161 wpa_dbg(wpa_s
, MSG_DEBUG
,
1162 " skip - no matching GO P2P Device Address in P2P element");
1163 wpabuf_free(p2p_ie
);
1166 wpabuf_free(p2p_ie
);
1170 * TODO: skip the AP if its P2P IE has Group Formation
1171 * bit set in the P2P Group Capability Bitmap and we
1172 * are not in Group Formation with that device.
1174 #endif /* CONFIG_P2P */
1176 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1178 struct os_reltime diff
;
1180 os_reltime_sub(&wpa_s
->scan_min_time
,
1181 &bss
->last_update
, &diff
);
1183 wpa_dbg(wpa_s
, MSG_DEBUG
,
1184 " skip - scan result not recent enough (%u.%06u seconds too old)",
1185 (unsigned int) diff
.sec
,
1186 (unsigned int) diff
.usec
);
1190 #ifdef CONFIG_TESTING_OPTIONS
1191 if (wpa_s
->ignore_assoc_disallow
)
1192 goto skip_assoc_disallow
;
1193 #endif /* CONFIG_TESTING_OPTIONS */
1194 assoc_disallow
= wpas_mbo_get_bss_attr(
1195 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1196 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1198 wpa_dbg(wpa_s
, MSG_DEBUG
,
1199 " skip - MBO association disallowed (reason %u)",
1204 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1206 wpa_dbg(wpa_s
, MSG_DEBUG
,
1207 " skip - MBO retry delay has not passed yet");
1210 #ifdef CONFIG_TESTING_OPTIONS
1211 skip_assoc_disallow
:
1212 #endif /* CONFIG_TESTING_OPTIONS */
1213 #endif /* CONFIG_MBO */
1215 /* Matching configuration found */
1219 /* No matching configuration found */
1224 static struct wpa_bss
*
1225 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1226 struct wpa_ssid
*group
,
1227 struct wpa_ssid
**selected_ssid
,
1228 int only_first_ssid
)
1232 if (wpa_s
->current_ssid
) {
1233 struct wpa_ssid
*ssid
;
1235 wpa_dbg(wpa_s
, MSG_DEBUG
,
1236 "Scan results matching the currently selected network");
1237 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1238 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1240 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1241 only_first_ssid
, 0);
1242 if (ssid
!= wpa_s
->current_ssid
)
1244 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1245 " freq=%d level=%d snr=%d est_throughput=%u",
1246 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1247 bss
->snr
, bss
->est_throughput
);
1251 if (only_first_ssid
)
1252 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1255 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1258 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1259 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1260 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1261 only_first_ssid
, 1);
1262 if (!*selected_ssid
)
1264 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1266 MAC2STR(bss
->bssid
),
1267 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1275 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1276 struct wpa_ssid
**selected_ssid
)
1278 struct wpa_bss
*selected
= NULL
;
1280 struct wpa_ssid
*next_ssid
= NULL
;
1281 struct wpa_ssid
*ssid
;
1283 if (wpa_s
->last_scan_res
== NULL
||
1284 wpa_s
->last_scan_res_used
== 0)
1285 return NULL
; /* no scan results from last update */
1287 if (wpa_s
->next_ssid
) {
1288 /* check that next_ssid is still valid */
1289 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1290 if (ssid
== wpa_s
->next_ssid
)
1294 wpa_s
->next_ssid
= NULL
;
1297 while (selected
== NULL
) {
1298 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1299 if (next_ssid
&& next_ssid
->priority
==
1300 wpa_s
->conf
->pssid
[prio
]->priority
) {
1301 selected
= wpa_supplicant_select_bss(
1302 wpa_s
, next_ssid
, selected_ssid
, 1);
1306 selected
= wpa_supplicant_select_bss(
1307 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1313 if (selected
== NULL
&& wpa_s
->blacklist
&&
1314 !wpa_s
->countermeasures
) {
1315 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1316 "blacklist and try again");
1317 wpa_blacklist_clear(wpa_s
);
1318 wpa_s
->blacklist_cleared
++;
1319 } else if (selected
== NULL
)
1323 ssid
= *selected_ssid
;
1324 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1325 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1326 const char *field_name
, *txt
= NULL
;
1328 wpa_dbg(wpa_s
, MSG_DEBUG
,
1329 "PSK/passphrase not yet available for the selected network");
1331 wpas_notify_network_request(wpa_s
, ssid
,
1332 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1334 field_name
= wpa_supplicant_ctrl_req_to_string(
1335 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1336 if (field_name
== NULL
)
1339 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1348 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1349 int timeout_sec
, int timeout_usec
)
1351 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1353 * No networks are enabled; short-circuit request so
1354 * we don't wait timeout seconds before transitioning
1355 * to INACTIVE state.
1357 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1358 "since there are no enabled networks");
1359 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1363 wpa_s
->scan_for_connection
= 1;
1364 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1368 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1369 struct wpa_bss
*selected
,
1370 struct wpa_ssid
*ssid
)
1372 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1373 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1374 "PBC session overlap");
1375 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1377 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1378 wpa_s
->p2p_in_provisioning
) {
1379 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1383 #endif /* CONFIG_P2P */
1386 wpas_wps_pbc_overlap(wpa_s
);
1387 wpas_wps_cancel(wpa_s
);
1388 #endif /* CONFIG_WPS */
1392 wpa_msg(wpa_s
, MSG_DEBUG
,
1393 "Considering connect request: reassociate: %d selected: "
1394 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1395 " wpa_state: %s ssid=%p current_ssid=%p",
1396 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1397 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1398 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1399 ssid
, wpa_s
->current_ssid
);
1402 * Do not trigger new association unless the BSSID has changed or if
1403 * reassociation is requested. If we are in process of associating with
1404 * the selected BSSID, do not trigger new attempt.
1406 if (wpa_s
->reassociate
||
1407 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1408 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1409 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1410 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1411 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1413 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1414 ssid
!= wpa_s
->current_ssid
)))) {
1415 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1416 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1419 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1420 MAC2STR(selected
->bssid
));
1421 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1423 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1424 "connect with the selected AP");
1431 static struct wpa_ssid
*
1432 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1435 struct wpa_ssid
*ssid
;
1437 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1438 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1440 if (wpas_network_disabled(wpa_s
, ssid
))
1442 #ifndef CONFIG_IBSS_RSN
1443 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1444 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1445 WPA_KEY_MGMT_WPA_NONE
))) {
1446 wpa_msg(wpa_s
, MSG_INFO
,
1447 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1448 wpa_ssid_txt(ssid
->ssid
,
1452 #endif /* !CONFIG_IBSS_RSN */
1453 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1454 ssid
->mode
== IEEE80211_MODE_AP
||
1455 ssid
->mode
== IEEE80211_MODE_MESH
)
1463 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1464 * on BSS added and BSS changed events */
1465 static void wpa_supplicant_rsn_preauth_scan_results(
1466 struct wpa_supplicant
*wpa_s
)
1468 struct wpa_bss
*bss
;
1470 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1473 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1474 const u8
*ssid
, *rsn
;
1476 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1480 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1484 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1490 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1491 struct wpa_bss
*selected
,
1492 struct wpa_ssid
*ssid
)
1494 struct wpa_bss
*current_bss
= NULL
;
1495 #ifndef CONFIG_NO_ROAMING
1498 int cur_est
, sel_est
;
1499 #endif /* CONFIG_NO_ROAMING */
1501 if (wpa_s
->reassociate
)
1502 return 1; /* explicit request to reassociate */
1503 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1504 return 1; /* we are not associated; continue */
1505 if (wpa_s
->current_ssid
== NULL
)
1506 return 1; /* unknown current SSID */
1507 if (wpa_s
->current_ssid
!= ssid
)
1508 return 1; /* different network block */
1510 if (wpas_driver_bss_selection(wpa_s
))
1511 return 0; /* Driver-based roaming */
1513 if (wpa_s
->current_ssid
->ssid
)
1514 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1515 wpa_s
->current_ssid
->ssid
,
1516 wpa_s
->current_ssid
->ssid_len
);
1518 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1521 return 1; /* current BSS not seen in scan results */
1523 if (current_bss
== selected
)
1526 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1527 return 1; /* current BSS not seen in the last scan */
1529 #ifndef CONFIG_NO_ROAMING
1530 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1531 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1532 " freq=%d level=%d snr=%d est_throughput=%u",
1533 MAC2STR(current_bss
->bssid
),
1534 current_bss
->freq
, current_bss
->level
,
1535 current_bss
->snr
, current_bss
->est_throughput
);
1536 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1537 " freq=%d level=%d snr=%d est_throughput=%u",
1538 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1539 selected
->snr
, selected
->est_throughput
);
1541 if (wpa_s
->current_ssid
->bssid_set
&&
1542 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1544 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1545 "has preferred BSSID");
1549 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1550 wpa_dbg(wpa_s
, MSG_DEBUG
,
1551 "Allow reassociation - selected BSS has better estimated throughput");
1555 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1557 if (current_bss
->level
< 0 &&
1558 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1559 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1564 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1565 wpa_dbg(wpa_s
, MSG_DEBUG
,
1566 "Skip roam - Current BSS has better estimated throughput");
1570 cur_est
= current_bss
->est_throughput
;
1571 sel_est
= selected
->est_throughput
;
1573 if (current_bss
->level
< 0) {
1574 if (current_bss
->level
< -85)
1576 else if (current_bss
->level
< -80)
1578 else if (current_bss
->level
< -75)
1580 else if (current_bss
->level
< -70)
1584 if (cur_est
> sel_est
* 1.5)
1586 else if (cur_est
> sel_est
* 1.2)
1588 else if (cur_est
> sel_est
* 1.1)
1590 else if (cur_est
> sel_est
)
1596 /* Make it easier to move to 5 GHz band */
1597 if (sel_est
> cur_est
* 1.5)
1599 else if (sel_est
> cur_est
* 1.2)
1601 else if (sel_est
> cur_est
* 1.1)
1604 if (min_diff
> reduce
)
1609 diff
= abs(current_bss
->level
- selected
->level
);
1610 if (diff
< min_diff
) {
1611 wpa_dbg(wpa_s
, MSG_DEBUG
,
1612 "Skip roam - too small difference in signal level (%d < %d)",
1617 wpa_dbg(wpa_s
, MSG_DEBUG
,
1618 "Allow reassociation due to difference in signal level (%d >= %d)",
1621 #else /* CONFIG_NO_ROAMING */
1623 #endif /* CONFIG_NO_ROAMING */
1628 * Return a negative value if no scan results could be fetched or if scan
1629 * results should not be shared with other virtual interfaces.
1630 * Return 0 if scan results were fetched and may be shared with other
1632 * Return 1 if scan results may be shared with other virtual interfaces but may
1633 * not trigger any operations.
1634 * Return 2 if the interface was removed and cannot be used.
1636 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1637 union wpa_event_data
*data
,
1638 int own_request
, int update_only
)
1640 struct wpa_scan_results
*scan_res
= NULL
;
1643 #ifndef CONFIG_NO_RANDOM_POOL
1645 #endif /* CONFIG_NO_RANDOM_POOL */
1648 if (wpa_s
->ap_iface
)
1650 #endif /* CONFIG_AP */
1652 wpa_supplicant_notify_scanning(wpa_s
, 0);
1654 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1655 data
? &data
->scan_info
:
1657 if (scan_res
== NULL
) {
1658 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1659 wpa_s
->scan_res_handler
== scan_only_handler
)
1663 if (data
&& data
->scan_info
.external_scan
)
1665 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1667 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1669 goto scan_work_done
;
1672 #ifndef CONFIG_NO_RANDOM_POOL
1673 num
= scan_res
->num
;
1676 for (i
= 0; i
< num
; i
++) {
1678 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1679 buf
[0] = res
->bssid
[5];
1680 buf
[1] = res
->qual
& 0xff;
1681 buf
[2] = res
->noise
& 0xff;
1682 buf
[3] = res
->level
& 0xff;
1683 buf
[4] = res
->tsf
& 0xff;
1684 random_add_randomness(buf
, sizeof(buf
));
1686 #endif /* CONFIG_NO_RANDOM_POOL */
1690 goto scan_work_done
;
1693 if (own_request
&& wpa_s
->scan_res_handler
&&
1694 !(data
&& data
->scan_info
.external_scan
)) {
1695 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1696 struct wpa_scan_results
*scan_res
);
1698 scan_res_handler
= wpa_s
->scan_res_handler
;
1699 wpa_s
->scan_res_handler
= NULL
;
1700 scan_res_handler(wpa_s
, scan_res
);
1702 goto scan_work_done
;
1706 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1708 if (wpa_s
->ap_iface
->scan_cb
)
1709 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1710 #endif /* CONFIG_AP */
1711 goto scan_work_done
;
1714 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1715 wpa_s
->own_scan_running
,
1716 data
? data
->scan_info
.external_scan
: 0);
1717 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1718 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1719 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1720 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1721 wpa_s
->manual_scan_id
);
1722 wpa_s
->manual_scan_use_id
= 0;
1724 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1726 wpas_notify_scan_results(wpa_s
);
1728 wpas_notify_scan_done(wpa_s
, 1);
1730 if (data
&& data
->scan_info
.external_scan
) {
1731 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1732 wpa_scan_results_free(scan_res
);
1736 if (wnm_scan_process(wpa_s
, 1) > 0)
1737 goto scan_work_done
;
1739 if (sme_proc_obss_scan(wpa_s
) > 0)
1740 goto scan_work_done
;
1743 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1744 goto scan_work_done
;
1746 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1747 goto scan_work_done
;
1749 if (autoscan_notify_scan(wpa_s
, scan_res
))
1750 goto scan_work_done
;
1752 if (wpa_s
->disconnected
) {
1753 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1754 goto scan_work_done
;
1757 if (!wpas_driver_bss_selection(wpa_s
) &&
1758 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1759 goto scan_work_done
;
1761 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1763 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1764 wpa_s
->wpa_state
< WPA_COMPLETED
)
1765 goto scan_work_done
;
1767 wpa_scan_results_free(scan_res
);
1769 if (own_request
&& wpa_s
->scan_work
) {
1770 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1771 wpa_s
->scan_work
= NULL
;
1772 radio_work_done(work
);
1775 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1778 wpa_scan_results_free(scan_res
);
1779 if (own_request
&& wpa_s
->scan_work
) {
1780 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1781 wpa_s
->scan_work
= NULL
;
1782 radio_work_done(work
);
1788 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1789 int new_scan
, int own_request
)
1791 struct wpa_bss
*selected
;
1792 struct wpa_ssid
*ssid
= NULL
;
1793 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1795 if (time_to_reenable
> 0) {
1796 wpa_dbg(wpa_s
, MSG_DEBUG
,
1797 "Postpone network selection by %d seconds since all networks are disabled",
1799 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1800 eloop_register_timeout(time_to_reenable
, 0,
1801 wpas_network_reenabled
, wpa_s
, NULL
);
1805 if (wpa_s
->p2p_mgmt
)
1806 return 0; /* no normal connection on p2p_mgmt interface */
1808 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1812 wpa_msg(wpa_s
, MSG_INFO
,
1813 "Avoiding join because we already joined a mesh group");
1816 #endif /* CONFIG_MESH */
1820 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1823 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1827 if (ssid
!= wpa_s
->current_ssid
&&
1828 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1829 wpa_s
->own_disconnect_req
= 1;
1830 wpa_supplicant_deauthenticate(
1831 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1834 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1835 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1839 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1841 * Do not allow other virtual radios to trigger operations based
1842 * on these scan results since we do not want them to start
1843 * other associations at the same time.
1847 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1848 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1850 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1851 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1853 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1854 } else if (own_request
) {
1856 * No SSID found. If SCAN results are as a result of
1857 * own scan request and not due to a scan request on
1858 * another shared interface, try another scan.
1860 int timeout_sec
= wpa_s
->scan_interval
;
1861 int timeout_usec
= 0;
1865 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1871 if (wpa_s
->p2p_in_provisioning
||
1872 wpa_s
->show_group_started
||
1873 wpa_s
->p2p_in_invitation
) {
1875 * Use shorter wait during P2P Provisioning
1876 * state and during P2P join-a-group operation
1877 * to speed up group formation.
1880 timeout_usec
= 250000;
1881 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1885 #endif /* CONFIG_P2P */
1886 #ifdef CONFIG_INTERWORKING
1887 if (wpa_s
->conf
->auto_interworking
&&
1888 wpa_s
->conf
->interworking
&&
1889 wpa_s
->conf
->cred
) {
1890 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1891 "start ANQP fetch since no matching "
1893 wpa_s
->network_select
= 1;
1894 wpa_s
->auto_network_select
= 1;
1895 interworking_start_fetch_anqp(wpa_s
);
1898 #endif /* CONFIG_INTERWORKING */
1900 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1901 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1903 timeout_usec
= 500000;
1904 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1908 #endif /* CONFIG_WPS */
1909 if (wpa_supplicant_req_sched_scan(wpa_s
))
1910 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1913 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1914 WPA_EVENT_NETWORK_NOT_FOUND
);
1921 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1922 union wpa_event_data
*data
)
1924 struct wpa_supplicant
*ifs
;
1927 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
1930 * Interface may have been removed, so must not dereference
1938 * If no scan results could be fetched, then no need to
1939 * notify those interfaces that did not actually request
1940 * this scan. Similarly, if scan results started a new operation on this
1941 * interface, do not notify other interfaces to avoid concurrent
1942 * operations during a connection attempt.
1948 * Check other interfaces to see if they share the same radio. If
1949 * so, they get updated with this same scan info.
1951 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1954 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1955 "sibling", ifs
->ifname
);
1956 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
1966 #endif /* CONFIG_NO_SCAN_PROCESSING */
1969 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1971 #ifdef CONFIG_NO_SCAN_PROCESSING
1973 #else /* CONFIG_NO_SCAN_PROCESSING */
1974 struct os_reltime now
;
1976 wpa_s
->ignore_post_flush_scan_res
= 0;
1978 if (wpa_s
->last_scan_res_used
== 0)
1981 os_get_reltime(&now
);
1982 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1983 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1987 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1988 #endif /* CONFIG_NO_SCAN_PROCESSING */
1993 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1995 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1997 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2000 if (!wpa_s
->no_keep_alive
) {
2001 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2002 MAC2STR(wpa_s
->bssid
));
2003 /* TODO: could skip this if normal data traffic has been sent */
2004 /* TODO: Consider using some more appropriate data frame for
2007 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2012 if (wpa_s
->sme
.bss_max_idle_period
) {
2014 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2017 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2018 wnm_bss_keep_alive
, wpa_s
, NULL
);
2020 #endif /* CONFIG_SME */
2024 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2025 const u8
*ies
, size_t ies_len
)
2027 struct ieee802_11_elems elems
;
2032 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2036 if (elems
.bss_max_idle_period
) {
2038 wpa_s
->sme
.bss_max_idle_period
=
2039 WPA_GET_LE16(elems
.bss_max_idle_period
);
2040 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2041 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2042 (elems
.bss_max_idle_period
[2] & 0x01) ?
2043 " (protected keep-live required)" : "");
2044 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2045 wpa_s
->sme
.bss_max_idle_period
= 1;
2046 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2047 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2048 /* msec times 1000 */
2049 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2052 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2053 wnm_bss_keep_alive
, wpa_s
,
2057 #endif /* CONFIG_SME */
2060 #endif /* CONFIG_WNM */
2063 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2066 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2067 #endif /* CONFIG_WNM */
2071 #ifdef CONFIG_INTERWORKING
2073 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2078 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2079 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2081 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2088 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2089 const u8
*ies
, size_t ies_len
)
2091 struct ieee802_11_elems elems
;
2096 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2099 if (elems
.qos_map_set
) {
2100 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2101 elems
.qos_map_set_len
);
2105 #endif /* CONFIG_INTERWORKING */
2109 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2110 const u8
*ie
, size_t ie_len
)
2112 struct mb_ies_info mb_ies
;
2114 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2117 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2119 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2124 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2129 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2130 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2131 (unsigned int) len
);
2132 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2133 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2141 if (mb_ies
.nof_ies
> 0) {
2142 wpabuf_free(wpa_s
->received_mb_ies
);
2143 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2149 #endif /* CONFIG_FST */
2152 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2153 union wpa_event_data
*data
)
2155 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2157 #ifdef CONFIG_IEEE80211R
2159 #endif /* CONFIG_IEEE80211R */
2161 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2162 if (data
->assoc_info
.req_ies
)
2163 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2164 data
->assoc_info
.req_ies_len
);
2165 if (data
->assoc_info
.resp_ies
) {
2166 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2167 data
->assoc_info
.resp_ies_len
);
2169 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2170 data
->assoc_info
.resp_ies_len
);
2171 #endif /* CONFIG_TDLS */
2173 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2174 data
->assoc_info
.resp_ies_len
);
2175 #endif /* CONFIG_WNM */
2176 #ifdef CONFIG_INTERWORKING
2177 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2178 data
->assoc_info
.resp_ies_len
);
2179 #endif /* CONFIG_INTERWORKING */
2181 if (data
->assoc_info
.beacon_ies
)
2182 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2183 data
->assoc_info
.beacon_ies
,
2184 data
->assoc_info
.beacon_ies_len
);
2185 if (data
->assoc_info
.freq
)
2186 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2187 data
->assoc_info
.freq
);
2189 p
= data
->assoc_info
.req_ies
;
2190 l
= data
->assoc_info
.req_ies_len
;
2192 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2193 while (p
&& l
>= 2) {
2196 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2200 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2201 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2202 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2203 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2204 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2205 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2208 wpa_find_assoc_pmkid(wpa_s
);
2214 if (!found
&& data
->assoc_info
.req_ies
)
2215 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2219 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2220 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2221 (!data
->assoc_info
.resp_frame
||
2222 fils_process_assoc_resp(wpa_s
->wpa
,
2223 data
->assoc_info
.resp_frame
,
2224 data
->assoc_info
.resp_frame_len
) < 0)) {
2225 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2228 #endif /* CONFIG_SME */
2230 /* Additional processing for FILS when SME is in driver */
2231 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2232 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2233 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2234 #endif /* CONFIG_FILS */
2237 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2238 owe_process_assoc_resp(wpa_s
->wpa
,
2239 data
->assoc_info
.resp_ies
,
2240 data
->assoc_info
.resp_ies_len
) < 0) {
2241 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2244 #endif /* CONFIG_OWE */
2246 #ifdef CONFIG_IEEE80211R
2248 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2249 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2250 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2251 data
->assoc_info
.resp_ies
,
2252 data
->assoc_info
.resp_ies_len
,
2254 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2255 "Reassociation Response failed");
2256 wpa_supplicant_deauthenticate(
2257 wpa_s
, WLAN_REASON_INVALID_IE
);
2262 p
= data
->assoc_info
.resp_ies
;
2263 l
= data
->assoc_info
.resp_ies_len
;
2265 #ifdef CONFIG_WPS_STRICT
2266 if (p
&& wpa_s
->current_ssid
&&
2267 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2269 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2271 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2272 "include WPS IE in (Re)Association Response");
2276 if (wps_validate_assoc_resp(wps
) < 0) {
2278 wpa_supplicant_deauthenticate(
2279 wpa_s
, WLAN_REASON_INVALID_IE
);
2284 #endif /* CONFIG_WPS_STRICT */
2286 /* Go through the IEs and make a copy of the MDIE, if present. */
2287 while (p
&& l
>= 2) {
2290 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2294 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2295 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2296 wpa_s
->sme
.ft_used
= 1;
2297 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2298 MOBILITY_DOMAIN_ID_LEN
);
2304 #endif /* CONFIG_SME */
2306 /* Process FT when SME is in the driver */
2307 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2308 wpa_ft_is_completed(wpa_s
->wpa
)) {
2309 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2310 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2311 data
->assoc_info
.resp_ies
,
2312 data
->assoc_info
.resp_ies_len
,
2314 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2315 "Reassociation Response failed");
2316 wpa_supplicant_deauthenticate(
2317 wpa_s
, WLAN_REASON_INVALID_IE
);
2320 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2323 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2324 data
->assoc_info
.resp_ies_len
);
2325 #endif /* CONFIG_IEEE80211R */
2327 /* WPA/RSN IE from Beacon/ProbeResp */
2328 p
= data
->assoc_info
.beacon_ies
;
2329 l
= data
->assoc_info
.beacon_ies_len
;
2331 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2333 wpa_found
= rsn_found
= 0;
2334 while (p
&& l
>= 2) {
2337 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2342 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2343 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2345 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2349 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2351 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2358 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2359 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2360 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2361 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2362 if (wpa_found
|| rsn_found
)
2363 wpa_s
->ap_ies_from_associnfo
= 1;
2365 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2366 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2367 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2369 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2370 wpa_supplicant_update_scan_results(wpa_s
);
2373 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2379 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2381 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2383 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2386 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2389 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2390 WPA_IE_VENDOR_TYPE
);
2391 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2393 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2394 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2395 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2396 bss_rsn
? 2 + bss_rsn
[1] : 0))
2403 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2404 union wpa_event_data
*data
)
2407 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2408 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2409 const u8
*ieprb
, *iebcn
;
2411 wpabuf_free(wpa_s
->received_mb_ies
);
2412 wpa_s
->received_mb_ies
= NULL
;
2415 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2416 wpa_printf(MSG_DEBUG
,
2417 "FST: MB IEs updated from Association Response frame");
2422 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2423 wpa_printf(MSG_DEBUG
,
2424 "FST: MB IEs updated from association event Beacon IEs");
2431 ieprb
= (const u8
*) (bss
+ 1);
2432 iebcn
= ieprb
+ bss
->ie_len
;
2434 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2435 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2436 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2437 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2438 #endif /* CONFIG_FST */
2442 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2443 union wpa_event_data
*data
)
2446 int ft_completed
, already_authorized
;
2450 if (wpa_s
->ap_iface
) {
2453 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2454 data
->assoc_info
.addr
,
2455 data
->assoc_info
.req_ies
,
2456 data
->assoc_info
.req_ies_len
,
2457 data
->assoc_info
.reassoc
);
2460 #endif /* CONFIG_AP */
2462 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2464 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2465 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2468 * FILS authentication can share the same mechanism to mark the
2469 * connection fully authenticated, so set ft_completed also based on
2473 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2475 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2476 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2477 wpa_supplicant_deauthenticate(
2478 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2482 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2483 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2484 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2485 MACSTR
, MAC2STR(bssid
));
2487 random_add_randomness(bssid
, ETH_ALEN
);
2488 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2489 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2490 wpas_notify_bssid_changed(wpa_s
);
2492 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2493 wpa_clear_keys(wpa_s
, bssid
);
2495 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2496 wpa_supplicant_deauthenticate(
2497 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2502 if (wpa_s
->conf
->ap_scan
== 1 &&
2503 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2504 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2505 wpa_msg(wpa_s
, MSG_WARNING
,
2506 "WPA/RSN IEs not updated");
2509 wpas_fst_update_mb_assoc(wpa_s
, data
);
2512 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2513 wpa_s
->sme
.prev_bssid_set
= 1;
2514 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2515 #endif /* CONFIG_SME */
2517 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2518 if (wpa_s
->current_ssid
) {
2519 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2520 * initialized before association, but for other modes,
2521 * initialize PC/SC here, if the current configuration needs
2522 * smartcard or SIM/USIM. */
2523 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2525 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2527 l2_packet_notify_auth_start(wpa_s
->l2
);
2529 already_authorized
= data
&& data
->assoc_info
.authorized
;
2532 * Set portEnabled first to FALSE in order to get EAP state machine out
2533 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2534 * state machine may transit to AUTHENTICATING state based on obsolete
2535 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2536 * AUTHENTICATED without ever giving chance to EAP state machine to
2539 if (!ft_completed
&& !already_authorized
) {
2540 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2541 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2543 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2544 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2546 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2547 /* 802.1X::portControl = Auto */
2548 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2549 wpa_s
->eapol_received
= 0;
2550 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2551 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2552 (wpa_s
->current_ssid
&&
2553 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2554 if (wpa_s
->current_ssid
&&
2555 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2557 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2559 * Set the key after having received joined-IBSS event
2562 wpa_supplicant_set_wpa_none_key(wpa_s
,
2563 wpa_s
->current_ssid
);
2565 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2566 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2567 } else if (!ft_completed
) {
2568 /* Timeout for receiving the first EAPOL packet */
2569 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2571 wpa_supplicant_cancel_scan(wpa_s
);
2573 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2574 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2576 * We are done; the driver will take care of RSN 4-way
2579 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2580 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2581 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2582 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2583 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2584 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2586 * The driver will take care of RSN 4-way handshake, so we need
2587 * to allow EAPOL supplicant to complete its work without
2588 * waiting for WPA supplicant.
2590 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2591 } else if (ft_completed
) {
2593 * FT protocol completed - make sure EAPOL state machine ends
2594 * up in authenticated.
2596 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2597 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2598 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2599 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2602 wpa_s
->last_eapol_matches_bssid
= 0;
2604 if (wpa_s
->pending_eapol_rx
) {
2605 struct os_reltime now
, age
;
2606 os_get_reltime(&now
);
2607 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2608 if (age
.sec
== 0 && age
.usec
< 200000 &&
2609 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2611 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2612 "frame that was received just before "
2613 "association notification");
2614 wpa_supplicant_rx_eapol(
2615 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2616 wpabuf_head(wpa_s
->pending_eapol_rx
),
2617 wpabuf_len(wpa_s
->pending_eapol_rx
));
2619 wpabuf_free(wpa_s
->pending_eapol_rx
);
2620 wpa_s
->pending_eapol_rx
= NULL
;
2623 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2624 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2625 wpa_s
->current_ssid
&&
2626 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2627 /* Set static WEP keys again */
2628 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2631 #ifdef CONFIG_IBSS_RSN
2632 if (wpa_s
->current_ssid
&&
2633 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2634 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2635 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2636 wpa_s
->ibss_rsn
== NULL
) {
2637 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2638 if (!wpa_s
->ibss_rsn
) {
2639 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2640 wpa_supplicant_deauthenticate(
2641 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2645 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2647 #endif /* CONFIG_IBSS_RSN */
2649 wpas_wps_notify_assoc(wpa_s
, bssid
);
2652 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2653 data
->assoc_info
.resp_ies_len
,
2654 &data
->assoc_info
.wmm_params
);
2656 if (wpa_s
->reassoc_same_bss
)
2657 wmm_ac_restore_tspecs(wpa_s
);
2661 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2662 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2663 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2666 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2668 #endif /* CONFIG_FILS */
2672 static int disconnect_reason_recoverable(u16 reason_code
)
2674 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2675 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2676 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2680 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2682 int locally_generated
)
2686 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2688 * At least Host AP driver and a Prism3 card seemed to be
2689 * generating streams of disconnected events when configuring
2690 * IBSS for WPA-None. Ignore them for now.
2695 bssid
= wpa_s
->bssid
;
2696 if (is_zero_ether_addr(bssid
))
2697 bssid
= wpa_s
->pending_bssid
;
2699 if (!is_zero_ether_addr(bssid
) ||
2700 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2701 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2703 MAC2STR(bssid
), reason_code
,
2704 locally_generated
? " locally_generated=1" : "");
2709 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2710 int locally_generated
)
2712 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2713 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2714 return 0; /* Not in 4-way handshake with PSK */
2717 * It looks like connection was lost while trying to go through PSK
2718 * 4-way handshake. Filter out known disconnection cases that are caused
2719 * by something else than PSK mismatch to avoid confusing reports.
2722 if (locally_generated
) {
2723 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2731 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2733 int locally_generated
)
2737 u8 prev_pending_bssid
[ETH_ALEN
];
2738 struct wpa_bss
*fast_reconnect
= NULL
;
2739 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2740 struct wpa_ssid
*last_ssid
;
2741 struct wpa_bss
*curr
= NULL
;
2743 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2744 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2746 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2748 * At least Host AP driver and a Prism3 card seemed to be
2749 * generating streams of disconnected events when configuring
2750 * IBSS for WPA-None. Ignore them for now.
2752 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2753 "IBSS/WPA-None mode");
2757 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2758 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2761 * Remove the inactive AP (which is probably out of range) from
2762 * the BSS list after marking disassociation. In particular
2763 * mac80211-based drivers use the
2764 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2765 * locally generated disconnection events for cases where the
2766 * AP does not reply anymore.
2768 curr
= wpa_s
->current_bss
;
2770 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2771 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2772 "pre-shared key may be incorrect");
2773 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2774 return; /* P2P group removed */
2775 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2777 if (!wpa_s
->disconnected
&&
2778 (!wpa_s
->auto_reconnect_disabled
||
2779 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2780 wpas_wps_searching(wpa_s
) ||
2781 wpas_wps_reenable_networks_pending(wpa_s
))) {
2782 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2783 "reconnect (wps=%d/%d wpa_state=%d)",
2784 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2785 wpas_wps_searching(wpa_s
),
2787 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2788 wpa_s
->current_ssid
&&
2789 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2790 !locally_generated
&&
2791 disconnect_reason_recoverable(reason_code
)) {
2793 * It looks like the AP has dropped association with
2794 * us, but could allow us to get back in. Try to
2795 * reconnect to the same BSS without full scan to save
2796 * time for some common cases.
2798 fast_reconnect
= wpa_s
->current_bss
;
2799 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2800 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2801 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2803 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2806 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2807 "try to re-connect");
2808 wpa_s
->reassociate
= 0;
2809 wpa_s
->disconnected
= 1;
2811 wpa_supplicant_cancel_sched_scan(wpa_s
);
2813 bssid
= wpa_s
->bssid
;
2814 if (is_zero_ether_addr(bssid
))
2815 bssid
= wpa_s
->pending_bssid
;
2816 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2817 wpas_connection_failed(wpa_s
, bssid
);
2818 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2819 if (locally_generated
)
2820 wpa_s
->disconnect_reason
= -reason_code
;
2822 wpa_s
->disconnect_reason
= reason_code
;
2823 wpas_notify_disconnect_reason(wpa_s
);
2824 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2825 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2826 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2828 last_ssid
= wpa_s
->current_ssid
;
2829 wpa_supplicant_mark_disassoc(wpa_s
);
2832 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2834 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2835 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2836 wpa_s
->current_ssid
= last_ssid
;
2839 if (fast_reconnect
&&
2840 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2841 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2842 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2843 fast_reconnect
->ssid_len
) &&
2844 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2845 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2846 #ifndef CONFIG_NO_SCAN_PROCESSING
2847 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2848 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2849 fast_reconnect_ssid
) < 0) {
2850 /* Recover through full scan */
2851 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2853 #endif /* CONFIG_NO_SCAN_PROCESSING */
2854 } else if (fast_reconnect
) {
2856 * Could not reconnect to the same BSS due to network being
2857 * disabled. Use a new scan to match the alternative behavior
2858 * above, i.e., to continue automatic reconnection attempt in a
2859 * way that enforces disabled network rules.
2861 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2866 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2867 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2869 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2871 if (!wpa_s
->pending_mic_error_report
)
2874 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2875 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2876 wpa_s
->pending_mic_error_report
= 0;
2878 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2882 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2883 union wpa_event_data
*data
)
2886 struct os_reltime t
;
2888 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2889 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2891 if ((wpa_s
->last_michael_mic_error
.sec
&&
2892 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2893 wpa_s
->pending_mic_error_report
) {
2894 if (wpa_s
->pending_mic_error_report
) {
2896 * Send the pending MIC error report immediately since
2897 * we are going to start countermeasures and AP better
2900 wpa_sm_key_request(wpa_s
->wpa
, 1,
2901 wpa_s
->pending_mic_error_pairwise
);
2904 /* Send the new MIC error report immediately since we are going
2905 * to start countermeasures and AP better do the same.
2907 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2909 /* initialize countermeasures */
2910 wpa_s
->countermeasures
= 1;
2912 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2914 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2917 * Need to wait for completion of request frame. We do not get
2918 * any callback for the message completion, so just wait a
2919 * short while and hope for the best. */
2922 wpa_drv_set_countermeasures(wpa_s
, 1);
2923 wpa_supplicant_deauthenticate(wpa_s
,
2924 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2925 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2927 eloop_register_timeout(60, 0,
2928 wpa_supplicant_stop_countermeasures
,
2930 /* TODO: mark the AP rejected for 60 second. STA is
2931 * allowed to associate with another AP.. */
2933 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2934 if (wpa_s
->mic_errors_seen
) {
2936 * Reduce the effectiveness of Michael MIC error
2937 * reports as a means for attacking against TKIP if
2938 * more than one MIC failure is noticed with the same
2939 * PTK. We delay the transmission of the reports by a
2940 * random time between 0 and 60 seconds in order to
2941 * force the attacker wait 60 seconds before getting
2942 * the information on whether a frame resulted in a MIC
2948 if (os_get_random(rval
, sizeof(rval
)) < 0)
2949 sec
= os_random() % 60;
2951 sec
= WPA_GET_BE32(rval
) % 60;
2952 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2953 "report %d seconds", sec
);
2954 wpa_s
->pending_mic_error_report
= 1;
2955 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2956 eloop_cancel_timeout(
2957 wpa_supplicant_delayed_mic_error_report
,
2959 eloop_register_timeout(
2960 sec
, os_random() % 1000000,
2961 wpa_supplicant_delayed_mic_error_report
,
2964 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2966 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2967 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2968 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2970 wpa_s
->last_michael_mic_error
= t
;
2971 wpa_s
->mic_errors_seen
++;
2975 #ifdef CONFIG_TERMINATE_ONLASTIF
2976 static int any_interfaces(struct wpa_supplicant
*head
)
2978 struct wpa_supplicant
*wpa_s
;
2980 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2981 if (!wpa_s
->interface_removed
)
2985 #endif /* CONFIG_TERMINATE_ONLASTIF */
2989 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2990 union wpa_event_data
*data
)
2992 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2995 switch (data
->interface_status
.ievent
) {
2996 case EVENT_INTERFACE_ADDED
:
2997 if (!wpa_s
->interface_removed
)
2999 wpa_s
->interface_removed
= 0;
3000 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3001 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3002 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3003 "driver after interface was added");
3007 if (!wpa_s
->global
->p2p
&&
3008 !wpa_s
->global
->p2p_disabled
&&
3009 !wpa_s
->conf
->p2p_disabled
&&
3011 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3012 wpas_p2p_add_p2pdev_interface(
3013 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3014 wpa_printf(MSG_INFO
,
3015 "P2P: Failed to enable P2P Device interface");
3016 /* Try to continue without. P2P will be disabled. */
3018 #endif /* CONFIG_P2P */
3021 case EVENT_INTERFACE_REMOVED
:
3022 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3023 wpa_s
->interface_removed
= 1;
3024 wpa_supplicant_mark_disassoc(wpa_s
);
3025 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3026 l2_packet_deinit(wpa_s
->l2
);
3030 if (wpa_s
->global
->p2p
&&
3031 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3033 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3034 wpa_dbg(wpa_s
, MSG_DEBUG
,
3035 "Removing P2P Device interface");
3036 wpa_supplicant_remove_iface(
3037 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3039 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3041 #endif /* CONFIG_P2P */
3043 #ifdef CONFIG_MATCH_IFACE
3044 if (wpa_s
->matched
) {
3045 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3048 #endif /* CONFIG_MATCH_IFACE */
3050 #ifdef CONFIG_TERMINATE_ONLASTIF
3051 /* check if last interface */
3052 if (!any_interfaces(wpa_s
->global
->ifaces
))
3054 #endif /* CONFIG_TERMINATE_ONLASTIF */
3060 #ifdef CONFIG_PEERKEY
3062 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
3063 union wpa_event_data
*data
)
3067 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
3069 #endif /* CONFIG_PEERKEY */
3073 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3074 union wpa_event_data
*data
)
3078 switch (data
->tdls
.oper
) {
3079 case TDLS_REQUEST_SETUP
:
3080 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3081 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3082 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3084 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3086 case TDLS_REQUEST_TEARDOWN
:
3087 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3088 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3089 data
->tdls
.reason_code
);
3091 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3094 case TDLS_REQUEST_DISCOVER
:
3095 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3100 #endif /* CONFIG_TDLS */
3104 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3105 union wpa_event_data
*data
)
3109 switch (data
->wnm
.oper
) {
3110 case WNM_OPER_SLEEP
:
3111 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3112 "(action=%d, intval=%d)",
3113 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3114 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3115 data
->wnm
.sleep_intval
, NULL
);
3119 #endif /* CONFIG_WNM */
3122 #ifdef CONFIG_IEEE80211R
3124 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3125 union wpa_event_data
*data
)
3130 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3131 data
->ft_ies
.ies_len
,
3132 data
->ft_ies
.ft_action
,
3133 data
->ft_ies
.target_ap
,
3134 data
->ft_ies
.ric_ies
,
3135 data
->ft_ies
.ric_ies_len
) < 0) {
3136 /* TODO: prevent MLME/driver from trying to associate? */
3139 #endif /* CONFIG_IEEE80211R */
3142 #ifdef CONFIG_IBSS_RSN
3143 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3144 union wpa_event_data
*data
)
3146 struct wpa_ssid
*ssid
;
3147 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3151 ssid
= wpa_s
->current_ssid
;
3154 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3157 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3161 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3162 union wpa_event_data
*data
)
3164 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3169 /* check if the ssid is correctly configured as IBSS/RSN */
3170 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3173 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3174 data
->rx_mgmt
.frame_len
);
3176 #endif /* CONFIG_IBSS_RSN */
3179 #ifdef CONFIG_IEEE80211R
3180 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3183 const u8
*sta_addr
, *target_ap_addr
;
3186 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3187 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3188 return; /* only SME case supported for now */
3189 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3192 return; /* Only FT Action Response is supported for now */
3193 sta_addr
= data
+ 1;
3194 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3195 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3196 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3197 MACSTR
" TargetAP " MACSTR
" status %u",
3198 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3200 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3201 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3202 " in FT Action Response", MAC2STR(sta_addr
));
3207 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3208 "failure (status code %d)", status
);
3209 /* TODO: report error to FT code(?) */
3213 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3214 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3215 target_ap_addr
, NULL
, 0) < 0)
3220 struct wpa_bss
*bss
;
3221 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3223 wpa_s
->sme
.freq
= bss
->freq
;
3224 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3225 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3228 #endif /* CONFIG_SME */
3230 #endif /* CONFIG_IEEE80211R */
3233 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3234 struct unprot_deauth
*e
)
3236 #ifdef CONFIG_IEEE80211W
3237 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3238 "dropped: " MACSTR
" -> " MACSTR
3239 " (reason code %u)",
3240 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3241 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3242 #endif /* CONFIG_IEEE80211W */
3246 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3247 struct unprot_disassoc
*e
)
3249 #ifdef CONFIG_IEEE80211W
3250 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3251 "dropped: " MACSTR
" -> " MACSTR
3252 " (reason code %u)",
3253 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3254 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3255 #endif /* CONFIG_IEEE80211W */
3259 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3260 u16 reason_code
, int locally_generated
,
3261 const u8
*ie
, size_t ie_len
, int deauth
)
3264 if (wpa_s
->ap_iface
&& addr
) {
3265 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3269 if (wpa_s
->ap_iface
) {
3270 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3273 #endif /* CONFIG_AP */
3275 if (!locally_generated
)
3276 wpa_s
->own_disconnect_req
= 0;
3278 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3280 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3281 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3282 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3283 eapol_sm_failed(wpa_s
->eapol
))) &&
3284 !wpa_s
->eap_expected_failure
))
3285 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3288 if (deauth
&& reason_code
> 0) {
3289 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3290 locally_generated
) > 0) {
3292 * The interface was removed, so cannot continue
3293 * processing any additional operations after this.
3298 #endif /* CONFIG_P2P */
3300 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3305 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3306 struct disassoc_info
*info
)
3308 u16 reason_code
= 0;
3309 int locally_generated
= 0;
3310 const u8
*addr
= NULL
;
3311 const u8
*ie
= NULL
;
3314 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3319 ie_len
= info
->ie_len
;
3320 reason_code
= info
->reason_code
;
3321 locally_generated
= info
->locally_generated
;
3322 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3323 locally_generated
? " (locally generated)" : "");
3325 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3327 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3332 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3333 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3337 if (wpa_s
->ap_iface
) {
3338 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3341 #endif /* CONFIG_AP */
3345 wpas_p2p_disassoc_notif(
3346 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3349 #endif /* CONFIG_P2P */
3351 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3352 sme_event_disassoc(wpa_s
, info
);
3354 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3359 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3360 struct deauth_info
*info
)
3362 u16 reason_code
= 0;
3363 int locally_generated
= 0;
3364 const u8
*addr
= NULL
;
3365 const u8
*ie
= NULL
;
3368 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3373 ie_len
= info
->ie_len
;
3374 reason_code
= info
->reason_code
;
3375 locally_generated
= info
->locally_generated
;
3376 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3378 locally_generated
? " (locally generated)" : "");
3380 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3383 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3387 wpa_reset_ft_completed(wpa_s
->wpa
);
3389 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3390 locally_generated
, ie
, ie_len
, 1);
3394 static const char * reg_init_str(enum reg_change_initiator init
)
3397 case REGDOM_SET_BY_CORE
:
3399 case REGDOM_SET_BY_USER
:
3401 case REGDOM_SET_BY_DRIVER
:
3403 case REGDOM_SET_BY_COUNTRY_IE
:
3404 return "COUNTRY_IE";
3405 case REGDOM_BEACON_HINT
:
3406 return "BEACON_HINT";
3412 static const char * reg_type_str(enum reg_type type
)
3415 case REGDOM_TYPE_UNKNOWN
:
3417 case REGDOM_TYPE_COUNTRY
:
3419 case REGDOM_TYPE_WORLD
:
3421 case REGDOM_TYPE_CUSTOM_WORLD
:
3422 return "CUSTOM_WORLD";
3423 case REGDOM_TYPE_INTERSECTION
:
3424 return "INTERSECTION";
3430 static void wpa_supplicant_update_channel_list(
3431 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3433 struct wpa_supplicant
*ifs
;
3437 * To allow backwards compatibility with higher level layers that
3438 * assumed the REGDOM_CHANGE event is sent over the initially added
3439 * interface. Find the highest parent of this interface and use it to
3442 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3445 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3446 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3447 info
->alpha2
[0] ? " alpha2=" : "",
3448 info
->alpha2
[0] ? info
->alpha2
: "");
3450 if (wpa_s
->drv_priv
== NULL
)
3451 return; /* Ignore event during drv initialization */
3453 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3455 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3457 free_hw_features(ifs
);
3458 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3459 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3461 /* Restart PNO/sched_scan with updated channel list */
3464 wpas_start_pno(ifs
);
3465 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3466 wpa_dbg(ifs
, MSG_DEBUG
,
3467 "Channel list changed - restart sched_scan");
3468 wpas_scan_restart_sched_scan(ifs
);
3472 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3476 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3477 const u8
*frame
, size_t len
, int freq
,
3480 const struct ieee80211_mgmt
*mgmt
;
3485 if (len
< IEEE80211_HDRLEN
+ 2)
3488 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3489 payload
= frame
+ IEEE80211_HDRLEN
;
3490 category
= *payload
++;
3491 plen
= len
- IEEE80211_HDRLEN
- 1;
3493 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3494 " Category=%u DataLen=%d freq=%d MHz",
3495 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3497 if (category
== WLAN_ACTION_WMM
) {
3498 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3502 #ifdef CONFIG_IEEE80211R
3503 if (category
== WLAN_ACTION_FT
) {
3504 ft_rx_action(wpa_s
, payload
, plen
);
3507 #endif /* CONFIG_IEEE80211R */
3509 #ifdef CONFIG_IEEE80211W
3511 if (category
== WLAN_ACTION_SA_QUERY
) {
3512 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3515 #endif /* CONFIG_SME */
3516 #endif /* CONFIG_IEEE80211W */
3519 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3520 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3523 #endif /* CONFIG_WNM */
3526 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3527 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3528 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3529 mgmt
->u
.action
.category
,
3530 payload
, plen
, freq
) == 0)
3532 #endif /* CONFIG_GAS */
3534 #ifdef CONFIG_GAS_SERVER
3535 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3536 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3537 gas_server_rx(wpa_s
->gas_server
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3538 mgmt
->u
.action
.category
,
3539 payload
, plen
, freq
) == 0)
3541 #endif /* CONFIG_GAS_SERVER */
3544 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3545 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3546 wpa_dbg(wpa_s
, MSG_DEBUG
,
3547 "TDLS: Received Discovery Response from " MACSTR
,
3551 #endif /* CONFIG_TDLS */
3553 #ifdef CONFIG_INTERWORKING
3554 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3555 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3556 const u8
*pos
= payload
+ 1;
3557 size_t qlen
= plen
- 1;
3558 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3559 MACSTR
, MAC2STR(mgmt
->sa
));
3560 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3561 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3562 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3563 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3566 #endif /* CONFIG_INTERWORKING */
3568 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3569 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3570 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3576 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3577 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3578 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3582 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3583 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3584 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3585 payload
+ 1, plen
- 1,
3591 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3592 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3595 #endif /* CONFIG_FST */
3598 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3599 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3600 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3601 payload
[4] == DPP_OUI_TYPE
) {
3604 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3607 #endif /* CONFIG_DPP */
3609 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3610 category
, payload
, plen
, freq
);
3612 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3616 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3617 union wpa_event_data
*event
)
3619 struct wpa_freq_range_list
*list
;
3622 list
= &event
->freq_range
;
3625 str
= freq_range_list_str(list
);
3626 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3630 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3631 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3634 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3637 * The update channel flow will also take care of moving a GO
3638 * from the unsafe frequency if needed.
3640 wpas_p2p_update_channel_list(wpa_s
,
3641 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3643 #endif /* CONFIG_P2P */
3649 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3650 union wpa_event_data
*data
)
3652 wpa_dbg(wpa_s
, MSG_DEBUG
,
3653 "Connection authorized by device, previous state %d",
3655 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3656 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3657 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3658 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3659 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3661 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3662 data
->assoc_info
.ptk_kck_len
,
3663 data
->assoc_info
.ptk_kek
,
3664 data
->assoc_info
.ptk_kek_len
);
3666 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3667 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3668 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3670 /* Update ERP next sequence number */
3671 eapol_sm_update_erp_next_seq_num(
3672 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3674 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3675 /* Add the new PMK and PMKID to the PMKSA cache */
3676 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3677 data
->assoc_info
.fils_pmk
,
3678 data
->assoc_info
.fils_pmk_len
,
3679 data
->assoc_info
.fils_pmkid
,
3680 wpa_s
->bssid
, fils_cache_id
);
3681 } else if (data
->assoc_info
.fils_pmkid
) {
3682 /* Update the current PMKSA used for this connection */
3683 pmksa_cache_set_current(wpa_s
->wpa
,
3684 data
->assoc_info
.fils_pmkid
,
3685 NULL
, NULL
, 0, NULL
);
3688 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
,
3689 data
->assoc_info
.key_replay_ctr
);
3691 #else /* CONFIG_FILS */
3692 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3693 #endif /* CONFIG_FILS */
3697 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3698 union wpa_event_data
*data
)
3700 struct wpa_supplicant
*wpa_s
= ctx
;
3703 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3704 event
!= EVENT_INTERFACE_ENABLED
&&
3705 event
!= EVENT_INTERFACE_STATUS
&&
3706 event
!= EVENT_SCAN_RESULTS
&&
3707 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3708 wpa_dbg(wpa_s
, MSG_DEBUG
,
3709 "Ignore event %s (%d) while interface is disabled",
3710 event_to_string(event
), event
);
3714 #ifndef CONFIG_NO_STDOUT_DEBUG
3716 int level
= MSG_DEBUG
;
3718 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3719 const struct ieee80211_hdr
*hdr
;
3721 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3722 fc
= le_to_host16(hdr
->frame_control
);
3723 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3724 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3725 level
= MSG_EXCESSIVE
;
3728 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3729 event_to_string(event
), event
);
3731 #endif /* CONFIG_NO_STDOUT_DEBUG */
3736 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3737 data
->auth
.ies_len
))
3738 wpa_printf(MSG_DEBUG
,
3739 "FST: MB IEs updated from auth IE");
3740 #endif /* CONFIG_FST */
3741 sme_event_auth(wpa_s
, data
);
3744 #ifdef CONFIG_TESTING_OPTIONS
3745 if (wpa_s
->ignore_auth_resp
) {
3746 wpa_printf(MSG_INFO
,
3747 "EVENT_ASSOC - ignore_auth_resp active!");
3750 #endif /* CONFIG_TESTING_OPTIONS */
3751 wpa_supplicant_event_assoc(wpa_s
, data
);
3752 if ((data
&& data
->assoc_info
.authorized
) ||
3753 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
3754 wpa_fils_is_completed(wpa_s
->wpa
)))
3755 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3757 wpa_msg(wpa_s
, MSG_INFO
,
3758 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3759 data
->assoc_info
.subnet_status
);
3762 case EVENT_DISASSOC
:
3763 wpas_event_disassoc(wpa_s
,
3764 data
? &data
->disassoc_info
: NULL
);
3767 #ifdef CONFIG_TESTING_OPTIONS
3768 if (wpa_s
->ignore_auth_resp
) {
3769 wpa_printf(MSG_INFO
,
3770 "EVENT_DEAUTH - ignore_auth_resp active!");
3773 #endif /* CONFIG_TESTING_OPTIONS */
3774 wpas_event_deauth(wpa_s
,
3775 data
? &data
->deauth_info
: NULL
);
3777 case EVENT_MICHAEL_MIC_FAILURE
:
3778 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3780 #ifndef CONFIG_NO_SCAN_PROCESSING
3781 case EVENT_SCAN_STARTED
:
3782 if (wpa_s
->own_scan_requested
||
3783 (data
&& !data
->scan_info
.external_scan
)) {
3784 struct os_reltime diff
;
3786 os_get_reltime(&wpa_s
->scan_start_time
);
3787 os_reltime_sub(&wpa_s
->scan_start_time
,
3788 &wpa_s
->scan_trigger_time
, &diff
);
3789 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3790 diff
.sec
, diff
.usec
);
3791 wpa_s
->own_scan_requested
= 0;
3792 wpa_s
->own_scan_running
= 1;
3793 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3794 wpa_s
->manual_scan_use_id
) {
3795 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3796 WPA_EVENT_SCAN_STARTED
"id=%u",
3797 wpa_s
->manual_scan_id
);
3799 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3800 WPA_EVENT_SCAN_STARTED
);
3803 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3804 wpa_s
->radio
->external_scan_running
= 1;
3805 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3808 case EVENT_SCAN_RESULTS
:
3809 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3810 wpa_s
->scan_res_handler
= NULL
;
3811 wpa_s
->own_scan_running
= 0;
3812 wpa_s
->radio
->external_scan_running
= 0;
3813 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3817 if (!(data
&& data
->scan_info
.external_scan
) &&
3818 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3819 struct os_reltime now
, diff
;
3820 os_get_reltime(&now
);
3821 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3822 wpa_s
->scan_start_time
.sec
= 0;
3823 wpa_s
->scan_start_time
.usec
= 0;
3824 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3825 diff
.sec
, diff
.usec
);
3827 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3828 break; /* interface may have been removed */
3829 if (!(data
&& data
->scan_info
.external_scan
))
3830 wpa_s
->own_scan_running
= 0;
3831 if (data
&& data
->scan_info
.nl_scan_event
)
3832 wpa_s
->radio
->external_scan_running
= 0;
3833 radio_work_check_next(wpa_s
);
3835 #endif /* CONFIG_NO_SCAN_PROCESSING */
3836 case EVENT_ASSOCINFO
:
3837 wpa_supplicant_event_associnfo(wpa_s
, data
);
3839 case EVENT_INTERFACE_STATUS
:
3840 wpa_supplicant_event_interface_status(wpa_s
, data
);
3842 case EVENT_PMKID_CANDIDATE
:
3843 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3845 #ifdef CONFIG_PEERKEY
3846 case EVENT_STKSTART
:
3847 wpa_supplicant_event_stkstart(wpa_s
, data
);
3849 #endif /* CONFIG_PEERKEY */
3852 wpa_supplicant_event_tdls(wpa_s
, data
);
3854 #endif /* CONFIG_TDLS */
3857 wpa_supplicant_event_wnm(wpa_s
, data
);
3859 #endif /* CONFIG_WNM */
3860 #ifdef CONFIG_IEEE80211R
3861 case EVENT_FT_RESPONSE
:
3862 wpa_supplicant_event_ft_response(wpa_s
, data
);
3864 #endif /* CONFIG_IEEE80211R */
3865 #ifdef CONFIG_IBSS_RSN
3866 case EVENT_IBSS_RSN_START
:
3867 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3869 #endif /* CONFIG_IBSS_RSN */
3870 case EVENT_ASSOC_REJECT
:
3871 if (data
->assoc_reject
.bssid
)
3872 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3873 "bssid=" MACSTR
" status_code=%u%s%s%s",
3874 MAC2STR(data
->assoc_reject
.bssid
),
3875 data
->assoc_reject
.status_code
,
3876 data
->assoc_reject
.timed_out
? " timeout" : "",
3877 data
->assoc_reject
.timeout_reason
? "=" : "",
3878 data
->assoc_reject
.timeout_reason
?
3879 data
->assoc_reject
.timeout_reason
: "");
3881 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3882 "status_code=%u%s%s%s",
3883 data
->assoc_reject
.status_code
,
3884 data
->assoc_reject
.timed_out
? " timeout" : "",
3885 data
->assoc_reject
.timeout_reason
? "=" : "",
3886 data
->assoc_reject
.timeout_reason
?
3887 data
->assoc_reject
.timeout_reason
: "");
3888 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3889 wpas_notify_assoc_status_code(wpa_s
);
3890 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3891 sme_event_assoc_reject(wpa_s
, data
);
3893 const u8
*bssid
= data
->assoc_reject
.bssid
;
3896 /* Update ERP next sequence number */
3897 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
)
3898 eapol_sm_update_erp_next_seq_num(
3900 data
->assoc_reject
.fils_erp_next_seq_num
);
3901 #endif /* CONFIG_FILS */
3903 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
3904 bssid
= wpa_s
->pending_bssid
;
3905 wpas_connection_failed(wpa_s
, bssid
);
3906 wpa_supplicant_mark_disassoc(wpa_s
);
3909 case EVENT_AUTH_TIMED_OUT
:
3910 /* It is possible to get this event from earlier connection */
3911 if (wpa_s
->current_ssid
&&
3912 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3913 wpa_dbg(wpa_s
, MSG_DEBUG
,
3914 "Ignore AUTH_TIMED_OUT in mesh configuration");
3917 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3918 sme_event_auth_timed_out(wpa_s
, data
);
3920 case EVENT_ASSOC_TIMED_OUT
:
3921 /* It is possible to get this event from earlier connection */
3922 if (wpa_s
->current_ssid
&&
3923 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3924 wpa_dbg(wpa_s
, MSG_DEBUG
,
3925 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3928 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3929 sme_event_assoc_timed_out(wpa_s
, data
);
3931 case EVENT_TX_STATUS
:
3932 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3933 " type=%d stype=%d",
3934 MAC2STR(data
->tx_status
.dst
),
3935 data
->tx_status
.type
, data
->tx_status
.stype
);
3937 if (wpa_s
->ap_iface
== NULL
) {
3938 #ifdef CONFIG_OFFCHANNEL
3939 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3940 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3941 offchannel_send_action_tx_status(
3942 wpa_s
, data
->tx_status
.dst
,
3943 data
->tx_status
.data
,
3944 data
->tx_status
.data_len
,
3945 data
->tx_status
.ack
?
3946 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3947 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3948 #endif /* CONFIG_OFFCHANNEL */
3951 #endif /* CONFIG_AP */
3952 #ifdef CONFIG_OFFCHANNEL
3953 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3954 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
3956 * Catch TX status events for Action frames we sent via group
3957 * interface in GO mode, or via standalone AP interface.
3958 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3959 * except when the primary interface is used as a GO interface
3960 * (for drivers which do not have group interface concurrency)
3962 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3963 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3964 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
3965 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3966 offchannel_send_action_tx_status(
3967 wpa_s
->p2pdev
, data
->tx_status
.dst
,
3968 data
->tx_status
.data
,
3969 data
->tx_status
.data_len
,
3970 data
->tx_status
.ack
?
3971 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3972 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3975 #endif /* CONFIG_OFFCHANNEL */
3977 switch (data
->tx_status
.type
) {
3978 case WLAN_FC_TYPE_MGMT
:
3979 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3980 data
->tx_status
.data_len
,
3981 data
->tx_status
.stype
,
3982 data
->tx_status
.ack
);
3984 case WLAN_FC_TYPE_DATA
:
3985 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3986 data
->tx_status
.data
,
3987 data
->tx_status
.data_len
,
3988 data
->tx_status
.ack
);
3991 #endif /* CONFIG_AP */
3994 case EVENT_EAPOL_TX_STATUS
:
3995 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3996 data
->eapol_tx_status
.data
,
3997 data
->eapol_tx_status
.data_len
,
3998 data
->eapol_tx_status
.ack
);
4000 case EVENT_DRIVER_CLIENT_POLL_OK
:
4001 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
4003 case EVENT_RX_FROM_UNKNOWN
:
4004 if (wpa_s
->ap_iface
== NULL
)
4006 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
4007 data
->rx_from_unknown
.wds
);
4009 case EVENT_CH_SWITCH
:
4010 if (!data
|| !wpa_s
->current_ssid
)
4013 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4014 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4015 data
->ch_switch
.freq
,
4016 data
->ch_switch
.ht_enabled
,
4017 data
->ch_switch
.ch_offset
,
4018 channel_width_to_string(data
->ch_switch
.ch_width
),
4019 data
->ch_switch
.cf1
,
4020 data
->ch_switch
.cf2
);
4022 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4023 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4025 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4026 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4027 wpa_s
->current_ssid
->mode
==
4028 WPAS_MODE_P2P_GROUP_FORMATION
) {
4029 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4030 data
->ch_switch
.ht_enabled
,
4031 data
->ch_switch
.ch_offset
,
4032 data
->ch_switch
.ch_width
,
4033 data
->ch_switch
.cf1
,
4034 data
->ch_switch
.cf2
);
4037 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4040 case EVENT_DFS_RADAR_DETECTED
:
4042 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
4044 case EVENT_DFS_CAC_STARTED
:
4046 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4048 case EVENT_DFS_CAC_FINISHED
:
4050 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4052 case EVENT_DFS_CAC_ABORTED
:
4054 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4056 case EVENT_DFS_NOP_FINISHED
:
4058 wpas_event_dfs_cac_nop_finished(wpa_s
,
4061 #endif /* NEED_AP_MLME */
4062 #endif /* CONFIG_AP */
4063 case EVENT_RX_MGMT
: {
4065 const struct ieee80211_mgmt
*mgmt
;
4067 #ifdef CONFIG_TESTING_OPTIONS
4068 if (wpa_s
->ext_mgmt_frame_handling
) {
4069 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4070 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4071 char *hex
= os_malloc(hex_len
);
4073 wpa_snprintf_hex(hex
, hex_len
,
4074 rx
->frame
, rx
->frame_len
);
4075 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4076 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4082 #endif /* CONFIG_TESTING_OPTIONS */
4084 mgmt
= (const struct ieee80211_mgmt
*)
4085 data
->rx_mgmt
.frame
;
4086 fc
= le_to_host16(mgmt
->frame_control
);
4087 stype
= WLAN_FC_GET_STYPE(fc
);
4090 if (wpa_s
->ap_iface
== NULL
) {
4091 #endif /* CONFIG_AP */
4093 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4094 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4095 const u8
*src
= mgmt
->sa
;
4099 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4100 ie_len
= data
->rx_mgmt
.frame_len
-
4102 wpas_p2p_probe_req_rx(
4103 wpa_s
, src
, mgmt
->da
,
4104 mgmt
->bssid
, ie
, ie_len
,
4106 data
->rx_mgmt
.ssi_signal
);
4109 #endif /* CONFIG_P2P */
4110 #ifdef CONFIG_IBSS_RSN
4111 if (wpa_s
->current_ssid
&&
4112 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4113 stype
== WLAN_FC_STYPE_AUTH
&&
4114 data
->rx_mgmt
.frame_len
>= 30) {
4115 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4118 #endif /* CONFIG_IBSS_RSN */
4120 if (stype
== WLAN_FC_STYPE_ACTION
) {
4121 wpas_event_rx_mgmt_action(
4122 wpa_s
, data
->rx_mgmt
.frame
,
4123 data
->rx_mgmt
.frame_len
,
4125 data
->rx_mgmt
.ssi_signal
);
4130 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4134 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4135 "management frame in non-AP mode");
4140 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4141 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4145 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4146 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4148 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4149 mgmt
->bssid
, ie
, ie_len
,
4150 data
->rx_mgmt
.ssi_signal
);
4153 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4154 #endif /* CONFIG_AP */
4157 case EVENT_RX_PROBE_REQ
:
4158 if (data
->rx_probe_req
.sa
== NULL
||
4159 data
->rx_probe_req
.ie
== NULL
)
4162 if (wpa_s
->ap_iface
) {
4163 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4164 data
->rx_probe_req
.sa
,
4165 data
->rx_probe_req
.da
,
4166 data
->rx_probe_req
.bssid
,
4167 data
->rx_probe_req
.ie
,
4168 data
->rx_probe_req
.ie_len
,
4169 data
->rx_probe_req
.ssi_signal
);
4172 #endif /* CONFIG_AP */
4173 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4174 data
->rx_probe_req
.da
,
4175 data
->rx_probe_req
.bssid
,
4176 data
->rx_probe_req
.ie
,
4177 data
->rx_probe_req
.ie_len
,
4179 data
->rx_probe_req
.ssi_signal
);
4181 case EVENT_REMAIN_ON_CHANNEL
:
4182 #ifdef CONFIG_OFFCHANNEL
4183 offchannel_remain_on_channel_cb(
4184 wpa_s
, data
->remain_on_channel
.freq
,
4185 data
->remain_on_channel
.duration
);
4186 #endif /* CONFIG_OFFCHANNEL */
4187 wpas_p2p_remain_on_channel_cb(
4188 wpa_s
, data
->remain_on_channel
.freq
,
4189 data
->remain_on_channel
.duration
);
4191 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4192 #ifdef CONFIG_OFFCHANNEL
4193 offchannel_cancel_remain_on_channel_cb(
4194 wpa_s
, data
->remain_on_channel
.freq
);
4195 #endif /* CONFIG_OFFCHANNEL */
4196 wpas_p2p_cancel_remain_on_channel_cb(
4197 wpa_s
, data
->remain_on_channel
.freq
);
4199 wpas_dpp_cancel_remain_on_channel_cb(
4200 wpa_s
, data
->remain_on_channel
.freq
);
4201 #endif /* CONFIG_DPP */
4203 case EVENT_EAPOL_RX
:
4204 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4205 data
->eapol_rx
.data
,
4206 data
->eapol_rx
.data_len
);
4208 case EVENT_SIGNAL_CHANGE
:
4209 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4210 "above=%d signal=%d noise=%d txrate=%d",
4211 data
->signal_change
.above_threshold
,
4212 data
->signal_change
.current_signal
,
4213 data
->signal_change
.current_noise
,
4214 data
->signal_change
.current_txrate
);
4215 wpa_bss_update_level(wpa_s
->current_bss
,
4216 data
->signal_change
.current_signal
);
4217 bgscan_notify_signal_change(
4218 wpa_s
, data
->signal_change
.above_threshold
,
4219 data
->signal_change
.current_signal
,
4220 data
->signal_change
.current_noise
,
4221 data
->signal_change
.current_txrate
);
4223 case EVENT_INTERFACE_ENABLED
:
4224 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4225 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4226 wpa_supplicant_update_mac_addr(wpa_s
);
4227 if (wpa_s
->p2p_mgmt
) {
4228 wpa_supplicant_set_state(wpa_s
,
4234 if (!wpa_s
->ap_iface
) {
4235 wpa_supplicant_set_state(wpa_s
,
4237 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4238 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4240 wpa_supplicant_set_state(wpa_s
,
4242 #else /* CONFIG_AP */
4243 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4244 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4245 #endif /* CONFIG_AP */
4248 case EVENT_INTERFACE_DISABLED
:
4249 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4251 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4252 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4253 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4255 * Mark interface disabled if this happens to end up not
4256 * being removed as a separate P2P group interface.
4258 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4260 * The interface was externally disabled. Remove
4261 * it assuming an external entity will start a
4262 * new session if needed.
4264 if (wpa_s
->current_ssid
&&
4265 wpa_s
->current_ssid
->p2p_group
)
4266 wpas_p2p_interface_unavailable(wpa_s
);
4268 wpas_p2p_disconnect(wpa_s
);
4270 * wpa_s instance may have been freed, so must not use
4275 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4276 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4277 /* This radio work will be cancelled, so clear P2P
4280 p2p_stop_find(wpa_s
->global
->p2p
);
4282 #endif /* CONFIG_P2P */
4284 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4286 * Indicate disconnection to keep ctrl_iface events
4289 wpa_supplicant_event_disassoc(
4290 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4292 wpa_supplicant_mark_disassoc(wpa_s
);
4293 wpa_bss_flush(wpa_s
);
4294 radio_remove_works(wpa_s
, NULL
, 0);
4296 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4298 case EVENT_CHANNEL_LIST_CHANGED
:
4299 wpa_supplicant_update_channel_list(
4300 wpa_s
, &data
->channel_list_changed
);
4302 case EVENT_INTERFACE_UNAVAILABLE
:
4303 wpas_p2p_interface_unavailable(wpa_s
);
4305 case EVENT_BEST_CHANNEL
:
4306 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4308 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4309 data
->best_chan
.freq_overall
);
4310 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4311 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4312 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4313 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4314 data
->best_chan
.freq_5
,
4315 data
->best_chan
.freq_overall
);
4317 case EVENT_UNPROT_DEAUTH
:
4318 wpa_supplicant_event_unprot_deauth(wpa_s
,
4319 &data
->unprot_deauth
);
4321 case EVENT_UNPROT_DISASSOC
:
4322 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4323 &data
->unprot_disassoc
);
4325 case EVENT_STATION_LOW_ACK
:
4327 if (wpa_s
->ap_iface
&& data
)
4328 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4329 data
->low_ack
.addr
);
4330 #endif /* CONFIG_AP */
4333 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4334 data
->low_ack
.addr
);
4335 #endif /* CONFIG_TDLS */
4337 case EVENT_IBSS_PEER_LOST
:
4338 #ifdef CONFIG_IBSS_RSN
4339 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4340 #endif /* CONFIG_IBSS_RSN */
4342 case EVENT_DRIVER_GTK_REKEY
:
4343 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4344 wpa_s
->bssid
, ETH_ALEN
))
4348 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4349 data
->driver_gtk_rekey
.replay_ctr
);
4351 case EVENT_SCHED_SCAN_STOPPED
:
4352 wpa_s
->sched_scanning
= 0;
4353 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4354 wpa_supplicant_notify_scanning(wpa_s
, 0);
4356 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4360 * If the driver stopped scanning without being requested to,
4361 * request a new scan to continue scanning for networks.
4363 if (!wpa_s
->sched_scan_stop_req
&&
4364 wpa_s
->wpa_state
== WPA_SCANNING
) {
4365 wpa_dbg(wpa_s
, MSG_DEBUG
,
4366 "Restart scanning after unexpected sched_scan stop event");
4367 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4371 wpa_s
->sched_scan_stop_req
= 0;
4374 * Start a new sched scan to continue searching for more SSIDs
4375 * either if timed out or PNO schedule scan is pending.
4377 if (wpa_s
->sched_scan_timed_out
) {
4378 wpa_supplicant_req_sched_scan(wpa_s
);
4379 } else if (wpa_s
->pno_sched_pending
) {
4380 wpa_s
->pno_sched_pending
= 0;
4381 wpas_start_pno(wpa_s
);
4382 } else if (resched
) {
4383 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4387 case EVENT_WPS_BUTTON_PUSHED
:
4389 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4390 #endif /* CONFIG_WPS */
4392 case EVENT_AVOID_FREQUENCIES
:
4393 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4395 case EVENT_CONNECT_FAILED_REASON
:
4397 if (!wpa_s
->ap_iface
|| !data
)
4399 hostapd_event_connect_failed_reason(
4400 wpa_s
->ap_iface
->bss
[0],
4401 data
->connect_failed_reason
.addr
,
4402 data
->connect_failed_reason
.code
);
4403 #endif /* CONFIG_AP */
4405 case EVENT_NEW_PEER_CANDIDATE
:
4407 if (!wpa_s
->ifmsh
|| !data
)
4409 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4410 data
->mesh_peer
.ies
,
4411 data
->mesh_peer
.ie_len
);
4412 #endif /* CONFIG_MESH */
4416 if (!wpa_s
->ap_iface
)
4418 hostapd_event_get_survey(wpa_s
->ap_iface
,
4419 &data
->survey_results
);
4420 #endif /* CONFIG_AP */
4422 case EVENT_ACS_CHANNEL_SELECTED
:
4425 if (!wpa_s
->ap_iface
)
4427 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4428 &data
->acs_selected_channels
);
4429 #endif /* CONFIG_ACS */
4430 #endif /* CONFIG_AP */
4432 case EVENT_P2P_LO_STOP
:
4434 wpa_s
->p2p_lo_started
= 0;
4435 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4436 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4437 data
->p2p_lo_stop
.reason_code
);
4438 #endif /* CONFIG_P2P */
4440 case EVENT_BEACON_LOSS
:
4441 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4443 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4444 bgscan_notify_beacon_loss(wpa_s
);
4447 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4453 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4454 union wpa_event_data
*data
)
4456 struct wpa_supplicant
*wpa_s
;
4458 if (event
!= EVENT_INTERFACE_STATUS
)
4461 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4462 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4463 unsigned int ifindex
;
4465 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4466 if (ifindex
!= data
->interface_status
.ifindex
) {
4467 wpa_dbg(wpa_s
, MSG_DEBUG
,
4468 "interface status ifindex %d mismatch (%d)",
4469 ifindex
, data
->interface_status
.ifindex
);
4473 #ifdef CONFIG_MATCH_IFACE
4474 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4475 struct wpa_interface
*wpa_i
;
4477 wpa_i
= wpa_supplicant_match_iface(
4478 ctx
, data
->interface_status
.ifname
);
4481 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4486 #endif /* CONFIG_MATCH_IFACE */
4489 wpa_supplicant_event(wpa_s
, event
, data
);