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 "crypto/random.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
37 #include "gas_query.h"
38 #include "p2p_supplicant.h"
44 #include "offchannel.h"
45 #include "interworking.h"
51 #ifndef CONFIG_NO_SCAN_PROCESSING
52 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
53 int new_scan
, int own_request
);
54 #endif /* CONFIG_NO_SCAN_PROCESSING */
57 static int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
,
58 struct wpa_ssid
*ssid
)
60 struct os_reltime now
;
62 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
66 if (ssid
->disabled_until
.sec
> now
.sec
)
67 return ssid
->disabled_until
.sec
- now
.sec
;
69 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
75 #ifndef CONFIG_NO_SCAN_PROCESSING
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
86 static int wpas_reenabled_network_time(struct wpa_supplicant
*wpa_s
)
88 struct wpa_ssid
*ssid
;
89 int disabled_for
, res
= 0;
91 #ifdef CONFIG_INTERWORKING
92 if (wpa_s
->conf
->auto_interworking
&& wpa_s
->conf
->interworking
&&
95 #endif /* CONFIG_INTERWORKING */
97 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
101 disabled_for
= wpas_temp_disabled(wpa_s
, ssid
);
105 if (!res
|| disabled_for
< res
)
111 #endif /* CONFIG_NO_SCAN_PROCESSING */
114 void wpas_network_reenabled(void *eloop_ctx
, void *timeout_ctx
)
116 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
118 if (wpa_s
->disconnected
|| wpa_s
->wpa_state
!= WPA_SCANNING
)
121 wpa_dbg(wpa_s
, MSG_DEBUG
,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s
);
125 wpa_supplicant_req_scan(wpa_s
, 0, 0);
130 static struct wpa_bss
* wpa_supplicant_get_new_bss(
131 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
133 struct wpa_bss
*bss
= NULL
;
134 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
136 if (ssid
->ssid_len
> 0)
137 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
139 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
145 static void wpa_supplicant_update_current_bss(struct wpa_supplicant
*wpa_s
)
147 struct wpa_bss
*bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
150 wpa_supplicant_update_scan_results(wpa_s
);
152 /* Get the BSS from the new scan results */
153 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
157 wpa_s
->current_bss
= bss
;
161 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
163 struct wpa_ssid
*ssid
, *old_ssid
;
164 u8 drv_ssid
[SSID_MAX_LEN
];
168 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
) {
169 wpa_supplicant_update_current_bss(wpa_s
);
171 if (wpa_s
->current_ssid
->ssid_len
== 0)
172 return 0; /* current profile still in use */
173 res
= wpa_drv_get_ssid(wpa_s
, drv_ssid
);
175 wpa_msg(wpa_s
, MSG_INFO
,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
181 if (drv_ssid_len
== wpa_s
->current_ssid
->ssid_len
&&
182 os_memcmp(drv_ssid
, wpa_s
->current_ssid
->ssid
,
184 return 0; /* current profile still in use */
186 wpa_msg(wpa_s
, MSG_DEBUG
,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid
, drv_ssid_len
));
189 /* continue selecting a new network profile */
192 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
194 ssid
= wpa_supplicant_get_ssid(wpa_s
);
196 wpa_msg(wpa_s
, MSG_INFO
,
197 "No network configuration found for the current AP");
201 if (wpas_network_disabled(wpa_s
, ssid
)) {
202 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
206 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
207 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
208 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
212 res
= wpas_temp_disabled(wpa_s
, ssid
);
214 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
215 "disabled for %d second(s)", res
);
219 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
221 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
223 size_t wpa_ie_len
= sizeof(wpa_ie
);
224 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
225 wpa_ie
, &wpa_ie_len
) < 0)
226 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
228 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
231 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
232 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
233 old_ssid
= wpa_s
->current_ssid
;
234 wpa_s
->current_ssid
= ssid
;
236 wpa_supplicant_update_current_bss(wpa_s
);
238 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
239 wpa_supplicant_initiate_eapol(wpa_s
);
240 if (old_ssid
!= wpa_s
->current_ssid
)
241 wpas_notify_network_changed(wpa_s
);
247 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
249 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
251 if (wpa_s
->countermeasures
) {
252 wpa_s
->countermeasures
= 0;
253 wpa_drv_set_countermeasures(wpa_s
, 0);
254 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
263 wpa_supplicant_cancel_sched_scan(wpa_s
);
264 wpa_supplicant_req_scan(wpa_s
, 0, 0);
269 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
273 wnm_bss_keep_alive_deinit(wpa_s
);
275 #ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
277 wpa_s
->ibss_rsn
= NULL
;
278 #endif /* CONFIG_IBSS_RSN */
281 wpa_supplicant_ap_deinit(wpa_s
);
282 #endif /* CONFIG_AP */
285 /* Clear possibly configured frame filters */
286 wpa_drv_configure_frame_filters(wpa_s
, 0);
287 #endif /* CONFIG_HS20 */
289 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
292 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
293 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
294 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
295 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
296 sme_clear_on_disassoc(wpa_s
);
297 wpa_s
->current_bss
= NULL
;
298 wpa_s
->assoc_freq
= 0;
301 wpas_notify_bssid_changed(wpa_s
);
303 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
304 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
305 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
306 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
307 wpa_s
->ap_ies_from_associnfo
= 0;
308 wpa_s
->current_ssid
= NULL
;
309 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
312 wpas_rrm_reset(wpa_s
);
313 wpa_s
->wnmsleep_used
= 0;
317 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
319 struct wpa_ie_data ie
;
323 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
327 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
328 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
329 ie
.pmkid
+ i
* PMKID_LEN
,
331 if (pmksa_set
== 0) {
332 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
337 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
338 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
342 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
343 union wpa_event_data
*data
)
346 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
350 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
351 " index=%d preauth=%d",
352 MAC2STR(data
->pmkid_candidate
.bssid
),
353 data
->pmkid_candidate
.index
,
354 data
->pmkid_candidate
.preauth
);
356 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
357 data
->pmkid_candidate
.index
,
358 data
->pmkid_candidate
.preauth
);
362 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
364 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
365 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
368 #ifdef IEEE8021X_EAPOL
369 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
370 wpa_s
->current_ssid
&&
371 !(wpa_s
->current_ssid
->eapol_flags
&
372 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
373 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
374 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
375 * plaintext or static WEP keys). */
378 #endif /* IEEE8021X_EAPOL */
385 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
386 * @wpa_s: pointer to wpa_supplicant data
387 * @ssid: Configuration data for the network
388 * Returns: 0 on success, -1 on failure
390 * This function is called when starting authentication with a network that is
391 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
393 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
394 struct wpa_ssid
*ssid
)
396 #ifdef IEEE8021X_EAPOL
398 int aka
= 0, sim
= 0;
400 if ((ssid
!= NULL
&& ssid
->eap
.pcsc
== NULL
) ||
401 wpa_s
->scard
!= NULL
|| wpa_s
->conf
->external_sim
)
404 if (ssid
== NULL
|| ssid
->eap
.eap_methods
== NULL
) {
408 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
409 while (eap
->vendor
!= EAP_VENDOR_IETF
||
410 eap
->method
!= EAP_TYPE_NONE
) {
411 if (eap
->vendor
== EAP_VENDOR_IETF
) {
412 if (eap
->method
== EAP_TYPE_SIM
)
414 else if (eap
->method
== EAP_TYPE_AKA
||
415 eap
->method
== EAP_TYPE_AKA_PRIME
)
422 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
424 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
425 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
430 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
431 "use SIM, but neither EAP-SIM nor EAP-AKA are "
436 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
437 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
439 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
440 if (wpa_s
->scard
== NULL
) {
441 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
445 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
446 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
447 #endif /* PCSC_FUNCS */
448 #endif /* IEEE8021X_EAPOL */
454 #ifndef CONFIG_NO_SCAN_PROCESSING
456 static int has_wep_key(struct wpa_ssid
*ssid
)
460 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
461 if (ssid
->wep_key_len
[i
])
469 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
470 struct wpa_ssid
*ssid
)
474 if (ssid
->mixed_cell
)
478 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
480 #endif /* CONFIG_WPS */
482 if (has_wep_key(ssid
))
485 #ifdef IEEE8021X_EAPOL
486 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
487 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
488 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
490 #endif /* IEEE8021X_EAPOL */
492 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
495 if (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)
498 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
504 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
505 struct wpa_ssid
*ssid
,
506 struct wpa_bss
*bss
, int debug_print
)
508 struct wpa_ie_data ie
;
510 const u8
*rsn_ie
, *wpa_ie
;
514 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
518 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
519 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
520 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
521 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
522 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
524 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
525 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
528 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
530 wpa_dbg(wpa_s
, MSG_DEBUG
,
531 " skip RSN IE - parse failed");
536 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
539 wpa_dbg(wpa_s
, MSG_DEBUG
,
540 " selected based on TSN in RSN IE");
544 if (!(ie
.proto
& ssid
->proto
)) {
546 wpa_dbg(wpa_s
, MSG_DEBUG
,
547 " skip RSN IE - proto mismatch");
551 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
553 wpa_dbg(wpa_s
, MSG_DEBUG
,
554 " skip RSN IE - PTK cipher mismatch");
558 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
560 wpa_dbg(wpa_s
, MSG_DEBUG
,
561 " skip RSN IE - GTK cipher mismatch");
565 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
567 wpa_dbg(wpa_s
, MSG_DEBUG
,
568 " skip RSN IE - key mgmt mismatch");
572 #ifdef CONFIG_IEEE80211W
573 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
574 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
575 MGMT_FRAME_PROTECTION_REQUIRED
) {
577 wpa_dbg(wpa_s
, MSG_DEBUG
,
578 " skip RSN IE - no mgmt frame protection");
581 #endif /* CONFIG_IEEE80211W */
582 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
583 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
584 NO_MGMT_FRAME_PROTECTION
) {
586 wpa_dbg(wpa_s
, MSG_DEBUG
,
587 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
591 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
592 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
593 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
594 NO_MGMT_FRAME_PROTECTION
) {
596 wpa_dbg(wpa_s
, MSG_DEBUG
,
597 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
600 #endif /* CONFIG_MBO */
603 wpa_dbg(wpa_s
, MSG_DEBUG
,
604 " selected based on RSN IE");
608 #ifdef CONFIG_IEEE80211W
609 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
611 wpa_dbg(wpa_s
, MSG_DEBUG
,
612 " skip - MFP Required but network not MFP Capable");
615 #endif /* CONFIG_IEEE80211W */
617 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
618 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
621 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
623 wpa_dbg(wpa_s
, MSG_DEBUG
,
624 " skip WPA IE - parse failed");
629 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
632 wpa_dbg(wpa_s
, MSG_DEBUG
,
633 " selected based on TSN in WPA IE");
637 if (!(ie
.proto
& ssid
->proto
)) {
639 wpa_dbg(wpa_s
, MSG_DEBUG
,
640 " skip WPA IE - proto mismatch");
644 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
646 wpa_dbg(wpa_s
, MSG_DEBUG
,
647 " skip WPA IE - PTK cipher mismatch");
651 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
653 wpa_dbg(wpa_s
, MSG_DEBUG
,
654 " skip WPA IE - GTK cipher mismatch");
658 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
660 wpa_dbg(wpa_s
, MSG_DEBUG
,
661 " skip WPA IE - key mgmt mismatch");
666 wpa_dbg(wpa_s
, MSG_DEBUG
,
667 " selected based on WPA IE");
671 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
674 wpa_dbg(wpa_s
, MSG_DEBUG
,
675 " allow for non-WPA IEEE 802.1X");
679 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
680 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
682 wpa_dbg(wpa_s
, MSG_DEBUG
,
683 " skip - no WPA/RSN proto match");
687 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
688 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
690 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
694 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
696 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
701 wpa_dbg(wpa_s
, MSG_DEBUG
,
702 " reject due to mismatch with WPA/WPA2");
708 static int freq_allowed(int *freqs
, int freq
)
715 for (i
= 0; freqs
[i
]; i
++)
716 if (freqs
[i
] == freq
)
722 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
725 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
726 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
731 return 1; /* Cannot do matching without knowing band */
733 modes
= wpa_s
->hw
.modes
;
736 * The driver does not provide any additional information
737 * about the utilized hardware, so allow the connection attempt
743 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
744 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
745 int freq
= modes
[i
].channels
[j
].freq
;
746 if (freq
== bss
->freq
) {
748 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
749 break; /* do not allow 802.11b replace
760 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
761 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
765 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
766 int flagged
= !!(rate_ie
[j
] & 0x80);
767 int r
= (rate_ie
[j
] & 0x7f) * 5;
770 * IEEE Std 802.11n-2009 7.3.2.2:
771 * The new BSS Membership selector value is encoded
772 * like a legacy basic rate, but it is not a rate and
773 * only indicates if the BSS members are required to
774 * support the mandatory features of Clause 20 [HT PHY]
775 * in order to join the BSS.
777 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
778 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
779 if (!ht_supported(mode
)) {
781 wpa_dbg(wpa_s
, MSG_DEBUG
,
782 " hardware does not support HT PHY");
788 /* There's also a VHT selector for 802.11ac */
789 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
790 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
791 if (!vht_supported(mode
)) {
793 wpa_dbg(wpa_s
, MSG_DEBUG
,
794 " hardware does not support VHT PHY");
803 /* check for legacy basic rates */
804 for (k
= 0; k
< mode
->num_rates
; k
++) {
805 if (mode
->rates
[k
] == r
)
808 if (k
== mode
->num_rates
) {
810 * IEEE Std 802.11-2007 7.3.2.2 demands that in
811 * order to join a BSS all required rates
812 * have to be supported by the hardware.
815 wpa_dbg(wpa_s
, MSG_DEBUG
,
816 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
818 bss
->freq
, mode
->mode
, mode
->num_rates
);
829 * Test whether BSS is in an ESS.
830 * This is done differently in DMG (60 GHz) and non-DMG bands
832 static int bss_is_ess(struct wpa_bss
*bss
)
834 if (bss_is_dmg(bss
)) {
835 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
836 IEEE80211_CAP_DMG_AP
;
839 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
844 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
848 for (i
= 0; i
< ETH_ALEN
; i
++) {
849 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
856 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
860 for (i
= 0; i
< num
; i
++) {
861 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
862 const u8
*m
= a
+ ETH_ALEN
;
864 if (match_mac_mask(a
, addr
, m
))
871 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
872 int i
, struct wpa_bss
*bss
,
873 struct wpa_ssid
*group
,
874 int only_first_ssid
, int debug_print
)
876 u8 wpa_ie_len
, rsn_ie_len
;
878 struct wpa_blacklist
*e
;
880 struct wpa_ssid
*ssid
;
883 const u8
*assoc_disallow
;
884 #endif /* CONFIG_MBO */
886 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
887 wpa_ie_len
= ie
? ie
[1] : 0;
889 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
890 rsn_ie_len
= ie
? ie
[1] : 0;
892 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
896 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
897 " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
898 i
, MAC2STR(bss
->bssid
),
899 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
900 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
902 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
904 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
905 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
))
907 osen
? " osen=1" : "");
910 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
913 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
915 * When only a single network is enabled, we can
916 * trigger blacklisting on the first failure. This
917 * should not be done with multiple enabled networks to
918 * avoid getting forced to move into a worse ESS on
919 * single error if there are no other BSSes of the
924 if (e
->count
> limit
) {
926 wpa_dbg(wpa_s
, MSG_DEBUG
,
927 " skip - blacklisted (count=%d limit=%d)",
934 if (bss
->ssid_len
== 0) {
936 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
940 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
942 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
946 if (disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
948 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
952 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
954 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
955 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
958 if (wpas_network_disabled(wpa_s
, ssid
)) {
960 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
964 res
= wpas_temp_disabled(wpa_s
, ssid
);
967 wpa_dbg(wpa_s
, MSG_DEBUG
,
968 " skip - disabled temporarily for %d second(s)",
974 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
976 wpa_dbg(wpa_s
, MSG_DEBUG
,
977 " skip - blacklisted (WPS)");
981 if (wpa
&& ssid
->ssid_len
== 0 &&
982 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
985 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
986 /* Only allow wildcard SSID match if an AP
987 * advertises active WPS operation that matches
990 if (ssid
->ssid_len
== 0 &&
991 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
994 #endif /* CONFIG_WPS */
996 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
997 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
1001 (bss
->ssid_len
!= ssid
->ssid_len
||
1002 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
1004 wpa_dbg(wpa_s
, MSG_DEBUG
,
1005 " skip - SSID mismatch");
1009 if (ssid
->bssid_set
&&
1010 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
1012 wpa_dbg(wpa_s
, MSG_DEBUG
,
1013 " skip - BSSID mismatch");
1017 /* check blacklist */
1018 if (ssid
->num_bssid_blacklist
&&
1019 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
1020 ssid
->num_bssid_blacklist
)) {
1022 wpa_dbg(wpa_s
, MSG_DEBUG
,
1023 " skip - BSSID blacklisted");
1027 /* if there is a whitelist, only accept those APs */
1028 if (ssid
->num_bssid_whitelist
&&
1029 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
1030 ssid
->num_bssid_whitelist
)) {
1032 wpa_dbg(wpa_s
, MSG_DEBUG
,
1033 " skip - BSSID not in whitelist");
1037 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
,
1041 if (!osen
&& !wpa
&&
1042 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
1043 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1044 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
1046 wpa_dbg(wpa_s
, MSG_DEBUG
,
1047 " skip - non-WPA network not allowed");
1051 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1052 has_wep_key(ssid
)) {
1054 wpa_dbg(wpa_s
, MSG_DEBUG
,
1055 " skip - ignore WPA/WPA2 AP for WEP network block");
1059 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1061 wpa_dbg(wpa_s
, MSG_DEBUG
,
1062 " skip - non-OSEN network not allowed");
1066 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1068 wpa_dbg(wpa_s
, MSG_DEBUG
,
1069 " skip - privacy mismatch");
1073 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1074 !bss_is_pbss(bss
)) {
1076 wpa_dbg(wpa_s
, MSG_DEBUG
,
1077 " skip - not ESS, PBSS, or MBSS");
1081 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1083 wpa_dbg(wpa_s
, MSG_DEBUG
,
1084 " skip - PBSS mismatch (ssid %d bss %d)",
1085 ssid
->pbss
, bss_is_pbss(bss
));
1089 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1091 wpa_dbg(wpa_s
, MSG_DEBUG
,
1092 " skip - frequency not allowed");
1097 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1098 ssid
->frequency
!= bss
->freq
) {
1100 wpa_dbg(wpa_s
, MSG_DEBUG
,
1101 " skip - frequency not allowed (mesh)");
1104 #endif /* CONFIG_MESH */
1106 if (!rate_match(wpa_s
, bss
, debug_print
)) {
1108 wpa_dbg(wpa_s
, MSG_DEBUG
,
1109 " skip - rate sets do not match");
1113 #ifndef CONFIG_IBSS_RSN
1114 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1115 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1116 WPA_KEY_MGMT_WPA_NONE
))) {
1118 wpa_dbg(wpa_s
, MSG_DEBUG
,
1119 " skip - IBSS RSN not supported in the build");
1122 #endif /* !CONFIG_IBSS_RSN */
1125 if (ssid
->p2p_group
&&
1126 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1127 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1129 wpa_dbg(wpa_s
, MSG_DEBUG
,
1130 " skip - no P2P IE seen");
1134 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1135 struct wpabuf
*p2p_ie
;
1136 u8 dev_addr
[ETH_ALEN
];
1138 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1141 wpa_dbg(wpa_s
, MSG_DEBUG
,
1142 " skip - no P2P element");
1145 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1146 bss
, P2P_IE_VENDOR_TYPE
);
1147 if (p2p_ie
== NULL
) {
1149 wpa_dbg(wpa_s
, MSG_DEBUG
,
1150 " skip - could not fetch P2P element");
1154 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1155 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1158 wpa_dbg(wpa_s
, MSG_DEBUG
,
1159 " skip - no matching GO P2P Device Address in P2P element");
1160 wpabuf_free(p2p_ie
);
1163 wpabuf_free(p2p_ie
);
1167 * TODO: skip the AP if its P2P IE has Group Formation
1168 * bit set in the P2P Group Capability Bitmap and we
1169 * are not in Group Formation with that device.
1171 #endif /* CONFIG_P2P */
1173 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1175 struct os_reltime diff
;
1177 os_reltime_sub(&wpa_s
->scan_min_time
,
1178 &bss
->last_update
, &diff
);
1180 wpa_dbg(wpa_s
, MSG_DEBUG
,
1181 " skip - scan result not recent enough (%u.%06u seconds too old)",
1182 (unsigned int) diff
.sec
,
1183 (unsigned int) diff
.usec
);
1187 #ifdef CONFIG_TESTING_OPTIONS
1188 if (wpa_s
->ignore_assoc_disallow
)
1189 goto skip_assoc_disallow
;
1190 #endif /* CONFIG_TESTING_OPTIONS */
1191 assoc_disallow
= wpas_mbo_get_bss_attr(
1192 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1193 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1195 wpa_dbg(wpa_s
, MSG_DEBUG
,
1196 " skip - MBO association disallowed (reason %u)",
1201 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1203 wpa_dbg(wpa_s
, MSG_DEBUG
,
1204 " skip - MBO retry delay has not passed yet");
1207 #ifdef CONFIG_TESTING_OPTIONS
1208 skip_assoc_disallow
:
1209 #endif /* CONFIG_TESTING_OPTIONS */
1210 #endif /* CONFIG_MBO */
1212 /* Matching configuration found */
1216 /* No matching configuration found */
1221 static struct wpa_bss
*
1222 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1223 struct wpa_ssid
*group
,
1224 struct wpa_ssid
**selected_ssid
,
1225 int only_first_ssid
)
1229 if (wpa_s
->current_ssid
) {
1230 struct wpa_ssid
*ssid
;
1232 wpa_dbg(wpa_s
, MSG_DEBUG
,
1233 "Scan results matching the currently selected network");
1234 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1235 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1237 ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1238 only_first_ssid
, 0);
1239 if (ssid
!= wpa_s
->current_ssid
)
1241 wpa_dbg(wpa_s
, MSG_DEBUG
, "%u: " MACSTR
1242 " freq=%d level=%d snr=%d est_throughput=%u",
1243 i
, MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
,
1244 bss
->snr
, bss
->est_throughput
);
1248 if (only_first_ssid
)
1249 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1252 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1255 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1256 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1257 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1258 only_first_ssid
, 1);
1259 if (!*selected_ssid
)
1261 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1263 MAC2STR(bss
->bssid
),
1264 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1272 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1273 struct wpa_ssid
**selected_ssid
)
1275 struct wpa_bss
*selected
= NULL
;
1277 struct wpa_ssid
*next_ssid
= NULL
;
1278 struct wpa_ssid
*ssid
;
1280 if (wpa_s
->last_scan_res
== NULL
||
1281 wpa_s
->last_scan_res_used
== 0)
1282 return NULL
; /* no scan results from last update */
1284 if (wpa_s
->next_ssid
) {
1285 /* check that next_ssid is still valid */
1286 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1287 if (ssid
== wpa_s
->next_ssid
)
1291 wpa_s
->next_ssid
= NULL
;
1294 while (selected
== NULL
) {
1295 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1296 if (next_ssid
&& next_ssid
->priority
==
1297 wpa_s
->conf
->pssid
[prio
]->priority
) {
1298 selected
= wpa_supplicant_select_bss(
1299 wpa_s
, next_ssid
, selected_ssid
, 1);
1303 selected
= wpa_supplicant_select_bss(
1304 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1310 if (selected
== NULL
&& wpa_s
->blacklist
&&
1311 !wpa_s
->countermeasures
) {
1312 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1313 "blacklist and try again");
1314 wpa_blacklist_clear(wpa_s
);
1315 wpa_s
->blacklist_cleared
++;
1316 } else if (selected
== NULL
)
1320 ssid
= *selected_ssid
;
1321 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1322 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1323 const char *field_name
, *txt
= NULL
;
1325 wpa_dbg(wpa_s
, MSG_DEBUG
,
1326 "PSK/passphrase not yet available for the selected network");
1328 wpas_notify_network_request(wpa_s
, ssid
,
1329 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1331 field_name
= wpa_supplicant_ctrl_req_to_string(
1332 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1333 if (field_name
== NULL
)
1336 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1345 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1346 int timeout_sec
, int timeout_usec
)
1348 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1350 * No networks are enabled; short-circuit request so
1351 * we don't wait timeout seconds before transitioning
1352 * to INACTIVE state.
1354 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1355 "since there are no enabled networks");
1356 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1360 wpa_s
->scan_for_connection
= 1;
1361 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1365 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1366 struct wpa_bss
*selected
,
1367 struct wpa_ssid
*ssid
)
1369 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1370 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1371 "PBC session overlap");
1372 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1374 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1375 wpa_s
->p2p_in_provisioning
) {
1376 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1380 #endif /* CONFIG_P2P */
1383 wpas_wps_pbc_overlap(wpa_s
);
1384 wpas_wps_cancel(wpa_s
);
1385 #endif /* CONFIG_WPS */
1389 wpa_msg(wpa_s
, MSG_DEBUG
,
1390 "Considering connect request: reassociate: %d selected: "
1391 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1392 " wpa_state: %s ssid=%p current_ssid=%p",
1393 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1394 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1395 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1396 ssid
, wpa_s
->current_ssid
);
1399 * Do not trigger new association unless the BSSID has changed or if
1400 * reassociation is requested. If we are in process of associating with
1401 * the selected BSSID, do not trigger new attempt.
1403 if (wpa_s
->reassociate
||
1404 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1405 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1406 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1407 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1408 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1410 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1411 ssid
!= wpa_s
->current_ssid
)))) {
1412 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1413 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1416 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1417 MAC2STR(selected
->bssid
));
1418 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1420 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1421 "connect with the selected AP");
1428 static struct wpa_ssid
*
1429 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1432 struct wpa_ssid
*ssid
;
1434 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1435 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1437 if (wpas_network_disabled(wpa_s
, ssid
))
1439 #ifndef CONFIG_IBSS_RSN
1440 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1441 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
|
1442 WPA_KEY_MGMT_WPA_NONE
))) {
1443 wpa_msg(wpa_s
, MSG_INFO
,
1444 "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
1445 wpa_ssid_txt(ssid
->ssid
,
1449 #endif /* !CONFIG_IBSS_RSN */
1450 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1451 ssid
->mode
== IEEE80211_MODE_AP
||
1452 ssid
->mode
== IEEE80211_MODE_MESH
)
1460 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1461 * on BSS added and BSS changed events */
1462 static void wpa_supplicant_rsn_preauth_scan_results(
1463 struct wpa_supplicant
*wpa_s
)
1465 struct wpa_bss
*bss
;
1467 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1470 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1471 const u8
*ssid
, *rsn
;
1473 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1477 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1481 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1487 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1488 struct wpa_bss
*selected
,
1489 struct wpa_ssid
*ssid
)
1491 struct wpa_bss
*current_bss
= NULL
;
1492 #ifndef CONFIG_NO_ROAMING
1495 int cur_est
, sel_est
;
1496 #endif /* CONFIG_NO_ROAMING */
1498 if (wpa_s
->reassociate
)
1499 return 1; /* explicit request to reassociate */
1500 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1501 return 1; /* we are not associated; continue */
1502 if (wpa_s
->current_ssid
== NULL
)
1503 return 1; /* unknown current SSID */
1504 if (wpa_s
->current_ssid
!= ssid
)
1505 return 1; /* different network block */
1507 if (wpas_driver_bss_selection(wpa_s
))
1508 return 0; /* Driver-based roaming */
1510 if (wpa_s
->current_ssid
->ssid
)
1511 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1512 wpa_s
->current_ssid
->ssid
,
1513 wpa_s
->current_ssid
->ssid_len
);
1515 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1518 return 1; /* current BSS not seen in scan results */
1520 if (current_bss
== selected
)
1523 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1524 return 1; /* current BSS not seen in the last scan */
1526 #ifndef CONFIG_NO_ROAMING
1527 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1528 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1529 " freq=%d level=%d snr=%d est_throughput=%u",
1530 MAC2STR(current_bss
->bssid
),
1531 current_bss
->freq
, current_bss
->level
,
1532 current_bss
->snr
, current_bss
->est_throughput
);
1533 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1534 " freq=%d level=%d snr=%d est_throughput=%u",
1535 MAC2STR(selected
->bssid
), selected
->freq
, selected
->level
,
1536 selected
->snr
, selected
->est_throughput
);
1538 if (wpa_s
->current_ssid
->bssid_set
&&
1539 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1541 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1542 "has preferred BSSID");
1546 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1547 wpa_dbg(wpa_s
, MSG_DEBUG
,
1548 "Allow reassociation - selected BSS has better estimated throughput");
1552 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1554 if (current_bss
->level
< 0 &&
1555 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1556 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1561 if (current_bss
->est_throughput
> selected
->est_throughput
+ 5000) {
1562 wpa_dbg(wpa_s
, MSG_DEBUG
,
1563 "Skip roam - Current BSS has better estimated throughput");
1567 cur_est
= current_bss
->est_throughput
;
1568 sel_est
= selected
->est_throughput
;
1570 if (current_bss
->level
< 0) {
1571 if (current_bss
->level
< -85)
1573 else if (current_bss
->level
< -80)
1575 else if (current_bss
->level
< -75)
1577 else if (current_bss
->level
< -70)
1581 if (cur_est
> sel_est
* 1.5)
1583 else if (cur_est
> sel_est
* 1.2)
1585 else if (cur_est
> sel_est
* 1.1)
1587 else if (cur_est
> sel_est
)
1593 /* Make it easier to move to 5 GHz band */
1594 if (sel_est
> cur_est
* 1.5)
1596 else if (sel_est
> cur_est
* 1.2)
1598 else if (sel_est
> cur_est
* 1.1)
1601 if (min_diff
> reduce
)
1606 diff
= abs(current_bss
->level
- selected
->level
);
1607 if (diff
< min_diff
) {
1608 wpa_dbg(wpa_s
, MSG_DEBUG
,
1609 "Skip roam - too small difference in signal level (%d < %d)",
1614 wpa_dbg(wpa_s
, MSG_DEBUG
,
1615 "Allow reassociation due to difference in signal level (%d >= %d)",
1618 #else /* CONFIG_NO_ROAMING */
1620 #endif /* CONFIG_NO_ROAMING */
1625 * Return a negative value if no scan results could be fetched or if scan
1626 * results should not be shared with other virtual interfaces.
1627 * Return 0 if scan results were fetched and may be shared with other
1629 * Return 1 if scan results may be shared with other virtual interfaces but may
1630 * not trigger any operations.
1631 * Return 2 if the interface was removed and cannot be used.
1633 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1634 union wpa_event_data
*data
,
1635 int own_request
, int update_only
)
1637 struct wpa_scan_results
*scan_res
= NULL
;
1640 #ifndef CONFIG_NO_RANDOM_POOL
1642 #endif /* CONFIG_NO_RANDOM_POOL */
1645 if (wpa_s
->ap_iface
)
1647 #endif /* CONFIG_AP */
1649 wpa_supplicant_notify_scanning(wpa_s
, 0);
1651 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1652 data
? &data
->scan_info
:
1654 if (scan_res
== NULL
) {
1655 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1656 wpa_s
->scan_res_handler
== scan_only_handler
)
1660 if (data
&& data
->scan_info
.external_scan
)
1662 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1664 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1666 goto scan_work_done
;
1669 #ifndef CONFIG_NO_RANDOM_POOL
1670 num
= scan_res
->num
;
1673 for (i
= 0; i
< num
; i
++) {
1675 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1676 buf
[0] = res
->bssid
[5];
1677 buf
[1] = res
->qual
& 0xff;
1678 buf
[2] = res
->noise
& 0xff;
1679 buf
[3] = res
->level
& 0xff;
1680 buf
[4] = res
->tsf
& 0xff;
1681 random_add_randomness(buf
, sizeof(buf
));
1683 #endif /* CONFIG_NO_RANDOM_POOL */
1687 goto scan_work_done
;
1690 if (own_request
&& wpa_s
->scan_res_handler
&&
1691 !(data
&& data
->scan_info
.external_scan
)) {
1692 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1693 struct wpa_scan_results
*scan_res
);
1695 scan_res_handler
= wpa_s
->scan_res_handler
;
1696 wpa_s
->scan_res_handler
= NULL
;
1697 scan_res_handler(wpa_s
, scan_res
);
1699 goto scan_work_done
;
1703 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1705 if (wpa_s
->ap_iface
->scan_cb
)
1706 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1707 #endif /* CONFIG_AP */
1708 goto scan_work_done
;
1711 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1712 wpa_s
->own_scan_running
,
1713 data
? data
->scan_info
.external_scan
: 0);
1714 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1715 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1716 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1717 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1718 wpa_s
->manual_scan_id
);
1719 wpa_s
->manual_scan_use_id
= 0;
1721 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1723 wpas_notify_scan_results(wpa_s
);
1725 wpas_notify_scan_done(wpa_s
, 1);
1727 if (data
&& data
->scan_info
.external_scan
) {
1728 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1729 wpa_scan_results_free(scan_res
);
1733 if (wnm_scan_process(wpa_s
, 1) > 0)
1734 goto scan_work_done
;
1736 if (sme_proc_obss_scan(wpa_s
) > 0)
1737 goto scan_work_done
;
1740 wpas_beacon_rep_scan_process(wpa_s
, scan_res
, &data
->scan_info
) > 0)
1741 goto scan_work_done
;
1743 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1744 goto scan_work_done
;
1746 if (autoscan_notify_scan(wpa_s
, scan_res
))
1747 goto scan_work_done
;
1749 if (wpa_s
->disconnected
) {
1750 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1751 goto scan_work_done
;
1754 if (!wpas_driver_bss_selection(wpa_s
) &&
1755 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1756 goto scan_work_done
;
1758 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1760 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1761 wpa_s
->wpa_state
< WPA_COMPLETED
)
1762 goto scan_work_done
;
1764 wpa_scan_results_free(scan_res
);
1766 if (own_request
&& wpa_s
->scan_work
) {
1767 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1768 wpa_s
->scan_work
= NULL
;
1769 radio_work_done(work
);
1772 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1775 wpa_scan_results_free(scan_res
);
1776 if (own_request
&& wpa_s
->scan_work
) {
1777 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1778 wpa_s
->scan_work
= NULL
;
1779 radio_work_done(work
);
1785 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1786 int new_scan
, int own_request
)
1788 struct wpa_bss
*selected
;
1789 struct wpa_ssid
*ssid
= NULL
;
1790 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1792 if (time_to_reenable
> 0) {
1793 wpa_dbg(wpa_s
, MSG_DEBUG
,
1794 "Postpone network selection by %d seconds since all networks are disabled",
1796 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1797 eloop_register_timeout(time_to_reenable
, 0,
1798 wpas_network_reenabled
, wpa_s
, NULL
);
1802 if (wpa_s
->p2p_mgmt
)
1803 return 0; /* no normal connection on p2p_mgmt interface */
1805 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1809 wpa_msg(wpa_s
, MSG_INFO
,
1810 "Avoiding join because we already joined a mesh group");
1813 #endif /* CONFIG_MESH */
1817 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1820 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1824 if (ssid
!= wpa_s
->current_ssid
&&
1825 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1826 wpa_s
->own_disconnect_req
= 1;
1827 wpa_supplicant_deauthenticate(
1828 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1831 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1832 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1836 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1838 * Do not allow other virtual radios to trigger operations based
1839 * on these scan results since we do not want them to start
1840 * other associations at the same time.
1844 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1845 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1847 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1848 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1850 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1851 } else if (own_request
) {
1853 * No SSID found. If SCAN results are as a result of
1854 * own scan request and not due to a scan request on
1855 * another shared interface, try another scan.
1857 int timeout_sec
= wpa_s
->scan_interval
;
1858 int timeout_usec
= 0;
1862 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1868 if (wpa_s
->p2p_in_provisioning
||
1869 wpa_s
->show_group_started
||
1870 wpa_s
->p2p_in_invitation
) {
1872 * Use shorter wait during P2P Provisioning
1873 * state and during P2P join-a-group operation
1874 * to speed up group formation.
1877 timeout_usec
= 250000;
1878 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1882 #endif /* CONFIG_P2P */
1883 #ifdef CONFIG_INTERWORKING
1884 if (wpa_s
->conf
->auto_interworking
&&
1885 wpa_s
->conf
->interworking
&&
1886 wpa_s
->conf
->cred
) {
1887 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1888 "start ANQP fetch since no matching "
1890 wpa_s
->network_select
= 1;
1891 wpa_s
->auto_network_select
= 1;
1892 interworking_start_fetch_anqp(wpa_s
);
1895 #endif /* CONFIG_INTERWORKING */
1897 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1898 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1900 timeout_usec
= 500000;
1901 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1905 #endif /* CONFIG_WPS */
1906 if (wpa_supplicant_req_sched_scan(wpa_s
))
1907 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1910 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1911 WPA_EVENT_NETWORK_NOT_FOUND
);
1918 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1919 union wpa_event_data
*data
)
1921 struct wpa_supplicant
*ifs
;
1924 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1, 0);
1927 * Interface may have been removed, so must not dereference
1935 * If no scan results could be fetched, then no need to
1936 * notify those interfaces that did not actually request
1937 * this scan. Similarly, if scan results started a new operation on this
1938 * interface, do not notify other interfaces to avoid concurrent
1939 * operations during a connection attempt.
1945 * Check other interfaces to see if they share the same radio. If
1946 * so, they get updated with this same scan info.
1948 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1951 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1952 "sibling", ifs
->ifname
);
1953 res
= _wpa_supplicant_event_scan_results(ifs
, data
, 0,
1963 #endif /* CONFIG_NO_SCAN_PROCESSING */
1966 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1968 #ifdef CONFIG_NO_SCAN_PROCESSING
1970 #else /* CONFIG_NO_SCAN_PROCESSING */
1971 struct os_reltime now
;
1973 wpa_s
->ignore_post_flush_scan_res
= 0;
1975 if (wpa_s
->last_scan_res_used
== 0)
1978 os_get_reltime(&now
);
1979 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1980 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1984 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1985 #endif /* CONFIG_NO_SCAN_PROCESSING */
1990 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1992 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1994 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1997 if (!wpa_s
->no_keep_alive
) {
1998 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1999 MAC2STR(wpa_s
->bssid
));
2000 /* TODO: could skip this if normal data traffic has been sent */
2001 /* TODO: Consider using some more appropriate data frame for
2004 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
2009 if (wpa_s
->sme
.bss_max_idle_period
) {
2011 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
2014 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2015 wnm_bss_keep_alive
, wpa_s
, NULL
);
2017 #endif /* CONFIG_SME */
2021 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2022 const u8
*ies
, size_t ies_len
)
2024 struct ieee802_11_elems elems
;
2029 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2033 if (elems
.bss_max_idle_period
) {
2035 wpa_s
->sme
.bss_max_idle_period
=
2036 WPA_GET_LE16(elems
.bss_max_idle_period
);
2037 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
2038 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
2039 (elems
.bss_max_idle_period
[2] & 0x01) ?
2040 " (protected keep-live required)" : "");
2041 if (wpa_s
->sme
.bss_max_idle_period
== 0)
2042 wpa_s
->sme
.bss_max_idle_period
= 1;
2043 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
2044 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2045 /* msec times 1000 */
2046 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
2049 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
2050 wnm_bss_keep_alive
, wpa_s
,
2054 #endif /* CONFIG_SME */
2057 #endif /* CONFIG_WNM */
2060 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
2063 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
2064 #endif /* CONFIG_WNM */
2068 #ifdef CONFIG_INTERWORKING
2070 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
2075 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
2076 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
2078 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
2085 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
2086 const u8
*ies
, size_t ies_len
)
2088 struct ieee802_11_elems elems
;
2093 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
2096 if (elems
.qos_map_set
) {
2097 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
2098 elems
.qos_map_set_len
);
2102 #endif /* CONFIG_INTERWORKING */
2106 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
2107 const u8
*ie
, size_t ie_len
)
2109 struct mb_ies_info mb_ies
;
2111 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
2114 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
2116 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
2121 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
2126 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
2127 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
2128 (unsigned int) len
);
2129 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
2130 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
2138 if (mb_ies
.nof_ies
> 0) {
2139 wpabuf_free(wpa_s
->received_mb_ies
);
2140 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
2146 #endif /* CONFIG_FST */
2149 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
2150 union wpa_event_data
*data
)
2152 int l
, len
, found
= 0, wpa_found
, rsn_found
;
2154 #ifdef CONFIG_IEEE80211R
2156 #endif /* CONFIG_IEEE80211R */
2158 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
2159 if (data
->assoc_info
.req_ies
)
2160 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
2161 data
->assoc_info
.req_ies_len
);
2162 if (data
->assoc_info
.resp_ies
) {
2163 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
2164 data
->assoc_info
.resp_ies_len
);
2166 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2167 data
->assoc_info
.resp_ies_len
);
2168 #endif /* CONFIG_TDLS */
2170 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2171 data
->assoc_info
.resp_ies_len
);
2172 #endif /* CONFIG_WNM */
2173 #ifdef CONFIG_INTERWORKING
2174 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2175 data
->assoc_info
.resp_ies_len
);
2176 #endif /* CONFIG_INTERWORKING */
2178 if (data
->assoc_info
.beacon_ies
)
2179 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2180 data
->assoc_info
.beacon_ies
,
2181 data
->assoc_info
.beacon_ies_len
);
2182 if (data
->assoc_info
.freq
)
2183 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2184 data
->assoc_info
.freq
);
2186 p
= data
->assoc_info
.req_ies
;
2187 l
= data
->assoc_info
.req_ies_len
;
2189 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2190 while (p
&& l
>= 2) {
2193 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2197 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2198 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2199 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2200 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2201 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2202 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2205 wpa_find_assoc_pmkid(wpa_s
);
2211 if (!found
&& data
->assoc_info
.req_ies
)
2212 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2216 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
&&
2217 (!data
->assoc_info
.resp_frame
||
2218 fils_process_assoc_resp(wpa_s
->wpa
,
2219 data
->assoc_info
.resp_frame
,
2220 data
->assoc_info
.resp_frame_len
) < 0)) {
2221 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2224 #endif /* CONFIG_SME */
2225 #endif /* CONFIG_FILS */
2227 #ifdef CONFIG_IEEE80211R
2229 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2230 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2231 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2232 data
->assoc_info
.resp_ies
,
2233 data
->assoc_info
.resp_ies_len
,
2235 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2236 "Reassociation Response failed");
2237 wpa_supplicant_deauthenticate(
2238 wpa_s
, WLAN_REASON_INVALID_IE
);
2243 p
= data
->assoc_info
.resp_ies
;
2244 l
= data
->assoc_info
.resp_ies_len
;
2246 #ifdef CONFIG_WPS_STRICT
2247 if (p
&& wpa_s
->current_ssid
&&
2248 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2250 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2252 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2253 "include WPS IE in (Re)Association Response");
2257 if (wps_validate_assoc_resp(wps
) < 0) {
2259 wpa_supplicant_deauthenticate(
2260 wpa_s
, WLAN_REASON_INVALID_IE
);
2265 #endif /* CONFIG_WPS_STRICT */
2267 /* Go through the IEs and make a copy of the MDIE, if present. */
2268 while (p
&& l
>= 2) {
2271 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2275 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2276 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2277 wpa_s
->sme
.ft_used
= 1;
2278 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2279 MOBILITY_DOMAIN_ID_LEN
);
2285 #endif /* CONFIG_SME */
2287 /* Process FT when SME is in the driver */
2288 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2289 wpa_ft_is_completed(wpa_s
->wpa
)) {
2290 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2291 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2292 data
->assoc_info
.resp_ies
,
2293 data
->assoc_info
.resp_ies_len
,
2295 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2296 "Reassociation Response failed");
2297 wpa_supplicant_deauthenticate(
2298 wpa_s
, WLAN_REASON_INVALID_IE
);
2301 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2304 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2305 data
->assoc_info
.resp_ies_len
);
2306 #endif /* CONFIG_IEEE80211R */
2308 /* WPA/RSN IE from Beacon/ProbeResp */
2309 p
= data
->assoc_info
.beacon_ies
;
2310 l
= data
->assoc_info
.beacon_ies_len
;
2312 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2314 wpa_found
= rsn_found
= 0;
2315 while (p
&& l
>= 2) {
2318 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2323 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2324 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2326 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2330 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2332 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2339 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2340 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2341 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2342 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2343 if (wpa_found
|| rsn_found
)
2344 wpa_s
->ap_ies_from_associnfo
= 1;
2346 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2347 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2348 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2350 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2351 wpa_supplicant_update_scan_results(wpa_s
);
2354 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2360 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2362 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2364 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2367 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2370 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2371 WPA_IE_VENDOR_TYPE
);
2372 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2374 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2375 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2376 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2377 bss_rsn
? 2 + bss_rsn
[1] : 0))
2384 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2385 union wpa_event_data
*data
)
2388 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2389 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2390 const u8
*ieprb
, *iebcn
;
2392 wpabuf_free(wpa_s
->received_mb_ies
);
2393 wpa_s
->received_mb_ies
= NULL
;
2396 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2397 wpa_printf(MSG_DEBUG
,
2398 "FST: MB IEs updated from Association Response frame");
2403 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2404 wpa_printf(MSG_DEBUG
,
2405 "FST: MB IEs updated from association event Beacon IEs");
2412 ieprb
= (const u8
*) (bss
+ 1);
2413 iebcn
= ieprb
+ bss
->ie_len
;
2415 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2416 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2417 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2418 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2419 #endif /* CONFIG_FST */
2423 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2424 union wpa_event_data
*data
)
2427 int ft_completed
, already_authorized
;
2431 if (wpa_s
->ap_iface
) {
2434 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2435 data
->assoc_info
.addr
,
2436 data
->assoc_info
.req_ies
,
2437 data
->assoc_info
.req_ies_len
,
2438 data
->assoc_info
.reassoc
);
2441 #endif /* CONFIG_AP */
2443 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2445 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2446 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2449 * FILS authentication can share the same mechanism to mark the
2450 * connection fully authenticated, so set ft_completed also based on
2454 ft_completed
= wpa_fils_is_completed(wpa_s
->wpa
);
2456 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2457 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2458 wpa_supplicant_deauthenticate(
2459 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2463 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2464 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2465 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2466 MACSTR
, MAC2STR(bssid
));
2468 random_add_randomness(bssid
, ETH_ALEN
);
2469 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2470 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2471 wpas_notify_bssid_changed(wpa_s
);
2473 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2474 wpa_clear_keys(wpa_s
, bssid
);
2476 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2477 wpa_supplicant_deauthenticate(
2478 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2483 if (wpa_s
->conf
->ap_scan
== 1 &&
2484 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2485 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2486 wpa_msg(wpa_s
, MSG_WARNING
,
2487 "WPA/RSN IEs not updated");
2490 wpas_fst_update_mb_assoc(wpa_s
, data
);
2493 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2494 wpa_s
->sme
.prev_bssid_set
= 1;
2495 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2496 #endif /* CONFIG_SME */
2498 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2499 if (wpa_s
->current_ssid
) {
2500 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2501 * initialized before association, but for other modes,
2502 * initialize PC/SC here, if the current configuration needs
2503 * smartcard or SIM/USIM. */
2504 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2506 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2508 l2_packet_notify_auth_start(wpa_s
->l2
);
2510 already_authorized
= data
&& data
->assoc_info
.authorized
;
2513 * Set portEnabled first to FALSE in order to get EAP state machine out
2514 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2515 * state machine may transit to AUTHENTICATING state based on obsolete
2516 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2517 * AUTHENTICATED without ever giving chance to EAP state machine to
2520 if (!ft_completed
&& !already_authorized
) {
2521 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2522 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2524 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
||
2526 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2527 /* 802.1X::portControl = Auto */
2528 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2529 wpa_s
->eapol_received
= 0;
2530 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2531 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2532 (wpa_s
->current_ssid
&&
2533 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2534 if (wpa_s
->current_ssid
&&
2535 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2537 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2539 * Set the key after having received joined-IBSS event
2542 wpa_supplicant_set_wpa_none_key(wpa_s
,
2543 wpa_s
->current_ssid
);
2545 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2546 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2547 } else if (!ft_completed
) {
2548 /* Timeout for receiving the first EAPOL packet */
2549 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2551 wpa_supplicant_cancel_scan(wpa_s
);
2553 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2554 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2556 * We are done; the driver will take care of RSN 4-way
2559 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2560 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2561 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2562 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2563 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2564 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2566 * The driver will take care of RSN 4-way handshake, so we need
2567 * to allow EAPOL supplicant to complete its work without
2568 * waiting for WPA supplicant.
2570 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2571 } else if (ft_completed
) {
2573 * FT protocol completed - make sure EAPOL state machine ends
2574 * up in authenticated.
2576 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2577 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2578 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2579 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2582 wpa_s
->last_eapol_matches_bssid
= 0;
2584 if (wpa_s
->pending_eapol_rx
) {
2585 struct os_reltime now
, age
;
2586 os_get_reltime(&now
);
2587 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2588 if (age
.sec
== 0 && age
.usec
< 100000 &&
2589 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2591 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2592 "frame that was received just before "
2593 "association notification");
2594 wpa_supplicant_rx_eapol(
2595 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2596 wpabuf_head(wpa_s
->pending_eapol_rx
),
2597 wpabuf_len(wpa_s
->pending_eapol_rx
));
2599 wpabuf_free(wpa_s
->pending_eapol_rx
);
2600 wpa_s
->pending_eapol_rx
= NULL
;
2603 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2604 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2605 wpa_s
->current_ssid
&&
2606 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2607 /* Set static WEP keys again */
2608 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2611 #ifdef CONFIG_IBSS_RSN
2612 if (wpa_s
->current_ssid
&&
2613 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2614 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2615 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2616 wpa_s
->ibss_rsn
== NULL
) {
2617 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2618 if (!wpa_s
->ibss_rsn
) {
2619 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2620 wpa_supplicant_deauthenticate(
2621 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2625 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2627 #endif /* CONFIG_IBSS_RSN */
2629 wpas_wps_notify_assoc(wpa_s
, bssid
);
2632 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2633 data
->assoc_info
.resp_ies_len
,
2634 &data
->assoc_info
.wmm_params
);
2636 if (wpa_s
->reassoc_same_bss
)
2637 wmm_ac_restore_tspecs(wpa_s
);
2642 static int disconnect_reason_recoverable(u16 reason_code
)
2644 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2645 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2646 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2650 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2652 int locally_generated
)
2656 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2658 * At least Host AP driver and a Prism3 card seemed to be
2659 * generating streams of disconnected events when configuring
2660 * IBSS for WPA-None. Ignore them for now.
2665 bssid
= wpa_s
->bssid
;
2666 if (is_zero_ether_addr(bssid
))
2667 bssid
= wpa_s
->pending_bssid
;
2669 if (!is_zero_ether_addr(bssid
) ||
2670 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2671 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2673 MAC2STR(bssid
), reason_code
,
2674 locally_generated
? " locally_generated=1" : "");
2679 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2680 int locally_generated
)
2682 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2683 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2684 return 0; /* Not in 4-way handshake with PSK */
2687 * It looks like connection was lost while trying to go through PSK
2688 * 4-way handshake. Filter out known disconnection cases that are caused
2689 * by something else than PSK mismatch to avoid confusing reports.
2692 if (locally_generated
) {
2693 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2701 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2703 int locally_generated
)
2707 u8 prev_pending_bssid
[ETH_ALEN
];
2708 struct wpa_bss
*fast_reconnect
= NULL
;
2709 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2710 struct wpa_ssid
*last_ssid
;
2711 struct wpa_bss
*curr
= NULL
;
2713 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2714 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2716 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2718 * At least Host AP driver and a Prism3 card seemed to be
2719 * generating streams of disconnected events when configuring
2720 * IBSS for WPA-None. Ignore them for now.
2722 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2723 "IBSS/WPA-None mode");
2727 if (!wpa_s
->disconnected
&& wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
2728 reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
&&
2731 * Remove the inactive AP (which is probably out of range) from
2732 * the BSS list after marking disassociation. In particular
2733 * mac80211-based drivers use the
2734 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
2735 * locally generated disconnection events for cases where the
2736 * AP does not reply anymore.
2738 curr
= wpa_s
->current_bss
;
2740 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2741 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2742 "pre-shared key may be incorrect");
2743 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2744 return; /* P2P group removed */
2745 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2747 if (!wpa_s
->disconnected
&&
2748 (!wpa_s
->auto_reconnect_disabled
||
2749 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2750 wpas_wps_searching(wpa_s
) ||
2751 wpas_wps_reenable_networks_pending(wpa_s
))) {
2752 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2753 "reconnect (wps=%d/%d wpa_state=%d)",
2754 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2755 wpas_wps_searching(wpa_s
),
2757 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2758 wpa_s
->current_ssid
&&
2759 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2760 !locally_generated
&&
2761 disconnect_reason_recoverable(reason_code
)) {
2763 * It looks like the AP has dropped association with
2764 * us, but could allow us to get back in. Try to
2765 * reconnect to the same BSS without full scan to save
2766 * time for some common cases.
2768 fast_reconnect
= wpa_s
->current_bss
;
2769 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2770 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2771 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2773 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2776 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2777 "try to re-connect");
2778 wpa_s
->reassociate
= 0;
2779 wpa_s
->disconnected
= 1;
2781 wpa_supplicant_cancel_sched_scan(wpa_s
);
2783 bssid
= wpa_s
->bssid
;
2784 if (is_zero_ether_addr(bssid
))
2785 bssid
= wpa_s
->pending_bssid
;
2786 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2787 wpas_connection_failed(wpa_s
, bssid
);
2788 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2789 if (locally_generated
)
2790 wpa_s
->disconnect_reason
= -reason_code
;
2792 wpa_s
->disconnect_reason
= reason_code
;
2793 wpas_notify_disconnect_reason(wpa_s
);
2794 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2795 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2796 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2798 last_ssid
= wpa_s
->current_ssid
;
2799 wpa_supplicant_mark_disassoc(wpa_s
);
2802 wpa_bss_remove(wpa_s
, curr
, "Connection to AP lost");
2804 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2805 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2806 wpa_s
->current_ssid
= last_ssid
;
2809 if (fast_reconnect
&&
2810 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2811 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2812 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2813 fast_reconnect
->ssid_len
) &&
2814 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2815 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2816 #ifndef CONFIG_NO_SCAN_PROCESSING
2817 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2818 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2819 fast_reconnect_ssid
) < 0) {
2820 /* Recover through full scan */
2821 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2823 #endif /* CONFIG_NO_SCAN_PROCESSING */
2824 } else if (fast_reconnect
) {
2826 * Could not reconnect to the same BSS due to network being
2827 * disabled. Use a new scan to match the alternative behavior
2828 * above, i.e., to continue automatic reconnection attempt in a
2829 * way that enforces disabled network rules.
2831 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2836 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2837 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2839 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2841 if (!wpa_s
->pending_mic_error_report
)
2844 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2845 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2846 wpa_s
->pending_mic_error_report
= 0;
2848 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2852 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2853 union wpa_event_data
*data
)
2856 struct os_reltime t
;
2858 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2859 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2861 if ((wpa_s
->last_michael_mic_error
.sec
&&
2862 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2863 wpa_s
->pending_mic_error_report
) {
2864 if (wpa_s
->pending_mic_error_report
) {
2866 * Send the pending MIC error report immediately since
2867 * we are going to start countermeasures and AP better
2870 wpa_sm_key_request(wpa_s
->wpa
, 1,
2871 wpa_s
->pending_mic_error_pairwise
);
2874 /* Send the new MIC error report immediately since we are going
2875 * to start countermeasures and AP better do the same.
2877 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2879 /* initialize countermeasures */
2880 wpa_s
->countermeasures
= 1;
2882 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2884 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2887 * Need to wait for completion of request frame. We do not get
2888 * any callback for the message completion, so just wait a
2889 * short while and hope for the best. */
2892 wpa_drv_set_countermeasures(wpa_s
, 1);
2893 wpa_supplicant_deauthenticate(wpa_s
,
2894 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2895 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2897 eloop_register_timeout(60, 0,
2898 wpa_supplicant_stop_countermeasures
,
2900 /* TODO: mark the AP rejected for 60 second. STA is
2901 * allowed to associate with another AP.. */
2903 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2904 if (wpa_s
->mic_errors_seen
) {
2906 * Reduce the effectiveness of Michael MIC error
2907 * reports as a means for attacking against TKIP if
2908 * more than one MIC failure is noticed with the same
2909 * PTK. We delay the transmission of the reports by a
2910 * random time between 0 and 60 seconds in order to
2911 * force the attacker wait 60 seconds before getting
2912 * the information on whether a frame resulted in a MIC
2918 if (os_get_random(rval
, sizeof(rval
)) < 0)
2919 sec
= os_random() % 60;
2921 sec
= WPA_GET_BE32(rval
) % 60;
2922 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2923 "report %d seconds", sec
);
2924 wpa_s
->pending_mic_error_report
= 1;
2925 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2926 eloop_cancel_timeout(
2927 wpa_supplicant_delayed_mic_error_report
,
2929 eloop_register_timeout(
2930 sec
, os_random() % 1000000,
2931 wpa_supplicant_delayed_mic_error_report
,
2934 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2936 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2937 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2938 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2940 wpa_s
->last_michael_mic_error
= t
;
2941 wpa_s
->mic_errors_seen
++;
2945 #ifdef CONFIG_TERMINATE_ONLASTIF
2946 static int any_interfaces(struct wpa_supplicant
*head
)
2948 struct wpa_supplicant
*wpa_s
;
2950 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2951 if (!wpa_s
->interface_removed
)
2955 #endif /* CONFIG_TERMINATE_ONLASTIF */
2959 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2960 union wpa_event_data
*data
)
2962 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2965 switch (data
->interface_status
.ievent
) {
2966 case EVENT_INTERFACE_ADDED
:
2967 if (!wpa_s
->interface_removed
)
2969 wpa_s
->interface_removed
= 0;
2970 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
2971 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
2972 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
2973 "driver after interface was added");
2977 if (!wpa_s
->global
->p2p
&&
2978 !wpa_s
->global
->p2p_disabled
&&
2979 !wpa_s
->conf
->p2p_disabled
&&
2981 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
2982 wpas_p2p_add_p2pdev_interface(
2983 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
2984 wpa_printf(MSG_INFO
,
2985 "P2P: Failed to enable P2P Device interface");
2986 /* Try to continue without. P2P will be disabled. */
2988 #endif /* CONFIG_P2P */
2991 case EVENT_INTERFACE_REMOVED
:
2992 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
2993 wpa_s
->interface_removed
= 1;
2994 wpa_supplicant_mark_disassoc(wpa_s
);
2995 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2996 l2_packet_deinit(wpa_s
->l2
);
3000 if (wpa_s
->global
->p2p
&&
3001 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
3003 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
3004 wpa_dbg(wpa_s
, MSG_DEBUG
,
3005 "Removing P2P Device interface");
3006 wpa_supplicant_remove_iface(
3007 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
3009 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
3011 #endif /* CONFIG_P2P */
3013 #ifdef CONFIG_MATCH_IFACE
3014 if (wpa_s
->matched
) {
3015 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
3018 #endif /* CONFIG_MATCH_IFACE */
3020 #ifdef CONFIG_TERMINATE_ONLASTIF
3021 /* check if last interface */
3022 if (!any_interfaces(wpa_s
->global
->ifaces
))
3024 #endif /* CONFIG_TERMINATE_ONLASTIF */
3030 #ifdef CONFIG_PEERKEY
3032 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
3033 union wpa_event_data
*data
)
3037 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
3039 #endif /* CONFIG_PEERKEY */
3043 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
3044 union wpa_event_data
*data
)
3048 switch (data
->tdls
.oper
) {
3049 case TDLS_REQUEST_SETUP
:
3050 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
3051 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3052 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
3054 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
3056 case TDLS_REQUEST_TEARDOWN
:
3057 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
3058 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
3059 data
->tdls
.reason_code
);
3061 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
3064 case TDLS_REQUEST_DISCOVER
:
3065 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
3070 #endif /* CONFIG_TDLS */
3074 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
3075 union wpa_event_data
*data
)
3079 switch (data
->wnm
.oper
) {
3080 case WNM_OPER_SLEEP
:
3081 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
3082 "(action=%d, intval=%d)",
3083 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
3084 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
3085 data
->wnm
.sleep_intval
, NULL
);
3089 #endif /* CONFIG_WNM */
3092 #ifdef CONFIG_IEEE80211R
3094 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
3095 union wpa_event_data
*data
)
3100 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
3101 data
->ft_ies
.ies_len
,
3102 data
->ft_ies
.ft_action
,
3103 data
->ft_ies
.target_ap
,
3104 data
->ft_ies
.ric_ies
,
3105 data
->ft_ies
.ric_ies_len
) < 0) {
3106 /* TODO: prevent MLME/driver from trying to associate? */
3109 #endif /* CONFIG_IEEE80211R */
3112 #ifdef CONFIG_IBSS_RSN
3113 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
3114 union wpa_event_data
*data
)
3116 struct wpa_ssid
*ssid
;
3117 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
3121 ssid
= wpa_s
->current_ssid
;
3124 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3127 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
3131 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
3132 union wpa_event_data
*data
)
3134 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3139 /* check if the ssid is correctly configured as IBSS/RSN */
3140 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
3143 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
3144 data
->rx_mgmt
.frame_len
);
3146 #endif /* CONFIG_IBSS_RSN */
3149 #ifdef CONFIG_IEEE80211R
3150 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
3153 const u8
*sta_addr
, *target_ap_addr
;
3156 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
3157 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
3158 return; /* only SME case supported for now */
3159 if (len
< 1 + 2 * ETH_ALEN
+ 2)
3162 return; /* Only FT Action Response is supported for now */
3163 sta_addr
= data
+ 1;
3164 target_ap_addr
= data
+ 1 + ETH_ALEN
;
3165 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
3166 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
3167 MACSTR
" TargetAP " MACSTR
" status %u",
3168 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
3170 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
3171 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
3172 " in FT Action Response", MAC2STR(sta_addr
));
3177 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
3178 "failure (status code %d)", status
);
3179 /* TODO: report error to FT code(?) */
3183 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
3184 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
3185 target_ap_addr
, NULL
, 0) < 0)
3190 struct wpa_bss
*bss
;
3191 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
3193 wpa_s
->sme
.freq
= bss
->freq
;
3194 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
3195 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
3198 #endif /* CONFIG_SME */
3200 #endif /* CONFIG_IEEE80211R */
3203 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
3204 struct unprot_deauth
*e
)
3206 #ifdef CONFIG_IEEE80211W
3207 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3208 "dropped: " MACSTR
" -> " MACSTR
3209 " (reason code %u)",
3210 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3211 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3212 #endif /* CONFIG_IEEE80211W */
3216 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3217 struct unprot_disassoc
*e
)
3219 #ifdef CONFIG_IEEE80211W
3220 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3221 "dropped: " MACSTR
" -> " MACSTR
3222 " (reason code %u)",
3223 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3224 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3225 #endif /* CONFIG_IEEE80211W */
3229 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3230 u16 reason_code
, int locally_generated
,
3231 const u8
*ie
, size_t ie_len
, int deauth
)
3234 if (wpa_s
->ap_iface
&& addr
) {
3235 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3239 if (wpa_s
->ap_iface
) {
3240 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3243 #endif /* CONFIG_AP */
3245 if (!locally_generated
)
3246 wpa_s
->own_disconnect_req
= 0;
3248 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3250 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3251 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3252 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3253 eapol_sm_failed(wpa_s
->eapol
))) &&
3254 !wpa_s
->eap_expected_failure
))
3255 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3258 if (deauth
&& reason_code
> 0) {
3259 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3260 locally_generated
) > 0) {
3262 * The interface was removed, so cannot continue
3263 * processing any additional operations after this.
3268 #endif /* CONFIG_P2P */
3270 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3275 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3276 struct disassoc_info
*info
)
3278 u16 reason_code
= 0;
3279 int locally_generated
= 0;
3280 const u8
*addr
= NULL
;
3281 const u8
*ie
= NULL
;
3284 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3289 ie_len
= info
->ie_len
;
3290 reason_code
= info
->reason_code
;
3291 locally_generated
= info
->locally_generated
;
3292 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3293 locally_generated
? " (locally generated)" : "");
3295 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3297 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3302 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3303 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3307 if (wpa_s
->ap_iface
) {
3308 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3311 #endif /* CONFIG_AP */
3315 wpas_p2p_disassoc_notif(
3316 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3319 #endif /* CONFIG_P2P */
3321 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3322 sme_event_disassoc(wpa_s
, info
);
3324 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3329 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3330 struct deauth_info
*info
)
3332 u16 reason_code
= 0;
3333 int locally_generated
= 0;
3334 const u8
*addr
= NULL
;
3335 const u8
*ie
= NULL
;
3338 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3343 ie_len
= info
->ie_len
;
3344 reason_code
= info
->reason_code
;
3345 locally_generated
= info
->locally_generated
;
3346 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3348 locally_generated
? " (locally generated)" : "");
3350 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3353 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3357 wpa_reset_ft_completed(wpa_s
->wpa
);
3359 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3360 locally_generated
, ie
, ie_len
, 1);
3364 static const char * reg_init_str(enum reg_change_initiator init
)
3367 case REGDOM_SET_BY_CORE
:
3369 case REGDOM_SET_BY_USER
:
3371 case REGDOM_SET_BY_DRIVER
:
3373 case REGDOM_SET_BY_COUNTRY_IE
:
3374 return "COUNTRY_IE";
3375 case REGDOM_BEACON_HINT
:
3376 return "BEACON_HINT";
3382 static const char * reg_type_str(enum reg_type type
)
3385 case REGDOM_TYPE_UNKNOWN
:
3387 case REGDOM_TYPE_COUNTRY
:
3389 case REGDOM_TYPE_WORLD
:
3391 case REGDOM_TYPE_CUSTOM_WORLD
:
3392 return "CUSTOM_WORLD";
3393 case REGDOM_TYPE_INTERSECTION
:
3394 return "INTERSECTION";
3400 static void wpa_supplicant_update_channel_list(
3401 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3403 struct wpa_supplicant
*ifs
;
3406 * To allow backwards compatibility with higher level layers that
3407 * assumed the REGDOM_CHANGE event is sent over the initially added
3408 * interface. Find the highest parent of this interface and use it to
3411 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3414 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3415 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3416 info
->alpha2
[0] ? " alpha2=" : "",
3417 info
->alpha2
[0] ? info
->alpha2
: "");
3419 if (wpa_s
->drv_priv
== NULL
)
3420 return; /* Ignore event during drv initialization */
3422 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3424 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3426 free_hw_features(ifs
);
3427 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3428 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
);
3430 /* Restart PNO/sched_scan with updated channel list */
3433 wpas_start_pno(ifs
);
3434 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3435 wpa_dbg(ifs
, MSG_DEBUG
,
3436 "Channel list changed - restart sched_scan");
3437 wpas_scan_restart_sched_scan(ifs
);
3441 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3445 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3446 const u8
*frame
, size_t len
, int freq
,
3449 const struct ieee80211_mgmt
*mgmt
;
3454 if (len
< IEEE80211_HDRLEN
+ 2)
3457 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3458 payload
= frame
+ IEEE80211_HDRLEN
;
3459 category
= *payload
++;
3460 plen
= len
- IEEE80211_HDRLEN
- 1;
3462 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3463 " Category=%u DataLen=%d freq=%d MHz",
3464 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3466 if (category
== WLAN_ACTION_WMM
) {
3467 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3471 #ifdef CONFIG_IEEE80211R
3472 if (category
== WLAN_ACTION_FT
) {
3473 ft_rx_action(wpa_s
, payload
, plen
);
3476 #endif /* CONFIG_IEEE80211R */
3478 #ifdef CONFIG_IEEE80211W
3480 if (category
== WLAN_ACTION_SA_QUERY
) {
3481 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3484 #endif /* CONFIG_SME */
3485 #endif /* CONFIG_IEEE80211W */
3488 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3489 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3492 #endif /* CONFIG_WNM */
3495 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3496 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3497 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3498 mgmt
->u
.action
.category
,
3499 payload
, plen
, freq
) == 0)
3501 #endif /* CONFIG_GAS */
3504 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3505 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3506 wpa_dbg(wpa_s
, MSG_DEBUG
,
3507 "TDLS: Received Discovery Response from " MACSTR
,
3511 #endif /* CONFIG_TDLS */
3513 #ifdef CONFIG_INTERWORKING
3514 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3515 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3516 const u8
*pos
= payload
+ 1;
3517 size_t qlen
= plen
- 1;
3518 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3519 MACSTR
, MAC2STR(mgmt
->sa
));
3520 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3521 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3522 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3523 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3526 #endif /* CONFIG_INTERWORKING */
3528 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3529 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3530 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3536 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3537 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3538 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3542 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3543 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3544 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3545 payload
+ 1, plen
- 1,
3551 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3552 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3555 #endif /* CONFIG_FST */
3557 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3558 category
, payload
, plen
, freq
);
3560 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3564 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3565 union wpa_event_data
*event
)
3567 struct wpa_freq_range_list
*list
;
3570 list
= &event
->freq_range
;
3573 str
= freq_range_list_str(list
);
3574 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3578 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3579 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3582 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3585 * The update channel flow will also take care of moving a GO
3586 * from the unsafe frequency if needed.
3588 wpas_p2p_update_channel_list(wpa_s
,
3589 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3591 #endif /* CONFIG_P2P */
3597 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3598 union wpa_event_data
*data
)
3600 wpa_dbg(wpa_s
, MSG_DEBUG
,
3601 "Connection authorized by device, previous state %d",
3603 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3604 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3605 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3606 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3607 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3609 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3610 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3611 data
->assoc_info
.ptk_kck_len
,
3612 data
->assoc_info
.ptk_kek
,
3613 data
->assoc_info
.ptk_kek_len
);
3617 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3618 union wpa_event_data
*data
)
3620 struct wpa_supplicant
*wpa_s
= ctx
;
3623 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3624 event
!= EVENT_INTERFACE_ENABLED
&&
3625 event
!= EVENT_INTERFACE_STATUS
&&
3626 event
!= EVENT_SCAN_RESULTS
&&
3627 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3628 wpa_dbg(wpa_s
, MSG_DEBUG
,
3629 "Ignore event %s (%d) while interface is disabled",
3630 event_to_string(event
), event
);
3634 #ifndef CONFIG_NO_STDOUT_DEBUG
3636 int level
= MSG_DEBUG
;
3638 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3639 const struct ieee80211_hdr
*hdr
;
3641 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3642 fc
= le_to_host16(hdr
->frame_control
);
3643 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3644 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3645 level
= MSG_EXCESSIVE
;
3648 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3649 event_to_string(event
), event
);
3651 #endif /* CONFIG_NO_STDOUT_DEBUG */
3656 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3657 data
->auth
.ies_len
))
3658 wpa_printf(MSG_DEBUG
,
3659 "FST: MB IEs updated from auth IE");
3660 #endif /* CONFIG_FST */
3661 sme_event_auth(wpa_s
, data
);
3664 #ifdef CONFIG_TESTING_OPTIONS
3665 if (wpa_s
->ignore_auth_resp
) {
3666 wpa_printf(MSG_INFO
,
3667 "EVENT_ASSOC - ignore_auth_resp active!");
3670 #endif /* CONFIG_TESTING_OPTIONS */
3671 wpa_supplicant_event_assoc(wpa_s
, data
);
3672 if (data
&& data
->assoc_info
.authorized
)
3673 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3675 wpa_msg(wpa_s
, MSG_INFO
,
3676 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3677 data
->assoc_info
.subnet_status
);
3680 case EVENT_DISASSOC
:
3681 wpas_event_disassoc(wpa_s
,
3682 data
? &data
->disassoc_info
: NULL
);
3685 #ifdef CONFIG_TESTING_OPTIONS
3686 if (wpa_s
->ignore_auth_resp
) {
3687 wpa_printf(MSG_INFO
,
3688 "EVENT_DEAUTH - ignore_auth_resp active!");
3691 #endif /* CONFIG_TESTING_OPTIONS */
3692 wpas_event_deauth(wpa_s
,
3693 data
? &data
->deauth_info
: NULL
);
3695 case EVENT_MICHAEL_MIC_FAILURE
:
3696 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3698 #ifndef CONFIG_NO_SCAN_PROCESSING
3699 case EVENT_SCAN_STARTED
:
3700 if (wpa_s
->own_scan_requested
||
3701 (data
&& !data
->scan_info
.external_scan
)) {
3702 struct os_reltime diff
;
3704 os_get_reltime(&wpa_s
->scan_start_time
);
3705 os_reltime_sub(&wpa_s
->scan_start_time
,
3706 &wpa_s
->scan_trigger_time
, &diff
);
3707 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3708 diff
.sec
, diff
.usec
);
3709 wpa_s
->own_scan_requested
= 0;
3710 wpa_s
->own_scan_running
= 1;
3711 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3712 wpa_s
->manual_scan_use_id
) {
3713 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3714 WPA_EVENT_SCAN_STARTED
"id=%u",
3715 wpa_s
->manual_scan_id
);
3717 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3718 WPA_EVENT_SCAN_STARTED
);
3721 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3722 wpa_s
->radio
->external_scan_running
= 1;
3723 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3726 case EVENT_SCAN_RESULTS
:
3727 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3728 wpa_s
->scan_res_handler
= NULL
;
3729 wpa_s
->own_scan_running
= 0;
3730 wpa_s
->radio
->external_scan_running
= 0;
3731 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3735 if (!(data
&& data
->scan_info
.external_scan
) &&
3736 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3737 struct os_reltime now
, diff
;
3738 os_get_reltime(&now
);
3739 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3740 wpa_s
->scan_start_time
.sec
= 0;
3741 wpa_s
->scan_start_time
.usec
= 0;
3742 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3743 diff
.sec
, diff
.usec
);
3745 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3746 break; /* interface may have been removed */
3747 if (!(data
&& data
->scan_info
.external_scan
))
3748 wpa_s
->own_scan_running
= 0;
3749 if (data
&& data
->scan_info
.nl_scan_event
)
3750 wpa_s
->radio
->external_scan_running
= 0;
3751 radio_work_check_next(wpa_s
);
3753 #endif /* CONFIG_NO_SCAN_PROCESSING */
3754 case EVENT_ASSOCINFO
:
3755 wpa_supplicant_event_associnfo(wpa_s
, data
);
3757 case EVENT_INTERFACE_STATUS
:
3758 wpa_supplicant_event_interface_status(wpa_s
, data
);
3760 case EVENT_PMKID_CANDIDATE
:
3761 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3763 #ifdef CONFIG_PEERKEY
3764 case EVENT_STKSTART
:
3765 wpa_supplicant_event_stkstart(wpa_s
, data
);
3767 #endif /* CONFIG_PEERKEY */
3770 wpa_supplicant_event_tdls(wpa_s
, data
);
3772 #endif /* CONFIG_TDLS */
3775 wpa_supplicant_event_wnm(wpa_s
, data
);
3777 #endif /* CONFIG_WNM */
3778 #ifdef CONFIG_IEEE80211R
3779 case EVENT_FT_RESPONSE
:
3780 wpa_supplicant_event_ft_response(wpa_s
, data
);
3782 #endif /* CONFIG_IEEE80211R */
3783 #ifdef CONFIG_IBSS_RSN
3784 case EVENT_IBSS_RSN_START
:
3785 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3787 #endif /* CONFIG_IBSS_RSN */
3788 case EVENT_ASSOC_REJECT
:
3789 if (data
->assoc_reject
.bssid
)
3790 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3791 "bssid=" MACSTR
" status_code=%u%s",
3792 MAC2STR(data
->assoc_reject
.bssid
),
3793 data
->assoc_reject
.status_code
,
3794 data
->assoc_reject
.timed_out
? " timeout" : "");
3796 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3798 data
->assoc_reject
.status_code
,
3799 data
->assoc_reject
.timed_out
? " timeout" : "");
3800 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3801 wpas_notify_assoc_status_code(wpa_s
);
3802 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3803 sme_event_assoc_reject(wpa_s
, data
);
3805 const u8
*bssid
= data
->assoc_reject
.bssid
;
3806 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
3807 bssid
= wpa_s
->pending_bssid
;
3808 wpas_connection_failed(wpa_s
, bssid
);
3809 wpa_supplicant_mark_disassoc(wpa_s
);
3812 case EVENT_AUTH_TIMED_OUT
:
3813 /* It is possible to get this event from earlier connection */
3814 if (wpa_s
->current_ssid
&&
3815 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3816 wpa_dbg(wpa_s
, MSG_DEBUG
,
3817 "Ignore AUTH_TIMED_OUT in mesh configuration");
3820 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3821 sme_event_auth_timed_out(wpa_s
, data
);
3823 case EVENT_ASSOC_TIMED_OUT
:
3824 /* It is possible to get this event from earlier connection */
3825 if (wpa_s
->current_ssid
&&
3826 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3827 wpa_dbg(wpa_s
, MSG_DEBUG
,
3828 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3831 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3832 sme_event_assoc_timed_out(wpa_s
, data
);
3834 case EVENT_TX_STATUS
:
3835 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3836 " type=%d stype=%d",
3837 MAC2STR(data
->tx_status
.dst
),
3838 data
->tx_status
.type
, data
->tx_status
.stype
);
3840 if (wpa_s
->ap_iface
== NULL
) {
3841 #ifdef CONFIG_OFFCHANNEL
3842 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3843 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3844 offchannel_send_action_tx_status(
3845 wpa_s
, data
->tx_status
.dst
,
3846 data
->tx_status
.data
,
3847 data
->tx_status
.data_len
,
3848 data
->tx_status
.ack
?
3849 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3850 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3851 #endif /* CONFIG_OFFCHANNEL */
3854 #endif /* CONFIG_AP */
3855 #ifdef CONFIG_OFFCHANNEL
3856 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3857 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
3859 * Catch TX status events for Action frames we sent via group
3860 * interface in GO mode, or via standalone AP interface.
3861 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3862 * except when the primary interface is used as a GO interface
3863 * (for drivers which do not have group interface concurrency)
3865 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3866 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3867 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
3868 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3869 offchannel_send_action_tx_status(
3870 wpa_s
->p2pdev
, data
->tx_status
.dst
,
3871 data
->tx_status
.data
,
3872 data
->tx_status
.data_len
,
3873 data
->tx_status
.ack
?
3874 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3875 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3878 #endif /* CONFIG_OFFCHANNEL */
3880 switch (data
->tx_status
.type
) {
3881 case WLAN_FC_TYPE_MGMT
:
3882 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3883 data
->tx_status
.data_len
,
3884 data
->tx_status
.stype
,
3885 data
->tx_status
.ack
);
3887 case WLAN_FC_TYPE_DATA
:
3888 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3889 data
->tx_status
.data
,
3890 data
->tx_status
.data_len
,
3891 data
->tx_status
.ack
);
3894 #endif /* CONFIG_AP */
3897 case EVENT_EAPOL_TX_STATUS
:
3898 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3899 data
->eapol_tx_status
.data
,
3900 data
->eapol_tx_status
.data_len
,
3901 data
->eapol_tx_status
.ack
);
3903 case EVENT_DRIVER_CLIENT_POLL_OK
:
3904 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
3906 case EVENT_RX_FROM_UNKNOWN
:
3907 if (wpa_s
->ap_iface
== NULL
)
3909 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
3910 data
->rx_from_unknown
.wds
);
3912 case EVENT_CH_SWITCH
:
3913 if (!data
|| !wpa_s
->current_ssid
)
3916 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
3917 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
3918 data
->ch_switch
.freq
,
3919 data
->ch_switch
.ht_enabled
,
3920 data
->ch_switch
.ch_offset
,
3921 channel_width_to_string(data
->ch_switch
.ch_width
),
3922 data
->ch_switch
.cf1
,
3923 data
->ch_switch
.cf2
);
3925 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
3926 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
3928 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
3929 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
3930 wpa_s
->current_ssid
->mode
==
3931 WPAS_MODE_P2P_GROUP_FORMATION
) {
3932 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
3933 data
->ch_switch
.ht_enabled
,
3934 data
->ch_switch
.ch_offset
,
3935 data
->ch_switch
.ch_width
,
3936 data
->ch_switch
.cf1
,
3937 data
->ch_switch
.cf2
);
3940 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
3943 case EVENT_DFS_RADAR_DETECTED
:
3945 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
3947 case EVENT_DFS_CAC_STARTED
:
3949 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
3951 case EVENT_DFS_CAC_FINISHED
:
3953 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
3955 case EVENT_DFS_CAC_ABORTED
:
3957 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
3959 case EVENT_DFS_NOP_FINISHED
:
3961 wpas_event_dfs_cac_nop_finished(wpa_s
,
3964 #endif /* NEED_AP_MLME */
3965 #endif /* CONFIG_AP */
3966 case EVENT_RX_MGMT
: {
3968 const struct ieee80211_mgmt
*mgmt
;
3970 #ifdef CONFIG_TESTING_OPTIONS
3971 if (wpa_s
->ext_mgmt_frame_handling
) {
3972 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
3973 size_t hex_len
= 2 * rx
->frame_len
+ 1;
3974 char *hex
= os_malloc(hex_len
);
3976 wpa_snprintf_hex(hex
, hex_len
,
3977 rx
->frame
, rx
->frame_len
);
3978 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3979 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
3985 #endif /* CONFIG_TESTING_OPTIONS */
3987 mgmt
= (const struct ieee80211_mgmt
*)
3988 data
->rx_mgmt
.frame
;
3989 fc
= le_to_host16(mgmt
->frame_control
);
3990 stype
= WLAN_FC_GET_STYPE(fc
);
3993 if (wpa_s
->ap_iface
== NULL
) {
3994 #endif /* CONFIG_AP */
3996 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3997 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
3998 const u8
*src
= mgmt
->sa
;
4002 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4003 ie_len
= data
->rx_mgmt
.frame_len
-
4005 wpas_p2p_probe_req_rx(
4006 wpa_s
, src
, mgmt
->da
,
4007 mgmt
->bssid
, ie
, ie_len
,
4009 data
->rx_mgmt
.ssi_signal
);
4012 #endif /* CONFIG_P2P */
4013 #ifdef CONFIG_IBSS_RSN
4014 if (wpa_s
->current_ssid
&&
4015 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
4016 stype
== WLAN_FC_STYPE_AUTH
&&
4017 data
->rx_mgmt
.frame_len
>= 30) {
4018 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
4021 #endif /* CONFIG_IBSS_RSN */
4023 if (stype
== WLAN_FC_STYPE_ACTION
) {
4024 wpas_event_rx_mgmt_action(
4025 wpa_s
, data
->rx_mgmt
.frame
,
4026 data
->rx_mgmt
.frame_len
,
4028 data
->rx_mgmt
.ssi_signal
);
4033 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4037 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
4038 "management frame in non-AP mode");
4043 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
4044 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
4048 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
4049 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
4051 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
4052 mgmt
->bssid
, ie
, ie_len
,
4053 data
->rx_mgmt
.ssi_signal
);
4056 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
4057 #endif /* CONFIG_AP */
4060 case EVENT_RX_PROBE_REQ
:
4061 if (data
->rx_probe_req
.sa
== NULL
||
4062 data
->rx_probe_req
.ie
== NULL
)
4065 if (wpa_s
->ap_iface
) {
4066 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
4067 data
->rx_probe_req
.sa
,
4068 data
->rx_probe_req
.da
,
4069 data
->rx_probe_req
.bssid
,
4070 data
->rx_probe_req
.ie
,
4071 data
->rx_probe_req
.ie_len
,
4072 data
->rx_probe_req
.ssi_signal
);
4075 #endif /* CONFIG_AP */
4076 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
4077 data
->rx_probe_req
.da
,
4078 data
->rx_probe_req
.bssid
,
4079 data
->rx_probe_req
.ie
,
4080 data
->rx_probe_req
.ie_len
,
4082 data
->rx_probe_req
.ssi_signal
);
4084 case EVENT_REMAIN_ON_CHANNEL
:
4085 #ifdef CONFIG_OFFCHANNEL
4086 offchannel_remain_on_channel_cb(
4087 wpa_s
, data
->remain_on_channel
.freq
,
4088 data
->remain_on_channel
.duration
);
4089 #endif /* CONFIG_OFFCHANNEL */
4090 wpas_p2p_remain_on_channel_cb(
4091 wpa_s
, data
->remain_on_channel
.freq
,
4092 data
->remain_on_channel
.duration
);
4094 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
4095 #ifdef CONFIG_OFFCHANNEL
4096 offchannel_cancel_remain_on_channel_cb(
4097 wpa_s
, data
->remain_on_channel
.freq
);
4098 #endif /* CONFIG_OFFCHANNEL */
4099 wpas_p2p_cancel_remain_on_channel_cb(
4100 wpa_s
, data
->remain_on_channel
.freq
);
4102 case EVENT_EAPOL_RX
:
4103 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
4104 data
->eapol_rx
.data
,
4105 data
->eapol_rx
.data_len
);
4107 case EVENT_SIGNAL_CHANGE
:
4108 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
4109 "above=%d signal=%d noise=%d txrate=%d",
4110 data
->signal_change
.above_threshold
,
4111 data
->signal_change
.current_signal
,
4112 data
->signal_change
.current_noise
,
4113 data
->signal_change
.current_txrate
);
4114 wpa_bss_update_level(wpa_s
->current_bss
,
4115 data
->signal_change
.current_signal
);
4116 bgscan_notify_signal_change(
4117 wpa_s
, data
->signal_change
.above_threshold
,
4118 data
->signal_change
.current_signal
,
4119 data
->signal_change
.current_noise
,
4120 data
->signal_change
.current_txrate
);
4122 case EVENT_INTERFACE_ENABLED
:
4123 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
4124 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4125 wpa_supplicant_update_mac_addr(wpa_s
);
4126 if (wpa_s
->p2p_mgmt
) {
4127 wpa_supplicant_set_state(wpa_s
,
4133 if (!wpa_s
->ap_iface
) {
4134 wpa_supplicant_set_state(wpa_s
,
4136 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4137 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4139 wpa_supplicant_set_state(wpa_s
,
4141 #else /* CONFIG_AP */
4142 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4143 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4144 #endif /* CONFIG_AP */
4147 case EVENT_INTERFACE_DISABLED
:
4148 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
4150 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
4151 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
4152 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4154 * Mark interface disabled if this happens to end up not
4155 * being removed as a separate P2P group interface.
4157 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4159 * The interface was externally disabled. Remove
4160 * it assuming an external entity will start a
4161 * new session if needed.
4163 if (wpa_s
->current_ssid
&&
4164 wpa_s
->current_ssid
->p2p_group
)
4165 wpas_p2p_interface_unavailable(wpa_s
);
4167 wpas_p2p_disconnect(wpa_s
);
4169 * wpa_s instance may have been freed, so must not use
4174 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
4175 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
4176 /* This radio work will be cancelled, so clear P2P
4179 p2p_stop_find(wpa_s
->global
->p2p
);
4181 #endif /* CONFIG_P2P */
4183 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
4185 * Indicate disconnection to keep ctrl_iface events
4188 wpa_supplicant_event_disassoc(
4189 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
4191 wpa_supplicant_mark_disassoc(wpa_s
);
4192 wpa_bss_flush(wpa_s
);
4193 radio_remove_works(wpa_s
, NULL
, 0);
4195 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
4197 case EVENT_CHANNEL_LIST_CHANGED
:
4198 wpa_supplicant_update_channel_list(
4199 wpa_s
, &data
->channel_list_changed
);
4201 case EVENT_INTERFACE_UNAVAILABLE
:
4202 wpas_p2p_interface_unavailable(wpa_s
);
4204 case EVENT_BEST_CHANNEL
:
4205 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4207 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4208 data
->best_chan
.freq_overall
);
4209 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4210 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4211 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4212 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4213 data
->best_chan
.freq_5
,
4214 data
->best_chan
.freq_overall
);
4216 case EVENT_UNPROT_DEAUTH
:
4217 wpa_supplicant_event_unprot_deauth(wpa_s
,
4218 &data
->unprot_deauth
);
4220 case EVENT_UNPROT_DISASSOC
:
4221 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4222 &data
->unprot_disassoc
);
4224 case EVENT_STATION_LOW_ACK
:
4226 if (wpa_s
->ap_iface
&& data
)
4227 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4228 data
->low_ack
.addr
);
4229 #endif /* CONFIG_AP */
4232 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4233 data
->low_ack
.addr
);
4234 #endif /* CONFIG_TDLS */
4236 case EVENT_IBSS_PEER_LOST
:
4237 #ifdef CONFIG_IBSS_RSN
4238 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4239 #endif /* CONFIG_IBSS_RSN */
4241 case EVENT_DRIVER_GTK_REKEY
:
4242 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4243 wpa_s
->bssid
, ETH_ALEN
))
4247 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4248 data
->driver_gtk_rekey
.replay_ctr
);
4250 case EVENT_SCHED_SCAN_STOPPED
:
4251 wpa_s
->sched_scanning
= 0;
4252 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4253 wpa_supplicant_notify_scanning(wpa_s
, 0);
4255 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4259 * If the driver stopped scanning without being requested to,
4260 * request a new scan to continue scanning for networks.
4262 if (!wpa_s
->sched_scan_stop_req
&&
4263 wpa_s
->wpa_state
== WPA_SCANNING
) {
4264 wpa_dbg(wpa_s
, MSG_DEBUG
,
4265 "Restart scanning after unexpected sched_scan stop event");
4266 wpa_supplicant_req_scan(wpa_s
, 1, 0);
4270 wpa_s
->sched_scan_stop_req
= 0;
4273 * Start a new sched scan to continue searching for more SSIDs
4274 * either if timed out or PNO schedule scan is pending.
4276 if (wpa_s
->sched_scan_timed_out
) {
4277 wpa_supplicant_req_sched_scan(wpa_s
);
4278 } else if (wpa_s
->pno_sched_pending
) {
4279 wpa_s
->pno_sched_pending
= 0;
4280 wpas_start_pno(wpa_s
);
4281 } else if (resched
) {
4282 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4286 case EVENT_WPS_BUTTON_PUSHED
:
4288 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4289 #endif /* CONFIG_WPS */
4291 case EVENT_AVOID_FREQUENCIES
:
4292 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4294 case EVENT_CONNECT_FAILED_REASON
:
4296 if (!wpa_s
->ap_iface
|| !data
)
4298 hostapd_event_connect_failed_reason(
4299 wpa_s
->ap_iface
->bss
[0],
4300 data
->connect_failed_reason
.addr
,
4301 data
->connect_failed_reason
.code
);
4302 #endif /* CONFIG_AP */
4304 case EVENT_NEW_PEER_CANDIDATE
:
4306 if (!wpa_s
->ifmsh
|| !data
)
4308 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4309 data
->mesh_peer
.ies
,
4310 data
->mesh_peer
.ie_len
);
4311 #endif /* CONFIG_MESH */
4315 if (!wpa_s
->ap_iface
)
4317 hostapd_event_get_survey(wpa_s
->ap_iface
,
4318 &data
->survey_results
);
4319 #endif /* CONFIG_AP */
4321 case EVENT_ACS_CHANNEL_SELECTED
:
4324 if (!wpa_s
->ap_iface
)
4326 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4327 &data
->acs_selected_channels
);
4328 #endif /* CONFIG_ACS */
4329 #endif /* CONFIG_AP */
4331 case EVENT_P2P_LO_STOP
:
4333 wpa_s
->p2p_lo_started
= 0;
4334 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4335 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4336 data
->p2p_lo_stop
.reason_code
);
4337 #endif /* CONFIG_P2P */
4339 case EVENT_BEACON_LOSS
:
4340 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
4342 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_BEACON_LOSS
);
4343 bgscan_notify_beacon_loss(wpa_s
);
4346 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4352 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4353 union wpa_event_data
*data
)
4355 struct wpa_supplicant
*wpa_s
;
4357 if (event
!= EVENT_INTERFACE_STATUS
)
4360 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4361 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4362 unsigned int ifindex
;
4364 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4365 if (ifindex
!= data
->interface_status
.ifindex
) {
4366 wpa_dbg(wpa_s
, MSG_DEBUG
,
4367 "interface status ifindex %d mismatch (%d)",
4368 ifindex
, data
->interface_status
.ifindex
);
4372 #ifdef CONFIG_MATCH_IFACE
4373 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4374 struct wpa_interface
*wpa_i
;
4376 wpa_i
= wpa_supplicant_match_iface(
4377 ctx
, data
->interface_status
.ifname
);
4380 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4385 #endif /* CONFIG_MATCH_IFACE */
4388 wpa_supplicant_event(wpa_s
, event
, data
);