2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, 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"
50 #ifndef CONFIG_NO_SCAN_PROCESSING
51 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
52 int new_scan, int own_request);
53 #endif /* CONFIG_NO_SCAN_PROCESSING */
56 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
59 struct os_reltime now;
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
65 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
74 static struct wpa_bss * wpa_supplicant_get_new_bss(
75 struct wpa_supplicant *wpa_s, const u8 *bssid)
77 struct wpa_bss *bss = NULL;
78 struct wpa_ssid *ssid = wpa_s->current_ssid;
80 if (ssid->ssid_len > 0)
81 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
83 bss = wpa_bss_get_bssid(wpa_s, bssid);
89 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
91 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
94 wpa_supplicant_update_scan_results(wpa_s);
96 /* Get the BSS from the new scan results */
97 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
101 wpa_s->current_bss = bss;
105 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
107 struct wpa_ssid *ssid, *old_ssid;
110 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
111 wpa_supplicant_update_current_bss(wpa_s);
115 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
117 ssid = wpa_supplicant_get_ssid(wpa_s);
119 wpa_msg(wpa_s, MSG_INFO,
120 "No network configuration found for the current AP");
124 if (wpas_network_disabled(wpa_s, ssid)) {
125 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
129 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
130 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
131 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
135 res = wpas_temp_disabled(wpa_s, ssid);
137 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
138 "disabled for %d second(s)", res);
142 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
144 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
146 size_t wpa_ie_len = sizeof(wpa_ie);
147 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
148 wpa_ie, &wpa_ie_len) < 0)
149 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
151 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
154 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
155 eapol_sm_invalidate_cached_session(wpa_s->eapol);
156 old_ssid = wpa_s->current_ssid;
157 wpa_s->current_ssid = ssid;
159 wpa_supplicant_update_current_bss(wpa_s);
161 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
162 wpa_supplicant_initiate_eapol(wpa_s);
163 if (old_ssid != wpa_s->current_ssid)
164 wpas_notify_network_changed(wpa_s);
170 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
172 struct wpa_supplicant *wpa_s = eloop_ctx;
174 if (wpa_s->countermeasures) {
175 wpa_s->countermeasures = 0;
176 wpa_drv_set_countermeasures(wpa_s, 0);
177 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
178 wpa_supplicant_req_scan(wpa_s, 0, 0);
183 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
187 wnm_bss_keep_alive_deinit(wpa_s);
189 #ifdef CONFIG_IBSS_RSN
190 ibss_rsn_deinit(wpa_s->ibss_rsn);
191 wpa_s->ibss_rsn = NULL;
192 #endif /* CONFIG_IBSS_RSN */
195 wpa_supplicant_ap_deinit(wpa_s);
196 #endif /* CONFIG_AP */
198 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
201 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
202 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
203 os_memset(wpa_s->bssid, 0, ETH_ALEN);
204 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
205 sme_clear_on_disassoc(wpa_s);
207 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
208 #endif /* CONFIG_P2P */
209 wpa_s->current_bss = NULL;
210 wpa_s->assoc_freq = 0;
213 wpas_notify_bssid_changed(wpa_s);
215 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
216 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
217 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
218 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
219 wpa_s->ap_ies_from_associnfo = 0;
220 wpa_s->current_ssid = NULL;
221 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
224 wpas_rrm_reset(wpa_s);
228 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
230 struct wpa_ie_data ie;
234 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
238 for (i = 0; i < ie.num_pmkid; i++) {
239 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
240 ie.pmkid + i * PMKID_LEN,
242 if (pmksa_set == 0) {
243 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
248 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
249 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
253 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
254 union wpa_event_data *data)
257 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
261 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
262 " index=%d preauth=%d",
263 MAC2STR(data->pmkid_candidate.bssid),
264 data->pmkid_candidate.index,
265 data->pmkid_candidate.preauth);
267 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
268 data->pmkid_candidate.index,
269 data->pmkid_candidate.preauth);
273 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
275 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
276 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
279 #ifdef IEEE8021X_EAPOL
280 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
281 wpa_s->current_ssid &&
282 !(wpa_s->current_ssid->eapol_flags &
283 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
284 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
285 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
286 * plaintext or static WEP keys). */
289 #endif /* IEEE8021X_EAPOL */
296 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
297 * @wpa_s: pointer to wpa_supplicant data
298 * @ssid: Configuration data for the network
299 * Returns: 0 on success, -1 on failure
301 * This function is called when starting authentication with a network that is
302 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
304 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
305 struct wpa_ssid *ssid)
307 #ifdef IEEE8021X_EAPOL
309 int aka = 0, sim = 0;
311 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
312 wpa_s->scard != NULL || wpa_s->conf->external_sim)
315 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
319 struct eap_method_type *eap = ssid->eap.eap_methods;
320 while (eap->vendor != EAP_VENDOR_IETF ||
321 eap->method != EAP_TYPE_NONE) {
322 if (eap->vendor == EAP_VENDOR_IETF) {
323 if (eap->method == EAP_TYPE_SIM)
325 else if (eap->method == EAP_TYPE_AKA ||
326 eap->method == EAP_TYPE_AKA_PRIME)
333 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
335 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
336 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
341 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
342 "use SIM, but neither EAP-SIM nor EAP-AKA are "
347 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
348 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
350 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
351 if (wpa_s->scard == NULL) {
352 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
356 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
357 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
358 #endif /* PCSC_FUNCS */
359 #endif /* IEEE8021X_EAPOL */
365 #ifndef CONFIG_NO_SCAN_PROCESSING
367 static int has_wep_key(struct wpa_ssid *ssid)
371 for (i = 0; i < NUM_WEP_KEYS; i++) {
372 if (ssid->wep_key_len[i])
380 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
381 struct wpa_ssid *ssid)
385 if (ssid->mixed_cell)
389 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
391 #endif /* CONFIG_WPS */
393 if (has_wep_key(ssid))
396 #ifdef IEEE8021X_EAPOL
397 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
398 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
399 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
401 #endif /* IEEE8021X_EAPOL */
403 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
406 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
409 if (bss->caps & IEEE80211_CAP_PRIVACY)
415 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
416 struct wpa_ssid *ssid,
419 struct wpa_ie_data ie;
421 const u8 *rsn_ie, *wpa_ie;
425 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
429 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
430 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
431 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
432 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
433 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
435 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
436 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
439 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
446 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
448 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
453 if (!(ie.proto & ssid->proto)) {
454 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
459 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
460 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
465 if (!(ie.group_cipher & ssid->group_cipher)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
471 if (!(ie.key_mgmt & ssid->key_mgmt)) {
472 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
477 #ifdef CONFIG_IEEE80211W
478 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
479 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
480 wpa_s->conf->pmf : ssid->ieee80211w) ==
481 MGMT_FRAME_PROTECTION_REQUIRED) {
482 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
486 #endif /* CONFIG_IEEE80211W */
488 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
492 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
493 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
496 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
497 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
503 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
505 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
510 if (!(ie.proto & ssid->proto)) {
511 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
516 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
517 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
522 if (!(ie.group_cipher & ssid->group_cipher)) {
523 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
528 if (!(ie.key_mgmt & ssid->key_mgmt)) {
529 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
534 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
538 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
540 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
544 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
545 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
546 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
550 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
551 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
552 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
556 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
557 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
561 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
568 static int freq_allowed(int *freqs, int freq)
575 for (i = 0; freqs[i]; i++)
576 if (freqs[i] == freq)
582 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
584 const struct hostapd_hw_modes *mode = NULL, *modes;
585 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
590 return 1; /* Cannot do matching without knowing band */
592 modes = wpa_s->hw.modes;
595 * The driver does not provide any additional information
596 * about the utilized hardware, so allow the connection attempt
602 for (i = 0; i < wpa_s->hw.num_modes; i++) {
603 for (j = 0; j < modes[i].num_channels; j++) {
604 int freq = modes[i].channels[j].freq;
605 if (freq == bss->freq) {
607 mode->mode == HOSTAPD_MODE_IEEE80211G)
608 break; /* do not allow 802.11b replace
619 for (i = 0; i < (int) sizeof(scan_ie); i++) {
620 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
624 for (j = 2; j < rate_ie[1] + 2; j++) {
625 int flagged = !!(rate_ie[j] & 0x80);
626 int r = (rate_ie[j] & 0x7f) * 5;
629 * IEEE Std 802.11n-2009 7.3.2.2:
630 * The new BSS Membership selector value is encoded
631 * like a legacy basic rate, but it is not a rate and
632 * only indicates if the BSS members are required to
633 * support the mandatory features of Clause 20 [HT PHY]
634 * in order to join the BSS.
636 if (flagged && ((rate_ie[j] & 0x7f) ==
637 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
638 if (!ht_supported(mode)) {
639 wpa_dbg(wpa_s, MSG_DEBUG,
640 " hardware does not support "
647 /* There's also a VHT selector for 802.11ac */
648 if (flagged && ((rate_ie[j] & 0x7f) ==
649 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
650 if (!vht_supported(mode)) {
651 wpa_dbg(wpa_s, MSG_DEBUG,
652 " hardware does not support "
662 /* check for legacy basic rates */
663 for (k = 0; k < mode->num_rates; k++) {
664 if (mode->rates[k] == r)
667 if (k == mode->num_rates) {
669 * IEEE Std 802.11-2007 7.3.2.2 demands that in
670 * order to join a BSS all required rates
671 * have to be supported by the hardware.
673 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
674 "not support required rate %d.%d Mbps",
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
689 static int bss_is_ess(struct wpa_bss *bss)
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
701 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
705 for (i = 0; i < ETH_ALEN; i++) {
706 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
713 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
717 for (i = 0; i < num; i++) {
718 const u8 *a = list + i * ETH_ALEN * 2;
719 const u8 *m = a + ETH_ALEN;
721 if (match_mac_mask(a, addr, m))
728 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
729 int i, struct wpa_bss *bss,
730 struct wpa_ssid *group,
733 u8 wpa_ie_len, rsn_ie_len;
735 struct wpa_blacklist *e;
737 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 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
749 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
750 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
751 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
752 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
753 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
754 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
755 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
757 osen ? " osen=1" : "");
759 e = wpa_blacklist_get(wpa_s, bss->bssid);
762 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
764 * When only a single network is enabled, we can
765 * trigger blacklisting on the first failure. This
766 * should not be done with multiple enabled networks to
767 * avoid getting forced to move into a worse ESS on
768 * single error if there are no other BSSes of the
773 if (e->count > limit) {
774 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
775 "(count=%d limit=%d)", e->count, limit);
780 if (bss->ssid_len == 0) {
781 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
785 if (disallowed_bssid(wpa_s, bss->bssid)) {
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
790 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
791 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
795 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
797 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
798 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
801 if (wpas_network_disabled(wpa_s, ssid)) {
802 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
806 res = wpas_temp_disabled(wpa_s, ssid);
808 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
809 "temporarily for %d second(s)", res);
814 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
820 if (wpa && ssid->ssid_len == 0 &&
821 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
824 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
825 /* Only allow wildcard SSID match if an AP
826 * advertises active WPS operation that matches
829 if (ssid->ssid_len == 0 &&
830 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
833 #endif /* CONFIG_WPS */
835 if (ssid->bssid_set && ssid->ssid_len == 0 &&
836 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
840 (bss->ssid_len != ssid->ssid_len ||
841 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
842 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
846 if (ssid->bssid_set &&
847 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
848 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
852 /* check blacklist */
853 if (ssid->num_bssid_blacklist &&
854 addr_in_list(bss->bssid, ssid->bssid_blacklist,
855 ssid->num_bssid_blacklist)) {
856 wpa_dbg(wpa_s, MSG_DEBUG,
857 " skip - BSSID blacklisted");
861 /* if there is a whitelist, only accept those APs */
862 if (ssid->num_bssid_whitelist &&
863 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
864 ssid->num_bssid_whitelist)) {
865 wpa_dbg(wpa_s, MSG_DEBUG,
866 " skip - BSSID not in whitelist");
870 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
874 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
875 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
876 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
877 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
882 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
884 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
888 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
889 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
894 if (!wpa_supplicant_match_privacy(bss, ssid)) {
895 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
900 if (!bss_is_ess(bss)) {
901 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
905 if (!freq_allowed(ssid->freq_list, bss->freq)) {
906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
911 if (!rate_match(wpa_s, bss)) {
912 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
918 if (ssid->p2p_group &&
919 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
920 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
921 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
925 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
926 struct wpabuf *p2p_ie;
927 u8 dev_addr[ETH_ALEN];
929 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
931 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
934 p2p_ie = wpa_bss_get_vendor_ie_multi(
935 bss, P2P_IE_VENDOR_TYPE);
936 if (p2p_ie == NULL) {
937 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
941 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
942 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
944 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
952 * TODO: skip the AP if its P2P IE has Group Formation
953 * bit set in the P2P Group Capability Bitmap and we
954 * are not in Group Formation with that device.
956 #endif /* CONFIG_P2P */
958 /* Matching configuration found */
962 /* No matching configuration found */
967 static struct wpa_bss *
968 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
969 struct wpa_ssid *group,
970 struct wpa_ssid **selected_ssid,
976 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
979 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
982 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
983 struct wpa_bss *bss = wpa_s->last_scan_res[i];
984 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
988 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
991 wpa_ssid_txt(bss->ssid, bss->ssid_len));
999 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1000 struct wpa_ssid **selected_ssid)
1002 struct wpa_bss *selected = NULL;
1004 struct wpa_ssid *next_ssid = NULL;
1006 if (wpa_s->last_scan_res == NULL ||
1007 wpa_s->last_scan_res_used == 0)
1008 return NULL; /* no scan results from last update */
1010 if (wpa_s->next_ssid) {
1011 struct wpa_ssid *ssid;
1013 /* check that next_ssid is still valid */
1014 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1015 if (ssid == wpa_s->next_ssid)
1019 wpa_s->next_ssid = NULL;
1022 while (selected == NULL) {
1023 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1024 if (next_ssid && next_ssid->priority ==
1025 wpa_s->conf->pssid[prio]->priority) {
1026 selected = wpa_supplicant_select_bss(
1027 wpa_s, next_ssid, selected_ssid, 1);
1031 selected = wpa_supplicant_select_bss(
1032 wpa_s, wpa_s->conf->pssid[prio],
1038 if (selected == NULL && wpa_s->blacklist &&
1039 !wpa_s->countermeasures) {
1040 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1041 "blacklist and try again");
1042 wpa_blacklist_clear(wpa_s);
1043 wpa_s->blacklist_cleared++;
1044 } else if (selected == NULL)
1052 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1053 int timeout_sec, int timeout_usec)
1055 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1057 * No networks are enabled; short-circuit request so
1058 * we don't wait timeout seconds before transitioning
1059 * to INACTIVE state.
1061 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1062 "since there are no enabled networks");
1063 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1067 wpa_s->scan_for_connection = 1;
1068 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1072 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1073 struct wpa_bss *selected,
1074 struct wpa_ssid *ssid)
1076 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1077 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1078 "PBC session overlap");
1080 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1081 wpa_s->p2p_in_provisioning) {
1082 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1086 #endif /* CONFIG_P2P */
1089 wpas_wps_cancel(wpa_s);
1090 #endif /* CONFIG_WPS */
1094 wpa_msg(wpa_s, MSG_DEBUG,
1095 "Considering connect request: reassociate: %d selected: "
1096 MACSTR " bssid: " MACSTR " pending: " MACSTR
1097 " wpa_state: %s ssid=%p current_ssid=%p",
1098 wpa_s->reassociate, MAC2STR(selected->bssid),
1099 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1100 wpa_supplicant_state_txt(wpa_s->wpa_state),
1101 ssid, wpa_s->current_ssid);
1104 * Do not trigger new association unless the BSSID has changed or if
1105 * reassociation is requested. If we are in process of associating with
1106 * the selected BSSID, do not trigger new attempt.
1108 if (wpa_s->reassociate ||
1109 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1110 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1111 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1112 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1113 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1115 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1116 ssid != wpa_s->current_ssid)))) {
1117 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1118 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1121 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1122 MAC2STR(selected->bssid));
1123 wpa_supplicant_associate(wpa_s, selected, ssid);
1125 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1126 "connect with the selected AP");
1133 static struct wpa_ssid *
1134 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1137 struct wpa_ssid *ssid;
1139 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1140 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1142 if (wpas_network_disabled(wpa_s, ssid))
1144 if (ssid->mode == IEEE80211_MODE_IBSS ||
1145 ssid->mode == IEEE80211_MODE_AP ||
1146 ssid->mode == IEEE80211_MODE_MESH)
1154 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1155 * on BSS added and BSS changed events */
1156 static void wpa_supplicant_rsn_preauth_scan_results(
1157 struct wpa_supplicant *wpa_s)
1159 struct wpa_bss *bss;
1161 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1164 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1165 const u8 *ssid, *rsn;
1167 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1171 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1175 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1181 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1182 struct wpa_bss *selected,
1183 struct wpa_ssid *ssid)
1185 struct wpa_bss *current_bss = NULL;
1188 if (wpa_s->reassociate)
1189 return 1; /* explicit request to reassociate */
1190 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1191 return 1; /* we are not associated; continue */
1192 if (wpa_s->current_ssid == NULL)
1193 return 1; /* unknown current SSID */
1194 if (wpa_s->current_ssid != ssid)
1195 return 1; /* different network block */
1197 if (wpas_driver_bss_selection(wpa_s))
1198 return 0; /* Driver-based roaming */
1200 if (wpa_s->current_ssid->ssid)
1201 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1202 wpa_s->current_ssid->ssid,
1203 wpa_s->current_ssid->ssid_len);
1205 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1208 return 1; /* current BSS not seen in scan results */
1210 if (current_bss == selected)
1213 if (selected->last_update_idx > current_bss->last_update_idx)
1214 return 1; /* current BSS not seen in the last scan */
1216 #ifndef CONFIG_NO_ROAMING
1217 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1218 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1219 MAC2STR(current_bss->bssid), current_bss->level);
1220 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1221 MAC2STR(selected->bssid), selected->level);
1223 if (wpa_s->current_ssid->bssid_set &&
1224 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1226 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1227 "has preferred BSSID");
1231 if (current_bss->level < 0 && current_bss->level > selected->level) {
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1238 if (current_bss->level < 0) {
1239 if (current_bss->level < -85)
1241 else if (current_bss->level < -80)
1243 else if (current_bss->level < -75)
1245 else if (current_bss->level < -70)
1250 if (abs(current_bss->level - selected->level) < min_diff) {
1251 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1257 #else /* CONFIG_NO_ROAMING */
1259 #endif /* CONFIG_NO_ROAMING */
1263 /* Return != 0 if no scan results could be fetched or if scan results should not
1264 * be shared with other virtual interfaces. */
1265 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1266 union wpa_event_data *data,
1269 struct wpa_scan_results *scan_res = NULL;
1272 #ifndef CONFIG_NO_RANDOM_POOL
1274 #endif /* CONFIG_NO_RANDOM_POOL */
1277 if (wpa_s->ap_iface)
1279 #endif /* CONFIG_AP */
1281 wpa_supplicant_notify_scanning(wpa_s, 0);
1283 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1284 data ? &data->scan_info :
1286 if (scan_res == NULL) {
1287 if (wpa_s->conf->ap_scan == 2 || ap ||
1288 wpa_s->scan_res_handler == scan_only_handler)
1292 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1294 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1296 goto scan_work_done;
1299 #ifndef CONFIG_NO_RANDOM_POOL
1300 num = scan_res->num;
1303 for (i = 0; i < num; i++) {
1305 struct wpa_scan_res *res = scan_res->res[i];
1306 buf[0] = res->bssid[5];
1307 buf[1] = res->qual & 0xff;
1308 buf[2] = res->noise & 0xff;
1309 buf[3] = res->level & 0xff;
1310 buf[4] = res->tsf & 0xff;
1311 random_add_randomness(buf, sizeof(buf));
1313 #endif /* CONFIG_NO_RANDOM_POOL */
1315 if (own_request && wpa_s->scan_res_handler &&
1316 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1317 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1318 struct wpa_scan_results *scan_res);
1320 scan_res_handler = wpa_s->scan_res_handler;
1321 wpa_s->scan_res_handler = NULL;
1322 scan_res_handler(wpa_s, scan_res);
1324 goto scan_work_done;
1328 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1330 if (wpa_s->ap_iface->scan_cb)
1331 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1332 #endif /* CONFIG_AP */
1333 goto scan_work_done;
1336 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1337 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1338 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1339 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1340 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1341 wpa_s->manual_scan_id);
1342 wpa_s->manual_scan_use_id = 0;
1344 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1346 wpas_notify_scan_results(wpa_s);
1348 wpas_notify_scan_done(wpa_s, 1);
1350 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1351 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1352 wpa_scan_results_free(scan_res);
1356 if (wnm_scan_process(wpa_s, 1) > 0)
1357 goto scan_work_done;
1359 if (sme_proc_obss_scan(wpa_s) > 0)
1360 goto scan_work_done;
1362 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1363 goto scan_work_done;
1365 if (autoscan_notify_scan(wpa_s, scan_res))
1366 goto scan_work_done;
1368 if (wpa_s->disconnected) {
1369 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1370 goto scan_work_done;
1373 if (!wpas_driver_bss_selection(wpa_s) &&
1374 bgscan_notify_scan(wpa_s, scan_res) == 1)
1375 goto scan_work_done;
1377 wpas_wps_update_ap_info(wpa_s, scan_res);
1379 wpa_scan_results_free(scan_res);
1381 if (wpa_s->scan_work) {
1382 struct wpa_radio_work *work = wpa_s->scan_work;
1383 wpa_s->scan_work = NULL;
1384 radio_work_done(work);
1387 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1390 wpa_scan_results_free(scan_res);
1391 if (wpa_s->scan_work) {
1392 struct wpa_radio_work *work = wpa_s->scan_work;
1393 wpa_s->scan_work = NULL;
1394 radio_work_done(work);
1400 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1401 int new_scan, int own_request)
1403 struct wpa_bss *selected;
1404 struct wpa_ssid *ssid = NULL;
1406 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1410 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1413 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1417 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1418 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1422 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1424 * Do not notify other virtual radios of scan results since we do not
1425 * want them to start other associations at the same time.
1431 wpa_msg(wpa_s, MSG_INFO,
1432 "Avoiding join because we already joined a mesh group");
1435 #endif /* CONFIG_MESH */
1436 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1437 ssid = wpa_supplicant_pick_new_network(wpa_s);
1439 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1440 wpa_supplicant_associate(wpa_s, NULL, ssid);
1442 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1443 } else if (own_request) {
1445 * No SSID found. If SCAN results are as a result of
1446 * own scan request and not due to a scan request on
1447 * another shared interface, try another scan.
1449 int timeout_sec = wpa_s->scan_interval;
1450 int timeout_usec = 0;
1452 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1455 if (wpa_s->p2p_in_provisioning ||
1456 wpa_s->show_group_started ||
1457 wpa_s->p2p_in_invitation) {
1459 * Use shorter wait during P2P Provisioning
1460 * state and during P2P join-a-group operation
1461 * to speed up group formation.
1464 timeout_usec = 250000;
1465 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1469 #endif /* CONFIG_P2P */
1470 #ifdef CONFIG_INTERWORKING
1471 if (wpa_s->conf->auto_interworking &&
1472 wpa_s->conf->interworking &&
1473 wpa_s->conf->cred) {
1474 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1475 "start ANQP fetch since no matching "
1477 wpa_s->network_select = 1;
1478 wpa_s->auto_network_select = 1;
1479 interworking_start_fetch_anqp(wpa_s);
1482 #endif /* CONFIG_INTERWORKING */
1484 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1485 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1487 timeout_usec = 500000;
1488 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1492 #endif /* CONFIG_WPS */
1493 if (wpa_supplicant_req_sched_scan(wpa_s))
1494 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1502 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1503 union wpa_event_data *data)
1505 struct wpa_supplicant *ifs;
1507 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1509 * If no scan results could be fetched, then no need to
1510 * notify those interfaces that did not actually request
1511 * this scan. Similarly, if scan results started a new operation on this
1512 * interface, do not notify other interfaces to avoid concurrent
1513 * operations during a connection attempt.
1519 * Check other interfaces to see if they share the same radio. If
1520 * so, they get updated with this same scan info.
1522 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1525 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1526 "sibling", ifs->ifname);
1527 _wpa_supplicant_event_scan_results(ifs, data, 0);
1532 #endif /* CONFIG_NO_SCAN_PROCESSING */
1535 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1537 #ifdef CONFIG_NO_SCAN_PROCESSING
1539 #else /* CONFIG_NO_SCAN_PROCESSING */
1540 struct os_reltime now;
1542 if (wpa_s->last_scan_res_used <= 0)
1545 os_get_reltime(&now);
1546 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1547 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1551 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1552 #endif /* CONFIG_NO_SCAN_PROCESSING */
1557 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1559 struct wpa_supplicant *wpa_s = eloop_ctx;
1561 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1564 if (!wpa_s->no_keep_alive) {
1565 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1566 MAC2STR(wpa_s->bssid));
1567 /* TODO: could skip this if normal data traffic has been sent */
1568 /* TODO: Consider using some more appropriate data frame for
1571 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1576 if (wpa_s->sme.bss_max_idle_period) {
1578 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1581 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1582 wnm_bss_keep_alive, wpa_s, NULL);
1584 #endif /* CONFIG_SME */
1588 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1589 const u8 *ies, size_t ies_len)
1591 struct ieee802_11_elems elems;
1596 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1600 if (elems.bss_max_idle_period) {
1602 wpa_s->sme.bss_max_idle_period =
1603 WPA_GET_LE16(elems.bss_max_idle_period);
1604 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1605 "TU)%s", wpa_s->sme.bss_max_idle_period,
1606 (elems.bss_max_idle_period[2] & 0x01) ?
1607 " (protected keep-live required)" : "");
1608 if (wpa_s->sme.bss_max_idle_period == 0)
1609 wpa_s->sme.bss_max_idle_period = 1;
1610 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1611 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1612 /* msec times 1000 */
1613 msec = wpa_s->sme.bss_max_idle_period * 1024;
1616 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1617 wnm_bss_keep_alive, wpa_s,
1621 #endif /* CONFIG_SME */
1624 #endif /* CONFIG_WNM */
1627 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1630 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1631 #endif /* CONFIG_WNM */
1635 #ifdef CONFIG_INTERWORKING
1637 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1642 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1643 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1645 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1652 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1653 const u8 *ies, size_t ies_len)
1655 struct ieee802_11_elems elems;
1660 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1663 if (elems.qos_map_set) {
1664 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1665 elems.qos_map_set_len);
1669 #endif /* CONFIG_INTERWORKING */
1672 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1673 union wpa_event_data *data)
1675 int l, len, found = 0, wpa_found, rsn_found;
1677 #ifdef CONFIG_IEEE80211R
1679 #endif /* CONFIG_IEEE80211R */
1681 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1682 if (data->assoc_info.req_ies)
1683 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1684 data->assoc_info.req_ies_len);
1685 if (data->assoc_info.resp_ies) {
1686 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1687 data->assoc_info.resp_ies_len);
1689 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1690 data->assoc_info.resp_ies_len);
1691 #endif /* CONFIG_TDLS */
1693 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1694 data->assoc_info.resp_ies_len);
1695 #endif /* CONFIG_WNM */
1696 #ifdef CONFIG_INTERWORKING
1697 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1698 data->assoc_info.resp_ies_len);
1699 #endif /* CONFIG_INTERWORKING */
1701 if (data->assoc_info.beacon_ies)
1702 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1703 data->assoc_info.beacon_ies,
1704 data->assoc_info.beacon_ies_len);
1705 if (data->assoc_info.freq)
1706 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1707 data->assoc_info.freq);
1709 p = data->assoc_info.req_ies;
1710 l = data->assoc_info.req_ies_len;
1712 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1713 while (p && l >= 2) {
1716 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1720 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1721 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1722 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1723 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1726 wpa_find_assoc_pmkid(wpa_s);
1732 if (!found && data->assoc_info.req_ies)
1733 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1735 #ifdef CONFIG_IEEE80211R
1737 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1738 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1739 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1740 data->assoc_info.resp_ies,
1741 data->assoc_info.resp_ies_len,
1743 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1744 "Reassociation Response failed");
1745 wpa_supplicant_deauthenticate(
1746 wpa_s, WLAN_REASON_INVALID_IE);
1751 p = data->assoc_info.resp_ies;
1752 l = data->assoc_info.resp_ies_len;
1754 #ifdef CONFIG_WPS_STRICT
1755 if (p && wpa_s->current_ssid &&
1756 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1758 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1760 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1761 "include WPS IE in (Re)Association Response");
1765 if (wps_validate_assoc_resp(wps) < 0) {
1767 wpa_supplicant_deauthenticate(
1768 wpa_s, WLAN_REASON_INVALID_IE);
1773 #endif /* CONFIG_WPS_STRICT */
1775 /* Go through the IEs and make a copy of the MDIE, if present. */
1776 while (p && l >= 2) {
1779 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1783 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1784 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1785 wpa_s->sme.ft_used = 1;
1786 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1787 MOBILITY_DOMAIN_ID_LEN);
1793 #endif /* CONFIG_SME */
1795 /* Process FT when SME is in the driver */
1796 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1797 wpa_ft_is_completed(wpa_s->wpa)) {
1798 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1799 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1800 data->assoc_info.resp_ies,
1801 data->assoc_info.resp_ies_len,
1803 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1804 "Reassociation Response failed");
1805 wpa_supplicant_deauthenticate(
1806 wpa_s, WLAN_REASON_INVALID_IE);
1809 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1812 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1813 data->assoc_info.resp_ies_len);
1814 #endif /* CONFIG_IEEE80211R */
1816 /* WPA/RSN IE from Beacon/ProbeResp */
1817 p = data->assoc_info.beacon_ies;
1818 l = data->assoc_info.beacon_ies_len;
1820 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1822 wpa_found = rsn_found = 0;
1823 while (p && l >= 2) {
1826 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1831 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1832 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1834 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1838 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1840 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1847 if (!wpa_found && data->assoc_info.beacon_ies)
1848 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1849 if (!rsn_found && data->assoc_info.beacon_ies)
1850 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1851 if (wpa_found || rsn_found)
1852 wpa_s->ap_ies_from_associnfo = 1;
1854 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1855 wpa_s->assoc_freq != data->assoc_info.freq) {
1856 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1858 wpa_s->assoc_freq, data->assoc_info.freq);
1859 wpa_supplicant_update_scan_results(wpa_s);
1862 wpa_s->assoc_freq = data->assoc_info.freq;
1868 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1870 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1872 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1875 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1878 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1879 WPA_IE_VENDOR_TYPE);
1880 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1882 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1883 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1884 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1885 bss_rsn ? 2 + bss_rsn[1] : 0))
1892 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1893 union wpa_event_data *data)
1899 if (wpa_s->ap_iface) {
1902 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1903 data->assoc_info.addr,
1904 data->assoc_info.req_ies,
1905 data->assoc_info.req_ies_len,
1906 data->assoc_info.reassoc);
1909 #endif /* CONFIG_AP */
1911 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1912 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1915 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1916 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1917 wpa_supplicant_deauthenticate(
1918 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1922 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1923 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1924 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1925 MACSTR, MAC2STR(bssid));
1926 random_add_randomness(bssid, ETH_ALEN);
1927 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1928 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1929 wpas_notify_bssid_changed(wpa_s);
1931 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1932 wpa_clear_keys(wpa_s, bssid);
1934 if (wpa_supplicant_select_config(wpa_s) < 0) {
1935 wpa_supplicant_deauthenticate(
1936 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1940 if (wpa_s->conf->ap_scan == 1 &&
1941 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1942 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1943 wpa_msg(wpa_s, MSG_WARNING,
1944 "WPA/RSN IEs not updated");
1949 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1950 wpa_s->sme.prev_bssid_set = 1;
1951 wpa_s->sme.last_unprot_disconnect.sec = 0;
1952 #endif /* CONFIG_SME */
1954 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1955 if (wpa_s->current_ssid) {
1956 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1957 * initialized before association, but for other modes,
1958 * initialize PC/SC here, if the current configuration needs
1959 * smartcard or SIM/USIM. */
1960 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1962 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1964 l2_packet_notify_auth_start(wpa_s->l2);
1967 * Set portEnabled first to FALSE in order to get EAP state machine out
1968 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1969 * state machine may transit to AUTHENTICATING state based on obsolete
1970 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1971 * AUTHENTICATED without ever giving chance to EAP state machine to
1974 if (!ft_completed) {
1975 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1976 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1978 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1979 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1980 /* 802.1X::portControl = Auto */
1981 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1982 wpa_s->eapol_received = 0;
1983 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1984 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1985 (wpa_s->current_ssid &&
1986 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1987 if (wpa_s->current_ssid &&
1988 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1990 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1992 * Set the key after having received joined-IBSS event
1995 wpa_supplicant_set_wpa_none_key(wpa_s,
1996 wpa_s->current_ssid);
1998 wpa_supplicant_cancel_auth_timeout(wpa_s);
1999 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2000 } else if (!ft_completed) {
2001 /* Timeout for receiving the first EAPOL packet */
2002 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2004 wpa_supplicant_cancel_scan(wpa_s);
2006 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2007 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2009 * We are done; the driver will take care of RSN 4-way
2012 wpa_supplicant_cancel_auth_timeout(wpa_s);
2013 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2014 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2015 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2016 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2017 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2019 * The driver will take care of RSN 4-way handshake, so we need
2020 * to allow EAPOL supplicant to complete its work without
2021 * waiting for WPA supplicant.
2023 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2024 } else if (ft_completed) {
2026 * FT protocol completed - make sure EAPOL state machine ends
2027 * up in authenticated.
2029 wpa_supplicant_cancel_auth_timeout(wpa_s);
2030 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2031 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2032 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2035 wpa_s->last_eapol_matches_bssid = 0;
2037 if (wpa_s->pending_eapol_rx) {
2038 struct os_reltime now, age;
2039 os_get_reltime(&now);
2040 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2041 if (age.sec == 0 && age.usec < 100000 &&
2042 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2044 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2045 "frame that was received just before "
2046 "association notification");
2047 wpa_supplicant_rx_eapol(
2048 wpa_s, wpa_s->pending_eapol_rx_src,
2049 wpabuf_head(wpa_s->pending_eapol_rx),
2050 wpabuf_len(wpa_s->pending_eapol_rx));
2052 wpabuf_free(wpa_s->pending_eapol_rx);
2053 wpa_s->pending_eapol_rx = NULL;
2056 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2057 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2058 wpa_s->current_ssid &&
2059 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2060 /* Set static WEP keys again */
2061 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2064 #ifdef CONFIG_IBSS_RSN
2065 if (wpa_s->current_ssid &&
2066 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2067 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2068 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2069 wpa_s->ibss_rsn == NULL) {
2070 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2071 if (!wpa_s->ibss_rsn) {
2072 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2073 wpa_supplicant_deauthenticate(
2074 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2078 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2080 #endif /* CONFIG_IBSS_RSN */
2082 wpas_wps_notify_assoc(wpa_s, bssid);
2085 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2086 data->assoc_info.resp_ies_len,
2087 &data->assoc_info.wmm_params);
2089 if (wpa_s->reassoc_same_bss)
2090 wmm_ac_restore_tspecs(wpa_s);
2095 static int disconnect_reason_recoverable(u16 reason_code)
2097 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2098 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2099 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2103 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2105 int locally_generated)
2109 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2111 * At least Host AP driver and a Prism3 card seemed to be
2112 * generating streams of disconnected events when configuring
2113 * IBSS for WPA-None. Ignore them for now.
2118 bssid = wpa_s->bssid;
2119 if (is_zero_ether_addr(bssid))
2120 bssid = wpa_s->pending_bssid;
2122 if (!is_zero_ether_addr(bssid) ||
2123 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2124 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2126 MAC2STR(bssid), reason_code,
2127 locally_generated ? " locally_generated=1" : "");
2132 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2133 int locally_generated)
2135 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2136 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2137 return 0; /* Not in 4-way handshake with PSK */
2140 * It looks like connection was lost while trying to go through PSK
2141 * 4-way handshake. Filter out known disconnection cases that are caused
2142 * by something else than PSK mismatch to avoid confusing reports.
2145 if (locally_generated) {
2146 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2154 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2156 int locally_generated)
2160 u8 prev_pending_bssid[ETH_ALEN];
2161 struct wpa_bss *fast_reconnect = NULL;
2162 struct wpa_ssid *fast_reconnect_ssid = NULL;
2163 struct wpa_ssid *last_ssid;
2165 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2166 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2168 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2170 * At least Host AP driver and a Prism3 card seemed to be
2171 * generating streams of disconnected events when configuring
2172 * IBSS for WPA-None. Ignore them for now.
2174 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2175 "IBSS/WPA-None mode");
2179 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2180 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2181 "pre-shared key may be incorrect");
2182 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2183 return; /* P2P group removed */
2184 wpas_auth_failed(wpa_s, "WRONG_KEY");
2186 if (!wpa_s->disconnected &&
2187 (!wpa_s->auto_reconnect_disabled ||
2188 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2189 wpas_wps_searching(wpa_s))) {
2190 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2191 "reconnect (wps=%d/%d wpa_state=%d)",
2192 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2193 wpas_wps_searching(wpa_s),
2195 if (wpa_s->wpa_state == WPA_COMPLETED &&
2196 wpa_s->current_ssid &&
2197 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2198 !locally_generated &&
2199 disconnect_reason_recoverable(reason_code)) {
2201 * It looks like the AP has dropped association with
2202 * us, but could allow us to get back in. Try to
2203 * reconnect to the same BSS without full scan to save
2204 * time for some common cases.
2206 fast_reconnect = wpa_s->current_bss;
2207 fast_reconnect_ssid = wpa_s->current_ssid;
2208 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2209 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2211 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2214 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2215 "try to re-connect");
2216 wpa_s->reassociate = 0;
2217 wpa_s->disconnected = 1;
2218 wpa_supplicant_cancel_sched_scan(wpa_s);
2220 bssid = wpa_s->bssid;
2221 if (is_zero_ether_addr(bssid))
2222 bssid = wpa_s->pending_bssid;
2223 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2224 wpas_connection_failed(wpa_s, bssid);
2225 wpa_sm_notify_disassoc(wpa_s->wpa);
2226 if (locally_generated)
2227 wpa_s->disconnect_reason = -reason_code;
2229 wpa_s->disconnect_reason = reason_code;
2230 wpas_notify_disconnect_reason(wpa_s);
2231 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2232 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2233 wpa_clear_keys(wpa_s, wpa_s->bssid);
2235 last_ssid = wpa_s->current_ssid;
2236 wpa_supplicant_mark_disassoc(wpa_s);
2238 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2239 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2240 wpa_s->current_ssid = last_ssid;
2243 if (fast_reconnect &&
2244 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2245 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2246 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2247 fast_reconnect->ssid_len) &&
2248 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2249 #ifndef CONFIG_NO_SCAN_PROCESSING
2250 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2251 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2252 fast_reconnect_ssid) < 0) {
2253 /* Recover through full scan */
2254 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2256 #endif /* CONFIG_NO_SCAN_PROCESSING */
2257 } else if (fast_reconnect) {
2259 * Could not reconnect to the same BSS due to network being
2260 * disabled. Use a new scan to match the alternative behavior
2261 * above, i.e., to continue automatic reconnection attempt in a
2262 * way that enforces disabled network rules.
2264 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2269 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2270 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2272 struct wpa_supplicant *wpa_s = eloop_ctx;
2274 if (!wpa_s->pending_mic_error_report)
2277 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2278 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2279 wpa_s->pending_mic_error_report = 0;
2281 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2285 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2286 union wpa_event_data *data)
2289 struct os_reltime t;
2291 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2292 pairwise = (data && data->michael_mic_failure.unicast);
2294 if ((wpa_s->last_michael_mic_error.sec &&
2295 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2296 wpa_s->pending_mic_error_report) {
2297 if (wpa_s->pending_mic_error_report) {
2299 * Send the pending MIC error report immediately since
2300 * we are going to start countermeasures and AP better
2303 wpa_sm_key_request(wpa_s->wpa, 1,
2304 wpa_s->pending_mic_error_pairwise);
2307 /* Send the new MIC error report immediately since we are going
2308 * to start countermeasures and AP better do the same.
2310 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2312 /* initialize countermeasures */
2313 wpa_s->countermeasures = 1;
2315 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2317 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2320 * Need to wait for completion of request frame. We do not get
2321 * any callback for the message completion, so just wait a
2322 * short while and hope for the best. */
2325 wpa_drv_set_countermeasures(wpa_s, 1);
2326 wpa_supplicant_deauthenticate(wpa_s,
2327 WLAN_REASON_MICHAEL_MIC_FAILURE);
2328 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2330 eloop_register_timeout(60, 0,
2331 wpa_supplicant_stop_countermeasures,
2333 /* TODO: mark the AP rejected for 60 second. STA is
2334 * allowed to associate with another AP.. */
2336 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2337 if (wpa_s->mic_errors_seen) {
2339 * Reduce the effectiveness of Michael MIC error
2340 * reports as a means for attacking against TKIP if
2341 * more than one MIC failure is noticed with the same
2342 * PTK. We delay the transmission of the reports by a
2343 * random time between 0 and 60 seconds in order to
2344 * force the attacker wait 60 seconds before getting
2345 * the information on whether a frame resulted in a MIC
2351 if (os_get_random(rval, sizeof(rval)) < 0)
2352 sec = os_random() % 60;
2354 sec = WPA_GET_BE32(rval) % 60;
2355 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2356 "report %d seconds", sec);
2357 wpa_s->pending_mic_error_report = 1;
2358 wpa_s->pending_mic_error_pairwise = pairwise;
2359 eloop_cancel_timeout(
2360 wpa_supplicant_delayed_mic_error_report,
2362 eloop_register_timeout(
2363 sec, os_random() % 1000000,
2364 wpa_supplicant_delayed_mic_error_report,
2367 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2369 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2370 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2371 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2373 wpa_s->last_michael_mic_error = t;
2374 wpa_s->mic_errors_seen++;
2378 #ifdef CONFIG_TERMINATE_ONLASTIF
2379 static int any_interfaces(struct wpa_supplicant *head)
2381 struct wpa_supplicant *wpa_s;
2383 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2384 if (!wpa_s->interface_removed)
2388 #endif /* CONFIG_TERMINATE_ONLASTIF */
2392 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2393 union wpa_event_data *data)
2395 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2398 switch (data->interface_status.ievent) {
2399 case EVENT_INTERFACE_ADDED:
2400 if (!wpa_s->interface_removed)
2402 wpa_s->interface_removed = 0;
2403 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2404 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2405 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2406 "driver after interface was added");
2409 case EVENT_INTERFACE_REMOVED:
2410 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2411 wpa_s->interface_removed = 1;
2412 wpa_supplicant_mark_disassoc(wpa_s);
2413 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2414 l2_packet_deinit(wpa_s->l2);
2416 #ifdef CONFIG_TERMINATE_ONLASTIF
2417 /* check if last interface */
2418 if (!any_interfaces(wpa_s->global->ifaces))
2420 #endif /* CONFIG_TERMINATE_ONLASTIF */
2426 #ifdef CONFIG_PEERKEY
2428 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2429 union wpa_event_data *data)
2433 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2435 #endif /* CONFIG_PEERKEY */
2439 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2440 union wpa_event_data *data)
2444 switch (data->tdls.oper) {
2445 case TDLS_REQUEST_SETUP:
2446 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2447 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2448 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2450 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2452 case TDLS_REQUEST_TEARDOWN:
2453 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2454 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2455 data->tdls.reason_code);
2457 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2462 #endif /* CONFIG_TDLS */
2466 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2467 union wpa_event_data *data)
2471 switch (data->wnm.oper) {
2472 case WNM_OPER_SLEEP:
2473 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2474 "(action=%d, intval=%d)",
2475 data->wnm.sleep_action, data->wnm.sleep_intval);
2476 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2477 data->wnm.sleep_intval, NULL);
2481 #endif /* CONFIG_WNM */
2484 #ifdef CONFIG_IEEE80211R
2486 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2487 union wpa_event_data *data)
2492 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2493 data->ft_ies.ies_len,
2494 data->ft_ies.ft_action,
2495 data->ft_ies.target_ap,
2496 data->ft_ies.ric_ies,
2497 data->ft_ies.ric_ies_len) < 0) {
2498 /* TODO: prevent MLME/driver from trying to associate? */
2501 #endif /* CONFIG_IEEE80211R */
2504 #ifdef CONFIG_IBSS_RSN
2505 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2506 union wpa_event_data *data)
2508 struct wpa_ssid *ssid;
2509 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2513 ssid = wpa_s->current_ssid;
2516 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2519 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2523 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2524 union wpa_event_data *data)
2526 struct wpa_ssid *ssid = wpa_s->current_ssid;
2531 /* check if the ssid is correctly configured as IBSS/RSN */
2532 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2535 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2536 data->rx_mgmt.frame_len);
2538 #endif /* CONFIG_IBSS_RSN */
2541 #ifdef CONFIG_IEEE80211R
2542 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2545 const u8 *sta_addr, *target_ap_addr;
2548 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2549 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2550 return; /* only SME case supported for now */
2551 if (len < 1 + 2 * ETH_ALEN + 2)
2554 return; /* Only FT Action Response is supported for now */
2555 sta_addr = data + 1;
2556 target_ap_addr = data + 1 + ETH_ALEN;
2557 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2558 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2559 MACSTR " TargetAP " MACSTR " status %u",
2560 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2562 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2563 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2564 " in FT Action Response", MAC2STR(sta_addr));
2569 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2570 "failure (status code %d)", status);
2571 /* TODO: report error to FT code(?) */
2575 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2576 len - (1 + 2 * ETH_ALEN + 2), 1,
2577 target_ap_addr, NULL, 0) < 0)
2582 struct wpa_bss *bss;
2583 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2585 wpa_s->sme.freq = bss->freq;
2586 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2587 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2590 #endif /* CONFIG_SME */
2592 #endif /* CONFIG_IEEE80211R */
2595 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2596 struct unprot_deauth *e)
2598 #ifdef CONFIG_IEEE80211W
2599 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2600 "dropped: " MACSTR " -> " MACSTR
2601 " (reason code %u)",
2602 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2603 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2604 #endif /* CONFIG_IEEE80211W */
2608 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2609 struct unprot_disassoc *e)
2611 #ifdef CONFIG_IEEE80211W
2612 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2613 "dropped: " MACSTR " -> " MACSTR
2614 " (reason code %u)",
2615 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2616 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2617 #endif /* CONFIG_IEEE80211W */
2621 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2622 u16 reason_code, int locally_generated,
2623 const u8 *ie, size_t ie_len, int deauth)
2626 if (wpa_s->ap_iface && addr) {
2627 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2631 if (wpa_s->ap_iface) {
2632 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2635 #endif /* CONFIG_AP */
2637 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2639 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2640 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2641 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2642 eapol_sm_failed(wpa_s->eapol))) &&
2643 !wpa_s->eap_expected_failure))
2644 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2647 if (deauth && reason_code > 0) {
2648 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2649 locally_generated) > 0) {
2651 * The interface was removed, so cannot continue
2652 * processing any additional operations after this.
2657 #endif /* CONFIG_P2P */
2659 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2664 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2665 struct disassoc_info *info)
2667 u16 reason_code = 0;
2668 int locally_generated = 0;
2669 const u8 *addr = NULL;
2670 const u8 *ie = NULL;
2673 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2678 ie_len = info->ie_len;
2679 reason_code = info->reason_code;
2680 locally_generated = info->locally_generated;
2681 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2682 locally_generated ? " (locally generated)" : "");
2684 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2686 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2691 if (wpa_s->ap_iface && info && info->addr) {
2692 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2696 if (wpa_s->ap_iface) {
2697 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2700 #endif /* CONFIG_AP */
2704 wpas_p2p_disassoc_notif(
2705 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2708 #endif /* CONFIG_P2P */
2710 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2711 sme_event_disassoc(wpa_s, info);
2713 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2718 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2719 struct deauth_info *info)
2721 u16 reason_code = 0;
2722 int locally_generated = 0;
2723 const u8 *addr = NULL;
2724 const u8 *ie = NULL;
2727 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2732 ie_len = info->ie_len;
2733 reason_code = info->reason_code;
2734 locally_generated = info->locally_generated;
2735 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2737 locally_generated ? " (locally generated)" : "");
2739 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2742 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2746 wpa_reset_ft_completed(wpa_s->wpa);
2748 wpas_event_disconnect(wpa_s, addr, reason_code,
2749 locally_generated, ie, ie_len, 1);
2753 static const char * reg_init_str(enum reg_change_initiator init)
2756 case REGDOM_SET_BY_CORE:
2758 case REGDOM_SET_BY_USER:
2760 case REGDOM_SET_BY_DRIVER:
2762 case REGDOM_SET_BY_COUNTRY_IE:
2763 return "COUNTRY_IE";
2764 case REGDOM_BEACON_HINT:
2765 return "BEACON_HINT";
2771 static const char * reg_type_str(enum reg_type type)
2774 case REGDOM_TYPE_UNKNOWN:
2776 case REGDOM_TYPE_COUNTRY:
2778 case REGDOM_TYPE_WORLD:
2780 case REGDOM_TYPE_CUSTOM_WORLD:
2781 return "CUSTOM_WORLD";
2782 case REGDOM_TYPE_INTERSECTION:
2783 return "INTERSECTION";
2789 static void wpa_supplicant_update_channel_list(
2790 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2792 struct wpa_supplicant *ifs;
2794 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2795 reg_init_str(info->initiator), reg_type_str(info->type),
2796 info->alpha2[0] ? " alpha2=" : "",
2797 info->alpha2[0] ? info->alpha2 : "");
2799 if (wpa_s->drv_priv == NULL)
2800 return; /* Ignore event during drv initialization */
2802 free_hw_features(wpa_s);
2803 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2804 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2806 wpas_p2p_update_channel_list(wpa_s);
2809 * Check other interfaces to see if they share the same radio. If
2810 * so, they get updated with this same hw mode info.
2812 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2815 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2817 free_hw_features(ifs);
2818 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2819 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2825 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2826 const u8 *frame, size_t len, int freq,
2829 const struct ieee80211_mgmt *mgmt;
2834 if (len < IEEE80211_HDRLEN + 2)
2837 mgmt = (const struct ieee80211_mgmt *) frame;
2838 payload = frame + IEEE80211_HDRLEN;
2839 category = *payload++;
2840 plen = len - IEEE80211_HDRLEN - 1;
2842 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2843 " Category=%u DataLen=%d freq=%d MHz",
2844 MAC2STR(mgmt->sa), category, (int) plen, freq);
2846 if (category == WLAN_ACTION_WMM) {
2847 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2851 #ifdef CONFIG_IEEE80211R
2852 if (category == WLAN_ACTION_FT) {
2853 ft_rx_action(wpa_s, payload, plen);
2856 #endif /* CONFIG_IEEE80211R */
2858 #ifdef CONFIG_IEEE80211W
2860 if (category == WLAN_ACTION_SA_QUERY) {
2861 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2864 #endif /* CONFIG_SME */
2865 #endif /* CONFIG_IEEE80211W */
2868 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2869 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2872 #endif /* CONFIG_WNM */
2875 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2876 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2877 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2878 mgmt->u.action.category,
2879 payload, plen, freq) == 0)
2881 #endif /* CONFIG_GAS */
2884 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2885 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2886 wpa_dbg(wpa_s, MSG_DEBUG,
2887 "TDLS: Received Discovery Response from " MACSTR,
2891 #endif /* CONFIG_TDLS */
2893 #ifdef CONFIG_INTERWORKING
2894 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2895 payload[0] == QOS_QOS_MAP_CONFIG) {
2896 const u8 *pos = payload + 1;
2897 size_t qlen = plen - 1;
2898 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2899 MACSTR, MAC2STR(mgmt->sa));
2900 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2901 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2902 pos[1] <= qlen - 2 && pos[1] >= 16)
2903 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2906 #endif /* CONFIG_INTERWORKING */
2908 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2909 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2910 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2914 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2915 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2916 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2917 payload + 1, plen - 1,
2922 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2923 category, payload, plen, freq);
2925 mesh_mpm_action_rx(wpa_s, mgmt, len);
2929 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2930 union wpa_event_data *event)
2933 struct wpa_supplicant *ifs;
2934 #endif /* CONFIG_P2P */
2935 struct wpa_freq_range_list *list;
2938 list = &event->freq_range;
2941 str = freq_range_list_str(list);
2942 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2946 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2947 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2950 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2951 wpas_p2p_update_channel_list(wpa_s);
2954 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2956 if (!ifs->current_ssid ||
2957 !ifs->current_ssid->p2p_group ||
2958 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2959 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2962 freq = ifs->current_ssid->frequency;
2963 if (!freq_range_list_includes(list, freq)) {
2964 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2969 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2971 /* TODO: Consider using CSA or removing the group within
2973 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2975 #endif /* CONFIG_P2P */
2981 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2982 union wpa_event_data *data)
2984 wpa_dbg(wpa_s, MSG_DEBUG,
2985 "Connection authorized by device, previous state %d",
2987 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
2988 wpa_supplicant_cancel_auth_timeout(wpa_s);
2989 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2990 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2991 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2993 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
2994 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
2995 data->assoc_info.ptk_kck_len,
2996 data->assoc_info.ptk_kek,
2997 data->assoc_info.ptk_kek_len);
3001 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3002 union wpa_event_data *data)
3004 struct wpa_supplicant *wpa_s = ctx;
3006 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3007 event != EVENT_INTERFACE_ENABLED &&
3008 event != EVENT_INTERFACE_STATUS &&
3009 event != EVENT_SCHED_SCAN_STOPPED) {
3010 wpa_dbg(wpa_s, MSG_DEBUG,
3011 "Ignore event %s (%d) while interface is disabled",
3012 event_to_string(event), event);
3016 #ifndef CONFIG_NO_STDOUT_DEBUG
3018 int level = MSG_DEBUG;
3020 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3021 const struct ieee80211_hdr *hdr;
3023 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3024 fc = le_to_host16(hdr->frame_control);
3025 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3026 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3027 level = MSG_EXCESSIVE;
3030 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3031 event_to_string(event), event);
3033 #endif /* CONFIG_NO_STDOUT_DEBUG */
3037 sme_event_auth(wpa_s, data);
3040 wpa_supplicant_event_assoc(wpa_s, data);
3041 if (data && data->assoc_info.authorized)
3042 wpa_supplicant_event_assoc_auth(wpa_s, data);
3044 case EVENT_DISASSOC:
3045 wpas_event_disassoc(wpa_s,
3046 data ? &data->disassoc_info : NULL);
3049 wpas_event_deauth(wpa_s,
3050 data ? &data->deauth_info : NULL);
3052 case EVENT_MICHAEL_MIC_FAILURE:
3053 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3055 #ifndef CONFIG_NO_SCAN_PROCESSING
3056 case EVENT_SCAN_STARTED:
3057 os_get_reltime(&wpa_s->scan_start_time);
3058 if (wpa_s->own_scan_requested) {
3059 struct os_reltime diff;
3061 os_reltime_sub(&wpa_s->scan_start_time,
3062 &wpa_s->scan_trigger_time, &diff);
3063 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3064 diff.sec, diff.usec);
3065 wpa_s->own_scan_requested = 0;
3066 wpa_s->own_scan_running = 1;
3067 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3068 wpa_s->manual_scan_use_id) {
3069 wpa_msg_ctrl(wpa_s, MSG_INFO,
3070 WPA_EVENT_SCAN_STARTED "id=%u",
3071 wpa_s->manual_scan_id);
3073 wpa_msg_ctrl(wpa_s, MSG_INFO,
3074 WPA_EVENT_SCAN_STARTED);
3077 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3078 wpa_s->radio->external_scan_running = 1;
3079 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3082 case EVENT_SCAN_RESULTS:
3083 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3084 struct os_reltime now, diff;
3085 os_get_reltime(&now);
3086 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3087 wpa_s->scan_start_time.sec = 0;
3088 wpa_s->scan_start_time.usec = 0;
3089 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3090 diff.sec, diff.usec);
3092 wpa_supplicant_event_scan_results(wpa_s, data);
3093 wpa_s->own_scan_running = 0;
3094 wpa_s->radio->external_scan_running = 0;
3095 radio_work_check_next(wpa_s);
3097 #endif /* CONFIG_NO_SCAN_PROCESSING */
3098 case EVENT_ASSOCINFO:
3099 wpa_supplicant_event_associnfo(wpa_s, data);
3101 case EVENT_INTERFACE_STATUS:
3102 wpa_supplicant_event_interface_status(wpa_s, data);
3104 case EVENT_PMKID_CANDIDATE:
3105 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3107 #ifdef CONFIG_PEERKEY
3108 case EVENT_STKSTART:
3109 wpa_supplicant_event_stkstart(wpa_s, data);
3111 #endif /* CONFIG_PEERKEY */
3114 wpa_supplicant_event_tdls(wpa_s, data);
3116 #endif /* CONFIG_TDLS */
3119 wpa_supplicant_event_wnm(wpa_s, data);
3121 #endif /* CONFIG_WNM */
3122 #ifdef CONFIG_IEEE80211R
3123 case EVENT_FT_RESPONSE:
3124 wpa_supplicant_event_ft_response(wpa_s, data);
3126 #endif /* CONFIG_IEEE80211R */
3127 #ifdef CONFIG_IBSS_RSN
3128 case EVENT_IBSS_RSN_START:
3129 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3131 #endif /* CONFIG_IBSS_RSN */
3132 case EVENT_ASSOC_REJECT:
3133 if (data->assoc_reject.bssid)
3134 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3135 "bssid=" MACSTR " status_code=%u",
3136 MAC2STR(data->assoc_reject.bssid),
3137 data->assoc_reject.status_code);
3139 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3141 data->assoc_reject.status_code);
3142 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3143 sme_event_assoc_reject(wpa_s, data);
3145 const u8 *bssid = data->assoc_reject.bssid;
3146 if (bssid == NULL || is_zero_ether_addr(bssid))
3147 bssid = wpa_s->pending_bssid;
3148 wpas_connection_failed(wpa_s, bssid);
3149 wpa_supplicant_mark_disassoc(wpa_s);
3152 case EVENT_AUTH_TIMED_OUT:
3153 /* It is possible to get this event from earlier connection */
3154 if (wpa_s->current_ssid &&
3155 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3156 wpa_dbg(wpa_s, MSG_DEBUG,
3157 "Ignore AUTH_TIMED_OUT in mesh configuration");
3160 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3161 sme_event_auth_timed_out(wpa_s, data);
3163 case EVENT_ASSOC_TIMED_OUT:
3164 /* It is possible to get this event from earlier connection */
3165 if (wpa_s->current_ssid &&
3166 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3167 wpa_dbg(wpa_s, MSG_DEBUG,
3168 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3171 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3172 sme_event_assoc_timed_out(wpa_s, data);
3174 case EVENT_TX_STATUS:
3175 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3176 " type=%d stype=%d",
3177 MAC2STR(data->tx_status.dst),
3178 data->tx_status.type, data->tx_status.stype);
3180 if (wpa_s->ap_iface == NULL) {
3181 #ifdef CONFIG_OFFCHANNEL
3182 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3183 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3184 offchannel_send_action_tx_status(
3185 wpa_s, data->tx_status.dst,
3186 data->tx_status.data,
3187 data->tx_status.data_len,
3188 data->tx_status.ack ?
3189 OFFCHANNEL_SEND_ACTION_SUCCESS :
3190 OFFCHANNEL_SEND_ACTION_NO_ACK);
3191 #endif /* CONFIG_OFFCHANNEL */
3194 #endif /* CONFIG_AP */
3195 #ifdef CONFIG_OFFCHANNEL
3196 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3197 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3199 * Catch TX status events for Action frames we sent via group
3200 * interface in GO mode.
3202 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3203 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3204 os_memcmp(wpa_s->parent->pending_action_dst,
3205 data->tx_status.dst, ETH_ALEN) == 0) {
3206 offchannel_send_action_tx_status(
3207 wpa_s->parent, data->tx_status.dst,
3208 data->tx_status.data,
3209 data->tx_status.data_len,
3210 data->tx_status.ack ?
3211 OFFCHANNEL_SEND_ACTION_SUCCESS :
3212 OFFCHANNEL_SEND_ACTION_NO_ACK);
3215 #endif /* CONFIG_OFFCHANNEL */
3217 switch (data->tx_status.type) {
3218 case WLAN_FC_TYPE_MGMT:
3219 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3220 data->tx_status.data_len,
3221 data->tx_status.stype,
3222 data->tx_status.ack);
3224 case WLAN_FC_TYPE_DATA:
3225 ap_tx_status(wpa_s, data->tx_status.dst,
3226 data->tx_status.data,
3227 data->tx_status.data_len,
3228 data->tx_status.ack);
3231 #endif /* CONFIG_AP */
3234 case EVENT_EAPOL_TX_STATUS:
3235 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3236 data->eapol_tx_status.data,
3237 data->eapol_tx_status.data_len,
3238 data->eapol_tx_status.ack);
3240 case EVENT_DRIVER_CLIENT_POLL_OK:
3241 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3243 case EVENT_RX_FROM_UNKNOWN:
3244 if (wpa_s->ap_iface == NULL)
3246 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3247 data->rx_from_unknown.wds);
3249 case EVENT_CH_SWITCH:
3252 if (!wpa_s->ap_iface) {
3253 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3254 "event in non-AP mode");
3258 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3259 data->ch_switch.ht_enabled,
3260 data->ch_switch.ch_offset,
3261 data->ch_switch.ch_width,
3262 data->ch_switch.cf1,
3263 data->ch_switch.cf2);
3265 #endif /* CONFIG_AP */
3266 case EVENT_RX_MGMT: {
3268 const struct ieee80211_mgmt *mgmt;
3270 #ifdef CONFIG_TESTING_OPTIONS
3271 if (wpa_s->ext_mgmt_frame_handling) {
3272 struct rx_mgmt *rx = &data->rx_mgmt;
3273 size_t hex_len = 2 * rx->frame_len + 1;
3274 char *hex = os_malloc(hex_len);
3276 wpa_snprintf_hex(hex, hex_len,
3277 rx->frame, rx->frame_len);
3278 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3279 rx->freq, rx->datarate, rx->ssi_signal,
3285 #endif /* CONFIG_TESTING_OPTIONS */
3287 mgmt = (const struct ieee80211_mgmt *)
3288 data->rx_mgmt.frame;
3289 fc = le_to_host16(mgmt->frame_control);
3290 stype = WLAN_FC_GET_STYPE(fc);
3293 if (wpa_s->ap_iface == NULL) {
3294 #endif /* CONFIG_AP */
3296 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3297 data->rx_mgmt.frame_len > 24) {
3298 const u8 *src = mgmt->sa;
3299 const u8 *ie = mgmt->u.probe_req.variable;
3300 size_t ie_len = data->rx_mgmt.frame_len -
3301 (mgmt->u.probe_req.variable -
3302 data->rx_mgmt.frame);
3303 wpas_p2p_probe_req_rx(
3304 wpa_s, src, mgmt->da,
3305 mgmt->bssid, ie, ie_len,
3306 data->rx_mgmt.ssi_signal);
3309 #endif /* CONFIG_P2P */
3310 #ifdef CONFIG_IBSS_RSN
3311 if (wpa_s->current_ssid &&
3312 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3313 stype == WLAN_FC_STYPE_AUTH &&
3314 data->rx_mgmt.frame_len >= 30) {
3315 wpa_supplicant_event_ibss_auth(wpa_s, data);
3318 #endif /* CONFIG_IBSS_RSN */
3320 if (stype == WLAN_FC_STYPE_ACTION) {
3321 wpas_event_rx_mgmt_action(
3322 wpa_s, data->rx_mgmt.frame,
3323 data->rx_mgmt.frame_len,
3325 data->rx_mgmt.ssi_signal);
3330 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3334 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3335 "management frame in non-AP mode");
3340 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3341 data->rx_mgmt.frame_len > 24) {
3342 const u8 *ie = mgmt->u.probe_req.variable;
3343 size_t ie_len = data->rx_mgmt.frame_len -
3344 (mgmt->u.probe_req.variable -
3345 data->rx_mgmt.frame);
3347 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3348 mgmt->bssid, ie, ie_len,
3349 data->rx_mgmt.ssi_signal);
3352 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3353 #endif /* CONFIG_AP */
3356 case EVENT_RX_PROBE_REQ:
3357 if (data->rx_probe_req.sa == NULL ||
3358 data->rx_probe_req.ie == NULL)
3361 if (wpa_s->ap_iface) {
3362 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3363 data->rx_probe_req.sa,
3364 data->rx_probe_req.da,
3365 data->rx_probe_req.bssid,
3366 data->rx_probe_req.ie,
3367 data->rx_probe_req.ie_len,
3368 data->rx_probe_req.ssi_signal);
3371 #endif /* CONFIG_AP */
3372 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3373 data->rx_probe_req.da,
3374 data->rx_probe_req.bssid,
3375 data->rx_probe_req.ie,
3376 data->rx_probe_req.ie_len,
3377 data->rx_probe_req.ssi_signal);
3379 case EVENT_REMAIN_ON_CHANNEL:
3380 #ifdef CONFIG_OFFCHANNEL
3381 offchannel_remain_on_channel_cb(
3382 wpa_s, data->remain_on_channel.freq,
3383 data->remain_on_channel.duration);
3384 #endif /* CONFIG_OFFCHANNEL */
3385 wpas_p2p_remain_on_channel_cb(
3386 wpa_s, data->remain_on_channel.freq,
3387 data->remain_on_channel.duration);
3389 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3390 #ifdef CONFIG_OFFCHANNEL
3391 offchannel_cancel_remain_on_channel_cb(
3392 wpa_s, data->remain_on_channel.freq);
3393 #endif /* CONFIG_OFFCHANNEL */
3394 wpas_p2p_cancel_remain_on_channel_cb(
3395 wpa_s, data->remain_on_channel.freq);
3397 case EVENT_EAPOL_RX:
3398 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3399 data->eapol_rx.data,
3400 data->eapol_rx.data_len);
3402 case EVENT_SIGNAL_CHANGE:
3403 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3404 "above=%d signal=%d noise=%d txrate=%d",
3405 data->signal_change.above_threshold,
3406 data->signal_change.current_signal,
3407 data->signal_change.current_noise,
3408 data->signal_change.current_txrate);
3409 bgscan_notify_signal_change(
3410 wpa_s, data->signal_change.above_threshold,
3411 data->signal_change.current_signal,
3412 data->signal_change.current_noise,
3413 data->signal_change.current_txrate);
3415 case EVENT_INTERFACE_ENABLED:
3416 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3417 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3418 wpa_supplicant_update_mac_addr(wpa_s);
3419 if (wpa_s->p2p_mgmt) {
3420 wpa_supplicant_set_state(wpa_s,
3426 if (!wpa_s->ap_iface) {
3427 wpa_supplicant_set_state(wpa_s,
3429 wpa_s->scan_req = NORMAL_SCAN_REQ;
3430 wpa_supplicant_req_scan(wpa_s, 0, 0);
3432 wpa_supplicant_set_state(wpa_s,
3434 #else /* CONFIG_AP */
3435 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3436 wpa_supplicant_req_scan(wpa_s, 0, 0);
3437 #endif /* CONFIG_AP */
3440 case EVENT_INTERFACE_DISABLED:
3441 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3443 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3444 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3445 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3447 * Mark interface disabled if this happens to end up not
3448 * being removed as a separate P2P group interface.
3450 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3452 * The interface was externally disabled. Remove
3453 * it assuming an external entity will start a
3454 * new session if needed.
3456 if (wpa_s->current_ssid &&
3457 wpa_s->current_ssid->p2p_group)
3458 wpas_p2p_interface_unavailable(wpa_s);
3460 wpas_p2p_disconnect(wpa_s);
3462 * wpa_s instance may have been freed, so must not use
3467 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3468 p2p_in_progress(wpa_s->global->p2p) > 1) {
3469 /* This radio work will be cancelled, so clear P2P
3472 p2p_stop_find(wpa_s->global->p2p);
3474 #endif /* CONFIG_P2P */
3476 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3478 * Indicate disconnection to keep ctrl_iface events
3481 wpa_supplicant_event_disassoc(
3482 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3484 wpa_supplicant_mark_disassoc(wpa_s);
3485 radio_remove_works(wpa_s, NULL, 0);
3487 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3489 case EVENT_CHANNEL_LIST_CHANGED:
3490 wpa_supplicant_update_channel_list(
3491 wpa_s, &data->channel_list_changed);
3493 case EVENT_INTERFACE_UNAVAILABLE:
3494 wpas_p2p_interface_unavailable(wpa_s);
3496 case EVENT_BEST_CHANNEL:
3497 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3499 data->best_chan.freq_24, data->best_chan.freq_5,
3500 data->best_chan.freq_overall);
3501 wpa_s->best_24_freq = data->best_chan.freq_24;
3502 wpa_s->best_5_freq = data->best_chan.freq_5;
3503 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3504 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3505 data->best_chan.freq_5,
3506 data->best_chan.freq_overall);
3508 case EVENT_UNPROT_DEAUTH:
3509 wpa_supplicant_event_unprot_deauth(wpa_s,
3510 &data->unprot_deauth);
3512 case EVENT_UNPROT_DISASSOC:
3513 wpa_supplicant_event_unprot_disassoc(wpa_s,
3514 &data->unprot_disassoc);
3516 case EVENT_STATION_LOW_ACK:
3518 if (wpa_s->ap_iface && data)
3519 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3520 data->low_ack.addr);
3521 #endif /* CONFIG_AP */
3524 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3525 data->low_ack.addr);
3526 #endif /* CONFIG_TDLS */
3528 case EVENT_IBSS_PEER_LOST:
3529 #ifdef CONFIG_IBSS_RSN
3530 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3531 #endif /* CONFIG_IBSS_RSN */
3533 case EVENT_DRIVER_GTK_REKEY:
3534 if (os_memcmp(data->driver_gtk_rekey.bssid,
3535 wpa_s->bssid, ETH_ALEN))
3539 wpa_sm_update_replay_ctr(wpa_s->wpa,
3540 data->driver_gtk_rekey.replay_ctr);
3542 case EVENT_SCHED_SCAN_STOPPED:
3544 wpa_s->sched_scanning = 0;
3545 wpa_supplicant_notify_scanning(wpa_s, 0);
3547 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3551 * Start a new sched scan to continue searching for more SSIDs
3552 * either if timed out or PNO schedule scan is pending.
3554 if (wpa_s->sched_scan_timed_out) {
3555 wpa_supplicant_req_sched_scan(wpa_s);
3556 } else if (wpa_s->pno_sched_pending) {
3557 wpa_s->pno_sched_pending = 0;
3558 wpas_start_pno(wpa_s);
3562 case EVENT_WPS_BUTTON_PUSHED:
3564 wpas_wps_start_pbc(wpa_s, NULL, 0);
3565 #endif /* CONFIG_WPS */
3567 case EVENT_AVOID_FREQUENCIES:
3568 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3570 case EVENT_CONNECT_FAILED_REASON:
3572 if (!wpa_s->ap_iface || !data)
3574 hostapd_event_connect_failed_reason(
3575 wpa_s->ap_iface->bss[0],
3576 data->connect_failed_reason.addr,
3577 data->connect_failed_reason.code);
3578 #endif /* CONFIG_AP */
3580 case EVENT_NEW_PEER_CANDIDATE:
3582 if (!wpa_s->ifmsh || !data)
3584 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3585 data->mesh_peer.ies,
3586 data->mesh_peer.ie_len);
3587 #endif /* CONFIG_MESH */
3590 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);