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