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 freq=%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, bss->freq,
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_pbc_overlap(wpa_s);
1205 wpas_wps_cancel(wpa_s);
1206 #endif /* CONFIG_WPS */
1210 wpa_msg(wpa_s, MSG_DEBUG,
1211 "Considering connect request: reassociate: %d selected: "
1212 MACSTR " bssid: " MACSTR " pending: " MACSTR
1213 " wpa_state: %s ssid=%p current_ssid=%p",
1214 wpa_s->reassociate, MAC2STR(selected->bssid),
1215 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1216 wpa_supplicant_state_txt(wpa_s->wpa_state),
1217 ssid, wpa_s->current_ssid);
1220 * Do not trigger new association unless the BSSID has changed or if
1221 * reassociation is requested. If we are in process of associating with
1222 * the selected BSSID, do not trigger new attempt.
1224 if (wpa_s->reassociate ||
1225 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1226 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1227 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1228 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1229 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1231 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1232 ssid != wpa_s->current_ssid)))) {
1233 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1234 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1237 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1238 MAC2STR(selected->bssid));
1239 wpa_supplicant_associate(wpa_s, selected, ssid);
1241 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1242 "connect with the selected AP");
1249 static struct wpa_ssid *
1250 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1253 struct wpa_ssid *ssid;
1255 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1256 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1258 if (wpas_network_disabled(wpa_s, ssid))
1260 if (ssid->mode == IEEE80211_MODE_IBSS ||
1261 ssid->mode == IEEE80211_MODE_AP ||
1262 ssid->mode == IEEE80211_MODE_MESH)
1270 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1271 * on BSS added and BSS changed events */
1272 static void wpa_supplicant_rsn_preauth_scan_results(
1273 struct wpa_supplicant *wpa_s)
1275 struct wpa_bss *bss;
1277 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1280 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1281 const u8 *ssid, *rsn;
1283 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1287 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1291 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1297 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1298 struct wpa_bss *selected,
1299 struct wpa_ssid *ssid)
1301 struct wpa_bss *current_bss = NULL;
1302 #ifndef CONFIG_NO_ROAMING
1304 #endif /* CONFIG_NO_ROAMING */
1306 if (wpa_s->reassociate)
1307 return 1; /* explicit request to reassociate */
1308 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1309 return 1; /* we are not associated; continue */
1310 if (wpa_s->current_ssid == NULL)
1311 return 1; /* unknown current SSID */
1312 if (wpa_s->current_ssid != ssid)
1313 return 1; /* different network block */
1315 if (wpas_driver_bss_selection(wpa_s))
1316 return 0; /* Driver-based roaming */
1318 if (wpa_s->current_ssid->ssid)
1319 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1320 wpa_s->current_ssid->ssid,
1321 wpa_s->current_ssid->ssid_len);
1323 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1326 return 1; /* current BSS not seen in scan results */
1328 if (current_bss == selected)
1331 if (selected->last_update_idx > current_bss->last_update_idx)
1332 return 1; /* current BSS not seen in the last scan */
1334 #ifndef CONFIG_NO_ROAMING
1335 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1336 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1337 " level=%d snr=%d est_throughput=%u",
1338 MAC2STR(current_bss->bssid), current_bss->level,
1339 current_bss->snr, current_bss->est_throughput);
1340 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1341 " level=%d snr=%d est_throughput=%u",
1342 MAC2STR(selected->bssid), selected->level,
1343 selected->snr, selected->est_throughput);
1345 if (wpa_s->current_ssid->bssid_set &&
1346 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1348 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1349 "has preferred BSSID");
1353 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1354 wpa_dbg(wpa_s, MSG_DEBUG,
1355 "Allow reassociation - selected BSS has better estimated throughput");
1359 if (current_bss->level < 0 && current_bss->level > selected->level) {
1360 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1366 if (current_bss->level < 0) {
1367 if (current_bss->level < -85)
1369 else if (current_bss->level < -80)
1371 else if (current_bss->level < -75)
1373 else if (current_bss->level < -70)
1378 if (abs(current_bss->level - selected->level) < min_diff) {
1379 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1385 #else /* CONFIG_NO_ROAMING */
1387 #endif /* CONFIG_NO_ROAMING */
1391 /* Return != 0 if no scan results could be fetched or if scan results should not
1392 * be shared with other virtual interfaces. */
1393 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1394 union wpa_event_data *data,
1397 struct wpa_scan_results *scan_res = NULL;
1400 #ifndef CONFIG_NO_RANDOM_POOL
1402 #endif /* CONFIG_NO_RANDOM_POOL */
1405 if (wpa_s->ap_iface)
1407 #endif /* CONFIG_AP */
1409 wpa_supplicant_notify_scanning(wpa_s, 0);
1411 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1412 data ? &data->scan_info :
1414 if (scan_res == NULL) {
1415 if (wpa_s->conf->ap_scan == 2 || ap ||
1416 wpa_s->scan_res_handler == scan_only_handler)
1420 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1422 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1424 goto scan_work_done;
1427 #ifndef CONFIG_NO_RANDOM_POOL
1428 num = scan_res->num;
1431 for (i = 0; i < num; i++) {
1433 struct wpa_scan_res *res = scan_res->res[i];
1434 buf[0] = res->bssid[5];
1435 buf[1] = res->qual & 0xff;
1436 buf[2] = res->noise & 0xff;
1437 buf[3] = res->level & 0xff;
1438 buf[4] = res->tsf & 0xff;
1439 random_add_randomness(buf, sizeof(buf));
1441 #endif /* CONFIG_NO_RANDOM_POOL */
1443 if (own_request && wpa_s->scan_res_handler &&
1444 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1445 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1446 struct wpa_scan_results *scan_res);
1448 scan_res_handler = wpa_s->scan_res_handler;
1449 wpa_s->scan_res_handler = NULL;
1450 scan_res_handler(wpa_s, scan_res);
1452 goto scan_work_done;
1456 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1458 if (wpa_s->ap_iface->scan_cb)
1459 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1460 #endif /* CONFIG_AP */
1461 goto scan_work_done;
1464 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1465 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1466 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1467 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1468 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1469 wpa_s->manual_scan_id);
1470 wpa_s->manual_scan_use_id = 0;
1472 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1474 wpas_notify_scan_results(wpa_s);
1476 wpas_notify_scan_done(wpa_s, 1);
1478 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1479 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1480 wpa_scan_results_free(scan_res);
1484 if (wnm_scan_process(wpa_s, 1) > 0)
1485 goto scan_work_done;
1487 if (sme_proc_obss_scan(wpa_s) > 0)
1488 goto scan_work_done;
1490 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1491 goto scan_work_done;
1493 if (autoscan_notify_scan(wpa_s, scan_res))
1494 goto scan_work_done;
1496 if (wpa_s->disconnected) {
1497 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1498 goto scan_work_done;
1501 if (!wpas_driver_bss_selection(wpa_s) &&
1502 bgscan_notify_scan(wpa_s, scan_res) == 1)
1503 goto scan_work_done;
1505 wpas_wps_update_ap_info(wpa_s, scan_res);
1507 wpa_scan_results_free(scan_res);
1509 if (wpa_s->scan_work) {
1510 struct wpa_radio_work *work = wpa_s->scan_work;
1511 wpa_s->scan_work = NULL;
1512 radio_work_done(work);
1515 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1518 wpa_scan_results_free(scan_res);
1519 if (wpa_s->scan_work) {
1520 struct wpa_radio_work *work = wpa_s->scan_work;
1521 wpa_s->scan_work = NULL;
1522 radio_work_done(work);
1528 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1529 int new_scan, int own_request)
1531 struct wpa_bss *selected;
1532 struct wpa_ssid *ssid = NULL;
1533 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1535 if (time_to_reenable > 0) {
1536 wpa_dbg(wpa_s, MSG_DEBUG,
1537 "Postpone network selection by %d seconds since all networks are disabled",
1539 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1540 eloop_register_timeout(time_to_reenable, 0,
1541 wpas_network_reenabled, wpa_s, NULL);
1545 if (wpa_s->p2p_mgmt)
1546 return 0; /* no normal connection on p2p_mgmt interface */
1548 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1552 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1555 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1559 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1560 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1564 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1566 * Do not notify other virtual radios of scan results since we do not
1567 * want them to start other associations at the same time.
1573 wpa_msg(wpa_s, MSG_INFO,
1574 "Avoiding join because we already joined a mesh group");
1577 #endif /* CONFIG_MESH */
1578 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1579 ssid = wpa_supplicant_pick_new_network(wpa_s);
1581 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1582 wpa_supplicant_associate(wpa_s, NULL, ssid);
1584 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1585 } else if (own_request) {
1587 * No SSID found. If SCAN results are as a result of
1588 * own scan request and not due to a scan request on
1589 * another shared interface, try another scan.
1591 int timeout_sec = wpa_s->scan_interval;
1592 int timeout_usec = 0;
1596 res = wpas_p2p_scan_no_go_seen(wpa_s);
1602 if (wpa_s->p2p_in_provisioning ||
1603 wpa_s->show_group_started ||
1604 wpa_s->p2p_in_invitation) {
1606 * Use shorter wait during P2P Provisioning
1607 * state and during P2P join-a-group operation
1608 * to speed up group formation.
1611 timeout_usec = 250000;
1612 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1616 #endif /* CONFIG_P2P */
1617 #ifdef CONFIG_INTERWORKING
1618 if (wpa_s->conf->auto_interworking &&
1619 wpa_s->conf->interworking &&
1620 wpa_s->conf->cred) {
1621 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1622 "start ANQP fetch since no matching "
1624 wpa_s->network_select = 1;
1625 wpa_s->auto_network_select = 1;
1626 interworking_start_fetch_anqp(wpa_s);
1629 #endif /* CONFIG_INTERWORKING */
1631 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1632 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1634 timeout_usec = 500000;
1635 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1639 #endif /* CONFIG_WPS */
1640 if (wpa_supplicant_req_sched_scan(wpa_s))
1641 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1644 wpa_msg_ctrl(wpa_s, MSG_INFO,
1645 WPA_EVENT_NETWORK_NOT_FOUND);
1652 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1653 union wpa_event_data *data)
1655 struct wpa_supplicant *ifs;
1658 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1661 * Interface may have been removed, so must not dereference
1668 * If no scan results could be fetched, then no need to
1669 * notify those interfaces that did not actually request
1670 * this scan. Similarly, if scan results started a new operation on this
1671 * interface, do not notify other interfaces to avoid concurrent
1672 * operations during a connection attempt.
1678 * Check other interfaces to see if they share the same radio. If
1679 * so, they get updated with this same scan info.
1681 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1684 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1685 "sibling", ifs->ifname);
1686 _wpa_supplicant_event_scan_results(ifs, data, 0);
1693 #endif /* CONFIG_NO_SCAN_PROCESSING */
1696 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1698 #ifdef CONFIG_NO_SCAN_PROCESSING
1700 #else /* CONFIG_NO_SCAN_PROCESSING */
1701 struct os_reltime now;
1703 if (wpa_s->last_scan_res_used == 0)
1706 os_get_reltime(&now);
1707 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1708 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1712 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1713 #endif /* CONFIG_NO_SCAN_PROCESSING */
1718 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1720 struct wpa_supplicant *wpa_s = eloop_ctx;
1722 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1725 if (!wpa_s->no_keep_alive) {
1726 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1727 MAC2STR(wpa_s->bssid));
1728 /* TODO: could skip this if normal data traffic has been sent */
1729 /* TODO: Consider using some more appropriate data frame for
1732 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1737 if (wpa_s->sme.bss_max_idle_period) {
1739 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1742 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1743 wnm_bss_keep_alive, wpa_s, NULL);
1745 #endif /* CONFIG_SME */
1749 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1750 const u8 *ies, size_t ies_len)
1752 struct ieee802_11_elems elems;
1757 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1761 if (elems.bss_max_idle_period) {
1763 wpa_s->sme.bss_max_idle_period =
1764 WPA_GET_LE16(elems.bss_max_idle_period);
1765 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1766 "TU)%s", wpa_s->sme.bss_max_idle_period,
1767 (elems.bss_max_idle_period[2] & 0x01) ?
1768 " (protected keep-live required)" : "");
1769 if (wpa_s->sme.bss_max_idle_period == 0)
1770 wpa_s->sme.bss_max_idle_period = 1;
1771 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1772 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1773 /* msec times 1000 */
1774 msec = wpa_s->sme.bss_max_idle_period * 1024;
1777 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1778 wnm_bss_keep_alive, wpa_s,
1782 #endif /* CONFIG_SME */
1785 #endif /* CONFIG_WNM */
1788 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1791 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1792 #endif /* CONFIG_WNM */
1796 #ifdef CONFIG_INTERWORKING
1798 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1803 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1804 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1806 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1813 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1814 const u8 *ies, size_t ies_len)
1816 struct ieee802_11_elems elems;
1821 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1824 if (elems.qos_map_set) {
1825 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1826 elems.qos_map_set_len);
1830 #endif /* CONFIG_INTERWORKING */
1833 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1834 union wpa_event_data *data)
1836 int l, len, found = 0, wpa_found, rsn_found;
1838 #ifdef CONFIG_IEEE80211R
1840 #endif /* CONFIG_IEEE80211R */
1842 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1843 if (data->assoc_info.req_ies)
1844 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1845 data->assoc_info.req_ies_len);
1846 if (data->assoc_info.resp_ies) {
1847 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1848 data->assoc_info.resp_ies_len);
1850 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1851 data->assoc_info.resp_ies_len);
1852 #endif /* CONFIG_TDLS */
1854 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1855 data->assoc_info.resp_ies_len);
1856 #endif /* CONFIG_WNM */
1857 #ifdef CONFIG_INTERWORKING
1858 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1859 data->assoc_info.resp_ies_len);
1860 #endif /* CONFIG_INTERWORKING */
1862 if (data->assoc_info.beacon_ies)
1863 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1864 data->assoc_info.beacon_ies,
1865 data->assoc_info.beacon_ies_len);
1866 if (data->assoc_info.freq)
1867 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1868 data->assoc_info.freq);
1870 p = data->assoc_info.req_ies;
1871 l = data->assoc_info.req_ies_len;
1873 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1874 while (p && l >= 2) {
1877 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1881 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1882 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1883 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1884 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1887 wpa_find_assoc_pmkid(wpa_s);
1893 if (!found && data->assoc_info.req_ies)
1894 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1896 #ifdef CONFIG_IEEE80211R
1898 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1899 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1900 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1901 data->assoc_info.resp_ies,
1902 data->assoc_info.resp_ies_len,
1904 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1905 "Reassociation Response failed");
1906 wpa_supplicant_deauthenticate(
1907 wpa_s, WLAN_REASON_INVALID_IE);
1912 p = data->assoc_info.resp_ies;
1913 l = data->assoc_info.resp_ies_len;
1915 #ifdef CONFIG_WPS_STRICT
1916 if (p && wpa_s->current_ssid &&
1917 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1919 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1921 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1922 "include WPS IE in (Re)Association Response");
1926 if (wps_validate_assoc_resp(wps) < 0) {
1928 wpa_supplicant_deauthenticate(
1929 wpa_s, WLAN_REASON_INVALID_IE);
1934 #endif /* CONFIG_WPS_STRICT */
1936 /* Go through the IEs and make a copy of the MDIE, if present. */
1937 while (p && l >= 2) {
1940 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1944 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1945 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1946 wpa_s->sme.ft_used = 1;
1947 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1948 MOBILITY_DOMAIN_ID_LEN);
1954 #endif /* CONFIG_SME */
1956 /* Process FT when SME is in the driver */
1957 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1958 wpa_ft_is_completed(wpa_s->wpa)) {
1959 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1960 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1961 data->assoc_info.resp_ies,
1962 data->assoc_info.resp_ies_len,
1964 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1965 "Reassociation Response failed");
1966 wpa_supplicant_deauthenticate(
1967 wpa_s, WLAN_REASON_INVALID_IE);
1970 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1973 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1974 data->assoc_info.resp_ies_len);
1975 #endif /* CONFIG_IEEE80211R */
1977 /* WPA/RSN IE from Beacon/ProbeResp */
1978 p = data->assoc_info.beacon_ies;
1979 l = data->assoc_info.beacon_ies_len;
1981 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1983 wpa_found = rsn_found = 0;
1984 while (p && l >= 2) {
1987 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1992 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1993 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1995 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1999 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2001 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2008 if (!wpa_found && data->assoc_info.beacon_ies)
2009 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2010 if (!rsn_found && data->assoc_info.beacon_ies)
2011 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2012 if (wpa_found || rsn_found)
2013 wpa_s->ap_ies_from_associnfo = 1;
2016 wpabuf_free(wpa_s->received_mb_ies);
2017 wpa_s->received_mb_ies = NULL;
2019 struct mb_ies_info mb_ies;
2021 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2022 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2023 data->assoc_info.resp_ies_len))
2024 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2026 #endif /* CONFIG_FST */
2028 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2029 wpa_s->assoc_freq != data->assoc_info.freq) {
2030 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2032 wpa_s->assoc_freq, data->assoc_info.freq);
2033 wpa_supplicant_update_scan_results(wpa_s);
2036 wpa_s->assoc_freq = data->assoc_info.freq;
2042 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2044 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2046 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2049 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2052 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2053 WPA_IE_VENDOR_TYPE);
2054 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2056 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2057 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2058 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2059 bss_rsn ? 2 + bss_rsn[1] : 0))
2066 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2067 union wpa_event_data *data)
2074 if (wpa_s->ap_iface) {
2077 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2078 data->assoc_info.addr,
2079 data->assoc_info.req_ies,
2080 data->assoc_info.req_ies_len,
2081 data->assoc_info.reassoc);
2084 #endif /* CONFIG_AP */
2086 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2088 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2089 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2092 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2093 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2094 wpa_supplicant_deauthenticate(
2095 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2099 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2100 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2101 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2102 MACSTR, MAC2STR(bssid));
2104 random_add_randomness(bssid, ETH_ALEN);
2105 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2106 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2107 wpas_notify_bssid_changed(wpa_s);
2109 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2110 wpa_clear_keys(wpa_s, bssid);
2112 if (wpa_supplicant_select_config(wpa_s) < 0) {
2113 wpa_supplicant_deauthenticate(
2114 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2119 if (wpa_s->conf->ap_scan == 1 &&
2120 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2121 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2122 wpa_msg(wpa_s, MSG_WARNING,
2123 "WPA/RSN IEs not updated");
2127 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2128 wpa_s->sme.prev_bssid_set = 1;
2129 wpa_s->sme.last_unprot_disconnect.sec = 0;
2130 #endif /* CONFIG_SME */
2132 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2133 if (wpa_s->current_ssid) {
2134 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2135 * initialized before association, but for other modes,
2136 * initialize PC/SC here, if the current configuration needs
2137 * smartcard or SIM/USIM. */
2138 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2140 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2142 l2_packet_notify_auth_start(wpa_s->l2);
2145 * Set portEnabled first to FALSE in order to get EAP state machine out
2146 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2147 * state machine may transit to AUTHENTICATING state based on obsolete
2148 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2149 * AUTHENTICATED without ever giving chance to EAP state machine to
2152 if (!ft_completed) {
2153 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2154 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2156 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2157 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2158 /* 802.1X::portControl = Auto */
2159 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2160 wpa_s->eapol_received = 0;
2161 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2162 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2163 (wpa_s->current_ssid &&
2164 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2165 if (wpa_s->current_ssid &&
2166 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2168 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2170 * Set the key after having received joined-IBSS event
2173 wpa_supplicant_set_wpa_none_key(wpa_s,
2174 wpa_s->current_ssid);
2176 wpa_supplicant_cancel_auth_timeout(wpa_s);
2177 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2178 } else if (!ft_completed) {
2179 /* Timeout for receiving the first EAPOL packet */
2180 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2182 wpa_supplicant_cancel_scan(wpa_s);
2184 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2185 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2187 * We are done; the driver will take care of RSN 4-way
2190 wpa_supplicant_cancel_auth_timeout(wpa_s);
2191 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2192 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2193 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2194 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2195 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2197 * The driver will take care of RSN 4-way handshake, so we need
2198 * to allow EAPOL supplicant to complete its work without
2199 * waiting for WPA supplicant.
2201 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2202 } else if (ft_completed) {
2204 * FT protocol completed - make sure EAPOL state machine ends
2205 * up in authenticated.
2207 wpa_supplicant_cancel_auth_timeout(wpa_s);
2208 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2209 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2210 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2213 wpa_s->last_eapol_matches_bssid = 0;
2215 if (wpa_s->pending_eapol_rx) {
2216 struct os_reltime now, age;
2217 os_get_reltime(&now);
2218 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2219 if (age.sec == 0 && age.usec < 100000 &&
2220 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2222 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2223 "frame that was received just before "
2224 "association notification");
2225 wpa_supplicant_rx_eapol(
2226 wpa_s, wpa_s->pending_eapol_rx_src,
2227 wpabuf_head(wpa_s->pending_eapol_rx),
2228 wpabuf_len(wpa_s->pending_eapol_rx));
2230 wpabuf_free(wpa_s->pending_eapol_rx);
2231 wpa_s->pending_eapol_rx = NULL;
2234 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2235 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2236 wpa_s->current_ssid &&
2237 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2238 /* Set static WEP keys again */
2239 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2242 #ifdef CONFIG_IBSS_RSN
2243 if (wpa_s->current_ssid &&
2244 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2245 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2246 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2247 wpa_s->ibss_rsn == NULL) {
2248 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2249 if (!wpa_s->ibss_rsn) {
2250 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2251 wpa_supplicant_deauthenticate(
2252 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2256 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2258 #endif /* CONFIG_IBSS_RSN */
2260 wpas_wps_notify_assoc(wpa_s, bssid);
2263 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2264 data->assoc_info.resp_ies_len,
2265 &data->assoc_info.wmm_params);
2267 if (wpa_s->reassoc_same_bss)
2268 wmm_ac_restore_tspecs(wpa_s);
2273 static int disconnect_reason_recoverable(u16 reason_code)
2275 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2276 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2277 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2281 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2283 int locally_generated)
2287 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2289 * At least Host AP driver and a Prism3 card seemed to be
2290 * generating streams of disconnected events when configuring
2291 * IBSS for WPA-None. Ignore them for now.
2296 bssid = wpa_s->bssid;
2297 if (is_zero_ether_addr(bssid))
2298 bssid = wpa_s->pending_bssid;
2300 if (!is_zero_ether_addr(bssid) ||
2301 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2302 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2304 MAC2STR(bssid), reason_code,
2305 locally_generated ? " locally_generated=1" : "");
2310 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2311 int locally_generated)
2313 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2314 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2315 return 0; /* Not in 4-way handshake with PSK */
2318 * It looks like connection was lost while trying to go through PSK
2319 * 4-way handshake. Filter out known disconnection cases that are caused
2320 * by something else than PSK mismatch to avoid confusing reports.
2323 if (locally_generated) {
2324 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2332 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2334 int locally_generated)
2338 u8 prev_pending_bssid[ETH_ALEN];
2339 struct wpa_bss *fast_reconnect = NULL;
2340 struct wpa_ssid *fast_reconnect_ssid = NULL;
2341 struct wpa_ssid *last_ssid;
2343 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2344 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2346 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2348 * At least Host AP driver and a Prism3 card seemed to be
2349 * generating streams of disconnected events when configuring
2350 * IBSS for WPA-None. Ignore them for now.
2352 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2353 "IBSS/WPA-None mode");
2357 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2358 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2359 "pre-shared key may be incorrect");
2360 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2361 return; /* P2P group removed */
2362 wpas_auth_failed(wpa_s, "WRONG_KEY");
2364 if (!wpa_s->disconnected &&
2365 (!wpa_s->auto_reconnect_disabled ||
2366 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2367 wpas_wps_searching(wpa_s))) {
2368 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2369 "reconnect (wps=%d/%d wpa_state=%d)",
2370 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2371 wpas_wps_searching(wpa_s),
2373 if (wpa_s->wpa_state == WPA_COMPLETED &&
2374 wpa_s->current_ssid &&
2375 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2376 !locally_generated &&
2377 disconnect_reason_recoverable(reason_code)) {
2379 * It looks like the AP has dropped association with
2380 * us, but could allow us to get back in. Try to
2381 * reconnect to the same BSS without full scan to save
2382 * time for some common cases.
2384 fast_reconnect = wpa_s->current_bss;
2385 fast_reconnect_ssid = wpa_s->current_ssid;
2386 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2387 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2389 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2392 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2393 "try to re-connect");
2394 wpa_s->reassociate = 0;
2395 wpa_s->disconnected = 1;
2397 wpa_supplicant_cancel_sched_scan(wpa_s);
2399 bssid = wpa_s->bssid;
2400 if (is_zero_ether_addr(bssid))
2401 bssid = wpa_s->pending_bssid;
2402 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2403 wpas_connection_failed(wpa_s, bssid);
2404 wpa_sm_notify_disassoc(wpa_s->wpa);
2405 if (locally_generated)
2406 wpa_s->disconnect_reason = -reason_code;
2408 wpa_s->disconnect_reason = reason_code;
2409 wpas_notify_disconnect_reason(wpa_s);
2410 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2411 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2412 wpa_clear_keys(wpa_s, wpa_s->bssid);
2414 last_ssid = wpa_s->current_ssid;
2415 wpa_supplicant_mark_disassoc(wpa_s);
2417 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2418 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2419 wpa_s->current_ssid = last_ssid;
2422 if (fast_reconnect &&
2423 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2424 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2425 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2426 fast_reconnect->ssid_len) &&
2427 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2428 #ifndef CONFIG_NO_SCAN_PROCESSING
2429 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2430 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2431 fast_reconnect_ssid) < 0) {
2432 /* Recover through full scan */
2433 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2435 #endif /* CONFIG_NO_SCAN_PROCESSING */
2436 } else if (fast_reconnect) {
2438 * Could not reconnect to the same BSS due to network being
2439 * disabled. Use a new scan to match the alternative behavior
2440 * above, i.e., to continue automatic reconnection attempt in a
2441 * way that enforces disabled network rules.
2443 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2448 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2449 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2451 struct wpa_supplicant *wpa_s = eloop_ctx;
2453 if (!wpa_s->pending_mic_error_report)
2456 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2457 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2458 wpa_s->pending_mic_error_report = 0;
2460 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2464 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2465 union wpa_event_data *data)
2468 struct os_reltime t;
2470 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2471 pairwise = (data && data->michael_mic_failure.unicast);
2473 if ((wpa_s->last_michael_mic_error.sec &&
2474 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2475 wpa_s->pending_mic_error_report) {
2476 if (wpa_s->pending_mic_error_report) {
2478 * Send the pending MIC error report immediately since
2479 * we are going to start countermeasures and AP better
2482 wpa_sm_key_request(wpa_s->wpa, 1,
2483 wpa_s->pending_mic_error_pairwise);
2486 /* Send the new MIC error report immediately since we are going
2487 * to start countermeasures and AP better do the same.
2489 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2491 /* initialize countermeasures */
2492 wpa_s->countermeasures = 1;
2494 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2496 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2499 * Need to wait for completion of request frame. We do not get
2500 * any callback for the message completion, so just wait a
2501 * short while and hope for the best. */
2504 wpa_drv_set_countermeasures(wpa_s, 1);
2505 wpa_supplicant_deauthenticate(wpa_s,
2506 WLAN_REASON_MICHAEL_MIC_FAILURE);
2507 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2509 eloop_register_timeout(60, 0,
2510 wpa_supplicant_stop_countermeasures,
2512 /* TODO: mark the AP rejected for 60 second. STA is
2513 * allowed to associate with another AP.. */
2515 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2516 if (wpa_s->mic_errors_seen) {
2518 * Reduce the effectiveness of Michael MIC error
2519 * reports as a means for attacking against TKIP if
2520 * more than one MIC failure is noticed with the same
2521 * PTK. We delay the transmission of the reports by a
2522 * random time between 0 and 60 seconds in order to
2523 * force the attacker wait 60 seconds before getting
2524 * the information on whether a frame resulted in a MIC
2530 if (os_get_random(rval, sizeof(rval)) < 0)
2531 sec = os_random() % 60;
2533 sec = WPA_GET_BE32(rval) % 60;
2534 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2535 "report %d seconds", sec);
2536 wpa_s->pending_mic_error_report = 1;
2537 wpa_s->pending_mic_error_pairwise = pairwise;
2538 eloop_cancel_timeout(
2539 wpa_supplicant_delayed_mic_error_report,
2541 eloop_register_timeout(
2542 sec, os_random() % 1000000,
2543 wpa_supplicant_delayed_mic_error_report,
2546 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2548 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2549 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2550 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2552 wpa_s->last_michael_mic_error = t;
2553 wpa_s->mic_errors_seen++;
2557 #ifdef CONFIG_TERMINATE_ONLASTIF
2558 static int any_interfaces(struct wpa_supplicant *head)
2560 struct wpa_supplicant *wpa_s;
2562 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2563 if (!wpa_s->interface_removed)
2567 #endif /* CONFIG_TERMINATE_ONLASTIF */
2571 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2572 union wpa_event_data *data)
2574 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2577 switch (data->interface_status.ievent) {
2578 case EVENT_INTERFACE_ADDED:
2579 if (!wpa_s->interface_removed)
2581 wpa_s->interface_removed = 0;
2582 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2583 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2584 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2585 "driver after interface was added");
2589 if (!wpa_s->global->p2p &&
2590 !wpa_s->global->p2p_disabled &&
2591 !wpa_s->conf->p2p_disabled &&
2593 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2594 wpas_p2p_add_p2pdev_interface(
2595 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2596 wpa_printf(MSG_INFO,
2597 "P2P: Failed to enable P2P Device interface");
2598 /* Try to continue without. P2P will be disabled. */
2600 #endif /* CONFIG_P2P */
2603 case EVENT_INTERFACE_REMOVED:
2604 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2605 wpa_s->interface_removed = 1;
2606 wpa_supplicant_mark_disassoc(wpa_s);
2607 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2608 l2_packet_deinit(wpa_s->l2);
2612 if (wpa_s->global->p2p &&
2613 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2615 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2616 wpa_dbg(wpa_s, MSG_DEBUG,
2617 "Removing P2P Device interface");
2618 wpa_supplicant_remove_iface(
2619 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2621 wpa_s->global->p2p_init_wpa_s = NULL;
2623 #endif /* CONFIG_P2P */
2625 #ifdef CONFIG_TERMINATE_ONLASTIF
2626 /* check if last interface */
2627 if (!any_interfaces(wpa_s->global->ifaces))
2629 #endif /* CONFIG_TERMINATE_ONLASTIF */
2635 #ifdef CONFIG_PEERKEY
2637 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2638 union wpa_event_data *data)
2642 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2644 #endif /* CONFIG_PEERKEY */
2648 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2649 union wpa_event_data *data)
2653 switch (data->tdls.oper) {
2654 case TDLS_REQUEST_SETUP:
2655 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2656 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2657 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2659 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2661 case TDLS_REQUEST_TEARDOWN:
2662 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2663 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2664 data->tdls.reason_code);
2666 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2669 case TDLS_REQUEST_DISCOVER:
2670 wpa_tdls_send_discovery_request(wpa_s->wpa,
2675 #endif /* CONFIG_TDLS */
2679 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2680 union wpa_event_data *data)
2684 switch (data->wnm.oper) {
2685 case WNM_OPER_SLEEP:
2686 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2687 "(action=%d, intval=%d)",
2688 data->wnm.sleep_action, data->wnm.sleep_intval);
2689 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2690 data->wnm.sleep_intval, NULL);
2694 #endif /* CONFIG_WNM */
2697 #ifdef CONFIG_IEEE80211R
2699 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2700 union wpa_event_data *data)
2705 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2706 data->ft_ies.ies_len,
2707 data->ft_ies.ft_action,
2708 data->ft_ies.target_ap,
2709 data->ft_ies.ric_ies,
2710 data->ft_ies.ric_ies_len) < 0) {
2711 /* TODO: prevent MLME/driver from trying to associate? */
2714 #endif /* CONFIG_IEEE80211R */
2717 #ifdef CONFIG_IBSS_RSN
2718 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2719 union wpa_event_data *data)
2721 struct wpa_ssid *ssid;
2722 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2726 ssid = wpa_s->current_ssid;
2729 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2732 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2736 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2737 union wpa_event_data *data)
2739 struct wpa_ssid *ssid = wpa_s->current_ssid;
2744 /* check if the ssid is correctly configured as IBSS/RSN */
2745 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2748 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2749 data->rx_mgmt.frame_len);
2751 #endif /* CONFIG_IBSS_RSN */
2754 #ifdef CONFIG_IEEE80211R
2755 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2758 const u8 *sta_addr, *target_ap_addr;
2761 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2762 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2763 return; /* only SME case supported for now */
2764 if (len < 1 + 2 * ETH_ALEN + 2)
2767 return; /* Only FT Action Response is supported for now */
2768 sta_addr = data + 1;
2769 target_ap_addr = data + 1 + ETH_ALEN;
2770 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2771 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2772 MACSTR " TargetAP " MACSTR " status %u",
2773 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2775 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2776 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2777 " in FT Action Response", MAC2STR(sta_addr));
2782 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2783 "failure (status code %d)", status);
2784 /* TODO: report error to FT code(?) */
2788 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2789 len - (1 + 2 * ETH_ALEN + 2), 1,
2790 target_ap_addr, NULL, 0) < 0)
2795 struct wpa_bss *bss;
2796 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2798 wpa_s->sme.freq = bss->freq;
2799 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2800 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2803 #endif /* CONFIG_SME */
2805 #endif /* CONFIG_IEEE80211R */
2808 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2809 struct unprot_deauth *e)
2811 #ifdef CONFIG_IEEE80211W
2812 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2813 "dropped: " MACSTR " -> " MACSTR
2814 " (reason code %u)",
2815 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2816 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2817 #endif /* CONFIG_IEEE80211W */
2821 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2822 struct unprot_disassoc *e)
2824 #ifdef CONFIG_IEEE80211W
2825 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2826 "dropped: " MACSTR " -> " MACSTR
2827 " (reason code %u)",
2828 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2829 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2830 #endif /* CONFIG_IEEE80211W */
2834 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2835 u16 reason_code, int locally_generated,
2836 const u8 *ie, size_t ie_len, int deauth)
2839 if (wpa_s->ap_iface && addr) {
2840 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2844 if (wpa_s->ap_iface) {
2845 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2848 #endif /* CONFIG_AP */
2850 if (!locally_generated)
2851 wpa_s->own_disconnect_req = 0;
2853 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2855 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2856 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2857 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2858 eapol_sm_failed(wpa_s->eapol))) &&
2859 !wpa_s->eap_expected_failure))
2860 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2863 if (deauth && reason_code > 0) {
2864 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2865 locally_generated) > 0) {
2867 * The interface was removed, so cannot continue
2868 * processing any additional operations after this.
2873 #endif /* CONFIG_P2P */
2875 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2880 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2881 struct disassoc_info *info)
2883 u16 reason_code = 0;
2884 int locally_generated = 0;
2885 const u8 *addr = NULL;
2886 const u8 *ie = NULL;
2889 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2894 ie_len = info->ie_len;
2895 reason_code = info->reason_code;
2896 locally_generated = info->locally_generated;
2897 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2898 locally_generated ? " (locally generated)" : "");
2900 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2902 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2907 if (wpa_s->ap_iface && info && info->addr) {
2908 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2912 if (wpa_s->ap_iface) {
2913 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2916 #endif /* CONFIG_AP */
2920 wpas_p2p_disassoc_notif(
2921 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2924 #endif /* CONFIG_P2P */
2926 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2927 sme_event_disassoc(wpa_s, info);
2929 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2934 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2935 struct deauth_info *info)
2937 u16 reason_code = 0;
2938 int locally_generated = 0;
2939 const u8 *addr = NULL;
2940 const u8 *ie = NULL;
2943 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2948 ie_len = info->ie_len;
2949 reason_code = info->reason_code;
2950 locally_generated = info->locally_generated;
2951 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2953 locally_generated ? " (locally generated)" : "");
2955 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2958 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2962 wpa_reset_ft_completed(wpa_s->wpa);
2964 wpas_event_disconnect(wpa_s, addr, reason_code,
2965 locally_generated, ie, ie_len, 1);
2969 static const char * reg_init_str(enum reg_change_initiator init)
2972 case REGDOM_SET_BY_CORE:
2974 case REGDOM_SET_BY_USER:
2976 case REGDOM_SET_BY_DRIVER:
2978 case REGDOM_SET_BY_COUNTRY_IE:
2979 return "COUNTRY_IE";
2980 case REGDOM_BEACON_HINT:
2981 return "BEACON_HINT";
2987 static const char * reg_type_str(enum reg_type type)
2990 case REGDOM_TYPE_UNKNOWN:
2992 case REGDOM_TYPE_COUNTRY:
2994 case REGDOM_TYPE_WORLD:
2996 case REGDOM_TYPE_CUSTOM_WORLD:
2997 return "CUSTOM_WORLD";
2998 case REGDOM_TYPE_INTERSECTION:
2999 return "INTERSECTION";
3005 static void wpa_supplicant_update_channel_list(
3006 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3008 struct wpa_supplicant *ifs;
3010 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3011 reg_init_str(info->initiator), reg_type_str(info->type),
3012 info->alpha2[0] ? " alpha2=" : "",
3013 info->alpha2[0] ? info->alpha2 : "");
3015 if (wpa_s->drv_priv == NULL)
3016 return; /* Ignore event during drv initialization */
3018 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3020 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3022 free_hw_features(ifs);
3023 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3024 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3027 /* Restart sched_scan with updated channel list */
3028 if (wpa_s->sched_scanning) {
3029 wpa_dbg(wpa_s, MSG_DEBUG,
3030 "Channel list changed restart sched scan.");
3031 wpa_supplicant_cancel_sched_scan(wpa_s);
3032 wpa_supplicant_req_scan(wpa_s, 0, 0);
3035 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3039 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3040 const u8 *frame, size_t len, int freq,
3043 const struct ieee80211_mgmt *mgmt;
3048 if (len < IEEE80211_HDRLEN + 2)
3051 mgmt = (const struct ieee80211_mgmt *) frame;
3052 payload = frame + IEEE80211_HDRLEN;
3053 category = *payload++;
3054 plen = len - IEEE80211_HDRLEN - 1;
3056 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3057 " Category=%u DataLen=%d freq=%d MHz",
3058 MAC2STR(mgmt->sa), category, (int) plen, freq);
3060 if (category == WLAN_ACTION_WMM) {
3061 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3065 #ifdef CONFIG_IEEE80211R
3066 if (category == WLAN_ACTION_FT) {
3067 ft_rx_action(wpa_s, payload, plen);
3070 #endif /* CONFIG_IEEE80211R */
3072 #ifdef CONFIG_IEEE80211W
3074 if (category == WLAN_ACTION_SA_QUERY) {
3075 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3078 #endif /* CONFIG_SME */
3079 #endif /* CONFIG_IEEE80211W */
3082 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3083 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3086 #endif /* CONFIG_WNM */
3089 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3090 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3091 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3092 mgmt->u.action.category,
3093 payload, plen, freq) == 0)
3095 #endif /* CONFIG_GAS */
3098 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3099 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3100 wpa_dbg(wpa_s, MSG_DEBUG,
3101 "TDLS: Received Discovery Response from " MACSTR,
3105 #endif /* CONFIG_TDLS */
3107 #ifdef CONFIG_INTERWORKING
3108 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3109 payload[0] == QOS_QOS_MAP_CONFIG) {
3110 const u8 *pos = payload + 1;
3111 size_t qlen = plen - 1;
3112 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3113 MACSTR, MAC2STR(mgmt->sa));
3114 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3115 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3116 pos[1] <= qlen - 2 && pos[1] >= 16)
3117 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3120 #endif /* CONFIG_INTERWORKING */
3122 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3123 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3124 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3128 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3129 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3130 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3131 payload + 1, plen - 1,
3137 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3138 fst_rx_action(wpa_s->fst, mgmt, len);
3141 #endif /* CONFIG_FST */
3143 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3144 category, payload, plen, freq);
3146 mesh_mpm_action_rx(wpa_s, mgmt, len);
3150 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3151 union wpa_event_data *event)
3153 struct wpa_freq_range_list *list;
3156 list = &event->freq_range;
3159 str = freq_range_list_str(list);
3160 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3164 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3165 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3168 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3171 * The update channel flow will also take care of moving a GO
3172 * from the unsafe frequency if needed.
3174 wpas_p2p_update_channel_list(wpa_s,
3175 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3177 #endif /* CONFIG_P2P */
3183 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3184 union wpa_event_data *data)
3186 wpa_dbg(wpa_s, MSG_DEBUG,
3187 "Connection authorized by device, previous state %d",
3189 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3190 wpa_supplicant_cancel_auth_timeout(wpa_s);
3191 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3192 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3193 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3195 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3196 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3197 data->assoc_info.ptk_kck_len,
3198 data->assoc_info.ptk_kek,
3199 data->assoc_info.ptk_kek_len);
3203 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3204 union wpa_event_data *data)
3206 struct wpa_supplicant *wpa_s = ctx;
3209 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3210 event != EVENT_INTERFACE_ENABLED &&
3211 event != EVENT_INTERFACE_STATUS &&
3212 event != EVENT_SCHED_SCAN_STOPPED) {
3213 wpa_dbg(wpa_s, MSG_DEBUG,
3214 "Ignore event %s (%d) while interface is disabled",
3215 event_to_string(event), event);
3219 #ifndef CONFIG_NO_STDOUT_DEBUG
3221 int level = MSG_DEBUG;
3223 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3224 const struct ieee80211_hdr *hdr;
3226 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3227 fc = le_to_host16(hdr->frame_control);
3228 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3229 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3230 level = MSG_EXCESSIVE;
3233 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3234 event_to_string(event), event);
3236 #endif /* CONFIG_NO_STDOUT_DEBUG */
3240 sme_event_auth(wpa_s, data);
3243 wpa_supplicant_event_assoc(wpa_s, data);
3244 if (data && data->assoc_info.authorized)
3245 wpa_supplicant_event_assoc_auth(wpa_s, data);
3247 case EVENT_DISASSOC:
3248 wpas_event_disassoc(wpa_s,
3249 data ? &data->disassoc_info : NULL);
3252 wpas_event_deauth(wpa_s,
3253 data ? &data->deauth_info : NULL);
3255 case EVENT_MICHAEL_MIC_FAILURE:
3256 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3258 #ifndef CONFIG_NO_SCAN_PROCESSING
3259 case EVENT_SCAN_STARTED:
3260 os_get_reltime(&wpa_s->scan_start_time);
3261 if (wpa_s->own_scan_requested) {
3262 struct os_reltime diff;
3264 os_reltime_sub(&wpa_s->scan_start_time,
3265 &wpa_s->scan_trigger_time, &diff);
3266 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3267 diff.sec, diff.usec);
3268 wpa_s->own_scan_requested = 0;
3269 wpa_s->own_scan_running = 1;
3270 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3271 wpa_s->manual_scan_use_id) {
3272 wpa_msg_ctrl(wpa_s, MSG_INFO,
3273 WPA_EVENT_SCAN_STARTED "id=%u",
3274 wpa_s->manual_scan_id);
3276 wpa_msg_ctrl(wpa_s, MSG_INFO,
3277 WPA_EVENT_SCAN_STARTED);
3280 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3281 wpa_s->radio->external_scan_running = 1;
3282 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3285 case EVENT_SCAN_RESULTS:
3286 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3287 struct os_reltime now, diff;
3288 os_get_reltime(&now);
3289 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3290 wpa_s->scan_start_time.sec = 0;
3291 wpa_s->scan_start_time.usec = 0;
3292 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3293 diff.sec, diff.usec);
3295 if (wpa_supplicant_event_scan_results(wpa_s, data))
3296 break; /* interface may have been removed */
3297 wpa_s->own_scan_running = 0;
3298 wpa_s->radio->external_scan_running = 0;
3299 radio_work_check_next(wpa_s);
3301 #endif /* CONFIG_NO_SCAN_PROCESSING */
3302 case EVENT_ASSOCINFO:
3303 wpa_supplicant_event_associnfo(wpa_s, data);
3305 case EVENT_INTERFACE_STATUS:
3306 wpa_supplicant_event_interface_status(wpa_s, data);
3308 case EVENT_PMKID_CANDIDATE:
3309 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3311 #ifdef CONFIG_PEERKEY
3312 case EVENT_STKSTART:
3313 wpa_supplicant_event_stkstart(wpa_s, data);
3315 #endif /* CONFIG_PEERKEY */
3318 wpa_supplicant_event_tdls(wpa_s, data);
3320 #endif /* CONFIG_TDLS */
3323 wpa_supplicant_event_wnm(wpa_s, data);
3325 #endif /* CONFIG_WNM */
3326 #ifdef CONFIG_IEEE80211R
3327 case EVENT_FT_RESPONSE:
3328 wpa_supplicant_event_ft_response(wpa_s, data);
3330 #endif /* CONFIG_IEEE80211R */
3331 #ifdef CONFIG_IBSS_RSN
3332 case EVENT_IBSS_RSN_START:
3333 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3335 #endif /* CONFIG_IBSS_RSN */
3336 case EVENT_ASSOC_REJECT:
3337 if (data->assoc_reject.bssid)
3338 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3339 "bssid=" MACSTR " status_code=%u",
3340 MAC2STR(data->assoc_reject.bssid),
3341 data->assoc_reject.status_code);
3343 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3345 data->assoc_reject.status_code);
3346 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3347 sme_event_assoc_reject(wpa_s, data);
3349 const u8 *bssid = data->assoc_reject.bssid;
3350 if (bssid == NULL || is_zero_ether_addr(bssid))
3351 bssid = wpa_s->pending_bssid;
3352 wpas_connection_failed(wpa_s, bssid);
3353 wpa_supplicant_mark_disassoc(wpa_s);
3356 case EVENT_AUTH_TIMED_OUT:
3357 /* It is possible to get this event from earlier connection */
3358 if (wpa_s->current_ssid &&
3359 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3360 wpa_dbg(wpa_s, MSG_DEBUG,
3361 "Ignore AUTH_TIMED_OUT in mesh configuration");
3364 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3365 sme_event_auth_timed_out(wpa_s, data);
3367 case EVENT_ASSOC_TIMED_OUT:
3368 /* It is possible to get this event from earlier connection */
3369 if (wpa_s->current_ssid &&
3370 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3371 wpa_dbg(wpa_s, MSG_DEBUG,
3372 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3375 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3376 sme_event_assoc_timed_out(wpa_s, data);
3378 case EVENT_TX_STATUS:
3379 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3380 " type=%d stype=%d",
3381 MAC2STR(data->tx_status.dst),
3382 data->tx_status.type, data->tx_status.stype);
3384 if (wpa_s->ap_iface == NULL) {
3385 #ifdef CONFIG_OFFCHANNEL
3386 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3387 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3388 offchannel_send_action_tx_status(
3389 wpa_s, data->tx_status.dst,
3390 data->tx_status.data,
3391 data->tx_status.data_len,
3392 data->tx_status.ack ?
3393 OFFCHANNEL_SEND_ACTION_SUCCESS :
3394 OFFCHANNEL_SEND_ACTION_NO_ACK);
3395 #endif /* CONFIG_OFFCHANNEL */
3398 #endif /* CONFIG_AP */
3399 #ifdef CONFIG_OFFCHANNEL
3400 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3401 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3403 * Catch TX status events for Action frames we sent via group
3404 * interface in GO mode.
3406 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3407 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3408 os_memcmp(wpa_s->parent->pending_action_dst,
3409 data->tx_status.dst, ETH_ALEN) == 0) {
3410 offchannel_send_action_tx_status(
3411 wpa_s->parent, data->tx_status.dst,
3412 data->tx_status.data,
3413 data->tx_status.data_len,
3414 data->tx_status.ack ?
3415 OFFCHANNEL_SEND_ACTION_SUCCESS :
3416 OFFCHANNEL_SEND_ACTION_NO_ACK);
3419 #endif /* CONFIG_OFFCHANNEL */
3421 switch (data->tx_status.type) {
3422 case WLAN_FC_TYPE_MGMT:
3423 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3424 data->tx_status.data_len,
3425 data->tx_status.stype,
3426 data->tx_status.ack);
3428 case WLAN_FC_TYPE_DATA:
3429 ap_tx_status(wpa_s, data->tx_status.dst,
3430 data->tx_status.data,
3431 data->tx_status.data_len,
3432 data->tx_status.ack);
3435 #endif /* CONFIG_AP */
3438 case EVENT_EAPOL_TX_STATUS:
3439 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3440 data->eapol_tx_status.data,
3441 data->eapol_tx_status.data_len,
3442 data->eapol_tx_status.ack);
3444 case EVENT_DRIVER_CLIENT_POLL_OK:
3445 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3447 case EVENT_RX_FROM_UNKNOWN:
3448 if (wpa_s->ap_iface == NULL)
3450 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3451 data->rx_from_unknown.wds);
3453 case EVENT_CH_SWITCH:
3456 if (!wpa_s->ap_iface) {
3457 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3458 "event in non-AP mode");
3462 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3463 data->ch_switch.ht_enabled,
3464 data->ch_switch.ch_offset,
3465 data->ch_switch.ch_width,
3466 data->ch_switch.cf1,
3467 data->ch_switch.cf2);
3470 case EVENT_DFS_RADAR_DETECTED:
3472 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3474 case EVENT_DFS_CAC_STARTED:
3476 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3478 case EVENT_DFS_CAC_FINISHED:
3480 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3482 case EVENT_DFS_CAC_ABORTED:
3484 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3486 case EVENT_DFS_NOP_FINISHED:
3488 wpas_event_dfs_cac_nop_finished(wpa_s,
3491 #endif /* NEED_AP_MLME */
3492 #endif /* CONFIG_AP */
3493 case EVENT_RX_MGMT: {
3495 const struct ieee80211_mgmt *mgmt;
3497 #ifdef CONFIG_TESTING_OPTIONS
3498 if (wpa_s->ext_mgmt_frame_handling) {
3499 struct rx_mgmt *rx = &data->rx_mgmt;
3500 size_t hex_len = 2 * rx->frame_len + 1;
3501 char *hex = os_malloc(hex_len);
3503 wpa_snprintf_hex(hex, hex_len,
3504 rx->frame, rx->frame_len);
3505 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3506 rx->freq, rx->datarate, rx->ssi_signal,
3512 #endif /* CONFIG_TESTING_OPTIONS */
3514 mgmt = (const struct ieee80211_mgmt *)
3515 data->rx_mgmt.frame;
3516 fc = le_to_host16(mgmt->frame_control);
3517 stype = WLAN_FC_GET_STYPE(fc);
3520 if (wpa_s->ap_iface == NULL) {
3521 #endif /* CONFIG_AP */
3523 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3524 data->rx_mgmt.frame_len > 24) {
3525 const u8 *src = mgmt->sa;
3526 const u8 *ie = mgmt->u.probe_req.variable;
3527 size_t ie_len = data->rx_mgmt.frame_len -
3528 (mgmt->u.probe_req.variable -
3529 data->rx_mgmt.frame);
3530 wpas_p2p_probe_req_rx(
3531 wpa_s, src, mgmt->da,
3532 mgmt->bssid, ie, ie_len,
3534 data->rx_mgmt.ssi_signal);
3537 #endif /* CONFIG_P2P */
3538 #ifdef CONFIG_IBSS_RSN
3539 if (wpa_s->current_ssid &&
3540 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3541 stype == WLAN_FC_STYPE_AUTH &&
3542 data->rx_mgmt.frame_len >= 30) {
3543 wpa_supplicant_event_ibss_auth(wpa_s, data);
3546 #endif /* CONFIG_IBSS_RSN */
3548 if (stype == WLAN_FC_STYPE_ACTION) {
3549 wpas_event_rx_mgmt_action(
3550 wpa_s, data->rx_mgmt.frame,
3551 data->rx_mgmt.frame_len,
3553 data->rx_mgmt.ssi_signal);
3558 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3562 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3563 "management frame in non-AP mode");
3568 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3569 data->rx_mgmt.frame_len > 24) {
3570 const u8 *ie = mgmt->u.probe_req.variable;
3571 size_t ie_len = data->rx_mgmt.frame_len -
3572 (mgmt->u.probe_req.variable -
3573 data->rx_mgmt.frame);
3575 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3576 mgmt->bssid, ie, ie_len,
3577 data->rx_mgmt.ssi_signal);
3580 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3581 #endif /* CONFIG_AP */
3584 case EVENT_RX_PROBE_REQ:
3585 if (data->rx_probe_req.sa == NULL ||
3586 data->rx_probe_req.ie == NULL)
3589 if (wpa_s->ap_iface) {
3590 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3591 data->rx_probe_req.sa,
3592 data->rx_probe_req.da,
3593 data->rx_probe_req.bssid,
3594 data->rx_probe_req.ie,
3595 data->rx_probe_req.ie_len,
3596 data->rx_probe_req.ssi_signal);
3599 #endif /* CONFIG_AP */
3600 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3601 data->rx_probe_req.da,
3602 data->rx_probe_req.bssid,
3603 data->rx_probe_req.ie,
3604 data->rx_probe_req.ie_len,
3606 data->rx_probe_req.ssi_signal);
3608 case EVENT_REMAIN_ON_CHANNEL:
3609 #ifdef CONFIG_OFFCHANNEL
3610 offchannel_remain_on_channel_cb(
3611 wpa_s, data->remain_on_channel.freq,
3612 data->remain_on_channel.duration);
3613 #endif /* CONFIG_OFFCHANNEL */
3614 wpas_p2p_remain_on_channel_cb(
3615 wpa_s, data->remain_on_channel.freq,
3616 data->remain_on_channel.duration);
3618 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3619 #ifdef CONFIG_OFFCHANNEL
3620 offchannel_cancel_remain_on_channel_cb(
3621 wpa_s, data->remain_on_channel.freq);
3622 #endif /* CONFIG_OFFCHANNEL */
3623 wpas_p2p_cancel_remain_on_channel_cb(
3624 wpa_s, data->remain_on_channel.freq);
3626 case EVENT_EAPOL_RX:
3627 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3628 data->eapol_rx.data,
3629 data->eapol_rx.data_len);
3631 case EVENT_SIGNAL_CHANGE:
3632 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3633 "above=%d signal=%d noise=%d txrate=%d",
3634 data->signal_change.above_threshold,
3635 data->signal_change.current_signal,
3636 data->signal_change.current_noise,
3637 data->signal_change.current_txrate);
3638 wpa_bss_update_level(wpa_s->current_bss,
3639 data->signal_change.current_signal);
3640 bgscan_notify_signal_change(
3641 wpa_s, data->signal_change.above_threshold,
3642 data->signal_change.current_signal,
3643 data->signal_change.current_noise,
3644 data->signal_change.current_txrate);
3646 case EVENT_INTERFACE_ENABLED:
3647 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3648 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3649 wpa_supplicant_update_mac_addr(wpa_s);
3650 if (wpa_s->p2p_mgmt) {
3651 wpa_supplicant_set_state(wpa_s,
3657 if (!wpa_s->ap_iface) {
3658 wpa_supplicant_set_state(wpa_s,
3660 wpa_s->scan_req = NORMAL_SCAN_REQ;
3661 wpa_supplicant_req_scan(wpa_s, 0, 0);
3663 wpa_supplicant_set_state(wpa_s,
3665 #else /* CONFIG_AP */
3666 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3667 wpa_supplicant_req_scan(wpa_s, 0, 0);
3668 #endif /* CONFIG_AP */
3671 case EVENT_INTERFACE_DISABLED:
3672 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3674 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3675 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3676 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3678 * Mark interface disabled if this happens to end up not
3679 * being removed as a separate P2P group interface.
3681 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3683 * The interface was externally disabled. Remove
3684 * it assuming an external entity will start a
3685 * new session if needed.
3687 if (wpa_s->current_ssid &&
3688 wpa_s->current_ssid->p2p_group)
3689 wpas_p2p_interface_unavailable(wpa_s);
3691 wpas_p2p_disconnect(wpa_s);
3693 * wpa_s instance may have been freed, so must not use
3698 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3699 p2p_in_progress(wpa_s->global->p2p) > 1) {
3700 /* This radio work will be cancelled, so clear P2P
3703 p2p_stop_find(wpa_s->global->p2p);
3705 #endif /* CONFIG_P2P */
3707 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3709 * Indicate disconnection to keep ctrl_iface events
3712 wpa_supplicant_event_disassoc(
3713 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3715 wpa_supplicant_mark_disassoc(wpa_s);
3716 radio_remove_works(wpa_s, NULL, 0);
3718 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3720 case EVENT_CHANNEL_LIST_CHANGED:
3721 wpa_supplicant_update_channel_list(
3722 wpa_s, &data->channel_list_changed);
3724 case EVENT_INTERFACE_UNAVAILABLE:
3725 wpas_p2p_interface_unavailable(wpa_s);
3727 case EVENT_BEST_CHANNEL:
3728 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3730 data->best_chan.freq_24, data->best_chan.freq_5,
3731 data->best_chan.freq_overall);
3732 wpa_s->best_24_freq = data->best_chan.freq_24;
3733 wpa_s->best_5_freq = data->best_chan.freq_5;
3734 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3735 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3736 data->best_chan.freq_5,
3737 data->best_chan.freq_overall);
3739 case EVENT_UNPROT_DEAUTH:
3740 wpa_supplicant_event_unprot_deauth(wpa_s,
3741 &data->unprot_deauth);
3743 case EVENT_UNPROT_DISASSOC:
3744 wpa_supplicant_event_unprot_disassoc(wpa_s,
3745 &data->unprot_disassoc);
3747 case EVENT_STATION_LOW_ACK:
3749 if (wpa_s->ap_iface && data)
3750 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3751 data->low_ack.addr);
3752 #endif /* CONFIG_AP */
3755 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3756 data->low_ack.addr);
3757 #endif /* CONFIG_TDLS */
3759 case EVENT_IBSS_PEER_LOST:
3760 #ifdef CONFIG_IBSS_RSN
3761 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3762 #endif /* CONFIG_IBSS_RSN */
3764 case EVENT_DRIVER_GTK_REKEY:
3765 if (os_memcmp(data->driver_gtk_rekey.bssid,
3766 wpa_s->bssid, ETH_ALEN))
3770 wpa_sm_update_replay_ctr(wpa_s->wpa,
3771 data->driver_gtk_rekey.replay_ctr);
3773 case EVENT_SCHED_SCAN_STOPPED:
3775 wpa_s->sched_scanning = 0;
3776 resched = wpa_s->scanning;
3777 wpa_supplicant_notify_scanning(wpa_s, 0);
3779 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3783 * Start a new sched scan to continue searching for more SSIDs
3784 * either if timed out or PNO schedule scan is pending.
3786 if (wpa_s->sched_scan_timed_out) {
3787 wpa_supplicant_req_sched_scan(wpa_s);
3788 } else if (wpa_s->pno_sched_pending) {
3789 wpa_s->pno_sched_pending = 0;
3790 wpas_start_pno(wpa_s);
3791 } else if (resched) {
3792 wpa_supplicant_req_scan(wpa_s, 0, 0);
3796 case EVENT_WPS_BUTTON_PUSHED:
3798 wpas_wps_start_pbc(wpa_s, NULL, 0);
3799 #endif /* CONFIG_WPS */
3801 case EVENT_AVOID_FREQUENCIES:
3802 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3804 case EVENT_CONNECT_FAILED_REASON:
3806 if (!wpa_s->ap_iface || !data)
3808 hostapd_event_connect_failed_reason(
3809 wpa_s->ap_iface->bss[0],
3810 data->connect_failed_reason.addr,
3811 data->connect_failed_reason.code);
3812 #endif /* CONFIG_AP */
3814 case EVENT_NEW_PEER_CANDIDATE:
3816 if (!wpa_s->ifmsh || !data)
3818 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3819 data->mesh_peer.ies,
3820 data->mesh_peer.ie_len);
3821 #endif /* CONFIG_MESH */
3824 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);