2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "crypto/random.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
37 #include "gas_query.h"
38 #include "p2p_supplicant.h"
44 #include "offchannel.h"
45 #include "interworking.h"
51 #ifndef CONFIG_NO_SCAN_PROCESSING
52 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
53 int new_scan, int own_request);
54 #endif /* CONFIG_NO_SCAN_PROCESSING */
57 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
60 struct os_reltime now;
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
66 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
76 * wpas_reenabled_network_time - Time until first network is re-enabled
77 * @wpa_s: Pointer to wpa_supplicant data
78 * Returns: If all enabled networks are temporarily disabled, returns the time
79 * (in sec) until the first network is re-enabled. Otherwise returns 0.
81 * This function is used in case all enabled networks are temporarily disabled,
82 * in which case it returns the time (in sec) that the first network will be
83 * re-enabled. The function assumes that at least one network is enabled.
85 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
87 struct wpa_ssid *ssid;
88 int disabled_for, res = 0;
90 #ifdef CONFIG_INTERWORKING
91 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
94 #endif /* CONFIG_INTERWORKING */
96 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
100 disabled_for = wpas_temp_disabled(wpa_s, ssid);
104 if (!res || disabled_for < res)
112 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
114 struct wpa_supplicant *wpa_s = eloop_ctx;
116 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
119 wpa_dbg(wpa_s, MSG_DEBUG,
120 "Try to associate due to network getting re-enabled");
121 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
122 wpa_supplicant_cancel_sched_scan(wpa_s);
123 wpa_supplicant_req_scan(wpa_s, 0, 0);
128 static struct wpa_bss * wpa_supplicant_get_new_bss(
129 struct wpa_supplicant *wpa_s, const u8 *bssid)
131 struct wpa_bss *bss = NULL;
132 struct wpa_ssid *ssid = wpa_s->current_ssid;
134 if (ssid->ssid_len > 0)
135 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
137 bss = wpa_bss_get_bssid(wpa_s, bssid);
143 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
145 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148 wpa_supplicant_update_scan_results(wpa_s);
150 /* Get the BSS from the new scan results */
151 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155 wpa_s->current_bss = bss;
159 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
161 struct wpa_ssid *ssid, *old_ssid;
162 u8 drv_ssid[SSID_MAX_LEN];
166 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
167 wpa_supplicant_update_current_bss(wpa_s);
169 if (wpa_s->current_ssid->ssid_len == 0)
170 return 0; /* current profile still in use */
171 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
173 wpa_msg(wpa_s, MSG_INFO,
174 "Failed to read SSID from driver");
175 return 0; /* try to use current profile */
179 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
180 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
182 return 0; /* current profile still in use */
184 wpa_msg(wpa_s, MSG_DEBUG,
185 "Driver-initiated BSS selection changed the SSID to %s",
186 wpa_ssid_txt(drv_ssid, drv_ssid_len));
187 /* continue selecting a new network profile */
190 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
192 ssid = wpa_supplicant_get_ssid(wpa_s);
194 wpa_msg(wpa_s, MSG_INFO,
195 "No network configuration found for the current AP");
199 if (wpas_network_disabled(wpa_s, ssid)) {
200 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
204 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
205 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
206 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
210 res = wpas_temp_disabled(wpa_s, ssid);
212 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
213 "disabled for %d second(s)", res);
217 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
219 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
221 size_t wpa_ie_len = sizeof(wpa_ie);
222 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
223 wpa_ie, &wpa_ie_len) < 0)
224 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
226 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
229 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
230 eapol_sm_invalidate_cached_session(wpa_s->eapol);
231 old_ssid = wpa_s->current_ssid;
232 wpa_s->current_ssid = ssid;
234 wpa_supplicant_update_current_bss(wpa_s);
236 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
237 wpa_supplicant_initiate_eapol(wpa_s);
238 if (old_ssid != wpa_s->current_ssid)
239 wpas_notify_network_changed(wpa_s);
245 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
247 struct wpa_supplicant *wpa_s = eloop_ctx;
249 if (wpa_s->countermeasures) {
250 wpa_s->countermeasures = 0;
251 wpa_drv_set_countermeasures(wpa_s, 0);
252 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
255 * It is possible that the device is sched scanning, which means
256 * that a connection attempt will be done only when we receive
257 * scan results. However, in this case, it would be preferable
258 * to scan and connect immediately, so cancel the sched_scan and
259 * issue a regular scan flow.
261 wpa_supplicant_cancel_sched_scan(wpa_s);
262 wpa_supplicant_req_scan(wpa_s, 0, 0);
267 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
271 wnm_bss_keep_alive_deinit(wpa_s);
273 #ifdef CONFIG_IBSS_RSN
274 ibss_rsn_deinit(wpa_s->ibss_rsn);
275 wpa_s->ibss_rsn = NULL;
276 #endif /* CONFIG_IBSS_RSN */
279 wpa_supplicant_ap_deinit(wpa_s);
280 #endif /* CONFIG_AP */
282 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
285 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
286 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
287 os_memset(wpa_s->bssid, 0, ETH_ALEN);
288 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
289 sme_clear_on_disassoc(wpa_s);
290 wpa_s->current_bss = NULL;
291 wpa_s->assoc_freq = 0;
294 wpas_notify_bssid_changed(wpa_s);
296 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
297 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
298 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
299 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
300 wpa_s->ap_ies_from_associnfo = 0;
301 wpa_s->current_ssid = NULL;
302 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
305 wpas_rrm_reset(wpa_s);
306 wpa_s->wnmsleep_used = 0;
310 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
312 struct wpa_ie_data ie;
316 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
320 for (i = 0; i < ie.num_pmkid; i++) {
321 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
322 ie.pmkid + i * PMKID_LEN,
324 if (pmksa_set == 0) {
325 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
330 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
331 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
335 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
336 union wpa_event_data *data)
339 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
343 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
344 " index=%d preauth=%d",
345 MAC2STR(data->pmkid_candidate.bssid),
346 data->pmkid_candidate.index,
347 data->pmkid_candidate.preauth);
349 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
350 data->pmkid_candidate.index,
351 data->pmkid_candidate.preauth);
355 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
357 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
358 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
361 #ifdef IEEE8021X_EAPOL
362 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
363 wpa_s->current_ssid &&
364 !(wpa_s->current_ssid->eapol_flags &
365 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
367 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
368 * plaintext or static WEP keys). */
371 #endif /* IEEE8021X_EAPOL */
378 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
379 * @wpa_s: pointer to wpa_supplicant data
380 * @ssid: Configuration data for the network
381 * Returns: 0 on success, -1 on failure
383 * This function is called when starting authentication with a network that is
384 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
386 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
387 struct wpa_ssid *ssid)
389 #ifdef IEEE8021X_EAPOL
391 int aka = 0, sim = 0;
393 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
394 wpa_s->scard != NULL || wpa_s->conf->external_sim)
397 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
401 struct eap_method_type *eap = ssid->eap.eap_methods;
402 while (eap->vendor != EAP_VENDOR_IETF ||
403 eap->method != EAP_TYPE_NONE) {
404 if (eap->vendor == EAP_VENDOR_IETF) {
405 if (eap->method == EAP_TYPE_SIM)
407 else if (eap->method == EAP_TYPE_AKA ||
408 eap->method == EAP_TYPE_AKA_PRIME)
415 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
418 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
423 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
424 "use SIM, but neither EAP-SIM nor EAP-AKA are "
429 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
430 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
432 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
433 if (wpa_s->scard == NULL) {
434 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
438 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
439 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
440 #endif /* PCSC_FUNCS */
441 #endif /* IEEE8021X_EAPOL */
447 #ifndef CONFIG_NO_SCAN_PROCESSING
449 static int has_wep_key(struct wpa_ssid *ssid)
453 for (i = 0; i < NUM_WEP_KEYS; i++) {
454 if (ssid->wep_key_len[i])
462 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
463 struct wpa_ssid *ssid)
467 if (ssid->mixed_cell)
471 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
473 #endif /* CONFIG_WPS */
475 if (has_wep_key(ssid))
478 #ifdef IEEE8021X_EAPOL
479 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
480 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
481 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
483 #endif /* IEEE8021X_EAPOL */
485 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
488 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
491 if (bss->caps & IEEE80211_CAP_PRIVACY)
497 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
498 struct wpa_ssid *ssid,
501 struct wpa_ie_data ie;
503 const u8 *rsn_ie, *wpa_ie;
507 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
511 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
512 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
513 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
514 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
515 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
517 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
518 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
521 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
528 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
530 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
535 if (!(ie.proto & ssid->proto)) {
536 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
541 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
542 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
547 if (!(ie.group_cipher & ssid->group_cipher)) {
548 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
553 if (!(ie.key_mgmt & ssid->key_mgmt)) {
554 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
559 #ifdef CONFIG_IEEE80211W
560 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
561 wpas_get_ssid_pmf(wpa_s, ssid) ==
562 MGMT_FRAME_PROTECTION_REQUIRED) {
563 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
567 #endif /* CONFIG_IEEE80211W */
568 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
569 wpas_get_ssid_pmf(wpa_s, ssid) ==
570 NO_MGMT_FRAME_PROTECTION) {
571 wpa_dbg(wpa_s, MSG_DEBUG,
572 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
576 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
580 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
581 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
584 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
585 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
591 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
593 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
598 if (!(ie.proto & ssid->proto)) {
599 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
604 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
605 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
610 if (!(ie.group_cipher & ssid->group_cipher)) {
611 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
616 if (!(ie.key_mgmt & ssid->key_mgmt)) {
617 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
622 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
626 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
628 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
632 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
633 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
638 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
639 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
640 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
644 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
645 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
649 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
656 static int freq_allowed(int *freqs, int freq)
663 for (i = 0; freqs[i]; i++)
664 if (freqs[i] == freq)
670 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
672 const struct hostapd_hw_modes *mode = NULL, *modes;
673 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
678 return 1; /* Cannot do matching without knowing band */
680 modes = wpa_s->hw.modes;
683 * The driver does not provide any additional information
684 * about the utilized hardware, so allow the connection attempt
690 for (i = 0; i < wpa_s->hw.num_modes; i++) {
691 for (j = 0; j < modes[i].num_channels; j++) {
692 int freq = modes[i].channels[j].freq;
693 if (freq == bss->freq) {
695 mode->mode == HOSTAPD_MODE_IEEE80211G)
696 break; /* do not allow 802.11b replace
707 for (i = 0; i < (int) sizeof(scan_ie); i++) {
708 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
712 for (j = 2; j < rate_ie[1] + 2; j++) {
713 int flagged = !!(rate_ie[j] & 0x80);
714 int r = (rate_ie[j] & 0x7f) * 5;
717 * IEEE Std 802.11n-2009 7.3.2.2:
718 * The new BSS Membership selector value is encoded
719 * like a legacy basic rate, but it is not a rate and
720 * only indicates if the BSS members are required to
721 * support the mandatory features of Clause 20 [HT PHY]
722 * in order to join the BSS.
724 if (flagged && ((rate_ie[j] & 0x7f) ==
725 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
726 if (!ht_supported(mode)) {
727 wpa_dbg(wpa_s, MSG_DEBUG,
728 " hardware does not support "
735 /* There's also a VHT selector for 802.11ac */
736 if (flagged && ((rate_ie[j] & 0x7f) ==
737 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
738 if (!vht_supported(mode)) {
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " hardware does not support "
750 /* check for legacy basic rates */
751 for (k = 0; k < mode->num_rates; k++) {
752 if (mode->rates[k] == r)
755 if (k == mode->num_rates) {
757 * IEEE Std 802.11-2007 7.3.2.2 demands that in
758 * order to join a BSS all required rates
759 * have to be supported by the hardware.
761 wpa_dbg(wpa_s, MSG_DEBUG,
762 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
764 bss->freq, mode->mode, mode->num_rates);
775 * Test whether BSS is in an ESS.
776 * This is done differently in DMG (60 GHz) and non-DMG bands
778 static int bss_is_ess(struct wpa_bss *bss)
780 if (bss_is_dmg(bss)) {
781 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
782 IEEE80211_CAP_DMG_AP;
785 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
790 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
794 for (i = 0; i < ETH_ALEN; i++) {
795 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
802 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
806 for (i = 0; i < num; i++) {
807 const u8 *a = list + i * ETH_ALEN * 2;
808 const u8 *m = a + ETH_ALEN;
810 if (match_mac_mask(a, addr, m))
817 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
818 int i, struct wpa_bss *bss,
819 struct wpa_ssid *group,
822 u8 wpa_ie_len, rsn_ie_len;
824 struct wpa_blacklist *e;
826 struct wpa_ssid *ssid;
829 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
830 wpa_ie_len = ie ? ie[1] : 0;
832 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
833 rsn_ie_len = ie ? ie[1] : 0;
835 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
838 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
839 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
840 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
841 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
842 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
843 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
844 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
846 osen ? " osen=1" : "");
848 e = wpa_blacklist_get(wpa_s, bss->bssid);
851 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
853 * When only a single network is enabled, we can
854 * trigger blacklisting on the first failure. This
855 * should not be done with multiple enabled networks to
856 * avoid getting forced to move into a worse ESS on
857 * single error if there are no other BSSes of the
862 if (e->count > limit) {
863 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
864 "(count=%d limit=%d)", e->count, limit);
869 if (bss->ssid_len == 0) {
870 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
874 if (disallowed_bssid(wpa_s, bss->bssid)) {
875 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
879 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
880 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
884 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
886 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
887 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
890 if (wpas_network_disabled(wpa_s, ssid)) {
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
895 res = wpas_temp_disabled(wpa_s, ssid);
897 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
898 "temporarily for %d second(s)", res);
903 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
904 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
909 if (wpa && ssid->ssid_len == 0 &&
910 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
913 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
914 /* Only allow wildcard SSID match if an AP
915 * advertises active WPS operation that matches
918 if (ssid->ssid_len == 0 &&
919 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
922 #endif /* CONFIG_WPS */
924 if (ssid->bssid_set && ssid->ssid_len == 0 &&
925 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
929 (bss->ssid_len != ssid->ssid_len ||
930 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
931 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
935 if (ssid->bssid_set &&
936 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
937 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
941 /* check blacklist */
942 if (ssid->num_bssid_blacklist &&
943 addr_in_list(bss->bssid, ssid->bssid_blacklist,
944 ssid->num_bssid_blacklist)) {
945 wpa_dbg(wpa_s, MSG_DEBUG,
946 " skip - BSSID blacklisted");
950 /* if there is a whitelist, only accept those APs */
951 if (ssid->num_bssid_whitelist &&
952 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
953 ssid->num_bssid_whitelist)) {
954 wpa_dbg(wpa_s, MSG_DEBUG,
955 " skip - BSSID not in whitelist");
959 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
963 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
964 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
965 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
966 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
971 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
973 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
977 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
978 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
983 if (!wpa_supplicant_match_privacy(bss, ssid)) {
984 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
989 if (!bss_is_ess(bss)) {
990 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
994 if (!freq_allowed(ssid->freq_list, bss->freq)) {
995 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1000 if (!rate_match(wpa_s, bss)) {
1001 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1007 if (ssid->p2p_group &&
1008 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1009 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1010 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1014 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1015 struct wpabuf *p2p_ie;
1016 u8 dev_addr[ETH_ALEN];
1018 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1020 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1023 p2p_ie = wpa_bss_get_vendor_ie_multi(
1024 bss, P2P_IE_VENDOR_TYPE);
1025 if (p2p_ie == NULL) {
1026 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1030 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1031 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1033 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1034 wpabuf_free(p2p_ie);
1037 wpabuf_free(p2p_ie);
1041 * TODO: skip the AP if its P2P IE has Group Formation
1042 * bit set in the P2P Group Capability Bitmap and we
1043 * are not in Group Formation with that device.
1045 #endif /* CONFIG_P2P */
1047 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1049 struct os_reltime diff;
1051 os_reltime_sub(&wpa_s->scan_min_time,
1052 &bss->last_update, &diff);
1053 wpa_dbg(wpa_s, MSG_DEBUG,
1054 " skip - scan result not recent enough (%u.%06u seconds too old)",
1055 (unsigned int) diff.sec,
1056 (unsigned int) diff.usec);
1060 /* Matching configuration found */
1064 /* No matching configuration found */
1069 static struct wpa_bss *
1070 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1071 struct wpa_ssid *group,
1072 struct wpa_ssid **selected_ssid,
1073 int only_first_ssid)
1077 if (only_first_ssid)
1078 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1081 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1084 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1085 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1086 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1088 if (!*selected_ssid)
1090 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1092 MAC2STR(bss->bssid),
1093 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1101 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1102 struct wpa_ssid **selected_ssid)
1104 struct wpa_bss *selected = NULL;
1106 struct wpa_ssid *next_ssid = NULL;
1107 struct wpa_ssid *ssid;
1109 if (wpa_s->last_scan_res == NULL ||
1110 wpa_s->last_scan_res_used == 0)
1111 return NULL; /* no scan results from last update */
1113 if (wpa_s->next_ssid) {
1114 /* check that next_ssid is still valid */
1115 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1116 if (ssid == wpa_s->next_ssid)
1120 wpa_s->next_ssid = NULL;
1123 while (selected == NULL) {
1124 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1125 if (next_ssid && next_ssid->priority ==
1126 wpa_s->conf->pssid[prio]->priority) {
1127 selected = wpa_supplicant_select_bss(
1128 wpa_s, next_ssid, selected_ssid, 1);
1132 selected = wpa_supplicant_select_bss(
1133 wpa_s, wpa_s->conf->pssid[prio],
1139 if (selected == NULL && wpa_s->blacklist &&
1140 !wpa_s->countermeasures) {
1141 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1142 "blacklist and try again");
1143 wpa_blacklist_clear(wpa_s);
1144 wpa_s->blacklist_cleared++;
1145 } else if (selected == NULL)
1149 ssid = *selected_ssid;
1150 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1151 !ssid->passphrase && !ssid->ext_psk) {
1152 const char *field_name, *txt = NULL;
1154 wpa_dbg(wpa_s, MSG_DEBUG,
1155 "PSK/passphrase not yet available for the selected network");
1157 wpas_notify_network_request(wpa_s, ssid,
1158 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1160 field_name = wpa_supplicant_ctrl_req_to_string(
1161 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1162 if (field_name == NULL)
1165 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1174 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1175 int timeout_sec, int timeout_usec)
1177 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1179 * No networks are enabled; short-circuit request so
1180 * we don't wait timeout seconds before transitioning
1181 * to INACTIVE state.
1183 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1184 "since there are no enabled networks");
1185 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1189 wpa_s->scan_for_connection = 1;
1190 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1194 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1195 struct wpa_bss *selected,
1196 struct wpa_ssid *ssid)
1198 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1199 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1200 "PBC session overlap");
1201 wpas_notify_wps_event_pbc_overlap(wpa_s);
1203 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1204 wpa_s->p2p_in_provisioning) {
1205 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1209 #endif /* CONFIG_P2P */
1212 wpas_wps_pbc_overlap(wpa_s);
1213 wpas_wps_cancel(wpa_s);
1214 #endif /* CONFIG_WPS */
1218 wpa_msg(wpa_s, MSG_DEBUG,
1219 "Considering connect request: reassociate: %d selected: "
1220 MACSTR " bssid: " MACSTR " pending: " MACSTR
1221 " wpa_state: %s ssid=%p current_ssid=%p",
1222 wpa_s->reassociate, MAC2STR(selected->bssid),
1223 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1224 wpa_supplicant_state_txt(wpa_s->wpa_state),
1225 ssid, wpa_s->current_ssid);
1228 * Do not trigger new association unless the BSSID has changed or if
1229 * reassociation is requested. If we are in process of associating with
1230 * the selected BSSID, do not trigger new attempt.
1232 if (wpa_s->reassociate ||
1233 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1234 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1235 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1236 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1237 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1239 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1240 ssid != wpa_s->current_ssid)))) {
1241 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1242 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1245 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1246 MAC2STR(selected->bssid));
1247 wpa_supplicant_associate(wpa_s, selected, ssid);
1249 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1250 "connect with the selected AP");
1257 static struct wpa_ssid *
1258 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1261 struct wpa_ssid *ssid;
1263 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1264 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1266 if (wpas_network_disabled(wpa_s, ssid))
1268 if (ssid->mode == IEEE80211_MODE_IBSS ||
1269 ssid->mode == IEEE80211_MODE_AP ||
1270 ssid->mode == IEEE80211_MODE_MESH)
1278 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1279 * on BSS added and BSS changed events */
1280 static void wpa_supplicant_rsn_preauth_scan_results(
1281 struct wpa_supplicant *wpa_s)
1283 struct wpa_bss *bss;
1285 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1288 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1289 const u8 *ssid, *rsn;
1291 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1295 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1299 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1305 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1306 struct wpa_bss *selected,
1307 struct wpa_ssid *ssid)
1309 struct wpa_bss *current_bss = NULL;
1310 #ifndef CONFIG_NO_ROAMING
1312 #endif /* CONFIG_NO_ROAMING */
1314 if (wpa_s->reassociate)
1315 return 1; /* explicit request to reassociate */
1316 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1317 return 1; /* we are not associated; continue */
1318 if (wpa_s->current_ssid == NULL)
1319 return 1; /* unknown current SSID */
1320 if (wpa_s->current_ssid != ssid)
1321 return 1; /* different network block */
1323 if (wpas_driver_bss_selection(wpa_s))
1324 return 0; /* Driver-based roaming */
1326 if (wpa_s->current_ssid->ssid)
1327 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1328 wpa_s->current_ssid->ssid,
1329 wpa_s->current_ssid->ssid_len);
1331 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1334 return 1; /* current BSS not seen in scan results */
1336 if (current_bss == selected)
1339 if (selected->last_update_idx > current_bss->last_update_idx)
1340 return 1; /* current BSS not seen in the last scan */
1342 #ifndef CONFIG_NO_ROAMING
1343 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1344 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1345 " level=%d snr=%d est_throughput=%u",
1346 MAC2STR(current_bss->bssid), current_bss->level,
1347 current_bss->snr, current_bss->est_throughput);
1348 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1349 " level=%d snr=%d est_throughput=%u",
1350 MAC2STR(selected->bssid), selected->level,
1351 selected->snr, selected->est_throughput);
1353 if (wpa_s->current_ssid->bssid_set &&
1354 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1356 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1357 "has preferred BSSID");
1361 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1362 wpa_dbg(wpa_s, MSG_DEBUG,
1363 "Allow reassociation - selected BSS has better estimated throughput");
1367 if (current_bss->level < 0 && current_bss->level > selected->level) {
1368 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1374 if (current_bss->level < 0) {
1375 if (current_bss->level < -85)
1377 else if (current_bss->level < -80)
1379 else if (current_bss->level < -75)
1381 else if (current_bss->level < -70)
1386 if (abs(current_bss->level - selected->level) < min_diff) {
1387 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1393 #else /* CONFIG_NO_ROAMING */
1395 #endif /* CONFIG_NO_ROAMING */
1399 /* Return != 0 if no scan results could be fetched or if scan results should not
1400 * be shared with other virtual interfaces. */
1401 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1402 union wpa_event_data *data,
1405 struct wpa_scan_results *scan_res = NULL;
1408 #ifndef CONFIG_NO_RANDOM_POOL
1410 #endif /* CONFIG_NO_RANDOM_POOL */
1413 if (wpa_s->ap_iface)
1415 #endif /* CONFIG_AP */
1417 wpa_supplicant_notify_scanning(wpa_s, 0);
1419 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1420 data ? &data->scan_info :
1422 if (scan_res == NULL) {
1423 if (wpa_s->conf->ap_scan == 2 || ap ||
1424 wpa_s->scan_res_handler == scan_only_handler)
1428 if (data && data->scan_info.external_scan)
1430 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1432 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1434 goto scan_work_done;
1437 #ifndef CONFIG_NO_RANDOM_POOL
1438 num = scan_res->num;
1441 for (i = 0; i < num; i++) {
1443 struct wpa_scan_res *res = scan_res->res[i];
1444 buf[0] = res->bssid[5];
1445 buf[1] = res->qual & 0xff;
1446 buf[2] = res->noise & 0xff;
1447 buf[3] = res->level & 0xff;
1448 buf[4] = res->tsf & 0xff;
1449 random_add_randomness(buf, sizeof(buf));
1451 #endif /* CONFIG_NO_RANDOM_POOL */
1453 if (own_request && wpa_s->scan_res_handler &&
1454 !(data && data->scan_info.external_scan)) {
1455 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1456 struct wpa_scan_results *scan_res);
1458 scan_res_handler = wpa_s->scan_res_handler;
1459 wpa_s->scan_res_handler = NULL;
1460 scan_res_handler(wpa_s, scan_res);
1462 goto scan_work_done;
1466 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1468 if (wpa_s->ap_iface->scan_cb)
1469 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1470 #endif /* CONFIG_AP */
1471 goto scan_work_done;
1474 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1475 wpa_s->own_scan_running,
1476 data ? data->scan_info.external_scan : 0);
1477 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1478 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1479 own_request && !(data && data->scan_info.external_scan)) {
1480 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1481 wpa_s->manual_scan_id);
1482 wpa_s->manual_scan_use_id = 0;
1484 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1486 wpas_notify_scan_results(wpa_s);
1488 wpas_notify_scan_done(wpa_s, 1);
1490 if (data && data->scan_info.external_scan) {
1491 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1492 wpa_scan_results_free(scan_res);
1496 if (wnm_scan_process(wpa_s, 1) > 0)
1497 goto scan_work_done;
1499 if (sme_proc_obss_scan(wpa_s) > 0)
1500 goto scan_work_done;
1502 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1503 goto scan_work_done;
1505 if (autoscan_notify_scan(wpa_s, scan_res))
1506 goto scan_work_done;
1508 if (wpa_s->disconnected) {
1509 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1510 goto scan_work_done;
1513 if (!wpas_driver_bss_selection(wpa_s) &&
1514 bgscan_notify_scan(wpa_s, scan_res) == 1)
1515 goto scan_work_done;
1517 wpas_wps_update_ap_info(wpa_s, scan_res);
1519 wpa_scan_results_free(scan_res);
1521 if (own_request && wpa_s->scan_work) {
1522 struct wpa_radio_work *work = wpa_s->scan_work;
1523 wpa_s->scan_work = NULL;
1524 radio_work_done(work);
1527 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1530 wpa_scan_results_free(scan_res);
1531 if (own_request && wpa_s->scan_work) {
1532 struct wpa_radio_work *work = wpa_s->scan_work;
1533 wpa_s->scan_work = NULL;
1534 radio_work_done(work);
1540 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1541 int new_scan, int own_request)
1543 struct wpa_bss *selected;
1544 struct wpa_ssid *ssid = NULL;
1545 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1547 if (time_to_reenable > 0) {
1548 wpa_dbg(wpa_s, MSG_DEBUG,
1549 "Postpone network selection by %d seconds since all networks are disabled",
1551 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1552 eloop_register_timeout(time_to_reenable, 0,
1553 wpas_network_reenabled, wpa_s, NULL);
1557 if (wpa_s->p2p_mgmt)
1558 return 0; /* no normal connection on p2p_mgmt interface */
1560 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1564 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1567 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1571 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1572 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1576 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1578 * Do not notify other virtual radios of scan results since we do not
1579 * want them to start other associations at the same time.
1585 wpa_msg(wpa_s, MSG_INFO,
1586 "Avoiding join because we already joined a mesh group");
1589 #endif /* CONFIG_MESH */
1590 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1591 ssid = wpa_supplicant_pick_new_network(wpa_s);
1593 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1594 wpa_supplicant_associate(wpa_s, NULL, ssid);
1596 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1597 } else if (own_request) {
1599 * No SSID found. If SCAN results are as a result of
1600 * own scan request and not due to a scan request on
1601 * another shared interface, try another scan.
1603 int timeout_sec = wpa_s->scan_interval;
1604 int timeout_usec = 0;
1608 res = wpas_p2p_scan_no_go_seen(wpa_s);
1614 if (wpa_s->p2p_in_provisioning ||
1615 wpa_s->show_group_started ||
1616 wpa_s->p2p_in_invitation) {
1618 * Use shorter wait during P2P Provisioning
1619 * state and during P2P join-a-group operation
1620 * to speed up group formation.
1623 timeout_usec = 250000;
1624 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1628 #endif /* CONFIG_P2P */
1629 #ifdef CONFIG_INTERWORKING
1630 if (wpa_s->conf->auto_interworking &&
1631 wpa_s->conf->interworking &&
1632 wpa_s->conf->cred) {
1633 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1634 "start ANQP fetch since no matching "
1636 wpa_s->network_select = 1;
1637 wpa_s->auto_network_select = 1;
1638 interworking_start_fetch_anqp(wpa_s);
1641 #endif /* CONFIG_INTERWORKING */
1643 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1644 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1646 timeout_usec = 500000;
1647 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1651 #endif /* CONFIG_WPS */
1652 if (wpa_supplicant_req_sched_scan(wpa_s))
1653 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1656 wpa_msg_ctrl(wpa_s, MSG_INFO,
1657 WPA_EVENT_NETWORK_NOT_FOUND);
1664 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1665 union wpa_event_data *data)
1667 struct wpa_supplicant *ifs;
1670 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1673 * Interface may have been removed, so must not dereference
1680 * If no scan results could be fetched, then no need to
1681 * notify those interfaces that did not actually request
1682 * this scan. Similarly, if scan results started a new operation on this
1683 * interface, do not notify other interfaces to avoid concurrent
1684 * operations during a connection attempt.
1690 * Check other interfaces to see if they share the same radio. If
1691 * so, they get updated with this same scan info.
1693 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1696 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1697 "sibling", ifs->ifname);
1698 _wpa_supplicant_event_scan_results(ifs, data, 0);
1705 #endif /* CONFIG_NO_SCAN_PROCESSING */
1708 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1710 #ifdef CONFIG_NO_SCAN_PROCESSING
1712 #else /* CONFIG_NO_SCAN_PROCESSING */
1713 struct os_reltime now;
1715 if (wpa_s->last_scan_res_used == 0)
1718 os_get_reltime(&now);
1719 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1720 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1724 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1725 #endif /* CONFIG_NO_SCAN_PROCESSING */
1730 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1732 struct wpa_supplicant *wpa_s = eloop_ctx;
1734 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1737 if (!wpa_s->no_keep_alive) {
1738 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1739 MAC2STR(wpa_s->bssid));
1740 /* TODO: could skip this if normal data traffic has been sent */
1741 /* TODO: Consider using some more appropriate data frame for
1744 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1749 if (wpa_s->sme.bss_max_idle_period) {
1751 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1754 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1755 wnm_bss_keep_alive, wpa_s, NULL);
1757 #endif /* CONFIG_SME */
1761 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1762 const u8 *ies, size_t ies_len)
1764 struct ieee802_11_elems elems;
1769 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1773 if (elems.bss_max_idle_period) {
1775 wpa_s->sme.bss_max_idle_period =
1776 WPA_GET_LE16(elems.bss_max_idle_period);
1777 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1778 "TU)%s", wpa_s->sme.bss_max_idle_period,
1779 (elems.bss_max_idle_period[2] & 0x01) ?
1780 " (protected keep-live required)" : "");
1781 if (wpa_s->sme.bss_max_idle_period == 0)
1782 wpa_s->sme.bss_max_idle_period = 1;
1783 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1784 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1785 /* msec times 1000 */
1786 msec = wpa_s->sme.bss_max_idle_period * 1024;
1789 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1790 wnm_bss_keep_alive, wpa_s,
1794 #endif /* CONFIG_SME */
1797 #endif /* CONFIG_WNM */
1800 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1803 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1804 #endif /* CONFIG_WNM */
1808 #ifdef CONFIG_INTERWORKING
1810 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1815 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1816 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1818 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1825 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1826 const u8 *ies, size_t ies_len)
1828 struct ieee802_11_elems elems;
1833 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1836 if (elems.qos_map_set) {
1837 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1838 elems.qos_map_set_len);
1842 #endif /* CONFIG_INTERWORKING */
1845 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1846 union wpa_event_data *data)
1848 int l, len, found = 0, wpa_found, rsn_found;
1850 #ifdef CONFIG_IEEE80211R
1852 #endif /* CONFIG_IEEE80211R */
1854 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1855 if (data->assoc_info.req_ies)
1856 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1857 data->assoc_info.req_ies_len);
1858 if (data->assoc_info.resp_ies) {
1859 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1860 data->assoc_info.resp_ies_len);
1862 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1863 data->assoc_info.resp_ies_len);
1864 #endif /* CONFIG_TDLS */
1866 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1867 data->assoc_info.resp_ies_len);
1868 #endif /* CONFIG_WNM */
1869 #ifdef CONFIG_INTERWORKING
1870 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1871 data->assoc_info.resp_ies_len);
1872 #endif /* CONFIG_INTERWORKING */
1874 if (data->assoc_info.beacon_ies)
1875 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1876 data->assoc_info.beacon_ies,
1877 data->assoc_info.beacon_ies_len);
1878 if (data->assoc_info.freq)
1879 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1880 data->assoc_info.freq);
1882 p = data->assoc_info.req_ies;
1883 l = data->assoc_info.req_ies_len;
1885 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1886 while (p && l >= 2) {
1889 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1893 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1894 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1895 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1896 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1899 wpa_find_assoc_pmkid(wpa_s);
1905 if (!found && data->assoc_info.req_ies)
1906 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1908 #ifdef CONFIG_IEEE80211R
1910 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1911 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1912 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1913 data->assoc_info.resp_ies,
1914 data->assoc_info.resp_ies_len,
1916 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1917 "Reassociation Response failed");
1918 wpa_supplicant_deauthenticate(
1919 wpa_s, WLAN_REASON_INVALID_IE);
1924 p = data->assoc_info.resp_ies;
1925 l = data->assoc_info.resp_ies_len;
1927 #ifdef CONFIG_WPS_STRICT
1928 if (p && wpa_s->current_ssid &&
1929 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1931 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1933 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1934 "include WPS IE in (Re)Association Response");
1938 if (wps_validate_assoc_resp(wps) < 0) {
1940 wpa_supplicant_deauthenticate(
1941 wpa_s, WLAN_REASON_INVALID_IE);
1946 #endif /* CONFIG_WPS_STRICT */
1948 /* Go through the IEs and make a copy of the MDIE, if present. */
1949 while (p && l >= 2) {
1952 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1956 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1957 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1958 wpa_s->sme.ft_used = 1;
1959 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1960 MOBILITY_DOMAIN_ID_LEN);
1966 #endif /* CONFIG_SME */
1968 /* Process FT when SME is in the driver */
1969 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1970 wpa_ft_is_completed(wpa_s->wpa)) {
1971 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1972 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1973 data->assoc_info.resp_ies,
1974 data->assoc_info.resp_ies_len,
1976 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1977 "Reassociation Response failed");
1978 wpa_supplicant_deauthenticate(
1979 wpa_s, WLAN_REASON_INVALID_IE);
1982 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1985 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1986 data->assoc_info.resp_ies_len);
1987 #endif /* CONFIG_IEEE80211R */
1989 /* WPA/RSN IE from Beacon/ProbeResp */
1990 p = data->assoc_info.beacon_ies;
1991 l = data->assoc_info.beacon_ies_len;
1993 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1995 wpa_found = rsn_found = 0;
1996 while (p && l >= 2) {
1999 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2004 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2005 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2007 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2011 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2013 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2020 if (!wpa_found && data->assoc_info.beacon_ies)
2021 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2022 if (!rsn_found && data->assoc_info.beacon_ies)
2023 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2024 if (wpa_found || rsn_found)
2025 wpa_s->ap_ies_from_associnfo = 1;
2028 wpabuf_free(wpa_s->received_mb_ies);
2029 wpa_s->received_mb_ies = NULL;
2031 struct mb_ies_info mb_ies;
2033 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2034 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2035 data->assoc_info.resp_ies_len))
2036 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2038 #endif /* CONFIG_FST */
2040 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2041 wpa_s->assoc_freq != data->assoc_info.freq) {
2042 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2044 wpa_s->assoc_freq, data->assoc_info.freq);
2045 wpa_supplicant_update_scan_results(wpa_s);
2048 wpa_s->assoc_freq = data->assoc_info.freq;
2054 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2056 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2058 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2061 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2064 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2065 WPA_IE_VENDOR_TYPE);
2066 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2068 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2069 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2070 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2071 bss_rsn ? 2 + bss_rsn[1] : 0))
2078 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2079 union wpa_event_data *data)
2086 if (wpa_s->ap_iface) {
2089 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2090 data->assoc_info.addr,
2091 data->assoc_info.req_ies,
2092 data->assoc_info.req_ies_len,
2093 data->assoc_info.reassoc);
2096 #endif /* CONFIG_AP */
2098 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2100 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2101 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2104 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2105 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2106 wpa_supplicant_deauthenticate(
2107 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2111 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2112 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2113 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2114 MACSTR, MAC2STR(bssid));
2116 random_add_randomness(bssid, ETH_ALEN);
2117 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2118 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2119 wpas_notify_bssid_changed(wpa_s);
2121 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2122 wpa_clear_keys(wpa_s, bssid);
2124 if (wpa_supplicant_select_config(wpa_s) < 0) {
2125 wpa_supplicant_deauthenticate(
2126 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2131 if (wpa_s->conf->ap_scan == 1 &&
2132 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2133 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2134 wpa_msg(wpa_s, MSG_WARNING,
2135 "WPA/RSN IEs not updated");
2139 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2140 wpa_s->sme.prev_bssid_set = 1;
2141 wpa_s->sme.last_unprot_disconnect.sec = 0;
2142 #endif /* CONFIG_SME */
2144 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2145 if (wpa_s->current_ssid) {
2146 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2147 * initialized before association, but for other modes,
2148 * initialize PC/SC here, if the current configuration needs
2149 * smartcard or SIM/USIM. */
2150 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2152 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2154 l2_packet_notify_auth_start(wpa_s->l2);
2157 * Set portEnabled first to FALSE in order to get EAP state machine out
2158 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2159 * state machine may transit to AUTHENTICATING state based on obsolete
2160 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2161 * AUTHENTICATED without ever giving chance to EAP state machine to
2164 if (!ft_completed) {
2165 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2166 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2168 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2169 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2170 /* 802.1X::portControl = Auto */
2171 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2172 wpa_s->eapol_received = 0;
2173 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2174 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2175 (wpa_s->current_ssid &&
2176 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2177 if (wpa_s->current_ssid &&
2178 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2180 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2182 * Set the key after having received joined-IBSS event
2185 wpa_supplicant_set_wpa_none_key(wpa_s,
2186 wpa_s->current_ssid);
2188 wpa_supplicant_cancel_auth_timeout(wpa_s);
2189 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2190 } else if (!ft_completed) {
2191 /* Timeout for receiving the first EAPOL packet */
2192 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2194 wpa_supplicant_cancel_scan(wpa_s);
2196 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2197 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2199 * We are done; the driver will take care of RSN 4-way
2202 wpa_supplicant_cancel_auth_timeout(wpa_s);
2203 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2204 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2205 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2206 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2207 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2209 * The driver will take care of RSN 4-way handshake, so we need
2210 * to allow EAPOL supplicant to complete its work without
2211 * waiting for WPA supplicant.
2213 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2214 } else if (ft_completed) {
2216 * FT protocol completed - make sure EAPOL state machine ends
2217 * up in authenticated.
2219 wpa_supplicant_cancel_auth_timeout(wpa_s);
2220 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2221 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2222 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2225 wpa_s->last_eapol_matches_bssid = 0;
2227 if (wpa_s->pending_eapol_rx) {
2228 struct os_reltime now, age;
2229 os_get_reltime(&now);
2230 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2231 if (age.sec == 0 && age.usec < 100000 &&
2232 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2234 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2235 "frame that was received just before "
2236 "association notification");
2237 wpa_supplicant_rx_eapol(
2238 wpa_s, wpa_s->pending_eapol_rx_src,
2239 wpabuf_head(wpa_s->pending_eapol_rx),
2240 wpabuf_len(wpa_s->pending_eapol_rx));
2242 wpabuf_free(wpa_s->pending_eapol_rx);
2243 wpa_s->pending_eapol_rx = NULL;
2246 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2247 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2248 wpa_s->current_ssid &&
2249 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2250 /* Set static WEP keys again */
2251 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2254 #ifdef CONFIG_IBSS_RSN
2255 if (wpa_s->current_ssid &&
2256 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2257 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2258 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2259 wpa_s->ibss_rsn == NULL) {
2260 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2261 if (!wpa_s->ibss_rsn) {
2262 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2263 wpa_supplicant_deauthenticate(
2264 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2268 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2270 #endif /* CONFIG_IBSS_RSN */
2272 wpas_wps_notify_assoc(wpa_s, bssid);
2275 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2276 data->assoc_info.resp_ies_len,
2277 &data->assoc_info.wmm_params);
2279 if (wpa_s->reassoc_same_bss)
2280 wmm_ac_restore_tspecs(wpa_s);
2285 static int disconnect_reason_recoverable(u16 reason_code)
2287 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2288 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2289 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2293 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2295 int locally_generated)
2299 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2301 * At least Host AP driver and a Prism3 card seemed to be
2302 * generating streams of disconnected events when configuring
2303 * IBSS for WPA-None. Ignore them for now.
2308 bssid = wpa_s->bssid;
2309 if (is_zero_ether_addr(bssid))
2310 bssid = wpa_s->pending_bssid;
2312 if (!is_zero_ether_addr(bssid) ||
2313 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2314 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2316 MAC2STR(bssid), reason_code,
2317 locally_generated ? " locally_generated=1" : "");
2322 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2323 int locally_generated)
2325 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2326 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2327 return 0; /* Not in 4-way handshake with PSK */
2330 * It looks like connection was lost while trying to go through PSK
2331 * 4-way handshake. Filter out known disconnection cases that are caused
2332 * by something else than PSK mismatch to avoid confusing reports.
2335 if (locally_generated) {
2336 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2344 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2346 int locally_generated)
2350 u8 prev_pending_bssid[ETH_ALEN];
2351 struct wpa_bss *fast_reconnect = NULL;
2352 struct wpa_ssid *fast_reconnect_ssid = NULL;
2353 struct wpa_ssid *last_ssid;
2355 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2356 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2358 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2360 * At least Host AP driver and a Prism3 card seemed to be
2361 * generating streams of disconnected events when configuring
2362 * IBSS for WPA-None. Ignore them for now.
2364 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2365 "IBSS/WPA-None mode");
2369 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2370 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2371 "pre-shared key may be incorrect");
2372 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2373 return; /* P2P group removed */
2374 wpas_auth_failed(wpa_s, "WRONG_KEY");
2376 if (!wpa_s->disconnected &&
2377 (!wpa_s->auto_reconnect_disabled ||
2378 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2379 wpas_wps_searching(wpa_s) ||
2380 wpas_wps_reenable_networks_pending(wpa_s))) {
2381 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2382 "reconnect (wps=%d/%d wpa_state=%d)",
2383 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2384 wpas_wps_searching(wpa_s),
2386 if (wpa_s->wpa_state == WPA_COMPLETED &&
2387 wpa_s->current_ssid &&
2388 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2389 !locally_generated &&
2390 disconnect_reason_recoverable(reason_code)) {
2392 * It looks like the AP has dropped association with
2393 * us, but could allow us to get back in. Try to
2394 * reconnect to the same BSS without full scan to save
2395 * time for some common cases.
2397 fast_reconnect = wpa_s->current_bss;
2398 fast_reconnect_ssid = wpa_s->current_ssid;
2399 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2400 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2402 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2405 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2406 "try to re-connect");
2407 wpa_s->reassociate = 0;
2408 wpa_s->disconnected = 1;
2410 wpa_supplicant_cancel_sched_scan(wpa_s);
2412 bssid = wpa_s->bssid;
2413 if (is_zero_ether_addr(bssid))
2414 bssid = wpa_s->pending_bssid;
2415 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2416 wpas_connection_failed(wpa_s, bssid);
2417 wpa_sm_notify_disassoc(wpa_s->wpa);
2418 if (locally_generated)
2419 wpa_s->disconnect_reason = -reason_code;
2421 wpa_s->disconnect_reason = reason_code;
2422 wpas_notify_disconnect_reason(wpa_s);
2423 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2424 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2425 wpa_clear_keys(wpa_s, wpa_s->bssid);
2427 last_ssid = wpa_s->current_ssid;
2428 wpa_supplicant_mark_disassoc(wpa_s);
2430 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2431 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2432 wpa_s->current_ssid = last_ssid;
2435 if (fast_reconnect &&
2436 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2437 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2438 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2439 fast_reconnect->ssid_len) &&
2440 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2441 #ifndef CONFIG_NO_SCAN_PROCESSING
2442 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2443 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2444 fast_reconnect_ssid) < 0) {
2445 /* Recover through full scan */
2446 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2448 #endif /* CONFIG_NO_SCAN_PROCESSING */
2449 } else if (fast_reconnect) {
2451 * Could not reconnect to the same BSS due to network being
2452 * disabled. Use a new scan to match the alternative behavior
2453 * above, i.e., to continue automatic reconnection attempt in a
2454 * way that enforces disabled network rules.
2456 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2461 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2462 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2464 struct wpa_supplicant *wpa_s = eloop_ctx;
2466 if (!wpa_s->pending_mic_error_report)
2469 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2470 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2471 wpa_s->pending_mic_error_report = 0;
2473 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2477 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2478 union wpa_event_data *data)
2481 struct os_reltime t;
2483 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2484 pairwise = (data && data->michael_mic_failure.unicast);
2486 if ((wpa_s->last_michael_mic_error.sec &&
2487 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2488 wpa_s->pending_mic_error_report) {
2489 if (wpa_s->pending_mic_error_report) {
2491 * Send the pending MIC error report immediately since
2492 * we are going to start countermeasures and AP better
2495 wpa_sm_key_request(wpa_s->wpa, 1,
2496 wpa_s->pending_mic_error_pairwise);
2499 /* Send the new MIC error report immediately since we are going
2500 * to start countermeasures and AP better do the same.
2502 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2504 /* initialize countermeasures */
2505 wpa_s->countermeasures = 1;
2507 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2509 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2512 * Need to wait for completion of request frame. We do not get
2513 * any callback for the message completion, so just wait a
2514 * short while and hope for the best. */
2517 wpa_drv_set_countermeasures(wpa_s, 1);
2518 wpa_supplicant_deauthenticate(wpa_s,
2519 WLAN_REASON_MICHAEL_MIC_FAILURE);
2520 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2522 eloop_register_timeout(60, 0,
2523 wpa_supplicant_stop_countermeasures,
2525 /* TODO: mark the AP rejected for 60 second. STA is
2526 * allowed to associate with another AP.. */
2528 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2529 if (wpa_s->mic_errors_seen) {
2531 * Reduce the effectiveness of Michael MIC error
2532 * reports as a means for attacking against TKIP if
2533 * more than one MIC failure is noticed with the same
2534 * PTK. We delay the transmission of the reports by a
2535 * random time between 0 and 60 seconds in order to
2536 * force the attacker wait 60 seconds before getting
2537 * the information on whether a frame resulted in a MIC
2543 if (os_get_random(rval, sizeof(rval)) < 0)
2544 sec = os_random() % 60;
2546 sec = WPA_GET_BE32(rval) % 60;
2547 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2548 "report %d seconds", sec);
2549 wpa_s->pending_mic_error_report = 1;
2550 wpa_s->pending_mic_error_pairwise = pairwise;
2551 eloop_cancel_timeout(
2552 wpa_supplicant_delayed_mic_error_report,
2554 eloop_register_timeout(
2555 sec, os_random() % 1000000,
2556 wpa_supplicant_delayed_mic_error_report,
2559 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2561 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2562 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2563 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2565 wpa_s->last_michael_mic_error = t;
2566 wpa_s->mic_errors_seen++;
2570 #ifdef CONFIG_TERMINATE_ONLASTIF
2571 static int any_interfaces(struct wpa_supplicant *head)
2573 struct wpa_supplicant *wpa_s;
2575 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2576 if (!wpa_s->interface_removed)
2580 #endif /* CONFIG_TERMINATE_ONLASTIF */
2584 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2585 union wpa_event_data *data)
2587 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2590 switch (data->interface_status.ievent) {
2591 case EVENT_INTERFACE_ADDED:
2592 if (!wpa_s->interface_removed)
2594 wpa_s->interface_removed = 0;
2595 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2596 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2597 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2598 "driver after interface was added");
2602 if (!wpa_s->global->p2p &&
2603 !wpa_s->global->p2p_disabled &&
2604 !wpa_s->conf->p2p_disabled &&
2606 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2607 wpas_p2p_add_p2pdev_interface(
2608 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2609 wpa_printf(MSG_INFO,
2610 "P2P: Failed to enable P2P Device interface");
2611 /* Try to continue without. P2P will be disabled. */
2613 #endif /* CONFIG_P2P */
2616 case EVENT_INTERFACE_REMOVED:
2617 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2618 wpa_s->interface_removed = 1;
2619 wpa_supplicant_mark_disassoc(wpa_s);
2620 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2621 l2_packet_deinit(wpa_s->l2);
2625 if (wpa_s->global->p2p &&
2626 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2628 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2629 wpa_dbg(wpa_s, MSG_DEBUG,
2630 "Removing P2P Device interface");
2631 wpa_supplicant_remove_iface(
2632 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2634 wpa_s->global->p2p_init_wpa_s = NULL;
2636 #endif /* CONFIG_P2P */
2638 #ifdef CONFIG_TERMINATE_ONLASTIF
2639 /* check if last interface */
2640 if (!any_interfaces(wpa_s->global->ifaces))
2642 #endif /* CONFIG_TERMINATE_ONLASTIF */
2648 #ifdef CONFIG_PEERKEY
2650 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2651 union wpa_event_data *data)
2655 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2657 #endif /* CONFIG_PEERKEY */
2661 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2662 union wpa_event_data *data)
2666 switch (data->tdls.oper) {
2667 case TDLS_REQUEST_SETUP:
2668 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2669 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2670 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2672 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2674 case TDLS_REQUEST_TEARDOWN:
2675 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2676 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2677 data->tdls.reason_code);
2679 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2682 case TDLS_REQUEST_DISCOVER:
2683 wpa_tdls_send_discovery_request(wpa_s->wpa,
2688 #endif /* CONFIG_TDLS */
2692 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2693 union wpa_event_data *data)
2697 switch (data->wnm.oper) {
2698 case WNM_OPER_SLEEP:
2699 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2700 "(action=%d, intval=%d)",
2701 data->wnm.sleep_action, data->wnm.sleep_intval);
2702 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2703 data->wnm.sleep_intval, NULL);
2707 #endif /* CONFIG_WNM */
2710 #ifdef CONFIG_IEEE80211R
2712 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2713 union wpa_event_data *data)
2718 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2719 data->ft_ies.ies_len,
2720 data->ft_ies.ft_action,
2721 data->ft_ies.target_ap,
2722 data->ft_ies.ric_ies,
2723 data->ft_ies.ric_ies_len) < 0) {
2724 /* TODO: prevent MLME/driver from trying to associate? */
2727 #endif /* CONFIG_IEEE80211R */
2730 #ifdef CONFIG_IBSS_RSN
2731 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2732 union wpa_event_data *data)
2734 struct wpa_ssid *ssid;
2735 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2739 ssid = wpa_s->current_ssid;
2742 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2745 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2749 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2750 union wpa_event_data *data)
2752 struct wpa_ssid *ssid = wpa_s->current_ssid;
2757 /* check if the ssid is correctly configured as IBSS/RSN */
2758 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2761 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2762 data->rx_mgmt.frame_len);
2764 #endif /* CONFIG_IBSS_RSN */
2767 #ifdef CONFIG_IEEE80211R
2768 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2771 const u8 *sta_addr, *target_ap_addr;
2774 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2775 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2776 return; /* only SME case supported for now */
2777 if (len < 1 + 2 * ETH_ALEN + 2)
2780 return; /* Only FT Action Response is supported for now */
2781 sta_addr = data + 1;
2782 target_ap_addr = data + 1 + ETH_ALEN;
2783 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2784 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2785 MACSTR " TargetAP " MACSTR " status %u",
2786 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2788 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2789 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2790 " in FT Action Response", MAC2STR(sta_addr));
2795 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2796 "failure (status code %d)", status);
2797 /* TODO: report error to FT code(?) */
2801 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2802 len - (1 + 2 * ETH_ALEN + 2), 1,
2803 target_ap_addr, NULL, 0) < 0)
2808 struct wpa_bss *bss;
2809 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2811 wpa_s->sme.freq = bss->freq;
2812 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2813 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2816 #endif /* CONFIG_SME */
2818 #endif /* CONFIG_IEEE80211R */
2821 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2822 struct unprot_deauth *e)
2824 #ifdef CONFIG_IEEE80211W
2825 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2826 "dropped: " MACSTR " -> " MACSTR
2827 " (reason code %u)",
2828 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2829 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2830 #endif /* CONFIG_IEEE80211W */
2834 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2835 struct unprot_disassoc *e)
2837 #ifdef CONFIG_IEEE80211W
2838 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2839 "dropped: " MACSTR " -> " MACSTR
2840 " (reason code %u)",
2841 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2842 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2843 #endif /* CONFIG_IEEE80211W */
2847 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2848 u16 reason_code, int locally_generated,
2849 const u8 *ie, size_t ie_len, int deauth)
2852 if (wpa_s->ap_iface && addr) {
2853 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2857 if (wpa_s->ap_iface) {
2858 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2861 #endif /* CONFIG_AP */
2863 if (!locally_generated)
2864 wpa_s->own_disconnect_req = 0;
2866 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2868 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2869 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2870 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2871 eapol_sm_failed(wpa_s->eapol))) &&
2872 !wpa_s->eap_expected_failure))
2873 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2876 if (deauth && reason_code > 0) {
2877 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2878 locally_generated) > 0) {
2880 * The interface was removed, so cannot continue
2881 * processing any additional operations after this.
2886 #endif /* CONFIG_P2P */
2888 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2893 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2894 struct disassoc_info *info)
2896 u16 reason_code = 0;
2897 int locally_generated = 0;
2898 const u8 *addr = NULL;
2899 const u8 *ie = NULL;
2902 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2907 ie_len = info->ie_len;
2908 reason_code = info->reason_code;
2909 locally_generated = info->locally_generated;
2910 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2911 locally_generated ? " (locally generated)" : "");
2913 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2915 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2920 if (wpa_s->ap_iface && info && info->addr) {
2921 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2925 if (wpa_s->ap_iface) {
2926 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2929 #endif /* CONFIG_AP */
2933 wpas_p2p_disassoc_notif(
2934 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2937 #endif /* CONFIG_P2P */
2939 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2940 sme_event_disassoc(wpa_s, info);
2942 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2947 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2948 struct deauth_info *info)
2950 u16 reason_code = 0;
2951 int locally_generated = 0;
2952 const u8 *addr = NULL;
2953 const u8 *ie = NULL;
2956 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2961 ie_len = info->ie_len;
2962 reason_code = info->reason_code;
2963 locally_generated = info->locally_generated;
2964 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2966 locally_generated ? " (locally generated)" : "");
2968 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2971 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2975 wpa_reset_ft_completed(wpa_s->wpa);
2977 wpas_event_disconnect(wpa_s, addr, reason_code,
2978 locally_generated, ie, ie_len, 1);
2982 static const char * reg_init_str(enum reg_change_initiator init)
2985 case REGDOM_SET_BY_CORE:
2987 case REGDOM_SET_BY_USER:
2989 case REGDOM_SET_BY_DRIVER:
2991 case REGDOM_SET_BY_COUNTRY_IE:
2992 return "COUNTRY_IE";
2993 case REGDOM_BEACON_HINT:
2994 return "BEACON_HINT";
3000 static const char * reg_type_str(enum reg_type type)
3003 case REGDOM_TYPE_UNKNOWN:
3005 case REGDOM_TYPE_COUNTRY:
3007 case REGDOM_TYPE_WORLD:
3009 case REGDOM_TYPE_CUSTOM_WORLD:
3010 return "CUSTOM_WORLD";
3011 case REGDOM_TYPE_INTERSECTION:
3012 return "INTERSECTION";
3018 static void wpa_supplicant_update_channel_list(
3019 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3021 struct wpa_supplicant *ifs;
3023 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3024 reg_init_str(info->initiator), reg_type_str(info->type),
3025 info->alpha2[0] ? " alpha2=" : "",
3026 info->alpha2[0] ? info->alpha2 : "");
3028 if (wpa_s->drv_priv == NULL)
3029 return; /* Ignore event during drv initialization */
3031 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3033 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3035 free_hw_features(ifs);
3036 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3037 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3040 /* Restart sched_scan with updated channel list */
3041 if (wpa_s->sched_scanning) {
3042 wpa_dbg(wpa_s, MSG_DEBUG,
3043 "Channel list changed restart sched scan.");
3044 wpa_supplicant_cancel_sched_scan(wpa_s);
3045 wpa_supplicant_req_scan(wpa_s, 0, 0);
3048 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3052 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3053 const u8 *frame, size_t len, int freq,
3056 const struct ieee80211_mgmt *mgmt;
3061 if (len < IEEE80211_HDRLEN + 2)
3064 mgmt = (const struct ieee80211_mgmt *) frame;
3065 payload = frame + IEEE80211_HDRLEN;
3066 category = *payload++;
3067 plen = len - IEEE80211_HDRLEN - 1;
3069 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3070 " Category=%u DataLen=%d freq=%d MHz",
3071 MAC2STR(mgmt->sa), category, (int) plen, freq);
3073 if (category == WLAN_ACTION_WMM) {
3074 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3078 #ifdef CONFIG_IEEE80211R
3079 if (category == WLAN_ACTION_FT) {
3080 ft_rx_action(wpa_s, payload, plen);
3083 #endif /* CONFIG_IEEE80211R */
3085 #ifdef CONFIG_IEEE80211W
3087 if (category == WLAN_ACTION_SA_QUERY) {
3088 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3091 #endif /* CONFIG_SME */
3092 #endif /* CONFIG_IEEE80211W */
3095 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3096 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3099 #endif /* CONFIG_WNM */
3102 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3103 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3104 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3105 mgmt->u.action.category,
3106 payload, plen, freq) == 0)
3108 #endif /* CONFIG_GAS */
3111 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3112 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3113 wpa_dbg(wpa_s, MSG_DEBUG,
3114 "TDLS: Received Discovery Response from " MACSTR,
3118 #endif /* CONFIG_TDLS */
3120 #ifdef CONFIG_INTERWORKING
3121 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3122 payload[0] == QOS_QOS_MAP_CONFIG) {
3123 const u8 *pos = payload + 1;
3124 size_t qlen = plen - 1;
3125 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3126 MACSTR, MAC2STR(mgmt->sa));
3127 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3128 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3129 pos[1] <= qlen - 2 && pos[1] >= 16)
3130 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3133 #endif /* CONFIG_INTERWORKING */
3135 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3136 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3137 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3141 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3142 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3143 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3144 payload + 1, plen - 1,
3150 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3151 fst_rx_action(wpa_s->fst, mgmt, len);
3154 #endif /* CONFIG_FST */
3156 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3157 category, payload, plen, freq);
3159 mesh_mpm_action_rx(wpa_s, mgmt, len);
3163 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3164 union wpa_event_data *event)
3166 struct wpa_freq_range_list *list;
3169 list = &event->freq_range;
3172 str = freq_range_list_str(list);
3173 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3177 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3178 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3181 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3184 * The update channel flow will also take care of moving a GO
3185 * from the unsafe frequency if needed.
3187 wpas_p2p_update_channel_list(wpa_s,
3188 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3190 #endif /* CONFIG_P2P */
3196 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3197 union wpa_event_data *data)
3199 wpa_dbg(wpa_s, MSG_DEBUG,
3200 "Connection authorized by device, previous state %d",
3202 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3203 wpa_supplicant_cancel_auth_timeout(wpa_s);
3204 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3205 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3206 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3208 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3209 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3210 data->assoc_info.ptk_kck_len,
3211 data->assoc_info.ptk_kek,
3212 data->assoc_info.ptk_kek_len);
3216 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3217 union wpa_event_data *data)
3219 struct wpa_supplicant *wpa_s = ctx;
3222 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3223 event != EVENT_INTERFACE_ENABLED &&
3224 event != EVENT_INTERFACE_STATUS &&
3225 event != EVENT_SCHED_SCAN_STOPPED) {
3226 wpa_dbg(wpa_s, MSG_DEBUG,
3227 "Ignore event %s (%d) while interface is disabled",
3228 event_to_string(event), event);
3232 #ifndef CONFIG_NO_STDOUT_DEBUG
3234 int level = MSG_DEBUG;
3236 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3237 const struct ieee80211_hdr *hdr;
3239 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3240 fc = le_to_host16(hdr->frame_control);
3241 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3242 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3243 level = MSG_EXCESSIVE;
3246 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3247 event_to_string(event), event);
3249 #endif /* CONFIG_NO_STDOUT_DEBUG */
3253 sme_event_auth(wpa_s, data);
3256 wpa_supplicant_event_assoc(wpa_s, data);
3257 if (data && data->assoc_info.authorized)
3258 wpa_supplicant_event_assoc_auth(wpa_s, data);
3260 case EVENT_DISASSOC:
3261 wpas_event_disassoc(wpa_s,
3262 data ? &data->disassoc_info : NULL);
3265 wpas_event_deauth(wpa_s,
3266 data ? &data->deauth_info : NULL);
3268 case EVENT_MICHAEL_MIC_FAILURE:
3269 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3271 #ifndef CONFIG_NO_SCAN_PROCESSING
3272 case EVENT_SCAN_STARTED:
3273 if (wpa_s->own_scan_requested ||
3274 (data && !data->scan_info.external_scan)) {
3275 struct os_reltime diff;
3277 os_get_reltime(&wpa_s->scan_start_time);
3278 os_reltime_sub(&wpa_s->scan_start_time,
3279 &wpa_s->scan_trigger_time, &diff);
3280 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3281 diff.sec, diff.usec);
3282 wpa_s->own_scan_requested = 0;
3283 wpa_s->own_scan_running = 1;
3284 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3285 wpa_s->manual_scan_use_id) {
3286 wpa_msg_ctrl(wpa_s, MSG_INFO,
3287 WPA_EVENT_SCAN_STARTED "id=%u",
3288 wpa_s->manual_scan_id);
3290 wpa_msg_ctrl(wpa_s, MSG_INFO,
3291 WPA_EVENT_SCAN_STARTED);
3294 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3295 wpa_s->radio->external_scan_running = 1;
3296 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3299 case EVENT_SCAN_RESULTS:
3300 if (!(data && data->scan_info.external_scan) &&
3301 os_reltime_initialized(&wpa_s->scan_start_time)) {
3302 struct os_reltime now, diff;
3303 os_get_reltime(&now);
3304 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3305 wpa_s->scan_start_time.sec = 0;
3306 wpa_s->scan_start_time.usec = 0;
3307 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3308 diff.sec, diff.usec);
3310 if (wpa_supplicant_event_scan_results(wpa_s, data))
3311 break; /* interface may have been removed */
3312 if (!(data && data->scan_info.external_scan))
3313 wpa_s->own_scan_running = 0;
3314 if (data && data->scan_info.nl_scan_event)
3315 wpa_s->radio->external_scan_running = 0;
3316 radio_work_check_next(wpa_s);
3318 #endif /* CONFIG_NO_SCAN_PROCESSING */
3319 case EVENT_ASSOCINFO:
3320 wpa_supplicant_event_associnfo(wpa_s, data);
3322 case EVENT_INTERFACE_STATUS:
3323 wpa_supplicant_event_interface_status(wpa_s, data);
3325 case EVENT_PMKID_CANDIDATE:
3326 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3328 #ifdef CONFIG_PEERKEY
3329 case EVENT_STKSTART:
3330 wpa_supplicant_event_stkstart(wpa_s, data);
3332 #endif /* CONFIG_PEERKEY */
3335 wpa_supplicant_event_tdls(wpa_s, data);
3337 #endif /* CONFIG_TDLS */
3340 wpa_supplicant_event_wnm(wpa_s, data);
3342 #endif /* CONFIG_WNM */
3343 #ifdef CONFIG_IEEE80211R
3344 case EVENT_FT_RESPONSE:
3345 wpa_supplicant_event_ft_response(wpa_s, data);
3347 #endif /* CONFIG_IEEE80211R */
3348 #ifdef CONFIG_IBSS_RSN
3349 case EVENT_IBSS_RSN_START:
3350 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3352 #endif /* CONFIG_IBSS_RSN */
3353 case EVENT_ASSOC_REJECT:
3354 if (data->assoc_reject.bssid)
3355 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3356 "bssid=" MACSTR " status_code=%u",
3357 MAC2STR(data->assoc_reject.bssid),
3358 data->assoc_reject.status_code);
3360 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3362 data->assoc_reject.status_code);
3363 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3364 sme_event_assoc_reject(wpa_s, data);
3366 const u8 *bssid = data->assoc_reject.bssid;
3367 if (bssid == NULL || is_zero_ether_addr(bssid))
3368 bssid = wpa_s->pending_bssid;
3369 wpas_connection_failed(wpa_s, bssid);
3370 wpa_supplicant_mark_disassoc(wpa_s);
3373 case EVENT_AUTH_TIMED_OUT:
3374 /* It is possible to get this event from earlier connection */
3375 if (wpa_s->current_ssid &&
3376 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3377 wpa_dbg(wpa_s, MSG_DEBUG,
3378 "Ignore AUTH_TIMED_OUT in mesh configuration");
3381 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3382 sme_event_auth_timed_out(wpa_s, data);
3384 case EVENT_ASSOC_TIMED_OUT:
3385 /* It is possible to get this event from earlier connection */
3386 if (wpa_s->current_ssid &&
3387 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3388 wpa_dbg(wpa_s, MSG_DEBUG,
3389 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3392 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3393 sme_event_assoc_timed_out(wpa_s, data);
3395 case EVENT_TX_STATUS:
3396 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3397 " type=%d stype=%d",
3398 MAC2STR(data->tx_status.dst),
3399 data->tx_status.type, data->tx_status.stype);
3401 if (wpa_s->ap_iface == NULL) {
3402 #ifdef CONFIG_OFFCHANNEL
3403 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3404 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3405 offchannel_send_action_tx_status(
3406 wpa_s, data->tx_status.dst,
3407 data->tx_status.data,
3408 data->tx_status.data_len,
3409 data->tx_status.ack ?
3410 OFFCHANNEL_SEND_ACTION_SUCCESS :
3411 OFFCHANNEL_SEND_ACTION_NO_ACK);
3412 #endif /* CONFIG_OFFCHANNEL */
3415 #endif /* CONFIG_AP */
3416 #ifdef CONFIG_OFFCHANNEL
3417 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3418 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3420 * Catch TX status events for Action frames we sent via group
3421 * interface in GO mode.
3423 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3424 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3425 os_memcmp(wpa_s->parent->pending_action_dst,
3426 data->tx_status.dst, ETH_ALEN) == 0) {
3427 offchannel_send_action_tx_status(
3428 wpa_s->parent, data->tx_status.dst,
3429 data->tx_status.data,
3430 data->tx_status.data_len,
3431 data->tx_status.ack ?
3432 OFFCHANNEL_SEND_ACTION_SUCCESS :
3433 OFFCHANNEL_SEND_ACTION_NO_ACK);
3436 #endif /* CONFIG_OFFCHANNEL */
3438 switch (data->tx_status.type) {
3439 case WLAN_FC_TYPE_MGMT:
3440 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3441 data->tx_status.data_len,
3442 data->tx_status.stype,
3443 data->tx_status.ack);
3445 case WLAN_FC_TYPE_DATA:
3446 ap_tx_status(wpa_s, data->tx_status.dst,
3447 data->tx_status.data,
3448 data->tx_status.data_len,
3449 data->tx_status.ack);
3452 #endif /* CONFIG_AP */
3455 case EVENT_EAPOL_TX_STATUS:
3456 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3457 data->eapol_tx_status.data,
3458 data->eapol_tx_status.data_len,
3459 data->eapol_tx_status.ack);
3461 case EVENT_DRIVER_CLIENT_POLL_OK:
3462 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3464 case EVENT_RX_FROM_UNKNOWN:
3465 if (wpa_s->ap_iface == NULL)
3467 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3468 data->rx_from_unknown.wds);
3470 case EVENT_CH_SWITCH:
3471 if (!data || !wpa_s->current_ssid)
3474 wpa_s->assoc_freq = data->ch_switch.freq;
3475 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3477 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3478 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3479 wpa_s->current_ssid->mode ==
3480 WPAS_MODE_P2P_GROUP_FORMATION) {
3481 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3482 data->ch_switch.ht_enabled,
3483 data->ch_switch.ch_offset,
3484 data->ch_switch.ch_width,
3485 data->ch_switch.cf1,
3486 data->ch_switch.cf2);
3489 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3492 case EVENT_DFS_RADAR_DETECTED:
3494 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3496 case EVENT_DFS_CAC_STARTED:
3498 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3500 case EVENT_DFS_CAC_FINISHED:
3502 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3504 case EVENT_DFS_CAC_ABORTED:
3506 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3508 case EVENT_DFS_NOP_FINISHED:
3510 wpas_event_dfs_cac_nop_finished(wpa_s,
3513 #endif /* NEED_AP_MLME */
3514 #endif /* CONFIG_AP */
3515 case EVENT_RX_MGMT: {
3517 const struct ieee80211_mgmt *mgmt;
3519 #ifdef CONFIG_TESTING_OPTIONS
3520 if (wpa_s->ext_mgmt_frame_handling) {
3521 struct rx_mgmt *rx = &data->rx_mgmt;
3522 size_t hex_len = 2 * rx->frame_len + 1;
3523 char *hex = os_malloc(hex_len);
3525 wpa_snprintf_hex(hex, hex_len,
3526 rx->frame, rx->frame_len);
3527 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3528 rx->freq, rx->datarate, rx->ssi_signal,
3534 #endif /* CONFIG_TESTING_OPTIONS */
3536 mgmt = (const struct ieee80211_mgmt *)
3537 data->rx_mgmt.frame;
3538 fc = le_to_host16(mgmt->frame_control);
3539 stype = WLAN_FC_GET_STYPE(fc);
3542 if (wpa_s->ap_iface == NULL) {
3543 #endif /* CONFIG_AP */
3545 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3546 data->rx_mgmt.frame_len > 24) {
3547 const u8 *src = mgmt->sa;
3548 const u8 *ie = mgmt->u.probe_req.variable;
3549 size_t ie_len = data->rx_mgmt.frame_len -
3550 (mgmt->u.probe_req.variable -
3551 data->rx_mgmt.frame);
3552 wpas_p2p_probe_req_rx(
3553 wpa_s, src, mgmt->da,
3554 mgmt->bssid, ie, ie_len,
3556 data->rx_mgmt.ssi_signal);
3559 #endif /* CONFIG_P2P */
3560 #ifdef CONFIG_IBSS_RSN
3561 if (wpa_s->current_ssid &&
3562 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3563 stype == WLAN_FC_STYPE_AUTH &&
3564 data->rx_mgmt.frame_len >= 30) {
3565 wpa_supplicant_event_ibss_auth(wpa_s, data);
3568 #endif /* CONFIG_IBSS_RSN */
3570 if (stype == WLAN_FC_STYPE_ACTION) {
3571 wpas_event_rx_mgmt_action(
3572 wpa_s, data->rx_mgmt.frame,
3573 data->rx_mgmt.frame_len,
3575 data->rx_mgmt.ssi_signal);
3580 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3584 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3585 "management frame in non-AP mode");
3590 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3591 data->rx_mgmt.frame_len > 24) {
3592 const u8 *ie = mgmt->u.probe_req.variable;
3593 size_t ie_len = data->rx_mgmt.frame_len -
3594 (mgmt->u.probe_req.variable -
3595 data->rx_mgmt.frame);
3597 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3598 mgmt->bssid, ie, ie_len,
3599 data->rx_mgmt.ssi_signal);
3602 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3603 #endif /* CONFIG_AP */
3606 case EVENT_RX_PROBE_REQ:
3607 if (data->rx_probe_req.sa == NULL ||
3608 data->rx_probe_req.ie == NULL)
3611 if (wpa_s->ap_iface) {
3612 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3613 data->rx_probe_req.sa,
3614 data->rx_probe_req.da,
3615 data->rx_probe_req.bssid,
3616 data->rx_probe_req.ie,
3617 data->rx_probe_req.ie_len,
3618 data->rx_probe_req.ssi_signal);
3621 #endif /* CONFIG_AP */
3622 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3623 data->rx_probe_req.da,
3624 data->rx_probe_req.bssid,
3625 data->rx_probe_req.ie,
3626 data->rx_probe_req.ie_len,
3628 data->rx_probe_req.ssi_signal);
3630 case EVENT_REMAIN_ON_CHANNEL:
3631 #ifdef CONFIG_OFFCHANNEL
3632 offchannel_remain_on_channel_cb(
3633 wpa_s, data->remain_on_channel.freq,
3634 data->remain_on_channel.duration);
3635 #endif /* CONFIG_OFFCHANNEL */
3636 wpas_p2p_remain_on_channel_cb(
3637 wpa_s, data->remain_on_channel.freq,
3638 data->remain_on_channel.duration);
3640 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3641 #ifdef CONFIG_OFFCHANNEL
3642 offchannel_cancel_remain_on_channel_cb(
3643 wpa_s, data->remain_on_channel.freq);
3644 #endif /* CONFIG_OFFCHANNEL */
3645 wpas_p2p_cancel_remain_on_channel_cb(
3646 wpa_s, data->remain_on_channel.freq);
3648 case EVENT_EAPOL_RX:
3649 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3650 data->eapol_rx.data,
3651 data->eapol_rx.data_len);
3653 case EVENT_SIGNAL_CHANGE:
3654 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3655 "above=%d signal=%d noise=%d txrate=%d",
3656 data->signal_change.above_threshold,
3657 data->signal_change.current_signal,
3658 data->signal_change.current_noise,
3659 data->signal_change.current_txrate);
3660 wpa_bss_update_level(wpa_s->current_bss,
3661 data->signal_change.current_signal);
3662 bgscan_notify_signal_change(
3663 wpa_s, data->signal_change.above_threshold,
3664 data->signal_change.current_signal,
3665 data->signal_change.current_noise,
3666 data->signal_change.current_txrate);
3668 case EVENT_INTERFACE_ENABLED:
3669 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3670 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3671 wpa_supplicant_update_mac_addr(wpa_s);
3672 if (wpa_s->p2p_mgmt) {
3673 wpa_supplicant_set_state(wpa_s,
3679 if (!wpa_s->ap_iface) {
3680 wpa_supplicant_set_state(wpa_s,
3682 wpa_s->scan_req = NORMAL_SCAN_REQ;
3683 wpa_supplicant_req_scan(wpa_s, 0, 0);
3685 wpa_supplicant_set_state(wpa_s,
3687 #else /* CONFIG_AP */
3688 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3689 wpa_supplicant_req_scan(wpa_s, 0, 0);
3690 #endif /* CONFIG_AP */
3693 case EVENT_INTERFACE_DISABLED:
3694 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3696 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3697 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3698 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3700 * Mark interface disabled if this happens to end up not
3701 * being removed as a separate P2P group interface.
3703 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3705 * The interface was externally disabled. Remove
3706 * it assuming an external entity will start a
3707 * new session if needed.
3709 if (wpa_s->current_ssid &&
3710 wpa_s->current_ssid->p2p_group)
3711 wpas_p2p_interface_unavailable(wpa_s);
3713 wpas_p2p_disconnect(wpa_s);
3715 * wpa_s instance may have been freed, so must not use
3720 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3721 p2p_in_progress(wpa_s->global->p2p) > 1) {
3722 /* This radio work will be cancelled, so clear P2P
3725 p2p_stop_find(wpa_s->global->p2p);
3727 #endif /* CONFIG_P2P */
3729 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3731 * Indicate disconnection to keep ctrl_iface events
3734 wpa_supplicant_event_disassoc(
3735 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3737 wpa_supplicant_mark_disassoc(wpa_s);
3738 radio_remove_works(wpa_s, NULL, 0);
3740 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3742 case EVENT_CHANNEL_LIST_CHANGED:
3743 wpa_supplicant_update_channel_list(
3744 wpa_s, &data->channel_list_changed);
3746 case EVENT_INTERFACE_UNAVAILABLE:
3747 wpas_p2p_interface_unavailable(wpa_s);
3749 case EVENT_BEST_CHANNEL:
3750 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3752 data->best_chan.freq_24, data->best_chan.freq_5,
3753 data->best_chan.freq_overall);
3754 wpa_s->best_24_freq = data->best_chan.freq_24;
3755 wpa_s->best_5_freq = data->best_chan.freq_5;
3756 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3757 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3758 data->best_chan.freq_5,
3759 data->best_chan.freq_overall);
3761 case EVENT_UNPROT_DEAUTH:
3762 wpa_supplicant_event_unprot_deauth(wpa_s,
3763 &data->unprot_deauth);
3765 case EVENT_UNPROT_DISASSOC:
3766 wpa_supplicant_event_unprot_disassoc(wpa_s,
3767 &data->unprot_disassoc);
3769 case EVENT_STATION_LOW_ACK:
3771 if (wpa_s->ap_iface && data)
3772 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3773 data->low_ack.addr);
3774 #endif /* CONFIG_AP */
3777 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3778 data->low_ack.addr);
3779 #endif /* CONFIG_TDLS */
3781 case EVENT_IBSS_PEER_LOST:
3782 #ifdef CONFIG_IBSS_RSN
3783 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3784 #endif /* CONFIG_IBSS_RSN */
3786 case EVENT_DRIVER_GTK_REKEY:
3787 if (os_memcmp(data->driver_gtk_rekey.bssid,
3788 wpa_s->bssid, ETH_ALEN))
3792 wpa_sm_update_replay_ctr(wpa_s->wpa,
3793 data->driver_gtk_rekey.replay_ctr);
3795 case EVENT_SCHED_SCAN_STOPPED:
3797 wpa_s->sched_scanning = 0;
3798 resched = wpa_s->scanning;
3799 wpa_supplicant_notify_scanning(wpa_s, 0);
3801 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3805 * Start a new sched scan to continue searching for more SSIDs
3806 * either if timed out or PNO schedule scan is pending.
3808 if (wpa_s->sched_scan_timed_out) {
3809 wpa_supplicant_req_sched_scan(wpa_s);
3810 } else if (wpa_s->pno_sched_pending) {
3811 wpa_s->pno_sched_pending = 0;
3812 wpas_start_pno(wpa_s);
3813 } else if (resched) {
3814 wpa_supplicant_req_scan(wpa_s, 0, 0);
3818 case EVENT_WPS_BUTTON_PUSHED:
3820 wpas_wps_start_pbc(wpa_s, NULL, 0);
3821 #endif /* CONFIG_WPS */
3823 case EVENT_AVOID_FREQUENCIES:
3824 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3826 case EVENT_CONNECT_FAILED_REASON:
3828 if (!wpa_s->ap_iface || !data)
3830 hostapd_event_connect_failed_reason(
3831 wpa_s->ap_iface->bss[0],
3832 data->connect_failed_reason.addr,
3833 data->connect_failed_reason.code);
3834 #endif /* CONFIG_AP */
3836 case EVENT_NEW_PEER_CANDIDATE:
3838 if (!wpa_s->ifmsh || !data)
3840 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3841 data->mesh_peer.ies,
3842 data->mesh_peer.ie_len);
3843 #endif /* CONFIG_MESH */
3846 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);