2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
65 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
67 struct wpa_ssid *ssid, *old_ssid;
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
75 ssid = wpa_supplicant_get_ssid(wpa_s);
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
82 if (wpas_network_disabled(wpa_s, ssid)) {
83 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
87 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
88 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
93 res = wpas_temp_disabled(wpa_s, ssid);
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
96 "disabled for %d second(s)", res);
100 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
102 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
104 size_t wpa_ie_len = sizeof(wpa_ie);
105 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
106 wpa_ie, &wpa_ie_len);
108 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
111 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
112 eapol_sm_invalidate_cached_session(wpa_s->eapol);
113 old_ssid = wpa_s->current_ssid;
114 wpa_s->current_ssid = ssid;
115 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
116 wpa_supplicant_initiate_eapol(wpa_s);
117 if (old_ssid != wpa_s->current_ssid)
118 wpas_notify_network_changed(wpa_s);
124 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
126 struct wpa_supplicant *wpa_s = eloop_ctx;
128 if (wpa_s->countermeasures) {
129 wpa_s->countermeasures = 0;
130 wpa_drv_set_countermeasures(wpa_s, 0);
131 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
132 wpa_supplicant_req_scan(wpa_s, 0, 0);
137 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
141 wnm_bss_keep_alive_deinit(wpa_s);
143 #ifdef CONFIG_IBSS_RSN
144 ibss_rsn_deinit(wpa_s->ibss_rsn);
145 wpa_s->ibss_rsn = NULL;
146 #endif /* CONFIG_IBSS_RSN */
149 wpa_supplicant_ap_deinit(wpa_s);
150 #endif /* CONFIG_AP */
152 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
155 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
156 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
157 os_memset(wpa_s->bssid, 0, ETH_ALEN);
158 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
160 wpa_s->sme.prev_bssid_set = 0;
161 #endif /* CONFIG_SME */
163 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
164 #endif /* CONFIG_P2P */
165 wpa_s->current_bss = NULL;
166 wpa_s->assoc_freq = 0;
167 #ifdef CONFIG_IEEE80211R
169 if (wpa_s->sme.ft_ies)
170 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
171 #endif /* CONFIG_SME */
172 #endif /* CONFIG_IEEE80211R */
175 wpas_notify_bssid_changed(wpa_s);
177 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
178 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
179 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
180 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
181 wpa_s->ap_ies_from_associnfo = 0;
182 wpa_s->current_ssid = NULL;
187 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
189 struct wpa_ie_data ie;
193 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
197 for (i = 0; i < ie.num_pmkid; i++) {
198 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
199 ie.pmkid + i * PMKID_LEN,
201 if (pmksa_set == 0) {
202 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
207 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
208 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
212 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
213 union wpa_event_data *data)
216 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
220 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
221 " index=%d preauth=%d",
222 MAC2STR(data->pmkid_candidate.bssid),
223 data->pmkid_candidate.index,
224 data->pmkid_candidate.preauth);
226 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
227 data->pmkid_candidate.index,
228 data->pmkid_candidate.preauth);
232 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
234 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
235 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
238 #ifdef IEEE8021X_EAPOL
239 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
240 wpa_s->current_ssid &&
241 !(wpa_s->current_ssid->eapol_flags &
242 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
243 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
244 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
245 * plaintext or static WEP keys). */
248 #endif /* IEEE8021X_EAPOL */
255 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
256 * @wpa_s: pointer to wpa_supplicant data
257 * @ssid: Configuration data for the network
258 * Returns: 0 on success, -1 on failure
260 * This function is called when starting authentication with a network that is
261 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
263 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
264 struct wpa_ssid *ssid)
266 #ifdef IEEE8021X_EAPOL
268 int aka = 0, sim = 0, type;
270 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
273 if (ssid->eap.eap_methods == NULL) {
277 struct eap_method_type *eap = ssid->eap.eap_methods;
278 while (eap->vendor != EAP_VENDOR_IETF ||
279 eap->method != EAP_TYPE_NONE) {
280 if (eap->vendor == EAP_VENDOR_IETF) {
281 if (eap->method == EAP_TYPE_SIM)
283 else if (eap->method == EAP_TYPE_AKA ||
284 eap->method == EAP_TYPE_AKA_PRIME)
291 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
293 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
294 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
299 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
300 "use SIM, but neither EAP-SIM nor EAP-AKA are "
305 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
306 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
308 type = SCARD_TRY_BOTH;
310 type = SCARD_USIM_ONLY;
312 type = SCARD_GSM_SIM_ONLY;
314 wpa_s->scard = scard_init(type, NULL);
315 if (wpa_s->scard == NULL) {
316 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
320 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
321 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
322 #endif /* PCSC_FUNCS */
323 #endif /* IEEE8021X_EAPOL */
329 #ifndef CONFIG_NO_SCAN_PROCESSING
330 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
331 struct wpa_ssid *ssid)
335 if (ssid->mixed_cell)
339 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
341 #endif /* CONFIG_WPS */
343 for (i = 0; i < NUM_WEP_KEYS; i++) {
344 if (ssid->wep_key_len[i]) {
349 #ifdef IEEE8021X_EAPOL
350 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
351 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
352 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
354 #endif /* IEEE8021X_EAPOL */
356 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
359 if (bss->caps & IEEE80211_CAP_PRIVACY)
365 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
366 struct wpa_ssid *ssid,
369 struct wpa_ie_data ie;
371 const u8 *rsn_ie, *wpa_ie;
375 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
379 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
380 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
381 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
382 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
383 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
385 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
386 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
389 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
390 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
396 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
398 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
403 if (!(ie.proto & ssid->proto)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
409 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
410 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
415 if (!(ie.group_cipher & ssid->group_cipher)) {
416 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
421 if (!(ie.key_mgmt & ssid->key_mgmt)) {
422 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
427 #ifdef CONFIG_IEEE80211W
428 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
429 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
434 #endif /* CONFIG_IEEE80211W */
436 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
440 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
441 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
444 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
445 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
451 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
453 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
458 if (!(ie.proto & ssid->proto)) {
459 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
464 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
470 if (!(ie.group_cipher & ssid->group_cipher)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
476 if (!(ie.key_mgmt & ssid->key_mgmt)) {
477 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
482 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
486 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
488 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
492 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
493 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
494 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
498 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
499 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
503 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
510 static int freq_allowed(int *freqs, int freq)
517 for (i = 0; freqs[i]; i++)
518 if (freqs[i] == freq)
524 static int ht_supported(const struct hostapd_hw_modes *mode)
526 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
528 * The driver did not indicate whether it supports HT. Assume
529 * it does to avoid connection issues.
535 * IEEE Std 802.11n-2009 20.1.1:
536 * An HT non-AP STA shall support all EQM rates for one spatial stream.
538 return mode->mcs_set[0] == 0xff;
542 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
544 const struct hostapd_hw_modes *mode = NULL, *modes;
545 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
550 return 1; /* Cannot do matching without knowing band */
552 modes = wpa_s->hw.modes;
555 * The driver does not provide any additional information
556 * about the utilized hardware, so allow the connection attempt
562 for (i = 0; i < wpa_s->hw.num_modes; i++) {
563 for (j = 0; j < modes[i].num_channels; j++) {
564 int freq = modes[i].channels[j].freq;
565 if (freq == bss->freq) {
567 mode->mode == HOSTAPD_MODE_IEEE80211G)
568 break; /* do not allow 802.11b replace
579 for (i = 0; i < (int) sizeof(scan_ie); i++) {
580 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
584 for (j = 2; j < rate_ie[1] + 2; j++) {
585 int flagged = !!(rate_ie[j] & 0x80);
586 int r = (rate_ie[j] & 0x7f) * 5;
589 * IEEE Std 802.11n-2009 7.3.2.2:
590 * The new BSS Membership selector value is encoded
591 * like a legacy basic rate, but it is not a rate and
592 * only indicates if the BSS members are required to
593 * support the mandatory features of Clause 20 [HT PHY]
594 * in order to join the BSS.
596 if (flagged && ((rate_ie[j] & 0x7f) ==
597 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
598 if (!ht_supported(mode)) {
599 wpa_dbg(wpa_s, MSG_DEBUG,
600 " hardware does not support "
610 /* check for legacy basic rates */
611 for (k = 0; k < mode->num_rates; k++) {
612 if (mode->rates[k] == r)
615 if (k == mode->num_rates) {
617 * IEEE Std 802.11-2007 7.3.2.2 demands that in
618 * order to join a BSS all required rates
619 * have to be supported by the hardware.
621 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
622 "not support required rate %d.%d Mbps",
633 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
634 int i, struct wpa_bss *bss,
635 struct wpa_ssid *group)
637 u8 wpa_ie_len, rsn_ie_len;
639 struct wpa_blacklist *e;
641 struct wpa_ssid *ssid;
643 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
644 wpa_ie_len = ie ? ie[1] : 0;
646 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
647 rsn_ie_len = ie ? ie[1] : 0;
649 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
650 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
651 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
652 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
653 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
655 e = wpa_blacklist_get(wpa_s, bss->bssid);
658 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
660 * When only a single network is enabled, we can
661 * trigger blacklisting on the first failure. This
662 * should not be done with multiple enabled networks to
663 * avoid getting forced to move into a worse ESS on
664 * single error if there are no other BSSes of the
669 if (e->count > limit) {
670 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
671 "(count=%d limit=%d)", e->count, limit);
676 if (bss->ssid_len == 0) {
677 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
681 if (disallowed_bssid(wpa_s, bss->bssid)) {
682 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
686 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
687 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
691 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
693 for (ssid = group; ssid; ssid = ssid->pnext) {
694 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
697 if (wpas_network_disabled(wpa_s, ssid)) {
698 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
702 res = wpas_temp_disabled(wpa_s, ssid);
704 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
705 "temporarily for %d second(s)", res);
710 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
711 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
716 if (wpa && ssid->ssid_len == 0 &&
717 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
720 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
721 /* Only allow wildcard SSID match if an AP
722 * advertises active WPS operation that matches
725 if (ssid->ssid_len == 0 &&
726 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
729 #endif /* CONFIG_WPS */
731 if (ssid->bssid_set && ssid->ssid_len == 0 &&
732 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
736 (bss->ssid_len != ssid->ssid_len ||
737 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
738 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
742 if (ssid->bssid_set &&
743 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
744 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
748 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
752 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
753 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
754 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
755 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
760 if (!wpa_supplicant_match_privacy(bss, ssid)) {
761 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
766 if (bss->caps & IEEE80211_CAP_IBSS) {
767 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
772 if (!freq_allowed(ssid->freq_list, bss->freq)) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
778 if (!rate_match(wpa_s, bss)) {
779 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
786 * TODO: skip the AP if its P2P IE has Group Formation
787 * bit set in the P2P Group Capability Bitmap and we
788 * are not in Group Formation with that device.
790 #endif /* CONFIG_P2P */
792 /* Matching configuration found */
796 /* No matching configuration found */
801 static struct wpa_bss *
802 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
803 struct wpa_ssid *group,
804 struct wpa_ssid **selected_ssid)
808 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
811 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
812 struct wpa_bss *bss = wpa_s->last_scan_res[i];
813 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
816 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
819 wpa_ssid_txt(bss->ssid, bss->ssid_len));
827 static struct wpa_bss *
828 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
829 struct wpa_ssid **selected_ssid)
831 struct wpa_bss *selected = NULL;
834 if (wpa_s->last_scan_res == NULL ||
835 wpa_s->last_scan_res_used == 0)
836 return NULL; /* no scan results from last update */
838 while (selected == NULL) {
839 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
840 selected = wpa_supplicant_select_bss(
841 wpa_s, wpa_s->conf->pssid[prio],
847 if (selected == NULL && wpa_s->blacklist &&
848 !wpa_s->countermeasures) {
849 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
850 "blacklist and try again");
851 wpa_blacklist_clear(wpa_s);
852 wpa_s->blacklist_cleared++;
853 } else if (selected == NULL)
861 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
862 int timeout_sec, int timeout_usec)
864 if (!wpa_supplicant_enabled_networks(wpa_s)) {
866 * No networks are enabled; short-circuit request so
867 * we don't wait timeout seconds before transitioning
870 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
871 "since there are no enabled networks");
872 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
874 wpa_s->sta_scan_pending = 0;
875 #endif /* CONFIG_P2P */
878 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
882 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
883 struct wpa_bss *selected,
884 struct wpa_ssid *ssid)
886 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
887 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
888 "PBC session overlap");
890 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
892 #endif /* CONFIG_P2P */
895 wpas_wps_cancel(wpa_s);
896 #endif /* CONFIG_WPS */
901 * Do not trigger new association unless the BSSID has changed or if
902 * reassociation is requested. If we are in process of associating with
903 * the selected BSSID, do not trigger new attempt.
905 if (wpa_s->reassociate ||
906 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
907 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
908 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
909 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
911 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
912 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
915 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
916 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
917 " pending: " MACSTR " wpa_state: %s",
918 wpa_s->reassociate, MAC2STR(selected->bssid),
919 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
920 wpa_supplicant_state_txt(wpa_s->wpa_state));
921 wpa_supplicant_associate(wpa_s, selected, ssid);
923 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
931 static struct wpa_ssid *
932 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
935 struct wpa_ssid *ssid;
937 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
938 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
940 if (wpas_network_disabled(wpa_s, ssid))
942 if (ssid->mode == IEEE80211_MODE_IBSS ||
943 ssid->mode == IEEE80211_MODE_AP)
951 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
952 * on BSS added and BSS changed events */
953 static void wpa_supplicant_rsn_preauth_scan_results(
954 struct wpa_supplicant *wpa_s)
958 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
961 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
962 const u8 *ssid, *rsn;
964 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
968 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
972 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
978 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
979 struct wpa_bss *selected,
980 struct wpa_ssid *ssid)
982 struct wpa_bss *current_bss = NULL;
985 if (wpa_s->reassociate)
986 return 1; /* explicit request to reassociate */
987 if (wpa_s->wpa_state < WPA_ASSOCIATED)
988 return 1; /* we are not associated; continue */
989 if (wpa_s->current_ssid == NULL)
990 return 1; /* unknown current SSID */
991 if (wpa_s->current_ssid != ssid)
992 return 1; /* different network block */
994 if (wpas_driver_bss_selection(wpa_s))
995 return 0; /* Driver-based roaming */
997 if (wpa_s->current_ssid->ssid)
998 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
999 wpa_s->current_ssid->ssid,
1000 wpa_s->current_ssid->ssid_len);
1002 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1005 return 1; /* current BSS not seen in scan results */
1007 if (current_bss == selected)
1010 if (selected->last_update_idx > current_bss->last_update_idx)
1011 return 1; /* current BSS not seen in the last scan */
1013 #ifndef CONFIG_NO_ROAMING
1014 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1015 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1016 MAC2STR(current_bss->bssid), current_bss->level);
1017 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1018 MAC2STR(selected->bssid), selected->level);
1020 if (wpa_s->current_ssid->bssid_set &&
1021 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1023 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1024 "has preferred BSSID");
1029 if (current_bss->level < 0) {
1030 if (current_bss->level < -85)
1032 else if (current_bss->level < -80)
1034 else if (current_bss->level < -75)
1036 else if (current_bss->level < -70)
1041 if (abs(current_bss->level - selected->level) < min_diff) {
1042 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1048 #else /* CONFIG_NO_ROAMING */
1050 #endif /* CONFIG_NO_ROAMING */
1054 /* Return != 0 if no scan results could be fetched or if scan results should not
1055 * be shared with other virtual interfaces. */
1056 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1057 union wpa_event_data *data)
1059 struct wpa_scan_results *scan_res;
1061 #ifndef CONFIG_NO_RANDOM_POOL
1063 #endif /* CONFIG_NO_RANDOM_POOL */
1066 if (wpa_s->ap_iface)
1068 #endif /* CONFIG_AP */
1070 wpa_supplicant_notify_scanning(wpa_s, 0);
1073 if (wpa_s->global->p2p_cb_on_scan_complete &&
1074 !wpa_s->global->p2p_disabled &&
1075 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1076 !wpa_s->scan_res_handler) {
1077 wpa_s->global->p2p_cb_on_scan_complete = 0;
1078 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1079 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1080 "stopped scan processing");
1081 wpa_s->sta_scan_pending = 1;
1082 wpa_supplicant_req_scan(wpa_s, 5, 0);
1086 wpa_s->sta_scan_pending = 0;
1087 #endif /* CONFIG_P2P */
1089 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1090 data ? &data->scan_info :
1092 if (scan_res == NULL) {
1093 if (wpa_s->conf->ap_scan == 2 || ap)
1095 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1097 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1101 #ifndef CONFIG_NO_RANDOM_POOL
1102 num = scan_res->num;
1105 for (i = 0; i < num; i++) {
1107 struct wpa_scan_res *res = scan_res->res[i];
1108 buf[0] = res->bssid[5];
1109 buf[1] = res->qual & 0xff;
1110 buf[2] = res->noise & 0xff;
1111 buf[3] = res->level & 0xff;
1112 buf[4] = res->tsf & 0xff;
1113 random_add_randomness(buf, sizeof(buf));
1115 #endif /* CONFIG_NO_RANDOM_POOL */
1117 if (wpa_s->scan_res_handler) {
1118 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1119 struct wpa_scan_results *scan_res);
1121 scan_res_handler = wpa_s->scan_res_handler;
1122 wpa_s->scan_res_handler = NULL;
1123 scan_res_handler(wpa_s, scan_res);
1125 wpa_scan_results_free(scan_res);
1130 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1132 if (wpa_s->ap_iface->scan_cb)
1133 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1134 #endif /* CONFIG_AP */
1135 wpa_scan_results_free(scan_res);
1139 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1140 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1141 wpas_notify_scan_results(wpa_s);
1143 wpas_notify_scan_done(wpa_s, 1);
1145 if (sme_proc_obss_scan(wpa_s) > 0) {
1146 wpa_scan_results_free(scan_res);
1150 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1151 wpa_scan_results_free(scan_res);
1155 if (autoscan_notify_scan(wpa_s, scan_res)) {
1156 wpa_scan_results_free(scan_res);
1160 if (wpa_s->disconnected) {
1161 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1162 wpa_scan_results_free(scan_res);
1166 if (!wpas_driver_bss_selection(wpa_s) &&
1167 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1168 wpa_scan_results_free(scan_res);
1172 wpas_wps_update_ap_info(wpa_s, scan_res);
1174 wpa_scan_results_free(scan_res);
1176 return wpas_select_network_from_last_scan(wpa_s);
1180 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1182 struct wpa_bss *selected;
1183 struct wpa_ssid *ssid = NULL;
1185 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1189 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1191 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1195 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1196 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1199 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1201 * Do not notify other virtual radios of scan results since we do not
1202 * want them to start other associations at the same time.
1206 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1207 ssid = wpa_supplicant_pick_new_network(wpa_s);
1209 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1210 wpa_supplicant_associate(wpa_s, NULL, ssid);
1211 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1213 int timeout_sec = wpa_s->scan_interval;
1214 int timeout_usec = 0;
1216 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1219 if (wpa_s->p2p_in_provisioning) {
1221 * Use shorter wait during P2P Provisioning
1222 * state to speed up group formation.
1225 timeout_usec = 250000;
1226 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1230 #endif /* CONFIG_P2P */
1231 #ifdef CONFIG_INTERWORKING
1232 if (wpa_s->conf->auto_interworking &&
1233 wpa_s->conf->interworking &&
1234 wpa_s->conf->cred) {
1235 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1236 "start ANQP fetch since no matching "
1238 wpa_s->network_select = 1;
1239 wpa_s->auto_network_select = 1;
1240 interworking_start_fetch_anqp(wpa_s);
1243 #endif /* CONFIG_INTERWORKING */
1244 if (wpa_supplicant_req_sched_scan(wpa_s))
1245 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1253 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1254 union wpa_event_data *data)
1256 const char *rn, *rn2;
1257 struct wpa_supplicant *ifs;
1259 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1261 * If no scan results could be fetched, then no need to
1262 * notify those interfaces that did not actually request
1263 * this scan. Similarly, if scan results started a new operation on this
1264 * interface, do not notify other interfaces to avoid concurrent
1265 * operations during a connection attempt.
1271 * Check other interfaces to see if they have the same radio-name. If
1272 * so, they get updated with this same scan info.
1274 if (!wpa_s->driver->get_radio_name)
1277 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1278 if (rn == NULL || rn[0] == '\0')
1281 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1282 "sharing same radio (%s) in event_scan_results", rn);
1284 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1285 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1288 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1289 if (rn2 && os_strcmp(rn, rn2) == 0) {
1290 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1291 "sibling", ifs->ifname);
1292 _wpa_supplicant_event_scan_results(ifs, data);
1297 #endif /* CONFIG_NO_SCAN_PROCESSING */
1302 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1304 struct wpa_supplicant *wpa_s = eloop_ctx;
1306 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1309 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1310 MAC2STR(wpa_s->bssid));
1311 /* TODO: could skip this if normal data traffic has been sent */
1312 /* TODO: Consider using some more appropriate data frame for this */
1314 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1317 if (wpa_s->sme.bss_max_idle_period) {
1319 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1322 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1323 wnm_bss_keep_alive, wpa_s, NULL);
1325 #endif /* CONFIG_SME */
1329 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1330 const u8 *ies, size_t ies_len)
1332 struct ieee802_11_elems elems;
1337 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1341 if (elems.bss_max_idle_period) {
1343 wpa_s->sme.bss_max_idle_period =
1344 WPA_GET_LE16(elems.bss_max_idle_period);
1345 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1346 "TU)%s", wpa_s->sme.bss_max_idle_period,
1347 (elems.bss_max_idle_period[2] & 0x01) ?
1348 " (protected keep-live required)" : "");
1349 if (wpa_s->sme.bss_max_idle_period == 0)
1350 wpa_s->sme.bss_max_idle_period = 1;
1351 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1352 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1353 /* msec times 1000 */
1354 msec = wpa_s->sme.bss_max_idle_period * 1024;
1357 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1358 wnm_bss_keep_alive, wpa_s,
1362 #endif /* CONFIG_SME */
1365 #endif /* CONFIG_WNM */
1368 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1371 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1372 #endif /* CONFIG_WNM */
1376 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1377 union wpa_event_data *data)
1379 int l, len, found = 0, wpa_found, rsn_found;
1382 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1383 if (data->assoc_info.req_ies)
1384 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1385 data->assoc_info.req_ies_len);
1386 if (data->assoc_info.resp_ies) {
1387 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1388 data->assoc_info.resp_ies_len);
1390 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1391 data->assoc_info.resp_ies_len);
1392 #endif /* CONFIG_TDLS */
1394 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1395 data->assoc_info.resp_ies_len);
1396 #endif /* CONFIG_WNM */
1398 if (data->assoc_info.beacon_ies)
1399 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1400 data->assoc_info.beacon_ies,
1401 data->assoc_info.beacon_ies_len);
1402 if (data->assoc_info.freq)
1403 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1404 data->assoc_info.freq);
1406 p = data->assoc_info.req_ies;
1407 l = data->assoc_info.req_ies_len;
1409 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1410 while (p && l >= 2) {
1413 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1417 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1418 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1419 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1420 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1423 wpa_find_assoc_pmkid(wpa_s);
1429 if (!found && data->assoc_info.req_ies)
1430 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1432 #ifdef CONFIG_IEEE80211R
1434 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1436 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1437 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1438 data->assoc_info.resp_ies,
1439 data->assoc_info.resp_ies_len,
1441 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1442 "Reassociation Response failed");
1443 wpa_supplicant_deauthenticate(
1444 wpa_s, WLAN_REASON_INVALID_IE);
1449 p = data->assoc_info.resp_ies;
1450 l = data->assoc_info.resp_ies_len;
1452 #ifdef CONFIG_WPS_STRICT
1453 if (p && wpa_s->current_ssid &&
1454 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1456 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1458 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1459 "include WPS IE in (Re)Association Response");
1463 if (wps_validate_assoc_resp(wps) < 0) {
1465 wpa_supplicant_deauthenticate(
1466 wpa_s, WLAN_REASON_INVALID_IE);
1471 #endif /* CONFIG_WPS_STRICT */
1473 /* Go through the IEs and make a copy of the MDIE, if present. */
1474 while (p && l >= 2) {
1477 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1481 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1482 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1483 wpa_s->sme.ft_used = 1;
1484 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1485 MOBILITY_DOMAIN_ID_LEN);
1491 #endif /* CONFIG_SME */
1493 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1494 data->assoc_info.resp_ies_len);
1495 #endif /* CONFIG_IEEE80211R */
1497 /* WPA/RSN IE from Beacon/ProbeResp */
1498 p = data->assoc_info.beacon_ies;
1499 l = data->assoc_info.beacon_ies_len;
1501 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1503 wpa_found = rsn_found = 0;
1504 while (p && l >= 2) {
1507 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1512 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1513 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1515 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1519 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1521 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1528 if (!wpa_found && data->assoc_info.beacon_ies)
1529 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1530 if (!rsn_found && data->assoc_info.beacon_ies)
1531 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1532 if (wpa_found || rsn_found)
1533 wpa_s->ap_ies_from_associnfo = 1;
1535 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1536 wpa_s->assoc_freq != data->assoc_info.freq) {
1537 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1539 wpa_s->assoc_freq, data->assoc_info.freq);
1540 wpa_supplicant_update_scan_results(wpa_s);
1543 wpa_s->assoc_freq = data->assoc_info.freq;
1549 static struct wpa_bss * wpa_supplicant_get_new_bss(
1550 struct wpa_supplicant *wpa_s, const u8 *bssid)
1552 struct wpa_bss *bss = NULL;
1553 struct wpa_ssid *ssid = wpa_s->current_ssid;
1555 if (ssid->ssid_len > 0)
1556 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1558 bss = wpa_bss_get_bssid(wpa_s, bssid);
1564 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1566 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1568 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1571 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1574 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1575 WPA_IE_VENDOR_TYPE);
1576 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1578 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1579 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1580 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1581 bss_rsn ? 2 + bss_rsn[1] : 0))
1588 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1589 union wpa_event_data *data)
1593 struct wpa_driver_capa capa;
1596 if (wpa_s->ap_iface) {
1597 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1598 data->assoc_info.addr,
1599 data->assoc_info.req_ies,
1600 data->assoc_info.req_ies_len,
1601 data->assoc_info.reassoc);
1604 #endif /* CONFIG_AP */
1606 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1607 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1610 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1611 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1612 wpa_supplicant_disassociate(
1613 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1617 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1618 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1619 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1620 MACSTR, MAC2STR(bssid));
1621 random_add_randomness(bssid, ETH_ALEN);
1622 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1623 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1624 wpas_notify_bssid_changed(wpa_s);
1626 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1627 wpa_clear_keys(wpa_s, bssid);
1629 if (wpa_supplicant_select_config(wpa_s) < 0) {
1630 wpa_supplicant_disassociate(
1631 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1634 if (wpa_s->current_ssid) {
1635 struct wpa_bss *bss = NULL;
1637 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1639 wpa_supplicant_update_scan_results(wpa_s);
1641 /* Get the BSS from the new scan results */
1642 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1646 wpa_s->current_bss = bss;
1649 if (wpa_s->conf->ap_scan == 1 &&
1650 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1651 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1652 wpa_msg(wpa_s, MSG_WARNING,
1653 "WPA/RSN IEs not updated");
1658 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1659 wpa_s->sme.prev_bssid_set = 1;
1660 #endif /* CONFIG_SME */
1662 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1663 if (wpa_s->current_ssid) {
1664 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1665 * initialized before association, but for other modes,
1666 * initialize PC/SC here, if the current configuration needs
1667 * smartcard or SIM/USIM. */
1668 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1670 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1672 l2_packet_notify_auth_start(wpa_s->l2);
1675 * Set portEnabled first to FALSE in order to get EAP state machine out
1676 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1677 * state machine may transit to AUTHENTICATING state based on obsolete
1678 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1679 * AUTHENTICATED without ever giving chance to EAP state machine to
1682 if (!ft_completed) {
1683 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1684 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1686 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1687 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1688 /* 802.1X::portControl = Auto */
1689 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1690 wpa_s->eapol_received = 0;
1691 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1692 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1693 (wpa_s->current_ssid &&
1694 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1695 wpa_supplicant_cancel_auth_timeout(wpa_s);
1696 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1697 } else if (!ft_completed) {
1698 /* Timeout for receiving the first EAPOL packet */
1699 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1701 wpa_supplicant_cancel_scan(wpa_s);
1703 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1704 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1706 * We are done; the driver will take care of RSN 4-way
1709 wpa_supplicant_cancel_auth_timeout(wpa_s);
1710 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1711 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1712 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1713 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1714 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1716 * The driver will take care of RSN 4-way handshake, so we need
1717 * to allow EAPOL supplicant to complete its work without
1718 * waiting for WPA supplicant.
1720 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1721 } else if (ft_completed) {
1723 * FT protocol completed - make sure EAPOL state machine ends
1724 * up in authenticated.
1726 wpa_supplicant_cancel_auth_timeout(wpa_s);
1727 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1728 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1729 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1732 if (wpa_s->pending_eapol_rx) {
1733 struct os_time now, age;
1735 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1736 if (age.sec == 0 && age.usec < 100000 &&
1737 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1739 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1740 "frame that was received just before "
1741 "association notification");
1742 wpa_supplicant_rx_eapol(
1743 wpa_s, wpa_s->pending_eapol_rx_src,
1744 wpabuf_head(wpa_s->pending_eapol_rx),
1745 wpabuf_len(wpa_s->pending_eapol_rx));
1747 wpabuf_free(wpa_s->pending_eapol_rx);
1748 wpa_s->pending_eapol_rx = NULL;
1751 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1752 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1753 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1754 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1755 /* Set static WEP keys again */
1756 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1759 #ifdef CONFIG_IBSS_RSN
1760 if (wpa_s->current_ssid &&
1761 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1762 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1763 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1764 wpa_s->ibss_rsn == NULL) {
1765 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1766 if (!wpa_s->ibss_rsn) {
1767 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1768 wpa_supplicant_deauthenticate(
1769 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1773 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1775 #endif /* CONFIG_IBSS_RSN */
1777 wpas_wps_notify_assoc(wpa_s, bssid);
1781 static int disconnect_reason_recoverable(u16 reason_code)
1783 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1784 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1785 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1789 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1791 int locally_generated)
1795 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1797 * At least Host AP driver and a Prism3 card seemed to be
1798 * generating streams of disconnected events when configuring
1799 * IBSS for WPA-None. Ignore them for now.
1804 bssid = wpa_s->bssid;
1805 if (is_zero_ether_addr(bssid))
1806 bssid = wpa_s->pending_bssid;
1808 if (!is_zero_ether_addr(bssid) ||
1809 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1810 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1812 MAC2STR(bssid), reason_code,
1813 locally_generated ? " locally_generated=1" : "");
1818 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1819 int locally_generated)
1821 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1822 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1823 return 0; /* Not in 4-way handshake with PSK */
1826 * It looks like connection was lost while trying to go through PSK
1827 * 4-way handshake. Filter out known disconnection cases that are caused
1828 * by something else than PSK mismatch to avoid confusing reports.
1831 if (locally_generated) {
1832 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1840 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1842 int locally_generated)
1846 u8 prev_pending_bssid[ETH_ALEN];
1847 struct wpa_bss *fast_reconnect = NULL;
1848 struct wpa_ssid *fast_reconnect_ssid = NULL;
1849 struct wpa_ssid *last_ssid;
1851 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1852 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1854 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1856 * At least Host AP driver and a Prism3 card seemed to be
1857 * generating streams of disconnected events when configuring
1858 * IBSS for WPA-None. Ignore them for now.
1860 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1861 "IBSS/WPA-None mode");
1865 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1866 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1867 "pre-shared key may be incorrect");
1868 wpas_auth_failed(wpa_s);
1870 if (!wpa_s->auto_reconnect_disabled ||
1871 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1872 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1873 "reconnect (wps=%d wpa_state=%d)",
1874 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1876 if (wpa_s->wpa_state == WPA_COMPLETED &&
1877 wpa_s->current_ssid &&
1878 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1879 !locally_generated &&
1880 disconnect_reason_recoverable(reason_code)) {
1882 * It looks like the AP has dropped association with
1883 * us, but could allow us to get back in. Try to
1884 * reconnect to the same BSS without full scan to save
1885 * time for some common cases.
1887 fast_reconnect = wpa_s->current_bss;
1888 fast_reconnect_ssid = wpa_s->current_ssid;
1889 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1890 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1892 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1895 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1896 "try to re-connect");
1897 wpa_s->reassociate = 0;
1898 wpa_s->disconnected = 1;
1899 wpa_supplicant_cancel_sched_scan(wpa_s);
1901 bssid = wpa_s->bssid;
1902 if (is_zero_ether_addr(bssid))
1903 bssid = wpa_s->pending_bssid;
1904 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1905 wpas_connection_failed(wpa_s, bssid);
1906 wpa_sm_notify_disassoc(wpa_s->wpa);
1907 if (locally_generated)
1908 wpa_s->disconnect_reason = -reason_code;
1910 wpa_s->disconnect_reason = reason_code;
1911 wpas_notify_disconnect_reason(wpa_s);
1912 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1913 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1914 wpa_s->keys_cleared = 0;
1915 wpa_clear_keys(wpa_s, wpa_s->bssid);
1917 last_ssid = wpa_s->current_ssid;
1918 wpa_supplicant_mark_disassoc(wpa_s);
1920 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1921 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1922 wpa_s->current_ssid = last_ssid;
1925 if (fast_reconnect) {
1926 #ifndef CONFIG_NO_SCAN_PROCESSING
1927 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1928 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1929 fast_reconnect_ssid) < 0) {
1930 /* Recover through full scan */
1931 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1933 #endif /* CONFIG_NO_SCAN_PROCESSING */
1938 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1939 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1941 struct wpa_supplicant *wpa_s = eloop_ctx;
1943 if (!wpa_s->pending_mic_error_report)
1946 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1947 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1948 wpa_s->pending_mic_error_report = 0;
1950 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1954 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1955 union wpa_event_data *data)
1960 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1961 pairwise = (data && data->michael_mic_failure.unicast);
1963 if ((wpa_s->last_michael_mic_error &&
1964 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1965 wpa_s->pending_mic_error_report) {
1966 if (wpa_s->pending_mic_error_report) {
1968 * Send the pending MIC error report immediately since
1969 * we are going to start countermeasures and AP better
1972 wpa_sm_key_request(wpa_s->wpa, 1,
1973 wpa_s->pending_mic_error_pairwise);
1976 /* Send the new MIC error report immediately since we are going
1977 * to start countermeasures and AP better do the same.
1979 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1981 /* initialize countermeasures */
1982 wpa_s->countermeasures = 1;
1984 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1986 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1989 * Need to wait for completion of request frame. We do not get
1990 * any callback for the message completion, so just wait a
1991 * short while and hope for the best. */
1994 wpa_drv_set_countermeasures(wpa_s, 1);
1995 wpa_supplicant_deauthenticate(wpa_s,
1996 WLAN_REASON_MICHAEL_MIC_FAILURE);
1997 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1999 eloop_register_timeout(60, 0,
2000 wpa_supplicant_stop_countermeasures,
2002 /* TODO: mark the AP rejected for 60 second. STA is
2003 * allowed to associate with another AP.. */
2005 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2006 if (wpa_s->mic_errors_seen) {
2008 * Reduce the effectiveness of Michael MIC error
2009 * reports as a means for attacking against TKIP if
2010 * more than one MIC failure is noticed with the same
2011 * PTK. We delay the transmission of the reports by a
2012 * random time between 0 and 60 seconds in order to
2013 * force the attacker wait 60 seconds before getting
2014 * the information on whether a frame resulted in a MIC
2020 if (os_get_random(rval, sizeof(rval)) < 0)
2021 sec = os_random() % 60;
2023 sec = WPA_GET_BE32(rval) % 60;
2024 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2025 "report %d seconds", sec);
2026 wpa_s->pending_mic_error_report = 1;
2027 wpa_s->pending_mic_error_pairwise = pairwise;
2028 eloop_cancel_timeout(
2029 wpa_supplicant_delayed_mic_error_report,
2031 eloop_register_timeout(
2032 sec, os_random() % 1000000,
2033 wpa_supplicant_delayed_mic_error_report,
2036 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2038 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2039 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2040 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2042 wpa_s->last_michael_mic_error = t.sec;
2043 wpa_s->mic_errors_seen++;
2047 #ifdef CONFIG_TERMINATE_ONLASTIF
2048 static int any_interfaces(struct wpa_supplicant *head)
2050 struct wpa_supplicant *wpa_s;
2052 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2053 if (!wpa_s->interface_removed)
2057 #endif /* CONFIG_TERMINATE_ONLASTIF */
2061 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2062 union wpa_event_data *data)
2064 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2067 switch (data->interface_status.ievent) {
2068 case EVENT_INTERFACE_ADDED:
2069 if (!wpa_s->interface_removed)
2071 wpa_s->interface_removed = 0;
2072 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2073 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2074 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2075 "driver after interface was added");
2077 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2079 case EVENT_INTERFACE_REMOVED:
2080 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2081 wpa_s->interface_removed = 1;
2082 wpa_supplicant_mark_disassoc(wpa_s);
2083 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2084 l2_packet_deinit(wpa_s->l2);
2086 #ifdef CONFIG_IBSS_RSN
2087 ibss_rsn_deinit(wpa_s->ibss_rsn);
2088 wpa_s->ibss_rsn = NULL;
2089 #endif /* CONFIG_IBSS_RSN */
2090 #ifdef CONFIG_TERMINATE_ONLASTIF
2091 /* check if last interface */
2092 if (!any_interfaces(wpa_s->global->ifaces))
2094 #endif /* CONFIG_TERMINATE_ONLASTIF */
2100 #ifdef CONFIG_PEERKEY
2102 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2103 union wpa_event_data *data)
2107 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2109 #endif /* CONFIG_PEERKEY */
2113 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2114 union wpa_event_data *data)
2118 switch (data->tdls.oper) {
2119 case TDLS_REQUEST_SETUP:
2120 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2122 case TDLS_REQUEST_TEARDOWN:
2123 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2124 data->tdls.reason_code);
2128 #endif /* CONFIG_TDLS */
2131 #ifdef CONFIG_IEEE80211V
2132 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2133 union wpa_event_data *data)
2137 switch (data->wnm.oper) {
2138 case WNM_OPER_SLEEP:
2139 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2140 "(action=%d, intval=%d)",
2141 data->wnm.sleep_action, data->wnm.sleep_intval);
2142 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2143 data->wnm.sleep_intval);
2147 #endif /* CONFIG_IEEE80211V */
2150 #ifdef CONFIG_IEEE80211R
2152 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2153 union wpa_event_data *data)
2158 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2159 data->ft_ies.ies_len,
2160 data->ft_ies.ft_action,
2161 data->ft_ies.target_ap,
2162 data->ft_ies.ric_ies,
2163 data->ft_ies.ric_ies_len) < 0) {
2164 /* TODO: prevent MLME/driver from trying to associate? */
2167 #endif /* CONFIG_IEEE80211R */
2170 #ifdef CONFIG_IBSS_RSN
2171 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2172 union wpa_event_data *data)
2174 struct wpa_ssid *ssid;
2175 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2179 ssid = wpa_s->current_ssid;
2182 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2185 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2187 #endif /* CONFIG_IBSS_RSN */
2190 #ifdef CONFIG_IEEE80211R
2191 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2194 const u8 *sta_addr, *target_ap_addr;
2197 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2198 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2199 return; /* only SME case supported for now */
2200 if (len < 1 + 2 * ETH_ALEN + 2)
2203 return; /* Only FT Action Response is supported for now */
2204 sta_addr = data + 1;
2205 target_ap_addr = data + 1 + ETH_ALEN;
2206 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2207 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2208 MACSTR " TargetAP " MACSTR " status %u",
2209 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2211 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2212 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2213 " in FT Action Response", MAC2STR(sta_addr));
2218 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2219 "failure (status code %d)", status);
2220 /* TODO: report error to FT code(?) */
2224 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2225 len - (1 + 2 * ETH_ALEN + 2), 1,
2226 target_ap_addr, NULL, 0) < 0)
2231 struct wpa_bss *bss;
2232 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2234 wpa_s->sme.freq = bss->freq;
2235 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2236 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2239 #endif /* CONFIG_SME */
2241 #endif /* CONFIG_IEEE80211R */
2244 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2245 struct unprot_deauth *e)
2247 #ifdef CONFIG_IEEE80211W
2248 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2249 "dropped: " MACSTR " -> " MACSTR
2250 " (reason code %u)",
2251 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2252 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2253 #endif /* CONFIG_IEEE80211W */
2257 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2258 struct unprot_disassoc *e)
2260 #ifdef CONFIG_IEEE80211W
2261 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2262 "dropped: " MACSTR " -> " MACSTR
2263 " (reason code %u)",
2264 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2265 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2266 #endif /* CONFIG_IEEE80211W */
2270 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2273 const u8 *pos, *end;
2275 if (rx->data == NULL || rx->len == 0)
2279 end = pos + rx->len;
2282 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2283 action, MAC2STR(rx->sa));
2285 case WNM_BSS_TRANS_MGMT_REQ:
2288 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2289 "Request: dialog_token=%u request_mode=0x%x "
2290 "disassoc_timer=%u validity_interval=%u",
2291 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2295 pos += 12; /* BSS Termination Duration */
2298 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2299 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2300 "Transition Management Request "
2304 os_memcpy(url, pos + 1, pos[0]);
2306 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2307 "Imminent - session_info_url=%s", url);
2314 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2315 union wpa_event_data *data)
2317 struct wpa_supplicant *wpa_s = ctx;
2318 u16 reason_code = 0;
2319 int locally_generated = 0;
2321 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2322 event != EVENT_INTERFACE_ENABLED &&
2323 event != EVENT_INTERFACE_STATUS &&
2324 event != EVENT_SCHED_SCAN_STOPPED) {
2325 wpa_dbg(wpa_s, MSG_DEBUG,
2326 "Ignore event %s (%d) while interface is disabled",
2327 event_to_string(event), event);
2331 #ifndef CONFIG_NO_STDOUT_DEBUG
2333 int level = MSG_DEBUG;
2335 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2336 const struct ieee80211_hdr *hdr;
2338 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2339 fc = le_to_host16(hdr->frame_control);
2340 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2341 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2342 level = MSG_EXCESSIVE;
2345 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2346 event_to_string(event), event);
2348 #endif /* CONFIG_NO_STDOUT_DEBUG */
2352 sme_event_auth(wpa_s, data);
2355 wpa_supplicant_event_assoc(wpa_s, data);
2357 case EVENT_DISASSOC:
2358 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2360 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2361 data->disassoc_info.reason_code,
2362 data->disassoc_info.locally_generated ?
2363 " (locally generated)" : "");
2364 if (data->disassoc_info.addr)
2365 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2366 MAC2STR(data->disassoc_info.addr));
2369 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2370 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2371 data->disassoc_info.addr);
2374 if (wpa_s->ap_iface) {
2375 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2379 #endif /* CONFIG_AP */
2381 reason_code = data->disassoc_info.reason_code;
2383 data->disassoc_info.locally_generated;
2384 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2385 data->disassoc_info.ie,
2386 data->disassoc_info.ie_len);
2388 wpas_p2p_disassoc_notif(
2389 wpa_s, data->disassoc_info.addr, reason_code,
2390 data->disassoc_info.ie,
2391 data->disassoc_info.ie_len,
2393 #endif /* CONFIG_P2P */
2395 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2396 sme_event_disassoc(wpa_s, data);
2399 if (event == EVENT_DEAUTH) {
2400 wpa_dbg(wpa_s, MSG_DEBUG,
2401 "Deauthentication notification");
2403 reason_code = data->deauth_info.reason_code;
2405 data->deauth_info.locally_generated;
2406 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2407 data->deauth_info.reason_code,
2408 data->deauth_info.locally_generated ?
2409 " (locally generated)" : "");
2410 if (data->deauth_info.addr) {
2411 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2413 MAC2STR(data->deauth_info.
2416 wpa_hexdump(MSG_DEBUG,
2417 "Deauthentication frame IE(s)",
2418 data->deauth_info.ie,
2419 data->deauth_info.ie_len);
2423 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2424 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2425 data->deauth_info.addr);
2428 if (wpa_s->ap_iface) {
2429 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2433 #endif /* CONFIG_AP */
2434 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2436 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2437 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2438 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2439 eapol_sm_failed(wpa_s->eapol)))
2440 wpas_auth_failed(wpa_s);
2442 if (event == EVENT_DEAUTH && data) {
2443 if (wpas_p2p_deauth_notif(wpa_s,
2444 data->deauth_info.addr,
2446 data->deauth_info.ie,
2447 data->deauth_info.ie_len,
2448 locally_generated) > 0) {
2450 * The interface was removed, so cannot
2451 * continue processing any additional
2452 * operations after this.
2457 #endif /* CONFIG_P2P */
2458 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2461 case EVENT_MICHAEL_MIC_FAILURE:
2462 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2464 #ifndef CONFIG_NO_SCAN_PROCESSING
2465 case EVENT_SCAN_RESULTS:
2466 wpa_supplicant_event_scan_results(wpa_s, data);
2468 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2469 wpa_s->global->p2p != NULL &&
2470 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2471 wpa_s->wpa_state != WPA_ASSOCIATING) {
2472 wpa_s->global->p2p_cb_on_scan_complete = 0;
2473 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2474 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2475 "continued after scan result processing");
2478 #endif /* CONFIG_P2P */
2480 #endif /* CONFIG_NO_SCAN_PROCESSING */
2481 case EVENT_ASSOCINFO:
2482 wpa_supplicant_event_associnfo(wpa_s, data);
2484 case EVENT_INTERFACE_STATUS:
2485 wpa_supplicant_event_interface_status(wpa_s, data);
2487 case EVENT_PMKID_CANDIDATE:
2488 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2490 #ifdef CONFIG_PEERKEY
2491 case EVENT_STKSTART:
2492 wpa_supplicant_event_stkstart(wpa_s, data);
2494 #endif /* CONFIG_PEERKEY */
2497 wpa_supplicant_event_tdls(wpa_s, data);
2499 #endif /* CONFIG_TDLS */
2500 #ifdef CONFIG_IEEE80211V
2502 wpa_supplicant_event_wnm(wpa_s, data);
2504 #endif /* CONFIG_IEEE80211V */
2505 #ifdef CONFIG_IEEE80211R
2506 case EVENT_FT_RESPONSE:
2507 wpa_supplicant_event_ft_response(wpa_s, data);
2509 #endif /* CONFIG_IEEE80211R */
2510 #ifdef CONFIG_IBSS_RSN
2511 case EVENT_IBSS_RSN_START:
2512 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2514 #endif /* CONFIG_IBSS_RSN */
2515 case EVENT_ASSOC_REJECT:
2516 if (data->assoc_reject.bssid)
2517 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2518 "bssid=" MACSTR " status_code=%u",
2519 MAC2STR(data->assoc_reject.bssid),
2520 data->assoc_reject.status_code);
2522 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2524 data->assoc_reject.status_code);
2525 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2526 sme_event_assoc_reject(wpa_s, data);
2528 const u8 *bssid = data->assoc_reject.bssid;
2529 if (bssid == NULL || is_zero_ether_addr(bssid))
2530 bssid = wpa_s->pending_bssid;
2531 wpas_connection_failed(wpa_s, bssid);
2532 wpa_supplicant_mark_disassoc(wpa_s);
2535 case EVENT_AUTH_TIMED_OUT:
2536 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2537 sme_event_auth_timed_out(wpa_s, data);
2539 case EVENT_ASSOC_TIMED_OUT:
2540 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2541 sme_event_assoc_timed_out(wpa_s, data);
2543 case EVENT_TX_STATUS:
2544 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2545 " type=%d stype=%d",
2546 MAC2STR(data->tx_status.dst),
2547 data->tx_status.type, data->tx_status.stype);
2549 if (wpa_s->ap_iface == NULL) {
2550 #ifdef CONFIG_OFFCHANNEL
2551 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2552 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2553 offchannel_send_action_tx_status(
2554 wpa_s, data->tx_status.dst,
2555 data->tx_status.data,
2556 data->tx_status.data_len,
2557 data->tx_status.ack ?
2558 OFFCHANNEL_SEND_ACTION_SUCCESS :
2559 OFFCHANNEL_SEND_ACTION_NO_ACK);
2560 #endif /* CONFIG_OFFCHANNEL */
2563 #endif /* CONFIG_AP */
2564 #ifdef CONFIG_OFFCHANNEL
2565 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2566 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2568 * Catch TX status events for Action frames we sent via group
2569 * interface in GO mode.
2571 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2572 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2573 os_memcmp(wpa_s->parent->pending_action_dst,
2574 data->tx_status.dst, ETH_ALEN) == 0) {
2575 offchannel_send_action_tx_status(
2576 wpa_s->parent, data->tx_status.dst,
2577 data->tx_status.data,
2578 data->tx_status.data_len,
2579 data->tx_status.ack ?
2580 OFFCHANNEL_SEND_ACTION_SUCCESS :
2581 OFFCHANNEL_SEND_ACTION_NO_ACK);
2584 #endif /* CONFIG_OFFCHANNEL */
2586 switch (data->tx_status.type) {
2587 case WLAN_FC_TYPE_MGMT:
2588 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2589 data->tx_status.data_len,
2590 data->tx_status.stype,
2591 data->tx_status.ack);
2593 case WLAN_FC_TYPE_DATA:
2594 ap_tx_status(wpa_s, data->tx_status.dst,
2595 data->tx_status.data,
2596 data->tx_status.data_len,
2597 data->tx_status.ack);
2600 #endif /* CONFIG_AP */
2603 case EVENT_EAPOL_TX_STATUS:
2604 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2605 data->eapol_tx_status.data,
2606 data->eapol_tx_status.data_len,
2607 data->eapol_tx_status.ack);
2609 case EVENT_DRIVER_CLIENT_POLL_OK:
2610 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2612 case EVENT_RX_FROM_UNKNOWN:
2613 if (wpa_s->ap_iface == NULL)
2615 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2616 data->rx_from_unknown.wds);
2618 case EVENT_CH_SWITCH:
2621 if (!wpa_s->ap_iface) {
2622 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2623 "event in non-AP mode");
2628 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2629 data->ch_switch.ht_enabled,
2630 data->ch_switch.ch_offset);
2631 #endif /* CONFIG_AP */
2633 case EVENT_RX_MGMT: {
2635 const struct ieee80211_mgmt *mgmt;
2637 mgmt = (const struct ieee80211_mgmt *)
2638 data->rx_mgmt.frame;
2639 fc = le_to_host16(mgmt->frame_control);
2640 stype = WLAN_FC_GET_STYPE(fc);
2642 if (wpa_s->ap_iface == NULL) {
2644 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2645 data->rx_mgmt.frame_len > 24) {
2646 const u8 *src = mgmt->sa;
2647 const u8 *ie = mgmt->u.probe_req.variable;
2648 size_t ie_len = data->rx_mgmt.frame_len -
2649 (mgmt->u.probe_req.variable -
2650 data->rx_mgmt.frame);
2651 wpas_p2p_probe_req_rx(
2652 wpa_s, src, mgmt->da,
2653 mgmt->bssid, ie, ie_len,
2654 data->rx_mgmt.ssi_signal);
2657 #endif /* CONFIG_P2P */
2658 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2659 "management frame in non-AP mode");
2663 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2664 data->rx_mgmt.frame_len > 24) {
2665 const u8 *ie = mgmt->u.probe_req.variable;
2666 size_t ie_len = data->rx_mgmt.frame_len -
2667 (mgmt->u.probe_req.variable -
2668 data->rx_mgmt.frame);
2670 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2671 mgmt->bssid, ie, ie_len,
2672 data->rx_mgmt.ssi_signal);
2675 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2678 #endif /* CONFIG_AP */
2679 case EVENT_RX_ACTION:
2680 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2681 " Category=%u DataLen=%d freq=%d MHz",
2682 MAC2STR(data->rx_action.sa),
2683 data->rx_action.category, (int) data->rx_action.len,
2684 data->rx_action.freq);
2685 #ifdef CONFIG_IEEE80211R
2686 if (data->rx_action.category == WLAN_ACTION_FT) {
2687 ft_rx_action(wpa_s, data->rx_action.data,
2688 data->rx_action.len);
2691 #endif /* CONFIG_IEEE80211R */
2692 #ifdef CONFIG_IEEE80211W
2694 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2695 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2696 data->rx_action.data,
2697 data->rx_action.len);
2700 #endif /* CONFIG_SME */
2701 #endif /* CONFIG_IEEE80211W */
2702 #ifdef CONFIG_IEEE80211V
2703 if (data->rx_action.category == WLAN_ACTION_WNM) {
2704 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2707 #endif /* CONFIG_IEEE80211V */
2709 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2710 gas_query_rx(wpa_s->gas, data->rx_action.da,
2711 data->rx_action.sa, data->rx_action.bssid,
2712 data->rx_action.data, data->rx_action.len,
2713 data->rx_action.freq) == 0)
2715 #endif /* CONFIG_GAS */
2716 if (data->rx_action.category == WLAN_ACTION_WNM) {
2717 wnm_action_rx(wpa_s, &data->rx_action);
2721 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2722 data->rx_action.len >= 4 &&
2723 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2724 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2725 "Response from " MACSTR,
2726 MAC2STR(data->rx_action.sa));
2729 #endif /* CONFIG_TDLS */
2731 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2733 data->rx_action.bssid,
2734 data->rx_action.category,
2735 data->rx_action.data,
2736 data->rx_action.len, data->rx_action.freq);
2737 #endif /* CONFIG_P2P */
2739 case EVENT_RX_PROBE_REQ:
2740 if (data->rx_probe_req.sa == NULL ||
2741 data->rx_probe_req.ie == NULL)
2744 if (wpa_s->ap_iface) {
2745 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2746 data->rx_probe_req.sa,
2747 data->rx_probe_req.da,
2748 data->rx_probe_req.bssid,
2749 data->rx_probe_req.ie,
2750 data->rx_probe_req.ie_len,
2751 data->rx_probe_req.ssi_signal);
2754 #endif /* CONFIG_AP */
2756 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2757 data->rx_probe_req.da,
2758 data->rx_probe_req.bssid,
2759 data->rx_probe_req.ie,
2760 data->rx_probe_req.ie_len,
2761 data->rx_probe_req.ssi_signal);
2762 #endif /* CONFIG_P2P */
2764 case EVENT_REMAIN_ON_CHANNEL:
2765 #ifdef CONFIG_OFFCHANNEL
2766 offchannel_remain_on_channel_cb(
2767 wpa_s, data->remain_on_channel.freq,
2768 data->remain_on_channel.duration);
2769 #endif /* CONFIG_OFFCHANNEL */
2771 wpas_p2p_remain_on_channel_cb(
2772 wpa_s, data->remain_on_channel.freq,
2773 data->remain_on_channel.duration);
2774 #endif /* CONFIG_P2P */
2776 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2777 #ifdef CONFIG_OFFCHANNEL
2778 offchannel_cancel_remain_on_channel_cb(
2779 wpa_s, data->remain_on_channel.freq);
2780 #endif /* CONFIG_OFFCHANNEL */
2782 wpas_p2p_cancel_remain_on_channel_cb(
2783 wpa_s, data->remain_on_channel.freq);
2784 #endif /* CONFIG_P2P */
2787 case EVENT_P2P_DEV_FOUND: {
2788 struct p2p_peer_info peer_info;
2790 os_memset(&peer_info, 0, sizeof(peer_info));
2791 if (data->p2p_dev_found.dev_addr)
2792 os_memcpy(peer_info.p2p_device_addr,
2793 data->p2p_dev_found.dev_addr, ETH_ALEN);
2794 if (data->p2p_dev_found.pri_dev_type)
2795 os_memcpy(peer_info.pri_dev_type,
2796 data->p2p_dev_found.pri_dev_type,
2797 sizeof(peer_info.pri_dev_type));
2798 if (data->p2p_dev_found.dev_name)
2799 os_strlcpy(peer_info.device_name,
2800 data->p2p_dev_found.dev_name,
2801 sizeof(peer_info.device_name));
2802 peer_info.config_methods = data->p2p_dev_found.config_methods;
2803 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2804 peer_info.group_capab = data->p2p_dev_found.group_capab;
2807 * FIX: new_device=1 is not necessarily correct. We should
2808 * maintain a P2P peer database in wpa_supplicant and update
2809 * this information based on whether the peer is truly new.
2811 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2814 case EVENT_P2P_GO_NEG_REQ_RX:
2815 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2816 data->p2p_go_neg_req_rx.dev_passwd_id);
2818 case EVENT_P2P_GO_NEG_COMPLETED:
2819 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2821 case EVENT_P2P_PROV_DISC_REQUEST:
2822 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2823 data->p2p_prov_disc_req.config_methods,
2824 data->p2p_prov_disc_req.dev_addr,
2825 data->p2p_prov_disc_req.pri_dev_type,
2826 data->p2p_prov_disc_req.dev_name,
2827 data->p2p_prov_disc_req.supp_config_methods,
2828 data->p2p_prov_disc_req.dev_capab,
2829 data->p2p_prov_disc_req.group_capab,
2832 case EVENT_P2P_PROV_DISC_RESPONSE:
2833 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2834 data->p2p_prov_disc_resp.config_methods);
2836 case EVENT_P2P_SD_REQUEST:
2837 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2838 data->p2p_sd_req.sa,
2839 data->p2p_sd_req.dialog_token,
2840 data->p2p_sd_req.update_indic,
2841 data->p2p_sd_req.tlvs,
2842 data->p2p_sd_req.tlvs_len);
2844 case EVENT_P2P_SD_RESPONSE:
2845 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2846 data->p2p_sd_resp.update_indic,
2847 data->p2p_sd_resp.tlvs,
2848 data->p2p_sd_resp.tlvs_len);
2850 #endif /* CONFIG_P2P */
2851 case EVENT_EAPOL_RX:
2852 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2853 data->eapol_rx.data,
2854 data->eapol_rx.data_len);
2856 case EVENT_SIGNAL_CHANGE:
2857 bgscan_notify_signal_change(
2858 wpa_s, data->signal_change.above_threshold,
2859 data->signal_change.current_signal,
2860 data->signal_change.current_noise,
2861 data->signal_change.current_txrate);
2863 case EVENT_INTERFACE_ENABLED:
2864 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2865 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2866 wpa_supplicant_update_mac_addr(wpa_s);
2868 if (!wpa_s->ap_iface) {
2869 wpa_supplicant_set_state(wpa_s,
2871 wpa_supplicant_req_scan(wpa_s, 0, 0);
2873 wpa_supplicant_set_state(wpa_s,
2875 #else /* CONFIG_AP */
2876 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2877 wpa_supplicant_req_scan(wpa_s, 0, 0);
2878 #endif /* CONFIG_AP */
2881 case EVENT_INTERFACE_DISABLED:
2882 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2883 wpa_supplicant_mark_disassoc(wpa_s);
2884 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2886 case EVENT_CHANNEL_LIST_CHANGED:
2887 if (wpa_s->drv_priv == NULL)
2888 break; /* Ignore event during drv initialization */
2890 free_hw_features(wpa_s);
2891 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2892 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2895 wpas_p2p_update_channel_list(wpa_s);
2896 #endif /* CONFIG_P2P */
2898 case EVENT_INTERFACE_UNAVAILABLE:
2900 wpas_p2p_interface_unavailable(wpa_s);
2901 #endif /* CONFIG_P2P */
2903 case EVENT_BEST_CHANNEL:
2904 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2906 data->best_chan.freq_24, data->best_chan.freq_5,
2907 data->best_chan.freq_overall);
2908 wpa_s->best_24_freq = data->best_chan.freq_24;
2909 wpa_s->best_5_freq = data->best_chan.freq_5;
2910 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2912 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2913 data->best_chan.freq_5,
2914 data->best_chan.freq_overall);
2915 #endif /* CONFIG_P2P */
2917 case EVENT_UNPROT_DEAUTH:
2918 wpa_supplicant_event_unprot_deauth(wpa_s,
2919 &data->unprot_deauth);
2921 case EVENT_UNPROT_DISASSOC:
2922 wpa_supplicant_event_unprot_disassoc(wpa_s,
2923 &data->unprot_disassoc);
2925 case EVENT_STATION_LOW_ACK:
2927 if (wpa_s->ap_iface && data)
2928 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2929 data->low_ack.addr);
2930 #endif /* CONFIG_AP */
2933 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2934 #endif /* CONFIG_TDLS */
2936 case EVENT_IBSS_PEER_LOST:
2937 #ifdef CONFIG_IBSS_RSN
2938 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2939 #endif /* CONFIG_IBSS_RSN */
2941 case EVENT_DRIVER_GTK_REKEY:
2942 if (os_memcmp(data->driver_gtk_rekey.bssid,
2943 wpa_s->bssid, ETH_ALEN))
2947 wpa_sm_update_replay_ctr(wpa_s->wpa,
2948 data->driver_gtk_rekey.replay_ctr);
2950 case EVENT_SCHED_SCAN_STOPPED:
2951 wpa_s->sched_scanning = 0;
2952 wpa_supplicant_notify_scanning(wpa_s, 0);
2954 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2958 * If we timed out, start a new sched scan to continue
2959 * searching for more SSIDs.
2961 if (wpa_s->sched_scan_timed_out)
2962 wpa_supplicant_req_sched_scan(wpa_s);
2964 case EVENT_WPS_BUTTON_PUSHED:
2966 wpas_wps_start_pbc(wpa_s, NULL, 0);
2967 #endif /* CONFIG_WPS */
2970 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);