]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/events.c
P2P: Embed publically visible struct in peer info
[thirdparty/hostap.git] / wpa_supplicant / events.c
CommitLineData
6fc6879b
JM
1/*
2 * WPA Supplicant - Driver event processing
16a83d29 3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
6fc6879b
JM
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
15#include "includes.h"
16
17#include "common.h"
18#include "eapol_supp/eapol_supp_sm.h"
3acb5005 19#include "rsn_supp/wpa.h"
6fc6879b 20#include "eloop.h"
6fc6879b
JM
21#include "config.h"
22#include "l2_packet/l2_packet.h"
23#include "wpa_supplicant_i.h"
2d5b792d 24#include "driver_i.h"
6fc6879b 25#include "pcsc_funcs.h"
3acb5005
JM
26#include "rsn_supp/preauth.h"
27#include "rsn_supp/pmksa_cache.h"
90973fb2 28#include "common/wpa_ctrl.h"
6fc6879b 29#include "eap_peer/eap.h"
1d041bec 30#include "ap/hostapd.h"
93b7ddd0 31#include "p2p/p2p.h"
8bac466b 32#include "notify.h"
90973fb2 33#include "common/ieee802_11_defs.h"
54f489be 34#include "common/ieee802_11_common.h"
bbb921da 35#include "crypto/random.h"
6fc6879b
JM
36#include "blacklist.h"
37#include "wpas_glue.h"
351f09a2 38#include "wps_supplicant.h"
11ef8d35 39#include "ibss_rsn.h"
c2a04078 40#include "sme.h"
9bae1be0 41#include "p2p_supplicant.h"
60b94c98 42#include "bgscan.h"
f8b1f695 43#include "ap.h"
6fa81a3b 44#include "bss.h"
245519e0 45#include "mlme.h"
9ba9fa07 46#include "scan.h"
6fc6879b
JM
47
48
49static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
50{
8bac466b 51 struct wpa_ssid *ssid, *old_ssid;
6fc6879b
JM
52
53 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
54 return 0;
55
f049052b
BG
56 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
57 "information");
6fc6879b
JM
58 ssid = wpa_supplicant_get_ssid(wpa_s);
59 if (ssid == NULL) {
f049052b
BG
60 wpa_msg(wpa_s, MSG_INFO,
61 "No network configuration found for the current AP");
6fc6879b
JM
62 return -1;
63 }
64
65 if (ssid->disabled) {
f049052b 66 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
6fc6879b
JM
67 return -1;
68 }
69
f049052b
BG
70 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
71 "current AP");
6fc6879b
JM
72 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
73 WPA_KEY_MGMT_WPA_NONE |
56586197
JM
74 WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
75 WPA_KEY_MGMT_PSK_SHA256 |
76 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
6fc6879b
JM
77 u8 wpa_ie[80];
78 size_t wpa_ie_len = sizeof(wpa_ie);
79 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
80 wpa_ie, &wpa_ie_len);
81 } else {
82 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
83 }
84
85 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
86 eapol_sm_invalidate_cached_session(wpa_s->eapol);
8bac466b 87 old_ssid = wpa_s->current_ssid;
6fc6879b
JM
88 wpa_s->current_ssid = ssid;
89 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
90 wpa_supplicant_initiate_eapol(wpa_s);
8bac466b
JM
91 if (old_ssid != wpa_s->current_ssid)
92 wpas_notify_network_changed(wpa_s);
6fc6879b
JM
93
94 return 0;
95}
96
97
98static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
99 void *sock_ctx)
100{
101 struct wpa_supplicant *wpa_s = eloop_ctx;
102
103 if (wpa_s->countermeasures) {
104 wpa_s->countermeasures = 0;
105 wpa_drv_set_countermeasures(wpa_s, 0);
106 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
107 wpa_supplicant_req_scan(wpa_s, 0, 0);
108 }
109}
110
111
112void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
113{
8bac466b
JM
114 int bssid_changed;
115
8401a6b0
JM
116 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
117 return;
118
6fc6879b 119 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8bac466b 120 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
6fc6879b
JM
121 os_memset(wpa_s->bssid, 0, ETH_ALEN);
122 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
be8be671 123 wpa_s->current_bss = NULL;
3c85f144 124 wpa_s->assoc_freq = 0;
8bac466b
JM
125 if (bssid_changed)
126 wpas_notify_bssid_changed(wpa_s);
127
6fc6879b
JM
128 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
129 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
56586197 130 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
6fc6879b
JM
131 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
132 wpa_s->ap_ies_from_associnfo = 0;
133}
134
135
136static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
137{
138 struct wpa_ie_data ie;
139 int pmksa_set = -1;
140 size_t i;
141
142 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
143 ie.pmkid == NULL)
144 return;
145
146 for (i = 0; i < ie.num_pmkid; i++) {
147 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
148 ie.pmkid + i * PMKID_LEN,
149 NULL, NULL, 0);
150 if (pmksa_set == 0) {
151 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
152 break;
153 }
154 }
155
f049052b
BG
156 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
157 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
6fc6879b
JM
158}
159
160
161static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
162 union wpa_event_data *data)
163{
164 if (data == NULL) {
f049052b
BG
165 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
166 "event");
6fc6879b
JM
167 return;
168 }
f049052b
BG
169 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
170 " index=%d preauth=%d",
171 MAC2STR(data->pmkid_candidate.bssid),
172 data->pmkid_candidate.index,
173 data->pmkid_candidate.preauth);
6fc6879b
JM
174
175 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
176 data->pmkid_candidate.index,
177 data->pmkid_candidate.preauth);
178}
179
180
181static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
182{
183 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
184 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
185 return 0;
186
187#ifdef IEEE8021X_EAPOL
188 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
189 wpa_s->current_ssid &&
190 !(wpa_s->current_ssid->eapol_flags &
191 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
192 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
193 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
194 * plaintext or static WEP keys). */
195 return 0;
196 }
197#endif /* IEEE8021X_EAPOL */
198
199 return 1;
200}
201
202
203/**
204 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
205 * @wpa_s: pointer to wpa_supplicant data
206 * @ssid: Configuration data for the network
207 * Returns: 0 on success, -1 on failure
208 *
209 * This function is called when starting authentication with a network that is
210 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
211 */
212int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
213 struct wpa_ssid *ssid)
214{
215#ifdef IEEE8021X_EAPOL
216 int aka = 0, sim = 0, type;
217
218 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
219 return 0;
220
221 if (ssid->eap.eap_methods == NULL) {
222 sim = 1;
223 aka = 1;
224 } else {
225 struct eap_method_type *eap = ssid->eap.eap_methods;
226 while (eap->vendor != EAP_VENDOR_IETF ||
227 eap->method != EAP_TYPE_NONE) {
228 if (eap->vendor == EAP_VENDOR_IETF) {
229 if (eap->method == EAP_TYPE_SIM)
230 sim = 1;
231 else if (eap->method == EAP_TYPE_AKA)
232 aka = 1;
233 }
234 eap++;
235 }
236 }
237
238 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
239 sim = 0;
240 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
241 aka = 0;
242
243 if (!sim && !aka) {
f049052b
BG
244 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
245 "use SIM, but neither EAP-SIM nor EAP-AKA are "
246 "enabled");
6fc6879b
JM
247 return 0;
248 }
249
f049052b
BG
250 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
251 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
6fc6879b
JM
252 if (sim && aka)
253 type = SCARD_TRY_BOTH;
254 else if (aka)
255 type = SCARD_USIM_ONLY;
256 else
257 type = SCARD_GSM_SIM_ONLY;
258
259 wpa_s->scard = scard_init(type);
260 if (wpa_s->scard == NULL) {
f049052b
BG
261 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
262 "(pcsc-lite)");
6fc6879b
JM
263 return -1;
264 }
265 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
266 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
267#endif /* IEEE8021X_EAPOL */
268
269 return 0;
270}
271
272
273#ifndef CONFIG_NO_SCAN_PROCESSING
274static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
275 struct wpa_ssid *ssid)
276{
277 int i, privacy = 0;
278
279 if (ssid->mixed_cell)
280 return 1;
281
0632542b
AT
282#ifdef CONFIG_WPS
283 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
284 return 1;
285#endif /* CONFIG_WPS */
286
6fc6879b
JM
287 for (i = 0; i < NUM_WEP_KEYS; i++) {
288 if (ssid->wep_key_len[i]) {
289 privacy = 1;
290 break;
291 }
292 }
293#ifdef IEEE8021X_EAPOL
294 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
295 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
296 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
297 privacy = 1;
298#endif /* IEEE8021X_EAPOL */
299
300 if (bss->caps & IEEE80211_CAP_PRIVACY)
301 return privacy;
302 return !privacy;
303}
304
305
a6099152
JM
306static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
307 struct wpa_ssid *ssid,
6fc6879b
JM
308 struct wpa_scan_res *bss)
309{
310 struct wpa_ie_data ie;
311 int proto_match = 0;
312 const u8 *rsn_ie, *wpa_ie;
351f09a2 313 int ret;
43882f1e 314 int wep_ok;
6fc6879b 315
a6099152 316 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
351f09a2
JM
317 if (ret >= 0)
318 return ret;
ad08c363 319
43882f1e
JM
320 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
321 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
322 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
323 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
324 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
325
6fc6879b
JM
326 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
327 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
328 proto_match++;
329
330 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
f049052b
BG
331 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
332 "failed");
6fc6879b
JM
333 break;
334 }
43882f1e
JM
335
336 if (wep_ok &&
337 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
338 {
f049052b
BG
339 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
340 "in RSN IE");
43882f1e
JM
341 return 1;
342 }
343
6fc6879b 344 if (!(ie.proto & ssid->proto)) {
f049052b
BG
345 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
346 "mismatch");
6fc6879b
JM
347 break;
348 }
349
350 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
f049052b
BG
351 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
352 "cipher mismatch");
6fc6879b
JM
353 break;
354 }
355
356 if (!(ie.group_cipher & ssid->group_cipher)) {
f049052b
BG
357 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
358 "cipher mismatch");
6fc6879b
JM
359 break;
360 }
361
362 if (!(ie.key_mgmt & ssid->key_mgmt)) {
f049052b
BG
363 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
364 "mismatch");
6fc6879b
JM
365 break;
366 }
367
368#ifdef CONFIG_IEEE80211W
0b60b0aa 369 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
70f8cc8e 370 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
f049052b
BG
371 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
372 "frame protection");
6fc6879b
JM
373 break;
374 }
375#endif /* CONFIG_IEEE80211W */
376
f049052b 377 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
6fc6879b
JM
378 return 1;
379 }
380
381 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
382 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
383 proto_match++;
384
385 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
f049052b
BG
386 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
387 "failed");
6fc6879b
JM
388 break;
389 }
43882f1e
JM
390
391 if (wep_ok &&
392 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
393 {
f049052b
BG
394 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
395 "in WPA IE");
43882f1e
JM
396 return 1;
397 }
398
6fc6879b 399 if (!(ie.proto & ssid->proto)) {
f049052b
BG
400 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
401 "mismatch");
6fc6879b
JM
402 break;
403 }
404
405 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
f049052b
BG
406 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
407 "cipher mismatch");
6fc6879b
JM
408 break;
409 }
410
411 if (!(ie.group_cipher & ssid->group_cipher)) {
f049052b
BG
412 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
413 "cipher mismatch");
6fc6879b
JM
414 break;
415 }
416
417 if (!(ie.key_mgmt & ssid->key_mgmt)) {
f049052b
BG
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
419 "mismatch");
6fc6879b
JM
420 break;
421 }
422
f049052b 423 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
6fc6879b
JM
424 return 1;
425 }
426
cc5e390d 427 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
df83fb7d 428 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
f049052b 429 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
cc5e390d
JM
430 return 0;
431 }
6fc6879b 432
cc5e390d
JM
433 /* Allow in non-WPA configuration */
434 return 1;
6fc6879b
JM
435}
436
437
b766a9a2
JM
438static int freq_allowed(int *freqs, int freq)
439{
440 int i;
441
442 if (freqs == NULL)
443 return 1;
444
445 for (i = 0; freqs[i]; i++)
446 if (freqs[i] == freq)
447 return 1;
448 return 0;
449}
450
451
d8d940b7
JM
452static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
453 int i, struct wpa_scan_res *bss,
454 struct wpa_ssid *group)
6fc6879b 455{
d8d940b7
JM
456 const u8 *ssid_;
457 u8 wpa_ie_len, rsn_ie_len, ssid_len;
458 int wpa;
6fc6879b
JM
459 struct wpa_blacklist *e;
460 const u8 *ie;
d8d940b7 461 struct wpa_ssid *ssid;
6fc6879b 462
d8d940b7
JM
463 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
464 ssid_ = ie ? ie + 2 : (u8 *) "";
465 ssid_len = ie ? ie[1] : 0;
6fc6879b 466
d8d940b7
JM
467 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
468 wpa_ie_len = ie ? ie[1] : 0;
6fc6879b 469
d8d940b7
JM
470 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
471 rsn_ie_len = ie ? ie[1] : 0;
6fc6879b 472
f049052b
BG
473 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
474 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
475 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
476 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
477 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
9cf32261 478
d8d940b7 479 e = wpa_blacklist_get(wpa_s, bss->bssid);
5471c343
JM
480 if (e) {
481 int limit = 1;
482 if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
483 /*
484 * When only a single network is enabled, we can
485 * trigger blacklisting on the first failure. This
486 * should not be done with multiple enabled networks to
487 * avoid getting forced to move into a worse ESS on
488 * single error if there are no other BSSes of the
489 * current ESS.
490 */
491 limit = 0;
492 }
493 if (e->count > limit) {
f049052b
BG
494 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
495 "(count=%d limit=%d)", e->count, limit);
5471c343
JM
496 return 0;
497 }
d8d940b7 498 }
6fc6879b 499
d8d940b7 500 if (ssid_len == 0) {
f049052b 501 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
d8d940b7
JM
502 return 0;
503 }
e81634cd 504
d8d940b7 505 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
6fc6879b 506
d8d940b7
JM
507 for (ssid = group; ssid; ssid = ssid->pnext) {
508 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
ad08c363 509
d8d940b7 510 if (ssid->disabled) {
f049052b 511 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
0c703df3 512 continue;
d8d940b7 513 }
9cf32261 514
ad08c363 515#ifdef CONFIG_WPS
f648bc7d 516 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
f049052b
BG
517 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
518 "(WPS)");
f648bc7d
JM
519 continue;
520 }
521
d8d940b7
JM
522 if (wpa && ssid->ssid_len == 0 &&
523 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
524 check_ssid = 0;
525
526 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
527 /* Only allow wildcard SSID match if an AP
528 * advertises active WPS operation that matches
529 * with our mode. */
530 check_ssid = 1;
ad08c363 531 if (ssid->ssid_len == 0 &&
a6099152 532 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
ad08c363 533 check_ssid = 0;
d8d940b7 534 }
ad08c363
JM
535#endif /* CONFIG_WPS */
536
d8d940b7
JM
537 if (check_ssid &&
538 (ssid_len != ssid->ssid_len ||
539 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
f049052b 540 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
0c703df3 541 continue;
6fc6879b 542 }
6fc6879b 543
d8d940b7
JM
544 if (ssid->bssid_set &&
545 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
f049052b 546 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
0c703df3 547 continue;
d8d940b7 548 }
6fc6879b 549
cc5e390d 550 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
0c703df3 551 continue;
9cf32261 552
d8d940b7
JM
553 if (!wpa &&
554 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
555 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
556 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
f049052b
BG
557 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
558 "not allowed");
0c703df3 559 continue;
6fc6879b 560 }
9cf32261 561
d8d940b7 562 if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
f049052b
BG
563 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
564 "mismatch");
0c703df3 565 continue;
e81634cd
JM
566 }
567
d8d940b7 568 if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
f049052b
BG
569 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
570 "network");
0c703df3 571 continue;
d8d940b7 572 }
b766a9a2 573
d8d940b7 574 if (!freq_allowed(ssid->freq_list, bss->freq)) {
f049052b
BG
575 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
576 "allowed");
0c703df3 577 continue;
6fc6879b 578 }
d8d940b7 579
73e49269
JM
580#ifdef CONFIG_P2P
581 /*
582 * TODO: skip the AP if its P2P IE has Group Formation
583 * bit set in the P2P Group Capability Bitmap and we
584 * are not in Group Formation with that device.
585 */
586#endif /* CONFIG_P2P */
587
d8d940b7
JM
588 /* Matching configuration found */
589 return ssid;
6fc6879b
JM
590 }
591
d8d940b7
JM
592 /* No matching configuration found */
593 return 0;
9cf32261
JM
594}
595
596
6fa81a3b 597static struct wpa_bss *
a1fd2ce5
JM
598wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
599 struct wpa_scan_results *scan_res,
600 struct wpa_ssid *group,
9cf32261
JM
601 struct wpa_ssid **selected_ssid)
602{
d8d940b7 603 size_t i;
9cf32261 604
f049052b
BG
605 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
606 group->priority);
9cf32261 607
d8d940b7
JM
608 for (i = 0; i < scan_res->num; i++) {
609 struct wpa_scan_res *bss = scan_res->res[i];
610 const u8 *ie, *ssid;
611 u8 ssid_len;
612
613 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
614 if (!*selected_ssid)
615 continue;
616
617 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
618 ssid = ie ? ie + 2 : (u8 *) "";
619 ssid_len = ie ? ie[1] : 0;
9cf32261 620
f049052b
BG
621 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
622 " ssid='%s'",
623 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
d8d940b7
JM
624 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
625 }
626
627 return NULL;
6fc6879b
JM
628}
629
630
6fa81a3b 631static struct wpa_bss *
09b9df4e 632wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
a1fd2ce5 633 struct wpa_scan_results *scan_res,
09b9df4e 634 struct wpa_ssid **selected_ssid)
6fc6879b 635{
6fa81a3b 636 struct wpa_bss *selected = NULL;
09b9df4e
JM
637 int prio;
638
639 while (selected == NULL) {
640 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
641 selected = wpa_supplicant_select_bss(
a1fd2ce5 642 wpa_s, scan_res, wpa_s->conf->pssid[prio],
09b9df4e
JM
643 selected_ssid);
644 if (selected)
645 break;
646 }
647
648 if (selected == NULL && wpa_s->blacklist) {
f049052b
BG
649 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
650 "blacklist and try again");
09b9df4e
JM
651 wpa_blacklist_clear(wpa_s);
652 wpa_s->blacklist_cleared++;
653 } else if (selected == NULL)
654 break;
655 }
656
657 return selected;
658}
659
660
661static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
977b1174 662 int timeout_sec, int timeout_usec)
09b9df4e 663{
24f76940 664 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
4f34d51a
SL
665 /*
666 * No networks are enabled; short-circuit request so
667 * we don't wait timeout seconds before transitioning
668 * to INACTIVE state.
669 */
670 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
671 return;
09b9df4e 672 }
977b1174 673 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
09b9df4e
JM
674}
675
676
86d4f806
JM
677void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
678 struct wpa_bss *selected,
679 struct wpa_ssid *ssid)
09b9df4e
JM
680{
681 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
682 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
683 "PBC session overlap");
b73bf0a7
JM
684#ifdef CONFIG_P2P
685 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
686 return;
687#endif /* CONFIG_P2P */
199716ad
BG
688
689#ifdef CONFIG_WPS
7736f18b 690 wpas_wps_cancel(wpa_s);
199716ad 691#endif /* CONFIG_WPS */
09b9df4e
JM
692 return;
693 }
694
695 /*
696 * Do not trigger new association unless the BSSID has changed or if
697 * reassociation is requested. If we are in process of associating with
698 * the selected BSSID, do not trigger new attempt.
699 */
700 if (wpa_s->reassociate ||
701 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
e29853bb
BG
702 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
703 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
09b9df4e
JM
704 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
705 0))) {
706 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
977b1174 707 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
09b9df4e
JM
708 return;
709 }
e29853bb
BG
710 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
711 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
712 " pending: " MACSTR " wpa_state: %s",
713 wpa_s->reassociate, MAC2STR(selected->bssid),
714 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
715 wpa_supplicant_state_txt(wpa_s->wpa_state));
09b9df4e
JM
716 wpa_supplicant_associate(wpa_s, selected, ssid);
717 } else {
f049052b
BG
718 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
719 "selected AP");
09b9df4e 720 }
09b9df4e
JM
721}
722
723
b55aaa5f
JM
724static struct wpa_ssid *
725wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
726{
727 int prio;
728 struct wpa_ssid *ssid;
729
730 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
731 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
732 {
733 if (ssid->disabled)
734 continue;
735 if (ssid->mode == IEEE80211_MODE_IBSS ||
736 ssid->mode == IEEE80211_MODE_AP)
737 return ssid;
738 }
739 }
740 return NULL;
741}
742
743
a1fd2ce5
JM
744/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
745 * on BSS added and BSS changed events */
6ae93185 746static void wpa_supplicant_rsn_preauth_scan_results(
a1fd2ce5 747 struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
6ae93185
JM
748{
749 int i;
750
751 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
752 return;
753
a1fd2ce5 754 for (i = scan_res->num - 1; i >= 0; i--) {
6ae93185
JM
755 const u8 *ssid, *rsn;
756 struct wpa_scan_res *r;
757
a1fd2ce5 758 r = scan_res->res[i];
6ae93185
JM
759
760 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
761 if (ssid == NULL)
762 continue;
763
764 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
765 if (rsn == NULL)
766 continue;
767
768 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
769 }
770
771}
772
773
48563d86
JM
774static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
775 struct wpa_bss *selected,
776 struct wpa_ssid *ssid,
777 struct wpa_scan_results *scan_res)
778{
779 size_t i;
780 struct wpa_scan_res *current_bss = NULL;
781 int min_diff;
782
783 if (wpa_s->reassociate)
784 return 1; /* explicit request to reassociate */
785 if (wpa_s->wpa_state < WPA_ASSOCIATED)
786 return 1; /* we are not associated; continue */
787 if (wpa_s->current_ssid == NULL)
788 return 1; /* unknown current SSID */
789 if (wpa_s->current_ssid != ssid)
790 return 1; /* different network block */
791
792 for (i = 0; i < scan_res->num; i++) {
793 struct wpa_scan_res *res = scan_res->res[i];
794 const u8 *ie;
795 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
796 continue;
797
798 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
799 if (ie == NULL)
800 continue;
801 if (ie[1] != wpa_s->current_ssid->ssid_len ||
802 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
803 continue;
804 current_bss = res;
805 break;
806 }
807
808 if (!current_bss)
809 return 1; /* current BSS not seen in scan results */
810
f049052b
BG
811 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
812 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
813 MAC2STR(current_bss->bssid), current_bss->level);
814 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
815 MAC2STR(selected->bssid), selected->level);
48563d86 816
ac26ebd8
JM
817 if (wpa_s->current_ssid->bssid_set &&
818 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
819 0) {
f049052b
BG
820 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
821 "has preferred BSSID");
ac26ebd8
JM
822 return 1;
823 }
824
48563d86
JM
825 min_diff = 2;
826 if (current_bss->level < 0) {
827 if (current_bss->level < -85)
828 min_diff = 1;
829 else if (current_bss->level < -80)
830 min_diff = 2;
831 else if (current_bss->level < -75)
832 min_diff = 3;
833 else if (current_bss->level < -70)
834 min_diff = 4;
835 else
836 min_diff = 5;
837 }
838 if (abs(current_bss->level - selected->level) < min_diff) {
f049052b
BG
839 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
840 "in signal level");
48563d86
JM
841 return 0;
842 }
843
844 return 1;
845}
846
e1504976
BG
847/* Return < 0 if no scan results could be fetched. */
848static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
849 union wpa_event_data *data)
09b9df4e 850{
6fa81a3b 851 struct wpa_bss *selected;
6fc6879b 852 struct wpa_ssid *ssid = NULL;
a1fd2ce5 853 struct wpa_scan_results *scan_res;
5bc0cdb7
JM
854 int ap = 0;
855
856#ifdef CONFIG_AP
857 if (wpa_s->ap_iface)
858 ap = 1;
859#endif /* CONFIG_AP */
6fc6879b 860
cb8564b1
DW
861 wpa_supplicant_notify_scanning(wpa_s, 0);
862
a1fd2ce5
JM
863 scan_res = wpa_supplicant_get_scan_results(wpa_s,
864 data ? &data->scan_info :
865 NULL, 1);
866 if (scan_res == NULL) {
5bc0cdb7 867 if (wpa_s->conf->ap_scan == 2 || ap)
e1504976 868 return -1;
f049052b
BG
869 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
870 "scanning again");
977b1174 871 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
e1504976 872 return -1;
6fc6879b
JM
873 }
874
bbb921da
JM
875#ifndef CONFIG_NO_RANDOM_POOL
876 size_t i, num;
877 num = scan_res->num;
878 if (num > 10)
879 num = 10;
880 for (i = 0; i < num; i++) {
881 u8 buf[5];
882 struct wpa_scan_res *res = scan_res->res[i];
883 buf[0] = res->bssid[5];
884 buf[1] = res->qual & 0xff;
885 buf[2] = res->noise & 0xff;
886 buf[3] = res->level & 0xff;
887 buf[4] = res->tsf & 0xff;
888 random_add_randomness(buf, sizeof(buf));
889 }
890#endif /* CONFIG_NO_RANDOM_POOL */
891
64e58f51 892 if (wpa_s->scan_res_handler) {
860fddbb
JB
893 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
894 struct wpa_scan_results *scan_res);
895
896 scan_res_handler = wpa_s->scan_res_handler;
64e58f51 897 wpa_s->scan_res_handler = NULL;
860fddbb
JB
898 scan_res_handler(wpa_s, scan_res);
899
64e58f51 900 wpa_scan_results_free(scan_res);
e1504976 901 return 0;
64e58f51
JM
902 }
903
5bc0cdb7 904 if (ap) {
f049052b 905 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
5bc0cdb7 906 wpa_scan_results_free(scan_res);
e1504976 907 return 0;
5bc0cdb7
JM
908 }
909
f049052b 910 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
24f76940
JM
911 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
912 wpas_notify_scan_results(wpa_s);
6fc6879b 913
8bac466b
JM
914 wpas_notify_scan_done(wpa_s, 1);
915
a1fd2ce5
JM
916 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
917 wpa_scan_results_free(scan_res);
e1504976 918 return 0;
a1fd2ce5 919 }
6fc6879b 920
3180d7a2
SO
921 if (wpa_s->disconnected) {
922 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
a1fd2ce5 923 wpa_scan_results_free(scan_res);
e1504976 924 return 0;
3180d7a2
SO
925 }
926
c2594c36 927 if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
a1fd2ce5 928 wpa_scan_results_free(scan_res);
e1504976 929 return 0;
a1fd2ce5
JM
930 }
931
932 wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
60b94c98 933
a1fd2ce5 934 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
6ae93185 935
6fc6879b 936 if (selected) {
48563d86
JM
937 int skip;
938 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
939 scan_res);
940 wpa_scan_results_free(scan_res);
941 if (skip)
e1504976 942 return 0;
09b9df4e 943 wpa_supplicant_connect(wpa_s, selected, ssid);
6fc6879b 944 } else {
48563d86 945 wpa_scan_results_free(scan_res);
f049052b 946 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
b55aaa5f
JM
947 ssid = wpa_supplicant_pick_new_network(wpa_s);
948 if (ssid) {
f049052b 949 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
b55aaa5f 950 wpa_supplicant_associate(wpa_s, NULL, ssid);
977b1174
JM
951 } else {
952 int timeout_sec = 5;
953 int timeout_usec = 0;
0817de90
JM
954#ifdef CONFIG_P2P
955 if (wpa_s->p2p_in_provisioning) {
956 /*
957 * Use shorter wait during P2P Provisioning
958 * state to speed up group formation.
959 */
960 timeout_sec = 0;
961 timeout_usec = 250000;
962 }
963#endif /* CONFIG_P2P */
977b1174
JM
964 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
965 timeout_usec);
966 }
6fc6879b 967 }
e1504976 968 return 0;
6fc6879b 969}
6859f1cb
BG
970
971
972static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
973 union wpa_event_data *data)
974{
975 const char *rn, *rn2;
976 struct wpa_supplicant *ifs;
977
e1504976
BG
978 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
979 /*
980 * If no scan results could be fetched, then no need to
981 * notify those interfaces that did not actually request
982 * this scan.
983 */
984 return;
985 }
6859f1cb
BG
986
987 /*
988 * Check other interfaces to see if they have the same radio-name. If
989 * so, they get updated with this same scan info.
990 */
991 if (!wpa_s->driver->get_radio_name)
992 return;
993
994 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
995 if (rn == NULL || rn[0] == '\0')
996 return;
997
f049052b
BG
998 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
999 "sharing same radio (%s) in event_scan_results", rn);
6859f1cb
BG
1000
1001 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1002 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1003 continue;
1004
1005 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1006 if (rn2 && os_strcmp(rn, rn2) == 0) {
1007 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1008 "sibling", ifs->ifname);
1009 _wpa_supplicant_event_scan_results(ifs, data);
1010 }
1011 }
1012}
1013
6fc6879b
JM
1014#endif /* CONFIG_NO_SCAN_PROCESSING */
1015
1016
579ce771
JM
1017static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1018 union wpa_event_data *data)
6fc6879b
JM
1019{
1020 int l, len, found = 0, wpa_found, rsn_found;
c2a04078 1021 const u8 *p;
6fc6879b 1022
f049052b 1023 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
6fc6879b
JM
1024 if (data->assoc_info.req_ies)
1025 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1026 data->assoc_info.req_ies_len);
1027 if (data->assoc_info.resp_ies)
1028 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1029 data->assoc_info.resp_ies_len);
1030 if (data->assoc_info.beacon_ies)
1031 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1032 data->assoc_info.beacon_ies,
1033 data->assoc_info.beacon_ies_len);
4832ecd7 1034 if (data->assoc_info.freq)
f049052b
BG
1035 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1036 data->assoc_info.freq);
6fc6879b
JM
1037
1038 p = data->assoc_info.req_ies;
1039 l = data->assoc_info.req_ies_len;
1040
1041 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1042 while (p && l >= 2) {
1043 len = p[1] + 2;
1044 if (len > l) {
1045 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1046 p, l);
1047 break;
1048 }
1049 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1050 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1051 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1052 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1053 break;
1054 found = 1;
1055 wpa_find_assoc_pmkid(wpa_s);
1056 break;
1057 }
1058 l -= len;
1059 p += len;
1060 }
1061 if (!found && data->assoc_info.req_ies)
1062 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1063
c2a04078 1064#ifdef CONFIG_IEEE80211R
62c72d72
JM
1065#ifdef CONFIG_SME
1066 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1067 u8 bssid[ETH_ALEN];
1068 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1069 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1070 data->assoc_info.resp_ies,
1071 data->assoc_info.resp_ies_len,
1072 bssid) < 0) {
f049052b
BG
1073 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1074 "Reassociation Response failed");
579ce771
JM
1075 wpa_supplicant_deauthenticate(
1076 wpa_s, WLAN_REASON_INVALID_IE);
1077 return -1;
62c72d72
JM
1078 }
1079 }
62c72d72 1080
c2a04078
JM
1081 p = data->assoc_info.resp_ies;
1082 l = data->assoc_info.resp_ies_len;
1083
54f489be
JM
1084#ifdef CONFIG_WPS_STRICT
1085 if (wpa_s->current_ssid &&
1086 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1087 struct wpabuf *wps;
1088 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1089 if (wps == NULL) {
f049052b
BG
1090 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1091 "include WPS IE in (Re)Association Response");
54f489be
JM
1092 return -1;
1093 }
1094
1095 if (wps_validate_assoc_resp(wps) < 0) {
1096 wpabuf_free(wps);
1097 wpa_supplicant_deauthenticate(
1098 wpa_s, WLAN_REASON_INVALID_IE);
1099 return -1;
1100 }
1101 wpabuf_free(wps);
1102 }
1103#endif /* CONFIG_WPS_STRICT */
1104
e7846b68 1105 /* Go through the IEs and make a copy of the MDIE, if present. */
c2a04078
JM
1106 while (p && l >= 2) {
1107 len = p[1] + 2;
1108 if (len > l) {
1109 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1110 p, l);
1111 break;
1112 }
e7846b68
JM
1113 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1114 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1115 wpa_s->sme.ft_used = 1;
1116 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1117 MOBILITY_DOMAIN_ID_LEN);
1118 break;
1119 }
c2a04078
JM
1120 l -= len;
1121 p += len;
1122 }
e7846b68 1123#endif /* CONFIG_SME */
c2a04078 1124
e7846b68
JM
1125 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1126 data->assoc_info.resp_ies_len);
c2a04078
JM
1127#endif /* CONFIG_IEEE80211R */
1128
6fc6879b
JM
1129 /* WPA/RSN IE from Beacon/ProbeResp */
1130 p = data->assoc_info.beacon_ies;
1131 l = data->assoc_info.beacon_ies_len;
1132
1133 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1134 */
1135 wpa_found = rsn_found = 0;
1136 while (p && l >= 2) {
1137 len = p[1] + 2;
1138 if (len > l) {
1139 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1140 p, l);
1141 break;
1142 }
1143 if (!wpa_found &&
1144 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1145 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1146 wpa_found = 1;
1147 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1148 }
1149
1150 if (!rsn_found &&
1151 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1152 rsn_found = 1;
1153 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1154 }
1155
1156 l -= len;
1157 p += len;
1158 }
1159
1160 if (!wpa_found && data->assoc_info.beacon_ies)
1161 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1162 if (!rsn_found && data->assoc_info.beacon_ies)
1163 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1164 if (wpa_found || rsn_found)
1165 wpa_s->ap_ies_from_associnfo = 1;
4832ecd7
JM
1166
1167 wpa_s->assoc_freq = data->assoc_info.freq;
579ce771
JM
1168
1169 return 0;
6fc6879b
JM
1170}
1171
1172
1173static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1174 union wpa_event_data *data)
1175{
1176 u8 bssid[ETH_ALEN];
1d041bec 1177 int ft_completed;
8bac466b 1178 int bssid_changed;
0194fedb 1179 struct wpa_driver_capa capa;
6fc6879b 1180
1d041bec
JM
1181#ifdef CONFIG_AP
1182 if (wpa_s->ap_iface) {
1183 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1184 data->assoc_info.addr,
1185 data->assoc_info.req_ies,
1186 data->assoc_info.req_ies_len);
1187 return;
1188 }
1189#endif /* CONFIG_AP */
1190
1191 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
579ce771
JM
1192 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1193 return;
6fc6879b
JM
1194
1195 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
c2a04078 1196 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
6fc6879b 1197 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
c2a04078 1198 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
6fc6879b
JM
1199 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1200 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
f049052b 1201 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
6fc6879b 1202 MACSTR, MAC2STR(bssid));
bbb921da 1203 random_add_randomness(bssid, ETH_ALEN);
8bac466b 1204 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
6fc6879b
JM
1205 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1206 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
8bac466b
JM
1207 if (bssid_changed)
1208 wpas_notify_bssid_changed(wpa_s);
1209
6fc6879b
JM
1210 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1211 wpa_clear_keys(wpa_s, bssid);
1212 }
1213 if (wpa_supplicant_select_config(wpa_s) < 0) {
1214 wpa_supplicant_disassociate(
1215 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1216 return;
1217 }
8f770587
JM
1218 if (wpa_s->current_ssid) {
1219 struct wpa_bss *bss = NULL;
1220 struct wpa_ssid *ssid = wpa_s->current_ssid;
1221 if (ssid->ssid_len > 0)
1222 bss = wpa_bss_get(wpa_s, bssid,
1223 ssid->ssid, ssid->ssid_len);
1224 if (!bss)
1225 bss = wpa_bss_get_bssid(wpa_s, bssid);
1226 if (bss)
1227 wpa_s->current_bss = bss;
1228 }
6fc6879b
JM
1229 }
1230
62fa124c
JM
1231#ifdef CONFIG_SME
1232 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1233 wpa_s->sme.prev_bssid_set = 1;
1234#endif /* CONFIG_SME */
1235
6fc6879b
JM
1236 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1237 if (wpa_s->current_ssid) {
1238 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1239 * initialized before association, but for other modes,
1240 * initialize PC/SC here, if the current configuration needs
1241 * smartcard or SIM/USIM. */
1242 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1243 }
1244 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
3f967fe0
JM
1245 if (wpa_s->l2)
1246 l2_packet_notify_auth_start(wpa_s->l2);
6fc6879b
JM
1247
1248 /*
1249 * Set portEnabled first to FALSE in order to get EAP state machine out
1250 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1251 * state machine may transit to AUTHENTICATING state based on obsolete
1252 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1253 * AUTHENTICATED without ever giving chance to EAP state machine to
1254 * reset the state.
1255 */
1256 if (!ft_completed) {
1257 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1258 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1259 }
56586197 1260 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
6fc6879b
JM
1261 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1262 /* 802.1X::portControl = Auto */
1263 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1264 wpa_s->eapol_received = 0;
1265 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
9c972abb
JM
1266 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1267 (wpa_s->current_ssid &&
1268 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
6fc6879b
JM
1269 wpa_supplicant_cancel_auth_timeout(wpa_s);
1270 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1271 } else if (!ft_completed) {
1272 /* Timeout for receiving the first EAPOL packet */
1273 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1274 }
1275 wpa_supplicant_cancel_scan(wpa_s);
1276
c2a04078 1277 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
56586197 1278 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
6fc6879b
JM
1279 /*
1280 * We are done; the driver will take care of RSN 4-way
1281 * handshake.
1282 */
1283 wpa_supplicant_cancel_auth_timeout(wpa_s);
1284 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1285 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1286 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
98ea9431
JM
1287 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1288 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1289 /*
1290 * The driver will take care of RSN 4-way handshake, so we need
1291 * to allow EAPOL supplicant to complete its work without
1292 * waiting for WPA supplicant.
1293 */
1294 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
16a83d29
JM
1295 } else if (ft_completed) {
1296 /*
1297 * FT protocol completed - make sure EAPOL state machine ends
1298 * up in authenticated.
1299 */
1300 wpa_supplicant_cancel_auth_timeout(wpa_s);
1301 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1302 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1303 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
6fc6879b 1304 }
1ff73338
JM
1305
1306 if (wpa_s->pending_eapol_rx) {
1307 struct os_time now, age;
1308 os_get_time(&now);
1309 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1310 if (age.sec == 0 && age.usec < 100000 &&
1311 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1312 0) {
f049052b
BG
1313 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1314 "frame that was received just before "
1315 "association notification");
1ff73338
JM
1316 wpa_supplicant_rx_eapol(
1317 wpa_s, wpa_s->pending_eapol_rx_src,
1318 wpabuf_head(wpa_s->pending_eapol_rx),
1319 wpabuf_len(wpa_s->pending_eapol_rx));
1320 }
1321 wpabuf_free(wpa_s->pending_eapol_rx);
1322 wpa_s->pending_eapol_rx = NULL;
1323 }
60b94c98
JM
1324
1325#ifdef CONFIG_BGSCAN
1326 if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1327 bgscan_deinit(wpa_s);
1328 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1329 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
f049052b
BG
1330 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to "
1331 "initialize bgscan");
60b94c98
JM
1332 /*
1333 * Live without bgscan; it is only used as a
1334 * roaming optimization, so the initial
1335 * connection is not affected.
1336 */
1337 } else
1338 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1339 } else
1340 wpa_s->bgscan_ssid = NULL;
1341 }
1342#endif /* CONFIG_BGSCAN */
0194fedb
JB
1343
1344 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1345 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1346 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1347 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1348 /* Set static WEP keys again */
1349 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1350 }
50b05780
JM
1351
1352#ifdef CONFIG_IBSS_RSN
1353 if (wpa_s->current_ssid &&
1354 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1355 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1356 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE)
1357 ibss_rsn_connected(wpa_s->ibss_rsn);
1358#endif /* CONFIG_IBSS_RSN */
6fc6879b
JM
1359}
1360
1361
0544b242
JM
1362static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1363 u16 reason_code)
6fc6879b
JM
1364{
1365 const u8 *bssid;
6d6f4bb8
JM
1366 int authenticating;
1367 u8 prev_pending_bssid[ETH_ALEN];
1368
1369 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1370 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
6fc6879b
JM
1371
1372 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1373 /*
1374 * At least Host AP driver and a Prism3 card seemed to be
1375 * generating streams of disconnected events when configuring
1376 * IBSS for WPA-None. Ignore them for now.
1377 */
f049052b
BG
1378 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1379 "IBSS/WPA-None mode");
6fc6879b
JM
1380 return;
1381 }
1382
1383 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
56586197 1384 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
6fc6879b
JM
1385 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1386 "pre-shared key may be incorrect");
1387 }
0d0a8ca1
AC
1388 if (!wpa_s->auto_reconnect_disabled ||
1389 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
f049052b
BG
1390 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
1391 "reconnect (wps=%d)",
1392 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
ea184114 1393 if (wpa_s->wpa_state >= WPA_ASSOCIATING)
0d0a8ca1
AC
1394 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1395 } else {
f049052b
BG
1396 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
1397 "try to re-connect");
0d0a8ca1
AC
1398 wpa_s->reassociate = 0;
1399 wpa_s->disconnected = 1;
1400 }
6fc6879b 1401 bssid = wpa_s->bssid;
a8e16edc 1402 if (is_zero_ether_addr(bssid))
6fc6879b 1403 bssid = wpa_s->pending_bssid;
0fb337c1 1404 wpas_connection_failed(wpa_s, bssid);
6fc6879b 1405 wpa_sm_notify_disassoc(wpa_s->wpa);
0544b242
JM
1406 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1407 " reason=%d",
1408 MAC2STR(bssid), reason_code);
6fc6879b 1409 if (wpa_supplicant_dynamic_keys(wpa_s)) {
f049052b 1410 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
6fc6879b
JM
1411 wpa_s->keys_cleared = 0;
1412 wpa_clear_keys(wpa_s, wpa_s->bssid);
1413 }
1414 wpa_supplicant_mark_disassoc(wpa_s);
60b94c98 1415 bgscan_deinit(wpa_s);
3b038d79 1416 wpa_s->bgscan_ssid = NULL;
e29853bb
BG
1417
1418 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1419 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
6fc6879b
JM
1420}
1421
1422
46690a3b
JM
1423#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1424static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1425 void *sock_ctx)
1426{
1427 struct wpa_supplicant *wpa_s = eloop_ctx;
1428
1429 if (!wpa_s->pending_mic_error_report)
1430 return;
1431
f049052b 1432 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
46690a3b
JM
1433 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1434 wpa_s->pending_mic_error_report = 0;
1435}
1436#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1437
1438
6fc6879b
JM
1439static void
1440wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1441 union wpa_event_data *data)
1442{
1443 int pairwise;
1444 struct os_time t;
1445
1446 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1447 pairwise = (data && data->michael_mic_failure.unicast);
6fc6879b 1448 os_get_time(&t);
46690a3b
JM
1449 if ((wpa_s->last_michael_mic_error &&
1450 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1451 wpa_s->pending_mic_error_report) {
1452 if (wpa_s->pending_mic_error_report) {
1453 /*
1454 * Send the pending MIC error report immediately since
1455 * we are going to start countermeasures and AP better
1456 * do the same.
1457 */
1458 wpa_sm_key_request(wpa_s->wpa, 1,
1459 wpa_s->pending_mic_error_pairwise);
1460 }
1461
1462 /* Send the new MIC error report immediately since we are going
1463 * to start countermeasures and AP better do the same.
1464 */
1465 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1466
6fc6879b
JM
1467 /* initialize countermeasures */
1468 wpa_s->countermeasures = 1;
1469 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1470
1471 /*
1472 * Need to wait for completion of request frame. We do not get
1473 * any callback for the message completion, so just wait a
1474 * short while and hope for the best. */
1475 os_sleep(0, 10000);
1476
1477 wpa_drv_set_countermeasures(wpa_s, 1);
1478 wpa_supplicant_deauthenticate(wpa_s,
1479 WLAN_REASON_MICHAEL_MIC_FAILURE);
1480 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1481 wpa_s, NULL);
1482 eloop_register_timeout(60, 0,
1483 wpa_supplicant_stop_countermeasures,
1484 wpa_s, NULL);
1485 /* TODO: mark the AP rejected for 60 second. STA is
1486 * allowed to associate with another AP.. */
46690a3b
JM
1487 } else {
1488#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1489 if (wpa_s->mic_errors_seen) {
1490 /*
1491 * Reduce the effectiveness of Michael MIC error
1492 * reports as a means for attacking against TKIP if
1493 * more than one MIC failure is noticed with the same
1494 * PTK. We delay the transmission of the reports by a
1495 * random time between 0 and 60 seconds in order to
1496 * force the attacker wait 60 seconds before getting
1497 * the information on whether a frame resulted in a MIC
1498 * failure.
1499 */
1500 u8 rval[4];
1501 int sec;
1502
1503 if (os_get_random(rval, sizeof(rval)) < 0)
1504 sec = os_random() % 60;
1505 else
1506 sec = WPA_GET_BE32(rval) % 60;
f049052b
BG
1507 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1508 "report %d seconds", sec);
46690a3b
JM
1509 wpa_s->pending_mic_error_report = 1;
1510 wpa_s->pending_mic_error_pairwise = pairwise;
1511 eloop_cancel_timeout(
1512 wpa_supplicant_delayed_mic_error_report,
1513 wpa_s, NULL);
1514 eloop_register_timeout(
1515 sec, os_random() % 1000000,
1516 wpa_supplicant_delayed_mic_error_report,
1517 wpa_s, NULL);
1518 } else {
1519 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1520 }
1521#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1522 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1523#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
6fc6879b
JM
1524 }
1525 wpa_s->last_michael_mic_error = t.sec;
46690a3b 1526 wpa_s->mic_errors_seen++;
6fc6879b
JM
1527}
1528
1529
a83d9c96
SL
1530#ifdef CONFIG_TERMINATE_ONLASTIF
1531static int any_interfaces(struct wpa_supplicant *head)
1532{
1533 struct wpa_supplicant *wpa_s;
1534
1535 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1536 if (!wpa_s->interface_removed)
1537 return 1;
1538 return 0;
1539}
1540#endif /* CONFIG_TERMINATE_ONLASTIF */
1541
1542
6fc6879b
JM
1543static void
1544wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1545 union wpa_event_data *data)
1546{
1547 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1548 return;
1549
1550 switch (data->interface_status.ievent) {
1551 case EVENT_INTERFACE_ADDED:
1552 if (!wpa_s->interface_removed)
1553 break;
1554 wpa_s->interface_removed = 0;
f049052b 1555 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
6fc6879b 1556 if (wpa_supplicant_driver_init(wpa_s) < 0) {
f049052b
BG
1557 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1558 "driver after interface was added");
6fc6879b
JM
1559 }
1560 break;
1561 case EVENT_INTERFACE_REMOVED:
f049052b 1562 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
6fc6879b
JM
1563 wpa_s->interface_removed = 1;
1564 wpa_supplicant_mark_disassoc(wpa_s);
1565 l2_packet_deinit(wpa_s->l2);
1566 wpa_s->l2 = NULL;
a83d9c96
SL
1567#ifdef CONFIG_TERMINATE_ONLASTIF
1568 /* check if last interface */
1569 if (!any_interfaces(wpa_s->global->ifaces))
1570 eloop_terminate();
1571#endif /* CONFIG_TERMINATE_ONLASTIF */
6fc6879b
JM
1572 break;
1573 }
1574}
1575
1576
1577#ifdef CONFIG_PEERKEY
1578static void
1579wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1580 union wpa_event_data *data)
1581{
1582 if (data == NULL)
1583 return;
1584 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1585}
1586#endif /* CONFIG_PEERKEY */
1587
1588
1589#ifdef CONFIG_IEEE80211R
1590static void
1591wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1592 union wpa_event_data *data)
1593{
1594 if (data == NULL)
1595 return;
1596
1597 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1598 data->ft_ies.ies_len,
1599 data->ft_ies.ft_action,
babfbf15
JM
1600 data->ft_ies.target_ap,
1601 data->ft_ies.ric_ies,
1602 data->ft_ies.ric_ies_len) < 0) {
6fc6879b
JM
1603 /* TODO: prevent MLME/driver from trying to associate? */
1604 }
1605}
1606#endif /* CONFIG_IEEE80211R */
1607
1608
11ef8d35
JM
1609#ifdef CONFIG_IBSS_RSN
1610static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1611 union wpa_event_data *data)
1612{
df4bc509 1613 struct wpa_ssid *ssid;
11ef8d35
JM
1614 if (data == NULL)
1615 return;
df4bc509
JM
1616 ssid = wpa_s->current_ssid;
1617 if (ssid == NULL)
1618 return;
1619 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
1620 return;
1621
11ef8d35
JM
1622 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1623}
1624#endif /* CONFIG_IBSS_RSN */
1625
1626
036f7c4a
JM
1627#ifdef CONFIG_IEEE80211R
1628static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1629 size_t len)
1630{
1631 const u8 *sta_addr, *target_ap_addr;
1632 u16 status;
1633
1634 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1635 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1636 return; /* only SME case supported for now */
1637 if (len < 1 + 2 * ETH_ALEN + 2)
1638 return;
1639 if (data[0] != 2)
1640 return; /* Only FT Action Response is supported for now */
1641 sta_addr = data + 1;
1642 target_ap_addr = data + 1 + ETH_ALEN;
1643 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
f049052b
BG
1644 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
1645 MACSTR " TargetAP " MACSTR " status %u",
1646 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
036f7c4a
JM
1647
1648 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
f049052b
BG
1649 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1650 " in FT Action Response", MAC2STR(sta_addr));
036f7c4a
JM
1651 return;
1652 }
1653
1654 if (status) {
f049052b
BG
1655 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
1656 "failure (status code %d)", status);
036f7c4a
JM
1657 /* TODO: report error to FT code(?) */
1658 return;
1659 }
1660
1661 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1662 len - (1 + 2 * ETH_ALEN + 2), 1,
1663 target_ap_addr, NULL, 0) < 0)
1664 return;
1665
fe191985
JM
1666#ifdef CONFIG_SME
1667 {
1668 struct wpa_bss *bss;
1669 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1670 if (bss)
1671 wpa_s->sme.freq = bss->freq;
62c72d72 1672 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
fe191985
JM
1673 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1674 WLAN_AUTH_FT);
1675 }
1676#endif /* CONFIG_SME */
036f7c4a
JM
1677}
1678#endif /* CONFIG_IEEE80211R */
1679
1680
7d878ca7
JM
1681static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
1682 struct unprot_deauth *e)
1683{
1684#ifdef CONFIG_IEEE80211W
1685 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
1686 "dropped: " MACSTR " -> " MACSTR
1687 " (reason code %u)",
1688 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1689 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1690#endif /* CONFIG_IEEE80211W */
1691}
1692
1693
1694static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
1695 struct unprot_disassoc *e)
1696{
1697#ifdef CONFIG_IEEE80211W
1698 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
1699 "dropped: " MACSTR " -> " MACSTR
1700 " (reason code %u)",
1701 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1702 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1703#endif /* CONFIG_IEEE80211W */
1704}
1705
1706
9646a8ab 1707void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6fc6879b
JM
1708 union wpa_event_data *data)
1709{
1710 struct wpa_supplicant *wpa_s = ctx;
0544b242 1711 u16 reason_code = 0;
6fc6879b 1712
8401a6b0
JM
1713 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1714 event != EVENT_INTERFACE_ENABLED &&
1715 event != EVENT_INTERFACE_STATUS) {
f049052b
BG
1716 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
1717 "disabled", event);
8401a6b0
JM
1718 return;
1719 }
1720
f049052b
BG
1721 wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
1722 event, wpa_s->ifname);
9b7124b2 1723
6fc6879b 1724 switch (event) {
c2a04078
JM
1725 case EVENT_AUTH:
1726 sme_event_auth(wpa_s, data);
1727 break;
6fc6879b
JM
1728 case EVENT_ASSOC:
1729 wpa_supplicant_event_assoc(wpa_s, data);
1730 break;
1731 case EVENT_DISASSOC:
f049052b 1732 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2e75a2b3 1733 if (data) {
f049052b
BG
1734 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
1735 data->disassoc_info.reason_code);
2e75a2b3 1736 if (data->disassoc_info.addr)
f049052b
BG
1737 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
1738 MAC2STR(data->disassoc_info.addr));
2e75a2b3 1739 }
1d041bec 1740#ifdef CONFIG_AP
7f542069 1741 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1d041bec
JM
1742 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1743 data->disassoc_info.addr);
1744 break;
1745 }
1746#endif /* CONFIG_AP */
9fdd0fad
JM
1747 if (data) {
1748 reason_code = data->disassoc_info.reason_code;
1749 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
1750 data->disassoc_info.ie,
1751 data->disassoc_info.ie_len);
1752#ifdef CONFIG_P2P
1753 wpas_p2p_disassoc_notif(
1754 wpa_s, data->disassoc_info.addr, reason_code,
1755 data->disassoc_info.ie,
1756 data->disassoc_info.ie_len);
1757#endif /* CONFIG_P2P */
1758 }
0e379654
JM
1759 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1760 sme_event_disassoc(wpa_s, data);
a84ed99e
JM
1761 /* fall through */
1762 case EVENT_DEAUTH:
0544b242 1763 if (event == EVENT_DEAUTH) {
f049052b
BG
1764 wpa_dbg(wpa_s, MSG_DEBUG,
1765 "Deauthentication notification");
2e75a2b3 1766 if (data) {
0544b242 1767 reason_code = data->deauth_info.reason_code;
f049052b
BG
1768 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
1769 data->deauth_info.reason_code);
2e75a2b3 1770 if (data->deauth_info.addr) {
f049052b
BG
1771 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
1772 MACSTR,
1773 MAC2STR(data->deauth_info.
1774 addr));
2e75a2b3 1775 }
9fdd0fad
JM
1776 wpa_hexdump(MSG_DEBUG,
1777 "Deauthentication frame IE(s)",
1778 data->deauth_info.ie,
1779 data->deauth_info.ie_len);
1780#ifdef CONFIG_P2P
1781 wpas_p2p_deauth_notif(
1782 wpa_s, data->deauth_info.addr,
1783 reason_code,
1784 data->deauth_info.ie,
1785 data->deauth_info.ie_len);
1786#endif /* CONFIG_P2P */
2e75a2b3 1787 }
0544b242 1788 }
1d041bec 1789#ifdef CONFIG_AP
7f542069 1790 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1d041bec
JM
1791 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1792 data->deauth_info.addr);
1793 break;
1794 }
1795#endif /* CONFIG_AP */
0544b242 1796 wpa_supplicant_event_disassoc(wpa_s, reason_code);
6fc6879b
JM
1797 break;
1798 case EVENT_MICHAEL_MIC_FAILURE:
1799 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1800 break;
1801#ifndef CONFIG_NO_SCAN_PROCESSING
1802 case EVENT_SCAN_RESULTS:
8d923a4a 1803 wpa_supplicant_event_scan_results(wpa_s, data);
6fc6879b
JM
1804 break;
1805#endif /* CONFIG_NO_SCAN_PROCESSING */
1806 case EVENT_ASSOCINFO:
1807 wpa_supplicant_event_associnfo(wpa_s, data);
1808 break;
1809 case EVENT_INTERFACE_STATUS:
1810 wpa_supplicant_event_interface_status(wpa_s, data);
1811 break;
1812 case EVENT_PMKID_CANDIDATE:
1813 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1814 break;
1815#ifdef CONFIG_PEERKEY
1816 case EVENT_STKSTART:
1817 wpa_supplicant_event_stkstart(wpa_s, data);
1818 break;
1819#endif /* CONFIG_PEERKEY */
1820#ifdef CONFIG_IEEE80211R
1821 case EVENT_FT_RESPONSE:
1822 wpa_supplicant_event_ft_response(wpa_s, data);
1823 break;
1824#endif /* CONFIG_IEEE80211R */
11ef8d35
JM
1825#ifdef CONFIG_IBSS_RSN
1826 case EVENT_IBSS_RSN_START:
1827 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1828 break;
1829#endif /* CONFIG_IBSS_RSN */
efa46078 1830 case EVENT_ASSOC_REJECT:
c05d6d18
JM
1831 if (data->assoc_reject.bssid)
1832 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
1833 "bssid=" MACSTR " status_code=%u",
1834 MAC2STR(data->assoc_reject.bssid),
1835 data->assoc_reject.status_code);
1836 else
1837 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
1838 "status_code=%u",
1839 data->assoc_reject.status_code);
ea78c315
JM
1840 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1841 sme_event_assoc_reject(wpa_s, data);
efa46078 1842 break;
da1fb17c 1843 case EVENT_AUTH_TIMED_OUT:
ea78c315
JM
1844 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1845 sme_event_auth_timed_out(wpa_s, data);
da1fb17c
JM
1846 break;
1847 case EVENT_ASSOC_TIMED_OUT:
ea78c315
JM
1848 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1849 sme_event_assoc_timed_out(wpa_s, data);
da1fb17c 1850 break;
f8b1f695
JM
1851#ifdef CONFIG_AP
1852 case EVENT_TX_STATUS:
f049052b
BG
1853 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
1854 " type=%d stype=%d",
1855 MAC2STR(data->tx_status.dst),
1856 data->tx_status.type, data->tx_status.stype);
9bae1be0
JM
1857 if (wpa_s->ap_iface == NULL) {
1858#ifdef CONFIG_P2P
1859 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1860 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
1861 wpas_send_action_tx_status(
1862 wpa_s, data->tx_status.dst,
1863 data->tx_status.data,
1864 data->tx_status.data_len,
93b7ddd0
JM
1865 data->tx_status.ack ?
1866 P2P_SEND_ACTION_SUCCESS :
1867 P2P_SEND_ACTION_NO_ACK);
9bae1be0
JM
1868#endif /* CONFIG_P2P */
1869 break;
1870 }
1871#ifdef CONFIG_P2P
f049052b
BG
1872 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
1873 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
9bae1be0
JM
1874 /*
1875 * Catch TX status events for Action frames we sent via group
1876 * interface in GO mode.
1877 */
1878 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1879 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
1880 os_memcmp(wpa_s->parent->pending_action_dst,
1881 data->tx_status.dst, ETH_ALEN) == 0) {
1882 wpas_send_action_tx_status(
1883 wpa_s->parent, data->tx_status.dst,
1884 data->tx_status.data,
1885 data->tx_status.data_len,
1d39378a
AL
1886 data->tx_status.ack ?
1887 P2P_SEND_ACTION_SUCCESS :
1888 P2P_SEND_ACTION_NO_ACK);
f8b1f695 1889 break;
9bae1be0
JM
1890 }
1891#endif /* CONFIG_P2P */
f8b1f695
JM
1892 switch (data->tx_status.type) {
1893 case WLAN_FC_TYPE_MGMT:
1894 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1895 data->tx_status.data_len,
1896 data->tx_status.stype,
1897 data->tx_status.ack);
1898 break;
1899 case WLAN_FC_TYPE_DATA:
1900 ap_tx_status(wpa_s, data->tx_status.dst,
1901 data->tx_status.data,
1902 data->tx_status.data_len,
1903 data->tx_status.ack);
1904 break;
1905 }
1906 break;
1907 case EVENT_RX_FROM_UNKNOWN:
1908 if (wpa_s->ap_iface == NULL)
1909 break;
fdbe50ed 1910 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
f8b1f695
JM
1911 data->rx_from_unknown.len);
1912 break;
1913 case EVENT_RX_MGMT:
9bae1be0
JM
1914 if (wpa_s->ap_iface == NULL) {
1915#ifdef CONFIG_P2P
1916 u16 fc, stype;
1917 const struct ieee80211_mgmt *mgmt;
1918 mgmt = (const struct ieee80211_mgmt *)
1919 data->rx_mgmt.frame;
1920 fc = le_to_host16(mgmt->frame_control);
1921 stype = WLAN_FC_GET_STYPE(fc);
1922 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
1923 data->rx_mgmt.frame_len > 24) {
1924 const u8 *src = mgmt->sa;
1925 const u8 *ie = mgmt->u.probe_req.variable;
1926 size_t ie_len = data->rx_mgmt.frame_len -
1927 (mgmt->u.probe_req.variable -
1928 data->rx_mgmt.frame);
1929 wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
1930 break;
1931 }
1932#endif /* CONFIG_P2P */
f049052b
BG
1933 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
1934 "management frame in non-AP mode");
f8b1f695 1935 break;
9bae1be0 1936 }
2a8b7416 1937 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
f8b1f695
JM
1938 break;
1939#endif /* CONFIG_AP */
036f7c4a 1940 case EVENT_RX_ACTION:
f049052b
BG
1941 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
1942 " Category=%u DataLen=%d freq=%d MHz",
1943 MAC2STR(data->rx_action.sa),
1944 data->rx_action.category, (int) data->rx_action.len,
1945 data->rx_action.freq);
036f7c4a
JM
1946#ifdef CONFIG_IEEE80211R
1947 if (data->rx_action.category == WLAN_ACTION_FT) {
1948 ft_rx_action(wpa_s, data->rx_action.data,
1949 data->rx_action.len);
1950 break;
1951 }
1952#endif /* CONFIG_IEEE80211R */
7d878ca7
JM
1953#ifdef CONFIG_IEEE80211W
1954#ifdef CONFIG_SME
1955 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
1956 sme_sa_query_rx(wpa_s, data->rx_action.sa,
1957 data->rx_action.data,
1958 data->rx_action.len);
1959 break;
1960 }
1961#endif /* CONFIG_SME */
1962#endif /* CONFIG_IEEE80211W */
9bae1be0
JM
1963#ifdef CONFIG_P2P
1964 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
1965 data->rx_action.sa,
1966 data->rx_action.bssid,
1967 data->rx_action.category,
1968 data->rx_action.data,
1969 data->rx_action.len, data->rx_action.freq);
e67b55fb
JM
1970#endif /* CONFIG_P2P */
1971 break;
1972 case EVENT_RX_PROBE_REQ:
1973#ifdef CONFIG_AP
1974 if (wpa_s->ap_iface) {
1975 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
1976 data->rx_probe_req.sa,
1977 data->rx_probe_req.ie,
1978 data->rx_probe_req.ie_len);
1979 break;
1980 }
1981#endif /* CONFIG_AP */
1982#ifdef CONFIG_P2P
1983 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
1984 data->rx_probe_req.ie,
1985 data->rx_probe_req.ie_len);
9bae1be0 1986#endif /* CONFIG_P2P */
036f7c4a 1987 break;
9bae1be0
JM
1988#ifdef CONFIG_P2P
1989 case EVENT_REMAIN_ON_CHANNEL:
1990 wpas_p2p_remain_on_channel_cb(
1991 wpa_s, data->remain_on_channel.freq,
1992 data->remain_on_channel.duration);
1993 break;
1994 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
1995 wpas_p2p_cancel_remain_on_channel_cb(
1996 wpa_s, data->remain_on_channel.freq);
1997 break;
c5db8e51
KRK
1998 case EVENT_P2P_DEV_FOUND: {
1999 struct p2p_peer_info peer_info;
2000
2001 os_memset(&peer_info, 0, sizeof(peer_info));
2002 if (data->p2p_dev_found.dev_addr)
2003 os_memcpy(peer_info.p2p_device_addr,
2004 data->p2p_dev_found.dev_addr, ETH_ALEN);
2005 if (data->p2p_dev_found.pri_dev_type)
2006 os_memcpy(peer_info.pri_dev_type,
2007 data->p2p_dev_found.pri_dev_type,
2008 sizeof(peer_info.pri_dev_type));
2009 if (data->p2p_dev_found.dev_name)
2010 os_strlcpy(peer_info.device_name,
2011 data->p2p_dev_found.dev_name,
2012 sizeof(peer_info.device_name));
2013 peer_info.config_methods = data->p2p_dev_found.config_methods;
2014 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2015 peer_info.group_capab = data->p2p_dev_found.group_capab;
2016
2017 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info);
3ac17eba 2018 break;
c5db8e51 2019 }
3ac17eba
JM
2020 case EVENT_P2P_GO_NEG_REQ_RX:
2021 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2022 data->p2p_go_neg_req_rx.dev_passwd_id);
2023 break;
2024 case EVENT_P2P_GO_NEG_COMPLETED:
2025 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2026 break;
2027 case EVENT_P2P_PROV_DISC_REQUEST:
2028 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2029 data->p2p_prov_disc_req.config_methods,
2030 data->p2p_prov_disc_req.dev_addr,
2031 data->p2p_prov_disc_req.pri_dev_type,
2032 data->p2p_prov_disc_req.dev_name,
2033 data->p2p_prov_disc_req.supp_config_methods,
2034 data->p2p_prov_disc_req.dev_capab,
2035 data->p2p_prov_disc_req.group_capab);
2036 break;
2037 case EVENT_P2P_PROV_DISC_RESPONSE:
2038 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2039 data->p2p_prov_disc_resp.config_methods);
2040 break;
2041 case EVENT_P2P_SD_REQUEST:
2042 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2043 data->p2p_sd_req.sa,
2044 data->p2p_sd_req.dialog_token,
2045 data->p2p_sd_req.update_indic,
2046 data->p2p_sd_req.tlvs,
2047 data->p2p_sd_req.tlvs_len);
2048 break;
2049 case EVENT_P2P_SD_RESPONSE:
2050 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2051 data->p2p_sd_resp.update_indic,
2052 data->p2p_sd_resp.tlvs,
2053 data->p2p_sd_resp.tlvs_len);
2054 break;
9bae1be0 2055#endif /* CONFIG_P2P */
245519e0
JM
2056#ifdef CONFIG_CLIENT_MLME
2057 case EVENT_MLME_RX: {
2058 struct ieee80211_rx_status rx_status;
2059 os_memset(&rx_status, 0, sizeof(rx_status));
2060 rx_status.freq = data->mlme_rx.freq;
2061 rx_status.channel = data->mlme_rx.channel;
2062 rx_status.ssi = data->mlme_rx.ssi;
2063 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
2064 &rx_status);
2065 break;
2066 }
2067#endif /* CONFIG_CLIENT_MLME */
a8e0505b
JM
2068 case EVENT_EAPOL_RX:
2069 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2070 data->eapol_rx.data,
2071 data->eapol_rx.data_len);
2072 break;
e2f74005
JM
2073 case EVENT_SIGNAL_CHANGE:
2074 bgscan_notify_signal_change(
60a972a6 2075 wpa_s, data->signal_change.above_threshold,
174fa789
PS
2076 data->signal_change.current_signal,
2077 data->signal_change.current_noise,
2078 data->signal_change.current_txrate);
e2f74005 2079 break;
8401a6b0 2080 case EVENT_INTERFACE_ENABLED:
f049052b 2081 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
8401a6b0 2082 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
199716ad 2083#ifdef CONFIG_AP
9919f7a2
JB
2084 if (!wpa_s->ap_iface) {
2085 wpa_supplicant_set_state(wpa_s,
2086 WPA_DISCONNECTED);
2087 wpa_supplicant_req_scan(wpa_s, 0, 0);
2088 } else
2089 wpa_supplicant_set_state(wpa_s,
2090 WPA_COMPLETED);
199716ad
BG
2091#else /* CONFIG_AP */
2092 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2093 wpa_supplicant_req_scan(wpa_s, 0, 0);
2094#endif /* CONFIG_AP */
8401a6b0
JM
2095 }
2096 break;
2097 case EVENT_INTERFACE_DISABLED:
f049052b 2098 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
8401a6b0
JM
2099 wpa_supplicant_mark_disassoc(wpa_s);
2100 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2101 break;
b5c9da8d 2102 case EVENT_CHANNEL_LIST_CHANGED:
35c5d610
JM
2103 if (wpa_s->drv_priv == NULL)
2104 break; /* Ignore event during drv initialization */
b5c9da8d
JM
2105#ifdef CONFIG_P2P
2106 wpas_p2p_update_channel_list(wpa_s);
c973f386
JM
2107#endif /* CONFIG_P2P */
2108 break;
2109 case EVENT_INTERFACE_UNAVAILABLE:
2110#ifdef CONFIG_P2P
2111 wpas_p2p_interface_unavailable(wpa_s);
7cfc4ac3
AGS
2112#endif /* CONFIG_P2P */
2113 break;
2114 case EVENT_BEST_CHANNEL:
f049052b
BG
2115 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2116 "(%d %d %d)",
2117 data->best_chan.freq_24, data->best_chan.freq_5,
2118 data->best_chan.freq_overall);
7cfc4ac3
AGS
2119 wpa_s->best_24_freq = data->best_chan.freq_24;
2120 wpa_s->best_5_freq = data->best_chan.freq_5;
2121 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2122#ifdef CONFIG_P2P
2123 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2124 data->best_chan.freq_5,
2125 data->best_chan.freq_overall);
b5c9da8d
JM
2126#endif /* CONFIG_P2P */
2127 break;
7d878ca7
JM
2128 case EVENT_UNPROT_DEAUTH:
2129 wpa_supplicant_event_unprot_deauth(wpa_s,
2130 &data->unprot_deauth);
2131 break;
2132 case EVENT_UNPROT_DISASSOC:
2133 wpa_supplicant_event_unprot_disassoc(wpa_s,
2134 &data->unprot_disassoc);
2135 break;
0d7e5a3a
JB
2136 case EVENT_STATION_LOW_ACK:
2137#ifdef CONFIG_AP
2138 if (wpa_s->ap_iface && data)
2139 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2140 data->low_ack.addr);
2141#endif /* CONFIG_AP */
2142 break;
6fc6879b 2143 default:
f049052b 2144 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
6fc6879b
JM
2145 break;
2146 }
2147}