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_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
58 ssid
= wpa_supplicant_get_ssid(wpa_s
);
60 wpa_msg(wpa_s
, MSG_INFO
,
61 "No network configuration found for the current AP");
66 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
70 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
72 if (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
73 WPA_KEY_MGMT_WPA_NONE
|
74 WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_FT_IEEE8021X
|
75 WPA_KEY_MGMT_PSK_SHA256
|
76 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
78 size_t wpa_ie_len
= sizeof(wpa_ie
);
79 wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
82 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
85 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
86 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
87 old_ssid
= wpa_s
->current_ssid
;
88 wpa_s
->current_ssid
= ssid
;
89 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
90 wpa_supplicant_initiate_eapol(wpa_s
);
91 if (old_ssid
!= wpa_s
->current_ssid
)
92 wpas_notify_network_changed(wpa_s
);
98 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx
,
101 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
103 if (wpa_s
->countermeasures
) {
104 wpa_s
->countermeasures
= 0;
105 wpa_drv_set_countermeasures(wpa_s
, 0);
106 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
107 wpa_supplicant_req_scan(wpa_s
, 0, 0);
112 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
116 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_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
157 "PMKSA 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_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
169 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
170 " index=%d preauth=%d",
171 MAC2STR(data
->pmkid_candidate
.bssid
),
172 data
->pmkid_candidate
.index
,
173 data
->pmkid_candidate
.preauth
);
175 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
176 data
->pmkid_candidate
.index
,
177 data
->pmkid_candidate
.preauth
);
181 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
183 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
184 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
187 #ifdef IEEE8021X_EAPOL
188 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
189 wpa_s
->current_ssid
&&
190 !(wpa_s
->current_ssid
->eapol_flags
&
191 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
192 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
193 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
194 * plaintext or static WEP keys). */
197 #endif /* IEEE8021X_EAPOL */
204 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
205 * @wpa_s: pointer to wpa_supplicant data
206 * @ssid: Configuration data for the network
207 * Returns: 0 on success, -1 on failure
209 * This function is called when starting authentication with a network that is
210 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
212 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
213 struct wpa_ssid
*ssid
)
215 #ifdef IEEE8021X_EAPOL
216 int aka
= 0, sim
= 0, type
;
218 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
)
221 if (ssid
->eap
.eap_methods
== NULL
) {
225 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
226 while (eap
->vendor
!= EAP_VENDOR_IETF
||
227 eap
->method
!= EAP_TYPE_NONE
) {
228 if (eap
->vendor
== EAP_VENDOR_IETF
) {
229 if (eap
->method
== EAP_TYPE_SIM
)
231 else if (eap
->method
== EAP_TYPE_AKA
)
238 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
240 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
)
244 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
245 "use SIM, but neither EAP-SIM nor EAP-AKA are "
250 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
251 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
253 type
= SCARD_TRY_BOTH
;
255 type
= SCARD_USIM_ONLY
;
257 type
= SCARD_GSM_SIM_ONLY
;
259 wpa_s
->scard
= scard_init(type
);
260 if (wpa_s
->scard
== NULL
) {
261 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
265 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
266 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
267 #endif /* IEEE8021X_EAPOL */
273 #ifndef CONFIG_NO_SCAN_PROCESSING
274 static int wpa_supplicant_match_privacy(struct wpa_scan_res
*bss
,
275 struct wpa_ssid
*ssid
)
279 if (ssid
->mixed_cell
)
283 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
285 #endif /* CONFIG_WPS */
287 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
288 if (ssid
->wep_key_len
[i
]) {
293 #ifdef IEEE8021X_EAPOL
294 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
295 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
296 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
298 #endif /* IEEE8021X_EAPOL */
300 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
306 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
307 struct wpa_ssid
*ssid
,
308 struct wpa_scan_res
*bss
)
310 struct wpa_ie_data ie
;
312 const u8
*rsn_ie
, *wpa_ie
;
316 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
320 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
321 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
322 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
323 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
324 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
326 rsn_ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
327 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
330 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
331 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
337 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
339 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
344 if (!(ie
.proto
& ssid
->proto
)) {
345 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
350 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
351 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
356 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
357 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
362 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
363 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
368 #ifdef CONFIG_IEEE80211W
369 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
370 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
371 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
375 #endif /* CONFIG_IEEE80211W */
377 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
381 wpa_ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
382 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
385 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
386 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
392 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
394 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
399 if (!(ie
.proto
& ssid
->proto
)) {
400 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
405 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
406 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
411 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
412 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
417 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
418 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
423 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
427 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
428 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
429 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
433 /* Allow in non-WPA configuration */
438 static int freq_allowed(int *freqs
, int freq
)
445 for (i
= 0; freqs
[i
]; i
++)
446 if (freqs
[i
] == freq
)
452 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
453 int i
, struct wpa_scan_res
*bss
,
454 struct wpa_ssid
*group
)
457 u8 wpa_ie_len
, rsn_ie_len
, ssid_len
;
459 struct wpa_blacklist
*e
;
461 struct wpa_ssid
*ssid
;
463 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
464 ssid_
= ie
? ie
+ 2 : (u8
*) "";
465 ssid_len
= ie
? ie
[1] : 0;
467 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
468 wpa_ie_len
= ie
? ie
[1] : 0;
470 ie
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
471 rsn_ie_len
= ie
? ie
[1] : 0;
473 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
474 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
475 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid_
, ssid_len
),
476 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
477 wpa_scan_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "");
479 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
482 if (wpa_supplicant_enabled_networks(wpa_s
->conf
) == 1) {
484 * When only a single network is enabled, we can
485 * trigger blacklisting on the first failure. This
486 * should not be done with multiple enabled networks to
487 * avoid getting forced to move into a worse ESS on
488 * single error if there are no other BSSes of the
493 if (e
->count
> limit
) {
494 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
495 "(count=%d limit=%d)", e
->count
, limit
);
501 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
505 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
507 for (ssid
= group
; ssid
; ssid
= ssid
->pnext
) {
508 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
510 if (ssid
->disabled
) {
511 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
516 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
517 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
522 if (wpa
&& ssid
->ssid_len
== 0 &&
523 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
526 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
527 /* Only allow wildcard SSID match if an AP
528 * advertises active WPS operation that matches
531 if (ssid
->ssid_len
== 0 &&
532 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
535 #endif /* CONFIG_WPS */
538 (ssid_len
!= ssid
->ssid_len
||
539 os_memcmp(ssid_
, ssid
->ssid
, ssid_len
) != 0)) {
540 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
544 if (ssid
->bssid_set
&&
545 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
546 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
550 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
554 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
555 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
556 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
557 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
562 if (!wpa
&& !wpa_supplicant_match_privacy(bss
, ssid
)) {
563 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
568 if (!wpa
&& (bss
->caps
& IEEE80211_CAP_IBSS
)) {
569 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - IBSS (adhoc) "
574 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
575 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
582 * TODO: skip the AP if its P2P IE has Group Formation
583 * bit set in the P2P Group Capability Bitmap and we
584 * are not in Group Formation with that device.
586 #endif /* CONFIG_P2P */
588 /* Matching configuration found */
592 /* No matching configuration found */
597 static struct wpa_bss
*
598 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
599 struct wpa_scan_results
*scan_res
,
600 struct wpa_ssid
*group
,
601 struct wpa_ssid
**selected_ssid
)
605 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
608 for (i
= 0; i
< scan_res
->num
; i
++) {
609 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
613 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
);
617 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
618 ssid
= ie
? ie
+ 2 : (u8
*) "";
619 ssid_len
= ie
? ie
[1] : 0;
621 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
623 MAC2STR(bss
->bssid
), wpa_ssid_txt(ssid
, ssid_len
));
624 return wpa_bss_get(wpa_s
, bss
->bssid
, ssid
, ssid_len
);
631 static struct wpa_bss
*
632 wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
633 struct wpa_scan_results
*scan_res
,
634 struct wpa_ssid
**selected_ssid
)
636 struct wpa_bss
*selected
= NULL
;
639 while (selected
== NULL
) {
640 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
641 selected
= wpa_supplicant_select_bss(
642 wpa_s
, scan_res
, wpa_s
->conf
->pssid
[prio
],
648 if (selected
== NULL
&& wpa_s
->blacklist
) {
649 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
650 "blacklist and try again");
651 wpa_blacklist_clear(wpa_s
);
652 wpa_s
->blacklist_cleared
++;
653 } else if (selected
== NULL
)
661 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
662 int timeout_sec
, int timeout_usec
)
664 if (!wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
666 * No networks are enabled; short-circuit request so
667 * we don't wait timeout seconds before transitioning
670 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
673 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
677 void wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
678 struct wpa_bss
*selected
,
679 struct wpa_ssid
*ssid
)
681 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
682 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
683 "PBC session overlap");
685 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
687 #endif /* CONFIG_P2P */
690 wpas_wps_cancel(wpa_s
);
691 #endif /* CONFIG_WPS */
696 * Do not trigger new association unless the BSSID has changed or if
697 * reassociation is requested. If we are in process of associating with
698 * the selected BSSID, do not trigger new attempt.
700 if (wpa_s
->reassociate
||
701 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
702 (wpa_s
->wpa_state
!= WPA_ASSOCIATING
||
703 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
705 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
706 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
709 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
711 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated with the "
717 static struct wpa_ssid
*
718 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
721 struct wpa_ssid
*ssid
;
723 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
724 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
728 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
729 ssid
->mode
== IEEE80211_MODE_AP
)
737 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
738 * on BSS added and BSS changed events */
739 static void wpa_supplicant_rsn_preauth_scan_results(
740 struct wpa_supplicant
*wpa_s
, struct wpa_scan_results
*scan_res
)
744 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
747 for (i
= scan_res
->num
- 1; i
>= 0; i
--) {
748 const u8
*ssid
, *rsn
;
749 struct wpa_scan_res
*r
;
751 r
= scan_res
->res
[i
];
753 ssid
= wpa_scan_get_ie(r
, WLAN_EID_SSID
);
757 rsn
= wpa_scan_get_ie(r
, WLAN_EID_RSN
);
761 rsn_preauth_scan_result(wpa_s
->wpa
, r
->bssid
, ssid
, rsn
);
767 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
768 struct wpa_bss
*selected
,
769 struct wpa_ssid
*ssid
,
770 struct wpa_scan_results
*scan_res
)
773 struct wpa_scan_res
*current_bss
= NULL
;
776 if (wpa_s
->reassociate
)
777 return 1; /* explicit request to reassociate */
778 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
779 return 1; /* we are not associated; continue */
780 if (wpa_s
->current_ssid
== NULL
)
781 return 1; /* unknown current SSID */
782 if (wpa_s
->current_ssid
!= ssid
)
783 return 1; /* different network block */
785 for (i
= 0; i
< scan_res
->num
; i
++) {
786 struct wpa_scan_res
*res
= scan_res
->res
[i
];
788 if (os_memcmp(res
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
791 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
794 if (ie
[1] != wpa_s
->current_ssid
->ssid_len
||
795 os_memcmp(ie
+ 2, wpa_s
->current_ssid
->ssid
, ie
[1]) != 0)
802 return 1; /* current BSS not seen in scan results */
804 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
805 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
806 MAC2STR(current_bss
->bssid
), current_bss
->level
);
807 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
808 MAC2STR(selected
->bssid
), selected
->level
);
810 if (wpa_s
->current_ssid
->bssid_set
&&
811 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
813 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
814 "has preferred BSSID");
819 if (current_bss
->level
< 0) {
820 if (current_bss
->level
< -85)
822 else if (current_bss
->level
< -80)
824 else if (current_bss
->level
< -75)
826 else if (current_bss
->level
< -70)
831 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
832 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
840 /* Return < 0 if no scan results could be fetched. */
841 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
842 union wpa_event_data
*data
)
844 struct wpa_bss
*selected
;
845 struct wpa_ssid
*ssid
= NULL
;
846 struct wpa_scan_results
*scan_res
;
852 #endif /* CONFIG_AP */
854 wpa_supplicant_notify_scanning(wpa_s
, 0);
856 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
857 data
? &data
->scan_info
:
859 if (scan_res
== NULL
) {
860 if (wpa_s
->conf
->ap_scan
== 2 || ap
)
862 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
864 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
868 #ifndef CONFIG_NO_RANDOM_POOL
873 for (i
= 0; i
< num
; i
++) {
875 struct wpa_scan_res
*res
= scan_res
->res
[i
];
876 buf
[0] = res
->bssid
[5];
877 buf
[1] = res
->qual
& 0xff;
878 buf
[2] = res
->noise
& 0xff;
879 buf
[3] = res
->level
& 0xff;
880 buf
[4] = res
->tsf
& 0xff;
881 random_add_randomness(buf
, sizeof(buf
));
883 #endif /* CONFIG_NO_RANDOM_POOL */
885 if (wpa_s
->scan_res_handler
) {
886 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
887 struct wpa_scan_results
*scan_res
);
889 scan_res_handler
= wpa_s
->scan_res_handler
;
890 wpa_s
->scan_res_handler
= NULL
;
891 scan_res_handler(wpa_s
, scan_res
);
893 wpa_scan_results_free(scan_res
);
898 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
899 wpa_scan_results_free(scan_res
);
903 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available");
904 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
905 wpas_notify_scan_results(wpa_s
);
907 wpas_notify_scan_done(wpa_s
, 1);
909 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
))) {
910 wpa_scan_results_free(scan_res
);
914 if (wpa_s
->disconnected
) {
915 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
916 wpa_scan_results_free(scan_res
);
920 if (bgscan_notify_scan(wpa_s
, scan_res
) == 1) {
921 wpa_scan_results_free(scan_res
);
925 wpa_supplicant_rsn_preauth_scan_results(wpa_s
, scan_res
);
927 selected
= wpa_supplicant_pick_network(wpa_s
, scan_res
, &ssid
);
931 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
,
933 wpa_scan_results_free(scan_res
);
936 wpa_supplicant_connect(wpa_s
, selected
, ssid
);
938 wpa_scan_results_free(scan_res
);
939 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
940 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
942 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
943 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
946 int timeout_usec
= 0;
948 if (wpa_s
->p2p_in_provisioning
) {
950 * Use shorter wait during P2P Provisioning
951 * state to speed up group formation.
954 timeout_usec
= 250000;
956 #endif /* CONFIG_P2P */
957 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
965 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
966 union wpa_event_data
*data
)
968 const char *rn
, *rn2
;
969 struct wpa_supplicant
*ifs
;
971 if (_wpa_supplicant_event_scan_results(wpa_s
, data
) < 0) {
973 * If no scan results could be fetched, then no need to
974 * notify those interfaces that did not actually request
981 * Check other interfaces to see if they have the same radio-name. If
982 * so, they get updated with this same scan info.
984 if (!wpa_s
->driver
->get_radio_name
)
987 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
988 if (rn
== NULL
|| rn
[0] == '\0')
991 wpa_dbg(wpa_s
, MSG_DEBUG
, "Checking for other virtual interfaces "
992 "sharing same radio (%s) in event_scan_results", rn
);
994 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
995 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
998 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
999 if (rn2
&& os_strcmp(rn
, rn2
) == 0) {
1000 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1001 "sibling", ifs
->ifname
);
1002 _wpa_supplicant_event_scan_results(ifs
, data
);
1007 #endif /* CONFIG_NO_SCAN_PROCESSING */
1010 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1011 union wpa_event_data
*data
)
1013 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1016 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1017 if (data
->assoc_info
.req_ies
)
1018 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1019 data
->assoc_info
.req_ies_len
);
1020 if (data
->assoc_info
.resp_ies
)
1021 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1022 data
->assoc_info
.resp_ies_len
);
1023 if (data
->assoc_info
.beacon_ies
)
1024 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1025 data
->assoc_info
.beacon_ies
,
1026 data
->assoc_info
.beacon_ies_len
);
1027 if (data
->assoc_info
.freq
)
1028 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1029 data
->assoc_info
.freq
);
1031 p
= data
->assoc_info
.req_ies
;
1032 l
= data
->assoc_info
.req_ies_len
;
1034 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1035 while (p
&& l
>= 2) {
1038 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1042 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1043 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1044 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1045 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1048 wpa_find_assoc_pmkid(wpa_s
);
1054 if (!found
&& data
->assoc_info
.req_ies
)
1055 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1057 #ifdef CONFIG_IEEE80211R
1059 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1061 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1062 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1063 data
->assoc_info
.resp_ies
,
1064 data
->assoc_info
.resp_ies_len
,
1066 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1067 "Reassociation Response failed");
1068 wpa_supplicant_deauthenticate(
1069 wpa_s
, WLAN_REASON_INVALID_IE
);
1074 p
= data
->assoc_info
.resp_ies
;
1075 l
= data
->assoc_info
.resp_ies_len
;
1077 #ifdef CONFIG_WPS_STRICT
1078 if (wpa_s
->current_ssid
&&
1079 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1081 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1083 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1084 "include WPS IE in (Re)Association Response");
1088 if (wps_validate_assoc_resp(wps
) < 0) {
1090 wpa_supplicant_deauthenticate(
1091 wpa_s
, WLAN_REASON_INVALID_IE
);
1096 #endif /* CONFIG_WPS_STRICT */
1098 /* Go through the IEs and make a copy of the MDIE, if present. */
1099 while (p
&& l
>= 2) {
1102 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1106 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1107 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1108 wpa_s
->sme
.ft_used
= 1;
1109 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1110 MOBILITY_DOMAIN_ID_LEN
);
1116 #endif /* CONFIG_SME */
1118 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1119 data
->assoc_info
.resp_ies_len
);
1120 #endif /* CONFIG_IEEE80211R */
1122 /* WPA/RSN IE from Beacon/ProbeResp */
1123 p
= data
->assoc_info
.beacon_ies
;
1124 l
= data
->assoc_info
.beacon_ies_len
;
1126 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1128 wpa_found
= rsn_found
= 0;
1129 while (p
&& l
>= 2) {
1132 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1137 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1138 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1140 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1144 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1146 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1153 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1154 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1155 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1156 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1157 if (wpa_found
|| rsn_found
)
1158 wpa_s
->ap_ies_from_associnfo
= 1;
1160 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1166 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1167 union wpa_event_data
*data
)
1172 struct wpa_driver_capa capa
;
1175 if (wpa_s
->ap_iface
) {
1176 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1177 data
->assoc_info
.addr
,
1178 data
->assoc_info
.req_ies
,
1179 data
->assoc_info
.req_ies_len
);
1182 #endif /* CONFIG_AP */
1184 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1185 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1188 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1189 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1190 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1191 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) ||
1192 (wpa_drv_get_bssid(wpa_s
, bssid
) >= 0 &&
1193 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
1194 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1195 MACSTR
, MAC2STR(bssid
));
1196 random_add_randomness(bssid
, ETH_ALEN
);
1197 bssid_changed
= os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1198 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1199 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1201 wpas_notify_bssid_changed(wpa_s
);
1203 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1204 wpa_clear_keys(wpa_s
, bssid
);
1206 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1207 wpa_supplicant_disassociate(
1208 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1211 if (wpa_s
->current_ssid
) {
1212 struct wpa_bss
*bss
= NULL
;
1213 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1214 if (ssid
->ssid_len
> 0)
1215 bss
= wpa_bss_get(wpa_s
, bssid
,
1216 ssid
->ssid
, ssid
->ssid_len
);
1218 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1220 wpa_s
->current_bss
= bss
;
1225 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1226 wpa_s
->sme
.prev_bssid_set
= 1;
1227 #endif /* CONFIG_SME */
1229 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1230 if (wpa_s
->current_ssid
) {
1231 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1232 * initialized before association, but for other modes,
1233 * initialize PC/SC here, if the current configuration needs
1234 * smartcard or SIM/USIM. */
1235 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1237 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1239 l2_packet_notify_auth_start(wpa_s
->l2
);
1242 * Set portEnabled first to FALSE in order to get EAP state machine out
1243 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1244 * state machine may transit to AUTHENTICATING state based on obsolete
1245 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1246 * AUTHENTICATED without ever giving chance to EAP state machine to
1249 if (!ft_completed
) {
1250 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1251 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1253 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1254 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1255 /* 802.1X::portControl = Auto */
1256 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1257 wpa_s
->eapol_received
= 0;
1258 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1259 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1260 (wpa_s
->current_ssid
&&
1261 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1262 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1263 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1264 } else if (!ft_completed
) {
1265 /* Timeout for receiving the first EAPOL packet */
1266 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1268 wpa_supplicant_cancel_scan(wpa_s
);
1270 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1271 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1273 * We are done; the driver will take care of RSN 4-way
1276 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1277 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1278 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1279 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1280 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1281 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1283 * The driver will take care of RSN 4-way handshake, so we need
1284 * to allow EAPOL supplicant to complete its work without
1285 * waiting for WPA supplicant.
1287 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1290 if (wpa_s
->pending_eapol_rx
) {
1291 struct os_time now
, age
;
1293 os_time_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1294 if (age
.sec
== 0 && age
.usec
< 100000 &&
1295 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1297 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1298 "frame that was received just before "
1299 "association notification");
1300 wpa_supplicant_rx_eapol(
1301 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1302 wpabuf_head(wpa_s
->pending_eapol_rx
),
1303 wpabuf_len(wpa_s
->pending_eapol_rx
));
1305 wpabuf_free(wpa_s
->pending_eapol_rx
);
1306 wpa_s
->pending_eapol_rx
= NULL
;
1309 #ifdef CONFIG_BGSCAN
1310 if (wpa_s
->current_ssid
!= wpa_s
->bgscan_ssid
) {
1311 bgscan_deinit(wpa_s
);
1312 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
1313 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
1314 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to "
1315 "initialize bgscan");
1317 * Live without bgscan; it is only used as a
1318 * roaming optimization, so the initial
1319 * connection is not affected.
1322 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
1324 wpa_s
->bgscan_ssid
= NULL
;
1326 #endif /* CONFIG_BGSCAN */
1328 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1329 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
1330 wpa_s
->current_ssid
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1331 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
) {
1332 /* Set static WEP keys again */
1333 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
1336 #ifdef CONFIG_IBSS_RSN
1337 if (wpa_s
->current_ssid
&&
1338 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
1339 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1340 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
)
1341 ibss_rsn_connected(wpa_s
->ibss_rsn
);
1342 #endif /* CONFIG_IBSS_RSN */
1346 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
1352 u8 prev_pending_bssid
[ETH_ALEN
];
1354 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
1355 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
1356 #endif /* CONFIG_SME */
1358 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1360 * At least Host AP driver and a Prism3 card seemed to be
1361 * generating streams of disconnected events when configuring
1362 * IBSS for WPA-None. Ignore them for now.
1364 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
1365 "IBSS/WPA-None mode");
1369 if (wpa_s
->wpa_state
== WPA_4WAY_HANDSHAKE
&&
1370 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1371 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
1372 "pre-shared key may be incorrect");
1374 if (!wpa_s
->auto_reconnect_disabled
||
1375 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1376 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect enabled: try to "
1377 "reconnect (wps=%d)",
1378 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
1379 if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
1380 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
1382 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Auto connect disabled: do not "
1383 "try to re-connect");
1384 wpa_s
->reassociate
= 0;
1385 wpa_s
->disconnected
= 1;
1387 bssid
= wpa_s
->bssid
;
1388 if (is_zero_ether_addr(bssid
))
1389 bssid
= wpa_s
->pending_bssid
;
1390 wpas_connection_failed(wpa_s
, bssid
);
1391 wpa_sm_notify_disassoc(wpa_s
->wpa
);
1392 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
1394 MAC2STR(bssid
), reason_code
);
1395 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
1396 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
1397 wpa_s
->keys_cleared
= 0;
1398 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
1400 wpa_supplicant_mark_disassoc(wpa_s
);
1401 bgscan_deinit(wpa_s
);
1402 wpa_s
->bgscan_ssid
= NULL
;
1404 if (authenticating
&&
1405 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
1407 * mac80211-workaround to force deauth on failed auth cmd,
1408 * requires us to remain in authenticating state to allow the
1409 * second authentication attempt to be continued properly.
1411 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
1412 "to proceed after disconnection event");
1413 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1414 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1416 #endif /* CONFIG_SME */
1420 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1421 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
,
1424 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1426 if (!wpa_s
->pending_mic_error_report
)
1429 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
1430 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
1431 wpa_s
->pending_mic_error_report
= 0;
1433 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1437 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
1438 union wpa_event_data
*data
)
1443 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
1444 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
1446 if ((wpa_s
->last_michael_mic_error
&&
1447 t
.sec
- wpa_s
->last_michael_mic_error
<= 60) ||
1448 wpa_s
->pending_mic_error_report
) {
1449 if (wpa_s
->pending_mic_error_report
) {
1451 * Send the pending MIC error report immediately since
1452 * we are going to start countermeasures and AP better
1455 wpa_sm_key_request(wpa_s
->wpa
, 1,
1456 wpa_s
->pending_mic_error_pairwise
);
1459 /* Send the new MIC error report immediately since we are going
1460 * to start countermeasures and AP better do the same.
1462 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1464 /* initialize countermeasures */
1465 wpa_s
->countermeasures
= 1;
1466 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
1469 * Need to wait for completion of request frame. We do not get
1470 * any callback for the message completion, so just wait a
1471 * short while and hope for the best. */
1474 wpa_drv_set_countermeasures(wpa_s
, 1);
1475 wpa_supplicant_deauthenticate(wpa_s
,
1476 WLAN_REASON_MICHAEL_MIC_FAILURE
);
1477 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
1479 eloop_register_timeout(60, 0,
1480 wpa_supplicant_stop_countermeasures
,
1482 /* TODO: mark the AP rejected for 60 second. STA is
1483 * allowed to associate with another AP.. */
1485 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1486 if (wpa_s
->mic_errors_seen
) {
1488 * Reduce the effectiveness of Michael MIC error
1489 * reports as a means for attacking against TKIP if
1490 * more than one MIC failure is noticed with the same
1491 * PTK. We delay the transmission of the reports by a
1492 * random time between 0 and 60 seconds in order to
1493 * force the attacker wait 60 seconds before getting
1494 * the information on whether a frame resulted in a MIC
1500 if (os_get_random(rval
, sizeof(rval
)) < 0)
1501 sec
= os_random() % 60;
1503 sec
= WPA_GET_BE32(rval
) % 60;
1504 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
1505 "report %d seconds", sec
);
1506 wpa_s
->pending_mic_error_report
= 1;
1507 wpa_s
->pending_mic_error_pairwise
= pairwise
;
1508 eloop_cancel_timeout(
1509 wpa_supplicant_delayed_mic_error_report
,
1511 eloop_register_timeout(
1512 sec
, os_random() % 1000000,
1513 wpa_supplicant_delayed_mic_error_report
,
1516 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1518 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1519 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
1520 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1522 wpa_s
->last_michael_mic_error
= t
.sec
;
1523 wpa_s
->mic_errors_seen
++;
1527 #ifdef CONFIG_TERMINATE_ONLASTIF
1528 static int any_interfaces(struct wpa_supplicant
*head
)
1530 struct wpa_supplicant
*wpa_s
;
1532 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
1533 if (!wpa_s
->interface_removed
)
1537 #endif /* CONFIG_TERMINATE_ONLASTIF */
1541 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
1542 union wpa_event_data
*data
)
1544 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
1547 switch (data
->interface_status
.ievent
) {
1548 case EVENT_INTERFACE_ADDED
:
1549 if (!wpa_s
->interface_removed
)
1551 wpa_s
->interface_removed
= 0;
1552 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
1553 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
1554 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
1555 "driver after interface was added");
1558 case EVENT_INTERFACE_REMOVED
:
1559 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
1560 wpa_s
->interface_removed
= 1;
1561 wpa_supplicant_mark_disassoc(wpa_s
);
1562 l2_packet_deinit(wpa_s
->l2
);
1564 #ifdef CONFIG_TERMINATE_ONLASTIF
1565 /* check if last interface */
1566 if (!any_interfaces(wpa_s
->global
->ifaces
))
1568 #endif /* CONFIG_TERMINATE_ONLASTIF */
1574 #ifdef CONFIG_PEERKEY
1576 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
1577 union wpa_event_data
*data
)
1581 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
1583 #endif /* CONFIG_PEERKEY */
1586 #ifdef CONFIG_IEEE80211R
1588 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
1589 union wpa_event_data
*data
)
1594 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
1595 data
->ft_ies
.ies_len
,
1596 data
->ft_ies
.ft_action
,
1597 data
->ft_ies
.target_ap
,
1598 data
->ft_ies
.ric_ies
,
1599 data
->ft_ies
.ric_ies_len
) < 0) {
1600 /* TODO: prevent MLME/driver from trying to associate? */
1603 #endif /* CONFIG_IEEE80211R */
1606 #ifdef CONFIG_IBSS_RSN
1607 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
1608 union wpa_event_data
*data
)
1610 struct wpa_ssid
*ssid
;
1613 ssid
= wpa_s
->current_ssid
;
1616 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
1619 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
1621 #endif /* CONFIG_IBSS_RSN */
1624 #ifdef CONFIG_IEEE80211R
1625 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
1628 const u8
*sta_addr
, *target_ap_addr
;
1631 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
1632 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
1633 return; /* only SME case supported for now */
1634 if (len
< 1 + 2 * ETH_ALEN
+ 2)
1637 return; /* Only FT Action Response is supported for now */
1638 sta_addr
= data
+ 1;
1639 target_ap_addr
= data
+ 1 + ETH_ALEN
;
1640 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
1641 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
1642 MACSTR
" TargetAP " MACSTR
" status %u",
1643 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1645 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1646 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
1647 " in FT Action Response", MAC2STR(sta_addr
));
1652 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
1653 "failure (status code %d)", status
);
1654 /* TODO: report error to FT code(?) */
1658 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
1659 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
1660 target_ap_addr
, NULL
, 0) < 0)
1665 struct wpa_bss
*bss
;
1666 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
1668 wpa_s
->sme
.freq
= bss
->freq
;
1669 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
1670 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
1673 #endif /* CONFIG_SME */
1675 #endif /* CONFIG_IEEE80211R */
1678 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
1679 struct unprot_deauth
*e
)
1681 #ifdef CONFIG_IEEE80211W
1682 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
1683 "dropped: " MACSTR
" -> " MACSTR
1684 " (reason code %u)",
1685 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1686 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1687 #endif /* CONFIG_IEEE80211W */
1691 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
1692 struct unprot_disassoc
*e
)
1694 #ifdef CONFIG_IEEE80211W
1695 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
1696 "dropped: " MACSTR
" -> " MACSTR
1697 " (reason code %u)",
1698 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
1699 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
1700 #endif /* CONFIG_IEEE80211W */
1704 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1705 union wpa_event_data
*data
)
1707 struct wpa_supplicant
*wpa_s
= ctx
;
1708 u16 reason_code
= 0;
1710 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
1711 event
!= EVENT_INTERFACE_ENABLED
&&
1712 event
!= EVENT_INTERFACE_STATUS
) {
1713 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore event %d while interface is "
1718 wpa_dbg(wpa_s
, MSG_DEBUG
, "Event %d received on interface %s",
1719 event
, wpa_s
->ifname
);
1723 sme_event_auth(wpa_s
, data
);
1726 wpa_supplicant_event_assoc(wpa_s
, data
);
1728 case EVENT_DISASSOC
:
1729 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
1731 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1732 data
->disassoc_info
.reason_code
);
1733 if (data
->disassoc_info
.addr
)
1734 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
1735 MAC2STR(data
->disassoc_info
.addr
));
1738 if (wpa_s
->ap_iface
&& data
&& data
->disassoc_info
.addr
) {
1739 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1740 data
->disassoc_info
.addr
);
1743 #endif /* CONFIG_AP */
1745 reason_code
= data
->disassoc_info
.reason_code
;
1746 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
1747 data
->disassoc_info
.ie
,
1748 data
->disassoc_info
.ie_len
);
1750 wpas_p2p_disassoc_notif(
1751 wpa_s
, data
->disassoc_info
.addr
, reason_code
,
1752 data
->disassoc_info
.ie
,
1753 data
->disassoc_info
.ie_len
);
1754 #endif /* CONFIG_P2P */
1756 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1757 sme_event_disassoc(wpa_s
, data
);
1760 if (event
== EVENT_DEAUTH
) {
1761 wpa_dbg(wpa_s
, MSG_DEBUG
,
1762 "Deauthentication notification");
1764 reason_code
= data
->deauth_info
.reason_code
;
1765 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u",
1766 data
->deauth_info
.reason_code
);
1767 if (data
->deauth_info
.addr
) {
1768 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address "
1770 MAC2STR(data
->deauth_info
.
1773 wpa_hexdump(MSG_DEBUG
,
1774 "Deauthentication frame IE(s)",
1775 data
->deauth_info
.ie
,
1776 data
->deauth_info
.ie_len
);
1778 wpas_p2p_deauth_notif(
1779 wpa_s
, data
->deauth_info
.addr
,
1781 data
->deauth_info
.ie
,
1782 data
->deauth_info
.ie_len
);
1783 #endif /* CONFIG_P2P */
1787 if (wpa_s
->ap_iface
&& data
&& data
->deauth_info
.addr
) {
1788 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0],
1789 data
->deauth_info
.addr
);
1792 #endif /* CONFIG_AP */
1793 wpa_supplicant_event_disassoc(wpa_s
, reason_code
);
1795 case EVENT_MICHAEL_MIC_FAILURE
:
1796 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
1798 #ifndef CONFIG_NO_SCAN_PROCESSING
1799 case EVENT_SCAN_RESULTS
:
1800 wpa_supplicant_event_scan_results(wpa_s
, data
);
1802 #endif /* CONFIG_NO_SCAN_PROCESSING */
1803 case EVENT_ASSOCINFO
:
1804 wpa_supplicant_event_associnfo(wpa_s
, data
);
1806 case EVENT_INTERFACE_STATUS
:
1807 wpa_supplicant_event_interface_status(wpa_s
, data
);
1809 case EVENT_PMKID_CANDIDATE
:
1810 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
1812 #ifdef CONFIG_PEERKEY
1813 case EVENT_STKSTART
:
1814 wpa_supplicant_event_stkstart(wpa_s
, data
);
1816 #endif /* CONFIG_PEERKEY */
1817 #ifdef CONFIG_IEEE80211R
1818 case EVENT_FT_RESPONSE
:
1819 wpa_supplicant_event_ft_response(wpa_s
, data
);
1821 #endif /* CONFIG_IEEE80211R */
1822 #ifdef CONFIG_IBSS_RSN
1823 case EVENT_IBSS_RSN_START
:
1824 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
1826 #endif /* CONFIG_IBSS_RSN */
1827 case EVENT_ASSOC_REJECT
:
1828 if (data
->assoc_reject
.bssid
)
1829 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1830 "bssid=" MACSTR
" status_code=%u",
1831 MAC2STR(data
->assoc_reject
.bssid
),
1832 data
->assoc_reject
.status_code
);
1834 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
1836 data
->assoc_reject
.status_code
);
1837 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1838 sme_event_assoc_reject(wpa_s
, data
);
1840 case EVENT_AUTH_TIMED_OUT
:
1841 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1842 sme_event_auth_timed_out(wpa_s
, data
);
1844 case EVENT_ASSOC_TIMED_OUT
:
1845 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
1846 sme_event_assoc_timed_out(wpa_s
, data
);
1849 case EVENT_TX_STATUS
:
1850 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
1851 " type=%d stype=%d",
1852 MAC2STR(data
->tx_status
.dst
),
1853 data
->tx_status
.type
, data
->tx_status
.stype
);
1854 if (wpa_s
->ap_iface
== NULL
) {
1856 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1857 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
1858 wpas_send_action_tx_status(
1859 wpa_s
, data
->tx_status
.dst
,
1860 data
->tx_status
.data
,
1861 data
->tx_status
.data_len
,
1862 data
->tx_status
.ack
?
1863 P2P_SEND_ACTION_SUCCESS
:
1864 P2P_SEND_ACTION_NO_ACK
);
1865 #endif /* CONFIG_P2P */
1869 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
1870 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
1872 * Catch TX status events for Action frames we sent via group
1873 * interface in GO mode.
1875 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
1876 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
1877 os_memcmp(wpa_s
->parent
->pending_action_dst
,
1878 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
1879 wpas_send_action_tx_status(
1880 wpa_s
->parent
, data
->tx_status
.dst
,
1881 data
->tx_status
.data
,
1882 data
->tx_status
.data_len
,
1883 data
->tx_status
.ack
?
1884 P2P_SEND_ACTION_SUCCESS
:
1885 P2P_SEND_ACTION_NO_ACK
);
1888 #endif /* CONFIG_P2P */
1889 switch (data
->tx_status
.type
) {
1890 case WLAN_FC_TYPE_MGMT
:
1891 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
1892 data
->tx_status
.data_len
,
1893 data
->tx_status
.stype
,
1894 data
->tx_status
.ack
);
1896 case WLAN_FC_TYPE_DATA
:
1897 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
1898 data
->tx_status
.data
,
1899 data
->tx_status
.data_len
,
1900 data
->tx_status
.ack
);
1904 case EVENT_RX_FROM_UNKNOWN
:
1905 if (wpa_s
->ap_iface
== NULL
)
1907 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.frame
,
1908 data
->rx_from_unknown
.len
);
1911 if (wpa_s
->ap_iface
== NULL
) {
1914 const struct ieee80211_mgmt
*mgmt
;
1915 mgmt
= (const struct ieee80211_mgmt
*)
1916 data
->rx_mgmt
.frame
;
1917 fc
= le_to_host16(mgmt
->frame_control
);
1918 stype
= WLAN_FC_GET_STYPE(fc
);
1919 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
1920 data
->rx_mgmt
.frame_len
> 24) {
1921 const u8
*src
= mgmt
->sa
;
1922 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
1923 size_t ie_len
= data
->rx_mgmt
.frame_len
-
1924 (mgmt
->u
.probe_req
.variable
-
1925 data
->rx_mgmt
.frame
);
1926 wpas_p2p_probe_req_rx(wpa_s
, src
, ie
, ie_len
);
1929 #endif /* CONFIG_P2P */
1930 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
1931 "management frame in non-AP mode");
1934 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
1936 #endif /* CONFIG_AP */
1937 case EVENT_RX_ACTION
:
1938 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
1939 " Category=%u DataLen=%d freq=%d MHz",
1940 MAC2STR(data
->rx_action
.sa
),
1941 data
->rx_action
.category
, (int) data
->rx_action
.len
,
1942 data
->rx_action
.freq
);
1943 #ifdef CONFIG_IEEE80211R
1944 if (data
->rx_action
.category
== WLAN_ACTION_FT
) {
1945 ft_rx_action(wpa_s
, data
->rx_action
.data
,
1946 data
->rx_action
.len
);
1949 #endif /* CONFIG_IEEE80211R */
1950 #ifdef CONFIG_IEEE80211W
1952 if (data
->rx_action
.category
== WLAN_ACTION_SA_QUERY
) {
1953 sme_sa_query_rx(wpa_s
, data
->rx_action
.sa
,
1954 data
->rx_action
.data
,
1955 data
->rx_action
.len
);
1958 #endif /* CONFIG_SME */
1959 #endif /* CONFIG_IEEE80211W */
1961 wpas_p2p_rx_action(wpa_s
, data
->rx_action
.da
,
1963 data
->rx_action
.bssid
,
1964 data
->rx_action
.category
,
1965 data
->rx_action
.data
,
1966 data
->rx_action
.len
, data
->rx_action
.freq
);
1967 #endif /* CONFIG_P2P */
1969 case EVENT_RX_PROBE_REQ
:
1971 if (wpa_s
->ap_iface
) {
1972 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
1973 data
->rx_probe_req
.sa
,
1974 data
->rx_probe_req
.ie
,
1975 data
->rx_probe_req
.ie_len
);
1978 #endif /* CONFIG_AP */
1980 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
1981 data
->rx_probe_req
.ie
,
1982 data
->rx_probe_req
.ie_len
);
1983 #endif /* CONFIG_P2P */
1986 case EVENT_REMAIN_ON_CHANNEL
:
1987 wpas_p2p_remain_on_channel_cb(
1988 wpa_s
, data
->remain_on_channel
.freq
,
1989 data
->remain_on_channel
.duration
);
1991 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1992 wpas_p2p_cancel_remain_on_channel_cb(
1993 wpa_s
, data
->remain_on_channel
.freq
);
1995 case EVENT_P2P_DEV_FOUND
:
1996 wpas_dev_found(wpa_s
, data
->p2p_dev_found
.addr
,
1997 data
->p2p_dev_found
.dev_addr
,
1998 data
->p2p_dev_found
.pri_dev_type
,
1999 data
->p2p_dev_found
.dev_name
,
2000 data
->p2p_dev_found
.config_methods
,
2001 data
->p2p_dev_found
.dev_capab
,
2002 data
->p2p_dev_found
.group_capab
);
2004 case EVENT_P2P_GO_NEG_REQ_RX
:
2005 wpas_go_neg_req_rx(wpa_s
, data
->p2p_go_neg_req_rx
.src
,
2006 data
->p2p_go_neg_req_rx
.dev_passwd_id
);
2008 case EVENT_P2P_GO_NEG_COMPLETED
:
2009 wpas_go_neg_completed(wpa_s
, data
->p2p_go_neg_completed
.res
);
2011 case EVENT_P2P_PROV_DISC_REQUEST
:
2012 wpas_prov_disc_req(wpa_s
, data
->p2p_prov_disc_req
.peer
,
2013 data
->p2p_prov_disc_req
.config_methods
,
2014 data
->p2p_prov_disc_req
.dev_addr
,
2015 data
->p2p_prov_disc_req
.pri_dev_type
,
2016 data
->p2p_prov_disc_req
.dev_name
,
2017 data
->p2p_prov_disc_req
.supp_config_methods
,
2018 data
->p2p_prov_disc_req
.dev_capab
,
2019 data
->p2p_prov_disc_req
.group_capab
);
2021 case EVENT_P2P_PROV_DISC_RESPONSE
:
2022 wpas_prov_disc_resp(wpa_s
, data
->p2p_prov_disc_resp
.peer
,
2023 data
->p2p_prov_disc_resp
.config_methods
);
2025 case EVENT_P2P_SD_REQUEST
:
2026 wpas_sd_request(wpa_s
, data
->p2p_sd_req
.freq
,
2027 data
->p2p_sd_req
.sa
,
2028 data
->p2p_sd_req
.dialog_token
,
2029 data
->p2p_sd_req
.update_indic
,
2030 data
->p2p_sd_req
.tlvs
,
2031 data
->p2p_sd_req
.tlvs_len
);
2033 case EVENT_P2P_SD_RESPONSE
:
2034 wpas_sd_response(wpa_s
, data
->p2p_sd_resp
.sa
,
2035 data
->p2p_sd_resp
.update_indic
,
2036 data
->p2p_sd_resp
.tlvs
,
2037 data
->p2p_sd_resp
.tlvs_len
);
2039 #endif /* CONFIG_P2P */
2040 #ifdef CONFIG_CLIENT_MLME
2041 case EVENT_MLME_RX
: {
2042 struct ieee80211_rx_status rx_status
;
2043 os_memset(&rx_status
, 0, sizeof(rx_status
));
2044 rx_status
.freq
= data
->mlme_rx
.freq
;
2045 rx_status
.channel
= data
->mlme_rx
.channel
;
2046 rx_status
.ssi
= data
->mlme_rx
.ssi
;
2047 ieee80211_sta_rx(wpa_s
, data
->mlme_rx
.buf
, data
->mlme_rx
.len
,
2051 #endif /* CONFIG_CLIENT_MLME */
2052 case EVENT_EAPOL_RX
:
2053 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
2054 data
->eapol_rx
.data
,
2055 data
->eapol_rx
.data_len
);
2057 case EVENT_SIGNAL_CHANGE
:
2058 bgscan_notify_signal_change(
2059 wpa_s
, data
->signal_change
.above_threshold
,
2060 data
->signal_change
.current_signal
,
2061 data
->signal_change
.current_noise
,
2062 data
->signal_change
.current_txrate
);
2064 case EVENT_INTERFACE_ENABLED
:
2065 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
2066 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2068 if (!wpa_s
->ap_iface
) {
2069 wpa_supplicant_set_state(wpa_s
,
2071 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2073 wpa_supplicant_set_state(wpa_s
,
2075 #else /* CONFIG_AP */
2076 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2077 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2078 #endif /* CONFIG_AP */
2081 case EVENT_INTERFACE_DISABLED
:
2082 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
2083 wpa_supplicant_mark_disassoc(wpa_s
);
2084 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2086 case EVENT_CHANNEL_LIST_CHANGED
:
2087 if (wpa_s
->drv_priv
== NULL
)
2088 break; /* Ignore event during drv initialization */
2090 wpas_p2p_update_channel_list(wpa_s
);
2091 #endif /* CONFIG_P2P */
2093 case EVENT_INTERFACE_UNAVAILABLE
:
2095 wpas_p2p_interface_unavailable(wpa_s
);
2096 #endif /* CONFIG_P2P */
2098 case EVENT_BEST_CHANNEL
:
2099 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
2101 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
2102 data
->best_chan
.freq_overall
);
2103 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
2104 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
2105 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
2107 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
2108 data
->best_chan
.freq_5
,
2109 data
->best_chan
.freq_overall
);
2110 #endif /* CONFIG_P2P */
2112 case EVENT_UNPROT_DEAUTH
:
2113 wpa_supplicant_event_unprot_deauth(wpa_s
,
2114 &data
->unprot_deauth
);
2116 case EVENT_UNPROT_DISASSOC
:
2117 wpa_supplicant_event_unprot_disassoc(wpa_s
,
2118 &data
->unprot_disassoc
);
2120 case EVENT_STATION_LOW_ACK
:
2122 if (wpa_s
->ap_iface
&& data
)
2123 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
2124 data
->low_ack
.addr
);
2125 #endif /* CONFIG_AP */
2128 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);