2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
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"
50 #ifndef CONFIG_NO_SCAN_PROCESSING
51 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
52 int new_scan, int own_request);
53 #endif /* CONFIG_NO_SCAN_PROCESSING */
56 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
59 struct os_reltime now;
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
65 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
74 static struct wpa_bss * wpa_supplicant_get_new_bss(
75 struct wpa_supplicant *wpa_s, const u8 *bssid)
77 struct wpa_bss *bss = NULL;
78 struct wpa_ssid *ssid = wpa_s->current_ssid;
80 if (ssid->ssid_len > 0)
81 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
83 bss = wpa_bss_get_bssid(wpa_s, bssid);
89 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
91 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
94 wpa_supplicant_update_scan_results(wpa_s);
96 /* Get the BSS from the new scan results */
97 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
101 wpa_s->current_bss = bss;
105 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
107 struct wpa_ssid *ssid, *old_ssid;
110 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
111 wpa_supplicant_update_current_bss(wpa_s);
115 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
117 ssid = wpa_supplicant_get_ssid(wpa_s);
119 wpa_msg(wpa_s, MSG_INFO,
120 "No network configuration found for the current AP");
124 if (wpas_network_disabled(wpa_s, ssid)) {
125 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
129 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
130 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
131 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
135 res = wpas_temp_disabled(wpa_s, ssid);
137 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
138 "disabled for %d second(s)", res);
142 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
144 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
146 size_t wpa_ie_len = sizeof(wpa_ie);
147 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
148 wpa_ie, &wpa_ie_len) < 0)
149 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
151 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
154 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
155 eapol_sm_invalidate_cached_session(wpa_s->eapol);
156 old_ssid = wpa_s->current_ssid;
157 wpa_s->current_ssid = ssid;
159 wpa_supplicant_update_current_bss(wpa_s);
161 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
162 wpa_supplicant_initiate_eapol(wpa_s);
163 if (old_ssid != wpa_s->current_ssid)
164 wpas_notify_network_changed(wpa_s);
170 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
172 struct wpa_supplicant *wpa_s = eloop_ctx;
174 if (wpa_s->countermeasures) {
175 wpa_s->countermeasures = 0;
176 wpa_drv_set_countermeasures(wpa_s, 0);
177 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
180 * It is possible that the device is sched scanning, which means
181 * that a connection attempt will be done only when we receive
182 * scan results. However, in this case, it would be preferable
183 * to scan and connect immediately, so cancel the sched_scan and
184 * issue a regular scan flow.
186 wpa_supplicant_cancel_sched_scan(wpa_s);
187 wpa_supplicant_req_scan(wpa_s, 0, 0);
192 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
196 wnm_bss_keep_alive_deinit(wpa_s);
198 #ifdef CONFIG_IBSS_RSN
199 ibss_rsn_deinit(wpa_s->ibss_rsn);
200 wpa_s->ibss_rsn = NULL;
201 #endif /* CONFIG_IBSS_RSN */
204 wpa_supplicant_ap_deinit(wpa_s);
205 #endif /* CONFIG_AP */
207 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
210 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
211 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
212 os_memset(wpa_s->bssid, 0, ETH_ALEN);
213 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
214 sme_clear_on_disassoc(wpa_s);
216 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
217 #endif /* CONFIG_P2P */
218 wpa_s->current_bss = NULL;
219 wpa_s->assoc_freq = 0;
222 wpas_notify_bssid_changed(wpa_s);
224 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
225 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
226 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
227 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
228 wpa_s->ap_ies_from_associnfo = 0;
229 wpa_s->current_ssid = NULL;
230 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
233 wpas_rrm_reset(wpa_s);
237 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
239 struct wpa_ie_data ie;
243 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
247 for (i = 0; i < ie.num_pmkid; i++) {
248 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
249 ie.pmkid + i * PMKID_LEN,
251 if (pmksa_set == 0) {
252 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
257 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
258 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
262 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
263 union wpa_event_data *data)
266 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
270 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
271 " index=%d preauth=%d",
272 MAC2STR(data->pmkid_candidate.bssid),
273 data->pmkid_candidate.index,
274 data->pmkid_candidate.preauth);
276 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
277 data->pmkid_candidate.index,
278 data->pmkid_candidate.preauth);
282 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
284 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
285 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
288 #ifdef IEEE8021X_EAPOL
289 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
290 wpa_s->current_ssid &&
291 !(wpa_s->current_ssid->eapol_flags &
292 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
293 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
294 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
295 * plaintext or static WEP keys). */
298 #endif /* IEEE8021X_EAPOL */
305 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
306 * @wpa_s: pointer to wpa_supplicant data
307 * @ssid: Configuration data for the network
308 * Returns: 0 on success, -1 on failure
310 * This function is called when starting authentication with a network that is
311 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
313 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
314 struct wpa_ssid *ssid)
316 #ifdef IEEE8021X_EAPOL
318 int aka = 0, sim = 0;
320 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
321 wpa_s->scard != NULL || wpa_s->conf->external_sim)
324 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
328 struct eap_method_type *eap = ssid->eap.eap_methods;
329 while (eap->vendor != EAP_VENDOR_IETF ||
330 eap->method != EAP_TYPE_NONE) {
331 if (eap->vendor == EAP_VENDOR_IETF) {
332 if (eap->method == EAP_TYPE_SIM)
334 else if (eap->method == EAP_TYPE_AKA ||
335 eap->method == EAP_TYPE_AKA_PRIME)
342 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
344 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
345 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
350 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
351 "use SIM, but neither EAP-SIM nor EAP-AKA are "
356 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
357 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
359 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
360 if (wpa_s->scard == NULL) {
361 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
365 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
366 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
367 #endif /* PCSC_FUNCS */
368 #endif /* IEEE8021X_EAPOL */
374 #ifndef CONFIG_NO_SCAN_PROCESSING
376 static int has_wep_key(struct wpa_ssid *ssid)
380 for (i = 0; i < NUM_WEP_KEYS; i++) {
381 if (ssid->wep_key_len[i])
389 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
390 struct wpa_ssid *ssid)
394 if (ssid->mixed_cell)
398 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
400 #endif /* CONFIG_WPS */
402 if (has_wep_key(ssid))
405 #ifdef IEEE8021X_EAPOL
406 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
407 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
408 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
410 #endif /* IEEE8021X_EAPOL */
412 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
415 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
418 if (bss->caps & IEEE80211_CAP_PRIVACY)
424 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
425 struct wpa_ssid *ssid,
428 struct wpa_ie_data ie;
430 const u8 *rsn_ie, *wpa_ie;
434 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
438 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
439 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
440 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
441 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
442 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
444 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
445 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
448 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
449 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
455 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
457 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
462 if (!(ie.proto & ssid->proto)) {
463 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
468 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
469 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
474 if (!(ie.group_cipher & ssid->group_cipher)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
480 if (!(ie.key_mgmt & ssid->key_mgmt)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
486 #ifdef CONFIG_IEEE80211W
487 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
488 wpas_get_ssid_pmf(wpa_s, ssid) ==
489 MGMT_FRAME_PROTECTION_REQUIRED) {
490 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
494 #endif /* CONFIG_IEEE80211W */
496 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
500 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
501 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
504 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
505 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
511 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
513 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
518 if (!(ie.proto & ssid->proto)) {
519 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
524 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
525 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
530 if (!(ie.group_cipher & ssid->group_cipher)) {
531 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
536 if (!(ie.key_mgmt & ssid->key_mgmt)) {
537 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
542 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
546 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
548 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
552 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
553 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
554 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
558 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
559 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
560 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
564 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
565 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
569 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
576 static int freq_allowed(int *freqs, int freq)
583 for (i = 0; freqs[i]; i++)
584 if (freqs[i] == freq)
590 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
592 const struct hostapd_hw_modes *mode = NULL, *modes;
593 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
598 return 1; /* Cannot do matching without knowing band */
600 modes = wpa_s->hw.modes;
603 * The driver does not provide any additional information
604 * about the utilized hardware, so allow the connection attempt
610 for (i = 0; i < wpa_s->hw.num_modes; i++) {
611 for (j = 0; j < modes[i].num_channels; j++) {
612 int freq = modes[i].channels[j].freq;
613 if (freq == bss->freq) {
615 mode->mode == HOSTAPD_MODE_IEEE80211G)
616 break; /* do not allow 802.11b replace
627 for (i = 0; i < (int) sizeof(scan_ie); i++) {
628 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
632 for (j = 2; j < rate_ie[1] + 2; j++) {
633 int flagged = !!(rate_ie[j] & 0x80);
634 int r = (rate_ie[j] & 0x7f) * 5;
637 * IEEE Std 802.11n-2009 7.3.2.2:
638 * The new BSS Membership selector value is encoded
639 * like a legacy basic rate, but it is not a rate and
640 * only indicates if the BSS members are required to
641 * support the mandatory features of Clause 20 [HT PHY]
642 * in order to join the BSS.
644 if (flagged && ((rate_ie[j] & 0x7f) ==
645 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
646 if (!ht_supported(mode)) {
647 wpa_dbg(wpa_s, MSG_DEBUG,
648 " hardware does not support "
655 /* There's also a VHT selector for 802.11ac */
656 if (flagged && ((rate_ie[j] & 0x7f) ==
657 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
658 if (!vht_supported(mode)) {
659 wpa_dbg(wpa_s, MSG_DEBUG,
660 " hardware does not support "
670 /* check for legacy basic rates */
671 for (k = 0; k < mode->num_rates; k++) {
672 if (mode->rates[k] == r)
675 if (k == mode->num_rates) {
677 * IEEE Std 802.11-2007 7.3.2.2 demands that in
678 * order to join a BSS all required rates
679 * have to be supported by the hardware.
681 wpa_dbg(wpa_s, MSG_DEBUG,
682 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
684 bss->freq, mode->mode, mode->num_rates);
695 * Test whether BSS is in an ESS.
696 * This is done differently in DMG (60 GHz) and non-DMG bands
698 static int bss_is_ess(struct wpa_bss *bss)
700 if (bss_is_dmg(bss)) {
701 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
702 IEEE80211_CAP_DMG_AP;
705 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
710 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
714 for (i = 0; i < ETH_ALEN; i++) {
715 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
722 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
726 for (i = 0; i < num; i++) {
727 const u8 *a = list + i * ETH_ALEN * 2;
728 const u8 *m = a + ETH_ALEN;
730 if (match_mac_mask(a, addr, m))
737 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
738 int i, struct wpa_bss *bss,
739 struct wpa_ssid *group,
742 u8 wpa_ie_len, rsn_ie_len;
744 struct wpa_blacklist *e;
746 struct wpa_ssid *ssid;
749 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
750 wpa_ie_len = ie ? ie[1] : 0;
752 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
753 rsn_ie_len = ie ? ie[1] : 0;
755 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
758 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
759 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
760 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
761 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
762 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
763 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
764 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
766 osen ? " osen=1" : "");
768 e = wpa_blacklist_get(wpa_s, bss->bssid);
771 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
773 * When only a single network is enabled, we can
774 * trigger blacklisting on the first failure. This
775 * should not be done with multiple enabled networks to
776 * avoid getting forced to move into a worse ESS on
777 * single error if there are no other BSSes of the
782 if (e->count > limit) {
783 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
784 "(count=%d limit=%d)", e->count, limit);
789 if (bss->ssid_len == 0) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
794 if (disallowed_bssid(wpa_s, bss->bssid)) {
795 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
799 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
800 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
804 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
806 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
807 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
810 if (wpas_network_disabled(wpa_s, ssid)) {
811 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
815 res = wpas_temp_disabled(wpa_s, ssid);
817 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
818 "temporarily for %d second(s)", res);
823 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
824 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
829 if (wpa && ssid->ssid_len == 0 &&
830 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
833 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
834 /* Only allow wildcard SSID match if an AP
835 * advertises active WPS operation that matches
838 if (ssid->ssid_len == 0 &&
839 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
842 #endif /* CONFIG_WPS */
844 if (ssid->bssid_set && ssid->ssid_len == 0 &&
845 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
849 (bss->ssid_len != ssid->ssid_len ||
850 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
851 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
855 if (ssid->bssid_set &&
856 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
857 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
861 /* check blacklist */
862 if (ssid->num_bssid_blacklist &&
863 addr_in_list(bss->bssid, ssid->bssid_blacklist,
864 ssid->num_bssid_blacklist)) {
865 wpa_dbg(wpa_s, MSG_DEBUG,
866 " skip - BSSID blacklisted");
870 /* if there is a whitelist, only accept those APs */
871 if (ssid->num_bssid_whitelist &&
872 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
873 ssid->num_bssid_whitelist)) {
874 wpa_dbg(wpa_s, MSG_DEBUG,
875 " skip - BSSID not in whitelist");
879 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
883 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
884 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
885 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
886 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
891 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
893 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
897 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
898 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
903 if (!wpa_supplicant_match_privacy(bss, ssid)) {
904 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
909 if (!bss_is_ess(bss)) {
910 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
914 if (!freq_allowed(ssid->freq_list, bss->freq)) {
915 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
920 if (!rate_match(wpa_s, bss)) {
921 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
927 if (ssid->p2p_group &&
928 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
929 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
934 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
935 struct wpabuf *p2p_ie;
936 u8 dev_addr[ETH_ALEN];
938 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
940 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
943 p2p_ie = wpa_bss_get_vendor_ie_multi(
944 bss, P2P_IE_VENDOR_TYPE);
945 if (p2p_ie == NULL) {
946 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
950 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
951 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
953 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
961 * TODO: skip the AP if its P2P IE has Group Formation
962 * bit set in the P2P Group Capability Bitmap and we
963 * are not in Group Formation with that device.
965 #endif /* CONFIG_P2P */
967 /* Matching configuration found */
971 /* No matching configuration found */
976 static struct wpa_bss *
977 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
978 struct wpa_ssid *group,
979 struct wpa_ssid **selected_ssid,
985 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
988 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
991 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
992 struct wpa_bss *bss = wpa_s->last_scan_res[i];
993 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
997 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1000 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1008 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1009 struct wpa_ssid **selected_ssid)
1011 struct wpa_bss *selected = NULL;
1013 struct wpa_ssid *next_ssid = NULL;
1015 if (wpa_s->last_scan_res == NULL ||
1016 wpa_s->last_scan_res_used == 0)
1017 return NULL; /* no scan results from last update */
1019 if (wpa_s->next_ssid) {
1020 struct wpa_ssid *ssid;
1022 /* check that next_ssid is still valid */
1023 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1024 if (ssid == wpa_s->next_ssid)
1028 wpa_s->next_ssid = NULL;
1031 while (selected == NULL) {
1032 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1033 if (next_ssid && next_ssid->priority ==
1034 wpa_s->conf->pssid[prio]->priority) {
1035 selected = wpa_supplicant_select_bss(
1036 wpa_s, next_ssid, selected_ssid, 1);
1040 selected = wpa_supplicant_select_bss(
1041 wpa_s, wpa_s->conf->pssid[prio],
1047 if (selected == NULL && wpa_s->blacklist &&
1048 !wpa_s->countermeasures) {
1049 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1050 "blacklist and try again");
1051 wpa_blacklist_clear(wpa_s);
1052 wpa_s->blacklist_cleared++;
1053 } else if (selected == NULL)
1061 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1062 int timeout_sec, int timeout_usec)
1064 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1066 * No networks are enabled; short-circuit request so
1067 * we don't wait timeout seconds before transitioning
1068 * to INACTIVE state.
1070 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1071 "since there are no enabled networks");
1072 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1076 wpa_s->scan_for_connection = 1;
1077 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1081 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1082 struct wpa_bss *selected,
1083 struct wpa_ssid *ssid)
1085 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1086 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1087 "PBC session overlap");
1089 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1090 wpa_s->p2p_in_provisioning) {
1091 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1095 #endif /* CONFIG_P2P */
1098 wpas_wps_cancel(wpa_s);
1099 #endif /* CONFIG_WPS */
1103 wpa_msg(wpa_s, MSG_DEBUG,
1104 "Considering connect request: reassociate: %d selected: "
1105 MACSTR " bssid: " MACSTR " pending: " MACSTR
1106 " wpa_state: %s ssid=%p current_ssid=%p",
1107 wpa_s->reassociate, MAC2STR(selected->bssid),
1108 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1109 wpa_supplicant_state_txt(wpa_s->wpa_state),
1110 ssid, wpa_s->current_ssid);
1113 * Do not trigger new association unless the BSSID has changed or if
1114 * reassociation is requested. If we are in process of associating with
1115 * the selected BSSID, do not trigger new attempt.
1117 if (wpa_s->reassociate ||
1118 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1119 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1120 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1121 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1122 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1124 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1125 ssid != wpa_s->current_ssid)))) {
1126 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1127 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1130 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1131 MAC2STR(selected->bssid));
1132 wpa_supplicant_associate(wpa_s, selected, ssid);
1134 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1135 "connect with the selected AP");
1142 static struct wpa_ssid *
1143 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1146 struct wpa_ssid *ssid;
1148 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1149 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1151 if (wpas_network_disabled(wpa_s, ssid))
1153 if (ssid->mode == IEEE80211_MODE_IBSS ||
1154 ssid->mode == IEEE80211_MODE_AP ||
1155 ssid->mode == IEEE80211_MODE_MESH)
1163 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1164 * on BSS added and BSS changed events */
1165 static void wpa_supplicant_rsn_preauth_scan_results(
1166 struct wpa_supplicant *wpa_s)
1168 struct wpa_bss *bss;
1170 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1173 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1174 const u8 *ssid, *rsn;
1176 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1180 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1184 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1190 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1191 struct wpa_bss *selected,
1192 struct wpa_ssid *ssid)
1194 struct wpa_bss *current_bss = NULL;
1197 if (wpa_s->reassociate)
1198 return 1; /* explicit request to reassociate */
1199 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1200 return 1; /* we are not associated; continue */
1201 if (wpa_s->current_ssid == NULL)
1202 return 1; /* unknown current SSID */
1203 if (wpa_s->current_ssid != ssid)
1204 return 1; /* different network block */
1206 if (wpas_driver_bss_selection(wpa_s))
1207 return 0; /* Driver-based roaming */
1209 if (wpa_s->current_ssid->ssid)
1210 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1211 wpa_s->current_ssid->ssid,
1212 wpa_s->current_ssid->ssid_len);
1214 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1217 return 1; /* current BSS not seen in scan results */
1219 if (current_bss == selected)
1222 if (selected->last_update_idx > current_bss->last_update_idx)
1223 return 1; /* current BSS not seen in the last scan */
1225 #ifndef CONFIG_NO_ROAMING
1226 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1227 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1228 " level=%d snr=%d est_throughput=%u",
1229 MAC2STR(current_bss->bssid), current_bss->level,
1230 current_bss->snr, current_bss->est_throughput);
1231 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1232 " level=%d snr=%d est_throughput=%u",
1233 MAC2STR(selected->bssid), selected->level,
1234 selected->snr, selected->est_throughput);
1236 if (wpa_s->current_ssid->bssid_set &&
1237 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1239 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1240 "has preferred BSSID");
1244 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1245 wpa_dbg(wpa_s, MSG_DEBUG,
1246 "Allow reassociation - selected BSS has better estimated throughput");
1250 if (current_bss->level < 0 && current_bss->level > selected->level) {
1251 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1257 if (current_bss->level < 0) {
1258 if (current_bss->level < -85)
1260 else if (current_bss->level < -80)
1262 else if (current_bss->level < -75)
1264 else if (current_bss->level < -70)
1269 if (abs(current_bss->level - selected->level) < min_diff) {
1270 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1276 #else /* CONFIG_NO_ROAMING */
1278 #endif /* CONFIG_NO_ROAMING */
1282 /* Return != 0 if no scan results could be fetched or if scan results should not
1283 * be shared with other virtual interfaces. */
1284 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1285 union wpa_event_data *data,
1288 struct wpa_scan_results *scan_res = NULL;
1291 #ifndef CONFIG_NO_RANDOM_POOL
1293 #endif /* CONFIG_NO_RANDOM_POOL */
1296 if (wpa_s->ap_iface)
1298 #endif /* CONFIG_AP */
1300 wpa_supplicant_notify_scanning(wpa_s, 0);
1302 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1303 data ? &data->scan_info :
1305 if (scan_res == NULL) {
1306 if (wpa_s->conf->ap_scan == 2 || ap ||
1307 wpa_s->scan_res_handler == scan_only_handler)
1311 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1313 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1315 goto scan_work_done;
1318 #ifndef CONFIG_NO_RANDOM_POOL
1319 num = scan_res->num;
1322 for (i = 0; i < num; i++) {
1324 struct wpa_scan_res *res = scan_res->res[i];
1325 buf[0] = res->bssid[5];
1326 buf[1] = res->qual & 0xff;
1327 buf[2] = res->noise & 0xff;
1328 buf[3] = res->level & 0xff;
1329 buf[4] = res->tsf & 0xff;
1330 random_add_randomness(buf, sizeof(buf));
1332 #endif /* CONFIG_NO_RANDOM_POOL */
1334 if (own_request && wpa_s->scan_res_handler &&
1335 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1336 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1337 struct wpa_scan_results *scan_res);
1339 scan_res_handler = wpa_s->scan_res_handler;
1340 wpa_s->scan_res_handler = NULL;
1341 scan_res_handler(wpa_s, scan_res);
1343 goto scan_work_done;
1347 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1349 if (wpa_s->ap_iface->scan_cb)
1350 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1351 #endif /* CONFIG_AP */
1352 goto scan_work_done;
1355 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1356 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1357 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1358 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1359 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1360 wpa_s->manual_scan_id);
1361 wpa_s->manual_scan_use_id = 0;
1363 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1365 wpas_notify_scan_results(wpa_s);
1367 wpas_notify_scan_done(wpa_s, 1);
1369 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1370 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1371 wpa_scan_results_free(scan_res);
1375 if (wnm_scan_process(wpa_s, 1) > 0)
1376 goto scan_work_done;
1378 if (sme_proc_obss_scan(wpa_s) > 0)
1379 goto scan_work_done;
1381 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1382 goto scan_work_done;
1384 if (autoscan_notify_scan(wpa_s, scan_res))
1385 goto scan_work_done;
1387 if (wpa_s->disconnected) {
1388 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1389 goto scan_work_done;
1392 if (!wpas_driver_bss_selection(wpa_s) &&
1393 bgscan_notify_scan(wpa_s, scan_res) == 1)
1394 goto scan_work_done;
1396 wpas_wps_update_ap_info(wpa_s, scan_res);
1398 wpa_scan_results_free(scan_res);
1400 if (wpa_s->scan_work) {
1401 struct wpa_radio_work *work = wpa_s->scan_work;
1402 wpa_s->scan_work = NULL;
1403 radio_work_done(work);
1406 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1409 wpa_scan_results_free(scan_res);
1410 if (wpa_s->scan_work) {
1411 struct wpa_radio_work *work = wpa_s->scan_work;
1412 wpa_s->scan_work = NULL;
1413 radio_work_done(work);
1419 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1420 int new_scan, int own_request)
1422 struct wpa_bss *selected;
1423 struct wpa_ssid *ssid = NULL;
1425 if (wpa_s->p2p_mgmt)
1426 return 0; /* no normal connection on p2p_mgmt interface */
1428 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1432 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1435 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1439 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1440 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1444 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1446 * Do not notify other virtual radios of scan results since we do not
1447 * want them to start other associations at the same time.
1453 wpa_msg(wpa_s, MSG_INFO,
1454 "Avoiding join because we already joined a mesh group");
1457 #endif /* CONFIG_MESH */
1458 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1459 ssid = wpa_supplicant_pick_new_network(wpa_s);
1461 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1462 wpa_supplicant_associate(wpa_s, NULL, ssid);
1464 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1465 } else if (own_request) {
1467 * No SSID found. If SCAN results are as a result of
1468 * own scan request and not due to a scan request on
1469 * another shared interface, try another scan.
1471 int timeout_sec = wpa_s->scan_interval;
1472 int timeout_usec = 0;
1476 res = wpas_p2p_scan_no_go_seen(wpa_s);
1482 if (wpa_s->p2p_in_provisioning ||
1483 wpa_s->show_group_started ||
1484 wpa_s->p2p_in_invitation) {
1486 * Use shorter wait during P2P Provisioning
1487 * state and during P2P join-a-group operation
1488 * to speed up group formation.
1491 timeout_usec = 250000;
1492 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1496 #endif /* CONFIG_P2P */
1497 #ifdef CONFIG_INTERWORKING
1498 if (wpa_s->conf->auto_interworking &&
1499 wpa_s->conf->interworking &&
1500 wpa_s->conf->cred) {
1501 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1502 "start ANQP fetch since no matching "
1504 wpa_s->network_select = 1;
1505 wpa_s->auto_network_select = 1;
1506 interworking_start_fetch_anqp(wpa_s);
1509 #endif /* CONFIG_INTERWORKING */
1511 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1512 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1514 timeout_usec = 500000;
1515 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1519 #endif /* CONFIG_WPS */
1520 if (wpa_supplicant_req_sched_scan(wpa_s))
1521 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1529 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1530 union wpa_event_data *data)
1532 struct wpa_supplicant *ifs;
1535 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1538 * Interface may have been removed, so must not dereference
1545 * If no scan results could be fetched, then no need to
1546 * notify those interfaces that did not actually request
1547 * this scan. Similarly, if scan results started a new operation on this
1548 * interface, do not notify other interfaces to avoid concurrent
1549 * operations during a connection attempt.
1555 * Check other interfaces to see if they share the same radio. If
1556 * so, they get updated with this same scan info.
1558 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1561 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1562 "sibling", ifs->ifname);
1563 _wpa_supplicant_event_scan_results(ifs, data, 0);
1570 #endif /* CONFIG_NO_SCAN_PROCESSING */
1573 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1575 #ifdef CONFIG_NO_SCAN_PROCESSING
1577 #else /* CONFIG_NO_SCAN_PROCESSING */
1578 struct os_reltime now;
1580 if (wpa_s->last_scan_res_used <= 0)
1583 os_get_reltime(&now);
1584 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1585 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1589 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1590 #endif /* CONFIG_NO_SCAN_PROCESSING */
1595 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1597 struct wpa_supplicant *wpa_s = eloop_ctx;
1599 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1602 if (!wpa_s->no_keep_alive) {
1603 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1604 MAC2STR(wpa_s->bssid));
1605 /* TODO: could skip this if normal data traffic has been sent */
1606 /* TODO: Consider using some more appropriate data frame for
1609 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1614 if (wpa_s->sme.bss_max_idle_period) {
1616 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1619 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1620 wnm_bss_keep_alive, wpa_s, NULL);
1622 #endif /* CONFIG_SME */
1626 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1627 const u8 *ies, size_t ies_len)
1629 struct ieee802_11_elems elems;
1634 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1638 if (elems.bss_max_idle_period) {
1640 wpa_s->sme.bss_max_idle_period =
1641 WPA_GET_LE16(elems.bss_max_idle_period);
1642 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1643 "TU)%s", wpa_s->sme.bss_max_idle_period,
1644 (elems.bss_max_idle_period[2] & 0x01) ?
1645 " (protected keep-live required)" : "");
1646 if (wpa_s->sme.bss_max_idle_period == 0)
1647 wpa_s->sme.bss_max_idle_period = 1;
1648 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1649 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1650 /* msec times 1000 */
1651 msec = wpa_s->sme.bss_max_idle_period * 1024;
1654 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1655 wnm_bss_keep_alive, wpa_s,
1659 #endif /* CONFIG_SME */
1662 #endif /* CONFIG_WNM */
1665 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1668 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1669 #endif /* CONFIG_WNM */
1673 #ifdef CONFIG_INTERWORKING
1675 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1680 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1681 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1683 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1690 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1691 const u8 *ies, size_t ies_len)
1693 struct ieee802_11_elems elems;
1698 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1701 if (elems.qos_map_set) {
1702 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1703 elems.qos_map_set_len);
1707 #endif /* CONFIG_INTERWORKING */
1710 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1711 union wpa_event_data *data)
1713 int l, len, found = 0, wpa_found, rsn_found;
1715 #ifdef CONFIG_IEEE80211R
1717 #endif /* CONFIG_IEEE80211R */
1719 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1720 if (data->assoc_info.req_ies)
1721 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1722 data->assoc_info.req_ies_len);
1723 if (data->assoc_info.resp_ies) {
1724 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1725 data->assoc_info.resp_ies_len);
1727 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1728 data->assoc_info.resp_ies_len);
1729 #endif /* CONFIG_TDLS */
1731 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1732 data->assoc_info.resp_ies_len);
1733 #endif /* CONFIG_WNM */
1734 #ifdef CONFIG_INTERWORKING
1735 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1736 data->assoc_info.resp_ies_len);
1737 #endif /* CONFIG_INTERWORKING */
1739 if (data->assoc_info.beacon_ies)
1740 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1741 data->assoc_info.beacon_ies,
1742 data->assoc_info.beacon_ies_len);
1743 if (data->assoc_info.freq)
1744 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1745 data->assoc_info.freq);
1747 p = data->assoc_info.req_ies;
1748 l = data->assoc_info.req_ies_len;
1750 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1751 while (p && l >= 2) {
1754 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1758 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1759 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1760 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1761 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1764 wpa_find_assoc_pmkid(wpa_s);
1770 if (!found && data->assoc_info.req_ies)
1771 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1773 #ifdef CONFIG_IEEE80211R
1775 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1776 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1777 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1778 data->assoc_info.resp_ies,
1779 data->assoc_info.resp_ies_len,
1781 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1782 "Reassociation Response failed");
1783 wpa_supplicant_deauthenticate(
1784 wpa_s, WLAN_REASON_INVALID_IE);
1789 p = data->assoc_info.resp_ies;
1790 l = data->assoc_info.resp_ies_len;
1792 #ifdef CONFIG_WPS_STRICT
1793 if (p && wpa_s->current_ssid &&
1794 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1796 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1798 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1799 "include WPS IE in (Re)Association Response");
1803 if (wps_validate_assoc_resp(wps) < 0) {
1805 wpa_supplicant_deauthenticate(
1806 wpa_s, WLAN_REASON_INVALID_IE);
1811 #endif /* CONFIG_WPS_STRICT */
1813 /* Go through the IEs and make a copy of the MDIE, if present. */
1814 while (p && l >= 2) {
1817 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1821 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1822 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1823 wpa_s->sme.ft_used = 1;
1824 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1825 MOBILITY_DOMAIN_ID_LEN);
1831 #endif /* CONFIG_SME */
1833 /* Process FT when SME is in the driver */
1834 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1835 wpa_ft_is_completed(wpa_s->wpa)) {
1836 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1837 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1838 data->assoc_info.resp_ies,
1839 data->assoc_info.resp_ies_len,
1841 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1842 "Reassociation Response failed");
1843 wpa_supplicant_deauthenticate(
1844 wpa_s, WLAN_REASON_INVALID_IE);
1847 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1850 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1851 data->assoc_info.resp_ies_len);
1852 #endif /* CONFIG_IEEE80211R */
1854 /* WPA/RSN IE from Beacon/ProbeResp */
1855 p = data->assoc_info.beacon_ies;
1856 l = data->assoc_info.beacon_ies_len;
1858 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1860 wpa_found = rsn_found = 0;
1861 while (p && l >= 2) {
1864 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1869 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1870 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1872 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1876 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1878 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1885 if (!wpa_found && data->assoc_info.beacon_ies)
1886 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1887 if (!rsn_found && data->assoc_info.beacon_ies)
1888 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1889 if (wpa_found || rsn_found)
1890 wpa_s->ap_ies_from_associnfo = 1;
1892 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1893 wpa_s->assoc_freq != data->assoc_info.freq) {
1894 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1896 wpa_s->assoc_freq, data->assoc_info.freq);
1897 wpa_supplicant_update_scan_results(wpa_s);
1900 wpa_s->assoc_freq = data->assoc_info.freq;
1906 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1908 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1910 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1913 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1916 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1917 WPA_IE_VENDOR_TYPE);
1918 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1920 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1921 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1922 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1923 bss_rsn ? 2 + bss_rsn[1] : 0))
1930 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1931 union wpa_event_data *data)
1937 if (wpa_s->ap_iface) {
1940 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1941 data->assoc_info.addr,
1942 data->assoc_info.req_ies,
1943 data->assoc_info.req_ies_len,
1944 data->assoc_info.reassoc);
1947 #endif /* CONFIG_AP */
1949 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1950 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1953 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1954 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1955 wpa_supplicant_deauthenticate(
1956 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1960 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1961 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1962 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1963 MACSTR, MAC2STR(bssid));
1964 random_add_randomness(bssid, ETH_ALEN);
1965 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1966 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1967 wpas_notify_bssid_changed(wpa_s);
1969 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1970 wpa_clear_keys(wpa_s, bssid);
1972 if (wpa_supplicant_select_config(wpa_s) < 0) {
1973 wpa_supplicant_deauthenticate(
1974 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1978 if (wpa_s->conf->ap_scan == 1 &&
1979 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1980 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1981 wpa_msg(wpa_s, MSG_WARNING,
1982 "WPA/RSN IEs not updated");
1987 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1988 wpa_s->sme.prev_bssid_set = 1;
1989 wpa_s->sme.last_unprot_disconnect.sec = 0;
1990 #endif /* CONFIG_SME */
1992 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1993 if (wpa_s->current_ssid) {
1994 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1995 * initialized before association, but for other modes,
1996 * initialize PC/SC here, if the current configuration needs
1997 * smartcard or SIM/USIM. */
1998 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2000 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2002 l2_packet_notify_auth_start(wpa_s->l2);
2005 * Set portEnabled first to FALSE in order to get EAP state machine out
2006 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2007 * state machine may transit to AUTHENTICATING state based on obsolete
2008 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2009 * AUTHENTICATED without ever giving chance to EAP state machine to
2012 if (!ft_completed) {
2013 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2014 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2016 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2017 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2018 /* 802.1X::portControl = Auto */
2019 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2020 wpa_s->eapol_received = 0;
2021 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2022 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2023 (wpa_s->current_ssid &&
2024 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2025 if (wpa_s->current_ssid &&
2026 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2028 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2030 * Set the key after having received joined-IBSS event
2033 wpa_supplicant_set_wpa_none_key(wpa_s,
2034 wpa_s->current_ssid);
2036 wpa_supplicant_cancel_auth_timeout(wpa_s);
2037 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2038 } else if (!ft_completed) {
2039 /* Timeout for receiving the first EAPOL packet */
2040 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2042 wpa_supplicant_cancel_scan(wpa_s);
2044 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2045 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2047 * We are done; the driver will take care of RSN 4-way
2050 wpa_supplicant_cancel_auth_timeout(wpa_s);
2051 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2052 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2053 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2054 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2055 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2057 * The driver will take care of RSN 4-way handshake, so we need
2058 * to allow EAPOL supplicant to complete its work without
2059 * waiting for WPA supplicant.
2061 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2062 } else if (ft_completed) {
2064 * FT protocol completed - make sure EAPOL state machine ends
2065 * up in authenticated.
2067 wpa_supplicant_cancel_auth_timeout(wpa_s);
2068 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2069 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2070 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2073 wpa_s->last_eapol_matches_bssid = 0;
2075 if (wpa_s->pending_eapol_rx) {
2076 struct os_reltime now, age;
2077 os_get_reltime(&now);
2078 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2079 if (age.sec == 0 && age.usec < 100000 &&
2080 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2082 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2083 "frame that was received just before "
2084 "association notification");
2085 wpa_supplicant_rx_eapol(
2086 wpa_s, wpa_s->pending_eapol_rx_src,
2087 wpabuf_head(wpa_s->pending_eapol_rx),
2088 wpabuf_len(wpa_s->pending_eapol_rx));
2090 wpabuf_free(wpa_s->pending_eapol_rx);
2091 wpa_s->pending_eapol_rx = NULL;
2094 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2095 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2096 wpa_s->current_ssid &&
2097 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2098 /* Set static WEP keys again */
2099 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2102 #ifdef CONFIG_IBSS_RSN
2103 if (wpa_s->current_ssid &&
2104 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2105 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2106 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2107 wpa_s->ibss_rsn == NULL) {
2108 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2109 if (!wpa_s->ibss_rsn) {
2110 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2111 wpa_supplicant_deauthenticate(
2112 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2116 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2118 #endif /* CONFIG_IBSS_RSN */
2120 wpas_wps_notify_assoc(wpa_s, bssid);
2123 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2124 data->assoc_info.resp_ies_len,
2125 &data->assoc_info.wmm_params);
2127 if (wpa_s->reassoc_same_bss)
2128 wmm_ac_restore_tspecs(wpa_s);
2133 static int disconnect_reason_recoverable(u16 reason_code)
2135 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2136 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2137 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2141 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2143 int locally_generated)
2147 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2149 * At least Host AP driver and a Prism3 card seemed to be
2150 * generating streams of disconnected events when configuring
2151 * IBSS for WPA-None. Ignore them for now.
2156 bssid = wpa_s->bssid;
2157 if (is_zero_ether_addr(bssid))
2158 bssid = wpa_s->pending_bssid;
2160 if (!is_zero_ether_addr(bssid) ||
2161 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2162 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2164 MAC2STR(bssid), reason_code,
2165 locally_generated ? " locally_generated=1" : "");
2170 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2171 int locally_generated)
2173 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2174 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2175 return 0; /* Not in 4-way handshake with PSK */
2178 * It looks like connection was lost while trying to go through PSK
2179 * 4-way handshake. Filter out known disconnection cases that are caused
2180 * by something else than PSK mismatch to avoid confusing reports.
2183 if (locally_generated) {
2184 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2192 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2194 int locally_generated)
2198 u8 prev_pending_bssid[ETH_ALEN];
2199 struct wpa_bss *fast_reconnect = NULL;
2200 struct wpa_ssid *fast_reconnect_ssid = NULL;
2201 struct wpa_ssid *last_ssid;
2203 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2204 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2206 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2208 * At least Host AP driver and a Prism3 card seemed to be
2209 * generating streams of disconnected events when configuring
2210 * IBSS for WPA-None. Ignore them for now.
2212 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2213 "IBSS/WPA-None mode");
2217 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2218 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2219 "pre-shared key may be incorrect");
2220 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2221 return; /* P2P group removed */
2222 wpas_auth_failed(wpa_s, "WRONG_KEY");
2224 if (!wpa_s->disconnected &&
2225 (!wpa_s->auto_reconnect_disabled ||
2226 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2227 wpas_wps_searching(wpa_s))) {
2228 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2229 "reconnect (wps=%d/%d wpa_state=%d)",
2230 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2231 wpas_wps_searching(wpa_s),
2233 if (wpa_s->wpa_state == WPA_COMPLETED &&
2234 wpa_s->current_ssid &&
2235 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2236 !locally_generated &&
2237 disconnect_reason_recoverable(reason_code)) {
2239 * It looks like the AP has dropped association with
2240 * us, but could allow us to get back in. Try to
2241 * reconnect to the same BSS without full scan to save
2242 * time for some common cases.
2244 fast_reconnect = wpa_s->current_bss;
2245 fast_reconnect_ssid = wpa_s->current_ssid;
2246 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2247 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2249 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2252 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2253 "try to re-connect");
2254 wpa_s->reassociate = 0;
2255 wpa_s->disconnected = 1;
2256 wpa_supplicant_cancel_sched_scan(wpa_s);
2258 bssid = wpa_s->bssid;
2259 if (is_zero_ether_addr(bssid))
2260 bssid = wpa_s->pending_bssid;
2261 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2262 wpas_connection_failed(wpa_s, bssid);
2263 wpa_sm_notify_disassoc(wpa_s->wpa);
2264 if (locally_generated)
2265 wpa_s->disconnect_reason = -reason_code;
2267 wpa_s->disconnect_reason = reason_code;
2268 wpas_notify_disconnect_reason(wpa_s);
2269 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2270 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2271 wpa_clear_keys(wpa_s, wpa_s->bssid);
2273 last_ssid = wpa_s->current_ssid;
2274 wpa_supplicant_mark_disassoc(wpa_s);
2276 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2277 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2278 wpa_s->current_ssid = last_ssid;
2281 if (fast_reconnect &&
2282 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2283 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2284 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2285 fast_reconnect->ssid_len) &&
2286 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2287 #ifndef CONFIG_NO_SCAN_PROCESSING
2288 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2289 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2290 fast_reconnect_ssid) < 0) {
2291 /* Recover through full scan */
2292 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2294 #endif /* CONFIG_NO_SCAN_PROCESSING */
2295 } else if (fast_reconnect) {
2297 * Could not reconnect to the same BSS due to network being
2298 * disabled. Use a new scan to match the alternative behavior
2299 * above, i.e., to continue automatic reconnection attempt in a
2300 * way that enforces disabled network rules.
2302 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2307 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2308 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2310 struct wpa_supplicant *wpa_s = eloop_ctx;
2312 if (!wpa_s->pending_mic_error_report)
2315 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2316 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2317 wpa_s->pending_mic_error_report = 0;
2319 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2323 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2324 union wpa_event_data *data)
2327 struct os_reltime t;
2329 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2330 pairwise = (data && data->michael_mic_failure.unicast);
2332 if ((wpa_s->last_michael_mic_error.sec &&
2333 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2334 wpa_s->pending_mic_error_report) {
2335 if (wpa_s->pending_mic_error_report) {
2337 * Send the pending MIC error report immediately since
2338 * we are going to start countermeasures and AP better
2341 wpa_sm_key_request(wpa_s->wpa, 1,
2342 wpa_s->pending_mic_error_pairwise);
2345 /* Send the new MIC error report immediately since we are going
2346 * to start countermeasures and AP better do the same.
2348 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2350 /* initialize countermeasures */
2351 wpa_s->countermeasures = 1;
2353 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2355 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2358 * Need to wait for completion of request frame. We do not get
2359 * any callback for the message completion, so just wait a
2360 * short while and hope for the best. */
2363 wpa_drv_set_countermeasures(wpa_s, 1);
2364 wpa_supplicant_deauthenticate(wpa_s,
2365 WLAN_REASON_MICHAEL_MIC_FAILURE);
2366 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2368 eloop_register_timeout(60, 0,
2369 wpa_supplicant_stop_countermeasures,
2371 /* TODO: mark the AP rejected for 60 second. STA is
2372 * allowed to associate with another AP.. */
2374 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2375 if (wpa_s->mic_errors_seen) {
2377 * Reduce the effectiveness of Michael MIC error
2378 * reports as a means for attacking against TKIP if
2379 * more than one MIC failure is noticed with the same
2380 * PTK. We delay the transmission of the reports by a
2381 * random time between 0 and 60 seconds in order to
2382 * force the attacker wait 60 seconds before getting
2383 * the information on whether a frame resulted in a MIC
2389 if (os_get_random(rval, sizeof(rval)) < 0)
2390 sec = os_random() % 60;
2392 sec = WPA_GET_BE32(rval) % 60;
2393 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2394 "report %d seconds", sec);
2395 wpa_s->pending_mic_error_report = 1;
2396 wpa_s->pending_mic_error_pairwise = pairwise;
2397 eloop_cancel_timeout(
2398 wpa_supplicant_delayed_mic_error_report,
2400 eloop_register_timeout(
2401 sec, os_random() % 1000000,
2402 wpa_supplicant_delayed_mic_error_report,
2405 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2407 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2408 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2409 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2411 wpa_s->last_michael_mic_error = t;
2412 wpa_s->mic_errors_seen++;
2416 #ifdef CONFIG_TERMINATE_ONLASTIF
2417 static int any_interfaces(struct wpa_supplicant *head)
2419 struct wpa_supplicant *wpa_s;
2421 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2422 if (!wpa_s->interface_removed)
2426 #endif /* CONFIG_TERMINATE_ONLASTIF */
2430 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2431 union wpa_event_data *data)
2433 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2436 switch (data->interface_status.ievent) {
2437 case EVENT_INTERFACE_ADDED:
2438 if (!wpa_s->interface_removed)
2440 wpa_s->interface_removed = 0;
2441 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2442 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2443 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2444 "driver after interface was added");
2447 case EVENT_INTERFACE_REMOVED:
2448 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2449 wpa_s->interface_removed = 1;
2450 wpa_supplicant_mark_disassoc(wpa_s);
2451 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2452 l2_packet_deinit(wpa_s->l2);
2454 #ifdef CONFIG_TERMINATE_ONLASTIF
2455 /* check if last interface */
2456 if (!any_interfaces(wpa_s->global->ifaces))
2458 #endif /* CONFIG_TERMINATE_ONLASTIF */
2464 #ifdef CONFIG_PEERKEY
2466 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2467 union wpa_event_data *data)
2471 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2473 #endif /* CONFIG_PEERKEY */
2477 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2478 union wpa_event_data *data)
2482 switch (data->tdls.oper) {
2483 case TDLS_REQUEST_SETUP:
2484 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2485 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2486 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2488 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2490 case TDLS_REQUEST_TEARDOWN:
2491 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2492 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2493 data->tdls.reason_code);
2495 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2498 case TDLS_REQUEST_DISCOVER:
2499 wpa_tdls_send_discovery_request(wpa_s->wpa,
2504 #endif /* CONFIG_TDLS */
2508 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2509 union wpa_event_data *data)
2513 switch (data->wnm.oper) {
2514 case WNM_OPER_SLEEP:
2515 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2516 "(action=%d, intval=%d)",
2517 data->wnm.sleep_action, data->wnm.sleep_intval);
2518 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2519 data->wnm.sleep_intval, NULL);
2523 #endif /* CONFIG_WNM */
2526 #ifdef CONFIG_IEEE80211R
2528 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2529 union wpa_event_data *data)
2534 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2535 data->ft_ies.ies_len,
2536 data->ft_ies.ft_action,
2537 data->ft_ies.target_ap,
2538 data->ft_ies.ric_ies,
2539 data->ft_ies.ric_ies_len) < 0) {
2540 /* TODO: prevent MLME/driver from trying to associate? */
2543 #endif /* CONFIG_IEEE80211R */
2546 #ifdef CONFIG_IBSS_RSN
2547 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2548 union wpa_event_data *data)
2550 struct wpa_ssid *ssid;
2551 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2555 ssid = wpa_s->current_ssid;
2558 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2561 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2565 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2566 union wpa_event_data *data)
2568 struct wpa_ssid *ssid = wpa_s->current_ssid;
2573 /* check if the ssid is correctly configured as IBSS/RSN */
2574 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2577 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2578 data->rx_mgmt.frame_len);
2580 #endif /* CONFIG_IBSS_RSN */
2583 #ifdef CONFIG_IEEE80211R
2584 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2587 const u8 *sta_addr, *target_ap_addr;
2590 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2591 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2592 return; /* only SME case supported for now */
2593 if (len < 1 + 2 * ETH_ALEN + 2)
2596 return; /* Only FT Action Response is supported for now */
2597 sta_addr = data + 1;
2598 target_ap_addr = data + 1 + ETH_ALEN;
2599 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2600 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2601 MACSTR " TargetAP " MACSTR " status %u",
2602 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2604 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2605 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2606 " in FT Action Response", MAC2STR(sta_addr));
2611 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2612 "failure (status code %d)", status);
2613 /* TODO: report error to FT code(?) */
2617 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2618 len - (1 + 2 * ETH_ALEN + 2), 1,
2619 target_ap_addr, NULL, 0) < 0)
2624 struct wpa_bss *bss;
2625 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2627 wpa_s->sme.freq = bss->freq;
2628 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2629 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2632 #endif /* CONFIG_SME */
2634 #endif /* CONFIG_IEEE80211R */
2637 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2638 struct unprot_deauth *e)
2640 #ifdef CONFIG_IEEE80211W
2641 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2642 "dropped: " MACSTR " -> " MACSTR
2643 " (reason code %u)",
2644 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2645 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2646 #endif /* CONFIG_IEEE80211W */
2650 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2651 struct unprot_disassoc *e)
2653 #ifdef CONFIG_IEEE80211W
2654 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2655 "dropped: " MACSTR " -> " MACSTR
2656 " (reason code %u)",
2657 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2658 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2659 #endif /* CONFIG_IEEE80211W */
2663 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2664 u16 reason_code, int locally_generated,
2665 const u8 *ie, size_t ie_len, int deauth)
2668 if (wpa_s->ap_iface && addr) {
2669 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2673 if (wpa_s->ap_iface) {
2674 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2677 #endif /* CONFIG_AP */
2679 if (!locally_generated)
2680 wpa_s->own_disconnect_req = 0;
2682 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2684 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2685 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2686 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2687 eapol_sm_failed(wpa_s->eapol))) &&
2688 !wpa_s->eap_expected_failure))
2689 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2692 if (deauth && reason_code > 0) {
2693 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2694 locally_generated) > 0) {
2696 * The interface was removed, so cannot continue
2697 * processing any additional operations after this.
2702 #endif /* CONFIG_P2P */
2704 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2709 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2710 struct disassoc_info *info)
2712 u16 reason_code = 0;
2713 int locally_generated = 0;
2714 const u8 *addr = NULL;
2715 const u8 *ie = NULL;
2718 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2723 ie_len = info->ie_len;
2724 reason_code = info->reason_code;
2725 locally_generated = info->locally_generated;
2726 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2727 locally_generated ? " (locally generated)" : "");
2729 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2731 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2736 if (wpa_s->ap_iface && info && info->addr) {
2737 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2741 if (wpa_s->ap_iface) {
2742 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2745 #endif /* CONFIG_AP */
2749 wpas_p2p_disassoc_notif(
2750 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2753 #endif /* CONFIG_P2P */
2755 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2756 sme_event_disassoc(wpa_s, info);
2758 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2763 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2764 struct deauth_info *info)
2766 u16 reason_code = 0;
2767 int locally_generated = 0;
2768 const u8 *addr = NULL;
2769 const u8 *ie = NULL;
2772 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2777 ie_len = info->ie_len;
2778 reason_code = info->reason_code;
2779 locally_generated = info->locally_generated;
2780 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2782 locally_generated ? " (locally generated)" : "");
2784 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2787 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2791 wpa_reset_ft_completed(wpa_s->wpa);
2793 wpas_event_disconnect(wpa_s, addr, reason_code,
2794 locally_generated, ie, ie_len, 1);
2798 static const char * reg_init_str(enum reg_change_initiator init)
2801 case REGDOM_SET_BY_CORE:
2803 case REGDOM_SET_BY_USER:
2805 case REGDOM_SET_BY_DRIVER:
2807 case REGDOM_SET_BY_COUNTRY_IE:
2808 return "COUNTRY_IE";
2809 case REGDOM_BEACON_HINT:
2810 return "BEACON_HINT";
2816 static const char * reg_type_str(enum reg_type type)
2819 case REGDOM_TYPE_UNKNOWN:
2821 case REGDOM_TYPE_COUNTRY:
2823 case REGDOM_TYPE_WORLD:
2825 case REGDOM_TYPE_CUSTOM_WORLD:
2826 return "CUSTOM_WORLD";
2827 case REGDOM_TYPE_INTERSECTION:
2828 return "INTERSECTION";
2834 static void wpa_supplicant_update_channel_list(
2835 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2837 struct wpa_supplicant *ifs;
2839 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2840 reg_init_str(info->initiator), reg_type_str(info->type),
2841 info->alpha2[0] ? " alpha2=" : "",
2842 info->alpha2[0] ? info->alpha2 : "");
2844 if (wpa_s->drv_priv == NULL)
2845 return; /* Ignore event during drv initialization */
2847 free_hw_features(wpa_s);
2848 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2849 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2851 wpas_p2p_update_channel_list(wpa_s);
2854 * Check other interfaces to see if they share the same radio. If
2855 * so, they get updated with this same hw mode info.
2857 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2860 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2862 free_hw_features(ifs);
2863 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2864 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2868 /* Restart sched_scan with updated channel list */
2869 if (wpa_s->sched_scanning) {
2870 wpa_dbg(wpa_s, MSG_DEBUG,
2871 "Channel list changed restart sched scan.");
2872 wpa_supplicant_cancel_sched_scan(wpa_s);
2873 wpa_supplicant_req_scan(wpa_s, 0, 0);
2878 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2879 const u8 *frame, size_t len, int freq,
2882 const struct ieee80211_mgmt *mgmt;
2887 if (len < IEEE80211_HDRLEN + 2)
2890 mgmt = (const struct ieee80211_mgmt *) frame;
2891 payload = frame + IEEE80211_HDRLEN;
2892 category = *payload++;
2893 plen = len - IEEE80211_HDRLEN - 1;
2895 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2896 " Category=%u DataLen=%d freq=%d MHz",
2897 MAC2STR(mgmt->sa), category, (int) plen, freq);
2899 if (category == WLAN_ACTION_WMM) {
2900 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2904 #ifdef CONFIG_IEEE80211R
2905 if (category == WLAN_ACTION_FT) {
2906 ft_rx_action(wpa_s, payload, plen);
2909 #endif /* CONFIG_IEEE80211R */
2911 #ifdef CONFIG_IEEE80211W
2913 if (category == WLAN_ACTION_SA_QUERY) {
2914 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2917 #endif /* CONFIG_SME */
2918 #endif /* CONFIG_IEEE80211W */
2921 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2922 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2925 #endif /* CONFIG_WNM */
2928 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2929 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
2930 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2931 mgmt->u.action.category,
2932 payload, plen, freq) == 0)
2934 #endif /* CONFIG_GAS */
2937 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2938 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2939 wpa_dbg(wpa_s, MSG_DEBUG,
2940 "TDLS: Received Discovery Response from " MACSTR,
2944 #endif /* CONFIG_TDLS */
2946 #ifdef CONFIG_INTERWORKING
2947 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2948 payload[0] == QOS_QOS_MAP_CONFIG) {
2949 const u8 *pos = payload + 1;
2950 size_t qlen = plen - 1;
2951 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2952 MACSTR, MAC2STR(mgmt->sa));
2953 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2954 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2955 pos[1] <= qlen - 2 && pos[1] >= 16)
2956 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2959 #endif /* CONFIG_INTERWORKING */
2961 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2962 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2963 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2967 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2968 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2969 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2970 payload + 1, plen - 1,
2975 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2976 category, payload, plen, freq);
2978 mesh_mpm_action_rx(wpa_s, mgmt, len);
2982 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2983 union wpa_event_data *event)
2986 struct wpa_supplicant *ifs;
2987 #endif /* CONFIG_P2P */
2988 struct wpa_freq_range_list *list;
2991 list = &event->freq_range;
2994 str = freq_range_list_str(list);
2995 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2999 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3000 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3003 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3004 wpas_p2p_update_channel_list(wpa_s);
3007 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3009 if (!ifs->current_ssid ||
3010 !ifs->current_ssid->p2p_group ||
3011 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
3012 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
3015 freq = ifs->current_ssid->frequency;
3016 if (!freq_range_list_includes(list, freq)) {
3017 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
3022 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
3024 /* TODO: Consider using CSA or removing the group within
3026 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
3028 #endif /* CONFIG_P2P */
3034 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3035 union wpa_event_data *data)
3037 wpa_dbg(wpa_s, MSG_DEBUG,
3038 "Connection authorized by device, previous state %d",
3040 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3041 wpa_supplicant_cancel_auth_timeout(wpa_s);
3042 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3043 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3044 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3046 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3047 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3048 data->assoc_info.ptk_kck_len,
3049 data->assoc_info.ptk_kek,
3050 data->assoc_info.ptk_kek_len);
3054 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3055 union wpa_event_data *data)
3057 struct wpa_supplicant *wpa_s = ctx;
3059 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3060 event != EVENT_INTERFACE_ENABLED &&
3061 event != EVENT_INTERFACE_STATUS &&
3062 event != EVENT_SCHED_SCAN_STOPPED) {
3063 wpa_dbg(wpa_s, MSG_DEBUG,
3064 "Ignore event %s (%d) while interface is disabled",
3065 event_to_string(event), event);
3069 #ifndef CONFIG_NO_STDOUT_DEBUG
3071 int level = MSG_DEBUG;
3073 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3074 const struct ieee80211_hdr *hdr;
3076 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3077 fc = le_to_host16(hdr->frame_control);
3078 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3079 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3080 level = MSG_EXCESSIVE;
3083 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3084 event_to_string(event), event);
3086 #endif /* CONFIG_NO_STDOUT_DEBUG */
3090 sme_event_auth(wpa_s, data);
3093 wpa_supplicant_event_assoc(wpa_s, data);
3094 if (data && data->assoc_info.authorized)
3095 wpa_supplicant_event_assoc_auth(wpa_s, data);
3097 case EVENT_DISASSOC:
3098 wpas_event_disassoc(wpa_s,
3099 data ? &data->disassoc_info : NULL);
3102 wpas_event_deauth(wpa_s,
3103 data ? &data->deauth_info : NULL);
3105 case EVENT_MICHAEL_MIC_FAILURE:
3106 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3108 #ifndef CONFIG_NO_SCAN_PROCESSING
3109 case EVENT_SCAN_STARTED:
3110 os_get_reltime(&wpa_s->scan_start_time);
3111 if (wpa_s->own_scan_requested) {
3112 struct os_reltime diff;
3114 os_reltime_sub(&wpa_s->scan_start_time,
3115 &wpa_s->scan_trigger_time, &diff);
3116 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3117 diff.sec, diff.usec);
3118 wpa_s->own_scan_requested = 0;
3119 wpa_s->own_scan_running = 1;
3120 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3121 wpa_s->manual_scan_use_id) {
3122 wpa_msg_ctrl(wpa_s, MSG_INFO,
3123 WPA_EVENT_SCAN_STARTED "id=%u",
3124 wpa_s->manual_scan_id);
3126 wpa_msg_ctrl(wpa_s, MSG_INFO,
3127 WPA_EVENT_SCAN_STARTED);
3130 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3131 wpa_s->radio->external_scan_running = 1;
3132 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3135 case EVENT_SCAN_RESULTS:
3136 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3137 struct os_reltime now, diff;
3138 os_get_reltime(&now);
3139 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3140 wpa_s->scan_start_time.sec = 0;
3141 wpa_s->scan_start_time.usec = 0;
3142 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3143 diff.sec, diff.usec);
3145 if (wpa_supplicant_event_scan_results(wpa_s, data))
3146 break; /* interface may have been removed */
3147 wpa_s->own_scan_running = 0;
3148 wpa_s->radio->external_scan_running = 0;
3149 radio_work_check_next(wpa_s);
3151 #endif /* CONFIG_NO_SCAN_PROCESSING */
3152 case EVENT_ASSOCINFO:
3153 wpa_supplicant_event_associnfo(wpa_s, data);
3155 case EVENT_INTERFACE_STATUS:
3156 wpa_supplicant_event_interface_status(wpa_s, data);
3158 case EVENT_PMKID_CANDIDATE:
3159 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3161 #ifdef CONFIG_PEERKEY
3162 case EVENT_STKSTART:
3163 wpa_supplicant_event_stkstart(wpa_s, data);
3165 #endif /* CONFIG_PEERKEY */
3168 wpa_supplicant_event_tdls(wpa_s, data);
3170 #endif /* CONFIG_TDLS */
3173 wpa_supplicant_event_wnm(wpa_s, data);
3175 #endif /* CONFIG_WNM */
3176 #ifdef CONFIG_IEEE80211R
3177 case EVENT_FT_RESPONSE:
3178 wpa_supplicant_event_ft_response(wpa_s, data);
3180 #endif /* CONFIG_IEEE80211R */
3181 #ifdef CONFIG_IBSS_RSN
3182 case EVENT_IBSS_RSN_START:
3183 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3185 #endif /* CONFIG_IBSS_RSN */
3186 case EVENT_ASSOC_REJECT:
3187 if (data->assoc_reject.bssid)
3188 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3189 "bssid=" MACSTR " status_code=%u",
3190 MAC2STR(data->assoc_reject.bssid),
3191 data->assoc_reject.status_code);
3193 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3195 data->assoc_reject.status_code);
3196 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3197 sme_event_assoc_reject(wpa_s, data);
3199 const u8 *bssid = data->assoc_reject.bssid;
3200 if (bssid == NULL || is_zero_ether_addr(bssid))
3201 bssid = wpa_s->pending_bssid;
3202 wpas_connection_failed(wpa_s, bssid);
3203 wpa_supplicant_mark_disassoc(wpa_s);
3206 case EVENT_AUTH_TIMED_OUT:
3207 /* It is possible to get this event from earlier connection */
3208 if (wpa_s->current_ssid &&
3209 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3210 wpa_dbg(wpa_s, MSG_DEBUG,
3211 "Ignore AUTH_TIMED_OUT in mesh configuration");
3214 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3215 sme_event_auth_timed_out(wpa_s, data);
3217 case EVENT_ASSOC_TIMED_OUT:
3218 /* It is possible to get this event from earlier connection */
3219 if (wpa_s->current_ssid &&
3220 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3221 wpa_dbg(wpa_s, MSG_DEBUG,
3222 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3225 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3226 sme_event_assoc_timed_out(wpa_s, data);
3228 case EVENT_TX_STATUS:
3229 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3230 " type=%d stype=%d",
3231 MAC2STR(data->tx_status.dst),
3232 data->tx_status.type, data->tx_status.stype);
3234 if (wpa_s->ap_iface == NULL) {
3235 #ifdef CONFIG_OFFCHANNEL
3236 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3237 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3238 offchannel_send_action_tx_status(
3239 wpa_s, data->tx_status.dst,
3240 data->tx_status.data,
3241 data->tx_status.data_len,
3242 data->tx_status.ack ?
3243 OFFCHANNEL_SEND_ACTION_SUCCESS :
3244 OFFCHANNEL_SEND_ACTION_NO_ACK);
3245 #endif /* CONFIG_OFFCHANNEL */
3248 #endif /* CONFIG_AP */
3249 #ifdef CONFIG_OFFCHANNEL
3250 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3251 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3253 * Catch TX status events for Action frames we sent via group
3254 * interface in GO mode.
3256 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3257 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3258 os_memcmp(wpa_s->parent->pending_action_dst,
3259 data->tx_status.dst, ETH_ALEN) == 0) {
3260 offchannel_send_action_tx_status(
3261 wpa_s->parent, data->tx_status.dst,
3262 data->tx_status.data,
3263 data->tx_status.data_len,
3264 data->tx_status.ack ?
3265 OFFCHANNEL_SEND_ACTION_SUCCESS :
3266 OFFCHANNEL_SEND_ACTION_NO_ACK);
3269 #endif /* CONFIG_OFFCHANNEL */
3271 switch (data->tx_status.type) {
3272 case WLAN_FC_TYPE_MGMT:
3273 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3274 data->tx_status.data_len,
3275 data->tx_status.stype,
3276 data->tx_status.ack);
3278 case WLAN_FC_TYPE_DATA:
3279 ap_tx_status(wpa_s, data->tx_status.dst,
3280 data->tx_status.data,
3281 data->tx_status.data_len,
3282 data->tx_status.ack);
3285 #endif /* CONFIG_AP */
3288 case EVENT_EAPOL_TX_STATUS:
3289 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3290 data->eapol_tx_status.data,
3291 data->eapol_tx_status.data_len,
3292 data->eapol_tx_status.ack);
3294 case EVENT_DRIVER_CLIENT_POLL_OK:
3295 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3297 case EVENT_RX_FROM_UNKNOWN:
3298 if (wpa_s->ap_iface == NULL)
3300 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3301 data->rx_from_unknown.wds);
3303 case EVENT_CH_SWITCH:
3306 if (!wpa_s->ap_iface) {
3307 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3308 "event in non-AP mode");
3312 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3313 data->ch_switch.ht_enabled,
3314 data->ch_switch.ch_offset,
3315 data->ch_switch.ch_width,
3316 data->ch_switch.cf1,
3317 data->ch_switch.cf2);
3320 case EVENT_DFS_RADAR_DETECTED:
3322 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3324 case EVENT_DFS_CAC_STARTED:
3326 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3328 case EVENT_DFS_CAC_FINISHED:
3330 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3332 case EVENT_DFS_CAC_ABORTED:
3334 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3336 case EVENT_DFS_NOP_FINISHED:
3338 wpas_event_dfs_cac_nop_finished(wpa_s,
3341 #endif /* NEED_AP_MLME */
3342 #endif /* CONFIG_AP */
3343 case EVENT_RX_MGMT: {
3345 const struct ieee80211_mgmt *mgmt;
3347 #ifdef CONFIG_TESTING_OPTIONS
3348 if (wpa_s->ext_mgmt_frame_handling) {
3349 struct rx_mgmt *rx = &data->rx_mgmt;
3350 size_t hex_len = 2 * rx->frame_len + 1;
3351 char *hex = os_malloc(hex_len);
3353 wpa_snprintf_hex(hex, hex_len,
3354 rx->frame, rx->frame_len);
3355 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3356 rx->freq, rx->datarate, rx->ssi_signal,
3362 #endif /* CONFIG_TESTING_OPTIONS */
3364 mgmt = (const struct ieee80211_mgmt *)
3365 data->rx_mgmt.frame;
3366 fc = le_to_host16(mgmt->frame_control);
3367 stype = WLAN_FC_GET_STYPE(fc);
3370 if (wpa_s->ap_iface == NULL) {
3371 #endif /* CONFIG_AP */
3373 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3374 data->rx_mgmt.frame_len > 24) {
3375 const u8 *src = mgmt->sa;
3376 const u8 *ie = mgmt->u.probe_req.variable;
3377 size_t ie_len = data->rx_mgmt.frame_len -
3378 (mgmt->u.probe_req.variable -
3379 data->rx_mgmt.frame);
3380 wpas_p2p_probe_req_rx(
3381 wpa_s, src, mgmt->da,
3382 mgmt->bssid, ie, ie_len,
3383 data->rx_mgmt.ssi_signal);
3386 #endif /* CONFIG_P2P */
3387 #ifdef CONFIG_IBSS_RSN
3388 if (wpa_s->current_ssid &&
3389 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3390 stype == WLAN_FC_STYPE_AUTH &&
3391 data->rx_mgmt.frame_len >= 30) {
3392 wpa_supplicant_event_ibss_auth(wpa_s, data);
3395 #endif /* CONFIG_IBSS_RSN */
3397 if (stype == WLAN_FC_STYPE_ACTION) {
3398 wpas_event_rx_mgmt_action(
3399 wpa_s, data->rx_mgmt.frame,
3400 data->rx_mgmt.frame_len,
3402 data->rx_mgmt.ssi_signal);
3407 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3411 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3412 "management frame in non-AP mode");
3417 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3418 data->rx_mgmt.frame_len > 24) {
3419 const u8 *ie = mgmt->u.probe_req.variable;
3420 size_t ie_len = data->rx_mgmt.frame_len -
3421 (mgmt->u.probe_req.variable -
3422 data->rx_mgmt.frame);
3424 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3425 mgmt->bssid, ie, ie_len,
3426 data->rx_mgmt.ssi_signal);
3429 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3430 #endif /* CONFIG_AP */
3433 case EVENT_RX_PROBE_REQ:
3434 if (data->rx_probe_req.sa == NULL ||
3435 data->rx_probe_req.ie == NULL)
3438 if (wpa_s->ap_iface) {
3439 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3440 data->rx_probe_req.sa,
3441 data->rx_probe_req.da,
3442 data->rx_probe_req.bssid,
3443 data->rx_probe_req.ie,
3444 data->rx_probe_req.ie_len,
3445 data->rx_probe_req.ssi_signal);
3448 #endif /* CONFIG_AP */
3449 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3450 data->rx_probe_req.da,
3451 data->rx_probe_req.bssid,
3452 data->rx_probe_req.ie,
3453 data->rx_probe_req.ie_len,
3454 data->rx_probe_req.ssi_signal);
3456 case EVENT_REMAIN_ON_CHANNEL:
3457 #ifdef CONFIG_OFFCHANNEL
3458 offchannel_remain_on_channel_cb(
3459 wpa_s, data->remain_on_channel.freq,
3460 data->remain_on_channel.duration);
3461 #endif /* CONFIG_OFFCHANNEL */
3462 wpas_p2p_remain_on_channel_cb(
3463 wpa_s, data->remain_on_channel.freq,
3464 data->remain_on_channel.duration);
3466 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3467 #ifdef CONFIG_OFFCHANNEL
3468 offchannel_cancel_remain_on_channel_cb(
3469 wpa_s, data->remain_on_channel.freq);
3470 #endif /* CONFIG_OFFCHANNEL */
3471 wpas_p2p_cancel_remain_on_channel_cb(
3472 wpa_s, data->remain_on_channel.freq);
3474 case EVENT_EAPOL_RX:
3475 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3476 data->eapol_rx.data,
3477 data->eapol_rx.data_len);
3479 case EVENT_SIGNAL_CHANGE:
3480 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3481 "above=%d signal=%d noise=%d txrate=%d",
3482 data->signal_change.above_threshold,
3483 data->signal_change.current_signal,
3484 data->signal_change.current_noise,
3485 data->signal_change.current_txrate);
3486 wpa_bss_update_level(wpa_s->current_bss,
3487 data->signal_change.current_signal);
3488 bgscan_notify_signal_change(
3489 wpa_s, data->signal_change.above_threshold,
3490 data->signal_change.current_signal,
3491 data->signal_change.current_noise,
3492 data->signal_change.current_txrate);
3494 case EVENT_INTERFACE_ENABLED:
3495 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3496 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3497 wpa_supplicant_update_mac_addr(wpa_s);
3498 if (wpa_s->p2p_mgmt) {
3499 wpa_supplicant_set_state(wpa_s,
3505 if (!wpa_s->ap_iface) {
3506 wpa_supplicant_set_state(wpa_s,
3508 wpa_s->scan_req = NORMAL_SCAN_REQ;
3509 wpa_supplicant_req_scan(wpa_s, 0, 0);
3511 wpa_supplicant_set_state(wpa_s,
3513 #else /* CONFIG_AP */
3514 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3515 wpa_supplicant_req_scan(wpa_s, 0, 0);
3516 #endif /* CONFIG_AP */
3519 case EVENT_INTERFACE_DISABLED:
3520 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3522 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3523 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3524 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3526 * Mark interface disabled if this happens to end up not
3527 * being removed as a separate P2P group interface.
3529 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3531 * The interface was externally disabled. Remove
3532 * it assuming an external entity will start a
3533 * new session if needed.
3535 if (wpa_s->current_ssid &&
3536 wpa_s->current_ssid->p2p_group)
3537 wpas_p2p_interface_unavailable(wpa_s);
3539 wpas_p2p_disconnect(wpa_s);
3541 * wpa_s instance may have been freed, so must not use
3546 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3547 p2p_in_progress(wpa_s->global->p2p) > 1) {
3548 /* This radio work will be cancelled, so clear P2P
3551 p2p_stop_find(wpa_s->global->p2p);
3553 #endif /* CONFIG_P2P */
3555 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3557 * Indicate disconnection to keep ctrl_iface events
3560 wpa_supplicant_event_disassoc(
3561 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3563 wpa_supplicant_mark_disassoc(wpa_s);
3564 radio_remove_works(wpa_s, NULL, 0);
3566 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3568 case EVENT_CHANNEL_LIST_CHANGED:
3569 wpa_supplicant_update_channel_list(
3570 wpa_s, &data->channel_list_changed);
3572 case EVENT_INTERFACE_UNAVAILABLE:
3573 wpas_p2p_interface_unavailable(wpa_s);
3575 case EVENT_BEST_CHANNEL:
3576 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3578 data->best_chan.freq_24, data->best_chan.freq_5,
3579 data->best_chan.freq_overall);
3580 wpa_s->best_24_freq = data->best_chan.freq_24;
3581 wpa_s->best_5_freq = data->best_chan.freq_5;
3582 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3583 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3584 data->best_chan.freq_5,
3585 data->best_chan.freq_overall);
3587 case EVENT_UNPROT_DEAUTH:
3588 wpa_supplicant_event_unprot_deauth(wpa_s,
3589 &data->unprot_deauth);
3591 case EVENT_UNPROT_DISASSOC:
3592 wpa_supplicant_event_unprot_disassoc(wpa_s,
3593 &data->unprot_disassoc);
3595 case EVENT_STATION_LOW_ACK:
3597 if (wpa_s->ap_iface && data)
3598 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3599 data->low_ack.addr);
3600 #endif /* CONFIG_AP */
3603 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3604 data->low_ack.addr);
3605 #endif /* CONFIG_TDLS */
3607 case EVENT_IBSS_PEER_LOST:
3608 #ifdef CONFIG_IBSS_RSN
3609 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3610 #endif /* CONFIG_IBSS_RSN */
3612 case EVENT_DRIVER_GTK_REKEY:
3613 if (os_memcmp(data->driver_gtk_rekey.bssid,
3614 wpa_s->bssid, ETH_ALEN))
3618 wpa_sm_update_replay_ctr(wpa_s->wpa,
3619 data->driver_gtk_rekey.replay_ctr);
3621 case EVENT_SCHED_SCAN_STOPPED:
3623 wpa_s->sched_scanning = 0;
3624 wpa_supplicant_notify_scanning(wpa_s, 0);
3626 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3630 * Start a new sched scan to continue searching for more SSIDs
3631 * either if timed out or PNO schedule scan is pending.
3633 if (wpa_s->sched_scan_timed_out) {
3634 wpa_supplicant_req_sched_scan(wpa_s);
3635 } else if (wpa_s->pno_sched_pending) {
3636 wpa_s->pno_sched_pending = 0;
3637 wpas_start_pno(wpa_s);
3641 case EVENT_WPS_BUTTON_PUSHED:
3643 wpas_wps_start_pbc(wpa_s, NULL, 0);
3644 #endif /* CONFIG_WPS */
3646 case EVENT_AVOID_FREQUENCIES:
3647 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3649 case EVENT_CONNECT_FAILED_REASON:
3651 if (!wpa_s->ap_iface || !data)
3653 hostapd_event_connect_failed_reason(
3654 wpa_s->ap_iface->bss[0],
3655 data->connect_failed_reason.addr,
3656 data->connect_failed_reason.code);
3657 #endif /* CONFIG_AP */
3659 case EVENT_NEW_PEER_CANDIDATE:
3661 if (!wpa_s->ifmsh || !data)
3663 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3664 data->mesh_peer.ies,
3665 data->mesh_peer.ie_len);
3666 #endif /* CONFIG_MESH */
3669 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);