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 res = wpas_temp_disabled(wpa_s, ssid);
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
90 "disabled for %d second(s)", res);
94 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
96 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
98 size_t wpa_ie_len = sizeof(wpa_ie);
99 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
100 wpa_ie, &wpa_ie_len);
102 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
105 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
106 eapol_sm_invalidate_cached_session(wpa_s->eapol);
107 old_ssid = wpa_s->current_ssid;
108 wpa_s->current_ssid = ssid;
109 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
110 wpa_supplicant_initiate_eapol(wpa_s);
111 if (old_ssid != wpa_s->current_ssid)
112 wpas_notify_network_changed(wpa_s);
118 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
120 struct wpa_supplicant *wpa_s = eloop_ctx;
122 if (wpa_s->countermeasures) {
123 wpa_s->countermeasures = 0;
124 wpa_drv_set_countermeasures(wpa_s, 0);
125 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
135 wnm_bss_keep_alive_deinit(wpa_s);
137 #ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s->ibss_rsn);
139 wpa_s->ibss_rsn = NULL;
140 #endif /* CONFIG_IBSS_RSN */
143 wpa_supplicant_ap_deinit(wpa_s);
144 #endif /* CONFIG_AP */
146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
149 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
150 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
151 os_memset(wpa_s->bssid, 0, ETH_ALEN);
152 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
154 wpa_s->sme.prev_bssid_set = 0;
155 #endif /* CONFIG_SME */
157 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
158 #endif /* CONFIG_P2P */
159 wpa_s->current_bss = NULL;
160 wpa_s->assoc_freq = 0;
161 #ifdef CONFIG_IEEE80211R
163 if (wpa_s->sme.ft_ies)
164 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
165 #endif /* CONFIG_SME */
166 #endif /* CONFIG_IEEE80211R */
169 wpas_notify_bssid_changed(wpa_s);
171 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
172 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
173 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
174 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
175 wpa_s->ap_ies_from_associnfo = 0;
176 wpa_s->current_ssid = NULL;
181 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
183 struct wpa_ie_data ie;
187 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
191 for (i = 0; i < ie.num_pmkid; i++) {
192 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
193 ie.pmkid + i * PMKID_LEN,
195 if (pmksa_set == 0) {
196 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
201 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
202 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
206 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
207 union wpa_event_data *data)
210 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
214 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
215 " index=%d preauth=%d",
216 MAC2STR(data->pmkid_candidate.bssid),
217 data->pmkid_candidate.index,
218 data->pmkid_candidate.preauth);
220 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
221 data->pmkid_candidate.index,
222 data->pmkid_candidate.preauth);
226 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
228 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
229 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
232 #ifdef IEEE8021X_EAPOL
233 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
234 wpa_s->current_ssid &&
235 !(wpa_s->current_ssid->eapol_flags &
236 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
237 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
238 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
239 * plaintext or static WEP keys). */
242 #endif /* IEEE8021X_EAPOL */
249 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
250 * @wpa_s: pointer to wpa_supplicant data
251 * @ssid: Configuration data for the network
252 * Returns: 0 on success, -1 on failure
254 * This function is called when starting authentication with a network that is
255 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
257 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
258 struct wpa_ssid *ssid)
260 #ifdef IEEE8021X_EAPOL
262 int aka = 0, sim = 0, type;
264 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
267 if (ssid->eap.eap_methods == NULL) {
271 struct eap_method_type *eap = ssid->eap.eap_methods;
272 while (eap->vendor != EAP_VENDOR_IETF ||
273 eap->method != EAP_TYPE_NONE) {
274 if (eap->vendor == EAP_VENDOR_IETF) {
275 if (eap->method == EAP_TYPE_SIM)
277 else if (eap->method == EAP_TYPE_AKA ||
278 eap->method == EAP_TYPE_AKA_PRIME)
285 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
287 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
288 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
293 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
294 "use SIM, but neither EAP-SIM nor EAP-AKA are "
299 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
300 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
302 type = SCARD_TRY_BOTH;
304 type = SCARD_USIM_ONLY;
306 type = SCARD_GSM_SIM_ONLY;
308 wpa_s->scard = scard_init(type, NULL);
309 if (wpa_s->scard == NULL) {
310 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
314 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
315 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
316 #endif /* PCSC_FUNCS */
317 #endif /* IEEE8021X_EAPOL */
323 #ifndef CONFIG_NO_SCAN_PROCESSING
324 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
325 struct wpa_ssid *ssid)
329 if (ssid->mixed_cell)
333 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
335 #endif /* CONFIG_WPS */
337 for (i = 0; i < NUM_WEP_KEYS; i++) {
338 if (ssid->wep_key_len[i]) {
343 #ifdef IEEE8021X_EAPOL
344 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
345 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
346 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
348 #endif /* IEEE8021X_EAPOL */
350 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
353 if (bss->caps & IEEE80211_CAP_PRIVACY)
359 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
360 struct wpa_ssid *ssid,
363 struct wpa_ie_data ie;
365 const u8 *rsn_ie, *wpa_ie;
369 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
373 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
374 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
375 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
376 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
377 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
379 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
380 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
383 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
384 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
390 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
392 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
397 if (!(ie.proto & ssid->proto)) {
398 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
403 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
409 if (!(ie.group_cipher & ssid->group_cipher)) {
410 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
415 if (!(ie.key_mgmt & ssid->key_mgmt)) {
416 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
421 #ifdef CONFIG_IEEE80211W
422 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
423 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
428 #endif /* CONFIG_IEEE80211W */
430 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
434 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
435 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
438 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
439 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
445 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
447 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
452 if (!(ie.proto & ssid->proto)) {
453 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
458 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
459 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
464 if (!(ie.group_cipher & ssid->group_cipher)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
470 if (!(ie.key_mgmt & ssid->key_mgmt)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
476 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
480 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
482 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
486 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
487 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
488 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
492 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
497 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
504 static int freq_allowed(int *freqs, int freq)
511 for (i = 0; freqs[i]; i++)
512 if (freqs[i] == freq)
518 static int ht_supported(const struct hostapd_hw_modes *mode)
520 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
522 * The driver did not indicate whether it supports HT. Assume
523 * it does to avoid connection issues.
529 * IEEE Std 802.11n-2009 20.1.1:
530 * An HT non-AP STA shall support all EQM rates for one spatial stream.
532 return mode->mcs_set[0] == 0xff;
536 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
538 const struct hostapd_hw_modes *mode = NULL, *modes;
539 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
544 return 1; /* Cannot do matching without knowing band */
546 modes = wpa_s->hw.modes;
549 * The driver does not provide any additional information
550 * about the utilized hardware, so allow the connection attempt
556 for (i = 0; i < wpa_s->hw.num_modes; i++) {
557 for (j = 0; j < modes[i].num_channels; j++) {
558 int freq = modes[i].channels[j].freq;
559 if (freq == bss->freq) {
561 mode->mode == HOSTAPD_MODE_IEEE80211G)
562 break; /* do not allow 802.11b replace
573 for (i = 0; i < (int) sizeof(scan_ie); i++) {
574 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
578 for (j = 2; j < rate_ie[1] + 2; j++) {
579 int flagged = !!(rate_ie[j] & 0x80);
580 int r = (rate_ie[j] & 0x7f) * 5;
583 * IEEE Std 802.11n-2009 7.3.2.2:
584 * The new BSS Membership selector value is encoded
585 * like a legacy basic rate, but it is not a rate and
586 * only indicates if the BSS members are required to
587 * support the mandatory features of Clause 20 [HT PHY]
588 * in order to join the BSS.
590 if (flagged && ((rate_ie[j] & 0x7f) ==
591 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
592 if (!ht_supported(mode)) {
593 wpa_dbg(wpa_s, MSG_DEBUG,
594 " hardware does not support "
604 /* check for legacy basic rates */
605 for (k = 0; k < mode->num_rates; k++) {
606 if (mode->rates[k] == r)
609 if (k == mode->num_rates) {
611 * IEEE Std 802.11-2007 7.3.2.2 demands that in
612 * order to join a BSS all required rates
613 * have to be supported by the hardware.
615 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
616 "not support required rate %d.%d Mbps",
627 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
628 int i, struct wpa_bss *bss,
629 struct wpa_ssid *group)
631 u8 wpa_ie_len, rsn_ie_len;
633 struct wpa_blacklist *e;
635 struct wpa_ssid *ssid;
637 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
638 wpa_ie_len = ie ? ie[1] : 0;
640 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
641 rsn_ie_len = ie ? ie[1] : 0;
643 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
644 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
645 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
646 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
647 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
649 e = wpa_blacklist_get(wpa_s, bss->bssid);
652 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
654 * When only a single network is enabled, we can
655 * trigger blacklisting on the first failure. This
656 * should not be done with multiple enabled networks to
657 * avoid getting forced to move into a worse ESS on
658 * single error if there are no other BSSes of the
663 if (e->count > limit) {
664 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
665 "(count=%d limit=%d)", e->count, limit);
670 if (bss->ssid_len == 0) {
671 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
675 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
677 for (ssid = group; ssid; ssid = ssid->pnext) {
678 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
681 if (wpas_network_disabled(wpa_s, ssid)) {
682 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
686 res = wpas_temp_disabled(wpa_s, ssid);
688 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
689 "temporarily for %d second(s)", res);
694 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
695 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
700 if (wpa && ssid->ssid_len == 0 &&
701 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
704 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
705 /* Only allow wildcard SSID match if an AP
706 * advertises active WPS operation that matches
709 if (ssid->ssid_len == 0 &&
710 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
713 #endif /* CONFIG_WPS */
715 if (ssid->bssid_set && ssid->ssid_len == 0 &&
716 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
720 (bss->ssid_len != ssid->ssid_len ||
721 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
722 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
726 if (ssid->bssid_set &&
727 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
728 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
732 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
736 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
737 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
738 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
739 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
744 if (!wpa_supplicant_match_privacy(bss, ssid)) {
745 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
750 if (bss->caps & IEEE80211_CAP_IBSS) {
751 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
756 if (!freq_allowed(ssid->freq_list, bss->freq)) {
757 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
762 if (!rate_match(wpa_s, bss)) {
763 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
770 * TODO: skip the AP if its P2P IE has Group Formation
771 * bit set in the P2P Group Capability Bitmap and we
772 * are not in Group Formation with that device.
774 #endif /* CONFIG_P2P */
776 /* Matching configuration found */
780 /* No matching configuration found */
785 static struct wpa_bss *
786 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
787 struct wpa_ssid *group,
788 struct wpa_ssid **selected_ssid)
792 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
795 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
796 struct wpa_bss *bss = wpa_s->last_scan_res[i];
797 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
800 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
803 wpa_ssid_txt(bss->ssid, bss->ssid_len));
811 static struct wpa_bss *
812 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
813 struct wpa_ssid **selected_ssid)
815 struct wpa_bss *selected = NULL;
818 if (wpa_s->last_scan_res == NULL ||
819 wpa_s->last_scan_res_used == 0)
820 return NULL; /* no scan results from last update */
822 while (selected == NULL) {
823 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
824 selected = wpa_supplicant_select_bss(
825 wpa_s, wpa_s->conf->pssid[prio],
831 if (selected == NULL && wpa_s->blacklist &&
832 !wpa_s->countermeasures) {
833 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
834 "blacklist and try again");
835 wpa_blacklist_clear(wpa_s);
836 wpa_s->blacklist_cleared++;
837 } else if (selected == NULL)
845 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
846 int timeout_sec, int timeout_usec)
848 if (!wpa_supplicant_enabled_networks(wpa_s)) {
850 * No networks are enabled; short-circuit request so
851 * we don't wait timeout seconds before transitioning
854 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
857 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
861 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
862 struct wpa_bss *selected,
863 struct wpa_ssid *ssid)
865 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
866 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
867 "PBC session overlap");
869 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
871 #endif /* CONFIG_P2P */
874 wpas_wps_cancel(wpa_s);
875 #endif /* CONFIG_WPS */
880 * Do not trigger new association unless the BSSID has changed or if
881 * reassociation is requested. If we are in process of associating with
882 * the selected BSSID, do not trigger new attempt.
884 if (wpa_s->reassociate ||
885 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
886 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
887 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
888 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
890 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
891 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
894 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
895 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
896 " pending: " MACSTR " wpa_state: %s",
897 wpa_s->reassociate, MAC2STR(selected->bssid),
898 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
899 wpa_supplicant_state_txt(wpa_s->wpa_state));
900 wpa_supplicant_associate(wpa_s, selected, ssid);
902 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
910 static struct wpa_ssid *
911 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
914 struct wpa_ssid *ssid;
916 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
917 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
919 if (wpas_network_disabled(wpa_s, ssid))
921 if (ssid->mode == IEEE80211_MODE_IBSS ||
922 ssid->mode == IEEE80211_MODE_AP)
930 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
931 * on BSS added and BSS changed events */
932 static void wpa_supplicant_rsn_preauth_scan_results(
933 struct wpa_supplicant *wpa_s)
937 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
940 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
941 const u8 *ssid, *rsn;
943 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
947 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
951 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
957 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
958 struct wpa_bss *selected,
959 struct wpa_ssid *ssid)
961 struct wpa_bss *current_bss = NULL;
964 if (wpa_s->reassociate)
965 return 1; /* explicit request to reassociate */
966 if (wpa_s->wpa_state < WPA_ASSOCIATED)
967 return 1; /* we are not associated; continue */
968 if (wpa_s->current_ssid == NULL)
969 return 1; /* unknown current SSID */
970 if (wpa_s->current_ssid != ssid)
971 return 1; /* different network block */
973 if (wpas_driver_bss_selection(wpa_s))
974 return 0; /* Driver-based roaming */
976 if (wpa_s->current_ssid->ssid)
977 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
978 wpa_s->current_ssid->ssid,
979 wpa_s->current_ssid->ssid_len);
981 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
984 return 1; /* current BSS not seen in scan results */
986 if (current_bss == selected)
989 if (selected->last_update_idx > current_bss->last_update_idx)
990 return 1; /* current BSS not seen in the last scan */
992 #ifndef CONFIG_NO_ROAMING
993 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
994 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
995 MAC2STR(current_bss->bssid), current_bss->level);
996 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
997 MAC2STR(selected->bssid), selected->level);
999 if (wpa_s->current_ssid->bssid_set &&
1000 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1002 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1003 "has preferred BSSID");
1008 if (current_bss->level < 0) {
1009 if (current_bss->level < -85)
1011 else if (current_bss->level < -80)
1013 else if (current_bss->level < -75)
1015 else if (current_bss->level < -70)
1020 if (abs(current_bss->level - selected->level) < min_diff) {
1021 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1027 #else /* CONFIG_NO_ROAMING */
1029 #endif /* CONFIG_NO_ROAMING */
1033 /* Return < 0 if no scan results could be fetched or if scan results should not
1034 * be shared with other virtual interfaces. */
1035 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1036 union wpa_event_data *data)
1038 struct wpa_bss *selected;
1039 struct wpa_ssid *ssid = NULL;
1040 struct wpa_scan_results *scan_res;
1042 #ifndef CONFIG_NO_RANDOM_POOL
1044 #endif /* CONFIG_NO_RANDOM_POOL */
1047 if (wpa_s->ap_iface)
1049 #endif /* CONFIG_AP */
1051 wpa_supplicant_notify_scanning(wpa_s, 0);
1054 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1055 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
1056 wpa_s->p2p_cb_on_scan_complete = 0;
1057 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1058 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1059 "stopped scan processing");
1063 wpa_s->sta_scan_pending = 0;
1064 #endif /* CONFIG_P2P */
1066 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1067 data ? &data->scan_info :
1069 if (scan_res == NULL) {
1070 if (wpa_s->conf->ap_scan == 2 || ap)
1072 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1074 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1078 #ifndef CONFIG_NO_RANDOM_POOL
1079 num = scan_res->num;
1082 for (i = 0; i < num; i++) {
1084 struct wpa_scan_res *res = scan_res->res[i];
1085 buf[0] = res->bssid[5];
1086 buf[1] = res->qual & 0xff;
1087 buf[2] = res->noise & 0xff;
1088 buf[3] = res->level & 0xff;
1089 buf[4] = res->tsf & 0xff;
1090 random_add_randomness(buf, sizeof(buf));
1092 #endif /* CONFIG_NO_RANDOM_POOL */
1094 if (wpa_s->scan_res_handler) {
1095 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1096 struct wpa_scan_results *scan_res);
1098 scan_res_handler = wpa_s->scan_res_handler;
1099 wpa_s->scan_res_handler = NULL;
1100 scan_res_handler(wpa_s, scan_res);
1102 wpa_scan_results_free(scan_res);
1107 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1109 if (wpa_s->ap_iface->scan_cb)
1110 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1111 #endif /* CONFIG_AP */
1112 wpa_scan_results_free(scan_res);
1116 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1117 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1118 wpas_notify_scan_results(wpa_s);
1120 wpas_notify_scan_done(wpa_s, 1);
1122 if (sme_proc_obss_scan(wpa_s) > 0) {
1123 wpa_scan_results_free(scan_res);
1127 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1128 wpa_scan_results_free(scan_res);
1132 if (autoscan_notify_scan(wpa_s, scan_res)) {
1133 wpa_scan_results_free(scan_res);
1137 if (wpa_s->disconnected) {
1138 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1139 wpa_scan_results_free(scan_res);
1143 if (!wpas_driver_bss_selection(wpa_s) &&
1144 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1145 wpa_scan_results_free(scan_res);
1149 wpas_wps_update_ap_info(wpa_s, scan_res);
1151 wpa_scan_results_free(scan_res);
1153 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1157 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1159 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1163 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1164 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1167 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1169 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1170 ssid = wpa_supplicant_pick_new_network(wpa_s);
1172 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1173 wpa_supplicant_associate(wpa_s, NULL, ssid);
1174 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1176 int timeout_sec = wpa_s->scan_interval;
1177 int timeout_usec = 0;
1179 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1182 if (wpa_s->p2p_in_provisioning) {
1184 * Use shorter wait during P2P Provisioning
1185 * state to speed up group formation.
1188 timeout_usec = 250000;
1189 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1193 #endif /* CONFIG_P2P */
1194 #ifdef CONFIG_INTERWORKING
1195 if (wpa_s->conf->auto_interworking &&
1196 wpa_s->conf->interworking &&
1197 wpa_s->conf->cred) {
1198 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1199 "start ANQP fetch since no matching "
1201 wpa_s->network_select = 1;
1202 wpa_s->auto_network_select = 1;
1203 interworking_start_fetch_anqp(wpa_s);
1206 #endif /* CONFIG_INTERWORKING */
1207 if (wpa_supplicant_req_sched_scan(wpa_s))
1208 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1216 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1217 union wpa_event_data *data)
1219 const char *rn, *rn2;
1220 struct wpa_supplicant *ifs;
1222 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1224 * If no scan results could be fetched, then no need to
1225 * notify those interfaces that did not actually request
1232 * Check other interfaces to see if they have the same radio-name. If
1233 * so, they get updated with this same scan info.
1235 if (!wpa_s->driver->get_radio_name)
1238 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1239 if (rn == NULL || rn[0] == '\0')
1242 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1243 "sharing same radio (%s) in event_scan_results", rn);
1245 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1246 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1249 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1250 if (rn2 && os_strcmp(rn, rn2) == 0) {
1251 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1252 "sibling", ifs->ifname);
1253 _wpa_supplicant_event_scan_results(ifs, data);
1258 #endif /* CONFIG_NO_SCAN_PROCESSING */
1263 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1265 struct wpa_supplicant *wpa_s = eloop_ctx;
1267 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1270 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1271 MAC2STR(wpa_s->bssid));
1272 /* TODO: could skip this if normal data traffic has been sent */
1273 /* TODO: Consider using some more appropriate data frame for this */
1275 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1278 if (wpa_s->sme.bss_max_idle_period) {
1280 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1283 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1284 wnm_bss_keep_alive, wpa_s, NULL);
1286 #endif /* CONFIG_SME */
1290 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1291 const u8 *ies, size_t ies_len)
1293 struct ieee802_11_elems elems;
1298 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1302 if (elems.bss_max_idle_period) {
1304 wpa_s->sme.bss_max_idle_period =
1305 WPA_GET_LE16(elems.bss_max_idle_period);
1306 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1307 "TU)%s", wpa_s->sme.bss_max_idle_period,
1308 (elems.bss_max_idle_period[2] & 0x01) ?
1309 " (protected keep-live required)" : "");
1310 if (wpa_s->sme.bss_max_idle_period == 0)
1311 wpa_s->sme.bss_max_idle_period = 1;
1312 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1313 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1314 /* msec times 1000 */
1315 msec = wpa_s->sme.bss_max_idle_period * 1024;
1318 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1319 wnm_bss_keep_alive, wpa_s,
1323 #endif /* CONFIG_SME */
1326 #endif /* CONFIG_WNM */
1329 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1332 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1333 #endif /* CONFIG_WNM */
1337 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1338 union wpa_event_data *data)
1340 int l, len, found = 0, wpa_found, rsn_found;
1343 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1344 if (data->assoc_info.req_ies)
1345 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1346 data->assoc_info.req_ies_len);
1347 if (data->assoc_info.resp_ies) {
1348 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1349 data->assoc_info.resp_ies_len);
1351 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1352 data->assoc_info.resp_ies_len);
1353 #endif /* CONFIG_TDLS */
1355 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1356 data->assoc_info.resp_ies_len);
1357 #endif /* CONFIG_WNM */
1359 if (data->assoc_info.beacon_ies)
1360 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1361 data->assoc_info.beacon_ies,
1362 data->assoc_info.beacon_ies_len);
1363 if (data->assoc_info.freq)
1364 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1365 data->assoc_info.freq);
1367 p = data->assoc_info.req_ies;
1368 l = data->assoc_info.req_ies_len;
1370 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1371 while (p && l >= 2) {
1374 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1378 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1379 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1380 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1381 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1384 wpa_find_assoc_pmkid(wpa_s);
1390 if (!found && data->assoc_info.req_ies)
1391 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1393 #ifdef CONFIG_IEEE80211R
1395 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1397 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1398 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1399 data->assoc_info.resp_ies,
1400 data->assoc_info.resp_ies_len,
1402 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1403 "Reassociation Response failed");
1404 wpa_supplicant_deauthenticate(
1405 wpa_s, WLAN_REASON_INVALID_IE);
1410 p = data->assoc_info.resp_ies;
1411 l = data->assoc_info.resp_ies_len;
1413 #ifdef CONFIG_WPS_STRICT
1414 if (p && wpa_s->current_ssid &&
1415 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1417 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1419 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1420 "include WPS IE in (Re)Association Response");
1424 if (wps_validate_assoc_resp(wps) < 0) {
1426 wpa_supplicant_deauthenticate(
1427 wpa_s, WLAN_REASON_INVALID_IE);
1432 #endif /* CONFIG_WPS_STRICT */
1434 /* Go through the IEs and make a copy of the MDIE, if present. */
1435 while (p && l >= 2) {
1438 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1442 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1443 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1444 wpa_s->sme.ft_used = 1;
1445 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1446 MOBILITY_DOMAIN_ID_LEN);
1452 #endif /* CONFIG_SME */
1454 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1455 data->assoc_info.resp_ies_len);
1456 #endif /* CONFIG_IEEE80211R */
1458 /* WPA/RSN IE from Beacon/ProbeResp */
1459 p = data->assoc_info.beacon_ies;
1460 l = data->assoc_info.beacon_ies_len;
1462 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1464 wpa_found = rsn_found = 0;
1465 while (p && l >= 2) {
1468 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1473 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1474 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1476 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1480 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1482 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1489 if (!wpa_found && data->assoc_info.beacon_ies)
1490 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1491 if (!rsn_found && data->assoc_info.beacon_ies)
1492 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1493 if (wpa_found || rsn_found)
1494 wpa_s->ap_ies_from_associnfo = 1;
1496 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1497 wpa_s->assoc_freq != data->assoc_info.freq) {
1498 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1500 wpa_s->assoc_freq, data->assoc_info.freq);
1501 wpa_supplicant_update_scan_results(wpa_s);
1504 wpa_s->assoc_freq = data->assoc_info.freq;
1510 static struct wpa_bss * wpa_supplicant_get_new_bss(
1511 struct wpa_supplicant *wpa_s, const u8 *bssid)
1513 struct wpa_bss *bss = NULL;
1514 struct wpa_ssid *ssid = wpa_s->current_ssid;
1516 if (ssid->ssid_len > 0)
1517 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1519 bss = wpa_bss_get_bssid(wpa_s, bssid);
1525 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1527 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1529 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1532 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1535 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1536 WPA_IE_VENDOR_TYPE);
1537 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1539 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1540 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1541 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1542 bss_rsn ? 2 + bss_rsn[1] : 0))
1549 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1550 union wpa_event_data *data)
1554 struct wpa_driver_capa capa;
1557 if (wpa_s->ap_iface) {
1558 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1559 data->assoc_info.addr,
1560 data->assoc_info.req_ies,
1561 data->assoc_info.req_ies_len,
1562 data->assoc_info.reassoc);
1565 #endif /* CONFIG_AP */
1567 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1568 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1571 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1572 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1573 wpa_supplicant_disassociate(
1574 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1578 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1579 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1580 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1581 MACSTR, MAC2STR(bssid));
1582 random_add_randomness(bssid, ETH_ALEN);
1583 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1584 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1585 wpas_notify_bssid_changed(wpa_s);
1587 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1588 wpa_clear_keys(wpa_s, bssid);
1590 if (wpa_supplicant_select_config(wpa_s) < 0) {
1591 wpa_supplicant_disassociate(
1592 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1595 if (wpa_s->current_ssid) {
1596 struct wpa_bss *bss = NULL;
1598 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1600 wpa_supplicant_update_scan_results(wpa_s);
1602 /* Get the BSS from the new scan results */
1603 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1607 wpa_s->current_bss = bss;
1610 if (wpa_s->conf->ap_scan == 1 &&
1611 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1612 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1613 wpa_msg(wpa_s, MSG_WARNING,
1614 "WPA/RSN IEs not updated");
1619 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1620 wpa_s->sme.prev_bssid_set = 1;
1621 #endif /* CONFIG_SME */
1623 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1624 if (wpa_s->current_ssid) {
1625 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1626 * initialized before association, but for other modes,
1627 * initialize PC/SC here, if the current configuration needs
1628 * smartcard or SIM/USIM. */
1629 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1631 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1633 l2_packet_notify_auth_start(wpa_s->l2);
1636 * Set portEnabled first to FALSE in order to get EAP state machine out
1637 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1638 * state machine may transit to AUTHENTICATING state based on obsolete
1639 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1640 * AUTHENTICATED without ever giving chance to EAP state machine to
1643 if (!ft_completed) {
1644 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1645 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1647 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1648 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1649 /* 802.1X::portControl = Auto */
1650 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1651 wpa_s->eapol_received = 0;
1652 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1653 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1654 (wpa_s->current_ssid &&
1655 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1656 wpa_supplicant_cancel_auth_timeout(wpa_s);
1657 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1658 } else if (!ft_completed) {
1659 /* Timeout for receiving the first EAPOL packet */
1660 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1662 wpa_supplicant_cancel_scan(wpa_s);
1664 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1665 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1667 * We are done; the driver will take care of RSN 4-way
1670 wpa_supplicant_cancel_auth_timeout(wpa_s);
1671 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1672 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1673 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1674 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1675 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1677 * The driver will take care of RSN 4-way handshake, so we need
1678 * to allow EAPOL supplicant to complete its work without
1679 * waiting for WPA supplicant.
1681 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1682 } else if (ft_completed) {
1684 * FT protocol completed - make sure EAPOL state machine ends
1685 * up in authenticated.
1687 wpa_supplicant_cancel_auth_timeout(wpa_s);
1688 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1689 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1690 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1693 if (wpa_s->pending_eapol_rx) {
1694 struct os_time now, age;
1696 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1697 if (age.sec == 0 && age.usec < 100000 &&
1698 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1700 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1701 "frame that was received just before "
1702 "association notification");
1703 wpa_supplicant_rx_eapol(
1704 wpa_s, wpa_s->pending_eapol_rx_src,
1705 wpabuf_head(wpa_s->pending_eapol_rx),
1706 wpabuf_len(wpa_s->pending_eapol_rx));
1708 wpabuf_free(wpa_s->pending_eapol_rx);
1709 wpa_s->pending_eapol_rx = NULL;
1712 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1713 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1714 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1715 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1716 /* Set static WEP keys again */
1717 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1720 #ifdef CONFIG_IBSS_RSN
1721 if (wpa_s->current_ssid &&
1722 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1723 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1724 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1725 wpa_s->ibss_rsn == NULL) {
1726 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1727 if (!wpa_s->ibss_rsn) {
1728 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1729 wpa_supplicant_deauthenticate(
1730 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1734 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1736 #endif /* CONFIG_IBSS_RSN */
1738 wpas_wps_notify_assoc(wpa_s, bssid);
1742 static int disconnect_reason_recoverable(u16 reason_code)
1744 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1745 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1746 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1750 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1752 int locally_generated)
1756 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1758 * At least Host AP driver and a Prism3 card seemed to be
1759 * generating streams of disconnected events when configuring
1760 * IBSS for WPA-None. Ignore them for now.
1765 bssid = wpa_s->bssid;
1766 if (is_zero_ether_addr(bssid))
1767 bssid = wpa_s->pending_bssid;
1769 if (!is_zero_ether_addr(bssid) ||
1770 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1771 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1773 MAC2STR(bssid), reason_code,
1774 locally_generated ? " locally_generated=1" : "");
1779 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1781 int locally_generated)
1785 u8 prev_pending_bssid[ETH_ALEN];
1786 struct wpa_bss *fast_reconnect = NULL;
1787 struct wpa_ssid *fast_reconnect_ssid = NULL;
1788 struct wpa_ssid *last_ssid;
1790 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1791 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1793 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1795 * At least Host AP driver and a Prism3 card seemed to be
1796 * generating streams of disconnected events when configuring
1797 * IBSS for WPA-None. Ignore them for now.
1799 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1800 "IBSS/WPA-None mode");
1804 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1805 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1806 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1807 "pre-shared key may be incorrect");
1808 wpas_auth_failed(wpa_s);
1810 if (!wpa_s->auto_reconnect_disabled ||
1811 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1812 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1813 "reconnect (wps=%d wpa_state=%d)",
1814 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1816 if (wpa_s->wpa_state == WPA_COMPLETED &&
1817 wpa_s->current_ssid &&
1818 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1819 !locally_generated &&
1820 disconnect_reason_recoverable(reason_code)) {
1822 * It looks like the AP has dropped association with
1823 * us, but could allow us to get back in. Try to
1824 * reconnect to the same BSS without full scan to save
1825 * time for some common cases.
1827 fast_reconnect = wpa_s->current_bss;
1828 fast_reconnect_ssid = wpa_s->current_ssid;
1829 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1830 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1832 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1835 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1836 "try to re-connect");
1837 wpa_s->reassociate = 0;
1838 wpa_s->disconnected = 1;
1839 wpa_supplicant_cancel_sched_scan(wpa_s);
1841 bssid = wpa_s->bssid;
1842 if (is_zero_ether_addr(bssid))
1843 bssid = wpa_s->pending_bssid;
1844 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1845 wpas_connection_failed(wpa_s, bssid);
1846 wpa_sm_notify_disassoc(wpa_s->wpa);
1847 if (locally_generated)
1848 wpa_s->disconnect_reason = -reason_code;
1850 wpa_s->disconnect_reason = reason_code;
1851 wpas_notify_disconnect_reason(wpa_s);
1852 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1853 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1854 wpa_s->keys_cleared = 0;
1855 wpa_clear_keys(wpa_s, wpa_s->bssid);
1857 last_ssid = wpa_s->current_ssid;
1858 wpa_supplicant_mark_disassoc(wpa_s);
1860 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1861 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1862 wpa_s->current_ssid = last_ssid;
1865 if (fast_reconnect) {
1866 #ifndef CONFIG_NO_SCAN_PROCESSING
1867 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1868 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1869 fast_reconnect_ssid) < 0) {
1870 /* Recover through full scan */
1871 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1873 #endif /* CONFIG_NO_SCAN_PROCESSING */
1878 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1879 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1881 struct wpa_supplicant *wpa_s = eloop_ctx;
1883 if (!wpa_s->pending_mic_error_report)
1886 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1887 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1888 wpa_s->pending_mic_error_report = 0;
1890 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1894 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1895 union wpa_event_data *data)
1900 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1901 pairwise = (data && data->michael_mic_failure.unicast);
1903 if ((wpa_s->last_michael_mic_error &&
1904 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1905 wpa_s->pending_mic_error_report) {
1906 if (wpa_s->pending_mic_error_report) {
1908 * Send the pending MIC error report immediately since
1909 * we are going to start countermeasures and AP better
1912 wpa_sm_key_request(wpa_s->wpa, 1,
1913 wpa_s->pending_mic_error_pairwise);
1916 /* Send the new MIC error report immediately since we are going
1917 * to start countermeasures and AP better do the same.
1919 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1921 /* initialize countermeasures */
1922 wpa_s->countermeasures = 1;
1924 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1926 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1929 * Need to wait for completion of request frame. We do not get
1930 * any callback for the message completion, so just wait a
1931 * short while and hope for the best. */
1934 wpa_drv_set_countermeasures(wpa_s, 1);
1935 wpa_supplicant_deauthenticate(wpa_s,
1936 WLAN_REASON_MICHAEL_MIC_FAILURE);
1937 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1939 eloop_register_timeout(60, 0,
1940 wpa_supplicant_stop_countermeasures,
1942 /* TODO: mark the AP rejected for 60 second. STA is
1943 * allowed to associate with another AP.. */
1945 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1946 if (wpa_s->mic_errors_seen) {
1948 * Reduce the effectiveness of Michael MIC error
1949 * reports as a means for attacking against TKIP if
1950 * more than one MIC failure is noticed with the same
1951 * PTK. We delay the transmission of the reports by a
1952 * random time between 0 and 60 seconds in order to
1953 * force the attacker wait 60 seconds before getting
1954 * the information on whether a frame resulted in a MIC
1960 if (os_get_random(rval, sizeof(rval)) < 0)
1961 sec = os_random() % 60;
1963 sec = WPA_GET_BE32(rval) % 60;
1964 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1965 "report %d seconds", sec);
1966 wpa_s->pending_mic_error_report = 1;
1967 wpa_s->pending_mic_error_pairwise = pairwise;
1968 eloop_cancel_timeout(
1969 wpa_supplicant_delayed_mic_error_report,
1971 eloop_register_timeout(
1972 sec, os_random() % 1000000,
1973 wpa_supplicant_delayed_mic_error_report,
1976 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1978 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1979 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1980 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1982 wpa_s->last_michael_mic_error = t.sec;
1983 wpa_s->mic_errors_seen++;
1987 #ifdef CONFIG_TERMINATE_ONLASTIF
1988 static int any_interfaces(struct wpa_supplicant *head)
1990 struct wpa_supplicant *wpa_s;
1992 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1993 if (!wpa_s->interface_removed)
1997 #endif /* CONFIG_TERMINATE_ONLASTIF */
2001 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2002 union wpa_event_data *data)
2004 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2007 switch (data->interface_status.ievent) {
2008 case EVENT_INTERFACE_ADDED:
2009 if (!wpa_s->interface_removed)
2011 wpa_s->interface_removed = 0;
2012 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2013 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2014 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2015 "driver after interface was added");
2017 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2019 case EVENT_INTERFACE_REMOVED:
2020 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2021 wpa_s->interface_removed = 1;
2022 wpa_supplicant_mark_disassoc(wpa_s);
2023 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2024 l2_packet_deinit(wpa_s->l2);
2026 #ifdef CONFIG_IBSS_RSN
2027 ibss_rsn_deinit(wpa_s->ibss_rsn);
2028 wpa_s->ibss_rsn = NULL;
2029 #endif /* CONFIG_IBSS_RSN */
2030 #ifdef CONFIG_TERMINATE_ONLASTIF
2031 /* check if last interface */
2032 if (!any_interfaces(wpa_s->global->ifaces))
2034 #endif /* CONFIG_TERMINATE_ONLASTIF */
2040 #ifdef CONFIG_PEERKEY
2042 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2043 union wpa_event_data *data)
2047 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2049 #endif /* CONFIG_PEERKEY */
2053 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2054 union wpa_event_data *data)
2058 switch (data->tdls.oper) {
2059 case TDLS_REQUEST_SETUP:
2060 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2062 case TDLS_REQUEST_TEARDOWN:
2063 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2064 data->tdls.reason_code);
2068 #endif /* CONFIG_TDLS */
2071 #ifdef CONFIG_IEEE80211V
2072 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2073 union wpa_event_data *data)
2077 switch (data->wnm.oper) {
2078 case WNM_OPER_SLEEP:
2079 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2080 "(action=%d, intval=%d)",
2081 data->wnm.sleep_action, data->wnm.sleep_intval);
2082 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2083 data->wnm.sleep_intval);
2087 #endif /* CONFIG_IEEE80211V */
2090 #ifdef CONFIG_IEEE80211R
2092 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2093 union wpa_event_data *data)
2098 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2099 data->ft_ies.ies_len,
2100 data->ft_ies.ft_action,
2101 data->ft_ies.target_ap,
2102 data->ft_ies.ric_ies,
2103 data->ft_ies.ric_ies_len) < 0) {
2104 /* TODO: prevent MLME/driver from trying to associate? */
2107 #endif /* CONFIG_IEEE80211R */
2110 #ifdef CONFIG_IBSS_RSN
2111 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2112 union wpa_event_data *data)
2114 struct wpa_ssid *ssid;
2115 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2119 ssid = wpa_s->current_ssid;
2122 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2125 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2127 #endif /* CONFIG_IBSS_RSN */
2130 #ifdef CONFIG_IEEE80211R
2131 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2134 const u8 *sta_addr, *target_ap_addr;
2137 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2138 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2139 return; /* only SME case supported for now */
2140 if (len < 1 + 2 * ETH_ALEN + 2)
2143 return; /* Only FT Action Response is supported for now */
2144 sta_addr = data + 1;
2145 target_ap_addr = data + 1 + ETH_ALEN;
2146 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2147 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2148 MACSTR " TargetAP " MACSTR " status %u",
2149 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2151 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2152 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2153 " in FT Action Response", MAC2STR(sta_addr));
2158 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2159 "failure (status code %d)", status);
2160 /* TODO: report error to FT code(?) */
2164 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2165 len - (1 + 2 * ETH_ALEN + 2), 1,
2166 target_ap_addr, NULL, 0) < 0)
2171 struct wpa_bss *bss;
2172 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2174 wpa_s->sme.freq = bss->freq;
2175 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2176 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2179 #endif /* CONFIG_SME */
2181 #endif /* CONFIG_IEEE80211R */
2184 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2185 struct unprot_deauth *e)
2187 #ifdef CONFIG_IEEE80211W
2188 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2189 "dropped: " MACSTR " -> " MACSTR
2190 " (reason code %u)",
2191 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2192 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2193 #endif /* CONFIG_IEEE80211W */
2197 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2198 struct unprot_disassoc *e)
2200 #ifdef CONFIG_IEEE80211W
2201 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2202 "dropped: " MACSTR " -> " MACSTR
2203 " (reason code %u)",
2204 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2205 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2206 #endif /* CONFIG_IEEE80211W */
2210 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2213 const u8 *pos, *end;
2215 if (rx->data == NULL || rx->len == 0)
2219 end = pos + rx->len;
2222 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2223 action, MAC2STR(rx->sa));
2225 case WNM_BSS_TRANS_MGMT_REQ:
2228 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2229 "Request: dialog_token=%u request_mode=0x%x "
2230 "disassoc_timer=%u validity_interval=%u",
2231 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2235 pos += 12; /* BSS Termination Duration */
2238 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2239 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2240 "Transition Management Request "
2244 os_memcpy(url, pos + 1, pos[0]);
2246 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2247 "Imminent - session_info_url=%s", url);
2254 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2255 union wpa_event_data *data)
2257 struct wpa_supplicant *wpa_s = ctx;
2258 u16 reason_code = 0;
2259 int locally_generated = 0;
2261 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2262 event != EVENT_INTERFACE_ENABLED &&
2263 event != EVENT_INTERFACE_STATUS &&
2264 event != EVENT_SCHED_SCAN_STOPPED) {
2265 wpa_dbg(wpa_s, MSG_DEBUG,
2266 "Ignore event %s (%d) while interface is disabled",
2267 event_to_string(event), event);
2271 #ifndef CONFIG_NO_STDOUT_DEBUG
2273 int level = MSG_DEBUG;
2275 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2276 const struct ieee80211_hdr *hdr;
2278 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2279 fc = le_to_host16(hdr->frame_control);
2280 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2281 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2282 level = MSG_EXCESSIVE;
2285 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2286 event_to_string(event), event);
2288 #endif /* CONFIG_NO_STDOUT_DEBUG */
2292 sme_event_auth(wpa_s, data);
2295 wpa_supplicant_event_assoc(wpa_s, data);
2297 case EVENT_DISASSOC:
2298 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2300 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2301 data->disassoc_info.reason_code,
2302 data->disassoc_info.locally_generated ?
2303 " (locally generated)" : "");
2304 if (data->disassoc_info.addr)
2305 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2306 MAC2STR(data->disassoc_info.addr));
2309 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2310 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2311 data->disassoc_info.addr);
2314 if (wpa_s->ap_iface) {
2315 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2319 #endif /* CONFIG_AP */
2321 reason_code = data->disassoc_info.reason_code;
2323 data->disassoc_info.locally_generated;
2324 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2325 data->disassoc_info.ie,
2326 data->disassoc_info.ie_len);
2328 wpas_p2p_disassoc_notif(
2329 wpa_s, data->disassoc_info.addr, reason_code,
2330 data->disassoc_info.ie,
2331 data->disassoc_info.ie_len,
2333 #endif /* CONFIG_P2P */
2335 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2336 sme_event_disassoc(wpa_s, data);
2339 if (event == EVENT_DEAUTH) {
2340 wpa_dbg(wpa_s, MSG_DEBUG,
2341 "Deauthentication notification");
2343 reason_code = data->deauth_info.reason_code;
2345 data->deauth_info.locally_generated;
2346 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2347 data->deauth_info.reason_code,
2348 data->deauth_info.locally_generated ?
2349 " (locally generated)" : "");
2350 if (data->deauth_info.addr) {
2351 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2353 MAC2STR(data->deauth_info.
2356 wpa_hexdump(MSG_DEBUG,
2357 "Deauthentication frame IE(s)",
2358 data->deauth_info.ie,
2359 data->deauth_info.ie_len);
2363 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2364 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2365 data->deauth_info.addr);
2368 if (wpa_s->ap_iface) {
2369 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2373 #endif /* CONFIG_AP */
2374 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2376 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2377 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2378 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2379 eapol_sm_failed(wpa_s->eapol)))
2380 wpas_auth_failed(wpa_s);
2382 if (event == EVENT_DEAUTH && data) {
2383 if (wpas_p2p_deauth_notif(wpa_s,
2384 data->deauth_info.addr,
2386 data->deauth_info.ie,
2387 data->deauth_info.ie_len,
2388 locally_generated) > 0) {
2390 * The interface was removed, so cannot
2391 * continue processing any additional
2392 * operations after this.
2397 #endif /* CONFIG_P2P */
2398 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2401 case EVENT_MICHAEL_MIC_FAILURE:
2402 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2404 #ifndef CONFIG_NO_SCAN_PROCESSING
2405 case EVENT_SCAN_RESULTS:
2406 wpa_supplicant_event_scan_results(wpa_s, data);
2408 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2409 wpa_s->global->p2p != NULL &&
2410 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2411 wpa_s->wpa_state != WPA_ASSOCIATING) {
2412 wpa_s->p2p_cb_on_scan_complete = 0;
2413 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2414 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2415 "continued after scan result processing");
2418 #endif /* CONFIG_P2P */
2420 #endif /* CONFIG_NO_SCAN_PROCESSING */
2421 case EVENT_ASSOCINFO:
2422 wpa_supplicant_event_associnfo(wpa_s, data);
2424 case EVENT_INTERFACE_STATUS:
2425 wpa_supplicant_event_interface_status(wpa_s, data);
2427 case EVENT_PMKID_CANDIDATE:
2428 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2430 #ifdef CONFIG_PEERKEY
2431 case EVENT_STKSTART:
2432 wpa_supplicant_event_stkstart(wpa_s, data);
2434 #endif /* CONFIG_PEERKEY */
2437 wpa_supplicant_event_tdls(wpa_s, data);
2439 #endif /* CONFIG_TDLS */
2440 #ifdef CONFIG_IEEE80211V
2442 wpa_supplicant_event_wnm(wpa_s, data);
2444 #endif /* CONFIG_IEEE80211V */
2445 #ifdef CONFIG_IEEE80211R
2446 case EVENT_FT_RESPONSE:
2447 wpa_supplicant_event_ft_response(wpa_s, data);
2449 #endif /* CONFIG_IEEE80211R */
2450 #ifdef CONFIG_IBSS_RSN
2451 case EVENT_IBSS_RSN_START:
2452 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2454 #endif /* CONFIG_IBSS_RSN */
2455 case EVENT_ASSOC_REJECT:
2456 if (data->assoc_reject.bssid)
2457 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2458 "bssid=" MACSTR " status_code=%u",
2459 MAC2STR(data->assoc_reject.bssid),
2460 data->assoc_reject.status_code);
2462 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2464 data->assoc_reject.status_code);
2465 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2466 sme_event_assoc_reject(wpa_s, data);
2468 case EVENT_AUTH_TIMED_OUT:
2469 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2470 sme_event_auth_timed_out(wpa_s, data);
2472 case EVENT_ASSOC_TIMED_OUT:
2473 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2474 sme_event_assoc_timed_out(wpa_s, data);
2476 case EVENT_TX_STATUS:
2477 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2478 " type=%d stype=%d",
2479 MAC2STR(data->tx_status.dst),
2480 data->tx_status.type, data->tx_status.stype);
2482 if (wpa_s->ap_iface == NULL) {
2483 #ifdef CONFIG_OFFCHANNEL
2484 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2485 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2486 offchannel_send_action_tx_status(
2487 wpa_s, data->tx_status.dst,
2488 data->tx_status.data,
2489 data->tx_status.data_len,
2490 data->tx_status.ack ?
2491 OFFCHANNEL_SEND_ACTION_SUCCESS :
2492 OFFCHANNEL_SEND_ACTION_NO_ACK);
2493 #endif /* CONFIG_OFFCHANNEL */
2496 #endif /* CONFIG_AP */
2497 #ifdef CONFIG_OFFCHANNEL
2498 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2499 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2501 * Catch TX status events for Action frames we sent via group
2502 * interface in GO mode.
2504 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2505 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2506 os_memcmp(wpa_s->parent->pending_action_dst,
2507 data->tx_status.dst, ETH_ALEN) == 0) {
2508 offchannel_send_action_tx_status(
2509 wpa_s->parent, data->tx_status.dst,
2510 data->tx_status.data,
2511 data->tx_status.data_len,
2512 data->tx_status.ack ?
2513 OFFCHANNEL_SEND_ACTION_SUCCESS :
2514 OFFCHANNEL_SEND_ACTION_NO_ACK);
2517 #endif /* CONFIG_OFFCHANNEL */
2519 switch (data->tx_status.type) {
2520 case WLAN_FC_TYPE_MGMT:
2521 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2522 data->tx_status.data_len,
2523 data->tx_status.stype,
2524 data->tx_status.ack);
2526 case WLAN_FC_TYPE_DATA:
2527 ap_tx_status(wpa_s, data->tx_status.dst,
2528 data->tx_status.data,
2529 data->tx_status.data_len,
2530 data->tx_status.ack);
2533 #endif /* CONFIG_AP */
2536 case EVENT_EAPOL_TX_STATUS:
2537 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2538 data->eapol_tx_status.data,
2539 data->eapol_tx_status.data_len,
2540 data->eapol_tx_status.ack);
2542 case EVENT_DRIVER_CLIENT_POLL_OK:
2543 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2545 case EVENT_RX_FROM_UNKNOWN:
2546 if (wpa_s->ap_iface == NULL)
2548 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2549 data->rx_from_unknown.wds);
2551 case EVENT_CH_SWITCH:
2554 if (!wpa_s->ap_iface) {
2555 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2556 "event in non-AP mode");
2561 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2562 data->ch_switch.ht_enabled,
2563 data->ch_switch.ch_offset);
2564 #endif /* CONFIG_AP */
2566 case EVENT_RX_MGMT: {
2568 const struct ieee80211_mgmt *mgmt;
2570 mgmt = (const struct ieee80211_mgmt *)
2571 data->rx_mgmt.frame;
2572 fc = le_to_host16(mgmt->frame_control);
2573 stype = WLAN_FC_GET_STYPE(fc);
2575 if (wpa_s->ap_iface == NULL) {
2577 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2578 data->rx_mgmt.frame_len > 24) {
2579 const u8 *src = mgmt->sa;
2580 const u8 *ie = mgmt->u.probe_req.variable;
2581 size_t ie_len = data->rx_mgmt.frame_len -
2582 (mgmt->u.probe_req.variable -
2583 data->rx_mgmt.frame);
2584 wpas_p2p_probe_req_rx(
2585 wpa_s, src, mgmt->da,
2586 mgmt->bssid, ie, ie_len,
2587 data->rx_mgmt.ssi_signal);
2590 #endif /* CONFIG_P2P */
2591 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2592 "management frame in non-AP mode");
2596 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2597 data->rx_mgmt.frame_len > 24) {
2598 const u8 *ie = mgmt->u.probe_req.variable;
2599 size_t ie_len = data->rx_mgmt.frame_len -
2600 (mgmt->u.probe_req.variable -
2601 data->rx_mgmt.frame);
2603 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2604 mgmt->bssid, ie, ie_len,
2605 data->rx_mgmt.ssi_signal);
2608 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2611 #endif /* CONFIG_AP */
2612 case EVENT_RX_ACTION:
2613 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2614 " Category=%u DataLen=%d freq=%d MHz",
2615 MAC2STR(data->rx_action.sa),
2616 data->rx_action.category, (int) data->rx_action.len,
2617 data->rx_action.freq);
2618 #ifdef CONFIG_IEEE80211R
2619 if (data->rx_action.category == WLAN_ACTION_FT) {
2620 ft_rx_action(wpa_s, data->rx_action.data,
2621 data->rx_action.len);
2624 #endif /* CONFIG_IEEE80211R */
2625 #ifdef CONFIG_IEEE80211W
2627 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2628 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2629 data->rx_action.data,
2630 data->rx_action.len);
2633 #endif /* CONFIG_SME */
2634 #endif /* CONFIG_IEEE80211W */
2635 #ifdef CONFIG_IEEE80211V
2636 if (data->rx_action.category == WLAN_ACTION_WNM) {
2637 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2640 #endif /* CONFIG_IEEE80211V */
2642 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2643 gas_query_rx(wpa_s->gas, data->rx_action.da,
2644 data->rx_action.sa, data->rx_action.bssid,
2645 data->rx_action.data, data->rx_action.len,
2646 data->rx_action.freq) == 0)
2648 #endif /* CONFIG_GAS */
2649 if (data->rx_action.category == WLAN_ACTION_WNM) {
2650 wnm_action_rx(wpa_s, &data->rx_action);
2654 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2655 data->rx_action.len >= 4 &&
2656 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2657 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2658 "Response from " MACSTR,
2659 MAC2STR(data->rx_action.sa));
2662 #endif /* CONFIG_TDLS */
2664 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2666 data->rx_action.bssid,
2667 data->rx_action.category,
2668 data->rx_action.data,
2669 data->rx_action.len, data->rx_action.freq);
2670 #endif /* CONFIG_P2P */
2672 case EVENT_RX_PROBE_REQ:
2673 if (data->rx_probe_req.sa == NULL ||
2674 data->rx_probe_req.ie == NULL)
2677 if (wpa_s->ap_iface) {
2678 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2679 data->rx_probe_req.sa,
2680 data->rx_probe_req.da,
2681 data->rx_probe_req.bssid,
2682 data->rx_probe_req.ie,
2683 data->rx_probe_req.ie_len,
2684 data->rx_probe_req.ssi_signal);
2687 #endif /* CONFIG_AP */
2689 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2690 data->rx_probe_req.da,
2691 data->rx_probe_req.bssid,
2692 data->rx_probe_req.ie,
2693 data->rx_probe_req.ie_len,
2694 data->rx_probe_req.ssi_signal);
2695 #endif /* CONFIG_P2P */
2697 case EVENT_REMAIN_ON_CHANNEL:
2698 #ifdef CONFIG_OFFCHANNEL
2699 offchannel_remain_on_channel_cb(
2700 wpa_s, data->remain_on_channel.freq,
2701 data->remain_on_channel.duration);
2702 #endif /* CONFIG_OFFCHANNEL */
2704 wpas_p2p_remain_on_channel_cb(
2705 wpa_s, data->remain_on_channel.freq,
2706 data->remain_on_channel.duration);
2707 #endif /* CONFIG_P2P */
2709 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2710 #ifdef CONFIG_OFFCHANNEL
2711 offchannel_cancel_remain_on_channel_cb(
2712 wpa_s, data->remain_on_channel.freq);
2713 #endif /* CONFIG_OFFCHANNEL */
2715 wpas_p2p_cancel_remain_on_channel_cb(
2716 wpa_s, data->remain_on_channel.freq);
2717 #endif /* CONFIG_P2P */
2720 case EVENT_P2P_DEV_FOUND: {
2721 struct p2p_peer_info peer_info;
2723 os_memset(&peer_info, 0, sizeof(peer_info));
2724 if (data->p2p_dev_found.dev_addr)
2725 os_memcpy(peer_info.p2p_device_addr,
2726 data->p2p_dev_found.dev_addr, ETH_ALEN);
2727 if (data->p2p_dev_found.pri_dev_type)
2728 os_memcpy(peer_info.pri_dev_type,
2729 data->p2p_dev_found.pri_dev_type,
2730 sizeof(peer_info.pri_dev_type));
2731 if (data->p2p_dev_found.dev_name)
2732 os_strlcpy(peer_info.device_name,
2733 data->p2p_dev_found.dev_name,
2734 sizeof(peer_info.device_name));
2735 peer_info.config_methods = data->p2p_dev_found.config_methods;
2736 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2737 peer_info.group_capab = data->p2p_dev_found.group_capab;
2740 * FIX: new_device=1 is not necessarily correct. We should
2741 * maintain a P2P peer database in wpa_supplicant and update
2742 * this information based on whether the peer is truly new.
2744 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2747 case EVENT_P2P_GO_NEG_REQ_RX:
2748 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2749 data->p2p_go_neg_req_rx.dev_passwd_id);
2751 case EVENT_P2P_GO_NEG_COMPLETED:
2752 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2754 case EVENT_P2P_PROV_DISC_REQUEST:
2755 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2756 data->p2p_prov_disc_req.config_methods,
2757 data->p2p_prov_disc_req.dev_addr,
2758 data->p2p_prov_disc_req.pri_dev_type,
2759 data->p2p_prov_disc_req.dev_name,
2760 data->p2p_prov_disc_req.supp_config_methods,
2761 data->p2p_prov_disc_req.dev_capab,
2762 data->p2p_prov_disc_req.group_capab,
2765 case EVENT_P2P_PROV_DISC_RESPONSE:
2766 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2767 data->p2p_prov_disc_resp.config_methods);
2769 case EVENT_P2P_SD_REQUEST:
2770 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2771 data->p2p_sd_req.sa,
2772 data->p2p_sd_req.dialog_token,
2773 data->p2p_sd_req.update_indic,
2774 data->p2p_sd_req.tlvs,
2775 data->p2p_sd_req.tlvs_len);
2777 case EVENT_P2P_SD_RESPONSE:
2778 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2779 data->p2p_sd_resp.update_indic,
2780 data->p2p_sd_resp.tlvs,
2781 data->p2p_sd_resp.tlvs_len);
2783 #endif /* CONFIG_P2P */
2784 case EVENT_EAPOL_RX:
2785 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2786 data->eapol_rx.data,
2787 data->eapol_rx.data_len);
2789 case EVENT_SIGNAL_CHANGE:
2790 bgscan_notify_signal_change(
2791 wpa_s, data->signal_change.above_threshold,
2792 data->signal_change.current_signal,
2793 data->signal_change.current_noise,
2794 data->signal_change.current_txrate);
2796 case EVENT_INTERFACE_ENABLED:
2797 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2798 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2799 wpa_supplicant_update_mac_addr(wpa_s);
2801 if (!wpa_s->ap_iface) {
2802 wpa_supplicant_set_state(wpa_s,
2804 wpa_supplicant_req_scan(wpa_s, 0, 0);
2806 wpa_supplicant_set_state(wpa_s,
2808 #else /* CONFIG_AP */
2809 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2810 wpa_supplicant_req_scan(wpa_s, 0, 0);
2811 #endif /* CONFIG_AP */
2814 case EVENT_INTERFACE_DISABLED:
2815 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2816 wpa_supplicant_mark_disassoc(wpa_s);
2817 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2819 case EVENT_CHANNEL_LIST_CHANGED:
2820 if (wpa_s->drv_priv == NULL)
2821 break; /* Ignore event during drv initialization */
2823 free_hw_features(wpa_s);
2824 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2825 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2828 wpas_p2p_update_channel_list(wpa_s);
2829 #endif /* CONFIG_P2P */
2831 case EVENT_INTERFACE_UNAVAILABLE:
2833 wpas_p2p_interface_unavailable(wpa_s);
2834 #endif /* CONFIG_P2P */
2836 case EVENT_BEST_CHANNEL:
2837 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2839 data->best_chan.freq_24, data->best_chan.freq_5,
2840 data->best_chan.freq_overall);
2841 wpa_s->best_24_freq = data->best_chan.freq_24;
2842 wpa_s->best_5_freq = data->best_chan.freq_5;
2843 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2845 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2846 data->best_chan.freq_5,
2847 data->best_chan.freq_overall);
2848 #endif /* CONFIG_P2P */
2850 case EVENT_UNPROT_DEAUTH:
2851 wpa_supplicant_event_unprot_deauth(wpa_s,
2852 &data->unprot_deauth);
2854 case EVENT_UNPROT_DISASSOC:
2855 wpa_supplicant_event_unprot_disassoc(wpa_s,
2856 &data->unprot_disassoc);
2858 case EVENT_STATION_LOW_ACK:
2860 if (wpa_s->ap_iface && data)
2861 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2862 data->low_ack.addr);
2863 #endif /* CONFIG_AP */
2866 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2867 #endif /* CONFIG_TDLS */
2869 case EVENT_IBSS_PEER_LOST:
2870 #ifdef CONFIG_IBSS_RSN
2871 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2872 #endif /* CONFIG_IBSS_RSN */
2874 case EVENT_DRIVER_GTK_REKEY:
2875 if (os_memcmp(data->driver_gtk_rekey.bssid,
2876 wpa_s->bssid, ETH_ALEN))
2880 wpa_sm_update_replay_ctr(wpa_s->wpa,
2881 data->driver_gtk_rekey.replay_ctr);
2883 case EVENT_SCHED_SCAN_STOPPED:
2884 wpa_s->sched_scanning = 0;
2885 wpa_supplicant_notify_scanning(wpa_s, 0);
2887 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2891 * If we timed out, start a new sched scan to continue
2892 * searching for more SSIDs.
2894 if (wpa_s->sched_scan_timed_out)
2895 wpa_supplicant_req_sched_scan(wpa_s);
2897 case EVENT_WPS_BUTTON_PUSHED:
2899 wpas_wps_start_pbc(wpa_s, NULL, 0);
2900 #endif /* CONFIG_WPS */
2903 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);