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"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
50 #ifndef CONFIG_NO_SCAN_PROCESSING
51 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
52 int new_scan, int own_request);
53 #endif /* CONFIG_NO_SCAN_PROCESSING */
56 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
59 struct os_reltime now;
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
65 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
75 * wpas_reenabled_network_time - Time until first network is re-enabled
76 * @wpa_s: Pointer to wpa_supplicant data
77 * Returns: If all enabled networks are temporarily disabled, returns the time
78 * (in sec) until the first network is re-enabled. Otherwise returns 0.
80 * This function is used in case all enabled networks are temporarily disabled,
81 * in which case it returns the time (in sec) that the first network will be
82 * re-enabled. The function assumes that at least one network is enabled.
84 static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
86 struct wpa_ssid *ssid;
87 int disabled_for, res = 0;
89 #ifdef CONFIG_INTERWORKING
90 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
93 #endif /* CONFIG_INTERWORKING */
95 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
99 disabled_for = wpas_temp_disabled(wpa_s, ssid);
103 if (!res || disabled_for < res)
111 void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
113 struct wpa_supplicant *wpa_s = eloop_ctx;
115 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
118 wpa_dbg(wpa_s, MSG_DEBUG,
119 "Try to associate due to network getting re-enabled");
120 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
121 wpa_supplicant_cancel_sched_scan(wpa_s);
122 wpa_supplicant_req_scan(wpa_s, 0, 0);
127 static struct wpa_bss * wpa_supplicant_get_new_bss(
128 struct wpa_supplicant *wpa_s, const u8 *bssid)
130 struct wpa_bss *bss = NULL;
131 struct wpa_ssid *ssid = wpa_s->current_ssid;
133 if (ssid->ssid_len > 0)
134 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
136 bss = wpa_bss_get_bssid(wpa_s, bssid);
142 static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
144 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
147 wpa_supplicant_update_scan_results(wpa_s);
149 /* Get the BSS from the new scan results */
150 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
154 wpa_s->current_bss = bss;
158 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
160 struct wpa_ssid *ssid, *old_ssid;
161 u8 drv_ssid[MAX_SSID_LEN];
165 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
166 wpa_supplicant_update_current_bss(wpa_s);
168 if (wpa_s->current_ssid->ssid_len == 0)
169 return 0; /* current profile still in use */
170 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
172 wpa_msg(wpa_s, MSG_INFO,
173 "Failed to read SSID from driver");
174 return 0; /* try to use current profile */
178 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
179 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
181 return 0; /* current profile still in use */
183 wpa_msg(wpa_s, MSG_DEBUG,
184 "Driver-initiated BSS selection changed the SSID to %s",
185 wpa_ssid_txt(drv_ssid, drv_ssid_len));
186 /* continue selecting a new network profile */
189 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
191 ssid = wpa_supplicant_get_ssid(wpa_s);
193 wpa_msg(wpa_s, MSG_INFO,
194 "No network configuration found for the current AP");
198 if (wpas_network_disabled(wpa_s, ssid)) {
199 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
203 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
204 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
205 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
209 res = wpas_temp_disabled(wpa_s, ssid);
211 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
212 "disabled for %d second(s)", res);
216 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
218 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
220 size_t wpa_ie_len = sizeof(wpa_ie);
221 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
222 wpa_ie, &wpa_ie_len) < 0)
223 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
225 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
228 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
229 eapol_sm_invalidate_cached_session(wpa_s->eapol);
230 old_ssid = wpa_s->current_ssid;
231 wpa_s->current_ssid = ssid;
233 wpa_supplicant_update_current_bss(wpa_s);
235 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
236 wpa_supplicant_initiate_eapol(wpa_s);
237 if (old_ssid != wpa_s->current_ssid)
238 wpas_notify_network_changed(wpa_s);
244 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
246 struct wpa_supplicant *wpa_s = eloop_ctx;
248 if (wpa_s->countermeasures) {
249 wpa_s->countermeasures = 0;
250 wpa_drv_set_countermeasures(wpa_s, 0);
251 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
254 * It is possible that the device is sched scanning, which means
255 * that a connection attempt will be done only when we receive
256 * scan results. However, in this case, it would be preferable
257 * to scan and connect immediately, so cancel the sched_scan and
258 * issue a regular scan flow.
260 wpa_supplicant_cancel_sched_scan(wpa_s);
261 wpa_supplicant_req_scan(wpa_s, 0, 0);
266 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
270 wnm_bss_keep_alive_deinit(wpa_s);
272 #ifdef CONFIG_IBSS_RSN
273 ibss_rsn_deinit(wpa_s->ibss_rsn);
274 wpa_s->ibss_rsn = NULL;
275 #endif /* CONFIG_IBSS_RSN */
278 wpa_supplicant_ap_deinit(wpa_s);
279 #endif /* CONFIG_AP */
281 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
284 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
285 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
286 os_memset(wpa_s->bssid, 0, ETH_ALEN);
287 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
288 sme_clear_on_disassoc(wpa_s);
290 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
291 #endif /* CONFIG_P2P */
292 wpa_s->current_bss = NULL;
293 wpa_s->assoc_freq = 0;
296 wpas_notify_bssid_changed(wpa_s);
298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
300 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
301 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
302 wpa_s->ap_ies_from_associnfo = 0;
303 wpa_s->current_ssid = NULL;
304 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
307 wpas_rrm_reset(wpa_s);
311 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
313 struct wpa_ie_data ie;
317 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
321 for (i = 0; i < ie.num_pmkid; i++) {
322 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
323 ie.pmkid + i * PMKID_LEN,
325 if (pmksa_set == 0) {
326 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
331 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
332 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
336 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
337 union wpa_event_data *data)
340 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
344 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
345 " index=%d preauth=%d",
346 MAC2STR(data->pmkid_candidate.bssid),
347 data->pmkid_candidate.index,
348 data->pmkid_candidate.preauth);
350 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
351 data->pmkid_candidate.index,
352 data->pmkid_candidate.preauth);
356 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
358 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
359 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
362 #ifdef IEEE8021X_EAPOL
363 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
364 wpa_s->current_ssid &&
365 !(wpa_s->current_ssid->eapol_flags &
366 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
367 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
368 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
369 * plaintext or static WEP keys). */
372 #endif /* IEEE8021X_EAPOL */
379 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
380 * @wpa_s: pointer to wpa_supplicant data
381 * @ssid: Configuration data for the network
382 * Returns: 0 on success, -1 on failure
384 * This function is called when starting authentication with a network that is
385 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
387 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
388 struct wpa_ssid *ssid)
390 #ifdef IEEE8021X_EAPOL
392 int aka = 0, sim = 0;
394 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
395 wpa_s->scard != NULL || wpa_s->conf->external_sim)
398 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
402 struct eap_method_type *eap = ssid->eap.eap_methods;
403 while (eap->vendor != EAP_VENDOR_IETF ||
404 eap->method != EAP_TYPE_NONE) {
405 if (eap->vendor == EAP_VENDOR_IETF) {
406 if (eap->method == EAP_TYPE_SIM)
408 else if (eap->method == EAP_TYPE_AKA ||
409 eap->method == EAP_TYPE_AKA_PRIME)
416 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
418 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
419 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
424 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
425 "use SIM, but neither EAP-SIM nor EAP-AKA are "
430 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
431 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
433 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
434 if (wpa_s->scard == NULL) {
435 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
439 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
440 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
441 #endif /* PCSC_FUNCS */
442 #endif /* IEEE8021X_EAPOL */
448 #ifndef CONFIG_NO_SCAN_PROCESSING
450 static int has_wep_key(struct wpa_ssid *ssid)
454 for (i = 0; i < NUM_WEP_KEYS; i++) {
455 if (ssid->wep_key_len[i])
463 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
464 struct wpa_ssid *ssid)
468 if (ssid->mixed_cell)
472 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
474 #endif /* CONFIG_WPS */
476 if (has_wep_key(ssid))
479 #ifdef IEEE8021X_EAPOL
480 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
481 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
482 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
484 #endif /* IEEE8021X_EAPOL */
486 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
489 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
492 if (bss->caps & IEEE80211_CAP_PRIVACY)
498 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
499 struct wpa_ssid *ssid,
502 struct wpa_ie_data ie;
504 const u8 *rsn_ie, *wpa_ie;
508 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
512 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
513 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
514 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
515 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
516 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
518 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
519 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
522 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
523 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
529 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
531 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
536 if (!(ie.proto & ssid->proto)) {
537 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
542 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
543 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
548 if (!(ie.group_cipher & ssid->group_cipher)) {
549 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
554 if (!(ie.key_mgmt & ssid->key_mgmt)) {
555 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
560 #ifdef CONFIG_IEEE80211W
561 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
562 wpas_get_ssid_pmf(wpa_s, ssid) ==
563 MGMT_FRAME_PROTECTION_REQUIRED) {
564 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
568 #endif /* CONFIG_IEEE80211W */
570 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
574 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
575 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
578 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
579 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
585 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
587 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
592 if (!(ie.proto & ssid->proto)) {
593 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
598 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
599 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
604 if (!(ie.group_cipher & ssid->group_cipher)) {
605 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
610 if (!(ie.key_mgmt & ssid->key_mgmt)) {
611 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
616 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
620 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
622 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
626 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
627 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
628 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
632 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
633 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
638 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
639 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
643 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
650 static int freq_allowed(int *freqs, int freq)
657 for (i = 0; freqs[i]; i++)
658 if (freqs[i] == freq)
664 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
666 const struct hostapd_hw_modes *mode = NULL, *modes;
667 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
672 return 1; /* Cannot do matching without knowing band */
674 modes = wpa_s->hw.modes;
677 * The driver does not provide any additional information
678 * about the utilized hardware, so allow the connection attempt
684 for (i = 0; i < wpa_s->hw.num_modes; i++) {
685 for (j = 0; j < modes[i].num_channels; j++) {
686 int freq = modes[i].channels[j].freq;
687 if (freq == bss->freq) {
689 mode->mode == HOSTAPD_MODE_IEEE80211G)
690 break; /* do not allow 802.11b replace
701 for (i = 0; i < (int) sizeof(scan_ie); i++) {
702 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
706 for (j = 2; j < rate_ie[1] + 2; j++) {
707 int flagged = !!(rate_ie[j] & 0x80);
708 int r = (rate_ie[j] & 0x7f) * 5;
711 * IEEE Std 802.11n-2009 7.3.2.2:
712 * The new BSS Membership selector value is encoded
713 * like a legacy basic rate, but it is not a rate and
714 * only indicates if the BSS members are required to
715 * support the mandatory features of Clause 20 [HT PHY]
716 * in order to join the BSS.
718 if (flagged && ((rate_ie[j] & 0x7f) ==
719 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
720 if (!ht_supported(mode)) {
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " hardware does not support "
729 /* There's also a VHT selector for 802.11ac */
730 if (flagged && ((rate_ie[j] & 0x7f) ==
731 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
732 if (!vht_supported(mode)) {
733 wpa_dbg(wpa_s, MSG_DEBUG,
734 " hardware does not support "
744 /* check for legacy basic rates */
745 for (k = 0; k < mode->num_rates; k++) {
746 if (mode->rates[k] == r)
749 if (k == mode->num_rates) {
751 * IEEE Std 802.11-2007 7.3.2.2 demands that in
752 * order to join a BSS all required rates
753 * have to be supported by the hardware.
755 wpa_dbg(wpa_s, MSG_DEBUG,
756 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
758 bss->freq, mode->mode, mode->num_rates);
769 * Test whether BSS is in an ESS.
770 * This is done differently in DMG (60 GHz) and non-DMG bands
772 static int bss_is_ess(struct wpa_bss *bss)
774 if (bss_is_dmg(bss)) {
775 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
776 IEEE80211_CAP_DMG_AP;
779 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
784 static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
788 for (i = 0; i < ETH_ALEN; i++) {
789 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
796 static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
800 for (i = 0; i < num; i++) {
801 const u8 *a = list + i * ETH_ALEN * 2;
802 const u8 *m = a + ETH_ALEN;
804 if (match_mac_mask(a, addr, m))
811 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
812 int i, struct wpa_bss *bss,
813 struct wpa_ssid *group,
816 u8 wpa_ie_len, rsn_ie_len;
818 struct wpa_blacklist *e;
820 struct wpa_ssid *ssid;
823 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
824 wpa_ie_len = ie ? ie[1] : 0;
826 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
827 rsn_ie_len = ie ? ie[1] : 0;
829 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
832 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
833 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
834 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
835 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
836 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
837 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
838 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
840 osen ? " osen=1" : "");
842 e = wpa_blacklist_get(wpa_s, bss->bssid);
845 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
847 * When only a single network is enabled, we can
848 * trigger blacklisting on the first failure. This
849 * should not be done with multiple enabled networks to
850 * avoid getting forced to move into a worse ESS on
851 * single error if there are no other BSSes of the
856 if (e->count > limit) {
857 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
858 "(count=%d limit=%d)", e->count, limit);
863 if (bss->ssid_len == 0) {
864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
868 if (disallowed_bssid(wpa_s, bss->bssid)) {
869 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
873 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
878 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
880 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
881 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
884 if (wpas_network_disabled(wpa_s, ssid)) {
885 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
889 res = wpas_temp_disabled(wpa_s, ssid);
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
892 "temporarily for %d second(s)", res);
897 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
898 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
903 if (wpa && ssid->ssid_len == 0 &&
904 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
907 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
908 /* Only allow wildcard SSID match if an AP
909 * advertises active WPS operation that matches
912 if (ssid->ssid_len == 0 &&
913 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
916 #endif /* CONFIG_WPS */
918 if (ssid->bssid_set && ssid->ssid_len == 0 &&
919 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
923 (bss->ssid_len != ssid->ssid_len ||
924 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
925 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
929 if (ssid->bssid_set &&
930 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
931 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
935 /* check blacklist */
936 if (ssid->num_bssid_blacklist &&
937 addr_in_list(bss->bssid, ssid->bssid_blacklist,
938 ssid->num_bssid_blacklist)) {
939 wpa_dbg(wpa_s, MSG_DEBUG,
940 " skip - BSSID blacklisted");
944 /* if there is a whitelist, only accept those APs */
945 if (ssid->num_bssid_whitelist &&
946 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
947 ssid->num_bssid_whitelist)) {
948 wpa_dbg(wpa_s, MSG_DEBUG,
949 " skip - BSSID not in whitelist");
953 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
957 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
958 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
959 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
960 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
965 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
967 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
971 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
972 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
977 if (!wpa_supplicant_match_privacy(bss, ssid)) {
978 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
983 if (!bss_is_ess(bss)) {
984 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
988 if (!freq_allowed(ssid->freq_list, bss->freq)) {
989 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
994 if (!rate_match(wpa_s, bss)) {
995 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1001 if (ssid->p2p_group &&
1002 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1003 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1004 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1008 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1009 struct wpabuf *p2p_ie;
1010 u8 dev_addr[ETH_ALEN];
1012 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1014 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1017 p2p_ie = wpa_bss_get_vendor_ie_multi(
1018 bss, P2P_IE_VENDOR_TYPE);
1019 if (p2p_ie == NULL) {
1020 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1024 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1025 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1027 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1028 wpabuf_free(p2p_ie);
1031 wpabuf_free(p2p_ie);
1035 * TODO: skip the AP if its P2P IE has Group Formation
1036 * bit set in the P2P Group Capability Bitmap and we
1037 * are not in Group Formation with that device.
1039 #endif /* CONFIG_P2P */
1041 /* Matching configuration found */
1045 /* No matching configuration found */
1050 static struct wpa_bss *
1051 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1052 struct wpa_ssid *group,
1053 struct wpa_ssid **selected_ssid,
1054 int only_first_ssid)
1058 if (only_first_ssid)
1059 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1062 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1065 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1066 struct wpa_bss *bss = wpa_s->last_scan_res[i];
1067 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1069 if (!*selected_ssid)
1071 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1073 MAC2STR(bss->bssid),
1074 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1082 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1083 struct wpa_ssid **selected_ssid)
1085 struct wpa_bss *selected = NULL;
1087 struct wpa_ssid *next_ssid = NULL;
1089 if (wpa_s->last_scan_res == NULL ||
1090 wpa_s->last_scan_res_used == 0)
1091 return NULL; /* no scan results from last update */
1093 if (wpa_s->next_ssid) {
1094 struct wpa_ssid *ssid;
1096 /* check that next_ssid is still valid */
1097 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1098 if (ssid == wpa_s->next_ssid)
1102 wpa_s->next_ssid = NULL;
1105 while (selected == NULL) {
1106 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1107 if (next_ssid && next_ssid->priority ==
1108 wpa_s->conf->pssid[prio]->priority) {
1109 selected = wpa_supplicant_select_bss(
1110 wpa_s, next_ssid, selected_ssid, 1);
1114 selected = wpa_supplicant_select_bss(
1115 wpa_s, wpa_s->conf->pssid[prio],
1121 if (selected == NULL && wpa_s->blacklist &&
1122 !wpa_s->countermeasures) {
1123 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1124 "blacklist and try again");
1125 wpa_blacklist_clear(wpa_s);
1126 wpa_s->blacklist_cleared++;
1127 } else if (selected == NULL)
1135 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1136 int timeout_sec, int timeout_usec)
1138 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1140 * No networks are enabled; short-circuit request so
1141 * we don't wait timeout seconds before transitioning
1142 * to INACTIVE state.
1144 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1145 "since there are no enabled networks");
1146 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1150 wpa_s->scan_for_connection = 1;
1151 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1155 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1156 struct wpa_bss *selected,
1157 struct wpa_ssid *ssid)
1159 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1160 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1161 "PBC session overlap");
1163 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1164 wpa_s->p2p_in_provisioning) {
1165 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1169 #endif /* CONFIG_P2P */
1172 wpas_wps_cancel(wpa_s);
1173 #endif /* CONFIG_WPS */
1177 wpa_msg(wpa_s, MSG_DEBUG,
1178 "Considering connect request: reassociate: %d selected: "
1179 MACSTR " bssid: " MACSTR " pending: " MACSTR
1180 " wpa_state: %s ssid=%p current_ssid=%p",
1181 wpa_s->reassociate, MAC2STR(selected->bssid),
1182 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1183 wpa_supplicant_state_txt(wpa_s->wpa_state),
1184 ssid, wpa_s->current_ssid);
1187 * Do not trigger new association unless the BSSID has changed or if
1188 * reassociation is requested. If we are in process of associating with
1189 * the selected BSSID, do not trigger new attempt.
1191 if (wpa_s->reassociate ||
1192 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1193 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1194 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1195 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1196 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1198 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1199 ssid != wpa_s->current_ssid)))) {
1200 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1201 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1204 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1205 MAC2STR(selected->bssid));
1206 wpa_supplicant_associate(wpa_s, selected, ssid);
1208 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1209 "connect with the selected AP");
1216 static struct wpa_ssid *
1217 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1220 struct wpa_ssid *ssid;
1222 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1223 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1225 if (wpas_network_disabled(wpa_s, ssid))
1227 if (ssid->mode == IEEE80211_MODE_IBSS ||
1228 ssid->mode == IEEE80211_MODE_AP ||
1229 ssid->mode == IEEE80211_MODE_MESH)
1237 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1238 * on BSS added and BSS changed events */
1239 static void wpa_supplicant_rsn_preauth_scan_results(
1240 struct wpa_supplicant *wpa_s)
1242 struct wpa_bss *bss;
1244 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1247 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1248 const u8 *ssid, *rsn;
1250 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1254 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1258 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1264 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1265 struct wpa_bss *selected,
1266 struct wpa_ssid *ssid)
1268 struct wpa_bss *current_bss = NULL;
1271 if (wpa_s->reassociate)
1272 return 1; /* explicit request to reassociate */
1273 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1274 return 1; /* we are not associated; continue */
1275 if (wpa_s->current_ssid == NULL)
1276 return 1; /* unknown current SSID */
1277 if (wpa_s->current_ssid != ssid)
1278 return 1; /* different network block */
1280 if (wpas_driver_bss_selection(wpa_s))
1281 return 0; /* Driver-based roaming */
1283 if (wpa_s->current_ssid->ssid)
1284 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1285 wpa_s->current_ssid->ssid,
1286 wpa_s->current_ssid->ssid_len);
1288 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1291 return 1; /* current BSS not seen in scan results */
1293 if (current_bss == selected)
1296 if (selected->last_update_idx > current_bss->last_update_idx)
1297 return 1; /* current BSS not seen in the last scan */
1299 #ifndef CONFIG_NO_ROAMING
1300 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1301 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1302 " level=%d snr=%d est_throughput=%u",
1303 MAC2STR(current_bss->bssid), current_bss->level,
1304 current_bss->snr, current_bss->est_throughput);
1305 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1306 " level=%d snr=%d est_throughput=%u",
1307 MAC2STR(selected->bssid), selected->level,
1308 selected->snr, selected->est_throughput);
1310 if (wpa_s->current_ssid->bssid_set &&
1311 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1313 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1314 "has preferred BSSID");
1318 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1319 wpa_dbg(wpa_s, MSG_DEBUG,
1320 "Allow reassociation - selected BSS has better estimated throughput");
1324 if (current_bss->level < 0 && current_bss->level > selected->level) {
1325 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1331 if (current_bss->level < 0) {
1332 if (current_bss->level < -85)
1334 else if (current_bss->level < -80)
1336 else if (current_bss->level < -75)
1338 else if (current_bss->level < -70)
1343 if (abs(current_bss->level - selected->level) < min_diff) {
1344 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1350 #else /* CONFIG_NO_ROAMING */
1352 #endif /* CONFIG_NO_ROAMING */
1356 /* Return != 0 if no scan results could be fetched or if scan results should not
1357 * be shared with other virtual interfaces. */
1358 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1359 union wpa_event_data *data,
1362 struct wpa_scan_results *scan_res = NULL;
1365 #ifndef CONFIG_NO_RANDOM_POOL
1367 #endif /* CONFIG_NO_RANDOM_POOL */
1370 if (wpa_s->ap_iface)
1372 #endif /* CONFIG_AP */
1374 wpa_supplicant_notify_scanning(wpa_s, 0);
1376 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1377 data ? &data->scan_info :
1379 if (scan_res == NULL) {
1380 if (wpa_s->conf->ap_scan == 2 || ap ||
1381 wpa_s->scan_res_handler == scan_only_handler)
1385 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1387 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1389 goto scan_work_done;
1392 #ifndef CONFIG_NO_RANDOM_POOL
1393 num = scan_res->num;
1396 for (i = 0; i < num; i++) {
1398 struct wpa_scan_res *res = scan_res->res[i];
1399 buf[0] = res->bssid[5];
1400 buf[1] = res->qual & 0xff;
1401 buf[2] = res->noise & 0xff;
1402 buf[3] = res->level & 0xff;
1403 buf[4] = res->tsf & 0xff;
1404 random_add_randomness(buf, sizeof(buf));
1406 #endif /* CONFIG_NO_RANDOM_POOL */
1408 if (own_request && wpa_s->scan_res_handler &&
1409 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1410 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1411 struct wpa_scan_results *scan_res);
1413 scan_res_handler = wpa_s->scan_res_handler;
1414 wpa_s->scan_res_handler = NULL;
1415 scan_res_handler(wpa_s, scan_res);
1417 goto scan_work_done;
1421 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1423 if (wpa_s->ap_iface->scan_cb)
1424 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1425 #endif /* CONFIG_AP */
1426 goto scan_work_done;
1429 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1430 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1431 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1432 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1433 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1434 wpa_s->manual_scan_id);
1435 wpa_s->manual_scan_use_id = 0;
1437 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1439 wpas_notify_scan_results(wpa_s);
1441 wpas_notify_scan_done(wpa_s, 1);
1443 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1444 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1445 wpa_scan_results_free(scan_res);
1449 if (wnm_scan_process(wpa_s, 1) > 0)
1450 goto scan_work_done;
1452 if (sme_proc_obss_scan(wpa_s) > 0)
1453 goto scan_work_done;
1455 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1456 goto scan_work_done;
1458 if (autoscan_notify_scan(wpa_s, scan_res))
1459 goto scan_work_done;
1461 if (wpa_s->disconnected) {
1462 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1463 goto scan_work_done;
1466 if (!wpas_driver_bss_selection(wpa_s) &&
1467 bgscan_notify_scan(wpa_s, scan_res) == 1)
1468 goto scan_work_done;
1470 wpas_wps_update_ap_info(wpa_s, scan_res);
1472 wpa_scan_results_free(scan_res);
1474 if (wpa_s->scan_work) {
1475 struct wpa_radio_work *work = wpa_s->scan_work;
1476 wpa_s->scan_work = NULL;
1477 radio_work_done(work);
1480 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1483 wpa_scan_results_free(scan_res);
1484 if (wpa_s->scan_work) {
1485 struct wpa_radio_work *work = wpa_s->scan_work;
1486 wpa_s->scan_work = NULL;
1487 radio_work_done(work);
1493 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1494 int new_scan, int own_request)
1496 struct wpa_bss *selected;
1497 struct wpa_ssid *ssid = NULL;
1498 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1500 if (time_to_reenable > 0) {
1501 wpa_dbg(wpa_s, MSG_DEBUG,
1502 "Postpone network selection by %d seconds since all networks are disabled",
1504 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1505 eloop_register_timeout(time_to_reenable, 0,
1506 wpas_network_reenabled, wpa_s, NULL);
1510 if (wpa_s->p2p_mgmt)
1511 return 0; /* no normal connection on p2p_mgmt interface */
1513 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1517 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1520 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1524 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1525 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1529 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1531 * Do not notify other virtual radios of scan results since we do not
1532 * want them to start other associations at the same time.
1538 wpa_msg(wpa_s, MSG_INFO,
1539 "Avoiding join because we already joined a mesh group");
1542 #endif /* CONFIG_MESH */
1543 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1544 ssid = wpa_supplicant_pick_new_network(wpa_s);
1546 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1547 wpa_supplicant_associate(wpa_s, NULL, ssid);
1549 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1550 } else if (own_request) {
1552 * No SSID found. If SCAN results are as a result of
1553 * own scan request and not due to a scan request on
1554 * another shared interface, try another scan.
1556 int timeout_sec = wpa_s->scan_interval;
1557 int timeout_usec = 0;
1561 res = wpas_p2p_scan_no_go_seen(wpa_s);
1567 if (wpa_s->p2p_in_provisioning ||
1568 wpa_s->show_group_started ||
1569 wpa_s->p2p_in_invitation) {
1571 * Use shorter wait during P2P Provisioning
1572 * state and during P2P join-a-group operation
1573 * to speed up group formation.
1576 timeout_usec = 250000;
1577 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1581 #endif /* CONFIG_P2P */
1582 #ifdef CONFIG_INTERWORKING
1583 if (wpa_s->conf->auto_interworking &&
1584 wpa_s->conf->interworking &&
1585 wpa_s->conf->cred) {
1586 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1587 "start ANQP fetch since no matching "
1589 wpa_s->network_select = 1;
1590 wpa_s->auto_network_select = 1;
1591 interworking_start_fetch_anqp(wpa_s);
1594 #endif /* CONFIG_INTERWORKING */
1596 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1597 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1599 timeout_usec = 500000;
1600 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1604 #endif /* CONFIG_WPS */
1605 if (wpa_supplicant_req_sched_scan(wpa_s))
1606 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1614 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1615 union wpa_event_data *data)
1617 struct wpa_supplicant *ifs;
1620 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1623 * Interface may have been removed, so must not dereference
1630 * If no scan results could be fetched, then no need to
1631 * notify those interfaces that did not actually request
1632 * this scan. Similarly, if scan results started a new operation on this
1633 * interface, do not notify other interfaces to avoid concurrent
1634 * operations during a connection attempt.
1640 * Check other interfaces to see if they share the same radio. If
1641 * so, they get updated with this same scan info.
1643 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1646 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1647 "sibling", ifs->ifname);
1648 _wpa_supplicant_event_scan_results(ifs, data, 0);
1655 #endif /* CONFIG_NO_SCAN_PROCESSING */
1658 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1660 #ifdef CONFIG_NO_SCAN_PROCESSING
1662 #else /* CONFIG_NO_SCAN_PROCESSING */
1663 struct os_reltime now;
1665 if (wpa_s->last_scan_res_used <= 0)
1668 os_get_reltime(&now);
1669 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1670 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1674 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1675 #endif /* CONFIG_NO_SCAN_PROCESSING */
1680 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1682 struct wpa_supplicant *wpa_s = eloop_ctx;
1684 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1687 if (!wpa_s->no_keep_alive) {
1688 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1689 MAC2STR(wpa_s->bssid));
1690 /* TODO: could skip this if normal data traffic has been sent */
1691 /* TODO: Consider using some more appropriate data frame for
1694 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1699 if (wpa_s->sme.bss_max_idle_period) {
1701 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1704 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1705 wnm_bss_keep_alive, wpa_s, NULL);
1707 #endif /* CONFIG_SME */
1711 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1712 const u8 *ies, size_t ies_len)
1714 struct ieee802_11_elems elems;
1719 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1723 if (elems.bss_max_idle_period) {
1725 wpa_s->sme.bss_max_idle_period =
1726 WPA_GET_LE16(elems.bss_max_idle_period);
1727 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1728 "TU)%s", wpa_s->sme.bss_max_idle_period,
1729 (elems.bss_max_idle_period[2] & 0x01) ?
1730 " (protected keep-live required)" : "");
1731 if (wpa_s->sme.bss_max_idle_period == 0)
1732 wpa_s->sme.bss_max_idle_period = 1;
1733 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1734 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1735 /* msec times 1000 */
1736 msec = wpa_s->sme.bss_max_idle_period * 1024;
1739 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1740 wnm_bss_keep_alive, wpa_s,
1744 #endif /* CONFIG_SME */
1747 #endif /* CONFIG_WNM */
1750 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1753 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1754 #endif /* CONFIG_WNM */
1758 #ifdef CONFIG_INTERWORKING
1760 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1765 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1766 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1768 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1775 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1776 const u8 *ies, size_t ies_len)
1778 struct ieee802_11_elems elems;
1783 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1786 if (elems.qos_map_set) {
1787 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1788 elems.qos_map_set_len);
1792 #endif /* CONFIG_INTERWORKING */
1795 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1796 union wpa_event_data *data)
1798 int l, len, found = 0, wpa_found, rsn_found;
1800 #ifdef CONFIG_IEEE80211R
1802 #endif /* CONFIG_IEEE80211R */
1804 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1805 if (data->assoc_info.req_ies)
1806 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1807 data->assoc_info.req_ies_len);
1808 if (data->assoc_info.resp_ies) {
1809 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1810 data->assoc_info.resp_ies_len);
1812 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1813 data->assoc_info.resp_ies_len);
1814 #endif /* CONFIG_TDLS */
1816 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1817 data->assoc_info.resp_ies_len);
1818 #endif /* CONFIG_WNM */
1819 #ifdef CONFIG_INTERWORKING
1820 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1821 data->assoc_info.resp_ies_len);
1822 #endif /* CONFIG_INTERWORKING */
1824 if (data->assoc_info.beacon_ies)
1825 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1826 data->assoc_info.beacon_ies,
1827 data->assoc_info.beacon_ies_len);
1828 if (data->assoc_info.freq)
1829 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1830 data->assoc_info.freq);
1832 p = data->assoc_info.req_ies;
1833 l = data->assoc_info.req_ies_len;
1835 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1836 while (p && l >= 2) {
1839 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1843 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1844 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1845 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1846 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1849 wpa_find_assoc_pmkid(wpa_s);
1855 if (!found && data->assoc_info.req_ies)
1856 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1858 #ifdef CONFIG_IEEE80211R
1860 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1861 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1862 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1863 data->assoc_info.resp_ies,
1864 data->assoc_info.resp_ies_len,
1866 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1867 "Reassociation Response failed");
1868 wpa_supplicant_deauthenticate(
1869 wpa_s, WLAN_REASON_INVALID_IE);
1874 p = data->assoc_info.resp_ies;
1875 l = data->assoc_info.resp_ies_len;
1877 #ifdef CONFIG_WPS_STRICT
1878 if (p && wpa_s->current_ssid &&
1879 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1881 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1883 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1884 "include WPS IE in (Re)Association Response");
1888 if (wps_validate_assoc_resp(wps) < 0) {
1890 wpa_supplicant_deauthenticate(
1891 wpa_s, WLAN_REASON_INVALID_IE);
1896 #endif /* CONFIG_WPS_STRICT */
1898 /* Go through the IEs and make a copy of the MDIE, if present. */
1899 while (p && l >= 2) {
1902 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1906 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1907 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1908 wpa_s->sme.ft_used = 1;
1909 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1910 MOBILITY_DOMAIN_ID_LEN);
1916 #endif /* CONFIG_SME */
1918 /* Process FT when SME is in the driver */
1919 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1920 wpa_ft_is_completed(wpa_s->wpa)) {
1921 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1922 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1923 data->assoc_info.resp_ies,
1924 data->assoc_info.resp_ies_len,
1926 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1927 "Reassociation Response failed");
1928 wpa_supplicant_deauthenticate(
1929 wpa_s, WLAN_REASON_INVALID_IE);
1932 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1935 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1936 data->assoc_info.resp_ies_len);
1937 #endif /* CONFIG_IEEE80211R */
1939 /* WPA/RSN IE from Beacon/ProbeResp */
1940 p = data->assoc_info.beacon_ies;
1941 l = data->assoc_info.beacon_ies_len;
1943 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1945 wpa_found = rsn_found = 0;
1946 while (p && l >= 2) {
1949 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1954 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1955 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1957 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1961 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1963 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1970 if (!wpa_found && data->assoc_info.beacon_ies)
1971 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1972 if (!rsn_found && data->assoc_info.beacon_ies)
1973 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1974 if (wpa_found || rsn_found)
1975 wpa_s->ap_ies_from_associnfo = 1;
1977 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1978 wpa_s->assoc_freq != data->assoc_info.freq) {
1979 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1981 wpa_s->assoc_freq, data->assoc_info.freq);
1982 wpa_supplicant_update_scan_results(wpa_s);
1985 wpa_s->assoc_freq = data->assoc_info.freq;
1991 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1993 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1995 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1998 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2001 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2002 WPA_IE_VENDOR_TYPE);
2003 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2005 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2006 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2007 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2008 bss_rsn ? 2 + bss_rsn[1] : 0))
2015 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2016 union wpa_event_data *data)
2022 if (wpa_s->ap_iface) {
2025 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2026 data->assoc_info.addr,
2027 data->assoc_info.req_ies,
2028 data->assoc_info.req_ies_len,
2029 data->assoc_info.reassoc);
2032 #endif /* CONFIG_AP */
2034 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2036 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2037 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2040 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2041 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2042 wpa_supplicant_deauthenticate(
2043 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2047 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2048 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2049 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2050 MACSTR, MAC2STR(bssid));
2051 random_add_randomness(bssid, ETH_ALEN);
2052 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2053 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2054 wpas_notify_bssid_changed(wpa_s);
2056 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2057 wpa_clear_keys(wpa_s, bssid);
2059 if (wpa_supplicant_select_config(wpa_s) < 0) {
2060 wpa_supplicant_deauthenticate(
2061 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2065 if (wpa_s->conf->ap_scan == 1 &&
2066 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2067 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
2068 wpa_msg(wpa_s, MSG_WARNING,
2069 "WPA/RSN IEs not updated");
2074 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2075 wpa_s->sme.prev_bssid_set = 1;
2076 wpa_s->sme.last_unprot_disconnect.sec = 0;
2077 #endif /* CONFIG_SME */
2079 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2080 if (wpa_s->current_ssid) {
2081 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2082 * initialized before association, but for other modes,
2083 * initialize PC/SC here, if the current configuration needs
2084 * smartcard or SIM/USIM. */
2085 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2087 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2089 l2_packet_notify_auth_start(wpa_s->l2);
2092 * Set portEnabled first to FALSE in order to get EAP state machine out
2093 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2094 * state machine may transit to AUTHENTICATING state based on obsolete
2095 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2096 * AUTHENTICATED without ever giving chance to EAP state machine to
2099 if (!ft_completed) {
2100 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2101 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2103 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2104 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2105 /* 802.1X::portControl = Auto */
2106 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2107 wpa_s->eapol_received = 0;
2108 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2109 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2110 (wpa_s->current_ssid &&
2111 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2112 if (wpa_s->current_ssid &&
2113 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2115 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2117 * Set the key after having received joined-IBSS event
2120 wpa_supplicant_set_wpa_none_key(wpa_s,
2121 wpa_s->current_ssid);
2123 wpa_supplicant_cancel_auth_timeout(wpa_s);
2124 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2125 } else if (!ft_completed) {
2126 /* Timeout for receiving the first EAPOL packet */
2127 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2129 wpa_supplicant_cancel_scan(wpa_s);
2131 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2132 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2134 * We are done; the driver will take care of RSN 4-way
2137 wpa_supplicant_cancel_auth_timeout(wpa_s);
2138 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2139 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2140 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2141 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2142 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2144 * The driver will take care of RSN 4-way handshake, so we need
2145 * to allow EAPOL supplicant to complete its work without
2146 * waiting for WPA supplicant.
2148 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2149 } else if (ft_completed) {
2151 * FT protocol completed - make sure EAPOL state machine ends
2152 * up in authenticated.
2154 wpa_supplicant_cancel_auth_timeout(wpa_s);
2155 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2156 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2157 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2160 wpa_s->last_eapol_matches_bssid = 0;
2162 if (wpa_s->pending_eapol_rx) {
2163 struct os_reltime now, age;
2164 os_get_reltime(&now);
2165 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2166 if (age.sec == 0 && age.usec < 100000 &&
2167 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2169 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2170 "frame that was received just before "
2171 "association notification");
2172 wpa_supplicant_rx_eapol(
2173 wpa_s, wpa_s->pending_eapol_rx_src,
2174 wpabuf_head(wpa_s->pending_eapol_rx),
2175 wpabuf_len(wpa_s->pending_eapol_rx));
2177 wpabuf_free(wpa_s->pending_eapol_rx);
2178 wpa_s->pending_eapol_rx = NULL;
2181 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2182 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2183 wpa_s->current_ssid &&
2184 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2185 /* Set static WEP keys again */
2186 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2189 #ifdef CONFIG_IBSS_RSN
2190 if (wpa_s->current_ssid &&
2191 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2192 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2193 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2194 wpa_s->ibss_rsn == NULL) {
2195 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2196 if (!wpa_s->ibss_rsn) {
2197 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2198 wpa_supplicant_deauthenticate(
2199 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2203 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2205 #endif /* CONFIG_IBSS_RSN */
2207 wpas_wps_notify_assoc(wpa_s, bssid);
2210 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2211 data->assoc_info.resp_ies_len,
2212 &data->assoc_info.wmm_params);
2214 if (wpa_s->reassoc_same_bss)
2215 wmm_ac_restore_tspecs(wpa_s);
2220 static int disconnect_reason_recoverable(u16 reason_code)
2222 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2223 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2224 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2228 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2230 int locally_generated)
2234 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2236 * At least Host AP driver and a Prism3 card seemed to be
2237 * generating streams of disconnected events when configuring
2238 * IBSS for WPA-None. Ignore them for now.
2243 bssid = wpa_s->bssid;
2244 if (is_zero_ether_addr(bssid))
2245 bssid = wpa_s->pending_bssid;
2247 if (!is_zero_ether_addr(bssid) ||
2248 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2249 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2251 MAC2STR(bssid), reason_code,
2252 locally_generated ? " locally_generated=1" : "");
2257 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2258 int locally_generated)
2260 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2261 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2262 return 0; /* Not in 4-way handshake with PSK */
2265 * It looks like connection was lost while trying to go through PSK
2266 * 4-way handshake. Filter out known disconnection cases that are caused
2267 * by something else than PSK mismatch to avoid confusing reports.
2270 if (locally_generated) {
2271 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2279 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2281 int locally_generated)
2285 u8 prev_pending_bssid[ETH_ALEN];
2286 struct wpa_bss *fast_reconnect = NULL;
2287 struct wpa_ssid *fast_reconnect_ssid = NULL;
2288 struct wpa_ssid *last_ssid;
2290 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2291 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2293 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2295 * At least Host AP driver and a Prism3 card seemed to be
2296 * generating streams of disconnected events when configuring
2297 * IBSS for WPA-None. Ignore them for now.
2299 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2300 "IBSS/WPA-None mode");
2304 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2305 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2306 "pre-shared key may be incorrect");
2307 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2308 return; /* P2P group removed */
2309 wpas_auth_failed(wpa_s, "WRONG_KEY");
2311 if (!wpa_s->disconnected &&
2312 (!wpa_s->auto_reconnect_disabled ||
2313 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2314 wpas_wps_searching(wpa_s))) {
2315 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2316 "reconnect (wps=%d/%d wpa_state=%d)",
2317 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2318 wpas_wps_searching(wpa_s),
2320 if (wpa_s->wpa_state == WPA_COMPLETED &&
2321 wpa_s->current_ssid &&
2322 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2323 !locally_generated &&
2324 disconnect_reason_recoverable(reason_code)) {
2326 * It looks like the AP has dropped association with
2327 * us, but could allow us to get back in. Try to
2328 * reconnect to the same BSS without full scan to save
2329 * time for some common cases.
2331 fast_reconnect = wpa_s->current_bss;
2332 fast_reconnect_ssid = wpa_s->current_ssid;
2333 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2334 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2336 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2339 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2340 "try to re-connect");
2341 wpa_s->reassociate = 0;
2342 wpa_s->disconnected = 1;
2343 wpa_supplicant_cancel_sched_scan(wpa_s);
2345 bssid = wpa_s->bssid;
2346 if (is_zero_ether_addr(bssid))
2347 bssid = wpa_s->pending_bssid;
2348 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2349 wpas_connection_failed(wpa_s, bssid);
2350 wpa_sm_notify_disassoc(wpa_s->wpa);
2351 if (locally_generated)
2352 wpa_s->disconnect_reason = -reason_code;
2354 wpa_s->disconnect_reason = reason_code;
2355 wpas_notify_disconnect_reason(wpa_s);
2356 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2357 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2358 wpa_clear_keys(wpa_s, wpa_s->bssid);
2360 last_ssid = wpa_s->current_ssid;
2361 wpa_supplicant_mark_disassoc(wpa_s);
2363 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2364 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2365 wpa_s->current_ssid = last_ssid;
2368 if (fast_reconnect &&
2369 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2370 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2371 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2372 fast_reconnect->ssid_len) &&
2373 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2374 #ifndef CONFIG_NO_SCAN_PROCESSING
2375 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2376 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2377 fast_reconnect_ssid) < 0) {
2378 /* Recover through full scan */
2379 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2381 #endif /* CONFIG_NO_SCAN_PROCESSING */
2382 } else if (fast_reconnect) {
2384 * Could not reconnect to the same BSS due to network being
2385 * disabled. Use a new scan to match the alternative behavior
2386 * above, i.e., to continue automatic reconnection attempt in a
2387 * way that enforces disabled network rules.
2389 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2394 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2395 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2397 struct wpa_supplicant *wpa_s = eloop_ctx;
2399 if (!wpa_s->pending_mic_error_report)
2402 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2403 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2404 wpa_s->pending_mic_error_report = 0;
2406 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2410 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2411 union wpa_event_data *data)
2414 struct os_reltime t;
2416 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2417 pairwise = (data && data->michael_mic_failure.unicast);
2419 if ((wpa_s->last_michael_mic_error.sec &&
2420 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2421 wpa_s->pending_mic_error_report) {
2422 if (wpa_s->pending_mic_error_report) {
2424 * Send the pending MIC error report immediately since
2425 * we are going to start countermeasures and AP better
2428 wpa_sm_key_request(wpa_s->wpa, 1,
2429 wpa_s->pending_mic_error_pairwise);
2432 /* Send the new MIC error report immediately since we are going
2433 * to start countermeasures and AP better do the same.
2435 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2437 /* initialize countermeasures */
2438 wpa_s->countermeasures = 1;
2440 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2442 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2445 * Need to wait for completion of request frame. We do not get
2446 * any callback for the message completion, so just wait a
2447 * short while and hope for the best. */
2450 wpa_drv_set_countermeasures(wpa_s, 1);
2451 wpa_supplicant_deauthenticate(wpa_s,
2452 WLAN_REASON_MICHAEL_MIC_FAILURE);
2453 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2455 eloop_register_timeout(60, 0,
2456 wpa_supplicant_stop_countermeasures,
2458 /* TODO: mark the AP rejected for 60 second. STA is
2459 * allowed to associate with another AP.. */
2461 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2462 if (wpa_s->mic_errors_seen) {
2464 * Reduce the effectiveness of Michael MIC error
2465 * reports as a means for attacking against TKIP if
2466 * more than one MIC failure is noticed with the same
2467 * PTK. We delay the transmission of the reports by a
2468 * random time between 0 and 60 seconds in order to
2469 * force the attacker wait 60 seconds before getting
2470 * the information on whether a frame resulted in a MIC
2476 if (os_get_random(rval, sizeof(rval)) < 0)
2477 sec = os_random() % 60;
2479 sec = WPA_GET_BE32(rval) % 60;
2480 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2481 "report %d seconds", sec);
2482 wpa_s->pending_mic_error_report = 1;
2483 wpa_s->pending_mic_error_pairwise = pairwise;
2484 eloop_cancel_timeout(
2485 wpa_supplicant_delayed_mic_error_report,
2487 eloop_register_timeout(
2488 sec, os_random() % 1000000,
2489 wpa_supplicant_delayed_mic_error_report,
2492 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2494 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2495 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2496 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2498 wpa_s->last_michael_mic_error = t;
2499 wpa_s->mic_errors_seen++;
2503 #ifdef CONFIG_TERMINATE_ONLASTIF
2504 static int any_interfaces(struct wpa_supplicant *head)
2506 struct wpa_supplicant *wpa_s;
2508 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2509 if (!wpa_s->interface_removed)
2513 #endif /* CONFIG_TERMINATE_ONLASTIF */
2517 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2518 union wpa_event_data *data)
2520 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2523 switch (data->interface_status.ievent) {
2524 case EVENT_INTERFACE_ADDED:
2525 if (!wpa_s->interface_removed)
2527 wpa_s->interface_removed = 0;
2528 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2529 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2530 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2531 "driver after interface was added");
2534 case EVENT_INTERFACE_REMOVED:
2535 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2536 wpa_s->interface_removed = 1;
2537 wpa_supplicant_mark_disassoc(wpa_s);
2538 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2539 l2_packet_deinit(wpa_s->l2);
2541 #ifdef CONFIG_TERMINATE_ONLASTIF
2542 /* check if last interface */
2543 if (!any_interfaces(wpa_s->global->ifaces))
2545 #endif /* CONFIG_TERMINATE_ONLASTIF */
2551 #ifdef CONFIG_PEERKEY
2553 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2554 union wpa_event_data *data)
2558 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2560 #endif /* CONFIG_PEERKEY */
2564 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2565 union wpa_event_data *data)
2569 switch (data->tdls.oper) {
2570 case TDLS_REQUEST_SETUP:
2571 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2572 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2573 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2575 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2577 case TDLS_REQUEST_TEARDOWN:
2578 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2579 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2580 data->tdls.reason_code);
2582 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2585 case TDLS_REQUEST_DISCOVER:
2586 wpa_tdls_send_discovery_request(wpa_s->wpa,
2591 #endif /* CONFIG_TDLS */
2595 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2596 union wpa_event_data *data)
2600 switch (data->wnm.oper) {
2601 case WNM_OPER_SLEEP:
2602 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2603 "(action=%d, intval=%d)",
2604 data->wnm.sleep_action, data->wnm.sleep_intval);
2605 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2606 data->wnm.sleep_intval, NULL);
2610 #endif /* CONFIG_WNM */
2613 #ifdef CONFIG_IEEE80211R
2615 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2616 union wpa_event_data *data)
2621 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2622 data->ft_ies.ies_len,
2623 data->ft_ies.ft_action,
2624 data->ft_ies.target_ap,
2625 data->ft_ies.ric_ies,
2626 data->ft_ies.ric_ies_len) < 0) {
2627 /* TODO: prevent MLME/driver from trying to associate? */
2630 #endif /* CONFIG_IEEE80211R */
2633 #ifdef CONFIG_IBSS_RSN
2634 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2635 union wpa_event_data *data)
2637 struct wpa_ssid *ssid;
2638 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2642 ssid = wpa_s->current_ssid;
2645 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2648 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2652 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2653 union wpa_event_data *data)
2655 struct wpa_ssid *ssid = wpa_s->current_ssid;
2660 /* check if the ssid is correctly configured as IBSS/RSN */
2661 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2664 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2665 data->rx_mgmt.frame_len);
2667 #endif /* CONFIG_IBSS_RSN */
2670 #ifdef CONFIG_IEEE80211R
2671 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2674 const u8 *sta_addr, *target_ap_addr;
2677 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2678 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2679 return; /* only SME case supported for now */
2680 if (len < 1 + 2 * ETH_ALEN + 2)
2683 return; /* Only FT Action Response is supported for now */
2684 sta_addr = data + 1;
2685 target_ap_addr = data + 1 + ETH_ALEN;
2686 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2687 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2688 MACSTR " TargetAP " MACSTR " status %u",
2689 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2691 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2692 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2693 " in FT Action Response", MAC2STR(sta_addr));
2698 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2699 "failure (status code %d)", status);
2700 /* TODO: report error to FT code(?) */
2704 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2705 len - (1 + 2 * ETH_ALEN + 2), 1,
2706 target_ap_addr, NULL, 0) < 0)
2711 struct wpa_bss *bss;
2712 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2714 wpa_s->sme.freq = bss->freq;
2715 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2716 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2719 #endif /* CONFIG_SME */
2721 #endif /* CONFIG_IEEE80211R */
2724 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2725 struct unprot_deauth *e)
2727 #ifdef CONFIG_IEEE80211W
2728 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2729 "dropped: " MACSTR " -> " MACSTR
2730 " (reason code %u)",
2731 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2732 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2733 #endif /* CONFIG_IEEE80211W */
2737 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2738 struct unprot_disassoc *e)
2740 #ifdef CONFIG_IEEE80211W
2741 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2742 "dropped: " MACSTR " -> " MACSTR
2743 " (reason code %u)",
2744 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2745 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2746 #endif /* CONFIG_IEEE80211W */
2750 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2751 u16 reason_code, int locally_generated,
2752 const u8 *ie, size_t ie_len, int deauth)
2755 if (wpa_s->ap_iface && addr) {
2756 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2760 if (wpa_s->ap_iface) {
2761 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2764 #endif /* CONFIG_AP */
2766 if (!locally_generated)
2767 wpa_s->own_disconnect_req = 0;
2769 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2771 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2772 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2773 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2774 eapol_sm_failed(wpa_s->eapol))) &&
2775 !wpa_s->eap_expected_failure))
2776 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2779 if (deauth && reason_code > 0) {
2780 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2781 locally_generated) > 0) {
2783 * The interface was removed, so cannot continue
2784 * processing any additional operations after this.
2789 #endif /* CONFIG_P2P */
2791 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2796 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2797 struct disassoc_info *info)
2799 u16 reason_code = 0;
2800 int locally_generated = 0;
2801 const u8 *addr = NULL;
2802 const u8 *ie = NULL;
2805 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2810 ie_len = info->ie_len;
2811 reason_code = info->reason_code;
2812 locally_generated = info->locally_generated;
2813 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2814 locally_generated ? " (locally generated)" : "");
2816 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2818 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2823 if (wpa_s->ap_iface && info && info->addr) {
2824 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2828 if (wpa_s->ap_iface) {
2829 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2832 #endif /* CONFIG_AP */
2836 wpas_p2p_disassoc_notif(
2837 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2840 #endif /* CONFIG_P2P */
2842 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2843 sme_event_disassoc(wpa_s, info);
2845 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2850 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2851 struct deauth_info *info)
2853 u16 reason_code = 0;
2854 int locally_generated = 0;
2855 const u8 *addr = NULL;
2856 const u8 *ie = NULL;
2859 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2864 ie_len = info->ie_len;
2865 reason_code = info->reason_code;
2866 locally_generated = info->locally_generated;
2867 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2869 locally_generated ? " (locally generated)" : "");
2871 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2874 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2878 wpa_reset_ft_completed(wpa_s->wpa);
2880 wpas_event_disconnect(wpa_s, addr, reason_code,
2881 locally_generated, ie, ie_len, 1);
2885 static const char * reg_init_str(enum reg_change_initiator init)
2888 case REGDOM_SET_BY_CORE:
2890 case REGDOM_SET_BY_USER:
2892 case REGDOM_SET_BY_DRIVER:
2894 case REGDOM_SET_BY_COUNTRY_IE:
2895 return "COUNTRY_IE";
2896 case REGDOM_BEACON_HINT:
2897 return "BEACON_HINT";
2903 static const char * reg_type_str(enum reg_type type)
2906 case REGDOM_TYPE_UNKNOWN:
2908 case REGDOM_TYPE_COUNTRY:
2910 case REGDOM_TYPE_WORLD:
2912 case REGDOM_TYPE_CUSTOM_WORLD:
2913 return "CUSTOM_WORLD";
2914 case REGDOM_TYPE_INTERSECTION:
2915 return "INTERSECTION";
2921 static void wpa_supplicant_update_channel_list(
2922 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2924 struct wpa_supplicant *ifs;
2926 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2927 reg_init_str(info->initiator), reg_type_str(info->type),
2928 info->alpha2[0] ? " alpha2=" : "",
2929 info->alpha2[0] ? info->alpha2 : "");
2931 if (wpa_s->drv_priv == NULL)
2932 return; /* Ignore event during drv initialization */
2934 free_hw_features(wpa_s);
2935 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2936 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2938 wpas_p2p_update_channel_list(wpa_s);
2941 * Check other interfaces to see if they share the same radio. If
2942 * so, they get updated with this same hw mode info.
2944 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2947 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2949 free_hw_features(ifs);
2950 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2951 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2955 /* Restart sched_scan with updated channel list */
2956 if (wpa_s->sched_scanning) {
2957 wpa_dbg(wpa_s, MSG_DEBUG,
2958 "Channel list changed restart sched scan.");
2959 wpa_supplicant_cancel_sched_scan(wpa_s);
2960 wpa_supplicant_req_scan(wpa_s, 0, 0);
2965 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2966 const u8 *frame, size_t len, int freq,
2969 const struct ieee80211_mgmt *mgmt;
2974 if (len < IEEE80211_HDRLEN + 2)
2977 mgmt = (const struct ieee80211_mgmt *) frame;
2978 payload = frame + IEEE80211_HDRLEN;
2979 category = *payload++;
2980 plen = len - IEEE80211_HDRLEN - 1;
2982 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2983 " Category=%u DataLen=%d freq=%d MHz",
2984 MAC2STR(mgmt->sa), category, (int) plen, freq);
2986 if (category == WLAN_ACTION_WMM) {
2987 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2991 #ifdef CONFIG_IEEE80211R
2992 if (category == WLAN_ACTION_FT) {
2993 ft_rx_action(wpa_s, payload, plen);
2996 #endif /* CONFIG_IEEE80211R */
2998 #ifdef CONFIG_IEEE80211W
3000 if (category == WLAN_ACTION_SA_QUERY) {
3001 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3004 #endif /* CONFIG_SME */
3005 #endif /* CONFIG_IEEE80211W */
3008 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3009 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3012 #endif /* CONFIG_WNM */
3015 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3016 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3017 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3018 mgmt->u.action.category,
3019 payload, plen, freq) == 0)
3021 #endif /* CONFIG_GAS */
3024 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3025 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3026 wpa_dbg(wpa_s, MSG_DEBUG,
3027 "TDLS: Received Discovery Response from " MACSTR,
3031 #endif /* CONFIG_TDLS */
3033 #ifdef CONFIG_INTERWORKING
3034 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3035 payload[0] == QOS_QOS_MAP_CONFIG) {
3036 const u8 *pos = payload + 1;
3037 size_t qlen = plen - 1;
3038 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3039 MACSTR, MAC2STR(mgmt->sa));
3040 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3041 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3042 pos[1] <= qlen - 2 && pos[1] >= 16)
3043 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3046 #endif /* CONFIG_INTERWORKING */
3048 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3049 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3050 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3054 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3055 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3056 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3057 payload + 1, plen - 1,
3062 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3063 category, payload, plen, freq);
3065 mesh_mpm_action_rx(wpa_s, mgmt, len);
3069 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3070 union wpa_event_data *event)
3073 struct wpa_supplicant *ifs;
3074 #endif /* CONFIG_P2P */
3075 struct wpa_freq_range_list *list;
3078 list = &event->freq_range;
3081 str = freq_range_list_str(list);
3082 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3086 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3087 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3090 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3091 wpas_p2p_update_channel_list(wpa_s);
3094 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3096 if (!ifs->current_ssid ||
3097 !ifs->current_ssid->p2p_group ||
3098 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
3099 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
3102 freq = ifs->current_ssid->frequency;
3103 if (!freq_range_list_includes(list, freq)) {
3104 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
3109 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
3111 /* TODO: Consider using CSA or removing the group within
3113 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
3115 #endif /* CONFIG_P2P */
3121 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3122 union wpa_event_data *data)
3124 wpa_dbg(wpa_s, MSG_DEBUG,
3125 "Connection authorized by device, previous state %d",
3127 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3128 wpa_supplicant_cancel_auth_timeout(wpa_s);
3129 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3130 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3131 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3133 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3134 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3135 data->assoc_info.ptk_kck_len,
3136 data->assoc_info.ptk_kek,
3137 data->assoc_info.ptk_kek_len);
3141 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3142 union wpa_event_data *data)
3144 struct wpa_supplicant *wpa_s = ctx;
3146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3147 event != EVENT_INTERFACE_ENABLED &&
3148 event != EVENT_INTERFACE_STATUS &&
3149 event != EVENT_SCHED_SCAN_STOPPED) {
3150 wpa_dbg(wpa_s, MSG_DEBUG,
3151 "Ignore event %s (%d) while interface is disabled",
3152 event_to_string(event), event);
3156 #ifndef CONFIG_NO_STDOUT_DEBUG
3158 int level = MSG_DEBUG;
3160 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3161 const struct ieee80211_hdr *hdr;
3163 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3164 fc = le_to_host16(hdr->frame_control);
3165 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3166 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3167 level = MSG_EXCESSIVE;
3170 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3171 event_to_string(event), event);
3173 #endif /* CONFIG_NO_STDOUT_DEBUG */
3177 sme_event_auth(wpa_s, data);
3180 wpa_supplicant_event_assoc(wpa_s, data);
3181 if (data && data->assoc_info.authorized)
3182 wpa_supplicant_event_assoc_auth(wpa_s, data);
3184 case EVENT_DISASSOC:
3185 wpas_event_disassoc(wpa_s,
3186 data ? &data->disassoc_info : NULL);
3189 wpas_event_deauth(wpa_s,
3190 data ? &data->deauth_info : NULL);
3192 case EVENT_MICHAEL_MIC_FAILURE:
3193 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3195 #ifndef CONFIG_NO_SCAN_PROCESSING
3196 case EVENT_SCAN_STARTED:
3197 os_get_reltime(&wpa_s->scan_start_time);
3198 if (wpa_s->own_scan_requested) {
3199 struct os_reltime diff;
3201 os_reltime_sub(&wpa_s->scan_start_time,
3202 &wpa_s->scan_trigger_time, &diff);
3203 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3204 diff.sec, diff.usec);
3205 wpa_s->own_scan_requested = 0;
3206 wpa_s->own_scan_running = 1;
3207 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3208 wpa_s->manual_scan_use_id) {
3209 wpa_msg_ctrl(wpa_s, MSG_INFO,
3210 WPA_EVENT_SCAN_STARTED "id=%u",
3211 wpa_s->manual_scan_id);
3213 wpa_msg_ctrl(wpa_s, MSG_INFO,
3214 WPA_EVENT_SCAN_STARTED);
3217 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3218 wpa_s->radio->external_scan_running = 1;
3219 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3222 case EVENT_SCAN_RESULTS:
3223 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3224 struct os_reltime now, diff;
3225 os_get_reltime(&now);
3226 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3227 wpa_s->scan_start_time.sec = 0;
3228 wpa_s->scan_start_time.usec = 0;
3229 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3230 diff.sec, diff.usec);
3232 if (wpa_supplicant_event_scan_results(wpa_s, data))
3233 break; /* interface may have been removed */
3234 wpa_s->own_scan_running = 0;
3235 wpa_s->radio->external_scan_running = 0;
3236 radio_work_check_next(wpa_s);
3238 #endif /* CONFIG_NO_SCAN_PROCESSING */
3239 case EVENT_ASSOCINFO:
3240 wpa_supplicant_event_associnfo(wpa_s, data);
3242 case EVENT_INTERFACE_STATUS:
3243 wpa_supplicant_event_interface_status(wpa_s, data);
3245 case EVENT_PMKID_CANDIDATE:
3246 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3248 #ifdef CONFIG_PEERKEY
3249 case EVENT_STKSTART:
3250 wpa_supplicant_event_stkstart(wpa_s, data);
3252 #endif /* CONFIG_PEERKEY */
3255 wpa_supplicant_event_tdls(wpa_s, data);
3257 #endif /* CONFIG_TDLS */
3260 wpa_supplicant_event_wnm(wpa_s, data);
3262 #endif /* CONFIG_WNM */
3263 #ifdef CONFIG_IEEE80211R
3264 case EVENT_FT_RESPONSE:
3265 wpa_supplicant_event_ft_response(wpa_s, data);
3267 #endif /* CONFIG_IEEE80211R */
3268 #ifdef CONFIG_IBSS_RSN
3269 case EVENT_IBSS_RSN_START:
3270 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3272 #endif /* CONFIG_IBSS_RSN */
3273 case EVENT_ASSOC_REJECT:
3274 if (data->assoc_reject.bssid)
3275 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3276 "bssid=" MACSTR " status_code=%u",
3277 MAC2STR(data->assoc_reject.bssid),
3278 data->assoc_reject.status_code);
3280 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3282 data->assoc_reject.status_code);
3283 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3284 sme_event_assoc_reject(wpa_s, data);
3286 const u8 *bssid = data->assoc_reject.bssid;
3287 if (bssid == NULL || is_zero_ether_addr(bssid))
3288 bssid = wpa_s->pending_bssid;
3289 wpas_connection_failed(wpa_s, bssid);
3290 wpa_supplicant_mark_disassoc(wpa_s);
3293 case EVENT_AUTH_TIMED_OUT:
3294 /* It is possible to get this event from earlier connection */
3295 if (wpa_s->current_ssid &&
3296 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3297 wpa_dbg(wpa_s, MSG_DEBUG,
3298 "Ignore AUTH_TIMED_OUT in mesh configuration");
3301 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3302 sme_event_auth_timed_out(wpa_s, data);
3304 case EVENT_ASSOC_TIMED_OUT:
3305 /* It is possible to get this event from earlier connection */
3306 if (wpa_s->current_ssid &&
3307 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3308 wpa_dbg(wpa_s, MSG_DEBUG,
3309 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3312 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3313 sme_event_assoc_timed_out(wpa_s, data);
3315 case EVENT_TX_STATUS:
3316 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3317 " type=%d stype=%d",
3318 MAC2STR(data->tx_status.dst),
3319 data->tx_status.type, data->tx_status.stype);
3321 if (wpa_s->ap_iface == NULL) {
3322 #ifdef CONFIG_OFFCHANNEL
3323 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3324 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3325 offchannel_send_action_tx_status(
3326 wpa_s, data->tx_status.dst,
3327 data->tx_status.data,
3328 data->tx_status.data_len,
3329 data->tx_status.ack ?
3330 OFFCHANNEL_SEND_ACTION_SUCCESS :
3331 OFFCHANNEL_SEND_ACTION_NO_ACK);
3332 #endif /* CONFIG_OFFCHANNEL */
3335 #endif /* CONFIG_AP */
3336 #ifdef CONFIG_OFFCHANNEL
3337 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3338 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3340 * Catch TX status events for Action frames we sent via group
3341 * interface in GO mode.
3343 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3344 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3345 os_memcmp(wpa_s->parent->pending_action_dst,
3346 data->tx_status.dst, ETH_ALEN) == 0) {
3347 offchannel_send_action_tx_status(
3348 wpa_s->parent, data->tx_status.dst,
3349 data->tx_status.data,
3350 data->tx_status.data_len,
3351 data->tx_status.ack ?
3352 OFFCHANNEL_SEND_ACTION_SUCCESS :
3353 OFFCHANNEL_SEND_ACTION_NO_ACK);
3356 #endif /* CONFIG_OFFCHANNEL */
3358 switch (data->tx_status.type) {
3359 case WLAN_FC_TYPE_MGMT:
3360 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3361 data->tx_status.data_len,
3362 data->tx_status.stype,
3363 data->tx_status.ack);
3365 case WLAN_FC_TYPE_DATA:
3366 ap_tx_status(wpa_s, data->tx_status.dst,
3367 data->tx_status.data,
3368 data->tx_status.data_len,
3369 data->tx_status.ack);
3372 #endif /* CONFIG_AP */
3375 case EVENT_EAPOL_TX_STATUS:
3376 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3377 data->eapol_tx_status.data,
3378 data->eapol_tx_status.data_len,
3379 data->eapol_tx_status.ack);
3381 case EVENT_DRIVER_CLIENT_POLL_OK:
3382 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3384 case EVENT_RX_FROM_UNKNOWN:
3385 if (wpa_s->ap_iface == NULL)
3387 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3388 data->rx_from_unknown.wds);
3390 case EVENT_CH_SWITCH:
3393 if (!wpa_s->ap_iface) {
3394 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3395 "event in non-AP mode");
3399 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3400 data->ch_switch.ht_enabled,
3401 data->ch_switch.ch_offset,
3402 data->ch_switch.ch_width,
3403 data->ch_switch.cf1,
3404 data->ch_switch.cf2);
3407 case EVENT_DFS_RADAR_DETECTED:
3409 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3411 case EVENT_DFS_CAC_STARTED:
3413 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3415 case EVENT_DFS_CAC_FINISHED:
3417 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3419 case EVENT_DFS_CAC_ABORTED:
3421 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3423 case EVENT_DFS_NOP_FINISHED:
3425 wpas_event_dfs_cac_nop_finished(wpa_s,
3428 #endif /* NEED_AP_MLME */
3429 #endif /* CONFIG_AP */
3430 case EVENT_RX_MGMT: {
3432 const struct ieee80211_mgmt *mgmt;
3434 #ifdef CONFIG_TESTING_OPTIONS
3435 if (wpa_s->ext_mgmt_frame_handling) {
3436 struct rx_mgmt *rx = &data->rx_mgmt;
3437 size_t hex_len = 2 * rx->frame_len + 1;
3438 char *hex = os_malloc(hex_len);
3440 wpa_snprintf_hex(hex, hex_len,
3441 rx->frame, rx->frame_len);
3442 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3443 rx->freq, rx->datarate, rx->ssi_signal,
3449 #endif /* CONFIG_TESTING_OPTIONS */
3451 mgmt = (const struct ieee80211_mgmt *)
3452 data->rx_mgmt.frame;
3453 fc = le_to_host16(mgmt->frame_control);
3454 stype = WLAN_FC_GET_STYPE(fc);
3457 if (wpa_s->ap_iface == NULL) {
3458 #endif /* CONFIG_AP */
3460 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3461 data->rx_mgmt.frame_len > 24) {
3462 const u8 *src = mgmt->sa;
3463 const u8 *ie = mgmt->u.probe_req.variable;
3464 size_t ie_len = data->rx_mgmt.frame_len -
3465 (mgmt->u.probe_req.variable -
3466 data->rx_mgmt.frame);
3467 wpas_p2p_probe_req_rx(
3468 wpa_s, src, mgmt->da,
3469 mgmt->bssid, ie, ie_len,
3470 data->rx_mgmt.ssi_signal);
3473 #endif /* CONFIG_P2P */
3474 #ifdef CONFIG_IBSS_RSN
3475 if (wpa_s->current_ssid &&
3476 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3477 stype == WLAN_FC_STYPE_AUTH &&
3478 data->rx_mgmt.frame_len >= 30) {
3479 wpa_supplicant_event_ibss_auth(wpa_s, data);
3482 #endif /* CONFIG_IBSS_RSN */
3484 if (stype == WLAN_FC_STYPE_ACTION) {
3485 wpas_event_rx_mgmt_action(
3486 wpa_s, data->rx_mgmt.frame,
3487 data->rx_mgmt.frame_len,
3489 data->rx_mgmt.ssi_signal);
3494 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3498 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3499 "management frame in non-AP mode");
3504 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3505 data->rx_mgmt.frame_len > 24) {
3506 const u8 *ie = mgmt->u.probe_req.variable;
3507 size_t ie_len = data->rx_mgmt.frame_len -
3508 (mgmt->u.probe_req.variable -
3509 data->rx_mgmt.frame);
3511 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3512 mgmt->bssid, ie, ie_len,
3513 data->rx_mgmt.ssi_signal);
3516 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3517 #endif /* CONFIG_AP */
3520 case EVENT_RX_PROBE_REQ:
3521 if (data->rx_probe_req.sa == NULL ||
3522 data->rx_probe_req.ie == NULL)
3525 if (wpa_s->ap_iface) {
3526 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3527 data->rx_probe_req.sa,
3528 data->rx_probe_req.da,
3529 data->rx_probe_req.bssid,
3530 data->rx_probe_req.ie,
3531 data->rx_probe_req.ie_len,
3532 data->rx_probe_req.ssi_signal);
3535 #endif /* CONFIG_AP */
3536 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3537 data->rx_probe_req.da,
3538 data->rx_probe_req.bssid,
3539 data->rx_probe_req.ie,
3540 data->rx_probe_req.ie_len,
3541 data->rx_probe_req.ssi_signal);
3543 case EVENT_REMAIN_ON_CHANNEL:
3544 #ifdef CONFIG_OFFCHANNEL
3545 offchannel_remain_on_channel_cb(
3546 wpa_s, data->remain_on_channel.freq,
3547 data->remain_on_channel.duration);
3548 #endif /* CONFIG_OFFCHANNEL */
3549 wpas_p2p_remain_on_channel_cb(
3550 wpa_s, data->remain_on_channel.freq,
3551 data->remain_on_channel.duration);
3553 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3554 #ifdef CONFIG_OFFCHANNEL
3555 offchannel_cancel_remain_on_channel_cb(
3556 wpa_s, data->remain_on_channel.freq);
3557 #endif /* CONFIG_OFFCHANNEL */
3558 wpas_p2p_cancel_remain_on_channel_cb(
3559 wpa_s, data->remain_on_channel.freq);
3561 case EVENT_EAPOL_RX:
3562 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3563 data->eapol_rx.data,
3564 data->eapol_rx.data_len);
3566 case EVENT_SIGNAL_CHANGE:
3567 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3568 "above=%d signal=%d noise=%d txrate=%d",
3569 data->signal_change.above_threshold,
3570 data->signal_change.current_signal,
3571 data->signal_change.current_noise,
3572 data->signal_change.current_txrate);
3573 wpa_bss_update_level(wpa_s->current_bss,
3574 data->signal_change.current_signal);
3575 bgscan_notify_signal_change(
3576 wpa_s, data->signal_change.above_threshold,
3577 data->signal_change.current_signal,
3578 data->signal_change.current_noise,
3579 data->signal_change.current_txrate);
3581 case EVENT_INTERFACE_ENABLED:
3582 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3583 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3584 wpa_supplicant_update_mac_addr(wpa_s);
3585 if (wpa_s->p2p_mgmt) {
3586 wpa_supplicant_set_state(wpa_s,
3592 if (!wpa_s->ap_iface) {
3593 wpa_supplicant_set_state(wpa_s,
3595 wpa_s->scan_req = NORMAL_SCAN_REQ;
3596 wpa_supplicant_req_scan(wpa_s, 0, 0);
3598 wpa_supplicant_set_state(wpa_s,
3600 #else /* CONFIG_AP */
3601 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3602 wpa_supplicant_req_scan(wpa_s, 0, 0);
3603 #endif /* CONFIG_AP */
3606 case EVENT_INTERFACE_DISABLED:
3607 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3609 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3610 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3611 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3613 * Mark interface disabled if this happens to end up not
3614 * being removed as a separate P2P group interface.
3616 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3618 * The interface was externally disabled. Remove
3619 * it assuming an external entity will start a
3620 * new session if needed.
3622 if (wpa_s->current_ssid &&
3623 wpa_s->current_ssid->p2p_group)
3624 wpas_p2p_interface_unavailable(wpa_s);
3626 wpas_p2p_disconnect(wpa_s);
3628 * wpa_s instance may have been freed, so must not use
3633 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3634 p2p_in_progress(wpa_s->global->p2p) > 1) {
3635 /* This radio work will be cancelled, so clear P2P
3638 p2p_stop_find(wpa_s->global->p2p);
3640 #endif /* CONFIG_P2P */
3642 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3644 * Indicate disconnection to keep ctrl_iface events
3647 wpa_supplicant_event_disassoc(
3648 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3650 wpa_supplicant_mark_disassoc(wpa_s);
3651 radio_remove_works(wpa_s, NULL, 0);
3653 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3655 case EVENT_CHANNEL_LIST_CHANGED:
3656 wpa_supplicant_update_channel_list(
3657 wpa_s, &data->channel_list_changed);
3659 case EVENT_INTERFACE_UNAVAILABLE:
3660 wpas_p2p_interface_unavailable(wpa_s);
3662 case EVENT_BEST_CHANNEL:
3663 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3665 data->best_chan.freq_24, data->best_chan.freq_5,
3666 data->best_chan.freq_overall);
3667 wpa_s->best_24_freq = data->best_chan.freq_24;
3668 wpa_s->best_5_freq = data->best_chan.freq_5;
3669 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3670 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3671 data->best_chan.freq_5,
3672 data->best_chan.freq_overall);
3674 case EVENT_UNPROT_DEAUTH:
3675 wpa_supplicant_event_unprot_deauth(wpa_s,
3676 &data->unprot_deauth);
3678 case EVENT_UNPROT_DISASSOC:
3679 wpa_supplicant_event_unprot_disassoc(wpa_s,
3680 &data->unprot_disassoc);
3682 case EVENT_STATION_LOW_ACK:
3684 if (wpa_s->ap_iface && data)
3685 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3686 data->low_ack.addr);
3687 #endif /* CONFIG_AP */
3690 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3691 data->low_ack.addr);
3692 #endif /* CONFIG_TDLS */
3694 case EVENT_IBSS_PEER_LOST:
3695 #ifdef CONFIG_IBSS_RSN
3696 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3697 #endif /* CONFIG_IBSS_RSN */
3699 case EVENT_DRIVER_GTK_REKEY:
3700 if (os_memcmp(data->driver_gtk_rekey.bssid,
3701 wpa_s->bssid, ETH_ALEN))
3705 wpa_sm_update_replay_ctr(wpa_s->wpa,
3706 data->driver_gtk_rekey.replay_ctr);
3708 case EVENT_SCHED_SCAN_STOPPED:
3710 wpa_s->sched_scanning = 0;
3711 wpa_supplicant_notify_scanning(wpa_s, 0);
3713 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3717 * Start a new sched scan to continue searching for more SSIDs
3718 * either if timed out or PNO schedule scan is pending.
3720 if (wpa_s->sched_scan_timed_out) {
3721 wpa_supplicant_req_sched_scan(wpa_s);
3722 } else if (wpa_s->pno_sched_pending) {
3723 wpa_s->pno_sched_pending = 0;
3724 wpas_start_pno(wpa_s);
3728 case EVENT_WPS_BUTTON_PUSHED:
3730 wpas_wps_start_pbc(wpa_s, NULL, 0);
3731 #endif /* CONFIG_WPS */
3733 case EVENT_AVOID_FREQUENCIES:
3734 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3736 case EVENT_CONNECT_FAILED_REASON:
3738 if (!wpa_s->ap_iface || !data)
3740 hostapd_event_connect_failed_reason(
3741 wpa_s->ap_iface->bss[0],
3742 data->connect_failed_reason.addr,
3743 data->connect_failed_reason.code);
3744 #endif /* CONFIG_AP */
3746 case EVENT_NEW_PEER_CANDIDATE:
3748 if (!wpa_s->ifmsh || !data)
3750 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3751 data->mesh_peer.ies,
3752 data->mesh_peer.ie_len);
3753 #endif /* CONFIG_MESH */
3756 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);