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 "crypto/random.h"
33 #include "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
38 #include "gas_query.h"
39 #include "p2p_supplicant.h"
45 #include "offchannel.h"
46 #include "interworking.h"
50 #include "dpp_supplicant.h"
53 #ifndef CONFIG_NO_SCAN_PROCESSING
54 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
55 int new_scan
, int own_request
);
56 #endif /* CONFIG_NO_SCAN_PROCESSING */
59 int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
61 struct os_reltime now
;
63 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
67 if (ssid
->disabled_until
.sec
> now
.sec
)
68 return ssid
->disabled_until
.sec
- now
.sec
;
70 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
76 #ifndef CONFIG_NO_SCAN_PROCESSING
78 * wpas_reenabled_network_time - Time until first network is re-enabled
79 * @wpa_s: Pointer to wpa_supplicant data
80 * Returns: If all enabled networks are temporarily disabled, returns the time
81 * (in sec) until the first network is re-enabled. Otherwise returns 0.
83 * This function is used in case all enabled networks are temporarily disabled,
84 * in which case it returns the time (in sec) that the first network will be
85 * re-enabled. The function assumes that at least one network is enabled.
87 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
89 struct wpa_ssid
*ssid
;
90 int disabled_for
, res
= 0;
92 #ifdef CONFIG_INTERWORKING
93 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
96 #endif /* CONFIG_INTERWORKING */
98 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
102 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
106 if (!res
|| disabled_for
< res
)
112 #endif /* CONFIG_NO_SCAN_PROCESSING */
115 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
117 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
119 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
122 wpa_dbg(wpa_s
, MSG_DEBUG
,
123 "Try to associate due to network getting re-enabled");
124 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
125 wpa_supplicant_cancel_sched_scan(wpa_s
);
126 wpa_supplicant_req_scan(wpa_s
, 0, 0);
131 static struct wpa_bss
* wpa_supplicant_get_new_bss(
132 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
134 struct wpa_bss
*bss
= NULL
;
135 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
137 if (ssid
->ssid_len
> 0)
138 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
140 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
146 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
148 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
151 wpa_supplicant_update_scan_results(wpa_s
);
153 /* Get the BSS from the new scan results */
154 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
158 wpa_s
->current_bss
= bss
;
162 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
164 struct wpa_ssid
*ssid
, *old_ssid
;
165 u8 drv_ssid
[SSID_MAX_LEN
];
169 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
170 wpa_supplicant_update_current_bss(wpa_s
);
172 if (wpa_s
->current_ssid
->ssid_len
== 0)
173 return 0; /* current profile still in use */
174 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
176 wpa_msg(wpa_s
, MSG_INFO
,
177 "Failed to read SSID from driver");
178 return 0; /* try to use current profile */
182 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
183 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
185 return 0; /* current profile still in use */
187 wpa_msg(wpa_s
, MSG_DEBUG
,
188 "Driver-initiated BSS selection changed the SSID to %s",
189 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
190 /* continue selecting a new network profile */
193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
195 ssid
= wpa_supplicant_get_ssid(wpa_s
);
197 wpa_msg(wpa_s
, MSG_INFO
,
198 "No network configuration found for the current AP");
202 if (wpas_network_disabled(wpa_s
, ssid
)) {
203 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
207 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
208 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
209 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
213 res
= wpas_temp_disabled(wpa_s
, ssid
);
215 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
216 "disabled for %d second(s)", res
);
220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
222 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
224 size_t wpa_ie_len
= sizeof(wpa_ie
);
225 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
226 wpa_ie
, &wpa_ie_len
) < 0)
227 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
229 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
232 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
233 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
234 old_ssid
= wpa_s
->current_ssid
;
235 wpa_s
->current_ssid
= ssid
;
237 wpa_supplicant_update_current_bss(wpa_s
);
239 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
240 wpa_supplicant_initiate_eapol(wpa_s
);
241 if (old_ssid
!= wpa_s
->current_ssid
)
242 wpas_notify_network_changed(wpa_s
);
248 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
250 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
252 if (wpa_s
->countermeasures
) {
253 wpa_s
->countermeasures
= 0;
254 wpa_drv_set_countermeasures(wpa_s
, 0);
255 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
258 * It is possible that the device is sched scanning, which means
259 * that a connection attempt will be done only when we receive
260 * scan results. However, in this case, it would be preferable
261 * to scan and connect immediately, so cancel the sched_scan and
262 * issue a regular scan flow.
264 wpa_supplicant_cancel_sched_scan(wpa_s
);
265 wpa_supplicant_req_scan(wpa_s
, 0, 0);
270 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
274 wnm_bss_keep_alive_deinit(wpa_s
);
276 #ifdef CONFIG_IBSS_RSN
277 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
278 wpa_s
->ibss_rsn
= NULL
;
279 #endif /* CONFIG_IBSS_RSN */
282 wpa_supplicant_ap_deinit(wpa_s
);
283 #endif /* CONFIG_AP */
286 /* Clear possibly configured frame filters */
287 wpa_drv_configure_frame_filters(wpa_s
, 0);
288 #endif /* CONFIG_HS20 */
290 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
293 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
294 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
295 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
296 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
297 sme_clear_on_disassoc(wpa_s
);
298 wpa_s
->current_bss
= NULL
;
299 wpa_s
->assoc_freq
= 0;
302 wpas_notify_bssid_changed(wpa_s
);
304 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
305 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
306 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
307 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
)
308 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
309 wpa_s
->ap_ies_from_associnfo
= 0;
310 wpa_s
->current_ssid
= NULL
;
311 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
314 wpas_rrm_reset(wpa_s
);
315 wpa_s
->wnmsleep_used
= 0;
319 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
321 struct wpa_ie_data ie
;
325 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
329 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
330 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
331 ie
.pmkid
+ i
* PMKID_LEN
,
332 NULL
, NULL
, 0, NULL
);
333 if (pmksa_set
== 0) {
334 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
339 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
340 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
344 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
345 union wpa_event_data
*data
)
348 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
352 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
353 " index=%d preauth=%d",
354 MAC2STR(data
->pmkid_candidate
.bssid
),
355 data
->pmkid_candidate
.index
,
356 data
->pmkid_candidate
.preauth
);
358 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
359 data
->pmkid_candidate
.index
,
360 data
->pmkid_candidate
.preauth
);
364 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
366 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
367 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
370 #ifdef IEEE8021X_EAPOL
371 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
372 wpa_s
->current_ssid
&&
373 !(wpa_s
->current_ssid
->eapol_flags
&
374 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
375 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
376 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
377 * plaintext or static WEP keys). */
380 #endif /* IEEE8021X_EAPOL */
387 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
388 * @wpa_s: pointer to wpa_supplicant data
389 * @ssid: Configuration data for the network
390 * Returns: 0 on success, -1 on failure
392 * This function is called when starting authentication with a network that is
393 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
395 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
396 struct wpa_ssid
*ssid
)
398 #ifdef IEEE8021X_EAPOL
400 int aka
= 0, sim
= 0;
402 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
403 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
406 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
410 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
411 while (eap
->vendor
!= EAP_VENDOR_IETF
||
412 eap
->method
!= EAP_TYPE_NONE
) {
413 if (eap
->vendor
== EAP_VENDOR_IETF
) {
414 if (eap
->method
== EAP_TYPE_SIM
)
416 else if (eap
->method
== EAP_TYPE_AKA
||
417 eap
->method
== EAP_TYPE_AKA_PRIME
)
424 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
426 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
427 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
432 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
433 "use SIM, but neither EAP-SIM nor EAP-AKA are "
438 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
439 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
441 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
442 if (wpa_s
->scard
== NULL
) {
443 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
447 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
448 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
449 #endif /* PCSC_FUNCS */
450 #endif /* IEEE8021X_EAPOL */
456 #ifndef CONFIG_NO_SCAN_PROCESSING
458 static int has_wep_key(struct wpa_ssid
*ssid
)
462 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
463 if (ssid
->wep_key_len
[i
])
471 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
472 struct wpa_ssid
*ssid
)
476 if (ssid
->mixed_cell
)
480 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
482 #endif /* CONFIG_WPS */
484 if (has_wep_key(ssid
))
487 #ifdef IEEE8021X_EAPOL
488 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
489 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
490 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
492 #endif /* IEEE8021X_EAPOL */
494 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
497 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
500 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
506 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
507 struct wpa_ssid
*ssid
,
508 struct wpa_bss
*bss
, int debug_print
)
510 struct wpa_ie_data ie
;
512 const u8
*rsn_ie
, *wpa_ie
;
516 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
520 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
521 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
522 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
523 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
524 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
526 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
527 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
530 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
532 wpa_dbg(wpa_s
, MSG_DEBUG
,
533 " skip RSN IE - parse failed");
538 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
541 wpa_dbg(wpa_s
, MSG_DEBUG
,
542 " selected based on TSN in RSN IE");
546 if (!(ie
.proto
& ssid
->proto
)) {
548 wpa_dbg(wpa_s
, MSG_DEBUG
,
549 " skip RSN IE - proto mismatch");
553 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
555 wpa_dbg(wpa_s
, MSG_DEBUG
,
556 " skip RSN IE - PTK cipher mismatch");
560 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
562 wpa_dbg(wpa_s
, MSG_DEBUG
,
563 " skip RSN IE - GTK cipher mismatch");
567 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
569 wpa_dbg(wpa_s
, MSG_DEBUG
,
570 " skip RSN IE - key mgmt mismatch");
574 #ifdef CONFIG_IEEE80211W
575 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
576 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
577 MGMT_FRAME_PROTECTION_REQUIRED
) {
579 wpa_dbg(wpa_s
, MSG_DEBUG
,
580 " skip RSN IE - no mgmt frame protection");
583 #endif /* CONFIG_IEEE80211W */
584 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
585 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
586 NO_MGMT_FRAME_PROTECTION
) {
588 wpa_dbg(wpa_s
, MSG_DEBUG
,
589 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
593 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
594 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
595 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
596 NO_MGMT_FRAME_PROTECTION
) {
598 wpa_dbg(wpa_s
, MSG_DEBUG
,
599 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
602 #endif /* CONFIG_MBO */
605 wpa_dbg(wpa_s
, MSG_DEBUG
,
606 " selected based on RSN IE");
610 #ifdef CONFIG_IEEE80211W
611 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
613 wpa_dbg(wpa_s
, MSG_DEBUG
,
614 " skip - MFP Required but network not MFP Capable");
617 #endif /* CONFIG_IEEE80211W */
619 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
620 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
623 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
625 wpa_dbg(wpa_s
, MSG_DEBUG
,
626 " skip WPA IE - parse failed");
631 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
634 wpa_dbg(wpa_s
, MSG_DEBUG
,
635 " selected based on TSN in WPA IE");
639 if (!(ie
.proto
& ssid
->proto
)) {
641 wpa_dbg(wpa_s
, MSG_DEBUG
,
642 " skip WPA IE - proto mismatch");
646 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
648 wpa_dbg(wpa_s
, MSG_DEBUG
,
649 " skip WPA IE - PTK cipher mismatch");
653 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
655 wpa_dbg(wpa_s
, MSG_DEBUG
,
656 " skip WPA IE - GTK cipher mismatch");
660 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
662 wpa_dbg(wpa_s
, MSG_DEBUG
,
663 " skip WPA IE - key mgmt mismatch");
668 wpa_dbg(wpa_s
, MSG_DEBUG
,
669 " selected based on WPA IE");
673 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
676 wpa_dbg(wpa_s
, MSG_DEBUG
,
677 " allow for non-WPA IEEE 802.1X");
681 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
682 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
684 wpa_dbg(wpa_s
, MSG_DEBUG
,
685 " skip - no WPA/RSN proto match");
689 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
690 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
692 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
696 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
698 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
703 wpa_dbg(wpa_s
, MSG_DEBUG
,
704 " reject due to mismatch with WPA/WPA2");
710 static int freq_allowed(int *freqs
, int freq
)
717 for (i
= 0; freqs
[i
]; i
++)
718 if (freqs
[i
] == freq
)
724 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
727 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
728 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
733 return 1; /* Cannot do matching without knowing band */
735 modes
= wpa_s
->hw
.modes
;
738 * The driver does not provide any additional information
739 * about the utilized hardware, so allow the connection attempt
745 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
746 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
747 int freq
= modes
[i
].channels
[j
].freq
;
748 if (freq
== bss
->freq
) {
750 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
751 break; /* do not allow 802.11b replace
762 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
763 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
767 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
768 int flagged
= !!(rate_ie
[j
] & 0x80);
769 int r
= (rate_ie
[j
] & 0x7f) * 5;
772 * IEEE Std 802.11n-2009 7.3.2.2:
773 * The new BSS Membership selector value is encoded
774 * like a legacy basic rate, but it is not a rate and
775 * only indicates if the BSS members are required to
776 * support the mandatory features of Clause 20 [HT PHY]
777 * in order to join the BSS.
779 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
780 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
781 if (!ht_supported(mode
)) {
783 wpa_dbg(wpa_s
, MSG_DEBUG
,
784 " hardware does not support HT PHY");
790 /* There's also a VHT selector for 802.11ac */
791 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
792 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
793 if (!vht_supported(mode
)) {
795 wpa_dbg(wpa_s
, MSG_DEBUG
,
796 " hardware does not support VHT PHY");
805 /* check for legacy basic rates */
806 for (k
= 0; k
< mode
->num_rates
; k
++) {
807 if (mode
->rates
[k
] == r
)
810 if (k
== mode
->num_rates
) {
812 * IEEE Std 802.11-2007 7.3.2.2 demands that in
813 * order to join a BSS all required rates
814 * have to be supported by the hardware.
817 wpa_dbg(wpa_s
, MSG_DEBUG
,
818 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
820 bss
->freq
, mode
->mode
, mode
->num_rates
);
831 * Test whether BSS is in an ESS.
832 * This is done differently in DMG (60 GHz) and non-DMG bands
834 static int bss_is_ess(struct wpa_bss
*bss
)
836 if (bss_is_dmg(bss
)) {
837 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
838 IEEE80211_CAP_DMG_AP
;
841 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
846 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
850 for (i
= 0; i
< ETH_ALEN
; i
++) {
851 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
858 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
862 for (i
= 0; i
< num
; i
++) {
863 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
864 const u8
*m
= a
+ ETH_ALEN
;
866 if (match_mac_mask(a
, addr
, m
))
873 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
874 int i
, struct wpa_bss
*bss
,
875 struct wpa_ssid
*group
,
876 int only_first_ssid
, int debug_print
)
878 u8 wpa_ie_len
, rsn_ie_len
;
880 struct wpa_blacklist
*e
;
882 struct wpa_ssid
*ssid
;
885 const u8
*assoc_disallow
;
886 #endif /* CONFIG_MBO */
888 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
889 wpa_ie_len
= ie
? ie
[1] : 0;
891 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
892 rsn_ie_len
= ie
? ie
[1] : 0;
894 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
898 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
899 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
900 i
, MAC2STR(bss
->bssid
),
901 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
902 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
904 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
906 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
907 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
909 osen
? " osen=1" : "");
912 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
915 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
917 * When only a single network is enabled, we can
918 * trigger blacklisting on the first failure. This
919 * should not be done with multiple enabled networks to
920 * avoid getting forced to move into a worse ESS on
921 * single error if there are no other BSSes of the
926 if (e
->count
> limit
) {
928 wpa_dbg(wpa_s
, MSG_DEBUG
,
929 " skip - blacklisted (count=%d limit=%d)",
936 if (bss
->ssid_len
== 0) {
938 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
942 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
944 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
948 if (disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
950 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
954 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
956 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
957 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
960 if (wpas_network_disabled(wpa_s
, ssid
)) {
962 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
966 res
= wpas_temp_disabled(wpa_s
, ssid
);
969 wpa_dbg(wpa_s
, MSG_DEBUG
,
970 " skip - disabled temporarily for %d second(s)",
976 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
978 wpa_dbg(wpa_s
, MSG_DEBUG
,
979 " skip - blacklisted (WPS)");
983 if (wpa
&& ssid
->ssid_len
== 0 &&
984 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
987 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
988 /* Only allow wildcard SSID match if an AP
989 * advertises active WPS operation that matches
992 if (ssid
->ssid_len
== 0 &&
993 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
996 #endif /* CONFIG_WPS */
998 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
999 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1003 (bss
->ssid_len
!= ssid
->ssid_len
||
1004 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
1006 wpa_dbg(wpa_s
, MSG_DEBUG
,
1007 " skip - SSID mismatch");
1011 if (ssid
->bssid_set
&&
1012 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1014 wpa_dbg(wpa_s
, MSG_DEBUG
,
1015 " skip - BSSID mismatch");
1019 /* check blacklist */
1020 if (ssid
->num_bssid_blacklist
&&
1021 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1022 ssid
->num_bssid_blacklist
)) {
1024 wpa_dbg(wpa_s
, MSG_DEBUG
,
1025 " skip - BSSID blacklisted");
1029 /* if there is a whitelist, only accept those APs */
1030 if (ssid
->num_bssid_whitelist
&&
1031 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1032 ssid
->num_bssid_whitelist
)) {
1034 wpa_dbg(wpa_s
, MSG_DEBUG
,
1035 " skip - BSSID not in whitelist");
1039 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1043 if (!osen
&& !wpa
&&
1044 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1045 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1046 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1048 wpa_dbg(wpa_s
, MSG_DEBUG
,
1049 " skip - non-WPA network not allowed");
1053 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1054 has_wep_key(ssid
)) {
1056 wpa_dbg(wpa_s
, MSG_DEBUG
,
1057 " skip - ignore WPA/WPA2 AP for WEP network block");
1061 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1063 wpa_dbg(wpa_s
, MSG_DEBUG
,
1064 " skip - non-OSEN network not allowed");
1068 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1070 wpa_dbg(wpa_s
, MSG_DEBUG
,
1071 " skip - privacy mismatch");
1075 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1076 !bss_is_pbss(bss
)) {
1078 wpa_dbg(wpa_s
, MSG_DEBUG
,
1079 " skip - not ESS, PBSS, or MBSS");
1083 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1085 wpa_dbg(wpa_s
, MSG_DEBUG
,
1086 " skip - PBSS mismatch (ssid %d bss %d)",
1087 ssid
->pbss
, bss_is_pbss(bss
));
1091 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1093 wpa_dbg(wpa_s
, MSG_DEBUG
,
1094 " skip - frequency not allowed");
1099 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1100 ssid
->frequency
!= bss
->freq
) {
1102 wpa_dbg(wpa_s
, MSG_DEBUG
,
1103 " skip - frequency not allowed (mesh)");
1106 #endif /* CONFIG_MESH */
1108 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1110 wpa_dbg(wpa_s
, MSG_DEBUG
,
1111 " skip - rate sets do not match");
1115 #ifndef CONFIG_IBSS_RSN
1116 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1117 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1118 WPA_KEY_MGMT_WPA_NONE
))) {
1120 wpa_dbg(wpa_s
, MSG_DEBUG
,
1121 " skip - IBSS RSN not supported in the build");
1124 #endif /* !CONFIG_IBSS_RSN */
1127 if (ssid
->p2p_group
&&
1128 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1129 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1131 wpa_dbg(wpa_s
, MSG_DEBUG
,
1132 " skip - no P2P IE seen");
1136 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1137 struct wpabuf
*p2p_ie
;
1138 u8 dev_addr
[ETH_ALEN
];
1140 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1143 wpa_dbg(wpa_s
, MSG_DEBUG
,
1144 " skip - no P2P element");
1147 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1148 bss
, P2P_IE_VENDOR_TYPE
);
1149 if (p2p_ie
== NULL
) {
1151 wpa_dbg(wpa_s
, MSG_DEBUG
,
1152 " skip - could not fetch P2P element");
1156 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1157 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1160 wpa_dbg(wpa_s
, MSG_DEBUG
,
1161 " skip - no matching GO P2P Device Address in P2P element");
1162 wpabuf_free(p2p_ie
);
1165 wpabuf_free(p2p_ie
);
1169 * TODO: skip the AP if its P2P IE has Group Formation
1170 * bit set in the P2P Group Capability Bitmap and we
1171 * are not in Group Formation with that device.
1173 #endif /* CONFIG_P2P */
1175 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1177 struct os_reltime diff
;
1179 os_reltime_sub(&wpa_s
->scan_min_time
,
1180 &bss
->last_update
, &diff
);
1182 wpa_dbg(wpa_s
, MSG_DEBUG
,
1183 " skip - scan result not recent enough (%u.%06u seconds too old)",
1184 (unsigned int) diff
.sec
,
1185 (unsigned int) diff
.usec
);
1189 #ifdef CONFIG_TESTING_OPTIONS
1190 if (wpa_s
->ignore_assoc_disallow
)
1191 goto skip_assoc_disallow
;
1192 #endif /* CONFIG_TESTING_OPTIONS */
1193 assoc_disallow
= wpas_mbo_get_bss_attr(
1194 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1195 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1197 wpa_dbg(wpa_s
, MSG_DEBUG
,
1198 " skip - MBO association disallowed (reason %u)",
1203 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1205 wpa_dbg(wpa_s
, MSG_DEBUG
,
1206 " skip - MBO retry delay has not passed yet");
1209 #ifdef CONFIG_TESTING_OPTIONS
1210 skip_assoc_disallow
:
1211 #endif /* CONFIG_TESTING_OPTIONS */
1212 #endif /* CONFIG_MBO */
1214 /* Matching configuration found */
1218 /* No matching configuration found */
1223 static struct wpa_bss
*
1224 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1225 struct wpa_ssid
*group
,
1226 struct wpa_ssid
**selected_ssid
,
1227 int only_first_ssid
)
1231 if (wpa_s
->current_ssid
) {
1232 struct wpa_ssid
*ssid
;
1234 wpa_dbg(wpa_s
, MSG_DEBUG
,
1235 "Scan results matching the currently selected network");
1236 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1237 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1239 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1240 only_first_ssid
, 0);
1241 if (ssid
!= wpa_s
->current_ssid
)
1243 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1244 " freq=%d level=%d snr=%d est_throughput=%u",
1245 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1246 bss
->snr
, bss
->est_throughput
);
1250 if (only_first_ssid
)
1251 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1254 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1257 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1258 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1259 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1260 only_first_ssid
, 1);
1261 if (!*selected_ssid
)
1263 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1265 MAC2STR(bss
->bssid
),
1266 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1274 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1275 struct wpa_ssid
**selected_ssid
)
1277 struct wpa_bss
*selected
= NULL
;
1279 struct wpa_ssid
*next_ssid
= NULL
;
1280 struct wpa_ssid
*ssid
;
1282 if (wpa_s
->last_scan_res
== NULL
||
1283 wpa_s
->last_scan_res_used
== 0)
1284 return NULL
; /* no scan results from last update */
1286 if (wpa_s
->next_ssid
) {
1287 /* check that next_ssid is still valid */
1288 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1289 if (ssid
== wpa_s
->next_ssid
)
1293 wpa_s
->next_ssid
= NULL
;
1296 while (selected
== NULL
) {
1297 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1298 if (next_ssid
&& next_ssid
->priority
==
1299 wpa_s
->conf
->pssid
[prio
]->priority
) {
1300 selected
= wpa_supplicant_select_bss(
1301 wpa_s
, next_ssid
, selected_ssid
, 1);
1305 selected
= wpa_supplicant_select_bss(
1306 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1312 if (selected
== NULL
&& wpa_s
->blacklist
&&
1313 !wpa_s
->countermeasures
) {
1314 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1315 "blacklist and try again");
1316 wpa_blacklist_clear(wpa_s
);
1317 wpa_s
->blacklist_cleared
++;
1318 } else if (selected
== NULL
)
1322 ssid
= *selected_ssid
;
1323 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1324 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1325 const char *field_name
, *txt
= NULL
;
1327 wpa_dbg(wpa_s
, MSG_DEBUG
,
1328 "PSK/passphrase not yet available for the selected network");
1330 wpas_notify_network_request(wpa_s
, ssid
,
1331 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1333 field_name
= wpa_supplicant_ctrl_req_to_string(
1334 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1335 if (field_name
== NULL
)
1338 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1347 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1348 int timeout_sec
, int timeout_usec
)
1350 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1352 * No networks are enabled; short-circuit request so
1353 * we don't wait timeout seconds before transitioning
1354 * to INACTIVE state.
1356 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1357 "since there are no enabled networks");
1358 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1362 wpa_s
->scan_for_connection
= 1;
1363 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1367 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1368 struct wpa_bss
*selected
,
1369 struct wpa_ssid
*ssid
)
1371 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1372 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1373 "PBC session overlap");
1374 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1376 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1377 wpa_s
->p2p_in_provisioning
) {
1378 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1382 #endif /* CONFIG_P2P */
1385 wpas_wps_pbc_overlap(wpa_s
);
1386 wpas_wps_cancel(wpa_s
);
1387 #endif /* CONFIG_WPS */
1391 wpa_msg(wpa_s
, MSG_DEBUG
,
1392 "Considering connect request: reassociate: %d selected: "
1393 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1394 " wpa_state: %s ssid=%p current_ssid=%p",
1395 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1396 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1397 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1398 ssid
, wpa_s
->current_ssid
);
1401 * Do not trigger new association unless the BSSID has changed or if
1402 * reassociation is requested. If we are in process of associating with
1403 * the selected BSSID, do not trigger new attempt.
1405 if (wpa_s
->reassociate
||
1406 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1407 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1408 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1409 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1410 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1412 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1413 ssid
!= wpa_s
->current_ssid
)))) {
1414 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1415 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1418 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1419 MAC2STR(selected
->bssid
));
1420 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1422 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1423 "connect with the selected AP");
1430 static struct wpa_ssid
*
1431 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1434 struct wpa_ssid
*ssid
;
1436 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1437 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1439 if (wpas_network_disabled(wpa_s
, ssid
))
1441 #ifndef CONFIG_IBSS_RSN
1442 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1443 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1444 WPA_KEY_MGMT_WPA_NONE
))) {
1445 wpa_msg(wpa_s
, MSG_INFO
,
1446 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1447 wpa_ssid_txt(ssid
->ssid
,
1451 #endif /* !CONFIG_IBSS_RSN */
1452 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1453 ssid
->mode
== IEEE80211_MODE_AP
||
1454 ssid
->mode
== IEEE80211_MODE_MESH
)
1462 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1463 * on BSS added and BSS changed events */
1464 static void wpa_supplicant_rsn_preauth_scan_results(
1465 struct wpa_supplicant
*wpa_s
)
1467 struct wpa_bss
*bss
;
1469 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1472 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1473 const u8
*ssid
, *rsn
;
1475 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1479 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1483 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1489 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1490 struct wpa_bss
*selected
,
1491 struct wpa_ssid
*ssid
)
1493 struct wpa_bss
*current_bss
= NULL
;
1494 #ifndef CONFIG_NO_ROAMING
1497 int cur_est
, sel_est
;
1498 #endif /* CONFIG_NO_ROAMING */
1500 if (wpa_s
->reassociate
)
1501 return 1; /* explicit request to reassociate */
1502 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1503 return 1; /* we are not associated; continue */
1504 if (wpa_s
->current_ssid
== NULL
)
1505 return 1; /* unknown current SSID */
1506 if (wpa_s
->current_ssid
!= ssid
)
1507 return 1; /* different network block */
1509 if (wpas_driver_bss_selection(wpa_s
))
1510 return 0; /* Driver-based roaming */
1512 if (wpa_s
->current_ssid
->ssid
)
1513 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1514 wpa_s
->current_ssid
->ssid
,
1515 wpa_s
->current_ssid
->ssid_len
);
1517 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1520 return 1; /* current BSS not seen in scan results */
1522 if (current_bss
== selected
)
1525 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1526 return 1; /* current BSS not seen in the last scan */
1528 #ifndef CONFIG_NO_ROAMING
1529 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1530 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1531 " freq=%d level=%d snr=%d est_throughput=%u",
1532 MAC2STR(current_bss
->bssid
),
1533 current_bss
->freq
, current_bss
->level
,
1534 current_bss
->snr
, current_bss
->est_throughput
);
1535 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1536 " freq=%d level=%d snr=%d est_throughput=%u",
1537 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1538 selected
->snr
, selected
->est_throughput
);
1540 if (wpa_s
->current_ssid
->bssid_set
&&
1541 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1543 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1544 "has preferred BSSID");
1548 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1549 wpa_dbg(wpa_s
, MSG_DEBUG
,
1550 "Allow reassociation - selected BSS has better estimated throughput");
1554 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1556 if (current_bss
->level
< 0 &&
1557 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1558 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1563 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1564 wpa_dbg(wpa_s
, MSG_DEBUG
,
1565 "Skip roam - Current BSS has better estimated throughput");
1569 cur_est
= current_bss
->est_throughput
;
1570 sel_est
= selected
->est_throughput
;
1572 if (current_bss
->level
< 0) {
1573 if (current_bss
->level
< -85)
1575 else if (current_bss
->level
< -80)
1577 else if (current_bss
->level
< -75)
1579 else if (current_bss
->level
< -70)
1583 if (cur_est
> sel_est
* 1.5)
1585 else if (cur_est
> sel_est
* 1.2)
1587 else if (cur_est
> sel_est
* 1.1)
1589 else if (cur_est
> sel_est
)
1595 /* Make it easier to move to 5 GHz band */
1596 if (sel_est
> cur_est
* 1.5)
1598 else if (sel_est
> cur_est
* 1.2)
1600 else if (sel_est
> cur_est
* 1.1)
1603 if (min_diff
> reduce
)
1608 diff
= abs(current_bss
->level
- selected
->level
);
1609 if (diff
< min_diff
) {
1610 wpa_dbg(wpa_s
, MSG_DEBUG
,
1611 "Skip roam - too small difference in signal level (%d < %d)",
1616 wpa_dbg(wpa_s
, MSG_DEBUG
,
1617 "Allow reassociation due to difference in signal level (%d >= %d)",
1620 #else /* CONFIG_NO_ROAMING */
1622 #endif /* CONFIG_NO_ROAMING */
1627 * Return a negative value if no scan results could be fetched or if scan
1628 * results should not be shared with other virtual interfaces.
1629 * Return 0 if scan results were fetched and may be shared with other
1631 * Return 1 if scan results may be shared with other virtual interfaces but may
1632 * not trigger any operations.
1633 * Return 2 if the interface was removed and cannot be used.
1635 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1636 union wpa_event_data
*data
,
1637 int own_request
, int update_only
)
1639 struct wpa_scan_results
*scan_res
= NULL
;
1642 #ifndef CONFIG_NO_RANDOM_POOL
1644 #endif /* CONFIG_NO_RANDOM_POOL */
1647 if (wpa_s
->ap_iface
)
1649 #endif /* CONFIG_AP */
1651 wpa_supplicant_notify_scanning(wpa_s
, 0);
1653 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1654 data
? &data
->scan_info
:
1656 if (scan_res
== NULL
) {
1657 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1658 wpa_s
->scan_res_handler
== scan_only_handler
)
1662 if (data
&& data
->scan_info
.external_scan
)
1664 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1666 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1668 goto scan_work_done
;
1671 #ifndef CONFIG_NO_RANDOM_POOL
1672 num
= scan_res
->num
;
1675 for (i
= 0; i
< num
; i
++) {
1677 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1678 buf
[0] = res
->bssid
[5];
1679 buf
[1] = res
->qual
& 0xff;
1680 buf
[2] = res
->noise
& 0xff;
1681 buf
[3] = res
->level
& 0xff;
1682 buf
[4] = res
->tsf
& 0xff;
1683 random_add_randomness(buf
, sizeof(buf
));
1685 #endif /* CONFIG_NO_RANDOM_POOL */
1689 goto scan_work_done
;
1692 if (own_request
&& wpa_s
->scan_res_handler
&&
1693 !(data
&& data
->scan_info
.external_scan
)) {
1694 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1695 struct wpa_scan_results
*scan_res
);
1697 scan_res_handler
= wpa_s
->scan_res_handler
;
1698 wpa_s
->scan_res_handler
= NULL
;
1699 scan_res_handler(wpa_s
, scan_res
);
1701 goto scan_work_done
;
1705 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1707 if (wpa_s
->ap_iface
->scan_cb
)
1708 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1709 #endif /* CONFIG_AP */
1710 goto scan_work_done
;
1713 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1714 wpa_s
->own_scan_running
,
1715 data
? data
->scan_info
.external_scan
: 0);
1716 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1717 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1718 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1719 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1720 wpa_s
->manual_scan_id
);
1721 wpa_s
->manual_scan_use_id
= 0;
1723 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1725 wpas_notify_scan_results(wpa_s
);
1727 wpas_notify_scan_done(wpa_s
, 1);
1729 if (data
&& data
->scan_info
.external_scan
) {
1730 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1731 wpa_scan_results_free(scan_res
);
1735 if (wnm_scan_process(wpa_s
, 1) > 0)
1736 goto scan_work_done
;
1738 if (sme_proc_obss_scan(wpa_s
) > 0)
1739 goto scan_work_done
;
1742 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1743 goto scan_work_done
;
1745 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1746 goto scan_work_done
;
1748 if (autoscan_notify_scan(wpa_s
, scan_res
))
1749 goto scan_work_done
;
1751 if (wpa_s
->disconnected
) {
1752 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1753 goto scan_work_done
;
1756 if (!wpas_driver_bss_selection(wpa_s
) &&
1757 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1758 goto scan_work_done
;
1760 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1762 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1763 wpa_s
->wpa_state
< WPA_COMPLETED
)
1764 goto scan_work_done
;
1766 wpa_scan_results_free(scan_res
);
1768 if (own_request
&& wpa_s
->scan_work
) {
1769 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1770 wpa_s
->scan_work
= NULL
;
1771 radio_work_done(work
);
1774 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1777 wpa_scan_results_free(scan_res
);
1778 if (own_request
&& wpa_s
->scan_work
) {
1779 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1780 wpa_s
->scan_work
= NULL
;
1781 radio_work_done(work
);
1787 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1788 int new_scan
, int own_request
)
1790 struct wpa_bss
*selected
;
1791 struct wpa_ssid
*ssid
= NULL
;
1792 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1794 if (time_to_reenable
> 0) {
1795 wpa_dbg(wpa_s
, MSG_DEBUG
,
1796 "Postpone network selection by %d seconds since all networks are disabled",
1798 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1799 eloop_register_timeout(time_to_reenable
, 0,
1800 wpas_network_reenabled
, wpa_s
, NULL
);
1804 if (wpa_s
->p2p_mgmt
)
1805 return 0; /* no normal connection on p2p_mgmt interface */
1807 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1811 wpa_msg(wpa_s
, MSG_INFO
,
1812 "Avoiding join because we already joined a mesh group");
1815 #endif /* CONFIG_MESH */
1819 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1822 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1826 if (ssid
!= wpa_s
->current_ssid
&&
1827 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1828 wpa_s
->own_disconnect_req
= 1;
1829 wpa_supplicant_deauthenticate(
1830 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1833 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1834 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1838 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1840 * Do not allow other virtual radios to trigger operations based
1841 * on these scan results since we do not want them to start
1842 * other associations at the same time.
1846 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1847 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1849 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1850 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1852 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1853 } else if (own_request
) {
1855 * No SSID found. If SCAN results are as a result of
1856 * own scan request and not due to a scan request on
1857 * another shared interface, try another scan.
1859 int timeout_sec
= wpa_s
->scan_interval
;
1860 int timeout_usec
= 0;
1864 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1870 if (wpa_s
->p2p_in_provisioning
||
1871 wpa_s
->show_group_started
||
1872 wpa_s
->p2p_in_invitation
) {
1874 * Use shorter wait during P2P Provisioning
1875 * state and during P2P join-a-group operation
1876 * to speed up group formation.
1879 timeout_usec
= 250000;
1880 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1884 #endif /* CONFIG_P2P */
1885 #ifdef CONFIG_INTERWORKING
1886 if (wpa_s
->conf
->auto_interworking
&&
1887 wpa_s
->conf
->interworking
&&
1888 wpa_s
->conf
->cred
) {
1889 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1890 "start ANQP fetch since no matching "
1892 wpa_s
->network_select
= 1;
1893 wpa_s
->auto_network_select
= 1;
1894 interworking_start_fetch_anqp(wpa_s
);
1897 #endif /* CONFIG_INTERWORKING */
1899 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1900 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1902 timeout_usec
= 500000;
1903 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1907 #endif /* CONFIG_WPS */
1908 if (wpa_supplicant_req_sched_scan(wpa_s
))
1909 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1912 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1913 WPA_EVENT_NETWORK_NOT_FOUND
);
1920 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1921 union wpa_event_data
*data
)
1923 struct wpa_supplicant
*ifs
;
1926 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
1929 * Interface may have been removed, so must not dereference
1937 * If no scan results could be fetched, then no need to
1938 * notify those interfaces that did not actually request
1939 * this scan. Similarly, if scan results started a new operation on this
1940 * interface, do not notify other interfaces to avoid concurrent
1941 * operations during a connection attempt.
1947 * Check other interfaces to see if they share the same radio. If
1948 * so, they get updated with this same scan info.
1950 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1953 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1954 "sibling", ifs
->ifname
);
1955 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
1965 #endif /* CONFIG_NO_SCAN_PROCESSING */
1968 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1970 #ifdef CONFIG_NO_SCAN_PROCESSING
1972 #else /* CONFIG_NO_SCAN_PROCESSING */
1973 struct os_reltime now
;
1975 wpa_s
->ignore_post_flush_scan_res
= 0;
1977 if (wpa_s
->last_scan_res_used
== 0)
1980 os_get_reltime(&now
);
1981 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1982 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1986 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1987 #endif /* CONFIG_NO_SCAN_PROCESSING */
1992 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1994 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1996 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1999 if (!wpa_s
->no_keep_alive
) {
2000 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
2001 MAC2STR(wpa_s
->bssid
));
2002 /* TODO: could skip this if normal data traffic has been sent */
2003 /* TODO: Consider using some more appropriate data frame for
2006 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2011 if (wpa_s
->sme
.bss_max_idle_period
) {
2013 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2016 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2017 wnm_bss_keep_alive
, wpa_s
, NULL
);
2019 #endif /* CONFIG_SME */
2023 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2024 const u8
*ies
, size_t ies_len
)
2026 struct ieee802_11_elems elems
;
2031 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2035 if (elems
.bss_max_idle_period
) {
2037 wpa_s
->sme
.bss_max_idle_period
=
2038 WPA_GET_LE16(elems
.bss_max_idle_period
);
2039 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2040 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2041 (elems
.bss_max_idle_period
[2] & 0x01) ?
2042 " (protected keep-live required)" : "");
2043 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2044 wpa_s
->sme
.bss_max_idle_period
= 1;
2045 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2046 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2047 /* msec times 1000 */
2048 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2051 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2052 wnm_bss_keep_alive
, wpa_s
,
2056 #endif /* CONFIG_SME */
2059 #endif /* CONFIG_WNM */
2062 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2065 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2066 #endif /* CONFIG_WNM */
2070 #ifdef CONFIG_INTERWORKING
2072 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2077 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2078 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2080 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2087 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2088 const u8
*ies
, size_t ies_len
)
2090 struct ieee802_11_elems elems
;
2095 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2098 if (elems
.qos_map_set
) {
2099 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2100 elems
.qos_map_set_len
);
2104 #endif /* CONFIG_INTERWORKING */
2108 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2109 const u8
*ie
, size_t ie_len
)
2111 struct mb_ies_info mb_ies
;
2113 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2116 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2118 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2123 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2128 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2129 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2130 (unsigned int) len
);
2131 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2132 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2140 if (mb_ies
.nof_ies
> 0) {
2141 wpabuf_free(wpa_s
->received_mb_ies
);
2142 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2148 #endif /* CONFIG_FST */
2151 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2152 union wpa_event_data
*data
)
2154 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2156 #ifdef CONFIG_IEEE80211R
2158 #endif /* CONFIG_IEEE80211R */
2160 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2161 if (data
->assoc_info
.req_ies
)
2162 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2163 data
->assoc_info
.req_ies_len
);
2164 if (data
->assoc_info
.resp_ies
) {
2165 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2166 data
->assoc_info
.resp_ies_len
);
2168 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2169 data
->assoc_info
.resp_ies_len
);
2170 #endif /* CONFIG_TDLS */
2172 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2173 data
->assoc_info
.resp_ies_len
);
2174 #endif /* CONFIG_WNM */
2175 #ifdef CONFIG_INTERWORKING
2176 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2177 data
->assoc_info
.resp_ies_len
);
2178 #endif /* CONFIG_INTERWORKING */
2180 if (data
->assoc_info
.beacon_ies
)
2181 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2182 data
->assoc_info
.beacon_ies
,
2183 data
->assoc_info
.beacon_ies_len
);
2184 if (data
->assoc_info
.freq
)
2185 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2186 data
->assoc_info
.freq
);
2188 p
= data
->assoc_info
.req_ies
;
2189 l
= data
->assoc_info
.req_ies_len
;
2191 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2192 while (p
&& l
>= 2) {
2195 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2199 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2200 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2201 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2202 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2203 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2204 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2207 wpa_find_assoc_pmkid(wpa_s
);
2213 if (!found
&& data
->assoc_info
.req_ies
)
2214 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2218 if ((wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
2219 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
) &&
2220 (!data
->assoc_info
.resp_frame
||
2221 fils_process_assoc_resp(wpa_s
->wpa
,
2222 data
->assoc_info
.resp_frame
,
2223 data
->assoc_info
.resp_frame_len
) < 0)) {
2224 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2227 #endif /* CONFIG_SME */
2229 /* Additional processing for FILS when SME is in driver */
2230 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
&&
2231 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2232 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 1);
2233 #endif /* CONFIG_FILS */
2236 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
&&
2237 owe_process_assoc_resp(wpa_s
->wpa
,
2238 data
->assoc_info
.resp_ies
,
2239 data
->assoc_info
.resp_ies_len
) < 0) {
2240 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2243 #endif /* CONFIG_OWE */
2245 #ifdef CONFIG_IEEE80211R
2247 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2248 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2249 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2250 data
->assoc_info
.resp_ies
,
2251 data
->assoc_info
.resp_ies_len
,
2253 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2254 "Reassociation Response failed");
2255 wpa_supplicant_deauthenticate(
2256 wpa_s
, WLAN_REASON_INVALID_IE
);
2261 p
= data
->assoc_info
.resp_ies
;
2262 l
= data
->assoc_info
.resp_ies_len
;
2264 #ifdef CONFIG_WPS_STRICT
2265 if (p
&& wpa_s
->current_ssid
&&
2266 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2268 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2270 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2271 "include WPS IE in (Re)Association Response");
2275 if (wps_validate_assoc_resp(wps
) < 0) {
2277 wpa_supplicant_deauthenticate(
2278 wpa_s
, WLAN_REASON_INVALID_IE
);
2283 #endif /* CONFIG_WPS_STRICT */
2285 /* Go through the IEs and make a copy of the MDIE, if present. */
2286 while (p
&& l
>= 2) {
2289 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2293 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2294 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2295 wpa_s
->sme
.ft_used
= 1;
2296 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2297 MOBILITY_DOMAIN_ID_LEN
);
2303 #endif /* CONFIG_SME */
2305 /* Process FT when SME is in the driver */
2306 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2307 wpa_ft_is_completed(wpa_s
->wpa
)) {
2308 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2309 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2310 data
->assoc_info
.resp_ies
,
2311 data
->assoc_info
.resp_ies_len
,
2313 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2314 "Reassociation Response failed");
2315 wpa_supplicant_deauthenticate(
2316 wpa_s
, WLAN_REASON_INVALID_IE
);
2319 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2322 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2323 data
->assoc_info
.resp_ies_len
);
2324 #endif /* CONFIG_IEEE80211R */
2326 /* WPA/RSN IE from Beacon/ProbeResp */
2327 p
= data
->assoc_info
.beacon_ies
;
2328 l
= data
->assoc_info
.beacon_ies_len
;
2330 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2332 wpa_found
= rsn_found
= 0;
2333 while (p
&& l
>= 2) {
2336 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2341 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2342 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2344 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2348 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2350 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2357 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2358 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2359 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2360 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2361 if (wpa_found
|| rsn_found
)
2362 wpa_s
->ap_ies_from_associnfo
= 1;
2364 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2365 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2366 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2368 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2369 wpa_supplicant_update_scan_results(wpa_s
);
2372 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2378 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2380 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2382 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2385 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2388 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2389 WPA_IE_VENDOR_TYPE
);
2390 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2392 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2393 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2394 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2395 bss_rsn
? 2 + bss_rsn
[1] : 0))
2402 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2403 union wpa_event_data
*data
)
2406 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2407 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2408 const u8
*ieprb
, *iebcn
;
2410 wpabuf_free(wpa_s
->received_mb_ies
);
2411 wpa_s
->received_mb_ies
= NULL
;
2414 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2415 wpa_printf(MSG_DEBUG
,
2416 "FST: MB IEs updated from Association Response frame");
2421 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2422 wpa_printf(MSG_DEBUG
,
2423 "FST: MB IEs updated from association event Beacon IEs");
2430 ieprb
= (const u8
*) (bss
+ 1);
2431 iebcn
= ieprb
+ bss
->ie_len
;
2433 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2434 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2435 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2436 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2437 #endif /* CONFIG_FST */
2441 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2442 union wpa_event_data
*data
)
2445 int ft_completed
, already_authorized
;
2449 if (wpa_s
->ap_iface
) {
2452 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2453 data
->assoc_info
.addr
,
2454 data
->assoc_info
.req_ies
,
2455 data
->assoc_info
.req_ies_len
,
2456 data
->assoc_info
.reassoc
);
2459 #endif /* CONFIG_AP */
2461 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2463 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2464 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2467 * FILS authentication can share the same mechanism to mark the
2468 * connection fully authenticated, so set ft_completed also based on
2472 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2474 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2475 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2476 wpa_supplicant_deauthenticate(
2477 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2481 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2482 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2483 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2484 MACSTR
, MAC2STR(bssid
));
2486 random_add_randomness(bssid
, ETH_ALEN
);
2487 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2488 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2489 wpas_notify_bssid_changed(wpa_s
);
2491 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2492 wpa_clear_keys(wpa_s
, bssid
);
2494 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2495 wpa_supplicant_deauthenticate(
2496 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2501 if (wpa_s
->conf
->ap_scan
== 1 &&
2502 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2503 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2504 wpa_msg(wpa_s
, MSG_WARNING
,
2505 "WPA/RSN IEs not updated");
2508 wpas_fst_update_mb_assoc(wpa_s
, data
);
2511 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2512 wpa_s
->sme
.prev_bssid_set
= 1;
2513 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2514 #endif /* CONFIG_SME */
2516 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2517 if (wpa_s
->current_ssid
) {
2518 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2519 * initialized before association, but for other modes,
2520 * initialize PC/SC here, if the current configuration needs
2521 * smartcard or SIM/USIM. */
2522 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2524 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2526 l2_packet_notify_auth_start(wpa_s
->l2
);
2528 already_authorized
= data
&& data
->assoc_info
.authorized
;
2531 * Set portEnabled first to FALSE in order to get EAP state machine out
2532 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2533 * state machine may transit to AUTHENTICATING state based on obsolete
2534 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2535 * AUTHENTICATED without ever giving chance to EAP state machine to
2538 if (!ft_completed
&& !already_authorized
) {
2539 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2540 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2542 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2543 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
|| ft_completed
||
2545 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2546 /* 802.1X::portControl = Auto */
2547 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2548 wpa_s
->eapol_received
= 0;
2549 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2550 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2551 (wpa_s
->current_ssid
&&
2552 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2553 if (wpa_s
->current_ssid
&&
2554 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2556 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2558 * Set the key after having received joined-IBSS event
2561 wpa_supplicant_set_wpa_none_key(wpa_s
,
2562 wpa_s
->current_ssid
);
2564 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2565 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2566 } else if (!ft_completed
) {
2567 /* Timeout for receiving the first EAPOL packet */
2568 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2570 wpa_supplicant_cancel_scan(wpa_s
);
2572 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2573 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2575 * We are done; the driver will take care of RSN 4-way
2578 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2579 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2580 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2581 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2582 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2583 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2585 * The driver will take care of RSN 4-way handshake, so we need
2586 * to allow EAPOL supplicant to complete its work without
2587 * waiting for WPA supplicant.
2589 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2590 } else if (ft_completed
) {
2592 * FT protocol completed - make sure EAPOL state machine ends
2593 * up in authenticated.
2595 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2596 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2597 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2598 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2601 wpa_s
->last_eapol_matches_bssid
= 0;
2603 if (wpa_s
->pending_eapol_rx
) {
2604 struct os_reltime now
, age
;
2605 os_get_reltime(&now
);
2606 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2607 if (age
.sec
== 0 && age
.usec
< 200000 &&
2608 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2610 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2611 "frame that was received just before "
2612 "association notification");
2613 wpa_supplicant_rx_eapol(
2614 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2615 wpabuf_head(wpa_s
->pending_eapol_rx
),
2616 wpabuf_len(wpa_s
->pending_eapol_rx
));
2618 wpabuf_free(wpa_s
->pending_eapol_rx
);
2619 wpa_s
->pending_eapol_rx
= NULL
;
2622 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2623 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2624 wpa_s
->current_ssid
&&
2625 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2626 /* Set static WEP keys again */
2627 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2630 #ifdef CONFIG_IBSS_RSN
2631 if (wpa_s
->current_ssid
&&
2632 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2633 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2634 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2635 wpa_s
->ibss_rsn
== NULL
) {
2636 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2637 if (!wpa_s
->ibss_rsn
) {
2638 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2639 wpa_supplicant_deauthenticate(
2640 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2644 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2646 #endif /* CONFIG_IBSS_RSN */
2648 wpas_wps_notify_assoc(wpa_s
, bssid
);
2651 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2652 data
->assoc_info
.resp_ies_len
,
2653 &data
->assoc_info
.wmm_params
);
2655 if (wpa_s
->reassoc_same_bss
)
2656 wmm_ac_restore_tspecs(wpa_s
);
2660 if (wpa_key_mgmt_fils(wpa_s
->key_mgmt
)) {
2661 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2662 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
2665 wpa_sm_set_fils_cache_id(wpa_s
->wpa
, fils_cache_id
);
2667 #endif /* CONFIG_FILS */
2671 static int disconnect_reason_recoverable(u16 reason_code
)
2673 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2674 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2675 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2679 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2681 int locally_generated
)
2685 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2687 * At least Host AP driver and a Prism3 card seemed to be
2688 * generating streams of disconnected events when configuring
2689 * IBSS for WPA-None. Ignore them for now.
2694 bssid
= wpa_s
->bssid
;
2695 if (is_zero_ether_addr(bssid
))
2696 bssid
= wpa_s
->pending_bssid
;
2698 if (!is_zero_ether_addr(bssid
) ||
2699 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2700 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2702 MAC2STR(bssid
), reason_code
,
2703 locally_generated
? " locally_generated=1" : "");
2708 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2709 int locally_generated
)
2711 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2712 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2713 return 0; /* Not in 4-way handshake with PSK */
2716 * It looks like connection was lost while trying to go through PSK
2717 * 4-way handshake. Filter out known disconnection cases that are caused
2718 * by something else than PSK mismatch to avoid confusing reports.
2721 if (locally_generated
) {
2722 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2730 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2732 int locally_generated
)
2736 u8 prev_pending_bssid
[ETH_ALEN
];
2737 struct wpa_bss
*fast_reconnect
= NULL
;
2738 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2739 struct wpa_ssid
*last_ssid
;
2740 struct wpa_bss
*curr
= NULL
;
2742 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2743 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2745 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2747 * At least Host AP driver and a Prism3 card seemed to be
2748 * generating streams of disconnected events when configuring
2749 * IBSS for WPA-None. Ignore them for now.
2751 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2752 "IBSS/WPA-None mode");
2756 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2757 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2760 * Remove the inactive AP (which is probably out of range) from
2761 * the BSS list after marking disassociation. In particular
2762 * mac80211-based drivers use the
2763 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2764 * locally generated disconnection events for cases where the
2765 * AP does not reply anymore.
2767 curr
= wpa_s
->current_bss
;
2769 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2770 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2771 "pre-shared key may be incorrect");
2772 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2773 return; /* P2P group removed */
2774 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2776 if (!wpa_s
->disconnected
&&
2777 (!wpa_s
->auto_reconnect_disabled
||
2778 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2779 wpas_wps_searching(wpa_s
) ||
2780 wpas_wps_reenable_networks_pending(wpa_s
))) {
2781 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2782 "reconnect (wps=%d/%d wpa_state=%d)",
2783 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2784 wpas_wps_searching(wpa_s
),
2786 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2787 wpa_s
->current_ssid
&&
2788 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2789 !locally_generated
&&
2790 disconnect_reason_recoverable(reason_code
)) {
2792 * It looks like the AP has dropped association with
2793 * us, but could allow us to get back in. Try to
2794 * reconnect to the same BSS without full scan to save
2795 * time for some common cases.
2797 fast_reconnect
= wpa_s
->current_bss
;
2798 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2799 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2800 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2802 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2805 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2806 "try to re-connect");
2807 wpa_s
->reassociate
= 0;
2808 wpa_s
->disconnected
= 1;
2810 wpa_supplicant_cancel_sched_scan(wpa_s
);
2812 bssid
= wpa_s
->bssid
;
2813 if (is_zero_ether_addr(bssid
))
2814 bssid
= wpa_s
->pending_bssid
;
2815 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2816 wpas_connection_failed(wpa_s
, bssid
);
2817 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2818 if (locally_generated
)
2819 wpa_s
->disconnect_reason
= -reason_code
;
2821 wpa_s
->disconnect_reason
= reason_code
;
2822 wpas_notify_disconnect_reason(wpa_s
);
2823 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2824 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2825 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2827 last_ssid
= wpa_s
->current_ssid
;
2828 wpa_supplicant_mark_disassoc(wpa_s
);
2831 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2833 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2834 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2835 wpa_s
->current_ssid
= last_ssid
;
2838 if (fast_reconnect
&&
2839 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2840 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2841 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2842 fast_reconnect
->ssid_len
) &&
2843 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2844 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2845 #ifndef CONFIG_NO_SCAN_PROCESSING
2846 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2847 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2848 fast_reconnect_ssid
) < 0) {
2849 /* Recover through full scan */
2850 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2852 #endif /* CONFIG_NO_SCAN_PROCESSING */
2853 } else if (fast_reconnect
) {
2855 * Could not reconnect to the same BSS due to network being
2856 * disabled. Use a new scan to match the alternative behavior
2857 * above, i.e., to continue automatic reconnection attempt in a
2858 * way that enforces disabled network rules.
2860 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2865 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2866 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2868 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2870 if (!wpa_s
->pending_mic_error_report
)
2873 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2874 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2875 wpa_s
->pending_mic_error_report
= 0;
2877 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2881 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2882 union wpa_event_data
*data
)
2885 struct os_reltime t
;
2887 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2888 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2890 if ((wpa_s
->last_michael_mic_error
.sec
&&
2891 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2892 wpa_s
->pending_mic_error_report
) {
2893 if (wpa_s
->pending_mic_error_report
) {
2895 * Send the pending MIC error report immediately since
2896 * we are going to start countermeasures and AP better
2899 wpa_sm_key_request(wpa_s
->wpa
, 1,
2900 wpa_s
->pending_mic_error_pairwise
);
2903 /* Send the new MIC error report immediately since we are going
2904 * to start countermeasures and AP better do the same.
2906 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2908 /* initialize countermeasures */
2909 wpa_s
->countermeasures
= 1;
2911 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2913 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2916 * Need to wait for completion of request frame. We do not get
2917 * any callback for the message completion, so just wait a
2918 * short while and hope for the best. */
2921 wpa_drv_set_countermeasures(wpa_s
, 1);
2922 wpa_supplicant_deauthenticate(wpa_s
,
2923 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2924 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2926 eloop_register_timeout(60, 0,
2927 wpa_supplicant_stop_countermeasures
,
2929 /* TODO: mark the AP rejected for 60 second. STA is
2930 * allowed to associate with another AP.. */
2932 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2933 if (wpa_s
->mic_errors_seen
) {
2935 * Reduce the effectiveness of Michael MIC error
2936 * reports as a means for attacking against TKIP if
2937 * more than one MIC failure is noticed with the same
2938 * PTK. We delay the transmission of the reports by a
2939 * random time between 0 and 60 seconds in order to
2940 * force the attacker wait 60 seconds before getting
2941 * the information on whether a frame resulted in a MIC
2947 if (os_get_random(rval
, sizeof(rval
)) < 0)
2948 sec
= os_random() % 60;
2950 sec
= WPA_GET_BE32(rval
) % 60;
2951 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2952 "report %d seconds", sec
);
2953 wpa_s
->pending_mic_error_report
= 1;
2954 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2955 eloop_cancel_timeout(
2956 wpa_supplicant_delayed_mic_error_report
,
2958 eloop_register_timeout(
2959 sec
, os_random() % 1000000,
2960 wpa_supplicant_delayed_mic_error_report
,
2963 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2965 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2966 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2967 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2969 wpa_s
->last_michael_mic_error
= t
;
2970 wpa_s
->mic_errors_seen
++;
2974 #ifdef CONFIG_TERMINATE_ONLASTIF
2975 static int any_interfaces(struct wpa_supplicant
*head
)
2977 struct wpa_supplicant
*wpa_s
;
2979 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2980 if (!wpa_s
->interface_removed
)
2984 #endif /* CONFIG_TERMINATE_ONLASTIF */
2988 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2989 union wpa_event_data
*data
)
2991 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2994 switch (data
->interface_status
.ievent
) {
2995 case EVENT_INTERFACE_ADDED
:
2996 if (!wpa_s
->interface_removed
)
2998 wpa_s
->interface_removed
= 0;
2999 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
3000 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
3001 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
3002 "driver after interface was added");
3006 if (!wpa_s
->global
->p2p
&&
3007 !wpa_s
->global
->p2p_disabled
&&
3008 !wpa_s
->conf
->p2p_disabled
&&
3010 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3011 wpas_p2p_add_p2pdev_interface(
3012 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
3013 wpa_printf(MSG_INFO
,
3014 "P2P: Failed to enable P2P Device interface");
3015 /* Try to continue without. P2P will be disabled. */
3017 #endif /* CONFIG_P2P */
3020 case EVENT_INTERFACE_REMOVED
:
3021 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
3022 wpa_s
->interface_removed
= 1;
3023 wpa_supplicant_mark_disassoc(wpa_s
);
3024 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3025 l2_packet_deinit(wpa_s
->l2
);
3029 if (wpa_s
->global
->p2p
&&
3030 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3032 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3033 wpa_dbg(wpa_s
, MSG_DEBUG
,
3034 "Removing P2P Device interface");
3035 wpa_supplicant_remove_iface(
3036 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3038 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3040 #endif /* CONFIG_P2P */
3042 #ifdef CONFIG_MATCH_IFACE
3043 if (wpa_s
->matched
) {
3044 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3047 #endif /* CONFIG_MATCH_IFACE */
3049 #ifdef CONFIG_TERMINATE_ONLASTIF
3050 /* check if last interface */
3051 if (!any_interfaces(wpa_s
->global
->ifaces
))
3053 #endif /* CONFIG_TERMINATE_ONLASTIF */
3059 #ifdef CONFIG_PEERKEY
3061 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
3062 union wpa_event_data
*data
)
3066 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
3068 #endif /* CONFIG_PEERKEY */
3072 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3073 union wpa_event_data
*data
)
3077 switch (data
->tdls
.oper
) {
3078 case TDLS_REQUEST_SETUP
:
3079 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3080 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3081 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3083 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3085 case TDLS_REQUEST_TEARDOWN
:
3086 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3087 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3088 data
->tdls
.reason_code
);
3090 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3093 case TDLS_REQUEST_DISCOVER
:
3094 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3099 #endif /* CONFIG_TDLS */
3103 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3104 union wpa_event_data
*data
)
3108 switch (data
->wnm
.oper
) {
3109 case WNM_OPER_SLEEP
:
3110 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3111 "(action=%d, intval=%d)",
3112 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3113 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3114 data
->wnm
.sleep_intval
, NULL
);
3118 #endif /* CONFIG_WNM */
3121 #ifdef CONFIG_IEEE80211R
3123 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3124 union wpa_event_data
*data
)
3129 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3130 data
->ft_ies
.ies_len
,
3131 data
->ft_ies
.ft_action
,
3132 data
->ft_ies
.target_ap
,
3133 data
->ft_ies
.ric_ies
,
3134 data
->ft_ies
.ric_ies_len
) < 0) {
3135 /* TODO: prevent MLME/driver from trying to associate? */
3138 #endif /* CONFIG_IEEE80211R */
3141 #ifdef CONFIG_IBSS_RSN
3142 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3143 union wpa_event_data
*data
)
3145 struct wpa_ssid
*ssid
;
3146 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3150 ssid
= wpa_s
->current_ssid
;
3153 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3156 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3160 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3161 union wpa_event_data
*data
)
3163 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3168 /* check if the ssid is correctly configured as IBSS/RSN */
3169 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3172 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3173 data
->rx_mgmt
.frame_len
);
3175 #endif /* CONFIG_IBSS_RSN */
3178 #ifdef CONFIG_IEEE80211R
3179 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3182 const u8
*sta_addr
, *target_ap_addr
;
3185 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3186 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3187 return; /* only SME case supported for now */
3188 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3191 return; /* Only FT Action Response is supported for now */
3192 sta_addr
= data
+ 1;
3193 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3194 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3195 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3196 MACSTR
" TargetAP " MACSTR
" status %u",
3197 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3199 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3200 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3201 " in FT Action Response", MAC2STR(sta_addr
));
3206 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3207 "failure (status code %d)", status
);
3208 /* TODO: report error to FT code(?) */
3212 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3213 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3214 target_ap_addr
, NULL
, 0) < 0)
3219 struct wpa_bss
*bss
;
3220 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3222 wpa_s
->sme
.freq
= bss
->freq
;
3223 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3224 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3227 #endif /* CONFIG_SME */
3229 #endif /* CONFIG_IEEE80211R */
3232 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3233 struct unprot_deauth
*e
)
3235 #ifdef CONFIG_IEEE80211W
3236 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3237 "dropped: " MACSTR
" -> " MACSTR
3238 " (reason code %u)",
3239 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3240 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3241 #endif /* CONFIG_IEEE80211W */
3245 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3246 struct unprot_disassoc
*e
)
3248 #ifdef CONFIG_IEEE80211W
3249 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3250 "dropped: " MACSTR
" -> " MACSTR
3251 " (reason code %u)",
3252 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3253 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3254 #endif /* CONFIG_IEEE80211W */
3258 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3259 u16 reason_code
, int locally_generated
,
3260 const u8
*ie
, size_t ie_len
, int deauth
)
3263 if (wpa_s
->ap_iface
&& addr
) {
3264 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3268 if (wpa_s
->ap_iface
) {
3269 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3272 #endif /* CONFIG_AP */
3274 if (!locally_generated
)
3275 wpa_s
->own_disconnect_req
= 0;
3277 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3279 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3280 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3281 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3282 eapol_sm_failed(wpa_s
->eapol
))) &&
3283 !wpa_s
->eap_expected_failure
))
3284 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3287 if (deauth
&& reason_code
> 0) {
3288 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3289 locally_generated
) > 0) {
3291 * The interface was removed, so cannot continue
3292 * processing any additional operations after this.
3297 #endif /* CONFIG_P2P */
3299 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3304 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3305 struct disassoc_info
*info
)
3307 u16 reason_code
= 0;
3308 int locally_generated
= 0;
3309 const u8
*addr
= NULL
;
3310 const u8
*ie
= NULL
;
3313 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3318 ie_len
= info
->ie_len
;
3319 reason_code
= info
->reason_code
;
3320 locally_generated
= info
->locally_generated
;
3321 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3322 locally_generated
? " (locally generated)" : "");
3324 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3326 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3331 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3332 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3336 if (wpa_s
->ap_iface
) {
3337 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3340 #endif /* CONFIG_AP */
3344 wpas_p2p_disassoc_notif(
3345 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3348 #endif /* CONFIG_P2P */
3350 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3351 sme_event_disassoc(wpa_s
, info
);
3353 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3358 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3359 struct deauth_info
*info
)
3361 u16 reason_code
= 0;
3362 int locally_generated
= 0;
3363 const u8
*addr
= NULL
;
3364 const u8
*ie
= NULL
;
3367 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3372 ie_len
= info
->ie_len
;
3373 reason_code
= info
->reason_code
;
3374 locally_generated
= info
->locally_generated
;
3375 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3377 locally_generated
? " (locally generated)" : "");
3379 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3382 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3386 wpa_reset_ft_completed(wpa_s
->wpa
);
3388 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3389 locally_generated
, ie
, ie_len
, 1);
3393 static const char * reg_init_str(enum reg_change_initiator init
)
3396 case REGDOM_SET_BY_CORE
:
3398 case REGDOM_SET_BY_USER
:
3400 case REGDOM_SET_BY_DRIVER
:
3402 case REGDOM_SET_BY_COUNTRY_IE
:
3403 return "COUNTRY_IE";
3404 case REGDOM_BEACON_HINT
:
3405 return "BEACON_HINT";
3411 static const char * reg_type_str(enum reg_type type
)
3414 case REGDOM_TYPE_UNKNOWN
:
3416 case REGDOM_TYPE_COUNTRY
:
3418 case REGDOM_TYPE_WORLD
:
3420 case REGDOM_TYPE_CUSTOM_WORLD
:
3421 return "CUSTOM_WORLD";
3422 case REGDOM_TYPE_INTERSECTION
:
3423 return "INTERSECTION";
3429 static void wpa_supplicant_update_channel_list(
3430 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3432 struct wpa_supplicant
*ifs
;
3436 * To allow backwards compatibility with higher level layers that
3437 * assumed the REGDOM_CHANGE event is sent over the initially added
3438 * interface. Find the highest parent of this interface and use it to
3441 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3444 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3445 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3446 info
->alpha2
[0] ? " alpha2=" : "",
3447 info
->alpha2
[0] ? info
->alpha2
: "");
3449 if (wpa_s
->drv_priv
== NULL
)
3450 return; /* Ignore event during drv initialization */
3452 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3454 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3456 free_hw_features(ifs
);
3457 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3458 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
, &dfs_domain
);
3460 /* Restart PNO/sched_scan with updated channel list */
3463 wpas_start_pno(ifs
);
3464 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3465 wpa_dbg(ifs
, MSG_DEBUG
,
3466 "Channel list changed - restart sched_scan");
3467 wpas_scan_restart_sched_scan(ifs
);
3471 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3475 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3476 const u8
*frame
, size_t len
, int freq
,
3479 const struct ieee80211_mgmt
*mgmt
;
3484 if (len
< IEEE80211_HDRLEN
+ 2)
3487 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3488 payload
= frame
+ IEEE80211_HDRLEN
;
3489 category
= *payload
++;
3490 plen
= len
- IEEE80211_HDRLEN
- 1;
3492 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3493 " Category=%u DataLen=%d freq=%d MHz",
3494 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3496 if (category
== WLAN_ACTION_WMM
) {
3497 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3501 #ifdef CONFIG_IEEE80211R
3502 if (category
== WLAN_ACTION_FT
) {
3503 ft_rx_action(wpa_s
, payload
, plen
);
3506 #endif /* CONFIG_IEEE80211R */
3508 #ifdef CONFIG_IEEE80211W
3510 if (category
== WLAN_ACTION_SA_QUERY
) {
3511 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3514 #endif /* CONFIG_SME */
3515 #endif /* CONFIG_IEEE80211W */
3518 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3519 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3522 #endif /* CONFIG_WNM */
3525 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3526 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3527 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3528 mgmt
->u
.action
.category
,
3529 payload
, plen
, freq
) == 0)
3531 #endif /* CONFIG_GAS */
3534 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3535 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3536 wpa_dbg(wpa_s
, MSG_DEBUG
,
3537 "TDLS: Received Discovery Response from " MACSTR
,
3541 #endif /* CONFIG_TDLS */
3543 #ifdef CONFIG_INTERWORKING
3544 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3545 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3546 const u8
*pos
= payload
+ 1;
3547 size_t qlen
= plen
- 1;
3548 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3549 MACSTR
, MAC2STR(mgmt
->sa
));
3550 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3551 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3552 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3553 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3556 #endif /* CONFIG_INTERWORKING */
3558 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3559 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3560 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3566 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3567 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3568 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3572 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3573 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3574 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3575 payload
+ 1, plen
- 1,
3581 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3582 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3585 #endif /* CONFIG_FST */
3588 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 5 &&
3589 payload
[0] == WLAN_PA_VENDOR_SPECIFIC
&&
3590 WPA_GET_BE24(&payload
[1]) == OUI_WFA
&&
3591 payload
[4] == DPP_OUI_TYPE
) {
3594 wpas_dpp_rx_action(wpa_s
, mgmt
->sa
, payload
, plen
, freq
);
3597 #endif /* CONFIG_DPP */
3599 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3600 category
, payload
, plen
, freq
);
3602 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3606 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3607 union wpa_event_data
*event
)
3609 struct wpa_freq_range_list
*list
;
3612 list
= &event
->freq_range
;
3615 str
= freq_range_list_str(list
);
3616 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3620 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3621 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3624 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3627 * The update channel flow will also take care of moving a GO
3628 * from the unsafe frequency if needed.
3630 wpas_p2p_update_channel_list(wpa_s
,
3631 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3633 #endif /* CONFIG_P2P */
3639 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3640 union wpa_event_data
*data
)
3642 wpa_dbg(wpa_s
, MSG_DEBUG
,
3643 "Connection authorized by device, previous state %d",
3645 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3646 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3647 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3648 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3649 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3651 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3652 data
->assoc_info
.ptk_kck_len
,
3653 data
->assoc_info
.ptk_kek
,
3654 data
->assoc_info
.ptk_kek_len
);
3656 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
) {
3657 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
3658 const u8
*fils_cache_id
= wpa_bss_get_fils_cache_id(bss
);
3660 /* Update ERP next sequence number */
3661 eapol_sm_update_erp_next_seq_num(
3662 wpa_s
->eapol
, data
->assoc_info
.fils_erp_next_seq_num
);
3664 if (data
->assoc_info
.fils_pmk
&& data
->assoc_info
.fils_pmkid
) {
3665 /* Add the new PMK and PMKID to the PMKSA cache */
3666 wpa_sm_pmksa_cache_add(wpa_s
->wpa
,
3667 data
->assoc_info
.fils_pmk
,
3668 data
->assoc_info
.fils_pmk_len
,
3669 data
->assoc_info
.fils_pmkid
,
3670 wpa_s
->bssid
, fils_cache_id
);
3671 } else if (data
->assoc_info
.fils_pmkid
) {
3672 /* Update the current PMKSA used for this connection */
3673 pmksa_cache_set_current(wpa_s
->wpa
,
3674 data
->assoc_info
.fils_pmkid
,
3675 NULL
, NULL
, 0, NULL
);
3678 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
,
3679 data
->assoc_info
.key_replay_ctr
);
3681 #else /* CONFIG_FILS */
3682 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3683 #endif /* CONFIG_FILS */
3687 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3688 union wpa_event_data
*data
)
3690 struct wpa_supplicant
*wpa_s
= ctx
;
3693 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3694 event
!= EVENT_INTERFACE_ENABLED
&&
3695 event
!= EVENT_INTERFACE_STATUS
&&
3696 event
!= EVENT_SCAN_RESULTS
&&
3697 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3698 wpa_dbg(wpa_s
, MSG_DEBUG
,
3699 "Ignore event %s (%d) while interface is disabled",
3700 event_to_string(event
), event
);
3704 #ifndef CONFIG_NO_STDOUT_DEBUG
3706 int level
= MSG_DEBUG
;
3708 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3709 const struct ieee80211_hdr
*hdr
;
3711 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3712 fc
= le_to_host16(hdr
->frame_control
);
3713 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3714 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3715 level
= MSG_EXCESSIVE
;
3718 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3719 event_to_string(event
), event
);
3721 #endif /* CONFIG_NO_STDOUT_DEBUG */
3726 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3727 data
->auth
.ies_len
))
3728 wpa_printf(MSG_DEBUG
,
3729 "FST: MB IEs updated from auth IE");
3730 #endif /* CONFIG_FST */
3731 sme_event_auth(wpa_s
, data
);
3734 #ifdef CONFIG_TESTING_OPTIONS
3735 if (wpa_s
->ignore_auth_resp
) {
3736 wpa_printf(MSG_INFO
,
3737 "EVENT_ASSOC - ignore_auth_resp active!");
3740 #endif /* CONFIG_TESTING_OPTIONS */
3741 wpa_supplicant_event_assoc(wpa_s
, data
);
3742 if ((data
&& data
->assoc_info
.authorized
) ||
3743 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
3744 wpa_fils_is_completed(wpa_s
->wpa
)))
3745 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3747 wpa_msg(wpa_s
, MSG_INFO
,
3748 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3749 data
->assoc_info
.subnet_status
);
3752 case EVENT_DISASSOC
:
3753 wpas_event_disassoc(wpa_s
,
3754 data
? &data
->disassoc_info
: NULL
);
3757 #ifdef CONFIG_TESTING_OPTIONS
3758 if (wpa_s
->ignore_auth_resp
) {
3759 wpa_printf(MSG_INFO
,
3760 "EVENT_DEAUTH - ignore_auth_resp active!");
3763 #endif /* CONFIG_TESTING_OPTIONS */
3764 wpas_event_deauth(wpa_s
,
3765 data
? &data
->deauth_info
: NULL
);
3767 case EVENT_MICHAEL_MIC_FAILURE
:
3768 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3770 #ifndef CONFIG_NO_SCAN_PROCESSING
3771 case EVENT_SCAN_STARTED
:
3772 if (wpa_s
->own_scan_requested
||
3773 (data
&& !data
->scan_info
.external_scan
)) {
3774 struct os_reltime diff
;
3776 os_get_reltime(&wpa_s
->scan_start_time
);
3777 os_reltime_sub(&wpa_s
->scan_start_time
,
3778 &wpa_s
->scan_trigger_time
, &diff
);
3779 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3780 diff
.sec
, diff
.usec
);
3781 wpa_s
->own_scan_requested
= 0;
3782 wpa_s
->own_scan_running
= 1;
3783 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3784 wpa_s
->manual_scan_use_id
) {
3785 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3786 WPA_EVENT_SCAN_STARTED
"id=%u",
3787 wpa_s
->manual_scan_id
);
3789 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3790 WPA_EVENT_SCAN_STARTED
);
3793 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3794 wpa_s
->radio
->external_scan_running
= 1;
3795 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3798 case EVENT_SCAN_RESULTS
:
3799 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3800 wpa_s
->scan_res_handler
= NULL
;
3801 wpa_s
->own_scan_running
= 0;
3802 wpa_s
->radio
->external_scan_running
= 0;
3803 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3807 if (!(data
&& data
->scan_info
.external_scan
) &&
3808 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3809 struct os_reltime now
, diff
;
3810 os_get_reltime(&now
);
3811 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3812 wpa_s
->scan_start_time
.sec
= 0;
3813 wpa_s
->scan_start_time
.usec
= 0;
3814 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3815 diff
.sec
, diff
.usec
);
3817 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3818 break; /* interface may have been removed */
3819 if (!(data
&& data
->scan_info
.external_scan
))
3820 wpa_s
->own_scan_running
= 0;
3821 if (data
&& data
->scan_info
.nl_scan_event
)
3822 wpa_s
->radio
->external_scan_running
= 0;
3823 radio_work_check_next(wpa_s
);
3825 #endif /* CONFIG_NO_SCAN_PROCESSING */
3826 case EVENT_ASSOCINFO
:
3827 wpa_supplicant_event_associnfo(wpa_s
, data
);
3829 case EVENT_INTERFACE_STATUS
:
3830 wpa_supplicant_event_interface_status(wpa_s
, data
);
3832 case EVENT_PMKID_CANDIDATE
:
3833 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3835 #ifdef CONFIG_PEERKEY
3836 case EVENT_STKSTART
:
3837 wpa_supplicant_event_stkstart(wpa_s
, data
);
3839 #endif /* CONFIG_PEERKEY */
3842 wpa_supplicant_event_tdls(wpa_s
, data
);
3844 #endif /* CONFIG_TDLS */
3847 wpa_supplicant_event_wnm(wpa_s
, data
);
3849 #endif /* CONFIG_WNM */
3850 #ifdef CONFIG_IEEE80211R
3851 case EVENT_FT_RESPONSE
:
3852 wpa_supplicant_event_ft_response(wpa_s
, data
);
3854 #endif /* CONFIG_IEEE80211R */
3855 #ifdef CONFIG_IBSS_RSN
3856 case EVENT_IBSS_RSN_START
:
3857 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3859 #endif /* CONFIG_IBSS_RSN */
3860 case EVENT_ASSOC_REJECT
:
3861 if (data
->assoc_reject
.bssid
)
3862 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3863 "bssid=" MACSTR
" status_code=%u%s%s%s",
3864 MAC2STR(data
->assoc_reject
.bssid
),
3865 data
->assoc_reject
.status_code
,
3866 data
->assoc_reject
.timed_out
? " timeout" : "",
3867 data
->assoc_reject
.timeout_reason
? "=" : "",
3868 data
->assoc_reject
.timeout_reason
?
3869 data
->assoc_reject
.timeout_reason
: "");
3871 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3872 "status_code=%u%s%s%s",
3873 data
->assoc_reject
.status_code
,
3874 data
->assoc_reject
.timed_out
? " timeout" : "",
3875 data
->assoc_reject
.timeout_reason
? "=" : "",
3876 data
->assoc_reject
.timeout_reason
?
3877 data
->assoc_reject
.timeout_reason
: "");
3878 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3879 wpas_notify_assoc_status_code(wpa_s
);
3880 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3881 sme_event_assoc_reject(wpa_s
, data
);
3883 const u8
*bssid
= data
->assoc_reject
.bssid
;
3886 /* Update ERP next sequence number */
3887 if (wpa_s
->auth_alg
== WPA_AUTH_ALG_FILS
)
3888 eapol_sm_update_erp_next_seq_num(
3890 data
->assoc_reject
.fils_erp_next_seq_num
);
3891 #endif /* CONFIG_FILS */
3893 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
3894 bssid
= wpa_s
->pending_bssid
;
3895 wpas_connection_failed(wpa_s
, bssid
);
3896 wpa_supplicant_mark_disassoc(wpa_s
);
3899 case EVENT_AUTH_TIMED_OUT
:
3900 /* It is possible to get this event from earlier connection */
3901 if (wpa_s
->current_ssid
&&
3902 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3903 wpa_dbg(wpa_s
, MSG_DEBUG
,
3904 "Ignore AUTH_TIMED_OUT in mesh configuration");
3907 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3908 sme_event_auth_timed_out(wpa_s
, data
);
3910 case EVENT_ASSOC_TIMED_OUT
:
3911 /* It is possible to get this event from earlier connection */
3912 if (wpa_s
->current_ssid
&&
3913 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3914 wpa_dbg(wpa_s
, MSG_DEBUG
,
3915 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3918 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3919 sme_event_assoc_timed_out(wpa_s
, data
);
3921 case EVENT_TX_STATUS
:
3922 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3923 " type=%d stype=%d",
3924 MAC2STR(data
->tx_status
.dst
),
3925 data
->tx_status
.type
, data
->tx_status
.stype
);
3927 if (wpa_s
->ap_iface
== NULL
) {
3928 #ifdef CONFIG_OFFCHANNEL
3929 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3930 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3931 offchannel_send_action_tx_status(
3932 wpa_s
, data
->tx_status
.dst
,
3933 data
->tx_status
.data
,
3934 data
->tx_status
.data_len
,
3935 data
->tx_status
.ack
?
3936 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3937 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3938 #endif /* CONFIG_OFFCHANNEL */
3941 #endif /* CONFIG_AP */
3942 #ifdef CONFIG_OFFCHANNEL
3943 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3944 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
3946 * Catch TX status events for Action frames we sent via group
3947 * interface in GO mode, or via standalone AP interface.
3948 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3949 * except when the primary interface is used as a GO interface
3950 * (for drivers which do not have group interface concurrency)
3952 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3953 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3954 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
3955 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3956 offchannel_send_action_tx_status(
3957 wpa_s
->p2pdev
, data
->tx_status
.dst
,
3958 data
->tx_status
.data
,
3959 data
->tx_status
.data_len
,
3960 data
->tx_status
.ack
?
3961 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3962 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3965 #endif /* CONFIG_OFFCHANNEL */
3967 switch (data
->tx_status
.type
) {
3968 case WLAN_FC_TYPE_MGMT
:
3969 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3970 data
->tx_status
.data_len
,
3971 data
->tx_status
.stype
,
3972 data
->tx_status
.ack
);
3974 case WLAN_FC_TYPE_DATA
:
3975 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3976 data
->tx_status
.data
,
3977 data
->tx_status
.data_len
,
3978 data
->tx_status
.ack
);
3981 #endif /* CONFIG_AP */
3984 case EVENT_EAPOL_TX_STATUS
:
3985 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3986 data
->eapol_tx_status
.data
,
3987 data
->eapol_tx_status
.data_len
,
3988 data
->eapol_tx_status
.ack
);
3990 case EVENT_DRIVER_CLIENT_POLL_OK
:
3991 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
3993 case EVENT_RX_FROM_UNKNOWN
:
3994 if (wpa_s
->ap_iface
== NULL
)
3996 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
3997 data
->rx_from_unknown
.wds
);
3999 case EVENT_CH_SWITCH
:
4000 if (!data
|| !wpa_s
->current_ssid
)
4003 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
4004 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
4005 data
->ch_switch
.freq
,
4006 data
->ch_switch
.ht_enabled
,
4007 data
->ch_switch
.ch_offset
,
4008 channel_width_to_string(data
->ch_switch
.ch_width
),
4009 data
->ch_switch
.cf1
,
4010 data
->ch_switch
.cf2
);
4012 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
4013 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
4015 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
4016 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
4017 wpa_s
->current_ssid
->mode
==
4018 WPAS_MODE_P2P_GROUP_FORMATION
) {
4019 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
4020 data
->ch_switch
.ht_enabled
,
4021 data
->ch_switch
.ch_offset
,
4022 data
->ch_switch
.ch_width
,
4023 data
->ch_switch
.cf1
,
4024 data
->ch_switch
.cf2
);
4027 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
4030 case EVENT_DFS_RADAR_DETECTED
:
4032 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
4034 case EVENT_DFS_CAC_STARTED
:
4036 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
4038 case EVENT_DFS_CAC_FINISHED
:
4040 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
4042 case EVENT_DFS_CAC_ABORTED
:
4044 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
4046 case EVENT_DFS_NOP_FINISHED
:
4048 wpas_event_dfs_cac_nop_finished(wpa_s
,
4051 #endif /* NEED_AP_MLME */
4052 #endif /* CONFIG_AP */
4053 case EVENT_RX_MGMT
: {
4055 const struct ieee80211_mgmt
*mgmt
;
4057 #ifdef CONFIG_TESTING_OPTIONS
4058 if (wpa_s
->ext_mgmt_frame_handling
) {
4059 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
4060 size_t hex_len
= 2 * rx
->frame_len
+ 1;
4061 char *hex
= os_malloc(hex_len
);
4063 wpa_snprintf_hex(hex
, hex_len
,
4064 rx
->frame
, rx
->frame_len
);
4065 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
4066 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
4072 #endif /* CONFIG_TESTING_OPTIONS */
4074 mgmt
= (const struct ieee80211_mgmt
*)
4075 data
->rx_mgmt
.frame
;
4076 fc
= le_to_host16(mgmt
->frame_control
);
4077 stype
= WLAN_FC_GET_STYPE(fc
);
4080 if (wpa_s
->ap_iface
== NULL
) {
4081 #endif /* CONFIG_AP */
4083 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4084 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4085 const u8
*src
= mgmt
->sa
;
4089 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4090 ie_len
= data
->rx_mgmt
.frame_len
-
4092 wpas_p2p_probe_req_rx(
4093 wpa_s
, src
, mgmt
->da
,
4094 mgmt
->bssid
, ie
, ie_len
,
4096 data
->rx_mgmt
.ssi_signal
);
4099 #endif /* CONFIG_P2P */
4100 #ifdef CONFIG_IBSS_RSN
4101 if (wpa_s
->current_ssid
&&
4102 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4103 stype
== WLAN_FC_STYPE_AUTH
&&
4104 data
->rx_mgmt
.frame_len
>= 30) {
4105 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4108 #endif /* CONFIG_IBSS_RSN */
4110 if (stype
== WLAN_FC_STYPE_ACTION
) {
4111 wpas_event_rx_mgmt_action(
4112 wpa_s
, data
->rx_mgmt
.frame
,
4113 data
->rx_mgmt
.frame_len
,
4115 data
->rx_mgmt
.ssi_signal
);
4120 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4124 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4125 "management frame in non-AP mode");
4130 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4131 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4135 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4136 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4138 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4139 mgmt
->bssid
, ie
, ie_len
,
4140 data
->rx_mgmt
.ssi_signal
);
4143 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4144 #endif /* CONFIG_AP */
4147 case EVENT_RX_PROBE_REQ
:
4148 if (data
->rx_probe_req
.sa
== NULL
||
4149 data
->rx_probe_req
.ie
== NULL
)
4152 if (wpa_s
->ap_iface
) {
4153 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4154 data
->rx_probe_req
.sa
,
4155 data
->rx_probe_req
.da
,
4156 data
->rx_probe_req
.bssid
,
4157 data
->rx_probe_req
.ie
,
4158 data
->rx_probe_req
.ie_len
,
4159 data
->rx_probe_req
.ssi_signal
);
4162 #endif /* CONFIG_AP */
4163 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4164 data
->rx_probe_req
.da
,
4165 data
->rx_probe_req
.bssid
,
4166 data
->rx_probe_req
.ie
,
4167 data
->rx_probe_req
.ie_len
,
4169 data
->rx_probe_req
.ssi_signal
);
4171 case EVENT_REMAIN_ON_CHANNEL
:
4172 #ifdef CONFIG_OFFCHANNEL
4173 offchannel_remain_on_channel_cb(
4174 wpa_s
, data
->remain_on_channel
.freq
,
4175 data
->remain_on_channel
.duration
);
4176 #endif /* CONFIG_OFFCHANNEL */
4177 wpas_p2p_remain_on_channel_cb(
4178 wpa_s
, data
->remain_on_channel
.freq
,
4179 data
->remain_on_channel
.duration
);
4181 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4182 #ifdef CONFIG_OFFCHANNEL
4183 offchannel_cancel_remain_on_channel_cb(
4184 wpa_s
, data
->remain_on_channel
.freq
);
4185 #endif /* CONFIG_OFFCHANNEL */
4186 wpas_p2p_cancel_remain_on_channel_cb(
4187 wpa_s
, data
->remain_on_channel
.freq
);
4189 wpas_dpp_cancel_remain_on_channel_cb(
4190 wpa_s
, data
->remain_on_channel
.freq
);
4191 #endif /* CONFIG_DPP */
4193 case EVENT_EAPOL_RX
:
4194 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4195 data
->eapol_rx
.data
,
4196 data
->eapol_rx
.data_len
);
4198 case EVENT_SIGNAL_CHANGE
:
4199 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4200 "above=%d signal=%d noise=%d txrate=%d",
4201 data
->signal_change
.above_threshold
,
4202 data
->signal_change
.current_signal
,
4203 data
->signal_change
.current_noise
,
4204 data
->signal_change
.current_txrate
);
4205 wpa_bss_update_level(wpa_s
->current_bss
,
4206 data
->signal_change
.current_signal
);
4207 bgscan_notify_signal_change(
4208 wpa_s
, data
->signal_change
.above_threshold
,
4209 data
->signal_change
.current_signal
,
4210 data
->signal_change
.current_noise
,
4211 data
->signal_change
.current_txrate
);
4213 case EVENT_INTERFACE_ENABLED
:
4214 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4215 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4216 wpa_supplicant_update_mac_addr(wpa_s
);
4217 if (wpa_s
->p2p_mgmt
) {
4218 wpa_supplicant_set_state(wpa_s
,
4224 if (!wpa_s
->ap_iface
) {
4225 wpa_supplicant_set_state(wpa_s
,
4227 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4228 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4230 wpa_supplicant_set_state(wpa_s
,
4232 #else /* CONFIG_AP */
4233 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4234 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4235 #endif /* CONFIG_AP */
4238 case EVENT_INTERFACE_DISABLED
:
4239 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4241 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4242 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4243 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4245 * Mark interface disabled if this happens to end up not
4246 * being removed as a separate P2P group interface.
4248 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4250 * The interface was externally disabled. Remove
4251 * it assuming an external entity will start a
4252 * new session if needed.
4254 if (wpa_s
->current_ssid
&&
4255 wpa_s
->current_ssid
->p2p_group
)
4256 wpas_p2p_interface_unavailable(wpa_s
);
4258 wpas_p2p_disconnect(wpa_s
);
4260 * wpa_s instance may have been freed, so must not use
4265 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4266 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4267 /* This radio work will be cancelled, so clear P2P
4270 p2p_stop_find(wpa_s
->global
->p2p
);
4272 #endif /* CONFIG_P2P */
4274 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4276 * Indicate disconnection to keep ctrl_iface events
4279 wpa_supplicant_event_disassoc(
4280 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4282 wpa_supplicant_mark_disassoc(wpa_s
);
4283 wpa_bss_flush(wpa_s
);
4284 radio_remove_works(wpa_s
, NULL
, 0);
4286 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4288 case EVENT_CHANNEL_LIST_CHANGED
:
4289 wpa_supplicant_update_channel_list(
4290 wpa_s
, &data
->channel_list_changed
);
4292 case EVENT_INTERFACE_UNAVAILABLE
:
4293 wpas_p2p_interface_unavailable(wpa_s
);
4295 case EVENT_BEST_CHANNEL
:
4296 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4298 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4299 data
->best_chan
.freq_overall
);
4300 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4301 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4302 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4303 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4304 data
->best_chan
.freq_5
,
4305 data
->best_chan
.freq_overall
);
4307 case EVENT_UNPROT_DEAUTH
:
4308 wpa_supplicant_event_unprot_deauth(wpa_s
,
4309 &data
->unprot_deauth
);
4311 case EVENT_UNPROT_DISASSOC
:
4312 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4313 &data
->unprot_disassoc
);
4315 case EVENT_STATION_LOW_ACK
:
4317 if (wpa_s
->ap_iface
&& data
)
4318 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4319 data
->low_ack
.addr
);
4320 #endif /* CONFIG_AP */
4323 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4324 data
->low_ack
.addr
);
4325 #endif /* CONFIG_TDLS */
4327 case EVENT_IBSS_PEER_LOST
:
4328 #ifdef CONFIG_IBSS_RSN
4329 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4330 #endif /* CONFIG_IBSS_RSN */
4332 case EVENT_DRIVER_GTK_REKEY
:
4333 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4334 wpa_s
->bssid
, ETH_ALEN
))
4338 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4339 data
->driver_gtk_rekey
.replay_ctr
);
4341 case EVENT_SCHED_SCAN_STOPPED
:
4342 wpa_s
->sched_scanning
= 0;
4343 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4344 wpa_supplicant_notify_scanning(wpa_s
, 0);
4346 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4350 * If the driver stopped scanning without being requested to,
4351 * request a new scan to continue scanning for networks.
4353 if (!wpa_s
->sched_scan_stop_req
&&
4354 wpa_s
->wpa_state
== WPA_SCANNING
) {
4355 wpa_dbg(wpa_s
, MSG_DEBUG
,
4356 "Restart scanning after unexpected sched_scan stop event");
4357 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4361 wpa_s
->sched_scan_stop_req
= 0;
4364 * Start a new sched scan to continue searching for more SSIDs
4365 * either if timed out or PNO schedule scan is pending.
4367 if (wpa_s
->sched_scan_timed_out
) {
4368 wpa_supplicant_req_sched_scan(wpa_s
);
4369 } else if (wpa_s
->pno_sched_pending
) {
4370 wpa_s
->pno_sched_pending
= 0;
4371 wpas_start_pno(wpa_s
);
4372 } else if (resched
) {
4373 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4377 case EVENT_WPS_BUTTON_PUSHED
:
4379 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4380 #endif /* CONFIG_WPS */
4382 case EVENT_AVOID_FREQUENCIES
:
4383 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4385 case EVENT_CONNECT_FAILED_REASON
:
4387 if (!wpa_s
->ap_iface
|| !data
)
4389 hostapd_event_connect_failed_reason(
4390 wpa_s
->ap_iface
->bss
[0],
4391 data
->connect_failed_reason
.addr
,
4392 data
->connect_failed_reason
.code
);
4393 #endif /* CONFIG_AP */
4395 case EVENT_NEW_PEER_CANDIDATE
:
4397 if (!wpa_s
->ifmsh
|| !data
)
4399 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4400 data
->mesh_peer
.ies
,
4401 data
->mesh_peer
.ie_len
);
4402 #endif /* CONFIG_MESH */
4406 if (!wpa_s
->ap_iface
)
4408 hostapd_event_get_survey(wpa_s
->ap_iface
,
4409 &data
->survey_results
);
4410 #endif /* CONFIG_AP */
4412 case EVENT_ACS_CHANNEL_SELECTED
:
4415 if (!wpa_s
->ap_iface
)
4417 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4418 &data
->acs_selected_channels
);
4419 #endif /* CONFIG_ACS */
4420 #endif /* CONFIG_AP */
4422 case EVENT_P2P_LO_STOP
:
4424 wpa_s
->p2p_lo_started
= 0;
4425 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4426 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4427 data
->p2p_lo_stop
.reason_code
);
4428 #endif /* CONFIG_P2P */
4430 case EVENT_BEACON_LOSS
:
4431 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4433 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4434 bgscan_notify_beacon_loss(wpa_s
);
4437 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4443 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4444 union wpa_event_data
*data
)
4446 struct wpa_supplicant
*wpa_s
;
4448 if (event
!= EVENT_INTERFACE_STATUS
)
4451 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4452 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4453 unsigned int ifindex
;
4455 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4456 if (ifindex
!= data
->interface_status
.ifindex
) {
4457 wpa_dbg(wpa_s
, MSG_DEBUG
,
4458 "interface status ifindex %d mismatch (%d)",
4459 ifindex
, data
->interface_status
.ifindex
);
4463 #ifdef CONFIG_MATCH_IFACE
4464 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4465 struct wpa_interface
*wpa_i
;
4467 wpa_i
= wpa_supplicant_match_iface(
4468 ctx
, data
->interface_status
.ifname
);
4471 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4476 #endif /* CONFIG_MATCH_IFACE */
4479 wpa_supplicant_event(wpa_s
, event
, data
);