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"
41 #include "offchannel.h"
44 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
46 struct wpa_ssid *ssid, *old_ssid;
48 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
51 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
53 ssid = wpa_supplicant_get_ssid(wpa_s);
55 wpa_msg(wpa_s, MSG_INFO,
56 "No network configuration found for the current AP");
61 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
65 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
67 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
69 size_t wpa_ie_len = sizeof(wpa_ie);
70 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
73 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
76 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
77 eapol_sm_invalidate_cached_session(wpa_s->eapol);
78 old_ssid = wpa_s->current_ssid;
79 wpa_s->current_ssid = ssid;
80 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
81 wpa_supplicant_initiate_eapol(wpa_s);
82 if (old_ssid != wpa_s->current_ssid)
83 wpas_notify_network_changed(wpa_s);
89 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
91 struct wpa_supplicant *wpa_s = eloop_ctx;
93 if (wpa_s->countermeasures) {
94 wpa_s->countermeasures = 0;
95 wpa_drv_set_countermeasures(wpa_s, 0);
96 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
97 wpa_supplicant_req_scan(wpa_s, 0, 0);
102 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
106 #ifdef CONFIG_IBSS_RSN
107 ibss_rsn_deinit(wpa_s->ibss_rsn);
108 wpa_s->ibss_rsn = NULL;
109 #endif /* CONFIG_IBSS_RSN */
112 wpa_supplicant_ap_deinit(wpa_s);
113 #endif /* CONFIG_AP */
115 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
118 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
119 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
120 os_memset(wpa_s->bssid, 0, ETH_ALEN);
121 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
123 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
124 #endif /* CONFIG_P2P */
125 wpa_s->current_bss = NULL;
126 wpa_s->assoc_freq = 0;
127 #ifdef CONFIG_IEEE80211R
129 if (wpa_s->sme.ft_ies)
130 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
131 #endif /* CONFIG_SME */
132 #endif /* CONFIG_IEEE80211R */
135 wpas_notify_bssid_changed(wpa_s);
137 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
138 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
139 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
140 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
141 wpa_s->ap_ies_from_associnfo = 0;
145 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
147 struct wpa_ie_data ie;
151 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
155 for (i = 0; i < ie.num_pmkid; i++) {
156 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
157 ie.pmkid + i * PMKID_LEN,
159 if (pmksa_set == 0) {
160 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
165 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
166 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
170 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
171 union wpa_event_data *data)
174 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
178 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
179 " index=%d preauth=%d",
180 MAC2STR(data->pmkid_candidate.bssid),
181 data->pmkid_candidate.index,
182 data->pmkid_candidate.preauth);
184 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
185 data->pmkid_candidate.index,
186 data->pmkid_candidate.preauth);
190 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
192 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
193 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
196 #ifdef IEEE8021X_EAPOL
197 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
198 wpa_s->current_ssid &&
199 !(wpa_s->current_ssid->eapol_flags &
200 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
201 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
202 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
203 * plaintext or static WEP keys). */
206 #endif /* IEEE8021X_EAPOL */
213 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
214 * @wpa_s: pointer to wpa_supplicant data
215 * @ssid: Configuration data for the network
216 * Returns: 0 on success, -1 on failure
218 * This function is called when starting authentication with a network that is
219 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
221 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
222 struct wpa_ssid *ssid)
224 #ifdef IEEE8021X_EAPOL
226 int aka = 0, sim = 0, type;
228 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
231 if (ssid->eap.eap_methods == NULL) {
235 struct eap_method_type *eap = ssid->eap.eap_methods;
236 while (eap->vendor != EAP_VENDOR_IETF ||
237 eap->method != EAP_TYPE_NONE) {
238 if (eap->vendor == EAP_VENDOR_IETF) {
239 if (eap->method == EAP_TYPE_SIM)
241 else if (eap->method == EAP_TYPE_AKA)
248 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
250 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
254 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
255 "use SIM, but neither EAP-SIM nor EAP-AKA are "
260 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
261 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
263 type = SCARD_TRY_BOTH;
265 type = SCARD_USIM_ONLY;
267 type = SCARD_GSM_SIM_ONLY;
269 wpa_s->scard = scard_init(type);
270 if (wpa_s->scard == NULL) {
271 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
275 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
276 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
277 #endif /* PCSC_FUNCS */
278 #endif /* IEEE8021X_EAPOL */
284 #ifndef CONFIG_NO_SCAN_PROCESSING
285 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
286 struct wpa_ssid *ssid)
290 if (ssid->mixed_cell)
294 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
296 #endif /* CONFIG_WPS */
298 for (i = 0; i < NUM_WEP_KEYS; i++) {
299 if (ssid->wep_key_len[i]) {
304 #ifdef IEEE8021X_EAPOL
305 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
306 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
307 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
309 #endif /* IEEE8021X_EAPOL */
311 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
314 if (bss->caps & IEEE80211_CAP_PRIVACY)
320 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
321 struct wpa_ssid *ssid,
322 struct wpa_scan_res *bss)
324 struct wpa_ie_data ie;
326 const u8 *rsn_ie, *wpa_ie;
330 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
334 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
335 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
336 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
337 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
338 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
340 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
341 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
344 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
345 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
351 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
353 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
358 if (!(ie.proto & ssid->proto)) {
359 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
364 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
365 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
370 if (!(ie.group_cipher & ssid->group_cipher)) {
371 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
376 if (!(ie.key_mgmt & ssid->key_mgmt)) {
377 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
382 #ifdef CONFIG_IEEE80211W
383 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
384 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
385 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
389 #endif /* CONFIG_IEEE80211W */
391 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
395 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
396 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
399 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
400 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
406 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
408 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
413 if (!(ie.proto & ssid->proto)) {
414 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
419 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
420 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
425 if (!(ie.group_cipher & ssid->group_cipher)) {
426 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
431 if (!(ie.key_mgmt & ssid->key_mgmt)) {
432 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
437 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
441 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
442 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
443 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
447 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
448 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
452 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
459 static int freq_allowed(int *freqs, int freq)
466 for (i = 0; freqs[i]; i++)
467 if (freqs[i] == freq)
473 static int ht_supported(const struct hostapd_hw_modes *mode)
475 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
477 * The driver did not indicate whether it supports HT. Assume
478 * it does to avoid connection issues.
484 * IEEE Std 802.11n-2009 20.1.1:
485 * An HT non-AP STA shall support all EQM rates for one spatial stream.
487 return mode->mcs_set[0] == 0xff;
491 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
493 const struct hostapd_hw_modes *mode = NULL, *modes;
494 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
499 return 1; /* Cannot do matching without knowing band */
501 modes = wpa_s->hw.modes;
504 * The driver does not provide any additional information
505 * about the utilized hardware, so allow the connection attempt
511 for (i = 0; i < wpa_s->hw.num_modes; i++) {
512 for (j = 0; j < modes[i].num_channels; j++) {
513 int freq = modes[i].channels[j].freq;
514 if (freq == bss->freq) {
516 mode->mode == HOSTAPD_MODE_IEEE80211G)
517 break; /* do not allow 802.11b replace
528 for (i = 0; i < (int) sizeof(scan_ie); i++) {
529 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
533 for (j = 2; j < rate_ie[1] + 2; j++) {
534 int flagged = !!(rate_ie[j] & 0x80);
535 int r = (rate_ie[j] & 0x7f) * 5;
538 * IEEE Std 802.11n-2009 7.3.2.2:
539 * The new BSS Membership selector value is encoded
540 * like a legacy basic rate, but it is not a rate and
541 * only indicates if the BSS members are required to
542 * support the mandatory features of Clause 20 [HT PHY]
543 * in order to join the BSS.
545 if (flagged && ((rate_ie[j] & 0x7f) ==
546 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
547 if (!ht_supported(mode)) {
548 wpa_dbg(wpa_s, MSG_DEBUG,
549 " hardware does not support "
559 /* check for legacy basic rates */
560 for (k = 0; k < mode->num_rates; k++) {
561 if (mode->rates[k] == r)
564 if (k == mode->num_rates) {
566 * IEEE Std 802.11-2007 7.3.2.2 demands that in
567 * order to join a BSS all required rates
568 * have to be supported by the hardware.
570 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
571 "not support required rate %d.%d Mbps",
582 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
583 int i, struct wpa_scan_res *bss,
584 struct wpa_ssid *group)
587 u8 wpa_ie_len, rsn_ie_len, ssid_len;
589 struct wpa_blacklist *e;
591 struct wpa_ssid *ssid;
593 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
594 ssid_ = ie ? ie + 2 : (u8 *) "";
595 ssid_len = ie ? ie[1] : 0;
597 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
598 wpa_ie_len = ie ? ie[1] : 0;
600 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
601 rsn_ie_len = ie ? ie[1] : 0;
603 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
604 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
605 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
606 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
607 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
609 e = wpa_blacklist_get(wpa_s, bss->bssid);
612 if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
614 * When only a single network is enabled, we can
615 * trigger blacklisting on the first failure. This
616 * should not be done with multiple enabled networks to
617 * avoid getting forced to move into a worse ESS on
618 * single error if there are no other BSSes of the
623 if (e->count > limit) {
624 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
625 "(count=%d limit=%d)", e->count, limit);
631 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
635 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
637 for (ssid = group; ssid; ssid = ssid->pnext) {
638 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
640 if (ssid->disabled) {
641 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
646 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
647 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
652 if (wpa && ssid->ssid_len == 0 &&
653 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
656 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
657 /* Only allow wildcard SSID match if an AP
658 * advertises active WPS operation that matches
661 if (ssid->ssid_len == 0 &&
662 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
665 #endif /* CONFIG_WPS */
667 if (ssid->bssid_set && ssid->ssid_len == 0 &&
668 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
672 (ssid_len != ssid->ssid_len ||
673 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
674 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
678 if (ssid->bssid_set &&
679 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
680 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
684 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
688 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
689 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
690 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
691 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
696 if (!wpa_supplicant_match_privacy(bss, ssid)) {
697 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
702 if (bss->caps & IEEE80211_CAP_IBSS) {
703 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
708 if (!freq_allowed(ssid->freq_list, bss->freq)) {
709 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
714 if (!rate_match(wpa_s, bss)) {
715 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
722 * TODO: skip the AP if its P2P IE has Group Formation
723 * bit set in the P2P Group Capability Bitmap and we
724 * are not in Group Formation with that device.
726 #endif /* CONFIG_P2P */
728 /* Matching configuration found */
732 /* No matching configuration found */
737 static struct wpa_bss *
738 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
739 struct wpa_scan_results *scan_res,
740 struct wpa_ssid *group,
741 struct wpa_ssid **selected_ssid)
745 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
748 for (i = 0; i < scan_res->num; i++) {
749 struct wpa_scan_res *bss = scan_res->res[i];
753 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
757 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
758 ssid = ie ? ie + 2 : (u8 *) "";
759 ssid_len = ie ? ie[1] : 0;
761 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
763 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
764 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
771 static struct wpa_bss *
772 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
773 struct wpa_scan_results *scan_res,
774 struct wpa_ssid **selected_ssid)
776 struct wpa_bss *selected = NULL;
779 while (selected == NULL) {
780 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
781 selected = wpa_supplicant_select_bss(
782 wpa_s, scan_res, wpa_s->conf->pssid[prio],
788 if (selected == NULL && wpa_s->blacklist &&
789 !wpa_s->countermeasures) {
790 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
791 "blacklist and try again");
792 wpa_blacklist_clear(wpa_s);
793 wpa_s->blacklist_cleared++;
794 } else if (selected == NULL)
802 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
803 int timeout_sec, int timeout_usec)
805 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
807 * No networks are enabled; short-circuit request so
808 * we don't wait timeout seconds before transitioning
811 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
814 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
818 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
819 struct wpa_bss *selected,
820 struct wpa_ssid *ssid)
822 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
823 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
824 "PBC session overlap");
826 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
828 #endif /* CONFIG_P2P */
831 wpas_wps_cancel(wpa_s);
832 #endif /* CONFIG_WPS */
837 * Do not trigger new association unless the BSSID has changed or if
838 * reassociation is requested. If we are in process of associating with
839 * the selected BSSID, do not trigger new attempt.
841 if (wpa_s->reassociate ||
842 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
843 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
844 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
845 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
847 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
848 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
851 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
852 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
853 " pending: " MACSTR " wpa_state: %s",
854 wpa_s->reassociate, MAC2STR(selected->bssid),
855 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
856 wpa_supplicant_state_txt(wpa_s->wpa_state));
857 wpa_supplicant_associate(wpa_s, selected, ssid);
859 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
867 static struct wpa_ssid *
868 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
871 struct wpa_ssid *ssid;
873 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
874 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
878 if (ssid->mode == IEEE80211_MODE_IBSS ||
879 ssid->mode == IEEE80211_MODE_AP)
887 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
888 * on BSS added and BSS changed events */
889 static void wpa_supplicant_rsn_preauth_scan_results(
890 struct wpa_supplicant *wpa_s)
894 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
897 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
898 const u8 *ssid, *rsn;
900 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
904 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
908 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
914 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
915 struct wpa_bss *selected,
916 struct wpa_ssid *ssid,
917 struct wpa_scan_results *scan_res)
920 struct wpa_scan_res *current_bss = NULL;
923 if (wpa_s->reassociate)
924 return 1; /* explicit request to reassociate */
925 if (wpa_s->wpa_state < WPA_ASSOCIATED)
926 return 1; /* we are not associated; continue */
927 if (wpa_s->current_ssid == NULL)
928 return 1; /* unknown current SSID */
929 if (wpa_s->current_ssid != ssid)
930 return 1; /* different network block */
932 if (wpas_driver_bss_selection(wpa_s))
933 return 0; /* Driver-based roaming */
935 for (i = 0; i < scan_res->num; i++) {
936 struct wpa_scan_res *res = scan_res->res[i];
938 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
941 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
944 if (ie[1] != wpa_s->current_ssid->ssid_len ||
945 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
952 return 1; /* current BSS not seen in scan results */
954 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
955 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
956 MAC2STR(current_bss->bssid), current_bss->level);
957 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
958 MAC2STR(selected->bssid), selected->level);
960 if (wpa_s->current_ssid->bssid_set &&
961 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
963 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
964 "has preferred BSSID");
969 if (current_bss->level < 0) {
970 if (current_bss->level < -85)
972 else if (current_bss->level < -80)
974 else if (current_bss->level < -75)
976 else if (current_bss->level < -70)
981 if (abs(current_bss->level - selected->level) < min_diff) {
982 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
991 /* Return < 0 if no scan results could be fetched. */
992 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
993 union wpa_event_data *data)
995 struct wpa_bss *selected;
996 struct wpa_ssid *ssid = NULL;
997 struct wpa_scan_results *scan_res;
1001 if (wpa_s->ap_iface)
1003 #endif /* CONFIG_AP */
1005 wpa_supplicant_notify_scanning(wpa_s, 0);
1008 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1009 wpa_s->global->p2p != NULL) {
1010 wpa_s->p2p_cb_on_scan_complete = 0;
1011 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1012 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1013 "stopped scan processing");
1017 #endif /* CONFIG_P2P */
1019 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1020 data ? &data->scan_info :
1022 if (scan_res == NULL) {
1023 if (wpa_s->conf->ap_scan == 2 || ap)
1025 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1027 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1031 #ifndef CONFIG_NO_RANDOM_POOL
1033 num = scan_res->num;
1036 for (i = 0; i < num; i++) {
1038 struct wpa_scan_res *res = scan_res->res[i];
1039 buf[0] = res->bssid[5];
1040 buf[1] = res->qual & 0xff;
1041 buf[2] = res->noise & 0xff;
1042 buf[3] = res->level & 0xff;
1043 buf[4] = res->tsf & 0xff;
1044 random_add_randomness(buf, sizeof(buf));
1046 #endif /* CONFIG_NO_RANDOM_POOL */
1048 if (wpa_s->scan_res_handler) {
1049 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1050 struct wpa_scan_results *scan_res);
1052 scan_res_handler = wpa_s->scan_res_handler;
1053 wpa_s->scan_res_handler = NULL;
1054 scan_res_handler(wpa_s, scan_res);
1056 wpa_scan_results_free(scan_res);
1061 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1063 if (wpa_s->ap_iface->scan_cb)
1064 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1065 #endif /* CONFIG_AP */
1066 wpa_scan_results_free(scan_res);
1070 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1071 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1072 wpas_notify_scan_results(wpa_s);
1074 wpas_notify_scan_done(wpa_s, 1);
1076 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1077 wpa_scan_results_free(scan_res);
1081 if (wpa_s->disconnected) {
1082 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1083 wpa_scan_results_free(scan_res);
1087 if (!wpas_driver_bss_selection(wpa_s) &&
1088 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1089 wpa_scan_results_free(scan_res);
1093 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1097 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1099 wpa_scan_results_free(scan_res);
1101 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1105 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1106 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1109 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1111 wpa_scan_results_free(scan_res);
1112 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1113 ssid = wpa_supplicant_pick_new_network(wpa_s);
1115 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1116 wpa_supplicant_associate(wpa_s, NULL, ssid);
1117 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1119 int timeout_sec = wpa_s->scan_interval;
1120 int timeout_usec = 0;
1122 if (wpa_s->p2p_in_provisioning) {
1124 * Use shorter wait during P2P Provisioning
1125 * state to speed up group formation.
1128 timeout_usec = 250000;
1129 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1133 #endif /* CONFIG_P2P */
1134 if (wpa_supplicant_req_sched_scan(wpa_s))
1135 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1143 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1144 union wpa_event_data *data)
1146 const char *rn, *rn2;
1147 struct wpa_supplicant *ifs;
1149 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1151 * If no scan results could be fetched, then no need to
1152 * notify those interfaces that did not actually request
1159 * Check other interfaces to see if they have the same radio-name. If
1160 * so, they get updated with this same scan info.
1162 if (!wpa_s->driver->get_radio_name)
1165 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1166 if (rn == NULL || rn[0] == '\0')
1169 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1170 "sharing same radio (%s) in event_scan_results", rn);
1172 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1173 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1176 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1177 if (rn2 && os_strcmp(rn, rn2) == 0) {
1178 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1179 "sibling", ifs->ifname);
1180 _wpa_supplicant_event_scan_results(ifs, data);
1185 #endif /* CONFIG_NO_SCAN_PROCESSING */
1188 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1189 union wpa_event_data *data)
1191 int l, len, found = 0, wpa_found, rsn_found;
1194 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1195 if (data->assoc_info.req_ies)
1196 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1197 data->assoc_info.req_ies_len);
1198 if (data->assoc_info.resp_ies) {
1199 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1200 data->assoc_info.resp_ies_len);
1202 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1203 data->assoc_info.resp_ies_len);
1204 #endif /* CONFIG_TDLS */
1206 if (data->assoc_info.beacon_ies)
1207 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1208 data->assoc_info.beacon_ies,
1209 data->assoc_info.beacon_ies_len);
1210 if (data->assoc_info.freq)
1211 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1212 data->assoc_info.freq);
1214 p = data->assoc_info.req_ies;
1215 l = data->assoc_info.req_ies_len;
1217 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1218 while (p && l >= 2) {
1221 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1225 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1226 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1227 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1228 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1231 wpa_find_assoc_pmkid(wpa_s);
1237 if (!found && data->assoc_info.req_ies)
1238 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1240 #ifdef CONFIG_IEEE80211R
1242 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1244 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1245 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1246 data->assoc_info.resp_ies,
1247 data->assoc_info.resp_ies_len,
1249 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1250 "Reassociation Response failed");
1251 wpa_supplicant_deauthenticate(
1252 wpa_s, WLAN_REASON_INVALID_IE);
1257 p = data->assoc_info.resp_ies;
1258 l = data->assoc_info.resp_ies_len;
1260 #ifdef CONFIG_WPS_STRICT
1261 if (p && wpa_s->current_ssid &&
1262 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1264 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1266 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1267 "include WPS IE in (Re)Association Response");
1271 if (wps_validate_assoc_resp(wps) < 0) {
1273 wpa_supplicant_deauthenticate(
1274 wpa_s, WLAN_REASON_INVALID_IE);
1279 #endif /* CONFIG_WPS_STRICT */
1281 /* Go through the IEs and make a copy of the MDIE, if present. */
1282 while (p && l >= 2) {
1285 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1289 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1290 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1291 wpa_s->sme.ft_used = 1;
1292 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1293 MOBILITY_DOMAIN_ID_LEN);
1299 #endif /* CONFIG_SME */
1301 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1302 data->assoc_info.resp_ies_len);
1303 #endif /* CONFIG_IEEE80211R */
1305 /* WPA/RSN IE from Beacon/ProbeResp */
1306 p = data->assoc_info.beacon_ies;
1307 l = data->assoc_info.beacon_ies_len;
1309 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1311 wpa_found = rsn_found = 0;
1312 while (p && l >= 2) {
1315 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1320 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1321 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1323 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1327 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1329 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1336 if (!wpa_found && data->assoc_info.beacon_ies)
1337 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1338 if (!rsn_found && data->assoc_info.beacon_ies)
1339 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1340 if (wpa_found || rsn_found)
1341 wpa_s->ap_ies_from_associnfo = 1;
1343 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1344 wpa_s->assoc_freq != data->assoc_info.freq) {
1345 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1347 wpa_s->assoc_freq, data->assoc_info.freq);
1348 wpa_supplicant_update_scan_results(wpa_s);
1351 wpa_s->assoc_freq = data->assoc_info.freq;
1357 static struct wpa_bss * wpa_supplicant_get_new_bss(
1358 struct wpa_supplicant *wpa_s, const u8 *bssid)
1360 struct wpa_bss *bss = NULL;
1361 struct wpa_ssid *ssid = wpa_s->current_ssid;
1363 if (ssid->ssid_len > 0)
1364 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1366 bss = wpa_bss_get_bssid(wpa_s, bssid);
1372 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1374 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1376 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1379 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1382 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1383 WPA_IE_VENDOR_TYPE);
1384 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1386 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1387 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1388 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1389 bss_rsn ? 2 + bss_rsn[1] : 0))
1396 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1397 union wpa_event_data *data)
1402 struct wpa_driver_capa capa;
1405 if (wpa_s->ap_iface) {
1406 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1407 data->assoc_info.addr,
1408 data->assoc_info.req_ies,
1409 data->assoc_info.req_ies_len,
1410 data->assoc_info.reassoc);
1413 #endif /* CONFIG_AP */
1415 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1416 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1419 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1420 if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1421 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1422 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1423 MACSTR, MAC2STR(bssid));
1424 random_add_randomness(bssid, ETH_ALEN);
1425 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1426 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1427 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1429 wpas_notify_bssid_changed(wpa_s);
1431 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1432 wpa_clear_keys(wpa_s, bssid);
1434 if (wpa_supplicant_select_config(wpa_s) < 0) {
1435 wpa_supplicant_disassociate(
1436 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1439 if (wpa_s->current_ssid) {
1440 struct wpa_bss *bss = NULL;
1442 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1444 wpa_supplicant_update_scan_results(wpa_s);
1446 /* Get the BSS from the new scan results */
1447 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1451 wpa_s->current_bss = bss;
1454 if (wpa_s->conf->ap_scan == 1 &&
1455 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1456 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1457 wpa_msg(wpa_s, MSG_WARNING,
1458 "WPA/RSN IEs not updated");
1463 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1464 wpa_s->sme.prev_bssid_set = 1;
1465 #endif /* CONFIG_SME */
1467 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1468 if (wpa_s->current_ssid) {
1469 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1470 * initialized before association, but for other modes,
1471 * initialize PC/SC here, if the current configuration needs
1472 * smartcard or SIM/USIM. */
1473 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1475 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1477 l2_packet_notify_auth_start(wpa_s->l2);
1480 * Set portEnabled first to FALSE in order to get EAP state machine out
1481 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1482 * state machine may transit to AUTHENTICATING state based on obsolete
1483 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1484 * AUTHENTICATED without ever giving chance to EAP state machine to
1487 if (!ft_completed) {
1488 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1489 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1491 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1492 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1493 /* 802.1X::portControl = Auto */
1494 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1495 wpa_s->eapol_received = 0;
1496 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1497 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1498 (wpa_s->current_ssid &&
1499 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1500 wpa_supplicant_cancel_auth_timeout(wpa_s);
1501 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1502 } else if (!ft_completed) {
1503 /* Timeout for receiving the first EAPOL packet */
1504 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1506 wpa_supplicant_cancel_scan(wpa_s);
1508 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1509 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1511 * We are done; the driver will take care of RSN 4-way
1514 wpa_supplicant_cancel_auth_timeout(wpa_s);
1515 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1516 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1517 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1518 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1519 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1521 * The driver will take care of RSN 4-way handshake, so we need
1522 * to allow EAPOL supplicant to complete its work without
1523 * waiting for WPA supplicant.
1525 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1526 } else if (ft_completed) {
1528 * FT protocol completed - make sure EAPOL state machine ends
1529 * up in authenticated.
1531 wpa_supplicant_cancel_auth_timeout(wpa_s);
1532 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1533 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1534 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1537 if (wpa_s->pending_eapol_rx) {
1538 struct os_time now, age;
1540 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1541 if (age.sec == 0 && age.usec < 100000 &&
1542 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1544 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1545 "frame that was received just before "
1546 "association notification");
1547 wpa_supplicant_rx_eapol(
1548 wpa_s, wpa_s->pending_eapol_rx_src,
1549 wpabuf_head(wpa_s->pending_eapol_rx),
1550 wpabuf_len(wpa_s->pending_eapol_rx));
1552 wpabuf_free(wpa_s->pending_eapol_rx);
1553 wpa_s->pending_eapol_rx = NULL;
1556 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1557 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1558 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1559 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1560 /* Set static WEP keys again */
1561 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1564 #ifdef CONFIG_IBSS_RSN
1565 if (wpa_s->current_ssid &&
1566 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1567 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1568 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1569 wpa_s->ibss_rsn == NULL) {
1570 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1571 if (!wpa_s->ibss_rsn) {
1572 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1573 wpa_supplicant_deauthenticate(
1574 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1578 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1580 #endif /* CONFIG_IBSS_RSN */
1584 static int disconnect_reason_recoverable(u16 reason_code)
1586 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1587 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1588 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1592 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1594 int locally_generated)
1598 u8 prev_pending_bssid[ETH_ALEN];
1599 struct wpa_bss *fast_reconnect = NULL;
1600 struct wpa_ssid *fast_reconnect_ssid = NULL;
1602 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1603 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1605 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1607 * At least Host AP driver and a Prism3 card seemed to be
1608 * generating streams of disconnected events when configuring
1609 * IBSS for WPA-None. Ignore them for now.
1611 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1612 "IBSS/WPA-None mode");
1616 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1617 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1618 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1619 "pre-shared key may be incorrect");
1621 if (!wpa_s->auto_reconnect_disabled ||
1622 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1623 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1624 "reconnect (wps=%d wpa_state=%d)",
1625 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1627 if (wpa_s->wpa_state == WPA_COMPLETED &&
1628 wpa_s->current_ssid &&
1629 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1630 !locally_generated &&
1631 disconnect_reason_recoverable(reason_code)) {
1633 * It looks like the AP has dropped association with
1634 * us, but could allow us to get back in. Try to
1635 * reconnect to the same BSS without full scan to save
1636 * time for some common cases.
1638 fast_reconnect = wpa_s->current_bss;
1639 fast_reconnect_ssid = wpa_s->current_ssid;
1640 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1641 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1643 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1646 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1647 "try to re-connect");
1648 wpa_s->reassociate = 0;
1649 wpa_s->disconnected = 1;
1650 wpa_supplicant_cancel_sched_scan(wpa_s);
1652 bssid = wpa_s->bssid;
1653 if (is_zero_ether_addr(bssid))
1654 bssid = wpa_s->pending_bssid;
1655 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1656 wpas_connection_failed(wpa_s, bssid);
1657 wpa_sm_notify_disassoc(wpa_s->wpa);
1658 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1660 MAC2STR(bssid), reason_code);
1661 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1662 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1663 wpa_s->keys_cleared = 0;
1664 wpa_clear_keys(wpa_s, wpa_s->bssid);
1666 wpa_supplicant_mark_disassoc(wpa_s);
1668 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1669 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1671 if (fast_reconnect) {
1672 #ifndef CONFIG_NO_SCAN_PROCESSING
1673 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1674 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1675 fast_reconnect_ssid) < 0) {
1676 /* Recover through full scan */
1677 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1679 #endif /* CONFIG_NO_SCAN_PROCESSING */
1684 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1685 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1687 struct wpa_supplicant *wpa_s = eloop_ctx;
1689 if (!wpa_s->pending_mic_error_report)
1692 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1693 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1694 wpa_s->pending_mic_error_report = 0;
1696 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1700 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1701 union wpa_event_data *data)
1706 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1707 pairwise = (data && data->michael_mic_failure.unicast);
1709 if ((wpa_s->last_michael_mic_error &&
1710 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1711 wpa_s->pending_mic_error_report) {
1712 if (wpa_s->pending_mic_error_report) {
1714 * Send the pending MIC error report immediately since
1715 * we are going to start countermeasures and AP better
1718 wpa_sm_key_request(wpa_s->wpa, 1,
1719 wpa_s->pending_mic_error_pairwise);
1722 /* Send the new MIC error report immediately since we are going
1723 * to start countermeasures and AP better do the same.
1725 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1727 /* initialize countermeasures */
1728 wpa_s->countermeasures = 1;
1730 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1732 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1735 * Need to wait for completion of request frame. We do not get
1736 * any callback for the message completion, so just wait a
1737 * short while and hope for the best. */
1740 wpa_drv_set_countermeasures(wpa_s, 1);
1741 wpa_supplicant_deauthenticate(wpa_s,
1742 WLAN_REASON_MICHAEL_MIC_FAILURE);
1743 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1745 eloop_register_timeout(60, 0,
1746 wpa_supplicant_stop_countermeasures,
1748 /* TODO: mark the AP rejected for 60 second. STA is
1749 * allowed to associate with another AP.. */
1751 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1752 if (wpa_s->mic_errors_seen) {
1754 * Reduce the effectiveness of Michael MIC error
1755 * reports as a means for attacking against TKIP if
1756 * more than one MIC failure is noticed with the same
1757 * PTK. We delay the transmission of the reports by a
1758 * random time between 0 and 60 seconds in order to
1759 * force the attacker wait 60 seconds before getting
1760 * the information on whether a frame resulted in a MIC
1766 if (os_get_random(rval, sizeof(rval)) < 0)
1767 sec = os_random() % 60;
1769 sec = WPA_GET_BE32(rval) % 60;
1770 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1771 "report %d seconds", sec);
1772 wpa_s->pending_mic_error_report = 1;
1773 wpa_s->pending_mic_error_pairwise = pairwise;
1774 eloop_cancel_timeout(
1775 wpa_supplicant_delayed_mic_error_report,
1777 eloop_register_timeout(
1778 sec, os_random() % 1000000,
1779 wpa_supplicant_delayed_mic_error_report,
1782 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1784 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1785 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1786 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1788 wpa_s->last_michael_mic_error = t.sec;
1789 wpa_s->mic_errors_seen++;
1793 #ifdef CONFIG_TERMINATE_ONLASTIF
1794 static int any_interfaces(struct wpa_supplicant *head)
1796 struct wpa_supplicant *wpa_s;
1798 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1799 if (!wpa_s->interface_removed)
1803 #endif /* CONFIG_TERMINATE_ONLASTIF */
1807 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1808 union wpa_event_data *data)
1810 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1813 switch (data->interface_status.ievent) {
1814 case EVENT_INTERFACE_ADDED:
1815 if (!wpa_s->interface_removed)
1817 wpa_s->interface_removed = 0;
1818 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1819 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1820 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1821 "driver after interface was added");
1824 case EVENT_INTERFACE_REMOVED:
1825 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1826 wpa_s->interface_removed = 1;
1827 wpa_supplicant_mark_disassoc(wpa_s);
1828 l2_packet_deinit(wpa_s->l2);
1830 #ifdef CONFIG_IBSS_RSN
1831 ibss_rsn_deinit(wpa_s->ibss_rsn);
1832 wpa_s->ibss_rsn = NULL;
1833 #endif /* CONFIG_IBSS_RSN */
1834 #ifdef CONFIG_TERMINATE_ONLASTIF
1835 /* check if last interface */
1836 if (!any_interfaces(wpa_s->global->ifaces))
1838 #endif /* CONFIG_TERMINATE_ONLASTIF */
1844 #ifdef CONFIG_PEERKEY
1846 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1847 union wpa_event_data *data)
1851 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1853 #endif /* CONFIG_PEERKEY */
1857 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
1858 union wpa_event_data *data)
1862 switch (data->tdls.oper) {
1863 case TDLS_REQUEST_SETUP:
1864 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
1866 case TDLS_REQUEST_TEARDOWN:
1867 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
1868 data->tdls.reason_code);
1872 #endif /* CONFIG_TDLS */
1875 #ifdef CONFIG_IEEE80211R
1877 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1878 union wpa_event_data *data)
1883 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1884 data->ft_ies.ies_len,
1885 data->ft_ies.ft_action,
1886 data->ft_ies.target_ap,
1887 data->ft_ies.ric_ies,
1888 data->ft_ies.ric_ies_len) < 0) {
1889 /* TODO: prevent MLME/driver from trying to associate? */
1892 #endif /* CONFIG_IEEE80211R */
1895 #ifdef CONFIG_IBSS_RSN
1896 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1897 union wpa_event_data *data)
1899 struct wpa_ssid *ssid;
1900 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1904 ssid = wpa_s->current_ssid;
1907 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
1910 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1912 #endif /* CONFIG_IBSS_RSN */
1915 #ifdef CONFIG_IEEE80211R
1916 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1919 const u8 *sta_addr, *target_ap_addr;
1922 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1923 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1924 return; /* only SME case supported for now */
1925 if (len < 1 + 2 * ETH_ALEN + 2)
1928 return; /* Only FT Action Response is supported for now */
1929 sta_addr = data + 1;
1930 target_ap_addr = data + 1 + ETH_ALEN;
1931 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1932 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
1933 MACSTR " TargetAP " MACSTR " status %u",
1934 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1936 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1937 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1938 " in FT Action Response", MAC2STR(sta_addr));
1943 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
1944 "failure (status code %d)", status);
1945 /* TODO: report error to FT code(?) */
1949 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1950 len - (1 + 2 * ETH_ALEN + 2), 1,
1951 target_ap_addr, NULL, 0) < 0)
1956 struct wpa_bss *bss;
1957 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1959 wpa_s->sme.freq = bss->freq;
1960 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1961 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1964 #endif /* CONFIG_SME */
1966 #endif /* CONFIG_IEEE80211R */
1969 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
1970 struct unprot_deauth *e)
1972 #ifdef CONFIG_IEEE80211W
1973 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
1974 "dropped: " MACSTR " -> " MACSTR
1975 " (reason code %u)",
1976 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1977 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1978 #endif /* CONFIG_IEEE80211W */
1982 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
1983 struct unprot_disassoc *e)
1985 #ifdef CONFIG_IEEE80211W
1986 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
1987 "dropped: " MACSTR " -> " MACSTR
1988 " (reason code %u)",
1989 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1990 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1991 #endif /* CONFIG_IEEE80211W */
1995 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
1998 const u8 *pos, *end;
2000 if (rx->data == NULL || rx->len == 0)
2004 end = pos + rx->len;
2007 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2008 action, MAC2STR(rx->sa));
2010 case WNM_BSS_TRANS_MGMT_REQ:
2013 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2014 "Request: dialog_token=%u request_mode=0x%x "
2015 "disassoc_timer=%u validity_interval=%u",
2016 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2020 pos += 12; /* BSS Termination Duration */
2023 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2024 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2025 "Transition Management Request "
2029 os_memcpy(url, pos + 1, pos[0]);
2031 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2032 "Imminent - session_info_url=%s", url);
2039 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2040 union wpa_event_data *data)
2042 struct wpa_supplicant *wpa_s = ctx;
2043 u16 reason_code = 0;
2044 int locally_generated = 0;
2046 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2047 event != EVENT_INTERFACE_ENABLED &&
2048 event != EVENT_INTERFACE_STATUS &&
2049 event != EVENT_SCHED_SCAN_STOPPED) {
2050 wpa_dbg(wpa_s, MSG_DEBUG,
2051 "Ignore event %s (%d) while interface is disabled",
2052 event_to_string(event), event);
2056 #ifndef CONFIG_NO_STDOUT_DEBUG
2058 int level = MSG_DEBUG;
2060 if (event == EVENT_RX_MGMT && data && data->rx_mgmt.frame &&
2061 data->rx_mgmt.frame_len >= 24) {
2062 const struct ieee80211_hdr *hdr;
2064 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2065 fc = le_to_host16(hdr->frame_control);
2066 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2067 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2068 level = MSG_EXCESSIVE;
2071 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2072 event_to_string(event), event);
2074 #endif /* CONFIG_NO_STDOUT_DEBUG */
2078 sme_event_auth(wpa_s, data);
2081 wpa_supplicant_event_assoc(wpa_s, data);
2083 case EVENT_DISASSOC:
2084 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2086 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2087 data->disassoc_info.reason_code,
2088 data->disassoc_info.locally_generated ?
2089 " (locally generated)" : "");
2090 if (data->disassoc_info.addr)
2091 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2092 MAC2STR(data->disassoc_info.addr));
2095 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2096 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2097 data->disassoc_info.addr);
2100 if (wpa_s->ap_iface) {
2101 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2105 #endif /* CONFIG_AP */
2107 reason_code = data->disassoc_info.reason_code;
2109 data->disassoc_info.locally_generated;
2110 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2111 data->disassoc_info.ie,
2112 data->disassoc_info.ie_len);
2114 wpas_p2p_disassoc_notif(
2115 wpa_s, data->disassoc_info.addr, reason_code,
2116 data->disassoc_info.ie,
2117 data->disassoc_info.ie_len);
2118 #endif /* CONFIG_P2P */
2120 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2121 sme_event_disassoc(wpa_s, data);
2124 if (event == EVENT_DEAUTH) {
2125 wpa_dbg(wpa_s, MSG_DEBUG,
2126 "Deauthentication notification");
2128 reason_code = data->deauth_info.reason_code;
2130 data->deauth_info.locally_generated;
2131 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2132 data->deauth_info.reason_code,
2133 data->deauth_info.locally_generated ?
2134 " (locally generated)" : "");
2135 if (data->deauth_info.addr) {
2136 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2138 MAC2STR(data->deauth_info.
2141 wpa_hexdump(MSG_DEBUG,
2142 "Deauthentication frame IE(s)",
2143 data->deauth_info.ie,
2144 data->deauth_info.ie_len);
2146 wpas_p2p_deauth_notif(
2147 wpa_s, data->deauth_info.addr,
2149 data->deauth_info.ie,
2150 data->deauth_info.ie_len);
2151 #endif /* CONFIG_P2P */
2155 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2156 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2157 data->deauth_info.addr);
2160 if (wpa_s->ap_iface) {
2161 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2165 #endif /* CONFIG_AP */
2166 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2169 case EVENT_MICHAEL_MIC_FAILURE:
2170 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2172 #ifndef CONFIG_NO_SCAN_PROCESSING
2173 case EVENT_SCAN_RESULTS:
2174 wpa_supplicant_event_scan_results(wpa_s, data);
2176 #endif /* CONFIG_NO_SCAN_PROCESSING */
2177 case EVENT_ASSOCINFO:
2178 wpa_supplicant_event_associnfo(wpa_s, data);
2180 case EVENT_INTERFACE_STATUS:
2181 wpa_supplicant_event_interface_status(wpa_s, data);
2183 case EVENT_PMKID_CANDIDATE:
2184 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2186 #ifdef CONFIG_PEERKEY
2187 case EVENT_STKSTART:
2188 wpa_supplicant_event_stkstart(wpa_s, data);
2190 #endif /* CONFIG_PEERKEY */
2193 wpa_supplicant_event_tdls(wpa_s, data);
2195 #endif /* CONFIG_TDLS */
2196 #ifdef CONFIG_IEEE80211R
2197 case EVENT_FT_RESPONSE:
2198 wpa_supplicant_event_ft_response(wpa_s, data);
2200 #endif /* CONFIG_IEEE80211R */
2201 #ifdef CONFIG_IBSS_RSN
2202 case EVENT_IBSS_RSN_START:
2203 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2205 #endif /* CONFIG_IBSS_RSN */
2206 case EVENT_ASSOC_REJECT:
2207 if (data->assoc_reject.bssid)
2208 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2209 "bssid=" MACSTR " status_code=%u",
2210 MAC2STR(data->assoc_reject.bssid),
2211 data->assoc_reject.status_code);
2213 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2215 data->assoc_reject.status_code);
2216 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2217 sme_event_assoc_reject(wpa_s, data);
2219 case EVENT_AUTH_TIMED_OUT:
2220 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2221 sme_event_auth_timed_out(wpa_s, data);
2223 case EVENT_ASSOC_TIMED_OUT:
2224 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2225 sme_event_assoc_timed_out(wpa_s, data);
2227 case EVENT_TX_STATUS:
2228 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2229 " type=%d stype=%d",
2230 MAC2STR(data->tx_status.dst),
2231 data->tx_status.type, data->tx_status.stype);
2233 if (wpa_s->ap_iface == NULL) {
2234 #ifdef CONFIG_OFFCHANNEL
2235 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2236 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2237 offchannel_send_action_tx_status(
2238 wpa_s, data->tx_status.dst,
2239 data->tx_status.data,
2240 data->tx_status.data_len,
2241 data->tx_status.ack ?
2242 OFFCHANNEL_SEND_ACTION_SUCCESS :
2243 OFFCHANNEL_SEND_ACTION_NO_ACK);
2244 #endif /* CONFIG_OFFCHANNEL */
2247 #endif /* CONFIG_AP */
2248 #ifdef CONFIG_OFFCHANNEL
2249 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2250 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2252 * Catch TX status events for Action frames we sent via group
2253 * interface in GO mode.
2255 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2256 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2257 os_memcmp(wpa_s->parent->pending_action_dst,
2258 data->tx_status.dst, ETH_ALEN) == 0) {
2259 offchannel_send_action_tx_status(
2260 wpa_s->parent, data->tx_status.dst,
2261 data->tx_status.data,
2262 data->tx_status.data_len,
2263 data->tx_status.ack ?
2264 OFFCHANNEL_SEND_ACTION_SUCCESS :
2265 OFFCHANNEL_SEND_ACTION_NO_ACK);
2268 #endif /* CONFIG_OFFCHANNEL */
2270 switch (data->tx_status.type) {
2271 case WLAN_FC_TYPE_MGMT:
2272 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2273 data->tx_status.data_len,
2274 data->tx_status.stype,
2275 data->tx_status.ack);
2277 case WLAN_FC_TYPE_DATA:
2278 ap_tx_status(wpa_s, data->tx_status.dst,
2279 data->tx_status.data,
2280 data->tx_status.data_len,
2281 data->tx_status.ack);
2284 #endif /* CONFIG_AP */
2287 case EVENT_EAPOL_TX_STATUS:
2288 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2289 data->eapol_tx_status.data,
2290 data->eapol_tx_status.data_len,
2291 data->eapol_tx_status.ack);
2293 case EVENT_DRIVER_CLIENT_POLL_OK:
2294 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2296 case EVENT_RX_FROM_UNKNOWN:
2297 if (wpa_s->ap_iface == NULL)
2299 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2300 data->rx_from_unknown.wds);
2303 if (wpa_s->ap_iface == NULL) {
2306 const struct ieee80211_mgmt *mgmt;
2307 mgmt = (const struct ieee80211_mgmt *)
2308 data->rx_mgmt.frame;
2309 fc = le_to_host16(mgmt->frame_control);
2310 stype = WLAN_FC_GET_STYPE(fc);
2311 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2312 data->rx_mgmt.frame_len > 24) {
2313 const u8 *src = mgmt->sa;
2314 const u8 *ie = mgmt->u.probe_req.variable;
2315 size_t ie_len = data->rx_mgmt.frame_len -
2316 (mgmt->u.probe_req.variable -
2317 data->rx_mgmt.frame);
2318 wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da,
2319 mgmt->bssid, ie, ie_len);
2322 #endif /* CONFIG_P2P */
2323 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2324 "management frame in non-AP mode");
2327 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2329 #endif /* CONFIG_AP */
2330 case EVENT_RX_ACTION:
2331 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2332 " Category=%u DataLen=%d freq=%d MHz",
2333 MAC2STR(data->rx_action.sa),
2334 data->rx_action.category, (int) data->rx_action.len,
2335 data->rx_action.freq);
2336 #ifdef CONFIG_IEEE80211R
2337 if (data->rx_action.category == WLAN_ACTION_FT) {
2338 ft_rx_action(wpa_s, data->rx_action.data,
2339 data->rx_action.len);
2342 #endif /* CONFIG_IEEE80211R */
2343 #ifdef CONFIG_IEEE80211W
2345 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2346 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2347 data->rx_action.data,
2348 data->rx_action.len);
2351 #endif /* CONFIG_SME */
2352 #endif /* CONFIG_IEEE80211W */
2354 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2355 gas_query_rx(wpa_s->gas, data->rx_action.da,
2356 data->rx_action.sa, data->rx_action.bssid,
2357 data->rx_action.data, data->rx_action.len,
2358 data->rx_action.freq) == 0)
2360 #endif /* CONFIG_GAS */
2361 if (data->rx_action.category == WLAN_ACTION_WNM) {
2362 wnm_action_rx(wpa_s, &data->rx_action);
2366 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2367 data->rx_action.len >= 4 &&
2368 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2369 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2370 "Response from " MACSTR,
2371 MAC2STR(data->rx_action.sa));
2374 #endif /* CONFIG_TDLS */
2376 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2378 data->rx_action.bssid,
2379 data->rx_action.category,
2380 data->rx_action.data,
2381 data->rx_action.len, data->rx_action.freq);
2382 #endif /* CONFIG_P2P */
2384 case EVENT_RX_PROBE_REQ:
2385 if (data->rx_probe_req.sa == NULL ||
2386 data->rx_probe_req.ie == NULL)
2389 if (wpa_s->ap_iface) {
2390 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2391 data->rx_probe_req.sa,
2392 data->rx_probe_req.da,
2393 data->rx_probe_req.bssid,
2394 data->rx_probe_req.ie,
2395 data->rx_probe_req.ie_len);
2398 #endif /* CONFIG_AP */
2400 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2401 data->rx_probe_req.da,
2402 data->rx_probe_req.bssid,
2403 data->rx_probe_req.ie,
2404 data->rx_probe_req.ie_len);
2405 #endif /* CONFIG_P2P */
2407 case EVENT_REMAIN_ON_CHANNEL:
2408 #ifdef CONFIG_OFFCHANNEL
2409 offchannel_remain_on_channel_cb(
2410 wpa_s, data->remain_on_channel.freq,
2411 data->remain_on_channel.duration);
2412 #endif /* CONFIG_OFFCHANNEL */
2414 wpas_p2p_remain_on_channel_cb(
2415 wpa_s, data->remain_on_channel.freq,
2416 data->remain_on_channel.duration);
2417 #endif /* CONFIG_P2P */
2419 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2420 #ifdef CONFIG_OFFCHANNEL
2421 offchannel_cancel_remain_on_channel_cb(
2422 wpa_s, data->remain_on_channel.freq);
2423 #endif /* CONFIG_OFFCHANNEL */
2425 wpas_p2p_cancel_remain_on_channel_cb(
2426 wpa_s, data->remain_on_channel.freq);
2427 #endif /* CONFIG_P2P */
2430 case EVENT_P2P_DEV_FOUND: {
2431 struct p2p_peer_info peer_info;
2433 os_memset(&peer_info, 0, sizeof(peer_info));
2434 if (data->p2p_dev_found.dev_addr)
2435 os_memcpy(peer_info.p2p_device_addr,
2436 data->p2p_dev_found.dev_addr, ETH_ALEN);
2437 if (data->p2p_dev_found.pri_dev_type)
2438 os_memcpy(peer_info.pri_dev_type,
2439 data->p2p_dev_found.pri_dev_type,
2440 sizeof(peer_info.pri_dev_type));
2441 if (data->p2p_dev_found.dev_name)
2442 os_strlcpy(peer_info.device_name,
2443 data->p2p_dev_found.dev_name,
2444 sizeof(peer_info.device_name));
2445 peer_info.config_methods = data->p2p_dev_found.config_methods;
2446 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2447 peer_info.group_capab = data->p2p_dev_found.group_capab;
2450 * FIX: new_device=1 is not necessarily correct. We should
2451 * maintain a P2P peer database in wpa_supplicant and update
2452 * this information based on whether the peer is truly new.
2454 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2457 case EVENT_P2P_GO_NEG_REQ_RX:
2458 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2459 data->p2p_go_neg_req_rx.dev_passwd_id);
2461 case EVENT_P2P_GO_NEG_COMPLETED:
2462 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2464 case EVENT_P2P_PROV_DISC_REQUEST:
2465 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2466 data->p2p_prov_disc_req.config_methods,
2467 data->p2p_prov_disc_req.dev_addr,
2468 data->p2p_prov_disc_req.pri_dev_type,
2469 data->p2p_prov_disc_req.dev_name,
2470 data->p2p_prov_disc_req.supp_config_methods,
2471 data->p2p_prov_disc_req.dev_capab,
2472 data->p2p_prov_disc_req.group_capab,
2475 case EVENT_P2P_PROV_DISC_RESPONSE:
2476 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2477 data->p2p_prov_disc_resp.config_methods);
2479 case EVENT_P2P_SD_REQUEST:
2480 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2481 data->p2p_sd_req.sa,
2482 data->p2p_sd_req.dialog_token,
2483 data->p2p_sd_req.update_indic,
2484 data->p2p_sd_req.tlvs,
2485 data->p2p_sd_req.tlvs_len);
2487 case EVENT_P2P_SD_RESPONSE:
2488 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2489 data->p2p_sd_resp.update_indic,
2490 data->p2p_sd_resp.tlvs,
2491 data->p2p_sd_resp.tlvs_len);
2493 #endif /* CONFIG_P2P */
2494 case EVENT_EAPOL_RX:
2495 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2496 data->eapol_rx.data,
2497 data->eapol_rx.data_len);
2499 case EVENT_SIGNAL_CHANGE:
2500 bgscan_notify_signal_change(
2501 wpa_s, data->signal_change.above_threshold,
2502 data->signal_change.current_signal,
2503 data->signal_change.current_noise,
2504 data->signal_change.current_txrate);
2506 case EVENT_INTERFACE_ENABLED:
2507 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2508 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2509 wpa_supplicant_update_mac_addr(wpa_s);
2511 if (!wpa_s->ap_iface) {
2512 wpa_supplicant_set_state(wpa_s,
2514 wpa_supplicant_req_scan(wpa_s, 0, 0);
2516 wpa_supplicant_set_state(wpa_s,
2518 #else /* CONFIG_AP */
2519 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2520 wpa_supplicant_req_scan(wpa_s, 0, 0);
2521 #endif /* CONFIG_AP */
2524 case EVENT_INTERFACE_DISABLED:
2525 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2526 wpa_supplicant_mark_disassoc(wpa_s);
2527 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2529 case EVENT_CHANNEL_LIST_CHANGED:
2530 if (wpa_s->drv_priv == NULL)
2531 break; /* Ignore event during drv initialization */
2533 wpas_p2p_update_channel_list(wpa_s);
2534 #endif /* CONFIG_P2P */
2536 case EVENT_INTERFACE_UNAVAILABLE:
2538 wpas_p2p_interface_unavailable(wpa_s);
2539 #endif /* CONFIG_P2P */
2541 case EVENT_BEST_CHANNEL:
2542 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2544 data->best_chan.freq_24, data->best_chan.freq_5,
2545 data->best_chan.freq_overall);
2546 wpa_s->best_24_freq = data->best_chan.freq_24;
2547 wpa_s->best_5_freq = data->best_chan.freq_5;
2548 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2550 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2551 data->best_chan.freq_5,
2552 data->best_chan.freq_overall);
2553 #endif /* CONFIG_P2P */
2555 case EVENT_UNPROT_DEAUTH:
2556 wpa_supplicant_event_unprot_deauth(wpa_s,
2557 &data->unprot_deauth);
2559 case EVENT_UNPROT_DISASSOC:
2560 wpa_supplicant_event_unprot_disassoc(wpa_s,
2561 &data->unprot_disassoc);
2563 case EVENT_STATION_LOW_ACK:
2565 if (wpa_s->ap_iface && data)
2566 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2567 data->low_ack.addr);
2568 #endif /* CONFIG_AP */
2571 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2572 #endif /* CONFIG_TDLS */
2574 case EVENT_IBSS_PEER_LOST:
2575 #ifdef CONFIG_IBSS_RSN
2576 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2577 #endif /* CONFIG_IBSS_RSN */
2579 case EVENT_DRIVER_GTK_REKEY:
2580 if (os_memcmp(data->driver_gtk_rekey.bssid,
2581 wpa_s->bssid, ETH_ALEN))
2585 wpa_sm_update_replay_ctr(wpa_s->wpa,
2586 data->driver_gtk_rekey.replay_ctr);
2588 case EVENT_SCHED_SCAN_STOPPED:
2589 wpa_s->sched_scanning = 0;
2590 wpa_supplicant_notify_scanning(wpa_s, 0);
2592 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2596 * If we timed out, start a new sched scan to continue
2597 * searching for more SSIDs.
2599 if (wpa_s->sched_scan_timed_out)
2600 wpa_supplicant_req_sched_scan(wpa_s);
2602 case EVENT_WPS_BUTTON_PUSHED:
2604 wpas_wps_start_pbc(wpa_s, NULL, 0);
2605 #endif /* CONFIG_WPS */
2608 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);