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 if (!wpa_s->no_keep_alive) {
1320 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1321 MAC2STR(wpa_s->bssid));
1322 /* TODO: could skip this if normal data traffic has been sent */
1323 /* TODO: Consider using some more appropriate data frame for
1326 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1331 if (wpa_s->sme.bss_max_idle_period) {
1333 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1336 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1337 wnm_bss_keep_alive, wpa_s, NULL);
1339 #endif /* CONFIG_SME */
1343 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1344 const u8 *ies, size_t ies_len)
1346 struct ieee802_11_elems elems;
1351 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1355 if (elems.bss_max_idle_period) {
1357 wpa_s->sme.bss_max_idle_period =
1358 WPA_GET_LE16(elems.bss_max_idle_period);
1359 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1360 "TU)%s", wpa_s->sme.bss_max_idle_period,
1361 (elems.bss_max_idle_period[2] & 0x01) ?
1362 " (protected keep-live required)" : "");
1363 if (wpa_s->sme.bss_max_idle_period == 0)
1364 wpa_s->sme.bss_max_idle_period = 1;
1365 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1366 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1367 /* msec times 1000 */
1368 msec = wpa_s->sme.bss_max_idle_period * 1024;
1371 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1372 wnm_bss_keep_alive, wpa_s,
1376 #endif /* CONFIG_SME */
1379 #endif /* CONFIG_WNM */
1382 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1385 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1386 #endif /* CONFIG_WNM */
1390 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1391 union wpa_event_data *data)
1393 int l, len, found = 0, wpa_found, rsn_found;
1396 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1397 if (data->assoc_info.req_ies)
1398 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1399 data->assoc_info.req_ies_len);
1400 if (data->assoc_info.resp_ies) {
1401 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1402 data->assoc_info.resp_ies_len);
1404 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1405 data->assoc_info.resp_ies_len);
1406 #endif /* CONFIG_TDLS */
1408 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1409 data->assoc_info.resp_ies_len);
1410 #endif /* CONFIG_WNM */
1412 if (data->assoc_info.beacon_ies)
1413 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1414 data->assoc_info.beacon_ies,
1415 data->assoc_info.beacon_ies_len);
1416 if (data->assoc_info.freq)
1417 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1418 data->assoc_info.freq);
1420 p = data->assoc_info.req_ies;
1421 l = data->assoc_info.req_ies_len;
1423 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1424 while (p && l >= 2) {
1427 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1431 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1432 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1433 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1434 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1437 wpa_find_assoc_pmkid(wpa_s);
1443 if (!found && data->assoc_info.req_ies)
1444 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1446 #ifdef CONFIG_IEEE80211R
1448 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1450 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1451 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1452 data->assoc_info.resp_ies,
1453 data->assoc_info.resp_ies_len,
1455 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1456 "Reassociation Response failed");
1457 wpa_supplicant_deauthenticate(
1458 wpa_s, WLAN_REASON_INVALID_IE);
1463 p = data->assoc_info.resp_ies;
1464 l = data->assoc_info.resp_ies_len;
1466 #ifdef CONFIG_WPS_STRICT
1467 if (p && wpa_s->current_ssid &&
1468 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1470 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1472 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1473 "include WPS IE in (Re)Association Response");
1477 if (wps_validate_assoc_resp(wps) < 0) {
1479 wpa_supplicant_deauthenticate(
1480 wpa_s, WLAN_REASON_INVALID_IE);
1485 #endif /* CONFIG_WPS_STRICT */
1487 /* Go through the IEs and make a copy of the MDIE, if present. */
1488 while (p && l >= 2) {
1491 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1495 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1496 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1497 wpa_s->sme.ft_used = 1;
1498 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1499 MOBILITY_DOMAIN_ID_LEN);
1505 #endif /* CONFIG_SME */
1507 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1508 data->assoc_info.resp_ies_len);
1509 #endif /* CONFIG_IEEE80211R */
1511 /* WPA/RSN IE from Beacon/ProbeResp */
1512 p = data->assoc_info.beacon_ies;
1513 l = data->assoc_info.beacon_ies_len;
1515 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1517 wpa_found = rsn_found = 0;
1518 while (p && l >= 2) {
1521 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1526 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1527 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1529 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1533 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1535 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1542 if (!wpa_found && data->assoc_info.beacon_ies)
1543 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1544 if (!rsn_found && data->assoc_info.beacon_ies)
1545 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1546 if (wpa_found || rsn_found)
1547 wpa_s->ap_ies_from_associnfo = 1;
1549 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1550 wpa_s->assoc_freq != data->assoc_info.freq) {
1551 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1553 wpa_s->assoc_freq, data->assoc_info.freq);
1554 wpa_supplicant_update_scan_results(wpa_s);
1557 wpa_s->assoc_freq = data->assoc_info.freq;
1563 static struct wpa_bss * wpa_supplicant_get_new_bss(
1564 struct wpa_supplicant *wpa_s, const u8 *bssid)
1566 struct wpa_bss *bss = NULL;
1567 struct wpa_ssid *ssid = wpa_s->current_ssid;
1569 if (ssid->ssid_len > 0)
1570 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1572 bss = wpa_bss_get_bssid(wpa_s, bssid);
1578 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1580 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1582 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1585 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1588 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1589 WPA_IE_VENDOR_TYPE);
1590 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1592 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1593 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1594 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1595 bss_rsn ? 2 + bss_rsn[1] : 0))
1602 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1603 union wpa_event_data *data)
1607 struct wpa_driver_capa capa;
1610 if (wpa_s->ap_iface) {
1611 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1612 data->assoc_info.addr,
1613 data->assoc_info.req_ies,
1614 data->assoc_info.req_ies_len,
1615 data->assoc_info.reassoc);
1618 #endif /* CONFIG_AP */
1620 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1621 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1624 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1625 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1626 wpa_supplicant_deauthenticate(
1627 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1631 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1632 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1633 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1634 MACSTR, MAC2STR(bssid));
1635 random_add_randomness(bssid, ETH_ALEN);
1636 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1637 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1638 wpas_notify_bssid_changed(wpa_s);
1640 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1641 wpa_clear_keys(wpa_s, bssid);
1643 if (wpa_supplicant_select_config(wpa_s) < 0) {
1644 wpa_supplicant_deauthenticate(
1645 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1648 if (wpa_s->current_ssid) {
1649 struct wpa_bss *bss = NULL;
1651 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1653 wpa_supplicant_update_scan_results(wpa_s);
1655 /* Get the BSS from the new scan results */
1656 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1660 wpa_s->current_bss = bss;
1663 if (wpa_s->conf->ap_scan == 1 &&
1664 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1665 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1666 wpa_msg(wpa_s, MSG_WARNING,
1667 "WPA/RSN IEs not updated");
1672 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1673 wpa_s->sme.prev_bssid_set = 1;
1674 #endif /* CONFIG_SME */
1676 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1677 if (wpa_s->current_ssid) {
1678 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1679 * initialized before association, but for other modes,
1680 * initialize PC/SC here, if the current configuration needs
1681 * smartcard or SIM/USIM. */
1682 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1684 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1686 l2_packet_notify_auth_start(wpa_s->l2);
1689 * Set portEnabled first to FALSE in order to get EAP state machine out
1690 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1691 * state machine may transit to AUTHENTICATING state based on obsolete
1692 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1693 * AUTHENTICATED without ever giving chance to EAP state machine to
1696 if (!ft_completed) {
1697 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1698 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1700 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1701 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1702 /* 802.1X::portControl = Auto */
1703 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1704 wpa_s->eapol_received = 0;
1705 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1706 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1707 (wpa_s->current_ssid &&
1708 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1709 wpa_supplicant_cancel_auth_timeout(wpa_s);
1710 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1711 } else if (!ft_completed) {
1712 /* Timeout for receiving the first EAPOL packet */
1713 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1715 wpa_supplicant_cancel_scan(wpa_s);
1717 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1718 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1720 * We are done; the driver will take care of RSN 4-way
1723 wpa_supplicant_cancel_auth_timeout(wpa_s);
1724 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1725 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1726 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1727 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1728 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1730 * The driver will take care of RSN 4-way handshake, so we need
1731 * to allow EAPOL supplicant to complete its work without
1732 * waiting for WPA supplicant.
1734 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1735 } else if (ft_completed) {
1737 * FT protocol completed - make sure EAPOL state machine ends
1738 * up in authenticated.
1740 wpa_supplicant_cancel_auth_timeout(wpa_s);
1741 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1742 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1743 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1746 wpa_s->last_eapol_matches_bssid = 0;
1748 if (wpa_s->pending_eapol_rx) {
1749 struct os_time now, age;
1751 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1752 if (age.sec == 0 && age.usec < 100000 &&
1753 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1755 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1756 "frame that was received just before "
1757 "association notification");
1758 wpa_supplicant_rx_eapol(
1759 wpa_s, wpa_s->pending_eapol_rx_src,
1760 wpabuf_head(wpa_s->pending_eapol_rx),
1761 wpabuf_len(wpa_s->pending_eapol_rx));
1763 wpabuf_free(wpa_s->pending_eapol_rx);
1764 wpa_s->pending_eapol_rx = NULL;
1767 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1768 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1769 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1770 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1771 /* Set static WEP keys again */
1772 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1775 #ifdef CONFIG_IBSS_RSN
1776 if (wpa_s->current_ssid &&
1777 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1778 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1779 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1780 wpa_s->ibss_rsn == NULL) {
1781 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1782 if (!wpa_s->ibss_rsn) {
1783 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1784 wpa_supplicant_deauthenticate(
1785 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1789 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1791 #endif /* CONFIG_IBSS_RSN */
1793 wpas_wps_notify_assoc(wpa_s, bssid);
1797 static int disconnect_reason_recoverable(u16 reason_code)
1799 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1800 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1801 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1805 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1807 int locally_generated)
1811 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1813 * At least Host AP driver and a Prism3 card seemed to be
1814 * generating streams of disconnected events when configuring
1815 * IBSS for WPA-None. Ignore them for now.
1820 bssid = wpa_s->bssid;
1821 if (is_zero_ether_addr(bssid))
1822 bssid = wpa_s->pending_bssid;
1824 if (!is_zero_ether_addr(bssid) ||
1825 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1826 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1828 MAC2STR(bssid), reason_code,
1829 locally_generated ? " locally_generated=1" : "");
1834 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1835 int locally_generated)
1837 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1838 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1839 return 0; /* Not in 4-way handshake with PSK */
1842 * It looks like connection was lost while trying to go through PSK
1843 * 4-way handshake. Filter out known disconnection cases that are caused
1844 * by something else than PSK mismatch to avoid confusing reports.
1847 if (locally_generated) {
1848 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1856 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1858 int locally_generated)
1862 u8 prev_pending_bssid[ETH_ALEN];
1863 struct wpa_bss *fast_reconnect = NULL;
1864 struct wpa_ssid *fast_reconnect_ssid = NULL;
1865 struct wpa_ssid *last_ssid;
1867 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1868 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1870 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1872 * At least Host AP driver and a Prism3 card seemed to be
1873 * generating streams of disconnected events when configuring
1874 * IBSS for WPA-None. Ignore them for now.
1876 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1877 "IBSS/WPA-None mode");
1881 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1882 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1883 "pre-shared key may be incorrect");
1884 wpas_auth_failed(wpa_s);
1886 if (!wpa_s->auto_reconnect_disabled ||
1887 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1888 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1889 "reconnect (wps=%d wpa_state=%d)",
1890 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1892 if (wpa_s->wpa_state == WPA_COMPLETED &&
1893 wpa_s->current_ssid &&
1894 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1895 !locally_generated &&
1896 disconnect_reason_recoverable(reason_code)) {
1898 * It looks like the AP has dropped association with
1899 * us, but could allow us to get back in. Try to
1900 * reconnect to the same BSS without full scan to save
1901 * time for some common cases.
1903 fast_reconnect = wpa_s->current_bss;
1904 fast_reconnect_ssid = wpa_s->current_ssid;
1905 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1906 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1908 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1911 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1912 "try to re-connect");
1913 wpa_s->reassociate = 0;
1914 wpa_s->disconnected = 1;
1915 wpa_supplicant_cancel_sched_scan(wpa_s);
1917 bssid = wpa_s->bssid;
1918 if (is_zero_ether_addr(bssid))
1919 bssid = wpa_s->pending_bssid;
1920 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1921 wpas_connection_failed(wpa_s, bssid);
1922 wpa_sm_notify_disassoc(wpa_s->wpa);
1923 if (locally_generated)
1924 wpa_s->disconnect_reason = -reason_code;
1926 wpa_s->disconnect_reason = reason_code;
1927 wpas_notify_disconnect_reason(wpa_s);
1928 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1929 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1930 wpa_s->keys_cleared = 0;
1931 wpa_clear_keys(wpa_s, wpa_s->bssid);
1933 last_ssid = wpa_s->current_ssid;
1934 wpa_supplicant_mark_disassoc(wpa_s);
1936 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1937 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1938 wpa_s->current_ssid = last_ssid;
1941 if (fast_reconnect) {
1942 #ifndef CONFIG_NO_SCAN_PROCESSING
1943 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1944 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1945 fast_reconnect_ssid) < 0) {
1946 /* Recover through full scan */
1947 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1949 #endif /* CONFIG_NO_SCAN_PROCESSING */
1954 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1955 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1957 struct wpa_supplicant *wpa_s = eloop_ctx;
1959 if (!wpa_s->pending_mic_error_report)
1962 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1963 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1964 wpa_s->pending_mic_error_report = 0;
1966 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1970 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1971 union wpa_event_data *data)
1976 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1977 pairwise = (data && data->michael_mic_failure.unicast);
1979 if ((wpa_s->last_michael_mic_error &&
1980 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1981 wpa_s->pending_mic_error_report) {
1982 if (wpa_s->pending_mic_error_report) {
1984 * Send the pending MIC error report immediately since
1985 * we are going to start countermeasures and AP better
1988 wpa_sm_key_request(wpa_s->wpa, 1,
1989 wpa_s->pending_mic_error_pairwise);
1992 /* Send the new MIC error report immediately since we are going
1993 * to start countermeasures and AP better do the same.
1995 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1997 /* initialize countermeasures */
1998 wpa_s->countermeasures = 1;
2000 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2002 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2005 * Need to wait for completion of request frame. We do not get
2006 * any callback for the message completion, so just wait a
2007 * short while and hope for the best. */
2010 wpa_drv_set_countermeasures(wpa_s, 1);
2011 wpa_supplicant_deauthenticate(wpa_s,
2012 WLAN_REASON_MICHAEL_MIC_FAILURE);
2013 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2015 eloop_register_timeout(60, 0,
2016 wpa_supplicant_stop_countermeasures,
2018 /* TODO: mark the AP rejected for 60 second. STA is
2019 * allowed to associate with another AP.. */
2021 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2022 if (wpa_s->mic_errors_seen) {
2024 * Reduce the effectiveness of Michael MIC error
2025 * reports as a means for attacking against TKIP if
2026 * more than one MIC failure is noticed with the same
2027 * PTK. We delay the transmission of the reports by a
2028 * random time between 0 and 60 seconds in order to
2029 * force the attacker wait 60 seconds before getting
2030 * the information on whether a frame resulted in a MIC
2036 if (os_get_random(rval, sizeof(rval)) < 0)
2037 sec = os_random() % 60;
2039 sec = WPA_GET_BE32(rval) % 60;
2040 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2041 "report %d seconds", sec);
2042 wpa_s->pending_mic_error_report = 1;
2043 wpa_s->pending_mic_error_pairwise = pairwise;
2044 eloop_cancel_timeout(
2045 wpa_supplicant_delayed_mic_error_report,
2047 eloop_register_timeout(
2048 sec, os_random() % 1000000,
2049 wpa_supplicant_delayed_mic_error_report,
2052 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2054 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2055 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2056 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2058 wpa_s->last_michael_mic_error = t.sec;
2059 wpa_s->mic_errors_seen++;
2063 #ifdef CONFIG_TERMINATE_ONLASTIF
2064 static int any_interfaces(struct wpa_supplicant *head)
2066 struct wpa_supplicant *wpa_s;
2068 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2069 if (!wpa_s->interface_removed)
2073 #endif /* CONFIG_TERMINATE_ONLASTIF */
2077 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2078 union wpa_event_data *data)
2080 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2083 switch (data->interface_status.ievent) {
2084 case EVENT_INTERFACE_ADDED:
2085 if (!wpa_s->interface_removed)
2087 wpa_s->interface_removed = 0;
2088 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2089 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2090 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2091 "driver after interface was added");
2093 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2095 case EVENT_INTERFACE_REMOVED:
2096 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2097 wpa_s->interface_removed = 1;
2098 wpa_supplicant_mark_disassoc(wpa_s);
2099 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2100 l2_packet_deinit(wpa_s->l2);
2102 #ifdef CONFIG_IBSS_RSN
2103 ibss_rsn_deinit(wpa_s->ibss_rsn);
2104 wpa_s->ibss_rsn = NULL;
2105 #endif /* CONFIG_IBSS_RSN */
2106 #ifdef CONFIG_TERMINATE_ONLASTIF
2107 /* check if last interface */
2108 if (!any_interfaces(wpa_s->global->ifaces))
2110 #endif /* CONFIG_TERMINATE_ONLASTIF */
2116 #ifdef CONFIG_PEERKEY
2118 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2119 union wpa_event_data *data)
2123 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2125 #endif /* CONFIG_PEERKEY */
2129 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2130 union wpa_event_data *data)
2134 switch (data->tdls.oper) {
2135 case TDLS_REQUEST_SETUP:
2136 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2138 case TDLS_REQUEST_TEARDOWN:
2139 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2140 data->tdls.reason_code);
2144 #endif /* CONFIG_TDLS */
2148 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2149 union wpa_event_data *data)
2153 switch (data->wnm.oper) {
2154 case WNM_OPER_SLEEP:
2155 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2156 "(action=%d, intval=%d)",
2157 data->wnm.sleep_action, data->wnm.sleep_intval);
2158 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2159 data->wnm.sleep_intval, NULL);
2163 #endif /* CONFIG_WNM */
2166 #ifdef CONFIG_IEEE80211R
2168 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2169 union wpa_event_data *data)
2174 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2175 data->ft_ies.ies_len,
2176 data->ft_ies.ft_action,
2177 data->ft_ies.target_ap,
2178 data->ft_ies.ric_ies,
2179 data->ft_ies.ric_ies_len) < 0) {
2180 /* TODO: prevent MLME/driver from trying to associate? */
2183 #endif /* CONFIG_IEEE80211R */
2186 #ifdef CONFIG_IBSS_RSN
2187 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2188 union wpa_event_data *data)
2190 struct wpa_ssid *ssid;
2191 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2195 ssid = wpa_s->current_ssid;
2198 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2201 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2203 #endif /* CONFIG_IBSS_RSN */
2206 #ifdef CONFIG_IEEE80211R
2207 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2210 const u8 *sta_addr, *target_ap_addr;
2213 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2214 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2215 return; /* only SME case supported for now */
2216 if (len < 1 + 2 * ETH_ALEN + 2)
2219 return; /* Only FT Action Response is supported for now */
2220 sta_addr = data + 1;
2221 target_ap_addr = data + 1 + ETH_ALEN;
2222 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2223 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2224 MACSTR " TargetAP " MACSTR " status %u",
2225 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2227 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2228 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2229 " in FT Action Response", MAC2STR(sta_addr));
2234 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2235 "failure (status code %d)", status);
2236 /* TODO: report error to FT code(?) */
2240 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2241 len - (1 + 2 * ETH_ALEN + 2), 1,
2242 target_ap_addr, NULL, 0) < 0)
2247 struct wpa_bss *bss;
2248 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2250 wpa_s->sme.freq = bss->freq;
2251 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2252 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2255 #endif /* CONFIG_SME */
2257 #endif /* CONFIG_IEEE80211R */
2260 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2261 struct unprot_deauth *e)
2263 #ifdef CONFIG_IEEE80211W
2264 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2265 "dropped: " MACSTR " -> " MACSTR
2266 " (reason code %u)",
2267 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2268 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2269 #endif /* CONFIG_IEEE80211W */
2273 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2274 struct unprot_disassoc *e)
2276 #ifdef CONFIG_IEEE80211W
2277 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2278 "dropped: " MACSTR " -> " MACSTR
2279 " (reason code %u)",
2280 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2281 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2282 #endif /* CONFIG_IEEE80211W */
2286 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2287 union wpa_event_data *data)
2289 struct wpa_supplicant *wpa_s = ctx;
2290 u16 reason_code = 0;
2291 int locally_generated = 0;
2293 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2294 event != EVENT_INTERFACE_ENABLED &&
2295 event != EVENT_INTERFACE_STATUS &&
2296 event != EVENT_SCHED_SCAN_STOPPED) {
2297 wpa_dbg(wpa_s, MSG_DEBUG,
2298 "Ignore event %s (%d) while interface is disabled",
2299 event_to_string(event), event);
2303 #ifndef CONFIG_NO_STDOUT_DEBUG
2305 int level = MSG_DEBUG;
2307 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2308 const struct ieee80211_hdr *hdr;
2310 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2311 fc = le_to_host16(hdr->frame_control);
2312 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2313 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2314 level = MSG_EXCESSIVE;
2317 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2318 event_to_string(event), event);
2320 #endif /* CONFIG_NO_STDOUT_DEBUG */
2324 sme_event_auth(wpa_s, data);
2327 wpa_supplicant_event_assoc(wpa_s, data);
2329 case EVENT_DISASSOC:
2330 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2332 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2333 data->disassoc_info.reason_code,
2334 data->disassoc_info.locally_generated ?
2335 " (locally generated)" : "");
2336 if (data->disassoc_info.addr)
2337 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2338 MAC2STR(data->disassoc_info.addr));
2341 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2342 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2343 data->disassoc_info.addr);
2346 if (wpa_s->ap_iface) {
2347 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2351 #endif /* CONFIG_AP */
2353 reason_code = data->disassoc_info.reason_code;
2355 data->disassoc_info.locally_generated;
2356 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2357 data->disassoc_info.ie,
2358 data->disassoc_info.ie_len);
2360 wpas_p2p_disassoc_notif(
2361 wpa_s, data->disassoc_info.addr, reason_code,
2362 data->disassoc_info.ie,
2363 data->disassoc_info.ie_len,
2365 #endif /* CONFIG_P2P */
2367 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2368 sme_event_disassoc(wpa_s, data);
2371 if (event == EVENT_DEAUTH) {
2372 wpa_dbg(wpa_s, MSG_DEBUG,
2373 "Deauthentication notification");
2375 reason_code = data->deauth_info.reason_code;
2377 data->deauth_info.locally_generated;
2378 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2379 data->deauth_info.reason_code,
2380 data->deauth_info.locally_generated ?
2381 " (locally generated)" : "");
2382 if (data->deauth_info.addr) {
2383 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2385 MAC2STR(data->deauth_info.
2388 wpa_hexdump(MSG_DEBUG,
2389 "Deauthentication frame IE(s)",
2390 data->deauth_info.ie,
2391 data->deauth_info.ie_len);
2395 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2396 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2397 data->deauth_info.addr);
2400 if (wpa_s->ap_iface) {
2401 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2405 #endif /* CONFIG_AP */
2406 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2408 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2409 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2410 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2411 eapol_sm_failed(wpa_s->eapol)))
2412 wpas_auth_failed(wpa_s);
2414 if (event == EVENT_DEAUTH && data) {
2415 if (wpas_p2p_deauth_notif(wpa_s,
2416 data->deauth_info.addr,
2418 data->deauth_info.ie,
2419 data->deauth_info.ie_len,
2420 locally_generated) > 0) {
2422 * The interface was removed, so cannot
2423 * continue processing any additional
2424 * operations after this.
2429 #endif /* CONFIG_P2P */
2430 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2433 case EVENT_MICHAEL_MIC_FAILURE:
2434 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2436 #ifndef CONFIG_NO_SCAN_PROCESSING
2437 case EVENT_SCAN_RESULTS:
2438 wpa_supplicant_event_scan_results(wpa_s, data);
2440 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2441 wpa_s->global->p2p != NULL &&
2442 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2443 wpa_s->wpa_state != WPA_ASSOCIATING) {
2444 wpa_s->global->p2p_cb_on_scan_complete = 0;
2445 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2446 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2447 "continued after scan result processing");
2450 #endif /* CONFIG_P2P */
2452 #endif /* CONFIG_NO_SCAN_PROCESSING */
2453 case EVENT_ASSOCINFO:
2454 wpa_supplicant_event_associnfo(wpa_s, data);
2456 case EVENT_INTERFACE_STATUS:
2457 wpa_supplicant_event_interface_status(wpa_s, data);
2459 case EVENT_PMKID_CANDIDATE:
2460 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2462 #ifdef CONFIG_PEERKEY
2463 case EVENT_STKSTART:
2464 wpa_supplicant_event_stkstart(wpa_s, data);
2466 #endif /* CONFIG_PEERKEY */
2469 wpa_supplicant_event_tdls(wpa_s, data);
2471 #endif /* CONFIG_TDLS */
2474 wpa_supplicant_event_wnm(wpa_s, data);
2476 #endif /* CONFIG_WNM */
2477 #ifdef CONFIG_IEEE80211R
2478 case EVENT_FT_RESPONSE:
2479 wpa_supplicant_event_ft_response(wpa_s, data);
2481 #endif /* CONFIG_IEEE80211R */
2482 #ifdef CONFIG_IBSS_RSN
2483 case EVENT_IBSS_RSN_START:
2484 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2486 #endif /* CONFIG_IBSS_RSN */
2487 case EVENT_ASSOC_REJECT:
2488 if (data->assoc_reject.bssid)
2489 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2490 "bssid=" MACSTR " status_code=%u",
2491 MAC2STR(data->assoc_reject.bssid),
2492 data->assoc_reject.status_code);
2494 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2496 data->assoc_reject.status_code);
2497 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2498 sme_event_assoc_reject(wpa_s, data);
2500 const u8 *bssid = data->assoc_reject.bssid;
2501 if (bssid == NULL || is_zero_ether_addr(bssid))
2502 bssid = wpa_s->pending_bssid;
2503 wpas_connection_failed(wpa_s, bssid);
2504 wpa_supplicant_mark_disassoc(wpa_s);
2507 case EVENT_AUTH_TIMED_OUT:
2508 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2509 sme_event_auth_timed_out(wpa_s, data);
2511 case EVENT_ASSOC_TIMED_OUT:
2512 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2513 sme_event_assoc_timed_out(wpa_s, data);
2515 case EVENT_TX_STATUS:
2516 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2517 " type=%d stype=%d",
2518 MAC2STR(data->tx_status.dst),
2519 data->tx_status.type, data->tx_status.stype);
2521 if (wpa_s->ap_iface == NULL) {
2522 #ifdef CONFIG_OFFCHANNEL
2523 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2524 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2525 offchannel_send_action_tx_status(
2526 wpa_s, data->tx_status.dst,
2527 data->tx_status.data,
2528 data->tx_status.data_len,
2529 data->tx_status.ack ?
2530 OFFCHANNEL_SEND_ACTION_SUCCESS :
2531 OFFCHANNEL_SEND_ACTION_NO_ACK);
2532 #endif /* CONFIG_OFFCHANNEL */
2535 #endif /* CONFIG_AP */
2536 #ifdef CONFIG_OFFCHANNEL
2537 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2538 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2540 * Catch TX status events for Action frames we sent via group
2541 * interface in GO mode.
2543 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2544 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2545 os_memcmp(wpa_s->parent->pending_action_dst,
2546 data->tx_status.dst, ETH_ALEN) == 0) {
2547 offchannel_send_action_tx_status(
2548 wpa_s->parent, data->tx_status.dst,
2549 data->tx_status.data,
2550 data->tx_status.data_len,
2551 data->tx_status.ack ?
2552 OFFCHANNEL_SEND_ACTION_SUCCESS :
2553 OFFCHANNEL_SEND_ACTION_NO_ACK);
2556 #endif /* CONFIG_OFFCHANNEL */
2558 switch (data->tx_status.type) {
2559 case WLAN_FC_TYPE_MGMT:
2560 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2561 data->tx_status.data_len,
2562 data->tx_status.stype,
2563 data->tx_status.ack);
2565 case WLAN_FC_TYPE_DATA:
2566 ap_tx_status(wpa_s, data->tx_status.dst,
2567 data->tx_status.data,
2568 data->tx_status.data_len,
2569 data->tx_status.ack);
2572 #endif /* CONFIG_AP */
2575 case EVENT_EAPOL_TX_STATUS:
2576 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2577 data->eapol_tx_status.data,
2578 data->eapol_tx_status.data_len,
2579 data->eapol_tx_status.ack);
2581 case EVENT_DRIVER_CLIENT_POLL_OK:
2582 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2584 case EVENT_RX_FROM_UNKNOWN:
2585 if (wpa_s->ap_iface == NULL)
2587 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2588 data->rx_from_unknown.wds);
2590 case EVENT_CH_SWITCH:
2593 if (!wpa_s->ap_iface) {
2594 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2595 "event in non-AP mode");
2600 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2601 data->ch_switch.ht_enabled,
2602 data->ch_switch.ch_offset);
2603 #endif /* CONFIG_AP */
2605 case EVENT_RX_MGMT: {
2607 const struct ieee80211_mgmt *mgmt;
2609 mgmt = (const struct ieee80211_mgmt *)
2610 data->rx_mgmt.frame;
2611 fc = le_to_host16(mgmt->frame_control);
2612 stype = WLAN_FC_GET_STYPE(fc);
2614 if (wpa_s->ap_iface == NULL) {
2616 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2617 data->rx_mgmt.frame_len > 24) {
2618 const u8 *src = mgmt->sa;
2619 const u8 *ie = mgmt->u.probe_req.variable;
2620 size_t ie_len = data->rx_mgmt.frame_len -
2621 (mgmt->u.probe_req.variable -
2622 data->rx_mgmt.frame);
2623 wpas_p2p_probe_req_rx(
2624 wpa_s, src, mgmt->da,
2625 mgmt->bssid, ie, ie_len,
2626 data->rx_mgmt.ssi_signal);
2629 #endif /* CONFIG_P2P */
2630 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2631 "management frame in non-AP mode");
2635 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2636 data->rx_mgmt.frame_len > 24) {
2637 const u8 *ie = mgmt->u.probe_req.variable;
2638 size_t ie_len = data->rx_mgmt.frame_len -
2639 (mgmt->u.probe_req.variable -
2640 data->rx_mgmt.frame);
2642 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2643 mgmt->bssid, ie, ie_len,
2644 data->rx_mgmt.ssi_signal);
2647 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2650 #endif /* CONFIG_AP */
2651 case EVENT_RX_ACTION:
2652 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2653 " Category=%u DataLen=%d freq=%d MHz",
2654 MAC2STR(data->rx_action.sa),
2655 data->rx_action.category, (int) data->rx_action.len,
2656 data->rx_action.freq);
2657 #ifdef CONFIG_IEEE80211R
2658 if (data->rx_action.category == WLAN_ACTION_FT) {
2659 ft_rx_action(wpa_s, data->rx_action.data,
2660 data->rx_action.len);
2663 #endif /* CONFIG_IEEE80211R */
2664 #ifdef CONFIG_IEEE80211W
2666 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2667 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2668 data->rx_action.data,
2669 data->rx_action.len);
2672 #endif /* CONFIG_SME */
2673 #endif /* CONFIG_IEEE80211W */
2675 if (data->rx_action.category == WLAN_ACTION_WNM) {
2676 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2679 #endif /* CONFIG_WNM */
2681 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2682 gas_query_rx(wpa_s->gas, data->rx_action.da,
2683 data->rx_action.sa, data->rx_action.bssid,
2684 data->rx_action.data, data->rx_action.len,
2685 data->rx_action.freq) == 0)
2687 #endif /* CONFIG_GAS */
2689 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2690 data->rx_action.len >= 4 &&
2691 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2692 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2693 "Response from " MACSTR,
2694 MAC2STR(data->rx_action.sa));
2697 #endif /* CONFIG_TDLS */
2699 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2701 data->rx_action.bssid,
2702 data->rx_action.category,
2703 data->rx_action.data,
2704 data->rx_action.len, data->rx_action.freq);
2705 #endif /* CONFIG_P2P */
2707 case EVENT_RX_PROBE_REQ:
2708 if (data->rx_probe_req.sa == NULL ||
2709 data->rx_probe_req.ie == NULL)
2712 if (wpa_s->ap_iface) {
2713 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2714 data->rx_probe_req.sa,
2715 data->rx_probe_req.da,
2716 data->rx_probe_req.bssid,
2717 data->rx_probe_req.ie,
2718 data->rx_probe_req.ie_len,
2719 data->rx_probe_req.ssi_signal);
2722 #endif /* CONFIG_AP */
2724 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2725 data->rx_probe_req.da,
2726 data->rx_probe_req.bssid,
2727 data->rx_probe_req.ie,
2728 data->rx_probe_req.ie_len,
2729 data->rx_probe_req.ssi_signal);
2730 #endif /* CONFIG_P2P */
2732 case EVENT_REMAIN_ON_CHANNEL:
2733 #ifdef CONFIG_OFFCHANNEL
2734 offchannel_remain_on_channel_cb(
2735 wpa_s, data->remain_on_channel.freq,
2736 data->remain_on_channel.duration);
2737 #endif /* CONFIG_OFFCHANNEL */
2739 wpas_p2p_remain_on_channel_cb(
2740 wpa_s, data->remain_on_channel.freq,
2741 data->remain_on_channel.duration);
2742 #endif /* CONFIG_P2P */
2744 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2745 #ifdef CONFIG_OFFCHANNEL
2746 offchannel_cancel_remain_on_channel_cb(
2747 wpa_s, data->remain_on_channel.freq);
2748 #endif /* CONFIG_OFFCHANNEL */
2750 wpas_p2p_cancel_remain_on_channel_cb(
2751 wpa_s, data->remain_on_channel.freq);
2752 #endif /* CONFIG_P2P */
2755 case EVENT_P2P_DEV_FOUND: {
2756 struct p2p_peer_info peer_info;
2758 os_memset(&peer_info, 0, sizeof(peer_info));
2759 if (data->p2p_dev_found.dev_addr)
2760 os_memcpy(peer_info.p2p_device_addr,
2761 data->p2p_dev_found.dev_addr, ETH_ALEN);
2762 if (data->p2p_dev_found.pri_dev_type)
2763 os_memcpy(peer_info.pri_dev_type,
2764 data->p2p_dev_found.pri_dev_type,
2765 sizeof(peer_info.pri_dev_type));
2766 if (data->p2p_dev_found.dev_name)
2767 os_strlcpy(peer_info.device_name,
2768 data->p2p_dev_found.dev_name,
2769 sizeof(peer_info.device_name));
2770 peer_info.config_methods = data->p2p_dev_found.config_methods;
2771 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2772 peer_info.group_capab = data->p2p_dev_found.group_capab;
2775 * FIX: new_device=1 is not necessarily correct. We should
2776 * maintain a P2P peer database in wpa_supplicant and update
2777 * this information based on whether the peer is truly new.
2779 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2782 case EVENT_P2P_GO_NEG_REQ_RX:
2783 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2784 data->p2p_go_neg_req_rx.dev_passwd_id);
2786 case EVENT_P2P_GO_NEG_COMPLETED:
2787 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2789 case EVENT_P2P_PROV_DISC_REQUEST:
2790 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2791 data->p2p_prov_disc_req.config_methods,
2792 data->p2p_prov_disc_req.dev_addr,
2793 data->p2p_prov_disc_req.pri_dev_type,
2794 data->p2p_prov_disc_req.dev_name,
2795 data->p2p_prov_disc_req.supp_config_methods,
2796 data->p2p_prov_disc_req.dev_capab,
2797 data->p2p_prov_disc_req.group_capab,
2800 case EVENT_P2P_PROV_DISC_RESPONSE:
2801 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2802 data->p2p_prov_disc_resp.config_methods);
2804 case EVENT_P2P_SD_REQUEST:
2805 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2806 data->p2p_sd_req.sa,
2807 data->p2p_sd_req.dialog_token,
2808 data->p2p_sd_req.update_indic,
2809 data->p2p_sd_req.tlvs,
2810 data->p2p_sd_req.tlvs_len);
2812 case EVENT_P2P_SD_RESPONSE:
2813 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2814 data->p2p_sd_resp.update_indic,
2815 data->p2p_sd_resp.tlvs,
2816 data->p2p_sd_resp.tlvs_len);
2818 #endif /* CONFIG_P2P */
2819 case EVENT_EAPOL_RX:
2820 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2821 data->eapol_rx.data,
2822 data->eapol_rx.data_len);
2824 case EVENT_SIGNAL_CHANGE:
2825 bgscan_notify_signal_change(
2826 wpa_s, data->signal_change.above_threshold,
2827 data->signal_change.current_signal,
2828 data->signal_change.current_noise,
2829 data->signal_change.current_txrate);
2831 case EVENT_INTERFACE_ENABLED:
2832 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2833 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2834 wpa_supplicant_update_mac_addr(wpa_s);
2836 if (!wpa_s->ap_iface) {
2837 wpa_supplicant_set_state(wpa_s,
2839 wpa_supplicant_req_scan(wpa_s, 0, 0);
2841 wpa_supplicant_set_state(wpa_s,
2843 #else /* CONFIG_AP */
2844 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2845 wpa_supplicant_req_scan(wpa_s, 0, 0);
2846 #endif /* CONFIG_AP */
2849 case EVENT_INTERFACE_DISABLED:
2850 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2851 wpa_supplicant_mark_disassoc(wpa_s);
2852 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2854 case EVENT_CHANNEL_LIST_CHANGED:
2855 if (wpa_s->drv_priv == NULL)
2856 break; /* Ignore event during drv initialization */
2858 free_hw_features(wpa_s);
2859 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2860 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2863 wpas_p2p_update_channel_list(wpa_s);
2864 #endif /* CONFIG_P2P */
2866 case EVENT_INTERFACE_UNAVAILABLE:
2868 wpas_p2p_interface_unavailable(wpa_s);
2869 #endif /* CONFIG_P2P */
2871 case EVENT_BEST_CHANNEL:
2872 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2874 data->best_chan.freq_24, data->best_chan.freq_5,
2875 data->best_chan.freq_overall);
2876 wpa_s->best_24_freq = data->best_chan.freq_24;
2877 wpa_s->best_5_freq = data->best_chan.freq_5;
2878 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2880 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2881 data->best_chan.freq_5,
2882 data->best_chan.freq_overall);
2883 #endif /* CONFIG_P2P */
2885 case EVENT_UNPROT_DEAUTH:
2886 wpa_supplicant_event_unprot_deauth(wpa_s,
2887 &data->unprot_deauth);
2889 case EVENT_UNPROT_DISASSOC:
2890 wpa_supplicant_event_unprot_disassoc(wpa_s,
2891 &data->unprot_disassoc);
2893 case EVENT_STATION_LOW_ACK:
2895 if (wpa_s->ap_iface && data)
2896 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2897 data->low_ack.addr);
2898 #endif /* CONFIG_AP */
2901 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2902 #endif /* CONFIG_TDLS */
2904 case EVENT_IBSS_PEER_LOST:
2905 #ifdef CONFIG_IBSS_RSN
2906 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2907 #endif /* CONFIG_IBSS_RSN */
2909 case EVENT_DRIVER_GTK_REKEY:
2910 if (os_memcmp(data->driver_gtk_rekey.bssid,
2911 wpa_s->bssid, ETH_ALEN))
2915 wpa_sm_update_replay_ctr(wpa_s->wpa,
2916 data->driver_gtk_rekey.replay_ctr);
2918 case EVENT_SCHED_SCAN_STOPPED:
2919 wpa_s->sched_scanning = 0;
2920 wpa_supplicant_notify_scanning(wpa_s, 0);
2922 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2926 * If we timed out, start a new sched scan to continue
2927 * searching for more SSIDs.
2929 if (wpa_s->sched_scan_timed_out)
2930 wpa_supplicant_req_sched_scan(wpa_s);
2932 case EVENT_WPS_BUTTON_PUSHED:
2934 wpas_wps_start_pbc(wpa_s, NULL, 0);
2935 #endif /* CONFIG_WPS */
2938 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);