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 (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
75 size_t wpa_ie_len
= sizeof(wpa_ie
);
76 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
79 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
82 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
83 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
84 old_ssid
= wpa_s
->current_ssid
;
85 wpa_s
->current_ssid
= ssid
;
86 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
87 wpa_supplicant_initiate_eapol(wpa_s
);
88 if (old_ssid
!= wpa_s
->current_ssid
)
89 wpas_notify_network_changed(wpa_s
);
95 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
97 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
99 if (wpa_s
->countermeasures
) {
100 wpa_s
->countermeasures
= 0;
101 wpa_drv_set_countermeasures(wpa_s
, 0);
102 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
103 wpa_supplicant_req_scan(wpa_s
, 0, 0);
108 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
112 #ifdef CONFIG_IBSS_RSN
113 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
114 wpa_s
->ibss_rsn
= NULL
;
115 #endif /* CONFIG_IBSS_RSN */
118 wpa_supplicant_ap_deinit(wpa_s
);
119 #endif /* CONFIG_AP */
121 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
124 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
125 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
126 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
127 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
128 wpa_s
->current_bss
= NULL
;
129 wpa_s
->assoc_freq
= 0;
130 #ifdef CONFIG_IEEE80211R
132 if (wpa_s
->sme
.ft_ies
)
133 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
134 #endif /* CONFIG_SME */
135 #endif /* CONFIG_IEEE80211R */
138 wpas_notify_bssid_changed(wpa_s
);
140 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
141 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
142 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
143 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
144 wpa_s
->ap_ies_from_associnfo
= 0;
148 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
150 struct wpa_ie_data ie
;
154 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
158 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
159 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
160 ie
.pmkid
+ i
* PMKID_LEN
,
162 if (pmksa_set
== 0) {
163 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
168 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
169 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
173 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
174 union wpa_event_data
*data
)
177 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
181 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
182 " index=%d preauth=%d",
183 MAC2STR(data
->pmkid_candidate
.bssid
),
184 data
->pmkid_candidate
.index
,
185 data
->pmkid_candidate
.preauth
);
187 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
188 data
->pmkid_candidate
.index
,
189 data
->pmkid_candidate
.preauth
);
193 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
195 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
196 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
199 #ifdef IEEE8021X_EAPOL
200 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
201 wpa_s
->current_ssid
&&
202 !(wpa_s
->current_ssid
->eapol_flags
&
203 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
204 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
205 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
206 * plaintext or static WEP keys). */
209 #endif /* IEEE8021X_EAPOL */
216 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
217 * @wpa_s: pointer to wpa_supplicant data
218 * @ssid: Configuration data for the network
219 * Returns: 0 on success, -1 on failure
221 * This function is called when starting authentication with a network that is
222 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
224 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
225 struct wpa_ssid
*ssid
)
227 #ifdef IEEE8021X_EAPOL
229 int aka
= 0, sim
= 0, type
;
231 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
234 if (ssid
->eap
.eap_methods
== NULL
) {
238 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
239 while (eap
->vendor
!= EAP_VENDOR_IETF
||
240 eap
->method
!= EAP_TYPE_NONE
) {
241 if (eap
->vendor
== EAP_VENDOR_IETF
) {
242 if (eap
->method
== EAP_TYPE_SIM
)
244 else if (eap
->method
== EAP_TYPE_AKA
)
251 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
253 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
257 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
258 "use SIM, but neither EAP-SIM nor EAP-AKA are "
263 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
264 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
266 type
= SCARD_TRY_BOTH
;
268 type
= SCARD_USIM_ONLY
;
270 type
= SCARD_GSM_SIM_ONLY
;
272 wpa_s
->scard
= scard_init(type
);
273 if (wpa_s
->scard
== NULL
) {
274 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
278 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
279 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
280 #endif /* PCSC_FUNCS */
281 #endif /* IEEE8021X_EAPOL */
287 #ifndef CONFIG_NO_SCAN_PROCESSING
288 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
289 struct wpa_ssid
*ssid
)
293 if (ssid
->mixed_cell
)
297 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
299 #endif /* CONFIG_WPS */
301 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
302 if (ssid
->wep_key_len
[i
]) {
307 #ifdef IEEE8021X_EAPOL
308 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
309 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
310 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
312 #endif /* IEEE8021X_EAPOL */
314 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
317 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
323 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
324 struct wpa_ssid
*ssid
,
325 struct wpa_scan_res
*bss
)
327 struct wpa_ie_data ie
;
329 const u8
*rsn_ie
, *wpa_ie
;
333 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
337 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
338 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
339 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
340 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
341 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
343 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
344 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
347 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
348 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
354 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
356 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
361 if (!(ie
.proto
& ssid
->proto
)) {
362 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
367 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
368 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
373 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
374 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
379 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
380 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
385 #ifdef CONFIG_IEEE80211W
386 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
387 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
388 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
392 #endif /* CONFIG_IEEE80211W */
394 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
398 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
399 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
402 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
403 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
409 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
411 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
416 if (!(ie
.proto
& ssid
->proto
)) {
417 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
422 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
423 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
428 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
429 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
434 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
435 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
440 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
444 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
445 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
446 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
450 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
451 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
455 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
462 static int freq_allowed(int *freqs
, int freq
)
469 for (i
= 0; freqs
[i
]; i
++)
470 if (freqs
[i
] == freq
)
476 static int ht_supported(const struct hostapd_hw_modes
*mode
)
478 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
480 * The driver did not indicate whether it supports HT. Assume
481 * it does to avoid connection issues.
487 * IEEE Std 802.11n-2009 20.1.1:
488 * An HT non-AP STA shall support all EQM rates for one spatial stream.
490 return mode
->mcs_set
[0] == 0xff;
494 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_scan_res
*bss
)
496 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
497 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
502 return 1; /* Cannot do matching without knowing band */
504 modes
= wpa_s
->hw
.modes
;
507 * The driver does not provide any additional information
508 * about the utilized hardware, so allow the connection attempt
514 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
515 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
516 int freq
= modes
[i
].channels
[j
].freq
;
517 if (freq
== bss
->freq
) {
519 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
520 break; /* do not allow 802.11b replace
531 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
532 rate_ie
= wpa_scan_get_ie(bss
, scan_ie
[i
]);
536 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
537 int flagged
= !!(rate_ie
[j
] & 0x80);
538 int r
= (rate_ie
[j
] & 0x7f) * 5;
541 * IEEE Std 802.11n-2009 7.3.2.2:
542 * The new BSS Membership selector value is encoded
543 * like a legacy basic rate, but it is not a rate and
544 * only indicates if the BSS members are required to
545 * support the mandatory features of Clause 20 [HT PHY]
546 * in order to join the BSS.
548 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
549 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
550 if (!ht_supported(mode
)) {
551 wpa_dbg(wpa_s
, MSG_DEBUG
,
552 " hardware does not support "
562 /* check for legacy basic rates */
563 for (k
= 0; k
< mode
->num_rates
; k
++) {
564 if (mode
->rates
[k
] == r
)
567 if (k
== mode
->num_rates
) {
569 * IEEE Std 802.11-2007 7.3.2.2 demands that in
570 * order to join a BSS all required rates
571 * have to be supported by the hardware.
573 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
574 "not support required rate %d.%d Mbps",
585 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
586 int i
, struct wpa_scan_res
*bss
,
587 struct wpa_ssid
*group
)
590 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
592 struct wpa_blacklist
*e
;
594 struct wpa_ssid
*ssid
;
596 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
597 ssid_
= ie
? ie
+ 2 : (u8
*) "";
598 ssid_len
= ie
? ie
[1] : 0;
600 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
601 wpa_ie_len
= ie
? ie
[1] : 0;
603 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
604 rsn_ie_len
= ie
? ie
[1] : 0;
606 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
607 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
608 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
609 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
610 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
612 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
615 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
617 * When only a single network is enabled, we can
618 * trigger blacklisting on the first failure. This
619 * should not be done with multiple enabled networks to
620 * avoid getting forced to move into a worse ESS on
621 * single error if there are no other BSSes of the
626 if (e
->count
> limit
) {
627 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
628 "(count=%d limit=%d)", e
->count
, limit
);
634 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
638 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
640 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
641 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
643 if (ssid
->disabled
) {
644 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
649 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
650 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
655 if (wpa
&& ssid
->ssid_len
== 0 &&
656 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
659 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
660 /* Only allow wildcard SSID match if an AP
661 * advertises active WPS operation that matches
664 if (ssid
->ssid_len
== 0 &&
665 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
668 #endif /* CONFIG_WPS */
670 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
671 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
675 (ssid_len
!= ssid
->ssid_len
||
676 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
677 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
681 if (ssid
->bssid_set
&&
682 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
683 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
687 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
691 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
692 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
693 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
694 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
699 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
700 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
705 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
706 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
711 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
712 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
717 if (!rate_match(wpa_s
, bss
)) {
718 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
725 * TODO: skip the AP if its P2P IE has Group Formation
726 * bit set in the P2P Group Capability Bitmap and we
727 * are not in Group Formation with that device.
729 #endif /* CONFIG_P2P */
731 /* Matching configuration found */
735 /* No matching configuration found */
740 static struct wpa_bss
*
741 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
742 struct wpa_scan_results
*scan_res
,
743 struct wpa_ssid
*group
,
744 struct wpa_ssid
**selected_ssid
)
748 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
751 for (i
= 0; i
< scan_res
->num
; i
++) {
752 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
756 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
760 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
761 ssid
= ie
? ie
+ 2 : (u8
*) "";
762 ssid_len
= ie
? ie
[1] : 0;
764 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
766 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
767 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
774 static struct wpa_bss
*
775 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
776 struct wpa_scan_results
*scan_res
,
777 struct wpa_ssid
**selected_ssid
)
779 struct wpa_bss
*selected
= NULL
;
782 while (selected
== NULL
) {
783 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
784 selected
= wpa_supplicant_select_bss(
785 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
791 if (selected
== NULL
&& wpa_s
->blacklist
) {
792 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
793 "blacklist and try again");
794 wpa_blacklist_clear(wpa_s
);
795 wpa_s
->blacklist_cleared
++;
796 } else if (selected
== NULL
)
804 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
805 int timeout_sec
, int timeout_usec
)
807 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
809 * No networks are enabled; short-circuit request so
810 * we don't wait timeout seconds before transitioning
813 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
816 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
820 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
821 struct wpa_bss
*selected
,
822 struct wpa_ssid
*ssid
)
824 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
825 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
826 "PBC session overlap");
828 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
830 #endif /* CONFIG_P2P */
833 wpas_wps_cancel(wpa_s
);
834 #endif /* CONFIG_WPS */
839 * Do not trigger new association unless the BSSID has changed or if
840 * reassociation is requested. If we are in process of associating with
841 * the selected BSSID, do not trigger new attempt.
843 if (wpa_s
->reassociate
||
844 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
845 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
846 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
847 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
849 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
850 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
853 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
854 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
855 " pending: " MACSTR
" wpa_state: %s",
856 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
857 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
858 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
859 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
861 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);
1009 if (wpa_s
->p2p_cb_on_scan_complete
&& !wpa_s
->global
->p2p_disabled
&&
1010 wpa_s
->global
->p2p
!= NULL
) {
1011 wpa_s
->p2p_cb_on_scan_complete
= 0;
1012 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
1013 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
1014 "stopped scan processing");
1018 #endif /* CONFIG_P2P */
1020 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1021 data
? &data
->scan_info
:
1023 if (scan_res
== NULL
) {
1024 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
1026 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1028 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1032 #ifndef CONFIG_NO_RANDOM_POOL
1034 num
= scan_res
->num
;
1037 for (i
= 0; i
< num
; i
++) {
1039 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1040 buf
[0] = res
->bssid
[5];
1041 buf
[1] = res
->qual
& 0xff;
1042 buf
[2] = res
->noise
& 0xff;
1043 buf
[3] = res
->level
& 0xff;
1044 buf
[4] = res
->tsf
& 0xff;
1045 random_add_randomness(buf
, sizeof(buf
));
1047 #endif /* CONFIG_NO_RANDOM_POOL */
1049 if (wpa_s
->scan_res_handler
) {
1050 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1051 struct wpa_scan_results
*scan_res
);
1053 scan_res_handler
= wpa_s
->scan_res_handler
;
1054 wpa_s
->scan_res_handler
= NULL
;
1055 scan_res_handler(wpa_s
, scan_res
);
1057 wpa_scan_results_free(scan_res
);
1062 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1064 if (wpa_s
->ap_iface
->scan_cb
)
1065 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1066 #endif /* CONFIG_AP */
1067 wpa_scan_results_free(scan_res
);
1071 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
1072 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1073 wpas_notify_scan_results(wpa_s
);
1075 wpas_notify_scan_done(wpa_s
, 1);
1077 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
1078 wpa_scan_results_free(scan_res
);
1082 if (wpa_s
->disconnected
) {
1083 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1084 wpa_scan_results_free(scan_res
);
1088 if (!wpas_driver_bss_selection(wpa_s
) &&
1089 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
1090 wpa_scan_results_free(scan_res
);
1094 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
1098 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
1100 wpa_scan_results_free(scan_res
);
1102 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1106 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1107 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1110 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1112 wpa_scan_results_free(scan_res
);
1113 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1114 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1116 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1117 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1118 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1120 int timeout_sec
= wpa_s
->scan_interval
;
1121 int timeout_usec
= 0;
1123 if (wpa_s
->p2p_in_provisioning
) {
1125 * Use shorter wait during P2P Provisioning
1126 * state to speed up group formation.
1129 timeout_usec
= 250000;
1130 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1134 #endif /* CONFIG_P2P */
1135 if (wpa_supplicant_req_sched_scan(wpa_s
))
1136 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1144 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1145 union wpa_event_data
*data
)
1147 const char *rn
, *rn2
;
1148 struct wpa_supplicant
*ifs
;
1150 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1152 * If no scan results could be fetched, then no need to
1153 * notify those interfaces that did not actually request
1160 * Check other interfaces to see if they have the same radio-name. If
1161 * so, they get updated with this same scan info.
1163 if (!wpa_s
->driver
->get_radio_name
)
1166 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1167 if (rn
== NULL
|| rn
[0] == '\0')
1170 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1171 "sharing same radio (%s) in event_scan_results", rn
);
1173 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1174 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1177 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1178 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1179 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1180 "sibling", ifs
->ifname
);
1181 _wpa_supplicant_event_scan_results(ifs
, data
);
1186 #endif /* CONFIG_NO_SCAN_PROCESSING */
1189 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1190 union wpa_event_data
*data
)
1192 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1195 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1196 if (data
->assoc_info
.req_ies
)
1197 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1198 data
->assoc_info
.req_ies_len
);
1199 if (data
->assoc_info
.resp_ies
) {
1200 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1201 data
->assoc_info
.resp_ies_len
);
1203 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1204 data
->assoc_info
.resp_ies_len
);
1205 #endif /* CONFIG_TDLS */
1207 if (data
->assoc_info
.beacon_ies
)
1208 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1209 data
->assoc_info
.beacon_ies
,
1210 data
->assoc_info
.beacon_ies_len
);
1211 if (data
->assoc_info
.freq
)
1212 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1213 data
->assoc_info
.freq
);
1215 p
= data
->assoc_info
.req_ies
;
1216 l
= data
->assoc_info
.req_ies_len
;
1218 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1219 while (p
&& l
>= 2) {
1222 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1226 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1227 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1228 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1229 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1232 wpa_find_assoc_pmkid(wpa_s
);
1238 if (!found
&& data
->assoc_info
.req_ies
)
1239 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1241 #ifdef CONFIG_IEEE80211R
1243 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1245 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1246 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1247 data
->assoc_info
.resp_ies
,
1248 data
->assoc_info
.resp_ies_len
,
1250 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1251 "Reassociation Response failed");
1252 wpa_supplicant_deauthenticate(
1253 wpa_s
, WLAN_REASON_INVALID_IE
);
1258 p
= data
->assoc_info
.resp_ies
;
1259 l
= data
->assoc_info
.resp_ies_len
;
1261 #ifdef CONFIG_WPS_STRICT
1262 if (p
&& wpa_s
->current_ssid
&&
1263 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1265 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1267 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1268 "include WPS IE in (Re)Association Response");
1272 if (wps_validate_assoc_resp(wps
) < 0) {
1274 wpa_supplicant_deauthenticate(
1275 wpa_s
, WLAN_REASON_INVALID_IE
);
1280 #endif /* CONFIG_WPS_STRICT */
1282 /* Go through the IEs and make a copy of the MDIE, if present. */
1283 while (p
&& l
>= 2) {
1286 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1290 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1291 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1292 wpa_s
->sme
.ft_used
= 1;
1293 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1294 MOBILITY_DOMAIN_ID_LEN
);
1300 #endif /* CONFIG_SME */
1302 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1303 data
->assoc_info
.resp_ies_len
);
1304 #endif /* CONFIG_IEEE80211R */
1306 /* WPA/RSN IE from Beacon/ProbeResp */
1307 p
= data
->assoc_info
.beacon_ies
;
1308 l
= data
->assoc_info
.beacon_ies_len
;
1310 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1312 wpa_found
= rsn_found
= 0;
1313 while (p
&& l
>= 2) {
1316 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1321 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1322 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1324 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1328 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1330 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1337 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1338 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1339 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1340 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1341 if (wpa_found
|| rsn_found
)
1342 wpa_s
->ap_ies_from_associnfo
= 1;
1344 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1345 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1346 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1348 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1349 wpa_supplicant_update_scan_results(wpa_s
);
1352 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1358 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1359 union wpa_event_data
*data
)
1364 struct wpa_driver_capa capa
;
1367 if (wpa_s
->ap_iface
) {
1368 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1369 data
->assoc_info
.addr
,
1370 data
->assoc_info
.req_ies
,
1371 data
->assoc_info
.req_ies_len
,
1372 data
->assoc_info
.reassoc
);
1375 #endif /* CONFIG_AP */
1377 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1378 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1381 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1382 if (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1383 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1384 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1385 MACSTR
, MAC2STR(bssid
));
1386 random_add_randomness(bssid
, ETH_ALEN
);
1387 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1388 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1389 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1391 wpas_notify_bssid_changed(wpa_s
);
1393 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1394 wpa_clear_keys(wpa_s
, bssid
);
1396 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1397 wpa_supplicant_disassociate(
1398 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1401 if (wpa_s
->current_ssid
) {
1402 struct wpa_bss
*bss
= NULL
;
1403 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1404 if (ssid
->ssid_len
> 0)
1405 bss
= wpa_bss_get(wpa_s
, bssid
,
1406 ssid
->ssid
, ssid
->ssid_len
);
1408 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1410 wpa_s
->current_bss
= bss
;
1415 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1416 wpa_s
->sme
.prev_bssid_set
= 1;
1417 #endif /* CONFIG_SME */
1419 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1420 if (wpa_s
->current_ssid
) {
1421 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1422 * initialized before association, but for other modes,
1423 * initialize PC/SC here, if the current configuration needs
1424 * smartcard or SIM/USIM. */
1425 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1427 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1429 l2_packet_notify_auth_start(wpa_s
->l2
);
1432 * Set portEnabled first to FALSE in order to get EAP state machine out
1433 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1434 * state machine may transit to AUTHENTICATING state based on obsolete
1435 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1436 * AUTHENTICATED without ever giving chance to EAP state machine to
1439 if (!ft_completed
) {
1440 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1441 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1443 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1444 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1445 /* 802.1X::portControl = Auto */
1446 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1447 wpa_s
->eapol_received
= 0;
1448 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1449 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1450 (wpa_s
->current_ssid
&&
1451 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1452 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1453 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1454 } else if (!ft_completed
) {
1455 /* Timeout for receiving the first EAPOL packet */
1456 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1458 wpa_supplicant_cancel_scan(wpa_s
);
1460 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1461 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1463 * We are done; the driver will take care of RSN 4-way
1466 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1467 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1468 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1469 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1470 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1471 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1473 * The driver will take care of RSN 4-way handshake, so we need
1474 * to allow EAPOL supplicant to complete its work without
1475 * waiting for WPA supplicant.
1477 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1478 } else if (ft_completed
) {
1480 * FT protocol completed - make sure EAPOL state machine ends
1481 * up in authenticated.
1483 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1484 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1485 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1486 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1489 if (wpa_s
->pending_eapol_rx
) {
1490 struct os_time now
, age
;
1492 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1493 if (age
.sec
== 0 && age
.usec
< 100000 &&
1494 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1496 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1497 "frame that was received just before "
1498 "association notification");
1499 wpa_supplicant_rx_eapol(
1500 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1501 wpabuf_head(wpa_s
->pending_eapol_rx
),
1502 wpabuf_len(wpa_s
->pending_eapol_rx
));
1504 wpabuf_free(wpa_s
->pending_eapol_rx
);
1505 wpa_s
->pending_eapol_rx
= NULL
;
1508 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1509 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1510 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1511 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1512 /* Set static WEP keys again */
1513 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1516 #ifdef CONFIG_IBSS_RSN
1517 if (wpa_s
->current_ssid
&&
1518 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1519 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1520 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1521 wpa_s
->ibss_rsn
== NULL
) {
1522 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1523 if (!wpa_s
->ibss_rsn
) {
1524 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1525 wpa_supplicant_deauthenticate(
1526 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1530 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1532 #endif /* CONFIG_IBSS_RSN */
1536 static int disconnect_reason_recoverable(u16 reason_code
)
1538 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
1539 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
1540 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
1544 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1549 u8 prev_pending_bssid
[ETH_ALEN
];
1550 struct wpa_bss
*fast_reconnect
= NULL
;
1551 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
1553 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1554 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1556 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1558 * At least Host AP driver and a Prism3 card seemed to be
1559 * generating streams of disconnected events when configuring
1560 * IBSS for WPA-None. Ignore them for now.
1562 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1563 "IBSS/WPA-None mode");
1567 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1568 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1569 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1570 "pre-shared key may be incorrect");
1572 if (!wpa_s
->auto_reconnect_disabled
||
1573 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1574 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
1575 "reconnect (wps=%d wpa_state=%d)",
1576 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
1578 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
1579 wpa_s
->current_ssid
&&
1580 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
1581 disconnect_reason_recoverable(reason_code
)) {
1583 * It looks like the AP has dropped association with
1584 * us, but could allow us to get back in. Try to
1585 * reconnect to the same BSS without full scan to save
1586 * time for some common cases.
1588 fast_reconnect
= wpa_s
->current_bss
;
1589 fast_reconnect_ssid
= wpa_s
->current_ssid
;
1590 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1591 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1593 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
1596 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
1597 "try to re-connect");
1598 wpa_s
->reassociate
= 0;
1599 wpa_s
->disconnected
= 1;
1601 bssid
= wpa_s
->bssid
;
1602 if (is_zero_ether_addr(bssid
))
1603 bssid
= wpa_s
->pending_bssid
;
1604 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
1605 wpas_connection_failed(wpa_s
, bssid
);
1606 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1607 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1609 MAC2STR(bssid
), reason_code
);
1610 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1611 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1612 wpa_s
->keys_cleared
= 0;
1613 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1615 wpa_supplicant_mark_disassoc(wpa_s
);
1617 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1618 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1620 if (fast_reconnect
) {
1621 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
1622 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
1623 fast_reconnect_ssid
) < 0) {
1624 /* Recover through full scan */
1625 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1631 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1632 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
1634 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1636 if (!wpa_s
->pending_mic_error_report
)
1639 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1640 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1641 wpa_s
->pending_mic_error_report
= 0;
1643 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1647 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1648 union wpa_event_data
*data
)
1653 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1654 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1656 if ((wpa_s
->last_michael_mic_error
&&
1657 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1658 wpa_s
->pending_mic_error_report
) {
1659 if (wpa_s
->pending_mic_error_report
) {
1661 * Send the pending MIC error report immediately since
1662 * we are going to start countermeasures and AP better
1665 wpa_sm_key_request(wpa_s
->wpa
, 1,
1666 wpa_s
->pending_mic_error_pairwise
);
1669 /* Send the new MIC error report immediately since we are going
1670 * to start countermeasures and AP better do the same.
1672 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1674 /* initialize countermeasures */
1675 wpa_s
->countermeasures
= 1;
1676 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1679 * Need to wait for completion of request frame. We do not get
1680 * any callback for the message completion, so just wait a
1681 * short while and hope for the best. */
1684 wpa_drv_set_countermeasures(wpa_s
, 1);
1685 wpa_supplicant_deauthenticate(wpa_s
,
1686 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1687 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1689 eloop_register_timeout(60, 0,
1690 wpa_supplicant_stop_countermeasures
,
1692 /* TODO: mark the AP rejected for 60 second. STA is
1693 * allowed to associate with another AP.. */
1695 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1696 if (wpa_s
->mic_errors_seen
) {
1698 * Reduce the effectiveness of Michael MIC error
1699 * reports as a means for attacking against TKIP if
1700 * more than one MIC failure is noticed with the same
1701 * PTK. We delay the transmission of the reports by a
1702 * random time between 0 and 60 seconds in order to
1703 * force the attacker wait 60 seconds before getting
1704 * the information on whether a frame resulted in a MIC
1710 if (os_get_random(rval
, sizeof(rval
)) < 0)
1711 sec
= os_random() % 60;
1713 sec
= WPA_GET_BE32(rval
) % 60;
1714 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1715 "report %d seconds", sec
);
1716 wpa_s
->pending_mic_error_report
= 1;
1717 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1718 eloop_cancel_timeout(
1719 wpa_supplicant_delayed_mic_error_report
,
1721 eloop_register_timeout(
1722 sec
, os_random() % 1000000,
1723 wpa_supplicant_delayed_mic_error_report
,
1726 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1728 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1729 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1730 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1732 wpa_s
->last_michael_mic_error
= t
.sec
;
1733 wpa_s
->mic_errors_seen
++;
1737 #ifdef CONFIG_TERMINATE_ONLASTIF
1738 static int any_interfaces(struct wpa_supplicant
*head
)
1740 struct wpa_supplicant
*wpa_s
;
1742 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1743 if (!wpa_s
->interface_removed
)
1747 #endif /* CONFIG_TERMINATE_ONLASTIF */
1751 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1752 union wpa_event_data
*data
)
1754 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1757 switch (data
->interface_status
.ievent
) {
1758 case EVENT_INTERFACE_ADDED
:
1759 if (!wpa_s
->interface_removed
)
1761 wpa_s
->interface_removed
= 0;
1762 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1763 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1764 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1765 "driver after interface was added");
1768 case EVENT_INTERFACE_REMOVED
:
1769 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1770 wpa_s
->interface_removed
= 1;
1771 wpa_supplicant_mark_disassoc(wpa_s
);
1772 l2_packet_deinit(wpa_s
->l2
);
1774 #ifdef CONFIG_IBSS_RSN
1775 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1776 wpa_s
->ibss_rsn
= NULL
;
1777 #endif /* CONFIG_IBSS_RSN */
1778 #ifdef CONFIG_TERMINATE_ONLASTIF
1779 /* check if last interface */
1780 if (!any_interfaces(wpa_s
->global
->ifaces
))
1782 #endif /* CONFIG_TERMINATE_ONLASTIF */
1788 #ifdef CONFIG_PEERKEY
1790 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1791 union wpa_event_data
*data
)
1795 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1797 #endif /* CONFIG_PEERKEY */
1801 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1802 union wpa_event_data
*data
)
1806 switch (data
->tdls
.oper
) {
1807 case TDLS_REQUEST_SETUP
:
1808 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1810 case TDLS_REQUEST_TEARDOWN
:
1811 wpa_tdls_send_teardown(wpa_s
->wpa
, data
->tdls
.peer
,
1812 data
->tdls
.reason_code
);
1816 #endif /* CONFIG_TDLS */
1819 #ifdef CONFIG_IEEE80211R
1821 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1822 union wpa_event_data
*data
)
1827 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1828 data
->ft_ies
.ies_len
,
1829 data
->ft_ies
.ft_action
,
1830 data
->ft_ies
.target_ap
,
1831 data
->ft_ies
.ric_ies
,
1832 data
->ft_ies
.ric_ies_len
) < 0) {
1833 /* TODO: prevent MLME/driver from trying to associate? */
1836 #endif /* CONFIG_IEEE80211R */
1839 #ifdef CONFIG_IBSS_RSN
1840 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1841 union wpa_event_data
*data
)
1843 struct wpa_ssid
*ssid
;
1844 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1848 ssid
= wpa_s
->current_ssid
;
1851 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1854 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1856 #endif /* CONFIG_IBSS_RSN */
1859 #ifdef CONFIG_IEEE80211R
1860 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1863 const u8
*sta_addr
, *target_ap_addr
;
1866 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1867 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1868 return; /* only SME case supported for now */
1869 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1872 return; /* Only FT Action Response is supported for now */
1873 sta_addr
= data
+ 1;
1874 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1875 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1876 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1877 MACSTR
" TargetAP " MACSTR
" status %u",
1878 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1880 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1881 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1882 " in FT Action Response", MAC2STR(sta_addr
));
1887 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1888 "failure (status code %d)", status
);
1889 /* TODO: report error to FT code(?) */
1893 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1894 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1895 target_ap_addr
, NULL
, 0) < 0)
1900 struct wpa_bss
*bss
;
1901 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1903 wpa_s
->sme
.freq
= bss
->freq
;
1904 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1905 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1908 #endif /* CONFIG_SME */
1910 #endif /* CONFIG_IEEE80211R */
1913 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1914 struct unprot_deauth
*e
)
1916 #ifdef CONFIG_IEEE80211W
1917 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1918 "dropped: " MACSTR
" -> " MACSTR
1919 " (reason code %u)",
1920 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1921 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1922 #endif /* CONFIG_IEEE80211W */
1926 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1927 struct unprot_disassoc
*e
)
1929 #ifdef CONFIG_IEEE80211W
1930 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1931 "dropped: " MACSTR
" -> " MACSTR
1932 " (reason code %u)",
1933 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1934 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1935 #endif /* CONFIG_IEEE80211W */
1939 static void wnm_action_rx(struct wpa_supplicant
*wpa_s
, struct rx_action
*rx
)
1942 const u8
*pos
, *end
;
1944 if (rx
->data
== NULL
|| rx
->len
== 0)
1948 end
= pos
+ rx
->len
;
1951 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
1952 action
, MAC2STR(rx
->sa
));
1954 case WNM_BSS_TRANS_MGMT_REQ
:
1957 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management "
1958 "Request: dialog_token=%u request_mode=0x%x "
1959 "disassoc_timer=%u validity_interval=%u",
1960 pos
[0], pos
[1], WPA_GET_LE16(pos
+ 2), pos
[4]);
1964 pos
+= 12; /* BSS Termination Duration */
1967 if (pos
+ 1 > end
|| pos
+ 1 + pos
[0] > end
) {
1968 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS "
1969 "Transition Management Request "
1973 os_memcpy(url
, pos
+ 1, pos
[0]);
1975 wpa_msg(wpa_s
, MSG_INFO
, "WNM: ESS Disassociation "
1976 "Imminent - session_info_url=%s", url
);
1983 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1984 union wpa_event_data
*data
)
1986 struct wpa_supplicant
*wpa_s
= ctx
;
1987 u16 reason_code
= 0;
1989 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1990 event
!= EVENT_INTERFACE_ENABLED
&&
1991 event
!= EVENT_INTERFACE_STATUS
) {
1992 wpa_dbg(wpa_s
, MSG_DEBUG
,
1993 "Ignore event %s (%d) while interface is disabled",
1994 event_to_string(event
), event
);
1998 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %s (%d) received",
1999 event_to_string(event
), event
);
2003 sme_event_auth(wpa_s
, data
);
2006 wpa_supplicant_event_assoc(wpa_s
, data
);
2008 case EVENT_DISASSOC
:
2009 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
2011 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
2012 data
->disassoc_info
.reason_code
);
2013 if (data
->disassoc_info
.addr
)
2014 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
2015 MAC2STR(data
->disassoc_info
.addr
));
2018 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
2019 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2020 data
->disassoc_info
.addr
);
2023 #endif /* CONFIG_AP */
2025 reason_code
= data
->disassoc_info
.reason_code
;
2026 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
2027 data
->disassoc_info
.ie
,
2028 data
->disassoc_info
.ie_len
);
2030 wpas_p2p_disassoc_notif(
2031 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
2032 data
->disassoc_info
.ie
,
2033 data
->disassoc_info
.ie_len
);
2034 #endif /* CONFIG_P2P */
2036 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2037 sme_event_disassoc(wpa_s
, data
);
2040 if (event
== EVENT_DEAUTH
) {
2041 wpa_dbg(wpa_s
, MSG_DEBUG
,
2042 "Deauthentication notification");
2044 reason_code
= data
->deauth_info
.reason_code
;
2045 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
2046 data
->deauth_info
.reason_code
);
2047 if (data
->deauth_info
.addr
) {
2048 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
2050 MAC2STR(data
->deauth_info
.
2053 wpa_hexdump(MSG_DEBUG
,
2054 "Deauthentication frame IE(s)",
2055 data
->deauth_info
.ie
,
2056 data
->deauth_info
.ie_len
);
2058 wpas_p2p_deauth_notif(
2059 wpa_s
, data
->deauth_info
.addr
,
2061 data
->deauth_info
.ie
,
2062 data
->deauth_info
.ie_len
);
2063 #endif /* CONFIG_P2P */
2067 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
2068 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2069 data
->deauth_info
.addr
);
2072 #endif /* CONFIG_AP */
2073 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
2075 case EVENT_MICHAEL_MIC_FAILURE
:
2076 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2078 #ifndef CONFIG_NO_SCAN_PROCESSING
2079 case EVENT_SCAN_RESULTS
:
2080 wpa_supplicant_event_scan_results(wpa_s
, data
);
2082 #endif /* CONFIG_NO_SCAN_PROCESSING */
2083 case EVENT_ASSOCINFO
:
2084 wpa_supplicant_event_associnfo(wpa_s
, data
);
2086 case EVENT_INTERFACE_STATUS
:
2087 wpa_supplicant_event_interface_status(wpa_s
, data
);
2089 case EVENT_PMKID_CANDIDATE
:
2090 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2092 #ifdef CONFIG_PEERKEY
2093 case EVENT_STKSTART
:
2094 wpa_supplicant_event_stkstart(wpa_s
, data
);
2096 #endif /* CONFIG_PEERKEY */
2099 wpa_supplicant_event_tdls(wpa_s
, data
);
2101 #endif /* CONFIG_TDLS */
2102 #ifdef CONFIG_IEEE80211R
2103 case EVENT_FT_RESPONSE
:
2104 wpa_supplicant_event_ft_response(wpa_s
, data
);
2106 #endif /* CONFIG_IEEE80211R */
2107 #ifdef CONFIG_IBSS_RSN
2108 case EVENT_IBSS_RSN_START
:
2109 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2111 #endif /* CONFIG_IBSS_RSN */
2112 case EVENT_ASSOC_REJECT
:
2113 if (data
->assoc_reject
.bssid
)
2114 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2115 "bssid=" MACSTR
" status_code=%u",
2116 MAC2STR(data
->assoc_reject
.bssid
),
2117 data
->assoc_reject
.status_code
);
2119 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2121 data
->assoc_reject
.status_code
);
2122 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2123 sme_event_assoc_reject(wpa_s
, data
);
2125 case EVENT_AUTH_TIMED_OUT
:
2126 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2127 sme_event_auth_timed_out(wpa_s
, data
);
2129 case EVENT_ASSOC_TIMED_OUT
:
2130 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2131 sme_event_assoc_timed_out(wpa_s
, data
);
2133 case EVENT_TX_STATUS
:
2134 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
2135 " type=%d stype=%d",
2136 MAC2STR(data
->tx_status
.dst
),
2137 data
->tx_status
.type
, data
->tx_status
.stype
);
2139 if (wpa_s
->ap_iface
== NULL
) {
2140 #ifdef CONFIG_OFFCHANNEL
2141 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2142 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
2143 offchannel_send_action_tx_status(
2144 wpa_s
, data
->tx_status
.dst
,
2145 data
->tx_status
.data
,
2146 data
->tx_status
.data_len
,
2147 data
->tx_status
.ack
?
2148 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2149 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2150 #endif /* CONFIG_OFFCHANNEL */
2153 #endif /* CONFIG_AP */
2154 #ifdef CONFIG_OFFCHANNEL
2155 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
2156 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
2158 * Catch TX status events for Action frames we sent via group
2159 * interface in GO mode.
2161 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2162 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
2163 os_memcmp(wpa_s
->parent
->pending_action_dst
,
2164 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
2165 offchannel_send_action_tx_status(
2166 wpa_s
->parent
, data
->tx_status
.dst
,
2167 data
->tx_status
.data
,
2168 data
->tx_status
.data_len
,
2169 data
->tx_status
.ack
?
2170 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2171 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2174 #endif /* CONFIG_OFFCHANNEL */
2176 switch (data
->tx_status
.type
) {
2177 case WLAN_FC_TYPE_MGMT
:
2178 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
2179 data
->tx_status
.data_len
,
2180 data
->tx_status
.stype
,
2181 data
->tx_status
.ack
);
2183 case WLAN_FC_TYPE_DATA
:
2184 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
2185 data
->tx_status
.data
,
2186 data
->tx_status
.data_len
,
2187 data
->tx_status
.ack
);
2190 #endif /* CONFIG_AP */
2193 case EVENT_EAPOL_TX_STATUS
:
2194 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
2195 data
->eapol_tx_status
.data
,
2196 data
->eapol_tx_status
.data_len
,
2197 data
->eapol_tx_status
.ack
);
2199 case EVENT_DRIVER_CLIENT_POLL_OK
:
2200 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
2202 case EVENT_RX_FROM_UNKNOWN
:
2203 if (wpa_s
->ap_iface
== NULL
)
2205 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
2206 data
->rx_from_unknown
.wds
);
2209 if (wpa_s
->ap_iface
== NULL
) {
2212 const struct ieee80211_mgmt
*mgmt
;
2213 mgmt
= (const struct ieee80211_mgmt
*)
2214 data
->rx_mgmt
.frame
;
2215 fc
= le_to_host16(mgmt
->frame_control
);
2216 stype
= WLAN_FC_GET_STYPE(fc
);
2217 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2218 data
->rx_mgmt
.frame_len
> 24) {
2219 const u8
*src
= mgmt
->sa
;
2220 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2221 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2222 (mgmt
->u
.probe_req
.variable
-
2223 data
->rx_mgmt
.frame
);
2224 wpas_p2p_probe_req_rx(wpa_s
, src
, mgmt
->da
,
2225 mgmt
->bssid
, ie
, ie_len
);
2228 #endif /* CONFIG_P2P */
2229 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2230 "management frame in non-AP mode");
2233 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2235 #endif /* CONFIG_AP */
2236 case EVENT_RX_ACTION
:
2237 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2238 " Category=%u DataLen=%d freq=%d MHz",
2239 MAC2STR(data
->rx_action
.sa
),
2240 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2241 data
->rx_action
.freq
);
2242 #ifdef CONFIG_IEEE80211R
2243 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2244 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2245 data
->rx_action
.len
);
2248 #endif /* CONFIG_IEEE80211R */
2249 #ifdef CONFIG_IEEE80211W
2251 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2252 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2253 data
->rx_action
.data
,
2254 data
->rx_action
.len
);
2257 #endif /* CONFIG_SME */
2258 #endif /* CONFIG_IEEE80211W */
2260 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2261 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2262 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2263 data
->rx_action
.data
, data
->rx_action
.len
,
2264 data
->rx_action
.freq
) == 0)
2266 #endif /* CONFIG_GAS */
2267 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2268 wnm_action_rx(wpa_s
, &data
->rx_action
);
2272 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2273 data
->rx_action
.len
>= 4 &&
2274 data
->rx_action
.data
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
2275 wpa_dbg(wpa_s
, MSG_DEBUG
, "TDLS: Received Discovery "
2276 "Response from " MACSTR
,
2277 MAC2STR(data
->rx_action
.sa
));
2280 #endif /* CONFIG_TDLS */
2282 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2284 data
->rx_action
.bssid
,
2285 data
->rx_action
.category
,
2286 data
->rx_action
.data
,
2287 data
->rx_action
.len
, data
->rx_action
.freq
);
2288 #endif /* CONFIG_P2P */
2290 case EVENT_RX_PROBE_REQ
:
2291 if (data
->rx_probe_req
.sa
== NULL
||
2292 data
->rx_probe_req
.ie
== NULL
)
2295 if (wpa_s
->ap_iface
) {
2296 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2297 data
->rx_probe_req
.sa
,
2298 data
->rx_probe_req
.da
,
2299 data
->rx_probe_req
.bssid
,
2300 data
->rx_probe_req
.ie
,
2301 data
->rx_probe_req
.ie_len
);
2304 #endif /* CONFIG_AP */
2306 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2307 data
->rx_probe_req
.da
,
2308 data
->rx_probe_req
.bssid
,
2309 data
->rx_probe_req
.ie
,
2310 data
->rx_probe_req
.ie_len
);
2311 #endif /* CONFIG_P2P */
2313 case EVENT_REMAIN_ON_CHANNEL
:
2314 #ifdef CONFIG_OFFCHANNEL
2315 offchannel_remain_on_channel_cb(
2316 wpa_s
, data
->remain_on_channel
.freq
,
2317 data
->remain_on_channel
.duration
);
2318 #endif /* CONFIG_OFFCHANNEL */
2320 wpas_p2p_remain_on_channel_cb(
2321 wpa_s
, data
->remain_on_channel
.freq
,
2322 data
->remain_on_channel
.duration
);
2323 #endif /* CONFIG_P2P */
2325 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2326 #ifdef CONFIG_OFFCHANNEL
2327 offchannel_cancel_remain_on_channel_cb(
2328 wpa_s
, data
->remain_on_channel
.freq
);
2329 #endif /* CONFIG_OFFCHANNEL */
2331 wpas_p2p_cancel_remain_on_channel_cb(
2332 wpa_s
, data
->remain_on_channel
.freq
);
2333 #endif /* CONFIG_P2P */
2336 case EVENT_P2P_DEV_FOUND
: {
2337 struct p2p_peer_info peer_info
;
2339 os_memset(&peer_info
, 0, sizeof(peer_info
));
2340 if (data
->p2p_dev_found
.dev_addr
)
2341 os_memcpy(peer_info
.p2p_device_addr
,
2342 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2343 if (data
->p2p_dev_found
.pri_dev_type
)
2344 os_memcpy(peer_info
.pri_dev_type
,
2345 data
->p2p_dev_found
.pri_dev_type
,
2346 sizeof(peer_info
.pri_dev_type
));
2347 if (data
->p2p_dev_found
.dev_name
)
2348 os_strlcpy(peer_info
.device_name
,
2349 data
->p2p_dev_found
.dev_name
,
2350 sizeof(peer_info
.device_name
));
2351 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2352 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2353 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2356 * FIX: new_device=1 is not necessarily correct. We should
2357 * maintain a P2P peer database in wpa_supplicant and update
2358 * this information based on whether the peer is truly new.
2360 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2363 case EVENT_P2P_GO_NEG_REQ_RX
:
2364 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2365 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2367 case EVENT_P2P_GO_NEG_COMPLETED
:
2368 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2370 case EVENT_P2P_PROV_DISC_REQUEST
:
2371 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2372 data
->p2p_prov_disc_req
.config_methods
,
2373 data
->p2p_prov_disc_req
.dev_addr
,
2374 data
->p2p_prov_disc_req
.pri_dev_type
,
2375 data
->p2p_prov_disc_req
.dev_name
,
2376 data
->p2p_prov_disc_req
.supp_config_methods
,
2377 data
->p2p_prov_disc_req
.dev_capab
,
2378 data
->p2p_prov_disc_req
.group_capab
,
2381 case EVENT_P2P_PROV_DISC_RESPONSE
:
2382 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2383 data
->p2p_prov_disc_resp
.config_methods
);
2385 case EVENT_P2P_SD_REQUEST
:
2386 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2387 data
->p2p_sd_req
.sa
,
2388 data
->p2p_sd_req
.dialog_token
,
2389 data
->p2p_sd_req
.update_indic
,
2390 data
->p2p_sd_req
.tlvs
,
2391 data
->p2p_sd_req
.tlvs_len
);
2393 case EVENT_P2P_SD_RESPONSE
:
2394 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2395 data
->p2p_sd_resp
.update_indic
,
2396 data
->p2p_sd_resp
.tlvs
,
2397 data
->p2p_sd_resp
.tlvs_len
);
2399 #endif /* CONFIG_P2P */
2400 case EVENT_EAPOL_RX
:
2401 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2402 data
->eapol_rx
.data
,
2403 data
->eapol_rx
.data_len
);
2405 case EVENT_SIGNAL_CHANGE
:
2406 bgscan_notify_signal_change(
2407 wpa_s
, data
->signal_change
.above_threshold
,
2408 data
->signal_change
.current_signal
,
2409 data
->signal_change
.current_noise
,
2410 data
->signal_change
.current_txrate
);
2412 case EVENT_INTERFACE_ENABLED
:
2413 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2414 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2415 wpa_supplicant_update_mac_addr(wpa_s
);
2417 if (!wpa_s
->ap_iface
) {
2418 wpa_supplicant_set_state(wpa_s
,
2420 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2422 wpa_supplicant_set_state(wpa_s
,
2424 #else /* CONFIG_AP */
2425 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2426 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2427 #endif /* CONFIG_AP */
2430 case EVENT_INTERFACE_DISABLED
:
2431 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2432 wpa_supplicant_mark_disassoc(wpa_s
);
2433 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2435 case EVENT_CHANNEL_LIST_CHANGED
:
2436 if (wpa_s
->drv_priv
== NULL
)
2437 break; /* Ignore event during drv initialization */
2439 wpas_p2p_update_channel_list(wpa_s
);
2440 #endif /* CONFIG_P2P */
2442 case EVENT_INTERFACE_UNAVAILABLE
:
2444 wpas_p2p_interface_unavailable(wpa_s
);
2445 #endif /* CONFIG_P2P */
2447 case EVENT_BEST_CHANNEL
:
2448 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2450 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2451 data
->best_chan
.freq_overall
);
2452 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2453 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2454 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2456 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2457 data
->best_chan
.freq_5
,
2458 data
->best_chan
.freq_overall
);
2459 #endif /* CONFIG_P2P */
2461 case EVENT_UNPROT_DEAUTH
:
2462 wpa_supplicant_event_unprot_deauth(wpa_s
,
2463 &data
->unprot_deauth
);
2465 case EVENT_UNPROT_DISASSOC
:
2466 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2467 &data
->unprot_disassoc
);
2469 case EVENT_STATION_LOW_ACK
:
2471 if (wpa_s
->ap_iface
&& data
)
2472 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2473 data
->low_ack
.addr
);
2474 #endif /* CONFIG_AP */
2477 wpa_tdls_disable_link(wpa_s
->wpa
, data
->low_ack
.addr
);
2478 #endif /* CONFIG_TDLS */
2480 case EVENT_IBSS_PEER_LOST
:
2481 #ifdef CONFIG_IBSS_RSN
2482 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2483 #endif /* CONFIG_IBSS_RSN */
2485 case EVENT_DRIVER_GTK_REKEY
:
2486 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2487 wpa_s
->bssid
, ETH_ALEN
))
2491 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2492 data
->driver_gtk_rekey
.replay_ctr
);
2494 case EVENT_SCHED_SCAN_STOPPED
:
2495 wpa_s
->sched_scanning
= 0;
2496 wpa_supplicant_notify_scanning(wpa_s
, 0);
2499 * If we timed out, start a new sched scan to continue
2500 * searching for more SSIDs.
2502 if (wpa_s
->sched_scan_timed_out
)
2503 wpa_supplicant_req_sched_scan(wpa_s
);
2505 case EVENT_WPS_BUTTON_PUSHED
:
2507 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
2508 #endif /* CONFIG_WPS */
2511 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);