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 wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
48 struct wpa_ssid *ssid, *old_ssid;
50 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
53 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
55 ssid = wpa_supplicant_get_ssid(wpa_s);
57 wpa_msg(wpa_s, MSG_INFO,
58 "No network configuration found for the current AP");
62 if (wpas_network_disabled(wpa_s, ssid)) {
63 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
67 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
69 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
71 size_t wpa_ie_len = sizeof(wpa_ie);
72 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
75 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
78 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
79 eapol_sm_invalidate_cached_session(wpa_s->eapol);
80 old_ssid = wpa_s->current_ssid;
81 wpa_s->current_ssid = ssid;
82 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
83 wpa_supplicant_initiate_eapol(wpa_s);
84 if (old_ssid != wpa_s->current_ssid)
85 wpas_notify_network_changed(wpa_s);
91 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
93 struct wpa_supplicant *wpa_s = eloop_ctx;
95 if (wpa_s->countermeasures) {
96 wpa_s->countermeasures = 0;
97 wpa_drv_set_countermeasures(wpa_s, 0);
98 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
99 wpa_supplicant_req_scan(wpa_s, 0, 0);
104 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
108 wnm_bss_keep_alive_deinit(wpa_s);
110 #ifdef CONFIG_IBSS_RSN
111 ibss_rsn_deinit(wpa_s->ibss_rsn);
112 wpa_s->ibss_rsn = NULL;
113 #endif /* CONFIG_IBSS_RSN */
116 wpa_supplicant_ap_deinit(wpa_s);
117 #endif /* CONFIG_AP */
119 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
122 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
123 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
124 os_memset(wpa_s->bssid, 0, ETH_ALEN);
125 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
127 wpa_s->sme.prev_bssid_set = 0;
128 #endif /* CONFIG_SME */
130 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
131 #endif /* CONFIG_P2P */
132 wpa_s->current_bss = NULL;
133 wpa_s->assoc_freq = 0;
134 #ifdef CONFIG_IEEE80211R
136 if (wpa_s->sme.ft_ies)
137 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
138 #endif /* CONFIG_SME */
139 #endif /* CONFIG_IEEE80211R */
142 wpas_notify_bssid_changed(wpa_s);
144 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
145 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
146 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
147 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
148 wpa_s->ap_ies_from_associnfo = 0;
152 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
154 struct wpa_ie_data ie;
158 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
162 for (i = 0; i < ie.num_pmkid; i++) {
163 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
164 ie.pmkid + i * PMKID_LEN,
166 if (pmksa_set == 0) {
167 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
172 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
173 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
177 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
178 union wpa_event_data *data)
181 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
185 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
186 " index=%d preauth=%d",
187 MAC2STR(data->pmkid_candidate.bssid),
188 data->pmkid_candidate.index,
189 data->pmkid_candidate.preauth);
191 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
192 data->pmkid_candidate.index,
193 data->pmkid_candidate.preauth);
197 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
199 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
200 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
203 #ifdef IEEE8021X_EAPOL
204 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
205 wpa_s->current_ssid &&
206 !(wpa_s->current_ssid->eapol_flags &
207 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
208 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
209 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
210 * plaintext or static WEP keys). */
213 #endif /* IEEE8021X_EAPOL */
220 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
221 * @wpa_s: pointer to wpa_supplicant data
222 * @ssid: Configuration data for the network
223 * Returns: 0 on success, -1 on failure
225 * This function is called when starting authentication with a network that is
226 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
228 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
229 struct wpa_ssid *ssid)
231 #ifdef IEEE8021X_EAPOL
233 int aka = 0, sim = 0, type;
235 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
238 if (ssid->eap.eap_methods == NULL) {
242 struct eap_method_type *eap = ssid->eap.eap_methods;
243 while (eap->vendor != EAP_VENDOR_IETF ||
244 eap->method != EAP_TYPE_NONE) {
245 if (eap->vendor == EAP_VENDOR_IETF) {
246 if (eap->method == EAP_TYPE_SIM)
248 else if (eap->method == EAP_TYPE_AKA ||
249 eap->method == EAP_TYPE_AKA_PRIME)
256 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
258 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
259 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
264 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
265 "use SIM, but neither EAP-SIM nor EAP-AKA are "
270 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
271 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
273 type = SCARD_TRY_BOTH;
275 type = SCARD_USIM_ONLY;
277 type = SCARD_GSM_SIM_ONLY;
279 wpa_s->scard = scard_init(type, NULL);
280 if (wpa_s->scard == NULL) {
281 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
285 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
286 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
287 #endif /* PCSC_FUNCS */
288 #endif /* IEEE8021X_EAPOL */
294 #ifndef CONFIG_NO_SCAN_PROCESSING
295 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
296 struct wpa_ssid *ssid)
300 if (ssid->mixed_cell)
304 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
306 #endif /* CONFIG_WPS */
308 for (i = 0; i < NUM_WEP_KEYS; i++) {
309 if (ssid->wep_key_len[i]) {
314 #ifdef IEEE8021X_EAPOL
315 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
316 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
317 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
319 #endif /* IEEE8021X_EAPOL */
321 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
324 if (bss->caps & IEEE80211_CAP_PRIVACY)
330 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
331 struct wpa_ssid *ssid,
332 struct wpa_scan_res *bss)
334 struct wpa_ie_data ie;
336 const u8 *rsn_ie, *wpa_ie;
340 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
344 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
345 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
346 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
347 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
348 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
350 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
351 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
354 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
355 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
361 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
363 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
368 if (!(ie.proto & ssid->proto)) {
369 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
374 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
375 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
380 if (!(ie.group_cipher & ssid->group_cipher)) {
381 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
386 if (!(ie.key_mgmt & ssid->key_mgmt)) {
387 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
392 #ifdef CONFIG_IEEE80211W
393 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
394 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
395 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
399 #endif /* CONFIG_IEEE80211W */
401 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
405 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
406 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
409 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
410 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
416 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
418 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
423 if (!(ie.proto & ssid->proto)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
429 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
435 if (!(ie.group_cipher & ssid->group_cipher)) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
441 if (!(ie.key_mgmt & ssid->key_mgmt)) {
442 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
447 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
451 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
452 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
453 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
457 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
458 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
462 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
469 static int freq_allowed(int *freqs, int freq)
476 for (i = 0; freqs[i]; i++)
477 if (freqs[i] == freq)
483 static int ht_supported(const struct hostapd_hw_modes *mode)
485 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
487 * The driver did not indicate whether it supports HT. Assume
488 * it does to avoid connection issues.
494 * IEEE Std 802.11n-2009 20.1.1:
495 * An HT non-AP STA shall support all EQM rates for one spatial stream.
497 return mode->mcs_set[0] == 0xff;
501 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
503 const struct hostapd_hw_modes *mode = NULL, *modes;
504 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
509 return 1; /* Cannot do matching without knowing band */
511 modes = wpa_s->hw.modes;
514 * The driver does not provide any additional information
515 * about the utilized hardware, so allow the connection attempt
521 for (i = 0; i < wpa_s->hw.num_modes; i++) {
522 for (j = 0; j < modes[i].num_channels; j++) {
523 int freq = modes[i].channels[j].freq;
524 if (freq == bss->freq) {
526 mode->mode == HOSTAPD_MODE_IEEE80211G)
527 break; /* do not allow 802.11b replace
538 for (i = 0; i < (int) sizeof(scan_ie); i++) {
539 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
543 for (j = 2; j < rate_ie[1] + 2; j++) {
544 int flagged = !!(rate_ie[j] & 0x80);
545 int r = (rate_ie[j] & 0x7f) * 5;
548 * IEEE Std 802.11n-2009 7.3.2.2:
549 * The new BSS Membership selector value is encoded
550 * like a legacy basic rate, but it is not a rate and
551 * only indicates if the BSS members are required to
552 * support the mandatory features of Clause 20 [HT PHY]
553 * in order to join the BSS.
555 if (flagged && ((rate_ie[j] & 0x7f) ==
556 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
557 if (!ht_supported(mode)) {
558 wpa_dbg(wpa_s, MSG_DEBUG,
559 " hardware does not support "
569 /* check for legacy basic rates */
570 for (k = 0; k < mode->num_rates; k++) {
571 if (mode->rates[k] == r)
574 if (k == mode->num_rates) {
576 * IEEE Std 802.11-2007 7.3.2.2 demands that in
577 * order to join a BSS all required rates
578 * have to be supported by the hardware.
580 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
581 "not support required rate %d.%d Mbps",
592 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
593 int i, struct wpa_scan_res *bss,
594 struct wpa_ssid *group)
597 u8 wpa_ie_len, rsn_ie_len, ssid_len;
599 struct wpa_blacklist *e;
601 struct wpa_ssid *ssid;
603 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
604 ssid_ = ie ? ie + 2 : (u8 *) "";
605 ssid_len = ie ? ie[1] : 0;
607 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
608 wpa_ie_len = ie ? ie[1] : 0;
610 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
611 rsn_ie_len = ie ? ie[1] : 0;
613 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
614 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
615 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
616 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
617 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
619 e = wpa_blacklist_get(wpa_s, bss->bssid);
622 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
624 * When only a single network is enabled, we can
625 * trigger blacklisting on the first failure. This
626 * should not be done with multiple enabled networks to
627 * avoid getting forced to move into a worse ESS on
628 * single error if there are no other BSSes of the
633 if (e->count > limit) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
635 "(count=%d limit=%d)", e->count, limit);
641 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
645 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
647 for (ssid = group; ssid; ssid = ssid->pnext) {
648 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
650 if (wpas_network_disabled(wpa_s, ssid)) {
651 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
656 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
657 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
662 if (wpa && ssid->ssid_len == 0 &&
663 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
666 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
667 /* Only allow wildcard SSID match if an AP
668 * advertises active WPS operation that matches
671 if (ssid->ssid_len == 0 &&
672 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
675 #endif /* CONFIG_WPS */
677 if (ssid->bssid_set && ssid->ssid_len == 0 &&
678 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
682 (ssid_len != ssid->ssid_len ||
683 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
684 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
688 if (ssid->bssid_set &&
689 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
690 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
694 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
698 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
699 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
700 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
706 if (!wpa_supplicant_match_privacy(bss, ssid)) {
707 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
712 if (bss->caps & IEEE80211_CAP_IBSS) {
713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
718 if (!freq_allowed(ssid->freq_list, bss->freq)) {
719 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
724 if (!rate_match(wpa_s, bss)) {
725 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
732 * TODO: skip the AP if its P2P IE has Group Formation
733 * bit set in the P2P Group Capability Bitmap and we
734 * are not in Group Formation with that device.
736 #endif /* CONFIG_P2P */
738 /* Matching configuration found */
742 /* No matching configuration found */
747 static struct wpa_bss *
748 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
749 struct wpa_scan_results *scan_res,
750 struct wpa_ssid *group,
751 struct wpa_ssid **selected_ssid)
755 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
758 for (i = 0; i < scan_res->num; i++) {
759 struct wpa_scan_res *bss = scan_res->res[i];
763 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
767 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
768 ssid = ie ? ie + 2 : (u8 *) "";
769 ssid_len = ie ? ie[1] : 0;
771 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
773 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
774 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
781 static struct wpa_bss *
782 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
783 struct wpa_scan_results *scan_res,
784 struct wpa_ssid **selected_ssid)
786 struct wpa_bss *selected = NULL;
789 while (selected == NULL) {
790 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
791 selected = wpa_supplicant_select_bss(
792 wpa_s, scan_res, wpa_s->conf->pssid[prio],
798 if (selected == NULL && wpa_s->blacklist &&
799 !wpa_s->countermeasures) {
800 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
801 "blacklist and try again");
802 wpa_blacklist_clear(wpa_s);
803 wpa_s->blacklist_cleared++;
804 } else if (selected == NULL)
812 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
813 int timeout_sec, int timeout_usec)
815 if (!wpa_supplicant_enabled_networks(wpa_s)) {
817 * No networks are enabled; short-circuit request so
818 * we don't wait timeout seconds before transitioning
821 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
824 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
828 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
829 struct wpa_bss *selected,
830 struct wpa_ssid *ssid)
832 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
833 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
834 "PBC session overlap");
836 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
838 #endif /* CONFIG_P2P */
841 wpas_wps_cancel(wpa_s);
842 #endif /* CONFIG_WPS */
847 * Do not trigger new association unless the BSSID has changed or if
848 * reassociation is requested. If we are in process of associating with
849 * the selected BSSID, do not trigger new attempt.
851 if (wpa_s->reassociate ||
852 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
853 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
854 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
855 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
857 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
858 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
861 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
862 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
863 " pending: " MACSTR " wpa_state: %s",
864 wpa_s->reassociate, MAC2STR(selected->bssid),
865 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
866 wpa_supplicant_state_txt(wpa_s->wpa_state));
867 wpa_supplicant_associate(wpa_s, selected, ssid);
869 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
877 static struct wpa_ssid *
878 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
881 struct wpa_ssid *ssid;
883 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
884 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
886 if (wpas_network_disabled(wpa_s, ssid))
888 if (ssid->mode == IEEE80211_MODE_IBSS ||
889 ssid->mode == IEEE80211_MODE_AP)
897 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
898 * on BSS added and BSS changed events */
899 static void wpa_supplicant_rsn_preauth_scan_results(
900 struct wpa_supplicant *wpa_s)
904 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
907 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
908 const u8 *ssid, *rsn;
910 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
914 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
918 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
924 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
925 struct wpa_bss *selected,
926 struct wpa_ssid *ssid,
927 struct wpa_scan_results *scan_res)
930 struct wpa_scan_res *current_bss = NULL;
933 if (wpa_s->reassociate)
934 return 1; /* explicit request to reassociate */
935 if (wpa_s->wpa_state < WPA_ASSOCIATED)
936 return 1; /* we are not associated; continue */
937 if (wpa_s->current_ssid == NULL)
938 return 1; /* unknown current SSID */
939 if (wpa_s->current_ssid != ssid)
940 return 1; /* different network block */
942 if (wpas_driver_bss_selection(wpa_s))
943 return 0; /* Driver-based roaming */
945 for (i = 0; i < scan_res->num; i++) {
946 struct wpa_scan_res *res = scan_res->res[i];
948 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
951 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
954 if (ie[1] != wpa_s->current_ssid->ssid_len ||
955 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
962 return 1; /* current BSS not seen in scan results */
964 #ifndef CONFIG_NO_ROAMING
965 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
966 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
967 MAC2STR(current_bss->bssid), current_bss->level);
968 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
969 MAC2STR(selected->bssid), selected->level);
971 if (wpa_s->current_ssid->bssid_set &&
972 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
974 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
975 "has preferred BSSID");
980 if (current_bss->level < 0) {
981 if (current_bss->level < -85)
983 else if (current_bss->level < -80)
985 else if (current_bss->level < -75)
987 else if (current_bss->level < -70)
992 if (abs(current_bss->level - selected->level) < min_diff) {
993 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
999 #else /* CONFIG_NO_ROAMING */
1001 #endif /* CONFIG_NO_ROAMING */
1005 /* Return < 0 if no scan results could be fetched or if scan results should not
1006 * be shared with other virtual interfaces. */
1007 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1008 union wpa_event_data *data)
1010 struct wpa_bss *selected;
1011 struct wpa_ssid *ssid = NULL;
1012 struct wpa_scan_results *scan_res;
1016 if (wpa_s->ap_iface)
1018 #endif /* CONFIG_AP */
1020 wpa_supplicant_notify_scanning(wpa_s, 0);
1023 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1024 wpa_s->global->p2p != NULL) {
1025 wpa_s->p2p_cb_on_scan_complete = 0;
1026 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1027 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1028 "stopped scan processing");
1032 #endif /* CONFIG_P2P */
1034 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1035 data ? &data->scan_info :
1037 if (scan_res == NULL) {
1038 if (wpa_s->conf->ap_scan == 2 || ap)
1040 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1042 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1046 #ifndef CONFIG_NO_RANDOM_POOL
1048 num = scan_res->num;
1051 for (i = 0; i < num; i++) {
1053 struct wpa_scan_res *res = scan_res->res[i];
1054 buf[0] = res->bssid[5];
1055 buf[1] = res->qual & 0xff;
1056 buf[2] = res->noise & 0xff;
1057 buf[3] = res->level & 0xff;
1058 buf[4] = res->tsf & 0xff;
1059 random_add_randomness(buf, sizeof(buf));
1061 #endif /* CONFIG_NO_RANDOM_POOL */
1063 if (wpa_s->scan_res_handler) {
1064 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1065 struct wpa_scan_results *scan_res);
1067 scan_res_handler = wpa_s->scan_res_handler;
1068 wpa_s->scan_res_handler = NULL;
1069 scan_res_handler(wpa_s, scan_res);
1071 wpa_scan_results_free(scan_res);
1076 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1078 if (wpa_s->ap_iface->scan_cb)
1079 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1080 #endif /* CONFIG_AP */
1081 wpa_scan_results_free(scan_res);
1085 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1086 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1087 wpas_notify_scan_results(wpa_s);
1089 wpas_notify_scan_done(wpa_s, 1);
1091 if (sme_proc_obss_scan(wpa_s) > 0) {
1092 wpa_scan_results_free(scan_res);
1096 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1097 wpa_scan_results_free(scan_res);
1101 if (autoscan_notify_scan(wpa_s, scan_res)) {
1102 wpa_scan_results_free(scan_res);
1106 if (wpa_s->disconnected) {
1107 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1108 wpa_scan_results_free(scan_res);
1112 if (!wpas_driver_bss_selection(wpa_s) &&
1113 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1114 wpa_scan_results_free(scan_res);
1118 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1122 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1124 wpa_scan_results_free(scan_res);
1126 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1130 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1131 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1134 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1136 wpa_scan_results_free(scan_res);
1137 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1138 ssid = wpa_supplicant_pick_new_network(wpa_s);
1140 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1141 wpa_supplicant_associate(wpa_s, NULL, ssid);
1142 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1144 int timeout_sec = wpa_s->scan_interval;
1145 int timeout_usec = 0;
1147 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1150 if (wpa_s->p2p_in_provisioning) {
1152 * Use shorter wait during P2P Provisioning
1153 * state to speed up group formation.
1156 timeout_usec = 250000;
1157 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1161 #endif /* CONFIG_P2P */
1162 if (wpa_supplicant_req_sched_scan(wpa_s))
1163 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1171 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1172 union wpa_event_data *data)
1174 const char *rn, *rn2;
1175 struct wpa_supplicant *ifs;
1177 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1179 * If no scan results could be fetched, then no need to
1180 * notify those interfaces that did not actually request
1187 * Check other interfaces to see if they have the same radio-name. If
1188 * so, they get updated with this same scan info.
1190 if (!wpa_s->driver->get_radio_name)
1193 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1194 if (rn == NULL || rn[0] == '\0')
1197 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1198 "sharing same radio (%s) in event_scan_results", rn);
1200 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1201 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1204 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1205 if (rn2 && os_strcmp(rn, rn2) == 0) {
1206 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1207 "sibling", ifs->ifname);
1208 _wpa_supplicant_event_scan_results(ifs, data);
1213 #endif /* CONFIG_NO_SCAN_PROCESSING */
1218 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1220 struct wpa_supplicant *wpa_s = eloop_ctx;
1222 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1225 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1226 MAC2STR(wpa_s->bssid));
1227 /* TODO: could skip this if normal data traffic has been sent */
1228 /* TODO: Consider using some more appropriate data frame for this */
1230 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1233 if (wpa_s->sme.bss_max_idle_period) {
1235 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1238 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1239 wnm_bss_keep_alive, wpa_s, NULL);
1241 #endif /* CONFIG_SME */
1245 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1246 const u8 *ies, size_t ies_len)
1248 struct ieee802_11_elems elems;
1253 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1257 if (elems.bss_max_idle_period) {
1259 wpa_s->sme.bss_max_idle_period =
1260 WPA_GET_LE16(elems.bss_max_idle_period);
1261 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1262 "TU)%s", wpa_s->sme.bss_max_idle_period,
1263 (elems.bss_max_idle_period[2] & 0x01) ?
1264 " (protected keep-live required)" : "");
1265 if (wpa_s->sme.bss_max_idle_period == 0)
1266 wpa_s->sme.bss_max_idle_period = 1;
1267 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1268 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1269 /* msec times 1000 */
1270 msec = wpa_s->sme.bss_max_idle_period * 1024;
1273 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1274 wnm_bss_keep_alive, wpa_s,
1278 #endif /* CONFIG_SME */
1281 #endif /* CONFIG_WNM */
1284 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1287 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1288 #endif /* CONFIG_WNM */
1292 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1293 union wpa_event_data *data)
1295 int l, len, found = 0, wpa_found, rsn_found;
1298 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1299 if (data->assoc_info.req_ies)
1300 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1301 data->assoc_info.req_ies_len);
1302 if (data->assoc_info.resp_ies) {
1303 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1304 data->assoc_info.resp_ies_len);
1306 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1307 data->assoc_info.resp_ies_len);
1308 #endif /* CONFIG_TDLS */
1310 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1311 data->assoc_info.resp_ies_len);
1312 #endif /* CONFIG_WNM */
1314 if (data->assoc_info.beacon_ies)
1315 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1316 data->assoc_info.beacon_ies,
1317 data->assoc_info.beacon_ies_len);
1318 if (data->assoc_info.freq)
1319 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1320 data->assoc_info.freq);
1322 p = data->assoc_info.req_ies;
1323 l = data->assoc_info.req_ies_len;
1325 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1326 while (p && l >= 2) {
1329 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1333 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1334 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1335 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1336 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1339 wpa_find_assoc_pmkid(wpa_s);
1345 if (!found && data->assoc_info.req_ies)
1346 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1348 #ifdef CONFIG_IEEE80211R
1350 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1352 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1353 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1354 data->assoc_info.resp_ies,
1355 data->assoc_info.resp_ies_len,
1357 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1358 "Reassociation Response failed");
1359 wpa_supplicant_deauthenticate(
1360 wpa_s, WLAN_REASON_INVALID_IE);
1365 p = data->assoc_info.resp_ies;
1366 l = data->assoc_info.resp_ies_len;
1368 #ifdef CONFIG_WPS_STRICT
1369 if (p && wpa_s->current_ssid &&
1370 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1372 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1374 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1375 "include WPS IE in (Re)Association Response");
1379 if (wps_validate_assoc_resp(wps) < 0) {
1381 wpa_supplicant_deauthenticate(
1382 wpa_s, WLAN_REASON_INVALID_IE);
1387 #endif /* CONFIG_WPS_STRICT */
1389 /* Go through the IEs and make a copy of the MDIE, if present. */
1390 while (p && l >= 2) {
1393 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1397 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1398 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1399 wpa_s->sme.ft_used = 1;
1400 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1401 MOBILITY_DOMAIN_ID_LEN);
1407 #endif /* CONFIG_SME */
1409 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1410 data->assoc_info.resp_ies_len);
1411 #endif /* CONFIG_IEEE80211R */
1413 /* WPA/RSN IE from Beacon/ProbeResp */
1414 p = data->assoc_info.beacon_ies;
1415 l = data->assoc_info.beacon_ies_len;
1417 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1419 wpa_found = rsn_found = 0;
1420 while (p && l >= 2) {
1423 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1428 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1429 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1431 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1435 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1437 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1444 if (!wpa_found && data->assoc_info.beacon_ies)
1445 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1446 if (!rsn_found && data->assoc_info.beacon_ies)
1447 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1448 if (wpa_found || rsn_found)
1449 wpa_s->ap_ies_from_associnfo = 1;
1451 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1452 wpa_s->assoc_freq != data->assoc_info.freq) {
1453 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1455 wpa_s->assoc_freq, data->assoc_info.freq);
1456 wpa_supplicant_update_scan_results(wpa_s);
1459 wpa_s->assoc_freq = data->assoc_info.freq;
1465 static struct wpa_bss * wpa_supplicant_get_new_bss(
1466 struct wpa_supplicant *wpa_s, const u8 *bssid)
1468 struct wpa_bss *bss = NULL;
1469 struct wpa_ssid *ssid = wpa_s->current_ssid;
1471 if (ssid->ssid_len > 0)
1472 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1474 bss = wpa_bss_get_bssid(wpa_s, bssid);
1480 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1482 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1484 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1487 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1490 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1491 WPA_IE_VENDOR_TYPE);
1492 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1494 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1495 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1496 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1497 bss_rsn ? 2 + bss_rsn[1] : 0))
1504 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1505 union wpa_event_data *data)
1510 struct wpa_driver_capa capa;
1513 if (wpa_s->ap_iface) {
1514 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1515 data->assoc_info.addr,
1516 data->assoc_info.req_ies,
1517 data->assoc_info.req_ies_len,
1518 data->assoc_info.reassoc);
1521 #endif /* CONFIG_AP */
1523 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1524 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1527 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1528 if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1529 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1530 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1531 MACSTR, MAC2STR(bssid));
1532 random_add_randomness(bssid, ETH_ALEN);
1533 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1534 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1535 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1537 wpas_notify_bssid_changed(wpa_s);
1539 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1540 wpa_clear_keys(wpa_s, bssid);
1542 if (wpa_supplicant_select_config(wpa_s) < 0) {
1543 wpa_supplicant_disassociate(
1544 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1547 if (wpa_s->current_ssid) {
1548 struct wpa_bss *bss = NULL;
1550 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1552 wpa_supplicant_update_scan_results(wpa_s);
1554 /* Get the BSS from the new scan results */
1555 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1559 wpa_s->current_bss = bss;
1562 if (wpa_s->conf->ap_scan == 1 &&
1563 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1564 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1565 wpa_msg(wpa_s, MSG_WARNING,
1566 "WPA/RSN IEs not updated");
1571 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1572 wpa_s->sme.prev_bssid_set = 1;
1573 #endif /* CONFIG_SME */
1575 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1576 if (wpa_s->current_ssid) {
1577 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1578 * initialized before association, but for other modes,
1579 * initialize PC/SC here, if the current configuration needs
1580 * smartcard or SIM/USIM. */
1581 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1583 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1585 l2_packet_notify_auth_start(wpa_s->l2);
1588 * Set portEnabled first to FALSE in order to get EAP state machine out
1589 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1590 * state machine may transit to AUTHENTICATING state based on obsolete
1591 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1592 * AUTHENTICATED without ever giving chance to EAP state machine to
1595 if (!ft_completed) {
1596 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1597 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1599 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1600 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1601 /* 802.1X::portControl = Auto */
1602 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1603 wpa_s->eapol_received = 0;
1604 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1605 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1606 (wpa_s->current_ssid &&
1607 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1608 wpa_supplicant_cancel_auth_timeout(wpa_s);
1609 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1610 } else if (!ft_completed) {
1611 /* Timeout for receiving the first EAPOL packet */
1612 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1614 wpa_supplicant_cancel_scan(wpa_s);
1616 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1617 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1619 * We are done; the driver will take care of RSN 4-way
1622 wpa_supplicant_cancel_auth_timeout(wpa_s);
1623 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1624 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1625 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1626 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1627 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1629 * The driver will take care of RSN 4-way handshake, so we need
1630 * to allow EAPOL supplicant to complete its work without
1631 * waiting for WPA supplicant.
1633 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1634 } else if (ft_completed) {
1636 * FT protocol completed - make sure EAPOL state machine ends
1637 * up in authenticated.
1639 wpa_supplicant_cancel_auth_timeout(wpa_s);
1640 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1641 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1642 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1645 if (wpa_s->pending_eapol_rx) {
1646 struct os_time now, age;
1648 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1649 if (age.sec == 0 && age.usec < 100000 &&
1650 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1652 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1653 "frame that was received just before "
1654 "association notification");
1655 wpa_supplicant_rx_eapol(
1656 wpa_s, wpa_s->pending_eapol_rx_src,
1657 wpabuf_head(wpa_s->pending_eapol_rx),
1658 wpabuf_len(wpa_s->pending_eapol_rx));
1660 wpabuf_free(wpa_s->pending_eapol_rx);
1661 wpa_s->pending_eapol_rx = NULL;
1664 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1665 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1666 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1667 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1668 /* Set static WEP keys again */
1669 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1672 #ifdef CONFIG_IBSS_RSN
1673 if (wpa_s->current_ssid &&
1674 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1675 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1676 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1677 wpa_s->ibss_rsn == NULL) {
1678 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1679 if (!wpa_s->ibss_rsn) {
1680 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1681 wpa_supplicant_deauthenticate(
1682 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1686 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1688 #endif /* CONFIG_IBSS_RSN */
1692 static int disconnect_reason_recoverable(u16 reason_code)
1694 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1695 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1696 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1700 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1702 int locally_generated)
1706 u8 prev_pending_bssid[ETH_ALEN];
1707 struct wpa_bss *fast_reconnect = NULL;
1708 struct wpa_ssid *fast_reconnect_ssid = NULL;
1710 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1711 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1713 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1715 * At least Host AP driver and a Prism3 card seemed to be
1716 * generating streams of disconnected events when configuring
1717 * IBSS for WPA-None. Ignore them for now.
1719 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1720 "IBSS/WPA-None mode");
1724 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1725 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1726 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1727 "pre-shared key may be incorrect");
1729 if (!wpa_s->auto_reconnect_disabled ||
1730 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1731 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1732 "reconnect (wps=%d wpa_state=%d)",
1733 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1735 if (wpa_s->wpa_state == WPA_COMPLETED &&
1736 wpa_s->current_ssid &&
1737 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1738 !locally_generated &&
1739 disconnect_reason_recoverable(reason_code)) {
1741 * It looks like the AP has dropped association with
1742 * us, but could allow us to get back in. Try to
1743 * reconnect to the same BSS without full scan to save
1744 * time for some common cases.
1746 fast_reconnect = wpa_s->current_bss;
1747 fast_reconnect_ssid = wpa_s->current_ssid;
1748 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1749 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1751 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1754 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1755 "try to re-connect");
1756 wpa_s->reassociate = 0;
1757 wpa_s->disconnected = 1;
1758 wpa_supplicant_cancel_sched_scan(wpa_s);
1760 bssid = wpa_s->bssid;
1761 if (is_zero_ether_addr(bssid))
1762 bssid = wpa_s->pending_bssid;
1763 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1764 wpas_connection_failed(wpa_s, bssid);
1765 wpa_sm_notify_disassoc(wpa_s->wpa);
1766 if (locally_generated)
1767 wpa_s->disconnect_reason = -reason_code;
1769 wpa_s->disconnect_reason = reason_code;
1770 wpas_notify_disconnect_reason(wpa_s);
1771 if (!is_zero_ether_addr(bssid) ||
1772 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1773 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1775 MAC2STR(bssid), reason_code,
1776 locally_generated ? " locally_generated=1" : "");
1778 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1779 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1780 wpa_s->keys_cleared = 0;
1781 wpa_clear_keys(wpa_s, wpa_s->bssid);
1783 wpa_supplicant_mark_disassoc(wpa_s);
1785 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1786 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1788 if (fast_reconnect) {
1789 #ifndef CONFIG_NO_SCAN_PROCESSING
1790 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1791 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1792 fast_reconnect_ssid) < 0) {
1793 /* Recover through full scan */
1794 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1796 #endif /* CONFIG_NO_SCAN_PROCESSING */
1801 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1802 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1804 struct wpa_supplicant *wpa_s = eloop_ctx;
1806 if (!wpa_s->pending_mic_error_report)
1809 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1810 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1811 wpa_s->pending_mic_error_report = 0;
1813 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1817 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1818 union wpa_event_data *data)
1823 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1824 pairwise = (data && data->michael_mic_failure.unicast);
1826 if ((wpa_s->last_michael_mic_error &&
1827 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1828 wpa_s->pending_mic_error_report) {
1829 if (wpa_s->pending_mic_error_report) {
1831 * Send the pending MIC error report immediately since
1832 * we are going to start countermeasures and AP better
1835 wpa_sm_key_request(wpa_s->wpa, 1,
1836 wpa_s->pending_mic_error_pairwise);
1839 /* Send the new MIC error report immediately since we are going
1840 * to start countermeasures and AP better do the same.
1842 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1844 /* initialize countermeasures */
1845 wpa_s->countermeasures = 1;
1847 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1849 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1852 * Need to wait for completion of request frame. We do not get
1853 * any callback for the message completion, so just wait a
1854 * short while and hope for the best. */
1857 wpa_drv_set_countermeasures(wpa_s, 1);
1858 wpa_supplicant_deauthenticate(wpa_s,
1859 WLAN_REASON_MICHAEL_MIC_FAILURE);
1860 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1862 eloop_register_timeout(60, 0,
1863 wpa_supplicant_stop_countermeasures,
1865 /* TODO: mark the AP rejected for 60 second. STA is
1866 * allowed to associate with another AP.. */
1868 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1869 if (wpa_s->mic_errors_seen) {
1871 * Reduce the effectiveness of Michael MIC error
1872 * reports as a means for attacking against TKIP if
1873 * more than one MIC failure is noticed with the same
1874 * PTK. We delay the transmission of the reports by a
1875 * random time between 0 and 60 seconds in order to
1876 * force the attacker wait 60 seconds before getting
1877 * the information on whether a frame resulted in a MIC
1883 if (os_get_random(rval, sizeof(rval)) < 0)
1884 sec = os_random() % 60;
1886 sec = WPA_GET_BE32(rval) % 60;
1887 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1888 "report %d seconds", sec);
1889 wpa_s->pending_mic_error_report = 1;
1890 wpa_s->pending_mic_error_pairwise = pairwise;
1891 eloop_cancel_timeout(
1892 wpa_supplicant_delayed_mic_error_report,
1894 eloop_register_timeout(
1895 sec, os_random() % 1000000,
1896 wpa_supplicant_delayed_mic_error_report,
1899 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1901 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1902 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1903 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1905 wpa_s->last_michael_mic_error = t.sec;
1906 wpa_s->mic_errors_seen++;
1910 #ifdef CONFIG_TERMINATE_ONLASTIF
1911 static int any_interfaces(struct wpa_supplicant *head)
1913 struct wpa_supplicant *wpa_s;
1915 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1916 if (!wpa_s->interface_removed)
1920 #endif /* CONFIG_TERMINATE_ONLASTIF */
1924 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1925 union wpa_event_data *data)
1927 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1930 switch (data->interface_status.ievent) {
1931 case EVENT_INTERFACE_ADDED:
1932 if (!wpa_s->interface_removed)
1934 wpa_s->interface_removed = 0;
1935 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1936 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1937 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1938 "driver after interface was added");
1940 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1942 case EVENT_INTERFACE_REMOVED:
1943 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1944 wpa_s->interface_removed = 1;
1945 wpa_supplicant_mark_disassoc(wpa_s);
1946 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1947 l2_packet_deinit(wpa_s->l2);
1949 #ifdef CONFIG_IBSS_RSN
1950 ibss_rsn_deinit(wpa_s->ibss_rsn);
1951 wpa_s->ibss_rsn = NULL;
1952 #endif /* CONFIG_IBSS_RSN */
1953 #ifdef CONFIG_TERMINATE_ONLASTIF
1954 /* check if last interface */
1955 if (!any_interfaces(wpa_s->global->ifaces))
1957 #endif /* CONFIG_TERMINATE_ONLASTIF */
1963 #ifdef CONFIG_PEERKEY
1965 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1966 union wpa_event_data *data)
1970 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1972 #endif /* CONFIG_PEERKEY */
1976 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
1977 union wpa_event_data *data)
1981 switch (data->tdls.oper) {
1982 case TDLS_REQUEST_SETUP:
1983 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
1985 case TDLS_REQUEST_TEARDOWN:
1986 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
1987 data->tdls.reason_code);
1991 #endif /* CONFIG_TDLS */
1994 #ifdef CONFIG_IEEE80211V
1995 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
1996 union wpa_event_data *data)
2000 switch (data->wnm.oper) {
2001 case WNM_OPER_SLEEP:
2002 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2003 "(action=%d, intval=%d)",
2004 data->wnm.sleep_action, data->wnm.sleep_intval);
2005 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2006 data->wnm.sleep_intval);
2010 #endif /* CONFIG_IEEE80211V */
2013 #ifdef CONFIG_IEEE80211R
2015 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2016 union wpa_event_data *data)
2021 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2022 data->ft_ies.ies_len,
2023 data->ft_ies.ft_action,
2024 data->ft_ies.target_ap,
2025 data->ft_ies.ric_ies,
2026 data->ft_ies.ric_ies_len) < 0) {
2027 /* TODO: prevent MLME/driver from trying to associate? */
2030 #endif /* CONFIG_IEEE80211R */
2033 #ifdef CONFIG_IBSS_RSN
2034 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2035 union wpa_event_data *data)
2037 struct wpa_ssid *ssid;
2038 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2042 ssid = wpa_s->current_ssid;
2045 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2048 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2050 #endif /* CONFIG_IBSS_RSN */
2053 #ifdef CONFIG_IEEE80211R
2054 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2057 const u8 *sta_addr, *target_ap_addr;
2060 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2061 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2062 return; /* only SME case supported for now */
2063 if (len < 1 + 2 * ETH_ALEN + 2)
2066 return; /* Only FT Action Response is supported for now */
2067 sta_addr = data + 1;
2068 target_ap_addr = data + 1 + ETH_ALEN;
2069 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2070 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2071 MACSTR " TargetAP " MACSTR " status %u",
2072 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2074 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2075 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2076 " in FT Action Response", MAC2STR(sta_addr));
2081 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2082 "failure (status code %d)", status);
2083 /* TODO: report error to FT code(?) */
2087 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2088 len - (1 + 2 * ETH_ALEN + 2), 1,
2089 target_ap_addr, NULL, 0) < 0)
2094 struct wpa_bss *bss;
2095 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2097 wpa_s->sme.freq = bss->freq;
2098 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2099 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2102 #endif /* CONFIG_SME */
2104 #endif /* CONFIG_IEEE80211R */
2107 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2108 struct unprot_deauth *e)
2110 #ifdef CONFIG_IEEE80211W
2111 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2112 "dropped: " MACSTR " -> " MACSTR
2113 " (reason code %u)",
2114 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2115 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2116 #endif /* CONFIG_IEEE80211W */
2120 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2121 struct unprot_disassoc *e)
2123 #ifdef CONFIG_IEEE80211W
2124 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2125 "dropped: " MACSTR " -> " MACSTR
2126 " (reason code %u)",
2127 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2128 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2129 #endif /* CONFIG_IEEE80211W */
2133 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2136 const u8 *pos, *end;
2138 if (rx->data == NULL || rx->len == 0)
2142 end = pos + rx->len;
2145 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2146 action, MAC2STR(rx->sa));
2148 case WNM_BSS_TRANS_MGMT_REQ:
2151 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2152 "Request: dialog_token=%u request_mode=0x%x "
2153 "disassoc_timer=%u validity_interval=%u",
2154 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2158 pos += 12; /* BSS Termination Duration */
2161 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2162 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2163 "Transition Management Request "
2167 os_memcpy(url, pos + 1, pos[0]);
2169 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2170 "Imminent - session_info_url=%s", url);
2177 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2178 union wpa_event_data *data)
2180 struct wpa_supplicant *wpa_s = ctx;
2181 u16 reason_code = 0;
2182 int locally_generated = 0;
2184 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2185 event != EVENT_INTERFACE_ENABLED &&
2186 event != EVENT_INTERFACE_STATUS &&
2187 event != EVENT_SCHED_SCAN_STOPPED) {
2188 wpa_dbg(wpa_s, MSG_DEBUG,
2189 "Ignore event %s (%d) while interface is disabled",
2190 event_to_string(event), event);
2194 #ifndef CONFIG_NO_STDOUT_DEBUG
2196 int level = MSG_DEBUG;
2198 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2199 const struct ieee80211_hdr *hdr;
2201 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2202 fc = le_to_host16(hdr->frame_control);
2203 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2204 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2205 level = MSG_EXCESSIVE;
2208 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2209 event_to_string(event), event);
2211 #endif /* CONFIG_NO_STDOUT_DEBUG */
2215 sme_event_auth(wpa_s, data);
2218 wpa_supplicant_event_assoc(wpa_s, data);
2220 case EVENT_DISASSOC:
2221 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2223 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2224 data->disassoc_info.reason_code,
2225 data->disassoc_info.locally_generated ?
2226 " (locally generated)" : "");
2227 if (data->disassoc_info.addr)
2228 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2229 MAC2STR(data->disassoc_info.addr));
2232 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2233 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2234 data->disassoc_info.addr);
2237 if (wpa_s->ap_iface) {
2238 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2242 #endif /* CONFIG_AP */
2244 reason_code = data->disassoc_info.reason_code;
2246 data->disassoc_info.locally_generated;
2247 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2248 data->disassoc_info.ie,
2249 data->disassoc_info.ie_len);
2251 wpas_p2p_disassoc_notif(
2252 wpa_s, data->disassoc_info.addr, reason_code,
2253 data->disassoc_info.ie,
2254 data->disassoc_info.ie_len,
2256 #endif /* CONFIG_P2P */
2258 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2259 sme_event_disassoc(wpa_s, data);
2262 if (event == EVENT_DEAUTH) {
2263 wpa_dbg(wpa_s, MSG_DEBUG,
2264 "Deauthentication notification");
2266 reason_code = data->deauth_info.reason_code;
2268 data->deauth_info.locally_generated;
2269 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2270 data->deauth_info.reason_code,
2271 data->deauth_info.locally_generated ?
2272 " (locally generated)" : "");
2273 if (data->deauth_info.addr) {
2274 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2276 MAC2STR(data->deauth_info.
2279 wpa_hexdump(MSG_DEBUG,
2280 "Deauthentication frame IE(s)",
2281 data->deauth_info.ie,
2282 data->deauth_info.ie_len);
2286 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2287 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2288 data->deauth_info.addr);
2291 if (wpa_s->ap_iface) {
2292 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2296 #endif /* CONFIG_AP */
2297 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2300 if (event == EVENT_DEAUTH && data) {
2301 wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
2303 data->deauth_info.ie,
2304 data->deauth_info.ie_len,
2307 #endif /* CONFIG_P2P */
2309 case EVENT_MICHAEL_MIC_FAILURE:
2310 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2312 #ifndef CONFIG_NO_SCAN_PROCESSING
2313 case EVENT_SCAN_RESULTS:
2314 wpa_supplicant_event_scan_results(wpa_s, data);
2316 #endif /* CONFIG_NO_SCAN_PROCESSING */
2317 case EVENT_ASSOCINFO:
2318 wpa_supplicant_event_associnfo(wpa_s, data);
2320 case EVENT_INTERFACE_STATUS:
2321 wpa_supplicant_event_interface_status(wpa_s, data);
2323 case EVENT_PMKID_CANDIDATE:
2324 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2326 #ifdef CONFIG_PEERKEY
2327 case EVENT_STKSTART:
2328 wpa_supplicant_event_stkstart(wpa_s, data);
2330 #endif /* CONFIG_PEERKEY */
2333 wpa_supplicant_event_tdls(wpa_s, data);
2335 #endif /* CONFIG_TDLS */
2336 #ifdef CONFIG_IEEE80211V
2338 wpa_supplicant_event_wnm(wpa_s, data);
2340 #endif /* CONFIG_IEEE80211V */
2341 #ifdef CONFIG_IEEE80211R
2342 case EVENT_FT_RESPONSE:
2343 wpa_supplicant_event_ft_response(wpa_s, data);
2345 #endif /* CONFIG_IEEE80211R */
2346 #ifdef CONFIG_IBSS_RSN
2347 case EVENT_IBSS_RSN_START:
2348 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2350 #endif /* CONFIG_IBSS_RSN */
2351 case EVENT_ASSOC_REJECT:
2352 if (data->assoc_reject.bssid)
2353 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2354 "bssid=" MACSTR " status_code=%u",
2355 MAC2STR(data->assoc_reject.bssid),
2356 data->assoc_reject.status_code);
2358 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2360 data->assoc_reject.status_code);
2361 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2362 sme_event_assoc_reject(wpa_s, data);
2364 case EVENT_AUTH_TIMED_OUT:
2365 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2366 sme_event_auth_timed_out(wpa_s, data);
2368 case EVENT_ASSOC_TIMED_OUT:
2369 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2370 sme_event_assoc_timed_out(wpa_s, data);
2372 case EVENT_TX_STATUS:
2373 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2374 " type=%d stype=%d",
2375 MAC2STR(data->tx_status.dst),
2376 data->tx_status.type, data->tx_status.stype);
2378 if (wpa_s->ap_iface == NULL) {
2379 #ifdef CONFIG_OFFCHANNEL
2380 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2381 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2382 offchannel_send_action_tx_status(
2383 wpa_s, data->tx_status.dst,
2384 data->tx_status.data,
2385 data->tx_status.data_len,
2386 data->tx_status.ack ?
2387 OFFCHANNEL_SEND_ACTION_SUCCESS :
2388 OFFCHANNEL_SEND_ACTION_NO_ACK);
2389 #endif /* CONFIG_OFFCHANNEL */
2392 #endif /* CONFIG_AP */
2393 #ifdef CONFIG_OFFCHANNEL
2394 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2395 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2397 * Catch TX status events for Action frames we sent via group
2398 * interface in GO mode.
2400 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2401 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2402 os_memcmp(wpa_s->parent->pending_action_dst,
2403 data->tx_status.dst, ETH_ALEN) == 0) {
2404 offchannel_send_action_tx_status(
2405 wpa_s->parent, data->tx_status.dst,
2406 data->tx_status.data,
2407 data->tx_status.data_len,
2408 data->tx_status.ack ?
2409 OFFCHANNEL_SEND_ACTION_SUCCESS :
2410 OFFCHANNEL_SEND_ACTION_NO_ACK);
2413 #endif /* CONFIG_OFFCHANNEL */
2415 switch (data->tx_status.type) {
2416 case WLAN_FC_TYPE_MGMT:
2417 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2418 data->tx_status.data_len,
2419 data->tx_status.stype,
2420 data->tx_status.ack);
2422 case WLAN_FC_TYPE_DATA:
2423 ap_tx_status(wpa_s, data->tx_status.dst,
2424 data->tx_status.data,
2425 data->tx_status.data_len,
2426 data->tx_status.ack);
2429 #endif /* CONFIG_AP */
2432 case EVENT_EAPOL_TX_STATUS:
2433 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2434 data->eapol_tx_status.data,
2435 data->eapol_tx_status.data_len,
2436 data->eapol_tx_status.ack);
2438 case EVENT_DRIVER_CLIENT_POLL_OK:
2439 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2441 case EVENT_RX_FROM_UNKNOWN:
2442 if (wpa_s->ap_iface == NULL)
2444 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2445 data->rx_from_unknown.wds);
2447 case EVENT_CH_SWITCH:
2450 if (!wpa_s->ap_iface) {
2451 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2452 "event in non-AP mode");
2457 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2458 data->ch_switch.ht_enabled,
2459 data->ch_switch.ch_offset);
2460 #endif /* CONFIG_AP */
2462 case EVENT_RX_MGMT: {
2464 const struct ieee80211_mgmt *mgmt;
2466 mgmt = (const struct ieee80211_mgmt *)
2467 data->rx_mgmt.frame;
2468 fc = le_to_host16(mgmt->frame_control);
2469 stype = WLAN_FC_GET_STYPE(fc);
2471 if (wpa_s->ap_iface == NULL) {
2473 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2474 data->rx_mgmt.frame_len > 24) {
2475 const u8 *src = mgmt->sa;
2476 const u8 *ie = mgmt->u.probe_req.variable;
2477 size_t ie_len = data->rx_mgmt.frame_len -
2478 (mgmt->u.probe_req.variable -
2479 data->rx_mgmt.frame);
2480 wpas_p2p_probe_req_rx(
2481 wpa_s, src, mgmt->da,
2482 mgmt->bssid, ie, ie_len,
2483 data->rx_mgmt.ssi_signal);
2486 #endif /* CONFIG_P2P */
2487 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2488 "management frame in non-AP mode");
2492 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2493 data->rx_mgmt.frame_len > 24) {
2494 const u8 *ie = mgmt->u.probe_req.variable;
2495 size_t ie_len = data->rx_mgmt.frame_len -
2496 (mgmt->u.probe_req.variable -
2497 data->rx_mgmt.frame);
2499 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2500 mgmt->bssid, ie, ie_len,
2501 data->rx_mgmt.ssi_signal);
2504 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2507 #endif /* CONFIG_AP */
2508 case EVENT_RX_ACTION:
2509 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2510 " Category=%u DataLen=%d freq=%d MHz",
2511 MAC2STR(data->rx_action.sa),
2512 data->rx_action.category, (int) data->rx_action.len,
2513 data->rx_action.freq);
2514 #ifdef CONFIG_IEEE80211R
2515 if (data->rx_action.category == WLAN_ACTION_FT) {
2516 ft_rx_action(wpa_s, data->rx_action.data,
2517 data->rx_action.len);
2520 #endif /* CONFIG_IEEE80211R */
2521 #ifdef CONFIG_IEEE80211W
2523 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2524 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2525 data->rx_action.data,
2526 data->rx_action.len);
2529 #endif /* CONFIG_SME */
2530 #endif /* CONFIG_IEEE80211W */
2531 #ifdef CONFIG_IEEE80211V
2532 if (data->rx_action.category == WLAN_ACTION_WNM) {
2533 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2536 #endif /* CONFIG_IEEE80211V */
2538 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2539 gas_query_rx(wpa_s->gas, data->rx_action.da,
2540 data->rx_action.sa, data->rx_action.bssid,
2541 data->rx_action.data, data->rx_action.len,
2542 data->rx_action.freq) == 0)
2544 #endif /* CONFIG_GAS */
2545 if (data->rx_action.category == WLAN_ACTION_WNM) {
2546 wnm_action_rx(wpa_s, &data->rx_action);
2550 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2551 data->rx_action.len >= 4 &&
2552 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2553 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2554 "Response from " MACSTR,
2555 MAC2STR(data->rx_action.sa));
2558 #endif /* CONFIG_TDLS */
2560 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2562 data->rx_action.bssid,
2563 data->rx_action.category,
2564 data->rx_action.data,
2565 data->rx_action.len, data->rx_action.freq);
2566 #endif /* CONFIG_P2P */
2568 case EVENT_RX_PROBE_REQ:
2569 if (data->rx_probe_req.sa == NULL ||
2570 data->rx_probe_req.ie == NULL)
2573 if (wpa_s->ap_iface) {
2574 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2575 data->rx_probe_req.sa,
2576 data->rx_probe_req.da,
2577 data->rx_probe_req.bssid,
2578 data->rx_probe_req.ie,
2579 data->rx_probe_req.ie_len,
2580 data->rx_probe_req.ssi_signal);
2583 #endif /* CONFIG_AP */
2585 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2586 data->rx_probe_req.da,
2587 data->rx_probe_req.bssid,
2588 data->rx_probe_req.ie,
2589 data->rx_probe_req.ie_len,
2590 data->rx_probe_req.ssi_signal);
2591 #endif /* CONFIG_P2P */
2593 case EVENT_REMAIN_ON_CHANNEL:
2594 #ifdef CONFIG_OFFCHANNEL
2595 offchannel_remain_on_channel_cb(
2596 wpa_s, data->remain_on_channel.freq,
2597 data->remain_on_channel.duration);
2598 #endif /* CONFIG_OFFCHANNEL */
2600 wpas_p2p_remain_on_channel_cb(
2601 wpa_s, data->remain_on_channel.freq,
2602 data->remain_on_channel.duration);
2603 #endif /* CONFIG_P2P */
2605 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2606 #ifdef CONFIG_OFFCHANNEL
2607 offchannel_cancel_remain_on_channel_cb(
2608 wpa_s, data->remain_on_channel.freq);
2609 #endif /* CONFIG_OFFCHANNEL */
2611 wpas_p2p_cancel_remain_on_channel_cb(
2612 wpa_s, data->remain_on_channel.freq);
2613 #endif /* CONFIG_P2P */
2616 case EVENT_P2P_DEV_FOUND: {
2617 struct p2p_peer_info peer_info;
2619 os_memset(&peer_info, 0, sizeof(peer_info));
2620 if (data->p2p_dev_found.dev_addr)
2621 os_memcpy(peer_info.p2p_device_addr,
2622 data->p2p_dev_found.dev_addr, ETH_ALEN);
2623 if (data->p2p_dev_found.pri_dev_type)
2624 os_memcpy(peer_info.pri_dev_type,
2625 data->p2p_dev_found.pri_dev_type,
2626 sizeof(peer_info.pri_dev_type));
2627 if (data->p2p_dev_found.dev_name)
2628 os_strlcpy(peer_info.device_name,
2629 data->p2p_dev_found.dev_name,
2630 sizeof(peer_info.device_name));
2631 peer_info.config_methods = data->p2p_dev_found.config_methods;
2632 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2633 peer_info.group_capab = data->p2p_dev_found.group_capab;
2636 * FIX: new_device=1 is not necessarily correct. We should
2637 * maintain a P2P peer database in wpa_supplicant and update
2638 * this information based on whether the peer is truly new.
2640 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2643 case EVENT_P2P_GO_NEG_REQ_RX:
2644 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2645 data->p2p_go_neg_req_rx.dev_passwd_id);
2647 case EVENT_P2P_GO_NEG_COMPLETED:
2648 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2650 case EVENT_P2P_PROV_DISC_REQUEST:
2651 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2652 data->p2p_prov_disc_req.config_methods,
2653 data->p2p_prov_disc_req.dev_addr,
2654 data->p2p_prov_disc_req.pri_dev_type,
2655 data->p2p_prov_disc_req.dev_name,
2656 data->p2p_prov_disc_req.supp_config_methods,
2657 data->p2p_prov_disc_req.dev_capab,
2658 data->p2p_prov_disc_req.group_capab,
2661 case EVENT_P2P_PROV_DISC_RESPONSE:
2662 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2663 data->p2p_prov_disc_resp.config_methods);
2665 case EVENT_P2P_SD_REQUEST:
2666 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2667 data->p2p_sd_req.sa,
2668 data->p2p_sd_req.dialog_token,
2669 data->p2p_sd_req.update_indic,
2670 data->p2p_sd_req.tlvs,
2671 data->p2p_sd_req.tlvs_len);
2673 case EVENT_P2P_SD_RESPONSE:
2674 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2675 data->p2p_sd_resp.update_indic,
2676 data->p2p_sd_resp.tlvs,
2677 data->p2p_sd_resp.tlvs_len);
2679 #endif /* CONFIG_P2P */
2680 case EVENT_EAPOL_RX:
2681 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2682 data->eapol_rx.data,
2683 data->eapol_rx.data_len);
2685 case EVENT_SIGNAL_CHANGE:
2686 bgscan_notify_signal_change(
2687 wpa_s, data->signal_change.above_threshold,
2688 data->signal_change.current_signal,
2689 data->signal_change.current_noise,
2690 data->signal_change.current_txrate);
2692 case EVENT_INTERFACE_ENABLED:
2693 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2694 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2695 wpa_supplicant_update_mac_addr(wpa_s);
2697 if (!wpa_s->ap_iface) {
2698 wpa_supplicant_set_state(wpa_s,
2700 wpa_supplicant_req_scan(wpa_s, 0, 0);
2702 wpa_supplicant_set_state(wpa_s,
2704 #else /* CONFIG_AP */
2705 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2706 wpa_supplicant_req_scan(wpa_s, 0, 0);
2707 #endif /* CONFIG_AP */
2710 case EVENT_INTERFACE_DISABLED:
2711 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2712 wpa_supplicant_mark_disassoc(wpa_s);
2713 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2715 case EVENT_CHANNEL_LIST_CHANGED:
2716 if (wpa_s->drv_priv == NULL)
2717 break; /* Ignore event during drv initialization */
2719 free_hw_features(wpa_s);
2720 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2721 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2724 wpas_p2p_update_channel_list(wpa_s);
2725 #endif /* CONFIG_P2P */
2727 case EVENT_INTERFACE_UNAVAILABLE:
2729 wpas_p2p_interface_unavailable(wpa_s);
2730 #endif /* CONFIG_P2P */
2732 case EVENT_BEST_CHANNEL:
2733 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2735 data->best_chan.freq_24, data->best_chan.freq_5,
2736 data->best_chan.freq_overall);
2737 wpa_s->best_24_freq = data->best_chan.freq_24;
2738 wpa_s->best_5_freq = data->best_chan.freq_5;
2739 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2741 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2742 data->best_chan.freq_5,
2743 data->best_chan.freq_overall);
2744 #endif /* CONFIG_P2P */
2746 case EVENT_UNPROT_DEAUTH:
2747 wpa_supplicant_event_unprot_deauth(wpa_s,
2748 &data->unprot_deauth);
2750 case EVENT_UNPROT_DISASSOC:
2751 wpa_supplicant_event_unprot_disassoc(wpa_s,
2752 &data->unprot_disassoc);
2754 case EVENT_STATION_LOW_ACK:
2756 if (wpa_s->ap_iface && data)
2757 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2758 data->low_ack.addr);
2759 #endif /* CONFIG_AP */
2762 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2763 #endif /* CONFIG_TDLS */
2765 case EVENT_IBSS_PEER_LOST:
2766 #ifdef CONFIG_IBSS_RSN
2767 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2768 #endif /* CONFIG_IBSS_RSN */
2770 case EVENT_DRIVER_GTK_REKEY:
2771 if (os_memcmp(data->driver_gtk_rekey.bssid,
2772 wpa_s->bssid, ETH_ALEN))
2776 wpa_sm_update_replay_ctr(wpa_s->wpa,
2777 data->driver_gtk_rekey.replay_ctr);
2779 case EVENT_SCHED_SCAN_STOPPED:
2780 wpa_s->sched_scanning = 0;
2781 wpa_supplicant_notify_scanning(wpa_s, 0);
2783 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2787 * If we timed out, start a new sched scan to continue
2788 * searching for more SSIDs.
2790 if (wpa_s->sched_scan_timed_out)
2791 wpa_supplicant_req_sched_scan(wpa_s);
2793 case EVENT_WPS_BUTTON_PUSHED:
2795 wpas_wps_start_pbc(wpa_s, NULL, 0);
2796 #endif /* CONFIG_WPS */
2799 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);