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"
46 static int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
,
47 struct wpa_ssid
*ssid
)
51 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
55 if (ssid
->disabled_until
.sec
> now
.sec
)
56 return ssid
->disabled_until
.sec
- now
.sec
;
58 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
64 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
66 struct wpa_ssid
*ssid
, *old_ssid
;
69 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
72 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
74 ssid
= wpa_supplicant_get_ssid(wpa_s
);
76 wpa_msg(wpa_s
, MSG_INFO
,
77 "No network configuration found for the current AP");
81 if (wpas_network_disabled(wpa_s
, ssid
)) {
82 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
86 res
= wpas_temp_disabled(wpa_s
, ssid
);
88 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
89 "disabled for %d second(s)", res
);
93 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
95 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
97 size_t wpa_ie_len
= sizeof(wpa_ie
);
98 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
101 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
104 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
105 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
106 old_ssid
= wpa_s
->current_ssid
;
107 wpa_s
->current_ssid
= ssid
;
108 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
109 wpa_supplicant_initiate_eapol(wpa_s
);
110 if (old_ssid
!= wpa_s
->current_ssid
)
111 wpas_notify_network_changed(wpa_s
);
117 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
119 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
121 if (wpa_s
->countermeasures
) {
122 wpa_s
->countermeasures
= 0;
123 wpa_drv_set_countermeasures(wpa_s
, 0);
124 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
125 wpa_supplicant_req_scan(wpa_s
, 0, 0);
130 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
134 wnm_bss_keep_alive_deinit(wpa_s
);
136 #ifdef CONFIG_IBSS_RSN
137 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
138 wpa_s
->ibss_rsn
= NULL
;
139 #endif /* CONFIG_IBSS_RSN */
142 wpa_supplicant_ap_deinit(wpa_s
);
143 #endif /* CONFIG_AP */
145 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
148 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
149 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
150 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
151 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
153 wpa_s
->sme
.prev_bssid_set
= 0;
154 #endif /* CONFIG_SME */
156 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
157 #endif /* CONFIG_P2P */
158 wpa_s
->current_bss
= NULL
;
159 wpa_s
->assoc_freq
= 0;
160 #ifdef CONFIG_IEEE80211R
162 if (wpa_s
->sme
.ft_ies
)
163 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
164 #endif /* CONFIG_SME */
165 #endif /* CONFIG_IEEE80211R */
168 wpas_notify_bssid_changed(wpa_s
);
170 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
171 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
172 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
173 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
174 wpa_s
->ap_ies_from_associnfo
= 0;
178 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
180 struct wpa_ie_data ie
;
184 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
188 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
189 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
190 ie
.pmkid
+ i
* PMKID_LEN
,
192 if (pmksa_set
== 0) {
193 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
198 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
199 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
203 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
204 union wpa_event_data
*data
)
207 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
211 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
212 " index=%d preauth=%d",
213 MAC2STR(data
->pmkid_candidate
.bssid
),
214 data
->pmkid_candidate
.index
,
215 data
->pmkid_candidate
.preauth
);
217 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
218 data
->pmkid_candidate
.index
,
219 data
->pmkid_candidate
.preauth
);
223 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
225 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
226 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
229 #ifdef IEEE8021X_EAPOL
230 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
231 wpa_s
->current_ssid
&&
232 !(wpa_s
->current_ssid
->eapol_flags
&
233 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
234 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
235 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
236 * plaintext or static WEP keys). */
239 #endif /* IEEE8021X_EAPOL */
246 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
247 * @wpa_s: pointer to wpa_supplicant data
248 * @ssid: Configuration data for the network
249 * Returns: 0 on success, -1 on failure
251 * This function is called when starting authentication with a network that is
252 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
254 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
255 struct wpa_ssid
*ssid
)
257 #ifdef IEEE8021X_EAPOL
259 int aka
= 0, sim
= 0, type
;
261 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
264 if (ssid
->eap
.eap_methods
== NULL
) {
268 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
269 while (eap
->vendor
!= EAP_VENDOR_IETF
||
270 eap
->method
!= EAP_TYPE_NONE
) {
271 if (eap
->vendor
== EAP_VENDOR_IETF
) {
272 if (eap
->method
== EAP_TYPE_SIM
)
274 else if (eap
->method
== EAP_TYPE_AKA
||
275 eap
->method
== EAP_TYPE_AKA_PRIME
)
282 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
284 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
285 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
290 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
291 "use SIM, but neither EAP-SIM nor EAP-AKA are "
296 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
297 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
299 type
= SCARD_TRY_BOTH
;
301 type
= SCARD_USIM_ONLY
;
303 type
= SCARD_GSM_SIM_ONLY
;
305 wpa_s
->scard
= scard_init(type
, NULL
);
306 if (wpa_s
->scard
== NULL
) {
307 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
311 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
312 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
313 #endif /* PCSC_FUNCS */
314 #endif /* IEEE8021X_EAPOL */
320 #ifndef CONFIG_NO_SCAN_PROCESSING
321 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
322 struct wpa_ssid
*ssid
)
326 if (ssid
->mixed_cell
)
330 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
332 #endif /* CONFIG_WPS */
334 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
335 if (ssid
->wep_key_len
[i
]) {
340 #ifdef IEEE8021X_EAPOL
341 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
342 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
343 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
345 #endif /* IEEE8021X_EAPOL */
347 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
350 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
356 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
357 struct wpa_ssid
*ssid
,
358 struct wpa_scan_res
*bss
)
360 struct wpa_ie_data ie
;
362 const u8
*rsn_ie
, *wpa_ie
;
366 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
370 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
371 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
372 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
373 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
374 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
376 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
377 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
380 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
381 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
387 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
389 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
394 if (!(ie
.proto
& ssid
->proto
)) {
395 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
400 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
401 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
406 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
407 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
412 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
413 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
418 #ifdef CONFIG_IEEE80211W
419 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
420 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
421 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
425 #endif /* CONFIG_IEEE80211W */
427 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
431 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
432 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
435 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
436 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
442 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
444 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
449 if (!(ie
.proto
& ssid
->proto
)) {
450 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
455 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
456 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
461 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
462 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
467 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
468 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
473 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
477 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
479 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow for non-WPA IEEE 802.1X");
483 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
484 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
485 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
489 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
490 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
494 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
501 static int freq_allowed(int *freqs
, int freq
)
508 for (i
= 0; freqs
[i
]; i
++)
509 if (freqs
[i
] == freq
)
515 static int ht_supported(const struct hostapd_hw_modes
*mode
)
517 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
519 * The driver did not indicate whether it supports HT. Assume
520 * it does to avoid connection issues.
526 * IEEE Std 802.11n-2009 20.1.1:
527 * An HT non-AP STA shall support all EQM rates for one spatial stream.
529 return mode
->mcs_set
[0] == 0xff;
533 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_scan_res
*bss
)
535 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
536 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
541 return 1; /* Cannot do matching without knowing band */
543 modes
= wpa_s
->hw
.modes
;
546 * The driver does not provide any additional information
547 * about the utilized hardware, so allow the connection attempt
553 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
554 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
555 int freq
= modes
[i
].channels
[j
].freq
;
556 if (freq
== bss
->freq
) {
558 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
559 break; /* do not allow 802.11b replace
570 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
571 rate_ie
= wpa_scan_get_ie(bss
, scan_ie
[i
]);
575 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
576 int flagged
= !!(rate_ie
[j
] & 0x80);
577 int r
= (rate_ie
[j
] & 0x7f) * 5;
580 * IEEE Std 802.11n-2009 7.3.2.2:
581 * The new BSS Membership selector value is encoded
582 * like a legacy basic rate, but it is not a rate and
583 * only indicates if the BSS members are required to
584 * support the mandatory features of Clause 20 [HT PHY]
585 * in order to join the BSS.
587 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
588 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
589 if (!ht_supported(mode
)) {
590 wpa_dbg(wpa_s
, MSG_DEBUG
,
591 " hardware does not support "
601 /* check for legacy basic rates */
602 for (k
= 0; k
< mode
->num_rates
; k
++) {
603 if (mode
->rates
[k
] == r
)
606 if (k
== mode
->num_rates
) {
608 * IEEE Std 802.11-2007 7.3.2.2 demands that in
609 * order to join a BSS all required rates
610 * have to be supported by the hardware.
612 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
613 "not support required rate %d.%d Mbps",
624 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
625 int i
, struct wpa_scan_res
*bss
,
626 struct wpa_ssid
*group
)
629 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
631 struct wpa_blacklist
*e
;
633 struct wpa_ssid
*ssid
;
635 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
636 ssid_
= ie
? ie
+ 2 : (u8
*) "";
637 ssid_len
= ie
? ie
[1] : 0;
639 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
640 wpa_ie_len
= ie
? ie
[1] : 0;
642 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
643 rsn_ie_len
= ie
? ie
[1] : 0;
645 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
646 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
647 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
648 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
649 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
651 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
654 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
656 * When only a single network is enabled, we can
657 * trigger blacklisting on the first failure. This
658 * should not be done with multiple enabled networks to
659 * avoid getting forced to move into a worse ESS on
660 * single error if there are no other BSSes of the
665 if (e
->count
> limit
) {
666 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
667 "(count=%d limit=%d)", e
->count
, limit
);
673 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
677 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
679 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
680 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
683 if (wpas_network_disabled(wpa_s
, ssid
)) {
684 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
688 res
= wpas_temp_disabled(wpa_s
, ssid
);
690 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled "
691 "temporarily for %d second(s)", res
);
696 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
697 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
702 if (wpa
&& ssid
->ssid_len
== 0 &&
703 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
706 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
707 /* Only allow wildcard SSID match if an AP
708 * advertises active WPS operation that matches
711 if (ssid
->ssid_len
== 0 &&
712 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
715 #endif /* CONFIG_WPS */
717 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
718 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
722 (ssid_len
!= ssid
->ssid_len
||
723 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
724 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
728 if (ssid
->bssid_set
&&
729 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
730 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
734 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
738 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
739 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
740 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
741 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
746 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
747 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
752 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
753 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
758 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
759 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
764 if (!rate_match(wpa_s
, bss
)) {
765 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
772 * TODO: skip the AP if its P2P IE has Group Formation
773 * bit set in the P2P Group Capability Bitmap and we
774 * are not in Group Formation with that device.
776 #endif /* CONFIG_P2P */
778 /* Matching configuration found */
782 /* No matching configuration found */
787 static struct wpa_bss
*
788 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
789 struct wpa_scan_results
*scan_res
,
790 struct wpa_ssid
*group
,
791 struct wpa_ssid
**selected_ssid
)
795 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
798 for (i
= 0; i
< scan_res
->num
; i
++) {
799 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
803 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
807 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
808 ssid
= ie
? ie
+ 2 : (u8
*) "";
809 ssid_len
= ie
? ie
[1] : 0;
811 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
813 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
814 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
821 static struct wpa_bss
*
822 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
823 struct wpa_scan_results
*scan_res
,
824 struct wpa_ssid
**selected_ssid
)
826 struct wpa_bss
*selected
= NULL
;
829 while (selected
== NULL
) {
830 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
831 selected
= wpa_supplicant_select_bss(
832 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
838 if (selected
== NULL
&& wpa_s
->blacklist
&&
839 !wpa_s
->countermeasures
) {
840 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
841 "blacklist and try again");
842 wpa_blacklist_clear(wpa_s
);
843 wpa_s
->blacklist_cleared
++;
844 } else if (selected
== NULL
)
852 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
853 int timeout_sec
, int timeout_usec
)
855 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
857 * No networks are enabled; short-circuit request so
858 * we don't wait timeout seconds before transitioning
861 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
864 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
868 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
869 struct wpa_bss
*selected
,
870 struct wpa_ssid
*ssid
)
872 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
873 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
874 "PBC session overlap");
876 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
878 #endif /* CONFIG_P2P */
881 wpas_wps_cancel(wpa_s
);
882 #endif /* CONFIG_WPS */
887 * Do not trigger new association unless the BSSID has changed or if
888 * reassociation is requested. If we are in process of associating with
889 * the selected BSSID, do not trigger new attempt.
891 if (wpa_s
->reassociate
||
892 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
893 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
894 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
895 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
897 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
898 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
901 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
902 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
903 " pending: " MACSTR
" wpa_state: %s",
904 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
905 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
906 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
907 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
909 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
917 static struct wpa_ssid
*
918 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
921 struct wpa_ssid
*ssid
;
923 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
924 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
926 if (wpas_network_disabled(wpa_s
, ssid
))
928 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
929 ssid
->mode
== IEEE80211_MODE_AP
)
937 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
938 * on BSS added and BSS changed events */
939 static void wpa_supplicant_rsn_preauth_scan_results(
940 struct wpa_supplicant
*wpa_s
)
944 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
947 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
948 const u8
*ssid
, *rsn
;
950 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
954 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
958 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
964 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
965 struct wpa_bss
*selected
,
966 struct wpa_ssid
*ssid
,
967 struct wpa_scan_results
*scan_res
)
970 struct wpa_scan_res
*current_bss
= NULL
;
973 if (wpa_s
->reassociate
)
974 return 1; /* explicit request to reassociate */
975 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
976 return 1; /* we are not associated; continue */
977 if (wpa_s
->current_ssid
== NULL
)
978 return 1; /* unknown current SSID */
979 if (wpa_s
->current_ssid
!= ssid
)
980 return 1; /* different network block */
982 if (wpas_driver_bss_selection(wpa_s
))
983 return 0; /* Driver-based roaming */
985 for (i
= 0; i
< scan_res
->num
; i
++) {
986 struct wpa_scan_res
*res
= scan_res
->res
[i
];
988 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
991 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
994 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
995 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
1002 return 1; /* current BSS not seen in scan results */
1004 #ifndef CONFIG_NO_ROAMING
1005 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1006 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
1007 MAC2STR(current_bss
->bssid
), current_bss
->level
);
1008 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
1009 MAC2STR(selected
->bssid
), selected
->level
);
1011 if (wpa_s
->current_ssid
->bssid_set
&&
1012 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1014 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1015 "has preferred BSSID");
1020 if (current_bss
->level
< 0) {
1021 if (current_bss
->level
< -85)
1023 else if (current_bss
->level
< -80)
1025 else if (current_bss
->level
< -75)
1027 else if (current_bss
->level
< -70)
1032 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
1033 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
1039 #else /* CONFIG_NO_ROAMING */
1041 #endif /* CONFIG_NO_ROAMING */
1045 /* Return < 0 if no scan results could be fetched or if scan results should not
1046 * be shared with other virtual interfaces. */
1047 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1048 union wpa_event_data
*data
)
1050 struct wpa_bss
*selected
;
1051 struct wpa_ssid
*ssid
= NULL
;
1052 struct wpa_scan_results
*scan_res
;
1056 if (wpa_s
->ap_iface
)
1058 #endif /* CONFIG_AP */
1060 wpa_supplicant_notify_scanning(wpa_s
, 0);
1063 if (wpa_s
->p2p_cb_on_scan_complete
&& !wpa_s
->global
->p2p_disabled
&&
1064 wpa_s
->global
->p2p
!= NULL
&& !wpa_s
->sta_scan_pending
) {
1065 wpa_s
->p2p_cb_on_scan_complete
= 0;
1066 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
1067 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
1068 "stopped scan processing");
1072 wpa_s
->sta_scan_pending
= 0;
1073 #endif /* CONFIG_P2P */
1075 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1076 data
? &data
->scan_info
:
1078 if (scan_res
== NULL
) {
1079 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
1081 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1083 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1087 #ifndef CONFIG_NO_RANDOM_POOL
1089 num
= scan_res
->num
;
1092 for (i
= 0; i
< num
; i
++) {
1094 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1095 buf
[0] = res
->bssid
[5];
1096 buf
[1] = res
->qual
& 0xff;
1097 buf
[2] = res
->noise
& 0xff;
1098 buf
[3] = res
->level
& 0xff;
1099 buf
[4] = res
->tsf
& 0xff;
1100 random_add_randomness(buf
, sizeof(buf
));
1102 #endif /* CONFIG_NO_RANDOM_POOL */
1104 if (wpa_s
->scan_res_handler
) {
1105 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1106 struct wpa_scan_results
*scan_res
);
1108 scan_res_handler
= wpa_s
->scan_res_handler
;
1109 wpa_s
->scan_res_handler
= NULL
;
1110 scan_res_handler(wpa_s
, scan_res
);
1112 wpa_scan_results_free(scan_res
);
1117 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1119 if (wpa_s
->ap_iface
->scan_cb
)
1120 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1121 #endif /* CONFIG_AP */
1122 wpa_scan_results_free(scan_res
);
1126 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
1127 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1128 wpas_notify_scan_results(wpa_s
);
1130 wpas_notify_scan_done(wpa_s
, 1);
1132 if (sme_proc_obss_scan(wpa_s
) > 0) {
1133 wpa_scan_results_free(scan_res
);
1137 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
1138 wpa_scan_results_free(scan_res
);
1142 if (autoscan_notify_scan(wpa_s
, scan_res
)) {
1143 wpa_scan_results_free(scan_res
);
1147 if (wpa_s
->disconnected
) {
1148 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1149 wpa_scan_results_free(scan_res
);
1153 if (!wpas_driver_bss_selection(wpa_s
) &&
1154 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
1155 wpa_scan_results_free(scan_res
);
1159 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
1163 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
1165 wpa_scan_results_free(scan_res
);
1167 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1171 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1172 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1175 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1177 wpa_scan_results_free(scan_res
);
1178 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1179 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1181 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1182 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1183 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1185 int timeout_sec
= wpa_s
->scan_interval
;
1186 int timeout_usec
= 0;
1188 if (wpas_p2p_scan_no_go_seen(wpa_s
) == 1)
1191 if (wpa_s
->p2p_in_provisioning
) {
1193 * Use shorter wait during P2P Provisioning
1194 * state to speed up group formation.
1197 timeout_usec
= 250000;
1198 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1202 #endif /* CONFIG_P2P */
1203 if (wpa_supplicant_req_sched_scan(wpa_s
))
1204 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1212 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1213 union wpa_event_data
*data
)
1215 const char *rn
, *rn2
;
1216 struct wpa_supplicant
*ifs
;
1218 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1220 * If no scan results could be fetched, then no need to
1221 * notify those interfaces that did not actually request
1228 * Check other interfaces to see if they have the same radio-name. If
1229 * so, they get updated with this same scan info.
1231 if (!wpa_s
->driver
->get_radio_name
)
1234 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1235 if (rn
== NULL
|| rn
[0] == '\0')
1238 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1239 "sharing same radio (%s) in event_scan_results", rn
);
1241 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1242 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1245 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1246 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1247 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1248 "sibling", ifs
->ifname
);
1249 _wpa_supplicant_event_scan_results(ifs
, data
);
1254 #endif /* CONFIG_NO_SCAN_PROCESSING */
1259 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1261 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1263 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1266 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1267 MAC2STR(wpa_s
->bssid
));
1268 /* TODO: could skip this if normal data traffic has been sent */
1269 /* TODO: Consider using some more appropriate data frame for this */
1271 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800, (u8
*) "", 0);
1274 if (wpa_s
->sme
.bss_max_idle_period
) {
1276 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
1279 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1280 wnm_bss_keep_alive
, wpa_s
, NULL
);
1282 #endif /* CONFIG_SME */
1286 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1287 const u8
*ies
, size_t ies_len
)
1289 struct ieee802_11_elems elems
;
1294 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1298 if (elems
.bss_max_idle_period
) {
1300 wpa_s
->sme
.bss_max_idle_period
=
1301 WPA_GET_LE16(elems
.bss_max_idle_period
);
1302 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
1303 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
1304 (elems
.bss_max_idle_period
[2] & 0x01) ?
1305 " (protected keep-live required)" : "");
1306 if (wpa_s
->sme
.bss_max_idle_period
== 0)
1307 wpa_s
->sme
.bss_max_idle_period
= 1;
1308 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
1309 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1310 /* msec times 1000 */
1311 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
1314 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1315 wnm_bss_keep_alive
, wpa_s
,
1319 #endif /* CONFIG_SME */
1322 #endif /* CONFIG_WNM */
1325 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
1328 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1329 #endif /* CONFIG_WNM */
1333 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1334 union wpa_event_data
*data
)
1336 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1339 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1340 if (data
->assoc_info
.req_ies
)
1341 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1342 data
->assoc_info
.req_ies_len
);
1343 if (data
->assoc_info
.resp_ies
) {
1344 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1345 data
->assoc_info
.resp_ies_len
);
1347 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1348 data
->assoc_info
.resp_ies_len
);
1349 #endif /* CONFIG_TDLS */
1351 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1352 data
->assoc_info
.resp_ies_len
);
1353 #endif /* CONFIG_WNM */
1355 if (data
->assoc_info
.beacon_ies
)
1356 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1357 data
->assoc_info
.beacon_ies
,
1358 data
->assoc_info
.beacon_ies_len
);
1359 if (data
->assoc_info
.freq
)
1360 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1361 data
->assoc_info
.freq
);
1363 p
= data
->assoc_info
.req_ies
;
1364 l
= data
->assoc_info
.req_ies_len
;
1366 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1367 while (p
&& l
>= 2) {
1370 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1374 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1375 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1376 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1377 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1380 wpa_find_assoc_pmkid(wpa_s
);
1386 if (!found
&& data
->assoc_info
.req_ies
)
1387 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1389 #ifdef CONFIG_IEEE80211R
1391 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1393 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1394 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1395 data
->assoc_info
.resp_ies
,
1396 data
->assoc_info
.resp_ies_len
,
1398 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1399 "Reassociation Response failed");
1400 wpa_supplicant_deauthenticate(
1401 wpa_s
, WLAN_REASON_INVALID_IE
);
1406 p
= data
->assoc_info
.resp_ies
;
1407 l
= data
->assoc_info
.resp_ies_len
;
1409 #ifdef CONFIG_WPS_STRICT
1410 if (p
&& wpa_s
->current_ssid
&&
1411 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1413 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1415 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1416 "include WPS IE in (Re)Association Response");
1420 if (wps_validate_assoc_resp(wps
) < 0) {
1422 wpa_supplicant_deauthenticate(
1423 wpa_s
, WLAN_REASON_INVALID_IE
);
1428 #endif /* CONFIG_WPS_STRICT */
1430 /* Go through the IEs and make a copy of the MDIE, if present. */
1431 while (p
&& l
>= 2) {
1434 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1438 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1439 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1440 wpa_s
->sme
.ft_used
= 1;
1441 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1442 MOBILITY_DOMAIN_ID_LEN
);
1448 #endif /* CONFIG_SME */
1450 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1451 data
->assoc_info
.resp_ies_len
);
1452 #endif /* CONFIG_IEEE80211R */
1454 /* WPA/RSN IE from Beacon/ProbeResp */
1455 p
= data
->assoc_info
.beacon_ies
;
1456 l
= data
->assoc_info
.beacon_ies_len
;
1458 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1460 wpa_found
= rsn_found
= 0;
1461 while (p
&& l
>= 2) {
1464 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1469 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1470 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1472 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1476 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1478 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1485 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1486 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1487 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1488 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1489 if (wpa_found
|| rsn_found
)
1490 wpa_s
->ap_ies_from_associnfo
= 1;
1492 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1493 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1494 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1496 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1497 wpa_supplicant_update_scan_results(wpa_s
);
1500 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1506 static struct wpa_bss
* wpa_supplicant_get_new_bss(
1507 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
1509 struct wpa_bss
*bss
= NULL
;
1510 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1512 if (ssid
->ssid_len
> 0)
1513 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
1515 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1521 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
1523 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
1525 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
1528 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
1531 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1532 WPA_IE_VENDOR_TYPE
);
1533 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
1535 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1536 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1537 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1538 bss_rsn
? 2 + bss_rsn
[1] : 0))
1545 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1546 union wpa_event_data
*data
)
1550 struct wpa_driver_capa capa
;
1553 if (wpa_s
->ap_iface
) {
1554 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1555 data
->assoc_info
.addr
,
1556 data
->assoc_info
.req_ies
,
1557 data
->assoc_info
.req_ies_len
,
1558 data
->assoc_info
.reassoc
);
1561 #endif /* CONFIG_AP */
1563 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1564 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1567 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1568 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
1569 wpa_supplicant_disassociate(
1570 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1574 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1575 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1576 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1577 MACSTR
, MAC2STR(bssid
));
1578 random_add_randomness(bssid
, ETH_ALEN
);
1579 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1580 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1581 wpas_notify_bssid_changed(wpa_s
);
1583 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1584 wpa_clear_keys(wpa_s
, bssid
);
1586 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1587 wpa_supplicant_disassociate(
1588 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1591 if (wpa_s
->current_ssid
) {
1592 struct wpa_bss
*bss
= NULL
;
1594 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
1596 wpa_supplicant_update_scan_results(wpa_s
);
1598 /* Get the BSS from the new scan results */
1599 bss
= wpa_supplicant_get_new_bss(wpa_s
, bssid
);
1603 wpa_s
->current_bss
= bss
;
1606 if (wpa_s
->conf
->ap_scan
== 1 &&
1607 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
1608 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0)
1609 wpa_msg(wpa_s
, MSG_WARNING
,
1610 "WPA/RSN IEs not updated");
1615 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1616 wpa_s
->sme
.prev_bssid_set
= 1;
1617 #endif /* CONFIG_SME */
1619 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1620 if (wpa_s
->current_ssid
) {
1621 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1622 * initialized before association, but for other modes,
1623 * initialize PC/SC here, if the current configuration needs
1624 * smartcard or SIM/USIM. */
1625 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1627 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1629 l2_packet_notify_auth_start(wpa_s
->l2
);
1632 * Set portEnabled first to FALSE in order to get EAP state machine out
1633 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1634 * state machine may transit to AUTHENTICATING state based on obsolete
1635 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1636 * AUTHENTICATED without ever giving chance to EAP state machine to
1639 if (!ft_completed
) {
1640 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1641 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1643 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1644 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1645 /* 802.1X::portControl = Auto */
1646 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1647 wpa_s
->eapol_received
= 0;
1648 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1649 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1650 (wpa_s
->current_ssid
&&
1651 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1652 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1653 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1654 } else if (!ft_completed
) {
1655 /* Timeout for receiving the first EAPOL packet */
1656 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1658 wpa_supplicant_cancel_scan(wpa_s
);
1660 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1661 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1663 * We are done; the driver will take care of RSN 4-way
1666 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1667 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1668 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1669 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1670 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1671 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1673 * The driver will take care of RSN 4-way handshake, so we need
1674 * to allow EAPOL supplicant to complete its work without
1675 * waiting for WPA supplicant.
1677 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1678 } else if (ft_completed
) {
1680 * FT protocol completed - make sure EAPOL state machine ends
1681 * up in authenticated.
1683 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1684 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1685 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1686 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1689 if (wpa_s
->pending_eapol_rx
) {
1690 struct os_time now
, age
;
1692 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1693 if (age
.sec
== 0 && age
.usec
< 100000 &&
1694 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1696 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1697 "frame that was received just before "
1698 "association notification");
1699 wpa_supplicant_rx_eapol(
1700 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1701 wpabuf_head(wpa_s
->pending_eapol_rx
),
1702 wpabuf_len(wpa_s
->pending_eapol_rx
));
1704 wpabuf_free(wpa_s
->pending_eapol_rx
);
1705 wpa_s
->pending_eapol_rx
= NULL
;
1708 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1709 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1710 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1711 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1712 /* Set static WEP keys again */
1713 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1716 #ifdef CONFIG_IBSS_RSN
1717 if (wpa_s
->current_ssid
&&
1718 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1719 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1720 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1721 wpa_s
->ibss_rsn
== NULL
) {
1722 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1723 if (!wpa_s
->ibss_rsn
) {
1724 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1725 wpa_supplicant_deauthenticate(
1726 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1730 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1732 #endif /* CONFIG_IBSS_RSN */
1736 static int disconnect_reason_recoverable(u16 reason_code
)
1738 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
1739 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
1740 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
1744 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1746 int locally_generated
)
1750 u8 prev_pending_bssid
[ETH_ALEN
];
1751 struct wpa_bss
*fast_reconnect
= NULL
;
1752 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
1754 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1755 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1757 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1759 * At least Host AP driver and a Prism3 card seemed to be
1760 * generating streams of disconnected events when configuring
1761 * IBSS for WPA-None. Ignore them for now.
1763 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1764 "IBSS/WPA-None mode");
1768 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1769 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1770 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1771 "pre-shared key may be incorrect");
1772 wpas_auth_failed(wpa_s
);
1774 if (!wpa_s
->auto_reconnect_disabled
||
1775 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1776 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
1777 "reconnect (wps=%d wpa_state=%d)",
1778 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
1780 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
1781 wpa_s
->current_ssid
&&
1782 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
1783 !locally_generated
&&
1784 disconnect_reason_recoverable(reason_code
)) {
1786 * It looks like the AP has dropped association with
1787 * us, but could allow us to get back in. Try to
1788 * reconnect to the same BSS without full scan to save
1789 * time for some common cases.
1791 fast_reconnect
= wpa_s
->current_bss
;
1792 fast_reconnect_ssid
= wpa_s
->current_ssid
;
1793 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1794 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1796 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
1799 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
1800 "try to re-connect");
1801 wpa_s
->reassociate
= 0;
1802 wpa_s
->disconnected
= 1;
1803 wpa_supplicant_cancel_sched_scan(wpa_s
);
1805 bssid
= wpa_s
->bssid
;
1806 if (is_zero_ether_addr(bssid
))
1807 bssid
= wpa_s
->pending_bssid
;
1808 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
1809 wpas_connection_failed(wpa_s
, bssid
);
1810 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1811 if (locally_generated
)
1812 wpa_s
->disconnect_reason
= -reason_code
;
1814 wpa_s
->disconnect_reason
= reason_code
;
1815 wpas_notify_disconnect_reason(wpa_s
);
1816 if (!is_zero_ether_addr(bssid
) ||
1817 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1818 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1820 MAC2STR(bssid
), reason_code
,
1821 locally_generated
? " locally_generated=1" : "");
1823 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1824 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1825 wpa_s
->keys_cleared
= 0;
1826 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1828 wpa_supplicant_mark_disassoc(wpa_s
);
1830 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1831 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1833 if (fast_reconnect
) {
1834 #ifndef CONFIG_NO_SCAN_PROCESSING
1835 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
1836 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
1837 fast_reconnect_ssid
) < 0) {
1838 /* Recover through full scan */
1839 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1841 #endif /* CONFIG_NO_SCAN_PROCESSING */
1846 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1847 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
1849 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1851 if (!wpa_s
->pending_mic_error_report
)
1854 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1855 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1856 wpa_s
->pending_mic_error_report
= 0;
1858 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1862 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1863 union wpa_event_data
*data
)
1868 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1869 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1871 if ((wpa_s
->last_michael_mic_error
&&
1872 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1873 wpa_s
->pending_mic_error_report
) {
1874 if (wpa_s
->pending_mic_error_report
) {
1876 * Send the pending MIC error report immediately since
1877 * we are going to start countermeasures and AP better
1880 wpa_sm_key_request(wpa_s
->wpa
, 1,
1881 wpa_s
->pending_mic_error_pairwise
);
1884 /* Send the new MIC error report immediately since we are going
1885 * to start countermeasures and AP better do the same.
1887 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1889 /* initialize countermeasures */
1890 wpa_s
->countermeasures
= 1;
1892 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
1894 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1897 * Need to wait for completion of request frame. We do not get
1898 * any callback for the message completion, so just wait a
1899 * short while and hope for the best. */
1902 wpa_drv_set_countermeasures(wpa_s
, 1);
1903 wpa_supplicant_deauthenticate(wpa_s
,
1904 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1905 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1907 eloop_register_timeout(60, 0,
1908 wpa_supplicant_stop_countermeasures
,
1910 /* TODO: mark the AP rejected for 60 second. STA is
1911 * allowed to associate with another AP.. */
1913 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1914 if (wpa_s
->mic_errors_seen
) {
1916 * Reduce the effectiveness of Michael MIC error
1917 * reports as a means for attacking against TKIP if
1918 * more than one MIC failure is noticed with the same
1919 * PTK. We delay the transmission of the reports by a
1920 * random time between 0 and 60 seconds in order to
1921 * force the attacker wait 60 seconds before getting
1922 * the information on whether a frame resulted in a MIC
1928 if (os_get_random(rval
, sizeof(rval
)) < 0)
1929 sec
= os_random() % 60;
1931 sec
= WPA_GET_BE32(rval
) % 60;
1932 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1933 "report %d seconds", sec
);
1934 wpa_s
->pending_mic_error_report
= 1;
1935 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1936 eloop_cancel_timeout(
1937 wpa_supplicant_delayed_mic_error_report
,
1939 eloop_register_timeout(
1940 sec
, os_random() % 1000000,
1941 wpa_supplicant_delayed_mic_error_report
,
1944 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1946 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1947 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1948 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1950 wpa_s
->last_michael_mic_error
= t
.sec
;
1951 wpa_s
->mic_errors_seen
++;
1955 #ifdef CONFIG_TERMINATE_ONLASTIF
1956 static int any_interfaces(struct wpa_supplicant
*head
)
1958 struct wpa_supplicant
*wpa_s
;
1960 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1961 if (!wpa_s
->interface_removed
)
1965 #endif /* CONFIG_TERMINATE_ONLASTIF */
1969 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1970 union wpa_event_data
*data
)
1972 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1975 switch (data
->interface_status
.ievent
) {
1976 case EVENT_INTERFACE_ADDED
:
1977 if (!wpa_s
->interface_removed
)
1979 wpa_s
->interface_removed
= 0;
1980 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1981 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1982 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1983 "driver after interface was added");
1985 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1987 case EVENT_INTERFACE_REMOVED
:
1988 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1989 wpa_s
->interface_removed
= 1;
1990 wpa_supplicant_mark_disassoc(wpa_s
);
1991 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
1992 l2_packet_deinit(wpa_s
->l2
);
1994 #ifdef CONFIG_IBSS_RSN
1995 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1996 wpa_s
->ibss_rsn
= NULL
;
1997 #endif /* CONFIG_IBSS_RSN */
1998 #ifdef CONFIG_TERMINATE_ONLASTIF
1999 /* check if last interface */
2000 if (!any_interfaces(wpa_s
->global
->ifaces
))
2002 #endif /* CONFIG_TERMINATE_ONLASTIF */
2008 #ifdef CONFIG_PEERKEY
2010 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
2011 union wpa_event_data
*data
)
2015 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
2017 #endif /* CONFIG_PEERKEY */
2021 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
2022 union wpa_event_data
*data
)
2026 switch (data
->tdls
.oper
) {
2027 case TDLS_REQUEST_SETUP
:
2028 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
2030 case TDLS_REQUEST_TEARDOWN
:
2031 wpa_tdls_send_teardown(wpa_s
->wpa
, data
->tdls
.peer
,
2032 data
->tdls
.reason_code
);
2036 #endif /* CONFIG_TDLS */
2039 #ifdef CONFIG_IEEE80211V
2040 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
2041 union wpa_event_data
*data
)
2045 switch (data
->wnm
.oper
) {
2046 case WNM_OPER_SLEEP
:
2047 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
2048 "(action=%d, intval=%d)",
2049 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
2050 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
2051 data
->wnm
.sleep_intval
);
2055 #endif /* CONFIG_IEEE80211V */
2058 #ifdef CONFIG_IEEE80211R
2060 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
2061 union wpa_event_data
*data
)
2066 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
2067 data
->ft_ies
.ies_len
,
2068 data
->ft_ies
.ft_action
,
2069 data
->ft_ies
.target_ap
,
2070 data
->ft_ies
.ric_ies
,
2071 data
->ft_ies
.ric_ies_len
) < 0) {
2072 /* TODO: prevent MLME/driver from trying to associate? */
2075 #endif /* CONFIG_IEEE80211R */
2078 #ifdef CONFIG_IBSS_RSN
2079 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
2080 union wpa_event_data
*data
)
2082 struct wpa_ssid
*ssid
;
2083 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2087 ssid
= wpa_s
->current_ssid
;
2090 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2093 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
2095 #endif /* CONFIG_IBSS_RSN */
2098 #ifdef CONFIG_IEEE80211R
2099 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
2102 const u8
*sta_addr
, *target_ap_addr
;
2105 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
2106 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2107 return; /* only SME case supported for now */
2108 if (len
< 1 + 2 * ETH_ALEN
+ 2)
2111 return; /* Only FT Action Response is supported for now */
2112 sta_addr
= data
+ 1;
2113 target_ap_addr
= data
+ 1 + ETH_ALEN
;
2114 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
2115 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
2116 MACSTR
" TargetAP " MACSTR
" status %u",
2117 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
2119 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
2120 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
2121 " in FT Action Response", MAC2STR(sta_addr
));
2126 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
2127 "failure (status code %d)", status
);
2128 /* TODO: report error to FT code(?) */
2132 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
2133 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
2134 target_ap_addr
, NULL
, 0) < 0)
2139 struct wpa_bss
*bss
;
2140 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
2142 wpa_s
->sme
.freq
= bss
->freq
;
2143 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
2144 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
2147 #endif /* CONFIG_SME */
2149 #endif /* CONFIG_IEEE80211R */
2152 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
2153 struct unprot_deauth
*e
)
2155 #ifdef CONFIG_IEEE80211W
2156 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
2157 "dropped: " MACSTR
" -> " MACSTR
2158 " (reason code %u)",
2159 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2160 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2161 #endif /* CONFIG_IEEE80211W */
2165 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
2166 struct unprot_disassoc
*e
)
2168 #ifdef CONFIG_IEEE80211W
2169 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
2170 "dropped: " MACSTR
" -> " MACSTR
2171 " (reason code %u)",
2172 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2173 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2174 #endif /* CONFIG_IEEE80211W */
2178 static void wnm_action_rx(struct wpa_supplicant
*wpa_s
, struct rx_action
*rx
)
2181 const u8
*pos
, *end
;
2183 if (rx
->data
== NULL
|| rx
->len
== 0)
2187 end
= pos
+ rx
->len
;
2190 wpa_printf(MSG_DEBUG
, "WNM: RX action %u from " MACSTR
,
2191 action
, MAC2STR(rx
->sa
));
2193 case WNM_BSS_TRANS_MGMT_REQ
:
2196 wpa_printf(MSG_DEBUG
, "WNM: BSS Transition Management "
2197 "Request: dialog_token=%u request_mode=0x%x "
2198 "disassoc_timer=%u validity_interval=%u",
2199 pos
[0], pos
[1], WPA_GET_LE16(pos
+ 2), pos
[4]);
2203 pos
+= 12; /* BSS Termination Duration */
2206 if (pos
+ 1 > end
|| pos
+ 1 + pos
[0] > end
) {
2207 wpa_printf(MSG_DEBUG
, "WNM: Invalid BSS "
2208 "Transition Management Request "
2212 os_memcpy(url
, pos
+ 1, pos
[0]);
2214 wpa_msg(wpa_s
, MSG_INFO
, "WNM: ESS Disassociation "
2215 "Imminent - session_info_url=%s", url
);
2222 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
2223 union wpa_event_data
*data
)
2225 struct wpa_supplicant
*wpa_s
= ctx
;
2226 u16 reason_code
= 0;
2227 int locally_generated
= 0;
2229 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
2230 event
!= EVENT_INTERFACE_ENABLED
&&
2231 event
!= EVENT_INTERFACE_STATUS
&&
2232 event
!= EVENT_SCHED_SCAN_STOPPED
) {
2233 wpa_dbg(wpa_s
, MSG_DEBUG
,
2234 "Ignore event %s (%d) while interface is disabled",
2235 event_to_string(event
), event
);
2239 #ifndef CONFIG_NO_STDOUT_DEBUG
2241 int level
= MSG_DEBUG
;
2243 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
2244 const struct ieee80211_hdr
*hdr
;
2246 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
2247 fc
= le_to_host16(hdr
->frame_control
);
2248 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
2249 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
2250 level
= MSG_EXCESSIVE
;
2253 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
2254 event_to_string(event
), event
);
2256 #endif /* CONFIG_NO_STDOUT_DEBUG */
2260 sme_event_auth(wpa_s
, data
);
2263 wpa_supplicant_event_assoc(wpa_s
, data
);
2265 case EVENT_DISASSOC
:
2266 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
2268 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
2269 data
->disassoc_info
.reason_code
,
2270 data
->disassoc_info
.locally_generated
?
2271 " (locally generated)" : "");
2272 if (data
->disassoc_info
.addr
)
2273 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
2274 MAC2STR(data
->disassoc_info
.addr
));
2277 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
2278 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2279 data
->disassoc_info
.addr
);
2282 if (wpa_s
->ap_iface
) {
2283 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in "
2287 #endif /* CONFIG_AP */
2289 reason_code
= data
->disassoc_info
.reason_code
;
2291 data
->disassoc_info
.locally_generated
;
2292 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
2293 data
->disassoc_info
.ie
,
2294 data
->disassoc_info
.ie_len
);
2296 wpas_p2p_disassoc_notif(
2297 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
2298 data
->disassoc_info
.ie
,
2299 data
->disassoc_info
.ie_len
,
2301 #endif /* CONFIG_P2P */
2303 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2304 sme_event_disassoc(wpa_s
, data
);
2307 if (event
== EVENT_DEAUTH
) {
2308 wpa_dbg(wpa_s
, MSG_DEBUG
,
2309 "Deauthentication notification");
2311 reason_code
= data
->deauth_info
.reason_code
;
2313 data
->deauth_info
.locally_generated
;
2314 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
2315 data
->deauth_info
.reason_code
,
2316 data
->deauth_info
.locally_generated
?
2317 " (locally generated)" : "");
2318 if (data
->deauth_info
.addr
) {
2319 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
2321 MAC2STR(data
->deauth_info
.
2324 wpa_hexdump(MSG_DEBUG
,
2325 "Deauthentication frame IE(s)",
2326 data
->deauth_info
.ie
,
2327 data
->deauth_info
.ie_len
);
2331 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
2332 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
2333 data
->deauth_info
.addr
);
2336 if (wpa_s
->ap_iface
) {
2337 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in "
2341 #endif /* CONFIG_AP */
2342 wpa_supplicant_event_disassoc(wpa_s
, reason_code
,
2344 if (reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
2345 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2346 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
2347 eapol_sm_failed(wpa_s
->eapol
)))
2348 wpas_auth_failed(wpa_s
);
2350 if (event
== EVENT_DEAUTH
&& data
) {
2351 wpas_p2p_deauth_notif(wpa_s
, data
->deauth_info
.addr
,
2353 data
->deauth_info
.ie
,
2354 data
->deauth_info
.ie_len
,
2357 #endif /* CONFIG_P2P */
2359 case EVENT_MICHAEL_MIC_FAILURE
:
2360 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2362 #ifndef CONFIG_NO_SCAN_PROCESSING
2363 case EVENT_SCAN_RESULTS
:
2364 wpa_supplicant_event_scan_results(wpa_s
, data
);
2366 if (wpa_s
->p2p_cb_on_scan_complete
&& !wpa_s
->global
->p2p_disabled
&&
2367 wpa_s
->global
->p2p
!= NULL
&&
2368 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
&&
2369 wpa_s
->wpa_state
!= WPA_ASSOCIATING
) {
2370 wpa_s
->p2p_cb_on_scan_complete
= 0;
2371 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
2372 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
2373 "continued after scan result processing");
2376 #endif /* CONFIG_P2P */
2378 #endif /* CONFIG_NO_SCAN_PROCESSING */
2379 case EVENT_ASSOCINFO
:
2380 wpa_supplicant_event_associnfo(wpa_s
, data
);
2382 case EVENT_INTERFACE_STATUS
:
2383 wpa_supplicant_event_interface_status(wpa_s
, data
);
2385 case EVENT_PMKID_CANDIDATE
:
2386 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2388 #ifdef CONFIG_PEERKEY
2389 case EVENT_STKSTART
:
2390 wpa_supplicant_event_stkstart(wpa_s
, data
);
2392 #endif /* CONFIG_PEERKEY */
2395 wpa_supplicant_event_tdls(wpa_s
, data
);
2397 #endif /* CONFIG_TDLS */
2398 #ifdef CONFIG_IEEE80211V
2400 wpa_supplicant_event_wnm(wpa_s
, data
);
2402 #endif /* CONFIG_IEEE80211V */
2403 #ifdef CONFIG_IEEE80211R
2404 case EVENT_FT_RESPONSE
:
2405 wpa_supplicant_event_ft_response(wpa_s
, data
);
2407 #endif /* CONFIG_IEEE80211R */
2408 #ifdef CONFIG_IBSS_RSN
2409 case EVENT_IBSS_RSN_START
:
2410 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2412 #endif /* CONFIG_IBSS_RSN */
2413 case EVENT_ASSOC_REJECT
:
2414 if (data
->assoc_reject
.bssid
)
2415 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2416 "bssid=" MACSTR
" status_code=%u",
2417 MAC2STR(data
->assoc_reject
.bssid
),
2418 data
->assoc_reject
.status_code
);
2420 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2422 data
->assoc_reject
.status_code
);
2423 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2424 sme_event_assoc_reject(wpa_s
, data
);
2426 case EVENT_AUTH_TIMED_OUT
:
2427 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2428 sme_event_auth_timed_out(wpa_s
, data
);
2430 case EVENT_ASSOC_TIMED_OUT
:
2431 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2432 sme_event_assoc_timed_out(wpa_s
, data
);
2434 case EVENT_TX_STATUS
:
2435 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
2436 " type=%d stype=%d",
2437 MAC2STR(data
->tx_status
.dst
),
2438 data
->tx_status
.type
, data
->tx_status
.stype
);
2440 if (wpa_s
->ap_iface
== NULL
) {
2441 #ifdef CONFIG_OFFCHANNEL
2442 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2443 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
2444 offchannel_send_action_tx_status(
2445 wpa_s
, data
->tx_status
.dst
,
2446 data
->tx_status
.data
,
2447 data
->tx_status
.data_len
,
2448 data
->tx_status
.ack
?
2449 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2450 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2451 #endif /* CONFIG_OFFCHANNEL */
2454 #endif /* CONFIG_AP */
2455 #ifdef CONFIG_OFFCHANNEL
2456 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
2457 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
2459 * Catch TX status events for Action frames we sent via group
2460 * interface in GO mode.
2462 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
2463 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
2464 os_memcmp(wpa_s
->parent
->pending_action_dst
,
2465 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
2466 offchannel_send_action_tx_status(
2467 wpa_s
->parent
, data
->tx_status
.dst
,
2468 data
->tx_status
.data
,
2469 data
->tx_status
.data_len
,
2470 data
->tx_status
.ack
?
2471 OFFCHANNEL_SEND_ACTION_SUCCESS
:
2472 OFFCHANNEL_SEND_ACTION_NO_ACK
);
2475 #endif /* CONFIG_OFFCHANNEL */
2477 switch (data
->tx_status
.type
) {
2478 case WLAN_FC_TYPE_MGMT
:
2479 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
2480 data
->tx_status
.data_len
,
2481 data
->tx_status
.stype
,
2482 data
->tx_status
.ack
);
2484 case WLAN_FC_TYPE_DATA
:
2485 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
2486 data
->tx_status
.data
,
2487 data
->tx_status
.data_len
,
2488 data
->tx_status
.ack
);
2491 #endif /* CONFIG_AP */
2494 case EVENT_EAPOL_TX_STATUS
:
2495 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
2496 data
->eapol_tx_status
.data
,
2497 data
->eapol_tx_status
.data_len
,
2498 data
->eapol_tx_status
.ack
);
2500 case EVENT_DRIVER_CLIENT_POLL_OK
:
2501 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
2503 case EVENT_RX_FROM_UNKNOWN
:
2504 if (wpa_s
->ap_iface
== NULL
)
2506 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
2507 data
->rx_from_unknown
.wds
);
2509 case EVENT_CH_SWITCH
:
2512 if (!wpa_s
->ap_iface
) {
2513 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: Ignore channel switch "
2514 "event in non-AP mode");
2519 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
2520 data
->ch_switch
.ht_enabled
,
2521 data
->ch_switch
.ch_offset
);
2522 #endif /* CONFIG_AP */
2524 case EVENT_RX_MGMT
: {
2526 const struct ieee80211_mgmt
*mgmt
;
2528 mgmt
= (const struct ieee80211_mgmt
*)
2529 data
->rx_mgmt
.frame
;
2530 fc
= le_to_host16(mgmt
->frame_control
);
2531 stype
= WLAN_FC_GET_STYPE(fc
);
2533 if (wpa_s
->ap_iface
== NULL
) {
2535 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2536 data
->rx_mgmt
.frame_len
> 24) {
2537 const u8
*src
= mgmt
->sa
;
2538 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2539 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2540 (mgmt
->u
.probe_req
.variable
-
2541 data
->rx_mgmt
.frame
);
2542 wpas_p2p_probe_req_rx(
2543 wpa_s
, src
, mgmt
->da
,
2544 mgmt
->bssid
, ie
, ie_len
,
2545 data
->rx_mgmt
.ssi_signal
);
2548 #endif /* CONFIG_P2P */
2549 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2550 "management frame in non-AP mode");
2554 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
2555 data
->rx_mgmt
.frame_len
> 24) {
2556 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
2557 size_t ie_len
= data
->rx_mgmt
.frame_len
-
2558 (mgmt
->u
.probe_req
.variable
-
2559 data
->rx_mgmt
.frame
);
2561 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
2562 mgmt
->bssid
, ie
, ie_len
,
2563 data
->rx_mgmt
.ssi_signal
);
2566 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2569 #endif /* CONFIG_AP */
2570 case EVENT_RX_ACTION
:
2571 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2572 " Category=%u DataLen=%d freq=%d MHz",
2573 MAC2STR(data
->rx_action
.sa
),
2574 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2575 data
->rx_action
.freq
);
2576 #ifdef CONFIG_IEEE80211R
2577 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2578 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2579 data
->rx_action
.len
);
2582 #endif /* CONFIG_IEEE80211R */
2583 #ifdef CONFIG_IEEE80211W
2585 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2586 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2587 data
->rx_action
.data
,
2588 data
->rx_action
.len
);
2591 #endif /* CONFIG_SME */
2592 #endif /* CONFIG_IEEE80211W */
2593 #ifdef CONFIG_IEEE80211V
2594 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2595 ieee802_11_rx_wnm_action(wpa_s
, &data
->rx_action
);
2598 #endif /* CONFIG_IEEE80211V */
2600 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2601 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2602 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2603 data
->rx_action
.data
, data
->rx_action
.len
,
2604 data
->rx_action
.freq
) == 0)
2606 #endif /* CONFIG_GAS */
2607 if (data
->rx_action
.category
== WLAN_ACTION_WNM
) {
2608 wnm_action_rx(wpa_s
, &data
->rx_action
);
2612 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2613 data
->rx_action
.len
>= 4 &&
2614 data
->rx_action
.data
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
2615 wpa_dbg(wpa_s
, MSG_DEBUG
, "TDLS: Received Discovery "
2616 "Response from " MACSTR
,
2617 MAC2STR(data
->rx_action
.sa
));
2620 #endif /* CONFIG_TDLS */
2622 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2624 data
->rx_action
.bssid
,
2625 data
->rx_action
.category
,
2626 data
->rx_action
.data
,
2627 data
->rx_action
.len
, data
->rx_action
.freq
);
2628 #endif /* CONFIG_P2P */
2630 case EVENT_RX_PROBE_REQ
:
2631 if (data
->rx_probe_req
.sa
== NULL
||
2632 data
->rx_probe_req
.ie
== NULL
)
2635 if (wpa_s
->ap_iface
) {
2636 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2637 data
->rx_probe_req
.sa
,
2638 data
->rx_probe_req
.da
,
2639 data
->rx_probe_req
.bssid
,
2640 data
->rx_probe_req
.ie
,
2641 data
->rx_probe_req
.ie_len
,
2642 data
->rx_probe_req
.ssi_signal
);
2645 #endif /* CONFIG_AP */
2647 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2648 data
->rx_probe_req
.da
,
2649 data
->rx_probe_req
.bssid
,
2650 data
->rx_probe_req
.ie
,
2651 data
->rx_probe_req
.ie_len
,
2652 data
->rx_probe_req
.ssi_signal
);
2653 #endif /* CONFIG_P2P */
2655 case EVENT_REMAIN_ON_CHANNEL
:
2656 #ifdef CONFIG_OFFCHANNEL
2657 offchannel_remain_on_channel_cb(
2658 wpa_s
, data
->remain_on_channel
.freq
,
2659 data
->remain_on_channel
.duration
);
2660 #endif /* CONFIG_OFFCHANNEL */
2662 wpas_p2p_remain_on_channel_cb(
2663 wpa_s
, data
->remain_on_channel
.freq
,
2664 data
->remain_on_channel
.duration
);
2665 #endif /* CONFIG_P2P */
2667 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2668 #ifdef CONFIG_OFFCHANNEL
2669 offchannel_cancel_remain_on_channel_cb(
2670 wpa_s
, data
->remain_on_channel
.freq
);
2671 #endif /* CONFIG_OFFCHANNEL */
2673 wpas_p2p_cancel_remain_on_channel_cb(
2674 wpa_s
, data
->remain_on_channel
.freq
);
2675 #endif /* CONFIG_P2P */
2678 case EVENT_P2P_DEV_FOUND
: {
2679 struct p2p_peer_info peer_info
;
2681 os_memset(&peer_info
, 0, sizeof(peer_info
));
2682 if (data
->p2p_dev_found
.dev_addr
)
2683 os_memcpy(peer_info
.p2p_device_addr
,
2684 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2685 if (data
->p2p_dev_found
.pri_dev_type
)
2686 os_memcpy(peer_info
.pri_dev_type
,
2687 data
->p2p_dev_found
.pri_dev_type
,
2688 sizeof(peer_info
.pri_dev_type
));
2689 if (data
->p2p_dev_found
.dev_name
)
2690 os_strlcpy(peer_info
.device_name
,
2691 data
->p2p_dev_found
.dev_name
,
2692 sizeof(peer_info
.device_name
));
2693 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2694 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2695 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2698 * FIX: new_device=1 is not necessarily correct. We should
2699 * maintain a P2P peer database in wpa_supplicant and update
2700 * this information based on whether the peer is truly new.
2702 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2705 case EVENT_P2P_GO_NEG_REQ_RX
:
2706 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2707 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2709 case EVENT_P2P_GO_NEG_COMPLETED
:
2710 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2712 case EVENT_P2P_PROV_DISC_REQUEST
:
2713 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2714 data
->p2p_prov_disc_req
.config_methods
,
2715 data
->p2p_prov_disc_req
.dev_addr
,
2716 data
->p2p_prov_disc_req
.pri_dev_type
,
2717 data
->p2p_prov_disc_req
.dev_name
,
2718 data
->p2p_prov_disc_req
.supp_config_methods
,
2719 data
->p2p_prov_disc_req
.dev_capab
,
2720 data
->p2p_prov_disc_req
.group_capab
,
2723 case EVENT_P2P_PROV_DISC_RESPONSE
:
2724 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2725 data
->p2p_prov_disc_resp
.config_methods
);
2727 case EVENT_P2P_SD_REQUEST
:
2728 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2729 data
->p2p_sd_req
.sa
,
2730 data
->p2p_sd_req
.dialog_token
,
2731 data
->p2p_sd_req
.update_indic
,
2732 data
->p2p_sd_req
.tlvs
,
2733 data
->p2p_sd_req
.tlvs_len
);
2735 case EVENT_P2P_SD_RESPONSE
:
2736 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2737 data
->p2p_sd_resp
.update_indic
,
2738 data
->p2p_sd_resp
.tlvs
,
2739 data
->p2p_sd_resp
.tlvs_len
);
2741 #endif /* CONFIG_P2P */
2742 case EVENT_EAPOL_RX
:
2743 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2744 data
->eapol_rx
.data
,
2745 data
->eapol_rx
.data_len
);
2747 case EVENT_SIGNAL_CHANGE
:
2748 bgscan_notify_signal_change(
2749 wpa_s
, data
->signal_change
.above_threshold
,
2750 data
->signal_change
.current_signal
,
2751 data
->signal_change
.current_noise
,
2752 data
->signal_change
.current_txrate
);
2754 case EVENT_INTERFACE_ENABLED
:
2755 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2756 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2757 wpa_supplicant_update_mac_addr(wpa_s
);
2759 if (!wpa_s
->ap_iface
) {
2760 wpa_supplicant_set_state(wpa_s
,
2762 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2764 wpa_supplicant_set_state(wpa_s
,
2766 #else /* CONFIG_AP */
2767 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2768 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2769 #endif /* CONFIG_AP */
2772 case EVENT_INTERFACE_DISABLED
:
2773 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2774 wpa_supplicant_mark_disassoc(wpa_s
);
2775 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2777 case EVENT_CHANNEL_LIST_CHANGED
:
2778 if (wpa_s
->drv_priv
== NULL
)
2779 break; /* Ignore event during drv initialization */
2781 free_hw_features(wpa_s
);
2782 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(
2783 wpa_s
, &wpa_s
->hw
.num_modes
, &wpa_s
->hw
.flags
);
2786 wpas_p2p_update_channel_list(wpa_s
);
2787 #endif /* CONFIG_P2P */
2789 case EVENT_INTERFACE_UNAVAILABLE
:
2791 wpas_p2p_interface_unavailable(wpa_s
);
2792 #endif /* CONFIG_P2P */
2794 case EVENT_BEST_CHANNEL
:
2795 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2797 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2798 data
->best_chan
.freq_overall
);
2799 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2800 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2801 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2803 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2804 data
->best_chan
.freq_5
,
2805 data
->best_chan
.freq_overall
);
2806 #endif /* CONFIG_P2P */
2808 case EVENT_UNPROT_DEAUTH
:
2809 wpa_supplicant_event_unprot_deauth(wpa_s
,
2810 &data
->unprot_deauth
);
2812 case EVENT_UNPROT_DISASSOC
:
2813 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2814 &data
->unprot_disassoc
);
2816 case EVENT_STATION_LOW_ACK
:
2818 if (wpa_s
->ap_iface
&& data
)
2819 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2820 data
->low_ack
.addr
);
2821 #endif /* CONFIG_AP */
2824 wpa_tdls_disable_link(wpa_s
->wpa
, data
->low_ack
.addr
);
2825 #endif /* CONFIG_TDLS */
2827 case EVENT_IBSS_PEER_LOST
:
2828 #ifdef CONFIG_IBSS_RSN
2829 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2830 #endif /* CONFIG_IBSS_RSN */
2832 case EVENT_DRIVER_GTK_REKEY
:
2833 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2834 wpa_s
->bssid
, ETH_ALEN
))
2838 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2839 data
->driver_gtk_rekey
.replay_ctr
);
2841 case EVENT_SCHED_SCAN_STOPPED
:
2842 wpa_s
->sched_scanning
= 0;
2843 wpa_supplicant_notify_scanning(wpa_s
, 0);
2845 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
2849 * If we timed out, start a new sched scan to continue
2850 * searching for more SSIDs.
2852 if (wpa_s
->sched_scan_timed_out
)
2853 wpa_supplicant_req_sched_scan(wpa_s
);
2855 case EVENT_WPS_BUTTON_PUSHED
:
2857 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
2858 #endif /* CONFIG_WPS */
2861 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);