blob: 31c5baa5e544bd5077c30fb3e0fe145fe0a27004 [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,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080049 int new_scan, int own_request);
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);
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174#ifdef CONFIG_IEEE80211R
175#ifdef CONFIG_SME
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178#endif /* CONFIG_SME */
179#endif /* CONFIG_IEEE80211R */
180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700190 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192}
193
194
195static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
196{
197 struct wpa_ie_data ie;
198 int pmksa_set = -1;
199 size_t i;
200
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 ie.pmkid == NULL)
203 return;
204
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
208 NULL, NULL, 0);
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
211 break;
212 }
213 }
214
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217}
218
219
220static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
222{
223 if (data == NULL) {
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 "event");
226 return;
227 }
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
233
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
237}
238
239
240static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
241{
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
244 return 0;
245
246#ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
254 return 0;
255 }
256#endif /* IEEE8021X_EAPOL */
257
258 return 1;
259}
260
261
262/**
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
267 *
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
270 */
271int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
273{
274#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700276 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277
Dmitry Shmidt051af732013-10-22 13:52:46 -0700278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
279 wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 return 0;
281
282 if (ssid->eap.eap_methods == NULL) {
283 sim = 1;
284 aka = 1;
285 } else {
286 struct eap_method_type *eap = ssid->eap.eap_methods;
287 while (eap->vendor != EAP_VENDOR_IETF ||
288 eap->method != EAP_TYPE_NONE) {
289 if (eap->vendor == EAP_VENDOR_IETF) {
290 if (eap->method == EAP_TYPE_SIM)
291 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 else if (eap->method == EAP_TYPE_AKA ||
293 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 aka = 1;
295 }
296 eap++;
297 }
298 }
299
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
303 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 aka = 0;
306
307 if (!sim && !aka) {
308 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
309 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 "enabled");
311 return 0;
312 }
313
314 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
315 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800317 wpa_s->scard = scard_init(NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 if (wpa_s->scard == NULL) {
319 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
320 "(pcsc-lite)");
321 return -1;
322 }
323 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
324 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800325#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326#endif /* IEEE8021X_EAPOL */
327
328 return 0;
329}
330
331
332#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700333
334static int has_wep_key(struct wpa_ssid *ssid)
335{
336 int i;
337
338 for (i = 0; i < NUM_WEP_KEYS; i++) {
339 if (ssid->wep_key_len[i])
340 return 1;
341 }
342
343 return 0;
344}
345
346
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700347static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 struct wpa_ssid *ssid)
349{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700350 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351
352 if (ssid->mixed_cell)
353 return 1;
354
355#ifdef CONFIG_WPS
356 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
357 return 1;
358#endif /* CONFIG_WPS */
359
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700360 if (has_wep_key(ssid))
361 privacy = 1;
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363#ifdef IEEE8021X_EAPOL
364 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
365 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
367 privacy = 1;
368#endif /* IEEE8021X_EAPOL */
369
Jouni Malinen75ecf522011-06-27 15:19:46 -0700370 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
371 privacy = 1;
372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 if (bss->caps & IEEE80211_CAP_PRIVACY)
374 return privacy;
375 return !privacy;
376}
377
378
379static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
380 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700381 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382{
383 struct wpa_ie_data ie;
384 int proto_match = 0;
385 const u8 *rsn_ie, *wpa_ie;
386 int ret;
387 int wep_ok;
388
389 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
390 if (ret >= 0)
391 return ret;
392
393 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
394 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
395 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
396 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
397 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
398
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700399 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
401 proto_match++;
402
403 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
405 "failed");
406 break;
407 }
408
409 if (wep_ok &&
410 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
411 {
412 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
413 "in RSN IE");
414 return 1;
415 }
416
417 if (!(ie.proto & ssid->proto)) {
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
419 "mismatch");
420 break;
421 }
422
423 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
425 "cipher mismatch");
426 break;
427 }
428
429 if (!(ie.group_cipher & ssid->group_cipher)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
431 "cipher mismatch");
432 break;
433 }
434
435 if (!(ie.key_mgmt & ssid->key_mgmt)) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
437 "mismatch");
438 break;
439 }
440
441#ifdef CONFIG_IEEE80211W
442 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800443 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
444 wpa_s->conf->pmf : ssid->ieee80211w) ==
445 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
447 "frame protection");
448 break;
449 }
450#endif /* CONFIG_IEEE80211W */
451
452 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
453 return 1;
454 }
455
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700456 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
458 proto_match++;
459
460 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
462 "failed");
463 break;
464 }
465
466 if (wep_ok &&
467 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
468 {
469 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
470 "in WPA IE");
471 return 1;
472 }
473
474 if (!(ie.proto & ssid->proto)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
476 "mismatch");
477 break;
478 }
479
480 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
482 "cipher mismatch");
483 break;
484 }
485
486 if (!(ie.group_cipher & ssid->group_cipher)) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
488 "cipher mismatch");
489 break;
490 }
491
492 if (!(ie.key_mgmt & ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
494 "mismatch");
495 break;
496 }
497
498 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
499 return 1;
500 }
501
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700502 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
503 !rsn_ie) {
504 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
505 return 1;
506 }
507
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
509 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
511 return 0;
512 }
513
514 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
516 return 1;
517 }
518
519 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
520 "WPA/WPA2");
521
522 return 0;
523}
524
525
526static int freq_allowed(int *freqs, int freq)
527{
528 int i;
529
530 if (freqs == NULL)
531 return 1;
532
533 for (i = 0; freqs[i]; i++)
534 if (freqs[i] == freq)
535 return 1;
536 return 0;
537}
538
539
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540static int ht_supported(const struct hostapd_hw_modes *mode)
541{
542 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
543 /*
544 * The driver did not indicate whether it supports HT. Assume
545 * it does to avoid connection issues.
546 */
547 return 1;
548 }
549
550 /*
551 * IEEE Std 802.11n-2009 20.1.1:
552 * An HT non-AP STA shall support all EQM rates for one spatial stream.
553 */
554 return mode->mcs_set[0] == 0xff;
555}
556
557
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700558static int vht_supported(const struct hostapd_hw_modes *mode)
559{
560 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
561 /*
562 * The driver did not indicate whether it supports VHT. Assume
563 * it does to avoid connection issues.
564 */
565 return 1;
566 }
567
568 /*
569 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
570 * TODO: Verify if this complies with the standard
571 */
572 return (mode->vht_mcs_set[0] & 0x3) != 3;
573}
574
575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700576static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800577{
578 const struct hostapd_hw_modes *mode = NULL, *modes;
579 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
580 const u8 *rate_ie;
581 int i, j, k;
582
583 if (bss->freq == 0)
584 return 1; /* Cannot do matching without knowing band */
585
586 modes = wpa_s->hw.modes;
587 if (modes == NULL) {
588 /*
589 * The driver does not provide any additional information
590 * about the utilized hardware, so allow the connection attempt
591 * to continue.
592 */
593 return 1;
594 }
595
596 for (i = 0; i < wpa_s->hw.num_modes; i++) {
597 for (j = 0; j < modes[i].num_channels; j++) {
598 int freq = modes[i].channels[j].freq;
599 if (freq == bss->freq) {
600 if (mode &&
601 mode->mode == HOSTAPD_MODE_IEEE80211G)
602 break; /* do not allow 802.11b replace
603 * 802.11g */
604 mode = &modes[i];
605 break;
606 }
607 }
608 }
609
610 if (mode == NULL)
611 return 0;
612
613 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700614 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 if (rate_ie == NULL)
616 continue;
617
618 for (j = 2; j < rate_ie[1] + 2; j++) {
619 int flagged = !!(rate_ie[j] & 0x80);
620 int r = (rate_ie[j] & 0x7f) * 5;
621
622 /*
623 * IEEE Std 802.11n-2009 7.3.2.2:
624 * The new BSS Membership selector value is encoded
625 * like a legacy basic rate, but it is not a rate and
626 * only indicates if the BSS members are required to
627 * support the mandatory features of Clause 20 [HT PHY]
628 * in order to join the BSS.
629 */
630 if (flagged && ((rate_ie[j] & 0x7f) ==
631 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
632 if (!ht_supported(mode)) {
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " hardware does not support "
635 "HT PHY");
636 return 0;
637 }
638 continue;
639 }
640
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700641 /* There's also a VHT selector for 802.11ac */
642 if (flagged && ((rate_ie[j] & 0x7f) ==
643 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
644 if (!vht_supported(mode)) {
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " hardware does not support "
647 "VHT PHY");
648 return 0;
649 }
650 continue;
651 }
652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653 if (!flagged)
654 continue;
655
656 /* check for legacy basic rates */
657 for (k = 0; k < mode->num_rates; k++) {
658 if (mode->rates[k] == r)
659 break;
660 }
661 if (k == mode->num_rates) {
662 /*
663 * IEEE Std 802.11-2007 7.3.2.2 demands that in
664 * order to join a BSS all required rates
665 * have to be supported by the hardware.
666 */
667 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
668 "not support required rate %d.%d Mbps",
669 r / 10, r % 10);
670 return 0;
671 }
672 }
673 }
674
675 return 1;
676}
677
678
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800679static int bss_is_dmg(struct wpa_bss *bss)
680{
681 return bss->freq > 45000;
682}
683
684
685/*
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
688 */
689static int bss_is_ess(struct wpa_bss *bss)
690{
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
694 }
695
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
697 IEEE80211_CAP_ESS);
698}
699
700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700702 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 struct wpa_ssid *group)
704{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700705 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 int wpa;
707 struct wpa_blacklist *e;
708 const u8 *ie;
709 struct wpa_ssid *ssid;
710
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700711 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 wpa_ie_len = ie ? ie[1] : 0;
713
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700714 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 rsn_ie_len = ie ? ie[1] : 0;
716
717 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidt96571392013-10-14 12:54:46 -0700718 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700719 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700721 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
722 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
723 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
724 " p2p" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725
726 e = wpa_blacklist_get(wpa_s, bss->bssid);
727 if (e) {
728 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 /*
731 * When only a single network is enabled, we can
732 * trigger blacklisting on the first failure. This
733 * should not be done with multiple enabled networks to
734 * avoid getting forced to move into a worse ESS on
735 * single error if there are no other BSSes of the
736 * current ESS.
737 */
738 limit = 0;
739 }
740 if (e->count > limit) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
742 "(count=%d limit=%d)", e->count, limit);
743 return NULL;
744 }
745 }
746
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700747 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
749 return NULL;
750 }
751
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800752 if (disallowed_bssid(wpa_s, bss->bssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
754 return NULL;
755 }
756
757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
759 return NULL;
760 }
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
763
764 for (ssid = group; ssid; ssid = ssid->pnext) {
765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700766 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767
Dmitry Shmidt04949592012-07-19 12:16:46 -0700768 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
770 continue;
771 }
772
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700773 res = wpas_temp_disabled(wpa_s, ssid);
774 if (res > 0) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
776 "temporarily for %d second(s)", res);
777 continue;
778 }
779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780#ifdef CONFIG_WPS
781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
783 "(WPS)");
784 continue;
785 }
786
787 if (wpa && ssid->ssid_len == 0 &&
788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
789 check_ssid = 0;
790
791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
792 /* Only allow wildcard SSID match if an AP
793 * advertises active WPS operation that matches
794 * with our mode. */
795 check_ssid = 1;
796 if (ssid->ssid_len == 0 &&
797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
798 check_ssid = 0;
799 }
800#endif /* CONFIG_WPS */
801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 if (ssid->bssid_set && ssid->ssid_len == 0 &&
803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
804 check_ssid = 0;
805
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700807 (bss->ssid_len != ssid->ssid_len ||
808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
810 continue;
811 }
812
813 if (ssid->bssid_set &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
816 continue;
817 }
818
819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
820 continue;
821
822 if (!wpa &&
823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
827 "not allowed");
828 continue;
829 }
830
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
832 has_wep_key(ssid)) {
833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
834 continue;
835 }
836
Jouni Malinen75ecf522011-06-27 15:19:46 -0700837 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
839 "mismatch");
840 continue;
841 }
842
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800843 if (!bss_is_ess(bss)) {
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 continue;
846 }
847
848 if (!freq_allowed(ssid->freq_list, bss->freq)) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
850 "allowed");
851 continue;
852 }
853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854 if (!rate_match(wpa_s, bss)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
856 "not match");
857 continue;
858 }
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700861 if (ssid->p2p_group &&
862 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
863 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
865 continue;
866 }
867
Dmitry Shmidt54605472013-11-08 11:10:19 -0800868 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
869 struct wpabuf *p2p_ie;
870 u8 dev_addr[ETH_ALEN];
871
872 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
873 if (ie == NULL) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
875 continue;
876 }
877 p2p_ie = wpa_bss_get_vendor_ie_multi(
878 bss, P2P_IE_VENDOR_TYPE);
879 if (p2p_ie == NULL) {
880 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
881 continue;
882 }
883
884 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
885 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
886 ETH_ALEN) != 0) {
887 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
888 wpabuf_free(p2p_ie);
889 continue;
890 }
891 wpabuf_free(p2p_ie);
892 }
893
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 /*
895 * TODO: skip the AP if its P2P IE has Group Formation
896 * bit set in the P2P Group Capability Bitmap and we
897 * are not in Group Formation with that device.
898 */
899#endif /* CONFIG_P2P */
900
901 /* Matching configuration found */
902 return ssid;
903 }
904
905 /* No matching configuration found */
906 return NULL;
907}
908
909
910static struct wpa_bss *
911wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 struct wpa_ssid *group,
913 struct wpa_ssid **selected_ssid)
914{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700915 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916
917 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
918 group->priority);
919
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
921 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
923 if (!*selected_ssid)
924 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
926 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700927 MAC2STR(bss->bssid),
928 wpa_ssid_txt(bss->ssid, bss->ssid_len));
929 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 }
931
932 return NULL;
933}
934
935
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700936struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
937 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938{
939 struct wpa_bss *selected = NULL;
940 int prio;
941
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700942 if (wpa_s->last_scan_res == NULL ||
943 wpa_s->last_scan_res_used == 0)
944 return NULL; /* no scan results from last update */
945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 while (selected == NULL) {
947 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
948 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700949 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 selected_ssid);
951 if (selected)
952 break;
953 }
954
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800955 if (selected == NULL && wpa_s->blacklist &&
956 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
958 "blacklist and try again");
959 wpa_blacklist_clear(wpa_s);
960 wpa_s->blacklist_cleared++;
961 } else if (selected == NULL)
962 break;
963 }
964
965 return selected;
966}
967
968
969static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
970 int timeout_sec, int timeout_usec)
971{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700972 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973 /*
974 * No networks are enabled; short-circuit request so
975 * we don't wait timeout seconds before transitioning
976 * to INACTIVE state.
977 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700978 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
979 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700981#ifdef CONFIG_P2P
982 wpa_s->sta_scan_pending = 0;
983#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 return;
985 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800986
987 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
989}
990
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700992int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 struct wpa_bss *selected,
994 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995{
996 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
997 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
998 "PBC session overlap");
999#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001001 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002#endif /* CONFIG_P2P */
1003
1004#ifdef CONFIG_WPS
1005 wpas_wps_cancel(wpa_s);
1006#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001007 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008 }
1009
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001010 wpa_msg(wpa_s, MSG_DEBUG,
1011 "Considering connect request: reassociate: %d selected: "
1012 MACSTR " bssid: " MACSTR " pending: " MACSTR
1013 " wpa_state: %s ssid=%p current_ssid=%p",
1014 wpa_s->reassociate, MAC2STR(selected->bssid),
1015 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1016 wpa_supplicant_state_txt(wpa_s->wpa_state),
1017 ssid, wpa_s->current_ssid);
1018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 /*
1020 * Do not trigger new association unless the BSSID has changed or if
1021 * reassociation is requested. If we are in process of associating with
1022 * the selected BSSID, do not trigger new attempt.
1023 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1026 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1027 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001028 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1029 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1030 0) ||
1031 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1032 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1034 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001035 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001037 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1038 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 wpa_supplicant_associate(wpa_s, selected, ssid);
1040 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001041 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1042 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001045 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046}
1047
1048
1049static struct wpa_ssid *
1050wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1051{
1052 int prio;
1053 struct wpa_ssid *ssid;
1054
1055 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1056 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1057 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001058 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059 continue;
1060 if (ssid->mode == IEEE80211_MODE_IBSS ||
1061 ssid->mode == IEEE80211_MODE_AP)
1062 return ssid;
1063 }
1064 }
1065 return NULL;
1066}
1067
1068
1069/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1070 * on BSS added and BSS changed events */
1071static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001072 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001074 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075
1076 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1077 return;
1078
Jouni Malinen87fd2792011-05-16 18:35:42 +03001079 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081
Jouni Malinen87fd2792011-05-16 18:35:42 +03001082 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 if (ssid == NULL)
1084 continue;
1085
Jouni Malinen87fd2792011-05-16 18:35:42 +03001086 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 if (rsn == NULL)
1088 continue;
1089
Jouni Malinen87fd2792011-05-16 18:35:42 +03001090 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 }
1092
1093}
1094
1095
1096static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1097 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001098 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001100 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 int min_diff;
1102
1103 if (wpa_s->reassociate)
1104 return 1; /* explicit request to reassociate */
1105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1106 return 1; /* we are not associated; continue */
1107 if (wpa_s->current_ssid == NULL)
1108 return 1; /* unknown current SSID */
1109 if (wpa_s->current_ssid != ssid)
1110 return 1; /* different network block */
1111
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001112 if (wpas_driver_bss_selection(wpa_s))
1113 return 0; /* Driver-based roaming */
1114
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001115 if (wpa_s->current_ssid->ssid)
1116 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1117 wpa_s->current_ssid->ssid,
1118 wpa_s->current_ssid->ssid_len);
1119 if (!current_bss)
1120 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121
1122 if (!current_bss)
1123 return 1; /* current BSS not seen in scan results */
1124
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001125 if (current_bss == selected)
1126 return 0;
1127
1128 if (selected->last_update_idx > current_bss->last_update_idx)
1129 return 1; /* current BSS not seen in the last scan */
1130
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001131#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1133 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1134 MAC2STR(current_bss->bssid), current_bss->level);
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1136 MAC2STR(selected->bssid), selected->level);
1137
1138 if (wpa_s->current_ssid->bssid_set &&
1139 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1140 0) {
1141 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1142 "has preferred BSSID");
1143 return 1;
1144 }
1145
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001146 if (current_bss->level < 0 && current_bss->level > selected->level) {
1147 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1148 "signal level");
1149 return 0;
1150 }
1151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 min_diff = 2;
1153 if (current_bss->level < 0) {
1154 if (current_bss->level < -85)
1155 min_diff = 1;
1156 else if (current_bss->level < -80)
1157 min_diff = 2;
1158 else if (current_bss->level < -75)
1159 min_diff = 3;
1160 else if (current_bss->level < -70)
1161 min_diff = 4;
1162 else
1163 min_diff = 5;
1164 }
1165 if (abs(current_bss->level - selected->level) < min_diff) {
1166 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1167 "in signal level");
1168 return 0;
1169 }
1170
1171 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001172#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001173 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001174#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175}
1176
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001177
Jouni Malinen89ca7022012-09-14 13:03:12 -07001178/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001179 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001180static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001181 union wpa_event_data *data,
1182 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 struct wpa_scan_results *scan_res;
1185 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001186#ifndef CONFIG_NO_RANDOM_POOL
1187 size_t i, num;
1188#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189
1190#ifdef CONFIG_AP
1191 if (wpa_s->ap_iface)
1192 ap = 1;
1193#endif /* CONFIG_AP */
1194
1195 wpa_supplicant_notify_scanning(wpa_s, 0);
1196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001198 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001199 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001200 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1201 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001202 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001203 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1204 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1205 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001206 wpa_s->sta_scan_pending = 1;
1207 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001208 return -1;
1209 }
1210 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001211 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001212#endif /* CONFIG_P2P */
1213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1215 data ? &data->scan_info :
1216 NULL, 1);
1217 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001218 if (wpa_s->conf->ap_scan == 2 || ap ||
1219 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001221 if (!own_request)
1222 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1224 "scanning again");
1225 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1226 return -1;
1227 }
1228
1229#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 num = scan_res->num;
1231 if (num > 10)
1232 num = 10;
1233 for (i = 0; i < num; i++) {
1234 u8 buf[5];
1235 struct wpa_scan_res *res = scan_res->res[i];
1236 buf[0] = res->bssid[5];
1237 buf[1] = res->qual & 0xff;
1238 buf[2] = res->noise & 0xff;
1239 buf[3] = res->level & 0xff;
1240 buf[4] = res->tsf & 0xff;
1241 random_add_randomness(buf, sizeof(buf));
1242 }
1243#endif /* CONFIG_NO_RANDOM_POOL */
1244
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001245 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1247 struct wpa_scan_results *scan_res);
1248
1249 scan_res_handler = wpa_s->scan_res_handler;
1250 wpa_s->scan_res_handler = NULL;
1251 scan_res_handler(wpa_s, scan_res);
1252
1253 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001254 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 }
1256
1257 if (ap) {
1258 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1259#ifdef CONFIG_AP
1260 if (wpa_s->ap_iface->scan_cb)
1261 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1262#endif /* CONFIG_AP */
1263 wpa_scan_results_free(scan_res);
1264 return 0;
1265 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001266
Dmitry Shmidt04949592012-07-19 12:16:46 -07001267 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1268 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1269 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270
1271 wpas_notify_scan_done(wpa_s, 1);
1272
Dmitry Shmidt04949592012-07-19 12:16:46 -07001273 if (sme_proc_obss_scan(wpa_s) > 0) {
1274 wpa_scan_results_free(scan_res);
1275 return 0;
1276 }
1277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1279 wpa_scan_results_free(scan_res);
1280 return 0;
1281 }
1282
Dmitry Shmidt04949592012-07-19 12:16:46 -07001283 if (autoscan_notify_scan(wpa_s, scan_res)) {
1284 wpa_scan_results_free(scan_res);
1285 return 0;
1286 }
1287
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 if (wpa_s->disconnected) {
1289 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1290 wpa_scan_results_free(scan_res);
1291 return 0;
1292 }
1293
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001294 if (!wpas_driver_bss_selection(wpa_s) &&
1295 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296 wpa_scan_results_free(scan_res);
1297 return 0;
1298 }
1299
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300 wpas_wps_update_ap_info(wpa_s, scan_res);
1301
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001302 wpa_scan_results_free(scan_res);
1303
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001304 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001305}
1306
1307
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001308static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001309 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001310{
1311 struct wpa_bss *selected;
1312 struct wpa_ssid *ssid = NULL;
1313
1314 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315
1316 if (selected) {
1317 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001318 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001319 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001320 if (new_scan)
1321 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001323 }
1324
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001325 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001326 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001327 return -1;
1328 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001329 if (new_scan)
1330 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001331 /*
1332 * Do not notify other virtual radios of scan results since we do not
1333 * want them to start other associations at the same time.
1334 */
1335 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1338 ssid = wpa_supplicant_pick_new_network(wpa_s);
1339 if (ssid) {
1340 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1341 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001342 if (new_scan)
1343 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001344 } else if (own_request) {
1345 /*
1346 * No SSID found. If SCAN results are as a result of
1347 * own scan request and not due to a scan request on
1348 * another shared interface, try another scan.
1349 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 int timeout_sec = wpa_s->scan_interval;
1351 int timeout_usec = 0;
1352#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001353 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1354 return 0;
1355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 if (wpa_s->p2p_in_provisioning) {
1357 /*
1358 * Use shorter wait during P2P Provisioning
1359 * state to speed up group formation.
1360 */
1361 timeout_sec = 0;
1362 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001363 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1364 timeout_usec);
1365 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001366 }
1367#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001368#ifdef CONFIG_INTERWORKING
1369 if (wpa_s->conf->auto_interworking &&
1370 wpa_s->conf->interworking &&
1371 wpa_s->conf->cred) {
1372 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1373 "start ANQP fetch since no matching "
1374 "networks found");
1375 wpa_s->network_select = 1;
1376 wpa_s->auto_network_select = 1;
1377 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001378 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001379 }
1380#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001381 if (wpa_supplicant_req_sched_scan(wpa_s))
1382 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1383 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384 }
1385 }
1386 return 0;
1387}
1388
1389
1390static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1391 union wpa_event_data *data)
1392{
1393 const char *rn, *rn2;
1394 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001395
1396 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001397 /*
1398 * If no scan results could be fetched, then no need to
1399 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001400 * this scan. Similarly, if scan results started a new operation on this
1401 * interface, do not notify other interfaces to avoid concurrent
1402 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403 */
1404 return;
1405 }
1406
1407 /*
1408 * Check other interfaces to see if they have the same radio-name. If
1409 * so, they get updated with this same scan info.
1410 */
1411 if (!wpa_s->driver->get_radio_name)
1412 return;
1413
1414 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1415 if (rn == NULL || rn[0] == '\0')
1416 return;
1417
1418 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1419 "sharing same radio (%s) in event_scan_results", rn);
1420
1421 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1422 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1423 continue;
1424
1425 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1426 if (rn2 && os_strcmp(rn, rn2) == 0) {
1427 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1428 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001429 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430 }
1431 }
1432}
1433
1434#endif /* CONFIG_NO_SCAN_PROCESSING */
1435
1436
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001437int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1438{
1439#ifdef CONFIG_NO_SCAN_PROCESSING
1440 return -1;
1441#else /* CONFIG_NO_SCAN_PROCESSING */
1442 struct os_time now;
1443
1444 if (wpa_s->last_scan_res_used <= 0)
1445 return -1;
1446
1447 os_get_time(&now);
1448 if (now.sec - wpa_s->last_scan.sec > 5) {
1449 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1450 return -1;
1451 }
1452
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001453 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001454#endif /* CONFIG_NO_SCAN_PROCESSING */
1455}
1456
Dmitry Shmidt04949592012-07-19 12:16:46 -07001457#ifdef CONFIG_WNM
1458
1459static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1460{
1461 struct wpa_supplicant *wpa_s = eloop_ctx;
1462
1463 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1464 return;
1465
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001466 if (!wpa_s->no_keep_alive) {
1467 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1468 MAC2STR(wpa_s->bssid));
1469 /* TODO: could skip this if normal data traffic has been sent */
1470 /* TODO: Consider using some more appropriate data frame for
1471 * this */
1472 if (wpa_s->l2)
1473 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1474 (u8 *) "", 0);
1475 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001476
1477#ifdef CONFIG_SME
1478 if (wpa_s->sme.bss_max_idle_period) {
1479 unsigned int msec;
1480 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1481 if (msec > 100)
1482 msec -= 100;
1483 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1484 wnm_bss_keep_alive, wpa_s, NULL);
1485 }
1486#endif /* CONFIG_SME */
1487}
1488
1489
1490static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1491 const u8 *ies, size_t ies_len)
1492{
1493 struct ieee802_11_elems elems;
1494
1495 if (ies == NULL)
1496 return;
1497
1498 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1499 return;
1500
1501#ifdef CONFIG_SME
1502 if (elems.bss_max_idle_period) {
1503 unsigned int msec;
1504 wpa_s->sme.bss_max_idle_period =
1505 WPA_GET_LE16(elems.bss_max_idle_period);
1506 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1507 "TU)%s", wpa_s->sme.bss_max_idle_period,
1508 (elems.bss_max_idle_period[2] & 0x01) ?
1509 " (protected keep-live required)" : "");
1510 if (wpa_s->sme.bss_max_idle_period == 0)
1511 wpa_s->sme.bss_max_idle_period = 1;
1512 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1513 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1514 /* msec times 1000 */
1515 msec = wpa_s->sme.bss_max_idle_period * 1024;
1516 if (msec > 100)
1517 msec -= 100;
1518 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1519 wnm_bss_keep_alive, wpa_s,
1520 NULL);
1521 }
1522 }
1523#endif /* CONFIG_SME */
1524}
1525
1526#endif /* CONFIG_WNM */
1527
1528
1529void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1530{
1531#ifdef CONFIG_WNM
1532 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1533#endif /* CONFIG_WNM */
1534}
1535
1536
Dmitry Shmidt051af732013-10-22 13:52:46 -07001537#ifdef CONFIG_INTERWORKING
1538
1539static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1540 size_t len)
1541{
1542 int res;
1543
1544 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1545 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1546 if (res) {
1547 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1548 }
1549
1550 return res;
1551}
1552
1553
1554static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1555 const u8 *ies, size_t ies_len)
1556{
1557 struct ieee802_11_elems elems;
1558
1559 if (ies == NULL)
1560 return;
1561
1562 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1563 return;
1564
1565 if (elems.qos_map_set) {
1566 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1567 elems.qos_map_set_len);
1568 }
1569}
1570
1571#endif /* CONFIG_INTERWORKING */
1572
1573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001574static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1575 union wpa_event_data *data)
1576{
1577 int l, len, found = 0, wpa_found, rsn_found;
1578 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001579#ifdef CONFIG_IEEE80211R
1580 u8 bssid[ETH_ALEN];
1581#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001582
1583 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1584 if (data->assoc_info.req_ies)
1585 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1586 data->assoc_info.req_ies_len);
1587 if (data->assoc_info.resp_ies) {
1588 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1589 data->assoc_info.resp_ies_len);
1590#ifdef CONFIG_TDLS
1591 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1592 data->assoc_info.resp_ies_len);
1593#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001594#ifdef CONFIG_WNM
1595 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1596 data->assoc_info.resp_ies_len);
1597#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001598#ifdef CONFIG_INTERWORKING
1599 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1600 data->assoc_info.resp_ies_len);
1601#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602 }
1603 if (data->assoc_info.beacon_ies)
1604 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1605 data->assoc_info.beacon_ies,
1606 data->assoc_info.beacon_ies_len);
1607 if (data->assoc_info.freq)
1608 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1609 data->assoc_info.freq);
1610
1611 p = data->assoc_info.req_ies;
1612 l = data->assoc_info.req_ies_len;
1613
1614 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1615 while (p && l >= 2) {
1616 len = p[1] + 2;
1617 if (len > l) {
1618 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1619 p, l);
1620 break;
1621 }
1622 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1623 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1624 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1625 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1626 break;
1627 found = 1;
1628 wpa_find_assoc_pmkid(wpa_s);
1629 break;
1630 }
1631 l -= len;
1632 p += len;
1633 }
1634 if (!found && data->assoc_info.req_ies)
1635 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1636
1637#ifdef CONFIG_IEEE80211R
1638#ifdef CONFIG_SME
1639 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1641 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1642 data->assoc_info.resp_ies,
1643 data->assoc_info.resp_ies_len,
1644 bssid) < 0) {
1645 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1646 "Reassociation Response failed");
1647 wpa_supplicant_deauthenticate(
1648 wpa_s, WLAN_REASON_INVALID_IE);
1649 return -1;
1650 }
1651 }
1652
1653 p = data->assoc_info.resp_ies;
1654 l = data->assoc_info.resp_ies_len;
1655
1656#ifdef CONFIG_WPS_STRICT
1657 if (p && wpa_s->current_ssid &&
1658 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1659 struct wpabuf *wps;
1660 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1661 if (wps == NULL) {
1662 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1663 "include WPS IE in (Re)Association Response");
1664 return -1;
1665 }
1666
1667 if (wps_validate_assoc_resp(wps) < 0) {
1668 wpabuf_free(wps);
1669 wpa_supplicant_deauthenticate(
1670 wpa_s, WLAN_REASON_INVALID_IE);
1671 return -1;
1672 }
1673 wpabuf_free(wps);
1674 }
1675#endif /* CONFIG_WPS_STRICT */
1676
1677 /* Go through the IEs and make a copy of the MDIE, if present. */
1678 while (p && l >= 2) {
1679 len = p[1] + 2;
1680 if (len > l) {
1681 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1682 p, l);
1683 break;
1684 }
1685 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1686 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1687 wpa_s->sme.ft_used = 1;
1688 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1689 MOBILITY_DOMAIN_ID_LEN);
1690 break;
1691 }
1692 l -= len;
1693 p += len;
1694 }
1695#endif /* CONFIG_SME */
1696
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001697 /* Process FT when SME is in the driver */
1698 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1699 wpa_ft_is_completed(wpa_s->wpa)) {
1700 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1701 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1702 data->assoc_info.resp_ies,
1703 data->assoc_info.resp_ies_len,
1704 bssid) < 0) {
1705 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1706 "Reassociation Response failed");
1707 wpa_supplicant_deauthenticate(
1708 wpa_s, WLAN_REASON_INVALID_IE);
1709 return -1;
1710 }
1711 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1712 }
1713
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1715 data->assoc_info.resp_ies_len);
1716#endif /* CONFIG_IEEE80211R */
1717
1718 /* WPA/RSN IE from Beacon/ProbeResp */
1719 p = data->assoc_info.beacon_ies;
1720 l = data->assoc_info.beacon_ies_len;
1721
1722 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1723 */
1724 wpa_found = rsn_found = 0;
1725 while (p && l >= 2) {
1726 len = p[1] + 2;
1727 if (len > l) {
1728 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1729 p, l);
1730 break;
1731 }
1732 if (!wpa_found &&
1733 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1734 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1735 wpa_found = 1;
1736 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1737 }
1738
1739 if (!rsn_found &&
1740 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1741 rsn_found = 1;
1742 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1743 }
1744
1745 l -= len;
1746 p += len;
1747 }
1748
1749 if (!wpa_found && data->assoc_info.beacon_ies)
1750 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1751 if (!rsn_found && data->assoc_info.beacon_ies)
1752 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1753 if (wpa_found || rsn_found)
1754 wpa_s->ap_ies_from_associnfo = 1;
1755
Jouni Malinen87fd2792011-05-16 18:35:42 +03001756 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1757 wpa_s->assoc_freq != data->assoc_info.freq) {
1758 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1759 "%u to %u MHz",
1760 wpa_s->assoc_freq, data->assoc_info.freq);
1761 wpa_supplicant_update_scan_results(wpa_s);
1762 }
1763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 wpa_s->assoc_freq = data->assoc_info.freq;
1765
1766 return 0;
1767}
1768
1769
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001770static struct wpa_bss * wpa_supplicant_get_new_bss(
1771 struct wpa_supplicant *wpa_s, const u8 *bssid)
1772{
1773 struct wpa_bss *bss = NULL;
1774 struct wpa_ssid *ssid = wpa_s->current_ssid;
1775
1776 if (ssid->ssid_len > 0)
1777 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1778 if (!bss)
1779 bss = wpa_bss_get_bssid(wpa_s, bssid);
1780
1781 return bss;
1782}
1783
1784
1785static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1786{
1787 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1788
1789 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1790 return -1;
1791
1792 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1793 return 0;
1794
1795 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1796 WPA_IE_VENDOR_TYPE);
1797 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1798
1799 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1800 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1801 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1802 bss_rsn ? 2 + bss_rsn[1] : 0))
1803 return -1;
1804
1805 return 0;
1806}
1807
1808
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1810 union wpa_event_data *data)
1811{
1812 u8 bssid[ETH_ALEN];
1813 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001814
1815#ifdef CONFIG_AP
1816 if (wpa_s->ap_iface) {
1817 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1818 data->assoc_info.addr,
1819 data->assoc_info.req_ies,
1820 data->assoc_info.req_ies_len,
1821 data->assoc_info.reassoc);
1822 return;
1823 }
1824#endif /* CONFIG_AP */
1825
1826 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1827 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1828 return;
1829
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001830 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1831 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001832 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001833 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1834 return;
1835 }
1836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001838 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1840 MACSTR, MAC2STR(bssid));
1841 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001842 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1843 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001844 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845
1846 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1847 wpa_clear_keys(wpa_s, bssid);
1848 }
1849 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001850 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1852 return;
1853 }
1854 if (wpa_s->current_ssid) {
1855 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001856
1857 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1858 if (!bss) {
1859 wpa_supplicant_update_scan_results(wpa_s);
1860
1861 /* Get the BSS from the new scan results */
1862 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1863 }
1864
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 if (bss)
1866 wpa_s->current_bss = bss;
1867 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001868
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001869#ifdef ANDROID
1870 if (wpa_s->conf->ap_scan == 1) {
1871#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001872 if (wpa_s->conf->ap_scan == 1 &&
1873 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001874#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001875 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1876 wpa_msg(wpa_s, MSG_WARNING,
1877 "WPA/RSN IEs not updated");
1878 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001879 }
1880
1881#ifdef CONFIG_SME
1882 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1883 wpa_s->sme.prev_bssid_set = 1;
1884#endif /* CONFIG_SME */
1885
1886 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1887 if (wpa_s->current_ssid) {
1888 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1889 * initialized before association, but for other modes,
1890 * initialize PC/SC here, if the current configuration needs
1891 * smartcard or SIM/USIM. */
1892 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1893 }
1894 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1895 if (wpa_s->l2)
1896 l2_packet_notify_auth_start(wpa_s->l2);
1897
1898 /*
1899 * Set portEnabled first to FALSE in order to get EAP state machine out
1900 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1901 * state machine may transit to AUTHENTICATING state based on obsolete
1902 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1903 * AUTHENTICATED without ever giving chance to EAP state machine to
1904 * reset the state.
1905 */
1906 if (!ft_completed) {
1907 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1908 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1909 }
1910 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1911 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1912 /* 802.1X::portControl = Auto */
1913 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1914 wpa_s->eapol_received = 0;
1915 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1916 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1917 (wpa_s->current_ssid &&
1918 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001919 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1920 (wpa_s->drv_flags &
1921 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1922 /*
1923 * Set the key after having received joined-IBSS event
1924 * from the driver.
1925 */
1926 wpa_supplicant_set_wpa_none_key(wpa_s,
1927 wpa_s->current_ssid);
1928 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001929 wpa_supplicant_cancel_auth_timeout(wpa_s);
1930 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1931 } else if (!ft_completed) {
1932 /* Timeout for receiving the first EAPOL packet */
1933 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1934 }
1935 wpa_supplicant_cancel_scan(wpa_s);
1936
1937 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1938 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1939 /*
1940 * We are done; the driver will take care of RSN 4-way
1941 * handshake.
1942 */
1943 wpa_supplicant_cancel_auth_timeout(wpa_s);
1944 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1945 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1946 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1947 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1948 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1949 /*
1950 * The driver will take care of RSN 4-way handshake, so we need
1951 * to allow EAPOL supplicant to complete its work without
1952 * waiting for WPA supplicant.
1953 */
1954 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1955 } else if (ft_completed) {
1956 /*
1957 * FT protocol completed - make sure EAPOL state machine ends
1958 * up in authenticated.
1959 */
1960 wpa_supplicant_cancel_auth_timeout(wpa_s);
1961 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1962 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1963 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1964 }
1965
Jouni Malinena05074c2012-12-21 21:35:35 +02001966 wpa_s->last_eapol_matches_bssid = 0;
1967
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968 if (wpa_s->pending_eapol_rx) {
1969 struct os_time now, age;
1970 os_get_time(&now);
1971 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1972 if (age.sec == 0 && age.usec < 100000 &&
1973 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1974 0) {
1975 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1976 "frame that was received just before "
1977 "association notification");
1978 wpa_supplicant_rx_eapol(
1979 wpa_s, wpa_s->pending_eapol_rx_src,
1980 wpabuf_head(wpa_s->pending_eapol_rx),
1981 wpabuf_len(wpa_s->pending_eapol_rx));
1982 }
1983 wpabuf_free(wpa_s->pending_eapol_rx);
1984 wpa_s->pending_eapol_rx = NULL;
1985 }
1986
1987 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1988 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001989 wpa_s->current_ssid &&
1990 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001991 /* Set static WEP keys again */
1992 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1993 }
1994
1995#ifdef CONFIG_IBSS_RSN
1996 if (wpa_s->current_ssid &&
1997 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1998 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1999 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2000 wpa_s->ibss_rsn == NULL) {
2001 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2002 if (!wpa_s->ibss_rsn) {
2003 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2004 wpa_supplicant_deauthenticate(
2005 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2006 return;
2007 }
2008
2009 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2010 }
2011#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002012
2013 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014}
2015
2016
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002017static int disconnect_reason_recoverable(u16 reason_code)
2018{
2019 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2020 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2021 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2022}
2023
2024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002026 u16 reason_code,
2027 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002028{
2029 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002030
2031 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2032 /*
2033 * At least Host AP driver and a Prism3 card seemed to be
2034 * generating streams of disconnected events when configuring
2035 * IBSS for WPA-None. Ignore them for now.
2036 */
2037 return;
2038 }
2039
2040 bssid = wpa_s->bssid;
2041 if (is_zero_ether_addr(bssid))
2042 bssid = wpa_s->pending_bssid;
2043
2044 if (!is_zero_ether_addr(bssid) ||
2045 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2046 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2047 " reason=%d%s",
2048 MAC2STR(bssid), reason_code,
2049 locally_generated ? " locally_generated=1" : "");
2050 }
2051}
2052
2053
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002054static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2055 int locally_generated)
2056{
2057 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2058 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2059 return 0; /* Not in 4-way handshake with PSK */
2060
2061 /*
2062 * It looks like connection was lost while trying to go through PSK
2063 * 4-way handshake. Filter out known disconnection cases that are caused
2064 * by something else than PSK mismatch to avoid confusing reports.
2065 */
2066
2067 if (locally_generated) {
2068 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2069 return 0;
2070 }
2071
2072 return 1;
2073}
2074
2075
Jouni Malinen2b89da82012-08-31 22:04:41 +03002076static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2077 u16 reason_code,
2078 int locally_generated)
2079{
2080 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081 int authenticating;
2082 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002083 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002084#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002085 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002086#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002087 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088
2089 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2090 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2091
2092 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2093 /*
2094 * At least Host AP driver and a Prism3 card seemed to be
2095 * generating streams of disconnected events when configuring
2096 * IBSS for WPA-None. Ignore them for now.
2097 */
2098 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2099 "IBSS/WPA-None mode");
2100 return;
2101 }
2102
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002103 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002104 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2105 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002106 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2107 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002108 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002109 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002110 if (!wpa_s->disconnected &&
2111 (!wpa_s->auto_reconnect_disabled ||
2112 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002113 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2114 "reconnect (wps=%d wpa_state=%d)",
2115 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2116 wpa_s->wpa_state);
2117 if (wpa_s->wpa_state == WPA_COMPLETED &&
2118 wpa_s->current_ssid &&
2119 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002120 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002121 disconnect_reason_recoverable(reason_code)) {
2122 /*
2123 * It looks like the AP has dropped association with
2124 * us, but could allow us to get back in. Try to
2125 * reconnect to the same BSS without full scan to save
2126 * time for some common cases.
2127 */
2128 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002129#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002130 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002131#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002132 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002133#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002134 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002135#else
2136 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2137#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002138 else
2139 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2140 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002142 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143 "try to re-connect");
2144 wpa_s->reassociate = 0;
2145 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002146 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002147 }
2148 bssid = wpa_s->bssid;
2149 if (is_zero_ether_addr(bssid))
2150 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002151 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2152 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002154 if (locally_generated)
2155 wpa_s->disconnect_reason = -reason_code;
2156 else
2157 wpa_s->disconnect_reason = reason_code;
2158 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002159 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2160 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2161 wpa_s->keys_cleared = 0;
2162 wpa_clear_keys(wpa_s, wpa_s->bssid);
2163 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002164 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002165 wpa_supplicant_mark_disassoc(wpa_s);
2166
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002167 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002169 wpa_s->current_ssid = last_ssid;
2170 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002171
2172 if (fast_reconnect) {
2173#ifndef CONFIG_NO_SCAN_PROCESSING
2174 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2175 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2176 fast_reconnect_ssid) < 0) {
2177 /* Recover through full scan */
2178 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2179 }
2180#endif /* CONFIG_NO_SCAN_PROCESSING */
2181 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002182}
2183
2184
2185#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002186void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002187{
2188 struct wpa_supplicant *wpa_s = eloop_ctx;
2189
2190 if (!wpa_s->pending_mic_error_report)
2191 return;
2192
2193 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2194 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2195 wpa_s->pending_mic_error_report = 0;
2196}
2197#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2198
2199
2200static void
2201wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2202 union wpa_event_data *data)
2203{
2204 int pairwise;
2205 struct os_time t;
2206
2207 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2208 pairwise = (data && data->michael_mic_failure.unicast);
2209 os_get_time(&t);
2210 if ((wpa_s->last_michael_mic_error &&
2211 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2212 wpa_s->pending_mic_error_report) {
2213 if (wpa_s->pending_mic_error_report) {
2214 /*
2215 * Send the pending MIC error report immediately since
2216 * we are going to start countermeasures and AP better
2217 * do the same.
2218 */
2219 wpa_sm_key_request(wpa_s->wpa, 1,
2220 wpa_s->pending_mic_error_pairwise);
2221 }
2222
2223 /* Send the new MIC error report immediately since we are going
2224 * to start countermeasures and AP better do the same.
2225 */
2226 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2227
2228 /* initialize countermeasures */
2229 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002230
2231 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2232
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2234
2235 /*
2236 * Need to wait for completion of request frame. We do not get
2237 * any callback for the message completion, so just wait a
2238 * short while and hope for the best. */
2239 os_sleep(0, 10000);
2240
2241 wpa_drv_set_countermeasures(wpa_s, 1);
2242 wpa_supplicant_deauthenticate(wpa_s,
2243 WLAN_REASON_MICHAEL_MIC_FAILURE);
2244 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2245 wpa_s, NULL);
2246 eloop_register_timeout(60, 0,
2247 wpa_supplicant_stop_countermeasures,
2248 wpa_s, NULL);
2249 /* TODO: mark the AP rejected for 60 second. STA is
2250 * allowed to associate with another AP.. */
2251 } else {
2252#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2253 if (wpa_s->mic_errors_seen) {
2254 /*
2255 * Reduce the effectiveness of Michael MIC error
2256 * reports as a means for attacking against TKIP if
2257 * more than one MIC failure is noticed with the same
2258 * PTK. We delay the transmission of the reports by a
2259 * random time between 0 and 60 seconds in order to
2260 * force the attacker wait 60 seconds before getting
2261 * the information on whether a frame resulted in a MIC
2262 * failure.
2263 */
2264 u8 rval[4];
2265 int sec;
2266
2267 if (os_get_random(rval, sizeof(rval)) < 0)
2268 sec = os_random() % 60;
2269 else
2270 sec = WPA_GET_BE32(rval) % 60;
2271 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2272 "report %d seconds", sec);
2273 wpa_s->pending_mic_error_report = 1;
2274 wpa_s->pending_mic_error_pairwise = pairwise;
2275 eloop_cancel_timeout(
2276 wpa_supplicant_delayed_mic_error_report,
2277 wpa_s, NULL);
2278 eloop_register_timeout(
2279 sec, os_random() % 1000000,
2280 wpa_supplicant_delayed_mic_error_report,
2281 wpa_s, NULL);
2282 } else {
2283 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2284 }
2285#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2286 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2287#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2288 }
2289 wpa_s->last_michael_mic_error = t.sec;
2290 wpa_s->mic_errors_seen++;
2291}
2292
2293
2294#ifdef CONFIG_TERMINATE_ONLASTIF
2295static int any_interfaces(struct wpa_supplicant *head)
2296{
2297 struct wpa_supplicant *wpa_s;
2298
2299 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2300 if (!wpa_s->interface_removed)
2301 return 1;
2302 return 0;
2303}
2304#endif /* CONFIG_TERMINATE_ONLASTIF */
2305
2306
2307static void
2308wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2309 union wpa_event_data *data)
2310{
2311 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2312 return;
2313
2314 switch (data->interface_status.ievent) {
2315 case EVENT_INTERFACE_ADDED:
2316 if (!wpa_s->interface_removed)
2317 break;
2318 wpa_s->interface_removed = 0;
2319 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2320 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2321 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2322 "driver after interface was added");
2323 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002324 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 break;
2326 case EVENT_INTERFACE_REMOVED:
2327 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2328 wpa_s->interface_removed = 1;
2329 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002330 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 l2_packet_deinit(wpa_s->l2);
2332 wpa_s->l2 = NULL;
2333#ifdef CONFIG_IBSS_RSN
2334 ibss_rsn_deinit(wpa_s->ibss_rsn);
2335 wpa_s->ibss_rsn = NULL;
2336#endif /* CONFIG_IBSS_RSN */
2337#ifdef CONFIG_TERMINATE_ONLASTIF
2338 /* check if last interface */
2339 if (!any_interfaces(wpa_s->global->ifaces))
2340 eloop_terminate();
2341#endif /* CONFIG_TERMINATE_ONLASTIF */
2342 break;
2343 }
2344}
2345
2346
2347#ifdef CONFIG_PEERKEY
2348static void
2349wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2350 union wpa_event_data *data)
2351{
2352 if (data == NULL)
2353 return;
2354 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2355}
2356#endif /* CONFIG_PEERKEY */
2357
2358
2359#ifdef CONFIG_TDLS
2360static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2361 union wpa_event_data *data)
2362{
2363 if (data == NULL)
2364 return;
2365 switch (data->tdls.oper) {
2366 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002367 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2368 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2369 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2370 else
2371 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002372 break;
2373 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002374 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2375 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2376 data->tdls.reason_code);
2377 else
2378 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2379 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380 break;
2381 }
2382}
2383#endif /* CONFIG_TDLS */
2384
2385
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002386#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002387static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2388 union wpa_event_data *data)
2389{
2390 if (data == NULL)
2391 return;
2392 switch (data->wnm.oper) {
2393 case WNM_OPER_SLEEP:
2394 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2395 "(action=%d, intval=%d)",
2396 data->wnm.sleep_action, data->wnm.sleep_intval);
2397 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002398 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002399 break;
2400 }
2401}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002402#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002403
2404
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002405#ifdef CONFIG_IEEE80211R
2406static void
2407wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2408 union wpa_event_data *data)
2409{
2410 if (data == NULL)
2411 return;
2412
2413 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2414 data->ft_ies.ies_len,
2415 data->ft_ies.ft_action,
2416 data->ft_ies.target_ap,
2417 data->ft_ies.ric_ies,
2418 data->ft_ies.ric_ies_len) < 0) {
2419 /* TODO: prevent MLME/driver from trying to associate? */
2420 }
2421}
2422#endif /* CONFIG_IEEE80211R */
2423
2424
2425#ifdef CONFIG_IBSS_RSN
2426static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2427 union wpa_event_data *data)
2428{
2429 struct wpa_ssid *ssid;
2430 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2431 return;
2432 if (data == NULL)
2433 return;
2434 ssid = wpa_s->current_ssid;
2435 if (ssid == NULL)
2436 return;
2437 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2438 return;
2439
2440 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2441}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002442
2443
2444static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2445 union wpa_event_data *data)
2446{
2447 struct wpa_ssid *ssid = wpa_s->current_ssid;
2448
2449 if (ssid == NULL)
2450 return;
2451
2452 /* check if the ssid is correctly configured as IBSS/RSN */
2453 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2454 return;
2455
2456 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2457 data->rx_mgmt.frame_len);
2458}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459#endif /* CONFIG_IBSS_RSN */
2460
2461
2462#ifdef CONFIG_IEEE80211R
2463static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2464 size_t len)
2465{
2466 const u8 *sta_addr, *target_ap_addr;
2467 u16 status;
2468
2469 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2470 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2471 return; /* only SME case supported for now */
2472 if (len < 1 + 2 * ETH_ALEN + 2)
2473 return;
2474 if (data[0] != 2)
2475 return; /* Only FT Action Response is supported for now */
2476 sta_addr = data + 1;
2477 target_ap_addr = data + 1 + ETH_ALEN;
2478 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2479 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2480 MACSTR " TargetAP " MACSTR " status %u",
2481 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2482
2483 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2484 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2485 " in FT Action Response", MAC2STR(sta_addr));
2486 return;
2487 }
2488
2489 if (status) {
2490 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2491 "failure (status code %d)", status);
2492 /* TODO: report error to FT code(?) */
2493 return;
2494 }
2495
2496 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2497 len - (1 + 2 * ETH_ALEN + 2), 1,
2498 target_ap_addr, NULL, 0) < 0)
2499 return;
2500
2501#ifdef CONFIG_SME
2502 {
2503 struct wpa_bss *bss;
2504 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2505 if (bss)
2506 wpa_s->sme.freq = bss->freq;
2507 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2508 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2509 WLAN_AUTH_FT);
2510 }
2511#endif /* CONFIG_SME */
2512}
2513#endif /* CONFIG_IEEE80211R */
2514
2515
2516static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2517 struct unprot_deauth *e)
2518{
2519#ifdef CONFIG_IEEE80211W
2520 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2521 "dropped: " MACSTR " -> " MACSTR
2522 " (reason code %u)",
2523 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2524 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2525#endif /* CONFIG_IEEE80211W */
2526}
2527
2528
2529static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2530 struct unprot_disassoc *e)
2531{
2532#ifdef CONFIG_IEEE80211W
2533 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2534 "dropped: " MACSTR " -> " MACSTR
2535 " (reason code %u)",
2536 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2537 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2538#endif /* CONFIG_IEEE80211W */
2539}
2540
2541
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002542static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2543 u16 reason_code, int locally_generated,
2544 const u8 *ie, size_t ie_len, int deauth)
2545{
2546#ifdef CONFIG_AP
2547 if (wpa_s->ap_iface && addr) {
2548 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2549 return;
2550 }
2551
2552 if (wpa_s->ap_iface) {
2553 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2554 return;
2555 }
2556#endif /* CONFIG_AP */
2557
2558 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2559
2560 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2561 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2562 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2563 eapol_sm_failed(wpa_s->eapol)))
2564 wpas_auth_failed(wpa_s);
2565
2566#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002567 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002568 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2569 locally_generated) > 0) {
2570 /*
2571 * The interface was removed, so cannot continue
2572 * processing any additional operations after this.
2573 */
2574 return;
2575 }
2576 }
2577#endif /* CONFIG_P2P */
2578
2579 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2580 locally_generated);
2581}
2582
2583
2584static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2585 struct disassoc_info *info)
2586{
2587 u16 reason_code = 0;
2588 int locally_generated = 0;
2589 const u8 *addr = NULL;
2590 const u8 *ie = NULL;
2591 size_t ie_len = 0;
2592
2593 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2594
2595 if (info) {
2596 addr = info->addr;
2597 ie = info->ie;
2598 ie_len = info->ie_len;
2599 reason_code = info->reason_code;
2600 locally_generated = info->locally_generated;
2601 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2602 locally_generated ? " (locally generated)" : "");
2603 if (addr)
2604 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2605 MAC2STR(addr));
2606 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2607 ie, ie_len);
2608 }
2609
2610#ifdef CONFIG_AP
2611 if (wpa_s->ap_iface && info && info->addr) {
2612 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2613 return;
2614 }
2615
2616 if (wpa_s->ap_iface) {
2617 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2618 return;
2619 }
2620#endif /* CONFIG_AP */
2621
2622#ifdef CONFIG_P2P
2623 if (info) {
2624 wpas_p2p_disassoc_notif(
2625 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2626 locally_generated);
2627 }
2628#endif /* CONFIG_P2P */
2629
2630 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2631 sme_event_disassoc(wpa_s, info);
2632
2633 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2634 ie, ie_len, 0);
2635}
2636
2637
2638static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2639 struct deauth_info *info)
2640{
2641 u16 reason_code = 0;
2642 int locally_generated = 0;
2643 const u8 *addr = NULL;
2644 const u8 *ie = NULL;
2645 size_t ie_len = 0;
2646
2647 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2648
2649 if (info) {
2650 addr = info->addr;
2651 ie = info->ie;
2652 ie_len = info->ie_len;
2653 reason_code = info->reason_code;
2654 locally_generated = info->locally_generated;
2655 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2656 reason_code,
2657 locally_generated ? " (locally generated)" : "");
2658 if (addr) {
2659 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2660 MAC2STR(addr));
2661 }
2662 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2663 ie, ie_len);
2664 }
2665
2666 wpa_reset_ft_completed(wpa_s->wpa);
2667
2668 wpas_event_disconnect(wpa_s, addr, reason_code,
2669 locally_generated, ie, ie_len, 1);
2670}
2671
2672
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002673static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2674{
2675 const char *rn, *rn2;
2676 struct wpa_supplicant *ifs;
2677
2678 if (wpa_s->drv_priv == NULL)
2679 return; /* Ignore event during drv initialization */
2680
2681 free_hw_features(wpa_s);
2682 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2683 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2684
2685#ifdef CONFIG_P2P
2686 wpas_p2p_update_channel_list(wpa_s);
2687#endif /* CONFIG_P2P */
2688
2689 /*
2690 * Check other interfaces to see if they have the same radio-name. If
2691 * so, they get updated with this same hw mode info.
2692 */
2693 if (!wpa_s->driver->get_radio_name)
2694 return;
2695
2696 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2697 if (rn == NULL || rn[0] == '\0')
2698 return;
2699
2700 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2701 "sharing same radio (%s) in event_channel_list_change", rn);
2702
2703 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2704 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2705 continue;
2706
2707 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2708 if (rn2 && os_strcmp(rn, rn2) == 0) {
2709 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2710 ifs->ifname);
2711 free_hw_features(ifs);
2712 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2713 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2714 }
2715 }
2716}
2717
2718
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2720 union wpa_event_data *data)
2721{
2722 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002723
2724 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2725 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002726 event != EVENT_INTERFACE_STATUS &&
2727 event != EVENT_SCHED_SCAN_STOPPED) {
2728 wpa_dbg(wpa_s, MSG_DEBUG,
2729 "Ignore event %s (%d) while interface is disabled",
2730 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002731 return;
2732 }
2733
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002734#ifndef CONFIG_NO_STDOUT_DEBUG
2735{
2736 int level = MSG_DEBUG;
2737
Dmitry Shmidt04949592012-07-19 12:16:46 -07002738 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002739 const struct ieee80211_hdr *hdr;
2740 u16 fc;
2741 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2742 fc = le_to_host16(hdr->frame_control);
2743 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2744 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2745 level = MSG_EXCESSIVE;
2746 }
2747
2748 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2749 event_to_string(event), event);
2750}
2751#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002752
2753 switch (event) {
2754 case EVENT_AUTH:
2755 sme_event_auth(wpa_s, data);
2756 break;
2757 case EVENT_ASSOC:
2758 wpa_supplicant_event_assoc(wpa_s, data);
2759 break;
2760 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002761 wpas_event_disassoc(wpa_s,
2762 data ? &data->disassoc_info : NULL);
2763 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002765 wpas_event_deauth(wpa_s,
2766 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002767 break;
2768 case EVENT_MICHAEL_MIC_FAILURE:
2769 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2770 break;
2771#ifndef CONFIG_NO_SCAN_PROCESSING
2772 case EVENT_SCAN_RESULTS:
2773 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002774 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2775 wpa_s->wpa_state != WPA_ASSOCIATING)
2776 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002777 break;
2778#endif /* CONFIG_NO_SCAN_PROCESSING */
2779 case EVENT_ASSOCINFO:
2780 wpa_supplicant_event_associnfo(wpa_s, data);
2781 break;
2782 case EVENT_INTERFACE_STATUS:
2783 wpa_supplicant_event_interface_status(wpa_s, data);
2784 break;
2785 case EVENT_PMKID_CANDIDATE:
2786 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2787 break;
2788#ifdef CONFIG_PEERKEY
2789 case EVENT_STKSTART:
2790 wpa_supplicant_event_stkstart(wpa_s, data);
2791 break;
2792#endif /* CONFIG_PEERKEY */
2793#ifdef CONFIG_TDLS
2794 case EVENT_TDLS:
2795 wpa_supplicant_event_tdls(wpa_s, data);
2796 break;
2797#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002798#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002799 case EVENT_WNM:
2800 wpa_supplicant_event_wnm(wpa_s, data);
2801 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002802#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803#ifdef CONFIG_IEEE80211R
2804 case EVENT_FT_RESPONSE:
2805 wpa_supplicant_event_ft_response(wpa_s, data);
2806 break;
2807#endif /* CONFIG_IEEE80211R */
2808#ifdef CONFIG_IBSS_RSN
2809 case EVENT_IBSS_RSN_START:
2810 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2811 break;
2812#endif /* CONFIG_IBSS_RSN */
2813 case EVENT_ASSOC_REJECT:
2814 if (data->assoc_reject.bssid)
2815 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2816 "bssid=" MACSTR " status_code=%u",
2817 MAC2STR(data->assoc_reject.bssid),
2818 data->assoc_reject.status_code);
2819 else
2820 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2821 "status_code=%u",
2822 data->assoc_reject.status_code);
2823 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2824 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002825 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002826#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002827 if(!wpa_s->current_ssid) {
2828 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2829 break;
2830 }
2831 /* If assoc reject is reported by the driver, then avoid
2832 * waiting for the authentication timeout. Cancel the
2833 * authentication timeout and retry the assoc.
2834 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002835 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002836 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2837 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002838
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002839 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002840
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002841 /* Clear the states */
2842 wpa_sm_notify_disassoc(wpa_s->wpa);
2843 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2844
2845 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002846 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002847 const u8 *bl_bssid = data->assoc_reject.bssid;
2848 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2849 bl_bssid = wpa_s->pending_bssid;
2850 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002851 wpa_supplicant_req_scan(wpa_s, 0, 0);
2852 } else {
2853 wpa_supplicant_req_scan(wpa_s, 1, 0);
2854 }
2855 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002856 /* If we ASSOC_REJECT's hits threshold, disable the
2857 * network
2858 */
2859 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2860 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002861 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002862 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002863 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002864 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002865#else
2866 const u8 *bssid = data->assoc_reject.bssid;
2867 if (bssid == NULL || is_zero_ether_addr(bssid))
2868 bssid = wpa_s->pending_bssid;
2869 wpas_connection_failed(wpa_s, bssid);
2870 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002871#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002872 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 break;
2874 case EVENT_AUTH_TIMED_OUT:
2875 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2876 sme_event_auth_timed_out(wpa_s, data);
2877 break;
2878 case EVENT_ASSOC_TIMED_OUT:
2879 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2880 sme_event_assoc_timed_out(wpa_s, data);
2881 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002882 case EVENT_TX_STATUS:
2883 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2884 " type=%d stype=%d",
2885 MAC2STR(data->tx_status.dst),
2886 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002887#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002888 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002889#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002890 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2891 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002892 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002893 wpa_s, data->tx_status.dst,
2894 data->tx_status.data,
2895 data->tx_status.data_len,
2896 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002897 OFFCHANNEL_SEND_ACTION_SUCCESS :
2898 OFFCHANNEL_SEND_ACTION_NO_ACK);
2899#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 break;
2901 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002902#endif /* CONFIG_AP */
2903#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2905 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2906 /*
2907 * Catch TX status events for Action frames we sent via group
2908 * interface in GO mode.
2909 */
2910 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2911 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2912 os_memcmp(wpa_s->parent->pending_action_dst,
2913 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002914 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915 wpa_s->parent, data->tx_status.dst,
2916 data->tx_status.data,
2917 data->tx_status.data_len,
2918 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002919 OFFCHANNEL_SEND_ACTION_SUCCESS :
2920 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002921 break;
2922 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002923#endif /* CONFIG_OFFCHANNEL */
2924#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002925 switch (data->tx_status.type) {
2926 case WLAN_FC_TYPE_MGMT:
2927 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2928 data->tx_status.data_len,
2929 data->tx_status.stype,
2930 data->tx_status.ack);
2931 break;
2932 case WLAN_FC_TYPE_DATA:
2933 ap_tx_status(wpa_s, data->tx_status.dst,
2934 data->tx_status.data,
2935 data->tx_status.data_len,
2936 data->tx_status.ack);
2937 break;
2938 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002939#endif /* CONFIG_AP */
2940 break;
2941#ifdef CONFIG_AP
2942 case EVENT_EAPOL_TX_STATUS:
2943 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2944 data->eapol_tx_status.data,
2945 data->eapol_tx_status.data_len,
2946 data->eapol_tx_status.ack);
2947 break;
2948 case EVENT_DRIVER_CLIENT_POLL_OK:
2949 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002950 break;
2951 case EVENT_RX_FROM_UNKNOWN:
2952 if (wpa_s->ap_iface == NULL)
2953 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002954 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2955 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002956 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002957 case EVENT_CH_SWITCH:
2958 if (!data)
2959 break;
2960 if (!wpa_s->ap_iface) {
2961 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2962 "event in non-AP mode");
2963 break;
2964 }
2965
Dmitry Shmidt04949592012-07-19 12:16:46 -07002966 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2967 data->ch_switch.ht_enabled,
2968 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002969 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002970#endif /* CONFIG_AP */
2971#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002972 case EVENT_RX_MGMT: {
2973 u16 fc, stype;
2974 const struct ieee80211_mgmt *mgmt;
2975
2976 mgmt = (const struct ieee80211_mgmt *)
2977 data->rx_mgmt.frame;
2978 fc = le_to_host16(mgmt->frame_control);
2979 stype = WLAN_FC_GET_STYPE(fc);
2980
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002981#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002983#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2986 data->rx_mgmt.frame_len > 24) {
2987 const u8 *src = mgmt->sa;
2988 const u8 *ie = mgmt->u.probe_req.variable;
2989 size_t ie_len = data->rx_mgmt.frame_len -
2990 (mgmt->u.probe_req.variable -
2991 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002992 wpas_p2p_probe_req_rx(
2993 wpa_s, src, mgmt->da,
2994 mgmt->bssid, ie, ie_len,
2995 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996 break;
2997 }
2998#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002999#ifdef CONFIG_IBSS_RSN
3000 if (stype == WLAN_FC_STYPE_AUTH &&
3001 data->rx_mgmt.frame_len >= 30) {
3002 wpa_supplicant_event_ibss_auth(wpa_s, data);
3003 break;
3004 }
3005#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3007 "management frame in non-AP mode");
3008 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003009#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003010 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003011
3012 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3013 data->rx_mgmt.frame_len > 24) {
3014 const u8 *ie = mgmt->u.probe_req.variable;
3015 size_t ie_len = data->rx_mgmt.frame_len -
3016 (mgmt->u.probe_req.variable -
3017 data->rx_mgmt.frame);
3018
3019 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3020 mgmt->bssid, ie, ie_len,
3021 data->rx_mgmt.ssi_signal);
3022 }
3023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003025#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003026 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003027 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003028#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 case EVENT_RX_ACTION:
3030 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3031 " Category=%u DataLen=%d freq=%d MHz",
3032 MAC2STR(data->rx_action.sa),
3033 data->rx_action.category, (int) data->rx_action.len,
3034 data->rx_action.freq);
3035#ifdef CONFIG_IEEE80211R
3036 if (data->rx_action.category == WLAN_ACTION_FT) {
3037 ft_rx_action(wpa_s, data->rx_action.data,
3038 data->rx_action.len);
3039 break;
3040 }
3041#endif /* CONFIG_IEEE80211R */
3042#ifdef CONFIG_IEEE80211W
3043#ifdef CONFIG_SME
3044 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3045 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3046 data->rx_action.data,
3047 data->rx_action.len);
3048 break;
3049 }
3050#endif /* CONFIG_SME */
3051#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003052#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003053 if (data->rx_action.category == WLAN_ACTION_WNM) {
3054 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3055 break;
3056 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003057#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003058#ifdef CONFIG_GAS
3059 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3060 gas_query_rx(wpa_s->gas, data->rx_action.da,
3061 data->rx_action.sa, data->rx_action.bssid,
3062 data->rx_action.data, data->rx_action.len,
3063 data->rx_action.freq) == 0)
3064 break;
3065#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003066#ifdef CONFIG_TDLS
3067 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3068 data->rx_action.len >= 4 &&
3069 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3070 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3071 "Response from " MACSTR,
3072 MAC2STR(data->rx_action.sa));
3073 break;
3074 }
3075#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003076#ifdef CONFIG_INTERWORKING
3077 if (data->rx_action.category == WLAN_ACTION_QOS &&
3078 data->rx_action.len >= 1 &&
3079 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
3080 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3081 MACSTR, MAC2STR(data->rx_action.sa));
3082 if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
3083 == 0)
3084 wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
3085 data->rx_action.len - 1);
3086 break;
3087 }
3088#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003089#ifdef CONFIG_P2P
3090 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3091 data->rx_action.sa,
3092 data->rx_action.bssid,
3093 data->rx_action.category,
3094 data->rx_action.data,
3095 data->rx_action.len, data->rx_action.freq);
3096#endif /* CONFIG_P2P */
3097 break;
3098 case EVENT_RX_PROBE_REQ:
3099 if (data->rx_probe_req.sa == NULL ||
3100 data->rx_probe_req.ie == NULL)
3101 break;
3102#ifdef CONFIG_AP
3103 if (wpa_s->ap_iface) {
3104 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3105 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003106 data->rx_probe_req.da,
3107 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003108 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003109 data->rx_probe_req.ie_len,
3110 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003111 break;
3112 }
3113#endif /* CONFIG_AP */
3114#ifdef CONFIG_P2P
3115 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003116 data->rx_probe_req.da,
3117 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003118 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003119 data->rx_probe_req.ie_len,
3120 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003121#endif /* CONFIG_P2P */
3122 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003123 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003124#ifdef CONFIG_OFFCHANNEL
3125 offchannel_remain_on_channel_cb(
3126 wpa_s, data->remain_on_channel.freq,
3127 data->remain_on_channel.duration);
3128#endif /* CONFIG_OFFCHANNEL */
3129#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003130 wpas_p2p_remain_on_channel_cb(
3131 wpa_s, data->remain_on_channel.freq,
3132 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003133#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003134 break;
3135 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003136#ifdef CONFIG_OFFCHANNEL
3137 offchannel_cancel_remain_on_channel_cb(
3138 wpa_s, data->remain_on_channel.freq);
3139#endif /* CONFIG_OFFCHANNEL */
3140#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003141 wpas_p2p_cancel_remain_on_channel_cb(
3142 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003143#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003144 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003145#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003146 case EVENT_P2P_DEV_FOUND: {
3147 struct p2p_peer_info peer_info;
3148
3149 os_memset(&peer_info, 0, sizeof(peer_info));
3150 if (data->p2p_dev_found.dev_addr)
3151 os_memcpy(peer_info.p2p_device_addr,
3152 data->p2p_dev_found.dev_addr, ETH_ALEN);
3153 if (data->p2p_dev_found.pri_dev_type)
3154 os_memcpy(peer_info.pri_dev_type,
3155 data->p2p_dev_found.pri_dev_type,
3156 sizeof(peer_info.pri_dev_type));
3157 if (data->p2p_dev_found.dev_name)
3158 os_strlcpy(peer_info.device_name,
3159 data->p2p_dev_found.dev_name,
3160 sizeof(peer_info.device_name));
3161 peer_info.config_methods = data->p2p_dev_found.config_methods;
3162 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3163 peer_info.group_capab = data->p2p_dev_found.group_capab;
3164
3165 /*
3166 * FIX: new_device=1 is not necessarily correct. We should
3167 * maintain a P2P peer database in wpa_supplicant and update
3168 * this information based on whether the peer is truly new.
3169 */
3170 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3171 break;
3172 }
3173 case EVENT_P2P_GO_NEG_REQ_RX:
3174 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3175 data->p2p_go_neg_req_rx.dev_passwd_id);
3176 break;
3177 case EVENT_P2P_GO_NEG_COMPLETED:
3178 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3179 break;
3180 case EVENT_P2P_PROV_DISC_REQUEST:
3181 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3182 data->p2p_prov_disc_req.config_methods,
3183 data->p2p_prov_disc_req.dev_addr,
3184 data->p2p_prov_disc_req.pri_dev_type,
3185 data->p2p_prov_disc_req.dev_name,
3186 data->p2p_prov_disc_req.supp_config_methods,
3187 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003188 data->p2p_prov_disc_req.group_capab,
3189 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003190 break;
3191 case EVENT_P2P_PROV_DISC_RESPONSE:
3192 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3193 data->p2p_prov_disc_resp.config_methods);
3194 break;
3195 case EVENT_P2P_SD_REQUEST:
3196 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3197 data->p2p_sd_req.sa,
3198 data->p2p_sd_req.dialog_token,
3199 data->p2p_sd_req.update_indic,
3200 data->p2p_sd_req.tlvs,
3201 data->p2p_sd_req.tlvs_len);
3202 break;
3203 case EVENT_P2P_SD_RESPONSE:
3204 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3205 data->p2p_sd_resp.update_indic,
3206 data->p2p_sd_resp.tlvs,
3207 data->p2p_sd_resp.tlvs_len);
3208 break;
3209#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210 case EVENT_EAPOL_RX:
3211 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3212 data->eapol_rx.data,
3213 data->eapol_rx.data_len);
3214 break;
3215 case EVENT_SIGNAL_CHANGE:
3216 bgscan_notify_signal_change(
3217 wpa_s, data->signal_change.above_threshold,
3218 data->signal_change.current_signal,
3219 data->signal_change.current_noise,
3220 data->signal_change.current_txrate);
3221 break;
3222 case EVENT_INTERFACE_ENABLED:
3223 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3224 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003225 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226#ifdef CONFIG_AP
3227 if (!wpa_s->ap_iface) {
3228 wpa_supplicant_set_state(wpa_s,
3229 WPA_DISCONNECTED);
3230 wpa_supplicant_req_scan(wpa_s, 0, 0);
3231 } else
3232 wpa_supplicant_set_state(wpa_s,
3233 WPA_COMPLETED);
3234#else /* CONFIG_AP */
3235 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3236 wpa_supplicant_req_scan(wpa_s, 0, 0);
3237#endif /* CONFIG_AP */
3238 }
3239 break;
3240 case EVENT_INTERFACE_DISABLED:
3241 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3242 wpa_supplicant_mark_disassoc(wpa_s);
3243 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3244 break;
3245 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003246 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003247 break;
3248 case EVENT_INTERFACE_UNAVAILABLE:
3249#ifdef CONFIG_P2P
3250 wpas_p2p_interface_unavailable(wpa_s);
3251#endif /* CONFIG_P2P */
3252 break;
3253 case EVENT_BEST_CHANNEL:
3254 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3255 "(%d %d %d)",
3256 data->best_chan.freq_24, data->best_chan.freq_5,
3257 data->best_chan.freq_overall);
3258 wpa_s->best_24_freq = data->best_chan.freq_24;
3259 wpa_s->best_5_freq = data->best_chan.freq_5;
3260 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3261#ifdef CONFIG_P2P
3262 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3263 data->best_chan.freq_5,
3264 data->best_chan.freq_overall);
3265#endif /* CONFIG_P2P */
3266 break;
3267 case EVENT_UNPROT_DEAUTH:
3268 wpa_supplicant_event_unprot_deauth(wpa_s,
3269 &data->unprot_deauth);
3270 break;
3271 case EVENT_UNPROT_DISASSOC:
3272 wpa_supplicant_event_unprot_disassoc(wpa_s,
3273 &data->unprot_disassoc);
3274 break;
3275 case EVENT_STATION_LOW_ACK:
3276#ifdef CONFIG_AP
3277 if (wpa_s->ap_iface && data)
3278 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3279 data->low_ack.addr);
3280#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003281#ifdef CONFIG_TDLS
3282 if (data)
3283 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3284#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003285 break;
3286 case EVENT_IBSS_PEER_LOST:
3287#ifdef CONFIG_IBSS_RSN
3288 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3289#endif /* CONFIG_IBSS_RSN */
3290 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003291 case EVENT_DRIVER_GTK_REKEY:
3292 if (os_memcmp(data->driver_gtk_rekey.bssid,
3293 wpa_s->bssid, ETH_ALEN))
3294 break;
3295 if (!wpa_s->wpa)
3296 break;
3297 wpa_sm_update_replay_ctr(wpa_s->wpa,
3298 data->driver_gtk_rekey.replay_ctr);
3299 break;
3300 case EVENT_SCHED_SCAN_STOPPED:
3301 wpa_s->sched_scanning = 0;
3302 wpa_supplicant_notify_scanning(wpa_s, 0);
3303
3304 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3305 break;
3306
3307 /*
3308 * If we timed out, start a new sched scan to continue
3309 * searching for more SSIDs.
3310 */
3311 if (wpa_s->sched_scan_timed_out)
3312 wpa_supplicant_req_sched_scan(wpa_s);
3313 break;
3314 case EVENT_WPS_BUTTON_PUSHED:
3315#ifdef CONFIG_WPS
3316 wpas_wps_start_pbc(wpa_s, NULL, 0);
3317#endif /* CONFIG_WPS */
3318 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003319 case EVENT_CONNECT_FAILED_REASON:
3320#ifdef CONFIG_AP
3321 if (!wpa_s->ap_iface || !data)
3322 break;
3323 hostapd_event_connect_failed_reason(
3324 wpa_s->ap_iface->bss[0],
3325 data->connect_failed_reason.addr,
3326 data->connect_failed_reason.code);
3327#endif /* CONFIG_AP */
3328 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329 default:
3330 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3331 break;
3332 }
3333}