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);
161 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
162 os_memset(wpa_s->bssid, 0, ETH_ALEN);
163 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
165 wpa_s->sme.prev_bssid_set = 0;
166 #endif /* CONFIG_SME */
168 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
169 #endif /* CONFIG_P2P */
170 wpa_s->current_bss = NULL;
171 wpa_s->assoc_freq = 0;
172 #ifdef CONFIG_IEEE80211R
174 if (wpa_s->sme.ft_ies)
175 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
176 #endif /* CONFIG_SME */
177 #endif /* CONFIG_IEEE80211R */
180 wpas_notify_bssid_changed(wpa_s);
182 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
183 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
184 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
185 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
186 wpa_s->ap_ies_from_associnfo = 0;
187 wpa_s->current_ssid = NULL;
192 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
194 struct wpa_ie_data ie;
198 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 for (i = 0; i < ie.num_pmkid; i++) {
203 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
204 ie.pmkid + i * PMKID_LEN,
206 if (pmksa_set == 0) {
207 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
212 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
213 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
218 union wpa_event_data *data)
221 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
226 " index=%d preauth=%d",
227 MAC2STR(data->pmkid_candidate.bssid),
228 data->pmkid_candidate.index,
229 data->pmkid_candidate.preauth);
231 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
232 data->pmkid_candidate.index,
233 data->pmkid_candidate.preauth);
237 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
239 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
240 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
243 #ifdef IEEE8021X_EAPOL
244 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
245 wpa_s->current_ssid &&
246 !(wpa_s->current_ssid->eapol_flags &
247 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
248 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
249 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
250 * plaintext or static WEP keys). */
253 #endif /* IEEE8021X_EAPOL */
260 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
261 * @wpa_s: pointer to wpa_supplicant data
262 * @ssid: Configuration data for the network
263 * Returns: 0 on success, -1 on failure
265 * This function is called when starting authentication with a network that is
266 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
268 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
269 struct wpa_ssid *ssid)
271 #ifdef IEEE8021X_EAPOL
273 int aka = 0, sim = 0, type;
275 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
278 if (ssid->eap.eap_methods == NULL) {
282 struct eap_method_type *eap = ssid->eap.eap_methods;
283 while (eap->vendor != EAP_VENDOR_IETF ||
284 eap->method != EAP_TYPE_NONE) {
285 if (eap->vendor == EAP_VENDOR_IETF) {
286 if (eap->method == EAP_TYPE_SIM)
288 else if (eap->method == EAP_TYPE_AKA ||
289 eap->method == EAP_TYPE_AKA_PRIME)
296 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
298 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
299 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
305 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
311 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
313 type = SCARD_TRY_BOTH;
315 type = SCARD_USIM_ONLY;
317 type = SCARD_GSM_SIM_ONLY;
319 wpa_s->scard = scard_init(type, NULL);
320 if (wpa_s->scard == NULL) {
321 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
325 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
326 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
327 #endif /* PCSC_FUNCS */
328 #endif /* IEEE8021X_EAPOL */
334 #ifndef CONFIG_NO_SCAN_PROCESSING
335 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
336 struct wpa_ssid *ssid)
340 if (ssid->mixed_cell)
344 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
346 #endif /* CONFIG_WPS */
348 for (i = 0; i < NUM_WEP_KEYS; i++) {
349 if (ssid->wep_key_len[i]) {
354 #ifdef IEEE8021X_EAPOL
355 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
356 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
357 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
359 #endif /* IEEE8021X_EAPOL */
361 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
364 if (bss->caps & IEEE80211_CAP_PRIVACY)
370 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
371 struct wpa_ssid *ssid,
374 struct wpa_ie_data ie;
376 const u8 *rsn_ie, *wpa_ie;
380 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
384 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
385 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
386 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
387 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
388 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
390 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
391 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
394 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
395 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
401 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
403 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
408 if (!(ie.proto & ssid->proto)) {
409 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
414 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
415 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
420 if (!(ie.group_cipher & ssid->group_cipher)) {
421 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
426 if (!(ie.key_mgmt & ssid->key_mgmt)) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
432 #ifdef CONFIG_IEEE80211W
433 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
434 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
435 wpa_s->conf->pmf : ssid->ieee80211w) ==
436 MGMT_FRAME_PROTECTION_REQUIRED) {
437 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
441 #endif /* CONFIG_IEEE80211W */
443 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
447 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
448 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
451 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
452 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
458 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
460 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
465 if (!(ie.proto & ssid->proto)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
471 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
472 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
477 if (!(ie.group_cipher & ssid->group_cipher)) {
478 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
483 if (!(ie.key_mgmt & ssid->key_mgmt)) {
484 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
489 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
493 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
495 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
499 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
500 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
501 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
505 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
506 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
510 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
517 static int freq_allowed(int *freqs, int freq)
524 for (i = 0; freqs[i]; i++)
525 if (freqs[i] == freq)
531 static int ht_supported(const struct hostapd_hw_modes *mode)
533 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
535 * The driver did not indicate whether it supports HT. Assume
536 * it does to avoid connection issues.
542 * IEEE Std 802.11n-2009 20.1.1:
543 * An HT non-AP STA shall support all EQM rates for one spatial stream.
545 return mode->mcs_set[0] == 0xff;
549 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
551 const struct hostapd_hw_modes *mode = NULL, *modes;
552 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
557 return 1; /* Cannot do matching without knowing band */
559 modes = wpa_s->hw.modes;
562 * The driver does not provide any additional information
563 * about the utilized hardware, so allow the connection attempt
569 for (i = 0; i < wpa_s->hw.num_modes; i++) {
570 for (j = 0; j < modes[i].num_channels; j++) {
571 int freq = modes[i].channels[j].freq;
572 if (freq == bss->freq) {
574 mode->mode == HOSTAPD_MODE_IEEE80211G)
575 break; /* do not allow 802.11b replace
586 for (i = 0; i < (int) sizeof(scan_ie); i++) {
587 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
591 for (j = 2; j < rate_ie[1] + 2; j++) {
592 int flagged = !!(rate_ie[j] & 0x80);
593 int r = (rate_ie[j] & 0x7f) * 5;
596 * IEEE Std 802.11n-2009 7.3.2.2:
597 * The new BSS Membership selector value is encoded
598 * like a legacy basic rate, but it is not a rate and
599 * only indicates if the BSS members are required to
600 * support the mandatory features of Clause 20 [HT PHY]
601 * in order to join the BSS.
603 if (flagged && ((rate_ie[j] & 0x7f) ==
604 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
605 if (!ht_supported(mode)) {
606 wpa_dbg(wpa_s, MSG_DEBUG,
607 " hardware does not support "
617 /* check for legacy basic rates */
618 for (k = 0; k < mode->num_rates; k++) {
619 if (mode->rates[k] == r)
622 if (k == mode->num_rates) {
624 * IEEE Std 802.11-2007 7.3.2.2 demands that in
625 * order to join a BSS all required rates
626 * have to be supported by the hardware.
628 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
629 "not support required rate %d.%d Mbps",
640 static int bss_is_dmg(struct wpa_bss *bss)
642 return bss->freq > 45000;
647 * Test whether BSS is in an ESS.
648 * This is done differently in DMG (60 GHz) and non-DMG bands
650 static int bss_is_ess(struct wpa_bss *bss)
652 if (bss_is_dmg(bss)) {
653 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
654 IEEE80211_CAP_DMG_AP;
657 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
662 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
663 int i, struct wpa_bss *bss,
664 struct wpa_ssid *group)
666 u8 wpa_ie_len, rsn_ie_len;
668 struct wpa_blacklist *e;
670 struct wpa_ssid *ssid;
672 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
673 wpa_ie_len = ie ? ie[1] : 0;
675 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
676 rsn_ie_len = ie ? ie[1] : 0;
678 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
679 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
680 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
681 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
682 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
684 e = wpa_blacklist_get(wpa_s, bss->bssid);
687 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
689 * When only a single network is enabled, we can
690 * trigger blacklisting on the first failure. This
691 * should not be done with multiple enabled networks to
692 * avoid getting forced to move into a worse ESS on
693 * single error if there are no other BSSes of the
698 if (e->count > limit) {
699 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
700 "(count=%d limit=%d)", e->count, limit);
705 if (bss->ssid_len == 0) {
706 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
710 if (disallowed_bssid(wpa_s, bss->bssid)) {
711 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
715 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
716 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
720 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
722 for (ssid = group; ssid; ssid = ssid->pnext) {
723 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
726 if (wpas_network_disabled(wpa_s, ssid)) {
727 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
731 res = wpas_temp_disabled(wpa_s, ssid);
733 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
734 "temporarily for %d second(s)", res);
739 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
740 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
745 if (wpa && ssid->ssid_len == 0 &&
746 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
749 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
750 /* Only allow wildcard SSID match if an AP
751 * advertises active WPS operation that matches
754 if (ssid->ssid_len == 0 &&
755 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
758 #endif /* CONFIG_WPS */
760 if (ssid->bssid_set && ssid->ssid_len == 0 &&
761 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
765 (bss->ssid_len != ssid->ssid_len ||
766 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
767 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
771 if (ssid->bssid_set &&
772 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
777 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
781 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
782 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
783 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
784 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
789 if (!wpa_supplicant_match_privacy(bss, ssid)) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
795 if (!bss_is_ess(bss)) {
796 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
800 if (!freq_allowed(ssid->freq_list, bss->freq)) {
801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
806 if (!rate_match(wpa_s, bss)) {
807 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
814 * TODO: skip the AP if its P2P IE has Group Formation
815 * bit set in the P2P Group Capability Bitmap and we
816 * are not in Group Formation with that device.
818 #endif /* CONFIG_P2P */
820 /* Matching configuration found */
824 /* No matching configuration found */
829 static struct wpa_bss *
830 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
831 struct wpa_ssid *group,
832 struct wpa_ssid **selected_ssid)
836 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
839 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
840 struct wpa_bss *bss = wpa_s->last_scan_res[i];
841 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
844 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
847 wpa_ssid_txt(bss->ssid, bss->ssid_len));
855 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
856 struct wpa_ssid **selected_ssid)
858 struct wpa_bss *selected = NULL;
861 if (wpa_s->last_scan_res == NULL ||
862 wpa_s->last_scan_res_used == 0)
863 return NULL; /* no scan results from last update */
865 while (selected == NULL) {
866 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
867 selected = wpa_supplicant_select_bss(
868 wpa_s, wpa_s->conf->pssid[prio],
874 if (selected == NULL && wpa_s->blacklist &&
875 !wpa_s->countermeasures) {
876 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
877 "blacklist and try again");
878 wpa_blacklist_clear(wpa_s);
879 wpa_s->blacklist_cleared++;
880 } else if (selected == NULL)
888 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
889 int timeout_sec, int timeout_usec)
891 if (!wpa_supplicant_enabled_networks(wpa_s)) {
893 * No networks are enabled; short-circuit request so
894 * we don't wait timeout seconds before transitioning
897 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
898 "since there are no enabled networks");
899 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
901 wpa_s->sta_scan_pending = 0;
902 #endif /* CONFIG_P2P */
906 wpa_s->scan_for_connection = 1;
907 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
911 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
912 struct wpa_bss *selected,
913 struct wpa_ssid *ssid)
915 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
916 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
917 "PBC session overlap");
919 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
921 #endif /* CONFIG_P2P */
924 wpas_wps_cancel(wpa_s);
925 #endif /* CONFIG_WPS */
929 wpa_msg(wpa_s, MSG_DEBUG,
930 "Considering connect request: reassociate: %d selected: "
931 MACSTR " bssid: " MACSTR " pending: " MACSTR
932 " wpa_state: %s ssid=%p current_ssid=%p",
933 wpa_s->reassociate, MAC2STR(selected->bssid),
934 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
935 wpa_supplicant_state_txt(wpa_s->wpa_state),
936 ssid, wpa_s->current_ssid);
939 * Do not trigger new association unless the BSSID has changed or if
940 * reassociation is requested. If we are in process of associating with
941 * the selected BSSID, do not trigger new attempt.
943 if (wpa_s->reassociate ||
944 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
945 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
946 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
947 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
948 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
950 (is_zero_ether_addr(wpa_s->pending_bssid) &&
951 ssid != wpa_s->current_ssid)))) {
952 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
953 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
956 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
957 MAC2STR(selected->bssid));
958 wpa_supplicant_associate(wpa_s, selected, ssid);
960 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
961 "connect with the selected AP");
968 static struct wpa_ssid *
969 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
972 struct wpa_ssid *ssid;
974 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
975 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
977 if (wpas_network_disabled(wpa_s, ssid))
979 if (ssid->mode == IEEE80211_MODE_IBSS ||
980 ssid->mode == IEEE80211_MODE_AP)
988 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
989 * on BSS added and BSS changed events */
990 static void wpa_supplicant_rsn_preauth_scan_results(
991 struct wpa_supplicant *wpa_s)
995 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
998 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
999 const u8 *ssid, *rsn;
1001 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
1005 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1009 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1015 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1016 struct wpa_bss *selected,
1017 struct wpa_ssid *ssid)
1019 struct wpa_bss *current_bss = NULL;
1022 if (wpa_s->reassociate)
1023 return 1; /* explicit request to reassociate */
1024 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1025 return 1; /* we are not associated; continue */
1026 if (wpa_s->current_ssid == NULL)
1027 return 1; /* unknown current SSID */
1028 if (wpa_s->current_ssid != ssid)
1029 return 1; /* different network block */
1031 if (wpas_driver_bss_selection(wpa_s))
1032 return 0; /* Driver-based roaming */
1034 if (wpa_s->current_ssid->ssid)
1035 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1036 wpa_s->current_ssid->ssid,
1037 wpa_s->current_ssid->ssid_len);
1039 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1042 return 1; /* current BSS not seen in scan results */
1044 if (current_bss == selected)
1047 if (selected->last_update_idx > current_bss->last_update_idx)
1048 return 1; /* current BSS not seen in the last scan */
1050 #ifndef CONFIG_NO_ROAMING
1051 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1052 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1053 MAC2STR(current_bss->bssid), current_bss->level);
1054 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1055 MAC2STR(selected->bssid), selected->level);
1057 if (wpa_s->current_ssid->bssid_set &&
1058 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1060 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1061 "has preferred BSSID");
1065 if (current_bss->level < 0 && current_bss->level > selected->level) {
1066 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1072 if (current_bss->level < 0) {
1073 if (current_bss->level < -85)
1075 else if (current_bss->level < -80)
1077 else if (current_bss->level < -75)
1079 else if (current_bss->level < -70)
1084 if (abs(current_bss->level - selected->level) < min_diff) {
1085 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1091 #else /* CONFIG_NO_ROAMING */
1093 #endif /* CONFIG_NO_ROAMING */
1097 /* Return != 0 if no scan results could be fetched or if scan results should not
1098 * be shared with other virtual interfaces. */
1099 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1100 union wpa_event_data *data,
1103 struct wpa_scan_results *scan_res;
1105 #ifndef CONFIG_NO_RANDOM_POOL
1107 #endif /* CONFIG_NO_RANDOM_POOL */
1110 if (wpa_s->ap_iface)
1112 #endif /* CONFIG_AP */
1114 wpa_supplicant_notify_scanning(wpa_s, 0);
1117 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1118 !wpa_s->global->p2p_disabled &&
1119 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1120 !wpa_s->scan_res_handler) {
1121 wpa_s->global->p2p_cb_on_scan_complete = 0;
1122 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1123 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1124 "stopped scan processing");
1125 wpa_s->sta_scan_pending = 1;
1126 wpa_supplicant_req_scan(wpa_s, 5, 0);
1130 wpa_s->sta_scan_pending = 0;
1131 #endif /* CONFIG_P2P */
1133 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1134 data ? &data->scan_info :
1136 if (scan_res == NULL) {
1137 if (wpa_s->conf->ap_scan == 2 || ap ||
1138 wpa_s->scan_res_handler == scan_only_handler)
1142 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1144 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1148 #ifndef CONFIG_NO_RANDOM_POOL
1149 num = scan_res->num;
1152 for (i = 0; i < num; i++) {
1154 struct wpa_scan_res *res = scan_res->res[i];
1155 buf[0] = res->bssid[5];
1156 buf[1] = res->qual & 0xff;
1157 buf[2] = res->noise & 0xff;
1158 buf[3] = res->level & 0xff;
1159 buf[4] = res->tsf & 0xff;
1160 random_add_randomness(buf, sizeof(buf));
1162 #endif /* CONFIG_NO_RANDOM_POOL */
1164 if (own_request && wpa_s->scan_res_handler) {
1165 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1166 struct wpa_scan_results *scan_res);
1168 scan_res_handler = wpa_s->scan_res_handler;
1169 wpa_s->scan_res_handler = NULL;
1170 scan_res_handler(wpa_s, scan_res);
1172 wpa_scan_results_free(scan_res);
1177 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1179 if (wpa_s->ap_iface->scan_cb)
1180 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1181 #endif /* CONFIG_AP */
1182 wpa_scan_results_free(scan_res);
1186 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1187 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1188 wpas_notify_scan_results(wpa_s);
1190 wpas_notify_scan_done(wpa_s, 1);
1192 if (sme_proc_obss_scan(wpa_s) > 0) {
1193 wpa_scan_results_free(scan_res);
1197 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1198 wpa_scan_results_free(scan_res);
1202 if (autoscan_notify_scan(wpa_s, scan_res)) {
1203 wpa_scan_results_free(scan_res);
1207 if (wpa_s->disconnected) {
1208 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1209 wpa_scan_results_free(scan_res);
1213 if (!wpas_driver_bss_selection(wpa_s) &&
1214 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1215 wpa_scan_results_free(scan_res);
1219 wpas_wps_update_ap_info(wpa_s, scan_res);
1221 wpa_scan_results_free(scan_res);
1223 return wpas_select_network_from_last_scan(wpa_s, 1);
1227 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1230 struct wpa_bss *selected;
1231 struct wpa_ssid *ssid = NULL;
1233 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1237 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1240 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1244 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1245 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1249 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1251 * Do not notify other virtual radios of scan results since we do not
1252 * want them to start other associations at the same time.
1256 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1257 ssid = wpa_supplicant_pick_new_network(wpa_s);
1259 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1260 wpa_supplicant_associate(wpa_s, NULL, ssid);
1262 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1264 int timeout_sec = wpa_s->scan_interval;
1265 int timeout_usec = 0;
1267 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1270 if (wpa_s->p2p_in_provisioning) {
1272 * Use shorter wait during P2P Provisioning
1273 * state to speed up group formation.
1276 timeout_usec = 250000;
1277 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1281 #endif /* CONFIG_P2P */
1282 #ifdef CONFIG_INTERWORKING
1283 if (wpa_s->conf->auto_interworking &&
1284 wpa_s->conf->interworking &&
1285 wpa_s->conf->cred) {
1286 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1287 "start ANQP fetch since no matching "
1289 wpa_s->network_select = 1;
1290 wpa_s->auto_network_select = 1;
1291 interworking_start_fetch_anqp(wpa_s);
1294 #endif /* CONFIG_INTERWORKING */
1295 if (wpa_supplicant_req_sched_scan(wpa_s))
1296 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1304 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1305 union wpa_event_data *data)
1307 const char *rn, *rn2;
1308 struct wpa_supplicant *ifs;
1310 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1312 * If no scan results could be fetched, then no need to
1313 * notify those interfaces that did not actually request
1314 * this scan. Similarly, if scan results started a new operation on this
1315 * interface, do not notify other interfaces to avoid concurrent
1316 * operations during a connection attempt.
1322 * Check other interfaces to see if they have the same radio-name. If
1323 * so, they get updated with this same scan info.
1325 if (!wpa_s->driver->get_radio_name)
1328 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1329 if (rn == NULL || rn[0] == '\0')
1332 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1333 "sharing same radio (%s) in event_scan_results", rn);
1335 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1336 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1339 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1340 if (rn2 && os_strcmp(rn, rn2) == 0) {
1341 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1342 "sibling", ifs->ifname);
1343 _wpa_supplicant_event_scan_results(ifs, data, 0);
1348 #endif /* CONFIG_NO_SCAN_PROCESSING */
1351 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1353 #ifdef CONFIG_NO_SCAN_PROCESSING
1355 #else /* CONFIG_NO_SCAN_PROCESSING */
1358 if (wpa_s->last_scan_res_used <= 0)
1362 if (now.sec - wpa_s->last_scan.sec > 5) {
1363 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1367 return wpas_select_network_from_last_scan(wpa_s, 0);
1368 #endif /* CONFIG_NO_SCAN_PROCESSING */
1373 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1375 struct wpa_supplicant *wpa_s = eloop_ctx;
1377 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1380 if (!wpa_s->no_keep_alive) {
1381 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1382 MAC2STR(wpa_s->bssid));
1383 /* TODO: could skip this if normal data traffic has been sent */
1384 /* TODO: Consider using some more appropriate data frame for
1387 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1392 if (wpa_s->sme.bss_max_idle_period) {
1394 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1397 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1398 wnm_bss_keep_alive, wpa_s, NULL);
1400 #endif /* CONFIG_SME */
1404 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1405 const u8 *ies, size_t ies_len)
1407 struct ieee802_11_elems elems;
1412 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1416 if (elems.bss_max_idle_period) {
1418 wpa_s->sme.bss_max_idle_period =
1419 WPA_GET_LE16(elems.bss_max_idle_period);
1420 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1421 "TU)%s", wpa_s->sme.bss_max_idle_period,
1422 (elems.bss_max_idle_period[2] & 0x01) ?
1423 " (protected keep-live required)" : "");
1424 if (wpa_s->sme.bss_max_idle_period == 0)
1425 wpa_s->sme.bss_max_idle_period = 1;
1426 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1427 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1428 /* msec times 1000 */
1429 msec = wpa_s->sme.bss_max_idle_period * 1024;
1432 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1433 wnm_bss_keep_alive, wpa_s,
1437 #endif /* CONFIG_SME */
1440 #endif /* CONFIG_WNM */
1443 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1446 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1447 #endif /* CONFIG_WNM */
1451 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1452 union wpa_event_data *data)
1454 int l, len, found = 0, wpa_found, rsn_found;
1456 #ifdef CONFIG_IEEE80211R
1458 #endif /* CONFIG_IEEE80211R */
1460 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1461 if (data->assoc_info.req_ies)
1462 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1463 data->assoc_info.req_ies_len);
1464 if (data->assoc_info.resp_ies) {
1465 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1466 data->assoc_info.resp_ies_len);
1468 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1469 data->assoc_info.resp_ies_len);
1470 #endif /* CONFIG_TDLS */
1472 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1473 data->assoc_info.resp_ies_len);
1474 #endif /* CONFIG_WNM */
1476 if (data->assoc_info.beacon_ies)
1477 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1478 data->assoc_info.beacon_ies,
1479 data->assoc_info.beacon_ies_len);
1480 if (data->assoc_info.freq)
1481 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1482 data->assoc_info.freq);
1484 p = data->assoc_info.req_ies;
1485 l = data->assoc_info.req_ies_len;
1487 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1488 while (p && l >= 2) {
1491 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1495 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1496 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1497 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1498 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1501 wpa_find_assoc_pmkid(wpa_s);
1507 if (!found && data->assoc_info.req_ies)
1508 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1510 #ifdef CONFIG_IEEE80211R
1512 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1513 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1514 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1515 data->assoc_info.resp_ies,
1516 data->assoc_info.resp_ies_len,
1518 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1519 "Reassociation Response failed");
1520 wpa_supplicant_deauthenticate(
1521 wpa_s, WLAN_REASON_INVALID_IE);
1526 p = data->assoc_info.resp_ies;
1527 l = data->assoc_info.resp_ies_len;
1529 #ifdef CONFIG_WPS_STRICT
1530 if (p && wpa_s->current_ssid &&
1531 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1533 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1535 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1536 "include WPS IE in (Re)Association Response");
1540 if (wps_validate_assoc_resp(wps) < 0) {
1542 wpa_supplicant_deauthenticate(
1543 wpa_s, WLAN_REASON_INVALID_IE);
1548 #endif /* CONFIG_WPS_STRICT */
1550 /* Go through the IEs and make a copy of the MDIE, if present. */
1551 while (p && l >= 2) {
1554 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1558 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1559 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1560 wpa_s->sme.ft_used = 1;
1561 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1562 MOBILITY_DOMAIN_ID_LEN);
1568 #endif /* CONFIG_SME */
1570 /* Process FT when SME is in the driver */
1571 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1572 wpa_ft_is_completed(wpa_s->wpa)) {
1573 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1574 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1575 data->assoc_info.resp_ies,
1576 data->assoc_info.resp_ies_len,
1578 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1579 "Reassociation Response failed");
1580 wpa_supplicant_deauthenticate(
1581 wpa_s, WLAN_REASON_INVALID_IE);
1584 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1587 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1588 data->assoc_info.resp_ies_len);
1589 #endif /* CONFIG_IEEE80211R */
1591 /* WPA/RSN IE from Beacon/ProbeResp */
1592 p = data->assoc_info.beacon_ies;
1593 l = data->assoc_info.beacon_ies_len;
1595 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1597 wpa_found = rsn_found = 0;
1598 while (p && l >= 2) {
1601 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1606 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1607 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1609 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1613 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1615 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1622 if (!wpa_found && data->assoc_info.beacon_ies)
1623 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1624 if (!rsn_found && data->assoc_info.beacon_ies)
1625 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1626 if (wpa_found || rsn_found)
1627 wpa_s->ap_ies_from_associnfo = 1;
1629 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1630 wpa_s->assoc_freq != data->assoc_info.freq) {
1631 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1633 wpa_s->assoc_freq, data->assoc_info.freq);
1634 wpa_supplicant_update_scan_results(wpa_s);
1637 wpa_s->assoc_freq = data->assoc_info.freq;
1643 static struct wpa_bss * wpa_supplicant_get_new_bss(
1644 struct wpa_supplicant *wpa_s, const u8 *bssid)
1646 struct wpa_bss *bss = NULL;
1647 struct wpa_ssid *ssid = wpa_s->current_ssid;
1649 if (ssid->ssid_len > 0)
1650 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1652 bss = wpa_bss_get_bssid(wpa_s, bssid);
1658 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1660 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1662 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1665 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1668 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1669 WPA_IE_VENDOR_TYPE);
1670 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1672 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1673 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1674 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1675 bss_rsn ? 2 + bss_rsn[1] : 0))
1682 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1683 union wpa_event_data *data)
1689 if (wpa_s->ap_iface) {
1690 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1691 data->assoc_info.addr,
1692 data->assoc_info.req_ies,
1693 data->assoc_info.req_ies_len,
1694 data->assoc_info.reassoc);
1697 #endif /* CONFIG_AP */
1699 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1700 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1703 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1704 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1705 wpa_supplicant_deauthenticate(
1706 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1710 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1711 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1712 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1713 MACSTR, MAC2STR(bssid));
1714 random_add_randomness(bssid, ETH_ALEN);
1715 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1716 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1717 wpas_notify_bssid_changed(wpa_s);
1719 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1720 wpa_clear_keys(wpa_s, bssid);
1722 if (wpa_supplicant_select_config(wpa_s) < 0) {
1723 wpa_supplicant_deauthenticate(
1724 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1727 if (wpa_s->current_ssid) {
1728 struct wpa_bss *bss = NULL;
1730 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1732 wpa_supplicant_update_scan_results(wpa_s);
1734 /* Get the BSS from the new scan results */
1735 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1739 wpa_s->current_bss = bss;
1742 if (wpa_s->conf->ap_scan == 1 &&
1743 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1744 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1745 wpa_msg(wpa_s, MSG_WARNING,
1746 "WPA/RSN IEs not updated");
1751 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1752 wpa_s->sme.prev_bssid_set = 1;
1753 #endif /* CONFIG_SME */
1755 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1756 if (wpa_s->current_ssid) {
1757 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1758 * initialized before association, but for other modes,
1759 * initialize PC/SC here, if the current configuration needs
1760 * smartcard or SIM/USIM. */
1761 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1763 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1765 l2_packet_notify_auth_start(wpa_s->l2);
1768 * Set portEnabled first to FALSE in order to get EAP state machine out
1769 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1770 * state machine may transit to AUTHENTICATING state based on obsolete
1771 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1772 * AUTHENTICATED without ever giving chance to EAP state machine to
1775 if (!ft_completed) {
1776 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1777 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1779 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1780 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1781 /* 802.1X::portControl = Auto */
1782 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1783 wpa_s->eapol_received = 0;
1784 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1785 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1786 (wpa_s->current_ssid &&
1787 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1788 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1790 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1792 * Set the key after having received joined-IBSS event
1795 wpa_supplicant_set_wpa_none_key(wpa_s,
1796 wpa_s->current_ssid);
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 &&
1859 (wpa_s->drv_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->disconnected &&
1976 (!wpa_s->auto_reconnect_disabled ||
1977 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
1978 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1979 "reconnect (wps=%d wpa_state=%d)",
1980 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1982 if (wpa_s->wpa_state == WPA_COMPLETED &&
1983 wpa_s->current_ssid &&
1984 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1985 !locally_generated &&
1986 disconnect_reason_recoverable(reason_code)) {
1988 * It looks like the AP has dropped association with
1989 * us, but could allow us to get back in. Try to
1990 * reconnect to the same BSS without full scan to save
1991 * time for some common cases.
1993 fast_reconnect = wpa_s->current_bss;
1994 fast_reconnect_ssid = wpa_s->current_ssid;
1995 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1996 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1998 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
2002 "try to re-connect");
2003 wpa_s->reassociate = 0;
2004 wpa_s->disconnected = 1;
2005 wpa_supplicant_cancel_sched_scan(wpa_s);
2007 bssid = wpa_s->bssid;
2008 if (is_zero_ether_addr(bssid))
2009 bssid = wpa_s->pending_bssid;
2010 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2011 wpas_connection_failed(wpa_s, bssid);
2012 wpa_sm_notify_disassoc(wpa_s->wpa);
2013 if (locally_generated)
2014 wpa_s->disconnect_reason = -reason_code;
2016 wpa_s->disconnect_reason = reason_code;
2017 wpas_notify_disconnect_reason(wpa_s);
2018 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2019 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2020 wpa_s->keys_cleared = 0;
2021 wpa_clear_keys(wpa_s, wpa_s->bssid);
2023 last_ssid = wpa_s->current_ssid;
2024 wpa_supplicant_mark_disassoc(wpa_s);
2026 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2027 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2028 wpa_s->current_ssid = last_ssid;
2031 if (fast_reconnect) {
2032 #ifndef CONFIG_NO_SCAN_PROCESSING
2033 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2034 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2035 fast_reconnect_ssid) < 0) {
2036 /* Recover through full scan */
2037 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2039 #endif /* CONFIG_NO_SCAN_PROCESSING */
2044 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2045 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2047 struct wpa_supplicant *wpa_s = eloop_ctx;
2049 if (!wpa_s->pending_mic_error_report)
2052 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2053 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2054 wpa_s->pending_mic_error_report = 0;
2056 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2060 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2061 union wpa_event_data *data)
2066 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2067 pairwise = (data && data->michael_mic_failure.unicast);
2069 if ((wpa_s->last_michael_mic_error &&
2070 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2071 wpa_s->pending_mic_error_report) {
2072 if (wpa_s->pending_mic_error_report) {
2074 * Send the pending MIC error report immediately since
2075 * we are going to start countermeasures and AP better
2078 wpa_sm_key_request(wpa_s->wpa, 1,
2079 wpa_s->pending_mic_error_pairwise);
2082 /* Send the new MIC error report immediately since we are going
2083 * to start countermeasures and AP better do the same.
2085 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2087 /* initialize countermeasures */
2088 wpa_s->countermeasures = 1;
2090 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2092 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2095 * Need to wait for completion of request frame. We do not get
2096 * any callback for the message completion, so just wait a
2097 * short while and hope for the best. */
2100 wpa_drv_set_countermeasures(wpa_s, 1);
2101 wpa_supplicant_deauthenticate(wpa_s,
2102 WLAN_REASON_MICHAEL_MIC_FAILURE);
2103 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2105 eloop_register_timeout(60, 0,
2106 wpa_supplicant_stop_countermeasures,
2108 /* TODO: mark the AP rejected for 60 second. STA is
2109 * allowed to associate with another AP.. */
2111 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2112 if (wpa_s->mic_errors_seen) {
2114 * Reduce the effectiveness of Michael MIC error
2115 * reports as a means for attacking against TKIP if
2116 * more than one MIC failure is noticed with the same
2117 * PTK. We delay the transmission of the reports by a
2118 * random time between 0 and 60 seconds in order to
2119 * force the attacker wait 60 seconds before getting
2120 * the information on whether a frame resulted in a MIC
2126 if (os_get_random(rval, sizeof(rval)) < 0)
2127 sec = os_random() % 60;
2129 sec = WPA_GET_BE32(rval) % 60;
2130 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2131 "report %d seconds", sec);
2132 wpa_s->pending_mic_error_report = 1;
2133 wpa_s->pending_mic_error_pairwise = pairwise;
2134 eloop_cancel_timeout(
2135 wpa_supplicant_delayed_mic_error_report,
2137 eloop_register_timeout(
2138 sec, os_random() % 1000000,
2139 wpa_supplicant_delayed_mic_error_report,
2142 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2144 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2145 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2146 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2148 wpa_s->last_michael_mic_error = t.sec;
2149 wpa_s->mic_errors_seen++;
2153 #ifdef CONFIG_TERMINATE_ONLASTIF
2154 static int any_interfaces(struct wpa_supplicant *head)
2156 struct wpa_supplicant *wpa_s;
2158 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2159 if (!wpa_s->interface_removed)
2163 #endif /* CONFIG_TERMINATE_ONLASTIF */
2167 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2168 union wpa_event_data *data)
2170 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2173 switch (data->interface_status.ievent) {
2174 case EVENT_INTERFACE_ADDED:
2175 if (!wpa_s->interface_removed)
2177 wpa_s->interface_removed = 0;
2178 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2179 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2180 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2181 "driver after interface was added");
2183 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2185 case EVENT_INTERFACE_REMOVED:
2186 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2187 wpa_s->interface_removed = 1;
2188 wpa_supplicant_mark_disassoc(wpa_s);
2189 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2190 l2_packet_deinit(wpa_s->l2);
2192 #ifdef CONFIG_IBSS_RSN
2193 ibss_rsn_deinit(wpa_s->ibss_rsn);
2194 wpa_s->ibss_rsn = NULL;
2195 #endif /* CONFIG_IBSS_RSN */
2196 #ifdef CONFIG_TERMINATE_ONLASTIF
2197 /* check if last interface */
2198 if (!any_interfaces(wpa_s->global->ifaces))
2200 #endif /* CONFIG_TERMINATE_ONLASTIF */
2206 #ifdef CONFIG_PEERKEY
2208 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2209 union wpa_event_data *data)
2213 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2215 #endif /* CONFIG_PEERKEY */
2219 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2220 union wpa_event_data *data)
2224 switch (data->tdls.oper) {
2225 case TDLS_REQUEST_SETUP:
2226 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2227 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2228 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2230 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2232 case TDLS_REQUEST_TEARDOWN:
2233 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2234 data->tdls.reason_code);
2238 #endif /* CONFIG_TDLS */
2242 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2243 union wpa_event_data *data)
2247 switch (data->wnm.oper) {
2248 case WNM_OPER_SLEEP:
2249 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2250 "(action=%d, intval=%d)",
2251 data->wnm.sleep_action, data->wnm.sleep_intval);
2252 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2253 data->wnm.sleep_intval, NULL);
2257 #endif /* CONFIG_WNM */
2260 #ifdef CONFIG_IEEE80211R
2262 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2263 union wpa_event_data *data)
2268 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2269 data->ft_ies.ies_len,
2270 data->ft_ies.ft_action,
2271 data->ft_ies.target_ap,
2272 data->ft_ies.ric_ies,
2273 data->ft_ies.ric_ies_len) < 0) {
2274 /* TODO: prevent MLME/driver from trying to associate? */
2277 #endif /* CONFIG_IEEE80211R */
2280 #ifdef CONFIG_IBSS_RSN
2281 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2282 union wpa_event_data *data)
2284 struct wpa_ssid *ssid;
2285 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2289 ssid = wpa_s->current_ssid;
2292 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2295 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2297 #endif /* CONFIG_IBSS_RSN */
2300 #ifdef CONFIG_IEEE80211R
2301 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2304 const u8 *sta_addr, *target_ap_addr;
2307 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2308 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2309 return; /* only SME case supported for now */
2310 if (len < 1 + 2 * ETH_ALEN + 2)
2313 return; /* Only FT Action Response is supported for now */
2314 sta_addr = data + 1;
2315 target_ap_addr = data + 1 + ETH_ALEN;
2316 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2317 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2318 MACSTR " TargetAP " MACSTR " status %u",
2319 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2321 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2322 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2323 " in FT Action Response", MAC2STR(sta_addr));
2328 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2329 "failure (status code %d)", status);
2330 /* TODO: report error to FT code(?) */
2334 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2335 len - (1 + 2 * ETH_ALEN + 2), 1,
2336 target_ap_addr, NULL, 0) < 0)
2341 struct wpa_bss *bss;
2342 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2344 wpa_s->sme.freq = bss->freq;
2345 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2346 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2349 #endif /* CONFIG_SME */
2351 #endif /* CONFIG_IEEE80211R */
2354 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2355 struct unprot_deauth *e)
2357 #ifdef CONFIG_IEEE80211W
2358 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2359 "dropped: " MACSTR " -> " MACSTR
2360 " (reason code %u)",
2361 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2362 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2363 #endif /* CONFIG_IEEE80211W */
2367 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2368 struct unprot_disassoc *e)
2370 #ifdef CONFIG_IEEE80211W
2371 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2372 "dropped: " MACSTR " -> " MACSTR
2373 " (reason code %u)",
2374 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2375 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2376 #endif /* CONFIG_IEEE80211W */
2380 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2381 union wpa_event_data *data)
2383 struct wpa_supplicant *wpa_s = ctx;
2384 u16 reason_code = 0;
2385 int locally_generated = 0;
2387 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2388 event != EVENT_INTERFACE_ENABLED &&
2389 event != EVENT_INTERFACE_STATUS &&
2390 event != EVENT_SCHED_SCAN_STOPPED) {
2391 wpa_dbg(wpa_s, MSG_DEBUG,
2392 "Ignore event %s (%d) while interface is disabled",
2393 event_to_string(event), event);
2397 #ifndef CONFIG_NO_STDOUT_DEBUG
2399 int level = MSG_DEBUG;
2401 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2402 const struct ieee80211_hdr *hdr;
2404 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2405 fc = le_to_host16(hdr->frame_control);
2406 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2407 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2408 level = MSG_EXCESSIVE;
2411 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2412 event_to_string(event), event);
2414 #endif /* CONFIG_NO_STDOUT_DEBUG */
2418 sme_event_auth(wpa_s, data);
2421 wpa_supplicant_event_assoc(wpa_s, data);
2423 case EVENT_DISASSOC:
2424 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2426 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2427 data->disassoc_info.reason_code,
2428 data->disassoc_info.locally_generated ?
2429 " (locally generated)" : "");
2430 if (data->disassoc_info.addr)
2431 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2432 MAC2STR(data->disassoc_info.addr));
2435 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2436 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2437 data->disassoc_info.addr);
2440 if (wpa_s->ap_iface) {
2441 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2445 #endif /* CONFIG_AP */
2447 reason_code = data->disassoc_info.reason_code;
2449 data->disassoc_info.locally_generated;
2450 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2451 data->disassoc_info.ie,
2452 data->disassoc_info.ie_len);
2454 wpas_p2p_disassoc_notif(
2455 wpa_s, data->disassoc_info.addr, reason_code,
2456 data->disassoc_info.ie,
2457 data->disassoc_info.ie_len,
2459 #endif /* CONFIG_P2P */
2461 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2462 sme_event_disassoc(wpa_s, data);
2465 if (event == EVENT_DEAUTH) {
2466 wpa_dbg(wpa_s, MSG_DEBUG,
2467 "Deauthentication notification");
2469 reason_code = data->deauth_info.reason_code;
2471 data->deauth_info.locally_generated;
2472 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2473 data->deauth_info.reason_code,
2474 data->deauth_info.locally_generated ?
2475 " (locally generated)" : "");
2476 if (data->deauth_info.addr) {
2477 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2479 MAC2STR(data->deauth_info.
2482 wpa_hexdump(MSG_DEBUG,
2483 "Deauthentication frame IE(s)",
2484 data->deauth_info.ie,
2485 data->deauth_info.ie_len);
2487 wpa_reset_ft_completed(wpa_s->wpa);
2490 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2491 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2492 data->deauth_info.addr);
2495 if (wpa_s->ap_iface) {
2496 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2500 #endif /* CONFIG_AP */
2501 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2503 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2504 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2505 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2506 eapol_sm_failed(wpa_s->eapol)))
2507 wpas_auth_failed(wpa_s);
2509 if (event == EVENT_DEAUTH && data) {
2510 if (wpas_p2p_deauth_notif(wpa_s,
2511 data->deauth_info.addr,
2513 data->deauth_info.ie,
2514 data->deauth_info.ie_len,
2515 locally_generated) > 0) {
2517 * The interface was removed, so cannot
2518 * continue processing any additional
2519 * operations after this.
2524 #endif /* CONFIG_P2P */
2525 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2528 case EVENT_MICHAEL_MIC_FAILURE:
2529 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2531 #ifndef CONFIG_NO_SCAN_PROCESSING
2532 case EVENT_SCAN_RESULTS:
2533 wpa_supplicant_event_scan_results(wpa_s, data);
2534 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2535 wpa_s->wpa_state != WPA_ASSOCIATING)
2536 wpas_p2p_continue_after_scan(wpa_s);
2538 #endif /* CONFIG_NO_SCAN_PROCESSING */
2539 case EVENT_ASSOCINFO:
2540 wpa_supplicant_event_associnfo(wpa_s, data);
2542 case EVENT_INTERFACE_STATUS:
2543 wpa_supplicant_event_interface_status(wpa_s, data);
2545 case EVENT_PMKID_CANDIDATE:
2546 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2548 #ifdef CONFIG_PEERKEY
2549 case EVENT_STKSTART:
2550 wpa_supplicant_event_stkstart(wpa_s, data);
2552 #endif /* CONFIG_PEERKEY */
2555 wpa_supplicant_event_tdls(wpa_s, data);
2557 #endif /* CONFIG_TDLS */
2560 wpa_supplicant_event_wnm(wpa_s, data);
2562 #endif /* CONFIG_WNM */
2563 #ifdef CONFIG_IEEE80211R
2564 case EVENT_FT_RESPONSE:
2565 wpa_supplicant_event_ft_response(wpa_s, data);
2567 #endif /* CONFIG_IEEE80211R */
2568 #ifdef CONFIG_IBSS_RSN
2569 case EVENT_IBSS_RSN_START:
2570 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2572 #endif /* CONFIG_IBSS_RSN */
2573 case EVENT_ASSOC_REJECT:
2574 if (data->assoc_reject.bssid)
2575 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2576 "bssid=" MACSTR " status_code=%u",
2577 MAC2STR(data->assoc_reject.bssid),
2578 data->assoc_reject.status_code);
2580 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2582 data->assoc_reject.status_code);
2583 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2584 sme_event_assoc_reject(wpa_s, data);
2586 const u8 *bssid = data->assoc_reject.bssid;
2587 if (bssid == NULL || is_zero_ether_addr(bssid))
2588 bssid = wpa_s->pending_bssid;
2589 wpas_connection_failed(wpa_s, bssid);
2590 wpa_supplicant_mark_disassoc(wpa_s);
2593 case EVENT_AUTH_TIMED_OUT:
2594 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2595 sme_event_auth_timed_out(wpa_s, data);
2597 case EVENT_ASSOC_TIMED_OUT:
2598 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2599 sme_event_assoc_timed_out(wpa_s, data);
2601 case EVENT_TX_STATUS:
2602 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2603 " type=%d stype=%d",
2604 MAC2STR(data->tx_status.dst),
2605 data->tx_status.type, data->tx_status.stype);
2607 if (wpa_s->ap_iface == NULL) {
2608 #ifdef CONFIG_OFFCHANNEL
2609 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2610 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2611 offchannel_send_action_tx_status(
2612 wpa_s, data->tx_status.dst,
2613 data->tx_status.data,
2614 data->tx_status.data_len,
2615 data->tx_status.ack ?
2616 OFFCHANNEL_SEND_ACTION_SUCCESS :
2617 OFFCHANNEL_SEND_ACTION_NO_ACK);
2618 #endif /* CONFIG_OFFCHANNEL */
2621 #endif /* CONFIG_AP */
2622 #ifdef CONFIG_OFFCHANNEL
2623 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2624 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2626 * Catch TX status events for Action frames we sent via group
2627 * interface in GO mode.
2629 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2630 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2631 os_memcmp(wpa_s->parent->pending_action_dst,
2632 data->tx_status.dst, ETH_ALEN) == 0) {
2633 offchannel_send_action_tx_status(
2634 wpa_s->parent, data->tx_status.dst,
2635 data->tx_status.data,
2636 data->tx_status.data_len,
2637 data->tx_status.ack ?
2638 OFFCHANNEL_SEND_ACTION_SUCCESS :
2639 OFFCHANNEL_SEND_ACTION_NO_ACK);
2642 #endif /* CONFIG_OFFCHANNEL */
2644 switch (data->tx_status.type) {
2645 case WLAN_FC_TYPE_MGMT:
2646 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2647 data->tx_status.data_len,
2648 data->tx_status.stype,
2649 data->tx_status.ack);
2651 case WLAN_FC_TYPE_DATA:
2652 ap_tx_status(wpa_s, data->tx_status.dst,
2653 data->tx_status.data,
2654 data->tx_status.data_len,
2655 data->tx_status.ack);
2658 #endif /* CONFIG_AP */
2661 case EVENT_EAPOL_TX_STATUS:
2662 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2663 data->eapol_tx_status.data,
2664 data->eapol_tx_status.data_len,
2665 data->eapol_tx_status.ack);
2667 case EVENT_DRIVER_CLIENT_POLL_OK:
2668 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2670 case EVENT_RX_FROM_UNKNOWN:
2671 if (wpa_s->ap_iface == NULL)
2673 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2674 data->rx_from_unknown.wds);
2676 case EVENT_CH_SWITCH:
2679 if (!wpa_s->ap_iface) {
2680 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2681 "event in non-AP mode");
2686 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2687 data->ch_switch.ht_enabled,
2688 data->ch_switch.ch_offset);
2689 #endif /* CONFIG_AP */
2691 case EVENT_RX_MGMT: {
2693 const struct ieee80211_mgmt *mgmt;
2695 mgmt = (const struct ieee80211_mgmt *)
2696 data->rx_mgmt.frame;
2697 fc = le_to_host16(mgmt->frame_control);
2698 stype = WLAN_FC_GET_STYPE(fc);
2700 if (wpa_s->ap_iface == NULL) {
2702 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2703 data->rx_mgmt.frame_len > 24) {
2704 const u8 *src = mgmt->sa;
2705 const u8 *ie = mgmt->u.probe_req.variable;
2706 size_t ie_len = data->rx_mgmt.frame_len -
2707 (mgmt->u.probe_req.variable -
2708 data->rx_mgmt.frame);
2709 wpas_p2p_probe_req_rx(
2710 wpa_s, src, mgmt->da,
2711 mgmt->bssid, ie, ie_len,
2712 data->rx_mgmt.ssi_signal);
2715 #endif /* CONFIG_P2P */
2716 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2717 "management frame in non-AP mode");
2721 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2722 data->rx_mgmt.frame_len > 24) {
2723 const u8 *ie = mgmt->u.probe_req.variable;
2724 size_t ie_len = data->rx_mgmt.frame_len -
2725 (mgmt->u.probe_req.variable -
2726 data->rx_mgmt.frame);
2728 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2729 mgmt->bssid, ie, ie_len,
2730 data->rx_mgmt.ssi_signal);
2733 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2736 #endif /* CONFIG_AP */
2737 case EVENT_RX_ACTION:
2738 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2739 " Category=%u DataLen=%d freq=%d MHz",
2740 MAC2STR(data->rx_action.sa),
2741 data->rx_action.category, (int) data->rx_action.len,
2742 data->rx_action.freq);
2743 #ifdef CONFIG_IEEE80211R
2744 if (data->rx_action.category == WLAN_ACTION_FT) {
2745 ft_rx_action(wpa_s, data->rx_action.data,
2746 data->rx_action.len);
2749 #endif /* CONFIG_IEEE80211R */
2750 #ifdef CONFIG_IEEE80211W
2752 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2753 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2754 data->rx_action.data,
2755 data->rx_action.len);
2758 #endif /* CONFIG_SME */
2759 #endif /* CONFIG_IEEE80211W */
2761 if (data->rx_action.category == WLAN_ACTION_WNM) {
2762 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2765 #endif /* CONFIG_WNM */
2767 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2768 gas_query_rx(wpa_s->gas, data->rx_action.da,
2769 data->rx_action.sa, data->rx_action.bssid,
2770 data->rx_action.data, data->rx_action.len,
2771 data->rx_action.freq) == 0)
2773 #endif /* CONFIG_GAS */
2775 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2776 data->rx_action.len >= 4 &&
2777 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2778 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2779 "Response from " MACSTR,
2780 MAC2STR(data->rx_action.sa));
2783 #endif /* CONFIG_TDLS */
2785 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2787 data->rx_action.bssid,
2788 data->rx_action.category,
2789 data->rx_action.data,
2790 data->rx_action.len, data->rx_action.freq);
2791 #endif /* CONFIG_P2P */
2793 case EVENT_RX_PROBE_REQ:
2794 if (data->rx_probe_req.sa == NULL ||
2795 data->rx_probe_req.ie == NULL)
2798 if (wpa_s->ap_iface) {
2799 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2800 data->rx_probe_req.sa,
2801 data->rx_probe_req.da,
2802 data->rx_probe_req.bssid,
2803 data->rx_probe_req.ie,
2804 data->rx_probe_req.ie_len,
2805 data->rx_probe_req.ssi_signal);
2808 #endif /* CONFIG_AP */
2810 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2811 data->rx_probe_req.da,
2812 data->rx_probe_req.bssid,
2813 data->rx_probe_req.ie,
2814 data->rx_probe_req.ie_len,
2815 data->rx_probe_req.ssi_signal);
2816 #endif /* CONFIG_P2P */
2818 case EVENT_REMAIN_ON_CHANNEL:
2819 #ifdef CONFIG_OFFCHANNEL
2820 offchannel_remain_on_channel_cb(
2821 wpa_s, data->remain_on_channel.freq,
2822 data->remain_on_channel.duration);
2823 #endif /* CONFIG_OFFCHANNEL */
2825 wpas_p2p_remain_on_channel_cb(
2826 wpa_s, data->remain_on_channel.freq,
2827 data->remain_on_channel.duration);
2828 #endif /* CONFIG_P2P */
2830 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2831 #ifdef CONFIG_OFFCHANNEL
2832 offchannel_cancel_remain_on_channel_cb(
2833 wpa_s, data->remain_on_channel.freq);
2834 #endif /* CONFIG_OFFCHANNEL */
2836 wpas_p2p_cancel_remain_on_channel_cb(
2837 wpa_s, data->remain_on_channel.freq);
2838 #endif /* CONFIG_P2P */
2841 case EVENT_P2P_DEV_FOUND: {
2842 struct p2p_peer_info peer_info;
2844 os_memset(&peer_info, 0, sizeof(peer_info));
2845 if (data->p2p_dev_found.dev_addr)
2846 os_memcpy(peer_info.p2p_device_addr,
2847 data->p2p_dev_found.dev_addr, ETH_ALEN);
2848 if (data->p2p_dev_found.pri_dev_type)
2849 os_memcpy(peer_info.pri_dev_type,
2850 data->p2p_dev_found.pri_dev_type,
2851 sizeof(peer_info.pri_dev_type));
2852 if (data->p2p_dev_found.dev_name)
2853 os_strlcpy(peer_info.device_name,
2854 data->p2p_dev_found.dev_name,
2855 sizeof(peer_info.device_name));
2856 peer_info.config_methods = data->p2p_dev_found.config_methods;
2857 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2858 peer_info.group_capab = data->p2p_dev_found.group_capab;
2861 * FIX: new_device=1 is not necessarily correct. We should
2862 * maintain a P2P peer database in wpa_supplicant and update
2863 * this information based on whether the peer is truly new.
2865 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2868 case EVENT_P2P_GO_NEG_REQ_RX:
2869 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2870 data->p2p_go_neg_req_rx.dev_passwd_id);
2872 case EVENT_P2P_GO_NEG_COMPLETED:
2873 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2875 case EVENT_P2P_PROV_DISC_REQUEST:
2876 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2877 data->p2p_prov_disc_req.config_methods,
2878 data->p2p_prov_disc_req.dev_addr,
2879 data->p2p_prov_disc_req.pri_dev_type,
2880 data->p2p_prov_disc_req.dev_name,
2881 data->p2p_prov_disc_req.supp_config_methods,
2882 data->p2p_prov_disc_req.dev_capab,
2883 data->p2p_prov_disc_req.group_capab,
2886 case EVENT_P2P_PROV_DISC_RESPONSE:
2887 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2888 data->p2p_prov_disc_resp.config_methods);
2890 case EVENT_P2P_SD_REQUEST:
2891 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2892 data->p2p_sd_req.sa,
2893 data->p2p_sd_req.dialog_token,
2894 data->p2p_sd_req.update_indic,
2895 data->p2p_sd_req.tlvs,
2896 data->p2p_sd_req.tlvs_len);
2898 case EVENT_P2P_SD_RESPONSE:
2899 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2900 data->p2p_sd_resp.update_indic,
2901 data->p2p_sd_resp.tlvs,
2902 data->p2p_sd_resp.tlvs_len);
2904 #endif /* CONFIG_P2P */
2905 case EVENT_EAPOL_RX:
2906 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2907 data->eapol_rx.data,
2908 data->eapol_rx.data_len);
2910 case EVENT_SIGNAL_CHANGE:
2911 bgscan_notify_signal_change(
2912 wpa_s, data->signal_change.above_threshold,
2913 data->signal_change.current_signal,
2914 data->signal_change.current_noise,
2915 data->signal_change.current_txrate);
2917 case EVENT_INTERFACE_ENABLED:
2918 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2919 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2920 wpa_supplicant_update_mac_addr(wpa_s);
2922 if (!wpa_s->ap_iface) {
2923 wpa_supplicant_set_state(wpa_s,
2925 wpa_supplicant_req_scan(wpa_s, 0, 0);
2927 wpa_supplicant_set_state(wpa_s,
2929 #else /* CONFIG_AP */
2930 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2931 wpa_supplicant_req_scan(wpa_s, 0, 0);
2932 #endif /* CONFIG_AP */
2935 case EVENT_INTERFACE_DISABLED:
2936 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2937 wpa_supplicant_mark_disassoc(wpa_s);
2938 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2940 case EVENT_CHANNEL_LIST_CHANGED:
2941 if (wpa_s->drv_priv == NULL)
2942 break; /* Ignore event during drv initialization */
2944 free_hw_features(wpa_s);
2945 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2946 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2949 wpas_p2p_update_channel_list(wpa_s);
2950 #endif /* CONFIG_P2P */
2952 case EVENT_INTERFACE_UNAVAILABLE:
2954 wpas_p2p_interface_unavailable(wpa_s);
2955 #endif /* CONFIG_P2P */
2957 case EVENT_BEST_CHANNEL:
2958 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2960 data->best_chan.freq_24, data->best_chan.freq_5,
2961 data->best_chan.freq_overall);
2962 wpa_s->best_24_freq = data->best_chan.freq_24;
2963 wpa_s->best_5_freq = data->best_chan.freq_5;
2964 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2966 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2967 data->best_chan.freq_5,
2968 data->best_chan.freq_overall);
2969 #endif /* CONFIG_P2P */
2971 case EVENT_UNPROT_DEAUTH:
2972 wpa_supplicant_event_unprot_deauth(wpa_s,
2973 &data->unprot_deauth);
2975 case EVENT_UNPROT_DISASSOC:
2976 wpa_supplicant_event_unprot_disassoc(wpa_s,
2977 &data->unprot_disassoc);
2979 case EVENT_STATION_LOW_ACK:
2981 if (wpa_s->ap_iface && data)
2982 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2983 data->low_ack.addr);
2984 #endif /* CONFIG_AP */
2987 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2988 #endif /* CONFIG_TDLS */
2990 case EVENT_IBSS_PEER_LOST:
2991 #ifdef CONFIG_IBSS_RSN
2992 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2993 #endif /* CONFIG_IBSS_RSN */
2995 case EVENT_DRIVER_GTK_REKEY:
2996 if (os_memcmp(data->driver_gtk_rekey.bssid,
2997 wpa_s->bssid, ETH_ALEN))
3001 wpa_sm_update_replay_ctr(wpa_s->wpa,
3002 data->driver_gtk_rekey.replay_ctr);
3004 case EVENT_SCHED_SCAN_STOPPED:
3005 wpa_s->sched_scanning = 0;
3006 wpa_supplicant_notify_scanning(wpa_s, 0);
3008 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3012 * If we timed out, start a new sched scan to continue
3013 * searching for more SSIDs.
3015 if (wpa_s->sched_scan_timed_out)
3016 wpa_supplicant_req_sched_scan(wpa_s);
3018 case EVENT_WPS_BUTTON_PUSHED:
3020 wpas_wps_start_pbc(wpa_s, NULL, 0);
3021 #endif /* CONFIG_WPS */
3023 case EVENT_CONNECT_FAILED_REASON:
3025 if (!wpa_s->ap_iface || !data)
3027 hostapd_event_connect_failed_reason(
3028 wpa_s->ap_iface->bss[0],
3029 data->connect_failed_reason.addr,
3030 data->connect_failed_reason.code);
3031 #endif /* CONFIG_AP */
3034 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);