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 */
568 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
572 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
573 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
576 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
577 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
583 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
585 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
590 if (!(ie.proto & ssid->proto)) {
591 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
596 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
597 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
602 if (!(ie.group_cipher & ssid->group_cipher)) {
603 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
608 if (!(ie.key_mgmt & ssid->key_mgmt)) {
609 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
614 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
618 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
620 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
624 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
625 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
626 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
630 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
631 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
632 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
636 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
637 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
641 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
648 static int freq_allowed(int *freqs, int freq)
655 for (i = 0; freqs[i]; i++)
656 if (freqs[i] == freq)
662 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
664 const struct hostapd_hw_modes *mode = NULL, *modes;
665 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
670 return 1; /* Cannot do matching without knowing band */
672 modes = wpa_s->hw.modes;
675 * The driver does not provide any additional information
676 * about the utilized hardware, so allow the connection attempt
682 for (i = 0; i < wpa_s->hw.num_modes; i++) {
683 for (j = 0; j < modes[i].num_channels; j++) {
684 int freq = modes[i].channels[j].freq;
685 if (freq == bss->freq) {
687 mode->mode == HOSTAPD_MODE_IEEE80211G)
688 break; /* do not allow 802.11b replace
699 for (i = 0; i < (int) sizeof(scan_ie); i++) {
700 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
704 for (j = 2; j < rate_ie[1] + 2; j++) {
705 int flagged = !!(rate_ie[j] & 0x80);
706 int r = (rate_ie[j] & 0x7f) * 5;
709 * IEEE Std 802.11n-2009 7.3.2.2:
710 * The new BSS Membership selector value is encoded
711 * like a legacy basic rate, but it is not a rate and
712 * only indicates if the BSS members are required to
713 * support the mandatory features of Clause 20 [HT PHY]
714 * in order to join the BSS.
716 if (flagged && ((rate_ie[j] & 0x7f) ==
717 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
718 if (!ht_supported(mode)) {
719 wpa_dbg(wpa_s, MSG_DEBUG,
720 " hardware does not support "
727 /* There's also a VHT selector for 802.11ac */
728 if (flagged && ((rate_ie[j] & 0x7f) ==
729 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
730 if (!vht_supported(mode)) {
731 wpa_dbg(wpa_s, MSG_DEBUG,
732 " hardware does not support "
742 /* check for legacy basic rates */
743 for (k = 0; k < mode->num_rates; k++) {
744 if (mode->rates[k] == r)
747 if (k == mode->num_rates) {
749 * IEEE Std 802.11-2007 7.3.2.2 demands that in
750 * order to join a BSS all required rates
751 * have to be supported by the hardware.
753 wpa_dbg(wpa_s, MSG_DEBUG,
754 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
756 bss->freq, mode->mode, mode->num_rates);
767 * Test whether BSS is in an ESS.
768 * This is done differently in DMG (60 GHz) and non-DMG bands
770 static int bss_is_ess(struct wpa_bss *bss)
772 if (bss_is_dmg(bss)) {
773 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
774 IEEE80211_CAP_DMG_AP;
777 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
782 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
786 for (i = 0; i < ETH_ALEN; i++) {
787 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
794 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
798 for (i = 0; i < num; i++) {
799 const u8 *a = list + i * ETH_ALEN * 2;
800 const u8 *m = a + ETH_ALEN;
802 if (match_mac_mask(a, addr, m))
809 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
810 int i, struct wpa_bss *bss,
811 struct wpa_ssid *group,
814 u8 wpa_ie_len, rsn_ie_len;
816 struct wpa_blacklist *e;
818 struct wpa_ssid *ssid;
821 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
822 wpa_ie_len = ie ? ie[1] : 0;
824 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
825 rsn_ie_len = ie ? ie[1] : 0;
827 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
830 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
831 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
832 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
833 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
834 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
835 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
836 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
838 osen ? " osen=1" : "");
840 e = wpa_blacklist_get(wpa_s, bss->bssid);
843 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
845 * When only a single network is enabled, we can
846 * trigger blacklisting on the first failure. This
847 * should not be done with multiple enabled networks to
848 * avoid getting forced to move into a worse ESS on
849 * single error if there are no other BSSes of the
854 if (e->count > limit) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
856 "(count=%d limit=%d)", e->count, limit);
861 if (bss->ssid_len == 0) {
862 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
866 if (disallowed_bssid(wpa_s, bss->bssid)) {
867 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
871 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
872 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
876 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
878 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
879 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
882 if (wpas_network_disabled(wpa_s, ssid)) {
883 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
887 res = wpas_temp_disabled(wpa_s, ssid);
889 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
890 "temporarily for %d second(s)", res);
895 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
896 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
901 if (wpa && ssid->ssid_len == 0 &&
902 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
905 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
906 /* Only allow wildcard SSID match if an AP
907 * advertises active WPS operation that matches
910 if (ssid->ssid_len == 0 &&
911 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
914 #endif /* CONFIG_WPS */
916 if (ssid->bssid_set && ssid->ssid_len == 0 &&
917 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
921 (bss->ssid_len != ssid->ssid_len ||
922 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
923 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
927 if (ssid->bssid_set &&
928 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
929 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
933 /* check blacklist */
934 if (ssid->num_bssid_blacklist &&
935 addr_in_list(bss->bssid, ssid->bssid_blacklist,
936 ssid->num_bssid_blacklist)) {
937 wpa_dbg(wpa_s, MSG_DEBUG,
938 " skip - BSSID blacklisted");
942 /* if there is a whitelist, only accept those APs */
943 if (ssid->num_bssid_whitelist &&
944 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
945 ssid->num_bssid_whitelist)) {
946 wpa_dbg(wpa_s, MSG_DEBUG,
947 " skip - BSSID not in whitelist");
951 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
955 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
956 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
957 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
958 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
963 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
965 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
969 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
970 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
975 if (!wpa_supplicant_match_privacy(bss, ssid)) {
976 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
981 if (!bss_is_ess(bss)) {
982 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
986 if (!freq_allowed(ssid->freq_list, bss->freq)) {
987 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
992 if (!rate_match(wpa_s, bss)) {
993 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
999 if (ssid->p2p_group &&
1000 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1001 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1002 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1006 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1007 struct wpabuf *p2p_ie;
1008 u8 dev_addr[ETH_ALEN];
1010 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1012 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1015 p2p_ie = wpa_bss_get_vendor_ie_multi(
1016 bss, P2P_IE_VENDOR_TYPE);
1017 if (p2p_ie == NULL) {
1018 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1022 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1023 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1025 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1026 wpabuf_free(p2p_ie);
1029 wpabuf_free(p2p_ie);
1033 * TODO: skip the AP if its P2P IE has Group Formation
1034 * bit set in the P2P Group Capability Bitmap and we
1035 * are not in Group Formation with that device.
1037 #endif /* CONFIG_P2P */
1039 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1041 struct os_reltime diff;
1043 os_reltime_sub(&wpa_s->scan_min_time,
1044 &bss->last_update, &diff);
1045 wpa_dbg(wpa_s, MSG_DEBUG,
1046 " skip - scan result not recent enough (%u.%06u seconds too old)",
1047 (unsigned int) diff.sec,
1048 (unsigned int) diff.usec);
1052 /* Matching configuration found */
1056 /* No matching configuration found */
1061 static struct wpa_bss *
1062 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1063 struct wpa_ssid *group,
1064 struct wpa_ssid **selected_ssid,
1065 int only_first_ssid)
1069 if (only_first_ssid)
1070 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1073 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1076 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1077 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1078 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1080 if (!*selected_ssid)
1082 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1084 MAC2STR(bss->bssid),
1085 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1093 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1094 struct wpa_ssid **selected_ssid)
1096 struct wpa_bss *selected = NULL;
1098 struct wpa_ssid *next_ssid = NULL;
1099 struct wpa_ssid *ssid;
1101 if (wpa_s->last_scan_res == NULL ||
1102 wpa_s->last_scan_res_used == 0)
1103 return NULL; /* no scan results from last update */
1105 if (wpa_s->next_ssid) {
1106 /* check that next_ssid is still valid */
1107 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1108 if (ssid == wpa_s->next_ssid)
1112 wpa_s->next_ssid = NULL;
1115 while (selected == NULL) {
1116 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1117 if (next_ssid && next_ssid->priority ==
1118 wpa_s->conf->pssid[prio]->priority) {
1119 selected = wpa_supplicant_select_bss(
1120 wpa_s, next_ssid, selected_ssid, 1);
1124 selected = wpa_supplicant_select_bss(
1125 wpa_s, wpa_s->conf->pssid[prio],
1131 if (selected == NULL && wpa_s->blacklist &&
1132 !wpa_s->countermeasures) {
1133 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1134 "blacklist and try again");
1135 wpa_blacklist_clear(wpa_s);
1136 wpa_s->blacklist_cleared++;
1137 } else if (selected == NULL)
1141 ssid = *selected_ssid;
1142 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1143 !ssid->passphrase && !ssid->ext_psk) {
1144 const char *field_name, *txt = NULL;
1146 wpa_dbg(wpa_s, MSG_DEBUG,
1147 "PSK/passphrase not yet available for the selected network");
1149 wpas_notify_network_request(wpa_s, ssid,
1150 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1152 field_name = wpa_supplicant_ctrl_req_to_string(
1153 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1154 if (field_name == NULL)
1157 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1166 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1167 int timeout_sec, int timeout_usec)
1169 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1171 * No networks are enabled; short-circuit request so
1172 * we don't wait timeout seconds before transitioning
1173 * to INACTIVE state.
1175 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1176 "since there are no enabled networks");
1177 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1181 wpa_s->scan_for_connection = 1;
1182 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1186 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1187 struct wpa_bss *selected,
1188 struct wpa_ssid *ssid)
1190 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1191 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1192 "PBC session overlap");
1193 wpas_notify_wps_event_pbc_overlap(wpa_s);
1195 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1196 wpa_s->p2p_in_provisioning) {
1197 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1201 #endif /* CONFIG_P2P */
1204 wpas_wps_cancel(wpa_s);
1205 #endif /* CONFIG_WPS */
1209 wpa_msg(wpa_s, MSG_DEBUG,
1210 "Considering connect request: reassociate: %d selected: "
1211 MACSTR " bssid: " MACSTR " pending: " MACSTR
1212 " wpa_state: %s ssid=%p current_ssid=%p",
1213 wpa_s->reassociate, MAC2STR(selected->bssid),
1214 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1215 wpa_supplicant_state_txt(wpa_s->wpa_state),
1216 ssid, wpa_s->current_ssid);
1219 * Do not trigger new association unless the BSSID has changed or if
1220 * reassociation is requested. If we are in process of associating with
1221 * the selected BSSID, do not trigger new attempt.
1223 if (wpa_s->reassociate ||
1224 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1225 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1226 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1227 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1228 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1230 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1231 ssid != wpa_s->current_ssid)))) {
1232 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1233 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1236 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1237 MAC2STR(selected->bssid));
1238 wpa_supplicant_associate(wpa_s, selected, ssid);
1240 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1241 "connect with the selected AP");
1248 static struct wpa_ssid *
1249 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1252 struct wpa_ssid *ssid;
1254 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1255 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1257 if (wpas_network_disabled(wpa_s, ssid))
1259 if (ssid->mode == IEEE80211_MODE_IBSS ||
1260 ssid->mode == IEEE80211_MODE_AP ||
1261 ssid->mode == IEEE80211_MODE_MESH)
1269 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1270 * on BSS added and BSS changed events */
1271 static void wpa_supplicant_rsn_preauth_scan_results(
1272 struct wpa_supplicant *wpa_s)
1274 struct wpa_bss *bss;
1276 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1279 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1280 const u8 *ssid, *rsn;
1282 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1286 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1290 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1296 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1297 struct wpa_bss *selected,
1298 struct wpa_ssid *ssid)
1300 struct wpa_bss *current_bss = NULL;
1301 #ifndef CONFIG_NO_ROAMING
1303 #endif /* CONFIG_NO_ROAMING */
1305 if (wpa_s->reassociate)
1306 return 1; /* explicit request to reassociate */
1307 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1308 return 1; /* we are not associated; continue */
1309 if (wpa_s->current_ssid == NULL)
1310 return 1; /* unknown current SSID */
1311 if (wpa_s->current_ssid != ssid)
1312 return 1; /* different network block */
1314 if (wpas_driver_bss_selection(wpa_s))
1315 return 0; /* Driver-based roaming */
1317 if (wpa_s->current_ssid->ssid)
1318 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1319 wpa_s->current_ssid->ssid,
1320 wpa_s->current_ssid->ssid_len);
1322 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1325 return 1; /* current BSS not seen in scan results */
1327 if (current_bss == selected)
1330 if (selected->last_update_idx > current_bss->last_update_idx)
1331 return 1; /* current BSS not seen in the last scan */
1333 #ifndef CONFIG_NO_ROAMING
1334 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1335 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1336 " level=%d snr=%d est_throughput=%u",
1337 MAC2STR(current_bss->bssid), current_bss->level,
1338 current_bss->snr, current_bss->est_throughput);
1339 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1340 " level=%d snr=%d est_throughput=%u",
1341 MAC2STR(selected->bssid), selected->level,
1342 selected->snr, selected->est_throughput);
1344 if (wpa_s->current_ssid->bssid_set &&
1345 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1347 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1348 "has preferred BSSID");
1352 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1353 wpa_dbg(wpa_s, MSG_DEBUG,
1354 "Allow reassociation - selected BSS has better estimated throughput");
1358 if (current_bss->level < 0 && current_bss->level > selected->level) {
1359 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1365 if (current_bss->level < 0) {
1366 if (current_bss->level < -85)
1368 else if (current_bss->level < -80)
1370 else if (current_bss->level < -75)
1372 else if (current_bss->level < -70)
1377 if (abs(current_bss->level - selected->level) < min_diff) {
1378 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1384 #else /* CONFIG_NO_ROAMING */
1386 #endif /* CONFIG_NO_ROAMING */
1390 /* Return != 0 if no scan results could be fetched or if scan results should not
1391 * be shared with other virtual interfaces. */
1392 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1393 union wpa_event_data *data,
1396 struct wpa_scan_results *scan_res = NULL;
1399 #ifndef CONFIG_NO_RANDOM_POOL
1401 #endif /* CONFIG_NO_RANDOM_POOL */
1404 if (wpa_s->ap_iface)
1406 #endif /* CONFIG_AP */
1408 wpa_supplicant_notify_scanning(wpa_s, 0);
1410 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1411 data ? &data->scan_info :
1413 if (scan_res == NULL) {
1414 if (wpa_s->conf->ap_scan == 2 || ap ||
1415 wpa_s->scan_res_handler == scan_only_handler)
1419 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1421 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1423 goto scan_work_done;
1426 #ifndef CONFIG_NO_RANDOM_POOL
1427 num = scan_res->num;
1430 for (i = 0; i < num; i++) {
1432 struct wpa_scan_res *res = scan_res->res[i];
1433 buf[0] = res->bssid[5];
1434 buf[1] = res->qual & 0xff;
1435 buf[2] = res->noise & 0xff;
1436 buf[3] = res->level & 0xff;
1437 buf[4] = res->tsf & 0xff;
1438 random_add_randomness(buf, sizeof(buf));
1440 #endif /* CONFIG_NO_RANDOM_POOL */
1442 if (own_request && wpa_s->scan_res_handler &&
1443 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1444 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1445 struct wpa_scan_results *scan_res);
1447 scan_res_handler = wpa_s->scan_res_handler;
1448 wpa_s->scan_res_handler = NULL;
1449 scan_res_handler(wpa_s, scan_res);
1451 goto scan_work_done;
1455 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1457 if (wpa_s->ap_iface->scan_cb)
1458 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1459 #endif /* CONFIG_AP */
1460 goto scan_work_done;
1463 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1464 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1465 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1466 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1467 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1468 wpa_s->manual_scan_id);
1469 wpa_s->manual_scan_use_id = 0;
1471 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1473 wpas_notify_scan_results(wpa_s);
1475 wpas_notify_scan_done(wpa_s, 1);
1477 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1478 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1479 wpa_scan_results_free(scan_res);
1483 if (wnm_scan_process(wpa_s, 1) > 0)
1484 goto scan_work_done;
1486 if (sme_proc_obss_scan(wpa_s) > 0)
1487 goto scan_work_done;
1489 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1490 goto scan_work_done;
1492 if (autoscan_notify_scan(wpa_s, scan_res))
1493 goto scan_work_done;
1495 if (wpa_s->disconnected) {
1496 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1497 goto scan_work_done;
1500 if (!wpas_driver_bss_selection(wpa_s) &&
1501 bgscan_notify_scan(wpa_s, scan_res) == 1)
1502 goto scan_work_done;
1504 wpas_wps_update_ap_info(wpa_s, scan_res);
1506 wpa_scan_results_free(scan_res);
1508 if (wpa_s->scan_work) {
1509 struct wpa_radio_work *work = wpa_s->scan_work;
1510 wpa_s->scan_work = NULL;
1511 radio_work_done(work);
1514 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1517 wpa_scan_results_free(scan_res);
1518 if (wpa_s->scan_work) {
1519 struct wpa_radio_work *work = wpa_s->scan_work;
1520 wpa_s->scan_work = NULL;
1521 radio_work_done(work);
1527 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1528 int new_scan, int own_request)
1530 struct wpa_bss *selected;
1531 struct wpa_ssid *ssid = NULL;
1532 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1534 if (time_to_reenable > 0) {
1535 wpa_dbg(wpa_s, MSG_DEBUG,
1536 "Postpone network selection by %d seconds since all networks are disabled",
1538 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1539 eloop_register_timeout(time_to_reenable, 0,
1540 wpas_network_reenabled, wpa_s, NULL);
1544 if (wpa_s->p2p_mgmt)
1545 return 0; /* no normal connection on p2p_mgmt interface */
1547 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1551 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1554 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1558 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1559 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1563 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1565 * Do not notify other virtual radios of scan results since we do not
1566 * want them to start other associations at the same time.
1572 wpa_msg(wpa_s, MSG_INFO,
1573 "Avoiding join because we already joined a mesh group");
1576 #endif /* CONFIG_MESH */
1577 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1578 ssid = wpa_supplicant_pick_new_network(wpa_s);
1580 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1581 wpa_supplicant_associate(wpa_s, NULL, ssid);
1583 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1584 } else if (own_request) {
1586 * No SSID found. If SCAN results are as a result of
1587 * own scan request and not due to a scan request on
1588 * another shared interface, try another scan.
1590 int timeout_sec = wpa_s->scan_interval;
1591 int timeout_usec = 0;
1595 res = wpas_p2p_scan_no_go_seen(wpa_s);
1601 if (wpa_s->p2p_in_provisioning ||
1602 wpa_s->show_group_started ||
1603 wpa_s->p2p_in_invitation) {
1605 * Use shorter wait during P2P Provisioning
1606 * state and during P2P join-a-group operation
1607 * to speed up group formation.
1610 timeout_usec = 250000;
1611 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1615 #endif /* CONFIG_P2P */
1616 #ifdef CONFIG_INTERWORKING
1617 if (wpa_s->conf->auto_interworking &&
1618 wpa_s->conf->interworking &&
1619 wpa_s->conf->cred) {
1620 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1621 "start ANQP fetch since no matching "
1623 wpa_s->network_select = 1;
1624 wpa_s->auto_network_select = 1;
1625 interworking_start_fetch_anqp(wpa_s);
1628 #endif /* CONFIG_INTERWORKING */
1630 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1631 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1633 timeout_usec = 500000;
1634 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1638 #endif /* CONFIG_WPS */
1639 if (wpa_supplicant_req_sched_scan(wpa_s))
1640 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1643 wpa_msg_ctrl(wpa_s, MSG_INFO,
1644 WPA_EVENT_NETWORK_NOT_FOUND);
1651 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1652 union wpa_event_data *data)
1654 struct wpa_supplicant *ifs;
1657 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1660 * Interface may have been removed, so must not dereference
1667 * If no scan results could be fetched, then no need to
1668 * notify those interfaces that did not actually request
1669 * this scan. Similarly, if scan results started a new operation on this
1670 * interface, do not notify other interfaces to avoid concurrent
1671 * operations during a connection attempt.
1677 * Check other interfaces to see if they share the same radio. If
1678 * so, they get updated with this same scan info.
1680 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1683 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1684 "sibling", ifs->ifname);
1685 _wpa_supplicant_event_scan_results(ifs, data, 0);
1692 #endif /* CONFIG_NO_SCAN_PROCESSING */
1695 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1697 #ifdef CONFIG_NO_SCAN_PROCESSING
1699 #else /* CONFIG_NO_SCAN_PROCESSING */
1700 struct os_reltime now;
1702 if (wpa_s->last_scan_res_used == 0)
1705 os_get_reltime(&now);
1706 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1707 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1711 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1712 #endif /* CONFIG_NO_SCAN_PROCESSING */
1717 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1719 struct wpa_supplicant *wpa_s = eloop_ctx;
1721 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1724 if (!wpa_s->no_keep_alive) {
1725 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1726 MAC2STR(wpa_s->bssid));
1727 /* TODO: could skip this if normal data traffic has been sent */
1728 /* TODO: Consider using some more appropriate data frame for
1731 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1736 if (wpa_s->sme.bss_max_idle_period) {
1738 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1741 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1742 wnm_bss_keep_alive, wpa_s, NULL);
1744 #endif /* CONFIG_SME */
1748 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1749 const u8 *ies, size_t ies_len)
1751 struct ieee802_11_elems elems;
1756 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1760 if (elems.bss_max_idle_period) {
1762 wpa_s->sme.bss_max_idle_period =
1763 WPA_GET_LE16(elems.bss_max_idle_period);
1764 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1765 "TU)%s", wpa_s->sme.bss_max_idle_period,
1766 (elems.bss_max_idle_period[2] & 0x01) ?
1767 " (protected keep-live required)" : "");
1768 if (wpa_s->sme.bss_max_idle_period == 0)
1769 wpa_s->sme.bss_max_idle_period = 1;
1770 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1771 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1772 /* msec times 1000 */
1773 msec = wpa_s->sme.bss_max_idle_period * 1024;
1776 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1777 wnm_bss_keep_alive, wpa_s,
1781 #endif /* CONFIG_SME */
1784 #endif /* CONFIG_WNM */
1787 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1790 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1791 #endif /* CONFIG_WNM */
1795 #ifdef CONFIG_INTERWORKING
1797 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1802 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1803 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1805 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1812 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1813 const u8 *ies, size_t ies_len)
1815 struct ieee802_11_elems elems;
1820 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1823 if (elems.qos_map_set) {
1824 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1825 elems.qos_map_set_len);
1829 #endif /* CONFIG_INTERWORKING */
1832 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1833 union wpa_event_data *data)
1835 int l, len, found = 0, wpa_found, rsn_found;
1837 #ifdef CONFIG_IEEE80211R
1839 #endif /* CONFIG_IEEE80211R */
1841 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1842 if (data->assoc_info.req_ies)
1843 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1844 data->assoc_info.req_ies_len);
1845 if (data->assoc_info.resp_ies) {
1846 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1847 data->assoc_info.resp_ies_len);
1849 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1850 data->assoc_info.resp_ies_len);
1851 #endif /* CONFIG_TDLS */
1853 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1854 data->assoc_info.resp_ies_len);
1855 #endif /* CONFIG_WNM */
1856 #ifdef CONFIG_INTERWORKING
1857 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1858 data->assoc_info.resp_ies_len);
1859 #endif /* CONFIG_INTERWORKING */
1861 if (data->assoc_info.beacon_ies)
1862 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1863 data->assoc_info.beacon_ies,
1864 data->assoc_info.beacon_ies_len);
1865 if (data->assoc_info.freq)
1866 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1867 data->assoc_info.freq);
1869 p = data->assoc_info.req_ies;
1870 l = data->assoc_info.req_ies_len;
1872 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1873 while (p && l >= 2) {
1876 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1880 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1881 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1882 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1883 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1886 wpa_find_assoc_pmkid(wpa_s);
1892 if (!found && data->assoc_info.req_ies)
1893 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1895 #ifdef CONFIG_IEEE80211R
1897 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1898 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1899 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1900 data->assoc_info.resp_ies,
1901 data->assoc_info.resp_ies_len,
1903 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1904 "Reassociation Response failed");
1905 wpa_supplicant_deauthenticate(
1906 wpa_s, WLAN_REASON_INVALID_IE);
1911 p = data->assoc_info.resp_ies;
1912 l = data->assoc_info.resp_ies_len;
1914 #ifdef CONFIG_WPS_STRICT
1915 if (p && wpa_s->current_ssid &&
1916 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1918 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1920 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1921 "include WPS IE in (Re)Association Response");
1925 if (wps_validate_assoc_resp(wps) < 0) {
1927 wpa_supplicant_deauthenticate(
1928 wpa_s, WLAN_REASON_INVALID_IE);
1933 #endif /* CONFIG_WPS_STRICT */
1935 /* Go through the IEs and make a copy of the MDIE, if present. */
1936 while (p && l >= 2) {
1939 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1943 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1944 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1945 wpa_s->sme.ft_used = 1;
1946 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1947 MOBILITY_DOMAIN_ID_LEN);
1953 #endif /* CONFIG_SME */
1955 /* Process FT when SME is in the driver */
1956 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1957 wpa_ft_is_completed(wpa_s->wpa)) {
1958 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1959 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1960 data->assoc_info.resp_ies,
1961 data->assoc_info.resp_ies_len,
1963 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1964 "Reassociation Response failed");
1965 wpa_supplicant_deauthenticate(
1966 wpa_s, WLAN_REASON_INVALID_IE);
1969 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1972 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1973 data->assoc_info.resp_ies_len);
1974 #endif /* CONFIG_IEEE80211R */
1976 /* WPA/RSN IE from Beacon/ProbeResp */
1977 p = data->assoc_info.beacon_ies;
1978 l = data->assoc_info.beacon_ies_len;
1980 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1982 wpa_found = rsn_found = 0;
1983 while (p && l >= 2) {
1986 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1991 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1992 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1994 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1998 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2000 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2007 if (!wpa_found && data->assoc_info.beacon_ies)
2008 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2009 if (!rsn_found && data->assoc_info.beacon_ies)
2010 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2011 if (wpa_found || rsn_found)
2012 wpa_s->ap_ies_from_associnfo = 1;
2015 wpabuf_free(wpa_s->received_mb_ies);
2016 wpa_s->received_mb_ies = NULL;
2018 struct mb_ies_info mb_ies;
2020 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2021 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2022 data->assoc_info.resp_ies_len))
2023 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2025 #endif /* CONFIG_FST */
2027 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2028 wpa_s->assoc_freq != data->assoc_info.freq) {
2029 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2031 wpa_s->assoc_freq, data->assoc_info.freq);
2032 wpa_supplicant_update_scan_results(wpa_s);
2035 wpa_s->assoc_freq = data->assoc_info.freq;
2041 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2043 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2045 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2048 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2051 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2052 WPA_IE_VENDOR_TYPE);
2053 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2055 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2056 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2057 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2058 bss_rsn ? 2 + bss_rsn[1] : 0))
2065 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2066 union wpa_event_data *data)
2072 if (wpa_s->ap_iface) {
2075 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2076 data->assoc_info.addr,
2077 data->assoc_info.req_ies,
2078 data->assoc_info.req_ies_len,
2079 data->assoc_info.reassoc);
2082 #endif /* CONFIG_AP */
2084 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2086 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2087 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2090 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2091 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2092 wpa_supplicant_deauthenticate(
2093 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2097 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2098 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2099 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2100 MACSTR, MAC2STR(bssid));
2101 random_add_randomness(bssid, ETH_ALEN);
2102 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2103 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2104 wpas_notify_bssid_changed(wpa_s);
2106 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2107 wpa_clear_keys(wpa_s, bssid);
2109 if (wpa_supplicant_select_config(wpa_s) < 0) {
2110 wpa_supplicant_deauthenticate(
2111 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2115 if (wpa_s->conf->ap_scan == 1 &&
2116 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2117 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
2118 wpa_msg(wpa_s, MSG_WARNING,
2119 "WPA/RSN IEs not updated");
2124 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2125 wpa_s->sme.prev_bssid_set = 1;
2126 wpa_s->sme.last_unprot_disconnect.sec = 0;
2127 #endif /* CONFIG_SME */
2129 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2130 if (wpa_s->current_ssid) {
2131 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2132 * initialized before association, but for other modes,
2133 * initialize PC/SC here, if the current configuration needs
2134 * smartcard or SIM/USIM. */
2135 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2137 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2139 l2_packet_notify_auth_start(wpa_s->l2);
2142 * Set portEnabled first to FALSE in order to get EAP state machine out
2143 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2144 * state machine may transit to AUTHENTICATING state based on obsolete
2145 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2146 * AUTHENTICATED without ever giving chance to EAP state machine to
2149 if (!ft_completed) {
2150 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2151 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2153 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2154 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2155 /* 802.1X::portControl = Auto */
2156 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2157 wpa_s->eapol_received = 0;
2158 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2159 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2160 (wpa_s->current_ssid &&
2161 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2162 if (wpa_s->current_ssid &&
2163 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2165 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2167 * Set the key after having received joined-IBSS event
2170 wpa_supplicant_set_wpa_none_key(wpa_s,
2171 wpa_s->current_ssid);
2173 wpa_supplicant_cancel_auth_timeout(wpa_s);
2174 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2175 } else if (!ft_completed) {
2176 /* Timeout for receiving the first EAPOL packet */
2177 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2179 wpa_supplicant_cancel_scan(wpa_s);
2181 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2182 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2184 * We are done; the driver will take care of RSN 4-way
2187 wpa_supplicant_cancel_auth_timeout(wpa_s);
2188 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2189 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2190 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2191 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2192 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2194 * The driver will take care of RSN 4-way handshake, so we need
2195 * to allow EAPOL supplicant to complete its work without
2196 * waiting for WPA supplicant.
2198 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2199 } else if (ft_completed) {
2201 * FT protocol completed - make sure EAPOL state machine ends
2202 * up in authenticated.
2204 wpa_supplicant_cancel_auth_timeout(wpa_s);
2205 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2206 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2207 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2210 wpa_s->last_eapol_matches_bssid = 0;
2212 if (wpa_s->pending_eapol_rx) {
2213 struct os_reltime now, age;
2214 os_get_reltime(&now);
2215 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2216 if (age.sec == 0 && age.usec < 100000 &&
2217 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2219 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2220 "frame that was received just before "
2221 "association notification");
2222 wpa_supplicant_rx_eapol(
2223 wpa_s, wpa_s->pending_eapol_rx_src,
2224 wpabuf_head(wpa_s->pending_eapol_rx),
2225 wpabuf_len(wpa_s->pending_eapol_rx));
2227 wpabuf_free(wpa_s->pending_eapol_rx);
2228 wpa_s->pending_eapol_rx = NULL;
2231 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2232 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2233 wpa_s->current_ssid &&
2234 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2235 /* Set static WEP keys again */
2236 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2239 #ifdef CONFIG_IBSS_RSN
2240 if (wpa_s->current_ssid &&
2241 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2242 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2243 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2244 wpa_s->ibss_rsn == NULL) {
2245 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2246 if (!wpa_s->ibss_rsn) {
2247 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2248 wpa_supplicant_deauthenticate(
2249 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2253 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2255 #endif /* CONFIG_IBSS_RSN */
2257 wpas_wps_notify_assoc(wpa_s, bssid);
2260 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2261 data->assoc_info.resp_ies_len,
2262 &data->assoc_info.wmm_params);
2264 if (wpa_s->reassoc_same_bss)
2265 wmm_ac_restore_tspecs(wpa_s);
2270 static int disconnect_reason_recoverable(u16 reason_code)
2272 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2273 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2274 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2278 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2280 int locally_generated)
2284 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2286 * At least Host AP driver and a Prism3 card seemed to be
2287 * generating streams of disconnected events when configuring
2288 * IBSS for WPA-None. Ignore them for now.
2293 bssid = wpa_s->bssid;
2294 if (is_zero_ether_addr(bssid))
2295 bssid = wpa_s->pending_bssid;
2297 if (!is_zero_ether_addr(bssid) ||
2298 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2299 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2301 MAC2STR(bssid), reason_code,
2302 locally_generated ? " locally_generated=1" : "");
2307 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2308 int locally_generated)
2310 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2311 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2312 return 0; /* Not in 4-way handshake with PSK */
2315 * It looks like connection was lost while trying to go through PSK
2316 * 4-way handshake. Filter out known disconnection cases that are caused
2317 * by something else than PSK mismatch to avoid confusing reports.
2320 if (locally_generated) {
2321 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2329 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2331 int locally_generated)
2335 u8 prev_pending_bssid[ETH_ALEN];
2336 struct wpa_bss *fast_reconnect = NULL;
2337 struct wpa_ssid *fast_reconnect_ssid = NULL;
2338 struct wpa_ssid *last_ssid;
2340 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2341 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2343 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2345 * At least Host AP driver and a Prism3 card seemed to be
2346 * generating streams of disconnected events when configuring
2347 * IBSS for WPA-None. Ignore them for now.
2349 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2350 "IBSS/WPA-None mode");
2354 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2355 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2356 "pre-shared key may be incorrect");
2357 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2358 return; /* P2P group removed */
2359 wpas_auth_failed(wpa_s, "WRONG_KEY");
2361 if (!wpa_s->disconnected &&
2362 (!wpa_s->auto_reconnect_disabled ||
2363 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2364 wpas_wps_searching(wpa_s))) {
2365 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2366 "reconnect (wps=%d/%d wpa_state=%d)",
2367 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2368 wpas_wps_searching(wpa_s),
2370 if (wpa_s->wpa_state == WPA_COMPLETED &&
2371 wpa_s->current_ssid &&
2372 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2373 !locally_generated &&
2374 disconnect_reason_recoverable(reason_code)) {
2376 * It looks like the AP has dropped association with
2377 * us, but could allow us to get back in. Try to
2378 * reconnect to the same BSS without full scan to save
2379 * time for some common cases.
2381 fast_reconnect = wpa_s->current_bss;
2382 fast_reconnect_ssid = wpa_s->current_ssid;
2383 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2384 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2386 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2389 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2390 "try to re-connect");
2391 wpa_s->reassociate = 0;
2392 wpa_s->disconnected = 1;
2394 wpa_supplicant_cancel_sched_scan(wpa_s);
2396 bssid = wpa_s->bssid;
2397 if (is_zero_ether_addr(bssid))
2398 bssid = wpa_s->pending_bssid;
2399 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2400 wpas_connection_failed(wpa_s, bssid);
2401 wpa_sm_notify_disassoc(wpa_s->wpa);
2402 if (locally_generated)
2403 wpa_s->disconnect_reason = -reason_code;
2405 wpa_s->disconnect_reason = reason_code;
2406 wpas_notify_disconnect_reason(wpa_s);
2407 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2408 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2409 wpa_clear_keys(wpa_s, wpa_s->bssid);
2411 last_ssid = wpa_s->current_ssid;
2412 wpa_supplicant_mark_disassoc(wpa_s);
2414 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2415 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2416 wpa_s->current_ssid = last_ssid;
2419 if (fast_reconnect &&
2420 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2421 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2422 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2423 fast_reconnect->ssid_len) &&
2424 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2425 #ifndef CONFIG_NO_SCAN_PROCESSING
2426 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2427 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2428 fast_reconnect_ssid) < 0) {
2429 /* Recover through full scan */
2430 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2432 #endif /* CONFIG_NO_SCAN_PROCESSING */
2433 } else if (fast_reconnect) {
2435 * Could not reconnect to the same BSS due to network being
2436 * disabled. Use a new scan to match the alternative behavior
2437 * above, i.e., to continue automatic reconnection attempt in a
2438 * way that enforces disabled network rules.
2440 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2445 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2446 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2448 struct wpa_supplicant *wpa_s = eloop_ctx;
2450 if (!wpa_s->pending_mic_error_report)
2453 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2454 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2455 wpa_s->pending_mic_error_report = 0;
2457 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2461 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2462 union wpa_event_data *data)
2465 struct os_reltime t;
2467 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2468 pairwise = (data && data->michael_mic_failure.unicast);
2470 if ((wpa_s->last_michael_mic_error.sec &&
2471 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2472 wpa_s->pending_mic_error_report) {
2473 if (wpa_s->pending_mic_error_report) {
2475 * Send the pending MIC error report immediately since
2476 * we are going to start countermeasures and AP better
2479 wpa_sm_key_request(wpa_s->wpa, 1,
2480 wpa_s->pending_mic_error_pairwise);
2483 /* Send the new MIC error report immediately since we are going
2484 * to start countermeasures and AP better do the same.
2486 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2488 /* initialize countermeasures */
2489 wpa_s->countermeasures = 1;
2491 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2493 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2496 * Need to wait for completion of request frame. We do not get
2497 * any callback for the message completion, so just wait a
2498 * short while and hope for the best. */
2501 wpa_drv_set_countermeasures(wpa_s, 1);
2502 wpa_supplicant_deauthenticate(wpa_s,
2503 WLAN_REASON_MICHAEL_MIC_FAILURE);
2504 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2506 eloop_register_timeout(60, 0,
2507 wpa_supplicant_stop_countermeasures,
2509 /* TODO: mark the AP rejected for 60 second. STA is
2510 * allowed to associate with another AP.. */
2512 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2513 if (wpa_s->mic_errors_seen) {
2515 * Reduce the effectiveness of Michael MIC error
2516 * reports as a means for attacking against TKIP if
2517 * more than one MIC failure is noticed with the same
2518 * PTK. We delay the transmission of the reports by a
2519 * random time between 0 and 60 seconds in order to
2520 * force the attacker wait 60 seconds before getting
2521 * the information on whether a frame resulted in a MIC
2527 if (os_get_random(rval, sizeof(rval)) < 0)
2528 sec = os_random() % 60;
2530 sec = WPA_GET_BE32(rval) % 60;
2531 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2532 "report %d seconds", sec);
2533 wpa_s->pending_mic_error_report = 1;
2534 wpa_s->pending_mic_error_pairwise = pairwise;
2535 eloop_cancel_timeout(
2536 wpa_supplicant_delayed_mic_error_report,
2538 eloop_register_timeout(
2539 sec, os_random() % 1000000,
2540 wpa_supplicant_delayed_mic_error_report,
2543 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2545 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2546 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2547 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2549 wpa_s->last_michael_mic_error = t;
2550 wpa_s->mic_errors_seen++;
2554 #ifdef CONFIG_TERMINATE_ONLASTIF
2555 static int any_interfaces(struct wpa_supplicant *head)
2557 struct wpa_supplicant *wpa_s;
2559 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2560 if (!wpa_s->interface_removed)
2564 #endif /* CONFIG_TERMINATE_ONLASTIF */
2568 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2569 union wpa_event_data *data)
2571 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2574 switch (data->interface_status.ievent) {
2575 case EVENT_INTERFACE_ADDED:
2576 if (!wpa_s->interface_removed)
2578 wpa_s->interface_removed = 0;
2579 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2580 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2581 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2582 "driver after interface was added");
2586 if (!wpa_s->global->p2p &&
2587 !wpa_s->global->p2p_disabled &&
2588 !wpa_s->conf->p2p_disabled &&
2590 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2591 wpas_p2p_add_p2pdev_interface(
2592 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2593 wpa_printf(MSG_INFO,
2594 "P2P: Failed to enable P2P Device interface");
2595 /* Try to continue without. P2P will be disabled. */
2597 #endif /* CONFIG_P2P */
2600 case EVENT_INTERFACE_REMOVED:
2601 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2602 wpa_s->interface_removed = 1;
2603 wpa_supplicant_mark_disassoc(wpa_s);
2604 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2605 l2_packet_deinit(wpa_s->l2);
2609 if (wpa_s->global->p2p &&
2610 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2612 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2613 wpa_dbg(wpa_s, MSG_DEBUG,
2614 "Removing P2P Device interface");
2615 wpa_supplicant_remove_iface(
2616 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2618 wpa_s->global->p2p_init_wpa_s = NULL;
2620 #endif /* CONFIG_P2P */
2622 #ifdef CONFIG_TERMINATE_ONLASTIF
2623 /* check if last interface */
2624 if (!any_interfaces(wpa_s->global->ifaces))
2626 #endif /* CONFIG_TERMINATE_ONLASTIF */
2632 #ifdef CONFIG_PEERKEY
2634 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2635 union wpa_event_data *data)
2639 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2641 #endif /* CONFIG_PEERKEY */
2645 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2646 union wpa_event_data *data)
2650 switch (data->tdls.oper) {
2651 case TDLS_REQUEST_SETUP:
2652 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2653 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2654 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2656 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2658 case TDLS_REQUEST_TEARDOWN:
2659 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2660 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2661 data->tdls.reason_code);
2663 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2666 case TDLS_REQUEST_DISCOVER:
2667 wpa_tdls_send_discovery_request(wpa_s->wpa,
2672 #endif /* CONFIG_TDLS */
2676 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2677 union wpa_event_data *data)
2681 switch (data->wnm.oper) {
2682 case WNM_OPER_SLEEP:
2683 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2684 "(action=%d, intval=%d)",
2685 data->wnm.sleep_action, data->wnm.sleep_intval);
2686 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2687 data->wnm.sleep_intval, NULL);
2691 #endif /* CONFIG_WNM */
2694 #ifdef CONFIG_IEEE80211R
2696 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2697 union wpa_event_data *data)
2702 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2703 data->ft_ies.ies_len,
2704 data->ft_ies.ft_action,
2705 data->ft_ies.target_ap,
2706 data->ft_ies.ric_ies,
2707 data->ft_ies.ric_ies_len) < 0) {
2708 /* TODO: prevent MLME/driver from trying to associate? */
2711 #endif /* CONFIG_IEEE80211R */
2714 #ifdef CONFIG_IBSS_RSN
2715 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2716 union wpa_event_data *data)
2718 struct wpa_ssid *ssid;
2719 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2723 ssid = wpa_s->current_ssid;
2726 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2729 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2733 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2734 union wpa_event_data *data)
2736 struct wpa_ssid *ssid = wpa_s->current_ssid;
2741 /* check if the ssid is correctly configured as IBSS/RSN */
2742 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2745 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2746 data->rx_mgmt.frame_len);
2748 #endif /* CONFIG_IBSS_RSN */
2751 #ifdef CONFIG_IEEE80211R
2752 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2755 const u8 *sta_addr, *target_ap_addr;
2758 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2759 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2760 return; /* only SME case supported for now */
2761 if (len < 1 + 2 * ETH_ALEN + 2)
2764 return; /* Only FT Action Response is supported for now */
2765 sta_addr = data + 1;
2766 target_ap_addr = data + 1 + ETH_ALEN;
2767 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2768 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2769 MACSTR " TargetAP " MACSTR " status %u",
2770 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2772 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2773 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2774 " in FT Action Response", MAC2STR(sta_addr));
2779 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2780 "failure (status code %d)", status);
2781 /* TODO: report error to FT code(?) */
2785 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2786 len - (1 + 2 * ETH_ALEN + 2), 1,
2787 target_ap_addr, NULL, 0) < 0)
2792 struct wpa_bss *bss;
2793 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2795 wpa_s->sme.freq = bss->freq;
2796 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2797 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2800 #endif /* CONFIG_SME */
2802 #endif /* CONFIG_IEEE80211R */
2805 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2806 struct unprot_deauth *e)
2808 #ifdef CONFIG_IEEE80211W
2809 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2810 "dropped: " MACSTR " -> " MACSTR
2811 " (reason code %u)",
2812 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2813 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2814 #endif /* CONFIG_IEEE80211W */
2818 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2819 struct unprot_disassoc *e)
2821 #ifdef CONFIG_IEEE80211W
2822 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2823 "dropped: " MACSTR " -> " MACSTR
2824 " (reason code %u)",
2825 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2826 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2827 #endif /* CONFIG_IEEE80211W */
2831 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2832 u16 reason_code, int locally_generated,
2833 const u8 *ie, size_t ie_len, int deauth)
2836 if (wpa_s->ap_iface && addr) {
2837 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2841 if (wpa_s->ap_iface) {
2842 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2845 #endif /* CONFIG_AP */
2847 if (!locally_generated)
2848 wpa_s->own_disconnect_req = 0;
2850 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2852 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2853 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2854 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2855 eapol_sm_failed(wpa_s->eapol))) &&
2856 !wpa_s->eap_expected_failure))
2857 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2860 if (deauth && reason_code > 0) {
2861 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2862 locally_generated) > 0) {
2864 * The interface was removed, so cannot continue
2865 * processing any additional operations after this.
2870 #endif /* CONFIG_P2P */
2872 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2877 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2878 struct disassoc_info *info)
2880 u16 reason_code = 0;
2881 int locally_generated = 0;
2882 const u8 *addr = NULL;
2883 const u8 *ie = NULL;
2886 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2891 ie_len = info->ie_len;
2892 reason_code = info->reason_code;
2893 locally_generated = info->locally_generated;
2894 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2895 locally_generated ? " (locally generated)" : "");
2897 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2899 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2904 if (wpa_s->ap_iface && info && info->addr) {
2905 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2909 if (wpa_s->ap_iface) {
2910 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2913 #endif /* CONFIG_AP */
2917 wpas_p2p_disassoc_notif(
2918 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2921 #endif /* CONFIG_P2P */
2923 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2924 sme_event_disassoc(wpa_s, info);
2926 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2931 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2932 struct deauth_info *info)
2934 u16 reason_code = 0;
2935 int locally_generated = 0;
2936 const u8 *addr = NULL;
2937 const u8 *ie = NULL;
2940 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2945 ie_len = info->ie_len;
2946 reason_code = info->reason_code;
2947 locally_generated = info->locally_generated;
2948 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2950 locally_generated ? " (locally generated)" : "");
2952 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2955 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2959 wpa_reset_ft_completed(wpa_s->wpa);
2961 wpas_event_disconnect(wpa_s, addr, reason_code,
2962 locally_generated, ie, ie_len, 1);
2966 static const char * reg_init_str(enum reg_change_initiator init)
2969 case REGDOM_SET_BY_CORE:
2971 case REGDOM_SET_BY_USER:
2973 case REGDOM_SET_BY_DRIVER:
2975 case REGDOM_SET_BY_COUNTRY_IE:
2976 return "COUNTRY_IE";
2977 case REGDOM_BEACON_HINT:
2978 return "BEACON_HINT";
2984 static const char * reg_type_str(enum reg_type type)
2987 case REGDOM_TYPE_UNKNOWN:
2989 case REGDOM_TYPE_COUNTRY:
2991 case REGDOM_TYPE_WORLD:
2993 case REGDOM_TYPE_CUSTOM_WORLD:
2994 return "CUSTOM_WORLD";
2995 case REGDOM_TYPE_INTERSECTION:
2996 return "INTERSECTION";
3002 static void wpa_supplicant_update_channel_list(
3003 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3005 struct wpa_supplicant *ifs;
3007 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3008 reg_init_str(info->initiator), reg_type_str(info->type),
3009 info->alpha2[0] ? " alpha2=" : "",
3010 info->alpha2[0] ? info->alpha2 : "");
3012 if (wpa_s->drv_priv == NULL)
3013 return; /* Ignore event during drv initialization */
3015 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3017 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3019 free_hw_features(ifs);
3020 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3021 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3024 /* Restart sched_scan with updated channel list */
3025 if (wpa_s->sched_scanning) {
3026 wpa_dbg(wpa_s, MSG_DEBUG,
3027 "Channel list changed restart sched scan.");
3028 wpa_supplicant_cancel_sched_scan(wpa_s);
3029 wpa_supplicant_req_scan(wpa_s, 0, 0);
3032 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3036 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3037 const u8 *frame, size_t len, int freq,
3040 const struct ieee80211_mgmt *mgmt;
3045 if (len < IEEE80211_HDRLEN + 2)
3048 mgmt = (const struct ieee80211_mgmt *) frame;
3049 payload = frame + IEEE80211_HDRLEN;
3050 category = *payload++;
3051 plen = len - IEEE80211_HDRLEN - 1;
3053 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3054 " Category=%u DataLen=%d freq=%d MHz",
3055 MAC2STR(mgmt->sa), category, (int) plen, freq);
3057 if (category == WLAN_ACTION_WMM) {
3058 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3062 #ifdef CONFIG_IEEE80211R
3063 if (category == WLAN_ACTION_FT) {
3064 ft_rx_action(wpa_s, payload, plen);
3067 #endif /* CONFIG_IEEE80211R */
3069 #ifdef CONFIG_IEEE80211W
3071 if (category == WLAN_ACTION_SA_QUERY) {
3072 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3075 #endif /* CONFIG_SME */
3076 #endif /* CONFIG_IEEE80211W */
3079 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3080 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3083 #endif /* CONFIG_WNM */
3086 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3087 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3088 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3089 mgmt->u.action.category,
3090 payload, plen, freq) == 0)
3092 #endif /* CONFIG_GAS */
3095 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3096 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3097 wpa_dbg(wpa_s, MSG_DEBUG,
3098 "TDLS: Received Discovery Response from " MACSTR,
3102 #endif /* CONFIG_TDLS */
3104 #ifdef CONFIG_INTERWORKING
3105 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3106 payload[0] == QOS_QOS_MAP_CONFIG) {
3107 const u8 *pos = payload + 1;
3108 size_t qlen = plen - 1;
3109 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3110 MACSTR, MAC2STR(mgmt->sa));
3111 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3112 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3113 pos[1] <= qlen - 2 && pos[1] >= 16)
3114 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3117 #endif /* CONFIG_INTERWORKING */
3119 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3120 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3121 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3125 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3126 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3127 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3128 payload + 1, plen - 1,
3134 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3135 fst_rx_action(wpa_s->fst, mgmt, len);
3138 #endif /* CONFIG_FST */
3140 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3141 category, payload, plen, freq);
3143 mesh_mpm_action_rx(wpa_s, mgmt, len);
3147 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3148 union wpa_event_data *event)
3150 struct wpa_freq_range_list *list;
3153 list = &event->freq_range;
3156 str = freq_range_list_str(list);
3157 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3161 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3162 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3165 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3168 * The update channel flow will also take care of moving a GO
3169 * from the unsafe frequency if needed.
3171 wpas_p2p_update_channel_list(wpa_s,
3172 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3174 #endif /* CONFIG_P2P */
3180 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3181 union wpa_event_data *data)
3183 wpa_dbg(wpa_s, MSG_DEBUG,
3184 "Connection authorized by device, previous state %d",
3186 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3187 wpa_supplicant_cancel_auth_timeout(wpa_s);
3188 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3189 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3190 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3192 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3193 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3194 data->assoc_info.ptk_kck_len,
3195 data->assoc_info.ptk_kek,
3196 data->assoc_info.ptk_kek_len);
3200 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3201 union wpa_event_data *data)
3203 struct wpa_supplicant *wpa_s = ctx;
3206 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3207 event != EVENT_INTERFACE_ENABLED &&
3208 event != EVENT_INTERFACE_STATUS &&
3209 event != EVENT_SCHED_SCAN_STOPPED) {
3210 wpa_dbg(wpa_s, MSG_DEBUG,
3211 "Ignore event %s (%d) while interface is disabled",
3212 event_to_string(event), event);
3216 #ifndef CONFIG_NO_STDOUT_DEBUG
3218 int level = MSG_DEBUG;
3220 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3221 const struct ieee80211_hdr *hdr;
3223 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3224 fc = le_to_host16(hdr->frame_control);
3225 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3226 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3227 level = MSG_EXCESSIVE;
3230 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3231 event_to_string(event), event);
3233 #endif /* CONFIG_NO_STDOUT_DEBUG */
3237 sme_event_auth(wpa_s, data);
3240 wpa_supplicant_event_assoc(wpa_s, data);
3241 if (data && data->assoc_info.authorized)
3242 wpa_supplicant_event_assoc_auth(wpa_s, data);
3244 case EVENT_DISASSOC:
3245 wpas_event_disassoc(wpa_s,
3246 data ? &data->disassoc_info : NULL);
3249 wpas_event_deauth(wpa_s,
3250 data ? &data->deauth_info : NULL);
3252 case EVENT_MICHAEL_MIC_FAILURE:
3253 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3255 #ifndef CONFIG_NO_SCAN_PROCESSING
3256 case EVENT_SCAN_STARTED:
3257 os_get_reltime(&wpa_s->scan_start_time);
3258 if (wpa_s->own_scan_requested) {
3259 struct os_reltime diff;
3261 os_reltime_sub(&wpa_s->scan_start_time,
3262 &wpa_s->scan_trigger_time, &diff);
3263 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3264 diff.sec, diff.usec);
3265 wpa_s->own_scan_requested = 0;
3266 wpa_s->own_scan_running = 1;
3267 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3268 wpa_s->manual_scan_use_id) {
3269 wpa_msg_ctrl(wpa_s, MSG_INFO,
3270 WPA_EVENT_SCAN_STARTED "id=%u",
3271 wpa_s->manual_scan_id);
3273 wpa_msg_ctrl(wpa_s, MSG_INFO,
3274 WPA_EVENT_SCAN_STARTED);
3277 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3278 wpa_s->radio->external_scan_running = 1;
3279 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3282 case EVENT_SCAN_RESULTS:
3283 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3284 struct os_reltime now, diff;
3285 os_get_reltime(&now);
3286 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3287 wpa_s->scan_start_time.sec = 0;
3288 wpa_s->scan_start_time.usec = 0;
3289 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3290 diff.sec, diff.usec);
3292 if (wpa_supplicant_event_scan_results(wpa_s, data))
3293 break; /* interface may have been removed */
3294 wpa_s->own_scan_running = 0;
3295 wpa_s->radio->external_scan_running = 0;
3296 radio_work_check_next(wpa_s);
3298 #endif /* CONFIG_NO_SCAN_PROCESSING */
3299 case EVENT_ASSOCINFO:
3300 wpa_supplicant_event_associnfo(wpa_s, data);
3302 case EVENT_INTERFACE_STATUS:
3303 wpa_supplicant_event_interface_status(wpa_s, data);
3305 case EVENT_PMKID_CANDIDATE:
3306 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3308 #ifdef CONFIG_PEERKEY
3309 case EVENT_STKSTART:
3310 wpa_supplicant_event_stkstart(wpa_s, data);
3312 #endif /* CONFIG_PEERKEY */
3315 wpa_supplicant_event_tdls(wpa_s, data);
3317 #endif /* CONFIG_TDLS */
3320 wpa_supplicant_event_wnm(wpa_s, data);
3322 #endif /* CONFIG_WNM */
3323 #ifdef CONFIG_IEEE80211R
3324 case EVENT_FT_RESPONSE:
3325 wpa_supplicant_event_ft_response(wpa_s, data);
3327 #endif /* CONFIG_IEEE80211R */
3328 #ifdef CONFIG_IBSS_RSN
3329 case EVENT_IBSS_RSN_START:
3330 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3332 #endif /* CONFIG_IBSS_RSN */
3333 case EVENT_ASSOC_REJECT:
3334 if (data->assoc_reject.bssid)
3335 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3336 "bssid=" MACSTR " status_code=%u",
3337 MAC2STR(data->assoc_reject.bssid),
3338 data->assoc_reject.status_code);
3340 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3342 data->assoc_reject.status_code);
3343 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3344 sme_event_assoc_reject(wpa_s, data);
3346 const u8 *bssid = data->assoc_reject.bssid;
3347 if (bssid == NULL || is_zero_ether_addr(bssid))
3348 bssid = wpa_s->pending_bssid;
3349 wpas_connection_failed(wpa_s, bssid);
3350 wpa_supplicant_mark_disassoc(wpa_s);
3353 case EVENT_AUTH_TIMED_OUT:
3354 /* It is possible to get this event from earlier connection */
3355 if (wpa_s->current_ssid &&
3356 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3357 wpa_dbg(wpa_s, MSG_DEBUG,
3358 "Ignore AUTH_TIMED_OUT in mesh configuration");
3361 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3362 sme_event_auth_timed_out(wpa_s, data);
3364 case EVENT_ASSOC_TIMED_OUT:
3365 /* It is possible to get this event from earlier connection */
3366 if (wpa_s->current_ssid &&
3367 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3368 wpa_dbg(wpa_s, MSG_DEBUG,
3369 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3372 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3373 sme_event_assoc_timed_out(wpa_s, data);
3375 case EVENT_TX_STATUS:
3376 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3377 " type=%d stype=%d",
3378 MAC2STR(data->tx_status.dst),
3379 data->tx_status.type, data->tx_status.stype);
3381 if (wpa_s->ap_iface == NULL) {
3382 #ifdef CONFIG_OFFCHANNEL
3383 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3384 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3385 offchannel_send_action_tx_status(
3386 wpa_s, data->tx_status.dst,
3387 data->tx_status.data,
3388 data->tx_status.data_len,
3389 data->tx_status.ack ?
3390 OFFCHANNEL_SEND_ACTION_SUCCESS :
3391 OFFCHANNEL_SEND_ACTION_NO_ACK);
3392 #endif /* CONFIG_OFFCHANNEL */
3395 #endif /* CONFIG_AP */
3396 #ifdef CONFIG_OFFCHANNEL
3397 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3398 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3400 * Catch TX status events for Action frames we sent via group
3401 * interface in GO mode.
3403 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3404 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3405 os_memcmp(wpa_s->parent->pending_action_dst,
3406 data->tx_status.dst, ETH_ALEN) == 0) {
3407 offchannel_send_action_tx_status(
3408 wpa_s->parent, data->tx_status.dst,
3409 data->tx_status.data,
3410 data->tx_status.data_len,
3411 data->tx_status.ack ?
3412 OFFCHANNEL_SEND_ACTION_SUCCESS :
3413 OFFCHANNEL_SEND_ACTION_NO_ACK);
3416 #endif /* CONFIG_OFFCHANNEL */
3418 switch (data->tx_status.type) {
3419 case WLAN_FC_TYPE_MGMT:
3420 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3421 data->tx_status.data_len,
3422 data->tx_status.stype,
3423 data->tx_status.ack);
3425 case WLAN_FC_TYPE_DATA:
3426 ap_tx_status(wpa_s, data->tx_status.dst,
3427 data->tx_status.data,
3428 data->tx_status.data_len,
3429 data->tx_status.ack);
3432 #endif /* CONFIG_AP */
3435 case EVENT_EAPOL_TX_STATUS:
3436 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3437 data->eapol_tx_status.data,
3438 data->eapol_tx_status.data_len,
3439 data->eapol_tx_status.ack);
3441 case EVENT_DRIVER_CLIENT_POLL_OK:
3442 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3444 case EVENT_RX_FROM_UNKNOWN:
3445 if (wpa_s->ap_iface == NULL)
3447 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3448 data->rx_from_unknown.wds);
3450 case EVENT_CH_SWITCH:
3453 if (!wpa_s->ap_iface) {
3454 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3455 "event in non-AP mode");
3459 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3460 data->ch_switch.ht_enabled,
3461 data->ch_switch.ch_offset,
3462 data->ch_switch.ch_width,
3463 data->ch_switch.cf1,
3464 data->ch_switch.cf2);
3467 case EVENT_DFS_RADAR_DETECTED:
3469 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3471 case EVENT_DFS_CAC_STARTED:
3473 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3475 case EVENT_DFS_CAC_FINISHED:
3477 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3479 case EVENT_DFS_CAC_ABORTED:
3481 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3483 case EVENT_DFS_NOP_FINISHED:
3485 wpas_event_dfs_cac_nop_finished(wpa_s,
3488 #endif /* NEED_AP_MLME */
3489 #endif /* CONFIG_AP */
3490 case EVENT_RX_MGMT: {
3492 const struct ieee80211_mgmt *mgmt;
3494 #ifdef CONFIG_TESTING_OPTIONS
3495 if (wpa_s->ext_mgmt_frame_handling) {
3496 struct rx_mgmt *rx = &data->rx_mgmt;
3497 size_t hex_len = 2 * rx->frame_len + 1;
3498 char *hex = os_malloc(hex_len);
3500 wpa_snprintf_hex(hex, hex_len,
3501 rx->frame, rx->frame_len);
3502 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3503 rx->freq, rx->datarate, rx->ssi_signal,
3509 #endif /* CONFIG_TESTING_OPTIONS */
3511 mgmt = (const struct ieee80211_mgmt *)
3512 data->rx_mgmt.frame;
3513 fc = le_to_host16(mgmt->frame_control);
3514 stype = WLAN_FC_GET_STYPE(fc);
3517 if (wpa_s->ap_iface == NULL) {
3518 #endif /* CONFIG_AP */
3520 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3521 data->rx_mgmt.frame_len > 24) {
3522 const u8 *src = mgmt->sa;
3523 const u8 *ie = mgmt->u.probe_req.variable;
3524 size_t ie_len = data->rx_mgmt.frame_len -
3525 (mgmt->u.probe_req.variable -
3526 data->rx_mgmt.frame);
3527 wpas_p2p_probe_req_rx(
3528 wpa_s, src, mgmt->da,
3529 mgmt->bssid, ie, ie_len,
3531 data->rx_mgmt.ssi_signal);
3534 #endif /* CONFIG_P2P */
3535 #ifdef CONFIG_IBSS_RSN
3536 if (wpa_s->current_ssid &&
3537 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3538 stype == WLAN_FC_STYPE_AUTH &&
3539 data->rx_mgmt.frame_len >= 30) {
3540 wpa_supplicant_event_ibss_auth(wpa_s, data);
3543 #endif /* CONFIG_IBSS_RSN */
3545 if (stype == WLAN_FC_STYPE_ACTION) {
3546 wpas_event_rx_mgmt_action(
3547 wpa_s, data->rx_mgmt.frame,
3548 data->rx_mgmt.frame_len,
3550 data->rx_mgmt.ssi_signal);
3555 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3559 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3560 "management frame in non-AP mode");
3565 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3566 data->rx_mgmt.frame_len > 24) {
3567 const u8 *ie = mgmt->u.probe_req.variable;
3568 size_t ie_len = data->rx_mgmt.frame_len -
3569 (mgmt->u.probe_req.variable -
3570 data->rx_mgmt.frame);
3572 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3573 mgmt->bssid, ie, ie_len,
3574 data->rx_mgmt.ssi_signal);
3577 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3578 #endif /* CONFIG_AP */
3581 case EVENT_RX_PROBE_REQ:
3582 if (data->rx_probe_req.sa == NULL ||
3583 data->rx_probe_req.ie == NULL)
3586 if (wpa_s->ap_iface) {
3587 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3588 data->rx_probe_req.sa,
3589 data->rx_probe_req.da,
3590 data->rx_probe_req.bssid,
3591 data->rx_probe_req.ie,
3592 data->rx_probe_req.ie_len,
3593 data->rx_probe_req.ssi_signal);
3596 #endif /* CONFIG_AP */
3597 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3598 data->rx_probe_req.da,
3599 data->rx_probe_req.bssid,
3600 data->rx_probe_req.ie,
3601 data->rx_probe_req.ie_len,
3603 data->rx_probe_req.ssi_signal);
3605 case EVENT_REMAIN_ON_CHANNEL:
3606 #ifdef CONFIG_OFFCHANNEL
3607 offchannel_remain_on_channel_cb(
3608 wpa_s, data->remain_on_channel.freq,
3609 data->remain_on_channel.duration);
3610 #endif /* CONFIG_OFFCHANNEL */
3611 wpas_p2p_remain_on_channel_cb(
3612 wpa_s, data->remain_on_channel.freq,
3613 data->remain_on_channel.duration);
3615 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3616 #ifdef CONFIG_OFFCHANNEL
3617 offchannel_cancel_remain_on_channel_cb(
3618 wpa_s, data->remain_on_channel.freq);
3619 #endif /* CONFIG_OFFCHANNEL */
3620 wpas_p2p_cancel_remain_on_channel_cb(
3621 wpa_s, data->remain_on_channel.freq);
3623 case EVENT_EAPOL_RX:
3624 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3625 data->eapol_rx.data,
3626 data->eapol_rx.data_len);
3628 case EVENT_SIGNAL_CHANGE:
3629 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3630 "above=%d signal=%d noise=%d txrate=%d",
3631 data->signal_change.above_threshold,
3632 data->signal_change.current_signal,
3633 data->signal_change.current_noise,
3634 data->signal_change.current_txrate);
3635 wpa_bss_update_level(wpa_s->current_bss,
3636 data->signal_change.current_signal);
3637 bgscan_notify_signal_change(
3638 wpa_s, data->signal_change.above_threshold,
3639 data->signal_change.current_signal,
3640 data->signal_change.current_noise,
3641 data->signal_change.current_txrate);
3643 case EVENT_INTERFACE_ENABLED:
3644 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3645 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3646 wpa_supplicant_update_mac_addr(wpa_s);
3647 if (wpa_s->p2p_mgmt) {
3648 wpa_supplicant_set_state(wpa_s,
3654 if (!wpa_s->ap_iface) {
3655 wpa_supplicant_set_state(wpa_s,
3657 wpa_s->scan_req = NORMAL_SCAN_REQ;
3658 wpa_supplicant_req_scan(wpa_s, 0, 0);
3660 wpa_supplicant_set_state(wpa_s,
3662 #else /* CONFIG_AP */
3663 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3664 wpa_supplicant_req_scan(wpa_s, 0, 0);
3665 #endif /* CONFIG_AP */
3668 case EVENT_INTERFACE_DISABLED:
3669 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3671 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3672 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3673 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3675 * Mark interface disabled if this happens to end up not
3676 * being removed as a separate P2P group interface.
3678 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3680 * The interface was externally disabled. Remove
3681 * it assuming an external entity will start a
3682 * new session if needed.
3684 if (wpa_s->current_ssid &&
3685 wpa_s->current_ssid->p2p_group)
3686 wpas_p2p_interface_unavailable(wpa_s);
3688 wpas_p2p_disconnect(wpa_s);
3690 * wpa_s instance may have been freed, so must not use
3695 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3696 p2p_in_progress(wpa_s->global->p2p) > 1) {
3697 /* This radio work will be cancelled, so clear P2P
3700 p2p_stop_find(wpa_s->global->p2p);
3702 #endif /* CONFIG_P2P */
3704 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3706 * Indicate disconnection to keep ctrl_iface events
3709 wpa_supplicant_event_disassoc(
3710 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3712 wpa_supplicant_mark_disassoc(wpa_s);
3713 radio_remove_works(wpa_s, NULL, 0);
3715 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3717 case EVENT_CHANNEL_LIST_CHANGED:
3718 wpa_supplicant_update_channel_list(
3719 wpa_s, &data->channel_list_changed);
3721 case EVENT_INTERFACE_UNAVAILABLE:
3722 wpas_p2p_interface_unavailable(wpa_s);
3724 case EVENT_BEST_CHANNEL:
3725 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3727 data->best_chan.freq_24, data->best_chan.freq_5,
3728 data->best_chan.freq_overall);
3729 wpa_s->best_24_freq = data->best_chan.freq_24;
3730 wpa_s->best_5_freq = data->best_chan.freq_5;
3731 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3732 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3733 data->best_chan.freq_5,
3734 data->best_chan.freq_overall);
3736 case EVENT_UNPROT_DEAUTH:
3737 wpa_supplicant_event_unprot_deauth(wpa_s,
3738 &data->unprot_deauth);
3740 case EVENT_UNPROT_DISASSOC:
3741 wpa_supplicant_event_unprot_disassoc(wpa_s,
3742 &data->unprot_disassoc);
3744 case EVENT_STATION_LOW_ACK:
3746 if (wpa_s->ap_iface && data)
3747 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3748 data->low_ack.addr);
3749 #endif /* CONFIG_AP */
3752 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3753 data->low_ack.addr);
3754 #endif /* CONFIG_TDLS */
3756 case EVENT_IBSS_PEER_LOST:
3757 #ifdef CONFIG_IBSS_RSN
3758 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3759 #endif /* CONFIG_IBSS_RSN */
3761 case EVENT_DRIVER_GTK_REKEY:
3762 if (os_memcmp(data->driver_gtk_rekey.bssid,
3763 wpa_s->bssid, ETH_ALEN))
3767 wpa_sm_update_replay_ctr(wpa_s->wpa,
3768 data->driver_gtk_rekey.replay_ctr);
3770 case EVENT_SCHED_SCAN_STOPPED:
3772 wpa_s->sched_scanning = 0;
3773 resched = wpa_s->scanning;
3774 wpa_supplicant_notify_scanning(wpa_s, 0);
3776 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3780 * Start a new sched scan to continue searching for more SSIDs
3781 * either if timed out or PNO schedule scan is pending.
3783 if (wpa_s->sched_scan_timed_out) {
3784 wpa_supplicant_req_sched_scan(wpa_s);
3785 } else if (wpa_s->pno_sched_pending) {
3786 wpa_s->pno_sched_pending = 0;
3787 wpas_start_pno(wpa_s);
3788 } else if (resched) {
3789 wpa_supplicant_req_scan(wpa_s, 0, 0);
3793 case EVENT_WPS_BUTTON_PUSHED:
3795 wpas_wps_start_pbc(wpa_s, NULL, 0);
3796 #endif /* CONFIG_WPS */
3798 case EVENT_AVOID_FREQUENCIES:
3799 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3801 case EVENT_CONNECT_FAILED_REASON:
3803 if (!wpa_s->ap_iface || !data)
3805 hostapd_event_connect_failed_reason(
3806 wpa_s->ap_iface->bss[0],
3807 data->connect_failed_reason.addr,
3808 data->connect_failed_reason.code);
3809 #endif /* CONFIG_AP */
3811 case EVENT_NEW_PEER_CANDIDATE:
3813 if (!wpa_s->ifmsh || !data)
3815 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3816 data->mesh_peer.ies,
3817 data->mesh_peer.ie_len);
3818 #endif /* CONFIG_MESH */
3821 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);