blob: 093ab0d40844c10f37724eaee687b0c2e0ae87ef [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");
1067 return -1;
1068 }
1069 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001070 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001071#endif /* CONFIG_P2P */
1072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1074 data ? &data->scan_info :
1075 NULL, 1);
1076 if (scan_res == NULL) {
1077 if (wpa_s->conf->ap_scan == 2 || ap)
1078 return -1;
1079 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1080 "scanning again");
1081 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1082 return -1;
1083 }
1084
1085#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086 num = scan_res->num;
1087 if (num > 10)
1088 num = 10;
1089 for (i = 0; i < num; i++) {
1090 u8 buf[5];
1091 struct wpa_scan_res *res = scan_res->res[i];
1092 buf[0] = res->bssid[5];
1093 buf[1] = res->qual & 0xff;
1094 buf[2] = res->noise & 0xff;
1095 buf[3] = res->level & 0xff;
1096 buf[4] = res->tsf & 0xff;
1097 random_add_randomness(buf, sizeof(buf));
1098 }
1099#endif /* CONFIG_NO_RANDOM_POOL */
1100
1101 if (wpa_s->scan_res_handler) {
1102 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1103 struct wpa_scan_results *scan_res);
1104
1105 scan_res_handler = wpa_s->scan_res_handler;
1106 wpa_s->scan_res_handler = NULL;
1107 scan_res_handler(wpa_s, scan_res);
1108
1109 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001110 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 }
1112
1113 if (ap) {
1114 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1115#ifdef CONFIG_AP
1116 if (wpa_s->ap_iface->scan_cb)
1117 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1118#endif /* CONFIG_AP */
1119 wpa_scan_results_free(scan_res);
1120 return 0;
1121 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001122#ifdef ANDROID_P2P
1123 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001124 {
1125 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1126 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1127 wpas_notify_scan_results(wpa_s);
1128 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001129#else
1130 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1131 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1132 wpas_notify_scan_results(wpa_s);
1133#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134
1135 wpas_notify_scan_done(wpa_s, 1);
1136
Dmitry Shmidt04949592012-07-19 12:16:46 -07001137 if (sme_proc_obss_scan(wpa_s) > 0) {
1138 wpa_scan_results_free(scan_res);
1139 return 0;
1140 }
1141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1143 wpa_scan_results_free(scan_res);
1144 return 0;
1145 }
1146
Dmitry Shmidt04949592012-07-19 12:16:46 -07001147 if (autoscan_notify_scan(wpa_s, scan_res)) {
1148 wpa_scan_results_free(scan_res);
1149 return 0;
1150 }
1151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 if (wpa_s->disconnected) {
1153 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1154 wpa_scan_results_free(scan_res);
1155 return 0;
1156 }
1157
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001158 if (!wpas_driver_bss_selection(wpa_s) &&
1159 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 wpa_scan_results_free(scan_res);
1161 return 0;
1162 }
1163
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001164 wpas_wps_update_ap_info(wpa_s, scan_res);
1165
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001166 wpa_scan_results_free(scan_res);
1167
1168 return wpas_select_network_from_last_scan(wpa_s);
1169}
1170
1171
1172int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1173{
1174 struct wpa_bss *selected;
1175 struct wpa_ssid *ssid = NULL;
1176
1177 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178
1179 if (selected) {
1180 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001181 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001182 if (skip) {
1183 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001185 }
1186
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001187 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001188 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001189 return -1;
1190 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001191 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1194 ssid = wpa_supplicant_pick_new_network(wpa_s);
1195 if (ssid) {
1196 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1197 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001198 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 } else {
1200 int timeout_sec = wpa_s->scan_interval;
1201 int timeout_usec = 0;
1202#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001203 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1204 return 0;
1205
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 if (wpa_s->p2p_in_provisioning) {
1207 /*
1208 * Use shorter wait during P2P Provisioning
1209 * state to speed up group formation.
1210 */
1211 timeout_sec = 0;
1212 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1214 timeout_usec);
1215 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 }
1217#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001218#ifdef CONFIG_INTERWORKING
1219 if (wpa_s->conf->auto_interworking &&
1220 wpa_s->conf->interworking &&
1221 wpa_s->conf->cred) {
1222 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1223 "start ANQP fetch since no matching "
1224 "networks found");
1225 wpa_s->network_select = 1;
1226 wpa_s->auto_network_select = 1;
1227 interworking_start_fetch_anqp(wpa_s);
1228 return 0;
1229 }
1230#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001231 if (wpa_supplicant_req_sched_scan(wpa_s))
1232 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1233 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 }
1235 }
1236 return 0;
1237}
1238
1239
1240static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1241 union wpa_event_data *data)
1242{
1243 const char *rn, *rn2;
1244 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001245#ifdef ANDROID_P2P
1246 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1247#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001248 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001249#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 /*
1251 * If no scan results could be fetched, then no need to
1252 * notify those interfaces that did not actually request
1253 * this scan.
1254 */
1255 return;
1256 }
1257
1258 /*
1259 * Check other interfaces to see if they have the same radio-name. If
1260 * so, they get updated with this same scan info.
1261 */
1262 if (!wpa_s->driver->get_radio_name)
1263 return;
1264
1265 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1266 if (rn == NULL || rn[0] == '\0')
1267 return;
1268
1269 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1270 "sharing same radio (%s) in event_scan_results", rn);
1271
1272 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1273 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1274 continue;
1275
1276 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1277 if (rn2 && os_strcmp(rn, rn2) == 0) {
1278 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1279 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001280#ifdef ANDROID_P2P
1281 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1282 /* Do not update the scan results from STA interface to p2p interfaces */
1283 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1284 "sibling %s", ifs->ifname, wpa_s->ifname);
1285 continue;
1286 }
1287 else {
1288 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1289 * no time. Avoid announcing it to application as it may not
1290 * be that useful (since results will be that of only 1,6,11).
1291 * over to any other interface as it
1292 */
1293 if(p2p_search_in_progress(wpa_s->global->p2p))
1294 _wpa_supplicant_event_scan_results(ifs, data, 1);
1295 else
1296 _wpa_supplicant_event_scan_results(ifs, data, 0);
1297 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001298#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001299 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001300#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001301 }
1302 }
1303}
1304
1305#endif /* CONFIG_NO_SCAN_PROCESSING */
1306
1307
Dmitry Shmidt04949592012-07-19 12:16:46 -07001308#ifdef CONFIG_WNM
1309
1310static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1311{
1312 struct wpa_supplicant *wpa_s = eloop_ctx;
1313
1314 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1315 return;
1316
1317 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1318 MAC2STR(wpa_s->bssid));
1319 /* TODO: could skip this if normal data traffic has been sent */
1320 /* TODO: Consider using some more appropriate data frame for this */
1321 if (wpa_s->l2)
1322 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1323
1324#ifdef CONFIG_SME
1325 if (wpa_s->sme.bss_max_idle_period) {
1326 unsigned int msec;
1327 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1328 if (msec > 100)
1329 msec -= 100;
1330 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1331 wnm_bss_keep_alive, wpa_s, NULL);
1332 }
1333#endif /* CONFIG_SME */
1334}
1335
1336
1337static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1338 const u8 *ies, size_t ies_len)
1339{
1340 struct ieee802_11_elems elems;
1341
1342 if (ies == NULL)
1343 return;
1344
1345 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1346 return;
1347
1348#ifdef CONFIG_SME
1349 if (elems.bss_max_idle_period) {
1350 unsigned int msec;
1351 wpa_s->sme.bss_max_idle_period =
1352 WPA_GET_LE16(elems.bss_max_idle_period);
1353 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1354 "TU)%s", wpa_s->sme.bss_max_idle_period,
1355 (elems.bss_max_idle_period[2] & 0x01) ?
1356 " (protected keep-live required)" : "");
1357 if (wpa_s->sme.bss_max_idle_period == 0)
1358 wpa_s->sme.bss_max_idle_period = 1;
1359 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1360 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1361 /* msec times 1000 */
1362 msec = wpa_s->sme.bss_max_idle_period * 1024;
1363 if (msec > 100)
1364 msec -= 100;
1365 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1366 wnm_bss_keep_alive, wpa_s,
1367 NULL);
1368 }
1369 }
1370#endif /* CONFIG_SME */
1371}
1372
1373#endif /* CONFIG_WNM */
1374
1375
1376void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1377{
1378#ifdef CONFIG_WNM
1379 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1380#endif /* CONFIG_WNM */
1381}
1382
1383
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1385 union wpa_event_data *data)
1386{
1387 int l, len, found = 0, wpa_found, rsn_found;
1388 const u8 *p;
1389
1390 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1391 if (data->assoc_info.req_ies)
1392 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1393 data->assoc_info.req_ies_len);
1394 if (data->assoc_info.resp_ies) {
1395 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1396 data->assoc_info.resp_ies_len);
1397#ifdef CONFIG_TDLS
1398 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1399 data->assoc_info.resp_ies_len);
1400#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001401#ifdef CONFIG_WNM
1402 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1403 data->assoc_info.resp_ies_len);
1404#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 }
1406 if (data->assoc_info.beacon_ies)
1407 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1408 data->assoc_info.beacon_ies,
1409 data->assoc_info.beacon_ies_len);
1410 if (data->assoc_info.freq)
1411 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1412 data->assoc_info.freq);
1413
1414 p = data->assoc_info.req_ies;
1415 l = data->assoc_info.req_ies_len;
1416
1417 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1418 while (p && l >= 2) {
1419 len = p[1] + 2;
1420 if (len > l) {
1421 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1422 p, l);
1423 break;
1424 }
1425 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1426 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1427 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1428 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1429 break;
1430 found = 1;
1431 wpa_find_assoc_pmkid(wpa_s);
1432 break;
1433 }
1434 l -= len;
1435 p += len;
1436 }
1437 if (!found && data->assoc_info.req_ies)
1438 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1439
1440#ifdef CONFIG_IEEE80211R
1441#ifdef CONFIG_SME
1442 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1443 u8 bssid[ETH_ALEN];
1444 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1445 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1446 data->assoc_info.resp_ies,
1447 data->assoc_info.resp_ies_len,
1448 bssid) < 0) {
1449 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1450 "Reassociation Response failed");
1451 wpa_supplicant_deauthenticate(
1452 wpa_s, WLAN_REASON_INVALID_IE);
1453 return -1;
1454 }
1455 }
1456
1457 p = data->assoc_info.resp_ies;
1458 l = data->assoc_info.resp_ies_len;
1459
1460#ifdef CONFIG_WPS_STRICT
1461 if (p && wpa_s->current_ssid &&
1462 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1463 struct wpabuf *wps;
1464 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1465 if (wps == NULL) {
1466 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1467 "include WPS IE in (Re)Association Response");
1468 return -1;
1469 }
1470
1471 if (wps_validate_assoc_resp(wps) < 0) {
1472 wpabuf_free(wps);
1473 wpa_supplicant_deauthenticate(
1474 wpa_s, WLAN_REASON_INVALID_IE);
1475 return -1;
1476 }
1477 wpabuf_free(wps);
1478 }
1479#endif /* CONFIG_WPS_STRICT */
1480
1481 /* Go through the IEs and make a copy of the MDIE, if present. */
1482 while (p && l >= 2) {
1483 len = p[1] + 2;
1484 if (len > l) {
1485 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1486 p, l);
1487 break;
1488 }
1489 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1490 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1491 wpa_s->sme.ft_used = 1;
1492 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1493 MOBILITY_DOMAIN_ID_LEN);
1494 break;
1495 }
1496 l -= len;
1497 p += len;
1498 }
1499#endif /* CONFIG_SME */
1500
1501 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1502 data->assoc_info.resp_ies_len);
1503#endif /* CONFIG_IEEE80211R */
1504
1505 /* WPA/RSN IE from Beacon/ProbeResp */
1506 p = data->assoc_info.beacon_ies;
1507 l = data->assoc_info.beacon_ies_len;
1508
1509 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1510 */
1511 wpa_found = rsn_found = 0;
1512 while (p && l >= 2) {
1513 len = p[1] + 2;
1514 if (len > l) {
1515 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1516 p, l);
1517 break;
1518 }
1519 if (!wpa_found &&
1520 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1521 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1522 wpa_found = 1;
1523 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1524 }
1525
1526 if (!rsn_found &&
1527 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1528 rsn_found = 1;
1529 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1530 }
1531
1532 l -= len;
1533 p += len;
1534 }
1535
1536 if (!wpa_found && data->assoc_info.beacon_ies)
1537 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1538 if (!rsn_found && data->assoc_info.beacon_ies)
1539 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1540 if (wpa_found || rsn_found)
1541 wpa_s->ap_ies_from_associnfo = 1;
1542
Jouni Malinen87fd2792011-05-16 18:35:42 +03001543 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1544 wpa_s->assoc_freq != data->assoc_info.freq) {
1545 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1546 "%u to %u MHz",
1547 wpa_s->assoc_freq, data->assoc_info.freq);
1548 wpa_supplicant_update_scan_results(wpa_s);
1549 }
1550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551 wpa_s->assoc_freq = data->assoc_info.freq;
1552
1553 return 0;
1554}
1555
1556
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001557static struct wpa_bss * wpa_supplicant_get_new_bss(
1558 struct wpa_supplicant *wpa_s, const u8 *bssid)
1559{
1560 struct wpa_bss *bss = NULL;
1561 struct wpa_ssid *ssid = wpa_s->current_ssid;
1562
1563 if (ssid->ssid_len > 0)
1564 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1565 if (!bss)
1566 bss = wpa_bss_get_bssid(wpa_s, bssid);
1567
1568 return bss;
1569}
1570
1571
1572static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1573{
1574 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1575
1576 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1577 return -1;
1578
1579 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1580 return 0;
1581
1582 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1583 WPA_IE_VENDOR_TYPE);
1584 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1585
1586 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1587 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1588 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1589 bss_rsn ? 2 + bss_rsn[1] : 0))
1590 return -1;
1591
1592 return 0;
1593}
1594
1595
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1597 union wpa_event_data *data)
1598{
1599 u8 bssid[ETH_ALEN];
1600 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 struct wpa_driver_capa capa;
1602
1603#ifdef CONFIG_AP
1604 if (wpa_s->ap_iface) {
1605 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1606 data->assoc_info.addr,
1607 data->assoc_info.req_ies,
1608 data->assoc_info.req_ies_len,
1609 data->assoc_info.reassoc);
1610 return;
1611 }
1612#endif /* CONFIG_AP */
1613
1614 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1615 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1616 return;
1617
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001618 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1619 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1620 wpa_supplicant_disassociate(
1621 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1622 return;
1623 }
1624
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001626 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001627 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1628 MACSTR, MAC2STR(bssid));
1629 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1631 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001632 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633
1634 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1635 wpa_clear_keys(wpa_s, bssid);
1636 }
1637 if (wpa_supplicant_select_config(wpa_s) < 0) {
1638 wpa_supplicant_disassociate(
1639 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1640 return;
1641 }
1642 if (wpa_s->current_ssid) {
1643 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001644
1645 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1646 if (!bss) {
1647 wpa_supplicant_update_scan_results(wpa_s);
1648
1649 /* Get the BSS from the new scan results */
1650 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1651 }
1652
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001653 if (bss)
1654 wpa_s->current_bss = bss;
1655 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001656
1657 if (wpa_s->conf->ap_scan == 1 &&
1658 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1659 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1660 wpa_msg(wpa_s, MSG_WARNING,
1661 "WPA/RSN IEs not updated");
1662 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 }
1664
1665#ifdef CONFIG_SME
1666 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1667 wpa_s->sme.prev_bssid_set = 1;
1668#endif /* CONFIG_SME */
1669
1670 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1671 if (wpa_s->current_ssid) {
1672 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1673 * initialized before association, but for other modes,
1674 * initialize PC/SC here, if the current configuration needs
1675 * smartcard or SIM/USIM. */
1676 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1677 }
1678 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1679 if (wpa_s->l2)
1680 l2_packet_notify_auth_start(wpa_s->l2);
1681
1682 /*
1683 * Set portEnabled first to FALSE in order to get EAP state machine out
1684 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1685 * state machine may transit to AUTHENTICATING state based on obsolete
1686 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1687 * AUTHENTICATED without ever giving chance to EAP state machine to
1688 * reset the state.
1689 */
1690 if (!ft_completed) {
1691 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1692 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1693 }
1694 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1695 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1696 /* 802.1X::portControl = Auto */
1697 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1698 wpa_s->eapol_received = 0;
1699 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1700 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1701 (wpa_s->current_ssid &&
1702 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1703 wpa_supplicant_cancel_auth_timeout(wpa_s);
1704 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1705 } else if (!ft_completed) {
1706 /* Timeout for receiving the first EAPOL packet */
1707 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1708 }
1709 wpa_supplicant_cancel_scan(wpa_s);
1710
1711 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1712 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1713 /*
1714 * We are done; the driver will take care of RSN 4-way
1715 * handshake.
1716 */
1717 wpa_supplicant_cancel_auth_timeout(wpa_s);
1718 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1719 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1720 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1721 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1722 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1723 /*
1724 * The driver will take care of RSN 4-way handshake, so we need
1725 * to allow EAPOL supplicant to complete its work without
1726 * waiting for WPA supplicant.
1727 */
1728 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1729 } else if (ft_completed) {
1730 /*
1731 * FT protocol completed - make sure EAPOL state machine ends
1732 * up in authenticated.
1733 */
1734 wpa_supplicant_cancel_auth_timeout(wpa_s);
1735 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1736 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1737 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1738 }
1739
1740 if (wpa_s->pending_eapol_rx) {
1741 struct os_time now, age;
1742 os_get_time(&now);
1743 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1744 if (age.sec == 0 && age.usec < 100000 &&
1745 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1746 0) {
1747 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1748 "frame that was received just before "
1749 "association notification");
1750 wpa_supplicant_rx_eapol(
1751 wpa_s, wpa_s->pending_eapol_rx_src,
1752 wpabuf_head(wpa_s->pending_eapol_rx),
1753 wpabuf_len(wpa_s->pending_eapol_rx));
1754 }
1755 wpabuf_free(wpa_s->pending_eapol_rx);
1756 wpa_s->pending_eapol_rx = NULL;
1757 }
1758
1759 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1760 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1761 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1762 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1763 /* Set static WEP keys again */
1764 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1765 }
1766
1767#ifdef CONFIG_IBSS_RSN
1768 if (wpa_s->current_ssid &&
1769 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1770 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1771 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1772 wpa_s->ibss_rsn == NULL) {
1773 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1774 if (!wpa_s->ibss_rsn) {
1775 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1776 wpa_supplicant_deauthenticate(
1777 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1778 return;
1779 }
1780
1781 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1782 }
1783#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001784
1785 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786}
1787
1788
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001789static int disconnect_reason_recoverable(u16 reason_code)
1790{
1791 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1792 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1793 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1794}
1795
1796
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001798 u16 reason_code,
1799 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800{
1801 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001802
1803 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1804 /*
1805 * At least Host AP driver and a Prism3 card seemed to be
1806 * generating streams of disconnected events when configuring
1807 * IBSS for WPA-None. Ignore them for now.
1808 */
1809 return;
1810 }
1811
1812 bssid = wpa_s->bssid;
1813 if (is_zero_ether_addr(bssid))
1814 bssid = wpa_s->pending_bssid;
1815
1816 if (!is_zero_ether_addr(bssid) ||
1817 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1818 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1819 " reason=%d%s",
1820 MAC2STR(bssid), reason_code,
1821 locally_generated ? " locally_generated=1" : "");
1822 }
1823}
1824
1825
1826static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1827 u16 reason_code,
1828 int locally_generated)
1829{
1830 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831 int authenticating;
1832 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001833 struct wpa_bss *fast_reconnect = NULL;
1834 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001835 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836
1837 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1838 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1839
1840 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1841 /*
1842 * At least Host AP driver and a Prism3 card seemed to be
1843 * generating streams of disconnected events when configuring
1844 * IBSS for WPA-None. Ignore them for now.
1845 */
1846 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1847 "IBSS/WPA-None mode");
1848 return;
1849 }
1850
1851 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1852 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1853 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1854 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001855 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001856 }
1857 if (!wpa_s->auto_reconnect_disabled ||
1858 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001859 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1860 "reconnect (wps=%d wpa_state=%d)",
1861 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1862 wpa_s->wpa_state);
1863 if (wpa_s->wpa_state == WPA_COMPLETED &&
1864 wpa_s->current_ssid &&
1865 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001866 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001867 disconnect_reason_recoverable(reason_code)) {
1868 /*
1869 * It looks like the AP has dropped association with
1870 * us, but could allow us to get back in. Try to
1871 * reconnect to the same BSS without full scan to save
1872 * time for some common cases.
1873 */
1874 fast_reconnect = wpa_s->current_bss;
1875 fast_reconnect_ssid = wpa_s->current_ssid;
1876 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001877#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001878 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001879#else
1880 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1881#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001882 else
1883 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1884 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001886 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 "try to re-connect");
1888 wpa_s->reassociate = 0;
1889 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001890 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001891 }
1892 bssid = wpa_s->bssid;
1893 if (is_zero_ether_addr(bssid))
1894 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001895 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1896 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001898 if (locally_generated)
1899 wpa_s->disconnect_reason = -reason_code;
1900 else
1901 wpa_s->disconnect_reason = reason_code;
1902 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001903 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1904 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1905 wpa_s->keys_cleared = 0;
1906 wpa_clear_keys(wpa_s, wpa_s->bssid);
1907 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001908 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001909 wpa_supplicant_mark_disassoc(wpa_s);
1910
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001911 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001913 wpa_s->current_ssid = last_ssid;
1914 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001915
1916 if (fast_reconnect) {
1917#ifndef CONFIG_NO_SCAN_PROCESSING
1918 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1919 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1920 fast_reconnect_ssid) < 0) {
1921 /* Recover through full scan */
1922 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1923 }
1924#endif /* CONFIG_NO_SCAN_PROCESSING */
1925 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001926}
1927
1928
1929#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001930void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931{
1932 struct wpa_supplicant *wpa_s = eloop_ctx;
1933
1934 if (!wpa_s->pending_mic_error_report)
1935 return;
1936
1937 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1938 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1939 wpa_s->pending_mic_error_report = 0;
1940}
1941#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1942
1943
1944static void
1945wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1946 union wpa_event_data *data)
1947{
1948 int pairwise;
1949 struct os_time t;
1950
1951 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1952 pairwise = (data && data->michael_mic_failure.unicast);
1953 os_get_time(&t);
1954 if ((wpa_s->last_michael_mic_error &&
1955 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1956 wpa_s->pending_mic_error_report) {
1957 if (wpa_s->pending_mic_error_report) {
1958 /*
1959 * Send the pending MIC error report immediately since
1960 * we are going to start countermeasures and AP better
1961 * do the same.
1962 */
1963 wpa_sm_key_request(wpa_s->wpa, 1,
1964 wpa_s->pending_mic_error_pairwise);
1965 }
1966
1967 /* Send the new MIC error report immediately since we are going
1968 * to start countermeasures and AP better do the same.
1969 */
1970 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1971
1972 /* initialize countermeasures */
1973 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001974
1975 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1976
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001977 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1978
1979 /*
1980 * Need to wait for completion of request frame. We do not get
1981 * any callback for the message completion, so just wait a
1982 * short while and hope for the best. */
1983 os_sleep(0, 10000);
1984
1985 wpa_drv_set_countermeasures(wpa_s, 1);
1986 wpa_supplicant_deauthenticate(wpa_s,
1987 WLAN_REASON_MICHAEL_MIC_FAILURE);
1988 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1989 wpa_s, NULL);
1990 eloop_register_timeout(60, 0,
1991 wpa_supplicant_stop_countermeasures,
1992 wpa_s, NULL);
1993 /* TODO: mark the AP rejected for 60 second. STA is
1994 * allowed to associate with another AP.. */
1995 } else {
1996#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1997 if (wpa_s->mic_errors_seen) {
1998 /*
1999 * Reduce the effectiveness of Michael MIC error
2000 * reports as a means for attacking against TKIP if
2001 * more than one MIC failure is noticed with the same
2002 * PTK. We delay the transmission of the reports by a
2003 * random time between 0 and 60 seconds in order to
2004 * force the attacker wait 60 seconds before getting
2005 * the information on whether a frame resulted in a MIC
2006 * failure.
2007 */
2008 u8 rval[4];
2009 int sec;
2010
2011 if (os_get_random(rval, sizeof(rval)) < 0)
2012 sec = os_random() % 60;
2013 else
2014 sec = WPA_GET_BE32(rval) % 60;
2015 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2016 "report %d seconds", sec);
2017 wpa_s->pending_mic_error_report = 1;
2018 wpa_s->pending_mic_error_pairwise = pairwise;
2019 eloop_cancel_timeout(
2020 wpa_supplicant_delayed_mic_error_report,
2021 wpa_s, NULL);
2022 eloop_register_timeout(
2023 sec, os_random() % 1000000,
2024 wpa_supplicant_delayed_mic_error_report,
2025 wpa_s, NULL);
2026 } else {
2027 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2028 }
2029#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2030 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2031#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2032 }
2033 wpa_s->last_michael_mic_error = t.sec;
2034 wpa_s->mic_errors_seen++;
2035}
2036
2037
2038#ifdef CONFIG_TERMINATE_ONLASTIF
2039static int any_interfaces(struct wpa_supplicant *head)
2040{
2041 struct wpa_supplicant *wpa_s;
2042
2043 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2044 if (!wpa_s->interface_removed)
2045 return 1;
2046 return 0;
2047}
2048#endif /* CONFIG_TERMINATE_ONLASTIF */
2049
2050
2051static void
2052wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2053 union wpa_event_data *data)
2054{
2055 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2056 return;
2057
2058 switch (data->interface_status.ievent) {
2059 case EVENT_INTERFACE_ADDED:
2060 if (!wpa_s->interface_removed)
2061 break;
2062 wpa_s->interface_removed = 0;
2063 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2064 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2065 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2066 "driver after interface was added");
2067 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002068 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 break;
2070 case EVENT_INTERFACE_REMOVED:
2071 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2072 wpa_s->interface_removed = 1;
2073 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002074 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 l2_packet_deinit(wpa_s->l2);
2076 wpa_s->l2 = NULL;
2077#ifdef CONFIG_IBSS_RSN
2078 ibss_rsn_deinit(wpa_s->ibss_rsn);
2079 wpa_s->ibss_rsn = NULL;
2080#endif /* CONFIG_IBSS_RSN */
2081#ifdef CONFIG_TERMINATE_ONLASTIF
2082 /* check if last interface */
2083 if (!any_interfaces(wpa_s->global->ifaces))
2084 eloop_terminate();
2085#endif /* CONFIG_TERMINATE_ONLASTIF */
2086 break;
2087 }
2088}
2089
2090
2091#ifdef CONFIG_PEERKEY
2092static void
2093wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2094 union wpa_event_data *data)
2095{
2096 if (data == NULL)
2097 return;
2098 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2099}
2100#endif /* CONFIG_PEERKEY */
2101
2102
2103#ifdef CONFIG_TDLS
2104static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2105 union wpa_event_data *data)
2106{
2107 if (data == NULL)
2108 return;
2109 switch (data->tdls.oper) {
2110 case TDLS_REQUEST_SETUP:
2111 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2112 break;
2113 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002114 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2115 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002116 break;
2117 }
2118}
2119#endif /* CONFIG_TDLS */
2120
2121
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002122#ifdef CONFIG_IEEE80211V
2123static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2124 union wpa_event_data *data)
2125{
2126 if (data == NULL)
2127 return;
2128 switch (data->wnm.oper) {
2129 case WNM_OPER_SLEEP:
2130 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2131 "(action=%d, intval=%d)",
2132 data->wnm.sleep_action, data->wnm.sleep_intval);
2133 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2134 data->wnm.sleep_intval);
2135 break;
2136 }
2137}
2138#endif /* CONFIG_IEEE80211V */
2139
2140
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141#ifdef CONFIG_IEEE80211R
2142static void
2143wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2144 union wpa_event_data *data)
2145{
2146 if (data == NULL)
2147 return;
2148
2149 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2150 data->ft_ies.ies_len,
2151 data->ft_ies.ft_action,
2152 data->ft_ies.target_ap,
2153 data->ft_ies.ric_ies,
2154 data->ft_ies.ric_ies_len) < 0) {
2155 /* TODO: prevent MLME/driver from trying to associate? */
2156 }
2157}
2158#endif /* CONFIG_IEEE80211R */
2159
2160
2161#ifdef CONFIG_IBSS_RSN
2162static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2163 union wpa_event_data *data)
2164{
2165 struct wpa_ssid *ssid;
2166 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2167 return;
2168 if (data == NULL)
2169 return;
2170 ssid = wpa_s->current_ssid;
2171 if (ssid == NULL)
2172 return;
2173 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2174 return;
2175
2176 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2177}
2178#endif /* CONFIG_IBSS_RSN */
2179
2180
2181#ifdef CONFIG_IEEE80211R
2182static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2183 size_t len)
2184{
2185 const u8 *sta_addr, *target_ap_addr;
2186 u16 status;
2187
2188 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2189 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2190 return; /* only SME case supported for now */
2191 if (len < 1 + 2 * ETH_ALEN + 2)
2192 return;
2193 if (data[0] != 2)
2194 return; /* Only FT Action Response is supported for now */
2195 sta_addr = data + 1;
2196 target_ap_addr = data + 1 + ETH_ALEN;
2197 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2198 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2199 MACSTR " TargetAP " MACSTR " status %u",
2200 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2201
2202 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2203 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2204 " in FT Action Response", MAC2STR(sta_addr));
2205 return;
2206 }
2207
2208 if (status) {
2209 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2210 "failure (status code %d)", status);
2211 /* TODO: report error to FT code(?) */
2212 return;
2213 }
2214
2215 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2216 len - (1 + 2 * ETH_ALEN + 2), 1,
2217 target_ap_addr, NULL, 0) < 0)
2218 return;
2219
2220#ifdef CONFIG_SME
2221 {
2222 struct wpa_bss *bss;
2223 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2224 if (bss)
2225 wpa_s->sme.freq = bss->freq;
2226 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2227 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2228 WLAN_AUTH_FT);
2229 }
2230#endif /* CONFIG_SME */
2231}
2232#endif /* CONFIG_IEEE80211R */
2233
2234
2235static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2236 struct unprot_deauth *e)
2237{
2238#ifdef CONFIG_IEEE80211W
2239 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2240 "dropped: " MACSTR " -> " MACSTR
2241 " (reason code %u)",
2242 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2243 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2244#endif /* CONFIG_IEEE80211W */
2245}
2246
2247
2248static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2249 struct unprot_disassoc *e)
2250{
2251#ifdef CONFIG_IEEE80211W
2252 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2253 "dropped: " MACSTR " -> " MACSTR
2254 " (reason code %u)",
2255 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2256 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2257#endif /* CONFIG_IEEE80211W */
2258}
2259
2260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002261static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2262{
2263 u8 action, mode;
2264 const u8 *pos, *end;
2265
2266 if (rx->data == NULL || rx->len == 0)
2267 return;
2268
2269 pos = rx->data;
2270 end = pos + rx->len;
2271 action = *pos++;
2272
2273 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2274 action, MAC2STR(rx->sa));
2275 switch (action) {
2276 case WNM_BSS_TRANS_MGMT_REQ:
2277 if (pos + 5 > end)
2278 break;
2279 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2280 "Request: dialog_token=%u request_mode=0x%x "
2281 "disassoc_timer=%u validity_interval=%u",
2282 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2283 mode = pos[1];
2284 pos += 5;
2285 if (mode & 0x08)
2286 pos += 12; /* BSS Termination Duration */
2287 if (mode & 0x10) {
2288 char url[256];
2289 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2290 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2291 "Transition Management Request "
2292 "(URL)");
2293 break;
2294 }
2295 os_memcpy(url, pos + 1, pos[0]);
2296 url[pos[0]] = '\0';
2297 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2298 "Imminent - session_info_url=%s", url);
2299 }
2300 break;
2301 }
2302}
2303
2304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002305void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2306 union wpa_event_data *data)
2307{
2308 struct wpa_supplicant *wpa_s = ctx;
2309 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002310 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311
2312 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2313 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002314 event != EVENT_INTERFACE_STATUS &&
2315 event != EVENT_SCHED_SCAN_STOPPED) {
2316 wpa_dbg(wpa_s, MSG_DEBUG,
2317 "Ignore event %s (%d) while interface is disabled",
2318 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319 return;
2320 }
2321
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002322#ifndef CONFIG_NO_STDOUT_DEBUG
2323{
2324 int level = MSG_DEBUG;
2325
Dmitry Shmidt04949592012-07-19 12:16:46 -07002326 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002327 const struct ieee80211_hdr *hdr;
2328 u16 fc;
2329 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2330 fc = le_to_host16(hdr->frame_control);
2331 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2332 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2333 level = MSG_EXCESSIVE;
2334 }
2335
2336 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2337 event_to_string(event), event);
2338}
2339#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002340
2341 switch (event) {
2342 case EVENT_AUTH:
2343 sme_event_auth(wpa_s, data);
2344 break;
2345 case EVENT_ASSOC:
2346 wpa_supplicant_event_assoc(wpa_s, data);
2347 break;
2348 case EVENT_DISASSOC:
2349 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2350 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002351 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2352 data->disassoc_info.reason_code,
2353 data->disassoc_info.locally_generated ?
2354 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 if (data->disassoc_info.addr)
2356 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2357 MAC2STR(data->disassoc_info.addr));
2358 }
2359#ifdef CONFIG_AP
2360 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2361 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2362 data->disassoc_info.addr);
2363 break;
2364 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002365 if (wpa_s->ap_iface) {
2366 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2367 "AP mode");
2368 break;
2369 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370#endif /* CONFIG_AP */
2371 if (data) {
2372 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002373 locally_generated =
2374 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2376 data->disassoc_info.ie,
2377 data->disassoc_info.ie_len);
2378#ifdef CONFIG_P2P
2379 wpas_p2p_disassoc_notif(
2380 wpa_s, data->disassoc_info.addr, reason_code,
2381 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002382 data->disassoc_info.ie_len,
2383 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384#endif /* CONFIG_P2P */
2385 }
2386 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2387 sme_event_disassoc(wpa_s, data);
2388 /* fall through */
2389 case EVENT_DEAUTH:
2390 if (event == EVENT_DEAUTH) {
2391 wpa_dbg(wpa_s, MSG_DEBUG,
2392 "Deauthentication notification");
2393 if (data) {
2394 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002395 locally_generated =
2396 data->deauth_info.locally_generated;
2397 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2398 data->deauth_info.reason_code,
2399 data->deauth_info.locally_generated ?
2400 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002401 if (data->deauth_info.addr) {
2402 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2403 MACSTR,
2404 MAC2STR(data->deauth_info.
2405 addr));
2406 }
2407 wpa_hexdump(MSG_DEBUG,
2408 "Deauthentication frame IE(s)",
2409 data->deauth_info.ie,
2410 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002411 }
2412 }
2413#ifdef CONFIG_AP
2414 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2415 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2416 data->deauth_info.addr);
2417 break;
2418 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002419 if (wpa_s->ap_iface) {
2420 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2421 "AP mode");
2422 break;
2423 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002424#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002425 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2426 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002427 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2428 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2429 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2430 eapol_sm_failed(wpa_s->eapol)))
2431 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002432#ifdef CONFIG_P2P
2433 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002434 if (wpas_p2p_deauth_notif(wpa_s,
2435 data->deauth_info.addr,
2436 reason_code,
2437 data->deauth_info.ie,
2438 data->deauth_info.ie_len,
2439 locally_generated) > 0) {
2440 /*
2441 * The interface was removed, so cannot
2442 * continue processing any additional
2443 * operations after this.
2444 */
2445 break;
2446 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002447 }
2448#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002449 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2450 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002451 break;
2452 case EVENT_MICHAEL_MIC_FAILURE:
2453 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2454 break;
2455#ifndef CONFIG_NO_SCAN_PROCESSING
2456 case EVENT_SCAN_RESULTS:
2457 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002458#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07002459 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002460 wpa_s->global->p2p != NULL &&
2461 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2462 wpa_s->wpa_state != WPA_ASSOCIATING) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07002463 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002464 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2465 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2466 "continued after scan result processing");
2467 }
2468 }
2469#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002470 break;
2471#endif /* CONFIG_NO_SCAN_PROCESSING */
2472 case EVENT_ASSOCINFO:
2473 wpa_supplicant_event_associnfo(wpa_s, data);
2474 break;
2475 case EVENT_INTERFACE_STATUS:
2476 wpa_supplicant_event_interface_status(wpa_s, data);
2477 break;
2478 case EVENT_PMKID_CANDIDATE:
2479 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2480 break;
2481#ifdef CONFIG_PEERKEY
2482 case EVENT_STKSTART:
2483 wpa_supplicant_event_stkstart(wpa_s, data);
2484 break;
2485#endif /* CONFIG_PEERKEY */
2486#ifdef CONFIG_TDLS
2487 case EVENT_TDLS:
2488 wpa_supplicant_event_tdls(wpa_s, data);
2489 break;
2490#endif /* CONFIG_TDLS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002491#ifdef CONFIG_IEEE80211V
2492 case EVENT_WNM:
2493 wpa_supplicant_event_wnm(wpa_s, data);
2494 break;
2495#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496#ifdef CONFIG_IEEE80211R
2497 case EVENT_FT_RESPONSE:
2498 wpa_supplicant_event_ft_response(wpa_s, data);
2499 break;
2500#endif /* CONFIG_IEEE80211R */
2501#ifdef CONFIG_IBSS_RSN
2502 case EVENT_IBSS_RSN_START:
2503 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2504 break;
2505#endif /* CONFIG_IBSS_RSN */
2506 case EVENT_ASSOC_REJECT:
2507 if (data->assoc_reject.bssid)
2508 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2509 "bssid=" MACSTR " status_code=%u",
2510 MAC2STR(data->assoc_reject.bssid),
2511 data->assoc_reject.status_code);
2512 else
2513 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2514 "status_code=%u",
2515 data->assoc_reject.status_code);
2516 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2517 sme_event_assoc_reject(wpa_s, data);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002518#ifdef ANDROID_P2P
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002519#ifdef CONFIG_P2P
2520 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002521 if(!wpa_s->current_ssid) {
2522 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2523 break;
2524 }
2525 /* If assoc reject is reported by the driver, then avoid
2526 * waiting for the authentication timeout. Cancel the
2527 * authentication timeout and retry the assoc.
2528 */
2529 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2530 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2531 wpa_s->current_ssid->assoc_retry);
2532 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002533
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002534 /* Clear the states */
2535 wpa_sm_notify_disassoc(wpa_s->wpa);
2536 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2537
2538 wpa_s->reassociate = 1;
2539 wpa_supplicant_req_scan(wpa_s, 1, 0);
2540 } else {
2541 /* If we ASSOC_REJECT's hits threshold, disable the
2542 * network
2543 */
2544 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2545 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002546 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002547 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002548 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002549 }
2550 }
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002551#endif
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002552#endif /* ANDROID_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553 break;
2554 case EVENT_AUTH_TIMED_OUT:
2555 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2556 sme_event_auth_timed_out(wpa_s, data);
2557 break;
2558 case EVENT_ASSOC_TIMED_OUT:
2559 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2560 sme_event_assoc_timed_out(wpa_s, data);
2561 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 case EVENT_TX_STATUS:
2563 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2564 " type=%d stype=%d",
2565 MAC2STR(data->tx_status.dst),
2566 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002567#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002569#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2571 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002572 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 wpa_s, data->tx_status.dst,
2574 data->tx_status.data,
2575 data->tx_status.data_len,
2576 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002577 OFFCHANNEL_SEND_ACTION_SUCCESS :
2578 OFFCHANNEL_SEND_ACTION_NO_ACK);
2579#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580 break;
2581 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582#endif /* CONFIG_AP */
2583#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002584 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2585 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2586 /*
2587 * Catch TX status events for Action frames we sent via group
2588 * interface in GO mode.
2589 */
2590 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2591 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2592 os_memcmp(wpa_s->parent->pending_action_dst,
2593 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002594 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002595 wpa_s->parent, data->tx_status.dst,
2596 data->tx_status.data,
2597 data->tx_status.data_len,
2598 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002599 OFFCHANNEL_SEND_ACTION_SUCCESS :
2600 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002601 break;
2602 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002603#endif /* CONFIG_OFFCHANNEL */
2604#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605 switch (data->tx_status.type) {
2606 case WLAN_FC_TYPE_MGMT:
2607 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2608 data->tx_status.data_len,
2609 data->tx_status.stype,
2610 data->tx_status.ack);
2611 break;
2612 case WLAN_FC_TYPE_DATA:
2613 ap_tx_status(wpa_s, data->tx_status.dst,
2614 data->tx_status.data,
2615 data->tx_status.data_len,
2616 data->tx_status.ack);
2617 break;
2618 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002619#endif /* CONFIG_AP */
2620 break;
2621#ifdef CONFIG_AP
2622 case EVENT_EAPOL_TX_STATUS:
2623 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2624 data->eapol_tx_status.data,
2625 data->eapol_tx_status.data_len,
2626 data->eapol_tx_status.ack);
2627 break;
2628 case EVENT_DRIVER_CLIENT_POLL_OK:
2629 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002630 break;
2631 case EVENT_RX_FROM_UNKNOWN:
2632 if (wpa_s->ap_iface == NULL)
2633 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002634 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2635 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002637 case EVENT_CH_SWITCH:
2638 if (!data)
2639 break;
2640 if (!wpa_s->ap_iface) {
2641 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2642 "event in non-AP mode");
2643 break;
2644 }
2645
2646#ifdef CONFIG_AP
2647 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2648 data->ch_switch.ht_enabled,
2649 data->ch_switch.ch_offset);
2650#endif /* CONFIG_AP */
2651 break;
2652 case EVENT_RX_MGMT: {
2653 u16 fc, stype;
2654 const struct ieee80211_mgmt *mgmt;
2655
2656 mgmt = (const struct ieee80211_mgmt *)
2657 data->rx_mgmt.frame;
2658 fc = le_to_host16(mgmt->frame_control);
2659 stype = WLAN_FC_GET_STYPE(fc);
2660
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002661 if (wpa_s->ap_iface == NULL) {
2662#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002663 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2664 data->rx_mgmt.frame_len > 24) {
2665 const u8 *src = mgmt->sa;
2666 const u8 *ie = mgmt->u.probe_req.variable;
2667 size_t ie_len = data->rx_mgmt.frame_len -
2668 (mgmt->u.probe_req.variable -
2669 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002670 wpas_p2p_probe_req_rx(
2671 wpa_s, src, mgmt->da,
2672 mgmt->bssid, ie, ie_len,
2673 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 break;
2675 }
2676#endif /* CONFIG_P2P */
2677 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2678 "management frame in non-AP mode");
2679 break;
2680 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002681
2682 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2683 data->rx_mgmt.frame_len > 24) {
2684 const u8 *ie = mgmt->u.probe_req.variable;
2685 size_t ie_len = data->rx_mgmt.frame_len -
2686 (mgmt->u.probe_req.variable -
2687 data->rx_mgmt.frame);
2688
2689 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2690 mgmt->bssid, ie, ie_len,
2691 data->rx_mgmt.ssi_signal);
2692 }
2693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2695 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002696 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002697#endif /* CONFIG_AP */
2698 case EVENT_RX_ACTION:
2699 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2700 " Category=%u DataLen=%d freq=%d MHz",
2701 MAC2STR(data->rx_action.sa),
2702 data->rx_action.category, (int) data->rx_action.len,
2703 data->rx_action.freq);
2704#ifdef CONFIG_IEEE80211R
2705 if (data->rx_action.category == WLAN_ACTION_FT) {
2706 ft_rx_action(wpa_s, data->rx_action.data,
2707 data->rx_action.len);
2708 break;
2709 }
2710#endif /* CONFIG_IEEE80211R */
2711#ifdef CONFIG_IEEE80211W
2712#ifdef CONFIG_SME
2713 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2714 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2715 data->rx_action.data,
2716 data->rx_action.len);
2717 break;
2718 }
2719#endif /* CONFIG_SME */
2720#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002721#ifdef CONFIG_IEEE80211V
2722 if (data->rx_action.category == WLAN_ACTION_WNM) {
2723 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2724 break;
2725 }
2726#endif /* CONFIG_IEEE80211V */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002727#ifdef CONFIG_GAS
2728 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2729 gas_query_rx(wpa_s->gas, data->rx_action.da,
2730 data->rx_action.sa, data->rx_action.bssid,
2731 data->rx_action.data, data->rx_action.len,
2732 data->rx_action.freq) == 0)
2733 break;
2734#endif /* CONFIG_GAS */
2735 if (data->rx_action.category == WLAN_ACTION_WNM) {
2736 wnm_action_rx(wpa_s, &data->rx_action);
2737 break;
2738 }
2739#ifdef CONFIG_TDLS
2740 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2741 data->rx_action.len >= 4 &&
2742 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2743 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2744 "Response from " MACSTR,
2745 MAC2STR(data->rx_action.sa));
2746 break;
2747 }
2748#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749#ifdef CONFIG_P2P
2750 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2751 data->rx_action.sa,
2752 data->rx_action.bssid,
2753 data->rx_action.category,
2754 data->rx_action.data,
2755 data->rx_action.len, data->rx_action.freq);
2756#endif /* CONFIG_P2P */
2757 break;
2758 case EVENT_RX_PROBE_REQ:
2759 if (data->rx_probe_req.sa == NULL ||
2760 data->rx_probe_req.ie == NULL)
2761 break;
2762#ifdef CONFIG_AP
2763 if (wpa_s->ap_iface) {
2764 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2765 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002766 data->rx_probe_req.da,
2767 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002769 data->rx_probe_req.ie_len,
2770 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 break;
2772 }
2773#endif /* CONFIG_AP */
2774#ifdef CONFIG_P2P
2775 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002776 data->rx_probe_req.da,
2777 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002779 data->rx_probe_req.ie_len,
2780 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002781#endif /* CONFIG_P2P */
2782 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002784#ifdef CONFIG_OFFCHANNEL
2785 offchannel_remain_on_channel_cb(
2786 wpa_s, data->remain_on_channel.freq,
2787 data->remain_on_channel.duration);
2788#endif /* CONFIG_OFFCHANNEL */
2789#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002790 wpas_p2p_remain_on_channel_cb(
2791 wpa_s, data->remain_on_channel.freq,
2792 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002793#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794 break;
2795 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002796#ifdef CONFIG_OFFCHANNEL
2797 offchannel_cancel_remain_on_channel_cb(
2798 wpa_s, data->remain_on_channel.freq);
2799#endif /* CONFIG_OFFCHANNEL */
2800#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002801 wpas_p2p_cancel_remain_on_channel_cb(
2802 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002803#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002805#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 case EVENT_P2P_DEV_FOUND: {
2807 struct p2p_peer_info peer_info;
2808
2809 os_memset(&peer_info, 0, sizeof(peer_info));
2810 if (data->p2p_dev_found.dev_addr)
2811 os_memcpy(peer_info.p2p_device_addr,
2812 data->p2p_dev_found.dev_addr, ETH_ALEN);
2813 if (data->p2p_dev_found.pri_dev_type)
2814 os_memcpy(peer_info.pri_dev_type,
2815 data->p2p_dev_found.pri_dev_type,
2816 sizeof(peer_info.pri_dev_type));
2817 if (data->p2p_dev_found.dev_name)
2818 os_strlcpy(peer_info.device_name,
2819 data->p2p_dev_found.dev_name,
2820 sizeof(peer_info.device_name));
2821 peer_info.config_methods = data->p2p_dev_found.config_methods;
2822 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2823 peer_info.group_capab = data->p2p_dev_found.group_capab;
2824
2825 /*
2826 * FIX: new_device=1 is not necessarily correct. We should
2827 * maintain a P2P peer database in wpa_supplicant and update
2828 * this information based on whether the peer is truly new.
2829 */
2830 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2831 break;
2832 }
2833 case EVENT_P2P_GO_NEG_REQ_RX:
2834 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2835 data->p2p_go_neg_req_rx.dev_passwd_id);
2836 break;
2837 case EVENT_P2P_GO_NEG_COMPLETED:
2838 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2839 break;
2840 case EVENT_P2P_PROV_DISC_REQUEST:
2841 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2842 data->p2p_prov_disc_req.config_methods,
2843 data->p2p_prov_disc_req.dev_addr,
2844 data->p2p_prov_disc_req.pri_dev_type,
2845 data->p2p_prov_disc_req.dev_name,
2846 data->p2p_prov_disc_req.supp_config_methods,
2847 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002848 data->p2p_prov_disc_req.group_capab,
2849 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850 break;
2851 case EVENT_P2P_PROV_DISC_RESPONSE:
2852 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2853 data->p2p_prov_disc_resp.config_methods);
2854 break;
2855 case EVENT_P2P_SD_REQUEST:
2856 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2857 data->p2p_sd_req.sa,
2858 data->p2p_sd_req.dialog_token,
2859 data->p2p_sd_req.update_indic,
2860 data->p2p_sd_req.tlvs,
2861 data->p2p_sd_req.tlvs_len);
2862 break;
2863 case EVENT_P2P_SD_RESPONSE:
2864 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2865 data->p2p_sd_resp.update_indic,
2866 data->p2p_sd_resp.tlvs,
2867 data->p2p_sd_resp.tlvs_len);
2868 break;
2869#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 case EVENT_EAPOL_RX:
2871 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2872 data->eapol_rx.data,
2873 data->eapol_rx.data_len);
2874 break;
2875 case EVENT_SIGNAL_CHANGE:
2876 bgscan_notify_signal_change(
2877 wpa_s, data->signal_change.above_threshold,
2878 data->signal_change.current_signal,
2879 data->signal_change.current_noise,
2880 data->signal_change.current_txrate);
2881 break;
2882 case EVENT_INTERFACE_ENABLED:
2883 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2884 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002885 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002886#ifdef CONFIG_AP
2887 if (!wpa_s->ap_iface) {
2888 wpa_supplicant_set_state(wpa_s,
2889 WPA_DISCONNECTED);
2890 wpa_supplicant_req_scan(wpa_s, 0, 0);
2891 } else
2892 wpa_supplicant_set_state(wpa_s,
2893 WPA_COMPLETED);
2894#else /* CONFIG_AP */
2895 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2896 wpa_supplicant_req_scan(wpa_s, 0, 0);
2897#endif /* CONFIG_AP */
2898 }
2899 break;
2900 case EVENT_INTERFACE_DISABLED:
2901 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2902 wpa_supplicant_mark_disassoc(wpa_s);
2903 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2904 break;
2905 case EVENT_CHANNEL_LIST_CHANGED:
2906 if (wpa_s->drv_priv == NULL)
2907 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002908
2909 free_hw_features(wpa_s);
2910 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2911 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002913#ifdef CONFIG_P2P
2914 wpas_p2p_update_channel_list(wpa_s);
2915#endif /* CONFIG_P2P */
2916 break;
2917 case EVENT_INTERFACE_UNAVAILABLE:
2918#ifdef CONFIG_P2P
2919 wpas_p2p_interface_unavailable(wpa_s);
2920#endif /* CONFIG_P2P */
2921 break;
2922 case EVENT_BEST_CHANNEL:
2923 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2924 "(%d %d %d)",
2925 data->best_chan.freq_24, data->best_chan.freq_5,
2926 data->best_chan.freq_overall);
2927 wpa_s->best_24_freq = data->best_chan.freq_24;
2928 wpa_s->best_5_freq = data->best_chan.freq_5;
2929 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2930#ifdef CONFIG_P2P
2931 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2932 data->best_chan.freq_5,
2933 data->best_chan.freq_overall);
2934#endif /* CONFIG_P2P */
2935 break;
2936 case EVENT_UNPROT_DEAUTH:
2937 wpa_supplicant_event_unprot_deauth(wpa_s,
2938 &data->unprot_deauth);
2939 break;
2940 case EVENT_UNPROT_DISASSOC:
2941 wpa_supplicant_event_unprot_disassoc(wpa_s,
2942 &data->unprot_disassoc);
2943 break;
2944 case EVENT_STATION_LOW_ACK:
2945#ifdef CONFIG_AP
2946 if (wpa_s->ap_iface && data)
2947 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2948 data->low_ack.addr);
2949#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002950#ifdef CONFIG_TDLS
2951 if (data)
2952 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2953#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002954 break;
2955 case EVENT_IBSS_PEER_LOST:
2956#ifdef CONFIG_IBSS_RSN
2957 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2958#endif /* CONFIG_IBSS_RSN */
2959 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002960 case EVENT_DRIVER_GTK_REKEY:
2961 if (os_memcmp(data->driver_gtk_rekey.bssid,
2962 wpa_s->bssid, ETH_ALEN))
2963 break;
2964 if (!wpa_s->wpa)
2965 break;
2966 wpa_sm_update_replay_ctr(wpa_s->wpa,
2967 data->driver_gtk_rekey.replay_ctr);
2968 break;
2969 case EVENT_SCHED_SCAN_STOPPED:
2970 wpa_s->sched_scanning = 0;
2971 wpa_supplicant_notify_scanning(wpa_s, 0);
2972
2973 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2974 break;
2975
2976 /*
2977 * If we timed out, start a new sched scan to continue
2978 * searching for more SSIDs.
2979 */
2980 if (wpa_s->sched_scan_timed_out)
2981 wpa_supplicant_req_sched_scan(wpa_s);
2982 break;
2983 case EVENT_WPS_BUTTON_PUSHED:
2984#ifdef CONFIG_WPS
2985 wpas_wps_start_pbc(wpa_s, NULL, 0);
2986#endif /* CONFIG_WPS */
2987 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002988 default:
2989 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
2990 break;
2991 }
2992}