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);
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 wpas_get_ssid_pmf(wpa_s, ssid) ==
480 MGMT_FRAME_PROTECTION_REQUIRED) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
485 #endif /* CONFIG_IEEE80211W */
487 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
491 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
492 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
495 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
502 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
504 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
509 if (!(ie.proto & ssid->proto)) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
515 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
516 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
521 if (!(ie.group_cipher & ssid->group_cipher)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
527 if (!(ie.key_mgmt & ssid->key_mgmt)) {
528 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
533 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
537 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
539 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
543 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
544 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
545 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
549 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
550 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
551 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
555 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
560 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
567 static int freq_allowed(int *freqs, int freq)
574 for (i = 0; freqs[i]; i++)
575 if (freqs[i] == freq)
581 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
583 const struct hostapd_hw_modes *mode = NULL, *modes;
584 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
589 return 1; /* Cannot do matching without knowing band */
591 modes = wpa_s->hw.modes;
594 * The driver does not provide any additional information
595 * about the utilized hardware, so allow the connection attempt
601 for (i = 0; i < wpa_s->hw.num_modes; i++) {
602 for (j = 0; j < modes[i].num_channels; j++) {
603 int freq = modes[i].channels[j].freq;
604 if (freq == bss->freq) {
606 mode->mode == HOSTAPD_MODE_IEEE80211G)
607 break; /* do not allow 802.11b replace
618 for (i = 0; i < (int) sizeof(scan_ie); i++) {
619 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
623 for (j = 2; j < rate_ie[1] + 2; j++) {
624 int flagged = !!(rate_ie[j] & 0x80);
625 int r = (rate_ie[j] & 0x7f) * 5;
628 * IEEE Std 802.11n-2009 7.3.2.2:
629 * The new BSS Membership selector value is encoded
630 * like a legacy basic rate, but it is not a rate and
631 * only indicates if the BSS members are required to
632 * support the mandatory features of Clause 20 [HT PHY]
633 * in order to join the BSS.
635 if (flagged && ((rate_ie[j] & 0x7f) ==
636 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
637 if (!ht_supported(mode)) {
638 wpa_dbg(wpa_s, MSG_DEBUG,
639 " hardware does not support "
646 /* There's also a VHT selector for 802.11ac */
647 if (flagged && ((rate_ie[j] & 0x7f) ==
648 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
649 if (!vht_supported(mode)) {
650 wpa_dbg(wpa_s, MSG_DEBUG,
651 " hardware does not support "
661 /* check for legacy basic rates */
662 for (k = 0; k < mode->num_rates; k++) {
663 if (mode->rates[k] == r)
666 if (k == mode->num_rates) {
668 * IEEE Std 802.11-2007 7.3.2.2 demands that in
669 * order to join a BSS all required rates
670 * have to be supported by the hardware.
672 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
673 "not support required rate %d.%d Mbps",
685 * Test whether BSS is in an ESS.
686 * This is done differently in DMG (60 GHz) and non-DMG bands
688 static int bss_is_ess(struct wpa_bss *bss)
690 if (bss_is_dmg(bss)) {
691 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
692 IEEE80211_CAP_DMG_AP;
695 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
700 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
704 for (i = 0; i < ETH_ALEN; i++) {
705 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
712 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
716 for (i = 0; i < num; i++) {
717 const u8 *a = list + i * ETH_ALEN * 2;
718 const u8 *m = a + ETH_ALEN;
720 if (match_mac_mask(a, addr, m))
727 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
728 int i, struct wpa_bss *bss,
729 struct wpa_ssid *group,
732 u8 wpa_ie_len, rsn_ie_len;
734 struct wpa_blacklist *e;
736 struct wpa_ssid *ssid;
739 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
740 wpa_ie_len = ie ? ie[1] : 0;
742 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
743 rsn_ie_len = ie ? ie[1] : 0;
745 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
748 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
749 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
750 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
751 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
752 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
753 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
754 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
756 osen ? " osen=1" : "");
758 e = wpa_blacklist_get(wpa_s, bss->bssid);
761 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
763 * When only a single network is enabled, we can
764 * trigger blacklisting on the first failure. This
765 * should not be done with multiple enabled networks to
766 * avoid getting forced to move into a worse ESS on
767 * single error if there are no other BSSes of the
772 if (e->count > limit) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
774 "(count=%d limit=%d)", e->count, limit);
779 if (bss->ssid_len == 0) {
780 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
784 if (disallowed_bssid(wpa_s, bss->bssid)) {
785 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
789 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
794 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
796 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
797 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
800 if (wpas_network_disabled(wpa_s, ssid)) {
801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
805 res = wpas_temp_disabled(wpa_s, ssid);
807 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
808 "temporarily for %d second(s)", res);
813 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
814 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
819 if (wpa && ssid->ssid_len == 0 &&
820 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
823 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
824 /* Only allow wildcard SSID match if an AP
825 * advertises active WPS operation that matches
828 if (ssid->ssid_len == 0 &&
829 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
832 #endif /* CONFIG_WPS */
834 if (ssid->bssid_set && ssid->ssid_len == 0 &&
835 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
839 (bss->ssid_len != ssid->ssid_len ||
840 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
841 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
845 if (ssid->bssid_set &&
846 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
847 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
851 /* check blacklist */
852 if (ssid->num_bssid_blacklist &&
853 addr_in_list(bss->bssid, ssid->bssid_blacklist,
854 ssid->num_bssid_blacklist)) {
855 wpa_dbg(wpa_s, MSG_DEBUG,
856 " skip - BSSID blacklisted");
860 /* if there is a whitelist, only accept those APs */
861 if (ssid->num_bssid_whitelist &&
862 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
863 ssid->num_bssid_whitelist)) {
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip - BSSID not in whitelist");
869 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
873 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
874 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
875 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
876 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
881 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
887 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
888 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
893 if (!wpa_supplicant_match_privacy(bss, ssid)) {
894 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
899 if (!bss_is_ess(bss)) {
900 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
904 if (!freq_allowed(ssid->freq_list, bss->freq)) {
905 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
910 if (!rate_match(wpa_s, bss)) {
911 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
917 if (ssid->p2p_group &&
918 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
919 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
920 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
924 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
925 struct wpabuf *p2p_ie;
926 u8 dev_addr[ETH_ALEN];
928 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
933 p2p_ie = wpa_bss_get_vendor_ie_multi(
934 bss, P2P_IE_VENDOR_TYPE);
935 if (p2p_ie == NULL) {
936 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
940 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
941 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
943 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
951 * TODO: skip the AP if its P2P IE has Group Formation
952 * bit set in the P2P Group Capability Bitmap and we
953 * are not in Group Formation with that device.
955 #endif /* CONFIG_P2P */
957 /* Matching configuration found */
961 /* No matching configuration found */
966 static struct wpa_bss *
967 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
968 struct wpa_ssid *group,
969 struct wpa_ssid **selected_ssid,
975 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
978 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
981 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
982 struct wpa_bss *bss = wpa_s->last_scan_res[i];
983 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
987 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
990 wpa_ssid_txt(bss->ssid, bss->ssid_len));
998 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
999 struct wpa_ssid **selected_ssid)
1001 struct wpa_bss *selected = NULL;
1003 struct wpa_ssid *next_ssid = NULL;
1005 if (wpa_s->last_scan_res == NULL ||
1006 wpa_s->last_scan_res_used == 0)
1007 return NULL; /* no scan results from last update */
1009 if (wpa_s->next_ssid) {
1010 struct wpa_ssid *ssid;
1012 /* check that next_ssid is still valid */
1013 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1014 if (ssid == wpa_s->next_ssid)
1018 wpa_s->next_ssid = NULL;
1021 while (selected == NULL) {
1022 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1023 if (next_ssid && next_ssid->priority ==
1024 wpa_s->conf->pssid[prio]->priority) {
1025 selected = wpa_supplicant_select_bss(
1026 wpa_s, next_ssid, selected_ssid, 1);
1030 selected = wpa_supplicant_select_bss(
1031 wpa_s, wpa_s->conf->pssid[prio],
1037 if (selected == NULL && wpa_s->blacklist &&
1038 !wpa_s->countermeasures) {
1039 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1040 "blacklist and try again");
1041 wpa_blacklist_clear(wpa_s);
1042 wpa_s->blacklist_cleared++;
1043 } else if (selected == NULL)
1051 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1052 int timeout_sec, int timeout_usec)
1054 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1056 * No networks are enabled; short-circuit request so
1057 * we don't wait timeout seconds before transitioning
1058 * to INACTIVE state.
1060 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1061 "since there are no enabled networks");
1062 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1066 wpa_s->scan_for_connection = 1;
1067 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1071 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1072 struct wpa_bss *selected,
1073 struct wpa_ssid *ssid)
1075 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1076 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1077 "PBC session overlap");
1079 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1080 wpa_s->p2p_in_provisioning) {
1081 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1085 #endif /* CONFIG_P2P */
1088 wpas_wps_cancel(wpa_s);
1089 #endif /* CONFIG_WPS */
1093 wpa_msg(wpa_s, MSG_DEBUG,
1094 "Considering connect request: reassociate: %d selected: "
1095 MACSTR " bssid: " MACSTR " pending: " MACSTR
1096 " wpa_state: %s ssid=%p current_ssid=%p",
1097 wpa_s->reassociate, MAC2STR(selected->bssid),
1098 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1099 wpa_supplicant_state_txt(wpa_s->wpa_state),
1100 ssid, wpa_s->current_ssid);
1103 * Do not trigger new association unless the BSSID has changed or if
1104 * reassociation is requested. If we are in process of associating with
1105 * the selected BSSID, do not trigger new attempt.
1107 if (wpa_s->reassociate ||
1108 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1109 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1110 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1111 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1112 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1114 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1115 ssid != wpa_s->current_ssid)))) {
1116 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1117 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1120 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1121 MAC2STR(selected->bssid));
1122 wpa_supplicant_associate(wpa_s, selected, ssid);
1124 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1125 "connect with the selected AP");
1132 static struct wpa_ssid *
1133 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1136 struct wpa_ssid *ssid;
1138 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1139 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1141 if (wpas_network_disabled(wpa_s, ssid))
1143 if (ssid->mode == IEEE80211_MODE_IBSS ||
1144 ssid->mode == IEEE80211_MODE_AP ||
1145 ssid->mode == IEEE80211_MODE_MESH)
1153 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1154 * on BSS added and BSS changed events */
1155 static void wpa_supplicant_rsn_preauth_scan_results(
1156 struct wpa_supplicant *wpa_s)
1158 struct wpa_bss *bss;
1160 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1163 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1164 const u8 *ssid, *rsn;
1166 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1170 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1174 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1180 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1181 struct wpa_bss *selected,
1182 struct wpa_ssid *ssid)
1184 struct wpa_bss *current_bss = NULL;
1187 if (wpa_s->reassociate)
1188 return 1; /* explicit request to reassociate */
1189 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1190 return 1; /* we are not associated; continue */
1191 if (wpa_s->current_ssid == NULL)
1192 return 1; /* unknown current SSID */
1193 if (wpa_s->current_ssid != ssid)
1194 return 1; /* different network block */
1196 if (wpas_driver_bss_selection(wpa_s))
1197 return 0; /* Driver-based roaming */
1199 if (wpa_s->current_ssid->ssid)
1200 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1201 wpa_s->current_ssid->ssid,
1202 wpa_s->current_ssid->ssid_len);
1204 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1207 return 1; /* current BSS not seen in scan results */
1209 if (current_bss == selected)
1212 if (selected->last_update_idx > current_bss->last_update_idx)
1213 return 1; /* current BSS not seen in the last scan */
1215 #ifndef CONFIG_NO_ROAMING
1216 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1217 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1218 MAC2STR(current_bss->bssid), current_bss->level);
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1220 MAC2STR(selected->bssid), selected->level);
1222 if (wpa_s->current_ssid->bssid_set &&
1223 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1226 "has preferred BSSID");
1230 if (current_bss->level < 0 && current_bss->level > selected->level) {
1231 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1237 if (current_bss->level < 0) {
1238 if (current_bss->level < -85)
1240 else if (current_bss->level < -80)
1242 else if (current_bss->level < -75)
1244 else if (current_bss->level < -70)
1249 if (abs(current_bss->level - selected->level) < min_diff) {
1250 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1256 #else /* CONFIG_NO_ROAMING */
1258 #endif /* CONFIG_NO_ROAMING */
1262 /* Return != 0 if no scan results could be fetched or if scan results should not
1263 * be shared with other virtual interfaces. */
1264 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1265 union wpa_event_data *data,
1268 struct wpa_scan_results *scan_res = NULL;
1271 #ifndef CONFIG_NO_RANDOM_POOL
1273 #endif /* CONFIG_NO_RANDOM_POOL */
1276 if (wpa_s->ap_iface)
1278 #endif /* CONFIG_AP */
1280 wpa_supplicant_notify_scanning(wpa_s, 0);
1282 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1283 data ? &data->scan_info :
1285 if (scan_res == NULL) {
1286 if (wpa_s->conf->ap_scan == 2 || ap ||
1287 wpa_s->scan_res_handler == scan_only_handler)
1291 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1293 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1295 goto scan_work_done;
1298 #ifndef CONFIG_NO_RANDOM_POOL
1299 num = scan_res->num;
1302 for (i = 0; i < num; i++) {
1304 struct wpa_scan_res *res = scan_res->res[i];
1305 buf[0] = res->bssid[5];
1306 buf[1] = res->qual & 0xff;
1307 buf[2] = res->noise & 0xff;
1308 buf[3] = res->level & 0xff;
1309 buf[4] = res->tsf & 0xff;
1310 random_add_randomness(buf, sizeof(buf));
1312 #endif /* CONFIG_NO_RANDOM_POOL */
1314 if (own_request && wpa_s->scan_res_handler &&
1315 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1316 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1317 struct wpa_scan_results *scan_res);
1319 scan_res_handler = wpa_s->scan_res_handler;
1320 wpa_s->scan_res_handler = NULL;
1321 scan_res_handler(wpa_s, scan_res);
1323 goto scan_work_done;
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1329 if (wpa_s->ap_iface->scan_cb)
1330 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1331 #endif /* CONFIG_AP */
1332 goto scan_work_done;
1335 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1336 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1337 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1338 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1339 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1340 wpa_s->manual_scan_id);
1341 wpa_s->manual_scan_use_id = 0;
1343 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1345 wpas_notify_scan_results(wpa_s);
1347 wpas_notify_scan_done(wpa_s, 1);
1349 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1350 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1351 wpa_scan_results_free(scan_res);
1355 if (wnm_scan_process(wpa_s, 1) > 0)
1356 goto scan_work_done;
1358 if (sme_proc_obss_scan(wpa_s) > 0)
1359 goto scan_work_done;
1361 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1362 goto scan_work_done;
1364 if (autoscan_notify_scan(wpa_s, scan_res))
1365 goto scan_work_done;
1367 if (wpa_s->disconnected) {
1368 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1369 goto scan_work_done;
1372 if (!wpas_driver_bss_selection(wpa_s) &&
1373 bgscan_notify_scan(wpa_s, scan_res) == 1)
1374 goto scan_work_done;
1376 wpas_wps_update_ap_info(wpa_s, scan_res);
1378 wpa_scan_results_free(scan_res);
1380 if (wpa_s->scan_work) {
1381 struct wpa_radio_work *work = wpa_s->scan_work;
1382 wpa_s->scan_work = NULL;
1383 radio_work_done(work);
1386 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1389 wpa_scan_results_free(scan_res);
1390 if (wpa_s->scan_work) {
1391 struct wpa_radio_work *work = wpa_s->scan_work;
1392 wpa_s->scan_work = NULL;
1393 radio_work_done(work);
1399 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1400 int new_scan, int own_request)
1402 struct wpa_bss *selected;
1403 struct wpa_ssid *ssid = NULL;
1405 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1409 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1412 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1416 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1421 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1423 * Do not notify other virtual radios of scan results since we do not
1424 * want them to start other associations at the same time.
1430 wpa_msg(wpa_s, MSG_INFO,
1431 "Avoiding join because we already joined a mesh group");
1434 #endif /* CONFIG_MESH */
1435 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1436 ssid = wpa_supplicant_pick_new_network(wpa_s);
1438 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1439 wpa_supplicant_associate(wpa_s, NULL, ssid);
1441 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1442 } else if (own_request) {
1444 * No SSID found. If SCAN results are as a result of
1445 * own scan request and not due to a scan request on
1446 * another shared interface, try another scan.
1448 int timeout_sec = wpa_s->scan_interval;
1449 int timeout_usec = 0;
1453 res = wpas_p2p_scan_no_go_seen(wpa_s);
1459 if (wpa_s->p2p_in_provisioning ||
1460 wpa_s->show_group_started ||
1461 wpa_s->p2p_in_invitation) {
1463 * Use shorter wait during P2P Provisioning
1464 * state and during P2P join-a-group operation
1465 * to speed up group formation.
1468 timeout_usec = 250000;
1469 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1473 #endif /* CONFIG_P2P */
1474 #ifdef CONFIG_INTERWORKING
1475 if (wpa_s->conf->auto_interworking &&
1476 wpa_s->conf->interworking &&
1477 wpa_s->conf->cred) {
1478 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1479 "start ANQP fetch since no matching "
1481 wpa_s->network_select = 1;
1482 wpa_s->auto_network_select = 1;
1483 interworking_start_fetch_anqp(wpa_s);
1486 #endif /* CONFIG_INTERWORKING */
1488 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1489 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1491 timeout_usec = 500000;
1492 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1496 #endif /* CONFIG_WPS */
1497 if (wpa_supplicant_req_sched_scan(wpa_s))
1498 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1506 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1507 union wpa_event_data *data)
1509 struct wpa_supplicant *ifs;
1512 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1515 * Interface may have been removed, so must not dereference
1522 * If no scan results could be fetched, then no need to
1523 * notify those interfaces that did not actually request
1524 * this scan. Similarly, if scan results started a new operation on this
1525 * interface, do not notify other interfaces to avoid concurrent
1526 * operations during a connection attempt.
1532 * Check other interfaces to see if they share the same radio. If
1533 * so, they get updated with this same scan info.
1535 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1538 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1539 "sibling", ifs->ifname);
1540 _wpa_supplicant_event_scan_results(ifs, data, 0);
1547 #endif /* CONFIG_NO_SCAN_PROCESSING */
1550 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1552 #ifdef CONFIG_NO_SCAN_PROCESSING
1554 #else /* CONFIG_NO_SCAN_PROCESSING */
1555 struct os_reltime now;
1557 if (wpa_s->last_scan_res_used <= 0)
1560 os_get_reltime(&now);
1561 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1562 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1566 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1567 #endif /* CONFIG_NO_SCAN_PROCESSING */
1572 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1574 struct wpa_supplicant *wpa_s = eloop_ctx;
1576 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1579 if (!wpa_s->no_keep_alive) {
1580 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1581 MAC2STR(wpa_s->bssid));
1582 /* TODO: could skip this if normal data traffic has been sent */
1583 /* TODO: Consider using some more appropriate data frame for
1586 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1591 if (wpa_s->sme.bss_max_idle_period) {
1593 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1596 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1597 wnm_bss_keep_alive, wpa_s, NULL);
1599 #endif /* CONFIG_SME */
1603 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1604 const u8 *ies, size_t ies_len)
1606 struct ieee802_11_elems elems;
1611 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1615 if (elems.bss_max_idle_period) {
1617 wpa_s->sme.bss_max_idle_period =
1618 WPA_GET_LE16(elems.bss_max_idle_period);
1619 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1620 "TU)%s", wpa_s->sme.bss_max_idle_period,
1621 (elems.bss_max_idle_period[2] & 0x01) ?
1622 " (protected keep-live required)" : "");
1623 if (wpa_s->sme.bss_max_idle_period == 0)
1624 wpa_s->sme.bss_max_idle_period = 1;
1625 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1626 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1627 /* msec times 1000 */
1628 msec = wpa_s->sme.bss_max_idle_period * 1024;
1631 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1632 wnm_bss_keep_alive, wpa_s,
1636 #endif /* CONFIG_SME */
1639 #endif /* CONFIG_WNM */
1642 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1645 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1646 #endif /* CONFIG_WNM */
1650 #ifdef CONFIG_INTERWORKING
1652 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1657 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1658 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1660 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1667 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1668 const u8 *ies, size_t ies_len)
1670 struct ieee802_11_elems elems;
1675 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1678 if (elems.qos_map_set) {
1679 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1680 elems.qos_map_set_len);
1684 #endif /* CONFIG_INTERWORKING */
1687 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1688 union wpa_event_data *data)
1690 int l, len, found = 0, wpa_found, rsn_found;
1692 #ifdef CONFIG_IEEE80211R
1694 #endif /* CONFIG_IEEE80211R */
1696 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1697 if (data->assoc_info.req_ies)
1698 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1699 data->assoc_info.req_ies_len);
1700 if (data->assoc_info.resp_ies) {
1701 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1702 data->assoc_info.resp_ies_len);
1704 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1705 data->assoc_info.resp_ies_len);
1706 #endif /* CONFIG_TDLS */
1708 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1709 data->assoc_info.resp_ies_len);
1710 #endif /* CONFIG_WNM */
1711 #ifdef CONFIG_INTERWORKING
1712 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1713 data->assoc_info.resp_ies_len);
1714 #endif /* CONFIG_INTERWORKING */
1716 if (data->assoc_info.beacon_ies)
1717 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1718 data->assoc_info.beacon_ies,
1719 data->assoc_info.beacon_ies_len);
1720 if (data->assoc_info.freq)
1721 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1722 data->assoc_info.freq);
1724 p = data->assoc_info.req_ies;
1725 l = data->assoc_info.req_ies_len;
1727 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1728 while (p && l >= 2) {
1731 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1735 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1736 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1737 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1738 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1741 wpa_find_assoc_pmkid(wpa_s);
1747 if (!found && data->assoc_info.req_ies)
1748 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1750 #ifdef CONFIG_IEEE80211R
1752 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1753 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1754 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1755 data->assoc_info.resp_ies,
1756 data->assoc_info.resp_ies_len,
1758 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1759 "Reassociation Response failed");
1760 wpa_supplicant_deauthenticate(
1761 wpa_s, WLAN_REASON_INVALID_IE);
1766 p = data->assoc_info.resp_ies;
1767 l = data->assoc_info.resp_ies_len;
1769 #ifdef CONFIG_WPS_STRICT
1770 if (p && wpa_s->current_ssid &&
1771 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1773 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1775 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1776 "include WPS IE in (Re)Association Response");
1780 if (wps_validate_assoc_resp(wps) < 0) {
1782 wpa_supplicant_deauthenticate(
1783 wpa_s, WLAN_REASON_INVALID_IE);
1788 #endif /* CONFIG_WPS_STRICT */
1790 /* Go through the IEs and make a copy of the MDIE, if present. */
1791 while (p && l >= 2) {
1794 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1798 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1799 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1800 wpa_s->sme.ft_used = 1;
1801 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1802 MOBILITY_DOMAIN_ID_LEN);
1808 #endif /* CONFIG_SME */
1810 /* Process FT when SME is in the driver */
1811 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1812 wpa_ft_is_completed(wpa_s->wpa)) {
1813 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1814 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1815 data->assoc_info.resp_ies,
1816 data->assoc_info.resp_ies_len,
1818 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1819 "Reassociation Response failed");
1820 wpa_supplicant_deauthenticate(
1821 wpa_s, WLAN_REASON_INVALID_IE);
1824 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1827 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1828 data->assoc_info.resp_ies_len);
1829 #endif /* CONFIG_IEEE80211R */
1831 /* WPA/RSN IE from Beacon/ProbeResp */
1832 p = data->assoc_info.beacon_ies;
1833 l = data->assoc_info.beacon_ies_len;
1835 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1837 wpa_found = rsn_found = 0;
1838 while (p && l >= 2) {
1841 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1846 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1847 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1849 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1853 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1855 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1862 if (!wpa_found && data->assoc_info.beacon_ies)
1863 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1864 if (!rsn_found && data->assoc_info.beacon_ies)
1865 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1866 if (wpa_found || rsn_found)
1867 wpa_s->ap_ies_from_associnfo = 1;
1869 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1870 wpa_s->assoc_freq != data->assoc_info.freq) {
1871 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1873 wpa_s->assoc_freq, data->assoc_info.freq);
1874 wpa_supplicant_update_scan_results(wpa_s);
1877 wpa_s->assoc_freq = data->assoc_info.freq;
1883 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1885 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1887 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1890 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1893 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1894 WPA_IE_VENDOR_TYPE);
1895 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1897 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1898 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1899 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1900 bss_rsn ? 2 + bss_rsn[1] : 0))
1907 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1908 union wpa_event_data *data)
1914 if (wpa_s->ap_iface) {
1917 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1918 data->assoc_info.addr,
1919 data->assoc_info.req_ies,
1920 data->assoc_info.req_ies_len,
1921 data->assoc_info.reassoc);
1924 #endif /* CONFIG_AP */
1926 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1927 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1930 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1931 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1932 wpa_supplicant_deauthenticate(
1933 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1937 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1938 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1939 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1940 MACSTR, MAC2STR(bssid));
1941 random_add_randomness(bssid, ETH_ALEN);
1942 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1943 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1944 wpas_notify_bssid_changed(wpa_s);
1946 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1947 wpa_clear_keys(wpa_s, bssid);
1949 if (wpa_supplicant_select_config(wpa_s) < 0) {
1950 wpa_supplicant_deauthenticate(
1951 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1955 if (wpa_s->conf->ap_scan == 1 &&
1956 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1957 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1958 wpa_msg(wpa_s, MSG_WARNING,
1959 "WPA/RSN IEs not updated");
1964 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1965 wpa_s->sme.prev_bssid_set = 1;
1966 wpa_s->sme.last_unprot_disconnect.sec = 0;
1967 #endif /* CONFIG_SME */
1969 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1970 if (wpa_s->current_ssid) {
1971 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1972 * initialized before association, but for other modes,
1973 * initialize PC/SC here, if the current configuration needs
1974 * smartcard or SIM/USIM. */
1975 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1977 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1979 l2_packet_notify_auth_start(wpa_s->l2);
1982 * Set portEnabled first to FALSE in order to get EAP state machine out
1983 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1984 * state machine may transit to AUTHENTICATING state based on obsolete
1985 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1986 * AUTHENTICATED without ever giving chance to EAP state machine to
1989 if (!ft_completed) {
1990 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1991 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1993 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1994 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1995 /* 802.1X::portControl = Auto */
1996 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1997 wpa_s->eapol_received = 0;
1998 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1999 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2000 (wpa_s->current_ssid &&
2001 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2002 if (wpa_s->current_ssid &&
2003 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2005 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2007 * Set the key after having received joined-IBSS event
2010 wpa_supplicant_set_wpa_none_key(wpa_s,
2011 wpa_s->current_ssid);
2013 wpa_supplicant_cancel_auth_timeout(wpa_s);
2014 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2015 } else if (!ft_completed) {
2016 /* Timeout for receiving the first EAPOL packet */
2017 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2019 wpa_supplicant_cancel_scan(wpa_s);
2021 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2022 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2024 * We are done; the driver will take care of RSN 4-way
2027 wpa_supplicant_cancel_auth_timeout(wpa_s);
2028 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2029 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2030 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2031 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2032 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2034 * The driver will take care of RSN 4-way handshake, so we need
2035 * to allow EAPOL supplicant to complete its work without
2036 * waiting for WPA supplicant.
2038 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2039 } else if (ft_completed) {
2041 * FT protocol completed - make sure EAPOL state machine ends
2042 * up in authenticated.
2044 wpa_supplicant_cancel_auth_timeout(wpa_s);
2045 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2046 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2047 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2050 wpa_s->last_eapol_matches_bssid = 0;
2052 if (wpa_s->pending_eapol_rx) {
2053 struct os_reltime now, age;
2054 os_get_reltime(&now);
2055 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2056 if (age.sec == 0 && age.usec < 100000 &&
2057 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2059 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2060 "frame that was received just before "
2061 "association notification");
2062 wpa_supplicant_rx_eapol(
2063 wpa_s, wpa_s->pending_eapol_rx_src,
2064 wpabuf_head(wpa_s->pending_eapol_rx),
2065 wpabuf_len(wpa_s->pending_eapol_rx));
2067 wpabuf_free(wpa_s->pending_eapol_rx);
2068 wpa_s->pending_eapol_rx = NULL;
2071 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2072 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2073 wpa_s->current_ssid &&
2074 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2075 /* Set static WEP keys again */
2076 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2079 #ifdef CONFIG_IBSS_RSN
2080 if (wpa_s->current_ssid &&
2081 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2082 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2083 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2084 wpa_s->ibss_rsn == NULL) {
2085 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2086 if (!wpa_s->ibss_rsn) {
2087 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2088 wpa_supplicant_deauthenticate(
2089 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2093 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2095 #endif /* CONFIG_IBSS_RSN */
2097 wpas_wps_notify_assoc(wpa_s, bssid);
2100 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2101 data->assoc_info.resp_ies_len,
2102 &data->assoc_info.wmm_params);
2104 if (wpa_s->reassoc_same_bss)
2105 wmm_ac_restore_tspecs(wpa_s);
2110 static int disconnect_reason_recoverable(u16 reason_code)
2112 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2113 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2114 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2118 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2120 int locally_generated)
2124 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2126 * At least Host AP driver and a Prism3 card seemed to be
2127 * generating streams of disconnected events when configuring
2128 * IBSS for WPA-None. Ignore them for now.
2133 bssid = wpa_s->bssid;
2134 if (is_zero_ether_addr(bssid))
2135 bssid = wpa_s->pending_bssid;
2137 if (!is_zero_ether_addr(bssid) ||
2138 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2139 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2141 MAC2STR(bssid), reason_code,
2142 locally_generated ? " locally_generated=1" : "");
2147 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2148 int locally_generated)
2150 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2151 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2152 return 0; /* Not in 4-way handshake with PSK */
2155 * It looks like connection was lost while trying to go through PSK
2156 * 4-way handshake. Filter out known disconnection cases that are caused
2157 * by something else than PSK mismatch to avoid confusing reports.
2160 if (locally_generated) {
2161 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2169 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2171 int locally_generated)
2175 u8 prev_pending_bssid[ETH_ALEN];
2176 struct wpa_bss *fast_reconnect = NULL;
2177 struct wpa_ssid *fast_reconnect_ssid = NULL;
2178 struct wpa_ssid *last_ssid;
2180 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2181 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2183 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2185 * At least Host AP driver and a Prism3 card seemed to be
2186 * generating streams of disconnected events when configuring
2187 * IBSS for WPA-None. Ignore them for now.
2189 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2190 "IBSS/WPA-None mode");
2194 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2195 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2196 "pre-shared key may be incorrect");
2197 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2198 return; /* P2P group removed */
2199 wpas_auth_failed(wpa_s, "WRONG_KEY");
2201 if (!wpa_s->disconnected &&
2202 (!wpa_s->auto_reconnect_disabled ||
2203 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2204 wpas_wps_searching(wpa_s))) {
2205 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2206 "reconnect (wps=%d/%d wpa_state=%d)",
2207 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2208 wpas_wps_searching(wpa_s),
2210 if (wpa_s->wpa_state == WPA_COMPLETED &&
2211 wpa_s->current_ssid &&
2212 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2213 !locally_generated &&
2214 disconnect_reason_recoverable(reason_code)) {
2216 * It looks like the AP has dropped association with
2217 * us, but could allow us to get back in. Try to
2218 * reconnect to the same BSS without full scan to save
2219 * time for some common cases.
2221 fast_reconnect = wpa_s->current_bss;
2222 fast_reconnect_ssid = wpa_s->current_ssid;
2223 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2224 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2226 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2229 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2230 "try to re-connect");
2231 wpa_s->reassociate = 0;
2232 wpa_s->disconnected = 1;
2233 wpa_supplicant_cancel_sched_scan(wpa_s);
2235 bssid = wpa_s->bssid;
2236 if (is_zero_ether_addr(bssid))
2237 bssid = wpa_s->pending_bssid;
2238 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2239 wpas_connection_failed(wpa_s, bssid);
2240 wpa_sm_notify_disassoc(wpa_s->wpa);
2241 if (locally_generated)
2242 wpa_s->disconnect_reason = -reason_code;
2244 wpa_s->disconnect_reason = reason_code;
2245 wpas_notify_disconnect_reason(wpa_s);
2246 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2247 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2248 wpa_clear_keys(wpa_s, wpa_s->bssid);
2250 last_ssid = wpa_s->current_ssid;
2251 wpa_supplicant_mark_disassoc(wpa_s);
2253 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2254 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2255 wpa_s->current_ssid = last_ssid;
2258 if (fast_reconnect &&
2259 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2260 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2261 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2262 fast_reconnect->ssid_len) &&
2263 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2264 #ifndef CONFIG_NO_SCAN_PROCESSING
2265 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2266 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2267 fast_reconnect_ssid) < 0) {
2268 /* Recover through full scan */
2269 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2271 #endif /* CONFIG_NO_SCAN_PROCESSING */
2272 } else if (fast_reconnect) {
2274 * Could not reconnect to the same BSS due to network being
2275 * disabled. Use a new scan to match the alternative behavior
2276 * above, i.e., to continue automatic reconnection attempt in a
2277 * way that enforces disabled network rules.
2279 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2284 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2285 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2287 struct wpa_supplicant *wpa_s = eloop_ctx;
2289 if (!wpa_s->pending_mic_error_report)
2292 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2293 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2294 wpa_s->pending_mic_error_report = 0;
2296 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2300 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2301 union wpa_event_data *data)
2304 struct os_reltime t;
2306 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2307 pairwise = (data && data->michael_mic_failure.unicast);
2309 if ((wpa_s->last_michael_mic_error.sec &&
2310 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2311 wpa_s->pending_mic_error_report) {
2312 if (wpa_s->pending_mic_error_report) {
2314 * Send the pending MIC error report immediately since
2315 * we are going to start countermeasures and AP better
2318 wpa_sm_key_request(wpa_s->wpa, 1,
2319 wpa_s->pending_mic_error_pairwise);
2322 /* Send the new MIC error report immediately since we are going
2323 * to start countermeasures and AP better do the same.
2325 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2327 /* initialize countermeasures */
2328 wpa_s->countermeasures = 1;
2330 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2332 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2335 * Need to wait for completion of request frame. We do not get
2336 * any callback for the message completion, so just wait a
2337 * short while and hope for the best. */
2340 wpa_drv_set_countermeasures(wpa_s, 1);
2341 wpa_supplicant_deauthenticate(wpa_s,
2342 WLAN_REASON_MICHAEL_MIC_FAILURE);
2343 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2345 eloop_register_timeout(60, 0,
2346 wpa_supplicant_stop_countermeasures,
2348 /* TODO: mark the AP rejected for 60 second. STA is
2349 * allowed to associate with another AP.. */
2351 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2352 if (wpa_s->mic_errors_seen) {
2354 * Reduce the effectiveness of Michael MIC error
2355 * reports as a means for attacking against TKIP if
2356 * more than one MIC failure is noticed with the same
2357 * PTK. We delay the transmission of the reports by a
2358 * random time between 0 and 60 seconds in order to
2359 * force the attacker wait 60 seconds before getting
2360 * the information on whether a frame resulted in a MIC
2366 if (os_get_random(rval, sizeof(rval)) < 0)
2367 sec = os_random() % 60;
2369 sec = WPA_GET_BE32(rval) % 60;
2370 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2371 "report %d seconds", sec);
2372 wpa_s->pending_mic_error_report = 1;
2373 wpa_s->pending_mic_error_pairwise = pairwise;
2374 eloop_cancel_timeout(
2375 wpa_supplicant_delayed_mic_error_report,
2377 eloop_register_timeout(
2378 sec, os_random() % 1000000,
2379 wpa_supplicant_delayed_mic_error_report,
2382 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2384 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2385 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2386 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2388 wpa_s->last_michael_mic_error = t;
2389 wpa_s->mic_errors_seen++;
2393 #ifdef CONFIG_TERMINATE_ONLASTIF
2394 static int any_interfaces(struct wpa_supplicant *head)
2396 struct wpa_supplicant *wpa_s;
2398 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2399 if (!wpa_s->interface_removed)
2403 #endif /* CONFIG_TERMINATE_ONLASTIF */
2407 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2408 union wpa_event_data *data)
2410 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2413 switch (data->interface_status.ievent) {
2414 case EVENT_INTERFACE_ADDED:
2415 if (!wpa_s->interface_removed)
2417 wpa_s->interface_removed = 0;
2418 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2419 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2420 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2421 "driver after interface was added");
2424 case EVENT_INTERFACE_REMOVED:
2425 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2426 wpa_s->interface_removed = 1;
2427 wpa_supplicant_mark_disassoc(wpa_s);
2428 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2429 l2_packet_deinit(wpa_s->l2);
2431 #ifdef CONFIG_TERMINATE_ONLASTIF
2432 /* check if last interface */
2433 if (!any_interfaces(wpa_s->global->ifaces))
2435 #endif /* CONFIG_TERMINATE_ONLASTIF */
2441 #ifdef CONFIG_PEERKEY
2443 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2444 union wpa_event_data *data)
2448 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2450 #endif /* CONFIG_PEERKEY */
2454 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2455 union wpa_event_data *data)
2459 switch (data->tdls.oper) {
2460 case TDLS_REQUEST_SETUP:
2461 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2462 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2463 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2465 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2467 case TDLS_REQUEST_TEARDOWN:
2468 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2469 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2470 data->tdls.reason_code);
2472 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2477 #endif /* CONFIG_TDLS */
2481 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2482 union wpa_event_data *data)
2486 switch (data->wnm.oper) {
2487 case WNM_OPER_SLEEP:
2488 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2489 "(action=%d, intval=%d)",
2490 data->wnm.sleep_action, data->wnm.sleep_intval);
2491 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2492 data->wnm.sleep_intval, NULL);
2496 #endif /* CONFIG_WNM */
2499 #ifdef CONFIG_IEEE80211R
2501 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2502 union wpa_event_data *data)
2507 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2508 data->ft_ies.ies_len,
2509 data->ft_ies.ft_action,
2510 data->ft_ies.target_ap,
2511 data->ft_ies.ric_ies,
2512 data->ft_ies.ric_ies_len) < 0) {
2513 /* TODO: prevent MLME/driver from trying to associate? */
2516 #endif /* CONFIG_IEEE80211R */
2519 #ifdef CONFIG_IBSS_RSN
2520 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2521 union wpa_event_data *data)
2523 struct wpa_ssid *ssid;
2524 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2528 ssid = wpa_s->current_ssid;
2531 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2534 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2538 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2539 union wpa_event_data *data)
2541 struct wpa_ssid *ssid = wpa_s->current_ssid;
2546 /* check if the ssid is correctly configured as IBSS/RSN */
2547 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2550 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2551 data->rx_mgmt.frame_len);
2553 #endif /* CONFIG_IBSS_RSN */
2556 #ifdef CONFIG_IEEE80211R
2557 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2560 const u8 *sta_addr, *target_ap_addr;
2563 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2564 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2565 return; /* only SME case supported for now */
2566 if (len < 1 + 2 * ETH_ALEN + 2)
2569 return; /* Only FT Action Response is supported for now */
2570 sta_addr = data + 1;
2571 target_ap_addr = data + 1 + ETH_ALEN;
2572 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2573 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2574 MACSTR " TargetAP " MACSTR " status %u",
2575 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2577 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2578 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2579 " in FT Action Response", MAC2STR(sta_addr));
2584 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2585 "failure (status code %d)", status);
2586 /* TODO: report error to FT code(?) */
2590 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2591 len - (1 + 2 * ETH_ALEN + 2), 1,
2592 target_ap_addr, NULL, 0) < 0)
2597 struct wpa_bss *bss;
2598 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2600 wpa_s->sme.freq = bss->freq;
2601 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2602 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2605 #endif /* CONFIG_SME */
2607 #endif /* CONFIG_IEEE80211R */
2610 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2611 struct unprot_deauth *e)
2613 #ifdef CONFIG_IEEE80211W
2614 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2615 "dropped: " MACSTR " -> " MACSTR
2616 " (reason code %u)",
2617 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2618 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2619 #endif /* CONFIG_IEEE80211W */
2623 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2624 struct unprot_disassoc *e)
2626 #ifdef CONFIG_IEEE80211W
2627 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2628 "dropped: " MACSTR " -> " MACSTR
2629 " (reason code %u)",
2630 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2631 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2632 #endif /* CONFIG_IEEE80211W */
2636 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2637 u16 reason_code, int locally_generated,
2638 const u8 *ie, size_t ie_len, int deauth)
2641 if (wpa_s->ap_iface && addr) {
2642 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2646 if (wpa_s->ap_iface) {
2647 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2650 #endif /* CONFIG_AP */
2652 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2654 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2655 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2656 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2657 eapol_sm_failed(wpa_s->eapol))) &&
2658 !wpa_s->eap_expected_failure))
2659 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2662 if (deauth && reason_code > 0) {
2663 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2664 locally_generated) > 0) {
2666 * The interface was removed, so cannot continue
2667 * processing any additional operations after this.
2672 #endif /* CONFIG_P2P */
2674 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2679 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2680 struct disassoc_info *info)
2682 u16 reason_code = 0;
2683 int locally_generated = 0;
2684 const u8 *addr = NULL;
2685 const u8 *ie = NULL;
2688 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2693 ie_len = info->ie_len;
2694 reason_code = info->reason_code;
2695 locally_generated = info->locally_generated;
2696 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2697 locally_generated ? " (locally generated)" : "");
2699 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2701 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2706 if (wpa_s->ap_iface && info && info->addr) {
2707 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2711 if (wpa_s->ap_iface) {
2712 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2715 #endif /* CONFIG_AP */
2719 wpas_p2p_disassoc_notif(
2720 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2723 #endif /* CONFIG_P2P */
2725 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2726 sme_event_disassoc(wpa_s, info);
2728 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2733 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2734 struct deauth_info *info)
2736 u16 reason_code = 0;
2737 int locally_generated = 0;
2738 const u8 *addr = NULL;
2739 const u8 *ie = NULL;
2742 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2747 ie_len = info->ie_len;
2748 reason_code = info->reason_code;
2749 locally_generated = info->locally_generated;
2750 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2752 locally_generated ? " (locally generated)" : "");
2754 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2757 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2761 wpa_reset_ft_completed(wpa_s->wpa);
2763 wpas_event_disconnect(wpa_s, addr, reason_code,
2764 locally_generated, ie, ie_len, 1);
2768 static const char * reg_init_str(enum reg_change_initiator init)
2771 case REGDOM_SET_BY_CORE:
2773 case REGDOM_SET_BY_USER:
2775 case REGDOM_SET_BY_DRIVER:
2777 case REGDOM_SET_BY_COUNTRY_IE:
2778 return "COUNTRY_IE";
2779 case REGDOM_BEACON_HINT:
2780 return "BEACON_HINT";
2786 static const char * reg_type_str(enum reg_type type)
2789 case REGDOM_TYPE_UNKNOWN:
2791 case REGDOM_TYPE_COUNTRY:
2793 case REGDOM_TYPE_WORLD:
2795 case REGDOM_TYPE_CUSTOM_WORLD:
2796 return "CUSTOM_WORLD";
2797 case REGDOM_TYPE_INTERSECTION:
2798 return "INTERSECTION";
2804 static void wpa_supplicant_update_channel_list(
2805 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2807 struct wpa_supplicant *ifs;
2809 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2810 reg_init_str(info->initiator), reg_type_str(info->type),
2811 info->alpha2[0] ? " alpha2=" : "",
2812 info->alpha2[0] ? info->alpha2 : "");
2814 if (wpa_s->drv_priv == NULL)
2815 return; /* Ignore event during drv initialization */
2817 free_hw_features(wpa_s);
2818 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2819 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2821 wpas_p2p_update_channel_list(wpa_s);
2824 * Check other interfaces to see if they share the same radio. If
2825 * so, they get updated with this same hw mode info.
2827 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2830 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2832 free_hw_features(ifs);
2833 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2834 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2840 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2841 const u8 *frame, size_t len, int freq,
2844 const struct ieee80211_mgmt *mgmt;
2849 if (len < IEEE80211_HDRLEN + 2)
2852 mgmt = (const struct ieee80211_mgmt *) frame;
2853 payload = frame + IEEE80211_HDRLEN;
2854 category = *payload++;
2855 plen = len - IEEE80211_HDRLEN - 1;
2857 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2858 " Category=%u DataLen=%d freq=%d MHz",
2859 MAC2STR(mgmt->sa), category, (int) plen, freq);
2861 if (category == WLAN_ACTION_WMM) {
2862 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2866 #ifdef CONFIG_IEEE80211R
2867 if (category == WLAN_ACTION_FT) {
2868 ft_rx_action(wpa_s, payload, plen);
2871 #endif /* CONFIG_IEEE80211R */
2873 #ifdef CONFIG_IEEE80211W
2875 if (category == WLAN_ACTION_SA_QUERY) {
2876 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2879 #endif /* CONFIG_SME */
2880 #endif /* CONFIG_IEEE80211W */
2883 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2884 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2887 #endif /* CONFIG_WNM */
2890 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2891 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2892 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2893 mgmt->u.action.category,
2894 payload, plen, freq) == 0)
2896 #endif /* CONFIG_GAS */
2899 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2900 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2901 wpa_dbg(wpa_s, MSG_DEBUG,
2902 "TDLS: Received Discovery Response from " MACSTR,
2906 #endif /* CONFIG_TDLS */
2908 #ifdef CONFIG_INTERWORKING
2909 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2910 payload[0] == QOS_QOS_MAP_CONFIG) {
2911 const u8 *pos = payload + 1;
2912 size_t qlen = plen - 1;
2913 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2914 MACSTR, MAC2STR(mgmt->sa));
2915 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2916 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2917 pos[1] <= qlen - 2 && pos[1] >= 16)
2918 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2921 #endif /* CONFIG_INTERWORKING */
2923 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2924 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2925 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2929 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2930 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2931 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2932 payload + 1, plen - 1,
2937 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2938 category, payload, plen, freq);
2940 mesh_mpm_action_rx(wpa_s, mgmt, len);
2944 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2945 union wpa_event_data *event)
2948 struct wpa_supplicant *ifs;
2949 #endif /* CONFIG_P2P */
2950 struct wpa_freq_range_list *list;
2953 list = &event->freq_range;
2956 str = freq_range_list_str(list);
2957 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2961 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2962 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2965 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2966 wpas_p2p_update_channel_list(wpa_s);
2969 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2971 if (!ifs->current_ssid ||
2972 !ifs->current_ssid->p2p_group ||
2973 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2974 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2977 freq = ifs->current_ssid->frequency;
2978 if (!freq_range_list_includes(list, freq)) {
2979 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2984 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2986 /* TODO: Consider using CSA or removing the group within
2988 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2990 #endif /* CONFIG_P2P */
2996 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
2997 union wpa_event_data *data)
2999 wpa_dbg(wpa_s, MSG_DEBUG,
3000 "Connection authorized by device, previous state %d",
3002 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3003 wpa_supplicant_cancel_auth_timeout(wpa_s);
3004 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3005 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3006 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3008 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3009 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3010 data->assoc_info.ptk_kck_len,
3011 data->assoc_info.ptk_kek,
3012 data->assoc_info.ptk_kek_len);
3016 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3017 union wpa_event_data *data)
3019 struct wpa_supplicant *wpa_s = ctx;
3021 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3022 event != EVENT_INTERFACE_ENABLED &&
3023 event != EVENT_INTERFACE_STATUS &&
3024 event != EVENT_SCHED_SCAN_STOPPED) {
3025 wpa_dbg(wpa_s, MSG_DEBUG,
3026 "Ignore event %s (%d) while interface is disabled",
3027 event_to_string(event), event);
3031 #ifndef CONFIG_NO_STDOUT_DEBUG
3033 int level = MSG_DEBUG;
3035 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3036 const struct ieee80211_hdr *hdr;
3038 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3039 fc = le_to_host16(hdr->frame_control);
3040 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3041 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3042 level = MSG_EXCESSIVE;
3045 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3046 event_to_string(event), event);
3048 #endif /* CONFIG_NO_STDOUT_DEBUG */
3052 sme_event_auth(wpa_s, data);
3055 wpa_supplicant_event_assoc(wpa_s, data);
3056 if (data && data->assoc_info.authorized)
3057 wpa_supplicant_event_assoc_auth(wpa_s, data);
3059 case EVENT_DISASSOC:
3060 wpas_event_disassoc(wpa_s,
3061 data ? &data->disassoc_info : NULL);
3064 wpas_event_deauth(wpa_s,
3065 data ? &data->deauth_info : NULL);
3067 case EVENT_MICHAEL_MIC_FAILURE:
3068 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3070 #ifndef CONFIG_NO_SCAN_PROCESSING
3071 case EVENT_SCAN_STARTED:
3072 os_get_reltime(&wpa_s->scan_start_time);
3073 if (wpa_s->own_scan_requested) {
3074 struct os_reltime diff;
3076 os_reltime_sub(&wpa_s->scan_start_time,
3077 &wpa_s->scan_trigger_time, &diff);
3078 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3079 diff.sec, diff.usec);
3080 wpa_s->own_scan_requested = 0;
3081 wpa_s->own_scan_running = 1;
3082 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3083 wpa_s->manual_scan_use_id) {
3084 wpa_msg_ctrl(wpa_s, MSG_INFO,
3085 WPA_EVENT_SCAN_STARTED "id=%u",
3086 wpa_s->manual_scan_id);
3088 wpa_msg_ctrl(wpa_s, MSG_INFO,
3089 WPA_EVENT_SCAN_STARTED);
3092 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3093 wpa_s->radio->external_scan_running = 1;
3094 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3097 case EVENT_SCAN_RESULTS:
3098 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3099 struct os_reltime now, diff;
3100 os_get_reltime(&now);
3101 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3102 wpa_s->scan_start_time.sec = 0;
3103 wpa_s->scan_start_time.usec = 0;
3104 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3105 diff.sec, diff.usec);
3107 if (wpa_supplicant_event_scan_results(wpa_s, data))
3108 break; /* interface may have been removed */
3109 wpa_s->own_scan_running = 0;
3110 wpa_s->radio->external_scan_running = 0;
3111 radio_work_check_next(wpa_s);
3113 #endif /* CONFIG_NO_SCAN_PROCESSING */
3114 case EVENT_ASSOCINFO:
3115 wpa_supplicant_event_associnfo(wpa_s, data);
3117 case EVENT_INTERFACE_STATUS:
3118 wpa_supplicant_event_interface_status(wpa_s, data);
3120 case EVENT_PMKID_CANDIDATE:
3121 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3123 #ifdef CONFIG_PEERKEY
3124 case EVENT_STKSTART:
3125 wpa_supplicant_event_stkstart(wpa_s, data);
3127 #endif /* CONFIG_PEERKEY */
3130 wpa_supplicant_event_tdls(wpa_s, data);
3132 #endif /* CONFIG_TDLS */
3135 wpa_supplicant_event_wnm(wpa_s, data);
3137 #endif /* CONFIG_WNM */
3138 #ifdef CONFIG_IEEE80211R
3139 case EVENT_FT_RESPONSE:
3140 wpa_supplicant_event_ft_response(wpa_s, data);
3142 #endif /* CONFIG_IEEE80211R */
3143 #ifdef CONFIG_IBSS_RSN
3144 case EVENT_IBSS_RSN_START:
3145 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3147 #endif /* CONFIG_IBSS_RSN */
3148 case EVENT_ASSOC_REJECT:
3149 if (data->assoc_reject.bssid)
3150 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3151 "bssid=" MACSTR " status_code=%u",
3152 MAC2STR(data->assoc_reject.bssid),
3153 data->assoc_reject.status_code);
3155 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3157 data->assoc_reject.status_code);
3158 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3159 sme_event_assoc_reject(wpa_s, data);
3161 const u8 *bssid = data->assoc_reject.bssid;
3162 if (bssid == NULL || is_zero_ether_addr(bssid))
3163 bssid = wpa_s->pending_bssid;
3164 wpas_connection_failed(wpa_s, bssid);
3165 wpa_supplicant_mark_disassoc(wpa_s);
3168 case EVENT_AUTH_TIMED_OUT:
3169 /* It is possible to get this event from earlier connection */
3170 if (wpa_s->current_ssid &&
3171 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3172 wpa_dbg(wpa_s, MSG_DEBUG,
3173 "Ignore AUTH_TIMED_OUT in mesh configuration");
3176 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3177 sme_event_auth_timed_out(wpa_s, data);
3179 case EVENT_ASSOC_TIMED_OUT:
3180 /* It is possible to get this event from earlier connection */
3181 if (wpa_s->current_ssid &&
3182 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3183 wpa_dbg(wpa_s, MSG_DEBUG,
3184 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3187 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3188 sme_event_assoc_timed_out(wpa_s, data);
3190 case EVENT_TX_STATUS:
3191 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3192 " type=%d stype=%d",
3193 MAC2STR(data->tx_status.dst),
3194 data->tx_status.type, data->tx_status.stype);
3196 if (wpa_s->ap_iface == NULL) {
3197 #ifdef CONFIG_OFFCHANNEL
3198 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3199 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3200 offchannel_send_action_tx_status(
3201 wpa_s, data->tx_status.dst,
3202 data->tx_status.data,
3203 data->tx_status.data_len,
3204 data->tx_status.ack ?
3205 OFFCHANNEL_SEND_ACTION_SUCCESS :
3206 OFFCHANNEL_SEND_ACTION_NO_ACK);
3207 #endif /* CONFIG_OFFCHANNEL */
3210 #endif /* CONFIG_AP */
3211 #ifdef CONFIG_OFFCHANNEL
3212 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3213 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3215 * Catch TX status events for Action frames we sent via group
3216 * interface in GO mode.
3218 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3219 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3220 os_memcmp(wpa_s->parent->pending_action_dst,
3221 data->tx_status.dst, ETH_ALEN) == 0) {
3222 offchannel_send_action_tx_status(
3223 wpa_s->parent, data->tx_status.dst,
3224 data->tx_status.data,
3225 data->tx_status.data_len,
3226 data->tx_status.ack ?
3227 OFFCHANNEL_SEND_ACTION_SUCCESS :
3228 OFFCHANNEL_SEND_ACTION_NO_ACK);
3231 #endif /* CONFIG_OFFCHANNEL */
3233 switch (data->tx_status.type) {
3234 case WLAN_FC_TYPE_MGMT:
3235 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3236 data->tx_status.data_len,
3237 data->tx_status.stype,
3238 data->tx_status.ack);
3240 case WLAN_FC_TYPE_DATA:
3241 ap_tx_status(wpa_s, data->tx_status.dst,
3242 data->tx_status.data,
3243 data->tx_status.data_len,
3244 data->tx_status.ack);
3247 #endif /* CONFIG_AP */
3250 case EVENT_EAPOL_TX_STATUS:
3251 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3252 data->eapol_tx_status.data,
3253 data->eapol_tx_status.data_len,
3254 data->eapol_tx_status.ack);
3256 case EVENT_DRIVER_CLIENT_POLL_OK:
3257 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3259 case EVENT_RX_FROM_UNKNOWN:
3260 if (wpa_s->ap_iface == NULL)
3262 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3263 data->rx_from_unknown.wds);
3265 case EVENT_CH_SWITCH:
3268 if (!wpa_s->ap_iface) {
3269 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3270 "event in non-AP mode");
3274 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3275 data->ch_switch.ht_enabled,
3276 data->ch_switch.ch_offset,
3277 data->ch_switch.ch_width,
3278 data->ch_switch.cf1,
3279 data->ch_switch.cf2);
3281 #endif /* CONFIG_AP */
3282 case EVENT_RX_MGMT: {
3284 const struct ieee80211_mgmt *mgmt;
3286 #ifdef CONFIG_TESTING_OPTIONS
3287 if (wpa_s->ext_mgmt_frame_handling) {
3288 struct rx_mgmt *rx = &data->rx_mgmt;
3289 size_t hex_len = 2 * rx->frame_len + 1;
3290 char *hex = os_malloc(hex_len);
3292 wpa_snprintf_hex(hex, hex_len,
3293 rx->frame, rx->frame_len);
3294 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3295 rx->freq, rx->datarate, rx->ssi_signal,
3301 #endif /* CONFIG_TESTING_OPTIONS */
3303 mgmt = (const struct ieee80211_mgmt *)
3304 data->rx_mgmt.frame;
3305 fc = le_to_host16(mgmt->frame_control);
3306 stype = WLAN_FC_GET_STYPE(fc);
3309 if (wpa_s->ap_iface == NULL) {
3310 #endif /* CONFIG_AP */
3312 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3313 data->rx_mgmt.frame_len > 24) {
3314 const u8 *src = mgmt->sa;
3315 const u8 *ie = mgmt->u.probe_req.variable;
3316 size_t ie_len = data->rx_mgmt.frame_len -
3317 (mgmt->u.probe_req.variable -
3318 data->rx_mgmt.frame);
3319 wpas_p2p_probe_req_rx(
3320 wpa_s, src, mgmt->da,
3321 mgmt->bssid, ie, ie_len,
3322 data->rx_mgmt.ssi_signal);
3325 #endif /* CONFIG_P2P */
3326 #ifdef CONFIG_IBSS_RSN
3327 if (wpa_s->current_ssid &&
3328 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3329 stype == WLAN_FC_STYPE_AUTH &&
3330 data->rx_mgmt.frame_len >= 30) {
3331 wpa_supplicant_event_ibss_auth(wpa_s, data);
3334 #endif /* CONFIG_IBSS_RSN */
3336 if (stype == WLAN_FC_STYPE_ACTION) {
3337 wpas_event_rx_mgmt_action(
3338 wpa_s, data->rx_mgmt.frame,
3339 data->rx_mgmt.frame_len,
3341 data->rx_mgmt.ssi_signal);
3346 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3350 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3351 "management frame in non-AP mode");
3356 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3357 data->rx_mgmt.frame_len > 24) {
3358 const u8 *ie = mgmt->u.probe_req.variable;
3359 size_t ie_len = data->rx_mgmt.frame_len -
3360 (mgmt->u.probe_req.variable -
3361 data->rx_mgmt.frame);
3363 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3364 mgmt->bssid, ie, ie_len,
3365 data->rx_mgmt.ssi_signal);
3368 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3369 #endif /* CONFIG_AP */
3372 case EVENT_RX_PROBE_REQ:
3373 if (data->rx_probe_req.sa == NULL ||
3374 data->rx_probe_req.ie == NULL)
3377 if (wpa_s->ap_iface) {
3378 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3379 data->rx_probe_req.sa,
3380 data->rx_probe_req.da,
3381 data->rx_probe_req.bssid,
3382 data->rx_probe_req.ie,
3383 data->rx_probe_req.ie_len,
3384 data->rx_probe_req.ssi_signal);
3387 #endif /* CONFIG_AP */
3388 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3389 data->rx_probe_req.da,
3390 data->rx_probe_req.bssid,
3391 data->rx_probe_req.ie,
3392 data->rx_probe_req.ie_len,
3393 data->rx_probe_req.ssi_signal);
3395 case EVENT_REMAIN_ON_CHANNEL:
3396 #ifdef CONFIG_OFFCHANNEL
3397 offchannel_remain_on_channel_cb(
3398 wpa_s, data->remain_on_channel.freq,
3399 data->remain_on_channel.duration);
3400 #endif /* CONFIG_OFFCHANNEL */
3401 wpas_p2p_remain_on_channel_cb(
3402 wpa_s, data->remain_on_channel.freq,
3403 data->remain_on_channel.duration);
3405 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3406 #ifdef CONFIG_OFFCHANNEL
3407 offchannel_cancel_remain_on_channel_cb(
3408 wpa_s, data->remain_on_channel.freq);
3409 #endif /* CONFIG_OFFCHANNEL */
3410 wpas_p2p_cancel_remain_on_channel_cb(
3411 wpa_s, data->remain_on_channel.freq);
3413 case EVENT_EAPOL_RX:
3414 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3415 data->eapol_rx.data,
3416 data->eapol_rx.data_len);
3418 case EVENT_SIGNAL_CHANGE:
3419 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3420 "above=%d signal=%d noise=%d txrate=%d",
3421 data->signal_change.above_threshold,
3422 data->signal_change.current_signal,
3423 data->signal_change.current_noise,
3424 data->signal_change.current_txrate);
3425 bgscan_notify_signal_change(
3426 wpa_s, data->signal_change.above_threshold,
3427 data->signal_change.current_signal,
3428 data->signal_change.current_noise,
3429 data->signal_change.current_txrate);
3431 case EVENT_INTERFACE_ENABLED:
3432 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3433 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3434 wpa_supplicant_update_mac_addr(wpa_s);
3435 if (wpa_s->p2p_mgmt) {
3436 wpa_supplicant_set_state(wpa_s,
3442 if (!wpa_s->ap_iface) {
3443 wpa_supplicant_set_state(wpa_s,
3445 wpa_s->scan_req = NORMAL_SCAN_REQ;
3446 wpa_supplicant_req_scan(wpa_s, 0, 0);
3448 wpa_supplicant_set_state(wpa_s,
3450 #else /* CONFIG_AP */
3451 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3452 wpa_supplicant_req_scan(wpa_s, 0, 0);
3453 #endif /* CONFIG_AP */
3456 case EVENT_INTERFACE_DISABLED:
3457 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3459 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3460 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3461 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3463 * Mark interface disabled if this happens to end up not
3464 * being removed as a separate P2P group interface.
3466 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3468 * The interface was externally disabled. Remove
3469 * it assuming an external entity will start a
3470 * new session if needed.
3472 if (wpa_s->current_ssid &&
3473 wpa_s->current_ssid->p2p_group)
3474 wpas_p2p_interface_unavailable(wpa_s);
3476 wpas_p2p_disconnect(wpa_s);
3478 * wpa_s instance may have been freed, so must not use
3483 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3484 p2p_in_progress(wpa_s->global->p2p) > 1) {
3485 /* This radio work will be cancelled, so clear P2P
3488 p2p_stop_find(wpa_s->global->p2p);
3490 #endif /* CONFIG_P2P */
3492 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3494 * Indicate disconnection to keep ctrl_iface events
3497 wpa_supplicant_event_disassoc(
3498 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3500 wpa_supplicant_mark_disassoc(wpa_s);
3501 radio_remove_works(wpa_s, NULL, 0);
3503 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3505 case EVENT_CHANNEL_LIST_CHANGED:
3506 wpa_supplicant_update_channel_list(
3507 wpa_s, &data->channel_list_changed);
3509 case EVENT_INTERFACE_UNAVAILABLE:
3510 wpas_p2p_interface_unavailable(wpa_s);
3512 case EVENT_BEST_CHANNEL:
3513 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3515 data->best_chan.freq_24, data->best_chan.freq_5,
3516 data->best_chan.freq_overall);
3517 wpa_s->best_24_freq = data->best_chan.freq_24;
3518 wpa_s->best_5_freq = data->best_chan.freq_5;
3519 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3520 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3521 data->best_chan.freq_5,
3522 data->best_chan.freq_overall);
3524 case EVENT_UNPROT_DEAUTH:
3525 wpa_supplicant_event_unprot_deauth(wpa_s,
3526 &data->unprot_deauth);
3528 case EVENT_UNPROT_DISASSOC:
3529 wpa_supplicant_event_unprot_disassoc(wpa_s,
3530 &data->unprot_disassoc);
3532 case EVENT_STATION_LOW_ACK:
3534 if (wpa_s->ap_iface && data)
3535 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3536 data->low_ack.addr);
3537 #endif /* CONFIG_AP */
3540 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3541 data->low_ack.addr);
3542 #endif /* CONFIG_TDLS */
3544 case EVENT_IBSS_PEER_LOST:
3545 #ifdef CONFIG_IBSS_RSN
3546 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3547 #endif /* CONFIG_IBSS_RSN */
3549 case EVENT_DRIVER_GTK_REKEY:
3550 if (os_memcmp(data->driver_gtk_rekey.bssid,
3551 wpa_s->bssid, ETH_ALEN))
3555 wpa_sm_update_replay_ctr(wpa_s->wpa,
3556 data->driver_gtk_rekey.replay_ctr);
3558 case EVENT_SCHED_SCAN_STOPPED:
3560 wpa_s->sched_scanning = 0;
3561 wpa_supplicant_notify_scanning(wpa_s, 0);
3563 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3567 * Start a new sched scan to continue searching for more SSIDs
3568 * either if timed out or PNO schedule scan is pending.
3570 if (wpa_s->sched_scan_timed_out) {
3571 wpa_supplicant_req_sched_scan(wpa_s);
3572 } else if (wpa_s->pno_sched_pending) {
3573 wpa_s->pno_sched_pending = 0;
3574 wpas_start_pno(wpa_s);
3578 case EVENT_WPS_BUTTON_PUSHED:
3580 wpas_wps_start_pbc(wpa_s, NULL, 0);
3581 #endif /* CONFIG_WPS */
3583 case EVENT_AVOID_FREQUENCIES:
3584 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3586 case EVENT_CONNECT_FAILED_REASON:
3588 if (!wpa_s->ap_iface || !data)
3590 hostapd_event_connect_failed_reason(
3591 wpa_s->ap_iface->bss[0],
3592 data->connect_failed_reason.addr,
3593 data->connect_failed_reason.code);
3594 #endif /* CONFIG_AP */
3596 case EVENT_NEW_PEER_CANDIDATE:
3598 if (!wpa_s->ifmsh || !data)
3600 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3601 data->mesh_peer.ies,
3602 data->mesh_peer.ie_len);
3603 #endif /* CONFIG_MESH */
3606 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);