2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
65 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
67 struct wpa_ssid *ssid, *old_ssid;
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
75 ssid = wpa_supplicant_get_ssid(wpa_s);
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
82 if (wpas_network_disabled(wpa_s, ssid)) {
83 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
87 res = wpas_temp_disabled(wpa_s, ssid);
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
90 "disabled for %d second(s)", res);
94 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
96 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
98 size_t wpa_ie_len = sizeof(wpa_ie);
99 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
100 wpa_ie, &wpa_ie_len);
102 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
105 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
106 eapol_sm_invalidate_cached_session(wpa_s->eapol);
107 old_ssid = wpa_s->current_ssid;
108 wpa_s->current_ssid = ssid;
109 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
110 wpa_supplicant_initiate_eapol(wpa_s);
111 if (old_ssid != wpa_s->current_ssid)
112 wpas_notify_network_changed(wpa_s);
118 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
120 struct wpa_supplicant *wpa_s = eloop_ctx;
122 if (wpa_s->countermeasures) {
123 wpa_s->countermeasures = 0;
124 wpa_drv_set_countermeasures(wpa_s, 0);
125 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
135 wnm_bss_keep_alive_deinit(wpa_s);
137 #ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s->ibss_rsn);
139 wpa_s->ibss_rsn = NULL;
140 #endif /* CONFIG_IBSS_RSN */
143 wpa_supplicant_ap_deinit(wpa_s);
144 #endif /* CONFIG_AP */
146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
149 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
150 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
151 os_memset(wpa_s->bssid, 0, ETH_ALEN);
152 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
154 wpa_s->sme.prev_bssid_set = 0;
155 #endif /* CONFIG_SME */
157 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
158 #endif /* CONFIG_P2P */
159 wpa_s->current_bss = NULL;
160 wpa_s->assoc_freq = 0;
161 #ifdef CONFIG_IEEE80211R
163 if (wpa_s->sme.ft_ies)
164 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
165 #endif /* CONFIG_SME */
166 #endif /* CONFIG_IEEE80211R */
169 wpas_notify_bssid_changed(wpa_s);
171 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
172 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
173 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
174 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
175 wpa_s->ap_ies_from_associnfo = 0;
176 wpa_s->current_ssid = NULL;
181 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
183 struct wpa_ie_data ie;
187 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
191 for (i = 0; i < ie.num_pmkid; i++) {
192 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
193 ie.pmkid + i * PMKID_LEN,
195 if (pmksa_set == 0) {
196 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
201 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
202 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
206 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
207 union wpa_event_data *data)
210 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
214 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
215 " index=%d preauth=%d",
216 MAC2STR(data->pmkid_candidate.bssid),
217 data->pmkid_candidate.index,
218 data->pmkid_candidate.preauth);
220 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
221 data->pmkid_candidate.index,
222 data->pmkid_candidate.preauth);
226 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
228 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
229 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
232 #ifdef IEEE8021X_EAPOL
233 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
234 wpa_s->current_ssid &&
235 !(wpa_s->current_ssid->eapol_flags &
236 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
237 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
238 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
239 * plaintext or static WEP keys). */
242 #endif /* IEEE8021X_EAPOL */
249 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
250 * @wpa_s: pointer to wpa_supplicant data
251 * @ssid: Configuration data for the network
252 * Returns: 0 on success, -1 on failure
254 * This function is called when starting authentication with a network that is
255 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
257 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
258 struct wpa_ssid *ssid)
260 #ifdef IEEE8021X_EAPOL
262 int aka = 0, sim = 0, type;
264 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
267 if (ssid->eap.eap_methods == NULL) {
271 struct eap_method_type *eap = ssid->eap.eap_methods;
272 while (eap->vendor != EAP_VENDOR_IETF ||
273 eap->method != EAP_TYPE_NONE) {
274 if (eap->vendor == EAP_VENDOR_IETF) {
275 if (eap->method == EAP_TYPE_SIM)
277 else if (eap->method == EAP_TYPE_AKA ||
278 eap->method == EAP_TYPE_AKA_PRIME)
285 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
287 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
288 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
293 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
294 "use SIM, but neither EAP-SIM nor EAP-AKA are "
299 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
300 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
302 type = SCARD_TRY_BOTH;
304 type = SCARD_USIM_ONLY;
306 type = SCARD_GSM_SIM_ONLY;
308 wpa_s->scard = scard_init(type, NULL);
309 if (wpa_s->scard == NULL) {
310 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
314 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
315 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
316 #endif /* PCSC_FUNCS */
317 #endif /* IEEE8021X_EAPOL */
323 #ifndef CONFIG_NO_SCAN_PROCESSING
324 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
325 struct wpa_ssid *ssid)
329 if (ssid->mixed_cell)
333 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
335 #endif /* CONFIG_WPS */
337 for (i = 0; i < NUM_WEP_KEYS; i++) {
338 if (ssid->wep_key_len[i]) {
343 #ifdef IEEE8021X_EAPOL
344 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
345 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
346 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
348 #endif /* IEEE8021X_EAPOL */
350 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
353 if (bss->caps & IEEE80211_CAP_PRIVACY)
359 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
360 struct wpa_ssid *ssid,
363 struct wpa_ie_data ie;
365 const u8 *rsn_ie, *wpa_ie;
369 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
373 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
374 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
375 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
376 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
377 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
379 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
380 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
383 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
384 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
390 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
392 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
397 if (!(ie.proto & ssid->proto)) {
398 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
403 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
409 if (!(ie.group_cipher & ssid->group_cipher)) {
410 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
415 if (!(ie.key_mgmt & ssid->key_mgmt)) {
416 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
421 #ifdef CONFIG_IEEE80211W
422 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
423 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
428 #endif /* CONFIG_IEEE80211W */
430 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
434 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
435 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
438 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
439 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
445 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
447 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
452 if (!(ie.proto & ssid->proto)) {
453 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
458 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
459 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
464 if (!(ie.group_cipher & ssid->group_cipher)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
470 if (!(ie.key_mgmt & ssid->key_mgmt)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
476 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
480 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
482 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
486 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
487 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
488 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
492 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
497 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
504 static int freq_allowed(int *freqs, int freq)
511 for (i = 0; freqs[i]; i++)
512 if (freqs[i] == freq)
518 static int ht_supported(const struct hostapd_hw_modes *mode)
520 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
522 * The driver did not indicate whether it supports HT. Assume
523 * it does to avoid connection issues.
529 * IEEE Std 802.11n-2009 20.1.1:
530 * An HT non-AP STA shall support all EQM rates for one spatial stream.
532 return mode->mcs_set[0] == 0xff;
536 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
538 const struct hostapd_hw_modes *mode = NULL, *modes;
539 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
544 return 1; /* Cannot do matching without knowing band */
546 modes = wpa_s->hw.modes;
549 * The driver does not provide any additional information
550 * about the utilized hardware, so allow the connection attempt
556 for (i = 0; i < wpa_s->hw.num_modes; i++) {
557 for (j = 0; j < modes[i].num_channels; j++) {
558 int freq = modes[i].channels[j].freq;
559 if (freq == bss->freq) {
561 mode->mode == HOSTAPD_MODE_IEEE80211G)
562 break; /* do not allow 802.11b replace
573 for (i = 0; i < (int) sizeof(scan_ie); i++) {
574 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
578 for (j = 2; j < rate_ie[1] + 2; j++) {
579 int flagged = !!(rate_ie[j] & 0x80);
580 int r = (rate_ie[j] & 0x7f) * 5;
583 * IEEE Std 802.11n-2009 7.3.2.2:
584 * The new BSS Membership selector value is encoded
585 * like a legacy basic rate, but it is not a rate and
586 * only indicates if the BSS members are required to
587 * support the mandatory features of Clause 20 [HT PHY]
588 * in order to join the BSS.
590 if (flagged && ((rate_ie[j] & 0x7f) ==
591 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
592 if (!ht_supported(mode)) {
593 wpa_dbg(wpa_s, MSG_DEBUG,
594 " hardware does not support "
604 /* check for legacy basic rates */
605 for (k = 0; k < mode->num_rates; k++) {
606 if (mode->rates[k] == r)
609 if (k == mode->num_rates) {
611 * IEEE Std 802.11-2007 7.3.2.2 demands that in
612 * order to join a BSS all required rates
613 * have to be supported by the hardware.
615 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
616 "not support required rate %d.%d Mbps",
627 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
628 int i, struct wpa_bss *bss,
629 struct wpa_ssid *group)
631 u8 wpa_ie_len, rsn_ie_len;
633 struct wpa_blacklist *e;
635 struct wpa_ssid *ssid;
637 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
638 wpa_ie_len = ie ? ie[1] : 0;
640 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
641 rsn_ie_len = ie ? ie[1] : 0;
643 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
644 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
645 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
646 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
647 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
649 e = wpa_blacklist_get(wpa_s, bss->bssid);
652 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
654 * When only a single network is enabled, we can
655 * trigger blacklisting on the first failure. This
656 * should not be done with multiple enabled networks to
657 * avoid getting forced to move into a worse ESS on
658 * single error if there are no other BSSes of the
663 if (e->count > limit) {
664 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
665 "(count=%d limit=%d)", e->count, limit);
670 if (bss->ssid_len == 0) {
671 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
675 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
677 for (ssid = group; ssid; ssid = ssid->pnext) {
678 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
681 if (wpas_network_disabled(wpa_s, ssid)) {
682 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
686 res = wpas_temp_disabled(wpa_s, ssid);
688 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
689 "temporarily for %d second(s)", res);
694 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
695 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
700 if (wpa && ssid->ssid_len == 0 &&
701 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
704 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
705 /* Only allow wildcard SSID match if an AP
706 * advertises active WPS operation that matches
709 if (ssid->ssid_len == 0 &&
710 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
713 #endif /* CONFIG_WPS */
715 if (ssid->bssid_set && ssid->ssid_len == 0 &&
716 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
720 (bss->ssid_len != ssid->ssid_len ||
721 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
722 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
726 if (ssid->bssid_set &&
727 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
728 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
732 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
736 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
737 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
738 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
739 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
744 if (!wpa_supplicant_match_privacy(bss, ssid)) {
745 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
750 if (bss->caps & IEEE80211_CAP_IBSS) {
751 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
756 if (!freq_allowed(ssid->freq_list, bss->freq)) {
757 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
762 if (!rate_match(wpa_s, bss)) {
763 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
770 * TODO: skip the AP if its P2P IE has Group Formation
771 * bit set in the P2P Group Capability Bitmap and we
772 * are not in Group Formation with that device.
774 #endif /* CONFIG_P2P */
776 /* Matching configuration found */
780 /* No matching configuration found */
785 static struct wpa_bss *
786 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
787 struct wpa_ssid *group,
788 struct wpa_ssid **selected_ssid)
792 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
795 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
796 struct wpa_bss *bss = wpa_s->last_scan_res[i];
797 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
800 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
803 wpa_ssid_txt(bss->ssid, bss->ssid_len));
811 static struct wpa_bss *
812 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
813 struct wpa_ssid **selected_ssid)
815 struct wpa_bss *selected = NULL;
818 if (wpa_s->last_scan_res == NULL ||
819 wpa_s->last_scan_res_used == 0)
820 return NULL; /* no scan results from last update */
822 while (selected == NULL) {
823 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
824 selected = wpa_supplicant_select_bss(
825 wpa_s, wpa_s->conf->pssid[prio],
831 if (selected == NULL && wpa_s->blacklist &&
832 !wpa_s->countermeasures) {
833 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
834 "blacklist and try again");
835 wpa_blacklist_clear(wpa_s);
836 wpa_s->blacklist_cleared++;
837 } else if (selected == NULL)
845 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
846 int timeout_sec, int timeout_usec)
848 if (!wpa_supplicant_enabled_networks(wpa_s)) {
850 * No networks are enabled; short-circuit request so
851 * we don't wait timeout seconds before transitioning
854 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
855 "since there are no enabled networks");
856 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
859 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
863 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
864 struct wpa_bss *selected,
865 struct wpa_ssid *ssid)
867 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
868 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
869 "PBC session overlap");
871 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
873 #endif /* CONFIG_P2P */
876 wpas_wps_cancel(wpa_s);
877 #endif /* CONFIG_WPS */
882 * Do not trigger new association unless the BSSID has changed or if
883 * reassociation is requested. If we are in process of associating with
884 * the selected BSSID, do not trigger new attempt.
886 if (wpa_s->reassociate ||
887 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
888 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
889 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
890 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
892 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
893 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
896 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
897 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
898 " pending: " MACSTR " wpa_state: %s",
899 wpa_s->reassociate, MAC2STR(selected->bssid),
900 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
901 wpa_supplicant_state_txt(wpa_s->wpa_state));
902 wpa_supplicant_associate(wpa_s, selected, ssid);
904 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
912 static struct wpa_ssid *
913 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
916 struct wpa_ssid *ssid;
918 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
919 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
921 if (wpas_network_disabled(wpa_s, ssid))
923 if (ssid->mode == IEEE80211_MODE_IBSS ||
924 ssid->mode == IEEE80211_MODE_AP)
932 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
933 * on BSS added and BSS changed events */
934 static void wpa_supplicant_rsn_preauth_scan_results(
935 struct wpa_supplicant *wpa_s)
939 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
942 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
943 const u8 *ssid, *rsn;
945 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
949 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
953 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
959 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
960 struct wpa_bss *selected,
961 struct wpa_ssid *ssid)
963 struct wpa_bss *current_bss = NULL;
966 if (wpa_s->reassociate)
967 return 1; /* explicit request to reassociate */
968 if (wpa_s->wpa_state < WPA_ASSOCIATED)
969 return 1; /* we are not associated; continue */
970 if (wpa_s->current_ssid == NULL)
971 return 1; /* unknown current SSID */
972 if (wpa_s->current_ssid != ssid)
973 return 1; /* different network block */
975 if (wpas_driver_bss_selection(wpa_s))
976 return 0; /* Driver-based roaming */
978 if (wpa_s->current_ssid->ssid)
979 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
980 wpa_s->current_ssid->ssid,
981 wpa_s->current_ssid->ssid_len);
983 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
986 return 1; /* current BSS not seen in scan results */
988 if (current_bss == selected)
991 if (selected->last_update_idx > current_bss->last_update_idx)
992 return 1; /* current BSS not seen in the last scan */
994 #ifndef CONFIG_NO_ROAMING
995 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
996 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
997 MAC2STR(current_bss->bssid), current_bss->level);
998 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
999 MAC2STR(selected->bssid), selected->level);
1001 if (wpa_s->current_ssid->bssid_set &&
1002 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1004 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1005 "has preferred BSSID");
1010 if (current_bss->level < 0) {
1011 if (current_bss->level < -85)
1013 else if (current_bss->level < -80)
1015 else if (current_bss->level < -75)
1017 else if (current_bss->level < -70)
1022 if (abs(current_bss->level - selected->level) < min_diff) {
1023 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1029 #else /* CONFIG_NO_ROAMING */
1031 #endif /* CONFIG_NO_ROAMING */
1035 /* Return != 0 if no scan results could be fetched or if scan results should not
1036 * be shared with other virtual interfaces. */
1037 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1038 union wpa_event_data *data)
1040 struct wpa_scan_results *scan_res;
1042 #ifndef CONFIG_NO_RANDOM_POOL
1044 #endif /* CONFIG_NO_RANDOM_POOL */
1047 if (wpa_s->ap_iface)
1049 #endif /* CONFIG_AP */
1051 wpa_supplicant_notify_scanning(wpa_s, 0);
1054 if (wpa_s->global->p2p_cb_on_scan_complete &&
1055 !wpa_s->global->p2p_disabled &&
1056 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
1057 wpa_s->global->p2p_cb_on_scan_complete = 0;
1058 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1059 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1060 "stopped scan processing");
1061 wpa_s->sta_scan_pending = 1;
1062 wpa_supplicant_req_scan(wpa_s, 5, 0);
1066 wpa_s->sta_scan_pending = 0;
1067 #endif /* CONFIG_P2P */
1069 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1070 data ? &data->scan_info :
1072 if (scan_res == NULL) {
1073 if (wpa_s->conf->ap_scan == 2 || ap)
1075 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1077 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1081 #ifndef CONFIG_NO_RANDOM_POOL
1082 num = scan_res->num;
1085 for (i = 0; i < num; i++) {
1087 struct wpa_scan_res *res = scan_res->res[i];
1088 buf[0] = res->bssid[5];
1089 buf[1] = res->qual & 0xff;
1090 buf[2] = res->noise & 0xff;
1091 buf[3] = res->level & 0xff;
1092 buf[4] = res->tsf & 0xff;
1093 random_add_randomness(buf, sizeof(buf));
1095 #endif /* CONFIG_NO_RANDOM_POOL */
1097 if (wpa_s->scan_res_handler) {
1098 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1099 struct wpa_scan_results *scan_res);
1101 scan_res_handler = wpa_s->scan_res_handler;
1102 wpa_s->scan_res_handler = NULL;
1103 scan_res_handler(wpa_s, scan_res);
1105 wpa_scan_results_free(scan_res);
1110 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1112 if (wpa_s->ap_iface->scan_cb)
1113 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1114 #endif /* CONFIG_AP */
1115 wpa_scan_results_free(scan_res);
1119 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1120 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1121 wpas_notify_scan_results(wpa_s);
1123 wpas_notify_scan_done(wpa_s, 1);
1125 if (sme_proc_obss_scan(wpa_s) > 0) {
1126 wpa_scan_results_free(scan_res);
1130 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1131 wpa_scan_results_free(scan_res);
1135 if (autoscan_notify_scan(wpa_s, scan_res)) {
1136 wpa_scan_results_free(scan_res);
1140 if (wpa_s->disconnected) {
1141 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1142 wpa_scan_results_free(scan_res);
1146 if (!wpas_driver_bss_selection(wpa_s) &&
1147 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1148 wpa_scan_results_free(scan_res);
1152 wpas_wps_update_ap_info(wpa_s, scan_res);
1154 wpa_scan_results_free(scan_res);
1156 return wpas_select_network_from_last_scan(wpa_s);
1160 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1162 struct wpa_bss *selected;
1163 struct wpa_ssid *ssid = NULL;
1165 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1169 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1171 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1175 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1176 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1179 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1181 * Do not notify other virtual radios of scan results since we do not
1182 * want them to start other associations at the same time.
1186 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1187 ssid = wpa_supplicant_pick_new_network(wpa_s);
1189 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1190 wpa_supplicant_associate(wpa_s, NULL, ssid);
1191 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1193 int timeout_sec = wpa_s->scan_interval;
1194 int timeout_usec = 0;
1196 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1199 if (wpa_s->p2p_in_provisioning) {
1201 * Use shorter wait during P2P Provisioning
1202 * state to speed up group formation.
1205 timeout_usec = 250000;
1206 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1210 #endif /* CONFIG_P2P */
1211 #ifdef CONFIG_INTERWORKING
1212 if (wpa_s->conf->auto_interworking &&
1213 wpa_s->conf->interworking &&
1214 wpa_s->conf->cred) {
1215 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1216 "start ANQP fetch since no matching "
1218 wpa_s->network_select = 1;
1219 wpa_s->auto_network_select = 1;
1220 interworking_start_fetch_anqp(wpa_s);
1223 #endif /* CONFIG_INTERWORKING */
1224 if (wpa_supplicant_req_sched_scan(wpa_s))
1225 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1233 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1234 union wpa_event_data *data)
1236 const char *rn, *rn2;
1237 struct wpa_supplicant *ifs;
1239 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1241 * If no scan results could be fetched, then no need to
1242 * notify those interfaces that did not actually request
1243 * this scan. Similarly, if scan results started a new operation on this
1244 * interface, do not notify other interfaces to avoid concurrent
1245 * operations during a connection attempt.
1251 * Check other interfaces to see if they have the same radio-name. If
1252 * so, they get updated with this same scan info.
1254 if (!wpa_s->driver->get_radio_name)
1257 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1258 if (rn == NULL || rn[0] == '\0')
1261 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1262 "sharing same radio (%s) in event_scan_results", rn);
1264 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1265 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1268 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1269 if (rn2 && os_strcmp(rn, rn2) == 0) {
1270 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1271 "sibling", ifs->ifname);
1272 _wpa_supplicant_event_scan_results(ifs, data);
1277 #endif /* CONFIG_NO_SCAN_PROCESSING */
1282 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1284 struct wpa_supplicant *wpa_s = eloop_ctx;
1286 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1289 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1290 MAC2STR(wpa_s->bssid));
1291 /* TODO: could skip this if normal data traffic has been sent */
1292 /* TODO: Consider using some more appropriate data frame for this */
1294 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1297 if (wpa_s->sme.bss_max_idle_period) {
1299 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1302 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1303 wnm_bss_keep_alive, wpa_s, NULL);
1305 #endif /* CONFIG_SME */
1309 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1310 const u8 *ies, size_t ies_len)
1312 struct ieee802_11_elems elems;
1317 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1321 if (elems.bss_max_idle_period) {
1323 wpa_s->sme.bss_max_idle_period =
1324 WPA_GET_LE16(elems.bss_max_idle_period);
1325 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1326 "TU)%s", wpa_s->sme.bss_max_idle_period,
1327 (elems.bss_max_idle_period[2] & 0x01) ?
1328 " (protected keep-live required)" : "");
1329 if (wpa_s->sme.bss_max_idle_period == 0)
1330 wpa_s->sme.bss_max_idle_period = 1;
1331 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1332 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1333 /* msec times 1000 */
1334 msec = wpa_s->sme.bss_max_idle_period * 1024;
1337 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1338 wnm_bss_keep_alive, wpa_s,
1342 #endif /* CONFIG_SME */
1345 #endif /* CONFIG_WNM */
1348 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1351 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1352 #endif /* CONFIG_WNM */
1356 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1357 union wpa_event_data *data)
1359 int l, len, found = 0, wpa_found, rsn_found;
1362 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1363 if (data->assoc_info.req_ies)
1364 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1365 data->assoc_info.req_ies_len);
1366 if (data->assoc_info.resp_ies) {
1367 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1368 data->assoc_info.resp_ies_len);
1370 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1371 data->assoc_info.resp_ies_len);
1372 #endif /* CONFIG_TDLS */
1374 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1375 data->assoc_info.resp_ies_len);
1376 #endif /* CONFIG_WNM */
1378 if (data->assoc_info.beacon_ies)
1379 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1380 data->assoc_info.beacon_ies,
1381 data->assoc_info.beacon_ies_len);
1382 if (data->assoc_info.freq)
1383 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1384 data->assoc_info.freq);
1386 p = data->assoc_info.req_ies;
1387 l = data->assoc_info.req_ies_len;
1389 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1390 while (p && l >= 2) {
1393 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1397 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1398 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1399 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1400 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1403 wpa_find_assoc_pmkid(wpa_s);
1409 if (!found && data->assoc_info.req_ies)
1410 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1412 #ifdef CONFIG_IEEE80211R
1414 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1416 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1417 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1418 data->assoc_info.resp_ies,
1419 data->assoc_info.resp_ies_len,
1421 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1422 "Reassociation Response failed");
1423 wpa_supplicant_deauthenticate(
1424 wpa_s, WLAN_REASON_INVALID_IE);
1429 p = data->assoc_info.resp_ies;
1430 l = data->assoc_info.resp_ies_len;
1432 #ifdef CONFIG_WPS_STRICT
1433 if (p && wpa_s->current_ssid &&
1434 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1436 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1438 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1439 "include WPS IE in (Re)Association Response");
1443 if (wps_validate_assoc_resp(wps) < 0) {
1445 wpa_supplicant_deauthenticate(
1446 wpa_s, WLAN_REASON_INVALID_IE);
1451 #endif /* CONFIG_WPS_STRICT */
1453 /* Go through the IEs and make a copy of the MDIE, if present. */
1454 while (p && l >= 2) {
1457 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1461 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1462 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1463 wpa_s->sme.ft_used = 1;
1464 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1465 MOBILITY_DOMAIN_ID_LEN);
1471 #endif /* CONFIG_SME */
1473 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1474 data->assoc_info.resp_ies_len);
1475 #endif /* CONFIG_IEEE80211R */
1477 /* WPA/RSN IE from Beacon/ProbeResp */
1478 p = data->assoc_info.beacon_ies;
1479 l = data->assoc_info.beacon_ies_len;
1481 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1483 wpa_found = rsn_found = 0;
1484 while (p && l >= 2) {
1487 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1492 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1493 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1495 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1499 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1501 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1508 if (!wpa_found && data->assoc_info.beacon_ies)
1509 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1510 if (!rsn_found && data->assoc_info.beacon_ies)
1511 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1512 if (wpa_found || rsn_found)
1513 wpa_s->ap_ies_from_associnfo = 1;
1515 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1516 wpa_s->assoc_freq != data->assoc_info.freq) {
1517 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1519 wpa_s->assoc_freq, data->assoc_info.freq);
1520 wpa_supplicant_update_scan_results(wpa_s);
1523 wpa_s->assoc_freq = data->assoc_info.freq;
1529 static struct wpa_bss * wpa_supplicant_get_new_bss(
1530 struct wpa_supplicant *wpa_s, const u8 *bssid)
1532 struct wpa_bss *bss = NULL;
1533 struct wpa_ssid *ssid = wpa_s->current_ssid;
1535 if (ssid->ssid_len > 0)
1536 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1538 bss = wpa_bss_get_bssid(wpa_s, bssid);
1544 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1546 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1548 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1551 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1554 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1555 WPA_IE_VENDOR_TYPE);
1556 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1558 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1559 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1560 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1561 bss_rsn ? 2 + bss_rsn[1] : 0))
1568 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1569 union wpa_event_data *data)
1573 struct wpa_driver_capa capa;
1576 if (wpa_s->ap_iface) {
1577 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1578 data->assoc_info.addr,
1579 data->assoc_info.req_ies,
1580 data->assoc_info.req_ies_len,
1581 data->assoc_info.reassoc);
1584 #endif /* CONFIG_AP */
1586 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1587 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1590 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1591 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1592 wpa_supplicant_disassociate(
1593 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1597 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1598 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1599 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1600 MACSTR, MAC2STR(bssid));
1601 random_add_randomness(bssid, ETH_ALEN);
1602 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1603 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1604 wpas_notify_bssid_changed(wpa_s);
1606 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1607 wpa_clear_keys(wpa_s, bssid);
1609 if (wpa_supplicant_select_config(wpa_s) < 0) {
1610 wpa_supplicant_disassociate(
1611 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1614 if (wpa_s->current_ssid) {
1615 struct wpa_bss *bss = NULL;
1617 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1619 wpa_supplicant_update_scan_results(wpa_s);
1621 /* Get the BSS from the new scan results */
1622 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1626 wpa_s->current_bss = bss;
1629 if (wpa_s->conf->ap_scan == 1 &&
1630 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1631 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1632 wpa_msg(wpa_s, MSG_WARNING,
1633 "WPA/RSN IEs not updated");
1638 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1639 wpa_s->sme.prev_bssid_set = 1;
1640 #endif /* CONFIG_SME */
1642 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1643 if (wpa_s->current_ssid) {
1644 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1645 * initialized before association, but for other modes,
1646 * initialize PC/SC here, if the current configuration needs
1647 * smartcard or SIM/USIM. */
1648 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1650 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1652 l2_packet_notify_auth_start(wpa_s->l2);
1655 * Set portEnabled first to FALSE in order to get EAP state machine out
1656 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1657 * state machine may transit to AUTHENTICATING state based on obsolete
1658 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1659 * AUTHENTICATED without ever giving chance to EAP state machine to
1662 if (!ft_completed) {
1663 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1664 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1666 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1667 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1668 /* 802.1X::portControl = Auto */
1669 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1670 wpa_s->eapol_received = 0;
1671 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1672 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1673 (wpa_s->current_ssid &&
1674 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1675 wpa_supplicant_cancel_auth_timeout(wpa_s);
1676 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1677 } else if (!ft_completed) {
1678 /* Timeout for receiving the first EAPOL packet */
1679 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1681 wpa_supplicant_cancel_scan(wpa_s);
1683 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1684 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1686 * We are done; the driver will take care of RSN 4-way
1689 wpa_supplicant_cancel_auth_timeout(wpa_s);
1690 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1691 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1692 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1693 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1694 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1696 * The driver will take care of RSN 4-way handshake, so we need
1697 * to allow EAPOL supplicant to complete its work without
1698 * waiting for WPA supplicant.
1700 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1701 } else if (ft_completed) {
1703 * FT protocol completed - make sure EAPOL state machine ends
1704 * up in authenticated.
1706 wpa_supplicant_cancel_auth_timeout(wpa_s);
1707 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1708 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1709 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1712 if (wpa_s->pending_eapol_rx) {
1713 struct os_time now, age;
1715 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1716 if (age.sec == 0 && age.usec < 100000 &&
1717 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1719 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1720 "frame that was received just before "
1721 "association notification");
1722 wpa_supplicant_rx_eapol(
1723 wpa_s, wpa_s->pending_eapol_rx_src,
1724 wpabuf_head(wpa_s->pending_eapol_rx),
1725 wpabuf_len(wpa_s->pending_eapol_rx));
1727 wpabuf_free(wpa_s->pending_eapol_rx);
1728 wpa_s->pending_eapol_rx = NULL;
1731 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1732 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1733 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1734 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1735 /* Set static WEP keys again */
1736 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1739 #ifdef CONFIG_IBSS_RSN
1740 if (wpa_s->current_ssid &&
1741 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1742 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1743 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1744 wpa_s->ibss_rsn == NULL) {
1745 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1746 if (!wpa_s->ibss_rsn) {
1747 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1748 wpa_supplicant_deauthenticate(
1749 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1753 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1755 #endif /* CONFIG_IBSS_RSN */
1757 wpas_wps_notify_assoc(wpa_s, bssid);
1761 static int disconnect_reason_recoverable(u16 reason_code)
1763 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1764 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1765 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1769 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1771 int locally_generated)
1775 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1777 * At least Host AP driver and a Prism3 card seemed to be
1778 * generating streams of disconnected events when configuring
1779 * IBSS for WPA-None. Ignore them for now.
1784 bssid = wpa_s->bssid;
1785 if (is_zero_ether_addr(bssid))
1786 bssid = wpa_s->pending_bssid;
1788 if (!is_zero_ether_addr(bssid) ||
1789 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1790 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1792 MAC2STR(bssid), reason_code,
1793 locally_generated ? " locally_generated=1" : "");
1798 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1800 int locally_generated)
1804 u8 prev_pending_bssid[ETH_ALEN];
1805 struct wpa_bss *fast_reconnect = NULL;
1806 struct wpa_ssid *fast_reconnect_ssid = NULL;
1807 struct wpa_ssid *last_ssid;
1809 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1810 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1812 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1814 * At least Host AP driver and a Prism3 card seemed to be
1815 * generating streams of disconnected events when configuring
1816 * IBSS for WPA-None. Ignore them for now.
1818 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1819 "IBSS/WPA-None mode");
1823 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1824 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1825 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1826 "pre-shared key may be incorrect");
1827 wpas_auth_failed(wpa_s);
1829 if (!wpa_s->auto_reconnect_disabled ||
1830 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1831 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1832 "reconnect (wps=%d wpa_state=%d)",
1833 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1835 if (wpa_s->wpa_state == WPA_COMPLETED &&
1836 wpa_s->current_ssid &&
1837 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1838 !locally_generated &&
1839 disconnect_reason_recoverable(reason_code)) {
1841 * It looks like the AP has dropped association with
1842 * us, but could allow us to get back in. Try to
1843 * reconnect to the same BSS without full scan to save
1844 * time for some common cases.
1846 fast_reconnect = wpa_s->current_bss;
1847 fast_reconnect_ssid = wpa_s->current_ssid;
1848 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1849 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1851 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1854 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1855 "try to re-connect");
1856 wpa_s->reassociate = 0;
1857 wpa_s->disconnected = 1;
1858 wpa_supplicant_cancel_sched_scan(wpa_s);
1860 bssid = wpa_s->bssid;
1861 if (is_zero_ether_addr(bssid))
1862 bssid = wpa_s->pending_bssid;
1863 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1864 wpas_connection_failed(wpa_s, bssid);
1865 wpa_sm_notify_disassoc(wpa_s->wpa);
1866 if (locally_generated)
1867 wpa_s->disconnect_reason = -reason_code;
1869 wpa_s->disconnect_reason = reason_code;
1870 wpas_notify_disconnect_reason(wpa_s);
1871 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1872 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1873 wpa_s->keys_cleared = 0;
1874 wpa_clear_keys(wpa_s, wpa_s->bssid);
1876 last_ssid = wpa_s->current_ssid;
1877 wpa_supplicant_mark_disassoc(wpa_s);
1879 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1880 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1881 wpa_s->current_ssid = last_ssid;
1884 if (fast_reconnect) {
1885 #ifndef CONFIG_NO_SCAN_PROCESSING
1886 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1887 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1888 fast_reconnect_ssid) < 0) {
1889 /* Recover through full scan */
1890 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1892 #endif /* CONFIG_NO_SCAN_PROCESSING */
1897 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1898 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1900 struct wpa_supplicant *wpa_s = eloop_ctx;
1902 if (!wpa_s->pending_mic_error_report)
1905 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1906 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1907 wpa_s->pending_mic_error_report = 0;
1909 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1913 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1914 union wpa_event_data *data)
1919 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1920 pairwise = (data && data->michael_mic_failure.unicast);
1922 if ((wpa_s->last_michael_mic_error &&
1923 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1924 wpa_s->pending_mic_error_report) {
1925 if (wpa_s->pending_mic_error_report) {
1927 * Send the pending MIC error report immediately since
1928 * we are going to start countermeasures and AP better
1931 wpa_sm_key_request(wpa_s->wpa, 1,
1932 wpa_s->pending_mic_error_pairwise);
1935 /* Send the new MIC error report immediately since we are going
1936 * to start countermeasures and AP better do the same.
1938 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1940 /* initialize countermeasures */
1941 wpa_s->countermeasures = 1;
1943 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1945 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1948 * Need to wait for completion of request frame. We do not get
1949 * any callback for the message completion, so just wait a
1950 * short while and hope for the best. */
1953 wpa_drv_set_countermeasures(wpa_s, 1);
1954 wpa_supplicant_deauthenticate(wpa_s,
1955 WLAN_REASON_MICHAEL_MIC_FAILURE);
1956 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1958 eloop_register_timeout(60, 0,
1959 wpa_supplicant_stop_countermeasures,
1961 /* TODO: mark the AP rejected for 60 second. STA is
1962 * allowed to associate with another AP.. */
1964 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1965 if (wpa_s->mic_errors_seen) {
1967 * Reduce the effectiveness of Michael MIC error
1968 * reports as a means for attacking against TKIP if
1969 * more than one MIC failure is noticed with the same
1970 * PTK. We delay the transmission of the reports by a
1971 * random time between 0 and 60 seconds in order to
1972 * force the attacker wait 60 seconds before getting
1973 * the information on whether a frame resulted in a MIC
1979 if (os_get_random(rval, sizeof(rval)) < 0)
1980 sec = os_random() % 60;
1982 sec = WPA_GET_BE32(rval) % 60;
1983 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1984 "report %d seconds", sec);
1985 wpa_s->pending_mic_error_report = 1;
1986 wpa_s->pending_mic_error_pairwise = pairwise;
1987 eloop_cancel_timeout(
1988 wpa_supplicant_delayed_mic_error_report,
1990 eloop_register_timeout(
1991 sec, os_random() % 1000000,
1992 wpa_supplicant_delayed_mic_error_report,
1995 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1997 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1998 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1999 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2001 wpa_s->last_michael_mic_error = t.sec;
2002 wpa_s->mic_errors_seen++;
2006 #ifdef CONFIG_TERMINATE_ONLASTIF
2007 static int any_interfaces(struct wpa_supplicant *head)
2009 struct wpa_supplicant *wpa_s;
2011 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2012 if (!wpa_s->interface_removed)
2016 #endif /* CONFIG_TERMINATE_ONLASTIF */
2020 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2021 union wpa_event_data *data)
2023 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2026 switch (data->interface_status.ievent) {
2027 case EVENT_INTERFACE_ADDED:
2028 if (!wpa_s->interface_removed)
2030 wpa_s->interface_removed = 0;
2031 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2032 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2033 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2034 "driver after interface was added");
2036 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2038 case EVENT_INTERFACE_REMOVED:
2039 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2040 wpa_s->interface_removed = 1;
2041 wpa_supplicant_mark_disassoc(wpa_s);
2042 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2043 l2_packet_deinit(wpa_s->l2);
2045 #ifdef CONFIG_IBSS_RSN
2046 ibss_rsn_deinit(wpa_s->ibss_rsn);
2047 wpa_s->ibss_rsn = NULL;
2048 #endif /* CONFIG_IBSS_RSN */
2049 #ifdef CONFIG_TERMINATE_ONLASTIF
2050 /* check if last interface */
2051 if (!any_interfaces(wpa_s->global->ifaces))
2053 #endif /* CONFIG_TERMINATE_ONLASTIF */
2059 #ifdef CONFIG_PEERKEY
2061 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2062 union wpa_event_data *data)
2066 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2068 #endif /* CONFIG_PEERKEY */
2072 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2073 union wpa_event_data *data)
2077 switch (data->tdls.oper) {
2078 case TDLS_REQUEST_SETUP:
2079 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2081 case TDLS_REQUEST_TEARDOWN:
2082 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2083 data->tdls.reason_code);
2087 #endif /* CONFIG_TDLS */
2090 #ifdef CONFIG_IEEE80211V
2091 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2092 union wpa_event_data *data)
2096 switch (data->wnm.oper) {
2097 case WNM_OPER_SLEEP:
2098 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2099 "(action=%d, intval=%d)",
2100 data->wnm.sleep_action, data->wnm.sleep_intval);
2101 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2102 data->wnm.sleep_intval);
2106 #endif /* CONFIG_IEEE80211V */
2109 #ifdef CONFIG_IEEE80211R
2111 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2112 union wpa_event_data *data)
2117 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2118 data->ft_ies.ies_len,
2119 data->ft_ies.ft_action,
2120 data->ft_ies.target_ap,
2121 data->ft_ies.ric_ies,
2122 data->ft_ies.ric_ies_len) < 0) {
2123 /* TODO: prevent MLME/driver from trying to associate? */
2126 #endif /* CONFIG_IEEE80211R */
2129 #ifdef CONFIG_IBSS_RSN
2130 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2131 union wpa_event_data *data)
2133 struct wpa_ssid *ssid;
2134 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2138 ssid = wpa_s->current_ssid;
2141 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2144 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2146 #endif /* CONFIG_IBSS_RSN */
2149 #ifdef CONFIG_IEEE80211R
2150 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2153 const u8 *sta_addr, *target_ap_addr;
2156 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2157 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2158 return; /* only SME case supported for now */
2159 if (len < 1 + 2 * ETH_ALEN + 2)
2162 return; /* Only FT Action Response is supported for now */
2163 sta_addr = data + 1;
2164 target_ap_addr = data + 1 + ETH_ALEN;
2165 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2166 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2167 MACSTR " TargetAP " MACSTR " status %u",
2168 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2170 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2171 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2172 " in FT Action Response", MAC2STR(sta_addr));
2177 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2178 "failure (status code %d)", status);
2179 /* TODO: report error to FT code(?) */
2183 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2184 len - (1 + 2 * ETH_ALEN + 2), 1,
2185 target_ap_addr, NULL, 0) < 0)
2190 struct wpa_bss *bss;
2191 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2193 wpa_s->sme.freq = bss->freq;
2194 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2195 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2198 #endif /* CONFIG_SME */
2200 #endif /* CONFIG_IEEE80211R */
2203 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2204 struct unprot_deauth *e)
2206 #ifdef CONFIG_IEEE80211W
2207 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2208 "dropped: " MACSTR " -> " MACSTR
2209 " (reason code %u)",
2210 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2211 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2212 #endif /* CONFIG_IEEE80211W */
2216 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2217 struct unprot_disassoc *e)
2219 #ifdef CONFIG_IEEE80211W
2220 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2221 "dropped: " MACSTR " -> " MACSTR
2222 " (reason code %u)",
2223 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2224 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2225 #endif /* CONFIG_IEEE80211W */
2229 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2232 const u8 *pos, *end;
2234 if (rx->data == NULL || rx->len == 0)
2238 end = pos + rx->len;
2241 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2242 action, MAC2STR(rx->sa));
2244 case WNM_BSS_TRANS_MGMT_REQ:
2247 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2248 "Request: dialog_token=%u request_mode=0x%x "
2249 "disassoc_timer=%u validity_interval=%u",
2250 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2254 pos += 12; /* BSS Termination Duration */
2257 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2258 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2259 "Transition Management Request "
2263 os_memcpy(url, pos + 1, pos[0]);
2265 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2266 "Imminent - session_info_url=%s", url);
2273 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2274 union wpa_event_data *data)
2276 struct wpa_supplicant *wpa_s = ctx;
2277 u16 reason_code = 0;
2278 int locally_generated = 0;
2280 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2281 event != EVENT_INTERFACE_ENABLED &&
2282 event != EVENT_INTERFACE_STATUS &&
2283 event != EVENT_SCHED_SCAN_STOPPED) {
2284 wpa_dbg(wpa_s, MSG_DEBUG,
2285 "Ignore event %s (%d) while interface is disabled",
2286 event_to_string(event), event);
2290 #ifndef CONFIG_NO_STDOUT_DEBUG
2292 int level = MSG_DEBUG;
2294 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2295 const struct ieee80211_hdr *hdr;
2297 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2298 fc = le_to_host16(hdr->frame_control);
2299 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2300 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2301 level = MSG_EXCESSIVE;
2304 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2305 event_to_string(event), event);
2307 #endif /* CONFIG_NO_STDOUT_DEBUG */
2311 sme_event_auth(wpa_s, data);
2314 wpa_supplicant_event_assoc(wpa_s, data);
2316 case EVENT_DISASSOC:
2317 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2319 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2320 data->disassoc_info.reason_code,
2321 data->disassoc_info.locally_generated ?
2322 " (locally generated)" : "");
2323 if (data->disassoc_info.addr)
2324 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2325 MAC2STR(data->disassoc_info.addr));
2328 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2329 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2330 data->disassoc_info.addr);
2333 if (wpa_s->ap_iface) {
2334 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2338 #endif /* CONFIG_AP */
2340 reason_code = data->disassoc_info.reason_code;
2342 data->disassoc_info.locally_generated;
2343 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2344 data->disassoc_info.ie,
2345 data->disassoc_info.ie_len);
2347 wpas_p2p_disassoc_notif(
2348 wpa_s, data->disassoc_info.addr, reason_code,
2349 data->disassoc_info.ie,
2350 data->disassoc_info.ie_len,
2352 #endif /* CONFIG_P2P */
2354 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2355 sme_event_disassoc(wpa_s, data);
2358 if (event == EVENT_DEAUTH) {
2359 wpa_dbg(wpa_s, MSG_DEBUG,
2360 "Deauthentication notification");
2362 reason_code = data->deauth_info.reason_code;
2364 data->deauth_info.locally_generated;
2365 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2366 data->deauth_info.reason_code,
2367 data->deauth_info.locally_generated ?
2368 " (locally generated)" : "");
2369 if (data->deauth_info.addr) {
2370 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2372 MAC2STR(data->deauth_info.
2375 wpa_hexdump(MSG_DEBUG,
2376 "Deauthentication frame IE(s)",
2377 data->deauth_info.ie,
2378 data->deauth_info.ie_len);
2382 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2383 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2384 data->deauth_info.addr);
2387 if (wpa_s->ap_iface) {
2388 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2392 #endif /* CONFIG_AP */
2393 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2395 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2396 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2397 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2398 eapol_sm_failed(wpa_s->eapol)))
2399 wpas_auth_failed(wpa_s);
2401 if (event == EVENT_DEAUTH && data) {
2402 if (wpas_p2p_deauth_notif(wpa_s,
2403 data->deauth_info.addr,
2405 data->deauth_info.ie,
2406 data->deauth_info.ie_len,
2407 locally_generated) > 0) {
2409 * The interface was removed, so cannot
2410 * continue processing any additional
2411 * operations after this.
2416 #endif /* CONFIG_P2P */
2417 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2420 case EVENT_MICHAEL_MIC_FAILURE:
2421 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2423 #ifndef CONFIG_NO_SCAN_PROCESSING
2424 case EVENT_SCAN_RESULTS:
2425 wpa_supplicant_event_scan_results(wpa_s, data);
2427 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2428 wpa_s->global->p2p != NULL &&
2429 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2430 wpa_s->wpa_state != WPA_ASSOCIATING) {
2431 wpa_s->global->p2p_cb_on_scan_complete = 0;
2432 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2433 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2434 "continued after scan result processing");
2437 #endif /* CONFIG_P2P */
2439 #endif /* CONFIG_NO_SCAN_PROCESSING */
2440 case EVENT_ASSOCINFO:
2441 wpa_supplicant_event_associnfo(wpa_s, data);
2443 case EVENT_INTERFACE_STATUS:
2444 wpa_supplicant_event_interface_status(wpa_s, data);
2446 case EVENT_PMKID_CANDIDATE:
2447 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2449 #ifdef CONFIG_PEERKEY
2450 case EVENT_STKSTART:
2451 wpa_supplicant_event_stkstart(wpa_s, data);
2453 #endif /* CONFIG_PEERKEY */
2456 wpa_supplicant_event_tdls(wpa_s, data);
2458 #endif /* CONFIG_TDLS */
2459 #ifdef CONFIG_IEEE80211V
2461 wpa_supplicant_event_wnm(wpa_s, data);
2463 #endif /* CONFIG_IEEE80211V */
2464 #ifdef CONFIG_IEEE80211R
2465 case EVENT_FT_RESPONSE:
2466 wpa_supplicant_event_ft_response(wpa_s, data);
2468 #endif /* CONFIG_IEEE80211R */
2469 #ifdef CONFIG_IBSS_RSN
2470 case EVENT_IBSS_RSN_START:
2471 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2473 #endif /* CONFIG_IBSS_RSN */
2474 case EVENT_ASSOC_REJECT:
2475 if (data->assoc_reject.bssid)
2476 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2477 "bssid=" MACSTR " status_code=%u",
2478 MAC2STR(data->assoc_reject.bssid),
2479 data->assoc_reject.status_code);
2481 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2483 data->assoc_reject.status_code);
2484 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2485 sme_event_assoc_reject(wpa_s, data);
2487 case EVENT_AUTH_TIMED_OUT:
2488 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2489 sme_event_auth_timed_out(wpa_s, data);
2491 case EVENT_ASSOC_TIMED_OUT:
2492 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2493 sme_event_assoc_timed_out(wpa_s, data);
2495 case EVENT_TX_STATUS:
2496 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2497 " type=%d stype=%d",
2498 MAC2STR(data->tx_status.dst),
2499 data->tx_status.type, data->tx_status.stype);
2501 if (wpa_s->ap_iface == NULL) {
2502 #ifdef CONFIG_OFFCHANNEL
2503 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2504 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2505 offchannel_send_action_tx_status(
2506 wpa_s, data->tx_status.dst,
2507 data->tx_status.data,
2508 data->tx_status.data_len,
2509 data->tx_status.ack ?
2510 OFFCHANNEL_SEND_ACTION_SUCCESS :
2511 OFFCHANNEL_SEND_ACTION_NO_ACK);
2512 #endif /* CONFIG_OFFCHANNEL */
2515 #endif /* CONFIG_AP */
2516 #ifdef CONFIG_OFFCHANNEL
2517 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2518 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2520 * Catch TX status events for Action frames we sent via group
2521 * interface in GO mode.
2523 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2524 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2525 os_memcmp(wpa_s->parent->pending_action_dst,
2526 data->tx_status.dst, ETH_ALEN) == 0) {
2527 offchannel_send_action_tx_status(
2528 wpa_s->parent, data->tx_status.dst,
2529 data->tx_status.data,
2530 data->tx_status.data_len,
2531 data->tx_status.ack ?
2532 OFFCHANNEL_SEND_ACTION_SUCCESS :
2533 OFFCHANNEL_SEND_ACTION_NO_ACK);
2536 #endif /* CONFIG_OFFCHANNEL */
2538 switch (data->tx_status.type) {
2539 case WLAN_FC_TYPE_MGMT:
2540 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2541 data->tx_status.data_len,
2542 data->tx_status.stype,
2543 data->tx_status.ack);
2545 case WLAN_FC_TYPE_DATA:
2546 ap_tx_status(wpa_s, data->tx_status.dst,
2547 data->tx_status.data,
2548 data->tx_status.data_len,
2549 data->tx_status.ack);
2552 #endif /* CONFIG_AP */
2555 case EVENT_EAPOL_TX_STATUS:
2556 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2557 data->eapol_tx_status.data,
2558 data->eapol_tx_status.data_len,
2559 data->eapol_tx_status.ack);
2561 case EVENT_DRIVER_CLIENT_POLL_OK:
2562 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2564 case EVENT_RX_FROM_UNKNOWN:
2565 if (wpa_s->ap_iface == NULL)
2567 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2568 data->rx_from_unknown.wds);
2570 case EVENT_CH_SWITCH:
2573 if (!wpa_s->ap_iface) {
2574 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2575 "event in non-AP mode");
2580 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2581 data->ch_switch.ht_enabled,
2582 data->ch_switch.ch_offset);
2583 #endif /* CONFIG_AP */
2585 case EVENT_RX_MGMT: {
2587 const struct ieee80211_mgmt *mgmt;
2589 mgmt = (const struct ieee80211_mgmt *)
2590 data->rx_mgmt.frame;
2591 fc = le_to_host16(mgmt->frame_control);
2592 stype = WLAN_FC_GET_STYPE(fc);
2594 if (wpa_s->ap_iface == NULL) {
2596 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2597 data->rx_mgmt.frame_len > 24) {
2598 const u8 *src = mgmt->sa;
2599 const u8 *ie = mgmt->u.probe_req.variable;
2600 size_t ie_len = data->rx_mgmt.frame_len -
2601 (mgmt->u.probe_req.variable -
2602 data->rx_mgmt.frame);
2603 wpas_p2p_probe_req_rx(
2604 wpa_s, src, mgmt->da,
2605 mgmt->bssid, ie, ie_len,
2606 data->rx_mgmt.ssi_signal);
2609 #endif /* CONFIG_P2P */
2610 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2611 "management frame in non-AP mode");
2615 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2616 data->rx_mgmt.frame_len > 24) {
2617 const u8 *ie = mgmt->u.probe_req.variable;
2618 size_t ie_len = data->rx_mgmt.frame_len -
2619 (mgmt->u.probe_req.variable -
2620 data->rx_mgmt.frame);
2622 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2623 mgmt->bssid, ie, ie_len,
2624 data->rx_mgmt.ssi_signal);
2627 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2630 #endif /* CONFIG_AP */
2631 case EVENT_RX_ACTION:
2632 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2633 " Category=%u DataLen=%d freq=%d MHz",
2634 MAC2STR(data->rx_action.sa),
2635 data->rx_action.category, (int) data->rx_action.len,
2636 data->rx_action.freq);
2637 #ifdef CONFIG_IEEE80211R
2638 if (data->rx_action.category == WLAN_ACTION_FT) {
2639 ft_rx_action(wpa_s, data->rx_action.data,
2640 data->rx_action.len);
2643 #endif /* CONFIG_IEEE80211R */
2644 #ifdef CONFIG_IEEE80211W
2646 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2647 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2648 data->rx_action.data,
2649 data->rx_action.len);
2652 #endif /* CONFIG_SME */
2653 #endif /* CONFIG_IEEE80211W */
2654 #ifdef CONFIG_IEEE80211V
2655 if (data->rx_action.category == WLAN_ACTION_WNM) {
2656 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2659 #endif /* CONFIG_IEEE80211V */
2661 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2662 gas_query_rx(wpa_s->gas, data->rx_action.da,
2663 data->rx_action.sa, data->rx_action.bssid,
2664 data->rx_action.data, data->rx_action.len,
2665 data->rx_action.freq) == 0)
2667 #endif /* CONFIG_GAS */
2668 if (data->rx_action.category == WLAN_ACTION_WNM) {
2669 wnm_action_rx(wpa_s, &data->rx_action);
2673 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2674 data->rx_action.len >= 4 &&
2675 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2676 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2677 "Response from " MACSTR,
2678 MAC2STR(data->rx_action.sa));
2681 #endif /* CONFIG_TDLS */
2683 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2685 data->rx_action.bssid,
2686 data->rx_action.category,
2687 data->rx_action.data,
2688 data->rx_action.len, data->rx_action.freq);
2689 #endif /* CONFIG_P2P */
2691 case EVENT_RX_PROBE_REQ:
2692 if (data->rx_probe_req.sa == NULL ||
2693 data->rx_probe_req.ie == NULL)
2696 if (wpa_s->ap_iface) {
2697 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2698 data->rx_probe_req.sa,
2699 data->rx_probe_req.da,
2700 data->rx_probe_req.bssid,
2701 data->rx_probe_req.ie,
2702 data->rx_probe_req.ie_len,
2703 data->rx_probe_req.ssi_signal);
2706 #endif /* CONFIG_AP */
2708 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2709 data->rx_probe_req.da,
2710 data->rx_probe_req.bssid,
2711 data->rx_probe_req.ie,
2712 data->rx_probe_req.ie_len,
2713 data->rx_probe_req.ssi_signal);
2714 #endif /* CONFIG_P2P */
2716 case EVENT_REMAIN_ON_CHANNEL:
2717 #ifdef CONFIG_OFFCHANNEL
2718 offchannel_remain_on_channel_cb(
2719 wpa_s, data->remain_on_channel.freq,
2720 data->remain_on_channel.duration);
2721 #endif /* CONFIG_OFFCHANNEL */
2723 wpas_p2p_remain_on_channel_cb(
2724 wpa_s, data->remain_on_channel.freq,
2725 data->remain_on_channel.duration);
2726 #endif /* CONFIG_P2P */
2728 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2729 #ifdef CONFIG_OFFCHANNEL
2730 offchannel_cancel_remain_on_channel_cb(
2731 wpa_s, data->remain_on_channel.freq);
2732 #endif /* CONFIG_OFFCHANNEL */
2734 wpas_p2p_cancel_remain_on_channel_cb(
2735 wpa_s, data->remain_on_channel.freq);
2736 #endif /* CONFIG_P2P */
2739 case EVENT_P2P_DEV_FOUND: {
2740 struct p2p_peer_info peer_info;
2742 os_memset(&peer_info, 0, sizeof(peer_info));
2743 if (data->p2p_dev_found.dev_addr)
2744 os_memcpy(peer_info.p2p_device_addr,
2745 data->p2p_dev_found.dev_addr, ETH_ALEN);
2746 if (data->p2p_dev_found.pri_dev_type)
2747 os_memcpy(peer_info.pri_dev_type,
2748 data->p2p_dev_found.pri_dev_type,
2749 sizeof(peer_info.pri_dev_type));
2750 if (data->p2p_dev_found.dev_name)
2751 os_strlcpy(peer_info.device_name,
2752 data->p2p_dev_found.dev_name,
2753 sizeof(peer_info.device_name));
2754 peer_info.config_methods = data->p2p_dev_found.config_methods;
2755 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2756 peer_info.group_capab = data->p2p_dev_found.group_capab;
2759 * FIX: new_device=1 is not necessarily correct. We should
2760 * maintain a P2P peer database in wpa_supplicant and update
2761 * this information based on whether the peer is truly new.
2763 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2766 case EVENT_P2P_GO_NEG_REQ_RX:
2767 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2768 data->p2p_go_neg_req_rx.dev_passwd_id);
2770 case EVENT_P2P_GO_NEG_COMPLETED:
2771 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2773 case EVENT_P2P_PROV_DISC_REQUEST:
2774 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2775 data->p2p_prov_disc_req.config_methods,
2776 data->p2p_prov_disc_req.dev_addr,
2777 data->p2p_prov_disc_req.pri_dev_type,
2778 data->p2p_prov_disc_req.dev_name,
2779 data->p2p_prov_disc_req.supp_config_methods,
2780 data->p2p_prov_disc_req.dev_capab,
2781 data->p2p_prov_disc_req.group_capab,
2784 case EVENT_P2P_PROV_DISC_RESPONSE:
2785 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2786 data->p2p_prov_disc_resp.config_methods);
2788 case EVENT_P2P_SD_REQUEST:
2789 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2790 data->p2p_sd_req.sa,
2791 data->p2p_sd_req.dialog_token,
2792 data->p2p_sd_req.update_indic,
2793 data->p2p_sd_req.tlvs,
2794 data->p2p_sd_req.tlvs_len);
2796 case EVENT_P2P_SD_RESPONSE:
2797 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2798 data->p2p_sd_resp.update_indic,
2799 data->p2p_sd_resp.tlvs,
2800 data->p2p_sd_resp.tlvs_len);
2802 #endif /* CONFIG_P2P */
2803 case EVENT_EAPOL_RX:
2804 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2805 data->eapol_rx.data,
2806 data->eapol_rx.data_len);
2808 case EVENT_SIGNAL_CHANGE:
2809 bgscan_notify_signal_change(
2810 wpa_s, data->signal_change.above_threshold,
2811 data->signal_change.current_signal,
2812 data->signal_change.current_noise,
2813 data->signal_change.current_txrate);
2815 case EVENT_INTERFACE_ENABLED:
2816 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2817 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2818 wpa_supplicant_update_mac_addr(wpa_s);
2820 if (!wpa_s->ap_iface) {
2821 wpa_supplicant_set_state(wpa_s,
2823 wpa_supplicant_req_scan(wpa_s, 0, 0);
2825 wpa_supplicant_set_state(wpa_s,
2827 #else /* CONFIG_AP */
2828 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2829 wpa_supplicant_req_scan(wpa_s, 0, 0);
2830 #endif /* CONFIG_AP */
2833 case EVENT_INTERFACE_DISABLED:
2834 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2835 wpa_supplicant_mark_disassoc(wpa_s);
2836 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2838 case EVENT_CHANNEL_LIST_CHANGED:
2839 if (wpa_s->drv_priv == NULL)
2840 break; /* Ignore event during drv initialization */
2842 free_hw_features(wpa_s);
2843 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2844 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2847 wpas_p2p_update_channel_list(wpa_s);
2848 #endif /* CONFIG_P2P */
2850 case EVENT_INTERFACE_UNAVAILABLE:
2852 wpas_p2p_interface_unavailable(wpa_s);
2853 #endif /* CONFIG_P2P */
2855 case EVENT_BEST_CHANNEL:
2856 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2858 data->best_chan.freq_24, data->best_chan.freq_5,
2859 data->best_chan.freq_overall);
2860 wpa_s->best_24_freq = data->best_chan.freq_24;
2861 wpa_s->best_5_freq = data->best_chan.freq_5;
2862 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2864 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2865 data->best_chan.freq_5,
2866 data->best_chan.freq_overall);
2867 #endif /* CONFIG_P2P */
2869 case EVENT_UNPROT_DEAUTH:
2870 wpa_supplicant_event_unprot_deauth(wpa_s,
2871 &data->unprot_deauth);
2873 case EVENT_UNPROT_DISASSOC:
2874 wpa_supplicant_event_unprot_disassoc(wpa_s,
2875 &data->unprot_disassoc);
2877 case EVENT_STATION_LOW_ACK:
2879 if (wpa_s->ap_iface && data)
2880 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2881 data->low_ack.addr);
2882 #endif /* CONFIG_AP */
2885 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2886 #endif /* CONFIG_TDLS */
2888 case EVENT_IBSS_PEER_LOST:
2889 #ifdef CONFIG_IBSS_RSN
2890 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2891 #endif /* CONFIG_IBSS_RSN */
2893 case EVENT_DRIVER_GTK_REKEY:
2894 if (os_memcmp(data->driver_gtk_rekey.bssid,
2895 wpa_s->bssid, ETH_ALEN))
2899 wpa_sm_update_replay_ctr(wpa_s->wpa,
2900 data->driver_gtk_rekey.replay_ctr);
2902 case EVENT_SCHED_SCAN_STOPPED:
2903 wpa_s->sched_scanning = 0;
2904 wpa_supplicant_notify_scanning(wpa_s, 0);
2906 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2910 * If we timed out, start a new sched scan to continue
2911 * searching for more SSIDs.
2913 if (wpa_s->sched_scan_timed_out)
2914 wpa_supplicant_req_sched_scan(wpa_s);
2916 case EVENT_WPS_BUTTON_PUSHED:
2918 wpas_wps_start_pbc(wpa_s, NULL, 0);
2919 #endif /* CONFIG_WPS */
2922 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);