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");
1028 if (current_bss->level < 0 && current_bss->level > selected->level) {
1029 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1035 if (current_bss->level < 0) {
1036 if (current_bss->level < -85)
1038 else if (current_bss->level < -80)
1040 else if (current_bss->level < -75)
1042 else if (current_bss->level < -70)
1047 if (abs(current_bss->level - selected->level) < min_diff) {
1048 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1054 #else /* CONFIG_NO_ROAMING */
1056 #endif /* CONFIG_NO_ROAMING */
1060 /* Return != 0 if no scan results could be fetched or if scan results should not
1061 * be shared with other virtual interfaces. */
1062 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1063 union wpa_event_data *data)
1065 struct wpa_scan_results *scan_res;
1067 #ifndef CONFIG_NO_RANDOM_POOL
1069 #endif /* CONFIG_NO_RANDOM_POOL */
1072 if (wpa_s->ap_iface)
1074 #endif /* CONFIG_AP */
1076 wpa_supplicant_notify_scanning(wpa_s, 0);
1079 if (wpa_s->global->p2p_cb_on_scan_complete &&
1080 !wpa_s->global->p2p_disabled &&
1081 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1082 !wpa_s->scan_res_handler) {
1083 wpa_s->global->p2p_cb_on_scan_complete = 0;
1084 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1085 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1086 "stopped scan processing");
1087 wpa_s->sta_scan_pending = 1;
1088 wpa_supplicant_req_scan(wpa_s, 5, 0);
1092 wpa_s->sta_scan_pending = 0;
1093 #endif /* CONFIG_P2P */
1095 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1096 data ? &data->scan_info :
1098 if (scan_res == NULL) {
1099 if (wpa_s->conf->ap_scan == 2 || ap)
1101 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1103 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1107 #ifndef CONFIG_NO_RANDOM_POOL
1108 num = scan_res->num;
1111 for (i = 0; i < num; i++) {
1113 struct wpa_scan_res *res = scan_res->res[i];
1114 buf[0] = res->bssid[5];
1115 buf[1] = res->qual & 0xff;
1116 buf[2] = res->noise & 0xff;
1117 buf[3] = res->level & 0xff;
1118 buf[4] = res->tsf & 0xff;
1119 random_add_randomness(buf, sizeof(buf));
1121 #endif /* CONFIG_NO_RANDOM_POOL */
1123 if (wpa_s->scan_res_handler) {
1124 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1125 struct wpa_scan_results *scan_res);
1127 scan_res_handler = wpa_s->scan_res_handler;
1128 wpa_s->scan_res_handler = NULL;
1129 scan_res_handler(wpa_s, scan_res);
1131 wpa_scan_results_free(scan_res);
1136 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1138 if (wpa_s->ap_iface->scan_cb)
1139 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1140 #endif /* CONFIG_AP */
1141 wpa_scan_results_free(scan_res);
1145 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1146 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1147 wpas_notify_scan_results(wpa_s);
1149 wpas_notify_scan_done(wpa_s, 1);
1151 if (sme_proc_obss_scan(wpa_s) > 0) {
1152 wpa_scan_results_free(scan_res);
1156 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1157 wpa_scan_results_free(scan_res);
1161 if (autoscan_notify_scan(wpa_s, scan_res)) {
1162 wpa_scan_results_free(scan_res);
1166 if (wpa_s->disconnected) {
1167 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1168 wpa_scan_results_free(scan_res);
1172 if (!wpas_driver_bss_selection(wpa_s) &&
1173 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1174 wpa_scan_results_free(scan_res);
1178 wpas_wps_update_ap_info(wpa_s, scan_res);
1180 wpa_scan_results_free(scan_res);
1182 return wpas_select_network_from_last_scan(wpa_s);
1186 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1188 struct wpa_bss *selected;
1189 struct wpa_ssid *ssid = NULL;
1191 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1195 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1197 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1201 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1202 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1205 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1207 * Do not notify other virtual radios of scan results since we do not
1208 * want them to start other associations at the same time.
1212 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1213 ssid = wpa_supplicant_pick_new_network(wpa_s);
1215 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1216 wpa_supplicant_associate(wpa_s, NULL, ssid);
1217 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1219 int timeout_sec = wpa_s->scan_interval;
1220 int timeout_usec = 0;
1222 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1225 if (wpa_s->p2p_in_provisioning) {
1227 * Use shorter wait during P2P Provisioning
1228 * state to speed up group formation.
1231 timeout_usec = 250000;
1232 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1236 #endif /* CONFIG_P2P */
1237 #ifdef CONFIG_INTERWORKING
1238 if (wpa_s->conf->auto_interworking &&
1239 wpa_s->conf->interworking &&
1240 wpa_s->conf->cred) {
1241 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1242 "start ANQP fetch since no matching "
1244 wpa_s->network_select = 1;
1245 wpa_s->auto_network_select = 1;
1246 interworking_start_fetch_anqp(wpa_s);
1249 #endif /* CONFIG_INTERWORKING */
1250 if (wpa_supplicant_req_sched_scan(wpa_s))
1251 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1259 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1260 union wpa_event_data *data)
1262 const char *rn, *rn2;
1263 struct wpa_supplicant *ifs;
1265 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1267 * If no scan results could be fetched, then no need to
1268 * notify those interfaces that did not actually request
1269 * this scan. Similarly, if scan results started a new operation on this
1270 * interface, do not notify other interfaces to avoid concurrent
1271 * operations during a connection attempt.
1277 * Check other interfaces to see if they have the same radio-name. If
1278 * so, they get updated with this same scan info.
1280 if (!wpa_s->driver->get_radio_name)
1283 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1284 if (rn == NULL || rn[0] == '\0')
1287 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1288 "sharing same radio (%s) in event_scan_results", rn);
1290 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1291 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1294 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1295 if (rn2 && os_strcmp(rn, rn2) == 0) {
1296 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1297 "sibling", ifs->ifname);
1298 _wpa_supplicant_event_scan_results(ifs, data);
1303 #endif /* CONFIG_NO_SCAN_PROCESSING */
1308 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1310 struct wpa_supplicant *wpa_s = eloop_ctx;
1312 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1315 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1316 MAC2STR(wpa_s->bssid));
1317 /* TODO: could skip this if normal data traffic has been sent */
1318 /* TODO: Consider using some more appropriate data frame for this */
1320 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1323 if (wpa_s->sme.bss_max_idle_period) {
1325 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1328 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1329 wnm_bss_keep_alive, wpa_s, NULL);
1331 #endif /* CONFIG_SME */
1335 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1336 const u8 *ies, size_t ies_len)
1338 struct ieee802_11_elems elems;
1343 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1347 if (elems.bss_max_idle_period) {
1349 wpa_s->sme.bss_max_idle_period =
1350 WPA_GET_LE16(elems.bss_max_idle_period);
1351 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1352 "TU)%s", wpa_s->sme.bss_max_idle_period,
1353 (elems.bss_max_idle_period[2] & 0x01) ?
1354 " (protected keep-live required)" : "");
1355 if (wpa_s->sme.bss_max_idle_period == 0)
1356 wpa_s->sme.bss_max_idle_period = 1;
1357 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1358 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1359 /* msec times 1000 */
1360 msec = wpa_s->sme.bss_max_idle_period * 1024;
1363 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1364 wnm_bss_keep_alive, wpa_s,
1368 #endif /* CONFIG_SME */
1371 #endif /* CONFIG_WNM */
1374 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1377 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1378 #endif /* CONFIG_WNM */
1382 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1383 union wpa_event_data *data)
1385 int l, len, found = 0, wpa_found, rsn_found;
1388 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1389 if (data->assoc_info.req_ies)
1390 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1391 data->assoc_info.req_ies_len);
1392 if (data->assoc_info.resp_ies) {
1393 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1394 data->assoc_info.resp_ies_len);
1396 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1397 data->assoc_info.resp_ies_len);
1398 #endif /* CONFIG_TDLS */
1400 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1401 data->assoc_info.resp_ies_len);
1402 #endif /* CONFIG_WNM */
1404 if (data->assoc_info.beacon_ies)
1405 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1406 data->assoc_info.beacon_ies,
1407 data->assoc_info.beacon_ies_len);
1408 if (data->assoc_info.freq)
1409 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1410 data->assoc_info.freq);
1412 p = data->assoc_info.req_ies;
1413 l = data->assoc_info.req_ies_len;
1415 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1416 while (p && l >= 2) {
1419 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1423 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1424 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1425 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1426 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1429 wpa_find_assoc_pmkid(wpa_s);
1435 if (!found && data->assoc_info.req_ies)
1436 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1438 #ifdef CONFIG_IEEE80211R
1440 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1442 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1443 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1444 data->assoc_info.resp_ies,
1445 data->assoc_info.resp_ies_len,
1447 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1448 "Reassociation Response failed");
1449 wpa_supplicant_deauthenticate(
1450 wpa_s, WLAN_REASON_INVALID_IE);
1455 p = data->assoc_info.resp_ies;
1456 l = data->assoc_info.resp_ies_len;
1458 #ifdef CONFIG_WPS_STRICT
1459 if (p && wpa_s->current_ssid &&
1460 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1462 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1464 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1465 "include WPS IE in (Re)Association Response");
1469 if (wps_validate_assoc_resp(wps) < 0) {
1471 wpa_supplicant_deauthenticate(
1472 wpa_s, WLAN_REASON_INVALID_IE);
1477 #endif /* CONFIG_WPS_STRICT */
1479 /* Go through the IEs and make a copy of the MDIE, if present. */
1480 while (p && l >= 2) {
1483 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1487 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1488 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1489 wpa_s->sme.ft_used = 1;
1490 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1491 MOBILITY_DOMAIN_ID_LEN);
1497 #endif /* CONFIG_SME */
1499 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1500 data->assoc_info.resp_ies_len);
1501 #endif /* CONFIG_IEEE80211R */
1503 /* WPA/RSN IE from Beacon/ProbeResp */
1504 p = data->assoc_info.beacon_ies;
1505 l = data->assoc_info.beacon_ies_len;
1507 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1509 wpa_found = rsn_found = 0;
1510 while (p && l >= 2) {
1513 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1518 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1519 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1521 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1525 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1527 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1534 if (!wpa_found && data->assoc_info.beacon_ies)
1535 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1536 if (!rsn_found && data->assoc_info.beacon_ies)
1537 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1538 if (wpa_found || rsn_found)
1539 wpa_s->ap_ies_from_associnfo = 1;
1541 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1542 wpa_s->assoc_freq != data->assoc_info.freq) {
1543 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1545 wpa_s->assoc_freq, data->assoc_info.freq);
1546 wpa_supplicant_update_scan_results(wpa_s);
1549 wpa_s->assoc_freq = data->assoc_info.freq;
1555 static struct wpa_bss * wpa_supplicant_get_new_bss(
1556 struct wpa_supplicant *wpa_s, const u8 *bssid)
1558 struct wpa_bss *bss = NULL;
1559 struct wpa_ssid *ssid = wpa_s->current_ssid;
1561 if (ssid->ssid_len > 0)
1562 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1564 bss = wpa_bss_get_bssid(wpa_s, bssid);
1570 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1572 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1574 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1577 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1580 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1581 WPA_IE_VENDOR_TYPE);
1582 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1584 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1585 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1586 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1587 bss_rsn ? 2 + bss_rsn[1] : 0))
1594 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1595 union wpa_event_data *data)
1599 struct wpa_driver_capa capa;
1602 if (wpa_s->ap_iface) {
1603 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1604 data->assoc_info.addr,
1605 data->assoc_info.req_ies,
1606 data->assoc_info.req_ies_len,
1607 data->assoc_info.reassoc);
1610 #endif /* CONFIG_AP */
1612 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1613 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1616 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1617 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1618 wpa_supplicant_deauthenticate(
1619 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1623 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1624 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1625 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1626 MACSTR, MAC2STR(bssid));
1627 random_add_randomness(bssid, ETH_ALEN);
1628 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1629 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1630 wpas_notify_bssid_changed(wpa_s);
1632 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1633 wpa_clear_keys(wpa_s, bssid);
1635 if (wpa_supplicant_select_config(wpa_s) < 0) {
1636 wpa_supplicant_deauthenticate(
1637 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1640 if (wpa_s->current_ssid) {
1641 struct wpa_bss *bss = NULL;
1643 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1645 wpa_supplicant_update_scan_results(wpa_s);
1647 /* Get the BSS from the new scan results */
1648 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1652 wpa_s->current_bss = bss;
1655 if (wpa_s->conf->ap_scan == 1 &&
1656 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1657 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1658 wpa_msg(wpa_s, MSG_WARNING,
1659 "WPA/RSN IEs not updated");
1664 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1665 wpa_s->sme.prev_bssid_set = 1;
1666 #endif /* CONFIG_SME */
1668 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1669 if (wpa_s->current_ssid) {
1670 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1671 * initialized before association, but for other modes,
1672 * initialize PC/SC here, if the current configuration needs
1673 * smartcard or SIM/USIM. */
1674 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1676 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1678 l2_packet_notify_auth_start(wpa_s->l2);
1681 * Set portEnabled first to FALSE in order to get EAP state machine out
1682 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1683 * state machine may transit to AUTHENTICATING state based on obsolete
1684 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1685 * AUTHENTICATED without ever giving chance to EAP state machine to
1688 if (!ft_completed) {
1689 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1690 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1692 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1693 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1694 /* 802.1X::portControl = Auto */
1695 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1696 wpa_s->eapol_received = 0;
1697 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1698 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1699 (wpa_s->current_ssid &&
1700 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1701 wpa_supplicant_cancel_auth_timeout(wpa_s);
1702 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1703 } else if (!ft_completed) {
1704 /* Timeout for receiving the first EAPOL packet */
1705 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1707 wpa_supplicant_cancel_scan(wpa_s);
1709 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1710 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1712 * We are done; the driver will take care of RSN 4-way
1715 wpa_supplicant_cancel_auth_timeout(wpa_s);
1716 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1717 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1718 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1719 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1720 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1722 * The driver will take care of RSN 4-way handshake, so we need
1723 * to allow EAPOL supplicant to complete its work without
1724 * waiting for WPA supplicant.
1726 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1727 } else if (ft_completed) {
1729 * FT protocol completed - make sure EAPOL state machine ends
1730 * up in authenticated.
1732 wpa_supplicant_cancel_auth_timeout(wpa_s);
1733 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1734 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1735 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1738 if (wpa_s->pending_eapol_rx) {
1739 struct os_time now, age;
1741 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1742 if (age.sec == 0 && age.usec < 100000 &&
1743 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1745 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1746 "frame that was received just before "
1747 "association notification");
1748 wpa_supplicant_rx_eapol(
1749 wpa_s, wpa_s->pending_eapol_rx_src,
1750 wpabuf_head(wpa_s->pending_eapol_rx),
1751 wpabuf_len(wpa_s->pending_eapol_rx));
1753 wpabuf_free(wpa_s->pending_eapol_rx);
1754 wpa_s->pending_eapol_rx = NULL;
1757 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1758 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1759 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1760 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1761 /* Set static WEP keys again */
1762 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1765 #ifdef CONFIG_IBSS_RSN
1766 if (wpa_s->current_ssid &&
1767 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1768 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1769 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1770 wpa_s->ibss_rsn == NULL) {
1771 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1772 if (!wpa_s->ibss_rsn) {
1773 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1774 wpa_supplicant_deauthenticate(
1775 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1779 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1781 #endif /* CONFIG_IBSS_RSN */
1783 wpas_wps_notify_assoc(wpa_s, bssid);
1787 static int disconnect_reason_recoverable(u16 reason_code)
1789 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1790 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1791 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1795 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1797 int locally_generated)
1801 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1803 * At least Host AP driver and a Prism3 card seemed to be
1804 * generating streams of disconnected events when configuring
1805 * IBSS for WPA-None. Ignore them for now.
1810 bssid = wpa_s->bssid;
1811 if (is_zero_ether_addr(bssid))
1812 bssid = wpa_s->pending_bssid;
1814 if (!is_zero_ether_addr(bssid) ||
1815 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1816 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1818 MAC2STR(bssid), reason_code,
1819 locally_generated ? " locally_generated=1" : "");
1824 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1825 int locally_generated)
1827 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1828 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1829 return 0; /* Not in 4-way handshake with PSK */
1832 * It looks like connection was lost while trying to go through PSK
1833 * 4-way handshake. Filter out known disconnection cases that are caused
1834 * by something else than PSK mismatch to avoid confusing reports.
1837 if (locally_generated) {
1838 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1846 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1848 int locally_generated)
1852 u8 prev_pending_bssid[ETH_ALEN];
1853 struct wpa_bss *fast_reconnect = NULL;
1854 struct wpa_ssid *fast_reconnect_ssid = NULL;
1855 struct wpa_ssid *last_ssid;
1857 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1858 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1860 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1862 * At least Host AP driver and a Prism3 card seemed to be
1863 * generating streams of disconnected events when configuring
1864 * IBSS for WPA-None. Ignore them for now.
1866 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1867 "IBSS/WPA-None mode");
1871 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1872 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1873 "pre-shared key may be incorrect");
1874 wpas_auth_failed(wpa_s);
1876 if (!wpa_s->auto_reconnect_disabled ||
1877 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1878 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1879 "reconnect (wps=%d wpa_state=%d)",
1880 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1882 if (wpa_s->wpa_state == WPA_COMPLETED &&
1883 wpa_s->current_ssid &&
1884 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1885 !locally_generated &&
1886 disconnect_reason_recoverable(reason_code)) {
1888 * It looks like the AP has dropped association with
1889 * us, but could allow us to get back in. Try to
1890 * reconnect to the same BSS without full scan to save
1891 * time for some common cases.
1893 fast_reconnect = wpa_s->current_bss;
1894 fast_reconnect_ssid = wpa_s->current_ssid;
1895 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1896 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1898 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1901 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1902 "try to re-connect");
1903 wpa_s->reassociate = 0;
1904 wpa_s->disconnected = 1;
1905 wpa_supplicant_cancel_sched_scan(wpa_s);
1907 bssid = wpa_s->bssid;
1908 if (is_zero_ether_addr(bssid))
1909 bssid = wpa_s->pending_bssid;
1910 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1911 wpas_connection_failed(wpa_s, bssid);
1912 wpa_sm_notify_disassoc(wpa_s->wpa);
1913 if (locally_generated)
1914 wpa_s->disconnect_reason = -reason_code;
1916 wpa_s->disconnect_reason = reason_code;
1917 wpas_notify_disconnect_reason(wpa_s);
1918 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1919 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1920 wpa_s->keys_cleared = 0;
1921 wpa_clear_keys(wpa_s, wpa_s->bssid);
1923 last_ssid = wpa_s->current_ssid;
1924 wpa_supplicant_mark_disassoc(wpa_s);
1926 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1927 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1928 wpa_s->current_ssid = last_ssid;
1931 if (fast_reconnect) {
1932 #ifndef CONFIG_NO_SCAN_PROCESSING
1933 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1934 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1935 fast_reconnect_ssid) < 0) {
1936 /* Recover through full scan */
1937 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1939 #endif /* CONFIG_NO_SCAN_PROCESSING */
1944 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1945 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1947 struct wpa_supplicant *wpa_s = eloop_ctx;
1949 if (!wpa_s->pending_mic_error_report)
1952 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1953 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1954 wpa_s->pending_mic_error_report = 0;
1956 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1960 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1961 union wpa_event_data *data)
1966 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1967 pairwise = (data && data->michael_mic_failure.unicast);
1969 if ((wpa_s->last_michael_mic_error &&
1970 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1971 wpa_s->pending_mic_error_report) {
1972 if (wpa_s->pending_mic_error_report) {
1974 * Send the pending MIC error report immediately since
1975 * we are going to start countermeasures and AP better
1978 wpa_sm_key_request(wpa_s->wpa, 1,
1979 wpa_s->pending_mic_error_pairwise);
1982 /* Send the new MIC error report immediately since we are going
1983 * to start countermeasures and AP better do the same.
1985 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1987 /* initialize countermeasures */
1988 wpa_s->countermeasures = 1;
1990 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1992 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1995 * Need to wait for completion of request frame. We do not get
1996 * any callback for the message completion, so just wait a
1997 * short while and hope for the best. */
2000 wpa_drv_set_countermeasures(wpa_s, 1);
2001 wpa_supplicant_deauthenticate(wpa_s,
2002 WLAN_REASON_MICHAEL_MIC_FAILURE);
2003 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2005 eloop_register_timeout(60, 0,
2006 wpa_supplicant_stop_countermeasures,
2008 /* TODO: mark the AP rejected for 60 second. STA is
2009 * allowed to associate with another AP.. */
2011 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2012 if (wpa_s->mic_errors_seen) {
2014 * Reduce the effectiveness of Michael MIC error
2015 * reports as a means for attacking against TKIP if
2016 * more than one MIC failure is noticed with the same
2017 * PTK. We delay the transmission of the reports by a
2018 * random time between 0 and 60 seconds in order to
2019 * force the attacker wait 60 seconds before getting
2020 * the information on whether a frame resulted in a MIC
2026 if (os_get_random(rval, sizeof(rval)) < 0)
2027 sec = os_random() % 60;
2029 sec = WPA_GET_BE32(rval) % 60;
2030 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2031 "report %d seconds", sec);
2032 wpa_s->pending_mic_error_report = 1;
2033 wpa_s->pending_mic_error_pairwise = pairwise;
2034 eloop_cancel_timeout(
2035 wpa_supplicant_delayed_mic_error_report,
2037 eloop_register_timeout(
2038 sec, os_random() % 1000000,
2039 wpa_supplicant_delayed_mic_error_report,
2042 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2044 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2045 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2046 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2048 wpa_s->last_michael_mic_error = t.sec;
2049 wpa_s->mic_errors_seen++;
2053 #ifdef CONFIG_TERMINATE_ONLASTIF
2054 static int any_interfaces(struct wpa_supplicant *head)
2056 struct wpa_supplicant *wpa_s;
2058 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2059 if (!wpa_s->interface_removed)
2063 #endif /* CONFIG_TERMINATE_ONLASTIF */
2067 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2068 union wpa_event_data *data)
2070 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2073 switch (data->interface_status.ievent) {
2074 case EVENT_INTERFACE_ADDED:
2075 if (!wpa_s->interface_removed)
2077 wpa_s->interface_removed = 0;
2078 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2079 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2080 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2081 "driver after interface was added");
2083 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2085 case EVENT_INTERFACE_REMOVED:
2086 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2087 wpa_s->interface_removed = 1;
2088 wpa_supplicant_mark_disassoc(wpa_s);
2089 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2090 l2_packet_deinit(wpa_s->l2);
2092 #ifdef CONFIG_IBSS_RSN
2093 ibss_rsn_deinit(wpa_s->ibss_rsn);
2094 wpa_s->ibss_rsn = NULL;
2095 #endif /* CONFIG_IBSS_RSN */
2096 #ifdef CONFIG_TERMINATE_ONLASTIF
2097 /* check if last interface */
2098 if (!any_interfaces(wpa_s->global->ifaces))
2100 #endif /* CONFIG_TERMINATE_ONLASTIF */
2106 #ifdef CONFIG_PEERKEY
2108 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2109 union wpa_event_data *data)
2113 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2115 #endif /* CONFIG_PEERKEY */
2119 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2120 union wpa_event_data *data)
2124 switch (data->tdls.oper) {
2125 case TDLS_REQUEST_SETUP:
2126 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2128 case TDLS_REQUEST_TEARDOWN:
2129 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2130 data->tdls.reason_code);
2134 #endif /* CONFIG_TDLS */
2137 #ifdef CONFIG_IEEE80211V
2138 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2139 union wpa_event_data *data)
2143 switch (data->wnm.oper) {
2144 case WNM_OPER_SLEEP:
2145 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2146 "(action=%d, intval=%d)",
2147 data->wnm.sleep_action, data->wnm.sleep_intval);
2148 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2149 data->wnm.sleep_intval);
2153 #endif /* CONFIG_IEEE80211V */
2156 #ifdef CONFIG_IEEE80211R
2158 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2159 union wpa_event_data *data)
2164 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2165 data->ft_ies.ies_len,
2166 data->ft_ies.ft_action,
2167 data->ft_ies.target_ap,
2168 data->ft_ies.ric_ies,
2169 data->ft_ies.ric_ies_len) < 0) {
2170 /* TODO: prevent MLME/driver from trying to associate? */
2173 #endif /* CONFIG_IEEE80211R */
2176 #ifdef CONFIG_IBSS_RSN
2177 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2178 union wpa_event_data *data)
2180 struct wpa_ssid *ssid;
2181 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2185 ssid = wpa_s->current_ssid;
2188 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2191 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2193 #endif /* CONFIG_IBSS_RSN */
2196 #ifdef CONFIG_IEEE80211R
2197 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2200 const u8 *sta_addr, *target_ap_addr;
2203 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2204 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2205 return; /* only SME case supported for now */
2206 if (len < 1 + 2 * ETH_ALEN + 2)
2209 return; /* Only FT Action Response is supported for now */
2210 sta_addr = data + 1;
2211 target_ap_addr = data + 1 + ETH_ALEN;
2212 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2213 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2214 MACSTR " TargetAP " MACSTR " status %u",
2215 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2217 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2218 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2219 " in FT Action Response", MAC2STR(sta_addr));
2224 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2225 "failure (status code %d)", status);
2226 /* TODO: report error to FT code(?) */
2230 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2231 len - (1 + 2 * ETH_ALEN + 2), 1,
2232 target_ap_addr, NULL, 0) < 0)
2237 struct wpa_bss *bss;
2238 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2240 wpa_s->sme.freq = bss->freq;
2241 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2242 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2245 #endif /* CONFIG_SME */
2247 #endif /* CONFIG_IEEE80211R */
2250 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2251 struct unprot_deauth *e)
2253 #ifdef CONFIG_IEEE80211W
2254 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2255 "dropped: " MACSTR " -> " MACSTR
2256 " (reason code %u)",
2257 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2258 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2259 #endif /* CONFIG_IEEE80211W */
2263 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2264 struct unprot_disassoc *e)
2266 #ifdef CONFIG_IEEE80211W
2267 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2268 "dropped: " MACSTR " -> " MACSTR
2269 " (reason code %u)",
2270 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2271 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2272 #endif /* CONFIG_IEEE80211W */
2276 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2279 const u8 *pos, *end;
2281 if (rx->data == NULL || rx->len == 0)
2285 end = pos + rx->len;
2288 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2289 action, MAC2STR(rx->sa));
2291 case WNM_BSS_TRANS_MGMT_REQ:
2294 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2295 "Request: dialog_token=%u request_mode=0x%x "
2296 "disassoc_timer=%u validity_interval=%u",
2297 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2301 pos += 12; /* BSS Termination Duration */
2304 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2305 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2306 "Transition Management Request "
2310 os_memcpy(url, pos + 1, pos[0]);
2312 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2313 "Imminent - session_info_url=%s", url);
2320 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2321 union wpa_event_data *data)
2323 struct wpa_supplicant *wpa_s = ctx;
2324 u16 reason_code = 0;
2325 int locally_generated = 0;
2327 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2328 event != EVENT_INTERFACE_ENABLED &&
2329 event != EVENT_INTERFACE_STATUS &&
2330 event != EVENT_SCHED_SCAN_STOPPED) {
2331 wpa_dbg(wpa_s, MSG_DEBUG,
2332 "Ignore event %s (%d) while interface is disabled",
2333 event_to_string(event), event);
2337 #ifndef CONFIG_NO_STDOUT_DEBUG
2339 int level = MSG_DEBUG;
2341 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2342 const struct ieee80211_hdr *hdr;
2344 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2345 fc = le_to_host16(hdr->frame_control);
2346 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2347 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2348 level = MSG_EXCESSIVE;
2351 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2352 event_to_string(event), event);
2354 #endif /* CONFIG_NO_STDOUT_DEBUG */
2358 sme_event_auth(wpa_s, data);
2361 wpa_supplicant_event_assoc(wpa_s, data);
2363 case EVENT_DISASSOC:
2364 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2366 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2367 data->disassoc_info.reason_code,
2368 data->disassoc_info.locally_generated ?
2369 " (locally generated)" : "");
2370 if (data->disassoc_info.addr)
2371 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2372 MAC2STR(data->disassoc_info.addr));
2375 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2376 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2377 data->disassoc_info.addr);
2380 if (wpa_s->ap_iface) {
2381 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2385 #endif /* CONFIG_AP */
2387 reason_code = data->disassoc_info.reason_code;
2389 data->disassoc_info.locally_generated;
2390 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2391 data->disassoc_info.ie,
2392 data->disassoc_info.ie_len);
2394 wpas_p2p_disassoc_notif(
2395 wpa_s, data->disassoc_info.addr, reason_code,
2396 data->disassoc_info.ie,
2397 data->disassoc_info.ie_len,
2399 #endif /* CONFIG_P2P */
2401 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2402 sme_event_disassoc(wpa_s, data);
2405 if (event == EVENT_DEAUTH) {
2406 wpa_dbg(wpa_s, MSG_DEBUG,
2407 "Deauthentication notification");
2409 reason_code = data->deauth_info.reason_code;
2411 data->deauth_info.locally_generated;
2412 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2413 data->deauth_info.reason_code,
2414 data->deauth_info.locally_generated ?
2415 " (locally generated)" : "");
2416 if (data->deauth_info.addr) {
2417 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2419 MAC2STR(data->deauth_info.
2422 wpa_hexdump(MSG_DEBUG,
2423 "Deauthentication frame IE(s)",
2424 data->deauth_info.ie,
2425 data->deauth_info.ie_len);
2429 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2430 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2431 data->deauth_info.addr);
2434 if (wpa_s->ap_iface) {
2435 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2439 #endif /* CONFIG_AP */
2440 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2442 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2443 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2444 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2445 eapol_sm_failed(wpa_s->eapol)))
2446 wpas_auth_failed(wpa_s);
2448 if (event == EVENT_DEAUTH && data) {
2449 if (wpas_p2p_deauth_notif(wpa_s,
2450 data->deauth_info.addr,
2452 data->deauth_info.ie,
2453 data->deauth_info.ie_len,
2454 locally_generated) > 0) {
2456 * The interface was removed, so cannot
2457 * continue processing any additional
2458 * operations after this.
2463 #endif /* CONFIG_P2P */
2464 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2467 case EVENT_MICHAEL_MIC_FAILURE:
2468 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2470 #ifndef CONFIG_NO_SCAN_PROCESSING
2471 case EVENT_SCAN_RESULTS:
2472 wpa_supplicant_event_scan_results(wpa_s, data);
2474 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2475 wpa_s->global->p2p != NULL &&
2476 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2477 wpa_s->wpa_state != WPA_ASSOCIATING) {
2478 wpa_s->global->p2p_cb_on_scan_complete = 0;
2479 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2480 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2481 "continued after scan result processing");
2484 #endif /* CONFIG_P2P */
2486 #endif /* CONFIG_NO_SCAN_PROCESSING */
2487 case EVENT_ASSOCINFO:
2488 wpa_supplicant_event_associnfo(wpa_s, data);
2490 case EVENT_INTERFACE_STATUS:
2491 wpa_supplicant_event_interface_status(wpa_s, data);
2493 case EVENT_PMKID_CANDIDATE:
2494 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2496 #ifdef CONFIG_PEERKEY
2497 case EVENT_STKSTART:
2498 wpa_supplicant_event_stkstart(wpa_s, data);
2500 #endif /* CONFIG_PEERKEY */
2503 wpa_supplicant_event_tdls(wpa_s, data);
2505 #endif /* CONFIG_TDLS */
2506 #ifdef CONFIG_IEEE80211V
2508 wpa_supplicant_event_wnm(wpa_s, data);
2510 #endif /* CONFIG_IEEE80211V */
2511 #ifdef CONFIG_IEEE80211R
2512 case EVENT_FT_RESPONSE:
2513 wpa_supplicant_event_ft_response(wpa_s, data);
2515 #endif /* CONFIG_IEEE80211R */
2516 #ifdef CONFIG_IBSS_RSN
2517 case EVENT_IBSS_RSN_START:
2518 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2520 #endif /* CONFIG_IBSS_RSN */
2521 case EVENT_ASSOC_REJECT:
2522 if (data->assoc_reject.bssid)
2523 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2524 "bssid=" MACSTR " status_code=%u",
2525 MAC2STR(data->assoc_reject.bssid),
2526 data->assoc_reject.status_code);
2528 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2530 data->assoc_reject.status_code);
2531 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2532 sme_event_assoc_reject(wpa_s, data);
2534 const u8 *bssid = data->assoc_reject.bssid;
2535 if (bssid == NULL || is_zero_ether_addr(bssid))
2536 bssid = wpa_s->pending_bssid;
2537 wpas_connection_failed(wpa_s, bssid);
2538 wpa_supplicant_mark_disassoc(wpa_s);
2541 case EVENT_AUTH_TIMED_OUT:
2542 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2543 sme_event_auth_timed_out(wpa_s, data);
2545 case EVENT_ASSOC_TIMED_OUT:
2546 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2547 sme_event_assoc_timed_out(wpa_s, data);
2549 case EVENT_TX_STATUS:
2550 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2551 " type=%d stype=%d",
2552 MAC2STR(data->tx_status.dst),
2553 data->tx_status.type, data->tx_status.stype);
2555 if (wpa_s->ap_iface == NULL) {
2556 #ifdef CONFIG_OFFCHANNEL
2557 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2558 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2559 offchannel_send_action_tx_status(
2560 wpa_s, data->tx_status.dst,
2561 data->tx_status.data,
2562 data->tx_status.data_len,
2563 data->tx_status.ack ?
2564 OFFCHANNEL_SEND_ACTION_SUCCESS :
2565 OFFCHANNEL_SEND_ACTION_NO_ACK);
2566 #endif /* CONFIG_OFFCHANNEL */
2569 #endif /* CONFIG_AP */
2570 #ifdef CONFIG_OFFCHANNEL
2571 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2572 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2574 * Catch TX status events for Action frames we sent via group
2575 * interface in GO mode.
2577 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2578 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2579 os_memcmp(wpa_s->parent->pending_action_dst,
2580 data->tx_status.dst, ETH_ALEN) == 0) {
2581 offchannel_send_action_tx_status(
2582 wpa_s->parent, data->tx_status.dst,
2583 data->tx_status.data,
2584 data->tx_status.data_len,
2585 data->tx_status.ack ?
2586 OFFCHANNEL_SEND_ACTION_SUCCESS :
2587 OFFCHANNEL_SEND_ACTION_NO_ACK);
2590 #endif /* CONFIG_OFFCHANNEL */
2592 switch (data->tx_status.type) {
2593 case WLAN_FC_TYPE_MGMT:
2594 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2595 data->tx_status.data_len,
2596 data->tx_status.stype,
2597 data->tx_status.ack);
2599 case WLAN_FC_TYPE_DATA:
2600 ap_tx_status(wpa_s, data->tx_status.dst,
2601 data->tx_status.data,
2602 data->tx_status.data_len,
2603 data->tx_status.ack);
2606 #endif /* CONFIG_AP */
2609 case EVENT_EAPOL_TX_STATUS:
2610 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2611 data->eapol_tx_status.data,
2612 data->eapol_tx_status.data_len,
2613 data->eapol_tx_status.ack);
2615 case EVENT_DRIVER_CLIENT_POLL_OK:
2616 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2618 case EVENT_RX_FROM_UNKNOWN:
2619 if (wpa_s->ap_iface == NULL)
2621 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2622 data->rx_from_unknown.wds);
2624 case EVENT_CH_SWITCH:
2627 if (!wpa_s->ap_iface) {
2628 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2629 "event in non-AP mode");
2634 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2635 data->ch_switch.ht_enabled,
2636 data->ch_switch.ch_offset);
2637 #endif /* CONFIG_AP */
2639 case EVENT_RX_MGMT: {
2641 const struct ieee80211_mgmt *mgmt;
2643 mgmt = (const struct ieee80211_mgmt *)
2644 data->rx_mgmt.frame;
2645 fc = le_to_host16(mgmt->frame_control);
2646 stype = WLAN_FC_GET_STYPE(fc);
2648 if (wpa_s->ap_iface == NULL) {
2650 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2651 data->rx_mgmt.frame_len > 24) {
2652 const u8 *src = mgmt->sa;
2653 const u8 *ie = mgmt->u.probe_req.variable;
2654 size_t ie_len = data->rx_mgmt.frame_len -
2655 (mgmt->u.probe_req.variable -
2656 data->rx_mgmt.frame);
2657 wpas_p2p_probe_req_rx(
2658 wpa_s, src, mgmt->da,
2659 mgmt->bssid, ie, ie_len,
2660 data->rx_mgmt.ssi_signal);
2663 #endif /* CONFIG_P2P */
2664 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2665 "management frame in non-AP mode");
2669 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2670 data->rx_mgmt.frame_len > 24) {
2671 const u8 *ie = mgmt->u.probe_req.variable;
2672 size_t ie_len = data->rx_mgmt.frame_len -
2673 (mgmt->u.probe_req.variable -
2674 data->rx_mgmt.frame);
2676 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2677 mgmt->bssid, ie, ie_len,
2678 data->rx_mgmt.ssi_signal);
2681 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2684 #endif /* CONFIG_AP */
2685 case EVENT_RX_ACTION:
2686 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2687 " Category=%u DataLen=%d freq=%d MHz",
2688 MAC2STR(data->rx_action.sa),
2689 data->rx_action.category, (int) data->rx_action.len,
2690 data->rx_action.freq);
2691 #ifdef CONFIG_IEEE80211R
2692 if (data->rx_action.category == WLAN_ACTION_FT) {
2693 ft_rx_action(wpa_s, data->rx_action.data,
2694 data->rx_action.len);
2697 #endif /* CONFIG_IEEE80211R */
2698 #ifdef CONFIG_IEEE80211W
2700 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2701 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2702 data->rx_action.data,
2703 data->rx_action.len);
2706 #endif /* CONFIG_SME */
2707 #endif /* CONFIG_IEEE80211W */
2708 #ifdef CONFIG_IEEE80211V
2709 if (data->rx_action.category == WLAN_ACTION_WNM) {
2710 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2713 #endif /* CONFIG_IEEE80211V */
2715 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2716 gas_query_rx(wpa_s->gas, data->rx_action.da,
2717 data->rx_action.sa, data->rx_action.bssid,
2718 data->rx_action.data, data->rx_action.len,
2719 data->rx_action.freq) == 0)
2721 #endif /* CONFIG_GAS */
2722 if (data->rx_action.category == WLAN_ACTION_WNM) {
2723 wnm_action_rx(wpa_s, &data->rx_action);
2727 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2728 data->rx_action.len >= 4 &&
2729 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2730 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2731 "Response from " MACSTR,
2732 MAC2STR(data->rx_action.sa));
2735 #endif /* CONFIG_TDLS */
2737 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2739 data->rx_action.bssid,
2740 data->rx_action.category,
2741 data->rx_action.data,
2742 data->rx_action.len, data->rx_action.freq);
2743 #endif /* CONFIG_P2P */
2745 case EVENT_RX_PROBE_REQ:
2746 if (data->rx_probe_req.sa == NULL ||
2747 data->rx_probe_req.ie == NULL)
2750 if (wpa_s->ap_iface) {
2751 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2752 data->rx_probe_req.sa,
2753 data->rx_probe_req.da,
2754 data->rx_probe_req.bssid,
2755 data->rx_probe_req.ie,
2756 data->rx_probe_req.ie_len,
2757 data->rx_probe_req.ssi_signal);
2760 #endif /* CONFIG_AP */
2762 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2763 data->rx_probe_req.da,
2764 data->rx_probe_req.bssid,
2765 data->rx_probe_req.ie,
2766 data->rx_probe_req.ie_len,
2767 data->rx_probe_req.ssi_signal);
2768 #endif /* CONFIG_P2P */
2770 case EVENT_REMAIN_ON_CHANNEL:
2771 #ifdef CONFIG_OFFCHANNEL
2772 offchannel_remain_on_channel_cb(
2773 wpa_s, data->remain_on_channel.freq,
2774 data->remain_on_channel.duration);
2775 #endif /* CONFIG_OFFCHANNEL */
2777 wpas_p2p_remain_on_channel_cb(
2778 wpa_s, data->remain_on_channel.freq,
2779 data->remain_on_channel.duration);
2780 #endif /* CONFIG_P2P */
2782 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2783 #ifdef CONFIG_OFFCHANNEL
2784 offchannel_cancel_remain_on_channel_cb(
2785 wpa_s, data->remain_on_channel.freq);
2786 #endif /* CONFIG_OFFCHANNEL */
2788 wpas_p2p_cancel_remain_on_channel_cb(
2789 wpa_s, data->remain_on_channel.freq);
2790 #endif /* CONFIG_P2P */
2793 case EVENT_P2P_DEV_FOUND: {
2794 struct p2p_peer_info peer_info;
2796 os_memset(&peer_info, 0, sizeof(peer_info));
2797 if (data->p2p_dev_found.dev_addr)
2798 os_memcpy(peer_info.p2p_device_addr,
2799 data->p2p_dev_found.dev_addr, ETH_ALEN);
2800 if (data->p2p_dev_found.pri_dev_type)
2801 os_memcpy(peer_info.pri_dev_type,
2802 data->p2p_dev_found.pri_dev_type,
2803 sizeof(peer_info.pri_dev_type));
2804 if (data->p2p_dev_found.dev_name)
2805 os_strlcpy(peer_info.device_name,
2806 data->p2p_dev_found.dev_name,
2807 sizeof(peer_info.device_name));
2808 peer_info.config_methods = data->p2p_dev_found.config_methods;
2809 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2810 peer_info.group_capab = data->p2p_dev_found.group_capab;
2813 * FIX: new_device=1 is not necessarily correct. We should
2814 * maintain a P2P peer database in wpa_supplicant and update
2815 * this information based on whether the peer is truly new.
2817 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2820 case EVENT_P2P_GO_NEG_REQ_RX:
2821 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2822 data->p2p_go_neg_req_rx.dev_passwd_id);
2824 case EVENT_P2P_GO_NEG_COMPLETED:
2825 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2827 case EVENT_P2P_PROV_DISC_REQUEST:
2828 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2829 data->p2p_prov_disc_req.config_methods,
2830 data->p2p_prov_disc_req.dev_addr,
2831 data->p2p_prov_disc_req.pri_dev_type,
2832 data->p2p_prov_disc_req.dev_name,
2833 data->p2p_prov_disc_req.supp_config_methods,
2834 data->p2p_prov_disc_req.dev_capab,
2835 data->p2p_prov_disc_req.group_capab,
2838 case EVENT_P2P_PROV_DISC_RESPONSE:
2839 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2840 data->p2p_prov_disc_resp.config_methods);
2842 case EVENT_P2P_SD_REQUEST:
2843 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2844 data->p2p_sd_req.sa,
2845 data->p2p_sd_req.dialog_token,
2846 data->p2p_sd_req.update_indic,
2847 data->p2p_sd_req.tlvs,
2848 data->p2p_sd_req.tlvs_len);
2850 case EVENT_P2P_SD_RESPONSE:
2851 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2852 data->p2p_sd_resp.update_indic,
2853 data->p2p_sd_resp.tlvs,
2854 data->p2p_sd_resp.tlvs_len);
2856 #endif /* CONFIG_P2P */
2857 case EVENT_EAPOL_RX:
2858 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2859 data->eapol_rx.data,
2860 data->eapol_rx.data_len);
2862 case EVENT_SIGNAL_CHANGE:
2863 bgscan_notify_signal_change(
2864 wpa_s, data->signal_change.above_threshold,
2865 data->signal_change.current_signal,
2866 data->signal_change.current_noise,
2867 data->signal_change.current_txrate);
2869 case EVENT_INTERFACE_ENABLED:
2870 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2871 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2872 wpa_supplicant_update_mac_addr(wpa_s);
2874 if (!wpa_s->ap_iface) {
2875 wpa_supplicant_set_state(wpa_s,
2877 wpa_supplicant_req_scan(wpa_s, 0, 0);
2879 wpa_supplicant_set_state(wpa_s,
2881 #else /* CONFIG_AP */
2882 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2883 wpa_supplicant_req_scan(wpa_s, 0, 0);
2884 #endif /* CONFIG_AP */
2887 case EVENT_INTERFACE_DISABLED:
2888 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2889 wpa_supplicant_mark_disassoc(wpa_s);
2890 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2892 case EVENT_CHANNEL_LIST_CHANGED:
2893 if (wpa_s->drv_priv == NULL)
2894 break; /* Ignore event during drv initialization */
2896 free_hw_features(wpa_s);
2897 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2898 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2901 wpas_p2p_update_channel_list(wpa_s);
2902 #endif /* CONFIG_P2P */
2904 case EVENT_INTERFACE_UNAVAILABLE:
2906 wpas_p2p_interface_unavailable(wpa_s);
2907 #endif /* CONFIG_P2P */
2909 case EVENT_BEST_CHANNEL:
2910 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2912 data->best_chan.freq_24, data->best_chan.freq_5,
2913 data->best_chan.freq_overall);
2914 wpa_s->best_24_freq = data->best_chan.freq_24;
2915 wpa_s->best_5_freq = data->best_chan.freq_5;
2916 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2918 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2919 data->best_chan.freq_5,
2920 data->best_chan.freq_overall);
2921 #endif /* CONFIG_P2P */
2923 case EVENT_UNPROT_DEAUTH:
2924 wpa_supplicant_event_unprot_deauth(wpa_s,
2925 &data->unprot_deauth);
2927 case EVENT_UNPROT_DISASSOC:
2928 wpa_supplicant_event_unprot_disassoc(wpa_s,
2929 &data->unprot_disassoc);
2931 case EVENT_STATION_LOW_ACK:
2933 if (wpa_s->ap_iface && data)
2934 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2935 data->low_ack.addr);
2936 #endif /* CONFIG_AP */
2939 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2940 #endif /* CONFIG_TDLS */
2942 case EVENT_IBSS_PEER_LOST:
2943 #ifdef CONFIG_IBSS_RSN
2944 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2945 #endif /* CONFIG_IBSS_RSN */
2947 case EVENT_DRIVER_GTK_REKEY:
2948 if (os_memcmp(data->driver_gtk_rekey.bssid,
2949 wpa_s->bssid, ETH_ALEN))
2953 wpa_sm_update_replay_ctr(wpa_s->wpa,
2954 data->driver_gtk_rekey.replay_ctr);
2956 case EVENT_SCHED_SCAN_STOPPED:
2957 wpa_s->sched_scanning = 0;
2958 wpa_supplicant_notify_scanning(wpa_s, 0);
2960 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2964 * If we timed out, start a new sched scan to continue
2965 * searching for more SSIDs.
2967 if (wpa_s->sched_scan_timed_out)
2968 wpa_supplicant_req_sched_scan(wpa_s);
2970 case EVENT_WPS_BUTTON_PUSHED:
2972 wpas_wps_start_pbc(wpa_s, NULL, 0);
2973 #endif /* CONFIG_WPS */
2976 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);