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_DEFAULT ?
430 wpa_s->conf->pmf : ssid->ieee80211w) ==
431 MGMT_FRAME_PROTECTION_REQUIRED) {
432 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
436 #endif /* CONFIG_IEEE80211W */
438 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
442 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
443 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
446 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
447 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
453 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
455 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
460 if (!(ie.proto & ssid->proto)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
466 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
467 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
472 if (!(ie.group_cipher & ssid->group_cipher)) {
473 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
478 if (!(ie.key_mgmt & ssid->key_mgmt)) {
479 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
484 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
488 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
490 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
494 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
495 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
500 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
501 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
505 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
512 static int freq_allowed(int *freqs, int freq)
519 for (i = 0; freqs[i]; i++)
520 if (freqs[i] == freq)
526 static int ht_supported(const struct hostapd_hw_modes *mode)
528 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
530 * The driver did not indicate whether it supports HT. Assume
531 * it does to avoid connection issues.
537 * IEEE Std 802.11n-2009 20.1.1:
538 * An HT non-AP STA shall support all EQM rates for one spatial stream.
540 return mode->mcs_set[0] == 0xff;
544 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
546 const struct hostapd_hw_modes *mode = NULL, *modes;
547 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
552 return 1; /* Cannot do matching without knowing band */
554 modes = wpa_s->hw.modes;
557 * The driver does not provide any additional information
558 * about the utilized hardware, so allow the connection attempt
564 for (i = 0; i < wpa_s->hw.num_modes; i++) {
565 for (j = 0; j < modes[i].num_channels; j++) {
566 int freq = modes[i].channels[j].freq;
567 if (freq == bss->freq) {
569 mode->mode == HOSTAPD_MODE_IEEE80211G)
570 break; /* do not allow 802.11b replace
581 for (i = 0; i < (int) sizeof(scan_ie); i++) {
582 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
586 for (j = 2; j < rate_ie[1] + 2; j++) {
587 int flagged = !!(rate_ie[j] & 0x80);
588 int r = (rate_ie[j] & 0x7f) * 5;
591 * IEEE Std 802.11n-2009 7.3.2.2:
592 * The new BSS Membership selector value is encoded
593 * like a legacy basic rate, but it is not a rate and
594 * only indicates if the BSS members are required to
595 * support the mandatory features of Clause 20 [HT PHY]
596 * in order to join the BSS.
598 if (flagged && ((rate_ie[j] & 0x7f) ==
599 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
600 if (!ht_supported(mode)) {
601 wpa_dbg(wpa_s, MSG_DEBUG,
602 " hardware does not support "
612 /* check for legacy basic rates */
613 for (k = 0; k < mode->num_rates; k++) {
614 if (mode->rates[k] == r)
617 if (k == mode->num_rates) {
619 * IEEE Std 802.11-2007 7.3.2.2 demands that in
620 * order to join a BSS all required rates
621 * have to be supported by the hardware.
623 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
624 "not support required rate %d.%d Mbps",
635 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
636 int i, struct wpa_bss *bss,
637 struct wpa_ssid *group)
639 u8 wpa_ie_len, rsn_ie_len;
641 struct wpa_blacklist *e;
643 struct wpa_ssid *ssid;
645 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
646 wpa_ie_len = ie ? ie[1] : 0;
648 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
649 rsn_ie_len = ie ? ie[1] : 0;
651 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
652 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
653 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
654 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
655 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
657 e = wpa_blacklist_get(wpa_s, bss->bssid);
660 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
662 * When only a single network is enabled, we can
663 * trigger blacklisting on the first failure. This
664 * should not be done with multiple enabled networks to
665 * avoid getting forced to move into a worse ESS on
666 * single error if there are no other BSSes of the
671 if (e->count > limit) {
672 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
673 "(count=%d limit=%d)", e->count, limit);
678 if (bss->ssid_len == 0) {
679 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
683 if (disallowed_bssid(wpa_s, bss->bssid)) {
684 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
688 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
689 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
693 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
695 for (ssid = group; ssid; ssid = ssid->pnext) {
696 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
699 if (wpas_network_disabled(wpa_s, ssid)) {
700 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
704 res = wpas_temp_disabled(wpa_s, ssid);
706 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
707 "temporarily for %d second(s)", res);
712 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
718 if (wpa && ssid->ssid_len == 0 &&
719 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
722 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
723 /* Only allow wildcard SSID match if an AP
724 * advertises active WPS operation that matches
727 if (ssid->ssid_len == 0 &&
728 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
731 #endif /* CONFIG_WPS */
733 if (ssid->bssid_set && ssid->ssid_len == 0 &&
734 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
738 (bss->ssid_len != ssid->ssid_len ||
739 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
740 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
744 if (ssid->bssid_set &&
745 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
746 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
750 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
754 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
755 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
756 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
757 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
762 if (!wpa_supplicant_match_privacy(bss, ssid)) {
763 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
768 if (bss->caps & IEEE80211_CAP_IBSS) {
769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
774 if (!freq_allowed(ssid->freq_list, bss->freq)) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
780 if (!rate_match(wpa_s, bss)) {
781 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
788 * TODO: skip the AP if its P2P IE has Group Formation
789 * bit set in the P2P Group Capability Bitmap and we
790 * are not in Group Formation with that device.
792 #endif /* CONFIG_P2P */
794 /* Matching configuration found */
798 /* No matching configuration found */
803 static struct wpa_bss *
804 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
805 struct wpa_ssid *group,
806 struct wpa_ssid **selected_ssid)
810 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
813 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
814 struct wpa_bss *bss = wpa_s->last_scan_res[i];
815 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
818 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
821 wpa_ssid_txt(bss->ssid, bss->ssid_len));
829 static struct wpa_bss *
830 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
831 struct wpa_ssid **selected_ssid)
833 struct wpa_bss *selected = NULL;
836 if (wpa_s->last_scan_res == NULL ||
837 wpa_s->last_scan_res_used == 0)
838 return NULL; /* no scan results from last update */
840 while (selected == NULL) {
841 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
842 selected = wpa_supplicant_select_bss(
843 wpa_s, wpa_s->conf->pssid[prio],
849 if (selected == NULL && wpa_s->blacklist &&
850 !wpa_s->countermeasures) {
851 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
852 "blacklist and try again");
853 wpa_blacklist_clear(wpa_s);
854 wpa_s->blacklist_cleared++;
855 } else if (selected == NULL)
863 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
864 int timeout_sec, int timeout_usec)
866 if (!wpa_supplicant_enabled_networks(wpa_s)) {
868 * No networks are enabled; short-circuit request so
869 * we don't wait timeout seconds before transitioning
872 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
873 "since there are no enabled networks");
874 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
876 wpa_s->sta_scan_pending = 0;
877 #endif /* CONFIG_P2P */
881 wpa_s->scan_for_connection = 1;
882 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
886 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
887 struct wpa_bss *selected,
888 struct wpa_ssid *ssid)
890 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
891 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
892 "PBC session overlap");
894 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
896 #endif /* CONFIG_P2P */
899 wpas_wps_cancel(wpa_s);
900 #endif /* CONFIG_WPS */
905 * Do not trigger new association unless the BSSID has changed or if
906 * reassociation is requested. If we are in process of associating with
907 * the selected BSSID, do not trigger new attempt.
909 if (wpa_s->reassociate ||
910 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
911 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
912 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
913 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
915 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
916 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
919 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
920 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
921 " pending: " MACSTR " wpa_state: %s",
922 wpa_s->reassociate, MAC2STR(selected->bssid),
923 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
924 wpa_supplicant_state_txt(wpa_s->wpa_state));
925 wpa_supplicant_associate(wpa_s, selected, ssid);
927 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
935 static struct wpa_ssid *
936 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
939 struct wpa_ssid *ssid;
941 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
942 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
944 if (wpas_network_disabled(wpa_s, ssid))
946 if (ssid->mode == IEEE80211_MODE_IBSS ||
947 ssid->mode == IEEE80211_MODE_AP)
955 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
956 * on BSS added and BSS changed events */
957 static void wpa_supplicant_rsn_preauth_scan_results(
958 struct wpa_supplicant *wpa_s)
962 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
965 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
966 const u8 *ssid, *rsn;
968 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
972 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
976 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
982 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
983 struct wpa_bss *selected,
984 struct wpa_ssid *ssid)
986 struct wpa_bss *current_bss = NULL;
989 if (wpa_s->reassociate)
990 return 1; /* explicit request to reassociate */
991 if (wpa_s->wpa_state < WPA_ASSOCIATED)
992 return 1; /* we are not associated; continue */
993 if (wpa_s->current_ssid == NULL)
994 return 1; /* unknown current SSID */
995 if (wpa_s->current_ssid != ssid)
996 return 1; /* different network block */
998 if (wpas_driver_bss_selection(wpa_s))
999 return 0; /* Driver-based roaming */
1001 if (wpa_s->current_ssid->ssid)
1002 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1003 wpa_s->current_ssid->ssid,
1004 wpa_s->current_ssid->ssid_len);
1006 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1009 return 1; /* current BSS not seen in scan results */
1011 if (current_bss == selected)
1014 if (selected->last_update_idx > current_bss->last_update_idx)
1015 return 1; /* current BSS not seen in the last scan */
1017 #ifndef CONFIG_NO_ROAMING
1018 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1019 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1020 MAC2STR(current_bss->bssid), current_bss->level);
1021 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1022 MAC2STR(selected->bssid), selected->level);
1024 if (wpa_s->current_ssid->bssid_set &&
1025 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1027 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1028 "has preferred BSSID");
1032 if (current_bss->level < 0 && current_bss->level > selected->level) {
1033 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1039 if (current_bss->level < 0) {
1040 if (current_bss->level < -85)
1042 else if (current_bss->level < -80)
1044 else if (current_bss->level < -75)
1046 else if (current_bss->level < -70)
1051 if (abs(current_bss->level - selected->level) < min_diff) {
1052 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1058 #else /* CONFIG_NO_ROAMING */
1060 #endif /* CONFIG_NO_ROAMING */
1064 /* Return != 0 if no scan results could be fetched or if scan results should not
1065 * be shared with other virtual interfaces. */
1066 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1067 union wpa_event_data *data)
1069 struct wpa_scan_results *scan_res;
1071 #ifndef CONFIG_NO_RANDOM_POOL
1073 #endif /* CONFIG_NO_RANDOM_POOL */
1076 if (wpa_s->ap_iface)
1078 #endif /* CONFIG_AP */
1080 wpa_supplicant_notify_scanning(wpa_s, 0);
1083 if (wpa_s->global->p2p_cb_on_scan_complete &&
1084 !wpa_s->global->p2p_disabled &&
1085 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1086 !wpa_s->scan_res_handler) {
1087 wpa_s->global->p2p_cb_on_scan_complete = 0;
1088 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1089 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1090 "stopped scan processing");
1091 wpa_s->sta_scan_pending = 1;
1092 wpa_supplicant_req_scan(wpa_s, 5, 0);
1096 wpa_s->sta_scan_pending = 0;
1097 #endif /* CONFIG_P2P */
1099 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1100 data ? &data->scan_info :
1102 if (scan_res == NULL) {
1103 if (wpa_s->conf->ap_scan == 2 || ap)
1105 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1107 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1111 #ifndef CONFIG_NO_RANDOM_POOL
1112 num = scan_res->num;
1115 for (i = 0; i < num; i++) {
1117 struct wpa_scan_res *res = scan_res->res[i];
1118 buf[0] = res->bssid[5];
1119 buf[1] = res->qual & 0xff;
1120 buf[2] = res->noise & 0xff;
1121 buf[3] = res->level & 0xff;
1122 buf[4] = res->tsf & 0xff;
1123 random_add_randomness(buf, sizeof(buf));
1125 #endif /* CONFIG_NO_RANDOM_POOL */
1127 if (wpa_s->scan_res_handler) {
1128 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1129 struct wpa_scan_results *scan_res);
1131 scan_res_handler = wpa_s->scan_res_handler;
1132 wpa_s->scan_res_handler = NULL;
1133 scan_res_handler(wpa_s, scan_res);
1135 wpa_scan_results_free(scan_res);
1140 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1142 if (wpa_s->ap_iface->scan_cb)
1143 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1144 #endif /* CONFIG_AP */
1145 wpa_scan_results_free(scan_res);
1149 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1150 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1151 wpas_notify_scan_results(wpa_s);
1153 wpas_notify_scan_done(wpa_s, 1);
1155 if (sme_proc_obss_scan(wpa_s) > 0) {
1156 wpa_scan_results_free(scan_res);
1160 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1161 wpa_scan_results_free(scan_res);
1165 if (autoscan_notify_scan(wpa_s, scan_res)) {
1166 wpa_scan_results_free(scan_res);
1170 if (wpa_s->disconnected) {
1171 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1172 wpa_scan_results_free(scan_res);
1176 if (!wpas_driver_bss_selection(wpa_s) &&
1177 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1178 wpa_scan_results_free(scan_res);
1182 wpas_wps_update_ap_info(wpa_s, scan_res);
1184 wpa_scan_results_free(scan_res);
1186 return wpas_select_network_from_last_scan(wpa_s);
1190 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1192 struct wpa_bss *selected;
1193 struct wpa_ssid *ssid = NULL;
1195 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1199 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1201 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1205 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1206 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1209 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1211 * Do not notify other virtual radios of scan results since we do not
1212 * want them to start other associations at the same time.
1216 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1217 ssid = wpa_supplicant_pick_new_network(wpa_s);
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1220 wpa_supplicant_associate(wpa_s, NULL, ssid);
1221 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1223 int timeout_sec = wpa_s->scan_interval;
1224 int timeout_usec = 0;
1226 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1229 if (wpa_s->p2p_in_provisioning) {
1231 * Use shorter wait during P2P Provisioning
1232 * state to speed up group formation.
1235 timeout_usec = 250000;
1236 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1240 #endif /* CONFIG_P2P */
1241 #ifdef CONFIG_INTERWORKING
1242 if (wpa_s->conf->auto_interworking &&
1243 wpa_s->conf->interworking &&
1244 wpa_s->conf->cred) {
1245 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1246 "start ANQP fetch since no matching "
1248 wpa_s->network_select = 1;
1249 wpa_s->auto_network_select = 1;
1250 interworking_start_fetch_anqp(wpa_s);
1253 #endif /* CONFIG_INTERWORKING */
1254 if (wpa_supplicant_req_sched_scan(wpa_s))
1255 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1263 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1264 union wpa_event_data *data)
1266 const char *rn, *rn2;
1267 struct wpa_supplicant *ifs;
1269 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1271 * If no scan results could be fetched, then no need to
1272 * notify those interfaces that did not actually request
1273 * this scan. Similarly, if scan results started a new operation on this
1274 * interface, do not notify other interfaces to avoid concurrent
1275 * operations during a connection attempt.
1281 * Check other interfaces to see if they have the same radio-name. If
1282 * so, they get updated with this same scan info.
1284 if (!wpa_s->driver->get_radio_name)
1287 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1288 if (rn == NULL || rn[0] == '\0')
1291 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1292 "sharing same radio (%s) in event_scan_results", rn);
1294 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1295 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1298 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1299 if (rn2 && os_strcmp(rn, rn2) == 0) {
1300 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1301 "sibling", ifs->ifname);
1302 _wpa_supplicant_event_scan_results(ifs, data);
1307 #endif /* CONFIG_NO_SCAN_PROCESSING */
1312 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1314 struct wpa_supplicant *wpa_s = eloop_ctx;
1316 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1319 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1320 MAC2STR(wpa_s->bssid));
1321 /* TODO: could skip this if normal data traffic has been sent */
1322 /* TODO: Consider using some more appropriate data frame for this */
1324 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1327 if (wpa_s->sme.bss_max_idle_period) {
1329 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1332 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1333 wnm_bss_keep_alive, wpa_s, NULL);
1335 #endif /* CONFIG_SME */
1339 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1340 const u8 *ies, size_t ies_len)
1342 struct ieee802_11_elems elems;
1347 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1351 if (elems.bss_max_idle_period) {
1353 wpa_s->sme.bss_max_idle_period =
1354 WPA_GET_LE16(elems.bss_max_idle_period);
1355 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1356 "TU)%s", wpa_s->sme.bss_max_idle_period,
1357 (elems.bss_max_idle_period[2] & 0x01) ?
1358 " (protected keep-live required)" : "");
1359 if (wpa_s->sme.bss_max_idle_period == 0)
1360 wpa_s->sme.bss_max_idle_period = 1;
1361 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1362 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1363 /* msec times 1000 */
1364 msec = wpa_s->sme.bss_max_idle_period * 1024;
1367 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1368 wnm_bss_keep_alive, wpa_s,
1372 #endif /* CONFIG_SME */
1375 #endif /* CONFIG_WNM */
1378 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1381 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1382 #endif /* CONFIG_WNM */
1386 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1387 union wpa_event_data *data)
1389 int l, len, found = 0, wpa_found, rsn_found;
1392 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1393 if (data->assoc_info.req_ies)
1394 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1395 data->assoc_info.req_ies_len);
1396 if (data->assoc_info.resp_ies) {
1397 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1398 data->assoc_info.resp_ies_len);
1400 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1401 data->assoc_info.resp_ies_len);
1402 #endif /* CONFIG_TDLS */
1404 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1405 data->assoc_info.resp_ies_len);
1406 #endif /* CONFIG_WNM */
1408 if (data->assoc_info.beacon_ies)
1409 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1410 data->assoc_info.beacon_ies,
1411 data->assoc_info.beacon_ies_len);
1412 if (data->assoc_info.freq)
1413 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1414 data->assoc_info.freq);
1416 p = data->assoc_info.req_ies;
1417 l = data->assoc_info.req_ies_len;
1419 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1420 while (p && l >= 2) {
1423 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1427 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1428 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1429 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1430 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1433 wpa_find_assoc_pmkid(wpa_s);
1439 if (!found && data->assoc_info.req_ies)
1440 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1442 #ifdef CONFIG_IEEE80211R
1444 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1446 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1447 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1448 data->assoc_info.resp_ies,
1449 data->assoc_info.resp_ies_len,
1451 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1452 "Reassociation Response failed");
1453 wpa_supplicant_deauthenticate(
1454 wpa_s, WLAN_REASON_INVALID_IE);
1459 p = data->assoc_info.resp_ies;
1460 l = data->assoc_info.resp_ies_len;
1462 #ifdef CONFIG_WPS_STRICT
1463 if (p && wpa_s->current_ssid &&
1464 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1466 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1468 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1469 "include WPS IE in (Re)Association Response");
1473 if (wps_validate_assoc_resp(wps) < 0) {
1475 wpa_supplicant_deauthenticate(
1476 wpa_s, WLAN_REASON_INVALID_IE);
1481 #endif /* CONFIG_WPS_STRICT */
1483 /* Go through the IEs and make a copy of the MDIE, if present. */
1484 while (p && l >= 2) {
1487 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1491 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1492 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1493 wpa_s->sme.ft_used = 1;
1494 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1495 MOBILITY_DOMAIN_ID_LEN);
1501 #endif /* CONFIG_SME */
1503 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1504 data->assoc_info.resp_ies_len);
1505 #endif /* CONFIG_IEEE80211R */
1507 /* WPA/RSN IE from Beacon/ProbeResp */
1508 p = data->assoc_info.beacon_ies;
1509 l = data->assoc_info.beacon_ies_len;
1511 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1513 wpa_found = rsn_found = 0;
1514 while (p && l >= 2) {
1517 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1522 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1523 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1525 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1529 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1531 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1538 if (!wpa_found && data->assoc_info.beacon_ies)
1539 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1540 if (!rsn_found && data->assoc_info.beacon_ies)
1541 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1542 if (wpa_found || rsn_found)
1543 wpa_s->ap_ies_from_associnfo = 1;
1545 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1546 wpa_s->assoc_freq != data->assoc_info.freq) {
1547 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1549 wpa_s->assoc_freq, data->assoc_info.freq);
1550 wpa_supplicant_update_scan_results(wpa_s);
1553 wpa_s->assoc_freq = data->assoc_info.freq;
1559 static struct wpa_bss * wpa_supplicant_get_new_bss(
1560 struct wpa_supplicant *wpa_s, const u8 *bssid)
1562 struct wpa_bss *bss = NULL;
1563 struct wpa_ssid *ssid = wpa_s->current_ssid;
1565 if (ssid->ssid_len > 0)
1566 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1568 bss = wpa_bss_get_bssid(wpa_s, bssid);
1574 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1576 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1578 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1581 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1584 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1585 WPA_IE_VENDOR_TYPE);
1586 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1588 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1589 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1590 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1591 bss_rsn ? 2 + bss_rsn[1] : 0))
1598 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1599 union wpa_event_data *data)
1603 struct wpa_driver_capa capa;
1606 if (wpa_s->ap_iface) {
1607 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1608 data->assoc_info.addr,
1609 data->assoc_info.req_ies,
1610 data->assoc_info.req_ies_len,
1611 data->assoc_info.reassoc);
1614 #endif /* CONFIG_AP */
1616 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1617 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1620 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1621 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1622 wpa_supplicant_deauthenticate(
1623 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1627 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1628 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1629 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1630 MACSTR, MAC2STR(bssid));
1631 random_add_randomness(bssid, ETH_ALEN);
1632 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1633 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1634 wpas_notify_bssid_changed(wpa_s);
1636 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1637 wpa_clear_keys(wpa_s, bssid);
1639 if (wpa_supplicant_select_config(wpa_s) < 0) {
1640 wpa_supplicant_deauthenticate(
1641 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1644 if (wpa_s->current_ssid) {
1645 struct wpa_bss *bss = NULL;
1647 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1649 wpa_supplicant_update_scan_results(wpa_s);
1651 /* Get the BSS from the new scan results */
1652 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1656 wpa_s->current_bss = bss;
1659 if (wpa_s->conf->ap_scan == 1 &&
1660 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1661 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1662 wpa_msg(wpa_s, MSG_WARNING,
1663 "WPA/RSN IEs not updated");
1668 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1669 wpa_s->sme.prev_bssid_set = 1;
1670 #endif /* CONFIG_SME */
1672 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1673 if (wpa_s->current_ssid) {
1674 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1675 * initialized before association, but for other modes,
1676 * initialize PC/SC here, if the current configuration needs
1677 * smartcard or SIM/USIM. */
1678 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1680 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1682 l2_packet_notify_auth_start(wpa_s->l2);
1685 * Set portEnabled first to FALSE in order to get EAP state machine out
1686 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1687 * state machine may transit to AUTHENTICATING state based on obsolete
1688 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1689 * AUTHENTICATED without ever giving chance to EAP state machine to
1692 if (!ft_completed) {
1693 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1694 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1696 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1697 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1698 /* 802.1X::portControl = Auto */
1699 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1700 wpa_s->eapol_received = 0;
1701 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1702 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1703 (wpa_s->current_ssid &&
1704 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1705 wpa_supplicant_cancel_auth_timeout(wpa_s);
1706 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1707 } else if (!ft_completed) {
1708 /* Timeout for receiving the first EAPOL packet */
1709 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1711 wpa_supplicant_cancel_scan(wpa_s);
1713 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1714 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1716 * We are done; the driver will take care of RSN 4-way
1719 wpa_supplicant_cancel_auth_timeout(wpa_s);
1720 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1721 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1722 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1723 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1724 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1726 * The driver will take care of RSN 4-way handshake, so we need
1727 * to allow EAPOL supplicant to complete its work without
1728 * waiting for WPA supplicant.
1730 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1731 } else if (ft_completed) {
1733 * FT protocol completed - make sure EAPOL state machine ends
1734 * up in authenticated.
1736 wpa_supplicant_cancel_auth_timeout(wpa_s);
1737 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1738 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1739 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1742 if (wpa_s->pending_eapol_rx) {
1743 struct os_time now, age;
1745 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1746 if (age.sec == 0 && age.usec < 100000 &&
1747 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1749 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1750 "frame that was received just before "
1751 "association notification");
1752 wpa_supplicant_rx_eapol(
1753 wpa_s, wpa_s->pending_eapol_rx_src,
1754 wpabuf_head(wpa_s->pending_eapol_rx),
1755 wpabuf_len(wpa_s->pending_eapol_rx));
1757 wpabuf_free(wpa_s->pending_eapol_rx);
1758 wpa_s->pending_eapol_rx = NULL;
1761 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1762 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1763 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1764 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1765 /* Set static WEP keys again */
1766 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1769 #ifdef CONFIG_IBSS_RSN
1770 if (wpa_s->current_ssid &&
1771 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1772 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1773 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1774 wpa_s->ibss_rsn == NULL) {
1775 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1776 if (!wpa_s->ibss_rsn) {
1777 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1778 wpa_supplicant_deauthenticate(
1779 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1783 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1785 #endif /* CONFIG_IBSS_RSN */
1787 wpas_wps_notify_assoc(wpa_s, bssid);
1791 static int disconnect_reason_recoverable(u16 reason_code)
1793 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1794 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1795 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1799 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1801 int locally_generated)
1805 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1807 * At least Host AP driver and a Prism3 card seemed to be
1808 * generating streams of disconnected events when configuring
1809 * IBSS for WPA-None. Ignore them for now.
1814 bssid = wpa_s->bssid;
1815 if (is_zero_ether_addr(bssid))
1816 bssid = wpa_s->pending_bssid;
1818 if (!is_zero_ether_addr(bssid) ||
1819 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1820 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1822 MAC2STR(bssid), reason_code,
1823 locally_generated ? " locally_generated=1" : "");
1828 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1829 int locally_generated)
1831 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1832 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1833 return 0; /* Not in 4-way handshake with PSK */
1836 * It looks like connection was lost while trying to go through PSK
1837 * 4-way handshake. Filter out known disconnection cases that are caused
1838 * by something else than PSK mismatch to avoid confusing reports.
1841 if (locally_generated) {
1842 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1850 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1852 int locally_generated)
1856 u8 prev_pending_bssid[ETH_ALEN];
1857 struct wpa_bss *fast_reconnect = NULL;
1858 struct wpa_ssid *fast_reconnect_ssid = NULL;
1859 struct wpa_ssid *last_ssid;
1861 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1862 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1864 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1866 * At least Host AP driver and a Prism3 card seemed to be
1867 * generating streams of disconnected events when configuring
1868 * IBSS for WPA-None. Ignore them for now.
1870 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1871 "IBSS/WPA-None mode");
1875 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1876 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1877 "pre-shared key may be incorrect");
1878 wpas_auth_failed(wpa_s);
1880 if (!wpa_s->auto_reconnect_disabled ||
1881 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1882 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1883 "reconnect (wps=%d wpa_state=%d)",
1884 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1886 if (wpa_s->wpa_state == WPA_COMPLETED &&
1887 wpa_s->current_ssid &&
1888 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1889 !locally_generated &&
1890 disconnect_reason_recoverable(reason_code)) {
1892 * It looks like the AP has dropped association with
1893 * us, but could allow us to get back in. Try to
1894 * reconnect to the same BSS without full scan to save
1895 * time for some common cases.
1897 fast_reconnect = wpa_s->current_bss;
1898 fast_reconnect_ssid = wpa_s->current_ssid;
1899 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1900 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1902 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1905 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1906 "try to re-connect");
1907 wpa_s->reassociate = 0;
1908 wpa_s->disconnected = 1;
1909 wpa_supplicant_cancel_sched_scan(wpa_s);
1911 bssid = wpa_s->bssid;
1912 if (is_zero_ether_addr(bssid))
1913 bssid = wpa_s->pending_bssid;
1914 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1915 wpas_connection_failed(wpa_s, bssid);
1916 wpa_sm_notify_disassoc(wpa_s->wpa);
1917 if (locally_generated)
1918 wpa_s->disconnect_reason = -reason_code;
1920 wpa_s->disconnect_reason = reason_code;
1921 wpas_notify_disconnect_reason(wpa_s);
1922 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1923 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1924 wpa_s->keys_cleared = 0;
1925 wpa_clear_keys(wpa_s, wpa_s->bssid);
1927 last_ssid = wpa_s->current_ssid;
1928 wpa_supplicant_mark_disassoc(wpa_s);
1930 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1931 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1932 wpa_s->current_ssid = last_ssid;
1935 if (fast_reconnect) {
1936 #ifndef CONFIG_NO_SCAN_PROCESSING
1937 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1938 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1939 fast_reconnect_ssid) < 0) {
1940 /* Recover through full scan */
1941 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1943 #endif /* CONFIG_NO_SCAN_PROCESSING */
1948 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1949 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1951 struct wpa_supplicant *wpa_s = eloop_ctx;
1953 if (!wpa_s->pending_mic_error_report)
1956 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1957 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1958 wpa_s->pending_mic_error_report = 0;
1960 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1964 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1965 union wpa_event_data *data)
1970 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1971 pairwise = (data && data->michael_mic_failure.unicast);
1973 if ((wpa_s->last_michael_mic_error &&
1974 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1975 wpa_s->pending_mic_error_report) {
1976 if (wpa_s->pending_mic_error_report) {
1978 * Send the pending MIC error report immediately since
1979 * we are going to start countermeasures and AP better
1982 wpa_sm_key_request(wpa_s->wpa, 1,
1983 wpa_s->pending_mic_error_pairwise);
1986 /* Send the new MIC error report immediately since we are going
1987 * to start countermeasures and AP better do the same.
1989 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1991 /* initialize countermeasures */
1992 wpa_s->countermeasures = 1;
1994 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1996 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1999 * Need to wait for completion of request frame. We do not get
2000 * any callback for the message completion, so just wait a
2001 * short while and hope for the best. */
2004 wpa_drv_set_countermeasures(wpa_s, 1);
2005 wpa_supplicant_deauthenticate(wpa_s,
2006 WLAN_REASON_MICHAEL_MIC_FAILURE);
2007 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2009 eloop_register_timeout(60, 0,
2010 wpa_supplicant_stop_countermeasures,
2012 /* TODO: mark the AP rejected for 60 second. STA is
2013 * allowed to associate with another AP.. */
2015 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2016 if (wpa_s->mic_errors_seen) {
2018 * Reduce the effectiveness of Michael MIC error
2019 * reports as a means for attacking against TKIP if
2020 * more than one MIC failure is noticed with the same
2021 * PTK. We delay the transmission of the reports by a
2022 * random time between 0 and 60 seconds in order to
2023 * force the attacker wait 60 seconds before getting
2024 * the information on whether a frame resulted in a MIC
2030 if (os_get_random(rval, sizeof(rval)) < 0)
2031 sec = os_random() % 60;
2033 sec = WPA_GET_BE32(rval) % 60;
2034 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2035 "report %d seconds", sec);
2036 wpa_s->pending_mic_error_report = 1;
2037 wpa_s->pending_mic_error_pairwise = pairwise;
2038 eloop_cancel_timeout(
2039 wpa_supplicant_delayed_mic_error_report,
2041 eloop_register_timeout(
2042 sec, os_random() % 1000000,
2043 wpa_supplicant_delayed_mic_error_report,
2046 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2048 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2049 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2050 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2052 wpa_s->last_michael_mic_error = t.sec;
2053 wpa_s->mic_errors_seen++;
2057 #ifdef CONFIG_TERMINATE_ONLASTIF
2058 static int any_interfaces(struct wpa_supplicant *head)
2060 struct wpa_supplicant *wpa_s;
2062 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2063 if (!wpa_s->interface_removed)
2067 #endif /* CONFIG_TERMINATE_ONLASTIF */
2071 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2072 union wpa_event_data *data)
2074 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2077 switch (data->interface_status.ievent) {
2078 case EVENT_INTERFACE_ADDED:
2079 if (!wpa_s->interface_removed)
2081 wpa_s->interface_removed = 0;
2082 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2083 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2084 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2085 "driver after interface was added");
2087 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2089 case EVENT_INTERFACE_REMOVED:
2090 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2091 wpa_s->interface_removed = 1;
2092 wpa_supplicant_mark_disassoc(wpa_s);
2093 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2094 l2_packet_deinit(wpa_s->l2);
2096 #ifdef CONFIG_IBSS_RSN
2097 ibss_rsn_deinit(wpa_s->ibss_rsn);
2098 wpa_s->ibss_rsn = NULL;
2099 #endif /* CONFIG_IBSS_RSN */
2100 #ifdef CONFIG_TERMINATE_ONLASTIF
2101 /* check if last interface */
2102 if (!any_interfaces(wpa_s->global->ifaces))
2104 #endif /* CONFIG_TERMINATE_ONLASTIF */
2110 #ifdef CONFIG_PEERKEY
2112 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2113 union wpa_event_data *data)
2117 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2119 #endif /* CONFIG_PEERKEY */
2123 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2124 union wpa_event_data *data)
2128 switch (data->tdls.oper) {
2129 case TDLS_REQUEST_SETUP:
2130 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2132 case TDLS_REQUEST_TEARDOWN:
2133 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2134 data->tdls.reason_code);
2138 #endif /* CONFIG_TDLS */
2141 #ifdef CONFIG_IEEE80211V
2142 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2143 union wpa_event_data *data)
2147 switch (data->wnm.oper) {
2148 case WNM_OPER_SLEEP:
2149 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2150 "(action=%d, intval=%d)",
2151 data->wnm.sleep_action, data->wnm.sleep_intval);
2152 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2153 data->wnm.sleep_intval, NULL);
2157 #endif /* CONFIG_IEEE80211V */
2160 #ifdef CONFIG_IEEE80211R
2162 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2163 union wpa_event_data *data)
2168 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2169 data->ft_ies.ies_len,
2170 data->ft_ies.ft_action,
2171 data->ft_ies.target_ap,
2172 data->ft_ies.ric_ies,
2173 data->ft_ies.ric_ies_len) < 0) {
2174 /* TODO: prevent MLME/driver from trying to associate? */
2177 #endif /* CONFIG_IEEE80211R */
2180 #ifdef CONFIG_IBSS_RSN
2181 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2182 union wpa_event_data *data)
2184 struct wpa_ssid *ssid;
2185 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2189 ssid = wpa_s->current_ssid;
2192 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2195 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2197 #endif /* CONFIG_IBSS_RSN */
2200 #ifdef CONFIG_IEEE80211R
2201 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2204 const u8 *sta_addr, *target_ap_addr;
2207 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2208 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2209 return; /* only SME case supported for now */
2210 if (len < 1 + 2 * ETH_ALEN + 2)
2213 return; /* Only FT Action Response is supported for now */
2214 sta_addr = data + 1;
2215 target_ap_addr = data + 1 + ETH_ALEN;
2216 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2217 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2218 MACSTR " TargetAP " MACSTR " status %u",
2219 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2221 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2222 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2223 " in FT Action Response", MAC2STR(sta_addr));
2228 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2229 "failure (status code %d)", status);
2230 /* TODO: report error to FT code(?) */
2234 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2235 len - (1 + 2 * ETH_ALEN + 2), 1,
2236 target_ap_addr, NULL, 0) < 0)
2241 struct wpa_bss *bss;
2242 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2244 wpa_s->sme.freq = bss->freq;
2245 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2246 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2249 #endif /* CONFIG_SME */
2251 #endif /* CONFIG_IEEE80211R */
2254 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2255 struct unprot_deauth *e)
2257 #ifdef CONFIG_IEEE80211W
2258 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2259 "dropped: " MACSTR " -> " MACSTR
2260 " (reason code %u)",
2261 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2262 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2263 #endif /* CONFIG_IEEE80211W */
2267 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2268 struct unprot_disassoc *e)
2270 #ifdef CONFIG_IEEE80211W
2271 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2272 "dropped: " MACSTR " -> " MACSTR
2273 " (reason code %u)",
2274 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2275 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2276 #endif /* CONFIG_IEEE80211W */
2280 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2283 const u8 *pos, *end;
2285 if (rx->data == NULL || rx->len == 0)
2289 end = pos + rx->len;
2292 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2293 action, MAC2STR(rx->sa));
2295 case WNM_BSS_TRANS_MGMT_REQ:
2298 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2299 "Request: dialog_token=%u request_mode=0x%x "
2300 "disassoc_timer=%u validity_interval=%u",
2301 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2305 pos += 12; /* BSS Termination Duration */
2308 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2309 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2310 "Transition Management Request "
2314 os_memcpy(url, pos + 1, pos[0]);
2316 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2317 "Imminent - session_info_url=%s", url);
2324 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2325 union wpa_event_data *data)
2327 struct wpa_supplicant *wpa_s = ctx;
2328 u16 reason_code = 0;
2329 int locally_generated = 0;
2331 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2332 event != EVENT_INTERFACE_ENABLED &&
2333 event != EVENT_INTERFACE_STATUS &&
2334 event != EVENT_SCHED_SCAN_STOPPED) {
2335 wpa_dbg(wpa_s, MSG_DEBUG,
2336 "Ignore event %s (%d) while interface is disabled",
2337 event_to_string(event), event);
2341 #ifndef CONFIG_NO_STDOUT_DEBUG
2343 int level = MSG_DEBUG;
2345 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2346 const struct ieee80211_hdr *hdr;
2348 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2349 fc = le_to_host16(hdr->frame_control);
2350 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2351 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2352 level = MSG_EXCESSIVE;
2355 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2356 event_to_string(event), event);
2358 #endif /* CONFIG_NO_STDOUT_DEBUG */
2362 sme_event_auth(wpa_s, data);
2365 wpa_supplicant_event_assoc(wpa_s, data);
2367 case EVENT_DISASSOC:
2368 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2370 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2371 data->disassoc_info.reason_code,
2372 data->disassoc_info.locally_generated ?
2373 " (locally generated)" : "");
2374 if (data->disassoc_info.addr)
2375 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2376 MAC2STR(data->disassoc_info.addr));
2379 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2380 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2381 data->disassoc_info.addr);
2384 if (wpa_s->ap_iface) {
2385 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2389 #endif /* CONFIG_AP */
2391 reason_code = data->disassoc_info.reason_code;
2393 data->disassoc_info.locally_generated;
2394 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2395 data->disassoc_info.ie,
2396 data->disassoc_info.ie_len);
2398 wpas_p2p_disassoc_notif(
2399 wpa_s, data->disassoc_info.addr, reason_code,
2400 data->disassoc_info.ie,
2401 data->disassoc_info.ie_len,
2403 #endif /* CONFIG_P2P */
2405 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2406 sme_event_disassoc(wpa_s, data);
2409 if (event == EVENT_DEAUTH) {
2410 wpa_dbg(wpa_s, MSG_DEBUG,
2411 "Deauthentication notification");
2413 reason_code = data->deauth_info.reason_code;
2415 data->deauth_info.locally_generated;
2416 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2417 data->deauth_info.reason_code,
2418 data->deauth_info.locally_generated ?
2419 " (locally generated)" : "");
2420 if (data->deauth_info.addr) {
2421 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2423 MAC2STR(data->deauth_info.
2426 wpa_hexdump(MSG_DEBUG,
2427 "Deauthentication frame IE(s)",
2428 data->deauth_info.ie,
2429 data->deauth_info.ie_len);
2433 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2434 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2435 data->deauth_info.addr);
2438 if (wpa_s->ap_iface) {
2439 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2443 #endif /* CONFIG_AP */
2444 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2446 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2447 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2448 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2449 eapol_sm_failed(wpa_s->eapol)))
2450 wpas_auth_failed(wpa_s);
2452 if (event == EVENT_DEAUTH && data) {
2453 if (wpas_p2p_deauth_notif(wpa_s,
2454 data->deauth_info.addr,
2456 data->deauth_info.ie,
2457 data->deauth_info.ie_len,
2458 locally_generated) > 0) {
2460 * The interface was removed, so cannot
2461 * continue processing any additional
2462 * operations after this.
2467 #endif /* CONFIG_P2P */
2468 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2471 case EVENT_MICHAEL_MIC_FAILURE:
2472 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2474 #ifndef CONFIG_NO_SCAN_PROCESSING
2475 case EVENT_SCAN_RESULTS:
2476 wpa_supplicant_event_scan_results(wpa_s, data);
2478 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2479 wpa_s->global->p2p != NULL &&
2480 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2481 wpa_s->wpa_state != WPA_ASSOCIATING) {
2482 wpa_s->global->p2p_cb_on_scan_complete = 0;
2483 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2484 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2485 "continued after scan result processing");
2488 #endif /* CONFIG_P2P */
2490 #endif /* CONFIG_NO_SCAN_PROCESSING */
2491 case EVENT_ASSOCINFO:
2492 wpa_supplicant_event_associnfo(wpa_s, data);
2494 case EVENT_INTERFACE_STATUS:
2495 wpa_supplicant_event_interface_status(wpa_s, data);
2497 case EVENT_PMKID_CANDIDATE:
2498 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2500 #ifdef CONFIG_PEERKEY
2501 case EVENT_STKSTART:
2502 wpa_supplicant_event_stkstart(wpa_s, data);
2504 #endif /* CONFIG_PEERKEY */
2507 wpa_supplicant_event_tdls(wpa_s, data);
2509 #endif /* CONFIG_TDLS */
2510 #ifdef CONFIG_IEEE80211V
2512 wpa_supplicant_event_wnm(wpa_s, data);
2514 #endif /* CONFIG_IEEE80211V */
2515 #ifdef CONFIG_IEEE80211R
2516 case EVENT_FT_RESPONSE:
2517 wpa_supplicant_event_ft_response(wpa_s, data);
2519 #endif /* CONFIG_IEEE80211R */
2520 #ifdef CONFIG_IBSS_RSN
2521 case EVENT_IBSS_RSN_START:
2522 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2524 #endif /* CONFIG_IBSS_RSN */
2525 case EVENT_ASSOC_REJECT:
2526 if (data->assoc_reject.bssid)
2527 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2528 "bssid=" MACSTR " status_code=%u",
2529 MAC2STR(data->assoc_reject.bssid),
2530 data->assoc_reject.status_code);
2532 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2534 data->assoc_reject.status_code);
2535 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2536 sme_event_assoc_reject(wpa_s, data);
2538 const u8 *bssid = data->assoc_reject.bssid;
2539 if (bssid == NULL || is_zero_ether_addr(bssid))
2540 bssid = wpa_s->pending_bssid;
2541 wpas_connection_failed(wpa_s, bssid);
2542 wpa_supplicant_mark_disassoc(wpa_s);
2545 case EVENT_AUTH_TIMED_OUT:
2546 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2547 sme_event_auth_timed_out(wpa_s, data);
2549 case EVENT_ASSOC_TIMED_OUT:
2550 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2551 sme_event_assoc_timed_out(wpa_s, data);
2553 case EVENT_TX_STATUS:
2554 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2555 " type=%d stype=%d",
2556 MAC2STR(data->tx_status.dst),
2557 data->tx_status.type, data->tx_status.stype);
2559 if (wpa_s->ap_iface == NULL) {
2560 #ifdef CONFIG_OFFCHANNEL
2561 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2562 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2563 offchannel_send_action_tx_status(
2564 wpa_s, data->tx_status.dst,
2565 data->tx_status.data,
2566 data->tx_status.data_len,
2567 data->tx_status.ack ?
2568 OFFCHANNEL_SEND_ACTION_SUCCESS :
2569 OFFCHANNEL_SEND_ACTION_NO_ACK);
2570 #endif /* CONFIG_OFFCHANNEL */
2573 #endif /* CONFIG_AP */
2574 #ifdef CONFIG_OFFCHANNEL
2575 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2576 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2578 * Catch TX status events for Action frames we sent via group
2579 * interface in GO mode.
2581 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2582 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2583 os_memcmp(wpa_s->parent->pending_action_dst,
2584 data->tx_status.dst, ETH_ALEN) == 0) {
2585 offchannel_send_action_tx_status(
2586 wpa_s->parent, data->tx_status.dst,
2587 data->tx_status.data,
2588 data->tx_status.data_len,
2589 data->tx_status.ack ?
2590 OFFCHANNEL_SEND_ACTION_SUCCESS :
2591 OFFCHANNEL_SEND_ACTION_NO_ACK);
2594 #endif /* CONFIG_OFFCHANNEL */
2596 switch (data->tx_status.type) {
2597 case WLAN_FC_TYPE_MGMT:
2598 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2599 data->tx_status.data_len,
2600 data->tx_status.stype,
2601 data->tx_status.ack);
2603 case WLAN_FC_TYPE_DATA:
2604 ap_tx_status(wpa_s, data->tx_status.dst,
2605 data->tx_status.data,
2606 data->tx_status.data_len,
2607 data->tx_status.ack);
2610 #endif /* CONFIG_AP */
2613 case EVENT_EAPOL_TX_STATUS:
2614 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2615 data->eapol_tx_status.data,
2616 data->eapol_tx_status.data_len,
2617 data->eapol_tx_status.ack);
2619 case EVENT_DRIVER_CLIENT_POLL_OK:
2620 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2622 case EVENT_RX_FROM_UNKNOWN:
2623 if (wpa_s->ap_iface == NULL)
2625 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2626 data->rx_from_unknown.wds);
2628 case EVENT_CH_SWITCH:
2631 if (!wpa_s->ap_iface) {
2632 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2633 "event in non-AP mode");
2638 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2639 data->ch_switch.ht_enabled,
2640 data->ch_switch.ch_offset);
2641 #endif /* CONFIG_AP */
2643 case EVENT_RX_MGMT: {
2645 const struct ieee80211_mgmt *mgmt;
2647 mgmt = (const struct ieee80211_mgmt *)
2648 data->rx_mgmt.frame;
2649 fc = le_to_host16(mgmt->frame_control);
2650 stype = WLAN_FC_GET_STYPE(fc);
2652 if (wpa_s->ap_iface == NULL) {
2654 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2655 data->rx_mgmt.frame_len > 24) {
2656 const u8 *src = mgmt->sa;
2657 const u8 *ie = mgmt->u.probe_req.variable;
2658 size_t ie_len = data->rx_mgmt.frame_len -
2659 (mgmt->u.probe_req.variable -
2660 data->rx_mgmt.frame);
2661 wpas_p2p_probe_req_rx(
2662 wpa_s, src, mgmt->da,
2663 mgmt->bssid, ie, ie_len,
2664 data->rx_mgmt.ssi_signal);
2667 #endif /* CONFIG_P2P */
2668 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2669 "management frame in non-AP mode");
2673 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2674 data->rx_mgmt.frame_len > 24) {
2675 const u8 *ie = mgmt->u.probe_req.variable;
2676 size_t ie_len = data->rx_mgmt.frame_len -
2677 (mgmt->u.probe_req.variable -
2678 data->rx_mgmt.frame);
2680 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2681 mgmt->bssid, ie, ie_len,
2682 data->rx_mgmt.ssi_signal);
2685 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2688 #endif /* CONFIG_AP */
2689 case EVENT_RX_ACTION:
2690 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2691 " Category=%u DataLen=%d freq=%d MHz",
2692 MAC2STR(data->rx_action.sa),
2693 data->rx_action.category, (int) data->rx_action.len,
2694 data->rx_action.freq);
2695 #ifdef CONFIG_IEEE80211R
2696 if (data->rx_action.category == WLAN_ACTION_FT) {
2697 ft_rx_action(wpa_s, data->rx_action.data,
2698 data->rx_action.len);
2701 #endif /* CONFIG_IEEE80211R */
2702 #ifdef CONFIG_IEEE80211W
2704 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2705 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2706 data->rx_action.data,
2707 data->rx_action.len);
2710 #endif /* CONFIG_SME */
2711 #endif /* CONFIG_IEEE80211W */
2712 #ifdef CONFIG_IEEE80211V
2713 if (data->rx_action.category == WLAN_ACTION_WNM) {
2714 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2717 #endif /* CONFIG_IEEE80211V */
2719 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2720 gas_query_rx(wpa_s->gas, data->rx_action.da,
2721 data->rx_action.sa, data->rx_action.bssid,
2722 data->rx_action.data, data->rx_action.len,
2723 data->rx_action.freq) == 0)
2725 #endif /* CONFIG_GAS */
2726 if (data->rx_action.category == WLAN_ACTION_WNM) {
2727 wnm_action_rx(wpa_s, &data->rx_action);
2731 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2732 data->rx_action.len >= 4 &&
2733 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2734 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2735 "Response from " MACSTR,
2736 MAC2STR(data->rx_action.sa));
2739 #endif /* CONFIG_TDLS */
2741 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2743 data->rx_action.bssid,
2744 data->rx_action.category,
2745 data->rx_action.data,
2746 data->rx_action.len, data->rx_action.freq);
2747 #endif /* CONFIG_P2P */
2749 case EVENT_RX_PROBE_REQ:
2750 if (data->rx_probe_req.sa == NULL ||
2751 data->rx_probe_req.ie == NULL)
2754 if (wpa_s->ap_iface) {
2755 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2756 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);
2764 #endif /* CONFIG_AP */
2766 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2767 data->rx_probe_req.da,
2768 data->rx_probe_req.bssid,
2769 data->rx_probe_req.ie,
2770 data->rx_probe_req.ie_len,
2771 data->rx_probe_req.ssi_signal);
2772 #endif /* CONFIG_P2P */
2774 case EVENT_REMAIN_ON_CHANNEL:
2775 #ifdef CONFIG_OFFCHANNEL
2776 offchannel_remain_on_channel_cb(
2777 wpa_s, data->remain_on_channel.freq,
2778 data->remain_on_channel.duration);
2779 #endif /* CONFIG_OFFCHANNEL */
2781 wpas_p2p_remain_on_channel_cb(
2782 wpa_s, data->remain_on_channel.freq,
2783 data->remain_on_channel.duration);
2784 #endif /* CONFIG_P2P */
2786 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2787 #ifdef CONFIG_OFFCHANNEL
2788 offchannel_cancel_remain_on_channel_cb(
2789 wpa_s, data->remain_on_channel.freq);
2790 #endif /* CONFIG_OFFCHANNEL */
2792 wpas_p2p_cancel_remain_on_channel_cb(
2793 wpa_s, data->remain_on_channel.freq);
2794 #endif /* CONFIG_P2P */
2797 case EVENT_P2P_DEV_FOUND: {
2798 struct p2p_peer_info peer_info;
2800 os_memset(&peer_info, 0, sizeof(peer_info));
2801 if (data->p2p_dev_found.dev_addr)
2802 os_memcpy(peer_info.p2p_device_addr,
2803 data->p2p_dev_found.dev_addr, ETH_ALEN);
2804 if (data->p2p_dev_found.pri_dev_type)
2805 os_memcpy(peer_info.pri_dev_type,
2806 data->p2p_dev_found.pri_dev_type,
2807 sizeof(peer_info.pri_dev_type));
2808 if (data->p2p_dev_found.dev_name)
2809 os_strlcpy(peer_info.device_name,
2810 data->p2p_dev_found.dev_name,
2811 sizeof(peer_info.device_name));
2812 peer_info.config_methods = data->p2p_dev_found.config_methods;
2813 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2814 peer_info.group_capab = data->p2p_dev_found.group_capab;
2817 * FIX: new_device=1 is not necessarily correct. We should
2818 * maintain a P2P peer database in wpa_supplicant and update
2819 * this information based on whether the peer is truly new.
2821 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2824 case EVENT_P2P_GO_NEG_REQ_RX:
2825 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2826 data->p2p_go_neg_req_rx.dev_passwd_id);
2828 case EVENT_P2P_GO_NEG_COMPLETED:
2829 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2831 case EVENT_P2P_PROV_DISC_REQUEST:
2832 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2833 data->p2p_prov_disc_req.config_methods,
2834 data->p2p_prov_disc_req.dev_addr,
2835 data->p2p_prov_disc_req.pri_dev_type,
2836 data->p2p_prov_disc_req.dev_name,
2837 data->p2p_prov_disc_req.supp_config_methods,
2838 data->p2p_prov_disc_req.dev_capab,
2839 data->p2p_prov_disc_req.group_capab,
2842 case EVENT_P2P_PROV_DISC_RESPONSE:
2843 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2844 data->p2p_prov_disc_resp.config_methods);
2846 case EVENT_P2P_SD_REQUEST:
2847 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2848 data->p2p_sd_req.sa,
2849 data->p2p_sd_req.dialog_token,
2850 data->p2p_sd_req.update_indic,
2851 data->p2p_sd_req.tlvs,
2852 data->p2p_sd_req.tlvs_len);
2854 case EVENT_P2P_SD_RESPONSE:
2855 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2856 data->p2p_sd_resp.update_indic,
2857 data->p2p_sd_resp.tlvs,
2858 data->p2p_sd_resp.tlvs_len);
2860 #endif /* CONFIG_P2P */
2861 case EVENT_EAPOL_RX:
2862 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2863 data->eapol_rx.data,
2864 data->eapol_rx.data_len);
2866 case EVENT_SIGNAL_CHANGE:
2867 bgscan_notify_signal_change(
2868 wpa_s, data->signal_change.above_threshold,
2869 data->signal_change.current_signal,
2870 data->signal_change.current_noise,
2871 data->signal_change.current_txrate);
2873 case EVENT_INTERFACE_ENABLED:
2874 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2875 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2876 wpa_supplicant_update_mac_addr(wpa_s);
2878 if (!wpa_s->ap_iface) {
2879 wpa_supplicant_set_state(wpa_s,
2881 wpa_supplicant_req_scan(wpa_s, 0, 0);
2883 wpa_supplicant_set_state(wpa_s,
2885 #else /* CONFIG_AP */
2886 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2887 wpa_supplicant_req_scan(wpa_s, 0, 0);
2888 #endif /* CONFIG_AP */
2891 case EVENT_INTERFACE_DISABLED:
2892 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2893 wpa_supplicant_mark_disassoc(wpa_s);
2894 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2896 case EVENT_CHANNEL_LIST_CHANGED:
2897 if (wpa_s->drv_priv == NULL)
2898 break; /* Ignore event during drv initialization */
2900 free_hw_features(wpa_s);
2901 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2902 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2905 wpas_p2p_update_channel_list(wpa_s);
2906 #endif /* CONFIG_P2P */
2908 case EVENT_INTERFACE_UNAVAILABLE:
2910 wpas_p2p_interface_unavailable(wpa_s);
2911 #endif /* CONFIG_P2P */
2913 case EVENT_BEST_CHANNEL:
2914 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2916 data->best_chan.freq_24, data->best_chan.freq_5,
2917 data->best_chan.freq_overall);
2918 wpa_s->best_24_freq = data->best_chan.freq_24;
2919 wpa_s->best_5_freq = data->best_chan.freq_5;
2920 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2922 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2923 data->best_chan.freq_5,
2924 data->best_chan.freq_overall);
2925 #endif /* CONFIG_P2P */
2927 case EVENT_UNPROT_DEAUTH:
2928 wpa_supplicant_event_unprot_deauth(wpa_s,
2929 &data->unprot_deauth);
2931 case EVENT_UNPROT_DISASSOC:
2932 wpa_supplicant_event_unprot_disassoc(wpa_s,
2933 &data->unprot_disassoc);
2935 case EVENT_STATION_LOW_ACK:
2937 if (wpa_s->ap_iface && data)
2938 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2939 data->low_ack.addr);
2940 #endif /* CONFIG_AP */
2943 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2944 #endif /* CONFIG_TDLS */
2946 case EVENT_IBSS_PEER_LOST:
2947 #ifdef CONFIG_IBSS_RSN
2948 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2949 #endif /* CONFIG_IBSS_RSN */
2951 case EVENT_DRIVER_GTK_REKEY:
2952 if (os_memcmp(data->driver_gtk_rekey.bssid,
2953 wpa_s->bssid, ETH_ALEN))
2957 wpa_sm_update_replay_ctr(wpa_s->wpa,
2958 data->driver_gtk_rekey.replay_ctr);
2960 case EVENT_SCHED_SCAN_STOPPED:
2961 wpa_s->sched_scanning = 0;
2962 wpa_supplicant_notify_scanning(wpa_s, 0);
2964 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2968 * If we timed out, start a new sched scan to continue
2969 * searching for more SSIDs.
2971 if (wpa_s->sched_scan_timed_out)
2972 wpa_supplicant_req_sched_scan(wpa_s);
2974 case EVENT_WPS_BUTTON_PUSHED:
2976 wpas_wps_start_pbc(wpa_s, NULL, 0);
2977 #endif /* CONFIG_WPS */
2980 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);