blob: daabecbaa4fd6d014cb5431ab1e75a1ed4269dc6 [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 Shmidt54605472013-11-08 11:10:19 -0800872 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
873 struct wpabuf *p2p_ie;
874 u8 dev_addr[ETH_ALEN];
875
876 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
877 if (ie == NULL) {
878 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
879 continue;
880 }
881 p2p_ie = wpa_bss_get_vendor_ie_multi(
882 bss, P2P_IE_VENDOR_TYPE);
883 if (p2p_ie == NULL) {
884 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
885 continue;
886 }
887
888 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
889 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
890 ETH_ALEN) != 0) {
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
892 wpabuf_free(p2p_ie);
893 continue;
894 }
895 wpabuf_free(p2p_ie);
896 }
897
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 /*
899 * TODO: skip the AP if its P2P IE has Group Formation
900 * bit set in the P2P Group Capability Bitmap and we
901 * are not in Group Formation with that device.
902 */
903#endif /* CONFIG_P2P */
904
905 /* Matching configuration found */
906 return ssid;
907 }
908
909 /* No matching configuration found */
910 return NULL;
911}
912
913
914static struct wpa_bss *
915wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916 struct wpa_ssid *group,
917 struct wpa_ssid **selected_ssid)
918{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700919 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700920
921 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
922 group->priority);
923
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700924 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
925 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
927 if (!*selected_ssid)
928 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700929 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
930 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700931 MAC2STR(bss->bssid),
932 wpa_ssid_txt(bss->ssid, bss->ssid_len));
933 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934 }
935
936 return NULL;
937}
938
939
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700940struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
941 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700942{
943 struct wpa_bss *selected = NULL;
944 int prio;
945
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700946 if (wpa_s->last_scan_res == NULL ||
947 wpa_s->last_scan_res_used == 0)
948 return NULL; /* no scan results from last update */
949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 while (selected == NULL) {
951 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
952 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700953 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 selected_ssid);
955 if (selected)
956 break;
957 }
958
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800959 if (selected == NULL && wpa_s->blacklist &&
960 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
962 "blacklist and try again");
963 wpa_blacklist_clear(wpa_s);
964 wpa_s->blacklist_cleared++;
965 } else if (selected == NULL)
966 break;
967 }
968
969 return selected;
970}
971
972
973static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
974 int timeout_sec, int timeout_usec)
975{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700976 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 /*
978 * No networks are enabled; short-circuit request so
979 * we don't wait timeout seconds before transitioning
980 * to INACTIVE state.
981 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700982 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
983 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700985#ifdef CONFIG_P2P
986 wpa_s->sta_scan_pending = 0;
987#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 return;
989 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800990
991 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
993}
994
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700996int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997 struct wpa_bss *selected,
998 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999{
1000 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1001 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1002 "PBC session overlap");
1003#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001004 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001005 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006#endif /* CONFIG_P2P */
1007
1008#ifdef CONFIG_WPS
1009 wpas_wps_cancel(wpa_s);
1010#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001011 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 }
1013
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001014 wpa_msg(wpa_s, MSG_DEBUG,
1015 "Considering connect request: reassociate: %d selected: "
1016 MACSTR " bssid: " MACSTR " pending: " MACSTR
1017 " wpa_state: %s ssid=%p current_ssid=%p",
1018 wpa_s->reassociate, MAC2STR(selected->bssid),
1019 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1020 wpa_supplicant_state_txt(wpa_s->wpa_state),
1021 ssid, wpa_s->current_ssid);
1022
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023 /*
1024 * Do not trigger new association unless the BSSID has changed or if
1025 * reassociation is requested. If we are in process of associating with
1026 * the selected BSSID, do not trigger new attempt.
1027 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001028 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1030 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1031 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001032 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1033 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1034 0) ||
1035 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1036 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1038 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001039 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001041 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1042 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 wpa_supplicant_associate(wpa_s, selected, ssid);
1044 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001045 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1046 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001048
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001049 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050}
1051
1052
1053static struct wpa_ssid *
1054wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1055{
1056 int prio;
1057 struct wpa_ssid *ssid;
1058
1059 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1060 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1061 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001062 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063 continue;
1064 if (ssid->mode == IEEE80211_MODE_IBSS ||
1065 ssid->mode == IEEE80211_MODE_AP)
1066 return ssid;
1067 }
1068 }
1069 return NULL;
1070}
1071
1072
1073/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1074 * on BSS added and BSS changed events */
1075static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001076 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001078 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079
1080 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1081 return;
1082
Jouni Malinen87fd2792011-05-16 18:35:42 +03001083 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085
Jouni Malinen87fd2792011-05-16 18:35:42 +03001086 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 if (ssid == NULL)
1088 continue;
1089
Jouni Malinen87fd2792011-05-16 18:35:42 +03001090 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 if (rsn == NULL)
1092 continue;
1093
Jouni Malinen87fd2792011-05-16 18:35:42 +03001094 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095 }
1096
1097}
1098
1099
1100static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1101 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001102 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001104 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 int min_diff;
1106
1107 if (wpa_s->reassociate)
1108 return 1; /* explicit request to reassociate */
1109 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1110 return 1; /* we are not associated; continue */
1111 if (wpa_s->current_ssid == NULL)
1112 return 1; /* unknown current SSID */
1113 if (wpa_s->current_ssid != ssid)
1114 return 1; /* different network block */
1115
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 if (wpas_driver_bss_selection(wpa_s))
1117 return 0; /* Driver-based roaming */
1118
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001119 if (wpa_s->current_ssid->ssid)
1120 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1121 wpa_s->current_ssid->ssid,
1122 wpa_s->current_ssid->ssid_len);
1123 if (!current_bss)
1124 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125
1126 if (!current_bss)
1127 return 1; /* current BSS not seen in scan results */
1128
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001129 if (current_bss == selected)
1130 return 0;
1131
1132 if (selected->last_update_idx > current_bss->last_update_idx)
1133 return 1; /* current BSS not seen in the last scan */
1134
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001135#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1137 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1138 MAC2STR(current_bss->bssid), current_bss->level);
1139 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1140 MAC2STR(selected->bssid), selected->level);
1141
1142 if (wpa_s->current_ssid->bssid_set &&
1143 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1144 0) {
1145 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1146 "has preferred BSSID");
1147 return 1;
1148 }
1149
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001150 if (current_bss->level < 0 && current_bss->level > selected->level) {
1151 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1152 "signal level");
1153 return 0;
1154 }
1155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 min_diff = 2;
1157 if (current_bss->level < 0) {
1158 if (current_bss->level < -85)
1159 min_diff = 1;
1160 else if (current_bss->level < -80)
1161 min_diff = 2;
1162 else if (current_bss->level < -75)
1163 min_diff = 3;
1164 else if (current_bss->level < -70)
1165 min_diff = 4;
1166 else
1167 min_diff = 5;
1168 }
1169 if (abs(current_bss->level - selected->level) < min_diff) {
1170 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1171 "in signal level");
1172 return 0;
1173 }
1174
1175 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001176#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001177 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001178#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001179}
1180
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001181
Jouni Malinen89ca7022012-09-14 13:03:12 -07001182/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001183 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001184static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001185 union wpa_event_data *data,
1186 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001188 struct wpa_scan_results *scan_res;
1189 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001190#ifndef CONFIG_NO_RANDOM_POOL
1191 size_t i, num;
1192#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193
1194#ifdef CONFIG_AP
1195 if (wpa_s->ap_iface)
1196 ap = 1;
1197#endif /* CONFIG_AP */
1198
1199 wpa_supplicant_notify_scanning(wpa_s, 0);
1200
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001201#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001202 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001203 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001204 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1205 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001206 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001207 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1208 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1209 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001210 wpa_s->sta_scan_pending = 1;
1211 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001212 return -1;
1213 }
1214 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001215 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001216#endif /* CONFIG_P2P */
1217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1219 data ? &data->scan_info :
1220 NULL, 1);
1221 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001222 if (wpa_s->conf->ap_scan == 2 || ap ||
1223 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001225 if (!own_request)
1226 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1228 "scanning again");
1229 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1230 return -1;
1231 }
1232
1233#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 num = scan_res->num;
1235 if (num > 10)
1236 num = 10;
1237 for (i = 0; i < num; i++) {
1238 u8 buf[5];
1239 struct wpa_scan_res *res = scan_res->res[i];
1240 buf[0] = res->bssid[5];
1241 buf[1] = res->qual & 0xff;
1242 buf[2] = res->noise & 0xff;
1243 buf[3] = res->level & 0xff;
1244 buf[4] = res->tsf & 0xff;
1245 random_add_randomness(buf, sizeof(buf));
1246 }
1247#endif /* CONFIG_NO_RANDOM_POOL */
1248
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001249 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1251 struct wpa_scan_results *scan_res);
1252
1253 scan_res_handler = wpa_s->scan_res_handler;
1254 wpa_s->scan_res_handler = NULL;
1255 scan_res_handler(wpa_s, scan_res);
1256
1257 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001258 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259 }
1260
1261 if (ap) {
1262 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1263#ifdef CONFIG_AP
1264 if (wpa_s->ap_iface->scan_cb)
1265 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1266#endif /* CONFIG_AP */
1267 wpa_scan_results_free(scan_res);
1268 return 0;
1269 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001270
Dmitry Shmidt04949592012-07-19 12:16:46 -07001271 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1272 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1273 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274
1275 wpas_notify_scan_done(wpa_s, 1);
1276
Dmitry Shmidt04949592012-07-19 12:16:46 -07001277 if (sme_proc_obss_scan(wpa_s) > 0) {
1278 wpa_scan_results_free(scan_res);
1279 return 0;
1280 }
1281
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001282 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1283 wpa_scan_results_free(scan_res);
1284 return 0;
1285 }
1286
Dmitry Shmidt04949592012-07-19 12:16:46 -07001287 if (autoscan_notify_scan(wpa_s, scan_res)) {
1288 wpa_scan_results_free(scan_res);
1289 return 0;
1290 }
1291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292 if (wpa_s->disconnected) {
1293 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1294 wpa_scan_results_free(scan_res);
1295 return 0;
1296 }
1297
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001298 if (!wpas_driver_bss_selection(wpa_s) &&
1299 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 wpa_scan_results_free(scan_res);
1301 return 0;
1302 }
1303
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001304 wpas_wps_update_ap_info(wpa_s, scan_res);
1305
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001306 wpa_scan_results_free(scan_res);
1307
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001308 return wpas_select_network_from_last_scan(wpa_s, 1);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001309}
1310
1311
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001312static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1313 int new_scan)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001314{
1315 struct wpa_bss *selected;
1316 struct wpa_ssid *ssid = NULL;
1317
1318 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319
1320 if (selected) {
1321 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001322 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001323 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001324 if (new_scan)
1325 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001327 }
1328
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001329 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001330 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001331 return -1;
1332 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001333 if (new_scan)
1334 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001335 /*
1336 * Do not notify other virtual radios of scan results since we do not
1337 * want them to start other associations at the same time.
1338 */
1339 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001340 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001341 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1342 ssid = wpa_supplicant_pick_new_network(wpa_s);
1343 if (ssid) {
1344 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1345 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001346 if (new_scan)
1347 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348 } else {
1349 int timeout_sec = wpa_s->scan_interval;
1350 int timeout_usec = 0;
1351#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001352 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1353 return 0;
1354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001355 if (wpa_s->p2p_in_provisioning) {
1356 /*
1357 * Use shorter wait during P2P Provisioning
1358 * state to speed up group formation.
1359 */
1360 timeout_sec = 0;
1361 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001362 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1363 timeout_usec);
1364 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365 }
1366#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001367#ifdef CONFIG_INTERWORKING
1368 if (wpa_s->conf->auto_interworking &&
1369 wpa_s->conf->interworking &&
1370 wpa_s->conf->cred) {
1371 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1372 "start ANQP fetch since no matching "
1373 "networks found");
1374 wpa_s->network_select = 1;
1375 wpa_s->auto_network_select = 1;
1376 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001377 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001378 }
1379#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001380 if (wpa_supplicant_req_sched_scan(wpa_s))
1381 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1382 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001383 }
1384 }
1385 return 0;
1386}
1387
1388
1389static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1390 union wpa_event_data *data)
1391{
1392 const char *rn, *rn2;
1393 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001394
1395 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001396 /*
1397 * If no scan results could be fetched, then no need to
1398 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001399 * this scan. Similarly, if scan results started a new operation on this
1400 * interface, do not notify other interfaces to avoid concurrent
1401 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001402 */
1403 return;
1404 }
1405
1406 /*
1407 * Check other interfaces to see if they have the same radio-name. If
1408 * so, they get updated with this same scan info.
1409 */
1410 if (!wpa_s->driver->get_radio_name)
1411 return;
1412
1413 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1414 if (rn == NULL || rn[0] == '\0')
1415 return;
1416
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1418 "sharing same radio (%s) in event_scan_results", rn);
1419
1420 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1421 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1422 continue;
1423
1424 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1425 if (rn2 && os_strcmp(rn, rn2) == 0) {
1426 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1427 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001428 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 }
1430 }
1431}
1432
1433#endif /* CONFIG_NO_SCAN_PROCESSING */
1434
1435
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001436int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1437{
1438#ifdef CONFIG_NO_SCAN_PROCESSING
1439 return -1;
1440#else /* CONFIG_NO_SCAN_PROCESSING */
1441 struct os_time now;
1442
1443 if (wpa_s->last_scan_res_used <= 0)
1444 return -1;
1445
1446 os_get_time(&now);
1447 if (now.sec - wpa_s->last_scan.sec > 5) {
1448 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1449 return -1;
1450 }
1451
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001452 return wpas_select_network_from_last_scan(wpa_s, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001453#endif /* CONFIG_NO_SCAN_PROCESSING */
1454}
1455
Dmitry Shmidt04949592012-07-19 12:16:46 -07001456#ifdef CONFIG_WNM
1457
1458static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1459{
1460 struct wpa_supplicant *wpa_s = eloop_ctx;
1461
1462 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1463 return;
1464
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001465 if (!wpa_s->no_keep_alive) {
1466 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1467 MAC2STR(wpa_s->bssid));
1468 /* TODO: could skip this if normal data traffic has been sent */
1469 /* TODO: Consider using some more appropriate data frame for
1470 * this */
1471 if (wpa_s->l2)
1472 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1473 (u8 *) "", 0);
1474 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001475
1476#ifdef CONFIG_SME
1477 if (wpa_s->sme.bss_max_idle_period) {
1478 unsigned int msec;
1479 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1480 if (msec > 100)
1481 msec -= 100;
1482 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1483 wnm_bss_keep_alive, wpa_s, NULL);
1484 }
1485#endif /* CONFIG_SME */
1486}
1487
1488
1489static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1490 const u8 *ies, size_t ies_len)
1491{
1492 struct ieee802_11_elems elems;
1493
1494 if (ies == NULL)
1495 return;
1496
1497 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1498 return;
1499
1500#ifdef CONFIG_SME
1501 if (elems.bss_max_idle_period) {
1502 unsigned int msec;
1503 wpa_s->sme.bss_max_idle_period =
1504 WPA_GET_LE16(elems.bss_max_idle_period);
1505 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1506 "TU)%s", wpa_s->sme.bss_max_idle_period,
1507 (elems.bss_max_idle_period[2] & 0x01) ?
1508 " (protected keep-live required)" : "");
1509 if (wpa_s->sme.bss_max_idle_period == 0)
1510 wpa_s->sme.bss_max_idle_period = 1;
1511 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1512 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1513 /* msec times 1000 */
1514 msec = wpa_s->sme.bss_max_idle_period * 1024;
1515 if (msec > 100)
1516 msec -= 100;
1517 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1518 wnm_bss_keep_alive, wpa_s,
1519 NULL);
1520 }
1521 }
1522#endif /* CONFIG_SME */
1523}
1524
1525#endif /* CONFIG_WNM */
1526
1527
1528void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1529{
1530#ifdef CONFIG_WNM
1531 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1532#endif /* CONFIG_WNM */
1533}
1534
1535
Dmitry Shmidt051af732013-10-22 13:52:46 -07001536#ifdef CONFIG_INTERWORKING
1537
1538static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1539 size_t len)
1540{
1541 int res;
1542
1543 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1544 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1545 if (res) {
1546 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1547 }
1548
1549 return res;
1550}
1551
1552
1553static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1554 const u8 *ies, size_t ies_len)
1555{
1556 struct ieee802_11_elems elems;
1557
1558 if (ies == NULL)
1559 return;
1560
1561 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1562 return;
1563
1564 if (elems.qos_map_set) {
1565 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1566 elems.qos_map_set_len);
1567 }
1568}
1569
1570#endif /* CONFIG_INTERWORKING */
1571
1572
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001573static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1574 union wpa_event_data *data)
1575{
1576 int l, len, found = 0, wpa_found, rsn_found;
1577 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001578#ifdef CONFIG_IEEE80211R
1579 u8 bssid[ETH_ALEN];
1580#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001581
1582 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1583 if (data->assoc_info.req_ies)
1584 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1585 data->assoc_info.req_ies_len);
1586 if (data->assoc_info.resp_ies) {
1587 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1588 data->assoc_info.resp_ies_len);
1589#ifdef CONFIG_TDLS
1590 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1591 data->assoc_info.resp_ies_len);
1592#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593#ifdef CONFIG_WNM
1594 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1595 data->assoc_info.resp_ies_len);
1596#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001597#ifdef CONFIG_INTERWORKING
1598 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1599 data->assoc_info.resp_ies_len);
1600#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 }
1602 if (data->assoc_info.beacon_ies)
1603 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1604 data->assoc_info.beacon_ies,
1605 data->assoc_info.beacon_ies_len);
1606 if (data->assoc_info.freq)
1607 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1608 data->assoc_info.freq);
1609
1610 p = data->assoc_info.req_ies;
1611 l = data->assoc_info.req_ies_len;
1612
1613 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1614 while (p && l >= 2) {
1615 len = p[1] + 2;
1616 if (len > l) {
1617 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1618 p, l);
1619 break;
1620 }
1621 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1622 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1623 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1624 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1625 break;
1626 found = 1;
1627 wpa_find_assoc_pmkid(wpa_s);
1628 break;
1629 }
1630 l -= len;
1631 p += len;
1632 }
1633 if (!found && data->assoc_info.req_ies)
1634 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1635
1636#ifdef CONFIG_IEEE80211R
1637#ifdef CONFIG_SME
1638 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1640 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1641 data->assoc_info.resp_ies,
1642 data->assoc_info.resp_ies_len,
1643 bssid) < 0) {
1644 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1645 "Reassociation Response failed");
1646 wpa_supplicant_deauthenticate(
1647 wpa_s, WLAN_REASON_INVALID_IE);
1648 return -1;
1649 }
1650 }
1651
1652 p = data->assoc_info.resp_ies;
1653 l = data->assoc_info.resp_ies_len;
1654
1655#ifdef CONFIG_WPS_STRICT
1656 if (p && wpa_s->current_ssid &&
1657 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1658 struct wpabuf *wps;
1659 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1660 if (wps == NULL) {
1661 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1662 "include WPS IE in (Re)Association Response");
1663 return -1;
1664 }
1665
1666 if (wps_validate_assoc_resp(wps) < 0) {
1667 wpabuf_free(wps);
1668 wpa_supplicant_deauthenticate(
1669 wpa_s, WLAN_REASON_INVALID_IE);
1670 return -1;
1671 }
1672 wpabuf_free(wps);
1673 }
1674#endif /* CONFIG_WPS_STRICT */
1675
1676 /* Go through the IEs and make a copy of the MDIE, if present. */
1677 while (p && l >= 2) {
1678 len = p[1] + 2;
1679 if (len > l) {
1680 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1681 p, l);
1682 break;
1683 }
1684 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1685 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1686 wpa_s->sme.ft_used = 1;
1687 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1688 MOBILITY_DOMAIN_ID_LEN);
1689 break;
1690 }
1691 l -= len;
1692 p += len;
1693 }
1694#endif /* CONFIG_SME */
1695
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001696 /* Process FT when SME is in the driver */
1697 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1698 wpa_ft_is_completed(wpa_s->wpa)) {
1699 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1700 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1701 data->assoc_info.resp_ies,
1702 data->assoc_info.resp_ies_len,
1703 bssid) < 0) {
1704 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1705 "Reassociation Response failed");
1706 wpa_supplicant_deauthenticate(
1707 wpa_s, WLAN_REASON_INVALID_IE);
1708 return -1;
1709 }
1710 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1711 }
1712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1714 data->assoc_info.resp_ies_len);
1715#endif /* CONFIG_IEEE80211R */
1716
1717 /* WPA/RSN IE from Beacon/ProbeResp */
1718 p = data->assoc_info.beacon_ies;
1719 l = data->assoc_info.beacon_ies_len;
1720
1721 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1722 */
1723 wpa_found = rsn_found = 0;
1724 while (p && l >= 2) {
1725 len = p[1] + 2;
1726 if (len > l) {
1727 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1728 p, l);
1729 break;
1730 }
1731 if (!wpa_found &&
1732 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1733 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1734 wpa_found = 1;
1735 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1736 }
1737
1738 if (!rsn_found &&
1739 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1740 rsn_found = 1;
1741 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1742 }
1743
1744 l -= len;
1745 p += len;
1746 }
1747
1748 if (!wpa_found && data->assoc_info.beacon_ies)
1749 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1750 if (!rsn_found && data->assoc_info.beacon_ies)
1751 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1752 if (wpa_found || rsn_found)
1753 wpa_s->ap_ies_from_associnfo = 1;
1754
Jouni Malinen87fd2792011-05-16 18:35:42 +03001755 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1756 wpa_s->assoc_freq != data->assoc_info.freq) {
1757 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1758 "%u to %u MHz",
1759 wpa_s->assoc_freq, data->assoc_info.freq);
1760 wpa_supplicant_update_scan_results(wpa_s);
1761 }
1762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 wpa_s->assoc_freq = data->assoc_info.freq;
1764
1765 return 0;
1766}
1767
1768
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001769static struct wpa_bss * wpa_supplicant_get_new_bss(
1770 struct wpa_supplicant *wpa_s, const u8 *bssid)
1771{
1772 struct wpa_bss *bss = NULL;
1773 struct wpa_ssid *ssid = wpa_s->current_ssid;
1774
1775 if (ssid->ssid_len > 0)
1776 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1777 if (!bss)
1778 bss = wpa_bss_get_bssid(wpa_s, bssid);
1779
1780 return bss;
1781}
1782
1783
1784static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1785{
1786 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1787
1788 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1789 return -1;
1790
1791 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1792 return 0;
1793
1794 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1795 WPA_IE_VENDOR_TYPE);
1796 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1797
1798 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1799 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1800 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1801 bss_rsn ? 2 + bss_rsn[1] : 0))
1802 return -1;
1803
1804 return 0;
1805}
1806
1807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1809 union wpa_event_data *data)
1810{
1811 u8 bssid[ETH_ALEN];
1812 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001813
1814#ifdef CONFIG_AP
1815 if (wpa_s->ap_iface) {
1816 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1817 data->assoc_info.addr,
1818 data->assoc_info.req_ies,
1819 data->assoc_info.req_ies_len,
1820 data->assoc_info.reassoc);
1821 return;
1822 }
1823#endif /* CONFIG_AP */
1824
1825 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1826 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1827 return;
1828
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001829 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1830 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001831 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001832 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1833 return;
1834 }
1835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001837 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1839 MACSTR, MAC2STR(bssid));
1840 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1842 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001843 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844
1845 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1846 wpa_clear_keys(wpa_s, bssid);
1847 }
1848 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001849 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1851 return;
1852 }
1853 if (wpa_s->current_ssid) {
1854 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001855
1856 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1857 if (!bss) {
1858 wpa_supplicant_update_scan_results(wpa_s);
1859
1860 /* Get the BSS from the new scan results */
1861 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1862 }
1863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001864 if (bss)
1865 wpa_s->current_bss = bss;
1866 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001867
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001868#ifdef ANDROID
1869 if (wpa_s->conf->ap_scan == 1) {
1870#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001871 if (wpa_s->conf->ap_scan == 1 &&
1872 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001873#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001874 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1875 wpa_msg(wpa_s, MSG_WARNING,
1876 "WPA/RSN IEs not updated");
1877 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 }
1879
1880#ifdef CONFIG_SME
1881 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1882 wpa_s->sme.prev_bssid_set = 1;
1883#endif /* CONFIG_SME */
1884
1885 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1886 if (wpa_s->current_ssid) {
1887 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1888 * initialized before association, but for other modes,
1889 * initialize PC/SC here, if the current configuration needs
1890 * smartcard or SIM/USIM. */
1891 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1892 }
1893 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1894 if (wpa_s->l2)
1895 l2_packet_notify_auth_start(wpa_s->l2);
1896
1897 /*
1898 * Set portEnabled first to FALSE in order to get EAP state machine out
1899 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1900 * state machine may transit to AUTHENTICATING state based on obsolete
1901 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1902 * AUTHENTICATED without ever giving chance to EAP state machine to
1903 * reset the state.
1904 */
1905 if (!ft_completed) {
1906 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1907 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1908 }
1909 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1910 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1911 /* 802.1X::portControl = Auto */
1912 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1913 wpa_s->eapol_received = 0;
1914 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1915 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1916 (wpa_s->current_ssid &&
1917 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001918 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1919 (wpa_s->drv_flags &
1920 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1921 /*
1922 * Set the key after having received joined-IBSS event
1923 * from the driver.
1924 */
1925 wpa_supplicant_set_wpa_none_key(wpa_s,
1926 wpa_s->current_ssid);
1927 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001928 wpa_supplicant_cancel_auth_timeout(wpa_s);
1929 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1930 } else if (!ft_completed) {
1931 /* Timeout for receiving the first EAPOL packet */
1932 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1933 }
1934 wpa_supplicant_cancel_scan(wpa_s);
1935
1936 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1937 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1938 /*
1939 * We are done; the driver will take care of RSN 4-way
1940 * handshake.
1941 */
1942 wpa_supplicant_cancel_auth_timeout(wpa_s);
1943 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1944 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1945 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1946 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1947 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1948 /*
1949 * The driver will take care of RSN 4-way handshake, so we need
1950 * to allow EAPOL supplicant to complete its work without
1951 * waiting for WPA supplicant.
1952 */
1953 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1954 } else if (ft_completed) {
1955 /*
1956 * FT protocol completed - make sure EAPOL state machine ends
1957 * up in authenticated.
1958 */
1959 wpa_supplicant_cancel_auth_timeout(wpa_s);
1960 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1961 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1962 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1963 }
1964
Jouni Malinena05074c2012-12-21 21:35:35 +02001965 wpa_s->last_eapol_matches_bssid = 0;
1966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001967 if (wpa_s->pending_eapol_rx) {
1968 struct os_time now, age;
1969 os_get_time(&now);
1970 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1971 if (age.sec == 0 && age.usec < 100000 &&
1972 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1973 0) {
1974 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1975 "frame that was received just before "
1976 "association notification");
1977 wpa_supplicant_rx_eapol(
1978 wpa_s, wpa_s->pending_eapol_rx_src,
1979 wpabuf_head(wpa_s->pending_eapol_rx),
1980 wpabuf_len(wpa_s->pending_eapol_rx));
1981 }
1982 wpabuf_free(wpa_s->pending_eapol_rx);
1983 wpa_s->pending_eapol_rx = NULL;
1984 }
1985
1986 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1987 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001988 wpa_s->current_ssid &&
1989 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990 /* Set static WEP keys again */
1991 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1992 }
1993
1994#ifdef CONFIG_IBSS_RSN
1995 if (wpa_s->current_ssid &&
1996 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1997 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1998 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1999 wpa_s->ibss_rsn == NULL) {
2000 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2001 if (!wpa_s->ibss_rsn) {
2002 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2003 wpa_supplicant_deauthenticate(
2004 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2005 return;
2006 }
2007
2008 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2009 }
2010#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002011
2012 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002013}
2014
2015
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002016static int disconnect_reason_recoverable(u16 reason_code)
2017{
2018 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2019 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2020 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2021}
2022
2023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002024static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002025 u16 reason_code,
2026 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002027{
2028 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002029
2030 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2031 /*
2032 * At least Host AP driver and a Prism3 card seemed to be
2033 * generating streams of disconnected events when configuring
2034 * IBSS for WPA-None. Ignore them for now.
2035 */
2036 return;
2037 }
2038
2039 bssid = wpa_s->bssid;
2040 if (is_zero_ether_addr(bssid))
2041 bssid = wpa_s->pending_bssid;
2042
2043 if (!is_zero_ether_addr(bssid) ||
2044 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2045 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2046 " reason=%d%s",
2047 MAC2STR(bssid), reason_code,
2048 locally_generated ? " locally_generated=1" : "");
2049 }
2050}
2051
2052
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002053static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2054 int locally_generated)
2055{
2056 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2057 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2058 return 0; /* Not in 4-way handshake with PSK */
2059
2060 /*
2061 * It looks like connection was lost while trying to go through PSK
2062 * 4-way handshake. Filter out known disconnection cases that are caused
2063 * by something else than PSK mismatch to avoid confusing reports.
2064 */
2065
2066 if (locally_generated) {
2067 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2068 return 0;
2069 }
2070
2071 return 1;
2072}
2073
2074
Jouni Malinen2b89da82012-08-31 22:04:41 +03002075static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2076 u16 reason_code,
2077 int locally_generated)
2078{
2079 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080 int authenticating;
2081 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002082 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002083#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002084 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002085#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002086 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087
2088 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2089 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2090
2091 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2092 /*
2093 * At least Host AP driver and a Prism3 card seemed to be
2094 * generating streams of disconnected events when configuring
2095 * IBSS for WPA-None. Ignore them for now.
2096 */
2097 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2098 "IBSS/WPA-None mode");
2099 return;
2100 }
2101
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002102 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2104 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002105 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2106 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002107 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002108 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002109 if (!wpa_s->disconnected &&
2110 (!wpa_s->auto_reconnect_disabled ||
2111 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002112 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2113 "reconnect (wps=%d wpa_state=%d)",
2114 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2115 wpa_s->wpa_state);
2116 if (wpa_s->wpa_state == WPA_COMPLETED &&
2117 wpa_s->current_ssid &&
2118 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002119 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002120 disconnect_reason_recoverable(reason_code)) {
2121 /*
2122 * It looks like the AP has dropped association with
2123 * us, but could allow us to get back in. Try to
2124 * reconnect to the same BSS without full scan to save
2125 * time for some common cases.
2126 */
2127 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002128#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002129 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002130#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002131 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002132#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002133 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002134#else
2135 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2136#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002137 else
2138 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2139 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002141 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002142 "try to re-connect");
2143 wpa_s->reassociate = 0;
2144 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002145 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002146 }
2147 bssid = wpa_s->bssid;
2148 if (is_zero_ether_addr(bssid))
2149 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002150 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2151 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002153 if (locally_generated)
2154 wpa_s->disconnect_reason = -reason_code;
2155 else
2156 wpa_s->disconnect_reason = reason_code;
2157 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2159 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2160 wpa_s->keys_cleared = 0;
2161 wpa_clear_keys(wpa_s, wpa_s->bssid);
2162 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002163 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 wpa_supplicant_mark_disassoc(wpa_s);
2165
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002166 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002168 wpa_s->current_ssid = last_ssid;
2169 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002170
2171 if (fast_reconnect) {
2172#ifndef CONFIG_NO_SCAN_PROCESSING
2173 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2174 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2175 fast_reconnect_ssid) < 0) {
2176 /* Recover through full scan */
2177 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2178 }
2179#endif /* CONFIG_NO_SCAN_PROCESSING */
2180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181}
2182
2183
2184#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002185void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186{
2187 struct wpa_supplicant *wpa_s = eloop_ctx;
2188
2189 if (!wpa_s->pending_mic_error_report)
2190 return;
2191
2192 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2193 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2194 wpa_s->pending_mic_error_report = 0;
2195}
2196#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2197
2198
2199static void
2200wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2201 union wpa_event_data *data)
2202{
2203 int pairwise;
2204 struct os_time t;
2205
2206 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2207 pairwise = (data && data->michael_mic_failure.unicast);
2208 os_get_time(&t);
2209 if ((wpa_s->last_michael_mic_error &&
2210 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2211 wpa_s->pending_mic_error_report) {
2212 if (wpa_s->pending_mic_error_report) {
2213 /*
2214 * Send the pending MIC error report immediately since
2215 * we are going to start countermeasures and AP better
2216 * do the same.
2217 */
2218 wpa_sm_key_request(wpa_s->wpa, 1,
2219 wpa_s->pending_mic_error_pairwise);
2220 }
2221
2222 /* Send the new MIC error report immediately since we are going
2223 * to start countermeasures and AP better do the same.
2224 */
2225 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2226
2227 /* initialize countermeasures */
2228 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002229
2230 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2231
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002232 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2233
2234 /*
2235 * Need to wait for completion of request frame. We do not get
2236 * any callback for the message completion, so just wait a
2237 * short while and hope for the best. */
2238 os_sleep(0, 10000);
2239
2240 wpa_drv_set_countermeasures(wpa_s, 1);
2241 wpa_supplicant_deauthenticate(wpa_s,
2242 WLAN_REASON_MICHAEL_MIC_FAILURE);
2243 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2244 wpa_s, NULL);
2245 eloop_register_timeout(60, 0,
2246 wpa_supplicant_stop_countermeasures,
2247 wpa_s, NULL);
2248 /* TODO: mark the AP rejected for 60 second. STA is
2249 * allowed to associate with another AP.. */
2250 } else {
2251#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2252 if (wpa_s->mic_errors_seen) {
2253 /*
2254 * Reduce the effectiveness of Michael MIC error
2255 * reports as a means for attacking against TKIP if
2256 * more than one MIC failure is noticed with the same
2257 * PTK. We delay the transmission of the reports by a
2258 * random time between 0 and 60 seconds in order to
2259 * force the attacker wait 60 seconds before getting
2260 * the information on whether a frame resulted in a MIC
2261 * failure.
2262 */
2263 u8 rval[4];
2264 int sec;
2265
2266 if (os_get_random(rval, sizeof(rval)) < 0)
2267 sec = os_random() % 60;
2268 else
2269 sec = WPA_GET_BE32(rval) % 60;
2270 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2271 "report %d seconds", sec);
2272 wpa_s->pending_mic_error_report = 1;
2273 wpa_s->pending_mic_error_pairwise = pairwise;
2274 eloop_cancel_timeout(
2275 wpa_supplicant_delayed_mic_error_report,
2276 wpa_s, NULL);
2277 eloop_register_timeout(
2278 sec, os_random() % 1000000,
2279 wpa_supplicant_delayed_mic_error_report,
2280 wpa_s, NULL);
2281 } else {
2282 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2283 }
2284#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2285 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2286#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2287 }
2288 wpa_s->last_michael_mic_error = t.sec;
2289 wpa_s->mic_errors_seen++;
2290}
2291
2292
2293#ifdef CONFIG_TERMINATE_ONLASTIF
2294static int any_interfaces(struct wpa_supplicant *head)
2295{
2296 struct wpa_supplicant *wpa_s;
2297
2298 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2299 if (!wpa_s->interface_removed)
2300 return 1;
2301 return 0;
2302}
2303#endif /* CONFIG_TERMINATE_ONLASTIF */
2304
2305
2306static void
2307wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2308 union wpa_event_data *data)
2309{
2310 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2311 return;
2312
2313 switch (data->interface_status.ievent) {
2314 case EVENT_INTERFACE_ADDED:
2315 if (!wpa_s->interface_removed)
2316 break;
2317 wpa_s->interface_removed = 0;
2318 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2319 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2320 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2321 "driver after interface was added");
2322 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002323 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324 break;
2325 case EVENT_INTERFACE_REMOVED:
2326 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2327 wpa_s->interface_removed = 1;
2328 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002329 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002330 l2_packet_deinit(wpa_s->l2);
2331 wpa_s->l2 = NULL;
2332#ifdef CONFIG_IBSS_RSN
2333 ibss_rsn_deinit(wpa_s->ibss_rsn);
2334 wpa_s->ibss_rsn = NULL;
2335#endif /* CONFIG_IBSS_RSN */
2336#ifdef CONFIG_TERMINATE_ONLASTIF
2337 /* check if last interface */
2338 if (!any_interfaces(wpa_s->global->ifaces))
2339 eloop_terminate();
2340#endif /* CONFIG_TERMINATE_ONLASTIF */
2341 break;
2342 }
2343}
2344
2345
2346#ifdef CONFIG_PEERKEY
2347static void
2348wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2349 union wpa_event_data *data)
2350{
2351 if (data == NULL)
2352 return;
2353 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2354}
2355#endif /* CONFIG_PEERKEY */
2356
2357
2358#ifdef CONFIG_TDLS
2359static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2360 union wpa_event_data *data)
2361{
2362 if (data == NULL)
2363 return;
2364 switch (data->tdls.oper) {
2365 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002366 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2367 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2368 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2369 else
2370 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002371 break;
2372 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002373 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2374 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2375 data->tdls.reason_code);
2376 else
2377 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2378 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002379 break;
2380 }
2381}
2382#endif /* CONFIG_TDLS */
2383
2384
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002385#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002386static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2387 union wpa_event_data *data)
2388{
2389 if (data == NULL)
2390 return;
2391 switch (data->wnm.oper) {
2392 case WNM_OPER_SLEEP:
2393 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2394 "(action=%d, intval=%d)",
2395 data->wnm.sleep_action, data->wnm.sleep_intval);
2396 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002397 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002398 break;
2399 }
2400}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002401#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002402
2403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002404#ifdef CONFIG_IEEE80211R
2405static void
2406wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2407 union wpa_event_data *data)
2408{
2409 if (data == NULL)
2410 return;
2411
2412 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2413 data->ft_ies.ies_len,
2414 data->ft_ies.ft_action,
2415 data->ft_ies.target_ap,
2416 data->ft_ies.ric_ies,
2417 data->ft_ies.ric_ies_len) < 0) {
2418 /* TODO: prevent MLME/driver from trying to associate? */
2419 }
2420}
2421#endif /* CONFIG_IEEE80211R */
2422
2423
2424#ifdef CONFIG_IBSS_RSN
2425static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2426 union wpa_event_data *data)
2427{
2428 struct wpa_ssid *ssid;
2429 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2430 return;
2431 if (data == NULL)
2432 return;
2433 ssid = wpa_s->current_ssid;
2434 if (ssid == NULL)
2435 return;
2436 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2437 return;
2438
2439 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2440}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002441
2442
2443static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2444 union wpa_event_data *data)
2445{
2446 struct wpa_ssid *ssid = wpa_s->current_ssid;
2447
2448 if (ssid == NULL)
2449 return;
2450
2451 /* check if the ssid is correctly configured as IBSS/RSN */
2452 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2453 return;
2454
2455 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2456 data->rx_mgmt.frame_len);
2457}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458#endif /* CONFIG_IBSS_RSN */
2459
2460
2461#ifdef CONFIG_IEEE80211R
2462static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2463 size_t len)
2464{
2465 const u8 *sta_addr, *target_ap_addr;
2466 u16 status;
2467
2468 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2469 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2470 return; /* only SME case supported for now */
2471 if (len < 1 + 2 * ETH_ALEN + 2)
2472 return;
2473 if (data[0] != 2)
2474 return; /* Only FT Action Response is supported for now */
2475 sta_addr = data + 1;
2476 target_ap_addr = data + 1 + ETH_ALEN;
2477 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2479 MACSTR " TargetAP " MACSTR " status %u",
2480 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2481
2482 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2483 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2484 " in FT Action Response", MAC2STR(sta_addr));
2485 return;
2486 }
2487
2488 if (status) {
2489 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2490 "failure (status code %d)", status);
2491 /* TODO: report error to FT code(?) */
2492 return;
2493 }
2494
2495 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2496 len - (1 + 2 * ETH_ALEN + 2), 1,
2497 target_ap_addr, NULL, 0) < 0)
2498 return;
2499
2500#ifdef CONFIG_SME
2501 {
2502 struct wpa_bss *bss;
2503 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2504 if (bss)
2505 wpa_s->sme.freq = bss->freq;
2506 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2507 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2508 WLAN_AUTH_FT);
2509 }
2510#endif /* CONFIG_SME */
2511}
2512#endif /* CONFIG_IEEE80211R */
2513
2514
2515static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2516 struct unprot_deauth *e)
2517{
2518#ifdef CONFIG_IEEE80211W
2519 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2520 "dropped: " MACSTR " -> " MACSTR
2521 " (reason code %u)",
2522 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2523 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2524#endif /* CONFIG_IEEE80211W */
2525}
2526
2527
2528static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2529 struct unprot_disassoc *e)
2530{
2531#ifdef CONFIG_IEEE80211W
2532 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2533 "dropped: " MACSTR " -> " MACSTR
2534 " (reason code %u)",
2535 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2536 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2537#endif /* CONFIG_IEEE80211W */
2538}
2539
2540
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002541static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2542 u16 reason_code, int locally_generated,
2543 const u8 *ie, size_t ie_len, int deauth)
2544{
2545#ifdef CONFIG_AP
2546 if (wpa_s->ap_iface && addr) {
2547 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2548 return;
2549 }
2550
2551 if (wpa_s->ap_iface) {
2552 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2553 return;
2554 }
2555#endif /* CONFIG_AP */
2556
2557 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2558
2559 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2560 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2561 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2562 eapol_sm_failed(wpa_s->eapol)))
2563 wpas_auth_failed(wpa_s);
2564
2565#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002566 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002567 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2568 locally_generated) > 0) {
2569 /*
2570 * The interface was removed, so cannot continue
2571 * processing any additional operations after this.
2572 */
2573 return;
2574 }
2575 }
2576#endif /* CONFIG_P2P */
2577
2578 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2579 locally_generated);
2580}
2581
2582
2583static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2584 struct disassoc_info *info)
2585{
2586 u16 reason_code = 0;
2587 int locally_generated = 0;
2588 const u8 *addr = NULL;
2589 const u8 *ie = NULL;
2590 size_t ie_len = 0;
2591
2592 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2593
2594 if (info) {
2595 addr = info->addr;
2596 ie = info->ie;
2597 ie_len = info->ie_len;
2598 reason_code = info->reason_code;
2599 locally_generated = info->locally_generated;
2600 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2601 locally_generated ? " (locally generated)" : "");
2602 if (addr)
2603 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2604 MAC2STR(addr));
2605 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2606 ie, ie_len);
2607 }
2608
2609#ifdef CONFIG_AP
2610 if (wpa_s->ap_iface && info && info->addr) {
2611 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2612 return;
2613 }
2614
2615 if (wpa_s->ap_iface) {
2616 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2617 return;
2618 }
2619#endif /* CONFIG_AP */
2620
2621#ifdef CONFIG_P2P
2622 if (info) {
2623 wpas_p2p_disassoc_notif(
2624 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2625 locally_generated);
2626 }
2627#endif /* CONFIG_P2P */
2628
2629 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2630 sme_event_disassoc(wpa_s, info);
2631
2632 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2633 ie, ie_len, 0);
2634}
2635
2636
2637static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2638 struct deauth_info *info)
2639{
2640 u16 reason_code = 0;
2641 int locally_generated = 0;
2642 const u8 *addr = NULL;
2643 const u8 *ie = NULL;
2644 size_t ie_len = 0;
2645
2646 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2647
2648 if (info) {
2649 addr = info->addr;
2650 ie = info->ie;
2651 ie_len = info->ie_len;
2652 reason_code = info->reason_code;
2653 locally_generated = info->locally_generated;
2654 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2655 reason_code,
2656 locally_generated ? " (locally generated)" : "");
2657 if (addr) {
2658 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2659 MAC2STR(addr));
2660 }
2661 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2662 ie, ie_len);
2663 }
2664
2665 wpa_reset_ft_completed(wpa_s->wpa);
2666
2667 wpas_event_disconnect(wpa_s, addr, reason_code,
2668 locally_generated, ie, ie_len, 1);
2669}
2670
2671
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002672static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2673{
2674 const char *rn, *rn2;
2675 struct wpa_supplicant *ifs;
2676
2677 if (wpa_s->drv_priv == NULL)
2678 return; /* Ignore event during drv initialization */
2679
2680 free_hw_features(wpa_s);
2681 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2682 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2683
2684#ifdef CONFIG_P2P
2685 wpas_p2p_update_channel_list(wpa_s);
2686#endif /* CONFIG_P2P */
2687
2688 /*
2689 * Check other interfaces to see if they have the same radio-name. If
2690 * so, they get updated with this same hw mode info.
2691 */
2692 if (!wpa_s->driver->get_radio_name)
2693 return;
2694
2695 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2696 if (rn == NULL || rn[0] == '\0')
2697 return;
2698
2699 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2700 "sharing same radio (%s) in event_channel_list_change", rn);
2701
2702 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2703 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2704 continue;
2705
2706 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2707 if (rn2 && os_strcmp(rn, rn2) == 0) {
2708 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2709 ifs->ifname);
2710 free_hw_features(ifs);
2711 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2712 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2713 }
2714 }
2715}
2716
2717
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2719 union wpa_event_data *data)
2720{
2721 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722
2723 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2724 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002725 event != EVENT_INTERFACE_STATUS &&
2726 event != EVENT_SCHED_SCAN_STOPPED) {
2727 wpa_dbg(wpa_s, MSG_DEBUG,
2728 "Ignore event %s (%d) while interface is disabled",
2729 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 return;
2731 }
2732
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002733#ifndef CONFIG_NO_STDOUT_DEBUG
2734{
2735 int level = MSG_DEBUG;
2736
Dmitry Shmidt04949592012-07-19 12:16:46 -07002737 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002738 const struct ieee80211_hdr *hdr;
2739 u16 fc;
2740 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2741 fc = le_to_host16(hdr->frame_control);
2742 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2743 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2744 level = MSG_EXCESSIVE;
2745 }
2746
2747 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2748 event_to_string(event), event);
2749}
2750#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751
2752 switch (event) {
2753 case EVENT_AUTH:
2754 sme_event_auth(wpa_s, data);
2755 break;
2756 case EVENT_ASSOC:
2757 wpa_supplicant_event_assoc(wpa_s, data);
2758 break;
2759 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002760 wpas_event_disassoc(wpa_s,
2761 data ? &data->disassoc_info : NULL);
2762 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002764 wpas_event_deauth(wpa_s,
2765 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002766 break;
2767 case EVENT_MICHAEL_MIC_FAILURE:
2768 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2769 break;
2770#ifndef CONFIG_NO_SCAN_PROCESSING
2771 case EVENT_SCAN_RESULTS:
2772 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002773 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2774 wpa_s->wpa_state != WPA_ASSOCIATING)
2775 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 break;
2777#endif /* CONFIG_NO_SCAN_PROCESSING */
2778 case EVENT_ASSOCINFO:
2779 wpa_supplicant_event_associnfo(wpa_s, data);
2780 break;
2781 case EVENT_INTERFACE_STATUS:
2782 wpa_supplicant_event_interface_status(wpa_s, data);
2783 break;
2784 case EVENT_PMKID_CANDIDATE:
2785 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2786 break;
2787#ifdef CONFIG_PEERKEY
2788 case EVENT_STKSTART:
2789 wpa_supplicant_event_stkstart(wpa_s, data);
2790 break;
2791#endif /* CONFIG_PEERKEY */
2792#ifdef CONFIG_TDLS
2793 case EVENT_TDLS:
2794 wpa_supplicant_event_tdls(wpa_s, data);
2795 break;
2796#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002797#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002798 case EVENT_WNM:
2799 wpa_supplicant_event_wnm(wpa_s, data);
2800 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002801#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802#ifdef CONFIG_IEEE80211R
2803 case EVENT_FT_RESPONSE:
2804 wpa_supplicant_event_ft_response(wpa_s, data);
2805 break;
2806#endif /* CONFIG_IEEE80211R */
2807#ifdef CONFIG_IBSS_RSN
2808 case EVENT_IBSS_RSN_START:
2809 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2810 break;
2811#endif /* CONFIG_IBSS_RSN */
2812 case EVENT_ASSOC_REJECT:
2813 if (data->assoc_reject.bssid)
2814 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2815 "bssid=" MACSTR " status_code=%u",
2816 MAC2STR(data->assoc_reject.bssid),
2817 data->assoc_reject.status_code);
2818 else
2819 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2820 "status_code=%u",
2821 data->assoc_reject.status_code);
2822 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2823 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002824 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002825#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002826 if(!wpa_s->current_ssid) {
2827 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2828 break;
2829 }
2830 /* If assoc reject is reported by the driver, then avoid
2831 * waiting for the authentication timeout. Cancel the
2832 * authentication timeout and retry the assoc.
2833 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002834 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002835 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2836 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002837
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002838 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002839
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002840 /* Clear the states */
2841 wpa_sm_notify_disassoc(wpa_s->wpa);
2842 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2843
2844 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002845 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002846 const u8 *bl_bssid = data->assoc_reject.bssid;
2847 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2848 bl_bssid = wpa_s->pending_bssid;
2849 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002850 wpa_supplicant_req_scan(wpa_s, 0, 0);
2851 } else {
2852 wpa_supplicant_req_scan(wpa_s, 1, 0);
2853 }
2854 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002855 /* If we ASSOC_REJECT's hits threshold, disable the
2856 * network
2857 */
2858 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2859 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002860 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002861 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002862 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002863 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002864#else
2865 const u8 *bssid = data->assoc_reject.bssid;
2866 if (bssid == NULL || is_zero_ether_addr(bssid))
2867 bssid = wpa_s->pending_bssid;
2868 wpas_connection_failed(wpa_s, bssid);
2869 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002870#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002871 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 break;
2873 case EVENT_AUTH_TIMED_OUT:
2874 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2875 sme_event_auth_timed_out(wpa_s, data);
2876 break;
2877 case EVENT_ASSOC_TIMED_OUT:
2878 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2879 sme_event_assoc_timed_out(wpa_s, data);
2880 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 case EVENT_TX_STATUS:
2882 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2883 " type=%d stype=%d",
2884 MAC2STR(data->tx_status.dst),
2885 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002886#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002888#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2890 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002891 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 wpa_s, data->tx_status.dst,
2893 data->tx_status.data,
2894 data->tx_status.data_len,
2895 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002896 OFFCHANNEL_SEND_ACTION_SUCCESS :
2897 OFFCHANNEL_SEND_ACTION_NO_ACK);
2898#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002899 break;
2900 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002901#endif /* CONFIG_AP */
2902#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2904 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2905 /*
2906 * Catch TX status events for Action frames we sent via group
2907 * interface in GO mode.
2908 */
2909 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2910 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2911 os_memcmp(wpa_s->parent->pending_action_dst,
2912 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002913 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002914 wpa_s->parent, data->tx_status.dst,
2915 data->tx_status.data,
2916 data->tx_status.data_len,
2917 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002918 OFFCHANNEL_SEND_ACTION_SUCCESS :
2919 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002920 break;
2921 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002922#endif /* CONFIG_OFFCHANNEL */
2923#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002924 switch (data->tx_status.type) {
2925 case WLAN_FC_TYPE_MGMT:
2926 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2927 data->tx_status.data_len,
2928 data->tx_status.stype,
2929 data->tx_status.ack);
2930 break;
2931 case WLAN_FC_TYPE_DATA:
2932 ap_tx_status(wpa_s, data->tx_status.dst,
2933 data->tx_status.data,
2934 data->tx_status.data_len,
2935 data->tx_status.ack);
2936 break;
2937 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002938#endif /* CONFIG_AP */
2939 break;
2940#ifdef CONFIG_AP
2941 case EVENT_EAPOL_TX_STATUS:
2942 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2943 data->eapol_tx_status.data,
2944 data->eapol_tx_status.data_len,
2945 data->eapol_tx_status.ack);
2946 break;
2947 case EVENT_DRIVER_CLIENT_POLL_OK:
2948 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002949 break;
2950 case EVENT_RX_FROM_UNKNOWN:
2951 if (wpa_s->ap_iface == NULL)
2952 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002953 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2954 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002955 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002956 case EVENT_CH_SWITCH:
2957 if (!data)
2958 break;
2959 if (!wpa_s->ap_iface) {
2960 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2961 "event in non-AP mode");
2962 break;
2963 }
2964
Dmitry Shmidt04949592012-07-19 12:16:46 -07002965 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2966 data->ch_switch.ht_enabled,
2967 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002968 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002969#endif /* CONFIG_AP */
2970#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002971 case EVENT_RX_MGMT: {
2972 u16 fc, stype;
2973 const struct ieee80211_mgmt *mgmt;
2974
2975 mgmt = (const struct ieee80211_mgmt *)
2976 data->rx_mgmt.frame;
2977 fc = le_to_host16(mgmt->frame_control);
2978 stype = WLAN_FC_GET_STYPE(fc);
2979
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002980#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002982#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2985 data->rx_mgmt.frame_len > 24) {
2986 const u8 *src = mgmt->sa;
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);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002991 wpas_p2p_probe_req_rx(
2992 wpa_s, src, mgmt->da,
2993 mgmt->bssid, ie, ie_len,
2994 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002995 break;
2996 }
2997#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002998#ifdef CONFIG_IBSS_RSN
2999 if (stype == WLAN_FC_STYPE_AUTH &&
3000 data->rx_mgmt.frame_len >= 30) {
3001 wpa_supplicant_event_ibss_auth(wpa_s, data);
3002 break;
3003 }
3004#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003005 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3006 "management frame in non-AP mode");
3007 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003008#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003009 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003010
3011 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3012 data->rx_mgmt.frame_len > 24) {
3013 const u8 *ie = mgmt->u.probe_req.variable;
3014 size_t ie_len = data->rx_mgmt.frame_len -
3015 (mgmt->u.probe_req.variable -
3016 data->rx_mgmt.frame);
3017
3018 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3019 mgmt->bssid, ie, ie_len,
3020 data->rx_mgmt.ssi_signal);
3021 }
3022
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003023 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003024#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003026 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003027#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 case EVENT_RX_ACTION:
3029 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3030 " Category=%u DataLen=%d freq=%d MHz",
3031 MAC2STR(data->rx_action.sa),
3032 data->rx_action.category, (int) data->rx_action.len,
3033 data->rx_action.freq);
3034#ifdef CONFIG_IEEE80211R
3035 if (data->rx_action.category == WLAN_ACTION_FT) {
3036 ft_rx_action(wpa_s, data->rx_action.data,
3037 data->rx_action.len);
3038 break;
3039 }
3040#endif /* CONFIG_IEEE80211R */
3041#ifdef CONFIG_IEEE80211W
3042#ifdef CONFIG_SME
3043 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3044 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3045 data->rx_action.data,
3046 data->rx_action.len);
3047 break;
3048 }
3049#endif /* CONFIG_SME */
3050#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003051#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003052 if (data->rx_action.category == WLAN_ACTION_WNM) {
3053 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3054 break;
3055 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003056#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003057#ifdef CONFIG_GAS
3058 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3059 gas_query_rx(wpa_s->gas, data->rx_action.da,
3060 data->rx_action.sa, data->rx_action.bssid,
3061 data->rx_action.data, data->rx_action.len,
3062 data->rx_action.freq) == 0)
3063 break;
3064#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003065#ifdef CONFIG_TDLS
3066 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3067 data->rx_action.len >= 4 &&
3068 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3069 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3070 "Response from " MACSTR,
3071 MAC2STR(data->rx_action.sa));
3072 break;
3073 }
3074#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003075#ifdef CONFIG_INTERWORKING
3076 if (data->rx_action.category == WLAN_ACTION_QOS &&
3077 data->rx_action.len >= 1 &&
3078 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
3079 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3080 MACSTR, MAC2STR(data->rx_action.sa));
3081 if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
3082 == 0)
3083 wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
3084 data->rx_action.len - 1);
3085 break;
3086 }
3087#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088#ifdef CONFIG_P2P
3089 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3090 data->rx_action.sa,
3091 data->rx_action.bssid,
3092 data->rx_action.category,
3093 data->rx_action.data,
3094 data->rx_action.len, data->rx_action.freq);
3095#endif /* CONFIG_P2P */
3096 break;
3097 case EVENT_RX_PROBE_REQ:
3098 if (data->rx_probe_req.sa == NULL ||
3099 data->rx_probe_req.ie == NULL)
3100 break;
3101#ifdef CONFIG_AP
3102 if (wpa_s->ap_iface) {
3103 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3104 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003105 data->rx_probe_req.da,
3106 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003107 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003108 data->rx_probe_req.ie_len,
3109 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003110 break;
3111 }
3112#endif /* CONFIG_AP */
3113#ifdef CONFIG_P2P
3114 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003115 data->rx_probe_req.da,
3116 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003118 data->rx_probe_req.ie_len,
3119 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003120#endif /* CONFIG_P2P */
3121 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003122 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003123#ifdef CONFIG_OFFCHANNEL
3124 offchannel_remain_on_channel_cb(
3125 wpa_s, data->remain_on_channel.freq,
3126 data->remain_on_channel.duration);
3127#endif /* CONFIG_OFFCHANNEL */
3128#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003129 wpas_p2p_remain_on_channel_cb(
3130 wpa_s, data->remain_on_channel.freq,
3131 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003132#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003133 break;
3134 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003135#ifdef CONFIG_OFFCHANNEL
3136 offchannel_cancel_remain_on_channel_cb(
3137 wpa_s, data->remain_on_channel.freq);
3138#endif /* CONFIG_OFFCHANNEL */
3139#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003140 wpas_p2p_cancel_remain_on_channel_cb(
3141 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003142#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003143 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003144#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003145 case EVENT_P2P_DEV_FOUND: {
3146 struct p2p_peer_info peer_info;
3147
3148 os_memset(&peer_info, 0, sizeof(peer_info));
3149 if (data->p2p_dev_found.dev_addr)
3150 os_memcpy(peer_info.p2p_device_addr,
3151 data->p2p_dev_found.dev_addr, ETH_ALEN);
3152 if (data->p2p_dev_found.pri_dev_type)
3153 os_memcpy(peer_info.pri_dev_type,
3154 data->p2p_dev_found.pri_dev_type,
3155 sizeof(peer_info.pri_dev_type));
3156 if (data->p2p_dev_found.dev_name)
3157 os_strlcpy(peer_info.device_name,
3158 data->p2p_dev_found.dev_name,
3159 sizeof(peer_info.device_name));
3160 peer_info.config_methods = data->p2p_dev_found.config_methods;
3161 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3162 peer_info.group_capab = data->p2p_dev_found.group_capab;
3163
3164 /*
3165 * FIX: new_device=1 is not necessarily correct. We should
3166 * maintain a P2P peer database in wpa_supplicant and update
3167 * this information based on whether the peer is truly new.
3168 */
3169 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3170 break;
3171 }
3172 case EVENT_P2P_GO_NEG_REQ_RX:
3173 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3174 data->p2p_go_neg_req_rx.dev_passwd_id);
3175 break;
3176 case EVENT_P2P_GO_NEG_COMPLETED:
3177 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3178 break;
3179 case EVENT_P2P_PROV_DISC_REQUEST:
3180 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3181 data->p2p_prov_disc_req.config_methods,
3182 data->p2p_prov_disc_req.dev_addr,
3183 data->p2p_prov_disc_req.pri_dev_type,
3184 data->p2p_prov_disc_req.dev_name,
3185 data->p2p_prov_disc_req.supp_config_methods,
3186 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003187 data->p2p_prov_disc_req.group_capab,
3188 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003189 break;
3190 case EVENT_P2P_PROV_DISC_RESPONSE:
3191 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3192 data->p2p_prov_disc_resp.config_methods);
3193 break;
3194 case EVENT_P2P_SD_REQUEST:
3195 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3196 data->p2p_sd_req.sa,
3197 data->p2p_sd_req.dialog_token,
3198 data->p2p_sd_req.update_indic,
3199 data->p2p_sd_req.tlvs,
3200 data->p2p_sd_req.tlvs_len);
3201 break;
3202 case EVENT_P2P_SD_RESPONSE:
3203 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3204 data->p2p_sd_resp.update_indic,
3205 data->p2p_sd_resp.tlvs,
3206 data->p2p_sd_resp.tlvs_len);
3207 break;
3208#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 case EVENT_EAPOL_RX:
3210 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3211 data->eapol_rx.data,
3212 data->eapol_rx.data_len);
3213 break;
3214 case EVENT_SIGNAL_CHANGE:
3215 bgscan_notify_signal_change(
3216 wpa_s, data->signal_change.above_threshold,
3217 data->signal_change.current_signal,
3218 data->signal_change.current_noise,
3219 data->signal_change.current_txrate);
3220 break;
3221 case EVENT_INTERFACE_ENABLED:
3222 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3223 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003224 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003225#ifdef CONFIG_AP
3226 if (!wpa_s->ap_iface) {
3227 wpa_supplicant_set_state(wpa_s,
3228 WPA_DISCONNECTED);
3229 wpa_supplicant_req_scan(wpa_s, 0, 0);
3230 } else
3231 wpa_supplicant_set_state(wpa_s,
3232 WPA_COMPLETED);
3233#else /* CONFIG_AP */
3234 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3235 wpa_supplicant_req_scan(wpa_s, 0, 0);
3236#endif /* CONFIG_AP */
3237 }
3238 break;
3239 case EVENT_INTERFACE_DISABLED:
3240 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3241 wpa_supplicant_mark_disassoc(wpa_s);
3242 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3243 break;
3244 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003245 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003246 break;
3247 case EVENT_INTERFACE_UNAVAILABLE:
3248#ifdef CONFIG_P2P
3249 wpas_p2p_interface_unavailable(wpa_s);
3250#endif /* CONFIG_P2P */
3251 break;
3252 case EVENT_BEST_CHANNEL:
3253 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3254 "(%d %d %d)",
3255 data->best_chan.freq_24, data->best_chan.freq_5,
3256 data->best_chan.freq_overall);
3257 wpa_s->best_24_freq = data->best_chan.freq_24;
3258 wpa_s->best_5_freq = data->best_chan.freq_5;
3259 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3260#ifdef CONFIG_P2P
3261 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3262 data->best_chan.freq_5,
3263 data->best_chan.freq_overall);
3264#endif /* CONFIG_P2P */
3265 break;
3266 case EVENT_UNPROT_DEAUTH:
3267 wpa_supplicant_event_unprot_deauth(wpa_s,
3268 &data->unprot_deauth);
3269 break;
3270 case EVENT_UNPROT_DISASSOC:
3271 wpa_supplicant_event_unprot_disassoc(wpa_s,
3272 &data->unprot_disassoc);
3273 break;
3274 case EVENT_STATION_LOW_ACK:
3275#ifdef CONFIG_AP
3276 if (wpa_s->ap_iface && data)
3277 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3278 data->low_ack.addr);
3279#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003280#ifdef CONFIG_TDLS
3281 if (data)
3282 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3283#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003284 break;
3285 case EVENT_IBSS_PEER_LOST:
3286#ifdef CONFIG_IBSS_RSN
3287 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3288#endif /* CONFIG_IBSS_RSN */
3289 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003290 case EVENT_DRIVER_GTK_REKEY:
3291 if (os_memcmp(data->driver_gtk_rekey.bssid,
3292 wpa_s->bssid, ETH_ALEN))
3293 break;
3294 if (!wpa_s->wpa)
3295 break;
3296 wpa_sm_update_replay_ctr(wpa_s->wpa,
3297 data->driver_gtk_rekey.replay_ctr);
3298 break;
3299 case EVENT_SCHED_SCAN_STOPPED:
3300 wpa_s->sched_scanning = 0;
3301 wpa_supplicant_notify_scanning(wpa_s, 0);
3302
3303 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3304 break;
3305
3306 /*
3307 * If we timed out, start a new sched scan to continue
3308 * searching for more SSIDs.
3309 */
3310 if (wpa_s->sched_scan_timed_out)
3311 wpa_supplicant_req_sched_scan(wpa_s);
3312 break;
3313 case EVENT_WPS_BUTTON_PUSHED:
3314#ifdef CONFIG_WPS
3315 wpas_wps_start_pbc(wpa_s, NULL, 0);
3316#endif /* CONFIG_WPS */
3317 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003318 case EVENT_CONNECT_FAILED_REASON:
3319#ifdef CONFIG_AP
3320 if (!wpa_s->ap_iface || !data)
3321 break;
3322 hostapd_event_connect_failed_reason(
3323 wpa_s->ap_iface->bss[0],
3324 data->connect_failed_reason.addr,
3325 data->connect_failed_reason.code);
3326#endif /* CONFIG_AP */
3327 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003328 default:
3329 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3330 break;
3331 }
3332}