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"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "crypto/random.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
37 #include "gas_query.h"
38 #include "p2p_supplicant.h"
44 #include "offchannel.h"
45 #include "interworking.h"
51 #ifndef CONFIG_NO_SCAN_PROCESSING
52 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
53 int new_scan, int own_request);
54 #endif /* CONFIG_NO_SCAN_PROCESSING */
57 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
60 struct os_reltime now;
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
66 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75 #ifndef CONFIG_NO_SCAN_PROCESSING
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
86 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
88 struct wpa_ssid *ssid;
89 int disabled_for, res = 0;
91 #ifdef CONFIG_INTERWORKING
92 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
95 #endif /* CONFIG_INTERWORKING */
97 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
101 disabled_for = wpas_temp_disabled(wpa_s, ssid);
105 if (!res || disabled_for < res)
111 #endif /* CONFIG_NO_SCAN_PROCESSING */
114 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
116 struct wpa_supplicant *wpa_s = eloop_ctx;
118 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
121 wpa_dbg(wpa_s, MSG_DEBUG,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s);
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
130 static struct wpa_bss * wpa_supplicant_get_new_bss(
131 struct wpa_supplicant *wpa_s, const u8 *bssid)
133 struct wpa_bss *bss = NULL;
134 struct wpa_ssid *ssid = wpa_s->current_ssid;
136 if (ssid->ssid_len > 0)
137 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
139 bss = wpa_bss_get_bssid(wpa_s, bssid);
145 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
147 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
150 wpa_supplicant_update_scan_results(wpa_s);
152 /* Get the BSS from the new scan results */
153 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
157 wpa_s->current_bss = bss;
161 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
163 struct wpa_ssid *ssid, *old_ssid;
164 u8 drv_ssid[SSID_MAX_LEN];
168 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
169 wpa_supplicant_update_current_bss(wpa_s);
171 if (wpa_s->current_ssid->ssid_len == 0)
172 return 0; /* current profile still in use */
173 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
175 wpa_msg(wpa_s, MSG_INFO,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
181 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
182 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
184 return 0; /* current profile still in use */
186 wpa_msg(wpa_s, MSG_DEBUG,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid, drv_ssid_len));
189 /* continue selecting a new network profile */
192 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
194 ssid = wpa_supplicant_get_ssid(wpa_s);
196 wpa_msg(wpa_s, MSG_INFO,
197 "No network configuration found for the current AP");
201 if (wpas_network_disabled(wpa_s, ssid)) {
202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
206 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
207 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
208 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
212 res = wpas_temp_disabled(wpa_s, ssid);
214 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
215 "disabled for %d second(s)", res);
219 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
221 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
223 size_t wpa_ie_len = sizeof(wpa_ie);
224 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
225 wpa_ie, &wpa_ie_len) < 0)
226 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
228 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
231 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
232 eapol_sm_invalidate_cached_session(wpa_s->eapol);
233 old_ssid = wpa_s->current_ssid;
234 wpa_s->current_ssid = ssid;
236 wpa_supplicant_update_current_bss(wpa_s);
238 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
239 wpa_supplicant_initiate_eapol(wpa_s);
240 if (old_ssid != wpa_s->current_ssid)
241 wpas_notify_network_changed(wpa_s);
247 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
249 struct wpa_supplicant *wpa_s = eloop_ctx;
251 if (wpa_s->countermeasures) {
252 wpa_s->countermeasures = 0;
253 wpa_drv_set_countermeasures(wpa_s, 0);
254 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
263 wpa_supplicant_cancel_sched_scan(wpa_s);
264 wpa_supplicant_req_scan(wpa_s, 0, 0);
269 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
273 wnm_bss_keep_alive_deinit(wpa_s);
275 #ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s->ibss_rsn);
277 wpa_s->ibss_rsn = NULL;
278 #endif /* CONFIG_IBSS_RSN */
281 wpa_supplicant_ap_deinit(wpa_s);
282 #endif /* CONFIG_AP */
284 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
287 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
288 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
289 os_memset(wpa_s->bssid, 0, ETH_ALEN);
290 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
291 sme_clear_on_disassoc(wpa_s);
292 wpa_s->current_bss = NULL;
293 wpa_s->assoc_freq = 0;
296 wpas_notify_bssid_changed(wpa_s);
298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
300 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
301 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
302 wpa_s->ap_ies_from_associnfo = 0;
303 wpa_s->current_ssid = NULL;
304 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
307 wpas_rrm_reset(wpa_s);
308 wpa_s->wnmsleep_used = 0;
312 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
314 struct wpa_ie_data ie;
318 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
322 for (i = 0; i < ie.num_pmkid; i++) {
323 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
324 ie.pmkid + i * PMKID_LEN,
326 if (pmksa_set == 0) {
327 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
332 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
333 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
337 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
338 union wpa_event_data *data)
341 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
345 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
346 " index=%d preauth=%d",
347 MAC2STR(data->pmkid_candidate.bssid),
348 data->pmkid_candidate.index,
349 data->pmkid_candidate.preauth);
351 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
352 data->pmkid_candidate.index,
353 data->pmkid_candidate.preauth);
357 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
360 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
363 #ifdef IEEE8021X_EAPOL
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
365 wpa_s->current_ssid &&
366 !(wpa_s->current_ssid->eapol_flags &
367 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
368 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
369 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
370 * plaintext or static WEP keys). */
373 #endif /* IEEE8021X_EAPOL */
380 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
381 * @wpa_s: pointer to wpa_supplicant data
382 * @ssid: Configuration data for the network
383 * Returns: 0 on success, -1 on failure
385 * This function is called when starting authentication with a network that is
386 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
388 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
389 struct wpa_ssid *ssid)
391 #ifdef IEEE8021X_EAPOL
393 int aka = 0, sim = 0;
395 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
396 wpa_s->scard != NULL || wpa_s->conf->external_sim)
399 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
403 struct eap_method_type *eap = ssid->eap.eap_methods;
404 while (eap->vendor != EAP_VENDOR_IETF ||
405 eap->method != EAP_TYPE_NONE) {
406 if (eap->vendor == EAP_VENDOR_IETF) {
407 if (eap->method == EAP_TYPE_SIM)
409 else if (eap->method == EAP_TYPE_AKA ||
410 eap->method == EAP_TYPE_AKA_PRIME)
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
419 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
420 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
425 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
426 "use SIM, but neither EAP-SIM nor EAP-AKA are "
431 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
432 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
434 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
435 if (wpa_s->scard == NULL) {
436 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
440 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
441 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
442 #endif /* PCSC_FUNCS */
443 #endif /* IEEE8021X_EAPOL */
449 #ifndef CONFIG_NO_SCAN_PROCESSING
451 static int has_wep_key(struct wpa_ssid *ssid)
455 for (i = 0; i < NUM_WEP_KEYS; i++) {
456 if (ssid->wep_key_len[i])
464 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
465 struct wpa_ssid *ssid)
469 if (ssid->mixed_cell)
473 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
475 #endif /* CONFIG_WPS */
477 if (has_wep_key(ssid))
480 #ifdef IEEE8021X_EAPOL
481 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
482 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
483 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
485 #endif /* IEEE8021X_EAPOL */
487 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
490 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
493 if (bss->caps & IEEE80211_CAP_PRIVACY)
499 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid,
503 struct wpa_ie_data ie;
505 const u8 *rsn_ie, *wpa_ie;
509 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
513 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
514 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
515 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
516 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
517 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
519 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
520 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
523 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
524 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
530 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
532 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
537 if (!(ie.proto & ssid->proto)) {
538 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
543 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
544 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
549 if (!(ie.group_cipher & ssid->group_cipher)) {
550 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
555 if (!(ie.key_mgmt & ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
561 #ifdef CONFIG_IEEE80211W
562 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
563 wpas_get_ssid_pmf(wpa_s, ssid) ==
564 MGMT_FRAME_PROTECTION_REQUIRED) {
565 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
569 #endif /* CONFIG_IEEE80211W */
570 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
571 wpas_get_ssid_pmf(wpa_s, ssid) ==
572 NO_MGMT_FRAME_PROTECTION) {
573 wpa_dbg(wpa_s, MSG_DEBUG,
574 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
578 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
582 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
583 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
586 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
587 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
593 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
595 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
600 if (!(ie.proto & ssid->proto)) {
601 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
606 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
607 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
612 if (!(ie.group_cipher & ssid->group_cipher)) {
613 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
618 if (!(ie.key_mgmt & ssid->key_mgmt)) {
619 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
624 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
628 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
630 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
634 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
635 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
636 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
640 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
641 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
642 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
646 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
647 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
651 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
658 static int freq_allowed(int *freqs, int freq)
665 for (i = 0; freqs[i]; i++)
666 if (freqs[i] == freq)
672 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
674 const struct hostapd_hw_modes *mode = NULL, *modes;
675 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
680 return 1; /* Cannot do matching without knowing band */
682 modes = wpa_s->hw.modes;
685 * The driver does not provide any additional information
686 * about the utilized hardware, so allow the connection attempt
692 for (i = 0; i < wpa_s->hw.num_modes; i++) {
693 for (j = 0; j < modes[i].num_channels; j++) {
694 int freq = modes[i].channels[j].freq;
695 if (freq == bss->freq) {
697 mode->mode == HOSTAPD_MODE_IEEE80211G)
698 break; /* do not allow 802.11b replace
709 for (i = 0; i < (int) sizeof(scan_ie); i++) {
710 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
714 for (j = 2; j < rate_ie[1] + 2; j++) {
715 int flagged = !!(rate_ie[j] & 0x80);
716 int r = (rate_ie[j] & 0x7f) * 5;
719 * IEEE Std 802.11n-2009 7.3.2.2:
720 * The new BSS Membership selector value is encoded
721 * like a legacy basic rate, but it is not a rate and
722 * only indicates if the BSS members are required to
723 * support the mandatory features of Clause 20 [HT PHY]
724 * in order to join the BSS.
726 if (flagged && ((rate_ie[j] & 0x7f) ==
727 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
728 if (!ht_supported(mode)) {
729 wpa_dbg(wpa_s, MSG_DEBUG,
730 " hardware does not support "
737 /* There's also a VHT selector for 802.11ac */
738 if (flagged && ((rate_ie[j] & 0x7f) ==
739 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
740 if (!vht_supported(mode)) {
741 wpa_dbg(wpa_s, MSG_DEBUG,
742 " hardware does not support "
752 /* check for legacy basic rates */
753 for (k = 0; k < mode->num_rates; k++) {
754 if (mode->rates[k] == r)
757 if (k == mode->num_rates) {
759 * IEEE Std 802.11-2007 7.3.2.2 demands that in
760 * order to join a BSS all required rates
761 * have to be supported by the hardware.
763 wpa_dbg(wpa_s, MSG_DEBUG,
764 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
766 bss->freq, mode->mode, mode->num_rates);
777 * Test whether BSS is in an ESS.
778 * This is done differently in DMG (60 GHz) and non-DMG bands
780 static int bss_is_ess(struct wpa_bss *bss)
782 if (bss_is_dmg(bss)) {
783 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
784 IEEE80211_CAP_DMG_AP;
787 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
792 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
796 for (i = 0; i < ETH_ALEN; i++) {
797 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
804 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
808 for (i = 0; i < num; i++) {
809 const u8 *a = list + i * ETH_ALEN * 2;
810 const u8 *m = a + ETH_ALEN;
812 if (match_mac_mask(a, addr, m))
819 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
820 int i, struct wpa_bss *bss,
821 struct wpa_ssid *group,
824 u8 wpa_ie_len, rsn_ie_len;
826 struct wpa_blacklist *e;
828 struct wpa_ssid *ssid;
831 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
832 wpa_ie_len = ie ? ie[1] : 0;
834 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
835 rsn_ie_len = ie ? ie[1] : 0;
837 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
840 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
841 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
842 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
843 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
844 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
845 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
846 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
848 osen ? " osen=1" : "");
850 e = wpa_blacklist_get(wpa_s, bss->bssid);
853 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
855 * When only a single network is enabled, we can
856 * trigger blacklisting on the first failure. This
857 * should not be done with multiple enabled networks to
858 * avoid getting forced to move into a worse ESS on
859 * single error if there are no other BSSes of the
864 if (e->count > limit) {
865 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
866 "(count=%d limit=%d)", e->count, limit);
871 if (bss->ssid_len == 0) {
872 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
876 if (disallowed_bssid(wpa_s, bss->bssid)) {
877 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
881 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
882 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
886 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
888 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
889 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
892 if (wpas_network_disabled(wpa_s, ssid)) {
893 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
897 res = wpas_temp_disabled(wpa_s, ssid);
899 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
900 "temporarily for %d second(s)", res);
905 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
911 if (wpa && ssid->ssid_len == 0 &&
912 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
915 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
916 /* Only allow wildcard SSID match if an AP
917 * advertises active WPS operation that matches
920 if (ssid->ssid_len == 0 &&
921 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
924 #endif /* CONFIG_WPS */
926 if (ssid->bssid_set && ssid->ssid_len == 0 &&
927 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
931 (bss->ssid_len != ssid->ssid_len ||
932 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
933 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
937 if (ssid->bssid_set &&
938 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
939 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
943 /* check blacklist */
944 if (ssid->num_bssid_blacklist &&
945 addr_in_list(bss->bssid, ssid->bssid_blacklist,
946 ssid->num_bssid_blacklist)) {
947 wpa_dbg(wpa_s, MSG_DEBUG,
948 " skip - BSSID blacklisted");
952 /* if there is a whitelist, only accept those APs */
953 if (ssid->num_bssid_whitelist &&
954 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
955 ssid->num_bssid_whitelist)) {
956 wpa_dbg(wpa_s, MSG_DEBUG,
957 " skip - BSSID not in whitelist");
961 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
965 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
966 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
967 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
968 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
973 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
975 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
979 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
980 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
985 if (!wpa_supplicant_match_privacy(bss, ssid)) {
986 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
991 if (!bss_is_ess(bss)) {
992 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
996 if (!freq_allowed(ssid->freq_list, bss->freq)) {
997 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1002 if (!rate_match(wpa_s, bss)) {
1003 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1009 if (ssid->p2p_group &&
1010 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1011 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1012 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1016 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1017 struct wpabuf *p2p_ie;
1018 u8 dev_addr[ETH_ALEN];
1020 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1022 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1025 p2p_ie = wpa_bss_get_vendor_ie_multi(
1026 bss, P2P_IE_VENDOR_TYPE);
1027 if (p2p_ie == NULL) {
1028 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1032 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1033 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1035 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1036 wpabuf_free(p2p_ie);
1039 wpabuf_free(p2p_ie);
1043 * TODO: skip the AP if its P2P IE has Group Formation
1044 * bit set in the P2P Group Capability Bitmap and we
1045 * are not in Group Formation with that device.
1047 #endif /* CONFIG_P2P */
1049 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1051 struct os_reltime diff;
1053 os_reltime_sub(&wpa_s->scan_min_time,
1054 &bss->last_update, &diff);
1055 wpa_dbg(wpa_s, MSG_DEBUG,
1056 " skip - scan result not recent enough (%u.%06u seconds too old)",
1057 (unsigned int) diff.sec,
1058 (unsigned int) diff.usec);
1062 /* Matching configuration found */
1066 /* No matching configuration found */
1071 static struct wpa_bss *
1072 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1073 struct wpa_ssid *group,
1074 struct wpa_ssid **selected_ssid,
1075 int only_first_ssid)
1079 if (only_first_ssid)
1080 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1083 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1086 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1087 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1088 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1090 if (!*selected_ssid)
1092 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1094 MAC2STR(bss->bssid),
1095 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1103 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1104 struct wpa_ssid **selected_ssid)
1106 struct wpa_bss *selected = NULL;
1108 struct wpa_ssid *next_ssid = NULL;
1109 struct wpa_ssid *ssid;
1111 if (wpa_s->last_scan_res == NULL ||
1112 wpa_s->last_scan_res_used == 0)
1113 return NULL; /* no scan results from last update */
1115 if (wpa_s->next_ssid) {
1116 /* check that next_ssid is still valid */
1117 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1118 if (ssid == wpa_s->next_ssid)
1122 wpa_s->next_ssid = NULL;
1125 while (selected == NULL) {
1126 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1127 if (next_ssid && next_ssid->priority ==
1128 wpa_s->conf->pssid[prio]->priority) {
1129 selected = wpa_supplicant_select_bss(
1130 wpa_s, next_ssid, selected_ssid, 1);
1134 selected = wpa_supplicant_select_bss(
1135 wpa_s, wpa_s->conf->pssid[prio],
1141 if (selected == NULL && wpa_s->blacklist &&
1142 !wpa_s->countermeasures) {
1143 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1144 "blacklist and try again");
1145 wpa_blacklist_clear(wpa_s);
1146 wpa_s->blacklist_cleared++;
1147 } else if (selected == NULL)
1151 ssid = *selected_ssid;
1152 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1153 !ssid->passphrase && !ssid->ext_psk) {
1154 const char *field_name, *txt = NULL;
1156 wpa_dbg(wpa_s, MSG_DEBUG,
1157 "PSK/passphrase not yet available for the selected network");
1159 wpas_notify_network_request(wpa_s, ssid,
1160 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1162 field_name = wpa_supplicant_ctrl_req_to_string(
1163 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1164 if (field_name == NULL)
1167 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1176 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1177 int timeout_sec, int timeout_usec)
1179 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1181 * No networks are enabled; short-circuit request so
1182 * we don't wait timeout seconds before transitioning
1183 * to INACTIVE state.
1185 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1186 "since there are no enabled networks");
1187 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1191 wpa_s->scan_for_connection = 1;
1192 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1196 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1197 struct wpa_bss *selected,
1198 struct wpa_ssid *ssid)
1200 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1201 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1202 "PBC session overlap");
1203 wpas_notify_wps_event_pbc_overlap(wpa_s);
1205 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1206 wpa_s->p2p_in_provisioning) {
1207 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1211 #endif /* CONFIG_P2P */
1214 wpas_wps_pbc_overlap(wpa_s);
1215 wpas_wps_cancel(wpa_s);
1216 #endif /* CONFIG_WPS */
1220 wpa_msg(wpa_s, MSG_DEBUG,
1221 "Considering connect request: reassociate: %d selected: "
1222 MACSTR " bssid: " MACSTR " pending: " MACSTR
1223 " wpa_state: %s ssid=%p current_ssid=%p",
1224 wpa_s->reassociate, MAC2STR(selected->bssid),
1225 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1226 wpa_supplicant_state_txt(wpa_s->wpa_state),
1227 ssid, wpa_s->current_ssid);
1230 * Do not trigger new association unless the BSSID has changed or if
1231 * reassociation is requested. If we are in process of associating with
1232 * the selected BSSID, do not trigger new attempt.
1234 if (wpa_s->reassociate ||
1235 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1236 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1237 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1238 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1239 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1241 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1242 ssid != wpa_s->current_ssid)))) {
1243 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1244 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1247 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1248 MAC2STR(selected->bssid));
1249 wpa_supplicant_associate(wpa_s, selected, ssid);
1251 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1252 "connect with the selected AP");
1259 static struct wpa_ssid *
1260 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1263 struct wpa_ssid *ssid;
1265 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1266 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1268 if (wpas_network_disabled(wpa_s, ssid))
1270 if (ssid->mode == IEEE80211_MODE_IBSS ||
1271 ssid->mode == IEEE80211_MODE_AP ||
1272 ssid->mode == IEEE80211_MODE_MESH)
1280 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1281 * on BSS added and BSS changed events */
1282 static void wpa_supplicant_rsn_preauth_scan_results(
1283 struct wpa_supplicant *wpa_s)
1285 struct wpa_bss *bss;
1287 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1290 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1291 const u8 *ssid, *rsn;
1293 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1297 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1301 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1307 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1308 struct wpa_bss *selected,
1309 struct wpa_ssid *ssid)
1311 struct wpa_bss *current_bss = NULL;
1312 #ifndef CONFIG_NO_ROAMING
1314 #endif /* CONFIG_NO_ROAMING */
1316 if (wpa_s->reassociate)
1317 return 1; /* explicit request to reassociate */
1318 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1319 return 1; /* we are not associated; continue */
1320 if (wpa_s->current_ssid == NULL)
1321 return 1; /* unknown current SSID */
1322 if (wpa_s->current_ssid != ssid)
1323 return 1; /* different network block */
1325 if (wpas_driver_bss_selection(wpa_s))
1326 return 0; /* Driver-based roaming */
1328 if (wpa_s->current_ssid->ssid)
1329 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1330 wpa_s->current_ssid->ssid,
1331 wpa_s->current_ssid->ssid_len);
1333 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1336 return 1; /* current BSS not seen in scan results */
1338 if (current_bss == selected)
1341 if (selected->last_update_idx > current_bss->last_update_idx)
1342 return 1; /* current BSS not seen in the last scan */
1344 #ifndef CONFIG_NO_ROAMING
1345 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1346 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1347 " level=%d snr=%d est_throughput=%u",
1348 MAC2STR(current_bss->bssid), current_bss->level,
1349 current_bss->snr, current_bss->est_throughput);
1350 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1351 " level=%d snr=%d est_throughput=%u",
1352 MAC2STR(selected->bssid), selected->level,
1353 selected->snr, selected->est_throughput);
1355 if (wpa_s->current_ssid->bssid_set &&
1356 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1358 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1359 "has preferred BSSID");
1363 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1364 wpa_dbg(wpa_s, MSG_DEBUG,
1365 "Allow reassociation - selected BSS has better estimated throughput");
1369 if (current_bss->level < 0 && current_bss->level > selected->level) {
1370 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1376 if (current_bss->level < 0) {
1377 if (current_bss->level < -85)
1379 else if (current_bss->level < -80)
1381 else if (current_bss->level < -75)
1383 else if (current_bss->level < -70)
1388 if (abs(current_bss->level - selected->level) < min_diff) {
1389 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1395 #else /* CONFIG_NO_ROAMING */
1397 #endif /* CONFIG_NO_ROAMING */
1401 /* Return != 0 if no scan results could be fetched or if scan results should not
1402 * be shared with other virtual interfaces. */
1403 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1404 union wpa_event_data *data,
1407 struct wpa_scan_results *scan_res = NULL;
1410 #ifndef CONFIG_NO_RANDOM_POOL
1412 #endif /* CONFIG_NO_RANDOM_POOL */
1415 if (wpa_s->ap_iface)
1417 #endif /* CONFIG_AP */
1419 wpa_supplicant_notify_scanning(wpa_s, 0);
1421 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1422 data ? &data->scan_info :
1424 if (scan_res == NULL) {
1425 if (wpa_s->conf->ap_scan == 2 || ap ||
1426 wpa_s->scan_res_handler == scan_only_handler)
1430 if (data && data->scan_info.external_scan)
1432 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1434 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1436 goto scan_work_done;
1439 #ifndef CONFIG_NO_RANDOM_POOL
1440 num = scan_res->num;
1443 for (i = 0; i < num; i++) {
1445 struct wpa_scan_res *res = scan_res->res[i];
1446 buf[0] = res->bssid[5];
1447 buf[1] = res->qual & 0xff;
1448 buf[2] = res->noise & 0xff;
1449 buf[3] = res->level & 0xff;
1450 buf[4] = res->tsf & 0xff;
1451 random_add_randomness(buf, sizeof(buf));
1453 #endif /* CONFIG_NO_RANDOM_POOL */
1455 if (own_request && wpa_s->scan_res_handler &&
1456 !(data && data->scan_info.external_scan)) {
1457 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1458 struct wpa_scan_results *scan_res);
1460 scan_res_handler = wpa_s->scan_res_handler;
1461 wpa_s->scan_res_handler = NULL;
1462 scan_res_handler(wpa_s, scan_res);
1464 goto scan_work_done;
1468 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1470 if (wpa_s->ap_iface->scan_cb)
1471 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1472 #endif /* CONFIG_AP */
1473 goto scan_work_done;
1476 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1477 wpa_s->own_scan_running,
1478 data ? data->scan_info.external_scan : 0);
1479 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1480 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1481 own_request && !(data && data->scan_info.external_scan)) {
1482 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1483 wpa_s->manual_scan_id);
1484 wpa_s->manual_scan_use_id = 0;
1486 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1488 wpas_notify_scan_results(wpa_s);
1490 wpas_notify_scan_done(wpa_s, 1);
1492 if (data && data->scan_info.external_scan) {
1493 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1494 wpa_scan_results_free(scan_res);
1498 if (wnm_scan_process(wpa_s, 1) > 0)
1499 goto scan_work_done;
1501 if (sme_proc_obss_scan(wpa_s) > 0)
1502 goto scan_work_done;
1504 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1505 goto scan_work_done;
1507 if (autoscan_notify_scan(wpa_s, scan_res))
1508 goto scan_work_done;
1510 if (wpa_s->disconnected) {
1511 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1512 goto scan_work_done;
1515 if (!wpas_driver_bss_selection(wpa_s) &&
1516 bgscan_notify_scan(wpa_s, scan_res) == 1)
1517 goto scan_work_done;
1519 wpas_wps_update_ap_info(wpa_s, scan_res);
1521 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1522 wpa_s->wpa_state < WPA_COMPLETED)
1523 goto scan_work_done;
1525 wpa_scan_results_free(scan_res);
1527 if (own_request && wpa_s->scan_work) {
1528 struct wpa_radio_work *work = wpa_s->scan_work;
1529 wpa_s->scan_work = NULL;
1530 radio_work_done(work);
1533 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1536 wpa_scan_results_free(scan_res);
1537 if (own_request && wpa_s->scan_work) {
1538 struct wpa_radio_work *work = wpa_s->scan_work;
1539 wpa_s->scan_work = NULL;
1540 radio_work_done(work);
1546 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1547 int new_scan, int own_request)
1549 struct wpa_bss *selected;
1550 struct wpa_ssid *ssid = NULL;
1551 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1553 if (time_to_reenable > 0) {
1554 wpa_dbg(wpa_s, MSG_DEBUG,
1555 "Postpone network selection by %d seconds since all networks are disabled",
1557 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1558 eloop_register_timeout(time_to_reenable, 0,
1559 wpas_network_reenabled, wpa_s, NULL);
1563 if (wpa_s->p2p_mgmt)
1564 return 0; /* no normal connection on p2p_mgmt interface */
1566 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1570 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1573 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1577 if (ssid != wpa_s->current_ssid &&
1578 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1579 wpa_s->own_disconnect_req = 1;
1580 wpa_supplicant_deauthenticate(
1581 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1584 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1585 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1589 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1591 * Do not notify other virtual radios of scan results since we do not
1592 * want them to start other associations at the same time.
1598 wpa_msg(wpa_s, MSG_INFO,
1599 "Avoiding join because we already joined a mesh group");
1602 #endif /* CONFIG_MESH */
1603 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1604 ssid = wpa_supplicant_pick_new_network(wpa_s);
1606 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1607 wpa_supplicant_associate(wpa_s, NULL, ssid);
1609 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1610 } else if (own_request) {
1612 * No SSID found. If SCAN results are as a result of
1613 * own scan request and not due to a scan request on
1614 * another shared interface, try another scan.
1616 int timeout_sec = wpa_s->scan_interval;
1617 int timeout_usec = 0;
1621 res = wpas_p2p_scan_no_go_seen(wpa_s);
1627 if (wpa_s->p2p_in_provisioning ||
1628 wpa_s->show_group_started ||
1629 wpa_s->p2p_in_invitation) {
1631 * Use shorter wait during P2P Provisioning
1632 * state and during P2P join-a-group operation
1633 * to speed up group formation.
1636 timeout_usec = 250000;
1637 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1641 #endif /* CONFIG_P2P */
1642 #ifdef CONFIG_INTERWORKING
1643 if (wpa_s->conf->auto_interworking &&
1644 wpa_s->conf->interworking &&
1645 wpa_s->conf->cred) {
1646 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1647 "start ANQP fetch since no matching "
1649 wpa_s->network_select = 1;
1650 wpa_s->auto_network_select = 1;
1651 interworking_start_fetch_anqp(wpa_s);
1654 #endif /* CONFIG_INTERWORKING */
1656 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1657 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1659 timeout_usec = 500000;
1660 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1664 #endif /* CONFIG_WPS */
1665 if (wpa_supplicant_req_sched_scan(wpa_s))
1666 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1669 wpa_msg_ctrl(wpa_s, MSG_INFO,
1670 WPA_EVENT_NETWORK_NOT_FOUND);
1677 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1678 union wpa_event_data *data)
1680 struct wpa_supplicant *ifs;
1683 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1686 * Interface may have been removed, so must not dereference
1693 * If no scan results could be fetched, then no need to
1694 * notify those interfaces that did not actually request
1695 * this scan. Similarly, if scan results started a new operation on this
1696 * interface, do not notify other interfaces to avoid concurrent
1697 * operations during a connection attempt.
1703 * Check other interfaces to see if they share the same radio. If
1704 * so, they get updated with this same scan info.
1706 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1709 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1710 "sibling", ifs->ifname);
1711 _wpa_supplicant_event_scan_results(ifs, data, 0);
1718 #endif /* CONFIG_NO_SCAN_PROCESSING */
1721 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1723 #ifdef CONFIG_NO_SCAN_PROCESSING
1725 #else /* CONFIG_NO_SCAN_PROCESSING */
1726 struct os_reltime now;
1728 if (wpa_s->last_scan_res_used == 0)
1731 os_get_reltime(&now);
1732 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1733 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1737 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1738 #endif /* CONFIG_NO_SCAN_PROCESSING */
1743 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1745 struct wpa_supplicant *wpa_s = eloop_ctx;
1747 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1750 if (!wpa_s->no_keep_alive) {
1751 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1752 MAC2STR(wpa_s->bssid));
1753 /* TODO: could skip this if normal data traffic has been sent */
1754 /* TODO: Consider using some more appropriate data frame for
1757 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1762 if (wpa_s->sme.bss_max_idle_period) {
1764 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1767 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1768 wnm_bss_keep_alive, wpa_s, NULL);
1770 #endif /* CONFIG_SME */
1774 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1775 const u8 *ies, size_t ies_len)
1777 struct ieee802_11_elems elems;
1782 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1786 if (elems.bss_max_idle_period) {
1788 wpa_s->sme.bss_max_idle_period =
1789 WPA_GET_LE16(elems.bss_max_idle_period);
1790 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1791 "TU)%s", wpa_s->sme.bss_max_idle_period,
1792 (elems.bss_max_idle_period[2] & 0x01) ?
1793 " (protected keep-live required)" : "");
1794 if (wpa_s->sme.bss_max_idle_period == 0)
1795 wpa_s->sme.bss_max_idle_period = 1;
1796 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1797 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1798 /* msec times 1000 */
1799 msec = wpa_s->sme.bss_max_idle_period * 1024;
1802 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1803 wnm_bss_keep_alive, wpa_s,
1807 #endif /* CONFIG_SME */
1810 #endif /* CONFIG_WNM */
1813 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1816 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1817 #endif /* CONFIG_WNM */
1821 #ifdef CONFIG_INTERWORKING
1823 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1828 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1829 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1831 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1838 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1839 const u8 *ies, size_t ies_len)
1841 struct ieee802_11_elems elems;
1846 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1849 if (elems.qos_map_set) {
1850 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1851 elems.qos_map_set_len);
1855 #endif /* CONFIG_INTERWORKING */
1859 static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1860 const u8 *ie, size_t ie_len)
1862 struct mb_ies_info mb_ies;
1864 if (!ie || !ie_len || !wpa_s->fst)
1867 os_memset(&mb_ies, 0, sizeof(mb_ies));
1869 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1874 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1879 if (ie[0] == WLAN_EID_MULTI_BAND) {
1880 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1881 (unsigned int) len);
1882 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1883 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1891 if (mb_ies.nof_ies > 0) {
1892 wpabuf_free(wpa_s->received_mb_ies);
1893 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1899 #endif /* CONFIG_FST */
1902 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1903 union wpa_event_data *data)
1905 int l, len, found = 0, wpa_found, rsn_found;
1907 #ifdef CONFIG_IEEE80211R
1909 #endif /* CONFIG_IEEE80211R */
1911 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1912 if (data->assoc_info.req_ies)
1913 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1914 data->assoc_info.req_ies_len);
1915 if (data->assoc_info.resp_ies) {
1916 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1917 data->assoc_info.resp_ies_len);
1919 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1920 data->assoc_info.resp_ies_len);
1921 #endif /* CONFIG_TDLS */
1923 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1924 data->assoc_info.resp_ies_len);
1925 #endif /* CONFIG_WNM */
1926 #ifdef CONFIG_INTERWORKING
1927 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1928 data->assoc_info.resp_ies_len);
1929 #endif /* CONFIG_INTERWORKING */
1931 if (data->assoc_info.beacon_ies)
1932 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1933 data->assoc_info.beacon_ies,
1934 data->assoc_info.beacon_ies_len);
1935 if (data->assoc_info.freq)
1936 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1937 data->assoc_info.freq);
1939 p = data->assoc_info.req_ies;
1940 l = data->assoc_info.req_ies_len;
1942 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1943 while (p && l >= 2) {
1946 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1950 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1951 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1952 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1953 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1956 wpa_find_assoc_pmkid(wpa_s);
1962 if (!found && data->assoc_info.req_ies)
1963 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1965 #ifdef CONFIG_IEEE80211R
1967 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1968 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1969 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1970 data->assoc_info.resp_ies,
1971 data->assoc_info.resp_ies_len,
1973 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1974 "Reassociation Response failed");
1975 wpa_supplicant_deauthenticate(
1976 wpa_s, WLAN_REASON_INVALID_IE);
1981 p = data->assoc_info.resp_ies;
1982 l = data->assoc_info.resp_ies_len;
1984 #ifdef CONFIG_WPS_STRICT
1985 if (p && wpa_s->current_ssid &&
1986 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1988 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1990 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1991 "include WPS IE in (Re)Association Response");
1995 if (wps_validate_assoc_resp(wps) < 0) {
1997 wpa_supplicant_deauthenticate(
1998 wpa_s, WLAN_REASON_INVALID_IE);
2003 #endif /* CONFIG_WPS_STRICT */
2005 /* Go through the IEs and make a copy of the MDIE, if present. */
2006 while (p && l >= 2) {
2009 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2013 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2014 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2015 wpa_s->sme.ft_used = 1;
2016 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2017 MOBILITY_DOMAIN_ID_LEN);
2023 #endif /* CONFIG_SME */
2025 /* Process FT when SME is in the driver */
2026 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2027 wpa_ft_is_completed(wpa_s->wpa)) {
2028 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2029 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2030 data->assoc_info.resp_ies,
2031 data->assoc_info.resp_ies_len,
2033 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2034 "Reassociation Response failed");
2035 wpa_supplicant_deauthenticate(
2036 wpa_s, WLAN_REASON_INVALID_IE);
2039 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2042 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2043 data->assoc_info.resp_ies_len);
2044 #endif /* CONFIG_IEEE80211R */
2046 /* WPA/RSN IE from Beacon/ProbeResp */
2047 p = data->assoc_info.beacon_ies;
2048 l = data->assoc_info.beacon_ies_len;
2050 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2052 wpa_found = rsn_found = 0;
2053 while (p && l >= 2) {
2056 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2061 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2062 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2064 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2068 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2070 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2077 if (!wpa_found && data->assoc_info.beacon_ies)
2078 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2079 if (!rsn_found && data->assoc_info.beacon_ies)
2080 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2081 if (wpa_found || rsn_found)
2082 wpa_s->ap_ies_from_associnfo = 1;
2084 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2085 wpa_s->assoc_freq != data->assoc_info.freq) {
2086 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2088 wpa_s->assoc_freq, data->assoc_info.freq);
2089 wpa_supplicant_update_scan_results(wpa_s);
2092 wpa_s->assoc_freq = data->assoc_info.freq;
2098 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2100 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2102 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2105 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2108 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2109 WPA_IE_VENDOR_TYPE);
2110 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2112 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2113 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2114 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2115 bss_rsn ? 2 + bss_rsn[1] : 0))
2122 static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2123 union wpa_event_data *data)
2126 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2127 struct wpa_bss *bss = wpa_s->current_bss;
2128 const u8 *ieprb, *iebcn;
2130 wpabuf_free(wpa_s->received_mb_ies);
2131 wpa_s->received_mb_ies = NULL;
2134 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2135 wpa_printf(MSG_DEBUG,
2136 "FST: MB IEs updated from Association Response frame");
2141 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2142 wpa_printf(MSG_DEBUG,
2143 "FST: MB IEs updated from association event Beacon IEs");
2150 ieprb = (const u8 *) (bss + 1);
2151 iebcn = ieprb + bss->ie_len;
2153 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2154 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2155 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2156 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2157 #endif /* CONFIG_FST */
2161 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2162 union wpa_event_data *data)
2169 if (wpa_s->ap_iface) {
2172 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2173 data->assoc_info.addr,
2174 data->assoc_info.req_ies,
2175 data->assoc_info.req_ies_len,
2176 data->assoc_info.reassoc);
2179 #endif /* CONFIG_AP */
2181 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2183 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2184 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2187 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2188 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2189 wpa_supplicant_deauthenticate(
2190 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2194 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2195 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2196 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2197 MACSTR, MAC2STR(bssid));
2199 random_add_randomness(bssid, ETH_ALEN);
2200 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2201 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2202 wpas_notify_bssid_changed(wpa_s);
2204 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2205 wpa_clear_keys(wpa_s, bssid);
2207 if (wpa_supplicant_select_config(wpa_s) < 0) {
2208 wpa_supplicant_deauthenticate(
2209 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2214 if (wpa_s->conf->ap_scan == 1 &&
2215 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2216 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2217 wpa_msg(wpa_s, MSG_WARNING,
2218 "WPA/RSN IEs not updated");
2221 wpas_fst_update_mb_assoc(wpa_s, data);
2224 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2225 wpa_s->sme.prev_bssid_set = 1;
2226 wpa_s->sme.last_unprot_disconnect.sec = 0;
2227 #endif /* CONFIG_SME */
2229 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2230 if (wpa_s->current_ssid) {
2231 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2232 * initialized before association, but for other modes,
2233 * initialize PC/SC here, if the current configuration needs
2234 * smartcard or SIM/USIM. */
2235 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2237 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2239 l2_packet_notify_auth_start(wpa_s->l2);
2242 * Set portEnabled first to FALSE in order to get EAP state machine out
2243 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2244 * state machine may transit to AUTHENTICATING state based on obsolete
2245 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2246 * AUTHENTICATED without ever giving chance to EAP state machine to
2249 if (!ft_completed) {
2250 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2251 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2253 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2254 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2255 /* 802.1X::portControl = Auto */
2256 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2257 wpa_s->eapol_received = 0;
2258 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2259 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2260 (wpa_s->current_ssid &&
2261 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2262 if (wpa_s->current_ssid &&
2263 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2265 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2267 * Set the key after having received joined-IBSS event
2270 wpa_supplicant_set_wpa_none_key(wpa_s,
2271 wpa_s->current_ssid);
2273 wpa_supplicant_cancel_auth_timeout(wpa_s);
2274 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2275 } else if (!ft_completed) {
2276 /* Timeout for receiving the first EAPOL packet */
2277 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2279 wpa_supplicant_cancel_scan(wpa_s);
2281 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2282 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2284 * We are done; the driver will take care of RSN 4-way
2287 wpa_supplicant_cancel_auth_timeout(wpa_s);
2288 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2289 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2290 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2291 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2292 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2294 * The driver will take care of RSN 4-way handshake, so we need
2295 * to allow EAPOL supplicant to complete its work without
2296 * waiting for WPA supplicant.
2298 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2299 } else if (ft_completed) {
2301 * FT protocol completed - make sure EAPOL state machine ends
2302 * up in authenticated.
2304 wpa_supplicant_cancel_auth_timeout(wpa_s);
2305 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2306 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2307 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2310 wpa_s->last_eapol_matches_bssid = 0;
2312 if (wpa_s->pending_eapol_rx) {
2313 struct os_reltime now, age;
2314 os_get_reltime(&now);
2315 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2316 if (age.sec == 0 && age.usec < 100000 &&
2317 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2319 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2320 "frame that was received just before "
2321 "association notification");
2322 wpa_supplicant_rx_eapol(
2323 wpa_s, wpa_s->pending_eapol_rx_src,
2324 wpabuf_head(wpa_s->pending_eapol_rx),
2325 wpabuf_len(wpa_s->pending_eapol_rx));
2327 wpabuf_free(wpa_s->pending_eapol_rx);
2328 wpa_s->pending_eapol_rx = NULL;
2331 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2332 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2333 wpa_s->current_ssid &&
2334 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2335 /* Set static WEP keys again */
2336 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2339 #ifdef CONFIG_IBSS_RSN
2340 if (wpa_s->current_ssid &&
2341 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2342 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2343 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2344 wpa_s->ibss_rsn == NULL) {
2345 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2346 if (!wpa_s->ibss_rsn) {
2347 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2348 wpa_supplicant_deauthenticate(
2349 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2353 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2355 #endif /* CONFIG_IBSS_RSN */
2357 wpas_wps_notify_assoc(wpa_s, bssid);
2360 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2361 data->assoc_info.resp_ies_len,
2362 &data->assoc_info.wmm_params);
2364 if (wpa_s->reassoc_same_bss)
2365 wmm_ac_restore_tspecs(wpa_s);
2370 static int disconnect_reason_recoverable(u16 reason_code)
2372 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2373 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2374 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2378 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2380 int locally_generated)
2384 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2386 * At least Host AP driver and a Prism3 card seemed to be
2387 * generating streams of disconnected events when configuring
2388 * IBSS for WPA-None. Ignore them for now.
2393 bssid = wpa_s->bssid;
2394 if (is_zero_ether_addr(bssid))
2395 bssid = wpa_s->pending_bssid;
2397 if (!is_zero_ether_addr(bssid) ||
2398 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2399 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2401 MAC2STR(bssid), reason_code,
2402 locally_generated ? " locally_generated=1" : "");
2407 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2408 int locally_generated)
2410 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2411 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2412 return 0; /* Not in 4-way handshake with PSK */
2415 * It looks like connection was lost while trying to go through PSK
2416 * 4-way handshake. Filter out known disconnection cases that are caused
2417 * by something else than PSK mismatch to avoid confusing reports.
2420 if (locally_generated) {
2421 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2429 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2431 int locally_generated)
2435 u8 prev_pending_bssid[ETH_ALEN];
2436 struct wpa_bss *fast_reconnect = NULL;
2437 struct wpa_ssid *fast_reconnect_ssid = NULL;
2438 struct wpa_ssid *last_ssid;
2440 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2441 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2443 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2445 * At least Host AP driver and a Prism3 card seemed to be
2446 * generating streams of disconnected events when configuring
2447 * IBSS for WPA-None. Ignore them for now.
2449 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2450 "IBSS/WPA-None mode");
2454 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2455 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2456 "pre-shared key may be incorrect");
2457 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2458 return; /* P2P group removed */
2459 wpas_auth_failed(wpa_s, "WRONG_KEY");
2461 if (!wpa_s->disconnected &&
2462 (!wpa_s->auto_reconnect_disabled ||
2463 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2464 wpas_wps_searching(wpa_s) ||
2465 wpas_wps_reenable_networks_pending(wpa_s))) {
2466 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2467 "reconnect (wps=%d/%d wpa_state=%d)",
2468 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2469 wpas_wps_searching(wpa_s),
2471 if (wpa_s->wpa_state == WPA_COMPLETED &&
2472 wpa_s->current_ssid &&
2473 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2474 !locally_generated &&
2475 disconnect_reason_recoverable(reason_code)) {
2477 * It looks like the AP has dropped association with
2478 * us, but could allow us to get back in. Try to
2479 * reconnect to the same BSS without full scan to save
2480 * time for some common cases.
2482 fast_reconnect = wpa_s->current_bss;
2483 fast_reconnect_ssid = wpa_s->current_ssid;
2484 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2485 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2487 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2490 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2491 "try to re-connect");
2492 wpa_s->reassociate = 0;
2493 wpa_s->disconnected = 1;
2495 wpa_supplicant_cancel_sched_scan(wpa_s);
2497 bssid = wpa_s->bssid;
2498 if (is_zero_ether_addr(bssid))
2499 bssid = wpa_s->pending_bssid;
2500 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2501 wpas_connection_failed(wpa_s, bssid);
2502 wpa_sm_notify_disassoc(wpa_s->wpa);
2503 if (locally_generated)
2504 wpa_s->disconnect_reason = -reason_code;
2506 wpa_s->disconnect_reason = reason_code;
2507 wpas_notify_disconnect_reason(wpa_s);
2508 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2509 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2510 wpa_clear_keys(wpa_s, wpa_s->bssid);
2512 last_ssid = wpa_s->current_ssid;
2513 wpa_supplicant_mark_disassoc(wpa_s);
2515 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2516 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2517 wpa_s->current_ssid = last_ssid;
2520 if (fast_reconnect &&
2521 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2522 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2523 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2524 fast_reconnect->ssid_len) &&
2525 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2526 #ifndef CONFIG_NO_SCAN_PROCESSING
2527 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2528 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2529 fast_reconnect_ssid) < 0) {
2530 /* Recover through full scan */
2531 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2533 #endif /* CONFIG_NO_SCAN_PROCESSING */
2534 } else if (fast_reconnect) {
2536 * Could not reconnect to the same BSS due to network being
2537 * disabled. Use a new scan to match the alternative behavior
2538 * above, i.e., to continue automatic reconnection attempt in a
2539 * way that enforces disabled network rules.
2541 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2546 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2547 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2549 struct wpa_supplicant *wpa_s = eloop_ctx;
2551 if (!wpa_s->pending_mic_error_report)
2554 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2555 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2556 wpa_s->pending_mic_error_report = 0;
2558 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2562 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2563 union wpa_event_data *data)
2566 struct os_reltime t;
2568 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2569 pairwise = (data && data->michael_mic_failure.unicast);
2571 if ((wpa_s->last_michael_mic_error.sec &&
2572 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2573 wpa_s->pending_mic_error_report) {
2574 if (wpa_s->pending_mic_error_report) {
2576 * Send the pending MIC error report immediately since
2577 * we are going to start countermeasures and AP better
2580 wpa_sm_key_request(wpa_s->wpa, 1,
2581 wpa_s->pending_mic_error_pairwise);
2584 /* Send the new MIC error report immediately since we are going
2585 * to start countermeasures and AP better do the same.
2587 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2589 /* initialize countermeasures */
2590 wpa_s->countermeasures = 1;
2592 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2594 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2597 * Need to wait for completion of request frame. We do not get
2598 * any callback for the message completion, so just wait a
2599 * short while and hope for the best. */
2602 wpa_drv_set_countermeasures(wpa_s, 1);
2603 wpa_supplicant_deauthenticate(wpa_s,
2604 WLAN_REASON_MICHAEL_MIC_FAILURE);
2605 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2607 eloop_register_timeout(60, 0,
2608 wpa_supplicant_stop_countermeasures,
2610 /* TODO: mark the AP rejected for 60 second. STA is
2611 * allowed to associate with another AP.. */
2613 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2614 if (wpa_s->mic_errors_seen) {
2616 * Reduce the effectiveness of Michael MIC error
2617 * reports as a means for attacking against TKIP if
2618 * more than one MIC failure is noticed with the same
2619 * PTK. We delay the transmission of the reports by a
2620 * random time between 0 and 60 seconds in order to
2621 * force the attacker wait 60 seconds before getting
2622 * the information on whether a frame resulted in a MIC
2628 if (os_get_random(rval, sizeof(rval)) < 0)
2629 sec = os_random() % 60;
2631 sec = WPA_GET_BE32(rval) % 60;
2632 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2633 "report %d seconds", sec);
2634 wpa_s->pending_mic_error_report = 1;
2635 wpa_s->pending_mic_error_pairwise = pairwise;
2636 eloop_cancel_timeout(
2637 wpa_supplicant_delayed_mic_error_report,
2639 eloop_register_timeout(
2640 sec, os_random() % 1000000,
2641 wpa_supplicant_delayed_mic_error_report,
2644 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2646 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2647 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2648 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2650 wpa_s->last_michael_mic_error = t;
2651 wpa_s->mic_errors_seen++;
2655 #ifdef CONFIG_TERMINATE_ONLASTIF
2656 static int any_interfaces(struct wpa_supplicant *head)
2658 struct wpa_supplicant *wpa_s;
2660 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2661 if (!wpa_s->interface_removed)
2665 #endif /* CONFIG_TERMINATE_ONLASTIF */
2669 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2670 union wpa_event_data *data)
2672 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2675 switch (data->interface_status.ievent) {
2676 case EVENT_INTERFACE_ADDED:
2677 if (!wpa_s->interface_removed)
2679 wpa_s->interface_removed = 0;
2680 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2681 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2682 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2683 "driver after interface was added");
2687 if (!wpa_s->global->p2p &&
2688 !wpa_s->global->p2p_disabled &&
2689 !wpa_s->conf->p2p_disabled &&
2691 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2692 wpas_p2p_add_p2pdev_interface(
2693 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2694 wpa_printf(MSG_INFO,
2695 "P2P: Failed to enable P2P Device interface");
2696 /* Try to continue without. P2P will be disabled. */
2698 #endif /* CONFIG_P2P */
2701 case EVENT_INTERFACE_REMOVED:
2702 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2703 wpa_s->interface_removed = 1;
2704 wpa_supplicant_mark_disassoc(wpa_s);
2705 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2706 l2_packet_deinit(wpa_s->l2);
2710 if (wpa_s->global->p2p &&
2711 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2713 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2714 wpa_dbg(wpa_s, MSG_DEBUG,
2715 "Removing P2P Device interface");
2716 wpa_supplicant_remove_iface(
2717 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2719 wpa_s->global->p2p_init_wpa_s = NULL;
2721 #endif /* CONFIG_P2P */
2723 #ifdef CONFIG_TERMINATE_ONLASTIF
2724 /* check if last interface */
2725 if (!any_interfaces(wpa_s->global->ifaces))
2727 #endif /* CONFIG_TERMINATE_ONLASTIF */
2733 #ifdef CONFIG_PEERKEY
2735 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2736 union wpa_event_data *data)
2740 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2742 #endif /* CONFIG_PEERKEY */
2746 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2747 union wpa_event_data *data)
2751 switch (data->tdls.oper) {
2752 case TDLS_REQUEST_SETUP:
2753 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2754 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2755 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2757 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2759 case TDLS_REQUEST_TEARDOWN:
2760 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2761 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2762 data->tdls.reason_code);
2764 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2767 case TDLS_REQUEST_DISCOVER:
2768 wpa_tdls_send_discovery_request(wpa_s->wpa,
2773 #endif /* CONFIG_TDLS */
2777 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2778 union wpa_event_data *data)
2782 switch (data->wnm.oper) {
2783 case WNM_OPER_SLEEP:
2784 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2785 "(action=%d, intval=%d)",
2786 data->wnm.sleep_action, data->wnm.sleep_intval);
2787 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2788 data->wnm.sleep_intval, NULL);
2792 #endif /* CONFIG_WNM */
2795 #ifdef CONFIG_IEEE80211R
2797 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2798 union wpa_event_data *data)
2803 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2804 data->ft_ies.ies_len,
2805 data->ft_ies.ft_action,
2806 data->ft_ies.target_ap,
2807 data->ft_ies.ric_ies,
2808 data->ft_ies.ric_ies_len) < 0) {
2809 /* TODO: prevent MLME/driver from trying to associate? */
2812 #endif /* CONFIG_IEEE80211R */
2815 #ifdef CONFIG_IBSS_RSN
2816 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2817 union wpa_event_data *data)
2819 struct wpa_ssid *ssid;
2820 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2824 ssid = wpa_s->current_ssid;
2827 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2830 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2834 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2835 union wpa_event_data *data)
2837 struct wpa_ssid *ssid = wpa_s->current_ssid;
2842 /* check if the ssid is correctly configured as IBSS/RSN */
2843 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2846 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2847 data->rx_mgmt.frame_len);
2849 #endif /* CONFIG_IBSS_RSN */
2852 #ifdef CONFIG_IEEE80211R
2853 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2856 const u8 *sta_addr, *target_ap_addr;
2859 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2860 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2861 return; /* only SME case supported for now */
2862 if (len < 1 + 2 * ETH_ALEN + 2)
2865 return; /* Only FT Action Response is supported for now */
2866 sta_addr = data + 1;
2867 target_ap_addr = data + 1 + ETH_ALEN;
2868 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2869 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2870 MACSTR " TargetAP " MACSTR " status %u",
2871 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2873 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2874 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2875 " in FT Action Response", MAC2STR(sta_addr));
2880 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2881 "failure (status code %d)", status);
2882 /* TODO: report error to FT code(?) */
2886 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2887 len - (1 + 2 * ETH_ALEN + 2), 1,
2888 target_ap_addr, NULL, 0) < 0)
2893 struct wpa_bss *bss;
2894 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2896 wpa_s->sme.freq = bss->freq;
2897 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2898 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2901 #endif /* CONFIG_SME */
2903 #endif /* CONFIG_IEEE80211R */
2906 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2907 struct unprot_deauth *e)
2909 #ifdef CONFIG_IEEE80211W
2910 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2911 "dropped: " MACSTR " -> " MACSTR
2912 " (reason code %u)",
2913 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2914 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2915 #endif /* CONFIG_IEEE80211W */
2919 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2920 struct unprot_disassoc *e)
2922 #ifdef CONFIG_IEEE80211W
2923 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2924 "dropped: " MACSTR " -> " MACSTR
2925 " (reason code %u)",
2926 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2927 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2928 #endif /* CONFIG_IEEE80211W */
2932 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2933 u16 reason_code, int locally_generated,
2934 const u8 *ie, size_t ie_len, int deauth)
2937 if (wpa_s->ap_iface && addr) {
2938 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2942 if (wpa_s->ap_iface) {
2943 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2946 #endif /* CONFIG_AP */
2948 if (!locally_generated)
2949 wpa_s->own_disconnect_req = 0;
2951 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2953 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2954 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2955 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2956 eapol_sm_failed(wpa_s->eapol))) &&
2957 !wpa_s->eap_expected_failure))
2958 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2961 if (deauth && reason_code > 0) {
2962 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2963 locally_generated) > 0) {
2965 * The interface was removed, so cannot continue
2966 * processing any additional operations after this.
2971 #endif /* CONFIG_P2P */
2973 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2978 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2979 struct disassoc_info *info)
2981 u16 reason_code = 0;
2982 int locally_generated = 0;
2983 const u8 *addr = NULL;
2984 const u8 *ie = NULL;
2987 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2992 ie_len = info->ie_len;
2993 reason_code = info->reason_code;
2994 locally_generated = info->locally_generated;
2995 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2996 locally_generated ? " (locally generated)" : "");
2998 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3000 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3005 if (wpa_s->ap_iface && info && info->addr) {
3006 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3010 if (wpa_s->ap_iface) {
3011 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3014 #endif /* CONFIG_AP */
3018 wpas_p2p_disassoc_notif(
3019 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3022 #endif /* CONFIG_P2P */
3024 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3025 sme_event_disassoc(wpa_s, info);
3027 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3032 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3033 struct deauth_info *info)
3035 u16 reason_code = 0;
3036 int locally_generated = 0;
3037 const u8 *addr = NULL;
3038 const u8 *ie = NULL;
3041 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3046 ie_len = info->ie_len;
3047 reason_code = info->reason_code;
3048 locally_generated = info->locally_generated;
3049 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3051 locally_generated ? " (locally generated)" : "");
3053 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3056 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3060 wpa_reset_ft_completed(wpa_s->wpa);
3062 wpas_event_disconnect(wpa_s, addr, reason_code,
3063 locally_generated, ie, ie_len, 1);
3067 static const char * reg_init_str(enum reg_change_initiator init)
3070 case REGDOM_SET_BY_CORE:
3072 case REGDOM_SET_BY_USER:
3074 case REGDOM_SET_BY_DRIVER:
3076 case REGDOM_SET_BY_COUNTRY_IE:
3077 return "COUNTRY_IE";
3078 case REGDOM_BEACON_HINT:
3079 return "BEACON_HINT";
3085 static const char * reg_type_str(enum reg_type type)
3088 case REGDOM_TYPE_UNKNOWN:
3090 case REGDOM_TYPE_COUNTRY:
3092 case REGDOM_TYPE_WORLD:
3094 case REGDOM_TYPE_CUSTOM_WORLD:
3095 return "CUSTOM_WORLD";
3096 case REGDOM_TYPE_INTERSECTION:
3097 return "INTERSECTION";
3103 static void wpa_supplicant_update_channel_list(
3104 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3106 struct wpa_supplicant *ifs;
3108 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3109 reg_init_str(info->initiator), reg_type_str(info->type),
3110 info->alpha2[0] ? " alpha2=" : "",
3111 info->alpha2[0] ? info->alpha2 : "");
3113 if (wpa_s->drv_priv == NULL)
3114 return; /* Ignore event during drv initialization */
3116 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3118 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3120 free_hw_features(ifs);
3121 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3122 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3125 /* Restart sched_scan with updated channel list */
3126 if (wpa_s->sched_scanning) {
3127 wpa_dbg(wpa_s, MSG_DEBUG,
3128 "Channel list changed restart sched scan.");
3129 wpa_supplicant_cancel_sched_scan(wpa_s);
3130 wpa_supplicant_req_scan(wpa_s, 0, 0);
3133 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3137 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3138 const u8 *frame, size_t len, int freq,
3141 const struct ieee80211_mgmt *mgmt;
3146 if (len < IEEE80211_HDRLEN + 2)
3149 mgmt = (const struct ieee80211_mgmt *) frame;
3150 payload = frame + IEEE80211_HDRLEN;
3151 category = *payload++;
3152 plen = len - IEEE80211_HDRLEN - 1;
3154 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3155 " Category=%u DataLen=%d freq=%d MHz",
3156 MAC2STR(mgmt->sa), category, (int) plen, freq);
3158 if (category == WLAN_ACTION_WMM) {
3159 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3163 #ifdef CONFIG_IEEE80211R
3164 if (category == WLAN_ACTION_FT) {
3165 ft_rx_action(wpa_s, payload, plen);
3168 #endif /* CONFIG_IEEE80211R */
3170 #ifdef CONFIG_IEEE80211W
3172 if (category == WLAN_ACTION_SA_QUERY) {
3173 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3176 #endif /* CONFIG_SME */
3177 #endif /* CONFIG_IEEE80211W */
3180 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3181 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3184 #endif /* CONFIG_WNM */
3187 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3188 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3189 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3190 mgmt->u.action.category,
3191 payload, plen, freq) == 0)
3193 #endif /* CONFIG_GAS */
3196 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3197 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3198 wpa_dbg(wpa_s, MSG_DEBUG,
3199 "TDLS: Received Discovery Response from " MACSTR,
3203 #endif /* CONFIG_TDLS */
3205 #ifdef CONFIG_INTERWORKING
3206 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3207 payload[0] == QOS_QOS_MAP_CONFIG) {
3208 const u8 *pos = payload + 1;
3209 size_t qlen = plen - 1;
3210 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3211 MACSTR, MAC2STR(mgmt->sa));
3212 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3213 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3214 pos[1] <= qlen - 2 && pos[1] >= 16)
3215 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3218 #endif /* CONFIG_INTERWORKING */
3220 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3221 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3222 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3226 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3227 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3228 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3229 payload + 1, plen - 1,
3235 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3236 fst_rx_action(wpa_s->fst, mgmt, len);
3239 #endif /* CONFIG_FST */
3241 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3242 category, payload, plen, freq);
3244 mesh_mpm_action_rx(wpa_s, mgmt, len);
3248 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3249 union wpa_event_data *event)
3251 struct wpa_freq_range_list *list;
3254 list = &event->freq_range;
3257 str = freq_range_list_str(list);
3258 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3262 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3263 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3266 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3269 * The update channel flow will also take care of moving a GO
3270 * from the unsafe frequency if needed.
3272 wpas_p2p_update_channel_list(wpa_s,
3273 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3275 #endif /* CONFIG_P2P */
3281 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3282 union wpa_event_data *data)
3284 wpa_dbg(wpa_s, MSG_DEBUG,
3285 "Connection authorized by device, previous state %d",
3287 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3288 wpa_supplicant_cancel_auth_timeout(wpa_s);
3289 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3290 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3291 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3293 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3294 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3295 data->assoc_info.ptk_kck_len,
3296 data->assoc_info.ptk_kek,
3297 data->assoc_info.ptk_kek_len);
3301 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3302 union wpa_event_data *data)
3304 struct wpa_supplicant *wpa_s = ctx;
3307 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3308 event != EVENT_INTERFACE_ENABLED &&
3309 event != EVENT_INTERFACE_STATUS &&
3310 event != EVENT_SCHED_SCAN_STOPPED) {
3311 wpa_dbg(wpa_s, MSG_DEBUG,
3312 "Ignore event %s (%d) while interface is disabled",
3313 event_to_string(event), event);
3317 #ifndef CONFIG_NO_STDOUT_DEBUG
3319 int level = MSG_DEBUG;
3321 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3322 const struct ieee80211_hdr *hdr;
3324 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3325 fc = le_to_host16(hdr->frame_control);
3326 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3327 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3328 level = MSG_EXCESSIVE;
3331 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3332 event_to_string(event), event);
3334 #endif /* CONFIG_NO_STDOUT_DEBUG */
3339 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3340 data->auth.ies_len))
3341 wpa_printf(MSG_DEBUG,
3342 "FST: MB IEs updated from auth IE");
3343 #endif /* CONFIG_FST */
3344 sme_event_auth(wpa_s, data);
3347 wpa_supplicant_event_assoc(wpa_s, data);
3348 if (data && data->assoc_info.authorized)
3349 wpa_supplicant_event_assoc_auth(wpa_s, data);
3351 wpa_msg(wpa_s, MSG_INFO,
3352 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3353 data->assoc_info.subnet_status);
3356 case EVENT_DISASSOC:
3357 wpas_event_disassoc(wpa_s,
3358 data ? &data->disassoc_info : NULL);
3361 wpas_event_deauth(wpa_s,
3362 data ? &data->deauth_info : NULL);
3364 case EVENT_MICHAEL_MIC_FAILURE:
3365 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3367 #ifndef CONFIG_NO_SCAN_PROCESSING
3368 case EVENT_SCAN_STARTED:
3369 if (wpa_s->own_scan_requested ||
3370 (data && !data->scan_info.external_scan)) {
3371 struct os_reltime diff;
3373 os_get_reltime(&wpa_s->scan_start_time);
3374 os_reltime_sub(&wpa_s->scan_start_time,
3375 &wpa_s->scan_trigger_time, &diff);
3376 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3377 diff.sec, diff.usec);
3378 wpa_s->own_scan_requested = 0;
3379 wpa_s->own_scan_running = 1;
3380 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3381 wpa_s->manual_scan_use_id) {
3382 wpa_msg_ctrl(wpa_s, MSG_INFO,
3383 WPA_EVENT_SCAN_STARTED "id=%u",
3384 wpa_s->manual_scan_id);
3386 wpa_msg_ctrl(wpa_s, MSG_INFO,
3387 WPA_EVENT_SCAN_STARTED);
3390 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3391 wpa_s->radio->external_scan_running = 1;
3392 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3395 case EVENT_SCAN_RESULTS:
3396 if (!(data && data->scan_info.external_scan) &&
3397 os_reltime_initialized(&wpa_s->scan_start_time)) {
3398 struct os_reltime now, diff;
3399 os_get_reltime(&now);
3400 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3401 wpa_s->scan_start_time.sec = 0;
3402 wpa_s->scan_start_time.usec = 0;
3403 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3404 diff.sec, diff.usec);
3406 if (wpa_supplicant_event_scan_results(wpa_s, data))
3407 break; /* interface may have been removed */
3408 if (!(data && data->scan_info.external_scan))
3409 wpa_s->own_scan_running = 0;
3410 if (data && data->scan_info.nl_scan_event)
3411 wpa_s->radio->external_scan_running = 0;
3412 radio_work_check_next(wpa_s);
3414 #endif /* CONFIG_NO_SCAN_PROCESSING */
3415 case EVENT_ASSOCINFO:
3416 wpa_supplicant_event_associnfo(wpa_s, data);
3418 case EVENT_INTERFACE_STATUS:
3419 wpa_supplicant_event_interface_status(wpa_s, data);
3421 case EVENT_PMKID_CANDIDATE:
3422 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3424 #ifdef CONFIG_PEERKEY
3425 case EVENT_STKSTART:
3426 wpa_supplicant_event_stkstart(wpa_s, data);
3428 #endif /* CONFIG_PEERKEY */
3431 wpa_supplicant_event_tdls(wpa_s, data);
3433 #endif /* CONFIG_TDLS */
3436 wpa_supplicant_event_wnm(wpa_s, data);
3438 #endif /* CONFIG_WNM */
3439 #ifdef CONFIG_IEEE80211R
3440 case EVENT_FT_RESPONSE:
3441 wpa_supplicant_event_ft_response(wpa_s, data);
3443 #endif /* CONFIG_IEEE80211R */
3444 #ifdef CONFIG_IBSS_RSN
3445 case EVENT_IBSS_RSN_START:
3446 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3448 #endif /* CONFIG_IBSS_RSN */
3449 case EVENT_ASSOC_REJECT:
3450 if (data->assoc_reject.bssid)
3451 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3452 "bssid=" MACSTR " status_code=%u",
3453 MAC2STR(data->assoc_reject.bssid),
3454 data->assoc_reject.status_code);
3456 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3458 data->assoc_reject.status_code);
3459 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3460 sme_event_assoc_reject(wpa_s, data);
3462 const u8 *bssid = data->assoc_reject.bssid;
3463 if (bssid == NULL || is_zero_ether_addr(bssid))
3464 bssid = wpa_s->pending_bssid;
3465 wpas_connection_failed(wpa_s, bssid);
3466 wpa_supplicant_mark_disassoc(wpa_s);
3469 case EVENT_AUTH_TIMED_OUT:
3470 /* It is possible to get this event from earlier connection */
3471 if (wpa_s->current_ssid &&
3472 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3473 wpa_dbg(wpa_s, MSG_DEBUG,
3474 "Ignore AUTH_TIMED_OUT in mesh configuration");
3477 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3478 sme_event_auth_timed_out(wpa_s, data);
3480 case EVENT_ASSOC_TIMED_OUT:
3481 /* It is possible to get this event from earlier connection */
3482 if (wpa_s->current_ssid &&
3483 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3484 wpa_dbg(wpa_s, MSG_DEBUG,
3485 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3488 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3489 sme_event_assoc_timed_out(wpa_s, data);
3491 case EVENT_TX_STATUS:
3492 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3493 " type=%d stype=%d",
3494 MAC2STR(data->tx_status.dst),
3495 data->tx_status.type, data->tx_status.stype);
3497 if (wpa_s->ap_iface == NULL) {
3498 #ifdef CONFIG_OFFCHANNEL
3499 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3500 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3501 offchannel_send_action_tx_status(
3502 wpa_s, data->tx_status.dst,
3503 data->tx_status.data,
3504 data->tx_status.data_len,
3505 data->tx_status.ack ?
3506 OFFCHANNEL_SEND_ACTION_SUCCESS :
3507 OFFCHANNEL_SEND_ACTION_NO_ACK);
3508 #endif /* CONFIG_OFFCHANNEL */
3511 #endif /* CONFIG_AP */
3512 #ifdef CONFIG_OFFCHANNEL
3513 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3514 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3516 * Catch TX status events for Action frames we sent via group
3517 * interface in GO mode.
3519 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3520 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3521 os_memcmp(wpa_s->parent->pending_action_dst,
3522 data->tx_status.dst, ETH_ALEN) == 0) {
3523 offchannel_send_action_tx_status(
3524 wpa_s->parent, data->tx_status.dst,
3525 data->tx_status.data,
3526 data->tx_status.data_len,
3527 data->tx_status.ack ?
3528 OFFCHANNEL_SEND_ACTION_SUCCESS :
3529 OFFCHANNEL_SEND_ACTION_NO_ACK);
3532 #endif /* CONFIG_OFFCHANNEL */
3534 switch (data->tx_status.type) {
3535 case WLAN_FC_TYPE_MGMT:
3536 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3537 data->tx_status.data_len,
3538 data->tx_status.stype,
3539 data->tx_status.ack);
3541 case WLAN_FC_TYPE_DATA:
3542 ap_tx_status(wpa_s, data->tx_status.dst,
3543 data->tx_status.data,
3544 data->tx_status.data_len,
3545 data->tx_status.ack);
3548 #endif /* CONFIG_AP */
3551 case EVENT_EAPOL_TX_STATUS:
3552 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3553 data->eapol_tx_status.data,
3554 data->eapol_tx_status.data_len,
3555 data->eapol_tx_status.ack);
3557 case EVENT_DRIVER_CLIENT_POLL_OK:
3558 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3560 case EVENT_RX_FROM_UNKNOWN:
3561 if (wpa_s->ap_iface == NULL)
3563 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3564 data->rx_from_unknown.wds);
3566 case EVENT_CH_SWITCH:
3567 if (!data || !wpa_s->current_ssid)
3570 wpa_s->assoc_freq = data->ch_switch.freq;
3571 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3573 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3574 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3575 wpa_s->current_ssid->mode ==
3576 WPAS_MODE_P2P_GROUP_FORMATION) {
3577 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3578 data->ch_switch.ht_enabled,
3579 data->ch_switch.ch_offset,
3580 data->ch_switch.ch_width,
3581 data->ch_switch.cf1,
3582 data->ch_switch.cf2);
3585 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3588 case EVENT_DFS_RADAR_DETECTED:
3590 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3592 case EVENT_DFS_CAC_STARTED:
3594 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3596 case EVENT_DFS_CAC_FINISHED:
3598 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3600 case EVENT_DFS_CAC_ABORTED:
3602 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3604 case EVENT_DFS_NOP_FINISHED:
3606 wpas_event_dfs_cac_nop_finished(wpa_s,
3609 #endif /* NEED_AP_MLME */
3610 #endif /* CONFIG_AP */
3611 case EVENT_RX_MGMT: {
3613 const struct ieee80211_mgmt *mgmt;
3615 #ifdef CONFIG_TESTING_OPTIONS
3616 if (wpa_s->ext_mgmt_frame_handling) {
3617 struct rx_mgmt *rx = &data->rx_mgmt;
3618 size_t hex_len = 2 * rx->frame_len + 1;
3619 char *hex = os_malloc(hex_len);
3621 wpa_snprintf_hex(hex, hex_len,
3622 rx->frame, rx->frame_len);
3623 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3624 rx->freq, rx->datarate, rx->ssi_signal,
3630 #endif /* CONFIG_TESTING_OPTIONS */
3632 mgmt = (const struct ieee80211_mgmt *)
3633 data->rx_mgmt.frame;
3634 fc = le_to_host16(mgmt->frame_control);
3635 stype = WLAN_FC_GET_STYPE(fc);
3638 if (wpa_s->ap_iface == NULL) {
3639 #endif /* CONFIG_AP */
3641 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3642 data->rx_mgmt.frame_len > 24) {
3643 const u8 *src = mgmt->sa;
3644 const u8 *ie = mgmt->u.probe_req.variable;
3645 size_t ie_len = data->rx_mgmt.frame_len -
3646 (mgmt->u.probe_req.variable -
3647 data->rx_mgmt.frame);
3648 wpas_p2p_probe_req_rx(
3649 wpa_s, src, mgmt->da,
3650 mgmt->bssid, ie, ie_len,
3652 data->rx_mgmt.ssi_signal);
3655 #endif /* CONFIG_P2P */
3656 #ifdef CONFIG_IBSS_RSN
3657 if (wpa_s->current_ssid &&
3658 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3659 stype == WLAN_FC_STYPE_AUTH &&
3660 data->rx_mgmt.frame_len >= 30) {
3661 wpa_supplicant_event_ibss_auth(wpa_s, data);
3664 #endif /* CONFIG_IBSS_RSN */
3666 if (stype == WLAN_FC_STYPE_ACTION) {
3667 wpas_event_rx_mgmt_action(
3668 wpa_s, data->rx_mgmt.frame,
3669 data->rx_mgmt.frame_len,
3671 data->rx_mgmt.ssi_signal);
3676 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3680 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3681 "management frame in non-AP mode");
3686 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3687 data->rx_mgmt.frame_len > 24) {
3688 const u8 *ie = mgmt->u.probe_req.variable;
3689 size_t ie_len = data->rx_mgmt.frame_len -
3690 (mgmt->u.probe_req.variable -
3691 data->rx_mgmt.frame);
3693 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3694 mgmt->bssid, ie, ie_len,
3695 data->rx_mgmt.ssi_signal);
3698 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3699 #endif /* CONFIG_AP */
3702 case EVENT_RX_PROBE_REQ:
3703 if (data->rx_probe_req.sa == NULL ||
3704 data->rx_probe_req.ie == NULL)
3707 if (wpa_s->ap_iface) {
3708 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3709 data->rx_probe_req.sa,
3710 data->rx_probe_req.da,
3711 data->rx_probe_req.bssid,
3712 data->rx_probe_req.ie,
3713 data->rx_probe_req.ie_len,
3714 data->rx_probe_req.ssi_signal);
3717 #endif /* CONFIG_AP */
3718 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3719 data->rx_probe_req.da,
3720 data->rx_probe_req.bssid,
3721 data->rx_probe_req.ie,
3722 data->rx_probe_req.ie_len,
3724 data->rx_probe_req.ssi_signal);
3726 case EVENT_REMAIN_ON_CHANNEL:
3727 #ifdef CONFIG_OFFCHANNEL
3728 offchannel_remain_on_channel_cb(
3729 wpa_s, data->remain_on_channel.freq,
3730 data->remain_on_channel.duration);
3731 #endif /* CONFIG_OFFCHANNEL */
3732 wpas_p2p_remain_on_channel_cb(
3733 wpa_s, data->remain_on_channel.freq,
3734 data->remain_on_channel.duration);
3736 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3737 #ifdef CONFIG_OFFCHANNEL
3738 offchannel_cancel_remain_on_channel_cb(
3739 wpa_s, data->remain_on_channel.freq);
3740 #endif /* CONFIG_OFFCHANNEL */
3741 wpas_p2p_cancel_remain_on_channel_cb(
3742 wpa_s, data->remain_on_channel.freq);
3744 case EVENT_EAPOL_RX:
3745 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3746 data->eapol_rx.data,
3747 data->eapol_rx.data_len);
3749 case EVENT_SIGNAL_CHANGE:
3750 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3751 "above=%d signal=%d noise=%d txrate=%d",
3752 data->signal_change.above_threshold,
3753 data->signal_change.current_signal,
3754 data->signal_change.current_noise,
3755 data->signal_change.current_txrate);
3756 wpa_bss_update_level(wpa_s->current_bss,
3757 data->signal_change.current_signal);
3758 bgscan_notify_signal_change(
3759 wpa_s, data->signal_change.above_threshold,
3760 data->signal_change.current_signal,
3761 data->signal_change.current_noise,
3762 data->signal_change.current_txrate);
3764 case EVENT_INTERFACE_ENABLED:
3765 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3766 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3767 wpa_supplicant_update_mac_addr(wpa_s);
3768 if (wpa_s->p2p_mgmt) {
3769 wpa_supplicant_set_state(wpa_s,
3775 if (!wpa_s->ap_iface) {
3776 wpa_supplicant_set_state(wpa_s,
3778 wpa_s->scan_req = NORMAL_SCAN_REQ;
3779 wpa_supplicant_req_scan(wpa_s, 0, 0);
3781 wpa_supplicant_set_state(wpa_s,
3783 #else /* CONFIG_AP */
3784 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3785 wpa_supplicant_req_scan(wpa_s, 0, 0);
3786 #endif /* CONFIG_AP */
3789 case EVENT_INTERFACE_DISABLED:
3790 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3792 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3793 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3794 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3796 * Mark interface disabled if this happens to end up not
3797 * being removed as a separate P2P group interface.
3799 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3801 * The interface was externally disabled. Remove
3802 * it assuming an external entity will start a
3803 * new session if needed.
3805 if (wpa_s->current_ssid &&
3806 wpa_s->current_ssid->p2p_group)
3807 wpas_p2p_interface_unavailable(wpa_s);
3809 wpas_p2p_disconnect(wpa_s);
3811 * wpa_s instance may have been freed, so must not use
3816 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3817 p2p_in_progress(wpa_s->global->p2p) > 1) {
3818 /* This radio work will be cancelled, so clear P2P
3821 p2p_stop_find(wpa_s->global->p2p);
3823 #endif /* CONFIG_P2P */
3825 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3827 * Indicate disconnection to keep ctrl_iface events
3830 wpa_supplicant_event_disassoc(
3831 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3833 wpa_supplicant_mark_disassoc(wpa_s);
3834 radio_remove_works(wpa_s, NULL, 0);
3836 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3838 case EVENT_CHANNEL_LIST_CHANGED:
3839 wpa_supplicant_update_channel_list(
3840 wpa_s, &data->channel_list_changed);
3842 case EVENT_INTERFACE_UNAVAILABLE:
3843 wpas_p2p_interface_unavailable(wpa_s);
3845 case EVENT_BEST_CHANNEL:
3846 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3848 data->best_chan.freq_24, data->best_chan.freq_5,
3849 data->best_chan.freq_overall);
3850 wpa_s->best_24_freq = data->best_chan.freq_24;
3851 wpa_s->best_5_freq = data->best_chan.freq_5;
3852 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3853 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3854 data->best_chan.freq_5,
3855 data->best_chan.freq_overall);
3857 case EVENT_UNPROT_DEAUTH:
3858 wpa_supplicant_event_unprot_deauth(wpa_s,
3859 &data->unprot_deauth);
3861 case EVENT_UNPROT_DISASSOC:
3862 wpa_supplicant_event_unprot_disassoc(wpa_s,
3863 &data->unprot_disassoc);
3865 case EVENT_STATION_LOW_ACK:
3867 if (wpa_s->ap_iface && data)
3868 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3869 data->low_ack.addr);
3870 #endif /* CONFIG_AP */
3873 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3874 data->low_ack.addr);
3875 #endif /* CONFIG_TDLS */
3877 case EVENT_IBSS_PEER_LOST:
3878 #ifdef CONFIG_IBSS_RSN
3879 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3880 #endif /* CONFIG_IBSS_RSN */
3882 case EVENT_DRIVER_GTK_REKEY:
3883 if (os_memcmp(data->driver_gtk_rekey.bssid,
3884 wpa_s->bssid, ETH_ALEN))
3888 wpa_sm_update_replay_ctr(wpa_s->wpa,
3889 data->driver_gtk_rekey.replay_ctr);
3891 case EVENT_SCHED_SCAN_STOPPED:
3893 wpa_s->sched_scanning = 0;
3894 resched = wpa_s->scanning;
3895 wpa_supplicant_notify_scanning(wpa_s, 0);
3897 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3901 * Start a new sched scan to continue searching for more SSIDs
3902 * either if timed out or PNO schedule scan is pending.
3904 if (wpa_s->sched_scan_timed_out) {
3905 wpa_supplicant_req_sched_scan(wpa_s);
3906 } else if (wpa_s->pno_sched_pending) {
3907 wpa_s->pno_sched_pending = 0;
3908 wpas_start_pno(wpa_s);
3909 } else if (resched) {
3910 wpa_supplicant_req_scan(wpa_s, 0, 0);
3914 case EVENT_WPS_BUTTON_PUSHED:
3916 wpas_wps_start_pbc(wpa_s, NULL, 0);
3917 #endif /* CONFIG_WPS */
3919 case EVENT_AVOID_FREQUENCIES:
3920 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3922 case EVENT_CONNECT_FAILED_REASON:
3924 if (!wpa_s->ap_iface || !data)
3926 hostapd_event_connect_failed_reason(
3927 wpa_s->ap_iface->bss[0],
3928 data->connect_failed_reason.addr,
3929 data->connect_failed_reason.code);
3930 #endif /* CONFIG_AP */
3932 case EVENT_NEW_PEER_CANDIDATE:
3934 if (!wpa_s->ifmsh || !data)
3936 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3937 data->mesh_peer.ies,
3938 data->mesh_peer.ie_len);
3939 #endif /* CONFIG_MESH */
3943 if (!wpa_s->ap_iface)
3945 hostapd_event_get_survey(wpa_s->ap_iface,
3946 &data->survey_results);
3947 #endif /* CONFIG_AP */
3949 case EVENT_ACS_CHANNEL_SELECTED:
3951 if (!wpa_s->ap_iface)
3953 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
3954 &data->acs_selected_channels);
3955 #endif /* CONFIG_ACS */
3958 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);