blob: 945ba4a7e4d9567633aee7cb4077848a0b54c182 [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
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080047static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s);
48
49
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070050static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
51 struct wpa_ssid *ssid)
52{
53 struct os_time now;
54
55 if (ssid == NULL || ssid->disabled_until.sec == 0)
56 return 0;
57
58 os_get_time(&now);
59 if (ssid->disabled_until.sec > now.sec)
60 return ssid->disabled_until.sec - now.sec;
61
62 wpas_clear_temp_disabled(wpa_s, ssid, 0);
63
64 return 0;
65}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066
67
68static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
69{
70 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070071 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072
73 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
74 return 0;
75
76 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
77 "information");
78 ssid = wpa_supplicant_get_ssid(wpa_s);
79 if (ssid == NULL) {
80 wpa_msg(wpa_s, MSG_INFO,
81 "No network configuration found for the current AP");
82 return -1;
83 }
84
Dmitry Shmidt04949592012-07-19 12:16:46 -070085 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070086 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
87 return -1;
88 }
89
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080090 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
91 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
92 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
93 return -1;
94 }
95
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070096 res = wpas_temp_disabled(wpa_s, ssid);
97 if (res > 0) {
98 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
99 "disabled for %d second(s)", res);
100 return -1;
101 }
102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
104 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800105 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 u8 wpa_ie[80];
107 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800108 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
109 wpa_ie, &wpa_ie_len) < 0)
110 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111 } else {
112 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
113 }
114
115 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
116 eapol_sm_invalidate_cached_session(wpa_s->eapol);
117 old_ssid = wpa_s->current_ssid;
118 wpa_s->current_ssid = ssid;
119 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
120 wpa_supplicant_initiate_eapol(wpa_s);
121 if (old_ssid != wpa_s->current_ssid)
122 wpas_notify_network_changed(wpa_s);
123
124 return 0;
125}
126
127
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800128void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700129{
130 struct wpa_supplicant *wpa_s = eloop_ctx;
131
132 if (wpa_s->countermeasures) {
133 wpa_s->countermeasures = 0;
134 wpa_drv_set_countermeasures(wpa_s, 0);
135 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
136 wpa_supplicant_req_scan(wpa_s, 0, 0);
137 }
138}
139
140
141void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
142{
143 int bssid_changed;
144
Dmitry Shmidt04949592012-07-19 12:16:46 -0700145 wnm_bss_keep_alive_deinit(wpa_s);
146
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700147#ifdef CONFIG_IBSS_RSN
148 ibss_rsn_deinit(wpa_s->ibss_rsn);
149 wpa_s->ibss_rsn = NULL;
150#endif /* CONFIG_IBSS_RSN */
151
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700152#ifdef CONFIG_AP
153 wpa_supplicant_ap_deinit(wpa_s);
154#endif /* CONFIG_AP */
155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
157 return;
158
159 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800160#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700161 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800162#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174#ifdef CONFIG_IEEE80211R
175#ifdef CONFIG_SME
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178#endif /* CONFIG_SME */
179#endif /* CONFIG_IEEE80211R */
180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 wpa_s->current_ssid = NULL;
190 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191}
192
193
194static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
195{
196 struct wpa_ie_data ie;
197 int pmksa_set = -1;
198 size_t i;
199
200 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
201 ie.pmkid == NULL)
202 return;
203
204 for (i = 0; i < ie.num_pmkid; i++) {
205 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
206 ie.pmkid + i * PMKID_LEN,
207 NULL, NULL, 0);
208 if (pmksa_set == 0) {
209 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
210 break;
211 }
212 }
213
214 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
215 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
216}
217
218
219static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
220 union wpa_event_data *data)
221{
222 if (data == NULL) {
223 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
224 "event");
225 return;
226 }
227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
228 " index=%d preauth=%d",
229 MAC2STR(data->pmkid_candidate.bssid),
230 data->pmkid_candidate.index,
231 data->pmkid_candidate.preauth);
232
233 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
234 data->pmkid_candidate.index,
235 data->pmkid_candidate.preauth);
236}
237
238
239static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
240{
241 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
242 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
243 return 0;
244
245#ifdef IEEE8021X_EAPOL
246 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
247 wpa_s->current_ssid &&
248 !(wpa_s->current_ssid->eapol_flags &
249 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
250 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
251 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
252 * plaintext or static WEP keys). */
253 return 0;
254 }
255#endif /* IEEE8021X_EAPOL */
256
257 return 1;
258}
259
260
261/**
262 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
263 * @wpa_s: pointer to wpa_supplicant data
264 * @ssid: Configuration data for the network
265 * Returns: 0 on success, -1 on failure
266 *
267 * This function is called when starting authentication with a network that is
268 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
269 */
270int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
271 struct wpa_ssid *ssid)
272{
273#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800274#ifdef PCSC_FUNCS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275 int aka = 0, sim = 0, type;
276
277 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
278 return 0;
279
280 if (ssid->eap.eap_methods == NULL) {
281 sim = 1;
282 aka = 1;
283 } else {
284 struct eap_method_type *eap = ssid->eap.eap_methods;
285 while (eap->vendor != EAP_VENDOR_IETF ||
286 eap->method != EAP_TYPE_NONE) {
287 if (eap->vendor == EAP_VENDOR_IETF) {
288 if (eap->method == EAP_TYPE_SIM)
289 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 else if (eap->method == EAP_TYPE_AKA ||
291 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 aka = 1;
293 }
294 eap++;
295 }
296 }
297
298 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
299 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
301 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
302 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303 aka = 0;
304
305 if (!sim && !aka) {
306 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
307 "use SIM, but neither EAP-SIM nor EAP-AKA are "
308 "enabled");
309 return 0;
310 }
311
312 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
313 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
314 if (sim && aka)
315 type = SCARD_TRY_BOTH;
316 else if (aka)
317 type = SCARD_USIM_ONLY;
318 else
319 type = SCARD_GSM_SIM_ONLY;
320
Dmitry Shmidt04949592012-07-19 12:16:46 -0700321 wpa_s->scard = scard_init(type, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 if (wpa_s->scard == NULL) {
323 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
324 "(pcsc-lite)");
325 return -1;
326 }
327 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
328 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800329#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330#endif /* IEEE8021X_EAPOL */
331
332 return 0;
333}
334
335
336#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700337static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 struct wpa_ssid *ssid)
339{
340 int i, privacy = 0;
341
342 if (ssid->mixed_cell)
343 return 1;
344
345#ifdef CONFIG_WPS
346 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
347 return 1;
348#endif /* CONFIG_WPS */
349
350 for (i = 0; i < NUM_WEP_KEYS; i++) {
351 if (ssid->wep_key_len[i]) {
352 privacy = 1;
353 break;
354 }
355 }
356#ifdef IEEE8021X_EAPOL
357 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
358 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
359 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
360 privacy = 1;
361#endif /* IEEE8021X_EAPOL */
362
Jouni Malinen75ecf522011-06-27 15:19:46 -0700363 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
364 privacy = 1;
365
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366 if (bss->caps & IEEE80211_CAP_PRIVACY)
367 return privacy;
368 return !privacy;
369}
370
371
372static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
373 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700374 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375{
376 struct wpa_ie_data ie;
377 int proto_match = 0;
378 const u8 *rsn_ie, *wpa_ie;
379 int ret;
380 int wep_ok;
381
382 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
383 if (ret >= 0)
384 return ret;
385
386 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
387 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
388 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
389 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
390 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
391
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700392 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
394 proto_match++;
395
396 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
397 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
398 "failed");
399 break;
400 }
401
402 if (wep_ok &&
403 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
404 {
405 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
406 "in RSN IE");
407 return 1;
408 }
409
410 if (!(ie.proto & ssid->proto)) {
411 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
412 "mismatch");
413 break;
414 }
415
416 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
417 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
418 "cipher mismatch");
419 break;
420 }
421
422 if (!(ie.group_cipher & ssid->group_cipher)) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
424 "cipher mismatch");
425 break;
426 }
427
428 if (!(ie.key_mgmt & ssid->key_mgmt)) {
429 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
430 "mismatch");
431 break;
432 }
433
434#ifdef CONFIG_IEEE80211W
435 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800436 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
437 wpa_s->conf->pmf : ssid->ieee80211w) ==
438 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
440 "frame protection");
441 break;
442 }
443#endif /* CONFIG_IEEE80211W */
444
445 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
446 return 1;
447 }
448
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700449 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
451 proto_match++;
452
453 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
454 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
455 "failed");
456 break;
457 }
458
459 if (wep_ok &&
460 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
461 {
462 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
463 "in WPA IE");
464 return 1;
465 }
466
467 if (!(ie.proto & ssid->proto)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
469 "mismatch");
470 break;
471 }
472
473 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
475 "cipher mismatch");
476 break;
477 }
478
479 if (!(ie.group_cipher & ssid->group_cipher)) {
480 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
481 "cipher mismatch");
482 break;
483 }
484
485 if (!(ie.key_mgmt & ssid->key_mgmt)) {
486 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
487 "mismatch");
488 break;
489 }
490
491 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
492 return 1;
493 }
494
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700495 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
496 !rsn_ie) {
497 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
498 return 1;
499 }
500
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
502 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
503 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
504 return 0;
505 }
506
507 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
508 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
509 return 1;
510 }
511
512 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
513 "WPA/WPA2");
514
515 return 0;
516}
517
518
519static int freq_allowed(int *freqs, int freq)
520{
521 int i;
522
523 if (freqs == NULL)
524 return 1;
525
526 for (i = 0; freqs[i]; i++)
527 if (freqs[i] == freq)
528 return 1;
529 return 0;
530}
531
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533static int ht_supported(const struct hostapd_hw_modes *mode)
534{
535 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
536 /*
537 * The driver did not indicate whether it supports HT. Assume
538 * it does to avoid connection issues.
539 */
540 return 1;
541 }
542
543 /*
544 * IEEE Std 802.11n-2009 20.1.1:
545 * An HT non-AP STA shall support all EQM rates for one spatial stream.
546 */
547 return mode->mcs_set[0] == 0xff;
548}
549
550
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700551static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552{
553 const struct hostapd_hw_modes *mode = NULL, *modes;
554 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
555 const u8 *rate_ie;
556 int i, j, k;
557
558 if (bss->freq == 0)
559 return 1; /* Cannot do matching without knowing band */
560
561 modes = wpa_s->hw.modes;
562 if (modes == NULL) {
563 /*
564 * The driver does not provide any additional information
565 * about the utilized hardware, so allow the connection attempt
566 * to continue.
567 */
568 return 1;
569 }
570
571 for (i = 0; i < wpa_s->hw.num_modes; i++) {
572 for (j = 0; j < modes[i].num_channels; j++) {
573 int freq = modes[i].channels[j].freq;
574 if (freq == bss->freq) {
575 if (mode &&
576 mode->mode == HOSTAPD_MODE_IEEE80211G)
577 break; /* do not allow 802.11b replace
578 * 802.11g */
579 mode = &modes[i];
580 break;
581 }
582 }
583 }
584
585 if (mode == NULL)
586 return 0;
587
588 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700589 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590 if (rate_ie == NULL)
591 continue;
592
593 for (j = 2; j < rate_ie[1] + 2; j++) {
594 int flagged = !!(rate_ie[j] & 0x80);
595 int r = (rate_ie[j] & 0x7f) * 5;
596
597 /*
598 * IEEE Std 802.11n-2009 7.3.2.2:
599 * The new BSS Membership selector value is encoded
600 * like a legacy basic rate, but it is not a rate and
601 * only indicates if the BSS members are required to
602 * support the mandatory features of Clause 20 [HT PHY]
603 * in order to join the BSS.
604 */
605 if (flagged && ((rate_ie[j] & 0x7f) ==
606 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
607 if (!ht_supported(mode)) {
608 wpa_dbg(wpa_s, MSG_DEBUG,
609 " hardware does not support "
610 "HT PHY");
611 return 0;
612 }
613 continue;
614 }
615
616 if (!flagged)
617 continue;
618
619 /* check for legacy basic rates */
620 for (k = 0; k < mode->num_rates; k++) {
621 if (mode->rates[k] == r)
622 break;
623 }
624 if (k == mode->num_rates) {
625 /*
626 * IEEE Std 802.11-2007 7.3.2.2 demands that in
627 * order to join a BSS all required rates
628 * have to be supported by the hardware.
629 */
630 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
631 "not support required rate %d.%d Mbps",
632 r / 10, r % 10);
633 return 0;
634 }
635 }
636 }
637
638 return 1;
639}
640
641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700643 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 struct wpa_ssid *group)
645{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700646 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 int wpa;
648 struct wpa_blacklist *e;
649 const u8 *ie;
650 struct wpa_ssid *ssid;
651
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700652 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 wpa_ie_len = ie ? ie[1] : 0;
654
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700655 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 rsn_ie_len = ie ? ie[1] : 0;
657
658 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
659 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700660 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700662 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663
664 e = wpa_blacklist_get(wpa_s, bss->bssid);
665 if (e) {
666 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700667 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 /*
669 * When only a single network is enabled, we can
670 * trigger blacklisting on the first failure. This
671 * should not be done with multiple enabled networks to
672 * avoid getting forced to move into a worse ESS on
673 * single error if there are no other BSSes of the
674 * current ESS.
675 */
676 limit = 0;
677 }
678 if (e->count > limit) {
679 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
680 "(count=%d limit=%d)", e->count, limit);
681 return NULL;
682 }
683 }
684
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700685 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
687 return NULL;
688 }
689
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800690 if (disallowed_bssid(wpa_s, bss->bssid)) {
691 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
692 return NULL;
693 }
694
695 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
696 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
697 return NULL;
698 }
699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
701
702 for (ssid = group; ssid; ssid = ssid->pnext) {
703 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700704 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705
Dmitry Shmidt04949592012-07-19 12:16:46 -0700706 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
708 continue;
709 }
710
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700711 res = wpas_temp_disabled(wpa_s, ssid);
712 if (res > 0) {
713 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
714 "temporarily for %d second(s)", res);
715 continue;
716 }
717
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718#ifdef CONFIG_WPS
719 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
720 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
721 "(WPS)");
722 continue;
723 }
724
725 if (wpa && ssid->ssid_len == 0 &&
726 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
727 check_ssid = 0;
728
729 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
730 /* Only allow wildcard SSID match if an AP
731 * advertises active WPS operation that matches
732 * with our mode. */
733 check_ssid = 1;
734 if (ssid->ssid_len == 0 &&
735 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
736 check_ssid = 0;
737 }
738#endif /* CONFIG_WPS */
739
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800740 if (ssid->bssid_set && ssid->ssid_len == 0 &&
741 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
742 check_ssid = 0;
743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700745 (bss->ssid_len != ssid->ssid_len ||
746 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
748 continue;
749 }
750
751 if (ssid->bssid_set &&
752 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
754 continue;
755 }
756
757 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
758 continue;
759
760 if (!wpa &&
761 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
762 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
763 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
764 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
765 "not allowed");
766 continue;
767 }
768
Jouni Malinen75ecf522011-06-27 15:19:46 -0700769 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
771 "mismatch");
772 continue;
773 }
774
Jouni Malinen75ecf522011-06-27 15:19:46 -0700775 if (bss->caps & IEEE80211_CAP_IBSS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
777 "network");
778 continue;
779 }
780
781 if (!freq_allowed(ssid->freq_list, bss->freq)) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
783 "allowed");
784 continue;
785 }
786
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800787 if (!rate_match(wpa_s, bss)) {
788 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
789 "not match");
790 continue;
791 }
792
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793#ifdef CONFIG_P2P
794 /*
795 * TODO: skip the AP if its P2P IE has Group Formation
796 * bit set in the P2P Group Capability Bitmap and we
797 * are not in Group Formation with that device.
798 */
799#endif /* CONFIG_P2P */
800
801 /* Matching configuration found */
802 return ssid;
803 }
804
805 /* No matching configuration found */
806 return NULL;
807}
808
809
810static struct wpa_bss *
811wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812 struct wpa_ssid *group,
813 struct wpa_ssid **selected_ssid)
814{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700815 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816
817 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
818 group->priority);
819
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700820 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
821 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
823 if (!*selected_ssid)
824 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
826 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700827 MAC2STR(bss->bssid),
828 wpa_ssid_txt(bss->ssid, bss->ssid_len));
829 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830 }
831
832 return NULL;
833}
834
835
836static struct wpa_bss *
837wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 struct wpa_ssid **selected_ssid)
839{
840 struct wpa_bss *selected = NULL;
841 int prio;
842
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700843 if (wpa_s->last_scan_res == NULL ||
844 wpa_s->last_scan_res_used == 0)
845 return NULL; /* no scan results from last update */
846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 while (selected == NULL) {
848 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
849 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700850 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851 selected_ssid);
852 if (selected)
853 break;
854 }
855
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800856 if (selected == NULL && wpa_s->blacklist &&
857 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
859 "blacklist and try again");
860 wpa_blacklist_clear(wpa_s);
861 wpa_s->blacklist_cleared++;
862 } else if (selected == NULL)
863 break;
864 }
865
866 return selected;
867}
868
869
870static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
871 int timeout_sec, int timeout_usec)
872{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700873 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 /*
875 * No networks are enabled; short-circuit request so
876 * we don't wait timeout seconds before transitioning
877 * to INACTIVE state.
878 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700879 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
880 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700882#ifdef CONFIG_P2P
883 wpa_s->sta_scan_pending = 0;
884#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885 return;
886 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800887
888 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
890}
891
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800892
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700893int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800894 struct wpa_bss *selected,
895 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896{
897 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
898 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
899 "PBC session overlap");
900#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800901 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700902 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903#endif /* CONFIG_P2P */
904
905#ifdef CONFIG_WPS
906 wpas_wps_cancel(wpa_s);
907#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700908 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909 }
910
911 /*
912 * Do not trigger new association unless the BSSID has changed or if
913 * reassociation is requested. If we are in process of associating with
914 * the selected BSSID, do not trigger new attempt.
915 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800916 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
918 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
919 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
920 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
921 0))) {
922 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
923 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700924 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 }
926 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
927 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
928 " pending: " MACSTR " wpa_state: %s",
929 wpa_s->reassociate, MAC2STR(selected->bssid),
930 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
931 wpa_supplicant_state_txt(wpa_s->wpa_state));
932 wpa_supplicant_associate(wpa_s, selected, ssid);
933 } else {
934 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
935 "selected AP");
936 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800937
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700938 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939}
940
941
942static struct wpa_ssid *
943wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
944{
945 int prio;
946 struct wpa_ssid *ssid;
947
948 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
949 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
950 {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700951 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700952 continue;
953 if (ssid->mode == IEEE80211_MODE_IBSS ||
954 ssid->mode == IEEE80211_MODE_AP)
955 return ssid;
956 }
957 }
958 return NULL;
959}
960
961
962/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
963 * on BSS added and BSS changed events */
964static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +0300965 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966{
Jouni Malinen87fd2792011-05-16 18:35:42 +0300967 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700968
969 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
970 return;
971
Jouni Malinen87fd2792011-05-16 18:35:42 +0300972 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974
Jouni Malinen87fd2792011-05-16 18:35:42 +0300975 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700976 if (ssid == NULL)
977 continue;
978
Jouni Malinen87fd2792011-05-16 18:35:42 +0300979 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 if (rsn == NULL)
981 continue;
982
Jouni Malinen87fd2792011-05-16 18:35:42 +0300983 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 }
985
986}
987
988
989static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
990 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700991 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700993 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994 int min_diff;
995
996 if (wpa_s->reassociate)
997 return 1; /* explicit request to reassociate */
998 if (wpa_s->wpa_state < WPA_ASSOCIATED)
999 return 1; /* we are not associated; continue */
1000 if (wpa_s->current_ssid == NULL)
1001 return 1; /* unknown current SSID */
1002 if (wpa_s->current_ssid != ssid)
1003 return 1; /* different network block */
1004
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001005 if (wpas_driver_bss_selection(wpa_s))
1006 return 0; /* Driver-based roaming */
1007
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001008 if (wpa_s->current_ssid->ssid)
1009 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1010 wpa_s->current_ssid->ssid,
1011 wpa_s->current_ssid->ssid_len);
1012 if (!current_bss)
1013 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014
1015 if (!current_bss)
1016 return 1; /* current BSS not seen in scan results */
1017
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001018 if (current_bss == selected)
1019 return 0;
1020
1021 if (selected->last_update_idx > current_bss->last_update_idx)
1022 return 1; /* current BSS not seen in the last scan */
1023
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001024#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1026 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1027 MAC2STR(current_bss->bssid), current_bss->level);
1028 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1029 MAC2STR(selected->bssid), selected->level);
1030
1031 if (wpa_s->current_ssid->bssid_set &&
1032 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1033 0) {
1034 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1035 "has preferred BSSID");
1036 return 1;
1037 }
1038
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001039 if (current_bss->level < 0 && current_bss->level > selected->level) {
1040 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1041 "signal level");
1042 return 0;
1043 }
1044
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 min_diff = 2;
1046 if (current_bss->level < 0) {
1047 if (current_bss->level < -85)
1048 min_diff = 1;
1049 else if (current_bss->level < -80)
1050 min_diff = 2;
1051 else if (current_bss->level < -75)
1052 min_diff = 3;
1053 else if (current_bss->level < -70)
1054 min_diff = 4;
1055 else
1056 min_diff = 5;
1057 }
1058 if (abs(current_bss->level - selected->level) < min_diff) {
1059 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1060 "in signal level");
1061 return 0;
1062 }
1063
1064 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001065#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001066 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001067#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068}
1069
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001070
Jouni Malinen89ca7022012-09-14 13:03:12 -07001071/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001072 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001073#ifdef ANDROID_P2P
1074static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1075 union wpa_event_data *data, int suppress_event)
1076#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1078 union wpa_event_data *data)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001079#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 struct wpa_scan_results *scan_res;
1082 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001083#ifndef CONFIG_NO_RANDOM_POOL
1084 size_t i, num;
1085#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086
1087#ifdef CONFIG_AP
1088 if (wpa_s->ap_iface)
1089 ap = 1;
1090#endif /* CONFIG_AP */
1091
1092 wpa_supplicant_notify_scanning(wpa_s, 0);
1093
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001094#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07001095 if (wpa_s->global->p2p_cb_on_scan_complete &&
1096 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001097 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1098 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001099 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001100 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1101 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1102 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001103 wpa_s->sta_scan_pending = 1;
1104 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001105 return -1;
1106 }
1107 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001108 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001109#endif /* CONFIG_P2P */
1110
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1112 data ? &data->scan_info :
1113 NULL, 1);
1114 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001115 if (wpa_s->conf->ap_scan == 2 || ap ||
1116 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 return -1;
1118 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1119 "scanning again");
1120 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1121 return -1;
1122 }
1123
1124#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 num = scan_res->num;
1126 if (num > 10)
1127 num = 10;
1128 for (i = 0; i < num; i++) {
1129 u8 buf[5];
1130 struct wpa_scan_res *res = scan_res->res[i];
1131 buf[0] = res->bssid[5];
1132 buf[1] = res->qual & 0xff;
1133 buf[2] = res->noise & 0xff;
1134 buf[3] = res->level & 0xff;
1135 buf[4] = res->tsf & 0xff;
1136 random_add_randomness(buf, sizeof(buf));
1137 }
1138#endif /* CONFIG_NO_RANDOM_POOL */
1139
1140 if (wpa_s->scan_res_handler) {
1141 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1142 struct wpa_scan_results *scan_res);
1143
1144 scan_res_handler = wpa_s->scan_res_handler;
1145 wpa_s->scan_res_handler = NULL;
1146 scan_res_handler(wpa_s, scan_res);
1147
1148 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001149 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 }
1151
1152 if (ap) {
1153 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1154#ifdef CONFIG_AP
1155 if (wpa_s->ap_iface->scan_cb)
1156 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1157#endif /* CONFIG_AP */
1158 wpa_scan_results_free(scan_res);
1159 return 0;
1160 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001161#ifdef ANDROID_P2P
1162 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001163 {
1164 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1165 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1166 wpas_notify_scan_results(wpa_s);
1167 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001168#else
1169 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1170 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1171 wpas_notify_scan_results(wpa_s);
1172#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173
1174 wpas_notify_scan_done(wpa_s, 1);
1175
Dmitry Shmidt04949592012-07-19 12:16:46 -07001176 if (sme_proc_obss_scan(wpa_s) > 0) {
1177 wpa_scan_results_free(scan_res);
1178 return 0;
1179 }
1180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1182 wpa_scan_results_free(scan_res);
1183 return 0;
1184 }
1185
Dmitry Shmidt04949592012-07-19 12:16:46 -07001186 if (autoscan_notify_scan(wpa_s, scan_res)) {
1187 wpa_scan_results_free(scan_res);
1188 return 0;
1189 }
1190
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 if (wpa_s->disconnected) {
1192 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1193 wpa_scan_results_free(scan_res);
1194 return 0;
1195 }
1196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 if (!wpas_driver_bss_selection(wpa_s) &&
1198 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 wpa_scan_results_free(scan_res);
1200 return 0;
1201 }
1202
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001203 wpas_wps_update_ap_info(wpa_s, scan_res);
1204
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001205 wpa_scan_results_free(scan_res);
1206
1207 return wpas_select_network_from_last_scan(wpa_s);
1208}
1209
1210
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001211static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001212{
1213 struct wpa_bss *selected;
1214 struct wpa_ssid *ssid = NULL;
1215
1216 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217
1218 if (selected) {
1219 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001220 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001221 if (skip) {
1222 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001224 }
1225
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001226 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001227 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001228 return -1;
1229 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001230 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001231 /*
1232 * Do not notify other virtual radios of scan results since we do not
1233 * want them to start other associations at the same time.
1234 */
1235 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1238 ssid = wpa_supplicant_pick_new_network(wpa_s);
1239 if (ssid) {
1240 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1241 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001242 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 } else {
1244 int timeout_sec = wpa_s->scan_interval;
1245 int timeout_usec = 0;
1246#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001247 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1248 return 0;
1249
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 if (wpa_s->p2p_in_provisioning) {
1251 /*
1252 * Use shorter wait during P2P Provisioning
1253 * state to speed up group formation.
1254 */
1255 timeout_sec = 0;
1256 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001257 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1258 timeout_usec);
1259 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260 }
1261#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001262#ifdef CONFIG_INTERWORKING
1263 if (wpa_s->conf->auto_interworking &&
1264 wpa_s->conf->interworking &&
1265 wpa_s->conf->cred) {
1266 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1267 "start ANQP fetch since no matching "
1268 "networks found");
1269 wpa_s->network_select = 1;
1270 wpa_s->auto_network_select = 1;
1271 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001272 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001273 }
1274#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001275 if (wpa_supplicant_req_sched_scan(wpa_s))
1276 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1277 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278 }
1279 }
1280 return 0;
1281}
1282
1283
1284static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1285 union wpa_event_data *data)
1286{
1287 const char *rn, *rn2;
1288 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001289#ifdef ANDROID_P2P
Jouni Malinen89ca7022012-09-14 13:03:12 -07001290 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) != 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001291#else
Jouni Malinen89ca7022012-09-14 13:03:12 -07001292 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001293#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294 /*
1295 * If no scan results could be fetched, then no need to
1296 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001297 * this scan. Similarly, if scan results started a new operation on this
1298 * interface, do not notify other interfaces to avoid concurrent
1299 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 */
1301 return;
1302 }
1303
1304 /*
1305 * Check other interfaces to see if they have the same radio-name. If
1306 * so, they get updated with this same scan info.
1307 */
1308 if (!wpa_s->driver->get_radio_name)
1309 return;
1310
1311 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1312 if (rn == NULL || rn[0] == '\0')
1313 return;
1314
1315 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1316 "sharing same radio (%s) in event_scan_results", rn);
1317
1318 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1319 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1320 continue;
1321
1322 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1323 if (rn2 && os_strcmp(rn, rn2) == 0) {
1324 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1325 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001326#ifdef ANDROID_P2P
1327 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1328 /* Do not update the scan results from STA interface to p2p interfaces */
1329 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1330 "sibling %s", ifs->ifname, wpa_s->ifname);
1331 continue;
1332 }
1333 else {
1334 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1335 * no time. Avoid announcing it to application as it may not
1336 * be that useful (since results will be that of only 1,6,11).
1337 * over to any other interface as it
1338 */
1339 if(p2p_search_in_progress(wpa_s->global->p2p))
1340 _wpa_supplicant_event_scan_results(ifs, data, 1);
1341 else
1342 _wpa_supplicant_event_scan_results(ifs, data, 0);
1343 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001344#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001345 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001346#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001347 }
1348 }
1349}
1350
1351#endif /* CONFIG_NO_SCAN_PROCESSING */
1352
1353
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001354int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1355{
1356#ifdef CONFIG_NO_SCAN_PROCESSING
1357 return -1;
1358#else /* CONFIG_NO_SCAN_PROCESSING */
1359 struct os_time now;
1360
1361 if (wpa_s->last_scan_res_used <= 0)
1362 return -1;
1363
1364 os_get_time(&now);
1365 if (now.sec - wpa_s->last_scan.sec > 5) {
1366 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1367 return -1;
1368 }
1369
1370 return wpas_select_network_from_last_scan(wpa_s);
1371#endif /* CONFIG_NO_SCAN_PROCESSING */
1372}
1373
Dmitry Shmidt04949592012-07-19 12:16:46 -07001374#ifdef CONFIG_WNM
1375
1376static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1377{
1378 struct wpa_supplicant *wpa_s = eloop_ctx;
1379
1380 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1381 return;
1382
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001383 if (!wpa_s->no_keep_alive) {
1384 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1385 MAC2STR(wpa_s->bssid));
1386 /* TODO: could skip this if normal data traffic has been sent */
1387 /* TODO: Consider using some more appropriate data frame for
1388 * this */
1389 if (wpa_s->l2)
1390 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1391 (u8 *) "", 0);
1392 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001393
1394#ifdef CONFIG_SME
1395 if (wpa_s->sme.bss_max_idle_period) {
1396 unsigned int msec;
1397 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1398 if (msec > 100)
1399 msec -= 100;
1400 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1401 wnm_bss_keep_alive, wpa_s, NULL);
1402 }
1403#endif /* CONFIG_SME */
1404}
1405
1406
1407static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1408 const u8 *ies, size_t ies_len)
1409{
1410 struct ieee802_11_elems elems;
1411
1412 if (ies == NULL)
1413 return;
1414
1415 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1416 return;
1417
1418#ifdef CONFIG_SME
1419 if (elems.bss_max_idle_period) {
1420 unsigned int msec;
1421 wpa_s->sme.bss_max_idle_period =
1422 WPA_GET_LE16(elems.bss_max_idle_period);
1423 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1424 "TU)%s", wpa_s->sme.bss_max_idle_period,
1425 (elems.bss_max_idle_period[2] & 0x01) ?
1426 " (protected keep-live required)" : "");
1427 if (wpa_s->sme.bss_max_idle_period == 0)
1428 wpa_s->sme.bss_max_idle_period = 1;
1429 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1430 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1431 /* msec times 1000 */
1432 msec = wpa_s->sme.bss_max_idle_period * 1024;
1433 if (msec > 100)
1434 msec -= 100;
1435 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1436 wnm_bss_keep_alive, wpa_s,
1437 NULL);
1438 }
1439 }
1440#endif /* CONFIG_SME */
1441}
1442
1443#endif /* CONFIG_WNM */
1444
1445
1446void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1447{
1448#ifdef CONFIG_WNM
1449 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1450#endif /* CONFIG_WNM */
1451}
1452
1453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001454static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1455 union wpa_event_data *data)
1456{
1457 int l, len, found = 0, wpa_found, rsn_found;
1458 const u8 *p;
1459
1460 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1461 if (data->assoc_info.req_ies)
1462 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1463 data->assoc_info.req_ies_len);
1464 if (data->assoc_info.resp_ies) {
1465 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1466 data->assoc_info.resp_ies_len);
1467#ifdef CONFIG_TDLS
1468 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1469 data->assoc_info.resp_ies_len);
1470#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001471#ifdef CONFIG_WNM
1472 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1473 data->assoc_info.resp_ies_len);
1474#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475 }
1476 if (data->assoc_info.beacon_ies)
1477 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1478 data->assoc_info.beacon_ies,
1479 data->assoc_info.beacon_ies_len);
1480 if (data->assoc_info.freq)
1481 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1482 data->assoc_info.freq);
1483
1484 p = data->assoc_info.req_ies;
1485 l = data->assoc_info.req_ies_len;
1486
1487 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1488 while (p && l >= 2) {
1489 len = p[1] + 2;
1490 if (len > l) {
1491 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1492 p, l);
1493 break;
1494 }
1495 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1496 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1497 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1498 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1499 break;
1500 found = 1;
1501 wpa_find_assoc_pmkid(wpa_s);
1502 break;
1503 }
1504 l -= len;
1505 p += len;
1506 }
1507 if (!found && data->assoc_info.req_ies)
1508 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1509
1510#ifdef CONFIG_IEEE80211R
1511#ifdef CONFIG_SME
1512 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1513 u8 bssid[ETH_ALEN];
1514 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1515 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1516 data->assoc_info.resp_ies,
1517 data->assoc_info.resp_ies_len,
1518 bssid) < 0) {
1519 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1520 "Reassociation Response failed");
1521 wpa_supplicant_deauthenticate(
1522 wpa_s, WLAN_REASON_INVALID_IE);
1523 return -1;
1524 }
1525 }
1526
1527 p = data->assoc_info.resp_ies;
1528 l = data->assoc_info.resp_ies_len;
1529
1530#ifdef CONFIG_WPS_STRICT
1531 if (p && wpa_s->current_ssid &&
1532 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1533 struct wpabuf *wps;
1534 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1535 if (wps == NULL) {
1536 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1537 "include WPS IE in (Re)Association Response");
1538 return -1;
1539 }
1540
1541 if (wps_validate_assoc_resp(wps) < 0) {
1542 wpabuf_free(wps);
1543 wpa_supplicant_deauthenticate(
1544 wpa_s, WLAN_REASON_INVALID_IE);
1545 return -1;
1546 }
1547 wpabuf_free(wps);
1548 }
1549#endif /* CONFIG_WPS_STRICT */
1550
1551 /* Go through the IEs and make a copy of the MDIE, if present. */
1552 while (p && l >= 2) {
1553 len = p[1] + 2;
1554 if (len > l) {
1555 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1556 p, l);
1557 break;
1558 }
1559 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1560 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1561 wpa_s->sme.ft_used = 1;
1562 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1563 MOBILITY_DOMAIN_ID_LEN);
1564 break;
1565 }
1566 l -= len;
1567 p += len;
1568 }
1569#endif /* CONFIG_SME */
1570
1571 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1572 data->assoc_info.resp_ies_len);
1573#endif /* CONFIG_IEEE80211R */
1574
1575 /* WPA/RSN IE from Beacon/ProbeResp */
1576 p = data->assoc_info.beacon_ies;
1577 l = data->assoc_info.beacon_ies_len;
1578
1579 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1580 */
1581 wpa_found = rsn_found = 0;
1582 while (p && l >= 2) {
1583 len = p[1] + 2;
1584 if (len > l) {
1585 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1586 p, l);
1587 break;
1588 }
1589 if (!wpa_found &&
1590 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1591 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1592 wpa_found = 1;
1593 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1594 }
1595
1596 if (!rsn_found &&
1597 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1598 rsn_found = 1;
1599 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1600 }
1601
1602 l -= len;
1603 p += len;
1604 }
1605
1606 if (!wpa_found && data->assoc_info.beacon_ies)
1607 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1608 if (!rsn_found && data->assoc_info.beacon_ies)
1609 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1610 if (wpa_found || rsn_found)
1611 wpa_s->ap_ies_from_associnfo = 1;
1612
Jouni Malinen87fd2792011-05-16 18:35:42 +03001613 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1614 wpa_s->assoc_freq != data->assoc_info.freq) {
1615 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1616 "%u to %u MHz",
1617 wpa_s->assoc_freq, data->assoc_info.freq);
1618 wpa_supplicant_update_scan_results(wpa_s);
1619 }
1620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 wpa_s->assoc_freq = data->assoc_info.freq;
1622
1623 return 0;
1624}
1625
1626
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001627static struct wpa_bss * wpa_supplicant_get_new_bss(
1628 struct wpa_supplicant *wpa_s, const u8 *bssid)
1629{
1630 struct wpa_bss *bss = NULL;
1631 struct wpa_ssid *ssid = wpa_s->current_ssid;
1632
1633 if (ssid->ssid_len > 0)
1634 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1635 if (!bss)
1636 bss = wpa_bss_get_bssid(wpa_s, bssid);
1637
1638 return bss;
1639}
1640
1641
1642static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1643{
1644 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1645
1646 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1647 return -1;
1648
1649 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1650 return 0;
1651
1652 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1653 WPA_IE_VENDOR_TYPE);
1654 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1655
1656 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1657 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1658 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1659 bss_rsn ? 2 + bss_rsn[1] : 0))
1660 return -1;
1661
1662 return 0;
1663}
1664
1665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001666static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1667 union wpa_event_data *data)
1668{
1669 u8 bssid[ETH_ALEN];
1670 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 struct wpa_driver_capa capa;
1672
1673#ifdef CONFIG_AP
1674 if (wpa_s->ap_iface) {
1675 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1676 data->assoc_info.addr,
1677 data->assoc_info.req_ies,
1678 data->assoc_info.req_ies_len,
1679 data->assoc_info.reassoc);
1680 return;
1681 }
1682#endif /* CONFIG_AP */
1683
1684 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1685 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1686 return;
1687
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001688 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1689 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001690 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001691 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1692 return;
1693 }
1694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001696 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1698 MACSTR, MAC2STR(bssid));
1699 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1701 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001702 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001703
1704 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1705 wpa_clear_keys(wpa_s, bssid);
1706 }
1707 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001708 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1710 return;
1711 }
1712 if (wpa_s->current_ssid) {
1713 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001714
1715 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1716 if (!bss) {
1717 wpa_supplicant_update_scan_results(wpa_s);
1718
1719 /* Get the BSS from the new scan results */
1720 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1721 }
1722
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723 if (bss)
1724 wpa_s->current_bss = bss;
1725 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001726
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001727#ifdef ANDROID
1728 if (wpa_s->conf->ap_scan == 1) {
1729#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001730 if (wpa_s->conf->ap_scan == 1 &&
1731 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001732#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001733 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1734 wpa_msg(wpa_s, MSG_WARNING,
1735 "WPA/RSN IEs not updated");
1736 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001737 }
1738
1739#ifdef CONFIG_SME
1740 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1741 wpa_s->sme.prev_bssid_set = 1;
1742#endif /* CONFIG_SME */
1743
1744 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1745 if (wpa_s->current_ssid) {
1746 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1747 * initialized before association, but for other modes,
1748 * initialize PC/SC here, if the current configuration needs
1749 * smartcard or SIM/USIM. */
1750 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1751 }
1752 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1753 if (wpa_s->l2)
1754 l2_packet_notify_auth_start(wpa_s->l2);
1755
1756 /*
1757 * Set portEnabled first to FALSE in order to get EAP state machine out
1758 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1759 * state machine may transit to AUTHENTICATING state based on obsolete
1760 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1761 * AUTHENTICATED without ever giving chance to EAP state machine to
1762 * reset the state.
1763 */
1764 if (!ft_completed) {
1765 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1766 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1767 }
1768 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1769 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1770 /* 802.1X::portControl = Auto */
1771 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1772 wpa_s->eapol_received = 0;
1773 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1774 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1775 (wpa_s->current_ssid &&
1776 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1777 wpa_supplicant_cancel_auth_timeout(wpa_s);
1778 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1779 } else if (!ft_completed) {
1780 /* Timeout for receiving the first EAPOL packet */
1781 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1782 }
1783 wpa_supplicant_cancel_scan(wpa_s);
1784
1785 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1786 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1787 /*
1788 * We are done; the driver will take care of RSN 4-way
1789 * handshake.
1790 */
1791 wpa_supplicant_cancel_auth_timeout(wpa_s);
1792 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1793 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1794 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1795 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1796 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1797 /*
1798 * The driver will take care of RSN 4-way handshake, so we need
1799 * to allow EAPOL supplicant to complete its work without
1800 * waiting for WPA supplicant.
1801 */
1802 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1803 } else if (ft_completed) {
1804 /*
1805 * FT protocol completed - make sure EAPOL state machine ends
1806 * up in authenticated.
1807 */
1808 wpa_supplicant_cancel_auth_timeout(wpa_s);
1809 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1810 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1811 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1812 }
1813
Jouni Malinena05074c2012-12-21 21:35:35 +02001814 wpa_s->last_eapol_matches_bssid = 0;
1815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816 if (wpa_s->pending_eapol_rx) {
1817 struct os_time now, age;
1818 os_get_time(&now);
1819 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1820 if (age.sec == 0 && age.usec < 100000 &&
1821 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1822 0) {
1823 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1824 "frame that was received just before "
1825 "association notification");
1826 wpa_supplicant_rx_eapol(
1827 wpa_s, wpa_s->pending_eapol_rx_src,
1828 wpabuf_head(wpa_s->pending_eapol_rx),
1829 wpabuf_len(wpa_s->pending_eapol_rx));
1830 }
1831 wpabuf_free(wpa_s->pending_eapol_rx);
1832 wpa_s->pending_eapol_rx = NULL;
1833 }
1834
1835 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1836 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1837 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1838 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1839 /* Set static WEP keys again */
1840 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1841 }
1842
1843#ifdef CONFIG_IBSS_RSN
1844 if (wpa_s->current_ssid &&
1845 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1846 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1847 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1848 wpa_s->ibss_rsn == NULL) {
1849 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1850 if (!wpa_s->ibss_rsn) {
1851 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1852 wpa_supplicant_deauthenticate(
1853 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1854 return;
1855 }
1856
1857 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1858 }
1859#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001860
1861 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001862}
1863
1864
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001865static int disconnect_reason_recoverable(u16 reason_code)
1866{
1867 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1868 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1869 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1870}
1871
1872
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001874 u16 reason_code,
1875 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001876{
1877 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001878
1879 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1880 /*
1881 * At least Host AP driver and a Prism3 card seemed to be
1882 * generating streams of disconnected events when configuring
1883 * IBSS for WPA-None. Ignore them for now.
1884 */
1885 return;
1886 }
1887
1888 bssid = wpa_s->bssid;
1889 if (is_zero_ether_addr(bssid))
1890 bssid = wpa_s->pending_bssid;
1891
1892 if (!is_zero_ether_addr(bssid) ||
1893 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1894 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1895 " reason=%d%s",
1896 MAC2STR(bssid), reason_code,
1897 locally_generated ? " locally_generated=1" : "");
1898 }
1899}
1900
1901
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001902static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1903 int locally_generated)
1904{
1905 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1906 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1907 return 0; /* Not in 4-way handshake with PSK */
1908
1909 /*
1910 * It looks like connection was lost while trying to go through PSK
1911 * 4-way handshake. Filter out known disconnection cases that are caused
1912 * by something else than PSK mismatch to avoid confusing reports.
1913 */
1914
1915 if (locally_generated) {
1916 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1917 return 0;
1918 }
1919
1920 return 1;
1921}
1922
1923
Jouni Malinen2b89da82012-08-31 22:04:41 +03001924static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1925 u16 reason_code,
1926 int locally_generated)
1927{
1928 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001929 int authenticating;
1930 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001931 struct wpa_bss *fast_reconnect = NULL;
1932 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001933 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934
1935 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1936 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1937
1938 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1939 /*
1940 * At least Host AP driver and a Prism3 card seemed to be
1941 * generating streams of disconnected events when configuring
1942 * IBSS for WPA-None. Ignore them for now.
1943 */
1944 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1945 "IBSS/WPA-None mode");
1946 return;
1947 }
1948
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001949 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001950 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1951 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001952 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001953 }
1954 if (!wpa_s->auto_reconnect_disabled ||
1955 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1957 "reconnect (wps=%d wpa_state=%d)",
1958 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1959 wpa_s->wpa_state);
1960 if (wpa_s->wpa_state == WPA_COMPLETED &&
1961 wpa_s->current_ssid &&
1962 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001963 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 disconnect_reason_recoverable(reason_code)) {
1965 /*
1966 * It looks like the AP has dropped association with
1967 * us, but could allow us to get back in. Try to
1968 * reconnect to the same BSS without full scan to save
1969 * time for some common cases.
1970 */
1971 fast_reconnect = wpa_s->current_bss;
1972 fast_reconnect_ssid = wpa_s->current_ssid;
1973 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001974#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001975 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001976#else
1977 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1978#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001979 else
1980 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1981 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001982 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001983 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001984 "try to re-connect");
1985 wpa_s->reassociate = 0;
1986 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001987 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001988 }
1989 bssid = wpa_s->bssid;
1990 if (is_zero_ether_addr(bssid))
1991 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001992 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1993 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001994 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001995 if (locally_generated)
1996 wpa_s->disconnect_reason = -reason_code;
1997 else
1998 wpa_s->disconnect_reason = reason_code;
1999 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2001 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2002 wpa_s->keys_cleared = 0;
2003 wpa_clear_keys(wpa_s, wpa_s->bssid);
2004 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002005 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002006 wpa_supplicant_mark_disassoc(wpa_s);
2007
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002008 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002010 wpa_s->current_ssid = last_ssid;
2011 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002012
2013 if (fast_reconnect) {
2014#ifndef CONFIG_NO_SCAN_PROCESSING
2015 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2016 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2017 fast_reconnect_ssid) < 0) {
2018 /* Recover through full scan */
2019 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2020 }
2021#endif /* CONFIG_NO_SCAN_PROCESSING */
2022 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023}
2024
2025
2026#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002027void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002028{
2029 struct wpa_supplicant *wpa_s = eloop_ctx;
2030
2031 if (!wpa_s->pending_mic_error_report)
2032 return;
2033
2034 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2035 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2036 wpa_s->pending_mic_error_report = 0;
2037}
2038#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2039
2040
2041static void
2042wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2043 union wpa_event_data *data)
2044{
2045 int pairwise;
2046 struct os_time t;
2047
2048 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2049 pairwise = (data && data->michael_mic_failure.unicast);
2050 os_get_time(&t);
2051 if ((wpa_s->last_michael_mic_error &&
2052 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2053 wpa_s->pending_mic_error_report) {
2054 if (wpa_s->pending_mic_error_report) {
2055 /*
2056 * Send the pending MIC error report immediately since
2057 * we are going to start countermeasures and AP better
2058 * do the same.
2059 */
2060 wpa_sm_key_request(wpa_s->wpa, 1,
2061 wpa_s->pending_mic_error_pairwise);
2062 }
2063
2064 /* Send the new MIC error report immediately since we are going
2065 * to start countermeasures and AP better do the same.
2066 */
2067 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2068
2069 /* initialize countermeasures */
2070 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002071
2072 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2075
2076 /*
2077 * Need to wait for completion of request frame. We do not get
2078 * any callback for the message completion, so just wait a
2079 * short while and hope for the best. */
2080 os_sleep(0, 10000);
2081
2082 wpa_drv_set_countermeasures(wpa_s, 1);
2083 wpa_supplicant_deauthenticate(wpa_s,
2084 WLAN_REASON_MICHAEL_MIC_FAILURE);
2085 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2086 wpa_s, NULL);
2087 eloop_register_timeout(60, 0,
2088 wpa_supplicant_stop_countermeasures,
2089 wpa_s, NULL);
2090 /* TODO: mark the AP rejected for 60 second. STA is
2091 * allowed to associate with another AP.. */
2092 } else {
2093#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2094 if (wpa_s->mic_errors_seen) {
2095 /*
2096 * Reduce the effectiveness of Michael MIC error
2097 * reports as a means for attacking against TKIP if
2098 * more than one MIC failure is noticed with the same
2099 * PTK. We delay the transmission of the reports by a
2100 * random time between 0 and 60 seconds in order to
2101 * force the attacker wait 60 seconds before getting
2102 * the information on whether a frame resulted in a MIC
2103 * failure.
2104 */
2105 u8 rval[4];
2106 int sec;
2107
2108 if (os_get_random(rval, sizeof(rval)) < 0)
2109 sec = os_random() % 60;
2110 else
2111 sec = WPA_GET_BE32(rval) % 60;
2112 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2113 "report %d seconds", sec);
2114 wpa_s->pending_mic_error_report = 1;
2115 wpa_s->pending_mic_error_pairwise = pairwise;
2116 eloop_cancel_timeout(
2117 wpa_supplicant_delayed_mic_error_report,
2118 wpa_s, NULL);
2119 eloop_register_timeout(
2120 sec, os_random() % 1000000,
2121 wpa_supplicant_delayed_mic_error_report,
2122 wpa_s, NULL);
2123 } else {
2124 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2125 }
2126#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2127 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2128#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2129 }
2130 wpa_s->last_michael_mic_error = t.sec;
2131 wpa_s->mic_errors_seen++;
2132}
2133
2134
2135#ifdef CONFIG_TERMINATE_ONLASTIF
2136static int any_interfaces(struct wpa_supplicant *head)
2137{
2138 struct wpa_supplicant *wpa_s;
2139
2140 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2141 if (!wpa_s->interface_removed)
2142 return 1;
2143 return 0;
2144}
2145#endif /* CONFIG_TERMINATE_ONLASTIF */
2146
2147
2148static void
2149wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2150 union wpa_event_data *data)
2151{
2152 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2153 return;
2154
2155 switch (data->interface_status.ievent) {
2156 case EVENT_INTERFACE_ADDED:
2157 if (!wpa_s->interface_removed)
2158 break;
2159 wpa_s->interface_removed = 0;
2160 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2161 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2162 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2163 "driver after interface was added");
2164 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002165 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002166 break;
2167 case EVENT_INTERFACE_REMOVED:
2168 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2169 wpa_s->interface_removed = 1;
2170 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002171 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172 l2_packet_deinit(wpa_s->l2);
2173 wpa_s->l2 = NULL;
2174#ifdef CONFIG_IBSS_RSN
2175 ibss_rsn_deinit(wpa_s->ibss_rsn);
2176 wpa_s->ibss_rsn = NULL;
2177#endif /* CONFIG_IBSS_RSN */
2178#ifdef CONFIG_TERMINATE_ONLASTIF
2179 /* check if last interface */
2180 if (!any_interfaces(wpa_s->global->ifaces))
2181 eloop_terminate();
2182#endif /* CONFIG_TERMINATE_ONLASTIF */
2183 break;
2184 }
2185}
2186
2187
2188#ifdef CONFIG_PEERKEY
2189static void
2190wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2191 union wpa_event_data *data)
2192{
2193 if (data == NULL)
2194 return;
2195 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2196}
2197#endif /* CONFIG_PEERKEY */
2198
2199
2200#ifdef CONFIG_TDLS
2201static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2202 union wpa_event_data *data)
2203{
2204 if (data == NULL)
2205 return;
2206 switch (data->tdls.oper) {
2207 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002208 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2209 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2210 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2211 else
2212 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002213 break;
2214 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002215 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002216 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 break;
2218 }
2219}
2220#endif /* CONFIG_TDLS */
2221
2222
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002223#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002224static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2225 union wpa_event_data *data)
2226{
2227 if (data == NULL)
2228 return;
2229 switch (data->wnm.oper) {
2230 case WNM_OPER_SLEEP:
2231 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2232 "(action=%d, intval=%d)",
2233 data->wnm.sleep_action, data->wnm.sleep_intval);
2234 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002235 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002236 break;
2237 }
2238}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002239#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002240
2241
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242#ifdef CONFIG_IEEE80211R
2243static void
2244wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2245 union wpa_event_data *data)
2246{
2247 if (data == NULL)
2248 return;
2249
2250 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2251 data->ft_ies.ies_len,
2252 data->ft_ies.ft_action,
2253 data->ft_ies.target_ap,
2254 data->ft_ies.ric_ies,
2255 data->ft_ies.ric_ies_len) < 0) {
2256 /* TODO: prevent MLME/driver from trying to associate? */
2257 }
2258}
2259#endif /* CONFIG_IEEE80211R */
2260
2261
2262#ifdef CONFIG_IBSS_RSN
2263static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2264 union wpa_event_data *data)
2265{
2266 struct wpa_ssid *ssid;
2267 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2268 return;
2269 if (data == NULL)
2270 return;
2271 ssid = wpa_s->current_ssid;
2272 if (ssid == NULL)
2273 return;
2274 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2275 return;
2276
2277 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2278}
2279#endif /* CONFIG_IBSS_RSN */
2280
2281
2282#ifdef CONFIG_IEEE80211R
2283static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2284 size_t len)
2285{
2286 const u8 *sta_addr, *target_ap_addr;
2287 u16 status;
2288
2289 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2290 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2291 return; /* only SME case supported for now */
2292 if (len < 1 + 2 * ETH_ALEN + 2)
2293 return;
2294 if (data[0] != 2)
2295 return; /* Only FT Action Response is supported for now */
2296 sta_addr = data + 1;
2297 target_ap_addr = data + 1 + ETH_ALEN;
2298 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2299 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2300 MACSTR " TargetAP " MACSTR " status %u",
2301 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2302
2303 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2304 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2305 " in FT Action Response", MAC2STR(sta_addr));
2306 return;
2307 }
2308
2309 if (status) {
2310 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2311 "failure (status code %d)", status);
2312 /* TODO: report error to FT code(?) */
2313 return;
2314 }
2315
2316 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2317 len - (1 + 2 * ETH_ALEN + 2), 1,
2318 target_ap_addr, NULL, 0) < 0)
2319 return;
2320
2321#ifdef CONFIG_SME
2322 {
2323 struct wpa_bss *bss;
2324 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2325 if (bss)
2326 wpa_s->sme.freq = bss->freq;
2327 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2328 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2329 WLAN_AUTH_FT);
2330 }
2331#endif /* CONFIG_SME */
2332}
2333#endif /* CONFIG_IEEE80211R */
2334
2335
2336static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2337 struct unprot_deauth *e)
2338{
2339#ifdef CONFIG_IEEE80211W
2340 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2341 "dropped: " MACSTR " -> " MACSTR
2342 " (reason code %u)",
2343 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2344 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2345#endif /* CONFIG_IEEE80211W */
2346}
2347
2348
2349static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2350 struct unprot_disassoc *e)
2351{
2352#ifdef CONFIG_IEEE80211W
2353 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2354 "dropped: " MACSTR " -> " MACSTR
2355 " (reason code %u)",
2356 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2357 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2358#endif /* CONFIG_IEEE80211W */
2359}
2360
2361
2362void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2363 union wpa_event_data *data)
2364{
2365 struct wpa_supplicant *wpa_s = ctx;
2366 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002367 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368
2369 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2370 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002371 event != EVENT_INTERFACE_STATUS &&
2372 event != EVENT_SCHED_SCAN_STOPPED) {
2373 wpa_dbg(wpa_s, MSG_DEBUG,
2374 "Ignore event %s (%d) while interface is disabled",
2375 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376 return;
2377 }
2378
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002379#ifndef CONFIG_NO_STDOUT_DEBUG
2380{
2381 int level = MSG_DEBUG;
2382
Dmitry Shmidt04949592012-07-19 12:16:46 -07002383 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002384 const struct ieee80211_hdr *hdr;
2385 u16 fc;
2386 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2387 fc = le_to_host16(hdr->frame_control);
2388 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2389 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2390 level = MSG_EXCESSIVE;
2391 }
2392
2393 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2394 event_to_string(event), event);
2395}
2396#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397
2398 switch (event) {
2399 case EVENT_AUTH:
2400 sme_event_auth(wpa_s, data);
2401 break;
2402 case EVENT_ASSOC:
2403 wpa_supplicant_event_assoc(wpa_s, data);
2404 break;
2405 case EVENT_DISASSOC:
2406 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2407 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002408 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2409 data->disassoc_info.reason_code,
2410 data->disassoc_info.locally_generated ?
2411 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 if (data->disassoc_info.addr)
2413 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2414 MAC2STR(data->disassoc_info.addr));
2415 }
2416#ifdef CONFIG_AP
2417 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2418 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2419 data->disassoc_info.addr);
2420 break;
2421 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002422 if (wpa_s->ap_iface) {
2423 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2424 "AP mode");
2425 break;
2426 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427#endif /* CONFIG_AP */
2428 if (data) {
2429 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002430 locally_generated =
2431 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002432 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2433 data->disassoc_info.ie,
2434 data->disassoc_info.ie_len);
2435#ifdef CONFIG_P2P
2436 wpas_p2p_disassoc_notif(
2437 wpa_s, data->disassoc_info.addr, reason_code,
2438 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002439 data->disassoc_info.ie_len,
2440 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002441#endif /* CONFIG_P2P */
2442 }
2443 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2444 sme_event_disassoc(wpa_s, data);
2445 /* fall through */
2446 case EVENT_DEAUTH:
2447 if (event == EVENT_DEAUTH) {
2448 wpa_dbg(wpa_s, MSG_DEBUG,
2449 "Deauthentication notification");
2450 if (data) {
2451 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002452 locally_generated =
2453 data->deauth_info.locally_generated;
2454 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2455 data->deauth_info.reason_code,
2456 data->deauth_info.locally_generated ?
2457 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002458 if (data->deauth_info.addr) {
2459 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2460 MACSTR,
2461 MAC2STR(data->deauth_info.
2462 addr));
2463 }
2464 wpa_hexdump(MSG_DEBUG,
2465 "Deauthentication frame IE(s)",
2466 data->deauth_info.ie,
2467 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 }
2469 }
2470#ifdef CONFIG_AP
2471 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2472 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2473 data->deauth_info.addr);
2474 break;
2475 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002476 if (wpa_s->ap_iface) {
2477 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2478 "AP mode");
2479 break;
2480 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002481#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002482 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2483 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002484 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2485 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2486 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2487 eapol_sm_failed(wpa_s->eapol)))
2488 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002489#ifdef CONFIG_P2P
2490 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002491 if (wpas_p2p_deauth_notif(wpa_s,
2492 data->deauth_info.addr,
2493 reason_code,
2494 data->deauth_info.ie,
2495 data->deauth_info.ie_len,
2496 locally_generated) > 0) {
2497 /*
2498 * The interface was removed, so cannot
2499 * continue processing any additional
2500 * operations after this.
2501 */
2502 break;
2503 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002504 }
2505#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002506 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2507 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 break;
2509 case EVENT_MICHAEL_MIC_FAILURE:
2510 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2511 break;
2512#ifndef CONFIG_NO_SCAN_PROCESSING
2513 case EVENT_SCAN_RESULTS:
2514 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002515#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07002516 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002517 wpa_s->global->p2p != NULL &&
2518 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2519 wpa_s->wpa_state != WPA_ASSOCIATING) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07002520 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002521 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2522 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2523 "continued after scan result processing");
2524 }
2525 }
2526#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002527 break;
2528#endif /* CONFIG_NO_SCAN_PROCESSING */
2529 case EVENT_ASSOCINFO:
2530 wpa_supplicant_event_associnfo(wpa_s, data);
2531 break;
2532 case EVENT_INTERFACE_STATUS:
2533 wpa_supplicant_event_interface_status(wpa_s, data);
2534 break;
2535 case EVENT_PMKID_CANDIDATE:
2536 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2537 break;
2538#ifdef CONFIG_PEERKEY
2539 case EVENT_STKSTART:
2540 wpa_supplicant_event_stkstart(wpa_s, data);
2541 break;
2542#endif /* CONFIG_PEERKEY */
2543#ifdef CONFIG_TDLS
2544 case EVENT_TDLS:
2545 wpa_supplicant_event_tdls(wpa_s, data);
2546 break;
2547#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002548#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002549 case EVENT_WNM:
2550 wpa_supplicant_event_wnm(wpa_s, data);
2551 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002552#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002553#ifdef CONFIG_IEEE80211R
2554 case EVENT_FT_RESPONSE:
2555 wpa_supplicant_event_ft_response(wpa_s, data);
2556 break;
2557#endif /* CONFIG_IEEE80211R */
2558#ifdef CONFIG_IBSS_RSN
2559 case EVENT_IBSS_RSN_START:
2560 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2561 break;
2562#endif /* CONFIG_IBSS_RSN */
2563 case EVENT_ASSOC_REJECT:
2564 if (data->assoc_reject.bssid)
2565 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2566 "bssid=" MACSTR " status_code=%u",
2567 MAC2STR(data->assoc_reject.bssid),
2568 data->assoc_reject.status_code);
2569 else
2570 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2571 "status_code=%u",
2572 data->assoc_reject.status_code);
2573 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2574 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002575 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002576#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002577 if(!wpa_s->current_ssid) {
2578 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2579 break;
2580 }
2581 /* If assoc reject is reported by the driver, then avoid
2582 * waiting for the authentication timeout. Cancel the
2583 * authentication timeout and retry the assoc.
2584 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002585 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002586 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2587 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002588
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002589 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002590
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002591 /* Clear the states */
2592 wpa_sm_notify_disassoc(wpa_s->wpa);
2593 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2594
2595 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002596 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002597 const u8 *bl_bssid = data->assoc_reject.bssid;
2598 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2599 bl_bssid = wpa_s->pending_bssid;
2600 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002601 wpa_supplicant_req_scan(wpa_s, 0, 0);
2602 } else {
2603 wpa_supplicant_req_scan(wpa_s, 1, 0);
2604 }
2605 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002606 /* If we ASSOC_REJECT's hits threshold, disable the
2607 * network
2608 */
2609 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2610 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002611 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002612 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002613 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002614 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002615#else
2616 const u8 *bssid = data->assoc_reject.bssid;
2617 if (bssid == NULL || is_zero_ether_addr(bssid))
2618 bssid = wpa_s->pending_bssid;
2619 wpas_connection_failed(wpa_s, bssid);
2620 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002621#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002622 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002623 break;
2624 case EVENT_AUTH_TIMED_OUT:
2625 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2626 sme_event_auth_timed_out(wpa_s, data);
2627 break;
2628 case EVENT_ASSOC_TIMED_OUT:
2629 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2630 sme_event_assoc_timed_out(wpa_s, data);
2631 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002632 case EVENT_TX_STATUS:
2633 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2634 " type=%d stype=%d",
2635 MAC2STR(data->tx_status.dst),
2636 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002637#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002639#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002640 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2641 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002642 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002643 wpa_s, data->tx_status.dst,
2644 data->tx_status.data,
2645 data->tx_status.data_len,
2646 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002647 OFFCHANNEL_SEND_ACTION_SUCCESS :
2648 OFFCHANNEL_SEND_ACTION_NO_ACK);
2649#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650 break;
2651 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002652#endif /* CONFIG_AP */
2653#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002654 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2655 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2656 /*
2657 * Catch TX status events for Action frames we sent via group
2658 * interface in GO mode.
2659 */
2660 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2661 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2662 os_memcmp(wpa_s->parent->pending_action_dst,
2663 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002664 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665 wpa_s->parent, data->tx_status.dst,
2666 data->tx_status.data,
2667 data->tx_status.data_len,
2668 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002669 OFFCHANNEL_SEND_ACTION_SUCCESS :
2670 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002671 break;
2672 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002673#endif /* CONFIG_OFFCHANNEL */
2674#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675 switch (data->tx_status.type) {
2676 case WLAN_FC_TYPE_MGMT:
2677 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2678 data->tx_status.data_len,
2679 data->tx_status.stype,
2680 data->tx_status.ack);
2681 break;
2682 case WLAN_FC_TYPE_DATA:
2683 ap_tx_status(wpa_s, data->tx_status.dst,
2684 data->tx_status.data,
2685 data->tx_status.data_len,
2686 data->tx_status.ack);
2687 break;
2688 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002689#endif /* CONFIG_AP */
2690 break;
2691#ifdef CONFIG_AP
2692 case EVENT_EAPOL_TX_STATUS:
2693 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2694 data->eapol_tx_status.data,
2695 data->eapol_tx_status.data_len,
2696 data->eapol_tx_status.ack);
2697 break;
2698 case EVENT_DRIVER_CLIENT_POLL_OK:
2699 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700 break;
2701 case EVENT_RX_FROM_UNKNOWN:
2702 if (wpa_s->ap_iface == NULL)
2703 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002704 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2705 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002706 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002707 case EVENT_CH_SWITCH:
2708 if (!data)
2709 break;
2710 if (!wpa_s->ap_iface) {
2711 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2712 "event in non-AP mode");
2713 break;
2714 }
2715
2716#ifdef CONFIG_AP
2717 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2718 data->ch_switch.ht_enabled,
2719 data->ch_switch.ch_offset);
2720#endif /* CONFIG_AP */
2721 break;
2722 case EVENT_RX_MGMT: {
2723 u16 fc, stype;
2724 const struct ieee80211_mgmt *mgmt;
2725
2726 mgmt = (const struct ieee80211_mgmt *)
2727 data->rx_mgmt.frame;
2728 fc = le_to_host16(mgmt->frame_control);
2729 stype = WLAN_FC_GET_STYPE(fc);
2730
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002731 if (wpa_s->ap_iface == NULL) {
2732#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2734 data->rx_mgmt.frame_len > 24) {
2735 const u8 *src = mgmt->sa;
2736 const u8 *ie = mgmt->u.probe_req.variable;
2737 size_t ie_len = data->rx_mgmt.frame_len -
2738 (mgmt->u.probe_req.variable -
2739 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002740 wpas_p2p_probe_req_rx(
2741 wpa_s, src, mgmt->da,
2742 mgmt->bssid, ie, ie_len,
2743 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002744 break;
2745 }
2746#endif /* CONFIG_P2P */
2747 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2748 "management frame in non-AP mode");
2749 break;
2750 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002751
2752 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2753 data->rx_mgmt.frame_len > 24) {
2754 const u8 *ie = mgmt->u.probe_req.variable;
2755 size_t ie_len = data->rx_mgmt.frame_len -
2756 (mgmt->u.probe_req.variable -
2757 data->rx_mgmt.frame);
2758
2759 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2760 mgmt->bssid, ie, ie_len,
2761 data->rx_mgmt.ssi_signal);
2762 }
2763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2765 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002766 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002767#endif /* CONFIG_AP */
2768 case EVENT_RX_ACTION:
2769 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2770 " Category=%u DataLen=%d freq=%d MHz",
2771 MAC2STR(data->rx_action.sa),
2772 data->rx_action.category, (int) data->rx_action.len,
2773 data->rx_action.freq);
2774#ifdef CONFIG_IEEE80211R
2775 if (data->rx_action.category == WLAN_ACTION_FT) {
2776 ft_rx_action(wpa_s, data->rx_action.data,
2777 data->rx_action.len);
2778 break;
2779 }
2780#endif /* CONFIG_IEEE80211R */
2781#ifdef CONFIG_IEEE80211W
2782#ifdef CONFIG_SME
2783 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2784 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2785 data->rx_action.data,
2786 data->rx_action.len);
2787 break;
2788 }
2789#endif /* CONFIG_SME */
2790#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002791#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002792 if (data->rx_action.category == WLAN_ACTION_WNM) {
2793 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2794 break;
2795 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002796#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002797#ifdef CONFIG_GAS
2798 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2799 gas_query_rx(wpa_s->gas, data->rx_action.da,
2800 data->rx_action.sa, data->rx_action.bssid,
2801 data->rx_action.data, data->rx_action.len,
2802 data->rx_action.freq) == 0)
2803 break;
2804#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002805#ifdef CONFIG_TDLS
2806 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2807 data->rx_action.len >= 4 &&
2808 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2809 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2810 "Response from " MACSTR,
2811 MAC2STR(data->rx_action.sa));
2812 break;
2813 }
2814#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815#ifdef CONFIG_P2P
2816 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2817 data->rx_action.sa,
2818 data->rx_action.bssid,
2819 data->rx_action.category,
2820 data->rx_action.data,
2821 data->rx_action.len, data->rx_action.freq);
2822#endif /* CONFIG_P2P */
2823 break;
2824 case EVENT_RX_PROBE_REQ:
2825 if (data->rx_probe_req.sa == NULL ||
2826 data->rx_probe_req.ie == NULL)
2827 break;
2828#ifdef CONFIG_AP
2829 if (wpa_s->ap_iface) {
2830 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2831 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002832 data->rx_probe_req.da,
2833 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002834 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002835 data->rx_probe_req.ie_len,
2836 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 break;
2838 }
2839#endif /* CONFIG_AP */
2840#ifdef CONFIG_P2P
2841 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002842 data->rx_probe_req.da,
2843 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002845 data->rx_probe_req.ie_len,
2846 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002847#endif /* CONFIG_P2P */
2848 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002849 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002850#ifdef CONFIG_OFFCHANNEL
2851 offchannel_remain_on_channel_cb(
2852 wpa_s, data->remain_on_channel.freq,
2853 data->remain_on_channel.duration);
2854#endif /* CONFIG_OFFCHANNEL */
2855#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002856 wpas_p2p_remain_on_channel_cb(
2857 wpa_s, data->remain_on_channel.freq,
2858 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002859#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860 break;
2861 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002862#ifdef CONFIG_OFFCHANNEL
2863 offchannel_cancel_remain_on_channel_cb(
2864 wpa_s, data->remain_on_channel.freq);
2865#endif /* CONFIG_OFFCHANNEL */
2866#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867 wpas_p2p_cancel_remain_on_channel_cb(
2868 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002869#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002871#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 case EVENT_P2P_DEV_FOUND: {
2873 struct p2p_peer_info peer_info;
2874
2875 os_memset(&peer_info, 0, sizeof(peer_info));
2876 if (data->p2p_dev_found.dev_addr)
2877 os_memcpy(peer_info.p2p_device_addr,
2878 data->p2p_dev_found.dev_addr, ETH_ALEN);
2879 if (data->p2p_dev_found.pri_dev_type)
2880 os_memcpy(peer_info.pri_dev_type,
2881 data->p2p_dev_found.pri_dev_type,
2882 sizeof(peer_info.pri_dev_type));
2883 if (data->p2p_dev_found.dev_name)
2884 os_strlcpy(peer_info.device_name,
2885 data->p2p_dev_found.dev_name,
2886 sizeof(peer_info.device_name));
2887 peer_info.config_methods = data->p2p_dev_found.config_methods;
2888 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2889 peer_info.group_capab = data->p2p_dev_found.group_capab;
2890
2891 /*
2892 * FIX: new_device=1 is not necessarily correct. We should
2893 * maintain a P2P peer database in wpa_supplicant and update
2894 * this information based on whether the peer is truly new.
2895 */
2896 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2897 break;
2898 }
2899 case EVENT_P2P_GO_NEG_REQ_RX:
2900 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2901 data->p2p_go_neg_req_rx.dev_passwd_id);
2902 break;
2903 case EVENT_P2P_GO_NEG_COMPLETED:
2904 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2905 break;
2906 case EVENT_P2P_PROV_DISC_REQUEST:
2907 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2908 data->p2p_prov_disc_req.config_methods,
2909 data->p2p_prov_disc_req.dev_addr,
2910 data->p2p_prov_disc_req.pri_dev_type,
2911 data->p2p_prov_disc_req.dev_name,
2912 data->p2p_prov_disc_req.supp_config_methods,
2913 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002914 data->p2p_prov_disc_req.group_capab,
2915 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002916 break;
2917 case EVENT_P2P_PROV_DISC_RESPONSE:
2918 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2919 data->p2p_prov_disc_resp.config_methods);
2920 break;
2921 case EVENT_P2P_SD_REQUEST:
2922 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2923 data->p2p_sd_req.sa,
2924 data->p2p_sd_req.dialog_token,
2925 data->p2p_sd_req.update_indic,
2926 data->p2p_sd_req.tlvs,
2927 data->p2p_sd_req.tlvs_len);
2928 break;
2929 case EVENT_P2P_SD_RESPONSE:
2930 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2931 data->p2p_sd_resp.update_indic,
2932 data->p2p_sd_resp.tlvs,
2933 data->p2p_sd_resp.tlvs_len);
2934 break;
2935#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002936 case EVENT_EAPOL_RX:
2937 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2938 data->eapol_rx.data,
2939 data->eapol_rx.data_len);
2940 break;
2941 case EVENT_SIGNAL_CHANGE:
2942 bgscan_notify_signal_change(
2943 wpa_s, data->signal_change.above_threshold,
2944 data->signal_change.current_signal,
2945 data->signal_change.current_noise,
2946 data->signal_change.current_txrate);
2947 break;
2948 case EVENT_INTERFACE_ENABLED:
2949 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2950 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002951 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002952#ifdef CONFIG_AP
2953 if (!wpa_s->ap_iface) {
2954 wpa_supplicant_set_state(wpa_s,
2955 WPA_DISCONNECTED);
2956 wpa_supplicant_req_scan(wpa_s, 0, 0);
2957 } else
2958 wpa_supplicant_set_state(wpa_s,
2959 WPA_COMPLETED);
2960#else /* CONFIG_AP */
2961 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2962 wpa_supplicant_req_scan(wpa_s, 0, 0);
2963#endif /* CONFIG_AP */
2964 }
2965 break;
2966 case EVENT_INTERFACE_DISABLED:
2967 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2968 wpa_supplicant_mark_disassoc(wpa_s);
2969 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2970 break;
2971 case EVENT_CHANNEL_LIST_CHANGED:
2972 if (wpa_s->drv_priv == NULL)
2973 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002974
2975 free_hw_features(wpa_s);
2976 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2977 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002979#ifdef CONFIG_P2P
2980 wpas_p2p_update_channel_list(wpa_s);
2981#endif /* CONFIG_P2P */
2982 break;
2983 case EVENT_INTERFACE_UNAVAILABLE:
2984#ifdef CONFIG_P2P
2985 wpas_p2p_interface_unavailable(wpa_s);
2986#endif /* CONFIG_P2P */
2987 break;
2988 case EVENT_BEST_CHANNEL:
2989 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2990 "(%d %d %d)",
2991 data->best_chan.freq_24, data->best_chan.freq_5,
2992 data->best_chan.freq_overall);
2993 wpa_s->best_24_freq = data->best_chan.freq_24;
2994 wpa_s->best_5_freq = data->best_chan.freq_5;
2995 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2996#ifdef CONFIG_P2P
2997 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2998 data->best_chan.freq_5,
2999 data->best_chan.freq_overall);
3000#endif /* CONFIG_P2P */
3001 break;
3002 case EVENT_UNPROT_DEAUTH:
3003 wpa_supplicant_event_unprot_deauth(wpa_s,
3004 &data->unprot_deauth);
3005 break;
3006 case EVENT_UNPROT_DISASSOC:
3007 wpa_supplicant_event_unprot_disassoc(wpa_s,
3008 &data->unprot_disassoc);
3009 break;
3010 case EVENT_STATION_LOW_ACK:
3011#ifdef CONFIG_AP
3012 if (wpa_s->ap_iface && data)
3013 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3014 data->low_ack.addr);
3015#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003016#ifdef CONFIG_TDLS
3017 if (data)
3018 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3019#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003020 break;
3021 case EVENT_IBSS_PEER_LOST:
3022#ifdef CONFIG_IBSS_RSN
3023 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3024#endif /* CONFIG_IBSS_RSN */
3025 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003026 case EVENT_DRIVER_GTK_REKEY:
3027 if (os_memcmp(data->driver_gtk_rekey.bssid,
3028 wpa_s->bssid, ETH_ALEN))
3029 break;
3030 if (!wpa_s->wpa)
3031 break;
3032 wpa_sm_update_replay_ctr(wpa_s->wpa,
3033 data->driver_gtk_rekey.replay_ctr);
3034 break;
3035 case EVENT_SCHED_SCAN_STOPPED:
3036 wpa_s->sched_scanning = 0;
3037 wpa_supplicant_notify_scanning(wpa_s, 0);
3038
3039 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3040 break;
3041
3042 /*
3043 * If we timed out, start a new sched scan to continue
3044 * searching for more SSIDs.
3045 */
3046 if (wpa_s->sched_scan_timed_out)
3047 wpa_supplicant_req_sched_scan(wpa_s);
3048 break;
3049 case EVENT_WPS_BUTTON_PUSHED:
3050#ifdef CONFIG_WPS
3051 wpas_wps_start_pbc(wpa_s, NULL, 0);
3052#endif /* CONFIG_WPS */
3053 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003054 default:
3055 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3056 break;
3057 }
3058}