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);
309 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
311 struct wpa_ie_data ie;
315 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
319 for (i = 0; i < ie.num_pmkid; i++) {
320 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
321 ie.pmkid + i * PMKID_LEN,
323 if (pmksa_set == 0) {
324 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
329 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
330 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
334 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
335 union wpa_event_data *data)
338 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
342 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
343 " index=%d preauth=%d",
344 MAC2STR(data->pmkid_candidate.bssid),
345 data->pmkid_candidate.index,
346 data->pmkid_candidate.preauth);
348 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
349 data->pmkid_candidate.index,
350 data->pmkid_candidate.preauth);
354 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
356 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
357 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
360 #ifdef IEEE8021X_EAPOL
361 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
362 wpa_s->current_ssid &&
363 !(wpa_s->current_ssid->eapol_flags &
364 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
365 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
366 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
367 * plaintext or static WEP keys). */
370 #endif /* IEEE8021X_EAPOL */
377 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
378 * @wpa_s: pointer to wpa_supplicant data
379 * @ssid: Configuration data for the network
380 * Returns: 0 on success, -1 on failure
382 * This function is called when starting authentication with a network that is
383 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
385 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
386 struct wpa_ssid *ssid)
388 #ifdef IEEE8021X_EAPOL
390 int aka = 0, sim = 0;
392 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
393 wpa_s->scard != NULL || wpa_s->conf->external_sim)
396 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
400 struct eap_method_type *eap = ssid->eap.eap_methods;
401 while (eap->vendor != EAP_VENDOR_IETF ||
402 eap->method != EAP_TYPE_NONE) {
403 if (eap->vendor == EAP_VENDOR_IETF) {
404 if (eap->method == EAP_TYPE_SIM)
406 else if (eap->method == EAP_TYPE_AKA ||
407 eap->method == EAP_TYPE_AKA_PRIME)
414 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
416 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
417 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
422 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
423 "use SIM, but neither EAP-SIM nor EAP-AKA are "
428 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
429 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
431 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
432 if (wpa_s->scard == NULL) {
433 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
437 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
438 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
439 #endif /* PCSC_FUNCS */
440 #endif /* IEEE8021X_EAPOL */
446 #ifndef CONFIG_NO_SCAN_PROCESSING
448 static int has_wep_key(struct wpa_ssid *ssid)
452 for (i = 0; i < NUM_WEP_KEYS; i++) {
453 if (ssid->wep_key_len[i])
461 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
462 struct wpa_ssid *ssid)
466 if (ssid->mixed_cell)
470 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
472 #endif /* CONFIG_WPS */
474 if (has_wep_key(ssid))
477 #ifdef IEEE8021X_EAPOL
478 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
479 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
480 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
482 #endif /* IEEE8021X_EAPOL */
484 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
487 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
490 if (bss->caps & IEEE80211_CAP_PRIVACY)
496 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
497 struct wpa_ssid *ssid,
500 struct wpa_ie_data ie;
502 const u8 *rsn_ie, *wpa_ie;
506 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
510 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
511 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
512 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
513 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
514 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
516 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
517 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
520 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
521 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
527 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
529 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
534 if (!(ie.proto & ssid->proto)) {
535 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
540 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
541 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
546 if (!(ie.group_cipher & ssid->group_cipher)) {
547 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
552 if (!(ie.key_mgmt & ssid->key_mgmt)) {
553 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
558 #ifdef CONFIG_IEEE80211W
559 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
560 wpas_get_ssid_pmf(wpa_s, ssid) ==
561 MGMT_FRAME_PROTECTION_REQUIRED) {
562 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
566 #endif /* CONFIG_IEEE80211W */
567 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
568 wpas_get_ssid_pmf(wpa_s, ssid) ==
569 NO_MGMT_FRAME_PROTECTION) {
570 wpa_dbg(wpa_s, MSG_DEBUG,
571 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
575 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
579 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
580 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
583 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
584 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
590 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
592 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
597 if (!(ie.proto & ssid->proto)) {
598 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
603 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
604 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
609 if (!(ie.group_cipher & ssid->group_cipher)) {
610 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
615 if (!(ie.key_mgmt & ssid->key_mgmt)) {
616 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
621 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
625 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
627 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
631 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
632 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
633 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
637 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
638 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
639 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
643 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
644 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
648 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
655 static int freq_allowed(int *freqs, int freq)
662 for (i = 0; freqs[i]; i++)
663 if (freqs[i] == freq)
669 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
671 const struct hostapd_hw_modes *mode = NULL, *modes;
672 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
677 return 1; /* Cannot do matching without knowing band */
679 modes = wpa_s->hw.modes;
682 * The driver does not provide any additional information
683 * about the utilized hardware, so allow the connection attempt
689 for (i = 0; i < wpa_s->hw.num_modes; i++) {
690 for (j = 0; j < modes[i].num_channels; j++) {
691 int freq = modes[i].channels[j].freq;
692 if (freq == bss->freq) {
694 mode->mode == HOSTAPD_MODE_IEEE80211G)
695 break; /* do not allow 802.11b replace
706 for (i = 0; i < (int) sizeof(scan_ie); i++) {
707 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
711 for (j = 2; j < rate_ie[1] + 2; j++) {
712 int flagged = !!(rate_ie[j] & 0x80);
713 int r = (rate_ie[j] & 0x7f) * 5;
716 * IEEE Std 802.11n-2009 7.3.2.2:
717 * The new BSS Membership selector value is encoded
718 * like a legacy basic rate, but it is not a rate and
719 * only indicates if the BSS members are required to
720 * support the mandatory features of Clause 20 [HT PHY]
721 * in order to join the BSS.
723 if (flagged && ((rate_ie[j] & 0x7f) ==
724 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
725 if (!ht_supported(mode)) {
726 wpa_dbg(wpa_s, MSG_DEBUG,
727 " hardware does not support "
734 /* There's also a VHT selector for 802.11ac */
735 if (flagged && ((rate_ie[j] & 0x7f) ==
736 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
737 if (!vht_supported(mode)) {
738 wpa_dbg(wpa_s, MSG_DEBUG,
739 " hardware does not support "
749 /* check for legacy basic rates */
750 for (k = 0; k < mode->num_rates; k++) {
751 if (mode->rates[k] == r)
754 if (k == mode->num_rates) {
756 * IEEE Std 802.11-2007 7.3.2.2 demands that in
757 * order to join a BSS all required rates
758 * have to be supported by the hardware.
760 wpa_dbg(wpa_s, MSG_DEBUG,
761 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
763 bss->freq, mode->mode, mode->num_rates);
774 * Test whether BSS is in an ESS.
775 * This is done differently in DMG (60 GHz) and non-DMG bands
777 static int bss_is_ess(struct wpa_bss *bss)
779 if (bss_is_dmg(bss)) {
780 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
781 IEEE80211_CAP_DMG_AP;
784 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
789 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
793 for (i = 0; i < ETH_ALEN; i++) {
794 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
801 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
805 for (i = 0; i < num; i++) {
806 const u8 *a = list + i * ETH_ALEN * 2;
807 const u8 *m = a + ETH_ALEN;
809 if (match_mac_mask(a, addr, m))
816 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
817 int i, struct wpa_bss *bss,
818 struct wpa_ssid *group,
821 u8 wpa_ie_len, rsn_ie_len;
823 struct wpa_blacklist *e;
825 struct wpa_ssid *ssid;
828 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
829 wpa_ie_len = ie ? ie[1] : 0;
831 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
832 rsn_ie_len = ie ? ie[1] : 0;
834 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
837 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
838 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
839 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
840 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
841 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
842 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
843 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
845 osen ? " osen=1" : "");
847 e = wpa_blacklist_get(wpa_s, bss->bssid);
850 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
852 * When only a single network is enabled, we can
853 * trigger blacklisting on the first failure. This
854 * should not be done with multiple enabled networks to
855 * avoid getting forced to move into a worse ESS on
856 * single error if there are no other BSSes of the
861 if (e->count > limit) {
862 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
863 "(count=%d limit=%d)", e->count, limit);
868 if (bss->ssid_len == 0) {
869 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
873 if (disallowed_bssid(wpa_s, bss->bssid)) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
878 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
879 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
883 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
885 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
886 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
889 if (wpas_network_disabled(wpa_s, ssid)) {
890 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
894 res = wpas_temp_disabled(wpa_s, ssid);
896 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
897 "temporarily for %d second(s)", res);
902 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
903 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
908 if (wpa && ssid->ssid_len == 0 &&
909 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
912 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
913 /* Only allow wildcard SSID match if an AP
914 * advertises active WPS operation that matches
917 if (ssid->ssid_len == 0 &&
918 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
921 #endif /* CONFIG_WPS */
923 if (ssid->bssid_set && ssid->ssid_len == 0 &&
924 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
928 (bss->ssid_len != ssid->ssid_len ||
929 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
934 if (ssid->bssid_set &&
935 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
936 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
940 /* check blacklist */
941 if (ssid->num_bssid_blacklist &&
942 addr_in_list(bss->bssid, ssid->bssid_blacklist,
943 ssid->num_bssid_blacklist)) {
944 wpa_dbg(wpa_s, MSG_DEBUG,
945 " skip - BSSID blacklisted");
949 /* if there is a whitelist, only accept those APs */
950 if (ssid->num_bssid_whitelist &&
951 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
952 ssid->num_bssid_whitelist)) {
953 wpa_dbg(wpa_s, MSG_DEBUG,
954 " skip - BSSID not in whitelist");
958 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
962 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
963 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
964 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
965 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
970 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
972 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
976 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
977 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
982 if (!wpa_supplicant_match_privacy(bss, ssid)) {
983 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
988 if (!bss_is_ess(bss)) {
989 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
993 if (!freq_allowed(ssid->freq_list, bss->freq)) {
994 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
999 if (!rate_match(wpa_s, bss)) {
1000 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1006 if (ssid->p2p_group &&
1007 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1008 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1009 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1013 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1014 struct wpabuf *p2p_ie;
1015 u8 dev_addr[ETH_ALEN];
1017 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1019 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1022 p2p_ie = wpa_bss_get_vendor_ie_multi(
1023 bss, P2P_IE_VENDOR_TYPE);
1024 if (p2p_ie == NULL) {
1025 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1029 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1030 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1032 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1033 wpabuf_free(p2p_ie);
1036 wpabuf_free(p2p_ie);
1040 * TODO: skip the AP if its P2P IE has Group Formation
1041 * bit set in the P2P Group Capability Bitmap and we
1042 * are not in Group Formation with that device.
1044 #endif /* CONFIG_P2P */
1046 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1048 struct os_reltime diff;
1050 os_reltime_sub(&wpa_s->scan_min_time,
1051 &bss->last_update, &diff);
1052 wpa_dbg(wpa_s, MSG_DEBUG,
1053 " skip - scan result not recent enough (%u.%06u seconds too old)",
1054 (unsigned int) diff.sec,
1055 (unsigned int) diff.usec);
1059 /* Matching configuration found */
1063 /* No matching configuration found */
1068 static struct wpa_bss *
1069 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1070 struct wpa_ssid *group,
1071 struct wpa_ssid **selected_ssid,
1072 int only_first_ssid)
1076 if (only_first_ssid)
1077 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1080 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1083 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1084 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1085 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1087 if (!*selected_ssid)
1089 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1091 MAC2STR(bss->bssid),
1092 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1100 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1101 struct wpa_ssid **selected_ssid)
1103 struct wpa_bss *selected = NULL;
1105 struct wpa_ssid *next_ssid = NULL;
1106 struct wpa_ssid *ssid;
1108 if (wpa_s->last_scan_res == NULL ||
1109 wpa_s->last_scan_res_used == 0)
1110 return NULL; /* no scan results from last update */
1112 if (wpa_s->next_ssid) {
1113 /* check that next_ssid is still valid */
1114 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1115 if (ssid == wpa_s->next_ssid)
1119 wpa_s->next_ssid = NULL;
1122 while (selected == NULL) {
1123 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1124 if (next_ssid && next_ssid->priority ==
1125 wpa_s->conf->pssid[prio]->priority) {
1126 selected = wpa_supplicant_select_bss(
1127 wpa_s, next_ssid, selected_ssid, 1);
1131 selected = wpa_supplicant_select_bss(
1132 wpa_s, wpa_s->conf->pssid[prio],
1138 if (selected == NULL && wpa_s->blacklist &&
1139 !wpa_s->countermeasures) {
1140 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1141 "blacklist and try again");
1142 wpa_blacklist_clear(wpa_s);
1143 wpa_s->blacklist_cleared++;
1144 } else if (selected == NULL)
1148 ssid = *selected_ssid;
1149 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1150 !ssid->passphrase && !ssid->ext_psk) {
1151 const char *field_name, *txt = NULL;
1153 wpa_dbg(wpa_s, MSG_DEBUG,
1154 "PSK/passphrase not yet available for the selected network");
1156 wpas_notify_network_request(wpa_s, ssid,
1157 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1159 field_name = wpa_supplicant_ctrl_req_to_string(
1160 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1161 if (field_name == NULL)
1164 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1173 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1174 int timeout_sec, int timeout_usec)
1176 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1178 * No networks are enabled; short-circuit request so
1179 * we don't wait timeout seconds before transitioning
1180 * to INACTIVE state.
1182 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1183 "since there are no enabled networks");
1184 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1188 wpa_s->scan_for_connection = 1;
1189 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1193 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1194 struct wpa_bss *selected,
1195 struct wpa_ssid *ssid)
1197 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1198 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1199 "PBC session overlap");
1200 wpas_notify_wps_event_pbc_overlap(wpa_s);
1202 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1203 wpa_s->p2p_in_provisioning) {
1204 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1208 #endif /* CONFIG_P2P */
1211 wpas_wps_pbc_overlap(wpa_s);
1212 wpas_wps_cancel(wpa_s);
1213 #endif /* CONFIG_WPS */
1217 wpa_msg(wpa_s, MSG_DEBUG,
1218 "Considering connect request: reassociate: %d selected: "
1219 MACSTR " bssid: " MACSTR " pending: " MACSTR
1220 " wpa_state: %s ssid=%p current_ssid=%p",
1221 wpa_s->reassociate, MAC2STR(selected->bssid),
1222 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1223 wpa_supplicant_state_txt(wpa_s->wpa_state),
1224 ssid, wpa_s->current_ssid);
1227 * Do not trigger new association unless the BSSID has changed or if
1228 * reassociation is requested. If we are in process of associating with
1229 * the selected BSSID, do not trigger new attempt.
1231 if (wpa_s->reassociate ||
1232 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1233 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1234 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1235 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1236 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1238 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1239 ssid != wpa_s->current_ssid)))) {
1240 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1241 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1244 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1245 MAC2STR(selected->bssid));
1246 wpa_supplicant_associate(wpa_s, selected, ssid);
1248 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1249 "connect with the selected AP");
1256 static struct wpa_ssid *
1257 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1260 struct wpa_ssid *ssid;
1262 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1263 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1265 if (wpas_network_disabled(wpa_s, ssid))
1267 if (ssid->mode == IEEE80211_MODE_IBSS ||
1268 ssid->mode == IEEE80211_MODE_AP ||
1269 ssid->mode == IEEE80211_MODE_MESH)
1277 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1278 * on BSS added and BSS changed events */
1279 static void wpa_supplicant_rsn_preauth_scan_results(
1280 struct wpa_supplicant *wpa_s)
1282 struct wpa_bss *bss;
1284 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1287 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1288 const u8 *ssid, *rsn;
1290 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1294 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1298 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1304 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1305 struct wpa_bss *selected,
1306 struct wpa_ssid *ssid)
1308 struct wpa_bss *current_bss = NULL;
1309 #ifndef CONFIG_NO_ROAMING
1311 #endif /* CONFIG_NO_ROAMING */
1313 if (wpa_s->reassociate)
1314 return 1; /* explicit request to reassociate */
1315 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1316 return 1; /* we are not associated; continue */
1317 if (wpa_s->current_ssid == NULL)
1318 return 1; /* unknown current SSID */
1319 if (wpa_s->current_ssid != ssid)
1320 return 1; /* different network block */
1322 if (wpas_driver_bss_selection(wpa_s))
1323 return 0; /* Driver-based roaming */
1325 if (wpa_s->current_ssid->ssid)
1326 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1327 wpa_s->current_ssid->ssid,
1328 wpa_s->current_ssid->ssid_len);
1330 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1333 return 1; /* current BSS not seen in scan results */
1335 if (current_bss == selected)
1338 if (selected->last_update_idx > current_bss->last_update_idx)
1339 return 1; /* current BSS not seen in the last scan */
1341 #ifndef CONFIG_NO_ROAMING
1342 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1343 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1344 " level=%d snr=%d est_throughput=%u",
1345 MAC2STR(current_bss->bssid), current_bss->level,
1346 current_bss->snr, current_bss->est_throughput);
1347 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1348 " level=%d snr=%d est_throughput=%u",
1349 MAC2STR(selected->bssid), selected->level,
1350 selected->snr, selected->est_throughput);
1352 if (wpa_s->current_ssid->bssid_set &&
1353 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1355 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1356 "has preferred BSSID");
1360 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1361 wpa_dbg(wpa_s, MSG_DEBUG,
1362 "Allow reassociation - selected BSS has better estimated throughput");
1366 if (current_bss->level < 0 && current_bss->level > selected->level) {
1367 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1373 if (current_bss->level < 0) {
1374 if (current_bss->level < -85)
1376 else if (current_bss->level < -80)
1378 else if (current_bss->level < -75)
1380 else if (current_bss->level < -70)
1385 if (abs(current_bss->level - selected->level) < min_diff) {
1386 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1392 #else /* CONFIG_NO_ROAMING */
1394 #endif /* CONFIG_NO_ROAMING */
1398 /* Return != 0 if no scan results could be fetched or if scan results should not
1399 * be shared with other virtual interfaces. */
1400 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1401 union wpa_event_data *data,
1404 struct wpa_scan_results *scan_res = NULL;
1407 #ifndef CONFIG_NO_RANDOM_POOL
1409 #endif /* CONFIG_NO_RANDOM_POOL */
1412 if (wpa_s->ap_iface)
1414 #endif /* CONFIG_AP */
1416 wpa_supplicant_notify_scanning(wpa_s, 0);
1418 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1419 data ? &data->scan_info :
1421 if (scan_res == NULL) {
1422 if (wpa_s->conf->ap_scan == 2 || ap ||
1423 wpa_s->scan_res_handler == scan_only_handler)
1427 if (data && data->scan_info.external_scan)
1429 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1431 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1433 goto scan_work_done;
1436 #ifndef CONFIG_NO_RANDOM_POOL
1437 num = scan_res->num;
1440 for (i = 0; i < num; i++) {
1442 struct wpa_scan_res *res = scan_res->res[i];
1443 buf[0] = res->bssid[5];
1444 buf[1] = res->qual & 0xff;
1445 buf[2] = res->noise & 0xff;
1446 buf[3] = res->level & 0xff;
1447 buf[4] = res->tsf & 0xff;
1448 random_add_randomness(buf, sizeof(buf));
1450 #endif /* CONFIG_NO_RANDOM_POOL */
1452 if (own_request && wpa_s->scan_res_handler &&
1453 !(data && data->scan_info.external_scan)) {
1454 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1455 struct wpa_scan_results *scan_res);
1457 scan_res_handler = wpa_s->scan_res_handler;
1458 wpa_s->scan_res_handler = NULL;
1459 scan_res_handler(wpa_s, scan_res);
1461 goto scan_work_done;
1465 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1467 if (wpa_s->ap_iface->scan_cb)
1468 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1469 #endif /* CONFIG_AP */
1470 goto scan_work_done;
1473 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1474 wpa_s->own_scan_running,
1475 data ? data->scan_info.external_scan : 0);
1476 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1477 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1478 own_request && !(data && data->scan_info.external_scan)) {
1479 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1480 wpa_s->manual_scan_id);
1481 wpa_s->manual_scan_use_id = 0;
1483 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1485 wpas_notify_scan_results(wpa_s);
1487 wpas_notify_scan_done(wpa_s, 1);
1489 if (data && data->scan_info.external_scan) {
1490 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1491 wpa_scan_results_free(scan_res);
1495 if (wnm_scan_process(wpa_s, 1) > 0)
1496 goto scan_work_done;
1498 if (sme_proc_obss_scan(wpa_s) > 0)
1499 goto scan_work_done;
1501 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1502 goto scan_work_done;
1504 if (autoscan_notify_scan(wpa_s, scan_res))
1505 goto scan_work_done;
1507 if (wpa_s->disconnected) {
1508 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1509 goto scan_work_done;
1512 if (!wpas_driver_bss_selection(wpa_s) &&
1513 bgscan_notify_scan(wpa_s, scan_res) == 1)
1514 goto scan_work_done;
1516 wpas_wps_update_ap_info(wpa_s, scan_res);
1518 wpa_scan_results_free(scan_res);
1520 if (own_request && wpa_s->scan_work) {
1521 struct wpa_radio_work *work = wpa_s->scan_work;
1522 wpa_s->scan_work = NULL;
1523 radio_work_done(work);
1526 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1529 wpa_scan_results_free(scan_res);
1530 if (own_request && wpa_s->scan_work) {
1531 struct wpa_radio_work *work = wpa_s->scan_work;
1532 wpa_s->scan_work = NULL;
1533 radio_work_done(work);
1539 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1540 int new_scan, int own_request)
1542 struct wpa_bss *selected;
1543 struct wpa_ssid *ssid = NULL;
1544 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1546 if (time_to_reenable > 0) {
1547 wpa_dbg(wpa_s, MSG_DEBUG,
1548 "Postpone network selection by %d seconds since all networks are disabled",
1550 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1551 eloop_register_timeout(time_to_reenable, 0,
1552 wpas_network_reenabled, wpa_s, NULL);
1556 if (wpa_s->p2p_mgmt)
1557 return 0; /* no normal connection on p2p_mgmt interface */
1559 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1563 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1566 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1570 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1571 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1575 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1577 * Do not notify other virtual radios of scan results since we do not
1578 * want them to start other associations at the same time.
1584 wpa_msg(wpa_s, MSG_INFO,
1585 "Avoiding join because we already joined a mesh group");
1588 #endif /* CONFIG_MESH */
1589 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1590 ssid = wpa_supplicant_pick_new_network(wpa_s);
1592 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1593 wpa_supplicant_associate(wpa_s, NULL, ssid);
1595 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1596 } else if (own_request) {
1598 * No SSID found. If SCAN results are as a result of
1599 * own scan request and not due to a scan request on
1600 * another shared interface, try another scan.
1602 int timeout_sec = wpa_s->scan_interval;
1603 int timeout_usec = 0;
1607 res = wpas_p2p_scan_no_go_seen(wpa_s);
1613 if (wpa_s->p2p_in_provisioning ||
1614 wpa_s->show_group_started ||
1615 wpa_s->p2p_in_invitation) {
1617 * Use shorter wait during P2P Provisioning
1618 * state and during P2P join-a-group operation
1619 * to speed up group formation.
1622 timeout_usec = 250000;
1623 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1627 #endif /* CONFIG_P2P */
1628 #ifdef CONFIG_INTERWORKING
1629 if (wpa_s->conf->auto_interworking &&
1630 wpa_s->conf->interworking &&
1631 wpa_s->conf->cred) {
1632 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1633 "start ANQP fetch since no matching "
1635 wpa_s->network_select = 1;
1636 wpa_s->auto_network_select = 1;
1637 interworking_start_fetch_anqp(wpa_s);
1640 #endif /* CONFIG_INTERWORKING */
1642 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1643 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1645 timeout_usec = 500000;
1646 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1650 #endif /* CONFIG_WPS */
1651 if (wpa_supplicant_req_sched_scan(wpa_s))
1652 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1655 wpa_msg_ctrl(wpa_s, MSG_INFO,
1656 WPA_EVENT_NETWORK_NOT_FOUND);
1663 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1664 union wpa_event_data *data)
1666 struct wpa_supplicant *ifs;
1669 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1672 * Interface may have been removed, so must not dereference
1679 * If no scan results could be fetched, then no need to
1680 * notify those interfaces that did not actually request
1681 * this scan. Similarly, if scan results started a new operation on this
1682 * interface, do not notify other interfaces to avoid concurrent
1683 * operations during a connection attempt.
1689 * Check other interfaces to see if they share the same radio. If
1690 * so, they get updated with this same scan info.
1692 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1695 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1696 "sibling", ifs->ifname);
1697 _wpa_supplicant_event_scan_results(ifs, data, 0);
1704 #endif /* CONFIG_NO_SCAN_PROCESSING */
1707 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1709 #ifdef CONFIG_NO_SCAN_PROCESSING
1711 #else /* CONFIG_NO_SCAN_PROCESSING */
1712 struct os_reltime now;
1714 if (wpa_s->last_scan_res_used == 0)
1717 os_get_reltime(&now);
1718 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1719 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1723 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1724 #endif /* CONFIG_NO_SCAN_PROCESSING */
1729 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1731 struct wpa_supplicant *wpa_s = eloop_ctx;
1733 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1736 if (!wpa_s->no_keep_alive) {
1737 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1738 MAC2STR(wpa_s->bssid));
1739 /* TODO: could skip this if normal data traffic has been sent */
1740 /* TODO: Consider using some more appropriate data frame for
1743 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1748 if (wpa_s->sme.bss_max_idle_period) {
1750 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1753 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1754 wnm_bss_keep_alive, wpa_s, NULL);
1756 #endif /* CONFIG_SME */
1760 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1761 const u8 *ies, size_t ies_len)
1763 struct ieee802_11_elems elems;
1768 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1772 if (elems.bss_max_idle_period) {
1774 wpa_s->sme.bss_max_idle_period =
1775 WPA_GET_LE16(elems.bss_max_idle_period);
1776 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1777 "TU)%s", wpa_s->sme.bss_max_idle_period,
1778 (elems.bss_max_idle_period[2] & 0x01) ?
1779 " (protected keep-live required)" : "");
1780 if (wpa_s->sme.bss_max_idle_period == 0)
1781 wpa_s->sme.bss_max_idle_period = 1;
1782 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1783 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1784 /* msec times 1000 */
1785 msec = wpa_s->sme.bss_max_idle_period * 1024;
1788 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1789 wnm_bss_keep_alive, wpa_s,
1793 #endif /* CONFIG_SME */
1796 #endif /* CONFIG_WNM */
1799 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1802 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1803 #endif /* CONFIG_WNM */
1807 #ifdef CONFIG_INTERWORKING
1809 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1814 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1815 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1817 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1824 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1825 const u8 *ies, size_t ies_len)
1827 struct ieee802_11_elems elems;
1832 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1835 if (elems.qos_map_set) {
1836 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1837 elems.qos_map_set_len);
1841 #endif /* CONFIG_INTERWORKING */
1844 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1845 union wpa_event_data *data)
1847 int l, len, found = 0, wpa_found, rsn_found;
1849 #ifdef CONFIG_IEEE80211R
1851 #endif /* CONFIG_IEEE80211R */
1853 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1854 if (data->assoc_info.req_ies)
1855 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1856 data->assoc_info.req_ies_len);
1857 if (data->assoc_info.resp_ies) {
1858 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1859 data->assoc_info.resp_ies_len);
1861 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1862 data->assoc_info.resp_ies_len);
1863 #endif /* CONFIG_TDLS */
1865 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1866 data->assoc_info.resp_ies_len);
1867 #endif /* CONFIG_WNM */
1868 #ifdef CONFIG_INTERWORKING
1869 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1870 data->assoc_info.resp_ies_len);
1871 #endif /* CONFIG_INTERWORKING */
1873 if (data->assoc_info.beacon_ies)
1874 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1875 data->assoc_info.beacon_ies,
1876 data->assoc_info.beacon_ies_len);
1877 if (data->assoc_info.freq)
1878 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1879 data->assoc_info.freq);
1881 p = data->assoc_info.req_ies;
1882 l = data->assoc_info.req_ies_len;
1884 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1885 while (p && l >= 2) {
1888 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1892 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1893 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1894 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1895 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1898 wpa_find_assoc_pmkid(wpa_s);
1904 if (!found && data->assoc_info.req_ies)
1905 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1907 #ifdef CONFIG_IEEE80211R
1909 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1910 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1911 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1912 data->assoc_info.resp_ies,
1913 data->assoc_info.resp_ies_len,
1915 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1916 "Reassociation Response failed");
1917 wpa_supplicant_deauthenticate(
1918 wpa_s, WLAN_REASON_INVALID_IE);
1923 p = data->assoc_info.resp_ies;
1924 l = data->assoc_info.resp_ies_len;
1926 #ifdef CONFIG_WPS_STRICT
1927 if (p && wpa_s->current_ssid &&
1928 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1930 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1932 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1933 "include WPS IE in (Re)Association Response");
1937 if (wps_validate_assoc_resp(wps) < 0) {
1939 wpa_supplicant_deauthenticate(
1940 wpa_s, WLAN_REASON_INVALID_IE);
1945 #endif /* CONFIG_WPS_STRICT */
1947 /* Go through the IEs and make a copy of the MDIE, if present. */
1948 while (p && l >= 2) {
1951 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1955 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1956 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1957 wpa_s->sme.ft_used = 1;
1958 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1959 MOBILITY_DOMAIN_ID_LEN);
1965 #endif /* CONFIG_SME */
1967 /* Process FT when SME is in the driver */
1968 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1969 wpa_ft_is_completed(wpa_s->wpa)) {
1970 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1971 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1972 data->assoc_info.resp_ies,
1973 data->assoc_info.resp_ies_len,
1975 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1976 "Reassociation Response failed");
1977 wpa_supplicant_deauthenticate(
1978 wpa_s, WLAN_REASON_INVALID_IE);
1981 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1984 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1985 data->assoc_info.resp_ies_len);
1986 #endif /* CONFIG_IEEE80211R */
1988 /* WPA/RSN IE from Beacon/ProbeResp */
1989 p = data->assoc_info.beacon_ies;
1990 l = data->assoc_info.beacon_ies_len;
1992 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1994 wpa_found = rsn_found = 0;
1995 while (p && l >= 2) {
1998 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2003 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2004 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2006 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2010 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2012 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2019 if (!wpa_found && data->assoc_info.beacon_ies)
2020 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2021 if (!rsn_found && data->assoc_info.beacon_ies)
2022 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2023 if (wpa_found || rsn_found)
2024 wpa_s->ap_ies_from_associnfo = 1;
2027 wpabuf_free(wpa_s->received_mb_ies);
2028 wpa_s->received_mb_ies = NULL;
2030 struct mb_ies_info mb_ies;
2032 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2033 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2034 data->assoc_info.resp_ies_len))
2035 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2037 #endif /* CONFIG_FST */
2039 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2040 wpa_s->assoc_freq != data->assoc_info.freq) {
2041 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2043 wpa_s->assoc_freq, data->assoc_info.freq);
2044 wpa_supplicant_update_scan_results(wpa_s);
2047 wpa_s->assoc_freq = data->assoc_info.freq;
2053 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2055 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2057 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2060 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2063 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2064 WPA_IE_VENDOR_TYPE);
2065 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2067 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2068 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2069 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2070 bss_rsn ? 2 + bss_rsn[1] : 0))
2077 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2078 union wpa_event_data *data)
2085 if (wpa_s->ap_iface) {
2088 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2089 data->assoc_info.addr,
2090 data->assoc_info.req_ies,
2091 data->assoc_info.req_ies_len,
2092 data->assoc_info.reassoc);
2095 #endif /* CONFIG_AP */
2097 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2099 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2100 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2103 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2104 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2105 wpa_supplicant_deauthenticate(
2106 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2110 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2111 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2112 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2113 MACSTR, MAC2STR(bssid));
2115 random_add_randomness(bssid, ETH_ALEN);
2116 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2117 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2118 wpas_notify_bssid_changed(wpa_s);
2120 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2121 wpa_clear_keys(wpa_s, bssid);
2123 if (wpa_supplicant_select_config(wpa_s) < 0) {
2124 wpa_supplicant_deauthenticate(
2125 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2130 if (wpa_s->conf->ap_scan == 1 &&
2131 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2132 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2133 wpa_msg(wpa_s, MSG_WARNING,
2134 "WPA/RSN IEs not updated");
2138 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2139 wpa_s->sme.prev_bssid_set = 1;
2140 wpa_s->sme.last_unprot_disconnect.sec = 0;
2141 #endif /* CONFIG_SME */
2143 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2144 if (wpa_s->current_ssid) {
2145 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2146 * initialized before association, but for other modes,
2147 * initialize PC/SC here, if the current configuration needs
2148 * smartcard or SIM/USIM. */
2149 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2151 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2153 l2_packet_notify_auth_start(wpa_s->l2);
2156 * Set portEnabled first to FALSE in order to get EAP state machine out
2157 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2158 * state machine may transit to AUTHENTICATING state based on obsolete
2159 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2160 * AUTHENTICATED without ever giving chance to EAP state machine to
2163 if (!ft_completed) {
2164 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2165 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2167 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2168 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2169 /* 802.1X::portControl = Auto */
2170 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2171 wpa_s->eapol_received = 0;
2172 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2173 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2174 (wpa_s->current_ssid &&
2175 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2176 if (wpa_s->current_ssid &&
2177 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2179 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2181 * Set the key after having received joined-IBSS event
2184 wpa_supplicant_set_wpa_none_key(wpa_s,
2185 wpa_s->current_ssid);
2187 wpa_supplicant_cancel_auth_timeout(wpa_s);
2188 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2189 } else if (!ft_completed) {
2190 /* Timeout for receiving the first EAPOL packet */
2191 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2193 wpa_supplicant_cancel_scan(wpa_s);
2195 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2196 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2198 * We are done; the driver will take care of RSN 4-way
2201 wpa_supplicant_cancel_auth_timeout(wpa_s);
2202 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2203 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2204 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2205 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2206 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2208 * The driver will take care of RSN 4-way handshake, so we need
2209 * to allow EAPOL supplicant to complete its work without
2210 * waiting for WPA supplicant.
2212 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2213 } else if (ft_completed) {
2215 * FT protocol completed - make sure EAPOL state machine ends
2216 * up in authenticated.
2218 wpa_supplicant_cancel_auth_timeout(wpa_s);
2219 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2220 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2221 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2224 wpa_s->last_eapol_matches_bssid = 0;
2226 if (wpa_s->pending_eapol_rx) {
2227 struct os_reltime now, age;
2228 os_get_reltime(&now);
2229 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2230 if (age.sec == 0 && age.usec < 100000 &&
2231 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2233 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2234 "frame that was received just before "
2235 "association notification");
2236 wpa_supplicant_rx_eapol(
2237 wpa_s, wpa_s->pending_eapol_rx_src,
2238 wpabuf_head(wpa_s->pending_eapol_rx),
2239 wpabuf_len(wpa_s->pending_eapol_rx));
2241 wpabuf_free(wpa_s->pending_eapol_rx);
2242 wpa_s->pending_eapol_rx = NULL;
2245 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2246 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2247 wpa_s->current_ssid &&
2248 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2249 /* Set static WEP keys again */
2250 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2253 #ifdef CONFIG_IBSS_RSN
2254 if (wpa_s->current_ssid &&
2255 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2256 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2257 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2258 wpa_s->ibss_rsn == NULL) {
2259 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2260 if (!wpa_s->ibss_rsn) {
2261 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2262 wpa_supplicant_deauthenticate(
2263 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2267 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2269 #endif /* CONFIG_IBSS_RSN */
2271 wpas_wps_notify_assoc(wpa_s, bssid);
2274 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2275 data->assoc_info.resp_ies_len,
2276 &data->assoc_info.wmm_params);
2278 if (wpa_s->reassoc_same_bss)
2279 wmm_ac_restore_tspecs(wpa_s);
2284 static int disconnect_reason_recoverable(u16 reason_code)
2286 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2287 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2288 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2292 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2294 int locally_generated)
2298 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2300 * At least Host AP driver and a Prism3 card seemed to be
2301 * generating streams of disconnected events when configuring
2302 * IBSS for WPA-None. Ignore them for now.
2307 bssid = wpa_s->bssid;
2308 if (is_zero_ether_addr(bssid))
2309 bssid = wpa_s->pending_bssid;
2311 if (!is_zero_ether_addr(bssid) ||
2312 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2313 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2315 MAC2STR(bssid), reason_code,
2316 locally_generated ? " locally_generated=1" : "");
2321 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2322 int locally_generated)
2324 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2325 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2326 return 0; /* Not in 4-way handshake with PSK */
2329 * It looks like connection was lost while trying to go through PSK
2330 * 4-way handshake. Filter out known disconnection cases that are caused
2331 * by something else than PSK mismatch to avoid confusing reports.
2334 if (locally_generated) {
2335 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2343 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2345 int locally_generated)
2349 u8 prev_pending_bssid[ETH_ALEN];
2350 struct wpa_bss *fast_reconnect = NULL;
2351 struct wpa_ssid *fast_reconnect_ssid = NULL;
2352 struct wpa_ssid *last_ssid;
2354 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2355 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2357 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2359 * At least Host AP driver and a Prism3 card seemed to be
2360 * generating streams of disconnected events when configuring
2361 * IBSS for WPA-None. Ignore them for now.
2363 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2364 "IBSS/WPA-None mode");
2368 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2369 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2370 "pre-shared key may be incorrect");
2371 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2372 return; /* P2P group removed */
2373 wpas_auth_failed(wpa_s, "WRONG_KEY");
2375 if (!wpa_s->disconnected &&
2376 (!wpa_s->auto_reconnect_disabled ||
2377 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2378 wpas_wps_searching(wpa_s))) {
2379 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2380 "reconnect (wps=%d/%d wpa_state=%d)",
2381 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2382 wpas_wps_searching(wpa_s),
2384 if (wpa_s->wpa_state == WPA_COMPLETED &&
2385 wpa_s->current_ssid &&
2386 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2387 !locally_generated &&
2388 disconnect_reason_recoverable(reason_code)) {
2390 * It looks like the AP has dropped association with
2391 * us, but could allow us to get back in. Try to
2392 * reconnect to the same BSS without full scan to save
2393 * time for some common cases.
2395 fast_reconnect = wpa_s->current_bss;
2396 fast_reconnect_ssid = wpa_s->current_ssid;
2397 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2398 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2400 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2403 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2404 "try to re-connect");
2405 wpa_s->reassociate = 0;
2406 wpa_s->disconnected = 1;
2408 wpa_supplicant_cancel_sched_scan(wpa_s);
2410 bssid = wpa_s->bssid;
2411 if (is_zero_ether_addr(bssid))
2412 bssid = wpa_s->pending_bssid;
2413 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2414 wpas_connection_failed(wpa_s, bssid);
2415 wpa_sm_notify_disassoc(wpa_s->wpa);
2416 if (locally_generated)
2417 wpa_s->disconnect_reason = -reason_code;
2419 wpa_s->disconnect_reason = reason_code;
2420 wpas_notify_disconnect_reason(wpa_s);
2421 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2422 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2423 wpa_clear_keys(wpa_s, wpa_s->bssid);
2425 last_ssid = wpa_s->current_ssid;
2426 wpa_supplicant_mark_disassoc(wpa_s);
2428 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2429 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2430 wpa_s->current_ssid = last_ssid;
2433 if (fast_reconnect &&
2434 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2435 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2436 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2437 fast_reconnect->ssid_len) &&
2438 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2439 #ifndef CONFIG_NO_SCAN_PROCESSING
2440 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2441 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2442 fast_reconnect_ssid) < 0) {
2443 /* Recover through full scan */
2444 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2446 #endif /* CONFIG_NO_SCAN_PROCESSING */
2447 } else if (fast_reconnect) {
2449 * Could not reconnect to the same BSS due to network being
2450 * disabled. Use a new scan to match the alternative behavior
2451 * above, i.e., to continue automatic reconnection attempt in a
2452 * way that enforces disabled network rules.
2454 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2459 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2460 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2462 struct wpa_supplicant *wpa_s = eloop_ctx;
2464 if (!wpa_s->pending_mic_error_report)
2467 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2468 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2469 wpa_s->pending_mic_error_report = 0;
2471 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2475 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2476 union wpa_event_data *data)
2479 struct os_reltime t;
2481 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2482 pairwise = (data && data->michael_mic_failure.unicast);
2484 if ((wpa_s->last_michael_mic_error.sec &&
2485 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2486 wpa_s->pending_mic_error_report) {
2487 if (wpa_s->pending_mic_error_report) {
2489 * Send the pending MIC error report immediately since
2490 * we are going to start countermeasures and AP better
2493 wpa_sm_key_request(wpa_s->wpa, 1,
2494 wpa_s->pending_mic_error_pairwise);
2497 /* Send the new MIC error report immediately since we are going
2498 * to start countermeasures and AP better do the same.
2500 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2502 /* initialize countermeasures */
2503 wpa_s->countermeasures = 1;
2505 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2507 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2510 * Need to wait for completion of request frame. We do not get
2511 * any callback for the message completion, so just wait a
2512 * short while and hope for the best. */
2515 wpa_drv_set_countermeasures(wpa_s, 1);
2516 wpa_supplicant_deauthenticate(wpa_s,
2517 WLAN_REASON_MICHAEL_MIC_FAILURE);
2518 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2520 eloop_register_timeout(60, 0,
2521 wpa_supplicant_stop_countermeasures,
2523 /* TODO: mark the AP rejected for 60 second. STA is
2524 * allowed to associate with another AP.. */
2526 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2527 if (wpa_s->mic_errors_seen) {
2529 * Reduce the effectiveness of Michael MIC error
2530 * reports as a means for attacking against TKIP if
2531 * more than one MIC failure is noticed with the same
2532 * PTK. We delay the transmission of the reports by a
2533 * random time between 0 and 60 seconds in order to
2534 * force the attacker wait 60 seconds before getting
2535 * the information on whether a frame resulted in a MIC
2541 if (os_get_random(rval, sizeof(rval)) < 0)
2542 sec = os_random() % 60;
2544 sec = WPA_GET_BE32(rval) % 60;
2545 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2546 "report %d seconds", sec);
2547 wpa_s->pending_mic_error_report = 1;
2548 wpa_s->pending_mic_error_pairwise = pairwise;
2549 eloop_cancel_timeout(
2550 wpa_supplicant_delayed_mic_error_report,
2552 eloop_register_timeout(
2553 sec, os_random() % 1000000,
2554 wpa_supplicant_delayed_mic_error_report,
2557 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2559 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2560 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2561 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2563 wpa_s->last_michael_mic_error = t;
2564 wpa_s->mic_errors_seen++;
2568 #ifdef CONFIG_TERMINATE_ONLASTIF
2569 static int any_interfaces(struct wpa_supplicant *head)
2571 struct wpa_supplicant *wpa_s;
2573 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2574 if (!wpa_s->interface_removed)
2578 #endif /* CONFIG_TERMINATE_ONLASTIF */
2582 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2583 union wpa_event_data *data)
2585 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2588 switch (data->interface_status.ievent) {
2589 case EVENT_INTERFACE_ADDED:
2590 if (!wpa_s->interface_removed)
2592 wpa_s->interface_removed = 0;
2593 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2594 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2595 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2596 "driver after interface was added");
2600 if (!wpa_s->global->p2p &&
2601 !wpa_s->global->p2p_disabled &&
2602 !wpa_s->conf->p2p_disabled &&
2604 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2605 wpas_p2p_add_p2pdev_interface(
2606 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2607 wpa_printf(MSG_INFO,
2608 "P2P: Failed to enable P2P Device interface");
2609 /* Try to continue without. P2P will be disabled. */
2611 #endif /* CONFIG_P2P */
2614 case EVENT_INTERFACE_REMOVED:
2615 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2616 wpa_s->interface_removed = 1;
2617 wpa_supplicant_mark_disassoc(wpa_s);
2618 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2619 l2_packet_deinit(wpa_s->l2);
2623 if (wpa_s->global->p2p &&
2624 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2626 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2627 wpa_dbg(wpa_s, MSG_DEBUG,
2628 "Removing P2P Device interface");
2629 wpa_supplicant_remove_iface(
2630 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2632 wpa_s->global->p2p_init_wpa_s = NULL;
2634 #endif /* CONFIG_P2P */
2636 #ifdef CONFIG_TERMINATE_ONLASTIF
2637 /* check if last interface */
2638 if (!any_interfaces(wpa_s->global->ifaces))
2640 #endif /* CONFIG_TERMINATE_ONLASTIF */
2646 #ifdef CONFIG_PEERKEY
2648 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2649 union wpa_event_data *data)
2653 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2655 #endif /* CONFIG_PEERKEY */
2659 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2660 union wpa_event_data *data)
2664 switch (data->tdls.oper) {
2665 case TDLS_REQUEST_SETUP:
2666 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2667 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2668 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2670 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2672 case TDLS_REQUEST_TEARDOWN:
2673 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2674 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2675 data->tdls.reason_code);
2677 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2680 case TDLS_REQUEST_DISCOVER:
2681 wpa_tdls_send_discovery_request(wpa_s->wpa,
2686 #endif /* CONFIG_TDLS */
2690 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2691 union wpa_event_data *data)
2695 switch (data->wnm.oper) {
2696 case WNM_OPER_SLEEP:
2697 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2698 "(action=%d, intval=%d)",
2699 data->wnm.sleep_action, data->wnm.sleep_intval);
2700 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2701 data->wnm.sleep_intval, NULL);
2705 #endif /* CONFIG_WNM */
2708 #ifdef CONFIG_IEEE80211R
2710 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2711 union wpa_event_data *data)
2716 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2717 data->ft_ies.ies_len,
2718 data->ft_ies.ft_action,
2719 data->ft_ies.target_ap,
2720 data->ft_ies.ric_ies,
2721 data->ft_ies.ric_ies_len) < 0) {
2722 /* TODO: prevent MLME/driver from trying to associate? */
2725 #endif /* CONFIG_IEEE80211R */
2728 #ifdef CONFIG_IBSS_RSN
2729 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2730 union wpa_event_data *data)
2732 struct wpa_ssid *ssid;
2733 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2737 ssid = wpa_s->current_ssid;
2740 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2743 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2747 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2748 union wpa_event_data *data)
2750 struct wpa_ssid *ssid = wpa_s->current_ssid;
2755 /* check if the ssid is correctly configured as IBSS/RSN */
2756 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2759 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2760 data->rx_mgmt.frame_len);
2762 #endif /* CONFIG_IBSS_RSN */
2765 #ifdef CONFIG_IEEE80211R
2766 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2769 const u8 *sta_addr, *target_ap_addr;
2772 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2773 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2774 return; /* only SME case supported for now */
2775 if (len < 1 + 2 * ETH_ALEN + 2)
2778 return; /* Only FT Action Response is supported for now */
2779 sta_addr = data + 1;
2780 target_ap_addr = data + 1 + ETH_ALEN;
2781 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2782 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2783 MACSTR " TargetAP " MACSTR " status %u",
2784 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2786 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2787 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2788 " in FT Action Response", MAC2STR(sta_addr));
2793 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2794 "failure (status code %d)", status);
2795 /* TODO: report error to FT code(?) */
2799 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2800 len - (1 + 2 * ETH_ALEN + 2), 1,
2801 target_ap_addr, NULL, 0) < 0)
2806 struct wpa_bss *bss;
2807 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2809 wpa_s->sme.freq = bss->freq;
2810 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2811 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2814 #endif /* CONFIG_SME */
2816 #endif /* CONFIG_IEEE80211R */
2819 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2820 struct unprot_deauth *e)
2822 #ifdef CONFIG_IEEE80211W
2823 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2824 "dropped: " MACSTR " -> " MACSTR
2825 " (reason code %u)",
2826 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2827 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2828 #endif /* CONFIG_IEEE80211W */
2832 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2833 struct unprot_disassoc *e)
2835 #ifdef CONFIG_IEEE80211W
2836 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2837 "dropped: " MACSTR " -> " MACSTR
2838 " (reason code %u)",
2839 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2840 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2841 #endif /* CONFIG_IEEE80211W */
2845 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2846 u16 reason_code, int locally_generated,
2847 const u8 *ie, size_t ie_len, int deauth)
2850 if (wpa_s->ap_iface && addr) {
2851 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2855 if (wpa_s->ap_iface) {
2856 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2859 #endif /* CONFIG_AP */
2861 if (!locally_generated)
2862 wpa_s->own_disconnect_req = 0;
2864 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2866 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2867 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2868 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2869 eapol_sm_failed(wpa_s->eapol))) &&
2870 !wpa_s->eap_expected_failure))
2871 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2874 if (deauth && reason_code > 0) {
2875 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2876 locally_generated) > 0) {
2878 * The interface was removed, so cannot continue
2879 * processing any additional operations after this.
2884 #endif /* CONFIG_P2P */
2886 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2891 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2892 struct disassoc_info *info)
2894 u16 reason_code = 0;
2895 int locally_generated = 0;
2896 const u8 *addr = NULL;
2897 const u8 *ie = NULL;
2900 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2905 ie_len = info->ie_len;
2906 reason_code = info->reason_code;
2907 locally_generated = info->locally_generated;
2908 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2909 locally_generated ? " (locally generated)" : "");
2911 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2913 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2918 if (wpa_s->ap_iface && info && info->addr) {
2919 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2923 if (wpa_s->ap_iface) {
2924 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2927 #endif /* CONFIG_AP */
2931 wpas_p2p_disassoc_notif(
2932 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2935 #endif /* CONFIG_P2P */
2937 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2938 sme_event_disassoc(wpa_s, info);
2940 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2945 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2946 struct deauth_info *info)
2948 u16 reason_code = 0;
2949 int locally_generated = 0;
2950 const u8 *addr = NULL;
2951 const u8 *ie = NULL;
2954 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2959 ie_len = info->ie_len;
2960 reason_code = info->reason_code;
2961 locally_generated = info->locally_generated;
2962 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2964 locally_generated ? " (locally generated)" : "");
2966 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2969 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2973 wpa_reset_ft_completed(wpa_s->wpa);
2975 wpas_event_disconnect(wpa_s, addr, reason_code,
2976 locally_generated, ie, ie_len, 1);
2980 static const char * reg_init_str(enum reg_change_initiator init)
2983 case REGDOM_SET_BY_CORE:
2985 case REGDOM_SET_BY_USER:
2987 case REGDOM_SET_BY_DRIVER:
2989 case REGDOM_SET_BY_COUNTRY_IE:
2990 return "COUNTRY_IE";
2991 case REGDOM_BEACON_HINT:
2992 return "BEACON_HINT";
2998 static const char * reg_type_str(enum reg_type type)
3001 case REGDOM_TYPE_UNKNOWN:
3003 case REGDOM_TYPE_COUNTRY:
3005 case REGDOM_TYPE_WORLD:
3007 case REGDOM_TYPE_CUSTOM_WORLD:
3008 return "CUSTOM_WORLD";
3009 case REGDOM_TYPE_INTERSECTION:
3010 return "INTERSECTION";
3016 static void wpa_supplicant_update_channel_list(
3017 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3019 struct wpa_supplicant *ifs;
3021 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3022 reg_init_str(info->initiator), reg_type_str(info->type),
3023 info->alpha2[0] ? " alpha2=" : "",
3024 info->alpha2[0] ? info->alpha2 : "");
3026 if (wpa_s->drv_priv == NULL)
3027 return; /* Ignore event during drv initialization */
3029 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3031 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3033 free_hw_features(ifs);
3034 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3035 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3038 /* Restart sched_scan with updated channel list */
3039 if (wpa_s->sched_scanning) {
3040 wpa_dbg(wpa_s, MSG_DEBUG,
3041 "Channel list changed restart sched scan.");
3042 wpa_supplicant_cancel_sched_scan(wpa_s);
3043 wpa_supplicant_req_scan(wpa_s, 0, 0);
3046 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3050 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3051 const u8 *frame, size_t len, int freq,
3054 const struct ieee80211_mgmt *mgmt;
3059 if (len < IEEE80211_HDRLEN + 2)
3062 mgmt = (const struct ieee80211_mgmt *) frame;
3063 payload = frame + IEEE80211_HDRLEN;
3064 category = *payload++;
3065 plen = len - IEEE80211_HDRLEN - 1;
3067 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3068 " Category=%u DataLen=%d freq=%d MHz",
3069 MAC2STR(mgmt->sa), category, (int) plen, freq);
3071 if (category == WLAN_ACTION_WMM) {
3072 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3076 #ifdef CONFIG_IEEE80211R
3077 if (category == WLAN_ACTION_FT) {
3078 ft_rx_action(wpa_s, payload, plen);
3081 #endif /* CONFIG_IEEE80211R */
3083 #ifdef CONFIG_IEEE80211W
3085 if (category == WLAN_ACTION_SA_QUERY) {
3086 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3089 #endif /* CONFIG_SME */
3090 #endif /* CONFIG_IEEE80211W */
3093 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3094 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3097 #endif /* CONFIG_WNM */
3100 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3101 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3102 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3103 mgmt->u.action.category,
3104 payload, plen, freq) == 0)
3106 #endif /* CONFIG_GAS */
3109 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3110 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3111 wpa_dbg(wpa_s, MSG_DEBUG,
3112 "TDLS: Received Discovery Response from " MACSTR,
3116 #endif /* CONFIG_TDLS */
3118 #ifdef CONFIG_INTERWORKING
3119 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3120 payload[0] == QOS_QOS_MAP_CONFIG) {
3121 const u8 *pos = payload + 1;
3122 size_t qlen = plen - 1;
3123 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3124 MACSTR, MAC2STR(mgmt->sa));
3125 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3126 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3127 pos[1] <= qlen - 2 && pos[1] >= 16)
3128 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3131 #endif /* CONFIG_INTERWORKING */
3133 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3134 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3135 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3139 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3140 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3141 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3142 payload + 1, plen - 1,
3148 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3149 fst_rx_action(wpa_s->fst, mgmt, len);
3152 #endif /* CONFIG_FST */
3154 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3155 category, payload, plen, freq);
3157 mesh_mpm_action_rx(wpa_s, mgmt, len);
3161 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3162 union wpa_event_data *event)
3164 struct wpa_freq_range_list *list;
3167 list = &event->freq_range;
3170 str = freq_range_list_str(list);
3171 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3175 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3176 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3179 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3182 * The update channel flow will also take care of moving a GO
3183 * from the unsafe frequency if needed.
3185 wpas_p2p_update_channel_list(wpa_s,
3186 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3188 #endif /* CONFIG_P2P */
3194 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3195 union wpa_event_data *data)
3197 wpa_dbg(wpa_s, MSG_DEBUG,
3198 "Connection authorized by device, previous state %d",
3200 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3201 wpa_supplicant_cancel_auth_timeout(wpa_s);
3202 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3203 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3204 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3206 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3207 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3208 data->assoc_info.ptk_kck_len,
3209 data->assoc_info.ptk_kek,
3210 data->assoc_info.ptk_kek_len);
3214 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3215 union wpa_event_data *data)
3217 struct wpa_supplicant *wpa_s = ctx;
3220 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3221 event != EVENT_INTERFACE_ENABLED &&
3222 event != EVENT_INTERFACE_STATUS &&
3223 event != EVENT_SCHED_SCAN_STOPPED) {
3224 wpa_dbg(wpa_s, MSG_DEBUG,
3225 "Ignore event %s (%d) while interface is disabled",
3226 event_to_string(event), event);
3230 #ifndef CONFIG_NO_STDOUT_DEBUG
3232 int level = MSG_DEBUG;
3234 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3235 const struct ieee80211_hdr *hdr;
3237 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3238 fc = le_to_host16(hdr->frame_control);
3239 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3240 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3241 level = MSG_EXCESSIVE;
3244 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3245 event_to_string(event), event);
3247 #endif /* CONFIG_NO_STDOUT_DEBUG */
3251 sme_event_auth(wpa_s, data);
3254 wpa_supplicant_event_assoc(wpa_s, data);
3255 if (data && data->assoc_info.authorized)
3256 wpa_supplicant_event_assoc_auth(wpa_s, data);
3258 case EVENT_DISASSOC:
3259 wpas_event_disassoc(wpa_s,
3260 data ? &data->disassoc_info : NULL);
3263 wpas_event_deauth(wpa_s,
3264 data ? &data->deauth_info : NULL);
3266 case EVENT_MICHAEL_MIC_FAILURE:
3267 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3269 #ifndef CONFIG_NO_SCAN_PROCESSING
3270 case EVENT_SCAN_STARTED:
3271 if (wpa_s->own_scan_requested ||
3272 (data && !data->scan_info.external_scan)) {
3273 struct os_reltime diff;
3275 os_get_reltime(&wpa_s->scan_start_time);
3276 os_reltime_sub(&wpa_s->scan_start_time,
3277 &wpa_s->scan_trigger_time, &diff);
3278 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3279 diff.sec, diff.usec);
3280 wpa_s->own_scan_requested = 0;
3281 wpa_s->own_scan_running = 1;
3282 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3283 wpa_s->manual_scan_use_id) {
3284 wpa_msg_ctrl(wpa_s, MSG_INFO,
3285 WPA_EVENT_SCAN_STARTED "id=%u",
3286 wpa_s->manual_scan_id);
3288 wpa_msg_ctrl(wpa_s, MSG_INFO,
3289 WPA_EVENT_SCAN_STARTED);
3292 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3293 wpa_s->radio->external_scan_running = 1;
3294 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3297 case EVENT_SCAN_RESULTS:
3298 if (!(data && data->scan_info.external_scan) &&
3299 os_reltime_initialized(&wpa_s->scan_start_time)) {
3300 struct os_reltime now, diff;
3301 os_get_reltime(&now);
3302 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3303 wpa_s->scan_start_time.sec = 0;
3304 wpa_s->scan_start_time.usec = 0;
3305 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3306 diff.sec, diff.usec);
3308 if (wpa_supplicant_event_scan_results(wpa_s, data))
3309 break; /* interface may have been removed */
3310 if (!(data && data->scan_info.external_scan))
3311 wpa_s->own_scan_running = 0;
3312 if (data && data->scan_info.nl_scan_event)
3313 wpa_s->radio->external_scan_running = 0;
3314 radio_work_check_next(wpa_s);
3316 #endif /* CONFIG_NO_SCAN_PROCESSING */
3317 case EVENT_ASSOCINFO:
3318 wpa_supplicant_event_associnfo(wpa_s, data);
3320 case EVENT_INTERFACE_STATUS:
3321 wpa_supplicant_event_interface_status(wpa_s, data);
3323 case EVENT_PMKID_CANDIDATE:
3324 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3326 #ifdef CONFIG_PEERKEY
3327 case EVENT_STKSTART:
3328 wpa_supplicant_event_stkstart(wpa_s, data);
3330 #endif /* CONFIG_PEERKEY */
3333 wpa_supplicant_event_tdls(wpa_s, data);
3335 #endif /* CONFIG_TDLS */
3338 wpa_supplicant_event_wnm(wpa_s, data);
3340 #endif /* CONFIG_WNM */
3341 #ifdef CONFIG_IEEE80211R
3342 case EVENT_FT_RESPONSE:
3343 wpa_supplicant_event_ft_response(wpa_s, data);
3345 #endif /* CONFIG_IEEE80211R */
3346 #ifdef CONFIG_IBSS_RSN
3347 case EVENT_IBSS_RSN_START:
3348 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3350 #endif /* CONFIG_IBSS_RSN */
3351 case EVENT_ASSOC_REJECT:
3352 if (data->assoc_reject.bssid)
3353 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3354 "bssid=" MACSTR " status_code=%u",
3355 MAC2STR(data->assoc_reject.bssid),
3356 data->assoc_reject.status_code);
3358 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3360 data->assoc_reject.status_code);
3361 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3362 sme_event_assoc_reject(wpa_s, data);
3364 const u8 *bssid = data->assoc_reject.bssid;
3365 if (bssid == NULL || is_zero_ether_addr(bssid))
3366 bssid = wpa_s->pending_bssid;
3367 wpas_connection_failed(wpa_s, bssid);
3368 wpa_supplicant_mark_disassoc(wpa_s);
3371 case EVENT_AUTH_TIMED_OUT:
3372 /* It is possible to get this event from earlier connection */
3373 if (wpa_s->current_ssid &&
3374 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3375 wpa_dbg(wpa_s, MSG_DEBUG,
3376 "Ignore AUTH_TIMED_OUT in mesh configuration");
3379 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3380 sme_event_auth_timed_out(wpa_s, data);
3382 case EVENT_ASSOC_TIMED_OUT:
3383 /* It is possible to get this event from earlier connection */
3384 if (wpa_s->current_ssid &&
3385 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3386 wpa_dbg(wpa_s, MSG_DEBUG,
3387 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3390 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3391 sme_event_assoc_timed_out(wpa_s, data);
3393 case EVENT_TX_STATUS:
3394 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3395 " type=%d stype=%d",
3396 MAC2STR(data->tx_status.dst),
3397 data->tx_status.type, data->tx_status.stype);
3399 if (wpa_s->ap_iface == NULL) {
3400 #ifdef CONFIG_OFFCHANNEL
3401 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3402 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3403 offchannel_send_action_tx_status(
3404 wpa_s, data->tx_status.dst,
3405 data->tx_status.data,
3406 data->tx_status.data_len,
3407 data->tx_status.ack ?
3408 OFFCHANNEL_SEND_ACTION_SUCCESS :
3409 OFFCHANNEL_SEND_ACTION_NO_ACK);
3410 #endif /* CONFIG_OFFCHANNEL */
3413 #endif /* CONFIG_AP */
3414 #ifdef CONFIG_OFFCHANNEL
3415 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3416 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3418 * Catch TX status events for Action frames we sent via group
3419 * interface in GO mode.
3421 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3422 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3423 os_memcmp(wpa_s->parent->pending_action_dst,
3424 data->tx_status.dst, ETH_ALEN) == 0) {
3425 offchannel_send_action_tx_status(
3426 wpa_s->parent, data->tx_status.dst,
3427 data->tx_status.data,
3428 data->tx_status.data_len,
3429 data->tx_status.ack ?
3430 OFFCHANNEL_SEND_ACTION_SUCCESS :
3431 OFFCHANNEL_SEND_ACTION_NO_ACK);
3434 #endif /* CONFIG_OFFCHANNEL */
3436 switch (data->tx_status.type) {
3437 case WLAN_FC_TYPE_MGMT:
3438 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3439 data->tx_status.data_len,
3440 data->tx_status.stype,
3441 data->tx_status.ack);
3443 case WLAN_FC_TYPE_DATA:
3444 ap_tx_status(wpa_s, data->tx_status.dst,
3445 data->tx_status.data,
3446 data->tx_status.data_len,
3447 data->tx_status.ack);
3450 #endif /* CONFIG_AP */
3453 case EVENT_EAPOL_TX_STATUS:
3454 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3455 data->eapol_tx_status.data,
3456 data->eapol_tx_status.data_len,
3457 data->eapol_tx_status.ack);
3459 case EVENT_DRIVER_CLIENT_POLL_OK:
3460 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3462 case EVENT_RX_FROM_UNKNOWN:
3463 if (wpa_s->ap_iface == NULL)
3465 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3466 data->rx_from_unknown.wds);
3468 case EVENT_CH_SWITCH:
3469 if (!data || !wpa_s->current_ssid)
3472 wpa_s->assoc_freq = data->ch_switch.freq;
3473 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3475 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3476 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3477 wpa_s->current_ssid->mode ==
3478 WPAS_MODE_P2P_GROUP_FORMATION) {
3479 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3480 data->ch_switch.ht_enabled,
3481 data->ch_switch.ch_offset,
3482 data->ch_switch.ch_width,
3483 data->ch_switch.cf1,
3484 data->ch_switch.cf2);
3487 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3490 case EVENT_DFS_RADAR_DETECTED:
3492 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3494 case EVENT_DFS_CAC_STARTED:
3496 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3498 case EVENT_DFS_CAC_FINISHED:
3500 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3502 case EVENT_DFS_CAC_ABORTED:
3504 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3506 case EVENT_DFS_NOP_FINISHED:
3508 wpas_event_dfs_cac_nop_finished(wpa_s,
3511 #endif /* NEED_AP_MLME */
3512 #endif /* CONFIG_AP */
3513 case EVENT_RX_MGMT: {
3515 const struct ieee80211_mgmt *mgmt;
3517 #ifdef CONFIG_TESTING_OPTIONS
3518 if (wpa_s->ext_mgmt_frame_handling) {
3519 struct rx_mgmt *rx = &data->rx_mgmt;
3520 size_t hex_len = 2 * rx->frame_len + 1;
3521 char *hex = os_malloc(hex_len);
3523 wpa_snprintf_hex(hex, hex_len,
3524 rx->frame, rx->frame_len);
3525 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3526 rx->freq, rx->datarate, rx->ssi_signal,
3532 #endif /* CONFIG_TESTING_OPTIONS */
3534 mgmt = (const struct ieee80211_mgmt *)
3535 data->rx_mgmt.frame;
3536 fc = le_to_host16(mgmt->frame_control);
3537 stype = WLAN_FC_GET_STYPE(fc);
3540 if (wpa_s->ap_iface == NULL) {
3541 #endif /* CONFIG_AP */
3543 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3544 data->rx_mgmt.frame_len > 24) {
3545 const u8 *src = mgmt->sa;
3546 const u8 *ie = mgmt->u.probe_req.variable;
3547 size_t ie_len = data->rx_mgmt.frame_len -
3548 (mgmt->u.probe_req.variable -
3549 data->rx_mgmt.frame);
3550 wpas_p2p_probe_req_rx(
3551 wpa_s, src, mgmt->da,
3552 mgmt->bssid, ie, ie_len,
3554 data->rx_mgmt.ssi_signal);
3557 #endif /* CONFIG_P2P */
3558 #ifdef CONFIG_IBSS_RSN
3559 if (wpa_s->current_ssid &&
3560 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3561 stype == WLAN_FC_STYPE_AUTH &&
3562 data->rx_mgmt.frame_len >= 30) {
3563 wpa_supplicant_event_ibss_auth(wpa_s, data);
3566 #endif /* CONFIG_IBSS_RSN */
3568 if (stype == WLAN_FC_STYPE_ACTION) {
3569 wpas_event_rx_mgmt_action(
3570 wpa_s, data->rx_mgmt.frame,
3571 data->rx_mgmt.frame_len,
3573 data->rx_mgmt.ssi_signal);
3578 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3582 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3583 "management frame in non-AP mode");
3588 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3589 data->rx_mgmt.frame_len > 24) {
3590 const u8 *ie = mgmt->u.probe_req.variable;
3591 size_t ie_len = data->rx_mgmt.frame_len -
3592 (mgmt->u.probe_req.variable -
3593 data->rx_mgmt.frame);
3595 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3596 mgmt->bssid, ie, ie_len,
3597 data->rx_mgmt.ssi_signal);
3600 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3601 #endif /* CONFIG_AP */
3604 case EVENT_RX_PROBE_REQ:
3605 if (data->rx_probe_req.sa == NULL ||
3606 data->rx_probe_req.ie == NULL)
3609 if (wpa_s->ap_iface) {
3610 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3611 data->rx_probe_req.sa,
3612 data->rx_probe_req.da,
3613 data->rx_probe_req.bssid,
3614 data->rx_probe_req.ie,
3615 data->rx_probe_req.ie_len,
3616 data->rx_probe_req.ssi_signal);
3619 #endif /* CONFIG_AP */
3620 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3621 data->rx_probe_req.da,
3622 data->rx_probe_req.bssid,
3623 data->rx_probe_req.ie,
3624 data->rx_probe_req.ie_len,
3626 data->rx_probe_req.ssi_signal);
3628 case EVENT_REMAIN_ON_CHANNEL:
3629 #ifdef CONFIG_OFFCHANNEL
3630 offchannel_remain_on_channel_cb(
3631 wpa_s, data->remain_on_channel.freq,
3632 data->remain_on_channel.duration);
3633 #endif /* CONFIG_OFFCHANNEL */
3634 wpas_p2p_remain_on_channel_cb(
3635 wpa_s, data->remain_on_channel.freq,
3636 data->remain_on_channel.duration);
3638 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3639 #ifdef CONFIG_OFFCHANNEL
3640 offchannel_cancel_remain_on_channel_cb(
3641 wpa_s, data->remain_on_channel.freq);
3642 #endif /* CONFIG_OFFCHANNEL */
3643 wpas_p2p_cancel_remain_on_channel_cb(
3644 wpa_s, data->remain_on_channel.freq);
3646 case EVENT_EAPOL_RX:
3647 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3648 data->eapol_rx.data,
3649 data->eapol_rx.data_len);
3651 case EVENT_SIGNAL_CHANGE:
3652 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3653 "above=%d signal=%d noise=%d txrate=%d",
3654 data->signal_change.above_threshold,
3655 data->signal_change.current_signal,
3656 data->signal_change.current_noise,
3657 data->signal_change.current_txrate);
3658 wpa_bss_update_level(wpa_s->current_bss,
3659 data->signal_change.current_signal);
3660 bgscan_notify_signal_change(
3661 wpa_s, data->signal_change.above_threshold,
3662 data->signal_change.current_signal,
3663 data->signal_change.current_noise,
3664 data->signal_change.current_txrate);
3666 case EVENT_INTERFACE_ENABLED:
3667 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3668 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3669 wpa_supplicant_update_mac_addr(wpa_s);
3670 if (wpa_s->p2p_mgmt) {
3671 wpa_supplicant_set_state(wpa_s,
3677 if (!wpa_s->ap_iface) {
3678 wpa_supplicant_set_state(wpa_s,
3680 wpa_s->scan_req = NORMAL_SCAN_REQ;
3681 wpa_supplicant_req_scan(wpa_s, 0, 0);
3683 wpa_supplicant_set_state(wpa_s,
3685 #else /* CONFIG_AP */
3686 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3687 wpa_supplicant_req_scan(wpa_s, 0, 0);
3688 #endif /* CONFIG_AP */
3691 case EVENT_INTERFACE_DISABLED:
3692 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3694 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3695 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3696 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3698 * Mark interface disabled if this happens to end up not
3699 * being removed as a separate P2P group interface.
3701 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3703 * The interface was externally disabled. Remove
3704 * it assuming an external entity will start a
3705 * new session if needed.
3707 if (wpa_s->current_ssid &&
3708 wpa_s->current_ssid->p2p_group)
3709 wpas_p2p_interface_unavailable(wpa_s);
3711 wpas_p2p_disconnect(wpa_s);
3713 * wpa_s instance may have been freed, so must not use
3718 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3719 p2p_in_progress(wpa_s->global->p2p) > 1) {
3720 /* This radio work will be cancelled, so clear P2P
3723 p2p_stop_find(wpa_s->global->p2p);
3725 #endif /* CONFIG_P2P */
3727 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3729 * Indicate disconnection to keep ctrl_iface events
3732 wpa_supplicant_event_disassoc(
3733 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3735 wpa_supplicant_mark_disassoc(wpa_s);
3736 radio_remove_works(wpa_s, NULL, 0);
3738 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3740 case EVENT_CHANNEL_LIST_CHANGED:
3741 wpa_supplicant_update_channel_list(
3742 wpa_s, &data->channel_list_changed);
3744 case EVENT_INTERFACE_UNAVAILABLE:
3745 wpas_p2p_interface_unavailable(wpa_s);
3747 case EVENT_BEST_CHANNEL:
3748 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3750 data->best_chan.freq_24, data->best_chan.freq_5,
3751 data->best_chan.freq_overall);
3752 wpa_s->best_24_freq = data->best_chan.freq_24;
3753 wpa_s->best_5_freq = data->best_chan.freq_5;
3754 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3755 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3756 data->best_chan.freq_5,
3757 data->best_chan.freq_overall);
3759 case EVENT_UNPROT_DEAUTH:
3760 wpa_supplicant_event_unprot_deauth(wpa_s,
3761 &data->unprot_deauth);
3763 case EVENT_UNPROT_DISASSOC:
3764 wpa_supplicant_event_unprot_disassoc(wpa_s,
3765 &data->unprot_disassoc);
3767 case EVENT_STATION_LOW_ACK:
3769 if (wpa_s->ap_iface && data)
3770 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3771 data->low_ack.addr);
3772 #endif /* CONFIG_AP */
3775 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3776 data->low_ack.addr);
3777 #endif /* CONFIG_TDLS */
3779 case EVENT_IBSS_PEER_LOST:
3780 #ifdef CONFIG_IBSS_RSN
3781 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3782 #endif /* CONFIG_IBSS_RSN */
3784 case EVENT_DRIVER_GTK_REKEY:
3785 if (os_memcmp(data->driver_gtk_rekey.bssid,
3786 wpa_s->bssid, ETH_ALEN))
3790 wpa_sm_update_replay_ctr(wpa_s->wpa,
3791 data->driver_gtk_rekey.replay_ctr);
3793 case EVENT_SCHED_SCAN_STOPPED:
3795 wpa_s->sched_scanning = 0;
3796 resched = wpa_s->scanning;
3797 wpa_supplicant_notify_scanning(wpa_s, 0);
3799 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3803 * Start a new sched scan to continue searching for more SSIDs
3804 * either if timed out or PNO schedule scan is pending.
3806 if (wpa_s->sched_scan_timed_out) {
3807 wpa_supplicant_req_sched_scan(wpa_s);
3808 } else if (wpa_s->pno_sched_pending) {
3809 wpa_s->pno_sched_pending = 0;
3810 wpas_start_pno(wpa_s);
3811 } else if (resched) {
3812 wpa_supplicant_req_scan(wpa_s, 0, 0);
3816 case EVENT_WPS_BUTTON_PUSHED:
3818 wpas_wps_start_pbc(wpa_s, NULL, 0);
3819 #endif /* CONFIG_WPS */
3821 case EVENT_AVOID_FREQUENCIES:
3822 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3824 case EVENT_CONNECT_FAILED_REASON:
3826 if (!wpa_s->ap_iface || !data)
3828 hostapd_event_connect_failed_reason(
3829 wpa_s->ap_iface->bss[0],
3830 data->connect_failed_reason.addr,
3831 data->connect_failed_reason.code);
3832 #endif /* CONFIG_AP */
3834 case EVENT_NEW_PEER_CANDIDATE:
3836 if (!wpa_s->ifmsh || !data)
3838 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3839 data->mesh_peer.ies,
3840 data->mesh_peer.ie_len);
3841 #endif /* CONFIG_MESH */
3844 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);