2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/ieee802_11_common.h"
31 #include "crypto/random.h"
32 #include "blacklist.h"
33 #include "wpas_glue.h"
34 #include "wps_supplicant.h"
37 #include "gas_query.h"
38 #include "p2p_supplicant.h"
44 #include "offchannel.h"
45 #include "interworking.h"
51 #ifndef CONFIG_NO_SCAN_PROCESSING
52 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
53 int new_scan, int own_request);
54 #endif /* CONFIG_NO_SCAN_PROCESSING */
57 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
60 struct os_reltime now;
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
66 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
76 * wpas_reenabled_network_time - Time until first network is re-enabled
77 * @wpa_s: Pointer to wpa_supplicant data
78 * Returns: If all enabled networks are temporarily disabled, returns the time
79 * (in sec) until the first network is re-enabled. Otherwise returns 0.
81 * This function is used in case all enabled networks are temporarily disabled,
82 * in which case it returns the time (in sec) that the first network will be
83 * re-enabled. The function assumes that at least one network is enabled.
85 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
87 struct wpa_ssid *ssid;
88 int disabled_for, res = 0;
90 #ifdef CONFIG_INTERWORKING
91 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
94 #endif /* CONFIG_INTERWORKING */
96 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
100 disabled_for = wpas_temp_disabled(wpa_s, ssid);
104 if (!res || disabled_for < res)
112 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
114 struct wpa_supplicant *wpa_s = eloop_ctx;
116 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
119 wpa_dbg(wpa_s, MSG_DEBUG,
120 "Try to associate due to network getting re-enabled");
121 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
122 wpa_supplicant_cancel_sched_scan(wpa_s);
123 wpa_supplicant_req_scan(wpa_s, 0, 0);
128 static struct wpa_bss * wpa_supplicant_get_new_bss(
129 struct wpa_supplicant *wpa_s, const u8 *bssid)
131 struct wpa_bss *bss = NULL;
132 struct wpa_ssid *ssid = wpa_s->current_ssid;
134 if (ssid->ssid_len > 0)
135 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
137 bss = wpa_bss_get_bssid(wpa_s, bssid);
143 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
145 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148 wpa_supplicant_update_scan_results(wpa_s);
150 /* Get the BSS from the new scan results */
151 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
155 wpa_s->current_bss = bss;
159 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
161 struct wpa_ssid *ssid, *old_ssid;
162 u8 drv_ssid[SSID_MAX_LEN];
166 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
167 wpa_supplicant_update_current_bss(wpa_s);
169 if (wpa_s->current_ssid->ssid_len == 0)
170 return 0; /* current profile still in use */
171 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
173 wpa_msg(wpa_s, MSG_INFO,
174 "Failed to read SSID from driver");
175 return 0; /* try to use current profile */
179 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
180 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
182 return 0; /* current profile still in use */
184 wpa_msg(wpa_s, MSG_DEBUG,
185 "Driver-initiated BSS selection changed the SSID to %s",
186 wpa_ssid_txt(drv_ssid, drv_ssid_len));
187 /* continue selecting a new network profile */
190 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
192 ssid = wpa_supplicant_get_ssid(wpa_s);
194 wpa_msg(wpa_s, MSG_INFO,
195 "No network configuration found for the current AP");
199 if (wpas_network_disabled(wpa_s, ssid)) {
200 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
204 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
205 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
206 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
210 res = wpas_temp_disabled(wpa_s, ssid);
212 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
213 "disabled for %d second(s)", res);
217 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
219 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
221 size_t wpa_ie_len = sizeof(wpa_ie);
222 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
223 wpa_ie, &wpa_ie_len) < 0)
224 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
226 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
229 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
230 eapol_sm_invalidate_cached_session(wpa_s->eapol);
231 old_ssid = wpa_s->current_ssid;
232 wpa_s->current_ssid = ssid;
234 wpa_supplicant_update_current_bss(wpa_s);
236 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
237 wpa_supplicant_initiate_eapol(wpa_s);
238 if (old_ssid != wpa_s->current_ssid)
239 wpas_notify_network_changed(wpa_s);
245 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
247 struct wpa_supplicant *wpa_s = eloop_ctx;
249 if (wpa_s->countermeasures) {
250 wpa_s->countermeasures = 0;
251 wpa_drv_set_countermeasures(wpa_s, 0);
252 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
255 * It is possible that the device is sched scanning, which means
256 * that a connection attempt will be done only when we receive
257 * scan results. However, in this case, it would be preferable
258 * to scan and connect immediately, so cancel the sched_scan and
259 * issue a regular scan flow.
261 wpa_supplicant_cancel_sched_scan(wpa_s);
262 wpa_supplicant_req_scan(wpa_s, 0, 0);
267 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
271 wnm_bss_keep_alive_deinit(wpa_s);
273 #ifdef CONFIG_IBSS_RSN
274 ibss_rsn_deinit(wpa_s->ibss_rsn);
275 wpa_s->ibss_rsn = NULL;
276 #endif /* CONFIG_IBSS_RSN */
279 wpa_supplicant_ap_deinit(wpa_s);
280 #endif /* CONFIG_AP */
282 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
285 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
286 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
287 os_memset(wpa_s->bssid, 0, ETH_ALEN);
288 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
289 sme_clear_on_disassoc(wpa_s);
290 wpa_s->current_bss = NULL;
291 wpa_s->assoc_freq = 0;
294 wpas_notify_bssid_changed(wpa_s);
296 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
297 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
298 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
299 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
300 wpa_s->ap_ies_from_associnfo = 0;
301 wpa_s->current_ssid = NULL;
302 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
305 wpas_rrm_reset(wpa_s);
306 wpa_s->wnmsleep_used = 0;
310 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
312 struct wpa_ie_data ie;
316 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
320 for (i = 0; i < ie.num_pmkid; i++) {
321 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
322 ie.pmkid + i * PMKID_LEN,
324 if (pmksa_set == 0) {
325 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
330 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
331 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
335 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
336 union wpa_event_data *data)
339 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
343 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
344 " index=%d preauth=%d",
345 MAC2STR(data->pmkid_candidate.bssid),
346 data->pmkid_candidate.index,
347 data->pmkid_candidate.preauth);
349 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
350 data->pmkid_candidate.index,
351 data->pmkid_candidate.preauth);
355 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
357 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
358 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
361 #ifdef IEEE8021X_EAPOL
362 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
363 wpa_s->current_ssid &&
364 !(wpa_s->current_ssid->eapol_flags &
365 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
367 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
368 * plaintext or static WEP keys). */
371 #endif /* IEEE8021X_EAPOL */
378 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
379 * @wpa_s: pointer to wpa_supplicant data
380 * @ssid: Configuration data for the network
381 * Returns: 0 on success, -1 on failure
383 * This function is called when starting authentication with a network that is
384 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
386 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
387 struct wpa_ssid *ssid)
389 #ifdef IEEE8021X_EAPOL
391 int aka = 0, sim = 0;
393 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
394 wpa_s->scard != NULL || wpa_s->conf->external_sim)
397 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
401 struct eap_method_type *eap = ssid->eap.eap_methods;
402 while (eap->vendor != EAP_VENDOR_IETF ||
403 eap->method != EAP_TYPE_NONE) {
404 if (eap->vendor == EAP_VENDOR_IETF) {
405 if (eap->method == EAP_TYPE_SIM)
407 else if (eap->method == EAP_TYPE_AKA ||
408 eap->method == EAP_TYPE_AKA_PRIME)
415 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
418 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
423 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
424 "use SIM, but neither EAP-SIM nor EAP-AKA are "
429 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
430 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
432 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
433 if (wpa_s->scard == NULL) {
434 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
438 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
439 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
440 #endif /* PCSC_FUNCS */
441 #endif /* IEEE8021X_EAPOL */
447 #ifndef CONFIG_NO_SCAN_PROCESSING
449 static int has_wep_key(struct wpa_ssid *ssid)
453 for (i = 0; i < NUM_WEP_KEYS; i++) {
454 if (ssid->wep_key_len[i])
462 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
463 struct wpa_ssid *ssid)
467 if (ssid->mixed_cell)
471 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
473 #endif /* CONFIG_WPS */
475 if (has_wep_key(ssid))
478 #ifdef IEEE8021X_EAPOL
479 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
480 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
481 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
483 #endif /* IEEE8021X_EAPOL */
485 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
488 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
491 if (bss->caps & IEEE80211_CAP_PRIVACY)
497 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
498 struct wpa_ssid *ssid,
501 struct wpa_ie_data ie;
503 const u8 *rsn_ie, *wpa_ie;
507 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
511 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
512 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
513 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
514 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
515 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
517 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
518 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
521 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
528 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
530 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
535 if (!(ie.proto & ssid->proto)) {
536 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
541 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
542 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
547 if (!(ie.group_cipher & ssid->group_cipher)) {
548 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
553 if (!(ie.key_mgmt & ssid->key_mgmt)) {
554 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
559 #ifdef CONFIG_IEEE80211W
560 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
561 wpas_get_ssid_pmf(wpa_s, ssid) ==
562 MGMT_FRAME_PROTECTION_REQUIRED) {
563 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
567 #endif /* CONFIG_IEEE80211W */
569 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
573 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
574 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
577 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
578 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
584 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
586 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
591 if (!(ie.proto & ssid->proto)) {
592 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
597 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
598 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
603 if (!(ie.group_cipher & ssid->group_cipher)) {
604 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
609 if (!(ie.key_mgmt & ssid->key_mgmt)) {
610 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
615 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
619 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
621 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
625 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
626 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
627 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
631 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
632 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
633 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
637 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
638 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
642 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
649 static int freq_allowed(int *freqs, int freq)
656 for (i = 0; freqs[i]; i++)
657 if (freqs[i] == freq)
663 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
665 const struct hostapd_hw_modes *mode = NULL, *modes;
666 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
671 return 1; /* Cannot do matching without knowing band */
673 modes = wpa_s->hw.modes;
676 * The driver does not provide any additional information
677 * about the utilized hardware, so allow the connection attempt
683 for (i = 0; i < wpa_s->hw.num_modes; i++) {
684 for (j = 0; j < modes[i].num_channels; j++) {
685 int freq = modes[i].channels[j].freq;
686 if (freq == bss->freq) {
688 mode->mode == HOSTAPD_MODE_IEEE80211G)
689 break; /* do not allow 802.11b replace
700 for (i = 0; i < (int) sizeof(scan_ie); i++) {
701 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
705 for (j = 2; j < rate_ie[1] + 2; j++) {
706 int flagged = !!(rate_ie[j] & 0x80);
707 int r = (rate_ie[j] & 0x7f) * 5;
710 * IEEE Std 802.11n-2009 7.3.2.2:
711 * The new BSS Membership selector value is encoded
712 * like a legacy basic rate, but it is not a rate and
713 * only indicates if the BSS members are required to
714 * support the mandatory features of Clause 20 [HT PHY]
715 * in order to join the BSS.
717 if (flagged && ((rate_ie[j] & 0x7f) ==
718 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
719 if (!ht_supported(mode)) {
720 wpa_dbg(wpa_s, MSG_DEBUG,
721 " hardware does not support "
728 /* There's also a VHT selector for 802.11ac */
729 if (flagged && ((rate_ie[j] & 0x7f) ==
730 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
731 if (!vht_supported(mode)) {
732 wpa_dbg(wpa_s, MSG_DEBUG,
733 " hardware does not support "
743 /* check for legacy basic rates */
744 for (k = 0; k < mode->num_rates; k++) {
745 if (mode->rates[k] == r)
748 if (k == mode->num_rates) {
750 * IEEE Std 802.11-2007 7.3.2.2 demands that in
751 * order to join a BSS all required rates
752 * have to be supported by the hardware.
754 wpa_dbg(wpa_s, MSG_DEBUG,
755 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
757 bss->freq, mode->mode, mode->num_rates);
768 * Test whether BSS is in an ESS.
769 * This is done differently in DMG (60 GHz) and non-DMG bands
771 static int bss_is_ess(struct wpa_bss *bss)
773 if (bss_is_dmg(bss)) {
774 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
775 IEEE80211_CAP_DMG_AP;
778 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
783 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
787 for (i = 0; i < ETH_ALEN; i++) {
788 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
795 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
799 for (i = 0; i < num; i++) {
800 const u8 *a = list + i * ETH_ALEN * 2;
801 const u8 *m = a + ETH_ALEN;
803 if (match_mac_mask(a, addr, m))
810 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
811 int i, struct wpa_bss *bss,
812 struct wpa_ssid *group,
815 u8 wpa_ie_len, rsn_ie_len;
817 struct wpa_blacklist *e;
819 struct wpa_ssid *ssid;
822 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
823 wpa_ie_len = ie ? ie[1] : 0;
825 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
826 rsn_ie_len = ie ? ie[1] : 0;
828 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
831 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
832 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
833 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
834 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
835 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
836 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
837 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
839 osen ? " osen=1" : "");
841 e = wpa_blacklist_get(wpa_s, bss->bssid);
844 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
846 * When only a single network is enabled, we can
847 * trigger blacklisting on the first failure. This
848 * should not be done with multiple enabled networks to
849 * avoid getting forced to move into a worse ESS on
850 * single error if there are no other BSSes of the
855 if (e->count > limit) {
856 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
857 "(count=%d limit=%d)", e->count, limit);
862 if (bss->ssid_len == 0) {
863 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
867 if (disallowed_bssid(wpa_s, bss->bssid)) {
868 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
872 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
873 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
877 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
879 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
880 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
883 if (wpas_network_disabled(wpa_s, ssid)) {
884 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
888 res = wpas_temp_disabled(wpa_s, ssid);
890 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
891 "temporarily for %d second(s)", res);
896 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
897 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
902 if (wpa && ssid->ssid_len == 0 &&
903 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
906 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
907 /* Only allow wildcard SSID match if an AP
908 * advertises active WPS operation that matches
911 if (ssid->ssid_len == 0 &&
912 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
915 #endif /* CONFIG_WPS */
917 if (ssid->bssid_set && ssid->ssid_len == 0 &&
918 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
922 (bss->ssid_len != ssid->ssid_len ||
923 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
924 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
928 if (ssid->bssid_set &&
929 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
930 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
934 /* check blacklist */
935 if (ssid->num_bssid_blacklist &&
936 addr_in_list(bss->bssid, ssid->bssid_blacklist,
937 ssid->num_bssid_blacklist)) {
938 wpa_dbg(wpa_s, MSG_DEBUG,
939 " skip - BSSID blacklisted");
943 /* if there is a whitelist, only accept those APs */
944 if (ssid->num_bssid_whitelist &&
945 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
946 ssid->num_bssid_whitelist)) {
947 wpa_dbg(wpa_s, MSG_DEBUG,
948 " skip - BSSID not in whitelist");
952 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
956 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
957 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
958 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
959 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
964 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
966 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
970 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
971 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
976 if (!wpa_supplicant_match_privacy(bss, ssid)) {
977 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
982 if (!bss_is_ess(bss)) {
983 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
987 if (!freq_allowed(ssid->freq_list, bss->freq)) {
988 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
993 if (!rate_match(wpa_s, bss)) {
994 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1000 if (ssid->p2p_group &&
1001 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1002 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1003 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1007 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1008 struct wpabuf *p2p_ie;
1009 u8 dev_addr[ETH_ALEN];
1011 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1013 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1016 p2p_ie = wpa_bss_get_vendor_ie_multi(
1017 bss, P2P_IE_VENDOR_TYPE);
1018 if (p2p_ie == NULL) {
1019 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1023 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1024 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1026 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1027 wpabuf_free(p2p_ie);
1030 wpabuf_free(p2p_ie);
1034 * TODO: skip the AP if its P2P IE has Group Formation
1035 * bit set in the P2P Group Capability Bitmap and we
1036 * are not in Group Formation with that device.
1038 #endif /* CONFIG_P2P */
1040 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1042 struct os_reltime diff;
1044 os_reltime_sub(&wpa_s->scan_min_time,
1045 &bss->last_update, &diff);
1046 wpa_dbg(wpa_s, MSG_DEBUG,
1047 " skip - scan result not recent enough (%u.%06u seconds too old)",
1048 (unsigned int) diff.sec,
1049 (unsigned int) diff.usec);
1053 /* Matching configuration found */
1057 /* No matching configuration found */
1062 static struct wpa_bss *
1063 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1064 struct wpa_ssid *group,
1065 struct wpa_ssid **selected_ssid,
1066 int only_first_ssid)
1070 if (only_first_ssid)
1071 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1074 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1077 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1078 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1079 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1081 if (!*selected_ssid)
1083 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1085 MAC2STR(bss->bssid),
1086 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1094 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1095 struct wpa_ssid **selected_ssid)
1097 struct wpa_bss *selected = NULL;
1099 struct wpa_ssid *next_ssid = NULL;
1100 struct wpa_ssid *ssid;
1102 if (wpa_s->last_scan_res == NULL ||
1103 wpa_s->last_scan_res_used == 0)
1104 return NULL; /* no scan results from last update */
1106 if (wpa_s->next_ssid) {
1107 /* check that next_ssid is still valid */
1108 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1109 if (ssid == wpa_s->next_ssid)
1113 wpa_s->next_ssid = NULL;
1116 while (selected == NULL) {
1117 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1118 if (next_ssid && next_ssid->priority ==
1119 wpa_s->conf->pssid[prio]->priority) {
1120 selected = wpa_supplicant_select_bss(
1121 wpa_s, next_ssid, selected_ssid, 1);
1125 selected = wpa_supplicant_select_bss(
1126 wpa_s, wpa_s->conf->pssid[prio],
1132 if (selected == NULL && wpa_s->blacklist &&
1133 !wpa_s->countermeasures) {
1134 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1135 "blacklist and try again");
1136 wpa_blacklist_clear(wpa_s);
1137 wpa_s->blacklist_cleared++;
1138 } else if (selected == NULL)
1142 ssid = *selected_ssid;
1143 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1144 !ssid->passphrase && !ssid->ext_psk) {
1145 const char *field_name, *txt = NULL;
1147 wpa_dbg(wpa_s, MSG_DEBUG,
1148 "PSK/passphrase not yet available for the selected network");
1150 wpas_notify_network_request(wpa_s, ssid,
1151 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1153 field_name = wpa_supplicant_ctrl_req_to_string(
1154 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1155 if (field_name == NULL)
1158 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1167 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1168 int timeout_sec, int timeout_usec)
1170 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1172 * No networks are enabled; short-circuit request so
1173 * we don't wait timeout seconds before transitioning
1174 * to INACTIVE state.
1176 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1177 "since there are no enabled networks");
1178 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1182 wpa_s->scan_for_connection = 1;
1183 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1187 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1188 struct wpa_bss *selected,
1189 struct wpa_ssid *ssid)
1191 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1192 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1193 "PBC session overlap");
1194 wpas_notify_wps_event_pbc_overlap(wpa_s);
1196 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1197 wpa_s->p2p_in_provisioning) {
1198 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1202 #endif /* CONFIG_P2P */
1205 wpas_wps_pbc_overlap(wpa_s);
1206 wpas_wps_cancel(wpa_s);
1207 #endif /* CONFIG_WPS */
1211 wpa_msg(wpa_s, MSG_DEBUG,
1212 "Considering connect request: reassociate: %d selected: "
1213 MACSTR " bssid: " MACSTR " pending: " MACSTR
1214 " wpa_state: %s ssid=%p current_ssid=%p",
1215 wpa_s->reassociate, MAC2STR(selected->bssid),
1216 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1217 wpa_supplicant_state_txt(wpa_s->wpa_state),
1218 ssid, wpa_s->current_ssid);
1221 * Do not trigger new association unless the BSSID has changed or if
1222 * reassociation is requested. If we are in process of associating with
1223 * the selected BSSID, do not trigger new attempt.
1225 if (wpa_s->reassociate ||
1226 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1227 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1228 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1229 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1230 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1232 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1233 ssid != wpa_s->current_ssid)))) {
1234 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1235 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1238 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1239 MAC2STR(selected->bssid));
1240 wpa_supplicant_associate(wpa_s, selected, ssid);
1242 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1243 "connect with the selected AP");
1250 static struct wpa_ssid *
1251 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1254 struct wpa_ssid *ssid;
1256 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1257 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1259 if (wpas_network_disabled(wpa_s, ssid))
1261 if (ssid->mode == IEEE80211_MODE_IBSS ||
1262 ssid->mode == IEEE80211_MODE_AP ||
1263 ssid->mode == IEEE80211_MODE_MESH)
1271 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1272 * on BSS added and BSS changed events */
1273 static void wpa_supplicant_rsn_preauth_scan_results(
1274 struct wpa_supplicant *wpa_s)
1276 struct wpa_bss *bss;
1278 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1281 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1282 const u8 *ssid, *rsn;
1284 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1288 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1292 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1298 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1299 struct wpa_bss *selected,
1300 struct wpa_ssid *ssid)
1302 struct wpa_bss *current_bss = NULL;
1303 #ifndef CONFIG_NO_ROAMING
1305 #endif /* CONFIG_NO_ROAMING */
1307 if (wpa_s->reassociate)
1308 return 1; /* explicit request to reassociate */
1309 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1310 return 1; /* we are not associated; continue */
1311 if (wpa_s->current_ssid == NULL)
1312 return 1; /* unknown current SSID */
1313 if (wpa_s->current_ssid != ssid)
1314 return 1; /* different network block */
1316 if (wpas_driver_bss_selection(wpa_s))
1317 return 0; /* Driver-based roaming */
1319 if (wpa_s->current_ssid->ssid)
1320 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1321 wpa_s->current_ssid->ssid,
1322 wpa_s->current_ssid->ssid_len);
1324 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1327 return 1; /* current BSS not seen in scan results */
1329 if (current_bss == selected)
1332 if (selected->last_update_idx > current_bss->last_update_idx)
1333 return 1; /* current BSS not seen in the last scan */
1335 #ifndef CONFIG_NO_ROAMING
1336 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1337 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1338 " level=%d snr=%d est_throughput=%u",
1339 MAC2STR(current_bss->bssid), current_bss->level,
1340 current_bss->snr, current_bss->est_throughput);
1341 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1342 " level=%d snr=%d est_throughput=%u",
1343 MAC2STR(selected->bssid), selected->level,
1344 selected->snr, selected->est_throughput);
1346 if (wpa_s->current_ssid->bssid_set &&
1347 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1349 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1350 "has preferred BSSID");
1354 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1355 wpa_dbg(wpa_s, MSG_DEBUG,
1356 "Allow reassociation - selected BSS has better estimated throughput");
1360 if (current_bss->level < 0 && current_bss->level > selected->level) {
1361 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1367 if (current_bss->level < 0) {
1368 if (current_bss->level < -85)
1370 else if (current_bss->level < -80)
1372 else if (current_bss->level < -75)
1374 else if (current_bss->level < -70)
1379 if (abs(current_bss->level - selected->level) < min_diff) {
1380 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1386 #else /* CONFIG_NO_ROAMING */
1388 #endif /* CONFIG_NO_ROAMING */
1392 /* Return != 0 if no scan results could be fetched or if scan results should not
1393 * be shared with other virtual interfaces. */
1394 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1395 union wpa_event_data *data,
1398 struct wpa_scan_results *scan_res = NULL;
1401 #ifndef CONFIG_NO_RANDOM_POOL
1403 #endif /* CONFIG_NO_RANDOM_POOL */
1406 if (wpa_s->ap_iface)
1408 #endif /* CONFIG_AP */
1410 wpa_supplicant_notify_scanning(wpa_s, 0);
1412 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1413 data ? &data->scan_info :
1415 if (scan_res == NULL) {
1416 if (wpa_s->conf->ap_scan == 2 || ap ||
1417 wpa_s->scan_res_handler == scan_only_handler)
1421 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1423 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1425 goto scan_work_done;
1428 #ifndef CONFIG_NO_RANDOM_POOL
1429 num = scan_res->num;
1432 for (i = 0; i < num; i++) {
1434 struct wpa_scan_res *res = scan_res->res[i];
1435 buf[0] = res->bssid[5];
1436 buf[1] = res->qual & 0xff;
1437 buf[2] = res->noise & 0xff;
1438 buf[3] = res->level & 0xff;
1439 buf[4] = res->tsf & 0xff;
1440 random_add_randomness(buf, sizeof(buf));
1442 #endif /* CONFIG_NO_RANDOM_POOL */
1444 if (own_request && wpa_s->scan_res_handler &&
1445 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1446 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1447 struct wpa_scan_results *scan_res);
1449 scan_res_handler = wpa_s->scan_res_handler;
1450 wpa_s->scan_res_handler = NULL;
1451 scan_res_handler(wpa_s, scan_res);
1453 goto scan_work_done;
1457 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1459 if (wpa_s->ap_iface->scan_cb)
1460 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1461 #endif /* CONFIG_AP */
1462 goto scan_work_done;
1465 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1466 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1467 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1468 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1469 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1470 wpa_s->manual_scan_id);
1471 wpa_s->manual_scan_use_id = 0;
1473 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1475 wpas_notify_scan_results(wpa_s);
1477 wpas_notify_scan_done(wpa_s, 1);
1479 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1480 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1481 wpa_scan_results_free(scan_res);
1485 if (wnm_scan_process(wpa_s, 1) > 0)
1486 goto scan_work_done;
1488 if (sme_proc_obss_scan(wpa_s) > 0)
1489 goto scan_work_done;
1491 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1492 goto scan_work_done;
1494 if (autoscan_notify_scan(wpa_s, scan_res))
1495 goto scan_work_done;
1497 if (wpa_s->disconnected) {
1498 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1499 goto scan_work_done;
1502 if (!wpas_driver_bss_selection(wpa_s) &&
1503 bgscan_notify_scan(wpa_s, scan_res) == 1)
1504 goto scan_work_done;
1506 wpas_wps_update_ap_info(wpa_s, scan_res);
1508 wpa_scan_results_free(scan_res);
1510 if (wpa_s->scan_work) {
1511 struct wpa_radio_work *work = wpa_s->scan_work;
1512 wpa_s->scan_work = NULL;
1513 radio_work_done(work);
1516 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1519 wpa_scan_results_free(scan_res);
1520 if (wpa_s->scan_work) {
1521 struct wpa_radio_work *work = wpa_s->scan_work;
1522 wpa_s->scan_work = NULL;
1523 radio_work_done(work);
1529 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1530 int new_scan, int own_request)
1532 struct wpa_bss *selected;
1533 struct wpa_ssid *ssid = NULL;
1534 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1536 if (time_to_reenable > 0) {
1537 wpa_dbg(wpa_s, MSG_DEBUG,
1538 "Postpone network selection by %d seconds since all networks are disabled",
1540 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1541 eloop_register_timeout(time_to_reenable, 0,
1542 wpas_network_reenabled, wpa_s, NULL);
1546 if (wpa_s->p2p_mgmt)
1547 return 0; /* no normal connection on p2p_mgmt interface */
1549 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1553 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1556 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1560 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1561 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1565 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1567 * Do not notify other virtual radios of scan results since we do not
1568 * want them to start other associations at the same time.
1574 wpa_msg(wpa_s, MSG_INFO,
1575 "Avoiding join because we already joined a mesh group");
1578 #endif /* CONFIG_MESH */
1579 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1580 ssid = wpa_supplicant_pick_new_network(wpa_s);
1582 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1583 wpa_supplicant_associate(wpa_s, NULL, ssid);
1585 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1586 } else if (own_request) {
1588 * No SSID found. If SCAN results are as a result of
1589 * own scan request and not due to a scan request on
1590 * another shared interface, try another scan.
1592 int timeout_sec = wpa_s->scan_interval;
1593 int timeout_usec = 0;
1597 res = wpas_p2p_scan_no_go_seen(wpa_s);
1603 if (wpa_s->p2p_in_provisioning ||
1604 wpa_s->show_group_started ||
1605 wpa_s->p2p_in_invitation) {
1607 * Use shorter wait during P2P Provisioning
1608 * state and during P2P join-a-group operation
1609 * to speed up group formation.
1612 timeout_usec = 250000;
1613 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1617 #endif /* CONFIG_P2P */
1618 #ifdef CONFIG_INTERWORKING
1619 if (wpa_s->conf->auto_interworking &&
1620 wpa_s->conf->interworking &&
1621 wpa_s->conf->cred) {
1622 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1623 "start ANQP fetch since no matching "
1625 wpa_s->network_select = 1;
1626 wpa_s->auto_network_select = 1;
1627 interworking_start_fetch_anqp(wpa_s);
1630 #endif /* CONFIG_INTERWORKING */
1632 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1633 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1635 timeout_usec = 500000;
1636 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1640 #endif /* CONFIG_WPS */
1641 if (wpa_supplicant_req_sched_scan(wpa_s))
1642 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1645 wpa_msg_ctrl(wpa_s, MSG_INFO,
1646 WPA_EVENT_NETWORK_NOT_FOUND);
1653 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1654 union wpa_event_data *data)
1656 struct wpa_supplicant *ifs;
1659 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1662 * Interface may have been removed, so must not dereference
1669 * If no scan results could be fetched, then no need to
1670 * notify those interfaces that did not actually request
1671 * this scan. Similarly, if scan results started a new operation on this
1672 * interface, do not notify other interfaces to avoid concurrent
1673 * operations during a connection attempt.
1679 * Check other interfaces to see if they share the same radio. If
1680 * so, they get updated with this same scan info.
1682 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1685 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1686 "sibling", ifs->ifname);
1687 _wpa_supplicant_event_scan_results(ifs, data, 0);
1694 #endif /* CONFIG_NO_SCAN_PROCESSING */
1697 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1699 #ifdef CONFIG_NO_SCAN_PROCESSING
1701 #else /* CONFIG_NO_SCAN_PROCESSING */
1702 struct os_reltime now;
1704 if (wpa_s->last_scan_res_used == 0)
1707 os_get_reltime(&now);
1708 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1709 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1713 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1714 #endif /* CONFIG_NO_SCAN_PROCESSING */
1719 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1721 struct wpa_supplicant *wpa_s = eloop_ctx;
1723 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1726 if (!wpa_s->no_keep_alive) {
1727 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1728 MAC2STR(wpa_s->bssid));
1729 /* TODO: could skip this if normal data traffic has been sent */
1730 /* TODO: Consider using some more appropriate data frame for
1733 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1738 if (wpa_s->sme.bss_max_idle_period) {
1740 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1743 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1744 wnm_bss_keep_alive, wpa_s, NULL);
1746 #endif /* CONFIG_SME */
1750 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1751 const u8 *ies, size_t ies_len)
1753 struct ieee802_11_elems elems;
1758 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1762 if (elems.bss_max_idle_period) {
1764 wpa_s->sme.bss_max_idle_period =
1765 WPA_GET_LE16(elems.bss_max_idle_period);
1766 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1767 "TU)%s", wpa_s->sme.bss_max_idle_period,
1768 (elems.bss_max_idle_period[2] & 0x01) ?
1769 " (protected keep-live required)" : "");
1770 if (wpa_s->sme.bss_max_idle_period == 0)
1771 wpa_s->sme.bss_max_idle_period = 1;
1772 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1773 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1774 /* msec times 1000 */
1775 msec = wpa_s->sme.bss_max_idle_period * 1024;
1778 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1779 wnm_bss_keep_alive, wpa_s,
1783 #endif /* CONFIG_SME */
1786 #endif /* CONFIG_WNM */
1789 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1792 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1793 #endif /* CONFIG_WNM */
1797 #ifdef CONFIG_INTERWORKING
1799 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1804 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1805 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1807 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1814 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1815 const u8 *ies, size_t ies_len)
1817 struct ieee802_11_elems elems;
1822 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1825 if (elems.qos_map_set) {
1826 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1827 elems.qos_map_set_len);
1831 #endif /* CONFIG_INTERWORKING */
1834 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1835 union wpa_event_data *data)
1837 int l, len, found = 0, wpa_found, rsn_found;
1839 #ifdef CONFIG_IEEE80211R
1841 #endif /* CONFIG_IEEE80211R */
1843 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1844 if (data->assoc_info.req_ies)
1845 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1846 data->assoc_info.req_ies_len);
1847 if (data->assoc_info.resp_ies) {
1848 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1849 data->assoc_info.resp_ies_len);
1851 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1852 data->assoc_info.resp_ies_len);
1853 #endif /* CONFIG_TDLS */
1855 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1856 data->assoc_info.resp_ies_len);
1857 #endif /* CONFIG_WNM */
1858 #ifdef CONFIG_INTERWORKING
1859 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1860 data->assoc_info.resp_ies_len);
1861 #endif /* CONFIG_INTERWORKING */
1863 if (data->assoc_info.beacon_ies)
1864 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1865 data->assoc_info.beacon_ies,
1866 data->assoc_info.beacon_ies_len);
1867 if (data->assoc_info.freq)
1868 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1869 data->assoc_info.freq);
1871 p = data->assoc_info.req_ies;
1872 l = data->assoc_info.req_ies_len;
1874 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1875 while (p && l >= 2) {
1878 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1882 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1883 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1884 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1885 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1888 wpa_find_assoc_pmkid(wpa_s);
1894 if (!found && data->assoc_info.req_ies)
1895 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1897 #ifdef CONFIG_IEEE80211R
1899 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1900 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1901 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1902 data->assoc_info.resp_ies,
1903 data->assoc_info.resp_ies_len,
1905 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1906 "Reassociation Response failed");
1907 wpa_supplicant_deauthenticate(
1908 wpa_s, WLAN_REASON_INVALID_IE);
1913 p = data->assoc_info.resp_ies;
1914 l = data->assoc_info.resp_ies_len;
1916 #ifdef CONFIG_WPS_STRICT
1917 if (p && wpa_s->current_ssid &&
1918 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1920 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1922 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1923 "include WPS IE in (Re)Association Response");
1927 if (wps_validate_assoc_resp(wps) < 0) {
1929 wpa_supplicant_deauthenticate(
1930 wpa_s, WLAN_REASON_INVALID_IE);
1935 #endif /* CONFIG_WPS_STRICT */
1937 /* Go through the IEs and make a copy of the MDIE, if present. */
1938 while (p && l >= 2) {
1941 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1945 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1946 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1947 wpa_s->sme.ft_used = 1;
1948 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1949 MOBILITY_DOMAIN_ID_LEN);
1955 #endif /* CONFIG_SME */
1957 /* Process FT when SME is in the driver */
1958 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1959 wpa_ft_is_completed(wpa_s->wpa)) {
1960 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1961 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1962 data->assoc_info.resp_ies,
1963 data->assoc_info.resp_ies_len,
1965 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1966 "Reassociation Response failed");
1967 wpa_supplicant_deauthenticate(
1968 wpa_s, WLAN_REASON_INVALID_IE);
1971 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1974 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1975 data->assoc_info.resp_ies_len);
1976 #endif /* CONFIG_IEEE80211R */
1978 /* WPA/RSN IE from Beacon/ProbeResp */
1979 p = data->assoc_info.beacon_ies;
1980 l = data->assoc_info.beacon_ies_len;
1982 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1984 wpa_found = rsn_found = 0;
1985 while (p && l >= 2) {
1988 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1993 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1994 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1996 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2000 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2002 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2009 if (!wpa_found && data->assoc_info.beacon_ies)
2010 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2011 if (!rsn_found && data->assoc_info.beacon_ies)
2012 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2013 if (wpa_found || rsn_found)
2014 wpa_s->ap_ies_from_associnfo = 1;
2017 wpabuf_free(wpa_s->received_mb_ies);
2018 wpa_s->received_mb_ies = NULL;
2020 struct mb_ies_info mb_ies;
2022 wpa_printf(MSG_DEBUG, "Looking for MB IE");
2023 if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
2024 data->assoc_info.resp_ies_len))
2025 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
2027 #endif /* CONFIG_FST */
2029 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2030 wpa_s->assoc_freq != data->assoc_info.freq) {
2031 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2033 wpa_s->assoc_freq, data->assoc_info.freq);
2034 wpa_supplicant_update_scan_results(wpa_s);
2037 wpa_s->assoc_freq = data->assoc_info.freq;
2043 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2045 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2047 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2050 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2053 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2054 WPA_IE_VENDOR_TYPE);
2055 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2057 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2058 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2059 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2060 bss_rsn ? 2 + bss_rsn[1] : 0))
2067 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2068 union wpa_event_data *data)
2075 if (wpa_s->ap_iface) {
2078 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2079 data->assoc_info.addr,
2080 data->assoc_info.req_ies,
2081 data->assoc_info.req_ies_len,
2082 data->assoc_info.reassoc);
2085 #endif /* CONFIG_AP */
2087 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2089 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2090 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2093 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2094 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2095 wpa_supplicant_deauthenticate(
2096 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2100 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2101 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2102 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2103 MACSTR, MAC2STR(bssid));
2105 random_add_randomness(bssid, ETH_ALEN);
2106 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2107 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2108 wpas_notify_bssid_changed(wpa_s);
2110 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2111 wpa_clear_keys(wpa_s, bssid);
2113 if (wpa_supplicant_select_config(wpa_s) < 0) {
2114 wpa_supplicant_deauthenticate(
2115 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2120 if (wpa_s->conf->ap_scan == 1 &&
2121 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2122 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2123 wpa_msg(wpa_s, MSG_WARNING,
2124 "WPA/RSN IEs not updated");
2128 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2129 wpa_s->sme.prev_bssid_set = 1;
2130 wpa_s->sme.last_unprot_disconnect.sec = 0;
2131 #endif /* CONFIG_SME */
2133 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2134 if (wpa_s->current_ssid) {
2135 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2136 * initialized before association, but for other modes,
2137 * initialize PC/SC here, if the current configuration needs
2138 * smartcard or SIM/USIM. */
2139 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2141 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2143 l2_packet_notify_auth_start(wpa_s->l2);
2146 * Set portEnabled first to FALSE in order to get EAP state machine out
2147 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2148 * state machine may transit to AUTHENTICATING state based on obsolete
2149 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2150 * AUTHENTICATED without ever giving chance to EAP state machine to
2153 if (!ft_completed) {
2154 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2155 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2157 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2158 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2159 /* 802.1X::portControl = Auto */
2160 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2161 wpa_s->eapol_received = 0;
2162 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2163 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2164 (wpa_s->current_ssid &&
2165 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2166 if (wpa_s->current_ssid &&
2167 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2169 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2171 * Set the key after having received joined-IBSS event
2174 wpa_supplicant_set_wpa_none_key(wpa_s,
2175 wpa_s->current_ssid);
2177 wpa_supplicant_cancel_auth_timeout(wpa_s);
2178 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2179 } else if (!ft_completed) {
2180 /* Timeout for receiving the first EAPOL packet */
2181 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2183 wpa_supplicant_cancel_scan(wpa_s);
2185 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2186 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2188 * We are done; the driver will take care of RSN 4-way
2191 wpa_supplicant_cancel_auth_timeout(wpa_s);
2192 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2193 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2194 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2195 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2196 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2198 * The driver will take care of RSN 4-way handshake, so we need
2199 * to allow EAPOL supplicant to complete its work without
2200 * waiting for WPA supplicant.
2202 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2203 } else if (ft_completed) {
2205 * FT protocol completed - make sure EAPOL state machine ends
2206 * up in authenticated.
2208 wpa_supplicant_cancel_auth_timeout(wpa_s);
2209 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2210 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2211 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2214 wpa_s->last_eapol_matches_bssid = 0;
2216 if (wpa_s->pending_eapol_rx) {
2217 struct os_reltime now, age;
2218 os_get_reltime(&now);
2219 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2220 if (age.sec == 0 && age.usec < 100000 &&
2221 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2223 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2224 "frame that was received just before "
2225 "association notification");
2226 wpa_supplicant_rx_eapol(
2227 wpa_s, wpa_s->pending_eapol_rx_src,
2228 wpabuf_head(wpa_s->pending_eapol_rx),
2229 wpabuf_len(wpa_s->pending_eapol_rx));
2231 wpabuf_free(wpa_s->pending_eapol_rx);
2232 wpa_s->pending_eapol_rx = NULL;
2235 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2236 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2237 wpa_s->current_ssid &&
2238 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2239 /* Set static WEP keys again */
2240 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2243 #ifdef CONFIG_IBSS_RSN
2244 if (wpa_s->current_ssid &&
2245 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2246 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2247 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2248 wpa_s->ibss_rsn == NULL) {
2249 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2250 if (!wpa_s->ibss_rsn) {
2251 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2252 wpa_supplicant_deauthenticate(
2253 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2257 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2259 #endif /* CONFIG_IBSS_RSN */
2261 wpas_wps_notify_assoc(wpa_s, bssid);
2264 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2265 data->assoc_info.resp_ies_len,
2266 &data->assoc_info.wmm_params);
2268 if (wpa_s->reassoc_same_bss)
2269 wmm_ac_restore_tspecs(wpa_s);
2274 static int disconnect_reason_recoverable(u16 reason_code)
2276 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2277 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2278 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2282 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2284 int locally_generated)
2288 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2290 * At least Host AP driver and a Prism3 card seemed to be
2291 * generating streams of disconnected events when configuring
2292 * IBSS for WPA-None. Ignore them for now.
2297 bssid = wpa_s->bssid;
2298 if (is_zero_ether_addr(bssid))
2299 bssid = wpa_s->pending_bssid;
2301 if (!is_zero_ether_addr(bssid) ||
2302 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2303 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2305 MAC2STR(bssid), reason_code,
2306 locally_generated ? " locally_generated=1" : "");
2311 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2312 int locally_generated)
2314 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2315 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2316 return 0; /* Not in 4-way handshake with PSK */
2319 * It looks like connection was lost while trying to go through PSK
2320 * 4-way handshake. Filter out known disconnection cases that are caused
2321 * by something else than PSK mismatch to avoid confusing reports.
2324 if (locally_generated) {
2325 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2333 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2335 int locally_generated)
2339 u8 prev_pending_bssid[ETH_ALEN];
2340 struct wpa_bss *fast_reconnect = NULL;
2341 struct wpa_ssid *fast_reconnect_ssid = NULL;
2342 struct wpa_ssid *last_ssid;
2344 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2345 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2347 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2349 * At least Host AP driver and a Prism3 card seemed to be
2350 * generating streams of disconnected events when configuring
2351 * IBSS for WPA-None. Ignore them for now.
2353 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2354 "IBSS/WPA-None mode");
2358 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2359 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2360 "pre-shared key may be incorrect");
2361 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2362 return; /* P2P group removed */
2363 wpas_auth_failed(wpa_s, "WRONG_KEY");
2365 if (!wpa_s->disconnected &&
2366 (!wpa_s->auto_reconnect_disabled ||
2367 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2368 wpas_wps_searching(wpa_s))) {
2369 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2370 "reconnect (wps=%d/%d wpa_state=%d)",
2371 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2372 wpas_wps_searching(wpa_s),
2374 if (wpa_s->wpa_state == WPA_COMPLETED &&
2375 wpa_s->current_ssid &&
2376 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2377 !locally_generated &&
2378 disconnect_reason_recoverable(reason_code)) {
2380 * It looks like the AP has dropped association with
2381 * us, but could allow us to get back in. Try to
2382 * reconnect to the same BSS without full scan to save
2383 * time for some common cases.
2385 fast_reconnect = wpa_s->current_bss;
2386 fast_reconnect_ssid = wpa_s->current_ssid;
2387 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2388 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2390 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2393 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2394 "try to re-connect");
2395 wpa_s->reassociate = 0;
2396 wpa_s->disconnected = 1;
2398 wpa_supplicant_cancel_sched_scan(wpa_s);
2400 bssid = wpa_s->bssid;
2401 if (is_zero_ether_addr(bssid))
2402 bssid = wpa_s->pending_bssid;
2403 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2404 wpas_connection_failed(wpa_s, bssid);
2405 wpa_sm_notify_disassoc(wpa_s->wpa);
2406 if (locally_generated)
2407 wpa_s->disconnect_reason = -reason_code;
2409 wpa_s->disconnect_reason = reason_code;
2410 wpas_notify_disconnect_reason(wpa_s);
2411 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2412 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2413 wpa_clear_keys(wpa_s, wpa_s->bssid);
2415 last_ssid = wpa_s->current_ssid;
2416 wpa_supplicant_mark_disassoc(wpa_s);
2418 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2419 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2420 wpa_s->current_ssid = last_ssid;
2423 if (fast_reconnect &&
2424 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2425 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2426 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2427 fast_reconnect->ssid_len) &&
2428 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2429 #ifndef CONFIG_NO_SCAN_PROCESSING
2430 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2431 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2432 fast_reconnect_ssid) < 0) {
2433 /* Recover through full scan */
2434 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2436 #endif /* CONFIG_NO_SCAN_PROCESSING */
2437 } else if (fast_reconnect) {
2439 * Could not reconnect to the same BSS due to network being
2440 * disabled. Use a new scan to match the alternative behavior
2441 * above, i.e., to continue automatic reconnection attempt in a
2442 * way that enforces disabled network rules.
2444 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2449 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2450 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2452 struct wpa_supplicant *wpa_s = eloop_ctx;
2454 if (!wpa_s->pending_mic_error_report)
2457 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2458 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2459 wpa_s->pending_mic_error_report = 0;
2461 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2465 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2466 union wpa_event_data *data)
2469 struct os_reltime t;
2471 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2472 pairwise = (data && data->michael_mic_failure.unicast);
2474 if ((wpa_s->last_michael_mic_error.sec &&
2475 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2476 wpa_s->pending_mic_error_report) {
2477 if (wpa_s->pending_mic_error_report) {
2479 * Send the pending MIC error report immediately since
2480 * we are going to start countermeasures and AP better
2483 wpa_sm_key_request(wpa_s->wpa, 1,
2484 wpa_s->pending_mic_error_pairwise);
2487 /* Send the new MIC error report immediately since we are going
2488 * to start countermeasures and AP better do the same.
2490 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2492 /* initialize countermeasures */
2493 wpa_s->countermeasures = 1;
2495 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2497 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2500 * Need to wait for completion of request frame. We do not get
2501 * any callback for the message completion, so just wait a
2502 * short while and hope for the best. */
2505 wpa_drv_set_countermeasures(wpa_s, 1);
2506 wpa_supplicant_deauthenticate(wpa_s,
2507 WLAN_REASON_MICHAEL_MIC_FAILURE);
2508 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2510 eloop_register_timeout(60, 0,
2511 wpa_supplicant_stop_countermeasures,
2513 /* TODO: mark the AP rejected for 60 second. STA is
2514 * allowed to associate with another AP.. */
2516 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2517 if (wpa_s->mic_errors_seen) {
2519 * Reduce the effectiveness of Michael MIC error
2520 * reports as a means for attacking against TKIP if
2521 * more than one MIC failure is noticed with the same
2522 * PTK. We delay the transmission of the reports by a
2523 * random time between 0 and 60 seconds in order to
2524 * force the attacker wait 60 seconds before getting
2525 * the information on whether a frame resulted in a MIC
2531 if (os_get_random(rval, sizeof(rval)) < 0)
2532 sec = os_random() % 60;
2534 sec = WPA_GET_BE32(rval) % 60;
2535 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2536 "report %d seconds", sec);
2537 wpa_s->pending_mic_error_report = 1;
2538 wpa_s->pending_mic_error_pairwise = pairwise;
2539 eloop_cancel_timeout(
2540 wpa_supplicant_delayed_mic_error_report,
2542 eloop_register_timeout(
2543 sec, os_random() % 1000000,
2544 wpa_supplicant_delayed_mic_error_report,
2547 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2549 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2550 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2551 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2553 wpa_s->last_michael_mic_error = t;
2554 wpa_s->mic_errors_seen++;
2558 #ifdef CONFIG_TERMINATE_ONLASTIF
2559 static int any_interfaces(struct wpa_supplicant *head)
2561 struct wpa_supplicant *wpa_s;
2563 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2564 if (!wpa_s->interface_removed)
2568 #endif /* CONFIG_TERMINATE_ONLASTIF */
2572 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2573 union wpa_event_data *data)
2575 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2578 switch (data->interface_status.ievent) {
2579 case EVENT_INTERFACE_ADDED:
2580 if (!wpa_s->interface_removed)
2582 wpa_s->interface_removed = 0;
2583 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2584 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2585 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2586 "driver after interface was added");
2590 if (!wpa_s->global->p2p &&
2591 !wpa_s->global->p2p_disabled &&
2592 !wpa_s->conf->p2p_disabled &&
2594 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2595 wpas_p2p_add_p2pdev_interface(
2596 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2597 wpa_printf(MSG_INFO,
2598 "P2P: Failed to enable P2P Device interface");
2599 /* Try to continue without. P2P will be disabled. */
2601 #endif /* CONFIG_P2P */
2604 case EVENT_INTERFACE_REMOVED:
2605 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2606 wpa_s->interface_removed = 1;
2607 wpa_supplicant_mark_disassoc(wpa_s);
2608 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2609 l2_packet_deinit(wpa_s->l2);
2613 if (wpa_s->global->p2p &&
2614 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2616 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2617 wpa_dbg(wpa_s, MSG_DEBUG,
2618 "Removing P2P Device interface");
2619 wpa_supplicant_remove_iface(
2620 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2622 wpa_s->global->p2p_init_wpa_s = NULL;
2624 #endif /* CONFIG_P2P */
2626 #ifdef CONFIG_TERMINATE_ONLASTIF
2627 /* check if last interface */
2628 if (!any_interfaces(wpa_s->global->ifaces))
2630 #endif /* CONFIG_TERMINATE_ONLASTIF */
2636 #ifdef CONFIG_PEERKEY
2638 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2639 union wpa_event_data *data)
2643 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2645 #endif /* CONFIG_PEERKEY */
2649 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2650 union wpa_event_data *data)
2654 switch (data->tdls.oper) {
2655 case TDLS_REQUEST_SETUP:
2656 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2657 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2658 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2660 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2662 case TDLS_REQUEST_TEARDOWN:
2663 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2664 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2665 data->tdls.reason_code);
2667 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2670 case TDLS_REQUEST_DISCOVER:
2671 wpa_tdls_send_discovery_request(wpa_s->wpa,
2676 #endif /* CONFIG_TDLS */
2680 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2681 union wpa_event_data *data)
2685 switch (data->wnm.oper) {
2686 case WNM_OPER_SLEEP:
2687 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2688 "(action=%d, intval=%d)",
2689 data->wnm.sleep_action, data->wnm.sleep_intval);
2690 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2691 data->wnm.sleep_intval, NULL);
2695 #endif /* CONFIG_WNM */
2698 #ifdef CONFIG_IEEE80211R
2700 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2701 union wpa_event_data *data)
2706 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2707 data->ft_ies.ies_len,
2708 data->ft_ies.ft_action,
2709 data->ft_ies.target_ap,
2710 data->ft_ies.ric_ies,
2711 data->ft_ies.ric_ies_len) < 0) {
2712 /* TODO: prevent MLME/driver from trying to associate? */
2715 #endif /* CONFIG_IEEE80211R */
2718 #ifdef CONFIG_IBSS_RSN
2719 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2720 union wpa_event_data *data)
2722 struct wpa_ssid *ssid;
2723 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2727 ssid = wpa_s->current_ssid;
2730 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2733 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2737 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2738 union wpa_event_data *data)
2740 struct wpa_ssid *ssid = wpa_s->current_ssid;
2745 /* check if the ssid is correctly configured as IBSS/RSN */
2746 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2749 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2750 data->rx_mgmt.frame_len);
2752 #endif /* CONFIG_IBSS_RSN */
2755 #ifdef CONFIG_IEEE80211R
2756 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2759 const u8 *sta_addr, *target_ap_addr;
2762 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2763 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2764 return; /* only SME case supported for now */
2765 if (len < 1 + 2 * ETH_ALEN + 2)
2768 return; /* Only FT Action Response is supported for now */
2769 sta_addr = data + 1;
2770 target_ap_addr = data + 1 + ETH_ALEN;
2771 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2772 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2773 MACSTR " TargetAP " MACSTR " status %u",
2774 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2776 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2777 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2778 " in FT Action Response", MAC2STR(sta_addr));
2783 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2784 "failure (status code %d)", status);
2785 /* TODO: report error to FT code(?) */
2789 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2790 len - (1 + 2 * ETH_ALEN + 2), 1,
2791 target_ap_addr, NULL, 0) < 0)
2796 struct wpa_bss *bss;
2797 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2799 wpa_s->sme.freq = bss->freq;
2800 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2801 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2804 #endif /* CONFIG_SME */
2806 #endif /* CONFIG_IEEE80211R */
2809 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2810 struct unprot_deauth *e)
2812 #ifdef CONFIG_IEEE80211W
2813 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2814 "dropped: " MACSTR " -> " MACSTR
2815 " (reason code %u)",
2816 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2817 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2818 #endif /* CONFIG_IEEE80211W */
2822 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2823 struct unprot_disassoc *e)
2825 #ifdef CONFIG_IEEE80211W
2826 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2827 "dropped: " MACSTR " -> " MACSTR
2828 " (reason code %u)",
2829 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2830 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2831 #endif /* CONFIG_IEEE80211W */
2835 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2836 u16 reason_code, int locally_generated,
2837 const u8 *ie, size_t ie_len, int deauth)
2840 if (wpa_s->ap_iface && addr) {
2841 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2845 if (wpa_s->ap_iface) {
2846 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2849 #endif /* CONFIG_AP */
2851 if (!locally_generated)
2852 wpa_s->own_disconnect_req = 0;
2854 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2856 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2857 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2858 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2859 eapol_sm_failed(wpa_s->eapol))) &&
2860 !wpa_s->eap_expected_failure))
2861 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2864 if (deauth && reason_code > 0) {
2865 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2866 locally_generated) > 0) {
2868 * The interface was removed, so cannot continue
2869 * processing any additional operations after this.
2874 #endif /* CONFIG_P2P */
2876 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2881 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2882 struct disassoc_info *info)
2884 u16 reason_code = 0;
2885 int locally_generated = 0;
2886 const u8 *addr = NULL;
2887 const u8 *ie = NULL;
2890 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2895 ie_len = info->ie_len;
2896 reason_code = info->reason_code;
2897 locally_generated = info->locally_generated;
2898 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2899 locally_generated ? " (locally generated)" : "");
2901 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2903 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2908 if (wpa_s->ap_iface && info && info->addr) {
2909 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2913 if (wpa_s->ap_iface) {
2914 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2917 #endif /* CONFIG_AP */
2921 wpas_p2p_disassoc_notif(
2922 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2925 #endif /* CONFIG_P2P */
2927 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2928 sme_event_disassoc(wpa_s, info);
2930 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2935 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2936 struct deauth_info *info)
2938 u16 reason_code = 0;
2939 int locally_generated = 0;
2940 const u8 *addr = NULL;
2941 const u8 *ie = NULL;
2944 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2949 ie_len = info->ie_len;
2950 reason_code = info->reason_code;
2951 locally_generated = info->locally_generated;
2952 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2954 locally_generated ? " (locally generated)" : "");
2956 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2959 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2963 wpa_reset_ft_completed(wpa_s->wpa);
2965 wpas_event_disconnect(wpa_s, addr, reason_code,
2966 locally_generated, ie, ie_len, 1);
2970 static const char * reg_init_str(enum reg_change_initiator init)
2973 case REGDOM_SET_BY_CORE:
2975 case REGDOM_SET_BY_USER:
2977 case REGDOM_SET_BY_DRIVER:
2979 case REGDOM_SET_BY_COUNTRY_IE:
2980 return "COUNTRY_IE";
2981 case REGDOM_BEACON_HINT:
2982 return "BEACON_HINT";
2988 static const char * reg_type_str(enum reg_type type)
2991 case REGDOM_TYPE_UNKNOWN:
2993 case REGDOM_TYPE_COUNTRY:
2995 case REGDOM_TYPE_WORLD:
2997 case REGDOM_TYPE_CUSTOM_WORLD:
2998 return "CUSTOM_WORLD";
2999 case REGDOM_TYPE_INTERSECTION:
3000 return "INTERSECTION";
3006 static void wpa_supplicant_update_channel_list(
3007 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
3009 struct wpa_supplicant *ifs;
3011 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
3012 reg_init_str(info->initiator), reg_type_str(info->type),
3013 info->alpha2[0] ? " alpha2=" : "",
3014 info->alpha2[0] ? info->alpha2 : "");
3016 if (wpa_s->drv_priv == NULL)
3017 return; /* Ignore event during drv initialization */
3019 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3021 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3023 free_hw_features(ifs);
3024 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3025 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
3028 /* Restart sched_scan with updated channel list */
3029 if (wpa_s->sched_scanning) {
3030 wpa_dbg(wpa_s, MSG_DEBUG,
3031 "Channel list changed restart sched scan.");
3032 wpa_supplicant_cancel_sched_scan(wpa_s);
3033 wpa_supplicant_req_scan(wpa_s, 0, 0);
3036 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
3040 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
3041 const u8 *frame, size_t len, int freq,
3044 const struct ieee80211_mgmt *mgmt;
3049 if (len < IEEE80211_HDRLEN + 2)
3052 mgmt = (const struct ieee80211_mgmt *) frame;
3053 payload = frame + IEEE80211_HDRLEN;
3054 category = *payload++;
3055 plen = len - IEEE80211_HDRLEN - 1;
3057 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3058 " Category=%u DataLen=%d freq=%d MHz",
3059 MAC2STR(mgmt->sa), category, (int) plen, freq);
3061 if (category == WLAN_ACTION_WMM) {
3062 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3066 #ifdef CONFIG_IEEE80211R
3067 if (category == WLAN_ACTION_FT) {
3068 ft_rx_action(wpa_s, payload, plen);
3071 #endif /* CONFIG_IEEE80211R */
3073 #ifdef CONFIG_IEEE80211W
3075 if (category == WLAN_ACTION_SA_QUERY) {
3076 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3079 #endif /* CONFIG_SME */
3080 #endif /* CONFIG_IEEE80211W */
3083 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3084 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3087 #endif /* CONFIG_WNM */
3090 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3091 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3092 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3093 mgmt->u.action.category,
3094 payload, plen, freq) == 0)
3096 #endif /* CONFIG_GAS */
3099 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3100 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3101 wpa_dbg(wpa_s, MSG_DEBUG,
3102 "TDLS: Received Discovery Response from " MACSTR,
3106 #endif /* CONFIG_TDLS */
3108 #ifdef CONFIG_INTERWORKING
3109 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3110 payload[0] == QOS_QOS_MAP_CONFIG) {
3111 const u8 *pos = payload + 1;
3112 size_t qlen = plen - 1;
3113 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3114 MACSTR, MAC2STR(mgmt->sa));
3115 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3116 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3117 pos[1] <= qlen - 2 && pos[1] >= 16)
3118 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3121 #endif /* CONFIG_INTERWORKING */
3123 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3124 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3125 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3129 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3130 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3131 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3132 payload + 1, plen - 1,
3138 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3139 fst_rx_action(wpa_s->fst, mgmt, len);
3142 #endif /* CONFIG_FST */
3144 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3145 category, payload, plen, freq);
3147 mesh_mpm_action_rx(wpa_s, mgmt, len);
3151 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3152 union wpa_event_data *event)
3154 struct wpa_freq_range_list *list;
3157 list = &event->freq_range;
3160 str = freq_range_list_str(list);
3161 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3165 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3166 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3169 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3172 * The update channel flow will also take care of moving a GO
3173 * from the unsafe frequency if needed.
3175 wpas_p2p_update_channel_list(wpa_s,
3176 WPAS_P2P_CHANNEL_UPDATE_AVOID);
3178 #endif /* CONFIG_P2P */
3184 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3185 union wpa_event_data *data)
3187 wpa_dbg(wpa_s, MSG_DEBUG,
3188 "Connection authorized by device, previous state %d",
3190 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3191 wpa_supplicant_cancel_auth_timeout(wpa_s);
3192 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3193 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3194 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3196 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3197 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3198 data->assoc_info.ptk_kck_len,
3199 data->assoc_info.ptk_kek,
3200 data->assoc_info.ptk_kek_len);
3204 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3205 union wpa_event_data *data)
3207 struct wpa_supplicant *wpa_s = ctx;
3210 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3211 event != EVENT_INTERFACE_ENABLED &&
3212 event != EVENT_INTERFACE_STATUS &&
3213 event != EVENT_SCHED_SCAN_STOPPED) {
3214 wpa_dbg(wpa_s, MSG_DEBUG,
3215 "Ignore event %s (%d) while interface is disabled",
3216 event_to_string(event), event);
3220 #ifndef CONFIG_NO_STDOUT_DEBUG
3222 int level = MSG_DEBUG;
3224 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3225 const struct ieee80211_hdr *hdr;
3227 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3228 fc = le_to_host16(hdr->frame_control);
3229 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3230 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3231 level = MSG_EXCESSIVE;
3234 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3235 event_to_string(event), event);
3237 #endif /* CONFIG_NO_STDOUT_DEBUG */
3241 sme_event_auth(wpa_s, data);
3244 wpa_supplicant_event_assoc(wpa_s, data);
3245 if (data && data->assoc_info.authorized)
3246 wpa_supplicant_event_assoc_auth(wpa_s, data);
3248 case EVENT_DISASSOC:
3249 wpas_event_disassoc(wpa_s,
3250 data ? &data->disassoc_info : NULL);
3253 wpas_event_deauth(wpa_s,
3254 data ? &data->deauth_info : NULL);
3256 case EVENT_MICHAEL_MIC_FAILURE:
3257 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3259 #ifndef CONFIG_NO_SCAN_PROCESSING
3260 case EVENT_SCAN_STARTED:
3261 os_get_reltime(&wpa_s->scan_start_time);
3262 if (wpa_s->own_scan_requested) {
3263 struct os_reltime diff;
3265 os_reltime_sub(&wpa_s->scan_start_time,
3266 &wpa_s->scan_trigger_time, &diff);
3267 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3268 diff.sec, diff.usec);
3269 wpa_s->own_scan_requested = 0;
3270 wpa_s->own_scan_running = 1;
3271 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3272 wpa_s->manual_scan_use_id) {
3273 wpa_msg_ctrl(wpa_s, MSG_INFO,
3274 WPA_EVENT_SCAN_STARTED "id=%u",
3275 wpa_s->manual_scan_id);
3277 wpa_msg_ctrl(wpa_s, MSG_INFO,
3278 WPA_EVENT_SCAN_STARTED);
3281 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3282 wpa_s->radio->external_scan_running = 1;
3283 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3286 case EVENT_SCAN_RESULTS:
3287 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3288 struct os_reltime now, diff;
3289 os_get_reltime(&now);
3290 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3291 wpa_s->scan_start_time.sec = 0;
3292 wpa_s->scan_start_time.usec = 0;
3293 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3294 diff.sec, diff.usec);
3296 if (wpa_supplicant_event_scan_results(wpa_s, data))
3297 break; /* interface may have been removed */
3298 wpa_s->own_scan_running = 0;
3299 wpa_s->radio->external_scan_running = 0;
3300 radio_work_check_next(wpa_s);
3302 #endif /* CONFIG_NO_SCAN_PROCESSING */
3303 case EVENT_ASSOCINFO:
3304 wpa_supplicant_event_associnfo(wpa_s, data);
3306 case EVENT_INTERFACE_STATUS:
3307 wpa_supplicant_event_interface_status(wpa_s, data);
3309 case EVENT_PMKID_CANDIDATE:
3310 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3312 #ifdef CONFIG_PEERKEY
3313 case EVENT_STKSTART:
3314 wpa_supplicant_event_stkstart(wpa_s, data);
3316 #endif /* CONFIG_PEERKEY */
3319 wpa_supplicant_event_tdls(wpa_s, data);
3321 #endif /* CONFIG_TDLS */
3324 wpa_supplicant_event_wnm(wpa_s, data);
3326 #endif /* CONFIG_WNM */
3327 #ifdef CONFIG_IEEE80211R
3328 case EVENT_FT_RESPONSE:
3329 wpa_supplicant_event_ft_response(wpa_s, data);
3331 #endif /* CONFIG_IEEE80211R */
3332 #ifdef CONFIG_IBSS_RSN
3333 case EVENT_IBSS_RSN_START:
3334 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3336 #endif /* CONFIG_IBSS_RSN */
3337 case EVENT_ASSOC_REJECT:
3338 if (data->assoc_reject.bssid)
3339 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3340 "bssid=" MACSTR " status_code=%u",
3341 MAC2STR(data->assoc_reject.bssid),
3342 data->assoc_reject.status_code);
3344 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3346 data->assoc_reject.status_code);
3347 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3348 sme_event_assoc_reject(wpa_s, data);
3350 const u8 *bssid = data->assoc_reject.bssid;
3351 if (bssid == NULL || is_zero_ether_addr(bssid))
3352 bssid = wpa_s->pending_bssid;
3353 wpas_connection_failed(wpa_s, bssid);
3354 wpa_supplicant_mark_disassoc(wpa_s);
3357 case EVENT_AUTH_TIMED_OUT:
3358 /* It is possible to get this event from earlier connection */
3359 if (wpa_s->current_ssid &&
3360 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3361 wpa_dbg(wpa_s, MSG_DEBUG,
3362 "Ignore AUTH_TIMED_OUT in mesh configuration");
3365 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3366 sme_event_auth_timed_out(wpa_s, data);
3368 case EVENT_ASSOC_TIMED_OUT:
3369 /* It is possible to get this event from earlier connection */
3370 if (wpa_s->current_ssid &&
3371 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3372 wpa_dbg(wpa_s, MSG_DEBUG,
3373 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3376 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3377 sme_event_assoc_timed_out(wpa_s, data);
3379 case EVENT_TX_STATUS:
3380 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3381 " type=%d stype=%d",
3382 MAC2STR(data->tx_status.dst),
3383 data->tx_status.type, data->tx_status.stype);
3385 if (wpa_s->ap_iface == NULL) {
3386 #ifdef CONFIG_OFFCHANNEL
3387 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3388 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3389 offchannel_send_action_tx_status(
3390 wpa_s, data->tx_status.dst,
3391 data->tx_status.data,
3392 data->tx_status.data_len,
3393 data->tx_status.ack ?
3394 OFFCHANNEL_SEND_ACTION_SUCCESS :
3395 OFFCHANNEL_SEND_ACTION_NO_ACK);
3396 #endif /* CONFIG_OFFCHANNEL */
3399 #endif /* CONFIG_AP */
3400 #ifdef CONFIG_OFFCHANNEL
3401 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3402 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3404 * Catch TX status events for Action frames we sent via group
3405 * interface in GO mode.
3407 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3408 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3409 os_memcmp(wpa_s->parent->pending_action_dst,
3410 data->tx_status.dst, ETH_ALEN) == 0) {
3411 offchannel_send_action_tx_status(
3412 wpa_s->parent, data->tx_status.dst,
3413 data->tx_status.data,
3414 data->tx_status.data_len,
3415 data->tx_status.ack ?
3416 OFFCHANNEL_SEND_ACTION_SUCCESS :
3417 OFFCHANNEL_SEND_ACTION_NO_ACK);
3420 #endif /* CONFIG_OFFCHANNEL */
3422 switch (data->tx_status.type) {
3423 case WLAN_FC_TYPE_MGMT:
3424 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3425 data->tx_status.data_len,
3426 data->tx_status.stype,
3427 data->tx_status.ack);
3429 case WLAN_FC_TYPE_DATA:
3430 ap_tx_status(wpa_s, data->tx_status.dst,
3431 data->tx_status.data,
3432 data->tx_status.data_len,
3433 data->tx_status.ack);
3436 #endif /* CONFIG_AP */
3439 case EVENT_EAPOL_TX_STATUS:
3440 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3441 data->eapol_tx_status.data,
3442 data->eapol_tx_status.data_len,
3443 data->eapol_tx_status.ack);
3445 case EVENT_DRIVER_CLIENT_POLL_OK:
3446 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3448 case EVENT_RX_FROM_UNKNOWN:
3449 if (wpa_s->ap_iface == NULL)
3451 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3452 data->rx_from_unknown.wds);
3454 case EVENT_CH_SWITCH:
3457 if (!wpa_s->ap_iface) {
3458 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3459 "event in non-AP mode");
3463 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3464 data->ch_switch.ht_enabled,
3465 data->ch_switch.ch_offset,
3466 data->ch_switch.ch_width,
3467 data->ch_switch.cf1,
3468 data->ch_switch.cf2);
3471 case EVENT_DFS_RADAR_DETECTED:
3473 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3475 case EVENT_DFS_CAC_STARTED:
3477 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3479 case EVENT_DFS_CAC_FINISHED:
3481 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3483 case EVENT_DFS_CAC_ABORTED:
3485 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3487 case EVENT_DFS_NOP_FINISHED:
3489 wpas_event_dfs_cac_nop_finished(wpa_s,
3492 #endif /* NEED_AP_MLME */
3493 #endif /* CONFIG_AP */
3494 case EVENT_RX_MGMT: {
3496 const struct ieee80211_mgmt *mgmt;
3498 #ifdef CONFIG_TESTING_OPTIONS
3499 if (wpa_s->ext_mgmt_frame_handling) {
3500 struct rx_mgmt *rx = &data->rx_mgmt;
3501 size_t hex_len = 2 * rx->frame_len + 1;
3502 char *hex = os_malloc(hex_len);
3504 wpa_snprintf_hex(hex, hex_len,
3505 rx->frame, rx->frame_len);
3506 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3507 rx->freq, rx->datarate, rx->ssi_signal,
3513 #endif /* CONFIG_TESTING_OPTIONS */
3515 mgmt = (const struct ieee80211_mgmt *)
3516 data->rx_mgmt.frame;
3517 fc = le_to_host16(mgmt->frame_control);
3518 stype = WLAN_FC_GET_STYPE(fc);
3521 if (wpa_s->ap_iface == NULL) {
3522 #endif /* CONFIG_AP */
3524 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3525 data->rx_mgmt.frame_len > 24) {
3526 const u8 *src = mgmt->sa;
3527 const u8 *ie = mgmt->u.probe_req.variable;
3528 size_t ie_len = data->rx_mgmt.frame_len -
3529 (mgmt->u.probe_req.variable -
3530 data->rx_mgmt.frame);
3531 wpas_p2p_probe_req_rx(
3532 wpa_s, src, mgmt->da,
3533 mgmt->bssid, ie, ie_len,
3535 data->rx_mgmt.ssi_signal);
3538 #endif /* CONFIG_P2P */
3539 #ifdef CONFIG_IBSS_RSN
3540 if (wpa_s->current_ssid &&
3541 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3542 stype == WLAN_FC_STYPE_AUTH &&
3543 data->rx_mgmt.frame_len >= 30) {
3544 wpa_supplicant_event_ibss_auth(wpa_s, data);
3547 #endif /* CONFIG_IBSS_RSN */
3549 if (stype == WLAN_FC_STYPE_ACTION) {
3550 wpas_event_rx_mgmt_action(
3551 wpa_s, data->rx_mgmt.frame,
3552 data->rx_mgmt.frame_len,
3554 data->rx_mgmt.ssi_signal);
3559 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3563 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3564 "management frame in non-AP mode");
3569 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3570 data->rx_mgmt.frame_len > 24) {
3571 const u8 *ie = mgmt->u.probe_req.variable;
3572 size_t ie_len = data->rx_mgmt.frame_len -
3573 (mgmt->u.probe_req.variable -
3574 data->rx_mgmt.frame);
3576 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3577 mgmt->bssid, ie, ie_len,
3578 data->rx_mgmt.ssi_signal);
3581 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3582 #endif /* CONFIG_AP */
3585 case EVENT_RX_PROBE_REQ:
3586 if (data->rx_probe_req.sa == NULL ||
3587 data->rx_probe_req.ie == NULL)
3590 if (wpa_s->ap_iface) {
3591 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3592 data->rx_probe_req.sa,
3593 data->rx_probe_req.da,
3594 data->rx_probe_req.bssid,
3595 data->rx_probe_req.ie,
3596 data->rx_probe_req.ie_len,
3597 data->rx_probe_req.ssi_signal);
3600 #endif /* CONFIG_AP */
3601 wpas_p2p_probe_req_rx(wpa_s, 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,
3607 data->rx_probe_req.ssi_signal);
3609 case EVENT_REMAIN_ON_CHANNEL:
3610 #ifdef CONFIG_OFFCHANNEL
3611 offchannel_remain_on_channel_cb(
3612 wpa_s, data->remain_on_channel.freq,
3613 data->remain_on_channel.duration);
3614 #endif /* CONFIG_OFFCHANNEL */
3615 wpas_p2p_remain_on_channel_cb(
3616 wpa_s, data->remain_on_channel.freq,
3617 data->remain_on_channel.duration);
3619 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3620 #ifdef CONFIG_OFFCHANNEL
3621 offchannel_cancel_remain_on_channel_cb(
3622 wpa_s, data->remain_on_channel.freq);
3623 #endif /* CONFIG_OFFCHANNEL */
3624 wpas_p2p_cancel_remain_on_channel_cb(
3625 wpa_s, data->remain_on_channel.freq);
3627 case EVENT_EAPOL_RX:
3628 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3629 data->eapol_rx.data,
3630 data->eapol_rx.data_len);
3632 case EVENT_SIGNAL_CHANGE:
3633 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3634 "above=%d signal=%d noise=%d txrate=%d",
3635 data->signal_change.above_threshold,
3636 data->signal_change.current_signal,
3637 data->signal_change.current_noise,
3638 data->signal_change.current_txrate);
3639 wpa_bss_update_level(wpa_s->current_bss,
3640 data->signal_change.current_signal);
3641 bgscan_notify_signal_change(
3642 wpa_s, data->signal_change.above_threshold,
3643 data->signal_change.current_signal,
3644 data->signal_change.current_noise,
3645 data->signal_change.current_txrate);
3647 case EVENT_INTERFACE_ENABLED:
3648 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3649 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3650 wpa_supplicant_update_mac_addr(wpa_s);
3651 if (wpa_s->p2p_mgmt) {
3652 wpa_supplicant_set_state(wpa_s,
3658 if (!wpa_s->ap_iface) {
3659 wpa_supplicant_set_state(wpa_s,
3661 wpa_s->scan_req = NORMAL_SCAN_REQ;
3662 wpa_supplicant_req_scan(wpa_s, 0, 0);
3664 wpa_supplicant_set_state(wpa_s,
3666 #else /* CONFIG_AP */
3667 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3668 wpa_supplicant_req_scan(wpa_s, 0, 0);
3669 #endif /* CONFIG_AP */
3672 case EVENT_INTERFACE_DISABLED:
3673 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3675 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3676 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3677 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3679 * Mark interface disabled if this happens to end up not
3680 * being removed as a separate P2P group interface.
3682 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3684 * The interface was externally disabled. Remove
3685 * it assuming an external entity will start a
3686 * new session if needed.
3688 if (wpa_s->current_ssid &&
3689 wpa_s->current_ssid->p2p_group)
3690 wpas_p2p_interface_unavailable(wpa_s);
3692 wpas_p2p_disconnect(wpa_s);
3694 * wpa_s instance may have been freed, so must not use
3699 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3700 p2p_in_progress(wpa_s->global->p2p) > 1) {
3701 /* This radio work will be cancelled, so clear P2P
3704 p2p_stop_find(wpa_s->global->p2p);
3706 #endif /* CONFIG_P2P */
3708 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3710 * Indicate disconnection to keep ctrl_iface events
3713 wpa_supplicant_event_disassoc(
3714 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3716 wpa_supplicant_mark_disassoc(wpa_s);
3717 radio_remove_works(wpa_s, NULL, 0);
3719 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3721 case EVENT_CHANNEL_LIST_CHANGED:
3722 wpa_supplicant_update_channel_list(
3723 wpa_s, &data->channel_list_changed);
3725 case EVENT_INTERFACE_UNAVAILABLE:
3726 wpas_p2p_interface_unavailable(wpa_s);
3728 case EVENT_BEST_CHANNEL:
3729 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3731 data->best_chan.freq_24, data->best_chan.freq_5,
3732 data->best_chan.freq_overall);
3733 wpa_s->best_24_freq = data->best_chan.freq_24;
3734 wpa_s->best_5_freq = data->best_chan.freq_5;
3735 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3736 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3737 data->best_chan.freq_5,
3738 data->best_chan.freq_overall);
3740 case EVENT_UNPROT_DEAUTH:
3741 wpa_supplicant_event_unprot_deauth(wpa_s,
3742 &data->unprot_deauth);
3744 case EVENT_UNPROT_DISASSOC:
3745 wpa_supplicant_event_unprot_disassoc(wpa_s,
3746 &data->unprot_disassoc);
3748 case EVENT_STATION_LOW_ACK:
3750 if (wpa_s->ap_iface && data)
3751 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3752 data->low_ack.addr);
3753 #endif /* CONFIG_AP */
3756 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3757 data->low_ack.addr);
3758 #endif /* CONFIG_TDLS */
3760 case EVENT_IBSS_PEER_LOST:
3761 #ifdef CONFIG_IBSS_RSN
3762 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3763 #endif /* CONFIG_IBSS_RSN */
3765 case EVENT_DRIVER_GTK_REKEY:
3766 if (os_memcmp(data->driver_gtk_rekey.bssid,
3767 wpa_s->bssid, ETH_ALEN))
3771 wpa_sm_update_replay_ctr(wpa_s->wpa,
3772 data->driver_gtk_rekey.replay_ctr);
3774 case EVENT_SCHED_SCAN_STOPPED:
3776 wpa_s->sched_scanning = 0;
3777 resched = wpa_s->scanning;
3778 wpa_supplicant_notify_scanning(wpa_s, 0);
3780 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3784 * Start a new sched scan to continue searching for more SSIDs
3785 * either if timed out or PNO schedule scan is pending.
3787 if (wpa_s->sched_scan_timed_out) {
3788 wpa_supplicant_req_sched_scan(wpa_s);
3789 } else if (wpa_s->pno_sched_pending) {
3790 wpa_s->pno_sched_pending = 0;
3791 wpas_start_pno(wpa_s);
3792 } else if (resched) {
3793 wpa_supplicant_req_scan(wpa_s, 0, 0);
3797 case EVENT_WPS_BUTTON_PUSHED:
3799 wpas_wps_start_pbc(wpa_s, NULL, 0);
3800 #endif /* CONFIG_WPS */
3802 case EVENT_AVOID_FREQUENCIES:
3803 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3805 case EVENT_CONNECT_FAILED_REASON:
3807 if (!wpa_s->ap_iface || !data)
3809 hostapd_event_connect_failed_reason(
3810 wpa_s->ap_iface->bss[0],
3811 data->connect_failed_reason.addr,
3812 data->connect_failed_reason.code);
3813 #endif /* CONFIG_AP */
3815 case EVENT_NEW_PEER_CANDIDATE:
3817 if (!wpa_s->ifmsh || !data)
3819 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3820 data->mesh_peer.ies,
3821 data->mesh_peer.ie_len);
3822 #endif /* CONFIG_MESH */
3825 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);