2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "ap/hostapd.h"
33 #include "common/ieee802_11_defs.h"
34 #include "common/ieee802_11_common.h"
35 #include "crypto/random.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
38 #include "wps_supplicant.h"
41 #include "gas_query.h"
42 #include "p2p_supplicant.h"
50 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
52 struct wpa_ssid
*ssid
, *old_ssid
;
54 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
57 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
59 ssid
= wpa_supplicant_get_ssid(wpa_s
);
61 wpa_msg(wpa_s
, MSG_INFO
,
62 "No network configuration found for the current AP");
67 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
71 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
73 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
74 WPA_KEY_MGMT_WPA_NONE
|
75 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
76 WPA_KEY_MGMT_PSK_SHA256
|
77 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
79 size_t wpa_ie_len
= sizeof(wpa_ie
);
80 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
83 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
86 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
87 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
88 old_ssid
= wpa_s
->current_ssid
;
89 wpa_s
->current_ssid
= ssid
;
90 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
91 wpa_supplicant_initiate_eapol(wpa_s
);
92 if (old_ssid
!= wpa_s
->current_ssid
)
93 wpas_notify_network_changed(wpa_s
);
99 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
102 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
104 if (wpa_s
->countermeasures
) {
105 wpa_s
->countermeasures
= 0;
106 wpa_drv_set_countermeasures(wpa_s
, 0);
107 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
108 wpa_supplicant_req_scan(wpa_s
, 0, 0);
113 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
117 #ifdef CONFIG_IBSS_RSN
118 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
119 wpa_s
->ibss_rsn
= NULL
;
120 #endif /* CONFIG_IBSS_RSN */
123 wpa_supplicant_ap_deinit(wpa_s
);
124 #endif /* CONFIG_AP */
126 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
129 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
130 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
131 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
132 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
133 wpa_s
->current_bss
= NULL
;
134 wpa_s
->assoc_freq
= 0;
135 #ifdef CONFIG_IEEE80211R
137 if (wpa_s
->sme
.ft_ies
)
138 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
139 #endif /* CONFIG_SME */
140 #endif /* CONFIG_IEEE80211R */
143 wpas_notify_bssid_changed(wpa_s
);
145 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
146 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
147 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
148 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
149 wpa_s
->ap_ies_from_associnfo
= 0;
153 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
155 struct wpa_ie_data ie
;
159 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
163 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
164 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
165 ie
.pmkid
+ i
* PMKID_LEN
,
167 if (pmksa_set
== 0) {
168 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
173 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
174 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
178 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
179 union wpa_event_data
*data
)
182 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
186 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
187 " index=%d preauth=%d",
188 MAC2STR(data
->pmkid_candidate
.bssid
),
189 data
->pmkid_candidate
.index
,
190 data
->pmkid_candidate
.preauth
);
192 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
193 data
->pmkid_candidate
.index
,
194 data
->pmkid_candidate
.preauth
);
198 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
200 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
201 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
204 #ifdef IEEE8021X_EAPOL
205 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
206 wpa_s
->current_ssid
&&
207 !(wpa_s
->current_ssid
->eapol_flags
&
208 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
209 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
210 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
211 * plaintext or static WEP keys). */
214 #endif /* IEEE8021X_EAPOL */
221 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
222 * @wpa_s: pointer to wpa_supplicant data
223 * @ssid: Configuration data for the network
224 * Returns: 0 on success, -1 on failure
226 * This function is called when starting authentication with a network that is
227 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
229 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
230 struct wpa_ssid
*ssid
)
232 #ifdef IEEE8021X_EAPOL
233 int aka
= 0, sim
= 0, type
;
235 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
238 if (ssid
->eap
.eap_methods
== NULL
) {
242 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
243 while (eap
->vendor
!= EAP_VENDOR_IETF
||
244 eap
->method
!= EAP_TYPE_NONE
) {
245 if (eap
->vendor
== EAP_VENDOR_IETF
) {
246 if (eap
->method
== EAP_TYPE_SIM
)
248 else if (eap
->method
== EAP_TYPE_AKA
)
255 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
257 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
261 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
262 "use SIM, but neither EAP-SIM nor EAP-AKA are "
267 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
268 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
270 type
= SCARD_TRY_BOTH
;
272 type
= SCARD_USIM_ONLY
;
274 type
= SCARD_GSM_SIM_ONLY
;
276 wpa_s
->scard
= scard_init(type
);
277 if (wpa_s
->scard
== NULL
) {
278 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
282 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
283 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
284 #endif /* IEEE8021X_EAPOL */
290 #ifndef CONFIG_NO_SCAN_PROCESSING
291 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
292 struct wpa_ssid
*ssid
)
296 if (ssid
->mixed_cell
)
300 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
302 #endif /* CONFIG_WPS */
304 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
305 if (ssid
->wep_key_len
[i
]) {
310 #ifdef IEEE8021X_EAPOL
311 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
312 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
313 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
315 #endif /* IEEE8021X_EAPOL */
317 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
320 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
326 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
327 struct wpa_ssid
*ssid
,
328 struct wpa_scan_res
*bss
)
330 struct wpa_ie_data ie
;
332 const u8
*rsn_ie
, *wpa_ie
;
336 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
340 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
341 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
342 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
343 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
344 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
346 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
347 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
350 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
351 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
357 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
359 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
364 if (!(ie
.proto
& ssid
->proto
)) {
365 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
370 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
371 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
376 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
377 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
382 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
383 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
388 #ifdef CONFIG_IEEE80211W
389 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
390 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
391 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
395 #endif /* CONFIG_IEEE80211W */
397 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
401 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
402 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
405 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
406 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
412 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
414 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
419 if (!(ie
.proto
& ssid
->proto
)) {
420 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
425 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
426 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
431 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
432 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
437 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
438 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
443 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
447 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
448 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
449 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
453 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
454 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
458 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
465 static int freq_allowed(int *freqs
, int freq
)
472 for (i
= 0; freqs
[i
]; i
++)
473 if (freqs
[i
] == freq
)
479 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
480 int i
, struct wpa_scan_res
*bss
,
481 struct wpa_ssid
*group
)
484 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
486 struct wpa_blacklist
*e
;
488 struct wpa_ssid
*ssid
;
490 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
491 ssid_
= ie
? ie
+ 2 : (u8
*) "";
492 ssid_len
= ie
? ie
[1] : 0;
494 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
495 wpa_ie_len
= ie
? ie
[1] : 0;
497 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
498 rsn_ie_len
= ie
? ie
[1] : 0;
500 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
501 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
502 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
503 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
504 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
506 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
509 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
511 * When only a single network is enabled, we can
512 * trigger blacklisting on the first failure. This
513 * should not be done with multiple enabled networks to
514 * avoid getting forced to move into a worse ESS on
515 * single error if there are no other BSSes of the
520 if (e
->count
> limit
) {
521 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
522 "(count=%d limit=%d)", e
->count
, limit
);
528 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
532 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
534 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
535 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
537 if (ssid
->disabled
) {
538 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
543 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
544 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
549 if (wpa
&& ssid
->ssid_len
== 0 &&
550 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
553 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
554 /* Only allow wildcard SSID match if an AP
555 * advertises active WPS operation that matches
558 if (ssid
->ssid_len
== 0 &&
559 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
562 #endif /* CONFIG_WPS */
565 (ssid_len
!= ssid
->ssid_len
||
566 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
567 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
571 if (ssid
->bssid_set
&&
572 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
573 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
577 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
581 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
582 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
583 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
584 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
589 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
590 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
595 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
596 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
601 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
602 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
609 * TODO: skip the AP if its P2P IE has Group Formation
610 * bit set in the P2P Group Capability Bitmap and we
611 * are not in Group Formation with that device.
613 #endif /* CONFIG_P2P */
615 /* Matching configuration found */
619 /* No matching configuration found */
624 static struct wpa_bss
*
625 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
626 struct wpa_scan_results
*scan_res
,
627 struct wpa_ssid
*group
,
628 struct wpa_ssid
**selected_ssid
)
632 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
635 for (i
= 0; i
< scan_res
->num
; i
++) {
636 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
640 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
644 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
645 ssid
= ie
? ie
+ 2 : (u8
*) "";
646 ssid_len
= ie
? ie
[1] : 0;
648 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
650 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
651 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
658 static struct wpa_bss
*
659 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
660 struct wpa_scan_results
*scan_res
,
661 struct wpa_ssid
**selected_ssid
)
663 struct wpa_bss
*selected
= NULL
;
666 while (selected
== NULL
) {
667 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
668 selected
= wpa_supplicant_select_bss(
669 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
675 if (selected
== NULL
&& wpa_s
->blacklist
) {
676 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
677 "blacklist and try again");
678 wpa_blacklist_clear(wpa_s
);
679 wpa_s
->blacklist_cleared
++;
680 } else if (selected
== NULL
)
688 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
689 int timeout_sec
, int timeout_usec
)
691 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
693 * No networks are enabled; short-circuit request so
694 * we don't wait timeout seconds before transitioning
697 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
700 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
704 void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
705 struct wpa_bss
*selected
,
706 struct wpa_ssid
*ssid
)
708 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
709 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
710 "PBC session overlap");
712 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
714 #endif /* CONFIG_P2P */
717 wpas_wps_cancel(wpa_s
);
718 #endif /* CONFIG_WPS */
723 * Do not trigger new association unless the BSSID has changed or if
724 * reassociation is requested. If we are in process of associating with
725 * the selected BSSID, do not trigger new attempt.
727 if (wpa_s
->reassociate
||
728 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
729 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
730 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
731 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
733 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
734 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
737 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association: "
738 "reassociate: %d selected: "MACSTR
" bssid: " MACSTR
739 " pending: " MACSTR
" wpa_state: %s",
740 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
741 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
742 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
743 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
745 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
751 static struct wpa_ssid
*
752 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
755 struct wpa_ssid
*ssid
;
757 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
758 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
762 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
763 ssid
->mode
== IEEE80211_MODE_AP
)
771 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
772 * on BSS added and BSS changed events */
773 static void wpa_supplicant_rsn_preauth_scan_results(
774 struct wpa_supplicant
*wpa_s
)
778 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
781 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
782 const u8
*ssid
, *rsn
;
784 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
788 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
792 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
798 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
799 struct wpa_bss
*selected
,
800 struct wpa_ssid
*ssid
,
801 struct wpa_scan_results
*scan_res
)
804 struct wpa_scan_res
*current_bss
= NULL
;
807 if (wpa_s
->reassociate
)
808 return 1; /* explicit request to reassociate */
809 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
810 return 1; /* we are not associated; continue */
811 if (wpa_s
->current_ssid
== NULL
)
812 return 1; /* unknown current SSID */
813 if (wpa_s
->current_ssid
!= ssid
)
814 return 1; /* different network block */
816 if (wpas_driver_bss_selection(wpa_s
))
817 return 0; /* Driver-based roaming */
819 for (i
= 0; i
< scan_res
->num
; i
++) {
820 struct wpa_scan_res
*res
= scan_res
->res
[i
];
822 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
825 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
828 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
829 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
836 return 1; /* current BSS not seen in scan results */
838 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
839 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
840 MAC2STR(current_bss
->bssid
), current_bss
->level
);
841 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
842 MAC2STR(selected
->bssid
), selected
->level
);
844 if (wpa_s
->current_ssid
->bssid_set
&&
845 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
847 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
848 "has preferred BSSID");
853 if (current_bss
->level
< 0) {
854 if (current_bss
->level
< -85)
856 else if (current_bss
->level
< -80)
858 else if (current_bss
->level
< -75)
860 else if (current_bss
->level
< -70)
865 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
866 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
874 /* Return < 0 if no scan results could be fetched. */
875 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
876 union wpa_event_data
*data
)
878 struct wpa_bss
*selected
;
879 struct wpa_ssid
*ssid
= NULL
;
880 struct wpa_scan_results
*scan_res
;
886 #endif /* CONFIG_AP */
888 wpa_supplicant_notify_scanning(wpa_s
, 0);
890 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
891 data
? &data
->scan_info
:
893 if (scan_res
== NULL
) {
894 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
896 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
898 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
902 #ifndef CONFIG_NO_RANDOM_POOL
907 for (i
= 0; i
< num
; i
++) {
909 struct wpa_scan_res
*res
= scan_res
->res
[i
];
910 buf
[0] = res
->bssid
[5];
911 buf
[1] = res
->qual
& 0xff;
912 buf
[2] = res
->noise
& 0xff;
913 buf
[3] = res
->level
& 0xff;
914 buf
[4] = res
->tsf
& 0xff;
915 random_add_randomness(buf
, sizeof(buf
));
917 #endif /* CONFIG_NO_RANDOM_POOL */
919 if (wpa_s
->scan_res_handler
) {
920 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
921 struct wpa_scan_results
*scan_res
);
923 scan_res_handler
= wpa_s
->scan_res_handler
;
924 wpa_s
->scan_res_handler
= NULL
;
925 scan_res_handler(wpa_s
, scan_res
);
927 wpa_scan_results_free(scan_res
);
932 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
934 if (wpa_s
->ap_iface
->scan_cb
)
935 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
936 #endif /* CONFIG_AP */
937 wpa_scan_results_free(scan_res
);
941 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
942 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
943 wpas_notify_scan_results(wpa_s
);
945 wpas_notify_scan_done(wpa_s
, 1);
947 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
948 wpa_scan_results_free(scan_res
);
952 if (wpa_s
->disconnected
) {
953 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
954 wpa_scan_results_free(scan_res
);
958 if (!wpas_driver_bss_selection(wpa_s
) &&
959 bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
960 wpa_scan_results_free(scan_res
);
964 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
968 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
970 wpa_scan_results_free(scan_res
);
973 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
974 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
976 wpa_scan_results_free(scan_res
);
977 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
978 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
980 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
981 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
982 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
984 int timeout_sec
= wpa_s
->scan_interval
;
985 int timeout_usec
= 0;
987 if (wpa_s
->p2p_in_provisioning
) {
989 * Use shorter wait during P2P Provisioning
990 * state to speed up group formation.
993 timeout_usec
= 250000;
995 #endif /* CONFIG_P2P */
996 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1004 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1005 union wpa_event_data
*data
)
1007 const char *rn
, *rn2
;
1008 struct wpa_supplicant
*ifs
;
1010 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
1012 * If no scan results could be fetched, then no need to
1013 * notify those interfaces that did not actually request
1020 * Check other interfaces to see if they have the same radio-name. If
1021 * so, they get updated with this same scan info.
1023 if (!wpa_s
->driver
->get_radio_name
)
1026 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
1027 if (rn
== NULL
|| rn
[0] == '\0')
1030 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
1031 "sharing same radio (%s) in event_scan_results", rn
);
1033 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
1034 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
1037 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
1038 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1039 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1040 "sibling", ifs
->ifname
);
1041 _wpa_supplicant_event_scan_results(ifs
, data
);
1046 #endif /* CONFIG_NO_SCAN_PROCESSING */
1049 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1050 union wpa_event_data
*data
)
1052 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1055 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1056 if (data
->assoc_info
.req_ies
)
1057 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1058 data
->assoc_info
.req_ies_len
);
1059 if (data
->assoc_info
.resp_ies
) {
1060 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1061 data
->assoc_info
.resp_ies_len
);
1063 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1064 data
->assoc_info
.resp_ies_len
);
1065 #endif /* CONFIG_TDLS */
1067 if (data
->assoc_info
.beacon_ies
)
1068 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1069 data
->assoc_info
.beacon_ies
,
1070 data
->assoc_info
.beacon_ies_len
);
1071 if (data
->assoc_info
.freq
)
1072 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1073 data
->assoc_info
.freq
);
1075 p
= data
->assoc_info
.req_ies
;
1076 l
= data
->assoc_info
.req_ies_len
;
1078 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1079 while (p
&& l
>= 2) {
1082 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1086 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1087 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1088 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1089 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1092 wpa_find_assoc_pmkid(wpa_s
);
1098 if (!found
&& data
->assoc_info
.req_ies
)
1099 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1101 #ifdef CONFIG_IEEE80211R
1103 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1105 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1106 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1107 data
->assoc_info
.resp_ies
,
1108 data
->assoc_info
.resp_ies_len
,
1110 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1111 "Reassociation Response failed");
1112 wpa_supplicant_deauthenticate(
1113 wpa_s
, WLAN_REASON_INVALID_IE
);
1118 p
= data
->assoc_info
.resp_ies
;
1119 l
= data
->assoc_info
.resp_ies_len
;
1121 #ifdef CONFIG_WPS_STRICT
1122 if (p
&& wpa_s
->current_ssid
&&
1123 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1125 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1127 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1128 "include WPS IE in (Re)Association Response");
1132 if (wps_validate_assoc_resp(wps
) < 0) {
1134 wpa_supplicant_deauthenticate(
1135 wpa_s
, WLAN_REASON_INVALID_IE
);
1140 #endif /* CONFIG_WPS_STRICT */
1142 /* Go through the IEs and make a copy of the MDIE, if present. */
1143 while (p
&& l
>= 2) {
1146 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1150 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1151 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1152 wpa_s
->sme
.ft_used
= 1;
1153 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1154 MOBILITY_DOMAIN_ID_LEN
);
1160 #endif /* CONFIG_SME */
1162 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1163 data
->assoc_info
.resp_ies_len
);
1164 #endif /* CONFIG_IEEE80211R */
1166 /* WPA/RSN IE from Beacon/ProbeResp */
1167 p
= data
->assoc_info
.beacon_ies
;
1168 l
= data
->assoc_info
.beacon_ies_len
;
1170 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1172 wpa_found
= rsn_found
= 0;
1173 while (p
&& l
>= 2) {
1176 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1181 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1182 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1184 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1188 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1190 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1197 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1198 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1199 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1200 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1201 if (wpa_found
|| rsn_found
)
1202 wpa_s
->ap_ies_from_associnfo
= 1;
1204 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1205 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1206 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1208 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1209 wpa_supplicant_update_scan_results(wpa_s
);
1212 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1218 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1219 union wpa_event_data
*data
)
1224 struct wpa_driver_capa capa
;
1227 if (wpa_s
->ap_iface
) {
1228 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1229 data
->assoc_info
.addr
,
1230 data
->assoc_info
.req_ies
,
1231 data
->assoc_info
.req_ies_len
,
1232 data
->assoc_info
.reassoc
);
1235 #endif /* CONFIG_AP */
1237 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1238 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1241 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1242 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1243 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1244 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1245 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1246 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1247 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1248 MACSTR
, MAC2STR(bssid
));
1249 random_add_randomness(bssid
, ETH_ALEN
);
1250 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1251 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1252 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1254 wpas_notify_bssid_changed(wpa_s
);
1256 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1257 wpa_clear_keys(wpa_s
, bssid
);
1259 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1260 wpa_supplicant_disassociate(
1261 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1264 if (wpa_s
->current_ssid
) {
1265 struct wpa_bss
*bss
= NULL
;
1266 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1267 if (ssid
->ssid_len
> 0)
1268 bss
= wpa_bss_get(wpa_s
, bssid
,
1269 ssid
->ssid
, ssid
->ssid_len
);
1271 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1273 wpa_s
->current_bss
= bss
;
1278 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1279 wpa_s
->sme
.prev_bssid_set
= 1;
1280 #endif /* CONFIG_SME */
1282 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1283 if (wpa_s
->current_ssid
) {
1284 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1285 * initialized before association, but for other modes,
1286 * initialize PC/SC here, if the current configuration needs
1287 * smartcard or SIM/USIM. */
1288 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1290 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1292 l2_packet_notify_auth_start(wpa_s
->l2
);
1295 * Set portEnabled first to FALSE in order to get EAP state machine out
1296 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1297 * state machine may transit to AUTHENTICATING state based on obsolete
1298 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1299 * AUTHENTICATED without ever giving chance to EAP state machine to
1302 if (!ft_completed
) {
1303 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1304 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1306 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1307 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1308 /* 802.1X::portControl = Auto */
1309 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1310 wpa_s
->eapol_received
= 0;
1311 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1312 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1313 (wpa_s
->current_ssid
&&
1314 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1315 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1316 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1317 } else if (!ft_completed
) {
1318 /* Timeout for receiving the first EAPOL packet */
1319 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1321 wpa_supplicant_cancel_scan(wpa_s
);
1323 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1324 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1326 * We are done; the driver will take care of RSN 4-way
1329 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1330 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1331 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1332 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1333 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1334 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1336 * The driver will take care of RSN 4-way handshake, so we need
1337 * to allow EAPOL supplicant to complete its work without
1338 * waiting for WPA supplicant.
1340 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1341 } else if (ft_completed
) {
1343 * FT protocol completed - make sure EAPOL state machine ends
1344 * up in authenticated.
1346 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1347 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1348 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1349 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1352 if (wpa_s
->pending_eapol_rx
) {
1353 struct os_time now
, age
;
1355 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1356 if (age
.sec
== 0 && age
.usec
< 100000 &&
1357 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1359 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1360 "frame that was received just before "
1361 "association notification");
1362 wpa_supplicant_rx_eapol(
1363 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1364 wpabuf_head(wpa_s
->pending_eapol_rx
),
1365 wpabuf_len(wpa_s
->pending_eapol_rx
));
1367 wpabuf_free(wpa_s
->pending_eapol_rx
);
1368 wpa_s
->pending_eapol_rx
= NULL
;
1371 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1372 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1373 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1374 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1375 /* Set static WEP keys again */
1376 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1379 #ifdef CONFIG_IBSS_RSN
1380 if (wpa_s
->current_ssid
&&
1381 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1382 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1383 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
1384 wpa_s
->ibss_rsn
== NULL
) {
1385 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
1386 if (!wpa_s
->ibss_rsn
) {
1387 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
1388 wpa_supplicant_deauthenticate(
1389 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1393 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
1395 #endif /* CONFIG_IBSS_RSN */
1399 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1404 u8 prev_pending_bssid
[ETH_ALEN
];
1406 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1407 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1409 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1411 * At least Host AP driver and a Prism3 card seemed to be
1412 * generating streams of disconnected events when configuring
1413 * IBSS for WPA-None. Ignore them for now.
1415 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1416 "IBSS/WPA-None mode");
1420 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1421 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1422 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1423 "pre-shared key may be incorrect");
1425 if (!wpa_s
->auto_reconnect_disabled
||
1426 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1427 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1428 "reconnect (wps=%d)",
1429 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1430 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1431 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1433 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1434 "try to re-connect");
1435 wpa_s
->reassociate
= 0;
1436 wpa_s
->disconnected
= 1;
1438 bssid
= wpa_s
->bssid
;
1439 if (is_zero_ether_addr(bssid
))
1440 bssid
= wpa_s
->pending_bssid
;
1441 wpas_connection_failed(wpa_s
, bssid
);
1442 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1443 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1445 MAC2STR(bssid
), reason_code
);
1446 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1447 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1448 wpa_s
->keys_cleared
= 0;
1449 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1451 wpa_supplicant_mark_disassoc(wpa_s
);
1453 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1454 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
1458 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1459 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1462 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1464 if (!wpa_s
->pending_mic_error_report
)
1467 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1468 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1469 wpa_s
->pending_mic_error_report
= 0;
1471 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1475 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1476 union wpa_event_data
*data
)
1481 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1482 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1484 if ((wpa_s
->last_michael_mic_error
&&
1485 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1486 wpa_s
->pending_mic_error_report
) {
1487 if (wpa_s
->pending_mic_error_report
) {
1489 * Send the pending MIC error report immediately since
1490 * we are going to start countermeasures and AP better
1493 wpa_sm_key_request(wpa_s
->wpa
, 1,
1494 wpa_s
->pending_mic_error_pairwise
);
1497 /* Send the new MIC error report immediately since we are going
1498 * to start countermeasures and AP better do the same.
1500 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1502 /* initialize countermeasures */
1503 wpa_s
->countermeasures
= 1;
1504 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1507 * Need to wait for completion of request frame. We do not get
1508 * any callback for the message completion, so just wait a
1509 * short while and hope for the best. */
1512 wpa_drv_set_countermeasures(wpa_s
, 1);
1513 wpa_supplicant_deauthenticate(wpa_s
,
1514 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1515 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1517 eloop_register_timeout(60, 0,
1518 wpa_supplicant_stop_countermeasures
,
1520 /* TODO: mark the AP rejected for 60 second. STA is
1521 * allowed to associate with another AP.. */
1523 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1524 if (wpa_s
->mic_errors_seen
) {
1526 * Reduce the effectiveness of Michael MIC error
1527 * reports as a means for attacking against TKIP if
1528 * more than one MIC failure is noticed with the same
1529 * PTK. We delay the transmission of the reports by a
1530 * random time between 0 and 60 seconds in order to
1531 * force the attacker wait 60 seconds before getting
1532 * the information on whether a frame resulted in a MIC
1538 if (os_get_random(rval
, sizeof(rval
)) < 0)
1539 sec
= os_random() % 60;
1541 sec
= WPA_GET_BE32(rval
) % 60;
1542 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1543 "report %d seconds", sec
);
1544 wpa_s
->pending_mic_error_report
= 1;
1545 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1546 eloop_cancel_timeout(
1547 wpa_supplicant_delayed_mic_error_report
,
1549 eloop_register_timeout(
1550 sec
, os_random() % 1000000,
1551 wpa_supplicant_delayed_mic_error_report
,
1554 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1556 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1557 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1558 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1560 wpa_s
->last_michael_mic_error
= t
.sec
;
1561 wpa_s
->mic_errors_seen
++;
1565 #ifdef CONFIG_TERMINATE_ONLASTIF
1566 static int any_interfaces(struct wpa_supplicant
*head
)
1568 struct wpa_supplicant
*wpa_s
;
1570 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1571 if (!wpa_s
->interface_removed
)
1575 #endif /* CONFIG_TERMINATE_ONLASTIF */
1579 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1580 union wpa_event_data
*data
)
1582 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1585 switch (data
->interface_status
.ievent
) {
1586 case EVENT_INTERFACE_ADDED
:
1587 if (!wpa_s
->interface_removed
)
1589 wpa_s
->interface_removed
= 0;
1590 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1591 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1592 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1593 "driver after interface was added");
1596 case EVENT_INTERFACE_REMOVED
:
1597 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1598 wpa_s
->interface_removed
= 1;
1599 wpa_supplicant_mark_disassoc(wpa_s
);
1600 l2_packet_deinit(wpa_s
->l2
);
1602 #ifdef CONFIG_IBSS_RSN
1603 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1604 wpa_s
->ibss_rsn
= NULL
;
1605 #endif /* CONFIG_IBSS_RSN */
1606 #ifdef CONFIG_TERMINATE_ONLASTIF
1607 /* check if last interface */
1608 if (!any_interfaces(wpa_s
->global
->ifaces
))
1610 #endif /* CONFIG_TERMINATE_ONLASTIF */
1616 #ifdef CONFIG_PEERKEY
1618 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1619 union wpa_event_data
*data
)
1623 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1625 #endif /* CONFIG_PEERKEY */
1629 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
1630 union wpa_event_data
*data
)
1634 switch (data
->tdls
.oper
) {
1635 case TDLS_REQUEST_SETUP
:
1636 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
1638 case TDLS_REQUEST_TEARDOWN
:
1639 /* request from driver to add FTIE */
1640 wpa_tdls_recv_teardown_notify(wpa_s
->wpa
, data
->tdls
.peer
,
1641 data
->tdls
.reason_code
);
1645 #endif /* CONFIG_TDLS */
1648 #ifdef CONFIG_IEEE80211R
1650 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1651 union wpa_event_data
*data
)
1656 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1657 data
->ft_ies
.ies_len
,
1658 data
->ft_ies
.ft_action
,
1659 data
->ft_ies
.target_ap
,
1660 data
->ft_ies
.ric_ies
,
1661 data
->ft_ies
.ric_ies_len
) < 0) {
1662 /* TODO: prevent MLME/driver from trying to associate? */
1665 #endif /* CONFIG_IEEE80211R */
1668 #ifdef CONFIG_IBSS_RSN
1669 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1670 union wpa_event_data
*data
)
1672 struct wpa_ssid
*ssid
;
1673 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1677 ssid
= wpa_s
->current_ssid
;
1680 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1683 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1685 #endif /* CONFIG_IBSS_RSN */
1688 #ifdef CONFIG_IEEE80211R
1689 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1692 const u8
*sta_addr
, *target_ap_addr
;
1695 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1696 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1697 return; /* only SME case supported for now */
1698 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1701 return; /* Only FT Action Response is supported for now */
1702 sta_addr
= data
+ 1;
1703 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1704 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1705 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1706 MACSTR
" TargetAP " MACSTR
" status %u",
1707 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1709 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1710 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1711 " in FT Action Response", MAC2STR(sta_addr
));
1716 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1717 "failure (status code %d)", status
);
1718 /* TODO: report error to FT code(?) */
1722 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1723 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1724 target_ap_addr
, NULL
, 0) < 0)
1729 struct wpa_bss
*bss
;
1730 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1732 wpa_s
->sme
.freq
= bss
->freq
;
1733 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1734 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1737 #endif /* CONFIG_SME */
1739 #endif /* CONFIG_IEEE80211R */
1742 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1743 struct unprot_deauth
*e
)
1745 #ifdef CONFIG_IEEE80211W
1746 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1747 "dropped: " MACSTR
" -> " MACSTR
1748 " (reason code %u)",
1749 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1750 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1751 #endif /* CONFIG_IEEE80211W */
1755 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1756 struct unprot_disassoc
*e
)
1758 #ifdef CONFIG_IEEE80211W
1759 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1760 "dropped: " MACSTR
" -> " MACSTR
1761 " (reason code %u)",
1762 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1763 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1764 #endif /* CONFIG_IEEE80211W */
1768 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1769 union wpa_event_data
*data
)
1771 struct wpa_supplicant
*wpa_s
= ctx
;
1772 u16 reason_code
= 0;
1774 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1775 event
!= EVENT_INTERFACE_ENABLED
&&
1776 event
!= EVENT_INTERFACE_STATUS
) {
1777 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1782 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1783 event
, wpa_s
->ifname
);
1787 sme_event_auth(wpa_s
, data
);
1790 wpa_supplicant_event_assoc(wpa_s
, data
);
1792 case EVENT_DISASSOC
:
1793 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1795 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1796 data
->disassoc_info
.reason_code
);
1797 if (data
->disassoc_info
.addr
)
1798 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1799 MAC2STR(data
->disassoc_info
.addr
));
1802 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1803 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1804 data
->disassoc_info
.addr
);
1807 #endif /* CONFIG_AP */
1809 reason_code
= data
->disassoc_info
.reason_code
;
1810 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1811 data
->disassoc_info
.ie
,
1812 data
->disassoc_info
.ie_len
);
1814 wpas_p2p_disassoc_notif(
1815 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1816 data
->disassoc_info
.ie
,
1817 data
->disassoc_info
.ie_len
);
1818 #endif /* CONFIG_P2P */
1820 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1821 sme_event_disassoc(wpa_s
, data
);
1824 if (event
== EVENT_DEAUTH
) {
1825 wpa_dbg(wpa_s
, MSG_DEBUG
,
1826 "Deauthentication notification");
1828 reason_code
= data
->deauth_info
.reason_code
;
1829 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1830 data
->deauth_info
.reason_code
);
1831 if (data
->deauth_info
.addr
) {
1832 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
1834 MAC2STR(data
->deauth_info
.
1837 wpa_hexdump(MSG_DEBUG
,
1838 "Deauthentication frame IE(s)",
1839 data
->deauth_info
.ie
,
1840 data
->deauth_info
.ie_len
);
1842 wpas_p2p_deauth_notif(
1843 wpa_s
, data
->deauth_info
.addr
,
1845 data
->deauth_info
.ie
,
1846 data
->deauth_info
.ie_len
);
1847 #endif /* CONFIG_P2P */
1851 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
1852 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1853 data
->deauth_info
.addr
);
1856 #endif /* CONFIG_AP */
1857 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
1859 case EVENT_MICHAEL_MIC_FAILURE
:
1860 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1862 #ifndef CONFIG_NO_SCAN_PROCESSING
1863 case EVENT_SCAN_RESULTS
:
1864 wpa_supplicant_event_scan_results(wpa_s
, data
);
1866 #endif /* CONFIG_NO_SCAN_PROCESSING */
1867 case EVENT_ASSOCINFO
:
1868 wpa_supplicant_event_associnfo(wpa_s
, data
);
1870 case EVENT_INTERFACE_STATUS
:
1871 wpa_supplicant_event_interface_status(wpa_s
, data
);
1873 case EVENT_PMKID_CANDIDATE
:
1874 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1876 #ifdef CONFIG_PEERKEY
1877 case EVENT_STKSTART
:
1878 wpa_supplicant_event_stkstart(wpa_s
, data
);
1880 #endif /* CONFIG_PEERKEY */
1883 wpa_supplicant_event_tdls(wpa_s
, data
);
1885 #endif /* CONFIG_TDLS */
1886 #ifdef CONFIG_IEEE80211R
1887 case EVENT_FT_RESPONSE
:
1888 wpa_supplicant_event_ft_response(wpa_s
, data
);
1890 #endif /* CONFIG_IEEE80211R */
1891 #ifdef CONFIG_IBSS_RSN
1892 case EVENT_IBSS_RSN_START
:
1893 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1895 #endif /* CONFIG_IBSS_RSN */
1896 case EVENT_ASSOC_REJECT
:
1897 if (data
->assoc_reject
.bssid
)
1898 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1899 "bssid=" MACSTR
" status_code=%u",
1900 MAC2STR(data
->assoc_reject
.bssid
),
1901 data
->assoc_reject
.status_code
);
1903 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1905 data
->assoc_reject
.status_code
);
1906 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1907 sme_event_assoc_reject(wpa_s
, data
);
1909 case EVENT_AUTH_TIMED_OUT
:
1910 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1911 sme_event_auth_timed_out(wpa_s
, data
);
1913 case EVENT_ASSOC_TIMED_OUT
:
1914 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1915 sme_event_assoc_timed_out(wpa_s
, data
);
1918 case EVENT_TX_STATUS
:
1919 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
1920 " type=%d stype=%d",
1921 MAC2STR(data
->tx_status
.dst
),
1922 data
->tx_status
.type
, data
->tx_status
.stype
);
1923 if (wpa_s
->ap_iface
== NULL
) {
1925 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1926 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
1927 wpas_send_action_tx_status(
1928 wpa_s
, data
->tx_status
.dst
,
1929 data
->tx_status
.data
,
1930 data
->tx_status
.data_len
,
1931 data
->tx_status
.ack
?
1932 P2P_SEND_ACTION_SUCCESS
:
1933 P2P_SEND_ACTION_NO_ACK
);
1934 #endif /* CONFIG_P2P */
1938 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
1939 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
1941 * Catch TX status events for Action frames we sent via group
1942 * interface in GO mode.
1944 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1945 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
1946 os_memcmp(wpa_s
->parent
->pending_action_dst
,
1947 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
1948 wpas_send_action_tx_status(
1949 wpa_s
->parent
, data
->tx_status
.dst
,
1950 data
->tx_status
.data
,
1951 data
->tx_status
.data_len
,
1952 data
->tx_status
.ack
?
1953 P2P_SEND_ACTION_SUCCESS
:
1954 P2P_SEND_ACTION_NO_ACK
);
1957 #endif /* CONFIG_P2P */
1958 switch (data
->tx_status
.type
) {
1959 case WLAN_FC_TYPE_MGMT
:
1960 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1961 data
->tx_status
.data_len
,
1962 data
->tx_status
.stype
,
1963 data
->tx_status
.ack
);
1965 case WLAN_FC_TYPE_DATA
:
1966 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1967 data
->tx_status
.data
,
1968 data
->tx_status
.data_len
,
1969 data
->tx_status
.ack
);
1973 case EVENT_RX_FROM_UNKNOWN
:
1974 if (wpa_s
->ap_iface
== NULL
)
1976 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1977 data
->rx_from_unknown
.len
);
1980 if (wpa_s
->ap_iface
== NULL
) {
1983 const struct ieee80211_mgmt
*mgmt
;
1984 mgmt
= (const struct ieee80211_mgmt
*)
1985 data
->rx_mgmt
.frame
;
1986 fc
= le_to_host16(mgmt
->frame_control
);
1987 stype
= WLAN_FC_GET_STYPE(fc
);
1988 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
1989 data
->rx_mgmt
.frame_len
> 24) {
1990 const u8
*src
= mgmt
->sa
;
1991 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
1992 size_t ie_len
= data
->rx_mgmt
.frame_len
-
1993 (mgmt
->u
.probe_req
.variable
-
1994 data
->rx_mgmt
.frame
);
1995 wpas_p2p_probe_req_rx(wpa_s
, src
, mgmt
->da
,
1996 mgmt
->bssid
, ie
, ie_len
);
1999 #endif /* CONFIG_P2P */
2000 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
2001 "management frame in non-AP mode");
2004 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
2006 #endif /* CONFIG_AP */
2007 case EVENT_RX_ACTION
:
2008 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2009 " Category=%u DataLen=%d freq=%d MHz",
2010 MAC2STR(data
->rx_action
.sa
),
2011 data
->rx_action
.category
, (int) data
->rx_action
.len
,
2012 data
->rx_action
.freq
);
2013 #ifdef CONFIG_IEEE80211R
2014 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
2015 ft_rx_action(wpa_s
, data
->rx_action
.data
,
2016 data
->rx_action
.len
);
2019 #endif /* CONFIG_IEEE80211R */
2020 #ifdef CONFIG_IEEE80211W
2022 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
2023 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
2024 data
->rx_action
.data
,
2025 data
->rx_action
.len
);
2028 #endif /* CONFIG_SME */
2029 #endif /* CONFIG_IEEE80211W */
2031 if (data
->rx_action
.category
== WLAN_ACTION_PUBLIC
&&
2032 gas_query_rx(wpa_s
->gas
, data
->rx_action
.da
,
2033 data
->rx_action
.sa
, data
->rx_action
.bssid
,
2034 data
->rx_action
.data
, data
->rx_action
.len
,
2035 data
->rx_action
.freq
) == 0)
2037 #endif /* CONFIG_GAS */
2039 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
2041 data
->rx_action
.bssid
,
2042 data
->rx_action
.category
,
2043 data
->rx_action
.data
,
2044 data
->rx_action
.len
, data
->rx_action
.freq
);
2045 #endif /* CONFIG_P2P */
2047 case EVENT_RX_PROBE_REQ
:
2048 if (data
->rx_probe_req
.sa
== NULL
||
2049 data
->rx_probe_req
.ie
== NULL
)
2052 if (wpa_s
->ap_iface
) {
2053 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
2054 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
);
2061 #endif /* CONFIG_AP */
2063 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
2064 data
->rx_probe_req
.da
,
2065 data
->rx_probe_req
.bssid
,
2066 data
->rx_probe_req
.ie
,
2067 data
->rx_probe_req
.ie_len
);
2068 #endif /* CONFIG_P2P */
2071 case EVENT_REMAIN_ON_CHANNEL
:
2072 wpas_p2p_remain_on_channel_cb(
2073 wpa_s
, data
->remain_on_channel
.freq
,
2074 data
->remain_on_channel
.duration
);
2076 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
2077 wpas_p2p_cancel_remain_on_channel_cb(
2078 wpa_s
, data
->remain_on_channel
.freq
);
2080 case EVENT_P2P_DEV_FOUND
: {
2081 struct p2p_peer_info peer_info
;
2083 os_memset(&peer_info
, 0, sizeof(peer_info
));
2084 if (data
->p2p_dev_found
.dev_addr
)
2085 os_memcpy(peer_info
.p2p_device_addr
,
2086 data
->p2p_dev_found
.dev_addr
, ETH_ALEN
);
2087 if (data
->p2p_dev_found
.pri_dev_type
)
2088 os_memcpy(peer_info
.pri_dev_type
,
2089 data
->p2p_dev_found
.pri_dev_type
,
2090 sizeof(peer_info
.pri_dev_type
));
2091 if (data
->p2p_dev_found
.dev_name
)
2092 os_strlcpy(peer_info
.device_name
,
2093 data
->p2p_dev_found
.dev_name
,
2094 sizeof(peer_info
.device_name
));
2095 peer_info
.config_methods
= data
->p2p_dev_found
.config_methods
;
2096 peer_info
.dev_capab
= data
->p2p_dev_found
.dev_capab
;
2097 peer_info
.group_capab
= data
->p2p_dev_found
.group_capab
;
2100 * FIX: new_device=1 is not necessarily correct. We should
2101 * maintain a P2P peer database in wpa_supplicant and update
2102 * this information based on whether the peer is truly new.
2104 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
, &peer_info
, 1);
2107 case EVENT_P2P_GO_NEG_REQ_RX
:
2108 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2109 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2111 case EVENT_P2P_GO_NEG_COMPLETED
:
2112 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2114 case EVENT_P2P_PROV_DISC_REQUEST
:
2115 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2116 data
->p2p_prov_disc_req
.config_methods
,
2117 data
->p2p_prov_disc_req
.dev_addr
,
2118 data
->p2p_prov_disc_req
.pri_dev_type
,
2119 data
->p2p_prov_disc_req
.dev_name
,
2120 data
->p2p_prov_disc_req
.supp_config_methods
,
2121 data
->p2p_prov_disc_req
.dev_capab
,
2122 data
->p2p_prov_disc_req
.group_capab
);
2124 case EVENT_P2P_PROV_DISC_RESPONSE
:
2125 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2126 data
->p2p_prov_disc_resp
.config_methods
);
2128 case EVENT_P2P_SD_REQUEST
:
2129 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2130 data
->p2p_sd_req
.sa
,
2131 data
->p2p_sd_req
.dialog_token
,
2132 data
->p2p_sd_req
.update_indic
,
2133 data
->p2p_sd_req
.tlvs
,
2134 data
->p2p_sd_req
.tlvs_len
);
2136 case EVENT_P2P_SD_RESPONSE
:
2137 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2138 data
->p2p_sd_resp
.update_indic
,
2139 data
->p2p_sd_resp
.tlvs
,
2140 data
->p2p_sd_resp
.tlvs_len
);
2142 #endif /* CONFIG_P2P */
2143 #ifdef CONFIG_CLIENT_MLME
2144 case EVENT_MLME_RX
: {
2145 struct ieee80211_rx_status rx_status
;
2146 os_memset(&rx_status
, 0, sizeof(rx_status
));
2147 rx_status
.freq
= data
->mlme_rx
.freq
;
2148 rx_status
.channel
= data
->mlme_rx
.channel
;
2149 rx_status
.ssi
= data
->mlme_rx
.ssi
;
2150 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
2154 #endif /* CONFIG_CLIENT_MLME */
2155 case EVENT_EAPOL_RX
:
2156 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2157 data
->eapol_rx
.data
,
2158 data
->eapol_rx
.data_len
);
2160 case EVENT_SIGNAL_CHANGE
:
2161 bgscan_notify_signal_change(
2162 wpa_s
, data
->signal_change
.above_threshold
,
2163 data
->signal_change
.current_signal
,
2164 data
->signal_change
.current_noise
,
2165 data
->signal_change
.current_txrate
);
2167 case EVENT_INTERFACE_ENABLED
:
2168 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2169 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2171 if (!wpa_s
->ap_iface
) {
2172 wpa_supplicant_set_state(wpa_s
,
2174 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2176 wpa_supplicant_set_state(wpa_s
,
2178 #else /* CONFIG_AP */
2179 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2180 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2181 #endif /* CONFIG_AP */
2184 case EVENT_INTERFACE_DISABLED
:
2185 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2186 wpa_supplicant_mark_disassoc(wpa_s
);
2187 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2189 case EVENT_CHANNEL_LIST_CHANGED
:
2190 if (wpa_s
->drv_priv
== NULL
)
2191 break; /* Ignore event during drv initialization */
2193 wpas_p2p_update_channel_list(wpa_s
);
2194 #endif /* CONFIG_P2P */
2196 case EVENT_INTERFACE_UNAVAILABLE
:
2198 wpas_p2p_interface_unavailable(wpa_s
);
2199 #endif /* CONFIG_P2P */
2201 case EVENT_BEST_CHANNEL
:
2202 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2204 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2205 data
->best_chan
.freq_overall
);
2206 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2207 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2208 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2210 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2211 data
->best_chan
.freq_5
,
2212 data
->best_chan
.freq_overall
);
2213 #endif /* CONFIG_P2P */
2215 case EVENT_UNPROT_DEAUTH
:
2216 wpa_supplicant_event_unprot_deauth(wpa_s
,
2217 &data
->unprot_deauth
);
2219 case EVENT_UNPROT_DISASSOC
:
2220 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2221 &data
->unprot_disassoc
);
2223 case EVENT_STATION_LOW_ACK
:
2225 if (wpa_s
->ap_iface
&& data
)
2226 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2227 data
->low_ack
.addr
);
2228 #endif /* CONFIG_AP */
2230 case EVENT_IBSS_PEER_LOST
:
2231 #ifdef CONFIG_IBSS_RSN
2232 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
2233 #endif /* CONFIG_IBSS_RSN */
2235 case EVENT_DRIVER_GTK_REKEY
:
2236 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
2237 wpa_s
->bssid
, ETH_ALEN
))
2241 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
2242 data
->driver_gtk_rekey
.replay_ctr
);
2245 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);