blob: b030a7308329cf34fab35c5f8b53739c4a6f6104 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
47static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
49{
50 struct os_time now;
51
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
53 return 0;
54
55 os_get_time(&now);
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
58
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
60
61 return 0;
62}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
64
65static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
66{
67 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
71 return 0;
72
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
74 "information");
75 ssid = wpa_supplicant_get_ssid(wpa_s);
76 if (ssid == NULL) {
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
79 return -1;
80 }
81
Dmitry Shmidt04949592012-07-19 12:16:46 -070082 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
84 return -1;
85 }
86
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070087 res = wpas_temp_disabled(wpa_s, ssid);
88 if (res > 0) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
90 "disabled for %d second(s)", res);
91 return -1;
92 }
93
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
95 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080096 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 u8 wpa_ie[80];
98 size_t wpa_ie_len = sizeof(wpa_ie);
99 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
100 wpa_ie, &wpa_ie_len);
101 } else {
102 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
103 }
104
105 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
106 eapol_sm_invalidate_cached_session(wpa_s->eapol);
107 old_ssid = wpa_s->current_ssid;
108 wpa_s->current_ssid = ssid;
109 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
110 wpa_supplicant_initiate_eapol(wpa_s);
111 if (old_ssid != wpa_s->current_ssid)
112 wpas_notify_network_changed(wpa_s);
113
114 return 0;
115}
116
117
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800118void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119{
120 struct wpa_supplicant *wpa_s = eloop_ctx;
121
122 if (wpa_s->countermeasures) {
123 wpa_s->countermeasures = 0;
124 wpa_drv_set_countermeasures(wpa_s, 0);
125 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
127 }
128}
129
130
131void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
132{
133 int bssid_changed;
134
Dmitry Shmidt04949592012-07-19 12:16:46 -0700135 wnm_bss_keep_alive_deinit(wpa_s);
136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137#ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s->ibss_rsn);
139 wpa_s->ibss_rsn = NULL;
140#endif /* CONFIG_IBSS_RSN */
141
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700142#ifdef CONFIG_AP
143 wpa_supplicant_ap_deinit(wpa_s);
144#endif /* CONFIG_AP */
145
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
147 return;
148
149 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800150#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700151 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800152#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
154 os_memset(wpa_s->bssid, 0, ETH_ALEN);
155 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700156#ifdef CONFIG_SME
157 wpa_s->sme.prev_bssid_set = 0;
158#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800159#ifdef CONFIG_P2P
160 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
161#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 wpa_s->current_bss = NULL;
163 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700164#ifdef CONFIG_IEEE80211R
165#ifdef CONFIG_SME
166 if (wpa_s->sme.ft_ies)
167 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
168#endif /* CONFIG_SME */
169#endif /* CONFIG_IEEE80211R */
170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 if (bssid_changed)
172 wpas_notify_bssid_changed(wpa_s);
173
174 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
175 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
176 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
177 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
178 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700179 wpa_s->current_ssid = NULL;
180 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181}
182
183
184static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
185{
186 struct wpa_ie_data ie;
187 int pmksa_set = -1;
188 size_t i;
189
190 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
191 ie.pmkid == NULL)
192 return;
193
194 for (i = 0; i < ie.num_pmkid; i++) {
195 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
196 ie.pmkid + i * PMKID_LEN,
197 NULL, NULL, 0);
198 if (pmksa_set == 0) {
199 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
200 break;
201 }
202 }
203
204 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
205 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
206}
207
208
209static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
210 union wpa_event_data *data)
211{
212 if (data == NULL) {
213 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
214 "event");
215 return;
216 }
217 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
218 " index=%d preauth=%d",
219 MAC2STR(data->pmkid_candidate.bssid),
220 data->pmkid_candidate.index,
221 data->pmkid_candidate.preauth);
222
223 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
224 data->pmkid_candidate.index,
225 data->pmkid_candidate.preauth);
226}
227
228
229static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
230{
231 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
232 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
233 return 0;
234
235#ifdef IEEE8021X_EAPOL
236 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
237 wpa_s->current_ssid &&
238 !(wpa_s->current_ssid->eapol_flags &
239 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
240 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
241 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
242 * plaintext or static WEP keys). */
243 return 0;
244 }
245#endif /* IEEE8021X_EAPOL */
246
247 return 1;
248}
249
250
251/**
252 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
253 * @wpa_s: pointer to wpa_supplicant data
254 * @ssid: Configuration data for the network
255 * Returns: 0 on success, -1 on failure
256 *
257 * This function is called when starting authentication with a network that is
258 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
259 */
260int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
261 struct wpa_ssid *ssid)
262{
263#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264#ifdef PCSC_FUNCS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 int aka = 0, sim = 0, type;
266
267 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
268 return 0;
269
270 if (ssid->eap.eap_methods == NULL) {
271 sim = 1;
272 aka = 1;
273 } else {
274 struct eap_method_type *eap = ssid->eap.eap_methods;
275 while (eap->vendor != EAP_VENDOR_IETF ||
276 eap->method != EAP_TYPE_NONE) {
277 if (eap->vendor == EAP_VENDOR_IETF) {
278 if (eap->method == EAP_TYPE_SIM)
279 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700280 else if (eap->method == EAP_TYPE_AKA ||
281 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 aka = 1;
283 }
284 eap++;
285 }
286 }
287
288 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
289 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
291 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
292 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 aka = 0;
294
295 if (!sim && !aka) {
296 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
297 "use SIM, but neither EAP-SIM nor EAP-AKA are "
298 "enabled");
299 return 0;
300 }
301
302 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
303 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
304 if (sim && aka)
305 type = SCARD_TRY_BOTH;
306 else if (aka)
307 type = SCARD_USIM_ONLY;
308 else
309 type = SCARD_GSM_SIM_ONLY;
310
Dmitry Shmidt04949592012-07-19 12:16:46 -0700311 wpa_s->scard = scard_init(type, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312 if (wpa_s->scard == NULL) {
313 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
314 "(pcsc-lite)");
315 return -1;
316 }
317 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
318 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800319#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320#endif /* IEEE8021X_EAPOL */
321
322 return 0;
323}
324
325
326#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700327static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 struct wpa_ssid *ssid)
329{
330 int i, privacy = 0;
331
332 if (ssid->mixed_cell)
333 return 1;
334
335#ifdef CONFIG_WPS
336 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
337 return 1;
338#endif /* CONFIG_WPS */
339
340 for (i = 0; i < NUM_WEP_KEYS; i++) {
341 if (ssid->wep_key_len[i]) {
342 privacy = 1;
343 break;
344 }
345 }
346#ifdef IEEE8021X_EAPOL
347 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
348 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
349 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
350 privacy = 1;
351#endif /* IEEE8021X_EAPOL */
352
Jouni Malinen75ecf522011-06-27 15:19:46 -0700353 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
354 privacy = 1;
355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 if (bss->caps & IEEE80211_CAP_PRIVACY)
357 return privacy;
358 return !privacy;
359}
360
361
362static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
363 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700364 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365{
366 struct wpa_ie_data ie;
367 int proto_match = 0;
368 const u8 *rsn_ie, *wpa_ie;
369 int ret;
370 int wep_ok;
371
372 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
373 if (ret >= 0)
374 return ret;
375
376 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
377 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
378 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
379 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
380 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
381
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700382 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
384 proto_match++;
385
386 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
387 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
388 "failed");
389 break;
390 }
391
392 if (wep_ok &&
393 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
394 {
395 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
396 "in RSN IE");
397 return 1;
398 }
399
400 if (!(ie.proto & ssid->proto)) {
401 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
402 "mismatch");
403 break;
404 }
405
406 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
407 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
408 "cipher mismatch");
409 break;
410 }
411
412 if (!(ie.group_cipher & ssid->group_cipher)) {
413 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
414 "cipher mismatch");
415 break;
416 }
417
418 if (!(ie.key_mgmt & ssid->key_mgmt)) {
419 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
420 "mismatch");
421 break;
422 }
423
424#ifdef CONFIG_IEEE80211W
425 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
426 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
428 "frame protection");
429 break;
430 }
431#endif /* CONFIG_IEEE80211W */
432
433 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
434 return 1;
435 }
436
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700437 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
439 proto_match++;
440
441 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
442 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
443 "failed");
444 break;
445 }
446
447 if (wep_ok &&
448 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
449 {
450 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
451 "in WPA IE");
452 return 1;
453 }
454
455 if (!(ie.proto & ssid->proto)) {
456 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
457 "mismatch");
458 break;
459 }
460
461 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
462 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
463 "cipher mismatch");
464 break;
465 }
466
467 if (!(ie.group_cipher & ssid->group_cipher)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
469 "cipher mismatch");
470 break;
471 }
472
473 if (!(ie.key_mgmt & ssid->key_mgmt)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
475 "mismatch");
476 break;
477 }
478
479 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
480 return 1;
481 }
482
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700483 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
484 !rsn_ie) {
485 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
486 return 1;
487 }
488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
490 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
491 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
492 return 0;
493 }
494
495 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
497 return 1;
498 }
499
500 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
501 "WPA/WPA2");
502
503 return 0;
504}
505
506
507static int freq_allowed(int *freqs, int freq)
508{
509 int i;
510
511 if (freqs == NULL)
512 return 1;
513
514 for (i = 0; freqs[i]; i++)
515 if (freqs[i] == freq)
516 return 1;
517 return 0;
518}
519
520
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521static int ht_supported(const struct hostapd_hw_modes *mode)
522{
523 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
524 /*
525 * The driver did not indicate whether it supports HT. Assume
526 * it does to avoid connection issues.
527 */
528 return 1;
529 }
530
531 /*
532 * IEEE Std 802.11n-2009 20.1.1:
533 * An HT non-AP STA shall support all EQM rates for one spatial stream.
534 */
535 return mode->mcs_set[0] == 0xff;
536}
537
538
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700539static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540{
541 const struct hostapd_hw_modes *mode = NULL, *modes;
542 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
543 const u8 *rate_ie;
544 int i, j, k;
545
546 if (bss->freq == 0)
547 return 1; /* Cannot do matching without knowing band */
548
549 modes = wpa_s->hw.modes;
550 if (modes == NULL) {
551 /*
552 * The driver does not provide any additional information
553 * about the utilized hardware, so allow the connection attempt
554 * to continue.
555 */
556 return 1;
557 }
558
559 for (i = 0; i < wpa_s->hw.num_modes; i++) {
560 for (j = 0; j < modes[i].num_channels; j++) {
561 int freq = modes[i].channels[j].freq;
562 if (freq == bss->freq) {
563 if (mode &&
564 mode->mode == HOSTAPD_MODE_IEEE80211G)
565 break; /* do not allow 802.11b replace
566 * 802.11g */
567 mode = &modes[i];
568 break;
569 }
570 }
571 }
572
573 if (mode == NULL)
574 return 0;
575
576 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700577 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800578 if (rate_ie == NULL)
579 continue;
580
581 for (j = 2; j < rate_ie[1] + 2; j++) {
582 int flagged = !!(rate_ie[j] & 0x80);
583 int r = (rate_ie[j] & 0x7f) * 5;
584
585 /*
586 * IEEE Std 802.11n-2009 7.3.2.2:
587 * The new BSS Membership selector value is encoded
588 * like a legacy basic rate, but it is not a rate and
589 * only indicates if the BSS members are required to
590 * support the mandatory features of Clause 20 [HT PHY]
591 * in order to join the BSS.
592 */
593 if (flagged && ((rate_ie[j] & 0x7f) ==
594 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
595 if (!ht_supported(mode)) {
596 wpa_dbg(wpa_s, MSG_DEBUG,
597 " hardware does not support "
598 "HT PHY");
599 return 0;
600 }
601 continue;
602 }
603
604 if (!flagged)
605 continue;
606
607 /* check for legacy basic rates */
608 for (k = 0; k < mode->num_rates; k++) {
609 if (mode->rates[k] == r)
610 break;
611 }
612 if (k == mode->num_rates) {
613 /*
614 * IEEE Std 802.11-2007 7.3.2.2 demands that in
615 * order to join a BSS all required rates
616 * have to be supported by the hardware.
617 */
618 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
619 "not support required rate %d.%d Mbps",
620 r / 10, r % 10);
621 return 0;
622 }
623 }
624 }
625
626 return 1;
627}
628
629
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700631 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 struct wpa_ssid *group)
633{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700634 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 int wpa;
636 struct wpa_blacklist *e;
637 const u8 *ie;
638 struct wpa_ssid *ssid;
639
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700640 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641 wpa_ie_len = ie ? ie[1] : 0;
642
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700643 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 rsn_ie_len = ie ? ie[1] : 0;
645
646 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
647 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700648 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700650 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651
652 e = wpa_blacklist_get(wpa_s, bss->bssid);
653 if (e) {
654 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700655 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 /*
657 * When only a single network is enabled, we can
658 * trigger blacklisting on the first failure. This
659 * should not be done with multiple enabled networks to
660 * avoid getting forced to move into a worse ESS on
661 * single error if there are no other BSSes of the
662 * current ESS.
663 */
664 limit = 0;
665 }
666 if (e->count > limit) {
667 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
668 "(count=%d limit=%d)", e->count, limit);
669 return NULL;
670 }
671 }
672
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700673 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
675 return NULL;
676 }
677
678 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
679
680 for (ssid = group; ssid; ssid = ssid->pnext) {
681 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700682 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683
Dmitry Shmidt04949592012-07-19 12:16:46 -0700684 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
686 continue;
687 }
688
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700689 res = wpas_temp_disabled(wpa_s, ssid);
690 if (res > 0) {
691 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
692 "temporarily for %d second(s)", res);
693 continue;
694 }
695
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696#ifdef CONFIG_WPS
697 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
698 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
699 "(WPS)");
700 continue;
701 }
702
703 if (wpa && ssid->ssid_len == 0 &&
704 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
705 check_ssid = 0;
706
707 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
708 /* Only allow wildcard SSID match if an AP
709 * advertises active WPS operation that matches
710 * with our mode. */
711 check_ssid = 1;
712 if (ssid->ssid_len == 0 &&
713 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
714 check_ssid = 0;
715 }
716#endif /* CONFIG_WPS */
717
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800718 if (ssid->bssid_set && ssid->ssid_len == 0 &&
719 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
720 check_ssid = 0;
721
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700723 (bss->ssid_len != ssid->ssid_len ||
724 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
726 continue;
727 }
728
729 if (ssid->bssid_set &&
730 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
731 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
732 continue;
733 }
734
735 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
736 continue;
737
738 if (!wpa &&
739 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
740 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
741 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
742 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
743 "not allowed");
744 continue;
745 }
746
Jouni Malinen75ecf522011-06-27 15:19:46 -0700747 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
749 "mismatch");
750 continue;
751 }
752
Jouni Malinen75ecf522011-06-27 15:19:46 -0700753 if (bss->caps & IEEE80211_CAP_IBSS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
755 "network");
756 continue;
757 }
758
759 if (!freq_allowed(ssid->freq_list, bss->freq)) {
760 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
761 "allowed");
762 continue;
763 }
764
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800765 if (!rate_match(wpa_s, bss)) {
766 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
767 "not match");
768 continue;
769 }
770
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771#ifdef CONFIG_P2P
772 /*
773 * TODO: skip the AP if its P2P IE has Group Formation
774 * bit set in the P2P Group Capability Bitmap and we
775 * are not in Group Formation with that device.
776 */
777#endif /* CONFIG_P2P */
778
779 /* Matching configuration found */
780 return ssid;
781 }
782
783 /* No matching configuration found */
784 return NULL;
785}
786
787
788static struct wpa_bss *
789wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 struct wpa_ssid *group,
791 struct wpa_ssid **selected_ssid)
792{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700793 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794
795 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
796 group->priority);
797
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700798 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
799 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
801 if (!*selected_ssid)
802 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
804 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700805 MAC2STR(bss->bssid),
806 wpa_ssid_txt(bss->ssid, bss->ssid_len));
807 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 }
809
810 return NULL;
811}
812
813
814static struct wpa_bss *
815wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816 struct wpa_ssid **selected_ssid)
817{
818 struct wpa_bss *selected = NULL;
819 int prio;
820
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700821 if (wpa_s->last_scan_res == NULL ||
822 wpa_s->last_scan_res_used == 0)
823 return NULL; /* no scan results from last update */
824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825 while (selected == NULL) {
826 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
827 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700828 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 selected_ssid);
830 if (selected)
831 break;
832 }
833
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800834 if (selected == NULL && wpa_s->blacklist &&
835 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
837 "blacklist and try again");
838 wpa_blacklist_clear(wpa_s);
839 wpa_s->blacklist_cleared++;
840 } else if (selected == NULL)
841 break;
842 }
843
844 return selected;
845}
846
847
848static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
849 int timeout_sec, int timeout_usec)
850{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700851 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 /*
853 * No networks are enabled; short-circuit request so
854 * we don't wait timeout seconds before transitioning
855 * to INACTIVE state.
856 */
857 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
858 return;
859 }
860 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
861}
862
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800863
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700864int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800865 struct wpa_bss *selected,
866 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867{
868 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
869 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
870 "PBC session overlap");
871#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800872 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700873 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874#endif /* CONFIG_P2P */
875
876#ifdef CONFIG_WPS
877 wpas_wps_cancel(wpa_s);
878#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700879 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 }
881
882 /*
883 * Do not trigger new association unless the BSSID has changed or if
884 * reassociation is requested. If we are in process of associating with
885 * the selected BSSID, do not trigger new attempt.
886 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800887 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
889 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
890 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
891 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
892 0))) {
893 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
894 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700895 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896 }
897 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
898 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
899 " pending: " MACSTR " wpa_state: %s",
900 wpa_s->reassociate, MAC2STR(selected->bssid),
901 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
902 wpa_supplicant_state_txt(wpa_s->wpa_state));
903 wpa_supplicant_associate(wpa_s, selected, ssid);
904 } else {
905 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
906 "selected AP");
907 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800908
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700909 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910}
911
912
913static struct wpa_ssid *
914wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
915{
916 int prio;
917 struct wpa_ssid *ssid;
918
919 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
920 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
921 {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700922 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 continue;
924 if (ssid->mode == IEEE80211_MODE_IBSS ||
925 ssid->mode == IEEE80211_MODE_AP)
926 return ssid;
927 }
928 }
929 return NULL;
930}
931
932
933/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
934 * on BSS added and BSS changed events */
935static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +0300936 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937{
Jouni Malinen87fd2792011-05-16 18:35:42 +0300938 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939
940 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
941 return;
942
Jouni Malinen87fd2792011-05-16 18:35:42 +0300943 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945
Jouni Malinen87fd2792011-05-16 18:35:42 +0300946 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 if (ssid == NULL)
948 continue;
949
Jouni Malinen87fd2792011-05-16 18:35:42 +0300950 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 if (rsn == NULL)
952 continue;
953
Jouni Malinen87fd2792011-05-16 18:35:42 +0300954 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 }
956
957}
958
959
960static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
961 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700962 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700964 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 int min_diff;
966
967 if (wpa_s->reassociate)
968 return 1; /* explicit request to reassociate */
969 if (wpa_s->wpa_state < WPA_ASSOCIATED)
970 return 1; /* we are not associated; continue */
971 if (wpa_s->current_ssid == NULL)
972 return 1; /* unknown current SSID */
973 if (wpa_s->current_ssid != ssid)
974 return 1; /* different network block */
975
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800976 if (wpas_driver_bss_selection(wpa_s))
977 return 0; /* Driver-based roaming */
978
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700979 if (wpa_s->current_ssid->ssid)
980 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
981 wpa_s->current_ssid->ssid,
982 wpa_s->current_ssid->ssid_len);
983 if (!current_bss)
984 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985
986 if (!current_bss)
987 return 1; /* current BSS not seen in scan results */
988
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700989 if (current_bss == selected)
990 return 0;
991
992 if (selected->last_update_idx > current_bss->last_update_idx)
993 return 1; /* current BSS not seen in the last scan */
994
Dmitry Shmidt9e077672012-04-13 10:07:27 -0700995#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
997 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
998 MAC2STR(current_bss->bssid), current_bss->level);
999 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1000 MAC2STR(selected->bssid), selected->level);
1001
1002 if (wpa_s->current_ssid->bssid_set &&
1003 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1004 0) {
1005 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1006 "has preferred BSSID");
1007 return 1;
1008 }
1009
1010 min_diff = 2;
1011 if (current_bss->level < 0) {
1012 if (current_bss->level < -85)
1013 min_diff = 1;
1014 else if (current_bss->level < -80)
1015 min_diff = 2;
1016 else if (current_bss->level < -75)
1017 min_diff = 3;
1018 else if (current_bss->level < -70)
1019 min_diff = 4;
1020 else
1021 min_diff = 5;
1022 }
1023 if (abs(current_bss->level - selected->level) < min_diff) {
1024 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1025 "in signal level");
1026 return 0;
1027 }
1028
1029 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001030#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001031 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001032#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033}
1034
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001035
Dmitry Shmidt04949592012-07-19 12:16:46 -07001036/* Return < 0 if no scan results could be fetched or if scan results should not
1037 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001038#ifdef ANDROID_P2P
1039static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1040 union wpa_event_data *data, int suppress_event)
1041#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1043 union wpa_event_data *data)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001044#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 struct wpa_scan_results *scan_res;
1047 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001048#ifndef CONFIG_NO_RANDOM_POOL
1049 size_t i, num;
1050#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051
1052#ifdef CONFIG_AP
1053 if (wpa_s->ap_iface)
1054 ap = 1;
1055#endif /* CONFIG_AP */
1056
1057 wpa_supplicant_notify_scanning(wpa_s, 0);
1058
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001059#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07001060 if (wpa_s->global->p2p_cb_on_scan_complete &&
1061 !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001062 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001063 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001064 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1065 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1066 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001067 wpa_s->sta_scan_pending = 1;
1068 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 return -1;
1070 }
1071 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001072 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001073#endif /* CONFIG_P2P */
1074
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1076 data ? &data->scan_info :
1077 NULL, 1);
1078 if (scan_res == NULL) {
1079 if (wpa_s->conf->ap_scan == 2 || ap)
1080 return -1;
1081 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1082 "scanning again");
1083 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1084 return -1;
1085 }
1086
1087#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 num = scan_res->num;
1089 if (num > 10)
1090 num = 10;
1091 for (i = 0; i < num; i++) {
1092 u8 buf[5];
1093 struct wpa_scan_res *res = scan_res->res[i];
1094 buf[0] = res->bssid[5];
1095 buf[1] = res->qual & 0xff;
1096 buf[2] = res->noise & 0xff;
1097 buf[3] = res->level & 0xff;
1098 buf[4] = res->tsf & 0xff;
1099 random_add_randomness(buf, sizeof(buf));
1100 }
1101#endif /* CONFIG_NO_RANDOM_POOL */
1102
1103 if (wpa_s->scan_res_handler) {
1104 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1105 struct wpa_scan_results *scan_res);
1106
1107 scan_res_handler = wpa_s->scan_res_handler;
1108 wpa_s->scan_res_handler = NULL;
1109 scan_res_handler(wpa_s, scan_res);
1110
1111 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001112 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 }
1114
1115 if (ap) {
1116 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1117#ifdef CONFIG_AP
1118 if (wpa_s->ap_iface->scan_cb)
1119 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1120#endif /* CONFIG_AP */
1121 wpa_scan_results_free(scan_res);
1122 return 0;
1123 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001124#ifdef ANDROID_P2P
1125 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001126 {
1127 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1128 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1129 wpas_notify_scan_results(wpa_s);
1130 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001131#else
1132 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1133 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1134 wpas_notify_scan_results(wpa_s);
1135#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136
1137 wpas_notify_scan_done(wpa_s, 1);
1138
Dmitry Shmidt04949592012-07-19 12:16:46 -07001139 if (sme_proc_obss_scan(wpa_s) > 0) {
1140 wpa_scan_results_free(scan_res);
1141 return 0;
1142 }
1143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1145 wpa_scan_results_free(scan_res);
1146 return 0;
1147 }
1148
Dmitry Shmidt04949592012-07-19 12:16:46 -07001149 if (autoscan_notify_scan(wpa_s, scan_res)) {
1150 wpa_scan_results_free(scan_res);
1151 return 0;
1152 }
1153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154 if (wpa_s->disconnected) {
1155 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1156 wpa_scan_results_free(scan_res);
1157 return 0;
1158 }
1159
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001160 if (!wpas_driver_bss_selection(wpa_s) &&
1161 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001162 wpa_scan_results_free(scan_res);
1163 return 0;
1164 }
1165
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001166 wpas_wps_update_ap_info(wpa_s, scan_res);
1167
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001168 wpa_scan_results_free(scan_res);
1169
1170 return wpas_select_network_from_last_scan(wpa_s);
1171}
1172
1173
1174int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1175{
1176 struct wpa_bss *selected;
1177 struct wpa_ssid *ssid = NULL;
1178
1179 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180
1181 if (selected) {
1182 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001183 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001184 if (skip) {
1185 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001187 }
1188
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001189 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001190 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001191 return -1;
1192 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001193 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001194 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1196 ssid = wpa_supplicant_pick_new_network(wpa_s);
1197 if (ssid) {
1198 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1199 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001200 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 } else {
1202 int timeout_sec = wpa_s->scan_interval;
1203 int timeout_usec = 0;
1204#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001205 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1206 return 0;
1207
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 if (wpa_s->p2p_in_provisioning) {
1209 /*
1210 * Use shorter wait during P2P Provisioning
1211 * state to speed up group formation.
1212 */
1213 timeout_sec = 0;
1214 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001215 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1216 timeout_usec);
1217 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 }
1219#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001220#ifdef CONFIG_INTERWORKING
1221 if (wpa_s->conf->auto_interworking &&
1222 wpa_s->conf->interworking &&
1223 wpa_s->conf->cred) {
1224 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1225 "start ANQP fetch since no matching "
1226 "networks found");
1227 wpa_s->network_select = 1;
1228 wpa_s->auto_network_select = 1;
1229 interworking_start_fetch_anqp(wpa_s);
1230 return 0;
1231 }
1232#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001233 if (wpa_supplicant_req_sched_scan(wpa_s))
1234 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1235 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 }
1237 }
1238 return 0;
1239}
1240
1241
1242static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1243 union wpa_event_data *data)
1244{
1245 const char *rn, *rn2;
1246 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001247#ifdef ANDROID_P2P
1248 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1249#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001251#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 /*
1253 * If no scan results could be fetched, then no need to
1254 * notify those interfaces that did not actually request
1255 * this scan.
1256 */
1257 return;
1258 }
1259
1260 /*
1261 * Check other interfaces to see if they have the same radio-name. If
1262 * so, they get updated with this same scan info.
1263 */
1264 if (!wpa_s->driver->get_radio_name)
1265 return;
1266
1267 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1268 if (rn == NULL || rn[0] == '\0')
1269 return;
1270
1271 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1272 "sharing same radio (%s) in event_scan_results", rn);
1273
1274 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1275 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1276 continue;
1277
1278 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1279 if (rn2 && os_strcmp(rn, rn2) == 0) {
1280 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1281 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001282#ifdef ANDROID_P2P
1283 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1284 /* Do not update the scan results from STA interface to p2p interfaces */
1285 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1286 "sibling %s", ifs->ifname, wpa_s->ifname);
1287 continue;
1288 }
1289 else {
1290 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1291 * no time. Avoid announcing it to application as it may not
1292 * be that useful (since results will be that of only 1,6,11).
1293 * over to any other interface as it
1294 */
1295 if(p2p_search_in_progress(wpa_s->global->p2p))
1296 _wpa_supplicant_event_scan_results(ifs, data, 1);
1297 else
1298 _wpa_supplicant_event_scan_results(ifs, data, 0);
1299 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001300#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001301 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001302#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 }
1304 }
1305}
1306
1307#endif /* CONFIG_NO_SCAN_PROCESSING */
1308
1309
Dmitry Shmidt04949592012-07-19 12:16:46 -07001310#ifdef CONFIG_WNM
1311
1312static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1313{
1314 struct wpa_supplicant *wpa_s = eloop_ctx;
1315
1316 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1317 return;
1318
1319 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1320 MAC2STR(wpa_s->bssid));
1321 /* TODO: could skip this if normal data traffic has been sent */
1322 /* TODO: Consider using some more appropriate data frame for this */
1323 if (wpa_s->l2)
1324 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1325
1326#ifdef CONFIG_SME
1327 if (wpa_s->sme.bss_max_idle_period) {
1328 unsigned int msec;
1329 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1330 if (msec > 100)
1331 msec -= 100;
1332 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1333 wnm_bss_keep_alive, wpa_s, NULL);
1334 }
1335#endif /* CONFIG_SME */
1336}
1337
1338
1339static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1340 const u8 *ies, size_t ies_len)
1341{
1342 struct ieee802_11_elems elems;
1343
1344 if (ies == NULL)
1345 return;
1346
1347 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1348 return;
1349
1350#ifdef CONFIG_SME
1351 if (elems.bss_max_idle_period) {
1352 unsigned int msec;
1353 wpa_s->sme.bss_max_idle_period =
1354 WPA_GET_LE16(elems.bss_max_idle_period);
1355 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1356 "TU)%s", wpa_s->sme.bss_max_idle_period,
1357 (elems.bss_max_idle_period[2] & 0x01) ?
1358 " (protected keep-live required)" : "");
1359 if (wpa_s->sme.bss_max_idle_period == 0)
1360 wpa_s->sme.bss_max_idle_period = 1;
1361 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1362 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1363 /* msec times 1000 */
1364 msec = wpa_s->sme.bss_max_idle_period * 1024;
1365 if (msec > 100)
1366 msec -= 100;
1367 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1368 wnm_bss_keep_alive, wpa_s,
1369 NULL);
1370 }
1371 }
1372#endif /* CONFIG_SME */
1373}
1374
1375#endif /* CONFIG_WNM */
1376
1377
1378void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1379{
1380#ifdef CONFIG_WNM
1381 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1382#endif /* CONFIG_WNM */
1383}
1384
1385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1387 union wpa_event_data *data)
1388{
1389 int l, len, found = 0, wpa_found, rsn_found;
1390 const u8 *p;
1391
1392 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1393 if (data->assoc_info.req_ies)
1394 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1395 data->assoc_info.req_ies_len);
1396 if (data->assoc_info.resp_ies) {
1397 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1398 data->assoc_info.resp_ies_len);
1399#ifdef CONFIG_TDLS
1400 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1401 data->assoc_info.resp_ies_len);
1402#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001403#ifdef CONFIG_WNM
1404 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1405 data->assoc_info.resp_ies_len);
1406#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001407 }
1408 if (data->assoc_info.beacon_ies)
1409 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1410 data->assoc_info.beacon_ies,
1411 data->assoc_info.beacon_ies_len);
1412 if (data->assoc_info.freq)
1413 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1414 data->assoc_info.freq);
1415
1416 p = data->assoc_info.req_ies;
1417 l = data->assoc_info.req_ies_len;
1418
1419 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1420 while (p && l >= 2) {
1421 len = p[1] + 2;
1422 if (len > l) {
1423 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1424 p, l);
1425 break;
1426 }
1427 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1428 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1429 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1430 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1431 break;
1432 found = 1;
1433 wpa_find_assoc_pmkid(wpa_s);
1434 break;
1435 }
1436 l -= len;
1437 p += len;
1438 }
1439 if (!found && data->assoc_info.req_ies)
1440 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1441
1442#ifdef CONFIG_IEEE80211R
1443#ifdef CONFIG_SME
1444 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1445 u8 bssid[ETH_ALEN];
1446 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1447 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1448 data->assoc_info.resp_ies,
1449 data->assoc_info.resp_ies_len,
1450 bssid) < 0) {
1451 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1452 "Reassociation Response failed");
1453 wpa_supplicant_deauthenticate(
1454 wpa_s, WLAN_REASON_INVALID_IE);
1455 return -1;
1456 }
1457 }
1458
1459 p = data->assoc_info.resp_ies;
1460 l = data->assoc_info.resp_ies_len;
1461
1462#ifdef CONFIG_WPS_STRICT
1463 if (p && wpa_s->current_ssid &&
1464 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1465 struct wpabuf *wps;
1466 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1467 if (wps == NULL) {
1468 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1469 "include WPS IE in (Re)Association Response");
1470 return -1;
1471 }
1472
1473 if (wps_validate_assoc_resp(wps) < 0) {
1474 wpabuf_free(wps);
1475 wpa_supplicant_deauthenticate(
1476 wpa_s, WLAN_REASON_INVALID_IE);
1477 return -1;
1478 }
1479 wpabuf_free(wps);
1480 }
1481#endif /* CONFIG_WPS_STRICT */
1482
1483 /* Go through the IEs and make a copy of the MDIE, if present. */
1484 while (p && l >= 2) {
1485 len = p[1] + 2;
1486 if (len > l) {
1487 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1488 p, l);
1489 break;
1490 }
1491 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1492 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1493 wpa_s->sme.ft_used = 1;
1494 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1495 MOBILITY_DOMAIN_ID_LEN);
1496 break;
1497 }
1498 l -= len;
1499 p += len;
1500 }
1501#endif /* CONFIG_SME */
1502
1503 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1504 data->assoc_info.resp_ies_len);
1505#endif /* CONFIG_IEEE80211R */
1506
1507 /* WPA/RSN IE from Beacon/ProbeResp */
1508 p = data->assoc_info.beacon_ies;
1509 l = data->assoc_info.beacon_ies_len;
1510
1511 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1512 */
1513 wpa_found = rsn_found = 0;
1514 while (p && l >= 2) {
1515 len = p[1] + 2;
1516 if (len > l) {
1517 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1518 p, l);
1519 break;
1520 }
1521 if (!wpa_found &&
1522 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1523 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1524 wpa_found = 1;
1525 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1526 }
1527
1528 if (!rsn_found &&
1529 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1530 rsn_found = 1;
1531 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1532 }
1533
1534 l -= len;
1535 p += len;
1536 }
1537
1538 if (!wpa_found && data->assoc_info.beacon_ies)
1539 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1540 if (!rsn_found && data->assoc_info.beacon_ies)
1541 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1542 if (wpa_found || rsn_found)
1543 wpa_s->ap_ies_from_associnfo = 1;
1544
Jouni Malinen87fd2792011-05-16 18:35:42 +03001545 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1546 wpa_s->assoc_freq != data->assoc_info.freq) {
1547 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1548 "%u to %u MHz",
1549 wpa_s->assoc_freq, data->assoc_info.freq);
1550 wpa_supplicant_update_scan_results(wpa_s);
1551 }
1552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001553 wpa_s->assoc_freq = data->assoc_info.freq;
1554
1555 return 0;
1556}
1557
1558
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001559static struct wpa_bss * wpa_supplicant_get_new_bss(
1560 struct wpa_supplicant *wpa_s, const u8 *bssid)
1561{
1562 struct wpa_bss *bss = NULL;
1563 struct wpa_ssid *ssid = wpa_s->current_ssid;
1564
1565 if (ssid->ssid_len > 0)
1566 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1567 if (!bss)
1568 bss = wpa_bss_get_bssid(wpa_s, bssid);
1569
1570 return bss;
1571}
1572
1573
1574static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1575{
1576 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1577
1578 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1579 return -1;
1580
1581 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1582 return 0;
1583
1584 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1585 WPA_IE_VENDOR_TYPE);
1586 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1587
1588 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1589 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1590 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1591 bss_rsn ? 2 + bss_rsn[1] : 0))
1592 return -1;
1593
1594 return 0;
1595}
1596
1597
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001598static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1599 union wpa_event_data *data)
1600{
1601 u8 bssid[ETH_ALEN];
1602 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 struct wpa_driver_capa capa;
1604
1605#ifdef CONFIG_AP
1606 if (wpa_s->ap_iface) {
1607 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1608 data->assoc_info.addr,
1609 data->assoc_info.req_ies,
1610 data->assoc_info.req_ies_len,
1611 data->assoc_info.reassoc);
1612 return;
1613 }
1614#endif /* CONFIG_AP */
1615
1616 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1617 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1618 return;
1619
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001620 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1621 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1622 wpa_supplicant_disassociate(
1623 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1624 return;
1625 }
1626
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001628 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1630 MACSTR, MAC2STR(bssid));
1631 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001632 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1633 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001634 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635
1636 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1637 wpa_clear_keys(wpa_s, bssid);
1638 }
1639 if (wpa_supplicant_select_config(wpa_s) < 0) {
1640 wpa_supplicant_disassociate(
1641 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1642 return;
1643 }
1644 if (wpa_s->current_ssid) {
1645 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001646
1647 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1648 if (!bss) {
1649 wpa_supplicant_update_scan_results(wpa_s);
1650
1651 /* Get the BSS from the new scan results */
1652 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1653 }
1654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 if (bss)
1656 wpa_s->current_bss = bss;
1657 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001658
1659 if (wpa_s->conf->ap_scan == 1 &&
1660 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1661 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1662 wpa_msg(wpa_s, MSG_WARNING,
1663 "WPA/RSN IEs not updated");
1664 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665 }
1666
1667#ifdef CONFIG_SME
1668 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1669 wpa_s->sme.prev_bssid_set = 1;
1670#endif /* CONFIG_SME */
1671
1672 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1673 if (wpa_s->current_ssid) {
1674 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1675 * initialized before association, but for other modes,
1676 * initialize PC/SC here, if the current configuration needs
1677 * smartcard or SIM/USIM. */
1678 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1679 }
1680 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1681 if (wpa_s->l2)
1682 l2_packet_notify_auth_start(wpa_s->l2);
1683
1684 /*
1685 * Set portEnabled first to FALSE in order to get EAP state machine out
1686 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1687 * state machine may transit to AUTHENTICATING state based on obsolete
1688 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1689 * AUTHENTICATED without ever giving chance to EAP state machine to
1690 * reset the state.
1691 */
1692 if (!ft_completed) {
1693 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1694 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1695 }
1696 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1697 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1698 /* 802.1X::portControl = Auto */
1699 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1700 wpa_s->eapol_received = 0;
1701 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1702 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1703 (wpa_s->current_ssid &&
1704 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1705 wpa_supplicant_cancel_auth_timeout(wpa_s);
1706 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1707 } else if (!ft_completed) {
1708 /* Timeout for receiving the first EAPOL packet */
1709 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1710 }
1711 wpa_supplicant_cancel_scan(wpa_s);
1712
1713 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1714 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1715 /*
1716 * We are done; the driver will take care of RSN 4-way
1717 * handshake.
1718 */
1719 wpa_supplicant_cancel_auth_timeout(wpa_s);
1720 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1721 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1722 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1723 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1724 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1725 /*
1726 * The driver will take care of RSN 4-way handshake, so we need
1727 * to allow EAPOL supplicant to complete its work without
1728 * waiting for WPA supplicant.
1729 */
1730 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1731 } else if (ft_completed) {
1732 /*
1733 * FT protocol completed - make sure EAPOL state machine ends
1734 * up in authenticated.
1735 */
1736 wpa_supplicant_cancel_auth_timeout(wpa_s);
1737 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1738 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1739 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1740 }
1741
1742 if (wpa_s->pending_eapol_rx) {
1743 struct os_time now, age;
1744 os_get_time(&now);
1745 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1746 if (age.sec == 0 && age.usec < 100000 &&
1747 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1748 0) {
1749 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1750 "frame that was received just before "
1751 "association notification");
1752 wpa_supplicant_rx_eapol(
1753 wpa_s, wpa_s->pending_eapol_rx_src,
1754 wpabuf_head(wpa_s->pending_eapol_rx),
1755 wpabuf_len(wpa_s->pending_eapol_rx));
1756 }
1757 wpabuf_free(wpa_s->pending_eapol_rx);
1758 wpa_s->pending_eapol_rx = NULL;
1759 }
1760
1761 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1762 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1763 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1764 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1765 /* Set static WEP keys again */
1766 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1767 }
1768
1769#ifdef CONFIG_IBSS_RSN
1770 if (wpa_s->current_ssid &&
1771 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1772 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1773 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1774 wpa_s->ibss_rsn == NULL) {
1775 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1776 if (!wpa_s->ibss_rsn) {
1777 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1778 wpa_supplicant_deauthenticate(
1779 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1780 return;
1781 }
1782
1783 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1784 }
1785#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001786
1787 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001788}
1789
1790
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001791static int disconnect_reason_recoverable(u16 reason_code)
1792{
1793 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1794 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1795 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1796}
1797
1798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001800 u16 reason_code,
1801 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802{
1803 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001804
1805 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1806 /*
1807 * At least Host AP driver and a Prism3 card seemed to be
1808 * generating streams of disconnected events when configuring
1809 * IBSS for WPA-None. Ignore them for now.
1810 */
1811 return;
1812 }
1813
1814 bssid = wpa_s->bssid;
1815 if (is_zero_ether_addr(bssid))
1816 bssid = wpa_s->pending_bssid;
1817
1818 if (!is_zero_ether_addr(bssid) ||
1819 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1820 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1821 " reason=%d%s",
1822 MAC2STR(bssid), reason_code,
1823 locally_generated ? " locally_generated=1" : "");
1824 }
1825}
1826
1827
1828static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1829 u16 reason_code,
1830 int locally_generated)
1831{
1832 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 int authenticating;
1834 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001835 struct wpa_bss *fast_reconnect = NULL;
1836 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001837 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838
1839 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1840 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1841
1842 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1843 /*
1844 * At least Host AP driver and a Prism3 card seemed to be
1845 * generating streams of disconnected events when configuring
1846 * IBSS for WPA-None. Ignore them for now.
1847 */
1848 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1849 "IBSS/WPA-None mode");
1850 return;
1851 }
1852
1853 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1854 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1855 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1856 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001857 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 }
1859 if (!wpa_s->auto_reconnect_disabled ||
1860 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001861 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1862 "reconnect (wps=%d wpa_state=%d)",
1863 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1864 wpa_s->wpa_state);
1865 if (wpa_s->wpa_state == WPA_COMPLETED &&
1866 wpa_s->current_ssid &&
1867 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001868 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001869 disconnect_reason_recoverable(reason_code)) {
1870 /*
1871 * It looks like the AP has dropped association with
1872 * us, but could allow us to get back in. Try to
1873 * reconnect to the same BSS without full scan to save
1874 * time for some common cases.
1875 */
1876 fast_reconnect = wpa_s->current_bss;
1877 fast_reconnect_ssid = wpa_s->current_ssid;
1878 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001879#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001880 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001881#else
1882 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1883#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884 else
1885 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1886 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001888 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 "try to re-connect");
1890 wpa_s->reassociate = 0;
1891 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001892 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001893 }
1894 bssid = wpa_s->bssid;
1895 if (is_zero_ether_addr(bssid))
1896 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001897 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1898 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001900 if (locally_generated)
1901 wpa_s->disconnect_reason = -reason_code;
1902 else
1903 wpa_s->disconnect_reason = reason_code;
1904 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1906 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1907 wpa_s->keys_cleared = 0;
1908 wpa_clear_keys(wpa_s, wpa_s->bssid);
1909 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001910 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001911 wpa_supplicant_mark_disassoc(wpa_s);
1912
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001913 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001914 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001915 wpa_s->current_ssid = last_ssid;
1916 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001917
1918 if (fast_reconnect) {
1919#ifndef CONFIG_NO_SCAN_PROCESSING
1920 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1921 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1922 fast_reconnect_ssid) < 0) {
1923 /* Recover through full scan */
1924 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1925 }
1926#endif /* CONFIG_NO_SCAN_PROCESSING */
1927 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001928}
1929
1930
1931#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001932void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001933{
1934 struct wpa_supplicant *wpa_s = eloop_ctx;
1935
1936 if (!wpa_s->pending_mic_error_report)
1937 return;
1938
1939 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1940 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1941 wpa_s->pending_mic_error_report = 0;
1942}
1943#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1944
1945
1946static void
1947wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1948 union wpa_event_data *data)
1949{
1950 int pairwise;
1951 struct os_time t;
1952
1953 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1954 pairwise = (data && data->michael_mic_failure.unicast);
1955 os_get_time(&t);
1956 if ((wpa_s->last_michael_mic_error &&
1957 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1958 wpa_s->pending_mic_error_report) {
1959 if (wpa_s->pending_mic_error_report) {
1960 /*
1961 * Send the pending MIC error report immediately since
1962 * we are going to start countermeasures and AP better
1963 * do the same.
1964 */
1965 wpa_sm_key_request(wpa_s->wpa, 1,
1966 wpa_s->pending_mic_error_pairwise);
1967 }
1968
1969 /* Send the new MIC error report immediately since we are going
1970 * to start countermeasures and AP better do the same.
1971 */
1972 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1973
1974 /* initialize countermeasures */
1975 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001976
1977 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1980
1981 /*
1982 * Need to wait for completion of request frame. We do not get
1983 * any callback for the message completion, so just wait a
1984 * short while and hope for the best. */
1985 os_sleep(0, 10000);
1986
1987 wpa_drv_set_countermeasures(wpa_s, 1);
1988 wpa_supplicant_deauthenticate(wpa_s,
1989 WLAN_REASON_MICHAEL_MIC_FAILURE);
1990 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1991 wpa_s, NULL);
1992 eloop_register_timeout(60, 0,
1993 wpa_supplicant_stop_countermeasures,
1994 wpa_s, NULL);
1995 /* TODO: mark the AP rejected for 60 second. STA is
1996 * allowed to associate with another AP.. */
1997 } else {
1998#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1999 if (wpa_s->mic_errors_seen) {
2000 /*
2001 * Reduce the effectiveness of Michael MIC error
2002 * reports as a means for attacking against TKIP if
2003 * more than one MIC failure is noticed with the same
2004 * PTK. We delay the transmission of the reports by a
2005 * random time between 0 and 60 seconds in order to
2006 * force the attacker wait 60 seconds before getting
2007 * the information on whether a frame resulted in a MIC
2008 * failure.
2009 */
2010 u8 rval[4];
2011 int sec;
2012
2013 if (os_get_random(rval, sizeof(rval)) < 0)
2014 sec = os_random() % 60;
2015 else
2016 sec = WPA_GET_BE32(rval) % 60;
2017 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2018 "report %d seconds", sec);
2019 wpa_s->pending_mic_error_report = 1;
2020 wpa_s->pending_mic_error_pairwise = pairwise;
2021 eloop_cancel_timeout(
2022 wpa_supplicant_delayed_mic_error_report,
2023 wpa_s, NULL);
2024 eloop_register_timeout(
2025 sec, os_random() % 1000000,
2026 wpa_supplicant_delayed_mic_error_report,
2027 wpa_s, NULL);
2028 } else {
2029 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2030 }
2031#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2032 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2033#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2034 }
2035 wpa_s->last_michael_mic_error = t.sec;
2036 wpa_s->mic_errors_seen++;
2037}
2038
2039
2040#ifdef CONFIG_TERMINATE_ONLASTIF
2041static int any_interfaces(struct wpa_supplicant *head)
2042{
2043 struct wpa_supplicant *wpa_s;
2044
2045 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2046 if (!wpa_s->interface_removed)
2047 return 1;
2048 return 0;
2049}
2050#endif /* CONFIG_TERMINATE_ONLASTIF */
2051
2052
2053static void
2054wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2055 union wpa_event_data *data)
2056{
2057 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2058 return;
2059
2060 switch (data->interface_status.ievent) {
2061 case EVENT_INTERFACE_ADDED:
2062 if (!wpa_s->interface_removed)
2063 break;
2064 wpa_s->interface_removed = 0;
2065 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2066 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2067 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2068 "driver after interface was added");
2069 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002070 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 break;
2072 case EVENT_INTERFACE_REMOVED:
2073 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2074 wpa_s->interface_removed = 1;
2075 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002076 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 l2_packet_deinit(wpa_s->l2);
2078 wpa_s->l2 = NULL;
2079#ifdef CONFIG_IBSS_RSN
2080 ibss_rsn_deinit(wpa_s->ibss_rsn);
2081 wpa_s->ibss_rsn = NULL;
2082#endif /* CONFIG_IBSS_RSN */
2083#ifdef CONFIG_TERMINATE_ONLASTIF
2084 /* check if last interface */
2085 if (!any_interfaces(wpa_s->global->ifaces))
2086 eloop_terminate();
2087#endif /* CONFIG_TERMINATE_ONLASTIF */
2088 break;
2089 }
2090}
2091
2092
2093#ifdef CONFIG_PEERKEY
2094static void
2095wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2096 union wpa_event_data *data)
2097{
2098 if (data == NULL)
2099 return;
2100 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2101}
2102#endif /* CONFIG_PEERKEY */
2103
2104
2105#ifdef CONFIG_TDLS
2106static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2107 union wpa_event_data *data)
2108{
2109 if (data == NULL)
2110 return;
2111 switch (data->tdls.oper) {
2112 case TDLS_REQUEST_SETUP:
2113 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2114 break;
2115 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002116 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2117 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 break;
2119 }
2120}
2121#endif /* CONFIG_TDLS */
2122
2123
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002124#ifdef CONFIG_IEEE80211V
2125static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2126 union wpa_event_data *data)
2127{
2128 if (data == NULL)
2129 return;
2130 switch (data->wnm.oper) {
2131 case WNM_OPER_SLEEP:
2132 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2133 "(action=%d, intval=%d)",
2134 data->wnm.sleep_action, data->wnm.sleep_intval);
2135 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2136 data->wnm.sleep_intval);
2137 break;
2138 }
2139}
2140#endif /* CONFIG_IEEE80211V */
2141
2142
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143#ifdef CONFIG_IEEE80211R
2144static void
2145wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2146 union wpa_event_data *data)
2147{
2148 if (data == NULL)
2149 return;
2150
2151 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2152 data->ft_ies.ies_len,
2153 data->ft_ies.ft_action,
2154 data->ft_ies.target_ap,
2155 data->ft_ies.ric_ies,
2156 data->ft_ies.ric_ies_len) < 0) {
2157 /* TODO: prevent MLME/driver from trying to associate? */
2158 }
2159}
2160#endif /* CONFIG_IEEE80211R */
2161
2162
2163#ifdef CONFIG_IBSS_RSN
2164static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2165 union wpa_event_data *data)
2166{
2167 struct wpa_ssid *ssid;
2168 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2169 return;
2170 if (data == NULL)
2171 return;
2172 ssid = wpa_s->current_ssid;
2173 if (ssid == NULL)
2174 return;
2175 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2176 return;
2177
2178 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2179}
2180#endif /* CONFIG_IBSS_RSN */
2181
2182
2183#ifdef CONFIG_IEEE80211R
2184static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2185 size_t len)
2186{
2187 const u8 *sta_addr, *target_ap_addr;
2188 u16 status;
2189
2190 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2191 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2192 return; /* only SME case supported for now */
2193 if (len < 1 + 2 * ETH_ALEN + 2)
2194 return;
2195 if (data[0] != 2)
2196 return; /* Only FT Action Response is supported for now */
2197 sta_addr = data + 1;
2198 target_ap_addr = data + 1 + ETH_ALEN;
2199 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2200 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2201 MACSTR " TargetAP " MACSTR " status %u",
2202 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2203
2204 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2205 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2206 " in FT Action Response", MAC2STR(sta_addr));
2207 return;
2208 }
2209
2210 if (status) {
2211 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2212 "failure (status code %d)", status);
2213 /* TODO: report error to FT code(?) */
2214 return;
2215 }
2216
2217 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2218 len - (1 + 2 * ETH_ALEN + 2), 1,
2219 target_ap_addr, NULL, 0) < 0)
2220 return;
2221
2222#ifdef CONFIG_SME
2223 {
2224 struct wpa_bss *bss;
2225 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2226 if (bss)
2227 wpa_s->sme.freq = bss->freq;
2228 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2229 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2230 WLAN_AUTH_FT);
2231 }
2232#endif /* CONFIG_SME */
2233}
2234#endif /* CONFIG_IEEE80211R */
2235
2236
2237static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2238 struct unprot_deauth *e)
2239{
2240#ifdef CONFIG_IEEE80211W
2241 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2242 "dropped: " MACSTR " -> " MACSTR
2243 " (reason code %u)",
2244 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2245 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2246#endif /* CONFIG_IEEE80211W */
2247}
2248
2249
2250static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2251 struct unprot_disassoc *e)
2252{
2253#ifdef CONFIG_IEEE80211W
2254 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2255 "dropped: " MACSTR " -> " MACSTR
2256 " (reason code %u)",
2257 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2258 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2259#endif /* CONFIG_IEEE80211W */
2260}
2261
2262
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002263static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2264{
2265 u8 action, mode;
2266 const u8 *pos, *end;
2267
2268 if (rx->data == NULL || rx->len == 0)
2269 return;
2270
2271 pos = rx->data;
2272 end = pos + rx->len;
2273 action = *pos++;
2274
2275 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2276 action, MAC2STR(rx->sa));
2277 switch (action) {
2278 case WNM_BSS_TRANS_MGMT_REQ:
2279 if (pos + 5 > end)
2280 break;
2281 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2282 "Request: dialog_token=%u request_mode=0x%x "
2283 "disassoc_timer=%u validity_interval=%u",
2284 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2285 mode = pos[1];
2286 pos += 5;
2287 if (mode & 0x08)
2288 pos += 12; /* BSS Termination Duration */
2289 if (mode & 0x10) {
2290 char url[256];
2291 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2292 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2293 "Transition Management Request "
2294 "(URL)");
2295 break;
2296 }
2297 os_memcpy(url, pos + 1, pos[0]);
2298 url[pos[0]] = '\0';
2299 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2300 "Imminent - session_info_url=%s", url);
2301 }
2302 break;
2303 }
2304}
2305
2306
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002307void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2308 union wpa_event_data *data)
2309{
2310 struct wpa_supplicant *wpa_s = ctx;
2311 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002312 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002313
2314 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2315 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002316 event != EVENT_INTERFACE_STATUS &&
2317 event != EVENT_SCHED_SCAN_STOPPED) {
2318 wpa_dbg(wpa_s, MSG_DEBUG,
2319 "Ignore event %s (%d) while interface is disabled",
2320 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002321 return;
2322 }
2323
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002324#ifndef CONFIG_NO_STDOUT_DEBUG
2325{
2326 int level = MSG_DEBUG;
2327
Dmitry Shmidt04949592012-07-19 12:16:46 -07002328 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002329 const struct ieee80211_hdr *hdr;
2330 u16 fc;
2331 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2332 fc = le_to_host16(hdr->frame_control);
2333 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2334 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2335 level = MSG_EXCESSIVE;
2336 }
2337
2338 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2339 event_to_string(event), event);
2340}
2341#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002342
2343 switch (event) {
2344 case EVENT_AUTH:
2345 sme_event_auth(wpa_s, data);
2346 break;
2347 case EVENT_ASSOC:
2348 wpa_supplicant_event_assoc(wpa_s, data);
2349 break;
2350 case EVENT_DISASSOC:
2351 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2352 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002353 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2354 data->disassoc_info.reason_code,
2355 data->disassoc_info.locally_generated ?
2356 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 if (data->disassoc_info.addr)
2358 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2359 MAC2STR(data->disassoc_info.addr));
2360 }
2361#ifdef CONFIG_AP
2362 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2363 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2364 data->disassoc_info.addr);
2365 break;
2366 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002367 if (wpa_s->ap_iface) {
2368 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2369 "AP mode");
2370 break;
2371 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002372#endif /* CONFIG_AP */
2373 if (data) {
2374 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002375 locally_generated =
2376 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002377 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2378 data->disassoc_info.ie,
2379 data->disassoc_info.ie_len);
2380#ifdef CONFIG_P2P
2381 wpas_p2p_disassoc_notif(
2382 wpa_s, data->disassoc_info.addr, reason_code,
2383 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002384 data->disassoc_info.ie_len,
2385 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386#endif /* CONFIG_P2P */
2387 }
2388 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2389 sme_event_disassoc(wpa_s, data);
2390 /* fall through */
2391 case EVENT_DEAUTH:
2392 if (event == EVENT_DEAUTH) {
2393 wpa_dbg(wpa_s, MSG_DEBUG,
2394 "Deauthentication notification");
2395 if (data) {
2396 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002397 locally_generated =
2398 data->deauth_info.locally_generated;
2399 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2400 data->deauth_info.reason_code,
2401 data->deauth_info.locally_generated ?
2402 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403 if (data->deauth_info.addr) {
2404 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2405 MACSTR,
2406 MAC2STR(data->deauth_info.
2407 addr));
2408 }
2409 wpa_hexdump(MSG_DEBUG,
2410 "Deauthentication frame IE(s)",
2411 data->deauth_info.ie,
2412 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413 }
2414 }
2415#ifdef CONFIG_AP
2416 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2417 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2418 data->deauth_info.addr);
2419 break;
2420 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002421 if (wpa_s->ap_iface) {
2422 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2423 "AP mode");
2424 break;
2425 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002426#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002427 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2428 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002429 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2430 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2431 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2432 eapol_sm_failed(wpa_s->eapol)))
2433 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002434#ifdef CONFIG_P2P
2435 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002436 if (wpas_p2p_deauth_notif(wpa_s,
2437 data->deauth_info.addr,
2438 reason_code,
2439 data->deauth_info.ie,
2440 data->deauth_info.ie_len,
2441 locally_generated) > 0) {
2442 /*
2443 * The interface was removed, so cannot
2444 * continue processing any additional
2445 * operations after this.
2446 */
2447 break;
2448 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002449 }
2450#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002451 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2452 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453 break;
2454 case EVENT_MICHAEL_MIC_FAILURE:
2455 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2456 break;
2457#ifndef CONFIG_NO_SCAN_PROCESSING
2458 case EVENT_SCAN_RESULTS:
2459 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002460#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07002461 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002462 wpa_s->global->p2p != NULL &&
2463 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2464 wpa_s->wpa_state != WPA_ASSOCIATING) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07002465 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002466 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2467 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2468 "continued after scan result processing");
2469 }
2470 }
2471#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002472 break;
2473#endif /* CONFIG_NO_SCAN_PROCESSING */
2474 case EVENT_ASSOCINFO:
2475 wpa_supplicant_event_associnfo(wpa_s, data);
2476 break;
2477 case EVENT_INTERFACE_STATUS:
2478 wpa_supplicant_event_interface_status(wpa_s, data);
2479 break;
2480 case EVENT_PMKID_CANDIDATE:
2481 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2482 break;
2483#ifdef CONFIG_PEERKEY
2484 case EVENT_STKSTART:
2485 wpa_supplicant_event_stkstart(wpa_s, data);
2486 break;
2487#endif /* CONFIG_PEERKEY */
2488#ifdef CONFIG_TDLS
2489 case EVENT_TDLS:
2490 wpa_supplicant_event_tdls(wpa_s, data);
2491 break;
2492#endif /* CONFIG_TDLS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002493#ifdef CONFIG_IEEE80211V
2494 case EVENT_WNM:
2495 wpa_supplicant_event_wnm(wpa_s, data);
2496 break;
2497#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002498#ifdef CONFIG_IEEE80211R
2499 case EVENT_FT_RESPONSE:
2500 wpa_supplicant_event_ft_response(wpa_s, data);
2501 break;
2502#endif /* CONFIG_IEEE80211R */
2503#ifdef CONFIG_IBSS_RSN
2504 case EVENT_IBSS_RSN_START:
2505 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2506 break;
2507#endif /* CONFIG_IBSS_RSN */
2508 case EVENT_ASSOC_REJECT:
2509 if (data->assoc_reject.bssid)
2510 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2511 "bssid=" MACSTR " status_code=%u",
2512 MAC2STR(data->assoc_reject.bssid),
2513 data->assoc_reject.status_code);
2514 else
2515 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2516 "status_code=%u",
2517 data->assoc_reject.status_code);
2518 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2519 sme_event_assoc_reject(wpa_s, data);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002520#ifdef ANDROID_P2P
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002521#ifdef CONFIG_P2P
2522 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002523 if(!wpa_s->current_ssid) {
2524 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2525 break;
2526 }
2527 /* If assoc reject is reported by the driver, then avoid
2528 * waiting for the authentication timeout. Cancel the
2529 * authentication timeout and retry the assoc.
2530 */
2531 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2532 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2533 wpa_s->current_ssid->assoc_retry);
2534 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002535
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002536 /* Clear the states */
2537 wpa_sm_notify_disassoc(wpa_s->wpa);
2538 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2539
2540 wpa_s->reassociate = 1;
2541 wpa_supplicant_req_scan(wpa_s, 1, 0);
2542 } else {
2543 /* If we ASSOC_REJECT's hits threshold, disable the
2544 * network
2545 */
2546 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2547 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002548 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002549 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002550 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002551 }
2552 }
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002553#endif
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002554#endif /* ANDROID_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555 break;
2556 case EVENT_AUTH_TIMED_OUT:
2557 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2558 sme_event_auth_timed_out(wpa_s, data);
2559 break;
2560 case EVENT_ASSOC_TIMED_OUT:
2561 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2562 sme_event_assoc_timed_out(wpa_s, data);
2563 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564 case EVENT_TX_STATUS:
2565 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2566 " type=%d stype=%d",
2567 MAC2STR(data->tx_status.dst),
2568 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002569#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002571#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002572 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2573 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002574 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002575 wpa_s, data->tx_status.dst,
2576 data->tx_status.data,
2577 data->tx_status.data_len,
2578 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002579 OFFCHANNEL_SEND_ACTION_SUCCESS :
2580 OFFCHANNEL_SEND_ACTION_NO_ACK);
2581#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002582 break;
2583 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002584#endif /* CONFIG_AP */
2585#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2587 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2588 /*
2589 * Catch TX status events for Action frames we sent via group
2590 * interface in GO mode.
2591 */
2592 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2593 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2594 os_memcmp(wpa_s->parent->pending_action_dst,
2595 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002596 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002597 wpa_s->parent, data->tx_status.dst,
2598 data->tx_status.data,
2599 data->tx_status.data_len,
2600 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002601 OFFCHANNEL_SEND_ACTION_SUCCESS :
2602 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603 break;
2604 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002605#endif /* CONFIG_OFFCHANNEL */
2606#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607 switch (data->tx_status.type) {
2608 case WLAN_FC_TYPE_MGMT:
2609 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2610 data->tx_status.data_len,
2611 data->tx_status.stype,
2612 data->tx_status.ack);
2613 break;
2614 case WLAN_FC_TYPE_DATA:
2615 ap_tx_status(wpa_s, data->tx_status.dst,
2616 data->tx_status.data,
2617 data->tx_status.data_len,
2618 data->tx_status.ack);
2619 break;
2620 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002621#endif /* CONFIG_AP */
2622 break;
2623#ifdef CONFIG_AP
2624 case EVENT_EAPOL_TX_STATUS:
2625 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2626 data->eapol_tx_status.data,
2627 data->eapol_tx_status.data_len,
2628 data->eapol_tx_status.ack);
2629 break;
2630 case EVENT_DRIVER_CLIENT_POLL_OK:
2631 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002632 break;
2633 case EVENT_RX_FROM_UNKNOWN:
2634 if (wpa_s->ap_iface == NULL)
2635 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002636 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2637 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002639 case EVENT_CH_SWITCH:
2640 if (!data)
2641 break;
2642 if (!wpa_s->ap_iface) {
2643 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2644 "event in non-AP mode");
2645 break;
2646 }
2647
2648#ifdef CONFIG_AP
2649 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2650 data->ch_switch.ht_enabled,
2651 data->ch_switch.ch_offset);
2652#endif /* CONFIG_AP */
2653 break;
2654 case EVENT_RX_MGMT: {
2655 u16 fc, stype;
2656 const struct ieee80211_mgmt *mgmt;
2657
2658 mgmt = (const struct ieee80211_mgmt *)
2659 data->rx_mgmt.frame;
2660 fc = le_to_host16(mgmt->frame_control);
2661 stype = WLAN_FC_GET_STYPE(fc);
2662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002663 if (wpa_s->ap_iface == NULL) {
2664#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2666 data->rx_mgmt.frame_len > 24) {
2667 const u8 *src = mgmt->sa;
2668 const u8 *ie = mgmt->u.probe_req.variable;
2669 size_t ie_len = data->rx_mgmt.frame_len -
2670 (mgmt->u.probe_req.variable -
2671 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002672 wpas_p2p_probe_req_rx(
2673 wpa_s, src, mgmt->da,
2674 mgmt->bssid, ie, ie_len,
2675 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002676 break;
2677 }
2678#endif /* CONFIG_P2P */
2679 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2680 "management frame in non-AP mode");
2681 break;
2682 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002683
2684 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2685 data->rx_mgmt.frame_len > 24) {
2686 const u8 *ie = mgmt->u.probe_req.variable;
2687 size_t ie_len = data->rx_mgmt.frame_len -
2688 (mgmt->u.probe_req.variable -
2689 data->rx_mgmt.frame);
2690
2691 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2692 mgmt->bssid, ie, ie_len,
2693 data->rx_mgmt.ssi_signal);
2694 }
2695
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2697 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002698 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699#endif /* CONFIG_AP */
2700 case EVENT_RX_ACTION:
2701 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2702 " Category=%u DataLen=%d freq=%d MHz",
2703 MAC2STR(data->rx_action.sa),
2704 data->rx_action.category, (int) data->rx_action.len,
2705 data->rx_action.freq);
2706#ifdef CONFIG_IEEE80211R
2707 if (data->rx_action.category == WLAN_ACTION_FT) {
2708 ft_rx_action(wpa_s, data->rx_action.data,
2709 data->rx_action.len);
2710 break;
2711 }
2712#endif /* CONFIG_IEEE80211R */
2713#ifdef CONFIG_IEEE80211W
2714#ifdef CONFIG_SME
2715 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2716 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2717 data->rx_action.data,
2718 data->rx_action.len);
2719 break;
2720 }
2721#endif /* CONFIG_SME */
2722#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002723#ifdef CONFIG_IEEE80211V
2724 if (data->rx_action.category == WLAN_ACTION_WNM) {
2725 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2726 break;
2727 }
2728#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002729#ifdef CONFIG_GAS
2730 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2731 gas_query_rx(wpa_s->gas, data->rx_action.da,
2732 data->rx_action.sa, data->rx_action.bssid,
2733 data->rx_action.data, data->rx_action.len,
2734 data->rx_action.freq) == 0)
2735 break;
2736#endif /* CONFIG_GAS */
2737 if (data->rx_action.category == WLAN_ACTION_WNM) {
2738 wnm_action_rx(wpa_s, &data->rx_action);
2739 break;
2740 }
2741#ifdef CONFIG_TDLS
2742 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2743 data->rx_action.len >= 4 &&
2744 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2745 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2746 "Response from " MACSTR,
2747 MAC2STR(data->rx_action.sa));
2748 break;
2749 }
2750#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751#ifdef CONFIG_P2P
2752 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2753 data->rx_action.sa,
2754 data->rx_action.bssid,
2755 data->rx_action.category,
2756 data->rx_action.data,
2757 data->rx_action.len, data->rx_action.freq);
2758#endif /* CONFIG_P2P */
2759 break;
2760 case EVENT_RX_PROBE_REQ:
2761 if (data->rx_probe_req.sa == NULL ||
2762 data->rx_probe_req.ie == NULL)
2763 break;
2764#ifdef CONFIG_AP
2765 if (wpa_s->ap_iface) {
2766 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2767 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002768 data->rx_probe_req.da,
2769 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002770 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002771 data->rx_probe_req.ie_len,
2772 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773 break;
2774 }
2775#endif /* CONFIG_AP */
2776#ifdef CONFIG_P2P
2777 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002778 data->rx_probe_req.da,
2779 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002780 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002781 data->rx_probe_req.ie_len,
2782 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783#endif /* CONFIG_P2P */
2784 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002785 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002786#ifdef CONFIG_OFFCHANNEL
2787 offchannel_remain_on_channel_cb(
2788 wpa_s, data->remain_on_channel.freq,
2789 data->remain_on_channel.duration);
2790#endif /* CONFIG_OFFCHANNEL */
2791#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002792 wpas_p2p_remain_on_channel_cb(
2793 wpa_s, data->remain_on_channel.freq,
2794 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002795#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002796 break;
2797 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002798#ifdef CONFIG_OFFCHANNEL
2799 offchannel_cancel_remain_on_channel_cb(
2800 wpa_s, data->remain_on_channel.freq);
2801#endif /* CONFIG_OFFCHANNEL */
2802#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803 wpas_p2p_cancel_remain_on_channel_cb(
2804 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002805#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002807#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002808 case EVENT_P2P_DEV_FOUND: {
2809 struct p2p_peer_info peer_info;
2810
2811 os_memset(&peer_info, 0, sizeof(peer_info));
2812 if (data->p2p_dev_found.dev_addr)
2813 os_memcpy(peer_info.p2p_device_addr,
2814 data->p2p_dev_found.dev_addr, ETH_ALEN);
2815 if (data->p2p_dev_found.pri_dev_type)
2816 os_memcpy(peer_info.pri_dev_type,
2817 data->p2p_dev_found.pri_dev_type,
2818 sizeof(peer_info.pri_dev_type));
2819 if (data->p2p_dev_found.dev_name)
2820 os_strlcpy(peer_info.device_name,
2821 data->p2p_dev_found.dev_name,
2822 sizeof(peer_info.device_name));
2823 peer_info.config_methods = data->p2p_dev_found.config_methods;
2824 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2825 peer_info.group_capab = data->p2p_dev_found.group_capab;
2826
2827 /*
2828 * FIX: new_device=1 is not necessarily correct. We should
2829 * maintain a P2P peer database in wpa_supplicant and update
2830 * this information based on whether the peer is truly new.
2831 */
2832 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2833 break;
2834 }
2835 case EVENT_P2P_GO_NEG_REQ_RX:
2836 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2837 data->p2p_go_neg_req_rx.dev_passwd_id);
2838 break;
2839 case EVENT_P2P_GO_NEG_COMPLETED:
2840 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2841 break;
2842 case EVENT_P2P_PROV_DISC_REQUEST:
2843 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2844 data->p2p_prov_disc_req.config_methods,
2845 data->p2p_prov_disc_req.dev_addr,
2846 data->p2p_prov_disc_req.pri_dev_type,
2847 data->p2p_prov_disc_req.dev_name,
2848 data->p2p_prov_disc_req.supp_config_methods,
2849 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002850 data->p2p_prov_disc_req.group_capab,
2851 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852 break;
2853 case EVENT_P2P_PROV_DISC_RESPONSE:
2854 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2855 data->p2p_prov_disc_resp.config_methods);
2856 break;
2857 case EVENT_P2P_SD_REQUEST:
2858 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2859 data->p2p_sd_req.sa,
2860 data->p2p_sd_req.dialog_token,
2861 data->p2p_sd_req.update_indic,
2862 data->p2p_sd_req.tlvs,
2863 data->p2p_sd_req.tlvs_len);
2864 break;
2865 case EVENT_P2P_SD_RESPONSE:
2866 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2867 data->p2p_sd_resp.update_indic,
2868 data->p2p_sd_resp.tlvs,
2869 data->p2p_sd_resp.tlvs_len);
2870 break;
2871#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 case EVENT_EAPOL_RX:
2873 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2874 data->eapol_rx.data,
2875 data->eapol_rx.data_len);
2876 break;
2877 case EVENT_SIGNAL_CHANGE:
2878 bgscan_notify_signal_change(
2879 wpa_s, data->signal_change.above_threshold,
2880 data->signal_change.current_signal,
2881 data->signal_change.current_noise,
2882 data->signal_change.current_txrate);
2883 break;
2884 case EVENT_INTERFACE_ENABLED:
2885 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2886 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002887 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002888#ifdef CONFIG_AP
2889 if (!wpa_s->ap_iface) {
2890 wpa_supplicant_set_state(wpa_s,
2891 WPA_DISCONNECTED);
2892 wpa_supplicant_req_scan(wpa_s, 0, 0);
2893 } else
2894 wpa_supplicant_set_state(wpa_s,
2895 WPA_COMPLETED);
2896#else /* CONFIG_AP */
2897 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2898 wpa_supplicant_req_scan(wpa_s, 0, 0);
2899#endif /* CONFIG_AP */
2900 }
2901 break;
2902 case EVENT_INTERFACE_DISABLED:
2903 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2904 wpa_supplicant_mark_disassoc(wpa_s);
2905 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2906 break;
2907 case EVENT_CHANNEL_LIST_CHANGED:
2908 if (wpa_s->drv_priv == NULL)
2909 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002910
2911 free_hw_features(wpa_s);
2912 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2913 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915#ifdef CONFIG_P2P
2916 wpas_p2p_update_channel_list(wpa_s);
2917#endif /* CONFIG_P2P */
2918 break;
2919 case EVENT_INTERFACE_UNAVAILABLE:
2920#ifdef CONFIG_P2P
2921 wpas_p2p_interface_unavailable(wpa_s);
2922#endif /* CONFIG_P2P */
2923 break;
2924 case EVENT_BEST_CHANNEL:
2925 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2926 "(%d %d %d)",
2927 data->best_chan.freq_24, data->best_chan.freq_5,
2928 data->best_chan.freq_overall);
2929 wpa_s->best_24_freq = data->best_chan.freq_24;
2930 wpa_s->best_5_freq = data->best_chan.freq_5;
2931 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2932#ifdef CONFIG_P2P
2933 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2934 data->best_chan.freq_5,
2935 data->best_chan.freq_overall);
2936#endif /* CONFIG_P2P */
2937 break;
2938 case EVENT_UNPROT_DEAUTH:
2939 wpa_supplicant_event_unprot_deauth(wpa_s,
2940 &data->unprot_deauth);
2941 break;
2942 case EVENT_UNPROT_DISASSOC:
2943 wpa_supplicant_event_unprot_disassoc(wpa_s,
2944 &data->unprot_disassoc);
2945 break;
2946 case EVENT_STATION_LOW_ACK:
2947#ifdef CONFIG_AP
2948 if (wpa_s->ap_iface && data)
2949 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2950 data->low_ack.addr);
2951#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002952#ifdef CONFIG_TDLS
2953 if (data)
2954 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2955#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002956 break;
2957 case EVENT_IBSS_PEER_LOST:
2958#ifdef CONFIG_IBSS_RSN
2959 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2960#endif /* CONFIG_IBSS_RSN */
2961 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002962 case EVENT_DRIVER_GTK_REKEY:
2963 if (os_memcmp(data->driver_gtk_rekey.bssid,
2964 wpa_s->bssid, ETH_ALEN))
2965 break;
2966 if (!wpa_s->wpa)
2967 break;
2968 wpa_sm_update_replay_ctr(wpa_s->wpa,
2969 data->driver_gtk_rekey.replay_ctr);
2970 break;
2971 case EVENT_SCHED_SCAN_STOPPED:
2972 wpa_s->sched_scanning = 0;
2973 wpa_supplicant_notify_scanning(wpa_s, 0);
2974
2975 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2976 break;
2977
2978 /*
2979 * If we timed out, start a new sched scan to continue
2980 * searching for more SSIDs.
2981 */
2982 if (wpa_s->sched_scan_timed_out)
2983 wpa_supplicant_req_sched_scan(wpa_s);
2984 break;
2985 case EVENT_WPS_BUTTON_PUSHED:
2986#ifdef CONFIG_WPS
2987 wpas_wps_start_pbc(wpa_s, NULL, 0);
2988#endif /* CONFIG_WPS */
2989 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002990 default:
2991 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
2992 break;
2993 }
2994}