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 (bss->caps & IEEE80211_CAP_PRIVACY)
407 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
408 struct wpa_ssid *ssid,
411 struct wpa_ie_data ie;
413 const u8 *rsn_ie, *wpa_ie;
417 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
421 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
422 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
423 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
424 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
425 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
427 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
428 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
431 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
432 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
438 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
440 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
445 if (!(ie.proto & ssid->proto)) {
446 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
451 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
452 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
457 if (!(ie.group_cipher & ssid->group_cipher)) {
458 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
463 if (!(ie.key_mgmt & ssid->key_mgmt)) {
464 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
469 #ifdef CONFIG_IEEE80211W
470 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
471 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
472 wpa_s->conf->pmf : ssid->ieee80211w) ==
473 MGMT_FRAME_PROTECTION_REQUIRED) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
478 #endif /* CONFIG_IEEE80211W */
480 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
484 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
485 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
488 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
489 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
495 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
497 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
502 if (!(ie.proto & ssid->proto)) {
503 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
508 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
509 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
514 if (!(ie.group_cipher & ssid->group_cipher)) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
520 if (!(ie.key_mgmt & ssid->key_mgmt)) {
521 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
526 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
530 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
532 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
536 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
537 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
538 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
542 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
543 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
547 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
554 static int freq_allowed(int *freqs, int freq)
561 for (i = 0; freqs[i]; i++)
562 if (freqs[i] == freq)
568 static int ht_supported(const struct hostapd_hw_modes *mode)
570 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
572 * The driver did not indicate whether it supports HT. Assume
573 * it does to avoid connection issues.
579 * IEEE Std 802.11n-2009 20.1.1:
580 * An HT non-AP STA shall support all EQM rates for one spatial stream.
582 return mode->mcs_set[0] == 0xff;
586 static int vht_supported(const struct hostapd_hw_modes *mode)
588 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
590 * The driver did not indicate whether it supports VHT. Assume
591 * it does to avoid connection issues.
597 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
598 * TODO: Verify if this complies with the standard
600 return (mode->vht_mcs_set[0] & 0x3) != 3;
604 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
606 const struct hostapd_hw_modes *mode = NULL, *modes;
607 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
612 return 1; /* Cannot do matching without knowing band */
614 modes = wpa_s->hw.modes;
617 * The driver does not provide any additional information
618 * about the utilized hardware, so allow the connection attempt
624 for (i = 0; i < wpa_s->hw.num_modes; i++) {
625 for (j = 0; j < modes[i].num_channels; j++) {
626 int freq = modes[i].channels[j].freq;
627 if (freq == bss->freq) {
629 mode->mode == HOSTAPD_MODE_IEEE80211G)
630 break; /* do not allow 802.11b replace
641 for (i = 0; i < (int) sizeof(scan_ie); i++) {
642 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
646 for (j = 2; j < rate_ie[1] + 2; j++) {
647 int flagged = !!(rate_ie[j] & 0x80);
648 int r = (rate_ie[j] & 0x7f) * 5;
651 * IEEE Std 802.11n-2009 7.3.2.2:
652 * The new BSS Membership selector value is encoded
653 * like a legacy basic rate, but it is not a rate and
654 * only indicates if the BSS members are required to
655 * support the mandatory features of Clause 20 [HT PHY]
656 * in order to join the BSS.
658 if (flagged && ((rate_ie[j] & 0x7f) ==
659 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
660 if (!ht_supported(mode)) {
661 wpa_dbg(wpa_s, MSG_DEBUG,
662 " hardware does not support "
669 /* There's also a VHT selector for 802.11ac */
670 if (flagged && ((rate_ie[j] & 0x7f) ==
671 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
672 if (!vht_supported(mode)) {
673 wpa_dbg(wpa_s, MSG_DEBUG,
674 " hardware does not support "
684 /* check for legacy basic rates */
685 for (k = 0; k < mode->num_rates; k++) {
686 if (mode->rates[k] == r)
689 if (k == mode->num_rates) {
691 * IEEE Std 802.11-2007 7.3.2.2 demands that in
692 * order to join a BSS all required rates
693 * have to be supported by the hardware.
695 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
696 "not support required rate %d.%d Mbps",
707 static int bss_is_dmg(struct wpa_bss *bss)
709 return bss->freq > 45000;
714 * Test whether BSS is in an ESS.
715 * This is done differently in DMG (60 GHz) and non-DMG bands
717 static int bss_is_ess(struct wpa_bss *bss)
719 if (bss_is_dmg(bss)) {
720 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
721 IEEE80211_CAP_DMG_AP;
724 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
729 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
730 int i, struct wpa_bss *bss,
731 struct wpa_ssid *group)
733 u8 wpa_ie_len, rsn_ie_len;
735 struct wpa_blacklist *e;
737 struct wpa_ssid *ssid;
739 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
740 wpa_ie_len = ie ? ie[1] : 0;
742 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
743 rsn_ie_len = ie ? ie[1] : 0;
745 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
746 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
747 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
748 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
749 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
750 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
751 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
754 e = wpa_blacklist_get(wpa_s, bss->bssid);
757 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
759 * When only a single network is enabled, we can
760 * trigger blacklisting on the first failure. This
761 * should not be done with multiple enabled networks to
762 * avoid getting forced to move into a worse ESS on
763 * single error if there are no other BSSes of the
768 if (e->count > limit) {
769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
770 "(count=%d limit=%d)", e->count, limit);
775 if (bss->ssid_len == 0) {
776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
780 if (disallowed_bssid(wpa_s, bss->bssid)) {
781 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
785 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
790 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
792 for (ssid = group; ssid; ssid = ssid->pnext) {
793 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
796 if (wpas_network_disabled(wpa_s, ssid)) {
797 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
801 res = wpas_temp_disabled(wpa_s, ssid);
803 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
804 "temporarily for %d second(s)", res);
809 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
810 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
815 if (wpa && ssid->ssid_len == 0 &&
816 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
819 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
820 /* Only allow wildcard SSID match if an AP
821 * advertises active WPS operation that matches
824 if (ssid->ssid_len == 0 &&
825 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
828 #endif /* CONFIG_WPS */
830 if (ssid->bssid_set && ssid->ssid_len == 0 &&
831 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
835 (bss->ssid_len != ssid->ssid_len ||
836 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
837 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
841 if (ssid->bssid_set &&
842 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
843 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
847 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
851 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
852 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
853 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
854 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
859 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
861 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
865 if (!wpa_supplicant_match_privacy(bss, ssid)) {
866 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
871 if (!bss_is_ess(bss)) {
872 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
876 if (!freq_allowed(ssid->freq_list, bss->freq)) {
877 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
882 if (!rate_match(wpa_s, bss)) {
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
889 if (ssid->p2p_group &&
890 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
891 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
892 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
896 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
897 struct wpabuf *p2p_ie;
898 u8 dev_addr[ETH_ALEN];
900 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
902 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
905 p2p_ie = wpa_bss_get_vendor_ie_multi(
906 bss, P2P_IE_VENDOR_TYPE);
907 if (p2p_ie == NULL) {
908 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
912 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
913 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
915 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
923 * TODO: skip the AP if its P2P IE has Group Formation
924 * bit set in the P2P Group Capability Bitmap and we
925 * are not in Group Formation with that device.
927 #endif /* CONFIG_P2P */
929 /* Matching configuration found */
933 /* No matching configuration found */
938 static struct wpa_bss *
939 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
940 struct wpa_ssid *group,
941 struct wpa_ssid **selected_ssid)
945 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
948 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
949 struct wpa_bss *bss = wpa_s->last_scan_res[i];
950 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
953 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
956 wpa_ssid_txt(bss->ssid, bss->ssid_len));
964 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
965 struct wpa_ssid **selected_ssid)
967 struct wpa_bss *selected = NULL;
970 if (wpa_s->last_scan_res == NULL ||
971 wpa_s->last_scan_res_used == 0)
972 return NULL; /* no scan results from last update */
974 while (selected == NULL) {
975 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
976 selected = wpa_supplicant_select_bss(
977 wpa_s, wpa_s->conf->pssid[prio],
983 if (selected == NULL && wpa_s->blacklist &&
984 !wpa_s->countermeasures) {
985 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
986 "blacklist and try again");
987 wpa_blacklist_clear(wpa_s);
988 wpa_s->blacklist_cleared++;
989 } else if (selected == NULL)
997 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
998 int timeout_sec, int timeout_usec)
1000 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1002 * No networks are enabled; short-circuit request so
1003 * we don't wait timeout seconds before transitioning
1004 * to INACTIVE state.
1006 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1007 "since there are no enabled networks");
1008 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1012 wpa_s->scan_for_connection = 1;
1013 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1017 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1018 struct wpa_bss *selected,
1019 struct wpa_ssid *ssid)
1021 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1022 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1023 "PBC session overlap");
1025 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
1027 #endif /* CONFIG_P2P */
1030 wpas_wps_cancel(wpa_s);
1031 #endif /* CONFIG_WPS */
1035 wpa_msg(wpa_s, MSG_DEBUG,
1036 "Considering connect request: reassociate: %d selected: "
1037 MACSTR " bssid: " MACSTR " pending: " MACSTR
1038 " wpa_state: %s ssid=%p current_ssid=%p",
1039 wpa_s->reassociate, MAC2STR(selected->bssid),
1040 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1041 wpa_supplicant_state_txt(wpa_s->wpa_state),
1042 ssid, wpa_s->current_ssid);
1045 * Do not trigger new association unless the BSSID has changed or if
1046 * reassociation is requested. If we are in process of associating with
1047 * the selected BSSID, do not trigger new attempt.
1049 if (wpa_s->reassociate ||
1050 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1051 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1052 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1053 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1054 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1056 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1057 ssid != wpa_s->current_ssid)))) {
1058 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1059 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1062 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1063 MAC2STR(selected->bssid));
1064 wpa_supplicant_associate(wpa_s, selected, ssid);
1066 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1067 "connect with the selected AP");
1074 static struct wpa_ssid *
1075 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1078 struct wpa_ssid *ssid;
1080 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1081 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1083 if (wpas_network_disabled(wpa_s, ssid))
1085 if (ssid->mode == IEEE80211_MODE_IBSS ||
1086 ssid->mode == IEEE80211_MODE_AP)
1094 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1095 * on BSS added and BSS changed events */
1096 static void wpa_supplicant_rsn_preauth_scan_results(
1097 struct wpa_supplicant *wpa_s)
1099 struct wpa_bss *bss;
1101 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1104 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1105 const u8 *ssid, *rsn;
1107 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1111 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1115 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1121 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1122 struct wpa_bss *selected,
1123 struct wpa_ssid *ssid)
1125 struct wpa_bss *current_bss = NULL;
1128 if (wpa_s->reassociate)
1129 return 1; /* explicit request to reassociate */
1130 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1131 return 1; /* we are not associated; continue */
1132 if (wpa_s->current_ssid == NULL)
1133 return 1; /* unknown current SSID */
1134 if (wpa_s->current_ssid != ssid)
1135 return 1; /* different network block */
1137 if (wpas_driver_bss_selection(wpa_s))
1138 return 0; /* Driver-based roaming */
1140 if (wpa_s->current_ssid->ssid)
1141 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1142 wpa_s->current_ssid->ssid,
1143 wpa_s->current_ssid->ssid_len);
1145 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1148 return 1; /* current BSS not seen in scan results */
1150 if (current_bss == selected)
1153 if (selected->last_update_idx > current_bss->last_update_idx)
1154 return 1; /* current BSS not seen in the last scan */
1156 #ifndef CONFIG_NO_ROAMING
1157 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1158 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1159 MAC2STR(current_bss->bssid), current_bss->level);
1160 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1161 MAC2STR(selected->bssid), selected->level);
1163 if (wpa_s->current_ssid->bssid_set &&
1164 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1166 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1167 "has preferred BSSID");
1171 if (current_bss->level < 0 && current_bss->level > selected->level) {
1172 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1178 if (current_bss->level < 0) {
1179 if (current_bss->level < -85)
1181 else if (current_bss->level < -80)
1183 else if (current_bss->level < -75)
1185 else if (current_bss->level < -70)
1190 if (abs(current_bss->level - selected->level) < min_diff) {
1191 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1197 #else /* CONFIG_NO_ROAMING */
1199 #endif /* CONFIG_NO_ROAMING */
1203 /* Return != 0 if no scan results could be fetched or if scan results should not
1204 * be shared with other virtual interfaces. */
1205 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1206 union wpa_event_data *data,
1209 struct wpa_scan_results *scan_res = NULL;
1212 #ifndef CONFIG_NO_RANDOM_POOL
1214 #endif /* CONFIG_NO_RANDOM_POOL */
1217 if (wpa_s->ap_iface)
1219 #endif /* CONFIG_AP */
1221 wpa_supplicant_notify_scanning(wpa_s, 0);
1223 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1224 data ? &data->scan_info :
1226 if (scan_res == NULL) {
1227 if (wpa_s->conf->ap_scan == 2 || ap ||
1228 wpa_s->scan_res_handler == scan_only_handler)
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1234 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1236 goto scan_work_done;
1239 #ifndef CONFIG_NO_RANDOM_POOL
1240 num = scan_res->num;
1243 for (i = 0; i < num; i++) {
1245 struct wpa_scan_res *res = scan_res->res[i];
1246 buf[0] = res->bssid[5];
1247 buf[1] = res->qual & 0xff;
1248 buf[2] = res->noise & 0xff;
1249 buf[3] = res->level & 0xff;
1250 buf[4] = res->tsf & 0xff;
1251 random_add_randomness(buf, sizeof(buf));
1253 #endif /* CONFIG_NO_RANDOM_POOL */
1255 if (own_request && wpa_s->scan_res_handler &&
1256 (wpa_s->own_scan_running || !wpa_s->external_scan_running)) {
1257 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1258 struct wpa_scan_results *scan_res);
1260 scan_res_handler = wpa_s->scan_res_handler;
1261 wpa_s->scan_res_handler = NULL;
1262 scan_res_handler(wpa_s, scan_res);
1264 goto scan_work_done;
1268 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1270 if (wpa_s->ap_iface->scan_cb)
1271 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1272 #endif /* CONFIG_AP */
1273 goto scan_work_done;
1276 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1277 wpa_s->own_scan_running, wpa_s->external_scan_running);
1278 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1279 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1280 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1281 wpa_s->manual_scan_id);
1282 wpa_s->manual_scan_use_id = 0;
1284 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1286 wpas_notify_scan_results(wpa_s);
1288 wpas_notify_scan_done(wpa_s, 1);
1290 if (!wpa_s->own_scan_running && wpa_s->external_scan_running) {
1291 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1292 wpa_scan_results_free(scan_res);
1296 if (sme_proc_obss_scan(wpa_s) > 0)
1297 goto scan_work_done;
1299 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1300 goto scan_work_done;
1302 if (autoscan_notify_scan(wpa_s, scan_res))
1303 goto scan_work_done;
1305 if (wpa_s->disconnected) {
1306 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1307 goto scan_work_done;
1310 if (!wpas_driver_bss_selection(wpa_s) &&
1311 bgscan_notify_scan(wpa_s, scan_res) == 1)
1312 goto scan_work_done;
1314 wpas_wps_update_ap_info(wpa_s, scan_res);
1316 wpa_scan_results_free(scan_res);
1318 if (wpa_s->scan_work) {
1319 struct wpa_radio_work *work = wpa_s->scan_work;
1320 wpa_s->scan_work = NULL;
1321 radio_work_done(work);
1324 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1327 wpa_scan_results_free(scan_res);
1328 if (wpa_s->scan_work) {
1329 struct wpa_radio_work *work = wpa_s->scan_work;
1330 wpa_s->scan_work = NULL;
1331 radio_work_done(work);
1337 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1338 int new_scan, int own_request)
1340 struct wpa_bss *selected;
1341 struct wpa_ssid *ssid = NULL;
1343 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1347 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1350 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1354 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1355 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1359 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1361 * Do not notify other virtual radios of scan results since we do not
1362 * want them to start other associations at the same time.
1366 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1367 ssid = wpa_supplicant_pick_new_network(wpa_s);
1369 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1370 wpa_supplicant_associate(wpa_s, NULL, ssid);
1372 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1373 } else if (own_request) {
1375 * No SSID found. If SCAN results are as a result of
1376 * own scan request and not due to a scan request on
1377 * another shared interface, try another scan.
1379 int timeout_sec = wpa_s->scan_interval;
1380 int timeout_usec = 0;
1382 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1385 if (wpa_s->p2p_in_provisioning ||
1386 wpa_s->show_group_started) {
1388 * Use shorter wait during P2P Provisioning
1389 * state and during P2P join-a-group operation
1390 * to speed up group formation.
1393 timeout_usec = 250000;
1394 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1398 #endif /* CONFIG_P2P */
1399 #ifdef CONFIG_INTERWORKING
1400 if (wpa_s->conf->auto_interworking &&
1401 wpa_s->conf->interworking &&
1402 wpa_s->conf->cred) {
1403 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1404 "start ANQP fetch since no matching "
1406 wpa_s->network_select = 1;
1407 wpa_s->auto_network_select = 1;
1408 interworking_start_fetch_anqp(wpa_s);
1411 #endif /* CONFIG_INTERWORKING */
1413 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1414 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1416 timeout_usec = 500000;
1417 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1421 #endif /* CONFIG_WPS */
1422 if (wpa_supplicant_req_sched_scan(wpa_s))
1423 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1431 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1432 union wpa_event_data *data)
1434 struct wpa_supplicant *ifs;
1436 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1438 * If no scan results could be fetched, then no need to
1439 * notify those interfaces that did not actually request
1440 * this scan. Similarly, if scan results started a new operation on this
1441 * interface, do not notify other interfaces to avoid concurrent
1442 * operations during a connection attempt.
1448 * Check other interfaces to see if they share the same radio. If
1449 * so, they get updated with this same scan info.
1451 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1454 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1455 "sibling", ifs->ifname);
1456 _wpa_supplicant_event_scan_results(ifs, data, 0);
1461 #endif /* CONFIG_NO_SCAN_PROCESSING */
1464 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1466 #ifdef CONFIG_NO_SCAN_PROCESSING
1468 #else /* CONFIG_NO_SCAN_PROCESSING */
1469 struct os_reltime now;
1471 if (wpa_s->last_scan_res_used <= 0)
1474 os_get_reltime(&now);
1475 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1476 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1480 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1481 #endif /* CONFIG_NO_SCAN_PROCESSING */
1486 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1488 struct wpa_supplicant *wpa_s = eloop_ctx;
1490 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1493 if (!wpa_s->no_keep_alive) {
1494 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1495 MAC2STR(wpa_s->bssid));
1496 /* TODO: could skip this if normal data traffic has been sent */
1497 /* TODO: Consider using some more appropriate data frame for
1500 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1505 if (wpa_s->sme.bss_max_idle_period) {
1507 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1510 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1511 wnm_bss_keep_alive, wpa_s, NULL);
1513 #endif /* CONFIG_SME */
1517 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1518 const u8 *ies, size_t ies_len)
1520 struct ieee802_11_elems elems;
1525 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1529 if (elems.bss_max_idle_period) {
1531 wpa_s->sme.bss_max_idle_period =
1532 WPA_GET_LE16(elems.bss_max_idle_period);
1533 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1534 "TU)%s", wpa_s->sme.bss_max_idle_period,
1535 (elems.bss_max_idle_period[2] & 0x01) ?
1536 " (protected keep-live required)" : "");
1537 if (wpa_s->sme.bss_max_idle_period == 0)
1538 wpa_s->sme.bss_max_idle_period = 1;
1539 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1540 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1541 /* msec times 1000 */
1542 msec = wpa_s->sme.bss_max_idle_period * 1024;
1545 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1546 wnm_bss_keep_alive, wpa_s,
1550 #endif /* CONFIG_SME */
1553 #endif /* CONFIG_WNM */
1556 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1559 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1560 #endif /* CONFIG_WNM */
1564 #ifdef CONFIG_INTERWORKING
1566 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1571 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1572 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1574 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1581 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1582 const u8 *ies, size_t ies_len)
1584 struct ieee802_11_elems elems;
1589 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1592 if (elems.qos_map_set) {
1593 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1594 elems.qos_map_set_len);
1598 #endif /* CONFIG_INTERWORKING */
1601 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1602 union wpa_event_data *data)
1604 int l, len, found = 0, wpa_found, rsn_found;
1606 #ifdef CONFIG_IEEE80211R
1608 #endif /* CONFIG_IEEE80211R */
1610 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1611 if (data->assoc_info.req_ies)
1612 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1613 data->assoc_info.req_ies_len);
1614 if (data->assoc_info.resp_ies) {
1615 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1616 data->assoc_info.resp_ies_len);
1618 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1619 data->assoc_info.resp_ies_len);
1620 #endif /* CONFIG_TDLS */
1622 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1623 data->assoc_info.resp_ies_len);
1624 #endif /* CONFIG_WNM */
1625 #ifdef CONFIG_INTERWORKING
1626 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1627 data->assoc_info.resp_ies_len);
1628 #endif /* CONFIG_INTERWORKING */
1630 if (data->assoc_info.beacon_ies)
1631 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1632 data->assoc_info.beacon_ies,
1633 data->assoc_info.beacon_ies_len);
1634 if (data->assoc_info.freq)
1635 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1636 data->assoc_info.freq);
1638 p = data->assoc_info.req_ies;
1639 l = data->assoc_info.req_ies_len;
1641 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1642 while (p && l >= 2) {
1645 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1649 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1650 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1651 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1652 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1655 wpa_find_assoc_pmkid(wpa_s);
1661 if (!found && data->assoc_info.req_ies)
1662 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1664 #ifdef CONFIG_IEEE80211R
1666 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1667 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1668 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1669 data->assoc_info.resp_ies,
1670 data->assoc_info.resp_ies_len,
1672 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1673 "Reassociation Response failed");
1674 wpa_supplicant_deauthenticate(
1675 wpa_s, WLAN_REASON_INVALID_IE);
1680 p = data->assoc_info.resp_ies;
1681 l = data->assoc_info.resp_ies_len;
1683 #ifdef CONFIG_WPS_STRICT
1684 if (p && wpa_s->current_ssid &&
1685 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1687 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1689 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1690 "include WPS IE in (Re)Association Response");
1694 if (wps_validate_assoc_resp(wps) < 0) {
1696 wpa_supplicant_deauthenticate(
1697 wpa_s, WLAN_REASON_INVALID_IE);
1702 #endif /* CONFIG_WPS_STRICT */
1704 /* Go through the IEs and make a copy of the MDIE, if present. */
1705 while (p && l >= 2) {
1708 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1712 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1713 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1714 wpa_s->sme.ft_used = 1;
1715 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1716 MOBILITY_DOMAIN_ID_LEN);
1722 #endif /* CONFIG_SME */
1724 /* Process FT when SME is in the driver */
1725 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1726 wpa_ft_is_completed(wpa_s->wpa)) {
1727 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1728 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1729 data->assoc_info.resp_ies,
1730 data->assoc_info.resp_ies_len,
1732 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1733 "Reassociation Response failed");
1734 wpa_supplicant_deauthenticate(
1735 wpa_s, WLAN_REASON_INVALID_IE);
1738 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1741 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1742 data->assoc_info.resp_ies_len);
1743 #endif /* CONFIG_IEEE80211R */
1745 /* WPA/RSN IE from Beacon/ProbeResp */
1746 p = data->assoc_info.beacon_ies;
1747 l = data->assoc_info.beacon_ies_len;
1749 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1751 wpa_found = rsn_found = 0;
1752 while (p && l >= 2) {
1755 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1760 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1761 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1763 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1767 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1769 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1776 if (!wpa_found && data->assoc_info.beacon_ies)
1777 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1778 if (!rsn_found && data->assoc_info.beacon_ies)
1779 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1780 if (wpa_found || rsn_found)
1781 wpa_s->ap_ies_from_associnfo = 1;
1783 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1784 wpa_s->assoc_freq != data->assoc_info.freq) {
1785 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1787 wpa_s->assoc_freq, data->assoc_info.freq);
1788 wpa_supplicant_update_scan_results(wpa_s);
1791 wpa_s->assoc_freq = data->assoc_info.freq;
1797 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1799 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1801 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1804 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1807 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1808 WPA_IE_VENDOR_TYPE);
1809 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1811 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1812 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1813 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1814 bss_rsn ? 2 + bss_rsn[1] : 0))
1821 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1822 union wpa_event_data *data)
1828 if (wpa_s->ap_iface) {
1829 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1830 data->assoc_info.addr,
1831 data->assoc_info.req_ies,
1832 data->assoc_info.req_ies_len,
1833 data->assoc_info.reassoc);
1836 #endif /* CONFIG_AP */
1838 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1839 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1842 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1843 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1844 wpa_supplicant_deauthenticate(
1845 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1849 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1850 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1851 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1852 MACSTR, MAC2STR(bssid));
1853 random_add_randomness(bssid, ETH_ALEN);
1854 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1855 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1856 wpas_notify_bssid_changed(wpa_s);
1858 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1859 wpa_clear_keys(wpa_s, bssid);
1861 if (wpa_supplicant_select_config(wpa_s) < 0) {
1862 wpa_supplicant_deauthenticate(
1863 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1867 if (wpa_s->conf->ap_scan == 1 &&
1868 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1869 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1870 wpa_msg(wpa_s, MSG_WARNING,
1871 "WPA/RSN IEs not updated");
1876 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1877 wpa_s->sme.prev_bssid_set = 1;
1878 #endif /* CONFIG_SME */
1880 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1881 if (wpa_s->current_ssid) {
1882 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1883 * initialized before association, but for other modes,
1884 * initialize PC/SC here, if the current configuration needs
1885 * smartcard or SIM/USIM. */
1886 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1888 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1890 l2_packet_notify_auth_start(wpa_s->l2);
1893 * Set portEnabled first to FALSE in order to get EAP state machine out
1894 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1895 * state machine may transit to AUTHENTICATING state based on obsolete
1896 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1897 * AUTHENTICATED without ever giving chance to EAP state machine to
1900 if (!ft_completed) {
1901 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1902 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1904 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1905 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1906 /* 802.1X::portControl = Auto */
1907 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1908 wpa_s->eapol_received = 0;
1909 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1910 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1911 (wpa_s->current_ssid &&
1912 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1913 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1915 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1917 * Set the key after having received joined-IBSS event
1920 wpa_supplicant_set_wpa_none_key(wpa_s,
1921 wpa_s->current_ssid);
1923 wpa_supplicant_cancel_auth_timeout(wpa_s);
1924 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1925 } else if (!ft_completed) {
1926 /* Timeout for receiving the first EAPOL packet */
1927 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1929 wpa_supplicant_cancel_scan(wpa_s);
1931 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1932 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1934 * We are done; the driver will take care of RSN 4-way
1937 wpa_supplicant_cancel_auth_timeout(wpa_s);
1938 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1939 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1940 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1941 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1942 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1944 * The driver will take care of RSN 4-way handshake, so we need
1945 * to allow EAPOL supplicant to complete its work without
1946 * waiting for WPA supplicant.
1948 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1949 } else if (ft_completed) {
1951 * FT protocol completed - make sure EAPOL state machine ends
1952 * up in authenticated.
1954 wpa_supplicant_cancel_auth_timeout(wpa_s);
1955 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1956 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1957 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1960 wpa_s->last_eapol_matches_bssid = 0;
1962 if (wpa_s->pending_eapol_rx) {
1963 struct os_reltime now, age;
1964 os_get_reltime(&now);
1965 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1966 if (age.sec == 0 && age.usec < 100000 &&
1967 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1969 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1970 "frame that was received just before "
1971 "association notification");
1972 wpa_supplicant_rx_eapol(
1973 wpa_s, wpa_s->pending_eapol_rx_src,
1974 wpabuf_head(wpa_s->pending_eapol_rx),
1975 wpabuf_len(wpa_s->pending_eapol_rx));
1977 wpabuf_free(wpa_s->pending_eapol_rx);
1978 wpa_s->pending_eapol_rx = NULL;
1981 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1982 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1983 wpa_s->current_ssid &&
1984 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1985 /* Set static WEP keys again */
1986 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1989 #ifdef CONFIG_IBSS_RSN
1990 if (wpa_s->current_ssid &&
1991 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1992 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1993 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1994 wpa_s->ibss_rsn == NULL) {
1995 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1996 if (!wpa_s->ibss_rsn) {
1997 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1998 wpa_supplicant_deauthenticate(
1999 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2003 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2005 #endif /* CONFIG_IBSS_RSN */
2007 wpas_wps_notify_assoc(wpa_s, bssid);
2011 static int disconnect_reason_recoverable(u16 reason_code)
2013 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2014 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2015 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2019 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2021 int locally_generated)
2025 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2027 * At least Host AP driver and a Prism3 card seemed to be
2028 * generating streams of disconnected events when configuring
2029 * IBSS for WPA-None. Ignore them for now.
2034 bssid = wpa_s->bssid;
2035 if (is_zero_ether_addr(bssid))
2036 bssid = wpa_s->pending_bssid;
2038 if (!is_zero_ether_addr(bssid) ||
2039 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2040 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2042 MAC2STR(bssid), reason_code,
2043 locally_generated ? " locally_generated=1" : "");
2048 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2049 int locally_generated)
2051 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2052 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2053 return 0; /* Not in 4-way handshake with PSK */
2056 * It looks like connection was lost while trying to go through PSK
2057 * 4-way handshake. Filter out known disconnection cases that are caused
2058 * by something else than PSK mismatch to avoid confusing reports.
2061 if (locally_generated) {
2062 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2070 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2072 int locally_generated)
2076 u8 prev_pending_bssid[ETH_ALEN];
2077 struct wpa_bss *fast_reconnect = NULL;
2078 #ifndef CONFIG_NO_SCAN_PROCESSING
2079 struct wpa_ssid *fast_reconnect_ssid = NULL;
2080 #endif /* CONFIG_NO_SCAN_PROCESSING */
2081 struct wpa_ssid *last_ssid;
2083 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2084 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2086 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2088 * At least Host AP driver and a Prism3 card seemed to be
2089 * generating streams of disconnected events when configuring
2090 * IBSS for WPA-None. Ignore them for now.
2092 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2093 "IBSS/WPA-None mode");
2097 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2098 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2099 "pre-shared key may be incorrect");
2100 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2101 return; /* P2P group removed */
2102 wpas_auth_failed(wpa_s);
2104 if (!wpa_s->disconnected &&
2105 (!wpa_s->auto_reconnect_disabled ||
2106 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
2107 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2108 "reconnect (wps=%d wpa_state=%d)",
2109 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2111 if (wpa_s->wpa_state == WPA_COMPLETED &&
2112 wpa_s->current_ssid &&
2113 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2114 !locally_generated &&
2115 disconnect_reason_recoverable(reason_code)) {
2117 * It looks like the AP has dropped association with
2118 * us, but could allow us to get back in. Try to
2119 * reconnect to the same BSS without full scan to save
2120 * time for some common cases.
2122 fast_reconnect = wpa_s->current_bss;
2123 #ifndef CONFIG_NO_SCAN_PROCESSING
2124 fast_reconnect_ssid = wpa_s->current_ssid;
2125 #endif /* CONFIG_NO_SCAN_PROCESSING */
2126 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2127 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2129 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2132 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2133 "try to re-connect");
2134 wpa_s->reassociate = 0;
2135 wpa_s->disconnected = 1;
2136 wpa_supplicant_cancel_sched_scan(wpa_s);
2138 bssid = wpa_s->bssid;
2139 if (is_zero_ether_addr(bssid))
2140 bssid = wpa_s->pending_bssid;
2141 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2142 wpas_connection_failed(wpa_s, bssid);
2143 wpa_sm_notify_disassoc(wpa_s->wpa);
2144 if (locally_generated)
2145 wpa_s->disconnect_reason = -reason_code;
2147 wpa_s->disconnect_reason = reason_code;
2148 wpas_notify_disconnect_reason(wpa_s);
2149 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2150 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2151 wpa_clear_keys(wpa_s, wpa_s->bssid);
2153 last_ssid = wpa_s->current_ssid;
2154 wpa_supplicant_mark_disassoc(wpa_s);
2156 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2157 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2158 wpa_s->current_ssid = last_ssid;
2161 if (fast_reconnect) {
2162 #ifndef CONFIG_NO_SCAN_PROCESSING
2163 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2164 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2165 fast_reconnect_ssid) < 0) {
2166 /* Recover through full scan */
2167 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2169 #endif /* CONFIG_NO_SCAN_PROCESSING */
2174 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2175 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2177 struct wpa_supplicant *wpa_s = eloop_ctx;
2179 if (!wpa_s->pending_mic_error_report)
2182 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2183 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2184 wpa_s->pending_mic_error_report = 0;
2186 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2190 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2191 union wpa_event_data *data)
2194 struct os_reltime t;
2196 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2197 pairwise = (data && data->michael_mic_failure.unicast);
2199 if ((wpa_s->last_michael_mic_error.sec &&
2200 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2201 wpa_s->pending_mic_error_report) {
2202 if (wpa_s->pending_mic_error_report) {
2204 * Send the pending MIC error report immediately since
2205 * we are going to start countermeasures and AP better
2208 wpa_sm_key_request(wpa_s->wpa, 1,
2209 wpa_s->pending_mic_error_pairwise);
2212 /* Send the new MIC error report immediately since we are going
2213 * to start countermeasures and AP better do the same.
2215 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2217 /* initialize countermeasures */
2218 wpa_s->countermeasures = 1;
2220 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2222 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2225 * Need to wait for completion of request frame. We do not get
2226 * any callback for the message completion, so just wait a
2227 * short while and hope for the best. */
2230 wpa_drv_set_countermeasures(wpa_s, 1);
2231 wpa_supplicant_deauthenticate(wpa_s,
2232 WLAN_REASON_MICHAEL_MIC_FAILURE);
2233 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2235 eloop_register_timeout(60, 0,
2236 wpa_supplicant_stop_countermeasures,
2238 /* TODO: mark the AP rejected for 60 second. STA is
2239 * allowed to associate with another AP.. */
2241 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2242 if (wpa_s->mic_errors_seen) {
2244 * Reduce the effectiveness of Michael MIC error
2245 * reports as a means for attacking against TKIP if
2246 * more than one MIC failure is noticed with the same
2247 * PTK. We delay the transmission of the reports by a
2248 * random time between 0 and 60 seconds in order to
2249 * force the attacker wait 60 seconds before getting
2250 * the information on whether a frame resulted in a MIC
2256 if (os_get_random(rval, sizeof(rval)) < 0)
2257 sec = os_random() % 60;
2259 sec = WPA_GET_BE32(rval) % 60;
2260 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2261 "report %d seconds", sec);
2262 wpa_s->pending_mic_error_report = 1;
2263 wpa_s->pending_mic_error_pairwise = pairwise;
2264 eloop_cancel_timeout(
2265 wpa_supplicant_delayed_mic_error_report,
2267 eloop_register_timeout(
2268 sec, os_random() % 1000000,
2269 wpa_supplicant_delayed_mic_error_report,
2272 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2274 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2275 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2276 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2278 wpa_s->last_michael_mic_error = t;
2279 wpa_s->mic_errors_seen++;
2283 #ifdef CONFIG_TERMINATE_ONLASTIF
2284 static int any_interfaces(struct wpa_supplicant *head)
2286 struct wpa_supplicant *wpa_s;
2288 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2289 if (!wpa_s->interface_removed)
2293 #endif /* CONFIG_TERMINATE_ONLASTIF */
2297 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2298 union wpa_event_data *data)
2300 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2303 switch (data->interface_status.ievent) {
2304 case EVENT_INTERFACE_ADDED:
2305 if (!wpa_s->interface_removed)
2307 wpa_s->interface_removed = 0;
2308 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2309 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2310 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2311 "driver after interface was added");
2314 case EVENT_INTERFACE_REMOVED:
2315 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2316 wpa_s->interface_removed = 1;
2317 wpa_supplicant_mark_disassoc(wpa_s);
2318 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2319 l2_packet_deinit(wpa_s->l2);
2321 #ifdef CONFIG_IBSS_RSN
2322 ibss_rsn_deinit(wpa_s->ibss_rsn);
2323 wpa_s->ibss_rsn = NULL;
2324 #endif /* CONFIG_IBSS_RSN */
2325 #ifdef CONFIG_TERMINATE_ONLASTIF
2326 /* check if last interface */
2327 if (!any_interfaces(wpa_s->global->ifaces))
2329 #endif /* CONFIG_TERMINATE_ONLASTIF */
2335 #ifdef CONFIG_PEERKEY
2337 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2338 union wpa_event_data *data)
2342 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2344 #endif /* CONFIG_PEERKEY */
2348 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2349 union wpa_event_data *data)
2353 switch (data->tdls.oper) {
2354 case TDLS_REQUEST_SETUP:
2355 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2356 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2357 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2359 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2361 case TDLS_REQUEST_TEARDOWN:
2362 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2363 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2364 data->tdls.reason_code);
2366 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2371 #endif /* CONFIG_TDLS */
2375 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2376 union wpa_event_data *data)
2380 switch (data->wnm.oper) {
2381 case WNM_OPER_SLEEP:
2382 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2383 "(action=%d, intval=%d)",
2384 data->wnm.sleep_action, data->wnm.sleep_intval);
2385 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2386 data->wnm.sleep_intval, NULL);
2390 #endif /* CONFIG_WNM */
2393 #ifdef CONFIG_IEEE80211R
2395 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2396 union wpa_event_data *data)
2401 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2402 data->ft_ies.ies_len,
2403 data->ft_ies.ft_action,
2404 data->ft_ies.target_ap,
2405 data->ft_ies.ric_ies,
2406 data->ft_ies.ric_ies_len) < 0) {
2407 /* TODO: prevent MLME/driver from trying to associate? */
2410 #endif /* CONFIG_IEEE80211R */
2413 #ifdef CONFIG_IBSS_RSN
2414 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2415 union wpa_event_data *data)
2417 struct wpa_ssid *ssid;
2418 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2422 ssid = wpa_s->current_ssid;
2425 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2428 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2432 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2433 union wpa_event_data *data)
2435 struct wpa_ssid *ssid = wpa_s->current_ssid;
2440 /* check if the ssid is correctly configured as IBSS/RSN */
2441 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2444 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2445 data->rx_mgmt.frame_len);
2447 #endif /* CONFIG_IBSS_RSN */
2450 #ifdef CONFIG_IEEE80211R
2451 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2454 const u8 *sta_addr, *target_ap_addr;
2457 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2458 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2459 return; /* only SME case supported for now */
2460 if (len < 1 + 2 * ETH_ALEN + 2)
2463 return; /* Only FT Action Response is supported for now */
2464 sta_addr = data + 1;
2465 target_ap_addr = data + 1 + ETH_ALEN;
2466 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2467 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2468 MACSTR " TargetAP " MACSTR " status %u",
2469 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2471 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2472 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2473 " in FT Action Response", MAC2STR(sta_addr));
2478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2479 "failure (status code %d)", status);
2480 /* TODO: report error to FT code(?) */
2484 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2485 len - (1 + 2 * ETH_ALEN + 2), 1,
2486 target_ap_addr, NULL, 0) < 0)
2491 struct wpa_bss *bss;
2492 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2494 wpa_s->sme.freq = bss->freq;
2495 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2496 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2499 #endif /* CONFIG_SME */
2501 #endif /* CONFIG_IEEE80211R */
2504 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2505 struct unprot_deauth *e)
2507 #ifdef CONFIG_IEEE80211W
2508 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2509 "dropped: " MACSTR " -> " MACSTR
2510 " (reason code %u)",
2511 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2512 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2513 #endif /* CONFIG_IEEE80211W */
2517 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2518 struct unprot_disassoc *e)
2520 #ifdef CONFIG_IEEE80211W
2521 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2522 "dropped: " MACSTR " -> " MACSTR
2523 " (reason code %u)",
2524 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2525 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2526 #endif /* CONFIG_IEEE80211W */
2530 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2531 u16 reason_code, int locally_generated,
2532 const u8 *ie, size_t ie_len, int deauth)
2535 if (wpa_s->ap_iface && addr) {
2536 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2540 if (wpa_s->ap_iface) {
2541 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2544 #endif /* CONFIG_AP */
2546 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2548 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2549 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2550 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2551 eapol_sm_failed(wpa_s->eapol))) &&
2552 !wpa_s->eap_expected_failure))
2553 wpas_auth_failed(wpa_s);
2556 if (deauth && reason_code > 0) {
2557 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2558 locally_generated) > 0) {
2560 * The interface was removed, so cannot continue
2561 * processing any additional operations after this.
2566 #endif /* CONFIG_P2P */
2568 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2573 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2574 struct disassoc_info *info)
2576 u16 reason_code = 0;
2577 int locally_generated = 0;
2578 const u8 *addr = NULL;
2579 const u8 *ie = NULL;
2582 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2587 ie_len = info->ie_len;
2588 reason_code = info->reason_code;
2589 locally_generated = info->locally_generated;
2590 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2591 locally_generated ? " (locally generated)" : "");
2593 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2595 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2600 if (wpa_s->ap_iface && info && info->addr) {
2601 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2605 if (wpa_s->ap_iface) {
2606 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2609 #endif /* CONFIG_AP */
2613 wpas_p2p_disassoc_notif(
2614 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2617 #endif /* CONFIG_P2P */
2619 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2620 sme_event_disassoc(wpa_s, info);
2622 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2627 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2628 struct deauth_info *info)
2630 u16 reason_code = 0;
2631 int locally_generated = 0;
2632 const u8 *addr = NULL;
2633 const u8 *ie = NULL;
2636 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2641 ie_len = info->ie_len;
2642 reason_code = info->reason_code;
2643 locally_generated = info->locally_generated;
2644 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2646 locally_generated ? " (locally generated)" : "");
2648 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2651 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2655 wpa_reset_ft_completed(wpa_s->wpa);
2657 wpas_event_disconnect(wpa_s, addr, reason_code,
2658 locally_generated, ie, ie_len, 1);
2662 static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2664 struct wpa_supplicant *ifs;
2666 if (wpa_s->drv_priv == NULL)
2667 return; /* Ignore event during drv initialization */
2669 free_hw_features(wpa_s);
2670 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2671 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2674 wpas_p2p_update_channel_list(wpa_s);
2675 #endif /* CONFIG_P2P */
2678 * Check other interfaces to see if they share the same radio. If
2679 * so, they get updated with this same hw mode info.
2681 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2684 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2686 free_hw_features(ifs);
2687 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2688 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2694 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2695 const struct ieee80211_mgmt *mgmt,
2696 size_t len, int freq)
2702 if (len < IEEE80211_HDRLEN + 2)
2705 payload = &mgmt->u.action.category;
2706 category = *payload++;
2707 plen = (((const u8 *) mgmt) + len) - payload;
2709 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2710 " Category=%u DataLen=%d freq=%d MHz",
2711 MAC2STR(mgmt->sa), category, (int) plen, freq);
2713 #ifdef CONFIG_IEEE80211R
2714 if (category == WLAN_ACTION_FT) {
2715 ft_rx_action(wpa_s, payload, plen);
2718 #endif /* CONFIG_IEEE80211R */
2720 #ifdef CONFIG_IEEE80211W
2722 if (category == WLAN_ACTION_SA_QUERY) {
2723 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2726 #endif /* CONFIG_SME */
2727 #endif /* CONFIG_IEEE80211W */
2730 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2731 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2734 #endif /* CONFIG_WNM */
2737 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2738 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2739 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2740 mgmt->u.action.category,
2741 payload, plen, freq) == 0)
2743 #endif /* CONFIG_GAS */
2746 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2747 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2748 wpa_dbg(wpa_s, MSG_DEBUG,
2749 "TDLS: Received Discovery Response from " MACSTR,
2753 #endif /* CONFIG_TDLS */
2755 #ifdef CONFIG_INTERWORKING
2756 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2757 payload[0] == QOS_QOS_MAP_CONFIG) {
2758 const u8 *pos = payload + 1;
2759 size_t qlen = plen - 1;
2760 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2761 MACSTR, MAC2STR(mgmt->sa));
2762 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2763 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2764 pos[1] <= qlen - 2 && pos[1] >= 16)
2765 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2768 #endif /* CONFIG_INTERWORKING */
2771 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2772 category, payload, plen, freq);
2773 #endif /* CONFIG_P2P */
2777 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2778 union wpa_event_data *event)
2781 struct wpa_supplicant *ifs;
2782 #endif /* CONFIG_P2P */
2783 struct wpa_freq_range_list *list;
2786 list = &event->freq_range;
2789 str = freq_range_list_str(list);
2790 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2794 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2795 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2798 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2799 wpas_p2p_update_channel_list(wpa_s);
2802 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2804 if (!ifs->current_ssid ||
2805 !ifs->current_ssid->p2p_group ||
2806 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2807 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2810 freq = ifs->current_ssid->frequency;
2811 if (!freq_range_list_includes(list, freq)) {
2812 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
2817 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
2819 /* TODO: Consider using CSA or removing the group within
2821 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
2823 #endif /* CONFIG_P2P */
2829 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2830 union wpa_event_data *data)
2832 struct wpa_supplicant *wpa_s = ctx;
2834 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2835 event != EVENT_INTERFACE_ENABLED &&
2836 event != EVENT_INTERFACE_STATUS &&
2837 event != EVENT_SCHED_SCAN_STOPPED) {
2838 wpa_dbg(wpa_s, MSG_DEBUG,
2839 "Ignore event %s (%d) while interface is disabled",
2840 event_to_string(event), event);
2844 #ifndef CONFIG_NO_STDOUT_DEBUG
2846 int level = MSG_DEBUG;
2848 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2849 const struct ieee80211_hdr *hdr;
2851 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2852 fc = le_to_host16(hdr->frame_control);
2853 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2854 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2855 level = MSG_EXCESSIVE;
2858 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2859 event_to_string(event), event);
2861 #endif /* CONFIG_NO_STDOUT_DEBUG */
2865 sme_event_auth(wpa_s, data);
2868 wpa_supplicant_event_assoc(wpa_s, data);
2870 case EVENT_DISASSOC:
2871 wpas_event_disassoc(wpa_s,
2872 data ? &data->disassoc_info : NULL);
2875 wpas_event_deauth(wpa_s,
2876 data ? &data->deauth_info : NULL);
2878 case EVENT_MICHAEL_MIC_FAILURE:
2879 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2881 #ifndef CONFIG_NO_SCAN_PROCESSING
2882 case EVENT_SCAN_STARTED:
2883 os_get_reltime(&wpa_s->scan_start_time);
2884 if (wpa_s->own_scan_requested) {
2885 struct os_reltime diff;
2887 os_reltime_sub(&wpa_s->scan_start_time,
2888 &wpa_s->scan_trigger_time, &diff);
2889 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
2890 diff.sec, diff.usec);
2891 wpa_s->own_scan_requested = 0;
2892 wpa_s->own_scan_running = 1;
2893 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2894 wpa_s->manual_scan_use_id) {
2895 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED "id=%u",
2896 wpa_s->manual_scan_id);
2898 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2901 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
2902 wpa_s->external_scan_running = 1;
2903 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2906 case EVENT_SCAN_RESULTS:
2907 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
2908 struct os_reltime now, diff;
2909 os_get_reltime(&now);
2910 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
2911 wpa_s->scan_start_time.sec = 0;
2912 wpa_s->scan_start_time.usec = 0;
2913 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
2914 diff.sec, diff.usec);
2916 wpa_supplicant_event_scan_results(wpa_s, data);
2917 wpa_s->own_scan_running = 0;
2918 wpa_s->external_scan_running = 0;
2919 radio_work_check_next(wpa_s);
2921 #endif /* CONFIG_NO_SCAN_PROCESSING */
2922 case EVENT_ASSOCINFO:
2923 wpa_supplicant_event_associnfo(wpa_s, data);
2925 case EVENT_INTERFACE_STATUS:
2926 wpa_supplicant_event_interface_status(wpa_s, data);
2928 case EVENT_PMKID_CANDIDATE:
2929 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2931 #ifdef CONFIG_PEERKEY
2932 case EVENT_STKSTART:
2933 wpa_supplicant_event_stkstart(wpa_s, data);
2935 #endif /* CONFIG_PEERKEY */
2938 wpa_supplicant_event_tdls(wpa_s, data);
2940 #endif /* CONFIG_TDLS */
2943 wpa_supplicant_event_wnm(wpa_s, data);
2945 #endif /* CONFIG_WNM */
2946 #ifdef CONFIG_IEEE80211R
2947 case EVENT_FT_RESPONSE:
2948 wpa_supplicant_event_ft_response(wpa_s, data);
2950 #endif /* CONFIG_IEEE80211R */
2951 #ifdef CONFIG_IBSS_RSN
2952 case EVENT_IBSS_RSN_START:
2953 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2955 #endif /* CONFIG_IBSS_RSN */
2956 case EVENT_ASSOC_REJECT:
2957 if (data->assoc_reject.bssid)
2958 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2959 "bssid=" MACSTR " status_code=%u",
2960 MAC2STR(data->assoc_reject.bssid),
2961 data->assoc_reject.status_code);
2963 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2965 data->assoc_reject.status_code);
2966 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2967 sme_event_assoc_reject(wpa_s, data);
2969 const u8 *bssid = data->assoc_reject.bssid;
2970 if (bssid == NULL || is_zero_ether_addr(bssid))
2971 bssid = wpa_s->pending_bssid;
2972 wpas_connection_failed(wpa_s, bssid);
2973 wpa_supplicant_mark_disassoc(wpa_s);
2976 case EVENT_AUTH_TIMED_OUT:
2977 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2978 sme_event_auth_timed_out(wpa_s, data);
2980 case EVENT_ASSOC_TIMED_OUT:
2981 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2982 sme_event_assoc_timed_out(wpa_s, data);
2984 case EVENT_TX_STATUS:
2985 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2986 " type=%d stype=%d",
2987 MAC2STR(data->tx_status.dst),
2988 data->tx_status.type, data->tx_status.stype);
2990 if (wpa_s->ap_iface == NULL) {
2991 #ifdef CONFIG_OFFCHANNEL
2992 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2993 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2994 offchannel_send_action_tx_status(
2995 wpa_s, data->tx_status.dst,
2996 data->tx_status.data,
2997 data->tx_status.data_len,
2998 data->tx_status.ack ?
2999 OFFCHANNEL_SEND_ACTION_SUCCESS :
3000 OFFCHANNEL_SEND_ACTION_NO_ACK);
3001 #endif /* CONFIG_OFFCHANNEL */
3004 #endif /* CONFIG_AP */
3005 #ifdef CONFIG_OFFCHANNEL
3006 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3007 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3009 * Catch TX status events for Action frames we sent via group
3010 * interface in GO mode.
3012 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3013 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3014 os_memcmp(wpa_s->parent->pending_action_dst,
3015 data->tx_status.dst, ETH_ALEN) == 0) {
3016 offchannel_send_action_tx_status(
3017 wpa_s->parent, data->tx_status.dst,
3018 data->tx_status.data,
3019 data->tx_status.data_len,
3020 data->tx_status.ack ?
3021 OFFCHANNEL_SEND_ACTION_SUCCESS :
3022 OFFCHANNEL_SEND_ACTION_NO_ACK);
3025 #endif /* CONFIG_OFFCHANNEL */
3027 switch (data->tx_status.type) {
3028 case WLAN_FC_TYPE_MGMT:
3029 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3030 data->tx_status.data_len,
3031 data->tx_status.stype,
3032 data->tx_status.ack);
3034 case WLAN_FC_TYPE_DATA:
3035 ap_tx_status(wpa_s, data->tx_status.dst,
3036 data->tx_status.data,
3037 data->tx_status.data_len,
3038 data->tx_status.ack);
3041 #endif /* CONFIG_AP */
3044 case EVENT_EAPOL_TX_STATUS:
3045 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3046 data->eapol_tx_status.data,
3047 data->eapol_tx_status.data_len,
3048 data->eapol_tx_status.ack);
3050 case EVENT_DRIVER_CLIENT_POLL_OK:
3051 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3053 case EVENT_RX_FROM_UNKNOWN:
3054 if (wpa_s->ap_iface == NULL)
3056 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3057 data->rx_from_unknown.wds);
3059 case EVENT_CH_SWITCH:
3062 if (!wpa_s->ap_iface) {
3063 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3064 "event in non-AP mode");
3068 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3069 data->ch_switch.ht_enabled,
3070 data->ch_switch.ch_offset,
3071 data->ch_switch.ch_width,
3072 data->ch_switch.cf1,
3073 data->ch_switch.cf2);
3075 #endif /* CONFIG_AP */
3076 case EVENT_RX_MGMT: {
3078 const struct ieee80211_mgmt *mgmt;
3080 mgmt = (const struct ieee80211_mgmt *)
3081 data->rx_mgmt.frame;
3082 fc = le_to_host16(mgmt->frame_control);
3083 stype = WLAN_FC_GET_STYPE(fc);
3086 if (wpa_s->ap_iface == NULL) {
3087 #endif /* CONFIG_AP */
3089 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3090 data->rx_mgmt.frame_len > 24) {
3091 const u8 *src = mgmt->sa;
3092 const u8 *ie = mgmt->u.probe_req.variable;
3093 size_t ie_len = data->rx_mgmt.frame_len -
3094 (mgmt->u.probe_req.variable -
3095 data->rx_mgmt.frame);
3096 wpas_p2p_probe_req_rx(
3097 wpa_s, src, mgmt->da,
3098 mgmt->bssid, ie, ie_len,
3099 data->rx_mgmt.ssi_signal);
3102 #endif /* CONFIG_P2P */
3103 #ifdef CONFIG_IBSS_RSN
3104 if (stype == WLAN_FC_STYPE_AUTH &&
3105 data->rx_mgmt.frame_len >= 30) {
3106 wpa_supplicant_event_ibss_auth(wpa_s, data);
3109 #endif /* CONFIG_IBSS_RSN */
3111 if (stype == WLAN_FC_STYPE_ACTION) {
3112 wpas_event_rx_mgmt_action(
3113 wpa_s, mgmt, data->rx_mgmt.frame_len,
3114 data->rx_mgmt.freq);
3118 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3119 "management frame in non-AP mode");
3124 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3125 data->rx_mgmt.frame_len > 24) {
3126 const u8 *ie = mgmt->u.probe_req.variable;
3127 size_t ie_len = data->rx_mgmt.frame_len -
3128 (mgmt->u.probe_req.variable -
3129 data->rx_mgmt.frame);
3131 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3132 mgmt->bssid, ie, ie_len,
3133 data->rx_mgmt.ssi_signal);
3136 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3137 #endif /* CONFIG_AP */
3140 case EVENT_RX_PROBE_REQ:
3141 if (data->rx_probe_req.sa == NULL ||
3142 data->rx_probe_req.ie == NULL)
3145 if (wpa_s->ap_iface) {
3146 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3147 data->rx_probe_req.sa,
3148 data->rx_probe_req.da,
3149 data->rx_probe_req.bssid,
3150 data->rx_probe_req.ie,
3151 data->rx_probe_req.ie_len,
3152 data->rx_probe_req.ssi_signal);
3155 #endif /* CONFIG_AP */
3157 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3158 data->rx_probe_req.da,
3159 data->rx_probe_req.bssid,
3160 data->rx_probe_req.ie,
3161 data->rx_probe_req.ie_len,
3162 data->rx_probe_req.ssi_signal);
3163 #endif /* CONFIG_P2P */
3165 case EVENT_REMAIN_ON_CHANNEL:
3166 #ifdef CONFIG_OFFCHANNEL
3167 offchannel_remain_on_channel_cb(
3168 wpa_s, data->remain_on_channel.freq,
3169 data->remain_on_channel.duration);
3170 #endif /* CONFIG_OFFCHANNEL */
3172 wpas_p2p_remain_on_channel_cb(
3173 wpa_s, data->remain_on_channel.freq,
3174 data->remain_on_channel.duration);
3175 #endif /* CONFIG_P2P */
3177 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3178 #ifdef CONFIG_OFFCHANNEL
3179 offchannel_cancel_remain_on_channel_cb(
3180 wpa_s, data->remain_on_channel.freq);
3181 #endif /* CONFIG_OFFCHANNEL */
3183 wpas_p2p_cancel_remain_on_channel_cb(
3184 wpa_s, data->remain_on_channel.freq);
3185 #endif /* CONFIG_P2P */
3187 case EVENT_EAPOL_RX:
3188 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3189 data->eapol_rx.data,
3190 data->eapol_rx.data_len);
3192 case EVENT_SIGNAL_CHANGE:
3193 bgscan_notify_signal_change(
3194 wpa_s, data->signal_change.above_threshold,
3195 data->signal_change.current_signal,
3196 data->signal_change.current_noise,
3197 data->signal_change.current_txrate);
3199 case EVENT_INTERFACE_ENABLED:
3200 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3201 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3202 wpa_supplicant_update_mac_addr(wpa_s);
3204 if (!wpa_s->ap_iface) {
3205 wpa_supplicant_set_state(wpa_s,
3207 wpa_supplicant_req_scan(wpa_s, 0, 0);
3209 wpa_supplicant_set_state(wpa_s,
3211 #else /* CONFIG_AP */
3212 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3213 wpa_supplicant_req_scan(wpa_s, 0, 0);
3214 #endif /* CONFIG_AP */
3217 case EVENT_INTERFACE_DISABLED:
3218 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3220 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3221 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3222 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3224 * The interface was externally disabled. Remove
3225 * it assuming an external entity will start a
3226 * new session if needed.
3228 wpas_p2p_disconnect(wpa_s);
3231 #endif /* CONFIG_P2P */
3233 wpa_supplicant_mark_disassoc(wpa_s);
3234 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3236 case EVENT_CHANNEL_LIST_CHANGED:
3237 wpa_supplicant_update_channel_list(wpa_s);
3239 case EVENT_INTERFACE_UNAVAILABLE:
3241 wpas_p2p_interface_unavailable(wpa_s);
3242 #endif /* CONFIG_P2P */
3244 case EVENT_BEST_CHANNEL:
3245 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3247 data->best_chan.freq_24, data->best_chan.freq_5,
3248 data->best_chan.freq_overall);
3249 wpa_s->best_24_freq = data->best_chan.freq_24;
3250 wpa_s->best_5_freq = data->best_chan.freq_5;
3251 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3253 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3254 data->best_chan.freq_5,
3255 data->best_chan.freq_overall);
3256 #endif /* CONFIG_P2P */
3258 case EVENT_UNPROT_DEAUTH:
3259 wpa_supplicant_event_unprot_deauth(wpa_s,
3260 &data->unprot_deauth);
3262 case EVENT_UNPROT_DISASSOC:
3263 wpa_supplicant_event_unprot_disassoc(wpa_s,
3264 &data->unprot_disassoc);
3266 case EVENT_STATION_LOW_ACK:
3268 if (wpa_s->ap_iface && data)
3269 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3270 data->low_ack.addr);
3271 #endif /* CONFIG_AP */
3274 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3275 #endif /* CONFIG_TDLS */
3277 case EVENT_IBSS_PEER_LOST:
3278 #ifdef CONFIG_IBSS_RSN
3279 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3280 #endif /* CONFIG_IBSS_RSN */
3282 case EVENT_DRIVER_GTK_REKEY:
3283 if (os_memcmp(data->driver_gtk_rekey.bssid,
3284 wpa_s->bssid, ETH_ALEN))
3288 wpa_sm_update_replay_ctr(wpa_s->wpa,
3289 data->driver_gtk_rekey.replay_ctr);
3291 case EVENT_SCHED_SCAN_STOPPED:
3293 wpa_s->sched_scanning = 0;
3294 wpa_supplicant_notify_scanning(wpa_s, 0);
3296 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3300 * Start a new sched scan to continue searching for more SSIDs
3301 * either if timed out or PNO schedule scan is pending.
3303 if (wpa_s->sched_scan_timed_out || wpa_s->pno_sched_pending) {
3305 if (wpa_supplicant_req_sched_scan(wpa_s) < 0 &&
3306 wpa_s->pno_sched_pending) {
3307 wpa_msg(wpa_s, MSG_ERROR, "Failed to schedule PNO");
3308 } else if (wpa_s->pno_sched_pending) {
3309 wpa_s->pno_sched_pending = 0;
3315 case EVENT_WPS_BUTTON_PUSHED:
3317 wpas_wps_start_pbc(wpa_s, NULL, 0);
3318 #endif /* CONFIG_WPS */
3320 case EVENT_AVOID_FREQUENCIES:
3321 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3323 case EVENT_CONNECT_FAILED_REASON:
3325 if (!wpa_s->ap_iface || !data)
3327 hostapd_event_connect_failed_reason(
3328 wpa_s->ap_iface->bss[0],
3329 data->connect_failed_reason.addr,
3330 data->connect_failed_reason.code);
3331 #endif /* CONFIG_AP */
3334 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);