blob: bffcd1a15588b4324ea3abc5aa2f1ae3ed8f33aa [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_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"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.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"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
Dmitry Shmidt34af3062013-07-11 10:46:32 -070047#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070048static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
49 int new_scan);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080051
52
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
55{
56 struct os_time now;
57
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
61 os_get_time(&now);
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
64
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
66
67 return 0;
68}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
73 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
85 return -1;
86 }
87
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 return -1;
91 }
92
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080093 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 return -1;
97 }
98
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 res = wpas_temp_disabled(wpa_s, ssid);
100 if (res > 0) {
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
103 return -1;
104 }
105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 } else {
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 }
117
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
126
127 return 0;
128}
129
130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132{
133 struct wpa_supplicant *wpa_s = eloop_ctx;
134
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
140 }
141}
142
143
144void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145{
146 int bssid_changed;
147
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148 wnm_bss_keep_alive_deinit(wpa_s);
149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800163#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700164 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800165#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
167 os_memset(wpa_s->bssid, 0, ETH_ALEN);
168 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700169#ifdef CONFIG_SME
170 wpa_s->sme.prev_bssid_set = 0;
171#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800172#ifdef CONFIG_P2P
173 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
174#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175 wpa_s->current_bss = NULL;
176 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700177#ifdef CONFIG_IEEE80211R
178#ifdef CONFIG_SME
179 if (wpa_s->sme.ft_ies)
180 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
181#endif /* CONFIG_SME */
182#endif /* CONFIG_IEEE80211R */
183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184 if (bssid_changed)
185 wpas_notify_bssid_changed(wpa_s);
186
187 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
188 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
189 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
190 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
191 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700192 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700193 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700194 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195}
196
197
198static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
199{
200 struct wpa_ie_data ie;
201 int pmksa_set = -1;
202 size_t i;
203
204 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
205 ie.pmkid == NULL)
206 return;
207
208 for (i = 0; i < ie.num_pmkid; i++) {
209 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
210 ie.pmkid + i * PMKID_LEN,
211 NULL, NULL, 0);
212 if (pmksa_set == 0) {
213 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
214 break;
215 }
216 }
217
218 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
219 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
220}
221
222
223static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
224 union wpa_event_data *data)
225{
226 if (data == NULL) {
227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
228 "event");
229 return;
230 }
231 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
232 " index=%d preauth=%d",
233 MAC2STR(data->pmkid_candidate.bssid),
234 data->pmkid_candidate.index,
235 data->pmkid_candidate.preauth);
236
237 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
238 data->pmkid_candidate.index,
239 data->pmkid_candidate.preauth);
240}
241
242
243static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
244{
245 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
246 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
247 return 0;
248
249#ifdef IEEE8021X_EAPOL
250 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
251 wpa_s->current_ssid &&
252 !(wpa_s->current_ssid->eapol_flags &
253 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
254 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
255 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
256 * plaintext or static WEP keys). */
257 return 0;
258 }
259#endif /* IEEE8021X_EAPOL */
260
261 return 1;
262}
263
264
265/**
266 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
267 * @wpa_s: pointer to wpa_supplicant data
268 * @ssid: Configuration data for the network
269 * Returns: 0 on success, -1 on failure
270 *
271 * This function is called when starting authentication with a network that is
272 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
273 */
274int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
275 struct wpa_ssid *ssid)
276{
277#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700279 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280
Dmitry Shmidt051af732013-10-22 13:52:46 -0700281 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
282 wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 return 0;
284
285 if (ssid->eap.eap_methods == NULL) {
286 sim = 1;
287 aka = 1;
288 } else {
289 struct eap_method_type *eap = ssid->eap.eap_methods;
290 while (eap->vendor != EAP_VENDOR_IETF ||
291 eap->method != EAP_TYPE_NONE) {
292 if (eap->vendor == EAP_VENDOR_IETF) {
293 if (eap->method == EAP_TYPE_SIM)
294 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700295 else if (eap->method == EAP_TYPE_AKA ||
296 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 aka = 1;
298 }
299 eap++;
300 }
301 }
302
303 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
304 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700305 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
306 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
307 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 aka = 0;
309
310 if (!sim && !aka) {
311 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
312 "use SIM, but neither EAP-SIM nor EAP-AKA are "
313 "enabled");
314 return 0;
315 }
316
317 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
318 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700320 wpa_s->scard = scard_init((!sim && aka) ? SCARD_USIM_ONLY :
321 SCARD_TRY_BOTH, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 if (wpa_s->scard == NULL) {
323 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
324 "(pcsc-lite)");
325 return -1;
326 }
327 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
328 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800329#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330#endif /* IEEE8021X_EAPOL */
331
332 return 0;
333}
334
335
336#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700337
338static int has_wep_key(struct wpa_ssid *ssid)
339{
340 int i;
341
342 for (i = 0; i < NUM_WEP_KEYS; i++) {
343 if (ssid->wep_key_len[i])
344 return 1;
345 }
346
347 return 0;
348}
349
350
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700351static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 struct wpa_ssid *ssid)
353{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700354 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355
356 if (ssid->mixed_cell)
357 return 1;
358
359#ifdef CONFIG_WPS
360 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
361 return 1;
362#endif /* CONFIG_WPS */
363
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700364 if (has_wep_key(ssid))
365 privacy = 1;
366
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367#ifdef IEEE8021X_EAPOL
368 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
369 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
370 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
371 privacy = 1;
372#endif /* IEEE8021X_EAPOL */
373
Jouni Malinen75ecf522011-06-27 15:19:46 -0700374 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
375 privacy = 1;
376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377 if (bss->caps & IEEE80211_CAP_PRIVACY)
378 return privacy;
379 return !privacy;
380}
381
382
383static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
384 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700385 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386{
387 struct wpa_ie_data ie;
388 int proto_match = 0;
389 const u8 *rsn_ie, *wpa_ie;
390 int ret;
391 int wep_ok;
392
393 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
394 if (ret >= 0)
395 return ret;
396
397 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
398 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
399 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
400 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
401 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
402
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700403 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
405 proto_match++;
406
407 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
408 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
409 "failed");
410 break;
411 }
412
413 if (wep_ok &&
414 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
415 {
416 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
417 "in RSN IE");
418 return 1;
419 }
420
421 if (!(ie.proto & ssid->proto)) {
422 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
423 "mismatch");
424 break;
425 }
426
427 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
428 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
429 "cipher mismatch");
430 break;
431 }
432
433 if (!(ie.group_cipher & ssid->group_cipher)) {
434 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
435 "cipher mismatch");
436 break;
437 }
438
439 if (!(ie.key_mgmt & ssid->key_mgmt)) {
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
441 "mismatch");
442 break;
443 }
444
445#ifdef CONFIG_IEEE80211W
446 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800447 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
448 wpa_s->conf->pmf : ssid->ieee80211w) ==
449 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
451 "frame protection");
452 break;
453 }
454#endif /* CONFIG_IEEE80211W */
455
456 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
457 return 1;
458 }
459
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700460 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
462 proto_match++;
463
464 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
466 "failed");
467 break;
468 }
469
470 if (wep_ok &&
471 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
472 {
473 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
474 "in WPA IE");
475 return 1;
476 }
477
478 if (!(ie.proto & ssid->proto)) {
479 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
480 "mismatch");
481 break;
482 }
483
484 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
485 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
486 "cipher mismatch");
487 break;
488 }
489
490 if (!(ie.group_cipher & ssid->group_cipher)) {
491 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
492 "cipher mismatch");
493 break;
494 }
495
496 if (!(ie.key_mgmt & ssid->key_mgmt)) {
497 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
498 "mismatch");
499 break;
500 }
501
502 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
503 return 1;
504 }
505
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700506 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
507 !rsn_ie) {
508 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
509 return 1;
510 }
511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
513 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
514 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
515 return 0;
516 }
517
518 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
519 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
520 return 1;
521 }
522
523 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
524 "WPA/WPA2");
525
526 return 0;
527}
528
529
530static int freq_allowed(int *freqs, int freq)
531{
532 int i;
533
534 if (freqs == NULL)
535 return 1;
536
537 for (i = 0; freqs[i]; i++)
538 if (freqs[i] == freq)
539 return 1;
540 return 0;
541}
542
543
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800544static int ht_supported(const struct hostapd_hw_modes *mode)
545{
546 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
547 /*
548 * The driver did not indicate whether it supports HT. Assume
549 * it does to avoid connection issues.
550 */
551 return 1;
552 }
553
554 /*
555 * IEEE Std 802.11n-2009 20.1.1:
556 * An HT non-AP STA shall support all EQM rates for one spatial stream.
557 */
558 return mode->mcs_set[0] == 0xff;
559}
560
561
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700562static int vht_supported(const struct hostapd_hw_modes *mode)
563{
564 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
565 /*
566 * The driver did not indicate whether it supports VHT. Assume
567 * it does to avoid connection issues.
568 */
569 return 1;
570 }
571
572 /*
573 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
574 * TODO: Verify if this complies with the standard
575 */
576 return (mode->vht_mcs_set[0] & 0x3) != 3;
577}
578
579
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700580static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800581{
582 const struct hostapd_hw_modes *mode = NULL, *modes;
583 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
584 const u8 *rate_ie;
585 int i, j, k;
586
587 if (bss->freq == 0)
588 return 1; /* Cannot do matching without knowing band */
589
590 modes = wpa_s->hw.modes;
591 if (modes == NULL) {
592 /*
593 * The driver does not provide any additional information
594 * about the utilized hardware, so allow the connection attempt
595 * to continue.
596 */
597 return 1;
598 }
599
600 for (i = 0; i < wpa_s->hw.num_modes; i++) {
601 for (j = 0; j < modes[i].num_channels; j++) {
602 int freq = modes[i].channels[j].freq;
603 if (freq == bss->freq) {
604 if (mode &&
605 mode->mode == HOSTAPD_MODE_IEEE80211G)
606 break; /* do not allow 802.11b replace
607 * 802.11g */
608 mode = &modes[i];
609 break;
610 }
611 }
612 }
613
614 if (mode == NULL)
615 return 0;
616
617 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700618 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800619 if (rate_ie == NULL)
620 continue;
621
622 for (j = 2; j < rate_ie[1] + 2; j++) {
623 int flagged = !!(rate_ie[j] & 0x80);
624 int r = (rate_ie[j] & 0x7f) * 5;
625
626 /*
627 * IEEE Std 802.11n-2009 7.3.2.2:
628 * The new BSS Membership selector value is encoded
629 * like a legacy basic rate, but it is not a rate and
630 * only indicates if the BSS members are required to
631 * support the mandatory features of Clause 20 [HT PHY]
632 * in order to join the BSS.
633 */
634 if (flagged && ((rate_ie[j] & 0x7f) ==
635 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
636 if (!ht_supported(mode)) {
637 wpa_dbg(wpa_s, MSG_DEBUG,
638 " hardware does not support "
639 "HT PHY");
640 return 0;
641 }
642 continue;
643 }
644
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700645 /* There's also a VHT selector for 802.11ac */
646 if (flagged && ((rate_ie[j] & 0x7f) ==
647 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
648 if (!vht_supported(mode)) {
649 wpa_dbg(wpa_s, MSG_DEBUG,
650 " hardware does not support "
651 "VHT PHY");
652 return 0;
653 }
654 continue;
655 }
656
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800657 if (!flagged)
658 continue;
659
660 /* check for legacy basic rates */
661 for (k = 0; k < mode->num_rates; k++) {
662 if (mode->rates[k] == r)
663 break;
664 }
665 if (k == mode->num_rates) {
666 /*
667 * IEEE Std 802.11-2007 7.3.2.2 demands that in
668 * order to join a BSS all required rates
669 * have to be supported by the hardware.
670 */
671 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
672 "not support required rate %d.%d Mbps",
673 r / 10, r % 10);
674 return 0;
675 }
676 }
677 }
678
679 return 1;
680}
681
682
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800683static int bss_is_dmg(struct wpa_bss *bss)
684{
685 return bss->freq > 45000;
686}
687
688
689/*
690 * Test whether BSS is in an ESS.
691 * This is done differently in DMG (60 GHz) and non-DMG bands
692 */
693static int bss_is_ess(struct wpa_bss *bss)
694{
695 if (bss_is_dmg(bss)) {
696 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
697 IEEE80211_CAP_DMG_AP;
698 }
699
700 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
701 IEEE80211_CAP_ESS);
702}
703
704
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700706 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 struct wpa_ssid *group)
708{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700709 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 int wpa;
711 struct wpa_blacklist *e;
712 const u8 *ie;
713 struct wpa_ssid *ssid;
714
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700715 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716 wpa_ie_len = ie ? ie[1] : 0;
717
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700718 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 rsn_ie_len = ie ? ie[1] : 0;
720
721 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidt96571392013-10-14 12:54:46 -0700722 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700723 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700725 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
726 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
727 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
728 " p2p" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729
730 e = wpa_blacklist_get(wpa_s, bss->bssid);
731 if (e) {
732 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700733 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 /*
735 * When only a single network is enabled, we can
736 * trigger blacklisting on the first failure. This
737 * should not be done with multiple enabled networks to
738 * avoid getting forced to move into a worse ESS on
739 * single error if there are no other BSSes of the
740 * current ESS.
741 */
742 limit = 0;
743 }
744 if (e->count > limit) {
745 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
746 "(count=%d limit=%d)", e->count, limit);
747 return NULL;
748 }
749 }
750
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700751 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
753 return NULL;
754 }
755
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800756 if (disallowed_bssid(wpa_s, bss->bssid)) {
757 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
758 return NULL;
759 }
760
761 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
762 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
763 return NULL;
764 }
765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
767
768 for (ssid = group; ssid; ssid = ssid->pnext) {
769 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700770 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771
Dmitry Shmidt04949592012-07-19 12:16:46 -0700772 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
774 continue;
775 }
776
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700777 res = wpas_temp_disabled(wpa_s, ssid);
778 if (res > 0) {
779 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
780 "temporarily for %d second(s)", res);
781 continue;
782 }
783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784#ifdef CONFIG_WPS
785 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
786 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
787 "(WPS)");
788 continue;
789 }
790
791 if (wpa && ssid->ssid_len == 0 &&
792 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
793 check_ssid = 0;
794
795 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
796 /* Only allow wildcard SSID match if an AP
797 * advertises active WPS operation that matches
798 * with our mode. */
799 check_ssid = 1;
800 if (ssid->ssid_len == 0 &&
801 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
802 check_ssid = 0;
803 }
804#endif /* CONFIG_WPS */
805
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806 if (ssid->bssid_set && ssid->ssid_len == 0 &&
807 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
808 check_ssid = 0;
809
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700811 (bss->ssid_len != ssid->ssid_len ||
812 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
814 continue;
815 }
816
817 if (ssid->bssid_set &&
818 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
819 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
820 continue;
821 }
822
823 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
824 continue;
825
826 if (!wpa &&
827 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
828 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
829 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
830 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
831 "not allowed");
832 continue;
833 }
834
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700835 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
836 has_wep_key(ssid)) {
837 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
838 continue;
839 }
840
Jouni Malinen75ecf522011-06-27 15:19:46 -0700841 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
843 "mismatch");
844 continue;
845 }
846
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800847 if (!bss_is_ess(bss)) {
848 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849 continue;
850 }
851
852 if (!freq_allowed(ssid->freq_list, bss->freq)) {
853 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
854 "allowed");
855 continue;
856 }
857
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800858 if (!rate_match(wpa_s, bss)) {
859 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
860 "not match");
861 continue;
862 }
863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700865 if (ssid->p2p_group &&
866 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
867 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
868 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
869 continue;
870 }
871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 /*
873 * TODO: skip the AP if its P2P IE has Group Formation
874 * bit set in the P2P Group Capability Bitmap and we
875 * are not in Group Formation with that device.
876 */
877#endif /* CONFIG_P2P */
878
879 /* Matching configuration found */
880 return ssid;
881 }
882
883 /* No matching configuration found */
884 return NULL;
885}
886
887
888static struct wpa_bss *
889wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890 struct wpa_ssid *group,
891 struct wpa_ssid **selected_ssid)
892{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700893 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894
895 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
896 group->priority);
897
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700898 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
899 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
901 if (!*selected_ssid)
902 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
904 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700905 MAC2STR(bss->bssid),
906 wpa_ssid_txt(bss->ssid, bss->ssid_len));
907 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 }
909
910 return NULL;
911}
912
913
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700914struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
915 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916{
917 struct wpa_bss *selected = NULL;
918 int prio;
919
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 if (wpa_s->last_scan_res == NULL ||
921 wpa_s->last_scan_res_used == 0)
922 return NULL; /* no scan results from last update */
923
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 while (selected == NULL) {
925 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
926 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700927 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 selected_ssid);
929 if (selected)
930 break;
931 }
932
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800933 if (selected == NULL && wpa_s->blacklist &&
934 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
936 "blacklist and try again");
937 wpa_blacklist_clear(wpa_s);
938 wpa_s->blacklist_cleared++;
939 } else if (selected == NULL)
940 break;
941 }
942
943 return selected;
944}
945
946
947static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
948 int timeout_sec, int timeout_usec)
949{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700950 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 /*
952 * No networks are enabled; short-circuit request so
953 * we don't wait timeout seconds before transitioning
954 * to INACTIVE state.
955 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700956 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
957 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700959#ifdef CONFIG_P2P
960 wpa_s->sta_scan_pending = 0;
961#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 return;
963 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800964
965 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
967}
968
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800969
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700970int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800971 struct wpa_bss *selected,
972 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973{
974 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
975 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
976 "PBC session overlap");
977#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800978 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700979 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980#endif /* CONFIG_P2P */
981
982#ifdef CONFIG_WPS
983 wpas_wps_cancel(wpa_s);
984#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700985 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 }
987
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700988 wpa_msg(wpa_s, MSG_DEBUG,
989 "Considering connect request: reassociate: %d selected: "
990 MACSTR " bssid: " MACSTR " pending: " MACSTR
991 " wpa_state: %s ssid=%p current_ssid=%p",
992 wpa_s->reassociate, MAC2STR(selected->bssid),
993 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
994 wpa_supplicant_state_txt(wpa_s->wpa_state),
995 ssid, wpa_s->current_ssid);
996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997 /*
998 * Do not trigger new association unless the BSSID has changed or if
999 * reassociation is requested. If we are in process of associating with
1000 * the selected BSSID, do not trigger new attempt.
1001 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1004 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1005 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001006 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1007 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1008 0) ||
1009 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1010 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1012 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001013 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001015 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1016 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017 wpa_supplicant_associate(wpa_s, selected, ssid);
1018 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001019 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1020 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001022
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001023 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001024}
1025
1026
1027static struct wpa_ssid *
1028wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1029{
1030 int prio;
1031 struct wpa_ssid *ssid;
1032
1033 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1034 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1035 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001036 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 continue;
1038 if (ssid->mode == IEEE80211_MODE_IBSS ||
1039 ssid->mode == IEEE80211_MODE_AP)
1040 return ssid;
1041 }
1042 }
1043 return NULL;
1044}
1045
1046
1047/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1048 * on BSS added and BSS changed events */
1049static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001050 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001052 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053
1054 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1055 return;
1056
Jouni Malinen87fd2792011-05-16 18:35:42 +03001057 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059
Jouni Malinen87fd2792011-05-16 18:35:42 +03001060 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 if (ssid == NULL)
1062 continue;
1063
Jouni Malinen87fd2792011-05-16 18:35:42 +03001064 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 if (rsn == NULL)
1066 continue;
1067
Jouni Malinen87fd2792011-05-16 18:35:42 +03001068 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 }
1070
1071}
1072
1073
1074static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1075 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001076 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001078 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 int min_diff;
1080
1081 if (wpa_s->reassociate)
1082 return 1; /* explicit request to reassociate */
1083 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1084 return 1; /* we are not associated; continue */
1085 if (wpa_s->current_ssid == NULL)
1086 return 1; /* unknown current SSID */
1087 if (wpa_s->current_ssid != ssid)
1088 return 1; /* different network block */
1089
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001090 if (wpas_driver_bss_selection(wpa_s))
1091 return 0; /* Driver-based roaming */
1092
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001093 if (wpa_s->current_ssid->ssid)
1094 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1095 wpa_s->current_ssid->ssid,
1096 wpa_s->current_ssid->ssid_len);
1097 if (!current_bss)
1098 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099
1100 if (!current_bss)
1101 return 1; /* current BSS not seen in scan results */
1102
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001103 if (current_bss == selected)
1104 return 0;
1105
1106 if (selected->last_update_idx > current_bss->last_update_idx)
1107 return 1; /* current BSS not seen in the last scan */
1108
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001109#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1111 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1112 MAC2STR(current_bss->bssid), current_bss->level);
1113 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1114 MAC2STR(selected->bssid), selected->level);
1115
1116 if (wpa_s->current_ssid->bssid_set &&
1117 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1118 0) {
1119 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1120 "has preferred BSSID");
1121 return 1;
1122 }
1123
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001124 if (current_bss->level < 0 && current_bss->level > selected->level) {
1125 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1126 "signal level");
1127 return 0;
1128 }
1129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 min_diff = 2;
1131 if (current_bss->level < 0) {
1132 if (current_bss->level < -85)
1133 min_diff = 1;
1134 else if (current_bss->level < -80)
1135 min_diff = 2;
1136 else if (current_bss->level < -75)
1137 min_diff = 3;
1138 else if (current_bss->level < -70)
1139 min_diff = 4;
1140 else
1141 min_diff = 5;
1142 }
1143 if (abs(current_bss->level - selected->level) < min_diff) {
1144 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1145 "in signal level");
1146 return 0;
1147 }
1148
1149 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001150#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001151 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001152#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153}
1154
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001155
Jouni Malinen89ca7022012-09-14 13:03:12 -07001156/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001157 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001158static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001159 union wpa_event_data *data,
1160 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001162 struct wpa_scan_results *scan_res;
1163 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001164#ifndef CONFIG_NO_RANDOM_POOL
1165 size_t i, num;
1166#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167
1168#ifdef CONFIG_AP
1169 if (wpa_s->ap_iface)
1170 ap = 1;
1171#endif /* CONFIG_AP */
1172
1173 wpa_supplicant_notify_scanning(wpa_s, 0);
1174
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001175#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001176 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001177 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001178 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1179 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001180 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001181 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1182 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1183 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001184 wpa_s->sta_scan_pending = 1;
1185 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001186 return -1;
1187 }
1188 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001189 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001190#endif /* CONFIG_P2P */
1191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1193 data ? &data->scan_info :
1194 NULL, 1);
1195 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001196 if (wpa_s->conf->ap_scan == 2 || ap ||
1197 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001198 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001199 if (!own_request)
1200 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1202 "scanning again");
1203 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1204 return -1;
1205 }
1206
1207#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 num = scan_res->num;
1209 if (num > 10)
1210 num = 10;
1211 for (i = 0; i < num; i++) {
1212 u8 buf[5];
1213 struct wpa_scan_res *res = scan_res->res[i];
1214 buf[0] = res->bssid[5];
1215 buf[1] = res->qual & 0xff;
1216 buf[2] = res->noise & 0xff;
1217 buf[3] = res->level & 0xff;
1218 buf[4] = res->tsf & 0xff;
1219 random_add_randomness(buf, sizeof(buf));
1220 }
1221#endif /* CONFIG_NO_RANDOM_POOL */
1222
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001223 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1225 struct wpa_scan_results *scan_res);
1226
1227 scan_res_handler = wpa_s->scan_res_handler;
1228 wpa_s->scan_res_handler = NULL;
1229 scan_res_handler(wpa_s, scan_res);
1230
1231 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001232 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233 }
1234
1235 if (ap) {
1236 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1237#ifdef CONFIG_AP
1238 if (wpa_s->ap_iface->scan_cb)
1239 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1240#endif /* CONFIG_AP */
1241 wpa_scan_results_free(scan_res);
1242 return 0;
1243 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001244
Dmitry Shmidt04949592012-07-19 12:16:46 -07001245 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1246 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1247 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001248
1249 wpas_notify_scan_done(wpa_s, 1);
1250
Dmitry Shmidt04949592012-07-19 12:16:46 -07001251 if (sme_proc_obss_scan(wpa_s) > 0) {
1252 wpa_scan_results_free(scan_res);
1253 return 0;
1254 }
1255
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1257 wpa_scan_results_free(scan_res);
1258 return 0;
1259 }
1260
Dmitry Shmidt04949592012-07-19 12:16:46 -07001261 if (autoscan_notify_scan(wpa_s, scan_res)) {
1262 wpa_scan_results_free(scan_res);
1263 return 0;
1264 }
1265
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266 if (wpa_s->disconnected) {
1267 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1268 wpa_scan_results_free(scan_res);
1269 return 0;
1270 }
1271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001272 if (!wpas_driver_bss_selection(wpa_s) &&
1273 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274 wpa_scan_results_free(scan_res);
1275 return 0;
1276 }
1277
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001278 wpas_wps_update_ap_info(wpa_s, scan_res);
1279
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001280 wpa_scan_results_free(scan_res);
1281
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001282 return wpas_select_network_from_last_scan(wpa_s, 1);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001283}
1284
1285
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001286static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1287 int new_scan)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001288{
1289 struct wpa_bss *selected;
1290 struct wpa_ssid *ssid = NULL;
1291
1292 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001293
1294 if (selected) {
1295 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001296 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001297 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001298 if (new_scan)
1299 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001301 }
1302
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001303 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001304 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001305 return -1;
1306 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001307 if (new_scan)
1308 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001309 /*
1310 * Do not notify other virtual radios of scan results since we do not
1311 * want them to start other associations at the same time.
1312 */
1313 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1316 ssid = wpa_supplicant_pick_new_network(wpa_s);
1317 if (ssid) {
1318 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1319 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001320 if (new_scan)
1321 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 } else {
1323 int timeout_sec = wpa_s->scan_interval;
1324 int timeout_usec = 0;
1325#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001326 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1327 return 0;
1328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 if (wpa_s->p2p_in_provisioning) {
1330 /*
1331 * Use shorter wait during P2P Provisioning
1332 * state to speed up group formation.
1333 */
1334 timeout_sec = 0;
1335 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001336 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1337 timeout_usec);
1338 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001339 }
1340#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001341#ifdef CONFIG_INTERWORKING
1342 if (wpa_s->conf->auto_interworking &&
1343 wpa_s->conf->interworking &&
1344 wpa_s->conf->cred) {
1345 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1346 "start ANQP fetch since no matching "
1347 "networks found");
1348 wpa_s->network_select = 1;
1349 wpa_s->auto_network_select = 1;
1350 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001351 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001352 }
1353#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001354 if (wpa_supplicant_req_sched_scan(wpa_s))
1355 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1356 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001357 }
1358 }
1359 return 0;
1360}
1361
1362
1363static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1364 union wpa_event_data *data)
1365{
1366 const char *rn, *rn2;
1367 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001368
1369 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370 /*
1371 * If no scan results could be fetched, then no need to
1372 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001373 * this scan. Similarly, if scan results started a new operation on this
1374 * interface, do not notify other interfaces to avoid concurrent
1375 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376 */
1377 return;
1378 }
1379
1380 /*
1381 * Check other interfaces to see if they have the same radio-name. If
1382 * so, they get updated with this same scan info.
1383 */
1384 if (!wpa_s->driver->get_radio_name)
1385 return;
1386
1387 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1388 if (rn == NULL || rn[0] == '\0')
1389 return;
1390
1391 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1392 "sharing same radio (%s) in event_scan_results", rn);
1393
1394 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1395 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1396 continue;
1397
1398 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1399 if (rn2 && os_strcmp(rn, rn2) == 0) {
1400 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1401 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001402 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403 }
1404 }
1405}
1406
1407#endif /* CONFIG_NO_SCAN_PROCESSING */
1408
1409
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001410int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1411{
1412#ifdef CONFIG_NO_SCAN_PROCESSING
1413 return -1;
1414#else /* CONFIG_NO_SCAN_PROCESSING */
1415 struct os_time now;
1416
1417 if (wpa_s->last_scan_res_used <= 0)
1418 return -1;
1419
1420 os_get_time(&now);
1421 if (now.sec - wpa_s->last_scan.sec > 5) {
1422 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1423 return -1;
1424 }
1425
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001426 return wpas_select_network_from_last_scan(wpa_s, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001427#endif /* CONFIG_NO_SCAN_PROCESSING */
1428}
1429
Dmitry Shmidt04949592012-07-19 12:16:46 -07001430#ifdef CONFIG_WNM
1431
1432static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1433{
1434 struct wpa_supplicant *wpa_s = eloop_ctx;
1435
1436 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1437 return;
1438
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001439 if (!wpa_s->no_keep_alive) {
1440 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1441 MAC2STR(wpa_s->bssid));
1442 /* TODO: could skip this if normal data traffic has been sent */
1443 /* TODO: Consider using some more appropriate data frame for
1444 * this */
1445 if (wpa_s->l2)
1446 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1447 (u8 *) "", 0);
1448 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001449
1450#ifdef CONFIG_SME
1451 if (wpa_s->sme.bss_max_idle_period) {
1452 unsigned int msec;
1453 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1454 if (msec > 100)
1455 msec -= 100;
1456 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1457 wnm_bss_keep_alive, wpa_s, NULL);
1458 }
1459#endif /* CONFIG_SME */
1460}
1461
1462
1463static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1464 const u8 *ies, size_t ies_len)
1465{
1466 struct ieee802_11_elems elems;
1467
1468 if (ies == NULL)
1469 return;
1470
1471 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1472 return;
1473
1474#ifdef CONFIG_SME
1475 if (elems.bss_max_idle_period) {
1476 unsigned int msec;
1477 wpa_s->sme.bss_max_idle_period =
1478 WPA_GET_LE16(elems.bss_max_idle_period);
1479 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1480 "TU)%s", wpa_s->sme.bss_max_idle_period,
1481 (elems.bss_max_idle_period[2] & 0x01) ?
1482 " (protected keep-live required)" : "");
1483 if (wpa_s->sme.bss_max_idle_period == 0)
1484 wpa_s->sme.bss_max_idle_period = 1;
1485 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1486 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1487 /* msec times 1000 */
1488 msec = wpa_s->sme.bss_max_idle_period * 1024;
1489 if (msec > 100)
1490 msec -= 100;
1491 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1492 wnm_bss_keep_alive, wpa_s,
1493 NULL);
1494 }
1495 }
1496#endif /* CONFIG_SME */
1497}
1498
1499#endif /* CONFIG_WNM */
1500
1501
1502void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1503{
1504#ifdef CONFIG_WNM
1505 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1506#endif /* CONFIG_WNM */
1507}
1508
1509
Dmitry Shmidt051af732013-10-22 13:52:46 -07001510#ifdef CONFIG_INTERWORKING
1511
1512static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1513 size_t len)
1514{
1515 int res;
1516
1517 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1518 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1519 if (res) {
1520 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1521 }
1522
1523 return res;
1524}
1525
1526
1527static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1528 const u8 *ies, size_t ies_len)
1529{
1530 struct ieee802_11_elems elems;
1531
1532 if (ies == NULL)
1533 return;
1534
1535 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1536 return;
1537
1538 if (elems.qos_map_set) {
1539 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1540 elems.qos_map_set_len);
1541 }
1542}
1543
1544#endif /* CONFIG_INTERWORKING */
1545
1546
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001547static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1548 union wpa_event_data *data)
1549{
1550 int l, len, found = 0, wpa_found, rsn_found;
1551 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001552#ifdef CONFIG_IEEE80211R
1553 u8 bssid[ETH_ALEN];
1554#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001555
1556 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1557 if (data->assoc_info.req_ies)
1558 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1559 data->assoc_info.req_ies_len);
1560 if (data->assoc_info.resp_ies) {
1561 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1562 data->assoc_info.resp_ies_len);
1563#ifdef CONFIG_TDLS
1564 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1565 data->assoc_info.resp_ies_len);
1566#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001567#ifdef CONFIG_WNM
1568 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1569 data->assoc_info.resp_ies_len);
1570#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001571#ifdef CONFIG_INTERWORKING
1572 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1573 data->assoc_info.resp_ies_len);
1574#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 }
1576 if (data->assoc_info.beacon_ies)
1577 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1578 data->assoc_info.beacon_ies,
1579 data->assoc_info.beacon_ies_len);
1580 if (data->assoc_info.freq)
1581 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1582 data->assoc_info.freq);
1583
1584 p = data->assoc_info.req_ies;
1585 l = data->assoc_info.req_ies_len;
1586
1587 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1588 while (p && l >= 2) {
1589 len = p[1] + 2;
1590 if (len > l) {
1591 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1592 p, l);
1593 break;
1594 }
1595 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1596 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1597 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1598 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1599 break;
1600 found = 1;
1601 wpa_find_assoc_pmkid(wpa_s);
1602 break;
1603 }
1604 l -= len;
1605 p += len;
1606 }
1607 if (!found && data->assoc_info.req_ies)
1608 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1609
1610#ifdef CONFIG_IEEE80211R
1611#ifdef CONFIG_SME
1612 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001613 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1614 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1615 data->assoc_info.resp_ies,
1616 data->assoc_info.resp_ies_len,
1617 bssid) < 0) {
1618 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1619 "Reassociation Response failed");
1620 wpa_supplicant_deauthenticate(
1621 wpa_s, WLAN_REASON_INVALID_IE);
1622 return -1;
1623 }
1624 }
1625
1626 p = data->assoc_info.resp_ies;
1627 l = data->assoc_info.resp_ies_len;
1628
1629#ifdef CONFIG_WPS_STRICT
1630 if (p && wpa_s->current_ssid &&
1631 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1632 struct wpabuf *wps;
1633 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1634 if (wps == NULL) {
1635 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1636 "include WPS IE in (Re)Association Response");
1637 return -1;
1638 }
1639
1640 if (wps_validate_assoc_resp(wps) < 0) {
1641 wpabuf_free(wps);
1642 wpa_supplicant_deauthenticate(
1643 wpa_s, WLAN_REASON_INVALID_IE);
1644 return -1;
1645 }
1646 wpabuf_free(wps);
1647 }
1648#endif /* CONFIG_WPS_STRICT */
1649
1650 /* Go through the IEs and make a copy of the MDIE, if present. */
1651 while (p && l >= 2) {
1652 len = p[1] + 2;
1653 if (len > l) {
1654 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1655 p, l);
1656 break;
1657 }
1658 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1659 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1660 wpa_s->sme.ft_used = 1;
1661 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1662 MOBILITY_DOMAIN_ID_LEN);
1663 break;
1664 }
1665 l -= len;
1666 p += len;
1667 }
1668#endif /* CONFIG_SME */
1669
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001670 /* Process FT when SME is in the driver */
1671 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1672 wpa_ft_is_completed(wpa_s->wpa)) {
1673 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1674 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1675 data->assoc_info.resp_ies,
1676 data->assoc_info.resp_ies_len,
1677 bssid) < 0) {
1678 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1679 "Reassociation Response failed");
1680 wpa_supplicant_deauthenticate(
1681 wpa_s, WLAN_REASON_INVALID_IE);
1682 return -1;
1683 }
1684 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1685 }
1686
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001687 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1688 data->assoc_info.resp_ies_len);
1689#endif /* CONFIG_IEEE80211R */
1690
1691 /* WPA/RSN IE from Beacon/ProbeResp */
1692 p = data->assoc_info.beacon_ies;
1693 l = data->assoc_info.beacon_ies_len;
1694
1695 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1696 */
1697 wpa_found = rsn_found = 0;
1698 while (p && l >= 2) {
1699 len = p[1] + 2;
1700 if (len > l) {
1701 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1702 p, l);
1703 break;
1704 }
1705 if (!wpa_found &&
1706 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1707 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1708 wpa_found = 1;
1709 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1710 }
1711
1712 if (!rsn_found &&
1713 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1714 rsn_found = 1;
1715 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1716 }
1717
1718 l -= len;
1719 p += len;
1720 }
1721
1722 if (!wpa_found && data->assoc_info.beacon_ies)
1723 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1724 if (!rsn_found && data->assoc_info.beacon_ies)
1725 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1726 if (wpa_found || rsn_found)
1727 wpa_s->ap_ies_from_associnfo = 1;
1728
Jouni Malinen87fd2792011-05-16 18:35:42 +03001729 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1730 wpa_s->assoc_freq != data->assoc_info.freq) {
1731 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1732 "%u to %u MHz",
1733 wpa_s->assoc_freq, data->assoc_info.freq);
1734 wpa_supplicant_update_scan_results(wpa_s);
1735 }
1736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 wpa_s->assoc_freq = data->assoc_info.freq;
1738
1739 return 0;
1740}
1741
1742
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001743static struct wpa_bss * wpa_supplicant_get_new_bss(
1744 struct wpa_supplicant *wpa_s, const u8 *bssid)
1745{
1746 struct wpa_bss *bss = NULL;
1747 struct wpa_ssid *ssid = wpa_s->current_ssid;
1748
1749 if (ssid->ssid_len > 0)
1750 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1751 if (!bss)
1752 bss = wpa_bss_get_bssid(wpa_s, bssid);
1753
1754 return bss;
1755}
1756
1757
1758static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1759{
1760 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1761
1762 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1763 return -1;
1764
1765 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1766 return 0;
1767
1768 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1769 WPA_IE_VENDOR_TYPE);
1770 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1771
1772 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1773 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1774 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1775 bss_rsn ? 2 + bss_rsn[1] : 0))
1776 return -1;
1777
1778 return 0;
1779}
1780
1781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1783 union wpa_event_data *data)
1784{
1785 u8 bssid[ETH_ALEN];
1786 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787
1788#ifdef CONFIG_AP
1789 if (wpa_s->ap_iface) {
1790 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1791 data->assoc_info.addr,
1792 data->assoc_info.req_ies,
1793 data->assoc_info.req_ies_len,
1794 data->assoc_info.reassoc);
1795 return;
1796 }
1797#endif /* CONFIG_AP */
1798
1799 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1800 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1801 return;
1802
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001803 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1804 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001805 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001806 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1807 return;
1808 }
1809
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001811 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001812 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1813 MACSTR, MAC2STR(bssid));
1814 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001815 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1816 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001817 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001818
1819 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1820 wpa_clear_keys(wpa_s, bssid);
1821 }
1822 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001823 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1825 return;
1826 }
1827 if (wpa_s->current_ssid) {
1828 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001829
1830 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1831 if (!bss) {
1832 wpa_supplicant_update_scan_results(wpa_s);
1833
1834 /* Get the BSS from the new scan results */
1835 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1836 }
1837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 if (bss)
1839 wpa_s->current_bss = bss;
1840 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001841
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001842#ifdef ANDROID
1843 if (wpa_s->conf->ap_scan == 1) {
1844#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001845 if (wpa_s->conf->ap_scan == 1 &&
1846 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001847#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001848 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1849 wpa_msg(wpa_s, MSG_WARNING,
1850 "WPA/RSN IEs not updated");
1851 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001852 }
1853
1854#ifdef CONFIG_SME
1855 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1856 wpa_s->sme.prev_bssid_set = 1;
1857#endif /* CONFIG_SME */
1858
1859 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1860 if (wpa_s->current_ssid) {
1861 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1862 * initialized before association, but for other modes,
1863 * initialize PC/SC here, if the current configuration needs
1864 * smartcard or SIM/USIM. */
1865 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1866 }
1867 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1868 if (wpa_s->l2)
1869 l2_packet_notify_auth_start(wpa_s->l2);
1870
1871 /*
1872 * Set portEnabled first to FALSE in order to get EAP state machine out
1873 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1874 * state machine may transit to AUTHENTICATING state based on obsolete
1875 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1876 * AUTHENTICATED without ever giving chance to EAP state machine to
1877 * reset the state.
1878 */
1879 if (!ft_completed) {
1880 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1881 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1882 }
1883 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1884 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1885 /* 802.1X::portControl = Auto */
1886 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1887 wpa_s->eapol_received = 0;
1888 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1889 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1890 (wpa_s->current_ssid &&
1891 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001892 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1893 (wpa_s->drv_flags &
1894 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1895 /*
1896 * Set the key after having received joined-IBSS event
1897 * from the driver.
1898 */
1899 wpa_supplicant_set_wpa_none_key(wpa_s,
1900 wpa_s->current_ssid);
1901 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902 wpa_supplicant_cancel_auth_timeout(wpa_s);
1903 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1904 } else if (!ft_completed) {
1905 /* Timeout for receiving the first EAPOL packet */
1906 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1907 }
1908 wpa_supplicant_cancel_scan(wpa_s);
1909
1910 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1911 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1912 /*
1913 * We are done; the driver will take care of RSN 4-way
1914 * handshake.
1915 */
1916 wpa_supplicant_cancel_auth_timeout(wpa_s);
1917 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1918 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1919 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1920 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1921 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1922 /*
1923 * The driver will take care of RSN 4-way handshake, so we need
1924 * to allow EAPOL supplicant to complete its work without
1925 * waiting for WPA supplicant.
1926 */
1927 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1928 } else if (ft_completed) {
1929 /*
1930 * FT protocol completed - make sure EAPOL state machine ends
1931 * up in authenticated.
1932 */
1933 wpa_supplicant_cancel_auth_timeout(wpa_s);
1934 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1935 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1936 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1937 }
1938
Jouni Malinena05074c2012-12-21 21:35:35 +02001939 wpa_s->last_eapol_matches_bssid = 0;
1940
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001941 if (wpa_s->pending_eapol_rx) {
1942 struct os_time now, age;
1943 os_get_time(&now);
1944 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1945 if (age.sec == 0 && age.usec < 100000 &&
1946 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1947 0) {
1948 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1949 "frame that was received just before "
1950 "association notification");
1951 wpa_supplicant_rx_eapol(
1952 wpa_s, wpa_s->pending_eapol_rx_src,
1953 wpabuf_head(wpa_s->pending_eapol_rx),
1954 wpabuf_len(wpa_s->pending_eapol_rx));
1955 }
1956 wpabuf_free(wpa_s->pending_eapol_rx);
1957 wpa_s->pending_eapol_rx = NULL;
1958 }
1959
1960 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1961 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001962 wpa_s->current_ssid &&
1963 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964 /* Set static WEP keys again */
1965 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1966 }
1967
1968#ifdef CONFIG_IBSS_RSN
1969 if (wpa_s->current_ssid &&
1970 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1971 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1972 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1973 wpa_s->ibss_rsn == NULL) {
1974 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1975 if (!wpa_s->ibss_rsn) {
1976 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1977 wpa_supplicant_deauthenticate(
1978 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1979 return;
1980 }
1981
1982 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1983 }
1984#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001985
1986 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001987}
1988
1989
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001990static int disconnect_reason_recoverable(u16 reason_code)
1991{
1992 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1993 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1994 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1995}
1996
1997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001999 u16 reason_code,
2000 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002001{
2002 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002003
2004 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2005 /*
2006 * At least Host AP driver and a Prism3 card seemed to be
2007 * generating streams of disconnected events when configuring
2008 * IBSS for WPA-None. Ignore them for now.
2009 */
2010 return;
2011 }
2012
2013 bssid = wpa_s->bssid;
2014 if (is_zero_ether_addr(bssid))
2015 bssid = wpa_s->pending_bssid;
2016
2017 if (!is_zero_ether_addr(bssid) ||
2018 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2019 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2020 " reason=%d%s",
2021 MAC2STR(bssid), reason_code,
2022 locally_generated ? " locally_generated=1" : "");
2023 }
2024}
2025
2026
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002027static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2028 int locally_generated)
2029{
2030 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2031 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2032 return 0; /* Not in 4-way handshake with PSK */
2033
2034 /*
2035 * It looks like connection was lost while trying to go through PSK
2036 * 4-way handshake. Filter out known disconnection cases that are caused
2037 * by something else than PSK mismatch to avoid confusing reports.
2038 */
2039
2040 if (locally_generated) {
2041 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2042 return 0;
2043 }
2044
2045 return 1;
2046}
2047
2048
Jouni Malinen2b89da82012-08-31 22:04:41 +03002049static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2050 u16 reason_code,
2051 int locally_generated)
2052{
2053 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002054 int authenticating;
2055 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002056 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002057#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002058 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002059#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002060 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002061
2062 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2063 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2064
2065 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2066 /*
2067 * At least Host AP driver and a Prism3 card seemed to be
2068 * generating streams of disconnected events when configuring
2069 * IBSS for WPA-None. Ignore them for now.
2070 */
2071 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2072 "IBSS/WPA-None mode");
2073 return;
2074 }
2075
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002076 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2078 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002079 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2080 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002081 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002083 if (!wpa_s->disconnected &&
2084 (!wpa_s->auto_reconnect_disabled ||
2085 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002086 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2087 "reconnect (wps=%d wpa_state=%d)",
2088 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2089 wpa_s->wpa_state);
2090 if (wpa_s->wpa_state == WPA_COMPLETED &&
2091 wpa_s->current_ssid &&
2092 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002093 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002094 disconnect_reason_recoverable(reason_code)) {
2095 /*
2096 * It looks like the AP has dropped association with
2097 * us, but could allow us to get back in. Try to
2098 * reconnect to the same BSS without full scan to save
2099 * time for some common cases.
2100 */
2101 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002102#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002103 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002104#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002105 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002106#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002107 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002108#else
2109 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2110#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002111 else
2112 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2113 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002114 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002115 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 "try to re-connect");
2117 wpa_s->reassociate = 0;
2118 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002119 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002120 }
2121 bssid = wpa_s->bssid;
2122 if (is_zero_ether_addr(bssid))
2123 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002124 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2125 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002127 if (locally_generated)
2128 wpa_s->disconnect_reason = -reason_code;
2129 else
2130 wpa_s->disconnect_reason = reason_code;
2131 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2133 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2134 wpa_s->keys_cleared = 0;
2135 wpa_clear_keys(wpa_s, wpa_s->bssid);
2136 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002137 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 wpa_supplicant_mark_disassoc(wpa_s);
2139
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002140 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002142 wpa_s->current_ssid = last_ssid;
2143 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002144
2145 if (fast_reconnect) {
2146#ifndef CONFIG_NO_SCAN_PROCESSING
2147 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2148 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2149 fast_reconnect_ssid) < 0) {
2150 /* Recover through full scan */
2151 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2152 }
2153#endif /* CONFIG_NO_SCAN_PROCESSING */
2154 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155}
2156
2157
2158#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002159void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160{
2161 struct wpa_supplicant *wpa_s = eloop_ctx;
2162
2163 if (!wpa_s->pending_mic_error_report)
2164 return;
2165
2166 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2167 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2168 wpa_s->pending_mic_error_report = 0;
2169}
2170#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2171
2172
2173static void
2174wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2175 union wpa_event_data *data)
2176{
2177 int pairwise;
2178 struct os_time t;
2179
2180 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2181 pairwise = (data && data->michael_mic_failure.unicast);
2182 os_get_time(&t);
2183 if ((wpa_s->last_michael_mic_error &&
2184 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2185 wpa_s->pending_mic_error_report) {
2186 if (wpa_s->pending_mic_error_report) {
2187 /*
2188 * Send the pending MIC error report immediately since
2189 * we are going to start countermeasures and AP better
2190 * do the same.
2191 */
2192 wpa_sm_key_request(wpa_s->wpa, 1,
2193 wpa_s->pending_mic_error_pairwise);
2194 }
2195
2196 /* Send the new MIC error report immediately since we are going
2197 * to start countermeasures and AP better do the same.
2198 */
2199 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2200
2201 /* initialize countermeasures */
2202 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002203
2204 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2205
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2207
2208 /*
2209 * Need to wait for completion of request frame. We do not get
2210 * any callback for the message completion, so just wait a
2211 * short while and hope for the best. */
2212 os_sleep(0, 10000);
2213
2214 wpa_drv_set_countermeasures(wpa_s, 1);
2215 wpa_supplicant_deauthenticate(wpa_s,
2216 WLAN_REASON_MICHAEL_MIC_FAILURE);
2217 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2218 wpa_s, NULL);
2219 eloop_register_timeout(60, 0,
2220 wpa_supplicant_stop_countermeasures,
2221 wpa_s, NULL);
2222 /* TODO: mark the AP rejected for 60 second. STA is
2223 * allowed to associate with another AP.. */
2224 } else {
2225#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2226 if (wpa_s->mic_errors_seen) {
2227 /*
2228 * Reduce the effectiveness of Michael MIC error
2229 * reports as a means for attacking against TKIP if
2230 * more than one MIC failure is noticed with the same
2231 * PTK. We delay the transmission of the reports by a
2232 * random time between 0 and 60 seconds in order to
2233 * force the attacker wait 60 seconds before getting
2234 * the information on whether a frame resulted in a MIC
2235 * failure.
2236 */
2237 u8 rval[4];
2238 int sec;
2239
2240 if (os_get_random(rval, sizeof(rval)) < 0)
2241 sec = os_random() % 60;
2242 else
2243 sec = WPA_GET_BE32(rval) % 60;
2244 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2245 "report %d seconds", sec);
2246 wpa_s->pending_mic_error_report = 1;
2247 wpa_s->pending_mic_error_pairwise = pairwise;
2248 eloop_cancel_timeout(
2249 wpa_supplicant_delayed_mic_error_report,
2250 wpa_s, NULL);
2251 eloop_register_timeout(
2252 sec, os_random() % 1000000,
2253 wpa_supplicant_delayed_mic_error_report,
2254 wpa_s, NULL);
2255 } else {
2256 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2257 }
2258#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2259 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2260#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2261 }
2262 wpa_s->last_michael_mic_error = t.sec;
2263 wpa_s->mic_errors_seen++;
2264}
2265
2266
2267#ifdef CONFIG_TERMINATE_ONLASTIF
2268static int any_interfaces(struct wpa_supplicant *head)
2269{
2270 struct wpa_supplicant *wpa_s;
2271
2272 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2273 if (!wpa_s->interface_removed)
2274 return 1;
2275 return 0;
2276}
2277#endif /* CONFIG_TERMINATE_ONLASTIF */
2278
2279
2280static void
2281wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2282 union wpa_event_data *data)
2283{
2284 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2285 return;
2286
2287 switch (data->interface_status.ievent) {
2288 case EVENT_INTERFACE_ADDED:
2289 if (!wpa_s->interface_removed)
2290 break;
2291 wpa_s->interface_removed = 0;
2292 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2293 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2294 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2295 "driver after interface was added");
2296 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002297 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 break;
2299 case EVENT_INTERFACE_REMOVED:
2300 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2301 wpa_s->interface_removed = 1;
2302 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002303 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002304 l2_packet_deinit(wpa_s->l2);
2305 wpa_s->l2 = NULL;
2306#ifdef CONFIG_IBSS_RSN
2307 ibss_rsn_deinit(wpa_s->ibss_rsn);
2308 wpa_s->ibss_rsn = NULL;
2309#endif /* CONFIG_IBSS_RSN */
2310#ifdef CONFIG_TERMINATE_ONLASTIF
2311 /* check if last interface */
2312 if (!any_interfaces(wpa_s->global->ifaces))
2313 eloop_terminate();
2314#endif /* CONFIG_TERMINATE_ONLASTIF */
2315 break;
2316 }
2317}
2318
2319
2320#ifdef CONFIG_PEERKEY
2321static void
2322wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2323 union wpa_event_data *data)
2324{
2325 if (data == NULL)
2326 return;
2327 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2328}
2329#endif /* CONFIG_PEERKEY */
2330
2331
2332#ifdef CONFIG_TDLS
2333static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2334 union wpa_event_data *data)
2335{
2336 if (data == NULL)
2337 return;
2338 switch (data->tdls.oper) {
2339 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002340 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2341 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2342 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2343 else
2344 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002345 break;
2346 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002347 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2348 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2349 data->tdls.reason_code);
2350 else
2351 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2352 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002353 break;
2354 }
2355}
2356#endif /* CONFIG_TDLS */
2357
2358
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002359#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002360static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2361 union wpa_event_data *data)
2362{
2363 if (data == NULL)
2364 return;
2365 switch (data->wnm.oper) {
2366 case WNM_OPER_SLEEP:
2367 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2368 "(action=%d, intval=%d)",
2369 data->wnm.sleep_action, data->wnm.sleep_intval);
2370 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002371 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002372 break;
2373 }
2374}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002375#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002376
2377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378#ifdef CONFIG_IEEE80211R
2379static void
2380wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2381 union wpa_event_data *data)
2382{
2383 if (data == NULL)
2384 return;
2385
2386 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2387 data->ft_ies.ies_len,
2388 data->ft_ies.ft_action,
2389 data->ft_ies.target_ap,
2390 data->ft_ies.ric_ies,
2391 data->ft_ies.ric_ies_len) < 0) {
2392 /* TODO: prevent MLME/driver from trying to associate? */
2393 }
2394}
2395#endif /* CONFIG_IEEE80211R */
2396
2397
2398#ifdef CONFIG_IBSS_RSN
2399static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2400 union wpa_event_data *data)
2401{
2402 struct wpa_ssid *ssid;
2403 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2404 return;
2405 if (data == NULL)
2406 return;
2407 ssid = wpa_s->current_ssid;
2408 if (ssid == NULL)
2409 return;
2410 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2411 return;
2412
2413 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2414}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002415
2416
2417static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2418 union wpa_event_data *data)
2419{
2420 struct wpa_ssid *ssid = wpa_s->current_ssid;
2421
2422 if (ssid == NULL)
2423 return;
2424
2425 /* check if the ssid is correctly configured as IBSS/RSN */
2426 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2427 return;
2428
2429 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2430 data->rx_mgmt.frame_len);
2431}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002432#endif /* CONFIG_IBSS_RSN */
2433
2434
2435#ifdef CONFIG_IEEE80211R
2436static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2437 size_t len)
2438{
2439 const u8 *sta_addr, *target_ap_addr;
2440 u16 status;
2441
2442 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2443 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2444 return; /* only SME case supported for now */
2445 if (len < 1 + 2 * ETH_ALEN + 2)
2446 return;
2447 if (data[0] != 2)
2448 return; /* Only FT Action Response is supported for now */
2449 sta_addr = data + 1;
2450 target_ap_addr = data + 1 + ETH_ALEN;
2451 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2452 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2453 MACSTR " TargetAP " MACSTR " status %u",
2454 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2455
2456 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2457 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2458 " in FT Action Response", MAC2STR(sta_addr));
2459 return;
2460 }
2461
2462 if (status) {
2463 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2464 "failure (status code %d)", status);
2465 /* TODO: report error to FT code(?) */
2466 return;
2467 }
2468
2469 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2470 len - (1 + 2 * ETH_ALEN + 2), 1,
2471 target_ap_addr, NULL, 0) < 0)
2472 return;
2473
2474#ifdef CONFIG_SME
2475 {
2476 struct wpa_bss *bss;
2477 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2478 if (bss)
2479 wpa_s->sme.freq = bss->freq;
2480 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2481 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2482 WLAN_AUTH_FT);
2483 }
2484#endif /* CONFIG_SME */
2485}
2486#endif /* CONFIG_IEEE80211R */
2487
2488
2489static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2490 struct unprot_deauth *e)
2491{
2492#ifdef CONFIG_IEEE80211W
2493 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2494 "dropped: " MACSTR " -> " MACSTR
2495 " (reason code %u)",
2496 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2497 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2498#endif /* CONFIG_IEEE80211W */
2499}
2500
2501
2502static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2503 struct unprot_disassoc *e)
2504{
2505#ifdef CONFIG_IEEE80211W
2506 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2507 "dropped: " MACSTR " -> " MACSTR
2508 " (reason code %u)",
2509 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2510 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2511#endif /* CONFIG_IEEE80211W */
2512}
2513
2514
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002515static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2516 u16 reason_code, int locally_generated,
2517 const u8 *ie, size_t ie_len, int deauth)
2518{
2519#ifdef CONFIG_AP
2520 if (wpa_s->ap_iface && addr) {
2521 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2522 return;
2523 }
2524
2525 if (wpa_s->ap_iface) {
2526 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2527 return;
2528 }
2529#endif /* CONFIG_AP */
2530
2531 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2532
2533 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2534 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2535 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2536 eapol_sm_failed(wpa_s->eapol)))
2537 wpas_auth_failed(wpa_s);
2538
2539#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002540 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002541 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2542 locally_generated) > 0) {
2543 /*
2544 * The interface was removed, so cannot continue
2545 * processing any additional operations after this.
2546 */
2547 return;
2548 }
2549 }
2550#endif /* CONFIG_P2P */
2551
2552 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2553 locally_generated);
2554}
2555
2556
2557static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2558 struct disassoc_info *info)
2559{
2560 u16 reason_code = 0;
2561 int locally_generated = 0;
2562 const u8 *addr = NULL;
2563 const u8 *ie = NULL;
2564 size_t ie_len = 0;
2565
2566 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2567
2568 if (info) {
2569 addr = info->addr;
2570 ie = info->ie;
2571 ie_len = info->ie_len;
2572 reason_code = info->reason_code;
2573 locally_generated = info->locally_generated;
2574 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2575 locally_generated ? " (locally generated)" : "");
2576 if (addr)
2577 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2578 MAC2STR(addr));
2579 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2580 ie, ie_len);
2581 }
2582
2583#ifdef CONFIG_AP
2584 if (wpa_s->ap_iface && info && info->addr) {
2585 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2586 return;
2587 }
2588
2589 if (wpa_s->ap_iface) {
2590 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2591 return;
2592 }
2593#endif /* CONFIG_AP */
2594
2595#ifdef CONFIG_P2P
2596 if (info) {
2597 wpas_p2p_disassoc_notif(
2598 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2599 locally_generated);
2600 }
2601#endif /* CONFIG_P2P */
2602
2603 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2604 sme_event_disassoc(wpa_s, info);
2605
2606 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2607 ie, ie_len, 0);
2608}
2609
2610
2611static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2612 struct deauth_info *info)
2613{
2614 u16 reason_code = 0;
2615 int locally_generated = 0;
2616 const u8 *addr = NULL;
2617 const u8 *ie = NULL;
2618 size_t ie_len = 0;
2619
2620 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2621
2622 if (info) {
2623 addr = info->addr;
2624 ie = info->ie;
2625 ie_len = info->ie_len;
2626 reason_code = info->reason_code;
2627 locally_generated = info->locally_generated;
2628 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2629 reason_code,
2630 locally_generated ? " (locally generated)" : "");
2631 if (addr) {
2632 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2633 MAC2STR(addr));
2634 }
2635 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2636 ie, ie_len);
2637 }
2638
2639 wpa_reset_ft_completed(wpa_s->wpa);
2640
2641 wpas_event_disconnect(wpa_s, addr, reason_code,
2642 locally_generated, ie, ie_len, 1);
2643}
2644
2645
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002646static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2647{
2648 const char *rn, *rn2;
2649 struct wpa_supplicant *ifs;
2650
2651 if (wpa_s->drv_priv == NULL)
2652 return; /* Ignore event during drv initialization */
2653
2654 free_hw_features(wpa_s);
2655 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2656 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2657
2658#ifdef CONFIG_P2P
2659 wpas_p2p_update_channel_list(wpa_s);
2660#endif /* CONFIG_P2P */
2661
2662 /*
2663 * Check other interfaces to see if they have the same radio-name. If
2664 * so, they get updated with this same hw mode info.
2665 */
2666 if (!wpa_s->driver->get_radio_name)
2667 return;
2668
2669 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2670 if (rn == NULL || rn[0] == '\0')
2671 return;
2672
2673 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2674 "sharing same radio (%s) in event_channel_list_change", rn);
2675
2676 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2677 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2678 continue;
2679
2680 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2681 if (rn2 && os_strcmp(rn, rn2) == 0) {
2682 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2683 ifs->ifname);
2684 free_hw_features(ifs);
2685 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2686 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2687 }
2688 }
2689}
2690
2691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002692void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2693 union wpa_event_data *data)
2694{
2695 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696
2697 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2698 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002699 event != EVENT_INTERFACE_STATUS &&
2700 event != EVENT_SCHED_SCAN_STOPPED) {
2701 wpa_dbg(wpa_s, MSG_DEBUG,
2702 "Ignore event %s (%d) while interface is disabled",
2703 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 return;
2705 }
2706
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002707#ifndef CONFIG_NO_STDOUT_DEBUG
2708{
2709 int level = MSG_DEBUG;
2710
Dmitry Shmidt04949592012-07-19 12:16:46 -07002711 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002712 const struct ieee80211_hdr *hdr;
2713 u16 fc;
2714 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2715 fc = le_to_host16(hdr->frame_control);
2716 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2717 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2718 level = MSG_EXCESSIVE;
2719 }
2720
2721 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2722 event_to_string(event), event);
2723}
2724#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725
2726 switch (event) {
2727 case EVENT_AUTH:
2728 sme_event_auth(wpa_s, data);
2729 break;
2730 case EVENT_ASSOC:
2731 wpa_supplicant_event_assoc(wpa_s, data);
2732 break;
2733 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002734 wpas_event_disassoc(wpa_s,
2735 data ? &data->disassoc_info : NULL);
2736 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002737 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002738 wpas_event_deauth(wpa_s,
2739 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 break;
2741 case EVENT_MICHAEL_MIC_FAILURE:
2742 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2743 break;
2744#ifndef CONFIG_NO_SCAN_PROCESSING
2745 case EVENT_SCAN_RESULTS:
2746 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002747 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2748 wpa_s->wpa_state != WPA_ASSOCIATING)
2749 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002750 break;
2751#endif /* CONFIG_NO_SCAN_PROCESSING */
2752 case EVENT_ASSOCINFO:
2753 wpa_supplicant_event_associnfo(wpa_s, data);
2754 break;
2755 case EVENT_INTERFACE_STATUS:
2756 wpa_supplicant_event_interface_status(wpa_s, data);
2757 break;
2758 case EVENT_PMKID_CANDIDATE:
2759 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2760 break;
2761#ifdef CONFIG_PEERKEY
2762 case EVENT_STKSTART:
2763 wpa_supplicant_event_stkstart(wpa_s, data);
2764 break;
2765#endif /* CONFIG_PEERKEY */
2766#ifdef CONFIG_TDLS
2767 case EVENT_TDLS:
2768 wpa_supplicant_event_tdls(wpa_s, data);
2769 break;
2770#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002771#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002772 case EVENT_WNM:
2773 wpa_supplicant_event_wnm(wpa_s, data);
2774 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002775#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776#ifdef CONFIG_IEEE80211R
2777 case EVENT_FT_RESPONSE:
2778 wpa_supplicant_event_ft_response(wpa_s, data);
2779 break;
2780#endif /* CONFIG_IEEE80211R */
2781#ifdef CONFIG_IBSS_RSN
2782 case EVENT_IBSS_RSN_START:
2783 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2784 break;
2785#endif /* CONFIG_IBSS_RSN */
2786 case EVENT_ASSOC_REJECT:
2787 if (data->assoc_reject.bssid)
2788 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2789 "bssid=" MACSTR " status_code=%u",
2790 MAC2STR(data->assoc_reject.bssid),
2791 data->assoc_reject.status_code);
2792 else
2793 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2794 "status_code=%u",
2795 data->assoc_reject.status_code);
2796 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2797 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002798 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002799#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002800 if(!wpa_s->current_ssid) {
2801 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2802 break;
2803 }
2804 /* If assoc reject is reported by the driver, then avoid
2805 * waiting for the authentication timeout. Cancel the
2806 * authentication timeout and retry the assoc.
2807 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002808 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002809 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2810 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002811
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002812 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002813
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002814 /* Clear the states */
2815 wpa_sm_notify_disassoc(wpa_s->wpa);
2816 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2817
2818 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002819 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002820 const u8 *bl_bssid = data->assoc_reject.bssid;
2821 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2822 bl_bssid = wpa_s->pending_bssid;
2823 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002824 wpa_supplicant_req_scan(wpa_s, 0, 0);
2825 } else {
2826 wpa_supplicant_req_scan(wpa_s, 1, 0);
2827 }
2828 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002829 /* If we ASSOC_REJECT's hits threshold, disable the
2830 * network
2831 */
2832 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2833 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002834 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002835 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002836 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002837 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002838#else
2839 const u8 *bssid = data->assoc_reject.bssid;
2840 if (bssid == NULL || is_zero_ether_addr(bssid))
2841 bssid = wpa_s->pending_bssid;
2842 wpas_connection_failed(wpa_s, bssid);
2843 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002844#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002845 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002846 break;
2847 case EVENT_AUTH_TIMED_OUT:
2848 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2849 sme_event_auth_timed_out(wpa_s, data);
2850 break;
2851 case EVENT_ASSOC_TIMED_OUT:
2852 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2853 sme_event_assoc_timed_out(wpa_s, data);
2854 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855 case EVENT_TX_STATUS:
2856 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2857 " type=%d stype=%d",
2858 MAC2STR(data->tx_status.dst),
2859 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002860#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002862#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002863 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2864 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002865 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866 wpa_s, data->tx_status.dst,
2867 data->tx_status.data,
2868 data->tx_status.data_len,
2869 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002870 OFFCHANNEL_SEND_ACTION_SUCCESS :
2871 OFFCHANNEL_SEND_ACTION_NO_ACK);
2872#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 break;
2874 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002875#endif /* CONFIG_AP */
2876#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002877 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2878 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2879 /*
2880 * Catch TX status events for Action frames we sent via group
2881 * interface in GO mode.
2882 */
2883 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2884 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2885 os_memcmp(wpa_s->parent->pending_action_dst,
2886 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002887 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002888 wpa_s->parent, data->tx_status.dst,
2889 data->tx_status.data,
2890 data->tx_status.data_len,
2891 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002892 OFFCHANNEL_SEND_ACTION_SUCCESS :
2893 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002894 break;
2895 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002896#endif /* CONFIG_OFFCHANNEL */
2897#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 switch (data->tx_status.type) {
2899 case WLAN_FC_TYPE_MGMT:
2900 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2901 data->tx_status.data_len,
2902 data->tx_status.stype,
2903 data->tx_status.ack);
2904 break;
2905 case WLAN_FC_TYPE_DATA:
2906 ap_tx_status(wpa_s, data->tx_status.dst,
2907 data->tx_status.data,
2908 data->tx_status.data_len,
2909 data->tx_status.ack);
2910 break;
2911 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002912#endif /* CONFIG_AP */
2913 break;
2914#ifdef CONFIG_AP
2915 case EVENT_EAPOL_TX_STATUS:
2916 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2917 data->eapol_tx_status.data,
2918 data->eapol_tx_status.data_len,
2919 data->eapol_tx_status.ack);
2920 break;
2921 case EVENT_DRIVER_CLIENT_POLL_OK:
2922 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002923 break;
2924 case EVENT_RX_FROM_UNKNOWN:
2925 if (wpa_s->ap_iface == NULL)
2926 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002927 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2928 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002929 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002930 case EVENT_CH_SWITCH:
2931 if (!data)
2932 break;
2933 if (!wpa_s->ap_iface) {
2934 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2935 "event in non-AP mode");
2936 break;
2937 }
2938
Dmitry Shmidt04949592012-07-19 12:16:46 -07002939 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2940 data->ch_switch.ht_enabled,
2941 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002942 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002943#endif /* CONFIG_AP */
2944#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002945 case EVENT_RX_MGMT: {
2946 u16 fc, stype;
2947 const struct ieee80211_mgmt *mgmt;
2948
2949 mgmt = (const struct ieee80211_mgmt *)
2950 data->rx_mgmt.frame;
2951 fc = le_to_host16(mgmt->frame_control);
2952 stype = WLAN_FC_GET_STYPE(fc);
2953
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002954#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002955 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002956#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002958 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2959 data->rx_mgmt.frame_len > 24) {
2960 const u8 *src = mgmt->sa;
2961 const u8 *ie = mgmt->u.probe_req.variable;
2962 size_t ie_len = data->rx_mgmt.frame_len -
2963 (mgmt->u.probe_req.variable -
2964 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002965 wpas_p2p_probe_req_rx(
2966 wpa_s, src, mgmt->da,
2967 mgmt->bssid, ie, ie_len,
2968 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002969 break;
2970 }
2971#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002972#ifdef CONFIG_IBSS_RSN
2973 if (stype == WLAN_FC_STYPE_AUTH &&
2974 data->rx_mgmt.frame_len >= 30) {
2975 wpa_supplicant_event_ibss_auth(wpa_s, data);
2976 break;
2977 }
2978#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002979 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2980 "management frame in non-AP mode");
2981 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002982#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002984
2985 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2986 data->rx_mgmt.frame_len > 24) {
2987 const u8 *ie = mgmt->u.probe_req.variable;
2988 size_t ie_len = data->rx_mgmt.frame_len -
2989 (mgmt->u.probe_req.variable -
2990 data->rx_mgmt.frame);
2991
2992 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2993 mgmt->bssid, ie, ie_len,
2994 data->rx_mgmt.ssi_signal);
2995 }
2996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002997 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002998#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002999 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003000 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003001#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 case EVENT_RX_ACTION:
3003 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3004 " Category=%u DataLen=%d freq=%d MHz",
3005 MAC2STR(data->rx_action.sa),
3006 data->rx_action.category, (int) data->rx_action.len,
3007 data->rx_action.freq);
3008#ifdef CONFIG_IEEE80211R
3009 if (data->rx_action.category == WLAN_ACTION_FT) {
3010 ft_rx_action(wpa_s, data->rx_action.data,
3011 data->rx_action.len);
3012 break;
3013 }
3014#endif /* CONFIG_IEEE80211R */
3015#ifdef CONFIG_IEEE80211W
3016#ifdef CONFIG_SME
3017 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3018 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3019 data->rx_action.data,
3020 data->rx_action.len);
3021 break;
3022 }
3023#endif /* CONFIG_SME */
3024#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003025#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003026 if (data->rx_action.category == WLAN_ACTION_WNM) {
3027 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3028 break;
3029 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003030#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003031#ifdef CONFIG_GAS
3032 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3033 gas_query_rx(wpa_s->gas, data->rx_action.da,
3034 data->rx_action.sa, data->rx_action.bssid,
3035 data->rx_action.data, data->rx_action.len,
3036 data->rx_action.freq) == 0)
3037 break;
3038#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003039#ifdef CONFIG_TDLS
3040 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3041 data->rx_action.len >= 4 &&
3042 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3043 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3044 "Response from " MACSTR,
3045 MAC2STR(data->rx_action.sa));
3046 break;
3047 }
3048#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003049#ifdef CONFIG_INTERWORKING
3050 if (data->rx_action.category == WLAN_ACTION_QOS &&
3051 data->rx_action.len >= 1 &&
3052 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
3053 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3054 MACSTR, MAC2STR(data->rx_action.sa));
3055 if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
3056 == 0)
3057 wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
3058 data->rx_action.len - 1);
3059 break;
3060 }
3061#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003062#ifdef CONFIG_P2P
3063 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3064 data->rx_action.sa,
3065 data->rx_action.bssid,
3066 data->rx_action.category,
3067 data->rx_action.data,
3068 data->rx_action.len, data->rx_action.freq);
3069#endif /* CONFIG_P2P */
3070 break;
3071 case EVENT_RX_PROBE_REQ:
3072 if (data->rx_probe_req.sa == NULL ||
3073 data->rx_probe_req.ie == NULL)
3074 break;
3075#ifdef CONFIG_AP
3076 if (wpa_s->ap_iface) {
3077 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3078 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003079 data->rx_probe_req.da,
3080 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003082 data->rx_probe_req.ie_len,
3083 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003084 break;
3085 }
3086#endif /* CONFIG_AP */
3087#ifdef CONFIG_P2P
3088 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003089 data->rx_probe_req.da,
3090 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003091 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003092 data->rx_probe_req.ie_len,
3093 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094#endif /* CONFIG_P2P */
3095 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003097#ifdef CONFIG_OFFCHANNEL
3098 offchannel_remain_on_channel_cb(
3099 wpa_s, data->remain_on_channel.freq,
3100 data->remain_on_channel.duration);
3101#endif /* CONFIG_OFFCHANNEL */
3102#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003103 wpas_p2p_remain_on_channel_cb(
3104 wpa_s, data->remain_on_channel.freq,
3105 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003106#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 break;
3108 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003109#ifdef CONFIG_OFFCHANNEL
3110 offchannel_cancel_remain_on_channel_cb(
3111 wpa_s, data->remain_on_channel.freq);
3112#endif /* CONFIG_OFFCHANNEL */
3113#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003114 wpas_p2p_cancel_remain_on_channel_cb(
3115 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003116#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003118#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003119 case EVENT_P2P_DEV_FOUND: {
3120 struct p2p_peer_info peer_info;
3121
3122 os_memset(&peer_info, 0, sizeof(peer_info));
3123 if (data->p2p_dev_found.dev_addr)
3124 os_memcpy(peer_info.p2p_device_addr,
3125 data->p2p_dev_found.dev_addr, ETH_ALEN);
3126 if (data->p2p_dev_found.pri_dev_type)
3127 os_memcpy(peer_info.pri_dev_type,
3128 data->p2p_dev_found.pri_dev_type,
3129 sizeof(peer_info.pri_dev_type));
3130 if (data->p2p_dev_found.dev_name)
3131 os_strlcpy(peer_info.device_name,
3132 data->p2p_dev_found.dev_name,
3133 sizeof(peer_info.device_name));
3134 peer_info.config_methods = data->p2p_dev_found.config_methods;
3135 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3136 peer_info.group_capab = data->p2p_dev_found.group_capab;
3137
3138 /*
3139 * FIX: new_device=1 is not necessarily correct. We should
3140 * maintain a P2P peer database in wpa_supplicant and update
3141 * this information based on whether the peer is truly new.
3142 */
3143 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3144 break;
3145 }
3146 case EVENT_P2P_GO_NEG_REQ_RX:
3147 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3148 data->p2p_go_neg_req_rx.dev_passwd_id);
3149 break;
3150 case EVENT_P2P_GO_NEG_COMPLETED:
3151 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3152 break;
3153 case EVENT_P2P_PROV_DISC_REQUEST:
3154 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3155 data->p2p_prov_disc_req.config_methods,
3156 data->p2p_prov_disc_req.dev_addr,
3157 data->p2p_prov_disc_req.pri_dev_type,
3158 data->p2p_prov_disc_req.dev_name,
3159 data->p2p_prov_disc_req.supp_config_methods,
3160 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003161 data->p2p_prov_disc_req.group_capab,
3162 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003163 break;
3164 case EVENT_P2P_PROV_DISC_RESPONSE:
3165 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3166 data->p2p_prov_disc_resp.config_methods);
3167 break;
3168 case EVENT_P2P_SD_REQUEST:
3169 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3170 data->p2p_sd_req.sa,
3171 data->p2p_sd_req.dialog_token,
3172 data->p2p_sd_req.update_indic,
3173 data->p2p_sd_req.tlvs,
3174 data->p2p_sd_req.tlvs_len);
3175 break;
3176 case EVENT_P2P_SD_RESPONSE:
3177 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3178 data->p2p_sd_resp.update_indic,
3179 data->p2p_sd_resp.tlvs,
3180 data->p2p_sd_resp.tlvs_len);
3181 break;
3182#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003183 case EVENT_EAPOL_RX:
3184 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3185 data->eapol_rx.data,
3186 data->eapol_rx.data_len);
3187 break;
3188 case EVENT_SIGNAL_CHANGE:
3189 bgscan_notify_signal_change(
3190 wpa_s, data->signal_change.above_threshold,
3191 data->signal_change.current_signal,
3192 data->signal_change.current_noise,
3193 data->signal_change.current_txrate);
3194 break;
3195 case EVENT_INTERFACE_ENABLED:
3196 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3197 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003198 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199#ifdef CONFIG_AP
3200 if (!wpa_s->ap_iface) {
3201 wpa_supplicant_set_state(wpa_s,
3202 WPA_DISCONNECTED);
3203 wpa_supplicant_req_scan(wpa_s, 0, 0);
3204 } else
3205 wpa_supplicant_set_state(wpa_s,
3206 WPA_COMPLETED);
3207#else /* CONFIG_AP */
3208 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3209 wpa_supplicant_req_scan(wpa_s, 0, 0);
3210#endif /* CONFIG_AP */
3211 }
3212 break;
3213 case EVENT_INTERFACE_DISABLED:
3214 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3215 wpa_supplicant_mark_disassoc(wpa_s);
3216 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3217 break;
3218 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003219 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003220 break;
3221 case EVENT_INTERFACE_UNAVAILABLE:
3222#ifdef CONFIG_P2P
3223 wpas_p2p_interface_unavailable(wpa_s);
3224#endif /* CONFIG_P2P */
3225 break;
3226 case EVENT_BEST_CHANNEL:
3227 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3228 "(%d %d %d)",
3229 data->best_chan.freq_24, data->best_chan.freq_5,
3230 data->best_chan.freq_overall);
3231 wpa_s->best_24_freq = data->best_chan.freq_24;
3232 wpa_s->best_5_freq = data->best_chan.freq_5;
3233 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3234#ifdef CONFIG_P2P
3235 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3236 data->best_chan.freq_5,
3237 data->best_chan.freq_overall);
3238#endif /* CONFIG_P2P */
3239 break;
3240 case EVENT_UNPROT_DEAUTH:
3241 wpa_supplicant_event_unprot_deauth(wpa_s,
3242 &data->unprot_deauth);
3243 break;
3244 case EVENT_UNPROT_DISASSOC:
3245 wpa_supplicant_event_unprot_disassoc(wpa_s,
3246 &data->unprot_disassoc);
3247 break;
3248 case EVENT_STATION_LOW_ACK:
3249#ifdef CONFIG_AP
3250 if (wpa_s->ap_iface && data)
3251 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3252 data->low_ack.addr);
3253#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003254#ifdef CONFIG_TDLS
3255 if (data)
3256 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3257#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003258 break;
3259 case EVENT_IBSS_PEER_LOST:
3260#ifdef CONFIG_IBSS_RSN
3261 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3262#endif /* CONFIG_IBSS_RSN */
3263 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003264 case EVENT_DRIVER_GTK_REKEY:
3265 if (os_memcmp(data->driver_gtk_rekey.bssid,
3266 wpa_s->bssid, ETH_ALEN))
3267 break;
3268 if (!wpa_s->wpa)
3269 break;
3270 wpa_sm_update_replay_ctr(wpa_s->wpa,
3271 data->driver_gtk_rekey.replay_ctr);
3272 break;
3273 case EVENT_SCHED_SCAN_STOPPED:
3274 wpa_s->sched_scanning = 0;
3275 wpa_supplicant_notify_scanning(wpa_s, 0);
3276
3277 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3278 break;
3279
3280 /*
3281 * If we timed out, start a new sched scan to continue
3282 * searching for more SSIDs.
3283 */
3284 if (wpa_s->sched_scan_timed_out)
3285 wpa_supplicant_req_sched_scan(wpa_s);
3286 break;
3287 case EVENT_WPS_BUTTON_PUSHED:
3288#ifdef CONFIG_WPS
3289 wpas_wps_start_pbc(wpa_s, NULL, 0);
3290#endif /* CONFIG_WPS */
3291 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003292 case EVENT_CONNECT_FAILED_REASON:
3293#ifdef CONFIG_AP
3294 if (!wpa_s->ap_iface || !data)
3295 break;
3296 hostapd_event_connect_failed_reason(
3297 wpa_s->ap_iface->bss[0],
3298 data->connect_failed_reason.addr,
3299 data->connect_failed_reason.code);
3300#endif /* CONFIG_AP */
3301 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003302 default:
3303 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3304 break;
3305 }
3306}