2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 #ifndef CONFIG_NO_SCAN_PROCESSING
48 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
49 int new_scan
, int own_request
);
50 #endif /* CONFIG_NO_SCAN_PROCESSING */
53 static int wpas_temp_disabled(struct wpa_supplicant
*wpa_s
,
54 struct wpa_ssid
*ssid
)
56 struct os_reltime now
;
58 if (ssid
== NULL
|| ssid
->disabled_until
.sec
== 0)
62 if (ssid
->disabled_until
.sec
> now
.sec
)
63 return ssid
->disabled_until
.sec
- now
.sec
;
65 wpas_clear_temp_disabled(wpa_s
, ssid
, 0);
71 static struct wpa_bss
* wpa_supplicant_get_new_bss(
72 struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
74 struct wpa_bss
*bss
= NULL
;
75 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
77 if (ssid
->ssid_len
> 0)
78 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
80 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
86 static int wpa_supplicant_select_config(struct wpa_supplicant
*wpa_s
)
88 struct wpa_ssid
*ssid
, *old_ssid
;
92 if (wpa_s
->conf
->ap_scan
== 1 && wpa_s
->current_ssid
)
95 wpa_dbg(wpa_s
, MSG_DEBUG
, "Select network based on association "
97 ssid
= wpa_supplicant_get_ssid(wpa_s
);
99 wpa_msg(wpa_s
, MSG_INFO
,
100 "No network configuration found for the current AP");
104 if (wpas_network_disabled(wpa_s
, ssid
)) {
105 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is disabled");
109 if (disallowed_bssid(wpa_s
, wpa_s
->bssid
) ||
110 disallowed_ssid(wpa_s
, ssid
->ssid
, ssid
->ssid_len
)) {
111 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS is disallowed");
115 res
= wpas_temp_disabled(wpa_s
, ssid
);
117 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is temporarily "
118 "disabled for %d second(s)", res
);
122 wpa_dbg(wpa_s
, MSG_DEBUG
, "Network configuration found for the "
124 if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
126 size_t wpa_ie_len
= sizeof(wpa_ie
);
127 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
128 wpa_ie
, &wpa_ie_len
) < 0)
129 wpa_dbg(wpa_s
, MSG_DEBUG
, "Could not set WPA suites");
131 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
134 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
)
135 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
136 old_ssid
= wpa_s
->current_ssid
;
137 wpa_s
->current_ssid
= ssid
;
139 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
141 wpa_supplicant_update_scan_results(wpa_s
);
143 /* Get the BSS from the new scan results */
144 bss
= wpa_supplicant_get_new_bss(wpa_s
, wpa_s
->bssid
);
148 wpa_s
->current_bss
= bss
;
150 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
151 wpa_supplicant_initiate_eapol(wpa_s
);
152 if (old_ssid
!= wpa_s
->current_ssid
)
153 wpas_notify_network_changed(wpa_s
);
159 void wpa_supplicant_stop_countermeasures(void *eloop_ctx
, void *sock_ctx
)
161 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
163 if (wpa_s
->countermeasures
) {
164 wpa_s
->countermeasures
= 0;
165 wpa_drv_set_countermeasures(wpa_s
, 0);
166 wpa_msg(wpa_s
, MSG_INFO
, "WPA: TKIP countermeasures stopped");
167 wpa_supplicant_req_scan(wpa_s
, 0, 0);
172 void wpa_supplicant_mark_disassoc(struct wpa_supplicant
*wpa_s
)
176 wnm_bss_keep_alive_deinit(wpa_s
);
178 #ifdef CONFIG_IBSS_RSN
179 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
180 wpa_s
->ibss_rsn
= NULL
;
181 #endif /* CONFIG_IBSS_RSN */
184 wpa_supplicant_ap_deinit(wpa_s
);
185 #endif /* CONFIG_AP */
187 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
190 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
191 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
192 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
193 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
195 wpa_s
->sme
.prev_bssid_set
= 0;
196 #endif /* CONFIG_SME */
198 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
199 #endif /* CONFIG_P2P */
200 wpa_s
->current_bss
= NULL
;
201 wpa_s
->assoc_freq
= 0;
202 #ifdef CONFIG_IEEE80211R
204 if (wpa_s
->sme
.ft_ies
)
205 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
206 #endif /* CONFIG_SME */
207 #endif /* CONFIG_IEEE80211R */
210 wpas_notify_bssid_changed(wpa_s
);
212 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
213 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
214 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
215 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
216 wpa_s
->ap_ies_from_associnfo
= 0;
217 wpa_s
->current_ssid
= NULL
;
218 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
223 static void wpa_find_assoc_pmkid(struct wpa_supplicant
*wpa_s
)
225 struct wpa_ie_data ie
;
229 if (wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, &ie
) < 0 ||
233 for (i
= 0; i
< ie
.num_pmkid
; i
++) {
234 pmksa_set
= pmksa_cache_set_current(wpa_s
->wpa
,
235 ie
.pmkid
+ i
* PMKID_LEN
,
237 if (pmksa_set
== 0) {
238 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
243 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID from assoc IE %sfound from "
244 "PMKSA cache", pmksa_set
== 0 ? "" : "not ");
248 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant
*wpa_s
,
249 union wpa_event_data
*data
)
252 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: No data in PMKID candidate "
256 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: PMKID candidate event - bssid=" MACSTR
257 " index=%d preauth=%d",
258 MAC2STR(data
->pmkid_candidate
.bssid
),
259 data
->pmkid_candidate
.index
,
260 data
->pmkid_candidate
.preauth
);
262 pmksa_candidate_add(wpa_s
->wpa
, data
->pmkid_candidate
.bssid
,
263 data
->pmkid_candidate
.index
,
264 data
->pmkid_candidate
.preauth
);
268 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant
*wpa_s
)
270 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
271 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
274 #ifdef IEEE8021X_EAPOL
275 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
276 wpa_s
->current_ssid
&&
277 !(wpa_s
->current_ssid
->eapol_flags
&
278 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
279 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))) {
280 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
281 * plaintext or static WEP keys). */
284 #endif /* IEEE8021X_EAPOL */
291 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
292 * @wpa_s: pointer to wpa_supplicant data
293 * @ssid: Configuration data for the network
294 * Returns: 0 on success, -1 on failure
296 * This function is called when starting authentication with a network that is
297 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
299 int wpa_supplicant_scard_init(struct wpa_supplicant
*wpa_s
,
300 struct wpa_ssid
*ssid
)
302 #ifdef IEEE8021X_EAPOL
304 int aka
= 0, sim
= 0;
306 if (ssid
->eap
.pcsc
== NULL
|| wpa_s
->scard
!= NULL
||
307 wpa_s
->conf
->external_sim
)
310 if (ssid
->eap
.eap_methods
== NULL
) {
314 struct eap_method_type
*eap
= ssid
->eap
.eap_methods
;
315 while (eap
->vendor
!= EAP_VENDOR_IETF
||
316 eap
->method
!= EAP_TYPE_NONE
) {
317 if (eap
->vendor
== EAP_VENDOR_IETF
) {
318 if (eap
->method
== EAP_TYPE_SIM
)
320 else if (eap
->method
== EAP_TYPE_AKA
||
321 eap
->method
== EAP_TYPE_AKA_PRIME
)
328 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_SIM
) == NULL
)
330 if (eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA
) == NULL
&&
331 eap_peer_get_eap_method(EAP_VENDOR_IETF
, EAP_TYPE_AKA_PRIME
) ==
336 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to "
337 "use SIM, but neither EAP-SIM nor EAP-AKA are "
342 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected network is configured to use SIM "
343 "(sim=%d aka=%d) - initialize PCSC", sim
, aka
);
345 wpa_s
->scard
= scard_init(NULL
);
346 if (wpa_s
->scard
== NULL
) {
347 wpa_msg(wpa_s
, MSG_WARNING
, "Failed to initialize SIM "
351 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
352 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
353 #endif /* PCSC_FUNCS */
354 #endif /* IEEE8021X_EAPOL */
360 #ifndef CONFIG_NO_SCAN_PROCESSING
362 static int has_wep_key(struct wpa_ssid
*ssid
)
366 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
367 if (ssid
->wep_key_len
[i
])
375 static int wpa_supplicant_match_privacy(struct wpa_bss
*bss
,
376 struct wpa_ssid
*ssid
)
380 if (ssid
->mixed_cell
)
384 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
386 #endif /* CONFIG_WPS */
388 if (has_wep_key(ssid
))
391 #ifdef IEEE8021X_EAPOL
392 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
393 ssid
->eapol_flags
& (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
394 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
))
396 #endif /* IEEE8021X_EAPOL */
398 if (wpa_key_mgmt_wpa(ssid
->key_mgmt
))
401 if (bss
->caps
& IEEE80211_CAP_PRIVACY
)
407 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant
*wpa_s
,
408 struct wpa_ssid
*ssid
,
411 struct wpa_ie_data ie
;
413 const u8
*rsn_ie
, *wpa_ie
;
417 ret
= wpas_wps_ssid_bss_match(wpa_s
, ssid
, bss
);
421 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
422 wep_ok
= !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
423 (((ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
424 ssid
->wep_key_len
[ssid
->wep_tx_keyidx
] > 0) ||
425 (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
));
427 rsn_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
428 while ((ssid
->proto
& WPA_PROTO_RSN
) && rsn_ie
) {
431 if (wpa_parse_wpa_ie(rsn_ie
, 2 + rsn_ie
[1], &ie
)) {
432 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - parse "
438 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
440 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
445 if (!(ie
.proto
& ssid
->proto
)) {
446 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - proto "
451 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
452 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - PTK "
457 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
458 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - GTK "
463 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
464 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - key mgmt "
469 #ifdef CONFIG_IEEE80211W
470 if (!(ie
.capabilities
& WPA_CAPABILITY_MFPC
) &&
471 (ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
?
472 wpa_s
->conf
->pmf
: ssid
->ieee80211w
) ==
473 MGMT_FRAME_PROTECTION_REQUIRED
) {
474 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip RSN IE - no mgmt "
478 #endif /* CONFIG_IEEE80211W */
480 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on RSN IE");
484 wpa_ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
485 while ((ssid
->proto
& WPA_PROTO_WPA
) && wpa_ie
) {
488 if (wpa_parse_wpa_ie(wpa_ie
, 2 + wpa_ie
[1], &ie
)) {
489 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - parse "
495 (ie
.group_cipher
& (WPA_CIPHER_WEP40
| WPA_CIPHER_WEP104
)))
497 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on TSN "
502 if (!(ie
.proto
& ssid
->proto
)) {
503 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - proto "
508 if (!(ie
.pairwise_cipher
& ssid
->pairwise_cipher
)) {
509 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - PTK "
514 if (!(ie
.group_cipher
& ssid
->group_cipher
)) {
515 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - GTK "
520 if (!(ie
.key_mgmt
& ssid
->key_mgmt
)) {
521 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip WPA IE - key mgmt "
526 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected based on WPA IE");
530 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && !wpa_ie
&&
532 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow for non-WPA IEEE 802.1X");
536 if ((ssid
->proto
& (WPA_PROTO_WPA
| WPA_PROTO_RSN
)) &&
537 wpa_key_mgmt_wpa(ssid
->key_mgmt
) && proto_match
== 0) {
538 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no WPA/RSN proto match");
542 if (!wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
543 wpa_dbg(wpa_s
, MSG_DEBUG
, " allow in non-WPA/WPA2");
547 wpa_dbg(wpa_s
, MSG_DEBUG
, " reject due to mismatch with "
554 static int freq_allowed(int *freqs
, int freq
)
561 for (i
= 0; freqs
[i
]; i
++)
562 if (freqs
[i
] == freq
)
568 static int ht_supported(const struct hostapd_hw_modes
*mode
)
570 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
)) {
572 * The driver did not indicate whether it supports HT. Assume
573 * it does to avoid connection issues.
579 * IEEE Std 802.11n-2009 20.1.1:
580 * An HT non-AP STA shall support all EQM rates for one spatial stream.
582 return mode
->mcs_set
[0] == 0xff;
586 static int vht_supported(const struct hostapd_hw_modes
*mode
)
588 if (!(mode
->flags
& HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN
)) {
590 * The driver did not indicate whether it supports VHT. Assume
591 * it does to avoid connection issues.
597 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
598 * TODO: Verify if this complies with the standard
600 return (mode
->vht_mcs_set
[0] & 0x3) != 3;
604 static int rate_match(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
606 const struct hostapd_hw_modes
*mode
= NULL
, *modes
;
607 const u8 scan_ie
[2] = { WLAN_EID_SUPP_RATES
, WLAN_EID_EXT_SUPP_RATES
};
612 return 1; /* Cannot do matching without knowing band */
614 modes
= wpa_s
->hw
.modes
;
617 * The driver does not provide any additional information
618 * about the utilized hardware, so allow the connection attempt
624 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
625 for (j
= 0; j
< modes
[i
].num_channels
; j
++) {
626 int freq
= modes
[i
].channels
[j
].freq
;
627 if (freq
== bss
->freq
) {
629 mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
630 break; /* do not allow 802.11b replace
641 for (i
= 0; i
< (int) sizeof(scan_ie
); i
++) {
642 rate_ie
= wpa_bss_get_ie(bss
, scan_ie
[i
]);
646 for (j
= 2; j
< rate_ie
[1] + 2; j
++) {
647 int flagged
= !!(rate_ie
[j
] & 0x80);
648 int r
= (rate_ie
[j
] & 0x7f) * 5;
651 * IEEE Std 802.11n-2009 7.3.2.2:
652 * The new BSS Membership selector value is encoded
653 * like a legacy basic rate, but it is not a rate and
654 * only indicates if the BSS members are required to
655 * support the mandatory features of Clause 20 [HT PHY]
656 * in order to join the BSS.
658 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
659 BSS_MEMBERSHIP_SELECTOR_HT_PHY
)) {
660 if (!ht_supported(mode
)) {
661 wpa_dbg(wpa_s
, MSG_DEBUG
,
662 " hardware does not support "
669 /* There's also a VHT selector for 802.11ac */
670 if (flagged
&& ((rate_ie
[j
] & 0x7f) ==
671 BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)) {
672 if (!vht_supported(mode
)) {
673 wpa_dbg(wpa_s
, MSG_DEBUG
,
674 " hardware does not support "
684 /* check for legacy basic rates */
685 for (k
= 0; k
< mode
->num_rates
; k
++) {
686 if (mode
->rates
[k
] == r
)
689 if (k
== mode
->num_rates
) {
691 * IEEE Std 802.11-2007 7.3.2.2 demands that in
692 * order to join a BSS all required rates
693 * have to be supported by the hardware.
695 wpa_dbg(wpa_s
, MSG_DEBUG
, " hardware does "
696 "not support required rate %d.%d Mbps",
707 static int bss_is_dmg(struct wpa_bss
*bss
)
709 return bss
->freq
> 45000;
714 * Test whether BSS is in an ESS.
715 * This is done differently in DMG (60 GHz) and non-DMG bands
717 static int bss_is_ess(struct wpa_bss
*bss
)
719 if (bss_is_dmg(bss
)) {
720 return (bss
->caps
& IEEE80211_CAP_DMG_MASK
) ==
721 IEEE80211_CAP_DMG_AP
;
724 return ((bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
729 static struct wpa_ssid
* wpa_scan_res_match(struct wpa_supplicant
*wpa_s
,
730 int i
, struct wpa_bss
*bss
,
731 struct wpa_ssid
*group
,
734 u8 wpa_ie_len
, rsn_ie_len
;
736 struct wpa_blacklist
*e
;
738 struct wpa_ssid
*ssid
;
740 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
741 wpa_ie_len
= ie
? ie
[1] : 0;
743 ie
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
744 rsn_ie_len
= ie
? ie
[1] : 0;
746 wpa_dbg(wpa_s
, MSG_DEBUG
, "%d: " MACSTR
" ssid='%s' "
747 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
748 i
, MAC2STR(bss
->bssid
), wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
749 wpa_ie_len
, rsn_ie_len
, bss
->caps
, bss
->level
,
750 wpa_bss_get_vendor_ie(bss
, WPS_IE_VENDOR_TYPE
) ? " wps" : "",
751 (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
752 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) ?
755 e
= wpa_blacklist_get(wpa_s
, bss
->bssid
);
758 if (wpa_supplicant_enabled_networks(wpa_s
) == 1) {
760 * When only a single network is enabled, we can
761 * trigger blacklisting on the first failure. This
762 * should not be done with multiple enabled networks to
763 * avoid getting forced to move into a worse ESS on
764 * single error if there are no other BSSes of the
769 if (e
->count
> limit
) {
770 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
771 "(count=%d limit=%d)", e
->count
, limit
);
776 if (bss
->ssid_len
== 0) {
777 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID not known");
781 if (disallowed_bssid(wpa_s
, bss
->bssid
)) {
782 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID disallowed");
786 if (disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
787 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID disallowed");
791 wpa
= wpa_ie_len
> 0 || rsn_ie_len
> 0;
793 for (ssid
= group
; ssid
; ssid
= only_first_ssid
? NULL
: ssid
->pnext
) {
794 int check_ssid
= wpa
? 1 : (ssid
->ssid_len
!= 0);
797 if (wpas_network_disabled(wpa_s
, ssid
)) {
798 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled");
802 res
= wpas_temp_disabled(wpa_s
, ssid
);
804 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - disabled "
805 "temporarily for %d second(s)", res
);
810 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) && e
&& e
->count
> 0) {
811 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - blacklisted "
816 if (wpa
&& ssid
->ssid_len
== 0 &&
817 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
820 if (!wpa
&& (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
821 /* Only allow wildcard SSID match if an AP
822 * advertises active WPS operation that matches
825 if (ssid
->ssid_len
== 0 &&
826 wpas_wps_ssid_wildcard_ok(wpa_s
, ssid
, bss
))
829 #endif /* CONFIG_WPS */
831 if (ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
832 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) == 0)
836 (bss
->ssid_len
!= ssid
->ssid_len
||
837 os_memcmp(bss
->ssid
, ssid
->ssid
, bss
->ssid_len
) != 0)) {
838 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - SSID mismatch");
842 if (ssid
->bssid_set
&&
843 os_memcmp(bss
->bssid
, ssid
->bssid
, ETH_ALEN
) != 0) {
844 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - BSSID mismatch");
848 if (!wpa_supplicant_ssid_bss_match(wpa_s
, ssid
, bss
))
852 !(ssid
->key_mgmt
& WPA_KEY_MGMT_NONE
) &&
853 !(ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
854 !(ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) {
855 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - non-WPA network "
860 if (wpa
&& !wpa_key_mgmt_wpa(ssid
->key_mgmt
) &&
862 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - ignore WPA/WPA2 AP for WEP network block");
866 if (!wpa_supplicant_match_privacy(bss
, ssid
)) {
867 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - privacy "
872 if (!bss_is_ess(bss
)) {
873 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - not ESS network");
877 if (!freq_allowed(ssid
->freq_list
, bss
->freq
)) {
878 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - frequency not "
883 if (!rate_match(wpa_s
, bss
)) {
884 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - rate sets do "
890 if (ssid
->p2p_group
&&
891 !wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
892 !wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
893 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no P2P IE seen");
897 if (!is_zero_ether_addr(ssid
->go_p2p_dev_addr
)) {
898 struct wpabuf
*p2p_ie
;
899 u8 dev_addr
[ETH_ALEN
];
901 ie
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
903 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no P2P element");
906 p2p_ie
= wpa_bss_get_vendor_ie_multi(
907 bss
, P2P_IE_VENDOR_TYPE
);
908 if (p2p_ie
== NULL
) {
909 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - could not fetch P2P element");
913 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie
, dev_addr
) < 0
914 || os_memcmp(dev_addr
, ssid
->go_p2p_dev_addr
,
916 wpa_dbg(wpa_s
, MSG_DEBUG
, " skip - no matching GO P2P Device Address in P2P element");
924 * TODO: skip the AP if its P2P IE has Group Formation
925 * bit set in the P2P Group Capability Bitmap and we
926 * are not in Group Formation with that device.
928 #endif /* CONFIG_P2P */
930 /* Matching configuration found */
934 /* No matching configuration found */
939 static struct wpa_bss
*
940 wpa_supplicant_select_bss(struct wpa_supplicant
*wpa_s
,
941 struct wpa_ssid
*group
,
942 struct wpa_ssid
**selected_ssid
,
948 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to find BSS matching pre-selected network id=%d",
951 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selecting BSS from priority group %d",
954 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
955 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[i
];
956 *selected_ssid
= wpa_scan_res_match(wpa_s
, i
, bss
, group
,
960 wpa_dbg(wpa_s
, MSG_DEBUG
, " selected BSS " MACSTR
963 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
971 struct wpa_bss
* wpa_supplicant_pick_network(struct wpa_supplicant
*wpa_s
,
972 struct wpa_ssid
**selected_ssid
)
974 struct wpa_bss
*selected
= NULL
;
977 if (wpa_s
->last_scan_res
== NULL
||
978 wpa_s
->last_scan_res_used
== 0)
979 return NULL
; /* no scan results from last update */
981 while (selected
== NULL
) {
982 if (wpa_s
->next_ssid
) {
983 struct wpa_ssid
*ssid
;
985 /* check that next_ssid is still valid */
986 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
987 if (ssid
== wpa_s
->next_ssid
)
989 wpa_s
->next_ssid
= NULL
;
992 selected
= wpa_supplicant_select_bss(
993 wpa_s
, ssid
, selected_ssid
, 1);
999 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1000 selected
= wpa_supplicant_select_bss(
1001 wpa_s
, wpa_s
->conf
->pssid
[prio
],
1007 if (selected
== NULL
&& wpa_s
->blacklist
&&
1008 !wpa_s
->countermeasures
) {
1009 wpa_dbg(wpa_s
, MSG_DEBUG
, "No APs found - clear "
1010 "blacklist and try again");
1011 wpa_blacklist_clear(wpa_s
);
1012 wpa_s
->blacklist_cleared
++;
1013 } else if (selected
== NULL
)
1021 static void wpa_supplicant_req_new_scan(struct wpa_supplicant
*wpa_s
,
1022 int timeout_sec
, int timeout_usec
)
1024 if (!wpa_supplicant_enabled_networks(wpa_s
)) {
1026 * No networks are enabled; short-circuit request so
1027 * we don't wait timeout seconds before transitioning
1028 * to INACTIVE state.
1030 wpa_dbg(wpa_s
, MSG_DEBUG
, "Short-circuit new scan request "
1031 "since there are no enabled networks");
1032 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1036 wpa_s
->scan_for_connection
= 1;
1037 wpa_supplicant_req_scan(wpa_s
, timeout_sec
, timeout_usec
);
1041 int wpa_supplicant_connect(struct wpa_supplicant
*wpa_s
,
1042 struct wpa_bss
*selected
,
1043 struct wpa_ssid
*ssid
)
1045 if (wpas_wps_scan_pbc_overlap(wpa_s
, selected
, ssid
)) {
1046 wpa_msg(wpa_s
, MSG_INFO
, WPS_EVENT_OVERLAP
1047 "PBC session overlap");
1049 if (wpas_p2p_notif_pbc_overlap(wpa_s
) == 1)
1051 #endif /* CONFIG_P2P */
1054 wpas_wps_cancel(wpa_s
);
1055 #endif /* CONFIG_WPS */
1059 wpa_msg(wpa_s
, MSG_DEBUG
,
1060 "Considering connect request: reassociate: %d selected: "
1061 MACSTR
" bssid: " MACSTR
" pending: " MACSTR
1062 " wpa_state: %s ssid=%p current_ssid=%p",
1063 wpa_s
->reassociate
, MAC2STR(selected
->bssid
),
1064 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
1065 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
1066 ssid
, wpa_s
->current_ssid
);
1069 * Do not trigger new association unless the BSSID has changed or if
1070 * reassociation is requested. If we are in process of associating with
1071 * the selected BSSID, do not trigger new attempt.
1073 if (wpa_s
->reassociate
||
1074 (os_memcmp(selected
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1075 ((wpa_s
->wpa_state
!= WPA_ASSOCIATING
&&
1076 wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) ||
1077 (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1078 os_memcmp(selected
->bssid
, wpa_s
->pending_bssid
, ETH_ALEN
) !=
1080 (is_zero_ether_addr(wpa_s
->pending_bssid
) &&
1081 ssid
!= wpa_s
->current_ssid
)))) {
1082 if (wpa_supplicant_scard_init(wpa_s
, ssid
)) {
1083 wpa_supplicant_req_new_scan(wpa_s
, 10, 0);
1086 wpa_msg(wpa_s
, MSG_DEBUG
, "Request association with " MACSTR
,
1087 MAC2STR(selected
->bssid
));
1088 wpa_supplicant_associate(wpa_s
, selected
, ssid
);
1090 wpa_dbg(wpa_s
, MSG_DEBUG
, "Already associated or trying to "
1091 "connect with the selected AP");
1098 static struct wpa_ssid
*
1099 wpa_supplicant_pick_new_network(struct wpa_supplicant
*wpa_s
)
1102 struct wpa_ssid
*ssid
;
1104 for (prio
= 0; prio
< wpa_s
->conf
->num_prio
; prio
++) {
1105 for (ssid
= wpa_s
->conf
->pssid
[prio
]; ssid
; ssid
= ssid
->pnext
)
1107 if (wpas_network_disabled(wpa_s
, ssid
))
1109 if (ssid
->mode
== IEEE80211_MODE_IBSS
||
1110 ssid
->mode
== IEEE80211_MODE_AP
)
1118 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1119 * on BSS added and BSS changed events */
1120 static void wpa_supplicant_rsn_preauth_scan_results(
1121 struct wpa_supplicant
*wpa_s
)
1123 struct wpa_bss
*bss
;
1125 if (rsn_preauth_scan_results(wpa_s
->wpa
) < 0)
1128 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1129 const u8
*ssid
, *rsn
;
1131 ssid
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1135 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1139 rsn_preauth_scan_result(wpa_s
->wpa
, bss
->bssid
, ssid
, rsn
);
1145 static int wpa_supplicant_need_to_roam(struct wpa_supplicant
*wpa_s
,
1146 struct wpa_bss
*selected
,
1147 struct wpa_ssid
*ssid
)
1149 struct wpa_bss
*current_bss
= NULL
;
1152 if (wpa_s
->reassociate
)
1153 return 1; /* explicit request to reassociate */
1154 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1155 return 1; /* we are not associated; continue */
1156 if (wpa_s
->current_ssid
== NULL
)
1157 return 1; /* unknown current SSID */
1158 if (wpa_s
->current_ssid
!= ssid
)
1159 return 1; /* different network block */
1161 if (wpas_driver_bss_selection(wpa_s
))
1162 return 0; /* Driver-based roaming */
1164 if (wpa_s
->current_ssid
->ssid
)
1165 current_bss
= wpa_bss_get(wpa_s
, wpa_s
->bssid
,
1166 wpa_s
->current_ssid
->ssid
,
1167 wpa_s
->current_ssid
->ssid_len
);
1169 current_bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->bssid
);
1172 return 1; /* current BSS not seen in scan results */
1174 if (current_bss
== selected
)
1177 if (selected
->last_update_idx
> current_bss
->last_update_idx
)
1178 return 1; /* current BSS not seen in the last scan */
1180 #ifndef CONFIG_NO_ROAMING
1181 wpa_dbg(wpa_s
, MSG_DEBUG
, "Considering within-ESS reassociation");
1182 wpa_dbg(wpa_s
, MSG_DEBUG
, "Current BSS: " MACSTR
" level=%d",
1183 MAC2STR(current_bss
->bssid
), current_bss
->level
);
1184 wpa_dbg(wpa_s
, MSG_DEBUG
, "Selected BSS: " MACSTR
" level=%d",
1185 MAC2STR(selected
->bssid
), selected
->level
);
1187 if (wpa_s
->current_ssid
->bssid_set
&&
1188 os_memcmp(selected
->bssid
, wpa_s
->current_ssid
->bssid
, ETH_ALEN
) ==
1190 wpa_dbg(wpa_s
, MSG_DEBUG
, "Allow reassociation - selected BSS "
1191 "has preferred BSSID");
1195 if (current_bss
->level
< 0 && current_bss
->level
> selected
->level
) {
1196 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - Current BSS has better "
1202 if (current_bss
->level
< 0) {
1203 if (current_bss
->level
< -85)
1205 else if (current_bss
->level
< -80)
1207 else if (current_bss
->level
< -75)
1209 else if (current_bss
->level
< -70)
1214 if (abs(current_bss
->level
- selected
->level
) < min_diff
) {
1215 wpa_dbg(wpa_s
, MSG_DEBUG
, "Skip roam - too small difference "
1221 #else /* CONFIG_NO_ROAMING */
1223 #endif /* CONFIG_NO_ROAMING */
1227 /* Return != 0 if no scan results could be fetched or if scan results should not
1228 * be shared with other virtual interfaces. */
1229 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1230 union wpa_event_data
*data
,
1233 struct wpa_scan_results
*scan_res
= NULL
;
1236 #ifndef CONFIG_NO_RANDOM_POOL
1238 #endif /* CONFIG_NO_RANDOM_POOL */
1241 if (wpa_s
->ap_iface
)
1243 #endif /* CONFIG_AP */
1245 wpa_supplicant_notify_scanning(wpa_s
, 0);
1247 scan_res
= wpa_supplicant_get_scan_results(wpa_s
,
1248 data
? &data
->scan_info
:
1250 if (scan_res
== NULL
) {
1251 if (wpa_s
->conf
->ap_scan
== 2 || ap
||
1252 wpa_s
->scan_res_handler
== scan_only_handler
)
1256 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to get scan results - try "
1258 wpa_supplicant_req_new_scan(wpa_s
, 1, 0);
1260 goto scan_work_done
;
1263 #ifndef CONFIG_NO_RANDOM_POOL
1264 num
= scan_res
->num
;
1267 for (i
= 0; i
< num
; i
++) {
1269 struct wpa_scan_res
*res
= scan_res
->res
[i
];
1270 buf
[0] = res
->bssid
[5];
1271 buf
[1] = res
->qual
& 0xff;
1272 buf
[2] = res
->noise
& 0xff;
1273 buf
[3] = res
->level
& 0xff;
1274 buf
[4] = res
->tsf
& 0xff;
1275 random_add_randomness(buf
, sizeof(buf
));
1277 #endif /* CONFIG_NO_RANDOM_POOL */
1279 if (own_request
&& wpa_s
->scan_res_handler
&&
1280 (wpa_s
->own_scan_running
|| !wpa_s
->external_scan_running
)) {
1281 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
1282 struct wpa_scan_results
*scan_res
);
1284 scan_res_handler
= wpa_s
->scan_res_handler
;
1285 wpa_s
->scan_res_handler
= NULL
;
1286 scan_res_handler(wpa_s
, scan_res
);
1288 goto scan_work_done
;
1292 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore scan results in AP mode");
1294 if (wpa_s
->ap_iface
->scan_cb
)
1295 wpa_s
->ap_iface
->scan_cb(wpa_s
->ap_iface
);
1296 #endif /* CONFIG_AP */
1297 goto scan_work_done
;
1300 wpa_dbg(wpa_s
, MSG_DEBUG
, "New scan results available (own=%u ext=%u)",
1301 wpa_s
->own_scan_running
, wpa_s
->external_scan_running
);
1302 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
1303 wpa_s
->manual_scan_use_id
&& wpa_s
->own_scan_running
) {
1304 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
"id=%u",
1305 wpa_s
->manual_scan_id
);
1306 wpa_s
->manual_scan_use_id
= 0;
1308 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_RESULTS
);
1310 wpas_notify_scan_results(wpa_s
);
1312 wpas_notify_scan_done(wpa_s
, 1);
1314 if (!wpa_s
->own_scan_running
&& wpa_s
->external_scan_running
) {
1315 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not use results from externally requested scan operation for network selection");
1316 wpa_scan_results_free(scan_res
);
1320 if (sme_proc_obss_scan(wpa_s
) > 0)
1321 goto scan_work_done
;
1323 if ((wpa_s
->conf
->ap_scan
== 2 && !wpas_wps_searching(wpa_s
)))
1324 goto scan_work_done
;
1326 if (autoscan_notify_scan(wpa_s
, scan_res
))
1327 goto scan_work_done
;
1329 if (wpa_s
->disconnected
) {
1330 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1331 goto scan_work_done
;
1334 if (!wpas_driver_bss_selection(wpa_s
) &&
1335 bgscan_notify_scan(wpa_s
, scan_res
) == 1)
1336 goto scan_work_done
;
1338 wpas_wps_update_ap_info(wpa_s
, scan_res
);
1340 wpa_scan_results_free(scan_res
);
1342 if (wpa_s
->scan_work
) {
1343 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1344 wpa_s
->scan_work
= NULL
;
1345 radio_work_done(work
);
1348 return wpas_select_network_from_last_scan(wpa_s
, 1, own_request
);
1351 wpa_scan_results_free(scan_res
);
1352 if (wpa_s
->scan_work
) {
1353 struct wpa_radio_work
*work
= wpa_s
->scan_work
;
1354 wpa_s
->scan_work
= NULL
;
1355 radio_work_done(work
);
1361 static int wpas_select_network_from_last_scan(struct wpa_supplicant
*wpa_s
,
1362 int new_scan
, int own_request
)
1364 struct wpa_bss
*selected
;
1365 struct wpa_ssid
*ssid
= NULL
;
1367 selected
= wpa_supplicant_pick_network(wpa_s
, &ssid
);
1371 skip
= !wpa_supplicant_need_to_roam(wpa_s
, selected
, ssid
);
1374 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1378 if (wpa_supplicant_connect(wpa_s
, selected
, ssid
) < 0) {
1379 wpa_dbg(wpa_s
, MSG_DEBUG
, "Connect failed");
1383 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1385 * Do not notify other virtual radios of scan results since we do not
1386 * want them to start other associations at the same time.
1390 wpa_dbg(wpa_s
, MSG_DEBUG
, "No suitable network found");
1391 ssid
= wpa_supplicant_pick_new_network(wpa_s
);
1393 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setup a new network");
1394 wpa_supplicant_associate(wpa_s
, NULL
, ssid
);
1396 wpa_supplicant_rsn_preauth_scan_results(wpa_s
);
1397 } else if (own_request
) {
1399 * No SSID found. If SCAN results are as a result of
1400 * own scan request and not due to a scan request on
1401 * another shared interface, try another scan.
1403 int timeout_sec
= wpa_s
->scan_interval
;
1404 int timeout_usec
= 0;
1406 if (wpas_p2p_scan_no_go_seen(wpa_s
) == 1)
1409 if (wpa_s
->p2p_in_provisioning
||
1410 wpa_s
->show_group_started
) {
1412 * Use shorter wait during P2P Provisioning
1413 * state and during P2P join-a-group operation
1414 * to speed up group formation.
1417 timeout_usec
= 250000;
1418 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1422 #endif /* CONFIG_P2P */
1423 #ifdef CONFIG_INTERWORKING
1424 if (wpa_s
->conf
->auto_interworking
&&
1425 wpa_s
->conf
->interworking
&&
1426 wpa_s
->conf
->cred
) {
1427 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: "
1428 "start ANQP fetch since no matching "
1430 wpa_s
->network_select
= 1;
1431 wpa_s
->auto_network_select
= 1;
1432 interworking_start_fetch_anqp(wpa_s
);
1435 #endif /* CONFIG_INTERWORKING */
1437 if (wpa_s
->after_wps
> 0 || wpas_wps_searching(wpa_s
)) {
1438 wpa_dbg(wpa_s
, MSG_DEBUG
, "Use shorter wait during WPS processing");
1440 timeout_usec
= 500000;
1441 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1445 #endif /* CONFIG_WPS */
1446 if (wpa_supplicant_req_sched_scan(wpa_s
))
1447 wpa_supplicant_req_new_scan(wpa_s
, timeout_sec
,
1455 static void wpa_supplicant_event_scan_results(struct wpa_supplicant
*wpa_s
,
1456 union wpa_event_data
*data
)
1458 struct wpa_supplicant
*ifs
;
1460 if (_wpa_supplicant_event_scan_results(wpa_s
, data
, 1) != 0) {
1462 * If no scan results could be fetched, then no need to
1463 * notify those interfaces that did not actually request
1464 * this scan. Similarly, if scan results started a new operation on this
1465 * interface, do not notify other interfaces to avoid concurrent
1466 * operations during a connection attempt.
1472 * Check other interfaces to see if they share the same radio. If
1473 * so, they get updated with this same scan info.
1475 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
1478 wpa_printf(MSG_DEBUG
, "%s: Updating scan results from "
1479 "sibling", ifs
->ifname
);
1480 _wpa_supplicant_event_scan_results(ifs
, data
, 0);
1485 #endif /* CONFIG_NO_SCAN_PROCESSING */
1488 int wpa_supplicant_fast_associate(struct wpa_supplicant
*wpa_s
)
1490 #ifdef CONFIG_NO_SCAN_PROCESSING
1492 #else /* CONFIG_NO_SCAN_PROCESSING */
1493 struct os_reltime now
;
1495 if (wpa_s
->last_scan_res_used
<= 0)
1498 os_get_reltime(&now
);
1499 if (os_reltime_expired(&now
, &wpa_s
->last_scan
, 5)) {
1500 wpa_printf(MSG_DEBUG
, "Fast associate: Old scan results");
1504 return wpas_select_network_from_last_scan(wpa_s
, 0, 1);
1505 #endif /* CONFIG_NO_SCAN_PROCESSING */
1510 static void wnm_bss_keep_alive(void *eloop_ctx
, void *sock_ctx
)
1512 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1514 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
1517 if (!wpa_s
->no_keep_alive
) {
1518 wpa_printf(MSG_DEBUG
, "WNM: Send keep-alive to AP " MACSTR
,
1519 MAC2STR(wpa_s
->bssid
));
1520 /* TODO: could skip this if normal data traffic has been sent */
1521 /* TODO: Consider using some more appropriate data frame for
1524 l2_packet_send(wpa_s
->l2
, wpa_s
->bssid
, 0x0800,
1529 if (wpa_s
->sme
.bss_max_idle_period
) {
1531 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024; /* times 1000 */
1534 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1535 wnm_bss_keep_alive
, wpa_s
, NULL
);
1537 #endif /* CONFIG_SME */
1541 static void wnm_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1542 const u8
*ies
, size_t ies_len
)
1544 struct ieee802_11_elems elems
;
1549 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1553 if (elems
.bss_max_idle_period
) {
1555 wpa_s
->sme
.bss_max_idle_period
=
1556 WPA_GET_LE16(elems
.bss_max_idle_period
);
1557 wpa_printf(MSG_DEBUG
, "WNM: BSS Max Idle Period: %u (* 1000 "
1558 "TU)%s", wpa_s
->sme
.bss_max_idle_period
,
1559 (elems
.bss_max_idle_period
[2] & 0x01) ?
1560 " (protected keep-live required)" : "");
1561 if (wpa_s
->sme
.bss_max_idle_period
== 0)
1562 wpa_s
->sme
.bss_max_idle_period
= 1;
1563 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) {
1564 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1565 /* msec times 1000 */
1566 msec
= wpa_s
->sme
.bss_max_idle_period
* 1024;
1569 eloop_register_timeout(msec
/ 1000, msec
% 1000 * 1000,
1570 wnm_bss_keep_alive
, wpa_s
,
1574 #endif /* CONFIG_SME */
1577 #endif /* CONFIG_WNM */
1580 void wnm_bss_keep_alive_deinit(struct wpa_supplicant
*wpa_s
)
1583 eloop_cancel_timeout(wnm_bss_keep_alive
, wpa_s
, NULL
);
1584 #endif /* CONFIG_WNM */
1588 #ifdef CONFIG_INTERWORKING
1590 static int wpas_qos_map_set(struct wpa_supplicant
*wpa_s
, const u8
*qos_map
,
1595 wpa_hexdump(MSG_DEBUG
, "Interworking: QoS Map Set", qos_map
, len
);
1596 res
= wpa_drv_set_qos_map(wpa_s
, qos_map
, len
);
1598 wpa_printf(MSG_DEBUG
, "Interworking: Failed to configure QoS Map Set to the driver");
1605 static void interworking_process_assoc_resp(struct wpa_supplicant
*wpa_s
,
1606 const u8
*ies
, size_t ies_len
)
1608 struct ieee802_11_elems elems
;
1613 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
)
1616 if (elems
.qos_map_set
) {
1617 wpas_qos_map_set(wpa_s
, elems
.qos_map_set
,
1618 elems
.qos_map_set_len
);
1622 #endif /* CONFIG_INTERWORKING */
1625 static int wpa_supplicant_event_associnfo(struct wpa_supplicant
*wpa_s
,
1626 union wpa_event_data
*data
)
1628 int l
, len
, found
= 0, wpa_found
, rsn_found
;
1630 #ifdef CONFIG_IEEE80211R
1632 #endif /* CONFIG_IEEE80211R */
1634 wpa_dbg(wpa_s
, MSG_DEBUG
, "Association info event");
1635 if (data
->assoc_info
.req_ies
)
1636 wpa_hexdump(MSG_DEBUG
, "req_ies", data
->assoc_info
.req_ies
,
1637 data
->assoc_info
.req_ies_len
);
1638 if (data
->assoc_info
.resp_ies
) {
1639 wpa_hexdump(MSG_DEBUG
, "resp_ies", data
->assoc_info
.resp_ies
,
1640 data
->assoc_info
.resp_ies_len
);
1642 wpa_tdls_assoc_resp_ies(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1643 data
->assoc_info
.resp_ies_len
);
1644 #endif /* CONFIG_TDLS */
1646 wnm_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1647 data
->assoc_info
.resp_ies_len
);
1648 #endif /* CONFIG_WNM */
1649 #ifdef CONFIG_INTERWORKING
1650 interworking_process_assoc_resp(wpa_s
, data
->assoc_info
.resp_ies
,
1651 data
->assoc_info
.resp_ies_len
);
1652 #endif /* CONFIG_INTERWORKING */
1654 if (data
->assoc_info
.beacon_ies
)
1655 wpa_hexdump(MSG_DEBUG
, "beacon_ies",
1656 data
->assoc_info
.beacon_ies
,
1657 data
->assoc_info
.beacon_ies_len
);
1658 if (data
->assoc_info
.freq
)
1659 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq=%u MHz",
1660 data
->assoc_info
.freq
);
1662 p
= data
->assoc_info
.req_ies
;
1663 l
= data
->assoc_info
.req_ies_len
;
1665 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1666 while (p
&& l
>= 2) {
1669 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1673 if ((p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1674 (os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1675 (p
[0] == WLAN_EID_RSN
&& p
[1] >= 2)) {
1676 if (wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, p
, len
))
1679 wpa_find_assoc_pmkid(wpa_s
);
1685 if (!found
&& data
->assoc_info
.req_ies
)
1686 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1688 #ifdef CONFIG_IEEE80211R
1690 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FT
) {
1691 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1692 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1693 data
->assoc_info
.resp_ies
,
1694 data
->assoc_info
.resp_ies_len
,
1696 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1697 "Reassociation Response failed");
1698 wpa_supplicant_deauthenticate(
1699 wpa_s
, WLAN_REASON_INVALID_IE
);
1704 p
= data
->assoc_info
.resp_ies
;
1705 l
= data
->assoc_info
.resp_ies_len
;
1707 #ifdef CONFIG_WPS_STRICT
1708 if (p
&& wpa_s
->current_ssid
&&
1709 wpa_s
->current_ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
1711 wps
= ieee802_11_vendor_ie_concat(p
, l
, WPS_IE_VENDOR_TYPE
);
1713 wpa_msg(wpa_s
, MSG_INFO
, "WPS-STRICT: AP did not "
1714 "include WPS IE in (Re)Association Response");
1718 if (wps_validate_assoc_resp(wps
) < 0) {
1720 wpa_supplicant_deauthenticate(
1721 wpa_s
, WLAN_REASON_INVALID_IE
);
1726 #endif /* CONFIG_WPS_STRICT */
1728 /* Go through the IEs and make a copy of the MDIE, if present. */
1729 while (p
&& l
>= 2) {
1732 wpa_hexdump(MSG_DEBUG
, "Truncated IE in assoc_info",
1736 if (p
[0] == WLAN_EID_MOBILITY_DOMAIN
&&
1737 p
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
1738 wpa_s
->sme
.ft_used
= 1;
1739 os_memcpy(wpa_s
->sme
.mobility_domain
, p
+ 2,
1740 MOBILITY_DOMAIN_ID_LEN
);
1746 #endif /* CONFIG_SME */
1748 /* Process FT when SME is in the driver */
1749 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1750 wpa_ft_is_completed(wpa_s
->wpa
)) {
1751 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0 ||
1752 wpa_ft_validate_reassoc_resp(wpa_s
->wpa
,
1753 data
->assoc_info
.resp_ies
,
1754 data
->assoc_info
.resp_ies_len
,
1756 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Validation of "
1757 "Reassociation Response failed");
1758 wpa_supplicant_deauthenticate(
1759 wpa_s
, WLAN_REASON_INVALID_IE
);
1762 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Reassociation Response done");
1765 wpa_sm_set_ft_params(wpa_s
->wpa
, data
->assoc_info
.resp_ies
,
1766 data
->assoc_info
.resp_ies_len
);
1767 #endif /* CONFIG_IEEE80211R */
1769 /* WPA/RSN IE from Beacon/ProbeResp */
1770 p
= data
->assoc_info
.beacon_ies
;
1771 l
= data
->assoc_info
.beacon_ies_len
;
1773 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1775 wpa_found
= rsn_found
= 0;
1776 while (p
&& l
>= 2) {
1779 wpa_hexdump(MSG_DEBUG
, "Truncated IE in beacon_ies",
1784 p
[0] == WLAN_EID_VENDOR_SPECIFIC
&& p
[1] >= 6 &&
1785 os_memcmp(&p
[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1787 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, p
, len
);
1791 p
[0] == WLAN_EID_RSN
&& p
[1] >= 2) {
1793 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, p
, len
);
1800 if (!wpa_found
&& data
->assoc_info
.beacon_ies
)
1801 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1802 if (!rsn_found
&& data
->assoc_info
.beacon_ies
)
1803 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
1804 if (wpa_found
|| rsn_found
)
1805 wpa_s
->ap_ies_from_associnfo
= 1;
1807 if (wpa_s
->assoc_freq
&& data
->assoc_info
.freq
&&
1808 wpa_s
->assoc_freq
!= data
->assoc_info
.freq
) {
1809 wpa_printf(MSG_DEBUG
, "Operating frequency changed from "
1811 wpa_s
->assoc_freq
, data
->assoc_info
.freq
);
1812 wpa_supplicant_update_scan_results(wpa_s
);
1815 wpa_s
->assoc_freq
= data
->assoc_info
.freq
;
1821 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant
*wpa_s
)
1823 const u8
*bss_wpa
= NULL
, *bss_rsn
= NULL
;
1825 if (!wpa_s
->current_bss
|| !wpa_s
->current_ssid
)
1828 if (!wpa_key_mgmt_wpa_any(wpa_s
->current_ssid
->key_mgmt
))
1831 bss_wpa
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1832 WPA_IE_VENDOR_TYPE
);
1833 bss_rsn
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_RSN
);
1835 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1836 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1837 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1838 bss_rsn
? 2 + bss_rsn
[1] : 0))
1845 static void wpa_supplicant_event_assoc(struct wpa_supplicant
*wpa_s
,
1846 union wpa_event_data
*data
)
1852 if (wpa_s
->ap_iface
) {
1853 hostapd_notif_assoc(wpa_s
->ap_iface
->bss
[0],
1854 data
->assoc_info
.addr
,
1855 data
->assoc_info
.req_ies
,
1856 data
->assoc_info
.req_ies_len
,
1857 data
->assoc_info
.reassoc
);
1860 #endif /* CONFIG_AP */
1862 ft_completed
= wpa_ft_is_completed(wpa_s
->wpa
);
1863 if (data
&& wpa_supplicant_event_associnfo(wpa_s
, data
) < 0)
1866 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1867 wpa_dbg(wpa_s
, MSG_ERROR
, "Failed to get BSSID");
1868 wpa_supplicant_deauthenticate(
1869 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1873 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATED
);
1874 if (os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1875 wpa_dbg(wpa_s
, MSG_DEBUG
, "Associated to a new BSS: BSSID="
1876 MACSTR
, MAC2STR(bssid
));
1877 random_add_randomness(bssid
, ETH_ALEN
);
1878 os_memcpy(wpa_s
->bssid
, bssid
, ETH_ALEN
);
1879 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1880 wpas_notify_bssid_changed(wpa_s
);
1882 if (wpa_supplicant_dynamic_keys(wpa_s
) && !ft_completed
) {
1883 wpa_clear_keys(wpa_s
, bssid
);
1885 if (wpa_supplicant_select_config(wpa_s
) < 0) {
1886 wpa_supplicant_deauthenticate(
1887 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1891 if (wpa_s
->conf
->ap_scan
== 1 &&
1892 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
) {
1893 if (wpa_supplicant_assoc_update_ie(wpa_s
) < 0)
1894 wpa_msg(wpa_s
, MSG_WARNING
,
1895 "WPA/RSN IEs not updated");
1900 os_memcpy(wpa_s
->sme
.prev_bssid
, bssid
, ETH_ALEN
);
1901 wpa_s
->sme
.prev_bssid_set
= 1;
1902 #endif /* CONFIG_SME */
1904 wpa_msg(wpa_s
, MSG_INFO
, "Associated with " MACSTR
, MAC2STR(bssid
));
1905 if (wpa_s
->current_ssid
) {
1906 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1907 * initialized before association, but for other modes,
1908 * initialize PC/SC here, if the current configuration needs
1909 * smartcard or SIM/USIM. */
1910 wpa_supplicant_scard_init(wpa_s
, wpa_s
->current_ssid
);
1912 wpa_sm_notify_assoc(wpa_s
->wpa
, bssid
);
1914 l2_packet_notify_auth_start(wpa_s
->l2
);
1917 * Set portEnabled first to FALSE in order to get EAP state machine out
1918 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1919 * state machine may transit to AUTHENTICATING state based on obsolete
1920 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1921 * AUTHENTICATED without ever giving chance to EAP state machine to
1924 if (!ft_completed
) {
1925 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1926 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1928 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) || ft_completed
)
1929 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1930 /* 802.1X::portControl = Auto */
1931 eapol_sm_notify_portEnabled(wpa_s
->eapol
, TRUE
);
1932 wpa_s
->eapol_received
= 0;
1933 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1934 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
||
1935 (wpa_s
->current_ssid
&&
1936 wpa_s
->current_ssid
->mode
== IEEE80211_MODE_IBSS
)) {
1937 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
&&
1939 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
1941 * Set the key after having received joined-IBSS event
1944 wpa_supplicant_set_wpa_none_key(wpa_s
,
1945 wpa_s
->current_ssid
);
1947 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1948 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1949 } else if (!ft_completed
) {
1950 /* Timeout for receiving the first EAPOL packet */
1951 wpa_supplicant_req_auth_timeout(wpa_s
, 10, 0);
1953 wpa_supplicant_cancel_scan(wpa_s
);
1955 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1956 wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
1958 * We are done; the driver will take care of RSN 4-way
1961 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1962 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1963 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1964 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1965 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1966 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1968 * The driver will take care of RSN 4-way handshake, so we need
1969 * to allow EAPOL supplicant to complete its work without
1970 * waiting for WPA supplicant.
1972 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1973 } else if (ft_completed
) {
1975 * FT protocol completed - make sure EAPOL state machine ends
1976 * up in authenticated.
1978 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1979 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1980 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1981 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
1984 wpa_s
->last_eapol_matches_bssid
= 0;
1986 if (wpa_s
->pending_eapol_rx
) {
1987 struct os_reltime now
, age
;
1988 os_get_reltime(&now
);
1989 os_reltime_sub(&now
, &wpa_s
->pending_eapol_rx_time
, &age
);
1990 if (age
.sec
== 0 && age
.usec
< 100000 &&
1991 os_memcmp(wpa_s
->pending_eapol_rx_src
, bssid
, ETH_ALEN
) ==
1993 wpa_dbg(wpa_s
, MSG_DEBUG
, "Process pending EAPOL "
1994 "frame that was received just before "
1995 "association notification");
1996 wpa_supplicant_rx_eapol(
1997 wpa_s
, wpa_s
->pending_eapol_rx_src
,
1998 wpabuf_head(wpa_s
->pending_eapol_rx
),
1999 wpabuf_len(wpa_s
->pending_eapol_rx
));
2001 wpabuf_free(wpa_s
->pending_eapol_rx
);
2002 wpa_s
->pending_eapol_rx
= NULL
;
2005 if ((wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2006 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
2007 wpa_s
->current_ssid
&&
2008 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
)) {
2009 /* Set static WEP keys again */
2010 wpa_set_wep_keys(wpa_s
, wpa_s
->current_ssid
);
2013 #ifdef CONFIG_IBSS_RSN
2014 if (wpa_s
->current_ssid
&&
2015 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
&&
2016 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2017 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
&&
2018 wpa_s
->ibss_rsn
== NULL
) {
2019 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
2020 if (!wpa_s
->ibss_rsn
) {
2021 wpa_msg(wpa_s
, MSG_INFO
, "Failed to init IBSS RSN");
2022 wpa_supplicant_deauthenticate(
2023 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2027 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, wpa_s
->current_ssid
->psk
);
2029 #endif /* CONFIG_IBSS_RSN */
2031 wpas_wps_notify_assoc(wpa_s
, bssid
);
2035 static int disconnect_reason_recoverable(u16 reason_code
)
2037 return reason_code
== WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
||
2038 reason_code
== WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
||
2039 reason_code
== WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
;
2043 static void wpa_supplicant_event_disassoc(struct wpa_supplicant
*wpa_s
,
2045 int locally_generated
)
2049 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2051 * At least Host AP driver and a Prism3 card seemed to be
2052 * generating streams of disconnected events when configuring
2053 * IBSS for WPA-None. Ignore them for now.
2058 bssid
= wpa_s
->bssid
;
2059 if (is_zero_ether_addr(bssid
))
2060 bssid
= wpa_s
->pending_bssid
;
2062 if (!is_zero_ether_addr(bssid
) ||
2063 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2064 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid=" MACSTR
2066 MAC2STR(bssid
), reason_code
,
2067 locally_generated
? " locally_generated=1" : "");
2072 static int could_be_psk_mismatch(struct wpa_supplicant
*wpa_s
, u16 reason_code
,
2073 int locally_generated
)
2075 if (wpa_s
->wpa_state
!= WPA_4WAY_HANDSHAKE
||
2076 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
))
2077 return 0; /* Not in 4-way handshake with PSK */
2080 * It looks like connection was lost while trying to go through PSK
2081 * 4-way handshake. Filter out known disconnection cases that are caused
2082 * by something else than PSK mismatch to avoid confusing reports.
2085 if (locally_generated
) {
2086 if (reason_code
== WLAN_REASON_IE_IN_4WAY_DIFFERS
)
2094 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant
*wpa_s
,
2096 int locally_generated
)
2100 u8 prev_pending_bssid
[ETH_ALEN
];
2101 struct wpa_bss
*fast_reconnect
= NULL
;
2102 #ifndef CONFIG_NO_SCAN_PROCESSING
2103 struct wpa_ssid
*fast_reconnect_ssid
= NULL
;
2104 #endif /* CONFIG_NO_SCAN_PROCESSING */
2105 struct wpa_ssid
*last_ssid
;
2107 authenticating
= wpa_s
->wpa_state
== WPA_AUTHENTICATING
;
2108 os_memcpy(prev_pending_bssid
, wpa_s
->pending_bssid
, ETH_ALEN
);
2110 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2112 * At least Host AP driver and a Prism3 card seemed to be
2113 * generating streams of disconnected events when configuring
2114 * IBSS for WPA-None. Ignore them for now.
2116 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - ignore in "
2117 "IBSS/WPA-None mode");
2121 if (could_be_psk_mismatch(wpa_s
, reason_code
, locally_generated
)) {
2122 wpa_msg(wpa_s
, MSG_INFO
, "WPA: 4-Way Handshake failed - "
2123 "pre-shared key may be incorrect");
2124 if (wpas_p2p_4way_hs_failed(wpa_s
) > 0)
2125 return; /* P2P group removed */
2126 wpas_auth_failed(wpa_s
);
2128 if (!wpa_s
->disconnected
&&
2129 (!wpa_s
->auto_reconnect_disabled
||
2130 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)) {
2131 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect enabled: try to "
2132 "reconnect (wps=%d wpa_state=%d)",
2133 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
,
2135 if (wpa_s
->wpa_state
== WPA_COMPLETED
&&
2136 wpa_s
->current_ssid
&&
2137 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
2138 !locally_generated
&&
2139 disconnect_reason_recoverable(reason_code
)) {
2141 * It looks like the AP has dropped association with
2142 * us, but could allow us to get back in. Try to
2143 * reconnect to the same BSS without full scan to save
2144 * time for some common cases.
2146 fast_reconnect
= wpa_s
->current_bss
;
2147 #ifndef CONFIG_NO_SCAN_PROCESSING
2148 fast_reconnect_ssid
= wpa_s
->current_ssid
;
2149 #endif /* CONFIG_NO_SCAN_PROCESSING */
2150 } else if (wpa_s
->wpa_state
>= WPA_ASSOCIATING
)
2151 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2153 wpa_dbg(wpa_s
, MSG_DEBUG
, "Do not request new "
2156 wpa_dbg(wpa_s
, MSG_DEBUG
, "Auto connect disabled: do not "
2157 "try to re-connect");
2158 wpa_s
->reassociate
= 0;
2159 wpa_s
->disconnected
= 1;
2160 wpa_supplicant_cancel_sched_scan(wpa_s
);
2162 bssid
= wpa_s
->bssid
;
2163 if (is_zero_ether_addr(bssid
))
2164 bssid
= wpa_s
->pending_bssid
;
2165 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2166 wpas_connection_failed(wpa_s
, bssid
);
2167 wpa_sm_notify_disassoc(wpa_s
->wpa
);
2168 if (locally_generated
)
2169 wpa_s
->disconnect_reason
= -reason_code
;
2171 wpa_s
->disconnect_reason
= reason_code
;
2172 wpas_notify_disconnect_reason(wpa_s
);
2173 if (wpa_supplicant_dynamic_keys(wpa_s
)) {
2174 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disconnect event - remove keys");
2175 wpa_clear_keys(wpa_s
, wpa_s
->bssid
);
2177 last_ssid
= wpa_s
->current_ssid
;
2178 wpa_supplicant_mark_disassoc(wpa_s
);
2180 if (authenticating
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)) {
2181 sme_disassoc_while_authenticating(wpa_s
, prev_pending_bssid
);
2182 wpa_s
->current_ssid
= last_ssid
;
2185 if (fast_reconnect
) {
2186 #ifndef CONFIG_NO_SCAN_PROCESSING
2187 wpa_dbg(wpa_s
, MSG_DEBUG
, "Try to reconnect to the same BSS");
2188 if (wpa_supplicant_connect(wpa_s
, fast_reconnect
,
2189 fast_reconnect_ssid
) < 0) {
2190 /* Recover through full scan */
2191 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
2193 #endif /* CONFIG_NO_SCAN_PROCESSING */
2198 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2199 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx
, void *sock_ctx
)
2201 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2203 if (!wpa_s
->pending_mic_error_report
)
2206 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Sending pending MIC error report");
2207 wpa_sm_key_request(wpa_s
->wpa
, 1, wpa_s
->pending_mic_error_pairwise
);
2208 wpa_s
->pending_mic_error_report
= 0;
2210 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2214 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant
*wpa_s
,
2215 union wpa_event_data
*data
)
2218 struct os_reltime t
;
2220 wpa_msg(wpa_s
, MSG_WARNING
, "Michael MIC failure detected");
2221 pairwise
= (data
&& data
->michael_mic_failure
.unicast
);
2223 if ((wpa_s
->last_michael_mic_error
.sec
&&
2224 !os_reltime_expired(&t
, &wpa_s
->last_michael_mic_error
, 60)) ||
2225 wpa_s
->pending_mic_error_report
) {
2226 if (wpa_s
->pending_mic_error_report
) {
2228 * Send the pending MIC error report immediately since
2229 * we are going to start countermeasures and AP better
2232 wpa_sm_key_request(wpa_s
->wpa
, 1,
2233 wpa_s
->pending_mic_error_pairwise
);
2236 /* Send the new MIC error report immediately since we are going
2237 * to start countermeasures and AP better do the same.
2239 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2241 /* initialize countermeasures */
2242 wpa_s
->countermeasures
= 1;
2244 wpa_blacklist_add(wpa_s
, wpa_s
->bssid
);
2246 wpa_msg(wpa_s
, MSG_WARNING
, "TKIP countermeasures started");
2249 * Need to wait for completion of request frame. We do not get
2250 * any callback for the message completion, so just wait a
2251 * short while and hope for the best. */
2254 wpa_drv_set_countermeasures(wpa_s
, 1);
2255 wpa_supplicant_deauthenticate(wpa_s
,
2256 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2257 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
,
2259 eloop_register_timeout(60, 0,
2260 wpa_supplicant_stop_countermeasures
,
2262 /* TODO: mark the AP rejected for 60 second. STA is
2263 * allowed to associate with another AP.. */
2265 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2266 if (wpa_s
->mic_errors_seen
) {
2268 * Reduce the effectiveness of Michael MIC error
2269 * reports as a means for attacking against TKIP if
2270 * more than one MIC failure is noticed with the same
2271 * PTK. We delay the transmission of the reports by a
2272 * random time between 0 and 60 seconds in order to
2273 * force the attacker wait 60 seconds before getting
2274 * the information on whether a frame resulted in a MIC
2280 if (os_get_random(rval
, sizeof(rval
)) < 0)
2281 sec
= os_random() % 60;
2283 sec
= WPA_GET_BE32(rval
) % 60;
2284 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Delay MIC error "
2285 "report %d seconds", sec
);
2286 wpa_s
->pending_mic_error_report
= 1;
2287 wpa_s
->pending_mic_error_pairwise
= pairwise
;
2288 eloop_cancel_timeout(
2289 wpa_supplicant_delayed_mic_error_report
,
2291 eloop_register_timeout(
2292 sec
, os_random() % 1000000,
2293 wpa_supplicant_delayed_mic_error_report
,
2296 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2298 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2299 wpa_sm_key_request(wpa_s
->wpa
, 1, pairwise
);
2300 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2302 wpa_s
->last_michael_mic_error
= t
;
2303 wpa_s
->mic_errors_seen
++;
2307 #ifdef CONFIG_TERMINATE_ONLASTIF
2308 static int any_interfaces(struct wpa_supplicant
*head
)
2310 struct wpa_supplicant
*wpa_s
;
2312 for (wpa_s
= head
; wpa_s
!= NULL
; wpa_s
= wpa_s
->next
)
2313 if (!wpa_s
->interface_removed
)
2317 #endif /* CONFIG_TERMINATE_ONLASTIF */
2321 wpa_supplicant_event_interface_status(struct wpa_supplicant
*wpa_s
,
2322 union wpa_event_data
*data
)
2324 if (os_strcmp(wpa_s
->ifname
, data
->interface_status
.ifname
) != 0)
2327 switch (data
->interface_status
.ievent
) {
2328 case EVENT_INTERFACE_ADDED
:
2329 if (!wpa_s
->interface_removed
)
2331 wpa_s
->interface_removed
= 0;
2332 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was added");
2333 if (wpa_supplicant_driver_init(wpa_s
) < 0) {
2334 wpa_msg(wpa_s
, MSG_INFO
, "Failed to initialize the "
2335 "driver after interface was added");
2338 case EVENT_INTERFACE_REMOVED
:
2339 wpa_dbg(wpa_s
, MSG_DEBUG
, "Configured interface was removed");
2340 wpa_s
->interface_removed
= 1;
2341 wpa_supplicant_mark_disassoc(wpa_s
);
2342 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
2343 l2_packet_deinit(wpa_s
->l2
);
2345 #ifdef CONFIG_IBSS_RSN
2346 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
2347 wpa_s
->ibss_rsn
= NULL
;
2348 #endif /* CONFIG_IBSS_RSN */
2349 #ifdef CONFIG_TERMINATE_ONLASTIF
2350 /* check if last interface */
2351 if (!any_interfaces(wpa_s
->global
->ifaces
))
2353 #endif /* CONFIG_TERMINATE_ONLASTIF */
2359 #ifdef CONFIG_PEERKEY
2361 wpa_supplicant_event_stkstart(struct wpa_supplicant
*wpa_s
,
2362 union wpa_event_data
*data
)
2366 wpa_sm_stkstart(wpa_s
->wpa
, data
->stkstart
.peer
);
2368 #endif /* CONFIG_PEERKEY */
2372 static void wpa_supplicant_event_tdls(struct wpa_supplicant
*wpa_s
,
2373 union wpa_event_data
*data
)
2377 switch (data
->tdls
.oper
) {
2378 case TDLS_REQUEST_SETUP
:
2379 wpa_tdls_remove(wpa_s
->wpa
, data
->tdls
.peer
);
2380 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2381 wpa_tdls_start(wpa_s
->wpa
, data
->tdls
.peer
);
2383 wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, data
->tdls
.peer
);
2385 case TDLS_REQUEST_TEARDOWN
:
2386 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
2387 wpa_tdls_teardown_link(wpa_s
->wpa
, data
->tdls
.peer
,
2388 data
->tdls
.reason_code
);
2390 wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
,
2395 #endif /* CONFIG_TDLS */
2399 static void wpa_supplicant_event_wnm(struct wpa_supplicant
*wpa_s
,
2400 union wpa_event_data
*data
)
2404 switch (data
->wnm
.oper
) {
2405 case WNM_OPER_SLEEP
:
2406 wpa_printf(MSG_DEBUG
, "Start sending WNM-Sleep Request "
2407 "(action=%d, intval=%d)",
2408 data
->wnm
.sleep_action
, data
->wnm
.sleep_intval
);
2409 ieee802_11_send_wnmsleep_req(wpa_s
, data
->wnm
.sleep_action
,
2410 data
->wnm
.sleep_intval
, NULL
);
2414 #endif /* CONFIG_WNM */
2417 #ifdef CONFIG_IEEE80211R
2419 wpa_supplicant_event_ft_response(struct wpa_supplicant
*wpa_s
,
2420 union wpa_event_data
*data
)
2425 if (wpa_ft_process_response(wpa_s
->wpa
, data
->ft_ies
.ies
,
2426 data
->ft_ies
.ies_len
,
2427 data
->ft_ies
.ft_action
,
2428 data
->ft_ies
.target_ap
,
2429 data
->ft_ies
.ric_ies
,
2430 data
->ft_ies
.ric_ies_len
) < 0) {
2431 /* TODO: prevent MLME/driver from trying to associate? */
2434 #endif /* CONFIG_IEEE80211R */
2437 #ifdef CONFIG_IBSS_RSN
2438 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant
*wpa_s
,
2439 union wpa_event_data
*data
)
2441 struct wpa_ssid
*ssid
;
2442 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
)
2446 ssid
= wpa_s
->current_ssid
;
2449 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2452 ibss_rsn_start(wpa_s
->ibss_rsn
, data
->ibss_rsn_start
.peer
);
2456 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant
*wpa_s
,
2457 union wpa_event_data
*data
)
2459 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2464 /* check if the ssid is correctly configured as IBSS/RSN */
2465 if (ssid
->mode
!= WPAS_MODE_IBSS
|| !wpa_key_mgmt_wpa(ssid
->key_mgmt
))
2468 ibss_rsn_handle_auth(wpa_s
->ibss_rsn
, data
->rx_mgmt
.frame
,
2469 data
->rx_mgmt
.frame_len
);
2471 #endif /* CONFIG_IBSS_RSN */
2474 #ifdef CONFIG_IEEE80211R
2475 static void ft_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*data
,
2478 const u8
*sta_addr
, *target_ap_addr
;
2481 wpa_hexdump(MSG_MSGDUMP
, "FT: RX Action", data
, len
);
2482 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
))
2483 return; /* only SME case supported for now */
2484 if (len
< 1 + 2 * ETH_ALEN
+ 2)
2487 return; /* Only FT Action Response is supported for now */
2488 sta_addr
= data
+ 1;
2489 target_ap_addr
= data
+ 1 + ETH_ALEN
;
2490 status
= WPA_GET_LE16(data
+ 1 + 2 * ETH_ALEN
);
2491 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Received FT Action Response: STA "
2492 MACSTR
" TargetAP " MACSTR
" status %u",
2493 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
2495 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
2496 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: Foreign STA Address " MACSTR
2497 " in FT Action Response", MAC2STR(sta_addr
));
2502 wpa_dbg(wpa_s
, MSG_DEBUG
, "FT: FT Action Response indicates "
2503 "failure (status code %d)", status
);
2504 /* TODO: report error to FT code(?) */
2508 if (wpa_ft_process_response(wpa_s
->wpa
, data
+ 1 + 2 * ETH_ALEN
+ 2,
2509 len
- (1 + 2 * ETH_ALEN
+ 2), 1,
2510 target_ap_addr
, NULL
, 0) < 0)
2515 struct wpa_bss
*bss
;
2516 bss
= wpa_bss_get_bssid(wpa_s
, target_ap_addr
);
2518 wpa_s
->sme
.freq
= bss
->freq
;
2519 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_FT
;
2520 sme_associate(wpa_s
, WPAS_MODE_INFRA
, target_ap_addr
,
2523 #endif /* CONFIG_SME */
2525 #endif /* CONFIG_IEEE80211R */
2528 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant
*wpa_s
,
2529 struct unprot_deauth
*e
)
2531 #ifdef CONFIG_IEEE80211W
2532 wpa_printf(MSG_DEBUG
, "Unprotected Deauthentication frame "
2533 "dropped: " MACSTR
" -> " MACSTR
2534 " (reason code %u)",
2535 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2536 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2537 #endif /* CONFIG_IEEE80211W */
2541 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant
*wpa_s
,
2542 struct unprot_disassoc
*e
)
2544 #ifdef CONFIG_IEEE80211W
2545 wpa_printf(MSG_DEBUG
, "Unprotected Disassociation frame "
2546 "dropped: " MACSTR
" -> " MACSTR
2547 " (reason code %u)",
2548 MAC2STR(e
->sa
), MAC2STR(e
->da
), e
->reason_code
);
2549 sme_event_unprot_disconnect(wpa_s
, e
->sa
, e
->da
, e
->reason_code
);
2550 #endif /* CONFIG_IEEE80211W */
2554 static void wpas_event_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
2555 u16 reason_code
, int locally_generated
,
2556 const u8
*ie
, size_t ie_len
, int deauth
)
2559 if (wpa_s
->ap_iface
&& addr
) {
2560 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], addr
);
2564 if (wpa_s
->ap_iface
) {
2565 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore deauth event in AP mode");
2568 #endif /* CONFIG_AP */
2570 wpa_supplicant_event_disassoc(wpa_s
, reason_code
, locally_generated
);
2572 if (((reason_code
== WLAN_REASON_IEEE_802_1X_AUTH_FAILED
||
2573 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2574 (wpa_s
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) &&
2575 eapol_sm_failed(wpa_s
->eapol
))) &&
2576 !wpa_s
->eap_expected_failure
))
2577 wpas_auth_failed(wpa_s
);
2580 if (deauth
&& reason_code
> 0) {
2581 if (wpas_p2p_deauth_notif(wpa_s
, addr
, reason_code
, ie
, ie_len
,
2582 locally_generated
) > 0) {
2584 * The interface was removed, so cannot continue
2585 * processing any additional operations after this.
2590 #endif /* CONFIG_P2P */
2592 wpa_supplicant_event_disassoc_finish(wpa_s
, reason_code
,
2597 static void wpas_event_disassoc(struct wpa_supplicant
*wpa_s
,
2598 struct disassoc_info
*info
)
2600 u16 reason_code
= 0;
2601 int locally_generated
= 0;
2602 const u8
*addr
= NULL
;
2603 const u8
*ie
= NULL
;
2606 wpa_dbg(wpa_s
, MSG_DEBUG
, "Disassociation notification");
2611 ie_len
= info
->ie_len
;
2612 reason_code
= info
->reason_code
;
2613 locally_generated
= info
->locally_generated
;
2614 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s", reason_code
,
2615 locally_generated
? " (locally generated)" : "");
2617 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
2619 wpa_hexdump(MSG_DEBUG
, "Disassociation frame IE(s)",
2624 if (wpa_s
->ap_iface
&& info
&& info
->addr
) {
2625 hostapd_notif_disassoc(wpa_s
->ap_iface
->bss
[0], info
->addr
);
2629 if (wpa_s
->ap_iface
) {
2630 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore disassoc event in AP mode");
2633 #endif /* CONFIG_AP */
2637 wpas_p2p_disassoc_notif(
2638 wpa_s
, info
->addr
, reason_code
, info
->ie
, info
->ie_len
,
2641 #endif /* CONFIG_P2P */
2643 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2644 sme_event_disassoc(wpa_s
, info
);
2646 wpas_event_disconnect(wpa_s
, addr
, reason_code
, locally_generated
,
2651 static void wpas_event_deauth(struct wpa_supplicant
*wpa_s
,
2652 struct deauth_info
*info
)
2654 u16 reason_code
= 0;
2655 int locally_generated
= 0;
2656 const u8
*addr
= NULL
;
2657 const u8
*ie
= NULL
;
2660 wpa_dbg(wpa_s
, MSG_DEBUG
, "Deauthentication notification");
2665 ie_len
= info
->ie_len
;
2666 reason_code
= info
->reason_code
;
2667 locally_generated
= info
->locally_generated
;
2668 wpa_dbg(wpa_s
, MSG_DEBUG
, " * reason %u%s",
2670 locally_generated
? " (locally generated)" : "");
2672 wpa_dbg(wpa_s
, MSG_DEBUG
, " * address " MACSTR
,
2675 wpa_hexdump(MSG_DEBUG
, "Deauthentication frame IE(s)",
2679 wpa_reset_ft_completed(wpa_s
->wpa
);
2681 wpas_event_disconnect(wpa_s
, addr
, reason_code
,
2682 locally_generated
, ie
, ie_len
, 1);
2686 static void wpa_supplicant_update_channel_list(struct wpa_supplicant
*wpa_s
)
2688 struct wpa_supplicant
*ifs
;
2690 if (wpa_s
->drv_priv
== NULL
)
2691 return; /* Ignore event during drv initialization */
2693 free_hw_features(wpa_s
);
2694 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(
2695 wpa_s
, &wpa_s
->hw
.num_modes
, &wpa_s
->hw
.flags
);
2698 wpas_p2p_update_channel_list(wpa_s
);
2699 #endif /* CONFIG_P2P */
2702 * Check other interfaces to see if they share the same radio. If
2703 * so, they get updated with this same hw mode info.
2705 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
2708 wpa_printf(MSG_DEBUG
, "%s: Updating hw mode",
2710 free_hw_features(ifs
);
2711 ifs
->hw
.modes
= wpa_drv_get_hw_feature_data(
2712 ifs
, &ifs
->hw
.num_modes
, &ifs
->hw
.flags
);
2718 static void wpas_event_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
2719 const struct ieee80211_mgmt
*mgmt
,
2720 size_t len
, int freq
)
2726 if (len
< IEEE80211_HDRLEN
+ 2)
2729 payload
= &mgmt
->u
.action
.category
;
2730 category
= *payload
++;
2731 plen
= (((const u8
*) mgmt
) + len
) - payload
;
2733 wpa_dbg(wpa_s
, MSG_DEBUG
, "Received Action frame: SA=" MACSTR
2734 " Category=%u DataLen=%d freq=%d MHz",
2735 MAC2STR(mgmt
->sa
), category
, (int) plen
, freq
);
2737 #ifdef CONFIG_IEEE80211R
2738 if (category
== WLAN_ACTION_FT
) {
2739 ft_rx_action(wpa_s
, payload
, plen
);
2742 #endif /* CONFIG_IEEE80211R */
2744 #ifdef CONFIG_IEEE80211W
2746 if (category
== WLAN_ACTION_SA_QUERY
) {
2747 sme_sa_query_rx(wpa_s
, mgmt
->sa
, payload
, plen
);
2750 #endif /* CONFIG_SME */
2751 #endif /* CONFIG_IEEE80211W */
2754 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
2755 ieee802_11_rx_wnm_action(wpa_s
, mgmt
, len
);
2758 #endif /* CONFIG_WNM */
2761 if ((mgmt
->u
.action
.category
== WLAN_ACTION_PUBLIC
||
2762 mgmt
->u
.action
.category
== WLAN_ACTION_PROTECTED_DUAL
) &&
2763 gas_query_rx(wpa_s
->gas
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
2764 mgmt
->u
.action
.category
,
2765 payload
, plen
, freq
) == 0)
2767 #endif /* CONFIG_GAS */
2770 if (category
== WLAN_ACTION_PUBLIC
&& plen
>= 4 &&
2771 payload
[0] == WLAN_TDLS_DISCOVERY_RESPONSE
) {
2772 wpa_dbg(wpa_s
, MSG_DEBUG
,
2773 "TDLS: Received Discovery Response from " MACSTR
,
2777 #endif /* CONFIG_TDLS */
2779 #ifdef CONFIG_INTERWORKING
2780 if (category
== WLAN_ACTION_QOS
&& plen
>= 1 &&
2781 payload
[0] == QOS_QOS_MAP_CONFIG
) {
2782 const u8
*pos
= payload
+ 1;
2783 size_t qlen
= plen
- 1;
2784 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interworking: Received QoS Map Configure frame from "
2785 MACSTR
, MAC2STR(mgmt
->sa
));
2786 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) == 0 &&
2787 qlen
> 2 && pos
[0] == WLAN_EID_QOS_MAP_SET
&&
2788 pos
[1] <= qlen
- 2 && pos
[1] >= 16)
2789 wpas_qos_map_set(wpa_s
, pos
+ 2, pos
[1]);
2792 #endif /* CONFIG_INTERWORKING */
2795 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
2796 category
, payload
, plen
, freq
);
2797 #endif /* CONFIG_P2P */
2801 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant
*wpa_s
,
2802 union wpa_event_data
*event
)
2805 struct wpa_supplicant
*ifs
;
2806 #endif /* CONFIG_P2P */
2807 struct wpa_freq_range_list
*list
;
2810 list
= &event
->freq_range
;
2813 str
= freq_range_list_str(list
);
2814 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AVOID_FREQ
"ranges=%s",
2818 if (freq_range_list_parse(&wpa_s
->global
->p2p_go_avoid_freq
, str
)) {
2819 wpa_dbg(wpa_s
, MSG_ERROR
, "%s: Failed to parse freq range",
2822 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Update channel list based on frequency avoid event");
2823 wpas_p2p_update_channel_list(wpa_s
);
2826 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
2828 if (!ifs
->current_ssid
||
2829 !ifs
->current_ssid
->p2p_group
||
2830 (ifs
->current_ssid
->mode
!= WPAS_MODE_P2P_GO
&&
2831 ifs
->current_ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
))
2834 freq
= ifs
->current_ssid
->frequency
;
2835 if (!freq_range_list_includes(list
, freq
)) {
2836 wpa_dbg(ifs
, MSG_DEBUG
, "P2P GO operating frequency %d MHz in safe range",
2841 wpa_dbg(ifs
, MSG_DEBUG
, "P2P GO operating in unsafe frequency %d MHz",
2843 /* TODO: Consider using CSA or removing the group within
2845 wpa_msg(ifs
, MSG_INFO
, P2P_EVENT_REMOVE_AND_REFORM_GROUP
);
2847 #endif /* CONFIG_P2P */
2853 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
2854 union wpa_event_data
*data
)
2856 struct wpa_supplicant
*wpa_s
= ctx
;
2858 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
&&
2859 event
!= EVENT_INTERFACE_ENABLED
&&
2860 event
!= EVENT_INTERFACE_STATUS
&&
2861 event
!= EVENT_SCHED_SCAN_STOPPED
) {
2862 wpa_dbg(wpa_s
, MSG_DEBUG
,
2863 "Ignore event %s (%d) while interface is disabled",
2864 event_to_string(event
), event
);
2868 #ifndef CONFIG_NO_STDOUT_DEBUG
2870 int level
= MSG_DEBUG
;
2872 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame_len
>= 24) {
2873 const struct ieee80211_hdr
*hdr
;
2875 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
2876 fc
= le_to_host16(hdr
->frame_control
);
2877 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
2878 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
2879 level
= MSG_EXCESSIVE
;
2882 wpa_dbg(wpa_s
, level
, "Event %s (%d) received",
2883 event_to_string(event
), event
);
2885 #endif /* CONFIG_NO_STDOUT_DEBUG */
2889 sme_event_auth(wpa_s
, data
);
2892 wpa_supplicant_event_assoc(wpa_s
, data
);
2894 case EVENT_DISASSOC
:
2895 wpas_event_disassoc(wpa_s
,
2896 data
? &data
->disassoc_info
: NULL
);
2899 wpas_event_deauth(wpa_s
,
2900 data
? &data
->deauth_info
: NULL
);
2902 case EVENT_MICHAEL_MIC_FAILURE
:
2903 wpa_supplicant_event_michael_mic_failure(wpa_s
, data
);
2905 #ifndef CONFIG_NO_SCAN_PROCESSING
2906 case EVENT_SCAN_STARTED
:
2907 os_get_reltime(&wpa_s
->scan_start_time
);
2908 if (wpa_s
->own_scan_requested
) {
2909 struct os_reltime diff
;
2911 os_reltime_sub(&wpa_s
->scan_start_time
,
2912 &wpa_s
->scan_trigger_time
, &diff
);
2913 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own scan request started a scan in %ld.%06ld seconds",
2914 diff
.sec
, diff
.usec
);
2915 wpa_s
->own_scan_requested
= 0;
2916 wpa_s
->own_scan_running
= 1;
2917 if (wpa_s
->last_scan_req
== MANUAL_SCAN_REQ
&&
2918 wpa_s
->manual_scan_use_id
) {
2919 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
"id=%u",
2920 wpa_s
->manual_scan_id
);
2922 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
2925 wpa_dbg(wpa_s
, MSG_DEBUG
, "External program started a scan");
2926 wpa_s
->external_scan_running
= 1;
2927 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_SCAN_STARTED
);
2930 case EVENT_SCAN_RESULTS
:
2931 if (os_reltime_initialized(&wpa_s
->scan_start_time
)) {
2932 struct os_reltime now
, diff
;
2933 os_get_reltime(&now
);
2934 os_reltime_sub(&now
, &wpa_s
->scan_start_time
, &diff
);
2935 wpa_s
->scan_start_time
.sec
= 0;
2936 wpa_s
->scan_start_time
.usec
= 0;
2937 wpa_dbg(wpa_s
, MSG_DEBUG
, "Scan completed in %ld.%06ld seconds",
2938 diff
.sec
, diff
.usec
);
2940 wpa_supplicant_event_scan_results(wpa_s
, data
);
2941 wpa_s
->own_scan_running
= 0;
2942 wpa_s
->external_scan_running
= 0;
2943 radio_work_check_next(wpa_s
);
2945 #endif /* CONFIG_NO_SCAN_PROCESSING */
2946 case EVENT_ASSOCINFO
:
2947 wpa_supplicant_event_associnfo(wpa_s
, data
);
2949 case EVENT_INTERFACE_STATUS
:
2950 wpa_supplicant_event_interface_status(wpa_s
, data
);
2952 case EVENT_PMKID_CANDIDATE
:
2953 wpa_supplicant_event_pmkid_candidate(wpa_s
, data
);
2955 #ifdef CONFIG_PEERKEY
2956 case EVENT_STKSTART
:
2957 wpa_supplicant_event_stkstart(wpa_s
, data
);
2959 #endif /* CONFIG_PEERKEY */
2962 wpa_supplicant_event_tdls(wpa_s
, data
);
2964 #endif /* CONFIG_TDLS */
2967 wpa_supplicant_event_wnm(wpa_s
, data
);
2969 #endif /* CONFIG_WNM */
2970 #ifdef CONFIG_IEEE80211R
2971 case EVENT_FT_RESPONSE
:
2972 wpa_supplicant_event_ft_response(wpa_s
, data
);
2974 #endif /* CONFIG_IEEE80211R */
2975 #ifdef CONFIG_IBSS_RSN
2976 case EVENT_IBSS_RSN_START
:
2977 wpa_supplicant_event_ibss_rsn_start(wpa_s
, data
);
2979 #endif /* CONFIG_IBSS_RSN */
2980 case EVENT_ASSOC_REJECT
:
2981 if (data
->assoc_reject
.bssid
)
2982 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2983 "bssid=" MACSTR
" status_code=%u",
2984 MAC2STR(data
->assoc_reject
.bssid
),
2985 data
->assoc_reject
.status_code
);
2987 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_ASSOC_REJECT
2989 data
->assoc_reject
.status_code
);
2990 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
2991 sme_event_assoc_reject(wpa_s
, data
);
2993 const u8
*bssid
= data
->assoc_reject
.bssid
;
2994 if (bssid
== NULL
|| is_zero_ether_addr(bssid
))
2995 bssid
= wpa_s
->pending_bssid
;
2996 wpas_connection_failed(wpa_s
, bssid
);
2997 wpa_supplicant_mark_disassoc(wpa_s
);
3000 case EVENT_AUTH_TIMED_OUT
:
3001 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3002 sme_event_auth_timed_out(wpa_s
, data
);
3004 case EVENT_ASSOC_TIMED_OUT
:
3005 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
)
3006 sme_event_assoc_timed_out(wpa_s
, data
);
3008 case EVENT_TX_STATUS
:
3009 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS dst=" MACSTR
3010 " type=%d stype=%d",
3011 MAC2STR(data
->tx_status
.dst
),
3012 data
->tx_status
.type
, data
->tx_status
.stype
);
3014 if (wpa_s
->ap_iface
== NULL
) {
3015 #ifdef CONFIG_OFFCHANNEL
3016 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3017 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
)
3018 offchannel_send_action_tx_status(
3019 wpa_s
, data
->tx_status
.dst
,
3020 data
->tx_status
.data
,
3021 data
->tx_status
.data_len
,
3022 data
->tx_status
.ack
?
3023 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3024 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3025 #endif /* CONFIG_OFFCHANNEL */
3028 #endif /* CONFIG_AP */
3029 #ifdef CONFIG_OFFCHANNEL
3030 wpa_dbg(wpa_s
, MSG_DEBUG
, "EVENT_TX_STATUS pending_dst="
3031 MACSTR
, MAC2STR(wpa_s
->parent
->pending_action_dst
));
3033 * Catch TX status events for Action frames we sent via group
3034 * interface in GO mode.
3036 if (data
->tx_status
.type
== WLAN_FC_TYPE_MGMT
&&
3037 data
->tx_status
.stype
== WLAN_FC_STYPE_ACTION
&&
3038 os_memcmp(wpa_s
->parent
->pending_action_dst
,
3039 data
->tx_status
.dst
, ETH_ALEN
) == 0) {
3040 offchannel_send_action_tx_status(
3041 wpa_s
->parent
, data
->tx_status
.dst
,
3042 data
->tx_status
.data
,
3043 data
->tx_status
.data_len
,
3044 data
->tx_status
.ack
?
3045 OFFCHANNEL_SEND_ACTION_SUCCESS
:
3046 OFFCHANNEL_SEND_ACTION_NO_ACK
);
3049 #endif /* CONFIG_OFFCHANNEL */
3051 switch (data
->tx_status
.type
) {
3052 case WLAN_FC_TYPE_MGMT
:
3053 ap_mgmt_tx_cb(wpa_s
, data
->tx_status
.data
,
3054 data
->tx_status
.data_len
,
3055 data
->tx_status
.stype
,
3056 data
->tx_status
.ack
);
3058 case WLAN_FC_TYPE_DATA
:
3059 ap_tx_status(wpa_s
, data
->tx_status
.dst
,
3060 data
->tx_status
.data
,
3061 data
->tx_status
.data_len
,
3062 data
->tx_status
.ack
);
3065 #endif /* CONFIG_AP */
3068 case EVENT_EAPOL_TX_STATUS
:
3069 ap_eapol_tx_status(wpa_s
, data
->eapol_tx_status
.dst
,
3070 data
->eapol_tx_status
.data
,
3071 data
->eapol_tx_status
.data_len
,
3072 data
->eapol_tx_status
.ack
);
3074 case EVENT_DRIVER_CLIENT_POLL_OK
:
3075 ap_client_poll_ok(wpa_s
, data
->client_poll
.addr
);
3077 case EVENT_RX_FROM_UNKNOWN
:
3078 if (wpa_s
->ap_iface
== NULL
)
3080 ap_rx_from_unknown_sta(wpa_s
, data
->rx_from_unknown
.addr
,
3081 data
->rx_from_unknown
.wds
);
3083 case EVENT_CH_SWITCH
:
3086 if (!wpa_s
->ap_iface
) {
3087 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: Ignore channel switch "
3088 "event in non-AP mode");
3092 wpas_ap_ch_switch(wpa_s
, data
->ch_switch
.freq
,
3093 data
->ch_switch
.ht_enabled
,
3094 data
->ch_switch
.ch_offset
,
3095 data
->ch_switch
.ch_width
,
3096 data
->ch_switch
.cf1
,
3097 data
->ch_switch
.cf2
);
3099 #endif /* CONFIG_AP */
3100 case EVENT_RX_MGMT
: {
3102 const struct ieee80211_mgmt
*mgmt
;
3104 mgmt
= (const struct ieee80211_mgmt
*)
3105 data
->rx_mgmt
.frame
;
3106 fc
= le_to_host16(mgmt
->frame_control
);
3107 stype
= WLAN_FC_GET_STYPE(fc
);
3110 if (wpa_s
->ap_iface
== NULL
) {
3111 #endif /* CONFIG_AP */
3113 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3114 data
->rx_mgmt
.frame_len
> 24) {
3115 const u8
*src
= mgmt
->sa
;
3116 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
3117 size_t ie_len
= data
->rx_mgmt
.frame_len
-
3118 (mgmt
->u
.probe_req
.variable
-
3119 data
->rx_mgmt
.frame
);
3120 wpas_p2p_probe_req_rx(
3121 wpa_s
, src
, mgmt
->da
,
3122 mgmt
->bssid
, ie
, ie_len
,
3123 data
->rx_mgmt
.ssi_signal
);
3126 #endif /* CONFIG_P2P */
3127 #ifdef CONFIG_IBSS_RSN
3128 if (stype
== WLAN_FC_STYPE_AUTH
&&
3129 data
->rx_mgmt
.frame_len
>= 30) {
3130 wpa_supplicant_event_ibss_auth(wpa_s
, data
);
3133 #endif /* CONFIG_IBSS_RSN */
3135 if (stype
== WLAN_FC_STYPE_ACTION
) {
3136 wpas_event_rx_mgmt_action(
3137 wpa_s
, mgmt
, data
->rx_mgmt
.frame_len
,
3138 data
->rx_mgmt
.freq
);
3142 wpa_dbg(wpa_s
, MSG_DEBUG
, "AP: ignore received "
3143 "management frame in non-AP mode");
3148 if (stype
== WLAN_FC_STYPE_PROBE_REQ
&&
3149 data
->rx_mgmt
.frame_len
> 24) {
3150 const u8
*ie
= mgmt
->u
.probe_req
.variable
;
3151 size_t ie_len
= data
->rx_mgmt
.frame_len
-
3152 (mgmt
->u
.probe_req
.variable
-
3153 data
->rx_mgmt
.frame
);
3155 wpas_notify_preq(wpa_s
, mgmt
->sa
, mgmt
->da
,
3156 mgmt
->bssid
, ie
, ie_len
,
3157 data
->rx_mgmt
.ssi_signal
);
3160 ap_mgmt_rx(wpa_s
, &data
->rx_mgmt
);
3161 #endif /* CONFIG_AP */
3164 case EVENT_RX_PROBE_REQ
:
3165 if (data
->rx_probe_req
.sa
== NULL
||
3166 data
->rx_probe_req
.ie
== NULL
)
3169 if (wpa_s
->ap_iface
) {
3170 hostapd_probe_req_rx(wpa_s
->ap_iface
->bss
[0],
3171 data
->rx_probe_req
.sa
,
3172 data
->rx_probe_req
.da
,
3173 data
->rx_probe_req
.bssid
,
3174 data
->rx_probe_req
.ie
,
3175 data
->rx_probe_req
.ie_len
,
3176 data
->rx_probe_req
.ssi_signal
);
3179 #endif /* CONFIG_AP */
3181 wpas_p2p_probe_req_rx(wpa_s
, data
->rx_probe_req
.sa
,
3182 data
->rx_probe_req
.da
,
3183 data
->rx_probe_req
.bssid
,
3184 data
->rx_probe_req
.ie
,
3185 data
->rx_probe_req
.ie_len
,
3186 data
->rx_probe_req
.ssi_signal
);
3187 #endif /* CONFIG_P2P */
3189 case EVENT_REMAIN_ON_CHANNEL
:
3190 #ifdef CONFIG_OFFCHANNEL
3191 offchannel_remain_on_channel_cb(
3192 wpa_s
, data
->remain_on_channel
.freq
,
3193 data
->remain_on_channel
.duration
);
3194 #endif /* CONFIG_OFFCHANNEL */
3196 wpas_p2p_remain_on_channel_cb(
3197 wpa_s
, data
->remain_on_channel
.freq
,
3198 data
->remain_on_channel
.duration
);
3199 #endif /* CONFIG_P2P */
3201 case EVENT_CANCEL_REMAIN_ON_CHANNEL
:
3202 #ifdef CONFIG_OFFCHANNEL
3203 offchannel_cancel_remain_on_channel_cb(
3204 wpa_s
, data
->remain_on_channel
.freq
);
3205 #endif /* CONFIG_OFFCHANNEL */
3207 wpas_p2p_cancel_remain_on_channel_cb(
3208 wpa_s
, data
->remain_on_channel
.freq
);
3209 #endif /* CONFIG_P2P */
3211 case EVENT_EAPOL_RX
:
3212 wpa_supplicant_rx_eapol(wpa_s
, data
->eapol_rx
.src
,
3213 data
->eapol_rx
.data
,
3214 data
->eapol_rx
.data_len
);
3216 case EVENT_SIGNAL_CHANGE
:
3217 bgscan_notify_signal_change(
3218 wpa_s
, data
->signal_change
.above_threshold
,
3219 data
->signal_change
.current_signal
,
3220 data
->signal_change
.current_noise
,
3221 data
->signal_change
.current_txrate
);
3223 case EVENT_INTERFACE_ENABLED
:
3224 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was enabled");
3225 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3226 wpa_supplicant_update_mac_addr(wpa_s
);
3228 if (!wpa_s
->ap_iface
) {
3229 wpa_supplicant_set_state(wpa_s
,
3231 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3233 wpa_supplicant_set_state(wpa_s
,
3235 #else /* CONFIG_AP */
3236 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
3237 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3238 #endif /* CONFIG_AP */
3241 case EVENT_INTERFACE_DISABLED
:
3242 wpa_dbg(wpa_s
, MSG_DEBUG
, "Interface was disabled");
3244 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
3245 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
&&
3246 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3248 * The interface was externally disabled. Remove
3249 * it assuming an external entity will start a
3250 * new session if needed.
3252 wpas_p2p_disconnect(wpa_s
);
3255 #endif /* CONFIG_P2P */
3257 wpa_supplicant_mark_disassoc(wpa_s
);
3258 radio_remove_works(wpa_s
, NULL
, 0);
3260 wpa_supplicant_set_state(wpa_s
, WPA_INTERFACE_DISABLED
);
3262 case EVENT_CHANNEL_LIST_CHANGED
:
3263 wpa_supplicant_update_channel_list(wpa_s
);
3265 case EVENT_INTERFACE_UNAVAILABLE
:
3267 wpas_p2p_interface_unavailable(wpa_s
);
3268 #endif /* CONFIG_P2P */
3270 case EVENT_BEST_CHANNEL
:
3271 wpa_dbg(wpa_s
, MSG_DEBUG
, "Best channel event received "
3273 data
->best_chan
.freq_24
, data
->best_chan
.freq_5
,
3274 data
->best_chan
.freq_overall
);
3275 wpa_s
->best_24_freq
= data
->best_chan
.freq_24
;
3276 wpa_s
->best_5_freq
= data
->best_chan
.freq_5
;
3277 wpa_s
->best_overall_freq
= data
->best_chan
.freq_overall
;
3279 wpas_p2p_update_best_channels(wpa_s
, data
->best_chan
.freq_24
,
3280 data
->best_chan
.freq_5
,
3281 data
->best_chan
.freq_overall
);
3282 #endif /* CONFIG_P2P */
3284 case EVENT_UNPROT_DEAUTH
:
3285 wpa_supplicant_event_unprot_deauth(wpa_s
,
3286 &data
->unprot_deauth
);
3288 case EVENT_UNPROT_DISASSOC
:
3289 wpa_supplicant_event_unprot_disassoc(wpa_s
,
3290 &data
->unprot_disassoc
);
3292 case EVENT_STATION_LOW_ACK
:
3294 if (wpa_s
->ap_iface
&& data
)
3295 hostapd_event_sta_low_ack(wpa_s
->ap_iface
->bss
[0],
3296 data
->low_ack
.addr
);
3297 #endif /* CONFIG_AP */
3300 wpa_tdls_disable_link(wpa_s
->wpa
, data
->low_ack
.addr
);
3301 #endif /* CONFIG_TDLS */
3303 case EVENT_IBSS_PEER_LOST
:
3304 #ifdef CONFIG_IBSS_RSN
3305 ibss_rsn_stop(wpa_s
->ibss_rsn
, data
->ibss_peer_lost
.peer
);
3306 #endif /* CONFIG_IBSS_RSN */
3308 case EVENT_DRIVER_GTK_REKEY
:
3309 if (os_memcmp(data
->driver_gtk_rekey
.bssid
,
3310 wpa_s
->bssid
, ETH_ALEN
))
3314 wpa_sm_update_replay_ctr(wpa_s
->wpa
,
3315 data
->driver_gtk_rekey
.replay_ctr
);
3317 case EVENT_SCHED_SCAN_STOPPED
:
3319 wpa_s
->sched_scanning
= 0;
3320 wpa_supplicant_notify_scanning(wpa_s
, 0);
3322 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3326 * Start a new sched scan to continue searching for more SSIDs
3327 * either if timed out or PNO schedule scan is pending.
3329 if (wpa_s
->sched_scan_timed_out
|| wpa_s
->pno_sched_pending
) {
3331 if (wpa_supplicant_req_sched_scan(wpa_s
) < 0 &&
3332 wpa_s
->pno_sched_pending
) {
3333 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to schedule PNO");
3334 } else if (wpa_s
->pno_sched_pending
) {
3335 wpa_s
->pno_sched_pending
= 0;
3341 case EVENT_WPS_BUTTON_PUSHED
:
3343 wpas_wps_start_pbc(wpa_s
, NULL
, 0);
3344 #endif /* CONFIG_WPS */
3346 case EVENT_AVOID_FREQUENCIES
:
3347 wpa_supplicant_notify_avoid_freq(wpa_s
, data
);
3349 case EVENT_CONNECT_FAILED_REASON
:
3351 if (!wpa_s
->ap_iface
|| !data
)
3353 hostapd_event_connect_failed_reason(
3354 wpa_s
->ap_iface
->bss
[0],
3355 data
->connect_failed_reason
.addr
,
3356 data
->connect_failed_reason
.code
);
3357 #endif /* CONFIG_AP */
3360 wpa_msg(wpa_s
, MSG_INFO
, "Unknown event %d", event
);