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"
46 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
47 struct wpa_ssid *ssid)
51 if (ssid == NULL || ssid->disabled_until.sec == 0)
55 if (ssid->disabled_until.sec > now.sec)
56 return ssid->disabled_until.sec - now.sec;
58 wpas_clear_temp_disabled(wpa_s, ssid, 0);
64 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
66 struct wpa_ssid *ssid, *old_ssid;
69 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
72 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
74 ssid = wpa_supplicant_get_ssid(wpa_s);
76 wpa_msg(wpa_s, MSG_INFO,
77 "No network configuration found for the current AP");
81 if (wpas_network_disabled(wpa_s, ssid)) {
82 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
86 res = wpas_temp_disabled(wpa_s, ssid);
88 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
89 "disabled for %d second(s)", res);
93 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
95 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
97 size_t wpa_ie_len = sizeof(wpa_ie);
98 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
101 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
104 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
105 eapol_sm_invalidate_cached_session(wpa_s->eapol);
106 old_ssid = wpa_s->current_ssid;
107 wpa_s->current_ssid = ssid;
108 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
109 wpa_supplicant_initiate_eapol(wpa_s);
110 if (old_ssid != wpa_s->current_ssid)
111 wpas_notify_network_changed(wpa_s);
117 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
119 struct wpa_supplicant *wpa_s = eloop_ctx;
121 if (wpa_s->countermeasures) {
122 wpa_s->countermeasures = 0;
123 wpa_drv_set_countermeasures(wpa_s, 0);
124 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
130 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
134 wnm_bss_keep_alive_deinit(wpa_s);
136 #ifdef CONFIG_IBSS_RSN
137 ibss_rsn_deinit(wpa_s->ibss_rsn);
138 wpa_s->ibss_rsn = NULL;
139 #endif /* CONFIG_IBSS_RSN */
142 wpa_supplicant_ap_deinit(wpa_s);
143 #endif /* CONFIG_AP */
145 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
148 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
149 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
150 os_memset(wpa_s->bssid, 0, ETH_ALEN);
151 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
153 wpa_s->sme.prev_bssid_set = 0;
154 #endif /* CONFIG_SME */
156 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
157 #endif /* CONFIG_P2P */
158 wpa_s->current_bss = NULL;
159 wpa_s->assoc_freq = 0;
160 #ifdef CONFIG_IEEE80211R
162 if (wpa_s->sme.ft_ies)
163 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
164 #endif /* CONFIG_SME */
165 #endif /* CONFIG_IEEE80211R */
168 wpas_notify_bssid_changed(wpa_s);
170 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
171 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
172 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
173 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
174 wpa_s->ap_ies_from_associnfo = 0;
175 wpa_s->current_ssid = NULL;
180 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
182 struct wpa_ie_data ie;
186 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
190 for (i = 0; i < ie.num_pmkid; i++) {
191 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
192 ie.pmkid + i * PMKID_LEN,
194 if (pmksa_set == 0) {
195 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
200 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
201 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
205 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
206 union wpa_event_data *data)
209 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
213 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
214 " index=%d preauth=%d",
215 MAC2STR(data->pmkid_candidate.bssid),
216 data->pmkid_candidate.index,
217 data->pmkid_candidate.preauth);
219 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
220 data->pmkid_candidate.index,
221 data->pmkid_candidate.preauth);
225 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
227 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
228 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
231 #ifdef IEEE8021X_EAPOL
232 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
233 wpa_s->current_ssid &&
234 !(wpa_s->current_ssid->eapol_flags &
235 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
236 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
237 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
238 * plaintext or static WEP keys). */
241 #endif /* IEEE8021X_EAPOL */
248 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
249 * @wpa_s: pointer to wpa_supplicant data
250 * @ssid: Configuration data for the network
251 * Returns: 0 on success, -1 on failure
253 * This function is called when starting authentication with a network that is
254 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
256 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
257 struct wpa_ssid *ssid)
259 #ifdef IEEE8021X_EAPOL
261 int aka = 0, sim = 0, type;
263 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
266 if (ssid->eap.eap_methods == NULL) {
270 struct eap_method_type *eap = ssid->eap.eap_methods;
271 while (eap->vendor != EAP_VENDOR_IETF ||
272 eap->method != EAP_TYPE_NONE) {
273 if (eap->vendor == EAP_VENDOR_IETF) {
274 if (eap->method == EAP_TYPE_SIM)
276 else if (eap->method == EAP_TYPE_AKA ||
277 eap->method == EAP_TYPE_AKA_PRIME)
284 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
286 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
287 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
292 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
293 "use SIM, but neither EAP-SIM nor EAP-AKA are "
298 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
299 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
301 type = SCARD_TRY_BOTH;
303 type = SCARD_USIM_ONLY;
305 type = SCARD_GSM_SIM_ONLY;
307 wpa_s->scard = scard_init(type, NULL);
308 if (wpa_s->scard == NULL) {
309 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
313 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
314 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
315 #endif /* PCSC_FUNCS */
316 #endif /* IEEE8021X_EAPOL */
322 #ifndef CONFIG_NO_SCAN_PROCESSING
323 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
324 struct wpa_ssid *ssid)
328 if (ssid->mixed_cell)
332 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
334 #endif /* CONFIG_WPS */
336 for (i = 0; i < NUM_WEP_KEYS; i++) {
337 if (ssid->wep_key_len[i]) {
342 #ifdef IEEE8021X_EAPOL
343 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
344 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
345 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
347 #endif /* IEEE8021X_EAPOL */
349 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
352 if (bss->caps & IEEE80211_CAP_PRIVACY)
358 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
359 struct wpa_ssid *ssid,
360 struct wpa_scan_res *bss)
362 struct wpa_ie_data ie;
364 const u8 *rsn_ie, *wpa_ie;
368 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
372 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
373 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
374 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
375 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
376 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
378 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
379 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
382 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
383 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
389 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
391 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
396 if (!(ie.proto & ssid->proto)) {
397 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
402 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
403 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
408 if (!(ie.group_cipher & ssid->group_cipher)) {
409 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
414 if (!(ie.key_mgmt & ssid->key_mgmt)) {
415 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
420 #ifdef CONFIG_IEEE80211W
421 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
422 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
427 #endif /* CONFIG_IEEE80211W */
429 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
433 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
434 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
437 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
438 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
444 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
446 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
451 if (!(ie.proto & ssid->proto)) {
452 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
457 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
458 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
463 if (!(ie.group_cipher & ssid->group_cipher)) {
464 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
469 if (!(ie.key_mgmt & ssid->key_mgmt)) {
470 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
475 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
479 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
481 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
485 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
486 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
491 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
492 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
496 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
503 static int freq_allowed(int *freqs, int freq)
510 for (i = 0; freqs[i]; i++)
511 if (freqs[i] == freq)
517 static int ht_supported(const struct hostapd_hw_modes *mode)
519 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
521 * The driver did not indicate whether it supports HT. Assume
522 * it does to avoid connection issues.
528 * IEEE Std 802.11n-2009 20.1.1:
529 * An HT non-AP STA shall support all EQM rates for one spatial stream.
531 return mode->mcs_set[0] == 0xff;
535 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
537 const struct hostapd_hw_modes *mode = NULL, *modes;
538 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
543 return 1; /* Cannot do matching without knowing band */
545 modes = wpa_s->hw.modes;
548 * The driver does not provide any additional information
549 * about the utilized hardware, so allow the connection attempt
555 for (i = 0; i < wpa_s->hw.num_modes; i++) {
556 for (j = 0; j < modes[i].num_channels; j++) {
557 int freq = modes[i].channels[j].freq;
558 if (freq == bss->freq) {
560 mode->mode == HOSTAPD_MODE_IEEE80211G)
561 break; /* do not allow 802.11b replace
572 for (i = 0; i < (int) sizeof(scan_ie); i++) {
573 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
577 for (j = 2; j < rate_ie[1] + 2; j++) {
578 int flagged = !!(rate_ie[j] & 0x80);
579 int r = (rate_ie[j] & 0x7f) * 5;
582 * IEEE Std 802.11n-2009 7.3.2.2:
583 * The new BSS Membership selector value is encoded
584 * like a legacy basic rate, but it is not a rate and
585 * only indicates if the BSS members are required to
586 * support the mandatory features of Clause 20 [HT PHY]
587 * in order to join the BSS.
589 if (flagged && ((rate_ie[j] & 0x7f) ==
590 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
591 if (!ht_supported(mode)) {
592 wpa_dbg(wpa_s, MSG_DEBUG,
593 " hardware does not support "
603 /* check for legacy basic rates */
604 for (k = 0; k < mode->num_rates; k++) {
605 if (mode->rates[k] == r)
608 if (k == mode->num_rates) {
610 * IEEE Std 802.11-2007 7.3.2.2 demands that in
611 * order to join a BSS all required rates
612 * have to be supported by the hardware.
614 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
615 "not support required rate %d.%d Mbps",
626 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
627 int i, struct wpa_scan_res *bss,
628 struct wpa_ssid *group)
631 u8 wpa_ie_len, rsn_ie_len, ssid_len;
633 struct wpa_blacklist *e;
635 struct wpa_ssid *ssid;
637 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
638 ssid_ = ie ? ie + 2 : (u8 *) "";
639 ssid_len = ie ? ie[1] : 0;
641 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
642 wpa_ie_len = ie ? ie[1] : 0;
644 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
645 rsn_ie_len = ie ? ie[1] : 0;
647 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
648 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
649 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
650 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
651 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
653 e = wpa_blacklist_get(wpa_s, bss->bssid);
656 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
658 * When only a single network is enabled, we can
659 * trigger blacklisting on the first failure. This
660 * should not be done with multiple enabled networks to
661 * avoid getting forced to move into a worse ESS on
662 * single error if there are no other BSSes of the
667 if (e->count > limit) {
668 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
669 "(count=%d limit=%d)", e->count, limit);
675 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
679 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
681 for (ssid = group; ssid; ssid = ssid->pnext) {
682 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
685 if (wpas_network_disabled(wpa_s, ssid)) {
686 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
690 res = wpas_temp_disabled(wpa_s, ssid);
692 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
693 "temporarily for %d second(s)", res);
698 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
699 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
704 if (wpa && ssid->ssid_len == 0 &&
705 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
708 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
709 /* Only allow wildcard SSID match if an AP
710 * advertises active WPS operation that matches
713 if (ssid->ssid_len == 0 &&
714 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
717 #endif /* CONFIG_WPS */
719 if (ssid->bssid_set && ssid->ssid_len == 0 &&
720 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
724 (ssid_len != ssid->ssid_len ||
725 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
726 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
730 if (ssid->bssid_set &&
731 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
732 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
736 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
740 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
741 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
742 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
743 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
748 if (!wpa_supplicant_match_privacy(bss, ssid)) {
749 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
754 if (bss->caps & IEEE80211_CAP_IBSS) {
755 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
760 if (!freq_allowed(ssid->freq_list, bss->freq)) {
761 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
766 if (!rate_match(wpa_s, bss)) {
767 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
774 * TODO: skip the AP if its P2P IE has Group Formation
775 * bit set in the P2P Group Capability Bitmap and we
776 * are not in Group Formation with that device.
778 #endif /* CONFIG_P2P */
780 /* Matching configuration found */
784 /* No matching configuration found */
789 static struct wpa_bss *
790 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
791 struct wpa_scan_results *scan_res,
792 struct wpa_ssid *group,
793 struct wpa_ssid **selected_ssid)
797 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
800 for (i = 0; i < scan_res->num; i++) {
801 struct wpa_scan_res *bss = scan_res->res[i];
805 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
809 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
810 ssid = ie ? ie + 2 : (u8 *) "";
811 ssid_len = ie ? ie[1] : 0;
813 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
815 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
816 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
823 static struct wpa_bss *
824 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
825 struct wpa_scan_results *scan_res,
826 struct wpa_ssid **selected_ssid)
828 struct wpa_bss *selected = NULL;
831 while (selected == NULL) {
832 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
833 selected = wpa_supplicant_select_bss(
834 wpa_s, scan_res, wpa_s->conf->pssid[prio],
840 if (selected == NULL && wpa_s->blacklist &&
841 !wpa_s->countermeasures) {
842 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
843 "blacklist and try again");
844 wpa_blacklist_clear(wpa_s);
845 wpa_s->blacklist_cleared++;
846 } else if (selected == NULL)
854 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
855 int timeout_sec, int timeout_usec)
857 if (!wpa_supplicant_enabled_networks(wpa_s)) {
859 * No networks are enabled; short-circuit request so
860 * we don't wait timeout seconds before transitioning
863 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
866 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
870 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
871 struct wpa_bss *selected,
872 struct wpa_ssid *ssid)
874 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
875 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
876 "PBC session overlap");
878 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
880 #endif /* CONFIG_P2P */
883 wpas_wps_cancel(wpa_s);
884 #endif /* CONFIG_WPS */
889 * Do not trigger new association unless the BSSID has changed or if
890 * reassociation is requested. If we are in process of associating with
891 * the selected BSSID, do not trigger new attempt.
893 if (wpa_s->reassociate ||
894 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
895 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
896 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
897 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
899 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
900 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
903 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
904 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
905 " pending: " MACSTR " wpa_state: %s",
906 wpa_s->reassociate, MAC2STR(selected->bssid),
907 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
908 wpa_supplicant_state_txt(wpa_s->wpa_state));
909 wpa_supplicant_associate(wpa_s, selected, ssid);
911 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
919 static struct wpa_ssid *
920 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
923 struct wpa_ssid *ssid;
925 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
926 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
928 if (wpas_network_disabled(wpa_s, ssid))
930 if (ssid->mode == IEEE80211_MODE_IBSS ||
931 ssid->mode == IEEE80211_MODE_AP)
939 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
940 * on BSS added and BSS changed events */
941 static void wpa_supplicant_rsn_preauth_scan_results(
942 struct wpa_supplicant *wpa_s)
946 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
949 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
950 const u8 *ssid, *rsn;
952 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
956 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
960 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
966 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
967 struct wpa_bss *selected,
968 struct wpa_ssid *ssid,
969 struct wpa_scan_results *scan_res)
972 struct wpa_scan_res *current_bss = NULL;
975 if (wpa_s->reassociate)
976 return 1; /* explicit request to reassociate */
977 if (wpa_s->wpa_state < WPA_ASSOCIATED)
978 return 1; /* we are not associated; continue */
979 if (wpa_s->current_ssid == NULL)
980 return 1; /* unknown current SSID */
981 if (wpa_s->current_ssid != ssid)
982 return 1; /* different network block */
984 if (wpas_driver_bss_selection(wpa_s))
985 return 0; /* Driver-based roaming */
987 for (i = 0; i < scan_res->num; i++) {
988 struct wpa_scan_res *res = scan_res->res[i];
990 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
993 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
996 if (ie[1] != wpa_s->current_ssid->ssid_len ||
997 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
1004 return 1; /* current BSS not seen in scan results */
1006 #ifndef CONFIG_NO_ROAMING
1007 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1008 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1009 MAC2STR(current_bss->bssid), current_bss->level);
1010 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1011 MAC2STR(selected->bssid), selected->level);
1013 if (wpa_s->current_ssid->bssid_set &&
1014 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1016 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1017 "has preferred BSSID");
1022 if (current_bss->level < 0) {
1023 if (current_bss->level < -85)
1025 else if (current_bss->level < -80)
1027 else if (current_bss->level < -75)
1029 else if (current_bss->level < -70)
1034 if (abs(current_bss->level - selected->level) < min_diff) {
1035 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1041 #else /* CONFIG_NO_ROAMING */
1043 #endif /* CONFIG_NO_ROAMING */
1047 /* Return < 0 if no scan results could be fetched or if scan results should not
1048 * be shared with other virtual interfaces. */
1049 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1050 union wpa_event_data *data)
1052 struct wpa_bss *selected;
1053 struct wpa_ssid *ssid = NULL;
1054 struct wpa_scan_results *scan_res;
1058 if (wpa_s->ap_iface)
1060 #endif /* CONFIG_AP */
1062 wpa_supplicant_notify_scanning(wpa_s, 0);
1065 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1066 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
1067 wpa_s->p2p_cb_on_scan_complete = 0;
1068 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1069 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1070 "stopped scan processing");
1074 wpa_s->sta_scan_pending = 0;
1075 #endif /* CONFIG_P2P */
1077 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1078 data ? &data->scan_info :
1080 if (scan_res == NULL) {
1081 if (wpa_s->conf->ap_scan == 2 || ap)
1083 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1085 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1089 #ifndef CONFIG_NO_RANDOM_POOL
1091 num = scan_res->num;
1094 for (i = 0; i < num; i++) {
1096 struct wpa_scan_res *res = scan_res->res[i];
1097 buf[0] = res->bssid[5];
1098 buf[1] = res->qual & 0xff;
1099 buf[2] = res->noise & 0xff;
1100 buf[3] = res->level & 0xff;
1101 buf[4] = res->tsf & 0xff;
1102 random_add_randomness(buf, sizeof(buf));
1104 #endif /* CONFIG_NO_RANDOM_POOL */
1106 if (wpa_s->scan_res_handler) {
1107 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1108 struct wpa_scan_results *scan_res);
1110 scan_res_handler = wpa_s->scan_res_handler;
1111 wpa_s->scan_res_handler = NULL;
1112 scan_res_handler(wpa_s, scan_res);
1114 wpa_scan_results_free(scan_res);
1119 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1121 if (wpa_s->ap_iface->scan_cb)
1122 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1123 #endif /* CONFIG_AP */
1124 wpa_scan_results_free(scan_res);
1128 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1129 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1130 wpas_notify_scan_results(wpa_s);
1132 wpas_notify_scan_done(wpa_s, 1);
1134 if (sme_proc_obss_scan(wpa_s) > 0) {
1135 wpa_scan_results_free(scan_res);
1139 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1140 wpa_scan_results_free(scan_res);
1144 if (autoscan_notify_scan(wpa_s, scan_res)) {
1145 wpa_scan_results_free(scan_res);
1149 if (wpa_s->disconnected) {
1150 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1151 wpa_scan_results_free(scan_res);
1155 if (!wpas_driver_bss_selection(wpa_s) &&
1156 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1157 wpa_scan_results_free(scan_res);
1161 wpas_wps_update_ap_info(wpa_s, scan_res);
1163 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1167 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1169 wpa_scan_results_free(scan_res);
1171 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1175 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1176 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1179 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1181 wpa_scan_results_free(scan_res);
1182 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1183 ssid = wpa_supplicant_pick_new_network(wpa_s);
1185 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1186 wpa_supplicant_associate(wpa_s, NULL, ssid);
1187 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1189 int timeout_sec = wpa_s->scan_interval;
1190 int timeout_usec = 0;
1192 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1195 if (wpa_s->p2p_in_provisioning) {
1197 * Use shorter wait during P2P Provisioning
1198 * state to speed up group formation.
1201 timeout_usec = 250000;
1202 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1206 #endif /* CONFIG_P2P */
1207 if (wpa_supplicant_req_sched_scan(wpa_s))
1208 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1216 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1217 union wpa_event_data *data)
1219 const char *rn, *rn2;
1220 struct wpa_supplicant *ifs;
1222 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1224 * If no scan results could be fetched, then no need to
1225 * notify those interfaces that did not actually request
1232 * Check other interfaces to see if they have the same radio-name. If
1233 * so, they get updated with this same scan info.
1235 if (!wpa_s->driver->get_radio_name)
1238 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1239 if (rn == NULL || rn[0] == '\0')
1242 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1243 "sharing same radio (%s) in event_scan_results", rn);
1245 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1246 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1249 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1250 if (rn2 && os_strcmp(rn, rn2) == 0) {
1251 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1252 "sibling", ifs->ifname);
1253 _wpa_supplicant_event_scan_results(ifs, data);
1258 #endif /* CONFIG_NO_SCAN_PROCESSING */
1263 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1265 struct wpa_supplicant *wpa_s = eloop_ctx;
1267 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1270 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1271 MAC2STR(wpa_s->bssid));
1272 /* TODO: could skip this if normal data traffic has been sent */
1273 /* TODO: Consider using some more appropriate data frame for this */
1275 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1278 if (wpa_s->sme.bss_max_idle_period) {
1280 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1283 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1284 wnm_bss_keep_alive, wpa_s, NULL);
1286 #endif /* CONFIG_SME */
1290 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1291 const u8 *ies, size_t ies_len)
1293 struct ieee802_11_elems elems;
1298 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1302 if (elems.bss_max_idle_period) {
1304 wpa_s->sme.bss_max_idle_period =
1305 WPA_GET_LE16(elems.bss_max_idle_period);
1306 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1307 "TU)%s", wpa_s->sme.bss_max_idle_period,
1308 (elems.bss_max_idle_period[2] & 0x01) ?
1309 " (protected keep-live required)" : "");
1310 if (wpa_s->sme.bss_max_idle_period == 0)
1311 wpa_s->sme.bss_max_idle_period = 1;
1312 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1313 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1314 /* msec times 1000 */
1315 msec = wpa_s->sme.bss_max_idle_period * 1024;
1318 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1319 wnm_bss_keep_alive, wpa_s,
1323 #endif /* CONFIG_SME */
1326 #endif /* CONFIG_WNM */
1329 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1332 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1333 #endif /* CONFIG_WNM */
1337 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1338 union wpa_event_data *data)
1340 int l, len, found = 0, wpa_found, rsn_found;
1343 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1344 if (data->assoc_info.req_ies)
1345 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1346 data->assoc_info.req_ies_len);
1347 if (data->assoc_info.resp_ies) {
1348 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1349 data->assoc_info.resp_ies_len);
1351 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1352 data->assoc_info.resp_ies_len);
1353 #endif /* CONFIG_TDLS */
1355 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1356 data->assoc_info.resp_ies_len);
1357 #endif /* CONFIG_WNM */
1359 if (data->assoc_info.beacon_ies)
1360 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1361 data->assoc_info.beacon_ies,
1362 data->assoc_info.beacon_ies_len);
1363 if (data->assoc_info.freq)
1364 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1365 data->assoc_info.freq);
1367 p = data->assoc_info.req_ies;
1368 l = data->assoc_info.req_ies_len;
1370 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1371 while (p && l >= 2) {
1374 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1378 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1379 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1380 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1381 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1384 wpa_find_assoc_pmkid(wpa_s);
1390 if (!found && data->assoc_info.req_ies)
1391 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1393 #ifdef CONFIG_IEEE80211R
1395 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1397 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1398 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1399 data->assoc_info.resp_ies,
1400 data->assoc_info.resp_ies_len,
1402 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1403 "Reassociation Response failed");
1404 wpa_supplicant_deauthenticate(
1405 wpa_s, WLAN_REASON_INVALID_IE);
1410 p = data->assoc_info.resp_ies;
1411 l = data->assoc_info.resp_ies_len;
1413 #ifdef CONFIG_WPS_STRICT
1414 if (p && wpa_s->current_ssid &&
1415 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1417 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1419 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1420 "include WPS IE in (Re)Association Response");
1424 if (wps_validate_assoc_resp(wps) < 0) {
1426 wpa_supplicant_deauthenticate(
1427 wpa_s, WLAN_REASON_INVALID_IE);
1432 #endif /* CONFIG_WPS_STRICT */
1434 /* Go through the IEs and make a copy of the MDIE, if present. */
1435 while (p && l >= 2) {
1438 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1442 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1443 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1444 wpa_s->sme.ft_used = 1;
1445 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1446 MOBILITY_DOMAIN_ID_LEN);
1452 #endif /* CONFIG_SME */
1454 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1455 data->assoc_info.resp_ies_len);
1456 #endif /* CONFIG_IEEE80211R */
1458 /* WPA/RSN IE from Beacon/ProbeResp */
1459 p = data->assoc_info.beacon_ies;
1460 l = data->assoc_info.beacon_ies_len;
1462 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1464 wpa_found = rsn_found = 0;
1465 while (p && l >= 2) {
1468 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1473 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1474 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1476 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1480 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1482 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1489 if (!wpa_found && data->assoc_info.beacon_ies)
1490 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1491 if (!rsn_found && data->assoc_info.beacon_ies)
1492 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1493 if (wpa_found || rsn_found)
1494 wpa_s->ap_ies_from_associnfo = 1;
1496 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1497 wpa_s->assoc_freq != data->assoc_info.freq) {
1498 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1500 wpa_s->assoc_freq, data->assoc_info.freq);
1501 wpa_supplicant_update_scan_results(wpa_s);
1504 wpa_s->assoc_freq = data->assoc_info.freq;
1510 static struct wpa_bss * wpa_supplicant_get_new_bss(
1511 struct wpa_supplicant *wpa_s, const u8 *bssid)
1513 struct wpa_bss *bss = NULL;
1514 struct wpa_ssid *ssid = wpa_s->current_ssid;
1516 if (ssid->ssid_len > 0)
1517 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1519 bss = wpa_bss_get_bssid(wpa_s, bssid);
1525 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1527 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1529 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1532 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1535 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1536 WPA_IE_VENDOR_TYPE);
1537 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1539 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1540 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1541 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1542 bss_rsn ? 2 + bss_rsn[1] : 0))
1549 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1550 union wpa_event_data *data)
1554 struct wpa_driver_capa capa;
1557 if (wpa_s->ap_iface) {
1558 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1559 data->assoc_info.addr,
1560 data->assoc_info.req_ies,
1561 data->assoc_info.req_ies_len,
1562 data->assoc_info.reassoc);
1565 #endif /* CONFIG_AP */
1567 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1568 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1571 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1572 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1573 wpa_supplicant_disassociate(
1574 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1578 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1579 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1580 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1581 MACSTR, MAC2STR(bssid));
1582 random_add_randomness(bssid, ETH_ALEN);
1583 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1584 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1585 wpas_notify_bssid_changed(wpa_s);
1587 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1588 wpa_clear_keys(wpa_s, bssid);
1590 if (wpa_supplicant_select_config(wpa_s) < 0) {
1591 wpa_supplicant_disassociate(
1592 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1595 if (wpa_s->current_ssid) {
1596 struct wpa_bss *bss = NULL;
1598 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1600 wpa_supplicant_update_scan_results(wpa_s);
1602 /* Get the BSS from the new scan results */
1603 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1607 wpa_s->current_bss = bss;
1610 if (wpa_s->conf->ap_scan == 1 &&
1611 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1612 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1613 wpa_msg(wpa_s, MSG_WARNING,
1614 "WPA/RSN IEs not updated");
1619 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1620 wpa_s->sme.prev_bssid_set = 1;
1621 #endif /* CONFIG_SME */
1623 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1624 if (wpa_s->current_ssid) {
1625 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1626 * initialized before association, but for other modes,
1627 * initialize PC/SC here, if the current configuration needs
1628 * smartcard or SIM/USIM. */
1629 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1631 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1633 l2_packet_notify_auth_start(wpa_s->l2);
1636 * Set portEnabled first to FALSE in order to get EAP state machine out
1637 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1638 * state machine may transit to AUTHENTICATING state based on obsolete
1639 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1640 * AUTHENTICATED without ever giving chance to EAP state machine to
1643 if (!ft_completed) {
1644 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1645 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1647 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1648 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1649 /* 802.1X::portControl = Auto */
1650 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1651 wpa_s->eapol_received = 0;
1652 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1653 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1654 (wpa_s->current_ssid &&
1655 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1656 wpa_supplicant_cancel_auth_timeout(wpa_s);
1657 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1658 } else if (!ft_completed) {
1659 /* Timeout for receiving the first EAPOL packet */
1660 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1662 wpa_supplicant_cancel_scan(wpa_s);
1664 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1665 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1667 * We are done; the driver will take care of RSN 4-way
1670 wpa_supplicant_cancel_auth_timeout(wpa_s);
1671 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1672 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1673 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1674 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1675 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1677 * The driver will take care of RSN 4-way handshake, so we need
1678 * to allow EAPOL supplicant to complete its work without
1679 * waiting for WPA supplicant.
1681 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1682 } else if (ft_completed) {
1684 * FT protocol completed - make sure EAPOL state machine ends
1685 * up in authenticated.
1687 wpa_supplicant_cancel_auth_timeout(wpa_s);
1688 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1689 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1690 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1693 if (wpa_s->pending_eapol_rx) {
1694 struct os_time now, age;
1696 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1697 if (age.sec == 0 && age.usec < 100000 &&
1698 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1700 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1701 "frame that was received just before "
1702 "association notification");
1703 wpa_supplicant_rx_eapol(
1704 wpa_s, wpa_s->pending_eapol_rx_src,
1705 wpabuf_head(wpa_s->pending_eapol_rx),
1706 wpabuf_len(wpa_s->pending_eapol_rx));
1708 wpabuf_free(wpa_s->pending_eapol_rx);
1709 wpa_s->pending_eapol_rx = NULL;
1712 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1713 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1714 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1715 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1716 /* Set static WEP keys again */
1717 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1720 #ifdef CONFIG_IBSS_RSN
1721 if (wpa_s->current_ssid &&
1722 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1723 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1724 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1725 wpa_s->ibss_rsn == NULL) {
1726 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1727 if (!wpa_s->ibss_rsn) {
1728 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1729 wpa_supplicant_deauthenticate(
1730 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1734 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1736 #endif /* CONFIG_IBSS_RSN */
1738 wpas_wps_notify_assoc(wpa_s, bssid);
1742 static int disconnect_reason_recoverable(u16 reason_code)
1744 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1745 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1746 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1750 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1752 int locally_generated)
1756 u8 prev_pending_bssid[ETH_ALEN];
1757 struct wpa_bss *fast_reconnect = NULL;
1758 struct wpa_ssid *fast_reconnect_ssid = NULL;
1760 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1761 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1763 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1765 * At least Host AP driver and a Prism3 card seemed to be
1766 * generating streams of disconnected events when configuring
1767 * IBSS for WPA-None. Ignore them for now.
1769 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1770 "IBSS/WPA-None mode");
1774 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1775 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1776 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1777 "pre-shared key may be incorrect");
1778 wpas_auth_failed(wpa_s);
1780 if (!wpa_s->auto_reconnect_disabled ||
1781 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1782 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1783 "reconnect (wps=%d wpa_state=%d)",
1784 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1786 if (wpa_s->wpa_state == WPA_COMPLETED &&
1787 wpa_s->current_ssid &&
1788 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1789 !locally_generated &&
1790 disconnect_reason_recoverable(reason_code)) {
1792 * It looks like the AP has dropped association with
1793 * us, but could allow us to get back in. Try to
1794 * reconnect to the same BSS without full scan to save
1795 * time for some common cases.
1797 fast_reconnect = wpa_s->current_bss;
1798 fast_reconnect_ssid = wpa_s->current_ssid;
1799 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1800 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1802 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1805 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1806 "try to re-connect");
1807 wpa_s->reassociate = 0;
1808 wpa_s->disconnected = 1;
1809 wpa_supplicant_cancel_sched_scan(wpa_s);
1811 bssid = wpa_s->bssid;
1812 if (is_zero_ether_addr(bssid))
1813 bssid = wpa_s->pending_bssid;
1814 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1815 wpas_connection_failed(wpa_s, bssid);
1816 wpa_sm_notify_disassoc(wpa_s->wpa);
1817 if (locally_generated)
1818 wpa_s->disconnect_reason = -reason_code;
1820 wpa_s->disconnect_reason = reason_code;
1821 wpas_notify_disconnect_reason(wpa_s);
1822 if (!is_zero_ether_addr(bssid) ||
1823 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1824 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1826 MAC2STR(bssid), reason_code,
1827 locally_generated ? " locally_generated=1" : "");
1829 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1830 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1831 wpa_s->keys_cleared = 0;
1832 wpa_clear_keys(wpa_s, wpa_s->bssid);
1834 wpa_supplicant_mark_disassoc(wpa_s);
1836 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1837 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1839 if (fast_reconnect) {
1840 #ifndef CONFIG_NO_SCAN_PROCESSING
1841 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1842 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1843 fast_reconnect_ssid) < 0) {
1844 /* Recover through full scan */
1845 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1847 #endif /* CONFIG_NO_SCAN_PROCESSING */
1852 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1853 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1855 struct wpa_supplicant *wpa_s = eloop_ctx;
1857 if (!wpa_s->pending_mic_error_report)
1860 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1861 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1862 wpa_s->pending_mic_error_report = 0;
1864 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1868 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1869 union wpa_event_data *data)
1874 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1875 pairwise = (data && data->michael_mic_failure.unicast);
1877 if ((wpa_s->last_michael_mic_error &&
1878 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1879 wpa_s->pending_mic_error_report) {
1880 if (wpa_s->pending_mic_error_report) {
1882 * Send the pending MIC error report immediately since
1883 * we are going to start countermeasures and AP better
1886 wpa_sm_key_request(wpa_s->wpa, 1,
1887 wpa_s->pending_mic_error_pairwise);
1890 /* Send the new MIC error report immediately since we are going
1891 * to start countermeasures and AP better do the same.
1893 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1895 /* initialize countermeasures */
1896 wpa_s->countermeasures = 1;
1898 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1900 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1903 * Need to wait for completion of request frame. We do not get
1904 * any callback for the message completion, so just wait a
1905 * short while and hope for the best. */
1908 wpa_drv_set_countermeasures(wpa_s, 1);
1909 wpa_supplicant_deauthenticate(wpa_s,
1910 WLAN_REASON_MICHAEL_MIC_FAILURE);
1911 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1913 eloop_register_timeout(60, 0,
1914 wpa_supplicant_stop_countermeasures,
1916 /* TODO: mark the AP rejected for 60 second. STA is
1917 * allowed to associate with another AP.. */
1919 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1920 if (wpa_s->mic_errors_seen) {
1922 * Reduce the effectiveness of Michael MIC error
1923 * reports as a means for attacking against TKIP if
1924 * more than one MIC failure is noticed with the same
1925 * PTK. We delay the transmission of the reports by a
1926 * random time between 0 and 60 seconds in order to
1927 * force the attacker wait 60 seconds before getting
1928 * the information on whether a frame resulted in a MIC
1934 if (os_get_random(rval, sizeof(rval)) < 0)
1935 sec = os_random() % 60;
1937 sec = WPA_GET_BE32(rval) % 60;
1938 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1939 "report %d seconds", sec);
1940 wpa_s->pending_mic_error_report = 1;
1941 wpa_s->pending_mic_error_pairwise = pairwise;
1942 eloop_cancel_timeout(
1943 wpa_supplicant_delayed_mic_error_report,
1945 eloop_register_timeout(
1946 sec, os_random() % 1000000,
1947 wpa_supplicant_delayed_mic_error_report,
1950 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1952 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1953 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1954 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1956 wpa_s->last_michael_mic_error = t.sec;
1957 wpa_s->mic_errors_seen++;
1961 #ifdef CONFIG_TERMINATE_ONLASTIF
1962 static int any_interfaces(struct wpa_supplicant *head)
1964 struct wpa_supplicant *wpa_s;
1966 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1967 if (!wpa_s->interface_removed)
1971 #endif /* CONFIG_TERMINATE_ONLASTIF */
1975 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1976 union wpa_event_data *data)
1978 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1981 switch (data->interface_status.ievent) {
1982 case EVENT_INTERFACE_ADDED:
1983 if (!wpa_s->interface_removed)
1985 wpa_s->interface_removed = 0;
1986 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1987 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1988 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1989 "driver after interface was added");
1991 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1993 case EVENT_INTERFACE_REMOVED:
1994 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1995 wpa_s->interface_removed = 1;
1996 wpa_supplicant_mark_disassoc(wpa_s);
1997 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1998 l2_packet_deinit(wpa_s->l2);
2000 #ifdef CONFIG_IBSS_RSN
2001 ibss_rsn_deinit(wpa_s->ibss_rsn);
2002 wpa_s->ibss_rsn = NULL;
2003 #endif /* CONFIG_IBSS_RSN */
2004 #ifdef CONFIG_TERMINATE_ONLASTIF
2005 /* check if last interface */
2006 if (!any_interfaces(wpa_s->global->ifaces))
2008 #endif /* CONFIG_TERMINATE_ONLASTIF */
2014 #ifdef CONFIG_PEERKEY
2016 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2017 union wpa_event_data *data)
2021 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2023 #endif /* CONFIG_PEERKEY */
2027 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2028 union wpa_event_data *data)
2032 switch (data->tdls.oper) {
2033 case TDLS_REQUEST_SETUP:
2034 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2036 case TDLS_REQUEST_TEARDOWN:
2037 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2038 data->tdls.reason_code);
2042 #endif /* CONFIG_TDLS */
2045 #ifdef CONFIG_IEEE80211V
2046 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2047 union wpa_event_data *data)
2051 switch (data->wnm.oper) {
2052 case WNM_OPER_SLEEP:
2053 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2054 "(action=%d, intval=%d)",
2055 data->wnm.sleep_action, data->wnm.sleep_intval);
2056 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2057 data->wnm.sleep_intval);
2061 #endif /* CONFIG_IEEE80211V */
2064 #ifdef CONFIG_IEEE80211R
2066 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2067 union wpa_event_data *data)
2072 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2073 data->ft_ies.ies_len,
2074 data->ft_ies.ft_action,
2075 data->ft_ies.target_ap,
2076 data->ft_ies.ric_ies,
2077 data->ft_ies.ric_ies_len) < 0) {
2078 /* TODO: prevent MLME/driver from trying to associate? */
2081 #endif /* CONFIG_IEEE80211R */
2084 #ifdef CONFIG_IBSS_RSN
2085 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2086 union wpa_event_data *data)
2088 struct wpa_ssid *ssid;
2089 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2093 ssid = wpa_s->current_ssid;
2096 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2099 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2101 #endif /* CONFIG_IBSS_RSN */
2104 #ifdef CONFIG_IEEE80211R
2105 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2108 const u8 *sta_addr, *target_ap_addr;
2111 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2112 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2113 return; /* only SME case supported for now */
2114 if (len < 1 + 2 * ETH_ALEN + 2)
2117 return; /* Only FT Action Response is supported for now */
2118 sta_addr = data + 1;
2119 target_ap_addr = data + 1 + ETH_ALEN;
2120 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2121 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2122 MACSTR " TargetAP " MACSTR " status %u",
2123 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2125 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2126 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2127 " in FT Action Response", MAC2STR(sta_addr));
2132 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2133 "failure (status code %d)", status);
2134 /* TODO: report error to FT code(?) */
2138 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2139 len - (1 + 2 * ETH_ALEN + 2), 1,
2140 target_ap_addr, NULL, 0) < 0)
2145 struct wpa_bss *bss;
2146 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2148 wpa_s->sme.freq = bss->freq;
2149 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2150 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2153 #endif /* CONFIG_SME */
2155 #endif /* CONFIG_IEEE80211R */
2158 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2159 struct unprot_deauth *e)
2161 #ifdef CONFIG_IEEE80211W
2162 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2163 "dropped: " MACSTR " -> " MACSTR
2164 " (reason code %u)",
2165 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2166 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2167 #endif /* CONFIG_IEEE80211W */
2171 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2172 struct unprot_disassoc *e)
2174 #ifdef CONFIG_IEEE80211W
2175 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2176 "dropped: " MACSTR " -> " MACSTR
2177 " (reason code %u)",
2178 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2179 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2180 #endif /* CONFIG_IEEE80211W */
2184 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2187 const u8 *pos, *end;
2189 if (rx->data == NULL || rx->len == 0)
2193 end = pos + rx->len;
2196 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2197 action, MAC2STR(rx->sa));
2199 case WNM_BSS_TRANS_MGMT_REQ:
2202 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2203 "Request: dialog_token=%u request_mode=0x%x "
2204 "disassoc_timer=%u validity_interval=%u",
2205 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2209 pos += 12; /* BSS Termination Duration */
2212 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2213 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2214 "Transition Management Request "
2218 os_memcpy(url, pos + 1, pos[0]);
2220 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2221 "Imminent - session_info_url=%s", url);
2228 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2229 union wpa_event_data *data)
2231 struct wpa_supplicant *wpa_s = ctx;
2232 u16 reason_code = 0;
2233 int locally_generated = 0;
2235 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2236 event != EVENT_INTERFACE_ENABLED &&
2237 event != EVENT_INTERFACE_STATUS &&
2238 event != EVENT_SCHED_SCAN_STOPPED) {
2239 wpa_dbg(wpa_s, MSG_DEBUG,
2240 "Ignore event %s (%d) while interface is disabled",
2241 event_to_string(event), event);
2245 #ifndef CONFIG_NO_STDOUT_DEBUG
2247 int level = MSG_DEBUG;
2249 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2250 const struct ieee80211_hdr *hdr;
2252 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2253 fc = le_to_host16(hdr->frame_control);
2254 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2255 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2256 level = MSG_EXCESSIVE;
2259 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2260 event_to_string(event), event);
2262 #endif /* CONFIG_NO_STDOUT_DEBUG */
2266 sme_event_auth(wpa_s, data);
2269 wpa_supplicant_event_assoc(wpa_s, data);
2271 case EVENT_DISASSOC:
2272 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2274 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2275 data->disassoc_info.reason_code,
2276 data->disassoc_info.locally_generated ?
2277 " (locally generated)" : "");
2278 if (data->disassoc_info.addr)
2279 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2280 MAC2STR(data->disassoc_info.addr));
2283 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2284 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2285 data->disassoc_info.addr);
2288 if (wpa_s->ap_iface) {
2289 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2293 #endif /* CONFIG_AP */
2295 reason_code = data->disassoc_info.reason_code;
2297 data->disassoc_info.locally_generated;
2298 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2299 data->disassoc_info.ie,
2300 data->disassoc_info.ie_len);
2302 wpas_p2p_disassoc_notif(
2303 wpa_s, data->disassoc_info.addr, reason_code,
2304 data->disassoc_info.ie,
2305 data->disassoc_info.ie_len,
2307 #endif /* CONFIG_P2P */
2309 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2310 sme_event_disassoc(wpa_s, data);
2313 if (event == EVENT_DEAUTH) {
2314 wpa_dbg(wpa_s, MSG_DEBUG,
2315 "Deauthentication notification");
2317 reason_code = data->deauth_info.reason_code;
2319 data->deauth_info.locally_generated;
2320 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2321 data->deauth_info.reason_code,
2322 data->deauth_info.locally_generated ?
2323 " (locally generated)" : "");
2324 if (data->deauth_info.addr) {
2325 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2327 MAC2STR(data->deauth_info.
2330 wpa_hexdump(MSG_DEBUG,
2331 "Deauthentication frame IE(s)",
2332 data->deauth_info.ie,
2333 data->deauth_info.ie_len);
2337 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2338 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2339 data->deauth_info.addr);
2342 if (wpa_s->ap_iface) {
2343 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2347 #endif /* CONFIG_AP */
2348 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2350 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2351 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2352 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2353 eapol_sm_failed(wpa_s->eapol)))
2354 wpas_auth_failed(wpa_s);
2356 if (event == EVENT_DEAUTH && data) {
2357 wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
2359 data->deauth_info.ie,
2360 data->deauth_info.ie_len,
2363 #endif /* CONFIG_P2P */
2365 case EVENT_MICHAEL_MIC_FAILURE:
2366 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2368 #ifndef CONFIG_NO_SCAN_PROCESSING
2369 case EVENT_SCAN_RESULTS:
2370 wpa_supplicant_event_scan_results(wpa_s, data);
2372 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2373 wpa_s->global->p2p != NULL &&
2374 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2375 wpa_s->wpa_state != WPA_ASSOCIATING) {
2376 wpa_s->p2p_cb_on_scan_complete = 0;
2377 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2378 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2379 "continued after scan result processing");
2382 #endif /* CONFIG_P2P */
2384 #endif /* CONFIG_NO_SCAN_PROCESSING */
2385 case EVENT_ASSOCINFO:
2386 wpa_supplicant_event_associnfo(wpa_s, data);
2388 case EVENT_INTERFACE_STATUS:
2389 wpa_supplicant_event_interface_status(wpa_s, data);
2391 case EVENT_PMKID_CANDIDATE:
2392 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2394 #ifdef CONFIG_PEERKEY
2395 case EVENT_STKSTART:
2396 wpa_supplicant_event_stkstart(wpa_s, data);
2398 #endif /* CONFIG_PEERKEY */
2401 wpa_supplicant_event_tdls(wpa_s, data);
2403 #endif /* CONFIG_TDLS */
2404 #ifdef CONFIG_IEEE80211V
2406 wpa_supplicant_event_wnm(wpa_s, data);
2408 #endif /* CONFIG_IEEE80211V */
2409 #ifdef CONFIG_IEEE80211R
2410 case EVENT_FT_RESPONSE:
2411 wpa_supplicant_event_ft_response(wpa_s, data);
2413 #endif /* CONFIG_IEEE80211R */
2414 #ifdef CONFIG_IBSS_RSN
2415 case EVENT_IBSS_RSN_START:
2416 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2418 #endif /* CONFIG_IBSS_RSN */
2419 case EVENT_ASSOC_REJECT:
2420 if (data->assoc_reject.bssid)
2421 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2422 "bssid=" MACSTR " status_code=%u",
2423 MAC2STR(data->assoc_reject.bssid),
2424 data->assoc_reject.status_code);
2426 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2428 data->assoc_reject.status_code);
2429 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2430 sme_event_assoc_reject(wpa_s, data);
2432 case EVENT_AUTH_TIMED_OUT:
2433 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2434 sme_event_auth_timed_out(wpa_s, data);
2436 case EVENT_ASSOC_TIMED_OUT:
2437 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2438 sme_event_assoc_timed_out(wpa_s, data);
2440 case EVENT_TX_STATUS:
2441 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2442 " type=%d stype=%d",
2443 MAC2STR(data->tx_status.dst),
2444 data->tx_status.type, data->tx_status.stype);
2446 if (wpa_s->ap_iface == NULL) {
2447 #ifdef CONFIG_OFFCHANNEL
2448 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2449 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2450 offchannel_send_action_tx_status(
2451 wpa_s, data->tx_status.dst,
2452 data->tx_status.data,
2453 data->tx_status.data_len,
2454 data->tx_status.ack ?
2455 OFFCHANNEL_SEND_ACTION_SUCCESS :
2456 OFFCHANNEL_SEND_ACTION_NO_ACK);
2457 #endif /* CONFIG_OFFCHANNEL */
2460 #endif /* CONFIG_AP */
2461 #ifdef CONFIG_OFFCHANNEL
2462 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2463 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2465 * Catch TX status events for Action frames we sent via group
2466 * interface in GO mode.
2468 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2469 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2470 os_memcmp(wpa_s->parent->pending_action_dst,
2471 data->tx_status.dst, ETH_ALEN) == 0) {
2472 offchannel_send_action_tx_status(
2473 wpa_s->parent, data->tx_status.dst,
2474 data->tx_status.data,
2475 data->tx_status.data_len,
2476 data->tx_status.ack ?
2477 OFFCHANNEL_SEND_ACTION_SUCCESS :
2478 OFFCHANNEL_SEND_ACTION_NO_ACK);
2481 #endif /* CONFIG_OFFCHANNEL */
2483 switch (data->tx_status.type) {
2484 case WLAN_FC_TYPE_MGMT:
2485 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2486 data->tx_status.data_len,
2487 data->tx_status.stype,
2488 data->tx_status.ack);
2490 case WLAN_FC_TYPE_DATA:
2491 ap_tx_status(wpa_s, data->tx_status.dst,
2492 data->tx_status.data,
2493 data->tx_status.data_len,
2494 data->tx_status.ack);
2497 #endif /* CONFIG_AP */
2500 case EVENT_EAPOL_TX_STATUS:
2501 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2502 data->eapol_tx_status.data,
2503 data->eapol_tx_status.data_len,
2504 data->eapol_tx_status.ack);
2506 case EVENT_DRIVER_CLIENT_POLL_OK:
2507 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2509 case EVENT_RX_FROM_UNKNOWN:
2510 if (wpa_s->ap_iface == NULL)
2512 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2513 data->rx_from_unknown.wds);
2515 case EVENT_CH_SWITCH:
2518 if (!wpa_s->ap_iface) {
2519 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2520 "event in non-AP mode");
2525 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2526 data->ch_switch.ht_enabled,
2527 data->ch_switch.ch_offset);
2528 #endif /* CONFIG_AP */
2530 case EVENT_RX_MGMT: {
2532 const struct ieee80211_mgmt *mgmt;
2534 mgmt = (const struct ieee80211_mgmt *)
2535 data->rx_mgmt.frame;
2536 fc = le_to_host16(mgmt->frame_control);
2537 stype = WLAN_FC_GET_STYPE(fc);
2539 if (wpa_s->ap_iface == NULL) {
2541 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2542 data->rx_mgmt.frame_len > 24) {
2543 const u8 *src = mgmt->sa;
2544 const u8 *ie = mgmt->u.probe_req.variable;
2545 size_t ie_len = data->rx_mgmt.frame_len -
2546 (mgmt->u.probe_req.variable -
2547 data->rx_mgmt.frame);
2548 wpas_p2p_probe_req_rx(
2549 wpa_s, src, mgmt->da,
2550 mgmt->bssid, ie, ie_len,
2551 data->rx_mgmt.ssi_signal);
2554 #endif /* CONFIG_P2P */
2555 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2556 "management frame in non-AP mode");
2560 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2561 data->rx_mgmt.frame_len > 24) {
2562 const u8 *ie = mgmt->u.probe_req.variable;
2563 size_t ie_len = data->rx_mgmt.frame_len -
2564 (mgmt->u.probe_req.variable -
2565 data->rx_mgmt.frame);
2567 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2568 mgmt->bssid, ie, ie_len,
2569 data->rx_mgmt.ssi_signal);
2572 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2575 #endif /* CONFIG_AP */
2576 case EVENT_RX_ACTION:
2577 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2578 " Category=%u DataLen=%d freq=%d MHz",
2579 MAC2STR(data->rx_action.sa),
2580 data->rx_action.category, (int) data->rx_action.len,
2581 data->rx_action.freq);
2582 #ifdef CONFIG_IEEE80211R
2583 if (data->rx_action.category == WLAN_ACTION_FT) {
2584 ft_rx_action(wpa_s, data->rx_action.data,
2585 data->rx_action.len);
2588 #endif /* CONFIG_IEEE80211R */
2589 #ifdef CONFIG_IEEE80211W
2591 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2592 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2593 data->rx_action.data,
2594 data->rx_action.len);
2597 #endif /* CONFIG_SME */
2598 #endif /* CONFIG_IEEE80211W */
2599 #ifdef CONFIG_IEEE80211V
2600 if (data->rx_action.category == WLAN_ACTION_WNM) {
2601 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2604 #endif /* CONFIG_IEEE80211V */
2606 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2607 gas_query_rx(wpa_s->gas, data->rx_action.da,
2608 data->rx_action.sa, data->rx_action.bssid,
2609 data->rx_action.data, data->rx_action.len,
2610 data->rx_action.freq) == 0)
2612 #endif /* CONFIG_GAS */
2613 if (data->rx_action.category == WLAN_ACTION_WNM) {
2614 wnm_action_rx(wpa_s, &data->rx_action);
2618 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2619 data->rx_action.len >= 4 &&
2620 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2621 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2622 "Response from " MACSTR,
2623 MAC2STR(data->rx_action.sa));
2626 #endif /* CONFIG_TDLS */
2628 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2630 data->rx_action.bssid,
2631 data->rx_action.category,
2632 data->rx_action.data,
2633 data->rx_action.len, data->rx_action.freq);
2634 #endif /* CONFIG_P2P */
2636 case EVENT_RX_PROBE_REQ:
2637 if (data->rx_probe_req.sa == NULL ||
2638 data->rx_probe_req.ie == NULL)
2641 if (wpa_s->ap_iface) {
2642 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2643 data->rx_probe_req.sa,
2644 data->rx_probe_req.da,
2645 data->rx_probe_req.bssid,
2646 data->rx_probe_req.ie,
2647 data->rx_probe_req.ie_len,
2648 data->rx_probe_req.ssi_signal);
2651 #endif /* CONFIG_AP */
2653 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2654 data->rx_probe_req.da,
2655 data->rx_probe_req.bssid,
2656 data->rx_probe_req.ie,
2657 data->rx_probe_req.ie_len,
2658 data->rx_probe_req.ssi_signal);
2659 #endif /* CONFIG_P2P */
2661 case EVENT_REMAIN_ON_CHANNEL:
2662 #ifdef CONFIG_OFFCHANNEL
2663 offchannel_remain_on_channel_cb(
2664 wpa_s, data->remain_on_channel.freq,
2665 data->remain_on_channel.duration);
2666 #endif /* CONFIG_OFFCHANNEL */
2668 wpas_p2p_remain_on_channel_cb(
2669 wpa_s, data->remain_on_channel.freq,
2670 data->remain_on_channel.duration);
2671 #endif /* CONFIG_P2P */
2673 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2674 #ifdef CONFIG_OFFCHANNEL
2675 offchannel_cancel_remain_on_channel_cb(
2676 wpa_s, data->remain_on_channel.freq);
2677 #endif /* CONFIG_OFFCHANNEL */
2679 wpas_p2p_cancel_remain_on_channel_cb(
2680 wpa_s, data->remain_on_channel.freq);
2681 #endif /* CONFIG_P2P */
2684 case EVENT_P2P_DEV_FOUND: {
2685 struct p2p_peer_info peer_info;
2687 os_memset(&peer_info, 0, sizeof(peer_info));
2688 if (data->p2p_dev_found.dev_addr)
2689 os_memcpy(peer_info.p2p_device_addr,
2690 data->p2p_dev_found.dev_addr, ETH_ALEN);
2691 if (data->p2p_dev_found.pri_dev_type)
2692 os_memcpy(peer_info.pri_dev_type,
2693 data->p2p_dev_found.pri_dev_type,
2694 sizeof(peer_info.pri_dev_type));
2695 if (data->p2p_dev_found.dev_name)
2696 os_strlcpy(peer_info.device_name,
2697 data->p2p_dev_found.dev_name,
2698 sizeof(peer_info.device_name));
2699 peer_info.config_methods = data->p2p_dev_found.config_methods;
2700 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2701 peer_info.group_capab = data->p2p_dev_found.group_capab;
2704 * FIX: new_device=1 is not necessarily correct. We should
2705 * maintain a P2P peer database in wpa_supplicant and update
2706 * this information based on whether the peer is truly new.
2708 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2711 case EVENT_P2P_GO_NEG_REQ_RX:
2712 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2713 data->p2p_go_neg_req_rx.dev_passwd_id);
2715 case EVENT_P2P_GO_NEG_COMPLETED:
2716 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2718 case EVENT_P2P_PROV_DISC_REQUEST:
2719 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2720 data->p2p_prov_disc_req.config_methods,
2721 data->p2p_prov_disc_req.dev_addr,
2722 data->p2p_prov_disc_req.pri_dev_type,
2723 data->p2p_prov_disc_req.dev_name,
2724 data->p2p_prov_disc_req.supp_config_methods,
2725 data->p2p_prov_disc_req.dev_capab,
2726 data->p2p_prov_disc_req.group_capab,
2729 case EVENT_P2P_PROV_DISC_RESPONSE:
2730 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2731 data->p2p_prov_disc_resp.config_methods);
2733 case EVENT_P2P_SD_REQUEST:
2734 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2735 data->p2p_sd_req.sa,
2736 data->p2p_sd_req.dialog_token,
2737 data->p2p_sd_req.update_indic,
2738 data->p2p_sd_req.tlvs,
2739 data->p2p_sd_req.tlvs_len);
2741 case EVENT_P2P_SD_RESPONSE:
2742 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2743 data->p2p_sd_resp.update_indic,
2744 data->p2p_sd_resp.tlvs,
2745 data->p2p_sd_resp.tlvs_len);
2747 #endif /* CONFIG_P2P */
2748 case EVENT_EAPOL_RX:
2749 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2750 data->eapol_rx.data,
2751 data->eapol_rx.data_len);
2753 case EVENT_SIGNAL_CHANGE:
2754 bgscan_notify_signal_change(
2755 wpa_s, data->signal_change.above_threshold,
2756 data->signal_change.current_signal,
2757 data->signal_change.current_noise,
2758 data->signal_change.current_txrate);
2760 case EVENT_INTERFACE_ENABLED:
2761 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2762 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2763 wpa_supplicant_update_mac_addr(wpa_s);
2765 if (!wpa_s->ap_iface) {
2766 wpa_supplicant_set_state(wpa_s,
2768 wpa_supplicant_req_scan(wpa_s, 0, 0);
2770 wpa_supplicant_set_state(wpa_s,
2772 #else /* CONFIG_AP */
2773 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2774 wpa_supplicant_req_scan(wpa_s, 0, 0);
2775 #endif /* CONFIG_AP */
2778 case EVENT_INTERFACE_DISABLED:
2779 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2780 wpa_supplicant_mark_disassoc(wpa_s);
2781 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2783 case EVENT_CHANNEL_LIST_CHANGED:
2784 if (wpa_s->drv_priv == NULL)
2785 break; /* Ignore event during drv initialization */
2787 free_hw_features(wpa_s);
2788 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2789 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2792 wpas_p2p_update_channel_list(wpa_s);
2793 #endif /* CONFIG_P2P */
2795 case EVENT_INTERFACE_UNAVAILABLE:
2797 wpas_p2p_interface_unavailable(wpa_s);
2798 #endif /* CONFIG_P2P */
2800 case EVENT_BEST_CHANNEL:
2801 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2803 data->best_chan.freq_24, data->best_chan.freq_5,
2804 data->best_chan.freq_overall);
2805 wpa_s->best_24_freq = data->best_chan.freq_24;
2806 wpa_s->best_5_freq = data->best_chan.freq_5;
2807 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2809 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2810 data->best_chan.freq_5,
2811 data->best_chan.freq_overall);
2812 #endif /* CONFIG_P2P */
2814 case EVENT_UNPROT_DEAUTH:
2815 wpa_supplicant_event_unprot_deauth(wpa_s,
2816 &data->unprot_deauth);
2818 case EVENT_UNPROT_DISASSOC:
2819 wpa_supplicant_event_unprot_disassoc(wpa_s,
2820 &data->unprot_disassoc);
2822 case EVENT_STATION_LOW_ACK:
2824 if (wpa_s->ap_iface && data)
2825 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2826 data->low_ack.addr);
2827 #endif /* CONFIG_AP */
2830 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2831 #endif /* CONFIG_TDLS */
2833 case EVENT_IBSS_PEER_LOST:
2834 #ifdef CONFIG_IBSS_RSN
2835 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2836 #endif /* CONFIG_IBSS_RSN */
2838 case EVENT_DRIVER_GTK_REKEY:
2839 if (os_memcmp(data->driver_gtk_rekey.bssid,
2840 wpa_s->bssid, ETH_ALEN))
2844 wpa_sm_update_replay_ctr(wpa_s->wpa,
2845 data->driver_gtk_rekey.replay_ctr);
2847 case EVENT_SCHED_SCAN_STOPPED:
2848 wpa_s->sched_scanning = 0;
2849 wpa_supplicant_notify_scanning(wpa_s, 0);
2851 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2855 * If we timed out, start a new sched scan to continue
2856 * searching for more SSIDs.
2858 if (wpa_s->sched_scan_timed_out)
2859 wpa_supplicant_req_sched_scan(wpa_s);
2861 case EVENT_WPS_BUTTON_PUSHED:
2863 wpas_wps_start_pbc(wpa_s, NULL, 0);
2864 #endif /* CONFIG_WPS */
2867 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);