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;
1088 struct wpa_ssid *ssid;
1090 if (wpa_s->last_scan_res == NULL ||
1091 wpa_s->last_scan_res_used == 0)
1092 return NULL; /* no scan results from last update */
1094 if (wpa_s->next_ssid) {
1095 /* check that next_ssid is still valid */
1096 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1097 if (ssid == wpa_s->next_ssid)
1101 wpa_s->next_ssid = NULL;
1104 while (selected == NULL) {
1105 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1106 if (next_ssid && next_ssid->priority ==
1107 wpa_s->conf->pssid[prio]->priority) {
1108 selected = wpa_supplicant_select_bss(
1109 wpa_s, next_ssid, selected_ssid, 1);
1113 selected = wpa_supplicant_select_bss(
1114 wpa_s, wpa_s->conf->pssid[prio],
1120 if (selected == NULL && wpa_s->blacklist &&
1121 !wpa_s->countermeasures) {
1122 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1123 "blacklist and try again");
1124 wpa_blacklist_clear(wpa_s);
1125 wpa_s->blacklist_cleared++;
1126 } else if (selected == NULL)
1130 ssid = *selected_ssid;
1131 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1132 !ssid->passphrase && !ssid->ext_psk) {
1133 const char *field_name, *txt = NULL;
1135 wpa_dbg(wpa_s, MSG_DEBUG,
1136 "PSK/passphrase not yet available for the selected network");
1138 wpas_notify_network_request(wpa_s, ssid,
1139 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1141 field_name = wpa_supplicant_ctrl_req_to_string(
1142 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1143 if (field_name == NULL)
1146 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1155 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1156 int timeout_sec, int timeout_usec)
1158 if (!wpa_supplicant_enabled_networks(wpa_s)) {
1160 * No networks are enabled; short-circuit request so
1161 * we don't wait timeout seconds before transitioning
1162 * to INACTIVE state.
1164 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1165 "since there are no enabled networks");
1166 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1170 wpa_s->scan_for_connection = 1;
1171 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1175 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1176 struct wpa_bss *selected,
1177 struct wpa_ssid *ssid)
1179 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1180 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1181 "PBC session overlap");
1183 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1184 wpa_s->p2p_in_provisioning) {
1185 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1189 #endif /* CONFIG_P2P */
1192 wpas_wps_cancel(wpa_s);
1193 #endif /* CONFIG_WPS */
1197 wpa_msg(wpa_s, MSG_DEBUG,
1198 "Considering connect request: reassociate: %d selected: "
1199 MACSTR " bssid: " MACSTR " pending: " MACSTR
1200 " wpa_state: %s ssid=%p current_ssid=%p",
1201 wpa_s->reassociate, MAC2STR(selected->bssid),
1202 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1203 wpa_supplicant_state_txt(wpa_s->wpa_state),
1204 ssid, wpa_s->current_ssid);
1207 * Do not trigger new association unless the BSSID has changed or if
1208 * reassociation is requested. If we are in process of associating with
1209 * the selected BSSID, do not trigger new attempt.
1211 if (wpa_s->reassociate ||
1212 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1213 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1214 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
1215 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1216 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1218 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1219 ssid != wpa_s->current_ssid)))) {
1220 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1221 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
1224 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1225 MAC2STR(selected->bssid));
1226 wpa_supplicant_associate(wpa_s, selected, ssid);
1228 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1229 "connect with the selected AP");
1236 static struct wpa_ssid *
1237 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1240 struct wpa_ssid *ssid;
1242 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1243 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1245 if (wpas_network_disabled(wpa_s, ssid))
1247 if (ssid->mode == IEEE80211_MODE_IBSS ||
1248 ssid->mode == IEEE80211_MODE_AP ||
1249 ssid->mode == IEEE80211_MODE_MESH)
1257 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1258 * on BSS added and BSS changed events */
1259 static void wpa_supplicant_rsn_preauth_scan_results(
1260 struct wpa_supplicant *wpa_s)
1262 struct wpa_bss *bss;
1264 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1267 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1268 const u8 *ssid, *rsn;
1270 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1274 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1278 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1284 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1285 struct wpa_bss *selected,
1286 struct wpa_ssid *ssid)
1288 struct wpa_bss *current_bss = NULL;
1289 #ifndef CONFIG_NO_ROAMING
1291 #endif /* CONFIG_NO_ROAMING */
1293 if (wpa_s->reassociate)
1294 return 1; /* explicit request to reassociate */
1295 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1296 return 1; /* we are not associated; continue */
1297 if (wpa_s->current_ssid == NULL)
1298 return 1; /* unknown current SSID */
1299 if (wpa_s->current_ssid != ssid)
1300 return 1; /* different network block */
1302 if (wpas_driver_bss_selection(wpa_s))
1303 return 0; /* Driver-based roaming */
1305 if (wpa_s->current_ssid->ssid)
1306 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1307 wpa_s->current_ssid->ssid,
1308 wpa_s->current_ssid->ssid_len);
1310 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1313 return 1; /* current BSS not seen in scan results */
1315 if (current_bss == selected)
1318 if (selected->last_update_idx > current_bss->last_update_idx)
1319 return 1; /* current BSS not seen in the last scan */
1321 #ifndef CONFIG_NO_ROAMING
1322 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1323 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1324 " level=%d snr=%d est_throughput=%u",
1325 MAC2STR(current_bss->bssid), current_bss->level,
1326 current_bss->snr, current_bss->est_throughput);
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1328 " level=%d snr=%d est_throughput=%u",
1329 MAC2STR(selected->bssid), selected->level,
1330 selected->snr, selected->est_throughput);
1332 if (wpa_s->current_ssid->bssid_set &&
1333 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1335 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1336 "has preferred BSSID");
1340 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1341 wpa_dbg(wpa_s, MSG_DEBUG,
1342 "Allow reassociation - selected BSS has better estimated throughput");
1346 if (current_bss->level < 0 && current_bss->level > selected->level) {
1347 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1353 if (current_bss->level < 0) {
1354 if (current_bss->level < -85)
1356 else if (current_bss->level < -80)
1358 else if (current_bss->level < -75)
1360 else if (current_bss->level < -70)
1365 if (abs(current_bss->level - selected->level) < min_diff) {
1366 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1372 #else /* CONFIG_NO_ROAMING */
1374 #endif /* CONFIG_NO_ROAMING */
1378 /* Return != 0 if no scan results could be fetched or if scan results should not
1379 * be shared with other virtual interfaces. */
1380 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1381 union wpa_event_data *data,
1384 struct wpa_scan_results *scan_res = NULL;
1387 #ifndef CONFIG_NO_RANDOM_POOL
1389 #endif /* CONFIG_NO_RANDOM_POOL */
1392 if (wpa_s->ap_iface)
1394 #endif /* CONFIG_AP */
1396 wpa_supplicant_notify_scanning(wpa_s, 0);
1398 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1399 data ? &data->scan_info :
1401 if (scan_res == NULL) {
1402 if (wpa_s->conf->ap_scan == 2 || ap ||
1403 wpa_s->scan_res_handler == scan_only_handler)
1407 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1409 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1411 goto scan_work_done;
1414 #ifndef CONFIG_NO_RANDOM_POOL
1415 num = scan_res->num;
1418 for (i = 0; i < num; i++) {
1420 struct wpa_scan_res *res = scan_res->res[i];
1421 buf[0] = res->bssid[5];
1422 buf[1] = res->qual & 0xff;
1423 buf[2] = res->noise & 0xff;
1424 buf[3] = res->level & 0xff;
1425 buf[4] = res->tsf & 0xff;
1426 random_add_randomness(buf, sizeof(buf));
1428 #endif /* CONFIG_NO_RANDOM_POOL */
1430 if (own_request && wpa_s->scan_res_handler &&
1431 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
1432 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1433 struct wpa_scan_results *scan_res);
1435 scan_res_handler = wpa_s->scan_res_handler;
1436 wpa_s->scan_res_handler = NULL;
1437 scan_res_handler(wpa_s, scan_res);
1439 goto scan_work_done;
1443 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1445 if (wpa_s->ap_iface->scan_cb)
1446 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1447 #endif /* CONFIG_AP */
1448 goto scan_work_done;
1451 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1452 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
1453 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1454 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1455 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1456 wpa_s->manual_scan_id);
1457 wpa_s->manual_scan_use_id = 0;
1459 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1461 wpas_notify_scan_results(wpa_s);
1463 wpas_notify_scan_done(wpa_s, 1);
1465 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
1466 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
1467 wpa_scan_results_free(scan_res);
1471 if (wnm_scan_process(wpa_s, 1) > 0)
1472 goto scan_work_done;
1474 if (sme_proc_obss_scan(wpa_s) > 0)
1475 goto scan_work_done;
1477 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1478 goto scan_work_done;
1480 if (autoscan_notify_scan(wpa_s, scan_res))
1481 goto scan_work_done;
1483 if (wpa_s->disconnected) {
1484 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1485 goto scan_work_done;
1488 if (!wpas_driver_bss_selection(wpa_s) &&
1489 bgscan_notify_scan(wpa_s, scan_res) == 1)
1490 goto scan_work_done;
1492 wpas_wps_update_ap_info(wpa_s, scan_res);
1494 wpa_scan_results_free(scan_res);
1496 if (wpa_s->scan_work) {
1497 struct wpa_radio_work *work = wpa_s->scan_work;
1498 wpa_s->scan_work = NULL;
1499 radio_work_done(work);
1502 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
1505 wpa_scan_results_free(scan_res);
1506 if (wpa_s->scan_work) {
1507 struct wpa_radio_work *work = wpa_s->scan_work;
1508 wpa_s->scan_work = NULL;
1509 radio_work_done(work);
1515 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1516 int new_scan, int own_request)
1518 struct wpa_bss *selected;
1519 struct wpa_ssid *ssid = NULL;
1520 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1522 if (time_to_reenable > 0) {
1523 wpa_dbg(wpa_s, MSG_DEBUG,
1524 "Postpone network selection by %d seconds since all networks are disabled",
1526 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1527 eloop_register_timeout(time_to_reenable, 0,
1528 wpas_network_reenabled, wpa_s, NULL);
1532 if (wpa_s->p2p_mgmt)
1533 return 0; /* no normal connection on p2p_mgmt interface */
1535 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1539 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1542 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1546 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1547 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1551 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1553 * Do not notify other virtual radios of scan results since we do not
1554 * want them to start other associations at the same time.
1560 wpa_msg(wpa_s, MSG_INFO,
1561 "Avoiding join because we already joined a mesh group");
1564 #endif /* CONFIG_MESH */
1565 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1566 ssid = wpa_supplicant_pick_new_network(wpa_s);
1568 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1569 wpa_supplicant_associate(wpa_s, NULL, ssid);
1571 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1572 } else if (own_request) {
1574 * No SSID found. If SCAN results are as a result of
1575 * own scan request and not due to a scan request on
1576 * another shared interface, try another scan.
1578 int timeout_sec = wpa_s->scan_interval;
1579 int timeout_usec = 0;
1583 res = wpas_p2p_scan_no_go_seen(wpa_s);
1589 if (wpa_s->p2p_in_provisioning ||
1590 wpa_s->show_group_started ||
1591 wpa_s->p2p_in_invitation) {
1593 * Use shorter wait during P2P Provisioning
1594 * state and during P2P join-a-group operation
1595 * to speed up group formation.
1598 timeout_usec = 250000;
1599 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1603 #endif /* CONFIG_P2P */
1604 #ifdef CONFIG_INTERWORKING
1605 if (wpa_s->conf->auto_interworking &&
1606 wpa_s->conf->interworking &&
1607 wpa_s->conf->cred) {
1608 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1609 "start ANQP fetch since no matching "
1611 wpa_s->network_select = 1;
1612 wpa_s->auto_network_select = 1;
1613 interworking_start_fetch_anqp(wpa_s);
1616 #endif /* CONFIG_INTERWORKING */
1618 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1619 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1621 timeout_usec = 500000;
1622 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1626 #endif /* CONFIG_WPS */
1627 if (wpa_supplicant_req_sched_scan(wpa_s))
1628 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1636 static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1637 union wpa_event_data *data)
1639 struct wpa_supplicant *ifs;
1642 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1645 * Interface may have been removed, so must not dereference
1652 * If no scan results could be fetched, then no need to
1653 * notify those interfaces that did not actually request
1654 * this scan. Similarly, if scan results started a new operation on this
1655 * interface, do not notify other interfaces to avoid concurrent
1656 * operations during a connection attempt.
1662 * Check other interfaces to see if they share the same radio. If
1663 * so, they get updated with this same scan info.
1665 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1668 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1669 "sibling", ifs->ifname);
1670 _wpa_supplicant_event_scan_results(ifs, data, 0);
1677 #endif /* CONFIG_NO_SCAN_PROCESSING */
1680 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1682 #ifdef CONFIG_NO_SCAN_PROCESSING
1684 #else /* CONFIG_NO_SCAN_PROCESSING */
1685 struct os_reltime now;
1687 if (wpa_s->last_scan_res_used <= 0)
1690 os_get_reltime(&now);
1691 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
1692 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1696 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
1697 #endif /* CONFIG_NO_SCAN_PROCESSING */
1702 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1704 struct wpa_supplicant *wpa_s = eloop_ctx;
1706 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1709 if (!wpa_s->no_keep_alive) {
1710 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1711 MAC2STR(wpa_s->bssid));
1712 /* TODO: could skip this if normal data traffic has been sent */
1713 /* TODO: Consider using some more appropriate data frame for
1716 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1721 if (wpa_s->sme.bss_max_idle_period) {
1723 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1726 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1727 wnm_bss_keep_alive, wpa_s, NULL);
1729 #endif /* CONFIG_SME */
1733 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1734 const u8 *ies, size_t ies_len)
1736 struct ieee802_11_elems elems;
1741 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1745 if (elems.bss_max_idle_period) {
1747 wpa_s->sme.bss_max_idle_period =
1748 WPA_GET_LE16(elems.bss_max_idle_period);
1749 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1750 "TU)%s", wpa_s->sme.bss_max_idle_period,
1751 (elems.bss_max_idle_period[2] & 0x01) ?
1752 " (protected keep-live required)" : "");
1753 if (wpa_s->sme.bss_max_idle_period == 0)
1754 wpa_s->sme.bss_max_idle_period = 1;
1755 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1756 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1757 /* msec times 1000 */
1758 msec = wpa_s->sme.bss_max_idle_period * 1024;
1761 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1762 wnm_bss_keep_alive, wpa_s,
1766 #endif /* CONFIG_SME */
1769 #endif /* CONFIG_WNM */
1772 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1775 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1776 #endif /* CONFIG_WNM */
1780 #ifdef CONFIG_INTERWORKING
1782 static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1787 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1788 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1790 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1797 static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1798 const u8 *ies, size_t ies_len)
1800 struct ieee802_11_elems elems;
1805 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1808 if (elems.qos_map_set) {
1809 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1810 elems.qos_map_set_len);
1814 #endif /* CONFIG_INTERWORKING */
1817 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1818 union wpa_event_data *data)
1820 int l, len, found = 0, wpa_found, rsn_found;
1822 #ifdef CONFIG_IEEE80211R
1824 #endif /* CONFIG_IEEE80211R */
1826 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1827 if (data->assoc_info.req_ies)
1828 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1829 data->assoc_info.req_ies_len);
1830 if (data->assoc_info.resp_ies) {
1831 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1832 data->assoc_info.resp_ies_len);
1834 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1835 data->assoc_info.resp_ies_len);
1836 #endif /* CONFIG_TDLS */
1838 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1839 data->assoc_info.resp_ies_len);
1840 #endif /* CONFIG_WNM */
1841 #ifdef CONFIG_INTERWORKING
1842 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1843 data->assoc_info.resp_ies_len);
1844 #endif /* CONFIG_INTERWORKING */
1846 if (data->assoc_info.beacon_ies)
1847 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1848 data->assoc_info.beacon_ies,
1849 data->assoc_info.beacon_ies_len);
1850 if (data->assoc_info.freq)
1851 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1852 data->assoc_info.freq);
1854 p = data->assoc_info.req_ies;
1855 l = data->assoc_info.req_ies_len;
1857 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1858 while (p && l >= 2) {
1861 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1865 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1866 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1867 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1868 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1871 wpa_find_assoc_pmkid(wpa_s);
1877 if (!found && data->assoc_info.req_ies)
1878 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1880 #ifdef CONFIG_IEEE80211R
1882 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1883 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1884 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1885 data->assoc_info.resp_ies,
1886 data->assoc_info.resp_ies_len,
1888 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1889 "Reassociation Response failed");
1890 wpa_supplicant_deauthenticate(
1891 wpa_s, WLAN_REASON_INVALID_IE);
1896 p = data->assoc_info.resp_ies;
1897 l = data->assoc_info.resp_ies_len;
1899 #ifdef CONFIG_WPS_STRICT
1900 if (p && wpa_s->current_ssid &&
1901 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1903 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1905 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1906 "include WPS IE in (Re)Association Response");
1910 if (wps_validate_assoc_resp(wps) < 0) {
1912 wpa_supplicant_deauthenticate(
1913 wpa_s, WLAN_REASON_INVALID_IE);
1918 #endif /* CONFIG_WPS_STRICT */
1920 /* Go through the IEs and make a copy of the MDIE, if present. */
1921 while (p && l >= 2) {
1924 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1928 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1929 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1930 wpa_s->sme.ft_used = 1;
1931 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1932 MOBILITY_DOMAIN_ID_LEN);
1938 #endif /* CONFIG_SME */
1940 /* Process FT when SME is in the driver */
1941 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1942 wpa_ft_is_completed(wpa_s->wpa)) {
1943 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1944 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1945 data->assoc_info.resp_ies,
1946 data->assoc_info.resp_ies_len,
1948 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1949 "Reassociation Response failed");
1950 wpa_supplicant_deauthenticate(
1951 wpa_s, WLAN_REASON_INVALID_IE);
1954 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1957 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1958 data->assoc_info.resp_ies_len);
1959 #endif /* CONFIG_IEEE80211R */
1961 /* WPA/RSN IE from Beacon/ProbeResp */
1962 p = data->assoc_info.beacon_ies;
1963 l = data->assoc_info.beacon_ies_len;
1965 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1967 wpa_found = rsn_found = 0;
1968 while (p && l >= 2) {
1971 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1976 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1977 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1979 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1983 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1985 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1992 if (!wpa_found && data->assoc_info.beacon_ies)
1993 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1994 if (!rsn_found && data->assoc_info.beacon_ies)
1995 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1996 if (wpa_found || rsn_found)
1997 wpa_s->ap_ies_from_associnfo = 1;
1999 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2000 wpa_s->assoc_freq != data->assoc_info.freq) {
2001 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2003 wpa_s->assoc_freq, data->assoc_info.freq);
2004 wpa_supplicant_update_scan_results(wpa_s);
2007 wpa_s->assoc_freq = data->assoc_info.freq;
2013 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2015 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2017 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2020 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2023 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2024 WPA_IE_VENDOR_TYPE);
2025 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2027 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2028 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2029 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2030 bss_rsn ? 2 + bss_rsn[1] : 0))
2037 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2038 union wpa_event_data *data)
2044 if (wpa_s->ap_iface) {
2047 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2048 data->assoc_info.addr,
2049 data->assoc_info.req_ies,
2050 data->assoc_info.req_ies_len,
2051 data->assoc_info.reassoc);
2054 #endif /* CONFIG_AP */
2056 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2058 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2059 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2062 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2063 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
2064 wpa_supplicant_deauthenticate(
2065 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2069 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
2070 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
2071 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2072 MACSTR, MAC2STR(bssid));
2073 random_add_randomness(bssid, ETH_ALEN);
2074 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2075 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
2076 wpas_notify_bssid_changed(wpa_s);
2078 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2079 wpa_clear_keys(wpa_s, bssid);
2081 if (wpa_supplicant_select_config(wpa_s) < 0) {
2082 wpa_supplicant_deauthenticate(
2083 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2087 if (wpa_s->conf->ap_scan == 1 &&
2088 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
2089 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
2090 wpa_msg(wpa_s, MSG_WARNING,
2091 "WPA/RSN IEs not updated");
2096 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2097 wpa_s->sme.prev_bssid_set = 1;
2098 wpa_s->sme.last_unprot_disconnect.sec = 0;
2099 #endif /* CONFIG_SME */
2101 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2102 if (wpa_s->current_ssid) {
2103 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2104 * initialized before association, but for other modes,
2105 * initialize PC/SC here, if the current configuration needs
2106 * smartcard or SIM/USIM. */
2107 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2109 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2111 l2_packet_notify_auth_start(wpa_s->l2);
2114 * Set portEnabled first to FALSE in order to get EAP state machine out
2115 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2116 * state machine may transit to AUTHENTICATING state based on obsolete
2117 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2118 * AUTHENTICATED without ever giving chance to EAP state machine to
2121 if (!ft_completed) {
2122 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2123 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2125 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2126 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2127 /* 802.1X::portControl = Auto */
2128 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2129 wpa_s->eapol_received = 0;
2130 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2131 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2132 (wpa_s->current_ssid &&
2133 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
2134 if (wpa_s->current_ssid &&
2135 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
2137 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2139 * Set the key after having received joined-IBSS event
2142 wpa_supplicant_set_wpa_none_key(wpa_s,
2143 wpa_s->current_ssid);
2145 wpa_supplicant_cancel_auth_timeout(wpa_s);
2146 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2147 } else if (!ft_completed) {
2148 /* Timeout for receiving the first EAPOL packet */
2149 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2151 wpa_supplicant_cancel_scan(wpa_s);
2153 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2154 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2156 * We are done; the driver will take care of RSN 4-way
2159 wpa_supplicant_cancel_auth_timeout(wpa_s);
2160 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2161 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2162 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2163 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2164 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2166 * The driver will take care of RSN 4-way handshake, so we need
2167 * to allow EAPOL supplicant to complete its work without
2168 * waiting for WPA supplicant.
2170 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2171 } else if (ft_completed) {
2173 * FT protocol completed - make sure EAPOL state machine ends
2174 * up in authenticated.
2176 wpa_supplicant_cancel_auth_timeout(wpa_s);
2177 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2178 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2179 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2182 wpa_s->last_eapol_matches_bssid = 0;
2184 if (wpa_s->pending_eapol_rx) {
2185 struct os_reltime now, age;
2186 os_get_reltime(&now);
2187 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
2188 if (age.sec == 0 && age.usec < 100000 &&
2189 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2191 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2192 "frame that was received just before "
2193 "association notification");
2194 wpa_supplicant_rx_eapol(
2195 wpa_s, wpa_s->pending_eapol_rx_src,
2196 wpabuf_head(wpa_s->pending_eapol_rx),
2197 wpabuf_len(wpa_s->pending_eapol_rx));
2199 wpabuf_free(wpa_s->pending_eapol_rx);
2200 wpa_s->pending_eapol_rx = NULL;
2203 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2204 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
2205 wpa_s->current_ssid &&
2206 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2207 /* Set static WEP keys again */
2208 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2211 #ifdef CONFIG_IBSS_RSN
2212 if (wpa_s->current_ssid &&
2213 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2214 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2215 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2216 wpa_s->ibss_rsn == NULL) {
2217 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2218 if (!wpa_s->ibss_rsn) {
2219 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2220 wpa_supplicant_deauthenticate(
2221 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2225 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2227 #endif /* CONFIG_IBSS_RSN */
2229 wpas_wps_notify_assoc(wpa_s, bssid);
2232 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2233 data->assoc_info.resp_ies_len,
2234 &data->assoc_info.wmm_params);
2236 if (wpa_s->reassoc_same_bss)
2237 wmm_ac_restore_tspecs(wpa_s);
2242 static int disconnect_reason_recoverable(u16 reason_code)
2244 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2245 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2246 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2250 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
2252 int locally_generated)
2256 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2258 * At least Host AP driver and a Prism3 card seemed to be
2259 * generating streams of disconnected events when configuring
2260 * IBSS for WPA-None. Ignore them for now.
2265 bssid = wpa_s->bssid;
2266 if (is_zero_ether_addr(bssid))
2267 bssid = wpa_s->pending_bssid;
2269 if (!is_zero_ether_addr(bssid) ||
2270 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2271 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2273 MAC2STR(bssid), reason_code,
2274 locally_generated ? " locally_generated=1" : "");
2279 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2280 int locally_generated)
2282 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2283 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2284 return 0; /* Not in 4-way handshake with PSK */
2287 * It looks like connection was lost while trying to go through PSK
2288 * 4-way handshake. Filter out known disconnection cases that are caused
2289 * by something else than PSK mismatch to avoid confusing reports.
2292 if (locally_generated) {
2293 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2301 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2303 int locally_generated)
2307 u8 prev_pending_bssid[ETH_ALEN];
2308 struct wpa_bss *fast_reconnect = NULL;
2309 struct wpa_ssid *fast_reconnect_ssid = NULL;
2310 struct wpa_ssid *last_ssid;
2312 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2313 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2315 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2317 * At least Host AP driver and a Prism3 card seemed to be
2318 * generating streams of disconnected events when configuring
2319 * IBSS for WPA-None. Ignore them for now.
2321 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2322 "IBSS/WPA-None mode");
2326 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
2327 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2328 "pre-shared key may be incorrect");
2329 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2330 return; /* P2P group removed */
2331 wpas_auth_failed(wpa_s, "WRONG_KEY");
2333 if (!wpa_s->disconnected &&
2334 (!wpa_s->auto_reconnect_disabled ||
2335 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2336 wpas_wps_searching(wpa_s))) {
2337 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2338 "reconnect (wps=%d/%d wpa_state=%d)",
2339 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2340 wpas_wps_searching(wpa_s),
2342 if (wpa_s->wpa_state == WPA_COMPLETED &&
2343 wpa_s->current_ssid &&
2344 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
2345 !locally_generated &&
2346 disconnect_reason_recoverable(reason_code)) {
2348 * It looks like the AP has dropped association with
2349 * us, but could allow us to get back in. Try to
2350 * reconnect to the same BSS without full scan to save
2351 * time for some common cases.
2353 fast_reconnect = wpa_s->current_bss;
2354 fast_reconnect_ssid = wpa_s->current_ssid;
2355 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
2356 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2358 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2361 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2362 "try to re-connect");
2363 wpa_s->reassociate = 0;
2364 wpa_s->disconnected = 1;
2365 wpa_supplicant_cancel_sched_scan(wpa_s);
2367 bssid = wpa_s->bssid;
2368 if (is_zero_ether_addr(bssid))
2369 bssid = wpa_s->pending_bssid;
2370 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2371 wpas_connection_failed(wpa_s, bssid);
2372 wpa_sm_notify_disassoc(wpa_s->wpa);
2373 if (locally_generated)
2374 wpa_s->disconnect_reason = -reason_code;
2376 wpa_s->disconnect_reason = reason_code;
2377 wpas_notify_disconnect_reason(wpa_s);
2378 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2379 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2380 wpa_clear_keys(wpa_s, wpa_s->bssid);
2382 last_ssid = wpa_s->current_ssid;
2383 wpa_supplicant_mark_disassoc(wpa_s);
2385 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2386 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2387 wpa_s->current_ssid = last_ssid;
2390 if (fast_reconnect &&
2391 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2392 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2393 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2394 fast_reconnect->ssid_len) &&
2395 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
2396 #ifndef CONFIG_NO_SCAN_PROCESSING
2397 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2398 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2399 fast_reconnect_ssid) < 0) {
2400 /* Recover through full scan */
2401 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2403 #endif /* CONFIG_NO_SCAN_PROCESSING */
2404 } else if (fast_reconnect) {
2406 * Could not reconnect to the same BSS due to network being
2407 * disabled. Use a new scan to match the alternative behavior
2408 * above, i.e., to continue automatic reconnection attempt in a
2409 * way that enforces disabled network rules.
2411 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2416 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2417 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2419 struct wpa_supplicant *wpa_s = eloop_ctx;
2421 if (!wpa_s->pending_mic_error_report)
2424 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2425 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2426 wpa_s->pending_mic_error_report = 0;
2428 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2432 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2433 union wpa_event_data *data)
2436 struct os_reltime t;
2438 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2439 pairwise = (data && data->michael_mic_failure.unicast);
2441 if ((wpa_s->last_michael_mic_error.sec &&
2442 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
2443 wpa_s->pending_mic_error_report) {
2444 if (wpa_s->pending_mic_error_report) {
2446 * Send the pending MIC error report immediately since
2447 * we are going to start countermeasures and AP better
2450 wpa_sm_key_request(wpa_s->wpa, 1,
2451 wpa_s->pending_mic_error_pairwise);
2454 /* Send the new MIC error report immediately since we are going
2455 * to start countermeasures and AP better do the same.
2457 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2459 /* initialize countermeasures */
2460 wpa_s->countermeasures = 1;
2462 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2464 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2467 * Need to wait for completion of request frame. We do not get
2468 * any callback for the message completion, so just wait a
2469 * short while and hope for the best. */
2472 wpa_drv_set_countermeasures(wpa_s, 1);
2473 wpa_supplicant_deauthenticate(wpa_s,
2474 WLAN_REASON_MICHAEL_MIC_FAILURE);
2475 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2477 eloop_register_timeout(60, 0,
2478 wpa_supplicant_stop_countermeasures,
2480 /* TODO: mark the AP rejected for 60 second. STA is
2481 * allowed to associate with another AP.. */
2483 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2484 if (wpa_s->mic_errors_seen) {
2486 * Reduce the effectiveness of Michael MIC error
2487 * reports as a means for attacking against TKIP if
2488 * more than one MIC failure is noticed with the same
2489 * PTK. We delay the transmission of the reports by a
2490 * random time between 0 and 60 seconds in order to
2491 * force the attacker wait 60 seconds before getting
2492 * the information on whether a frame resulted in a MIC
2498 if (os_get_random(rval, sizeof(rval)) < 0)
2499 sec = os_random() % 60;
2501 sec = WPA_GET_BE32(rval) % 60;
2502 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2503 "report %d seconds", sec);
2504 wpa_s->pending_mic_error_report = 1;
2505 wpa_s->pending_mic_error_pairwise = pairwise;
2506 eloop_cancel_timeout(
2507 wpa_supplicant_delayed_mic_error_report,
2509 eloop_register_timeout(
2510 sec, os_random() % 1000000,
2511 wpa_supplicant_delayed_mic_error_report,
2514 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2516 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2517 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2518 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2520 wpa_s->last_michael_mic_error = t;
2521 wpa_s->mic_errors_seen++;
2525 #ifdef CONFIG_TERMINATE_ONLASTIF
2526 static int any_interfaces(struct wpa_supplicant *head)
2528 struct wpa_supplicant *wpa_s;
2530 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2531 if (!wpa_s->interface_removed)
2535 #endif /* CONFIG_TERMINATE_ONLASTIF */
2539 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2540 union wpa_event_data *data)
2542 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2545 switch (data->interface_status.ievent) {
2546 case EVENT_INTERFACE_ADDED:
2547 if (!wpa_s->interface_removed)
2549 wpa_s->interface_removed = 0;
2550 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2551 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2552 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2553 "driver after interface was added");
2556 case EVENT_INTERFACE_REMOVED:
2557 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2558 wpa_s->interface_removed = 1;
2559 wpa_supplicant_mark_disassoc(wpa_s);
2560 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2561 l2_packet_deinit(wpa_s->l2);
2563 #ifdef CONFIG_TERMINATE_ONLASTIF
2564 /* check if last interface */
2565 if (!any_interfaces(wpa_s->global->ifaces))
2567 #endif /* CONFIG_TERMINATE_ONLASTIF */
2573 #ifdef CONFIG_PEERKEY
2575 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2576 union wpa_event_data *data)
2580 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2582 #endif /* CONFIG_PEERKEY */
2586 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2587 union wpa_event_data *data)
2591 switch (data->tdls.oper) {
2592 case TDLS_REQUEST_SETUP:
2593 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2594 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2595 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2597 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2599 case TDLS_REQUEST_TEARDOWN:
2600 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2601 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2602 data->tdls.reason_code);
2604 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2607 case TDLS_REQUEST_DISCOVER:
2608 wpa_tdls_send_discovery_request(wpa_s->wpa,
2613 #endif /* CONFIG_TDLS */
2617 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2618 union wpa_event_data *data)
2622 switch (data->wnm.oper) {
2623 case WNM_OPER_SLEEP:
2624 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2625 "(action=%d, intval=%d)",
2626 data->wnm.sleep_action, data->wnm.sleep_intval);
2627 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2628 data->wnm.sleep_intval, NULL);
2632 #endif /* CONFIG_WNM */
2635 #ifdef CONFIG_IEEE80211R
2637 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2638 union wpa_event_data *data)
2643 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2644 data->ft_ies.ies_len,
2645 data->ft_ies.ft_action,
2646 data->ft_ies.target_ap,
2647 data->ft_ies.ric_ies,
2648 data->ft_ies.ric_ies_len) < 0) {
2649 /* TODO: prevent MLME/driver from trying to associate? */
2652 #endif /* CONFIG_IEEE80211R */
2655 #ifdef CONFIG_IBSS_RSN
2656 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2657 union wpa_event_data *data)
2659 struct wpa_ssid *ssid;
2660 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2664 ssid = wpa_s->current_ssid;
2667 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2670 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2674 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2675 union wpa_event_data *data)
2677 struct wpa_ssid *ssid = wpa_s->current_ssid;
2682 /* check if the ssid is correctly configured as IBSS/RSN */
2683 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2686 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2687 data->rx_mgmt.frame_len);
2689 #endif /* CONFIG_IBSS_RSN */
2692 #ifdef CONFIG_IEEE80211R
2693 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2696 const u8 *sta_addr, *target_ap_addr;
2699 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2700 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2701 return; /* only SME case supported for now */
2702 if (len < 1 + 2 * ETH_ALEN + 2)
2705 return; /* Only FT Action Response is supported for now */
2706 sta_addr = data + 1;
2707 target_ap_addr = data + 1 + ETH_ALEN;
2708 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2709 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2710 MACSTR " TargetAP " MACSTR " status %u",
2711 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2713 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2714 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2715 " in FT Action Response", MAC2STR(sta_addr));
2720 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2721 "failure (status code %d)", status);
2722 /* TODO: report error to FT code(?) */
2726 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2727 len - (1 + 2 * ETH_ALEN + 2), 1,
2728 target_ap_addr, NULL, 0) < 0)
2733 struct wpa_bss *bss;
2734 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2736 wpa_s->sme.freq = bss->freq;
2737 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2738 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2741 #endif /* CONFIG_SME */
2743 #endif /* CONFIG_IEEE80211R */
2746 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2747 struct unprot_deauth *e)
2749 #ifdef CONFIG_IEEE80211W
2750 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2751 "dropped: " MACSTR " -> " MACSTR
2752 " (reason code %u)",
2753 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2754 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2755 #endif /* CONFIG_IEEE80211W */
2759 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2760 struct unprot_disassoc *e)
2762 #ifdef CONFIG_IEEE80211W
2763 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2764 "dropped: " MACSTR " -> " MACSTR
2765 " (reason code %u)",
2766 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2767 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2768 #endif /* CONFIG_IEEE80211W */
2772 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2773 u16 reason_code, int locally_generated,
2774 const u8 *ie, size_t ie_len, int deauth)
2777 if (wpa_s->ap_iface && addr) {
2778 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2782 if (wpa_s->ap_iface) {
2783 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2786 #endif /* CONFIG_AP */
2788 if (!locally_generated)
2789 wpa_s->own_disconnect_req = 0;
2791 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2793 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2794 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2795 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2796 eapol_sm_failed(wpa_s->eapol))) &&
2797 !wpa_s->eap_expected_failure))
2798 wpas_auth_failed(wpa_s, "AUTH_FAILED");
2801 if (deauth && reason_code > 0) {
2802 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2803 locally_generated) > 0) {
2805 * The interface was removed, so cannot continue
2806 * processing any additional operations after this.
2811 #endif /* CONFIG_P2P */
2813 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2818 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2819 struct disassoc_info *info)
2821 u16 reason_code = 0;
2822 int locally_generated = 0;
2823 const u8 *addr = NULL;
2824 const u8 *ie = NULL;
2827 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2832 ie_len = info->ie_len;
2833 reason_code = info->reason_code;
2834 locally_generated = info->locally_generated;
2835 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2836 locally_generated ? " (locally generated)" : "");
2838 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2840 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2845 if (wpa_s->ap_iface && info && info->addr) {
2846 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2850 if (wpa_s->ap_iface) {
2851 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2854 #endif /* CONFIG_AP */
2858 wpas_p2p_disassoc_notif(
2859 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2862 #endif /* CONFIG_P2P */
2864 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2865 sme_event_disassoc(wpa_s, info);
2867 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2872 static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2873 struct deauth_info *info)
2875 u16 reason_code = 0;
2876 int locally_generated = 0;
2877 const u8 *addr = NULL;
2878 const u8 *ie = NULL;
2881 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2886 ie_len = info->ie_len;
2887 reason_code = info->reason_code;
2888 locally_generated = info->locally_generated;
2889 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2891 locally_generated ? " (locally generated)" : "");
2893 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2896 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2900 wpa_reset_ft_completed(wpa_s->wpa);
2902 wpas_event_disconnect(wpa_s, addr, reason_code,
2903 locally_generated, ie, ie_len, 1);
2907 static const char * reg_init_str(enum reg_change_initiator init)
2910 case REGDOM_SET_BY_CORE:
2912 case REGDOM_SET_BY_USER:
2914 case REGDOM_SET_BY_DRIVER:
2916 case REGDOM_SET_BY_COUNTRY_IE:
2917 return "COUNTRY_IE";
2918 case REGDOM_BEACON_HINT:
2919 return "BEACON_HINT";
2925 static const char * reg_type_str(enum reg_type type)
2928 case REGDOM_TYPE_UNKNOWN:
2930 case REGDOM_TYPE_COUNTRY:
2932 case REGDOM_TYPE_WORLD:
2934 case REGDOM_TYPE_CUSTOM_WORLD:
2935 return "CUSTOM_WORLD";
2936 case REGDOM_TYPE_INTERSECTION:
2937 return "INTERSECTION";
2943 static void wpa_supplicant_update_channel_list(
2944 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
2946 struct wpa_supplicant *ifs;
2948 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
2949 reg_init_str(info->initiator), reg_type_str(info->type),
2950 info->alpha2[0] ? " alpha2=" : "",
2951 info->alpha2[0] ? info->alpha2 : "");
2953 if (wpa_s->drv_priv == NULL)
2954 return; /* Ignore event during drv initialization */
2956 free_hw_features(wpa_s);
2957 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2958 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2960 wpas_p2p_update_channel_list(wpa_s);
2963 * Check other interfaces to see if they share the same radio. If
2964 * so, they get updated with this same hw mode info.
2966 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2969 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2971 free_hw_features(ifs);
2972 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2973 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2977 /* Restart sched_scan with updated channel list */
2978 if (wpa_s->sched_scanning) {
2979 wpa_dbg(wpa_s, MSG_DEBUG,
2980 "Channel list changed restart sched scan.");
2981 wpa_supplicant_cancel_sched_scan(wpa_s);
2982 wpa_supplicant_req_scan(wpa_s, 0, 0);
2987 static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2988 const u8 *frame, size_t len, int freq,
2991 const struct ieee80211_mgmt *mgmt;
2996 if (len < IEEE80211_HDRLEN + 2)
2999 mgmt = (const struct ieee80211_mgmt *) frame;
3000 payload = frame + IEEE80211_HDRLEN;
3001 category = *payload++;
3002 plen = len - IEEE80211_HDRLEN - 1;
3004 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3005 " Category=%u DataLen=%d freq=%d MHz",
3006 MAC2STR(mgmt->sa), category, (int) plen, freq);
3008 if (category == WLAN_ACTION_WMM) {
3009 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3013 #ifdef CONFIG_IEEE80211R
3014 if (category == WLAN_ACTION_FT) {
3015 ft_rx_action(wpa_s, payload, plen);
3018 #endif /* CONFIG_IEEE80211R */
3020 #ifdef CONFIG_IEEE80211W
3022 if (category == WLAN_ACTION_SA_QUERY) {
3023 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3026 #endif /* CONFIG_SME */
3027 #endif /* CONFIG_IEEE80211W */
3030 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3031 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3034 #endif /* CONFIG_WNM */
3037 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3038 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
3039 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
3040 mgmt->u.action.category,
3041 payload, plen, freq) == 0)
3043 #endif /* CONFIG_GAS */
3046 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3047 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3048 wpa_dbg(wpa_s, MSG_DEBUG,
3049 "TDLS: Received Discovery Response from " MACSTR,
3053 #endif /* CONFIG_TDLS */
3055 #ifdef CONFIG_INTERWORKING
3056 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3057 payload[0] == QOS_QOS_MAP_CONFIG) {
3058 const u8 *pos = payload + 1;
3059 size_t qlen = plen - 1;
3060 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3061 MACSTR, MAC2STR(mgmt->sa));
3062 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3063 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3064 pos[1] <= qlen - 2 && pos[1] >= 16)
3065 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3068 #endif /* CONFIG_INTERWORKING */
3070 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3071 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3072 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3076 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3077 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3078 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3079 payload + 1, plen - 1,
3084 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3085 category, payload, plen, freq);
3087 mesh_mpm_action_rx(wpa_s, mgmt, len);
3091 static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3092 union wpa_event_data *event)
3095 struct wpa_supplicant *ifs;
3096 #endif /* CONFIG_P2P */
3097 struct wpa_freq_range_list *list;
3100 list = &event->freq_range;
3103 str = freq_range_list_str(list);
3104 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3108 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3109 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3112 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3113 wpas_p2p_update_channel_list(wpa_s);
3116 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3118 if (!ifs->current_ssid ||
3119 !ifs->current_ssid->p2p_group ||
3120 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
3121 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
3124 freq = ifs->current_ssid->frequency;
3125 if (!freq_range_list_includes(list, freq)) {
3126 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
3131 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
3133 /* TODO: Consider using CSA or removing the group within
3135 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
3137 #endif /* CONFIG_P2P */
3143 static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3144 union wpa_event_data *data)
3146 wpa_dbg(wpa_s, MSG_DEBUG,
3147 "Connection authorized by device, previous state %d",
3149 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3150 wpa_supplicant_cancel_auth_timeout(wpa_s);
3151 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3152 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3153 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3155 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3156 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
3157 data->assoc_info.ptk_kck_len,
3158 data->assoc_info.ptk_kek,
3159 data->assoc_info.ptk_kek_len);
3163 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3164 union wpa_event_data *data)
3166 struct wpa_supplicant *wpa_s = ctx;
3169 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3170 event != EVENT_INTERFACE_ENABLED &&
3171 event != EVENT_INTERFACE_STATUS &&
3172 event != EVENT_SCHED_SCAN_STOPPED) {
3173 wpa_dbg(wpa_s, MSG_DEBUG,
3174 "Ignore event %s (%d) while interface is disabled",
3175 event_to_string(event), event);
3179 #ifndef CONFIG_NO_STDOUT_DEBUG
3181 int level = MSG_DEBUG;
3183 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
3184 const struct ieee80211_hdr *hdr;
3186 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3187 fc = le_to_host16(hdr->frame_control);
3188 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3189 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3190 level = MSG_EXCESSIVE;
3193 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3194 event_to_string(event), event);
3196 #endif /* CONFIG_NO_STDOUT_DEBUG */
3200 sme_event_auth(wpa_s, data);
3203 wpa_supplicant_event_assoc(wpa_s, data);
3204 if (data && data->assoc_info.authorized)
3205 wpa_supplicant_event_assoc_auth(wpa_s, data);
3207 case EVENT_DISASSOC:
3208 wpas_event_disassoc(wpa_s,
3209 data ? &data->disassoc_info : NULL);
3212 wpas_event_deauth(wpa_s,
3213 data ? &data->deauth_info : NULL);
3215 case EVENT_MICHAEL_MIC_FAILURE:
3216 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3218 #ifndef CONFIG_NO_SCAN_PROCESSING
3219 case EVENT_SCAN_STARTED:
3220 os_get_reltime(&wpa_s->scan_start_time);
3221 if (wpa_s->own_scan_requested) {
3222 struct os_reltime diff;
3224 os_reltime_sub(&wpa_s->scan_start_time,
3225 &wpa_s->scan_trigger_time, &diff);
3226 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3227 diff.sec, diff.usec);
3228 wpa_s->own_scan_requested = 0;
3229 wpa_s->own_scan_running = 1;
3230 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3231 wpa_s->manual_scan_use_id) {
3232 wpa_msg_ctrl(wpa_s, MSG_INFO,
3233 WPA_EVENT_SCAN_STARTED "id=%u",
3234 wpa_s->manual_scan_id);
3236 wpa_msg_ctrl(wpa_s, MSG_INFO,
3237 WPA_EVENT_SCAN_STARTED);
3240 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
3241 wpa_s->radio->external_scan_running = 1;
3242 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
3245 case EVENT_SCAN_RESULTS:
3246 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3247 struct os_reltime now, diff;
3248 os_get_reltime(&now);
3249 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3250 wpa_s->scan_start_time.sec = 0;
3251 wpa_s->scan_start_time.usec = 0;
3252 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3253 diff.sec, diff.usec);
3255 if (wpa_supplicant_event_scan_results(wpa_s, data))
3256 break; /* interface may have been removed */
3257 wpa_s->own_scan_running = 0;
3258 wpa_s->radio->external_scan_running = 0;
3259 radio_work_check_next(wpa_s);
3261 #endif /* CONFIG_NO_SCAN_PROCESSING */
3262 case EVENT_ASSOCINFO:
3263 wpa_supplicant_event_associnfo(wpa_s, data);
3265 case EVENT_INTERFACE_STATUS:
3266 wpa_supplicant_event_interface_status(wpa_s, data);
3268 case EVENT_PMKID_CANDIDATE:
3269 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3271 #ifdef CONFIG_PEERKEY
3272 case EVENT_STKSTART:
3273 wpa_supplicant_event_stkstart(wpa_s, data);
3275 #endif /* CONFIG_PEERKEY */
3278 wpa_supplicant_event_tdls(wpa_s, data);
3280 #endif /* CONFIG_TDLS */
3283 wpa_supplicant_event_wnm(wpa_s, data);
3285 #endif /* CONFIG_WNM */
3286 #ifdef CONFIG_IEEE80211R
3287 case EVENT_FT_RESPONSE:
3288 wpa_supplicant_event_ft_response(wpa_s, data);
3290 #endif /* CONFIG_IEEE80211R */
3291 #ifdef CONFIG_IBSS_RSN
3292 case EVENT_IBSS_RSN_START:
3293 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3295 #endif /* CONFIG_IBSS_RSN */
3296 case EVENT_ASSOC_REJECT:
3297 if (data->assoc_reject.bssid)
3298 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3299 "bssid=" MACSTR " status_code=%u",
3300 MAC2STR(data->assoc_reject.bssid),
3301 data->assoc_reject.status_code);
3303 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3305 data->assoc_reject.status_code);
3306 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3307 sme_event_assoc_reject(wpa_s, data);
3309 const u8 *bssid = data->assoc_reject.bssid;
3310 if (bssid == NULL || is_zero_ether_addr(bssid))
3311 bssid = wpa_s->pending_bssid;
3312 wpas_connection_failed(wpa_s, bssid);
3313 wpa_supplicant_mark_disassoc(wpa_s);
3316 case EVENT_AUTH_TIMED_OUT:
3317 /* It is possible to get this event from earlier connection */
3318 if (wpa_s->current_ssid &&
3319 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3320 wpa_dbg(wpa_s, MSG_DEBUG,
3321 "Ignore AUTH_TIMED_OUT in mesh configuration");
3324 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3325 sme_event_auth_timed_out(wpa_s, data);
3327 case EVENT_ASSOC_TIMED_OUT:
3328 /* It is possible to get this event from earlier connection */
3329 if (wpa_s->current_ssid &&
3330 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3331 wpa_dbg(wpa_s, MSG_DEBUG,
3332 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3335 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3336 sme_event_assoc_timed_out(wpa_s, data);
3338 case EVENT_TX_STATUS:
3339 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3340 " type=%d stype=%d",
3341 MAC2STR(data->tx_status.dst),
3342 data->tx_status.type, data->tx_status.stype);
3344 if (wpa_s->ap_iface == NULL) {
3345 #ifdef CONFIG_OFFCHANNEL
3346 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3347 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
3348 offchannel_send_action_tx_status(
3349 wpa_s, data->tx_status.dst,
3350 data->tx_status.data,
3351 data->tx_status.data_len,
3352 data->tx_status.ack ?
3353 OFFCHANNEL_SEND_ACTION_SUCCESS :
3354 OFFCHANNEL_SEND_ACTION_NO_ACK);
3355 #endif /* CONFIG_OFFCHANNEL */
3358 #endif /* CONFIG_AP */
3359 #ifdef CONFIG_OFFCHANNEL
3360 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3361 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3363 * Catch TX status events for Action frames we sent via group
3364 * interface in GO mode.
3366 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3367 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3368 os_memcmp(wpa_s->parent->pending_action_dst,
3369 data->tx_status.dst, ETH_ALEN) == 0) {
3370 offchannel_send_action_tx_status(
3371 wpa_s->parent, data->tx_status.dst,
3372 data->tx_status.data,
3373 data->tx_status.data_len,
3374 data->tx_status.ack ?
3375 OFFCHANNEL_SEND_ACTION_SUCCESS :
3376 OFFCHANNEL_SEND_ACTION_NO_ACK);
3379 #endif /* CONFIG_OFFCHANNEL */
3381 switch (data->tx_status.type) {
3382 case WLAN_FC_TYPE_MGMT:
3383 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3384 data->tx_status.data_len,
3385 data->tx_status.stype,
3386 data->tx_status.ack);
3388 case WLAN_FC_TYPE_DATA:
3389 ap_tx_status(wpa_s, data->tx_status.dst,
3390 data->tx_status.data,
3391 data->tx_status.data_len,
3392 data->tx_status.ack);
3395 #endif /* CONFIG_AP */
3398 case EVENT_EAPOL_TX_STATUS:
3399 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3400 data->eapol_tx_status.data,
3401 data->eapol_tx_status.data_len,
3402 data->eapol_tx_status.ack);
3404 case EVENT_DRIVER_CLIENT_POLL_OK:
3405 ap_client_poll_ok(wpa_s, data->client_poll.addr);
3407 case EVENT_RX_FROM_UNKNOWN:
3408 if (wpa_s->ap_iface == NULL)
3410 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3411 data->rx_from_unknown.wds);
3413 case EVENT_CH_SWITCH:
3416 if (!wpa_s->ap_iface) {
3417 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3418 "event in non-AP mode");
3422 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3423 data->ch_switch.ht_enabled,
3424 data->ch_switch.ch_offset,
3425 data->ch_switch.ch_width,
3426 data->ch_switch.cf1,
3427 data->ch_switch.cf2);
3430 case EVENT_DFS_RADAR_DETECTED:
3432 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3434 case EVENT_DFS_CAC_STARTED:
3436 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3438 case EVENT_DFS_CAC_FINISHED:
3440 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3442 case EVENT_DFS_CAC_ABORTED:
3444 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3446 case EVENT_DFS_NOP_FINISHED:
3448 wpas_event_dfs_cac_nop_finished(wpa_s,
3451 #endif /* NEED_AP_MLME */
3452 #endif /* CONFIG_AP */
3453 case EVENT_RX_MGMT: {
3455 const struct ieee80211_mgmt *mgmt;
3457 #ifdef CONFIG_TESTING_OPTIONS
3458 if (wpa_s->ext_mgmt_frame_handling) {
3459 struct rx_mgmt *rx = &data->rx_mgmt;
3460 size_t hex_len = 2 * rx->frame_len + 1;
3461 char *hex = os_malloc(hex_len);
3463 wpa_snprintf_hex(hex, hex_len,
3464 rx->frame, rx->frame_len);
3465 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3466 rx->freq, rx->datarate, rx->ssi_signal,
3472 #endif /* CONFIG_TESTING_OPTIONS */
3474 mgmt = (const struct ieee80211_mgmt *)
3475 data->rx_mgmt.frame;
3476 fc = le_to_host16(mgmt->frame_control);
3477 stype = WLAN_FC_GET_STYPE(fc);
3480 if (wpa_s->ap_iface == NULL) {
3481 #endif /* CONFIG_AP */
3483 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3484 data->rx_mgmt.frame_len > 24) {
3485 const u8 *src = mgmt->sa;
3486 const u8 *ie = mgmt->u.probe_req.variable;
3487 size_t ie_len = data->rx_mgmt.frame_len -
3488 (mgmt->u.probe_req.variable -
3489 data->rx_mgmt.frame);
3490 wpas_p2p_probe_req_rx(
3491 wpa_s, src, mgmt->da,
3492 mgmt->bssid, ie, ie_len,
3493 data->rx_mgmt.ssi_signal);
3496 #endif /* CONFIG_P2P */
3497 #ifdef CONFIG_IBSS_RSN
3498 if (wpa_s->current_ssid &&
3499 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3500 stype == WLAN_FC_STYPE_AUTH &&
3501 data->rx_mgmt.frame_len >= 30) {
3502 wpa_supplicant_event_ibss_auth(wpa_s, data);
3505 #endif /* CONFIG_IBSS_RSN */
3507 if (stype == WLAN_FC_STYPE_ACTION) {
3508 wpas_event_rx_mgmt_action(
3509 wpa_s, data->rx_mgmt.frame,
3510 data->rx_mgmt.frame_len,
3512 data->rx_mgmt.ssi_signal);
3517 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
3521 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3522 "management frame in non-AP mode");
3527 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3528 data->rx_mgmt.frame_len > 24) {
3529 const u8 *ie = mgmt->u.probe_req.variable;
3530 size_t ie_len = data->rx_mgmt.frame_len -
3531 (mgmt->u.probe_req.variable -
3532 data->rx_mgmt.frame);
3534 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3535 mgmt->bssid, ie, ie_len,
3536 data->rx_mgmt.ssi_signal);
3539 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
3540 #endif /* CONFIG_AP */
3543 case EVENT_RX_PROBE_REQ:
3544 if (data->rx_probe_req.sa == NULL ||
3545 data->rx_probe_req.ie == NULL)
3548 if (wpa_s->ap_iface) {
3549 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3550 data->rx_probe_req.sa,
3551 data->rx_probe_req.da,
3552 data->rx_probe_req.bssid,
3553 data->rx_probe_req.ie,
3554 data->rx_probe_req.ie_len,
3555 data->rx_probe_req.ssi_signal);
3558 #endif /* CONFIG_AP */
3559 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
3560 data->rx_probe_req.da,
3561 data->rx_probe_req.bssid,
3562 data->rx_probe_req.ie,
3563 data->rx_probe_req.ie_len,
3564 data->rx_probe_req.ssi_signal);
3566 case EVENT_REMAIN_ON_CHANNEL:
3567 #ifdef CONFIG_OFFCHANNEL
3568 offchannel_remain_on_channel_cb(
3569 wpa_s, data->remain_on_channel.freq,
3570 data->remain_on_channel.duration);
3571 #endif /* CONFIG_OFFCHANNEL */
3572 wpas_p2p_remain_on_channel_cb(
3573 wpa_s, data->remain_on_channel.freq,
3574 data->remain_on_channel.duration);
3576 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
3577 #ifdef CONFIG_OFFCHANNEL
3578 offchannel_cancel_remain_on_channel_cb(
3579 wpa_s, data->remain_on_channel.freq);
3580 #endif /* CONFIG_OFFCHANNEL */
3581 wpas_p2p_cancel_remain_on_channel_cb(
3582 wpa_s, data->remain_on_channel.freq);
3584 case EVENT_EAPOL_RX:
3585 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3586 data->eapol_rx.data,
3587 data->eapol_rx.data_len);
3589 case EVENT_SIGNAL_CHANGE:
3590 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3591 "above=%d signal=%d noise=%d txrate=%d",
3592 data->signal_change.above_threshold,
3593 data->signal_change.current_signal,
3594 data->signal_change.current_noise,
3595 data->signal_change.current_txrate);
3596 wpa_bss_update_level(wpa_s->current_bss,
3597 data->signal_change.current_signal);
3598 bgscan_notify_signal_change(
3599 wpa_s, data->signal_change.above_threshold,
3600 data->signal_change.current_signal,
3601 data->signal_change.current_noise,
3602 data->signal_change.current_txrate);
3604 case EVENT_INTERFACE_ENABLED:
3605 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3606 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3607 wpa_supplicant_update_mac_addr(wpa_s);
3608 if (wpa_s->p2p_mgmt) {
3609 wpa_supplicant_set_state(wpa_s,
3615 if (!wpa_s->ap_iface) {
3616 wpa_supplicant_set_state(wpa_s,
3618 wpa_s->scan_req = NORMAL_SCAN_REQ;
3619 wpa_supplicant_req_scan(wpa_s, 0, 0);
3621 wpa_supplicant_set_state(wpa_s,
3623 #else /* CONFIG_AP */
3624 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3625 wpa_supplicant_req_scan(wpa_s, 0, 0);
3626 #endif /* CONFIG_AP */
3629 case EVENT_INTERFACE_DISABLED:
3630 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3632 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3633 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3634 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3636 * Mark interface disabled if this happens to end up not
3637 * being removed as a separate P2P group interface.
3639 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3641 * The interface was externally disabled. Remove
3642 * it assuming an external entity will start a
3643 * new session if needed.
3645 if (wpa_s->current_ssid &&
3646 wpa_s->current_ssid->p2p_group)
3647 wpas_p2p_interface_unavailable(wpa_s);
3649 wpas_p2p_disconnect(wpa_s);
3651 * wpa_s instance may have been freed, so must not use
3656 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3657 p2p_in_progress(wpa_s->global->p2p) > 1) {
3658 /* This radio work will be cancelled, so clear P2P
3661 p2p_stop_find(wpa_s->global->p2p);
3663 #endif /* CONFIG_P2P */
3665 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3667 * Indicate disconnection to keep ctrl_iface events
3670 wpa_supplicant_event_disassoc(
3671 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3673 wpa_supplicant_mark_disassoc(wpa_s);
3674 radio_remove_works(wpa_s, NULL, 0);
3676 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3678 case EVENT_CHANNEL_LIST_CHANGED:
3679 wpa_supplicant_update_channel_list(
3680 wpa_s, &data->channel_list_changed);
3682 case EVENT_INTERFACE_UNAVAILABLE:
3683 wpas_p2p_interface_unavailable(wpa_s);
3685 case EVENT_BEST_CHANNEL:
3686 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3688 data->best_chan.freq_24, data->best_chan.freq_5,
3689 data->best_chan.freq_overall);
3690 wpa_s->best_24_freq = data->best_chan.freq_24;
3691 wpa_s->best_5_freq = data->best_chan.freq_5;
3692 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3693 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3694 data->best_chan.freq_5,
3695 data->best_chan.freq_overall);
3697 case EVENT_UNPROT_DEAUTH:
3698 wpa_supplicant_event_unprot_deauth(wpa_s,
3699 &data->unprot_deauth);
3701 case EVENT_UNPROT_DISASSOC:
3702 wpa_supplicant_event_unprot_disassoc(wpa_s,
3703 &data->unprot_disassoc);
3705 case EVENT_STATION_LOW_ACK:
3707 if (wpa_s->ap_iface && data)
3708 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3709 data->low_ack.addr);
3710 #endif /* CONFIG_AP */
3713 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3714 data->low_ack.addr);
3715 #endif /* CONFIG_TDLS */
3717 case EVENT_IBSS_PEER_LOST:
3718 #ifdef CONFIG_IBSS_RSN
3719 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3720 #endif /* CONFIG_IBSS_RSN */
3722 case EVENT_DRIVER_GTK_REKEY:
3723 if (os_memcmp(data->driver_gtk_rekey.bssid,
3724 wpa_s->bssid, ETH_ALEN))
3728 wpa_sm_update_replay_ctr(wpa_s->wpa,
3729 data->driver_gtk_rekey.replay_ctr);
3731 case EVENT_SCHED_SCAN_STOPPED:
3733 wpa_s->sched_scanning = 0;
3734 resched = wpa_s->scanning;
3735 wpa_supplicant_notify_scanning(wpa_s, 0);
3737 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3741 * Start a new sched scan to continue searching for more SSIDs
3742 * either if timed out or PNO schedule scan is pending.
3744 if (wpa_s->sched_scan_timed_out) {
3745 wpa_supplicant_req_sched_scan(wpa_s);
3746 } else if (wpa_s->pno_sched_pending) {
3747 wpa_s->pno_sched_pending = 0;
3748 wpas_start_pno(wpa_s);
3749 } else if (resched) {
3750 wpa_supplicant_req_scan(wpa_s, 0, 0);
3754 case EVENT_WPS_BUTTON_PUSHED:
3756 wpas_wps_start_pbc(wpa_s, NULL, 0);
3757 #endif /* CONFIG_WPS */
3759 case EVENT_AVOID_FREQUENCIES:
3760 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3762 case EVENT_CONNECT_FAILED_REASON:
3764 if (!wpa_s->ap_iface || !data)
3766 hostapd_event_connect_failed_reason(
3767 wpa_s->ap_iface->bss[0],
3768 data->connect_failed_reason.addr,
3769 data->connect_failed_reason.code);
3770 #endif /* CONFIG_AP */
3772 case EVENT_NEW_PEER_CANDIDATE:
3774 if (!wpa_s->ifmsh || !data)
3776 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3777 data->mesh_peer.ies,
3778 data->mesh_peer.ie_len);
3779 #endif /* CONFIG_MESH */
3782 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);