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 */
285 /* Clear possibly configured frame filters */
286 wpa_drv_configure_frame_filters(wpa_s, 0);
287 #endif /* CONFIG_HS20 */
289 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
292 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
293 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
294 os_memset(wpa_s->bssid, 0, ETH_ALEN);
295 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
296 sme_clear_on_disassoc(wpa_s);
297 wpa_s->current_bss = NULL;
298 wpa_s->assoc_freq = 0;
301 wpas_notify_bssid_changed(wpa_s);
303 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
304 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
305 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
306 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
307 wpa_s->ap_ies_from_associnfo = 0;
308 wpa_s->current_ssid = NULL;
309 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
312 wpas_rrm_reset(wpa_s);
313 wpa_s->wnmsleep_used = 0;
317 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
319 struct wpa_ie_data ie;
323 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
327 for (i = 0; i < ie.num_pmkid; i++) {
328 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
329 ie.pmkid + i * PMKID_LEN,
331 if (pmksa_set == 0) {
332 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
337 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
338 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
342 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
343 union wpa_event_data *data)
346 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
350 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
351 " index=%d preauth=%d",
352 MAC2STR(data->pmkid_candidate.bssid),
353 data->pmkid_candidate.index,
354 data->pmkid_candidate.preauth);
356 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
357 data->pmkid_candidate.index,
358 data->pmkid_candidate.preauth);
362 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
365 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
368 #ifdef IEEE8021X_EAPOL
369 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
370 wpa_s->current_ssid &&
371 !(wpa_s->current_ssid->eapol_flags &
372 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
373 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
374 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
375 * plaintext or static WEP keys). */
378 #endif /* IEEE8021X_EAPOL */
385 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
386 * @wpa_s: pointer to wpa_supplicant data
387 * @ssid: Configuration data for the network
388 * Returns: 0 on success, -1 on failure
390 * This function is called when starting authentication with a network that is
391 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
393 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
394 struct wpa_ssid *ssid)
396 #ifdef IEEE8021X_EAPOL
398 int aka = 0, sim = 0;
400 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
401 wpa_s->scard != NULL || wpa_s->conf->external_sim)
404 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
408 struct eap_method_type *eap = ssid->eap.eap_methods;
409 while (eap->vendor != EAP_VENDOR_IETF ||
410 eap->method != EAP_TYPE_NONE) {
411 if (eap->vendor == EAP_VENDOR_IETF) {
412 if (eap->method == EAP_TYPE_SIM)
414 else if (eap->method == EAP_TYPE_AKA ||
415 eap->method == EAP_TYPE_AKA_PRIME)
422 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
424 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
425 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
430 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
431 "use SIM, but neither EAP-SIM nor EAP-AKA are "
436 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
437 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
439 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
440 if (wpa_s->scard == NULL) {
441 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
445 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
446 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
447 #endif /* PCSC_FUNCS */
448 #endif /* IEEE8021X_EAPOL */
454 #ifndef CONFIG_NO_SCAN_PROCESSING
456 static int has_wep_key(struct wpa_ssid *ssid)
460 for (i = 0; i < NUM_WEP_KEYS; i++) {
461 if (ssid->wep_key_len[i])
469 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
470 struct wpa_ssid *ssid)
474 if (ssid->mixed_cell)
478 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
480 #endif /* CONFIG_WPS */
482 if (has_wep_key(ssid))
485 #ifdef IEEE8021X_EAPOL
486 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
487 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
488 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
490 #endif /* IEEE8021X_EAPOL */
492 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
495 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
498 if (bss->caps & IEEE80211_CAP_PRIVACY)
504 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
505 struct wpa_ssid *ssid,
508 struct wpa_ie_data ie;
510 const u8 *rsn_ie, *wpa_ie;
514 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
518 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
519 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
520 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
521 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
522 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
524 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
525 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
528 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
529 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
535 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
537 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
542 if (!(ie.proto & ssid->proto)) {
543 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
548 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
549 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
554 if (!(ie.group_cipher & ssid->group_cipher)) {
555 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
560 if (!(ie.key_mgmt & ssid->key_mgmt)) {
561 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
566 #ifdef CONFIG_IEEE80211W
567 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
568 wpas_get_ssid_pmf(wpa_s, ssid) ==
569 MGMT_FRAME_PROTECTION_REQUIRED) {
570 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
574 #endif /* CONFIG_IEEE80211W */
575 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
576 wpas_get_ssid_pmf(wpa_s, ssid) ==
577 NO_MGMT_FRAME_PROTECTION) {
578 wpa_dbg(wpa_s, MSG_DEBUG,
579 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
583 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
584 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
585 wpas_get_ssid_pmf(wpa_s, ssid) !=
586 NO_MGMT_FRAME_PROTECTION) {
587 wpa_dbg(wpa_s, MSG_DEBUG,
588 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
591 #endif /* CONFIG_MBO */
593 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
597 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
598 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
601 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
602 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
608 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
610 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
615 if (!(ie.proto & ssid->proto)) {
616 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
621 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
622 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
627 if (!(ie.group_cipher & ssid->group_cipher)) {
628 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
633 if (!(ie.key_mgmt & ssid->key_mgmt)) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
639 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
643 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
645 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
649 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
650 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
651 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
655 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
656 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
657 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
661 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
662 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
666 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
673 static int freq_allowed(int *freqs, int freq)
680 for (i = 0; freqs[i]; i++)
681 if (freqs[i] == freq)
687 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
689 const struct hostapd_hw_modes *mode = NULL, *modes;
690 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
695 return 1; /* Cannot do matching without knowing band */
697 modes = wpa_s->hw.modes;
700 * The driver does not provide any additional information
701 * about the utilized hardware, so allow the connection attempt
707 for (i = 0; i < wpa_s->hw.num_modes; i++) {
708 for (j = 0; j < modes[i].num_channels; j++) {
709 int freq = modes[i].channels[j].freq;
710 if (freq == bss->freq) {
712 mode->mode == HOSTAPD_MODE_IEEE80211G)
713 break; /* do not allow 802.11b replace
724 for (i = 0; i < (int) sizeof(scan_ie); i++) {
725 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
729 for (j = 2; j < rate_ie[1] + 2; j++) {
730 int flagged = !!(rate_ie[j] & 0x80);
731 int r = (rate_ie[j] & 0x7f) * 5;
734 * IEEE Std 802.11n-2009 7.3.2.2:
735 * The new BSS Membership selector value is encoded
736 * like a legacy basic rate, but it is not a rate and
737 * only indicates if the BSS members are required to
738 * support the mandatory features of Clause 20 [HT PHY]
739 * in order to join the BSS.
741 if (flagged && ((rate_ie[j] & 0x7f) ==
742 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
743 if (!ht_supported(mode)) {
744 wpa_dbg(wpa_s, MSG_DEBUG,
745 " hardware does not support "
752 /* There's also a VHT selector for 802.11ac */
753 if (flagged && ((rate_ie[j] & 0x7f) ==
754 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
755 if (!vht_supported(mode)) {
756 wpa_dbg(wpa_s, MSG_DEBUG,
757 " hardware does not support "
767 /* check for legacy basic rates */
768 for (k = 0; k < mode->num_rates; k++) {
769 if (mode->rates[k] == r)
772 if (k == mode->num_rates) {
774 * IEEE Std 802.11-2007 7.3.2.2 demands that in
775 * order to join a BSS all required rates
776 * have to be supported by the hardware.
778 wpa_dbg(wpa_s, MSG_DEBUG,
779 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
781 bss->freq, mode->mode, mode->num_rates);
792 * Test whether BSS is in an ESS.
793 * This is done differently in DMG (60 GHz) and non-DMG bands
795 static int bss_is_ess(struct wpa_bss *bss)
797 if (bss_is_dmg(bss)) {
798 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
799 IEEE80211_CAP_DMG_AP;
802 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
807 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
811 for (i = 0; i < ETH_ALEN; i++) {
812 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
819 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
823 for (i = 0; i < num; i++) {
824 const u8 *a = list + i * ETH_ALEN * 2;
825 const u8 *m = a + ETH_ALEN;
827 if (match_mac_mask(a, addr, m))
834 struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
835 int i, struct wpa_bss *bss,
836 struct wpa_ssid *group,
839 u8 wpa_ie_len, rsn_ie_len;
841 struct wpa_blacklist *e;
843 struct wpa_ssid *ssid;
846 const u8 *assoc_disallow;
847 #endif /* CONFIG_MBO */
849 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
850 wpa_ie_len = ie ? ie[1] : 0;
852 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
853 rsn_ie_len = ie ? ie[1] : 0;
855 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
858 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
859 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
860 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
861 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
862 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
863 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
864 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
866 osen ? " osen=1" : "");
868 e = wpa_blacklist_get(wpa_s, bss->bssid);
871 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
873 * When only a single network is enabled, we can
874 * trigger blacklisting on the first failure. This
875 * should not be done with multiple enabled networks to
876 * avoid getting forced to move into a worse ESS on
877 * single error if there are no other BSSes of the
882 if (e->count > limit) {
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
884 "(count=%d limit=%d)", e->count, limit);
889 if (bss->ssid_len == 0) {
890 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
894 if (disallowed_bssid(wpa_s, bss->bssid)) {
895 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
899 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
900 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
904 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
906 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
907 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
910 if (wpas_network_disabled(wpa_s, ssid)) {
911 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
915 res = wpas_temp_disabled(wpa_s, ssid);
917 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
918 "temporarily for %d second(s)", res);
923 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
924 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
929 if (wpa && ssid->ssid_len == 0 &&
930 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
933 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
934 /* Only allow wildcard SSID match if an AP
935 * advertises active WPS operation that matches
938 if (ssid->ssid_len == 0 &&
939 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
942 #endif /* CONFIG_WPS */
944 if (ssid->bssid_set && ssid->ssid_len == 0 &&
945 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
949 (bss->ssid_len != ssid->ssid_len ||
950 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
951 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
955 if (ssid->bssid_set &&
956 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
957 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
961 /* check blacklist */
962 if (ssid->num_bssid_blacklist &&
963 addr_in_list(bss->bssid, ssid->bssid_blacklist,
964 ssid->num_bssid_blacklist)) {
965 wpa_dbg(wpa_s, MSG_DEBUG,
966 " skip - BSSID blacklisted");
970 /* if there is a whitelist, only accept those APs */
971 if (ssid->num_bssid_whitelist &&
972 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
973 ssid->num_bssid_whitelist)) {
974 wpa_dbg(wpa_s, MSG_DEBUG,
975 " skip - BSSID not in whitelist");
979 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
983 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
984 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
985 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
986 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
991 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
993 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
997 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
998 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
1003 if (!wpa_supplicant_match_privacy(bss, ssid)) {
1004 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
1009 if (!bss_is_ess(bss) && !bss_is_pbss(bss)) {
1010 wpa_dbg(wpa_s, MSG_DEBUG, " skip - neither ESS nor PBSS network");
1014 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1015 wpa_dbg(wpa_s, MSG_DEBUG, " skip - PBSS mismatch (ssid %d bss %d)",
1016 ssid->pbss, bss_is_pbss(bss));
1020 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1021 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1026 if (!rate_match(wpa_s, bss)) {
1027 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1033 if (ssid->p2p_group &&
1034 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1035 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1036 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1040 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1041 struct wpabuf *p2p_ie;
1042 u8 dev_addr[ETH_ALEN];
1044 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1046 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1049 p2p_ie = wpa_bss_get_vendor_ie_multi(
1050 bss, P2P_IE_VENDOR_TYPE);
1051 if (p2p_ie == NULL) {
1052 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1056 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1057 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1059 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1060 wpabuf_free(p2p_ie);
1063 wpabuf_free(p2p_ie);
1067 * TODO: skip the AP if its P2P IE has Group Formation
1068 * bit set in the P2P Group Capability Bitmap and we
1069 * are not in Group Formation with that device.
1071 #endif /* CONFIG_P2P */
1073 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1075 struct os_reltime diff;
1077 os_reltime_sub(&wpa_s->scan_min_time,
1078 &bss->last_update, &diff);
1079 wpa_dbg(wpa_s, MSG_DEBUG,
1080 " skip - scan result not recent enough (%u.%06u seconds too old)",
1081 (unsigned int) diff.sec,
1082 (unsigned int) diff.usec);
1086 assoc_disallow = wpas_mbo_get_bss_attr(
1087 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1088 if (assoc_disallow && assoc_disallow[1] >= 1) {
1089 wpa_dbg(wpa_s, MSG_DEBUG,
1090 " skip - MBO association disallowed (reason %u)",
1095 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
1096 wpa_dbg(wpa_s, MSG_DEBUG,
1097 " skip - MBO retry delay has not passed yet");
1100 #endif /* CONFIG_MBO */
1102 /* Matching configuration found */
1106 /* No matching configuration found */
1111 static struct wpa_bss *
1112 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1113 struct wpa_ssid *group,
1114 struct wpa_ssid **selected_ssid,
1115 int only_first_ssid)
1119 if (only_first_ssid)
1120 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1123 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1126 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1127 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1128 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1130 if (!*selected_ssid)
1132 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1134 MAC2STR(bss->bssid),
1135 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1143 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1144 struct wpa_ssid **selected_ssid)
1146 struct wpa_bss *selected = NULL;
1148 struct wpa_ssid *next_ssid = NULL;
1149 struct wpa_ssid *ssid;
1151 if (wpa_s->last_scan_res == NULL ||
1152 wpa_s->last_scan_res_used == 0)
1153 return NULL; /* no scan results from last update */
1155 if (wpa_s->next_ssid) {
1156 /* check that next_ssid is still valid */
1157 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1158 if (ssid == wpa_s->next_ssid)
1162 wpa_s->next_ssid = NULL;
1165 while (selected == NULL) {
1166 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1167 if (next_ssid && next_ssid->priority ==
1168 wpa_s->conf->pssid[prio]->priority) {
1169 selected = wpa_supplicant_select_bss(
1170 wpa_s, next_ssid, selected_ssid, 1);
1174 selected = wpa_supplicant_select_bss(
1175 wpa_s, wpa_s->conf->pssid[prio],
1181 if (selected == NULL && wpa_s->blacklist &&
1182 !wpa_s->countermeasures) {
1183 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1184 "blacklist and try again");
1185 wpa_blacklist_clear(wpa_s);
1186 wpa_s->blacklist_cleared++;
1187 } else if (selected == NULL)
1191 ssid = *selected_ssid;
1192 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1193 !ssid->passphrase && !ssid->ext_psk) {
1194 const char *field_name, *txt = NULL;
1196 wpa_dbg(wpa_s, MSG_DEBUG,
1197 "PSK/passphrase not yet available for the selected network");
1199 wpas_notify_network_request(wpa_s, ssid,
1200 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1202 field_name = wpa_supplicant_ctrl_req_to_string(
1203 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1204 if (field_name == NULL)
1207 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1216 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1217 int timeout_sec, int timeout_usec)
1219 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1221 * No networks are enabled; short-circuit request so
1222 * we don't wait timeout seconds before transitioning
1223 * to INACTIVE state.
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1226 "since there are no enabled networks");
1227 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1231 wpa_s->scan_for_connection = 1;
1232 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1236 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1237 struct wpa_bss *selected,
1238 struct wpa_ssid *ssid)
1240 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1241 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1242 "PBC session overlap");
1243 wpas_notify_wps_event_pbc_overlap(wpa_s);
1245 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1246 wpa_s->p2p_in_provisioning) {
1247 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1251 #endif /* CONFIG_P2P */
1254 wpas_wps_pbc_overlap(wpa_s);
1255 wpas_wps_cancel(wpa_s);
1256 #endif /* CONFIG_WPS */
1260 wpa_msg(wpa_s, MSG_DEBUG,
1261 "Considering connect request: reassociate: %d selected: "
1262 MACSTR " bssid: " MACSTR " pending: " MACSTR
1263 " wpa_state: %s ssid=%p current_ssid=%p",
1264 wpa_s->reassociate, MAC2STR(selected->bssid),
1265 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1266 wpa_supplicant_state_txt(wpa_s->wpa_state),
1267 ssid, wpa_s->current_ssid);
1270 * Do not trigger new association unless the BSSID has changed or if
1271 * reassociation is requested. If we are in process of associating with
1272 * the selected BSSID, do not trigger new attempt.
1274 if (wpa_s->reassociate ||
1275 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1276 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1277 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1278 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1279 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1281 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1282 ssid != wpa_s->current_ssid)))) {
1283 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1284 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1287 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1288 MAC2STR(selected->bssid));
1289 wpa_supplicant_associate(wpa_s, selected, ssid);
1291 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1292 "connect with the selected AP");
1299 static struct wpa_ssid *
1300 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1303 struct wpa_ssid *ssid;
1305 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1306 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1308 if (wpas_network_disabled(wpa_s, ssid))
1310 if (ssid->mode == IEEE80211_MODE_IBSS ||
1311 ssid->mode == IEEE80211_MODE_AP ||
1312 ssid->mode == IEEE80211_MODE_MESH)
1320 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1321 * on BSS added and BSS changed events */
1322 static void wpa_supplicant_rsn_preauth_scan_results(
1323 struct wpa_supplicant *wpa_s)
1325 struct wpa_bss *bss;
1327 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1330 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1331 const u8 *ssid, *rsn;
1333 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1337 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1341 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1347 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1348 struct wpa_bss *selected,
1349 struct wpa_ssid *ssid)
1351 struct wpa_bss *current_bss = NULL;
1352 #ifndef CONFIG_NO_ROAMING
1355 #endif /* CONFIG_NO_ROAMING */
1357 if (wpa_s->reassociate)
1358 return 1; /* explicit request to reassociate */
1359 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1360 return 1; /* we are not associated; continue */
1361 if (wpa_s->current_ssid == NULL)
1362 return 1; /* unknown current SSID */
1363 if (wpa_s->current_ssid != ssid)
1364 return 1; /* different network block */
1366 if (wpas_driver_bss_selection(wpa_s))
1367 return 0; /* Driver-based roaming */
1369 if (wpa_s->current_ssid->ssid)
1370 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1371 wpa_s->current_ssid->ssid,
1372 wpa_s->current_ssid->ssid_len);
1374 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1377 return 1; /* current BSS not seen in scan results */
1379 if (current_bss == selected)
1382 if (selected->last_update_idx > current_bss->last_update_idx)
1383 return 1; /* current BSS not seen in the last scan */
1385 #ifndef CONFIG_NO_ROAMING
1386 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1387 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1388 " level=%d snr=%d est_throughput=%u",
1389 MAC2STR(current_bss->bssid), current_bss->level,
1390 current_bss->snr, current_bss->est_throughput);
1391 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1392 " level=%d snr=%d est_throughput=%u",
1393 MAC2STR(selected->bssid), selected->level,
1394 selected->snr, selected->est_throughput);
1396 if (wpa_s->current_ssid->bssid_set &&
1397 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1399 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1400 "has preferred BSSID");
1404 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1405 wpa_dbg(wpa_s, MSG_DEBUG,
1406 "Allow reassociation - selected BSS has better estimated throughput");
1410 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1412 if (current_bss->level < 0 &&
1413 current_bss->level > selected->level + to_5ghz * 2) {
1414 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1420 if (current_bss->level < 0) {
1421 if (current_bss->level < -85)
1423 else if (current_bss->level < -80)
1425 else if (current_bss->level < -75)
1427 else if (current_bss->level < -70)
1433 /* Make it easier to move to 5 GHz band */
1439 if (abs(current_bss->level - selected->level) < min_diff) {
1440 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1446 #else /* CONFIG_NO_ROAMING */
1448 #endif /* CONFIG_NO_ROAMING */
1452 /* Return != 0 if no scan results could be fetched or if scan results should not
1453 * be shared with other virtual interfaces. */
1454 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1455 union wpa_event_data *data,
1458 struct wpa_scan_results *scan_res = NULL;
1461 #ifndef CONFIG_NO_RANDOM_POOL
1463 #endif /* CONFIG_NO_RANDOM_POOL */
1466 if (wpa_s->ap_iface)
1468 #endif /* CONFIG_AP */
1470 wpa_supplicant_notify_scanning(wpa_s, 0);
1472 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1473 data ? &data->scan_info :
1475 if (scan_res == NULL) {
1476 if (wpa_s->conf->ap_scan == 2 || ap ||
1477 wpa_s->scan_res_handler == scan_only_handler)
1481 if (data && data->scan_info.external_scan)
1483 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1485 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1487 goto scan_work_done;
1490 #ifndef CONFIG_NO_RANDOM_POOL
1491 num = scan_res->num;
1494 for (i = 0; i < num; i++) {
1496 struct wpa_scan_res *res = scan_res->res[i];
1497 buf[0] = res->bssid[5];
1498 buf[1] = res->qual & 0xff;
1499 buf[2] = res->noise & 0xff;
1500 buf[3] = res->level & 0xff;
1501 buf[4] = res->tsf & 0xff;
1502 random_add_randomness(buf, sizeof(buf));
1504 #endif /* CONFIG_NO_RANDOM_POOL */
1506 if (own_request && wpa_s->scan_res_handler &&
1507 !(data && data->scan_info.external_scan)) {
1508 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1509 struct wpa_scan_results *scan_res);
1511 scan_res_handler = wpa_s->scan_res_handler;
1512 wpa_s->scan_res_handler = NULL;
1513 scan_res_handler(wpa_s, scan_res);
1515 goto scan_work_done;
1519 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1521 if (wpa_s->ap_iface->scan_cb)
1522 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1523 #endif /* CONFIG_AP */
1524 goto scan_work_done;
1527 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1528 wpa_s->own_scan_running,
1529 data ? data->scan_info.external_scan : 0);
1530 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1531 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1532 own_request && !(data && data->scan_info.external_scan)) {
1533 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1534 wpa_s->manual_scan_id);
1535 wpa_s->manual_scan_use_id = 0;
1537 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1539 wpas_notify_scan_results(wpa_s);
1541 wpas_notify_scan_done(wpa_s, 1);
1543 if (data && data->scan_info.external_scan) {
1544 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1545 wpa_scan_results_free(scan_res);
1549 if (wnm_scan_process(wpa_s, 1) > 0)
1550 goto scan_work_done;
1552 if (sme_proc_obss_scan(wpa_s) > 0)
1553 goto scan_work_done;
1555 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1556 goto scan_work_done;
1558 if (autoscan_notify_scan(wpa_s, scan_res))
1559 goto scan_work_done;
1561 if (wpa_s->disconnected) {
1562 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1563 goto scan_work_done;
1566 if (!wpas_driver_bss_selection(wpa_s) &&
1567 bgscan_notify_scan(wpa_s, scan_res) == 1)
1568 goto scan_work_done;
1570 wpas_wps_update_ap_info(wpa_s, scan_res);
1572 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1573 wpa_s->wpa_state < WPA_COMPLETED)
1574 goto scan_work_done;
1576 wpa_scan_results_free(scan_res);
1578 if (own_request && wpa_s->scan_work) {
1579 struct wpa_radio_work *work = wpa_s->scan_work;
1580 wpa_s->scan_work = NULL;
1581 radio_work_done(work);
1584 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1587 wpa_scan_results_free(scan_res);
1588 if (own_request && wpa_s->scan_work) {
1589 struct wpa_radio_work *work = wpa_s->scan_work;
1590 wpa_s->scan_work = NULL;
1591 radio_work_done(work);
1597 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1598 int new_scan, int own_request)
1600 struct wpa_bss *selected;
1601 struct wpa_ssid *ssid = NULL;
1602 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1604 if (time_to_reenable > 0) {
1605 wpa_dbg(wpa_s, MSG_DEBUG,
1606 "Postpone network selection by %d seconds since all networks are disabled",
1608 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1609 eloop_register_timeout(time_to_reenable, 0,
1610 wpas_network_reenabled, wpa_s, NULL);
1614 if (wpa_s->p2p_mgmt)
1615 return 0; /* no normal connection on p2p_mgmt interface */
1617 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1621 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1624 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1628 if (ssid != wpa_s->current_ssid &&
1629 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1630 wpa_s->own_disconnect_req = 1;
1631 wpa_supplicant_deauthenticate(
1632 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1635 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1636 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1640 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1642 * Do not notify other virtual radios of scan results since we do not
1643 * want them to start other associations at the same time.
1649 wpa_msg(wpa_s, MSG_INFO,
1650 "Avoiding join because we already joined a mesh group");
1653 #endif /* CONFIG_MESH */
1654 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1655 ssid = wpa_supplicant_pick_new_network(wpa_s);
1657 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1658 wpa_supplicant_associate(wpa_s, NULL, ssid);
1660 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1661 } else if (own_request) {
1663 * No SSID found. If SCAN results are as a result of
1664 * own scan request and not due to a scan request on
1665 * another shared interface, try another scan.
1667 int timeout_sec = wpa_s->scan_interval;
1668 int timeout_usec = 0;
1672 res = wpas_p2p_scan_no_go_seen(wpa_s);
1678 if (wpa_s->p2p_in_provisioning ||
1679 wpa_s->show_group_started ||
1680 wpa_s->p2p_in_invitation) {
1682 * Use shorter wait during P2P Provisioning
1683 * state and during P2P join-a-group operation
1684 * to speed up group formation.
1687 timeout_usec = 250000;
1688 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1692 #endif /* CONFIG_P2P */
1693 #ifdef CONFIG_INTERWORKING
1694 if (wpa_s->conf->auto_interworking &&
1695 wpa_s->conf->interworking &&
1696 wpa_s->conf->cred) {
1697 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1698 "start ANQP fetch since no matching "
1700 wpa_s->network_select = 1;
1701 wpa_s->auto_network_select = 1;
1702 interworking_start_fetch_anqp(wpa_s);
1705 #endif /* CONFIG_INTERWORKING */
1707 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1708 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1710 timeout_usec = 500000;
1711 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1715 #endif /* CONFIG_WPS */
1716 if (wpa_supplicant_req_sched_scan(wpa_s))
1717 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1720 wpa_msg_ctrl(wpa_s, MSG_INFO,
1721 WPA_EVENT_NETWORK_NOT_FOUND);
1728 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1729 union wpa_event_data *data)
1731 struct wpa_supplicant *ifs;
1734 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1737 * Interface may have been removed, so must not dereference
1744 * If no scan results could be fetched, then no need to
1745 * notify those interfaces that did not actually request
1746 * this scan. Similarly, if scan results started a new operation on this
1747 * interface, do not notify other interfaces to avoid concurrent
1748 * operations during a connection attempt.
1754 * Check other interfaces to see if they share the same radio. If
1755 * so, they get updated with this same scan info.
1757 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1760 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1761 "sibling", ifs->ifname);
1762 _wpa_supplicant_event_scan_results(ifs, data, 0);
1769 #endif /* CONFIG_NO_SCAN_PROCESSING */
1772 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1774 #ifdef CONFIG_NO_SCAN_PROCESSING
1776 #else /* CONFIG_NO_SCAN_PROCESSING */
1777 struct os_reltime now;
1779 if (wpa_s->last_scan_res_used == 0)
1782 os_get_reltime(&now);
1783 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1784 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1788 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1789 #endif /* CONFIG_NO_SCAN_PROCESSING */
1794 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1796 struct wpa_supplicant *wpa_s = eloop_ctx;
1798 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1801 if (!wpa_s->no_keep_alive) {
1802 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1803 MAC2STR(wpa_s->bssid));
1804 /* TODO: could skip this if normal data traffic has been sent */
1805 /* TODO: Consider using some more appropriate data frame for
1808 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1813 if (wpa_s->sme.bss_max_idle_period) {
1815 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1818 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1819 wnm_bss_keep_alive, wpa_s, NULL);
1821 #endif /* CONFIG_SME */
1825 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1826 const u8 *ies, size_t ies_len)
1828 struct ieee802_11_elems elems;
1833 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1837 if (elems.bss_max_idle_period) {
1839 wpa_s->sme.bss_max_idle_period =
1840 WPA_GET_LE16(elems.bss_max_idle_period);
1841 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1842 "TU)%s", wpa_s->sme.bss_max_idle_period,
1843 (elems.bss_max_idle_period[2] & 0x01) ?
1844 " (protected keep-live required)" : "");
1845 if (wpa_s->sme.bss_max_idle_period == 0)
1846 wpa_s->sme.bss_max_idle_period = 1;
1847 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1848 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1849 /* msec times 1000 */
1850 msec = wpa_s->sme.bss_max_idle_period * 1024;
1853 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1854 wnm_bss_keep_alive, wpa_s,
1858 #endif /* CONFIG_SME */
1861 #endif /* CONFIG_WNM */
1864 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1867 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1868 #endif /* CONFIG_WNM */
1872 #ifdef CONFIG_INTERWORKING
1874 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1879 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1880 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1882 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1889 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1890 const u8 *ies, size_t ies_len)
1892 struct ieee802_11_elems elems;
1897 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1900 if (elems.qos_map_set) {
1901 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1902 elems.qos_map_set_len);
1906 #endif /* CONFIG_INTERWORKING */
1910 static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1911 const u8 *ie, size_t ie_len)
1913 struct mb_ies_info mb_ies;
1915 if (!ie || !ie_len || !wpa_s->fst)
1918 os_memset(&mb_ies, 0, sizeof(mb_ies));
1920 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1925 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1930 if (ie[0] == WLAN_EID_MULTI_BAND) {
1931 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1932 (unsigned int) len);
1933 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1934 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1942 if (mb_ies.nof_ies > 0) {
1943 wpabuf_free(wpa_s->received_mb_ies);
1944 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1950 #endif /* CONFIG_FST */
1953 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1954 union wpa_event_data *data)
1956 int l, len, found = 0, wpa_found, rsn_found;
1958 #ifdef CONFIG_IEEE80211R
1960 #endif /* CONFIG_IEEE80211R */
1962 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1963 if (data->assoc_info.req_ies)
1964 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1965 data->assoc_info.req_ies_len);
1966 if (data->assoc_info.resp_ies) {
1967 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1968 data->assoc_info.resp_ies_len);
1970 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1971 data->assoc_info.resp_ies_len);
1972 #endif /* CONFIG_TDLS */
1974 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1975 data->assoc_info.resp_ies_len);
1976 #endif /* CONFIG_WNM */
1977 #ifdef CONFIG_INTERWORKING
1978 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1979 data->assoc_info.resp_ies_len);
1980 #endif /* CONFIG_INTERWORKING */
1982 if (data->assoc_info.beacon_ies)
1983 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1984 data->assoc_info.beacon_ies,
1985 data->assoc_info.beacon_ies_len);
1986 if (data->assoc_info.freq)
1987 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1988 data->assoc_info.freq);
1990 p = data->assoc_info.req_ies;
1991 l = data->assoc_info.req_ies_len;
1993 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1994 while (p && l >= 2) {
1997 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2001 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2002 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
2003 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
2004 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2005 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2006 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2009 wpa_find_assoc_pmkid(wpa_s);
2015 if (!found && data->assoc_info.req_ies)
2016 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2018 #ifdef CONFIG_IEEE80211R
2020 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
2021 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2022 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2023 data->assoc_info.resp_ies,
2024 data->assoc_info.resp_ies_len,
2026 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2027 "Reassociation Response failed");
2028 wpa_supplicant_deauthenticate(
2029 wpa_s, WLAN_REASON_INVALID_IE);
2034 p = data->assoc_info.resp_ies;
2035 l = data->assoc_info.resp_ies_len;
2037 #ifdef CONFIG_WPS_STRICT
2038 if (p && wpa_s->current_ssid &&
2039 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2041 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2043 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2044 "include WPS IE in (Re)Association Response");
2048 if (wps_validate_assoc_resp(wps) < 0) {
2050 wpa_supplicant_deauthenticate(
2051 wpa_s, WLAN_REASON_INVALID_IE);
2056 #endif /* CONFIG_WPS_STRICT */
2058 /* Go through the IEs and make a copy of the MDIE, if present. */
2059 while (p && l >= 2) {
2062 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2066 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2067 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2068 wpa_s->sme.ft_used = 1;
2069 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2070 MOBILITY_DOMAIN_ID_LEN);
2076 #endif /* CONFIG_SME */
2078 /* Process FT when SME is in the driver */
2079 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2080 wpa_ft_is_completed(wpa_s->wpa)) {
2081 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2082 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2083 data->assoc_info.resp_ies,
2084 data->assoc_info.resp_ies_len,
2086 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2087 "Reassociation Response failed");
2088 wpa_supplicant_deauthenticate(
2089 wpa_s, WLAN_REASON_INVALID_IE);
2092 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2095 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2096 data->assoc_info.resp_ies_len);
2097 #endif /* CONFIG_IEEE80211R */
2099 /* WPA/RSN IE from Beacon/ProbeResp */
2100 p = data->assoc_info.beacon_ies;
2101 l = data->assoc_info.beacon_ies_len;
2103 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2105 wpa_found = rsn_found = 0;
2106 while (p && l >= 2) {
2109 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2114 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2115 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2117 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2121 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2123 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2130 if (!wpa_found && data->assoc_info.beacon_ies)
2131 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2132 if (!rsn_found && data->assoc_info.beacon_ies)
2133 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2134 if (wpa_found || rsn_found)
2135 wpa_s->ap_ies_from_associnfo = 1;
2137 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2138 wpa_s->assoc_freq != data->assoc_info.freq) {
2139 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2141 wpa_s->assoc_freq, data->assoc_info.freq);
2142 wpa_supplicant_update_scan_results(wpa_s);
2145 wpa_s->assoc_freq = data->assoc_info.freq;
2151 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2153 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2155 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2158 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2161 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2162 WPA_IE_VENDOR_TYPE);
2163 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2165 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2166 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2167 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2168 bss_rsn ? 2 + bss_rsn[1] : 0))
2175 static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2176 union wpa_event_data *data)
2179 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2180 struct wpa_bss *bss = wpa_s->current_bss;
2181 const u8 *ieprb, *iebcn;
2183 wpabuf_free(wpa_s->received_mb_ies);
2184 wpa_s->received_mb_ies = NULL;
2187 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2188 wpa_printf(MSG_DEBUG,
2189 "FST: MB IEs updated from Association Response frame");
2194 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2195 wpa_printf(MSG_DEBUG,
2196 "FST: MB IEs updated from association event Beacon IEs");
2203 ieprb = (const u8 *) (bss + 1);
2204 iebcn = ieprb + bss->ie_len;
2206 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2207 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2208 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2209 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2210 #endif /* CONFIG_FST */
2214 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2215 union wpa_event_data *data)
2222 if (wpa_s->ap_iface) {
2225 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2226 data->assoc_info.addr,
2227 data->assoc_info.req_ies,
2228 data->assoc_info.req_ies_len,
2229 data->assoc_info.reassoc);
2232 #endif /* CONFIG_AP */
2234 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2236 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2237 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2240 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2241 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2242 wpa_supplicant_deauthenticate(
2243 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2247 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2248 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2249 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2250 MACSTR, MAC2STR(bssid));
2252 random_add_randomness(bssid, ETH_ALEN);
2253 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2254 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2255 wpas_notify_bssid_changed(wpa_s);
2257 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2258 wpa_clear_keys(wpa_s, bssid);
2260 if (wpa_supplicant_select_config(wpa_s) < 0) {
2261 wpa_supplicant_deauthenticate(
2262 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2267 if (wpa_s->conf->ap_scan == 1 &&
2268 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2269 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2270 wpa_msg(wpa_s, MSG_WARNING,
2271 "WPA/RSN IEs not updated");
2274 wpas_fst_update_mb_assoc(wpa_s, data);
2277 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2278 wpa_s->sme.prev_bssid_set = 1;
2279 wpa_s->sme.last_unprot_disconnect.sec = 0;
2280 #endif /* CONFIG_SME */
2282 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2283 if (wpa_s->current_ssid) {
2284 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2285 * initialized before association, but for other modes,
2286 * initialize PC/SC here, if the current configuration needs
2287 * smartcard or SIM/USIM. */
2288 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2290 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2292 l2_packet_notify_auth_start(wpa_s->l2);
2295 * Set portEnabled first to FALSE in order to get EAP state machine out
2296 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2297 * state machine may transit to AUTHENTICATING state based on obsolete
2298 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2299 * AUTHENTICATED without ever giving chance to EAP state machine to
2302 if (!ft_completed) {
2303 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2304 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2306 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2307 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2308 /* 802.1X::portControl = Auto */
2309 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2310 wpa_s->eapol_received = 0;
2311 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2312 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2313 (wpa_s->current_ssid &&
2314 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2315 if (wpa_s->current_ssid &&
2316 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2318 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2320 * Set the key after having received joined-IBSS event
2323 wpa_supplicant_set_wpa_none_key(wpa_s,
2324 wpa_s->current_ssid);
2326 wpa_supplicant_cancel_auth_timeout(wpa_s);
2327 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2328 } else if (!ft_completed) {
2329 /* Timeout for receiving the first EAPOL packet */
2330 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2332 wpa_supplicant_cancel_scan(wpa_s);
2334 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2335 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2337 * We are done; the driver will take care of RSN 4-way
2340 wpa_supplicant_cancel_auth_timeout(wpa_s);
2341 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2342 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2343 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2344 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2345 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2347 * The driver will take care of RSN 4-way handshake, so we need
2348 * to allow EAPOL supplicant to complete its work without
2349 * waiting for WPA supplicant.
2351 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2352 } else if (ft_completed) {
2354 * FT protocol completed - make sure EAPOL state machine ends
2355 * up in authenticated.
2357 wpa_supplicant_cancel_auth_timeout(wpa_s);
2358 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2359 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2360 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2363 wpa_s->last_eapol_matches_bssid = 0;
2365 if (wpa_s->pending_eapol_rx) {
2366 struct os_reltime now, age;
2367 os_get_reltime(&now);
2368 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2369 if (age.sec == 0 && age.usec < 100000 &&
2370 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2372 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2373 "frame that was received just before "
2374 "association notification");
2375 wpa_supplicant_rx_eapol(
2376 wpa_s, wpa_s->pending_eapol_rx_src,
2377 wpabuf_head(wpa_s->pending_eapol_rx),
2378 wpabuf_len(wpa_s->pending_eapol_rx));
2380 wpabuf_free(wpa_s->pending_eapol_rx);
2381 wpa_s->pending_eapol_rx = NULL;
2384 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2385 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2386 wpa_s->current_ssid &&
2387 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2388 /* Set static WEP keys again */
2389 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2392 #ifdef CONFIG_IBSS_RSN
2393 if (wpa_s->current_ssid &&
2394 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2395 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2396 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2397 wpa_s->ibss_rsn == NULL) {
2398 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2399 if (!wpa_s->ibss_rsn) {
2400 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2401 wpa_supplicant_deauthenticate(
2402 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2406 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2408 #endif /* CONFIG_IBSS_RSN */
2410 wpas_wps_notify_assoc(wpa_s, bssid);
2413 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2414 data->assoc_info.resp_ies_len,
2415 &data->assoc_info.wmm_params);
2417 if (wpa_s->reassoc_same_bss)
2418 wmm_ac_restore_tspecs(wpa_s);
2423 static int disconnect_reason_recoverable(u16 reason_code)
2425 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2426 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2427 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2431 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2433 int locally_generated)
2437 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2439 * At least Host AP driver and a Prism3 card seemed to be
2440 * generating streams of disconnected events when configuring
2441 * IBSS for WPA-None. Ignore them for now.
2446 bssid = wpa_s->bssid;
2447 if (is_zero_ether_addr(bssid))
2448 bssid = wpa_s->pending_bssid;
2450 if (!is_zero_ether_addr(bssid) ||
2451 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2452 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2454 MAC2STR(bssid), reason_code,
2455 locally_generated ? " locally_generated=1" : "");
2460 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2461 int locally_generated)
2463 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2464 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2465 return 0; /* Not in 4-way handshake with PSK */
2468 * It looks like connection was lost while trying to go through PSK
2469 * 4-way handshake. Filter out known disconnection cases that are caused
2470 * by something else than PSK mismatch to avoid confusing reports.
2473 if (locally_generated) {
2474 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2482 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2484 int locally_generated)
2488 u8 prev_pending_bssid[ETH_ALEN];
2489 struct wpa_bss *fast_reconnect = NULL;
2490 struct wpa_ssid *fast_reconnect_ssid = NULL;
2491 struct wpa_ssid *last_ssid;
2493 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2494 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2496 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2498 * At least Host AP driver and a Prism3 card seemed to be
2499 * generating streams of disconnected events when configuring
2500 * IBSS for WPA-None. Ignore them for now.
2502 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2503 "IBSS/WPA-None mode");
2507 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2508 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2509 "pre-shared key may be incorrect");
2510 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2511 return; /* P2P group removed */
2512 wpas_auth_failed(wpa_s, "WRONG_KEY");
2514 if (!wpa_s->disconnected &&
2515 (!wpa_s->auto_reconnect_disabled ||
2516 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2517 wpas_wps_searching(wpa_s) ||
2518 wpas_wps_reenable_networks_pending(wpa_s))) {
2519 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2520 "reconnect (wps=%d/%d wpa_state=%d)",
2521 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2522 wpas_wps_searching(wpa_s),
2524 if (wpa_s->wpa_state == WPA_COMPLETED &&
2525 wpa_s->current_ssid &&
2526 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2527 !locally_generated &&
2528 disconnect_reason_recoverable(reason_code)) {
2530 * It looks like the AP has dropped association with
2531 * us, but could allow us to get back in. Try to
2532 * reconnect to the same BSS without full scan to save
2533 * time for some common cases.
2535 fast_reconnect = wpa_s->current_bss;
2536 fast_reconnect_ssid = wpa_s->current_ssid;
2537 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2538 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2540 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2543 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2544 "try to re-connect");
2545 wpa_s->reassociate = 0;
2546 wpa_s->disconnected = 1;
2548 wpa_supplicant_cancel_sched_scan(wpa_s);
2550 bssid = wpa_s->bssid;
2551 if (is_zero_ether_addr(bssid))
2552 bssid = wpa_s->pending_bssid;
2553 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2554 wpas_connection_failed(wpa_s, bssid);
2555 wpa_sm_notify_disassoc(wpa_s->wpa);
2556 if (locally_generated)
2557 wpa_s->disconnect_reason = -reason_code;
2559 wpa_s->disconnect_reason = reason_code;
2560 wpas_notify_disconnect_reason(wpa_s);
2561 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2562 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2563 wpa_clear_keys(wpa_s, wpa_s->bssid);
2565 last_ssid = wpa_s->current_ssid;
2566 wpa_supplicant_mark_disassoc(wpa_s);
2568 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2569 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2570 wpa_s->current_ssid = last_ssid;
2573 if (fast_reconnect &&
2574 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2575 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2576 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2577 fast_reconnect->ssid_len) &&
2578 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
2579 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
2580 #ifndef CONFIG_NO_SCAN_PROCESSING
2581 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2582 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2583 fast_reconnect_ssid) < 0) {
2584 /* Recover through full scan */
2585 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2587 #endif /* CONFIG_NO_SCAN_PROCESSING */
2588 } else if (fast_reconnect) {
2590 * Could not reconnect to the same BSS due to network being
2591 * disabled. Use a new scan to match the alternative behavior
2592 * above, i.e., to continue automatic reconnection attempt in a
2593 * way that enforces disabled network rules.
2595 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2600 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2601 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2603 struct wpa_supplicant *wpa_s = eloop_ctx;
2605 if (!wpa_s->pending_mic_error_report)
2608 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2609 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2610 wpa_s->pending_mic_error_report = 0;
2612 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2616 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2617 union wpa_event_data *data)
2620 struct os_reltime t;
2622 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2623 pairwise = (data && data->michael_mic_failure.unicast);
2625 if ((wpa_s->last_michael_mic_error.sec &&
2626 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2627 wpa_s->pending_mic_error_report) {
2628 if (wpa_s->pending_mic_error_report) {
2630 * Send the pending MIC error report immediately since
2631 * we are going to start countermeasures and AP better
2634 wpa_sm_key_request(wpa_s->wpa, 1,
2635 wpa_s->pending_mic_error_pairwise);
2638 /* Send the new MIC error report immediately since we are going
2639 * to start countermeasures and AP better do the same.
2641 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2643 /* initialize countermeasures */
2644 wpa_s->countermeasures = 1;
2646 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2648 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2651 * Need to wait for completion of request frame. We do not get
2652 * any callback for the message completion, so just wait a
2653 * short while and hope for the best. */
2656 wpa_drv_set_countermeasures(wpa_s, 1);
2657 wpa_supplicant_deauthenticate(wpa_s,
2658 WLAN_REASON_MICHAEL_MIC_FAILURE);
2659 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2661 eloop_register_timeout(60, 0,
2662 wpa_supplicant_stop_countermeasures,
2664 /* TODO: mark the AP rejected for 60 second. STA is
2665 * allowed to associate with another AP.. */
2667 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2668 if (wpa_s->mic_errors_seen) {
2670 * Reduce the effectiveness of Michael MIC error
2671 * reports as a means for attacking against TKIP if
2672 * more than one MIC failure is noticed with the same
2673 * PTK. We delay the transmission of the reports by a
2674 * random time between 0 and 60 seconds in order to
2675 * force the attacker wait 60 seconds before getting
2676 * the information on whether a frame resulted in a MIC
2682 if (os_get_random(rval, sizeof(rval)) < 0)
2683 sec = os_random() % 60;
2685 sec = WPA_GET_BE32(rval) % 60;
2686 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2687 "report %d seconds", sec);
2688 wpa_s->pending_mic_error_report = 1;
2689 wpa_s->pending_mic_error_pairwise = pairwise;
2690 eloop_cancel_timeout(
2691 wpa_supplicant_delayed_mic_error_report,
2693 eloop_register_timeout(
2694 sec, os_random() % 1000000,
2695 wpa_supplicant_delayed_mic_error_report,
2698 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2700 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2701 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2702 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2704 wpa_s->last_michael_mic_error = t;
2705 wpa_s->mic_errors_seen++;
2709 #ifdef CONFIG_TERMINATE_ONLASTIF
2710 static int any_interfaces(struct wpa_supplicant *head)
2712 struct wpa_supplicant *wpa_s;
2714 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2715 if (!wpa_s->interface_removed)
2719 #endif /* CONFIG_TERMINATE_ONLASTIF */
2723 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2724 union wpa_event_data *data)
2726 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2729 switch (data->interface_status.ievent) {
2730 case EVENT_INTERFACE_ADDED:
2731 if (!wpa_s->interface_removed)
2733 wpa_s->interface_removed = 0;
2734 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2735 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2736 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2737 "driver after interface was added");
2741 if (!wpa_s->global->p2p &&
2742 !wpa_s->global->p2p_disabled &&
2743 !wpa_s->conf->p2p_disabled &&
2745 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2746 wpas_p2p_add_p2pdev_interface(
2747 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2748 wpa_printf(MSG_INFO,
2749 "P2P: Failed to enable P2P Device interface");
2750 /* Try to continue without. P2P will be disabled. */
2752 #endif /* CONFIG_P2P */
2755 case EVENT_INTERFACE_REMOVED:
2756 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2757 wpa_s->interface_removed = 1;
2758 wpa_supplicant_mark_disassoc(wpa_s);
2759 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2760 l2_packet_deinit(wpa_s->l2);
2764 if (wpa_s->global->p2p &&
2765 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2767 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2768 wpa_dbg(wpa_s, MSG_DEBUG,
2769 "Removing P2P Device interface");
2770 wpa_supplicant_remove_iface(
2771 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2773 wpa_s->global->p2p_init_wpa_s = NULL;
2775 #endif /* CONFIG_P2P */
2777 #ifdef CONFIG_MATCH_IFACE
2778 if (wpa_s->matched) {
2779 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
2782 #endif /* CONFIG_MATCH_IFACE */
2784 #ifdef CONFIG_TERMINATE_ONLASTIF
2785 /* check if last interface */
2786 if (!any_interfaces(wpa_s->global->ifaces))
2788 #endif /* CONFIG_TERMINATE_ONLASTIF */
2794 #ifdef CONFIG_PEERKEY
2796 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2797 union wpa_event_data *data)
2801 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2803 #endif /* CONFIG_PEERKEY */
2807 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2808 union wpa_event_data *data)
2812 switch (data->tdls.oper) {
2813 case TDLS_REQUEST_SETUP:
2814 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2815 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2816 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2818 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2820 case TDLS_REQUEST_TEARDOWN:
2821 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2822 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2823 data->tdls.reason_code);
2825 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2828 case TDLS_REQUEST_DISCOVER:
2829 wpa_tdls_send_discovery_request(wpa_s->wpa,
2834 #endif /* CONFIG_TDLS */
2838 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2839 union wpa_event_data *data)
2843 switch (data->wnm.oper) {
2844 case WNM_OPER_SLEEP:
2845 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2846 "(action=%d, intval=%d)",
2847 data->wnm.sleep_action, data->wnm.sleep_intval);
2848 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2849 data->wnm.sleep_intval, NULL);
2853 #endif /* CONFIG_WNM */
2856 #ifdef CONFIG_IEEE80211R
2858 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2859 union wpa_event_data *data)
2864 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2865 data->ft_ies.ies_len,
2866 data->ft_ies.ft_action,
2867 data->ft_ies.target_ap,
2868 data->ft_ies.ric_ies,
2869 data->ft_ies.ric_ies_len) < 0) {
2870 /* TODO: prevent MLME/driver from trying to associate? */
2873 #endif /* CONFIG_IEEE80211R */
2876 #ifdef CONFIG_IBSS_RSN
2877 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2878 union wpa_event_data *data)
2880 struct wpa_ssid *ssid;
2881 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2885 ssid = wpa_s->current_ssid;
2888 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2891 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2895 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2896 union wpa_event_data *data)
2898 struct wpa_ssid *ssid = wpa_s->current_ssid;
2903 /* check if the ssid is correctly configured as IBSS/RSN */
2904 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2907 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2908 data->rx_mgmt.frame_len);
2910 #endif /* CONFIG_IBSS_RSN */
2913 #ifdef CONFIG_IEEE80211R
2914 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2917 const u8 *sta_addr, *target_ap_addr;
2920 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2921 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2922 return; /* only SME case supported for now */
2923 if (len < 1 + 2 * ETH_ALEN + 2)
2926 return; /* Only FT Action Response is supported for now */
2927 sta_addr = data + 1;
2928 target_ap_addr = data + 1 + ETH_ALEN;
2929 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2930 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2931 MACSTR " TargetAP " MACSTR " status %u",
2932 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2934 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2935 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2936 " in FT Action Response", MAC2STR(sta_addr));
2941 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2942 "failure (status code %d)", status);
2943 /* TODO: report error to FT code(?) */
2947 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2948 len - (1 + 2 * ETH_ALEN + 2), 1,
2949 target_ap_addr, NULL, 0) < 0)
2954 struct wpa_bss *bss;
2955 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2957 wpa_s->sme.freq = bss->freq;
2958 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2959 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2962 #endif /* CONFIG_SME */
2964 #endif /* CONFIG_IEEE80211R */
2967 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2968 struct unprot_deauth *e)
2970 #ifdef CONFIG_IEEE80211W
2971 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2972 "dropped: " MACSTR " -> " MACSTR
2973 " (reason code %u)",
2974 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2975 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2976 #endif /* CONFIG_IEEE80211W */
2980 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2981 struct unprot_disassoc *e)
2983 #ifdef CONFIG_IEEE80211W
2984 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2985 "dropped: " MACSTR " -> " MACSTR
2986 " (reason code %u)",
2987 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2988 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2989 #endif /* CONFIG_IEEE80211W */
2993 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2994 u16 reason_code, int locally_generated,
2995 const u8 *ie, size_t ie_len, int deauth)
2998 if (wpa_s->ap_iface && addr) {
2999 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
3003 if (wpa_s->ap_iface) {
3004 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3007 #endif /* CONFIG_AP */
3009 if (!locally_generated)
3010 wpa_s->own_disconnect_req = 0;
3012 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3014 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3015 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3016 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3017 eapol_sm_failed(wpa_s->eapol))) &&
3018 !wpa_s->eap_expected_failure))
3019 wpas_auth_failed(wpa_s, "AUTH_FAILED");
3022 if (deauth && reason_code > 0) {
3023 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3024 locally_generated) > 0) {
3026 * The interface was removed, so cannot continue
3027 * processing any additional operations after this.
3032 #endif /* CONFIG_P2P */
3034 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3039 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3040 struct disassoc_info *info)
3042 u16 reason_code = 0;
3043 int locally_generated = 0;
3044 const u8 *addr = NULL;
3045 const u8 *ie = NULL;
3048 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3053 ie_len = info->ie_len;
3054 reason_code = info->reason_code;
3055 locally_generated = info->locally_generated;
3056 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3057 locally_generated ? " (locally generated)" : "");
3059 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3061 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3066 if (wpa_s->ap_iface && info && info->addr) {
3067 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3071 if (wpa_s->ap_iface) {
3072 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3075 #endif /* CONFIG_AP */
3079 wpas_p2p_disassoc_notif(
3080 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3083 #endif /* CONFIG_P2P */
3085 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3086 sme_event_disassoc(wpa_s, info);
3088 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3093 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3094 struct deauth_info *info)
3096 u16 reason_code = 0;
3097 int locally_generated = 0;
3098 const u8 *addr = NULL;
3099 const u8 *ie = NULL;
3102 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3107 ie_len = info->ie_len;
3108 reason_code = info->reason_code;
3109 locally_generated = info->locally_generated;
3110 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3112 locally_generated ? " (locally generated)" : "");
3114 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3117 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3121 wpa_reset_ft_completed(wpa_s->wpa);
3123 wpas_event_disconnect(wpa_s, addr, reason_code,
3124 locally_generated, ie, ie_len, 1);
3128 static const char * reg_init_str(enum reg_change_initiator init)
3131 case REGDOM_SET_BY_CORE:
3133 case REGDOM_SET_BY_USER:
3135 case REGDOM_SET_BY_DRIVER:
3137 case REGDOM_SET_BY_COUNTRY_IE:
3138 return "COUNTRY_IE";
3139 case REGDOM_BEACON_HINT:
3140 return "BEACON_HINT";
3146 static const char * reg_type_str(enum reg_type type)
3149 case REGDOM_TYPE_UNKNOWN:
3151 case REGDOM_TYPE_COUNTRY:
3153 case REGDOM_TYPE_WORLD:
3155 case REGDOM_TYPE_CUSTOM_WORLD:
3156 return "CUSTOM_WORLD";
3157 case REGDOM_TYPE_INTERSECTION:
3158 return "INTERSECTION";
3164 static void wpa_supplicant_update_channel_list(
3165 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3167 struct wpa_supplicant *ifs;
3169 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3170 reg_init_str(info->initiator), reg_type_str(info->type),
3171 info->alpha2[0] ? " alpha2=" : "",
3172 info->alpha2[0] ? info->alpha2 : "");
3174 if (wpa_s->drv_priv == NULL)
3175 return; /* Ignore event during drv initialization */
3177 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3179 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3181 free_hw_features(ifs);
3182 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3183 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3186 /* Restart sched_scan with updated channel list */
3187 if (wpa_s->sched_scanning) {
3188 wpa_dbg(wpa_s, MSG_DEBUG,
3189 "Channel list changed restart sched scan.");
3190 wpa_supplicant_cancel_sched_scan(wpa_s);
3191 wpa_supplicant_req_scan(wpa_s, 0, 0);
3194 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3198 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3199 const u8 *frame, size_t len, int freq,
3202 const struct ieee80211_mgmt *mgmt;
3207 if (len < IEEE80211_HDRLEN + 2)
3210 mgmt = (const struct ieee80211_mgmt *) frame;
3211 payload = frame + IEEE80211_HDRLEN;
3212 category = *payload++;
3213 plen = len - IEEE80211_HDRLEN - 1;
3215 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3216 " Category=%u DataLen=%d freq=%d MHz",
3217 MAC2STR(mgmt->sa), category, (int) plen, freq);
3219 if (category == WLAN_ACTION_WMM) {
3220 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3224 #ifdef CONFIG_IEEE80211R
3225 if (category == WLAN_ACTION_FT) {
3226 ft_rx_action(wpa_s, payload, plen);
3229 #endif /* CONFIG_IEEE80211R */
3231 #ifdef CONFIG_IEEE80211W
3233 if (category == WLAN_ACTION_SA_QUERY) {
3234 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3237 #endif /* CONFIG_SME */
3238 #endif /* CONFIG_IEEE80211W */
3241 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3242 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3245 #endif /* CONFIG_WNM */
3248 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3249 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3250 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3251 mgmt->u.action.category,
3252 payload, plen, freq) == 0)
3254 #endif /* CONFIG_GAS */
3257 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3258 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3259 wpa_dbg(wpa_s, MSG_DEBUG,
3260 "TDLS: Received Discovery Response from " MACSTR,
3264 #endif /* CONFIG_TDLS */
3266 #ifdef CONFIG_INTERWORKING
3267 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3268 payload[0] == QOS_QOS_MAP_CONFIG) {
3269 const u8 *pos = payload + 1;
3270 size_t qlen = plen - 1;
3271 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3272 MACSTR, MAC2STR(mgmt->sa));
3273 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3274 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3275 pos[1] <= qlen - 2 && pos[1] >= 16)
3276 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3279 #endif /* CONFIG_INTERWORKING */
3281 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3282 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3283 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3287 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3288 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3289 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3290 payload + 1, plen - 1,
3296 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3297 fst_rx_action(wpa_s->fst, mgmt, len);
3300 #endif /* CONFIG_FST */
3302 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3303 category, payload, plen, freq);
3305 mesh_mpm_action_rx(wpa_s, mgmt, len);
3309 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3310 union wpa_event_data *event)
3312 struct wpa_freq_range_list *list;
3315 list = &event->freq_range;
3318 str = freq_range_list_str(list);
3319 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3323 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3324 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3327 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3330 * The update channel flow will also take care of moving a GO
3331 * from the unsafe frequency if needed.
3333 wpas_p2p_update_channel_list(wpa_s,
3334 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3336 #endif /* CONFIG_P2P */
3342 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3343 union wpa_event_data *data)
3345 wpa_dbg(wpa_s, MSG_DEBUG,
3346 "Connection authorized by device, previous state %d",
3348 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3349 wpa_supplicant_cancel_auth_timeout(wpa_s);
3350 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3351 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3352 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3354 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3355 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3356 data->assoc_info.ptk_kck_len,
3357 data->assoc_info.ptk_kek,
3358 data->assoc_info.ptk_kek_len);
3362 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3363 union wpa_event_data *data)
3365 struct wpa_supplicant *wpa_s = ctx;
3368 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3369 event != EVENT_INTERFACE_ENABLED &&
3370 event != EVENT_INTERFACE_STATUS &&
3371 event != EVENT_SCAN_RESULTS &&
3372 event != EVENT_SCHED_SCAN_STOPPED) {
3373 wpa_dbg(wpa_s, MSG_DEBUG,
3374 "Ignore event %s (%d) while interface is disabled",
3375 event_to_string(event), event);
3379 #ifndef CONFIG_NO_STDOUT_DEBUG
3381 int level = MSG_DEBUG;
3383 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3384 const struct ieee80211_hdr *hdr;
3386 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3387 fc = le_to_host16(hdr->frame_control);
3388 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3389 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3390 level = MSG_EXCESSIVE;
3393 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3394 event_to_string(event), event);
3396 #endif /* CONFIG_NO_STDOUT_DEBUG */
3401 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3402 data->auth.ies_len))
3403 wpa_printf(MSG_DEBUG,
3404 "FST: MB IEs updated from auth IE");
3405 #endif /* CONFIG_FST */
3406 sme_event_auth(wpa_s, data);
3409 wpa_supplicant_event_assoc(wpa_s, data);
3410 if (data && data->assoc_info.authorized)
3411 wpa_supplicant_event_assoc_auth(wpa_s, data);
3413 wpa_msg(wpa_s, MSG_INFO,
3414 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3415 data->assoc_info.subnet_status);
3418 case EVENT_DISASSOC:
3419 wpas_event_disassoc(wpa_s,
3420 data ? &data->disassoc_info : NULL);
3423 wpas_event_deauth(wpa_s,
3424 data ? &data->deauth_info : NULL);
3426 case EVENT_MICHAEL_MIC_FAILURE:
3427 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3429 #ifndef CONFIG_NO_SCAN_PROCESSING
3430 case EVENT_SCAN_STARTED:
3431 if (wpa_s->own_scan_requested ||
3432 (data && !data->scan_info.external_scan)) {
3433 struct os_reltime diff;
3435 os_get_reltime(&wpa_s->scan_start_time);
3436 os_reltime_sub(&wpa_s->scan_start_time,
3437 &wpa_s->scan_trigger_time, &diff);
3438 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3439 diff.sec, diff.usec);
3440 wpa_s->own_scan_requested = 0;
3441 wpa_s->own_scan_running = 1;
3442 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3443 wpa_s->manual_scan_use_id) {
3444 wpa_msg_ctrl(wpa_s, MSG_INFO,
3445 WPA_EVENT_SCAN_STARTED "id=%u",
3446 wpa_s->manual_scan_id);
3448 wpa_msg_ctrl(wpa_s, MSG_INFO,
3449 WPA_EVENT_SCAN_STARTED);
3452 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3453 wpa_s->radio->external_scan_running = 1;
3454 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3457 case EVENT_SCAN_RESULTS:
3458 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3459 wpa_s->scan_res_handler = NULL;
3460 wpa_s->own_scan_running = 0;
3461 wpa_s->radio->external_scan_running = 0;
3462 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
3466 if (!(data && data->scan_info.external_scan) &&
3467 os_reltime_initialized(&wpa_s->scan_start_time)) {
3468 struct os_reltime now, diff;
3469 os_get_reltime(&now);
3470 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3471 wpa_s->scan_start_time.sec = 0;
3472 wpa_s->scan_start_time.usec = 0;
3473 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3474 diff.sec, diff.usec);
3476 if (wpa_supplicant_event_scan_results(wpa_s, data))
3477 break; /* interface may have been removed */
3478 if (!(data && data->scan_info.external_scan))
3479 wpa_s->own_scan_running = 0;
3480 if (data && data->scan_info.nl_scan_event)
3481 wpa_s->radio->external_scan_running = 0;
3482 radio_work_check_next(wpa_s);
3484 #endif /* CONFIG_NO_SCAN_PROCESSING */
3485 case EVENT_ASSOCINFO:
3486 wpa_supplicant_event_associnfo(wpa_s, data);
3488 case EVENT_INTERFACE_STATUS:
3489 wpa_supplicant_event_interface_status(wpa_s, data);
3491 case EVENT_PMKID_CANDIDATE:
3492 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3494 #ifdef CONFIG_PEERKEY
3495 case EVENT_STKSTART:
3496 wpa_supplicant_event_stkstart(wpa_s, data);
3498 #endif /* CONFIG_PEERKEY */
3501 wpa_supplicant_event_tdls(wpa_s, data);
3503 #endif /* CONFIG_TDLS */
3506 wpa_supplicant_event_wnm(wpa_s, data);
3508 #endif /* CONFIG_WNM */
3509 #ifdef CONFIG_IEEE80211R
3510 case EVENT_FT_RESPONSE:
3511 wpa_supplicant_event_ft_response(wpa_s, data);
3513 #endif /* CONFIG_IEEE80211R */
3514 #ifdef CONFIG_IBSS_RSN
3515 case EVENT_IBSS_RSN_START:
3516 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3518 #endif /* CONFIG_IBSS_RSN */
3519 case EVENT_ASSOC_REJECT:
3520 if (data->assoc_reject.bssid)
3521 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3522 "bssid=" MACSTR " status_code=%u",
3523 MAC2STR(data->assoc_reject.bssid),
3524 data->assoc_reject.status_code);
3526 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3528 data->assoc_reject.status_code);
3529 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3530 wpas_notify_assoc_status_code(wpa_s);
3531 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3532 sme_event_assoc_reject(wpa_s, data);
3534 const u8 *bssid = data->assoc_reject.bssid;
3535 if (bssid == NULL || is_zero_ether_addr(bssid))
3536 bssid = wpa_s->pending_bssid;
3537 wpas_connection_failed(wpa_s, bssid);
3538 wpa_supplicant_mark_disassoc(wpa_s);
3541 case EVENT_AUTH_TIMED_OUT:
3542 /* It is possible to get this event from earlier connection */
3543 if (wpa_s->current_ssid &&
3544 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3545 wpa_dbg(wpa_s, MSG_DEBUG,
3546 "Ignore AUTH_TIMED_OUT in mesh configuration");
3549 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3550 sme_event_auth_timed_out(wpa_s, data);
3552 case EVENT_ASSOC_TIMED_OUT:
3553 /* It is possible to get this event from earlier connection */
3554 if (wpa_s->current_ssid &&
3555 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3556 wpa_dbg(wpa_s, MSG_DEBUG,
3557 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3560 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3561 sme_event_assoc_timed_out(wpa_s, data);
3563 case EVENT_TX_STATUS:
3564 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3565 " type=%d stype=%d",
3566 MAC2STR(data->tx_status.dst),
3567 data->tx_status.type, data->tx_status.stype);
3569 if (wpa_s->ap_iface == NULL) {
3570 #ifdef CONFIG_OFFCHANNEL
3571 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3572 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3573 offchannel_send_action_tx_status(
3574 wpa_s, data->tx_status.dst,
3575 data->tx_status.data,
3576 data->tx_status.data_len,
3577 data->tx_status.ack ?
3578 OFFCHANNEL_SEND_ACTION_SUCCESS :
3579 OFFCHANNEL_SEND_ACTION_NO_ACK);
3580 #endif /* CONFIG_OFFCHANNEL */
3583 #endif /* CONFIG_AP */
3584 #ifdef CONFIG_OFFCHANNEL
3585 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3586 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3588 * Catch TX status events for Action frames we sent via group
3589 * interface in GO mode.
3591 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3592 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3593 os_memcmp(wpa_s->parent->pending_action_dst,
3594 data->tx_status.dst, ETH_ALEN) == 0) {
3595 offchannel_send_action_tx_status(
3596 wpa_s->parent, data->tx_status.dst,
3597 data->tx_status.data,
3598 data->tx_status.data_len,
3599 data->tx_status.ack ?
3600 OFFCHANNEL_SEND_ACTION_SUCCESS :
3601 OFFCHANNEL_SEND_ACTION_NO_ACK);
3604 #endif /* CONFIG_OFFCHANNEL */
3606 switch (data->tx_status.type) {
3607 case WLAN_FC_TYPE_MGMT:
3608 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3609 data->tx_status.data_len,
3610 data->tx_status.stype,
3611 data->tx_status.ack);
3613 case WLAN_FC_TYPE_DATA:
3614 ap_tx_status(wpa_s, data->tx_status.dst,
3615 data->tx_status.data,
3616 data->tx_status.data_len,
3617 data->tx_status.ack);
3620 #endif /* CONFIG_AP */
3623 case EVENT_EAPOL_TX_STATUS:
3624 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3625 data->eapol_tx_status.data,
3626 data->eapol_tx_status.data_len,
3627 data->eapol_tx_status.ack);
3629 case EVENT_DRIVER_CLIENT_POLL_OK:
3630 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3632 case EVENT_RX_FROM_UNKNOWN:
3633 if (wpa_s->ap_iface == NULL)
3635 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3636 data->rx_from_unknown.wds);
3638 case EVENT_CH_SWITCH:
3639 if (!data || !wpa_s->current_ssid)
3642 wpa_s->assoc_freq = data->ch_switch.freq;
3643 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3645 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3646 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3647 wpa_s->current_ssid->mode ==
3648 WPAS_MODE_P2P_GROUP_FORMATION) {
3649 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3650 data->ch_switch.ht_enabled,
3651 data->ch_switch.ch_offset,
3652 data->ch_switch.ch_width,
3653 data->ch_switch.cf1,
3654 data->ch_switch.cf2);
3657 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3660 case EVENT_DFS_RADAR_DETECTED:
3662 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3664 case EVENT_DFS_CAC_STARTED:
3666 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3668 case EVENT_DFS_CAC_FINISHED:
3670 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3672 case EVENT_DFS_CAC_ABORTED:
3674 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3676 case EVENT_DFS_NOP_FINISHED:
3678 wpas_event_dfs_cac_nop_finished(wpa_s,
3681 #endif /* NEED_AP_MLME */
3682 #endif /* CONFIG_AP */
3683 case EVENT_RX_MGMT: {
3685 const struct ieee80211_mgmt *mgmt;
3687 #ifdef CONFIG_TESTING_OPTIONS
3688 if (wpa_s->ext_mgmt_frame_handling) {
3689 struct rx_mgmt *rx = &data->rx_mgmt;
3690 size_t hex_len = 2 * rx->frame_len + 1;
3691 char *hex = os_malloc(hex_len);
3693 wpa_snprintf_hex(hex, hex_len,
3694 rx->frame, rx->frame_len);
3695 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3696 rx->freq, rx->datarate, rx->ssi_signal,
3702 #endif /* CONFIG_TESTING_OPTIONS */
3704 mgmt = (const struct ieee80211_mgmt *)
3705 data->rx_mgmt.frame;
3706 fc = le_to_host16(mgmt->frame_control);
3707 stype = WLAN_FC_GET_STYPE(fc);
3710 if (wpa_s->ap_iface == NULL) {
3711 #endif /* CONFIG_AP */
3713 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3714 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
3715 const u8 *src = mgmt->sa;
3719 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3720 ie_len = data->rx_mgmt.frame_len -
3722 wpas_p2p_probe_req_rx(
3723 wpa_s, src, mgmt->da,
3724 mgmt->bssid, ie, ie_len,
3726 data->rx_mgmt.ssi_signal);
3729 #endif /* CONFIG_P2P */
3730 #ifdef CONFIG_IBSS_RSN
3731 if (wpa_s->current_ssid &&
3732 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3733 stype == WLAN_FC_STYPE_AUTH &&
3734 data->rx_mgmt.frame_len >= 30) {
3735 wpa_supplicant_event_ibss_auth(wpa_s, data);
3738 #endif /* CONFIG_IBSS_RSN */
3740 if (stype == WLAN_FC_STYPE_ACTION) {
3741 wpas_event_rx_mgmt_action(
3742 wpa_s, data->rx_mgmt.frame,
3743 data->rx_mgmt.frame_len,
3745 data->rx_mgmt.ssi_signal);
3750 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3754 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3755 "management frame in non-AP mode");
3760 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3761 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
3765 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3766 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
3768 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3769 mgmt->bssid, ie, ie_len,
3770 data->rx_mgmt.ssi_signal);
3773 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3774 #endif /* CONFIG_AP */
3777 case EVENT_RX_PROBE_REQ:
3778 if (data->rx_probe_req.sa == NULL ||
3779 data->rx_probe_req.ie == NULL)
3782 if (wpa_s->ap_iface) {
3783 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3784 data->rx_probe_req.sa,
3785 data->rx_probe_req.da,
3786 data->rx_probe_req.bssid,
3787 data->rx_probe_req.ie,
3788 data->rx_probe_req.ie_len,
3789 data->rx_probe_req.ssi_signal);
3792 #endif /* CONFIG_AP */
3793 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3794 data->rx_probe_req.da,
3795 data->rx_probe_req.bssid,
3796 data->rx_probe_req.ie,
3797 data->rx_probe_req.ie_len,
3799 data->rx_probe_req.ssi_signal);
3801 case EVENT_REMAIN_ON_CHANNEL:
3802 #ifdef CONFIG_OFFCHANNEL
3803 offchannel_remain_on_channel_cb(
3804 wpa_s, data->remain_on_channel.freq,
3805 data->remain_on_channel.duration);
3806 #endif /* CONFIG_OFFCHANNEL */
3807 wpas_p2p_remain_on_channel_cb(
3808 wpa_s, data->remain_on_channel.freq,
3809 data->remain_on_channel.duration);
3811 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3812 #ifdef CONFIG_OFFCHANNEL
3813 offchannel_cancel_remain_on_channel_cb(
3814 wpa_s, data->remain_on_channel.freq);
3815 #endif /* CONFIG_OFFCHANNEL */
3816 wpas_p2p_cancel_remain_on_channel_cb(
3817 wpa_s, data->remain_on_channel.freq);
3819 case EVENT_EAPOL_RX:
3820 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3821 data->eapol_rx.data,
3822 data->eapol_rx.data_len);
3824 case EVENT_SIGNAL_CHANGE:
3825 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3826 "above=%d signal=%d noise=%d txrate=%d",
3827 data->signal_change.above_threshold,
3828 data->signal_change.current_signal,
3829 data->signal_change.current_noise,
3830 data->signal_change.current_txrate);
3831 wpa_bss_update_level(wpa_s->current_bss,
3832 data->signal_change.current_signal);
3833 bgscan_notify_signal_change(
3834 wpa_s, data->signal_change.above_threshold,
3835 data->signal_change.current_signal,
3836 data->signal_change.current_noise,
3837 data->signal_change.current_txrate);
3839 case EVENT_INTERFACE_ENABLED:
3840 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3841 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3842 wpa_supplicant_update_mac_addr(wpa_s);
3843 if (wpa_s->p2p_mgmt) {
3844 wpa_supplicant_set_state(wpa_s,
3850 if (!wpa_s->ap_iface) {
3851 wpa_supplicant_set_state(wpa_s,
3853 wpa_s->scan_req = NORMAL_SCAN_REQ;
3854 wpa_supplicant_req_scan(wpa_s, 0, 0);
3856 wpa_supplicant_set_state(wpa_s,
3858 #else /* CONFIG_AP */
3859 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3860 wpa_supplicant_req_scan(wpa_s, 0, 0);
3861 #endif /* CONFIG_AP */
3864 case EVENT_INTERFACE_DISABLED:
3865 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3867 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3868 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3869 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3871 * Mark interface disabled if this happens to end up not
3872 * being removed as a separate P2P group interface.
3874 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3876 * The interface was externally disabled. Remove
3877 * it assuming an external entity will start a
3878 * new session if needed.
3880 if (wpa_s->current_ssid &&
3881 wpa_s->current_ssid->p2p_group)
3882 wpas_p2p_interface_unavailable(wpa_s);
3884 wpas_p2p_disconnect(wpa_s);
3886 * wpa_s instance may have been freed, so must not use
3891 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3892 p2p_in_progress(wpa_s->global->p2p) > 1) {
3893 /* This radio work will be cancelled, so clear P2P
3896 p2p_stop_find(wpa_s->global->p2p);
3898 #endif /* CONFIG_P2P */
3900 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3902 * Indicate disconnection to keep ctrl_iface events
3905 wpa_supplicant_event_disassoc(
3906 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3908 wpa_supplicant_mark_disassoc(wpa_s);
3909 radio_remove_works(wpa_s, NULL, 0);
3911 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3913 case EVENT_CHANNEL_LIST_CHANGED:
3914 wpa_supplicant_update_channel_list(
3915 wpa_s, &data->channel_list_changed);
3917 case EVENT_INTERFACE_UNAVAILABLE:
3918 wpas_p2p_interface_unavailable(wpa_s);
3920 case EVENT_BEST_CHANNEL:
3921 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3923 data->best_chan.freq_24, data->best_chan.freq_5,
3924 data->best_chan.freq_overall);
3925 wpa_s->best_24_freq = data->best_chan.freq_24;
3926 wpa_s->best_5_freq = data->best_chan.freq_5;
3927 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3928 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3929 data->best_chan.freq_5,
3930 data->best_chan.freq_overall);
3932 case EVENT_UNPROT_DEAUTH:
3933 wpa_supplicant_event_unprot_deauth(wpa_s,
3934 &data->unprot_deauth);
3936 case EVENT_UNPROT_DISASSOC:
3937 wpa_supplicant_event_unprot_disassoc(wpa_s,
3938 &data->unprot_disassoc);
3940 case EVENT_STATION_LOW_ACK:
3942 if (wpa_s->ap_iface && data)
3943 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3944 data->low_ack.addr);
3945 #endif /* CONFIG_AP */
3948 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3949 data->low_ack.addr);
3950 #endif /* CONFIG_TDLS */
3952 case EVENT_IBSS_PEER_LOST:
3953 #ifdef CONFIG_IBSS_RSN
3954 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3955 #endif /* CONFIG_IBSS_RSN */
3957 case EVENT_DRIVER_GTK_REKEY:
3958 if (os_memcmp(data->driver_gtk_rekey.bssid,
3959 wpa_s->bssid, ETH_ALEN))
3963 wpa_sm_update_replay_ctr(wpa_s->wpa,
3964 data->driver_gtk_rekey.replay_ctr);
3966 case EVENT_SCHED_SCAN_STOPPED:
3967 wpa_s->sched_scanning = 0;
3968 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
3969 wpa_supplicant_notify_scanning(wpa_s, 0);
3971 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3975 * Start a new sched scan to continue searching for more SSIDs
3976 * either if timed out or PNO schedule scan is pending.
3978 if (wpa_s->sched_scan_timed_out) {
3979 wpa_supplicant_req_sched_scan(wpa_s);
3980 } else if (wpa_s->pno_sched_pending) {
3981 wpa_s->pno_sched_pending = 0;
3982 wpas_start_pno(wpa_s);
3983 } else if (resched) {
3984 wpa_supplicant_req_scan(wpa_s, 0, 0);
3988 case EVENT_WPS_BUTTON_PUSHED:
3990 wpas_wps_start_pbc(wpa_s, NULL, 0);
3991 #endif /* CONFIG_WPS */
3993 case EVENT_AVOID_FREQUENCIES:
3994 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3996 case EVENT_CONNECT_FAILED_REASON:
3998 if (!wpa_s->ap_iface || !data)
4000 hostapd_event_connect_failed_reason(
4001 wpa_s->ap_iface->bss[0],
4002 data->connect_failed_reason.addr,
4003 data->connect_failed_reason.code);
4004 #endif /* CONFIG_AP */
4006 case EVENT_NEW_PEER_CANDIDATE:
4008 if (!wpa_s->ifmsh || !data)
4010 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4011 data->mesh_peer.ies,
4012 data->mesh_peer.ie_len);
4013 #endif /* CONFIG_MESH */
4017 if (!wpa_s->ap_iface)
4019 hostapd_event_get_survey(wpa_s->ap_iface,
4020 &data->survey_results);
4021 #endif /* CONFIG_AP */
4023 case EVENT_ACS_CHANNEL_SELECTED:
4025 if (!wpa_s->ap_iface)
4027 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4028 &data->acs_selected_channels);
4029 #endif /* CONFIG_ACS */
4032 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4038 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4039 union wpa_event_data *data)
4041 struct wpa_supplicant *wpa_s;
4043 if (event != EVENT_INTERFACE_STATUS)
4046 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4047 if (wpa_s && wpa_s->driver->get_ifindex) {
4048 unsigned int ifindex;
4050 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4051 if (ifindex != data->interface_status.ifindex) {
4052 wpa_dbg(wpa_s, MSG_DEBUG,
4053 "interface status ifindex %d mismatch (%d)",
4054 ifindex, data->interface_status.ifindex);
4058 #ifdef CONFIG_MATCH_IFACE
4059 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4060 struct wpa_interface *wpa_i;
4062 wpa_i = wpa_supplicant_match_iface(
4063 ctx, data->interface_status.ifname);
4066 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4071 #endif /* CONFIG_MATCH_IFACE */
4074 wpa_supplicant_event(wpa_s, event, data);