2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "ap/hostapd.h"
33 #include "common/ieee802_11_defs.h"
34 #include "common/ieee802_11_common.h"
35 #include "crypto/random.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
38 #include "wps_supplicant.h"
41 #include "gas_query.h"
42 #include "p2p_supplicant.h"
47 #include "offchannel.h"
50 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
52 struct wpa_ssid
*ssid
, *old_ssid
;
54 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
57 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
59 ssid
= wpa_supplicant_get_ssid(wpa_s
);
61 wpa_msg(wpa_s
, MSG_INFO
,
62 "No network configuration found for the current AP");
67 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
71 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
73 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
74 WPA_KEY_MGMT_WPA_NONE
|
75 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
76 WPA_KEY_MGMT_PSK_SHA256
|
77 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
79 size_t wpa_ie_len
= sizeof(wpa_ie
);
80 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
83 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
86 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
87 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
88 old_ssid
= wpa_s
->current_ssid
;
89 wpa_s
->current_ssid
= ssid
;
90 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
91 wpa_supplicant_initiate_eapol(wpa_s
);
92 if (old_ssid
!= wpa_s
->current_ssid
)
93 wpas_notify_network_changed(wpa_s
);
99 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
101 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
103 if (wpa_s
->countermeasures
) {
104 wpa_s
->countermeasures
= 0;
105 wpa_drv_set_countermeasures(wpa_s
, 0);
106 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
107 wpa_supplicant_req_scan(wpa_s
, 0, 0);
112 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
116 #ifdef CONFIG_IBSS_RSN
117 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
118 wpa_s
->ibss_rsn
= NULL
;
119 #endif /* CONFIG_IBSS_RSN */
122 wpa_supplicant_ap_deinit(wpa_s
);
123 #endif /* CONFIG_AP */
125 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
128 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
129 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
130 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
131 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
132 wpa_s
->current_bss
= NULL
;
133 wpa_s
->assoc_freq
= 0;
134 #ifdef CONFIG_IEEE80211R
136 if (wpa_s
->sme
.ft_ies
)
137 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
138 #endif /* CONFIG_SME */
139 #endif /* CONFIG_IEEE80211R */
142 wpas_notify_bssid_changed(wpa_s
);
144 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
145 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
146 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
147 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
148 wpa_s
->ap_ies_from_associnfo
= 0;
152 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
154 struct wpa_ie_data ie
;
158 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
162 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
163 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
164 ie
.pmkid
+ i
* PMKID_LEN
,
166 if (pmksa_set
== 0) {
167 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
172 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
173 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
177 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
178 union wpa_event_data
*data
)
181 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
185 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
186 " index=%d preauth=%d",
187 MAC2STR(data
->pmkid_candidate
.bssid
),
188 data
->pmkid_candidate
.index
,
189 data
->pmkid_candidate
.preauth
);
191 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
192 data
->pmkid_candidate
.index
,
193 data
->pmkid_candidate
.preauth
);
197 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
199 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
200 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
203 #ifdef IEEE8021X_EAPOL
204 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
205 wpa_s
->current_ssid
&&
206 !(wpa_s
->current_ssid
->eapol_flags
&
207 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
208 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
209 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
210 * plaintext or static WEP keys). */
213 #endif /* IEEE8021X_EAPOL */
220 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
221 * @wpa_s: pointer to wpa_supplicant data
222 * @ssid: Configuration data for the network
223 * Returns: 0 on success, -1 on failure
225 * This function is called when starting authentication with a network that is
226 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
228 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
229 struct wpa_ssid
*ssid
)
231 #ifdef IEEE8021X_EAPOL
233 int aka
= 0, sim
= 0, type
;
235 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
238 if (ssid
->eap
.eap_methods
== NULL
) {
242 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
243 while (eap
->vendor
!= EAP_VENDOR_IETF
||
244 eap
->method
!= EAP_TYPE_NONE
) {
245 if (eap
->vendor
== EAP_VENDOR_IETF
) {
246 if (eap
->method
== EAP_TYPE_SIM
)
248 else if (eap
->method
== EAP_TYPE_AKA
)
255 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
257 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
261 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
262 "use SIM, but neither EAP-SIM nor EAP-AKA are "
267 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
268 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
270 type
= SCARD_TRY_BOTH
;
272 type
= SCARD_USIM_ONLY
;
274 type
= SCARD_GSM_SIM_ONLY
;
276 wpa_s
->scard
= scard_init(type
);
277 if (wpa_s
->scard
== NULL
) {
278 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
282 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
283 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
284 #endif /* PCSC_FUNCS */
285 #endif /* IEEE8021X_EAPOL */
291 #ifndef CONFIG_NO_SCAN_PROCESSING
292 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
293 struct wpa_ssid
*ssid
)
297 if (ssid
->mixed_cell
)
301 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
303 #endif /* CONFIG_WPS */
305 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
306 if (ssid
->wep_key_len
[i
]) {
311 #ifdef IEEE8021X_EAPOL
312 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
313 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
314 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
316 #endif /* IEEE8021X_EAPOL */
318 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
321 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
327 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
328 struct wpa_ssid
*ssid
,
329 struct wpa_scan_res
*bss
)
331 struct wpa_ie_data ie
;
333 const u8
*rsn_ie
, *wpa_ie
;
337 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
341 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
342 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
343 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
344 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
345 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
347 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
348 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
351 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
352 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
358 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
360 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
365 if (!(ie
.proto
& ssid
->proto
)) {
366 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
371 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
372 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
377 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
378 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
383 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
384 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
389 #ifdef CONFIG_IEEE80211W
390 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
391 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
392 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
396 #endif /* CONFIG_IEEE80211W */
398 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
402 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
403 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
406 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
407 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
413 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
415 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
420 if (!(ie
.proto
& ssid
->proto
)) {
421 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
426 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
427 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
432 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
433 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
438 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
439 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
444 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
448 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
449 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
450 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
454 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
455 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
459 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
466 static int freq_allowed(int *freqs
, int freq
)
473 for (i
= 0; freqs
[i
]; i
++)
474 if (freqs
[i
] == freq
)
480 static int ht_supported(const struct hostapd_hw_modes
*mode
)
482 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
484 * The driver did not indicate whether it supports HT. Assume
485 * it does to avoid connection issues.
491 * IEEE Std 802.11n-2009 20.1.1:
492 * An HT non-AP STA shall support all EQM rates for one spatial stream.
494 return mode
->mcs_set
[0] == 0xff;
498 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_scan_res
*bss
)
500 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
501 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
506 return 1; /* Cannot do matching without knowing band */
508 modes
= wpa_s
->hw
.modes
;
511 * The driver does not provide any additional information
512 * about the utilized hardware, so allow the connection attempt
518 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
519 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
520 int freq
= modes
[i
].channels
[j
].freq
;
521 if (freq
== bss
->freq
) {
523 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
524 break; /* do not allow 802.11b replace
535 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
536 rate_ie
= wpa_scan_get_ie(bss
, scan_ie
[i
]);
540 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
541 int flagged
= !!(rate_ie
[j
] & 0x80);
542 int r
= (rate_ie
[j
] & 0x7f) * 5;
545 * IEEE Std 802.11n-2009 7.3.2.2:
546 * The new BSS Membership selector value is encoded
547 * like a legacy basic rate, but it is not a rate and
548 * only indicates if the BSS members are required to
549 * support the mandatory features of Clause 20 [HT PHY]
550 * in order to join the BSS.
552 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
553 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
554 if (!ht_supported(mode
)) {
555 wpa_dbg(wpa_s
, MSG_DEBUG
,
556 " hardware does not support "
566 /* check for legacy basic rates */
567 for (k
= 0; k
< mode
->num_rates
; k
++) {
568 if (mode
->rates
[k
] == r
)
571 if (k
== mode
->num_rates
) {
573 * IEEE Std 802.11-2007 7.3.2.2 demands that in
574 * order to join a BSS all required rates
575 * have to be supported by the hardware.
577 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
578 "not support required rate %d.%d Mbps",
589 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
590 int i
, struct wpa_scan_res
*bss
,
591 struct wpa_ssid
*group
)
594 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
596 struct wpa_blacklist
*e
;
598 struct wpa_ssid
*ssid
;
600 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
601 ssid_
= ie
? ie
+ 2 : (u8
*) "";
602 ssid_len
= ie
? ie
[1] : 0;
604 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
605 wpa_ie_len
= ie
? ie
[1] : 0;
607 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
608 rsn_ie_len
= ie
? ie
[1] : 0;
610 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
611 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
612 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
613 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
614 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
616 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
619 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
621 * When only a single network is enabled, we can
622 * trigger blacklisting on the first failure. This
623 * should not be done with multiple enabled networks to
624 * avoid getting forced to move into a worse ESS on
625 * single error if there are no other BSSes of the
630 if (e
->count
> limit
) {
631 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
632 "(count=%d limit=%d)", e
->count
, limit
);
638 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
642 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
644 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
645 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
647 if (ssid
->disabled
) {
648 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
653 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
654 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
659 if (wpa
&& ssid
->ssid_len
== 0 &&
660 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
663 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
664 /* Only allow wildcard SSID match if an AP
665 * advertises active WPS operation that matches
668 if (ssid
->ssid_len
== 0 &&
669 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
672 #endif /* CONFIG_WPS */
674 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
675 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
679 (ssid_len
!= ssid
->ssid_len
||
680 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
681 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
685 if (ssid
->bssid_set
&&
686 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
687 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
691 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
695 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
696 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
697 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
698 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
703 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
704 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
709 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
710 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
715 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
716 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
721 if (!rate_match(wpa_s
, bss
)) {
722 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
729 * TODO: skip the AP if its P2P IE has Group Formation
730 * bit set in the P2P Group Capability Bitmap and we
731 * are not in Group Formation with that device.
733 #endif /* CONFIG_P2P */
735 /* Matching configuration found */
739 /* No matching configuration found */
744 static struct wpa_bss
*
745 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
746 struct wpa_scan_results
*scan_res
,
747 struct wpa_ssid
*group
,
748 struct wpa_ssid
**selected_ssid
)
752 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
755 for (i
= 0; i
< scan_res
->num
; i
++) {
756 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
760 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
764 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
765 ssid
= ie
? ie
+ 2 : (u8
*) "";
766 ssid_len
= ie
? ie
[1] : 0;
768 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
770 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
771 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
778 static struct wpa_bss
*
779 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
780 struct wpa_scan_results
*scan_res
,
781 struct wpa_ssid
**selected_ssid
)
783 struct wpa_bss
*selected
= NULL
;
786 while (selected
== NULL
) {
787 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
788 selected
= wpa_supplicant_select_bss(
789 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
795 if (selected
== NULL
&& wpa_s
->blacklist
) {
796 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
797 "blacklist and try again");
798 wpa_blacklist_clear(wpa_s
);
799 wpa_s
->blacklist_cleared
++;
800 } else if (selected
== NULL
)
808 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
809 int timeout_sec
, int timeout_usec
)
811 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
813 * No networks are enabled; short-circuit request so
814 * we don't wait timeout seconds before transitioning
817 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
820 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
824 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
825 struct wpa_bss
*selected
,
826 struct wpa_ssid
*ssid
)
828 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
829 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
830 "PBC session overlap");
832 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
834 #endif /* CONFIG_P2P */
837 wpas_wps_cancel(wpa_s
);
838 #endif /* CONFIG_WPS */
843 * Do not trigger new association unless the BSSID has changed or if
844 * reassociation is requested. If we are in process of associating with
845 * the selected BSSID, do not trigger new attempt.
847 if (wpa_s
->reassociate
||
848 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
849 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
850 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
851 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
853 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
854 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
857 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
858 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
859 " pending: " MACSTR
" wpa_state: %s",
860 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
861 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
862 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
863 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
865 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
873 static struct wpa_ssid
*
874 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
877 struct wpa_ssid
*ssid
;
879 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
880 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
884 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
885 ssid
->mode
== IEEE80211_MODE_AP
)
893 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
894 * on BSS added and BSS changed events */
895 static void wpa_supplicant_rsn_preauth_scan_results(
896 struct wpa_supplicant
*wpa_s
)
900 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
903 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
904 const u8
*ssid
, *rsn
;
906 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
910 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
914 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
920 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
921 struct wpa_bss
*selected
,
922 struct wpa_ssid
*ssid
,
923 struct wpa_scan_results
*scan_res
)
926 struct wpa_scan_res
*current_bss
= NULL
;
929 if (wpa_s
->reassociate
)
930 return 1; /* explicit request to reassociate */
931 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
932 return 1; /* we are not associated; continue */
933 if (wpa_s
->current_ssid
== NULL
)
934 return 1; /* unknown current SSID */
935 if (wpa_s
->current_ssid
!= ssid
)
936 return 1; /* different network block */
938 if (wpas_driver_bss_selection(wpa_s
))
939 return 0; /* Driver-based roaming */
941 for (i
= 0; i
< scan_res
->num
; i
++) {
942 struct wpa_scan_res
*res
= scan_res
->res
[i
];
944 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
947 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
950 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
951 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
958 return 1; /* current BSS not seen in scan results */
960 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
961 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
962 MAC2STR(current_bss
->bssid
), current_bss
->level
);
963 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
964 MAC2STR(selected
->bssid
), selected
->level
);
966 if (wpa_s
->current_ssid
->bssid_set
&&
967 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
969 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
970 "has preferred BSSID");
975 if (current_bss
->level
< 0) {
976 if (current_bss
->level
< -85)
978 else if (current_bss
->level
< -80)
980 else if (current_bss
->level
< -75)
982 else if (current_bss
->level
< -70)
987 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
988 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
996 /* Return < 0 if no scan results could be fetched. */
997 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
998 union wpa_event_data
*data
)
1000 struct wpa_bss
*selected
;
1001 struct wpa_ssid
*ssid
= NULL
;
1002 struct wpa_scan_results
*scan_res
;
1006 if (wpa_s
->ap_iface
)
1008 #endif /* CONFIG_AP */
1010 wpa_supplicant_notify_scanning(wpa_s
, 0);
1012 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1013 data
? &data
->scan_info
:
1015 if (scan_res
== NULL
) {
1016 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
1018 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1020 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1024 #ifndef CONFIG_NO_RANDOM_POOL
1026 num
= scan_res
->num
;
1029 for (i
= 0; i
< num
; i
++) {
1031 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1032 buf
[0] = res
->bssid
[5];
1033 buf
[1] = res
->qual
& 0xff;
1034 buf
[2] = res
->noise
& 0xff;
1035 buf
[3] = res
->level
& 0xff;
1036 buf
[4] = res
->tsf
& 0xff;
1037 random_add_randomness(buf
, sizeof(buf
));
1039 #endif /* CONFIG_NO_RANDOM_POOL */
1041 if (wpa_s
->scan_res_handler
) {
1042 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1043 struct wpa_scan_results
*scan_res
);
1045 scan_res_handler
= wpa_s
->scan_res_handler
;
1046 wpa_s
->scan_res_handler
= NULL
;
1047 scan_res_handler(wpa_s
, scan_res
);
1049 wpa_scan_results_free(scan_res
);
1054 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1056 if (wpa_s
->ap_iface
->scan_cb
)
1057 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1058 #endif /* CONFIG_AP */
1059 wpa_scan_results_free(scan_res
);
1063 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
1064 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1065 wpas_notify_scan_results(wpa_s
);
1067 wpas_notify_scan_done(wpa_s
, 1);
1069 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
1070 wpa_scan_results_free(scan_res
);
1074 if (wpa_s
->disconnected
) {
1075 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1076 wpa_scan_results_free(scan_res
);
1080 if (!wpas_driver_bss_selection(wpa_s
) &&
1081 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
1082 wpa_scan_results_free(scan_res
);
1086 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
1090 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
1092 wpa_scan_results_free(scan_res
);
1096 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1097 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1100 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1102 wpa_scan_results_free(scan_res
);
1103 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1104 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1106 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1107 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1108 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1110 int timeout_sec
= wpa_s
->scan_interval
;
1111 int timeout_usec
= 0;
1113 if (wpa_s
->p2p_in_provisioning
) {
1115 * Use shorter wait during P2P Provisioning
1116 * state to speed up group formation.
1119 timeout_usec
= 250000;
1120 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1124 #endif /* CONFIG_P2P */
1125 if (wpa_supplicant_req_sched_scan(wpa_s
))
1126 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1134 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1135 union wpa_event_data
*data
)
1137 const char *rn
, *rn2
;
1138 struct wpa_supplicant
*ifs
;
1140 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1142 * If no scan results could be fetched, then no need to
1143 * notify those interfaces that did not actually request
1150 * Check other interfaces to see if they have the same radio-name. If
1151 * so, they get updated with this same scan info.
1153 if (!wpa_s
->driver
->get_radio_name
)
1156 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1157 if (rn
== NULL
|| rn
[0] == '\0')
1160 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1161 "sharing same radio (%s) in event_scan_results", rn
);
1163 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1164 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1167 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1168 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1169 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1170 "sibling", ifs
->ifname
);
1171 _wpa_supplicant_event_scan_results(ifs
, data
);
1176 #endif /* CONFIG_NO_SCAN_PROCESSING */
1179 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1180 union wpa_event_data
*data
)
1182 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1185 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1186 if (data
->assoc_info
.req_ies
)
1187 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1188 data
->assoc_info
.req_ies_len
);
1189 if (data
->assoc_info
.resp_ies
) {
1190 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1191 data
->assoc_info
.resp_ies_len
);
1193 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1194 data
->assoc_info
.resp_ies_len
);
1195 #endif /* CONFIG_TDLS */
1197 if (data
->assoc_info
.beacon_ies
)
1198 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1199 data
->assoc_info
.beacon_ies
,
1200 data
->assoc_info
.beacon_ies_len
);
1201 if (data
->assoc_info
.freq
)
1202 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1203 data
->assoc_info
.freq
);
1205 p
= data
->assoc_info
.req_ies
;
1206 l
= data
->assoc_info
.req_ies_len
;
1208 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1209 while (p
&& l
>= 2) {
1212 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1216 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1217 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1218 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1219 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1222 wpa_find_assoc_pmkid(wpa_s
);
1228 if (!found
&& data
->assoc_info
.req_ies
)
1229 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1231 #ifdef CONFIG_IEEE80211R
1233 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1235 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1236 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1237 data
->assoc_info
.resp_ies
,
1238 data
->assoc_info
.resp_ies_len
,
1240 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1241 "Reassociation Response failed");
1242 wpa_supplicant_deauthenticate(
1243 wpa_s
, WLAN_REASON_INVALID_IE
);
1248 p
= data
->assoc_info
.resp_ies
;
1249 l
= data
->assoc_info
.resp_ies_len
;
1251 #ifdef CONFIG_WPS_STRICT
1252 if (p
&& wpa_s
->current_ssid
&&
1253 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1255 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1257 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1258 "include WPS IE in (Re)Association Response");
1262 if (wps_validate_assoc_resp(wps
) < 0) {
1264 wpa_supplicant_deauthenticate(
1265 wpa_s
, WLAN_REASON_INVALID_IE
);
1270 #endif /* CONFIG_WPS_STRICT */
1272 /* Go through the IEs and make a copy of the MDIE, if present. */
1273 while (p
&& l
>= 2) {
1276 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1280 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1281 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1282 wpa_s
->sme
.ft_used
= 1;
1283 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1284 MOBILITY_DOMAIN_ID_LEN
);
1290 #endif /* CONFIG_SME */
1292 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1293 data
->assoc_info
.resp_ies_len
);
1294 #endif /* CONFIG_IEEE80211R */
1296 /* WPA/RSN IE from Beacon/ProbeResp */
1297 p
= data
->assoc_info
.beacon_ies
;
1298 l
= data
->assoc_info
.beacon_ies_len
;
1300 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1302 wpa_found
= rsn_found
= 0;
1303 while (p
&& l
>= 2) {
1306 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1311 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1312 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1314 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1318 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1320 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1327 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1328 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1329 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1330 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1331 if (wpa_found
|| rsn_found
)
1332 wpa_s
->ap_ies_from_associnfo
= 1;
1334 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1335 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1336 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1338 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1339 wpa_supplicant_update_scan_results(wpa_s
);
1342 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1348 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1349 union wpa_event_data
*data
)
1354 struct wpa_driver_capa capa
;
1357 if (wpa_s
->ap_iface
) {
1358 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1359 data
->assoc_info
.addr
,
1360 data
->assoc_info
.req_ies
,
1361 data
->assoc_info
.req_ies_len
,
1362 data
->assoc_info
.reassoc
);
1365 #endif /* CONFIG_AP */
1367 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1368 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1371 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1372 if (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1373 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1374 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1375 MACSTR
, MAC2STR(bssid
));
1376 random_add_randomness(bssid
, ETH_ALEN
);
1377 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1378 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1379 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1381 wpas_notify_bssid_changed(wpa_s
);
1383 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1384 wpa_clear_keys(wpa_s
, bssid
);
1386 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1387 wpa_supplicant_disassociate(
1388 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1391 if (wpa_s
->current_ssid
) {
1392 struct wpa_bss
*bss
= NULL
;
1393 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1394 if (ssid
->ssid_len
> 0)
1395 bss
= wpa_bss_get(wpa_s
, bssid
,
1396 ssid
->ssid
, ssid
->ssid_len
);
1398 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1400 wpa_s
->current_bss
= bss
;
1405 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1406 wpa_s
->sme
.prev_bssid_set
= 1;
1407 #endif /* CONFIG_SME */
1409 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1410 if (wpa_s
->current_ssid
) {
1411 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1412 * initialized before association, but for other modes,
1413 * initialize PC/SC here, if the current configuration needs
1414 * smartcard or SIM/USIM. */
1415 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1417 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1419 l2_packet_notify_auth_start(wpa_s
->l2
);
1422 * Set portEnabled first to FALSE in order to get EAP state machine out
1423 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1424 * state machine may transit to AUTHENTICATING state based on obsolete
1425 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1426 * AUTHENTICATED without ever giving chance to EAP state machine to
1429 if (!ft_completed
) {
1430 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1431 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1433 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1434 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1435 /* 802.1X::portControl = Auto */
1436 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1437 wpa_s
->eapol_received
= 0;
1438 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1439 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1440 (wpa_s
->current_ssid
&&
1441 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1442 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1443 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1444 } else if (!ft_completed
) {
1445 /* Timeout for receiving the first EAPOL packet */
1446 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1448 wpa_supplicant_cancel_scan(wpa_s
);
1450 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1451 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1453 * We are done; the driver will take care of RSN 4-way
1456 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1457 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1458 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1459 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1460 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1461 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1463 * The driver will take care of RSN 4-way handshake, so we need
1464 * to allow EAPOL supplicant to complete its work without
1465 * waiting for WPA supplicant.
1467 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1468 } else if (ft_completed
) {
1470 * FT protocol completed - make sure EAPOL state machine ends
1471 * up in authenticated.
1473 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1474 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1475 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1476 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1479 if (wpa_s
->pending_eapol_rx
) {
1480 struct os_time now
, age
;
1482 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1483 if (age
.sec
== 0 && age
.usec
< 100000 &&
1484 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1486 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1487 "frame that was received just before "
1488 "association notification");
1489 wpa_supplicant_rx_eapol(
1490 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1491 wpabuf_head(wpa_s
->pending_eapol_rx
),
1492 wpabuf_len(wpa_s
->pending_eapol_rx
));
1494 wpabuf_free(wpa_s
->pending_eapol_rx
);
1495 wpa_s
->pending_eapol_rx
= NULL
;
1498 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1499 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1500 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1501 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1502 /* Set static WEP keys again */
1503 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1506 #ifdef CONFIG_IBSS_RSN
1507 if (wpa_s
->current_ssid
&&
1508 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1509 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1510 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1511 wpa_s
->ibss_rsn
== NULL
) {
1512 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1513 if (!wpa_s
->ibss_rsn
) {
1514 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1515 wpa_supplicant_deauthenticate(
1516 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1520 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1522 #endif /* CONFIG_IBSS_RSN */
1526 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1531 u8 prev_pending_bssid
[ETH_ALEN
];
1533 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1534 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1536 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1538 * At least Host AP driver and a Prism3 card seemed to be
1539 * generating streams of disconnected events when configuring
1540 * IBSS for WPA-None. Ignore them for now.
1542 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1543 "IBSS/WPA-None mode");
1547 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1548 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1549 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1550 "pre-shared key may be incorrect");
1552 if (!wpa_s
->auto_reconnect_disabled
||
1553 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1554 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1555 "reconnect (wps=%d)",
1556 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1557 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1558 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1560 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1561 "try to re-connect");
1562 wpa_s
->reassociate
= 0;
1563 wpa_s
->disconnected
= 1;
1565 bssid
= wpa_s
->bssid
;
1566 if (is_zero_ether_addr(bssid
))
1567 bssid
= wpa_s
->pending_bssid
;
1568 wpas_connection_failed(wpa_s
, bssid
);
1569 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1570 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1572 MAC2STR(bssid
), reason_code
);
1573 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1574 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1575 wpa_s
->keys_cleared
= 0;
1576 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1578 wpa_supplicant_mark_disassoc(wpa_s
);
1580 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1581 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1585 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1586 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
1588 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1590 if (!wpa_s
->pending_mic_error_report
)
1593 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1594 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1595 wpa_s
->pending_mic_error_report
= 0;
1597 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1601 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1602 union wpa_event_data
*data
)
1607 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1608 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1610 if ((wpa_s
->last_michael_mic_error
&&
1611 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1612 wpa_s
->pending_mic_error_report
) {
1613 if (wpa_s
->pending_mic_error_report
) {
1615 * Send the pending MIC error report immediately since
1616 * we are going to start countermeasures and AP better
1619 wpa_sm_key_request(wpa_s
->wpa
, 1,
1620 wpa_s
->pending_mic_error_pairwise
);
1623 /* Send the new MIC error report immediately since we are going
1624 * to start countermeasures and AP better do the same.
1626 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1628 /* initialize countermeasures */
1629 wpa_s
->countermeasures
= 1;
1630 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1633 * Need to wait for completion of request frame. We do not get
1634 * any callback for the message completion, so just wait a
1635 * short while and hope for the best. */
1638 wpa_drv_set_countermeasures(wpa_s
, 1);
1639 wpa_supplicant_deauthenticate(wpa_s
,
1640 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1641 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1643 eloop_register_timeout(60, 0,
1644 wpa_supplicant_stop_countermeasures
,
1646 /* TODO: mark the AP rejected for 60 second. STA is
1647 * allowed to associate with another AP.. */
1649 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1650 if (wpa_s
->mic_errors_seen
) {
1652 * Reduce the effectiveness of Michael MIC error
1653 * reports as a means for attacking against TKIP if
1654 * more than one MIC failure is noticed with the same
1655 * PTK. We delay the transmission of the reports by a
1656 * random time between 0 and 60 seconds in order to
1657 * force the attacker wait 60 seconds before getting
1658 * the information on whether a frame resulted in a MIC
1664 if (os_get_random(rval
, sizeof(rval
)) < 0)
1665 sec
= os_random() % 60;
1667 sec
= WPA_GET_BE32(rval
) % 60;
1668 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1669 "report %d seconds", sec
);
1670 wpa_s
->pending_mic_error_report
= 1;
1671 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1672 eloop_cancel_timeout(
1673 wpa_supplicant_delayed_mic_error_report
,
1675 eloop_register_timeout(
1676 sec
, os_random() % 1000000,
1677 wpa_supplicant_delayed_mic_error_report
,
1680 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1682 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1683 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1684 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1686 wpa_s
->last_michael_mic_error
= t
.sec
;
1687 wpa_s
->mic_errors_seen
++;
1691 #ifdef CONFIG_TERMINATE_ONLASTIF
1692 static int any_interfaces(struct wpa_supplicant
*head
)
1694 struct wpa_supplicant
*wpa_s
;
1696 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1697 if (!wpa_s
->interface_removed
)
1701 #endif /* CONFIG_TERMINATE_ONLASTIF */
1705 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1706 union wpa_event_data
*data
)
1708 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1711 switch (data
->interface_status
.ievent
) {
1712 case EVENT_INTERFACE_ADDED
:
1713 if (!wpa_s
->interface_removed
)
1715 wpa_s
->interface_removed
= 0;
1716 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1717 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1718 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1719 "driver after interface was added");
1722 case EVENT_INTERFACE_REMOVED
:
1723 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1724 wpa_s
->interface_removed
= 1;
1725 wpa_supplicant_mark_disassoc(wpa_s
);
1726 l2_packet_deinit(wpa_s
->l2
);
1728 #ifdef CONFIG_IBSS_RSN
1729 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1730 wpa_s
->ibss_rsn
= NULL
;
1731 #endif /* CONFIG_IBSS_RSN */
1732 #ifdef CONFIG_TERMINATE_ONLASTIF
1733 /* check if last interface */
1734 if (!any_interfaces(wpa_s
->global
->ifaces
))
1736 #endif /* CONFIG_TERMINATE_ONLASTIF */
1742 #ifdef CONFIG_PEERKEY
1744 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1745 union wpa_event_data
*data
)
1749 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1751 #endif /* CONFIG_PEERKEY */
1755 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1756 union wpa_event_data
*data
)
1760 switch (data
->tdls
.oper
) {
1761 case TDLS_REQUEST_SETUP
:
1762 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1764 case TDLS_REQUEST_TEARDOWN
:
1765 wpa_tdls_send_teardown(wpa_s
->wpa
, data
->tdls
.peer
,
1766 data
->tdls
.reason_code
);
1770 #endif /* CONFIG_TDLS */
1773 #ifdef CONFIG_IEEE80211R
1775 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1776 union wpa_event_data
*data
)
1781 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1782 data
->ft_ies
.ies_len
,
1783 data
->ft_ies
.ft_action
,
1784 data
->ft_ies
.target_ap
,
1785 data
->ft_ies
.ric_ies
,
1786 data
->ft_ies
.ric_ies_len
) < 0) {
1787 /* TODO: prevent MLME/driver from trying to associate? */
1790 #endif /* CONFIG_IEEE80211R */
1793 #ifdef CONFIG_IBSS_RSN
1794 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1795 union wpa_event_data
*data
)
1797 struct wpa_ssid
*ssid
;
1798 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1802 ssid
= wpa_s
->current_ssid
;
1805 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1808 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1810 #endif /* CONFIG_IBSS_RSN */
1813 #ifdef CONFIG_IEEE80211R
1814 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1817 const u8
*sta_addr
, *target_ap_addr
;
1820 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1821 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1822 return; /* only SME case supported for now */
1823 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1826 return; /* Only FT Action Response is supported for now */
1827 sta_addr
= data
+ 1;
1828 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1829 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1830 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1831 MACSTR
" TargetAP " MACSTR
" status %u",
1832 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1834 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1835 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1836 " in FT Action Response", MAC2STR(sta_addr
));
1841 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1842 "failure (status code %d)", status
);
1843 /* TODO: report error to FT code(?) */
1847 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1848 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1849 target_ap_addr
, NULL
, 0) < 0)
1854 struct wpa_bss
*bss
;
1855 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1857 wpa_s
->sme
.freq
= bss
->freq
;
1858 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1859 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1862 #endif /* CONFIG_SME */
1864 #endif /* CONFIG_IEEE80211R */
1867 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1868 struct unprot_deauth
*e
)
1870 #ifdef CONFIG_IEEE80211W
1871 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1872 "dropped: " MACSTR
" -> " MACSTR
1873 " (reason code %u)",
1874 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1875 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1876 #endif /* CONFIG_IEEE80211W */
1880 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1881 struct unprot_disassoc
*e
)
1883 #ifdef CONFIG_IEEE80211W
1884 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1885 "dropped: " MACSTR
" -> " MACSTR
1886 " (reason code %u)",
1887 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1888 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1889 #endif /* CONFIG_IEEE80211W */
1893 static void wnm_action_rx(struct wpa_supplicant
*wpa_s
, struct rx_action
*rx
)
1896 const u8
*pos
, *end
;
1898 if (rx
->data
== NULL
|| rx
->len
== 0)
1902 end
= pos
+ rx
->len
;
1905 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
1906 action
, MAC2STR(rx
->sa
));
1908 case WNM_BSS_TRANS_MGMT_REQ
:
1911 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management "
1912 "Request: dialog_token=%u request_mode=0x%x "
1913 "disassoc_timer=%u validity_interval=%u",
1914 pos
[0], pos
[1], WPA_GET_LE16(pos
+ 2), pos
[4]);
1918 pos
+= 12; /* BSS Termination Duration */
1921 if (pos
+ 1 > end
|| pos
+ 1 + pos
[0] > end
) {
1922 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS "
1923 "Transition Management Request "
1927 os_memcpy(url
, pos
+ 1, pos
[0]);
1929 wpa_msg(wpa_s
, MSG_INFO
, "WNM: ESS Disassociation "
1930 "Imminent - session_info_url=%s", url
);
1937 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1938 union wpa_event_data
*data
)
1940 struct wpa_supplicant
*wpa_s
= ctx
;
1941 u16 reason_code
= 0;
1943 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1944 event
!= EVENT_INTERFACE_ENABLED
&&
1945 event
!= EVENT_INTERFACE_STATUS
) {
1946 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1951 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1952 event
, wpa_s
->ifname
);
1956 sme_event_auth(wpa_s
, data
);
1959 wpa_supplicant_event_assoc(wpa_s
, data
);
1961 case EVENT_DISASSOC
:
1962 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1964 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1965 data
->disassoc_info
.reason_code
);
1966 if (data
->disassoc_info
.addr
)
1967 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1968 MAC2STR(data
->disassoc_info
.addr
));
1971 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1972 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1973 data
->disassoc_info
.addr
);
1976 #endif /* CONFIG_AP */
1978 reason_code
= data
->disassoc_info
.reason_code
;
1979 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1980 data
->disassoc_info
.ie
,
1981 data
->disassoc_info
.ie_len
);
1983 wpas_p2p_disassoc_notif(
1984 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1985 data
->disassoc_info
.ie
,
1986 data
->disassoc_info
.ie_len
);
1987 #endif /* CONFIG_P2P */
1989 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1990 sme_event_disassoc(wpa_s
, data
);
1993 if (event
== EVENT_DEAUTH
) {
1994 wpa_dbg(wpa_s
, MSG_DEBUG
,
1995 "Deauthentication notification");
1997 reason_code
= data
->deauth_info
.reason_code
;
1998 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1999 data
->deauth_info
.reason_code
);
2000 if (data
->deauth_info
.addr
) {
2001 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
2003 MAC2STR(data
->deauth_info
.
2006 wpa_hexdump(MSG_DEBUG
,
2007 "Deauthentication frame IE(s)",
2008 data
->deauth_info
.ie
,
2009 data
->deauth_info
.ie_len
);
2011 wpas_p2p_deauth_notif(
2012 wpa_s
, data
->deauth_info
.addr
,
2014 data
->deauth_info
.ie
,
2015 data
->deauth_info
.ie_len
);
2016 #endif /* CONFIG_P2P */
2020 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
2021 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2022 data
->deauth_info
.addr
);
2025 #endif /* CONFIG_AP */
2026 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
2028 case EVENT_MICHAEL_MIC_FAILURE
:
2029 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2031 #ifndef CONFIG_NO_SCAN_PROCESSING
2032 case EVENT_SCAN_RESULTS
:
2033 wpa_supplicant_event_scan_results(wpa_s
, data
);
2035 #endif /* CONFIG_NO_SCAN_PROCESSING */
2036 case EVENT_ASSOCINFO
:
2037 wpa_supplicant_event_associnfo(wpa_s
, data
);
2039 case EVENT_INTERFACE_STATUS
:
2040 wpa_supplicant_event_interface_status(wpa_s
, data
);
2042 case EVENT_PMKID_CANDIDATE
:
2043 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2045 #ifdef CONFIG_PEERKEY
2046 case EVENT_STKSTART
:
2047 wpa_supplicant_event_stkstart(wpa_s
, data
);
2049 #endif /* CONFIG_PEERKEY */
2052 wpa_supplicant_event_tdls(wpa_s
, data
);
2054 #endif /* CONFIG_TDLS */
2055 #ifdef CONFIG_IEEE80211R
2056 case EVENT_FT_RESPONSE
:
2057 wpa_supplicant_event_ft_response(wpa_s
, data
);
2059 #endif /* CONFIG_IEEE80211R */
2060 #ifdef CONFIG_IBSS_RSN
2061 case EVENT_IBSS_RSN_START
:
2062 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2064 #endif /* CONFIG_IBSS_RSN */
2065 case EVENT_ASSOC_REJECT
:
2066 if (data
->assoc_reject
.bssid
)
2067 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2068 "bssid=" MACSTR
" status_code=%u",
2069 MAC2STR(data
->assoc_reject
.bssid
),
2070 data
->assoc_reject
.status_code
);
2072 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2074 data
->assoc_reject
.status_code
);
2075 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2076 sme_event_assoc_reject(wpa_s
, data
);
2078 case EVENT_AUTH_TIMED_OUT
:
2079 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2080 sme_event_auth_timed_out(wpa_s
, data
);
2082 case EVENT_ASSOC_TIMED_OUT
:
2083 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2084 sme_event_assoc_timed_out(wpa_s
, data
);
2086 case EVENT_TX_STATUS
:
2087 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
2088 " type=%d stype=%d",
2089 MAC2STR(data
->tx_status
.dst
),
2090 data
->tx_status
.type
, data
->tx_status
.stype
);
2092 if (wpa_s
->ap_iface
== NULL
) {
2093 #ifdef CONFIG_OFFCHANNEL
2094 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2095 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
2096 offchannel_send_action_tx_status(
2097 wpa_s
, data
->tx_status
.dst
,
2098 data
->tx_status
.data
,
2099 data
->tx_status
.data_len
,
2100 data
->tx_status
.ack
?
2101 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2102 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2103 #endif /* CONFIG_OFFCHANNEL */
2106 #endif /* CONFIG_AP */
2107 #ifdef CONFIG_OFFCHANNEL
2108 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
2109 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
2111 * Catch TX status events for Action frames we sent via group
2112 * interface in GO mode.
2114 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2115 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
2116 os_memcmp(wpa_s
->parent
->pending_action_dst
,
2117 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
2118 offchannel_send_action_tx_status(
2119 wpa_s
->parent
, data
->tx_status
.dst
,
2120 data
->tx_status
.data
,
2121 data
->tx_status
.data_len
,
2122 data
->tx_status
.ack
?
2123 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2124 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2127 #endif /* CONFIG_OFFCHANNEL */
2129 switch (data
->tx_status
.type
) {
2130 case WLAN_FC_TYPE_MGMT
:
2131 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
2132 data
->tx_status
.data_len
,
2133 data
->tx_status
.stype
,
2134 data
->tx_status
.ack
);
2136 case WLAN_FC_TYPE_DATA
:
2137 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
2138 data
->tx_status
.data
,
2139 data
->tx_status
.data_len
,
2140 data
->tx_status
.ack
);
2143 #endif /* CONFIG_AP */
2146 case EVENT_DRIVER_CLIENT_POLL_OK
:
2147 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
2149 case EVENT_RX_FROM_UNKNOWN
:
2150 if (wpa_s
->ap_iface
== NULL
)
2152 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
2153 data
->rx_from_unknown
.wds
);
2156 if (wpa_s
->ap_iface
== NULL
) {
2159 const struct ieee80211_mgmt
*mgmt
;
2160 mgmt
= (const struct ieee80211_mgmt
*)
2161 data
->rx_mgmt
.frame
;
2162 fc
= le_to_host16(mgmt
->frame_control
);
2163 stype
= WLAN_FC_GET_STYPE(fc
);
2164 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2165 data
->rx_mgmt
.frame_len
> 24) {
2166 const u8
*src
= mgmt
->sa
;
2167 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2168 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2169 (mgmt
->u
.probe_req
.variable
-
2170 data
->rx_mgmt
.frame
);
2171 wpas_p2p_probe_req_rx(wpa_s
, src
, mgmt
->da
,
2172 mgmt
->bssid
, ie
, ie_len
);
2175 #endif /* CONFIG_P2P */
2176 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2177 "management frame in non-AP mode");
2180 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2182 #endif /* CONFIG_AP */
2183 case EVENT_RX_ACTION
:
2184 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2185 " Category=%u DataLen=%d freq=%d MHz",
2186 MAC2STR(data
->rx_action
.sa
),
2187 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2188 data
->rx_action
.freq
);
2189 #ifdef CONFIG_IEEE80211R
2190 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2191 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2192 data
->rx_action
.len
);
2195 #endif /* CONFIG_IEEE80211R */
2196 #ifdef CONFIG_IEEE80211W
2198 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2199 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2200 data
->rx_action
.data
,
2201 data
->rx_action
.len
);
2204 #endif /* CONFIG_SME */
2205 #endif /* CONFIG_IEEE80211W */
2207 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2208 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2209 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2210 data
->rx_action
.data
, data
->rx_action
.len
,
2211 data
->rx_action
.freq
) == 0)
2213 #endif /* CONFIG_GAS */
2214 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2215 wnm_action_rx(wpa_s
, &data
->rx_action
);
2219 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2220 data
->rx_action
.len
>= 4 &&
2221 data
->rx_action
.data
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
2222 wpa_dbg(wpa_s
, MSG_DEBUG
, "TDLS: Received Discovery "
2223 "Response from " MACSTR
,
2224 MAC2STR(data
->rx_action
.sa
));
2227 #endif /* CONFIG_TDLS */
2229 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2231 data
->rx_action
.bssid
,
2232 data
->rx_action
.category
,
2233 data
->rx_action
.data
,
2234 data
->rx_action
.len
, data
->rx_action
.freq
);
2235 #endif /* CONFIG_P2P */
2237 case EVENT_RX_PROBE_REQ
:
2238 if (data
->rx_probe_req
.sa
== NULL
||
2239 data
->rx_probe_req
.ie
== NULL
)
2242 if (wpa_s
->ap_iface
) {
2243 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2244 data
->rx_probe_req
.sa
,
2245 data
->rx_probe_req
.da
,
2246 data
->rx_probe_req
.bssid
,
2247 data
->rx_probe_req
.ie
,
2248 data
->rx_probe_req
.ie_len
);
2251 #endif /* CONFIG_AP */
2253 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2254 data
->rx_probe_req
.da
,
2255 data
->rx_probe_req
.bssid
,
2256 data
->rx_probe_req
.ie
,
2257 data
->rx_probe_req
.ie_len
);
2258 #endif /* CONFIG_P2P */
2260 case EVENT_REMAIN_ON_CHANNEL
:
2261 #ifdef CONFIG_OFFCHANNEL
2262 offchannel_remain_on_channel_cb(
2263 wpa_s
, data
->remain_on_channel
.freq
,
2264 data
->remain_on_channel
.duration
);
2265 #endif /* CONFIG_OFFCHANNEL */
2267 wpas_p2p_remain_on_channel_cb(
2268 wpa_s
, data
->remain_on_channel
.freq
,
2269 data
->remain_on_channel
.duration
);
2270 #endif /* CONFIG_P2P */
2272 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2273 #ifdef CONFIG_OFFCHANNEL
2274 offchannel_cancel_remain_on_channel_cb(
2275 wpa_s
, data
->remain_on_channel
.freq
);
2276 #endif /* CONFIG_OFFCHANNEL */
2278 wpas_p2p_cancel_remain_on_channel_cb(
2279 wpa_s
, data
->remain_on_channel
.freq
);
2280 #endif /* CONFIG_P2P */
2283 case EVENT_P2P_DEV_FOUND
: {
2284 struct p2p_peer_info peer_info
;
2286 os_memset(&peer_info
, 0, sizeof(peer_info
));
2287 if (data
->p2p_dev_found
.dev_addr
)
2288 os_memcpy(peer_info
.p2p_device_addr
,
2289 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2290 if (data
->p2p_dev_found
.pri_dev_type
)
2291 os_memcpy(peer_info
.pri_dev_type
,
2292 data
->p2p_dev_found
.pri_dev_type
,
2293 sizeof(peer_info
.pri_dev_type
));
2294 if (data
->p2p_dev_found
.dev_name
)
2295 os_strlcpy(peer_info
.device_name
,
2296 data
->p2p_dev_found
.dev_name
,
2297 sizeof(peer_info
.device_name
));
2298 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2299 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2300 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2303 * FIX: new_device=1 is not necessarily correct. We should
2304 * maintain a P2P peer database in wpa_supplicant and update
2305 * this information based on whether the peer is truly new.
2307 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2310 case EVENT_P2P_GO_NEG_REQ_RX
:
2311 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2312 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2314 case EVENT_P2P_GO_NEG_COMPLETED
:
2315 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2317 case EVENT_P2P_PROV_DISC_REQUEST
:
2318 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2319 data
->p2p_prov_disc_req
.config_methods
,
2320 data
->p2p_prov_disc_req
.dev_addr
,
2321 data
->p2p_prov_disc_req
.pri_dev_type
,
2322 data
->p2p_prov_disc_req
.dev_name
,
2323 data
->p2p_prov_disc_req
.supp_config_methods
,
2324 data
->p2p_prov_disc_req
.dev_capab
,
2325 data
->p2p_prov_disc_req
.group_capab
);
2327 case EVENT_P2P_PROV_DISC_RESPONSE
:
2328 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2329 data
->p2p_prov_disc_resp
.config_methods
);
2331 case EVENT_P2P_SD_REQUEST
:
2332 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2333 data
->p2p_sd_req
.sa
,
2334 data
->p2p_sd_req
.dialog_token
,
2335 data
->p2p_sd_req
.update_indic
,
2336 data
->p2p_sd_req
.tlvs
,
2337 data
->p2p_sd_req
.tlvs_len
);
2339 case EVENT_P2P_SD_RESPONSE
:
2340 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2341 data
->p2p_sd_resp
.update_indic
,
2342 data
->p2p_sd_resp
.tlvs
,
2343 data
->p2p_sd_resp
.tlvs_len
);
2345 #endif /* CONFIG_P2P */
2346 case EVENT_EAPOL_RX
:
2347 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2348 data
->eapol_rx
.data
,
2349 data
->eapol_rx
.data_len
);
2351 case EVENT_SIGNAL_CHANGE
:
2352 bgscan_notify_signal_change(
2353 wpa_s
, data
->signal_change
.above_threshold
,
2354 data
->signal_change
.current_signal
,
2355 data
->signal_change
.current_noise
,
2356 data
->signal_change
.current_txrate
);
2358 case EVENT_INTERFACE_ENABLED
:
2359 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2360 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2362 if (!wpa_s
->ap_iface
) {
2363 wpa_supplicant_set_state(wpa_s
,
2365 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2367 wpa_supplicant_set_state(wpa_s
,
2369 #else /* CONFIG_AP */
2370 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2371 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2372 #endif /* CONFIG_AP */
2375 case EVENT_INTERFACE_DISABLED
:
2376 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2377 wpa_supplicant_mark_disassoc(wpa_s
);
2378 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2380 case EVENT_CHANNEL_LIST_CHANGED
:
2381 if (wpa_s
->drv_priv
== NULL
)
2382 break; /* Ignore event during drv initialization */
2384 wpas_p2p_update_channel_list(wpa_s
);
2385 #endif /* CONFIG_P2P */
2387 case EVENT_INTERFACE_UNAVAILABLE
:
2389 wpas_p2p_interface_unavailable(wpa_s
);
2390 #endif /* CONFIG_P2P */
2392 case EVENT_BEST_CHANNEL
:
2393 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2395 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2396 data
->best_chan
.freq_overall
);
2397 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2398 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2399 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2401 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2402 data
->best_chan
.freq_5
,
2403 data
->best_chan
.freq_overall
);
2404 #endif /* CONFIG_P2P */
2406 case EVENT_UNPROT_DEAUTH
:
2407 wpa_supplicant_event_unprot_deauth(wpa_s
,
2408 &data
->unprot_deauth
);
2410 case EVENT_UNPROT_DISASSOC
:
2411 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2412 &data
->unprot_disassoc
);
2414 case EVENT_STATION_LOW_ACK
:
2416 if (wpa_s
->ap_iface
&& data
)
2417 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2418 data
->low_ack
.addr
);
2419 #endif /* CONFIG_AP */
2422 wpa_tdls_disable_link(wpa_s
->wpa
, data
->low_ack
.addr
);
2423 #endif /* CONFIG_TDLS */
2425 case EVENT_IBSS_PEER_LOST
:
2426 #ifdef CONFIG_IBSS_RSN
2427 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2428 #endif /* CONFIG_IBSS_RSN */
2430 case EVENT_DRIVER_GTK_REKEY
:
2431 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2432 wpa_s
->bssid
, ETH_ALEN
))
2436 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2437 data
->driver_gtk_rekey
.replay_ctr
);
2439 case EVENT_SCHED_SCAN_STOPPED
:
2440 wpa_s
->sched_scanning
= 0;
2441 wpa_supplicant_notify_scanning(wpa_s
, 0);
2444 * If we timed out, start a new sched scan to continue
2445 * searching for more SSIDs.
2447 if (wpa_s
->sched_scan_timed_out
)
2448 wpa_supplicant_req_sched_scan(wpa_s
);
2450 case EVENT_WPS_BUTTON_PUSHED
:
2452 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
2453 #endif /* CONFIG_WPS */
2456 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);