]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/events.c
hostapd: Add survey dump support
[thirdparty/hostap.git] / wpa_supplicant / events.c
CommitLineData
6fc6879b
JM
1/*
2 * WPA Supplicant - Driver event processing
3d9975d5 3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
3acb5005 13#include "rsn_supp/wpa.h"
6fc6879b 14#include "eloop.h"
6fc6879b
JM
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
2d5b792d 18#include "driver_i.h"
6fc6879b 19#include "pcsc_funcs.h"
3acb5005
JM
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
90973fb2 22#include "common/wpa_ctrl.h"
6fc6879b 23#include "eap_peer/eap.h"
1d041bec 24#include "ap/hostapd.h"
93b7ddd0 25#include "p2p/p2p.h"
75cad1a0 26#include "wnm_sta.h"
8bac466b 27#include "notify.h"
90973fb2 28#include "common/ieee802_11_defs.h"
54f489be 29#include "common/ieee802_11_common.h"
bbb921da 30#include "crypto/random.h"
6fc6879b
JM
31#include "blacklist.h"
32#include "wpas_glue.h"
351f09a2 33#include "wps_supplicant.h"
11ef8d35 34#include "ibss_rsn.h"
c2a04078 35#include "sme.h"
04ea7b79 36#include "gas_query.h"
9bae1be0 37#include "p2p_supplicant.h"
60b94c98 38#include "bgscan.h"
7c865c68 39#include "autoscan.h"
f8b1f695 40#include "ap.h"
6fa81a3b 41#include "bss.h"
9ba9fa07 42#include "scan.h"
24f6497c 43#include "offchannel.h"
4d5bda5f 44#include "interworking.h"
6fc6879b
JM
45
46
5d5c4ee5 47#ifndef CONFIG_NO_SCAN_PROCESSING
06b7f58d
JM
48static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
49 int new_scan);
5d5c4ee5 50#endif /* CONFIG_NO_SCAN_PROCESSING */
d6bbcce4
JM
51
52
00e5e3d5
JM
53static 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}
69
70
6fc6879b
JM
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
8bac466b 73 struct wpa_ssid *ssid, *old_ssid;
00e5e3d5 74 int res;
6fc6879b
JM
75
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
f049052b
BG
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
6fc6879b
JM
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
f049052b
BG
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
6fc6879b
JM
85 return -1;
86 }
87
349493bd 88 if (wpas_network_disabled(wpa_s, ssid)) {
f049052b 89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
6fc6879b
JM
90 return -1;
91 }
92
6407f413
JM
93 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
00e5e3d5
JM
99 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
f049052b
BG
106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
0bf927a0 108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
6fc6879b
JM
109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
cbf61176
JM
111 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");
6fc6879b
JM
114 } 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);
8bac466b 120 old_ssid = wpa_s->current_ssid;
6fc6879b
JM
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);
8bac466b
JM
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
6fc6879b
JM
126
127 return 0;
128}
129
130
01a17491 131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
6fc6879b
JM
132{
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{
8bac466b
JM
146 int bssid_changed;
147
b6668734
JM
148 wnm_bss_keep_alive_deinit(wpa_s);
149
78177a00
JM
150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
ca62e114
JM
155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
8401a6b0
JM
159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
6fc6879b 162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8bac466b 163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
6fc6879b
JM
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
a0227929
JM
166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
b1aebbc4
JM
169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
be8be671 172 wpa_s->current_bss = NULL;
3c85f144 173 wpa_s->assoc_freq = 0;
8fd0f0f3
HW
174#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
8bac466b
JM
181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
6fc6879b
JM
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
56586197 186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
6fc6879b
JM
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
0d30cc24
JM
189 wpa_s->current_ssid = NULL;
190 wpa_s->key_mgmt = 0;
6fc6879b
JM
191}
192
193
194static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
195{
196 struct wpa_ie_data ie;
197 int pmksa_set = -1;
198 size_t i;
199
200 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
201 ie.pmkid == NULL)
202 return;
203
204 for (i = 0; i < ie.num_pmkid; i++) {
205 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
206 ie.pmkid + i * PMKID_LEN,
207 NULL, NULL, 0);
208 if (pmksa_set == 0) {
209 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
210 break;
211 }
212 }
213
f049052b
BG
214 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
215 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
6fc6879b
JM
216}
217
218
219static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
220 union wpa_event_data *data)
221{
222 if (data == NULL) {
f049052b
BG
223 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
224 "event");
6fc6879b
JM
225 return;
226 }
f049052b
BG
227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
228 " index=%d preauth=%d",
229 MAC2STR(data->pmkid_candidate.bssid),
230 data->pmkid_candidate.index,
231 data->pmkid_candidate.preauth);
6fc6879b
JM
232
233 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
234 data->pmkid_candidate.index,
235 data->pmkid_candidate.preauth);
236}
237
238
239static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
240{
241 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
242 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
243 return 0;
244
245#ifdef IEEE8021X_EAPOL
246 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
247 wpa_s->current_ssid &&
248 !(wpa_s->current_ssid->eapol_flags &
249 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
250 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
251 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
252 * plaintext or static WEP keys). */
253 return 0;
254 }
255#endif /* IEEE8021X_EAPOL */
256
257 return 1;
258}
259
260
261/**
262 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
263 * @wpa_s: pointer to wpa_supplicant data
264 * @ssid: Configuration data for the network
265 * Returns: 0 on success, -1 on failure
266 *
267 * This function is called when starting authentication with a network that is
268 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
269 */
270int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
271 struct wpa_ssid *ssid)
272{
273#ifdef IEEE8021X_EAPOL
b832d34c 274#ifdef PCSC_FUNCS
6fc6879b
JM
275 int aka = 0, sim = 0, type;
276
277 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
278 return 0;
279
280 if (ssid->eap.eap_methods == NULL) {
281 sim = 1;
282 aka = 1;
283 } else {
284 struct eap_method_type *eap = ssid->eap.eap_methods;
285 while (eap->vendor != EAP_VENDOR_IETF ||
286 eap->method != EAP_TYPE_NONE) {
287 if (eap->vendor == EAP_VENDOR_IETF) {
288 if (eap->method == EAP_TYPE_SIM)
289 sim = 1;
3d332fe7
JM
290 else if (eap->method == EAP_TYPE_AKA ||
291 eap->method == EAP_TYPE_AKA_PRIME)
6fc6879b
JM
292 aka = 1;
293 }
294 eap++;
295 }
296 }
297
298 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
299 sim = 0;
3d332fe7
JM
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
301 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
302 NULL)
6fc6879b
JM
303 aka = 0;
304
305 if (!sim && !aka) {
f049052b
BG
306 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
307 "use SIM, but neither EAP-SIM nor EAP-AKA are "
308 "enabled");
6fc6879b
JM
309 return 0;
310 }
311
f049052b
BG
312 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
313 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
6fc6879b
JM
314 if (sim && aka)
315 type = SCARD_TRY_BOTH;
316 else if (aka)
317 type = SCARD_USIM_ONLY;
318 else
319 type = SCARD_GSM_SIM_ONLY;
320
f64adcd7 321 wpa_s->scard = scard_init(type, NULL);
6fc6879b 322 if (wpa_s->scard == NULL) {
f049052b
BG
323 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
324 "(pcsc-lite)");
6fc6879b
JM
325 return -1;
326 }
327 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
328 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
b832d34c 329#endif /* PCSC_FUNCS */
6fc6879b
JM
330#endif /* IEEE8021X_EAPOL */
331
332 return 0;
333}
334
335
336#ifndef CONFIG_NO_SCAN_PROCESSING
86bd1410
JM
337
338static int has_wep_key(struct wpa_ssid *ssid)
339{
340 int i;
341
342 for (i = 0; i < NUM_WEP_KEYS; i++) {
343 if (ssid->wep_key_len[i])
344 return 1;
345 }
346
347 return 0;
348}
349
350
620c7837 351static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
6fc6879b
JM
352 struct wpa_ssid *ssid)
353{
86bd1410 354 int privacy = 0;
6fc6879b
JM
355
356 if (ssid->mixed_cell)
357 return 1;
358
0632542b
AT
359#ifdef CONFIG_WPS
360 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
361 return 1;
362#endif /* CONFIG_WPS */
363
86bd1410
JM
364 if (has_wep_key(ssid))
365 privacy = 1;
366
6fc6879b
JM
367#ifdef IEEE8021X_EAPOL
368 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
369 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
370 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
371 privacy = 1;
372#endif /* IEEE8021X_EAPOL */
373
29fbc522
JM
374 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
375 privacy = 1;
376
6fc6879b
JM
377 if (bss->caps & IEEE80211_CAP_PRIVACY)
378 return privacy;
379 return !privacy;
380}
381
382
a6099152
JM
383static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
384 struct wpa_ssid *ssid,
620c7837 385 struct wpa_bss *bss)
6fc6879b
JM
386{
387 struct wpa_ie_data ie;
388 int proto_match = 0;
389 const u8 *rsn_ie, *wpa_ie;
351f09a2 390 int ret;
43882f1e 391 int wep_ok;
6fc6879b 392
a6099152 393 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
351f09a2
JM
394 if (ret >= 0)
395 return ret;
ad08c363 396
43882f1e
JM
397 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
398 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
399 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
400 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
401 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
402
620c7837 403 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
6fc6879b
JM
404 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
405 proto_match++;
406
407 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
f049052b
BG
408 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
409 "failed");
6fc6879b
JM
410 break;
411 }
43882f1e
JM
412
413 if (wep_ok &&
414 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
415 {
f049052b
BG
416 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
417 "in RSN IE");
43882f1e
JM
418 return 1;
419 }
420
6fc6879b 421 if (!(ie.proto & ssid->proto)) {
f049052b
BG
422 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
423 "mismatch");
6fc6879b
JM
424 break;
425 }
426
427 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
f049052b
BG
428 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
429 "cipher mismatch");
6fc6879b
JM
430 break;
431 }
432
433 if (!(ie.group_cipher & ssid->group_cipher)) {
f049052b
BG
434 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
435 "cipher mismatch");
6fc6879b
JM
436 break;
437 }
438
439 if (!(ie.key_mgmt & ssid->key_mgmt)) {
f049052b
BG
440 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
441 "mismatch");
6fc6879b
JM
442 break;
443 }
444
445#ifdef CONFIG_IEEE80211W
0b60b0aa 446 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
62d49803
JM
447 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
448 wpa_s->conf->pmf : ssid->ieee80211w) ==
449 MGMT_FRAME_PROTECTION_REQUIRED) {
f049052b
BG
450 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
451 "frame protection");
6fc6879b
JM
452 break;
453 }
454#endif /* CONFIG_IEEE80211W */
455
f049052b 456 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
6fc6879b
JM
457 return 1;
458 }
459
620c7837 460 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
6fc6879b
JM
461 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
462 proto_match++;
463
464 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
f049052b
BG
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
466 "failed");
6fc6879b
JM
467 break;
468 }
43882f1e
JM
469
470 if (wep_ok &&
471 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
472 {
f049052b
BG
473 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
474 "in WPA IE");
43882f1e
JM
475 return 1;
476 }
477
6fc6879b 478 if (!(ie.proto & ssid->proto)) {
f049052b
BG
479 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
480 "mismatch");
6fc6879b
JM
481 break;
482 }
483
484 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
f049052b
BG
485 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
486 "cipher mismatch");
6fc6879b
JM
487 break;
488 }
489
490 if (!(ie.group_cipher & ssid->group_cipher)) {
f049052b
BG
491 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
492 "cipher mismatch");
6fc6879b
JM
493 break;
494 }
495
496 if (!(ie.key_mgmt & ssid->key_mgmt)) {
f049052b
BG
497 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
498 "mismatch");
6fc6879b
JM
499 break;
500 }
501
f049052b 502 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
6fc6879b
JM
503 return 1;
504 }
505
a3f7e518
JM
506 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
507 !rsn_ie) {
508 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
509 return 1;
510 }
511
cc5e390d 512 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
df83fb7d 513 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
f049052b 514 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
cc5e390d
JM
515 return 0;
516 }
6fc6879b 517
c2f1fe41
JM
518 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
519 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
520 return 1;
521 }
522
523 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
524 "WPA/WPA2");
525
526 return 0;
6fc6879b
JM
527}
528
529
b766a9a2
JM
530static int freq_allowed(int *freqs, int freq)
531{
532 int i;
533
534 if (freqs == NULL)
535 return 1;
536
537 for (i = 0; freqs[i]; i++)
538 if (freqs[i] == freq)
539 return 1;
540 return 0;
541}
542
543
e1e8cae3
CL
544static int ht_supported(const struct hostapd_hw_modes *mode)
545{
546 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
547 /*
548 * The driver did not indicate whether it supports HT. Assume
549 * it does to avoid connection issues.
550 */
551 return 1;
552 }
553
554 /*
555 * IEEE Std 802.11n-2009 20.1.1:
556 * An HT non-AP STA shall support all EQM rates for one spatial stream.
557 */
558 return mode->mcs_set[0] == 0xff;
559}
560
561
c8ebeda4
MK
562static int vht_supported(const struct hostapd_hw_modes *mode)
563{
564 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
565 /*
566 * The driver did not indicate whether it supports VHT. Assume
567 * it does to avoid connection issues.
568 */
569 return 1;
570 }
571
572 /*
573 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
574 * TODO: Verify if this complies with the standard
575 */
576 return (mode->vht_mcs_set[0] & 0x3) != 3;
577}
578
579
620c7837 580static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
e1e8cae3
CL
581{
582 const struct hostapd_hw_modes *mode = NULL, *modes;
583 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
584 const u8 *rate_ie;
585 int i, j, k;
586
a6d94e1b
JM
587 if (bss->freq == 0)
588 return 1; /* Cannot do matching without knowing band */
589
e1e8cae3
CL
590 modes = wpa_s->hw.modes;
591 if (modes == NULL) {
592 /*
593 * The driver does not provide any additional information
594 * about the utilized hardware, so allow the connection attempt
595 * to continue.
596 */
597 return 1;
598 }
599
600 for (i = 0; i < wpa_s->hw.num_modes; i++) {
601 for (j = 0; j < modes[i].num_channels; j++) {
602 int freq = modes[i].channels[j].freq;
603 if (freq == bss->freq) {
604 if (mode &&
605 mode->mode == HOSTAPD_MODE_IEEE80211G)
606 break; /* do not allow 802.11b replace
607 * 802.11g */
608 mode = &modes[i];
609 break;
610 }
611 }
612 }
613
614 if (mode == NULL)
615 return 0;
616
617 for (i = 0; i < (int) sizeof(scan_ie); i++) {
620c7837 618 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
e1e8cae3
CL
619 if (rate_ie == NULL)
620 continue;
621
622 for (j = 2; j < rate_ie[1] + 2; j++) {
623 int flagged = !!(rate_ie[j] & 0x80);
624 int r = (rate_ie[j] & 0x7f) * 5;
625
626 /*
627 * IEEE Std 802.11n-2009 7.3.2.2:
628 * The new BSS Membership selector value is encoded
629 * like a legacy basic rate, but it is not a rate and
630 * only indicates if the BSS members are required to
631 * support the mandatory features of Clause 20 [HT PHY]
632 * in order to join the BSS.
633 */
634 if (flagged && ((rate_ie[j] & 0x7f) ==
635 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
636 if (!ht_supported(mode)) {
637 wpa_dbg(wpa_s, MSG_DEBUG,
638 " hardware does not support "
639 "HT PHY");
640 return 0;
641 }
642 continue;
643 }
644
c8ebeda4
MK
645 /* There's also a VHT selector for 802.11ac */
646 if (flagged && ((rate_ie[j] & 0x7f) ==
647 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
648 if (!vht_supported(mode)) {
649 wpa_dbg(wpa_s, MSG_DEBUG,
650 " hardware does not support "
651 "VHT PHY");
652 return 0;
653 }
654 continue;
655 }
656
e1e8cae3
CL
657 if (!flagged)
658 continue;
659
660 /* check for legacy basic rates */
661 for (k = 0; k < mode->num_rates; k++) {
662 if (mode->rates[k] == r)
663 break;
664 }
665 if (k == mode->num_rates) {
666 /*
667 * IEEE Std 802.11-2007 7.3.2.2 demands that in
668 * order to join a BSS all required rates
669 * have to be supported by the hardware.
670 */
671 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
672 "not support required rate %d.%d Mbps",
673 r / 10, r % 10);
674 return 0;
675 }
676 }
677 }
678
679 return 1;
680}
681
682
ff3ad3c5
VK
683static int bss_is_dmg(struct wpa_bss *bss)
684{
685 return bss->freq > 45000;
686}
687
688
689/*
690 * Test whether BSS is in an ESS.
691 * This is done differently in DMG (60 GHz) and non-DMG bands
692 */
693static int bss_is_ess(struct wpa_bss *bss)
694{
695 if (bss_is_dmg(bss)) {
696 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
697 IEEE80211_CAP_DMG_AP;
698 }
699
700 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
701 IEEE80211_CAP_ESS);
702}
703
704
d8d940b7 705static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
620c7837 706 int i, struct wpa_bss *bss,
d8d940b7 707 struct wpa_ssid *group)
6fc6879b 708{
620c7837 709 u8 wpa_ie_len, rsn_ie_len;
d8d940b7 710 int wpa;
6fc6879b
JM
711 struct wpa_blacklist *e;
712 const u8 *ie;
d8d940b7 713 struct wpa_ssid *ssid;
6fc6879b 714
620c7837 715 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
d8d940b7 716 wpa_ie_len = ie ? ie[1] : 0;
6fc6879b 717
620c7837 718 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
d8d940b7 719 rsn_ie_len = ie ? ie[1] : 0;
6fc6879b 720
f049052b
BG
721 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
722 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
620c7837 723 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
f049052b 724 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
620c7837 725 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
9cf32261 726
d8d940b7 727 e = wpa_blacklist_get(wpa_s, bss->bssid);
5471c343
JM
728 if (e) {
729 int limit = 1;
349493bd 730 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
5471c343
JM
731 /*
732 * When only a single network is enabled, we can
733 * trigger blacklisting on the first failure. This
734 * should not be done with multiple enabled networks to
735 * avoid getting forced to move into a worse ESS on
736 * single error if there are no other BSSes of the
737 * current ESS.
738 */
739 limit = 0;
740 }
741 if (e->count > limit) {
f049052b
BG
742 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
743 "(count=%d limit=%d)", e->count, limit);
c2197bc9 744 return NULL;
5471c343 745 }
d8d940b7 746 }
6fc6879b 747
620c7837 748 if (bss->ssid_len == 0) {
f049052b 749 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
c2197bc9 750 return NULL;
d8d940b7 751 }
e81634cd 752
6407f413
JM
753 if (disallowed_bssid(wpa_s, bss->bssid)) {
754 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
755 return NULL;
756 }
757
758 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
759 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
760 return NULL;
761 }
762
d8d940b7 763 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
6fc6879b 764
d8d940b7
JM
765 for (ssid = group; ssid; ssid = ssid->pnext) {
766 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
00e5e3d5 767 int res;
ad08c363 768
349493bd 769 if (wpas_network_disabled(wpa_s, ssid)) {
f049052b 770 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
0c703df3 771 continue;
d8d940b7 772 }
9cf32261 773
00e5e3d5
JM
774 res = wpas_temp_disabled(wpa_s, ssid);
775 if (res > 0) {
776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
777 "temporarily for %d second(s)", res);
778 continue;
779 }
780
ad08c363 781#ifdef CONFIG_WPS
f648bc7d 782 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
f049052b
BG
783 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
784 "(WPS)");
f648bc7d
JM
785 continue;
786 }
787
d8d940b7
JM
788 if (wpa && ssid->ssid_len == 0 &&
789 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
790 check_ssid = 0;
791
792 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
793 /* Only allow wildcard SSID match if an AP
794 * advertises active WPS operation that matches
795 * with our mode. */
796 check_ssid = 1;
ad08c363 797 if (ssid->ssid_len == 0 &&
a6099152 798 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
ad08c363 799 check_ssid = 0;
d8d940b7 800 }
ad08c363
JM
801#endif /* CONFIG_WPS */
802
7d232e23
ZC
803 if (ssid->bssid_set && ssid->ssid_len == 0 &&
804 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
805 check_ssid = 0;
806
d8d940b7 807 if (check_ssid &&
620c7837
JM
808 (bss->ssid_len != ssid->ssid_len ||
809 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
f049052b 810 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
0c703df3 811 continue;
6fc6879b 812 }
6fc6879b 813
d8d940b7
JM
814 if (ssid->bssid_set &&
815 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
f049052b 816 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
0c703df3 817 continue;
d8d940b7 818 }
6fc6879b 819
cc5e390d 820 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
0c703df3 821 continue;
9cf32261 822
d8d940b7
JM
823 if (!wpa &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
826 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
f049052b
BG
827 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
828 "not allowed");
0c703df3 829 continue;
6fc6879b 830 }
9cf32261 831
86bd1410
JM
832 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
833 has_wep_key(ssid)) {
834 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
835 continue;
836 }
837
29fbc522 838 if (!wpa_supplicant_match_privacy(bss, ssid)) {
f049052b
BG
839 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
840 "mismatch");
0c703df3 841 continue;
e81634cd
JM
842 }
843
ff3ad3c5
VK
844 if (!bss_is_ess(bss)) {
845 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
0c703df3 846 continue;
d8d940b7 847 }
b766a9a2 848
d8d940b7 849 if (!freq_allowed(ssid->freq_list, bss->freq)) {
f049052b
BG
850 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
851 "allowed");
0c703df3 852 continue;
6fc6879b 853 }
d8d940b7 854
e1e8cae3
CL
855 if (!rate_match(wpa_s, bss)) {
856 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
857 "not match");
858 continue;
859 }
860
73e49269
JM
861#ifdef CONFIG_P2P
862 /*
863 * TODO: skip the AP if its P2P IE has Group Formation
864 * bit set in the P2P Group Capability Bitmap and we
865 * are not in Group Formation with that device.
866 */
867#endif /* CONFIG_P2P */
868
d8d940b7
JM
869 /* Matching configuration found */
870 return ssid;
6fc6879b
JM
871 }
872
d8d940b7 873 /* No matching configuration found */
c2197bc9 874 return NULL;
9cf32261
JM
875}
876
877
6fa81a3b 878static struct wpa_bss *
a1fd2ce5 879wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
a1fd2ce5 880 struct wpa_ssid *group,
9cf32261
JM
881 struct wpa_ssid **selected_ssid)
882{
620c7837 883 unsigned int i;
9cf32261 884
f049052b
BG
885 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
886 group->priority);
9cf32261 887
620c7837
JM
888 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
889 struct wpa_bss *bss = wpa_s->last_scan_res[i];
d8d940b7
JM
890 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
891 if (!*selected_ssid)
892 continue;
f049052b
BG
893 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
894 " ssid='%s'",
620c7837
JM
895 MAC2STR(bss->bssid),
896 wpa_ssid_txt(bss->ssid, bss->ssid_len));
897 return bss;
d8d940b7
JM
898 }
899
900 return NULL;
6fc6879b
JM
901}
902
903
97236cee
MH
904struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
905 struct wpa_ssid **selected_ssid)
6fc6879b 906{
6fa81a3b 907 struct wpa_bss *selected = NULL;
09b9df4e
JM
908 int prio;
909
620c7837
JM
910 if (wpa_s->last_scan_res == NULL ||
911 wpa_s->last_scan_res_used == 0)
912 return NULL; /* no scan results from last update */
913
09b9df4e
JM
914 while (selected == NULL) {
915 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
916 selected = wpa_supplicant_select_bss(
620c7837 917 wpa_s, wpa_s->conf->pssid[prio],
09b9df4e
JM
918 selected_ssid);
919 if (selected)
920 break;
921 }
922
8945cc45
BM
923 if (selected == NULL && wpa_s->blacklist &&
924 !wpa_s->countermeasures) {
f049052b
BG
925 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
926 "blacklist and try again");
09b9df4e
JM
927 wpa_blacklist_clear(wpa_s);
928 wpa_s->blacklist_cleared++;
929 } else if (selected == NULL)
930 break;
931 }
932
933 return selected;
934}
935
936
937static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
977b1174 938 int timeout_sec, int timeout_usec)
09b9df4e 939{
349493bd 940 if (!wpa_supplicant_enabled_networks(wpa_s)) {
4f34d51a
SL
941 /*
942 * No networks are enabled; short-circuit request so
943 * we don't wait timeout seconds before transitioning
944 * to INACTIVE state.
945 */
ac06fb12
JM
946 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
947 "since there are no enabled networks");
4f34d51a 948 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
4c490780
JM
949#ifdef CONFIG_P2P
950 wpa_s->sta_scan_pending = 0;
951#endif /* CONFIG_P2P */
4f34d51a 952 return;
09b9df4e 953 }
5cc70322
JM
954
955 wpa_s->scan_for_connection = 1;
977b1174 956 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
09b9df4e
JM
957}
958
959
5cbd88d9
JJ
960int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
961 struct wpa_bss *selected,
962 struct wpa_ssid *ssid)
09b9df4e
JM
963{
964 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
965 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
966 "PBC session overlap");
b73bf0a7
JM
967#ifdef CONFIG_P2P
968 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
5cbd88d9 969 return -1;
b73bf0a7 970#endif /* CONFIG_P2P */
199716ad
BG
971
972#ifdef CONFIG_WPS
7736f18b 973 wpas_wps_cancel(wpa_s);
199716ad 974#endif /* CONFIG_WPS */
5cbd88d9 975 return -1;
09b9df4e
JM
976 }
977
b0680017
JM
978 wpa_msg(wpa_s, MSG_DEBUG,
979 "Considering connect request: reassociate: %d selected: "
980 MACSTR " bssid: " MACSTR " pending: " MACSTR
981 " wpa_state: %s ssid=%p current_ssid=%p",
982 wpa_s->reassociate, MAC2STR(selected->bssid),
983 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
984 wpa_supplicant_state_txt(wpa_s->wpa_state),
985 ssid, wpa_s->current_ssid);
986
09b9df4e
JM
987 /*
988 * Do not trigger new association unless the BSSID has changed or if
989 * reassociation is requested. If we are in process of associating with
990 * the selected BSSID, do not trigger new attempt.
991 */
992 if (wpa_s->reassociate ||
993 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
e29853bb
BG
994 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
995 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
b0680017
JM
996 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
997 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
998 0) ||
999 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1000 ssid != wpa_s->current_ssid)))) {
09b9df4e 1001 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
977b1174 1002 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
5cbd88d9 1003 return 0;
09b9df4e 1004 }
b0680017
JM
1005 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1006 MAC2STR(selected->bssid));
09b9df4e
JM
1007 wpa_supplicant_associate(wpa_s, selected, ssid);
1008 } else {
b0680017
JM
1009 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1010 "connect with the selected AP");
09b9df4e 1011 }
5cbd88d9
JJ
1012
1013 return 0;
09b9df4e
JM
1014}
1015
1016
b55aaa5f
JM
1017static struct wpa_ssid *
1018wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1019{
1020 int prio;
1021 struct wpa_ssid *ssid;
1022
1023 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1024 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1025 {
349493bd 1026 if (wpas_network_disabled(wpa_s, ssid))
b55aaa5f
JM
1027 continue;
1028 if (ssid->mode == IEEE80211_MODE_IBSS ||
1029 ssid->mode == IEEE80211_MODE_AP)
1030 return ssid;
1031 }
1032 }
1033 return NULL;
1034}
1035
1036
a1fd2ce5
JM
1037/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1038 * on BSS added and BSS changed events */
6ae93185 1039static void wpa_supplicant_rsn_preauth_scan_results(
6d28fb96 1040 struct wpa_supplicant *wpa_s)
6ae93185 1041{
6d28fb96 1042 struct wpa_bss *bss;
6ae93185
JM
1043
1044 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1045 return;
1046
6d28fb96 1047 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
6ae93185 1048 const u8 *ssid, *rsn;
6ae93185 1049
6d28fb96 1050 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
6ae93185
JM
1051 if (ssid == NULL)
1052 continue;
1053
6d28fb96 1054 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
6ae93185
JM
1055 if (rsn == NULL)
1056 continue;
1057
6d28fb96 1058 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
6ae93185
JM
1059 }
1060
1061}
1062
1063
48563d86
JM
1064static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1065 struct wpa_bss *selected,
20ed5e40 1066 struct wpa_ssid *ssid)
48563d86 1067{
20ed5e40 1068 struct wpa_bss *current_bss = NULL;
48563d86
JM
1069 int min_diff;
1070
1071 if (wpa_s->reassociate)
1072 return 1; /* explicit request to reassociate */
1073 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1074 return 1; /* we are not associated; continue */
1075 if (wpa_s->current_ssid == NULL)
1076 return 1; /* unknown current SSID */
1077 if (wpa_s->current_ssid != ssid)
1078 return 1; /* different network block */
1079
22628eca
JM
1080 if (wpas_driver_bss_selection(wpa_s))
1081 return 0; /* Driver-based roaming */
1082
20ed5e40
JM
1083 if (wpa_s->current_ssid->ssid)
1084 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1085 wpa_s->current_ssid->ssid,
1086 wpa_s->current_ssid->ssid_len);
1087 if (!current_bss)
1088 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
48563d86
JM
1089
1090 if (!current_bss)
1091 return 1; /* current BSS not seen in scan results */
1092
20ed5e40
JM
1093 if (current_bss == selected)
1094 return 0;
1095
1096 if (selected->last_update_idx > current_bss->last_update_idx)
1097 return 1; /* current BSS not seen in the last scan */
1098
e9af53ad 1099#ifndef CONFIG_NO_ROAMING
f049052b
BG
1100 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1101 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1102 MAC2STR(current_bss->bssid), current_bss->level);
1103 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1104 MAC2STR(selected->bssid), selected->level);
48563d86 1105
ac26ebd8
JM
1106 if (wpa_s->current_ssid->bssid_set &&
1107 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1108 0) {
f049052b
BG
1109 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1110 "has preferred BSSID");
ac26ebd8
JM
1111 return 1;
1112 }
1113
bff954e9
RS
1114 if (current_bss->level < 0 && current_bss->level > selected->level) {
1115 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1116 "signal level");
1117 return 0;
1118 }
1119
48563d86
JM
1120 min_diff = 2;
1121 if (current_bss->level < 0) {
1122 if (current_bss->level < -85)
1123 min_diff = 1;
1124 else if (current_bss->level < -80)
1125 min_diff = 2;
1126 else if (current_bss->level < -75)
1127 min_diff = 3;
1128 else if (current_bss->level < -70)
1129 min_diff = 4;
1130 else
1131 min_diff = 5;
1132 }
1133 if (abs(current_bss->level - selected->level) < min_diff) {
f049052b
BG
1134 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1135 "in signal level");
48563d86
JM
1136 return 0;
1137 }
1138
1139 return 1;
e9af53ad
DS
1140#else /* CONFIG_NO_ROAMING */
1141 return 0;
1142#endif /* CONFIG_NO_ROAMING */
48563d86
JM
1143}
1144
cd2f4ddf 1145
0dd54313 1146/* Return != 0 if no scan results could be fetched or if scan results should not
10ac7ddf 1147 * be shared with other virtual interfaces. */
e1504976 1148static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
cfd31b50
JM
1149 union wpa_event_data *data,
1150 int own_request)
09b9df4e 1151{
a1fd2ce5 1152 struct wpa_scan_results *scan_res;
5bc0cdb7 1153 int ap = 0;
7b1aa4fe
JM
1154#ifndef CONFIG_NO_RANDOM_POOL
1155 size_t i, num;
1156#endif /* CONFIG_NO_RANDOM_POOL */
5bc0cdb7
JM
1157
1158#ifdef CONFIG_AP
1159 if (wpa_s->ap_iface)
1160 ap = 1;
1161#endif /* CONFIG_AP */
6fc6879b 1162
cb8564b1
DW
1163 wpa_supplicant_notify_scanning(wpa_s, 0);
1164
39185dfa 1165#ifdef CONFIG_P2P
cfd31b50 1166 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
e665ca9a 1167 !wpa_s->global->p2p_disabled &&
4c490780
JM
1168 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1169 !wpa_s->scan_res_handler) {
e665ca9a 1170 wpa_s->global->p2p_cb_on_scan_complete = 0;
39185dfa
JM
1171 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1172 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1173 "stopped scan processing");
ab03f6da
JM
1174 wpa_s->sta_scan_pending = 1;
1175 wpa_supplicant_req_scan(wpa_s, 5, 0);
39185dfa
JM
1176 return -1;
1177 }
1178 }
99fcd404 1179 wpa_s->sta_scan_pending = 0;
39185dfa
JM
1180#endif /* CONFIG_P2P */
1181
a1fd2ce5
JM
1182 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1183 data ? &data->scan_info :
1184 NULL, 1);
1185 if (scan_res == NULL) {
66fe0f70
DS
1186 if (wpa_s->conf->ap_scan == 2 || ap ||
1187 wpa_s->scan_res_handler == scan_only_handler)
e1504976 1188 return -1;
cfd31b50
JM
1189 if (!own_request)
1190 return -1;
f049052b
BG
1191 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1192 "scanning again");
977b1174 1193 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
e1504976 1194 return -1;
6fc6879b
JM
1195 }
1196
bbb921da 1197#ifndef CONFIG_NO_RANDOM_POOL
bbb921da
JM
1198 num = scan_res->num;
1199 if (num > 10)
1200 num = 10;
1201 for (i = 0; i < num; i++) {
1202 u8 buf[5];
1203 struct wpa_scan_res *res = scan_res->res[i];
1204 buf[0] = res->bssid[5];
1205 buf[1] = res->qual & 0xff;
1206 buf[2] = res->noise & 0xff;
1207 buf[3] = res->level & 0xff;
1208 buf[4] = res->tsf & 0xff;
1209 random_add_randomness(buf, sizeof(buf));
1210 }
1211#endif /* CONFIG_NO_RANDOM_POOL */
1212
cfd31b50 1213 if (own_request && wpa_s->scan_res_handler) {
860fddbb
JB
1214 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1215 struct wpa_scan_results *scan_res);
1216
1217 scan_res_handler = wpa_s->scan_res_handler;
64e58f51 1218 wpa_s->scan_res_handler = NULL;
860fddbb
JB
1219 scan_res_handler(wpa_s, scan_res);
1220
64e58f51 1221 wpa_scan_results_free(scan_res);
10ac7ddf 1222 return -2;
64e58f51
JM
1223 }
1224
5bc0cdb7 1225 if (ap) {
f049052b 1226 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
c202f19c
JB
1227#ifdef CONFIG_AP
1228 if (wpa_s->ap_iface->scan_cb)
1229 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1230#endif /* CONFIG_AP */
5bc0cdb7 1231 wpa_scan_results_free(scan_res);
e1504976 1232 return 0;
5bc0cdb7
JM
1233 }
1234
f049052b 1235 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
24f76940
JM
1236 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1237 wpas_notify_scan_results(wpa_s);
6fc6879b 1238
8bac466b
JM
1239 wpas_notify_scan_done(wpa_s, 1);
1240
c3701c66
RM
1241 if (sme_proc_obss_scan(wpa_s) > 0) {
1242 wpa_scan_results_free(scan_res);
1243 return 0;
1244 }
1245
a1fd2ce5
JM
1246 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1247 wpa_scan_results_free(scan_res);
e1504976 1248 return 0;
a1fd2ce5 1249 }
6fc6879b 1250
7c865c68
TB
1251 if (autoscan_notify_scan(wpa_s, scan_res)) {
1252 wpa_scan_results_free(scan_res);
1253 return 0;
1254 }
1255
3180d7a2
SO
1256 if (wpa_s->disconnected) {
1257 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
a1fd2ce5 1258 wpa_scan_results_free(scan_res);
e1504976 1259 return 0;
3180d7a2
SO
1260 }
1261
22628eca
JM
1262 if (!wpas_driver_bss_selection(wpa_s) &&
1263 bgscan_notify_scan(wpa_s, scan_res) == 1) {
a1fd2ce5 1264 wpa_scan_results_free(scan_res);
e1504976 1265 return 0;
a1fd2ce5
JM
1266 }
1267
f9f0526b
JM
1268 wpas_wps_update_ap_info(wpa_s, scan_res);
1269
20ed5e40
JM
1270 wpa_scan_results_free(scan_res);
1271
06b7f58d 1272 return wpas_select_network_from_last_scan(wpa_s, 1);
a594e2a9
JM
1273}
1274
1275
06b7f58d
JM
1276static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1277 int new_scan)
a594e2a9
JM
1278{
1279 struct wpa_bss *selected;
1280 struct wpa_ssid *ssid = NULL;
1281
620c7837
JM
1282 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1283
6fc6879b 1284 if (selected) {
48563d86 1285 int skip;
20ed5e40 1286 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1bbff09e 1287 if (skip) {
06b7f58d
JM
1288 if (new_scan)
1289 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
e1504976 1290 return 0;
1bbff09e 1291 }
5cbd88d9
JJ
1292
1293 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1294 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1295 return -1;
1296 }
06b7f58d
JM
1297 if (new_scan)
1298 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
0dd54313
JM
1299 /*
1300 * Do not notify other virtual radios of scan results since we do not
1301 * want them to start other associations at the same time.
1302 */
1303 return 1;
6fc6879b 1304 } else {
f049052b 1305 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
b55aaa5f
JM
1306 ssid = wpa_supplicant_pick_new_network(wpa_s);
1307 if (ssid) {
f049052b 1308 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
b55aaa5f 1309 wpa_supplicant_associate(wpa_s, NULL, ssid);
06b7f58d
JM
1310 if (new_scan)
1311 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
977b1174 1312 } else {
67b9bd08 1313 int timeout_sec = wpa_s->scan_interval;
977b1174 1314 int timeout_usec = 0;
0817de90 1315#ifdef CONFIG_P2P
aa9bb764
JM
1316 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1317 return 0;
1318
0817de90
JM
1319 if (wpa_s->p2p_in_provisioning) {
1320 /*
1321 * Use shorter wait during P2P Provisioning
1322 * state to speed up group formation.
1323 */
1324 timeout_sec = 0;
1325 timeout_usec = 250000;
a4cba8f1
LC
1326 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1327 timeout_usec);
1328 return 0;
0817de90
JM
1329 }
1330#endif /* CONFIG_P2P */
4d5bda5f
JM
1331#ifdef CONFIG_INTERWORKING
1332 if (wpa_s->conf->auto_interworking &&
1333 wpa_s->conf->interworking &&
1334 wpa_s->conf->cred) {
1335 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1336 "start ANQP fetch since no matching "
1337 "networks found");
1338 wpa_s->network_select = 1;
1339 wpa_s->auto_network_select = 1;
1340 interworking_start_fetch_anqp(wpa_s);
0dd54313 1341 return 1;
4d5bda5f
JM
1342 }
1343#endif /* CONFIG_INTERWORKING */
a4cba8f1
LC
1344 if (wpa_supplicant_req_sched_scan(wpa_s))
1345 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1346 timeout_usec);
977b1174 1347 }
6fc6879b 1348 }
e1504976 1349 return 0;
6fc6879b 1350}
6859f1cb
BG
1351
1352
1353static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1354 union wpa_event_data *data)
1355{
1356 const char *rn, *rn2;
1357 struct wpa_supplicant *ifs;
1358
cfd31b50 1359 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
e1504976
BG
1360 /*
1361 * If no scan results could be fetched, then no need to
1362 * notify those interfaces that did not actually request
0dd54313
JM
1363 * this scan. Similarly, if scan results started a new operation on this
1364 * interface, do not notify other interfaces to avoid concurrent
1365 * operations during a connection attempt.
e1504976
BG
1366 */
1367 return;
1368 }
6859f1cb
BG
1369
1370 /*
1371 * Check other interfaces to see if they have the same radio-name. If
1372 * so, they get updated with this same scan info.
1373 */
1374 if (!wpa_s->driver->get_radio_name)
1375 return;
1376
1377 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1378 if (rn == NULL || rn[0] == '\0')
1379 return;
1380
f049052b
BG
1381 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1382 "sharing same radio (%s) in event_scan_results", rn);
6859f1cb
BG
1383
1384 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1385 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1386 continue;
1387
1388 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1389 if (rn2 && os_strcmp(rn, rn2) == 0) {
1390 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1391 "sibling", ifs->ifname);
cfd31b50 1392 _wpa_supplicant_event_scan_results(ifs, data, 0);
6859f1cb
BG
1393 }
1394 }
1395}
1396
6fc6879b
JM
1397#endif /* CONFIG_NO_SCAN_PROCESSING */
1398
1399
cecdddc1
PS
1400int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1401{
1402#ifdef CONFIG_NO_SCAN_PROCESSING
1403 return -1;
1404#else /* CONFIG_NO_SCAN_PROCESSING */
1405 struct os_time now;
1406
1407 if (wpa_s->last_scan_res_used <= 0)
1408 return -1;
1409
1410 os_get_time(&now);
1411 if (now.sec - wpa_s->last_scan.sec > 5) {
1412 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1413 return -1;
1414 }
1415
06b7f58d 1416 return wpas_select_network_from_last_scan(wpa_s, 0);
cecdddc1
PS
1417#endif /* CONFIG_NO_SCAN_PROCESSING */
1418}
1419
b6668734
JM
1420#ifdef CONFIG_WNM
1421
1422static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1423{
1424 struct wpa_supplicant *wpa_s = eloop_ctx;
1425
1426 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1427 return;
1428
2ec535fd
JM
1429 if (!wpa_s->no_keep_alive) {
1430 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1431 MAC2STR(wpa_s->bssid));
1432 /* TODO: could skip this if normal data traffic has been sent */
1433 /* TODO: Consider using some more appropriate data frame for
1434 * this */
1435 if (wpa_s->l2)
1436 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1437 (u8 *) "", 0);
1438 }
b6668734 1439
597c7a8d 1440#ifdef CONFIG_SME
b6668734
JM
1441 if (wpa_s->sme.bss_max_idle_period) {
1442 unsigned int msec;
1443 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1444 if (msec > 100)
1445 msec -= 100;
1446 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1447 wnm_bss_keep_alive, wpa_s, NULL);
1448 }
597c7a8d 1449#endif /* CONFIG_SME */
b6668734
JM
1450}
1451
1452
1453static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1454 const u8 *ies, size_t ies_len)
1455{
1456 struct ieee802_11_elems elems;
1457
1458 if (ies == NULL)
1459 return;
1460
1461 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1462 return;
1463
1464#ifdef CONFIG_SME
1465 if (elems.bss_max_idle_period) {
1466 unsigned int msec;
1467 wpa_s->sme.bss_max_idle_period =
1468 WPA_GET_LE16(elems.bss_max_idle_period);
1469 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1470 "TU)%s", wpa_s->sme.bss_max_idle_period,
1471 (elems.bss_max_idle_period[2] & 0x01) ?
1472 " (protected keep-live required)" : "");
1473 if (wpa_s->sme.bss_max_idle_period == 0)
1474 wpa_s->sme.bss_max_idle_period = 1;
1475 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1476 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1477 /* msec times 1000 */
1478 msec = wpa_s->sme.bss_max_idle_period * 1024;
1479 if (msec > 100)
1480 msec -= 100;
1481 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1482 wnm_bss_keep_alive, wpa_s,
1483 NULL);
1484 }
1485 }
1486#endif /* CONFIG_SME */
1487}
1488
1489#endif /* CONFIG_WNM */
1490
1491
1492void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1493{
1494#ifdef CONFIG_WNM
1495 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1496#endif /* CONFIG_WNM */
1497}
1498
1499
579ce771
JM
1500static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1501 union wpa_event_data *data)
6fc6879b
JM
1502{
1503 int l, len, found = 0, wpa_found, rsn_found;
c2a04078 1504 const u8 *p;
b6714ca1 1505#ifdef CONFIG_IEEE80211R
6a1ce395 1506 u8 bssid[ETH_ALEN];
b6714ca1 1507#endif /* CONFIG_IEEE80211R */
6fc6879b 1508
f049052b 1509 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
6fc6879b
JM
1510 if (data->assoc_info.req_ies)
1511 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1512 data->assoc_info.req_ies_len);
52c9e6f3 1513 if (data->assoc_info.resp_ies) {
6fc6879b
JM
1514 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1515 data->assoc_info.resp_ies_len);
52c9e6f3
JM
1516#ifdef CONFIG_TDLS
1517 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1518 data->assoc_info.resp_ies_len);
1519#endif /* CONFIG_TDLS */
b6668734
JM
1520#ifdef CONFIG_WNM
1521 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1522 data->assoc_info.resp_ies_len);
1523#endif /* CONFIG_WNM */
52c9e6f3 1524 }
6fc6879b
JM
1525 if (data->assoc_info.beacon_ies)
1526 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1527 data->assoc_info.beacon_ies,
1528 data->assoc_info.beacon_ies_len);
4832ecd7 1529 if (data->assoc_info.freq)
f049052b
BG
1530 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1531 data->assoc_info.freq);
6fc6879b
JM
1532
1533 p = data->assoc_info.req_ies;
1534 l = data->assoc_info.req_ies_len;
1535
1536 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1537 while (p && l >= 2) {
1538 len = p[1] + 2;
1539 if (len > l) {
1540 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1541 p, l);
1542 break;
1543 }
1544 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1545 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1546 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1547 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1548 break;
1549 found = 1;
1550 wpa_find_assoc_pmkid(wpa_s);
1551 break;
1552 }
1553 l -= len;
1554 p += len;
1555 }
1556 if (!found && data->assoc_info.req_ies)
1557 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1558
c2a04078 1559#ifdef CONFIG_IEEE80211R
62c72d72
JM
1560#ifdef CONFIG_SME
1561 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
62c72d72
JM
1562 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1563 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1564 data->assoc_info.resp_ies,
1565 data->assoc_info.resp_ies_len,
1566 bssid) < 0) {
f049052b
BG
1567 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1568 "Reassociation Response failed");
579ce771
JM
1569 wpa_supplicant_deauthenticate(
1570 wpa_s, WLAN_REASON_INVALID_IE);
1571 return -1;
62c72d72
JM
1572 }
1573 }
62c72d72 1574
c2a04078
JM
1575 p = data->assoc_info.resp_ies;
1576 l = data->assoc_info.resp_ies_len;
1577
54f489be 1578#ifdef CONFIG_WPS_STRICT
5dac11e0 1579 if (p && wpa_s->current_ssid &&
54f489be
JM
1580 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1581 struct wpabuf *wps;
1582 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1583 if (wps == NULL) {
f049052b
BG
1584 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1585 "include WPS IE in (Re)Association Response");
54f489be
JM
1586 return -1;
1587 }
1588
1589 if (wps_validate_assoc_resp(wps) < 0) {
1590 wpabuf_free(wps);
1591 wpa_supplicant_deauthenticate(
1592 wpa_s, WLAN_REASON_INVALID_IE);
1593 return -1;
1594 }
1595 wpabuf_free(wps);
1596 }
1597#endif /* CONFIG_WPS_STRICT */
1598
e7846b68 1599 /* Go through the IEs and make a copy of the MDIE, if present. */
c2a04078
JM
1600 while (p && l >= 2) {
1601 len = p[1] + 2;
1602 if (len > l) {
1603 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1604 p, l);
1605 break;
1606 }
e7846b68
JM
1607 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1608 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1609 wpa_s->sme.ft_used = 1;
1610 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1611 MOBILITY_DOMAIN_ID_LEN);
1612 break;
1613 }
c2a04078
JM
1614 l -= len;
1615 p += len;
1616 }
e7846b68 1617#endif /* CONFIG_SME */
c2a04078 1618
6a1ce395
DG
1619 /* Process FT when SME is in the driver */
1620 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1621 wpa_ft_is_completed(wpa_s->wpa)) {
1622 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1623 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1624 data->assoc_info.resp_ies,
1625 data->assoc_info.resp_ies_len,
1626 bssid) < 0) {
1627 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1628 "Reassociation Response failed");
1629 wpa_supplicant_deauthenticate(
1630 wpa_s, WLAN_REASON_INVALID_IE);
1631 return -1;
1632 }
1633 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1634 }
1635
e7846b68
JM
1636 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1637 data->assoc_info.resp_ies_len);
c2a04078
JM
1638#endif /* CONFIG_IEEE80211R */
1639
6fc6879b
JM
1640 /* WPA/RSN IE from Beacon/ProbeResp */
1641 p = data->assoc_info.beacon_ies;
1642 l = data->assoc_info.beacon_ies_len;
1643
1644 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1645 */
1646 wpa_found = rsn_found = 0;
1647 while (p && l >= 2) {
1648 len = p[1] + 2;
1649 if (len > l) {
1650 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1651 p, l);
1652 break;
1653 }
1654 if (!wpa_found &&
1655 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1656 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1657 wpa_found = 1;
1658 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1659 }
1660
1661 if (!rsn_found &&
1662 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1663 rsn_found = 1;
1664 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1665 }
1666
1667 l -= len;
1668 p += len;
1669 }
1670
1671 if (!wpa_found && data->assoc_info.beacon_ies)
1672 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1673 if (!rsn_found && data->assoc_info.beacon_ies)
1674 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1675 if (wpa_found || rsn_found)
1676 wpa_s->ap_ies_from_associnfo = 1;
4832ecd7 1677
117e812d
JM
1678 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1679 wpa_s->assoc_freq != data->assoc_info.freq) {
1680 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1681 "%u to %u MHz",
1682 wpa_s->assoc_freq, data->assoc_info.freq);
1683 wpa_supplicant_update_scan_results(wpa_s);
1684 }
1685
4832ecd7 1686 wpa_s->assoc_freq = data->assoc_info.freq;
579ce771
JM
1687
1688 return 0;
6fc6879b
JM
1689}
1690
1691
cd2f4ddf
SM
1692static struct wpa_bss * wpa_supplicant_get_new_bss(
1693 struct wpa_supplicant *wpa_s, const u8 *bssid)
1694{
1695 struct wpa_bss *bss = NULL;
1696 struct wpa_ssid *ssid = wpa_s->current_ssid;
1697
1698 if (ssid->ssid_len > 0)
1699 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1700 if (!bss)
1701 bss = wpa_bss_get_bssid(wpa_s, bssid);
1702
1703 return bss;
1704}
1705
1706
ad9ee4d4
JM
1707static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1708{
1709 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1710
1711 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1712 return -1;
1713
1714 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1715 return 0;
1716
1717 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1718 WPA_IE_VENDOR_TYPE);
1719 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1720
1721 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1722 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1723 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1724 bss_rsn ? 2 + bss_rsn[1] : 0))
1725 return -1;
1726
1727 return 0;
1728}
1729
1730
6fc6879b
JM
1731static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1732 union wpa_event_data *data)
1733{
1734 u8 bssid[ETH_ALEN];
1d041bec 1735 int ft_completed;
6fc6879b 1736
1d041bec
JM
1737#ifdef CONFIG_AP
1738 if (wpa_s->ap_iface) {
1739 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1740 data->assoc_info.addr,
1741 data->assoc_info.req_ies,
39b08b5f
SP
1742 data->assoc_info.req_ies_len,
1743 data->assoc_info.reassoc);
1d041bec
JM
1744 return;
1745 }
1746#endif /* CONFIG_AP */
1747
1748 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
579ce771
JM
1749 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1750 return;
6fc6879b 1751
0a0c38f6
MH
1752 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1753 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
07783eaa 1754 wpa_supplicant_deauthenticate(
0a0c38f6
MH
1755 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1756 return;
1757 }
1758
6fc6879b 1759 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
0a0c38f6 1760 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
f049052b 1761 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
6fc6879b 1762 MACSTR, MAC2STR(bssid));
bbb921da 1763 random_add_randomness(bssid, ETH_ALEN);
6fc6879b
JM
1764 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1765 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
e485286c 1766 wpas_notify_bssid_changed(wpa_s);
8bac466b 1767
6fc6879b
JM
1768 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1769 wpa_clear_keys(wpa_s, bssid);
1770 }
1771 if (wpa_supplicant_select_config(wpa_s) < 0) {
07783eaa 1772 wpa_supplicant_deauthenticate(
6fc6879b
JM
1773 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1774 return;
1775 }
8f770587
JM
1776 if (wpa_s->current_ssid) {
1777 struct wpa_bss *bss = NULL;
cd2f4ddf
SM
1778
1779 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1780 if (!bss) {
1781 wpa_supplicant_update_scan_results(wpa_s);
1782
1783 /* Get the BSS from the new scan results */
1784 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1785 }
1786
8f770587
JM
1787 if (bss)
1788 wpa_s->current_bss = bss;
1789 }
cd2f4ddf
SM
1790
1791 if (wpa_s->conf->ap_scan == 1 &&
1792 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1793 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1794 wpa_msg(wpa_s, MSG_WARNING,
1795 "WPA/RSN IEs not updated");
1796 }
6fc6879b
JM
1797 }
1798
62fa124c
JM
1799#ifdef CONFIG_SME
1800 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1801 wpa_s->sme.prev_bssid_set = 1;
1802#endif /* CONFIG_SME */
1803
6fc6879b
JM
1804 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1805 if (wpa_s->current_ssid) {
1806 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1807 * initialized before association, but for other modes,
1808 * initialize PC/SC here, if the current configuration needs
1809 * smartcard or SIM/USIM. */
1810 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1811 }
1812 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3f967fe0
JM
1813 if (wpa_s->l2)
1814 l2_packet_notify_auth_start(wpa_s->l2);
6fc6879b
JM
1815
1816 /*
1817 * Set portEnabled first to FALSE in order to get EAP state machine out
1818 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1819 * state machine may transit to AUTHENTICATING state based on obsolete
1820 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1821 * AUTHENTICATED without ever giving chance to EAP state machine to
1822 * reset the state.
1823 */
1824 if (!ft_completed) {
1825 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1826 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1827 }
56586197 1828 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
6fc6879b
JM
1829 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1830 /* 802.1X::portControl = Auto */
1831 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1832 wpa_s->eapol_received = 0;
1833 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
9c972abb
JM
1834 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1835 (wpa_s->current_ssid &&
1836 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
6ea1f413
JM
1837 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1838 (wpa_s->drv_flags &
1839 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1840 /*
1841 * Set the key after having received joined-IBSS event
1842 * from the driver.
1843 */
1844 wpa_supplicant_set_wpa_none_key(wpa_s,
1845 wpa_s->current_ssid);
1846 }
6fc6879b
JM
1847 wpa_supplicant_cancel_auth_timeout(wpa_s);
1848 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1849 } else if (!ft_completed) {
1850 /* Timeout for receiving the first EAPOL packet */
1851 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1852 }
1853 wpa_supplicant_cancel_scan(wpa_s);
1854
c2a04078 1855 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
56586197 1856 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
6fc6879b
JM
1857 /*
1858 * We are done; the driver will take care of RSN 4-way
1859 * handshake.
1860 */
1861 wpa_supplicant_cancel_auth_timeout(wpa_s);
1862 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1863 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1864 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
98ea9431
JM
1865 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1866 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1867 /*
1868 * The driver will take care of RSN 4-way handshake, so we need
1869 * to allow EAPOL supplicant to complete its work without
1870 * waiting for WPA supplicant.
1871 */
1872 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
16a83d29
JM
1873 } else if (ft_completed) {
1874 /*
1875 * FT protocol completed - make sure EAPOL state machine ends
1876 * up in authenticated.
1877 */
1878 wpa_supplicant_cancel_auth_timeout(wpa_s);
1879 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1880 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1881 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
6fc6879b 1882 }
1ff73338 1883
3ab35a66
JM
1884 wpa_s->last_eapol_matches_bssid = 0;
1885
1ff73338
JM
1886 if (wpa_s->pending_eapol_rx) {
1887 struct os_time now, age;
1888 os_get_time(&now);
1889 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1890 if (age.sec == 0 && age.usec < 100000 &&
1891 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1892 0) {
f049052b
BG
1893 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1894 "frame that was received just before "
1895 "association notification");
1ff73338
JM
1896 wpa_supplicant_rx_eapol(
1897 wpa_s, wpa_s->pending_eapol_rx_src,
1898 wpabuf_head(wpa_s->pending_eapol_rx),
1899 wpabuf_len(wpa_s->pending_eapol_rx));
1900 }
1901 wpabuf_free(wpa_s->pending_eapol_rx);
1902 wpa_s->pending_eapol_rx = NULL;
1903 }
60b94c98 1904
0194fedb
JB
1905 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1906 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
66562e9c
JM
1907 wpa_s->current_ssid &&
1908 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
0194fedb
JB
1909 /* Set static WEP keys again */
1910 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1911 }
50b05780
JM
1912
1913#ifdef CONFIG_IBSS_RSN
1914 if (wpa_s->current_ssid &&
1915 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1916 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
78177a00
JM
1917 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1918 wpa_s->ibss_rsn == NULL) {
1919 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1920 if (!wpa_s->ibss_rsn) {
1921 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1922 wpa_supplicant_deauthenticate(
1923 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1924 return;
1925 }
1926
1927 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1928 }
50b05780 1929#endif /* CONFIG_IBSS_RSN */
f9f0526b
JM
1930
1931 wpas_wps_notify_assoc(wpa_s, bssid);
6fc6879b
JM
1932}
1933
1934
d00821e9
JM
1935static int disconnect_reason_recoverable(u16 reason_code)
1936{
1937 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1938 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1939 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1940}
1941
1942
0544b242 1943static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
3d9975d5
JM
1944 u16 reason_code,
1945 int locally_generated)
6fc6879b
JM
1946{
1947 const u8 *bssid;
0aadd568
JM
1948
1949 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1950 /*
1951 * At least Host AP driver and a Prism3 card seemed to be
1952 * generating streams of disconnected events when configuring
1953 * IBSS for WPA-None. Ignore them for now.
1954 */
1955 return;
1956 }
1957
1958 bssid = wpa_s->bssid;
1959 if (is_zero_ether_addr(bssid))
1960 bssid = wpa_s->pending_bssid;
1961
1962 if (!is_zero_ether_addr(bssid) ||
1963 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1964 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1965 " reason=%d%s",
1966 MAC2STR(bssid), reason_code,
1967 locally_generated ? " locally_generated=1" : "");
1968 }
1969}
1970
1971
c9a82218
JM
1972static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1973 int locally_generated)
1974{
1975 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1976 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1977 return 0; /* Not in 4-way handshake with PSK */
1978
1979 /*
1980 * It looks like connection was lost while trying to go through PSK
1981 * 4-way handshake. Filter out known disconnection cases that are caused
1982 * by something else than PSK mismatch to avoid confusing reports.
1983 */
1984
1985 if (locally_generated) {
1986 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1987 return 0;
1988 }
1989
1990 return 1;
1991}
1992
1993
0aadd568
JM
1994static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1995 u16 reason_code,
1996 int locally_generated)
1997{
1998 const u8 *bssid;
6d6f4bb8
JM
1999 int authenticating;
2000 u8 prev_pending_bssid[ETH_ALEN];
d00821e9 2001 struct wpa_bss *fast_reconnect = NULL;
5d5c4ee5 2002#ifndef CONFIG_NO_SCAN_PROCESSING
d00821e9 2003 struct wpa_ssid *fast_reconnect_ssid = NULL;
5d5c4ee5 2004#endif /* CONFIG_NO_SCAN_PROCESSING */
bcdf2096 2005 struct wpa_ssid *last_ssid;
6d6f4bb8
JM
2006
2007 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2008 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
6fc6879b
JM
2009
2010 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2011 /*
2012 * At least Host AP driver and a Prism3 card seemed to be
2013 * generating streams of disconnected events when configuring
2014 * IBSS for WPA-None. Ignore them for now.
2015 */
f049052b
BG
2016 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2017 "IBSS/WPA-None mode");
6fc6879b
JM
2018 return;
2019 }
2020
c9a82218 2021 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
6fc6879b
JM
2022 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2023 "pre-shared key may be incorrect");
00e5e3d5 2024 wpas_auth_failed(wpa_s);
6fc6879b 2025 }
3636b891
JM
2026 if (!wpa_s->disconnected &&
2027 (!wpa_s->auto_reconnect_disabled ||
2028 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
d00821e9 2029 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
f7da5a9e
JM
2030 "reconnect (wps=%d wpa_state=%d)",
2031 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2032 wpa_s->wpa_state);
d00821e9
JM
2033 if (wpa_s->wpa_state == WPA_COMPLETED &&
2034 wpa_s->current_ssid &&
2035 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
3d9975d5 2036 !locally_generated &&
d00821e9
JM
2037 disconnect_reason_recoverable(reason_code)) {
2038 /*
2039 * It looks like the AP has dropped association with
2040 * us, but could allow us to get back in. Try to
2041 * reconnect to the same BSS without full scan to save
2042 * time for some common cases.
2043 */
2044 fast_reconnect = wpa_s->current_bss;
5d5c4ee5 2045#ifndef CONFIG_NO_SCAN_PROCESSING
d00821e9 2046 fast_reconnect_ssid = wpa_s->current_ssid;
5d5c4ee5 2047#endif /* CONFIG_NO_SCAN_PROCESSING */
d00821e9 2048 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
0d0a8ca1 2049 wpa_supplicant_req_scan(wpa_s, 0, 100000);
f7da5a9e
JM
2050 else
2051 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2052 "immediate scan");
0d0a8ca1 2053 } else {
d00821e9 2054 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
f049052b 2055 "try to re-connect");
0d0a8ca1
AC
2056 wpa_s->reassociate = 0;
2057 wpa_s->disconnected = 1;
433cd2ce 2058 wpa_supplicant_cancel_sched_scan(wpa_s);
0d0a8ca1 2059 }
6fc6879b 2060 bssid = wpa_s->bssid;
a8e16edc 2061 if (is_zero_ether_addr(bssid))
6fc6879b 2062 bssid = wpa_s->pending_bssid;
56d24b4e
JM
2063 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2064 wpas_connection_failed(wpa_s, bssid);
6fc6879b 2065 wpa_sm_notify_disassoc(wpa_s->wpa);
0bb1e425
GM
2066 if (locally_generated)
2067 wpa_s->disconnect_reason = -reason_code;
2068 else
2069 wpa_s->disconnect_reason = reason_code;
2070 wpas_notify_disconnect_reason(wpa_s);
6fc6879b 2071 if (wpa_supplicant_dynamic_keys(wpa_s)) {
f049052b 2072 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
6fc6879b
JM
2073 wpa_s->keys_cleared = 0;
2074 wpa_clear_keys(wpa_s, wpa_s->bssid);
2075 }
bcdf2096 2076 last_ssid = wpa_s->current_ssid;
6fc6879b 2077 wpa_supplicant_mark_disassoc(wpa_s);
e29853bb 2078
bcdf2096 2079 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
e29853bb 2080 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
bcdf2096
JM
2081 wpa_s->current_ssid = last_ssid;
2082 }
d00821e9
JM
2083
2084 if (fast_reconnect) {
5928411e 2085#ifndef CONFIG_NO_SCAN_PROCESSING
d00821e9
JM
2086 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2087 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2088 fast_reconnect_ssid) < 0) {
2089 /* Recover through full scan */
2090 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2091 }
5928411e 2092#endif /* CONFIG_NO_SCAN_PROCESSING */
d00821e9 2093 }
6fc6879b
JM
2094}
2095
2096
46690a3b 2097#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
01a17491 2098void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
46690a3b
JM
2099{
2100 struct wpa_supplicant *wpa_s = eloop_ctx;
2101
2102 if (!wpa_s->pending_mic_error_report)
2103 return;
2104
f049052b 2105 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
46690a3b
JM
2106 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2107 wpa_s->pending_mic_error_report = 0;
2108}
2109#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2110
2111
6fc6879b
JM
2112static void
2113wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2114 union wpa_event_data *data)
2115{
2116 int pairwise;
2117 struct os_time t;
2118
2119 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2120 pairwise = (data && data->michael_mic_failure.unicast);
6fc6879b 2121 os_get_time(&t);
46690a3b
JM
2122 if ((wpa_s->last_michael_mic_error &&
2123 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2124 wpa_s->pending_mic_error_report) {
2125 if (wpa_s->pending_mic_error_report) {
2126 /*
2127 * Send the pending MIC error report immediately since
2128 * we are going to start countermeasures and AP better
2129 * do the same.
2130 */
2131 wpa_sm_key_request(wpa_s->wpa, 1,
2132 wpa_s->pending_mic_error_pairwise);
2133 }
2134
2135 /* Send the new MIC error report immediately since we are going
2136 * to start countermeasures and AP better do the same.
2137 */
2138 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2139
6fc6879b
JM
2140 /* initialize countermeasures */
2141 wpa_s->countermeasures = 1;
8945cc45
BM
2142
2143 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2144
6fc6879b
JM
2145 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2146
2147 /*
2148 * Need to wait for completion of request frame. We do not get
2149 * any callback for the message completion, so just wait a
2150 * short while and hope for the best. */
2151 os_sleep(0, 10000);
2152
2153 wpa_drv_set_countermeasures(wpa_s, 1);
2154 wpa_supplicant_deauthenticate(wpa_s,
2155 WLAN_REASON_MICHAEL_MIC_FAILURE);
2156 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2157 wpa_s, NULL);
2158 eloop_register_timeout(60, 0,
2159 wpa_supplicant_stop_countermeasures,
2160 wpa_s, NULL);
2161 /* TODO: mark the AP rejected for 60 second. STA is
2162 * allowed to associate with another AP.. */
46690a3b
JM
2163 } else {
2164#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2165 if (wpa_s->mic_errors_seen) {
2166 /*
2167 * Reduce the effectiveness of Michael MIC error
2168 * reports as a means for attacking against TKIP if
2169 * more than one MIC failure is noticed with the same
2170 * PTK. We delay the transmission of the reports by a
2171 * random time between 0 and 60 seconds in order to
2172 * force the attacker wait 60 seconds before getting
2173 * the information on whether a frame resulted in a MIC
2174 * failure.
2175 */
2176 u8 rval[4];
2177 int sec;
2178
2179 if (os_get_random(rval, sizeof(rval)) < 0)
2180 sec = os_random() % 60;
2181 else
2182 sec = WPA_GET_BE32(rval) % 60;
f049052b
BG
2183 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2184 "report %d seconds", sec);
46690a3b
JM
2185 wpa_s->pending_mic_error_report = 1;
2186 wpa_s->pending_mic_error_pairwise = pairwise;
2187 eloop_cancel_timeout(
2188 wpa_supplicant_delayed_mic_error_report,
2189 wpa_s, NULL);
2190 eloop_register_timeout(
2191 sec, os_random() % 1000000,
2192 wpa_supplicant_delayed_mic_error_report,
2193 wpa_s, NULL);
2194 } else {
2195 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2196 }
2197#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2198 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2199#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
6fc6879b
JM
2200 }
2201 wpa_s->last_michael_mic_error = t.sec;
46690a3b 2202 wpa_s->mic_errors_seen++;
6fc6879b
JM
2203}
2204
2205
a83d9c96
SL
2206#ifdef CONFIG_TERMINATE_ONLASTIF
2207static int any_interfaces(struct wpa_supplicant *head)
2208{
2209 struct wpa_supplicant *wpa_s;
2210
2211 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2212 if (!wpa_s->interface_removed)
2213 return 1;
2214 return 0;
2215}
2216#endif /* CONFIG_TERMINATE_ONLASTIF */
2217
2218
6fc6879b
JM
2219static void
2220wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2221 union wpa_event_data *data)
2222{
2223 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2224 return;
2225
2226 switch (data->interface_status.ievent) {
2227 case EVENT_INTERFACE_ADDED:
2228 if (!wpa_s->interface_removed)
2229 break;
2230 wpa_s->interface_removed = 0;
f049052b 2231 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
6fc6879b 2232 if (wpa_supplicant_driver_init(wpa_s) < 0) {
f049052b
BG
2233 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2234 "driver after interface was added");
6fc6879b 2235 }
cb6710a4 2236 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6fc6879b
JM
2237 break;
2238 case EVENT_INTERFACE_REMOVED:
f049052b 2239 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
6fc6879b
JM
2240 wpa_s->interface_removed = 1;
2241 wpa_supplicant_mark_disassoc(wpa_s);
cb6710a4 2242 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6fc6879b
JM
2243 l2_packet_deinit(wpa_s->l2);
2244 wpa_s->l2 = NULL;
ea244d21 2245#ifdef CONFIG_IBSS_RSN
78177a00
JM
2246 ibss_rsn_deinit(wpa_s->ibss_rsn);
2247 wpa_s->ibss_rsn = NULL;
ea244d21 2248#endif /* CONFIG_IBSS_RSN */
a83d9c96
SL
2249#ifdef CONFIG_TERMINATE_ONLASTIF
2250 /* check if last interface */
2251 if (!any_interfaces(wpa_s->global->ifaces))
2252 eloop_terminate();
2253#endif /* CONFIG_TERMINATE_ONLASTIF */
6fc6879b
JM
2254 break;
2255 }
2256}
2257
2258
2259#ifdef CONFIG_PEERKEY
2260static void
2261wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2262 union wpa_event_data *data)
2263{
2264 if (data == NULL)
2265 return;
2266 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2267}
2268#endif /* CONFIG_PEERKEY */
2269
2270
281ff0aa
GP
2271#ifdef CONFIG_TDLS
2272static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2273 union wpa_event_data *data)
2274{
2275 if (data == NULL)
2276 return;
2277 switch (data->tdls.oper) {
2278 case TDLS_REQUEST_SETUP:
3887878e
SD
2279 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2280 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2281 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2282 else
2283 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
281ff0aa
GP
2284 break;
2285 case TDLS_REQUEST_TEARDOWN:
f2e698de 2286 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
7de27409 2287 data->tdls.reason_code);
281ff0aa
GP
2288 break;
2289 }
2290}
2291#endif /* CONFIG_TDLS */
2292
2293
ad3872a3 2294#ifdef CONFIG_WNM
75cad1a0
XC
2295static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2296 union wpa_event_data *data)
2297{
2298 if (data == NULL)
2299 return;
2300 switch (data->wnm.oper) {
2301 case WNM_OPER_SLEEP:
2302 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2303 "(action=%d, intval=%d)",
2304 data->wnm.sleep_action, data->wnm.sleep_intval);
2305 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
cd0ef657 2306 data->wnm.sleep_intval, NULL);
75cad1a0
XC
2307 break;
2308 }
2309}
ad3872a3 2310#endif /* CONFIG_WNM */
75cad1a0
XC
2311
2312
6fc6879b
JM
2313#ifdef CONFIG_IEEE80211R
2314static void
2315wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2316 union wpa_event_data *data)
2317{
2318 if (data == NULL)
2319 return;
2320
2321 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2322 data->ft_ies.ies_len,
2323 data->ft_ies.ft_action,
babfbf15
JM
2324 data->ft_ies.target_ap,
2325 data->ft_ies.ric_ies,
2326 data->ft_ies.ric_ies_len) < 0) {
6fc6879b
JM
2327 /* TODO: prevent MLME/driver from trying to associate? */
2328 }
2329}
2330#endif /* CONFIG_IEEE80211R */
2331
2332
11ef8d35
JM
2333#ifdef CONFIG_IBSS_RSN
2334static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2335 union wpa_event_data *data)
2336{
df4bc509 2337 struct wpa_ssid *ssid;
df418245
XC
2338 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2339 return;
11ef8d35
JM
2340 if (data == NULL)
2341 return;
df4bc509
JM
2342 ssid = wpa_s->current_ssid;
2343 if (ssid == NULL)
2344 return;
2345 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2346 return;
2347
11ef8d35
JM
2348 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2349}
13adc57b
AQ
2350
2351
2352static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2353 union wpa_event_data *data)
2354{
2355 struct wpa_ssid *ssid = wpa_s->current_ssid;
2356
2357 if (ssid == NULL)
2358 return;
2359
2360 /* check if the ssid is correctly configured as IBSS/RSN */
2361 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2362 return;
2363
2364 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2365 data->rx_mgmt.frame_len);
2366}
11ef8d35
JM
2367#endif /* CONFIG_IBSS_RSN */
2368
2369
036f7c4a
JM
2370#ifdef CONFIG_IEEE80211R
2371static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2372 size_t len)
2373{
2374 const u8 *sta_addr, *target_ap_addr;
2375 u16 status;
2376
2377 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2378 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2379 return; /* only SME case supported for now */
2380 if (len < 1 + 2 * ETH_ALEN + 2)
2381 return;
2382 if (data[0] != 2)
2383 return; /* Only FT Action Response is supported for now */
2384 sta_addr = data + 1;
2385 target_ap_addr = data + 1 + ETH_ALEN;
2386 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
f049052b
BG
2387 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2388 MACSTR " TargetAP " MACSTR " status %u",
2389 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
036f7c4a
JM
2390
2391 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
f049052b
BG
2392 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2393 " in FT Action Response", MAC2STR(sta_addr));
036f7c4a
JM
2394 return;
2395 }
2396
2397 if (status) {
f049052b
BG
2398 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2399 "failure (status code %d)", status);
036f7c4a
JM
2400 /* TODO: report error to FT code(?) */
2401 return;
2402 }
2403
2404 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2405 len - (1 + 2 * ETH_ALEN + 2), 1,
2406 target_ap_addr, NULL, 0) < 0)
2407 return;
2408
fe191985
JM
2409#ifdef CONFIG_SME
2410 {
2411 struct wpa_bss *bss;
2412 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2413 if (bss)
2414 wpa_s->sme.freq = bss->freq;
62c72d72 2415 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
fe191985
JM
2416 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2417 WLAN_AUTH_FT);
2418 }
2419#endif /* CONFIG_SME */
036f7c4a
JM
2420}
2421#endif /* CONFIG_IEEE80211R */
2422
2423
7d878ca7
JM
2424static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2425 struct unprot_deauth *e)
2426{
2427#ifdef CONFIG_IEEE80211W
2428 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2429 "dropped: " MACSTR " -> " MACSTR
2430 " (reason code %u)",
2431 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2432 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2433#endif /* CONFIG_IEEE80211W */
2434}
2435
2436
2437static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2438 struct unprot_disassoc *e)
2439{
2440#ifdef CONFIG_IEEE80211W
2441 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2442 "dropped: " MACSTR " -> " MACSTR
2443 " (reason code %u)",
2444 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2445 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2446#endif /* CONFIG_IEEE80211W */
2447}
2448
2449
d7df0fa7
JM
2450static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2451 u16 reason_code, int locally_generated,
2452 const u8 *ie, size_t ie_len, int deauth)
2453{
2454#ifdef CONFIG_AP
2455 if (wpa_s->ap_iface && addr) {
2456 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2457 return;
2458 }
2459
2460 if (wpa_s->ap_iface) {
2461 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2462 return;
2463 }
2464#endif /* CONFIG_AP */
2465
2466 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2467
2468 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2469 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2470 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2471 eapol_sm_failed(wpa_s->eapol)))
2472 wpas_auth_failed(wpa_s);
2473
2474#ifdef CONFIG_P2P
2475 if (deauth && ie && ie_len > 0) {
2476 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2477 locally_generated) > 0) {
2478 /*
2479 * The interface was removed, so cannot continue
2480 * processing any additional operations after this.
2481 */
2482 return;
2483 }
2484 }
2485#endif /* CONFIG_P2P */
2486
2487 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2488 locally_generated);
2489}
2490
2491
2492static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2493 struct disassoc_info *info)
2494{
2495 u16 reason_code = 0;
2496 int locally_generated = 0;
2497 const u8 *addr = NULL;
2498 const u8 *ie = NULL;
2499 size_t ie_len = 0;
2500
2501 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2502
2503 if (info) {
2504 addr = info->addr;
2505 ie = info->ie;
2506 ie_len = info->ie_len;
2507 reason_code = info->reason_code;
2508 locally_generated = info->locally_generated;
2509 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2510 locally_generated ? " (locally generated)" : "");
2511 if (addr)
2512 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2513 MAC2STR(addr));
2514 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2515 ie, ie_len);
2516 }
2517
2518#ifdef CONFIG_AP
2519 if (wpa_s->ap_iface && info && info->addr) {
2520 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2521 return;
2522 }
2523
2524 if (wpa_s->ap_iface) {
2525 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2526 return;
2527 }
2528#endif /* CONFIG_AP */
2529
2530#ifdef CONFIG_P2P
2531 if (info) {
2532 wpas_p2p_disassoc_notif(
2533 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2534 locally_generated);
2535 }
2536#endif /* CONFIG_P2P */
2537
2538 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2539 sme_event_disassoc(wpa_s, info);
2540
2541 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2542 ie, ie_len, 0);
2543}
2544
2545
2546static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2547 struct deauth_info *info)
2548{
2549 u16 reason_code = 0;
2550 int locally_generated = 0;
2551 const u8 *addr = NULL;
2552 const u8 *ie = NULL;
2553 size_t ie_len = 0;
2554
2555 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2556
2557 if (info) {
2558 addr = info->addr;
2559 ie = info->ie;
2560 ie_len = info->ie_len;
2561 reason_code = info->reason_code;
2562 locally_generated = info->locally_generated;
2563 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2564 reason_code,
2565 locally_generated ? " (locally generated)" : "");
2566 if (addr) {
2567 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2568 MAC2STR(addr));
2569 }
2570 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2571 ie, ie_len);
2572 }
2573
2574 wpa_reset_ft_completed(wpa_s->wpa);
2575
2576 wpas_event_disconnect(wpa_s, addr, reason_code,
2577 locally_generated, ie, ie_len, 1);
2578}
2579
2580
9646a8ab 2581void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6fc6879b
JM
2582 union wpa_event_data *data)
2583{
2584 struct wpa_supplicant *wpa_s = ctx;
2585
8401a6b0
JM
2586 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2587 event != EVENT_INTERFACE_ENABLED &&
9b6f44cb
JM
2588 event != EVENT_INTERFACE_STATUS &&
2589 event != EVENT_SCHED_SCAN_STOPPED) {
6c3771d7
BG
2590 wpa_dbg(wpa_s, MSG_DEBUG,
2591 "Ignore event %s (%d) while interface is disabled",
2592 event_to_string(event), event);
8401a6b0
JM
2593 return;
2594 }
2595
74781dfc
JM
2596#ifndef CONFIG_NO_STDOUT_DEBUG
2597{
2598 int level = MSG_DEBUG;
2599
eab6f5e0 2600 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
74781dfc
JM
2601 const struct ieee80211_hdr *hdr;
2602 u16 fc;
2603 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2604 fc = le_to_host16(hdr->frame_control);
2605 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2606 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2607 level = MSG_EXCESSIVE;
2608 }
2609
2610 wpa_dbg(wpa_s, level, "Event %s (%d) received",
6c3771d7 2611 event_to_string(event), event);
74781dfc
JM
2612}
2613#endif /* CONFIG_NO_STDOUT_DEBUG */
9b7124b2 2614
6fc6879b 2615 switch (event) {
c2a04078
JM
2616 case EVENT_AUTH:
2617 sme_event_auth(wpa_s, data);
2618 break;
6fc6879b
JM
2619 case EVENT_ASSOC:
2620 wpa_supplicant_event_assoc(wpa_s, data);
2621 break;
2622 case EVENT_DISASSOC:
d7df0fa7
JM
2623 wpas_event_disassoc(wpa_s,
2624 data ? &data->disassoc_info : NULL);
2625 break;
a84ed99e 2626 case EVENT_DEAUTH:
d7df0fa7
JM
2627 wpas_event_deauth(wpa_s,
2628 data ? &data->deauth_info : NULL);
6fc6879b
JM
2629 break;
2630 case EVENT_MICHAEL_MIC_FAILURE:
2631 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2632 break;
2633#ifndef CONFIG_NO_SCAN_PROCESSING
2634 case EVENT_SCAN_RESULTS:
8d923a4a 2635 wpa_supplicant_event_scan_results(wpa_s, data);
f85f545e
JM
2636 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2637 wpa_s->wpa_state != WPA_ASSOCIATING)
2638 wpas_p2p_continue_after_scan(wpa_s);
6fc6879b
JM
2639 break;
2640#endif /* CONFIG_NO_SCAN_PROCESSING */
2641 case EVENT_ASSOCINFO:
2642 wpa_supplicant_event_associnfo(wpa_s, data);
2643 break;
2644 case EVENT_INTERFACE_STATUS:
2645 wpa_supplicant_event_interface_status(wpa_s, data);
2646 break;
2647 case EVENT_PMKID_CANDIDATE:
2648 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2649 break;
2650#ifdef CONFIG_PEERKEY
2651 case EVENT_STKSTART:
2652 wpa_supplicant_event_stkstart(wpa_s, data);
2653 break;
2654#endif /* CONFIG_PEERKEY */
281ff0aa
GP
2655#ifdef CONFIG_TDLS
2656 case EVENT_TDLS:
2657 wpa_supplicant_event_tdls(wpa_s, data);
2658 break;
2659#endif /* CONFIG_TDLS */
ad3872a3 2660#ifdef CONFIG_WNM
75cad1a0
XC
2661 case EVENT_WNM:
2662 wpa_supplicant_event_wnm(wpa_s, data);
2663 break;
ad3872a3 2664#endif /* CONFIG_WNM */
6fc6879b
JM
2665#ifdef CONFIG_IEEE80211R
2666 case EVENT_FT_RESPONSE:
2667 wpa_supplicant_event_ft_response(wpa_s, data);
2668 break;
2669#endif /* CONFIG_IEEE80211R */
11ef8d35
JM
2670#ifdef CONFIG_IBSS_RSN
2671 case EVENT_IBSS_RSN_START:
2672 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2673 break;
2674#endif /* CONFIG_IBSS_RSN */
efa46078 2675 case EVENT_ASSOC_REJECT:
c05d6d18
JM
2676 if (data->assoc_reject.bssid)
2677 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2678 "bssid=" MACSTR " status_code=%u",
2679 MAC2STR(data->assoc_reject.bssid),
2680 data->assoc_reject.status_code);
2681 else
2682 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2683 "status_code=%u",
2684 data->assoc_reject.status_code);
ea78c315
JM
2685 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2686 sme_event_assoc_reject(wpa_s, data);
10737aba
JM
2687 else {
2688 const u8 *bssid = data->assoc_reject.bssid;
2689 if (bssid == NULL || is_zero_ether_addr(bssid))
2690 bssid = wpa_s->pending_bssid;
2691 wpas_connection_failed(wpa_s, bssid);
2692 wpa_supplicant_mark_disassoc(wpa_s);
2693 }
efa46078 2694 break;
da1fb17c 2695 case EVENT_AUTH_TIMED_OUT:
ea78c315
JM
2696 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2697 sme_event_auth_timed_out(wpa_s, data);
da1fb17c
JM
2698 break;
2699 case EVENT_ASSOC_TIMED_OUT:
ea78c315
JM
2700 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2701 sme_event_assoc_timed_out(wpa_s, data);
da1fb17c 2702 break;
f8b1f695 2703 case EVENT_TX_STATUS:
f049052b
BG
2704 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2705 " type=%d stype=%d",
2706 MAC2STR(data->tx_status.dst),
2707 data->tx_status.type, data->tx_status.stype);
24f6497c 2708#ifdef CONFIG_AP
9bae1be0 2709 if (wpa_s->ap_iface == NULL) {
24f6497c 2710#ifdef CONFIG_OFFCHANNEL
9bae1be0
JM
2711 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2712 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
24f6497c 2713 offchannel_send_action_tx_status(
9bae1be0
JM
2714 wpa_s, data->tx_status.dst,
2715 data->tx_status.data,
2716 data->tx_status.data_len,
93b7ddd0 2717 data->tx_status.ack ?
24f6497c
JM
2718 OFFCHANNEL_SEND_ACTION_SUCCESS :
2719 OFFCHANNEL_SEND_ACTION_NO_ACK);
2720#endif /* CONFIG_OFFCHANNEL */
9bae1be0
JM
2721 break;
2722 }
24f6497c
JM
2723#endif /* CONFIG_AP */
2724#ifdef CONFIG_OFFCHANNEL
f049052b
BG
2725 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2726 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
9bae1be0
JM
2727 /*
2728 * Catch TX status events for Action frames we sent via group
2729 * interface in GO mode.
2730 */
2731 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2732 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2733 os_memcmp(wpa_s->parent->pending_action_dst,
2734 data->tx_status.dst, ETH_ALEN) == 0) {
24f6497c 2735 offchannel_send_action_tx_status(
9bae1be0
JM
2736 wpa_s->parent, data->tx_status.dst,
2737 data->tx_status.data,
2738 data->tx_status.data_len,
1d39378a 2739 data->tx_status.ack ?
24f6497c
JM
2740 OFFCHANNEL_SEND_ACTION_SUCCESS :
2741 OFFCHANNEL_SEND_ACTION_NO_ACK);
f8b1f695 2742 break;
9bae1be0 2743 }
24f6497c
JM
2744#endif /* CONFIG_OFFCHANNEL */
2745#ifdef CONFIG_AP
f8b1f695
JM
2746 switch (data->tx_status.type) {
2747 case WLAN_FC_TYPE_MGMT:
2748 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2749 data->tx_status.data_len,
2750 data->tx_status.stype,
2751 data->tx_status.ack);
2752 break;
2753 case WLAN_FC_TYPE_DATA:
2754 ap_tx_status(wpa_s, data->tx_status.dst,
2755 data->tx_status.data,
2756 data->tx_status.data_len,
2757 data->tx_status.ack);
2758 break;
2759 }
24f6497c 2760#endif /* CONFIG_AP */
f8b1f695 2761 break;
24f6497c 2762#ifdef CONFIG_AP
dd840f79
JB
2763 case EVENT_EAPOL_TX_STATUS:
2764 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2765 data->eapol_tx_status.data,
2766 data->eapol_tx_status.data_len,
2767 data->eapol_tx_status.ack);
2768 break;
bcf24348
JB
2769 case EVENT_DRIVER_CLIENT_POLL_OK:
2770 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2771 break;
f8b1f695
JM
2772 case EVENT_RX_FROM_UNKNOWN:
2773 if (wpa_s->ap_iface == NULL)
2774 break;
9b90955e
JB
2775 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2776 data->rx_from_unknown.wds);
f8b1f695 2777 break;
1b487b8b
TP
2778 case EVENT_CH_SWITCH:
2779 if (!data)
2780 break;
2781 if (!wpa_s->ap_iface) {
2782 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2783 "event in non-AP mode");
2784 break;
2785 }
2786
1b487b8b
TP
2787 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2788 data->ch_switch.ht_enabled,
2789 data->ch_switch.ch_offset);
1b487b8b 2790 break;
13adc57b
AQ
2791#endif /* CONFIG_AP */
2792#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
2d43d37f
JB
2793 case EVENT_RX_MGMT: {
2794 u16 fc, stype;
2795 const struct ieee80211_mgmt *mgmt;
2796
2797 mgmt = (const struct ieee80211_mgmt *)
2798 data->rx_mgmt.frame;
2799 fc = le_to_host16(mgmt->frame_control);
2800 stype = WLAN_FC_GET_STYPE(fc);
2801
13adc57b 2802#ifdef CONFIG_AP
9bae1be0 2803 if (wpa_s->ap_iface == NULL) {
13adc57b 2804#endif /* CONFIG_AP */
9bae1be0 2805#ifdef CONFIG_P2P
9bae1be0
JM
2806 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2807 data->rx_mgmt.frame_len > 24) {
2808 const u8 *src = mgmt->sa;
2809 const u8 *ie = mgmt->u.probe_req.variable;
2810 size_t ie_len = data->rx_mgmt.frame_len -
2811 (mgmt->u.probe_req.variable -
2812 data->rx_mgmt.frame);
baf513d6
JB
2813 wpas_p2p_probe_req_rx(
2814 wpa_s, src, mgmt->da,
2815 mgmt->bssid, ie, ie_len,
2816 data->rx_mgmt.ssi_signal);
9bae1be0
JM
2817 break;
2818 }
2819#endif /* CONFIG_P2P */
13adc57b
AQ
2820#ifdef CONFIG_IBSS_RSN
2821 if (stype == WLAN_FC_STYPE_AUTH &&
2822 data->rx_mgmt.frame_len >= 30) {
2823 wpa_supplicant_event_ibss_auth(wpa_s, data);
2824 break;
2825 }
2826#endif /* CONFIG_IBSS_RSN */
f049052b
BG
2827 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2828 "management frame in non-AP mode");
f8b1f695 2829 break;
13adc57b 2830#ifdef CONFIG_AP
9bae1be0 2831 }
2d43d37f
JB
2832
2833 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2834 data->rx_mgmt.frame_len > 24) {
2835 const u8 *ie = mgmt->u.probe_req.variable;
2836 size_t ie_len = data->rx_mgmt.frame_len -
2837 (mgmt->u.probe_req.variable -
2838 data->rx_mgmt.frame);
2839
2840 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2841 mgmt->bssid, ie, ie_len,
2842 data->rx_mgmt.ssi_signal);
2d43d37f
JB
2843 }
2844
2a8b7416 2845 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
13adc57b 2846#endif /* CONFIG_AP */
f8b1f695 2847 break;
2d43d37f 2848 }
13adc57b 2849#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
036f7c4a 2850 case EVENT_RX_ACTION:
f049052b
BG
2851 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2852 " Category=%u DataLen=%d freq=%d MHz",
2853 MAC2STR(data->rx_action.sa),
2854 data->rx_action.category, (int) data->rx_action.len,
2855 data->rx_action.freq);
036f7c4a
JM
2856#ifdef CONFIG_IEEE80211R
2857 if (data->rx_action.category == WLAN_ACTION_FT) {
2858 ft_rx_action(wpa_s, data->rx_action.data,
2859 data->rx_action.len);
2860 break;
2861 }
2862#endif /* CONFIG_IEEE80211R */
7d878ca7
JM
2863#ifdef CONFIG_IEEE80211W
2864#ifdef CONFIG_SME
2865 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2866 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2867 data->rx_action.data,
2868 data->rx_action.len);
2869 break;
2870 }
2871#endif /* CONFIG_SME */
2872#endif /* CONFIG_IEEE80211W */
ad3872a3 2873#ifdef CONFIG_WNM
75cad1a0
XC
2874 if (data->rx_action.category == WLAN_ACTION_WNM) {
2875 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2876 break;
2877 }
ad3872a3 2878#endif /* CONFIG_WNM */
04ea7b79
JM
2879#ifdef CONFIG_GAS
2880 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2881 gas_query_rx(wpa_s->gas, data->rx_action.da,
2882 data->rx_action.sa, data->rx_action.bssid,
2883 data->rx_action.data, data->rx_action.len,
2884 data->rx_action.freq) == 0)
2885 break;
2886#endif /* CONFIG_GAS */
35287637
AN
2887#ifdef CONFIG_TDLS
2888 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2889 data->rx_action.len >= 4 &&
2890 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2891 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2892 "Response from " MACSTR,
2893 MAC2STR(data->rx_action.sa));
2894 break;
2895 }
2896#endif /* CONFIG_TDLS */
9bae1be0
JM
2897#ifdef CONFIG_P2P
2898 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2899 data->rx_action.sa,
2900 data->rx_action.bssid,
2901 data->rx_action.category,
2902 data->rx_action.data,
2903 data->rx_action.len, data->rx_action.freq);
e67b55fb
JM
2904#endif /* CONFIG_P2P */
2905 break;
2906 case EVENT_RX_PROBE_REQ:
b211f3eb
JM
2907 if (data->rx_probe_req.sa == NULL ||
2908 data->rx_probe_req.ie == NULL)
2909 break;
e67b55fb
JM
2910#ifdef CONFIG_AP
2911 if (wpa_s->ap_iface) {
2912 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2913 data->rx_probe_req.sa,
04a85e44
JM
2914 data->rx_probe_req.da,
2915 data->rx_probe_req.bssid,
e67b55fb 2916 data->rx_probe_req.ie,
baf513d6
JB
2917 data->rx_probe_req.ie_len,
2918 data->rx_probe_req.ssi_signal);
e67b55fb
JM
2919 break;
2920 }
2921#endif /* CONFIG_AP */
2922#ifdef CONFIG_P2P
2923 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
04a85e44
JM
2924 data->rx_probe_req.da,
2925 data->rx_probe_req.bssid,
e67b55fb 2926 data->rx_probe_req.ie,
baf513d6
JB
2927 data->rx_probe_req.ie_len,
2928 data->rx_probe_req.ssi_signal);
9bae1be0 2929#endif /* CONFIG_P2P */
036f7c4a 2930 break;
9bae1be0 2931 case EVENT_REMAIN_ON_CHANNEL:
24f6497c
JM
2932#ifdef CONFIG_OFFCHANNEL
2933 offchannel_remain_on_channel_cb(
2934 wpa_s, data->remain_on_channel.freq,
2935 data->remain_on_channel.duration);
2936#endif /* CONFIG_OFFCHANNEL */
2937#ifdef CONFIG_P2P
9bae1be0
JM
2938 wpas_p2p_remain_on_channel_cb(
2939 wpa_s, data->remain_on_channel.freq,
2940 data->remain_on_channel.duration);
24f6497c 2941#endif /* CONFIG_P2P */
9bae1be0
JM
2942 break;
2943 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
24f6497c
JM
2944#ifdef CONFIG_OFFCHANNEL
2945 offchannel_cancel_remain_on_channel_cb(
2946 wpa_s, data->remain_on_channel.freq);
2947#endif /* CONFIG_OFFCHANNEL */
2948#ifdef CONFIG_P2P
9bae1be0
JM
2949 wpas_p2p_cancel_remain_on_channel_cb(
2950 wpa_s, data->remain_on_channel.freq);
24f6497c 2951#endif /* CONFIG_P2P */
9bae1be0 2952 break;
24f6497c 2953#ifdef CONFIG_P2P
c5db8e51
KRK
2954 case EVENT_P2P_DEV_FOUND: {
2955 struct p2p_peer_info peer_info;
2956
2957 os_memset(&peer_info, 0, sizeof(peer_info));
2958 if (data->p2p_dev_found.dev_addr)
2959 os_memcpy(peer_info.p2p_device_addr,
2960 data->p2p_dev_found.dev_addr, ETH_ALEN);
2961 if (data->p2p_dev_found.pri_dev_type)
2962 os_memcpy(peer_info.pri_dev_type,
2963 data->p2p_dev_found.pri_dev_type,
2964 sizeof(peer_info.pri_dev_type));
2965 if (data->p2p_dev_found.dev_name)
2966 os_strlcpy(peer_info.device_name,
2967 data->p2p_dev_found.dev_name,
2968 sizeof(peer_info.device_name));
2969 peer_info.config_methods = data->p2p_dev_found.config_methods;
2970 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2971 peer_info.group_capab = data->p2p_dev_found.group_capab;
2972
8fd7dc1b
JB
2973 /*
2974 * FIX: new_device=1 is not necessarily correct. We should
2975 * maintain a P2P peer database in wpa_supplicant and update
2976 * this information based on whether the peer is truly new.
2977 */
2978 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3ac17eba 2979 break;
c5db8e51 2980 }
3ac17eba
JM
2981 case EVENT_P2P_GO_NEG_REQ_RX:
2982 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2983 data->p2p_go_neg_req_rx.dev_passwd_id);
2984 break;
2985 case EVENT_P2P_GO_NEG_COMPLETED:
2986 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2987 break;
2988 case EVENT_P2P_PROV_DISC_REQUEST:
2989 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2990 data->p2p_prov_disc_req.config_methods,
2991 data->p2p_prov_disc_req.dev_addr,
2992 data->p2p_prov_disc_req.pri_dev_type,
2993 data->p2p_prov_disc_req.dev_name,
2994 data->p2p_prov_disc_req.supp_config_methods,
2995 data->p2p_prov_disc_req.dev_capab,
c3f42784
JM
2996 data->p2p_prov_disc_req.group_capab,
2997 NULL, 0);
3ac17eba
JM
2998 break;
2999 case EVENT_P2P_PROV_DISC_RESPONSE:
3000 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3001 data->p2p_prov_disc_resp.config_methods);
3002 break;
3003 case EVENT_P2P_SD_REQUEST:
3004 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3005 data->p2p_sd_req.sa,
3006 data->p2p_sd_req.dialog_token,
3007 data->p2p_sd_req.update_indic,
3008 data->p2p_sd_req.tlvs,
3009 data->p2p_sd_req.tlvs_len);
3010 break;
3011 case EVENT_P2P_SD_RESPONSE:
3012 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3013 data->p2p_sd_resp.update_indic,
3014 data->p2p_sd_resp.tlvs,
3015 data->p2p_sd_resp.tlvs_len);
3016 break;
9bae1be0 3017#endif /* CONFIG_P2P */
a8e0505b
JM
3018 case EVENT_EAPOL_RX:
3019 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3020 data->eapol_rx.data,
3021 data->eapol_rx.data_len);
3022 break;
e2f74005
JM
3023 case EVENT_SIGNAL_CHANGE:
3024 bgscan_notify_signal_change(
60a972a6 3025 wpa_s, data->signal_change.above_threshold,
174fa789
PS
3026 data->signal_change.current_signal,
3027 data->signal_change.current_noise,
3028 data->signal_change.current_txrate);
e2f74005 3029 break;
8401a6b0 3030 case EVENT_INTERFACE_ENABLED:
f049052b 3031 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
8401a6b0 3032 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
bfba8deb 3033 wpa_supplicant_update_mac_addr(wpa_s);
199716ad 3034#ifdef CONFIG_AP
9919f7a2
JB
3035 if (!wpa_s->ap_iface) {
3036 wpa_supplicant_set_state(wpa_s,
3037 WPA_DISCONNECTED);
3038 wpa_supplicant_req_scan(wpa_s, 0, 0);
3039 } else
3040 wpa_supplicant_set_state(wpa_s,
3041 WPA_COMPLETED);
199716ad
BG
3042#else /* CONFIG_AP */
3043 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3044 wpa_supplicant_req_scan(wpa_s, 0, 0);
3045#endif /* CONFIG_AP */
8401a6b0
JM
3046 }
3047 break;
3048 case EVENT_INTERFACE_DISABLED:
f049052b 3049 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
8401a6b0
JM
3050 wpa_supplicant_mark_disassoc(wpa_s);
3051 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3052 break;
b5c9da8d 3053 case EVENT_CHANNEL_LIST_CHANGED:
35c5d610
JM
3054 if (wpa_s->drv_priv == NULL)
3055 break; /* Ignore event during drv initialization */
6979582c
JM
3056
3057 free_hw_features(wpa_s);
3058 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
3059 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3060
b5c9da8d
JM
3061#ifdef CONFIG_P2P
3062 wpas_p2p_update_channel_list(wpa_s);
c973f386
JM
3063#endif /* CONFIG_P2P */
3064 break;
3065 case EVENT_INTERFACE_UNAVAILABLE:
3066#ifdef CONFIG_P2P
3067 wpas_p2p_interface_unavailable(wpa_s);
7cfc4ac3
AGS
3068#endif /* CONFIG_P2P */
3069 break;
3070 case EVENT_BEST_CHANNEL:
f049052b
BG
3071 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3072 "(%d %d %d)",
3073 data->best_chan.freq_24, data->best_chan.freq_5,
3074 data->best_chan.freq_overall);
7cfc4ac3
AGS
3075 wpa_s->best_24_freq = data->best_chan.freq_24;
3076 wpa_s->best_5_freq = data->best_chan.freq_5;
3077 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3078#ifdef CONFIG_P2P
3079 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3080 data->best_chan.freq_5,
3081 data->best_chan.freq_overall);
b5c9da8d
JM
3082#endif /* CONFIG_P2P */
3083 break;
7d878ca7
JM
3084 case EVENT_UNPROT_DEAUTH:
3085 wpa_supplicant_event_unprot_deauth(wpa_s,
3086 &data->unprot_deauth);
3087 break;
3088 case EVENT_UNPROT_DISASSOC:
3089 wpa_supplicant_event_unprot_disassoc(wpa_s,
3090 &data->unprot_disassoc);
3091 break;
0d7e5a3a
JB
3092 case EVENT_STATION_LOW_ACK:
3093#ifdef CONFIG_AP
3094 if (wpa_s->ap_iface && data)
3095 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3096 data->low_ack.addr);
3097#endif /* CONFIG_AP */
8f15f711
AN
3098#ifdef CONFIG_TDLS
3099 if (data)
3100 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3101#endif /* CONFIG_TDLS */
0d7e5a3a 3102 break;
ea244d21
XC
3103 case EVENT_IBSS_PEER_LOST:
3104#ifdef CONFIG_IBSS_RSN
3105 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3106#endif /* CONFIG_IBSS_RSN */
3107 break;
b14a210c
JB
3108 case EVENT_DRIVER_GTK_REKEY:
3109 if (os_memcmp(data->driver_gtk_rekey.bssid,
3110 wpa_s->bssid, ETH_ALEN))
3111 break;
3112 if (!wpa_s->wpa)
3113 break;
3114 wpa_sm_update_replay_ctr(wpa_s->wpa,
3115 data->driver_gtk_rekey.replay_ctr);
3116 break;
cbdf3507
LC
3117 case EVENT_SCHED_SCAN_STOPPED:
3118 wpa_s->sched_scanning = 0;
3119 wpa_supplicant_notify_scanning(wpa_s, 0);
3120
9b6f44cb
JM
3121 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3122 break;
3123
cbdf3507
LC
3124 /*
3125 * If we timed out, start a new sched scan to continue
3126 * searching for more SSIDs.
3127 */
3128 if (wpa_s->sched_scan_timed_out)
3129 wpa_supplicant_req_sched_scan(wpa_s);
3130 break;
783fcb7d
GG
3131 case EVENT_WPS_BUTTON_PUSHED:
3132#ifdef CONFIG_WPS
3133 wpas_wps_start_pbc(wpa_s, NULL, 0);
3134#endif /* CONFIG_WPS */
3135 break;
3140803b
RM
3136 case EVENT_CONNECT_FAILED_REASON:
3137#ifdef CONFIG_AP
3138 if (!wpa_s->ap_iface || !data)
3139 break;
3140 hostapd_event_connect_failed_reason(
3141 wpa_s->ap_iface->bss[0],
3142 data->connect_failed_reason.addr,
3143 data->connect_failed_reason.code);
3144#endif /* CONFIG_AP */
3145 break;
6fc6879b 3146 default:
f049052b 3147 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6fc6879b
JM
3148 break;
3149 }
3150}