2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, 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"
47 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
51 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
52 struct wpa_ssid *ssid)
56 if (ssid == NULL || ssid->disabled_until.sec == 0)
60 if (ssid->disabled_until.sec > now.sec)
61 return ssid->disabled_until.sec - now.sec;
63 wpas_clear_temp_disabled(wpa_s, ssid, 0);
69 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
71 struct wpa_ssid *ssid, *old_ssid;
74 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
79 ssid = wpa_supplicant_get_ssid(wpa_s);
81 wpa_msg(wpa_s, MSG_INFO,
82 "No network configuration found for the current AP");
86 if (wpas_network_disabled(wpa_s, ssid)) {
87 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
91 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
92 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
93 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
97 res = wpas_temp_disabled(wpa_s, ssid);
99 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
100 "disabled for %d second(s)", res);
104 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
106 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
108 size_t wpa_ie_len = sizeof(wpa_ie);
109 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
110 wpa_ie, &wpa_ie_len) < 0)
111 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
113 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
117 eapol_sm_invalidate_cached_session(wpa_s->eapol);
118 old_ssid = wpa_s->current_ssid;
119 wpa_s->current_ssid = ssid;
120 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
121 wpa_supplicant_initiate_eapol(wpa_s);
122 if (old_ssid != wpa_s->current_ssid)
123 wpas_notify_network_changed(wpa_s);
129 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
131 struct wpa_supplicant *wpa_s = eloop_ctx;
133 if (wpa_s->countermeasures) {
134 wpa_s->countermeasures = 0;
135 wpa_drv_set_countermeasures(wpa_s, 0);
136 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
137 wpa_supplicant_req_scan(wpa_s, 0, 0);
142 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
146 wnm_bss_keep_alive_deinit(wpa_s);
148 #ifdef CONFIG_IBSS_RSN
149 ibss_rsn_deinit(wpa_s->ibss_rsn);
150 wpa_s->ibss_rsn = NULL;
151 #endif /* CONFIG_IBSS_RSN */
154 wpa_supplicant_ap_deinit(wpa_s);
155 #endif /* CONFIG_AP */
157 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
162 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
164 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
165 os_memset(wpa_s->bssid, 0, ETH_ALEN);
166 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
168 wpa_s->sme.prev_bssid_set = 0;
169 #endif /* CONFIG_SME */
171 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
172 #endif /* CONFIG_P2P */
173 wpa_s->current_bss = NULL;
174 wpa_s->assoc_freq = 0;
175 #ifdef CONFIG_IEEE80211R
177 if (wpa_s->sme.ft_ies)
178 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
179 #endif /* CONFIG_SME */
180 #endif /* CONFIG_IEEE80211R */
183 wpas_notify_bssid_changed(wpa_s);
185 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
186 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
187 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
188 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
189 wpa_s->ap_ies_from_associnfo = 0;
190 wpa_s->current_ssid = NULL;
195 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
197 struct wpa_ie_data ie;
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
220 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
240 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
246 #ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
256 #endif /* IEEE8021X_EAPOL */
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
271 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
274 #ifdef IEEE8021X_EAPOL
276 int aka = 0, sim = 0, type;
278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
281 if (ssid->eap.eap_methods == NULL) {
285 struct eap_method_type *eap = ssid->eap.eap_methods;
286 while (eap->vendor != EAP_VENDOR_IETF ||
287 eap->method != EAP_TYPE_NONE) {
288 if (eap->vendor == EAP_VENDOR_IETF) {
289 if (eap->method == EAP_TYPE_SIM)
291 else if (eap->method == EAP_TYPE_AKA ||
292 eap->method == EAP_TYPE_AKA_PRIME)
299 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
302 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
307 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
308 "use SIM, but neither EAP-SIM nor EAP-AKA are "
313 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
314 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
316 type = SCARD_TRY_BOTH;
318 type = SCARD_USIM_ONLY;
320 type = SCARD_GSM_SIM_ONLY;
322 wpa_s->scard = scard_init(type, NULL);
323 if (wpa_s->scard == NULL) {
324 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
328 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
329 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
330 #endif /* PCSC_FUNCS */
331 #endif /* IEEE8021X_EAPOL */
337 #ifndef CONFIG_NO_SCAN_PROCESSING
338 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
339 struct wpa_ssid *ssid)
343 if (ssid->mixed_cell)
347 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
349 #endif /* CONFIG_WPS */
351 for (i = 0; i < NUM_WEP_KEYS; i++) {
352 if (ssid->wep_key_len[i]) {
357 #ifdef IEEE8021X_EAPOL
358 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
359 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
360 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
362 #endif /* IEEE8021X_EAPOL */
364 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
367 if (bss->caps & IEEE80211_CAP_PRIVACY)
373 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
374 struct wpa_ssid *ssid,
377 struct wpa_ie_data ie;
379 const u8 *rsn_ie, *wpa_ie;
383 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
387 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
388 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
389 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
390 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
391 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
393 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
394 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
397 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
398 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
404 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
406 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
411 if (!(ie.proto & ssid->proto)) {
412 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
417 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
423 if (!(ie.group_cipher & ssid->group_cipher)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
429 if (!(ie.key_mgmt & ssid->key_mgmt)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
435 #ifdef CONFIG_IEEE80211W
436 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
437 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
438 wpa_s->conf->pmf : ssid->ieee80211w) ==
439 MGMT_FRAME_PROTECTION_REQUIRED) {
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
444 #endif /* CONFIG_IEEE80211W */
446 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
450 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
451 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
454 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
455 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
461 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
463 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
468 if (!(ie.proto & ssid->proto)) {
469 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
474 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
480 if (!(ie.group_cipher & ssid->group_cipher)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
486 if (!(ie.key_mgmt & ssid->key_mgmt)) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
492 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
496 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
498 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
502 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
503 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
504 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
508 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
509 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
513 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
520 static int freq_allowed(int *freqs, int freq)
527 for (i = 0; freqs[i]; i++)
528 if (freqs[i] == freq)
534 static int ht_supported(const struct hostapd_hw_modes *mode)
536 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
538 * The driver did not indicate whether it supports HT. Assume
539 * it does to avoid connection issues.
545 * IEEE Std 802.11n-2009 20.1.1:
546 * An HT non-AP STA shall support all EQM rates for one spatial stream.
548 return mode->mcs_set[0] == 0xff;
552 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
554 const struct hostapd_hw_modes *mode = NULL, *modes;
555 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
560 return 1; /* Cannot do matching without knowing band */
562 modes = wpa_s->hw.modes;
565 * The driver does not provide any additional information
566 * about the utilized hardware, so allow the connection attempt
572 for (i = 0; i < wpa_s->hw.num_modes; i++) {
573 for (j = 0; j < modes[i].num_channels; j++) {
574 int freq = modes[i].channels[j].freq;
575 if (freq == bss->freq) {
577 mode->mode == HOSTAPD_MODE_IEEE80211G)
578 break; /* do not allow 802.11b replace
589 for (i = 0; i < (int) sizeof(scan_ie); i++) {
590 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
594 for (j = 2; j < rate_ie[1] + 2; j++) {
595 int flagged = !!(rate_ie[j] & 0x80);
596 int r = (rate_ie[j] & 0x7f) * 5;
599 * IEEE Std 802.11n-2009 7.3.2.2:
600 * The new BSS Membership selector value is encoded
601 * like a legacy basic rate, but it is not a rate and
602 * only indicates if the BSS members are required to
603 * support the mandatory features of Clause 20 [HT PHY]
604 * in order to join the BSS.
606 if (flagged && ((rate_ie[j] & 0x7f) ==
607 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
608 if (!ht_supported(mode)) {
609 wpa_dbg(wpa_s, MSG_DEBUG,
610 " hardware does not support "
620 /* check for legacy basic rates */
621 for (k = 0; k < mode->num_rates; k++) {
622 if (mode->rates[k] == r)
625 if (k == mode->num_rates) {
627 * IEEE Std 802.11-2007 7.3.2.2 demands that in
628 * order to join a BSS all required rates
629 * have to be supported by the hardware.
631 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
632 "not support required rate %d.%d Mbps",
643 static int bss_is_dmg(struct wpa_bss *bss)
645 return bss->freq > 45000;
650 * Test whether BSS is in an ESS.
651 * This is done differently in DMG (60 GHz) and non-DMG bands
653 static int bss_is_ess(struct wpa_bss *bss)
655 if (bss_is_dmg(bss)) {
656 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
657 IEEE80211_CAP_DMG_AP;
660 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
665 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
666 int i, struct wpa_bss *bss,
667 struct wpa_ssid *group)
669 u8 wpa_ie_len, rsn_ie_len;
671 struct wpa_blacklist *e;
673 struct wpa_ssid *ssid;
675 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
676 wpa_ie_len = ie ? ie[1] : 0;
678 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
679 rsn_ie_len = ie ? ie[1] : 0;
681 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
682 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
683 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
684 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
685 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
687 e = wpa_blacklist_get(wpa_s, bss->bssid);
690 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
692 * When only a single network is enabled, we can
693 * trigger blacklisting on the first failure. This
694 * should not be done with multiple enabled networks to
695 * avoid getting forced to move into a worse ESS on
696 * single error if there are no other BSSes of the
701 if (e->count > limit) {
702 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
703 "(count=%d limit=%d)", e->count, limit);
708 if (bss->ssid_len == 0) {
709 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
713 if (disallowed_bssid(wpa_s, bss->bssid)) {
714 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
718 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
719 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
723 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
725 for (ssid = group; ssid; ssid = ssid->pnext) {
726 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
729 if (wpas_network_disabled(wpa_s, ssid)) {
730 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
734 res = wpas_temp_disabled(wpa_s, ssid);
736 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
737 "temporarily for %d second(s)", res);
742 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
743 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
748 if (wpa && ssid->ssid_len == 0 &&
749 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
752 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
753 /* Only allow wildcard SSID match if an AP
754 * advertises active WPS operation that matches
757 if (ssid->ssid_len == 0 &&
758 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
761 #endif /* CONFIG_WPS */
763 if (ssid->bssid_set && ssid->ssid_len == 0 &&
764 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
768 (bss->ssid_len != ssid->ssid_len ||
769 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
770 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
774 if (ssid->bssid_set &&
775 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
780 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
784 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
785 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
786 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
787 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
792 if (!wpa_supplicant_match_privacy(bss, ssid)) {
793 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
798 if (!bss_is_ess(bss)) {
799 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
803 if (!freq_allowed(ssid->freq_list, bss->freq)) {
804 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
809 if (!rate_match(wpa_s, bss)) {
810 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
817 * TODO: skip the AP if its P2P IE has Group Formation
818 * bit set in the P2P Group Capability Bitmap and we
819 * are not in Group Formation with that device.
821 #endif /* CONFIG_P2P */
823 /* Matching configuration found */
827 /* No matching configuration found */
832 static struct wpa_bss *
833 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
834 struct wpa_ssid *group,
835 struct wpa_ssid **selected_ssid)
839 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
842 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
843 struct wpa_bss *bss = wpa_s->last_scan_res[i];
844 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
847 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
850 wpa_ssid_txt(bss->ssid, bss->ssid_len));
858 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
859 struct wpa_ssid **selected_ssid)
861 struct wpa_bss *selected = NULL;
864 if (wpa_s->last_scan_res == NULL ||
865 wpa_s->last_scan_res_used == 0)
866 return NULL; /* no scan results from last update */
868 while (selected == NULL) {
869 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
870 selected = wpa_supplicant_select_bss(
871 wpa_s, wpa_s->conf->pssid[prio],
877 if (selected == NULL && wpa_s->blacklist &&
878 !wpa_s->countermeasures) {
879 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
880 "blacklist and try again");
881 wpa_blacklist_clear(wpa_s);
882 wpa_s->blacklist_cleared++;
883 } else if (selected == NULL)
891 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
892 int timeout_sec, int timeout_usec)
894 if (!wpa_supplicant_enabled_networks(wpa_s)) {
896 * No networks are enabled; short-circuit request so
897 * we don't wait timeout seconds before transitioning
900 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
901 "since there are no enabled networks");
902 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
904 wpa_s->sta_scan_pending = 0;
905 #endif /* CONFIG_P2P */
909 wpa_s->scan_for_connection = 1;
910 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
914 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
915 struct wpa_bss *selected,
916 struct wpa_ssid *ssid)
918 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
919 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
920 "PBC session overlap");
922 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
924 #endif /* CONFIG_P2P */
927 wpas_wps_cancel(wpa_s);
928 #endif /* CONFIG_WPS */
933 * Do not trigger new association unless the BSSID has changed or if
934 * reassociation is requested. If we are in process of associating with
935 * the selected BSSID, do not trigger new attempt.
937 if (wpa_s->reassociate ||
938 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
939 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
940 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
941 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
943 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
944 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
947 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
948 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
949 " pending: " MACSTR " wpa_state: %s",
950 wpa_s->reassociate, MAC2STR(selected->bssid),
951 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
952 wpa_supplicant_state_txt(wpa_s->wpa_state));
953 wpa_supplicant_associate(wpa_s, selected, ssid);
955 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
963 static struct wpa_ssid *
964 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
967 struct wpa_ssid *ssid;
969 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
970 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
972 if (wpas_network_disabled(wpa_s, ssid))
974 if (ssid->mode == IEEE80211_MODE_IBSS ||
975 ssid->mode == IEEE80211_MODE_AP)
983 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
984 * on BSS added and BSS changed events */
985 static void wpa_supplicant_rsn_preauth_scan_results(
986 struct wpa_supplicant *wpa_s)
990 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
993 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
994 const u8 *ssid, *rsn;
996 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1000 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1004 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1010 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1011 struct wpa_bss *selected,
1012 struct wpa_ssid *ssid)
1014 struct wpa_bss *current_bss = NULL;
1017 if (wpa_s->reassociate)
1018 return 1; /* explicit request to reassociate */
1019 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1020 return 1; /* we are not associated; continue */
1021 if (wpa_s->current_ssid == NULL)
1022 return 1; /* unknown current SSID */
1023 if (wpa_s->current_ssid != ssid)
1024 return 1; /* different network block */
1026 if (wpas_driver_bss_selection(wpa_s))
1027 return 0; /* Driver-based roaming */
1029 if (wpa_s->current_ssid->ssid)
1030 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1031 wpa_s->current_ssid->ssid,
1032 wpa_s->current_ssid->ssid_len);
1034 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1037 return 1; /* current BSS not seen in scan results */
1039 if (current_bss == selected)
1042 if (selected->last_update_idx > current_bss->last_update_idx)
1043 return 1; /* current BSS not seen in the last scan */
1045 #ifndef CONFIG_NO_ROAMING
1046 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1047 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1048 MAC2STR(current_bss->bssid), current_bss->level);
1049 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1050 MAC2STR(selected->bssid), selected->level);
1052 if (wpa_s->current_ssid->bssid_set &&
1053 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1055 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1056 "has preferred BSSID");
1060 if (current_bss->level < 0 && current_bss->level > selected->level) {
1061 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1067 if (current_bss->level < 0) {
1068 if (current_bss->level < -85)
1070 else if (current_bss->level < -80)
1072 else if (current_bss->level < -75)
1074 else if (current_bss->level < -70)
1079 if (abs(current_bss->level - selected->level) < min_diff) {
1080 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1086 #else /* CONFIG_NO_ROAMING */
1088 #endif /* CONFIG_NO_ROAMING */
1092 /* Return != 0 if no scan results could be fetched or if scan results should not
1093 * be shared with other virtual interfaces. */
1094 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1095 union wpa_event_data *data,
1098 struct wpa_scan_results *scan_res;
1100 #ifndef CONFIG_NO_RANDOM_POOL
1102 #endif /* CONFIG_NO_RANDOM_POOL */
1105 if (wpa_s->ap_iface)
1107 #endif /* CONFIG_AP */
1109 wpa_supplicant_notify_scanning(wpa_s, 0);
1112 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1113 !wpa_s->global->p2p_disabled &&
1114 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1115 !wpa_s->scan_res_handler) {
1116 wpa_s->global->p2p_cb_on_scan_complete = 0;
1117 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1118 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1119 "stopped scan processing");
1120 wpa_s->sta_scan_pending = 1;
1121 wpa_supplicant_req_scan(wpa_s, 5, 0);
1125 wpa_s->sta_scan_pending = 0;
1126 #endif /* CONFIG_P2P */
1128 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1129 data ? &data->scan_info :
1131 if (scan_res == NULL) {
1132 if (wpa_s->conf->ap_scan == 2 || ap ||
1133 wpa_s->scan_res_handler == scan_only_handler)
1137 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1139 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1143 #ifndef CONFIG_NO_RANDOM_POOL
1144 num = scan_res->num;
1147 for (i = 0; i < num; i++) {
1149 struct wpa_scan_res *res = scan_res->res[i];
1150 buf[0] = res->bssid[5];
1151 buf[1] = res->qual & 0xff;
1152 buf[2] = res->noise & 0xff;
1153 buf[3] = res->level & 0xff;
1154 buf[4] = res->tsf & 0xff;
1155 random_add_randomness(buf, sizeof(buf));
1157 #endif /* CONFIG_NO_RANDOM_POOL */
1159 if (own_request && wpa_s->scan_res_handler) {
1160 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1161 struct wpa_scan_results *scan_res);
1163 scan_res_handler = wpa_s->scan_res_handler;
1164 wpa_s->scan_res_handler = NULL;
1165 scan_res_handler(wpa_s, scan_res);
1167 wpa_scan_results_free(scan_res);
1172 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1174 if (wpa_s->ap_iface->scan_cb)
1175 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1176 #endif /* CONFIG_AP */
1177 wpa_scan_results_free(scan_res);
1181 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1182 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1183 wpas_notify_scan_results(wpa_s);
1185 wpas_notify_scan_done(wpa_s, 1);
1187 if (sme_proc_obss_scan(wpa_s) > 0) {
1188 wpa_scan_results_free(scan_res);
1192 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1193 wpa_scan_results_free(scan_res);
1197 if (autoscan_notify_scan(wpa_s, scan_res)) {
1198 wpa_scan_results_free(scan_res);
1202 if (wpa_s->disconnected) {
1203 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1204 wpa_scan_results_free(scan_res);
1208 if (!wpas_driver_bss_selection(wpa_s) &&
1209 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1210 wpa_scan_results_free(scan_res);
1214 wpas_wps_update_ap_info(wpa_s, scan_res);
1216 wpa_scan_results_free(scan_res);
1218 return wpas_select_network_from_last_scan(wpa_s, 1);
1222 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1225 struct wpa_bss *selected;
1226 struct wpa_ssid *ssid = NULL;
1228 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1232 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1235 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1239 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1240 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1244 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1246 * Do not notify other virtual radios of scan results since we do not
1247 * want them to start other associations at the same time.
1251 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1252 ssid = wpa_supplicant_pick_new_network(wpa_s);
1254 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1255 wpa_supplicant_associate(wpa_s, NULL, ssid);
1257 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1259 int timeout_sec = wpa_s->scan_interval;
1260 int timeout_usec = 0;
1262 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1265 if (wpa_s->p2p_in_provisioning) {
1267 * Use shorter wait during P2P Provisioning
1268 * state to speed up group formation.
1271 timeout_usec = 250000;
1272 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1276 #endif /* CONFIG_P2P */
1277 #ifdef CONFIG_INTERWORKING
1278 if (wpa_s->conf->auto_interworking &&
1279 wpa_s->conf->interworking &&
1280 wpa_s->conf->cred) {
1281 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1282 "start ANQP fetch since no matching "
1284 wpa_s->network_select = 1;
1285 wpa_s->auto_network_select = 1;
1286 interworking_start_fetch_anqp(wpa_s);
1289 #endif /* CONFIG_INTERWORKING */
1290 if (wpa_supplicant_req_sched_scan(wpa_s))
1291 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1299 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1300 union wpa_event_data *data)
1302 const char *rn, *rn2;
1303 struct wpa_supplicant *ifs;
1305 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1307 * If no scan results could be fetched, then no need to
1308 * notify those interfaces that did not actually request
1309 * this scan. Similarly, if scan results started a new operation on this
1310 * interface, do not notify other interfaces to avoid concurrent
1311 * operations during a connection attempt.
1317 * Check other interfaces to see if they have the same radio-name. If
1318 * so, they get updated with this same scan info.
1320 if (!wpa_s->driver->get_radio_name)
1323 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1324 if (rn == NULL || rn[0] == '\0')
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1328 "sharing same radio (%s) in event_scan_results", rn);
1330 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1331 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1334 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1335 if (rn2 && os_strcmp(rn, rn2) == 0) {
1336 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1337 "sibling", ifs->ifname);
1338 _wpa_supplicant_event_scan_results(ifs, data, 0);
1343 #endif /* CONFIG_NO_SCAN_PROCESSING */
1346 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1348 #ifdef CONFIG_NO_SCAN_PROCESSING
1350 #else /* CONFIG_NO_SCAN_PROCESSING */
1353 if (wpa_s->last_scan_res_used <= 0)
1357 if (now.sec - wpa_s->last_scan.sec > 5) {
1358 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1362 return wpas_select_network_from_last_scan(wpa_s, 0);
1363 #endif /* CONFIG_NO_SCAN_PROCESSING */
1368 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1370 struct wpa_supplicant *wpa_s = eloop_ctx;
1372 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1375 if (!wpa_s->no_keep_alive) {
1376 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1377 MAC2STR(wpa_s->bssid));
1378 /* TODO: could skip this if normal data traffic has been sent */
1379 /* TODO: Consider using some more appropriate data frame for
1382 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1387 if (wpa_s->sme.bss_max_idle_period) {
1389 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1392 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1393 wnm_bss_keep_alive, wpa_s, NULL);
1395 #endif /* CONFIG_SME */
1399 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1400 const u8 *ies, size_t ies_len)
1402 struct ieee802_11_elems elems;
1407 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1411 if (elems.bss_max_idle_period) {
1413 wpa_s->sme.bss_max_idle_period =
1414 WPA_GET_LE16(elems.bss_max_idle_period);
1415 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1416 "TU)%s", wpa_s->sme.bss_max_idle_period,
1417 (elems.bss_max_idle_period[2] & 0x01) ?
1418 " (protected keep-live required)" : "");
1419 if (wpa_s->sme.bss_max_idle_period == 0)
1420 wpa_s->sme.bss_max_idle_period = 1;
1421 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1422 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1423 /* msec times 1000 */
1424 msec = wpa_s->sme.bss_max_idle_period * 1024;
1427 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1428 wnm_bss_keep_alive, wpa_s,
1432 #endif /* CONFIG_SME */
1435 #endif /* CONFIG_WNM */
1438 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1441 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1442 #endif /* CONFIG_WNM */
1446 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1447 union wpa_event_data *data)
1449 int l, len, found = 0, wpa_found, rsn_found;
1451 #ifdef CONFIG_IEEE80211R
1453 #endif /* CONFIG_IEEE80211R */
1455 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1456 if (data->assoc_info.req_ies)
1457 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1458 data->assoc_info.req_ies_len);
1459 if (data->assoc_info.resp_ies) {
1460 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1461 data->assoc_info.resp_ies_len);
1463 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1464 data->assoc_info.resp_ies_len);
1465 #endif /* CONFIG_TDLS */
1467 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1468 data->assoc_info.resp_ies_len);
1469 #endif /* CONFIG_WNM */
1471 if (data->assoc_info.beacon_ies)
1472 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1473 data->assoc_info.beacon_ies,
1474 data->assoc_info.beacon_ies_len);
1475 if (data->assoc_info.freq)
1476 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1477 data->assoc_info.freq);
1479 p = data->assoc_info.req_ies;
1480 l = data->assoc_info.req_ies_len;
1482 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1483 while (p && l >= 2) {
1486 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1490 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1491 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1492 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1493 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1496 wpa_find_assoc_pmkid(wpa_s);
1502 if (!found && data->assoc_info.req_ies)
1503 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1505 #ifdef CONFIG_IEEE80211R
1507 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1508 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1509 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1510 data->assoc_info.resp_ies,
1511 data->assoc_info.resp_ies_len,
1513 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1514 "Reassociation Response failed");
1515 wpa_supplicant_deauthenticate(
1516 wpa_s, WLAN_REASON_INVALID_IE);
1521 p = data->assoc_info.resp_ies;
1522 l = data->assoc_info.resp_ies_len;
1524 #ifdef CONFIG_WPS_STRICT
1525 if (p && wpa_s->current_ssid &&
1526 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1528 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1530 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1531 "include WPS IE in (Re)Association Response");
1535 if (wps_validate_assoc_resp(wps) < 0) {
1537 wpa_supplicant_deauthenticate(
1538 wpa_s, WLAN_REASON_INVALID_IE);
1543 #endif /* CONFIG_WPS_STRICT */
1545 /* Go through the IEs and make a copy of the MDIE, if present. */
1546 while (p && l >= 2) {
1549 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1553 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1554 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1555 wpa_s->sme.ft_used = 1;
1556 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1557 MOBILITY_DOMAIN_ID_LEN);
1563 #endif /* CONFIG_SME */
1565 /* Process FT when SME is in the driver */
1566 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1567 wpa_ft_is_completed(wpa_s->wpa)) {
1568 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1569 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1570 data->assoc_info.resp_ies,
1571 data->assoc_info.resp_ies_len,
1573 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1574 "Reassociation Response failed");
1575 wpa_supplicant_deauthenticate(
1576 wpa_s, WLAN_REASON_INVALID_IE);
1579 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1582 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1583 data->assoc_info.resp_ies_len);
1584 #endif /* CONFIG_IEEE80211R */
1586 /* WPA/RSN IE from Beacon/ProbeResp */
1587 p = data->assoc_info.beacon_ies;
1588 l = data->assoc_info.beacon_ies_len;
1590 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1592 wpa_found = rsn_found = 0;
1593 while (p && l >= 2) {
1596 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1601 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1602 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1604 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1608 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1610 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1617 if (!wpa_found && data->assoc_info.beacon_ies)
1618 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1619 if (!rsn_found && data->assoc_info.beacon_ies)
1620 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1621 if (wpa_found || rsn_found)
1622 wpa_s->ap_ies_from_associnfo = 1;
1624 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1625 wpa_s->assoc_freq != data->assoc_info.freq) {
1626 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1628 wpa_s->assoc_freq, data->assoc_info.freq);
1629 wpa_supplicant_update_scan_results(wpa_s);
1632 wpa_s->assoc_freq = data->assoc_info.freq;
1638 static struct wpa_bss * wpa_supplicant_get_new_bss(
1639 struct wpa_supplicant *wpa_s, const u8 *bssid)
1641 struct wpa_bss *bss = NULL;
1642 struct wpa_ssid *ssid = wpa_s->current_ssid;
1644 if (ssid->ssid_len > 0)
1645 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1647 bss = wpa_bss_get_bssid(wpa_s, bssid);
1653 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1655 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1657 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1660 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1663 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1664 WPA_IE_VENDOR_TYPE);
1665 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1667 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1668 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1669 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1670 bss_rsn ? 2 + bss_rsn[1] : 0))
1677 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1678 union wpa_event_data *data)
1684 if (wpa_s->ap_iface) {
1685 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1686 data->assoc_info.addr,
1687 data->assoc_info.req_ies,
1688 data->assoc_info.req_ies_len,
1689 data->assoc_info.reassoc);
1692 #endif /* CONFIG_AP */
1694 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1695 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1698 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1699 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1700 wpa_supplicant_deauthenticate(
1701 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1705 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1706 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1707 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1708 MACSTR, MAC2STR(bssid));
1709 random_add_randomness(bssid, ETH_ALEN);
1710 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1711 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1712 wpas_notify_bssid_changed(wpa_s);
1714 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1715 wpa_clear_keys(wpa_s, bssid);
1717 if (wpa_supplicant_select_config(wpa_s) < 0) {
1718 wpa_supplicant_deauthenticate(
1719 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1722 if (wpa_s->current_ssid) {
1723 struct wpa_bss *bss = NULL;
1725 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1727 wpa_supplicant_update_scan_results(wpa_s);
1729 /* Get the BSS from the new scan results */
1730 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1734 wpa_s->current_bss = bss;
1738 if (wpa_s->conf->ap_scan == 1) {
1740 if (wpa_s->conf->ap_scan == 1 &&
1741 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1743 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1744 wpa_msg(wpa_s, MSG_WARNING,
1745 "WPA/RSN IEs not updated");
1750 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1751 wpa_s->sme.prev_bssid_set = 1;
1752 #endif /* CONFIG_SME */
1754 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1755 if (wpa_s->current_ssid) {
1756 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1757 * initialized before association, but for other modes,
1758 * initialize PC/SC here, if the current configuration needs
1759 * smartcard or SIM/USIM. */
1760 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1762 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1764 l2_packet_notify_auth_start(wpa_s->l2);
1767 * Set portEnabled first to FALSE in order to get EAP state machine out
1768 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1769 * state machine may transit to AUTHENTICATING state based on obsolete
1770 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1771 * AUTHENTICATED without ever giving chance to EAP state machine to
1774 if (!ft_completed) {
1775 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1776 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1778 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1779 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1780 /* 802.1X::portControl = Auto */
1781 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1782 wpa_s->eapol_received = 0;
1783 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1784 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1785 (wpa_s->current_ssid &&
1786 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1787 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1789 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1791 * Set the key after having received joined-IBSS event
1794 wpa_supplicant_set_wpa_none_key(wpa_s,
1795 wpa_s->current_ssid);
1797 wpa_supplicant_cancel_auth_timeout(wpa_s);
1798 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1799 } else if (!ft_completed) {
1800 /* Timeout for receiving the first EAPOL packet */
1801 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1803 wpa_supplicant_cancel_scan(wpa_s);
1805 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1806 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1808 * We are done; the driver will take care of RSN 4-way
1811 wpa_supplicant_cancel_auth_timeout(wpa_s);
1812 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1813 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1814 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1815 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1816 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1818 * The driver will take care of RSN 4-way handshake, so we need
1819 * to allow EAPOL supplicant to complete its work without
1820 * waiting for WPA supplicant.
1822 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1823 } else if (ft_completed) {
1825 * FT protocol completed - make sure EAPOL state machine ends
1826 * up in authenticated.
1828 wpa_supplicant_cancel_auth_timeout(wpa_s);
1829 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1830 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1831 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1834 wpa_s->last_eapol_matches_bssid = 0;
1836 if (wpa_s->pending_eapol_rx) {
1837 struct os_time now, age;
1839 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1840 if (age.sec == 0 && age.usec < 100000 &&
1841 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1843 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1844 "frame that was received just before "
1845 "association notification");
1846 wpa_supplicant_rx_eapol(
1847 wpa_s, wpa_s->pending_eapol_rx_src,
1848 wpabuf_head(wpa_s->pending_eapol_rx),
1849 wpabuf_len(wpa_s->pending_eapol_rx));
1851 wpabuf_free(wpa_s->pending_eapol_rx);
1852 wpa_s->pending_eapol_rx = NULL;
1855 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1856 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1857 wpa_s->current_ssid &&
1858 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1859 /* Set static WEP keys again */
1860 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1863 #ifdef CONFIG_IBSS_RSN
1864 if (wpa_s->current_ssid &&
1865 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1866 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1867 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1868 wpa_s->ibss_rsn == NULL) {
1869 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1870 if (!wpa_s->ibss_rsn) {
1871 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1872 wpa_supplicant_deauthenticate(
1873 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1877 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1879 #endif /* CONFIG_IBSS_RSN */
1881 wpas_wps_notify_assoc(wpa_s, bssid);
1885 static int disconnect_reason_recoverable(u16 reason_code)
1887 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1888 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1889 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1893 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1895 int locally_generated)
1899 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1901 * At least Host AP driver and a Prism3 card seemed to be
1902 * generating streams of disconnected events when configuring
1903 * IBSS for WPA-None. Ignore them for now.
1908 bssid = wpa_s->bssid;
1909 if (is_zero_ether_addr(bssid))
1910 bssid = wpa_s->pending_bssid;
1912 if (!is_zero_ether_addr(bssid) ||
1913 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1914 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1916 MAC2STR(bssid), reason_code,
1917 locally_generated ? " locally_generated=1" : "");
1922 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1923 int locally_generated)
1925 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1926 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1927 return 0; /* Not in 4-way handshake with PSK */
1930 * It looks like connection was lost while trying to go through PSK
1931 * 4-way handshake. Filter out known disconnection cases that are caused
1932 * by something else than PSK mismatch to avoid confusing reports.
1935 if (locally_generated) {
1936 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1944 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1946 int locally_generated)
1950 u8 prev_pending_bssid[ETH_ALEN];
1951 struct wpa_bss *fast_reconnect = NULL;
1952 struct wpa_ssid *fast_reconnect_ssid = NULL;
1953 struct wpa_ssid *last_ssid;
1955 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1956 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1958 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1960 * At least Host AP driver and a Prism3 card seemed to be
1961 * generating streams of disconnected events when configuring
1962 * IBSS for WPA-None. Ignore them for now.
1964 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1965 "IBSS/WPA-None mode");
1969 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1970 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1971 "pre-shared key may be incorrect");
1972 wpas_auth_failed(wpa_s);
1974 if (!wpa_s->disconnected &&
1975 (!wpa_s->auto_reconnect_disabled ||
1976 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
1977 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1978 "reconnect (wps=%d wpa_state=%d)",
1979 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1981 if (wpa_s->wpa_state == WPA_COMPLETED &&
1982 wpa_s->current_ssid &&
1983 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1984 !locally_generated &&
1985 disconnect_reason_recoverable(reason_code)) {
1987 * It looks like the AP has dropped association with
1988 * us, but could allow us to get back in. Try to
1989 * reconnect to the same BSS without full scan to save
1990 * time for some common cases.
1992 fast_reconnect = wpa_s->current_bss;
1993 fast_reconnect_ssid = wpa_s->current_ssid;
1994 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1996 wpa_supplicant_req_scan(wpa_s, 0, 500000);
1998 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2004 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2005 "try to re-connect");
2006 wpa_s->reassociate = 0;
2007 wpa_s->disconnected = 1;
2008 wpa_supplicant_cancel_sched_scan(wpa_s);
2010 bssid = wpa_s->bssid;
2011 if (is_zero_ether_addr(bssid))
2012 bssid = wpa_s->pending_bssid;
2013 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2014 wpas_connection_failed(wpa_s, bssid);
2015 wpa_sm_notify_disassoc(wpa_s->wpa);
2016 if (locally_generated)
2017 wpa_s->disconnect_reason = -reason_code;
2019 wpa_s->disconnect_reason = reason_code;
2020 wpas_notify_disconnect_reason(wpa_s);
2021 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2022 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2023 wpa_s->keys_cleared = 0;
2024 wpa_clear_keys(wpa_s, wpa_s->bssid);
2026 last_ssid = wpa_s->current_ssid;
2027 wpa_supplicant_mark_disassoc(wpa_s);
2029 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2030 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2031 wpa_s->current_ssid = last_ssid;
2034 if (fast_reconnect) {
2035 #ifndef CONFIG_NO_SCAN_PROCESSING
2036 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2037 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2038 fast_reconnect_ssid) < 0) {
2039 /* Recover through full scan */
2040 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2042 #endif /* CONFIG_NO_SCAN_PROCESSING */
2047 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2048 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2050 struct wpa_supplicant *wpa_s = eloop_ctx;
2052 if (!wpa_s->pending_mic_error_report)
2055 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2056 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2057 wpa_s->pending_mic_error_report = 0;
2059 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2063 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2064 union wpa_event_data *data)
2069 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2070 pairwise = (data && data->michael_mic_failure.unicast);
2072 if ((wpa_s->last_michael_mic_error &&
2073 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2074 wpa_s->pending_mic_error_report) {
2075 if (wpa_s->pending_mic_error_report) {
2077 * Send the pending MIC error report immediately since
2078 * we are going to start countermeasures and AP better
2081 wpa_sm_key_request(wpa_s->wpa, 1,
2082 wpa_s->pending_mic_error_pairwise);
2085 /* Send the new MIC error report immediately since we are going
2086 * to start countermeasures and AP better do the same.
2088 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2090 /* initialize countermeasures */
2091 wpa_s->countermeasures = 1;
2093 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2095 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2098 * Need to wait for completion of request frame. We do not get
2099 * any callback for the message completion, so just wait a
2100 * short while and hope for the best. */
2103 wpa_drv_set_countermeasures(wpa_s, 1);
2104 wpa_supplicant_deauthenticate(wpa_s,
2105 WLAN_REASON_MICHAEL_MIC_FAILURE);
2106 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2108 eloop_register_timeout(60, 0,
2109 wpa_supplicant_stop_countermeasures,
2111 /* TODO: mark the AP rejected for 60 second. STA is
2112 * allowed to associate with another AP.. */
2114 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2115 if (wpa_s->mic_errors_seen) {
2117 * Reduce the effectiveness of Michael MIC error
2118 * reports as a means for attacking against TKIP if
2119 * more than one MIC failure is noticed with the same
2120 * PTK. We delay the transmission of the reports by a
2121 * random time between 0 and 60 seconds in order to
2122 * force the attacker wait 60 seconds before getting
2123 * the information on whether a frame resulted in a MIC
2129 if (os_get_random(rval, sizeof(rval)) < 0)
2130 sec = os_random() % 60;
2132 sec = WPA_GET_BE32(rval) % 60;
2133 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2134 "report %d seconds", sec);
2135 wpa_s->pending_mic_error_report = 1;
2136 wpa_s->pending_mic_error_pairwise = pairwise;
2137 eloop_cancel_timeout(
2138 wpa_supplicant_delayed_mic_error_report,
2140 eloop_register_timeout(
2141 sec, os_random() % 1000000,
2142 wpa_supplicant_delayed_mic_error_report,
2145 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2147 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2148 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2149 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2151 wpa_s->last_michael_mic_error = t.sec;
2152 wpa_s->mic_errors_seen++;
2156 #ifdef CONFIG_TERMINATE_ONLASTIF
2157 static int any_interfaces(struct wpa_supplicant *head)
2159 struct wpa_supplicant *wpa_s;
2161 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2162 if (!wpa_s->interface_removed)
2166 #endif /* CONFIG_TERMINATE_ONLASTIF */
2170 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2171 union wpa_event_data *data)
2173 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2176 switch (data->interface_status.ievent) {
2177 case EVENT_INTERFACE_ADDED:
2178 if (!wpa_s->interface_removed)
2180 wpa_s->interface_removed = 0;
2181 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2182 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2183 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2184 "driver after interface was added");
2186 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2188 case EVENT_INTERFACE_REMOVED:
2189 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2190 wpa_s->interface_removed = 1;
2191 wpa_supplicant_mark_disassoc(wpa_s);
2192 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2193 l2_packet_deinit(wpa_s->l2);
2195 #ifdef CONFIG_IBSS_RSN
2196 ibss_rsn_deinit(wpa_s->ibss_rsn);
2197 wpa_s->ibss_rsn = NULL;
2198 #endif /* CONFIG_IBSS_RSN */
2199 #ifdef CONFIG_TERMINATE_ONLASTIF
2200 /* check if last interface */
2201 if (!any_interfaces(wpa_s->global->ifaces))
2203 #endif /* CONFIG_TERMINATE_ONLASTIF */
2209 #ifdef CONFIG_PEERKEY
2211 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2212 union wpa_event_data *data)
2216 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2218 #endif /* CONFIG_PEERKEY */
2222 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2223 union wpa_event_data *data)
2227 switch (data->tdls.oper) {
2228 case TDLS_REQUEST_SETUP:
2229 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2230 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2231 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2233 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2235 case TDLS_REQUEST_TEARDOWN:
2236 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2237 data->tdls.reason_code);
2241 #endif /* CONFIG_TDLS */
2245 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2246 union wpa_event_data *data)
2250 switch (data->wnm.oper) {
2251 case WNM_OPER_SLEEP:
2252 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2253 "(action=%d, intval=%d)",
2254 data->wnm.sleep_action, data->wnm.sleep_intval);
2255 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2256 data->wnm.sleep_intval, NULL);
2260 #endif /* CONFIG_WNM */
2263 #ifdef CONFIG_IEEE80211R
2265 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2266 union wpa_event_data *data)
2271 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2272 data->ft_ies.ies_len,
2273 data->ft_ies.ft_action,
2274 data->ft_ies.target_ap,
2275 data->ft_ies.ric_ies,
2276 data->ft_ies.ric_ies_len) < 0) {
2277 /* TODO: prevent MLME/driver from trying to associate? */
2280 #endif /* CONFIG_IEEE80211R */
2283 #ifdef CONFIG_IBSS_RSN
2284 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2285 union wpa_event_data *data)
2287 struct wpa_ssid *ssid;
2288 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2292 ssid = wpa_s->current_ssid;
2295 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2298 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2300 #endif /* CONFIG_IBSS_RSN */
2303 #ifdef CONFIG_IEEE80211R
2304 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2307 const u8 *sta_addr, *target_ap_addr;
2310 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2311 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2312 return; /* only SME case supported for now */
2313 if (len < 1 + 2 * ETH_ALEN + 2)
2316 return; /* Only FT Action Response is supported for now */
2317 sta_addr = data + 1;
2318 target_ap_addr = data + 1 + ETH_ALEN;
2319 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2320 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2321 MACSTR " TargetAP " MACSTR " status %u",
2322 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2324 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2325 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2326 " in FT Action Response", MAC2STR(sta_addr));
2331 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2332 "failure (status code %d)", status);
2333 /* TODO: report error to FT code(?) */
2337 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2338 len - (1 + 2 * ETH_ALEN + 2), 1,
2339 target_ap_addr, NULL, 0) < 0)
2344 struct wpa_bss *bss;
2345 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2347 wpa_s->sme.freq = bss->freq;
2348 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2349 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2352 #endif /* CONFIG_SME */
2354 #endif /* CONFIG_IEEE80211R */
2357 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2358 struct unprot_deauth *e)
2360 #ifdef CONFIG_IEEE80211W
2361 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2362 "dropped: " MACSTR " -> " MACSTR
2363 " (reason code %u)",
2364 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2365 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2366 #endif /* CONFIG_IEEE80211W */
2370 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2371 struct unprot_disassoc *e)
2373 #ifdef CONFIG_IEEE80211W
2374 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2375 "dropped: " MACSTR " -> " MACSTR
2376 " (reason code %u)",
2377 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2378 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2379 #endif /* CONFIG_IEEE80211W */
2383 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2384 union wpa_event_data *data)
2386 struct wpa_supplicant *wpa_s = ctx;
2387 u16 reason_code = 0;
2388 int locally_generated = 0;
2390 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2391 event != EVENT_INTERFACE_ENABLED &&
2392 event != EVENT_INTERFACE_STATUS &&
2393 event != EVENT_SCHED_SCAN_STOPPED) {
2394 wpa_dbg(wpa_s, MSG_DEBUG,
2395 "Ignore event %s (%d) while interface is disabled",
2396 event_to_string(event), event);
2400 #ifndef CONFIG_NO_STDOUT_DEBUG
2402 int level = MSG_DEBUG;
2404 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2405 const struct ieee80211_hdr *hdr;
2407 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2408 fc = le_to_host16(hdr->frame_control);
2409 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2410 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2411 level = MSG_EXCESSIVE;
2414 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2415 event_to_string(event), event);
2417 #endif /* CONFIG_NO_STDOUT_DEBUG */
2421 sme_event_auth(wpa_s, data);
2424 wpa_supplicant_event_assoc(wpa_s, data);
2426 case EVENT_DISASSOC:
2427 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2429 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2430 data->disassoc_info.reason_code,
2431 data->disassoc_info.locally_generated ?
2432 " (locally generated)" : "");
2433 if (data->disassoc_info.addr)
2434 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2435 MAC2STR(data->disassoc_info.addr));
2438 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2439 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2440 data->disassoc_info.addr);
2443 if (wpa_s->ap_iface) {
2444 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2448 #endif /* CONFIG_AP */
2450 reason_code = data->disassoc_info.reason_code;
2452 data->disassoc_info.locally_generated;
2453 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2454 data->disassoc_info.ie,
2455 data->disassoc_info.ie_len);
2457 wpas_p2p_disassoc_notif(
2458 wpa_s, data->disassoc_info.addr, reason_code,
2459 data->disassoc_info.ie,
2460 data->disassoc_info.ie_len,
2462 #endif /* CONFIG_P2P */
2464 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2465 sme_event_disassoc(wpa_s, data);
2468 if (event == EVENT_DEAUTH) {
2469 wpa_dbg(wpa_s, MSG_DEBUG,
2470 "Deauthentication notification");
2472 reason_code = data->deauth_info.reason_code;
2474 data->deauth_info.locally_generated;
2475 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2476 data->deauth_info.reason_code,
2477 data->deauth_info.locally_generated ?
2478 " (locally generated)" : "");
2479 if (data->deauth_info.addr) {
2480 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2482 MAC2STR(data->deauth_info.
2485 wpa_hexdump(MSG_DEBUG,
2486 "Deauthentication frame IE(s)",
2487 data->deauth_info.ie,
2488 data->deauth_info.ie_len);
2490 wpa_reset_ft_completed(wpa_s->wpa);
2493 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2494 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2495 data->deauth_info.addr);
2498 if (wpa_s->ap_iface) {
2499 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2503 #endif /* CONFIG_AP */
2504 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2506 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2507 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2508 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2509 eapol_sm_failed(wpa_s->eapol)))
2510 wpas_auth_failed(wpa_s);
2512 if (event == EVENT_DEAUTH && data) {
2513 if (wpas_p2p_deauth_notif(wpa_s,
2514 data->deauth_info.addr,
2516 data->deauth_info.ie,
2517 data->deauth_info.ie_len,
2518 locally_generated) > 0) {
2520 * The interface was removed, so cannot
2521 * continue processing any additional
2522 * operations after this.
2527 #endif /* CONFIG_P2P */
2528 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2531 case EVENT_MICHAEL_MIC_FAILURE:
2532 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2534 #ifndef CONFIG_NO_SCAN_PROCESSING
2535 case EVENT_SCAN_RESULTS:
2536 wpa_supplicant_event_scan_results(wpa_s, data);
2537 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2538 wpa_s->wpa_state != WPA_ASSOCIATING)
2539 wpas_p2p_continue_after_scan(wpa_s);
2541 #endif /* CONFIG_NO_SCAN_PROCESSING */
2542 case EVENT_ASSOCINFO:
2543 wpa_supplicant_event_associnfo(wpa_s, data);
2545 case EVENT_INTERFACE_STATUS:
2546 wpa_supplicant_event_interface_status(wpa_s, data);
2548 case EVENT_PMKID_CANDIDATE:
2549 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2551 #ifdef CONFIG_PEERKEY
2552 case EVENT_STKSTART:
2553 wpa_supplicant_event_stkstart(wpa_s, data);
2555 #endif /* CONFIG_PEERKEY */
2558 wpa_supplicant_event_tdls(wpa_s, data);
2560 #endif /* CONFIG_TDLS */
2563 wpa_supplicant_event_wnm(wpa_s, data);
2565 #endif /* CONFIG_WNM */
2566 #ifdef CONFIG_IEEE80211R
2567 case EVENT_FT_RESPONSE:
2568 wpa_supplicant_event_ft_response(wpa_s, data);
2570 #endif /* CONFIG_IEEE80211R */
2571 #ifdef CONFIG_IBSS_RSN
2572 case EVENT_IBSS_RSN_START:
2573 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2575 #endif /* CONFIG_IBSS_RSN */
2576 case EVENT_ASSOC_REJECT:
2577 if (data->assoc_reject.bssid)
2578 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2579 "bssid=" MACSTR " status_code=%u",
2580 MAC2STR(data->assoc_reject.bssid),
2581 data->assoc_reject.status_code);
2583 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2585 data->assoc_reject.status_code);
2586 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2587 sme_event_assoc_reject(wpa_s, data);
2590 if(!wpa_s->current_ssid) {
2591 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2594 /* If assoc reject is reported by the driver, then avoid
2595 * waiting for the authentication timeout. Cancel the
2596 * authentication timeout and retry the assoc.
2598 if(wpa_s->current_ssid->assoc_retry++ < 10) {
2599 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2600 wpa_s->current_ssid->assoc_retry);
2602 wpa_supplicant_cancel_auth_timeout(wpa_s);
2604 /* Clear the states */
2605 wpa_sm_notify_disassoc(wpa_s->wpa);
2606 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2608 wpa_s->reassociate = 1;
2609 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
2610 const u8 *bl_bssid = data->assoc_reject.bssid;
2611 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2612 bl_bssid = wpa_s->pending_bssid;
2613 wpa_blacklist_add(wpa_s, bl_bssid);
2614 wpa_supplicant_req_scan(wpa_s, 0, 0);
2616 wpa_supplicant_req_scan(wpa_s, 1, 0);
2618 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
2619 /* If we ASSOC_REJECT's hits threshold, disable the
2622 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2623 "Disabling the network");
2624 wpa_s->current_ssid->assoc_retry = 0;
2625 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
2626 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
2629 const u8 *bssid = data->assoc_reject.bssid;
2630 if (bssid == NULL || is_zero_ether_addr(bssid))
2631 bssid = wpa_s->pending_bssid;
2632 wpas_connection_failed(wpa_s, bssid);
2633 wpa_supplicant_mark_disassoc(wpa_s);
2634 #endif /* ANDROID_P2P */
2637 case EVENT_AUTH_TIMED_OUT:
2638 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2639 sme_event_auth_timed_out(wpa_s, data);
2641 case EVENT_ASSOC_TIMED_OUT:
2642 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2643 sme_event_assoc_timed_out(wpa_s, data);
2645 case EVENT_TX_STATUS:
2646 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2647 " type=%d stype=%d",
2648 MAC2STR(data->tx_status.dst),
2649 data->tx_status.type, data->tx_status.stype);
2651 if (wpa_s->ap_iface == NULL) {
2652 #ifdef CONFIG_OFFCHANNEL
2653 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2654 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2655 offchannel_send_action_tx_status(
2656 wpa_s, data->tx_status.dst,
2657 data->tx_status.data,
2658 data->tx_status.data_len,
2659 data->tx_status.ack ?
2660 OFFCHANNEL_SEND_ACTION_SUCCESS :
2661 OFFCHANNEL_SEND_ACTION_NO_ACK);
2662 #endif /* CONFIG_OFFCHANNEL */
2665 #endif /* CONFIG_AP */
2666 #ifdef CONFIG_OFFCHANNEL
2667 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2668 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2670 * Catch TX status events for Action frames we sent via group
2671 * interface in GO mode.
2673 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2674 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2675 os_memcmp(wpa_s->parent->pending_action_dst,
2676 data->tx_status.dst, ETH_ALEN) == 0) {
2677 offchannel_send_action_tx_status(
2678 wpa_s->parent, data->tx_status.dst,
2679 data->tx_status.data,
2680 data->tx_status.data_len,
2681 data->tx_status.ack ?
2682 OFFCHANNEL_SEND_ACTION_SUCCESS :
2683 OFFCHANNEL_SEND_ACTION_NO_ACK);
2686 #endif /* CONFIG_OFFCHANNEL */
2688 switch (data->tx_status.type) {
2689 case WLAN_FC_TYPE_MGMT:
2690 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2691 data->tx_status.data_len,
2692 data->tx_status.stype,
2693 data->tx_status.ack);
2695 case WLAN_FC_TYPE_DATA:
2696 ap_tx_status(wpa_s, data->tx_status.dst,
2697 data->tx_status.data,
2698 data->tx_status.data_len,
2699 data->tx_status.ack);
2702 #endif /* CONFIG_AP */
2705 case EVENT_EAPOL_TX_STATUS:
2706 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2707 data->eapol_tx_status.data,
2708 data->eapol_tx_status.data_len,
2709 data->eapol_tx_status.ack);
2711 case EVENT_DRIVER_CLIENT_POLL_OK:
2712 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2714 case EVENT_RX_FROM_UNKNOWN:
2715 if (wpa_s->ap_iface == NULL)
2717 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2718 data->rx_from_unknown.wds);
2720 case EVENT_CH_SWITCH:
2723 if (!wpa_s->ap_iface) {
2724 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2725 "event in non-AP mode");
2730 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2731 data->ch_switch.ht_enabled,
2732 data->ch_switch.ch_offset);
2733 #endif /* CONFIG_AP */
2735 case EVENT_RX_MGMT: {
2737 const struct ieee80211_mgmt *mgmt;
2739 mgmt = (const struct ieee80211_mgmt *)
2740 data->rx_mgmt.frame;
2741 fc = le_to_host16(mgmt->frame_control);
2742 stype = WLAN_FC_GET_STYPE(fc);
2744 if (wpa_s->ap_iface == NULL) {
2746 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2747 data->rx_mgmt.frame_len > 24) {
2748 const u8 *src = mgmt->sa;
2749 const u8 *ie = mgmt->u.probe_req.variable;
2750 size_t ie_len = data->rx_mgmt.frame_len -
2751 (mgmt->u.probe_req.variable -
2752 data->rx_mgmt.frame);
2753 wpas_p2p_probe_req_rx(
2754 wpa_s, src, mgmt->da,
2755 mgmt->bssid, ie, ie_len,
2756 data->rx_mgmt.ssi_signal);
2759 #endif /* CONFIG_P2P */
2760 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2761 "management frame in non-AP mode");
2765 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2766 data->rx_mgmt.frame_len > 24) {
2767 const u8 *ie = mgmt->u.probe_req.variable;
2768 size_t ie_len = data->rx_mgmt.frame_len -
2769 (mgmt->u.probe_req.variable -
2770 data->rx_mgmt.frame);
2772 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2773 mgmt->bssid, ie, ie_len,
2774 data->rx_mgmt.ssi_signal);
2777 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2780 #endif /* CONFIG_AP */
2781 case EVENT_RX_ACTION:
2782 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2783 " Category=%u DataLen=%d freq=%d MHz",
2784 MAC2STR(data->rx_action.sa),
2785 data->rx_action.category, (int) data->rx_action.len,
2786 data->rx_action.freq);
2787 #ifdef CONFIG_IEEE80211R
2788 if (data->rx_action.category == WLAN_ACTION_FT) {
2789 ft_rx_action(wpa_s, data->rx_action.data,
2790 data->rx_action.len);
2793 #endif /* CONFIG_IEEE80211R */
2794 #ifdef CONFIG_IEEE80211W
2796 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2797 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2798 data->rx_action.data,
2799 data->rx_action.len);
2802 #endif /* CONFIG_SME */
2803 #endif /* CONFIG_IEEE80211W */
2805 if (data->rx_action.category == WLAN_ACTION_WNM) {
2806 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2809 #endif /* CONFIG_WNM */
2811 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2812 gas_query_rx(wpa_s->gas, data->rx_action.da,
2813 data->rx_action.sa, data->rx_action.bssid,
2814 data->rx_action.data, data->rx_action.len,
2815 data->rx_action.freq) == 0)
2817 #endif /* CONFIG_GAS */
2819 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2820 data->rx_action.len >= 4 &&
2821 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2822 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2823 "Response from " MACSTR,
2824 MAC2STR(data->rx_action.sa));
2827 #endif /* CONFIG_TDLS */
2829 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2831 data->rx_action.bssid,
2832 data->rx_action.category,
2833 data->rx_action.data,
2834 data->rx_action.len, data->rx_action.freq);
2835 #endif /* CONFIG_P2P */
2837 case EVENT_RX_PROBE_REQ:
2838 if (data->rx_probe_req.sa == NULL ||
2839 data->rx_probe_req.ie == NULL)
2842 if (wpa_s->ap_iface) {
2843 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2844 data->rx_probe_req.sa,
2845 data->rx_probe_req.da,
2846 data->rx_probe_req.bssid,
2847 data->rx_probe_req.ie,
2848 data->rx_probe_req.ie_len,
2849 data->rx_probe_req.ssi_signal);
2852 #endif /* CONFIG_AP */
2854 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2855 data->rx_probe_req.da,
2856 data->rx_probe_req.bssid,
2857 data->rx_probe_req.ie,
2858 data->rx_probe_req.ie_len,
2859 data->rx_probe_req.ssi_signal);
2860 #endif /* CONFIG_P2P */
2862 case EVENT_REMAIN_ON_CHANNEL:
2863 #ifdef CONFIG_OFFCHANNEL
2864 offchannel_remain_on_channel_cb(
2865 wpa_s, data->remain_on_channel.freq,
2866 data->remain_on_channel.duration);
2867 #endif /* CONFIG_OFFCHANNEL */
2869 wpas_p2p_remain_on_channel_cb(
2870 wpa_s, data->remain_on_channel.freq,
2871 data->remain_on_channel.duration);
2872 #endif /* CONFIG_P2P */
2874 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2875 #ifdef CONFIG_OFFCHANNEL
2876 offchannel_cancel_remain_on_channel_cb(
2877 wpa_s, data->remain_on_channel.freq);
2878 #endif /* CONFIG_OFFCHANNEL */
2880 wpas_p2p_cancel_remain_on_channel_cb(
2881 wpa_s, data->remain_on_channel.freq);
2882 #endif /* CONFIG_P2P */
2885 case EVENT_P2P_DEV_FOUND: {
2886 struct p2p_peer_info peer_info;
2888 os_memset(&peer_info, 0, sizeof(peer_info));
2889 if (data->p2p_dev_found.dev_addr)
2890 os_memcpy(peer_info.p2p_device_addr,
2891 data->p2p_dev_found.dev_addr, ETH_ALEN);
2892 if (data->p2p_dev_found.pri_dev_type)
2893 os_memcpy(peer_info.pri_dev_type,
2894 data->p2p_dev_found.pri_dev_type,
2895 sizeof(peer_info.pri_dev_type));
2896 if (data->p2p_dev_found.dev_name)
2897 os_strlcpy(peer_info.device_name,
2898 data->p2p_dev_found.dev_name,
2899 sizeof(peer_info.device_name));
2900 peer_info.config_methods = data->p2p_dev_found.config_methods;
2901 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2902 peer_info.group_capab = data->p2p_dev_found.group_capab;
2905 * FIX: new_device=1 is not necessarily correct. We should
2906 * maintain a P2P peer database in wpa_supplicant and update
2907 * this information based on whether the peer is truly new.
2909 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2912 case EVENT_P2P_GO_NEG_REQ_RX:
2913 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2914 data->p2p_go_neg_req_rx.dev_passwd_id);
2916 case EVENT_P2P_GO_NEG_COMPLETED:
2917 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2919 case EVENT_P2P_PROV_DISC_REQUEST:
2920 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2921 data->p2p_prov_disc_req.config_methods,
2922 data->p2p_prov_disc_req.dev_addr,
2923 data->p2p_prov_disc_req.pri_dev_type,
2924 data->p2p_prov_disc_req.dev_name,
2925 data->p2p_prov_disc_req.supp_config_methods,
2926 data->p2p_prov_disc_req.dev_capab,
2927 data->p2p_prov_disc_req.group_capab,
2930 case EVENT_P2P_PROV_DISC_RESPONSE:
2931 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2932 data->p2p_prov_disc_resp.config_methods);
2934 case EVENT_P2P_SD_REQUEST:
2935 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2936 data->p2p_sd_req.sa,
2937 data->p2p_sd_req.dialog_token,
2938 data->p2p_sd_req.update_indic,
2939 data->p2p_sd_req.tlvs,
2940 data->p2p_sd_req.tlvs_len);
2942 case EVENT_P2P_SD_RESPONSE:
2943 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2944 data->p2p_sd_resp.update_indic,
2945 data->p2p_sd_resp.tlvs,
2946 data->p2p_sd_resp.tlvs_len);
2948 #endif /* CONFIG_P2P */
2949 case EVENT_EAPOL_RX:
2950 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2951 data->eapol_rx.data,
2952 data->eapol_rx.data_len);
2954 case EVENT_SIGNAL_CHANGE:
2955 bgscan_notify_signal_change(
2956 wpa_s, data->signal_change.above_threshold,
2957 data->signal_change.current_signal,
2958 data->signal_change.current_noise,
2959 data->signal_change.current_txrate);
2961 case EVENT_INTERFACE_ENABLED:
2962 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2963 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2964 wpa_supplicant_update_mac_addr(wpa_s);
2966 if (!wpa_s->ap_iface) {
2967 wpa_supplicant_set_state(wpa_s,
2969 wpa_supplicant_req_scan(wpa_s, 0, 0);
2971 wpa_supplicant_set_state(wpa_s,
2973 #else /* CONFIG_AP */
2974 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2975 wpa_supplicant_req_scan(wpa_s, 0, 0);
2976 #endif /* CONFIG_AP */
2979 case EVENT_INTERFACE_DISABLED:
2980 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2981 wpa_supplicant_mark_disassoc(wpa_s);
2982 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2984 case EVENT_CHANNEL_LIST_CHANGED:
2985 if (wpa_s->drv_priv == NULL)
2986 break; /* Ignore event during drv initialization */
2988 free_hw_features(wpa_s);
2989 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2990 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2993 wpas_p2p_update_channel_list(wpa_s);
2994 #endif /* CONFIG_P2P */
2996 case EVENT_INTERFACE_UNAVAILABLE:
2998 wpas_p2p_interface_unavailable(wpa_s);
2999 #endif /* CONFIG_P2P */
3001 case EVENT_BEST_CHANNEL:
3002 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3004 data->best_chan.freq_24, data->best_chan.freq_5,
3005 data->best_chan.freq_overall);
3006 wpa_s->best_24_freq = data->best_chan.freq_24;
3007 wpa_s->best_5_freq = data->best_chan.freq_5;
3008 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3010 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3011 data->best_chan.freq_5,
3012 data->best_chan.freq_overall);
3013 #endif /* CONFIG_P2P */
3015 case EVENT_UNPROT_DEAUTH:
3016 wpa_supplicant_event_unprot_deauth(wpa_s,
3017 &data->unprot_deauth);
3019 case EVENT_UNPROT_DISASSOC:
3020 wpa_supplicant_event_unprot_disassoc(wpa_s,
3021 &data->unprot_disassoc);
3023 case EVENT_STATION_LOW_ACK:
3025 if (wpa_s->ap_iface && data)
3026 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3027 data->low_ack.addr);
3028 #endif /* CONFIG_AP */
3031 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3032 #endif /* CONFIG_TDLS */
3034 case EVENT_IBSS_PEER_LOST:
3035 #ifdef CONFIG_IBSS_RSN
3036 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3037 #endif /* CONFIG_IBSS_RSN */
3039 case EVENT_DRIVER_GTK_REKEY:
3040 if (os_memcmp(data->driver_gtk_rekey.bssid,
3041 wpa_s->bssid, ETH_ALEN))
3045 wpa_sm_update_replay_ctr(wpa_s->wpa,
3046 data->driver_gtk_rekey.replay_ctr);
3048 case EVENT_SCHED_SCAN_STOPPED:
3049 wpa_s->sched_scanning = 0;
3050 wpa_supplicant_notify_scanning(wpa_s, 0);
3052 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3056 * If we timed out, start a new sched scan to continue
3057 * searching for more SSIDs.
3059 if (wpa_s->sched_scan_timed_out)
3060 wpa_supplicant_req_sched_scan(wpa_s);
3062 case EVENT_WPS_BUTTON_PUSHED:
3064 wpas_wps_start_pbc(wpa_s, NULL, 0);
3065 #endif /* CONFIG_WPS */
3067 case EVENT_CONNECT_FAILED_REASON:
3069 if (!wpa_s->ap_iface || !data)
3071 hostapd_event_connect_failed_reason(
3072 wpa_s->ap_iface->bss[0],
3073 data->connect_failed_reason.addr,
3074 data->connect_failed_reason.code);
3075 #endif /* CONFIG_AP */
3078 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);