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);
160 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
161 os_memset(wpa_s->bssid, 0, ETH_ALEN);
162 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
164 wpa_s->sme.prev_bssid_set = 0;
165 #endif /* CONFIG_SME */
167 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
168 #endif /* CONFIG_P2P */
169 wpa_s->current_bss = NULL;
170 wpa_s->assoc_freq = 0;
171 #ifdef CONFIG_IEEE80211R
173 if (wpa_s->sme.ft_ies)
174 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
175 #endif /* CONFIG_SME */
176 #endif /* CONFIG_IEEE80211R */
179 wpas_notify_bssid_changed(wpa_s);
181 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
182 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
183 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
184 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
185 wpa_s->ap_ies_from_associnfo = 0;
186 wpa_s->current_ssid = NULL;
191 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
193 struct wpa_ie_data ie;
197 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
201 for (i = 0; i < ie.num_pmkid; i++) {
202 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
203 ie.pmkid + i * PMKID_LEN,
205 if (pmksa_set == 0) {
206 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
211 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
212 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
216 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
217 union wpa_event_data *data)
220 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
225 " index=%d preauth=%d",
226 MAC2STR(data->pmkid_candidate.bssid),
227 data->pmkid_candidate.index,
228 data->pmkid_candidate.preauth);
230 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
236 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
238 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
239 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
242 #ifdef IEEE8021X_EAPOL
243 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
244 wpa_s->current_ssid &&
245 !(wpa_s->current_ssid->eapol_flags &
246 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
247 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
248 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
249 * plaintext or static WEP keys). */
252 #endif /* IEEE8021X_EAPOL */
259 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
260 * @wpa_s: pointer to wpa_supplicant data
261 * @ssid: Configuration data for the network
262 * Returns: 0 on success, -1 on failure
264 * This function is called when starting authentication with a network that is
265 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
267 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
268 struct wpa_ssid *ssid)
270 #ifdef IEEE8021X_EAPOL
272 int aka = 0, sim = 0, type;
274 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
277 if (ssid->eap.eap_methods == NULL) {
281 struct eap_method_type *eap = ssid->eap.eap_methods;
282 while (eap->vendor != EAP_VENDOR_IETF ||
283 eap->method != EAP_TYPE_NONE) {
284 if (eap->vendor == EAP_VENDOR_IETF) {
285 if (eap->method == EAP_TYPE_SIM)
287 else if (eap->method == EAP_TYPE_AKA ||
288 eap->method == EAP_TYPE_AKA_PRIME)
295 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
297 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
298 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
303 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
304 "use SIM, but neither EAP-SIM nor EAP-AKA are "
309 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
310 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
312 type = SCARD_TRY_BOTH;
314 type = SCARD_USIM_ONLY;
316 type = SCARD_GSM_SIM_ONLY;
318 wpa_s->scard = scard_init(type, NULL);
319 if (wpa_s->scard == NULL) {
320 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
324 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
325 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
326 #endif /* PCSC_FUNCS */
327 #endif /* IEEE8021X_EAPOL */
333 #ifndef CONFIG_NO_SCAN_PROCESSING
334 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
335 struct wpa_ssid *ssid)
339 if (ssid->mixed_cell)
343 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
345 #endif /* CONFIG_WPS */
347 for (i = 0; i < NUM_WEP_KEYS; i++) {
348 if (ssid->wep_key_len[i]) {
353 #ifdef IEEE8021X_EAPOL
354 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
355 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
356 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
358 #endif /* IEEE8021X_EAPOL */
360 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
363 if (bss->caps & IEEE80211_CAP_PRIVACY)
369 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
370 struct wpa_ssid *ssid,
373 struct wpa_ie_data ie;
375 const u8 *rsn_ie, *wpa_ie;
379 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
383 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
384 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
385 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
386 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
387 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
389 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
390 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
393 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
394 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
400 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
402 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
407 if (!(ie.proto & ssid->proto)) {
408 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
413 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
414 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
419 if (!(ie.group_cipher & ssid->group_cipher)) {
420 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
425 if (!(ie.key_mgmt & ssid->key_mgmt)) {
426 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
431 #ifdef CONFIG_IEEE80211W
432 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
433 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
434 wpa_s->conf->pmf : ssid->ieee80211w) ==
435 MGMT_FRAME_PROTECTION_REQUIRED) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
440 #endif /* CONFIG_IEEE80211W */
442 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
446 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
447 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
450 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
451 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
457 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
459 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
464 if (!(ie.proto & ssid->proto)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
470 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
476 if (!(ie.group_cipher & ssid->group_cipher)) {
477 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
482 if (!(ie.key_mgmt & ssid->key_mgmt)) {
483 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
488 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
492 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
494 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
498 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
499 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
500 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
504 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
505 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
509 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
516 static int freq_allowed(int *freqs, int freq)
523 for (i = 0; freqs[i]; i++)
524 if (freqs[i] == freq)
530 static int ht_supported(const struct hostapd_hw_modes *mode)
532 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
534 * The driver did not indicate whether it supports HT. Assume
535 * it does to avoid connection issues.
541 * IEEE Std 802.11n-2009 20.1.1:
542 * An HT non-AP STA shall support all EQM rates for one spatial stream.
544 return mode->mcs_set[0] == 0xff;
548 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
550 const struct hostapd_hw_modes *mode = NULL, *modes;
551 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
556 return 1; /* Cannot do matching without knowing band */
558 modes = wpa_s->hw.modes;
561 * The driver does not provide any additional information
562 * about the utilized hardware, so allow the connection attempt
568 for (i = 0; i < wpa_s->hw.num_modes; i++) {
569 for (j = 0; j < modes[i].num_channels; j++) {
570 int freq = modes[i].channels[j].freq;
571 if (freq == bss->freq) {
573 mode->mode == HOSTAPD_MODE_IEEE80211G)
574 break; /* do not allow 802.11b replace
585 for (i = 0; i < (int) sizeof(scan_ie); i++) {
586 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
590 for (j = 2; j < rate_ie[1] + 2; j++) {
591 int flagged = !!(rate_ie[j] & 0x80);
592 int r = (rate_ie[j] & 0x7f) * 5;
595 * IEEE Std 802.11n-2009 7.3.2.2:
596 * The new BSS Membership selector value is encoded
597 * like a legacy basic rate, but it is not a rate and
598 * only indicates if the BSS members are required to
599 * support the mandatory features of Clause 20 [HT PHY]
600 * in order to join the BSS.
602 if (flagged && ((rate_ie[j] & 0x7f) ==
603 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
604 if (!ht_supported(mode)) {
605 wpa_dbg(wpa_s, MSG_DEBUG,
606 " hardware does not support "
616 /* check for legacy basic rates */
617 for (k = 0; k < mode->num_rates; k++) {
618 if (mode->rates[k] == r)
621 if (k == mode->num_rates) {
623 * IEEE Std 802.11-2007 7.3.2.2 demands that in
624 * order to join a BSS all required rates
625 * have to be supported by the hardware.
627 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
628 "not support required rate %d.%d Mbps",
639 static int bss_is_dmg(struct wpa_bss *bss)
641 return bss->freq > 45000;
646 * Test whether BSS is in an ESS.
647 * This is done differently in DMG (60 GHz) and non-DMG bands
649 static int bss_is_ess(struct wpa_bss *bss)
651 if (bss_is_dmg(bss)) {
652 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
653 IEEE80211_CAP_DMG_AP;
656 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
661 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
662 int i, struct wpa_bss *bss,
663 struct wpa_ssid *group)
665 u8 wpa_ie_len, rsn_ie_len;
667 struct wpa_blacklist *e;
669 struct wpa_ssid *ssid;
671 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
672 wpa_ie_len = ie ? ie[1] : 0;
674 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
675 rsn_ie_len = ie ? ie[1] : 0;
677 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
678 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
679 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
680 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
681 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
683 e = wpa_blacklist_get(wpa_s, bss->bssid);
686 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
688 * When only a single network is enabled, we can
689 * trigger blacklisting on the first failure. This
690 * should not be done with multiple enabled networks to
691 * avoid getting forced to move into a worse ESS on
692 * single error if there are no other BSSes of the
697 if (e->count > limit) {
698 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
699 "(count=%d limit=%d)", e->count, limit);
704 if (bss->ssid_len == 0) {
705 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
709 if (disallowed_bssid(wpa_s, bss->bssid)) {
710 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
714 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
715 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
719 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
721 for (ssid = group; ssid; ssid = ssid->pnext) {
722 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
725 if (wpas_network_disabled(wpa_s, ssid)) {
726 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
730 res = wpas_temp_disabled(wpa_s, ssid);
732 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
733 "temporarily for %d second(s)", res);
738 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
739 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
744 if (wpa && ssid->ssid_len == 0 &&
745 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
748 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
749 /* Only allow wildcard SSID match if an AP
750 * advertises active WPS operation that matches
753 if (ssid->ssid_len == 0 &&
754 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
757 #endif /* CONFIG_WPS */
759 if (ssid->bssid_set && ssid->ssid_len == 0 &&
760 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
764 (bss->ssid_len != ssid->ssid_len ||
765 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
766 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
770 if (ssid->bssid_set &&
771 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
772 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
776 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
780 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
781 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
782 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
783 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
788 if (!wpa_supplicant_match_privacy(bss, ssid)) {
789 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
794 if (!bss_is_ess(bss)) {
795 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
799 if (!freq_allowed(ssid->freq_list, bss->freq)) {
800 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
805 if (!rate_match(wpa_s, bss)) {
806 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
813 * TODO: skip the AP if its P2P IE has Group Formation
814 * bit set in the P2P Group Capability Bitmap and we
815 * are not in Group Formation with that device.
817 #endif /* CONFIG_P2P */
819 /* Matching configuration found */
823 /* No matching configuration found */
828 static struct wpa_bss *
829 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
830 struct wpa_ssid *group,
831 struct wpa_ssid **selected_ssid)
835 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
838 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
839 struct wpa_bss *bss = wpa_s->last_scan_res[i];
840 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
843 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
846 wpa_ssid_txt(bss->ssid, bss->ssid_len));
854 static struct wpa_bss *
855 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 */
930 * Do not trigger new association unless the BSSID has changed or if
931 * reassociation is requested. If we are in process of associating with
932 * the selected BSSID, do not trigger new attempt.
934 if (wpa_s->reassociate ||
935 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
936 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
937 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
938 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
940 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
941 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
944 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
945 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
946 " pending: " MACSTR " wpa_state: %s",
947 wpa_s->reassociate, MAC2STR(selected->bssid),
948 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
949 wpa_supplicant_state_txt(wpa_s->wpa_state));
950 wpa_supplicant_associate(wpa_s, selected, ssid);
952 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
960 static struct wpa_ssid *
961 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
964 struct wpa_ssid *ssid;
966 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
967 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
969 if (wpas_network_disabled(wpa_s, ssid))
971 if (ssid->mode == IEEE80211_MODE_IBSS ||
972 ssid->mode == IEEE80211_MODE_AP)
980 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
981 * on BSS added and BSS changed events */
982 static void wpa_supplicant_rsn_preauth_scan_results(
983 struct wpa_supplicant *wpa_s)
987 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
990 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
991 const u8 *ssid, *rsn;
993 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
997 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1001 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1007 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1008 struct wpa_bss *selected,
1009 struct wpa_ssid *ssid)
1011 struct wpa_bss *current_bss = NULL;
1014 if (wpa_s->reassociate)
1015 return 1; /* explicit request to reassociate */
1016 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1017 return 1; /* we are not associated; continue */
1018 if (wpa_s->current_ssid == NULL)
1019 return 1; /* unknown current SSID */
1020 if (wpa_s->current_ssid != ssid)
1021 return 1; /* different network block */
1023 if (wpas_driver_bss_selection(wpa_s))
1024 return 0; /* Driver-based roaming */
1026 if (wpa_s->current_ssid->ssid)
1027 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1028 wpa_s->current_ssid->ssid,
1029 wpa_s->current_ssid->ssid_len);
1031 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1034 return 1; /* current BSS not seen in scan results */
1036 if (current_bss == selected)
1039 if (selected->last_update_idx > current_bss->last_update_idx)
1040 return 1; /* current BSS not seen in the last scan */
1042 #ifndef CONFIG_NO_ROAMING
1043 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1044 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1045 MAC2STR(current_bss->bssid), current_bss->level);
1046 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1047 MAC2STR(selected->bssid), selected->level);
1049 if (wpa_s->current_ssid->bssid_set &&
1050 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1052 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1053 "has preferred BSSID");
1057 if (current_bss->level < 0 && current_bss->level > selected->level) {
1058 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1064 if (current_bss->level < 0) {
1065 if (current_bss->level < -85)
1067 else if (current_bss->level < -80)
1069 else if (current_bss->level < -75)
1071 else if (current_bss->level < -70)
1076 if (abs(current_bss->level - selected->level) < min_diff) {
1077 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1083 #else /* CONFIG_NO_ROAMING */
1085 #endif /* CONFIG_NO_ROAMING */
1089 /* Return != 0 if no scan results could be fetched or if scan results should not
1090 * be shared with other virtual interfaces. */
1091 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1092 union wpa_event_data *data)
1094 struct wpa_scan_results *scan_res;
1096 #ifndef CONFIG_NO_RANDOM_POOL
1098 #endif /* CONFIG_NO_RANDOM_POOL */
1101 if (wpa_s->ap_iface)
1103 #endif /* CONFIG_AP */
1105 wpa_supplicant_notify_scanning(wpa_s, 0);
1108 if (wpa_s->global->p2p_cb_on_scan_complete &&
1109 !wpa_s->global->p2p_disabled &&
1110 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1111 !wpa_s->scan_res_handler) {
1112 wpa_s->global->p2p_cb_on_scan_complete = 0;
1113 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1114 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1115 "stopped scan processing");
1116 wpa_s->sta_scan_pending = 1;
1117 wpa_supplicant_req_scan(wpa_s, 5, 0);
1121 wpa_s->sta_scan_pending = 0;
1122 #endif /* CONFIG_P2P */
1124 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1125 data ? &data->scan_info :
1127 if (scan_res == NULL) {
1128 if (wpa_s->conf->ap_scan == 2 || ap ||
1129 wpa_s->scan_res_handler == scan_only_handler)
1131 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1133 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1137 #ifndef CONFIG_NO_RANDOM_POOL
1138 num = scan_res->num;
1141 for (i = 0; i < num; i++) {
1143 struct wpa_scan_res *res = scan_res->res[i];
1144 buf[0] = res->bssid[5];
1145 buf[1] = res->qual & 0xff;
1146 buf[2] = res->noise & 0xff;
1147 buf[3] = res->level & 0xff;
1148 buf[4] = res->tsf & 0xff;
1149 random_add_randomness(buf, sizeof(buf));
1151 #endif /* CONFIG_NO_RANDOM_POOL */
1153 if (wpa_s->scan_res_handler) {
1154 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1155 struct wpa_scan_results *scan_res);
1157 scan_res_handler = wpa_s->scan_res_handler;
1158 wpa_s->scan_res_handler = NULL;
1159 scan_res_handler(wpa_s, scan_res);
1161 wpa_scan_results_free(scan_res);
1166 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1168 if (wpa_s->ap_iface->scan_cb)
1169 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1170 #endif /* CONFIG_AP */
1171 wpa_scan_results_free(scan_res);
1175 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1176 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1177 wpas_notify_scan_results(wpa_s);
1179 wpas_notify_scan_done(wpa_s, 1);
1181 if (sme_proc_obss_scan(wpa_s) > 0) {
1182 wpa_scan_results_free(scan_res);
1186 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1187 wpa_scan_results_free(scan_res);
1191 if (autoscan_notify_scan(wpa_s, scan_res)) {
1192 wpa_scan_results_free(scan_res);
1196 if (wpa_s->disconnected) {
1197 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1198 wpa_scan_results_free(scan_res);
1202 if (!wpas_driver_bss_selection(wpa_s) &&
1203 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1204 wpa_scan_results_free(scan_res);
1208 wpas_wps_update_ap_info(wpa_s, scan_res);
1210 wpa_scan_results_free(scan_res);
1212 return wpas_select_network_from_last_scan(wpa_s);
1216 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1218 struct wpa_bss *selected;
1219 struct wpa_ssid *ssid = NULL;
1221 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1225 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1227 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1231 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1235 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1237 * Do not notify other virtual radios of scan results since we do not
1238 * want them to start other associations at the same time.
1242 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1243 ssid = wpa_supplicant_pick_new_network(wpa_s);
1245 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1246 wpa_supplicant_associate(wpa_s, NULL, ssid);
1247 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1249 int timeout_sec = wpa_s->scan_interval;
1250 int timeout_usec = 0;
1252 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1255 if (wpa_s->p2p_in_provisioning) {
1257 * Use shorter wait during P2P Provisioning
1258 * state to speed up group formation.
1261 timeout_usec = 250000;
1262 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1266 #endif /* CONFIG_P2P */
1267 #ifdef CONFIG_INTERWORKING
1268 if (wpa_s->conf->auto_interworking &&
1269 wpa_s->conf->interworking &&
1270 wpa_s->conf->cred) {
1271 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1272 "start ANQP fetch since no matching "
1274 wpa_s->network_select = 1;
1275 wpa_s->auto_network_select = 1;
1276 interworking_start_fetch_anqp(wpa_s);
1279 #endif /* CONFIG_INTERWORKING */
1280 if (wpa_supplicant_req_sched_scan(wpa_s))
1281 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1289 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1290 union wpa_event_data *data)
1292 const char *rn, *rn2;
1293 struct wpa_supplicant *ifs;
1295 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1297 * If no scan results could be fetched, then no need to
1298 * notify those interfaces that did not actually request
1299 * this scan. Similarly, if scan results started a new operation on this
1300 * interface, do not notify other interfaces to avoid concurrent
1301 * operations during a connection attempt.
1307 * Check other interfaces to see if they have the same radio-name. If
1308 * so, they get updated with this same scan info.
1310 if (!wpa_s->driver->get_radio_name)
1313 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1314 if (rn == NULL || rn[0] == '\0')
1317 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1318 "sharing same radio (%s) in event_scan_results", rn);
1320 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1321 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1324 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1325 if (rn2 && os_strcmp(rn, rn2) == 0) {
1326 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1327 "sibling", ifs->ifname);
1328 _wpa_supplicant_event_scan_results(ifs, data);
1333 #endif /* CONFIG_NO_SCAN_PROCESSING */
1336 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1338 #ifdef CONFIG_NO_SCAN_PROCESSING
1340 #else /* CONFIG_NO_SCAN_PROCESSING */
1343 if (wpa_s->last_scan_res_used <= 0)
1347 if (now.sec - wpa_s->last_scan.sec > 5) {
1348 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1352 return wpas_select_network_from_last_scan(wpa_s);
1353 #endif /* CONFIG_NO_SCAN_PROCESSING */
1358 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1360 struct wpa_supplicant *wpa_s = eloop_ctx;
1362 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1365 if (!wpa_s->no_keep_alive) {
1366 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1367 MAC2STR(wpa_s->bssid));
1368 /* TODO: could skip this if normal data traffic has been sent */
1369 /* TODO: Consider using some more appropriate data frame for
1372 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1377 if (wpa_s->sme.bss_max_idle_period) {
1379 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1382 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1383 wnm_bss_keep_alive, wpa_s, NULL);
1385 #endif /* CONFIG_SME */
1389 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1390 const u8 *ies, size_t ies_len)
1392 struct ieee802_11_elems elems;
1397 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1401 if (elems.bss_max_idle_period) {
1403 wpa_s->sme.bss_max_idle_period =
1404 WPA_GET_LE16(elems.bss_max_idle_period);
1405 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1406 "TU)%s", wpa_s->sme.bss_max_idle_period,
1407 (elems.bss_max_idle_period[2] & 0x01) ?
1408 " (protected keep-live required)" : "");
1409 if (wpa_s->sme.bss_max_idle_period == 0)
1410 wpa_s->sme.bss_max_idle_period = 1;
1411 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1412 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1413 /* msec times 1000 */
1414 msec = wpa_s->sme.bss_max_idle_period * 1024;
1417 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1418 wnm_bss_keep_alive, wpa_s,
1422 #endif /* CONFIG_SME */
1425 #endif /* CONFIG_WNM */
1428 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1431 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1432 #endif /* CONFIG_WNM */
1436 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1437 union wpa_event_data *data)
1439 int l, len, found = 0, wpa_found, rsn_found;
1442 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1443 if (data->assoc_info.req_ies)
1444 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1445 data->assoc_info.req_ies_len);
1446 if (data->assoc_info.resp_ies) {
1447 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1448 data->assoc_info.resp_ies_len);
1450 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1451 data->assoc_info.resp_ies_len);
1452 #endif /* CONFIG_TDLS */
1454 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1455 data->assoc_info.resp_ies_len);
1456 #endif /* CONFIG_WNM */
1458 if (data->assoc_info.beacon_ies)
1459 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1460 data->assoc_info.beacon_ies,
1461 data->assoc_info.beacon_ies_len);
1462 if (data->assoc_info.freq)
1463 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1464 data->assoc_info.freq);
1466 p = data->assoc_info.req_ies;
1467 l = data->assoc_info.req_ies_len;
1469 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1470 while (p && l >= 2) {
1473 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1477 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1478 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1479 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1480 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1483 wpa_find_assoc_pmkid(wpa_s);
1489 if (!found && data->assoc_info.req_ies)
1490 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1492 #ifdef CONFIG_IEEE80211R
1494 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1496 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1497 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1498 data->assoc_info.resp_ies,
1499 data->assoc_info.resp_ies_len,
1501 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1502 "Reassociation Response failed");
1503 wpa_supplicant_deauthenticate(
1504 wpa_s, WLAN_REASON_INVALID_IE);
1509 p = data->assoc_info.resp_ies;
1510 l = data->assoc_info.resp_ies_len;
1512 #ifdef CONFIG_WPS_STRICT
1513 if (p && wpa_s->current_ssid &&
1514 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1516 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1518 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1519 "include WPS IE in (Re)Association Response");
1523 if (wps_validate_assoc_resp(wps) < 0) {
1525 wpa_supplicant_deauthenticate(
1526 wpa_s, WLAN_REASON_INVALID_IE);
1531 #endif /* CONFIG_WPS_STRICT */
1533 /* Go through the IEs and make a copy of the MDIE, if present. */
1534 while (p && l >= 2) {
1537 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1541 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1542 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1543 wpa_s->sme.ft_used = 1;
1544 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1545 MOBILITY_DOMAIN_ID_LEN);
1551 #endif /* CONFIG_SME */
1553 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1554 data->assoc_info.resp_ies_len);
1555 #endif /* CONFIG_IEEE80211R */
1557 /* WPA/RSN IE from Beacon/ProbeResp */
1558 p = data->assoc_info.beacon_ies;
1559 l = data->assoc_info.beacon_ies_len;
1561 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1563 wpa_found = rsn_found = 0;
1564 while (p && l >= 2) {
1567 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1572 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1573 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1575 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1579 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1581 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1588 if (!wpa_found && data->assoc_info.beacon_ies)
1589 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1590 if (!rsn_found && data->assoc_info.beacon_ies)
1591 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1592 if (wpa_found || rsn_found)
1593 wpa_s->ap_ies_from_associnfo = 1;
1595 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1596 wpa_s->assoc_freq != data->assoc_info.freq) {
1597 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1599 wpa_s->assoc_freq, data->assoc_info.freq);
1600 wpa_supplicant_update_scan_results(wpa_s);
1603 wpa_s->assoc_freq = data->assoc_info.freq;
1609 static struct wpa_bss * wpa_supplicant_get_new_bss(
1610 struct wpa_supplicant *wpa_s, const u8 *bssid)
1612 struct wpa_bss *bss = NULL;
1613 struct wpa_ssid *ssid = wpa_s->current_ssid;
1615 if (ssid->ssid_len > 0)
1616 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1618 bss = wpa_bss_get_bssid(wpa_s, bssid);
1624 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1626 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1628 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1631 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1634 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1635 WPA_IE_VENDOR_TYPE);
1636 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1638 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1639 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1640 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1641 bss_rsn ? 2 + bss_rsn[1] : 0))
1648 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1649 union wpa_event_data *data)
1653 struct wpa_driver_capa capa;
1656 if (wpa_s->ap_iface) {
1657 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1658 data->assoc_info.addr,
1659 data->assoc_info.req_ies,
1660 data->assoc_info.req_ies_len,
1661 data->assoc_info.reassoc);
1664 #endif /* CONFIG_AP */
1666 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1667 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1670 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1671 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1672 wpa_supplicant_deauthenticate(
1673 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1677 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1678 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1679 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1680 MACSTR, MAC2STR(bssid));
1681 random_add_randomness(bssid, ETH_ALEN);
1682 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1683 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1684 wpas_notify_bssid_changed(wpa_s);
1686 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1687 wpa_clear_keys(wpa_s, bssid);
1689 if (wpa_supplicant_select_config(wpa_s) < 0) {
1690 wpa_supplicant_deauthenticate(
1691 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1694 if (wpa_s->current_ssid) {
1695 struct wpa_bss *bss = NULL;
1697 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1699 wpa_supplicant_update_scan_results(wpa_s);
1701 /* Get the BSS from the new scan results */
1702 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1706 wpa_s->current_bss = bss;
1709 if (wpa_s->conf->ap_scan == 1 &&
1710 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1711 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1712 wpa_msg(wpa_s, MSG_WARNING,
1713 "WPA/RSN IEs not updated");
1718 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1719 wpa_s->sme.prev_bssid_set = 1;
1720 #endif /* CONFIG_SME */
1722 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1723 if (wpa_s->current_ssid) {
1724 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1725 * initialized before association, but for other modes,
1726 * initialize PC/SC here, if the current configuration needs
1727 * smartcard or SIM/USIM. */
1728 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1730 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1732 l2_packet_notify_auth_start(wpa_s->l2);
1735 * Set portEnabled first to FALSE in order to get EAP state machine out
1736 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1737 * state machine may transit to AUTHENTICATING state based on obsolete
1738 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1739 * AUTHENTICATED without ever giving chance to EAP state machine to
1742 if (!ft_completed) {
1743 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1744 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1746 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1747 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1748 /* 802.1X::portControl = Auto */
1749 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1750 wpa_s->eapol_received = 0;
1751 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1752 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1753 (wpa_s->current_ssid &&
1754 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1755 wpa_supplicant_cancel_auth_timeout(wpa_s);
1756 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1757 } else if (!ft_completed) {
1758 /* Timeout for receiving the first EAPOL packet */
1759 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1761 wpa_supplicant_cancel_scan(wpa_s);
1763 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1764 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1766 * We are done; the driver will take care of RSN 4-way
1769 wpa_supplicant_cancel_auth_timeout(wpa_s);
1770 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1771 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1772 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1773 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1774 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1776 * The driver will take care of RSN 4-way handshake, so we need
1777 * to allow EAPOL supplicant to complete its work without
1778 * waiting for WPA supplicant.
1780 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1781 } else if (ft_completed) {
1783 * FT protocol completed - make sure EAPOL state machine ends
1784 * up in authenticated.
1786 wpa_supplicant_cancel_auth_timeout(wpa_s);
1787 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1788 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1789 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1792 wpa_s->last_eapol_matches_bssid = 0;
1794 if (wpa_s->pending_eapol_rx) {
1795 struct os_time now, age;
1797 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1798 if (age.sec == 0 && age.usec < 100000 &&
1799 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1801 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1802 "frame that was received just before "
1803 "association notification");
1804 wpa_supplicant_rx_eapol(
1805 wpa_s, wpa_s->pending_eapol_rx_src,
1806 wpabuf_head(wpa_s->pending_eapol_rx),
1807 wpabuf_len(wpa_s->pending_eapol_rx));
1809 wpabuf_free(wpa_s->pending_eapol_rx);
1810 wpa_s->pending_eapol_rx = NULL;
1813 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1814 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1815 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1816 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1817 /* Set static WEP keys again */
1818 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1821 #ifdef CONFIG_IBSS_RSN
1822 if (wpa_s->current_ssid &&
1823 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1824 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1825 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1826 wpa_s->ibss_rsn == NULL) {
1827 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1828 if (!wpa_s->ibss_rsn) {
1829 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1830 wpa_supplicant_deauthenticate(
1831 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1835 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1837 #endif /* CONFIG_IBSS_RSN */
1839 wpas_wps_notify_assoc(wpa_s, bssid);
1843 static int disconnect_reason_recoverable(u16 reason_code)
1845 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1846 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1847 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1851 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1853 int locally_generated)
1857 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1859 * At least Host AP driver and a Prism3 card seemed to be
1860 * generating streams of disconnected events when configuring
1861 * IBSS for WPA-None. Ignore them for now.
1866 bssid = wpa_s->bssid;
1867 if (is_zero_ether_addr(bssid))
1868 bssid = wpa_s->pending_bssid;
1870 if (!is_zero_ether_addr(bssid) ||
1871 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1872 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1874 MAC2STR(bssid), reason_code,
1875 locally_generated ? " locally_generated=1" : "");
1880 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1881 int locally_generated)
1883 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1884 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1885 return 0; /* Not in 4-way handshake with PSK */
1888 * It looks like connection was lost while trying to go through PSK
1889 * 4-way handshake. Filter out known disconnection cases that are caused
1890 * by something else than PSK mismatch to avoid confusing reports.
1893 if (locally_generated) {
1894 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1902 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1904 int locally_generated)
1908 u8 prev_pending_bssid[ETH_ALEN];
1909 struct wpa_bss *fast_reconnect = NULL;
1910 struct wpa_ssid *fast_reconnect_ssid = NULL;
1911 struct wpa_ssid *last_ssid;
1913 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1914 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1916 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1918 * At least Host AP driver and a Prism3 card seemed to be
1919 * generating streams of disconnected events when configuring
1920 * IBSS for WPA-None. Ignore them for now.
1922 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1923 "IBSS/WPA-None mode");
1927 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1928 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1929 "pre-shared key may be incorrect");
1930 wpas_auth_failed(wpa_s);
1932 if (!wpa_s->auto_reconnect_disabled ||
1933 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1934 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1935 "reconnect (wps=%d wpa_state=%d)",
1936 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1938 if (wpa_s->wpa_state == WPA_COMPLETED &&
1939 wpa_s->current_ssid &&
1940 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1941 !locally_generated &&
1942 disconnect_reason_recoverable(reason_code)) {
1944 * It looks like the AP has dropped association with
1945 * us, but could allow us to get back in. Try to
1946 * reconnect to the same BSS without full scan to save
1947 * time for some common cases.
1949 fast_reconnect = wpa_s->current_bss;
1950 fast_reconnect_ssid = wpa_s->current_ssid;
1951 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1952 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1954 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1957 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1958 "try to re-connect");
1959 wpa_s->reassociate = 0;
1960 wpa_s->disconnected = 1;
1961 wpa_supplicant_cancel_sched_scan(wpa_s);
1963 bssid = wpa_s->bssid;
1964 if (is_zero_ether_addr(bssid))
1965 bssid = wpa_s->pending_bssid;
1966 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1967 wpas_connection_failed(wpa_s, bssid);
1968 wpa_sm_notify_disassoc(wpa_s->wpa);
1969 if (locally_generated)
1970 wpa_s->disconnect_reason = -reason_code;
1972 wpa_s->disconnect_reason = reason_code;
1973 wpas_notify_disconnect_reason(wpa_s);
1974 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1975 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1976 wpa_s->keys_cleared = 0;
1977 wpa_clear_keys(wpa_s, wpa_s->bssid);
1979 last_ssid = wpa_s->current_ssid;
1980 wpa_supplicant_mark_disassoc(wpa_s);
1982 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1983 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1984 wpa_s->current_ssid = last_ssid;
1987 if (fast_reconnect) {
1988 #ifndef CONFIG_NO_SCAN_PROCESSING
1989 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1990 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1991 fast_reconnect_ssid) < 0) {
1992 /* Recover through full scan */
1993 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1995 #endif /* CONFIG_NO_SCAN_PROCESSING */
2000 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2001 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2003 struct wpa_supplicant *wpa_s = eloop_ctx;
2005 if (!wpa_s->pending_mic_error_report)
2008 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2009 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2010 wpa_s->pending_mic_error_report = 0;
2012 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2016 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2017 union wpa_event_data *data)
2022 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2023 pairwise = (data && data->michael_mic_failure.unicast);
2025 if ((wpa_s->last_michael_mic_error &&
2026 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2027 wpa_s->pending_mic_error_report) {
2028 if (wpa_s->pending_mic_error_report) {
2030 * Send the pending MIC error report immediately since
2031 * we are going to start countermeasures and AP better
2034 wpa_sm_key_request(wpa_s->wpa, 1,
2035 wpa_s->pending_mic_error_pairwise);
2038 /* Send the new MIC error report immediately since we are going
2039 * to start countermeasures and AP better do the same.
2041 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2043 /* initialize countermeasures */
2044 wpa_s->countermeasures = 1;
2046 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2048 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2051 * Need to wait for completion of request frame. We do not get
2052 * any callback for the message completion, so just wait a
2053 * short while and hope for the best. */
2056 wpa_drv_set_countermeasures(wpa_s, 1);
2057 wpa_supplicant_deauthenticate(wpa_s,
2058 WLAN_REASON_MICHAEL_MIC_FAILURE);
2059 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2061 eloop_register_timeout(60, 0,
2062 wpa_supplicant_stop_countermeasures,
2064 /* TODO: mark the AP rejected for 60 second. STA is
2065 * allowed to associate with another AP.. */
2067 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2068 if (wpa_s->mic_errors_seen) {
2070 * Reduce the effectiveness of Michael MIC error
2071 * reports as a means for attacking against TKIP if
2072 * more than one MIC failure is noticed with the same
2073 * PTK. We delay the transmission of the reports by a
2074 * random time between 0 and 60 seconds in order to
2075 * force the attacker wait 60 seconds before getting
2076 * the information on whether a frame resulted in a MIC
2082 if (os_get_random(rval, sizeof(rval)) < 0)
2083 sec = os_random() % 60;
2085 sec = WPA_GET_BE32(rval) % 60;
2086 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2087 "report %d seconds", sec);
2088 wpa_s->pending_mic_error_report = 1;
2089 wpa_s->pending_mic_error_pairwise = pairwise;
2090 eloop_cancel_timeout(
2091 wpa_supplicant_delayed_mic_error_report,
2093 eloop_register_timeout(
2094 sec, os_random() % 1000000,
2095 wpa_supplicant_delayed_mic_error_report,
2098 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2100 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2101 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2102 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2104 wpa_s->last_michael_mic_error = t.sec;
2105 wpa_s->mic_errors_seen++;
2109 #ifdef CONFIG_TERMINATE_ONLASTIF
2110 static int any_interfaces(struct wpa_supplicant *head)
2112 struct wpa_supplicant *wpa_s;
2114 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2115 if (!wpa_s->interface_removed)
2119 #endif /* CONFIG_TERMINATE_ONLASTIF */
2123 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2124 union wpa_event_data *data)
2126 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2129 switch (data->interface_status.ievent) {
2130 case EVENT_INTERFACE_ADDED:
2131 if (!wpa_s->interface_removed)
2133 wpa_s->interface_removed = 0;
2134 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2135 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2136 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2137 "driver after interface was added");
2139 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2141 case EVENT_INTERFACE_REMOVED:
2142 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2143 wpa_s->interface_removed = 1;
2144 wpa_supplicant_mark_disassoc(wpa_s);
2145 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2146 l2_packet_deinit(wpa_s->l2);
2148 #ifdef CONFIG_IBSS_RSN
2149 ibss_rsn_deinit(wpa_s->ibss_rsn);
2150 wpa_s->ibss_rsn = NULL;
2151 #endif /* CONFIG_IBSS_RSN */
2152 #ifdef CONFIG_TERMINATE_ONLASTIF
2153 /* check if last interface */
2154 if (!any_interfaces(wpa_s->global->ifaces))
2156 #endif /* CONFIG_TERMINATE_ONLASTIF */
2162 #ifdef CONFIG_PEERKEY
2164 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2165 union wpa_event_data *data)
2169 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2171 #endif /* CONFIG_PEERKEY */
2175 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2176 union wpa_event_data *data)
2180 switch (data->tdls.oper) {
2181 case TDLS_REQUEST_SETUP:
2182 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2183 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2184 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2186 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2188 case TDLS_REQUEST_TEARDOWN:
2189 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2190 data->tdls.reason_code);
2194 #endif /* CONFIG_TDLS */
2198 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2199 union wpa_event_data *data)
2203 switch (data->wnm.oper) {
2204 case WNM_OPER_SLEEP:
2205 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2206 "(action=%d, intval=%d)",
2207 data->wnm.sleep_action, data->wnm.sleep_intval);
2208 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2209 data->wnm.sleep_intval, NULL);
2213 #endif /* CONFIG_WNM */
2216 #ifdef CONFIG_IEEE80211R
2218 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2219 union wpa_event_data *data)
2224 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2225 data->ft_ies.ies_len,
2226 data->ft_ies.ft_action,
2227 data->ft_ies.target_ap,
2228 data->ft_ies.ric_ies,
2229 data->ft_ies.ric_ies_len) < 0) {
2230 /* TODO: prevent MLME/driver from trying to associate? */
2233 #endif /* CONFIG_IEEE80211R */
2236 #ifdef CONFIG_IBSS_RSN
2237 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2238 union wpa_event_data *data)
2240 struct wpa_ssid *ssid;
2241 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2245 ssid = wpa_s->current_ssid;
2248 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2251 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2253 #endif /* CONFIG_IBSS_RSN */
2256 #ifdef CONFIG_IEEE80211R
2257 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2260 const u8 *sta_addr, *target_ap_addr;
2263 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2264 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2265 return; /* only SME case supported for now */
2266 if (len < 1 + 2 * ETH_ALEN + 2)
2269 return; /* Only FT Action Response is supported for now */
2270 sta_addr = data + 1;
2271 target_ap_addr = data + 1 + ETH_ALEN;
2272 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2273 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2274 MACSTR " TargetAP " MACSTR " status %u",
2275 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2277 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2278 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2279 " in FT Action Response", MAC2STR(sta_addr));
2284 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2285 "failure (status code %d)", status);
2286 /* TODO: report error to FT code(?) */
2290 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2291 len - (1 + 2 * ETH_ALEN + 2), 1,
2292 target_ap_addr, NULL, 0) < 0)
2297 struct wpa_bss *bss;
2298 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2300 wpa_s->sme.freq = bss->freq;
2301 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2302 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2305 #endif /* CONFIG_SME */
2307 #endif /* CONFIG_IEEE80211R */
2310 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2311 struct unprot_deauth *e)
2313 #ifdef CONFIG_IEEE80211W
2314 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2315 "dropped: " MACSTR " -> " MACSTR
2316 " (reason code %u)",
2317 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2318 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2319 #endif /* CONFIG_IEEE80211W */
2323 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2324 struct unprot_disassoc *e)
2326 #ifdef CONFIG_IEEE80211W
2327 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2328 "dropped: " MACSTR " -> " MACSTR
2329 " (reason code %u)",
2330 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2331 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2332 #endif /* CONFIG_IEEE80211W */
2336 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2337 union wpa_event_data *data)
2339 struct wpa_supplicant *wpa_s = ctx;
2340 u16 reason_code = 0;
2341 int locally_generated = 0;
2343 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2344 event != EVENT_INTERFACE_ENABLED &&
2345 event != EVENT_INTERFACE_STATUS &&
2346 event != EVENT_SCHED_SCAN_STOPPED) {
2347 wpa_dbg(wpa_s, MSG_DEBUG,
2348 "Ignore event %s (%d) while interface is disabled",
2349 event_to_string(event), event);
2353 #ifndef CONFIG_NO_STDOUT_DEBUG
2355 int level = MSG_DEBUG;
2357 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2358 const struct ieee80211_hdr *hdr;
2360 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2361 fc = le_to_host16(hdr->frame_control);
2362 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2363 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2364 level = MSG_EXCESSIVE;
2367 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2368 event_to_string(event), event);
2370 #endif /* CONFIG_NO_STDOUT_DEBUG */
2374 sme_event_auth(wpa_s, data);
2377 wpa_supplicant_event_assoc(wpa_s, data);
2379 case EVENT_DISASSOC:
2380 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2382 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2383 data->disassoc_info.reason_code,
2384 data->disassoc_info.locally_generated ?
2385 " (locally generated)" : "");
2386 if (data->disassoc_info.addr)
2387 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2388 MAC2STR(data->disassoc_info.addr));
2391 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2392 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2393 data->disassoc_info.addr);
2396 if (wpa_s->ap_iface) {
2397 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2401 #endif /* CONFIG_AP */
2403 reason_code = data->disassoc_info.reason_code;
2405 data->disassoc_info.locally_generated;
2406 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2407 data->disassoc_info.ie,
2408 data->disassoc_info.ie_len);
2410 wpas_p2p_disassoc_notif(
2411 wpa_s, data->disassoc_info.addr, reason_code,
2412 data->disassoc_info.ie,
2413 data->disassoc_info.ie_len,
2415 #endif /* CONFIG_P2P */
2417 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2418 sme_event_disassoc(wpa_s, data);
2421 if (event == EVENT_DEAUTH) {
2422 wpa_dbg(wpa_s, MSG_DEBUG,
2423 "Deauthentication notification");
2425 reason_code = data->deauth_info.reason_code;
2427 data->deauth_info.locally_generated;
2428 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2429 data->deauth_info.reason_code,
2430 data->deauth_info.locally_generated ?
2431 " (locally generated)" : "");
2432 if (data->deauth_info.addr) {
2433 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2435 MAC2STR(data->deauth_info.
2438 wpa_hexdump(MSG_DEBUG,
2439 "Deauthentication frame IE(s)",
2440 data->deauth_info.ie,
2441 data->deauth_info.ie_len);
2445 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2446 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2447 data->deauth_info.addr);
2450 if (wpa_s->ap_iface) {
2451 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2455 #endif /* CONFIG_AP */
2456 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2458 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2459 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2460 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2461 eapol_sm_failed(wpa_s->eapol)))
2462 wpas_auth_failed(wpa_s);
2464 if (event == EVENT_DEAUTH && data) {
2465 if (wpas_p2p_deauth_notif(wpa_s,
2466 data->deauth_info.addr,
2468 data->deauth_info.ie,
2469 data->deauth_info.ie_len,
2470 locally_generated) > 0) {
2472 * The interface was removed, so cannot
2473 * continue processing any additional
2474 * operations after this.
2479 #endif /* CONFIG_P2P */
2480 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2483 case EVENT_MICHAEL_MIC_FAILURE:
2484 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2486 #ifndef CONFIG_NO_SCAN_PROCESSING
2487 case EVENT_SCAN_RESULTS:
2488 wpa_supplicant_event_scan_results(wpa_s, data);
2490 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2491 wpa_s->global->p2p != NULL &&
2492 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2493 wpa_s->wpa_state != WPA_ASSOCIATING) {
2494 wpa_s->global->p2p_cb_on_scan_complete = 0;
2495 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2496 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2497 "continued after scan result processing");
2500 #endif /* CONFIG_P2P */
2502 #endif /* CONFIG_NO_SCAN_PROCESSING */
2503 case EVENT_ASSOCINFO:
2504 wpa_supplicant_event_associnfo(wpa_s, data);
2506 case EVENT_INTERFACE_STATUS:
2507 wpa_supplicant_event_interface_status(wpa_s, data);
2509 case EVENT_PMKID_CANDIDATE:
2510 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2512 #ifdef CONFIG_PEERKEY
2513 case EVENT_STKSTART:
2514 wpa_supplicant_event_stkstart(wpa_s, data);
2516 #endif /* CONFIG_PEERKEY */
2519 wpa_supplicant_event_tdls(wpa_s, data);
2521 #endif /* CONFIG_TDLS */
2524 wpa_supplicant_event_wnm(wpa_s, data);
2526 #endif /* CONFIG_WNM */
2527 #ifdef CONFIG_IEEE80211R
2528 case EVENT_FT_RESPONSE:
2529 wpa_supplicant_event_ft_response(wpa_s, data);
2531 #endif /* CONFIG_IEEE80211R */
2532 #ifdef CONFIG_IBSS_RSN
2533 case EVENT_IBSS_RSN_START:
2534 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2536 #endif /* CONFIG_IBSS_RSN */
2537 case EVENT_ASSOC_REJECT:
2538 if (data->assoc_reject.bssid)
2539 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2540 "bssid=" MACSTR " status_code=%u",
2541 MAC2STR(data->assoc_reject.bssid),
2542 data->assoc_reject.status_code);
2544 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2546 data->assoc_reject.status_code);
2547 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2548 sme_event_assoc_reject(wpa_s, data);
2550 const u8 *bssid = data->assoc_reject.bssid;
2551 if (bssid == NULL || is_zero_ether_addr(bssid))
2552 bssid = wpa_s->pending_bssid;
2553 wpas_connection_failed(wpa_s, bssid);
2554 wpa_supplicant_mark_disassoc(wpa_s);
2557 case EVENT_AUTH_TIMED_OUT:
2558 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2559 sme_event_auth_timed_out(wpa_s, data);
2561 case EVENT_ASSOC_TIMED_OUT:
2562 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2563 sme_event_assoc_timed_out(wpa_s, data);
2565 case EVENT_TX_STATUS:
2566 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2567 " type=%d stype=%d",
2568 MAC2STR(data->tx_status.dst),
2569 data->tx_status.type, data->tx_status.stype);
2571 if (wpa_s->ap_iface == NULL) {
2572 #ifdef CONFIG_OFFCHANNEL
2573 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2574 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2575 offchannel_send_action_tx_status(
2576 wpa_s, data->tx_status.dst,
2577 data->tx_status.data,
2578 data->tx_status.data_len,
2579 data->tx_status.ack ?
2580 OFFCHANNEL_SEND_ACTION_SUCCESS :
2581 OFFCHANNEL_SEND_ACTION_NO_ACK);
2582 #endif /* CONFIG_OFFCHANNEL */
2585 #endif /* CONFIG_AP */
2586 #ifdef CONFIG_OFFCHANNEL
2587 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2588 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2590 * Catch TX status events for Action frames we sent via group
2591 * interface in GO mode.
2593 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2594 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2595 os_memcmp(wpa_s->parent->pending_action_dst,
2596 data->tx_status.dst, ETH_ALEN) == 0) {
2597 offchannel_send_action_tx_status(
2598 wpa_s->parent, data->tx_status.dst,
2599 data->tx_status.data,
2600 data->tx_status.data_len,
2601 data->tx_status.ack ?
2602 OFFCHANNEL_SEND_ACTION_SUCCESS :
2603 OFFCHANNEL_SEND_ACTION_NO_ACK);
2606 #endif /* CONFIG_OFFCHANNEL */
2608 switch (data->tx_status.type) {
2609 case WLAN_FC_TYPE_MGMT:
2610 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2611 data->tx_status.data_len,
2612 data->tx_status.stype,
2613 data->tx_status.ack);
2615 case WLAN_FC_TYPE_DATA:
2616 ap_tx_status(wpa_s, data->tx_status.dst,
2617 data->tx_status.data,
2618 data->tx_status.data_len,
2619 data->tx_status.ack);
2622 #endif /* CONFIG_AP */
2625 case EVENT_EAPOL_TX_STATUS:
2626 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2627 data->eapol_tx_status.data,
2628 data->eapol_tx_status.data_len,
2629 data->eapol_tx_status.ack);
2631 case EVENT_DRIVER_CLIENT_POLL_OK:
2632 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2634 case EVENT_RX_FROM_UNKNOWN:
2635 if (wpa_s->ap_iface == NULL)
2637 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2638 data->rx_from_unknown.wds);
2640 case EVENT_CH_SWITCH:
2643 if (!wpa_s->ap_iface) {
2644 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2645 "event in non-AP mode");
2650 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2651 data->ch_switch.ht_enabled,
2652 data->ch_switch.ch_offset);
2653 #endif /* CONFIG_AP */
2655 case EVENT_RX_MGMT: {
2657 const struct ieee80211_mgmt *mgmt;
2659 mgmt = (const struct ieee80211_mgmt *)
2660 data->rx_mgmt.frame;
2661 fc = le_to_host16(mgmt->frame_control);
2662 stype = WLAN_FC_GET_STYPE(fc);
2664 if (wpa_s->ap_iface == NULL) {
2666 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2667 data->rx_mgmt.frame_len > 24) {
2668 const u8 *src = mgmt->sa;
2669 const u8 *ie = mgmt->u.probe_req.variable;
2670 size_t ie_len = data->rx_mgmt.frame_len -
2671 (mgmt->u.probe_req.variable -
2672 data->rx_mgmt.frame);
2673 wpas_p2p_probe_req_rx(
2674 wpa_s, src, mgmt->da,
2675 mgmt->bssid, ie, ie_len,
2676 data->rx_mgmt.ssi_signal);
2679 #endif /* CONFIG_P2P */
2680 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2681 "management frame in non-AP mode");
2685 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2686 data->rx_mgmt.frame_len > 24) {
2687 const u8 *ie = mgmt->u.probe_req.variable;
2688 size_t ie_len = data->rx_mgmt.frame_len -
2689 (mgmt->u.probe_req.variable -
2690 data->rx_mgmt.frame);
2692 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2693 mgmt->bssid, ie, ie_len,
2694 data->rx_mgmt.ssi_signal);
2697 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2700 #endif /* CONFIG_AP */
2701 case EVENT_RX_ACTION:
2702 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2703 " Category=%u DataLen=%d freq=%d MHz",
2704 MAC2STR(data->rx_action.sa),
2705 data->rx_action.category, (int) data->rx_action.len,
2706 data->rx_action.freq);
2707 #ifdef CONFIG_IEEE80211R
2708 if (data->rx_action.category == WLAN_ACTION_FT) {
2709 ft_rx_action(wpa_s, data->rx_action.data,
2710 data->rx_action.len);
2713 #endif /* CONFIG_IEEE80211R */
2714 #ifdef CONFIG_IEEE80211W
2716 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2717 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2718 data->rx_action.data,
2719 data->rx_action.len);
2722 #endif /* CONFIG_SME */
2723 #endif /* CONFIG_IEEE80211W */
2725 if (data->rx_action.category == WLAN_ACTION_WNM) {
2726 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2729 #endif /* CONFIG_WNM */
2731 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2732 gas_query_rx(wpa_s->gas, data->rx_action.da,
2733 data->rx_action.sa, data->rx_action.bssid,
2734 data->rx_action.data, data->rx_action.len,
2735 data->rx_action.freq) == 0)
2737 #endif /* CONFIG_GAS */
2739 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2740 data->rx_action.len >= 4 &&
2741 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2742 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2743 "Response from " MACSTR,
2744 MAC2STR(data->rx_action.sa));
2747 #endif /* CONFIG_TDLS */
2749 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2751 data->rx_action.bssid,
2752 data->rx_action.category,
2753 data->rx_action.data,
2754 data->rx_action.len, data->rx_action.freq);
2755 #endif /* CONFIG_P2P */
2757 case EVENT_RX_PROBE_REQ:
2758 if (data->rx_probe_req.sa == NULL ||
2759 data->rx_probe_req.ie == NULL)
2762 if (wpa_s->ap_iface) {
2763 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2764 data->rx_probe_req.sa,
2765 data->rx_probe_req.da,
2766 data->rx_probe_req.bssid,
2767 data->rx_probe_req.ie,
2768 data->rx_probe_req.ie_len,
2769 data->rx_probe_req.ssi_signal);
2772 #endif /* CONFIG_AP */
2774 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2775 data->rx_probe_req.da,
2776 data->rx_probe_req.bssid,
2777 data->rx_probe_req.ie,
2778 data->rx_probe_req.ie_len,
2779 data->rx_probe_req.ssi_signal);
2780 #endif /* CONFIG_P2P */
2782 case EVENT_REMAIN_ON_CHANNEL:
2783 #ifdef CONFIG_OFFCHANNEL
2784 offchannel_remain_on_channel_cb(
2785 wpa_s, data->remain_on_channel.freq,
2786 data->remain_on_channel.duration);
2787 #endif /* CONFIG_OFFCHANNEL */
2789 wpas_p2p_remain_on_channel_cb(
2790 wpa_s, data->remain_on_channel.freq,
2791 data->remain_on_channel.duration);
2792 #endif /* CONFIG_P2P */
2794 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2795 #ifdef CONFIG_OFFCHANNEL
2796 offchannel_cancel_remain_on_channel_cb(
2797 wpa_s, data->remain_on_channel.freq);
2798 #endif /* CONFIG_OFFCHANNEL */
2800 wpas_p2p_cancel_remain_on_channel_cb(
2801 wpa_s, data->remain_on_channel.freq);
2802 #endif /* CONFIG_P2P */
2805 case EVENT_P2P_DEV_FOUND: {
2806 struct p2p_peer_info peer_info;
2808 os_memset(&peer_info, 0, sizeof(peer_info));
2809 if (data->p2p_dev_found.dev_addr)
2810 os_memcpy(peer_info.p2p_device_addr,
2811 data->p2p_dev_found.dev_addr, ETH_ALEN);
2812 if (data->p2p_dev_found.pri_dev_type)
2813 os_memcpy(peer_info.pri_dev_type,
2814 data->p2p_dev_found.pri_dev_type,
2815 sizeof(peer_info.pri_dev_type));
2816 if (data->p2p_dev_found.dev_name)
2817 os_strlcpy(peer_info.device_name,
2818 data->p2p_dev_found.dev_name,
2819 sizeof(peer_info.device_name));
2820 peer_info.config_methods = data->p2p_dev_found.config_methods;
2821 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2822 peer_info.group_capab = data->p2p_dev_found.group_capab;
2825 * FIX: new_device=1 is not necessarily correct. We should
2826 * maintain a P2P peer database in wpa_supplicant and update
2827 * this information based on whether the peer is truly new.
2829 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2832 case EVENT_P2P_GO_NEG_REQ_RX:
2833 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2834 data->p2p_go_neg_req_rx.dev_passwd_id);
2836 case EVENT_P2P_GO_NEG_COMPLETED:
2837 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2839 case EVENT_P2P_PROV_DISC_REQUEST:
2840 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2841 data->p2p_prov_disc_req.config_methods,
2842 data->p2p_prov_disc_req.dev_addr,
2843 data->p2p_prov_disc_req.pri_dev_type,
2844 data->p2p_prov_disc_req.dev_name,
2845 data->p2p_prov_disc_req.supp_config_methods,
2846 data->p2p_prov_disc_req.dev_capab,
2847 data->p2p_prov_disc_req.group_capab,
2850 case EVENT_P2P_PROV_DISC_RESPONSE:
2851 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2852 data->p2p_prov_disc_resp.config_methods);
2854 case EVENT_P2P_SD_REQUEST:
2855 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2856 data->p2p_sd_req.sa,
2857 data->p2p_sd_req.dialog_token,
2858 data->p2p_sd_req.update_indic,
2859 data->p2p_sd_req.tlvs,
2860 data->p2p_sd_req.tlvs_len);
2862 case EVENT_P2P_SD_RESPONSE:
2863 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2864 data->p2p_sd_resp.update_indic,
2865 data->p2p_sd_resp.tlvs,
2866 data->p2p_sd_resp.tlvs_len);
2868 #endif /* CONFIG_P2P */
2869 case EVENT_EAPOL_RX:
2870 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2871 data->eapol_rx.data,
2872 data->eapol_rx.data_len);
2874 case EVENT_SIGNAL_CHANGE:
2875 bgscan_notify_signal_change(
2876 wpa_s, data->signal_change.above_threshold,
2877 data->signal_change.current_signal,
2878 data->signal_change.current_noise,
2879 data->signal_change.current_txrate);
2881 case EVENT_INTERFACE_ENABLED:
2882 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2883 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2884 wpa_supplicant_update_mac_addr(wpa_s);
2886 if (!wpa_s->ap_iface) {
2887 wpa_supplicant_set_state(wpa_s,
2889 wpa_supplicant_req_scan(wpa_s, 0, 0);
2891 wpa_supplicant_set_state(wpa_s,
2893 #else /* CONFIG_AP */
2894 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2895 wpa_supplicant_req_scan(wpa_s, 0, 0);
2896 #endif /* CONFIG_AP */
2899 case EVENT_INTERFACE_DISABLED:
2900 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2901 wpa_supplicant_mark_disassoc(wpa_s);
2902 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2904 case EVENT_CHANNEL_LIST_CHANGED:
2905 if (wpa_s->drv_priv == NULL)
2906 break; /* Ignore event during drv initialization */
2908 free_hw_features(wpa_s);
2909 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2910 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2913 wpas_p2p_update_channel_list(wpa_s);
2914 #endif /* CONFIG_P2P */
2916 case EVENT_INTERFACE_UNAVAILABLE:
2918 wpas_p2p_interface_unavailable(wpa_s);
2919 #endif /* CONFIG_P2P */
2921 case EVENT_BEST_CHANNEL:
2922 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2924 data->best_chan.freq_24, data->best_chan.freq_5,
2925 data->best_chan.freq_overall);
2926 wpa_s->best_24_freq = data->best_chan.freq_24;
2927 wpa_s->best_5_freq = data->best_chan.freq_5;
2928 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2930 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2931 data->best_chan.freq_5,
2932 data->best_chan.freq_overall);
2933 #endif /* CONFIG_P2P */
2935 case EVENT_UNPROT_DEAUTH:
2936 wpa_supplicant_event_unprot_deauth(wpa_s,
2937 &data->unprot_deauth);
2939 case EVENT_UNPROT_DISASSOC:
2940 wpa_supplicant_event_unprot_disassoc(wpa_s,
2941 &data->unprot_disassoc);
2943 case EVENT_STATION_LOW_ACK:
2945 if (wpa_s->ap_iface && data)
2946 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2947 data->low_ack.addr);
2948 #endif /* CONFIG_AP */
2951 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2952 #endif /* CONFIG_TDLS */
2954 case EVENT_IBSS_PEER_LOST:
2955 #ifdef CONFIG_IBSS_RSN
2956 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2957 #endif /* CONFIG_IBSS_RSN */
2959 case EVENT_DRIVER_GTK_REKEY:
2960 if (os_memcmp(data->driver_gtk_rekey.bssid,
2961 wpa_s->bssid, ETH_ALEN))
2965 wpa_sm_update_replay_ctr(wpa_s->wpa,
2966 data->driver_gtk_rekey.replay_ctr);
2968 case EVENT_SCHED_SCAN_STOPPED:
2969 wpa_s->sched_scanning = 0;
2970 wpa_supplicant_notify_scanning(wpa_s, 0);
2972 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2976 * If we timed out, start a new sched scan to continue
2977 * searching for more SSIDs.
2979 if (wpa_s->sched_scan_timed_out)
2980 wpa_supplicant_req_sched_scan(wpa_s);
2982 case EVENT_WPS_BUTTON_PUSHED:
2984 wpas_wps_start_pbc(wpa_s, NULL, 0);
2985 #endif /* CONFIG_WPS */
2987 case EVENT_CONNECT_FAILED_REASON:
2989 if (!wpa_s->ap_iface || !data)
2991 hostapd_event_connect_failed_reason(
2992 wpa_s->ap_iface->bss[0],
2993 data->connect_failed_reason.addr,
2994 data->connect_failed_reason.code);
2995 #endif /* CONFIG_AP */
2998 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);