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"
27 #include "common/ieee802_11_defs.h"
28 #include "common/ieee802_11_common.h"
29 #include "crypto/random.h"
30 #include "blacklist.h"
31 #include "wpas_glue.h"
32 #include "wps_supplicant.h"
35 #include "gas_query.h"
36 #include "p2p_supplicant.h"
42 #include "offchannel.h"
45 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
47 struct wpa_ssid *ssid, *old_ssid;
49 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
52 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
54 ssid = wpa_supplicant_get_ssid(wpa_s);
56 wpa_msg(wpa_s, MSG_INFO,
57 "No network configuration found for the current AP");
61 if (wpas_network_disabled(wpa_s, ssid)) {
62 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
66 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
68 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
70 size_t wpa_ie_len = sizeof(wpa_ie);
71 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
74 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
77 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
78 eapol_sm_invalidate_cached_session(wpa_s->eapol);
79 old_ssid = wpa_s->current_ssid;
80 wpa_s->current_ssid = ssid;
81 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
82 wpa_supplicant_initiate_eapol(wpa_s);
83 if (old_ssid != wpa_s->current_ssid)
84 wpas_notify_network_changed(wpa_s);
90 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
92 struct wpa_supplicant *wpa_s = eloop_ctx;
94 if (wpa_s->countermeasures) {
95 wpa_s->countermeasures = 0;
96 wpa_drv_set_countermeasures(wpa_s, 0);
97 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
98 wpa_supplicant_req_scan(wpa_s, 0, 0);
103 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
107 wnm_bss_keep_alive_deinit(wpa_s);
109 #ifdef CONFIG_IBSS_RSN
110 ibss_rsn_deinit(wpa_s->ibss_rsn);
111 wpa_s->ibss_rsn = NULL;
112 #endif /* CONFIG_IBSS_RSN */
115 wpa_supplicant_ap_deinit(wpa_s);
116 #endif /* CONFIG_AP */
118 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
121 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
123 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
125 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
126 os_memset(wpa_s->bssid, 0, ETH_ALEN);
127 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
129 wpa_s->sme.prev_bssid_set = 0;
130 #endif /* CONFIG_SME */
132 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
133 #endif /* CONFIG_P2P */
134 wpa_s->current_bss = NULL;
135 wpa_s->assoc_freq = 0;
136 #ifdef CONFIG_IEEE80211R
138 if (wpa_s->sme.ft_ies)
139 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
140 #endif /* CONFIG_SME */
141 #endif /* CONFIG_IEEE80211R */
144 wpas_notify_bssid_changed(wpa_s);
146 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
147 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
148 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
149 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
150 wpa_s->ap_ies_from_associnfo = 0;
154 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
156 struct wpa_ie_data ie;
160 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
164 for (i = 0; i < ie.num_pmkid; i++) {
165 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
166 ie.pmkid + i * PMKID_LEN,
168 if (pmksa_set == 0) {
169 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
174 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
175 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
179 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
180 union wpa_event_data *data)
183 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
187 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
188 " index=%d preauth=%d",
189 MAC2STR(data->pmkid_candidate.bssid),
190 data->pmkid_candidate.index,
191 data->pmkid_candidate.preauth);
193 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
194 data->pmkid_candidate.index,
195 data->pmkid_candidate.preauth);
199 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
201 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
202 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
205 #ifdef IEEE8021X_EAPOL
206 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
207 wpa_s->current_ssid &&
208 !(wpa_s->current_ssid->eapol_flags &
209 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
210 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
211 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
212 * plaintext or static WEP keys). */
215 #endif /* IEEE8021X_EAPOL */
222 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
223 * @wpa_s: pointer to wpa_supplicant data
224 * @ssid: Configuration data for the network
225 * Returns: 0 on success, -1 on failure
227 * This function is called when starting authentication with a network that is
228 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
230 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
231 struct wpa_ssid *ssid)
233 #ifdef IEEE8021X_EAPOL
235 int aka = 0, sim = 0, type;
237 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
240 if (ssid->eap.eap_methods == NULL) {
244 struct eap_method_type *eap = ssid->eap.eap_methods;
245 while (eap->vendor != EAP_VENDOR_IETF ||
246 eap->method != EAP_TYPE_NONE) {
247 if (eap->vendor == EAP_VENDOR_IETF) {
248 if (eap->method == EAP_TYPE_SIM)
250 else if (eap->method == EAP_TYPE_AKA ||
251 eap->method == EAP_TYPE_AKA_PRIME)
258 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
260 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
261 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
266 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
267 "use SIM, but neither EAP-SIM nor EAP-AKA are "
272 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
273 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
275 type = SCARD_TRY_BOTH;
277 type = SCARD_USIM_ONLY;
279 type = SCARD_GSM_SIM_ONLY;
281 wpa_s->scard = scard_init(type, NULL);
282 if (wpa_s->scard == NULL) {
283 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
287 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
288 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
289 #endif /* PCSC_FUNCS */
290 #endif /* IEEE8021X_EAPOL */
296 #ifndef CONFIG_NO_SCAN_PROCESSING
297 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
298 struct wpa_ssid *ssid)
302 if (ssid->mixed_cell)
306 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
308 #endif /* CONFIG_WPS */
310 for (i = 0; i < NUM_WEP_KEYS; i++) {
311 if (ssid->wep_key_len[i]) {
316 #ifdef IEEE8021X_EAPOL
317 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
318 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
319 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
321 #endif /* IEEE8021X_EAPOL */
323 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
326 if (bss->caps & IEEE80211_CAP_PRIVACY)
332 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
333 struct wpa_ssid *ssid,
334 struct wpa_scan_res *bss)
336 struct wpa_ie_data ie;
338 const u8 *rsn_ie, *wpa_ie;
342 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
346 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
347 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
348 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
349 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
350 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
352 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
353 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
356 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
357 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
363 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
365 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
370 if (!(ie.proto & ssid->proto)) {
371 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
376 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
377 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
382 if (!(ie.group_cipher & ssid->group_cipher)) {
383 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
388 if (!(ie.key_mgmt & ssid->key_mgmt)) {
389 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
394 #ifdef CONFIG_IEEE80211W
395 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
396 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
397 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
401 #endif /* CONFIG_IEEE80211W */
403 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
407 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
408 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
411 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
412 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
418 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
420 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
425 if (!(ie.proto & ssid->proto)) {
426 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
431 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
432 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
437 if (!(ie.group_cipher & ssid->group_cipher)) {
438 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
443 if (!(ie.key_mgmt & ssid->key_mgmt)) {
444 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
449 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
453 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
454 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
455 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
459 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
460 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
464 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
471 static int freq_allowed(int *freqs, int freq)
478 for (i = 0; freqs[i]; i++)
479 if (freqs[i] == freq)
485 static int ht_supported(const struct hostapd_hw_modes *mode)
487 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
489 * The driver did not indicate whether it supports HT. Assume
490 * it does to avoid connection issues.
496 * IEEE Std 802.11n-2009 20.1.1:
497 * An HT non-AP STA shall support all EQM rates for one spatial stream.
499 return mode->mcs_set[0] == 0xff;
503 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
505 const struct hostapd_hw_modes *mode = NULL, *modes;
506 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
511 return 1; /* Cannot do matching without knowing band */
513 modes = wpa_s->hw.modes;
516 * The driver does not provide any additional information
517 * about the utilized hardware, so allow the connection attempt
523 for (i = 0; i < wpa_s->hw.num_modes; i++) {
524 for (j = 0; j < modes[i].num_channels; j++) {
525 int freq = modes[i].channels[j].freq;
526 if (freq == bss->freq) {
528 mode->mode == HOSTAPD_MODE_IEEE80211G)
529 break; /* do not allow 802.11b replace
540 for (i = 0; i < (int) sizeof(scan_ie); i++) {
541 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
545 for (j = 2; j < rate_ie[1] + 2; j++) {
546 int flagged = !!(rate_ie[j] & 0x80);
547 int r = (rate_ie[j] & 0x7f) * 5;
550 * IEEE Std 802.11n-2009 7.3.2.2:
551 * The new BSS Membership selector value is encoded
552 * like a legacy basic rate, but it is not a rate and
553 * only indicates if the BSS members are required to
554 * support the mandatory features of Clause 20 [HT PHY]
555 * in order to join the BSS.
557 if (flagged && ((rate_ie[j] & 0x7f) ==
558 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
559 if (!ht_supported(mode)) {
560 wpa_dbg(wpa_s, MSG_DEBUG,
561 " hardware does not support "
571 /* check for legacy basic rates */
572 for (k = 0; k < mode->num_rates; k++) {
573 if (mode->rates[k] == r)
576 if (k == mode->num_rates) {
578 * IEEE Std 802.11-2007 7.3.2.2 demands that in
579 * order to join a BSS all required rates
580 * have to be supported by the hardware.
582 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
583 "not support required rate %d.%d Mbps",
594 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
595 int i, struct wpa_scan_res *bss,
596 struct wpa_ssid *group)
599 u8 wpa_ie_len, rsn_ie_len, ssid_len;
601 struct wpa_blacklist *e;
603 struct wpa_ssid *ssid;
605 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
606 ssid_ = ie ? ie + 2 : (u8 *) "";
607 ssid_len = ie ? ie[1] : 0;
609 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
610 wpa_ie_len = ie ? ie[1] : 0;
612 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
613 rsn_ie_len = ie ? ie[1] : 0;
615 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
616 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
617 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
618 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
619 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
621 e = wpa_blacklist_get(wpa_s, bss->bssid);
624 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
626 * When only a single network is enabled, we can
627 * trigger blacklisting on the first failure. This
628 * should not be done with multiple enabled networks to
629 * avoid getting forced to move into a worse ESS on
630 * single error if there are no other BSSes of the
635 if (e->count > limit) {
636 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
637 "(count=%d limit=%d)", e->count, limit);
643 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
647 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
649 for (ssid = group; ssid; ssid = ssid->pnext) {
650 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
652 if (wpas_network_disabled(wpa_s, ssid)) {
653 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
658 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
659 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
664 if (wpa && ssid->ssid_len == 0 &&
665 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
668 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
669 /* Only allow wildcard SSID match if an AP
670 * advertises active WPS operation that matches
673 if (ssid->ssid_len == 0 &&
674 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
677 #endif /* CONFIG_WPS */
679 if (ssid->bssid_set && ssid->ssid_len == 0 &&
680 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
684 (ssid_len != ssid->ssid_len ||
685 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
686 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
690 if (ssid->bssid_set &&
691 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
692 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
696 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
700 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
701 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
702 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
703 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
708 if (!wpa_supplicant_match_privacy(bss, ssid)) {
709 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
714 if (bss->caps & IEEE80211_CAP_IBSS) {
715 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
720 if (!freq_allowed(ssid->freq_list, bss->freq)) {
721 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
726 if (!rate_match(wpa_s, bss)) {
727 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
734 * TODO: skip the AP if its P2P IE has Group Formation
735 * bit set in the P2P Group Capability Bitmap and we
736 * are not in Group Formation with that device.
738 #endif /* CONFIG_P2P */
740 /* Matching configuration found */
744 /* No matching configuration found */
749 static struct wpa_bss *
750 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
751 struct wpa_scan_results *scan_res,
752 struct wpa_ssid *group,
753 struct wpa_ssid **selected_ssid)
757 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
760 for (i = 0; i < scan_res->num; i++) {
761 struct wpa_scan_res *bss = scan_res->res[i];
765 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
769 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
770 ssid = ie ? ie + 2 : (u8 *) "";
771 ssid_len = ie ? ie[1] : 0;
773 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
775 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
776 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
783 static struct wpa_bss *
784 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
785 struct wpa_scan_results *scan_res,
786 struct wpa_ssid **selected_ssid)
788 struct wpa_bss *selected = NULL;
791 while (selected == NULL) {
792 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
793 selected = wpa_supplicant_select_bss(
794 wpa_s, scan_res, wpa_s->conf->pssid[prio],
800 if (selected == NULL && wpa_s->blacklist &&
801 !wpa_s->countermeasures) {
802 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
803 "blacklist and try again");
804 wpa_blacklist_clear(wpa_s);
805 wpa_s->blacklist_cleared++;
806 } else if (selected == NULL)
814 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
815 int timeout_sec, int timeout_usec)
817 if (!wpa_supplicant_enabled_networks(wpa_s)) {
819 * No networks are enabled; short-circuit request so
820 * we don't wait timeout seconds before transitioning
823 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
826 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
830 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
831 struct wpa_bss *selected,
832 struct wpa_ssid *ssid)
834 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
835 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
836 "PBC session overlap");
838 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
840 #endif /* CONFIG_P2P */
843 wpas_wps_cancel(wpa_s);
844 #endif /* CONFIG_WPS */
849 * Do not trigger new association unless the BSSID has changed or if
850 * reassociation is requested. If we are in process of associating with
851 * the selected BSSID, do not trigger new attempt.
853 if (wpa_s->reassociate ||
854 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
855 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
856 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
857 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
859 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
860 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
863 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
864 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
865 " pending: " MACSTR " wpa_state: %s",
866 wpa_s->reassociate, MAC2STR(selected->bssid),
867 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
868 wpa_supplicant_state_txt(wpa_s->wpa_state));
869 wpa_supplicant_associate(wpa_s, selected, ssid);
871 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
879 static struct wpa_ssid *
880 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
883 struct wpa_ssid *ssid;
885 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
886 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
888 if (wpas_network_disabled(wpa_s, ssid))
890 if (ssid->mode == IEEE80211_MODE_IBSS ||
891 ssid->mode == IEEE80211_MODE_AP)
899 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
900 * on BSS added and BSS changed events */
901 static void wpa_supplicant_rsn_preauth_scan_results(
902 struct wpa_supplicant *wpa_s)
906 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
909 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
910 const u8 *ssid, *rsn;
912 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
916 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
920 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
926 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
927 struct wpa_bss *selected,
928 struct wpa_ssid *ssid,
929 struct wpa_scan_results *scan_res)
932 struct wpa_scan_res *current_bss = NULL;
935 if (wpa_s->reassociate)
936 return 1; /* explicit request to reassociate */
937 if (wpa_s->wpa_state < WPA_ASSOCIATED)
938 return 1; /* we are not associated; continue */
939 if (wpa_s->current_ssid == NULL)
940 return 1; /* unknown current SSID */
941 if (wpa_s->current_ssid != ssid)
942 return 1; /* different network block */
944 if (wpas_driver_bss_selection(wpa_s))
945 return 0; /* Driver-based roaming */
947 for (i = 0; i < scan_res->num; i++) {
948 struct wpa_scan_res *res = scan_res->res[i];
950 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
953 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
956 if (ie[1] != wpa_s->current_ssid->ssid_len ||
957 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
964 return 1; /* current BSS not seen in scan results */
966 #ifndef CONFIG_NO_ROAMING
967 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
968 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
969 MAC2STR(current_bss->bssid), current_bss->level);
970 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
971 MAC2STR(selected->bssid), selected->level);
973 if (wpa_s->current_ssid->bssid_set &&
974 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
976 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
977 "has preferred BSSID");
982 if (current_bss->level < 0) {
983 if (current_bss->level < -85)
985 else if (current_bss->level < -80)
987 else if (current_bss->level < -75)
989 else if (current_bss->level < -70)
994 if (abs(current_bss->level - selected->level) < min_diff) {
995 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1001 #else /* CONFIG_NO_ROAMING */
1003 #endif /* CONFIG_NO_ROAMING */
1007 /* Return < 0 if no scan results could be fetched or if scan results should not
1008 * be shared with other virtual interfaces. */
1010 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1011 union wpa_event_data *data, int suppress_event)
1013 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1014 union wpa_event_data *data)
1017 struct wpa_bss *selected;
1018 struct wpa_ssid *ssid = NULL;
1019 struct wpa_scan_results *scan_res;
1023 if (wpa_s->ap_iface)
1025 #endif /* CONFIG_AP */
1027 wpa_supplicant_notify_scanning(wpa_s, 0);
1031 if (p2p_search_pending(wpa_s->global->p2p) && !wpa_s->global->p2p_disabled &&
1033 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1035 wpa_s->global->p2p != NULL) {
1036 wpa_s->p2p_cb_on_scan_complete = 0;
1037 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1038 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1039 "stopped scan processing");
1043 #endif /* CONFIG_P2P */
1045 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1046 data ? &data->scan_info :
1048 if (scan_res == NULL) {
1049 if (wpa_s->conf->ap_scan == 2 || ap)
1051 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1053 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1057 #ifndef CONFIG_NO_RANDOM_POOL
1059 num = scan_res->num;
1062 for (i = 0; i < num; i++) {
1064 struct wpa_scan_res *res = scan_res->res[i];
1065 buf[0] = res->bssid[5];
1066 buf[1] = res->qual & 0xff;
1067 buf[2] = res->noise & 0xff;
1068 buf[3] = res->level & 0xff;
1069 buf[4] = res->tsf & 0xff;
1070 random_add_randomness(buf, sizeof(buf));
1072 #endif /* CONFIG_NO_RANDOM_POOL */
1074 if (wpa_s->scan_res_handler) {
1075 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1076 struct wpa_scan_results *scan_res);
1078 scan_res_handler = wpa_s->scan_res_handler;
1079 wpa_s->scan_res_handler = NULL;
1080 scan_res_handler(wpa_s, scan_res);
1082 wpa_scan_results_free(scan_res);
1087 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1089 if (wpa_s->ap_iface->scan_cb)
1090 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1091 #endif /* CONFIG_AP */
1092 wpa_scan_results_free(scan_res);
1098 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1099 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1100 wpas_notify_scan_results(wpa_s);
1103 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1104 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1105 wpas_notify_scan_results(wpa_s);
1108 wpas_notify_scan_done(wpa_s, 1);
1110 if (sme_proc_obss_scan(wpa_s) > 0) {
1111 wpa_scan_results_free(scan_res);
1115 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1116 wpa_scan_results_free(scan_res);
1120 if (autoscan_notify_scan(wpa_s, scan_res)) {
1121 wpa_scan_results_free(scan_res);
1125 if (wpa_s->disconnected) {
1126 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1127 wpa_scan_results_free(scan_res);
1131 if (!wpas_driver_bss_selection(wpa_s) &&
1132 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1133 wpa_scan_results_free(scan_res);
1137 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1141 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1143 wpa_scan_results_free(scan_res);
1145 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1149 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1150 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1153 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1155 wpa_scan_results_free(scan_res);
1156 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1157 ssid = wpa_supplicant_pick_new_network(wpa_s);
1159 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1160 wpa_supplicant_associate(wpa_s, NULL, ssid);
1161 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1163 int timeout_sec = wpa_s->scan_interval;
1164 int timeout_usec = 0;
1166 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1169 if (wpa_s->p2p_in_provisioning) {
1171 * Use shorter wait during P2P Provisioning
1172 * state to speed up group formation.
1175 timeout_usec = 250000;
1176 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1180 #endif /* CONFIG_P2P */
1181 if (wpa_supplicant_req_sched_scan(wpa_s))
1182 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1190 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1191 union wpa_event_data *data)
1193 const char *rn, *rn2;
1194 struct wpa_supplicant *ifs;
1196 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1198 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1201 * If no scan results could be fetched, then no need to
1202 * notify those interfaces that did not actually request
1209 * Check other interfaces to see if they have the same radio-name. If
1210 * so, they get updated with this same scan info.
1212 if (!wpa_s->driver->get_radio_name)
1215 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1216 if (rn == NULL || rn[0] == '\0')
1219 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1220 "sharing same radio (%s) in event_scan_results", rn);
1222 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1223 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1226 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1227 if (rn2 && os_strcmp(rn, rn2) == 0) {
1228 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1229 "sibling", ifs->ifname);
1231 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1232 /* Do not update the scan results from STA interface to p2p interfaces */
1233 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1234 "sibling %s", ifs->ifname, wpa_s->ifname);
1238 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1239 * no time. Avoid announcing it to application as it may not
1240 * be that useful (since results will be that of only 1,6,11).
1241 * over to any other interface as it
1243 if(p2p_search_in_progress(wpa_s->global->p2p))
1244 _wpa_supplicant_event_scan_results(ifs, data, 1);
1246 _wpa_supplicant_event_scan_results(ifs, data, 0);
1249 _wpa_supplicant_event_scan_results(ifs, data);
1255 #endif /* CONFIG_NO_SCAN_PROCESSING */
1260 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1262 struct wpa_supplicant *wpa_s = eloop_ctx;
1264 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1267 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1268 MAC2STR(wpa_s->bssid));
1269 /* TODO: could skip this if normal data traffic has been sent */
1270 /* TODO: Consider using some more appropriate data frame for this */
1272 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1275 if (wpa_s->sme.bss_max_idle_period) {
1277 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1280 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1281 wnm_bss_keep_alive, wpa_s, NULL);
1283 #endif /* CONFIG_SME */
1287 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1288 const u8 *ies, size_t ies_len)
1290 struct ieee802_11_elems elems;
1295 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1299 if (elems.bss_max_idle_period) {
1301 wpa_s->sme.bss_max_idle_period =
1302 WPA_GET_LE16(elems.bss_max_idle_period);
1303 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1304 "TU)%s", wpa_s->sme.bss_max_idle_period,
1305 (elems.bss_max_idle_period[2] & 0x01) ?
1306 " (protected keep-live required)" : "");
1307 if (wpa_s->sme.bss_max_idle_period == 0)
1308 wpa_s->sme.bss_max_idle_period = 1;
1309 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1310 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1311 /* msec times 1000 */
1312 msec = wpa_s->sme.bss_max_idle_period * 1024;
1315 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1316 wnm_bss_keep_alive, wpa_s,
1320 #endif /* CONFIG_SME */
1323 #endif /* CONFIG_WNM */
1326 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1329 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1330 #endif /* CONFIG_WNM */
1334 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1335 union wpa_event_data *data)
1337 int l, len, found = 0, wpa_found, rsn_found;
1340 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1341 if (data->assoc_info.req_ies)
1342 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1343 data->assoc_info.req_ies_len);
1344 if (data->assoc_info.resp_ies) {
1345 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1346 data->assoc_info.resp_ies_len);
1348 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1349 data->assoc_info.resp_ies_len);
1350 #endif /* CONFIG_TDLS */
1352 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1353 data->assoc_info.resp_ies_len);
1354 #endif /* CONFIG_WNM */
1356 if (data->assoc_info.beacon_ies)
1357 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1358 data->assoc_info.beacon_ies,
1359 data->assoc_info.beacon_ies_len);
1360 if (data->assoc_info.freq)
1361 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1362 data->assoc_info.freq);
1364 p = data->assoc_info.req_ies;
1365 l = data->assoc_info.req_ies_len;
1367 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1368 while (p && l >= 2) {
1371 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1375 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1376 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1377 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1378 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1381 wpa_find_assoc_pmkid(wpa_s);
1387 if (!found && data->assoc_info.req_ies)
1388 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1390 #ifdef CONFIG_IEEE80211R
1392 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1394 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1395 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1396 data->assoc_info.resp_ies,
1397 data->assoc_info.resp_ies_len,
1399 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1400 "Reassociation Response failed");
1401 wpa_supplicant_deauthenticate(
1402 wpa_s, WLAN_REASON_INVALID_IE);
1407 p = data->assoc_info.resp_ies;
1408 l = data->assoc_info.resp_ies_len;
1410 #ifdef CONFIG_WPS_STRICT
1411 if (p && wpa_s->current_ssid &&
1412 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1414 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1416 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1417 "include WPS IE in (Re)Association Response");
1421 if (wps_validate_assoc_resp(wps) < 0) {
1423 wpa_supplicant_deauthenticate(
1424 wpa_s, WLAN_REASON_INVALID_IE);
1429 #endif /* CONFIG_WPS_STRICT */
1431 /* Go through the IEs and make a copy of the MDIE, if present. */
1432 while (p && l >= 2) {
1435 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1439 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1440 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1441 wpa_s->sme.ft_used = 1;
1442 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1443 MOBILITY_DOMAIN_ID_LEN);
1449 #endif /* CONFIG_SME */
1451 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1452 data->assoc_info.resp_ies_len);
1453 #endif /* CONFIG_IEEE80211R */
1455 /* WPA/RSN IE from Beacon/ProbeResp */
1456 p = data->assoc_info.beacon_ies;
1457 l = data->assoc_info.beacon_ies_len;
1459 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1461 wpa_found = rsn_found = 0;
1462 while (p && l >= 2) {
1465 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1470 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1471 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1473 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1477 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1479 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1486 if (!wpa_found && data->assoc_info.beacon_ies)
1487 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1488 if (!rsn_found && data->assoc_info.beacon_ies)
1489 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1490 if (wpa_found || rsn_found)
1491 wpa_s->ap_ies_from_associnfo = 1;
1493 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1494 wpa_s->assoc_freq != data->assoc_info.freq) {
1495 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1497 wpa_s->assoc_freq, data->assoc_info.freq);
1498 wpa_supplicant_update_scan_results(wpa_s);
1501 wpa_s->assoc_freq = data->assoc_info.freq;
1507 static struct wpa_bss * wpa_supplicant_get_new_bss(
1508 struct wpa_supplicant *wpa_s, const u8 *bssid)
1510 struct wpa_bss *bss = NULL;
1511 struct wpa_ssid *ssid = wpa_s->current_ssid;
1513 if (ssid->ssid_len > 0)
1514 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1516 bss = wpa_bss_get_bssid(wpa_s, bssid);
1522 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1524 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1526 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1529 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1532 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1533 WPA_IE_VENDOR_TYPE);
1534 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1536 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1537 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1538 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1539 bss_rsn ? 2 + bss_rsn[1] : 0))
1546 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1547 union wpa_event_data *data)
1552 struct wpa_driver_capa capa;
1555 if (wpa_s->ap_iface) {
1556 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1557 data->assoc_info.addr,
1558 data->assoc_info.req_ies,
1559 data->assoc_info.req_ies_len,
1560 data->assoc_info.reassoc);
1563 #endif /* CONFIG_AP */
1565 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1566 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1569 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1570 if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1571 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1572 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1573 MACSTR, MAC2STR(bssid));
1574 random_add_randomness(bssid, ETH_ALEN);
1575 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1576 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1577 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1579 wpas_notify_bssid_changed(wpa_s);
1581 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1582 wpa_clear_keys(wpa_s, bssid);
1584 if (wpa_supplicant_select_config(wpa_s) < 0) {
1585 wpa_supplicant_disassociate(
1586 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1589 if (wpa_s->current_ssid) {
1590 struct wpa_bss *bss = NULL;
1592 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1594 wpa_supplicant_update_scan_results(wpa_s);
1596 /* Get the BSS from the new scan results */
1597 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1601 wpa_s->current_bss = bss;
1604 if (wpa_s->conf->ap_scan == 1 &&
1605 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1606 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1607 wpa_msg(wpa_s, MSG_WARNING,
1608 "WPA/RSN IEs not updated");
1613 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1614 wpa_s->sme.prev_bssid_set = 1;
1615 #endif /* CONFIG_SME */
1617 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1618 if (wpa_s->current_ssid) {
1619 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1620 * initialized before association, but for other modes,
1621 * initialize PC/SC here, if the current configuration needs
1622 * smartcard or SIM/USIM. */
1623 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1625 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1627 l2_packet_notify_auth_start(wpa_s->l2);
1630 * Set portEnabled first to FALSE in order to get EAP state machine out
1631 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1632 * state machine may transit to AUTHENTICATING state based on obsolete
1633 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1634 * AUTHENTICATED without ever giving chance to EAP state machine to
1637 if (!ft_completed) {
1638 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1639 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1641 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1642 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1643 /* 802.1X::portControl = Auto */
1644 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1645 wpa_s->eapol_received = 0;
1646 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1647 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1648 (wpa_s->current_ssid &&
1649 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1650 wpa_supplicant_cancel_auth_timeout(wpa_s);
1651 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1652 } else if (!ft_completed) {
1653 /* Timeout for receiving the first EAPOL packet */
1654 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1656 wpa_supplicant_cancel_scan(wpa_s);
1658 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1659 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1661 * We are done; the driver will take care of RSN 4-way
1664 wpa_supplicant_cancel_auth_timeout(wpa_s);
1665 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1666 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1667 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1668 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1669 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1671 * The driver will take care of RSN 4-way handshake, so we need
1672 * to allow EAPOL supplicant to complete its work without
1673 * waiting for WPA supplicant.
1675 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1676 } else if (ft_completed) {
1678 * FT protocol completed - make sure EAPOL state machine ends
1679 * up in authenticated.
1681 wpa_supplicant_cancel_auth_timeout(wpa_s);
1682 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1683 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1684 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1687 if (wpa_s->pending_eapol_rx) {
1688 struct os_time now, age;
1690 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1691 if (age.sec == 0 && age.usec < 100000 &&
1692 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1694 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1695 "frame that was received just before "
1696 "association notification");
1697 wpa_supplicant_rx_eapol(
1698 wpa_s, wpa_s->pending_eapol_rx_src,
1699 wpabuf_head(wpa_s->pending_eapol_rx),
1700 wpabuf_len(wpa_s->pending_eapol_rx));
1702 wpabuf_free(wpa_s->pending_eapol_rx);
1703 wpa_s->pending_eapol_rx = NULL;
1706 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1707 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1708 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1709 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1710 /* Set static WEP keys again */
1711 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1714 #ifdef CONFIG_IBSS_RSN
1715 if (wpa_s->current_ssid &&
1716 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1717 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1718 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1719 wpa_s->ibss_rsn == NULL) {
1720 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1721 if (!wpa_s->ibss_rsn) {
1722 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1723 wpa_supplicant_deauthenticate(
1724 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1728 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1730 #endif /* CONFIG_IBSS_RSN */
1734 static int disconnect_reason_recoverable(u16 reason_code)
1736 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1737 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1738 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1742 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1744 int locally_generated)
1748 u8 prev_pending_bssid[ETH_ALEN];
1749 struct wpa_bss *fast_reconnect = NULL;
1750 struct wpa_ssid *fast_reconnect_ssid = NULL;
1752 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1753 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1755 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1757 * At least Host AP driver and a Prism3 card seemed to be
1758 * generating streams of disconnected events when configuring
1759 * IBSS for WPA-None. Ignore them for now.
1761 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1762 "IBSS/WPA-None mode");
1766 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1767 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1768 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1769 "pre-shared key may be incorrect");
1771 if (!wpa_s->auto_reconnect_disabled ||
1772 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1773 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1774 "reconnect (wps=%d wpa_state=%d)",
1775 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1777 if (wpa_s->wpa_state == WPA_COMPLETED &&
1778 wpa_s->current_ssid &&
1779 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1780 !locally_generated &&
1781 disconnect_reason_recoverable(reason_code)) {
1783 * It looks like the AP has dropped association with
1784 * us, but could allow us to get back in. Try to
1785 * reconnect to the same BSS without full scan to save
1786 * time for some common cases.
1788 fast_reconnect = wpa_s->current_bss;
1789 fast_reconnect_ssid = wpa_s->current_ssid;
1790 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1792 wpa_supplicant_req_scan(wpa_s, 0, 500000);
1794 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1797 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1800 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1801 "try to re-connect");
1802 wpa_s->reassociate = 0;
1803 wpa_s->disconnected = 1;
1804 wpa_supplicant_cancel_sched_scan(wpa_s);
1806 bssid = wpa_s->bssid;
1807 if (is_zero_ether_addr(bssid))
1808 bssid = wpa_s->pending_bssid;
1809 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1810 wpas_connection_failed(wpa_s, bssid);
1811 wpa_sm_notify_disassoc(wpa_s->wpa);
1812 if (locally_generated)
1813 wpa_s->disconnect_reason = -reason_code;
1815 wpa_s->disconnect_reason = reason_code;
1816 wpas_notify_disconnect_reason(wpa_s);
1817 if (!is_zero_ether_addr(bssid) ||
1818 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1819 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1821 MAC2STR(bssid), reason_code,
1822 locally_generated ? " locally_generated=1" : "");
1824 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1825 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1826 wpa_s->keys_cleared = 0;
1827 wpa_clear_keys(wpa_s, wpa_s->bssid);
1829 wpa_supplicant_mark_disassoc(wpa_s);
1831 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1832 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1834 if (fast_reconnect) {
1835 #ifndef CONFIG_NO_SCAN_PROCESSING
1836 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1837 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1838 fast_reconnect_ssid) < 0) {
1839 /* Recover through full scan */
1840 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1842 #endif /* CONFIG_NO_SCAN_PROCESSING */
1847 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1848 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1850 struct wpa_supplicant *wpa_s = eloop_ctx;
1852 if (!wpa_s->pending_mic_error_report)
1855 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1856 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1857 wpa_s->pending_mic_error_report = 0;
1859 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1863 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1864 union wpa_event_data *data)
1869 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1870 pairwise = (data && data->michael_mic_failure.unicast);
1872 if ((wpa_s->last_michael_mic_error &&
1873 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1874 wpa_s->pending_mic_error_report) {
1875 if (wpa_s->pending_mic_error_report) {
1877 * Send the pending MIC error report immediately since
1878 * we are going to start countermeasures and AP better
1881 wpa_sm_key_request(wpa_s->wpa, 1,
1882 wpa_s->pending_mic_error_pairwise);
1885 /* Send the new MIC error report immediately since we are going
1886 * to start countermeasures and AP better do the same.
1888 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1890 /* initialize countermeasures */
1891 wpa_s->countermeasures = 1;
1893 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1895 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1898 * Need to wait for completion of request frame. We do not get
1899 * any callback for the message completion, so just wait a
1900 * short while and hope for the best. */
1903 wpa_drv_set_countermeasures(wpa_s, 1);
1904 wpa_supplicant_deauthenticate(wpa_s,
1905 WLAN_REASON_MICHAEL_MIC_FAILURE);
1906 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1908 eloop_register_timeout(60, 0,
1909 wpa_supplicant_stop_countermeasures,
1911 /* TODO: mark the AP rejected for 60 second. STA is
1912 * allowed to associate with another AP.. */
1914 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1915 if (wpa_s->mic_errors_seen) {
1917 * Reduce the effectiveness of Michael MIC error
1918 * reports as a means for attacking against TKIP if
1919 * more than one MIC failure is noticed with the same
1920 * PTK. We delay the transmission of the reports by a
1921 * random time between 0 and 60 seconds in order to
1922 * force the attacker wait 60 seconds before getting
1923 * the information on whether a frame resulted in a MIC
1929 if (os_get_random(rval, sizeof(rval)) < 0)
1930 sec = os_random() % 60;
1932 sec = WPA_GET_BE32(rval) % 60;
1933 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1934 "report %d seconds", sec);
1935 wpa_s->pending_mic_error_report = 1;
1936 wpa_s->pending_mic_error_pairwise = pairwise;
1937 eloop_cancel_timeout(
1938 wpa_supplicant_delayed_mic_error_report,
1940 eloop_register_timeout(
1941 sec, os_random() % 1000000,
1942 wpa_supplicant_delayed_mic_error_report,
1945 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1947 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1948 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1949 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1951 wpa_s->last_michael_mic_error = t.sec;
1952 wpa_s->mic_errors_seen++;
1956 #ifdef CONFIG_TERMINATE_ONLASTIF
1957 static int any_interfaces(struct wpa_supplicant *head)
1959 struct wpa_supplicant *wpa_s;
1961 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1962 if (!wpa_s->interface_removed)
1966 #endif /* CONFIG_TERMINATE_ONLASTIF */
1970 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1971 union wpa_event_data *data)
1973 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1976 switch (data->interface_status.ievent) {
1977 case EVENT_INTERFACE_ADDED:
1978 if (!wpa_s->interface_removed)
1980 wpa_s->interface_removed = 0;
1981 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1982 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1983 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1984 "driver after interface was added");
1986 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1988 case EVENT_INTERFACE_REMOVED:
1989 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1990 wpa_s->interface_removed = 1;
1991 wpa_supplicant_mark_disassoc(wpa_s);
1992 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1993 l2_packet_deinit(wpa_s->l2);
1995 #ifdef CONFIG_IBSS_RSN
1996 ibss_rsn_deinit(wpa_s->ibss_rsn);
1997 wpa_s->ibss_rsn = NULL;
1998 #endif /* CONFIG_IBSS_RSN */
1999 #ifdef CONFIG_TERMINATE_ONLASTIF
2000 /* check if last interface */
2001 if (!any_interfaces(wpa_s->global->ifaces))
2003 #endif /* CONFIG_TERMINATE_ONLASTIF */
2009 #ifdef CONFIG_PEERKEY
2011 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2012 union wpa_event_data *data)
2016 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2018 #endif /* CONFIG_PEERKEY */
2022 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2023 union wpa_event_data *data)
2027 switch (data->tdls.oper) {
2028 case TDLS_REQUEST_SETUP:
2029 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2031 case TDLS_REQUEST_TEARDOWN:
2032 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2033 data->tdls.reason_code);
2037 #endif /* CONFIG_TDLS */
2040 #ifdef CONFIG_IEEE80211R
2042 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2043 union wpa_event_data *data)
2048 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2049 data->ft_ies.ies_len,
2050 data->ft_ies.ft_action,
2051 data->ft_ies.target_ap,
2052 data->ft_ies.ric_ies,
2053 data->ft_ies.ric_ies_len) < 0) {
2054 /* TODO: prevent MLME/driver from trying to associate? */
2057 #endif /* CONFIG_IEEE80211R */
2060 #ifdef CONFIG_IBSS_RSN
2061 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2062 union wpa_event_data *data)
2064 struct wpa_ssid *ssid;
2065 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2069 ssid = wpa_s->current_ssid;
2072 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2075 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2077 #endif /* CONFIG_IBSS_RSN */
2080 #ifdef CONFIG_IEEE80211R
2081 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2084 const u8 *sta_addr, *target_ap_addr;
2087 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2088 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2089 return; /* only SME case supported for now */
2090 if (len < 1 + 2 * ETH_ALEN + 2)
2093 return; /* Only FT Action Response is supported for now */
2094 sta_addr = data + 1;
2095 target_ap_addr = data + 1 + ETH_ALEN;
2096 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2097 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2098 MACSTR " TargetAP " MACSTR " status %u",
2099 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2101 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2102 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2103 " in FT Action Response", MAC2STR(sta_addr));
2108 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2109 "failure (status code %d)", status);
2110 /* TODO: report error to FT code(?) */
2114 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2115 len - (1 + 2 * ETH_ALEN + 2), 1,
2116 target_ap_addr, NULL, 0) < 0)
2121 struct wpa_bss *bss;
2122 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2124 wpa_s->sme.freq = bss->freq;
2125 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2126 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2129 #endif /* CONFIG_SME */
2131 #endif /* CONFIG_IEEE80211R */
2134 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2135 struct unprot_deauth *e)
2137 #ifdef CONFIG_IEEE80211W
2138 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2139 "dropped: " MACSTR " -> " MACSTR
2140 " (reason code %u)",
2141 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2142 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2143 #endif /* CONFIG_IEEE80211W */
2147 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2148 struct unprot_disassoc *e)
2150 #ifdef CONFIG_IEEE80211W
2151 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2152 "dropped: " MACSTR " -> " MACSTR
2153 " (reason code %u)",
2154 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2155 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2156 #endif /* CONFIG_IEEE80211W */
2160 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2163 const u8 *pos, *end;
2165 if (rx->data == NULL || rx->len == 0)
2169 end = pos + rx->len;
2172 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2173 action, MAC2STR(rx->sa));
2175 case WNM_BSS_TRANS_MGMT_REQ:
2178 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2179 "Request: dialog_token=%u request_mode=0x%x "
2180 "disassoc_timer=%u validity_interval=%u",
2181 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2185 pos += 12; /* BSS Termination Duration */
2188 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2189 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2190 "Transition Management Request "
2194 os_memcpy(url, pos + 1, pos[0]);
2196 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2197 "Imminent - session_info_url=%s", url);
2204 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2205 union wpa_event_data *data)
2207 struct wpa_supplicant *wpa_s = ctx;
2208 u16 reason_code = 0;
2209 int locally_generated = 0;
2211 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2212 event != EVENT_INTERFACE_ENABLED &&
2213 event != EVENT_INTERFACE_STATUS &&
2214 event != EVENT_SCHED_SCAN_STOPPED) {
2215 wpa_dbg(wpa_s, MSG_DEBUG,
2216 "Ignore event %s (%d) while interface is disabled",
2217 event_to_string(event), event);
2221 #ifndef CONFIG_NO_STDOUT_DEBUG
2223 int level = MSG_DEBUG;
2225 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2226 const struct ieee80211_hdr *hdr;
2228 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2229 fc = le_to_host16(hdr->frame_control);
2230 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2231 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2232 level = MSG_EXCESSIVE;
2235 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2236 event_to_string(event), event);
2238 #endif /* CONFIG_NO_STDOUT_DEBUG */
2242 sme_event_auth(wpa_s, data);
2245 wpa_supplicant_event_assoc(wpa_s, data);
2247 case EVENT_DISASSOC:
2248 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2250 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2251 data->disassoc_info.reason_code,
2252 data->disassoc_info.locally_generated ?
2253 " (locally generated)" : "");
2254 if (data->disassoc_info.addr)
2255 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2256 MAC2STR(data->disassoc_info.addr));
2259 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2260 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2261 data->disassoc_info.addr);
2264 if (wpa_s->ap_iface) {
2265 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2269 #endif /* CONFIG_AP */
2271 reason_code = data->disassoc_info.reason_code;
2273 data->disassoc_info.locally_generated;
2274 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2275 data->disassoc_info.ie,
2276 data->disassoc_info.ie_len);
2278 wpas_p2p_disassoc_notif(
2279 wpa_s, data->disassoc_info.addr, reason_code,
2280 data->disassoc_info.ie,
2281 data->disassoc_info.ie_len,
2283 #endif /* CONFIG_P2P */
2285 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2286 sme_event_disassoc(wpa_s, data);
2289 if (event == EVENT_DEAUTH) {
2290 wpa_dbg(wpa_s, MSG_DEBUG,
2291 "Deauthentication notification");
2293 reason_code = data->deauth_info.reason_code;
2295 data->deauth_info.locally_generated;
2296 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2297 data->deauth_info.reason_code,
2298 data->deauth_info.locally_generated ?
2299 " (locally generated)" : "");
2300 if (data->deauth_info.addr) {
2301 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2303 MAC2STR(data->deauth_info.
2306 wpa_hexdump(MSG_DEBUG,
2307 "Deauthentication frame IE(s)",
2308 data->deauth_info.ie,
2309 data->deauth_info.ie_len);
2313 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2314 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2315 data->deauth_info.addr);
2318 if (wpa_s->ap_iface) {
2319 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2323 #endif /* CONFIG_AP */
2324 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2327 if (event == EVENT_DEAUTH && data) {
2328 wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
2330 data->deauth_info.ie,
2331 data->deauth_info.ie_len,
2334 #endif /* CONFIG_P2P */
2336 case EVENT_MICHAEL_MIC_FAILURE:
2337 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2339 #ifndef CONFIG_NO_SCAN_PROCESSING
2340 case EVENT_SCAN_RESULTS:
2341 wpa_supplicant_event_scan_results(wpa_s, data);
2343 #endif /* CONFIG_NO_SCAN_PROCESSING */
2344 case EVENT_ASSOCINFO:
2345 wpa_supplicant_event_associnfo(wpa_s, data);
2347 case EVENT_INTERFACE_STATUS:
2348 wpa_supplicant_event_interface_status(wpa_s, data);
2350 case EVENT_PMKID_CANDIDATE:
2351 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2353 #ifdef CONFIG_PEERKEY
2354 case EVENT_STKSTART:
2355 wpa_supplicant_event_stkstart(wpa_s, data);
2357 #endif /* CONFIG_PEERKEY */
2360 wpa_supplicant_event_tdls(wpa_s, data);
2362 #endif /* CONFIG_TDLS */
2363 #ifdef CONFIG_IEEE80211R
2364 case EVENT_FT_RESPONSE:
2365 wpa_supplicant_event_ft_response(wpa_s, data);
2367 #endif /* CONFIG_IEEE80211R */
2368 #ifdef CONFIG_IBSS_RSN
2369 case EVENT_IBSS_RSN_START:
2370 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2372 #endif /* CONFIG_IBSS_RSN */
2373 case EVENT_ASSOC_REJECT:
2374 if (data->assoc_reject.bssid)
2375 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2376 "bssid=" MACSTR " status_code=%u",
2377 MAC2STR(data->assoc_reject.bssid),
2378 data->assoc_reject.status_code);
2380 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2382 data->assoc_reject.status_code);
2383 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2384 sme_event_assoc_reject(wpa_s, data);
2388 if(!wpa_s->current_ssid) {
2389 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2392 /* If assoc reject is reported by the driver, then avoid
2393 * waiting for the authentication timeout. Cancel the
2394 * authentication timeout and retry the assoc.
2396 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2397 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2398 wpa_s->current_ssid->assoc_retry);
2399 wpa_supplicant_cancel_auth_timeout(wpa_s);
2401 /* Clear the states */
2402 wpa_sm_notify_disassoc(wpa_s->wpa);
2403 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2405 wpa_s->reassociate = 1;
2406 wpa_supplicant_req_scan(wpa_s, 1, 0);
2408 /* If we ASSOC_REJECT's hits threshold, disable the
2411 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2412 "Disabling the network");
2413 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
2415 if(wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
2416 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
2420 #endif /* ANDROID_P2P */
2422 case EVENT_AUTH_TIMED_OUT:
2423 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2424 sme_event_auth_timed_out(wpa_s, data);
2426 case EVENT_ASSOC_TIMED_OUT:
2427 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2428 sme_event_assoc_timed_out(wpa_s, data);
2430 case EVENT_TX_STATUS:
2431 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2432 " type=%d stype=%d",
2433 MAC2STR(data->tx_status.dst),
2434 data->tx_status.type, data->tx_status.stype);
2436 if (wpa_s->ap_iface == NULL) {
2437 #ifdef CONFIG_OFFCHANNEL
2438 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2439 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2440 offchannel_send_action_tx_status(
2441 wpa_s, data->tx_status.dst,
2442 data->tx_status.data,
2443 data->tx_status.data_len,
2444 data->tx_status.ack ?
2445 OFFCHANNEL_SEND_ACTION_SUCCESS :
2446 OFFCHANNEL_SEND_ACTION_NO_ACK);
2447 #endif /* CONFIG_OFFCHANNEL */
2450 #endif /* CONFIG_AP */
2451 #ifdef CONFIG_OFFCHANNEL
2452 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2453 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2455 * Catch TX status events for Action frames we sent via group
2456 * interface in GO mode.
2458 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2459 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2460 os_memcmp(wpa_s->parent->pending_action_dst,
2461 data->tx_status.dst, ETH_ALEN) == 0) {
2462 offchannel_send_action_tx_status(
2463 wpa_s->parent, data->tx_status.dst,
2464 data->tx_status.data,
2465 data->tx_status.data_len,
2466 data->tx_status.ack ?
2467 OFFCHANNEL_SEND_ACTION_SUCCESS :
2468 OFFCHANNEL_SEND_ACTION_NO_ACK);
2471 #endif /* CONFIG_OFFCHANNEL */
2473 switch (data->tx_status.type) {
2474 case WLAN_FC_TYPE_MGMT:
2475 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2476 data->tx_status.data_len,
2477 data->tx_status.stype,
2478 data->tx_status.ack);
2480 case WLAN_FC_TYPE_DATA:
2481 ap_tx_status(wpa_s, data->tx_status.dst,
2482 data->tx_status.data,
2483 data->tx_status.data_len,
2484 data->tx_status.ack);
2487 #endif /* CONFIG_AP */
2490 case EVENT_EAPOL_TX_STATUS:
2491 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2492 data->eapol_tx_status.data,
2493 data->eapol_tx_status.data_len,
2494 data->eapol_tx_status.ack);
2496 case EVENT_DRIVER_CLIENT_POLL_OK:
2497 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2499 case EVENT_RX_FROM_UNKNOWN:
2500 if (wpa_s->ap_iface == NULL)
2502 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2503 data->rx_from_unknown.wds);
2505 case EVENT_CH_SWITCH:
2508 if (!wpa_s->ap_iface) {
2509 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2510 "event in non-AP mode");
2515 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2516 data->ch_switch.ht_enabled,
2517 data->ch_switch.ch_offset);
2518 #endif /* CONFIG_AP */
2520 case EVENT_RX_MGMT: {
2522 const struct ieee80211_mgmt *mgmt;
2524 mgmt = (const struct ieee80211_mgmt *)
2525 data->rx_mgmt.frame;
2526 fc = le_to_host16(mgmt->frame_control);
2527 stype = WLAN_FC_GET_STYPE(fc);
2529 if (wpa_s->ap_iface == NULL) {
2531 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2532 data->rx_mgmt.frame_len > 24) {
2533 const u8 *src = mgmt->sa;
2534 const u8 *ie = mgmt->u.probe_req.variable;
2535 size_t ie_len = data->rx_mgmt.frame_len -
2536 (mgmt->u.probe_req.variable -
2537 data->rx_mgmt.frame);
2538 wpas_p2p_probe_req_rx(
2539 wpa_s, src, mgmt->da,
2540 mgmt->bssid, ie, ie_len,
2541 data->rx_mgmt.ssi_signal);
2544 #endif /* CONFIG_P2P */
2545 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2546 "management frame in non-AP mode");
2550 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2551 data->rx_mgmt.frame_len > 24) {
2552 const u8 *ie = mgmt->u.probe_req.variable;
2553 size_t ie_len = data->rx_mgmt.frame_len -
2554 (mgmt->u.probe_req.variable -
2555 data->rx_mgmt.frame);
2557 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2558 mgmt->bssid, ie, ie_len,
2559 data->rx_mgmt.ssi_signal);
2562 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2565 #endif /* CONFIG_AP */
2566 case EVENT_RX_ACTION:
2567 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2568 " Category=%u DataLen=%d freq=%d MHz",
2569 MAC2STR(data->rx_action.sa),
2570 data->rx_action.category, (int) data->rx_action.len,
2571 data->rx_action.freq);
2572 #ifdef CONFIG_IEEE80211R
2573 if (data->rx_action.category == WLAN_ACTION_FT) {
2574 ft_rx_action(wpa_s, data->rx_action.data,
2575 data->rx_action.len);
2578 #endif /* CONFIG_IEEE80211R */
2579 #ifdef CONFIG_IEEE80211W
2581 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2582 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2583 data->rx_action.data,
2584 data->rx_action.len);
2587 #endif /* CONFIG_SME */
2588 #endif /* CONFIG_IEEE80211W */
2590 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2591 gas_query_rx(wpa_s->gas, data->rx_action.da,
2592 data->rx_action.sa, data->rx_action.bssid,
2593 data->rx_action.data, data->rx_action.len,
2594 data->rx_action.freq) == 0)
2596 #endif /* CONFIG_GAS */
2597 if (data->rx_action.category == WLAN_ACTION_WNM) {
2598 wnm_action_rx(wpa_s, &data->rx_action);
2602 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2603 data->rx_action.len >= 4 &&
2604 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2605 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2606 "Response from " MACSTR,
2607 MAC2STR(data->rx_action.sa));
2610 #endif /* CONFIG_TDLS */
2612 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2614 data->rx_action.bssid,
2615 data->rx_action.category,
2616 data->rx_action.data,
2617 data->rx_action.len, data->rx_action.freq);
2618 #endif /* CONFIG_P2P */
2620 case EVENT_RX_PROBE_REQ:
2621 if (data->rx_probe_req.sa == NULL ||
2622 data->rx_probe_req.ie == NULL)
2625 if (wpa_s->ap_iface) {
2626 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2627 data->rx_probe_req.sa,
2628 data->rx_probe_req.da,
2629 data->rx_probe_req.bssid,
2630 data->rx_probe_req.ie,
2631 data->rx_probe_req.ie_len,
2632 data->rx_probe_req.ssi_signal);
2635 #endif /* CONFIG_AP */
2637 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2638 data->rx_probe_req.da,
2639 data->rx_probe_req.bssid,
2640 data->rx_probe_req.ie,
2641 data->rx_probe_req.ie_len,
2642 data->rx_probe_req.ssi_signal);
2643 #endif /* CONFIG_P2P */
2645 case EVENT_REMAIN_ON_CHANNEL:
2646 #ifdef CONFIG_OFFCHANNEL
2647 offchannel_remain_on_channel_cb(
2648 wpa_s, data->remain_on_channel.freq,
2649 data->remain_on_channel.duration);
2650 #endif /* CONFIG_OFFCHANNEL */
2652 wpas_p2p_remain_on_channel_cb(
2653 wpa_s, data->remain_on_channel.freq,
2654 data->remain_on_channel.duration);
2655 #endif /* CONFIG_P2P */
2657 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2658 #ifdef CONFIG_OFFCHANNEL
2659 offchannel_cancel_remain_on_channel_cb(
2660 wpa_s, data->remain_on_channel.freq);
2661 #endif /* CONFIG_OFFCHANNEL */
2663 wpas_p2p_cancel_remain_on_channel_cb(
2664 wpa_s, data->remain_on_channel.freq);
2665 #endif /* CONFIG_P2P */
2668 case EVENT_P2P_DEV_FOUND: {
2669 struct p2p_peer_info peer_info;
2671 os_memset(&peer_info, 0, sizeof(peer_info));
2672 if (data->p2p_dev_found.dev_addr)
2673 os_memcpy(peer_info.p2p_device_addr,
2674 data->p2p_dev_found.dev_addr, ETH_ALEN);
2675 if (data->p2p_dev_found.pri_dev_type)
2676 os_memcpy(peer_info.pri_dev_type,
2677 data->p2p_dev_found.pri_dev_type,
2678 sizeof(peer_info.pri_dev_type));
2679 if (data->p2p_dev_found.dev_name)
2680 os_strlcpy(peer_info.device_name,
2681 data->p2p_dev_found.dev_name,
2682 sizeof(peer_info.device_name));
2683 peer_info.config_methods = data->p2p_dev_found.config_methods;
2684 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2685 peer_info.group_capab = data->p2p_dev_found.group_capab;
2688 * FIX: new_device=1 is not necessarily correct. We should
2689 * maintain a P2P peer database in wpa_supplicant and update
2690 * this information based on whether the peer is truly new.
2692 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2695 case EVENT_P2P_GO_NEG_REQ_RX:
2696 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2697 data->p2p_go_neg_req_rx.dev_passwd_id);
2699 case EVENT_P2P_GO_NEG_COMPLETED:
2700 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2702 case EVENT_P2P_PROV_DISC_REQUEST:
2703 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2704 data->p2p_prov_disc_req.config_methods,
2705 data->p2p_prov_disc_req.dev_addr,
2706 data->p2p_prov_disc_req.pri_dev_type,
2707 data->p2p_prov_disc_req.dev_name,
2708 data->p2p_prov_disc_req.supp_config_methods,
2709 data->p2p_prov_disc_req.dev_capab,
2710 data->p2p_prov_disc_req.group_capab,
2713 case EVENT_P2P_PROV_DISC_RESPONSE:
2714 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2715 data->p2p_prov_disc_resp.config_methods);
2717 case EVENT_P2P_SD_REQUEST:
2718 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2719 data->p2p_sd_req.sa,
2720 data->p2p_sd_req.dialog_token,
2721 data->p2p_sd_req.update_indic,
2722 data->p2p_sd_req.tlvs,
2723 data->p2p_sd_req.tlvs_len);
2725 case EVENT_P2P_SD_RESPONSE:
2726 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2727 data->p2p_sd_resp.update_indic,
2728 data->p2p_sd_resp.tlvs,
2729 data->p2p_sd_resp.tlvs_len);
2731 #endif /* CONFIG_P2P */
2732 case EVENT_EAPOL_RX:
2733 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2734 data->eapol_rx.data,
2735 data->eapol_rx.data_len);
2737 case EVENT_SIGNAL_CHANGE:
2738 bgscan_notify_signal_change(
2739 wpa_s, data->signal_change.above_threshold,
2740 data->signal_change.current_signal,
2741 data->signal_change.current_noise,
2742 data->signal_change.current_txrate);
2744 case EVENT_INTERFACE_ENABLED:
2745 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2746 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2747 wpa_supplicant_update_mac_addr(wpa_s);
2749 if (!wpa_s->ap_iface) {
2750 wpa_supplicant_set_state(wpa_s,
2752 wpa_supplicant_req_scan(wpa_s, 0, 0);
2754 wpa_supplicant_set_state(wpa_s,
2756 #else /* CONFIG_AP */
2757 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2758 wpa_supplicant_req_scan(wpa_s, 0, 0);
2759 #endif /* CONFIG_AP */
2762 case EVENT_INTERFACE_DISABLED:
2763 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2764 wpa_supplicant_mark_disassoc(wpa_s);
2765 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2767 case EVENT_CHANNEL_LIST_CHANGED:
2768 if (wpa_s->drv_priv == NULL)
2769 break; /* Ignore event during drv initialization */
2771 free_hw_features(wpa_s);
2772 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2773 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2776 wpas_p2p_update_channel_list(wpa_s);
2777 #endif /* CONFIG_P2P */
2779 case EVENT_INTERFACE_UNAVAILABLE:
2781 wpas_p2p_interface_unavailable(wpa_s);
2782 #endif /* CONFIG_P2P */
2784 case EVENT_BEST_CHANNEL:
2785 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2787 data->best_chan.freq_24, data->best_chan.freq_5,
2788 data->best_chan.freq_overall);
2789 wpa_s->best_24_freq = data->best_chan.freq_24;
2790 wpa_s->best_5_freq = data->best_chan.freq_5;
2791 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2793 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2794 data->best_chan.freq_5,
2795 data->best_chan.freq_overall);
2796 #endif /* CONFIG_P2P */
2798 case EVENT_UNPROT_DEAUTH:
2799 wpa_supplicant_event_unprot_deauth(wpa_s,
2800 &data->unprot_deauth);
2802 case EVENT_UNPROT_DISASSOC:
2803 wpa_supplicant_event_unprot_disassoc(wpa_s,
2804 &data->unprot_disassoc);
2806 case EVENT_STATION_LOW_ACK:
2808 if (wpa_s->ap_iface && data)
2809 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2810 data->low_ack.addr);
2811 #endif /* CONFIG_AP */
2814 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2815 #endif /* CONFIG_TDLS */
2817 case EVENT_IBSS_PEER_LOST:
2818 #ifdef CONFIG_IBSS_RSN
2819 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2820 #endif /* CONFIG_IBSS_RSN */
2822 case EVENT_DRIVER_GTK_REKEY:
2823 if (os_memcmp(data->driver_gtk_rekey.bssid,
2824 wpa_s->bssid, ETH_ALEN))
2828 wpa_sm_update_replay_ctr(wpa_s->wpa,
2829 data->driver_gtk_rekey.replay_ctr);
2831 case EVENT_SCHED_SCAN_STOPPED:
2832 wpa_s->sched_scanning = 0;
2833 wpa_supplicant_notify_scanning(wpa_s, 0);
2835 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2839 * If we timed out, start a new sched scan to continue
2840 * searching for more SSIDs.
2842 if (wpa_s->sched_scan_timed_out)
2843 wpa_supplicant_req_sched_scan(wpa_s);
2845 case EVENT_WPS_BUTTON_PUSHED:
2847 wpas_wps_start_pbc(wpa_s, NULL, 0);
2848 #endif /* CONFIG_WPS */
2851 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);