2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2010, 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_printf(MSG_DEBUG
, "Select network based on association "
58 ssid
= wpa_supplicant_get_ssid(wpa_s
);
60 wpa_printf(MSG_INFO
, "No network configuration found for the "
66 wpa_printf(MSG_DEBUG
, "Selected network is disabled");
70 wpa_printf(MSG_DEBUG
, "Network configuration found for the current "
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 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
119 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
120 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
121 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
122 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
123 wpa_s
->current_bss
= NULL
;
124 wpa_s
->assoc_freq
= 0;
126 wpas_notify_bssid_changed(wpa_s
);
128 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
129 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
130 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
131 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
132 wpa_s
->ap_ies_from_associnfo
= 0;
136 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
138 struct wpa_ie_data ie
;
142 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
146 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
147 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
148 ie
.pmkid
+ i
* PMKID_LEN
,
150 if (pmksa_set
== 0) {
151 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
156 wpa_printf(MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from PMKSA "
157 "cache", pmksa_set
== 0 ? "" : "not ");
161 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
162 union wpa_event_data
*data
)
165 wpa_printf(MSG_DEBUG
, "RSN: No data in PMKID candidate event");
168 wpa_printf(MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
169 " index=%d preauth=%d",
170 MAC2STR(data
->pmkid_candidate
.bssid
),
171 data
->pmkid_candidate
.index
,
172 data
->pmkid_candidate
.preauth
);
174 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
175 data
->pmkid_candidate
.index
,
176 data
->pmkid_candidate
.preauth
);
180 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
182 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
183 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
186 #ifdef IEEE8021X_EAPOL
187 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
188 wpa_s
->current_ssid
&&
189 !(wpa_s
->current_ssid
->eapol_flags
&
190 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
191 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
192 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
193 * plaintext or static WEP keys). */
196 #endif /* IEEE8021X_EAPOL */
203 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
204 * @wpa_s: pointer to wpa_supplicant data
205 * @ssid: Configuration data for the network
206 * Returns: 0 on success, -1 on failure
208 * This function is called when starting authentication with a network that is
209 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
211 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
212 struct wpa_ssid
*ssid
)
214 #ifdef IEEE8021X_EAPOL
215 int aka
= 0, sim
= 0, type
;
217 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
220 if (ssid
->eap
.eap_methods
== NULL
) {
224 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
225 while (eap
->vendor
!= EAP_VENDOR_IETF
||
226 eap
->method
!= EAP_TYPE_NONE
) {
227 if (eap
->vendor
== EAP_VENDOR_IETF
) {
228 if (eap
->method
== EAP_TYPE_SIM
)
230 else if (eap
->method
== EAP_TYPE_AKA
)
237 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
239 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
243 wpa_printf(MSG_DEBUG
, "Selected network is configured to use "
244 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
248 wpa_printf(MSG_DEBUG
, "Selected network is configured to use SIM "
249 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
251 type
= SCARD_TRY_BOTH
;
253 type
= SCARD_USIM_ONLY
;
255 type
= SCARD_GSM_SIM_ONLY
;
257 wpa_s
->scard
= scard_init(type
);
258 if (wpa_s
->scard
== NULL
) {
259 wpa_printf(MSG_WARNING
, "Failed to initialize SIM "
263 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
264 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
265 #endif /* IEEE8021X_EAPOL */
271 #ifndef CONFIG_NO_SCAN_PROCESSING
272 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
273 struct wpa_ssid
*ssid
)
277 if (ssid
->mixed_cell
)
281 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
283 #endif /* CONFIG_WPS */
285 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
286 if (ssid
->wep_key_len
[i
]) {
291 #ifdef IEEE8021X_EAPOL
292 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
293 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
294 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
296 #endif /* IEEE8021X_EAPOL */
298 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
304 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
305 struct wpa_ssid
*ssid
,
306 struct wpa_scan_res
*bss
)
308 struct wpa_ie_data ie
;
310 const u8
*rsn_ie
, *wpa_ie
;
314 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
318 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
319 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
320 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
321 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
322 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
324 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
325 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
328 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
329 wpa_printf(MSG_DEBUG
, " skip RSN IE - parse failed");
334 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
336 wpa_printf(MSG_DEBUG
, " selected based on TSN in "
341 if (!(ie
.proto
& ssid
->proto
)) {
342 wpa_printf(MSG_DEBUG
, " skip RSN IE - proto "
347 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
348 wpa_printf(MSG_DEBUG
, " skip RSN IE - PTK cipher "
353 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
354 wpa_printf(MSG_DEBUG
, " skip RSN IE - GTK cipher "
359 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
360 wpa_printf(MSG_DEBUG
, " skip RSN IE - key mgmt "
365 #ifdef CONFIG_IEEE80211W
366 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
367 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
368 wpa_printf(MSG_DEBUG
, " skip RSN IE - no mgmt frame "
372 #endif /* CONFIG_IEEE80211W */
374 wpa_printf(MSG_DEBUG
, " selected based on RSN IE");
378 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
379 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
382 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
383 wpa_printf(MSG_DEBUG
, " skip WPA IE - parse failed");
388 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
390 wpa_printf(MSG_DEBUG
, " selected based on TSN in "
395 if (!(ie
.proto
& ssid
->proto
)) {
396 wpa_printf(MSG_DEBUG
, " skip WPA IE - proto "
401 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
402 wpa_printf(MSG_DEBUG
, " skip WPA IE - PTK cipher "
407 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
408 wpa_printf(MSG_DEBUG
, " skip WPA IE - GTK cipher "
413 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
414 wpa_printf(MSG_DEBUG
, " skip WPA IE - key mgmt "
419 wpa_printf(MSG_DEBUG
, " selected based on WPA IE");
423 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
424 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
425 wpa_printf(MSG_DEBUG
, " skip - no WPA/RSN proto match");
429 /* Allow in non-WPA configuration */
434 static int freq_allowed(int *freqs
, int freq
)
441 for (i
= 0; freqs
[i
]; i
++)
442 if (freqs
[i
] == freq
)
448 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
449 int i
, struct wpa_scan_res
*bss
,
450 struct wpa_ssid
*group
)
453 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
455 struct wpa_blacklist
*e
;
457 struct wpa_ssid
*ssid
;
459 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
460 ssid_
= ie
? ie
+ 2 : (u8
*) "";
461 ssid_len
= ie
? ie
[1] : 0;
463 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
464 wpa_ie_len
= ie
? ie
[1] : 0;
466 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
467 rsn_ie_len
= ie
? ie
[1] : 0;
469 wpa_printf(MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
470 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
471 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
472 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
473 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ?
476 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
479 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
481 * When only a single network is enabled, we can
482 * trigger blacklisting on the first failure. This
483 * should not be done with multiple enabled networks to
484 * avoid getting forced to move into a worse ESS on
485 * single error if there are no other BSSes of the
490 if (e
->count
> limit
) {
491 wpa_printf(MSG_DEBUG
, " skip - blacklisted "
492 "(count=%d limit=%d)", e
->count
, limit
);
498 wpa_printf(MSG_DEBUG
, " skip - SSID not known");
502 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
504 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
505 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
507 if (ssid
->disabled
) {
508 wpa_printf(MSG_DEBUG
, " skip - disabled");
513 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
514 wpa_printf(MSG_DEBUG
, " skip - blacklisted (WPS)");
518 if (wpa
&& ssid
->ssid_len
== 0 &&
519 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
522 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
523 /* Only allow wildcard SSID match if an AP
524 * advertises active WPS operation that matches
527 if (ssid
->ssid_len
== 0 &&
528 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
531 #endif /* CONFIG_WPS */
534 (ssid_len
!= ssid
->ssid_len
||
535 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
536 wpa_printf(MSG_DEBUG
, " skip - SSID mismatch");
540 if (ssid
->bssid_set
&&
541 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
542 wpa_printf(MSG_DEBUG
, " skip - BSSID mismatch");
546 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
550 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
551 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
552 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
553 wpa_printf(MSG_DEBUG
, " skip - non-WPA network not "
558 if (!wpa
&& !wpa_supplicant_match_privacy(bss
, ssid
)) {
559 wpa_printf(MSG_DEBUG
, " skip - privacy mismatch");
563 if (!wpa
&& (bss
->caps
& IEEE80211_CAP_IBSS
)) {
564 wpa_printf(MSG_DEBUG
, " skip - IBSS (adhoc) "
569 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
570 wpa_printf(MSG_DEBUG
, " skip - frequency not "
577 * TODO: skip the AP if its P2P IE has Group Formation
578 * bit set in the P2P Group Capability Bitmap and we
579 * are not in Group Formation with that device.
581 #endif /* CONFIG_P2P */
583 /* Matching configuration found */
587 /* No matching configuration found */
592 static struct wpa_bss
*
593 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
594 struct wpa_scan_results
*scan_res
,
595 struct wpa_ssid
*group
,
596 struct wpa_ssid
**selected_ssid
)
600 wpa_printf(MSG_DEBUG
, "Selecting BSS from priority group %d",
603 for (i
= 0; i
< scan_res
->num
; i
++) {
604 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
608 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
612 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
613 ssid
= ie
? ie
+ 2 : (u8
*) "";
614 ssid_len
= ie
? ie
[1] : 0;
616 wpa_printf(MSG_DEBUG
, " selected BSS " MACSTR
" ssid='%s'",
617 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
618 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
625 static struct wpa_bss
*
626 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
627 struct wpa_scan_results
*scan_res
,
628 struct wpa_ssid
**selected_ssid
)
630 struct wpa_bss
*selected
= NULL
;
633 while (selected
== NULL
) {
634 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
635 selected
= wpa_supplicant_select_bss(
636 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
642 if (selected
== NULL
&& wpa_s
->blacklist
) {
643 wpa_printf(MSG_DEBUG
, "No APs found - clear blacklist "
645 wpa_blacklist_clear(wpa_s
);
646 wpa_s
->blacklist_cleared
++;
647 } else if (selected
== NULL
)
655 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
656 int timeout_sec
, int timeout_usec
)
658 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
660 * No networks are enabled; short-circuit request so
661 * we don't wait timeout seconds before transitioning
664 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
667 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
671 void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
672 struct wpa_bss
*selected
,
673 struct wpa_ssid
*ssid
)
675 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
676 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
677 "PBC session overlap");
679 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
681 #endif /* CONFIG_P2P */
684 wpas_wps_cancel(wpa_s
);
685 #endif /* CONFIG_WPS */
690 * Do not trigger new association unless the BSSID has changed or if
691 * reassociation is requested. If we are in process of associating with
692 * the selected BSSID, do not trigger new attempt.
694 if (wpa_s
->reassociate
||
695 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
696 (wpa_s
->wpa_state
!= WPA_ASSOCIATING
||
697 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
699 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
700 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
703 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
705 wpa_printf(MSG_DEBUG
, "Already associated with the selected "
711 static struct wpa_ssid
*
712 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
715 struct wpa_ssid
*ssid
;
717 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
718 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
722 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
723 ssid
->mode
== IEEE80211_MODE_AP
)
731 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
732 * on BSS added and BSS changed events */
733 static void wpa_supplicant_rsn_preauth_scan_results(
734 struct wpa_supplicant
*wpa_s
, struct wpa_scan_results
*scan_res
)
738 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
741 for (i
= scan_res
->num
- 1; i
>= 0; i
--) {
742 const u8
*ssid
, *rsn
;
743 struct wpa_scan_res
*r
;
745 r
= scan_res
->res
[i
];
747 ssid
= wpa_scan_get_ie(r
, WLAN_EID_SSID
);
751 rsn
= wpa_scan_get_ie(r
, WLAN_EID_RSN
);
755 rsn_preauth_scan_result(wpa_s
->wpa
, r
->bssid
, ssid
, rsn
);
761 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
762 struct wpa_bss
*selected
,
763 struct wpa_ssid
*ssid
,
764 struct wpa_scan_results
*scan_res
)
767 struct wpa_scan_res
*current_bss
= NULL
;
770 if (wpa_s
->reassociate
)
771 return 1; /* explicit request to reassociate */
772 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
773 return 1; /* we are not associated; continue */
774 if (wpa_s
->current_ssid
== NULL
)
775 return 1; /* unknown current SSID */
776 if (wpa_s
->current_ssid
!= ssid
)
777 return 1; /* different network block */
779 for (i
= 0; i
< scan_res
->num
; i
++) {
780 struct wpa_scan_res
*res
= scan_res
->res
[i
];
782 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
785 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
788 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
789 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
796 return 1; /* current BSS not seen in scan results */
798 wpa_printf(MSG_DEBUG
, "Considering within-ESS reassociation");
799 wpa_printf(MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
800 MAC2STR(current_bss
->bssid
), current_bss
->level
);
801 wpa_printf(MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
802 MAC2STR(selected
->bssid
), selected
->level
);
804 if (wpa_s
->current_ssid
->bssid_set
&&
805 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
807 wpa_printf(MSG_DEBUG
, "Allow reassociation - selected BSS has "
813 if (current_bss
->level
< 0) {
814 if (current_bss
->level
< -85)
816 else if (current_bss
->level
< -80)
818 else if (current_bss
->level
< -75)
820 else if (current_bss
->level
< -70)
825 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
826 wpa_printf(MSG_DEBUG
, "Skip roam - too small difference in "
835 static void _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
836 union wpa_event_data
*data
)
838 struct wpa_bss
*selected
;
839 struct wpa_ssid
*ssid
= NULL
;
840 struct wpa_scan_results
*scan_res
;
846 #endif /* CONFIG_AP */
848 wpa_supplicant_notify_scanning(wpa_s
, 0);
850 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
851 data
? &data
->scan_info
:
853 if (scan_res
== NULL
) {
854 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
856 wpa_printf(MSG_DEBUG
, "Failed to get scan results - try "
858 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
862 #ifndef CONFIG_NO_RANDOM_POOL
867 for (i
= 0; i
< num
; i
++) {
869 struct wpa_scan_res
*res
= scan_res
->res
[i
];
870 buf
[0] = res
->bssid
[5];
871 buf
[1] = res
->qual
& 0xff;
872 buf
[2] = res
->noise
& 0xff;
873 buf
[3] = res
->level
& 0xff;
874 buf
[4] = res
->tsf
& 0xff;
875 random_add_randomness(buf
, sizeof(buf
));
877 #endif /* CONFIG_NO_RANDOM_POOL */
879 if (wpa_s
->scan_res_handler
) {
880 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
881 struct wpa_scan_results
*scan_res
);
883 scan_res_handler
= wpa_s
->scan_res_handler
;
884 wpa_s
->scan_res_handler
= NULL
;
885 scan_res_handler(wpa_s
, scan_res
);
887 wpa_scan_results_free(scan_res
);
892 wpa_printf(MSG_DEBUG
, "Ignore scan results in AP mode");
893 wpa_scan_results_free(scan_res
);
897 wpa_printf(MSG_DEBUG
, "%s: New scan results available", wpa_s
->ifname
);
898 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
899 wpas_notify_scan_results(wpa_s
);
901 wpas_notify_scan_done(wpa_s
, 1);
903 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
904 wpa_scan_results_free(scan_res
);
908 if (wpa_s
->disconnected
) {
909 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
910 wpa_scan_results_free(scan_res
);
914 if (bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
915 wpa_scan_results_free(scan_res
);
919 wpa_supplicant_rsn_preauth_scan_results(wpa_s
, scan_res
);
921 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
925 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
927 wpa_scan_results_free(scan_res
);
930 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
932 wpa_scan_results_free(scan_res
);
933 wpa_printf(MSG_DEBUG
, "No suitable network found");
934 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
936 wpa_printf(MSG_DEBUG
, "Setup a new network");
937 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
940 int timeout_usec
= 0;
942 if (wpa_s
->p2p_in_provisioning
) {
944 * Use shorter wait during P2P Provisioning
945 * state to speed up group formation.
948 timeout_usec
= 250000;
950 #endif /* CONFIG_P2P */
951 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
958 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
959 union wpa_event_data
*data
)
961 const char *rn
, *rn2
;
962 struct wpa_supplicant
*ifs
;
964 _wpa_supplicant_event_scan_results(wpa_s
, data
);
967 * Check other interfaces to see if they have the same radio-name. If
968 * so, they get updated with this same scan info.
970 if (!wpa_s
->driver
->get_radio_name
)
973 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
974 if (rn
== NULL
|| rn
[0] == '\0')
977 wpa_printf(MSG_DEBUG
, "%s: Checking for other virtual interfaces "
978 "sharing same radio (%s) in event_scan_results",
981 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
982 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
985 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
986 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
987 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
988 "sibling", ifs
->ifname
);
989 _wpa_supplicant_event_scan_results(ifs
, data
);
994 #endif /* CONFIG_NO_SCAN_PROCESSING */
997 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
998 union wpa_event_data
*data
)
1000 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1003 wpa_printf(MSG_DEBUG
, "Association info event");
1004 if (data
->assoc_info
.req_ies
)
1005 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1006 data
->assoc_info
.req_ies_len
);
1007 if (data
->assoc_info
.resp_ies
)
1008 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1009 data
->assoc_info
.resp_ies_len
);
1010 if (data
->assoc_info
.beacon_ies
)
1011 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1012 data
->assoc_info
.beacon_ies
,
1013 data
->assoc_info
.beacon_ies_len
);
1014 if (data
->assoc_info
.freq
)
1015 wpa_printf(MSG_DEBUG
, "freq=%u MHz", data
->assoc_info
.freq
);
1017 p
= data
->assoc_info
.req_ies
;
1018 l
= data
->assoc_info
.req_ies_len
;
1020 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1021 while (p
&& l
>= 2) {
1024 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1028 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1029 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1030 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1031 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1034 wpa_find_assoc_pmkid(wpa_s
);
1040 if (!found
&& data
->assoc_info
.req_ies
)
1041 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1043 #ifdef CONFIG_IEEE80211R
1045 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1047 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1048 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1049 data
->assoc_info
.resp_ies
,
1050 data
->assoc_info
.resp_ies_len
,
1052 wpa_printf(MSG_DEBUG
, "FT: Validation of "
1053 "Reassociation Response failed");
1054 wpa_supplicant_deauthenticate(
1055 wpa_s
, WLAN_REASON_INVALID_IE
);
1060 p
= data
->assoc_info
.resp_ies
;
1061 l
= data
->assoc_info
.resp_ies_len
;
1063 #ifdef CONFIG_WPS_STRICT
1064 if (wpa_s
->current_ssid
&&
1065 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1067 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1069 wpa_printf(MSG_INFO
, "WPS-STRICT: AP did not include "
1070 "WPS IE in (Re)Association Response");
1074 if (wps_validate_assoc_resp(wps
) < 0) {
1076 wpa_supplicant_deauthenticate(
1077 wpa_s
, WLAN_REASON_INVALID_IE
);
1082 #endif /* CONFIG_WPS_STRICT */
1084 /* Go through the IEs and make a copy of the MDIE, if present. */
1085 while (p
&& l
>= 2) {
1088 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1092 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1093 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1094 wpa_s
->sme
.ft_used
= 1;
1095 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1096 MOBILITY_DOMAIN_ID_LEN
);
1102 #endif /* CONFIG_SME */
1104 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1105 data
->assoc_info
.resp_ies_len
);
1106 #endif /* CONFIG_IEEE80211R */
1108 /* WPA/RSN IE from Beacon/ProbeResp */
1109 p
= data
->assoc_info
.beacon_ies
;
1110 l
= data
->assoc_info
.beacon_ies_len
;
1112 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1114 wpa_found
= rsn_found
= 0;
1115 while (p
&& l
>= 2) {
1118 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1123 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1124 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1126 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1130 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1132 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1139 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1140 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1141 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1142 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1143 if (wpa_found
|| rsn_found
)
1144 wpa_s
->ap_ies_from_associnfo
= 1;
1146 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1152 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1153 union wpa_event_data
*data
)
1158 struct wpa_driver_capa capa
;
1161 if (wpa_s
->ap_iface
) {
1162 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1163 data
->assoc_info
.addr
,
1164 data
->assoc_info
.req_ies
,
1165 data
->assoc_info
.req_ies_len
);
1168 #endif /* CONFIG_AP */
1170 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1171 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1174 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1175 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1176 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1177 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1178 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1179 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1180 wpa_msg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1181 MACSTR
, MAC2STR(bssid
));
1182 random_add_randomness(bssid
, ETH_ALEN
);
1183 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1184 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1185 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1187 wpas_notify_bssid_changed(wpa_s
);
1189 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1190 wpa_clear_keys(wpa_s
, bssid
);
1192 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1193 wpa_supplicant_disassociate(
1194 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1197 if (wpa_s
->current_ssid
) {
1198 struct wpa_bss
*bss
= NULL
;
1199 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1200 if (ssid
->ssid_len
> 0)
1201 bss
= wpa_bss_get(wpa_s
, bssid
,
1202 ssid
->ssid
, ssid
->ssid_len
);
1204 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1206 wpa_s
->current_bss
= bss
;
1211 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1212 wpa_s
->sme
.prev_bssid_set
= 1;
1213 #endif /* CONFIG_SME */
1215 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1216 if (wpa_s
->current_ssid
) {
1217 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1218 * initialized before association, but for other modes,
1219 * initialize PC/SC here, if the current configuration needs
1220 * smartcard or SIM/USIM. */
1221 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1223 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1225 l2_packet_notify_auth_start(wpa_s
->l2
);
1228 * Set portEnabled first to FALSE in order to get EAP state machine out
1229 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1230 * state machine may transit to AUTHENTICATING state based on obsolete
1231 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1232 * AUTHENTICATED without ever giving chance to EAP state machine to
1235 if (!ft_completed
) {
1236 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1237 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1239 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1240 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1241 /* 802.1X::portControl = Auto */
1242 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1243 wpa_s
->eapol_received
= 0;
1244 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1245 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1246 (wpa_s
->current_ssid
&&
1247 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1248 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1249 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1250 } else if (!ft_completed
) {
1251 /* Timeout for receiving the first EAPOL packet */
1252 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1254 wpa_supplicant_cancel_scan(wpa_s
);
1256 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1257 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1259 * We are done; the driver will take care of RSN 4-way
1262 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1263 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1264 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1265 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1266 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1267 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1269 * The driver will take care of RSN 4-way handshake, so we need
1270 * to allow EAPOL supplicant to complete its work without
1271 * waiting for WPA supplicant.
1273 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1276 if (wpa_s
->pending_eapol_rx
) {
1277 struct os_time now
, age
;
1279 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1280 if (age
.sec
== 0 && age
.usec
< 100000 &&
1281 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1283 wpa_printf(MSG_DEBUG
, "Process pending EAPOL frame "
1284 "that was received just before association "
1286 wpa_supplicant_rx_eapol(
1287 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1288 wpabuf_head(wpa_s
->pending_eapol_rx
),
1289 wpabuf_len(wpa_s
->pending_eapol_rx
));
1291 wpabuf_free(wpa_s
->pending_eapol_rx
);
1292 wpa_s
->pending_eapol_rx
= NULL
;
1295 #ifdef CONFIG_BGSCAN
1296 if (wpa_s
->current_ssid
!= wpa_s
->bgscan_ssid
) {
1297 bgscan_deinit(wpa_s
);
1298 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
1299 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
1300 wpa_printf(MSG_DEBUG
, "Failed to initialize "
1303 * Live without bgscan; it is only used as a
1304 * roaming optimization, so the initial
1305 * connection is not affected.
1308 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
1310 wpa_s
->bgscan_ssid
= NULL
;
1312 #endif /* CONFIG_BGSCAN */
1314 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1315 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1316 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1317 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1318 /* Set static WEP keys again */
1319 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1322 #ifdef CONFIG_IBSS_RSN
1323 if (wpa_s
->current_ssid
&&
1324 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1325 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1326 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
)
1327 ibss_rsn_connected(wpa_s
->ibss_rsn
);
1328 #endif /* CONFIG_IBSS_RSN */
1332 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1338 u8 prev_pending_bssid
[ETH_ALEN
];
1340 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1341 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1342 #endif /* CONFIG_SME */
1344 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1346 * At least Host AP driver and a Prism3 card seemed to be
1347 * generating streams of disconnected events when configuring
1348 * IBSS for WPA-None. Ignore them for now.
1350 wpa_printf(MSG_DEBUG
, "Disconnect event - ignore in "
1351 "IBSS/WPA-None mode");
1355 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1356 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1357 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1358 "pre-shared key may be incorrect");
1360 if (!wpa_s
->auto_reconnect_disabled
||
1361 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1362 wpa_printf(MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1363 "reconnect (wps=%d)",
1364 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1365 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1366 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1368 wpa_printf(MSG_DEBUG
, "WPA: Auto connect disabled: do not try "
1370 wpa_s
->reassociate
= 0;
1371 wpa_s
->disconnected
= 1;
1373 bssid
= wpa_s
->bssid
;
1374 if (is_zero_ether_addr(bssid
))
1375 bssid
= wpa_s
->pending_bssid
;
1376 wpas_connection_failed(wpa_s
, bssid
);
1377 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1378 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1380 MAC2STR(bssid
), reason_code
);
1381 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1382 wpa_printf(MSG_DEBUG
, "Disconnect event - remove keys");
1383 wpa_s
->keys_cleared
= 0;
1384 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1386 wpa_supplicant_mark_disassoc(wpa_s
);
1387 bgscan_deinit(wpa_s
);
1388 wpa_s
->bgscan_ssid
= NULL
;
1390 if (authenticating
&&
1391 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
1393 * mac80211-workaround to force deauth on failed auth cmd,
1394 * requires us to remain in authenticating state to allow the
1395 * second authentication attempt to be continued properly.
1397 wpa_printf(MSG_DEBUG
, "SME: Allow pending authentication to "
1398 "proceed after disconnection event");
1399 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1400 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1402 #endif /* CONFIG_SME */
1406 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1407 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1410 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1412 if (!wpa_s
->pending_mic_error_report
)
1415 wpa_printf(MSG_DEBUG
, "WPA: Sending pending MIC error report");
1416 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1417 wpa_s
->pending_mic_error_report
= 0;
1419 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1423 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1424 union wpa_event_data
*data
)
1429 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1430 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1432 if ((wpa_s
->last_michael_mic_error
&&
1433 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1434 wpa_s
->pending_mic_error_report
) {
1435 if (wpa_s
->pending_mic_error_report
) {
1437 * Send the pending MIC error report immediately since
1438 * we are going to start countermeasures and AP better
1441 wpa_sm_key_request(wpa_s
->wpa
, 1,
1442 wpa_s
->pending_mic_error_pairwise
);
1445 /* Send the new MIC error report immediately since we are going
1446 * to start countermeasures and AP better do the same.
1448 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1450 /* initialize countermeasures */
1451 wpa_s
->countermeasures
= 1;
1452 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1455 * Need to wait for completion of request frame. We do not get
1456 * any callback for the message completion, so just wait a
1457 * short while and hope for the best. */
1460 wpa_drv_set_countermeasures(wpa_s
, 1);
1461 wpa_supplicant_deauthenticate(wpa_s
,
1462 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1463 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1465 eloop_register_timeout(60, 0,
1466 wpa_supplicant_stop_countermeasures
,
1468 /* TODO: mark the AP rejected for 60 second. STA is
1469 * allowed to associate with another AP.. */
1471 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1472 if (wpa_s
->mic_errors_seen
) {
1474 * Reduce the effectiveness of Michael MIC error
1475 * reports as a means for attacking against TKIP if
1476 * more than one MIC failure is noticed with the same
1477 * PTK. We delay the transmission of the reports by a
1478 * random time between 0 and 60 seconds in order to
1479 * force the attacker wait 60 seconds before getting
1480 * the information on whether a frame resulted in a MIC
1486 if (os_get_random(rval
, sizeof(rval
)) < 0)
1487 sec
= os_random() % 60;
1489 sec
= WPA_GET_BE32(rval
) % 60;
1490 wpa_printf(MSG_DEBUG
, "WPA: Delay MIC error report %d "
1492 wpa_s
->pending_mic_error_report
= 1;
1493 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1494 eloop_cancel_timeout(
1495 wpa_supplicant_delayed_mic_error_report
,
1497 eloop_register_timeout(
1498 sec
, os_random() % 1000000,
1499 wpa_supplicant_delayed_mic_error_report
,
1502 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1504 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1505 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1506 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1508 wpa_s
->last_michael_mic_error
= t
.sec
;
1509 wpa_s
->mic_errors_seen
++;
1513 #ifdef CONFIG_TERMINATE_ONLASTIF
1514 static int any_interfaces(struct wpa_supplicant
*head
)
1516 struct wpa_supplicant
*wpa_s
;
1518 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1519 if (!wpa_s
->interface_removed
)
1523 #endif /* CONFIG_TERMINATE_ONLASTIF */
1527 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1528 union wpa_event_data
*data
)
1530 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1533 switch (data
->interface_status
.ievent
) {
1534 case EVENT_INTERFACE_ADDED
:
1535 if (!wpa_s
->interface_removed
)
1537 wpa_s
->interface_removed
= 0;
1538 wpa_printf(MSG_DEBUG
, "Configured interface was added.");
1539 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1540 wpa_printf(MSG_INFO
, "Failed to initialize the driver "
1541 "after interface was added.");
1544 case EVENT_INTERFACE_REMOVED
:
1545 wpa_printf(MSG_DEBUG
, "Configured interface was removed.");
1546 wpa_s
->interface_removed
= 1;
1547 wpa_supplicant_mark_disassoc(wpa_s
);
1548 l2_packet_deinit(wpa_s
->l2
);
1550 #ifdef CONFIG_TERMINATE_ONLASTIF
1551 /* check if last interface */
1552 if (!any_interfaces(wpa_s
->global
->ifaces
))
1554 #endif /* CONFIG_TERMINATE_ONLASTIF */
1560 #ifdef CONFIG_PEERKEY
1562 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1563 union wpa_event_data
*data
)
1567 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1569 #endif /* CONFIG_PEERKEY */
1572 #ifdef CONFIG_IEEE80211R
1574 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1575 union wpa_event_data
*data
)
1580 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1581 data
->ft_ies
.ies_len
,
1582 data
->ft_ies
.ft_action
,
1583 data
->ft_ies
.target_ap
,
1584 data
->ft_ies
.ric_ies
,
1585 data
->ft_ies
.ric_ies_len
) < 0) {
1586 /* TODO: prevent MLME/driver from trying to associate? */
1589 #endif /* CONFIG_IEEE80211R */
1592 #ifdef CONFIG_IBSS_RSN
1593 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1594 union wpa_event_data
*data
)
1596 struct wpa_ssid
*ssid
;
1599 ssid
= wpa_s
->current_ssid
;
1602 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1605 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1607 #endif /* CONFIG_IBSS_RSN */
1610 #ifdef CONFIG_IEEE80211R
1611 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1614 const u8
*sta_addr
, *target_ap_addr
;
1617 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1618 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1619 return; /* only SME case supported for now */
1620 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1623 return; /* Only FT Action Response is supported for now */
1624 sta_addr
= data
+ 1;
1625 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1626 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1627 wpa_printf(MSG_DEBUG
, "FT: Received FT Action Response: STA " MACSTR
1628 " TargetAP " MACSTR
" status %u",
1629 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1631 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1632 wpa_printf(MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1633 " in FT Action Response", MAC2STR(sta_addr
));
1638 wpa_printf(MSG_DEBUG
, "FT: FT Action Response indicates "
1639 "failure (status code %d)", status
);
1640 /* TODO: report error to FT code(?) */
1644 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1645 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1646 target_ap_addr
, NULL
, 0) < 0)
1651 struct wpa_bss
*bss
;
1652 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1654 wpa_s
->sme
.freq
= bss
->freq
;
1655 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1656 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1659 #endif /* CONFIG_SME */
1661 #endif /* CONFIG_IEEE80211R */
1664 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1665 struct unprot_deauth
*e
)
1667 #ifdef CONFIG_IEEE80211W
1668 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1669 "dropped: " MACSTR
" -> " MACSTR
1670 " (reason code %u)",
1671 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1672 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1673 #endif /* CONFIG_IEEE80211W */
1677 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1678 struct unprot_disassoc
*e
)
1680 #ifdef CONFIG_IEEE80211W
1681 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1682 "dropped: " MACSTR
" -> " MACSTR
1683 " (reason code %u)",
1684 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1685 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1686 #endif /* CONFIG_IEEE80211W */
1690 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1691 union wpa_event_data
*data
)
1693 struct wpa_supplicant
*wpa_s
= ctx
;
1694 u16 reason_code
= 0;
1696 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1697 event
!= EVENT_INTERFACE_ENABLED
&&
1698 event
!= EVENT_INTERFACE_STATUS
) {
1699 wpa_printf(MSG_DEBUG
, "Ignore event %d while interface is "
1704 wpa_printf(MSG_DEBUG
, "Event %d received on interface %s",
1705 event
, wpa_s
->ifname
);
1709 sme_event_auth(wpa_s
, data
);
1712 wpa_supplicant_event_assoc(wpa_s
, data
);
1714 case EVENT_DISASSOC
:
1715 wpa_printf(MSG_DEBUG
, "Disassociation notification");
1717 wpa_printf(MSG_DEBUG
, " * reason %u",
1718 data
->disassoc_info
.reason_code
);
1719 if (data
->disassoc_info
.addr
)
1720 wpa_printf(MSG_DEBUG
, " * address " MACSTR
,
1721 MAC2STR(data
->disassoc_info
.addr
));
1724 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1725 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1726 data
->disassoc_info
.addr
);
1729 #endif /* CONFIG_AP */
1731 reason_code
= data
->disassoc_info
.reason_code
;
1732 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1733 data
->disassoc_info
.ie
,
1734 data
->disassoc_info
.ie_len
);
1736 wpas_p2p_disassoc_notif(
1737 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1738 data
->disassoc_info
.ie
,
1739 data
->disassoc_info
.ie_len
);
1740 #endif /* CONFIG_P2P */
1742 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1743 sme_event_disassoc(wpa_s
, data
);
1746 if (event
== EVENT_DEAUTH
) {
1747 wpa_printf(MSG_DEBUG
, "Deauthentication notification");
1749 reason_code
= data
->deauth_info
.reason_code
;
1750 wpa_printf(MSG_DEBUG
, " * reason %u",
1751 data
->deauth_info
.reason_code
);
1752 if (data
->deauth_info
.addr
) {
1753 wpa_printf(MSG_DEBUG
, " * address "
1755 MAC2STR(data
->deauth_info
.
1758 wpa_hexdump(MSG_DEBUG
,
1759 "Deauthentication frame IE(s)",
1760 data
->deauth_info
.ie
,
1761 data
->deauth_info
.ie_len
);
1763 wpas_p2p_deauth_notif(
1764 wpa_s
, data
->deauth_info
.addr
,
1766 data
->deauth_info
.ie
,
1767 data
->deauth_info
.ie_len
);
1768 #endif /* CONFIG_P2P */
1772 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
1773 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1774 data
->deauth_info
.addr
);
1777 #endif /* CONFIG_AP */
1778 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
1780 case EVENT_MICHAEL_MIC_FAILURE
:
1781 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1783 #ifndef CONFIG_NO_SCAN_PROCESSING
1784 case EVENT_SCAN_RESULTS
:
1785 wpa_supplicant_event_scan_results(wpa_s
, data
);
1787 #endif /* CONFIG_NO_SCAN_PROCESSING */
1788 case EVENT_ASSOCINFO
:
1789 wpa_supplicant_event_associnfo(wpa_s
, data
);
1791 case EVENT_INTERFACE_STATUS
:
1792 wpa_supplicant_event_interface_status(wpa_s
, data
);
1794 case EVENT_PMKID_CANDIDATE
:
1795 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1797 #ifdef CONFIG_PEERKEY
1798 case EVENT_STKSTART
:
1799 wpa_supplicant_event_stkstart(wpa_s
, data
);
1801 #endif /* CONFIG_PEERKEY */
1802 #ifdef CONFIG_IEEE80211R
1803 case EVENT_FT_RESPONSE
:
1804 wpa_supplicant_event_ft_response(wpa_s
, data
);
1806 #endif /* CONFIG_IEEE80211R */
1807 #ifdef CONFIG_IBSS_RSN
1808 case EVENT_IBSS_RSN_START
:
1809 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1811 #endif /* CONFIG_IBSS_RSN */
1812 case EVENT_ASSOC_REJECT
:
1813 if (data
->assoc_reject
.bssid
)
1814 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1815 "bssid=" MACSTR
" status_code=%u",
1816 MAC2STR(data
->assoc_reject
.bssid
),
1817 data
->assoc_reject
.status_code
);
1819 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1821 data
->assoc_reject
.status_code
);
1822 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1823 sme_event_assoc_reject(wpa_s
, data
);
1825 case EVENT_AUTH_TIMED_OUT
:
1826 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1827 sme_event_auth_timed_out(wpa_s
, data
);
1829 case EVENT_ASSOC_TIMED_OUT
:
1830 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1831 sme_event_assoc_timed_out(wpa_s
, data
);
1834 case EVENT_TX_STATUS
:
1835 wpa_printf(MSG_DEBUG
, "EVENT_TX_STATUS on %s dst=" MACSTR
1836 " type=%d stype=%d",
1837 wpa_s
->ifname
, MAC2STR(data
->tx_status
.dst
),
1838 data
->tx_status
.type
, data
->tx_status
.stype
);
1839 if (wpa_s
->ap_iface
== NULL
) {
1841 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1842 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
1843 wpas_send_action_tx_status(
1844 wpa_s
, data
->tx_status
.dst
,
1845 data
->tx_status
.data
,
1846 data
->tx_status
.data_len
,
1847 data
->tx_status
.ack
?
1848 P2P_SEND_ACTION_SUCCESS
:
1849 P2P_SEND_ACTION_NO_ACK
);
1850 #endif /* CONFIG_P2P */
1854 wpa_printf(MSG_DEBUG
, "EVENT_TX_STATUS pending_dst=" MACSTR
,
1855 MAC2STR(wpa_s
->parent
->pending_action_dst
));
1857 * Catch TX status events for Action frames we sent via group
1858 * interface in GO mode.
1860 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1861 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
1862 os_memcmp(wpa_s
->parent
->pending_action_dst
,
1863 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
1864 wpas_send_action_tx_status(
1865 wpa_s
->parent
, data
->tx_status
.dst
,
1866 data
->tx_status
.data
,
1867 data
->tx_status
.data_len
,
1868 data
->tx_status
.ack
?
1869 P2P_SEND_ACTION_SUCCESS
:
1870 P2P_SEND_ACTION_NO_ACK
);
1873 #endif /* CONFIG_P2P */
1874 switch (data
->tx_status
.type
) {
1875 case WLAN_FC_TYPE_MGMT
:
1876 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1877 data
->tx_status
.data_len
,
1878 data
->tx_status
.stype
,
1879 data
->tx_status
.ack
);
1881 case WLAN_FC_TYPE_DATA
:
1882 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1883 data
->tx_status
.data
,
1884 data
->tx_status
.data_len
,
1885 data
->tx_status
.ack
);
1889 case EVENT_RX_FROM_UNKNOWN
:
1890 if (wpa_s
->ap_iface
== NULL
)
1892 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1893 data
->rx_from_unknown
.len
);
1896 if (wpa_s
->ap_iface
== NULL
) {
1899 const struct ieee80211_mgmt
*mgmt
;
1900 mgmt
= (const struct ieee80211_mgmt
*)
1901 data
->rx_mgmt
.frame
;
1902 fc
= le_to_host16(mgmt
->frame_control
);
1903 stype
= WLAN_FC_GET_STYPE(fc
);
1904 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
1905 data
->rx_mgmt
.frame_len
> 24) {
1906 const u8
*src
= mgmt
->sa
;
1907 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
1908 size_t ie_len
= data
->rx_mgmt
.frame_len
-
1909 (mgmt
->u
.probe_req
.variable
-
1910 data
->rx_mgmt
.frame
);
1911 wpas_p2p_probe_req_rx(wpa_s
, src
, ie
, ie_len
);
1914 #endif /* CONFIG_P2P */
1915 wpa_printf(MSG_DEBUG
, "AP: ignore received management "
1916 "frame in non-AP mode");
1919 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
1921 #endif /* CONFIG_AP */
1922 case EVENT_RX_ACTION
:
1923 wpa_printf(MSG_DEBUG
, "Received Action frame: SA=" MACSTR
1924 " Category=%u DataLen=%d freq=%d MHz",
1925 MAC2STR(data
->rx_action
.sa
),
1926 data
->rx_action
.category
, (int) data
->rx_action
.len
,
1927 data
->rx_action
.freq
);
1928 #ifdef CONFIG_IEEE80211R
1929 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
1930 ft_rx_action(wpa_s
, data
->rx_action
.data
,
1931 data
->rx_action
.len
);
1934 #endif /* CONFIG_IEEE80211R */
1935 #ifdef CONFIG_IEEE80211W
1937 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
1938 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
1939 data
->rx_action
.data
,
1940 data
->rx_action
.len
);
1943 #endif /* CONFIG_SME */
1944 #endif /* CONFIG_IEEE80211W */
1946 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
1948 data
->rx_action
.bssid
,
1949 data
->rx_action
.category
,
1950 data
->rx_action
.data
,
1951 data
->rx_action
.len
, data
->rx_action
.freq
);
1952 #endif /* CONFIG_P2P */
1954 case EVENT_RX_PROBE_REQ
:
1956 if (wpa_s
->ap_iface
) {
1957 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
1958 data
->rx_probe_req
.sa
,
1959 data
->rx_probe_req
.ie
,
1960 data
->rx_probe_req
.ie_len
);
1963 #endif /* CONFIG_AP */
1965 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
1966 data
->rx_probe_req
.ie
,
1967 data
->rx_probe_req
.ie_len
);
1968 #endif /* CONFIG_P2P */
1971 case EVENT_REMAIN_ON_CHANNEL
:
1972 wpas_p2p_remain_on_channel_cb(
1973 wpa_s
, data
->remain_on_channel
.freq
,
1974 data
->remain_on_channel
.duration
);
1976 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1977 wpas_p2p_cancel_remain_on_channel_cb(
1978 wpa_s
, data
->remain_on_channel
.freq
);
1980 case EVENT_P2P_DEV_FOUND
:
1981 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
,
1982 data
->p2p_dev_found
.dev_addr
,
1983 data
->p2p_dev_found
.pri_dev_type
,
1984 data
->p2p_dev_found
.dev_name
,
1985 data
->p2p_dev_found
.config_methods
,
1986 data
->p2p_dev_found
.dev_capab
,
1987 data
->p2p_dev_found
.group_capab
);
1989 case EVENT_P2P_GO_NEG_REQ_RX
:
1990 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
1991 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
1993 case EVENT_P2P_GO_NEG_COMPLETED
:
1994 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
1996 case EVENT_P2P_PROV_DISC_REQUEST
:
1997 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
1998 data
->p2p_prov_disc_req
.config_methods
,
1999 data
->p2p_prov_disc_req
.dev_addr
,
2000 data
->p2p_prov_disc_req
.pri_dev_type
,
2001 data
->p2p_prov_disc_req
.dev_name
,
2002 data
->p2p_prov_disc_req
.supp_config_methods
,
2003 data
->p2p_prov_disc_req
.dev_capab
,
2004 data
->p2p_prov_disc_req
.group_capab
);
2006 case EVENT_P2P_PROV_DISC_RESPONSE
:
2007 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2008 data
->p2p_prov_disc_resp
.config_methods
);
2010 case EVENT_P2P_SD_REQUEST
:
2011 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2012 data
->p2p_sd_req
.sa
,
2013 data
->p2p_sd_req
.dialog_token
,
2014 data
->p2p_sd_req
.update_indic
,
2015 data
->p2p_sd_req
.tlvs
,
2016 data
->p2p_sd_req
.tlvs_len
);
2018 case EVENT_P2P_SD_RESPONSE
:
2019 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2020 data
->p2p_sd_resp
.update_indic
,
2021 data
->p2p_sd_resp
.tlvs
,
2022 data
->p2p_sd_resp
.tlvs_len
);
2024 #endif /* CONFIG_P2P */
2025 #ifdef CONFIG_CLIENT_MLME
2026 case EVENT_MLME_RX
: {
2027 struct ieee80211_rx_status rx_status
;
2028 os_memset(&rx_status
, 0, sizeof(rx_status
));
2029 rx_status
.freq
= data
->mlme_rx
.freq
;
2030 rx_status
.channel
= data
->mlme_rx
.channel
;
2031 rx_status
.ssi
= data
->mlme_rx
.ssi
;
2032 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
2036 #endif /* CONFIG_CLIENT_MLME */
2037 case EVENT_EAPOL_RX
:
2038 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2039 data
->eapol_rx
.data
,
2040 data
->eapol_rx
.data_len
);
2042 case EVENT_SIGNAL_CHANGE
:
2043 bgscan_notify_signal_change(
2044 wpa_s
, data
->signal_change
.above_threshold
,
2045 data
->signal_change
.current_signal
,
2046 data
->signal_change
.current_noise
,
2047 data
->signal_change
.current_txrate
);
2049 case EVENT_INTERFACE_ENABLED
:
2050 wpa_printf(MSG_DEBUG
, "Interface was enabled");
2051 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2053 if (!wpa_s
->ap_iface
) {
2054 wpa_supplicant_set_state(wpa_s
,
2056 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2058 wpa_supplicant_set_state(wpa_s
,
2060 #else /* CONFIG_AP */
2061 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2062 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2063 #endif /* CONFIG_AP */
2066 case EVENT_INTERFACE_DISABLED
:
2067 wpa_printf(MSG_DEBUG
, "Interface was disabled");
2068 wpa_supplicant_mark_disassoc(wpa_s
);
2069 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2071 case EVENT_CHANNEL_LIST_CHANGED
:
2072 if (wpa_s
->drv_priv
== NULL
)
2073 break; /* Ignore event during drv initialization */
2075 wpas_p2p_update_channel_list(wpa_s
);
2076 #endif /* CONFIG_P2P */
2078 case EVENT_INTERFACE_UNAVAILABLE
:
2080 wpas_p2p_interface_unavailable(wpa_s
);
2081 #endif /* CONFIG_P2P */
2083 case EVENT_BEST_CHANNEL
:
2084 wpa_printf(MSG_DEBUG
, "Best channel event received (%d %d %d)",
2085 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2086 data
->best_chan
.freq_overall
);
2087 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2088 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2089 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2091 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2092 data
->best_chan
.freq_5
,
2093 data
->best_chan
.freq_overall
);
2094 #endif /* CONFIG_P2P */
2096 case EVENT_UNPROT_DEAUTH
:
2097 wpa_supplicant_event_unprot_deauth(wpa_s
,
2098 &data
->unprot_deauth
);
2100 case EVENT_UNPROT_DISASSOC
:
2101 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2102 &data
->unprot_disassoc
);
2104 case EVENT_STATION_LOW_ACK
:
2106 if (wpa_s
->ap_iface
&& data
)
2107 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2108 data
->low_ack
.addr
);
2109 #endif /* CONFIG_AP */
2112 wpa_printf(MSG_INFO
, "Unknown event %d", event
);