blob: 3fefb48d865b4cd8442ebe79644e27ab6539f91e [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
47static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
49{
50 struct os_time now;
51
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
53 return 0;
54
55 os_get_time(&now);
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
58
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
60
61 return 0;
62}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
64
65static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
66{
67 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070068 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
71 return 0;
72
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
74 "information");
75 ssid = wpa_supplicant_get_ssid(wpa_s);
76 if (ssid == NULL) {
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
79 return -1;
80 }
81
Dmitry Shmidt04949592012-07-19 12:16:46 -070082 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
84 return -1;
85 }
86
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080087 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
88 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
90 return -1;
91 }
92
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070093 res = wpas_temp_disabled(wpa_s, ssid);
94 if (res > 0) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
96 "disabled for %d second(s)", res);
97 return -1;
98 }
99
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
101 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800102 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 u8 wpa_ie[80];
104 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800105 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
106 wpa_ie, &wpa_ie_len) < 0)
107 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 } else {
109 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
110 }
111
112 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
113 eapol_sm_invalidate_cached_session(wpa_s->eapol);
114 old_ssid = wpa_s->current_ssid;
115 wpa_s->current_ssid = ssid;
116 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
117 wpa_supplicant_initiate_eapol(wpa_s);
118 if (old_ssid != wpa_s->current_ssid)
119 wpas_notify_network_changed(wpa_s);
120
121 return 0;
122}
123
124
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800125void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700126{
127 struct wpa_supplicant *wpa_s = eloop_ctx;
128
129 if (wpa_s->countermeasures) {
130 wpa_s->countermeasures = 0;
131 wpa_drv_set_countermeasures(wpa_s, 0);
132 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
133 wpa_supplicant_req_scan(wpa_s, 0, 0);
134 }
135}
136
137
138void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
139{
140 int bssid_changed;
141
Dmitry Shmidt04949592012-07-19 12:16:46 -0700142 wnm_bss_keep_alive_deinit(wpa_s);
143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700144#ifdef CONFIG_IBSS_RSN
145 ibss_rsn_deinit(wpa_s->ibss_rsn);
146 wpa_s->ibss_rsn = NULL;
147#endif /* CONFIG_IBSS_RSN */
148
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700149#ifdef CONFIG_AP
150 wpa_supplicant_ap_deinit(wpa_s);
151#endif /* CONFIG_AP */
152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
154 return;
155
156 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800157#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700158 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800159#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
161 os_memset(wpa_s->bssid, 0, ETH_ALEN);
162 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700163#ifdef CONFIG_SME
164 wpa_s->sme.prev_bssid_set = 0;
165#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800166#ifdef CONFIG_P2P
167 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
168#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 wpa_s->current_bss = NULL;
170 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700171#ifdef CONFIG_IEEE80211R
172#ifdef CONFIG_SME
173 if (wpa_s->sme.ft_ies)
174 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
175#endif /* CONFIG_SME */
176#endif /* CONFIG_IEEE80211R */
177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 if (bssid_changed)
179 wpas_notify_bssid_changed(wpa_s);
180
181 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
182 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
183 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
184 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
185 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700186 wpa_s->current_ssid = NULL;
187 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188}
189
190
191static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
192{
193 struct wpa_ie_data ie;
194 int pmksa_set = -1;
195 size_t i;
196
197 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
198 ie.pmkid == NULL)
199 return;
200
201 for (i = 0; i < ie.num_pmkid; i++) {
202 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
203 ie.pmkid + i * PMKID_LEN,
204 NULL, NULL, 0);
205 if (pmksa_set == 0) {
206 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
207 break;
208 }
209 }
210
211 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
212 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
213}
214
215
216static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
217 union wpa_event_data *data)
218{
219 if (data == NULL) {
220 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
221 "event");
222 return;
223 }
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
225 " index=%d preauth=%d",
226 MAC2STR(data->pmkid_candidate.bssid),
227 data->pmkid_candidate.index,
228 data->pmkid_candidate.preauth);
229
230 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
233}
234
235
236static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
237{
238 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
239 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
240 return 0;
241
242#ifdef IEEE8021X_EAPOL
243 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
244 wpa_s->current_ssid &&
245 !(wpa_s->current_ssid->eapol_flags &
246 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
247 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
248 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
249 * plaintext or static WEP keys). */
250 return 0;
251 }
252#endif /* IEEE8021X_EAPOL */
253
254 return 1;
255}
256
257
258/**
259 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
260 * @wpa_s: pointer to wpa_supplicant data
261 * @ssid: Configuration data for the network
262 * Returns: 0 on success, -1 on failure
263 *
264 * This function is called when starting authentication with a network that is
265 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
266 */
267int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
268 struct wpa_ssid *ssid)
269{
270#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800271#ifdef PCSC_FUNCS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 int aka = 0, sim = 0, type;
273
274 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
275 return 0;
276
277 if (ssid->eap.eap_methods == NULL) {
278 sim = 1;
279 aka = 1;
280 } else {
281 struct eap_method_type *eap = ssid->eap.eap_methods;
282 while (eap->vendor != EAP_VENDOR_IETF ||
283 eap->method != EAP_TYPE_NONE) {
284 if (eap->vendor == EAP_VENDOR_IETF) {
285 if (eap->method == EAP_TYPE_SIM)
286 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700287 else if (eap->method == EAP_TYPE_AKA ||
288 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 aka = 1;
290 }
291 eap++;
292 }
293 }
294
295 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
296 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700297 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
298 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
299 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 aka = 0;
301
302 if (!sim && !aka) {
303 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
304 "use SIM, but neither EAP-SIM nor EAP-AKA are "
305 "enabled");
306 return 0;
307 }
308
309 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
310 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
311 if (sim && aka)
312 type = SCARD_TRY_BOTH;
313 else if (aka)
314 type = SCARD_USIM_ONLY;
315 else
316 type = SCARD_GSM_SIM_ONLY;
317
Dmitry Shmidt04949592012-07-19 12:16:46 -0700318 wpa_s->scard = scard_init(type, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 if (wpa_s->scard == NULL) {
320 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
321 "(pcsc-lite)");
322 return -1;
323 }
324 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
325 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800326#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327#endif /* IEEE8021X_EAPOL */
328
329 return 0;
330}
331
332
333#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700334static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 struct wpa_ssid *ssid)
336{
337 int i, privacy = 0;
338
339 if (ssid->mixed_cell)
340 return 1;
341
342#ifdef CONFIG_WPS
343 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
344 return 1;
345#endif /* CONFIG_WPS */
346
347 for (i = 0; i < NUM_WEP_KEYS; i++) {
348 if (ssid->wep_key_len[i]) {
349 privacy = 1;
350 break;
351 }
352 }
353#ifdef IEEE8021X_EAPOL
354 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
355 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
356 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
357 privacy = 1;
358#endif /* IEEE8021X_EAPOL */
359
Jouni Malinen75ecf522011-06-27 15:19:46 -0700360 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
361 privacy = 1;
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 if (bss->caps & IEEE80211_CAP_PRIVACY)
364 return privacy;
365 return !privacy;
366}
367
368
369static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
370 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700371 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372{
373 struct wpa_ie_data ie;
374 int proto_match = 0;
375 const u8 *rsn_ie, *wpa_ie;
376 int ret;
377 int wep_ok;
378
379 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
380 if (ret >= 0)
381 return ret;
382
383 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
384 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
385 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
386 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
387 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
388
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700389 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
391 proto_match++;
392
393 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
394 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
395 "failed");
396 break;
397 }
398
399 if (wep_ok &&
400 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
401 {
402 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
403 "in RSN IE");
404 return 1;
405 }
406
407 if (!(ie.proto & ssid->proto)) {
408 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
409 "mismatch");
410 break;
411 }
412
413 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
414 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
415 "cipher mismatch");
416 break;
417 }
418
419 if (!(ie.group_cipher & ssid->group_cipher)) {
420 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
421 "cipher mismatch");
422 break;
423 }
424
425 if (!(ie.key_mgmt & ssid->key_mgmt)) {
426 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
427 "mismatch");
428 break;
429 }
430
431#ifdef CONFIG_IEEE80211W
432 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800433 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
434 wpa_s->conf->pmf : ssid->ieee80211w) ==
435 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
437 "frame protection");
438 break;
439 }
440#endif /* CONFIG_IEEE80211W */
441
442 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
443 return 1;
444 }
445
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700446 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
448 proto_match++;
449
450 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
451 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
452 "failed");
453 break;
454 }
455
456 if (wep_ok &&
457 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
458 {
459 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
460 "in WPA IE");
461 return 1;
462 }
463
464 if (!(ie.proto & ssid->proto)) {
465 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
466 "mismatch");
467 break;
468 }
469
470 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
471 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
472 "cipher mismatch");
473 break;
474 }
475
476 if (!(ie.group_cipher & ssid->group_cipher)) {
477 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
478 "cipher mismatch");
479 break;
480 }
481
482 if (!(ie.key_mgmt & ssid->key_mgmt)) {
483 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
484 "mismatch");
485 break;
486 }
487
488 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
489 return 1;
490 }
491
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700492 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
493 !rsn_ie) {
494 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
495 return 1;
496 }
497
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
499 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
500 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
501 return 0;
502 }
503
504 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
505 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
506 return 1;
507 }
508
509 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
510 "WPA/WPA2");
511
512 return 0;
513}
514
515
516static int freq_allowed(int *freqs, int freq)
517{
518 int i;
519
520 if (freqs == NULL)
521 return 1;
522
523 for (i = 0; freqs[i]; i++)
524 if (freqs[i] == freq)
525 return 1;
526 return 0;
527}
528
529
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800530static int ht_supported(const struct hostapd_hw_modes *mode)
531{
532 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
533 /*
534 * The driver did not indicate whether it supports HT. Assume
535 * it does to avoid connection issues.
536 */
537 return 1;
538 }
539
540 /*
541 * IEEE Std 802.11n-2009 20.1.1:
542 * An HT non-AP STA shall support all EQM rates for one spatial stream.
543 */
544 return mode->mcs_set[0] == 0xff;
545}
546
547
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700548static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800549{
550 const struct hostapd_hw_modes *mode = NULL, *modes;
551 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
552 const u8 *rate_ie;
553 int i, j, k;
554
555 if (bss->freq == 0)
556 return 1; /* Cannot do matching without knowing band */
557
558 modes = wpa_s->hw.modes;
559 if (modes == NULL) {
560 /*
561 * The driver does not provide any additional information
562 * about the utilized hardware, so allow the connection attempt
563 * to continue.
564 */
565 return 1;
566 }
567
568 for (i = 0; i < wpa_s->hw.num_modes; i++) {
569 for (j = 0; j < modes[i].num_channels; j++) {
570 int freq = modes[i].channels[j].freq;
571 if (freq == bss->freq) {
572 if (mode &&
573 mode->mode == HOSTAPD_MODE_IEEE80211G)
574 break; /* do not allow 802.11b replace
575 * 802.11g */
576 mode = &modes[i];
577 break;
578 }
579 }
580 }
581
582 if (mode == NULL)
583 return 0;
584
585 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700586 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587 if (rate_ie == NULL)
588 continue;
589
590 for (j = 2; j < rate_ie[1] + 2; j++) {
591 int flagged = !!(rate_ie[j] & 0x80);
592 int r = (rate_ie[j] & 0x7f) * 5;
593
594 /*
595 * IEEE Std 802.11n-2009 7.3.2.2:
596 * The new BSS Membership selector value is encoded
597 * like a legacy basic rate, but it is not a rate and
598 * only indicates if the BSS members are required to
599 * support the mandatory features of Clause 20 [HT PHY]
600 * in order to join the BSS.
601 */
602 if (flagged && ((rate_ie[j] & 0x7f) ==
603 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
604 if (!ht_supported(mode)) {
605 wpa_dbg(wpa_s, MSG_DEBUG,
606 " hardware does not support "
607 "HT PHY");
608 return 0;
609 }
610 continue;
611 }
612
613 if (!flagged)
614 continue;
615
616 /* check for legacy basic rates */
617 for (k = 0; k < mode->num_rates; k++) {
618 if (mode->rates[k] == r)
619 break;
620 }
621 if (k == mode->num_rates) {
622 /*
623 * IEEE Std 802.11-2007 7.3.2.2 demands that in
624 * order to join a BSS all required rates
625 * have to be supported by the hardware.
626 */
627 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
628 "not support required rate %d.%d Mbps",
629 r / 10, r % 10);
630 return 0;
631 }
632 }
633 }
634
635 return 1;
636}
637
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700640 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641 struct wpa_ssid *group)
642{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700643 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 int wpa;
645 struct wpa_blacklist *e;
646 const u8 *ie;
647 struct wpa_ssid *ssid;
648
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700649 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650 wpa_ie_len = ie ? ie[1] : 0;
651
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700652 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 rsn_ie_len = ie ? ie[1] : 0;
654
655 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
656 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700657 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700659 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660
661 e = wpa_blacklist_get(wpa_s, bss->bssid);
662 if (e) {
663 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700664 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665 /*
666 * When only a single network is enabled, we can
667 * trigger blacklisting on the first failure. This
668 * should not be done with multiple enabled networks to
669 * avoid getting forced to move into a worse ESS on
670 * single error if there are no other BSSes of the
671 * current ESS.
672 */
673 limit = 0;
674 }
675 if (e->count > limit) {
676 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
677 "(count=%d limit=%d)", e->count, limit);
678 return NULL;
679 }
680 }
681
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700682 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
684 return NULL;
685 }
686
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800687 if (disallowed_bssid(wpa_s, bss->bssid)) {
688 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
689 return NULL;
690 }
691
692 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
693 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
694 return NULL;
695 }
696
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
698
699 for (ssid = group; ssid; ssid = ssid->pnext) {
700 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700701 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702
Dmitry Shmidt04949592012-07-19 12:16:46 -0700703 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
705 continue;
706 }
707
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700708 res = wpas_temp_disabled(wpa_s, ssid);
709 if (res > 0) {
710 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
711 "temporarily for %d second(s)", res);
712 continue;
713 }
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715#ifdef CONFIG_WPS
716 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
717 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
718 "(WPS)");
719 continue;
720 }
721
722 if (wpa && ssid->ssid_len == 0 &&
723 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
724 check_ssid = 0;
725
726 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
727 /* Only allow wildcard SSID match if an AP
728 * advertises active WPS operation that matches
729 * with our mode. */
730 check_ssid = 1;
731 if (ssid->ssid_len == 0 &&
732 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
733 check_ssid = 0;
734 }
735#endif /* CONFIG_WPS */
736
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800737 if (ssid->bssid_set && ssid->ssid_len == 0 &&
738 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
739 check_ssid = 0;
740
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700742 (bss->ssid_len != ssid->ssid_len ||
743 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
745 continue;
746 }
747
748 if (ssid->bssid_set &&
749 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
750 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
751 continue;
752 }
753
754 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
755 continue;
756
757 if (!wpa &&
758 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
759 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
760 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
761 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
762 "not allowed");
763 continue;
764 }
765
Jouni Malinen75ecf522011-06-27 15:19:46 -0700766 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
768 "mismatch");
769 continue;
770 }
771
Jouni Malinen75ecf522011-06-27 15:19:46 -0700772 if (bss->caps & IEEE80211_CAP_IBSS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
774 "network");
775 continue;
776 }
777
778 if (!freq_allowed(ssid->freq_list, bss->freq)) {
779 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
780 "allowed");
781 continue;
782 }
783
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800784 if (!rate_match(wpa_s, bss)) {
785 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
786 "not match");
787 continue;
788 }
789
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790#ifdef CONFIG_P2P
791 /*
792 * TODO: skip the AP if its P2P IE has Group Formation
793 * bit set in the P2P Group Capability Bitmap and we
794 * are not in Group Formation with that device.
795 */
796#endif /* CONFIG_P2P */
797
798 /* Matching configuration found */
799 return ssid;
800 }
801
802 /* No matching configuration found */
803 return NULL;
804}
805
806
807static struct wpa_bss *
808wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 struct wpa_ssid *group,
810 struct wpa_ssid **selected_ssid)
811{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700812 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813
814 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
815 group->priority);
816
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700817 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
818 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
820 if (!*selected_ssid)
821 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
823 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700824 MAC2STR(bss->bssid),
825 wpa_ssid_txt(bss->ssid, bss->ssid_len));
826 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 }
828
829 return NULL;
830}
831
832
833static struct wpa_bss *
834wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 struct wpa_ssid **selected_ssid)
836{
837 struct wpa_bss *selected = NULL;
838 int prio;
839
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700840 if (wpa_s->last_scan_res == NULL ||
841 wpa_s->last_scan_res_used == 0)
842 return NULL; /* no scan results from last update */
843
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 while (selected == NULL) {
845 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
846 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700847 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 selected_ssid);
849 if (selected)
850 break;
851 }
852
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800853 if (selected == NULL && wpa_s->blacklist &&
854 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
856 "blacklist and try again");
857 wpa_blacklist_clear(wpa_s);
858 wpa_s->blacklist_cleared++;
859 } else if (selected == NULL)
860 break;
861 }
862
863 return selected;
864}
865
866
867static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
868 int timeout_sec, int timeout_usec)
869{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700870 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 /*
872 * No networks are enabled; short-circuit request so
873 * we don't wait timeout seconds before transitioning
874 * to INACTIVE state.
875 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700876 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
877 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700879#ifdef CONFIG_P2P
880 wpa_s->sta_scan_pending = 0;
881#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 return;
883 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800884
885 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
887}
888
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800889
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700890int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800891 struct wpa_bss *selected,
892 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893{
894 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
895 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
896 "PBC session overlap");
897#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800898 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700899 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900#endif /* CONFIG_P2P */
901
902#ifdef CONFIG_WPS
903 wpas_wps_cancel(wpa_s);
904#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700905 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 }
907
908 /*
909 * Do not trigger new association unless the BSSID has changed or if
910 * reassociation is requested. If we are in process of associating with
911 * the selected BSSID, do not trigger new attempt.
912 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800913 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
915 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
916 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
917 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
918 0))) {
919 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
920 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700921 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 }
923 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
924 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
925 " pending: " MACSTR " wpa_state: %s",
926 wpa_s->reassociate, MAC2STR(selected->bssid),
927 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
928 wpa_supplicant_state_txt(wpa_s->wpa_state));
929 wpa_supplicant_associate(wpa_s, selected, ssid);
930 } else {
931 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
932 "selected AP");
933 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800934
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700935 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936}
937
938
939static struct wpa_ssid *
940wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
941{
942 int prio;
943 struct wpa_ssid *ssid;
944
945 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
946 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
947 {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700948 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949 continue;
950 if (ssid->mode == IEEE80211_MODE_IBSS ||
951 ssid->mode == IEEE80211_MODE_AP)
952 return ssid;
953 }
954 }
955 return NULL;
956}
957
958
959/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
960 * on BSS added and BSS changed events */
961static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +0300962 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963{
Jouni Malinen87fd2792011-05-16 18:35:42 +0300964 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965
966 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
967 return;
968
Jouni Malinen87fd2792011-05-16 18:35:42 +0300969 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971
Jouni Malinen87fd2792011-05-16 18:35:42 +0300972 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973 if (ssid == NULL)
974 continue;
975
Jouni Malinen87fd2792011-05-16 18:35:42 +0300976 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 if (rsn == NULL)
978 continue;
979
Jouni Malinen87fd2792011-05-16 18:35:42 +0300980 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981 }
982
983}
984
985
986static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
987 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700988 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700990 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700991 int min_diff;
992
993 if (wpa_s->reassociate)
994 return 1; /* explicit request to reassociate */
995 if (wpa_s->wpa_state < WPA_ASSOCIATED)
996 return 1; /* we are not associated; continue */
997 if (wpa_s->current_ssid == NULL)
998 return 1; /* unknown current SSID */
999 if (wpa_s->current_ssid != ssid)
1000 return 1; /* different network block */
1001
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 if (wpas_driver_bss_selection(wpa_s))
1003 return 0; /* Driver-based roaming */
1004
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001005 if (wpa_s->current_ssid->ssid)
1006 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1007 wpa_s->current_ssid->ssid,
1008 wpa_s->current_ssid->ssid_len);
1009 if (!current_bss)
1010 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011
1012 if (!current_bss)
1013 return 1; /* current BSS not seen in scan results */
1014
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001015 if (current_bss == selected)
1016 return 0;
1017
1018 if (selected->last_update_idx > current_bss->last_update_idx)
1019 return 1; /* current BSS not seen in the last scan */
1020
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001021#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1023 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1024 MAC2STR(current_bss->bssid), current_bss->level);
1025 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1026 MAC2STR(selected->bssid), selected->level);
1027
1028 if (wpa_s->current_ssid->bssid_set &&
1029 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1030 0) {
1031 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1032 "has preferred BSSID");
1033 return 1;
1034 }
1035
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001036 if (current_bss->level < 0 && current_bss->level > selected->level) {
1037 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1038 "signal level");
1039 return 0;
1040 }
1041
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042 min_diff = 2;
1043 if (current_bss->level < 0) {
1044 if (current_bss->level < -85)
1045 min_diff = 1;
1046 else if (current_bss->level < -80)
1047 min_diff = 2;
1048 else if (current_bss->level < -75)
1049 min_diff = 3;
1050 else if (current_bss->level < -70)
1051 min_diff = 4;
1052 else
1053 min_diff = 5;
1054 }
1055 if (abs(current_bss->level - selected->level) < min_diff) {
1056 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1057 "in signal level");
1058 return 0;
1059 }
1060
1061 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001062#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001063 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001064#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065}
1066
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001067
Jouni Malinen89ca7022012-09-14 13:03:12 -07001068/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001069 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001070#ifdef ANDROID_P2P
1071static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1072 union wpa_event_data *data, int suppress_event)
1073#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1075 union wpa_event_data *data)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001076#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078 struct wpa_scan_results *scan_res;
1079 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001080#ifndef CONFIG_NO_RANDOM_POOL
1081 size_t i, num;
1082#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083
1084#ifdef CONFIG_AP
1085 if (wpa_s->ap_iface)
1086 ap = 1;
1087#endif /* CONFIG_AP */
1088
1089 wpa_supplicant_notify_scanning(wpa_s, 0);
1090
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001091#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07001092 if (wpa_s->global->p2p_cb_on_scan_complete &&
1093 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001094 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1095 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001096 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001097 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1098 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1099 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001100 wpa_s->sta_scan_pending = 1;
1101 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001102 return -1;
1103 }
1104 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001105 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001106#endif /* CONFIG_P2P */
1107
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1109 data ? &data->scan_info :
1110 NULL, 1);
1111 if (scan_res == NULL) {
1112 if (wpa_s->conf->ap_scan == 2 || ap)
1113 return -1;
1114 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1115 "scanning again");
1116 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1117 return -1;
1118 }
1119
1120#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 num = scan_res->num;
1122 if (num > 10)
1123 num = 10;
1124 for (i = 0; i < num; i++) {
1125 u8 buf[5];
1126 struct wpa_scan_res *res = scan_res->res[i];
1127 buf[0] = res->bssid[5];
1128 buf[1] = res->qual & 0xff;
1129 buf[2] = res->noise & 0xff;
1130 buf[3] = res->level & 0xff;
1131 buf[4] = res->tsf & 0xff;
1132 random_add_randomness(buf, sizeof(buf));
1133 }
1134#endif /* CONFIG_NO_RANDOM_POOL */
1135
1136 if (wpa_s->scan_res_handler) {
1137 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1138 struct wpa_scan_results *scan_res);
1139
1140 scan_res_handler = wpa_s->scan_res_handler;
1141 wpa_s->scan_res_handler = NULL;
1142 scan_res_handler(wpa_s, scan_res);
1143
1144 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001145 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001146 }
1147
1148 if (ap) {
1149 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1150#ifdef CONFIG_AP
1151 if (wpa_s->ap_iface->scan_cb)
1152 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1153#endif /* CONFIG_AP */
1154 wpa_scan_results_free(scan_res);
1155 return 0;
1156 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001157#ifdef ANDROID_P2P
1158 if(!suppress_event)
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001159 {
1160 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1161 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1162 wpas_notify_scan_results(wpa_s);
1163 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001164#else
1165 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1166 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1167 wpas_notify_scan_results(wpa_s);
1168#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001169
1170 wpas_notify_scan_done(wpa_s, 1);
1171
Dmitry Shmidt04949592012-07-19 12:16:46 -07001172 if (sme_proc_obss_scan(wpa_s) > 0) {
1173 wpa_scan_results_free(scan_res);
1174 return 0;
1175 }
1176
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1178 wpa_scan_results_free(scan_res);
1179 return 0;
1180 }
1181
Dmitry Shmidt04949592012-07-19 12:16:46 -07001182 if (autoscan_notify_scan(wpa_s, scan_res)) {
1183 wpa_scan_results_free(scan_res);
1184 return 0;
1185 }
1186
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 if (wpa_s->disconnected) {
1188 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1189 wpa_scan_results_free(scan_res);
1190 return 0;
1191 }
1192
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001193 if (!wpas_driver_bss_selection(wpa_s) &&
1194 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 wpa_scan_results_free(scan_res);
1196 return 0;
1197 }
1198
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001199 wpas_wps_update_ap_info(wpa_s, scan_res);
1200
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001201 wpa_scan_results_free(scan_res);
1202
1203 return wpas_select_network_from_last_scan(wpa_s);
1204}
1205
1206
1207int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1208{
1209 struct wpa_bss *selected;
1210 struct wpa_ssid *ssid = NULL;
1211
1212 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213
1214 if (selected) {
1215 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001216 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001217 if (skip) {
1218 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001220 }
1221
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001222 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001223 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001224 return -1;
1225 }
Jouni Malinen87fd2792011-05-16 18:35:42 +03001226 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001227 /*
1228 * Do not notify other virtual radios of scan results since we do not
1229 * want them to start other associations at the same time.
1230 */
1231 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001232 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1234 ssid = wpa_supplicant_pick_new_network(wpa_s);
1235 if (ssid) {
1236 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1237 wpa_supplicant_associate(wpa_s, NULL, ssid);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001238 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 } else {
1240 int timeout_sec = wpa_s->scan_interval;
1241 int timeout_usec = 0;
1242#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001243 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1244 return 0;
1245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 if (wpa_s->p2p_in_provisioning) {
1247 /*
1248 * Use shorter wait during P2P Provisioning
1249 * state to speed up group formation.
1250 */
1251 timeout_sec = 0;
1252 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001253 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1254 timeout_usec);
1255 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 }
1257#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001258#ifdef CONFIG_INTERWORKING
1259 if (wpa_s->conf->auto_interworking &&
1260 wpa_s->conf->interworking &&
1261 wpa_s->conf->cred) {
1262 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1263 "start ANQP fetch since no matching "
1264 "networks found");
1265 wpa_s->network_select = 1;
1266 wpa_s->auto_network_select = 1;
1267 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001268 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001269 }
1270#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001271 if (wpa_supplicant_req_sched_scan(wpa_s))
1272 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1273 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274 }
1275 }
1276 return 0;
1277}
1278
1279
1280static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1281 union wpa_event_data *data)
1282{
1283 const char *rn, *rn2;
1284 struct wpa_supplicant *ifs;
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001285#ifdef ANDROID_P2P
Jouni Malinen89ca7022012-09-14 13:03:12 -07001286 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) != 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001287#else
Jouni Malinen89ca7022012-09-14 13:03:12 -07001288 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001289#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001290 /*
1291 * If no scan results could be fetched, then no need to
1292 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001293 * this scan. Similarly, if scan results started a new operation on this
1294 * interface, do not notify other interfaces to avoid concurrent
1295 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296 */
1297 return;
1298 }
1299
1300 /*
1301 * Check other interfaces to see if they have the same radio-name. If
1302 * so, they get updated with this same scan info.
1303 */
1304 if (!wpa_s->driver->get_radio_name)
1305 return;
1306
1307 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1308 if (rn == NULL || rn[0] == '\0')
1309 return;
1310
1311 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1312 "sharing same radio (%s) in event_scan_results", rn);
1313
1314 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1315 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1316 continue;
1317
1318 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1319 if (rn2 && os_strcmp(rn, rn2) == 0) {
1320 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1321 "sibling", ifs->ifname);
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001322#ifdef ANDROID_P2P
1323 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1324 /* Do not update the scan results from STA interface to p2p interfaces */
1325 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1326 "sibling %s", ifs->ifname, wpa_s->ifname);
1327 continue;
1328 }
1329 else {
1330 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1331 * no time. Avoid announcing it to application as it may not
1332 * be that useful (since results will be that of only 1,6,11).
1333 * over to any other interface as it
1334 */
1335 if(p2p_search_in_progress(wpa_s->global->p2p))
1336 _wpa_supplicant_event_scan_results(ifs, data, 1);
1337 else
1338 _wpa_supplicant_event_scan_results(ifs, data, 0);
1339 }
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001340#else
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07001341 _wpa_supplicant_event_scan_results(ifs, data);
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001342#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343 }
1344 }
1345}
1346
1347#endif /* CONFIG_NO_SCAN_PROCESSING */
1348
1349
Dmitry Shmidt04949592012-07-19 12:16:46 -07001350#ifdef CONFIG_WNM
1351
1352static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1353{
1354 struct wpa_supplicant *wpa_s = eloop_ctx;
1355
1356 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1357 return;
1358
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001359 if (!wpa_s->no_keep_alive) {
1360 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1361 MAC2STR(wpa_s->bssid));
1362 /* TODO: could skip this if normal data traffic has been sent */
1363 /* TODO: Consider using some more appropriate data frame for
1364 * this */
1365 if (wpa_s->l2)
1366 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1367 (u8 *) "", 0);
1368 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001369
1370#ifdef CONFIG_SME
1371 if (wpa_s->sme.bss_max_idle_period) {
1372 unsigned int msec;
1373 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1374 if (msec > 100)
1375 msec -= 100;
1376 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1377 wnm_bss_keep_alive, wpa_s, NULL);
1378 }
1379#endif /* CONFIG_SME */
1380}
1381
1382
1383static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1384 const u8 *ies, size_t ies_len)
1385{
1386 struct ieee802_11_elems elems;
1387
1388 if (ies == NULL)
1389 return;
1390
1391 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1392 return;
1393
1394#ifdef CONFIG_SME
1395 if (elems.bss_max_idle_period) {
1396 unsigned int msec;
1397 wpa_s->sme.bss_max_idle_period =
1398 WPA_GET_LE16(elems.bss_max_idle_period);
1399 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1400 "TU)%s", wpa_s->sme.bss_max_idle_period,
1401 (elems.bss_max_idle_period[2] & 0x01) ?
1402 " (protected keep-live required)" : "");
1403 if (wpa_s->sme.bss_max_idle_period == 0)
1404 wpa_s->sme.bss_max_idle_period = 1;
1405 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1406 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1407 /* msec times 1000 */
1408 msec = wpa_s->sme.bss_max_idle_period * 1024;
1409 if (msec > 100)
1410 msec -= 100;
1411 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1412 wnm_bss_keep_alive, wpa_s,
1413 NULL);
1414 }
1415 }
1416#endif /* CONFIG_SME */
1417}
1418
1419#endif /* CONFIG_WNM */
1420
1421
1422void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1423{
1424#ifdef CONFIG_WNM
1425 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1426#endif /* CONFIG_WNM */
1427}
1428
1429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1431 union wpa_event_data *data)
1432{
1433 int l, len, found = 0, wpa_found, rsn_found;
1434 const u8 *p;
1435
1436 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1437 if (data->assoc_info.req_ies)
1438 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1439 data->assoc_info.req_ies_len);
1440 if (data->assoc_info.resp_ies) {
1441 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1442 data->assoc_info.resp_ies_len);
1443#ifdef CONFIG_TDLS
1444 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1445 data->assoc_info.resp_ies_len);
1446#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001447#ifdef CONFIG_WNM
1448 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1449 data->assoc_info.resp_ies_len);
1450#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001451 }
1452 if (data->assoc_info.beacon_ies)
1453 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1454 data->assoc_info.beacon_ies,
1455 data->assoc_info.beacon_ies_len);
1456 if (data->assoc_info.freq)
1457 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1458 data->assoc_info.freq);
1459
1460 p = data->assoc_info.req_ies;
1461 l = data->assoc_info.req_ies_len;
1462
1463 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1464 while (p && l >= 2) {
1465 len = p[1] + 2;
1466 if (len > l) {
1467 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1468 p, l);
1469 break;
1470 }
1471 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1472 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1473 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1474 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1475 break;
1476 found = 1;
1477 wpa_find_assoc_pmkid(wpa_s);
1478 break;
1479 }
1480 l -= len;
1481 p += len;
1482 }
1483 if (!found && data->assoc_info.req_ies)
1484 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1485
1486#ifdef CONFIG_IEEE80211R
1487#ifdef CONFIG_SME
1488 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1489 u8 bssid[ETH_ALEN];
1490 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1491 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1492 data->assoc_info.resp_ies,
1493 data->assoc_info.resp_ies_len,
1494 bssid) < 0) {
1495 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1496 "Reassociation Response failed");
1497 wpa_supplicant_deauthenticate(
1498 wpa_s, WLAN_REASON_INVALID_IE);
1499 return -1;
1500 }
1501 }
1502
1503 p = data->assoc_info.resp_ies;
1504 l = data->assoc_info.resp_ies_len;
1505
1506#ifdef CONFIG_WPS_STRICT
1507 if (p && wpa_s->current_ssid &&
1508 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1509 struct wpabuf *wps;
1510 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1511 if (wps == NULL) {
1512 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1513 "include WPS IE in (Re)Association Response");
1514 return -1;
1515 }
1516
1517 if (wps_validate_assoc_resp(wps) < 0) {
1518 wpabuf_free(wps);
1519 wpa_supplicant_deauthenticate(
1520 wpa_s, WLAN_REASON_INVALID_IE);
1521 return -1;
1522 }
1523 wpabuf_free(wps);
1524 }
1525#endif /* CONFIG_WPS_STRICT */
1526
1527 /* Go through the IEs and make a copy of the MDIE, if present. */
1528 while (p && l >= 2) {
1529 len = p[1] + 2;
1530 if (len > l) {
1531 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1532 p, l);
1533 break;
1534 }
1535 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1536 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1537 wpa_s->sme.ft_used = 1;
1538 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1539 MOBILITY_DOMAIN_ID_LEN);
1540 break;
1541 }
1542 l -= len;
1543 p += len;
1544 }
1545#endif /* CONFIG_SME */
1546
1547 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1548 data->assoc_info.resp_ies_len);
1549#endif /* CONFIG_IEEE80211R */
1550
1551 /* WPA/RSN IE from Beacon/ProbeResp */
1552 p = data->assoc_info.beacon_ies;
1553 l = data->assoc_info.beacon_ies_len;
1554
1555 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1556 */
1557 wpa_found = rsn_found = 0;
1558 while (p && l >= 2) {
1559 len = p[1] + 2;
1560 if (len > l) {
1561 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1562 p, l);
1563 break;
1564 }
1565 if (!wpa_found &&
1566 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1567 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1568 wpa_found = 1;
1569 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1570 }
1571
1572 if (!rsn_found &&
1573 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1574 rsn_found = 1;
1575 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1576 }
1577
1578 l -= len;
1579 p += len;
1580 }
1581
1582 if (!wpa_found && data->assoc_info.beacon_ies)
1583 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1584 if (!rsn_found && data->assoc_info.beacon_ies)
1585 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1586 if (wpa_found || rsn_found)
1587 wpa_s->ap_ies_from_associnfo = 1;
1588
Jouni Malinen87fd2792011-05-16 18:35:42 +03001589 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1590 wpa_s->assoc_freq != data->assoc_info.freq) {
1591 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1592 "%u to %u MHz",
1593 wpa_s->assoc_freq, data->assoc_info.freq);
1594 wpa_supplicant_update_scan_results(wpa_s);
1595 }
1596
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 wpa_s->assoc_freq = data->assoc_info.freq;
1598
1599 return 0;
1600}
1601
1602
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001603static struct wpa_bss * wpa_supplicant_get_new_bss(
1604 struct wpa_supplicant *wpa_s, const u8 *bssid)
1605{
1606 struct wpa_bss *bss = NULL;
1607 struct wpa_ssid *ssid = wpa_s->current_ssid;
1608
1609 if (ssid->ssid_len > 0)
1610 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1611 if (!bss)
1612 bss = wpa_bss_get_bssid(wpa_s, bssid);
1613
1614 return bss;
1615}
1616
1617
1618static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1619{
1620 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1621
1622 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1623 return -1;
1624
1625 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1626 return 0;
1627
1628 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1629 WPA_IE_VENDOR_TYPE);
1630 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1631
1632 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1633 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1634 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1635 bss_rsn ? 2 + bss_rsn[1] : 0))
1636 return -1;
1637
1638 return 0;
1639}
1640
1641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1643 union wpa_event_data *data)
1644{
1645 u8 bssid[ETH_ALEN];
1646 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647 struct wpa_driver_capa capa;
1648
1649#ifdef CONFIG_AP
1650 if (wpa_s->ap_iface) {
1651 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1652 data->assoc_info.addr,
1653 data->assoc_info.req_ies,
1654 data->assoc_info.req_ies_len,
1655 data->assoc_info.reassoc);
1656 return;
1657 }
1658#endif /* CONFIG_AP */
1659
1660 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1661 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1662 return;
1663
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001664 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1665 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001666 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001667 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1668 return;
1669 }
1670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001672 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001673 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1674 MACSTR, MAC2STR(bssid));
1675 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001676 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1677 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001678 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679
1680 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1681 wpa_clear_keys(wpa_s, bssid);
1682 }
1683 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001684 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001685 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1686 return;
1687 }
1688 if (wpa_s->current_ssid) {
1689 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001690
1691 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1692 if (!bss) {
1693 wpa_supplicant_update_scan_results(wpa_s);
1694
1695 /* Get the BSS from the new scan results */
1696 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1697 }
1698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001699 if (bss)
1700 wpa_s->current_bss = bss;
1701 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001702
1703 if (wpa_s->conf->ap_scan == 1 &&
1704 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1705 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1706 wpa_msg(wpa_s, MSG_WARNING,
1707 "WPA/RSN IEs not updated");
1708 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 }
1710
1711#ifdef CONFIG_SME
1712 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1713 wpa_s->sme.prev_bssid_set = 1;
1714#endif /* CONFIG_SME */
1715
1716 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1717 if (wpa_s->current_ssid) {
1718 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1719 * initialized before association, but for other modes,
1720 * initialize PC/SC here, if the current configuration needs
1721 * smartcard or SIM/USIM. */
1722 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1723 }
1724 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1725 if (wpa_s->l2)
1726 l2_packet_notify_auth_start(wpa_s->l2);
1727
1728 /*
1729 * Set portEnabled first to FALSE in order to get EAP state machine out
1730 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1731 * state machine may transit to AUTHENTICATING state based on obsolete
1732 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1733 * AUTHENTICATED without ever giving chance to EAP state machine to
1734 * reset the state.
1735 */
1736 if (!ft_completed) {
1737 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1738 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1739 }
1740 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1741 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1742 /* 802.1X::portControl = Auto */
1743 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1744 wpa_s->eapol_received = 0;
1745 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1746 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1747 (wpa_s->current_ssid &&
1748 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1749 wpa_supplicant_cancel_auth_timeout(wpa_s);
1750 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1751 } else if (!ft_completed) {
1752 /* Timeout for receiving the first EAPOL packet */
1753 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1754 }
1755 wpa_supplicant_cancel_scan(wpa_s);
1756
1757 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1758 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1759 /*
1760 * We are done; the driver will take care of RSN 4-way
1761 * handshake.
1762 */
1763 wpa_supplicant_cancel_auth_timeout(wpa_s);
1764 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1765 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1766 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1767 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1768 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1769 /*
1770 * The driver will take care of RSN 4-way handshake, so we need
1771 * to allow EAPOL supplicant to complete its work without
1772 * waiting for WPA supplicant.
1773 */
1774 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1775 } else if (ft_completed) {
1776 /*
1777 * FT protocol completed - make sure EAPOL state machine ends
1778 * up in authenticated.
1779 */
1780 wpa_supplicant_cancel_auth_timeout(wpa_s);
1781 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1782 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1783 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1784 }
1785
Jouni Malinena05074c2012-12-21 21:35:35 +02001786 wpa_s->last_eapol_matches_bssid = 0;
1787
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001788 if (wpa_s->pending_eapol_rx) {
1789 struct os_time now, age;
1790 os_get_time(&now);
1791 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1792 if (age.sec == 0 && age.usec < 100000 &&
1793 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1794 0) {
1795 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1796 "frame that was received just before "
1797 "association notification");
1798 wpa_supplicant_rx_eapol(
1799 wpa_s, wpa_s->pending_eapol_rx_src,
1800 wpabuf_head(wpa_s->pending_eapol_rx),
1801 wpabuf_len(wpa_s->pending_eapol_rx));
1802 }
1803 wpabuf_free(wpa_s->pending_eapol_rx);
1804 wpa_s->pending_eapol_rx = NULL;
1805 }
1806
1807 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1808 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1809 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1810 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1811 /* Set static WEP keys again */
1812 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1813 }
1814
1815#ifdef CONFIG_IBSS_RSN
1816 if (wpa_s->current_ssid &&
1817 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1818 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1819 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1820 wpa_s->ibss_rsn == NULL) {
1821 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1822 if (!wpa_s->ibss_rsn) {
1823 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1824 wpa_supplicant_deauthenticate(
1825 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1826 return;
1827 }
1828
1829 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1830 }
1831#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001832
1833 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834}
1835
1836
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001837static int disconnect_reason_recoverable(u16 reason_code)
1838{
1839 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1840 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1841 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1842}
1843
1844
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001846 u16 reason_code,
1847 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848{
1849 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001850
1851 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1852 /*
1853 * At least Host AP driver and a Prism3 card seemed to be
1854 * generating streams of disconnected events when configuring
1855 * IBSS for WPA-None. Ignore them for now.
1856 */
1857 return;
1858 }
1859
1860 bssid = wpa_s->bssid;
1861 if (is_zero_ether_addr(bssid))
1862 bssid = wpa_s->pending_bssid;
1863
1864 if (!is_zero_ether_addr(bssid) ||
1865 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1866 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1867 " reason=%d%s",
1868 MAC2STR(bssid), reason_code,
1869 locally_generated ? " locally_generated=1" : "");
1870 }
1871}
1872
1873
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001874static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1875 int locally_generated)
1876{
1877 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1878 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1879 return 0; /* Not in 4-way handshake with PSK */
1880
1881 /*
1882 * It looks like connection was lost while trying to go through PSK
1883 * 4-way handshake. Filter out known disconnection cases that are caused
1884 * by something else than PSK mismatch to avoid confusing reports.
1885 */
1886
1887 if (locally_generated) {
1888 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1889 return 0;
1890 }
1891
1892 return 1;
1893}
1894
1895
Jouni Malinen2b89da82012-08-31 22:04:41 +03001896static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1897 u16 reason_code,
1898 int locally_generated)
1899{
1900 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001901 int authenticating;
1902 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903 struct wpa_bss *fast_reconnect = NULL;
1904 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001905 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906
1907 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1908 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1909
1910 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1911 /*
1912 * At least Host AP driver and a Prism3 card seemed to be
1913 * generating streams of disconnected events when configuring
1914 * IBSS for WPA-None. Ignore them for now.
1915 */
1916 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1917 "IBSS/WPA-None mode");
1918 return;
1919 }
1920
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001921 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001922 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1923 "pre-shared key may be incorrect");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001924 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925 }
1926 if (!wpa_s->auto_reconnect_disabled ||
1927 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001928 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1929 "reconnect (wps=%d wpa_state=%d)",
1930 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1931 wpa_s->wpa_state);
1932 if (wpa_s->wpa_state == WPA_COMPLETED &&
1933 wpa_s->current_ssid &&
1934 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001935 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001936 disconnect_reason_recoverable(reason_code)) {
1937 /*
1938 * It looks like the AP has dropped association with
1939 * us, but could allow us to get back in. Try to
1940 * reconnect to the same BSS without full scan to save
1941 * time for some common cases.
1942 */
1943 fast_reconnect = wpa_s->current_bss;
1944 fast_reconnect_ssid = wpa_s->current_ssid;
1945 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001946#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07001947 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001948#else
1949 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1950#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001951 else
1952 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1953 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001955 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 "try to re-connect");
1957 wpa_s->reassociate = 0;
1958 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001959 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001960 }
1961 bssid = wpa_s->bssid;
1962 if (is_zero_ether_addr(bssid))
1963 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1965 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001966 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001967 if (locally_generated)
1968 wpa_s->disconnect_reason = -reason_code;
1969 else
1970 wpa_s->disconnect_reason = reason_code;
1971 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001972 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1973 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1974 wpa_s->keys_cleared = 0;
1975 wpa_clear_keys(wpa_s, wpa_s->bssid);
1976 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001977 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001978 wpa_supplicant_mark_disassoc(wpa_s);
1979
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001980 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001981 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03001982 wpa_s->current_ssid = last_ssid;
1983 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984
1985 if (fast_reconnect) {
1986#ifndef CONFIG_NO_SCAN_PROCESSING
1987 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1988 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1989 fast_reconnect_ssid) < 0) {
1990 /* Recover through full scan */
1991 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1992 }
1993#endif /* CONFIG_NO_SCAN_PROCESSING */
1994 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001995}
1996
1997
1998#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001999void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002000{
2001 struct wpa_supplicant *wpa_s = eloop_ctx;
2002
2003 if (!wpa_s->pending_mic_error_report)
2004 return;
2005
2006 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2007 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2008 wpa_s->pending_mic_error_report = 0;
2009}
2010#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2011
2012
2013static void
2014wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2015 union wpa_event_data *data)
2016{
2017 int pairwise;
2018 struct os_time t;
2019
2020 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2021 pairwise = (data && data->michael_mic_failure.unicast);
2022 os_get_time(&t);
2023 if ((wpa_s->last_michael_mic_error &&
2024 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2025 wpa_s->pending_mic_error_report) {
2026 if (wpa_s->pending_mic_error_report) {
2027 /*
2028 * Send the pending MIC error report immediately since
2029 * we are going to start countermeasures and AP better
2030 * do the same.
2031 */
2032 wpa_sm_key_request(wpa_s->wpa, 1,
2033 wpa_s->pending_mic_error_pairwise);
2034 }
2035
2036 /* Send the new MIC error report immediately since we are going
2037 * to start countermeasures and AP better do the same.
2038 */
2039 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2040
2041 /* initialize countermeasures */
2042 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002043
2044 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2045
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002046 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2047
2048 /*
2049 * Need to wait for completion of request frame. We do not get
2050 * any callback for the message completion, so just wait a
2051 * short while and hope for the best. */
2052 os_sleep(0, 10000);
2053
2054 wpa_drv_set_countermeasures(wpa_s, 1);
2055 wpa_supplicant_deauthenticate(wpa_s,
2056 WLAN_REASON_MICHAEL_MIC_FAILURE);
2057 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2058 wpa_s, NULL);
2059 eloop_register_timeout(60, 0,
2060 wpa_supplicant_stop_countermeasures,
2061 wpa_s, NULL);
2062 /* TODO: mark the AP rejected for 60 second. STA is
2063 * allowed to associate with another AP.. */
2064 } else {
2065#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2066 if (wpa_s->mic_errors_seen) {
2067 /*
2068 * Reduce the effectiveness of Michael MIC error
2069 * reports as a means for attacking against TKIP if
2070 * more than one MIC failure is noticed with the same
2071 * PTK. We delay the transmission of the reports by a
2072 * random time between 0 and 60 seconds in order to
2073 * force the attacker wait 60 seconds before getting
2074 * the information on whether a frame resulted in a MIC
2075 * failure.
2076 */
2077 u8 rval[4];
2078 int sec;
2079
2080 if (os_get_random(rval, sizeof(rval)) < 0)
2081 sec = os_random() % 60;
2082 else
2083 sec = WPA_GET_BE32(rval) % 60;
2084 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2085 "report %d seconds", sec);
2086 wpa_s->pending_mic_error_report = 1;
2087 wpa_s->pending_mic_error_pairwise = pairwise;
2088 eloop_cancel_timeout(
2089 wpa_supplicant_delayed_mic_error_report,
2090 wpa_s, NULL);
2091 eloop_register_timeout(
2092 sec, os_random() % 1000000,
2093 wpa_supplicant_delayed_mic_error_report,
2094 wpa_s, NULL);
2095 } else {
2096 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2097 }
2098#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2099 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2100#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2101 }
2102 wpa_s->last_michael_mic_error = t.sec;
2103 wpa_s->mic_errors_seen++;
2104}
2105
2106
2107#ifdef CONFIG_TERMINATE_ONLASTIF
2108static int any_interfaces(struct wpa_supplicant *head)
2109{
2110 struct wpa_supplicant *wpa_s;
2111
2112 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2113 if (!wpa_s->interface_removed)
2114 return 1;
2115 return 0;
2116}
2117#endif /* CONFIG_TERMINATE_ONLASTIF */
2118
2119
2120static void
2121wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2122 union wpa_event_data *data)
2123{
2124 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2125 return;
2126
2127 switch (data->interface_status.ievent) {
2128 case EVENT_INTERFACE_ADDED:
2129 if (!wpa_s->interface_removed)
2130 break;
2131 wpa_s->interface_removed = 0;
2132 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2133 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2134 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2135 "driver after interface was added");
2136 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002137 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 break;
2139 case EVENT_INTERFACE_REMOVED:
2140 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2141 wpa_s->interface_removed = 1;
2142 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002143 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144 l2_packet_deinit(wpa_s->l2);
2145 wpa_s->l2 = NULL;
2146#ifdef CONFIG_IBSS_RSN
2147 ibss_rsn_deinit(wpa_s->ibss_rsn);
2148 wpa_s->ibss_rsn = NULL;
2149#endif /* CONFIG_IBSS_RSN */
2150#ifdef CONFIG_TERMINATE_ONLASTIF
2151 /* check if last interface */
2152 if (!any_interfaces(wpa_s->global->ifaces))
2153 eloop_terminate();
2154#endif /* CONFIG_TERMINATE_ONLASTIF */
2155 break;
2156 }
2157}
2158
2159
2160#ifdef CONFIG_PEERKEY
2161static void
2162wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2163 union wpa_event_data *data)
2164{
2165 if (data == NULL)
2166 return;
2167 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2168}
2169#endif /* CONFIG_PEERKEY */
2170
2171
2172#ifdef CONFIG_TDLS
2173static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2174 union wpa_event_data *data)
2175{
2176 if (data == NULL)
2177 return;
2178 switch (data->tdls.oper) {
2179 case TDLS_REQUEST_SETUP:
2180 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2181 break;
2182 case TDLS_REQUEST_TEARDOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002183 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2184 data->tdls.reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002185 break;
2186 }
2187}
2188#endif /* CONFIG_TDLS */
2189
2190
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002191#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002192static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2193 union wpa_event_data *data)
2194{
2195 if (data == NULL)
2196 return;
2197 switch (data->wnm.oper) {
2198 case WNM_OPER_SLEEP:
2199 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2200 "(action=%d, intval=%d)",
2201 data->wnm.sleep_action, data->wnm.sleep_intval);
2202 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002203 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002204 break;
2205 }
2206}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002207#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002208
2209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002210#ifdef CONFIG_IEEE80211R
2211static void
2212wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2213 union wpa_event_data *data)
2214{
2215 if (data == NULL)
2216 return;
2217
2218 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2219 data->ft_ies.ies_len,
2220 data->ft_ies.ft_action,
2221 data->ft_ies.target_ap,
2222 data->ft_ies.ric_ies,
2223 data->ft_ies.ric_ies_len) < 0) {
2224 /* TODO: prevent MLME/driver from trying to associate? */
2225 }
2226}
2227#endif /* CONFIG_IEEE80211R */
2228
2229
2230#ifdef CONFIG_IBSS_RSN
2231static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2232 union wpa_event_data *data)
2233{
2234 struct wpa_ssid *ssid;
2235 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2236 return;
2237 if (data == NULL)
2238 return;
2239 ssid = wpa_s->current_ssid;
2240 if (ssid == NULL)
2241 return;
2242 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2243 return;
2244
2245 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2246}
2247#endif /* CONFIG_IBSS_RSN */
2248
2249
2250#ifdef CONFIG_IEEE80211R
2251static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2252 size_t len)
2253{
2254 const u8 *sta_addr, *target_ap_addr;
2255 u16 status;
2256
2257 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2258 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2259 return; /* only SME case supported for now */
2260 if (len < 1 + 2 * ETH_ALEN + 2)
2261 return;
2262 if (data[0] != 2)
2263 return; /* Only FT Action Response is supported for now */
2264 sta_addr = data + 1;
2265 target_ap_addr = data + 1 + ETH_ALEN;
2266 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2267 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2268 MACSTR " TargetAP " MACSTR " status %u",
2269 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2270
2271 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2272 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2273 " in FT Action Response", MAC2STR(sta_addr));
2274 return;
2275 }
2276
2277 if (status) {
2278 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2279 "failure (status code %d)", status);
2280 /* TODO: report error to FT code(?) */
2281 return;
2282 }
2283
2284 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2285 len - (1 + 2 * ETH_ALEN + 2), 1,
2286 target_ap_addr, NULL, 0) < 0)
2287 return;
2288
2289#ifdef CONFIG_SME
2290 {
2291 struct wpa_bss *bss;
2292 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2293 if (bss)
2294 wpa_s->sme.freq = bss->freq;
2295 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2296 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2297 WLAN_AUTH_FT);
2298 }
2299#endif /* CONFIG_SME */
2300}
2301#endif /* CONFIG_IEEE80211R */
2302
2303
2304static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2305 struct unprot_deauth *e)
2306{
2307#ifdef CONFIG_IEEE80211W
2308 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2309 "dropped: " MACSTR " -> " MACSTR
2310 " (reason code %u)",
2311 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2312 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2313#endif /* CONFIG_IEEE80211W */
2314}
2315
2316
2317static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2318 struct unprot_disassoc *e)
2319{
2320#ifdef CONFIG_IEEE80211W
2321 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2322 "dropped: " MACSTR " -> " MACSTR
2323 " (reason code %u)",
2324 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2325 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2326#endif /* CONFIG_IEEE80211W */
2327}
2328
2329
2330void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2331 union wpa_event_data *data)
2332{
2333 struct wpa_supplicant *wpa_s = ctx;
2334 u16 reason_code = 0;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002335 int locally_generated = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336
2337 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2338 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002339 event != EVENT_INTERFACE_STATUS &&
2340 event != EVENT_SCHED_SCAN_STOPPED) {
2341 wpa_dbg(wpa_s, MSG_DEBUG,
2342 "Ignore event %s (%d) while interface is disabled",
2343 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002344 return;
2345 }
2346
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002347#ifndef CONFIG_NO_STDOUT_DEBUG
2348{
2349 int level = MSG_DEBUG;
2350
Dmitry Shmidt04949592012-07-19 12:16:46 -07002351 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002352 const struct ieee80211_hdr *hdr;
2353 u16 fc;
2354 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2355 fc = le_to_host16(hdr->frame_control);
2356 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2357 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2358 level = MSG_EXCESSIVE;
2359 }
2360
2361 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2362 event_to_string(event), event);
2363}
2364#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002365
2366 switch (event) {
2367 case EVENT_AUTH:
2368 sme_event_auth(wpa_s, data);
2369 break;
2370 case EVENT_ASSOC:
2371 wpa_supplicant_event_assoc(wpa_s, data);
2372 break;
2373 case EVENT_DISASSOC:
2374 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2375 if (data) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002376 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2377 data->disassoc_info.reason_code,
2378 data->disassoc_info.locally_generated ?
2379 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380 if (data->disassoc_info.addr)
2381 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2382 MAC2STR(data->disassoc_info.addr));
2383 }
2384#ifdef CONFIG_AP
2385 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2386 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2387 data->disassoc_info.addr);
2388 break;
2389 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002390 if (wpa_s->ap_iface) {
2391 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2392 "AP mode");
2393 break;
2394 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002395#endif /* CONFIG_AP */
2396 if (data) {
2397 reason_code = data->disassoc_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002398 locally_generated =
2399 data->disassoc_info.locally_generated;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002400 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2401 data->disassoc_info.ie,
2402 data->disassoc_info.ie_len);
2403#ifdef CONFIG_P2P
2404 wpas_p2p_disassoc_notif(
2405 wpa_s, data->disassoc_info.addr, reason_code,
2406 data->disassoc_info.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002407 data->disassoc_info.ie_len,
2408 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002409#endif /* CONFIG_P2P */
2410 }
2411 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2412 sme_event_disassoc(wpa_s, data);
2413 /* fall through */
2414 case EVENT_DEAUTH:
2415 if (event == EVENT_DEAUTH) {
2416 wpa_dbg(wpa_s, MSG_DEBUG,
2417 "Deauthentication notification");
2418 if (data) {
2419 reason_code = data->deauth_info.reason_code;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002420 locally_generated =
2421 data->deauth_info.locally_generated;
2422 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2423 data->deauth_info.reason_code,
2424 data->deauth_info.locally_generated ?
2425 " (locally generated)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002426 if (data->deauth_info.addr) {
2427 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2428 MACSTR,
2429 MAC2STR(data->deauth_info.
2430 addr));
2431 }
2432 wpa_hexdump(MSG_DEBUG,
2433 "Deauthentication frame IE(s)",
2434 data->deauth_info.ie,
2435 data->deauth_info.ie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002436 }
2437 }
2438#ifdef CONFIG_AP
2439 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2440 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2441 data->deauth_info.addr);
2442 break;
2443 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002444 if (wpa_s->ap_iface) {
2445 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2446 "AP mode");
2447 break;
2448 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002449#endif /* CONFIG_AP */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002450 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2451 locally_generated);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002452 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2453 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2454 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2455 eapol_sm_failed(wpa_s->eapol)))
2456 wpas_auth_failed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002457#ifdef CONFIG_P2P
2458 if (event == EVENT_DEAUTH && data) {
Jouni Malinen2b89da82012-08-31 22:04:41 +03002459 if (wpas_p2p_deauth_notif(wpa_s,
2460 data->deauth_info.addr,
2461 reason_code,
2462 data->deauth_info.ie,
2463 data->deauth_info.ie_len,
2464 locally_generated) > 0) {
2465 /*
2466 * The interface was removed, so cannot
2467 * continue processing any additional
2468 * operations after this.
2469 */
2470 break;
2471 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002472 }
2473#endif /* CONFIG_P2P */
Jouni Malinen2b89da82012-08-31 22:04:41 +03002474 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2475 locally_generated);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002476 break;
2477 case EVENT_MICHAEL_MIC_FAILURE:
2478 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2479 break;
2480#ifndef CONFIG_NO_SCAN_PROCESSING
2481 case EVENT_SCAN_RESULTS:
2482 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002483#ifdef CONFIG_P2P
Jouni Malinendc7b7132012-09-14 12:53:47 -07002484 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002485 wpa_s->global->p2p != NULL &&
2486 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2487 wpa_s->wpa_state != WPA_ASSOCIATING) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07002488 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002489 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2490 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2491 "continued after scan result processing");
2492 }
2493 }
2494#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002495 break;
2496#endif /* CONFIG_NO_SCAN_PROCESSING */
2497 case EVENT_ASSOCINFO:
2498 wpa_supplicant_event_associnfo(wpa_s, data);
2499 break;
2500 case EVENT_INTERFACE_STATUS:
2501 wpa_supplicant_event_interface_status(wpa_s, data);
2502 break;
2503 case EVENT_PMKID_CANDIDATE:
2504 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2505 break;
2506#ifdef CONFIG_PEERKEY
2507 case EVENT_STKSTART:
2508 wpa_supplicant_event_stkstart(wpa_s, data);
2509 break;
2510#endif /* CONFIG_PEERKEY */
2511#ifdef CONFIG_TDLS
2512 case EVENT_TDLS:
2513 wpa_supplicant_event_tdls(wpa_s, data);
2514 break;
2515#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002516#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002517 case EVENT_WNM:
2518 wpa_supplicant_event_wnm(wpa_s, data);
2519 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002520#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002521#ifdef CONFIG_IEEE80211R
2522 case EVENT_FT_RESPONSE:
2523 wpa_supplicant_event_ft_response(wpa_s, data);
2524 break;
2525#endif /* CONFIG_IEEE80211R */
2526#ifdef CONFIG_IBSS_RSN
2527 case EVENT_IBSS_RSN_START:
2528 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2529 break;
2530#endif /* CONFIG_IBSS_RSN */
2531 case EVENT_ASSOC_REJECT:
2532 if (data->assoc_reject.bssid)
2533 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2534 "bssid=" MACSTR " status_code=%u",
2535 MAC2STR(data->assoc_reject.bssid),
2536 data->assoc_reject.status_code);
2537 else
2538 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2539 "status_code=%u",
2540 data->assoc_reject.status_code);
2541 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2542 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002543 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002544#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002545 if(!wpa_s->current_ssid) {
2546 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2547 break;
2548 }
2549 /* If assoc reject is reported by the driver, then avoid
2550 * waiting for the authentication timeout. Cancel the
2551 * authentication timeout and retry the assoc.
2552 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002553 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002554 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2555 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002556
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002557 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002558
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002559 /* Clear the states */
2560 wpa_sm_notify_disassoc(wpa_s->wpa);
2561 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2562
2563 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002564 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002565 const u8 *bl_bssid = data->assoc_reject.bssid;
2566 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2567 bl_bssid = wpa_s->pending_bssid;
2568 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002569 wpa_supplicant_req_scan(wpa_s, 0, 0);
2570 } else {
2571 wpa_supplicant_req_scan(wpa_s, 1, 0);
2572 }
2573 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002574 /* If we ASSOC_REJECT's hits threshold, disable the
2575 * network
2576 */
2577 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2578 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002579 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002580 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002581 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002582 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002583#else
2584 const u8 *bssid = data->assoc_reject.bssid;
2585 if (bssid == NULL || is_zero_ether_addr(bssid))
2586 bssid = wpa_s->pending_bssid;
2587 wpas_connection_failed(wpa_s, bssid);
2588 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002589#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002590 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002591 break;
2592 case EVENT_AUTH_TIMED_OUT:
2593 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2594 sme_event_auth_timed_out(wpa_s, data);
2595 break;
2596 case EVENT_ASSOC_TIMED_OUT:
2597 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2598 sme_event_assoc_timed_out(wpa_s, data);
2599 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002600 case EVENT_TX_STATUS:
2601 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2602 " type=%d stype=%d",
2603 MAC2STR(data->tx_status.dst),
2604 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002605#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002606 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002607#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2609 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002610 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002611 wpa_s, data->tx_status.dst,
2612 data->tx_status.data,
2613 data->tx_status.data_len,
2614 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002615 OFFCHANNEL_SEND_ACTION_SUCCESS :
2616 OFFCHANNEL_SEND_ACTION_NO_ACK);
2617#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002618 break;
2619 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002620#endif /* CONFIG_AP */
2621#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2623 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2624 /*
2625 * Catch TX status events for Action frames we sent via group
2626 * interface in GO mode.
2627 */
2628 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2629 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2630 os_memcmp(wpa_s->parent->pending_action_dst,
2631 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002632 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633 wpa_s->parent, data->tx_status.dst,
2634 data->tx_status.data,
2635 data->tx_status.data_len,
2636 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002637 OFFCHANNEL_SEND_ACTION_SUCCESS :
2638 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639 break;
2640 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002641#endif /* CONFIG_OFFCHANNEL */
2642#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002643 switch (data->tx_status.type) {
2644 case WLAN_FC_TYPE_MGMT:
2645 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2646 data->tx_status.data_len,
2647 data->tx_status.stype,
2648 data->tx_status.ack);
2649 break;
2650 case WLAN_FC_TYPE_DATA:
2651 ap_tx_status(wpa_s, data->tx_status.dst,
2652 data->tx_status.data,
2653 data->tx_status.data_len,
2654 data->tx_status.ack);
2655 break;
2656 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002657#endif /* CONFIG_AP */
2658 break;
2659#ifdef CONFIG_AP
2660 case EVENT_EAPOL_TX_STATUS:
2661 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2662 data->eapol_tx_status.data,
2663 data->eapol_tx_status.data_len,
2664 data->eapol_tx_status.ack);
2665 break;
2666 case EVENT_DRIVER_CLIENT_POLL_OK:
2667 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002668 break;
2669 case EVENT_RX_FROM_UNKNOWN:
2670 if (wpa_s->ap_iface == NULL)
2671 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002672 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2673 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002675 case EVENT_CH_SWITCH:
2676 if (!data)
2677 break;
2678 if (!wpa_s->ap_iface) {
2679 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2680 "event in non-AP mode");
2681 break;
2682 }
2683
2684#ifdef CONFIG_AP
2685 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2686 data->ch_switch.ht_enabled,
2687 data->ch_switch.ch_offset);
2688#endif /* CONFIG_AP */
2689 break;
2690 case EVENT_RX_MGMT: {
2691 u16 fc, stype;
2692 const struct ieee80211_mgmt *mgmt;
2693
2694 mgmt = (const struct ieee80211_mgmt *)
2695 data->rx_mgmt.frame;
2696 fc = le_to_host16(mgmt->frame_control);
2697 stype = WLAN_FC_GET_STYPE(fc);
2698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002699 if (wpa_s->ap_iface == NULL) {
2700#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002701 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2702 data->rx_mgmt.frame_len > 24) {
2703 const u8 *src = mgmt->sa;
2704 const u8 *ie = mgmt->u.probe_req.variable;
2705 size_t ie_len = data->rx_mgmt.frame_len -
2706 (mgmt->u.probe_req.variable -
2707 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002708 wpas_p2p_probe_req_rx(
2709 wpa_s, src, mgmt->da,
2710 mgmt->bssid, ie, ie_len,
2711 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712 break;
2713 }
2714#endif /* CONFIG_P2P */
2715 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2716 "management frame in non-AP mode");
2717 break;
2718 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002719
2720 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2721 data->rx_mgmt.frame_len > 24) {
2722 const u8 *ie = mgmt->u.probe_req.variable;
2723 size_t ie_len = data->rx_mgmt.frame_len -
2724 (mgmt->u.probe_req.variable -
2725 data->rx_mgmt.frame);
2726
2727 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2728 mgmt->bssid, ie, ie_len,
2729 data->rx_mgmt.ssi_signal);
2730 }
2731
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002732 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2733 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002734 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735#endif /* CONFIG_AP */
2736 case EVENT_RX_ACTION:
2737 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2738 " Category=%u DataLen=%d freq=%d MHz",
2739 MAC2STR(data->rx_action.sa),
2740 data->rx_action.category, (int) data->rx_action.len,
2741 data->rx_action.freq);
2742#ifdef CONFIG_IEEE80211R
2743 if (data->rx_action.category == WLAN_ACTION_FT) {
2744 ft_rx_action(wpa_s, data->rx_action.data,
2745 data->rx_action.len);
2746 break;
2747 }
2748#endif /* CONFIG_IEEE80211R */
2749#ifdef CONFIG_IEEE80211W
2750#ifdef CONFIG_SME
2751 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2752 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2753 data->rx_action.data,
2754 data->rx_action.len);
2755 break;
2756 }
2757#endif /* CONFIG_SME */
2758#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002759#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002760 if (data->rx_action.category == WLAN_ACTION_WNM) {
2761 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2762 break;
2763 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002764#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002765#ifdef CONFIG_GAS
2766 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2767 gas_query_rx(wpa_s->gas, data->rx_action.da,
2768 data->rx_action.sa, data->rx_action.bssid,
2769 data->rx_action.data, data->rx_action.len,
2770 data->rx_action.freq) == 0)
2771 break;
2772#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002773#ifdef CONFIG_TDLS
2774 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2775 data->rx_action.len >= 4 &&
2776 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2777 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2778 "Response from " MACSTR,
2779 MAC2STR(data->rx_action.sa));
2780 break;
2781 }
2782#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783#ifdef CONFIG_P2P
2784 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2785 data->rx_action.sa,
2786 data->rx_action.bssid,
2787 data->rx_action.category,
2788 data->rx_action.data,
2789 data->rx_action.len, data->rx_action.freq);
2790#endif /* CONFIG_P2P */
2791 break;
2792 case EVENT_RX_PROBE_REQ:
2793 if (data->rx_probe_req.sa == NULL ||
2794 data->rx_probe_req.ie == NULL)
2795 break;
2796#ifdef CONFIG_AP
2797 if (wpa_s->ap_iface) {
2798 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2799 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002800 data->rx_probe_req.da,
2801 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002803 data->rx_probe_req.ie_len,
2804 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805 break;
2806 }
2807#endif /* CONFIG_AP */
2808#ifdef CONFIG_P2P
2809 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002810 data->rx_probe_req.da,
2811 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002812 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002813 data->rx_probe_req.ie_len,
2814 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815#endif /* CONFIG_P2P */
2816 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002817 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002818#ifdef CONFIG_OFFCHANNEL
2819 offchannel_remain_on_channel_cb(
2820 wpa_s, data->remain_on_channel.freq,
2821 data->remain_on_channel.duration);
2822#endif /* CONFIG_OFFCHANNEL */
2823#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 wpas_p2p_remain_on_channel_cb(
2825 wpa_s, data->remain_on_channel.freq,
2826 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002827#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828 break;
2829 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002830#ifdef CONFIG_OFFCHANNEL
2831 offchannel_cancel_remain_on_channel_cb(
2832 wpa_s, data->remain_on_channel.freq);
2833#endif /* CONFIG_OFFCHANNEL */
2834#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835 wpas_p2p_cancel_remain_on_channel_cb(
2836 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002837#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002838 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002839#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002840 case EVENT_P2P_DEV_FOUND: {
2841 struct p2p_peer_info peer_info;
2842
2843 os_memset(&peer_info, 0, sizeof(peer_info));
2844 if (data->p2p_dev_found.dev_addr)
2845 os_memcpy(peer_info.p2p_device_addr,
2846 data->p2p_dev_found.dev_addr, ETH_ALEN);
2847 if (data->p2p_dev_found.pri_dev_type)
2848 os_memcpy(peer_info.pri_dev_type,
2849 data->p2p_dev_found.pri_dev_type,
2850 sizeof(peer_info.pri_dev_type));
2851 if (data->p2p_dev_found.dev_name)
2852 os_strlcpy(peer_info.device_name,
2853 data->p2p_dev_found.dev_name,
2854 sizeof(peer_info.device_name));
2855 peer_info.config_methods = data->p2p_dev_found.config_methods;
2856 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2857 peer_info.group_capab = data->p2p_dev_found.group_capab;
2858
2859 /*
2860 * FIX: new_device=1 is not necessarily correct. We should
2861 * maintain a P2P peer database in wpa_supplicant and update
2862 * this information based on whether the peer is truly new.
2863 */
2864 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2865 break;
2866 }
2867 case EVENT_P2P_GO_NEG_REQ_RX:
2868 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2869 data->p2p_go_neg_req_rx.dev_passwd_id);
2870 break;
2871 case EVENT_P2P_GO_NEG_COMPLETED:
2872 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2873 break;
2874 case EVENT_P2P_PROV_DISC_REQUEST:
2875 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2876 data->p2p_prov_disc_req.config_methods,
2877 data->p2p_prov_disc_req.dev_addr,
2878 data->p2p_prov_disc_req.pri_dev_type,
2879 data->p2p_prov_disc_req.dev_name,
2880 data->p2p_prov_disc_req.supp_config_methods,
2881 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002882 data->p2p_prov_disc_req.group_capab,
2883 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 break;
2885 case EVENT_P2P_PROV_DISC_RESPONSE:
2886 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2887 data->p2p_prov_disc_resp.config_methods);
2888 break;
2889 case EVENT_P2P_SD_REQUEST:
2890 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2891 data->p2p_sd_req.sa,
2892 data->p2p_sd_req.dialog_token,
2893 data->p2p_sd_req.update_indic,
2894 data->p2p_sd_req.tlvs,
2895 data->p2p_sd_req.tlvs_len);
2896 break;
2897 case EVENT_P2P_SD_RESPONSE:
2898 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2899 data->p2p_sd_resp.update_indic,
2900 data->p2p_sd_resp.tlvs,
2901 data->p2p_sd_resp.tlvs_len);
2902 break;
2903#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 case EVENT_EAPOL_RX:
2905 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2906 data->eapol_rx.data,
2907 data->eapol_rx.data_len);
2908 break;
2909 case EVENT_SIGNAL_CHANGE:
2910 bgscan_notify_signal_change(
2911 wpa_s, data->signal_change.above_threshold,
2912 data->signal_change.current_signal,
2913 data->signal_change.current_noise,
2914 data->signal_change.current_txrate);
2915 break;
2916 case EVENT_INTERFACE_ENABLED:
2917 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2918 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002919 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002920#ifdef CONFIG_AP
2921 if (!wpa_s->ap_iface) {
2922 wpa_supplicant_set_state(wpa_s,
2923 WPA_DISCONNECTED);
2924 wpa_supplicant_req_scan(wpa_s, 0, 0);
2925 } else
2926 wpa_supplicant_set_state(wpa_s,
2927 WPA_COMPLETED);
2928#else /* CONFIG_AP */
2929 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2930 wpa_supplicant_req_scan(wpa_s, 0, 0);
2931#endif /* CONFIG_AP */
2932 }
2933 break;
2934 case EVENT_INTERFACE_DISABLED:
2935 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2936 wpa_supplicant_mark_disassoc(wpa_s);
2937 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2938 break;
2939 case EVENT_CHANNEL_LIST_CHANGED:
2940 if (wpa_s->drv_priv == NULL)
2941 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002942
2943 free_hw_features(wpa_s);
2944 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2945 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2946
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002947#ifdef CONFIG_P2P
2948 wpas_p2p_update_channel_list(wpa_s);
2949#endif /* CONFIG_P2P */
2950 break;
2951 case EVENT_INTERFACE_UNAVAILABLE:
2952#ifdef CONFIG_P2P
2953 wpas_p2p_interface_unavailable(wpa_s);
2954#endif /* CONFIG_P2P */
2955 break;
2956 case EVENT_BEST_CHANNEL:
2957 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2958 "(%d %d %d)",
2959 data->best_chan.freq_24, data->best_chan.freq_5,
2960 data->best_chan.freq_overall);
2961 wpa_s->best_24_freq = data->best_chan.freq_24;
2962 wpa_s->best_5_freq = data->best_chan.freq_5;
2963 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2964#ifdef CONFIG_P2P
2965 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2966 data->best_chan.freq_5,
2967 data->best_chan.freq_overall);
2968#endif /* CONFIG_P2P */
2969 break;
2970 case EVENT_UNPROT_DEAUTH:
2971 wpa_supplicant_event_unprot_deauth(wpa_s,
2972 &data->unprot_deauth);
2973 break;
2974 case EVENT_UNPROT_DISASSOC:
2975 wpa_supplicant_event_unprot_disassoc(wpa_s,
2976 &data->unprot_disassoc);
2977 break;
2978 case EVENT_STATION_LOW_ACK:
2979#ifdef CONFIG_AP
2980 if (wpa_s->ap_iface && data)
2981 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2982 data->low_ack.addr);
2983#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002984#ifdef CONFIG_TDLS
2985 if (data)
2986 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2987#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002988 break;
2989 case EVENT_IBSS_PEER_LOST:
2990#ifdef CONFIG_IBSS_RSN
2991 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2992#endif /* CONFIG_IBSS_RSN */
2993 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002994 case EVENT_DRIVER_GTK_REKEY:
2995 if (os_memcmp(data->driver_gtk_rekey.bssid,
2996 wpa_s->bssid, ETH_ALEN))
2997 break;
2998 if (!wpa_s->wpa)
2999 break;
3000 wpa_sm_update_replay_ctr(wpa_s->wpa,
3001 data->driver_gtk_rekey.replay_ctr);
3002 break;
3003 case EVENT_SCHED_SCAN_STOPPED:
3004 wpa_s->sched_scanning = 0;
3005 wpa_supplicant_notify_scanning(wpa_s, 0);
3006
3007 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3008 break;
3009
3010 /*
3011 * If we timed out, start a new sched scan to continue
3012 * searching for more SSIDs.
3013 */
3014 if (wpa_s->sched_scan_timed_out)
3015 wpa_supplicant_req_sched_scan(wpa_s);
3016 break;
3017 case EVENT_WPS_BUTTON_PUSHED:
3018#ifdef CONFIG_WPS
3019 wpas_wps_start_pbc(wpa_s, NULL, 0);
3020#endif /* CONFIG_WPS */
3021 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003022 default:
3023 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3024 break;
3025 }
3026}