2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 static int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
,
48 struct wpa_ssid
*ssid
)
52 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
56 if (ssid
->disabled_until
.sec
> now
.sec
)
57 return ssid
->disabled_until
.sec
- now
.sec
;
59 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
65 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
67 struct wpa_ssid
*ssid
, *old_ssid
;
70 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
73 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
75 ssid
= wpa_supplicant_get_ssid(wpa_s
);
77 wpa_msg(wpa_s
, MSG_INFO
,
78 "No network configuration found for the current AP");
82 if (wpas_network_disabled(wpa_s
, ssid
)) {
83 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
87 res
= wpas_temp_disabled(wpa_s
, ssid
);
89 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
90 "disabled for %d second(s)", res
);
94 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
96 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
98 size_t wpa_ie_len
= sizeof(wpa_ie
);
99 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
100 wpa_ie
, &wpa_ie_len
);
102 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
105 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
106 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
107 old_ssid
= wpa_s
->current_ssid
;
108 wpa_s
->current_ssid
= ssid
;
109 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
110 wpa_supplicant_initiate_eapol(wpa_s
);
111 if (old_ssid
!= wpa_s
->current_ssid
)
112 wpas_notify_network_changed(wpa_s
);
118 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
120 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
122 if (wpa_s
->countermeasures
) {
123 wpa_s
->countermeasures
= 0;
124 wpa_drv_set_countermeasures(wpa_s
, 0);
125 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s
, 0, 0);
131 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
135 wnm_bss_keep_alive_deinit(wpa_s
);
137 #ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
139 wpa_s
->ibss_rsn
= NULL
;
140 #endif /* CONFIG_IBSS_RSN */
143 wpa_supplicant_ap_deinit(wpa_s
);
144 #endif /* CONFIG_AP */
146 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
149 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
150 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
151 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
152 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
154 wpa_s
->sme
.prev_bssid_set
= 0;
155 #endif /* CONFIG_SME */
157 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
158 #endif /* CONFIG_P2P */
159 wpa_s
->current_bss
= NULL
;
160 wpa_s
->assoc_freq
= 0;
161 #ifdef CONFIG_IEEE80211R
163 if (wpa_s
->sme
.ft_ies
)
164 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
165 #endif /* CONFIG_SME */
166 #endif /* CONFIG_IEEE80211R */
169 wpas_notify_bssid_changed(wpa_s
);
171 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
172 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
173 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
174 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
175 wpa_s
->ap_ies_from_associnfo
= 0;
176 wpa_s
->current_ssid
= NULL
;
181 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
183 struct wpa_ie_data ie
;
187 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
191 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
192 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
193 ie
.pmkid
+ i
* PMKID_LEN
,
195 if (pmksa_set
== 0) {
196 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
201 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
202 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
206 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
207 union wpa_event_data
*data
)
210 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
214 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
215 " index=%d preauth=%d",
216 MAC2STR(data
->pmkid_candidate
.bssid
),
217 data
->pmkid_candidate
.index
,
218 data
->pmkid_candidate
.preauth
);
220 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
221 data
->pmkid_candidate
.index
,
222 data
->pmkid_candidate
.preauth
);
226 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
228 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
229 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
232 #ifdef IEEE8021X_EAPOL
233 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
234 wpa_s
->current_ssid
&&
235 !(wpa_s
->current_ssid
->eapol_flags
&
236 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
237 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
238 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
239 * plaintext or static WEP keys). */
242 #endif /* IEEE8021X_EAPOL */
249 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
250 * @wpa_s: pointer to wpa_supplicant data
251 * @ssid: Configuration data for the network
252 * Returns: 0 on success, -1 on failure
254 * This function is called when starting authentication with a network that is
255 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
257 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
258 struct wpa_ssid
*ssid
)
260 #ifdef IEEE8021X_EAPOL
262 int aka
= 0, sim
= 0, type
;
264 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
267 if (ssid
->eap
.eap_methods
== NULL
) {
271 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
272 while (eap
->vendor
!= EAP_VENDOR_IETF
||
273 eap
->method
!= EAP_TYPE_NONE
) {
274 if (eap
->vendor
== EAP_VENDOR_IETF
) {
275 if (eap
->method
== EAP_TYPE_SIM
)
277 else if (eap
->method
== EAP_TYPE_AKA
||
278 eap
->method
== EAP_TYPE_AKA_PRIME
)
285 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
287 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
288 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
293 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
294 "use SIM, but neither EAP-SIM nor EAP-AKA are "
299 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
300 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
302 type
= SCARD_TRY_BOTH
;
304 type
= SCARD_USIM_ONLY
;
306 type
= SCARD_GSM_SIM_ONLY
;
308 wpa_s
->scard
= scard_init(type
, NULL
);
309 if (wpa_s
->scard
== NULL
) {
310 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
314 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
315 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
316 #endif /* PCSC_FUNCS */
317 #endif /* IEEE8021X_EAPOL */
323 #ifndef CONFIG_NO_SCAN_PROCESSING
324 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
325 struct wpa_ssid
*ssid
)
329 if (ssid
->mixed_cell
)
333 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
335 #endif /* CONFIG_WPS */
337 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
338 if (ssid
->wep_key_len
[i
]) {
343 #ifdef IEEE8021X_EAPOL
344 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
345 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
346 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
348 #endif /* IEEE8021X_EAPOL */
350 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
353 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
359 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
360 struct wpa_ssid
*ssid
,
363 struct wpa_ie_data ie
;
365 const u8
*rsn_ie
, *wpa_ie
;
369 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
373 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
374 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
375 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
376 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
377 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
379 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
380 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
383 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
384 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
390 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
392 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
397 if (!(ie
.proto
& ssid
->proto
)) {
398 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
403 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
404 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
409 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
410 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
415 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
416 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
421 #ifdef CONFIG_IEEE80211W
422 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
423 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
424 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
428 #endif /* CONFIG_IEEE80211W */
430 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
434 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
435 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
438 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
439 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
445 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
447 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
452 if (!(ie
.proto
& ssid
->proto
)) {
453 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
458 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
459 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
464 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
465 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
470 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
471 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
476 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
480 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
482 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow for non-WPA IEEE 802.1X");
486 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
487 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
488 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
492 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
493 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
497 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
504 static int freq_allowed(int *freqs
, int freq
)
511 for (i
= 0; freqs
[i
]; i
++)
512 if (freqs
[i
] == freq
)
518 static int ht_supported(const struct hostapd_hw_modes
*mode
)
520 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
522 * The driver did not indicate whether it supports HT. Assume
523 * it does to avoid connection issues.
529 * IEEE Std 802.11n-2009 20.1.1:
530 * An HT non-AP STA shall support all EQM rates for one spatial stream.
532 return mode
->mcs_set
[0] == 0xff;
536 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
538 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
539 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
544 return 1; /* Cannot do matching without knowing band */
546 modes
= wpa_s
->hw
.modes
;
549 * The driver does not provide any additional information
550 * about the utilized hardware, so allow the connection attempt
556 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
557 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
558 int freq
= modes
[i
].channels
[j
].freq
;
559 if (freq
== bss
->freq
) {
561 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
562 break; /* do not allow 802.11b replace
573 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
574 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
578 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
579 int flagged
= !!(rate_ie
[j
] & 0x80);
580 int r
= (rate_ie
[j
] & 0x7f) * 5;
583 * IEEE Std 802.11n-2009 7.3.2.2:
584 * The new BSS Membership selector value is encoded
585 * like a legacy basic rate, but it is not a rate and
586 * only indicates if the BSS members are required to
587 * support the mandatory features of Clause 20 [HT PHY]
588 * in order to join the BSS.
590 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
591 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
592 if (!ht_supported(mode
)) {
593 wpa_dbg(wpa_s
, MSG_DEBUG
,
594 " hardware does not support "
604 /* check for legacy basic rates */
605 for (k
= 0; k
< mode
->num_rates
; k
++) {
606 if (mode
->rates
[k
] == r
)
609 if (k
== mode
->num_rates
) {
611 * IEEE Std 802.11-2007 7.3.2.2 demands that in
612 * order to join a BSS all required rates
613 * have to be supported by the hardware.
615 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
616 "not support required rate %d.%d Mbps",
627 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
628 int i
, struct wpa_bss
*bss
,
629 struct wpa_ssid
*group
)
631 u8 wpa_ie_len
, rsn_ie_len
;
633 struct wpa_blacklist
*e
;
635 struct wpa_ssid
*ssid
;
637 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
638 wpa_ie_len
= ie
? ie
[1] : 0;
640 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
641 rsn_ie_len
= ie
? ie
[1] : 0;
643 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
644 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
645 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
646 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
647 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
649 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
652 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
654 * When only a single network is enabled, we can
655 * trigger blacklisting on the first failure. This
656 * should not be done with multiple enabled networks to
657 * avoid getting forced to move into a worse ESS on
658 * single error if there are no other BSSes of the
663 if (e
->count
> limit
) {
664 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
665 "(count=%d limit=%d)", e
->count
, limit
);
670 if (bss
->ssid_len
== 0) {
671 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
675 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
677 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
678 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
681 if (wpas_network_disabled(wpa_s
, ssid
)) {
682 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
686 res
= wpas_temp_disabled(wpa_s
, ssid
);
688 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled "
689 "temporarily for %d second(s)", res
);
694 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
695 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
700 if (wpa
&& ssid
->ssid_len
== 0 &&
701 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
704 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
705 /* Only allow wildcard SSID match if an AP
706 * advertises active WPS operation that matches
709 if (ssid
->ssid_len
== 0 &&
710 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
713 #endif /* CONFIG_WPS */
715 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
716 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
720 (bss
->ssid_len
!= ssid
->ssid_len
||
721 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
722 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
726 if (ssid
->bssid_set
&&
727 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
728 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
732 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
736 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
737 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
738 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
739 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
744 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
745 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
750 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
751 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
756 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
757 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
762 if (!rate_match(wpa_s
, bss
)) {
763 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
770 * TODO: skip the AP if its P2P IE has Group Formation
771 * bit set in the P2P Group Capability Bitmap and we
772 * are not in Group Formation with that device.
774 #endif /* CONFIG_P2P */
776 /* Matching configuration found */
780 /* No matching configuration found */
785 static struct wpa_bss
*
786 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
787 struct wpa_ssid
*group
,
788 struct wpa_ssid
**selected_ssid
)
792 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
795 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
796 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
797 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
800 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
803 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
811 static struct wpa_bss
*
812 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
813 struct wpa_ssid
**selected_ssid
)
815 struct wpa_bss
*selected
= NULL
;
818 if (wpa_s
->last_scan_res
== NULL
||
819 wpa_s
->last_scan_res_used
== 0)
820 return NULL
; /* no scan results from last update */
822 while (selected
== NULL
) {
823 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
824 selected
= wpa_supplicant_select_bss(
825 wpa_s
, wpa_s
->conf
->pssid
[prio
],
831 if (selected
== NULL
&& wpa_s
->blacklist
&&
832 !wpa_s
->countermeasures
) {
833 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
834 "blacklist and try again");
835 wpa_blacklist_clear(wpa_s
);
836 wpa_s
->blacklist_cleared
++;
837 } else if (selected
== NULL
)
845 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
846 int timeout_sec
, int timeout_usec
)
848 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
850 * No networks are enabled; short-circuit request so
851 * we don't wait timeout seconds before transitioning
854 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
857 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
861 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
862 struct wpa_bss
*selected
,
863 struct wpa_ssid
*ssid
)
865 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
866 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
867 "PBC session overlap");
869 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
871 #endif /* CONFIG_P2P */
874 wpas_wps_cancel(wpa_s
);
875 #endif /* CONFIG_WPS */
880 * Do not trigger new association unless the BSSID has changed or if
881 * reassociation is requested. If we are in process of associating with
882 * the selected BSSID, do not trigger new attempt.
884 if (wpa_s
->reassociate
||
885 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
886 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
887 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
888 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
890 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
891 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
894 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
895 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
896 " pending: " MACSTR
" wpa_state: %s",
897 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
898 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
899 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
900 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
902 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
910 static struct wpa_ssid
*
911 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
914 struct wpa_ssid
*ssid
;
916 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
917 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
919 if (wpas_network_disabled(wpa_s
, ssid
))
921 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
922 ssid
->mode
== IEEE80211_MODE_AP
)
930 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
931 * on BSS added and BSS changed events */
932 static void wpa_supplicant_rsn_preauth_scan_results(
933 struct wpa_supplicant
*wpa_s
)
937 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
940 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
941 const u8
*ssid
, *rsn
;
943 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
947 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
951 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
957 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
958 struct wpa_bss
*selected
,
959 struct wpa_ssid
*ssid
)
961 struct wpa_bss
*current_bss
= NULL
;
964 if (wpa_s
->reassociate
)
965 return 1; /* explicit request to reassociate */
966 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
967 return 1; /* we are not associated; continue */
968 if (wpa_s
->current_ssid
== NULL
)
969 return 1; /* unknown current SSID */
970 if (wpa_s
->current_ssid
!= ssid
)
971 return 1; /* different network block */
973 if (wpas_driver_bss_selection(wpa_s
))
974 return 0; /* Driver-based roaming */
976 if (wpa_s
->current_ssid
->ssid
)
977 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
978 wpa_s
->current_ssid
->ssid
,
979 wpa_s
->current_ssid
->ssid_len
);
981 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
984 return 1; /* current BSS not seen in scan results */
986 if (current_bss
== selected
)
989 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
990 return 1; /* current BSS not seen in the last scan */
992 #ifndef CONFIG_NO_ROAMING
993 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
994 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
995 MAC2STR(current_bss
->bssid
), current_bss
->level
);
996 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
997 MAC2STR(selected
->bssid
), selected
->level
);
999 if (wpa_s
->current_ssid
->bssid_set
&&
1000 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1002 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1003 "has preferred BSSID");
1008 if (current_bss
->level
< 0) {
1009 if (current_bss
->level
< -85)
1011 else if (current_bss
->level
< -80)
1013 else if (current_bss
->level
< -75)
1015 else if (current_bss
->level
< -70)
1020 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
1021 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
1027 #else /* CONFIG_NO_ROAMING */
1029 #endif /* CONFIG_NO_ROAMING */
1033 /* Return != 0 if no scan results could be fetched or if scan results should not
1034 * be shared with other virtual interfaces. */
1035 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1036 union wpa_event_data
*data
)
1038 struct wpa_scan_results
*scan_res
;
1040 #ifndef CONFIG_NO_RANDOM_POOL
1042 #endif /* CONFIG_NO_RANDOM_POOL */
1045 if (wpa_s
->ap_iface
)
1047 #endif /* CONFIG_AP */
1049 wpa_supplicant_notify_scanning(wpa_s
, 0);
1052 if (wpa_s
->global
->p2p_cb_on_scan_complete
&&
1053 !wpa_s
->global
->p2p_disabled
&&
1054 wpa_s
->global
->p2p
!= NULL
&& !wpa_s
->sta_scan_pending
) {
1055 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
1056 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
1057 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
1058 "stopped scan processing");
1059 wpa_s
->sta_scan_pending
= 1;
1060 wpa_supplicant_req_scan(wpa_s
, 5, 0);
1064 wpa_s
->sta_scan_pending
= 0;
1065 #endif /* CONFIG_P2P */
1067 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1068 data
? &data
->scan_info
:
1070 if (scan_res
== NULL
) {
1071 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
1073 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1075 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1079 #ifndef CONFIG_NO_RANDOM_POOL
1080 num
= scan_res
->num
;
1083 for (i
= 0; i
< num
; i
++) {
1085 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1086 buf
[0] = res
->bssid
[5];
1087 buf
[1] = res
->qual
& 0xff;
1088 buf
[2] = res
->noise
& 0xff;
1089 buf
[3] = res
->level
& 0xff;
1090 buf
[4] = res
->tsf
& 0xff;
1091 random_add_randomness(buf
, sizeof(buf
));
1093 #endif /* CONFIG_NO_RANDOM_POOL */
1095 if (wpa_s
->scan_res_handler
) {
1096 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1097 struct wpa_scan_results
*scan_res
);
1099 scan_res_handler
= wpa_s
->scan_res_handler
;
1100 wpa_s
->scan_res_handler
= NULL
;
1101 scan_res_handler(wpa_s
, scan_res
);
1103 wpa_scan_results_free(scan_res
);
1108 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1110 if (wpa_s
->ap_iface
->scan_cb
)
1111 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1112 #endif /* CONFIG_AP */
1113 wpa_scan_results_free(scan_res
);
1117 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
1118 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1119 wpas_notify_scan_results(wpa_s
);
1121 wpas_notify_scan_done(wpa_s
, 1);
1123 if (sme_proc_obss_scan(wpa_s
) > 0) {
1124 wpa_scan_results_free(scan_res
);
1128 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
1129 wpa_scan_results_free(scan_res
);
1133 if (autoscan_notify_scan(wpa_s
, scan_res
)) {
1134 wpa_scan_results_free(scan_res
);
1138 if (wpa_s
->disconnected
) {
1139 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1140 wpa_scan_results_free(scan_res
);
1144 if (!wpas_driver_bss_selection(wpa_s
) &&
1145 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
1146 wpa_scan_results_free(scan_res
);
1150 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1152 wpa_scan_results_free(scan_res
);
1154 return wpas_select_network_from_last_scan(wpa_s
);
1158 int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
)
1160 struct wpa_bss
*selected
;
1161 struct wpa_ssid
*ssid
= NULL
;
1163 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1167 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1169 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1173 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1174 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1177 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1179 * Do not notify other virtual radios of scan results since we do not
1180 * want them to start other associations at the same time.
1184 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1185 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1187 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1188 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1189 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1191 int timeout_sec
= wpa_s
->scan_interval
;
1192 int timeout_usec
= 0;
1194 if (wpas_p2p_scan_no_go_seen(wpa_s
) == 1)
1197 if (wpa_s
->p2p_in_provisioning
) {
1199 * Use shorter wait during P2P Provisioning
1200 * state to speed up group formation.
1203 timeout_usec
= 250000;
1204 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1208 #endif /* CONFIG_P2P */
1209 #ifdef CONFIG_INTERWORKING
1210 if (wpa_s
->conf
->auto_interworking
&&
1211 wpa_s
->conf
->interworking
&&
1212 wpa_s
->conf
->cred
) {
1213 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1214 "start ANQP fetch since no matching "
1216 wpa_s
->network_select
= 1;
1217 wpa_s
->auto_network_select
= 1;
1218 interworking_start_fetch_anqp(wpa_s
);
1221 #endif /* CONFIG_INTERWORKING */
1222 if (wpa_supplicant_req_sched_scan(wpa_s
))
1223 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1231 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1232 union wpa_event_data
*data
)
1234 const char *rn
, *rn2
;
1235 struct wpa_supplicant
*ifs
;
1237 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) != 0) {
1239 * If no scan results could be fetched, then no need to
1240 * notify those interfaces that did not actually request
1241 * this scan. Similarly, if scan results started a new operation on this
1242 * interface, do not notify other interfaces to avoid concurrent
1243 * operations during a connection attempt.
1249 * Check other interfaces to see if they have the same radio-name. If
1250 * so, they get updated with this same scan info.
1252 if (!wpa_s
->driver
->get_radio_name
)
1255 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1256 if (rn
== NULL
|| rn
[0] == '\0')
1259 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1260 "sharing same radio (%s) in event_scan_results", rn
);
1262 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1263 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1266 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1267 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1268 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1269 "sibling", ifs
->ifname
);
1270 _wpa_supplicant_event_scan_results(ifs
, data
);
1275 #endif /* CONFIG_NO_SCAN_PROCESSING */
1280 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1282 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1284 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1287 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1288 MAC2STR(wpa_s
->bssid
));
1289 /* TODO: could skip this if normal data traffic has been sent */
1290 /* TODO: Consider using some more appropriate data frame for this */
1292 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800, (u8
*) "", 0);
1295 if (wpa_s
->sme
.bss_max_idle_period
) {
1297 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
1300 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1301 wnm_bss_keep_alive
, wpa_s
, NULL
);
1303 #endif /* CONFIG_SME */
1307 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1308 const u8
*ies
, size_t ies_len
)
1310 struct ieee802_11_elems elems
;
1315 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1319 if (elems
.bss_max_idle_period
) {
1321 wpa_s
->sme
.bss_max_idle_period
=
1322 WPA_GET_LE16(elems
.bss_max_idle_period
);
1323 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
1324 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
1325 (elems
.bss_max_idle_period
[2] & 0x01) ?
1326 " (protected keep-live required)" : "");
1327 if (wpa_s
->sme
.bss_max_idle_period
== 0)
1328 wpa_s
->sme
.bss_max_idle_period
= 1;
1329 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
1330 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1331 /* msec times 1000 */
1332 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
1335 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1336 wnm_bss_keep_alive
, wpa_s
,
1340 #endif /* CONFIG_SME */
1343 #endif /* CONFIG_WNM */
1346 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
1349 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1350 #endif /* CONFIG_WNM */
1354 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1355 union wpa_event_data
*data
)
1357 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1360 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1361 if (data
->assoc_info
.req_ies
)
1362 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1363 data
->assoc_info
.req_ies_len
);
1364 if (data
->assoc_info
.resp_ies
) {
1365 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1366 data
->assoc_info
.resp_ies_len
);
1368 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1369 data
->assoc_info
.resp_ies_len
);
1370 #endif /* CONFIG_TDLS */
1372 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1373 data
->assoc_info
.resp_ies_len
);
1374 #endif /* CONFIG_WNM */
1376 if (data
->assoc_info
.beacon_ies
)
1377 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1378 data
->assoc_info
.beacon_ies
,
1379 data
->assoc_info
.beacon_ies_len
);
1380 if (data
->assoc_info
.freq
)
1381 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1382 data
->assoc_info
.freq
);
1384 p
= data
->assoc_info
.req_ies
;
1385 l
= data
->assoc_info
.req_ies_len
;
1387 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1388 while (p
&& l
>= 2) {
1391 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1395 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1396 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1397 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1398 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1401 wpa_find_assoc_pmkid(wpa_s
);
1407 if (!found
&& data
->assoc_info
.req_ies
)
1408 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1410 #ifdef CONFIG_IEEE80211R
1412 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1414 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1415 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1416 data
->assoc_info
.resp_ies
,
1417 data
->assoc_info
.resp_ies_len
,
1419 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1420 "Reassociation Response failed");
1421 wpa_supplicant_deauthenticate(
1422 wpa_s
, WLAN_REASON_INVALID_IE
);
1427 p
= data
->assoc_info
.resp_ies
;
1428 l
= data
->assoc_info
.resp_ies_len
;
1430 #ifdef CONFIG_WPS_STRICT
1431 if (p
&& wpa_s
->current_ssid
&&
1432 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1434 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1436 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1437 "include WPS IE in (Re)Association Response");
1441 if (wps_validate_assoc_resp(wps
) < 0) {
1443 wpa_supplicant_deauthenticate(
1444 wpa_s
, WLAN_REASON_INVALID_IE
);
1449 #endif /* CONFIG_WPS_STRICT */
1451 /* Go through the IEs and make a copy of the MDIE, if present. */
1452 while (p
&& l
>= 2) {
1455 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1459 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1460 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1461 wpa_s
->sme
.ft_used
= 1;
1462 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1463 MOBILITY_DOMAIN_ID_LEN
);
1469 #endif /* CONFIG_SME */
1471 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1472 data
->assoc_info
.resp_ies_len
);
1473 #endif /* CONFIG_IEEE80211R */
1475 /* WPA/RSN IE from Beacon/ProbeResp */
1476 p
= data
->assoc_info
.beacon_ies
;
1477 l
= data
->assoc_info
.beacon_ies_len
;
1479 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1481 wpa_found
= rsn_found
= 0;
1482 while (p
&& l
>= 2) {
1485 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1490 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1491 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1493 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1497 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1499 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1506 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1507 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1508 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1509 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1510 if (wpa_found
|| rsn_found
)
1511 wpa_s
->ap_ies_from_associnfo
= 1;
1513 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1514 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1515 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1517 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1518 wpa_supplicant_update_scan_results(wpa_s
);
1521 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1527 static struct wpa_bss
* wpa_supplicant_get_new_bss(
1528 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
1530 struct wpa_bss
*bss
= NULL
;
1531 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1533 if (ssid
->ssid_len
> 0)
1534 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
1536 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1542 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
1544 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
1546 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
1549 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
1552 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1553 WPA_IE_VENDOR_TYPE
);
1554 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
1556 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1557 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1558 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1559 bss_rsn
? 2 + bss_rsn
[1] : 0))
1566 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1567 union wpa_event_data
*data
)
1571 struct wpa_driver_capa capa
;
1574 if (wpa_s
->ap_iface
) {
1575 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1576 data
->assoc_info
.addr
,
1577 data
->assoc_info
.req_ies
,
1578 data
->assoc_info
.req_ies_len
,
1579 data
->assoc_info
.reassoc
);
1582 #endif /* CONFIG_AP */
1584 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1585 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1588 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1589 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
1590 wpa_supplicant_disassociate(
1591 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1595 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1596 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1597 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1598 MACSTR
, MAC2STR(bssid
));
1599 random_add_randomness(bssid
, ETH_ALEN
);
1600 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1601 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1602 wpas_notify_bssid_changed(wpa_s
);
1604 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1605 wpa_clear_keys(wpa_s
, bssid
);
1607 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1608 wpa_supplicant_disassociate(
1609 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1612 if (wpa_s
->current_ssid
) {
1613 struct wpa_bss
*bss
= NULL
;
1615 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
1617 wpa_supplicant_update_scan_results(wpa_s
);
1619 /* Get the BSS from the new scan results */
1620 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
1624 wpa_s
->current_bss
= bss
;
1627 if (wpa_s
->conf
->ap_scan
== 1 &&
1628 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
1629 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0)
1630 wpa_msg(wpa_s
, MSG_WARNING
,
1631 "WPA/RSN IEs not updated");
1636 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1637 wpa_s
->sme
.prev_bssid_set
= 1;
1638 #endif /* CONFIG_SME */
1640 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1641 if (wpa_s
->current_ssid
) {
1642 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1643 * initialized before association, but for other modes,
1644 * initialize PC/SC here, if the current configuration needs
1645 * smartcard or SIM/USIM. */
1646 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1648 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1650 l2_packet_notify_auth_start(wpa_s
->l2
);
1653 * Set portEnabled first to FALSE in order to get EAP state machine out
1654 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1655 * state machine may transit to AUTHENTICATING state based on obsolete
1656 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1657 * AUTHENTICATED without ever giving chance to EAP state machine to
1660 if (!ft_completed
) {
1661 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1662 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1664 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1665 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1666 /* 802.1X::portControl = Auto */
1667 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1668 wpa_s
->eapol_received
= 0;
1669 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1670 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1671 (wpa_s
->current_ssid
&&
1672 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1673 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1674 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1675 } else if (!ft_completed
) {
1676 /* Timeout for receiving the first EAPOL packet */
1677 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1679 wpa_supplicant_cancel_scan(wpa_s
);
1681 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1682 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1684 * We are done; the driver will take care of RSN 4-way
1687 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1688 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1689 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1690 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1691 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1692 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1694 * The driver will take care of RSN 4-way handshake, so we need
1695 * to allow EAPOL supplicant to complete its work without
1696 * waiting for WPA supplicant.
1698 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1699 } else if (ft_completed
) {
1701 * FT protocol completed - make sure EAPOL state machine ends
1702 * up in authenticated.
1704 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1705 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1706 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1707 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1710 if (wpa_s
->pending_eapol_rx
) {
1711 struct os_time now
, age
;
1713 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1714 if (age
.sec
== 0 && age
.usec
< 100000 &&
1715 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1717 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1718 "frame that was received just before "
1719 "association notification");
1720 wpa_supplicant_rx_eapol(
1721 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1722 wpabuf_head(wpa_s
->pending_eapol_rx
),
1723 wpabuf_len(wpa_s
->pending_eapol_rx
));
1725 wpabuf_free(wpa_s
->pending_eapol_rx
);
1726 wpa_s
->pending_eapol_rx
= NULL
;
1729 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1730 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1731 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1732 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1733 /* Set static WEP keys again */
1734 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1737 #ifdef CONFIG_IBSS_RSN
1738 if (wpa_s
->current_ssid
&&
1739 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1740 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1741 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1742 wpa_s
->ibss_rsn
== NULL
) {
1743 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1744 if (!wpa_s
->ibss_rsn
) {
1745 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1746 wpa_supplicant_deauthenticate(
1747 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1751 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1753 #endif /* CONFIG_IBSS_RSN */
1755 wpas_wps_notify_assoc(wpa_s
, bssid
);
1759 static int disconnect_reason_recoverable(u16 reason_code
)
1761 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
1762 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
1763 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
1767 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1769 int locally_generated
)
1773 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1775 * At least Host AP driver and a Prism3 card seemed to be
1776 * generating streams of disconnected events when configuring
1777 * IBSS for WPA-None. Ignore them for now.
1782 bssid
= wpa_s
->bssid
;
1783 if (is_zero_ether_addr(bssid
))
1784 bssid
= wpa_s
->pending_bssid
;
1786 if (!is_zero_ether_addr(bssid
) ||
1787 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1788 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1790 MAC2STR(bssid
), reason_code
,
1791 locally_generated
? " locally_generated=1" : "");
1796 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
1798 int locally_generated
)
1802 u8 prev_pending_bssid
[ETH_ALEN
];
1803 struct wpa_bss
*fast_reconnect
= NULL
;
1804 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
1805 struct wpa_ssid
*last_ssid
;
1807 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1808 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1810 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1812 * At least Host AP driver and a Prism3 card seemed to be
1813 * generating streams of disconnected events when configuring
1814 * IBSS for WPA-None. Ignore them for now.
1816 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1817 "IBSS/WPA-None mode");
1821 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1822 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1823 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1824 "pre-shared key may be incorrect");
1825 wpas_auth_failed(wpa_s
);
1827 if (!wpa_s
->auto_reconnect_disabled
||
1828 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1829 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
1830 "reconnect (wps=%d wpa_state=%d)",
1831 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
1833 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
1834 wpa_s
->current_ssid
&&
1835 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
1836 !locally_generated
&&
1837 disconnect_reason_recoverable(reason_code
)) {
1839 * It looks like the AP has dropped association with
1840 * us, but could allow us to get back in. Try to
1841 * reconnect to the same BSS without full scan to save
1842 * time for some common cases.
1844 fast_reconnect
= wpa_s
->current_bss
;
1845 fast_reconnect_ssid
= wpa_s
->current_ssid
;
1846 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1847 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1849 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
1852 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
1853 "try to re-connect");
1854 wpa_s
->reassociate
= 0;
1855 wpa_s
->disconnected
= 1;
1856 wpa_supplicant_cancel_sched_scan(wpa_s
);
1858 bssid
= wpa_s
->bssid
;
1859 if (is_zero_ether_addr(bssid
))
1860 bssid
= wpa_s
->pending_bssid
;
1861 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
1862 wpas_connection_failed(wpa_s
, bssid
);
1863 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1864 if (locally_generated
)
1865 wpa_s
->disconnect_reason
= -reason_code
;
1867 wpa_s
->disconnect_reason
= reason_code
;
1868 wpas_notify_disconnect_reason(wpa_s
);
1869 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1870 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1871 wpa_s
->keys_cleared
= 0;
1872 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1874 last_ssid
= wpa_s
->current_ssid
;
1875 wpa_supplicant_mark_disassoc(wpa_s
);
1877 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
1878 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1879 wpa_s
->current_ssid
= last_ssid
;
1882 if (fast_reconnect
) {
1883 #ifndef CONFIG_NO_SCAN_PROCESSING
1884 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
1885 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
1886 fast_reconnect_ssid
) < 0) {
1887 /* Recover through full scan */
1888 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1890 #endif /* CONFIG_NO_SCAN_PROCESSING */
1895 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1896 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
1898 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1900 if (!wpa_s
->pending_mic_error_report
)
1903 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1904 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1905 wpa_s
->pending_mic_error_report
= 0;
1907 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1911 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1912 union wpa_event_data
*data
)
1917 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1918 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1920 if ((wpa_s
->last_michael_mic_error
&&
1921 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1922 wpa_s
->pending_mic_error_report
) {
1923 if (wpa_s
->pending_mic_error_report
) {
1925 * Send the pending MIC error report immediately since
1926 * we are going to start countermeasures and AP better
1929 wpa_sm_key_request(wpa_s
->wpa
, 1,
1930 wpa_s
->pending_mic_error_pairwise
);
1933 /* Send the new MIC error report immediately since we are going
1934 * to start countermeasures and AP better do the same.
1936 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1938 /* initialize countermeasures */
1939 wpa_s
->countermeasures
= 1;
1941 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
1943 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1946 * Need to wait for completion of request frame. We do not get
1947 * any callback for the message completion, so just wait a
1948 * short while and hope for the best. */
1951 wpa_drv_set_countermeasures(wpa_s
, 1);
1952 wpa_supplicant_deauthenticate(wpa_s
,
1953 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1954 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1956 eloop_register_timeout(60, 0,
1957 wpa_supplicant_stop_countermeasures
,
1959 /* TODO: mark the AP rejected for 60 second. STA is
1960 * allowed to associate with another AP.. */
1962 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1963 if (wpa_s
->mic_errors_seen
) {
1965 * Reduce the effectiveness of Michael MIC error
1966 * reports as a means for attacking against TKIP if
1967 * more than one MIC failure is noticed with the same
1968 * PTK. We delay the transmission of the reports by a
1969 * random time between 0 and 60 seconds in order to
1970 * force the attacker wait 60 seconds before getting
1971 * the information on whether a frame resulted in a MIC
1977 if (os_get_random(rval
, sizeof(rval
)) < 0)
1978 sec
= os_random() % 60;
1980 sec
= WPA_GET_BE32(rval
) % 60;
1981 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1982 "report %d seconds", sec
);
1983 wpa_s
->pending_mic_error_report
= 1;
1984 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1985 eloop_cancel_timeout(
1986 wpa_supplicant_delayed_mic_error_report
,
1988 eloop_register_timeout(
1989 sec
, os_random() % 1000000,
1990 wpa_supplicant_delayed_mic_error_report
,
1993 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1995 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1996 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1997 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1999 wpa_s
->last_michael_mic_error
= t
.sec
;
2000 wpa_s
->mic_errors_seen
++;
2004 #ifdef CONFIG_TERMINATE_ONLASTIF
2005 static int any_interfaces(struct wpa_supplicant
*head
)
2007 struct wpa_supplicant
*wpa_s
;
2009 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2010 if (!wpa_s
->interface_removed
)
2014 #endif /* CONFIG_TERMINATE_ONLASTIF */
2018 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2019 union wpa_event_data
*data
)
2021 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2024 switch (data
->interface_status
.ievent
) {
2025 case EVENT_INTERFACE_ADDED
:
2026 if (!wpa_s
->interface_removed
)
2028 wpa_s
->interface_removed
= 0;
2029 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
2030 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
2031 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
2032 "driver after interface was added");
2034 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2036 case EVENT_INTERFACE_REMOVED
:
2037 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
2038 wpa_s
->interface_removed
= 1;
2039 wpa_supplicant_mark_disassoc(wpa_s
);
2040 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2041 l2_packet_deinit(wpa_s
->l2
);
2043 #ifdef CONFIG_IBSS_RSN
2044 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
2045 wpa_s
->ibss_rsn
= NULL
;
2046 #endif /* CONFIG_IBSS_RSN */
2047 #ifdef CONFIG_TERMINATE_ONLASTIF
2048 /* check if last interface */
2049 if (!any_interfaces(wpa_s
->global
->ifaces
))
2051 #endif /* CONFIG_TERMINATE_ONLASTIF */
2057 #ifdef CONFIG_PEERKEY
2059 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
2060 union wpa_event_data
*data
)
2064 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
2066 #endif /* CONFIG_PEERKEY */
2070 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
2071 union wpa_event_data
*data
)
2075 switch (data
->tdls
.oper
) {
2076 case TDLS_REQUEST_SETUP
:
2077 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
2079 case TDLS_REQUEST_TEARDOWN
:
2080 wpa_tdls_send_teardown(wpa_s
->wpa
, data
->tdls
.peer
,
2081 data
->tdls
.reason_code
);
2085 #endif /* CONFIG_TDLS */
2088 #ifdef CONFIG_IEEE80211V
2089 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
2090 union wpa_event_data
*data
)
2094 switch (data
->wnm
.oper
) {
2095 case WNM_OPER_SLEEP
:
2096 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
2097 "(action=%d, intval=%d)",
2098 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
2099 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
2100 data
->wnm
.sleep_intval
);
2104 #endif /* CONFIG_IEEE80211V */
2107 #ifdef CONFIG_IEEE80211R
2109 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
2110 union wpa_event_data
*data
)
2115 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
2116 data
->ft_ies
.ies_len
,
2117 data
->ft_ies
.ft_action
,
2118 data
->ft_ies
.target_ap
,
2119 data
->ft_ies
.ric_ies
,
2120 data
->ft_ies
.ric_ies_len
) < 0) {
2121 /* TODO: prevent MLME/driver from trying to associate? */
2124 #endif /* CONFIG_IEEE80211R */
2127 #ifdef CONFIG_IBSS_RSN
2128 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
2129 union wpa_event_data
*data
)
2131 struct wpa_ssid
*ssid
;
2132 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2136 ssid
= wpa_s
->current_ssid
;
2139 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2142 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
2144 #endif /* CONFIG_IBSS_RSN */
2147 #ifdef CONFIG_IEEE80211R
2148 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
2151 const u8
*sta_addr
, *target_ap_addr
;
2154 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
2155 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2156 return; /* only SME case supported for now */
2157 if (len
< 1 + 2 * ETH_ALEN
+ 2)
2160 return; /* Only FT Action Response is supported for now */
2161 sta_addr
= data
+ 1;
2162 target_ap_addr
= data
+ 1 + ETH_ALEN
;
2163 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
2164 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
2165 MACSTR
" TargetAP " MACSTR
" status %u",
2166 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
2168 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
2169 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
2170 " in FT Action Response", MAC2STR(sta_addr
));
2175 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
2176 "failure (status code %d)", status
);
2177 /* TODO: report error to FT code(?) */
2181 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
2182 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
2183 target_ap_addr
, NULL
, 0) < 0)
2188 struct wpa_bss
*bss
;
2189 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
2191 wpa_s
->sme
.freq
= bss
->freq
;
2192 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
2193 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
2196 #endif /* CONFIG_SME */
2198 #endif /* CONFIG_IEEE80211R */
2201 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
2202 struct unprot_deauth
*e
)
2204 #ifdef CONFIG_IEEE80211W
2205 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
2206 "dropped: " MACSTR
" -> " MACSTR
2207 " (reason code %u)",
2208 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2209 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2210 #endif /* CONFIG_IEEE80211W */
2214 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
2215 struct unprot_disassoc
*e
)
2217 #ifdef CONFIG_IEEE80211W
2218 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
2219 "dropped: " MACSTR
" -> " MACSTR
2220 " (reason code %u)",
2221 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2222 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2223 #endif /* CONFIG_IEEE80211W */
2227 static void wnm_action_rx(struct wpa_supplicant
*wpa_s
, struct rx_action
*rx
)
2230 const u8
*pos
, *end
;
2232 if (rx
->data
== NULL
|| rx
->len
== 0)
2236 end
= pos
+ rx
->len
;
2239 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
2240 action
, MAC2STR(rx
->sa
));
2242 case WNM_BSS_TRANS_MGMT_REQ
:
2245 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management "
2246 "Request: dialog_token=%u request_mode=0x%x "
2247 "disassoc_timer=%u validity_interval=%u",
2248 pos
[0], pos
[1], WPA_GET_LE16(pos
+ 2), pos
[4]);
2252 pos
+= 12; /* BSS Termination Duration */
2255 if (pos
+ 1 > end
|| pos
+ 1 + pos
[0] > end
) {
2256 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS "
2257 "Transition Management Request "
2261 os_memcpy(url
, pos
+ 1, pos
[0]);
2263 wpa_msg(wpa_s
, MSG_INFO
, "WNM: ESS Disassociation "
2264 "Imminent - session_info_url=%s", url
);
2271 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
2272 union wpa_event_data
*data
)
2274 struct wpa_supplicant
*wpa_s
= ctx
;
2275 u16 reason_code
= 0;
2276 int locally_generated
= 0;
2278 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
2279 event
!= EVENT_INTERFACE_ENABLED
&&
2280 event
!= EVENT_INTERFACE_STATUS
&&
2281 event
!= EVENT_SCHED_SCAN_STOPPED
) {
2282 wpa_dbg(wpa_s
, MSG_DEBUG
,
2283 "Ignore event %s (%d) while interface is disabled",
2284 event_to_string(event
), event
);
2288 #ifndef CONFIG_NO_STDOUT_DEBUG
2290 int level
= MSG_DEBUG
;
2292 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
2293 const struct ieee80211_hdr
*hdr
;
2295 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
2296 fc
= le_to_host16(hdr
->frame_control
);
2297 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
2298 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
2299 level
= MSG_EXCESSIVE
;
2302 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
2303 event_to_string(event
), event
);
2305 #endif /* CONFIG_NO_STDOUT_DEBUG */
2309 sme_event_auth(wpa_s
, data
);
2312 wpa_supplicant_event_assoc(wpa_s
, data
);
2314 case EVENT_DISASSOC
:
2315 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
2317 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
2318 data
->disassoc_info
.reason_code
,
2319 data
->disassoc_info
.locally_generated
?
2320 " (locally generated)" : "");
2321 if (data
->disassoc_info
.addr
)
2322 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
2323 MAC2STR(data
->disassoc_info
.addr
));
2326 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
2327 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2328 data
->disassoc_info
.addr
);
2331 if (wpa_s
->ap_iface
) {
2332 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in "
2336 #endif /* CONFIG_AP */
2338 reason_code
= data
->disassoc_info
.reason_code
;
2340 data
->disassoc_info
.locally_generated
;
2341 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
2342 data
->disassoc_info
.ie
,
2343 data
->disassoc_info
.ie_len
);
2345 wpas_p2p_disassoc_notif(
2346 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
2347 data
->disassoc_info
.ie
,
2348 data
->disassoc_info
.ie_len
,
2350 #endif /* CONFIG_P2P */
2352 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2353 sme_event_disassoc(wpa_s
, data
);
2356 if (event
== EVENT_DEAUTH
) {
2357 wpa_dbg(wpa_s
, MSG_DEBUG
,
2358 "Deauthentication notification");
2360 reason_code
= data
->deauth_info
.reason_code
;
2362 data
->deauth_info
.locally_generated
;
2363 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
2364 data
->deauth_info
.reason_code
,
2365 data
->deauth_info
.locally_generated
?
2366 " (locally generated)" : "");
2367 if (data
->deauth_info
.addr
) {
2368 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
2370 MAC2STR(data
->deauth_info
.
2373 wpa_hexdump(MSG_DEBUG
,
2374 "Deauthentication frame IE(s)",
2375 data
->deauth_info
.ie
,
2376 data
->deauth_info
.ie_len
);
2380 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
2381 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2382 data
->deauth_info
.addr
);
2385 if (wpa_s
->ap_iface
) {
2386 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in "
2390 #endif /* CONFIG_AP */
2391 wpa_supplicant_event_disassoc(wpa_s
, reason_code
,
2393 if (reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
2394 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2395 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
2396 eapol_sm_failed(wpa_s
->eapol
)))
2397 wpas_auth_failed(wpa_s
);
2399 if (event
== EVENT_DEAUTH
&& data
) {
2400 if (wpas_p2p_deauth_notif(wpa_s
,
2401 data
->deauth_info
.addr
,
2403 data
->deauth_info
.ie
,
2404 data
->deauth_info
.ie_len
,
2405 locally_generated
) > 0) {
2407 * The interface was removed, so cannot
2408 * continue processing any additional
2409 * operations after this.
2414 #endif /* CONFIG_P2P */
2415 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
2418 case EVENT_MICHAEL_MIC_FAILURE
:
2419 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2421 #ifndef CONFIG_NO_SCAN_PROCESSING
2422 case EVENT_SCAN_RESULTS
:
2423 wpa_supplicant_event_scan_results(wpa_s
, data
);
2425 if (wpa_s
->global
->p2p_cb_on_scan_complete
&& !wpa_s
->global
->p2p_disabled
&&
2426 wpa_s
->global
->p2p
!= NULL
&&
2427 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
&&
2428 wpa_s
->wpa_state
!= WPA_ASSOCIATING
) {
2429 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
2430 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
2431 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
2432 "continued after scan result processing");
2435 #endif /* CONFIG_P2P */
2437 #endif /* CONFIG_NO_SCAN_PROCESSING */
2438 case EVENT_ASSOCINFO
:
2439 wpa_supplicant_event_associnfo(wpa_s
, data
);
2441 case EVENT_INTERFACE_STATUS
:
2442 wpa_supplicant_event_interface_status(wpa_s
, data
);
2444 case EVENT_PMKID_CANDIDATE
:
2445 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2447 #ifdef CONFIG_PEERKEY
2448 case EVENT_STKSTART
:
2449 wpa_supplicant_event_stkstart(wpa_s
, data
);
2451 #endif /* CONFIG_PEERKEY */
2454 wpa_supplicant_event_tdls(wpa_s
, data
);
2456 #endif /* CONFIG_TDLS */
2457 #ifdef CONFIG_IEEE80211V
2459 wpa_supplicant_event_wnm(wpa_s
, data
);
2461 #endif /* CONFIG_IEEE80211V */
2462 #ifdef CONFIG_IEEE80211R
2463 case EVENT_FT_RESPONSE
:
2464 wpa_supplicant_event_ft_response(wpa_s
, data
);
2466 #endif /* CONFIG_IEEE80211R */
2467 #ifdef CONFIG_IBSS_RSN
2468 case EVENT_IBSS_RSN_START
:
2469 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2471 #endif /* CONFIG_IBSS_RSN */
2472 case EVENT_ASSOC_REJECT
:
2473 if (data
->assoc_reject
.bssid
)
2474 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2475 "bssid=" MACSTR
" status_code=%u",
2476 MAC2STR(data
->assoc_reject
.bssid
),
2477 data
->assoc_reject
.status_code
);
2479 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2481 data
->assoc_reject
.status_code
);
2482 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2483 sme_event_assoc_reject(wpa_s
, data
);
2485 case EVENT_AUTH_TIMED_OUT
:
2486 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2487 sme_event_auth_timed_out(wpa_s
, data
);
2489 case EVENT_ASSOC_TIMED_OUT
:
2490 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2491 sme_event_assoc_timed_out(wpa_s
, data
);
2493 case EVENT_TX_STATUS
:
2494 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
2495 " type=%d stype=%d",
2496 MAC2STR(data
->tx_status
.dst
),
2497 data
->tx_status
.type
, data
->tx_status
.stype
);
2499 if (wpa_s
->ap_iface
== NULL
) {
2500 #ifdef CONFIG_OFFCHANNEL
2501 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2502 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
2503 offchannel_send_action_tx_status(
2504 wpa_s
, data
->tx_status
.dst
,
2505 data
->tx_status
.data
,
2506 data
->tx_status
.data_len
,
2507 data
->tx_status
.ack
?
2508 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2509 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2510 #endif /* CONFIG_OFFCHANNEL */
2513 #endif /* CONFIG_AP */
2514 #ifdef CONFIG_OFFCHANNEL
2515 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
2516 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
2518 * Catch TX status events for Action frames we sent via group
2519 * interface in GO mode.
2521 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2522 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
2523 os_memcmp(wpa_s
->parent
->pending_action_dst
,
2524 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
2525 offchannel_send_action_tx_status(
2526 wpa_s
->parent
, data
->tx_status
.dst
,
2527 data
->tx_status
.data
,
2528 data
->tx_status
.data_len
,
2529 data
->tx_status
.ack
?
2530 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2531 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2534 #endif /* CONFIG_OFFCHANNEL */
2536 switch (data
->tx_status
.type
) {
2537 case WLAN_FC_TYPE_MGMT
:
2538 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
2539 data
->tx_status
.data_len
,
2540 data
->tx_status
.stype
,
2541 data
->tx_status
.ack
);
2543 case WLAN_FC_TYPE_DATA
:
2544 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
2545 data
->tx_status
.data
,
2546 data
->tx_status
.data_len
,
2547 data
->tx_status
.ack
);
2550 #endif /* CONFIG_AP */
2553 case EVENT_EAPOL_TX_STATUS
:
2554 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
2555 data
->eapol_tx_status
.data
,
2556 data
->eapol_tx_status
.data_len
,
2557 data
->eapol_tx_status
.ack
);
2559 case EVENT_DRIVER_CLIENT_POLL_OK
:
2560 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
2562 case EVENT_RX_FROM_UNKNOWN
:
2563 if (wpa_s
->ap_iface
== NULL
)
2565 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
2566 data
->rx_from_unknown
.wds
);
2568 case EVENT_CH_SWITCH
:
2571 if (!wpa_s
->ap_iface
) {
2572 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: Ignore channel switch "
2573 "event in non-AP mode");
2578 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
2579 data
->ch_switch
.ht_enabled
,
2580 data
->ch_switch
.ch_offset
);
2581 #endif /* CONFIG_AP */
2583 case EVENT_RX_MGMT
: {
2585 const struct ieee80211_mgmt
*mgmt
;
2587 mgmt
= (const struct ieee80211_mgmt
*)
2588 data
->rx_mgmt
.frame
;
2589 fc
= le_to_host16(mgmt
->frame_control
);
2590 stype
= WLAN_FC_GET_STYPE(fc
);
2592 if (wpa_s
->ap_iface
== NULL
) {
2594 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2595 data
->rx_mgmt
.frame_len
> 24) {
2596 const u8
*src
= mgmt
->sa
;
2597 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2598 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2599 (mgmt
->u
.probe_req
.variable
-
2600 data
->rx_mgmt
.frame
);
2601 wpas_p2p_probe_req_rx(
2602 wpa_s
, src
, mgmt
->da
,
2603 mgmt
->bssid
, ie
, ie_len
,
2604 data
->rx_mgmt
.ssi_signal
);
2607 #endif /* CONFIG_P2P */
2608 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2609 "management frame in non-AP mode");
2613 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2614 data
->rx_mgmt
.frame_len
> 24) {
2615 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2616 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2617 (mgmt
->u
.probe_req
.variable
-
2618 data
->rx_mgmt
.frame
);
2620 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
2621 mgmt
->bssid
, ie
, ie_len
,
2622 data
->rx_mgmt
.ssi_signal
);
2625 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2628 #endif /* CONFIG_AP */
2629 case EVENT_RX_ACTION
:
2630 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2631 " Category=%u DataLen=%d freq=%d MHz",
2632 MAC2STR(data
->rx_action
.sa
),
2633 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2634 data
->rx_action
.freq
);
2635 #ifdef CONFIG_IEEE80211R
2636 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2637 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2638 data
->rx_action
.len
);
2641 #endif /* CONFIG_IEEE80211R */
2642 #ifdef CONFIG_IEEE80211W
2644 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2645 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2646 data
->rx_action
.data
,
2647 data
->rx_action
.len
);
2650 #endif /* CONFIG_SME */
2651 #endif /* CONFIG_IEEE80211W */
2652 #ifdef CONFIG_IEEE80211V
2653 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2654 ieee802_11_rx_wnm_action(wpa_s
, &data
->rx_action
);
2657 #endif /* CONFIG_IEEE80211V */
2659 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2660 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2661 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2662 data
->rx_action
.data
, data
->rx_action
.len
,
2663 data
->rx_action
.freq
) == 0)
2665 #endif /* CONFIG_GAS */
2666 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2667 wnm_action_rx(wpa_s
, &data
->rx_action
);
2671 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2672 data
->rx_action
.len
>= 4 &&
2673 data
->rx_action
.data
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
2674 wpa_dbg(wpa_s
, MSG_DEBUG
, "TDLS: Received Discovery "
2675 "Response from " MACSTR
,
2676 MAC2STR(data
->rx_action
.sa
));
2679 #endif /* CONFIG_TDLS */
2681 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2683 data
->rx_action
.bssid
,
2684 data
->rx_action
.category
,
2685 data
->rx_action
.data
,
2686 data
->rx_action
.len
, data
->rx_action
.freq
);
2687 #endif /* CONFIG_P2P */
2689 case EVENT_RX_PROBE_REQ
:
2690 if (data
->rx_probe_req
.sa
== NULL
||
2691 data
->rx_probe_req
.ie
== NULL
)
2694 if (wpa_s
->ap_iface
) {
2695 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2696 data
->rx_probe_req
.sa
,
2697 data
->rx_probe_req
.da
,
2698 data
->rx_probe_req
.bssid
,
2699 data
->rx_probe_req
.ie
,
2700 data
->rx_probe_req
.ie_len
,
2701 data
->rx_probe_req
.ssi_signal
);
2704 #endif /* CONFIG_AP */
2706 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2707 data
->rx_probe_req
.da
,
2708 data
->rx_probe_req
.bssid
,
2709 data
->rx_probe_req
.ie
,
2710 data
->rx_probe_req
.ie_len
,
2711 data
->rx_probe_req
.ssi_signal
);
2712 #endif /* CONFIG_P2P */
2714 case EVENT_REMAIN_ON_CHANNEL
:
2715 #ifdef CONFIG_OFFCHANNEL
2716 offchannel_remain_on_channel_cb(
2717 wpa_s
, data
->remain_on_channel
.freq
,
2718 data
->remain_on_channel
.duration
);
2719 #endif /* CONFIG_OFFCHANNEL */
2721 wpas_p2p_remain_on_channel_cb(
2722 wpa_s
, data
->remain_on_channel
.freq
,
2723 data
->remain_on_channel
.duration
);
2724 #endif /* CONFIG_P2P */
2726 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2727 #ifdef CONFIG_OFFCHANNEL
2728 offchannel_cancel_remain_on_channel_cb(
2729 wpa_s
, data
->remain_on_channel
.freq
);
2730 #endif /* CONFIG_OFFCHANNEL */
2732 wpas_p2p_cancel_remain_on_channel_cb(
2733 wpa_s
, data
->remain_on_channel
.freq
);
2734 #endif /* CONFIG_P2P */
2737 case EVENT_P2P_DEV_FOUND
: {
2738 struct p2p_peer_info peer_info
;
2740 os_memset(&peer_info
, 0, sizeof(peer_info
));
2741 if (data
->p2p_dev_found
.dev_addr
)
2742 os_memcpy(peer_info
.p2p_device_addr
,
2743 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2744 if (data
->p2p_dev_found
.pri_dev_type
)
2745 os_memcpy(peer_info
.pri_dev_type
,
2746 data
->p2p_dev_found
.pri_dev_type
,
2747 sizeof(peer_info
.pri_dev_type
));
2748 if (data
->p2p_dev_found
.dev_name
)
2749 os_strlcpy(peer_info
.device_name
,
2750 data
->p2p_dev_found
.dev_name
,
2751 sizeof(peer_info
.device_name
));
2752 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2753 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2754 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2757 * FIX: new_device=1 is not necessarily correct. We should
2758 * maintain a P2P peer database in wpa_supplicant and update
2759 * this information based on whether the peer is truly new.
2761 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2764 case EVENT_P2P_GO_NEG_REQ_RX
:
2765 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2766 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2768 case EVENT_P2P_GO_NEG_COMPLETED
:
2769 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2771 case EVENT_P2P_PROV_DISC_REQUEST
:
2772 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2773 data
->p2p_prov_disc_req
.config_methods
,
2774 data
->p2p_prov_disc_req
.dev_addr
,
2775 data
->p2p_prov_disc_req
.pri_dev_type
,
2776 data
->p2p_prov_disc_req
.dev_name
,
2777 data
->p2p_prov_disc_req
.supp_config_methods
,
2778 data
->p2p_prov_disc_req
.dev_capab
,
2779 data
->p2p_prov_disc_req
.group_capab
,
2782 case EVENT_P2P_PROV_DISC_RESPONSE
:
2783 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2784 data
->p2p_prov_disc_resp
.config_methods
);
2786 case EVENT_P2P_SD_REQUEST
:
2787 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2788 data
->p2p_sd_req
.sa
,
2789 data
->p2p_sd_req
.dialog_token
,
2790 data
->p2p_sd_req
.update_indic
,
2791 data
->p2p_sd_req
.tlvs
,
2792 data
->p2p_sd_req
.tlvs_len
);
2794 case EVENT_P2P_SD_RESPONSE
:
2795 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2796 data
->p2p_sd_resp
.update_indic
,
2797 data
->p2p_sd_resp
.tlvs
,
2798 data
->p2p_sd_resp
.tlvs_len
);
2800 #endif /* CONFIG_P2P */
2801 case EVENT_EAPOL_RX
:
2802 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2803 data
->eapol_rx
.data
,
2804 data
->eapol_rx
.data_len
);
2806 case EVENT_SIGNAL_CHANGE
:
2807 bgscan_notify_signal_change(
2808 wpa_s
, data
->signal_change
.above_threshold
,
2809 data
->signal_change
.current_signal
,
2810 data
->signal_change
.current_noise
,
2811 data
->signal_change
.current_txrate
);
2813 case EVENT_INTERFACE_ENABLED
:
2814 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2815 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2816 wpa_supplicant_update_mac_addr(wpa_s
);
2818 if (!wpa_s
->ap_iface
) {
2819 wpa_supplicant_set_state(wpa_s
,
2821 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2823 wpa_supplicant_set_state(wpa_s
,
2825 #else /* CONFIG_AP */
2826 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2827 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2828 #endif /* CONFIG_AP */
2831 case EVENT_INTERFACE_DISABLED
:
2832 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2833 wpa_supplicant_mark_disassoc(wpa_s
);
2834 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2836 case EVENT_CHANNEL_LIST_CHANGED
:
2837 if (wpa_s
->drv_priv
== NULL
)
2838 break; /* Ignore event during drv initialization */
2840 free_hw_features(wpa_s
);
2841 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(
2842 wpa_s
, &wpa_s
->hw
.num_modes
, &wpa_s
->hw
.flags
);
2845 wpas_p2p_update_channel_list(wpa_s
);
2846 #endif /* CONFIG_P2P */
2848 case EVENT_INTERFACE_UNAVAILABLE
:
2850 wpas_p2p_interface_unavailable(wpa_s
);
2851 #endif /* CONFIG_P2P */
2853 case EVENT_BEST_CHANNEL
:
2854 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2856 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2857 data
->best_chan
.freq_overall
);
2858 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2859 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2860 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2862 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2863 data
->best_chan
.freq_5
,
2864 data
->best_chan
.freq_overall
);
2865 #endif /* CONFIG_P2P */
2867 case EVENT_UNPROT_DEAUTH
:
2868 wpa_supplicant_event_unprot_deauth(wpa_s
,
2869 &data
->unprot_deauth
);
2871 case EVENT_UNPROT_DISASSOC
:
2872 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2873 &data
->unprot_disassoc
);
2875 case EVENT_STATION_LOW_ACK
:
2877 if (wpa_s
->ap_iface
&& data
)
2878 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2879 data
->low_ack
.addr
);
2880 #endif /* CONFIG_AP */
2883 wpa_tdls_disable_link(wpa_s
->wpa
, data
->low_ack
.addr
);
2884 #endif /* CONFIG_TDLS */
2886 case EVENT_IBSS_PEER_LOST
:
2887 #ifdef CONFIG_IBSS_RSN
2888 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2889 #endif /* CONFIG_IBSS_RSN */
2891 case EVENT_DRIVER_GTK_REKEY
:
2892 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2893 wpa_s
->bssid
, ETH_ALEN
))
2897 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2898 data
->driver_gtk_rekey
.replay_ctr
);
2900 case EVENT_SCHED_SCAN_STOPPED
:
2901 wpa_s
->sched_scanning
= 0;
2902 wpa_supplicant_notify_scanning(wpa_s
, 0);
2904 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
2908 * If we timed out, start a new sched scan to continue
2909 * searching for more SSIDs.
2911 if (wpa_s
->sched_scan_timed_out
)
2912 wpa_supplicant_req_sched_scan(wpa_s
);
2914 case EVENT_WPS_BUTTON_PUSHED
:
2916 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
2917 #endif /* CONFIG_WPS */
2920 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);