2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 #ifndef CONFIG_NO_SCAN_PROCESSING
48 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
49 int new_scan, int own_request);
50 #endif /* CONFIG_NO_SCAN_PROCESSING */
53 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
56 struct os_reltime now;
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
71 static struct wpa_bss * wpa_supplicant_get_new_bss(
72 struct wpa_supplicant *wpa_s, const u8 *bssid)
74 struct wpa_bss *bss = NULL;
75 struct wpa_ssid *ssid = wpa_s->current_ssid;
77 if (ssid->ssid_len > 0)
78 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
80 bss = wpa_bss_get_bssid(wpa_s, bssid);
86 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
88 struct wpa_ssid *ssid, *old_ssid;
92 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
95 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
97 ssid = wpa_supplicant_get_ssid(wpa_s);
99 wpa_msg(wpa_s, MSG_INFO,
100 "No network configuration found for the current AP");
104 if (wpas_network_disabled(wpa_s, ssid)) {
105 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
109 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
110 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
111 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
115 res = wpas_temp_disabled(wpa_s, ssid);
117 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
118 "disabled for %d second(s)", res);
122 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
124 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
126 size_t wpa_ie_len = sizeof(wpa_ie);
127 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
128 wpa_ie, &wpa_ie_len) < 0)
129 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
131 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
134 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
135 eapol_sm_invalidate_cached_session(wpa_s->eapol);
136 old_ssid = wpa_s->current_ssid;
137 wpa_s->current_ssid = ssid;
139 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
141 wpa_supplicant_update_scan_results(wpa_s);
143 /* Get the BSS from the new scan results */
144 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148 wpa_s->current_bss = bss;
150 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
151 wpa_supplicant_initiate_eapol(wpa_s);
152 if (old_ssid != wpa_s->current_ssid)
153 wpas_notify_network_changed(wpa_s);
159 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
161 struct wpa_supplicant *wpa_s = eloop_ctx;
163 if (wpa_s->countermeasures) {
164 wpa_s->countermeasures = 0;
165 wpa_drv_set_countermeasures(wpa_s, 0);
166 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
167 wpa_supplicant_req_scan(wpa_s, 0, 0);
172 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
176 wnm_bss_keep_alive_deinit(wpa_s);
178 #ifdef CONFIG_IBSS_RSN
179 ibss_rsn_deinit(wpa_s->ibss_rsn);
180 wpa_s->ibss_rsn = NULL;
181 #endif /* CONFIG_IBSS_RSN */
184 wpa_supplicant_ap_deinit(wpa_s);
185 #endif /* CONFIG_AP */
187 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
190 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
191 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
192 os_memset(wpa_s->bssid, 0, ETH_ALEN);
193 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
195 wpa_s->sme.prev_bssid_set = 0;
196 #endif /* CONFIG_SME */
198 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
199 #endif /* CONFIG_P2P */
200 wpa_s->current_bss = NULL;
201 wpa_s->assoc_freq = 0;
202 #ifdef CONFIG_IEEE80211R
204 if (wpa_s->sme.ft_ies)
205 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
206 #endif /* CONFIG_SME */
207 #endif /* CONFIG_IEEE80211R */
210 wpas_notify_bssid_changed(wpa_s);
212 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
213 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
214 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
215 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
216 wpa_s->ap_ies_from_associnfo = 0;
217 wpa_s->current_ssid = NULL;
218 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
223 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
225 struct wpa_ie_data ie;
229 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
233 for (i = 0; i < ie.num_pmkid; i++) {
234 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
235 ie.pmkid + i * PMKID_LEN,
237 if (pmksa_set == 0) {
238 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
243 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
244 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
248 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
249 union wpa_event_data *data)
252 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
256 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
257 " index=%d preauth=%d",
258 MAC2STR(data->pmkid_candidate.bssid),
259 data->pmkid_candidate.index,
260 data->pmkid_candidate.preauth);
262 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
263 data->pmkid_candidate.index,
264 data->pmkid_candidate.preauth);
268 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
270 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
271 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
274 #ifdef IEEE8021X_EAPOL
275 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
276 wpa_s->current_ssid &&
277 !(wpa_s->current_ssid->eapol_flags &
278 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
279 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
280 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
281 * plaintext or static WEP keys). */
284 #endif /* IEEE8021X_EAPOL */
291 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
292 * @wpa_s: pointer to wpa_supplicant data
293 * @ssid: Configuration data for the network
294 * Returns: 0 on success, -1 on failure
296 * This function is called when starting authentication with a network that is
297 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
299 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
300 struct wpa_ssid *ssid)
302 #ifdef IEEE8021X_EAPOL
304 int aka = 0, sim = 0;
306 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
307 wpa_s->conf->external_sim)
310 if (ssid->eap.eap_methods == NULL) {
314 struct eap_method_type *eap = ssid->eap.eap_methods;
315 while (eap->vendor != EAP_VENDOR_IETF ||
316 eap->method != EAP_TYPE_NONE) {
317 if (eap->vendor == EAP_VENDOR_IETF) {
318 if (eap->method == EAP_TYPE_SIM)
320 else if (eap->method == EAP_TYPE_AKA ||
321 eap->method == EAP_TYPE_AKA_PRIME)
328 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
330 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
331 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
336 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
337 "use SIM, but neither EAP-SIM nor EAP-AKA are "
342 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
343 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
345 wpa_s->scard = scard_init(NULL);
346 if (wpa_s->scard == NULL) {
347 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
351 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
352 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
353 #endif /* PCSC_FUNCS */
354 #endif /* IEEE8021X_EAPOL */
360 #ifndef CONFIG_NO_SCAN_PROCESSING
362 static int has_wep_key(struct wpa_ssid *ssid)
366 for (i = 0; i < NUM_WEP_KEYS; i++) {
367 if (ssid->wep_key_len[i])
375 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
376 struct wpa_ssid *ssid)
380 if (ssid->mixed_cell)
384 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
386 #endif /* CONFIG_WPS */
388 if (has_wep_key(ssid))
391 #ifdef IEEE8021X_EAPOL
392 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
393 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
394 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
396 #endif /* IEEE8021X_EAPOL */
398 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
401 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
404 if (bss->caps & IEEE80211_CAP_PRIVACY)
410 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
411 struct wpa_ssid *ssid,
414 struct wpa_ie_data ie;
416 const u8 *rsn_ie, *wpa_ie;
420 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
424 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
425 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
426 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
427 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
428 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
430 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
431 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
434 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
435 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
441 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
443 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
448 if (!(ie.proto & ssid->proto)) {
449 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
454 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
455 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
460 if (!(ie.group_cipher & ssid->group_cipher)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
466 if (!(ie.key_mgmt & ssid->key_mgmt)) {
467 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
472 #ifdef CONFIG_IEEE80211W
473 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
474 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
475 wpa_s->conf->pmf : ssid->ieee80211w) ==
476 MGMT_FRAME_PROTECTION_REQUIRED) {
477 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
481 #endif /* CONFIG_IEEE80211W */
483 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
487 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
488 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
491 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
492 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
498 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
500 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
505 if (!(ie.proto & ssid->proto)) {
506 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
511 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
512 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
517 if (!(ie.group_cipher & ssid->group_cipher)) {
518 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
523 if (!(ie.key_mgmt & ssid->key_mgmt)) {
524 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
529 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
533 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
535 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
539 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
540 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
541 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
545 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
546 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
547 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
551 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
552 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
556 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
563 static int freq_allowed(int *freqs, int freq)
570 for (i = 0; freqs[i]; i++)
571 if (freqs[i] == freq)
577 static int ht_supported(const struct hostapd_hw_modes *mode)
579 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
581 * The driver did not indicate whether it supports HT. Assume
582 * it does to avoid connection issues.
588 * IEEE Std 802.11n-2009 20.1.1:
589 * An HT non-AP STA shall support all EQM rates for one spatial stream.
591 return mode->mcs_set[0] == 0xff;
595 static int vht_supported(const struct hostapd_hw_modes *mode)
597 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
599 * The driver did not indicate whether it supports VHT. Assume
600 * it does to avoid connection issues.
606 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
607 * TODO: Verify if this complies with the standard
609 return (mode->vht_mcs_set[0] & 0x3) != 3;
613 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
615 const struct hostapd_hw_modes *mode = NULL, *modes;
616 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
621 return 1; /* Cannot do matching without knowing band */
623 modes = wpa_s->hw.modes;
626 * The driver does not provide any additional information
627 * about the utilized hardware, so allow the connection attempt
633 for (i = 0; i < wpa_s->hw.num_modes; i++) {
634 for (j = 0; j < modes[i].num_channels; j++) {
635 int freq = modes[i].channels[j].freq;
636 if (freq == bss->freq) {
638 mode->mode == HOSTAPD_MODE_IEEE80211G)
639 break; /* do not allow 802.11b replace
650 for (i = 0; i < (int) sizeof(scan_ie); i++) {
651 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
655 for (j = 2; j < rate_ie[1] + 2; j++) {
656 int flagged = !!(rate_ie[j] & 0x80);
657 int r = (rate_ie[j] & 0x7f) * 5;
660 * IEEE Std 802.11n-2009 7.3.2.2:
661 * The new BSS Membership selector value is encoded
662 * like a legacy basic rate, but it is not a rate and
663 * only indicates if the BSS members are required to
664 * support the mandatory features of Clause 20 [HT PHY]
665 * in order to join the BSS.
667 if (flagged && ((rate_ie[j] & 0x7f) ==
668 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
669 if (!ht_supported(mode)) {
670 wpa_dbg(wpa_s, MSG_DEBUG,
671 " hardware does not support "
678 /* There's also a VHT selector for 802.11ac */
679 if (flagged && ((rate_ie[j] & 0x7f) ==
680 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
681 if (!vht_supported(mode)) {
682 wpa_dbg(wpa_s, MSG_DEBUG,
683 " hardware does not support "
693 /* check for legacy basic rates */
694 for (k = 0; k < mode->num_rates; k++) {
695 if (mode->rates[k] == r)
698 if (k == mode->num_rates) {
700 * IEEE Std 802.11-2007 7.3.2.2 demands that in
701 * order to join a BSS all required rates
702 * have to be supported by the hardware.
704 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
705 "not support required rate %d.%d Mbps",
716 static int bss_is_dmg(struct wpa_bss *bss)
718 return bss->freq > 45000;
723 * Test whether BSS is in an ESS.
724 * This is done differently in DMG (60 GHz) and non-DMG bands
726 static int bss_is_ess(struct wpa_bss *bss)
728 if (bss_is_dmg(bss)) {
729 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
730 IEEE80211_CAP_DMG_AP;
733 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
738 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
739 int i, struct wpa_bss *bss,
740 struct wpa_ssid *group,
743 u8 wpa_ie_len, rsn_ie_len;
745 struct wpa_blacklist *e;
747 struct wpa_ssid *ssid;
750 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
751 wpa_ie_len = ie ? ie[1] : 0;
753 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
754 rsn_ie_len = ie ? ie[1] : 0;
756 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
759 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
760 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
761 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
762 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
763 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
764 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
765 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
767 osen ? " osen=1" : "");
769 e = wpa_blacklist_get(wpa_s, bss->bssid);
772 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
774 * When only a single network is enabled, we can
775 * trigger blacklisting on the first failure. This
776 * should not be done with multiple enabled networks to
777 * avoid getting forced to move into a worse ESS on
778 * single error if there are no other BSSes of the
783 if (e->count > limit) {
784 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
785 "(count=%d limit=%d)", e->count, limit);
790 if (bss->ssid_len == 0) {
791 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
795 if (disallowed_bssid(wpa_s, bss->bssid)) {
796 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
800 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
805 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
807 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
808 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
811 if (wpas_network_disabled(wpa_s, ssid)) {
812 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
816 res = wpas_temp_disabled(wpa_s, ssid);
818 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
819 "temporarily for %d second(s)", res);
824 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
825 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
830 if (wpa && ssid->ssid_len == 0 &&
831 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
834 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
835 /* Only allow wildcard SSID match if an AP
836 * advertises active WPS operation that matches
839 if (ssid->ssid_len == 0 &&
840 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
843 #endif /* CONFIG_WPS */
845 if (ssid->bssid_set && ssid->ssid_len == 0 &&
846 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
850 (bss->ssid_len != ssid->ssid_len ||
851 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
852 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
856 if (ssid->bssid_set &&
857 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
858 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
862 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
866 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
867 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
868 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
869 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
874 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
876 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
880 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
881 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
886 if (!wpa_supplicant_match_privacy(bss, ssid)) {
887 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
892 if (!bss_is_ess(bss)) {
893 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
897 if (!freq_allowed(ssid->freq_list, bss->freq)) {
898 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
903 if (!rate_match(wpa_s, bss)) {
904 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
910 if (ssid->p2p_group &&
911 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
912 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
913 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
917 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
918 struct wpabuf *p2p_ie;
919 u8 dev_addr[ETH_ALEN];
921 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
923 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
926 p2p_ie = wpa_bss_get_vendor_ie_multi(
927 bss, P2P_IE_VENDOR_TYPE);
928 if (p2p_ie == NULL) {
929 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
933 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
934 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
936 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
944 * TODO: skip the AP if its P2P IE has Group Formation
945 * bit set in the P2P Group Capability Bitmap and we
946 * are not in Group Formation with that device.
948 #endif /* CONFIG_P2P */
950 /* Matching configuration found */
954 /* No matching configuration found */
959 static struct wpa_bss *
960 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
961 struct wpa_ssid *group,
962 struct wpa_ssid **selected_ssid,
968 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
971 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
974 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
975 struct wpa_bss *bss = wpa_s->last_scan_res[i];
976 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
980 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
983 wpa_ssid_txt(bss->ssid, bss->ssid_len));
991 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
992 struct wpa_ssid **selected_ssid)
994 struct wpa_bss *selected = NULL;
996 struct wpa_ssid *next_ssid = NULL;
998 if (wpa_s->last_scan_res == NULL ||
999 wpa_s->last_scan_res_used == 0)
1000 return NULL; /* no scan results from last update */
1002 if (wpa_s->next_ssid) {
1003 struct wpa_ssid *ssid;
1005 /* check that next_ssid is still valid */
1006 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1007 if (ssid == wpa_s->next_ssid)
1011 wpa_s->next_ssid = NULL;
1014 while (selected == NULL) {
1015 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1016 if (next_ssid && next_ssid->priority ==
1017 wpa_s->conf->pssid[prio]->priority) {
1018 selected = wpa_supplicant_select_bss(
1019 wpa_s, next_ssid, selected_ssid, 1);
1023 selected = wpa_supplicant_select_bss(
1024 wpa_s, wpa_s->conf->pssid[prio],
1030 if (selected == NULL && wpa_s->blacklist &&
1031 !wpa_s->countermeasures) {
1032 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1033 "blacklist and try again");
1034 wpa_blacklist_clear(wpa_s);
1035 wpa_s->blacklist_cleared++;
1036 } else if (selected == NULL)
1044 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1045 int timeout_sec, int timeout_usec)
1047 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1049 * No networks are enabled; short-circuit request so
1050 * we don't wait timeout seconds before transitioning
1051 * to INACTIVE state.
1053 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1054 "since there are no enabled networks");
1055 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1059 wpa_s->scan_for_connection = 1;
1060 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1064 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1065 struct wpa_bss *selected,
1066 struct wpa_ssid *ssid)
1068 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1069 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1070 "PBC session overlap");
1072 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
1074 #endif /* CONFIG_P2P */
1077 wpas_wps_cancel(wpa_s);
1078 #endif /* CONFIG_WPS */
1082 wpa_msg(wpa_s, MSG_DEBUG,
1083 "Considering connect request: reassociate: %d selected: "
1084 MACSTR " bssid: " MACSTR " pending: " MACSTR
1085 " wpa_state: %s ssid=%p current_ssid=%p",
1086 wpa_s->reassociate, MAC2STR(selected->bssid),
1087 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1088 wpa_supplicant_state_txt(wpa_s->wpa_state),
1089 ssid, wpa_s->current_ssid);
1092 * Do not trigger new association unless the BSSID has changed or if
1093 * reassociation is requested. If we are in process of associating with
1094 * the selected BSSID, do not trigger new attempt.
1096 if (wpa_s->reassociate ||
1097 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1098 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1099 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1100 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1101 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1103 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1104 ssid != wpa_s->current_ssid)))) {
1105 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1106 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1109 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1110 MAC2STR(selected->bssid));
1111 wpa_supplicant_associate(wpa_s, selected, ssid);
1113 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1114 "connect with the selected AP");
1121 static struct wpa_ssid *
1122 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1125 struct wpa_ssid *ssid;
1127 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1128 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1130 if (wpas_network_disabled(wpa_s, ssid))
1132 if (ssid->mode == IEEE80211_MODE_IBSS ||
1133 ssid->mode == IEEE80211_MODE_AP)
1141 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1142 * on BSS added and BSS changed events */
1143 static void wpa_supplicant_rsn_preauth_scan_results(
1144 struct wpa_supplicant *wpa_s)
1146 struct wpa_bss *bss;
1148 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1151 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1152 const u8 *ssid, *rsn;
1154 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1158 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1162 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1168 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1169 struct wpa_bss *selected,
1170 struct wpa_ssid *ssid)
1172 struct wpa_bss *current_bss = NULL;
1175 if (wpa_s->reassociate)
1176 return 1; /* explicit request to reassociate */
1177 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1178 return 1; /* we are not associated; continue */
1179 if (wpa_s->current_ssid == NULL)
1180 return 1; /* unknown current SSID */
1181 if (wpa_s->current_ssid != ssid)
1182 return 1; /* different network block */
1184 if (wpas_driver_bss_selection(wpa_s))
1185 return 0; /* Driver-based roaming */
1187 if (wpa_s->current_ssid->ssid)
1188 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1189 wpa_s->current_ssid->ssid,
1190 wpa_s->current_ssid->ssid_len);
1192 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1195 return 1; /* current BSS not seen in scan results */
1197 if (current_bss == selected)
1200 if (selected->last_update_idx > current_bss->last_update_idx)
1201 return 1; /* current BSS not seen in the last scan */
1203 #ifndef CONFIG_NO_ROAMING
1204 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1205 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1206 MAC2STR(current_bss->bssid), current_bss->level);
1207 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1208 MAC2STR(selected->bssid), selected->level);
1210 if (wpa_s->current_ssid->bssid_set &&
1211 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1213 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1214 "has preferred BSSID");
1218 if (current_bss->level < 0 && current_bss->level > selected->level) {
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1225 if (current_bss->level < 0) {
1226 if (current_bss->level < -85)
1228 else if (current_bss->level < -80)
1230 else if (current_bss->level < -75)
1232 else if (current_bss->level < -70)
1237 if (abs(current_bss->level - selected->level) < min_diff) {
1238 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1244 #else /* CONFIG_NO_ROAMING */
1246 #endif /* CONFIG_NO_ROAMING */
1250 /* Return != 0 if no scan results could be fetched or if scan results should not
1251 * be shared with other virtual interfaces. */
1252 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1253 union wpa_event_data *data,
1256 struct wpa_scan_results *scan_res = NULL;
1259 #ifndef CONFIG_NO_RANDOM_POOL
1261 #endif /* CONFIG_NO_RANDOM_POOL */
1264 if (wpa_s->ap_iface)
1266 #endif /* CONFIG_AP */
1268 wpa_supplicant_notify_scanning(wpa_s, 0);
1270 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1271 data ? &data->scan_info :
1273 if (scan_res == NULL) {
1274 if (wpa_s->conf->ap_scan == 2 || ap ||
1275 wpa_s->scan_res_handler == scan_only_handler)
1279 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1281 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1283 goto scan_work_done;
1286 #ifndef CONFIG_NO_RANDOM_POOL
1287 num = scan_res->num;
1290 for (i = 0; i < num; i++) {
1292 struct wpa_scan_res *res = scan_res->res[i];
1293 buf[0] = res->bssid[5];
1294 buf[1] = res->qual & 0xff;
1295 buf[2] = res->noise & 0xff;
1296 buf[3] = res->level & 0xff;
1297 buf[4] = res->tsf & 0xff;
1298 random_add_randomness(buf, sizeof(buf));
1300 #endif /* CONFIG_NO_RANDOM_POOL */
1302 if (own_request && wpa_s->scan_res_handler &&
1303 (wpa_s->own_scan_running || !wpa_s->external_scan_running)) {
1304 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1305 struct wpa_scan_results *scan_res);
1307 scan_res_handler = wpa_s->scan_res_handler;
1308 wpa_s->scan_res_handler = NULL;
1309 scan_res_handler(wpa_s, scan_res);
1311 goto scan_work_done;
1315 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1317 if (wpa_s->ap_iface->scan_cb)
1318 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1319 #endif /* CONFIG_AP */
1320 goto scan_work_done;
1323 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1324 wpa_s->own_scan_running, wpa_s->external_scan_running);
1325 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1326 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1327 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1328 wpa_s->manual_scan_id);
1329 wpa_s->manual_scan_use_id = 0;
1331 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1333 wpas_notify_scan_results(wpa_s);
1335 wpas_notify_scan_done(wpa_s, 1);
1337 if (!wpa_s->own_scan_running && wpa_s->external_scan_running) {
1338 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1339 wpa_scan_results_free(scan_res);
1343 if (sme_proc_obss_scan(wpa_s) > 0)
1344 goto scan_work_done;
1346 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1347 goto scan_work_done;
1349 if (autoscan_notify_scan(wpa_s, scan_res))
1350 goto scan_work_done;
1352 if (wpa_s->disconnected) {
1353 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1354 goto scan_work_done;
1357 if (!wpas_driver_bss_selection(wpa_s) &&
1358 bgscan_notify_scan(wpa_s, scan_res) == 1)
1359 goto scan_work_done;
1361 wpas_wps_update_ap_info(wpa_s, scan_res);
1363 wpa_scan_results_free(scan_res);
1365 if (wpa_s->scan_work) {
1366 struct wpa_radio_work *work = wpa_s->scan_work;
1367 wpa_s->scan_work = NULL;
1368 radio_work_done(work);
1371 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1374 wpa_scan_results_free(scan_res);
1375 if (wpa_s->scan_work) {
1376 struct wpa_radio_work *work = wpa_s->scan_work;
1377 wpa_s->scan_work = NULL;
1378 radio_work_done(work);
1384 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1385 int new_scan, int own_request)
1387 struct wpa_bss *selected;
1388 struct wpa_ssid *ssid = NULL;
1390 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1394 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1397 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1401 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1402 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1406 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1408 * Do not notify other virtual radios of scan results since we do not
1409 * want them to start other associations at the same time.
1413 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1414 ssid = wpa_supplicant_pick_new_network(wpa_s);
1416 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1417 wpa_supplicant_associate(wpa_s, NULL, ssid);
1419 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1420 } else if (own_request) {
1422 * No SSID found. If SCAN results are as a result of
1423 * own scan request and not due to a scan request on
1424 * another shared interface, try another scan.
1426 int timeout_sec = wpa_s->scan_interval;
1427 int timeout_usec = 0;
1429 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1432 if (wpa_s->p2p_in_provisioning ||
1433 wpa_s->show_group_started) {
1435 * Use shorter wait during P2P Provisioning
1436 * state and during P2P join-a-group operation
1437 * to speed up group formation.
1440 timeout_usec = 250000;
1441 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1445 #endif /* CONFIG_P2P */
1446 #ifdef CONFIG_INTERWORKING
1447 if (wpa_s->conf->auto_interworking &&
1448 wpa_s->conf->interworking &&
1449 wpa_s->conf->cred) {
1450 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1451 "start ANQP fetch since no matching "
1453 wpa_s->network_select = 1;
1454 wpa_s->auto_network_select = 1;
1455 interworking_start_fetch_anqp(wpa_s);
1458 #endif /* CONFIG_INTERWORKING */
1460 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1461 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1463 timeout_usec = 500000;
1464 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1468 #endif /* CONFIG_WPS */
1469 if (wpa_supplicant_req_sched_scan(wpa_s))
1470 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1478 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1479 union wpa_event_data *data)
1481 struct wpa_supplicant *ifs;
1483 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1485 * If no scan results could be fetched, then no need to
1486 * notify those interfaces that did not actually request
1487 * this scan. Similarly, if scan results started a new operation on this
1488 * interface, do not notify other interfaces to avoid concurrent
1489 * operations during a connection attempt.
1495 * Check other interfaces to see if they share the same radio. If
1496 * so, they get updated with this same scan info.
1498 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1501 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1502 "sibling", ifs->ifname);
1503 _wpa_supplicant_event_scan_results(ifs, data, 0);
1508 #endif /* CONFIG_NO_SCAN_PROCESSING */
1511 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1513 #ifdef CONFIG_NO_SCAN_PROCESSING
1515 #else /* CONFIG_NO_SCAN_PROCESSING */
1516 struct os_reltime now;
1518 if (wpa_s->last_scan_res_used <= 0)
1521 os_get_reltime(&now);
1522 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1523 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1527 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1528 #endif /* CONFIG_NO_SCAN_PROCESSING */
1533 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1535 struct wpa_supplicant *wpa_s = eloop_ctx;
1537 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1540 if (!wpa_s->no_keep_alive) {
1541 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1542 MAC2STR(wpa_s->bssid));
1543 /* TODO: could skip this if normal data traffic has been sent */
1544 /* TODO: Consider using some more appropriate data frame for
1547 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1552 if (wpa_s->sme.bss_max_idle_period) {
1554 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1557 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1558 wnm_bss_keep_alive, wpa_s, NULL);
1560 #endif /* CONFIG_SME */
1564 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1565 const u8 *ies, size_t ies_len)
1567 struct ieee802_11_elems elems;
1572 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1576 if (elems.bss_max_idle_period) {
1578 wpa_s->sme.bss_max_idle_period =
1579 WPA_GET_LE16(elems.bss_max_idle_period);
1580 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1581 "TU)%s", wpa_s->sme.bss_max_idle_period,
1582 (elems.bss_max_idle_period[2] & 0x01) ?
1583 " (protected keep-live required)" : "");
1584 if (wpa_s->sme.bss_max_idle_period == 0)
1585 wpa_s->sme.bss_max_idle_period = 1;
1586 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1587 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1588 /* msec times 1000 */
1589 msec = wpa_s->sme.bss_max_idle_period * 1024;
1592 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1593 wnm_bss_keep_alive, wpa_s,
1597 #endif /* CONFIG_SME */
1600 #endif /* CONFIG_WNM */
1603 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1606 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1607 #endif /* CONFIG_WNM */
1611 #ifdef CONFIG_INTERWORKING
1613 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1618 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1619 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1621 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1628 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1629 const u8 *ies, size_t ies_len)
1631 struct ieee802_11_elems elems;
1636 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1639 if (elems.qos_map_set) {
1640 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1641 elems.qos_map_set_len);
1645 #endif /* CONFIG_INTERWORKING */
1648 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1649 union wpa_event_data *data)
1651 int l, len, found = 0, wpa_found, rsn_found;
1653 #ifdef CONFIG_IEEE80211R
1655 #endif /* CONFIG_IEEE80211R */
1657 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1658 if (data->assoc_info.req_ies)
1659 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1660 data->assoc_info.req_ies_len);
1661 if (data->assoc_info.resp_ies) {
1662 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1663 data->assoc_info.resp_ies_len);
1665 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1666 data->assoc_info.resp_ies_len);
1667 #endif /* CONFIG_TDLS */
1669 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1670 data->assoc_info.resp_ies_len);
1671 #endif /* CONFIG_WNM */
1672 #ifdef CONFIG_INTERWORKING
1673 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1674 data->assoc_info.resp_ies_len);
1675 #endif /* CONFIG_INTERWORKING */
1677 if (data->assoc_info.beacon_ies)
1678 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1679 data->assoc_info.beacon_ies,
1680 data->assoc_info.beacon_ies_len);
1681 if (data->assoc_info.freq)
1682 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1683 data->assoc_info.freq);
1685 p = data->assoc_info.req_ies;
1686 l = data->assoc_info.req_ies_len;
1688 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1689 while (p && l >= 2) {
1692 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1696 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1697 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1698 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1699 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1702 wpa_find_assoc_pmkid(wpa_s);
1708 if (!found && data->assoc_info.req_ies)
1709 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1711 #ifdef CONFIG_IEEE80211R
1713 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1714 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1715 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1716 data->assoc_info.resp_ies,
1717 data->assoc_info.resp_ies_len,
1719 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1720 "Reassociation Response failed");
1721 wpa_supplicant_deauthenticate(
1722 wpa_s, WLAN_REASON_INVALID_IE);
1727 p = data->assoc_info.resp_ies;
1728 l = data->assoc_info.resp_ies_len;
1730 #ifdef CONFIG_WPS_STRICT
1731 if (p && wpa_s->current_ssid &&
1732 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1734 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1736 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1737 "include WPS IE in (Re)Association Response");
1741 if (wps_validate_assoc_resp(wps) < 0) {
1743 wpa_supplicant_deauthenticate(
1744 wpa_s, WLAN_REASON_INVALID_IE);
1749 #endif /* CONFIG_WPS_STRICT */
1751 /* Go through the IEs and make a copy of the MDIE, if present. */
1752 while (p && l >= 2) {
1755 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1759 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1760 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1761 wpa_s->sme.ft_used = 1;
1762 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1763 MOBILITY_DOMAIN_ID_LEN);
1769 #endif /* CONFIG_SME */
1771 /* Process FT when SME is in the driver */
1772 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1773 wpa_ft_is_completed(wpa_s->wpa)) {
1774 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1775 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1776 data->assoc_info.resp_ies,
1777 data->assoc_info.resp_ies_len,
1779 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1780 "Reassociation Response failed");
1781 wpa_supplicant_deauthenticate(
1782 wpa_s, WLAN_REASON_INVALID_IE);
1785 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1788 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1789 data->assoc_info.resp_ies_len);
1790 #endif /* CONFIG_IEEE80211R */
1792 /* WPA/RSN IE from Beacon/ProbeResp */
1793 p = data->assoc_info.beacon_ies;
1794 l = data->assoc_info.beacon_ies_len;
1796 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1798 wpa_found = rsn_found = 0;
1799 while (p && l >= 2) {
1802 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1807 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1808 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1810 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1814 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1816 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1823 if (!wpa_found && data->assoc_info.beacon_ies)
1824 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1825 if (!rsn_found && data->assoc_info.beacon_ies)
1826 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1827 if (wpa_found || rsn_found)
1828 wpa_s->ap_ies_from_associnfo = 1;
1830 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1831 wpa_s->assoc_freq != data->assoc_info.freq) {
1832 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1834 wpa_s->assoc_freq, data->assoc_info.freq);
1835 wpa_supplicant_update_scan_results(wpa_s);
1838 wpa_s->assoc_freq = data->assoc_info.freq;
1844 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1846 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1848 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1851 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1854 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1855 WPA_IE_VENDOR_TYPE);
1856 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1858 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1859 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1860 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1861 bss_rsn ? 2 + bss_rsn[1] : 0))
1868 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1869 union wpa_event_data *data)
1875 if (wpa_s->ap_iface) {
1876 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1877 data->assoc_info.addr,
1878 data->assoc_info.req_ies,
1879 data->assoc_info.req_ies_len,
1880 data->assoc_info.reassoc);
1883 #endif /* CONFIG_AP */
1885 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1886 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1889 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1890 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1891 wpa_supplicant_deauthenticate(
1892 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1896 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1897 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1898 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1899 MACSTR, MAC2STR(bssid));
1900 random_add_randomness(bssid, ETH_ALEN);
1901 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1902 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1903 wpas_notify_bssid_changed(wpa_s);
1905 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1906 wpa_clear_keys(wpa_s, bssid);
1908 if (wpa_supplicant_select_config(wpa_s) < 0) {
1909 wpa_supplicant_deauthenticate(
1910 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1914 if (wpa_s->conf->ap_scan == 1 &&
1915 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1916 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1917 wpa_msg(wpa_s, MSG_WARNING,
1918 "WPA/RSN IEs not updated");
1923 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1924 wpa_s->sme.prev_bssid_set = 1;
1925 #endif /* CONFIG_SME */
1927 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1928 if (wpa_s->current_ssid) {
1929 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1930 * initialized before association, but for other modes,
1931 * initialize PC/SC here, if the current configuration needs
1932 * smartcard or SIM/USIM. */
1933 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1935 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1937 l2_packet_notify_auth_start(wpa_s->l2);
1940 * Set portEnabled first to FALSE in order to get EAP state machine out
1941 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1942 * state machine may transit to AUTHENTICATING state based on obsolete
1943 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1944 * AUTHENTICATED without ever giving chance to EAP state machine to
1947 if (!ft_completed) {
1948 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1949 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1951 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1952 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1953 /* 802.1X::portControl = Auto */
1954 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1955 wpa_s->eapol_received = 0;
1956 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1957 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1958 (wpa_s->current_ssid &&
1959 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1960 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1962 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1964 * Set the key after having received joined-IBSS event
1967 wpa_supplicant_set_wpa_none_key(wpa_s,
1968 wpa_s->current_ssid);
1970 wpa_supplicant_cancel_auth_timeout(wpa_s);
1971 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1972 } else if (!ft_completed) {
1973 /* Timeout for receiving the first EAPOL packet */
1974 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1976 wpa_supplicant_cancel_scan(wpa_s);
1978 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1979 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1981 * We are done; the driver will take care of RSN 4-way
1984 wpa_supplicant_cancel_auth_timeout(wpa_s);
1985 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1986 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1987 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1988 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1989 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1991 * The driver will take care of RSN 4-way handshake, so we need
1992 * to allow EAPOL supplicant to complete its work without
1993 * waiting for WPA supplicant.
1995 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1996 } else if (ft_completed) {
1998 * FT protocol completed - make sure EAPOL state machine ends
1999 * up in authenticated.
2001 wpa_supplicant_cancel_auth_timeout(wpa_s);
2002 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2003 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2004 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2007 wpa_s->last_eapol_matches_bssid = 0;
2009 if (wpa_s->pending_eapol_rx) {
2010 struct os_reltime now, age;
2011 os_get_reltime(&now);
2012 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2013 if (age.sec == 0 && age.usec < 100000 &&
2014 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2016 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2017 "frame that was received just before "
2018 "association notification");
2019 wpa_supplicant_rx_eapol(
2020 wpa_s, wpa_s->pending_eapol_rx_src,
2021 wpabuf_head(wpa_s->pending_eapol_rx),
2022 wpabuf_len(wpa_s->pending_eapol_rx));
2024 wpabuf_free(wpa_s->pending_eapol_rx);
2025 wpa_s->pending_eapol_rx = NULL;
2028 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2029 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2030 wpa_s->current_ssid &&
2031 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2032 /* Set static WEP keys again */
2033 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2036 #ifdef CONFIG_IBSS_RSN
2037 if (wpa_s->current_ssid &&
2038 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2039 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2040 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2041 wpa_s->ibss_rsn == NULL) {
2042 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2043 if (!wpa_s->ibss_rsn) {
2044 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2045 wpa_supplicant_deauthenticate(
2046 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2050 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2052 #endif /* CONFIG_IBSS_RSN */
2054 wpas_wps_notify_assoc(wpa_s, bssid);
2058 static int disconnect_reason_recoverable(u16 reason_code)
2060 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2061 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2062 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2066 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2068 int locally_generated)
2072 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2074 * At least Host AP driver and a Prism3 card seemed to be
2075 * generating streams of disconnected events when configuring
2076 * IBSS for WPA-None. Ignore them for now.
2081 bssid = wpa_s->bssid;
2082 if (is_zero_ether_addr(bssid))
2083 bssid = wpa_s->pending_bssid;
2085 if (!is_zero_ether_addr(bssid) ||
2086 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2087 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2089 MAC2STR(bssid), reason_code,
2090 locally_generated ? " locally_generated=1" : "");
2095 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2096 int locally_generated)
2098 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2099 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2100 return 0; /* Not in 4-way handshake with PSK */
2103 * It looks like connection was lost while trying to go through PSK
2104 * 4-way handshake. Filter out known disconnection cases that are caused
2105 * by something else than PSK mismatch to avoid confusing reports.
2108 if (locally_generated) {
2109 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2117 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2119 int locally_generated)
2123 u8 prev_pending_bssid[ETH_ALEN];
2124 struct wpa_bss *fast_reconnect = NULL;
2125 #ifndef CONFIG_NO_SCAN_PROCESSING
2126 struct wpa_ssid *fast_reconnect_ssid = NULL;
2127 #endif /* CONFIG_NO_SCAN_PROCESSING */
2128 struct wpa_ssid *last_ssid;
2130 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2131 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2133 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2135 * At least Host AP driver and a Prism3 card seemed to be
2136 * generating streams of disconnected events when configuring
2137 * IBSS for WPA-None. Ignore them for now.
2139 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2140 "IBSS/WPA-None mode");
2144 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2145 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2146 "pre-shared key may be incorrect");
2147 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2148 return; /* P2P group removed */
2149 wpas_auth_failed(wpa_s);
2151 if (!wpa_s->disconnected &&
2152 (!wpa_s->auto_reconnect_disabled ||
2153 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
2154 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2155 "reconnect (wps=%d wpa_state=%d)",
2156 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2158 if (wpa_s->wpa_state == WPA_COMPLETED &&
2159 wpa_s->current_ssid &&
2160 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2161 !locally_generated &&
2162 disconnect_reason_recoverable(reason_code)) {
2164 * It looks like the AP has dropped association with
2165 * us, but could allow us to get back in. Try to
2166 * reconnect to the same BSS without full scan to save
2167 * time for some common cases.
2169 fast_reconnect = wpa_s->current_bss;
2170 #ifndef CONFIG_NO_SCAN_PROCESSING
2171 fast_reconnect_ssid = wpa_s->current_ssid;
2172 #endif /* CONFIG_NO_SCAN_PROCESSING */
2173 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2174 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2176 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2179 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2180 "try to re-connect");
2181 wpa_s->reassociate = 0;
2182 wpa_s->disconnected = 1;
2183 wpa_supplicant_cancel_sched_scan(wpa_s);
2185 bssid = wpa_s->bssid;
2186 if (is_zero_ether_addr(bssid))
2187 bssid = wpa_s->pending_bssid;
2188 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2189 wpas_connection_failed(wpa_s, bssid);
2190 wpa_sm_notify_disassoc(wpa_s->wpa);
2191 if (locally_generated)
2192 wpa_s->disconnect_reason = -reason_code;
2194 wpa_s->disconnect_reason = reason_code;
2195 wpas_notify_disconnect_reason(wpa_s);
2196 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2197 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2198 wpa_clear_keys(wpa_s, wpa_s->bssid);
2200 last_ssid = wpa_s->current_ssid;
2201 wpa_supplicant_mark_disassoc(wpa_s);
2203 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2204 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2205 wpa_s->current_ssid = last_ssid;
2208 if (fast_reconnect &&
2209 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2210 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2211 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2212 fast_reconnect->ssid_len) &&
2213 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2214 #ifndef CONFIG_NO_SCAN_PROCESSING
2215 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2216 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2217 fast_reconnect_ssid) < 0) {
2218 /* Recover through full scan */
2219 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2221 #endif /* CONFIG_NO_SCAN_PROCESSING */
2222 } else if (fast_reconnect) {
2224 * Could not reconnect to the same BSS due to network being
2225 * disabled. Use a new scan to match the alternative behavior
2226 * above, i.e., to continue automatic reconnection attempt in a
2227 * way that enforces disabled network rules.
2229 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2234 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2235 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2237 struct wpa_supplicant *wpa_s = eloop_ctx;
2239 if (!wpa_s->pending_mic_error_report)
2242 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2243 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2244 wpa_s->pending_mic_error_report = 0;
2246 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2250 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2251 union wpa_event_data *data)
2254 struct os_reltime t;
2256 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2257 pairwise = (data && data->michael_mic_failure.unicast);
2259 if ((wpa_s->last_michael_mic_error.sec &&
2260 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2261 wpa_s->pending_mic_error_report) {
2262 if (wpa_s->pending_mic_error_report) {
2264 * Send the pending MIC error report immediately since
2265 * we are going to start countermeasures and AP better
2268 wpa_sm_key_request(wpa_s->wpa, 1,
2269 wpa_s->pending_mic_error_pairwise);
2272 /* Send the new MIC error report immediately since we are going
2273 * to start countermeasures and AP better do the same.
2275 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2277 /* initialize countermeasures */
2278 wpa_s->countermeasures = 1;
2280 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2282 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2285 * Need to wait for completion of request frame. We do not get
2286 * any callback for the message completion, so just wait a
2287 * short while and hope for the best. */
2290 wpa_drv_set_countermeasures(wpa_s, 1);
2291 wpa_supplicant_deauthenticate(wpa_s,
2292 WLAN_REASON_MICHAEL_MIC_FAILURE);
2293 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2295 eloop_register_timeout(60, 0,
2296 wpa_supplicant_stop_countermeasures,
2298 /* TODO: mark the AP rejected for 60 second. STA is
2299 * allowed to associate with another AP.. */
2301 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2302 if (wpa_s->mic_errors_seen) {
2304 * Reduce the effectiveness of Michael MIC error
2305 * reports as a means for attacking against TKIP if
2306 * more than one MIC failure is noticed with the same
2307 * PTK. We delay the transmission of the reports by a
2308 * random time between 0 and 60 seconds in order to
2309 * force the attacker wait 60 seconds before getting
2310 * the information on whether a frame resulted in a MIC
2316 if (os_get_random(rval, sizeof(rval)) < 0)
2317 sec = os_random() % 60;
2319 sec = WPA_GET_BE32(rval) % 60;
2320 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2321 "report %d seconds", sec);
2322 wpa_s->pending_mic_error_report = 1;
2323 wpa_s->pending_mic_error_pairwise = pairwise;
2324 eloop_cancel_timeout(
2325 wpa_supplicant_delayed_mic_error_report,
2327 eloop_register_timeout(
2328 sec, os_random() % 1000000,
2329 wpa_supplicant_delayed_mic_error_report,
2332 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2334 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2335 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2336 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2338 wpa_s->last_michael_mic_error = t;
2339 wpa_s->mic_errors_seen++;
2343 #ifdef CONFIG_TERMINATE_ONLASTIF
2344 static int any_interfaces(struct wpa_supplicant *head)
2346 struct wpa_supplicant *wpa_s;
2348 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2349 if (!wpa_s->interface_removed)
2353 #endif /* CONFIG_TERMINATE_ONLASTIF */
2357 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2358 union wpa_event_data *data)
2360 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2363 switch (data->interface_status.ievent) {
2364 case EVENT_INTERFACE_ADDED:
2365 if (!wpa_s->interface_removed)
2367 wpa_s->interface_removed = 0;
2368 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2369 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2370 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2371 "driver after interface was added");
2374 case EVENT_INTERFACE_REMOVED:
2375 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2376 wpa_s->interface_removed = 1;
2377 wpa_supplicant_mark_disassoc(wpa_s);
2378 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2379 l2_packet_deinit(wpa_s->l2);
2381 #ifdef CONFIG_IBSS_RSN
2382 ibss_rsn_deinit(wpa_s->ibss_rsn);
2383 wpa_s->ibss_rsn = NULL;
2384 #endif /* CONFIG_IBSS_RSN */
2385 #ifdef CONFIG_TERMINATE_ONLASTIF
2386 /* check if last interface */
2387 if (!any_interfaces(wpa_s->global->ifaces))
2389 #endif /* CONFIG_TERMINATE_ONLASTIF */
2395 #ifdef CONFIG_PEERKEY
2397 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2398 union wpa_event_data *data)
2402 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2404 #endif /* CONFIG_PEERKEY */
2408 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2409 union wpa_event_data *data)
2413 switch (data->tdls.oper) {
2414 case TDLS_REQUEST_SETUP:
2415 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2416 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2417 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2419 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2421 case TDLS_REQUEST_TEARDOWN:
2422 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2423 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2424 data->tdls.reason_code);
2426 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2431 #endif /* CONFIG_TDLS */
2435 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2436 union wpa_event_data *data)
2440 switch (data->wnm.oper) {
2441 case WNM_OPER_SLEEP:
2442 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2443 "(action=%d, intval=%d)",
2444 data->wnm.sleep_action, data->wnm.sleep_intval);
2445 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2446 data->wnm.sleep_intval, NULL);
2450 #endif /* CONFIG_WNM */
2453 #ifdef CONFIG_IEEE80211R
2455 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2456 union wpa_event_data *data)
2461 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2462 data->ft_ies.ies_len,
2463 data->ft_ies.ft_action,
2464 data->ft_ies.target_ap,
2465 data->ft_ies.ric_ies,
2466 data->ft_ies.ric_ies_len) < 0) {
2467 /* TODO: prevent MLME/driver from trying to associate? */
2470 #endif /* CONFIG_IEEE80211R */
2473 #ifdef CONFIG_IBSS_RSN
2474 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2475 union wpa_event_data *data)
2477 struct wpa_ssid *ssid;
2478 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2482 ssid = wpa_s->current_ssid;
2485 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2488 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2492 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2493 union wpa_event_data *data)
2495 struct wpa_ssid *ssid = wpa_s->current_ssid;
2500 /* check if the ssid is correctly configured as IBSS/RSN */
2501 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2504 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2505 data->rx_mgmt.frame_len);
2507 #endif /* CONFIG_IBSS_RSN */
2510 #ifdef CONFIG_IEEE80211R
2511 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2514 const u8 *sta_addr, *target_ap_addr;
2517 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2518 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2519 return; /* only SME case supported for now */
2520 if (len < 1 + 2 * ETH_ALEN + 2)
2523 return; /* Only FT Action Response is supported for now */
2524 sta_addr = data + 1;
2525 target_ap_addr = data + 1 + ETH_ALEN;
2526 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2527 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2528 MACSTR " TargetAP " MACSTR " status %u",
2529 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2531 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2532 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2533 " in FT Action Response", MAC2STR(sta_addr));
2538 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2539 "failure (status code %d)", status);
2540 /* TODO: report error to FT code(?) */
2544 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2545 len - (1 + 2 * ETH_ALEN + 2), 1,
2546 target_ap_addr, NULL, 0) < 0)
2551 struct wpa_bss *bss;
2552 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2554 wpa_s->sme.freq = bss->freq;
2555 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2556 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2559 #endif /* CONFIG_SME */
2561 #endif /* CONFIG_IEEE80211R */
2564 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2565 struct unprot_deauth *e)
2567 #ifdef CONFIG_IEEE80211W
2568 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2569 "dropped: " MACSTR " -> " MACSTR
2570 " (reason code %u)",
2571 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2572 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2573 #endif /* CONFIG_IEEE80211W */
2577 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2578 struct unprot_disassoc *e)
2580 #ifdef CONFIG_IEEE80211W
2581 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2582 "dropped: " MACSTR " -> " MACSTR
2583 " (reason code %u)",
2584 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2585 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2586 #endif /* CONFIG_IEEE80211W */
2590 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2591 u16 reason_code, int locally_generated,
2592 const u8 *ie, size_t ie_len, int deauth)
2595 if (wpa_s->ap_iface && addr) {
2596 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2600 if (wpa_s->ap_iface) {
2601 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2604 #endif /* CONFIG_AP */
2606 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2608 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2609 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2610 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2611 eapol_sm_failed(wpa_s->eapol))) &&
2612 !wpa_s->eap_expected_failure))
2613 wpas_auth_failed(wpa_s);
2616 if (deauth && reason_code > 0) {
2617 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2618 locally_generated) > 0) {
2620 * The interface was removed, so cannot continue
2621 * processing any additional operations after this.
2626 #endif /* CONFIG_P2P */
2628 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2633 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2634 struct disassoc_info *info)
2636 u16 reason_code = 0;
2637 int locally_generated = 0;
2638 const u8 *addr = NULL;
2639 const u8 *ie = NULL;
2642 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2647 ie_len = info->ie_len;
2648 reason_code = info->reason_code;
2649 locally_generated = info->locally_generated;
2650 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2651 locally_generated ? " (locally generated)" : "");
2653 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2655 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2660 if (wpa_s->ap_iface && info && info->addr) {
2661 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2665 if (wpa_s->ap_iface) {
2666 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2669 #endif /* CONFIG_AP */
2673 wpas_p2p_disassoc_notif(
2674 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2677 #endif /* CONFIG_P2P */
2679 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2680 sme_event_disassoc(wpa_s, info);
2682 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2687 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2688 struct deauth_info *info)
2690 u16 reason_code = 0;
2691 int locally_generated = 0;
2692 const u8 *addr = NULL;
2693 const u8 *ie = NULL;
2696 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2701 ie_len = info->ie_len;
2702 reason_code = info->reason_code;
2703 locally_generated = info->locally_generated;
2704 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2706 locally_generated ? " (locally generated)" : "");
2708 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2711 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2715 wpa_reset_ft_completed(wpa_s->wpa);
2717 wpas_event_disconnect(wpa_s, addr, reason_code,
2718 locally_generated, ie, ie_len, 1);
2722 static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2724 struct wpa_supplicant *ifs;
2726 if (wpa_s->drv_priv == NULL)
2727 return; /* Ignore event during drv initialization */
2729 free_hw_features(wpa_s);
2730 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2731 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2734 wpas_p2p_update_channel_list(wpa_s);
2735 #endif /* CONFIG_P2P */
2738 * Check other interfaces to see if they share the same radio. If
2739 * so, they get updated with this same hw mode info.
2741 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2744 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2746 free_hw_features(ifs);
2747 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2748 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2754 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2755 const struct ieee80211_mgmt *mgmt,
2756 size_t len, int freq)
2762 if (len < IEEE80211_HDRLEN + 2)
2765 payload = &mgmt->u.action.category;
2766 category = *payload++;
2767 plen = (((const u8 *) mgmt) + len) - payload;
2769 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2770 " Category=%u DataLen=%d freq=%d MHz",
2771 MAC2STR(mgmt->sa), category, (int) plen, freq);
2773 #ifdef CONFIG_IEEE80211R
2774 if (category == WLAN_ACTION_FT) {
2775 ft_rx_action(wpa_s, payload, plen);
2778 #endif /* CONFIG_IEEE80211R */
2780 #ifdef CONFIG_IEEE80211W
2782 if (category == WLAN_ACTION_SA_QUERY) {
2783 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2786 #endif /* CONFIG_SME */
2787 #endif /* CONFIG_IEEE80211W */
2790 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2791 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2794 #endif /* CONFIG_WNM */
2797 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2798 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2799 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2800 mgmt->u.action.category,
2801 payload, plen, freq) == 0)
2803 #endif /* CONFIG_GAS */
2806 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2807 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2808 wpa_dbg(wpa_s, MSG_DEBUG,
2809 "TDLS: Received Discovery Response from " MACSTR,
2813 #endif /* CONFIG_TDLS */
2815 #ifdef CONFIG_INTERWORKING
2816 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2817 payload[0] == QOS_QOS_MAP_CONFIG) {
2818 const u8 *pos = payload + 1;
2819 size_t qlen = plen - 1;
2820 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2821 MACSTR, MAC2STR(mgmt->sa));
2822 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2823 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2824 pos[1] <= qlen - 2 && pos[1] >= 16)
2825 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2828 #endif /* CONFIG_INTERWORKING */
2831 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2832 category, payload, plen, freq);
2833 #endif /* CONFIG_P2P */
2837 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2838 union wpa_event_data *event)
2841 struct wpa_supplicant *ifs;
2842 #endif /* CONFIG_P2P */
2843 struct wpa_freq_range_list *list;
2846 list = &event->freq_range;
2849 str = freq_range_list_str(list);
2850 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2854 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2855 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2858 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2859 wpas_p2p_update_channel_list(wpa_s);
2862 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2864 if (!ifs->current_ssid ||
2865 !ifs->current_ssid->p2p_group ||
2866 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2867 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2870 freq = ifs->current_ssid->frequency;
2871 if (!freq_range_list_includes(list, freq)) {
2872 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2877 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2879 /* TODO: Consider using CSA or removing the group within
2881 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2883 #endif /* CONFIG_P2P */
2889 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2890 union wpa_event_data *data)
2892 struct wpa_supplicant *wpa_s = ctx;
2894 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2895 event != EVENT_INTERFACE_ENABLED &&
2896 event != EVENT_INTERFACE_STATUS &&
2897 event != EVENT_SCHED_SCAN_STOPPED) {
2898 wpa_dbg(wpa_s, MSG_DEBUG,
2899 "Ignore event %s (%d) while interface is disabled",
2900 event_to_string(event), event);
2904 #ifndef CONFIG_NO_STDOUT_DEBUG
2906 int level = MSG_DEBUG;
2908 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2909 const struct ieee80211_hdr *hdr;
2911 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2912 fc = le_to_host16(hdr->frame_control);
2913 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2914 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2915 level = MSG_EXCESSIVE;
2918 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2919 event_to_string(event), event);
2921 #endif /* CONFIG_NO_STDOUT_DEBUG */
2925 sme_event_auth(wpa_s, data);
2928 wpa_supplicant_event_assoc(wpa_s, data);
2930 case EVENT_DISASSOC:
2931 wpas_event_disassoc(wpa_s,
2932 data ? &data->disassoc_info : NULL);
2935 wpas_event_deauth(wpa_s,
2936 data ? &data->deauth_info : NULL);
2938 case EVENT_MICHAEL_MIC_FAILURE:
2939 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2941 #ifndef CONFIG_NO_SCAN_PROCESSING
2942 case EVENT_SCAN_STARTED:
2943 os_get_reltime(&wpa_s->scan_start_time);
2944 if (wpa_s->own_scan_requested) {
2945 struct os_reltime diff;
2947 os_reltime_sub(&wpa_s->scan_start_time,
2948 &wpa_s->scan_trigger_time, &diff);
2949 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
2950 diff.sec, diff.usec);
2951 wpa_s->own_scan_requested = 0;
2952 wpa_s->own_scan_running = 1;
2953 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2954 wpa_s->manual_scan_use_id) {
2955 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED "id=%u",
2956 wpa_s->manual_scan_id);
2958 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2961 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
2962 wpa_s->external_scan_running = 1;
2963 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2966 case EVENT_SCAN_RESULTS:
2967 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
2968 struct os_reltime now, diff;
2969 os_get_reltime(&now);
2970 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
2971 wpa_s->scan_start_time.sec = 0;
2972 wpa_s->scan_start_time.usec = 0;
2973 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
2974 diff.sec, diff.usec);
2976 wpa_supplicant_event_scan_results(wpa_s, data);
2977 wpa_s->own_scan_running = 0;
2978 wpa_s->external_scan_running = 0;
2979 radio_work_check_next(wpa_s);
2981 #endif /* CONFIG_NO_SCAN_PROCESSING */
2982 case EVENT_ASSOCINFO:
2983 wpa_supplicant_event_associnfo(wpa_s, data);
2985 case EVENT_INTERFACE_STATUS:
2986 wpa_supplicant_event_interface_status(wpa_s, data);
2988 case EVENT_PMKID_CANDIDATE:
2989 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2991 #ifdef CONFIG_PEERKEY
2992 case EVENT_STKSTART:
2993 wpa_supplicant_event_stkstart(wpa_s, data);
2995 #endif /* CONFIG_PEERKEY */
2998 wpa_supplicant_event_tdls(wpa_s, data);
3000 #endif /* CONFIG_TDLS */
3003 wpa_supplicant_event_wnm(wpa_s, data);
3005 #endif /* CONFIG_WNM */
3006 #ifdef CONFIG_IEEE80211R
3007 case EVENT_FT_RESPONSE:
3008 wpa_supplicant_event_ft_response(wpa_s, data);
3010 #endif /* CONFIG_IEEE80211R */
3011 #ifdef CONFIG_IBSS_RSN
3012 case EVENT_IBSS_RSN_START:
3013 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3015 #endif /* CONFIG_IBSS_RSN */
3016 case EVENT_ASSOC_REJECT:
3017 if (data->assoc_reject.bssid)
3018 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3019 "bssid=" MACSTR " status_code=%u",
3020 MAC2STR(data->assoc_reject.bssid),
3021 data->assoc_reject.status_code);
3023 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3025 data->assoc_reject.status_code);
3026 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3027 sme_event_assoc_reject(wpa_s, data);
3029 const u8 *bssid = data->assoc_reject.bssid;
3030 if (bssid == NULL || is_zero_ether_addr(bssid))
3031 bssid = wpa_s->pending_bssid;
3032 wpas_connection_failed(wpa_s, bssid);
3033 wpa_supplicant_mark_disassoc(wpa_s);
3036 case EVENT_AUTH_TIMED_OUT:
3037 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3038 sme_event_auth_timed_out(wpa_s, data);
3040 case EVENT_ASSOC_TIMED_OUT:
3041 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3042 sme_event_assoc_timed_out(wpa_s, data);
3044 case EVENT_TX_STATUS:
3045 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3046 " type=%d stype=%d",
3047 MAC2STR(data->tx_status.dst),
3048 data->tx_status.type, data->tx_status.stype);
3050 if (wpa_s->ap_iface == NULL) {
3051 #ifdef CONFIG_OFFCHANNEL
3052 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3053 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3054 offchannel_send_action_tx_status(
3055 wpa_s, data->tx_status.dst,
3056 data->tx_status.data,
3057 data->tx_status.data_len,
3058 data->tx_status.ack ?
3059 OFFCHANNEL_SEND_ACTION_SUCCESS :
3060 OFFCHANNEL_SEND_ACTION_NO_ACK);
3061 #endif /* CONFIG_OFFCHANNEL */
3064 #endif /* CONFIG_AP */
3065 #ifdef CONFIG_OFFCHANNEL
3066 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3067 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3069 * Catch TX status events for Action frames we sent via group
3070 * interface in GO mode.
3072 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3073 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3074 os_memcmp(wpa_s->parent->pending_action_dst,
3075 data->tx_status.dst, ETH_ALEN) == 0) {
3076 offchannel_send_action_tx_status(
3077 wpa_s->parent, data->tx_status.dst,
3078 data->tx_status.data,
3079 data->tx_status.data_len,
3080 data->tx_status.ack ?
3081 OFFCHANNEL_SEND_ACTION_SUCCESS :
3082 OFFCHANNEL_SEND_ACTION_NO_ACK);
3085 #endif /* CONFIG_OFFCHANNEL */
3087 switch (data->tx_status.type) {
3088 case WLAN_FC_TYPE_MGMT:
3089 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3090 data->tx_status.data_len,
3091 data->tx_status.stype,
3092 data->tx_status.ack);
3094 case WLAN_FC_TYPE_DATA:
3095 ap_tx_status(wpa_s, data->tx_status.dst,
3096 data->tx_status.data,
3097 data->tx_status.data_len,
3098 data->tx_status.ack);
3101 #endif /* CONFIG_AP */
3104 case EVENT_EAPOL_TX_STATUS:
3105 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3106 data->eapol_tx_status.data,
3107 data->eapol_tx_status.data_len,
3108 data->eapol_tx_status.ack);
3110 case EVENT_DRIVER_CLIENT_POLL_OK:
3111 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3113 case EVENT_RX_FROM_UNKNOWN:
3114 if (wpa_s->ap_iface == NULL)
3116 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3117 data->rx_from_unknown.wds);
3119 case EVENT_CH_SWITCH:
3122 if (!wpa_s->ap_iface) {
3123 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3124 "event in non-AP mode");
3128 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3129 data->ch_switch.ht_enabled,
3130 data->ch_switch.ch_offset,
3131 data->ch_switch.ch_width,
3132 data->ch_switch.cf1,
3133 data->ch_switch.cf2);
3135 #endif /* CONFIG_AP */
3136 case EVENT_RX_MGMT: {
3138 const struct ieee80211_mgmt *mgmt;
3140 mgmt = (const struct ieee80211_mgmt *)
3141 data->rx_mgmt.frame;
3142 fc = le_to_host16(mgmt->frame_control);
3143 stype = WLAN_FC_GET_STYPE(fc);
3146 if (wpa_s->ap_iface == NULL) {
3147 #endif /* CONFIG_AP */
3149 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3150 data->rx_mgmt.frame_len > 24) {
3151 const u8 *src = mgmt->sa;
3152 const u8 *ie = mgmt->u.probe_req.variable;
3153 size_t ie_len = data->rx_mgmt.frame_len -
3154 (mgmt->u.probe_req.variable -
3155 data->rx_mgmt.frame);
3156 wpas_p2p_probe_req_rx(
3157 wpa_s, src, mgmt->da,
3158 mgmt->bssid, ie, ie_len,
3159 data->rx_mgmt.ssi_signal);
3162 #endif /* CONFIG_P2P */
3163 #ifdef CONFIG_IBSS_RSN
3164 if (stype == WLAN_FC_STYPE_AUTH &&
3165 data->rx_mgmt.frame_len >= 30) {
3166 wpa_supplicant_event_ibss_auth(wpa_s, data);
3169 #endif /* CONFIG_IBSS_RSN */
3171 if (stype == WLAN_FC_STYPE_ACTION) {
3172 wpas_event_rx_mgmt_action(
3173 wpa_s, mgmt, data->rx_mgmt.frame_len,
3174 data->rx_mgmt.freq);
3178 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3179 "management frame in non-AP mode");
3184 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3185 data->rx_mgmt.frame_len > 24) {
3186 const u8 *ie = mgmt->u.probe_req.variable;
3187 size_t ie_len = data->rx_mgmt.frame_len -
3188 (mgmt->u.probe_req.variable -
3189 data->rx_mgmt.frame);
3191 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3192 mgmt->bssid, ie, ie_len,
3193 data->rx_mgmt.ssi_signal);
3196 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3197 #endif /* CONFIG_AP */
3200 case EVENT_RX_PROBE_REQ:
3201 if (data->rx_probe_req.sa == NULL ||
3202 data->rx_probe_req.ie == NULL)
3205 if (wpa_s->ap_iface) {
3206 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3207 data->rx_probe_req.sa,
3208 data->rx_probe_req.da,
3209 data->rx_probe_req.bssid,
3210 data->rx_probe_req.ie,
3211 data->rx_probe_req.ie_len,
3212 data->rx_probe_req.ssi_signal);
3215 #endif /* CONFIG_AP */
3217 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3218 data->rx_probe_req.da,
3219 data->rx_probe_req.bssid,
3220 data->rx_probe_req.ie,
3221 data->rx_probe_req.ie_len,
3222 data->rx_probe_req.ssi_signal);
3223 #endif /* CONFIG_P2P */
3225 case EVENT_REMAIN_ON_CHANNEL:
3226 #ifdef CONFIG_OFFCHANNEL
3227 offchannel_remain_on_channel_cb(
3228 wpa_s, data->remain_on_channel.freq,
3229 data->remain_on_channel.duration);
3230 #endif /* CONFIG_OFFCHANNEL */
3232 wpas_p2p_remain_on_channel_cb(
3233 wpa_s, data->remain_on_channel.freq,
3234 data->remain_on_channel.duration);
3235 #endif /* CONFIG_P2P */
3237 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3238 #ifdef CONFIG_OFFCHANNEL
3239 offchannel_cancel_remain_on_channel_cb(
3240 wpa_s, data->remain_on_channel.freq);
3241 #endif /* CONFIG_OFFCHANNEL */
3243 wpas_p2p_cancel_remain_on_channel_cb(
3244 wpa_s, data->remain_on_channel.freq);
3245 #endif /* CONFIG_P2P */
3247 case EVENT_EAPOL_RX:
3248 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3249 data->eapol_rx.data,
3250 data->eapol_rx.data_len);
3252 case EVENT_SIGNAL_CHANGE:
3253 bgscan_notify_signal_change(
3254 wpa_s, data->signal_change.above_threshold,
3255 data->signal_change.current_signal,
3256 data->signal_change.current_noise,
3257 data->signal_change.current_txrate);
3259 case EVENT_INTERFACE_ENABLED:
3260 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3261 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3262 wpa_supplicant_update_mac_addr(wpa_s);
3264 if (!wpa_s->ap_iface) {
3265 wpa_supplicant_set_state(wpa_s,
3267 wpa_supplicant_req_scan(wpa_s, 0, 0);
3269 wpa_supplicant_set_state(wpa_s,
3271 #else /* CONFIG_AP */
3272 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3273 wpa_supplicant_req_scan(wpa_s, 0, 0);
3274 #endif /* CONFIG_AP */
3277 case EVENT_INTERFACE_DISABLED:
3278 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3280 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3281 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3282 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3284 * The interface was externally disabled. Remove
3285 * it assuming an external entity will start a
3286 * new session if needed.
3288 wpas_p2p_disconnect(wpa_s);
3291 #endif /* CONFIG_P2P */
3293 wpa_supplicant_mark_disassoc(wpa_s);
3294 radio_remove_works(wpa_s, NULL, 0);
3296 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3298 case EVENT_CHANNEL_LIST_CHANGED:
3299 wpa_supplicant_update_channel_list(wpa_s);
3301 case EVENT_INTERFACE_UNAVAILABLE:
3303 wpas_p2p_interface_unavailable(wpa_s);
3304 #endif /* CONFIG_P2P */
3306 case EVENT_BEST_CHANNEL:
3307 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3309 data->best_chan.freq_24, data->best_chan.freq_5,
3310 data->best_chan.freq_overall);
3311 wpa_s->best_24_freq = data->best_chan.freq_24;
3312 wpa_s->best_5_freq = data->best_chan.freq_5;
3313 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3315 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3316 data->best_chan.freq_5,
3317 data->best_chan.freq_overall);
3318 #endif /* CONFIG_P2P */
3320 case EVENT_UNPROT_DEAUTH:
3321 wpa_supplicant_event_unprot_deauth(wpa_s,
3322 &data->unprot_deauth);
3324 case EVENT_UNPROT_DISASSOC:
3325 wpa_supplicant_event_unprot_disassoc(wpa_s,
3326 &data->unprot_disassoc);
3328 case EVENT_STATION_LOW_ACK:
3330 if (wpa_s->ap_iface && data)
3331 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3332 data->low_ack.addr);
3333 #endif /* CONFIG_AP */
3336 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3337 #endif /* CONFIG_TDLS */
3339 case EVENT_IBSS_PEER_LOST:
3340 #ifdef CONFIG_IBSS_RSN
3341 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3342 #endif /* CONFIG_IBSS_RSN */
3344 case EVENT_DRIVER_GTK_REKEY:
3345 if (os_memcmp(data->driver_gtk_rekey.bssid,
3346 wpa_s->bssid, ETH_ALEN))
3350 wpa_sm_update_replay_ctr(wpa_s->wpa,
3351 data->driver_gtk_rekey.replay_ctr);
3353 case EVENT_SCHED_SCAN_STOPPED:
3355 wpa_s->sched_scanning = 0;
3356 wpa_supplicant_notify_scanning(wpa_s, 0);
3358 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3362 * Start a new sched scan to continue searching for more SSIDs
3363 * either if timed out or PNO schedule scan is pending.
3365 if (wpa_s->sched_scan_timed_out || wpa_s->pno_sched_pending) {
3367 if (wpa_supplicant_req_sched_scan(wpa_s) < 0 &&
3368 wpa_s->pno_sched_pending) {
3369 wpa_msg(wpa_s, MSG_ERROR, "Failed to schedule PNO");
3370 } else if (wpa_s->pno_sched_pending) {
3371 wpa_s->pno_sched_pending = 0;
3377 case EVENT_WPS_BUTTON_PUSHED:
3379 wpas_wps_start_pbc(wpa_s, NULL, 0);
3380 #endif /* CONFIG_WPS */
3382 case EVENT_AVOID_FREQUENCIES:
3383 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3385 case EVENT_CONNECT_FAILED_REASON:
3387 if (!wpa_s->ap_iface || !data)
3389 hostapd_event_connect_failed_reason(
3390 wpa_s->ap_iface->bss[0],
3391 data->connect_failed_reason.addr,
3392 data->connect_failed_reason.code);
3393 #endif /* CONFIG_AP */
3396 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);