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_scan_res *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,
361 struct wpa_scan_res *bss)
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_scan_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_scan_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_scan_res *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_scan_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_scan_res *bss,
629 struct wpa_ssid *group)
632 u8 wpa_ie_len, rsn_ie_len, ssid_len;
634 struct wpa_blacklist *e;
636 struct wpa_ssid *ssid;
638 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
639 ssid_ = ie ? ie + 2 : (u8 *) "";
640 ssid_len = ie ? ie[1] : 0;
642 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
643 wpa_ie_len = ie ? ie[1] : 0;
645 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
646 rsn_ie_len = ie ? ie[1] : 0;
648 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
649 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
650 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
651 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
652 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
654 e = wpa_blacklist_get(wpa_s, bss->bssid);
657 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
659 * When only a single network is enabled, we can
660 * trigger blacklisting on the first failure. This
661 * should not be done with multiple enabled networks to
662 * avoid getting forced to move into a worse ESS on
663 * single error if there are no other BSSes of the
668 if (e->count > limit) {
669 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
670 "(count=%d limit=%d)", e->count, limit);
676 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
680 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
682 for (ssid = group; ssid; ssid = ssid->pnext) {
683 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
686 if (wpas_network_disabled(wpa_s, ssid)) {
687 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
691 res = wpas_temp_disabled(wpa_s, ssid);
693 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
694 "temporarily for %d second(s)", res);
699 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
700 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
705 if (wpa && ssid->ssid_len == 0 &&
706 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
709 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
710 /* Only allow wildcard SSID match if an AP
711 * advertises active WPS operation that matches
714 if (ssid->ssid_len == 0 &&
715 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
718 #endif /* CONFIG_WPS */
720 if (ssid->bssid_set && ssid->ssid_len == 0 &&
721 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
725 (ssid_len != ssid->ssid_len ||
726 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
727 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
731 if (ssid->bssid_set &&
732 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
733 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
737 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
741 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
742 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
743 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
744 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
749 if (!wpa_supplicant_match_privacy(bss, ssid)) {
750 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
755 if (bss->caps & IEEE80211_CAP_IBSS) {
756 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
761 if (!freq_allowed(ssid->freq_list, bss->freq)) {
762 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
767 if (!rate_match(wpa_s, bss)) {
768 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
775 * TODO: skip the AP if its P2P IE has Group Formation
776 * bit set in the P2P Group Capability Bitmap and we
777 * are not in Group Formation with that device.
779 #endif /* CONFIG_P2P */
781 /* Matching configuration found */
785 /* No matching configuration found */
790 static struct wpa_bss *
791 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
792 struct wpa_scan_results *scan_res,
793 struct wpa_ssid *group,
794 struct wpa_ssid **selected_ssid)
798 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
801 for (i = 0; i < scan_res->num; i++) {
802 struct wpa_scan_res *bss = scan_res->res[i];
806 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
810 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
811 ssid = ie ? ie + 2 : (u8 *) "";
812 ssid_len = ie ? ie[1] : 0;
814 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
816 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
817 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
824 static struct wpa_bss *
825 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
826 struct wpa_scan_results *scan_res,
827 struct wpa_ssid **selected_ssid)
829 struct wpa_bss *selected = NULL;
832 while (selected == NULL) {
833 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
834 selected = wpa_supplicant_select_bss(
835 wpa_s, scan_res, wpa_s->conf->pssid[prio],
841 if (selected == NULL && wpa_s->blacklist &&
842 !wpa_s->countermeasures) {
843 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
844 "blacklist and try again");
845 wpa_blacklist_clear(wpa_s);
846 wpa_s->blacklist_cleared++;
847 } else if (selected == NULL)
855 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
856 int timeout_sec, int timeout_usec)
858 if (!wpa_supplicant_enabled_networks(wpa_s)) {
860 * No networks are enabled; short-circuit request so
861 * we don't wait timeout seconds before transitioning
864 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
867 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
871 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
872 struct wpa_bss *selected,
873 struct wpa_ssid *ssid)
875 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
876 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
877 "PBC session overlap");
879 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
881 #endif /* CONFIG_P2P */
884 wpas_wps_cancel(wpa_s);
885 #endif /* CONFIG_WPS */
890 * Do not trigger new association unless the BSSID has changed or if
891 * reassociation is requested. If we are in process of associating with
892 * the selected BSSID, do not trigger new attempt.
894 if (wpa_s->reassociate ||
895 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
896 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
897 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
898 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
900 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
901 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
904 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
905 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
906 " pending: " MACSTR " wpa_state: %s",
907 wpa_s->reassociate, MAC2STR(selected->bssid),
908 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
909 wpa_supplicant_state_txt(wpa_s->wpa_state));
910 wpa_supplicant_associate(wpa_s, selected, ssid);
912 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
920 static struct wpa_ssid *
921 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
924 struct wpa_ssid *ssid;
926 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
927 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
929 if (wpas_network_disabled(wpa_s, ssid))
931 if (ssid->mode == IEEE80211_MODE_IBSS ||
932 ssid->mode == IEEE80211_MODE_AP)
940 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
941 * on BSS added and BSS changed events */
942 static void wpa_supplicant_rsn_preauth_scan_results(
943 struct wpa_supplicant *wpa_s)
947 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
950 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
951 const u8 *ssid, *rsn;
953 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
957 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
961 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
967 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
968 struct wpa_bss *selected,
969 struct wpa_ssid *ssid,
970 struct wpa_scan_results *scan_res)
973 struct wpa_scan_res *current_bss = NULL;
976 if (wpa_s->reassociate)
977 return 1; /* explicit request to reassociate */
978 if (wpa_s->wpa_state < WPA_ASSOCIATED)
979 return 1; /* we are not associated; continue */
980 if (wpa_s->current_ssid == NULL)
981 return 1; /* unknown current SSID */
982 if (wpa_s->current_ssid != ssid)
983 return 1; /* different network block */
985 if (wpas_driver_bss_selection(wpa_s))
986 return 0; /* Driver-based roaming */
988 for (i = 0; i < scan_res->num; i++) {
989 struct wpa_scan_res *res = scan_res->res[i];
991 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
994 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
997 if (ie[1] != wpa_s->current_ssid->ssid_len ||
998 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
1005 return 1; /* current BSS not seen in scan results */
1007 #ifndef CONFIG_NO_ROAMING
1008 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1009 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1010 MAC2STR(current_bss->bssid), current_bss->level);
1011 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1012 MAC2STR(selected->bssid), selected->level);
1014 if (wpa_s->current_ssid->bssid_set &&
1015 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1017 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1018 "has preferred BSSID");
1023 if (current_bss->level < 0) {
1024 if (current_bss->level < -85)
1026 else if (current_bss->level < -80)
1028 else if (current_bss->level < -75)
1030 else if (current_bss->level < -70)
1035 if (abs(current_bss->level - selected->level) < min_diff) {
1036 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1042 #else /* CONFIG_NO_ROAMING */
1044 #endif /* CONFIG_NO_ROAMING */
1048 /* Return < 0 if no scan results could be fetched or if scan results should not
1049 * be shared with other virtual interfaces. */
1050 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1051 union wpa_event_data *data)
1053 struct wpa_bss *selected;
1054 struct wpa_ssid *ssid = NULL;
1055 struct wpa_scan_results *scan_res;
1057 #ifndef CONFIG_NO_RANDOM_POOL
1059 #endif /* CONFIG_NO_RANDOM_POOL */
1062 if (wpa_s->ap_iface)
1064 #endif /* CONFIG_AP */
1066 wpa_supplicant_notify_scanning(wpa_s, 0);
1069 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1070 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
1071 wpa_s->p2p_cb_on_scan_complete = 0;
1072 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1073 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1074 "stopped scan processing");
1078 wpa_s->sta_scan_pending = 0;
1079 #endif /* CONFIG_P2P */
1081 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1082 data ? &data->scan_info :
1084 if (scan_res == NULL) {
1085 if (wpa_s->conf->ap_scan == 2 || ap)
1087 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1089 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1093 #ifndef CONFIG_NO_RANDOM_POOL
1094 num = scan_res->num;
1097 for (i = 0; i < num; i++) {
1099 struct wpa_scan_res *res = scan_res->res[i];
1100 buf[0] = res->bssid[5];
1101 buf[1] = res->qual & 0xff;
1102 buf[2] = res->noise & 0xff;
1103 buf[3] = res->level & 0xff;
1104 buf[4] = res->tsf & 0xff;
1105 random_add_randomness(buf, sizeof(buf));
1107 #endif /* CONFIG_NO_RANDOM_POOL */
1109 if (wpa_s->scan_res_handler) {
1110 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1111 struct wpa_scan_results *scan_res);
1113 scan_res_handler = wpa_s->scan_res_handler;
1114 wpa_s->scan_res_handler = NULL;
1115 scan_res_handler(wpa_s, scan_res);
1117 wpa_scan_results_free(scan_res);
1122 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1124 if (wpa_s->ap_iface->scan_cb)
1125 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1126 #endif /* CONFIG_AP */
1127 wpa_scan_results_free(scan_res);
1131 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1132 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1133 wpas_notify_scan_results(wpa_s);
1135 wpas_notify_scan_done(wpa_s, 1);
1137 if (sme_proc_obss_scan(wpa_s) > 0) {
1138 wpa_scan_results_free(scan_res);
1142 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1143 wpa_scan_results_free(scan_res);
1147 if (autoscan_notify_scan(wpa_s, scan_res)) {
1148 wpa_scan_results_free(scan_res);
1152 if (wpa_s->disconnected) {
1153 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1154 wpa_scan_results_free(scan_res);
1158 if (!wpas_driver_bss_selection(wpa_s) &&
1159 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1160 wpa_scan_results_free(scan_res);
1164 wpas_wps_update_ap_info(wpa_s, scan_res);
1166 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1170 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1172 wpa_scan_results_free(scan_res);
1174 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1178 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1179 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1182 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1184 wpa_scan_results_free(scan_res);
1185 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1186 ssid = wpa_supplicant_pick_new_network(wpa_s);
1188 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1189 wpa_supplicant_associate(wpa_s, NULL, ssid);
1190 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1192 int timeout_sec = wpa_s->scan_interval;
1193 int timeout_usec = 0;
1195 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1198 if (wpa_s->p2p_in_provisioning) {
1200 * Use shorter wait during P2P Provisioning
1201 * state to speed up group formation.
1204 timeout_usec = 250000;
1205 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1209 #endif /* CONFIG_P2P */
1210 #ifdef CONFIG_INTERWORKING
1211 if (wpa_s->conf->auto_interworking &&
1212 wpa_s->conf->interworking &&
1213 wpa_s->conf->cred) {
1214 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1215 "start ANQP fetch since no matching "
1217 wpa_s->network_select = 1;
1218 wpa_s->auto_network_select = 1;
1219 interworking_start_fetch_anqp(wpa_s);
1222 #endif /* CONFIG_INTERWORKING */
1223 if (wpa_supplicant_req_sched_scan(wpa_s))
1224 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1232 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1233 union wpa_event_data *data)
1235 const char *rn, *rn2;
1236 struct wpa_supplicant *ifs;
1238 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1240 * If no scan results could be fetched, then no need to
1241 * notify those interfaces that did not actually request
1248 * Check other interfaces to see if they have the same radio-name. If
1249 * so, they get updated with this same scan info.
1251 if (!wpa_s->driver->get_radio_name)
1254 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1255 if (rn == NULL || rn[0] == '\0')
1258 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1259 "sharing same radio (%s) in event_scan_results", rn);
1261 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1262 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1265 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1266 if (rn2 && os_strcmp(rn, rn2) == 0) {
1267 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1268 "sibling", ifs->ifname);
1269 _wpa_supplicant_event_scan_results(ifs, data);
1274 #endif /* CONFIG_NO_SCAN_PROCESSING */
1279 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1281 struct wpa_supplicant *wpa_s = eloop_ctx;
1283 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1286 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1287 MAC2STR(wpa_s->bssid));
1288 /* TODO: could skip this if normal data traffic has been sent */
1289 /* TODO: Consider using some more appropriate data frame for this */
1291 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1294 if (wpa_s->sme.bss_max_idle_period) {
1296 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1299 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1300 wnm_bss_keep_alive, wpa_s, NULL);
1302 #endif /* CONFIG_SME */
1306 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1307 const u8 *ies, size_t ies_len)
1309 struct ieee802_11_elems elems;
1314 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1318 if (elems.bss_max_idle_period) {
1320 wpa_s->sme.bss_max_idle_period =
1321 WPA_GET_LE16(elems.bss_max_idle_period);
1322 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1323 "TU)%s", wpa_s->sme.bss_max_idle_period,
1324 (elems.bss_max_idle_period[2] & 0x01) ?
1325 " (protected keep-live required)" : "");
1326 if (wpa_s->sme.bss_max_idle_period == 0)
1327 wpa_s->sme.bss_max_idle_period = 1;
1328 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1329 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1330 /* msec times 1000 */
1331 msec = wpa_s->sme.bss_max_idle_period * 1024;
1334 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1335 wnm_bss_keep_alive, wpa_s,
1339 #endif /* CONFIG_SME */
1342 #endif /* CONFIG_WNM */
1345 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1348 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1349 #endif /* CONFIG_WNM */
1353 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1354 union wpa_event_data *data)
1356 int l, len, found = 0, wpa_found, rsn_found;
1359 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1360 if (data->assoc_info.req_ies)
1361 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1362 data->assoc_info.req_ies_len);
1363 if (data->assoc_info.resp_ies) {
1364 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1365 data->assoc_info.resp_ies_len);
1367 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1368 data->assoc_info.resp_ies_len);
1369 #endif /* CONFIG_TDLS */
1371 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1372 data->assoc_info.resp_ies_len);
1373 #endif /* CONFIG_WNM */
1375 if (data->assoc_info.beacon_ies)
1376 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1377 data->assoc_info.beacon_ies,
1378 data->assoc_info.beacon_ies_len);
1379 if (data->assoc_info.freq)
1380 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1381 data->assoc_info.freq);
1383 p = data->assoc_info.req_ies;
1384 l = data->assoc_info.req_ies_len;
1386 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1387 while (p && l >= 2) {
1390 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1394 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1395 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1396 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1397 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1400 wpa_find_assoc_pmkid(wpa_s);
1406 if (!found && data->assoc_info.req_ies)
1407 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1409 #ifdef CONFIG_IEEE80211R
1411 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1413 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1414 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1415 data->assoc_info.resp_ies,
1416 data->assoc_info.resp_ies_len,
1418 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1419 "Reassociation Response failed");
1420 wpa_supplicant_deauthenticate(
1421 wpa_s, WLAN_REASON_INVALID_IE);
1426 p = data->assoc_info.resp_ies;
1427 l = data->assoc_info.resp_ies_len;
1429 #ifdef CONFIG_WPS_STRICT
1430 if (p && wpa_s->current_ssid &&
1431 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1433 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1435 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1436 "include WPS IE in (Re)Association Response");
1440 if (wps_validate_assoc_resp(wps) < 0) {
1442 wpa_supplicant_deauthenticate(
1443 wpa_s, WLAN_REASON_INVALID_IE);
1448 #endif /* CONFIG_WPS_STRICT */
1450 /* Go through the IEs and make a copy of the MDIE, if present. */
1451 while (p && l >= 2) {
1454 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1458 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1459 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1460 wpa_s->sme.ft_used = 1;
1461 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1462 MOBILITY_DOMAIN_ID_LEN);
1468 #endif /* CONFIG_SME */
1470 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1471 data->assoc_info.resp_ies_len);
1472 #endif /* CONFIG_IEEE80211R */
1474 /* WPA/RSN IE from Beacon/ProbeResp */
1475 p = data->assoc_info.beacon_ies;
1476 l = data->assoc_info.beacon_ies_len;
1478 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1480 wpa_found = rsn_found = 0;
1481 while (p && l >= 2) {
1484 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1489 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1490 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1492 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1496 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1498 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1505 if (!wpa_found && data->assoc_info.beacon_ies)
1506 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1507 if (!rsn_found && data->assoc_info.beacon_ies)
1508 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1509 if (wpa_found || rsn_found)
1510 wpa_s->ap_ies_from_associnfo = 1;
1512 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1513 wpa_s->assoc_freq != data->assoc_info.freq) {
1514 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1516 wpa_s->assoc_freq, data->assoc_info.freq);
1517 wpa_supplicant_update_scan_results(wpa_s);
1520 wpa_s->assoc_freq = data->assoc_info.freq;
1526 static struct wpa_bss * wpa_supplicant_get_new_bss(
1527 struct wpa_supplicant *wpa_s, const u8 *bssid)
1529 struct wpa_bss *bss = NULL;
1530 struct wpa_ssid *ssid = wpa_s->current_ssid;
1532 if (ssid->ssid_len > 0)
1533 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1535 bss = wpa_bss_get_bssid(wpa_s, bssid);
1541 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1543 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1545 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1548 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1551 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1552 WPA_IE_VENDOR_TYPE);
1553 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1555 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1556 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1557 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1558 bss_rsn ? 2 + bss_rsn[1] : 0))
1565 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1566 union wpa_event_data *data)
1570 struct wpa_driver_capa capa;
1573 if (wpa_s->ap_iface) {
1574 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1575 data->assoc_info.addr,
1576 data->assoc_info.req_ies,
1577 data->assoc_info.req_ies_len,
1578 data->assoc_info.reassoc);
1581 #endif /* CONFIG_AP */
1583 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1584 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1587 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1588 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1589 wpa_supplicant_disassociate(
1590 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1594 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1595 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1596 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1597 MACSTR, MAC2STR(bssid));
1598 random_add_randomness(bssid, ETH_ALEN);
1599 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1600 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1601 wpas_notify_bssid_changed(wpa_s);
1603 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1604 wpa_clear_keys(wpa_s, bssid);
1606 if (wpa_supplicant_select_config(wpa_s) < 0) {
1607 wpa_supplicant_disassociate(
1608 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1611 if (wpa_s->current_ssid) {
1612 struct wpa_bss *bss = NULL;
1614 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1616 wpa_supplicant_update_scan_results(wpa_s);
1618 /* Get the BSS from the new scan results */
1619 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1623 wpa_s->current_bss = bss;
1626 if (wpa_s->conf->ap_scan == 1 &&
1627 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1628 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1629 wpa_msg(wpa_s, MSG_WARNING,
1630 "WPA/RSN IEs not updated");
1635 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1636 wpa_s->sme.prev_bssid_set = 1;
1637 #endif /* CONFIG_SME */
1639 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1640 if (wpa_s->current_ssid) {
1641 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1642 * initialized before association, but for other modes,
1643 * initialize PC/SC here, if the current configuration needs
1644 * smartcard or SIM/USIM. */
1645 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1647 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1649 l2_packet_notify_auth_start(wpa_s->l2);
1652 * Set portEnabled first to FALSE in order to get EAP state machine out
1653 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1654 * state machine may transit to AUTHENTICATING state based on obsolete
1655 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1656 * AUTHENTICATED without ever giving chance to EAP state machine to
1659 if (!ft_completed) {
1660 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1661 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1663 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1664 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1665 /* 802.1X::portControl = Auto */
1666 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1667 wpa_s->eapol_received = 0;
1668 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1669 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1670 (wpa_s->current_ssid &&
1671 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1672 wpa_supplicant_cancel_auth_timeout(wpa_s);
1673 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1674 } else if (!ft_completed) {
1675 /* Timeout for receiving the first EAPOL packet */
1676 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1678 wpa_supplicant_cancel_scan(wpa_s);
1680 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1681 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1683 * We are done; the driver will take care of RSN 4-way
1686 wpa_supplicant_cancel_auth_timeout(wpa_s);
1687 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1688 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1689 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1690 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1691 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1693 * The driver will take care of RSN 4-way handshake, so we need
1694 * to allow EAPOL supplicant to complete its work without
1695 * waiting for WPA supplicant.
1697 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1698 } else if (ft_completed) {
1700 * FT protocol completed - make sure EAPOL state machine ends
1701 * up in authenticated.
1703 wpa_supplicant_cancel_auth_timeout(wpa_s);
1704 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1705 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1706 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1709 if (wpa_s->pending_eapol_rx) {
1710 struct os_time now, age;
1712 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1713 if (age.sec == 0 && age.usec < 100000 &&
1714 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1716 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1717 "frame that was received just before "
1718 "association notification");
1719 wpa_supplicant_rx_eapol(
1720 wpa_s, wpa_s->pending_eapol_rx_src,
1721 wpabuf_head(wpa_s->pending_eapol_rx),
1722 wpabuf_len(wpa_s->pending_eapol_rx));
1724 wpabuf_free(wpa_s->pending_eapol_rx);
1725 wpa_s->pending_eapol_rx = NULL;
1728 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1729 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1730 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1731 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1732 /* Set static WEP keys again */
1733 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1736 #ifdef CONFIG_IBSS_RSN
1737 if (wpa_s->current_ssid &&
1738 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1739 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1740 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1741 wpa_s->ibss_rsn == NULL) {
1742 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1743 if (!wpa_s->ibss_rsn) {
1744 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1745 wpa_supplicant_deauthenticate(
1746 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1750 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1752 #endif /* CONFIG_IBSS_RSN */
1754 wpas_wps_notify_assoc(wpa_s, bssid);
1758 static int disconnect_reason_recoverable(u16 reason_code)
1760 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1761 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1762 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1766 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1768 int locally_generated)
1772 u8 prev_pending_bssid[ETH_ALEN];
1773 struct wpa_bss *fast_reconnect = NULL;
1774 struct wpa_ssid *fast_reconnect_ssid = NULL;
1776 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1777 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1779 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1781 * At least Host AP driver and a Prism3 card seemed to be
1782 * generating streams of disconnected events when configuring
1783 * IBSS for WPA-None. Ignore them for now.
1785 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1786 "IBSS/WPA-None mode");
1790 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1791 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1792 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1793 "pre-shared key may be incorrect");
1794 wpas_auth_failed(wpa_s);
1796 if (!wpa_s->auto_reconnect_disabled ||
1797 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1798 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1799 "reconnect (wps=%d wpa_state=%d)",
1800 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1802 if (wpa_s->wpa_state == WPA_COMPLETED &&
1803 wpa_s->current_ssid &&
1804 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1805 !locally_generated &&
1806 disconnect_reason_recoverable(reason_code)) {
1808 * It looks like the AP has dropped association with
1809 * us, but could allow us to get back in. Try to
1810 * reconnect to the same BSS without full scan to save
1811 * time for some common cases.
1813 fast_reconnect = wpa_s->current_bss;
1814 fast_reconnect_ssid = wpa_s->current_ssid;
1815 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1816 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1818 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1821 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1822 "try to re-connect");
1823 wpa_s->reassociate = 0;
1824 wpa_s->disconnected = 1;
1825 wpa_supplicant_cancel_sched_scan(wpa_s);
1827 bssid = wpa_s->bssid;
1828 if (is_zero_ether_addr(bssid))
1829 bssid = wpa_s->pending_bssid;
1830 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1831 wpas_connection_failed(wpa_s, bssid);
1832 wpa_sm_notify_disassoc(wpa_s->wpa);
1833 if (locally_generated)
1834 wpa_s->disconnect_reason = -reason_code;
1836 wpa_s->disconnect_reason = reason_code;
1837 wpas_notify_disconnect_reason(wpa_s);
1838 if (!is_zero_ether_addr(bssid) ||
1839 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1840 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1842 MAC2STR(bssid), reason_code,
1843 locally_generated ? " locally_generated=1" : "");
1845 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1846 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1847 wpa_s->keys_cleared = 0;
1848 wpa_clear_keys(wpa_s, wpa_s->bssid);
1850 wpa_supplicant_mark_disassoc(wpa_s);
1852 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1853 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1855 if (fast_reconnect) {
1856 #ifndef CONFIG_NO_SCAN_PROCESSING
1857 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1858 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1859 fast_reconnect_ssid) < 0) {
1860 /* Recover through full scan */
1861 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1863 #endif /* CONFIG_NO_SCAN_PROCESSING */
1868 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1869 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1871 struct wpa_supplicant *wpa_s = eloop_ctx;
1873 if (!wpa_s->pending_mic_error_report)
1876 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1877 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1878 wpa_s->pending_mic_error_report = 0;
1880 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1884 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1885 union wpa_event_data *data)
1890 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1891 pairwise = (data && data->michael_mic_failure.unicast);
1893 if ((wpa_s->last_michael_mic_error &&
1894 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1895 wpa_s->pending_mic_error_report) {
1896 if (wpa_s->pending_mic_error_report) {
1898 * Send the pending MIC error report immediately since
1899 * we are going to start countermeasures and AP better
1902 wpa_sm_key_request(wpa_s->wpa, 1,
1903 wpa_s->pending_mic_error_pairwise);
1906 /* Send the new MIC error report immediately since we are going
1907 * to start countermeasures and AP better do the same.
1909 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1911 /* initialize countermeasures */
1912 wpa_s->countermeasures = 1;
1914 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1916 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1919 * Need to wait for completion of request frame. We do not get
1920 * any callback for the message completion, so just wait a
1921 * short while and hope for the best. */
1924 wpa_drv_set_countermeasures(wpa_s, 1);
1925 wpa_supplicant_deauthenticate(wpa_s,
1926 WLAN_REASON_MICHAEL_MIC_FAILURE);
1927 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1929 eloop_register_timeout(60, 0,
1930 wpa_supplicant_stop_countermeasures,
1932 /* TODO: mark the AP rejected for 60 second. STA is
1933 * allowed to associate with another AP.. */
1935 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1936 if (wpa_s->mic_errors_seen) {
1938 * Reduce the effectiveness of Michael MIC error
1939 * reports as a means for attacking against TKIP if
1940 * more than one MIC failure is noticed with the same
1941 * PTK. We delay the transmission of the reports by a
1942 * random time between 0 and 60 seconds in order to
1943 * force the attacker wait 60 seconds before getting
1944 * the information on whether a frame resulted in a MIC
1950 if (os_get_random(rval, sizeof(rval)) < 0)
1951 sec = os_random() % 60;
1953 sec = WPA_GET_BE32(rval) % 60;
1954 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1955 "report %d seconds", sec);
1956 wpa_s->pending_mic_error_report = 1;
1957 wpa_s->pending_mic_error_pairwise = pairwise;
1958 eloop_cancel_timeout(
1959 wpa_supplicant_delayed_mic_error_report,
1961 eloop_register_timeout(
1962 sec, os_random() % 1000000,
1963 wpa_supplicant_delayed_mic_error_report,
1966 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1968 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1969 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1970 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1972 wpa_s->last_michael_mic_error = t.sec;
1973 wpa_s->mic_errors_seen++;
1977 #ifdef CONFIG_TERMINATE_ONLASTIF
1978 static int any_interfaces(struct wpa_supplicant *head)
1980 struct wpa_supplicant *wpa_s;
1982 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1983 if (!wpa_s->interface_removed)
1987 #endif /* CONFIG_TERMINATE_ONLASTIF */
1991 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1992 union wpa_event_data *data)
1994 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1997 switch (data->interface_status.ievent) {
1998 case EVENT_INTERFACE_ADDED:
1999 if (!wpa_s->interface_removed)
2001 wpa_s->interface_removed = 0;
2002 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2003 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2004 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2005 "driver after interface was added");
2007 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2009 case EVENT_INTERFACE_REMOVED:
2010 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2011 wpa_s->interface_removed = 1;
2012 wpa_supplicant_mark_disassoc(wpa_s);
2013 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2014 l2_packet_deinit(wpa_s->l2);
2016 #ifdef CONFIG_IBSS_RSN
2017 ibss_rsn_deinit(wpa_s->ibss_rsn);
2018 wpa_s->ibss_rsn = NULL;
2019 #endif /* CONFIG_IBSS_RSN */
2020 #ifdef CONFIG_TERMINATE_ONLASTIF
2021 /* check if last interface */
2022 if (!any_interfaces(wpa_s->global->ifaces))
2024 #endif /* CONFIG_TERMINATE_ONLASTIF */
2030 #ifdef CONFIG_PEERKEY
2032 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2033 union wpa_event_data *data)
2037 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2039 #endif /* CONFIG_PEERKEY */
2043 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2044 union wpa_event_data *data)
2048 switch (data->tdls.oper) {
2049 case TDLS_REQUEST_SETUP:
2050 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2052 case TDLS_REQUEST_TEARDOWN:
2053 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2054 data->tdls.reason_code);
2058 #endif /* CONFIG_TDLS */
2061 #ifdef CONFIG_IEEE80211V
2062 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2063 union wpa_event_data *data)
2067 switch (data->wnm.oper) {
2068 case WNM_OPER_SLEEP:
2069 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2070 "(action=%d, intval=%d)",
2071 data->wnm.sleep_action, data->wnm.sleep_intval);
2072 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2073 data->wnm.sleep_intval);
2077 #endif /* CONFIG_IEEE80211V */
2080 #ifdef CONFIG_IEEE80211R
2082 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2083 union wpa_event_data *data)
2088 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2089 data->ft_ies.ies_len,
2090 data->ft_ies.ft_action,
2091 data->ft_ies.target_ap,
2092 data->ft_ies.ric_ies,
2093 data->ft_ies.ric_ies_len) < 0) {
2094 /* TODO: prevent MLME/driver from trying to associate? */
2097 #endif /* CONFIG_IEEE80211R */
2100 #ifdef CONFIG_IBSS_RSN
2101 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2102 union wpa_event_data *data)
2104 struct wpa_ssid *ssid;
2105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2109 ssid = wpa_s->current_ssid;
2112 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2115 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2117 #endif /* CONFIG_IBSS_RSN */
2120 #ifdef CONFIG_IEEE80211R
2121 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2124 const u8 *sta_addr, *target_ap_addr;
2127 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2128 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2129 return; /* only SME case supported for now */
2130 if (len < 1 + 2 * ETH_ALEN + 2)
2133 return; /* Only FT Action Response is supported for now */
2134 sta_addr = data + 1;
2135 target_ap_addr = data + 1 + ETH_ALEN;
2136 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2137 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2138 MACSTR " TargetAP " MACSTR " status %u",
2139 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2141 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2142 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2143 " in FT Action Response", MAC2STR(sta_addr));
2148 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2149 "failure (status code %d)", status);
2150 /* TODO: report error to FT code(?) */
2154 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2155 len - (1 + 2 * ETH_ALEN + 2), 1,
2156 target_ap_addr, NULL, 0) < 0)
2161 struct wpa_bss *bss;
2162 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2164 wpa_s->sme.freq = bss->freq;
2165 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2166 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2169 #endif /* CONFIG_SME */
2171 #endif /* CONFIG_IEEE80211R */
2174 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2175 struct unprot_deauth *e)
2177 #ifdef CONFIG_IEEE80211W
2178 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2179 "dropped: " MACSTR " -> " MACSTR
2180 " (reason code %u)",
2181 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2182 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2183 #endif /* CONFIG_IEEE80211W */
2187 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2188 struct unprot_disassoc *e)
2190 #ifdef CONFIG_IEEE80211W
2191 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2192 "dropped: " MACSTR " -> " MACSTR
2193 " (reason code %u)",
2194 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2195 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2196 #endif /* CONFIG_IEEE80211W */
2200 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2203 const u8 *pos, *end;
2205 if (rx->data == NULL || rx->len == 0)
2209 end = pos + rx->len;
2212 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2213 action, MAC2STR(rx->sa));
2215 case WNM_BSS_TRANS_MGMT_REQ:
2218 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2219 "Request: dialog_token=%u request_mode=0x%x "
2220 "disassoc_timer=%u validity_interval=%u",
2221 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2225 pos += 12; /* BSS Termination Duration */
2228 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2229 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2230 "Transition Management Request "
2234 os_memcpy(url, pos + 1, pos[0]);
2236 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2237 "Imminent - session_info_url=%s", url);
2244 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2245 union wpa_event_data *data)
2247 struct wpa_supplicant *wpa_s = ctx;
2248 u16 reason_code = 0;
2249 int locally_generated = 0;
2251 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2252 event != EVENT_INTERFACE_ENABLED &&
2253 event != EVENT_INTERFACE_STATUS &&
2254 event != EVENT_SCHED_SCAN_STOPPED) {
2255 wpa_dbg(wpa_s, MSG_DEBUG,
2256 "Ignore event %s (%d) while interface is disabled",
2257 event_to_string(event), event);
2261 #ifndef CONFIG_NO_STDOUT_DEBUG
2263 int level = MSG_DEBUG;
2265 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2266 const struct ieee80211_hdr *hdr;
2268 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2269 fc = le_to_host16(hdr->frame_control);
2270 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2271 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2272 level = MSG_EXCESSIVE;
2275 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2276 event_to_string(event), event);
2278 #endif /* CONFIG_NO_STDOUT_DEBUG */
2282 sme_event_auth(wpa_s, data);
2285 wpa_supplicant_event_assoc(wpa_s, data);
2287 case EVENT_DISASSOC:
2288 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2290 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2291 data->disassoc_info.reason_code,
2292 data->disassoc_info.locally_generated ?
2293 " (locally generated)" : "");
2294 if (data->disassoc_info.addr)
2295 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2296 MAC2STR(data->disassoc_info.addr));
2299 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2300 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2301 data->disassoc_info.addr);
2304 if (wpa_s->ap_iface) {
2305 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2309 #endif /* CONFIG_AP */
2311 reason_code = data->disassoc_info.reason_code;
2313 data->disassoc_info.locally_generated;
2314 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2315 data->disassoc_info.ie,
2316 data->disassoc_info.ie_len);
2318 wpas_p2p_disassoc_notif(
2319 wpa_s, data->disassoc_info.addr, reason_code,
2320 data->disassoc_info.ie,
2321 data->disassoc_info.ie_len,
2323 #endif /* CONFIG_P2P */
2325 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2326 sme_event_disassoc(wpa_s, data);
2329 if (event == EVENT_DEAUTH) {
2330 wpa_dbg(wpa_s, MSG_DEBUG,
2331 "Deauthentication notification");
2333 reason_code = data->deauth_info.reason_code;
2335 data->deauth_info.locally_generated;
2336 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2337 data->deauth_info.reason_code,
2338 data->deauth_info.locally_generated ?
2339 " (locally generated)" : "");
2340 if (data->deauth_info.addr) {
2341 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2343 MAC2STR(data->deauth_info.
2346 wpa_hexdump(MSG_DEBUG,
2347 "Deauthentication frame IE(s)",
2348 data->deauth_info.ie,
2349 data->deauth_info.ie_len);
2353 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2354 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2355 data->deauth_info.addr);
2358 if (wpa_s->ap_iface) {
2359 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2363 #endif /* CONFIG_AP */
2364 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2366 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2367 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2368 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2369 eapol_sm_failed(wpa_s->eapol)))
2370 wpas_auth_failed(wpa_s);
2372 if (event == EVENT_DEAUTH && data) {
2373 wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
2375 data->deauth_info.ie,
2376 data->deauth_info.ie_len,
2379 #endif /* CONFIG_P2P */
2381 case EVENT_MICHAEL_MIC_FAILURE:
2382 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2384 #ifndef CONFIG_NO_SCAN_PROCESSING
2385 case EVENT_SCAN_RESULTS:
2386 wpa_supplicant_event_scan_results(wpa_s, data);
2388 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2389 wpa_s->global->p2p != NULL &&
2390 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2391 wpa_s->wpa_state != WPA_ASSOCIATING) {
2392 wpa_s->p2p_cb_on_scan_complete = 0;
2393 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2394 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2395 "continued after scan result processing");
2398 #endif /* CONFIG_P2P */
2400 #endif /* CONFIG_NO_SCAN_PROCESSING */
2401 case EVENT_ASSOCINFO:
2402 wpa_supplicant_event_associnfo(wpa_s, data);
2404 case EVENT_INTERFACE_STATUS:
2405 wpa_supplicant_event_interface_status(wpa_s, data);
2407 case EVENT_PMKID_CANDIDATE:
2408 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2410 #ifdef CONFIG_PEERKEY
2411 case EVENT_STKSTART:
2412 wpa_supplicant_event_stkstart(wpa_s, data);
2414 #endif /* CONFIG_PEERKEY */
2417 wpa_supplicant_event_tdls(wpa_s, data);
2419 #endif /* CONFIG_TDLS */
2420 #ifdef CONFIG_IEEE80211V
2422 wpa_supplicant_event_wnm(wpa_s, data);
2424 #endif /* CONFIG_IEEE80211V */
2425 #ifdef CONFIG_IEEE80211R
2426 case EVENT_FT_RESPONSE:
2427 wpa_supplicant_event_ft_response(wpa_s, data);
2429 #endif /* CONFIG_IEEE80211R */
2430 #ifdef CONFIG_IBSS_RSN
2431 case EVENT_IBSS_RSN_START:
2432 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2434 #endif /* CONFIG_IBSS_RSN */
2435 case EVENT_ASSOC_REJECT:
2436 if (data->assoc_reject.bssid)
2437 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2438 "bssid=" MACSTR " status_code=%u",
2439 MAC2STR(data->assoc_reject.bssid),
2440 data->assoc_reject.status_code);
2442 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2444 data->assoc_reject.status_code);
2445 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2446 sme_event_assoc_reject(wpa_s, data);
2448 case EVENT_AUTH_TIMED_OUT:
2449 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2450 sme_event_auth_timed_out(wpa_s, data);
2452 case EVENT_ASSOC_TIMED_OUT:
2453 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2454 sme_event_assoc_timed_out(wpa_s, data);
2456 case EVENT_TX_STATUS:
2457 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2458 " type=%d stype=%d",
2459 MAC2STR(data->tx_status.dst),
2460 data->tx_status.type, data->tx_status.stype);
2462 if (wpa_s->ap_iface == NULL) {
2463 #ifdef CONFIG_OFFCHANNEL
2464 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2465 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2466 offchannel_send_action_tx_status(
2467 wpa_s, data->tx_status.dst,
2468 data->tx_status.data,
2469 data->tx_status.data_len,
2470 data->tx_status.ack ?
2471 OFFCHANNEL_SEND_ACTION_SUCCESS :
2472 OFFCHANNEL_SEND_ACTION_NO_ACK);
2473 #endif /* CONFIG_OFFCHANNEL */
2476 #endif /* CONFIG_AP */
2477 #ifdef CONFIG_OFFCHANNEL
2478 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2479 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2481 * Catch TX status events for Action frames we sent via group
2482 * interface in GO mode.
2484 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2485 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2486 os_memcmp(wpa_s->parent->pending_action_dst,
2487 data->tx_status.dst, ETH_ALEN) == 0) {
2488 offchannel_send_action_tx_status(
2489 wpa_s->parent, data->tx_status.dst,
2490 data->tx_status.data,
2491 data->tx_status.data_len,
2492 data->tx_status.ack ?
2493 OFFCHANNEL_SEND_ACTION_SUCCESS :
2494 OFFCHANNEL_SEND_ACTION_NO_ACK);
2497 #endif /* CONFIG_OFFCHANNEL */
2499 switch (data->tx_status.type) {
2500 case WLAN_FC_TYPE_MGMT:
2501 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2502 data->tx_status.data_len,
2503 data->tx_status.stype,
2504 data->tx_status.ack);
2506 case WLAN_FC_TYPE_DATA:
2507 ap_tx_status(wpa_s, data->tx_status.dst,
2508 data->tx_status.data,
2509 data->tx_status.data_len,
2510 data->tx_status.ack);
2513 #endif /* CONFIG_AP */
2516 case EVENT_EAPOL_TX_STATUS:
2517 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2518 data->eapol_tx_status.data,
2519 data->eapol_tx_status.data_len,
2520 data->eapol_tx_status.ack);
2522 case EVENT_DRIVER_CLIENT_POLL_OK:
2523 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2525 case EVENT_RX_FROM_UNKNOWN:
2526 if (wpa_s->ap_iface == NULL)
2528 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2529 data->rx_from_unknown.wds);
2531 case EVENT_CH_SWITCH:
2534 if (!wpa_s->ap_iface) {
2535 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2536 "event in non-AP mode");
2541 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2542 data->ch_switch.ht_enabled,
2543 data->ch_switch.ch_offset);
2544 #endif /* CONFIG_AP */
2546 case EVENT_RX_MGMT: {
2548 const struct ieee80211_mgmt *mgmt;
2550 mgmt = (const struct ieee80211_mgmt *)
2551 data->rx_mgmt.frame;
2552 fc = le_to_host16(mgmt->frame_control);
2553 stype = WLAN_FC_GET_STYPE(fc);
2555 if (wpa_s->ap_iface == NULL) {
2557 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2558 data->rx_mgmt.frame_len > 24) {
2559 const u8 *src = mgmt->sa;
2560 const u8 *ie = mgmt->u.probe_req.variable;
2561 size_t ie_len = data->rx_mgmt.frame_len -
2562 (mgmt->u.probe_req.variable -
2563 data->rx_mgmt.frame);
2564 wpas_p2p_probe_req_rx(
2565 wpa_s, src, mgmt->da,
2566 mgmt->bssid, ie, ie_len,
2567 data->rx_mgmt.ssi_signal);
2570 #endif /* CONFIG_P2P */
2571 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2572 "management frame in non-AP mode");
2576 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2577 data->rx_mgmt.frame_len > 24) {
2578 const u8 *ie = mgmt->u.probe_req.variable;
2579 size_t ie_len = data->rx_mgmt.frame_len -
2580 (mgmt->u.probe_req.variable -
2581 data->rx_mgmt.frame);
2583 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2584 mgmt->bssid, ie, ie_len,
2585 data->rx_mgmt.ssi_signal);
2588 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2591 #endif /* CONFIG_AP */
2592 case EVENT_RX_ACTION:
2593 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2594 " Category=%u DataLen=%d freq=%d MHz",
2595 MAC2STR(data->rx_action.sa),
2596 data->rx_action.category, (int) data->rx_action.len,
2597 data->rx_action.freq);
2598 #ifdef CONFIG_IEEE80211R
2599 if (data->rx_action.category == WLAN_ACTION_FT) {
2600 ft_rx_action(wpa_s, data->rx_action.data,
2601 data->rx_action.len);
2604 #endif /* CONFIG_IEEE80211R */
2605 #ifdef CONFIG_IEEE80211W
2607 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2608 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2609 data->rx_action.data,
2610 data->rx_action.len);
2613 #endif /* CONFIG_SME */
2614 #endif /* CONFIG_IEEE80211W */
2615 #ifdef CONFIG_IEEE80211V
2616 if (data->rx_action.category == WLAN_ACTION_WNM) {
2617 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2620 #endif /* CONFIG_IEEE80211V */
2622 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2623 gas_query_rx(wpa_s->gas, data->rx_action.da,
2624 data->rx_action.sa, data->rx_action.bssid,
2625 data->rx_action.data, data->rx_action.len,
2626 data->rx_action.freq) == 0)
2628 #endif /* CONFIG_GAS */
2629 if (data->rx_action.category == WLAN_ACTION_WNM) {
2630 wnm_action_rx(wpa_s, &data->rx_action);
2634 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2635 data->rx_action.len >= 4 &&
2636 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2637 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2638 "Response from " MACSTR,
2639 MAC2STR(data->rx_action.sa));
2642 #endif /* CONFIG_TDLS */
2644 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2646 data->rx_action.bssid,
2647 data->rx_action.category,
2648 data->rx_action.data,
2649 data->rx_action.len, data->rx_action.freq);
2650 #endif /* CONFIG_P2P */
2652 case EVENT_RX_PROBE_REQ:
2653 if (data->rx_probe_req.sa == NULL ||
2654 data->rx_probe_req.ie == NULL)
2657 if (wpa_s->ap_iface) {
2658 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2659 data->rx_probe_req.sa,
2660 data->rx_probe_req.da,
2661 data->rx_probe_req.bssid,
2662 data->rx_probe_req.ie,
2663 data->rx_probe_req.ie_len,
2664 data->rx_probe_req.ssi_signal);
2667 #endif /* CONFIG_AP */
2669 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2670 data->rx_probe_req.da,
2671 data->rx_probe_req.bssid,
2672 data->rx_probe_req.ie,
2673 data->rx_probe_req.ie_len,
2674 data->rx_probe_req.ssi_signal);
2675 #endif /* CONFIG_P2P */
2677 case EVENT_REMAIN_ON_CHANNEL:
2678 #ifdef CONFIG_OFFCHANNEL
2679 offchannel_remain_on_channel_cb(
2680 wpa_s, data->remain_on_channel.freq,
2681 data->remain_on_channel.duration);
2682 #endif /* CONFIG_OFFCHANNEL */
2684 wpas_p2p_remain_on_channel_cb(
2685 wpa_s, data->remain_on_channel.freq,
2686 data->remain_on_channel.duration);
2687 #endif /* CONFIG_P2P */
2689 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2690 #ifdef CONFIG_OFFCHANNEL
2691 offchannel_cancel_remain_on_channel_cb(
2692 wpa_s, data->remain_on_channel.freq);
2693 #endif /* CONFIG_OFFCHANNEL */
2695 wpas_p2p_cancel_remain_on_channel_cb(
2696 wpa_s, data->remain_on_channel.freq);
2697 #endif /* CONFIG_P2P */
2700 case EVENT_P2P_DEV_FOUND: {
2701 struct p2p_peer_info peer_info;
2703 os_memset(&peer_info, 0, sizeof(peer_info));
2704 if (data->p2p_dev_found.dev_addr)
2705 os_memcpy(peer_info.p2p_device_addr,
2706 data->p2p_dev_found.dev_addr, ETH_ALEN);
2707 if (data->p2p_dev_found.pri_dev_type)
2708 os_memcpy(peer_info.pri_dev_type,
2709 data->p2p_dev_found.pri_dev_type,
2710 sizeof(peer_info.pri_dev_type));
2711 if (data->p2p_dev_found.dev_name)
2712 os_strlcpy(peer_info.device_name,
2713 data->p2p_dev_found.dev_name,
2714 sizeof(peer_info.device_name));
2715 peer_info.config_methods = data->p2p_dev_found.config_methods;
2716 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2717 peer_info.group_capab = data->p2p_dev_found.group_capab;
2720 * FIX: new_device=1 is not necessarily correct. We should
2721 * maintain a P2P peer database in wpa_supplicant and update
2722 * this information based on whether the peer is truly new.
2724 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2727 case EVENT_P2P_GO_NEG_REQ_RX:
2728 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2729 data->p2p_go_neg_req_rx.dev_passwd_id);
2731 case EVENT_P2P_GO_NEG_COMPLETED:
2732 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2734 case EVENT_P2P_PROV_DISC_REQUEST:
2735 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2736 data->p2p_prov_disc_req.config_methods,
2737 data->p2p_prov_disc_req.dev_addr,
2738 data->p2p_prov_disc_req.pri_dev_type,
2739 data->p2p_prov_disc_req.dev_name,
2740 data->p2p_prov_disc_req.supp_config_methods,
2741 data->p2p_prov_disc_req.dev_capab,
2742 data->p2p_prov_disc_req.group_capab,
2745 case EVENT_P2P_PROV_DISC_RESPONSE:
2746 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2747 data->p2p_prov_disc_resp.config_methods);
2749 case EVENT_P2P_SD_REQUEST:
2750 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2751 data->p2p_sd_req.sa,
2752 data->p2p_sd_req.dialog_token,
2753 data->p2p_sd_req.update_indic,
2754 data->p2p_sd_req.tlvs,
2755 data->p2p_sd_req.tlvs_len);
2757 case EVENT_P2P_SD_RESPONSE:
2758 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2759 data->p2p_sd_resp.update_indic,
2760 data->p2p_sd_resp.tlvs,
2761 data->p2p_sd_resp.tlvs_len);
2763 #endif /* CONFIG_P2P */
2764 case EVENT_EAPOL_RX:
2765 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2766 data->eapol_rx.data,
2767 data->eapol_rx.data_len);
2769 case EVENT_SIGNAL_CHANGE:
2770 bgscan_notify_signal_change(
2771 wpa_s, data->signal_change.above_threshold,
2772 data->signal_change.current_signal,
2773 data->signal_change.current_noise,
2774 data->signal_change.current_txrate);
2776 case EVENT_INTERFACE_ENABLED:
2777 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2778 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2779 wpa_supplicant_update_mac_addr(wpa_s);
2781 if (!wpa_s->ap_iface) {
2782 wpa_supplicant_set_state(wpa_s,
2784 wpa_supplicant_req_scan(wpa_s, 0, 0);
2786 wpa_supplicant_set_state(wpa_s,
2788 #else /* CONFIG_AP */
2789 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2790 wpa_supplicant_req_scan(wpa_s, 0, 0);
2791 #endif /* CONFIG_AP */
2794 case EVENT_INTERFACE_DISABLED:
2795 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2796 wpa_supplicant_mark_disassoc(wpa_s);
2797 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2799 case EVENT_CHANNEL_LIST_CHANGED:
2800 if (wpa_s->drv_priv == NULL)
2801 break; /* Ignore event during drv initialization */
2803 free_hw_features(wpa_s);
2804 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2805 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2808 wpas_p2p_update_channel_list(wpa_s);
2809 #endif /* CONFIG_P2P */
2811 case EVENT_INTERFACE_UNAVAILABLE:
2813 wpas_p2p_interface_unavailable(wpa_s);
2814 #endif /* CONFIG_P2P */
2816 case EVENT_BEST_CHANNEL:
2817 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2819 data->best_chan.freq_24, data->best_chan.freq_5,
2820 data->best_chan.freq_overall);
2821 wpa_s->best_24_freq = data->best_chan.freq_24;
2822 wpa_s->best_5_freq = data->best_chan.freq_5;
2823 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2825 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2826 data->best_chan.freq_5,
2827 data->best_chan.freq_overall);
2828 #endif /* CONFIG_P2P */
2830 case EVENT_UNPROT_DEAUTH:
2831 wpa_supplicant_event_unprot_deauth(wpa_s,
2832 &data->unprot_deauth);
2834 case EVENT_UNPROT_DISASSOC:
2835 wpa_supplicant_event_unprot_disassoc(wpa_s,
2836 &data->unprot_disassoc);
2838 case EVENT_STATION_LOW_ACK:
2840 if (wpa_s->ap_iface && data)
2841 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2842 data->low_ack.addr);
2843 #endif /* CONFIG_AP */
2846 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2847 #endif /* CONFIG_TDLS */
2849 case EVENT_IBSS_PEER_LOST:
2850 #ifdef CONFIG_IBSS_RSN
2851 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2852 #endif /* CONFIG_IBSS_RSN */
2854 case EVENT_DRIVER_GTK_REKEY:
2855 if (os_memcmp(data->driver_gtk_rekey.bssid,
2856 wpa_s->bssid, ETH_ALEN))
2860 wpa_sm_update_replay_ctr(wpa_s->wpa,
2861 data->driver_gtk_rekey.replay_ctr);
2863 case EVENT_SCHED_SCAN_STOPPED:
2864 wpa_s->sched_scanning = 0;
2865 wpa_supplicant_notify_scanning(wpa_s, 0);
2867 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2871 * If we timed out, start a new sched scan to continue
2872 * searching for more SSIDs.
2874 if (wpa_s->sched_scan_timed_out)
2875 wpa_supplicant_req_sched_scan(wpa_s);
2877 case EVENT_WPS_BUTTON_PUSHED:
2879 wpas_wps_start_pbc(wpa_s, NULL, 0);
2880 #endif /* CONFIG_WPS */
2883 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);