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"
49 #ifndef CONFIG_NO_SCAN_PROCESSING
50 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
51 int new_scan, int own_request);
52 #endif /* CONFIG_NO_SCAN_PROCESSING */
55 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
56 struct wpa_ssid *ssid)
58 struct os_reltime now;
60 if (ssid == NULL || ssid->disabled_until.sec == 0)
64 if (ssid->disabled_until.sec > now.sec)
65 return ssid->disabled_until.sec - now.sec;
67 wpas_clear_temp_disabled(wpa_s, ssid, 0);
73 static struct wpa_bss * wpa_supplicant_get_new_bss(
74 struct wpa_supplicant *wpa_s, const u8 *bssid)
76 struct wpa_bss *bss = NULL;
77 struct wpa_ssid *ssid = wpa_s->current_ssid;
79 if (ssid->ssid_len > 0)
80 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
82 bss = wpa_bss_get_bssid(wpa_s, bssid);
88 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
90 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
93 wpa_supplicant_update_scan_results(wpa_s);
95 /* Get the BSS from the new scan results */
96 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
100 wpa_s->current_bss = bss;
104 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
106 struct wpa_ssid *ssid, *old_ssid;
109 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
110 wpa_supplicant_update_current_bss(wpa_s);
114 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
116 ssid = wpa_supplicant_get_ssid(wpa_s);
118 wpa_msg(wpa_s, MSG_INFO,
119 "No network configuration found for the current AP");
123 if (wpas_network_disabled(wpa_s, ssid)) {
124 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
128 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
129 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
130 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
134 res = wpas_temp_disabled(wpa_s, ssid);
136 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
137 "disabled for %d second(s)", res);
141 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
143 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
145 size_t wpa_ie_len = sizeof(wpa_ie);
146 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
147 wpa_ie, &wpa_ie_len) < 0)
148 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
150 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
153 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
154 eapol_sm_invalidate_cached_session(wpa_s->eapol);
155 old_ssid = wpa_s->current_ssid;
156 wpa_s->current_ssid = ssid;
158 wpa_supplicant_update_current_bss(wpa_s);
160 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
161 wpa_supplicant_initiate_eapol(wpa_s);
162 if (old_ssid != wpa_s->current_ssid)
163 wpas_notify_network_changed(wpa_s);
169 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
171 struct wpa_supplicant *wpa_s = eloop_ctx;
173 if (wpa_s->countermeasures) {
174 wpa_s->countermeasures = 0;
175 wpa_drv_set_countermeasures(wpa_s, 0);
176 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
177 wpa_supplicant_req_scan(wpa_s, 0, 0);
182 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
186 wnm_bss_keep_alive_deinit(wpa_s);
188 #ifdef CONFIG_IBSS_RSN
189 ibss_rsn_deinit(wpa_s->ibss_rsn);
190 wpa_s->ibss_rsn = NULL;
191 #endif /* CONFIG_IBSS_RSN */
194 wpa_supplicant_ap_deinit(wpa_s);
195 #endif /* CONFIG_AP */
197 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
200 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
201 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
202 os_memset(wpa_s->bssid, 0, ETH_ALEN);
203 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
205 wpa_s->sme.prev_bssid_set = 0;
206 #endif /* CONFIG_SME */
208 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
209 #endif /* CONFIG_P2P */
210 wpa_s->current_bss = NULL;
211 wpa_s->assoc_freq = 0;
212 #ifdef CONFIG_IEEE80211R
214 if (wpa_s->sme.ft_ies)
215 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
216 #endif /* CONFIG_SME */
217 #endif /* CONFIG_IEEE80211R */
220 wpas_notify_bssid_changed(wpa_s);
222 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
223 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
224 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
225 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
226 wpa_s->ap_ies_from_associnfo = 0;
227 wpa_s->current_ssid = NULL;
228 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
233 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
235 struct wpa_ie_data ie;
239 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
243 for (i = 0; i < ie.num_pmkid; i++) {
244 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
245 ie.pmkid + i * PMKID_LEN,
247 if (pmksa_set == 0) {
248 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
253 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
254 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
258 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
259 union wpa_event_data *data)
262 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
266 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
267 " index=%d preauth=%d",
268 MAC2STR(data->pmkid_candidate.bssid),
269 data->pmkid_candidate.index,
270 data->pmkid_candidate.preauth);
272 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
273 data->pmkid_candidate.index,
274 data->pmkid_candidate.preauth);
278 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
280 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
281 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
284 #ifdef IEEE8021X_EAPOL
285 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
286 wpa_s->current_ssid &&
287 !(wpa_s->current_ssid->eapol_flags &
288 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
289 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
290 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
291 * plaintext or static WEP keys). */
294 #endif /* IEEE8021X_EAPOL */
301 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
302 * @wpa_s: pointer to wpa_supplicant data
303 * @ssid: Configuration data for the network
304 * Returns: 0 on success, -1 on failure
306 * This function is called when starting authentication with a network that is
307 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
309 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
310 struct wpa_ssid *ssid)
312 #ifdef IEEE8021X_EAPOL
314 int aka = 0, sim = 0;
316 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
317 wpa_s->scard != NULL || wpa_s->conf->external_sim)
320 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
324 struct eap_method_type *eap = ssid->eap.eap_methods;
325 while (eap->vendor != EAP_VENDOR_IETF ||
326 eap->method != EAP_TYPE_NONE) {
327 if (eap->vendor == EAP_VENDOR_IETF) {
328 if (eap->method == EAP_TYPE_SIM)
330 else if (eap->method == EAP_TYPE_AKA ||
331 eap->method == EAP_TYPE_AKA_PRIME)
338 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
340 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
341 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
346 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
347 "use SIM, but neither EAP-SIM nor EAP-AKA are "
352 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
353 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
355 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
356 if (wpa_s->scard == NULL) {
357 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
361 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
362 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
363 #endif /* PCSC_FUNCS */
364 #endif /* IEEE8021X_EAPOL */
370 #ifndef CONFIG_NO_SCAN_PROCESSING
372 static int has_wep_key(struct wpa_ssid *ssid)
376 for (i = 0; i < NUM_WEP_KEYS; i++) {
377 if (ssid->wep_key_len[i])
385 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
386 struct wpa_ssid *ssid)
390 if (ssid->mixed_cell)
394 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
396 #endif /* CONFIG_WPS */
398 if (has_wep_key(ssid))
401 #ifdef IEEE8021X_EAPOL
402 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
403 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
404 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
406 #endif /* IEEE8021X_EAPOL */
408 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
411 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
414 if (bss->caps & IEEE80211_CAP_PRIVACY)
420 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
421 struct wpa_ssid *ssid,
424 struct wpa_ie_data ie;
426 const u8 *rsn_ie, *wpa_ie;
430 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
434 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
435 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
436 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
437 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
438 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
440 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
441 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
444 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
445 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
451 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
453 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
458 if (!(ie.proto & ssid->proto)) {
459 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
464 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
470 if (!(ie.group_cipher & ssid->group_cipher)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
476 if (!(ie.key_mgmt & ssid->key_mgmt)) {
477 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
482 #ifdef CONFIG_IEEE80211W
483 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
484 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
485 wpa_s->conf->pmf : ssid->ieee80211w) ==
486 MGMT_FRAME_PROTECTION_REQUIRED) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
491 #endif /* CONFIG_IEEE80211W */
493 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
497 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
498 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
501 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
502 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
508 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
510 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
515 if (!(ie.proto & ssid->proto)) {
516 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
521 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
527 if (!(ie.group_cipher & ssid->group_cipher)) {
528 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
533 if (!(ie.key_mgmt & ssid->key_mgmt)) {
534 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
539 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
543 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
545 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
549 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
550 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
551 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
555 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
556 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
557 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
561 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
562 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
566 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
573 static int freq_allowed(int *freqs, int freq)
580 for (i = 0; freqs[i]; i++)
581 if (freqs[i] == freq)
587 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
589 const struct hostapd_hw_modes *mode = NULL, *modes;
590 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
595 return 1; /* Cannot do matching without knowing band */
597 modes = wpa_s->hw.modes;
600 * The driver does not provide any additional information
601 * about the utilized hardware, so allow the connection attempt
607 for (i = 0; i < wpa_s->hw.num_modes; i++) {
608 for (j = 0; j < modes[i].num_channels; j++) {
609 int freq = modes[i].channels[j].freq;
610 if (freq == bss->freq) {
612 mode->mode == HOSTAPD_MODE_IEEE80211G)
613 break; /* do not allow 802.11b replace
624 for (i = 0; i < (int) sizeof(scan_ie); i++) {
625 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
629 for (j = 2; j < rate_ie[1] + 2; j++) {
630 int flagged = !!(rate_ie[j] & 0x80);
631 int r = (rate_ie[j] & 0x7f) * 5;
634 * IEEE Std 802.11n-2009 7.3.2.2:
635 * The new BSS Membership selector value is encoded
636 * like a legacy basic rate, but it is not a rate and
637 * only indicates if the BSS members are required to
638 * support the mandatory features of Clause 20 [HT PHY]
639 * in order to join the BSS.
641 if (flagged && ((rate_ie[j] & 0x7f) ==
642 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
643 if (!ht_supported(mode)) {
644 wpa_dbg(wpa_s, MSG_DEBUG,
645 " hardware does not support "
652 /* There's also a VHT selector for 802.11ac */
653 if (flagged && ((rate_ie[j] & 0x7f) ==
654 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
655 if (!vht_supported(mode)) {
656 wpa_dbg(wpa_s, MSG_DEBUG,
657 " hardware does not support "
667 /* check for legacy basic rates */
668 for (k = 0; k < mode->num_rates; k++) {
669 if (mode->rates[k] == r)
672 if (k == mode->num_rates) {
674 * IEEE Std 802.11-2007 7.3.2.2 demands that in
675 * order to join a BSS all required rates
676 * have to be supported by the hardware.
678 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
679 "not support required rate %d.%d Mbps",
691 * Test whether BSS is in an ESS.
692 * This is done differently in DMG (60 GHz) and non-DMG bands
694 static int bss_is_ess(struct wpa_bss *bss)
696 if (bss_is_dmg(bss)) {
697 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
698 IEEE80211_CAP_DMG_AP;
701 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
706 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
707 int i, struct wpa_bss *bss,
708 struct wpa_ssid *group,
711 u8 wpa_ie_len, rsn_ie_len;
713 struct wpa_blacklist *e;
715 struct wpa_ssid *ssid;
718 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
719 wpa_ie_len = ie ? ie[1] : 0;
721 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
722 rsn_ie_len = ie ? ie[1] : 0;
724 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
727 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
728 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
729 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
730 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
731 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
732 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
733 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
735 osen ? " osen=1" : "");
737 e = wpa_blacklist_get(wpa_s, bss->bssid);
740 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
742 * When only a single network is enabled, we can
743 * trigger blacklisting on the first failure. This
744 * should not be done with multiple enabled networks to
745 * avoid getting forced to move into a worse ESS on
746 * single error if there are no other BSSes of the
751 if (e->count > limit) {
752 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
753 "(count=%d limit=%d)", e->count, limit);
758 if (bss->ssid_len == 0) {
759 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
763 if (disallowed_bssid(wpa_s, bss->bssid)) {
764 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
768 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
773 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
775 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
776 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
779 if (wpas_network_disabled(wpa_s, ssid)) {
780 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
784 res = wpas_temp_disabled(wpa_s, ssid);
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
787 "temporarily for %d second(s)", res);
792 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
793 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
798 if (wpa && ssid->ssid_len == 0 &&
799 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
802 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
803 /* Only allow wildcard SSID match if an AP
804 * advertises active WPS operation that matches
807 if (ssid->ssid_len == 0 &&
808 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
811 #endif /* CONFIG_WPS */
813 if (ssid->bssid_set && ssid->ssid_len == 0 &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
818 (bss->ssid_len != ssid->ssid_len ||
819 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
820 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
824 if (ssid->bssid_set &&
825 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
830 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
834 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
835 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
836 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
837 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
842 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
848 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
854 if (!wpa_supplicant_match_privacy(bss, ssid)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
860 if (!bss_is_ess(bss)) {
861 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
865 if (!freq_allowed(ssid->freq_list, bss->freq)) {
866 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
871 if (!rate_match(wpa_s, bss)) {
872 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
878 if (ssid->p2p_group &&
879 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
880 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
881 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
885 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
886 struct wpabuf *p2p_ie;
887 u8 dev_addr[ETH_ALEN];
889 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
894 p2p_ie = wpa_bss_get_vendor_ie_multi(
895 bss, P2P_IE_VENDOR_TYPE);
896 if (p2p_ie == NULL) {
897 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
901 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
902 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
904 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
912 * TODO: skip the AP if its P2P IE has Group Formation
913 * bit set in the P2P Group Capability Bitmap and we
914 * are not in Group Formation with that device.
916 #endif /* CONFIG_P2P */
918 /* Matching configuration found */
922 /* No matching configuration found */
927 static struct wpa_bss *
928 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
929 struct wpa_ssid *group,
930 struct wpa_ssid **selected_ssid,
936 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
939 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
942 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
943 struct wpa_bss *bss = wpa_s->last_scan_res[i];
944 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
948 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
951 wpa_ssid_txt(bss->ssid, bss->ssid_len));
959 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
960 struct wpa_ssid **selected_ssid)
962 struct wpa_bss *selected = NULL;
964 struct wpa_ssid *next_ssid = NULL;
966 if (wpa_s->last_scan_res == NULL ||
967 wpa_s->last_scan_res_used == 0)
968 return NULL; /* no scan results from last update */
970 if (wpa_s->next_ssid) {
971 struct wpa_ssid *ssid;
973 /* check that next_ssid is still valid */
974 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
975 if (ssid == wpa_s->next_ssid)
979 wpa_s->next_ssid = NULL;
982 while (selected == NULL) {
983 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
984 if (next_ssid && next_ssid->priority ==
985 wpa_s->conf->pssid[prio]->priority) {
986 selected = wpa_supplicant_select_bss(
987 wpa_s, next_ssid, selected_ssid, 1);
991 selected = wpa_supplicant_select_bss(
992 wpa_s, wpa_s->conf->pssid[prio],
998 if (selected == NULL && wpa_s->blacklist &&
999 !wpa_s->countermeasures) {
1000 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1001 "blacklist and try again");
1002 wpa_blacklist_clear(wpa_s);
1003 wpa_s->blacklist_cleared++;
1004 } else if (selected == NULL)
1012 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1013 int timeout_sec, int timeout_usec)
1015 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1017 * No networks are enabled; short-circuit request so
1018 * we don't wait timeout seconds before transitioning
1019 * to INACTIVE state.
1021 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1022 "since there are no enabled networks");
1023 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1027 wpa_s->scan_for_connection = 1;
1028 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1032 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1033 struct wpa_bss *selected,
1034 struct wpa_ssid *ssid)
1036 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1037 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1038 "PBC session overlap");
1040 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1041 wpa_s->p2p_in_provisioning) {
1042 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1046 #endif /* CONFIG_P2P */
1049 wpas_wps_cancel(wpa_s);
1050 #endif /* CONFIG_WPS */
1054 wpa_msg(wpa_s, MSG_DEBUG,
1055 "Considering connect request: reassociate: %d selected: "
1056 MACSTR " bssid: " MACSTR " pending: " MACSTR
1057 " wpa_state: %s ssid=%p current_ssid=%p",
1058 wpa_s->reassociate, MAC2STR(selected->bssid),
1059 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1060 wpa_supplicant_state_txt(wpa_s->wpa_state),
1061 ssid, wpa_s->current_ssid);
1064 * Do not trigger new association unless the BSSID has changed or if
1065 * reassociation is requested. If we are in process of associating with
1066 * the selected BSSID, do not trigger new attempt.
1068 if (wpa_s->reassociate ||
1069 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1070 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1071 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1072 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1073 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1075 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1076 ssid != wpa_s->current_ssid)))) {
1077 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1078 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1081 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1082 MAC2STR(selected->bssid));
1083 wpa_supplicant_associate(wpa_s, selected, ssid);
1085 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1086 "connect with the selected AP");
1093 static struct wpa_ssid *
1094 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1097 struct wpa_ssid *ssid;
1099 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1100 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1102 if (wpas_network_disabled(wpa_s, ssid))
1104 if (ssid->mode == IEEE80211_MODE_IBSS ||
1105 ssid->mode == IEEE80211_MODE_AP ||
1106 ssid->mode == IEEE80211_MODE_MESH)
1114 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1115 * on BSS added and BSS changed events */
1116 static void wpa_supplicant_rsn_preauth_scan_results(
1117 struct wpa_supplicant *wpa_s)
1119 struct wpa_bss *bss;
1121 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1124 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1125 const u8 *ssid, *rsn;
1127 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1131 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1135 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1141 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1142 struct wpa_bss *selected,
1143 struct wpa_ssid *ssid)
1145 struct wpa_bss *current_bss = NULL;
1148 if (wpa_s->reassociate)
1149 return 1; /* explicit request to reassociate */
1150 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1151 return 1; /* we are not associated; continue */
1152 if (wpa_s->current_ssid == NULL)
1153 return 1; /* unknown current SSID */
1154 if (wpa_s->current_ssid != ssid)
1155 return 1; /* different network block */
1157 if (wpas_driver_bss_selection(wpa_s))
1158 return 0; /* Driver-based roaming */
1160 if (wpa_s->current_ssid->ssid)
1161 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1162 wpa_s->current_ssid->ssid,
1163 wpa_s->current_ssid->ssid_len);
1165 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1168 return 1; /* current BSS not seen in scan results */
1170 if (current_bss == selected)
1173 if (selected->last_update_idx > current_bss->last_update_idx)
1174 return 1; /* current BSS not seen in the last scan */
1176 #ifndef CONFIG_NO_ROAMING
1177 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1178 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1179 MAC2STR(current_bss->bssid), current_bss->level);
1180 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1181 MAC2STR(selected->bssid), selected->level);
1183 if (wpa_s->current_ssid->bssid_set &&
1184 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1186 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1187 "has preferred BSSID");
1191 if (current_bss->level < 0 && current_bss->level > selected->level) {
1192 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1198 if (current_bss->level < 0) {
1199 if (current_bss->level < -85)
1201 else if (current_bss->level < -80)
1203 else if (current_bss->level < -75)
1205 else if (current_bss->level < -70)
1210 if (abs(current_bss->level - selected->level) < min_diff) {
1211 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1217 #else /* CONFIG_NO_ROAMING */
1219 #endif /* CONFIG_NO_ROAMING */
1223 /* Return != 0 if no scan results could be fetched or if scan results should not
1224 * be shared with other virtual interfaces. */
1225 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1226 union wpa_event_data *data,
1229 struct wpa_scan_results *scan_res = NULL;
1232 #ifndef CONFIG_NO_RANDOM_POOL
1234 #endif /* CONFIG_NO_RANDOM_POOL */
1237 if (wpa_s->ap_iface)
1239 #endif /* CONFIG_AP */
1241 wpa_supplicant_notify_scanning(wpa_s, 0);
1243 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1244 data ? &data->scan_info :
1246 if (scan_res == NULL) {
1247 if (wpa_s->conf->ap_scan == 2 || ap ||
1248 wpa_s->scan_res_handler == scan_only_handler)
1252 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1254 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1256 goto scan_work_done;
1259 #ifndef CONFIG_NO_RANDOM_POOL
1260 num = scan_res->num;
1263 for (i = 0; i < num; i++) {
1265 struct wpa_scan_res *res = scan_res->res[i];
1266 buf[0] = res->bssid[5];
1267 buf[1] = res->qual & 0xff;
1268 buf[2] = res->noise & 0xff;
1269 buf[3] = res->level & 0xff;
1270 buf[4] = res->tsf & 0xff;
1271 random_add_randomness(buf, sizeof(buf));
1273 #endif /* CONFIG_NO_RANDOM_POOL */
1275 if (own_request && wpa_s->scan_res_handler &&
1276 (wpa_s->own_scan_running || !wpa_s->external_scan_running)) {
1277 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1278 struct wpa_scan_results *scan_res);
1280 scan_res_handler = wpa_s->scan_res_handler;
1281 wpa_s->scan_res_handler = NULL;
1282 scan_res_handler(wpa_s, scan_res);
1284 goto scan_work_done;
1288 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1290 if (wpa_s->ap_iface->scan_cb)
1291 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1292 #endif /* CONFIG_AP */
1293 goto scan_work_done;
1296 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1297 wpa_s->own_scan_running, wpa_s->external_scan_running);
1298 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1299 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1300 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1301 wpa_s->manual_scan_id);
1302 wpa_s->manual_scan_use_id = 0;
1304 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1306 wpas_notify_scan_results(wpa_s);
1308 wpas_notify_scan_done(wpa_s, 1);
1310 if (!wpa_s->own_scan_running && wpa_s->external_scan_running) {
1311 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1312 wpa_scan_results_free(scan_res);
1316 if (sme_proc_obss_scan(wpa_s) > 0)
1317 goto scan_work_done;
1319 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1320 goto scan_work_done;
1322 if (autoscan_notify_scan(wpa_s, scan_res))
1323 goto scan_work_done;
1325 if (wpa_s->disconnected) {
1326 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1327 goto scan_work_done;
1330 if (!wpas_driver_bss_selection(wpa_s) &&
1331 bgscan_notify_scan(wpa_s, scan_res) == 1)
1332 goto scan_work_done;
1334 wpas_wps_update_ap_info(wpa_s, scan_res);
1336 wpa_scan_results_free(scan_res);
1338 if (wpa_s->scan_work) {
1339 struct wpa_radio_work *work = wpa_s->scan_work;
1340 wpa_s->scan_work = NULL;
1341 radio_work_done(work);
1344 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1347 wpa_scan_results_free(scan_res);
1348 if (wpa_s->scan_work) {
1349 struct wpa_radio_work *work = wpa_s->scan_work;
1350 wpa_s->scan_work = NULL;
1351 radio_work_done(work);
1357 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1358 int new_scan, int own_request)
1360 struct wpa_bss *selected;
1361 struct wpa_ssid *ssid = NULL;
1363 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1367 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1370 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1374 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1375 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1379 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1381 * Do not notify other virtual radios of scan results since we do not
1382 * want them to start other associations at the same time.
1388 wpa_msg(wpa_s, MSG_INFO,
1389 "Avoiding join because we already joined a mesh group");
1392 #endif /* CONFIG_MESH */
1393 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1394 ssid = wpa_supplicant_pick_new_network(wpa_s);
1396 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1397 wpa_supplicant_associate(wpa_s, NULL, ssid);
1399 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1400 } else if (own_request) {
1402 * No SSID found. If SCAN results are as a result of
1403 * own scan request and not due to a scan request on
1404 * another shared interface, try another scan.
1406 int timeout_sec = wpa_s->scan_interval;
1407 int timeout_usec = 0;
1409 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1412 if (wpa_s->p2p_in_provisioning ||
1413 wpa_s->show_group_started ||
1414 wpa_s->p2p_in_invitation) {
1416 * Use shorter wait during P2P Provisioning
1417 * state and during P2P join-a-group operation
1418 * to speed up group formation.
1421 timeout_usec = 250000;
1422 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1426 #endif /* CONFIG_P2P */
1427 #ifdef CONFIG_INTERWORKING
1428 if (wpa_s->conf->auto_interworking &&
1429 wpa_s->conf->interworking &&
1430 wpa_s->conf->cred) {
1431 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1432 "start ANQP fetch since no matching "
1434 wpa_s->network_select = 1;
1435 wpa_s->auto_network_select = 1;
1436 interworking_start_fetch_anqp(wpa_s);
1439 #endif /* CONFIG_INTERWORKING */
1441 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1442 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1444 timeout_usec = 500000;
1445 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1449 #endif /* CONFIG_WPS */
1450 if (wpa_supplicant_req_sched_scan(wpa_s))
1451 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1459 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1460 union wpa_event_data *data)
1462 struct wpa_supplicant *ifs;
1464 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1466 * If no scan results could be fetched, then no need to
1467 * notify those interfaces that did not actually request
1468 * this scan. Similarly, if scan results started a new operation on this
1469 * interface, do not notify other interfaces to avoid concurrent
1470 * operations during a connection attempt.
1476 * Check other interfaces to see if they share the same radio. If
1477 * so, they get updated with this same scan info.
1479 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1482 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1483 "sibling", ifs->ifname);
1484 _wpa_supplicant_event_scan_results(ifs, data, 0);
1489 #endif /* CONFIG_NO_SCAN_PROCESSING */
1492 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1494 #ifdef CONFIG_NO_SCAN_PROCESSING
1496 #else /* CONFIG_NO_SCAN_PROCESSING */
1497 struct os_reltime now;
1499 if (wpa_s->last_scan_res_used <= 0)
1502 os_get_reltime(&now);
1503 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1504 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1508 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1509 #endif /* CONFIG_NO_SCAN_PROCESSING */
1514 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1516 struct wpa_supplicant *wpa_s = eloop_ctx;
1518 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1521 if (!wpa_s->no_keep_alive) {
1522 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1523 MAC2STR(wpa_s->bssid));
1524 /* TODO: could skip this if normal data traffic has been sent */
1525 /* TODO: Consider using some more appropriate data frame for
1528 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1533 if (wpa_s->sme.bss_max_idle_period) {
1535 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1538 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1539 wnm_bss_keep_alive, wpa_s, NULL);
1541 #endif /* CONFIG_SME */
1545 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1546 const u8 *ies, size_t ies_len)
1548 struct ieee802_11_elems elems;
1553 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1557 if (elems.bss_max_idle_period) {
1559 wpa_s->sme.bss_max_idle_period =
1560 WPA_GET_LE16(elems.bss_max_idle_period);
1561 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1562 "TU)%s", wpa_s->sme.bss_max_idle_period,
1563 (elems.bss_max_idle_period[2] & 0x01) ?
1564 " (protected keep-live required)" : "");
1565 if (wpa_s->sme.bss_max_idle_period == 0)
1566 wpa_s->sme.bss_max_idle_period = 1;
1567 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1568 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1569 /* msec times 1000 */
1570 msec = wpa_s->sme.bss_max_idle_period * 1024;
1573 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1574 wnm_bss_keep_alive, wpa_s,
1578 #endif /* CONFIG_SME */
1581 #endif /* CONFIG_WNM */
1584 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1587 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1588 #endif /* CONFIG_WNM */
1592 #ifdef CONFIG_INTERWORKING
1594 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1599 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1600 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1602 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1609 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1610 const u8 *ies, size_t ies_len)
1612 struct ieee802_11_elems elems;
1617 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1620 if (elems.qos_map_set) {
1621 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1622 elems.qos_map_set_len);
1626 #endif /* CONFIG_INTERWORKING */
1629 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1630 union wpa_event_data *data)
1632 int l, len, found = 0, wpa_found, rsn_found;
1634 #ifdef CONFIG_IEEE80211R
1636 #endif /* CONFIG_IEEE80211R */
1638 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1639 if (data->assoc_info.req_ies)
1640 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1641 data->assoc_info.req_ies_len);
1642 if (data->assoc_info.resp_ies) {
1643 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1644 data->assoc_info.resp_ies_len);
1646 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1647 data->assoc_info.resp_ies_len);
1648 #endif /* CONFIG_TDLS */
1650 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1651 data->assoc_info.resp_ies_len);
1652 #endif /* CONFIG_WNM */
1653 #ifdef CONFIG_INTERWORKING
1654 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1655 data->assoc_info.resp_ies_len);
1656 #endif /* CONFIG_INTERWORKING */
1658 if (data->assoc_info.beacon_ies)
1659 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1660 data->assoc_info.beacon_ies,
1661 data->assoc_info.beacon_ies_len);
1662 if (data->assoc_info.freq)
1663 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1664 data->assoc_info.freq);
1666 p = data->assoc_info.req_ies;
1667 l = data->assoc_info.req_ies_len;
1669 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1670 while (p && l >= 2) {
1673 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1677 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1678 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1679 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1680 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1683 wpa_find_assoc_pmkid(wpa_s);
1689 if (!found && data->assoc_info.req_ies)
1690 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1692 #ifdef CONFIG_IEEE80211R
1694 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1695 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1696 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1697 data->assoc_info.resp_ies,
1698 data->assoc_info.resp_ies_len,
1700 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1701 "Reassociation Response failed");
1702 wpa_supplicant_deauthenticate(
1703 wpa_s, WLAN_REASON_INVALID_IE);
1708 p = data->assoc_info.resp_ies;
1709 l = data->assoc_info.resp_ies_len;
1711 #ifdef CONFIG_WPS_STRICT
1712 if (p && wpa_s->current_ssid &&
1713 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1715 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1717 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1718 "include WPS IE in (Re)Association Response");
1722 if (wps_validate_assoc_resp(wps) < 0) {
1724 wpa_supplicant_deauthenticate(
1725 wpa_s, WLAN_REASON_INVALID_IE);
1730 #endif /* CONFIG_WPS_STRICT */
1732 /* Go through the IEs and make a copy of the MDIE, if present. */
1733 while (p && l >= 2) {
1736 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1740 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1741 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1742 wpa_s->sme.ft_used = 1;
1743 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1744 MOBILITY_DOMAIN_ID_LEN);
1750 #endif /* CONFIG_SME */
1752 /* Process FT when SME is in the driver */
1753 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1754 wpa_ft_is_completed(wpa_s->wpa)) {
1755 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1756 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1757 data->assoc_info.resp_ies,
1758 data->assoc_info.resp_ies_len,
1760 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1761 "Reassociation Response failed");
1762 wpa_supplicant_deauthenticate(
1763 wpa_s, WLAN_REASON_INVALID_IE);
1766 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1769 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1770 data->assoc_info.resp_ies_len);
1771 #endif /* CONFIG_IEEE80211R */
1773 /* WPA/RSN IE from Beacon/ProbeResp */
1774 p = data->assoc_info.beacon_ies;
1775 l = data->assoc_info.beacon_ies_len;
1777 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1779 wpa_found = rsn_found = 0;
1780 while (p && l >= 2) {
1783 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1788 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1789 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1791 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1795 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1797 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1804 if (!wpa_found && data->assoc_info.beacon_ies)
1805 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1806 if (!rsn_found && data->assoc_info.beacon_ies)
1807 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1808 if (wpa_found || rsn_found)
1809 wpa_s->ap_ies_from_associnfo = 1;
1811 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1812 wpa_s->assoc_freq != data->assoc_info.freq) {
1813 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1815 wpa_s->assoc_freq, data->assoc_info.freq);
1816 wpa_supplicant_update_scan_results(wpa_s);
1819 wpa_s->assoc_freq = data->assoc_info.freq;
1825 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1827 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1829 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1832 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1835 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1836 WPA_IE_VENDOR_TYPE);
1837 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1839 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1840 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1841 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1842 bss_rsn ? 2 + bss_rsn[1] : 0))
1849 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1850 union wpa_event_data *data)
1856 if (wpa_s->ap_iface) {
1859 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1860 data->assoc_info.addr,
1861 data->assoc_info.req_ies,
1862 data->assoc_info.req_ies_len,
1863 data->assoc_info.reassoc);
1866 #endif /* CONFIG_AP */
1868 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1869 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1872 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1873 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1874 wpa_supplicant_deauthenticate(
1875 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1879 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1880 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1881 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1882 MACSTR, MAC2STR(bssid));
1883 random_add_randomness(bssid, ETH_ALEN);
1884 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1885 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1886 wpas_notify_bssid_changed(wpa_s);
1888 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1889 wpa_clear_keys(wpa_s, bssid);
1891 if (wpa_supplicant_select_config(wpa_s) < 0) {
1892 wpa_supplicant_deauthenticate(
1893 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1897 if (wpa_s->conf->ap_scan == 1 &&
1898 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1899 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1900 wpa_msg(wpa_s, MSG_WARNING,
1901 "WPA/RSN IEs not updated");
1906 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1907 wpa_s->sme.prev_bssid_set = 1;
1908 wpa_s->sme.last_unprot_disconnect.sec = 0;
1909 #endif /* CONFIG_SME */
1911 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1912 if (wpa_s->current_ssid) {
1913 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1914 * initialized before association, but for other modes,
1915 * initialize PC/SC here, if the current configuration needs
1916 * smartcard or SIM/USIM. */
1917 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1919 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1921 l2_packet_notify_auth_start(wpa_s->l2);
1924 * Set portEnabled first to FALSE in order to get EAP state machine out
1925 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1926 * state machine may transit to AUTHENTICATING state based on obsolete
1927 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1928 * AUTHENTICATED without ever giving chance to EAP state machine to
1931 if (!ft_completed) {
1932 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1933 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1935 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1936 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1937 /* 802.1X::portControl = Auto */
1938 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1939 wpa_s->eapol_received = 0;
1940 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1941 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1942 (wpa_s->current_ssid &&
1943 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1944 if (wpa_s->current_ssid &&
1945 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1947 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1949 * Set the key after having received joined-IBSS event
1952 wpa_supplicant_set_wpa_none_key(wpa_s,
1953 wpa_s->current_ssid);
1955 wpa_supplicant_cancel_auth_timeout(wpa_s);
1956 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1957 } else if (!ft_completed) {
1958 /* Timeout for receiving the first EAPOL packet */
1959 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1961 wpa_supplicant_cancel_scan(wpa_s);
1963 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1964 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1966 * We are done; the driver will take care of RSN 4-way
1969 wpa_supplicant_cancel_auth_timeout(wpa_s);
1970 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1971 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1972 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1973 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1974 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1976 * The driver will take care of RSN 4-way handshake, so we need
1977 * to allow EAPOL supplicant to complete its work without
1978 * waiting for WPA supplicant.
1980 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1981 } else if (ft_completed) {
1983 * FT protocol completed - make sure EAPOL state machine ends
1984 * up in authenticated.
1986 wpa_supplicant_cancel_auth_timeout(wpa_s);
1987 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1988 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1989 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1992 wpa_s->last_eapol_matches_bssid = 0;
1994 if (wpa_s->pending_eapol_rx) {
1995 struct os_reltime now, age;
1996 os_get_reltime(&now);
1997 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1998 if (age.sec == 0 && age.usec < 100000 &&
1999 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2002 "frame that was received just before "
2003 "association notification");
2004 wpa_supplicant_rx_eapol(
2005 wpa_s, wpa_s->pending_eapol_rx_src,
2006 wpabuf_head(wpa_s->pending_eapol_rx),
2007 wpabuf_len(wpa_s->pending_eapol_rx));
2009 wpabuf_free(wpa_s->pending_eapol_rx);
2010 wpa_s->pending_eapol_rx = NULL;
2013 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2014 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2015 wpa_s->current_ssid &&
2016 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2017 /* Set static WEP keys again */
2018 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2021 #ifdef CONFIG_IBSS_RSN
2022 if (wpa_s->current_ssid &&
2023 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2024 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2025 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2026 wpa_s->ibss_rsn == NULL) {
2027 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2028 if (!wpa_s->ibss_rsn) {
2029 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2030 wpa_supplicant_deauthenticate(
2031 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2035 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2037 #endif /* CONFIG_IBSS_RSN */
2039 wpas_wps_notify_assoc(wpa_s, bssid);
2043 static int disconnect_reason_recoverable(u16 reason_code)
2045 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2046 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2047 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2051 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2053 int locally_generated)
2057 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2059 * At least Host AP driver and a Prism3 card seemed to be
2060 * generating streams of disconnected events when configuring
2061 * IBSS for WPA-None. Ignore them for now.
2066 bssid = wpa_s->bssid;
2067 if (is_zero_ether_addr(bssid))
2068 bssid = wpa_s->pending_bssid;
2070 if (!is_zero_ether_addr(bssid) ||
2071 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2072 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2074 MAC2STR(bssid), reason_code,
2075 locally_generated ? " locally_generated=1" : "");
2080 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2081 int locally_generated)
2083 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2084 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2085 return 0; /* Not in 4-way handshake with PSK */
2088 * It looks like connection was lost while trying to go through PSK
2089 * 4-way handshake. Filter out known disconnection cases that are caused
2090 * by something else than PSK mismatch to avoid confusing reports.
2093 if (locally_generated) {
2094 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2102 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2104 int locally_generated)
2108 u8 prev_pending_bssid[ETH_ALEN];
2109 struct wpa_bss *fast_reconnect = NULL;
2110 struct wpa_ssid *fast_reconnect_ssid = NULL;
2111 struct wpa_ssid *last_ssid;
2113 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2114 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2116 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2118 * At least Host AP driver and a Prism3 card seemed to be
2119 * generating streams of disconnected events when configuring
2120 * IBSS for WPA-None. Ignore them for now.
2122 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2123 "IBSS/WPA-None mode");
2127 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2128 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2129 "pre-shared key may be incorrect");
2130 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2131 return; /* P2P group removed */
2132 wpas_auth_failed(wpa_s, "WRONG_KEY");
2134 if (!wpa_s->disconnected &&
2135 (!wpa_s->auto_reconnect_disabled ||
2136 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2137 wpas_wps_searching(wpa_s))) {
2138 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2139 "reconnect (wps=%d/%d wpa_state=%d)",
2140 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2141 wpas_wps_searching(wpa_s),
2143 if (wpa_s->wpa_state == WPA_COMPLETED &&
2144 wpa_s->current_ssid &&
2145 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2146 !locally_generated &&
2147 disconnect_reason_recoverable(reason_code)) {
2149 * It looks like the AP has dropped association with
2150 * us, but could allow us to get back in. Try to
2151 * reconnect to the same BSS without full scan to save
2152 * time for some common cases.
2154 fast_reconnect = wpa_s->current_bss;
2155 fast_reconnect_ssid = wpa_s->current_ssid;
2156 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2157 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2159 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2162 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2163 "try to re-connect");
2164 wpa_s->reassociate = 0;
2165 wpa_s->disconnected = 1;
2166 wpa_supplicant_cancel_sched_scan(wpa_s);
2168 bssid = wpa_s->bssid;
2169 if (is_zero_ether_addr(bssid))
2170 bssid = wpa_s->pending_bssid;
2171 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2172 wpas_connection_failed(wpa_s, bssid);
2173 wpa_sm_notify_disassoc(wpa_s->wpa);
2174 if (locally_generated)
2175 wpa_s->disconnect_reason = -reason_code;
2177 wpa_s->disconnect_reason = reason_code;
2178 wpas_notify_disconnect_reason(wpa_s);
2179 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2180 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2181 wpa_clear_keys(wpa_s, wpa_s->bssid);
2183 last_ssid = wpa_s->current_ssid;
2184 wpa_supplicant_mark_disassoc(wpa_s);
2186 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2187 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2188 wpa_s->current_ssid = last_ssid;
2191 if (fast_reconnect &&
2192 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2193 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2194 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2195 fast_reconnect->ssid_len) &&
2196 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2197 #ifndef CONFIG_NO_SCAN_PROCESSING
2198 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2199 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2200 fast_reconnect_ssid) < 0) {
2201 /* Recover through full scan */
2202 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2204 #endif /* CONFIG_NO_SCAN_PROCESSING */
2205 } else if (fast_reconnect) {
2207 * Could not reconnect to the same BSS due to network being
2208 * disabled. Use a new scan to match the alternative behavior
2209 * above, i.e., to continue automatic reconnection attempt in a
2210 * way that enforces disabled network rules.
2212 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2217 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2218 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2220 struct wpa_supplicant *wpa_s = eloop_ctx;
2222 if (!wpa_s->pending_mic_error_report)
2225 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2226 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2227 wpa_s->pending_mic_error_report = 0;
2229 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2233 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2234 union wpa_event_data *data)
2237 struct os_reltime t;
2239 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2240 pairwise = (data && data->michael_mic_failure.unicast);
2242 if ((wpa_s->last_michael_mic_error.sec &&
2243 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2244 wpa_s->pending_mic_error_report) {
2245 if (wpa_s->pending_mic_error_report) {
2247 * Send the pending MIC error report immediately since
2248 * we are going to start countermeasures and AP better
2251 wpa_sm_key_request(wpa_s->wpa, 1,
2252 wpa_s->pending_mic_error_pairwise);
2255 /* Send the new MIC error report immediately since we are going
2256 * to start countermeasures and AP better do the same.
2258 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2260 /* initialize countermeasures */
2261 wpa_s->countermeasures = 1;
2263 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2265 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2268 * Need to wait for completion of request frame. We do not get
2269 * any callback for the message completion, so just wait a
2270 * short while and hope for the best. */
2273 wpa_drv_set_countermeasures(wpa_s, 1);
2274 wpa_supplicant_deauthenticate(wpa_s,
2275 WLAN_REASON_MICHAEL_MIC_FAILURE);
2276 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2278 eloop_register_timeout(60, 0,
2279 wpa_supplicant_stop_countermeasures,
2281 /* TODO: mark the AP rejected for 60 second. STA is
2282 * allowed to associate with another AP.. */
2284 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2285 if (wpa_s->mic_errors_seen) {
2287 * Reduce the effectiveness of Michael MIC error
2288 * reports as a means for attacking against TKIP if
2289 * more than one MIC failure is noticed with the same
2290 * PTK. We delay the transmission of the reports by a
2291 * random time between 0 and 60 seconds in order to
2292 * force the attacker wait 60 seconds before getting
2293 * the information on whether a frame resulted in a MIC
2299 if (os_get_random(rval, sizeof(rval)) < 0)
2300 sec = os_random() % 60;
2302 sec = WPA_GET_BE32(rval) % 60;
2303 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2304 "report %d seconds", sec);
2305 wpa_s->pending_mic_error_report = 1;
2306 wpa_s->pending_mic_error_pairwise = pairwise;
2307 eloop_cancel_timeout(
2308 wpa_supplicant_delayed_mic_error_report,
2310 eloop_register_timeout(
2311 sec, os_random() % 1000000,
2312 wpa_supplicant_delayed_mic_error_report,
2315 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2317 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2318 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2319 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2321 wpa_s->last_michael_mic_error = t;
2322 wpa_s->mic_errors_seen++;
2326 #ifdef CONFIG_TERMINATE_ONLASTIF
2327 static int any_interfaces(struct wpa_supplicant *head)
2329 struct wpa_supplicant *wpa_s;
2331 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2332 if (!wpa_s->interface_removed)
2336 #endif /* CONFIG_TERMINATE_ONLASTIF */
2340 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2341 union wpa_event_data *data)
2343 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2346 switch (data->interface_status.ievent) {
2347 case EVENT_INTERFACE_ADDED:
2348 if (!wpa_s->interface_removed)
2350 wpa_s->interface_removed = 0;
2351 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2352 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2353 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2354 "driver after interface was added");
2357 case EVENT_INTERFACE_REMOVED:
2358 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2359 wpa_s->interface_removed = 1;
2360 wpa_supplicant_mark_disassoc(wpa_s);
2361 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2362 l2_packet_deinit(wpa_s->l2);
2364 #ifdef CONFIG_TERMINATE_ONLASTIF
2365 /* check if last interface */
2366 if (!any_interfaces(wpa_s->global->ifaces))
2368 #endif /* CONFIG_TERMINATE_ONLASTIF */
2374 #ifdef CONFIG_PEERKEY
2376 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2377 union wpa_event_data *data)
2381 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2383 #endif /* CONFIG_PEERKEY */
2387 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2388 union wpa_event_data *data)
2392 switch (data->tdls.oper) {
2393 case TDLS_REQUEST_SETUP:
2394 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2395 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2396 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2398 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2400 case TDLS_REQUEST_TEARDOWN:
2401 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2402 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2403 data->tdls.reason_code);
2405 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2410 #endif /* CONFIG_TDLS */
2414 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2415 union wpa_event_data *data)
2419 switch (data->wnm.oper) {
2420 case WNM_OPER_SLEEP:
2421 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2422 "(action=%d, intval=%d)",
2423 data->wnm.sleep_action, data->wnm.sleep_intval);
2424 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2425 data->wnm.sleep_intval, NULL);
2429 #endif /* CONFIG_WNM */
2432 #ifdef CONFIG_IEEE80211R
2434 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2435 union wpa_event_data *data)
2440 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2441 data->ft_ies.ies_len,
2442 data->ft_ies.ft_action,
2443 data->ft_ies.target_ap,
2444 data->ft_ies.ric_ies,
2445 data->ft_ies.ric_ies_len) < 0) {
2446 /* TODO: prevent MLME/driver from trying to associate? */
2449 #endif /* CONFIG_IEEE80211R */
2452 #ifdef CONFIG_IBSS_RSN
2453 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2454 union wpa_event_data *data)
2456 struct wpa_ssid *ssid;
2457 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2461 ssid = wpa_s->current_ssid;
2464 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2467 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2471 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2472 union wpa_event_data *data)
2474 struct wpa_ssid *ssid = wpa_s->current_ssid;
2479 /* check if the ssid is correctly configured as IBSS/RSN */
2480 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2483 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2484 data->rx_mgmt.frame_len);
2486 #endif /* CONFIG_IBSS_RSN */
2489 #ifdef CONFIG_IEEE80211R
2490 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2493 const u8 *sta_addr, *target_ap_addr;
2496 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2497 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2498 return; /* only SME case supported for now */
2499 if (len < 1 + 2 * ETH_ALEN + 2)
2502 return; /* Only FT Action Response is supported for now */
2503 sta_addr = data + 1;
2504 target_ap_addr = data + 1 + ETH_ALEN;
2505 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2506 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2507 MACSTR " TargetAP " MACSTR " status %u",
2508 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2510 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2511 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2512 " in FT Action Response", MAC2STR(sta_addr));
2517 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2518 "failure (status code %d)", status);
2519 /* TODO: report error to FT code(?) */
2523 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2524 len - (1 + 2 * ETH_ALEN + 2), 1,
2525 target_ap_addr, NULL, 0) < 0)
2530 struct wpa_bss *bss;
2531 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2533 wpa_s->sme.freq = bss->freq;
2534 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2535 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2538 #endif /* CONFIG_SME */
2540 #endif /* CONFIG_IEEE80211R */
2543 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2544 struct unprot_deauth *e)
2546 #ifdef CONFIG_IEEE80211W
2547 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2548 "dropped: " MACSTR " -> " MACSTR
2549 " (reason code %u)",
2550 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2551 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2552 #endif /* CONFIG_IEEE80211W */
2556 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2557 struct unprot_disassoc *e)
2559 #ifdef CONFIG_IEEE80211W
2560 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2561 "dropped: " MACSTR " -> " MACSTR
2562 " (reason code %u)",
2563 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2564 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2565 #endif /* CONFIG_IEEE80211W */
2569 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2570 u16 reason_code, int locally_generated,
2571 const u8 *ie, size_t ie_len, int deauth)
2574 if (wpa_s->ap_iface && addr) {
2575 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2579 if (wpa_s->ap_iface) {
2580 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2583 #endif /* CONFIG_AP */
2585 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2587 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2588 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2589 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2590 eapol_sm_failed(wpa_s->eapol))) &&
2591 !wpa_s->eap_expected_failure))
2592 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2595 if (deauth && reason_code > 0) {
2596 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2597 locally_generated) > 0) {
2599 * The interface was removed, so cannot continue
2600 * processing any additional operations after this.
2605 #endif /* CONFIG_P2P */
2607 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2612 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2613 struct disassoc_info *info)
2615 u16 reason_code = 0;
2616 int locally_generated = 0;
2617 const u8 *addr = NULL;
2618 const u8 *ie = NULL;
2621 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2626 ie_len = info->ie_len;
2627 reason_code = info->reason_code;
2628 locally_generated = info->locally_generated;
2629 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2630 locally_generated ? " (locally generated)" : "");
2632 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2634 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2639 if (wpa_s->ap_iface && info && info->addr) {
2640 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2644 if (wpa_s->ap_iface) {
2645 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2648 #endif /* CONFIG_AP */
2652 wpas_p2p_disassoc_notif(
2653 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2656 #endif /* CONFIG_P2P */
2658 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2659 sme_event_disassoc(wpa_s, info);
2661 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2666 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2667 struct deauth_info *info)
2669 u16 reason_code = 0;
2670 int locally_generated = 0;
2671 const u8 *addr = NULL;
2672 const u8 *ie = NULL;
2675 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2680 ie_len = info->ie_len;
2681 reason_code = info->reason_code;
2682 locally_generated = info->locally_generated;
2683 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2685 locally_generated ? " (locally generated)" : "");
2687 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2690 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2694 wpa_reset_ft_completed(wpa_s->wpa);
2696 wpas_event_disconnect(wpa_s, addr, reason_code,
2697 locally_generated, ie, ie_len, 1);
2701 static const char * reg_init_str(enum reg_change_initiator init)
2704 case REGDOM_SET_BY_CORE:
2706 case REGDOM_SET_BY_USER:
2708 case REGDOM_SET_BY_DRIVER:
2710 case REGDOM_SET_BY_COUNTRY_IE:
2711 return "COUNTRY_IE";
2712 case REGDOM_BEACON_HINT:
2713 return "BEACON_HINT";
2719 static const char * reg_type_str(enum reg_type type)
2722 case REGDOM_TYPE_UNKNOWN:
2724 case REGDOM_TYPE_COUNTRY:
2726 case REGDOM_TYPE_WORLD:
2728 case REGDOM_TYPE_CUSTOM_WORLD:
2729 return "CUSTOM_WORLD";
2730 case REGDOM_TYPE_INTERSECTION:
2731 return "INTERSECTION";
2737 static void wpa_supplicant_update_channel_list(
2738 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2740 struct wpa_supplicant *ifs;
2742 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2743 reg_init_str(info->initiator), reg_type_str(info->type),
2744 info->alpha2[0] ? " alpha2=" : "",
2745 info->alpha2[0] ? info->alpha2 : "");
2747 if (wpa_s->drv_priv == NULL)
2748 return; /* Ignore event during drv initialization */
2750 free_hw_features(wpa_s);
2751 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2752 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2754 wpas_p2p_update_channel_list(wpa_s);
2757 * Check other interfaces to see if they share the same radio. If
2758 * so, they get updated with this same hw mode info.
2760 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2763 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2765 free_hw_features(ifs);
2766 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2767 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2773 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2774 const u8 *frame, size_t len, int freq)
2776 const struct ieee80211_mgmt *mgmt;
2781 if (len < IEEE80211_HDRLEN + 2)
2784 mgmt = (const struct ieee80211_mgmt *) frame;
2785 payload = frame + IEEE80211_HDRLEN;
2786 category = *payload++;
2787 plen = len - IEEE80211_HDRLEN - 1;
2789 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2790 " Category=%u DataLen=%d freq=%d MHz",
2791 MAC2STR(mgmt->sa), category, (int) plen, freq);
2793 #ifdef CONFIG_IEEE80211R
2794 if (category == WLAN_ACTION_FT) {
2795 ft_rx_action(wpa_s, payload, plen);
2798 #endif /* CONFIG_IEEE80211R */
2800 #ifdef CONFIG_IEEE80211W
2802 if (category == WLAN_ACTION_SA_QUERY) {
2803 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2806 #endif /* CONFIG_SME */
2807 #endif /* CONFIG_IEEE80211W */
2810 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2811 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2814 #endif /* CONFIG_WNM */
2817 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2818 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2819 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2820 mgmt->u.action.category,
2821 payload, plen, freq) == 0)
2823 #endif /* CONFIG_GAS */
2826 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2827 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2828 wpa_dbg(wpa_s, MSG_DEBUG,
2829 "TDLS: Received Discovery Response from " MACSTR,
2833 #endif /* CONFIG_TDLS */
2835 #ifdef CONFIG_INTERWORKING
2836 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2837 payload[0] == QOS_QOS_MAP_CONFIG) {
2838 const u8 *pos = payload + 1;
2839 size_t qlen = plen - 1;
2840 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2841 MACSTR, MAC2STR(mgmt->sa));
2842 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2843 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2844 pos[1] <= qlen - 2 && pos[1] >= 16)
2845 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2848 #endif /* CONFIG_INTERWORKING */
2850 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2851 category, payload, plen, freq);
2853 mesh_mpm_action_rx(wpa_s, mgmt, len);
2857 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2858 union wpa_event_data *event)
2861 struct wpa_supplicant *ifs;
2862 #endif /* CONFIG_P2P */
2863 struct wpa_freq_range_list *list;
2866 list = &event->freq_range;
2869 str = freq_range_list_str(list);
2870 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2874 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2875 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2878 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2879 wpas_p2p_update_channel_list(wpa_s);
2882 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2884 if (!ifs->current_ssid ||
2885 !ifs->current_ssid->p2p_group ||
2886 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2887 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2890 freq = ifs->current_ssid->frequency;
2891 if (!freq_range_list_includes(list, freq)) {
2892 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2897 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2899 /* TODO: Consider using CSA or removing the group within
2901 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2903 #endif /* CONFIG_P2P */
2909 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2910 union wpa_event_data *data)
2912 wpa_dbg(wpa_s, MSG_DEBUG,
2913 "Connection authorized by device, previous state %d",
2915 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
2916 wpa_supplicant_cancel_auth_timeout(wpa_s);
2917 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2918 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2919 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2921 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
2922 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
2923 data->assoc_info.ptk_kek);
2927 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2928 union wpa_event_data *data)
2930 struct wpa_supplicant *wpa_s = ctx;
2932 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2933 event != EVENT_INTERFACE_ENABLED &&
2934 event != EVENT_INTERFACE_STATUS &&
2935 event != EVENT_SCHED_SCAN_STOPPED) {
2936 wpa_dbg(wpa_s, MSG_DEBUG,
2937 "Ignore event %s (%d) while interface is disabled",
2938 event_to_string(event), event);
2942 #ifndef CONFIG_NO_STDOUT_DEBUG
2944 int level = MSG_DEBUG;
2946 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2947 const struct ieee80211_hdr *hdr;
2949 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2950 fc = le_to_host16(hdr->frame_control);
2951 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2952 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2953 level = MSG_EXCESSIVE;
2956 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2957 event_to_string(event), event);
2959 #endif /* CONFIG_NO_STDOUT_DEBUG */
2963 sme_event_auth(wpa_s, data);
2966 wpa_supplicant_event_assoc(wpa_s, data);
2967 if (data && data->assoc_info.authorized)
2968 wpa_supplicant_event_assoc_auth(wpa_s, data);
2970 case EVENT_DISASSOC:
2971 wpas_event_disassoc(wpa_s,
2972 data ? &data->disassoc_info : NULL);
2975 wpas_event_deauth(wpa_s,
2976 data ? &data->deauth_info : NULL);
2978 case EVENT_MICHAEL_MIC_FAILURE:
2979 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2981 #ifndef CONFIG_NO_SCAN_PROCESSING
2982 case EVENT_SCAN_STARTED:
2983 os_get_reltime(&wpa_s->scan_start_time);
2984 if (wpa_s->own_scan_requested) {
2985 struct os_reltime diff;
2987 os_reltime_sub(&wpa_s->scan_start_time,
2988 &wpa_s->scan_trigger_time, &diff);
2989 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
2990 diff.sec, diff.usec);
2991 wpa_s->own_scan_requested = 0;
2992 wpa_s->own_scan_running = 1;
2993 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2994 wpa_s->manual_scan_use_id) {
2995 wpa_msg_ctrl(wpa_s, MSG_INFO,
2996 WPA_EVENT_SCAN_STARTED "id=%u",
2997 wpa_s->manual_scan_id);
2999 wpa_msg_ctrl(wpa_s, MSG_INFO,
3000 WPA_EVENT_SCAN_STARTED);
3003 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3004 wpa_s->external_scan_running = 1;
3005 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3008 case EVENT_SCAN_RESULTS:
3009 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3010 struct os_reltime now, diff;
3011 os_get_reltime(&now);
3012 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3013 wpa_s->scan_start_time.sec = 0;
3014 wpa_s->scan_start_time.usec = 0;
3015 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3016 diff.sec, diff.usec);
3018 wpa_supplicant_event_scan_results(wpa_s, data);
3019 wpa_s->own_scan_running = 0;
3020 wpa_s->external_scan_running = 0;
3021 radio_work_check_next(wpa_s);
3023 #endif /* CONFIG_NO_SCAN_PROCESSING */
3024 case EVENT_ASSOCINFO:
3025 wpa_supplicant_event_associnfo(wpa_s, data);
3027 case EVENT_INTERFACE_STATUS:
3028 wpa_supplicant_event_interface_status(wpa_s, data);
3030 case EVENT_PMKID_CANDIDATE:
3031 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3033 #ifdef CONFIG_PEERKEY
3034 case EVENT_STKSTART:
3035 wpa_supplicant_event_stkstart(wpa_s, data);
3037 #endif /* CONFIG_PEERKEY */
3040 wpa_supplicant_event_tdls(wpa_s, data);
3042 #endif /* CONFIG_TDLS */
3045 wpa_supplicant_event_wnm(wpa_s, data);
3047 #endif /* CONFIG_WNM */
3048 #ifdef CONFIG_IEEE80211R
3049 case EVENT_FT_RESPONSE:
3050 wpa_supplicant_event_ft_response(wpa_s, data);
3052 #endif /* CONFIG_IEEE80211R */
3053 #ifdef CONFIG_IBSS_RSN
3054 case EVENT_IBSS_RSN_START:
3055 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3057 #endif /* CONFIG_IBSS_RSN */
3058 case EVENT_ASSOC_REJECT:
3059 if (data->assoc_reject.bssid)
3060 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3061 "bssid=" MACSTR " status_code=%u",
3062 MAC2STR(data->assoc_reject.bssid),
3063 data->assoc_reject.status_code);
3065 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3067 data->assoc_reject.status_code);
3068 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3069 sme_event_assoc_reject(wpa_s, data);
3071 const u8 *bssid = data->assoc_reject.bssid;
3072 if (bssid == NULL || is_zero_ether_addr(bssid))
3073 bssid = wpa_s->pending_bssid;
3074 wpas_connection_failed(wpa_s, bssid);
3075 wpa_supplicant_mark_disassoc(wpa_s);
3078 case EVENT_AUTH_TIMED_OUT:
3079 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3080 sme_event_auth_timed_out(wpa_s, data);
3082 case EVENT_ASSOC_TIMED_OUT:
3083 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3084 sme_event_assoc_timed_out(wpa_s, data);
3086 case EVENT_TX_STATUS:
3087 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3088 " type=%d stype=%d",
3089 MAC2STR(data->tx_status.dst),
3090 data->tx_status.type, data->tx_status.stype);
3092 if (wpa_s->ap_iface == NULL) {
3093 #ifdef CONFIG_OFFCHANNEL
3094 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3095 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3096 offchannel_send_action_tx_status(
3097 wpa_s, data->tx_status.dst,
3098 data->tx_status.data,
3099 data->tx_status.data_len,
3100 data->tx_status.ack ?
3101 OFFCHANNEL_SEND_ACTION_SUCCESS :
3102 OFFCHANNEL_SEND_ACTION_NO_ACK);
3103 #endif /* CONFIG_OFFCHANNEL */
3106 #endif /* CONFIG_AP */
3107 #ifdef CONFIG_OFFCHANNEL
3108 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3109 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3111 * Catch TX status events for Action frames we sent via group
3112 * interface in GO mode.
3114 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3115 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3116 os_memcmp(wpa_s->parent->pending_action_dst,
3117 data->tx_status.dst, ETH_ALEN) == 0) {
3118 offchannel_send_action_tx_status(
3119 wpa_s->parent, data->tx_status.dst,
3120 data->tx_status.data,
3121 data->tx_status.data_len,
3122 data->tx_status.ack ?
3123 OFFCHANNEL_SEND_ACTION_SUCCESS :
3124 OFFCHANNEL_SEND_ACTION_NO_ACK);
3127 #endif /* CONFIG_OFFCHANNEL */
3129 switch (data->tx_status.type) {
3130 case WLAN_FC_TYPE_MGMT:
3131 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3132 data->tx_status.data_len,
3133 data->tx_status.stype,
3134 data->tx_status.ack);
3136 case WLAN_FC_TYPE_DATA:
3137 ap_tx_status(wpa_s, data->tx_status.dst,
3138 data->tx_status.data,
3139 data->tx_status.data_len,
3140 data->tx_status.ack);
3143 #endif /* CONFIG_AP */
3146 case EVENT_EAPOL_TX_STATUS:
3147 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3148 data->eapol_tx_status.data,
3149 data->eapol_tx_status.data_len,
3150 data->eapol_tx_status.ack);
3152 case EVENT_DRIVER_CLIENT_POLL_OK:
3153 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3155 case EVENT_RX_FROM_UNKNOWN:
3156 if (wpa_s->ap_iface == NULL)
3158 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3159 data->rx_from_unknown.wds);
3161 case EVENT_CH_SWITCH:
3164 if (!wpa_s->ap_iface) {
3165 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3166 "event in non-AP mode");
3170 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3171 data->ch_switch.ht_enabled,
3172 data->ch_switch.ch_offset,
3173 data->ch_switch.ch_width,
3174 data->ch_switch.cf1,
3175 data->ch_switch.cf2);
3177 #endif /* CONFIG_AP */
3178 case EVENT_RX_MGMT: {
3180 const struct ieee80211_mgmt *mgmt;
3182 #ifdef CONFIG_TESTING_OPTIONS
3183 if (wpa_s->ext_mgmt_frame_handling) {
3184 struct rx_mgmt *rx = &data->rx_mgmt;
3185 size_t hex_len = 2 * rx->frame_len + 1;
3186 char *hex = os_malloc(hex_len);
3188 wpa_snprintf_hex(hex, hex_len,
3189 rx->frame, rx->frame_len);
3190 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3191 rx->freq, rx->datarate, rx->ssi_signal,
3197 #endif /* CONFIG_TESTING_OPTIONS */
3199 mgmt = (const struct ieee80211_mgmt *)
3200 data->rx_mgmt.frame;
3201 fc = le_to_host16(mgmt->frame_control);
3202 stype = WLAN_FC_GET_STYPE(fc);
3205 if (wpa_s->ap_iface == NULL) {
3206 #endif /* CONFIG_AP */
3208 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3209 data->rx_mgmt.frame_len > 24) {
3210 const u8 *src = mgmt->sa;
3211 const u8 *ie = mgmt->u.probe_req.variable;
3212 size_t ie_len = data->rx_mgmt.frame_len -
3213 (mgmt->u.probe_req.variable -
3214 data->rx_mgmt.frame);
3215 wpas_p2p_probe_req_rx(
3216 wpa_s, src, mgmt->da,
3217 mgmt->bssid, ie, ie_len,
3218 data->rx_mgmt.ssi_signal);
3221 #endif /* CONFIG_P2P */
3222 #ifdef CONFIG_IBSS_RSN
3223 if (wpa_s->current_ssid &&
3224 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3225 stype == WLAN_FC_STYPE_AUTH &&
3226 data->rx_mgmt.frame_len >= 30) {
3227 wpa_supplicant_event_ibss_auth(wpa_s, data);
3230 #endif /* CONFIG_IBSS_RSN */
3232 if (stype == WLAN_FC_STYPE_ACTION) {
3233 wpas_event_rx_mgmt_action(
3234 wpa_s, data->rx_mgmt.frame,
3235 data->rx_mgmt.frame_len,
3236 data->rx_mgmt.freq);
3241 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3245 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3246 "management frame in non-AP mode");
3251 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3252 data->rx_mgmt.frame_len > 24) {
3253 const u8 *ie = mgmt->u.probe_req.variable;
3254 size_t ie_len = data->rx_mgmt.frame_len -
3255 (mgmt->u.probe_req.variable -
3256 data->rx_mgmt.frame);
3258 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3259 mgmt->bssid, ie, ie_len,
3260 data->rx_mgmt.ssi_signal);
3263 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3264 #endif /* CONFIG_AP */
3267 case EVENT_RX_PROBE_REQ:
3268 if (data->rx_probe_req.sa == NULL ||
3269 data->rx_probe_req.ie == NULL)
3272 if (wpa_s->ap_iface) {
3273 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3274 data->rx_probe_req.sa,
3275 data->rx_probe_req.da,
3276 data->rx_probe_req.bssid,
3277 data->rx_probe_req.ie,
3278 data->rx_probe_req.ie_len,
3279 data->rx_probe_req.ssi_signal);
3282 #endif /* CONFIG_AP */
3283 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3284 data->rx_probe_req.da,
3285 data->rx_probe_req.bssid,
3286 data->rx_probe_req.ie,
3287 data->rx_probe_req.ie_len,
3288 data->rx_probe_req.ssi_signal);
3290 case EVENT_REMAIN_ON_CHANNEL:
3291 #ifdef CONFIG_OFFCHANNEL
3292 offchannel_remain_on_channel_cb(
3293 wpa_s, data->remain_on_channel.freq,
3294 data->remain_on_channel.duration);
3295 #endif /* CONFIG_OFFCHANNEL */
3296 wpas_p2p_remain_on_channel_cb(
3297 wpa_s, data->remain_on_channel.freq,
3298 data->remain_on_channel.duration);
3300 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3301 #ifdef CONFIG_OFFCHANNEL
3302 offchannel_cancel_remain_on_channel_cb(
3303 wpa_s, data->remain_on_channel.freq);
3304 #endif /* CONFIG_OFFCHANNEL */
3305 wpas_p2p_cancel_remain_on_channel_cb(
3306 wpa_s, data->remain_on_channel.freq);
3308 case EVENT_EAPOL_RX:
3309 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3310 data->eapol_rx.data,
3311 data->eapol_rx.data_len);
3313 case EVENT_SIGNAL_CHANGE:
3314 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3315 "above=%d signal=%d noise=%d txrate=%d",
3316 data->signal_change.above_threshold,
3317 data->signal_change.current_signal,
3318 data->signal_change.current_noise,
3319 data->signal_change.current_txrate);
3320 bgscan_notify_signal_change(
3321 wpa_s, data->signal_change.above_threshold,
3322 data->signal_change.current_signal,
3323 data->signal_change.current_noise,
3324 data->signal_change.current_txrate);
3326 case EVENT_INTERFACE_ENABLED:
3327 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3328 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3329 wpa_supplicant_update_mac_addr(wpa_s);
3330 if (wpa_s->p2p_mgmt) {
3331 wpa_supplicant_set_state(wpa_s,
3337 if (!wpa_s->ap_iface) {
3338 wpa_supplicant_set_state(wpa_s,
3340 wpa_supplicant_req_scan(wpa_s, 0, 0);
3342 wpa_supplicant_set_state(wpa_s,
3344 #else /* CONFIG_AP */
3345 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3346 wpa_supplicant_req_scan(wpa_s, 0, 0);
3347 #endif /* CONFIG_AP */
3350 case EVENT_INTERFACE_DISABLED:
3351 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3353 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3354 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3355 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3357 * The interface was externally disabled. Remove
3358 * it assuming an external entity will start a
3359 * new session if needed.
3361 wpas_p2p_disconnect(wpa_s);
3364 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3365 p2p_in_progress(wpa_s->global->p2p) > 1) {
3366 /* This radio work will be cancelled, so clear P2P
3369 p2p_stop_find(wpa_s->global->p2p);
3371 #endif /* CONFIG_P2P */
3373 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3375 * Indicate disconnection to keep ctrl_iface events
3378 wpa_supplicant_event_disassoc(
3379 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3381 wpa_supplicant_mark_disassoc(wpa_s);
3382 radio_remove_works(wpa_s, NULL, 0);
3384 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3386 case EVENT_CHANNEL_LIST_CHANGED:
3387 wpa_supplicant_update_channel_list(
3388 wpa_s, &data->channel_list_changed);
3390 case EVENT_INTERFACE_UNAVAILABLE:
3391 wpas_p2p_interface_unavailable(wpa_s);
3393 case EVENT_BEST_CHANNEL:
3394 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3396 data->best_chan.freq_24, data->best_chan.freq_5,
3397 data->best_chan.freq_overall);
3398 wpa_s->best_24_freq = data->best_chan.freq_24;
3399 wpa_s->best_5_freq = data->best_chan.freq_5;
3400 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3401 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3402 data->best_chan.freq_5,
3403 data->best_chan.freq_overall);
3405 case EVENT_UNPROT_DEAUTH:
3406 wpa_supplicant_event_unprot_deauth(wpa_s,
3407 &data->unprot_deauth);
3409 case EVENT_UNPROT_DISASSOC:
3410 wpa_supplicant_event_unprot_disassoc(wpa_s,
3411 &data->unprot_disassoc);
3413 case EVENT_STATION_LOW_ACK:
3415 if (wpa_s->ap_iface && data)
3416 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3417 data->low_ack.addr);
3418 #endif /* CONFIG_AP */
3421 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3422 data->low_ack.addr);
3423 #endif /* CONFIG_TDLS */
3425 case EVENT_IBSS_PEER_LOST:
3426 #ifdef CONFIG_IBSS_RSN
3427 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3428 #endif /* CONFIG_IBSS_RSN */
3430 case EVENT_DRIVER_GTK_REKEY:
3431 if (os_memcmp(data->driver_gtk_rekey.bssid,
3432 wpa_s->bssid, ETH_ALEN))
3436 wpa_sm_update_replay_ctr(wpa_s->wpa,
3437 data->driver_gtk_rekey.replay_ctr);
3439 case EVENT_SCHED_SCAN_STOPPED:
3441 wpa_s->sched_scanning = 0;
3442 wpa_supplicant_notify_scanning(wpa_s, 0);
3444 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3448 * Start a new sched scan to continue searching for more SSIDs
3449 * either if timed out or PNO schedule scan is pending.
3451 if (wpa_s->sched_scan_timed_out) {
3452 wpa_supplicant_req_sched_scan(wpa_s);
3453 } else if (wpa_s->pno_sched_pending) {
3454 wpa_s->pno_sched_pending = 0;
3455 wpas_start_pno(wpa_s);
3459 case EVENT_WPS_BUTTON_PUSHED:
3461 wpas_wps_start_pbc(wpa_s, NULL, 0);
3462 #endif /* CONFIG_WPS */
3464 case EVENT_AVOID_FREQUENCIES:
3465 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3467 case EVENT_CONNECT_FAILED_REASON:
3469 if (!wpa_s->ap_iface || !data)
3471 hostapd_event_connect_failed_reason(
3472 wpa_s->ap_iface->bss[0],
3473 data->connect_failed_reason.addr,
3474 data->connect_failed_reason.code);
3475 #endif /* CONFIG_AP */
3477 case EVENT_NEW_PEER_CANDIDATE:
3479 if (!wpa_s->ifmsh || !data)
3481 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3482 data->mesh_peer.ies,
3483 data->mesh_peer.ie_len);
3484 #endif /* CONFIG_MESH */
3487 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);