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 if (data && data->scan_info.external_scan)
1422 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1424 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1426 goto scan_work_done;
1429 #ifndef CONFIG_NO_RANDOM_POOL
1430 num = scan_res->num;
1433 for (i = 0; i < num; i++) {
1435 struct wpa_scan_res *res = scan_res->res[i];
1436 buf[0] = res->bssid[5];
1437 buf[1] = res->qual & 0xff;
1438 buf[2] = res->noise & 0xff;
1439 buf[3] = res->level & 0xff;
1440 buf[4] = res->tsf & 0xff;
1441 random_add_randomness(buf, sizeof(buf));
1443 #endif /* CONFIG_NO_RANDOM_POOL */
1445 if (own_request && wpa_s->scan_res_handler &&
1446 !(data && data->scan_info.external_scan)) {
1447 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1448 struct wpa_scan_results *scan_res);
1450 scan_res_handler = wpa_s->scan_res_handler;
1451 wpa_s->scan_res_handler = NULL;
1452 scan_res_handler(wpa_s, scan_res);
1454 goto scan_work_done;
1458 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1460 if (wpa_s->ap_iface->scan_cb)
1461 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1462 #endif /* CONFIG_AP */
1463 goto scan_work_done;
1466 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1467 wpa_s->own_scan_running,
1468 data ? data->scan_info.external_scan : 0);
1469 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1470 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1471 own_request && !(data && data->scan_info.external_scan)) {
1472 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1473 wpa_s->manual_scan_id);
1474 wpa_s->manual_scan_use_id = 0;
1476 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1478 wpas_notify_scan_results(wpa_s);
1480 wpas_notify_scan_done(wpa_s, 1);
1482 if (data && data->scan_info.external_scan) {
1483 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1484 wpa_scan_results_free(scan_res);
1488 if (wnm_scan_process(wpa_s, 1) > 0)
1489 goto scan_work_done;
1491 if (sme_proc_obss_scan(wpa_s) > 0)
1492 goto scan_work_done;
1494 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1495 goto scan_work_done;
1497 if (autoscan_notify_scan(wpa_s, scan_res))
1498 goto scan_work_done;
1500 if (wpa_s->disconnected) {
1501 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1502 goto scan_work_done;
1505 if (!wpas_driver_bss_selection(wpa_s) &&
1506 bgscan_notify_scan(wpa_s, scan_res) == 1)
1507 goto scan_work_done;
1509 wpas_wps_update_ap_info(wpa_s, scan_res);
1511 wpa_scan_results_free(scan_res);
1513 if (own_request && wpa_s->scan_work) {
1514 struct wpa_radio_work *work = wpa_s->scan_work;
1515 wpa_s->scan_work = NULL;
1516 radio_work_done(work);
1519 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1522 wpa_scan_results_free(scan_res);
1523 if (own_request && wpa_s->scan_work) {
1524 struct wpa_radio_work *work = wpa_s->scan_work;
1525 wpa_s->scan_work = NULL;
1526 radio_work_done(work);
1532 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1533 int new_scan, int own_request)
1535 struct wpa_bss *selected;
1536 struct wpa_ssid *ssid = NULL;
1537 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1539 if (time_to_reenable > 0) {
1540 wpa_dbg(wpa_s, MSG_DEBUG,
1541 "Postpone network selection by %d seconds since all networks are disabled",
1543 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1544 eloop_register_timeout(time_to_reenable, 0,
1545 wpas_network_reenabled, wpa_s, NULL);
1549 if (wpa_s->p2p_mgmt)
1550 return 0; /* no normal connection on p2p_mgmt interface */
1552 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1556 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1559 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1563 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1564 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1568 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1570 * Do not notify other virtual radios of scan results since we do not
1571 * want them to start other associations at the same time.
1577 wpa_msg(wpa_s, MSG_INFO,
1578 "Avoiding join because we already joined a mesh group");
1581 #endif /* CONFIG_MESH */
1582 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1583 ssid = wpa_supplicant_pick_new_network(wpa_s);
1585 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1586 wpa_supplicant_associate(wpa_s, NULL, ssid);
1588 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1589 } else if (own_request) {
1591 * No SSID found. If SCAN results are as a result of
1592 * own scan request and not due to a scan request on
1593 * another shared interface, try another scan.
1595 int timeout_sec = wpa_s->scan_interval;
1596 int timeout_usec = 0;
1600 res = wpas_p2p_scan_no_go_seen(wpa_s);
1606 if (wpa_s->p2p_in_provisioning ||
1607 wpa_s->show_group_started ||
1608 wpa_s->p2p_in_invitation) {
1610 * Use shorter wait during P2P Provisioning
1611 * state and during P2P join-a-group operation
1612 * to speed up group formation.
1615 timeout_usec = 250000;
1616 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1620 #endif /* CONFIG_P2P */
1621 #ifdef CONFIG_INTERWORKING
1622 if (wpa_s->conf->auto_interworking &&
1623 wpa_s->conf->interworking &&
1624 wpa_s->conf->cred) {
1625 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1626 "start ANQP fetch since no matching "
1628 wpa_s->network_select = 1;
1629 wpa_s->auto_network_select = 1;
1630 interworking_start_fetch_anqp(wpa_s);
1633 #endif /* CONFIG_INTERWORKING */
1635 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1636 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1638 timeout_usec = 500000;
1639 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1643 #endif /* CONFIG_WPS */
1644 if (wpa_supplicant_req_sched_scan(wpa_s))
1645 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1648 wpa_msg_ctrl(wpa_s, MSG_INFO,
1649 WPA_EVENT_NETWORK_NOT_FOUND);
1656 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1657 union wpa_event_data *data)
1659 struct wpa_supplicant *ifs;
1662 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1665 * Interface may have been removed, so must not dereference
1672 * If no scan results could be fetched, then no need to
1673 * notify those interfaces that did not actually request
1674 * this scan. Similarly, if scan results started a new operation on this
1675 * interface, do not notify other interfaces to avoid concurrent
1676 * operations during a connection attempt.
1682 * Check other interfaces to see if they share the same radio. If
1683 * so, they get updated with this same scan info.
1685 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1688 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1689 "sibling", ifs->ifname);
1690 _wpa_supplicant_event_scan_results(ifs, data, 0);
1697 #endif /* CONFIG_NO_SCAN_PROCESSING */
1700 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1702 #ifdef CONFIG_NO_SCAN_PROCESSING
1704 #else /* CONFIG_NO_SCAN_PROCESSING */
1705 struct os_reltime now;
1707 if (wpa_s->last_scan_res_used == 0)
1710 os_get_reltime(&now);
1711 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1712 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1716 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1717 #endif /* CONFIG_NO_SCAN_PROCESSING */
1722 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1724 struct wpa_supplicant *wpa_s = eloop_ctx;
1726 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1729 if (!wpa_s->no_keep_alive) {
1730 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1731 MAC2STR(wpa_s->bssid));
1732 /* TODO: could skip this if normal data traffic has been sent */
1733 /* TODO: Consider using some more appropriate data frame for
1736 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1741 if (wpa_s->sme.bss_max_idle_period) {
1743 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1746 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1747 wnm_bss_keep_alive, wpa_s, NULL);
1749 #endif /* CONFIG_SME */
1753 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1754 const u8 *ies, size_t ies_len)
1756 struct ieee802_11_elems elems;
1761 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1765 if (elems.bss_max_idle_period) {
1767 wpa_s->sme.bss_max_idle_period =
1768 WPA_GET_LE16(elems.bss_max_idle_period);
1769 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1770 "TU)%s", wpa_s->sme.bss_max_idle_period,
1771 (elems.bss_max_idle_period[2] & 0x01) ?
1772 " (protected keep-live required)" : "");
1773 if (wpa_s->sme.bss_max_idle_period == 0)
1774 wpa_s->sme.bss_max_idle_period = 1;
1775 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1776 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1777 /* msec times 1000 */
1778 msec = wpa_s->sme.bss_max_idle_period * 1024;
1781 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1782 wnm_bss_keep_alive, wpa_s,
1786 #endif /* CONFIG_SME */
1789 #endif /* CONFIG_WNM */
1792 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1795 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1796 #endif /* CONFIG_WNM */
1800 #ifdef CONFIG_INTERWORKING
1802 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1807 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1808 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1810 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1817 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1818 const u8 *ies, size_t ies_len)
1820 struct ieee802_11_elems elems;
1825 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1828 if (elems.qos_map_set) {
1829 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1830 elems.qos_map_set_len);
1834 #endif /* CONFIG_INTERWORKING */
1837 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1838 union wpa_event_data *data)
1840 int l, len, found = 0, wpa_found, rsn_found;
1842 #ifdef CONFIG_IEEE80211R
1844 #endif /* CONFIG_IEEE80211R */
1846 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1847 if (data->assoc_info.req_ies)
1848 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1849 data->assoc_info.req_ies_len);
1850 if (data->assoc_info.resp_ies) {
1851 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1852 data->assoc_info.resp_ies_len);
1854 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1855 data->assoc_info.resp_ies_len);
1856 #endif /* CONFIG_TDLS */
1858 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1859 data->assoc_info.resp_ies_len);
1860 #endif /* CONFIG_WNM */
1861 #ifdef CONFIG_INTERWORKING
1862 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1863 data->assoc_info.resp_ies_len);
1864 #endif /* CONFIG_INTERWORKING */
1866 if (data->assoc_info.beacon_ies)
1867 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1868 data->assoc_info.beacon_ies,
1869 data->assoc_info.beacon_ies_len);
1870 if (data->assoc_info.freq)
1871 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1872 data->assoc_info.freq);
1874 p = data->assoc_info.req_ies;
1875 l = data->assoc_info.req_ies_len;
1877 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1878 while (p && l >= 2) {
1881 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1885 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1886 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1887 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1888 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1891 wpa_find_assoc_pmkid(wpa_s);
1897 if (!found && data->assoc_info.req_ies)
1898 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1900 #ifdef CONFIG_IEEE80211R
1902 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1903 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1904 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1905 data->assoc_info.resp_ies,
1906 data->assoc_info.resp_ies_len,
1908 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1909 "Reassociation Response failed");
1910 wpa_supplicant_deauthenticate(
1911 wpa_s, WLAN_REASON_INVALID_IE);
1916 p = data->assoc_info.resp_ies;
1917 l = data->assoc_info.resp_ies_len;
1919 #ifdef CONFIG_WPS_STRICT
1920 if (p && wpa_s->current_ssid &&
1921 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1923 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1925 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1926 "include WPS IE in (Re)Association Response");
1930 if (wps_validate_assoc_resp(wps) < 0) {
1932 wpa_supplicant_deauthenticate(
1933 wpa_s, WLAN_REASON_INVALID_IE);
1938 #endif /* CONFIG_WPS_STRICT */
1940 /* Go through the IEs and make a copy of the MDIE, if present. */
1941 while (p && l >= 2) {
1944 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1948 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1949 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1950 wpa_s->sme.ft_used = 1;
1951 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1952 MOBILITY_DOMAIN_ID_LEN);
1958 #endif /* CONFIG_SME */
1960 /* Process FT when SME is in the driver */
1961 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1962 wpa_ft_is_completed(wpa_s->wpa)) {
1963 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1964 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1965 data->assoc_info.resp_ies,
1966 data->assoc_info.resp_ies_len,
1968 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1969 "Reassociation Response failed");
1970 wpa_supplicant_deauthenticate(
1971 wpa_s, WLAN_REASON_INVALID_IE);
1974 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1977 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1978 data->assoc_info.resp_ies_len);
1979 #endif /* CONFIG_IEEE80211R */
1981 /* WPA/RSN IE from Beacon/ProbeResp */
1982 p = data->assoc_info.beacon_ies;
1983 l = data->assoc_info.beacon_ies_len;
1985 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1987 wpa_found = rsn_found = 0;
1988 while (p && l >= 2) {
1991 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1996 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1997 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1999 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2003 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2005 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2012 if (!wpa_found && data->assoc_info.beacon_ies)
2013 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2014 if (!rsn_found && data->assoc_info.beacon_ies)
2015 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2016 if (wpa_found || rsn_found)
2017 wpa_s->ap_ies_from_associnfo = 1;
2020 wpabuf_free(wpa_s->received_mb_ies);
2021 wpa_s->received_mb_ies = NULL;
2023 struct mb_ies_info mb_ies;
2025 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2026 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2027 data->assoc_info.resp_ies_len))
2028 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2030 #endif /* CONFIG_FST */
2032 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2033 wpa_s->assoc_freq != data->assoc_info.freq) {
2034 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2036 wpa_s->assoc_freq, data->assoc_info.freq);
2037 wpa_supplicant_update_scan_results(wpa_s);
2040 wpa_s->assoc_freq = data->assoc_info.freq;
2046 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2048 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2050 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2053 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2056 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2057 WPA_IE_VENDOR_TYPE);
2058 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2060 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2061 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2062 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2063 bss_rsn ? 2 + bss_rsn[1] : 0))
2070 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2071 union wpa_event_data *data)
2078 if (wpa_s->ap_iface) {
2081 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2082 data->assoc_info.addr,
2083 data->assoc_info.req_ies,
2084 data->assoc_info.req_ies_len,
2085 data->assoc_info.reassoc);
2088 #endif /* CONFIG_AP */
2090 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2092 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2093 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2096 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2097 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2098 wpa_supplicant_deauthenticate(
2099 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2103 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2104 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2105 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2106 MACSTR, MAC2STR(bssid));
2108 random_add_randomness(bssid, ETH_ALEN);
2109 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2110 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2111 wpas_notify_bssid_changed(wpa_s);
2113 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2114 wpa_clear_keys(wpa_s, bssid);
2116 if (wpa_supplicant_select_config(wpa_s) < 0) {
2117 wpa_supplicant_deauthenticate(
2118 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2123 if (wpa_s->conf->ap_scan == 1 &&
2124 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2125 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2126 wpa_msg(wpa_s, MSG_WARNING,
2127 "WPA/RSN IEs not updated");
2131 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2132 wpa_s->sme.prev_bssid_set = 1;
2133 wpa_s->sme.last_unprot_disconnect.sec = 0;
2134 #endif /* CONFIG_SME */
2136 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2137 if (wpa_s->current_ssid) {
2138 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2139 * initialized before association, but for other modes,
2140 * initialize PC/SC here, if the current configuration needs
2141 * smartcard or SIM/USIM. */
2142 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2144 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2146 l2_packet_notify_auth_start(wpa_s->l2);
2149 * Set portEnabled first to FALSE in order to get EAP state machine out
2150 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2151 * state machine may transit to AUTHENTICATING state based on obsolete
2152 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2153 * AUTHENTICATED without ever giving chance to EAP state machine to
2156 if (!ft_completed) {
2157 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2158 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2160 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2161 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2162 /* 802.1X::portControl = Auto */
2163 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2164 wpa_s->eapol_received = 0;
2165 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2166 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2167 (wpa_s->current_ssid &&
2168 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2169 if (wpa_s->current_ssid &&
2170 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2172 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2174 * Set the key after having received joined-IBSS event
2177 wpa_supplicant_set_wpa_none_key(wpa_s,
2178 wpa_s->current_ssid);
2180 wpa_supplicant_cancel_auth_timeout(wpa_s);
2181 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2182 } else if (!ft_completed) {
2183 /* Timeout for receiving the first EAPOL packet */
2184 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2186 wpa_supplicant_cancel_scan(wpa_s);
2188 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2189 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2191 * We are done; the driver will take care of RSN 4-way
2194 wpa_supplicant_cancel_auth_timeout(wpa_s);
2195 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2196 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2197 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2198 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2199 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2201 * The driver will take care of RSN 4-way handshake, so we need
2202 * to allow EAPOL supplicant to complete its work without
2203 * waiting for WPA supplicant.
2205 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2206 } else if (ft_completed) {
2208 * FT protocol completed - make sure EAPOL state machine ends
2209 * up in authenticated.
2211 wpa_supplicant_cancel_auth_timeout(wpa_s);
2212 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2213 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2214 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2217 wpa_s->last_eapol_matches_bssid = 0;
2219 if (wpa_s->pending_eapol_rx) {
2220 struct os_reltime now, age;
2221 os_get_reltime(&now);
2222 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2223 if (age.sec == 0 && age.usec < 100000 &&
2224 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2226 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2227 "frame that was received just before "
2228 "association notification");
2229 wpa_supplicant_rx_eapol(
2230 wpa_s, wpa_s->pending_eapol_rx_src,
2231 wpabuf_head(wpa_s->pending_eapol_rx),
2232 wpabuf_len(wpa_s->pending_eapol_rx));
2234 wpabuf_free(wpa_s->pending_eapol_rx);
2235 wpa_s->pending_eapol_rx = NULL;
2238 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2239 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2240 wpa_s->current_ssid &&
2241 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2242 /* Set static WEP keys again */
2243 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2246 #ifdef CONFIG_IBSS_RSN
2247 if (wpa_s->current_ssid &&
2248 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2249 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2250 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2251 wpa_s->ibss_rsn == NULL) {
2252 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2253 if (!wpa_s->ibss_rsn) {
2254 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2255 wpa_supplicant_deauthenticate(
2256 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2260 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2262 #endif /* CONFIG_IBSS_RSN */
2264 wpas_wps_notify_assoc(wpa_s, bssid);
2267 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2268 data->assoc_info.resp_ies_len,
2269 &data->assoc_info.wmm_params);
2271 if (wpa_s->reassoc_same_bss)
2272 wmm_ac_restore_tspecs(wpa_s);
2277 static int disconnect_reason_recoverable(u16 reason_code)
2279 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2280 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2281 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2285 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2287 int locally_generated)
2291 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2293 * At least Host AP driver and a Prism3 card seemed to be
2294 * generating streams of disconnected events when configuring
2295 * IBSS for WPA-None. Ignore them for now.
2300 bssid = wpa_s->bssid;
2301 if (is_zero_ether_addr(bssid))
2302 bssid = wpa_s->pending_bssid;
2304 if (!is_zero_ether_addr(bssid) ||
2305 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2306 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2308 MAC2STR(bssid), reason_code,
2309 locally_generated ? " locally_generated=1" : "");
2314 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2315 int locally_generated)
2317 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2318 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2319 return 0; /* Not in 4-way handshake with PSK */
2322 * It looks like connection was lost while trying to go through PSK
2323 * 4-way handshake. Filter out known disconnection cases that are caused
2324 * by something else than PSK mismatch to avoid confusing reports.
2327 if (locally_generated) {
2328 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2336 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2338 int locally_generated)
2342 u8 prev_pending_bssid[ETH_ALEN];
2343 struct wpa_bss *fast_reconnect = NULL;
2344 struct wpa_ssid *fast_reconnect_ssid = NULL;
2345 struct wpa_ssid *last_ssid;
2347 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2348 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2350 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2352 * At least Host AP driver and a Prism3 card seemed to be
2353 * generating streams of disconnected events when configuring
2354 * IBSS for WPA-None. Ignore them for now.
2356 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2357 "IBSS/WPA-None mode");
2361 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2362 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2363 "pre-shared key may be incorrect");
2364 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2365 return; /* P2P group removed */
2366 wpas_auth_failed(wpa_s, "WRONG_KEY");
2368 if (!wpa_s->disconnected &&
2369 (!wpa_s->auto_reconnect_disabled ||
2370 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2371 wpas_wps_searching(wpa_s))) {
2372 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2373 "reconnect (wps=%d/%d wpa_state=%d)",
2374 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2375 wpas_wps_searching(wpa_s),
2377 if (wpa_s->wpa_state == WPA_COMPLETED &&
2378 wpa_s->current_ssid &&
2379 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2380 !locally_generated &&
2381 disconnect_reason_recoverable(reason_code)) {
2383 * It looks like the AP has dropped association with
2384 * us, but could allow us to get back in. Try to
2385 * reconnect to the same BSS without full scan to save
2386 * time for some common cases.
2388 fast_reconnect = wpa_s->current_bss;
2389 fast_reconnect_ssid = wpa_s->current_ssid;
2390 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2391 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2393 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2396 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2397 "try to re-connect");
2398 wpa_s->reassociate = 0;
2399 wpa_s->disconnected = 1;
2401 wpa_supplicant_cancel_sched_scan(wpa_s);
2403 bssid = wpa_s->bssid;
2404 if (is_zero_ether_addr(bssid))
2405 bssid = wpa_s->pending_bssid;
2406 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2407 wpas_connection_failed(wpa_s, bssid);
2408 wpa_sm_notify_disassoc(wpa_s->wpa);
2409 if (locally_generated)
2410 wpa_s->disconnect_reason = -reason_code;
2412 wpa_s->disconnect_reason = reason_code;
2413 wpas_notify_disconnect_reason(wpa_s);
2414 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2415 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2416 wpa_clear_keys(wpa_s, wpa_s->bssid);
2418 last_ssid = wpa_s->current_ssid;
2419 wpa_supplicant_mark_disassoc(wpa_s);
2421 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2422 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2423 wpa_s->current_ssid = last_ssid;
2426 if (fast_reconnect &&
2427 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2428 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2429 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2430 fast_reconnect->ssid_len) &&
2431 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2432 #ifndef CONFIG_NO_SCAN_PROCESSING
2433 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2434 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2435 fast_reconnect_ssid) < 0) {
2436 /* Recover through full scan */
2437 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2439 #endif /* CONFIG_NO_SCAN_PROCESSING */
2440 } else if (fast_reconnect) {
2442 * Could not reconnect to the same BSS due to network being
2443 * disabled. Use a new scan to match the alternative behavior
2444 * above, i.e., to continue automatic reconnection attempt in a
2445 * way that enforces disabled network rules.
2447 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2452 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2453 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2455 struct wpa_supplicant *wpa_s = eloop_ctx;
2457 if (!wpa_s->pending_mic_error_report)
2460 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2461 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2462 wpa_s->pending_mic_error_report = 0;
2464 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2468 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2469 union wpa_event_data *data)
2472 struct os_reltime t;
2474 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2475 pairwise = (data && data->michael_mic_failure.unicast);
2477 if ((wpa_s->last_michael_mic_error.sec &&
2478 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2479 wpa_s->pending_mic_error_report) {
2480 if (wpa_s->pending_mic_error_report) {
2482 * Send the pending MIC error report immediately since
2483 * we are going to start countermeasures and AP better
2486 wpa_sm_key_request(wpa_s->wpa, 1,
2487 wpa_s->pending_mic_error_pairwise);
2490 /* Send the new MIC error report immediately since we are going
2491 * to start countermeasures and AP better do the same.
2493 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2495 /* initialize countermeasures */
2496 wpa_s->countermeasures = 1;
2498 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2500 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2503 * Need to wait for completion of request frame. We do not get
2504 * any callback for the message completion, so just wait a
2505 * short while and hope for the best. */
2508 wpa_drv_set_countermeasures(wpa_s, 1);
2509 wpa_supplicant_deauthenticate(wpa_s,
2510 WLAN_REASON_MICHAEL_MIC_FAILURE);
2511 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2513 eloop_register_timeout(60, 0,
2514 wpa_supplicant_stop_countermeasures,
2516 /* TODO: mark the AP rejected for 60 second. STA is
2517 * allowed to associate with another AP.. */
2519 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2520 if (wpa_s->mic_errors_seen) {
2522 * Reduce the effectiveness of Michael MIC error
2523 * reports as a means for attacking against TKIP if
2524 * more than one MIC failure is noticed with the same
2525 * PTK. We delay the transmission of the reports by a
2526 * random time between 0 and 60 seconds in order to
2527 * force the attacker wait 60 seconds before getting
2528 * the information on whether a frame resulted in a MIC
2534 if (os_get_random(rval, sizeof(rval)) < 0)
2535 sec = os_random() % 60;
2537 sec = WPA_GET_BE32(rval) % 60;
2538 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2539 "report %d seconds", sec);
2540 wpa_s->pending_mic_error_report = 1;
2541 wpa_s->pending_mic_error_pairwise = pairwise;
2542 eloop_cancel_timeout(
2543 wpa_supplicant_delayed_mic_error_report,
2545 eloop_register_timeout(
2546 sec, os_random() % 1000000,
2547 wpa_supplicant_delayed_mic_error_report,
2550 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2552 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2553 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2554 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2556 wpa_s->last_michael_mic_error = t;
2557 wpa_s->mic_errors_seen++;
2561 #ifdef CONFIG_TERMINATE_ONLASTIF
2562 static int any_interfaces(struct wpa_supplicant *head)
2564 struct wpa_supplicant *wpa_s;
2566 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2567 if (!wpa_s->interface_removed)
2571 #endif /* CONFIG_TERMINATE_ONLASTIF */
2575 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2576 union wpa_event_data *data)
2578 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2581 switch (data->interface_status.ievent) {
2582 case EVENT_INTERFACE_ADDED:
2583 if (!wpa_s->interface_removed)
2585 wpa_s->interface_removed = 0;
2586 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2587 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2588 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2589 "driver after interface was added");
2593 if (!wpa_s->global->p2p &&
2594 !wpa_s->global->p2p_disabled &&
2595 !wpa_s->conf->p2p_disabled &&
2597 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2598 wpas_p2p_add_p2pdev_interface(
2599 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2600 wpa_printf(MSG_INFO,
2601 "P2P: Failed to enable P2P Device interface");
2602 /* Try to continue without. P2P will be disabled. */
2604 #endif /* CONFIG_P2P */
2607 case EVENT_INTERFACE_REMOVED:
2608 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2609 wpa_s->interface_removed = 1;
2610 wpa_supplicant_mark_disassoc(wpa_s);
2611 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2612 l2_packet_deinit(wpa_s->l2);
2616 if (wpa_s->global->p2p &&
2617 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2619 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2620 wpa_dbg(wpa_s, MSG_DEBUG,
2621 "Removing P2P Device interface");
2622 wpa_supplicant_remove_iface(
2623 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2625 wpa_s->global->p2p_init_wpa_s = NULL;
2627 #endif /* CONFIG_P2P */
2629 #ifdef CONFIG_TERMINATE_ONLASTIF
2630 /* check if last interface */
2631 if (!any_interfaces(wpa_s->global->ifaces))
2633 #endif /* CONFIG_TERMINATE_ONLASTIF */
2639 #ifdef CONFIG_PEERKEY
2641 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2642 union wpa_event_data *data)
2646 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2648 #endif /* CONFIG_PEERKEY */
2652 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2653 union wpa_event_data *data)
2657 switch (data->tdls.oper) {
2658 case TDLS_REQUEST_SETUP:
2659 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2660 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2661 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2663 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2665 case TDLS_REQUEST_TEARDOWN:
2666 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2667 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2668 data->tdls.reason_code);
2670 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2673 case TDLS_REQUEST_DISCOVER:
2674 wpa_tdls_send_discovery_request(wpa_s->wpa,
2679 #endif /* CONFIG_TDLS */
2683 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2684 union wpa_event_data *data)
2688 switch (data->wnm.oper) {
2689 case WNM_OPER_SLEEP:
2690 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2691 "(action=%d, intval=%d)",
2692 data->wnm.sleep_action, data->wnm.sleep_intval);
2693 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2694 data->wnm.sleep_intval, NULL);
2698 #endif /* CONFIG_WNM */
2701 #ifdef CONFIG_IEEE80211R
2703 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2704 union wpa_event_data *data)
2709 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2710 data->ft_ies.ies_len,
2711 data->ft_ies.ft_action,
2712 data->ft_ies.target_ap,
2713 data->ft_ies.ric_ies,
2714 data->ft_ies.ric_ies_len) < 0) {
2715 /* TODO: prevent MLME/driver from trying to associate? */
2718 #endif /* CONFIG_IEEE80211R */
2721 #ifdef CONFIG_IBSS_RSN
2722 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2723 union wpa_event_data *data)
2725 struct wpa_ssid *ssid;
2726 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2730 ssid = wpa_s->current_ssid;
2733 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2736 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2740 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2741 union wpa_event_data *data)
2743 struct wpa_ssid *ssid = wpa_s->current_ssid;
2748 /* check if the ssid is correctly configured as IBSS/RSN */
2749 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2752 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2753 data->rx_mgmt.frame_len);
2755 #endif /* CONFIG_IBSS_RSN */
2758 #ifdef CONFIG_IEEE80211R
2759 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2762 const u8 *sta_addr, *target_ap_addr;
2765 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2766 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2767 return; /* only SME case supported for now */
2768 if (len < 1 + 2 * ETH_ALEN + 2)
2771 return; /* Only FT Action Response is supported for now */
2772 sta_addr = data + 1;
2773 target_ap_addr = data + 1 + ETH_ALEN;
2774 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2775 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2776 MACSTR " TargetAP " MACSTR " status %u",
2777 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2779 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2780 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2781 " in FT Action Response", MAC2STR(sta_addr));
2786 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2787 "failure (status code %d)", status);
2788 /* TODO: report error to FT code(?) */
2792 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2793 len - (1 + 2 * ETH_ALEN + 2), 1,
2794 target_ap_addr, NULL, 0) < 0)
2799 struct wpa_bss *bss;
2800 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2802 wpa_s->sme.freq = bss->freq;
2803 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2804 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2807 #endif /* CONFIG_SME */
2809 #endif /* CONFIG_IEEE80211R */
2812 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2813 struct unprot_deauth *e)
2815 #ifdef CONFIG_IEEE80211W
2816 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2817 "dropped: " MACSTR " -> " MACSTR
2818 " (reason code %u)",
2819 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2820 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2821 #endif /* CONFIG_IEEE80211W */
2825 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2826 struct unprot_disassoc *e)
2828 #ifdef CONFIG_IEEE80211W
2829 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2830 "dropped: " MACSTR " -> " MACSTR
2831 " (reason code %u)",
2832 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2833 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2834 #endif /* CONFIG_IEEE80211W */
2838 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2839 u16 reason_code, int locally_generated,
2840 const u8 *ie, size_t ie_len, int deauth)
2843 if (wpa_s->ap_iface && addr) {
2844 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2848 if (wpa_s->ap_iface) {
2849 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2852 #endif /* CONFIG_AP */
2854 if (!locally_generated)
2855 wpa_s->own_disconnect_req = 0;
2857 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2859 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2860 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2861 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2862 eapol_sm_failed(wpa_s->eapol))) &&
2863 !wpa_s->eap_expected_failure))
2864 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2867 if (deauth && reason_code > 0) {
2868 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2869 locally_generated) > 0) {
2871 * The interface was removed, so cannot continue
2872 * processing any additional operations after this.
2877 #endif /* CONFIG_P2P */
2879 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2884 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2885 struct disassoc_info *info)
2887 u16 reason_code = 0;
2888 int locally_generated = 0;
2889 const u8 *addr = NULL;
2890 const u8 *ie = NULL;
2893 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2898 ie_len = info->ie_len;
2899 reason_code = info->reason_code;
2900 locally_generated = info->locally_generated;
2901 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2902 locally_generated ? " (locally generated)" : "");
2904 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2906 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2911 if (wpa_s->ap_iface && info && info->addr) {
2912 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2916 if (wpa_s->ap_iface) {
2917 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2920 #endif /* CONFIG_AP */
2924 wpas_p2p_disassoc_notif(
2925 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2928 #endif /* CONFIG_P2P */
2930 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2931 sme_event_disassoc(wpa_s, info);
2933 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2938 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2939 struct deauth_info *info)
2941 u16 reason_code = 0;
2942 int locally_generated = 0;
2943 const u8 *addr = NULL;
2944 const u8 *ie = NULL;
2947 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2952 ie_len = info->ie_len;
2953 reason_code = info->reason_code;
2954 locally_generated = info->locally_generated;
2955 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2957 locally_generated ? " (locally generated)" : "");
2959 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2962 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2966 wpa_reset_ft_completed(wpa_s->wpa);
2968 wpas_event_disconnect(wpa_s, addr, reason_code,
2969 locally_generated, ie, ie_len, 1);
2973 static const char * reg_init_str(enum reg_change_initiator init)
2976 case REGDOM_SET_BY_CORE:
2978 case REGDOM_SET_BY_USER:
2980 case REGDOM_SET_BY_DRIVER:
2982 case REGDOM_SET_BY_COUNTRY_IE:
2983 return "COUNTRY_IE";
2984 case REGDOM_BEACON_HINT:
2985 return "BEACON_HINT";
2991 static const char * reg_type_str(enum reg_type type)
2994 case REGDOM_TYPE_UNKNOWN:
2996 case REGDOM_TYPE_COUNTRY:
2998 case REGDOM_TYPE_WORLD:
3000 case REGDOM_TYPE_CUSTOM_WORLD:
3001 return "CUSTOM_WORLD";
3002 case REGDOM_TYPE_INTERSECTION:
3003 return "INTERSECTION";
3009 static void wpa_supplicant_update_channel_list(
3010 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3012 struct wpa_supplicant *ifs;
3014 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3015 reg_init_str(info->initiator), reg_type_str(info->type),
3016 info->alpha2[0] ? " alpha2=" : "",
3017 info->alpha2[0] ? info->alpha2 : "");
3019 if (wpa_s->drv_priv == NULL)
3020 return; /* Ignore event during drv initialization */
3022 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3024 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3026 free_hw_features(ifs);
3027 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3028 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3031 /* Restart sched_scan with updated channel list */
3032 if (wpa_s->sched_scanning) {
3033 wpa_dbg(wpa_s, MSG_DEBUG,
3034 "Channel list changed restart sched scan.");
3035 wpa_supplicant_cancel_sched_scan(wpa_s);
3036 wpa_supplicant_req_scan(wpa_s, 0, 0);
3039 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3043 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3044 const u8 *frame, size_t len, int freq,
3047 const struct ieee80211_mgmt *mgmt;
3052 if (len < IEEE80211_HDRLEN + 2)
3055 mgmt = (const struct ieee80211_mgmt *) frame;
3056 payload = frame + IEEE80211_HDRLEN;
3057 category = *payload++;
3058 plen = len - IEEE80211_HDRLEN - 1;
3060 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3061 " Category=%u DataLen=%d freq=%d MHz",
3062 MAC2STR(mgmt->sa), category, (int) plen, freq);
3064 if (category == WLAN_ACTION_WMM) {
3065 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3069 #ifdef CONFIG_IEEE80211R
3070 if (category == WLAN_ACTION_FT) {
3071 ft_rx_action(wpa_s, payload, plen);
3074 #endif /* CONFIG_IEEE80211R */
3076 #ifdef CONFIG_IEEE80211W
3078 if (category == WLAN_ACTION_SA_QUERY) {
3079 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3082 #endif /* CONFIG_SME */
3083 #endif /* CONFIG_IEEE80211W */
3086 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3087 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3090 #endif /* CONFIG_WNM */
3093 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3094 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3095 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3096 mgmt->u.action.category,
3097 payload, plen, freq) == 0)
3099 #endif /* CONFIG_GAS */
3102 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3103 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3104 wpa_dbg(wpa_s, MSG_DEBUG,
3105 "TDLS: Received Discovery Response from " MACSTR,
3109 #endif /* CONFIG_TDLS */
3111 #ifdef CONFIG_INTERWORKING
3112 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3113 payload[0] == QOS_QOS_MAP_CONFIG) {
3114 const u8 *pos = payload + 1;
3115 size_t qlen = plen - 1;
3116 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3117 MACSTR, MAC2STR(mgmt->sa));
3118 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3119 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3120 pos[1] <= qlen - 2 && pos[1] >= 16)
3121 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3124 #endif /* CONFIG_INTERWORKING */
3126 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3127 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3128 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3132 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3133 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3134 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3135 payload + 1, plen - 1,
3141 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3142 fst_rx_action(wpa_s->fst, mgmt, len);
3145 #endif /* CONFIG_FST */
3147 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3148 category, payload, plen, freq);
3150 mesh_mpm_action_rx(wpa_s, mgmt, len);
3154 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3155 union wpa_event_data *event)
3157 struct wpa_freq_range_list *list;
3160 list = &event->freq_range;
3163 str = freq_range_list_str(list);
3164 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3168 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3169 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3172 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3175 * The update channel flow will also take care of moving a GO
3176 * from the unsafe frequency if needed.
3178 wpas_p2p_update_channel_list(wpa_s,
3179 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3181 #endif /* CONFIG_P2P */
3187 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3188 union wpa_event_data *data)
3190 wpa_dbg(wpa_s, MSG_DEBUG,
3191 "Connection authorized by device, previous state %d",
3193 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3194 wpa_supplicant_cancel_auth_timeout(wpa_s);
3195 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3196 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3197 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3199 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3200 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3201 data->assoc_info.ptk_kck_len,
3202 data->assoc_info.ptk_kek,
3203 data->assoc_info.ptk_kek_len);
3207 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3208 union wpa_event_data *data)
3210 struct wpa_supplicant *wpa_s = ctx;
3213 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3214 event != EVENT_INTERFACE_ENABLED &&
3215 event != EVENT_INTERFACE_STATUS &&
3216 event != EVENT_SCHED_SCAN_STOPPED) {
3217 wpa_dbg(wpa_s, MSG_DEBUG,
3218 "Ignore event %s (%d) while interface is disabled",
3219 event_to_string(event), event);
3223 #ifndef CONFIG_NO_STDOUT_DEBUG
3225 int level = MSG_DEBUG;
3227 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3228 const struct ieee80211_hdr *hdr;
3230 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3231 fc = le_to_host16(hdr->frame_control);
3232 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3233 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3234 level = MSG_EXCESSIVE;
3237 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3238 event_to_string(event), event);
3240 #endif /* CONFIG_NO_STDOUT_DEBUG */
3244 sme_event_auth(wpa_s, data);
3247 wpa_supplicant_event_assoc(wpa_s, data);
3248 if (data && data->assoc_info.authorized)
3249 wpa_supplicant_event_assoc_auth(wpa_s, data);
3251 case EVENT_DISASSOC:
3252 wpas_event_disassoc(wpa_s,
3253 data ? &data->disassoc_info : NULL);
3256 wpas_event_deauth(wpa_s,
3257 data ? &data->deauth_info : NULL);
3259 case EVENT_MICHAEL_MIC_FAILURE:
3260 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3262 #ifndef CONFIG_NO_SCAN_PROCESSING
3263 case EVENT_SCAN_STARTED:
3264 if (wpa_s->own_scan_requested ||
3265 (data && !data->scan_info.external_scan)) {
3266 struct os_reltime diff;
3268 os_get_reltime(&wpa_s->scan_start_time);
3269 os_reltime_sub(&wpa_s->scan_start_time,
3270 &wpa_s->scan_trigger_time, &diff);
3271 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3272 diff.sec, diff.usec);
3273 wpa_s->own_scan_requested = 0;
3274 wpa_s->own_scan_running = 1;
3275 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3276 wpa_s->manual_scan_use_id) {
3277 wpa_msg_ctrl(wpa_s, MSG_INFO,
3278 WPA_EVENT_SCAN_STARTED "id=%u",
3279 wpa_s->manual_scan_id);
3281 wpa_msg_ctrl(wpa_s, MSG_INFO,
3282 WPA_EVENT_SCAN_STARTED);
3285 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3286 wpa_s->radio->external_scan_running = 1;
3287 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3290 case EVENT_SCAN_RESULTS:
3291 if (!(data && data->scan_info.external_scan) &&
3292 os_reltime_initialized(&wpa_s->scan_start_time)) {
3293 struct os_reltime now, diff;
3294 os_get_reltime(&now);
3295 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3296 wpa_s->scan_start_time.sec = 0;
3297 wpa_s->scan_start_time.usec = 0;
3298 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3299 diff.sec, diff.usec);
3301 if (wpa_supplicant_event_scan_results(wpa_s, data))
3302 break; /* interface may have been removed */
3303 if (!(data && data->scan_info.external_scan))
3304 wpa_s->own_scan_running = 0;
3305 if (data && data->scan_info.nl_scan_event)
3306 wpa_s->radio->external_scan_running = 0;
3307 radio_work_check_next(wpa_s);
3309 #endif /* CONFIG_NO_SCAN_PROCESSING */
3310 case EVENT_ASSOCINFO:
3311 wpa_supplicant_event_associnfo(wpa_s, data);
3313 case EVENT_INTERFACE_STATUS:
3314 wpa_supplicant_event_interface_status(wpa_s, data);
3316 case EVENT_PMKID_CANDIDATE:
3317 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3319 #ifdef CONFIG_PEERKEY
3320 case EVENT_STKSTART:
3321 wpa_supplicant_event_stkstart(wpa_s, data);
3323 #endif /* CONFIG_PEERKEY */
3326 wpa_supplicant_event_tdls(wpa_s, data);
3328 #endif /* CONFIG_TDLS */
3331 wpa_supplicant_event_wnm(wpa_s, data);
3333 #endif /* CONFIG_WNM */
3334 #ifdef CONFIG_IEEE80211R
3335 case EVENT_FT_RESPONSE:
3336 wpa_supplicant_event_ft_response(wpa_s, data);
3338 #endif /* CONFIG_IEEE80211R */
3339 #ifdef CONFIG_IBSS_RSN
3340 case EVENT_IBSS_RSN_START:
3341 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3343 #endif /* CONFIG_IBSS_RSN */
3344 case EVENT_ASSOC_REJECT:
3345 if (data->assoc_reject.bssid)
3346 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3347 "bssid=" MACSTR " status_code=%u",
3348 MAC2STR(data->assoc_reject.bssid),
3349 data->assoc_reject.status_code);
3351 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3353 data->assoc_reject.status_code);
3354 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3355 sme_event_assoc_reject(wpa_s, data);
3357 const u8 *bssid = data->assoc_reject.bssid;
3358 if (bssid == NULL || is_zero_ether_addr(bssid))
3359 bssid = wpa_s->pending_bssid;
3360 wpas_connection_failed(wpa_s, bssid);
3361 wpa_supplicant_mark_disassoc(wpa_s);
3364 case EVENT_AUTH_TIMED_OUT:
3365 /* It is possible to get this event from earlier connection */
3366 if (wpa_s->current_ssid &&
3367 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3368 wpa_dbg(wpa_s, MSG_DEBUG,
3369 "Ignore AUTH_TIMED_OUT in mesh configuration");
3372 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3373 sme_event_auth_timed_out(wpa_s, data);
3375 case EVENT_ASSOC_TIMED_OUT:
3376 /* It is possible to get this event from earlier connection */
3377 if (wpa_s->current_ssid &&
3378 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3379 wpa_dbg(wpa_s, MSG_DEBUG,
3380 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3383 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3384 sme_event_assoc_timed_out(wpa_s, data);
3386 case EVENT_TX_STATUS:
3387 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3388 " type=%d stype=%d",
3389 MAC2STR(data->tx_status.dst),
3390 data->tx_status.type, data->tx_status.stype);
3392 if (wpa_s->ap_iface == NULL) {
3393 #ifdef CONFIG_OFFCHANNEL
3394 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3395 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3396 offchannel_send_action_tx_status(
3397 wpa_s, data->tx_status.dst,
3398 data->tx_status.data,
3399 data->tx_status.data_len,
3400 data->tx_status.ack ?
3401 OFFCHANNEL_SEND_ACTION_SUCCESS :
3402 OFFCHANNEL_SEND_ACTION_NO_ACK);
3403 #endif /* CONFIG_OFFCHANNEL */
3406 #endif /* CONFIG_AP */
3407 #ifdef CONFIG_OFFCHANNEL
3408 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3409 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3411 * Catch TX status events for Action frames we sent via group
3412 * interface in GO mode.
3414 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3415 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3416 os_memcmp(wpa_s->parent->pending_action_dst,
3417 data->tx_status.dst, ETH_ALEN) == 0) {
3418 offchannel_send_action_tx_status(
3419 wpa_s->parent, data->tx_status.dst,
3420 data->tx_status.data,
3421 data->tx_status.data_len,
3422 data->tx_status.ack ?
3423 OFFCHANNEL_SEND_ACTION_SUCCESS :
3424 OFFCHANNEL_SEND_ACTION_NO_ACK);
3427 #endif /* CONFIG_OFFCHANNEL */
3429 switch (data->tx_status.type) {
3430 case WLAN_FC_TYPE_MGMT:
3431 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3432 data->tx_status.data_len,
3433 data->tx_status.stype,
3434 data->tx_status.ack);
3436 case WLAN_FC_TYPE_DATA:
3437 ap_tx_status(wpa_s, data->tx_status.dst,
3438 data->tx_status.data,
3439 data->tx_status.data_len,
3440 data->tx_status.ack);
3443 #endif /* CONFIG_AP */
3446 case EVENT_EAPOL_TX_STATUS:
3447 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3448 data->eapol_tx_status.data,
3449 data->eapol_tx_status.data_len,
3450 data->eapol_tx_status.ack);
3452 case EVENT_DRIVER_CLIENT_POLL_OK:
3453 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3455 case EVENT_RX_FROM_UNKNOWN:
3456 if (wpa_s->ap_iface == NULL)
3458 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3459 data->rx_from_unknown.wds);
3461 case EVENT_CH_SWITCH:
3464 if (!wpa_s->ap_iface) {
3465 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3466 "event in non-AP mode");
3470 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3471 data->ch_switch.ht_enabled,
3472 data->ch_switch.ch_offset,
3473 data->ch_switch.ch_width,
3474 data->ch_switch.cf1,
3475 data->ch_switch.cf2);
3477 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
3480 case EVENT_DFS_RADAR_DETECTED:
3482 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3484 case EVENT_DFS_CAC_STARTED:
3486 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3488 case EVENT_DFS_CAC_FINISHED:
3490 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3492 case EVENT_DFS_CAC_ABORTED:
3494 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3496 case EVENT_DFS_NOP_FINISHED:
3498 wpas_event_dfs_cac_nop_finished(wpa_s,
3501 #endif /* NEED_AP_MLME */
3502 #endif /* CONFIG_AP */
3503 case EVENT_RX_MGMT: {
3505 const struct ieee80211_mgmt *mgmt;
3507 #ifdef CONFIG_TESTING_OPTIONS
3508 if (wpa_s->ext_mgmt_frame_handling) {
3509 struct rx_mgmt *rx = &data->rx_mgmt;
3510 size_t hex_len = 2 * rx->frame_len + 1;
3511 char *hex = os_malloc(hex_len);
3513 wpa_snprintf_hex(hex, hex_len,
3514 rx->frame, rx->frame_len);
3515 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3516 rx->freq, rx->datarate, rx->ssi_signal,
3522 #endif /* CONFIG_TESTING_OPTIONS */
3524 mgmt = (const struct ieee80211_mgmt *)
3525 data->rx_mgmt.frame;
3526 fc = le_to_host16(mgmt->frame_control);
3527 stype = WLAN_FC_GET_STYPE(fc);
3530 if (wpa_s->ap_iface == NULL) {
3531 #endif /* CONFIG_AP */
3533 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3534 data->rx_mgmt.frame_len > 24) {
3535 const u8 *src = mgmt->sa;
3536 const u8 *ie = mgmt->u.probe_req.variable;
3537 size_t ie_len = data->rx_mgmt.frame_len -
3538 (mgmt->u.probe_req.variable -
3539 data->rx_mgmt.frame);
3540 wpas_p2p_probe_req_rx(
3541 wpa_s, src, mgmt->da,
3542 mgmt->bssid, ie, ie_len,
3544 data->rx_mgmt.ssi_signal);
3547 #endif /* CONFIG_P2P */
3548 #ifdef CONFIG_IBSS_RSN
3549 if (wpa_s->current_ssid &&
3550 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3551 stype == WLAN_FC_STYPE_AUTH &&
3552 data->rx_mgmt.frame_len >= 30) {
3553 wpa_supplicant_event_ibss_auth(wpa_s, data);
3556 #endif /* CONFIG_IBSS_RSN */
3558 if (stype == WLAN_FC_STYPE_ACTION) {
3559 wpas_event_rx_mgmt_action(
3560 wpa_s, data->rx_mgmt.frame,
3561 data->rx_mgmt.frame_len,
3563 data->rx_mgmt.ssi_signal);
3568 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3572 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3573 "management frame in non-AP mode");
3578 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3579 data->rx_mgmt.frame_len > 24) {
3580 const u8 *ie = mgmt->u.probe_req.variable;
3581 size_t ie_len = data->rx_mgmt.frame_len -
3582 (mgmt->u.probe_req.variable -
3583 data->rx_mgmt.frame);
3585 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3586 mgmt->bssid, ie, ie_len,
3587 data->rx_mgmt.ssi_signal);
3590 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3591 #endif /* CONFIG_AP */
3594 case EVENT_RX_PROBE_REQ:
3595 if (data->rx_probe_req.sa == NULL ||
3596 data->rx_probe_req.ie == NULL)
3599 if (wpa_s->ap_iface) {
3600 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3601 data->rx_probe_req.sa,
3602 data->rx_probe_req.da,
3603 data->rx_probe_req.bssid,
3604 data->rx_probe_req.ie,
3605 data->rx_probe_req.ie_len,
3606 data->rx_probe_req.ssi_signal);
3609 #endif /* CONFIG_AP */
3610 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3611 data->rx_probe_req.da,
3612 data->rx_probe_req.bssid,
3613 data->rx_probe_req.ie,
3614 data->rx_probe_req.ie_len,
3616 data->rx_probe_req.ssi_signal);
3618 case EVENT_REMAIN_ON_CHANNEL:
3619 #ifdef CONFIG_OFFCHANNEL
3620 offchannel_remain_on_channel_cb(
3621 wpa_s, data->remain_on_channel.freq,
3622 data->remain_on_channel.duration);
3623 #endif /* CONFIG_OFFCHANNEL */
3624 wpas_p2p_remain_on_channel_cb(
3625 wpa_s, data->remain_on_channel.freq,
3626 data->remain_on_channel.duration);
3628 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3629 #ifdef CONFIG_OFFCHANNEL
3630 offchannel_cancel_remain_on_channel_cb(
3631 wpa_s, data->remain_on_channel.freq);
3632 #endif /* CONFIG_OFFCHANNEL */
3633 wpas_p2p_cancel_remain_on_channel_cb(
3634 wpa_s, data->remain_on_channel.freq);
3636 case EVENT_EAPOL_RX:
3637 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3638 data->eapol_rx.data,
3639 data->eapol_rx.data_len);
3641 case EVENT_SIGNAL_CHANGE:
3642 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3643 "above=%d signal=%d noise=%d txrate=%d",
3644 data->signal_change.above_threshold,
3645 data->signal_change.current_signal,
3646 data->signal_change.current_noise,
3647 data->signal_change.current_txrate);
3648 wpa_bss_update_level(wpa_s->current_bss,
3649 data->signal_change.current_signal);
3650 bgscan_notify_signal_change(
3651 wpa_s, data->signal_change.above_threshold,
3652 data->signal_change.current_signal,
3653 data->signal_change.current_noise,
3654 data->signal_change.current_txrate);
3656 case EVENT_INTERFACE_ENABLED:
3657 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3658 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3659 wpa_supplicant_update_mac_addr(wpa_s);
3660 if (wpa_s->p2p_mgmt) {
3661 wpa_supplicant_set_state(wpa_s,
3667 if (!wpa_s->ap_iface) {
3668 wpa_supplicant_set_state(wpa_s,
3670 wpa_s->scan_req = NORMAL_SCAN_REQ;
3671 wpa_supplicant_req_scan(wpa_s, 0, 0);
3673 wpa_supplicant_set_state(wpa_s,
3675 #else /* CONFIG_AP */
3676 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3677 wpa_supplicant_req_scan(wpa_s, 0, 0);
3678 #endif /* CONFIG_AP */
3681 case EVENT_INTERFACE_DISABLED:
3682 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3684 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3685 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3686 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3688 * Mark interface disabled if this happens to end up not
3689 * being removed as a separate P2P group interface.
3691 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3693 * The interface was externally disabled. Remove
3694 * it assuming an external entity will start a
3695 * new session if needed.
3697 if (wpa_s->current_ssid &&
3698 wpa_s->current_ssid->p2p_group)
3699 wpas_p2p_interface_unavailable(wpa_s);
3701 wpas_p2p_disconnect(wpa_s);
3703 * wpa_s instance may have been freed, so must not use
3708 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3709 p2p_in_progress(wpa_s->global->p2p) > 1) {
3710 /* This radio work will be cancelled, so clear P2P
3713 p2p_stop_find(wpa_s->global->p2p);
3715 #endif /* CONFIG_P2P */
3717 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3719 * Indicate disconnection to keep ctrl_iface events
3722 wpa_supplicant_event_disassoc(
3723 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3725 wpa_supplicant_mark_disassoc(wpa_s);
3726 radio_remove_works(wpa_s, NULL, 0);
3728 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3730 case EVENT_CHANNEL_LIST_CHANGED:
3731 wpa_supplicant_update_channel_list(
3732 wpa_s, &data->channel_list_changed);
3734 case EVENT_INTERFACE_UNAVAILABLE:
3735 wpas_p2p_interface_unavailable(wpa_s);
3737 case EVENT_BEST_CHANNEL:
3738 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3740 data->best_chan.freq_24, data->best_chan.freq_5,
3741 data->best_chan.freq_overall);
3742 wpa_s->best_24_freq = data->best_chan.freq_24;
3743 wpa_s->best_5_freq = data->best_chan.freq_5;
3744 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3745 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3746 data->best_chan.freq_5,
3747 data->best_chan.freq_overall);
3749 case EVENT_UNPROT_DEAUTH:
3750 wpa_supplicant_event_unprot_deauth(wpa_s,
3751 &data->unprot_deauth);
3753 case EVENT_UNPROT_DISASSOC:
3754 wpa_supplicant_event_unprot_disassoc(wpa_s,
3755 &data->unprot_disassoc);
3757 case EVENT_STATION_LOW_ACK:
3759 if (wpa_s->ap_iface && data)
3760 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3761 data->low_ack.addr);
3762 #endif /* CONFIG_AP */
3765 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3766 data->low_ack.addr);
3767 #endif /* CONFIG_TDLS */
3769 case EVENT_IBSS_PEER_LOST:
3770 #ifdef CONFIG_IBSS_RSN
3771 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3772 #endif /* CONFIG_IBSS_RSN */
3774 case EVENT_DRIVER_GTK_REKEY:
3775 if (os_memcmp(data->driver_gtk_rekey.bssid,
3776 wpa_s->bssid, ETH_ALEN))
3780 wpa_sm_update_replay_ctr(wpa_s->wpa,
3781 data->driver_gtk_rekey.replay_ctr);
3783 case EVENT_SCHED_SCAN_STOPPED:
3785 wpa_s->sched_scanning = 0;
3786 resched = wpa_s->scanning;
3787 wpa_supplicant_notify_scanning(wpa_s, 0);
3789 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3793 * Start a new sched scan to continue searching for more SSIDs
3794 * either if timed out or PNO schedule scan is pending.
3796 if (wpa_s->sched_scan_timed_out) {
3797 wpa_supplicant_req_sched_scan(wpa_s);
3798 } else if (wpa_s->pno_sched_pending) {
3799 wpa_s->pno_sched_pending = 0;
3800 wpas_start_pno(wpa_s);
3801 } else if (resched) {
3802 wpa_supplicant_req_scan(wpa_s, 0, 0);
3806 case EVENT_WPS_BUTTON_PUSHED:
3808 wpas_wps_start_pbc(wpa_s, NULL, 0);
3809 #endif /* CONFIG_WPS */
3811 case EVENT_AVOID_FREQUENCIES:
3812 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3814 case EVENT_CONNECT_FAILED_REASON:
3816 if (!wpa_s->ap_iface || !data)
3818 hostapd_event_connect_failed_reason(
3819 wpa_s->ap_iface->bss[0],
3820 data->connect_failed_reason.addr,
3821 data->connect_failed_reason.code);
3822 #endif /* CONFIG_AP */
3824 case EVENT_NEW_PEER_CANDIDATE:
3826 if (!wpa_s->ifmsh || !data)
3828 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3829 data->mesh_peer.ies,
3830 data->mesh_peer.ie_len);
3831 #endif /* CONFIG_MESH */
3834 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);