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