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);
50 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
51 struct wpa_ssid *ssid)
55 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 if (ssid->disabled_until.sec > now.sec)
60 return ssid->disabled_until.sec - now.sec;
62 wpas_clear_temp_disabled(wpa_s, ssid, 0);
68 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
70 struct wpa_ssid *ssid, *old_ssid;
73 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
76 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
78 ssid = wpa_supplicant_get_ssid(wpa_s);
80 wpa_msg(wpa_s, MSG_INFO,
81 "No network configuration found for the current AP");
85 if (wpas_network_disabled(wpa_s, ssid)) {
86 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
91 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
92 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 res = wpas_temp_disabled(wpa_s, ssid);
98 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
99 "disabled for %d second(s)", res);
103 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
105 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
107 size_t wpa_ie_len = sizeof(wpa_ie);
108 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
109 wpa_ie, &wpa_ie_len) < 0)
110 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
112 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
115 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
116 eapol_sm_invalidate_cached_session(wpa_s->eapol);
117 old_ssid = wpa_s->current_ssid;
118 wpa_s->current_ssid = ssid;
119 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
120 wpa_supplicant_initiate_eapol(wpa_s);
121 if (old_ssid != wpa_s->current_ssid)
122 wpas_notify_network_changed(wpa_s);
128 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
130 struct wpa_supplicant *wpa_s = eloop_ctx;
132 if (wpa_s->countermeasures) {
133 wpa_s->countermeasures = 0;
134 wpa_drv_set_countermeasures(wpa_s, 0);
135 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
136 wpa_supplicant_req_scan(wpa_s, 0, 0);
141 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145 wnm_bss_keep_alive_deinit(wpa_s);
147 #ifdef CONFIG_IBSS_RSN
148 ibss_rsn_deinit(wpa_s->ibss_rsn);
149 wpa_s->ibss_rsn = NULL;
150 #endif /* CONFIG_IBSS_RSN */
153 wpa_supplicant_ap_deinit(wpa_s);
154 #endif /* CONFIG_AP */
156 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
159 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
161 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
167 wpa_s->sme.prev_bssid_set = 0;
168 #endif /* CONFIG_SME */
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171 #endif /* CONFIG_P2P */
172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
174 #ifdef CONFIG_IEEE80211R
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178 #endif /* CONFIG_SME */
179 #endif /* CONFIG_IEEE80211R */
182 wpas_notify_bssid_changed(wpa_s);
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
189 wpa_s->current_ssid = NULL;
194 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
196 struct wpa_ie_data ie;
200 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
204 for (i = 0; i < ie.num_pmkid; i++) {
205 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
206 ie.pmkid + i * PMKID_LEN,
208 if (pmksa_set == 0) {
209 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
214 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
215 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
219 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
220 union wpa_event_data *data)
223 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
228 " index=%d preauth=%d",
229 MAC2STR(data->pmkid_candidate.bssid),
230 data->pmkid_candidate.index,
231 data->pmkid_candidate.preauth);
233 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
234 data->pmkid_candidate.index,
235 data->pmkid_candidate.preauth);
239 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
241 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
242 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
245 #ifdef IEEE8021X_EAPOL
246 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
247 wpa_s->current_ssid &&
248 !(wpa_s->current_ssid->eapol_flags &
249 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
250 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
251 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
252 * plaintext or static WEP keys). */
255 #endif /* IEEE8021X_EAPOL */
262 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
263 * @wpa_s: pointer to wpa_supplicant data
264 * @ssid: Configuration data for the network
265 * Returns: 0 on success, -1 on failure
267 * This function is called when starting authentication with a network that is
268 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
270 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
271 struct wpa_ssid *ssid)
273 #ifdef IEEE8021X_EAPOL
275 int aka = 0, sim = 0, type;
277 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
280 if (ssid->eap.eap_methods == NULL) {
284 struct eap_method_type *eap = ssid->eap.eap_methods;
285 while (eap->vendor != EAP_VENDOR_IETF ||
286 eap->method != EAP_TYPE_NONE) {
287 if (eap->vendor == EAP_VENDOR_IETF) {
288 if (eap->method == EAP_TYPE_SIM)
290 else if (eap->method == EAP_TYPE_AKA ||
291 eap->method == EAP_TYPE_AKA_PRIME)
298 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
301 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
306 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
307 "use SIM, but neither EAP-SIM nor EAP-AKA are "
312 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
313 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
315 type = SCARD_TRY_BOTH;
317 type = SCARD_USIM_ONLY;
319 type = SCARD_GSM_SIM_ONLY;
321 wpa_s->scard = scard_init(type, NULL);
322 if (wpa_s->scard == NULL) {
323 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
327 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
328 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
329 #endif /* PCSC_FUNCS */
330 #endif /* IEEE8021X_EAPOL */
336 #ifndef CONFIG_NO_SCAN_PROCESSING
337 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
338 struct wpa_ssid *ssid)
342 if (ssid->mixed_cell)
346 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
348 #endif /* CONFIG_WPS */
350 for (i = 0; i < NUM_WEP_KEYS; i++) {
351 if (ssid->wep_key_len[i]) {
356 #ifdef IEEE8021X_EAPOL
357 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
358 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
359 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
361 #endif /* IEEE8021X_EAPOL */
363 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
366 if (bss->caps & IEEE80211_CAP_PRIVACY)
372 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
373 struct wpa_ssid *ssid,
376 struct wpa_ie_data ie;
378 const u8 *rsn_ie, *wpa_ie;
382 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
386 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
387 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
388 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
389 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
390 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
392 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
393 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
396 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
397 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
403 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
405 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
410 if (!(ie.proto & ssid->proto)) {
411 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
416 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
417 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
422 if (!(ie.group_cipher & ssid->group_cipher)) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
428 if (!(ie.key_mgmt & ssid->key_mgmt)) {
429 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
434 #ifdef CONFIG_IEEE80211W
435 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
436 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
437 wpa_s->conf->pmf : ssid->ieee80211w) ==
438 MGMT_FRAME_PROTECTION_REQUIRED) {
439 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
443 #endif /* CONFIG_IEEE80211W */
445 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
449 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
450 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
453 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
454 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
460 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
462 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
467 if (!(ie.proto & ssid->proto)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
473 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
479 if (!(ie.group_cipher & ssid->group_cipher)) {
480 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
485 if (!(ie.key_mgmt & ssid->key_mgmt)) {
486 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
491 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
495 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
497 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
501 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
502 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
503 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
507 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
508 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
512 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
519 static int freq_allowed(int *freqs, int freq)
526 for (i = 0; freqs[i]; i++)
527 if (freqs[i] == freq)
533 static int ht_supported(const struct hostapd_hw_modes *mode)
535 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
537 * The driver did not indicate whether it supports HT. Assume
538 * it does to avoid connection issues.
544 * IEEE Std 802.11n-2009 20.1.1:
545 * An HT non-AP STA shall support all EQM rates for one spatial stream.
547 return mode->mcs_set[0] == 0xff;
551 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
553 const struct hostapd_hw_modes *mode = NULL, *modes;
554 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
559 return 1; /* Cannot do matching without knowing band */
561 modes = wpa_s->hw.modes;
564 * The driver does not provide any additional information
565 * about the utilized hardware, so allow the connection attempt
571 for (i = 0; i < wpa_s->hw.num_modes; i++) {
572 for (j = 0; j < modes[i].num_channels; j++) {
573 int freq = modes[i].channels[j].freq;
574 if (freq == bss->freq) {
576 mode->mode == HOSTAPD_MODE_IEEE80211G)
577 break; /* do not allow 802.11b replace
588 for (i = 0; i < (int) sizeof(scan_ie); i++) {
589 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
593 for (j = 2; j < rate_ie[1] + 2; j++) {
594 int flagged = !!(rate_ie[j] & 0x80);
595 int r = (rate_ie[j] & 0x7f) * 5;
598 * IEEE Std 802.11n-2009 7.3.2.2:
599 * The new BSS Membership selector value is encoded
600 * like a legacy basic rate, but it is not a rate and
601 * only indicates if the BSS members are required to
602 * support the mandatory features of Clause 20 [HT PHY]
603 * in order to join the BSS.
605 if (flagged && ((rate_ie[j] & 0x7f) ==
606 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
607 if (!ht_supported(mode)) {
608 wpa_dbg(wpa_s, MSG_DEBUG,
609 " hardware does not support "
619 /* check for legacy basic rates */
620 for (k = 0; k < mode->num_rates; k++) {
621 if (mode->rates[k] == r)
624 if (k == mode->num_rates) {
626 * IEEE Std 802.11-2007 7.3.2.2 demands that in
627 * order to join a BSS all required rates
628 * have to be supported by the hardware.
630 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
631 "not support required rate %d.%d Mbps",
642 static int bss_is_dmg(struct wpa_bss *bss)
644 return bss->freq > 45000;
649 * Test whether BSS is in an ESS.
650 * This is done differently in DMG (60 GHz) and non-DMG bands
652 static int bss_is_ess(struct wpa_bss *bss)
654 if (bss_is_dmg(bss)) {
655 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
656 IEEE80211_CAP_DMG_AP;
659 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
664 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
665 int i, struct wpa_bss *bss,
666 struct wpa_ssid *group)
668 u8 wpa_ie_len, rsn_ie_len;
670 struct wpa_blacklist *e;
672 struct wpa_ssid *ssid;
674 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
675 wpa_ie_len = ie ? ie[1] : 0;
677 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
678 rsn_ie_len = ie ? ie[1] : 0;
680 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
681 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
682 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
683 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
684 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
686 e = wpa_blacklist_get(wpa_s, bss->bssid);
689 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
691 * When only a single network is enabled, we can
692 * trigger blacklisting on the first failure. This
693 * should not be done with multiple enabled networks to
694 * avoid getting forced to move into a worse ESS on
695 * single error if there are no other BSSes of the
700 if (e->count > limit) {
701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
702 "(count=%d limit=%d)", e->count, limit);
707 if (bss->ssid_len == 0) {
708 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
712 if (disallowed_bssid(wpa_s, bss->bssid)) {
713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
717 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
718 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
722 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
724 for (ssid = group; ssid; ssid = ssid->pnext) {
725 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
728 if (wpas_network_disabled(wpa_s, ssid)) {
729 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
733 res = wpas_temp_disabled(wpa_s, ssid);
735 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
736 "temporarily for %d second(s)", res);
741 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
742 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
747 if (wpa && ssid->ssid_len == 0 &&
748 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
751 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
752 /* Only allow wildcard SSID match if an AP
753 * advertises active WPS operation that matches
756 if (ssid->ssid_len == 0 &&
757 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
760 #endif /* CONFIG_WPS */
762 if (ssid->bssid_set && ssid->ssid_len == 0 &&
763 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
767 (bss->ssid_len != ssid->ssid_len ||
768 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
773 if (ssid->bssid_set &&
774 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
779 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
783 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
784 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
785 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
791 if (!wpa_supplicant_match_privacy(bss, ssid)) {
792 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
797 if (!bss_is_ess(bss)) {
798 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
802 if (!freq_allowed(ssid->freq_list, bss->freq)) {
803 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
808 if (!rate_match(wpa_s, bss)) {
809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
816 * TODO: skip the AP if its P2P IE has Group Formation
817 * bit set in the P2P Group Capability Bitmap and we
818 * are not in Group Formation with that device.
820 #endif /* CONFIG_P2P */
822 /* Matching configuration found */
826 /* No matching configuration found */
831 static struct wpa_bss *
832 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
833 struct wpa_ssid *group,
834 struct wpa_ssid **selected_ssid)
838 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
841 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
842 struct wpa_bss *bss = wpa_s->last_scan_res[i];
843 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
846 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
849 wpa_ssid_txt(bss->ssid, bss->ssid_len));
857 static struct wpa_bss *
858 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. */
1095 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1096 union wpa_event_data *data, int suppress_event)
1098 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1099 union wpa_event_data *data)
1102 struct wpa_scan_results *scan_res;
1104 #ifndef CONFIG_NO_RANDOM_POOL
1106 #endif /* CONFIG_NO_RANDOM_POOL */
1109 if (wpa_s->ap_iface)
1111 #endif /* CONFIG_AP */
1113 wpa_supplicant_notify_scanning(wpa_s, 0);
1116 if (wpa_s->global->p2p_cb_on_scan_complete &&
1117 !wpa_s->global->p2p_disabled &&
1118 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1119 !wpa_s->scan_res_handler) {
1120 wpa_s->global->p2p_cb_on_scan_complete = 0;
1121 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1122 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1123 "stopped scan processing");
1124 wpa_s->sta_scan_pending = 1;
1125 wpa_supplicant_req_scan(wpa_s, 5, 0);
1129 wpa_s->sta_scan_pending = 0;
1130 #endif /* CONFIG_P2P */
1132 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1133 data ? &data->scan_info :
1135 if (scan_res == NULL) {
1136 if (wpa_s->conf->ap_scan == 2 || ap ||
1137 wpa_s->scan_res_handler == scan_only_handler)
1139 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1141 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1145 #ifndef CONFIG_NO_RANDOM_POOL
1146 num = scan_res->num;
1149 for (i = 0; i < num; i++) {
1151 struct wpa_scan_res *res = scan_res->res[i];
1152 buf[0] = res->bssid[5];
1153 buf[1] = res->qual & 0xff;
1154 buf[2] = res->noise & 0xff;
1155 buf[3] = res->level & 0xff;
1156 buf[4] = res->tsf & 0xff;
1157 random_add_randomness(buf, sizeof(buf));
1159 #endif /* CONFIG_NO_RANDOM_POOL */
1161 if (wpa_s->scan_res_handler) {
1162 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1163 struct wpa_scan_results *scan_res);
1165 scan_res_handler = wpa_s->scan_res_handler;
1166 wpa_s->scan_res_handler = NULL;
1167 scan_res_handler(wpa_s, scan_res);
1169 wpa_scan_results_free(scan_res);
1174 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1176 if (wpa_s->ap_iface->scan_cb)
1177 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1178 #endif /* CONFIG_AP */
1179 wpa_scan_results_free(scan_res);
1185 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1186 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1187 wpas_notify_scan_results(wpa_s);
1190 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1191 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1192 wpas_notify_scan_results(wpa_s);
1195 wpas_notify_scan_done(wpa_s, 1);
1197 if (sme_proc_obss_scan(wpa_s) > 0) {
1198 wpa_scan_results_free(scan_res);
1202 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1203 wpa_scan_results_free(scan_res);
1207 if (autoscan_notify_scan(wpa_s, scan_res)) {
1208 wpa_scan_results_free(scan_res);
1212 if (wpa_s->disconnected) {
1213 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1214 wpa_scan_results_free(scan_res);
1218 if (!wpas_driver_bss_selection(wpa_s) &&
1219 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1220 wpa_scan_results_free(scan_res);
1224 wpas_wps_update_ap_info(wpa_s, scan_res);
1226 wpa_scan_results_free(scan_res);
1228 return wpas_select_network_from_last_scan(wpa_s);
1232 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1234 struct wpa_bss *selected;
1235 struct wpa_ssid *ssid = NULL;
1237 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1241 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1243 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1247 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1248 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1251 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1253 * Do not notify other virtual radios of scan results since we do not
1254 * want them to start other associations at the same time.
1258 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1259 ssid = wpa_supplicant_pick_new_network(wpa_s);
1261 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1262 wpa_supplicant_associate(wpa_s, NULL, ssid);
1263 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1265 int timeout_sec = wpa_s->scan_interval;
1266 int timeout_usec = 0;
1268 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1271 if (wpa_s->p2p_in_provisioning) {
1273 * Use shorter wait during P2P Provisioning
1274 * state to speed up group formation.
1277 timeout_usec = 250000;
1278 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1282 #endif /* CONFIG_P2P */
1283 #ifdef CONFIG_INTERWORKING
1284 if (wpa_s->conf->auto_interworking &&
1285 wpa_s->conf->interworking &&
1286 wpa_s->conf->cred) {
1287 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1288 "start ANQP fetch since no matching "
1290 wpa_s->network_select = 1;
1291 wpa_s->auto_network_select = 1;
1292 interworking_start_fetch_anqp(wpa_s);
1295 #endif /* CONFIG_INTERWORKING */
1296 if (wpa_supplicant_req_sched_scan(wpa_s))
1297 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1305 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1306 union wpa_event_data *data)
1308 const char *rn, *rn2;
1309 struct wpa_supplicant *ifs;
1311 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) != 0) {
1313 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1316 * If no scan results could be fetched, then no need to
1317 * notify those interfaces that did not actually request
1318 * this scan. Similarly, if scan results started a new operation on this
1319 * interface, do not notify other interfaces to avoid concurrent
1320 * operations during a connection attempt.
1326 * Check other interfaces to see if they have the same radio-name. If
1327 * so, they get updated with this same scan info.
1329 if (!wpa_s->driver->get_radio_name)
1332 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1333 if (rn == NULL || rn[0] == '\0')
1336 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1337 "sharing same radio (%s) in event_scan_results", rn);
1339 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1340 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1343 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1344 if (rn2 && os_strcmp(rn, rn2) == 0) {
1345 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1346 "sibling", ifs->ifname);
1348 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1349 /* Do not update the scan results from STA interface to p2p interfaces */
1350 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1351 "sibling %s", ifs->ifname, wpa_s->ifname);
1355 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1356 * no time. Avoid announcing it to application as it may not
1357 * be that useful (since results will be that of only 1,6,11).
1358 * over to any other interface as it
1360 if(p2p_search_in_progress(wpa_s->global->p2p))
1361 _wpa_supplicant_event_scan_results(ifs, data, 1);
1363 _wpa_supplicant_event_scan_results(ifs, data, 0);
1366 _wpa_supplicant_event_scan_results(ifs, data);
1372 #endif /* CONFIG_NO_SCAN_PROCESSING */
1375 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1377 #ifdef CONFIG_NO_SCAN_PROCESSING
1379 #else /* CONFIG_NO_SCAN_PROCESSING */
1382 if (wpa_s->last_scan_res_used <= 0)
1386 if (now.sec - wpa_s->last_scan.sec > 5) {
1387 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1391 return wpas_select_network_from_last_scan(wpa_s);
1392 #endif /* CONFIG_NO_SCAN_PROCESSING */
1397 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1399 struct wpa_supplicant *wpa_s = eloop_ctx;
1401 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1404 if (!wpa_s->no_keep_alive) {
1405 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1406 MAC2STR(wpa_s->bssid));
1407 /* TODO: could skip this if normal data traffic has been sent */
1408 /* TODO: Consider using some more appropriate data frame for
1411 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1416 if (wpa_s->sme.bss_max_idle_period) {
1418 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1421 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1422 wnm_bss_keep_alive, wpa_s, NULL);
1424 #endif /* CONFIG_SME */
1428 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1429 const u8 *ies, size_t ies_len)
1431 struct ieee802_11_elems elems;
1436 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1440 if (elems.bss_max_idle_period) {
1442 wpa_s->sme.bss_max_idle_period =
1443 WPA_GET_LE16(elems.bss_max_idle_period);
1444 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1445 "TU)%s", wpa_s->sme.bss_max_idle_period,
1446 (elems.bss_max_idle_period[2] & 0x01) ?
1447 " (protected keep-live required)" : "");
1448 if (wpa_s->sme.bss_max_idle_period == 0)
1449 wpa_s->sme.bss_max_idle_period = 1;
1450 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1451 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1452 /* msec times 1000 */
1453 msec = wpa_s->sme.bss_max_idle_period * 1024;
1456 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1457 wnm_bss_keep_alive, wpa_s,
1461 #endif /* CONFIG_SME */
1464 #endif /* CONFIG_WNM */
1467 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1470 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1471 #endif /* CONFIG_WNM */
1475 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1476 union wpa_event_data *data)
1478 int l, len, found = 0, wpa_found, rsn_found;
1481 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1482 if (data->assoc_info.req_ies)
1483 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1484 data->assoc_info.req_ies_len);
1485 if (data->assoc_info.resp_ies) {
1486 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1487 data->assoc_info.resp_ies_len);
1489 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1490 data->assoc_info.resp_ies_len);
1491 #endif /* CONFIG_TDLS */
1493 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1494 data->assoc_info.resp_ies_len);
1495 #endif /* CONFIG_WNM */
1497 if (data->assoc_info.beacon_ies)
1498 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1499 data->assoc_info.beacon_ies,
1500 data->assoc_info.beacon_ies_len);
1501 if (data->assoc_info.freq)
1502 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1503 data->assoc_info.freq);
1505 p = data->assoc_info.req_ies;
1506 l = data->assoc_info.req_ies_len;
1508 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1509 while (p && l >= 2) {
1512 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1516 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1517 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1518 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1519 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1522 wpa_find_assoc_pmkid(wpa_s);
1528 if (!found && data->assoc_info.req_ies)
1529 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1531 #ifdef CONFIG_IEEE80211R
1533 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1535 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1536 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1537 data->assoc_info.resp_ies,
1538 data->assoc_info.resp_ies_len,
1540 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1541 "Reassociation Response failed");
1542 wpa_supplicant_deauthenticate(
1543 wpa_s, WLAN_REASON_INVALID_IE);
1548 p = data->assoc_info.resp_ies;
1549 l = data->assoc_info.resp_ies_len;
1551 #ifdef CONFIG_WPS_STRICT
1552 if (p && wpa_s->current_ssid &&
1553 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1555 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1557 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1558 "include WPS IE in (Re)Association Response");
1562 if (wps_validate_assoc_resp(wps) < 0) {
1564 wpa_supplicant_deauthenticate(
1565 wpa_s, WLAN_REASON_INVALID_IE);
1570 #endif /* CONFIG_WPS_STRICT */
1572 /* Go through the IEs and make a copy of the MDIE, if present. */
1573 while (p && l >= 2) {
1576 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1580 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1581 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1582 wpa_s->sme.ft_used = 1;
1583 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1584 MOBILITY_DOMAIN_ID_LEN);
1590 #endif /* CONFIG_SME */
1592 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1593 data->assoc_info.resp_ies_len);
1594 #endif /* CONFIG_IEEE80211R */
1596 /* WPA/RSN IE from Beacon/ProbeResp */
1597 p = data->assoc_info.beacon_ies;
1598 l = data->assoc_info.beacon_ies_len;
1600 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1602 wpa_found = rsn_found = 0;
1603 while (p && l >= 2) {
1606 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1611 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1612 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1614 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1618 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1620 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1627 if (!wpa_found && data->assoc_info.beacon_ies)
1628 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1629 if (!rsn_found && data->assoc_info.beacon_ies)
1630 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1631 if (wpa_found || rsn_found)
1632 wpa_s->ap_ies_from_associnfo = 1;
1634 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1635 wpa_s->assoc_freq != data->assoc_info.freq) {
1636 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1638 wpa_s->assoc_freq, data->assoc_info.freq);
1639 wpa_supplicant_update_scan_results(wpa_s);
1642 wpa_s->assoc_freq = data->assoc_info.freq;
1648 static struct wpa_bss * wpa_supplicant_get_new_bss(
1649 struct wpa_supplicant *wpa_s, const u8 *bssid)
1651 struct wpa_bss *bss = NULL;
1652 struct wpa_ssid *ssid = wpa_s->current_ssid;
1654 if (ssid->ssid_len > 0)
1655 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1657 bss = wpa_bss_get_bssid(wpa_s, bssid);
1663 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1665 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1667 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1670 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1673 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1674 WPA_IE_VENDOR_TYPE);
1675 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1677 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1678 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1679 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1680 bss_rsn ? 2 + bss_rsn[1] : 0))
1687 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1688 union wpa_event_data *data)
1692 struct wpa_driver_capa capa;
1695 if (wpa_s->ap_iface) {
1696 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1697 data->assoc_info.addr,
1698 data->assoc_info.req_ies,
1699 data->assoc_info.req_ies_len,
1700 data->assoc_info.reassoc);
1703 #endif /* CONFIG_AP */
1705 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1706 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1709 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1710 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1711 wpa_supplicant_deauthenticate(
1712 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1716 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1717 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1718 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1719 MACSTR, MAC2STR(bssid));
1720 random_add_randomness(bssid, ETH_ALEN);
1721 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1722 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1723 wpas_notify_bssid_changed(wpa_s);
1725 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1726 wpa_clear_keys(wpa_s, bssid);
1728 if (wpa_supplicant_select_config(wpa_s) < 0) {
1729 wpa_supplicant_deauthenticate(
1730 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1733 if (wpa_s->current_ssid) {
1734 struct wpa_bss *bss = NULL;
1736 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1738 wpa_supplicant_update_scan_results(wpa_s);
1740 /* Get the BSS from the new scan results */
1741 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1745 wpa_s->current_bss = bss;
1749 if (wpa_s->conf->ap_scan == 1) {
1751 if (wpa_s->conf->ap_scan == 1 &&
1752 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1754 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1755 wpa_msg(wpa_s, MSG_WARNING,
1756 "WPA/RSN IEs not updated");
1761 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1762 wpa_s->sme.prev_bssid_set = 1;
1763 #endif /* CONFIG_SME */
1765 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1766 if (wpa_s->current_ssid) {
1767 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1768 * initialized before association, but for other modes,
1769 * initialize PC/SC here, if the current configuration needs
1770 * smartcard or SIM/USIM. */
1771 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1773 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1775 l2_packet_notify_auth_start(wpa_s->l2);
1778 * Set portEnabled first to FALSE in order to get EAP state machine out
1779 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1780 * state machine may transit to AUTHENTICATING state based on obsolete
1781 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1782 * AUTHENTICATED without ever giving chance to EAP state machine to
1785 if (!ft_completed) {
1786 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1787 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1789 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1790 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1791 /* 802.1X::portControl = Auto */
1792 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1793 wpa_s->eapol_received = 0;
1794 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1795 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1796 (wpa_s->current_ssid &&
1797 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1798 wpa_supplicant_cancel_auth_timeout(wpa_s);
1799 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1800 } else if (!ft_completed) {
1801 /* Timeout for receiving the first EAPOL packet */
1802 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1804 wpa_supplicant_cancel_scan(wpa_s);
1806 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1807 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1809 * We are done; the driver will take care of RSN 4-way
1812 wpa_supplicant_cancel_auth_timeout(wpa_s);
1813 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1814 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1815 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1816 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1817 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1819 * The driver will take care of RSN 4-way handshake, so we need
1820 * to allow EAPOL supplicant to complete its work without
1821 * waiting for WPA supplicant.
1823 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1824 } else if (ft_completed) {
1826 * FT protocol completed - make sure EAPOL state machine ends
1827 * up in authenticated.
1829 wpa_supplicant_cancel_auth_timeout(wpa_s);
1830 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1831 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1832 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1835 wpa_s->last_eapol_matches_bssid = 0;
1837 if (wpa_s->pending_eapol_rx) {
1838 struct os_time now, age;
1840 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1841 if (age.sec == 0 && age.usec < 100000 &&
1842 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1844 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1845 "frame that was received just before "
1846 "association notification");
1847 wpa_supplicant_rx_eapol(
1848 wpa_s, wpa_s->pending_eapol_rx_src,
1849 wpabuf_head(wpa_s->pending_eapol_rx),
1850 wpabuf_len(wpa_s->pending_eapol_rx));
1852 wpabuf_free(wpa_s->pending_eapol_rx);
1853 wpa_s->pending_eapol_rx = NULL;
1856 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1857 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1858 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1859 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1860 /* Set static WEP keys again */
1861 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1864 #ifdef CONFIG_IBSS_RSN
1865 if (wpa_s->current_ssid &&
1866 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1867 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1868 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1869 wpa_s->ibss_rsn == NULL) {
1870 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1871 if (!wpa_s->ibss_rsn) {
1872 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1873 wpa_supplicant_deauthenticate(
1874 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1878 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1880 #endif /* CONFIG_IBSS_RSN */
1882 wpas_wps_notify_assoc(wpa_s, bssid);
1886 static int disconnect_reason_recoverable(u16 reason_code)
1888 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1889 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1890 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1894 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1896 int locally_generated)
1900 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1902 * At least Host AP driver and a Prism3 card seemed to be
1903 * generating streams of disconnected events when configuring
1904 * IBSS for WPA-None. Ignore them for now.
1909 bssid = wpa_s->bssid;
1910 if (is_zero_ether_addr(bssid))
1911 bssid = wpa_s->pending_bssid;
1913 if (!is_zero_ether_addr(bssid) ||
1914 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1915 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1917 MAC2STR(bssid), reason_code,
1918 locally_generated ? " locally_generated=1" : "");
1923 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1924 int locally_generated)
1926 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1927 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1928 return 0; /* Not in 4-way handshake with PSK */
1931 * It looks like connection was lost while trying to go through PSK
1932 * 4-way handshake. Filter out known disconnection cases that are caused
1933 * by something else than PSK mismatch to avoid confusing reports.
1936 if (locally_generated) {
1937 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1945 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1947 int locally_generated)
1951 u8 prev_pending_bssid[ETH_ALEN];
1952 struct wpa_bss *fast_reconnect = NULL;
1953 struct wpa_ssid *fast_reconnect_ssid = NULL;
1954 struct wpa_ssid *last_ssid;
1956 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1957 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1959 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1961 * At least Host AP driver and a Prism3 card seemed to be
1962 * generating streams of disconnected events when configuring
1963 * IBSS for WPA-None. Ignore them for now.
1965 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1966 "IBSS/WPA-None mode");
1970 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1971 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1972 "pre-shared key may be incorrect");
1973 wpas_auth_failed(wpa_s);
1975 if (!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);
2492 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2493 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2494 data->deauth_info.addr);
2497 if (wpa_s->ap_iface) {
2498 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2502 #endif /* CONFIG_AP */
2503 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2505 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2506 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2507 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2508 eapol_sm_failed(wpa_s->eapol)))
2509 wpas_auth_failed(wpa_s);
2511 if (event == EVENT_DEAUTH && data) {
2512 if (wpas_p2p_deauth_notif(wpa_s,
2513 data->deauth_info.addr,
2515 data->deauth_info.ie,
2516 data->deauth_info.ie_len,
2517 locally_generated) > 0) {
2519 * The interface was removed, so cannot
2520 * continue processing any additional
2521 * operations after this.
2526 #endif /* CONFIG_P2P */
2527 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2530 case EVENT_MICHAEL_MIC_FAILURE:
2531 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2533 #ifndef CONFIG_NO_SCAN_PROCESSING
2534 case EVENT_SCAN_RESULTS:
2535 wpa_supplicant_event_scan_results(wpa_s, data);
2537 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2538 wpa_s->global->p2p != NULL &&
2539 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2540 wpa_s->wpa_state != WPA_ASSOCIATING) {
2541 wpa_s->global->p2p_cb_on_scan_complete = 0;
2542 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2543 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2544 "continued after scan result processing");
2547 #endif /* CONFIG_P2P */
2549 #endif /* CONFIG_NO_SCAN_PROCESSING */
2550 case EVENT_ASSOCINFO:
2551 wpa_supplicant_event_associnfo(wpa_s, data);
2553 case EVENT_INTERFACE_STATUS:
2554 wpa_supplicant_event_interface_status(wpa_s, data);
2556 case EVENT_PMKID_CANDIDATE:
2557 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2559 #ifdef CONFIG_PEERKEY
2560 case EVENT_STKSTART:
2561 wpa_supplicant_event_stkstart(wpa_s, data);
2563 #endif /* CONFIG_PEERKEY */
2566 wpa_supplicant_event_tdls(wpa_s, data);
2568 #endif /* CONFIG_TDLS */
2571 wpa_supplicant_event_wnm(wpa_s, data);
2573 #endif /* CONFIG_WNM */
2574 #ifdef CONFIG_IEEE80211R
2575 case EVENT_FT_RESPONSE:
2576 wpa_supplicant_event_ft_response(wpa_s, data);
2578 #endif /* CONFIG_IEEE80211R */
2579 #ifdef CONFIG_IBSS_RSN
2580 case EVENT_IBSS_RSN_START:
2581 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2583 #endif /* CONFIG_IBSS_RSN */
2584 case EVENT_ASSOC_REJECT:
2585 if (data->assoc_reject.bssid)
2586 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2587 "bssid=" MACSTR " status_code=%u",
2588 MAC2STR(data->assoc_reject.bssid),
2589 data->assoc_reject.status_code);
2591 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2593 data->assoc_reject.status_code);
2594 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2595 sme_event_assoc_reject(wpa_s, data);
2598 if(!wpa_s->current_ssid) {
2599 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2602 /* If assoc reject is reported by the driver, then avoid
2603 * waiting for the authentication timeout. Cancel the
2604 * authentication timeout and retry the assoc.
2606 if(wpa_s->current_ssid->assoc_retry++ < 10) {
2607 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2608 wpa_s->current_ssid->assoc_retry);
2610 wpa_supplicant_cancel_auth_timeout(wpa_s);
2612 /* Clear the states */
2613 wpa_sm_notify_disassoc(wpa_s->wpa);
2614 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2616 wpa_s->reassociate = 1;
2617 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
2618 const u8 *bl_bssid = data->assoc_reject.bssid;
2619 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2620 bl_bssid = wpa_s->pending_bssid;
2621 wpa_blacklist_add(wpa_s, bl_bssid);
2622 wpa_supplicant_req_scan(wpa_s, 0, 0);
2624 wpa_supplicant_req_scan(wpa_s, 1, 0);
2626 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
2627 /* If we ASSOC_REJECT's hits threshold, disable the
2630 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2631 "Disabling the network");
2632 wpa_s->current_ssid->assoc_retry = 0;
2633 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
2634 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
2637 const u8 *bssid = data->assoc_reject.bssid;
2638 if (bssid == NULL || is_zero_ether_addr(bssid))
2639 bssid = wpa_s->pending_bssid;
2640 wpas_connection_failed(wpa_s, bssid);
2641 wpa_supplicant_mark_disassoc(wpa_s);
2642 #endif /* ANDROID_P2P */
2645 case EVENT_AUTH_TIMED_OUT:
2646 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2647 sme_event_auth_timed_out(wpa_s, data);
2649 case EVENT_ASSOC_TIMED_OUT:
2650 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2651 sme_event_assoc_timed_out(wpa_s, data);
2653 case EVENT_TX_STATUS:
2654 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2655 " type=%d stype=%d",
2656 MAC2STR(data->tx_status.dst),
2657 data->tx_status.type, data->tx_status.stype);
2659 if (wpa_s->ap_iface == NULL) {
2660 #ifdef CONFIG_OFFCHANNEL
2661 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2662 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2663 offchannel_send_action_tx_status(
2664 wpa_s, data->tx_status.dst,
2665 data->tx_status.data,
2666 data->tx_status.data_len,
2667 data->tx_status.ack ?
2668 OFFCHANNEL_SEND_ACTION_SUCCESS :
2669 OFFCHANNEL_SEND_ACTION_NO_ACK);
2670 #endif /* CONFIG_OFFCHANNEL */
2673 #endif /* CONFIG_AP */
2674 #ifdef CONFIG_OFFCHANNEL
2675 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2676 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2678 * Catch TX status events for Action frames we sent via group
2679 * interface in GO mode.
2681 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2682 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2683 os_memcmp(wpa_s->parent->pending_action_dst,
2684 data->tx_status.dst, ETH_ALEN) == 0) {
2685 offchannel_send_action_tx_status(
2686 wpa_s->parent, data->tx_status.dst,
2687 data->tx_status.data,
2688 data->tx_status.data_len,
2689 data->tx_status.ack ?
2690 OFFCHANNEL_SEND_ACTION_SUCCESS :
2691 OFFCHANNEL_SEND_ACTION_NO_ACK);
2694 #endif /* CONFIG_OFFCHANNEL */
2696 switch (data->tx_status.type) {
2697 case WLAN_FC_TYPE_MGMT:
2698 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2699 data->tx_status.data_len,
2700 data->tx_status.stype,
2701 data->tx_status.ack);
2703 case WLAN_FC_TYPE_DATA:
2704 ap_tx_status(wpa_s, data->tx_status.dst,
2705 data->tx_status.data,
2706 data->tx_status.data_len,
2707 data->tx_status.ack);
2710 #endif /* CONFIG_AP */
2713 case EVENT_EAPOL_TX_STATUS:
2714 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2715 data->eapol_tx_status.data,
2716 data->eapol_tx_status.data_len,
2717 data->eapol_tx_status.ack);
2719 case EVENT_DRIVER_CLIENT_POLL_OK:
2720 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2722 case EVENT_RX_FROM_UNKNOWN:
2723 if (wpa_s->ap_iface == NULL)
2725 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2726 data->rx_from_unknown.wds);
2728 case EVENT_CH_SWITCH:
2731 if (!wpa_s->ap_iface) {
2732 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2733 "event in non-AP mode");
2738 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2739 data->ch_switch.ht_enabled,
2740 data->ch_switch.ch_offset);
2741 #endif /* CONFIG_AP */
2743 case EVENT_RX_MGMT: {
2745 const struct ieee80211_mgmt *mgmt;
2747 mgmt = (const struct ieee80211_mgmt *)
2748 data->rx_mgmt.frame;
2749 fc = le_to_host16(mgmt->frame_control);
2750 stype = WLAN_FC_GET_STYPE(fc);
2752 if (wpa_s->ap_iface == NULL) {
2754 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2755 data->rx_mgmt.frame_len > 24) {
2756 const u8 *src = mgmt->sa;
2757 const u8 *ie = mgmt->u.probe_req.variable;
2758 size_t ie_len = data->rx_mgmt.frame_len -
2759 (mgmt->u.probe_req.variable -
2760 data->rx_mgmt.frame);
2761 wpas_p2p_probe_req_rx(
2762 wpa_s, src, mgmt->da,
2763 mgmt->bssid, ie, ie_len,
2764 data->rx_mgmt.ssi_signal);
2767 #endif /* CONFIG_P2P */
2768 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2769 "management frame in non-AP mode");
2773 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2774 data->rx_mgmt.frame_len > 24) {
2775 const u8 *ie = mgmt->u.probe_req.variable;
2776 size_t ie_len = data->rx_mgmt.frame_len -
2777 (mgmt->u.probe_req.variable -
2778 data->rx_mgmt.frame);
2780 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2781 mgmt->bssid, ie, ie_len,
2782 data->rx_mgmt.ssi_signal);
2785 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2788 #endif /* CONFIG_AP */
2789 case EVENT_RX_ACTION:
2790 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2791 " Category=%u DataLen=%d freq=%d MHz",
2792 MAC2STR(data->rx_action.sa),
2793 data->rx_action.category, (int) data->rx_action.len,
2794 data->rx_action.freq);
2795 #ifdef CONFIG_IEEE80211R
2796 if (data->rx_action.category == WLAN_ACTION_FT) {
2797 ft_rx_action(wpa_s, data->rx_action.data,
2798 data->rx_action.len);
2801 #endif /* CONFIG_IEEE80211R */
2802 #ifdef CONFIG_IEEE80211W
2804 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2805 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2806 data->rx_action.data,
2807 data->rx_action.len);
2810 #endif /* CONFIG_SME */
2811 #endif /* CONFIG_IEEE80211W */
2813 if (data->rx_action.category == WLAN_ACTION_WNM) {
2814 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2817 #endif /* CONFIG_WNM */
2819 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2820 gas_query_rx(wpa_s->gas, data->rx_action.da,
2821 data->rx_action.sa, data->rx_action.bssid,
2822 data->rx_action.data, data->rx_action.len,
2823 data->rx_action.freq) == 0)
2825 #endif /* CONFIG_GAS */
2827 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2828 data->rx_action.len >= 4 &&
2829 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2830 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2831 "Response from " MACSTR,
2832 MAC2STR(data->rx_action.sa));
2835 #endif /* CONFIG_TDLS */
2837 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2839 data->rx_action.bssid,
2840 data->rx_action.category,
2841 data->rx_action.data,
2842 data->rx_action.len, data->rx_action.freq);
2843 #endif /* CONFIG_P2P */
2845 case EVENT_RX_PROBE_REQ:
2846 if (data->rx_probe_req.sa == NULL ||
2847 data->rx_probe_req.ie == NULL)
2850 if (wpa_s->ap_iface) {
2851 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2852 data->rx_probe_req.sa,
2853 data->rx_probe_req.da,
2854 data->rx_probe_req.bssid,
2855 data->rx_probe_req.ie,
2856 data->rx_probe_req.ie_len,
2857 data->rx_probe_req.ssi_signal);
2860 #endif /* CONFIG_AP */
2862 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2863 data->rx_probe_req.da,
2864 data->rx_probe_req.bssid,
2865 data->rx_probe_req.ie,
2866 data->rx_probe_req.ie_len,
2867 data->rx_probe_req.ssi_signal);
2868 #endif /* CONFIG_P2P */
2870 case EVENT_REMAIN_ON_CHANNEL:
2871 #ifdef CONFIG_OFFCHANNEL
2872 offchannel_remain_on_channel_cb(
2873 wpa_s, data->remain_on_channel.freq,
2874 data->remain_on_channel.duration);
2875 #endif /* CONFIG_OFFCHANNEL */
2877 wpas_p2p_remain_on_channel_cb(
2878 wpa_s, data->remain_on_channel.freq,
2879 data->remain_on_channel.duration);
2880 #endif /* CONFIG_P2P */
2882 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2883 #ifdef CONFIG_OFFCHANNEL
2884 offchannel_cancel_remain_on_channel_cb(
2885 wpa_s, data->remain_on_channel.freq);
2886 #endif /* CONFIG_OFFCHANNEL */
2888 wpas_p2p_cancel_remain_on_channel_cb(
2889 wpa_s, data->remain_on_channel.freq);
2890 #endif /* CONFIG_P2P */
2893 case EVENT_P2P_DEV_FOUND: {
2894 struct p2p_peer_info peer_info;
2896 os_memset(&peer_info, 0, sizeof(peer_info));
2897 if (data->p2p_dev_found.dev_addr)
2898 os_memcpy(peer_info.p2p_device_addr,
2899 data->p2p_dev_found.dev_addr, ETH_ALEN);
2900 if (data->p2p_dev_found.pri_dev_type)
2901 os_memcpy(peer_info.pri_dev_type,
2902 data->p2p_dev_found.pri_dev_type,
2903 sizeof(peer_info.pri_dev_type));
2904 if (data->p2p_dev_found.dev_name)
2905 os_strlcpy(peer_info.device_name,
2906 data->p2p_dev_found.dev_name,
2907 sizeof(peer_info.device_name));
2908 peer_info.config_methods = data->p2p_dev_found.config_methods;
2909 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2910 peer_info.group_capab = data->p2p_dev_found.group_capab;
2913 * FIX: new_device=1 is not necessarily correct. We should
2914 * maintain a P2P peer database in wpa_supplicant and update
2915 * this information based on whether the peer is truly new.
2917 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2920 case EVENT_P2P_GO_NEG_REQ_RX:
2921 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2922 data->p2p_go_neg_req_rx.dev_passwd_id);
2924 case EVENT_P2P_GO_NEG_COMPLETED:
2925 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2927 case EVENT_P2P_PROV_DISC_REQUEST:
2928 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2929 data->p2p_prov_disc_req.config_methods,
2930 data->p2p_prov_disc_req.dev_addr,
2931 data->p2p_prov_disc_req.pri_dev_type,
2932 data->p2p_prov_disc_req.dev_name,
2933 data->p2p_prov_disc_req.supp_config_methods,
2934 data->p2p_prov_disc_req.dev_capab,
2935 data->p2p_prov_disc_req.group_capab,
2938 case EVENT_P2P_PROV_DISC_RESPONSE:
2939 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2940 data->p2p_prov_disc_resp.config_methods);
2942 case EVENT_P2P_SD_REQUEST:
2943 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2944 data->p2p_sd_req.sa,
2945 data->p2p_sd_req.dialog_token,
2946 data->p2p_sd_req.update_indic,
2947 data->p2p_sd_req.tlvs,
2948 data->p2p_sd_req.tlvs_len);
2950 case EVENT_P2P_SD_RESPONSE:
2951 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2952 data->p2p_sd_resp.update_indic,
2953 data->p2p_sd_resp.tlvs,
2954 data->p2p_sd_resp.tlvs_len);
2956 #endif /* CONFIG_P2P */
2957 case EVENT_EAPOL_RX:
2958 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2959 data->eapol_rx.data,
2960 data->eapol_rx.data_len);
2962 case EVENT_SIGNAL_CHANGE:
2963 bgscan_notify_signal_change(
2964 wpa_s, data->signal_change.above_threshold,
2965 data->signal_change.current_signal,
2966 data->signal_change.current_noise,
2967 data->signal_change.current_txrate);
2969 case EVENT_INTERFACE_ENABLED:
2970 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2971 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2972 wpa_supplicant_update_mac_addr(wpa_s);
2974 if (!wpa_s->ap_iface) {
2975 wpa_supplicant_set_state(wpa_s,
2977 wpa_supplicant_req_scan(wpa_s, 0, 0);
2979 wpa_supplicant_set_state(wpa_s,
2981 #else /* CONFIG_AP */
2982 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2983 wpa_supplicant_req_scan(wpa_s, 0, 0);
2984 #endif /* CONFIG_AP */
2987 case EVENT_INTERFACE_DISABLED:
2988 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2989 wpa_supplicant_mark_disassoc(wpa_s);
2990 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2992 case EVENT_CHANNEL_LIST_CHANGED:
2993 if (wpa_s->drv_priv == NULL)
2994 break; /* Ignore event during drv initialization */
2996 free_hw_features(wpa_s);
2997 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2998 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3001 wpas_p2p_update_channel_list(wpa_s);
3002 #endif /* CONFIG_P2P */
3004 case EVENT_INTERFACE_UNAVAILABLE:
3006 wpas_p2p_interface_unavailable(wpa_s);
3007 #endif /* CONFIG_P2P */
3009 case EVENT_BEST_CHANNEL:
3010 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3012 data->best_chan.freq_24, data->best_chan.freq_5,
3013 data->best_chan.freq_overall);
3014 wpa_s->best_24_freq = data->best_chan.freq_24;
3015 wpa_s->best_5_freq = data->best_chan.freq_5;
3016 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3018 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3019 data->best_chan.freq_5,
3020 data->best_chan.freq_overall);
3021 #endif /* CONFIG_P2P */
3023 case EVENT_UNPROT_DEAUTH:
3024 wpa_supplicant_event_unprot_deauth(wpa_s,
3025 &data->unprot_deauth);
3027 case EVENT_UNPROT_DISASSOC:
3028 wpa_supplicant_event_unprot_disassoc(wpa_s,
3029 &data->unprot_disassoc);
3031 case EVENT_STATION_LOW_ACK:
3033 if (wpa_s->ap_iface && data)
3034 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3035 data->low_ack.addr);
3036 #endif /* CONFIG_AP */
3039 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3040 #endif /* CONFIG_TDLS */
3042 case EVENT_IBSS_PEER_LOST:
3043 #ifdef CONFIG_IBSS_RSN
3044 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3045 #endif /* CONFIG_IBSS_RSN */
3047 case EVENT_DRIVER_GTK_REKEY:
3048 if (os_memcmp(data->driver_gtk_rekey.bssid,
3049 wpa_s->bssid, ETH_ALEN))
3053 wpa_sm_update_replay_ctr(wpa_s->wpa,
3054 data->driver_gtk_rekey.replay_ctr);
3056 case EVENT_SCHED_SCAN_STOPPED:
3057 wpa_s->sched_scanning = 0;
3058 wpa_supplicant_notify_scanning(wpa_s, 0);
3060 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3064 * If we timed out, start a new sched scan to continue
3065 * searching for more SSIDs.
3067 if (wpa_s->sched_scan_timed_out)
3068 wpa_supplicant_req_sched_scan(wpa_s);
3070 case EVENT_WPS_BUTTON_PUSHED:
3072 wpas_wps_start_pbc(wpa_s, NULL, 0);
3073 #endif /* CONFIG_WPS */
3075 case EVENT_CONNECT_FAILED_REASON:
3077 if (!wpa_s->ap_iface || !data)
3079 hostapd_event_connect_failed_reason(
3080 wpa_s->ap_iface->bss[0],
3081 data->connect_failed_reason.addr,
3082 data->connect_failed_reason.code);
3083 #endif /* CONFIG_AP */
3086 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);