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 for (i
= 0; i
< scan_res
->num
; i
++) {
816 struct wpa_scan_res
*res
= scan_res
->res
[i
];
818 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
821 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
824 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
825 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
832 return 1; /* current BSS not seen in scan results */
834 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
835 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
836 MAC2STR(current_bss
->bssid
), current_bss
->level
);
837 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
838 MAC2STR(selected
->bssid
), selected
->level
);
840 if (wpa_s
->current_ssid
->bssid_set
&&
841 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
843 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
844 "has preferred BSSID");
849 if (current_bss
->level
< 0) {
850 if (current_bss
->level
< -85)
852 else if (current_bss
->level
< -80)
854 else if (current_bss
->level
< -75)
856 else if (current_bss
->level
< -70)
861 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
862 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
870 /* Return < 0 if no scan results could be fetched. */
871 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
872 union wpa_event_data
*data
)
874 struct wpa_bss
*selected
;
875 struct wpa_ssid
*ssid
= NULL
;
876 struct wpa_scan_results
*scan_res
;
882 #endif /* CONFIG_AP */
884 wpa_supplicant_notify_scanning(wpa_s
, 0);
886 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
887 data
? &data
->scan_info
:
889 if (scan_res
== NULL
) {
890 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
892 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
894 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
898 #ifndef CONFIG_NO_RANDOM_POOL
903 for (i
= 0; i
< num
; i
++) {
905 struct wpa_scan_res
*res
= scan_res
->res
[i
];
906 buf
[0] = res
->bssid
[5];
907 buf
[1] = res
->qual
& 0xff;
908 buf
[2] = res
->noise
& 0xff;
909 buf
[3] = res
->level
& 0xff;
910 buf
[4] = res
->tsf
& 0xff;
911 random_add_randomness(buf
, sizeof(buf
));
913 #endif /* CONFIG_NO_RANDOM_POOL */
915 if (wpa_s
->scan_res_handler
) {
916 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
917 struct wpa_scan_results
*scan_res
);
919 scan_res_handler
= wpa_s
->scan_res_handler
;
920 wpa_s
->scan_res_handler
= NULL
;
921 scan_res_handler(wpa_s
, scan_res
);
923 wpa_scan_results_free(scan_res
);
928 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
930 if (wpa_s
->ap_iface
->scan_cb
)
931 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
932 #endif /* CONFIG_AP */
933 wpa_scan_results_free(scan_res
);
937 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
938 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
939 wpas_notify_scan_results(wpa_s
);
941 wpas_notify_scan_done(wpa_s
, 1);
943 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
944 wpa_scan_results_free(scan_res
);
948 if (wpa_s
->disconnected
) {
949 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
950 wpa_scan_results_free(scan_res
);
954 if (bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
955 wpa_scan_results_free(scan_res
);
959 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
963 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
965 wpa_scan_results_free(scan_res
);
968 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
969 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
971 wpa_scan_results_free(scan_res
);
972 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
973 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
975 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
976 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
977 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
979 int timeout_sec
= wpa_s
->scan_interval
;
980 int timeout_usec
= 0;
982 if (wpa_s
->p2p_in_provisioning
) {
984 * Use shorter wait during P2P Provisioning
985 * state to speed up group formation.
988 timeout_usec
= 250000;
990 #endif /* CONFIG_P2P */
991 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
999 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1000 union wpa_event_data
*data
)
1002 const char *rn
, *rn2
;
1003 struct wpa_supplicant
*ifs
;
1005 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1007 * If no scan results could be fetched, then no need to
1008 * notify those interfaces that did not actually request
1015 * Check other interfaces to see if they have the same radio-name. If
1016 * so, they get updated with this same scan info.
1018 if (!wpa_s
->driver
->get_radio_name
)
1021 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1022 if (rn
== NULL
|| rn
[0] == '\0')
1025 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1026 "sharing same radio (%s) in event_scan_results", rn
);
1028 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1029 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1032 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1033 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1034 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1035 "sibling", ifs
->ifname
);
1036 _wpa_supplicant_event_scan_results(ifs
, data
);
1041 #endif /* CONFIG_NO_SCAN_PROCESSING */
1044 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1045 union wpa_event_data
*data
)
1047 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1050 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1051 if (data
->assoc_info
.req_ies
)
1052 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1053 data
->assoc_info
.req_ies_len
);
1054 if (data
->assoc_info
.resp_ies
) {
1055 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1056 data
->assoc_info
.resp_ies_len
);
1058 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1059 data
->assoc_info
.resp_ies_len
);
1060 #endif /* CONFIG_TDLS */
1062 if (data
->assoc_info
.beacon_ies
)
1063 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1064 data
->assoc_info
.beacon_ies
,
1065 data
->assoc_info
.beacon_ies_len
);
1066 if (data
->assoc_info
.freq
)
1067 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1068 data
->assoc_info
.freq
);
1070 p
= data
->assoc_info
.req_ies
;
1071 l
= data
->assoc_info
.req_ies_len
;
1073 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1074 while (p
&& l
>= 2) {
1077 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1081 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1082 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1083 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1084 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1087 wpa_find_assoc_pmkid(wpa_s
);
1093 if (!found
&& data
->assoc_info
.req_ies
)
1094 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1096 #ifdef CONFIG_IEEE80211R
1098 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1100 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1101 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1102 data
->assoc_info
.resp_ies
,
1103 data
->assoc_info
.resp_ies_len
,
1105 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1106 "Reassociation Response failed");
1107 wpa_supplicant_deauthenticate(
1108 wpa_s
, WLAN_REASON_INVALID_IE
);
1113 p
= data
->assoc_info
.resp_ies
;
1114 l
= data
->assoc_info
.resp_ies_len
;
1116 #ifdef CONFIG_WPS_STRICT
1117 if (p
&& wpa_s
->current_ssid
&&
1118 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1120 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1122 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1123 "include WPS IE in (Re)Association Response");
1127 if (wps_validate_assoc_resp(wps
) < 0) {
1129 wpa_supplicant_deauthenticate(
1130 wpa_s
, WLAN_REASON_INVALID_IE
);
1135 #endif /* CONFIG_WPS_STRICT */
1137 /* Go through the IEs and make a copy of the MDIE, if present. */
1138 while (p
&& l
>= 2) {
1141 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1145 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1146 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1147 wpa_s
->sme
.ft_used
= 1;
1148 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1149 MOBILITY_DOMAIN_ID_LEN
);
1155 #endif /* CONFIG_SME */
1157 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1158 data
->assoc_info
.resp_ies_len
);
1159 #endif /* CONFIG_IEEE80211R */
1161 /* WPA/RSN IE from Beacon/ProbeResp */
1162 p
= data
->assoc_info
.beacon_ies
;
1163 l
= data
->assoc_info
.beacon_ies_len
;
1165 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1167 wpa_found
= rsn_found
= 0;
1168 while (p
&& l
>= 2) {
1171 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1176 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1177 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1179 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1183 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1185 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1192 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1193 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1194 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1195 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1196 if (wpa_found
|| rsn_found
)
1197 wpa_s
->ap_ies_from_associnfo
= 1;
1199 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1200 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1201 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1203 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1204 wpa_supplicant_update_scan_results(wpa_s
);
1207 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1213 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1214 union wpa_event_data
*data
)
1219 struct wpa_driver_capa capa
;
1222 if (wpa_s
->ap_iface
) {
1223 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1224 data
->assoc_info
.addr
,
1225 data
->assoc_info
.req_ies
,
1226 data
->assoc_info
.req_ies_len
,
1227 data
->assoc_info
.reassoc
);
1230 #endif /* CONFIG_AP */
1232 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1233 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1236 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1237 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1238 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1239 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1240 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1241 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1242 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1243 MACSTR
, MAC2STR(bssid
));
1244 random_add_randomness(bssid
, ETH_ALEN
);
1245 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1246 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1247 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1249 wpas_notify_bssid_changed(wpa_s
);
1251 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1252 wpa_clear_keys(wpa_s
, bssid
);
1254 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1255 wpa_supplicant_disassociate(
1256 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1259 if (wpa_s
->current_ssid
) {
1260 struct wpa_bss
*bss
= NULL
;
1261 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1262 if (ssid
->ssid_len
> 0)
1263 bss
= wpa_bss_get(wpa_s
, bssid
,
1264 ssid
->ssid
, ssid
->ssid_len
);
1266 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1268 wpa_s
->current_bss
= bss
;
1273 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1274 wpa_s
->sme
.prev_bssid_set
= 1;
1275 #endif /* CONFIG_SME */
1277 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1278 if (wpa_s
->current_ssid
) {
1279 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1280 * initialized before association, but for other modes,
1281 * initialize PC/SC here, if the current configuration needs
1282 * smartcard or SIM/USIM. */
1283 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1285 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1287 l2_packet_notify_auth_start(wpa_s
->l2
);
1290 * Set portEnabled first to FALSE in order to get EAP state machine out
1291 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1292 * state machine may transit to AUTHENTICATING state based on obsolete
1293 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1294 * AUTHENTICATED without ever giving chance to EAP state machine to
1297 if (!ft_completed
) {
1298 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1299 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1301 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1302 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1303 /* 802.1X::portControl = Auto */
1304 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1305 wpa_s
->eapol_received
= 0;
1306 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1307 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1308 (wpa_s
->current_ssid
&&
1309 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1310 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1311 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1312 } else if (!ft_completed
) {
1313 /* Timeout for receiving the first EAPOL packet */
1314 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1316 wpa_supplicant_cancel_scan(wpa_s
);
1318 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1319 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1321 * We are done; the driver will take care of RSN 4-way
1324 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1325 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1326 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1327 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1328 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1329 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1331 * The driver will take care of RSN 4-way handshake, so we need
1332 * to allow EAPOL supplicant to complete its work without
1333 * waiting for WPA supplicant.
1335 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1336 } else if (ft_completed
) {
1338 * FT protocol completed - make sure EAPOL state machine ends
1339 * up in authenticated.
1341 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1342 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1343 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1344 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1347 if (wpa_s
->pending_eapol_rx
) {
1348 struct os_time now
, age
;
1350 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1351 if (age
.sec
== 0 && age
.usec
< 100000 &&
1352 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1354 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1355 "frame that was received just before "
1356 "association notification");
1357 wpa_supplicant_rx_eapol(
1358 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1359 wpabuf_head(wpa_s
->pending_eapol_rx
),
1360 wpabuf_len(wpa_s
->pending_eapol_rx
));
1362 wpabuf_free(wpa_s
->pending_eapol_rx
);
1363 wpa_s
->pending_eapol_rx
= NULL
;
1366 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1367 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1368 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1369 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1370 /* Set static WEP keys again */
1371 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1374 #ifdef CONFIG_IBSS_RSN
1375 if (wpa_s
->current_ssid
&&
1376 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1377 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1378 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1379 wpa_s
->ibss_rsn
== NULL
) {
1380 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1381 if (!wpa_s
->ibss_rsn
) {
1382 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1383 wpa_supplicant_deauthenticate(
1384 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1388 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1390 #endif /* CONFIG_IBSS_RSN */
1394 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1399 u8 prev_pending_bssid
[ETH_ALEN
];
1401 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1402 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1404 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1406 * At least Host AP driver and a Prism3 card seemed to be
1407 * generating streams of disconnected events when configuring
1408 * IBSS for WPA-None. Ignore them for now.
1410 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1411 "IBSS/WPA-None mode");
1415 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1416 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1417 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1418 "pre-shared key may be incorrect");
1420 if (!wpa_s
->auto_reconnect_disabled
||
1421 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1422 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1423 "reconnect (wps=%d)",
1424 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1425 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1426 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1428 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1429 "try to re-connect");
1430 wpa_s
->reassociate
= 0;
1431 wpa_s
->disconnected
= 1;
1433 bssid
= wpa_s
->bssid
;
1434 if (is_zero_ether_addr(bssid
))
1435 bssid
= wpa_s
->pending_bssid
;
1436 wpas_connection_failed(wpa_s
, bssid
);
1437 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1438 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1440 MAC2STR(bssid
), reason_code
);
1441 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1442 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1443 wpa_s
->keys_cleared
= 0;
1444 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1446 wpa_supplicant_mark_disassoc(wpa_s
);
1448 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1449 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1453 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1454 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1457 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1459 if (!wpa_s
->pending_mic_error_report
)
1462 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1463 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1464 wpa_s
->pending_mic_error_report
= 0;
1466 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1470 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1471 union wpa_event_data
*data
)
1476 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1477 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1479 if ((wpa_s
->last_michael_mic_error
&&
1480 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1481 wpa_s
->pending_mic_error_report
) {
1482 if (wpa_s
->pending_mic_error_report
) {
1484 * Send the pending MIC error report immediately since
1485 * we are going to start countermeasures and AP better
1488 wpa_sm_key_request(wpa_s
->wpa
, 1,
1489 wpa_s
->pending_mic_error_pairwise
);
1492 /* Send the new MIC error report immediately since we are going
1493 * to start countermeasures and AP better do the same.
1495 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1497 /* initialize countermeasures */
1498 wpa_s
->countermeasures
= 1;
1499 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1502 * Need to wait for completion of request frame. We do not get
1503 * any callback for the message completion, so just wait a
1504 * short while and hope for the best. */
1507 wpa_drv_set_countermeasures(wpa_s
, 1);
1508 wpa_supplicant_deauthenticate(wpa_s
,
1509 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1510 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1512 eloop_register_timeout(60, 0,
1513 wpa_supplicant_stop_countermeasures
,
1515 /* TODO: mark the AP rejected for 60 second. STA is
1516 * allowed to associate with another AP.. */
1518 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1519 if (wpa_s
->mic_errors_seen
) {
1521 * Reduce the effectiveness of Michael MIC error
1522 * reports as a means for attacking against TKIP if
1523 * more than one MIC failure is noticed with the same
1524 * PTK. We delay the transmission of the reports by a
1525 * random time between 0 and 60 seconds in order to
1526 * force the attacker wait 60 seconds before getting
1527 * the information on whether a frame resulted in a MIC
1533 if (os_get_random(rval
, sizeof(rval
)) < 0)
1534 sec
= os_random() % 60;
1536 sec
= WPA_GET_BE32(rval
) % 60;
1537 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1538 "report %d seconds", sec
);
1539 wpa_s
->pending_mic_error_report
= 1;
1540 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1541 eloop_cancel_timeout(
1542 wpa_supplicant_delayed_mic_error_report
,
1544 eloop_register_timeout(
1545 sec
, os_random() % 1000000,
1546 wpa_supplicant_delayed_mic_error_report
,
1549 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1551 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1552 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1553 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1555 wpa_s
->last_michael_mic_error
= t
.sec
;
1556 wpa_s
->mic_errors_seen
++;
1560 #ifdef CONFIG_TERMINATE_ONLASTIF
1561 static int any_interfaces(struct wpa_supplicant
*head
)
1563 struct wpa_supplicant
*wpa_s
;
1565 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1566 if (!wpa_s
->interface_removed
)
1570 #endif /* CONFIG_TERMINATE_ONLASTIF */
1574 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1575 union wpa_event_data
*data
)
1577 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1580 switch (data
->interface_status
.ievent
) {
1581 case EVENT_INTERFACE_ADDED
:
1582 if (!wpa_s
->interface_removed
)
1584 wpa_s
->interface_removed
= 0;
1585 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1586 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1587 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1588 "driver after interface was added");
1591 case EVENT_INTERFACE_REMOVED
:
1592 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1593 wpa_s
->interface_removed
= 1;
1594 wpa_supplicant_mark_disassoc(wpa_s
);
1595 l2_packet_deinit(wpa_s
->l2
);
1597 #ifdef CONFIG_IBSS_RSN
1598 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1599 wpa_s
->ibss_rsn
= NULL
;
1600 #endif /* CONFIG_IBSS_RSN */
1601 #ifdef CONFIG_TERMINATE_ONLASTIF
1602 /* check if last interface */
1603 if (!any_interfaces(wpa_s
->global
->ifaces
))
1605 #endif /* CONFIG_TERMINATE_ONLASTIF */
1611 #ifdef CONFIG_PEERKEY
1613 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1614 union wpa_event_data
*data
)
1618 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1620 #endif /* CONFIG_PEERKEY */
1624 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1625 union wpa_event_data
*data
)
1629 switch (data
->tdls
.oper
) {
1630 case TDLS_REQUEST_SETUP
:
1631 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1633 case TDLS_REQUEST_TEARDOWN
:
1634 /* request from driver to add FTIE */
1635 wpa_tdls_recv_teardown_notify(wpa_s
->wpa
, data
->tdls
.peer
,
1636 data
->tdls
.reason_code
);
1640 #endif /* CONFIG_TDLS */
1643 #ifdef CONFIG_IEEE80211R
1645 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1646 union wpa_event_data
*data
)
1651 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1652 data
->ft_ies
.ies_len
,
1653 data
->ft_ies
.ft_action
,
1654 data
->ft_ies
.target_ap
,
1655 data
->ft_ies
.ric_ies
,
1656 data
->ft_ies
.ric_ies_len
) < 0) {
1657 /* TODO: prevent MLME/driver from trying to associate? */
1660 #endif /* CONFIG_IEEE80211R */
1663 #ifdef CONFIG_IBSS_RSN
1664 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1665 union wpa_event_data
*data
)
1667 struct wpa_ssid
*ssid
;
1668 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1672 ssid
= wpa_s
->current_ssid
;
1675 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1678 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1680 #endif /* CONFIG_IBSS_RSN */
1683 #ifdef CONFIG_IEEE80211R
1684 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1687 const u8
*sta_addr
, *target_ap_addr
;
1690 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1691 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1692 return; /* only SME case supported for now */
1693 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1696 return; /* Only FT Action Response is supported for now */
1697 sta_addr
= data
+ 1;
1698 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1699 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1700 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1701 MACSTR
" TargetAP " MACSTR
" status %u",
1702 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1704 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1705 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1706 " in FT Action Response", MAC2STR(sta_addr
));
1711 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1712 "failure (status code %d)", status
);
1713 /* TODO: report error to FT code(?) */
1717 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1718 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1719 target_ap_addr
, NULL
, 0) < 0)
1724 struct wpa_bss
*bss
;
1725 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1727 wpa_s
->sme
.freq
= bss
->freq
;
1728 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1729 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1732 #endif /* CONFIG_SME */
1734 #endif /* CONFIG_IEEE80211R */
1737 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1738 struct unprot_deauth
*e
)
1740 #ifdef CONFIG_IEEE80211W
1741 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1742 "dropped: " MACSTR
" -> " MACSTR
1743 " (reason code %u)",
1744 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1745 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1746 #endif /* CONFIG_IEEE80211W */
1750 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1751 struct unprot_disassoc
*e
)
1753 #ifdef CONFIG_IEEE80211W
1754 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1755 "dropped: " MACSTR
" -> " MACSTR
1756 " (reason code %u)",
1757 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1758 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1759 #endif /* CONFIG_IEEE80211W */
1763 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1764 union wpa_event_data
*data
)
1766 struct wpa_supplicant
*wpa_s
= ctx
;
1767 u16 reason_code
= 0;
1769 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1770 event
!= EVENT_INTERFACE_ENABLED
&&
1771 event
!= EVENT_INTERFACE_STATUS
) {
1772 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1777 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1778 event
, wpa_s
->ifname
);
1782 sme_event_auth(wpa_s
, data
);
1785 wpa_supplicant_event_assoc(wpa_s
, data
);
1787 case EVENT_DISASSOC
:
1788 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1790 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1791 data
->disassoc_info
.reason_code
);
1792 if (data
->disassoc_info
.addr
)
1793 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1794 MAC2STR(data
->disassoc_info
.addr
));
1797 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1798 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1799 data
->disassoc_info
.addr
);
1802 #endif /* CONFIG_AP */
1804 reason_code
= data
->disassoc_info
.reason_code
;
1805 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1806 data
->disassoc_info
.ie
,
1807 data
->disassoc_info
.ie_len
);
1809 wpas_p2p_disassoc_notif(
1810 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1811 data
->disassoc_info
.ie
,
1812 data
->disassoc_info
.ie_len
);
1813 #endif /* CONFIG_P2P */
1815 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1816 sme_event_disassoc(wpa_s
, data
);
1819 if (event
== EVENT_DEAUTH
) {
1820 wpa_dbg(wpa_s
, MSG_DEBUG
,
1821 "Deauthentication notification");
1823 reason_code
= data
->deauth_info
.reason_code
;
1824 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1825 data
->deauth_info
.reason_code
);
1826 if (data
->deauth_info
.addr
) {
1827 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
1829 MAC2STR(data
->deauth_info
.
1832 wpa_hexdump(MSG_DEBUG
,
1833 "Deauthentication frame IE(s)",
1834 data
->deauth_info
.ie
,
1835 data
->deauth_info
.ie_len
);
1837 wpas_p2p_deauth_notif(
1838 wpa_s
, data
->deauth_info
.addr
,
1840 data
->deauth_info
.ie
,
1841 data
->deauth_info
.ie_len
);
1842 #endif /* CONFIG_P2P */
1846 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
1847 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1848 data
->deauth_info
.addr
);
1851 #endif /* CONFIG_AP */
1852 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
1854 case EVENT_MICHAEL_MIC_FAILURE
:
1855 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1857 #ifndef CONFIG_NO_SCAN_PROCESSING
1858 case EVENT_SCAN_RESULTS
:
1859 wpa_supplicant_event_scan_results(wpa_s
, data
);
1861 #endif /* CONFIG_NO_SCAN_PROCESSING */
1862 case EVENT_ASSOCINFO
:
1863 wpa_supplicant_event_associnfo(wpa_s
, data
);
1865 case EVENT_INTERFACE_STATUS
:
1866 wpa_supplicant_event_interface_status(wpa_s
, data
);
1868 case EVENT_PMKID_CANDIDATE
:
1869 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1871 #ifdef CONFIG_PEERKEY
1872 case EVENT_STKSTART
:
1873 wpa_supplicant_event_stkstart(wpa_s
, data
);
1875 #endif /* CONFIG_PEERKEY */
1878 wpa_supplicant_event_tdls(wpa_s
, data
);
1880 #endif /* CONFIG_TDLS */
1881 #ifdef CONFIG_IEEE80211R
1882 case EVENT_FT_RESPONSE
:
1883 wpa_supplicant_event_ft_response(wpa_s
, data
);
1885 #endif /* CONFIG_IEEE80211R */
1886 #ifdef CONFIG_IBSS_RSN
1887 case EVENT_IBSS_RSN_START
:
1888 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1890 #endif /* CONFIG_IBSS_RSN */
1891 case EVENT_ASSOC_REJECT
:
1892 if (data
->assoc_reject
.bssid
)
1893 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1894 "bssid=" MACSTR
" status_code=%u",
1895 MAC2STR(data
->assoc_reject
.bssid
),
1896 data
->assoc_reject
.status_code
);
1898 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1900 data
->assoc_reject
.status_code
);
1901 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1902 sme_event_assoc_reject(wpa_s
, data
);
1904 case EVENT_AUTH_TIMED_OUT
:
1905 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1906 sme_event_auth_timed_out(wpa_s
, data
);
1908 case EVENT_ASSOC_TIMED_OUT
:
1909 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1910 sme_event_assoc_timed_out(wpa_s
, data
);
1913 case EVENT_TX_STATUS
:
1914 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
1915 " type=%d stype=%d",
1916 MAC2STR(data
->tx_status
.dst
),
1917 data
->tx_status
.type
, data
->tx_status
.stype
);
1918 if (wpa_s
->ap_iface
== NULL
) {
1920 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1921 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
1922 wpas_send_action_tx_status(
1923 wpa_s
, data
->tx_status
.dst
,
1924 data
->tx_status
.data
,
1925 data
->tx_status
.data_len
,
1926 data
->tx_status
.ack
?
1927 P2P_SEND_ACTION_SUCCESS
:
1928 P2P_SEND_ACTION_NO_ACK
);
1929 #endif /* CONFIG_P2P */
1933 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
1934 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
1936 * Catch TX status events for Action frames we sent via group
1937 * interface in GO mode.
1939 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1940 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
1941 os_memcmp(wpa_s
->parent
->pending_action_dst
,
1942 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
1943 wpas_send_action_tx_status(
1944 wpa_s
->parent
, data
->tx_status
.dst
,
1945 data
->tx_status
.data
,
1946 data
->tx_status
.data_len
,
1947 data
->tx_status
.ack
?
1948 P2P_SEND_ACTION_SUCCESS
:
1949 P2P_SEND_ACTION_NO_ACK
);
1952 #endif /* CONFIG_P2P */
1953 switch (data
->tx_status
.type
) {
1954 case WLAN_FC_TYPE_MGMT
:
1955 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1956 data
->tx_status
.data_len
,
1957 data
->tx_status
.stype
,
1958 data
->tx_status
.ack
);
1960 case WLAN_FC_TYPE_DATA
:
1961 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1962 data
->tx_status
.data
,
1963 data
->tx_status
.data_len
,
1964 data
->tx_status
.ack
);
1968 case EVENT_RX_FROM_UNKNOWN
:
1969 if (wpa_s
->ap_iface
== NULL
)
1971 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1972 data
->rx_from_unknown
.len
);
1975 if (wpa_s
->ap_iface
== NULL
) {
1978 const struct ieee80211_mgmt
*mgmt
;
1979 mgmt
= (const struct ieee80211_mgmt
*)
1980 data
->rx_mgmt
.frame
;
1981 fc
= le_to_host16(mgmt
->frame_control
);
1982 stype
= WLAN_FC_GET_STYPE(fc
);
1983 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
1984 data
->rx_mgmt
.frame_len
> 24) {
1985 const u8
*src
= mgmt
->sa
;
1986 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
1987 size_t ie_len
= data
->rx_mgmt
.frame_len
-
1988 (mgmt
->u
.probe_req
.variable
-
1989 data
->rx_mgmt
.frame
);
1990 wpas_p2p_probe_req_rx(wpa_s
, src
, ie
, ie_len
);
1993 #endif /* CONFIG_P2P */
1994 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
1995 "management frame in non-AP mode");
1998 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2000 #endif /* CONFIG_AP */
2001 case EVENT_RX_ACTION
:
2002 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2003 " Category=%u DataLen=%d freq=%d MHz",
2004 MAC2STR(data
->rx_action
.sa
),
2005 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2006 data
->rx_action
.freq
);
2007 #ifdef CONFIG_IEEE80211R
2008 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2009 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2010 data
->rx_action
.len
);
2013 #endif /* CONFIG_IEEE80211R */
2014 #ifdef CONFIG_IEEE80211W
2016 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2017 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2018 data
->rx_action
.data
,
2019 data
->rx_action
.len
);
2022 #endif /* CONFIG_SME */
2023 #endif /* CONFIG_IEEE80211W */
2025 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2027 data
->rx_action
.bssid
,
2028 data
->rx_action
.category
,
2029 data
->rx_action
.data
,
2030 data
->rx_action
.len
, data
->rx_action
.freq
);
2031 #endif /* CONFIG_P2P */
2033 case EVENT_RX_PROBE_REQ
:
2034 if (data
->rx_probe_req
.sa
== NULL
||
2035 data
->rx_probe_req
.ie
== NULL
)
2038 if (wpa_s
->ap_iface
) {
2039 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2040 data
->rx_probe_req
.sa
,
2041 data
->rx_probe_req
.ie
,
2042 data
->rx_probe_req
.ie_len
);
2045 #endif /* CONFIG_AP */
2047 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2048 data
->rx_probe_req
.ie
,
2049 data
->rx_probe_req
.ie_len
);
2050 #endif /* CONFIG_P2P */
2053 case EVENT_REMAIN_ON_CHANNEL
:
2054 wpas_p2p_remain_on_channel_cb(
2055 wpa_s
, data
->remain_on_channel
.freq
,
2056 data
->remain_on_channel
.duration
);
2058 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2059 wpas_p2p_cancel_remain_on_channel_cb(
2060 wpa_s
, data
->remain_on_channel
.freq
);
2062 case EVENT_P2P_DEV_FOUND
: {
2063 struct p2p_peer_info peer_info
;
2065 os_memset(&peer_info
, 0, sizeof(peer_info
));
2066 if (data
->p2p_dev_found
.dev_addr
)
2067 os_memcpy(peer_info
.p2p_device_addr
,
2068 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2069 if (data
->p2p_dev_found
.pri_dev_type
)
2070 os_memcpy(peer_info
.pri_dev_type
,
2071 data
->p2p_dev_found
.pri_dev_type
,
2072 sizeof(peer_info
.pri_dev_type
));
2073 if (data
->p2p_dev_found
.dev_name
)
2074 os_strlcpy(peer_info
.device_name
,
2075 data
->p2p_dev_found
.dev_name
,
2076 sizeof(peer_info
.device_name
));
2077 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2078 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2079 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2082 * FIX: new_device=1 is not necessarily correct. We should
2083 * maintain a P2P peer database in wpa_supplicant and update
2084 * this information based on whether the peer is truly new.
2086 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2089 case EVENT_P2P_GO_NEG_REQ_RX
:
2090 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2091 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2093 case EVENT_P2P_GO_NEG_COMPLETED
:
2094 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2096 case EVENT_P2P_PROV_DISC_REQUEST
:
2097 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2098 data
->p2p_prov_disc_req
.config_methods
,
2099 data
->p2p_prov_disc_req
.dev_addr
,
2100 data
->p2p_prov_disc_req
.pri_dev_type
,
2101 data
->p2p_prov_disc_req
.dev_name
,
2102 data
->p2p_prov_disc_req
.supp_config_methods
,
2103 data
->p2p_prov_disc_req
.dev_capab
,
2104 data
->p2p_prov_disc_req
.group_capab
);
2106 case EVENT_P2P_PROV_DISC_RESPONSE
:
2107 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2108 data
->p2p_prov_disc_resp
.config_methods
);
2110 case EVENT_P2P_SD_REQUEST
:
2111 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2112 data
->p2p_sd_req
.sa
,
2113 data
->p2p_sd_req
.dialog_token
,
2114 data
->p2p_sd_req
.update_indic
,
2115 data
->p2p_sd_req
.tlvs
,
2116 data
->p2p_sd_req
.tlvs_len
);
2118 case EVENT_P2P_SD_RESPONSE
:
2119 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2120 data
->p2p_sd_resp
.update_indic
,
2121 data
->p2p_sd_resp
.tlvs
,
2122 data
->p2p_sd_resp
.tlvs_len
);
2124 #endif /* CONFIG_P2P */
2125 #ifdef CONFIG_CLIENT_MLME
2126 case EVENT_MLME_RX
: {
2127 struct ieee80211_rx_status rx_status
;
2128 os_memset(&rx_status
, 0, sizeof(rx_status
));
2129 rx_status
.freq
= data
->mlme_rx
.freq
;
2130 rx_status
.channel
= data
->mlme_rx
.channel
;
2131 rx_status
.ssi
= data
->mlme_rx
.ssi
;
2132 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
2136 #endif /* CONFIG_CLIENT_MLME */
2137 case EVENT_EAPOL_RX
:
2138 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2139 data
->eapol_rx
.data
,
2140 data
->eapol_rx
.data_len
);
2142 case EVENT_SIGNAL_CHANGE
:
2143 bgscan_notify_signal_change(
2144 wpa_s
, data
->signal_change
.above_threshold
,
2145 data
->signal_change
.current_signal
,
2146 data
->signal_change
.current_noise
,
2147 data
->signal_change
.current_txrate
);
2149 case EVENT_INTERFACE_ENABLED
:
2150 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2151 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2153 if (!wpa_s
->ap_iface
) {
2154 wpa_supplicant_set_state(wpa_s
,
2156 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2158 wpa_supplicant_set_state(wpa_s
,
2160 #else /* CONFIG_AP */
2161 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2162 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2163 #endif /* CONFIG_AP */
2166 case EVENT_INTERFACE_DISABLED
:
2167 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2168 wpa_supplicant_mark_disassoc(wpa_s
);
2169 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2171 case EVENT_CHANNEL_LIST_CHANGED
:
2172 if (wpa_s
->drv_priv
== NULL
)
2173 break; /* Ignore event during drv initialization */
2175 wpas_p2p_update_channel_list(wpa_s
);
2176 #endif /* CONFIG_P2P */
2178 case EVENT_INTERFACE_UNAVAILABLE
:
2180 wpas_p2p_interface_unavailable(wpa_s
);
2181 #endif /* CONFIG_P2P */
2183 case EVENT_BEST_CHANNEL
:
2184 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2186 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2187 data
->best_chan
.freq_overall
);
2188 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2189 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2190 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2192 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2193 data
->best_chan
.freq_5
,
2194 data
->best_chan
.freq_overall
);
2195 #endif /* CONFIG_P2P */
2197 case EVENT_UNPROT_DEAUTH
:
2198 wpa_supplicant_event_unprot_deauth(wpa_s
,
2199 &data
->unprot_deauth
);
2201 case EVENT_UNPROT_DISASSOC
:
2202 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2203 &data
->unprot_disassoc
);
2205 case EVENT_STATION_LOW_ACK
:
2207 if (wpa_s
->ap_iface
&& data
)
2208 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2209 data
->low_ack
.addr
);
2210 #endif /* CONFIG_AP */
2212 case EVENT_IBSS_PEER_LOST
:
2213 #ifdef CONFIG_IBSS_RSN
2214 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2215 #endif /* CONFIG_IBSS_RSN */
2218 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);