2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "ap/hostapd.h"
33 #include "common/ieee802_11_defs.h"
34 #include "common/ieee802_11_common.h"
35 #include "crypto/random.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
38 #include "wps_supplicant.h"
41 #include "p2p_supplicant.h"
49 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
51 struct wpa_ssid
*ssid
, *old_ssid
;
53 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
56 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
58 ssid
= wpa_supplicant_get_ssid(wpa_s
);
60 wpa_msg(wpa_s
, MSG_INFO
,
61 "No network configuration found for the current AP");
66 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
70 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
72 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
73 WPA_KEY_MGMT_WPA_NONE
|
74 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
75 WPA_KEY_MGMT_PSK_SHA256
|
76 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
78 size_t wpa_ie_len
= sizeof(wpa_ie
);
79 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
82 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
85 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
86 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
87 old_ssid
= wpa_s
->current_ssid
;
88 wpa_s
->current_ssid
= ssid
;
89 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
90 wpa_supplicant_initiate_eapol(wpa_s
);
91 if (old_ssid
!= wpa_s
->current_ssid
)
92 wpas_notify_network_changed(wpa_s
);
98 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
101 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
103 if (wpa_s
->countermeasures
) {
104 wpa_s
->countermeasures
= 0;
105 wpa_drv_set_countermeasures(wpa_s
, 0);
106 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
107 wpa_supplicant_req_scan(wpa_s
, 0, 0);
112 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
116 #ifdef CONFIG_IBSS_RSN
117 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
118 wpa_s
->ibss_rsn
= NULL
;
119 #endif /* CONFIG_IBSS_RSN */
122 wpa_supplicant_ap_deinit(wpa_s
);
123 #endif /* CONFIG_AP */
125 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
128 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
129 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
130 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
131 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
132 wpa_s
->current_bss
= NULL
;
133 wpa_s
->assoc_freq
= 0;
134 #ifdef CONFIG_IEEE80211R
136 if (wpa_s
->sme
.ft_ies
)
137 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
138 #endif /* CONFIG_SME */
139 #endif /* CONFIG_IEEE80211R */
142 wpas_notify_bssid_changed(wpa_s
);
144 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
145 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
146 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
147 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
148 wpa_s
->ap_ies_from_associnfo
= 0;
152 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
154 struct wpa_ie_data ie
;
158 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
162 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
163 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
164 ie
.pmkid
+ i
* PMKID_LEN
,
166 if (pmksa_set
== 0) {
167 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
172 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
173 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
177 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
178 union wpa_event_data
*data
)
181 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
185 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
186 " index=%d preauth=%d",
187 MAC2STR(data
->pmkid_candidate
.bssid
),
188 data
->pmkid_candidate
.index
,
189 data
->pmkid_candidate
.preauth
);
191 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
192 data
->pmkid_candidate
.index
,
193 data
->pmkid_candidate
.preauth
);
197 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
199 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
200 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
203 #ifdef IEEE8021X_EAPOL
204 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
205 wpa_s
->current_ssid
&&
206 !(wpa_s
->current_ssid
->eapol_flags
&
207 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
208 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
209 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
210 * plaintext or static WEP keys). */
213 #endif /* IEEE8021X_EAPOL */
220 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
221 * @wpa_s: pointer to wpa_supplicant data
222 * @ssid: Configuration data for the network
223 * Returns: 0 on success, -1 on failure
225 * This function is called when starting authentication with a network that is
226 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
228 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
229 struct wpa_ssid
*ssid
)
231 #ifdef IEEE8021X_EAPOL
232 int aka
= 0, sim
= 0, type
;
234 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
237 if (ssid
->eap
.eap_methods
== NULL
) {
241 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
242 while (eap
->vendor
!= EAP_VENDOR_IETF
||
243 eap
->method
!= EAP_TYPE_NONE
) {
244 if (eap
->vendor
== EAP_VENDOR_IETF
) {
245 if (eap
->method
== EAP_TYPE_SIM
)
247 else if (eap
->method
== EAP_TYPE_AKA
)
254 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
256 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
260 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
261 "use SIM, but neither EAP-SIM nor EAP-AKA are "
266 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
267 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
269 type
= SCARD_TRY_BOTH
;
271 type
= SCARD_USIM_ONLY
;
273 type
= SCARD_GSM_SIM_ONLY
;
275 wpa_s
->scard
= scard_init(type
);
276 if (wpa_s
->scard
== NULL
) {
277 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
281 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
282 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
283 #endif /* IEEE8021X_EAPOL */
289 #ifndef CONFIG_NO_SCAN_PROCESSING
290 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
291 struct wpa_ssid
*ssid
)
295 if (ssid
->mixed_cell
)
299 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
301 #endif /* CONFIG_WPS */
303 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
304 if (ssid
->wep_key_len
[i
]) {
309 #ifdef IEEE8021X_EAPOL
310 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
311 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
312 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
314 #endif /* IEEE8021X_EAPOL */
316 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
319 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
325 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
326 struct wpa_ssid
*ssid
,
327 struct wpa_scan_res
*bss
)
329 struct wpa_ie_data ie
;
331 const u8
*rsn_ie
, *wpa_ie
;
335 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
339 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
340 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
341 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
342 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
343 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
345 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
346 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
349 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
350 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
356 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
358 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
363 if (!(ie
.proto
& ssid
->proto
)) {
364 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
369 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
370 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
375 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
376 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
381 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
382 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
387 #ifdef CONFIG_IEEE80211W
388 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
389 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
390 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
394 #endif /* CONFIG_IEEE80211W */
396 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
400 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
401 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
404 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
405 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
411 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
413 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
418 if (!(ie
.proto
& ssid
->proto
)) {
419 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
424 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
425 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
430 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
431 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
436 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
437 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
442 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
446 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
447 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
448 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
452 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
453 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
457 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
464 static int freq_allowed(int *freqs
, int freq
)
471 for (i
= 0; freqs
[i
]; i
++)
472 if (freqs
[i
] == freq
)
478 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
479 int i
, struct wpa_scan_res
*bss
,
480 struct wpa_ssid
*group
)
483 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
485 struct wpa_blacklist
*e
;
487 struct wpa_ssid
*ssid
;
489 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
490 ssid_
= ie
? ie
+ 2 : (u8
*) "";
491 ssid_len
= ie
? ie
[1] : 0;
493 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
494 wpa_ie_len
= ie
? ie
[1] : 0;
496 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
497 rsn_ie_len
= ie
? ie
[1] : 0;
499 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
500 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
501 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
502 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
503 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
505 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
508 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
510 * When only a single network is enabled, we can
511 * trigger blacklisting on the first failure. This
512 * should not be done with multiple enabled networks to
513 * avoid getting forced to move into a worse ESS on
514 * single error if there are no other BSSes of the
519 if (e
->count
> limit
) {
520 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
521 "(count=%d limit=%d)", e
->count
, limit
);
527 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
531 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
533 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
534 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
536 if (ssid
->disabled
) {
537 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
542 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
543 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
548 if (wpa
&& ssid
->ssid_len
== 0 &&
549 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
552 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
553 /* Only allow wildcard SSID match if an AP
554 * advertises active WPS operation that matches
557 if (ssid
->ssid_len
== 0 &&
558 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
561 #endif /* CONFIG_WPS */
564 (ssid_len
!= ssid
->ssid_len
||
565 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
566 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
570 if (ssid
->bssid_set
&&
571 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
572 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
576 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
580 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
581 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
582 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
583 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
588 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
589 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
594 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
595 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
600 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
601 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
608 * TODO: skip the AP if its P2P IE has Group Formation
609 * bit set in the P2P Group Capability Bitmap and we
610 * are not in Group Formation with that device.
612 #endif /* CONFIG_P2P */
614 /* Matching configuration found */
618 /* No matching configuration found */
623 static struct wpa_bss
*
624 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
625 struct wpa_scan_results
*scan_res
,
626 struct wpa_ssid
*group
,
627 struct wpa_ssid
**selected_ssid
)
631 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
634 for (i
= 0; i
< scan_res
->num
; i
++) {
635 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
639 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
643 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
644 ssid
= ie
? ie
+ 2 : (u8
*) "";
645 ssid_len
= ie
? ie
[1] : 0;
647 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
649 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
650 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
657 static struct wpa_bss
*
658 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
659 struct wpa_scan_results
*scan_res
,
660 struct wpa_ssid
**selected_ssid
)
662 struct wpa_bss
*selected
= NULL
;
665 while (selected
== NULL
) {
666 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
667 selected
= wpa_supplicant_select_bss(
668 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
674 if (selected
== NULL
&& wpa_s
->blacklist
) {
675 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
676 "blacklist and try again");
677 wpa_blacklist_clear(wpa_s
);
678 wpa_s
->blacklist_cleared
++;
679 } else if (selected
== NULL
)
687 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
688 int timeout_sec
, int timeout_usec
)
690 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
692 * No networks are enabled; short-circuit request so
693 * we don't wait timeout seconds before transitioning
696 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
699 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
703 void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
704 struct wpa_bss
*selected
,
705 struct wpa_ssid
*ssid
)
707 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
708 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
709 "PBC session overlap");
711 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
713 #endif /* CONFIG_P2P */
716 wpas_wps_cancel(wpa_s
);
717 #endif /* CONFIG_WPS */
722 * Do not trigger new association unless the BSSID has changed or if
723 * reassociation is requested. If we are in process of associating with
724 * the selected BSSID, do not trigger new attempt.
726 if (wpa_s
->reassociate
||
727 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
728 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
729 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
730 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
732 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
733 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
736 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
737 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
738 " pending: " MACSTR
" wpa_state: %s",
739 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
740 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
741 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
742 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
744 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
750 static struct wpa_ssid
*
751 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
754 struct wpa_ssid
*ssid
;
756 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
757 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
761 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
762 ssid
->mode
== IEEE80211_MODE_AP
)
770 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
771 * on BSS added and BSS changed events */
772 static void wpa_supplicant_rsn_preauth_scan_results(
773 struct wpa_supplicant
*wpa_s
)
777 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
780 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
781 const u8
*ssid
, *rsn
;
783 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
787 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
791 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
797 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
798 struct wpa_bss
*selected
,
799 struct wpa_ssid
*ssid
,
800 struct wpa_scan_results
*scan_res
)
803 struct wpa_scan_res
*current_bss
= NULL
;
806 if (wpa_s
->reassociate
)
807 return 1; /* explicit request to reassociate */
808 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
809 return 1; /* we are not associated; continue */
810 if (wpa_s
->current_ssid
== NULL
)
811 return 1; /* unknown current SSID */
812 if (wpa_s
->current_ssid
!= ssid
)
813 return 1; /* different network block */
815 if (wpas_driver_bss_selection(wpa_s
))
816 return 0; /* Driver-based roaming */
818 for (i
= 0; i
< scan_res
->num
; i
++) {
819 struct wpa_scan_res
*res
= scan_res
->res
[i
];
821 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
824 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
827 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
828 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
835 return 1; /* current BSS not seen in scan results */
837 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
838 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
839 MAC2STR(current_bss
->bssid
), current_bss
->level
);
840 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
841 MAC2STR(selected
->bssid
), selected
->level
);
843 if (wpa_s
->current_ssid
->bssid_set
&&
844 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
846 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
847 "has preferred BSSID");
852 if (current_bss
->level
< 0) {
853 if (current_bss
->level
< -85)
855 else if (current_bss
->level
< -80)
857 else if (current_bss
->level
< -75)
859 else if (current_bss
->level
< -70)
864 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
865 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
873 /* Return < 0 if no scan results could be fetched. */
874 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
875 union wpa_event_data
*data
)
877 struct wpa_bss
*selected
;
878 struct wpa_ssid
*ssid
= NULL
;
879 struct wpa_scan_results
*scan_res
;
885 #endif /* CONFIG_AP */
887 wpa_supplicant_notify_scanning(wpa_s
, 0);
889 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
890 data
? &data
->scan_info
:
892 if (scan_res
== NULL
) {
893 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
895 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
897 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
901 #ifndef CONFIG_NO_RANDOM_POOL
906 for (i
= 0; i
< num
; i
++) {
908 struct wpa_scan_res
*res
= scan_res
->res
[i
];
909 buf
[0] = res
->bssid
[5];
910 buf
[1] = res
->qual
& 0xff;
911 buf
[2] = res
->noise
& 0xff;
912 buf
[3] = res
->level
& 0xff;
913 buf
[4] = res
->tsf
& 0xff;
914 random_add_randomness(buf
, sizeof(buf
));
916 #endif /* CONFIG_NO_RANDOM_POOL */
918 if (wpa_s
->scan_res_handler
) {
919 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
920 struct wpa_scan_results
*scan_res
);
922 scan_res_handler
= wpa_s
->scan_res_handler
;
923 wpa_s
->scan_res_handler
= NULL
;
924 scan_res_handler(wpa_s
, scan_res
);
926 wpa_scan_results_free(scan_res
);
931 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
933 if (wpa_s
->ap_iface
->scan_cb
)
934 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
935 #endif /* CONFIG_AP */
936 wpa_scan_results_free(scan_res
);
940 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
941 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
942 wpas_notify_scan_results(wpa_s
);
944 wpas_notify_scan_done(wpa_s
, 1);
946 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
947 wpa_scan_results_free(scan_res
);
951 if (wpa_s
->disconnected
) {
952 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
953 wpa_scan_results_free(scan_res
);
957 if (!wpas_driver_bss_selection(wpa_s
) &&
958 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
959 wpa_scan_results_free(scan_res
);
963 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
967 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
969 wpa_scan_results_free(scan_res
);
972 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
973 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
975 wpa_scan_results_free(scan_res
);
976 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
977 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
979 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
980 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
981 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
983 int timeout_sec
= wpa_s
->scan_interval
;
984 int timeout_usec
= 0;
986 if (wpa_s
->p2p_in_provisioning
) {
988 * Use shorter wait during P2P Provisioning
989 * state to speed up group formation.
992 timeout_usec
= 250000;
994 #endif /* CONFIG_P2P */
995 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1003 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1004 union wpa_event_data
*data
)
1006 const char *rn
, *rn2
;
1007 struct wpa_supplicant
*ifs
;
1009 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1011 * If no scan results could be fetched, then no need to
1012 * notify those interfaces that did not actually request
1019 * Check other interfaces to see if they have the same radio-name. If
1020 * so, they get updated with this same scan info.
1022 if (!wpa_s
->driver
->get_radio_name
)
1025 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1026 if (rn
== NULL
|| rn
[0] == '\0')
1029 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1030 "sharing same radio (%s) in event_scan_results", rn
);
1032 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1033 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1036 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1037 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1038 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1039 "sibling", ifs
->ifname
);
1040 _wpa_supplicant_event_scan_results(ifs
, data
);
1045 #endif /* CONFIG_NO_SCAN_PROCESSING */
1048 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1049 union wpa_event_data
*data
)
1051 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1054 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1055 if (data
->assoc_info
.req_ies
)
1056 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1057 data
->assoc_info
.req_ies_len
);
1058 if (data
->assoc_info
.resp_ies
) {
1059 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1060 data
->assoc_info
.resp_ies_len
);
1062 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1063 data
->assoc_info
.resp_ies_len
);
1064 #endif /* CONFIG_TDLS */
1066 if (data
->assoc_info
.beacon_ies
)
1067 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1068 data
->assoc_info
.beacon_ies
,
1069 data
->assoc_info
.beacon_ies_len
);
1070 if (data
->assoc_info
.freq
)
1071 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1072 data
->assoc_info
.freq
);
1074 p
= data
->assoc_info
.req_ies
;
1075 l
= data
->assoc_info
.req_ies_len
;
1077 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1078 while (p
&& l
>= 2) {
1081 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1085 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1086 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1087 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1088 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1091 wpa_find_assoc_pmkid(wpa_s
);
1097 if (!found
&& data
->assoc_info
.req_ies
)
1098 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1100 #ifdef CONFIG_IEEE80211R
1102 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1104 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1105 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1106 data
->assoc_info
.resp_ies
,
1107 data
->assoc_info
.resp_ies_len
,
1109 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1110 "Reassociation Response failed");
1111 wpa_supplicant_deauthenticate(
1112 wpa_s
, WLAN_REASON_INVALID_IE
);
1117 p
= data
->assoc_info
.resp_ies
;
1118 l
= data
->assoc_info
.resp_ies_len
;
1120 #ifdef CONFIG_WPS_STRICT
1121 if (p
&& wpa_s
->current_ssid
&&
1122 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1124 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1126 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1127 "include WPS IE in (Re)Association Response");
1131 if (wps_validate_assoc_resp(wps
) < 0) {
1133 wpa_supplicant_deauthenticate(
1134 wpa_s
, WLAN_REASON_INVALID_IE
);
1139 #endif /* CONFIG_WPS_STRICT */
1141 /* Go through the IEs and make a copy of the MDIE, if present. */
1142 while (p
&& l
>= 2) {
1145 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1149 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1150 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1151 wpa_s
->sme
.ft_used
= 1;
1152 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1153 MOBILITY_DOMAIN_ID_LEN
);
1159 #endif /* CONFIG_SME */
1161 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1162 data
->assoc_info
.resp_ies_len
);
1163 #endif /* CONFIG_IEEE80211R */
1165 /* WPA/RSN IE from Beacon/ProbeResp */
1166 p
= data
->assoc_info
.beacon_ies
;
1167 l
= data
->assoc_info
.beacon_ies_len
;
1169 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1171 wpa_found
= rsn_found
= 0;
1172 while (p
&& l
>= 2) {
1175 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1180 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1181 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1183 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1187 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1189 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1196 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1197 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1198 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1199 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1200 if (wpa_found
|| rsn_found
)
1201 wpa_s
->ap_ies_from_associnfo
= 1;
1203 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1204 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1205 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1207 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1208 wpa_supplicant_update_scan_results(wpa_s
);
1211 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1217 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1218 union wpa_event_data
*data
)
1223 struct wpa_driver_capa capa
;
1226 if (wpa_s
->ap_iface
) {
1227 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1228 data
->assoc_info
.addr
,
1229 data
->assoc_info
.req_ies
,
1230 data
->assoc_info
.req_ies_len
,
1231 data
->assoc_info
.reassoc
);
1234 #endif /* CONFIG_AP */
1236 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1237 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1240 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1241 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1242 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1243 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1244 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1245 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1246 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1247 MACSTR
, MAC2STR(bssid
));
1248 random_add_randomness(bssid
, ETH_ALEN
);
1249 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1250 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1251 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1253 wpas_notify_bssid_changed(wpa_s
);
1255 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1256 wpa_clear_keys(wpa_s
, bssid
);
1258 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1259 wpa_supplicant_disassociate(
1260 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1263 if (wpa_s
->current_ssid
) {
1264 struct wpa_bss
*bss
= NULL
;
1265 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1266 if (ssid
->ssid_len
> 0)
1267 bss
= wpa_bss_get(wpa_s
, bssid
,
1268 ssid
->ssid
, ssid
->ssid_len
);
1270 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1272 wpa_s
->current_bss
= bss
;
1277 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1278 wpa_s
->sme
.prev_bssid_set
= 1;
1279 #endif /* CONFIG_SME */
1281 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1282 if (wpa_s
->current_ssid
) {
1283 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1284 * initialized before association, but for other modes,
1285 * initialize PC/SC here, if the current configuration needs
1286 * smartcard or SIM/USIM. */
1287 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1289 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1291 l2_packet_notify_auth_start(wpa_s
->l2
);
1294 * Set portEnabled first to FALSE in order to get EAP state machine out
1295 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1296 * state machine may transit to AUTHENTICATING state based on obsolete
1297 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1298 * AUTHENTICATED without ever giving chance to EAP state machine to
1301 if (!ft_completed
) {
1302 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1303 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1305 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1306 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1307 /* 802.1X::portControl = Auto */
1308 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1309 wpa_s
->eapol_received
= 0;
1310 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1311 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1312 (wpa_s
->current_ssid
&&
1313 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1314 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1315 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1316 } else if (!ft_completed
) {
1317 /* Timeout for receiving the first EAPOL packet */
1318 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1320 wpa_supplicant_cancel_scan(wpa_s
);
1322 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1323 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1325 * We are done; the driver will take care of RSN 4-way
1328 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1329 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1330 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1331 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1332 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1333 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1335 * The driver will take care of RSN 4-way handshake, so we need
1336 * to allow EAPOL supplicant to complete its work without
1337 * waiting for WPA supplicant.
1339 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1340 } else if (ft_completed
) {
1342 * FT protocol completed - make sure EAPOL state machine ends
1343 * up in authenticated.
1345 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1346 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1347 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1348 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1351 if (wpa_s
->pending_eapol_rx
) {
1352 struct os_time now
, age
;
1354 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1355 if (age
.sec
== 0 && age
.usec
< 100000 &&
1356 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1358 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1359 "frame that was received just before "
1360 "association notification");
1361 wpa_supplicant_rx_eapol(
1362 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1363 wpabuf_head(wpa_s
->pending_eapol_rx
),
1364 wpabuf_len(wpa_s
->pending_eapol_rx
));
1366 wpabuf_free(wpa_s
->pending_eapol_rx
);
1367 wpa_s
->pending_eapol_rx
= NULL
;
1370 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1371 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1372 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1373 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1374 /* Set static WEP keys again */
1375 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1378 #ifdef CONFIG_IBSS_RSN
1379 if (wpa_s
->current_ssid
&&
1380 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1381 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1382 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1383 wpa_s
->ibss_rsn
== NULL
) {
1384 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1385 if (!wpa_s
->ibss_rsn
) {
1386 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1387 wpa_supplicant_deauthenticate(
1388 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1392 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1394 #endif /* CONFIG_IBSS_RSN */
1398 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1403 u8 prev_pending_bssid
[ETH_ALEN
];
1405 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1406 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1408 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1410 * At least Host AP driver and a Prism3 card seemed to be
1411 * generating streams of disconnected events when configuring
1412 * IBSS for WPA-None. Ignore them for now.
1414 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1415 "IBSS/WPA-None mode");
1419 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1420 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1421 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1422 "pre-shared key may be incorrect");
1424 if (!wpa_s
->auto_reconnect_disabled
||
1425 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1426 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1427 "reconnect (wps=%d)",
1428 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1429 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1430 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1432 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1433 "try to re-connect");
1434 wpa_s
->reassociate
= 0;
1435 wpa_s
->disconnected
= 1;
1437 bssid
= wpa_s
->bssid
;
1438 if (is_zero_ether_addr(bssid
))
1439 bssid
= wpa_s
->pending_bssid
;
1440 wpas_connection_failed(wpa_s
, bssid
);
1441 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1442 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1444 MAC2STR(bssid
), reason_code
);
1445 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1446 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1447 wpa_s
->keys_cleared
= 0;
1448 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1450 wpa_supplicant_mark_disassoc(wpa_s
);
1452 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1453 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1457 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1458 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1461 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1463 if (!wpa_s
->pending_mic_error_report
)
1466 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1467 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1468 wpa_s
->pending_mic_error_report
= 0;
1470 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1474 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1475 union wpa_event_data
*data
)
1480 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1481 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1483 if ((wpa_s
->last_michael_mic_error
&&
1484 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1485 wpa_s
->pending_mic_error_report
) {
1486 if (wpa_s
->pending_mic_error_report
) {
1488 * Send the pending MIC error report immediately since
1489 * we are going to start countermeasures and AP better
1492 wpa_sm_key_request(wpa_s
->wpa
, 1,
1493 wpa_s
->pending_mic_error_pairwise
);
1496 /* Send the new MIC error report immediately since we are going
1497 * to start countermeasures and AP better do the same.
1499 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1501 /* initialize countermeasures */
1502 wpa_s
->countermeasures
= 1;
1503 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1506 * Need to wait for completion of request frame. We do not get
1507 * any callback for the message completion, so just wait a
1508 * short while and hope for the best. */
1511 wpa_drv_set_countermeasures(wpa_s
, 1);
1512 wpa_supplicant_deauthenticate(wpa_s
,
1513 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1514 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1516 eloop_register_timeout(60, 0,
1517 wpa_supplicant_stop_countermeasures
,
1519 /* TODO: mark the AP rejected for 60 second. STA is
1520 * allowed to associate with another AP.. */
1522 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1523 if (wpa_s
->mic_errors_seen
) {
1525 * Reduce the effectiveness of Michael MIC error
1526 * reports as a means for attacking against TKIP if
1527 * more than one MIC failure is noticed with the same
1528 * PTK. We delay the transmission of the reports by a
1529 * random time between 0 and 60 seconds in order to
1530 * force the attacker wait 60 seconds before getting
1531 * the information on whether a frame resulted in a MIC
1537 if (os_get_random(rval
, sizeof(rval
)) < 0)
1538 sec
= os_random() % 60;
1540 sec
= WPA_GET_BE32(rval
) % 60;
1541 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1542 "report %d seconds", sec
);
1543 wpa_s
->pending_mic_error_report
= 1;
1544 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1545 eloop_cancel_timeout(
1546 wpa_supplicant_delayed_mic_error_report
,
1548 eloop_register_timeout(
1549 sec
, os_random() % 1000000,
1550 wpa_supplicant_delayed_mic_error_report
,
1553 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1555 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1556 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1557 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1559 wpa_s
->last_michael_mic_error
= t
.sec
;
1560 wpa_s
->mic_errors_seen
++;
1564 #ifdef CONFIG_TERMINATE_ONLASTIF
1565 static int any_interfaces(struct wpa_supplicant
*head
)
1567 struct wpa_supplicant
*wpa_s
;
1569 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1570 if (!wpa_s
->interface_removed
)
1574 #endif /* CONFIG_TERMINATE_ONLASTIF */
1578 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1579 union wpa_event_data
*data
)
1581 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1584 switch (data
->interface_status
.ievent
) {
1585 case EVENT_INTERFACE_ADDED
:
1586 if (!wpa_s
->interface_removed
)
1588 wpa_s
->interface_removed
= 0;
1589 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1590 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1591 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1592 "driver after interface was added");
1595 case EVENT_INTERFACE_REMOVED
:
1596 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1597 wpa_s
->interface_removed
= 1;
1598 wpa_supplicant_mark_disassoc(wpa_s
);
1599 l2_packet_deinit(wpa_s
->l2
);
1601 #ifdef CONFIG_IBSS_RSN
1602 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1603 wpa_s
->ibss_rsn
= NULL
;
1604 #endif /* CONFIG_IBSS_RSN */
1605 #ifdef CONFIG_TERMINATE_ONLASTIF
1606 /* check if last interface */
1607 if (!any_interfaces(wpa_s
->global
->ifaces
))
1609 #endif /* CONFIG_TERMINATE_ONLASTIF */
1615 #ifdef CONFIG_PEERKEY
1617 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1618 union wpa_event_data
*data
)
1622 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1624 #endif /* CONFIG_PEERKEY */
1628 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1629 union wpa_event_data
*data
)
1633 switch (data
->tdls
.oper
) {
1634 case TDLS_REQUEST_SETUP
:
1635 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1637 case TDLS_REQUEST_TEARDOWN
:
1638 /* request from driver to add FTIE */
1639 wpa_tdls_recv_teardown_notify(wpa_s
->wpa
, data
->tdls
.peer
,
1640 data
->tdls
.reason_code
);
1644 #endif /* CONFIG_TDLS */
1647 #ifdef CONFIG_IEEE80211R
1649 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1650 union wpa_event_data
*data
)
1655 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1656 data
->ft_ies
.ies_len
,
1657 data
->ft_ies
.ft_action
,
1658 data
->ft_ies
.target_ap
,
1659 data
->ft_ies
.ric_ies
,
1660 data
->ft_ies
.ric_ies_len
) < 0) {
1661 /* TODO: prevent MLME/driver from trying to associate? */
1664 #endif /* CONFIG_IEEE80211R */
1667 #ifdef CONFIG_IBSS_RSN
1668 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1669 union wpa_event_data
*data
)
1671 struct wpa_ssid
*ssid
;
1672 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1676 ssid
= wpa_s
->current_ssid
;
1679 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1682 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1684 #endif /* CONFIG_IBSS_RSN */
1687 #ifdef CONFIG_IEEE80211R
1688 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1691 const u8
*sta_addr
, *target_ap_addr
;
1694 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1695 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1696 return; /* only SME case supported for now */
1697 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1700 return; /* Only FT Action Response is supported for now */
1701 sta_addr
= data
+ 1;
1702 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1703 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1704 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1705 MACSTR
" TargetAP " MACSTR
" status %u",
1706 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1708 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1709 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1710 " in FT Action Response", MAC2STR(sta_addr
));
1715 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1716 "failure (status code %d)", status
);
1717 /* TODO: report error to FT code(?) */
1721 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1722 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1723 target_ap_addr
, NULL
, 0) < 0)
1728 struct wpa_bss
*bss
;
1729 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1731 wpa_s
->sme
.freq
= bss
->freq
;
1732 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1733 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1736 #endif /* CONFIG_SME */
1738 #endif /* CONFIG_IEEE80211R */
1741 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1742 struct unprot_deauth
*e
)
1744 #ifdef CONFIG_IEEE80211W
1745 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1746 "dropped: " MACSTR
" -> " MACSTR
1747 " (reason code %u)",
1748 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1749 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1750 #endif /* CONFIG_IEEE80211W */
1754 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1755 struct unprot_disassoc
*e
)
1757 #ifdef CONFIG_IEEE80211W
1758 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1759 "dropped: " MACSTR
" -> " MACSTR
1760 " (reason code %u)",
1761 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1762 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1763 #endif /* CONFIG_IEEE80211W */
1767 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1768 union wpa_event_data
*data
)
1770 struct wpa_supplicant
*wpa_s
= ctx
;
1771 u16 reason_code
= 0;
1773 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1774 event
!= EVENT_INTERFACE_ENABLED
&&
1775 event
!= EVENT_INTERFACE_STATUS
) {
1776 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1781 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1782 event
, wpa_s
->ifname
);
1786 sme_event_auth(wpa_s
, data
);
1789 wpa_supplicant_event_assoc(wpa_s
, data
);
1791 case EVENT_DISASSOC
:
1792 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1794 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1795 data
->disassoc_info
.reason_code
);
1796 if (data
->disassoc_info
.addr
)
1797 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1798 MAC2STR(data
->disassoc_info
.addr
));
1801 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1802 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1803 data
->disassoc_info
.addr
);
1806 #endif /* CONFIG_AP */
1808 reason_code
= data
->disassoc_info
.reason_code
;
1809 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1810 data
->disassoc_info
.ie
,
1811 data
->disassoc_info
.ie_len
);
1813 wpas_p2p_disassoc_notif(
1814 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1815 data
->disassoc_info
.ie
,
1816 data
->disassoc_info
.ie_len
);
1817 #endif /* CONFIG_P2P */
1819 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1820 sme_event_disassoc(wpa_s
, data
);
1823 if (event
== EVENT_DEAUTH
) {
1824 wpa_dbg(wpa_s
, MSG_DEBUG
,
1825 "Deauthentication notification");
1827 reason_code
= data
->deauth_info
.reason_code
;
1828 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1829 data
->deauth_info
.reason_code
);
1830 if (data
->deauth_info
.addr
) {
1831 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
1833 MAC2STR(data
->deauth_info
.
1836 wpa_hexdump(MSG_DEBUG
,
1837 "Deauthentication frame IE(s)",
1838 data
->deauth_info
.ie
,
1839 data
->deauth_info
.ie_len
);
1841 wpas_p2p_deauth_notif(
1842 wpa_s
, data
->deauth_info
.addr
,
1844 data
->deauth_info
.ie
,
1845 data
->deauth_info
.ie_len
);
1846 #endif /* CONFIG_P2P */
1850 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
1851 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1852 data
->deauth_info
.addr
);
1855 #endif /* CONFIG_AP */
1856 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
1858 case EVENT_MICHAEL_MIC_FAILURE
:
1859 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1861 #ifndef CONFIG_NO_SCAN_PROCESSING
1862 case EVENT_SCAN_RESULTS
:
1863 wpa_supplicant_event_scan_results(wpa_s
, data
);
1865 #endif /* CONFIG_NO_SCAN_PROCESSING */
1866 case EVENT_ASSOCINFO
:
1867 wpa_supplicant_event_associnfo(wpa_s
, data
);
1869 case EVENT_INTERFACE_STATUS
:
1870 wpa_supplicant_event_interface_status(wpa_s
, data
);
1872 case EVENT_PMKID_CANDIDATE
:
1873 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1875 #ifdef CONFIG_PEERKEY
1876 case EVENT_STKSTART
:
1877 wpa_supplicant_event_stkstart(wpa_s
, data
);
1879 #endif /* CONFIG_PEERKEY */
1882 wpa_supplicant_event_tdls(wpa_s
, data
);
1884 #endif /* CONFIG_TDLS */
1885 #ifdef CONFIG_IEEE80211R
1886 case EVENT_FT_RESPONSE
:
1887 wpa_supplicant_event_ft_response(wpa_s
, data
);
1889 #endif /* CONFIG_IEEE80211R */
1890 #ifdef CONFIG_IBSS_RSN
1891 case EVENT_IBSS_RSN_START
:
1892 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1894 #endif /* CONFIG_IBSS_RSN */
1895 case EVENT_ASSOC_REJECT
:
1896 if (data
->assoc_reject
.bssid
)
1897 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1898 "bssid=" MACSTR
" status_code=%u",
1899 MAC2STR(data
->assoc_reject
.bssid
),
1900 data
->assoc_reject
.status_code
);
1902 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1904 data
->assoc_reject
.status_code
);
1905 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1906 sme_event_assoc_reject(wpa_s
, data
);
1908 case EVENT_AUTH_TIMED_OUT
:
1909 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1910 sme_event_auth_timed_out(wpa_s
, data
);
1912 case EVENT_ASSOC_TIMED_OUT
:
1913 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1914 sme_event_assoc_timed_out(wpa_s
, data
);
1917 case EVENT_TX_STATUS
:
1918 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
1919 " type=%d stype=%d",
1920 MAC2STR(data
->tx_status
.dst
),
1921 data
->tx_status
.type
, data
->tx_status
.stype
);
1922 if (wpa_s
->ap_iface
== NULL
) {
1924 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1925 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
1926 wpas_send_action_tx_status(
1927 wpa_s
, data
->tx_status
.dst
,
1928 data
->tx_status
.data
,
1929 data
->tx_status
.data_len
,
1930 data
->tx_status
.ack
?
1931 P2P_SEND_ACTION_SUCCESS
:
1932 P2P_SEND_ACTION_NO_ACK
);
1933 #endif /* CONFIG_P2P */
1937 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
1938 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
1940 * Catch TX status events for Action frames we sent via group
1941 * interface in GO mode.
1943 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1944 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
1945 os_memcmp(wpa_s
->parent
->pending_action_dst
,
1946 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
1947 wpas_send_action_tx_status(
1948 wpa_s
->parent
, data
->tx_status
.dst
,
1949 data
->tx_status
.data
,
1950 data
->tx_status
.data_len
,
1951 data
->tx_status
.ack
?
1952 P2P_SEND_ACTION_SUCCESS
:
1953 P2P_SEND_ACTION_NO_ACK
);
1956 #endif /* CONFIG_P2P */
1957 switch (data
->tx_status
.type
) {
1958 case WLAN_FC_TYPE_MGMT
:
1959 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1960 data
->tx_status
.data_len
,
1961 data
->tx_status
.stype
,
1962 data
->tx_status
.ack
);
1964 case WLAN_FC_TYPE_DATA
:
1965 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1966 data
->tx_status
.data
,
1967 data
->tx_status
.data_len
,
1968 data
->tx_status
.ack
);
1972 case EVENT_RX_FROM_UNKNOWN
:
1973 if (wpa_s
->ap_iface
== NULL
)
1975 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1976 data
->rx_from_unknown
.len
);
1979 if (wpa_s
->ap_iface
== NULL
) {
1982 const struct ieee80211_mgmt
*mgmt
;
1983 mgmt
= (const struct ieee80211_mgmt
*)
1984 data
->rx_mgmt
.frame
;
1985 fc
= le_to_host16(mgmt
->frame_control
);
1986 stype
= WLAN_FC_GET_STYPE(fc
);
1987 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
1988 data
->rx_mgmt
.frame_len
> 24) {
1989 const u8
*src
= mgmt
->sa
;
1990 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
1991 size_t ie_len
= data
->rx_mgmt
.frame_len
-
1992 (mgmt
->u
.probe_req
.variable
-
1993 data
->rx_mgmt
.frame
);
1994 wpas_p2p_probe_req_rx(wpa_s
, src
, mgmt
->da
,
1995 mgmt
->bssid
, ie
, ie_len
);
1998 #endif /* CONFIG_P2P */
1999 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2000 "management frame in non-AP mode");
2003 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2005 #endif /* CONFIG_AP */
2006 case EVENT_RX_ACTION
:
2007 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2008 " Category=%u DataLen=%d freq=%d MHz",
2009 MAC2STR(data
->rx_action
.sa
),
2010 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2011 data
->rx_action
.freq
);
2012 #ifdef CONFIG_IEEE80211R
2013 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2014 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2015 data
->rx_action
.len
);
2018 #endif /* CONFIG_IEEE80211R */
2019 #ifdef CONFIG_IEEE80211W
2021 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2022 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2023 data
->rx_action
.data
,
2024 data
->rx_action
.len
);
2027 #endif /* CONFIG_SME */
2028 #endif /* CONFIG_IEEE80211W */
2030 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2032 data
->rx_action
.bssid
,
2033 data
->rx_action
.category
,
2034 data
->rx_action
.data
,
2035 data
->rx_action
.len
, data
->rx_action
.freq
);
2036 #endif /* CONFIG_P2P */
2038 case EVENT_RX_PROBE_REQ
:
2039 if (data
->rx_probe_req
.sa
== NULL
||
2040 data
->rx_probe_req
.ie
== NULL
)
2043 if (wpa_s
->ap_iface
) {
2044 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2045 data
->rx_probe_req
.sa
,
2046 data
->rx_probe_req
.da
,
2047 data
->rx_probe_req
.bssid
,
2048 data
->rx_probe_req
.ie
,
2049 data
->rx_probe_req
.ie_len
);
2052 #endif /* CONFIG_AP */
2054 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2055 data
->rx_probe_req
.da
,
2056 data
->rx_probe_req
.bssid
,
2057 data
->rx_probe_req
.ie
,
2058 data
->rx_probe_req
.ie_len
);
2059 #endif /* CONFIG_P2P */
2062 case EVENT_REMAIN_ON_CHANNEL
:
2063 wpas_p2p_remain_on_channel_cb(
2064 wpa_s
, data
->remain_on_channel
.freq
,
2065 data
->remain_on_channel
.duration
);
2067 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2068 wpas_p2p_cancel_remain_on_channel_cb(
2069 wpa_s
, data
->remain_on_channel
.freq
);
2071 case EVENT_P2P_DEV_FOUND
: {
2072 struct p2p_peer_info peer_info
;
2074 os_memset(&peer_info
, 0, sizeof(peer_info
));
2075 if (data
->p2p_dev_found
.dev_addr
)
2076 os_memcpy(peer_info
.p2p_device_addr
,
2077 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2078 if (data
->p2p_dev_found
.pri_dev_type
)
2079 os_memcpy(peer_info
.pri_dev_type
,
2080 data
->p2p_dev_found
.pri_dev_type
,
2081 sizeof(peer_info
.pri_dev_type
));
2082 if (data
->p2p_dev_found
.dev_name
)
2083 os_strlcpy(peer_info
.device_name
,
2084 data
->p2p_dev_found
.dev_name
,
2085 sizeof(peer_info
.device_name
));
2086 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2087 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2088 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2091 * FIX: new_device=1 is not necessarily correct. We should
2092 * maintain a P2P peer database in wpa_supplicant and update
2093 * this information based on whether the peer is truly new.
2095 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2098 case EVENT_P2P_GO_NEG_REQ_RX
:
2099 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2100 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2102 case EVENT_P2P_GO_NEG_COMPLETED
:
2103 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2105 case EVENT_P2P_PROV_DISC_REQUEST
:
2106 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2107 data
->p2p_prov_disc_req
.config_methods
,
2108 data
->p2p_prov_disc_req
.dev_addr
,
2109 data
->p2p_prov_disc_req
.pri_dev_type
,
2110 data
->p2p_prov_disc_req
.dev_name
,
2111 data
->p2p_prov_disc_req
.supp_config_methods
,
2112 data
->p2p_prov_disc_req
.dev_capab
,
2113 data
->p2p_prov_disc_req
.group_capab
);
2115 case EVENT_P2P_PROV_DISC_RESPONSE
:
2116 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2117 data
->p2p_prov_disc_resp
.config_methods
);
2119 case EVENT_P2P_SD_REQUEST
:
2120 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2121 data
->p2p_sd_req
.sa
,
2122 data
->p2p_sd_req
.dialog_token
,
2123 data
->p2p_sd_req
.update_indic
,
2124 data
->p2p_sd_req
.tlvs
,
2125 data
->p2p_sd_req
.tlvs_len
);
2127 case EVENT_P2P_SD_RESPONSE
:
2128 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2129 data
->p2p_sd_resp
.update_indic
,
2130 data
->p2p_sd_resp
.tlvs
,
2131 data
->p2p_sd_resp
.tlvs_len
);
2133 #endif /* CONFIG_P2P */
2134 #ifdef CONFIG_CLIENT_MLME
2135 case EVENT_MLME_RX
: {
2136 struct ieee80211_rx_status rx_status
;
2137 os_memset(&rx_status
, 0, sizeof(rx_status
));
2138 rx_status
.freq
= data
->mlme_rx
.freq
;
2139 rx_status
.channel
= data
->mlme_rx
.channel
;
2140 rx_status
.ssi
= data
->mlme_rx
.ssi
;
2141 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
2145 #endif /* CONFIG_CLIENT_MLME */
2146 case EVENT_EAPOL_RX
:
2147 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2148 data
->eapol_rx
.data
,
2149 data
->eapol_rx
.data_len
);
2151 case EVENT_SIGNAL_CHANGE
:
2152 bgscan_notify_signal_change(
2153 wpa_s
, data
->signal_change
.above_threshold
,
2154 data
->signal_change
.current_signal
,
2155 data
->signal_change
.current_noise
,
2156 data
->signal_change
.current_txrate
);
2158 case EVENT_INTERFACE_ENABLED
:
2159 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2160 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2162 if (!wpa_s
->ap_iface
) {
2163 wpa_supplicant_set_state(wpa_s
,
2165 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2167 wpa_supplicant_set_state(wpa_s
,
2169 #else /* CONFIG_AP */
2170 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2171 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2172 #endif /* CONFIG_AP */
2175 case EVENT_INTERFACE_DISABLED
:
2176 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2177 wpa_supplicant_mark_disassoc(wpa_s
);
2178 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2180 case EVENT_CHANNEL_LIST_CHANGED
:
2181 if (wpa_s
->drv_priv
== NULL
)
2182 break; /* Ignore event during drv initialization */
2184 wpas_p2p_update_channel_list(wpa_s
);
2185 #endif /* CONFIG_P2P */
2187 case EVENT_INTERFACE_UNAVAILABLE
:
2189 wpas_p2p_interface_unavailable(wpa_s
);
2190 #endif /* CONFIG_P2P */
2192 case EVENT_BEST_CHANNEL
:
2193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2195 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2196 data
->best_chan
.freq_overall
);
2197 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2198 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2199 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2201 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2202 data
->best_chan
.freq_5
,
2203 data
->best_chan
.freq_overall
);
2204 #endif /* CONFIG_P2P */
2206 case EVENT_UNPROT_DEAUTH
:
2207 wpa_supplicant_event_unprot_deauth(wpa_s
,
2208 &data
->unprot_deauth
);
2210 case EVENT_UNPROT_DISASSOC
:
2211 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2212 &data
->unprot_disassoc
);
2214 case EVENT_STATION_LOW_ACK
:
2216 if (wpa_s
->ap_iface
&& data
)
2217 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2218 data
->low_ack
.addr
);
2219 #endif /* CONFIG_AP */
2221 case EVENT_IBSS_PEER_LOST
:
2222 #ifdef CONFIG_IBSS_RSN
2223 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2224 #endif /* CONFIG_IBSS_RSN */
2226 case EVENT_DRIVER_GTK_REKEY
:
2227 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2228 wpa_s
->bssid
, ETH_ALEN
))
2232 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2233 data
->driver_gtk_rekey
.replay_ctr
);
2236 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);