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 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
102 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
104 if (wpa_s
->countermeasures
) {
105 wpa_s
->countermeasures
= 0;
106 wpa_drv_set_countermeasures(wpa_s
, 0);
107 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
108 wpa_supplicant_req_scan(wpa_s
, 0, 0);
113 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
117 #ifdef CONFIG_IBSS_RSN
118 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
119 wpa_s
->ibss_rsn
= NULL
;
120 #endif /* CONFIG_IBSS_RSN */
123 wpa_supplicant_ap_deinit(wpa_s
);
124 #endif /* CONFIG_AP */
126 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
129 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
130 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
131 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
132 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
133 wpa_s
->current_bss
= NULL
;
134 wpa_s
->assoc_freq
= 0;
135 #ifdef CONFIG_IEEE80211R
137 if (wpa_s
->sme
.ft_ies
)
138 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
139 #endif /* CONFIG_SME */
140 #endif /* CONFIG_IEEE80211R */
143 wpas_notify_bssid_changed(wpa_s
);
145 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
146 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
147 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
148 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
149 wpa_s
->ap_ies_from_associnfo
= 0;
153 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
155 struct wpa_ie_data ie
;
159 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
163 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
164 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
165 ie
.pmkid
+ i
* PMKID_LEN
,
167 if (pmksa_set
== 0) {
168 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
173 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
174 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
178 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
179 union wpa_event_data
*data
)
182 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
186 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
187 " index=%d preauth=%d",
188 MAC2STR(data
->pmkid_candidate
.bssid
),
189 data
->pmkid_candidate
.index
,
190 data
->pmkid_candidate
.preauth
);
192 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
193 data
->pmkid_candidate
.index
,
194 data
->pmkid_candidate
.preauth
);
198 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
200 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
201 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
204 #ifdef IEEE8021X_EAPOL
205 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
206 wpa_s
->current_ssid
&&
207 !(wpa_s
->current_ssid
->eapol_flags
&
208 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
209 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
210 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
211 * plaintext or static WEP keys). */
214 #endif /* IEEE8021X_EAPOL */
221 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
222 * @wpa_s: pointer to wpa_supplicant data
223 * @ssid: Configuration data for the network
224 * Returns: 0 on success, -1 on failure
226 * This function is called when starting authentication with a network that is
227 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
229 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
230 struct wpa_ssid
*ssid
)
232 #ifdef IEEE8021X_EAPOL
234 int aka
= 0, sim
= 0, type
;
236 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
239 if (ssid
->eap
.eap_methods
== NULL
) {
243 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
244 while (eap
->vendor
!= EAP_VENDOR_IETF
||
245 eap
->method
!= EAP_TYPE_NONE
) {
246 if (eap
->vendor
== EAP_VENDOR_IETF
) {
247 if (eap
->method
== EAP_TYPE_SIM
)
249 else if (eap
->method
== EAP_TYPE_AKA
)
256 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
258 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
262 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
263 "use SIM, but neither EAP-SIM nor EAP-AKA are "
268 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
269 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
271 type
= SCARD_TRY_BOTH
;
273 type
= SCARD_USIM_ONLY
;
275 type
= SCARD_GSM_SIM_ONLY
;
277 wpa_s
->scard
= scard_init(type
);
278 if (wpa_s
->scard
== NULL
) {
279 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
283 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
284 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
285 #endif /* PCSC_FUNCS */
286 #endif /* IEEE8021X_EAPOL */
292 #ifndef CONFIG_NO_SCAN_PROCESSING
293 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
294 struct wpa_ssid
*ssid
)
298 if (ssid
->mixed_cell
)
302 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
304 #endif /* CONFIG_WPS */
306 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
307 if (ssid
->wep_key_len
[i
]) {
312 #ifdef IEEE8021X_EAPOL
313 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
314 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
315 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
317 #endif /* IEEE8021X_EAPOL */
319 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
322 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
328 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
329 struct wpa_ssid
*ssid
,
330 struct wpa_scan_res
*bss
)
332 struct wpa_ie_data ie
;
334 const u8
*rsn_ie
, *wpa_ie
;
338 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
342 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
343 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
344 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
345 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
346 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
348 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
349 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
352 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
353 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
359 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
361 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
366 if (!(ie
.proto
& ssid
->proto
)) {
367 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
372 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
373 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
378 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
379 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
384 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
385 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
390 #ifdef CONFIG_IEEE80211W
391 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
392 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
393 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
397 #endif /* CONFIG_IEEE80211W */
399 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
403 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
404 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
407 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
408 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
414 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
416 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
421 if (!(ie
.proto
& ssid
->proto
)) {
422 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
427 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
428 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
433 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
434 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
439 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
440 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
445 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
449 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
450 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
451 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
455 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
456 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
460 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
467 static int freq_allowed(int *freqs
, int freq
)
474 for (i
= 0; freqs
[i
]; i
++)
475 if (freqs
[i
] == freq
)
481 static int ht_supported(const struct hostapd_hw_modes
*mode
)
483 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
485 * The driver did not indicate whether it supports HT. Assume
486 * it does to avoid connection issues.
492 * IEEE Std 802.11n-2009 20.1.1:
493 * An HT non-AP STA shall support all EQM rates for one spatial stream.
495 return mode
->mcs_set
[0] == 0xff;
499 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_scan_res
*bss
)
501 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
502 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
506 modes
= wpa_s
->hw
.modes
;
509 * The driver does not provide any additional information
510 * about the utilized hardware, so allow the connection attempt
516 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
517 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
518 int freq
= modes
[i
].channels
[j
].freq
;
519 if (freq
== bss
->freq
) {
521 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
522 break; /* do not allow 802.11b replace
533 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
534 rate_ie
= wpa_scan_get_ie(bss
, scan_ie
[i
]);
538 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
539 int flagged
= !!(rate_ie
[j
] & 0x80);
540 int r
= (rate_ie
[j
] & 0x7f) * 5;
543 * IEEE Std 802.11n-2009 7.3.2.2:
544 * The new BSS Membership selector value is encoded
545 * like a legacy basic rate, but it is not a rate and
546 * only indicates if the BSS members are required to
547 * support the mandatory features of Clause 20 [HT PHY]
548 * in order to join the BSS.
550 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
551 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
552 if (!ht_supported(mode
)) {
553 wpa_dbg(wpa_s
, MSG_DEBUG
,
554 " hardware does not support "
564 /* check for legacy basic rates */
565 for (k
= 0; k
< mode
->num_rates
; k
++) {
566 if (mode
->rates
[k
] == r
)
569 if (k
== mode
->num_rates
) {
571 * IEEE Std 802.11-2007 7.3.2.2 demands that in
572 * order to join a BSS all required rates
573 * have to be supported by the hardware.
575 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
576 "not support required rate %d.%d Mbps",
587 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
588 int i
, struct wpa_scan_res
*bss
,
589 struct wpa_ssid
*group
)
592 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
594 struct wpa_blacklist
*e
;
596 struct wpa_ssid
*ssid
;
598 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
599 ssid_
= ie
? ie
+ 2 : (u8
*) "";
600 ssid_len
= ie
? ie
[1] : 0;
602 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
603 wpa_ie_len
= ie
? ie
[1] : 0;
605 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
606 rsn_ie_len
= ie
? ie
[1] : 0;
608 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
609 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
610 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
611 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
612 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
614 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
617 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
619 * When only a single network is enabled, we can
620 * trigger blacklisting on the first failure. This
621 * should not be done with multiple enabled networks to
622 * avoid getting forced to move into a worse ESS on
623 * single error if there are no other BSSes of the
628 if (e
->count
> limit
) {
629 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
630 "(count=%d limit=%d)", e
->count
, limit
);
636 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
640 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
642 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
643 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
645 if (ssid
->disabled
) {
646 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
651 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
652 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
657 if (wpa
&& ssid
->ssid_len
== 0 &&
658 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
661 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
662 /* Only allow wildcard SSID match if an AP
663 * advertises active WPS operation that matches
666 if (ssid
->ssid_len
== 0 &&
667 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
670 #endif /* CONFIG_WPS */
672 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
673 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
677 (ssid_len
!= ssid
->ssid_len
||
678 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
679 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
683 if (ssid
->bssid_set
&&
684 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
685 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
689 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
693 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
694 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
695 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
696 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
701 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
702 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
707 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
708 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
713 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
714 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
719 if (!rate_match(wpa_s
, bss
)) {
720 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
727 * TODO: skip the AP if its P2P IE has Group Formation
728 * bit set in the P2P Group Capability Bitmap and we
729 * are not in Group Formation with that device.
731 #endif /* CONFIG_P2P */
733 /* Matching configuration found */
737 /* No matching configuration found */
742 static struct wpa_bss
*
743 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
744 struct wpa_scan_results
*scan_res
,
745 struct wpa_ssid
*group
,
746 struct wpa_ssid
**selected_ssid
)
750 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
753 for (i
= 0; i
< scan_res
->num
; i
++) {
754 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
758 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
762 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
763 ssid
= ie
? ie
+ 2 : (u8
*) "";
764 ssid_len
= ie
? ie
[1] : 0;
766 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
768 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
769 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
776 static struct wpa_bss
*
777 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
778 struct wpa_scan_results
*scan_res
,
779 struct wpa_ssid
**selected_ssid
)
781 struct wpa_bss
*selected
= NULL
;
784 while (selected
== NULL
) {
785 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
786 selected
= wpa_supplicant_select_bss(
787 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
793 if (selected
== NULL
&& wpa_s
->blacklist
) {
794 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
795 "blacklist and try again");
796 wpa_blacklist_clear(wpa_s
);
797 wpa_s
->blacklist_cleared
++;
798 } else if (selected
== NULL
)
806 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
807 int timeout_sec
, int timeout_usec
)
809 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
811 * No networks are enabled; short-circuit request so
812 * we don't wait timeout seconds before transitioning
815 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
818 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
822 void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
823 struct wpa_bss
*selected
,
824 struct wpa_ssid
*ssid
)
826 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
827 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
828 "PBC session overlap");
830 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
832 #endif /* CONFIG_P2P */
835 wpas_wps_cancel(wpa_s
);
836 #endif /* CONFIG_WPS */
841 * Do not trigger new association unless the BSSID has changed or if
842 * reassociation is requested. If we are in process of associating with
843 * the selected BSSID, do not trigger new attempt.
845 if (wpa_s
->reassociate
||
846 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
847 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
848 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
849 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
851 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
852 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
855 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
856 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
857 " pending: " MACSTR
" wpa_state: %s",
858 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
859 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
860 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
861 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
863 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
869 static struct wpa_ssid
*
870 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
873 struct wpa_ssid
*ssid
;
875 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
876 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
880 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
881 ssid
->mode
== IEEE80211_MODE_AP
)
889 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
890 * on BSS added and BSS changed events */
891 static void wpa_supplicant_rsn_preauth_scan_results(
892 struct wpa_supplicant
*wpa_s
)
896 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
899 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
900 const u8
*ssid
, *rsn
;
902 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
906 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
910 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
916 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
917 struct wpa_bss
*selected
,
918 struct wpa_ssid
*ssid
,
919 struct wpa_scan_results
*scan_res
)
922 struct wpa_scan_res
*current_bss
= NULL
;
925 if (wpa_s
->reassociate
)
926 return 1; /* explicit request to reassociate */
927 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
928 return 1; /* we are not associated; continue */
929 if (wpa_s
->current_ssid
== NULL
)
930 return 1; /* unknown current SSID */
931 if (wpa_s
->current_ssid
!= ssid
)
932 return 1; /* different network block */
934 if (wpas_driver_bss_selection(wpa_s
))
935 return 0; /* Driver-based roaming */
937 for (i
= 0; i
< scan_res
->num
; i
++) {
938 struct wpa_scan_res
*res
= scan_res
->res
[i
];
940 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
943 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
946 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
947 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
954 return 1; /* current BSS not seen in scan results */
956 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
957 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
958 MAC2STR(current_bss
->bssid
), current_bss
->level
);
959 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
960 MAC2STR(selected
->bssid
), selected
->level
);
962 if (wpa_s
->current_ssid
->bssid_set
&&
963 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
965 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
966 "has preferred BSSID");
971 if (current_bss
->level
< 0) {
972 if (current_bss
->level
< -85)
974 else if (current_bss
->level
< -80)
976 else if (current_bss
->level
< -75)
978 else if (current_bss
->level
< -70)
983 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
984 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
992 /* Return < 0 if no scan results could be fetched. */
993 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
994 union wpa_event_data
*data
)
996 struct wpa_bss
*selected
;
997 struct wpa_ssid
*ssid
= NULL
;
998 struct wpa_scan_results
*scan_res
;
1002 if (wpa_s
->ap_iface
)
1004 #endif /* CONFIG_AP */
1006 wpa_supplicant_notify_scanning(wpa_s
, 0);
1008 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1009 data
? &data
->scan_info
:
1011 if (scan_res
== NULL
) {
1012 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
1014 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1016 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1020 #ifndef CONFIG_NO_RANDOM_POOL
1022 num
= scan_res
->num
;
1025 for (i
= 0; i
< num
; i
++) {
1027 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1028 buf
[0] = res
->bssid
[5];
1029 buf
[1] = res
->qual
& 0xff;
1030 buf
[2] = res
->noise
& 0xff;
1031 buf
[3] = res
->level
& 0xff;
1032 buf
[4] = res
->tsf
& 0xff;
1033 random_add_randomness(buf
, sizeof(buf
));
1035 #endif /* CONFIG_NO_RANDOM_POOL */
1037 if (wpa_s
->scan_res_handler
) {
1038 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1039 struct wpa_scan_results
*scan_res
);
1041 scan_res_handler
= wpa_s
->scan_res_handler
;
1042 wpa_s
->scan_res_handler
= NULL
;
1043 scan_res_handler(wpa_s
, scan_res
);
1045 wpa_scan_results_free(scan_res
);
1050 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1052 if (wpa_s
->ap_iface
->scan_cb
)
1053 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1054 #endif /* CONFIG_AP */
1055 wpa_scan_results_free(scan_res
);
1059 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
1060 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1061 wpas_notify_scan_results(wpa_s
);
1063 wpas_notify_scan_done(wpa_s
, 1);
1065 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
1066 wpa_scan_results_free(scan_res
);
1070 if (wpa_s
->disconnected
) {
1071 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1072 wpa_scan_results_free(scan_res
);
1076 if (!wpas_driver_bss_selection(wpa_s
) &&
1077 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
1078 wpa_scan_results_free(scan_res
);
1082 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
1086 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
1088 wpa_scan_results_free(scan_res
);
1091 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
1092 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1094 wpa_scan_results_free(scan_res
);
1095 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1096 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1098 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1099 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1100 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1102 int timeout_sec
= wpa_s
->scan_interval
;
1103 int timeout_usec
= 0;
1105 if (wpa_s
->p2p_in_provisioning
) {
1107 * Use shorter wait during P2P Provisioning
1108 * state to speed up group formation.
1111 timeout_usec
= 250000;
1112 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1116 #endif /* CONFIG_P2P */
1117 if (wpa_supplicant_req_sched_scan(wpa_s
))
1118 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1126 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1127 union wpa_event_data
*data
)
1129 const char *rn
, *rn2
;
1130 struct wpa_supplicant
*ifs
;
1132 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1134 * If no scan results could be fetched, then no need to
1135 * notify those interfaces that did not actually request
1142 * Check other interfaces to see if they have the same radio-name. If
1143 * so, they get updated with this same scan info.
1145 if (!wpa_s
->driver
->get_radio_name
)
1148 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1149 if (rn
== NULL
|| rn
[0] == '\0')
1152 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1153 "sharing same radio (%s) in event_scan_results", rn
);
1155 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1156 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1159 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1160 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1161 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1162 "sibling", ifs
->ifname
);
1163 _wpa_supplicant_event_scan_results(ifs
, data
);
1168 #endif /* CONFIG_NO_SCAN_PROCESSING */
1171 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1172 union wpa_event_data
*data
)
1174 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1177 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1178 if (data
->assoc_info
.req_ies
)
1179 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1180 data
->assoc_info
.req_ies_len
);
1181 if (data
->assoc_info
.resp_ies
) {
1182 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1183 data
->assoc_info
.resp_ies_len
);
1185 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1186 data
->assoc_info
.resp_ies_len
);
1187 #endif /* CONFIG_TDLS */
1189 if (data
->assoc_info
.beacon_ies
)
1190 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1191 data
->assoc_info
.beacon_ies
,
1192 data
->assoc_info
.beacon_ies_len
);
1193 if (data
->assoc_info
.freq
)
1194 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1195 data
->assoc_info
.freq
);
1197 p
= data
->assoc_info
.req_ies
;
1198 l
= data
->assoc_info
.req_ies_len
;
1200 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1201 while (p
&& l
>= 2) {
1204 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1208 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1209 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1210 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1211 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1214 wpa_find_assoc_pmkid(wpa_s
);
1220 if (!found
&& data
->assoc_info
.req_ies
)
1221 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1223 #ifdef CONFIG_IEEE80211R
1225 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1227 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1228 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1229 data
->assoc_info
.resp_ies
,
1230 data
->assoc_info
.resp_ies_len
,
1232 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1233 "Reassociation Response failed");
1234 wpa_supplicant_deauthenticate(
1235 wpa_s
, WLAN_REASON_INVALID_IE
);
1240 p
= data
->assoc_info
.resp_ies
;
1241 l
= data
->assoc_info
.resp_ies_len
;
1243 #ifdef CONFIG_WPS_STRICT
1244 if (p
&& wpa_s
->current_ssid
&&
1245 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1247 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1249 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1250 "include WPS IE in (Re)Association Response");
1254 if (wps_validate_assoc_resp(wps
) < 0) {
1256 wpa_supplicant_deauthenticate(
1257 wpa_s
, WLAN_REASON_INVALID_IE
);
1262 #endif /* CONFIG_WPS_STRICT */
1264 /* Go through the IEs and make a copy of the MDIE, if present. */
1265 while (p
&& l
>= 2) {
1268 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1272 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1273 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1274 wpa_s
->sme
.ft_used
= 1;
1275 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1276 MOBILITY_DOMAIN_ID_LEN
);
1282 #endif /* CONFIG_SME */
1284 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1285 data
->assoc_info
.resp_ies_len
);
1286 #endif /* CONFIG_IEEE80211R */
1288 /* WPA/RSN IE from Beacon/ProbeResp */
1289 p
= data
->assoc_info
.beacon_ies
;
1290 l
= data
->assoc_info
.beacon_ies_len
;
1292 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1294 wpa_found
= rsn_found
= 0;
1295 while (p
&& l
>= 2) {
1298 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1303 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1304 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1306 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1310 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1312 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1319 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1320 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1321 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1322 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1323 if (wpa_found
|| rsn_found
)
1324 wpa_s
->ap_ies_from_associnfo
= 1;
1326 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1327 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1328 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1330 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1331 wpa_supplicant_update_scan_results(wpa_s
);
1334 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1340 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1341 union wpa_event_data
*data
)
1346 struct wpa_driver_capa capa
;
1349 if (wpa_s
->ap_iface
) {
1350 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1351 data
->assoc_info
.addr
,
1352 data
->assoc_info
.req_ies
,
1353 data
->assoc_info
.req_ies_len
,
1354 data
->assoc_info
.reassoc
);
1357 #endif /* CONFIG_AP */
1359 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1360 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1363 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1364 if (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1365 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1366 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1367 MACSTR
, MAC2STR(bssid
));
1368 random_add_randomness(bssid
, ETH_ALEN
);
1369 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1370 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1371 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1373 wpas_notify_bssid_changed(wpa_s
);
1375 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1376 wpa_clear_keys(wpa_s
, bssid
);
1378 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1379 wpa_supplicant_disassociate(
1380 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1383 if (wpa_s
->current_ssid
) {
1384 struct wpa_bss
*bss
= NULL
;
1385 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1386 if (ssid
->ssid_len
> 0)
1387 bss
= wpa_bss_get(wpa_s
, bssid
,
1388 ssid
->ssid
, ssid
->ssid_len
);
1390 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1392 wpa_s
->current_bss
= bss
;
1397 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1398 wpa_s
->sme
.prev_bssid_set
= 1;
1399 #endif /* CONFIG_SME */
1401 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1402 if (wpa_s
->current_ssid
) {
1403 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1404 * initialized before association, but for other modes,
1405 * initialize PC/SC here, if the current configuration needs
1406 * smartcard or SIM/USIM. */
1407 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1409 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1411 l2_packet_notify_auth_start(wpa_s
->l2
);
1414 * Set portEnabled first to FALSE in order to get EAP state machine out
1415 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1416 * state machine may transit to AUTHENTICATING state based on obsolete
1417 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1418 * AUTHENTICATED without ever giving chance to EAP state machine to
1421 if (!ft_completed
) {
1422 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1423 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1425 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1426 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1427 /* 802.1X::portControl = Auto */
1428 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1429 wpa_s
->eapol_received
= 0;
1430 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1431 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1432 (wpa_s
->current_ssid
&&
1433 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1434 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1435 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1436 } else if (!ft_completed
) {
1437 /* Timeout for receiving the first EAPOL packet */
1438 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1440 wpa_supplicant_cancel_scan(wpa_s
);
1442 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1443 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1445 * We are done; the driver will take care of RSN 4-way
1448 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1449 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1450 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1451 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1452 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1453 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1455 * The driver will take care of RSN 4-way handshake, so we need
1456 * to allow EAPOL supplicant to complete its work without
1457 * waiting for WPA supplicant.
1459 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1460 } else if (ft_completed
) {
1462 * FT protocol completed - make sure EAPOL state machine ends
1463 * up in authenticated.
1465 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1466 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1467 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1468 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1471 if (wpa_s
->pending_eapol_rx
) {
1472 struct os_time now
, age
;
1474 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1475 if (age
.sec
== 0 && age
.usec
< 100000 &&
1476 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1478 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1479 "frame that was received just before "
1480 "association notification");
1481 wpa_supplicant_rx_eapol(
1482 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1483 wpabuf_head(wpa_s
->pending_eapol_rx
),
1484 wpabuf_len(wpa_s
->pending_eapol_rx
));
1486 wpabuf_free(wpa_s
->pending_eapol_rx
);
1487 wpa_s
->pending_eapol_rx
= NULL
;
1490 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1491 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1492 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1493 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1494 /* Set static WEP keys again */
1495 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1498 #ifdef CONFIG_IBSS_RSN
1499 if (wpa_s
->current_ssid
&&
1500 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1501 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1502 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1503 wpa_s
->ibss_rsn
== NULL
) {
1504 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1505 if (!wpa_s
->ibss_rsn
) {
1506 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1507 wpa_supplicant_deauthenticate(
1508 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1512 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1514 #endif /* CONFIG_IBSS_RSN */
1518 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1523 u8 prev_pending_bssid
[ETH_ALEN
];
1525 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1526 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1528 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1530 * At least Host AP driver and a Prism3 card seemed to be
1531 * generating streams of disconnected events when configuring
1532 * IBSS for WPA-None. Ignore them for now.
1534 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1535 "IBSS/WPA-None mode");
1539 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1540 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1541 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1542 "pre-shared key may be incorrect");
1544 if (!wpa_s
->auto_reconnect_disabled
||
1545 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1546 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1547 "reconnect (wps=%d)",
1548 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1549 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1550 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1552 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1553 "try to re-connect");
1554 wpa_s
->reassociate
= 0;
1555 wpa_s
->disconnected
= 1;
1557 bssid
= wpa_s
->bssid
;
1558 if (is_zero_ether_addr(bssid
))
1559 bssid
= wpa_s
->pending_bssid
;
1560 wpas_connection_failed(wpa_s
, bssid
);
1561 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1562 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1564 MAC2STR(bssid
), reason_code
);
1565 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1566 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1567 wpa_s
->keys_cleared
= 0;
1568 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1570 wpa_supplicant_mark_disassoc(wpa_s
);
1572 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1573 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1577 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1578 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1581 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1583 if (!wpa_s
->pending_mic_error_report
)
1586 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1587 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1588 wpa_s
->pending_mic_error_report
= 0;
1590 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1594 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1595 union wpa_event_data
*data
)
1600 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1601 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1603 if ((wpa_s
->last_michael_mic_error
&&
1604 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1605 wpa_s
->pending_mic_error_report
) {
1606 if (wpa_s
->pending_mic_error_report
) {
1608 * Send the pending MIC error report immediately since
1609 * we are going to start countermeasures and AP better
1612 wpa_sm_key_request(wpa_s
->wpa
, 1,
1613 wpa_s
->pending_mic_error_pairwise
);
1616 /* Send the new MIC error report immediately since we are going
1617 * to start countermeasures and AP better do the same.
1619 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1621 /* initialize countermeasures */
1622 wpa_s
->countermeasures
= 1;
1623 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1626 * Need to wait for completion of request frame. We do not get
1627 * any callback for the message completion, so just wait a
1628 * short while and hope for the best. */
1631 wpa_drv_set_countermeasures(wpa_s
, 1);
1632 wpa_supplicant_deauthenticate(wpa_s
,
1633 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1634 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1636 eloop_register_timeout(60, 0,
1637 wpa_supplicant_stop_countermeasures
,
1639 /* TODO: mark the AP rejected for 60 second. STA is
1640 * allowed to associate with another AP.. */
1642 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1643 if (wpa_s
->mic_errors_seen
) {
1645 * Reduce the effectiveness of Michael MIC error
1646 * reports as a means for attacking against TKIP if
1647 * more than one MIC failure is noticed with the same
1648 * PTK. We delay the transmission of the reports by a
1649 * random time between 0 and 60 seconds in order to
1650 * force the attacker wait 60 seconds before getting
1651 * the information on whether a frame resulted in a MIC
1657 if (os_get_random(rval
, sizeof(rval
)) < 0)
1658 sec
= os_random() % 60;
1660 sec
= WPA_GET_BE32(rval
) % 60;
1661 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1662 "report %d seconds", sec
);
1663 wpa_s
->pending_mic_error_report
= 1;
1664 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1665 eloop_cancel_timeout(
1666 wpa_supplicant_delayed_mic_error_report
,
1668 eloop_register_timeout(
1669 sec
, os_random() % 1000000,
1670 wpa_supplicant_delayed_mic_error_report
,
1673 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1675 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1676 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1677 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1679 wpa_s
->last_michael_mic_error
= t
.sec
;
1680 wpa_s
->mic_errors_seen
++;
1684 #ifdef CONFIG_TERMINATE_ONLASTIF
1685 static int any_interfaces(struct wpa_supplicant
*head
)
1687 struct wpa_supplicant
*wpa_s
;
1689 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1690 if (!wpa_s
->interface_removed
)
1694 #endif /* CONFIG_TERMINATE_ONLASTIF */
1698 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1699 union wpa_event_data
*data
)
1701 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1704 switch (data
->interface_status
.ievent
) {
1705 case EVENT_INTERFACE_ADDED
:
1706 if (!wpa_s
->interface_removed
)
1708 wpa_s
->interface_removed
= 0;
1709 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1710 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1711 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1712 "driver after interface was added");
1715 case EVENT_INTERFACE_REMOVED
:
1716 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1717 wpa_s
->interface_removed
= 1;
1718 wpa_supplicant_mark_disassoc(wpa_s
);
1719 l2_packet_deinit(wpa_s
->l2
);
1721 #ifdef CONFIG_IBSS_RSN
1722 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1723 wpa_s
->ibss_rsn
= NULL
;
1724 #endif /* CONFIG_IBSS_RSN */
1725 #ifdef CONFIG_TERMINATE_ONLASTIF
1726 /* check if last interface */
1727 if (!any_interfaces(wpa_s
->global
->ifaces
))
1729 #endif /* CONFIG_TERMINATE_ONLASTIF */
1735 #ifdef CONFIG_PEERKEY
1737 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1738 union wpa_event_data
*data
)
1742 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1744 #endif /* CONFIG_PEERKEY */
1748 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1749 union wpa_event_data
*data
)
1753 switch (data
->tdls
.oper
) {
1754 case TDLS_REQUEST_SETUP
:
1755 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1757 case TDLS_REQUEST_TEARDOWN
:
1758 /* request from driver to add FTIE */
1759 wpa_tdls_recv_teardown_notify(wpa_s
->wpa
, data
->tdls
.peer
,
1760 data
->tdls
.reason_code
);
1764 #endif /* CONFIG_TDLS */
1767 #ifdef CONFIG_IEEE80211R
1769 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1770 union wpa_event_data
*data
)
1775 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1776 data
->ft_ies
.ies_len
,
1777 data
->ft_ies
.ft_action
,
1778 data
->ft_ies
.target_ap
,
1779 data
->ft_ies
.ric_ies
,
1780 data
->ft_ies
.ric_ies_len
) < 0) {
1781 /* TODO: prevent MLME/driver from trying to associate? */
1784 #endif /* CONFIG_IEEE80211R */
1787 #ifdef CONFIG_IBSS_RSN
1788 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1789 union wpa_event_data
*data
)
1791 struct wpa_ssid
*ssid
;
1792 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1796 ssid
= wpa_s
->current_ssid
;
1799 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1802 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1804 #endif /* CONFIG_IBSS_RSN */
1807 #ifdef CONFIG_IEEE80211R
1808 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1811 const u8
*sta_addr
, *target_ap_addr
;
1814 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1815 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1816 return; /* only SME case supported for now */
1817 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1820 return; /* Only FT Action Response is supported for now */
1821 sta_addr
= data
+ 1;
1822 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1823 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1824 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1825 MACSTR
" TargetAP " MACSTR
" status %u",
1826 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1828 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1829 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1830 " in FT Action Response", MAC2STR(sta_addr
));
1835 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1836 "failure (status code %d)", status
);
1837 /* TODO: report error to FT code(?) */
1841 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1842 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1843 target_ap_addr
, NULL
, 0) < 0)
1848 struct wpa_bss
*bss
;
1849 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1851 wpa_s
->sme
.freq
= bss
->freq
;
1852 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1853 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1856 #endif /* CONFIG_SME */
1858 #endif /* CONFIG_IEEE80211R */
1861 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1862 struct unprot_deauth
*e
)
1864 #ifdef CONFIG_IEEE80211W
1865 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1866 "dropped: " MACSTR
" -> " MACSTR
1867 " (reason code %u)",
1868 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1869 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1870 #endif /* CONFIG_IEEE80211W */
1874 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1875 struct unprot_disassoc
*e
)
1877 #ifdef CONFIG_IEEE80211W
1878 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1879 "dropped: " MACSTR
" -> " MACSTR
1880 " (reason code %u)",
1881 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1882 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1883 #endif /* CONFIG_IEEE80211W */
1887 static void wnm_action_rx(struct wpa_supplicant
*wpa_s
, struct rx_action
*rx
)
1890 const u8
*pos
, *end
;
1892 if (rx
->data
== NULL
|| rx
->len
== 0)
1896 end
= pos
+ rx
->len
;
1899 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
1900 action
, MAC2STR(rx
->sa
));
1902 case WNM_BSS_TRANS_MGMT_REQ
:
1905 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management "
1906 "Request: dialog_token=%u request_mode=0x%x "
1907 "disassoc_timer=%u validity_interval=%u",
1908 pos
[0], pos
[1], WPA_GET_LE16(pos
+ 2), pos
[4]);
1912 pos
+= 12; /* BSS Termination Duration */
1915 if (pos
+ 1 > end
|| pos
+ 1 + pos
[0] > end
) {
1916 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS "
1917 "Transition Management Request "
1921 os_memcpy(url
, pos
+ 1, pos
[0]);
1923 wpa_msg(wpa_s
, MSG_INFO
, "WNM: ESS Disassociation "
1924 "Imminent - session_info_url=%s", url
);
1931 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1932 union wpa_event_data
*data
)
1934 struct wpa_supplicant
*wpa_s
= ctx
;
1935 u16 reason_code
= 0;
1937 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1938 event
!= EVENT_INTERFACE_ENABLED
&&
1939 event
!= EVENT_INTERFACE_STATUS
) {
1940 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1945 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1946 event
, wpa_s
->ifname
);
1950 sme_event_auth(wpa_s
, data
);
1953 wpa_supplicant_event_assoc(wpa_s
, data
);
1955 case EVENT_DISASSOC
:
1956 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1958 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1959 data
->disassoc_info
.reason_code
);
1960 if (data
->disassoc_info
.addr
)
1961 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1962 MAC2STR(data
->disassoc_info
.addr
));
1965 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1966 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1967 data
->disassoc_info
.addr
);
1970 #endif /* CONFIG_AP */
1972 reason_code
= data
->disassoc_info
.reason_code
;
1973 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1974 data
->disassoc_info
.ie
,
1975 data
->disassoc_info
.ie_len
);
1977 wpas_p2p_disassoc_notif(
1978 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1979 data
->disassoc_info
.ie
,
1980 data
->disassoc_info
.ie_len
);
1981 #endif /* CONFIG_P2P */
1983 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1984 sme_event_disassoc(wpa_s
, data
);
1987 if (event
== EVENT_DEAUTH
) {
1988 wpa_dbg(wpa_s
, MSG_DEBUG
,
1989 "Deauthentication notification");
1991 reason_code
= data
->deauth_info
.reason_code
;
1992 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1993 data
->deauth_info
.reason_code
);
1994 if (data
->deauth_info
.addr
) {
1995 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
1997 MAC2STR(data
->deauth_info
.
2000 wpa_hexdump(MSG_DEBUG
,
2001 "Deauthentication frame IE(s)",
2002 data
->deauth_info
.ie
,
2003 data
->deauth_info
.ie_len
);
2005 wpas_p2p_deauth_notif(
2006 wpa_s
, data
->deauth_info
.addr
,
2008 data
->deauth_info
.ie
,
2009 data
->deauth_info
.ie_len
);
2010 #endif /* CONFIG_P2P */
2014 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
2015 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2016 data
->deauth_info
.addr
);
2019 #endif /* CONFIG_AP */
2020 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
2022 case EVENT_MICHAEL_MIC_FAILURE
:
2023 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2025 #ifndef CONFIG_NO_SCAN_PROCESSING
2026 case EVENT_SCAN_RESULTS
:
2027 wpa_supplicant_event_scan_results(wpa_s
, data
);
2029 #endif /* CONFIG_NO_SCAN_PROCESSING */
2030 case EVENT_ASSOCINFO
:
2031 wpa_supplicant_event_associnfo(wpa_s
, data
);
2033 case EVENT_INTERFACE_STATUS
:
2034 wpa_supplicant_event_interface_status(wpa_s
, data
);
2036 case EVENT_PMKID_CANDIDATE
:
2037 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2039 #ifdef CONFIG_PEERKEY
2040 case EVENT_STKSTART
:
2041 wpa_supplicant_event_stkstart(wpa_s
, data
);
2043 #endif /* CONFIG_PEERKEY */
2046 wpa_supplicant_event_tdls(wpa_s
, data
);
2048 #endif /* CONFIG_TDLS */
2049 #ifdef CONFIG_IEEE80211R
2050 case EVENT_FT_RESPONSE
:
2051 wpa_supplicant_event_ft_response(wpa_s
, data
);
2053 #endif /* CONFIG_IEEE80211R */
2054 #ifdef CONFIG_IBSS_RSN
2055 case EVENT_IBSS_RSN_START
:
2056 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2058 #endif /* CONFIG_IBSS_RSN */
2059 case EVENT_ASSOC_REJECT
:
2060 if (data
->assoc_reject
.bssid
)
2061 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2062 "bssid=" MACSTR
" status_code=%u",
2063 MAC2STR(data
->assoc_reject
.bssid
),
2064 data
->assoc_reject
.status_code
);
2066 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2068 data
->assoc_reject
.status_code
);
2069 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2070 sme_event_assoc_reject(wpa_s
, data
);
2072 case EVENT_AUTH_TIMED_OUT
:
2073 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2074 sme_event_auth_timed_out(wpa_s
, data
);
2076 case EVENT_ASSOC_TIMED_OUT
:
2077 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2078 sme_event_assoc_timed_out(wpa_s
, data
);
2080 case EVENT_TX_STATUS
:
2081 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
2082 " type=%d stype=%d",
2083 MAC2STR(data
->tx_status
.dst
),
2084 data
->tx_status
.type
, data
->tx_status
.stype
);
2086 if (wpa_s
->ap_iface
== NULL
) {
2087 #ifdef CONFIG_OFFCHANNEL
2088 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2089 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
2090 offchannel_send_action_tx_status(
2091 wpa_s
, data
->tx_status
.dst
,
2092 data
->tx_status
.data
,
2093 data
->tx_status
.data_len
,
2094 data
->tx_status
.ack
?
2095 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2096 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2097 #endif /* CONFIG_OFFCHANNEL */
2100 #endif /* CONFIG_AP */
2101 #ifdef CONFIG_OFFCHANNEL
2102 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
2103 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
2105 * Catch TX status events for Action frames we sent via group
2106 * interface in GO mode.
2108 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2109 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
2110 os_memcmp(wpa_s
->parent
->pending_action_dst
,
2111 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
2112 offchannel_send_action_tx_status(
2113 wpa_s
->parent
, data
->tx_status
.dst
,
2114 data
->tx_status
.data
,
2115 data
->tx_status
.data_len
,
2116 data
->tx_status
.ack
?
2117 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2118 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2121 #endif /* CONFIG_OFFCHANNEL */
2123 switch (data
->tx_status
.type
) {
2124 case WLAN_FC_TYPE_MGMT
:
2125 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
2126 data
->tx_status
.data_len
,
2127 data
->tx_status
.stype
,
2128 data
->tx_status
.ack
);
2130 case WLAN_FC_TYPE_DATA
:
2131 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
2132 data
->tx_status
.data
,
2133 data
->tx_status
.data_len
,
2134 data
->tx_status
.ack
);
2137 #endif /* CONFIG_AP */
2140 case EVENT_DRIVER_CLIENT_POLL_OK
:
2141 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
2143 case EVENT_RX_FROM_UNKNOWN
:
2144 if (wpa_s
->ap_iface
== NULL
)
2146 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
2147 data
->rx_from_unknown
.wds
);
2150 if (wpa_s
->ap_iface
== NULL
) {
2153 const struct ieee80211_mgmt
*mgmt
;
2154 mgmt
= (const struct ieee80211_mgmt
*)
2155 data
->rx_mgmt
.frame
;
2156 fc
= le_to_host16(mgmt
->frame_control
);
2157 stype
= WLAN_FC_GET_STYPE(fc
);
2158 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2159 data
->rx_mgmt
.frame_len
> 24) {
2160 const u8
*src
= mgmt
->sa
;
2161 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2162 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2163 (mgmt
->u
.probe_req
.variable
-
2164 data
->rx_mgmt
.frame
);
2165 wpas_p2p_probe_req_rx(wpa_s
, src
, mgmt
->da
,
2166 mgmt
->bssid
, ie
, ie_len
);
2169 #endif /* CONFIG_P2P */
2170 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2171 "management frame in non-AP mode");
2174 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2176 #endif /* CONFIG_AP */
2177 case EVENT_RX_ACTION
:
2178 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2179 " Category=%u DataLen=%d freq=%d MHz",
2180 MAC2STR(data
->rx_action
.sa
),
2181 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2182 data
->rx_action
.freq
);
2183 #ifdef CONFIG_IEEE80211R
2184 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2185 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2186 data
->rx_action
.len
);
2189 #endif /* CONFIG_IEEE80211R */
2190 #ifdef CONFIG_IEEE80211W
2192 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2193 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2194 data
->rx_action
.data
,
2195 data
->rx_action
.len
);
2198 #endif /* CONFIG_SME */
2199 #endif /* CONFIG_IEEE80211W */
2201 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2202 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2203 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2204 data
->rx_action
.data
, data
->rx_action
.len
,
2205 data
->rx_action
.freq
) == 0)
2207 #endif /* CONFIG_GAS */
2208 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2209 wnm_action_rx(wpa_s
, &data
->rx_action
);
2213 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2215 data
->rx_action
.bssid
,
2216 data
->rx_action
.category
,
2217 data
->rx_action
.data
,
2218 data
->rx_action
.len
, data
->rx_action
.freq
);
2219 #endif /* CONFIG_P2P */
2221 case EVENT_RX_PROBE_REQ
:
2222 if (data
->rx_probe_req
.sa
== NULL
||
2223 data
->rx_probe_req
.ie
== NULL
)
2226 if (wpa_s
->ap_iface
) {
2227 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2228 data
->rx_probe_req
.sa
,
2229 data
->rx_probe_req
.da
,
2230 data
->rx_probe_req
.bssid
,
2231 data
->rx_probe_req
.ie
,
2232 data
->rx_probe_req
.ie_len
);
2235 #endif /* CONFIG_AP */
2237 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2238 data
->rx_probe_req
.da
,
2239 data
->rx_probe_req
.bssid
,
2240 data
->rx_probe_req
.ie
,
2241 data
->rx_probe_req
.ie_len
);
2242 #endif /* CONFIG_P2P */
2244 case EVENT_REMAIN_ON_CHANNEL
:
2245 #ifdef CONFIG_OFFCHANNEL
2246 offchannel_remain_on_channel_cb(
2247 wpa_s
, data
->remain_on_channel
.freq
,
2248 data
->remain_on_channel
.duration
);
2249 #endif /* CONFIG_OFFCHANNEL */
2251 wpas_p2p_remain_on_channel_cb(
2252 wpa_s
, data
->remain_on_channel
.freq
,
2253 data
->remain_on_channel
.duration
);
2254 #endif /* CONFIG_P2P */
2256 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2257 #ifdef CONFIG_OFFCHANNEL
2258 offchannel_cancel_remain_on_channel_cb(
2259 wpa_s
, data
->remain_on_channel
.freq
);
2260 #endif /* CONFIG_OFFCHANNEL */
2262 wpas_p2p_cancel_remain_on_channel_cb(
2263 wpa_s
, data
->remain_on_channel
.freq
);
2264 #endif /* CONFIG_P2P */
2267 case EVENT_P2P_DEV_FOUND
: {
2268 struct p2p_peer_info peer_info
;
2270 os_memset(&peer_info
, 0, sizeof(peer_info
));
2271 if (data
->p2p_dev_found
.dev_addr
)
2272 os_memcpy(peer_info
.p2p_device_addr
,
2273 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2274 if (data
->p2p_dev_found
.pri_dev_type
)
2275 os_memcpy(peer_info
.pri_dev_type
,
2276 data
->p2p_dev_found
.pri_dev_type
,
2277 sizeof(peer_info
.pri_dev_type
));
2278 if (data
->p2p_dev_found
.dev_name
)
2279 os_strlcpy(peer_info
.device_name
,
2280 data
->p2p_dev_found
.dev_name
,
2281 sizeof(peer_info
.device_name
));
2282 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2283 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2284 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2287 * FIX: new_device=1 is not necessarily correct. We should
2288 * maintain a P2P peer database in wpa_supplicant and update
2289 * this information based on whether the peer is truly new.
2291 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2294 case EVENT_P2P_GO_NEG_REQ_RX
:
2295 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2296 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2298 case EVENT_P2P_GO_NEG_COMPLETED
:
2299 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2301 case EVENT_P2P_PROV_DISC_REQUEST
:
2302 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2303 data
->p2p_prov_disc_req
.config_methods
,
2304 data
->p2p_prov_disc_req
.dev_addr
,
2305 data
->p2p_prov_disc_req
.pri_dev_type
,
2306 data
->p2p_prov_disc_req
.dev_name
,
2307 data
->p2p_prov_disc_req
.supp_config_methods
,
2308 data
->p2p_prov_disc_req
.dev_capab
,
2309 data
->p2p_prov_disc_req
.group_capab
);
2311 case EVENT_P2P_PROV_DISC_RESPONSE
:
2312 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2313 data
->p2p_prov_disc_resp
.config_methods
);
2315 case EVENT_P2P_SD_REQUEST
:
2316 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2317 data
->p2p_sd_req
.sa
,
2318 data
->p2p_sd_req
.dialog_token
,
2319 data
->p2p_sd_req
.update_indic
,
2320 data
->p2p_sd_req
.tlvs
,
2321 data
->p2p_sd_req
.tlvs_len
);
2323 case EVENT_P2P_SD_RESPONSE
:
2324 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2325 data
->p2p_sd_resp
.update_indic
,
2326 data
->p2p_sd_resp
.tlvs
,
2327 data
->p2p_sd_resp
.tlvs_len
);
2329 #endif /* CONFIG_P2P */
2330 case EVENT_EAPOL_RX
:
2331 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2332 data
->eapol_rx
.data
,
2333 data
->eapol_rx
.data_len
);
2335 case EVENT_SIGNAL_CHANGE
:
2336 bgscan_notify_signal_change(
2337 wpa_s
, data
->signal_change
.above_threshold
,
2338 data
->signal_change
.current_signal
,
2339 data
->signal_change
.current_noise
,
2340 data
->signal_change
.current_txrate
);
2342 case EVENT_INTERFACE_ENABLED
:
2343 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2344 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2346 if (!wpa_s
->ap_iface
) {
2347 wpa_supplicant_set_state(wpa_s
,
2349 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2351 wpa_supplicant_set_state(wpa_s
,
2353 #else /* CONFIG_AP */
2354 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2355 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2356 #endif /* CONFIG_AP */
2359 case EVENT_INTERFACE_DISABLED
:
2360 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2361 wpa_supplicant_mark_disassoc(wpa_s
);
2362 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2364 case EVENT_CHANNEL_LIST_CHANGED
:
2365 if (wpa_s
->drv_priv
== NULL
)
2366 break; /* Ignore event during drv initialization */
2368 wpas_p2p_update_channel_list(wpa_s
);
2369 #endif /* CONFIG_P2P */
2371 case EVENT_INTERFACE_UNAVAILABLE
:
2373 wpas_p2p_interface_unavailable(wpa_s
);
2374 #endif /* CONFIG_P2P */
2376 case EVENT_BEST_CHANNEL
:
2377 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2379 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2380 data
->best_chan
.freq_overall
);
2381 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2382 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2383 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2385 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2386 data
->best_chan
.freq_5
,
2387 data
->best_chan
.freq_overall
);
2388 #endif /* CONFIG_P2P */
2390 case EVENT_UNPROT_DEAUTH
:
2391 wpa_supplicant_event_unprot_deauth(wpa_s
,
2392 &data
->unprot_deauth
);
2394 case EVENT_UNPROT_DISASSOC
:
2395 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2396 &data
->unprot_disassoc
);
2398 case EVENT_STATION_LOW_ACK
:
2400 if (wpa_s
->ap_iface
&& data
)
2401 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2402 data
->low_ack
.addr
);
2403 #endif /* CONFIG_AP */
2405 case EVENT_IBSS_PEER_LOST
:
2406 #ifdef CONFIG_IBSS_RSN
2407 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2408 #endif /* CONFIG_IBSS_RSN */
2410 case EVENT_DRIVER_GTK_REKEY
:
2411 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2412 wpa_s
->bssid
, ETH_ALEN
))
2416 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2417 data
->driver_gtk_rekey
.replay_ctr
);
2419 case EVENT_SCHED_SCAN_STOPPED
:
2420 wpa_s
->sched_scanning
= 0;
2421 wpa_supplicant_notify_scanning(wpa_s
, 0);
2424 * If we timed out, start a new sched scan to continue
2425 * searching for more SSIDs.
2427 if (wpa_s
->sched_scan_timed_out
)
2428 wpa_supplicant_req_sched_scan(wpa_s
);
2430 case EVENT_WPS_BUTTON_PUSHED
:
2432 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
2433 #endif /* CONFIG_WPS */
2436 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);