2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, 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
,
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
)) {
529 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
535 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
537 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
542 if (!(ie
.proto
& ssid
->proto
)) {
543 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
548 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
549 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
554 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
555 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
560 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
561 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
566 #ifdef CONFIG_IEEE80211W
567 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
568 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
569 MGMT_FRAME_PROTECTION_REQUIRED
) {
570 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
574 #endif /* CONFIG_IEEE80211W */
575 if ((ie
.capabilities
& WPA_CAPABILITY_MFPR
) &&
576 wpas_get_ssid_pmf(wpa_s
, ssid
) ==
577 NO_MGMT_FRAME_PROTECTION
) {
578 wpa_dbg(wpa_s
, MSG_DEBUG
,
579 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
583 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
584 wpas_mbo_get_bss_attr(bss
, MBO_ATTR_ID_AP_CAPA_IND
) &&
585 wpas_get_ssid_pmf(wpa_s
, ssid
) !=
586 NO_MGMT_FRAME_PROTECTION
) {
587 wpa_dbg(wpa_s
, MSG_DEBUG
,
588 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
591 #endif /* CONFIG_MBO */
593 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
597 #ifdef CONFIG_IEEE80211W
598 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
599 wpa_dbg(wpa_s
, MSG_DEBUG
,
600 " skip - MFP Required but network not MFP Capable");
603 #endif /* CONFIG_IEEE80211W */
605 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
606 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
609 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
610 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
616 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
618 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
623 if (!(ie
.proto
& ssid
->proto
)) {
624 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
629 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
630 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
635 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
636 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
641 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
642 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
647 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
651 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
653 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow for non-WPA IEEE 802.1X");
657 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
658 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
659 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
663 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) &&
664 wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
)) {
665 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in OSEN");
669 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
670 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
674 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
681 static int freq_allowed(int *freqs
, int freq
)
688 for (i
= 0; freqs
[i
]; i
++)
689 if (freqs
[i
] == freq
)
695 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
697 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
698 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
703 return 1; /* Cannot do matching without knowing band */
705 modes
= wpa_s
->hw
.modes
;
708 * The driver does not provide any additional information
709 * about the utilized hardware, so allow the connection attempt
715 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
716 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
717 int freq
= modes
[i
].channels
[j
].freq
;
718 if (freq
== bss
->freq
) {
720 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
721 break; /* do not allow 802.11b replace
732 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
733 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
737 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
738 int flagged
= !!(rate_ie
[j
] & 0x80);
739 int r
= (rate_ie
[j
] & 0x7f) * 5;
742 * IEEE Std 802.11n-2009 7.3.2.2:
743 * The new BSS Membership selector value is encoded
744 * like a legacy basic rate, but it is not a rate and
745 * only indicates if the BSS members are required to
746 * support the mandatory features of Clause 20 [HT PHY]
747 * in order to join the BSS.
749 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
750 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
751 if (!ht_supported(mode
)) {
752 wpa_dbg(wpa_s
, MSG_DEBUG
,
753 " hardware does not support "
760 /* There's also a VHT selector for 802.11ac */
761 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
762 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
763 if (!vht_supported(mode
)) {
764 wpa_dbg(wpa_s
, MSG_DEBUG
,
765 " hardware does not support "
775 /* check for legacy basic rates */
776 for (k
= 0; k
< mode
->num_rates
; k
++) {
777 if (mode
->rates
[k
] == r
)
780 if (k
== mode
->num_rates
) {
782 * IEEE Std 802.11-2007 7.3.2.2 demands that in
783 * order to join a BSS all required rates
784 * have to be supported by the hardware.
786 wpa_dbg(wpa_s
, MSG_DEBUG
,
787 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
789 bss
->freq
, mode
->mode
, mode
->num_rates
);
800 * Test whether BSS is in an ESS.
801 * This is done differently in DMG (60 GHz) and non-DMG bands
803 static int bss_is_ess(struct wpa_bss
*bss
)
805 if (bss_is_dmg(bss
)) {
806 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
807 IEEE80211_CAP_DMG_AP
;
810 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
815 static int match_mac_mask(const u8
*addr_a
, const u8
*addr_b
, const u8
*mask
)
819 for (i
= 0; i
< ETH_ALEN
; i
++) {
820 if ((addr_a
[i
] & mask
[i
]) != (addr_b
[i
] & mask
[i
]))
827 static int addr_in_list(const u8
*addr
, const u8
*list
, size_t num
)
831 for (i
= 0; i
< num
; i
++) {
832 const u8
*a
= list
+ i
* ETH_ALEN
* 2;
833 const u8
*m
= a
+ ETH_ALEN
;
835 if (match_mac_mask(a
, addr
, m
))
842 struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
843 int i
, struct wpa_bss
*bss
,
844 struct wpa_ssid
*group
,
847 u8 wpa_ie_len
, rsn_ie_len
;
849 struct wpa_blacklist
*e
;
851 struct wpa_ssid
*ssid
;
854 const u8
*assoc_disallow
;
855 #endif /* CONFIG_MBO */
857 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
858 wpa_ie_len
= ie
? ie
[1] : 0;
860 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
861 rsn_ie_len
= ie
? ie
[1] : 0;
863 ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
866 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
867 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
868 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
869 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
, bss
->freq
,
870 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "",
871 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
872 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) ?
874 osen
? " osen=1" : "");
876 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
879 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
881 * When only a single network is enabled, we can
882 * trigger blacklisting on the first failure. This
883 * should not be done with multiple enabled networks to
884 * avoid getting forced to move into a worse ESS on
885 * single error if there are no other BSSes of the
890 if (e
->count
> limit
) {
891 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
892 "(count=%d limit=%d)", e
->count
, limit
);
897 if (bss
->ssid_len
== 0) {
898 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
902 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
903 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
907 if (disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
908 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
912 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
914 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
915 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
918 if (wpas_network_disabled(wpa_s
, ssid
)) {
919 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
923 res
= wpas_temp_disabled(wpa_s
, ssid
);
925 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled "
926 "temporarily for %d second(s)", res
);
931 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
932 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
937 if (wpa
&& ssid
->ssid_len
== 0 &&
938 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
941 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
942 /* Only allow wildcard SSID match if an AP
943 * advertises active WPS operation that matches
946 if (ssid
->ssid_len
== 0 &&
947 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
950 #endif /* CONFIG_WPS */
952 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
953 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
957 (bss
->ssid_len
!= ssid
->ssid_len
||
958 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
959 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
963 if (ssid
->bssid_set
&&
964 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
965 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
969 /* check blacklist */
970 if (ssid
->num_bssid_blacklist
&&
971 addr_in_list(bss
->bssid
, ssid
->bssid_blacklist
,
972 ssid
->num_bssid_blacklist
)) {
973 wpa_dbg(wpa_s
, MSG_DEBUG
,
974 " skip - BSSID blacklisted");
978 /* if there is a whitelist, only accept those APs */
979 if (ssid
->num_bssid_whitelist
&&
980 !addr_in_list(bss
->bssid
, ssid
->bssid_whitelist
,
981 ssid
->num_bssid_whitelist
)) {
982 wpa_dbg(wpa_s
, MSG_DEBUG
,
983 " skip - BSSID not in whitelist");
987 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
991 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
992 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
993 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
994 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
999 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
1000 has_wep_key(ssid
)) {
1001 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - ignore WPA/WPA2 AP for WEP network block");
1005 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
) && !osen
) {
1006 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-OSEN network "
1011 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
1012 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
1017 if (ssid
->mode
!= IEEE80211_MODE_MESH
&& !bss_is_ess(bss
) &&
1018 !bss_is_pbss(bss
)) {
1019 wpa_dbg(wpa_s
, MSG_DEBUG
,
1020 " skip - not ESS, PBSS, or MBSS");
1024 if (ssid
->pbss
!= 2 && ssid
->pbss
!= bss_is_pbss(bss
)) {
1025 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - PBSS mismatch (ssid %d bss %d)",
1026 ssid
->pbss
, bss_is_pbss(bss
));
1030 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
1031 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
1037 if (ssid
->mode
== IEEE80211_MODE_MESH
&& ssid
->frequency
> 0 &&
1038 ssid
->frequency
!= bss
->freq
) {
1039 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not allowed (mesh)");
1042 #endif /* CONFIG_MESH */
1044 if (!rate_match(wpa_s
, bss
)) {
1045 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
1051 if (ssid
->p2p_group
&&
1052 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
1053 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
1054 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no P2P IE seen");
1058 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
1059 struct wpabuf
*p2p_ie
;
1060 u8 dev_addr
[ETH_ALEN
];
1062 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1064 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no P2P element");
1067 p2p_ie
= wpa_bss_get_vendor_ie_multi(
1068 bss
, P2P_IE_VENDOR_TYPE
);
1069 if (p2p_ie
== NULL
) {
1070 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - could not fetch P2P element");
1074 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
1075 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
1077 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no matching GO P2P Device Address in P2P element");
1078 wpabuf_free(p2p_ie
);
1081 wpabuf_free(p2p_ie
);
1085 * TODO: skip the AP if its P2P IE has Group Formation
1086 * bit set in the P2P Group Capability Bitmap and we
1087 * are not in Group Formation with that device.
1089 #endif /* CONFIG_P2P */
1091 if (os_reltime_before(&bss
->last_update
, &wpa_s
->scan_min_time
))
1093 struct os_reltime diff
;
1095 os_reltime_sub(&wpa_s
->scan_min_time
,
1096 &bss
->last_update
, &diff
);
1097 wpa_dbg(wpa_s
, MSG_DEBUG
,
1098 " skip - scan result not recent enough (%u.%06u seconds too old)",
1099 (unsigned int) diff
.sec
,
1100 (unsigned int) diff
.usec
);
1104 assoc_disallow
= wpas_mbo_get_bss_attr(
1105 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1106 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1107 wpa_dbg(wpa_s
, MSG_DEBUG
,
1108 " skip - MBO association disallowed (reason %u)",
1113 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1114 wpa_dbg(wpa_s
, MSG_DEBUG
,
1115 " skip - MBO retry delay has not passed yet");
1118 #endif /* CONFIG_MBO */
1120 /* Matching configuration found */
1124 /* No matching configuration found */
1129 static struct wpa_bss
*
1130 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1131 struct wpa_ssid
*group
,
1132 struct wpa_ssid
**selected_ssid
,
1133 int only_first_ssid
)
1137 if (only_first_ssid
)
1138 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1141 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1144 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1145 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1146 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1148 if (!*selected_ssid
)
1150 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1152 MAC2STR(bss
->bssid
),
1153 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1161 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1162 struct wpa_ssid
**selected_ssid
)
1164 struct wpa_bss
*selected
= NULL
;
1166 struct wpa_ssid
*next_ssid
= NULL
;
1167 struct wpa_ssid
*ssid
;
1169 if (wpa_s
->last_scan_res
== NULL
||
1170 wpa_s
->last_scan_res_used
== 0)
1171 return NULL
; /* no scan results from last update */
1173 if (wpa_s
->next_ssid
) {
1174 /* check that next_ssid is still valid */
1175 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1176 if (ssid
== wpa_s
->next_ssid
)
1180 wpa_s
->next_ssid
= NULL
;
1183 while (selected
== NULL
) {
1184 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1185 if (next_ssid
&& next_ssid
->priority
==
1186 wpa_s
->conf
->pssid
[prio
]->priority
) {
1187 selected
= wpa_supplicant_select_bss(
1188 wpa_s
, next_ssid
, selected_ssid
, 1);
1192 selected
= wpa_supplicant_select_bss(
1193 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1199 if (selected
== NULL
&& wpa_s
->blacklist
&&
1200 !wpa_s
->countermeasures
) {
1201 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1202 "blacklist and try again");
1203 wpa_blacklist_clear(wpa_s
);
1204 wpa_s
->blacklist_cleared
++;
1205 } else if (selected
== NULL
)
1209 ssid
= *selected_ssid
;
1210 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1211 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1212 const char *field_name
, *txt
= NULL
;
1214 wpa_dbg(wpa_s
, MSG_DEBUG
,
1215 "PSK/passphrase not yet available for the selected network");
1217 wpas_notify_network_request(wpa_s
, ssid
,
1218 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1220 field_name
= wpa_supplicant_ctrl_req_to_string(
1221 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1222 if (field_name
== NULL
)
1225 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1234 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1235 int timeout_sec
, int timeout_usec
)
1237 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1239 * No networks are enabled; short-circuit request so
1240 * we don't wait timeout seconds before transitioning
1241 * to INACTIVE state.
1243 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1244 "since there are no enabled networks");
1245 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1249 wpa_s
->scan_for_connection
= 1;
1250 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1254 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1255 struct wpa_bss
*selected
,
1256 struct wpa_ssid
*ssid
)
1258 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1259 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1260 "PBC session overlap");
1261 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1263 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1264 wpa_s
->p2p_in_provisioning
) {
1265 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1269 #endif /* CONFIG_P2P */
1272 wpas_wps_pbc_overlap(wpa_s
);
1273 wpas_wps_cancel(wpa_s
);
1274 #endif /* CONFIG_WPS */
1278 wpa_msg(wpa_s
, MSG_DEBUG
,
1279 "Considering connect request: reassociate: %d selected: "
1280 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1281 " wpa_state: %s ssid=%p current_ssid=%p",
1282 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1283 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1284 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1285 ssid
, wpa_s
->current_ssid
);
1288 * Do not trigger new association unless the BSSID has changed or if
1289 * reassociation is requested. If we are in process of associating with
1290 * the selected BSSID, do not trigger new attempt.
1292 if (wpa_s
->reassociate
||
1293 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1294 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1295 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1296 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1297 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1299 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1300 ssid
!= wpa_s
->current_ssid
)))) {
1301 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1302 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1305 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1306 MAC2STR(selected
->bssid
));
1307 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1309 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1310 "connect with the selected AP");
1317 static struct wpa_ssid
*
1318 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1321 struct wpa_ssid
*ssid
;
1323 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1324 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1326 if (wpas_network_disabled(wpa_s
, ssid
))
1328 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1329 ssid
->mode
== IEEE80211_MODE_AP
||
1330 ssid
->mode
== IEEE80211_MODE_MESH
)
1338 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1339 * on BSS added and BSS changed events */
1340 static void wpa_supplicant_rsn_preauth_scan_results(
1341 struct wpa_supplicant
*wpa_s
)
1343 struct wpa_bss
*bss
;
1345 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1348 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1349 const u8
*ssid
, *rsn
;
1351 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1355 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1359 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1365 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1366 struct wpa_bss
*selected
,
1367 struct wpa_ssid
*ssid
)
1369 struct wpa_bss
*current_bss
= NULL
;
1370 #ifndef CONFIG_NO_ROAMING
1373 #endif /* CONFIG_NO_ROAMING */
1375 if (wpa_s
->reassociate
)
1376 return 1; /* explicit request to reassociate */
1377 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1378 return 1; /* we are not associated; continue */
1379 if (wpa_s
->current_ssid
== NULL
)
1380 return 1; /* unknown current SSID */
1381 if (wpa_s
->current_ssid
!= ssid
)
1382 return 1; /* different network block */
1384 if (wpas_driver_bss_selection(wpa_s
))
1385 return 0; /* Driver-based roaming */
1387 if (wpa_s
->current_ssid
->ssid
)
1388 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1389 wpa_s
->current_ssid
->ssid
,
1390 wpa_s
->current_ssid
->ssid_len
);
1392 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1395 return 1; /* current BSS not seen in scan results */
1397 if (current_bss
== selected
)
1400 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1401 return 1; /* current BSS not seen in the last scan */
1403 #ifndef CONFIG_NO_ROAMING
1404 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1405 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1406 " level=%d snr=%d est_throughput=%u",
1407 MAC2STR(current_bss
->bssid
), current_bss
->level
,
1408 current_bss
->snr
, current_bss
->est_throughput
);
1409 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1410 " level=%d snr=%d est_throughput=%u",
1411 MAC2STR(selected
->bssid
), selected
->level
,
1412 selected
->snr
, selected
->est_throughput
);
1414 if (wpa_s
->current_ssid
->bssid_set
&&
1415 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1417 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1418 "has preferred BSSID");
1422 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1423 wpa_dbg(wpa_s
, MSG_DEBUG
,
1424 "Allow reassociation - selected BSS has better estimated throughput");
1428 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1430 if (current_bss
->level
< 0 &&
1431 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1432 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1438 if (current_bss
->level
< 0) {
1439 if (current_bss
->level
< -85)
1441 else if (current_bss
->level
< -80)
1443 else if (current_bss
->level
< -75)
1445 else if (current_bss
->level
< -70)
1451 /* Make it easier to move to 5 GHz band */
1457 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
1458 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
1464 #else /* CONFIG_NO_ROAMING */
1466 #endif /* CONFIG_NO_ROAMING */
1470 /* Return != 0 if no scan results could be fetched or if scan results should not
1471 * be shared with other virtual interfaces. */
1472 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1473 union wpa_event_data
*data
,
1476 struct wpa_scan_results
*scan_res
= NULL
;
1479 #ifndef CONFIG_NO_RANDOM_POOL
1481 #endif /* CONFIG_NO_RANDOM_POOL */
1484 if (wpa_s
->ap_iface
)
1486 #endif /* CONFIG_AP */
1488 wpa_supplicant_notify_scanning(wpa_s
, 0);
1490 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1491 data
? &data
->scan_info
:
1493 if (scan_res
== NULL
) {
1494 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1495 wpa_s
->scan_res_handler
== scan_only_handler
)
1499 if (data
&& data
->scan_info
.external_scan
)
1501 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1503 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1505 goto scan_work_done
;
1508 #ifndef CONFIG_NO_RANDOM_POOL
1509 num
= scan_res
->num
;
1512 for (i
= 0; i
< num
; i
++) {
1514 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1515 buf
[0] = res
->bssid
[5];
1516 buf
[1] = res
->qual
& 0xff;
1517 buf
[2] = res
->noise
& 0xff;
1518 buf
[3] = res
->level
& 0xff;
1519 buf
[4] = res
->tsf
& 0xff;
1520 random_add_randomness(buf
, sizeof(buf
));
1522 #endif /* CONFIG_NO_RANDOM_POOL */
1524 if (own_request
&& wpa_s
->scan_res_handler
&&
1525 !(data
&& data
->scan_info
.external_scan
)) {
1526 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1527 struct wpa_scan_results
*scan_res
);
1529 scan_res_handler
= wpa_s
->scan_res_handler
;
1530 wpa_s
->scan_res_handler
= NULL
;
1531 scan_res_handler(wpa_s
, scan_res
);
1533 goto scan_work_done
;
1537 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1539 if (wpa_s
->ap_iface
->scan_cb
)
1540 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1541 #endif /* CONFIG_AP */
1542 goto scan_work_done
;
1545 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1546 wpa_s
->own_scan_running
,
1547 data
? data
->scan_info
.external_scan
: 0);
1548 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1549 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1550 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1551 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1552 wpa_s
->manual_scan_id
);
1553 wpa_s
->manual_scan_use_id
= 0;
1555 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1557 wpas_notify_scan_results(wpa_s
);
1559 wpas_notify_scan_done(wpa_s
, 1);
1561 if (data
&& data
->scan_info
.external_scan
) {
1562 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1563 wpa_scan_results_free(scan_res
);
1567 if (wnm_scan_process(wpa_s
, 1) > 0)
1568 goto scan_work_done
;
1570 if (sme_proc_obss_scan(wpa_s
) > 0)
1571 goto scan_work_done
;
1573 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1574 goto scan_work_done
;
1576 if (autoscan_notify_scan(wpa_s
, scan_res
))
1577 goto scan_work_done
;
1579 if (wpa_s
->disconnected
) {
1580 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1581 goto scan_work_done
;
1584 if (!wpas_driver_bss_selection(wpa_s
) &&
1585 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1586 goto scan_work_done
;
1588 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1590 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1591 wpa_s
->wpa_state
< WPA_COMPLETED
)
1592 goto scan_work_done
;
1594 wpa_scan_results_free(scan_res
);
1596 if (own_request
&& wpa_s
->scan_work
) {
1597 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1598 wpa_s
->scan_work
= NULL
;
1599 radio_work_done(work
);
1602 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1605 wpa_scan_results_free(scan_res
);
1606 if (own_request
&& wpa_s
->scan_work
) {
1607 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1608 wpa_s
->scan_work
= NULL
;
1609 radio_work_done(work
);
1615 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1616 int new_scan
, int own_request
)
1618 struct wpa_bss
*selected
;
1619 struct wpa_ssid
*ssid
= NULL
;
1620 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1622 if (time_to_reenable
> 0) {
1623 wpa_dbg(wpa_s
, MSG_DEBUG
,
1624 "Postpone network selection by %d seconds since all networks are disabled",
1626 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1627 eloop_register_timeout(time_to_reenable
, 0,
1628 wpas_network_reenabled
, wpa_s
, NULL
);
1632 if (wpa_s
->p2p_mgmt
)
1633 return 0; /* no normal connection on p2p_mgmt interface */
1635 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1639 wpa_msg(wpa_s
, MSG_INFO
,
1640 "Avoiding join because we already joined a mesh group");
1643 #endif /* CONFIG_MESH */
1647 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1650 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1654 if (ssid
!= wpa_s
->current_ssid
&&
1655 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1656 wpa_s
->own_disconnect_req
= 1;
1657 wpa_supplicant_deauthenticate(
1658 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1661 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1662 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1666 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1668 * Do not notify other virtual radios of scan results since we do not
1669 * want them to start other associations at the same time.
1673 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1674 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1676 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1677 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1679 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1680 } else if (own_request
) {
1682 * No SSID found. If SCAN results are as a result of
1683 * own scan request and not due to a scan request on
1684 * another shared interface, try another scan.
1686 int timeout_sec
= wpa_s
->scan_interval
;
1687 int timeout_usec
= 0;
1691 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1697 if (wpa_s
->p2p_in_provisioning
||
1698 wpa_s
->show_group_started
||
1699 wpa_s
->p2p_in_invitation
) {
1701 * Use shorter wait during P2P Provisioning
1702 * state and during P2P join-a-group operation
1703 * to speed up group formation.
1706 timeout_usec
= 250000;
1707 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1711 #endif /* CONFIG_P2P */
1712 #ifdef CONFIG_INTERWORKING
1713 if (wpa_s
->conf
->auto_interworking
&&
1714 wpa_s
->conf
->interworking
&&
1715 wpa_s
->conf
->cred
) {
1716 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1717 "start ANQP fetch since no matching "
1719 wpa_s
->network_select
= 1;
1720 wpa_s
->auto_network_select
= 1;
1721 interworking_start_fetch_anqp(wpa_s
);
1724 #endif /* CONFIG_INTERWORKING */
1726 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1727 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1729 timeout_usec
= 500000;
1730 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1734 #endif /* CONFIG_WPS */
1735 if (wpa_supplicant_req_sched_scan(wpa_s
))
1736 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1739 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1740 WPA_EVENT_NETWORK_NOT_FOUND
);
1747 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1748 union wpa_event_data
*data
)
1750 struct wpa_supplicant
*ifs
;
1753 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1);
1756 * Interface may have been removed, so must not dereference
1763 * If no scan results could be fetched, then no need to
1764 * notify those interfaces that did not actually request
1765 * this scan. Similarly, if scan results started a new operation on this
1766 * interface, do not notify other interfaces to avoid concurrent
1767 * operations during a connection attempt.
1773 * Check other interfaces to see if they share the same radio. If
1774 * so, they get updated with this same scan info.
1776 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1779 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1780 "sibling", ifs
->ifname
);
1781 _wpa_supplicant_event_scan_results(ifs
, data
, 0);
1788 #endif /* CONFIG_NO_SCAN_PROCESSING */
1791 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1793 #ifdef CONFIG_NO_SCAN_PROCESSING
1795 #else /* CONFIG_NO_SCAN_PROCESSING */
1796 struct os_reltime now
;
1798 if (wpa_s
->last_scan_res_used
== 0)
1801 os_get_reltime(&now
);
1802 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1803 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1807 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1808 #endif /* CONFIG_NO_SCAN_PROCESSING */
1813 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1815 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1817 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1820 if (!wpa_s
->no_keep_alive
) {
1821 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1822 MAC2STR(wpa_s
->bssid
));
1823 /* TODO: could skip this if normal data traffic has been sent */
1824 /* TODO: Consider using some more appropriate data frame for
1827 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
1832 if (wpa_s
->sme
.bss_max_idle_period
) {
1834 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
1837 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1838 wnm_bss_keep_alive
, wpa_s
, NULL
);
1840 #endif /* CONFIG_SME */
1844 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1845 const u8
*ies
, size_t ies_len
)
1847 struct ieee802_11_elems elems
;
1852 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1856 if (elems
.bss_max_idle_period
) {
1858 wpa_s
->sme
.bss_max_idle_period
=
1859 WPA_GET_LE16(elems
.bss_max_idle_period
);
1860 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
1861 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
1862 (elems
.bss_max_idle_period
[2] & 0x01) ?
1863 " (protected keep-live required)" : "");
1864 if (wpa_s
->sme
.bss_max_idle_period
== 0)
1865 wpa_s
->sme
.bss_max_idle_period
= 1;
1866 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
1867 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1868 /* msec times 1000 */
1869 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
1872 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1873 wnm_bss_keep_alive
, wpa_s
,
1877 #endif /* CONFIG_SME */
1880 #endif /* CONFIG_WNM */
1883 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
1886 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1887 #endif /* CONFIG_WNM */
1891 #ifdef CONFIG_INTERWORKING
1893 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
1898 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
1899 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
1901 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
1908 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1909 const u8
*ies
, size_t ies_len
)
1911 struct ieee802_11_elems elems
;
1916 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1919 if (elems
.qos_map_set
) {
1920 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
1921 elems
.qos_map_set_len
);
1925 #endif /* CONFIG_INTERWORKING */
1929 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
1930 const u8
*ie
, size_t ie_len
)
1932 struct mb_ies_info mb_ies
;
1934 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
1937 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
1939 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
1944 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
1949 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
1950 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
1951 (unsigned int) len
);
1952 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
1953 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
1961 if (mb_ies
.nof_ies
> 0) {
1962 wpabuf_free(wpa_s
->received_mb_ies
);
1963 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
1969 #endif /* CONFIG_FST */
1972 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1973 union wpa_event_data
*data
)
1975 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1977 #ifdef CONFIG_IEEE80211R
1979 #endif /* CONFIG_IEEE80211R */
1981 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1982 if (data
->assoc_info
.req_ies
)
1983 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1984 data
->assoc_info
.req_ies_len
);
1985 if (data
->assoc_info
.resp_ies
) {
1986 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1987 data
->assoc_info
.resp_ies_len
);
1989 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1990 data
->assoc_info
.resp_ies_len
);
1991 #endif /* CONFIG_TDLS */
1993 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1994 data
->assoc_info
.resp_ies_len
);
1995 #endif /* CONFIG_WNM */
1996 #ifdef CONFIG_INTERWORKING
1997 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1998 data
->assoc_info
.resp_ies_len
);
1999 #endif /* CONFIG_INTERWORKING */
2001 if (data
->assoc_info
.beacon_ies
)
2002 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2003 data
->assoc_info
.beacon_ies
,
2004 data
->assoc_info
.beacon_ies_len
);
2005 if (data
->assoc_info
.freq
)
2006 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2007 data
->assoc_info
.freq
);
2009 p
= data
->assoc_info
.req_ies
;
2010 l
= data
->assoc_info
.req_ies_len
;
2012 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2013 while (p
&& l
>= 2) {
2016 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2020 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2021 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2022 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2023 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2024 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2025 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2028 wpa_find_assoc_pmkid(wpa_s
);
2034 if (!found
&& data
->assoc_info
.req_ies
)
2035 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2037 #ifdef CONFIG_IEEE80211R
2039 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2040 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2041 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2042 data
->assoc_info
.resp_ies
,
2043 data
->assoc_info
.resp_ies_len
,
2045 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2046 "Reassociation Response failed");
2047 wpa_supplicant_deauthenticate(
2048 wpa_s
, WLAN_REASON_INVALID_IE
);
2053 p
= data
->assoc_info
.resp_ies
;
2054 l
= data
->assoc_info
.resp_ies_len
;
2056 #ifdef CONFIG_WPS_STRICT
2057 if (p
&& wpa_s
->current_ssid
&&
2058 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2060 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2062 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2063 "include WPS IE in (Re)Association Response");
2067 if (wps_validate_assoc_resp(wps
) < 0) {
2069 wpa_supplicant_deauthenticate(
2070 wpa_s
, WLAN_REASON_INVALID_IE
);
2075 #endif /* CONFIG_WPS_STRICT */
2077 /* Go through the IEs and make a copy of the MDIE, if present. */
2078 while (p
&& l
>= 2) {
2081 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2085 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2086 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2087 wpa_s
->sme
.ft_used
= 1;
2088 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2089 MOBILITY_DOMAIN_ID_LEN
);
2095 #endif /* CONFIG_SME */
2097 /* Process FT when SME is in the driver */
2098 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2099 wpa_ft_is_completed(wpa_s
->wpa
)) {
2100 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2101 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2102 data
->assoc_info
.resp_ies
,
2103 data
->assoc_info
.resp_ies_len
,
2105 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2106 "Reassociation Response failed");
2107 wpa_supplicant_deauthenticate(
2108 wpa_s
, WLAN_REASON_INVALID_IE
);
2111 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2114 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2115 data
->assoc_info
.resp_ies_len
);
2116 #endif /* CONFIG_IEEE80211R */
2118 /* WPA/RSN IE from Beacon/ProbeResp */
2119 p
= data
->assoc_info
.beacon_ies
;
2120 l
= data
->assoc_info
.beacon_ies_len
;
2122 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2124 wpa_found
= rsn_found
= 0;
2125 while (p
&& l
>= 2) {
2128 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2133 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2134 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2136 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2140 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2142 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2149 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2150 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2151 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2152 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2153 if (wpa_found
|| rsn_found
)
2154 wpa_s
->ap_ies_from_associnfo
= 1;
2156 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2157 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2158 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2160 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2161 wpa_supplicant_update_scan_results(wpa_s
);
2164 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2170 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2172 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2174 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2177 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2180 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2181 WPA_IE_VENDOR_TYPE
);
2182 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2184 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2185 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2186 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2187 bss_rsn
? 2 + bss_rsn
[1] : 0))
2194 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2195 union wpa_event_data
*data
)
2198 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2199 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2200 const u8
*ieprb
, *iebcn
;
2202 wpabuf_free(wpa_s
->received_mb_ies
);
2203 wpa_s
->received_mb_ies
= NULL
;
2206 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2207 wpa_printf(MSG_DEBUG
,
2208 "FST: MB IEs updated from Association Response frame");
2213 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2214 wpa_printf(MSG_DEBUG
,
2215 "FST: MB IEs updated from association event Beacon IEs");
2222 ieprb
= (const u8
*) (bss
+ 1);
2223 iebcn
= ieprb
+ bss
->ie_len
;
2225 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2226 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2227 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2228 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2229 #endif /* CONFIG_FST */
2233 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2234 union wpa_event_data
*data
)
2237 int ft_completed
, already_authorized
;
2241 if (wpa_s
->ap_iface
) {
2244 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2245 data
->assoc_info
.addr
,
2246 data
->assoc_info
.req_ies
,
2247 data
->assoc_info
.req_ies_len
,
2248 data
->assoc_info
.reassoc
);
2251 #endif /* CONFIG_AP */
2253 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2255 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2256 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2259 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2260 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2261 wpa_supplicant_deauthenticate(
2262 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2266 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2267 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2268 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2269 MACSTR
, MAC2STR(bssid
));
2271 random_add_randomness(bssid
, ETH_ALEN
);
2272 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2273 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2274 wpas_notify_bssid_changed(wpa_s
);
2276 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2277 wpa_clear_keys(wpa_s
, bssid
);
2279 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2280 wpa_supplicant_deauthenticate(
2281 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2286 if (wpa_s
->conf
->ap_scan
== 1 &&
2287 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2288 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2289 wpa_msg(wpa_s
, MSG_WARNING
,
2290 "WPA/RSN IEs not updated");
2293 wpas_fst_update_mb_assoc(wpa_s
, data
);
2296 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2297 wpa_s
->sme
.prev_bssid_set
= 1;
2298 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2299 #endif /* CONFIG_SME */
2301 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2302 if (wpa_s
->current_ssid
) {
2303 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2304 * initialized before association, but for other modes,
2305 * initialize PC/SC here, if the current configuration needs
2306 * smartcard or SIM/USIM. */
2307 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2309 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2311 l2_packet_notify_auth_start(wpa_s
->l2
);
2313 already_authorized
= data
&& data
->assoc_info
.authorized
;
2316 * Set portEnabled first to FALSE in order to get EAP state machine out
2317 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2318 * state machine may transit to AUTHENTICATING state based on obsolete
2319 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2320 * AUTHENTICATED without ever giving chance to EAP state machine to
2323 if (!ft_completed
&& !already_authorized
) {
2324 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2325 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2327 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
||
2329 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2330 /* 802.1X::portControl = Auto */
2331 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2332 wpa_s
->eapol_received
= 0;
2333 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2334 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2335 (wpa_s
->current_ssid
&&
2336 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2337 if (wpa_s
->current_ssid
&&
2338 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2340 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2342 * Set the key after having received joined-IBSS event
2345 wpa_supplicant_set_wpa_none_key(wpa_s
,
2346 wpa_s
->current_ssid
);
2348 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2349 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2350 } else if (!ft_completed
) {
2351 /* Timeout for receiving the first EAPOL packet */
2352 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2354 wpa_supplicant_cancel_scan(wpa_s
);
2356 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2357 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2359 * We are done; the driver will take care of RSN 4-way
2362 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2363 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2364 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2365 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2366 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2367 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2369 * The driver will take care of RSN 4-way handshake, so we need
2370 * to allow EAPOL supplicant to complete its work without
2371 * waiting for WPA supplicant.
2373 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2374 } else if (ft_completed
) {
2376 * FT protocol completed - make sure EAPOL state machine ends
2377 * up in authenticated.
2379 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2380 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2381 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2382 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2385 wpa_s
->last_eapol_matches_bssid
= 0;
2387 if (wpa_s
->pending_eapol_rx
) {
2388 struct os_reltime now
, age
;
2389 os_get_reltime(&now
);
2390 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2391 if (age
.sec
== 0 && age
.usec
< 100000 &&
2392 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2394 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2395 "frame that was received just before "
2396 "association notification");
2397 wpa_supplicant_rx_eapol(
2398 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2399 wpabuf_head(wpa_s
->pending_eapol_rx
),
2400 wpabuf_len(wpa_s
->pending_eapol_rx
));
2402 wpabuf_free(wpa_s
->pending_eapol_rx
);
2403 wpa_s
->pending_eapol_rx
= NULL
;
2406 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2407 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2408 wpa_s
->current_ssid
&&
2409 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2410 /* Set static WEP keys again */
2411 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2414 #ifdef CONFIG_IBSS_RSN
2415 if (wpa_s
->current_ssid
&&
2416 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2417 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2418 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2419 wpa_s
->ibss_rsn
== NULL
) {
2420 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2421 if (!wpa_s
->ibss_rsn
) {
2422 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2423 wpa_supplicant_deauthenticate(
2424 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2428 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2430 #endif /* CONFIG_IBSS_RSN */
2432 wpas_wps_notify_assoc(wpa_s
, bssid
);
2435 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2436 data
->assoc_info
.resp_ies_len
,
2437 &data
->assoc_info
.wmm_params
);
2439 if (wpa_s
->reassoc_same_bss
)
2440 wmm_ac_restore_tspecs(wpa_s
);
2445 static int disconnect_reason_recoverable(u16 reason_code
)
2447 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2448 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2449 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2453 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2455 int locally_generated
)
2459 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2461 * At least Host AP driver and a Prism3 card seemed to be
2462 * generating streams of disconnected events when configuring
2463 * IBSS for WPA-None. Ignore them for now.
2468 bssid
= wpa_s
->bssid
;
2469 if (is_zero_ether_addr(bssid
))
2470 bssid
= wpa_s
->pending_bssid
;
2472 if (!is_zero_ether_addr(bssid
) ||
2473 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2474 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2476 MAC2STR(bssid
), reason_code
,
2477 locally_generated
? " locally_generated=1" : "");
2482 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2483 int locally_generated
)
2485 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2486 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2487 return 0; /* Not in 4-way handshake with PSK */
2490 * It looks like connection was lost while trying to go through PSK
2491 * 4-way handshake. Filter out known disconnection cases that are caused
2492 * by something else than PSK mismatch to avoid confusing reports.
2495 if (locally_generated
) {
2496 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2504 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2506 int locally_generated
)
2510 u8 prev_pending_bssid
[ETH_ALEN
];
2511 struct wpa_bss
*fast_reconnect
= NULL
;
2512 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2513 struct wpa_ssid
*last_ssid
;
2515 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2516 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2518 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2520 * At least Host AP driver and a Prism3 card seemed to be
2521 * generating streams of disconnected events when configuring
2522 * IBSS for WPA-None. Ignore them for now.
2524 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2525 "IBSS/WPA-None mode");
2529 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2530 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2531 "pre-shared key may be incorrect");
2532 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2533 return; /* P2P group removed */
2534 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2536 if (!wpa_s
->disconnected
&&
2537 (!wpa_s
->auto_reconnect_disabled
||
2538 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2539 wpas_wps_searching(wpa_s
) ||
2540 wpas_wps_reenable_networks_pending(wpa_s
))) {
2541 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2542 "reconnect (wps=%d/%d wpa_state=%d)",
2543 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2544 wpas_wps_searching(wpa_s
),
2546 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2547 wpa_s
->current_ssid
&&
2548 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2549 !locally_generated
&&
2550 disconnect_reason_recoverable(reason_code
)) {
2552 * It looks like the AP has dropped association with
2553 * us, but could allow us to get back in. Try to
2554 * reconnect to the same BSS without full scan to save
2555 * time for some common cases.
2557 fast_reconnect
= wpa_s
->current_bss
;
2558 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2559 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2560 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2562 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2565 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2566 "try to re-connect");
2567 wpa_s
->reassociate
= 0;
2568 wpa_s
->disconnected
= 1;
2570 wpa_supplicant_cancel_sched_scan(wpa_s
);
2572 bssid
= wpa_s
->bssid
;
2573 if (is_zero_ether_addr(bssid
))
2574 bssid
= wpa_s
->pending_bssid
;
2575 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2576 wpas_connection_failed(wpa_s
, bssid
);
2577 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2578 if (locally_generated
)
2579 wpa_s
->disconnect_reason
= -reason_code
;
2581 wpa_s
->disconnect_reason
= reason_code
;
2582 wpas_notify_disconnect_reason(wpa_s
);
2583 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2584 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2585 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2587 last_ssid
= wpa_s
->current_ssid
;
2588 wpa_supplicant_mark_disassoc(wpa_s
);
2590 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2591 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2592 wpa_s
->current_ssid
= last_ssid
;
2595 if (fast_reconnect
&&
2596 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2597 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2598 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2599 fast_reconnect
->ssid_len
) &&
2600 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2601 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2602 #ifndef CONFIG_NO_SCAN_PROCESSING
2603 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2604 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2605 fast_reconnect_ssid
) < 0) {
2606 /* Recover through full scan */
2607 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2609 #endif /* CONFIG_NO_SCAN_PROCESSING */
2610 } else if (fast_reconnect
) {
2612 * Could not reconnect to the same BSS due to network being
2613 * disabled. Use a new scan to match the alternative behavior
2614 * above, i.e., to continue automatic reconnection attempt in a
2615 * way that enforces disabled network rules.
2617 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2622 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2623 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2625 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2627 if (!wpa_s
->pending_mic_error_report
)
2630 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2631 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2632 wpa_s
->pending_mic_error_report
= 0;
2634 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2638 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2639 union wpa_event_data
*data
)
2642 struct os_reltime t
;
2644 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2645 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2647 if ((wpa_s
->last_michael_mic_error
.sec
&&
2648 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2649 wpa_s
->pending_mic_error_report
) {
2650 if (wpa_s
->pending_mic_error_report
) {
2652 * Send the pending MIC error report immediately since
2653 * we are going to start countermeasures and AP better
2656 wpa_sm_key_request(wpa_s
->wpa
, 1,
2657 wpa_s
->pending_mic_error_pairwise
);
2660 /* Send the new MIC error report immediately since we are going
2661 * to start countermeasures and AP better do the same.
2663 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2665 /* initialize countermeasures */
2666 wpa_s
->countermeasures
= 1;
2668 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2670 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2673 * Need to wait for completion of request frame. We do not get
2674 * any callback for the message completion, so just wait a
2675 * short while and hope for the best. */
2678 wpa_drv_set_countermeasures(wpa_s
, 1);
2679 wpa_supplicant_deauthenticate(wpa_s
,
2680 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2681 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2683 eloop_register_timeout(60, 0,
2684 wpa_supplicant_stop_countermeasures
,
2686 /* TODO: mark the AP rejected for 60 second. STA is
2687 * allowed to associate with another AP.. */
2689 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2690 if (wpa_s
->mic_errors_seen
) {
2692 * Reduce the effectiveness of Michael MIC error
2693 * reports as a means for attacking against TKIP if
2694 * more than one MIC failure is noticed with the same
2695 * PTK. We delay the transmission of the reports by a
2696 * random time between 0 and 60 seconds in order to
2697 * force the attacker wait 60 seconds before getting
2698 * the information on whether a frame resulted in a MIC
2704 if (os_get_random(rval
, sizeof(rval
)) < 0)
2705 sec
= os_random() % 60;
2707 sec
= WPA_GET_BE32(rval
) % 60;
2708 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2709 "report %d seconds", sec
);
2710 wpa_s
->pending_mic_error_report
= 1;
2711 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2712 eloop_cancel_timeout(
2713 wpa_supplicant_delayed_mic_error_report
,
2715 eloop_register_timeout(
2716 sec
, os_random() % 1000000,
2717 wpa_supplicant_delayed_mic_error_report
,
2720 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2722 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2723 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2724 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2726 wpa_s
->last_michael_mic_error
= t
;
2727 wpa_s
->mic_errors_seen
++;
2731 #ifdef CONFIG_TERMINATE_ONLASTIF
2732 static int any_interfaces(struct wpa_supplicant
*head
)
2734 struct wpa_supplicant
*wpa_s
;
2736 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2737 if (!wpa_s
->interface_removed
)
2741 #endif /* CONFIG_TERMINATE_ONLASTIF */
2745 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2746 union wpa_event_data
*data
)
2748 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2751 switch (data
->interface_status
.ievent
) {
2752 case EVENT_INTERFACE_ADDED
:
2753 if (!wpa_s
->interface_removed
)
2755 wpa_s
->interface_removed
= 0;
2756 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
2757 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
2758 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
2759 "driver after interface was added");
2763 if (!wpa_s
->global
->p2p
&&
2764 !wpa_s
->global
->p2p_disabled
&&
2765 !wpa_s
->conf
->p2p_disabled
&&
2767 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
2768 wpas_p2p_add_p2pdev_interface(
2769 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
2770 wpa_printf(MSG_INFO
,
2771 "P2P: Failed to enable P2P Device interface");
2772 /* Try to continue without. P2P will be disabled. */
2774 #endif /* CONFIG_P2P */
2777 case EVENT_INTERFACE_REMOVED
:
2778 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
2779 wpa_s
->interface_removed
= 1;
2780 wpa_supplicant_mark_disassoc(wpa_s
);
2781 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2782 l2_packet_deinit(wpa_s
->l2
);
2786 if (wpa_s
->global
->p2p
&&
2787 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
2789 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
2790 wpa_dbg(wpa_s
, MSG_DEBUG
,
2791 "Removing P2P Device interface");
2792 wpa_supplicant_remove_iface(
2793 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
2795 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
2797 #endif /* CONFIG_P2P */
2799 #ifdef CONFIG_MATCH_IFACE
2800 if (wpa_s
->matched
) {
2801 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
2804 #endif /* CONFIG_MATCH_IFACE */
2806 #ifdef CONFIG_TERMINATE_ONLASTIF
2807 /* check if last interface */
2808 if (!any_interfaces(wpa_s
->global
->ifaces
))
2810 #endif /* CONFIG_TERMINATE_ONLASTIF */
2816 #ifdef CONFIG_PEERKEY
2818 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
2819 union wpa_event_data
*data
)
2823 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
2825 #endif /* CONFIG_PEERKEY */
2829 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
2830 union wpa_event_data
*data
)
2834 switch (data
->tdls
.oper
) {
2835 case TDLS_REQUEST_SETUP
:
2836 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
2837 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2838 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
2840 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
2842 case TDLS_REQUEST_TEARDOWN
:
2843 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2844 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
2845 data
->tdls
.reason_code
);
2847 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
2850 case TDLS_REQUEST_DISCOVER
:
2851 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
2856 #endif /* CONFIG_TDLS */
2860 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
2861 union wpa_event_data
*data
)
2865 switch (data
->wnm
.oper
) {
2866 case WNM_OPER_SLEEP
:
2867 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
2868 "(action=%d, intval=%d)",
2869 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
2870 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
2871 data
->wnm
.sleep_intval
, NULL
);
2875 #endif /* CONFIG_WNM */
2878 #ifdef CONFIG_IEEE80211R
2880 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
2881 union wpa_event_data
*data
)
2886 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
2887 data
->ft_ies
.ies_len
,
2888 data
->ft_ies
.ft_action
,
2889 data
->ft_ies
.target_ap
,
2890 data
->ft_ies
.ric_ies
,
2891 data
->ft_ies
.ric_ies_len
) < 0) {
2892 /* TODO: prevent MLME/driver from trying to associate? */
2895 #endif /* CONFIG_IEEE80211R */
2898 #ifdef CONFIG_IBSS_RSN
2899 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
2900 union wpa_event_data
*data
)
2902 struct wpa_ssid
*ssid
;
2903 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2907 ssid
= wpa_s
->current_ssid
;
2910 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2913 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
2917 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
2918 union wpa_event_data
*data
)
2920 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2925 /* check if the ssid is correctly configured as IBSS/RSN */
2926 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2929 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
2930 data
->rx_mgmt
.frame_len
);
2932 #endif /* CONFIG_IBSS_RSN */
2935 #ifdef CONFIG_IEEE80211R
2936 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
2939 const u8
*sta_addr
, *target_ap_addr
;
2942 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
2943 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2944 return; /* only SME case supported for now */
2945 if (len
< 1 + 2 * ETH_ALEN
+ 2)
2948 return; /* Only FT Action Response is supported for now */
2949 sta_addr
= data
+ 1;
2950 target_ap_addr
= data
+ 1 + ETH_ALEN
;
2951 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
2952 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
2953 MACSTR
" TargetAP " MACSTR
" status %u",
2954 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
2956 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
2957 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
2958 " in FT Action Response", MAC2STR(sta_addr
));
2963 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
2964 "failure (status code %d)", status
);
2965 /* TODO: report error to FT code(?) */
2969 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
2970 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
2971 target_ap_addr
, NULL
, 0) < 0)
2976 struct wpa_bss
*bss
;
2977 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
2979 wpa_s
->sme
.freq
= bss
->freq
;
2980 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
2981 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
2984 #endif /* CONFIG_SME */
2986 #endif /* CONFIG_IEEE80211R */
2989 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
2990 struct unprot_deauth
*e
)
2992 #ifdef CONFIG_IEEE80211W
2993 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
2994 "dropped: " MACSTR
" -> " MACSTR
2995 " (reason code %u)",
2996 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2997 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2998 #endif /* CONFIG_IEEE80211W */
3002 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3003 struct unprot_disassoc
*e
)
3005 #ifdef CONFIG_IEEE80211W
3006 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3007 "dropped: " MACSTR
" -> " MACSTR
3008 " (reason code %u)",
3009 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3010 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3011 #endif /* CONFIG_IEEE80211W */
3015 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3016 u16 reason_code
, int locally_generated
,
3017 const u8
*ie
, size_t ie_len
, int deauth
)
3020 if (wpa_s
->ap_iface
&& addr
) {
3021 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3025 if (wpa_s
->ap_iface
) {
3026 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3029 #endif /* CONFIG_AP */
3031 if (!locally_generated
)
3032 wpa_s
->own_disconnect_req
= 0;
3034 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3036 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3037 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3038 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3039 eapol_sm_failed(wpa_s
->eapol
))) &&
3040 !wpa_s
->eap_expected_failure
))
3041 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3044 if (deauth
&& reason_code
> 0) {
3045 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3046 locally_generated
) > 0) {
3048 * The interface was removed, so cannot continue
3049 * processing any additional operations after this.
3054 #endif /* CONFIG_P2P */
3056 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3061 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3062 struct disassoc_info
*info
)
3064 u16 reason_code
= 0;
3065 int locally_generated
= 0;
3066 const u8
*addr
= NULL
;
3067 const u8
*ie
= NULL
;
3070 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3075 ie_len
= info
->ie_len
;
3076 reason_code
= info
->reason_code
;
3077 locally_generated
= info
->locally_generated
;
3078 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3079 locally_generated
? " (locally generated)" : "");
3081 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3083 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3088 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3089 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3093 if (wpa_s
->ap_iface
) {
3094 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3097 #endif /* CONFIG_AP */
3101 wpas_p2p_disassoc_notif(
3102 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3105 #endif /* CONFIG_P2P */
3107 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3108 sme_event_disassoc(wpa_s
, info
);
3110 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3115 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3116 struct deauth_info
*info
)
3118 u16 reason_code
= 0;
3119 int locally_generated
= 0;
3120 const u8
*addr
= NULL
;
3121 const u8
*ie
= NULL
;
3124 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3129 ie_len
= info
->ie_len
;
3130 reason_code
= info
->reason_code
;
3131 locally_generated
= info
->locally_generated
;
3132 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3134 locally_generated
? " (locally generated)" : "");
3136 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3139 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3143 wpa_reset_ft_completed(wpa_s
->wpa
);
3145 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3146 locally_generated
, ie
, ie_len
, 1);
3150 static const char * reg_init_str(enum reg_change_initiator init
)
3153 case REGDOM_SET_BY_CORE
:
3155 case REGDOM_SET_BY_USER
:
3157 case REGDOM_SET_BY_DRIVER
:
3159 case REGDOM_SET_BY_COUNTRY_IE
:
3160 return "COUNTRY_IE";
3161 case REGDOM_BEACON_HINT
:
3162 return "BEACON_HINT";
3168 static const char * reg_type_str(enum reg_type type
)
3171 case REGDOM_TYPE_UNKNOWN
:
3173 case REGDOM_TYPE_COUNTRY
:
3175 case REGDOM_TYPE_WORLD
:
3177 case REGDOM_TYPE_CUSTOM_WORLD
:
3178 return "CUSTOM_WORLD";
3179 case REGDOM_TYPE_INTERSECTION
:
3180 return "INTERSECTION";
3186 static void wpa_supplicant_update_channel_list(
3187 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3189 struct wpa_supplicant
*ifs
;
3192 * To allow backwards compatibility with higher level layers that
3193 * assumed the REGDOM_CHANGE event is sent over the initially added
3194 * interface. Find the highest parent of this interface and use it to
3197 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3200 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3201 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3202 info
->alpha2
[0] ? " alpha2=" : "",
3203 info
->alpha2
[0] ? info
->alpha2
: "");
3205 if (wpa_s
->drv_priv
== NULL
)
3206 return; /* Ignore event during drv initialization */
3208 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3210 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3212 free_hw_features(ifs
);
3213 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3214 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
);
3217 /* Restart sched_scan with updated channel list */
3218 if (wpa_s
->sched_scanning
) {
3219 wpa_dbg(wpa_s
, MSG_DEBUG
,
3220 "Channel list changed restart sched scan.");
3221 wpa_supplicant_cancel_sched_scan(wpa_s
);
3222 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3225 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3229 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3230 const u8
*frame
, size_t len
, int freq
,
3233 const struct ieee80211_mgmt
*mgmt
;
3238 if (len
< IEEE80211_HDRLEN
+ 2)
3241 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3242 payload
= frame
+ IEEE80211_HDRLEN
;
3243 category
= *payload
++;
3244 plen
= len
- IEEE80211_HDRLEN
- 1;
3246 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3247 " Category=%u DataLen=%d freq=%d MHz",
3248 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3250 if (category
== WLAN_ACTION_WMM
) {
3251 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3255 #ifdef CONFIG_IEEE80211R
3256 if (category
== WLAN_ACTION_FT
) {
3257 ft_rx_action(wpa_s
, payload
, plen
);
3260 #endif /* CONFIG_IEEE80211R */
3262 #ifdef CONFIG_IEEE80211W
3264 if (category
== WLAN_ACTION_SA_QUERY
) {
3265 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3268 #endif /* CONFIG_SME */
3269 #endif /* CONFIG_IEEE80211W */
3272 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3273 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3276 #endif /* CONFIG_WNM */
3279 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3280 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3281 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3282 mgmt
->u
.action
.category
,
3283 payload
, plen
, freq
) == 0)
3285 #endif /* CONFIG_GAS */
3288 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3289 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3290 wpa_dbg(wpa_s
, MSG_DEBUG
,
3291 "TDLS: Received Discovery Response from " MACSTR
,
3295 #endif /* CONFIG_TDLS */
3297 #ifdef CONFIG_INTERWORKING
3298 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3299 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3300 const u8
*pos
= payload
+ 1;
3301 size_t qlen
= plen
- 1;
3302 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3303 MACSTR
, MAC2STR(mgmt
->sa
));
3304 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3305 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3306 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3307 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3310 #endif /* CONFIG_INTERWORKING */
3312 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3313 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3314 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3320 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3321 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3322 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3326 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3327 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3328 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3329 payload
+ 1, plen
- 1,
3335 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3336 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3339 #endif /* CONFIG_FST */
3341 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3342 category
, payload
, plen
, freq
);
3344 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3348 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3349 union wpa_event_data
*event
)
3351 struct wpa_freq_range_list
*list
;
3354 list
= &event
->freq_range
;
3357 str
= freq_range_list_str(list
);
3358 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3362 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3363 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3366 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3369 * The update channel flow will also take care of moving a GO
3370 * from the unsafe frequency if needed.
3372 wpas_p2p_update_channel_list(wpa_s
,
3373 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3375 #endif /* CONFIG_P2P */
3381 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3382 union wpa_event_data
*data
)
3384 wpa_dbg(wpa_s
, MSG_DEBUG
,
3385 "Connection authorized by device, previous state %d",
3387 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3388 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3389 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3390 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3391 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3393 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3394 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3395 data
->assoc_info
.ptk_kck_len
,
3396 data
->assoc_info
.ptk_kek
,
3397 data
->assoc_info
.ptk_kek_len
);
3401 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3402 union wpa_event_data
*data
)
3404 struct wpa_supplicant
*wpa_s
= ctx
;
3407 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3408 event
!= EVENT_INTERFACE_ENABLED
&&
3409 event
!= EVENT_INTERFACE_STATUS
&&
3410 event
!= EVENT_SCAN_RESULTS
&&
3411 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3412 wpa_dbg(wpa_s
, MSG_DEBUG
,
3413 "Ignore event %s (%d) while interface is disabled",
3414 event_to_string(event
), event
);
3418 #ifndef CONFIG_NO_STDOUT_DEBUG
3420 int level
= MSG_DEBUG
;
3422 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3423 const struct ieee80211_hdr
*hdr
;
3425 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3426 fc
= le_to_host16(hdr
->frame_control
);
3427 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3428 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3429 level
= MSG_EXCESSIVE
;
3432 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3433 event_to_string(event
), event
);
3435 #endif /* CONFIG_NO_STDOUT_DEBUG */
3440 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3441 data
->auth
.ies_len
))
3442 wpa_printf(MSG_DEBUG
,
3443 "FST: MB IEs updated from auth IE");
3444 #endif /* CONFIG_FST */
3445 sme_event_auth(wpa_s
, data
);
3448 #ifdef CONFIG_TESTING_OPTIONS
3449 if (wpa_s
->ignore_auth_resp
) {
3450 wpa_printf(MSG_INFO
,
3451 "EVENT_ASSOC - ignore_auth_resp active!");
3454 #endif /* CONFIG_TESTING_OPTIONS */
3455 wpa_supplicant_event_assoc(wpa_s
, data
);
3456 if (data
&& data
->assoc_info
.authorized
)
3457 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3459 wpa_msg(wpa_s
, MSG_INFO
,
3460 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3461 data
->assoc_info
.subnet_status
);
3464 case EVENT_DISASSOC
:
3465 wpas_event_disassoc(wpa_s
,
3466 data
? &data
->disassoc_info
: NULL
);
3469 #ifdef CONFIG_TESTING_OPTIONS
3470 if (wpa_s
->ignore_auth_resp
) {
3471 wpa_printf(MSG_INFO
,
3472 "EVENT_DEAUTH - ignore_auth_resp active!");
3475 #endif /* CONFIG_TESTING_OPTIONS */
3476 wpas_event_deauth(wpa_s
,
3477 data
? &data
->deauth_info
: NULL
);
3479 case EVENT_MICHAEL_MIC_FAILURE
:
3480 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3482 #ifndef CONFIG_NO_SCAN_PROCESSING
3483 case EVENT_SCAN_STARTED
:
3484 if (wpa_s
->own_scan_requested
||
3485 (data
&& !data
->scan_info
.external_scan
)) {
3486 struct os_reltime diff
;
3488 os_get_reltime(&wpa_s
->scan_start_time
);
3489 os_reltime_sub(&wpa_s
->scan_start_time
,
3490 &wpa_s
->scan_trigger_time
, &diff
);
3491 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3492 diff
.sec
, diff
.usec
);
3493 wpa_s
->own_scan_requested
= 0;
3494 wpa_s
->own_scan_running
= 1;
3495 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3496 wpa_s
->manual_scan_use_id
) {
3497 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3498 WPA_EVENT_SCAN_STARTED
"id=%u",
3499 wpa_s
->manual_scan_id
);
3501 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3502 WPA_EVENT_SCAN_STARTED
);
3505 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3506 wpa_s
->radio
->external_scan_running
= 1;
3507 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3510 case EVENT_SCAN_RESULTS
:
3511 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3512 wpa_s
->scan_res_handler
= NULL
;
3513 wpa_s
->own_scan_running
= 0;
3514 wpa_s
->radio
->external_scan_running
= 0;
3515 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3519 if (!(data
&& data
->scan_info
.external_scan
) &&
3520 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3521 struct os_reltime now
, diff
;
3522 os_get_reltime(&now
);
3523 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3524 wpa_s
->scan_start_time
.sec
= 0;
3525 wpa_s
->scan_start_time
.usec
= 0;
3526 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3527 diff
.sec
, diff
.usec
);
3529 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3530 break; /* interface may have been removed */
3531 if (!(data
&& data
->scan_info
.external_scan
))
3532 wpa_s
->own_scan_running
= 0;
3533 if (data
&& data
->scan_info
.nl_scan_event
)
3534 wpa_s
->radio
->external_scan_running
= 0;
3535 radio_work_check_next(wpa_s
);
3537 #endif /* CONFIG_NO_SCAN_PROCESSING */
3538 case EVENT_ASSOCINFO
:
3539 wpa_supplicant_event_associnfo(wpa_s
, data
);
3541 case EVENT_INTERFACE_STATUS
:
3542 wpa_supplicant_event_interface_status(wpa_s
, data
);
3544 case EVENT_PMKID_CANDIDATE
:
3545 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3547 #ifdef CONFIG_PEERKEY
3548 case EVENT_STKSTART
:
3549 wpa_supplicant_event_stkstart(wpa_s
, data
);
3551 #endif /* CONFIG_PEERKEY */
3554 wpa_supplicant_event_tdls(wpa_s
, data
);
3556 #endif /* CONFIG_TDLS */
3559 wpa_supplicant_event_wnm(wpa_s
, data
);
3561 #endif /* CONFIG_WNM */
3562 #ifdef CONFIG_IEEE80211R
3563 case EVENT_FT_RESPONSE
:
3564 wpa_supplicant_event_ft_response(wpa_s
, data
);
3566 #endif /* CONFIG_IEEE80211R */
3567 #ifdef CONFIG_IBSS_RSN
3568 case EVENT_IBSS_RSN_START
:
3569 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3571 #endif /* CONFIG_IBSS_RSN */
3572 case EVENT_ASSOC_REJECT
:
3573 if (data
->assoc_reject
.bssid
)
3574 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3575 "bssid=" MACSTR
" status_code=%u%s",
3576 MAC2STR(data
->assoc_reject
.bssid
),
3577 data
->assoc_reject
.status_code
,
3578 data
->assoc_reject
.timed_out
? " timeout" : "");
3580 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3582 data
->assoc_reject
.status_code
,
3583 data
->assoc_reject
.timed_out
? " timeout" : "");
3584 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3585 wpas_notify_assoc_status_code(wpa_s
);
3586 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3587 sme_event_assoc_reject(wpa_s
, data
);
3589 const u8
*bssid
= data
->assoc_reject
.bssid
;
3590 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
3591 bssid
= wpa_s
->pending_bssid
;
3592 wpas_connection_failed(wpa_s
, bssid
);
3593 wpa_supplicant_mark_disassoc(wpa_s
);
3596 case EVENT_AUTH_TIMED_OUT
:
3597 /* It is possible to get this event from earlier connection */
3598 if (wpa_s
->current_ssid
&&
3599 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3600 wpa_dbg(wpa_s
, MSG_DEBUG
,
3601 "Ignore AUTH_TIMED_OUT in mesh configuration");
3604 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3605 sme_event_auth_timed_out(wpa_s
, data
);
3607 case EVENT_ASSOC_TIMED_OUT
:
3608 /* It is possible to get this event from earlier connection */
3609 if (wpa_s
->current_ssid
&&
3610 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3611 wpa_dbg(wpa_s
, MSG_DEBUG
,
3612 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3615 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3616 sme_event_assoc_timed_out(wpa_s
, data
);
3618 case EVENT_TX_STATUS
:
3619 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3620 " type=%d stype=%d",
3621 MAC2STR(data
->tx_status
.dst
),
3622 data
->tx_status
.type
, data
->tx_status
.stype
);
3624 if (wpa_s
->ap_iface
== NULL
) {
3625 #ifdef CONFIG_OFFCHANNEL
3626 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3627 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3628 offchannel_send_action_tx_status(
3629 wpa_s
, data
->tx_status
.dst
,
3630 data
->tx_status
.data
,
3631 data
->tx_status
.data_len
,
3632 data
->tx_status
.ack
?
3633 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3634 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3635 #endif /* CONFIG_OFFCHANNEL */
3638 #endif /* CONFIG_AP */
3639 #ifdef CONFIG_OFFCHANNEL
3640 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3641 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
3643 * Catch TX status events for Action frames we sent via group
3644 * interface in GO mode, or via standalone AP interface.
3645 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3646 * except when the primary interface is used as a GO interface
3647 * (for drivers which do not have group interface concurrency)
3649 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3650 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3651 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
3652 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3653 offchannel_send_action_tx_status(
3654 wpa_s
->p2pdev
, data
->tx_status
.dst
,
3655 data
->tx_status
.data
,
3656 data
->tx_status
.data_len
,
3657 data
->tx_status
.ack
?
3658 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3659 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3662 #endif /* CONFIG_OFFCHANNEL */
3664 switch (data
->tx_status
.type
) {
3665 case WLAN_FC_TYPE_MGMT
:
3666 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3667 data
->tx_status
.data_len
,
3668 data
->tx_status
.stype
,
3669 data
->tx_status
.ack
);
3671 case WLAN_FC_TYPE_DATA
:
3672 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3673 data
->tx_status
.data
,
3674 data
->tx_status
.data_len
,
3675 data
->tx_status
.ack
);
3678 #endif /* CONFIG_AP */
3681 case EVENT_EAPOL_TX_STATUS
:
3682 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3683 data
->eapol_tx_status
.data
,
3684 data
->eapol_tx_status
.data_len
,
3685 data
->eapol_tx_status
.ack
);
3687 case EVENT_DRIVER_CLIENT_POLL_OK
:
3688 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
3690 case EVENT_RX_FROM_UNKNOWN
:
3691 if (wpa_s
->ap_iface
== NULL
)
3693 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
3694 data
->rx_from_unknown
.wds
);
3696 case EVENT_CH_SWITCH
:
3697 if (!data
|| !wpa_s
->current_ssid
)
3700 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
3701 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
3702 data
->ch_switch
.freq
,
3703 data
->ch_switch
.ht_enabled
,
3704 data
->ch_switch
.ch_offset
,
3705 channel_width_to_string(data
->ch_switch
.ch_width
),
3706 data
->ch_switch
.cf1
,
3707 data
->ch_switch
.cf2
);
3709 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
3710 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
3712 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
3713 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
3714 wpa_s
->current_ssid
->mode
==
3715 WPAS_MODE_P2P_GROUP_FORMATION
) {
3716 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
3717 data
->ch_switch
.ht_enabled
,
3718 data
->ch_switch
.ch_offset
,
3719 data
->ch_switch
.ch_width
,
3720 data
->ch_switch
.cf1
,
3721 data
->ch_switch
.cf2
);
3724 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
3727 case EVENT_DFS_RADAR_DETECTED
:
3729 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
3731 case EVENT_DFS_CAC_STARTED
:
3733 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
3735 case EVENT_DFS_CAC_FINISHED
:
3737 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
3739 case EVENT_DFS_CAC_ABORTED
:
3741 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
3743 case EVENT_DFS_NOP_FINISHED
:
3745 wpas_event_dfs_cac_nop_finished(wpa_s
,
3748 #endif /* NEED_AP_MLME */
3749 #endif /* CONFIG_AP */
3750 case EVENT_RX_MGMT
: {
3752 const struct ieee80211_mgmt
*mgmt
;
3754 #ifdef CONFIG_TESTING_OPTIONS
3755 if (wpa_s
->ext_mgmt_frame_handling
) {
3756 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
3757 size_t hex_len
= 2 * rx
->frame_len
+ 1;
3758 char *hex
= os_malloc(hex_len
);
3760 wpa_snprintf_hex(hex
, hex_len
,
3761 rx
->frame
, rx
->frame_len
);
3762 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3763 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
3769 #endif /* CONFIG_TESTING_OPTIONS */
3771 mgmt
= (const struct ieee80211_mgmt
*)
3772 data
->rx_mgmt
.frame
;
3773 fc
= le_to_host16(mgmt
->frame_control
);
3774 stype
= WLAN_FC_GET_STYPE(fc
);
3777 if (wpa_s
->ap_iface
== NULL
) {
3778 #endif /* CONFIG_AP */
3780 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3781 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
3782 const u8
*src
= mgmt
->sa
;
3786 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
3787 ie_len
= data
->rx_mgmt
.frame_len
-
3789 wpas_p2p_probe_req_rx(
3790 wpa_s
, src
, mgmt
->da
,
3791 mgmt
->bssid
, ie
, ie_len
,
3793 data
->rx_mgmt
.ssi_signal
);
3796 #endif /* CONFIG_P2P */
3797 #ifdef CONFIG_IBSS_RSN
3798 if (wpa_s
->current_ssid
&&
3799 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
3800 stype
== WLAN_FC_STYPE_AUTH
&&
3801 data
->rx_mgmt
.frame_len
>= 30) {
3802 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
3805 #endif /* CONFIG_IBSS_RSN */
3807 if (stype
== WLAN_FC_STYPE_ACTION
) {
3808 wpas_event_rx_mgmt_action(
3809 wpa_s
, data
->rx_mgmt
.frame
,
3810 data
->rx_mgmt
.frame_len
,
3812 data
->rx_mgmt
.ssi_signal
);
3817 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
3821 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
3822 "management frame in non-AP mode");
3827 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3828 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
3832 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
3833 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
3835 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
3836 mgmt
->bssid
, ie
, ie_len
,
3837 data
->rx_mgmt
.ssi_signal
);
3840 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
3841 #endif /* CONFIG_AP */
3844 case EVENT_RX_PROBE_REQ
:
3845 if (data
->rx_probe_req
.sa
== NULL
||
3846 data
->rx_probe_req
.ie
== NULL
)
3849 if (wpa_s
->ap_iface
) {
3850 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
3851 data
->rx_probe_req
.sa
,
3852 data
->rx_probe_req
.da
,
3853 data
->rx_probe_req
.bssid
,
3854 data
->rx_probe_req
.ie
,
3855 data
->rx_probe_req
.ie_len
,
3856 data
->rx_probe_req
.ssi_signal
);
3859 #endif /* CONFIG_AP */
3860 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
3861 data
->rx_probe_req
.da
,
3862 data
->rx_probe_req
.bssid
,
3863 data
->rx_probe_req
.ie
,
3864 data
->rx_probe_req
.ie_len
,
3866 data
->rx_probe_req
.ssi_signal
);
3868 case EVENT_REMAIN_ON_CHANNEL
:
3869 #ifdef CONFIG_OFFCHANNEL
3870 offchannel_remain_on_channel_cb(
3871 wpa_s
, data
->remain_on_channel
.freq
,
3872 data
->remain_on_channel
.duration
);
3873 #endif /* CONFIG_OFFCHANNEL */
3874 wpas_p2p_remain_on_channel_cb(
3875 wpa_s
, data
->remain_on_channel
.freq
,
3876 data
->remain_on_channel
.duration
);
3878 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
3879 #ifdef CONFIG_OFFCHANNEL
3880 offchannel_cancel_remain_on_channel_cb(
3881 wpa_s
, data
->remain_on_channel
.freq
);
3882 #endif /* CONFIG_OFFCHANNEL */
3883 wpas_p2p_cancel_remain_on_channel_cb(
3884 wpa_s
, data
->remain_on_channel
.freq
);
3886 case EVENT_EAPOL_RX
:
3887 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
3888 data
->eapol_rx
.data
,
3889 data
->eapol_rx
.data_len
);
3891 case EVENT_SIGNAL_CHANGE
:
3892 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
3893 "above=%d signal=%d noise=%d txrate=%d",
3894 data
->signal_change
.above_threshold
,
3895 data
->signal_change
.current_signal
,
3896 data
->signal_change
.current_noise
,
3897 data
->signal_change
.current_txrate
);
3898 wpa_bss_update_level(wpa_s
->current_bss
,
3899 data
->signal_change
.current_signal
);
3900 bgscan_notify_signal_change(
3901 wpa_s
, data
->signal_change
.above_threshold
,
3902 data
->signal_change
.current_signal
,
3903 data
->signal_change
.current_noise
,
3904 data
->signal_change
.current_txrate
);
3906 case EVENT_INTERFACE_ENABLED
:
3907 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
3908 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3909 wpa_supplicant_update_mac_addr(wpa_s
);
3910 if (wpa_s
->p2p_mgmt
) {
3911 wpa_supplicant_set_state(wpa_s
,
3917 if (!wpa_s
->ap_iface
) {
3918 wpa_supplicant_set_state(wpa_s
,
3920 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
3921 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3923 wpa_supplicant_set_state(wpa_s
,
3925 #else /* CONFIG_AP */
3926 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
3927 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3928 #endif /* CONFIG_AP */
3931 case EVENT_INTERFACE_DISABLED
:
3932 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
3934 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
3935 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
3936 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3938 * Mark interface disabled if this happens to end up not
3939 * being removed as a separate P2P group interface.
3941 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3943 * The interface was externally disabled. Remove
3944 * it assuming an external entity will start a
3945 * new session if needed.
3947 if (wpa_s
->current_ssid
&&
3948 wpa_s
->current_ssid
->p2p_group
)
3949 wpas_p2p_interface_unavailable(wpa_s
);
3951 wpas_p2p_disconnect(wpa_s
);
3953 * wpa_s instance may have been freed, so must not use
3958 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
3959 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
3960 /* This radio work will be cancelled, so clear P2P
3963 p2p_stop_find(wpa_s
->global
->p2p
);
3965 #endif /* CONFIG_P2P */
3967 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
3969 * Indicate disconnection to keep ctrl_iface events
3972 wpa_supplicant_event_disassoc(
3973 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
3975 wpa_supplicant_mark_disassoc(wpa_s
);
3976 wpa_bss_flush(wpa_s
);
3977 radio_remove_works(wpa_s
, NULL
, 0);
3979 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3981 case EVENT_CHANNEL_LIST_CHANGED
:
3982 wpa_supplicant_update_channel_list(
3983 wpa_s
, &data
->channel_list_changed
);
3985 case EVENT_INTERFACE_UNAVAILABLE
:
3986 wpas_p2p_interface_unavailable(wpa_s
);
3988 case EVENT_BEST_CHANNEL
:
3989 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
3991 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
3992 data
->best_chan
.freq_overall
);
3993 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
3994 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
3995 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
3996 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
3997 data
->best_chan
.freq_5
,
3998 data
->best_chan
.freq_overall
);
4000 case EVENT_UNPROT_DEAUTH
:
4001 wpa_supplicant_event_unprot_deauth(wpa_s
,
4002 &data
->unprot_deauth
);
4004 case EVENT_UNPROT_DISASSOC
:
4005 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4006 &data
->unprot_disassoc
);
4008 case EVENT_STATION_LOW_ACK
:
4010 if (wpa_s
->ap_iface
&& data
)
4011 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4012 data
->low_ack
.addr
);
4013 #endif /* CONFIG_AP */
4016 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4017 data
->low_ack
.addr
);
4018 #endif /* CONFIG_TDLS */
4020 case EVENT_IBSS_PEER_LOST
:
4021 #ifdef CONFIG_IBSS_RSN
4022 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4023 #endif /* CONFIG_IBSS_RSN */
4025 case EVENT_DRIVER_GTK_REKEY
:
4026 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4027 wpa_s
->bssid
, ETH_ALEN
))
4031 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4032 data
->driver_gtk_rekey
.replay_ctr
);
4034 case EVENT_SCHED_SCAN_STOPPED
:
4035 wpa_s
->sched_scanning
= 0;
4036 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4037 wpa_supplicant_notify_scanning(wpa_s
, 0);
4039 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4043 * Start a new sched scan to continue searching for more SSIDs
4044 * either if timed out or PNO schedule scan is pending.
4046 if (wpa_s
->sched_scan_timed_out
) {
4047 wpa_supplicant_req_sched_scan(wpa_s
);
4048 } else if (wpa_s
->pno_sched_pending
) {
4049 wpa_s
->pno_sched_pending
= 0;
4050 wpas_start_pno(wpa_s
);
4051 } else if (resched
) {
4052 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4056 case EVENT_WPS_BUTTON_PUSHED
:
4058 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4059 #endif /* CONFIG_WPS */
4061 case EVENT_AVOID_FREQUENCIES
:
4062 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4064 case EVENT_CONNECT_FAILED_REASON
:
4066 if (!wpa_s
->ap_iface
|| !data
)
4068 hostapd_event_connect_failed_reason(
4069 wpa_s
->ap_iface
->bss
[0],
4070 data
->connect_failed_reason
.addr
,
4071 data
->connect_failed_reason
.code
);
4072 #endif /* CONFIG_AP */
4074 case EVENT_NEW_PEER_CANDIDATE
:
4076 if (!wpa_s
->ifmsh
|| !data
)
4078 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4079 data
->mesh_peer
.ies
,
4080 data
->mesh_peer
.ie_len
);
4081 #endif /* CONFIG_MESH */
4085 if (!wpa_s
->ap_iface
)
4087 hostapd_event_get_survey(wpa_s
->ap_iface
,
4088 &data
->survey_results
);
4089 #endif /* CONFIG_AP */
4091 case EVENT_ACS_CHANNEL_SELECTED
:
4093 if (!wpa_s
->ap_iface
)
4095 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4096 &data
->acs_selected_channels
);
4097 #endif /* CONFIG_ACS */
4099 case EVENT_P2P_LO_STOP
:
4101 wpa_s
->p2p_lo_started
= 0;
4102 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4103 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4104 data
->p2p_lo_stop
.reason_code
);
4105 #endif /* CONFIG_P2P */
4108 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4114 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4115 union wpa_event_data
*data
)
4117 struct wpa_supplicant
*wpa_s
;
4119 if (event
!= EVENT_INTERFACE_STATUS
)
4122 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4123 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4124 unsigned int ifindex
;
4126 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4127 if (ifindex
!= data
->interface_status
.ifindex
) {
4128 wpa_dbg(wpa_s
, MSG_DEBUG
,
4129 "interface status ifindex %d mismatch (%d)",
4130 ifindex
, data
->interface_status
.ifindex
);
4134 #ifdef CONFIG_MATCH_IFACE
4135 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4136 struct wpa_interface
*wpa_i
;
4138 wpa_i
= wpa_supplicant_match_iface(
4139 ctx
, data
->interface_status
.ifname
);
4142 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4147 #endif /* CONFIG_MATCH_IFACE */
4150 wpa_supplicant_event(wpa_s
, event
, data
);