2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "crypto/random.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
37 #include "gas_query.h"
38 #include "p2p_supplicant.h"
44 #include "offchannel.h"
45 #include "interworking.h"
51 #ifndef CONFIG_NO_SCAN_PROCESSING
52 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
53 int new_scan, int own_request);
54 #endif /* CONFIG_NO_SCAN_PROCESSING */
57 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
60 struct os_reltime now;
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
66 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75 #ifndef CONFIG_NO_SCAN_PROCESSING
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
86 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
88 struct wpa_ssid *ssid;
89 int disabled_for, res = 0;
91 #ifdef CONFIG_INTERWORKING
92 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
95 #endif /* CONFIG_INTERWORKING */
97 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
101 disabled_for = wpas_temp_disabled(wpa_s, ssid);
105 if (!res || disabled_for < res)
111 #endif /* CONFIG_NO_SCAN_PROCESSING */
114 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
116 struct wpa_supplicant *wpa_s = eloop_ctx;
118 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
121 wpa_dbg(wpa_s, MSG_DEBUG,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s);
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
130 static struct wpa_bss * wpa_supplicant_get_new_bss(
131 struct wpa_supplicant *wpa_s, const u8 *bssid)
133 struct wpa_bss *bss = NULL;
134 struct wpa_ssid *ssid = wpa_s->current_ssid;
136 if (ssid->ssid_len > 0)
137 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
139 bss = wpa_bss_get_bssid(wpa_s, bssid);
145 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
147 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
150 wpa_supplicant_update_scan_results(wpa_s);
152 /* Get the BSS from the new scan results */
153 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
157 wpa_s->current_bss = bss;
161 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
163 struct wpa_ssid *ssid, *old_ssid;
164 u8 drv_ssid[SSID_MAX_LEN];
168 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
169 wpa_supplicant_update_current_bss(wpa_s);
171 if (wpa_s->current_ssid->ssid_len == 0)
172 return 0; /* current profile still in use */
173 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
175 wpa_msg(wpa_s, MSG_INFO,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
181 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
182 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
184 return 0; /* current profile still in use */
186 wpa_msg(wpa_s, MSG_DEBUG,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid, drv_ssid_len));
189 /* continue selecting a new network profile */
192 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
194 ssid = wpa_supplicant_get_ssid(wpa_s);
196 wpa_msg(wpa_s, MSG_INFO,
197 "No network configuration found for the current AP");
201 if (wpas_network_disabled(wpa_s, ssid)) {
202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
206 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
207 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
208 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
212 res = wpas_temp_disabled(wpa_s, ssid);
214 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
215 "disabled for %d second(s)", res);
219 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
221 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
223 size_t wpa_ie_len = sizeof(wpa_ie);
224 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
225 wpa_ie, &wpa_ie_len) < 0)
226 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
228 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
231 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
232 eapol_sm_invalidate_cached_session(wpa_s->eapol);
233 old_ssid = wpa_s->current_ssid;
234 wpa_s->current_ssid = ssid;
236 wpa_supplicant_update_current_bss(wpa_s);
238 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
239 wpa_supplicant_initiate_eapol(wpa_s);
240 if (old_ssid != wpa_s->current_ssid)
241 wpas_notify_network_changed(wpa_s);
247 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
249 struct wpa_supplicant *wpa_s = eloop_ctx;
251 if (wpa_s->countermeasures) {
252 wpa_s->countermeasures = 0;
253 wpa_drv_set_countermeasures(wpa_s, 0);
254 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
263 wpa_supplicant_cancel_sched_scan(wpa_s);
264 wpa_supplicant_req_scan(wpa_s, 0, 0);
269 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
273 wnm_bss_keep_alive_deinit(wpa_s);
275 #ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s->ibss_rsn);
277 wpa_s->ibss_rsn = NULL;
278 #endif /* CONFIG_IBSS_RSN */
281 wpa_supplicant_ap_deinit(wpa_s);
282 #endif /* CONFIG_AP */
284 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
287 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
288 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
289 os_memset(wpa_s->bssid, 0, ETH_ALEN);
290 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
291 sme_clear_on_disassoc(wpa_s);
292 wpa_s->current_bss = NULL;
293 wpa_s->assoc_freq = 0;
296 wpas_notify_bssid_changed(wpa_s);
298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
300 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
301 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
302 wpa_s->ap_ies_from_associnfo = 0;
303 wpa_s->current_ssid = NULL;
304 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
307 wpas_rrm_reset(wpa_s);
308 wpa_s->wnmsleep_used = 0;
312 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
314 struct wpa_ie_data ie;
318 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
322 for (i = 0; i < ie.num_pmkid; i++) {
323 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
324 ie.pmkid + i * PMKID_LEN,
326 if (pmksa_set == 0) {
327 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
332 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
333 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
337 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
338 union wpa_event_data *data)
341 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
345 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
346 " index=%d preauth=%d",
347 MAC2STR(data->pmkid_candidate.bssid),
348 data->pmkid_candidate.index,
349 data->pmkid_candidate.preauth);
351 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
352 data->pmkid_candidate.index,
353 data->pmkid_candidate.preauth);
357 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
360 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
363 #ifdef IEEE8021X_EAPOL
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
365 wpa_s->current_ssid &&
366 !(wpa_s->current_ssid->eapol_flags &
367 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
368 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
369 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
370 * plaintext or static WEP keys). */
373 #endif /* IEEE8021X_EAPOL */
380 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
381 * @wpa_s: pointer to wpa_supplicant data
382 * @ssid: Configuration data for the network
383 * Returns: 0 on success, -1 on failure
385 * This function is called when starting authentication with a network that is
386 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
388 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
389 struct wpa_ssid *ssid)
391 #ifdef IEEE8021X_EAPOL
393 int aka = 0, sim = 0;
395 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
396 wpa_s->scard != NULL || wpa_s->conf->external_sim)
399 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
403 struct eap_method_type *eap = ssid->eap.eap_methods;
404 while (eap->vendor != EAP_VENDOR_IETF ||
405 eap->method != EAP_TYPE_NONE) {
406 if (eap->vendor == EAP_VENDOR_IETF) {
407 if (eap->method == EAP_TYPE_SIM)
409 else if (eap->method == EAP_TYPE_AKA ||
410 eap->method == EAP_TYPE_AKA_PRIME)
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
419 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
420 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
425 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
426 "use SIM, but neither EAP-SIM nor EAP-AKA are "
431 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
432 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
434 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
435 if (wpa_s->scard == NULL) {
436 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
440 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
441 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
442 #endif /* PCSC_FUNCS */
443 #endif /* IEEE8021X_EAPOL */
449 #ifndef CONFIG_NO_SCAN_PROCESSING
451 static int has_wep_key(struct wpa_ssid *ssid)
455 for (i = 0; i < NUM_WEP_KEYS; i++) {
456 if (ssid->wep_key_len[i])
464 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
465 struct wpa_ssid *ssid)
469 if (ssid->mixed_cell)
473 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
475 #endif /* CONFIG_WPS */
477 if (has_wep_key(ssid))
480 #ifdef IEEE8021X_EAPOL
481 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
482 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
483 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
485 #endif /* IEEE8021X_EAPOL */
487 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
490 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
493 if (bss->caps & IEEE80211_CAP_PRIVACY)
499 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid,
503 struct wpa_ie_data ie;
505 const u8 *rsn_ie, *wpa_ie;
509 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
513 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
514 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
515 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
516 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
517 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
519 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
520 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
523 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
524 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
530 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
532 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
537 if (!(ie.proto & ssid->proto)) {
538 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
543 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
544 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
549 if (!(ie.group_cipher & ssid->group_cipher)) {
550 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
555 if (!(ie.key_mgmt & ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
561 #ifdef CONFIG_IEEE80211W
562 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
563 wpas_get_ssid_pmf(wpa_s, ssid) ==
564 MGMT_FRAME_PROTECTION_REQUIRED) {
565 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
569 #endif /* CONFIG_IEEE80211W */
570 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
571 wpas_get_ssid_pmf(wpa_s, ssid) ==
572 NO_MGMT_FRAME_PROTECTION) {
573 wpa_dbg(wpa_s, MSG_DEBUG,
574 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
578 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
579 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
580 wpas_get_ssid_pmf(wpa_s, ssid) !=
581 NO_MGMT_FRAME_PROTECTION) {
582 wpa_dbg(wpa_s, MSG_DEBUG,
583 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
586 #endif /* CONFIG_MBO */
588 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
592 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
593 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
596 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
597 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
603 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
605 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
610 if (!(ie.proto & ssid->proto)) {
611 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
616 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
617 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
622 if (!(ie.group_cipher & ssid->group_cipher)) {
623 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
628 if (!(ie.key_mgmt & ssid->key_mgmt)) {
629 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
634 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
638 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
640 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
644 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
645 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
646 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
650 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
651 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
652 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
656 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
657 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
661 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
668 static int freq_allowed(int *freqs, int freq)
675 for (i = 0; freqs[i]; i++)
676 if (freqs[i] == freq)
682 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
684 const struct hostapd_hw_modes *mode = NULL, *modes;
685 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
690 return 1; /* Cannot do matching without knowing band */
692 modes = wpa_s->hw.modes;
695 * The driver does not provide any additional information
696 * about the utilized hardware, so allow the connection attempt
702 for (i = 0; i < wpa_s->hw.num_modes; i++) {
703 for (j = 0; j < modes[i].num_channels; j++) {
704 int freq = modes[i].channels[j].freq;
705 if (freq == bss->freq) {
707 mode->mode == HOSTAPD_MODE_IEEE80211G)
708 break; /* do not allow 802.11b replace
719 for (i = 0; i < (int) sizeof(scan_ie); i++) {
720 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
724 for (j = 2; j < rate_ie[1] + 2; j++) {
725 int flagged = !!(rate_ie[j] & 0x80);
726 int r = (rate_ie[j] & 0x7f) * 5;
729 * IEEE Std 802.11n-2009 7.3.2.2:
730 * The new BSS Membership selector value is encoded
731 * like a legacy basic rate, but it is not a rate and
732 * only indicates if the BSS members are required to
733 * support the mandatory features of Clause 20 [HT PHY]
734 * in order to join the BSS.
736 if (flagged && ((rate_ie[j] & 0x7f) ==
737 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
738 if (!ht_supported(mode)) {
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " hardware does not support "
747 /* There's also a VHT selector for 802.11ac */
748 if (flagged && ((rate_ie[j] & 0x7f) ==
749 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
750 if (!vht_supported(mode)) {
751 wpa_dbg(wpa_s, MSG_DEBUG,
752 " hardware does not support "
762 /* check for legacy basic rates */
763 for (k = 0; k < mode->num_rates; k++) {
764 if (mode->rates[k] == r)
767 if (k == mode->num_rates) {
769 * IEEE Std 802.11-2007 7.3.2.2 demands that in
770 * order to join a BSS all required rates
771 * have to be supported by the hardware.
773 wpa_dbg(wpa_s, MSG_DEBUG,
774 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
776 bss->freq, mode->mode, mode->num_rates);
787 * Test whether BSS is in an ESS.
788 * This is done differently in DMG (60 GHz) and non-DMG bands
790 static int bss_is_ess(struct wpa_bss *bss)
792 if (bss_is_dmg(bss)) {
793 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
794 IEEE80211_CAP_DMG_AP;
797 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
802 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
806 for (i = 0; i < ETH_ALEN; i++) {
807 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
814 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
818 for (i = 0; i < num; i++) {
819 const u8 *a = list + i * ETH_ALEN * 2;
820 const u8 *m = a + ETH_ALEN;
822 if (match_mac_mask(a, addr, m))
829 struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
830 int i, struct wpa_bss *bss,
831 struct wpa_ssid *group,
834 u8 wpa_ie_len, rsn_ie_len;
836 struct wpa_blacklist *e;
838 struct wpa_ssid *ssid;
841 const u8 *assoc_disallow;
842 #endif /* CONFIG_MBO */
844 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
845 wpa_ie_len = ie ? ie[1] : 0;
847 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
848 rsn_ie_len = ie ? ie[1] : 0;
850 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
853 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
854 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
855 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
856 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
857 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
858 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
859 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
861 osen ? " osen=1" : "");
863 e = wpa_blacklist_get(wpa_s, bss->bssid);
866 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
868 * When only a single network is enabled, we can
869 * trigger blacklisting on the first failure. This
870 * should not be done with multiple enabled networks to
871 * avoid getting forced to move into a worse ESS on
872 * single error if there are no other BSSes of the
877 if (e->count > limit) {
878 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
879 "(count=%d limit=%d)", e->count, limit);
884 if (bss->ssid_len == 0) {
885 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
889 if (disallowed_bssid(wpa_s, bss->bssid)) {
890 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
894 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
895 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
899 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
901 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
902 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
905 if (wpas_network_disabled(wpa_s, ssid)) {
906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
910 res = wpas_temp_disabled(wpa_s, ssid);
912 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
913 "temporarily for %d second(s)", res);
918 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
919 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
924 if (wpa && ssid->ssid_len == 0 &&
925 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
928 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
929 /* Only allow wildcard SSID match if an AP
930 * advertises active WPS operation that matches
933 if (ssid->ssid_len == 0 &&
934 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
937 #endif /* CONFIG_WPS */
939 if (ssid->bssid_set && ssid->ssid_len == 0 &&
940 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
944 (bss->ssid_len != ssid->ssid_len ||
945 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
946 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
950 if (ssid->bssid_set &&
951 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
952 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
956 /* check blacklist */
957 if (ssid->num_bssid_blacklist &&
958 addr_in_list(bss->bssid, ssid->bssid_blacklist,
959 ssid->num_bssid_blacklist)) {
960 wpa_dbg(wpa_s, MSG_DEBUG,
961 " skip - BSSID blacklisted");
965 /* if there is a whitelist, only accept those APs */
966 if (ssid->num_bssid_whitelist &&
967 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
968 ssid->num_bssid_whitelist)) {
969 wpa_dbg(wpa_s, MSG_DEBUG,
970 " skip - BSSID not in whitelist");
974 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
978 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
979 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
980 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
981 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
986 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
988 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
992 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
993 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
998 if (!wpa_supplicant_match_privacy(bss, ssid)) {
999 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
1004 if (!bss_is_ess(bss) && !bss_is_pbss(bss)) {
1005 wpa_dbg(wpa_s, MSG_DEBUG, " skip - neither ESS nor PBSS network");
1009 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1010 wpa_dbg(wpa_s, MSG_DEBUG, " skip - PBSS mismatch (ssid %d bss %d)",
1011 ssid->pbss, bss_is_pbss(bss));
1015 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1016 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1021 if (!rate_match(wpa_s, bss)) {
1022 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1028 if (ssid->p2p_group &&
1029 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1030 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1031 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1035 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1036 struct wpabuf *p2p_ie;
1037 u8 dev_addr[ETH_ALEN];
1039 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1041 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1044 p2p_ie = wpa_bss_get_vendor_ie_multi(
1045 bss, P2P_IE_VENDOR_TYPE);
1046 if (p2p_ie == NULL) {
1047 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1051 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1052 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1054 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1055 wpabuf_free(p2p_ie);
1058 wpabuf_free(p2p_ie);
1062 * TODO: skip the AP if its P2P IE has Group Formation
1063 * bit set in the P2P Group Capability Bitmap and we
1064 * are not in Group Formation with that device.
1066 #endif /* CONFIG_P2P */
1068 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1070 struct os_reltime diff;
1072 os_reltime_sub(&wpa_s->scan_min_time,
1073 &bss->last_update, &diff);
1074 wpa_dbg(wpa_s, MSG_DEBUG,
1075 " skip - scan result not recent enough (%u.%06u seconds too old)",
1076 (unsigned int) diff.sec,
1077 (unsigned int) diff.usec);
1081 assoc_disallow = wpas_mbo_get_bss_attr(
1082 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1083 if (assoc_disallow && assoc_disallow[1] >= 1) {
1084 wpa_dbg(wpa_s, MSG_DEBUG,
1085 " skip - MBO association disallowed (reason %u)",
1090 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
1091 wpa_dbg(wpa_s, MSG_DEBUG,
1092 " skip - MBO retry delay has not passed yet");
1095 #endif /* CONFIG_MBO */
1097 /* Matching configuration found */
1101 /* No matching configuration found */
1106 static struct wpa_bss *
1107 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1108 struct wpa_ssid *group,
1109 struct wpa_ssid **selected_ssid,
1110 int only_first_ssid)
1114 if (only_first_ssid)
1115 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1118 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1121 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1122 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1123 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1125 if (!*selected_ssid)
1127 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1129 MAC2STR(bss->bssid),
1130 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1138 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1139 struct wpa_ssid **selected_ssid)
1141 struct wpa_bss *selected = NULL;
1143 struct wpa_ssid *next_ssid = NULL;
1144 struct wpa_ssid *ssid;
1146 if (wpa_s->last_scan_res == NULL ||
1147 wpa_s->last_scan_res_used == 0)
1148 return NULL; /* no scan results from last update */
1150 if (wpa_s->next_ssid) {
1151 /* check that next_ssid is still valid */
1152 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1153 if (ssid == wpa_s->next_ssid)
1157 wpa_s->next_ssid = NULL;
1160 while (selected == NULL) {
1161 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1162 if (next_ssid && next_ssid->priority ==
1163 wpa_s->conf->pssid[prio]->priority) {
1164 selected = wpa_supplicant_select_bss(
1165 wpa_s, next_ssid, selected_ssid, 1);
1169 selected = wpa_supplicant_select_bss(
1170 wpa_s, wpa_s->conf->pssid[prio],
1176 if (selected == NULL && wpa_s->blacklist &&
1177 !wpa_s->countermeasures) {
1178 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1179 "blacklist and try again");
1180 wpa_blacklist_clear(wpa_s);
1181 wpa_s->blacklist_cleared++;
1182 } else if (selected == NULL)
1186 ssid = *selected_ssid;
1187 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1188 !ssid->passphrase && !ssid->ext_psk) {
1189 const char *field_name, *txt = NULL;
1191 wpa_dbg(wpa_s, MSG_DEBUG,
1192 "PSK/passphrase not yet available for the selected network");
1194 wpas_notify_network_request(wpa_s, ssid,
1195 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1197 field_name = wpa_supplicant_ctrl_req_to_string(
1198 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1199 if (field_name == NULL)
1202 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1211 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1212 int timeout_sec, int timeout_usec)
1214 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1216 * No networks are enabled; short-circuit request so
1217 * we don't wait timeout seconds before transitioning
1218 * to INACTIVE state.
1220 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1221 "since there are no enabled networks");
1222 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1226 wpa_s->scan_for_connection = 1;
1227 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1231 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1232 struct wpa_bss *selected,
1233 struct wpa_ssid *ssid)
1235 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1236 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1237 "PBC session overlap");
1238 wpas_notify_wps_event_pbc_overlap(wpa_s);
1240 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1241 wpa_s->p2p_in_provisioning) {
1242 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1246 #endif /* CONFIG_P2P */
1249 wpas_wps_pbc_overlap(wpa_s);
1250 wpas_wps_cancel(wpa_s);
1251 #endif /* CONFIG_WPS */
1255 wpa_msg(wpa_s, MSG_DEBUG,
1256 "Considering connect request: reassociate: %d selected: "
1257 MACSTR " bssid: " MACSTR " pending: " MACSTR
1258 " wpa_state: %s ssid=%p current_ssid=%p",
1259 wpa_s->reassociate, MAC2STR(selected->bssid),
1260 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1261 wpa_supplicant_state_txt(wpa_s->wpa_state),
1262 ssid, wpa_s->current_ssid);
1265 * Do not trigger new association unless the BSSID has changed or if
1266 * reassociation is requested. If we are in process of associating with
1267 * the selected BSSID, do not trigger new attempt.
1269 if (wpa_s->reassociate ||
1270 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1271 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1272 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1273 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1274 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1276 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1277 ssid != wpa_s->current_ssid)))) {
1278 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1279 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1282 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1283 MAC2STR(selected->bssid));
1284 wpa_supplicant_associate(wpa_s, selected, ssid);
1286 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1287 "connect with the selected AP");
1294 static struct wpa_ssid *
1295 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1298 struct wpa_ssid *ssid;
1300 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1301 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1303 if (wpas_network_disabled(wpa_s, ssid))
1305 if (ssid->mode == IEEE80211_MODE_IBSS ||
1306 ssid->mode == IEEE80211_MODE_AP ||
1307 ssid->mode == IEEE80211_MODE_MESH)
1315 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1316 * on BSS added and BSS changed events */
1317 static void wpa_supplicant_rsn_preauth_scan_results(
1318 struct wpa_supplicant *wpa_s)
1320 struct wpa_bss *bss;
1322 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1325 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1326 const u8 *ssid, *rsn;
1328 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1332 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1336 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1342 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1343 struct wpa_bss *selected,
1344 struct wpa_ssid *ssid)
1346 struct wpa_bss *current_bss = NULL;
1347 #ifndef CONFIG_NO_ROAMING
1350 #endif /* CONFIG_NO_ROAMING */
1352 if (wpa_s->reassociate)
1353 return 1; /* explicit request to reassociate */
1354 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1355 return 1; /* we are not associated; continue */
1356 if (wpa_s->current_ssid == NULL)
1357 return 1; /* unknown current SSID */
1358 if (wpa_s->current_ssid != ssid)
1359 return 1; /* different network block */
1361 if (wpas_driver_bss_selection(wpa_s))
1362 return 0; /* Driver-based roaming */
1364 if (wpa_s->current_ssid->ssid)
1365 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1366 wpa_s->current_ssid->ssid,
1367 wpa_s->current_ssid->ssid_len);
1369 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1372 return 1; /* current BSS not seen in scan results */
1374 if (current_bss == selected)
1377 if (selected->last_update_idx > current_bss->last_update_idx)
1378 return 1; /* current BSS not seen in the last scan */
1380 #ifndef CONFIG_NO_ROAMING
1381 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1382 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1383 " level=%d snr=%d est_throughput=%u",
1384 MAC2STR(current_bss->bssid), current_bss->level,
1385 current_bss->snr, current_bss->est_throughput);
1386 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1387 " level=%d snr=%d est_throughput=%u",
1388 MAC2STR(selected->bssid), selected->level,
1389 selected->snr, selected->est_throughput);
1391 if (wpa_s->current_ssid->bssid_set &&
1392 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1394 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1395 "has preferred BSSID");
1399 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1400 wpa_dbg(wpa_s, MSG_DEBUG,
1401 "Allow reassociation - selected BSS has better estimated throughput");
1405 to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
1407 if (current_bss->level < 0 &&
1408 current_bss->level > selected->level + to_5ghz * 2) {
1409 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1415 if (current_bss->level < 0) {
1416 if (current_bss->level < -85)
1418 else if (current_bss->level < -80)
1420 else if (current_bss->level < -75)
1422 else if (current_bss->level < -70)
1428 /* Make it easier to move to 5 GHz band */
1434 if (abs(current_bss->level - selected->level) < min_diff) {
1435 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1441 #else /* CONFIG_NO_ROAMING */
1443 #endif /* CONFIG_NO_ROAMING */
1447 /* Return != 0 if no scan results could be fetched or if scan results should not
1448 * be shared with other virtual interfaces. */
1449 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1450 union wpa_event_data *data,
1453 struct wpa_scan_results *scan_res = NULL;
1456 #ifndef CONFIG_NO_RANDOM_POOL
1458 #endif /* CONFIG_NO_RANDOM_POOL */
1461 if (wpa_s->ap_iface)
1463 #endif /* CONFIG_AP */
1465 wpa_supplicant_notify_scanning(wpa_s, 0);
1467 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1468 data ? &data->scan_info :
1470 if (scan_res == NULL) {
1471 if (wpa_s->conf->ap_scan == 2 || ap ||
1472 wpa_s->scan_res_handler == scan_only_handler)
1476 if (data && data->scan_info.external_scan)
1478 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1480 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1482 goto scan_work_done;
1485 #ifndef CONFIG_NO_RANDOM_POOL
1486 num = scan_res->num;
1489 for (i = 0; i < num; i++) {
1491 struct wpa_scan_res *res = scan_res->res[i];
1492 buf[0] = res->bssid[5];
1493 buf[1] = res->qual & 0xff;
1494 buf[2] = res->noise & 0xff;
1495 buf[3] = res->level & 0xff;
1496 buf[4] = res->tsf & 0xff;
1497 random_add_randomness(buf, sizeof(buf));
1499 #endif /* CONFIG_NO_RANDOM_POOL */
1501 if (own_request && wpa_s->scan_res_handler &&
1502 !(data && data->scan_info.external_scan)) {
1503 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1504 struct wpa_scan_results *scan_res);
1506 scan_res_handler = wpa_s->scan_res_handler;
1507 wpa_s->scan_res_handler = NULL;
1508 scan_res_handler(wpa_s, scan_res);
1510 goto scan_work_done;
1514 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1516 if (wpa_s->ap_iface->scan_cb)
1517 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1518 #endif /* CONFIG_AP */
1519 goto scan_work_done;
1522 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1523 wpa_s->own_scan_running,
1524 data ? data->scan_info.external_scan : 0);
1525 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1526 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1527 own_request && !(data && data->scan_info.external_scan)) {
1528 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1529 wpa_s->manual_scan_id);
1530 wpa_s->manual_scan_use_id = 0;
1532 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1534 wpas_notify_scan_results(wpa_s);
1536 wpas_notify_scan_done(wpa_s, 1);
1538 if (data && data->scan_info.external_scan) {
1539 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1540 wpa_scan_results_free(scan_res);
1544 if (wnm_scan_process(wpa_s, 1) > 0)
1545 goto scan_work_done;
1547 if (sme_proc_obss_scan(wpa_s) > 0)
1548 goto scan_work_done;
1550 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1551 goto scan_work_done;
1553 if (autoscan_notify_scan(wpa_s, scan_res))
1554 goto scan_work_done;
1556 if (wpa_s->disconnected) {
1557 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1558 goto scan_work_done;
1561 if (!wpas_driver_bss_selection(wpa_s) &&
1562 bgscan_notify_scan(wpa_s, scan_res) == 1)
1563 goto scan_work_done;
1565 wpas_wps_update_ap_info(wpa_s, scan_res);
1567 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1568 wpa_s->wpa_state < WPA_COMPLETED)
1569 goto scan_work_done;
1571 wpa_scan_results_free(scan_res);
1573 if (own_request && wpa_s->scan_work) {
1574 struct wpa_radio_work *work = wpa_s->scan_work;
1575 wpa_s->scan_work = NULL;
1576 radio_work_done(work);
1579 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1582 wpa_scan_results_free(scan_res);
1583 if (own_request && wpa_s->scan_work) {
1584 struct wpa_radio_work *work = wpa_s->scan_work;
1585 wpa_s->scan_work = NULL;
1586 radio_work_done(work);
1592 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1593 int new_scan, int own_request)
1595 struct wpa_bss *selected;
1596 struct wpa_ssid *ssid = NULL;
1597 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1599 if (time_to_reenable > 0) {
1600 wpa_dbg(wpa_s, MSG_DEBUG,
1601 "Postpone network selection by %d seconds since all networks are disabled",
1603 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1604 eloop_register_timeout(time_to_reenable, 0,
1605 wpas_network_reenabled, wpa_s, NULL);
1609 if (wpa_s->p2p_mgmt)
1610 return 0; /* no normal connection on p2p_mgmt interface */
1612 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1616 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1619 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1623 if (ssid != wpa_s->current_ssid &&
1624 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1625 wpa_s->own_disconnect_req = 1;
1626 wpa_supplicant_deauthenticate(
1627 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1630 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1631 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1635 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1637 * Do not notify other virtual radios of scan results since we do not
1638 * want them to start other associations at the same time.
1644 wpa_msg(wpa_s, MSG_INFO,
1645 "Avoiding join because we already joined a mesh group");
1648 #endif /* CONFIG_MESH */
1649 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1650 ssid = wpa_supplicant_pick_new_network(wpa_s);
1652 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1653 wpa_supplicant_associate(wpa_s, NULL, ssid);
1655 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1656 } else if (own_request) {
1658 * No SSID found. If SCAN results are as a result of
1659 * own scan request and not due to a scan request on
1660 * another shared interface, try another scan.
1662 int timeout_sec = wpa_s->scan_interval;
1663 int timeout_usec = 0;
1667 res = wpas_p2p_scan_no_go_seen(wpa_s);
1673 if (wpa_s->p2p_in_provisioning ||
1674 wpa_s->show_group_started ||
1675 wpa_s->p2p_in_invitation) {
1677 * Use shorter wait during P2P Provisioning
1678 * state and during P2P join-a-group operation
1679 * to speed up group formation.
1682 timeout_usec = 250000;
1683 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1687 #endif /* CONFIG_P2P */
1688 #ifdef CONFIG_INTERWORKING
1689 if (wpa_s->conf->auto_interworking &&
1690 wpa_s->conf->interworking &&
1691 wpa_s->conf->cred) {
1692 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1693 "start ANQP fetch since no matching "
1695 wpa_s->network_select = 1;
1696 wpa_s->auto_network_select = 1;
1697 interworking_start_fetch_anqp(wpa_s);
1700 #endif /* CONFIG_INTERWORKING */
1702 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1703 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1705 timeout_usec = 500000;
1706 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1710 #endif /* CONFIG_WPS */
1711 if (wpa_supplicant_req_sched_scan(wpa_s))
1712 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1715 wpa_msg_ctrl(wpa_s, MSG_INFO,
1716 WPA_EVENT_NETWORK_NOT_FOUND);
1723 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1724 union wpa_event_data *data)
1726 struct wpa_supplicant *ifs;
1729 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1732 * Interface may have been removed, so must not dereference
1739 * If no scan results could be fetched, then no need to
1740 * notify those interfaces that did not actually request
1741 * this scan. Similarly, if scan results started a new operation on this
1742 * interface, do not notify other interfaces to avoid concurrent
1743 * operations during a connection attempt.
1749 * Check other interfaces to see if they share the same radio. If
1750 * so, they get updated with this same scan info.
1752 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1755 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1756 "sibling", ifs->ifname);
1757 _wpa_supplicant_event_scan_results(ifs, data, 0);
1764 #endif /* CONFIG_NO_SCAN_PROCESSING */
1767 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1769 #ifdef CONFIG_NO_SCAN_PROCESSING
1771 #else /* CONFIG_NO_SCAN_PROCESSING */
1772 struct os_reltime now;
1774 if (wpa_s->last_scan_res_used == 0)
1777 os_get_reltime(&now);
1778 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1779 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1783 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1784 #endif /* CONFIG_NO_SCAN_PROCESSING */
1789 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1791 struct wpa_supplicant *wpa_s = eloop_ctx;
1793 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1796 if (!wpa_s->no_keep_alive) {
1797 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1798 MAC2STR(wpa_s->bssid));
1799 /* TODO: could skip this if normal data traffic has been sent */
1800 /* TODO: Consider using some more appropriate data frame for
1803 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1808 if (wpa_s->sme.bss_max_idle_period) {
1810 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1813 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1814 wnm_bss_keep_alive, wpa_s, NULL);
1816 #endif /* CONFIG_SME */
1820 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1821 const u8 *ies, size_t ies_len)
1823 struct ieee802_11_elems elems;
1828 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1832 if (elems.bss_max_idle_period) {
1834 wpa_s->sme.bss_max_idle_period =
1835 WPA_GET_LE16(elems.bss_max_idle_period);
1836 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1837 "TU)%s", wpa_s->sme.bss_max_idle_period,
1838 (elems.bss_max_idle_period[2] & 0x01) ?
1839 " (protected keep-live required)" : "");
1840 if (wpa_s->sme.bss_max_idle_period == 0)
1841 wpa_s->sme.bss_max_idle_period = 1;
1842 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1843 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1844 /* msec times 1000 */
1845 msec = wpa_s->sme.bss_max_idle_period * 1024;
1848 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1849 wnm_bss_keep_alive, wpa_s,
1853 #endif /* CONFIG_SME */
1856 #endif /* CONFIG_WNM */
1859 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1862 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1863 #endif /* CONFIG_WNM */
1867 #ifdef CONFIG_INTERWORKING
1869 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1874 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1875 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1877 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1884 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1885 const u8 *ies, size_t ies_len)
1887 struct ieee802_11_elems elems;
1892 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1895 if (elems.qos_map_set) {
1896 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1897 elems.qos_map_set_len);
1901 #endif /* CONFIG_INTERWORKING */
1905 static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1906 const u8 *ie, size_t ie_len)
1908 struct mb_ies_info mb_ies;
1910 if (!ie || !ie_len || !wpa_s->fst)
1913 os_memset(&mb_ies, 0, sizeof(mb_ies));
1915 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1920 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1925 if (ie[0] == WLAN_EID_MULTI_BAND) {
1926 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1927 (unsigned int) len);
1928 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1929 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1937 if (mb_ies.nof_ies > 0) {
1938 wpabuf_free(wpa_s->received_mb_ies);
1939 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1945 #endif /* CONFIG_FST */
1948 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1949 union wpa_event_data *data)
1951 int l, len, found = 0, wpa_found, rsn_found;
1953 #ifdef CONFIG_IEEE80211R
1955 #endif /* CONFIG_IEEE80211R */
1957 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1958 if (data->assoc_info.req_ies)
1959 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1960 data->assoc_info.req_ies_len);
1961 if (data->assoc_info.resp_ies) {
1962 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1963 data->assoc_info.resp_ies_len);
1965 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1966 data->assoc_info.resp_ies_len);
1967 #endif /* CONFIG_TDLS */
1969 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1970 data->assoc_info.resp_ies_len);
1971 #endif /* CONFIG_WNM */
1972 #ifdef CONFIG_INTERWORKING
1973 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1974 data->assoc_info.resp_ies_len);
1975 #endif /* CONFIG_INTERWORKING */
1977 if (data->assoc_info.beacon_ies)
1978 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1979 data->assoc_info.beacon_ies,
1980 data->assoc_info.beacon_ies_len);
1981 if (data->assoc_info.freq)
1982 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1983 data->assoc_info.freq);
1985 p = data->assoc_info.req_ies;
1986 l = data->assoc_info.req_ies_len;
1988 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1989 while (p && l >= 2) {
1992 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1996 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1997 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1998 (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
1999 (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
2000 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
2001 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
2004 wpa_find_assoc_pmkid(wpa_s);
2010 if (!found && data->assoc_info.req_ies)
2011 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
2013 #ifdef CONFIG_IEEE80211R
2015 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
2016 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2017 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2018 data->assoc_info.resp_ies,
2019 data->assoc_info.resp_ies_len,
2021 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2022 "Reassociation Response failed");
2023 wpa_supplicant_deauthenticate(
2024 wpa_s, WLAN_REASON_INVALID_IE);
2029 p = data->assoc_info.resp_ies;
2030 l = data->assoc_info.resp_ies_len;
2032 #ifdef CONFIG_WPS_STRICT
2033 if (p && wpa_s->current_ssid &&
2034 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2036 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2038 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2039 "include WPS IE in (Re)Association Response");
2043 if (wps_validate_assoc_resp(wps) < 0) {
2045 wpa_supplicant_deauthenticate(
2046 wpa_s, WLAN_REASON_INVALID_IE);
2051 #endif /* CONFIG_WPS_STRICT */
2053 /* Go through the IEs and make a copy of the MDIE, if present. */
2054 while (p && l >= 2) {
2057 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2061 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2062 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2063 wpa_s->sme.ft_used = 1;
2064 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2065 MOBILITY_DOMAIN_ID_LEN);
2071 #endif /* CONFIG_SME */
2073 /* Process FT when SME is in the driver */
2074 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2075 wpa_ft_is_completed(wpa_s->wpa)) {
2076 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2077 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2078 data->assoc_info.resp_ies,
2079 data->assoc_info.resp_ies_len,
2081 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2082 "Reassociation Response failed");
2083 wpa_supplicant_deauthenticate(
2084 wpa_s, WLAN_REASON_INVALID_IE);
2087 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2090 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2091 data->assoc_info.resp_ies_len);
2092 #endif /* CONFIG_IEEE80211R */
2094 /* WPA/RSN IE from Beacon/ProbeResp */
2095 p = data->assoc_info.beacon_ies;
2096 l = data->assoc_info.beacon_ies_len;
2098 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2100 wpa_found = rsn_found = 0;
2101 while (p && l >= 2) {
2104 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2109 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2110 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2112 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2116 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2118 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2125 if (!wpa_found && data->assoc_info.beacon_ies)
2126 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2127 if (!rsn_found && data->assoc_info.beacon_ies)
2128 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2129 if (wpa_found || rsn_found)
2130 wpa_s->ap_ies_from_associnfo = 1;
2132 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2133 wpa_s->assoc_freq != data->assoc_info.freq) {
2134 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2136 wpa_s->assoc_freq, data->assoc_info.freq);
2137 wpa_supplicant_update_scan_results(wpa_s);
2140 wpa_s->assoc_freq = data->assoc_info.freq;
2146 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2148 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2150 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2153 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2156 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2157 WPA_IE_VENDOR_TYPE);
2158 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2160 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2161 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2162 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2163 bss_rsn ? 2 + bss_rsn[1] : 0))
2170 static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2171 union wpa_event_data *data)
2174 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2175 struct wpa_bss *bss = wpa_s->current_bss;
2176 const u8 *ieprb, *iebcn;
2178 wpabuf_free(wpa_s->received_mb_ies);
2179 wpa_s->received_mb_ies = NULL;
2182 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2183 wpa_printf(MSG_DEBUG,
2184 "FST: MB IEs updated from Association Response frame");
2189 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2190 wpa_printf(MSG_DEBUG,
2191 "FST: MB IEs updated from association event Beacon IEs");
2198 ieprb = (const u8 *) (bss + 1);
2199 iebcn = ieprb + bss->ie_len;
2201 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2202 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2203 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2204 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2205 #endif /* CONFIG_FST */
2209 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2210 union wpa_event_data *data)
2217 if (wpa_s->ap_iface) {
2220 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2221 data->assoc_info.addr,
2222 data->assoc_info.req_ies,
2223 data->assoc_info.req_ies_len,
2224 data->assoc_info.reassoc);
2227 #endif /* CONFIG_AP */
2229 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2231 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2232 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2235 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2236 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2237 wpa_supplicant_deauthenticate(
2238 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2242 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2243 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2244 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2245 MACSTR, MAC2STR(bssid));
2247 random_add_randomness(bssid, ETH_ALEN);
2248 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2249 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2250 wpas_notify_bssid_changed(wpa_s);
2252 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2253 wpa_clear_keys(wpa_s, bssid);
2255 if (wpa_supplicant_select_config(wpa_s) < 0) {
2256 wpa_supplicant_deauthenticate(
2257 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2262 if (wpa_s->conf->ap_scan == 1 &&
2263 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2264 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2265 wpa_msg(wpa_s, MSG_WARNING,
2266 "WPA/RSN IEs not updated");
2269 wpas_fst_update_mb_assoc(wpa_s, data);
2272 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2273 wpa_s->sme.prev_bssid_set = 1;
2274 wpa_s->sme.last_unprot_disconnect.sec = 0;
2275 #endif /* CONFIG_SME */
2277 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2278 if (wpa_s->current_ssid) {
2279 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2280 * initialized before association, but for other modes,
2281 * initialize PC/SC here, if the current configuration needs
2282 * smartcard or SIM/USIM. */
2283 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2285 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2287 l2_packet_notify_auth_start(wpa_s->l2);
2290 * Set portEnabled first to FALSE in order to get EAP state machine out
2291 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2292 * state machine may transit to AUTHENTICATING state based on obsolete
2293 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2294 * AUTHENTICATED without ever giving chance to EAP state machine to
2297 if (!ft_completed) {
2298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2301 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2302 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2303 /* 802.1X::portControl = Auto */
2304 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2305 wpa_s->eapol_received = 0;
2306 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2307 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2308 (wpa_s->current_ssid &&
2309 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2310 if (wpa_s->current_ssid &&
2311 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2313 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2315 * Set the key after having received joined-IBSS event
2318 wpa_supplicant_set_wpa_none_key(wpa_s,
2319 wpa_s->current_ssid);
2321 wpa_supplicant_cancel_auth_timeout(wpa_s);
2322 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2323 } else if (!ft_completed) {
2324 /* Timeout for receiving the first EAPOL packet */
2325 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2327 wpa_supplicant_cancel_scan(wpa_s);
2329 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2330 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2332 * We are done; the driver will take care of RSN 4-way
2335 wpa_supplicant_cancel_auth_timeout(wpa_s);
2336 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2337 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2338 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2339 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2340 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2342 * The driver will take care of RSN 4-way handshake, so we need
2343 * to allow EAPOL supplicant to complete its work without
2344 * waiting for WPA supplicant.
2346 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2347 } else if (ft_completed) {
2349 * FT protocol completed - make sure EAPOL state machine ends
2350 * up in authenticated.
2352 wpa_supplicant_cancel_auth_timeout(wpa_s);
2353 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2354 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2355 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2358 wpa_s->last_eapol_matches_bssid = 0;
2360 if (wpa_s->pending_eapol_rx) {
2361 struct os_reltime now, age;
2362 os_get_reltime(&now);
2363 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2364 if (age.sec == 0 && age.usec < 100000 &&
2365 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2367 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2368 "frame that was received just before "
2369 "association notification");
2370 wpa_supplicant_rx_eapol(
2371 wpa_s, wpa_s->pending_eapol_rx_src,
2372 wpabuf_head(wpa_s->pending_eapol_rx),
2373 wpabuf_len(wpa_s->pending_eapol_rx));
2375 wpabuf_free(wpa_s->pending_eapol_rx);
2376 wpa_s->pending_eapol_rx = NULL;
2379 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2380 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2381 wpa_s->current_ssid &&
2382 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2383 /* Set static WEP keys again */
2384 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2387 #ifdef CONFIG_IBSS_RSN
2388 if (wpa_s->current_ssid &&
2389 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2390 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2391 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2392 wpa_s->ibss_rsn == NULL) {
2393 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2394 if (!wpa_s->ibss_rsn) {
2395 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2396 wpa_supplicant_deauthenticate(
2397 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2401 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2403 #endif /* CONFIG_IBSS_RSN */
2405 wpas_wps_notify_assoc(wpa_s, bssid);
2408 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2409 data->assoc_info.resp_ies_len,
2410 &data->assoc_info.wmm_params);
2412 if (wpa_s->reassoc_same_bss)
2413 wmm_ac_restore_tspecs(wpa_s);
2418 static int disconnect_reason_recoverable(u16 reason_code)
2420 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2421 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2422 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2426 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2428 int locally_generated)
2432 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2434 * At least Host AP driver and a Prism3 card seemed to be
2435 * generating streams of disconnected events when configuring
2436 * IBSS for WPA-None. Ignore them for now.
2441 bssid = wpa_s->bssid;
2442 if (is_zero_ether_addr(bssid))
2443 bssid = wpa_s->pending_bssid;
2445 if (!is_zero_ether_addr(bssid) ||
2446 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2447 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2449 MAC2STR(bssid), reason_code,
2450 locally_generated ? " locally_generated=1" : "");
2455 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2456 int locally_generated)
2458 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2459 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2460 return 0; /* Not in 4-way handshake with PSK */
2463 * It looks like connection was lost while trying to go through PSK
2464 * 4-way handshake. Filter out known disconnection cases that are caused
2465 * by something else than PSK mismatch to avoid confusing reports.
2468 if (locally_generated) {
2469 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2477 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2479 int locally_generated)
2483 u8 prev_pending_bssid[ETH_ALEN];
2484 struct wpa_bss *fast_reconnect = NULL;
2485 struct wpa_ssid *fast_reconnect_ssid = NULL;
2486 struct wpa_ssid *last_ssid;
2488 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2489 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2491 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2493 * At least Host AP driver and a Prism3 card seemed to be
2494 * generating streams of disconnected events when configuring
2495 * IBSS for WPA-None. Ignore them for now.
2497 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2498 "IBSS/WPA-None mode");
2502 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2503 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2504 "pre-shared key may be incorrect");
2505 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2506 return; /* P2P group removed */
2507 wpas_auth_failed(wpa_s, "WRONG_KEY");
2509 if (!wpa_s->disconnected &&
2510 (!wpa_s->auto_reconnect_disabled ||
2511 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2512 wpas_wps_searching(wpa_s) ||
2513 wpas_wps_reenable_networks_pending(wpa_s))) {
2514 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2515 "reconnect (wps=%d/%d wpa_state=%d)",
2516 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2517 wpas_wps_searching(wpa_s),
2519 if (wpa_s->wpa_state == WPA_COMPLETED &&
2520 wpa_s->current_ssid &&
2521 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2522 !locally_generated &&
2523 disconnect_reason_recoverable(reason_code)) {
2525 * It looks like the AP has dropped association with
2526 * us, but could allow us to get back in. Try to
2527 * reconnect to the same BSS without full scan to save
2528 * time for some common cases.
2530 fast_reconnect = wpa_s->current_bss;
2531 fast_reconnect_ssid = wpa_s->current_ssid;
2532 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2533 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2535 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2538 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2539 "try to re-connect");
2540 wpa_s->reassociate = 0;
2541 wpa_s->disconnected = 1;
2543 wpa_supplicant_cancel_sched_scan(wpa_s);
2545 bssid = wpa_s->bssid;
2546 if (is_zero_ether_addr(bssid))
2547 bssid = wpa_s->pending_bssid;
2548 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2549 wpas_connection_failed(wpa_s, bssid);
2550 wpa_sm_notify_disassoc(wpa_s->wpa);
2551 if (locally_generated)
2552 wpa_s->disconnect_reason = -reason_code;
2554 wpa_s->disconnect_reason = reason_code;
2555 wpas_notify_disconnect_reason(wpa_s);
2556 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2557 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2558 wpa_clear_keys(wpa_s, wpa_s->bssid);
2560 last_ssid = wpa_s->current_ssid;
2561 wpa_supplicant_mark_disassoc(wpa_s);
2563 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2564 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2565 wpa_s->current_ssid = last_ssid;
2568 if (fast_reconnect &&
2569 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2570 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2571 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2572 fast_reconnect->ssid_len) &&
2573 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
2574 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
2575 #ifndef CONFIG_NO_SCAN_PROCESSING
2576 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2577 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2578 fast_reconnect_ssid) < 0) {
2579 /* Recover through full scan */
2580 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2582 #endif /* CONFIG_NO_SCAN_PROCESSING */
2583 } else if (fast_reconnect) {
2585 * Could not reconnect to the same BSS due to network being
2586 * disabled. Use a new scan to match the alternative behavior
2587 * above, i.e., to continue automatic reconnection attempt in a
2588 * way that enforces disabled network rules.
2590 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2595 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2596 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2598 struct wpa_supplicant *wpa_s = eloop_ctx;
2600 if (!wpa_s->pending_mic_error_report)
2603 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2604 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2605 wpa_s->pending_mic_error_report = 0;
2607 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2611 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2612 union wpa_event_data *data)
2615 struct os_reltime t;
2617 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2618 pairwise = (data && data->michael_mic_failure.unicast);
2620 if ((wpa_s->last_michael_mic_error.sec &&
2621 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2622 wpa_s->pending_mic_error_report) {
2623 if (wpa_s->pending_mic_error_report) {
2625 * Send the pending MIC error report immediately since
2626 * we are going to start countermeasures and AP better
2629 wpa_sm_key_request(wpa_s->wpa, 1,
2630 wpa_s->pending_mic_error_pairwise);
2633 /* Send the new MIC error report immediately since we are going
2634 * to start countermeasures and AP better do the same.
2636 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2638 /* initialize countermeasures */
2639 wpa_s->countermeasures = 1;
2641 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2643 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2646 * Need to wait for completion of request frame. We do not get
2647 * any callback for the message completion, so just wait a
2648 * short while and hope for the best. */
2651 wpa_drv_set_countermeasures(wpa_s, 1);
2652 wpa_supplicant_deauthenticate(wpa_s,
2653 WLAN_REASON_MICHAEL_MIC_FAILURE);
2654 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2656 eloop_register_timeout(60, 0,
2657 wpa_supplicant_stop_countermeasures,
2659 /* TODO: mark the AP rejected for 60 second. STA is
2660 * allowed to associate with another AP.. */
2662 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2663 if (wpa_s->mic_errors_seen) {
2665 * Reduce the effectiveness of Michael MIC error
2666 * reports as a means for attacking against TKIP if
2667 * more than one MIC failure is noticed with the same
2668 * PTK. We delay the transmission of the reports by a
2669 * random time between 0 and 60 seconds in order to
2670 * force the attacker wait 60 seconds before getting
2671 * the information on whether a frame resulted in a MIC
2677 if (os_get_random(rval, sizeof(rval)) < 0)
2678 sec = os_random() % 60;
2680 sec = WPA_GET_BE32(rval) % 60;
2681 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2682 "report %d seconds", sec);
2683 wpa_s->pending_mic_error_report = 1;
2684 wpa_s->pending_mic_error_pairwise = pairwise;
2685 eloop_cancel_timeout(
2686 wpa_supplicant_delayed_mic_error_report,
2688 eloop_register_timeout(
2689 sec, os_random() % 1000000,
2690 wpa_supplicant_delayed_mic_error_report,
2693 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2695 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2696 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2697 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2699 wpa_s->last_michael_mic_error = t;
2700 wpa_s->mic_errors_seen++;
2704 #ifdef CONFIG_TERMINATE_ONLASTIF
2705 static int any_interfaces(struct wpa_supplicant *head)
2707 struct wpa_supplicant *wpa_s;
2709 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2710 if (!wpa_s->interface_removed)
2714 #endif /* CONFIG_TERMINATE_ONLASTIF */
2718 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2719 union wpa_event_data *data)
2721 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2724 switch (data->interface_status.ievent) {
2725 case EVENT_INTERFACE_ADDED:
2726 if (!wpa_s->interface_removed)
2728 wpa_s->interface_removed = 0;
2729 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2730 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2731 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2732 "driver after interface was added");
2736 if (!wpa_s->global->p2p &&
2737 !wpa_s->global->p2p_disabled &&
2738 !wpa_s->conf->p2p_disabled &&
2740 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2741 wpas_p2p_add_p2pdev_interface(
2742 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2743 wpa_printf(MSG_INFO,
2744 "P2P: Failed to enable P2P Device interface");
2745 /* Try to continue without. P2P will be disabled. */
2747 #endif /* CONFIG_P2P */
2750 case EVENT_INTERFACE_REMOVED:
2751 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2752 wpa_s->interface_removed = 1;
2753 wpa_supplicant_mark_disassoc(wpa_s);
2754 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2755 l2_packet_deinit(wpa_s->l2);
2759 if (wpa_s->global->p2p &&
2760 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2762 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2763 wpa_dbg(wpa_s, MSG_DEBUG,
2764 "Removing P2P Device interface");
2765 wpa_supplicant_remove_iface(
2766 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2768 wpa_s->global->p2p_init_wpa_s = NULL;
2770 #endif /* CONFIG_P2P */
2772 #ifdef CONFIG_MATCH_IFACE
2773 if (wpa_s->matched) {
2774 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
2777 #endif /* CONFIG_MATCH_IFACE */
2779 #ifdef CONFIG_TERMINATE_ONLASTIF
2780 /* check if last interface */
2781 if (!any_interfaces(wpa_s->global->ifaces))
2783 #endif /* CONFIG_TERMINATE_ONLASTIF */
2789 #ifdef CONFIG_PEERKEY
2791 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2792 union wpa_event_data *data)
2796 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2798 #endif /* CONFIG_PEERKEY */
2802 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2803 union wpa_event_data *data)
2807 switch (data->tdls.oper) {
2808 case TDLS_REQUEST_SETUP:
2809 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2810 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2811 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2813 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2815 case TDLS_REQUEST_TEARDOWN:
2816 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2817 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2818 data->tdls.reason_code);
2820 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2823 case TDLS_REQUEST_DISCOVER:
2824 wpa_tdls_send_discovery_request(wpa_s->wpa,
2829 #endif /* CONFIG_TDLS */
2833 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2834 union wpa_event_data *data)
2838 switch (data->wnm.oper) {
2839 case WNM_OPER_SLEEP:
2840 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2841 "(action=%d, intval=%d)",
2842 data->wnm.sleep_action, data->wnm.sleep_intval);
2843 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2844 data->wnm.sleep_intval, NULL);
2848 #endif /* CONFIG_WNM */
2851 #ifdef CONFIG_IEEE80211R
2853 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2854 union wpa_event_data *data)
2859 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2860 data->ft_ies.ies_len,
2861 data->ft_ies.ft_action,
2862 data->ft_ies.target_ap,
2863 data->ft_ies.ric_ies,
2864 data->ft_ies.ric_ies_len) < 0) {
2865 /* TODO: prevent MLME/driver from trying to associate? */
2868 #endif /* CONFIG_IEEE80211R */
2871 #ifdef CONFIG_IBSS_RSN
2872 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2873 union wpa_event_data *data)
2875 struct wpa_ssid *ssid;
2876 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2880 ssid = wpa_s->current_ssid;
2883 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2886 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2890 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2891 union wpa_event_data *data)
2893 struct wpa_ssid *ssid = wpa_s->current_ssid;
2898 /* check if the ssid is correctly configured as IBSS/RSN */
2899 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2902 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2903 data->rx_mgmt.frame_len);
2905 #endif /* CONFIG_IBSS_RSN */
2908 #ifdef CONFIG_IEEE80211R
2909 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2912 const u8 *sta_addr, *target_ap_addr;
2915 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2916 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2917 return; /* only SME case supported for now */
2918 if (len < 1 + 2 * ETH_ALEN + 2)
2921 return; /* Only FT Action Response is supported for now */
2922 sta_addr = data + 1;
2923 target_ap_addr = data + 1 + ETH_ALEN;
2924 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2925 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2926 MACSTR " TargetAP " MACSTR " status %u",
2927 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2929 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2930 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2931 " in FT Action Response", MAC2STR(sta_addr));
2936 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2937 "failure (status code %d)", status);
2938 /* TODO: report error to FT code(?) */
2942 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2943 len - (1 + 2 * ETH_ALEN + 2), 1,
2944 target_ap_addr, NULL, 0) < 0)
2949 struct wpa_bss *bss;
2950 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2952 wpa_s->sme.freq = bss->freq;
2953 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2954 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2957 #endif /* CONFIG_SME */
2959 #endif /* CONFIG_IEEE80211R */
2962 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2963 struct unprot_deauth *e)
2965 #ifdef CONFIG_IEEE80211W
2966 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2967 "dropped: " MACSTR " -> " MACSTR
2968 " (reason code %u)",
2969 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2970 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2971 #endif /* CONFIG_IEEE80211W */
2975 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2976 struct unprot_disassoc *e)
2978 #ifdef CONFIG_IEEE80211W
2979 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2980 "dropped: " MACSTR " -> " MACSTR
2981 " (reason code %u)",
2982 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2983 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2984 #endif /* CONFIG_IEEE80211W */
2988 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2989 u16 reason_code, int locally_generated,
2990 const u8 *ie, size_t ie_len, int deauth)
2993 if (wpa_s->ap_iface && addr) {
2994 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2998 if (wpa_s->ap_iface) {
2999 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
3002 #endif /* CONFIG_AP */
3004 if (!locally_generated)
3005 wpa_s->own_disconnect_req = 0;
3007 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
3009 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
3010 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
3011 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
3012 eapol_sm_failed(wpa_s->eapol))) &&
3013 !wpa_s->eap_expected_failure))
3014 wpas_auth_failed(wpa_s, "AUTH_FAILED");
3017 if (deauth && reason_code > 0) {
3018 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3019 locally_generated) > 0) {
3021 * The interface was removed, so cannot continue
3022 * processing any additional operations after this.
3027 #endif /* CONFIG_P2P */
3029 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3034 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3035 struct disassoc_info *info)
3037 u16 reason_code = 0;
3038 int locally_generated = 0;
3039 const u8 *addr = NULL;
3040 const u8 *ie = NULL;
3043 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3048 ie_len = info->ie_len;
3049 reason_code = info->reason_code;
3050 locally_generated = info->locally_generated;
3051 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3052 locally_generated ? " (locally generated)" : "");
3054 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3056 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3061 if (wpa_s->ap_iface && info && info->addr) {
3062 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3066 if (wpa_s->ap_iface) {
3067 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3070 #endif /* CONFIG_AP */
3074 wpas_p2p_disassoc_notif(
3075 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3078 #endif /* CONFIG_P2P */
3080 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3081 sme_event_disassoc(wpa_s, info);
3083 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3088 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3089 struct deauth_info *info)
3091 u16 reason_code = 0;
3092 int locally_generated = 0;
3093 const u8 *addr = NULL;
3094 const u8 *ie = NULL;
3097 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3102 ie_len = info->ie_len;
3103 reason_code = info->reason_code;
3104 locally_generated = info->locally_generated;
3105 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3107 locally_generated ? " (locally generated)" : "");
3109 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3112 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3116 wpa_reset_ft_completed(wpa_s->wpa);
3118 wpas_event_disconnect(wpa_s, addr, reason_code,
3119 locally_generated, ie, ie_len, 1);
3123 static const char * reg_init_str(enum reg_change_initiator init)
3126 case REGDOM_SET_BY_CORE:
3128 case REGDOM_SET_BY_USER:
3130 case REGDOM_SET_BY_DRIVER:
3132 case REGDOM_SET_BY_COUNTRY_IE:
3133 return "COUNTRY_IE";
3134 case REGDOM_BEACON_HINT:
3135 return "BEACON_HINT";
3141 static const char * reg_type_str(enum reg_type type)
3144 case REGDOM_TYPE_UNKNOWN:
3146 case REGDOM_TYPE_COUNTRY:
3148 case REGDOM_TYPE_WORLD:
3150 case REGDOM_TYPE_CUSTOM_WORLD:
3151 return "CUSTOM_WORLD";
3152 case REGDOM_TYPE_INTERSECTION:
3153 return "INTERSECTION";
3159 static void wpa_supplicant_update_channel_list(
3160 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3162 struct wpa_supplicant *ifs;
3164 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3165 reg_init_str(info->initiator), reg_type_str(info->type),
3166 info->alpha2[0] ? " alpha2=" : "",
3167 info->alpha2[0] ? info->alpha2 : "");
3169 if (wpa_s->drv_priv == NULL)
3170 return; /* Ignore event during drv initialization */
3172 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3174 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3176 free_hw_features(ifs);
3177 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3178 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3181 /* Restart sched_scan with updated channel list */
3182 if (wpa_s->sched_scanning) {
3183 wpa_dbg(wpa_s, MSG_DEBUG,
3184 "Channel list changed restart sched scan.");
3185 wpa_supplicant_cancel_sched_scan(wpa_s);
3186 wpa_supplicant_req_scan(wpa_s, 0, 0);
3189 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3193 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3194 const u8 *frame, size_t len, int freq,
3197 const struct ieee80211_mgmt *mgmt;
3202 if (len < IEEE80211_HDRLEN + 2)
3205 mgmt = (const struct ieee80211_mgmt *) frame;
3206 payload = frame + IEEE80211_HDRLEN;
3207 category = *payload++;
3208 plen = len - IEEE80211_HDRLEN - 1;
3210 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3211 " Category=%u DataLen=%d freq=%d MHz",
3212 MAC2STR(mgmt->sa), category, (int) plen, freq);
3214 if (category == WLAN_ACTION_WMM) {
3215 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3219 #ifdef CONFIG_IEEE80211R
3220 if (category == WLAN_ACTION_FT) {
3221 ft_rx_action(wpa_s, payload, plen);
3224 #endif /* CONFIG_IEEE80211R */
3226 #ifdef CONFIG_IEEE80211W
3228 if (category == WLAN_ACTION_SA_QUERY) {
3229 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3232 #endif /* CONFIG_SME */
3233 #endif /* CONFIG_IEEE80211W */
3236 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3237 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3240 #endif /* CONFIG_WNM */
3243 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3244 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3245 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3246 mgmt->u.action.category,
3247 payload, plen, freq) == 0)
3249 #endif /* CONFIG_GAS */
3252 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3253 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3254 wpa_dbg(wpa_s, MSG_DEBUG,
3255 "TDLS: Received Discovery Response from " MACSTR,
3259 #endif /* CONFIG_TDLS */
3261 #ifdef CONFIG_INTERWORKING
3262 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3263 payload[0] == QOS_QOS_MAP_CONFIG) {
3264 const u8 *pos = payload + 1;
3265 size_t qlen = plen - 1;
3266 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3267 MACSTR, MAC2STR(mgmt->sa));
3268 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3269 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3270 pos[1] <= qlen - 2 && pos[1] >= 16)
3271 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3274 #endif /* CONFIG_INTERWORKING */
3276 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3277 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3278 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3282 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3283 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3284 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3285 payload + 1, plen - 1,
3291 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3292 fst_rx_action(wpa_s->fst, mgmt, len);
3295 #endif /* CONFIG_FST */
3297 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3298 category, payload, plen, freq);
3300 mesh_mpm_action_rx(wpa_s, mgmt, len);
3304 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3305 union wpa_event_data *event)
3307 struct wpa_freq_range_list *list;
3310 list = &event->freq_range;
3313 str = freq_range_list_str(list);
3314 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3318 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3319 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3322 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3325 * The update channel flow will also take care of moving a GO
3326 * from the unsafe frequency if needed.
3328 wpas_p2p_update_channel_list(wpa_s,
3329 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3331 #endif /* CONFIG_P2P */
3337 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3338 union wpa_event_data *data)
3340 wpa_dbg(wpa_s, MSG_DEBUG,
3341 "Connection authorized by device, previous state %d",
3343 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3344 wpa_supplicant_cancel_auth_timeout(wpa_s);
3345 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3346 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3347 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3349 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3350 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3351 data->assoc_info.ptk_kck_len,
3352 data->assoc_info.ptk_kek,
3353 data->assoc_info.ptk_kek_len);
3357 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3358 union wpa_event_data *data)
3360 struct wpa_supplicant *wpa_s = ctx;
3363 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3364 event != EVENT_INTERFACE_ENABLED &&
3365 event != EVENT_INTERFACE_STATUS &&
3366 event != EVENT_SCAN_RESULTS &&
3367 event != EVENT_SCHED_SCAN_STOPPED) {
3368 wpa_dbg(wpa_s, MSG_DEBUG,
3369 "Ignore event %s (%d) while interface is disabled",
3370 event_to_string(event), event);
3374 #ifndef CONFIG_NO_STDOUT_DEBUG
3376 int level = MSG_DEBUG;
3378 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3379 const struct ieee80211_hdr *hdr;
3381 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3382 fc = le_to_host16(hdr->frame_control);
3383 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3384 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3385 level = MSG_EXCESSIVE;
3388 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3389 event_to_string(event), event);
3391 #endif /* CONFIG_NO_STDOUT_DEBUG */
3396 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3397 data->auth.ies_len))
3398 wpa_printf(MSG_DEBUG,
3399 "FST: MB IEs updated from auth IE");
3400 #endif /* CONFIG_FST */
3401 sme_event_auth(wpa_s, data);
3404 wpa_supplicant_event_assoc(wpa_s, data);
3405 if (data && data->assoc_info.authorized)
3406 wpa_supplicant_event_assoc_auth(wpa_s, data);
3408 wpa_msg(wpa_s, MSG_INFO,
3409 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3410 data->assoc_info.subnet_status);
3413 case EVENT_DISASSOC:
3414 wpas_event_disassoc(wpa_s,
3415 data ? &data->disassoc_info : NULL);
3418 wpas_event_deauth(wpa_s,
3419 data ? &data->deauth_info : NULL);
3421 case EVENT_MICHAEL_MIC_FAILURE:
3422 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3424 #ifndef CONFIG_NO_SCAN_PROCESSING
3425 case EVENT_SCAN_STARTED:
3426 if (wpa_s->own_scan_requested ||
3427 (data && !data->scan_info.external_scan)) {
3428 struct os_reltime diff;
3430 os_get_reltime(&wpa_s->scan_start_time);
3431 os_reltime_sub(&wpa_s->scan_start_time,
3432 &wpa_s->scan_trigger_time, &diff);
3433 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3434 diff.sec, diff.usec);
3435 wpa_s->own_scan_requested = 0;
3436 wpa_s->own_scan_running = 1;
3437 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3438 wpa_s->manual_scan_use_id) {
3439 wpa_msg_ctrl(wpa_s, MSG_INFO,
3440 WPA_EVENT_SCAN_STARTED "id=%u",
3441 wpa_s->manual_scan_id);
3443 wpa_msg_ctrl(wpa_s, MSG_INFO,
3444 WPA_EVENT_SCAN_STARTED);
3447 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3448 wpa_s->radio->external_scan_running = 1;
3449 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3452 case EVENT_SCAN_RESULTS:
3453 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3454 wpa_s->scan_res_handler = NULL;
3455 wpa_s->own_scan_running = 0;
3456 wpa_s->radio->external_scan_running = 0;
3457 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
3461 if (!(data && data->scan_info.external_scan) &&
3462 os_reltime_initialized(&wpa_s->scan_start_time)) {
3463 struct os_reltime now, diff;
3464 os_get_reltime(&now);
3465 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3466 wpa_s->scan_start_time.sec = 0;
3467 wpa_s->scan_start_time.usec = 0;
3468 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3469 diff.sec, diff.usec);
3471 if (wpa_supplicant_event_scan_results(wpa_s, data))
3472 break; /* interface may have been removed */
3473 if (!(data && data->scan_info.external_scan))
3474 wpa_s->own_scan_running = 0;
3475 if (data && data->scan_info.nl_scan_event)
3476 wpa_s->radio->external_scan_running = 0;
3477 radio_work_check_next(wpa_s);
3479 #endif /* CONFIG_NO_SCAN_PROCESSING */
3480 case EVENT_ASSOCINFO:
3481 wpa_supplicant_event_associnfo(wpa_s, data);
3483 case EVENT_INTERFACE_STATUS:
3484 wpa_supplicant_event_interface_status(wpa_s, data);
3486 case EVENT_PMKID_CANDIDATE:
3487 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3489 #ifdef CONFIG_PEERKEY
3490 case EVENT_STKSTART:
3491 wpa_supplicant_event_stkstart(wpa_s, data);
3493 #endif /* CONFIG_PEERKEY */
3496 wpa_supplicant_event_tdls(wpa_s, data);
3498 #endif /* CONFIG_TDLS */
3501 wpa_supplicant_event_wnm(wpa_s, data);
3503 #endif /* CONFIG_WNM */
3504 #ifdef CONFIG_IEEE80211R
3505 case EVENT_FT_RESPONSE:
3506 wpa_supplicant_event_ft_response(wpa_s, data);
3508 #endif /* CONFIG_IEEE80211R */
3509 #ifdef CONFIG_IBSS_RSN
3510 case EVENT_IBSS_RSN_START:
3511 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3513 #endif /* CONFIG_IBSS_RSN */
3514 case EVENT_ASSOC_REJECT:
3515 if (data->assoc_reject.bssid)
3516 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3517 "bssid=" MACSTR " status_code=%u",
3518 MAC2STR(data->assoc_reject.bssid),
3519 data->assoc_reject.status_code);
3521 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3523 data->assoc_reject.status_code);
3524 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3525 wpas_notify_assoc_status_code(wpa_s);
3526 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3527 sme_event_assoc_reject(wpa_s, data);
3529 const u8 *bssid = data->assoc_reject.bssid;
3530 if (bssid == NULL || is_zero_ether_addr(bssid))
3531 bssid = wpa_s->pending_bssid;
3532 wpas_connection_failed(wpa_s, bssid);
3533 wpa_supplicant_mark_disassoc(wpa_s);
3536 case EVENT_AUTH_TIMED_OUT:
3537 /* It is possible to get this event from earlier connection */
3538 if (wpa_s->current_ssid &&
3539 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3540 wpa_dbg(wpa_s, MSG_DEBUG,
3541 "Ignore AUTH_TIMED_OUT in mesh configuration");
3544 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3545 sme_event_auth_timed_out(wpa_s, data);
3547 case EVENT_ASSOC_TIMED_OUT:
3548 /* It is possible to get this event from earlier connection */
3549 if (wpa_s->current_ssid &&
3550 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3551 wpa_dbg(wpa_s, MSG_DEBUG,
3552 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3555 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3556 sme_event_assoc_timed_out(wpa_s, data);
3558 case EVENT_TX_STATUS:
3559 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3560 " type=%d stype=%d",
3561 MAC2STR(data->tx_status.dst),
3562 data->tx_status.type, data->tx_status.stype);
3564 if (wpa_s->ap_iface == NULL) {
3565 #ifdef CONFIG_OFFCHANNEL
3566 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3567 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3568 offchannel_send_action_tx_status(
3569 wpa_s, data->tx_status.dst,
3570 data->tx_status.data,
3571 data->tx_status.data_len,
3572 data->tx_status.ack ?
3573 OFFCHANNEL_SEND_ACTION_SUCCESS :
3574 OFFCHANNEL_SEND_ACTION_NO_ACK);
3575 #endif /* CONFIG_OFFCHANNEL */
3578 #endif /* CONFIG_AP */
3579 #ifdef CONFIG_OFFCHANNEL
3580 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3581 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3583 * Catch TX status events for Action frames we sent via group
3584 * interface in GO mode.
3586 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3587 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3588 os_memcmp(wpa_s->parent->pending_action_dst,
3589 data->tx_status.dst, ETH_ALEN) == 0) {
3590 offchannel_send_action_tx_status(
3591 wpa_s->parent, data->tx_status.dst,
3592 data->tx_status.data,
3593 data->tx_status.data_len,
3594 data->tx_status.ack ?
3595 OFFCHANNEL_SEND_ACTION_SUCCESS :
3596 OFFCHANNEL_SEND_ACTION_NO_ACK);
3599 #endif /* CONFIG_OFFCHANNEL */
3601 switch (data->tx_status.type) {
3602 case WLAN_FC_TYPE_MGMT:
3603 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3604 data->tx_status.data_len,
3605 data->tx_status.stype,
3606 data->tx_status.ack);
3608 case WLAN_FC_TYPE_DATA:
3609 ap_tx_status(wpa_s, data->tx_status.dst,
3610 data->tx_status.data,
3611 data->tx_status.data_len,
3612 data->tx_status.ack);
3615 #endif /* CONFIG_AP */
3618 case EVENT_EAPOL_TX_STATUS:
3619 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3620 data->eapol_tx_status.data,
3621 data->eapol_tx_status.data_len,
3622 data->eapol_tx_status.ack);
3624 case EVENT_DRIVER_CLIENT_POLL_OK:
3625 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3627 case EVENT_RX_FROM_UNKNOWN:
3628 if (wpa_s->ap_iface == NULL)
3630 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3631 data->rx_from_unknown.wds);
3633 case EVENT_CH_SWITCH:
3634 if (!data || !wpa_s->current_ssid)
3637 wpa_s->assoc_freq = data->ch_switch.freq;
3638 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3640 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3641 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3642 wpa_s->current_ssid->mode ==
3643 WPAS_MODE_P2P_GROUP_FORMATION) {
3644 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3645 data->ch_switch.ht_enabled,
3646 data->ch_switch.ch_offset,
3647 data->ch_switch.ch_width,
3648 data->ch_switch.cf1,
3649 data->ch_switch.cf2);
3652 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3655 case EVENT_DFS_RADAR_DETECTED:
3657 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3659 case EVENT_DFS_CAC_STARTED:
3661 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3663 case EVENT_DFS_CAC_FINISHED:
3665 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3667 case EVENT_DFS_CAC_ABORTED:
3669 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3671 case EVENT_DFS_NOP_FINISHED:
3673 wpas_event_dfs_cac_nop_finished(wpa_s,
3676 #endif /* NEED_AP_MLME */
3677 #endif /* CONFIG_AP */
3678 case EVENT_RX_MGMT: {
3680 const struct ieee80211_mgmt *mgmt;
3682 #ifdef CONFIG_TESTING_OPTIONS
3683 if (wpa_s->ext_mgmt_frame_handling) {
3684 struct rx_mgmt *rx = &data->rx_mgmt;
3685 size_t hex_len = 2 * rx->frame_len + 1;
3686 char *hex = os_malloc(hex_len);
3688 wpa_snprintf_hex(hex, hex_len,
3689 rx->frame, rx->frame_len);
3690 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3691 rx->freq, rx->datarate, rx->ssi_signal,
3697 #endif /* CONFIG_TESTING_OPTIONS */
3699 mgmt = (const struct ieee80211_mgmt *)
3700 data->rx_mgmt.frame;
3701 fc = le_to_host16(mgmt->frame_control);
3702 stype = WLAN_FC_GET_STYPE(fc);
3705 if (wpa_s->ap_iface == NULL) {
3706 #endif /* CONFIG_AP */
3708 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3709 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
3710 const u8 *src = mgmt->sa;
3714 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3715 ie_len = data->rx_mgmt.frame_len -
3717 wpas_p2p_probe_req_rx(
3718 wpa_s, src, mgmt->da,
3719 mgmt->bssid, ie, ie_len,
3721 data->rx_mgmt.ssi_signal);
3724 #endif /* CONFIG_P2P */
3725 #ifdef CONFIG_IBSS_RSN
3726 if (wpa_s->current_ssid &&
3727 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3728 stype == WLAN_FC_STYPE_AUTH &&
3729 data->rx_mgmt.frame_len >= 30) {
3730 wpa_supplicant_event_ibss_auth(wpa_s, data);
3733 #endif /* CONFIG_IBSS_RSN */
3735 if (stype == WLAN_FC_STYPE_ACTION) {
3736 wpas_event_rx_mgmt_action(
3737 wpa_s, data->rx_mgmt.frame,
3738 data->rx_mgmt.frame_len,
3740 data->rx_mgmt.ssi_signal);
3745 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3749 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3750 "management frame in non-AP mode");
3755 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3756 data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
3760 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
3761 ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
3763 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3764 mgmt->bssid, ie, ie_len,
3765 data->rx_mgmt.ssi_signal);
3768 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3769 #endif /* CONFIG_AP */
3772 case EVENT_RX_PROBE_REQ:
3773 if (data->rx_probe_req.sa == NULL ||
3774 data->rx_probe_req.ie == NULL)
3777 if (wpa_s->ap_iface) {
3778 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3779 data->rx_probe_req.sa,
3780 data->rx_probe_req.da,
3781 data->rx_probe_req.bssid,
3782 data->rx_probe_req.ie,
3783 data->rx_probe_req.ie_len,
3784 data->rx_probe_req.ssi_signal);
3787 #endif /* CONFIG_AP */
3788 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3789 data->rx_probe_req.da,
3790 data->rx_probe_req.bssid,
3791 data->rx_probe_req.ie,
3792 data->rx_probe_req.ie_len,
3794 data->rx_probe_req.ssi_signal);
3796 case EVENT_REMAIN_ON_CHANNEL:
3797 #ifdef CONFIG_OFFCHANNEL
3798 offchannel_remain_on_channel_cb(
3799 wpa_s, data->remain_on_channel.freq,
3800 data->remain_on_channel.duration);
3801 #endif /* CONFIG_OFFCHANNEL */
3802 wpas_p2p_remain_on_channel_cb(
3803 wpa_s, data->remain_on_channel.freq,
3804 data->remain_on_channel.duration);
3806 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3807 #ifdef CONFIG_OFFCHANNEL
3808 offchannel_cancel_remain_on_channel_cb(
3809 wpa_s, data->remain_on_channel.freq);
3810 #endif /* CONFIG_OFFCHANNEL */
3811 wpas_p2p_cancel_remain_on_channel_cb(
3812 wpa_s, data->remain_on_channel.freq);
3814 case EVENT_EAPOL_RX:
3815 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3816 data->eapol_rx.data,
3817 data->eapol_rx.data_len);
3819 case EVENT_SIGNAL_CHANGE:
3820 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3821 "above=%d signal=%d noise=%d txrate=%d",
3822 data->signal_change.above_threshold,
3823 data->signal_change.current_signal,
3824 data->signal_change.current_noise,
3825 data->signal_change.current_txrate);
3826 wpa_bss_update_level(wpa_s->current_bss,
3827 data->signal_change.current_signal);
3828 bgscan_notify_signal_change(
3829 wpa_s, data->signal_change.above_threshold,
3830 data->signal_change.current_signal,
3831 data->signal_change.current_noise,
3832 data->signal_change.current_txrate);
3834 case EVENT_INTERFACE_ENABLED:
3835 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3836 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3837 wpa_supplicant_update_mac_addr(wpa_s);
3838 if (wpa_s->p2p_mgmt) {
3839 wpa_supplicant_set_state(wpa_s,
3845 if (!wpa_s->ap_iface) {
3846 wpa_supplicant_set_state(wpa_s,
3848 wpa_s->scan_req = NORMAL_SCAN_REQ;
3849 wpa_supplicant_req_scan(wpa_s, 0, 0);
3851 wpa_supplicant_set_state(wpa_s,
3853 #else /* CONFIG_AP */
3854 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3855 wpa_supplicant_req_scan(wpa_s, 0, 0);
3856 #endif /* CONFIG_AP */
3859 case EVENT_INTERFACE_DISABLED:
3860 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3862 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3863 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3864 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3866 * Mark interface disabled if this happens to end up not
3867 * being removed as a separate P2P group interface.
3869 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3871 * The interface was externally disabled. Remove
3872 * it assuming an external entity will start a
3873 * new session if needed.
3875 if (wpa_s->current_ssid &&
3876 wpa_s->current_ssid->p2p_group)
3877 wpas_p2p_interface_unavailable(wpa_s);
3879 wpas_p2p_disconnect(wpa_s);
3881 * wpa_s instance may have been freed, so must not use
3886 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3887 p2p_in_progress(wpa_s->global->p2p) > 1) {
3888 /* This radio work will be cancelled, so clear P2P
3891 p2p_stop_find(wpa_s->global->p2p);
3893 #endif /* CONFIG_P2P */
3895 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3897 * Indicate disconnection to keep ctrl_iface events
3900 wpa_supplicant_event_disassoc(
3901 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3903 wpa_supplicant_mark_disassoc(wpa_s);
3904 radio_remove_works(wpa_s, NULL, 0);
3906 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3908 case EVENT_CHANNEL_LIST_CHANGED:
3909 wpa_supplicant_update_channel_list(
3910 wpa_s, &data->channel_list_changed);
3912 case EVENT_INTERFACE_UNAVAILABLE:
3913 wpas_p2p_interface_unavailable(wpa_s);
3915 case EVENT_BEST_CHANNEL:
3916 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3918 data->best_chan.freq_24, data->best_chan.freq_5,
3919 data->best_chan.freq_overall);
3920 wpa_s->best_24_freq = data->best_chan.freq_24;
3921 wpa_s->best_5_freq = data->best_chan.freq_5;
3922 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3923 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3924 data->best_chan.freq_5,
3925 data->best_chan.freq_overall);
3927 case EVENT_UNPROT_DEAUTH:
3928 wpa_supplicant_event_unprot_deauth(wpa_s,
3929 &data->unprot_deauth);
3931 case EVENT_UNPROT_DISASSOC:
3932 wpa_supplicant_event_unprot_disassoc(wpa_s,
3933 &data->unprot_disassoc);
3935 case EVENT_STATION_LOW_ACK:
3937 if (wpa_s->ap_iface && data)
3938 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3939 data->low_ack.addr);
3940 #endif /* CONFIG_AP */
3943 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3944 data->low_ack.addr);
3945 #endif /* CONFIG_TDLS */
3947 case EVENT_IBSS_PEER_LOST:
3948 #ifdef CONFIG_IBSS_RSN
3949 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3950 #endif /* CONFIG_IBSS_RSN */
3952 case EVENT_DRIVER_GTK_REKEY:
3953 if (os_memcmp(data->driver_gtk_rekey.bssid,
3954 wpa_s->bssid, ETH_ALEN))
3958 wpa_sm_update_replay_ctr(wpa_s->wpa,
3959 data->driver_gtk_rekey.replay_ctr);
3961 case EVENT_SCHED_SCAN_STOPPED:
3962 wpa_s->sched_scanning = 0;
3963 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
3964 wpa_supplicant_notify_scanning(wpa_s, 0);
3966 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3970 * Start a new sched scan to continue searching for more SSIDs
3971 * either if timed out or PNO schedule scan is pending.
3973 if (wpa_s->sched_scan_timed_out) {
3974 wpa_supplicant_req_sched_scan(wpa_s);
3975 } else if (wpa_s->pno_sched_pending) {
3976 wpa_s->pno_sched_pending = 0;
3977 wpas_start_pno(wpa_s);
3978 } else if (resched) {
3979 wpa_supplicant_req_scan(wpa_s, 0, 0);
3983 case EVENT_WPS_BUTTON_PUSHED:
3985 wpas_wps_start_pbc(wpa_s, NULL, 0);
3986 #endif /* CONFIG_WPS */
3988 case EVENT_AVOID_FREQUENCIES:
3989 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3991 case EVENT_CONNECT_FAILED_REASON:
3993 if (!wpa_s->ap_iface || !data)
3995 hostapd_event_connect_failed_reason(
3996 wpa_s->ap_iface->bss[0],
3997 data->connect_failed_reason.addr,
3998 data->connect_failed_reason.code);
3999 #endif /* CONFIG_AP */
4001 case EVENT_NEW_PEER_CANDIDATE:
4003 if (!wpa_s->ifmsh || !data)
4005 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
4006 data->mesh_peer.ies,
4007 data->mesh_peer.ie_len);
4008 #endif /* CONFIG_MESH */
4012 if (!wpa_s->ap_iface)
4014 hostapd_event_get_survey(wpa_s->ap_iface,
4015 &data->survey_results);
4016 #endif /* CONFIG_AP */
4018 case EVENT_ACS_CHANNEL_SELECTED:
4020 if (!wpa_s->ap_iface)
4022 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4023 &data->acs_selected_channels);
4024 #endif /* CONFIG_ACS */
4027 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4033 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
4034 union wpa_event_data *data)
4036 struct wpa_supplicant *wpa_s;
4038 if (event != EVENT_INTERFACE_STATUS)
4041 wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
4042 if (wpa_s && wpa_s->driver->get_ifindex) {
4043 unsigned int ifindex;
4045 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
4046 if (ifindex != data->interface_status.ifindex) {
4047 wpa_dbg(wpa_s, MSG_DEBUG,
4048 "interface status ifindex %d mismatch (%d)",
4049 ifindex, data->interface_status.ifindex);
4053 #ifdef CONFIG_MATCH_IFACE
4054 else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
4055 struct wpa_interface *wpa_i;
4057 wpa_i = wpa_supplicant_match_iface(
4058 ctx, data->interface_status.ifname);
4061 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
4066 #endif /* CONFIG_MATCH_IFACE */
4069 wpa_supplicant_event(wpa_s, event, data);