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 #ifdef CONFIG_TESTING_OPTIONS
1105 if (wpa_s
->ignore_assoc_disallow
)
1106 goto skip_assoc_disallow
;
1107 #endif /* CONFIG_TESTING_OPTIONS */
1108 assoc_disallow
= wpas_mbo_get_bss_attr(
1109 bss
, MBO_ATTR_ID_ASSOC_DISALLOW
);
1110 if (assoc_disallow
&& assoc_disallow
[1] >= 1) {
1111 wpa_dbg(wpa_s
, MSG_DEBUG
,
1112 " skip - MBO association disallowed (reason %u)",
1117 if (wpa_is_bss_tmp_disallowed(wpa_s
, bss
->bssid
)) {
1118 wpa_dbg(wpa_s
, MSG_DEBUG
,
1119 " skip - MBO retry delay has not passed yet");
1122 #ifdef CONFIG_TESTING_OPTIONS
1123 skip_assoc_disallow
:
1124 #endif /* CONFIG_TESTING_OPTIONS */
1125 #endif /* CONFIG_MBO */
1127 /* Matching configuration found */
1131 /* No matching configuration found */
1136 static struct wpa_bss
*
1137 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
1138 struct wpa_ssid
*group
,
1139 struct wpa_ssid
**selected_ssid
,
1140 int only_first_ssid
)
1144 if (only_first_ssid
)
1145 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
1148 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
1151 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
1152 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
1153 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
1155 if (!*selected_ssid
)
1157 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
1159 MAC2STR(bss
->bssid
),
1160 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1168 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
1169 struct wpa_ssid
**selected_ssid
)
1171 struct wpa_bss
*selected
= NULL
;
1173 struct wpa_ssid
*next_ssid
= NULL
;
1174 struct wpa_ssid
*ssid
;
1176 if (wpa_s
->last_scan_res
== NULL
||
1177 wpa_s
->last_scan_res_used
== 0)
1178 return NULL
; /* no scan results from last update */
1180 if (wpa_s
->next_ssid
) {
1181 /* check that next_ssid is still valid */
1182 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1183 if (ssid
== wpa_s
->next_ssid
)
1187 wpa_s
->next_ssid
= NULL
;
1190 while (selected
== NULL
) {
1191 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1192 if (next_ssid
&& next_ssid
->priority
==
1193 wpa_s
->conf
->pssid
[prio
]->priority
) {
1194 selected
= wpa_supplicant_select_bss(
1195 wpa_s
, next_ssid
, selected_ssid
, 1);
1199 selected
= wpa_supplicant_select_bss(
1200 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1206 if (selected
== NULL
&& wpa_s
->blacklist
&&
1207 !wpa_s
->countermeasures
) {
1208 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1209 "blacklist and try again");
1210 wpa_blacklist_clear(wpa_s
);
1211 wpa_s
->blacklist_cleared
++;
1212 } else if (selected
== NULL
)
1216 ssid
= *selected_ssid
;
1217 if (selected
&& ssid
&& ssid
->mem_only_psk
&& !ssid
->psk_set
&&
1218 !ssid
->passphrase
&& !ssid
->ext_psk
) {
1219 const char *field_name
, *txt
= NULL
;
1221 wpa_dbg(wpa_s
, MSG_DEBUG
,
1222 "PSK/passphrase not yet available for the selected network");
1224 wpas_notify_network_request(wpa_s
, ssid
,
1225 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
);
1227 field_name
= wpa_supplicant_ctrl_req_to_string(
1228 WPA_CTRL_REQ_PSK_PASSPHRASE
, NULL
, &txt
);
1229 if (field_name
== NULL
)
1232 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
1241 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1242 int timeout_sec
, int timeout_usec
)
1244 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1246 * No networks are enabled; short-circuit request so
1247 * we don't wait timeout seconds before transitioning
1248 * to INACTIVE state.
1250 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1251 "since there are no enabled networks");
1252 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1256 wpa_s
->scan_for_connection
= 1;
1257 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1261 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1262 struct wpa_bss
*selected
,
1263 struct wpa_ssid
*ssid
)
1265 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1266 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1267 "PBC session overlap");
1268 wpas_notify_wps_event_pbc_overlap(wpa_s
);
1270 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
1271 wpa_s
->p2p_in_provisioning
) {
1272 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb
,
1276 #endif /* CONFIG_P2P */
1279 wpas_wps_pbc_overlap(wpa_s
);
1280 wpas_wps_cancel(wpa_s
);
1281 #endif /* CONFIG_WPS */
1285 wpa_msg(wpa_s
, MSG_DEBUG
,
1286 "Considering connect request: reassociate: %d selected: "
1287 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1288 " wpa_state: %s ssid=%p current_ssid=%p",
1289 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1290 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1291 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1292 ssid
, wpa_s
->current_ssid
);
1295 * Do not trigger new association unless the BSSID has changed or if
1296 * reassociation is requested. If we are in process of associating with
1297 * the selected BSSID, do not trigger new attempt.
1299 if (wpa_s
->reassociate
||
1300 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1301 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1302 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1303 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1304 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1306 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1307 ssid
!= wpa_s
->current_ssid
)))) {
1308 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1309 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1312 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1313 MAC2STR(selected
->bssid
));
1314 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1316 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1317 "connect with the selected AP");
1324 static struct wpa_ssid
*
1325 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1328 struct wpa_ssid
*ssid
;
1330 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1331 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1333 if (wpas_network_disabled(wpa_s
, ssid
))
1335 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1336 ssid
->mode
== IEEE80211_MODE_AP
||
1337 ssid
->mode
== IEEE80211_MODE_MESH
)
1345 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1346 * on BSS added and BSS changed events */
1347 static void wpa_supplicant_rsn_preauth_scan_results(
1348 struct wpa_supplicant
*wpa_s
)
1350 struct wpa_bss
*bss
;
1352 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1355 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1356 const u8
*ssid
, *rsn
;
1358 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1362 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1366 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1372 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1373 struct wpa_bss
*selected
,
1374 struct wpa_ssid
*ssid
)
1376 struct wpa_bss
*current_bss
= NULL
;
1377 #ifndef CONFIG_NO_ROAMING
1380 #endif /* CONFIG_NO_ROAMING */
1382 if (wpa_s
->reassociate
)
1383 return 1; /* explicit request to reassociate */
1384 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1385 return 1; /* we are not associated; continue */
1386 if (wpa_s
->current_ssid
== NULL
)
1387 return 1; /* unknown current SSID */
1388 if (wpa_s
->current_ssid
!= ssid
)
1389 return 1; /* different network block */
1391 if (wpas_driver_bss_selection(wpa_s
))
1392 return 0; /* Driver-based roaming */
1394 if (wpa_s
->current_ssid
->ssid
)
1395 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1396 wpa_s
->current_ssid
->ssid
,
1397 wpa_s
->current_ssid
->ssid_len
);
1399 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1402 return 1; /* current BSS not seen in scan results */
1404 if (current_bss
== selected
)
1407 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1408 return 1; /* current BSS not seen in the last scan */
1410 #ifndef CONFIG_NO_ROAMING
1411 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1412 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
1413 " level=%d snr=%d est_throughput=%u",
1414 MAC2STR(current_bss
->bssid
), current_bss
->level
,
1415 current_bss
->snr
, current_bss
->est_throughput
);
1416 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
1417 " level=%d snr=%d est_throughput=%u",
1418 MAC2STR(selected
->bssid
), selected
->level
,
1419 selected
->snr
, selected
->est_throughput
);
1421 if (wpa_s
->current_ssid
->bssid_set
&&
1422 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1424 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1425 "has preferred BSSID");
1429 if (selected
->est_throughput
> current_bss
->est_throughput
+ 5000) {
1430 wpa_dbg(wpa_s
, MSG_DEBUG
,
1431 "Allow reassociation - selected BSS has better estimated throughput");
1435 to_5ghz
= selected
->freq
> 4000 && current_bss
->freq
< 4000;
1437 if (current_bss
->level
< 0 &&
1438 current_bss
->level
> selected
->level
+ to_5ghz
* 2) {
1439 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1445 if (current_bss
->level
< 0) {
1446 if (current_bss
->level
< -85)
1448 else if (current_bss
->level
< -80)
1450 else if (current_bss
->level
< -75)
1452 else if (current_bss
->level
< -70)
1458 /* Make it easier to move to 5 GHz band */
1464 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
1465 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
1471 #else /* CONFIG_NO_ROAMING */
1473 #endif /* CONFIG_NO_ROAMING */
1477 /* Return != 0 if no scan results could be fetched or if scan results should not
1478 * be shared with other virtual interfaces. */
1479 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1480 union wpa_event_data
*data
,
1483 struct wpa_scan_results
*scan_res
= NULL
;
1486 #ifndef CONFIG_NO_RANDOM_POOL
1488 #endif /* CONFIG_NO_RANDOM_POOL */
1491 if (wpa_s
->ap_iface
)
1493 #endif /* CONFIG_AP */
1495 wpa_supplicant_notify_scanning(wpa_s
, 0);
1497 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1498 data
? &data
->scan_info
:
1500 if (scan_res
== NULL
) {
1501 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1502 wpa_s
->scan_res_handler
== scan_only_handler
)
1506 if (data
&& data
->scan_info
.external_scan
)
1508 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1510 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1512 goto scan_work_done
;
1515 #ifndef CONFIG_NO_RANDOM_POOL
1516 num
= scan_res
->num
;
1519 for (i
= 0; i
< num
; i
++) {
1521 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1522 buf
[0] = res
->bssid
[5];
1523 buf
[1] = res
->qual
& 0xff;
1524 buf
[2] = res
->noise
& 0xff;
1525 buf
[3] = res
->level
& 0xff;
1526 buf
[4] = res
->tsf
& 0xff;
1527 random_add_randomness(buf
, sizeof(buf
));
1529 #endif /* CONFIG_NO_RANDOM_POOL */
1531 if (own_request
&& wpa_s
->scan_res_handler
&&
1532 !(data
&& data
->scan_info
.external_scan
)) {
1533 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1534 struct wpa_scan_results
*scan_res
);
1536 scan_res_handler
= wpa_s
->scan_res_handler
;
1537 wpa_s
->scan_res_handler
= NULL
;
1538 scan_res_handler(wpa_s
, scan_res
);
1540 goto scan_work_done
;
1544 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1546 if (wpa_s
->ap_iface
->scan_cb
)
1547 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1548 #endif /* CONFIG_AP */
1549 goto scan_work_done
;
1552 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1553 wpa_s
->own_scan_running
,
1554 data
? data
->scan_info
.external_scan
: 0);
1555 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1556 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
&&
1557 own_request
&& !(data
&& data
->scan_info
.external_scan
)) {
1558 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1559 wpa_s
->manual_scan_id
);
1560 wpa_s
->manual_scan_use_id
= 0;
1562 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1564 wpas_notify_scan_results(wpa_s
);
1566 wpas_notify_scan_done(wpa_s
, 1);
1568 if (data
&& data
->scan_info
.external_scan
) {
1569 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1570 wpa_scan_results_free(scan_res
);
1574 if (wnm_scan_process(wpa_s
, 1) > 0)
1575 goto scan_work_done
;
1577 if (sme_proc_obss_scan(wpa_s
) > 0)
1578 goto scan_work_done
;
1580 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1581 goto scan_work_done
;
1583 if (autoscan_notify_scan(wpa_s
, scan_res
))
1584 goto scan_work_done
;
1586 if (wpa_s
->disconnected
) {
1587 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1588 goto scan_work_done
;
1591 if (!wpas_driver_bss_selection(wpa_s
) &&
1592 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1593 goto scan_work_done
;
1595 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1597 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
&&
1598 wpa_s
->wpa_state
< WPA_COMPLETED
)
1599 goto scan_work_done
;
1601 wpa_scan_results_free(scan_res
);
1603 if (own_request
&& wpa_s
->scan_work
) {
1604 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1605 wpa_s
->scan_work
= NULL
;
1606 radio_work_done(work
);
1609 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1612 wpa_scan_results_free(scan_res
);
1613 if (own_request
&& wpa_s
->scan_work
) {
1614 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1615 wpa_s
->scan_work
= NULL
;
1616 radio_work_done(work
);
1622 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1623 int new_scan
, int own_request
)
1625 struct wpa_bss
*selected
;
1626 struct wpa_ssid
*ssid
= NULL
;
1627 int time_to_reenable
= wpas_reenabled_network_time(wpa_s
);
1629 if (time_to_reenable
> 0) {
1630 wpa_dbg(wpa_s
, MSG_DEBUG
,
1631 "Postpone network selection by %d seconds since all networks are disabled",
1633 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
1634 eloop_register_timeout(time_to_reenable
, 0,
1635 wpas_network_reenabled
, wpa_s
, NULL
);
1639 if (wpa_s
->p2p_mgmt
)
1640 return 0; /* no normal connection on p2p_mgmt interface */
1642 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1646 wpa_msg(wpa_s
, MSG_INFO
,
1647 "Avoiding join because we already joined a mesh group");
1650 #endif /* CONFIG_MESH */
1654 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1657 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1661 if (ssid
!= wpa_s
->current_ssid
&&
1662 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1663 wpa_s
->own_disconnect_req
= 1;
1664 wpa_supplicant_deauthenticate(
1665 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1668 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1669 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1673 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1675 * Do not notify other virtual radios of scan results since we do not
1676 * want them to start other associations at the same time.
1680 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1681 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1683 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1684 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1686 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1687 } else if (own_request
) {
1689 * No SSID found. If SCAN results are as a result of
1690 * own scan request and not due to a scan request on
1691 * another shared interface, try another scan.
1693 int timeout_sec
= wpa_s
->scan_interval
;
1694 int timeout_usec
= 0;
1698 res
= wpas_p2p_scan_no_go_seen(wpa_s
);
1704 if (wpa_s
->p2p_in_provisioning
||
1705 wpa_s
->show_group_started
||
1706 wpa_s
->p2p_in_invitation
) {
1708 * Use shorter wait during P2P Provisioning
1709 * state and during P2P join-a-group operation
1710 * to speed up group formation.
1713 timeout_usec
= 250000;
1714 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1718 #endif /* CONFIG_P2P */
1719 #ifdef CONFIG_INTERWORKING
1720 if (wpa_s
->conf
->auto_interworking
&&
1721 wpa_s
->conf
->interworking
&&
1722 wpa_s
->conf
->cred
) {
1723 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1724 "start ANQP fetch since no matching "
1726 wpa_s
->network_select
= 1;
1727 wpa_s
->auto_network_select
= 1;
1728 interworking_start_fetch_anqp(wpa_s
);
1731 #endif /* CONFIG_INTERWORKING */
1733 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1734 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1736 timeout_usec
= 500000;
1737 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1741 #endif /* CONFIG_WPS */
1742 if (wpa_supplicant_req_sched_scan(wpa_s
))
1743 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1746 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1747 WPA_EVENT_NETWORK_NOT_FOUND
);
1754 static int wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1755 union wpa_event_data
*data
)
1757 struct wpa_supplicant
*ifs
;
1760 res
= _wpa_supplicant_event_scan_results(wpa_s
, data
, 1);
1763 * Interface may have been removed, so must not dereference
1770 * If no scan results could be fetched, then no need to
1771 * notify those interfaces that did not actually request
1772 * this scan. Similarly, if scan results started a new operation on this
1773 * interface, do not notify other interfaces to avoid concurrent
1774 * operations during a connection attempt.
1780 * Check other interfaces to see if they share the same radio. If
1781 * so, they get updated with this same scan info.
1783 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1786 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1787 "sibling", ifs
->ifname
);
1788 _wpa_supplicant_event_scan_results(ifs
, data
, 0);
1795 #endif /* CONFIG_NO_SCAN_PROCESSING */
1798 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1800 #ifdef CONFIG_NO_SCAN_PROCESSING
1802 #else /* CONFIG_NO_SCAN_PROCESSING */
1803 struct os_reltime now
;
1805 if (wpa_s
->last_scan_res_used
== 0)
1808 os_get_reltime(&now
);
1809 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1810 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1814 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1815 #endif /* CONFIG_NO_SCAN_PROCESSING */
1820 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1822 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1824 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1827 if (!wpa_s
->no_keep_alive
) {
1828 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1829 MAC2STR(wpa_s
->bssid
));
1830 /* TODO: could skip this if normal data traffic has been sent */
1831 /* TODO: Consider using some more appropriate data frame for
1834 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
1839 if (wpa_s
->sme
.bss_max_idle_period
) {
1841 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
1844 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1845 wnm_bss_keep_alive
, wpa_s
, NULL
);
1847 #endif /* CONFIG_SME */
1851 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1852 const u8
*ies
, size_t ies_len
)
1854 struct ieee802_11_elems elems
;
1859 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1863 if (elems
.bss_max_idle_period
) {
1865 wpa_s
->sme
.bss_max_idle_period
=
1866 WPA_GET_LE16(elems
.bss_max_idle_period
);
1867 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
1868 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
1869 (elems
.bss_max_idle_period
[2] & 0x01) ?
1870 " (protected keep-live required)" : "");
1871 if (wpa_s
->sme
.bss_max_idle_period
== 0)
1872 wpa_s
->sme
.bss_max_idle_period
= 1;
1873 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
1874 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1875 /* msec times 1000 */
1876 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
1879 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1880 wnm_bss_keep_alive
, wpa_s
,
1884 #endif /* CONFIG_SME */
1887 #endif /* CONFIG_WNM */
1890 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
1893 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1894 #endif /* CONFIG_WNM */
1898 #ifdef CONFIG_INTERWORKING
1900 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
1905 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
1906 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
1908 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
1915 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1916 const u8
*ies
, size_t ies_len
)
1918 struct ieee802_11_elems elems
;
1923 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1926 if (elems
.qos_map_set
) {
1927 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
1928 elems
.qos_map_set_len
);
1932 #endif /* CONFIG_INTERWORKING */
1936 static int wpas_fst_update_mbie(struct wpa_supplicant
*wpa_s
,
1937 const u8
*ie
, size_t ie_len
)
1939 struct mb_ies_info mb_ies
;
1941 if (!ie
|| !ie_len
|| !wpa_s
->fst
)
1944 os_memset(&mb_ies
, 0, sizeof(mb_ies
));
1946 while (ie_len
>= 2 && mb_ies
.nof_ies
< MAX_NOF_MB_IES_SUPPORTED
) {
1951 wpa_hexdump(MSG_DEBUG
, "FST: Truncated IE found",
1956 if (ie
[0] == WLAN_EID_MULTI_BAND
) {
1957 wpa_printf(MSG_DEBUG
, "MB IE of %u bytes found",
1958 (unsigned int) len
);
1959 mb_ies
.ies
[mb_ies
.nof_ies
].ie
= ie
+ 2;
1960 mb_ies
.ies
[mb_ies
.nof_ies
].ie_len
= len
- 2;
1968 if (mb_ies
.nof_ies
> 0) {
1969 wpabuf_free(wpa_s
->received_mb_ies
);
1970 wpa_s
->received_mb_ies
= mb_ies_by_info(&mb_ies
);
1976 #endif /* CONFIG_FST */
1979 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1980 union wpa_event_data
*data
)
1982 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1984 #ifdef CONFIG_IEEE80211R
1986 #endif /* CONFIG_IEEE80211R */
1988 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1989 if (data
->assoc_info
.req_ies
)
1990 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1991 data
->assoc_info
.req_ies_len
);
1992 if (data
->assoc_info
.resp_ies
) {
1993 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1994 data
->assoc_info
.resp_ies_len
);
1996 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1997 data
->assoc_info
.resp_ies_len
);
1998 #endif /* CONFIG_TDLS */
2000 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2001 data
->assoc_info
.resp_ies_len
);
2002 #endif /* CONFIG_WNM */
2003 #ifdef CONFIG_INTERWORKING
2004 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
2005 data
->assoc_info
.resp_ies_len
);
2006 #endif /* CONFIG_INTERWORKING */
2008 if (data
->assoc_info
.beacon_ies
)
2009 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
2010 data
->assoc_info
.beacon_ies
,
2011 data
->assoc_info
.beacon_ies_len
);
2012 if (data
->assoc_info
.freq
)
2013 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
2014 data
->assoc_info
.freq
);
2016 p
= data
->assoc_info
.req_ies
;
2017 l
= data
->assoc_info
.req_ies_len
;
2019 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
2020 while (p
&& l
>= 2) {
2023 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2027 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2028 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2029 (p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 4 &&
2030 (os_memcmp(&p
[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2031 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
2032 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
2035 wpa_find_assoc_pmkid(wpa_s
);
2041 if (!found
&& data
->assoc_info
.req_ies
)
2042 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2044 #ifdef CONFIG_IEEE80211R
2046 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
2047 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2048 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2049 data
->assoc_info
.resp_ies
,
2050 data
->assoc_info
.resp_ies_len
,
2052 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2053 "Reassociation Response failed");
2054 wpa_supplicant_deauthenticate(
2055 wpa_s
, WLAN_REASON_INVALID_IE
);
2060 p
= data
->assoc_info
.resp_ies
;
2061 l
= data
->assoc_info
.resp_ies_len
;
2063 #ifdef CONFIG_WPS_STRICT
2064 if (p
&& wpa_s
->current_ssid
&&
2065 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2067 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
2069 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
2070 "include WPS IE in (Re)Association Response");
2074 if (wps_validate_assoc_resp(wps
) < 0) {
2076 wpa_supplicant_deauthenticate(
2077 wpa_s
, WLAN_REASON_INVALID_IE
);
2082 #endif /* CONFIG_WPS_STRICT */
2084 /* Go through the IEs and make a copy of the MDIE, if present. */
2085 while (p
&& l
>= 2) {
2088 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
2092 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
2093 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2094 wpa_s
->sme
.ft_used
= 1;
2095 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
2096 MOBILITY_DOMAIN_ID_LEN
);
2102 #endif /* CONFIG_SME */
2104 /* Process FT when SME is in the driver */
2105 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2106 wpa_ft_is_completed(wpa_s
->wpa
)) {
2107 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
2108 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
2109 data
->assoc_info
.resp_ies
,
2110 data
->assoc_info
.resp_ies_len
,
2112 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
2113 "Reassociation Response failed");
2114 wpa_supplicant_deauthenticate(
2115 wpa_s
, WLAN_REASON_INVALID_IE
);
2118 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
2121 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
2122 data
->assoc_info
.resp_ies_len
);
2123 #endif /* CONFIG_IEEE80211R */
2125 /* WPA/RSN IE from Beacon/ProbeResp */
2126 p
= data
->assoc_info
.beacon_ies
;
2127 l
= data
->assoc_info
.beacon_ies_len
;
2129 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2131 wpa_found
= rsn_found
= 0;
2132 while (p
&& l
>= 2) {
2135 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
2140 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
2141 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2143 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
2147 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
2149 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
2156 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
2157 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2158 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
2159 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
2160 if (wpa_found
|| rsn_found
)
2161 wpa_s
->ap_ies_from_associnfo
= 1;
2163 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
2164 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
2165 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
2167 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
2168 wpa_supplicant_update_scan_results(wpa_s
);
2171 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
2177 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
2179 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
2181 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
2184 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
2187 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2188 WPA_IE_VENDOR_TYPE
);
2189 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
2191 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
2192 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
2193 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
2194 bss_rsn
? 2 + bss_rsn
[1] : 0))
2201 static void wpas_fst_update_mb_assoc(struct wpa_supplicant
*wpa_s
,
2202 union wpa_event_data
*data
)
2205 struct assoc_info
*ai
= data
? &data
->assoc_info
: NULL
;
2206 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2207 const u8
*ieprb
, *iebcn
;
2209 wpabuf_free(wpa_s
->received_mb_ies
);
2210 wpa_s
->received_mb_ies
= NULL
;
2213 !wpas_fst_update_mbie(wpa_s
, ai
->resp_ies
, ai
->resp_ies_len
)) {
2214 wpa_printf(MSG_DEBUG
,
2215 "FST: MB IEs updated from Association Response frame");
2220 !wpas_fst_update_mbie(wpa_s
, ai
->beacon_ies
, ai
->beacon_ies_len
)) {
2221 wpa_printf(MSG_DEBUG
,
2222 "FST: MB IEs updated from association event Beacon IEs");
2229 ieprb
= (const u8
*) (bss
+ 1);
2230 iebcn
= ieprb
+ bss
->ie_len
;
2232 if (!wpas_fst_update_mbie(wpa_s
, ieprb
, bss
->ie_len
))
2233 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss IE");
2234 else if (!wpas_fst_update_mbie(wpa_s
, iebcn
, bss
->beacon_ie_len
))
2235 wpa_printf(MSG_DEBUG
, "FST: MB IEs updated from bss beacon IE");
2236 #endif /* CONFIG_FST */
2240 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
2241 union wpa_event_data
*data
)
2244 int ft_completed
, already_authorized
;
2248 if (wpa_s
->ap_iface
) {
2251 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
2252 data
->assoc_info
.addr
,
2253 data
->assoc_info
.req_ies
,
2254 data
->assoc_info
.req_ies_len
,
2255 data
->assoc_info
.reassoc
);
2258 #endif /* CONFIG_AP */
2260 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
2262 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
2263 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
2266 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2267 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
2268 wpa_supplicant_deauthenticate(
2269 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2273 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
2274 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
2275 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
2276 MACSTR
, MAC2STR(bssid
));
2278 random_add_randomness(bssid
, ETH_ALEN
);
2279 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
2280 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2281 wpas_notify_bssid_changed(wpa_s
);
2283 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
2284 wpa_clear_keys(wpa_s
, bssid
);
2286 if (wpa_supplicant_select_config(wpa_s
) < 0) {
2287 wpa_supplicant_deauthenticate(
2288 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2293 if (wpa_s
->conf
->ap_scan
== 1 &&
2294 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
2295 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0 && new_bss
)
2296 wpa_msg(wpa_s
, MSG_WARNING
,
2297 "WPA/RSN IEs not updated");
2300 wpas_fst_update_mb_assoc(wpa_s
, data
);
2303 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
2304 wpa_s
->sme
.prev_bssid_set
= 1;
2305 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
2306 #endif /* CONFIG_SME */
2308 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
2309 if (wpa_s
->current_ssid
) {
2310 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2311 * initialized before association, but for other modes,
2312 * initialize PC/SC here, if the current configuration needs
2313 * smartcard or SIM/USIM. */
2314 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
2316 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
2318 l2_packet_notify_auth_start(wpa_s
->l2
);
2320 already_authorized
= data
&& data
->assoc_info
.authorized
;
2323 * Set portEnabled first to FALSE in order to get EAP state machine out
2324 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2325 * state machine may transit to AUTHENTICATING state based on obsolete
2326 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2327 * AUTHENTICATED without ever giving chance to EAP state machine to
2330 if (!ft_completed
&& !already_authorized
) {
2331 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2332 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2334 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
||
2336 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
2337 /* 802.1X::portControl = Auto */
2338 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
2339 wpa_s
->eapol_received
= 0;
2340 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2341 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
2342 (wpa_s
->current_ssid
&&
2343 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
2344 if (wpa_s
->current_ssid
&&
2345 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
2347 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2349 * Set the key after having received joined-IBSS event
2352 wpa_supplicant_set_wpa_none_key(wpa_s
,
2353 wpa_s
->current_ssid
);
2355 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2356 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2357 } else if (!ft_completed
) {
2358 /* Timeout for receiving the first EAPOL packet */
2359 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
2361 wpa_supplicant_cancel_scan(wpa_s
);
2363 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2364 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
2366 * We are done; the driver will take care of RSN 4-way
2369 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2370 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2371 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2372 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2373 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2374 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2376 * The driver will take care of RSN 4-way handshake, so we need
2377 * to allow EAPOL supplicant to complete its work without
2378 * waiting for WPA supplicant.
2380 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2381 } else if (ft_completed
) {
2383 * FT protocol completed - make sure EAPOL state machine ends
2384 * up in authenticated.
2386 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2387 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2388 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2389 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
2392 wpa_s
->last_eapol_matches_bssid
= 0;
2394 if (wpa_s
->pending_eapol_rx
) {
2395 struct os_reltime now
, age
;
2396 os_get_reltime(&now
);
2397 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
2398 if (age
.sec
== 0 && age
.usec
< 100000 &&
2399 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
2401 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
2402 "frame that was received just before "
2403 "association notification");
2404 wpa_supplicant_rx_eapol(
2405 wpa_s
, wpa_s
->pending_eapol_rx_src
,
2406 wpabuf_head(wpa_s
->pending_eapol_rx
),
2407 wpabuf_len(wpa_s
->pending_eapol_rx
));
2409 wpabuf_free(wpa_s
->pending_eapol_rx
);
2410 wpa_s
->pending_eapol_rx
= NULL
;
2413 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2414 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2415 wpa_s
->current_ssid
&&
2416 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2417 /* Set static WEP keys again */
2418 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2421 #ifdef CONFIG_IBSS_RSN
2422 if (wpa_s
->current_ssid
&&
2423 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2424 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2425 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2426 wpa_s
->ibss_rsn
== NULL
) {
2427 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
, wpa_s
->current_ssid
);
2428 if (!wpa_s
->ibss_rsn
) {
2429 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2430 wpa_supplicant_deauthenticate(
2431 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2435 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2437 #endif /* CONFIG_IBSS_RSN */
2439 wpas_wps_notify_assoc(wpa_s
, bssid
);
2442 wmm_ac_notify_assoc(wpa_s
, data
->assoc_info
.resp_ies
,
2443 data
->assoc_info
.resp_ies_len
,
2444 &data
->assoc_info
.wmm_params
);
2446 if (wpa_s
->reassoc_same_bss
)
2447 wmm_ac_restore_tspecs(wpa_s
);
2452 static int disconnect_reason_recoverable(u16 reason_code
)
2454 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2455 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2456 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2460 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2462 int locally_generated
)
2466 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2468 * At least Host AP driver and a Prism3 card seemed to be
2469 * generating streams of disconnected events when configuring
2470 * IBSS for WPA-None. Ignore them for now.
2475 bssid
= wpa_s
->bssid
;
2476 if (is_zero_ether_addr(bssid
))
2477 bssid
= wpa_s
->pending_bssid
;
2479 if (!is_zero_ether_addr(bssid
) ||
2480 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2481 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2483 MAC2STR(bssid
), reason_code
,
2484 locally_generated
? " locally_generated=1" : "");
2489 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2490 int locally_generated
)
2492 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2493 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2494 return 0; /* Not in 4-way handshake with PSK */
2497 * It looks like connection was lost while trying to go through PSK
2498 * 4-way handshake. Filter out known disconnection cases that are caused
2499 * by something else than PSK mismatch to avoid confusing reports.
2502 if (locally_generated
) {
2503 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2511 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2513 int locally_generated
)
2517 u8 prev_pending_bssid
[ETH_ALEN
];
2518 struct wpa_bss
*fast_reconnect
= NULL
;
2519 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2520 struct wpa_ssid
*last_ssid
;
2522 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2523 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2525 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2527 * At least Host AP driver and a Prism3 card seemed to be
2528 * generating streams of disconnected events when configuring
2529 * IBSS for WPA-None. Ignore them for now.
2531 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2532 "IBSS/WPA-None mode");
2536 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2537 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2538 "pre-shared key may be incorrect");
2539 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2540 return; /* P2P group removed */
2541 wpas_auth_failed(wpa_s
, "WRONG_KEY");
2543 if (!wpa_s
->disconnected
&&
2544 (!wpa_s
->auto_reconnect_disabled
||
2545 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
||
2546 wpas_wps_searching(wpa_s
) ||
2547 wpas_wps_reenable_networks_pending(wpa_s
))) {
2548 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2549 "reconnect (wps=%d/%d wpa_state=%d)",
2550 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2551 wpas_wps_searching(wpa_s
),
2553 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2554 wpa_s
->current_ssid
&&
2555 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2556 !locally_generated
&&
2557 disconnect_reason_recoverable(reason_code
)) {
2559 * It looks like the AP has dropped association with
2560 * us, but could allow us to get back in. Try to
2561 * reconnect to the same BSS without full scan to save
2562 * time for some common cases.
2564 fast_reconnect
= wpa_s
->current_bss
;
2565 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2566 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2567 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2569 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2572 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2573 "try to re-connect");
2574 wpa_s
->reassociate
= 0;
2575 wpa_s
->disconnected
= 1;
2577 wpa_supplicant_cancel_sched_scan(wpa_s
);
2579 bssid
= wpa_s
->bssid
;
2580 if (is_zero_ether_addr(bssid
))
2581 bssid
= wpa_s
->pending_bssid
;
2582 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2583 wpas_connection_failed(wpa_s
, bssid
);
2584 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2585 if (locally_generated
)
2586 wpa_s
->disconnect_reason
= -reason_code
;
2588 wpa_s
->disconnect_reason
= reason_code
;
2589 wpas_notify_disconnect_reason(wpa_s
);
2590 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2591 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2592 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2594 last_ssid
= wpa_s
->current_ssid
;
2595 wpa_supplicant_mark_disassoc(wpa_s
);
2597 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2598 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2599 wpa_s
->current_ssid
= last_ssid
;
2602 if (fast_reconnect
&&
2603 !wpas_network_disabled(wpa_s
, fast_reconnect_ssid
) &&
2604 !disallowed_bssid(wpa_s
, fast_reconnect
->bssid
) &&
2605 !disallowed_ssid(wpa_s
, fast_reconnect
->ssid
,
2606 fast_reconnect
->ssid_len
) &&
2607 !wpas_temp_disabled(wpa_s
, fast_reconnect_ssid
) &&
2608 !wpa_is_bss_tmp_disallowed(wpa_s
, fast_reconnect
->bssid
)) {
2609 #ifndef CONFIG_NO_SCAN_PROCESSING
2610 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2611 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2612 fast_reconnect_ssid
) < 0) {
2613 /* Recover through full scan */
2614 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2616 #endif /* CONFIG_NO_SCAN_PROCESSING */
2617 } else if (fast_reconnect
) {
2619 * Could not reconnect to the same BSS due to network being
2620 * disabled. Use a new scan to match the alternative behavior
2621 * above, i.e., to continue automatic reconnection attempt in a
2622 * way that enforces disabled network rules.
2624 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2629 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2630 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2632 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2634 if (!wpa_s
->pending_mic_error_report
)
2637 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2638 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2639 wpa_s
->pending_mic_error_report
= 0;
2641 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2645 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2646 union wpa_event_data
*data
)
2649 struct os_reltime t
;
2651 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2652 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2654 if ((wpa_s
->last_michael_mic_error
.sec
&&
2655 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2656 wpa_s
->pending_mic_error_report
) {
2657 if (wpa_s
->pending_mic_error_report
) {
2659 * Send the pending MIC error report immediately since
2660 * we are going to start countermeasures and AP better
2663 wpa_sm_key_request(wpa_s
->wpa
, 1,
2664 wpa_s
->pending_mic_error_pairwise
);
2667 /* Send the new MIC error report immediately since we are going
2668 * to start countermeasures and AP better do the same.
2670 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2672 /* initialize countermeasures */
2673 wpa_s
->countermeasures
= 1;
2675 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2677 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2680 * Need to wait for completion of request frame. We do not get
2681 * any callback for the message completion, so just wait a
2682 * short while and hope for the best. */
2685 wpa_drv_set_countermeasures(wpa_s
, 1);
2686 wpa_supplicant_deauthenticate(wpa_s
,
2687 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2688 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2690 eloop_register_timeout(60, 0,
2691 wpa_supplicant_stop_countermeasures
,
2693 /* TODO: mark the AP rejected for 60 second. STA is
2694 * allowed to associate with another AP.. */
2696 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2697 if (wpa_s
->mic_errors_seen
) {
2699 * Reduce the effectiveness of Michael MIC error
2700 * reports as a means for attacking against TKIP if
2701 * more than one MIC failure is noticed with the same
2702 * PTK. We delay the transmission of the reports by a
2703 * random time between 0 and 60 seconds in order to
2704 * force the attacker wait 60 seconds before getting
2705 * the information on whether a frame resulted in a MIC
2711 if (os_get_random(rval
, sizeof(rval
)) < 0)
2712 sec
= os_random() % 60;
2714 sec
= WPA_GET_BE32(rval
) % 60;
2715 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2716 "report %d seconds", sec
);
2717 wpa_s
->pending_mic_error_report
= 1;
2718 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2719 eloop_cancel_timeout(
2720 wpa_supplicant_delayed_mic_error_report
,
2722 eloop_register_timeout(
2723 sec
, os_random() % 1000000,
2724 wpa_supplicant_delayed_mic_error_report
,
2727 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2729 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2730 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2731 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2733 wpa_s
->last_michael_mic_error
= t
;
2734 wpa_s
->mic_errors_seen
++;
2738 #ifdef CONFIG_TERMINATE_ONLASTIF
2739 static int any_interfaces(struct wpa_supplicant
*head
)
2741 struct wpa_supplicant
*wpa_s
;
2743 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2744 if (!wpa_s
->interface_removed
)
2748 #endif /* CONFIG_TERMINATE_ONLASTIF */
2752 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2753 union wpa_event_data
*data
)
2755 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2758 switch (data
->interface_status
.ievent
) {
2759 case EVENT_INTERFACE_ADDED
:
2760 if (!wpa_s
->interface_removed
)
2762 wpa_s
->interface_removed
= 0;
2763 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
2764 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
2765 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
2766 "driver after interface was added");
2770 if (!wpa_s
->global
->p2p
&&
2771 !wpa_s
->global
->p2p_disabled
&&
2772 !wpa_s
->conf
->p2p_disabled
&&
2774 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
2775 wpas_p2p_add_p2pdev_interface(
2776 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
2777 wpa_printf(MSG_INFO
,
2778 "P2P: Failed to enable P2P Device interface");
2779 /* Try to continue without. P2P will be disabled. */
2781 #endif /* CONFIG_P2P */
2784 case EVENT_INTERFACE_REMOVED
:
2785 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
2786 wpa_s
->interface_removed
= 1;
2787 wpa_supplicant_mark_disassoc(wpa_s
);
2788 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2789 l2_packet_deinit(wpa_s
->l2
);
2793 if (wpa_s
->global
->p2p
&&
2794 wpa_s
->global
->p2p_init_wpa_s
->parent
== wpa_s
&&
2796 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) {
2797 wpa_dbg(wpa_s
, MSG_DEBUG
,
2798 "Removing P2P Device interface");
2799 wpa_supplicant_remove_iface(
2800 wpa_s
->global
, wpa_s
->global
->p2p_init_wpa_s
,
2802 wpa_s
->global
->p2p_init_wpa_s
= NULL
;
2804 #endif /* CONFIG_P2P */
2806 #ifdef CONFIG_MATCH_IFACE
2807 if (wpa_s
->matched
) {
2808 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
2811 #endif /* CONFIG_MATCH_IFACE */
2813 #ifdef CONFIG_TERMINATE_ONLASTIF
2814 /* check if last interface */
2815 if (!any_interfaces(wpa_s
->global
->ifaces
))
2817 #endif /* CONFIG_TERMINATE_ONLASTIF */
2823 #ifdef CONFIG_PEERKEY
2825 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
2826 union wpa_event_data
*data
)
2830 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
2832 #endif /* CONFIG_PEERKEY */
2836 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
2837 union wpa_event_data
*data
)
2841 switch (data
->tdls
.oper
) {
2842 case TDLS_REQUEST_SETUP
:
2843 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
2844 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2845 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
2847 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
2849 case TDLS_REQUEST_TEARDOWN
:
2850 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2851 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
2852 data
->tdls
.reason_code
);
2854 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
2857 case TDLS_REQUEST_DISCOVER
:
2858 wpa_tdls_send_discovery_request(wpa_s
->wpa
,
2863 #endif /* CONFIG_TDLS */
2867 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
2868 union wpa_event_data
*data
)
2872 switch (data
->wnm
.oper
) {
2873 case WNM_OPER_SLEEP
:
2874 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
2875 "(action=%d, intval=%d)",
2876 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
2877 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
2878 data
->wnm
.sleep_intval
, NULL
);
2882 #endif /* CONFIG_WNM */
2885 #ifdef CONFIG_IEEE80211R
2887 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
2888 union wpa_event_data
*data
)
2893 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
2894 data
->ft_ies
.ies_len
,
2895 data
->ft_ies
.ft_action
,
2896 data
->ft_ies
.target_ap
,
2897 data
->ft_ies
.ric_ies
,
2898 data
->ft_ies
.ric_ies_len
) < 0) {
2899 /* TODO: prevent MLME/driver from trying to associate? */
2902 #endif /* CONFIG_IEEE80211R */
2905 #ifdef CONFIG_IBSS_RSN
2906 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
2907 union wpa_event_data
*data
)
2909 struct wpa_ssid
*ssid
;
2910 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2914 ssid
= wpa_s
->current_ssid
;
2917 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2920 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
2924 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
2925 union wpa_event_data
*data
)
2927 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2932 /* check if the ssid is correctly configured as IBSS/RSN */
2933 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2936 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
2937 data
->rx_mgmt
.frame_len
);
2939 #endif /* CONFIG_IBSS_RSN */
2942 #ifdef CONFIG_IEEE80211R
2943 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
2946 const u8
*sta_addr
, *target_ap_addr
;
2949 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
2950 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2951 return; /* only SME case supported for now */
2952 if (len
< 1 + 2 * ETH_ALEN
+ 2)
2955 return; /* Only FT Action Response is supported for now */
2956 sta_addr
= data
+ 1;
2957 target_ap_addr
= data
+ 1 + ETH_ALEN
;
2958 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
2959 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
2960 MACSTR
" TargetAP " MACSTR
" status %u",
2961 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
2963 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
2964 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
2965 " in FT Action Response", MAC2STR(sta_addr
));
2970 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
2971 "failure (status code %d)", status
);
2972 /* TODO: report error to FT code(?) */
2976 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
2977 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
2978 target_ap_addr
, NULL
, 0) < 0)
2983 struct wpa_bss
*bss
;
2984 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
2986 wpa_s
->sme
.freq
= bss
->freq
;
2987 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
2988 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
2991 #endif /* CONFIG_SME */
2993 #endif /* CONFIG_IEEE80211R */
2996 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
2997 struct unprot_deauth
*e
)
2999 #ifdef CONFIG_IEEE80211W
3000 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
3001 "dropped: " MACSTR
" -> " MACSTR
3002 " (reason code %u)",
3003 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3004 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3005 #endif /* CONFIG_IEEE80211W */
3009 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
3010 struct unprot_disassoc
*e
)
3012 #ifdef CONFIG_IEEE80211W
3013 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
3014 "dropped: " MACSTR
" -> " MACSTR
3015 " (reason code %u)",
3016 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
3017 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
3018 #endif /* CONFIG_IEEE80211W */
3022 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3023 u16 reason_code
, int locally_generated
,
3024 const u8
*ie
, size_t ie_len
, int deauth
)
3027 if (wpa_s
->ap_iface
&& addr
) {
3028 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
3032 if (wpa_s
->ap_iface
) {
3033 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
3036 #endif /* CONFIG_AP */
3038 if (!locally_generated
)
3039 wpa_s
->own_disconnect_req
= 0;
3041 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
3043 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
3044 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3045 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
3046 eapol_sm_failed(wpa_s
->eapol
))) &&
3047 !wpa_s
->eap_expected_failure
))
3048 wpas_auth_failed(wpa_s
, "AUTH_FAILED");
3051 if (deauth
&& reason_code
> 0) {
3052 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
3053 locally_generated
) > 0) {
3055 * The interface was removed, so cannot continue
3056 * processing any additional operations after this.
3061 #endif /* CONFIG_P2P */
3063 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
3068 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
3069 struct disassoc_info
*info
)
3071 u16 reason_code
= 0;
3072 int locally_generated
= 0;
3073 const u8
*addr
= NULL
;
3074 const u8
*ie
= NULL
;
3077 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
3082 ie_len
= info
->ie_len
;
3083 reason_code
= info
->reason_code
;
3084 locally_generated
= info
->locally_generated
;
3085 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
3086 locally_generated
? " (locally generated)" : "");
3088 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3090 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
3095 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
3096 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
3100 if (wpa_s
->ap_iface
) {
3101 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
3104 #endif /* CONFIG_AP */
3108 wpas_p2p_disassoc_notif(
3109 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
3112 #endif /* CONFIG_P2P */
3114 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3115 sme_event_disassoc(wpa_s
, info
);
3117 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
3122 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
3123 struct deauth_info
*info
)
3125 u16 reason_code
= 0;
3126 int locally_generated
= 0;
3127 const u8
*addr
= NULL
;
3128 const u8
*ie
= NULL
;
3131 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
3136 ie_len
= info
->ie_len
;
3137 reason_code
= info
->reason_code
;
3138 locally_generated
= info
->locally_generated
;
3139 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
3141 locally_generated
? " (locally generated)" : "");
3143 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
3146 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
3150 wpa_reset_ft_completed(wpa_s
->wpa
);
3152 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
3153 locally_generated
, ie
, ie_len
, 1);
3157 static const char * reg_init_str(enum reg_change_initiator init
)
3160 case REGDOM_SET_BY_CORE
:
3162 case REGDOM_SET_BY_USER
:
3164 case REGDOM_SET_BY_DRIVER
:
3166 case REGDOM_SET_BY_COUNTRY_IE
:
3167 return "COUNTRY_IE";
3168 case REGDOM_BEACON_HINT
:
3169 return "BEACON_HINT";
3175 static const char * reg_type_str(enum reg_type type
)
3178 case REGDOM_TYPE_UNKNOWN
:
3180 case REGDOM_TYPE_COUNTRY
:
3182 case REGDOM_TYPE_WORLD
:
3184 case REGDOM_TYPE_CUSTOM_WORLD
:
3185 return "CUSTOM_WORLD";
3186 case REGDOM_TYPE_INTERSECTION
:
3187 return "INTERSECTION";
3193 static void wpa_supplicant_update_channel_list(
3194 struct wpa_supplicant
*wpa_s
, struct channel_list_changed
*info
)
3196 struct wpa_supplicant
*ifs
;
3199 * To allow backwards compatibility with higher level layers that
3200 * assumed the REGDOM_CHANGE event is sent over the initially added
3201 * interface. Find the highest parent of this interface and use it to
3204 for (ifs
= wpa_s
; ifs
->parent
&& ifs
!= ifs
->parent
; ifs
= ifs
->parent
)
3207 wpa_msg(ifs
, MSG_INFO
, WPA_EVENT_REGDOM_CHANGE
"init=%s type=%s%s%s",
3208 reg_init_str(info
->initiator
), reg_type_str(info
->type
),
3209 info
->alpha2
[0] ? " alpha2=" : "",
3210 info
->alpha2
[0] ? info
->alpha2
: "");
3212 if (wpa_s
->drv_priv
== NULL
)
3213 return; /* Ignore event during drv initialization */
3215 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
3217 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
3219 free_hw_features(ifs
);
3220 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
3221 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
);
3223 /* Restart PNO/sched_scan with updated channel list */
3226 wpas_start_pno(ifs
);
3227 } else if (ifs
->sched_scanning
&& !ifs
->pno_sched_pending
) {
3228 wpa_dbg(ifs
, MSG_DEBUG
,
3229 "Channel list changed - restart sched_scan");
3230 wpas_scan_restart_sched_scan(ifs
);
3234 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DRIVER
);
3238 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
3239 const u8
*frame
, size_t len
, int freq
,
3242 const struct ieee80211_mgmt
*mgmt
;
3247 if (len
< IEEE80211_HDRLEN
+ 2)
3250 mgmt
= (const struct ieee80211_mgmt
*) frame
;
3251 payload
= frame
+ IEEE80211_HDRLEN
;
3252 category
= *payload
++;
3253 plen
= len
- IEEE80211_HDRLEN
- 1;
3255 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
3256 " Category=%u DataLen=%d freq=%d MHz",
3257 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
3259 if (category
== WLAN_ACTION_WMM
) {
3260 wmm_ac_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, payload
, plen
);
3264 #ifdef CONFIG_IEEE80211R
3265 if (category
== WLAN_ACTION_FT
) {
3266 ft_rx_action(wpa_s
, payload
, plen
);
3269 #endif /* CONFIG_IEEE80211R */
3271 #ifdef CONFIG_IEEE80211W
3273 if (category
== WLAN_ACTION_SA_QUERY
) {
3274 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
3277 #endif /* CONFIG_SME */
3278 #endif /* CONFIG_IEEE80211W */
3281 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
3282 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
3285 #endif /* CONFIG_WNM */
3288 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
3289 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
3290 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3291 mgmt
->u
.action
.category
,
3292 payload
, plen
, freq
) == 0)
3294 #endif /* CONFIG_GAS */
3297 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
3298 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
3299 wpa_dbg(wpa_s
, MSG_DEBUG
,
3300 "TDLS: Received Discovery Response from " MACSTR
,
3304 #endif /* CONFIG_TDLS */
3306 #ifdef CONFIG_INTERWORKING
3307 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
3308 payload
[0] == QOS_QOS_MAP_CONFIG
) {
3309 const u8
*pos
= payload
+ 1;
3310 size_t qlen
= plen
- 1;
3311 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
3312 MACSTR
, MAC2STR(mgmt
->sa
));
3313 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
3314 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
3315 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
3316 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
3319 #endif /* CONFIG_INTERWORKING */
3321 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3322 payload
[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST
) {
3323 wpas_rrm_handle_radio_measurement_request(wpa_s
, mgmt
->sa
,
3329 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3330 payload
[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE
) {
3331 wpas_rrm_process_neighbor_rep(wpa_s
, payload
+ 1, plen
- 1);
3335 if (category
== WLAN_ACTION_RADIO_MEASUREMENT
&&
3336 payload
[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST
) {
3337 wpas_rrm_handle_link_measurement_request(wpa_s
, mgmt
->sa
,
3338 payload
+ 1, plen
- 1,
3344 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& wpa_s
->fst
) {
3345 fst_rx_action(wpa_s
->fst
, mgmt
, len
);
3348 #endif /* CONFIG_FST */
3350 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
3351 category
, payload
, plen
, freq
);
3353 mesh_mpm_action_rx(wpa_s
, mgmt
, len
);
3357 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
3358 union wpa_event_data
*event
)
3360 struct wpa_freq_range_list
*list
;
3363 list
= &event
->freq_range
;
3366 str
= freq_range_list_str(list
);
3367 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
3371 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
3372 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
3375 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
3378 * The update channel flow will also take care of moving a GO
3379 * from the unsafe frequency if needed.
3381 wpas_p2p_update_channel_list(wpa_s
,
3382 WPAS_P2P_CHANNEL_UPDATE_AVOID
);
3384 #endif /* CONFIG_P2P */
3390 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant
*wpa_s
,
3391 union wpa_event_data
*data
)
3393 wpa_dbg(wpa_s
, MSG_DEBUG
,
3394 "Connection authorized by device, previous state %d",
3396 if (wpa_s
->wpa_state
== WPA_ASSOCIATED
) {
3397 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3398 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3399 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3400 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
3402 wpa_sm_set_rx_replay_ctr(wpa_s
->wpa
, data
->assoc_info
.key_replay_ctr
);
3403 wpa_sm_set_ptk_kck_kek(wpa_s
->wpa
, data
->assoc_info
.ptk_kck
,
3404 data
->assoc_info
.ptk_kck_len
,
3405 data
->assoc_info
.ptk_kek
,
3406 data
->assoc_info
.ptk_kek_len
);
3410 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
3411 union wpa_event_data
*data
)
3413 struct wpa_supplicant
*wpa_s
= ctx
;
3416 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
3417 event
!= EVENT_INTERFACE_ENABLED
&&
3418 event
!= EVENT_INTERFACE_STATUS
&&
3419 event
!= EVENT_SCAN_RESULTS
&&
3420 event
!= EVENT_SCHED_SCAN_STOPPED
) {
3421 wpa_dbg(wpa_s
, MSG_DEBUG
,
3422 "Ignore event %s (%d) while interface is disabled",
3423 event_to_string(event
), event
);
3427 #ifndef CONFIG_NO_STDOUT_DEBUG
3429 int level
= MSG_DEBUG
;
3431 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
3432 const struct ieee80211_hdr
*hdr
;
3434 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
3435 fc
= le_to_host16(hdr
->frame_control
);
3436 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
3437 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
3438 level
= MSG_EXCESSIVE
;
3441 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
3442 event_to_string(event
), event
);
3444 #endif /* CONFIG_NO_STDOUT_DEBUG */
3449 if (!wpas_fst_update_mbie(wpa_s
, data
->auth
.ies
,
3450 data
->auth
.ies_len
))
3451 wpa_printf(MSG_DEBUG
,
3452 "FST: MB IEs updated from auth IE");
3453 #endif /* CONFIG_FST */
3454 sme_event_auth(wpa_s
, data
);
3457 #ifdef CONFIG_TESTING_OPTIONS
3458 if (wpa_s
->ignore_auth_resp
) {
3459 wpa_printf(MSG_INFO
,
3460 "EVENT_ASSOC - ignore_auth_resp active!");
3463 #endif /* CONFIG_TESTING_OPTIONS */
3464 wpa_supplicant_event_assoc(wpa_s
, data
);
3465 if (data
&& data
->assoc_info
.authorized
)
3466 wpa_supplicant_event_assoc_auth(wpa_s
, data
);
3468 wpa_msg(wpa_s
, MSG_INFO
,
3469 WPA_EVENT_SUBNET_STATUS_UPDATE
"status=%u",
3470 data
->assoc_info
.subnet_status
);
3473 case EVENT_DISASSOC
:
3474 wpas_event_disassoc(wpa_s
,
3475 data
? &data
->disassoc_info
: NULL
);
3478 #ifdef CONFIG_TESTING_OPTIONS
3479 if (wpa_s
->ignore_auth_resp
) {
3480 wpa_printf(MSG_INFO
,
3481 "EVENT_DEAUTH - ignore_auth_resp active!");
3484 #endif /* CONFIG_TESTING_OPTIONS */
3485 wpas_event_deauth(wpa_s
,
3486 data
? &data
->deauth_info
: NULL
);
3488 case EVENT_MICHAEL_MIC_FAILURE
:
3489 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
3491 #ifndef CONFIG_NO_SCAN_PROCESSING
3492 case EVENT_SCAN_STARTED
:
3493 if (wpa_s
->own_scan_requested
||
3494 (data
&& !data
->scan_info
.external_scan
)) {
3495 struct os_reltime diff
;
3497 os_get_reltime(&wpa_s
->scan_start_time
);
3498 os_reltime_sub(&wpa_s
->scan_start_time
,
3499 &wpa_s
->scan_trigger_time
, &diff
);
3500 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
3501 diff
.sec
, diff
.usec
);
3502 wpa_s
->own_scan_requested
= 0;
3503 wpa_s
->own_scan_running
= 1;
3504 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
3505 wpa_s
->manual_scan_use_id
) {
3506 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3507 WPA_EVENT_SCAN_STARTED
"id=%u",
3508 wpa_s
->manual_scan_id
);
3510 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
3511 WPA_EVENT_SCAN_STARTED
);
3514 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
3515 wpa_s
->radio
->external_scan_running
= 1;
3516 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
3519 case EVENT_SCAN_RESULTS
:
3520 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3521 wpa_s
->scan_res_handler
= NULL
;
3522 wpa_s
->own_scan_running
= 0;
3523 wpa_s
->radio
->external_scan_running
= 0;
3524 wpa_s
->last_scan_req
= NORMAL_SCAN_REQ
;
3528 if (!(data
&& data
->scan_info
.external_scan
) &&
3529 os_reltime_initialized(&wpa_s
->scan_start_time
)) {
3530 struct os_reltime now
, diff
;
3531 os_get_reltime(&now
);
3532 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
3533 wpa_s
->scan_start_time
.sec
= 0;
3534 wpa_s
->scan_start_time
.usec
= 0;
3535 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
3536 diff
.sec
, diff
.usec
);
3538 if (wpa_supplicant_event_scan_results(wpa_s
, data
))
3539 break; /* interface may have been removed */
3540 if (!(data
&& data
->scan_info
.external_scan
))
3541 wpa_s
->own_scan_running
= 0;
3542 if (data
&& data
->scan_info
.nl_scan_event
)
3543 wpa_s
->radio
->external_scan_running
= 0;
3544 radio_work_check_next(wpa_s
);
3546 #endif /* CONFIG_NO_SCAN_PROCESSING */
3547 case EVENT_ASSOCINFO
:
3548 wpa_supplicant_event_associnfo(wpa_s
, data
);
3550 case EVENT_INTERFACE_STATUS
:
3551 wpa_supplicant_event_interface_status(wpa_s
, data
);
3553 case EVENT_PMKID_CANDIDATE
:
3554 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
3556 #ifdef CONFIG_PEERKEY
3557 case EVENT_STKSTART
:
3558 wpa_supplicant_event_stkstart(wpa_s
, data
);
3560 #endif /* CONFIG_PEERKEY */
3563 wpa_supplicant_event_tdls(wpa_s
, data
);
3565 #endif /* CONFIG_TDLS */
3568 wpa_supplicant_event_wnm(wpa_s
, data
);
3570 #endif /* CONFIG_WNM */
3571 #ifdef CONFIG_IEEE80211R
3572 case EVENT_FT_RESPONSE
:
3573 wpa_supplicant_event_ft_response(wpa_s
, data
);
3575 #endif /* CONFIG_IEEE80211R */
3576 #ifdef CONFIG_IBSS_RSN
3577 case EVENT_IBSS_RSN_START
:
3578 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
3580 #endif /* CONFIG_IBSS_RSN */
3581 case EVENT_ASSOC_REJECT
:
3582 if (data
->assoc_reject
.bssid
)
3583 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3584 "bssid=" MACSTR
" status_code=%u%s",
3585 MAC2STR(data
->assoc_reject
.bssid
),
3586 data
->assoc_reject
.status_code
,
3587 data
->assoc_reject
.timed_out
? " timeout" : "");
3589 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
3591 data
->assoc_reject
.status_code
,
3592 data
->assoc_reject
.timed_out
? " timeout" : "");
3593 wpa_s
->assoc_status_code
= data
->assoc_reject
.status_code
;
3594 wpas_notify_assoc_status_code(wpa_s
);
3595 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3596 sme_event_assoc_reject(wpa_s
, data
);
3598 const u8
*bssid
= data
->assoc_reject
.bssid
;
3599 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
3600 bssid
= wpa_s
->pending_bssid
;
3601 wpas_connection_failed(wpa_s
, bssid
);
3602 wpa_supplicant_mark_disassoc(wpa_s
);
3605 case EVENT_AUTH_TIMED_OUT
:
3606 /* It is possible to get this event from earlier connection */
3607 if (wpa_s
->current_ssid
&&
3608 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3609 wpa_dbg(wpa_s
, MSG_DEBUG
,
3610 "Ignore AUTH_TIMED_OUT in mesh configuration");
3613 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3614 sme_event_auth_timed_out(wpa_s
, data
);
3616 case EVENT_ASSOC_TIMED_OUT
:
3617 /* It is possible to get this event from earlier connection */
3618 if (wpa_s
->current_ssid
&&
3619 wpa_s
->current_ssid
->mode
== WPAS_MODE_MESH
) {
3620 wpa_dbg(wpa_s
, MSG_DEBUG
,
3621 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3624 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3625 sme_event_assoc_timed_out(wpa_s
, data
);
3627 case EVENT_TX_STATUS
:
3628 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3629 " type=%d stype=%d",
3630 MAC2STR(data
->tx_status
.dst
),
3631 data
->tx_status
.type
, data
->tx_status
.stype
);
3633 if (wpa_s
->ap_iface
== NULL
) {
3634 #ifdef CONFIG_OFFCHANNEL
3635 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3636 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3637 offchannel_send_action_tx_status(
3638 wpa_s
, data
->tx_status
.dst
,
3639 data
->tx_status
.data
,
3640 data
->tx_status
.data_len
,
3641 data
->tx_status
.ack
?
3642 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3643 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3644 #endif /* CONFIG_OFFCHANNEL */
3647 #endif /* CONFIG_AP */
3648 #ifdef CONFIG_OFFCHANNEL
3649 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3650 MACSTR
, MAC2STR(wpa_s
->p2pdev
->pending_action_dst
));
3652 * Catch TX status events for Action frames we sent via group
3653 * interface in GO mode, or via standalone AP interface.
3654 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
3655 * except when the primary interface is used as a GO interface
3656 * (for drivers which do not have group interface concurrency)
3658 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3659 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3660 os_memcmp(wpa_s
->p2pdev
->pending_action_dst
,
3661 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3662 offchannel_send_action_tx_status(
3663 wpa_s
->p2pdev
, data
->tx_status
.dst
,
3664 data
->tx_status
.data
,
3665 data
->tx_status
.data_len
,
3666 data
->tx_status
.ack
?
3667 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3668 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3671 #endif /* CONFIG_OFFCHANNEL */
3673 switch (data
->tx_status
.type
) {
3674 case WLAN_FC_TYPE_MGMT
:
3675 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3676 data
->tx_status
.data_len
,
3677 data
->tx_status
.stype
,
3678 data
->tx_status
.ack
);
3680 case WLAN_FC_TYPE_DATA
:
3681 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3682 data
->tx_status
.data
,
3683 data
->tx_status
.data_len
,
3684 data
->tx_status
.ack
);
3687 #endif /* CONFIG_AP */
3690 case EVENT_EAPOL_TX_STATUS
:
3691 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3692 data
->eapol_tx_status
.data
,
3693 data
->eapol_tx_status
.data_len
,
3694 data
->eapol_tx_status
.ack
);
3696 case EVENT_DRIVER_CLIENT_POLL_OK
:
3697 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
3699 case EVENT_RX_FROM_UNKNOWN
:
3700 if (wpa_s
->ap_iface
== NULL
)
3702 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
3703 data
->rx_from_unknown
.wds
);
3705 case EVENT_CH_SWITCH
:
3706 if (!data
|| !wpa_s
->current_ssid
)
3709 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CHANNEL_SWITCH
3710 "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
3711 data
->ch_switch
.freq
,
3712 data
->ch_switch
.ht_enabled
,
3713 data
->ch_switch
.ch_offset
,
3714 channel_width_to_string(data
->ch_switch
.ch_width
),
3715 data
->ch_switch
.cf1
,
3716 data
->ch_switch
.cf2
);
3718 wpa_s
->assoc_freq
= data
->ch_switch
.freq
;
3719 wpa_s
->current_ssid
->frequency
= data
->ch_switch
.freq
;
3721 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_AP
||
3722 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
3723 wpa_s
->current_ssid
->mode
==
3724 WPAS_MODE_P2P_GROUP_FORMATION
) {
3725 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
3726 data
->ch_switch
.ht_enabled
,
3727 data
->ch_switch
.ch_offset
,
3728 data
->ch_switch
.ch_width
,
3729 data
->ch_switch
.cf1
,
3730 data
->ch_switch
.cf2
);
3733 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_CS
);
3736 case EVENT_DFS_RADAR_DETECTED
:
3738 wpas_event_dfs_radar_detected(wpa_s
, &data
->dfs_event
);
3740 case EVENT_DFS_CAC_STARTED
:
3742 wpas_event_dfs_cac_started(wpa_s
, &data
->dfs_event
);
3744 case EVENT_DFS_CAC_FINISHED
:
3746 wpas_event_dfs_cac_finished(wpa_s
, &data
->dfs_event
);
3748 case EVENT_DFS_CAC_ABORTED
:
3750 wpas_event_dfs_cac_aborted(wpa_s
, &data
->dfs_event
);
3752 case EVENT_DFS_NOP_FINISHED
:
3754 wpas_event_dfs_cac_nop_finished(wpa_s
,
3757 #endif /* NEED_AP_MLME */
3758 #endif /* CONFIG_AP */
3759 case EVENT_RX_MGMT
: {
3761 const struct ieee80211_mgmt
*mgmt
;
3763 #ifdef CONFIG_TESTING_OPTIONS
3764 if (wpa_s
->ext_mgmt_frame_handling
) {
3765 struct rx_mgmt
*rx
= &data
->rx_mgmt
;
3766 size_t hex_len
= 2 * rx
->frame_len
+ 1;
3767 char *hex
= os_malloc(hex_len
);
3769 wpa_snprintf_hex(hex
, hex_len
,
3770 rx
->frame
, rx
->frame_len
);
3771 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3772 rx
->freq
, rx
->datarate
, rx
->ssi_signal
,
3778 #endif /* CONFIG_TESTING_OPTIONS */
3780 mgmt
= (const struct ieee80211_mgmt
*)
3781 data
->rx_mgmt
.frame
;
3782 fc
= le_to_host16(mgmt
->frame_control
);
3783 stype
= WLAN_FC_GET_STYPE(fc
);
3786 if (wpa_s
->ap_iface
== NULL
) {
3787 #endif /* CONFIG_AP */
3789 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3790 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
3791 const u8
*src
= mgmt
->sa
;
3795 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
3796 ie_len
= data
->rx_mgmt
.frame_len
-
3798 wpas_p2p_probe_req_rx(
3799 wpa_s
, src
, mgmt
->da
,
3800 mgmt
->bssid
, ie
, ie_len
,
3802 data
->rx_mgmt
.ssi_signal
);
3805 #endif /* CONFIG_P2P */
3806 #ifdef CONFIG_IBSS_RSN
3807 if (wpa_s
->current_ssid
&&
3808 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
3809 stype
== WLAN_FC_STYPE_AUTH
&&
3810 data
->rx_mgmt
.frame_len
>= 30) {
3811 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
3814 #endif /* CONFIG_IBSS_RSN */
3816 if (stype
== WLAN_FC_STYPE_ACTION
) {
3817 wpas_event_rx_mgmt_action(
3818 wpa_s
, data
->rx_mgmt
.frame
,
3819 data
->rx_mgmt
.frame_len
,
3821 data
->rx_mgmt
.ssi_signal
);
3826 mesh_mpm_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
3830 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
3831 "management frame in non-AP mode");
3836 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3837 data
->rx_mgmt
.frame_len
> IEEE80211_HDRLEN
) {
3841 ie
= data
->rx_mgmt
.frame
+ IEEE80211_HDRLEN
;
3842 ie_len
= data
->rx_mgmt
.frame_len
- IEEE80211_HDRLEN
;
3844 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
3845 mgmt
->bssid
, ie
, ie_len
,
3846 data
->rx_mgmt
.ssi_signal
);
3849 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
3850 #endif /* CONFIG_AP */
3853 case EVENT_RX_PROBE_REQ
:
3854 if (data
->rx_probe_req
.sa
== NULL
||
3855 data
->rx_probe_req
.ie
== NULL
)
3858 if (wpa_s
->ap_iface
) {
3859 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
3860 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
,
3865 data
->rx_probe_req
.ssi_signal
);
3868 #endif /* CONFIG_AP */
3869 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
3870 data
->rx_probe_req
.da
,
3871 data
->rx_probe_req
.bssid
,
3872 data
->rx_probe_req
.ie
,
3873 data
->rx_probe_req
.ie_len
,
3875 data
->rx_probe_req
.ssi_signal
);
3877 case EVENT_REMAIN_ON_CHANNEL
:
3878 #ifdef CONFIG_OFFCHANNEL
3879 offchannel_remain_on_channel_cb(
3880 wpa_s
, data
->remain_on_channel
.freq
,
3881 data
->remain_on_channel
.duration
);
3882 #endif /* CONFIG_OFFCHANNEL */
3883 wpas_p2p_remain_on_channel_cb(
3884 wpa_s
, data
->remain_on_channel
.freq
,
3885 data
->remain_on_channel
.duration
);
3887 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
3888 #ifdef CONFIG_OFFCHANNEL
3889 offchannel_cancel_remain_on_channel_cb(
3890 wpa_s
, data
->remain_on_channel
.freq
);
3891 #endif /* CONFIG_OFFCHANNEL */
3892 wpas_p2p_cancel_remain_on_channel_cb(
3893 wpa_s
, data
->remain_on_channel
.freq
);
3895 case EVENT_EAPOL_RX
:
3896 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
3897 data
->eapol_rx
.data
,
3898 data
->eapol_rx
.data_len
);
3900 case EVENT_SIGNAL_CHANGE
:
3901 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SIGNAL_CHANGE
3902 "above=%d signal=%d noise=%d txrate=%d",
3903 data
->signal_change
.above_threshold
,
3904 data
->signal_change
.current_signal
,
3905 data
->signal_change
.current_noise
,
3906 data
->signal_change
.current_txrate
);
3907 wpa_bss_update_level(wpa_s
->current_bss
,
3908 data
->signal_change
.current_signal
);
3909 bgscan_notify_signal_change(
3910 wpa_s
, data
->signal_change
.above_threshold
,
3911 data
->signal_change
.current_signal
,
3912 data
->signal_change
.current_noise
,
3913 data
->signal_change
.current_txrate
);
3915 case EVENT_INTERFACE_ENABLED
:
3916 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
3917 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3918 wpa_supplicant_update_mac_addr(wpa_s
);
3919 if (wpa_s
->p2p_mgmt
) {
3920 wpa_supplicant_set_state(wpa_s
,
3926 if (!wpa_s
->ap_iface
) {
3927 wpa_supplicant_set_state(wpa_s
,
3929 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
3930 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3932 wpa_supplicant_set_state(wpa_s
,
3934 #else /* CONFIG_AP */
3935 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
3936 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3937 #endif /* CONFIG_AP */
3940 case EVENT_INTERFACE_DISABLED
:
3941 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
3943 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
3944 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
3945 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3947 * Mark interface disabled if this happens to end up not
3948 * being removed as a separate P2P group interface.
3950 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3952 * The interface was externally disabled. Remove
3953 * it assuming an external entity will start a
3954 * new session if needed.
3956 if (wpa_s
->current_ssid
&&
3957 wpa_s
->current_ssid
->p2p_group
)
3958 wpas_p2p_interface_unavailable(wpa_s
);
3960 wpas_p2p_disconnect(wpa_s
);
3962 * wpa_s instance may have been freed, so must not use
3967 if (wpa_s
->p2p_scan_work
&& wpa_s
->global
->p2p
&&
3968 p2p_in_progress(wpa_s
->global
->p2p
) > 1) {
3969 /* This radio work will be cancelled, so clear P2P
3972 p2p_stop_find(wpa_s
->global
->p2p
);
3974 #endif /* CONFIG_P2P */
3976 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
3978 * Indicate disconnection to keep ctrl_iface events
3981 wpa_supplicant_event_disassoc(
3982 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
, 1);
3984 wpa_supplicant_mark_disassoc(wpa_s
);
3985 wpa_bss_flush(wpa_s
);
3986 radio_remove_works(wpa_s
, NULL
, 0);
3988 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3990 case EVENT_CHANNEL_LIST_CHANGED
:
3991 wpa_supplicant_update_channel_list(
3992 wpa_s
, &data
->channel_list_changed
);
3994 case EVENT_INTERFACE_UNAVAILABLE
:
3995 wpas_p2p_interface_unavailable(wpa_s
);
3997 case EVENT_BEST_CHANNEL
:
3998 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
4000 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
4001 data
->best_chan
.freq_overall
);
4002 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
4003 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
4004 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
4005 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
4006 data
->best_chan
.freq_5
,
4007 data
->best_chan
.freq_overall
);
4009 case EVENT_UNPROT_DEAUTH
:
4010 wpa_supplicant_event_unprot_deauth(wpa_s
,
4011 &data
->unprot_deauth
);
4013 case EVENT_UNPROT_DISASSOC
:
4014 wpa_supplicant_event_unprot_disassoc(wpa_s
,
4015 &data
->unprot_disassoc
);
4017 case EVENT_STATION_LOW_ACK
:
4019 if (wpa_s
->ap_iface
&& data
)
4020 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
4021 data
->low_ack
.addr
);
4022 #endif /* CONFIG_AP */
4025 wpa_tdls_disable_unreachable_link(wpa_s
->wpa
,
4026 data
->low_ack
.addr
);
4027 #endif /* CONFIG_TDLS */
4029 case EVENT_IBSS_PEER_LOST
:
4030 #ifdef CONFIG_IBSS_RSN
4031 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
4032 #endif /* CONFIG_IBSS_RSN */
4034 case EVENT_DRIVER_GTK_REKEY
:
4035 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
4036 wpa_s
->bssid
, ETH_ALEN
))
4040 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
4041 data
->driver_gtk_rekey
.replay_ctr
);
4043 case EVENT_SCHED_SCAN_STOPPED
:
4044 wpa_s
->sched_scanning
= 0;
4045 resched
= wpa_s
->scanning
&& wpas_scan_scheduled(wpa_s
);
4046 wpa_supplicant_notify_scanning(wpa_s
, 0);
4048 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4052 * Start a new sched scan to continue searching for more SSIDs
4053 * either if timed out or PNO schedule scan is pending.
4055 if (wpa_s
->sched_scan_timed_out
) {
4056 wpa_supplicant_req_sched_scan(wpa_s
);
4057 } else if (wpa_s
->pno_sched_pending
) {
4058 wpa_s
->pno_sched_pending
= 0;
4059 wpas_start_pno(wpa_s
);
4060 } else if (resched
) {
4061 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4065 case EVENT_WPS_BUTTON_PUSHED
:
4067 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
4068 #endif /* CONFIG_WPS */
4070 case EVENT_AVOID_FREQUENCIES
:
4071 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
4073 case EVENT_CONNECT_FAILED_REASON
:
4075 if (!wpa_s
->ap_iface
|| !data
)
4077 hostapd_event_connect_failed_reason(
4078 wpa_s
->ap_iface
->bss
[0],
4079 data
->connect_failed_reason
.addr
,
4080 data
->connect_failed_reason
.code
);
4081 #endif /* CONFIG_AP */
4083 case EVENT_NEW_PEER_CANDIDATE
:
4085 if (!wpa_s
->ifmsh
|| !data
)
4087 wpa_mesh_notify_peer(wpa_s
, data
->mesh_peer
.peer
,
4088 data
->mesh_peer
.ies
,
4089 data
->mesh_peer
.ie_len
);
4090 #endif /* CONFIG_MESH */
4094 if (!wpa_s
->ap_iface
)
4096 hostapd_event_get_survey(wpa_s
->ap_iface
,
4097 &data
->survey_results
);
4098 #endif /* CONFIG_AP */
4100 case EVENT_ACS_CHANNEL_SELECTED
:
4102 if (!wpa_s
->ap_iface
)
4104 hostapd_acs_channel_selected(wpa_s
->ap_iface
->bss
[0],
4105 &data
->acs_selected_channels
);
4106 #endif /* CONFIG_ACS */
4108 case EVENT_P2P_LO_STOP
:
4110 wpa_s
->p2p_lo_started
= 0;
4111 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_LISTEN_OFFLOAD_STOP
4112 P2P_LISTEN_OFFLOAD_STOP_REASON
"reason=%d",
4113 data
->p2p_lo_stop
.reason_code
);
4114 #endif /* CONFIG_P2P */
4117 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);
4123 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
4124 union wpa_event_data
*data
)
4126 struct wpa_supplicant
*wpa_s
;
4128 if (event
!= EVENT_INTERFACE_STATUS
)
4131 wpa_s
= wpa_supplicant_get_iface(ctx
, data
->interface_status
.ifname
);
4132 if (wpa_s
&& wpa_s
->driver
->get_ifindex
) {
4133 unsigned int ifindex
;
4135 ifindex
= wpa_s
->driver
->get_ifindex(wpa_s
->drv_priv
);
4136 if (ifindex
!= data
->interface_status
.ifindex
) {
4137 wpa_dbg(wpa_s
, MSG_DEBUG
,
4138 "interface status ifindex %d mismatch (%d)",
4139 ifindex
, data
->interface_status
.ifindex
);
4143 #ifdef CONFIG_MATCH_IFACE
4144 else if (data
->interface_status
.ievent
== EVENT_INTERFACE_ADDED
) {
4145 struct wpa_interface
*wpa_i
;
4147 wpa_i
= wpa_supplicant_match_iface(
4148 ctx
, data
->interface_status
.ifname
);
4151 wpa_s
= wpa_supplicant_add_iface(ctx
, wpa_i
, NULL
);
4156 #endif /* CONFIG_MATCH_IFACE */
4159 wpa_supplicant_event(wpa_s
, event
, data
);