blob: b9481f64094b303eca0a08f3846f988c552ae9ab [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
Dmitry Shmidt34af3062013-07-11 10:46:32 -070047#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070048static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080049 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080051
52
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
55{
56 struct os_time now;
57
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
61 os_get_time(&now);
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
64
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
66
67 return 0;
68}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
73 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
85 return -1;
86 }
87
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 return -1;
91 }
92
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080093 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 return -1;
97 }
98
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 res = wpas_temp_disabled(wpa_s, ssid);
100 if (res > 0) {
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
103 return -1;
104 }
105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 } else {
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 }
117
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
126
127 return 0;
128}
129
130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132{
133 struct wpa_supplicant *wpa_s = eloop_ctx;
134
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
140 }
141}
142
143
144void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145{
146 int bssid_changed;
147
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148 wnm_bss_keep_alive_deinit(wpa_s);
149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174#ifdef CONFIG_IEEE80211R
175#ifdef CONFIG_SME
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178#endif /* CONFIG_SME */
179#endif /* CONFIG_IEEE80211R */
180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700190 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192}
193
194
195static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
196{
197 struct wpa_ie_data ie;
198 int pmksa_set = -1;
199 size_t i;
200
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 ie.pmkid == NULL)
203 return;
204
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
208 NULL, NULL, 0);
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
211 break;
212 }
213 }
214
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217}
218
219
220static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
222{
223 if (data == NULL) {
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 "event");
226 return;
227 }
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
233
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
237}
238
239
240static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
241{
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
244 return 0;
245
246#ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
254 return 0;
255 }
256#endif /* IEEE8021X_EAPOL */
257
258 return 1;
259}
260
261
262/**
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
267 *
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
270 */
271int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
273{
274#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700276 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277
Dmitry Shmidt051af732013-10-22 13:52:46 -0700278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
279 wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 return 0;
281
282 if (ssid->eap.eap_methods == NULL) {
283 sim = 1;
284 aka = 1;
285 } else {
286 struct eap_method_type *eap = ssid->eap.eap_methods;
287 while (eap->vendor != EAP_VENDOR_IETF ||
288 eap->method != EAP_TYPE_NONE) {
289 if (eap->vendor == EAP_VENDOR_IETF) {
290 if (eap->method == EAP_TYPE_SIM)
291 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 else if (eap->method == EAP_TYPE_AKA ||
293 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 aka = 1;
295 }
296 eap++;
297 }
298 }
299
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
303 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 aka = 0;
306
307 if (!sim && !aka) {
308 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
309 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 "enabled");
311 return 0;
312 }
313
314 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
315 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800317 wpa_s->scard = scard_init(NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 if (wpa_s->scard == NULL) {
319 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
320 "(pcsc-lite)");
321 return -1;
322 }
323 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
324 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800325#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326#endif /* IEEE8021X_EAPOL */
327
328 return 0;
329}
330
331
332#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700333
334static int has_wep_key(struct wpa_ssid *ssid)
335{
336 int i;
337
338 for (i = 0; i < NUM_WEP_KEYS; i++) {
339 if (ssid->wep_key_len[i])
340 return 1;
341 }
342
343 return 0;
344}
345
346
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700347static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 struct wpa_ssid *ssid)
349{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700350 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351
352 if (ssid->mixed_cell)
353 return 1;
354
355#ifdef CONFIG_WPS
356 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
357 return 1;
358#endif /* CONFIG_WPS */
359
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700360 if (has_wep_key(ssid))
361 privacy = 1;
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363#ifdef IEEE8021X_EAPOL
364 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
365 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
367 privacy = 1;
368#endif /* IEEE8021X_EAPOL */
369
Jouni Malinen75ecf522011-06-27 15:19:46 -0700370 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
371 privacy = 1;
372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 if (bss->caps & IEEE80211_CAP_PRIVACY)
374 return privacy;
375 return !privacy;
376}
377
378
379static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
380 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700381 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382{
383 struct wpa_ie_data ie;
384 int proto_match = 0;
385 const u8 *rsn_ie, *wpa_ie;
386 int ret;
387 int wep_ok;
388
389 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
390 if (ret >= 0)
391 return ret;
392
393 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
394 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
395 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
396 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
397 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
398
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700399 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
401 proto_match++;
402
403 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
405 "failed");
406 break;
407 }
408
409 if (wep_ok &&
410 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
411 {
412 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
413 "in RSN IE");
414 return 1;
415 }
416
417 if (!(ie.proto & ssid->proto)) {
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
419 "mismatch");
420 break;
421 }
422
423 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
425 "cipher mismatch");
426 break;
427 }
428
429 if (!(ie.group_cipher & ssid->group_cipher)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
431 "cipher mismatch");
432 break;
433 }
434
435 if (!(ie.key_mgmt & ssid->key_mgmt)) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
437 "mismatch");
438 break;
439 }
440
441#ifdef CONFIG_IEEE80211W
442 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800443 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
444 wpa_s->conf->pmf : ssid->ieee80211w) ==
445 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
447 "frame protection");
448 break;
449 }
450#endif /* CONFIG_IEEE80211W */
451
452 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
453 return 1;
454 }
455
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700456 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
458 proto_match++;
459
460 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
462 "failed");
463 break;
464 }
465
466 if (wep_ok &&
467 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
468 {
469 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
470 "in WPA IE");
471 return 1;
472 }
473
474 if (!(ie.proto & ssid->proto)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
476 "mismatch");
477 break;
478 }
479
480 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
482 "cipher mismatch");
483 break;
484 }
485
486 if (!(ie.group_cipher & ssid->group_cipher)) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
488 "cipher mismatch");
489 break;
490 }
491
492 if (!(ie.key_mgmt & ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
494 "mismatch");
495 break;
496 }
497
498 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
499 return 1;
500 }
501
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700502 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
503 !rsn_ie) {
504 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
505 return 1;
506 }
507
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
509 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
511 return 0;
512 }
513
514 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
516 return 1;
517 }
518
519 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
520 "WPA/WPA2");
521
522 return 0;
523}
524
525
526static int freq_allowed(int *freqs, int freq)
527{
528 int i;
529
530 if (freqs == NULL)
531 return 1;
532
533 for (i = 0; freqs[i]; i++)
534 if (freqs[i] == freq)
535 return 1;
536 return 0;
537}
538
539
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540static int ht_supported(const struct hostapd_hw_modes *mode)
541{
542 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
543 /*
544 * The driver did not indicate whether it supports HT. Assume
545 * it does to avoid connection issues.
546 */
547 return 1;
548 }
549
550 /*
551 * IEEE Std 802.11n-2009 20.1.1:
552 * An HT non-AP STA shall support all EQM rates for one spatial stream.
553 */
554 return mode->mcs_set[0] == 0xff;
555}
556
557
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700558static int vht_supported(const struct hostapd_hw_modes *mode)
559{
560 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
561 /*
562 * The driver did not indicate whether it supports VHT. Assume
563 * it does to avoid connection issues.
564 */
565 return 1;
566 }
567
568 /*
569 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
570 * TODO: Verify if this complies with the standard
571 */
572 return (mode->vht_mcs_set[0] & 0x3) != 3;
573}
574
575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700576static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800577{
578 const struct hostapd_hw_modes *mode = NULL, *modes;
579 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
580 const u8 *rate_ie;
581 int i, j, k;
582
583 if (bss->freq == 0)
584 return 1; /* Cannot do matching without knowing band */
585
586 modes = wpa_s->hw.modes;
587 if (modes == NULL) {
588 /*
589 * The driver does not provide any additional information
590 * about the utilized hardware, so allow the connection attempt
591 * to continue.
592 */
593 return 1;
594 }
595
596 for (i = 0; i < wpa_s->hw.num_modes; i++) {
597 for (j = 0; j < modes[i].num_channels; j++) {
598 int freq = modes[i].channels[j].freq;
599 if (freq == bss->freq) {
600 if (mode &&
601 mode->mode == HOSTAPD_MODE_IEEE80211G)
602 break; /* do not allow 802.11b replace
603 * 802.11g */
604 mode = &modes[i];
605 break;
606 }
607 }
608 }
609
610 if (mode == NULL)
611 return 0;
612
613 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700614 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 if (rate_ie == NULL)
616 continue;
617
618 for (j = 2; j < rate_ie[1] + 2; j++) {
619 int flagged = !!(rate_ie[j] & 0x80);
620 int r = (rate_ie[j] & 0x7f) * 5;
621
622 /*
623 * IEEE Std 802.11n-2009 7.3.2.2:
624 * The new BSS Membership selector value is encoded
625 * like a legacy basic rate, but it is not a rate and
626 * only indicates if the BSS members are required to
627 * support the mandatory features of Clause 20 [HT PHY]
628 * in order to join the BSS.
629 */
630 if (flagged && ((rate_ie[j] & 0x7f) ==
631 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
632 if (!ht_supported(mode)) {
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " hardware does not support "
635 "HT PHY");
636 return 0;
637 }
638 continue;
639 }
640
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700641 /* There's also a VHT selector for 802.11ac */
642 if (flagged && ((rate_ie[j] & 0x7f) ==
643 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
644 if (!vht_supported(mode)) {
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " hardware does not support "
647 "VHT PHY");
648 return 0;
649 }
650 continue;
651 }
652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653 if (!flagged)
654 continue;
655
656 /* check for legacy basic rates */
657 for (k = 0; k < mode->num_rates; k++) {
658 if (mode->rates[k] == r)
659 break;
660 }
661 if (k == mode->num_rates) {
662 /*
663 * IEEE Std 802.11-2007 7.3.2.2 demands that in
664 * order to join a BSS all required rates
665 * have to be supported by the hardware.
666 */
667 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
668 "not support required rate %d.%d Mbps",
669 r / 10, r % 10);
670 return 0;
671 }
672 }
673 }
674
675 return 1;
676}
677
678
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800679static int bss_is_dmg(struct wpa_bss *bss)
680{
681 return bss->freq > 45000;
682}
683
684
685/*
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
688 */
689static int bss_is_ess(struct wpa_bss *bss)
690{
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
694 }
695
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
697 IEEE80211_CAP_ESS);
698}
699
700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700702 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 struct wpa_ssid *group)
704{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700705 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 int wpa;
707 struct wpa_blacklist *e;
708 const u8 *ie;
709 struct wpa_ssid *ssid;
710
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700711 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 wpa_ie_len = ie ? ie[1] : 0;
713
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700714 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 rsn_ie_len = ie ? ie[1] : 0;
716
717 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidt96571392013-10-14 12:54:46 -0700718 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700719 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700721 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
722 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
723 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
724 " p2p" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725
726 e = wpa_blacklist_get(wpa_s, bss->bssid);
727 if (e) {
728 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 /*
731 * When only a single network is enabled, we can
732 * trigger blacklisting on the first failure. This
733 * should not be done with multiple enabled networks to
734 * avoid getting forced to move into a worse ESS on
735 * single error if there are no other BSSes of the
736 * current ESS.
737 */
738 limit = 0;
739 }
740 if (e->count > limit) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
742 "(count=%d limit=%d)", e->count, limit);
743 return NULL;
744 }
745 }
746
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700747 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
749 return NULL;
750 }
751
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800752 if (disallowed_bssid(wpa_s, bss->bssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
754 return NULL;
755 }
756
757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
759 return NULL;
760 }
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
763
764 for (ssid = group; ssid; ssid = ssid->pnext) {
765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700766 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767
Dmitry Shmidt04949592012-07-19 12:16:46 -0700768 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
770 continue;
771 }
772
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700773 res = wpas_temp_disabled(wpa_s, ssid);
774 if (res > 0) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
776 "temporarily for %d second(s)", res);
777 continue;
778 }
779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780#ifdef CONFIG_WPS
781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
783 "(WPS)");
784 continue;
785 }
786
787 if (wpa && ssid->ssid_len == 0 &&
788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
789 check_ssid = 0;
790
791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
792 /* Only allow wildcard SSID match if an AP
793 * advertises active WPS operation that matches
794 * with our mode. */
795 check_ssid = 1;
796 if (ssid->ssid_len == 0 &&
797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
798 check_ssid = 0;
799 }
800#endif /* CONFIG_WPS */
801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 if (ssid->bssid_set && ssid->ssid_len == 0 &&
803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
804 check_ssid = 0;
805
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700807 (bss->ssid_len != ssid->ssid_len ||
808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
810 continue;
811 }
812
813 if (ssid->bssid_set &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
816 continue;
817 }
818
819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
820 continue;
821
822 if (!wpa &&
823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
827 "not allowed");
828 continue;
829 }
830
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
832 has_wep_key(ssid)) {
833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
834 continue;
835 }
836
Jouni Malinen75ecf522011-06-27 15:19:46 -0700837 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
839 "mismatch");
840 continue;
841 }
842
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800843 if (!bss_is_ess(bss)) {
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 continue;
846 }
847
848 if (!freq_allowed(ssid->freq_list, bss->freq)) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
850 "allowed");
851 continue;
852 }
853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854 if (!rate_match(wpa_s, bss)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
856 "not match");
857 continue;
858 }
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700861 if (ssid->p2p_group &&
862 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
863 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
865 continue;
866 }
867
Dmitry Shmidt54605472013-11-08 11:10:19 -0800868 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
869 struct wpabuf *p2p_ie;
870 u8 dev_addr[ETH_ALEN];
871
872 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
873 if (ie == NULL) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
875 continue;
876 }
877 p2p_ie = wpa_bss_get_vendor_ie_multi(
878 bss, P2P_IE_VENDOR_TYPE);
879 if (p2p_ie == NULL) {
880 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
881 continue;
882 }
883
884 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
885 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
886 ETH_ALEN) != 0) {
887 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
888 wpabuf_free(p2p_ie);
889 continue;
890 }
891 wpabuf_free(p2p_ie);
892 }
893
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 /*
895 * TODO: skip the AP if its P2P IE has Group Formation
896 * bit set in the P2P Group Capability Bitmap and we
897 * are not in Group Formation with that device.
898 */
899#endif /* CONFIG_P2P */
900
901 /* Matching configuration found */
902 return ssid;
903 }
904
905 /* No matching configuration found */
906 return NULL;
907}
908
909
910static struct wpa_bss *
911wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 struct wpa_ssid *group,
913 struct wpa_ssid **selected_ssid)
914{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700915 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916
917 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
918 group->priority);
919
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
921 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
923 if (!*selected_ssid)
924 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
926 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700927 MAC2STR(bss->bssid),
928 wpa_ssid_txt(bss->ssid, bss->ssid_len));
929 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 }
931
932 return NULL;
933}
934
935
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700936struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
937 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938{
939 struct wpa_bss *selected = NULL;
940 int prio;
941
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700942 if (wpa_s->last_scan_res == NULL ||
943 wpa_s->last_scan_res_used == 0)
944 return NULL; /* no scan results from last update */
945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 while (selected == NULL) {
947 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
948 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700949 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 selected_ssid);
951 if (selected)
952 break;
953 }
954
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800955 if (selected == NULL && wpa_s->blacklist &&
956 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
958 "blacklist and try again");
959 wpa_blacklist_clear(wpa_s);
960 wpa_s->blacklist_cleared++;
961 } else if (selected == NULL)
962 break;
963 }
964
965 return selected;
966}
967
968
969static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
970 int timeout_sec, int timeout_usec)
971{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700972 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973 /*
974 * No networks are enabled; short-circuit request so
975 * we don't wait timeout seconds before transitioning
976 * to INACTIVE state.
977 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700978 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
979 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700981#ifdef CONFIG_P2P
982 wpa_s->sta_scan_pending = 0;
983#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 return;
985 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800986
987 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
989}
990
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700992int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 struct wpa_bss *selected,
994 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995{
996 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
997 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
998 "PBC session overlap");
999#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001001 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002#endif /* CONFIG_P2P */
1003
1004#ifdef CONFIG_WPS
1005 wpas_wps_cancel(wpa_s);
1006#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001007 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008 }
1009
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001010 wpa_msg(wpa_s, MSG_DEBUG,
1011 "Considering connect request: reassociate: %d selected: "
1012 MACSTR " bssid: " MACSTR " pending: " MACSTR
1013 " wpa_state: %s ssid=%p current_ssid=%p",
1014 wpa_s->reassociate, MAC2STR(selected->bssid),
1015 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1016 wpa_supplicant_state_txt(wpa_s->wpa_state),
1017 ssid, wpa_s->current_ssid);
1018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 /*
1020 * Do not trigger new association unless the BSSID has changed or if
1021 * reassociation is requested. If we are in process of associating with
1022 * the selected BSSID, do not trigger new attempt.
1023 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1026 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1027 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001028 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1029 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1030 0) ||
1031 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1032 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1034 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001035 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001037 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1038 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 wpa_supplicant_associate(wpa_s, selected, ssid);
1040 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001041 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1042 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001045 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046}
1047
1048
1049static struct wpa_ssid *
1050wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1051{
1052 int prio;
1053 struct wpa_ssid *ssid;
1054
1055 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1056 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1057 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001058 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059 continue;
1060 if (ssid->mode == IEEE80211_MODE_IBSS ||
1061 ssid->mode == IEEE80211_MODE_AP)
1062 return ssid;
1063 }
1064 }
1065 return NULL;
1066}
1067
1068
1069/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1070 * on BSS added and BSS changed events */
1071static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001072 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001074 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075
1076 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1077 return;
1078
Jouni Malinen87fd2792011-05-16 18:35:42 +03001079 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081
Jouni Malinen87fd2792011-05-16 18:35:42 +03001082 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 if (ssid == NULL)
1084 continue;
1085
Jouni Malinen87fd2792011-05-16 18:35:42 +03001086 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 if (rsn == NULL)
1088 continue;
1089
Jouni Malinen87fd2792011-05-16 18:35:42 +03001090 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 }
1092
1093}
1094
1095
1096static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1097 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001098 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001100 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 int min_diff;
1102
1103 if (wpa_s->reassociate)
1104 return 1; /* explicit request to reassociate */
1105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1106 return 1; /* we are not associated; continue */
1107 if (wpa_s->current_ssid == NULL)
1108 return 1; /* unknown current SSID */
1109 if (wpa_s->current_ssid != ssid)
1110 return 1; /* different network block */
1111
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001112 if (wpas_driver_bss_selection(wpa_s))
1113 return 0; /* Driver-based roaming */
1114
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001115 if (wpa_s->current_ssid->ssid)
1116 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1117 wpa_s->current_ssid->ssid,
1118 wpa_s->current_ssid->ssid_len);
1119 if (!current_bss)
1120 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121
1122 if (!current_bss)
1123 return 1; /* current BSS not seen in scan results */
1124
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001125 if (current_bss == selected)
1126 return 0;
1127
1128 if (selected->last_update_idx > current_bss->last_update_idx)
1129 return 1; /* current BSS not seen in the last scan */
1130
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001131#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1133 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1134 MAC2STR(current_bss->bssid), current_bss->level);
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1136 MAC2STR(selected->bssid), selected->level);
1137
1138 if (wpa_s->current_ssid->bssid_set &&
1139 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1140 0) {
1141 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1142 "has preferred BSSID");
1143 return 1;
1144 }
1145
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001146 if (current_bss->level < 0 && current_bss->level > selected->level) {
1147 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1148 "signal level");
1149 return 0;
1150 }
1151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 min_diff = 2;
1153 if (current_bss->level < 0) {
1154 if (current_bss->level < -85)
1155 min_diff = 1;
1156 else if (current_bss->level < -80)
1157 min_diff = 2;
1158 else if (current_bss->level < -75)
1159 min_diff = 3;
1160 else if (current_bss->level < -70)
1161 min_diff = 4;
1162 else
1163 min_diff = 5;
1164 }
1165 if (abs(current_bss->level - selected->level) < min_diff) {
1166 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1167 "in signal level");
1168 return 0;
1169 }
1170
1171 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001172#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001173 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001174#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175}
1176
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001177
Jouni Malinen89ca7022012-09-14 13:03:12 -07001178/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001179 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001180static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001181 union wpa_event_data *data,
1182 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 struct wpa_scan_results *scan_res;
1185 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001186#ifndef CONFIG_NO_RANDOM_POOL
1187 size_t i, num;
1188#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189
1190#ifdef CONFIG_AP
1191 if (wpa_s->ap_iface)
1192 ap = 1;
1193#endif /* CONFIG_AP */
1194
1195 wpa_supplicant_notify_scanning(wpa_s, 0);
1196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001198 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001199 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001200 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1201 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001202 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001203 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1204 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1205 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001206 wpa_s->sta_scan_pending = 1;
1207 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001208 return -1;
1209 }
1210 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001211 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001212#endif /* CONFIG_P2P */
1213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1215 data ? &data->scan_info :
1216 NULL, 1);
1217 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001218 if (wpa_s->conf->ap_scan == 2 || ap ||
1219 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001221 if (!own_request)
1222 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1224 "scanning again");
1225 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1226 return -1;
1227 }
1228
1229#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 num = scan_res->num;
1231 if (num > 10)
1232 num = 10;
1233 for (i = 0; i < num; i++) {
1234 u8 buf[5];
1235 struct wpa_scan_res *res = scan_res->res[i];
1236 buf[0] = res->bssid[5];
1237 buf[1] = res->qual & 0xff;
1238 buf[2] = res->noise & 0xff;
1239 buf[3] = res->level & 0xff;
1240 buf[4] = res->tsf & 0xff;
1241 random_add_randomness(buf, sizeof(buf));
1242 }
1243#endif /* CONFIG_NO_RANDOM_POOL */
1244
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001245 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1247 struct wpa_scan_results *scan_res);
1248
1249 scan_res_handler = wpa_s->scan_res_handler;
1250 wpa_s->scan_res_handler = NULL;
1251 scan_res_handler(wpa_s, scan_res);
1252
1253 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001254 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 }
1256
1257 if (ap) {
1258 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1259#ifdef CONFIG_AP
1260 if (wpa_s->ap_iface->scan_cb)
1261 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1262#endif /* CONFIG_AP */
1263 wpa_scan_results_free(scan_res);
1264 return 0;
1265 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001266
Dmitry Shmidt04949592012-07-19 12:16:46 -07001267 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1268 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1269 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270
1271 wpas_notify_scan_done(wpa_s, 1);
1272
Dmitry Shmidt04949592012-07-19 12:16:46 -07001273 if (sme_proc_obss_scan(wpa_s) > 0) {
1274 wpa_scan_results_free(scan_res);
1275 return 0;
1276 }
1277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1279 wpa_scan_results_free(scan_res);
1280 return 0;
1281 }
1282
Dmitry Shmidt04949592012-07-19 12:16:46 -07001283 if (autoscan_notify_scan(wpa_s, scan_res)) {
1284 wpa_scan_results_free(scan_res);
1285 return 0;
1286 }
1287
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 if (wpa_s->disconnected) {
1289 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1290 wpa_scan_results_free(scan_res);
1291 return 0;
1292 }
1293
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001294 if (!wpas_driver_bss_selection(wpa_s) &&
1295 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001296 wpa_scan_results_free(scan_res);
1297 return 0;
1298 }
1299
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300 wpas_wps_update_ap_info(wpa_s, scan_res);
1301
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001302 wpa_scan_results_free(scan_res);
1303
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001304 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001305}
1306
1307
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001308static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001309 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001310{
1311 struct wpa_bss *selected;
1312 struct wpa_ssid *ssid = NULL;
1313
1314 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315
1316 if (selected) {
1317 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001318 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001319 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001320 if (new_scan)
1321 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001323 }
1324
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001325 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001326 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001327 return -1;
1328 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001329 if (new_scan)
1330 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001331 /*
1332 * Do not notify other virtual radios of scan results since we do not
1333 * want them to start other associations at the same time.
1334 */
1335 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1338 ssid = wpa_supplicant_pick_new_network(wpa_s);
1339 if (ssid) {
1340 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1341 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001342 if (new_scan)
1343 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001344 } else if (own_request) {
1345 /*
1346 * No SSID found. If SCAN results are as a result of
1347 * own scan request and not due to a scan request on
1348 * another shared interface, try another scan.
1349 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 int timeout_sec = wpa_s->scan_interval;
1351 int timeout_usec = 0;
1352#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001353 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1354 return 0;
1355
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001356 if (wpa_s->p2p_in_provisioning ||
1357 wpa_s->show_group_started) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001358 /*
1359 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001360 * state and during P2P join-a-group operation
1361 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 */
1363 timeout_sec = 0;
1364 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001365 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1366 timeout_usec);
1367 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001368 }
1369#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001370#ifdef CONFIG_INTERWORKING
1371 if (wpa_s->conf->auto_interworking &&
1372 wpa_s->conf->interworking &&
1373 wpa_s->conf->cred) {
1374 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1375 "start ANQP fetch since no matching "
1376 "networks found");
1377 wpa_s->network_select = 1;
1378 wpa_s->auto_network_select = 1;
1379 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001380 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001381 }
1382#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001383 if (wpa_supplicant_req_sched_scan(wpa_s))
1384 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1385 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 }
1387 }
1388 return 0;
1389}
1390
1391
1392static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1393 union wpa_event_data *data)
1394{
1395 const char *rn, *rn2;
1396 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001397
1398 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 /*
1400 * If no scan results could be fetched, then no need to
1401 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001402 * this scan. Similarly, if scan results started a new operation on this
1403 * interface, do not notify other interfaces to avoid concurrent
1404 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 */
1406 return;
1407 }
1408
1409 /*
1410 * Check other interfaces to see if they have the same radio-name. If
1411 * so, they get updated with this same scan info.
1412 */
1413 if (!wpa_s->driver->get_radio_name)
1414 return;
1415
1416 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1417 if (rn == NULL || rn[0] == '\0')
1418 return;
1419
1420 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1421 "sharing same radio (%s) in event_scan_results", rn);
1422
1423 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1424 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1425 continue;
1426
1427 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1428 if (rn2 && os_strcmp(rn, rn2) == 0) {
1429 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1430 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001431 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 }
1433 }
1434}
1435
1436#endif /* CONFIG_NO_SCAN_PROCESSING */
1437
1438
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001439int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1440{
1441#ifdef CONFIG_NO_SCAN_PROCESSING
1442 return -1;
1443#else /* CONFIG_NO_SCAN_PROCESSING */
1444 struct os_time now;
1445
1446 if (wpa_s->last_scan_res_used <= 0)
1447 return -1;
1448
1449 os_get_time(&now);
1450 if (now.sec - wpa_s->last_scan.sec > 5) {
1451 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1452 return -1;
1453 }
1454
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001455 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001456#endif /* CONFIG_NO_SCAN_PROCESSING */
1457}
1458
Dmitry Shmidt04949592012-07-19 12:16:46 -07001459#ifdef CONFIG_WNM
1460
1461static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1462{
1463 struct wpa_supplicant *wpa_s = eloop_ctx;
1464
1465 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1466 return;
1467
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001468 if (!wpa_s->no_keep_alive) {
1469 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1470 MAC2STR(wpa_s->bssid));
1471 /* TODO: could skip this if normal data traffic has been sent */
1472 /* TODO: Consider using some more appropriate data frame for
1473 * this */
1474 if (wpa_s->l2)
1475 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1476 (u8 *) "", 0);
1477 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001478
1479#ifdef CONFIG_SME
1480 if (wpa_s->sme.bss_max_idle_period) {
1481 unsigned int msec;
1482 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1483 if (msec > 100)
1484 msec -= 100;
1485 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1486 wnm_bss_keep_alive, wpa_s, NULL);
1487 }
1488#endif /* CONFIG_SME */
1489}
1490
1491
1492static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1493 const u8 *ies, size_t ies_len)
1494{
1495 struct ieee802_11_elems elems;
1496
1497 if (ies == NULL)
1498 return;
1499
1500 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1501 return;
1502
1503#ifdef CONFIG_SME
1504 if (elems.bss_max_idle_period) {
1505 unsigned int msec;
1506 wpa_s->sme.bss_max_idle_period =
1507 WPA_GET_LE16(elems.bss_max_idle_period);
1508 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1509 "TU)%s", wpa_s->sme.bss_max_idle_period,
1510 (elems.bss_max_idle_period[2] & 0x01) ?
1511 " (protected keep-live required)" : "");
1512 if (wpa_s->sme.bss_max_idle_period == 0)
1513 wpa_s->sme.bss_max_idle_period = 1;
1514 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1515 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1516 /* msec times 1000 */
1517 msec = wpa_s->sme.bss_max_idle_period * 1024;
1518 if (msec > 100)
1519 msec -= 100;
1520 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1521 wnm_bss_keep_alive, wpa_s,
1522 NULL);
1523 }
1524 }
1525#endif /* CONFIG_SME */
1526}
1527
1528#endif /* CONFIG_WNM */
1529
1530
1531void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1532{
1533#ifdef CONFIG_WNM
1534 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1535#endif /* CONFIG_WNM */
1536}
1537
1538
Dmitry Shmidt051af732013-10-22 13:52:46 -07001539#ifdef CONFIG_INTERWORKING
1540
1541static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1542 size_t len)
1543{
1544 int res;
1545
1546 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1547 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1548 if (res) {
1549 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1550 }
1551
1552 return res;
1553}
1554
1555
1556static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1557 const u8 *ies, size_t ies_len)
1558{
1559 struct ieee802_11_elems elems;
1560
1561 if (ies == NULL)
1562 return;
1563
1564 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1565 return;
1566
1567 if (elems.qos_map_set) {
1568 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1569 elems.qos_map_set_len);
1570 }
1571}
1572
1573#endif /* CONFIG_INTERWORKING */
1574
1575
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001576static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1577 union wpa_event_data *data)
1578{
1579 int l, len, found = 0, wpa_found, rsn_found;
1580 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001581#ifdef CONFIG_IEEE80211R
1582 u8 bssid[ETH_ALEN];
1583#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001584
1585 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1586 if (data->assoc_info.req_ies)
1587 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1588 data->assoc_info.req_ies_len);
1589 if (data->assoc_info.resp_ies) {
1590 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1591 data->assoc_info.resp_ies_len);
1592#ifdef CONFIG_TDLS
1593 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1594 data->assoc_info.resp_ies_len);
1595#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001596#ifdef CONFIG_WNM
1597 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1598 data->assoc_info.resp_ies_len);
1599#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001600#ifdef CONFIG_INTERWORKING
1601 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1602 data->assoc_info.resp_ies_len);
1603#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 }
1605 if (data->assoc_info.beacon_ies)
1606 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1607 data->assoc_info.beacon_ies,
1608 data->assoc_info.beacon_ies_len);
1609 if (data->assoc_info.freq)
1610 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1611 data->assoc_info.freq);
1612
1613 p = data->assoc_info.req_ies;
1614 l = data->assoc_info.req_ies_len;
1615
1616 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1617 while (p && l >= 2) {
1618 len = p[1] + 2;
1619 if (len > l) {
1620 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1621 p, l);
1622 break;
1623 }
1624 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1625 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1626 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1627 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1628 break;
1629 found = 1;
1630 wpa_find_assoc_pmkid(wpa_s);
1631 break;
1632 }
1633 l -= len;
1634 p += len;
1635 }
1636 if (!found && data->assoc_info.req_ies)
1637 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1638
1639#ifdef CONFIG_IEEE80211R
1640#ifdef CONFIG_SME
1641 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1643 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1644 data->assoc_info.resp_ies,
1645 data->assoc_info.resp_ies_len,
1646 bssid) < 0) {
1647 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1648 "Reassociation Response failed");
1649 wpa_supplicant_deauthenticate(
1650 wpa_s, WLAN_REASON_INVALID_IE);
1651 return -1;
1652 }
1653 }
1654
1655 p = data->assoc_info.resp_ies;
1656 l = data->assoc_info.resp_ies_len;
1657
1658#ifdef CONFIG_WPS_STRICT
1659 if (p && wpa_s->current_ssid &&
1660 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1661 struct wpabuf *wps;
1662 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1663 if (wps == NULL) {
1664 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1665 "include WPS IE in (Re)Association Response");
1666 return -1;
1667 }
1668
1669 if (wps_validate_assoc_resp(wps) < 0) {
1670 wpabuf_free(wps);
1671 wpa_supplicant_deauthenticate(
1672 wpa_s, WLAN_REASON_INVALID_IE);
1673 return -1;
1674 }
1675 wpabuf_free(wps);
1676 }
1677#endif /* CONFIG_WPS_STRICT */
1678
1679 /* Go through the IEs and make a copy of the MDIE, if present. */
1680 while (p && l >= 2) {
1681 len = p[1] + 2;
1682 if (len > l) {
1683 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1684 p, l);
1685 break;
1686 }
1687 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1688 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1689 wpa_s->sme.ft_used = 1;
1690 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1691 MOBILITY_DOMAIN_ID_LEN);
1692 break;
1693 }
1694 l -= len;
1695 p += len;
1696 }
1697#endif /* CONFIG_SME */
1698
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001699 /* Process FT when SME is in the driver */
1700 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1701 wpa_ft_is_completed(wpa_s->wpa)) {
1702 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1703 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1704 data->assoc_info.resp_ies,
1705 data->assoc_info.resp_ies_len,
1706 bssid) < 0) {
1707 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1708 "Reassociation Response failed");
1709 wpa_supplicant_deauthenticate(
1710 wpa_s, WLAN_REASON_INVALID_IE);
1711 return -1;
1712 }
1713 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1714 }
1715
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001716 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1717 data->assoc_info.resp_ies_len);
1718#endif /* CONFIG_IEEE80211R */
1719
1720 /* WPA/RSN IE from Beacon/ProbeResp */
1721 p = data->assoc_info.beacon_ies;
1722 l = data->assoc_info.beacon_ies_len;
1723
1724 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1725 */
1726 wpa_found = rsn_found = 0;
1727 while (p && l >= 2) {
1728 len = p[1] + 2;
1729 if (len > l) {
1730 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1731 p, l);
1732 break;
1733 }
1734 if (!wpa_found &&
1735 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1736 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1737 wpa_found = 1;
1738 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1739 }
1740
1741 if (!rsn_found &&
1742 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1743 rsn_found = 1;
1744 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1745 }
1746
1747 l -= len;
1748 p += len;
1749 }
1750
1751 if (!wpa_found && data->assoc_info.beacon_ies)
1752 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1753 if (!rsn_found && data->assoc_info.beacon_ies)
1754 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1755 if (wpa_found || rsn_found)
1756 wpa_s->ap_ies_from_associnfo = 1;
1757
Jouni Malinen87fd2792011-05-16 18:35:42 +03001758 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1759 wpa_s->assoc_freq != data->assoc_info.freq) {
1760 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1761 "%u to %u MHz",
1762 wpa_s->assoc_freq, data->assoc_info.freq);
1763 wpa_supplicant_update_scan_results(wpa_s);
1764 }
1765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766 wpa_s->assoc_freq = data->assoc_info.freq;
1767
1768 return 0;
1769}
1770
1771
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001772static struct wpa_bss * wpa_supplicant_get_new_bss(
1773 struct wpa_supplicant *wpa_s, const u8 *bssid)
1774{
1775 struct wpa_bss *bss = NULL;
1776 struct wpa_ssid *ssid = wpa_s->current_ssid;
1777
1778 if (ssid->ssid_len > 0)
1779 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1780 if (!bss)
1781 bss = wpa_bss_get_bssid(wpa_s, bssid);
1782
1783 return bss;
1784}
1785
1786
1787static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1788{
1789 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1790
1791 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1792 return -1;
1793
1794 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1795 return 0;
1796
1797 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1798 WPA_IE_VENDOR_TYPE);
1799 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1800
1801 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1802 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1803 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1804 bss_rsn ? 2 + bss_rsn[1] : 0))
1805 return -1;
1806
1807 return 0;
1808}
1809
1810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1812 union wpa_event_data *data)
1813{
1814 u8 bssid[ETH_ALEN];
1815 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816
1817#ifdef CONFIG_AP
1818 if (wpa_s->ap_iface) {
1819 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1820 data->assoc_info.addr,
1821 data->assoc_info.req_ies,
1822 data->assoc_info.req_ies_len,
1823 data->assoc_info.reassoc);
1824 return;
1825 }
1826#endif /* CONFIG_AP */
1827
1828 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1829 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1830 return;
1831
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001832 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1833 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001834 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001835 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1836 return;
1837 }
1838
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001840 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1842 MACSTR, MAC2STR(bssid));
1843 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1845 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001846 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001847
1848 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1849 wpa_clear_keys(wpa_s, bssid);
1850 }
1851 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001852 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001853 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1854 return;
1855 }
1856 if (wpa_s->current_ssid) {
1857 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001858
1859 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1860 if (!bss) {
1861 wpa_supplicant_update_scan_results(wpa_s);
1862
1863 /* Get the BSS from the new scan results */
1864 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1865 }
1866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001867 if (bss)
1868 wpa_s->current_bss = bss;
1869 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001870
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001871#ifdef ANDROID
1872 if (wpa_s->conf->ap_scan == 1) {
1873#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001874 if (wpa_s->conf->ap_scan == 1 &&
1875 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001876#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001877 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1878 wpa_msg(wpa_s, MSG_WARNING,
1879 "WPA/RSN IEs not updated");
1880 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881 }
1882
1883#ifdef CONFIG_SME
1884 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1885 wpa_s->sme.prev_bssid_set = 1;
1886#endif /* CONFIG_SME */
1887
1888 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1889 if (wpa_s->current_ssid) {
1890 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1891 * initialized before association, but for other modes,
1892 * initialize PC/SC here, if the current configuration needs
1893 * smartcard or SIM/USIM. */
1894 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1895 }
1896 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1897 if (wpa_s->l2)
1898 l2_packet_notify_auth_start(wpa_s->l2);
1899
1900 /*
1901 * Set portEnabled first to FALSE in order to get EAP state machine out
1902 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1903 * state machine may transit to AUTHENTICATING state based on obsolete
1904 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1905 * AUTHENTICATED without ever giving chance to EAP state machine to
1906 * reset the state.
1907 */
1908 if (!ft_completed) {
1909 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1910 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1911 }
1912 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1913 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1914 /* 802.1X::portControl = Auto */
1915 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1916 wpa_s->eapol_received = 0;
1917 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1918 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1919 (wpa_s->current_ssid &&
1920 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001921 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1922 (wpa_s->drv_flags &
1923 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1924 /*
1925 * Set the key after having received joined-IBSS event
1926 * from the driver.
1927 */
1928 wpa_supplicant_set_wpa_none_key(wpa_s,
1929 wpa_s->current_ssid);
1930 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931 wpa_supplicant_cancel_auth_timeout(wpa_s);
1932 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1933 } else if (!ft_completed) {
1934 /* Timeout for receiving the first EAPOL packet */
1935 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1936 }
1937 wpa_supplicant_cancel_scan(wpa_s);
1938
1939 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1940 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1941 /*
1942 * We are done; the driver will take care of RSN 4-way
1943 * handshake.
1944 */
1945 wpa_supplicant_cancel_auth_timeout(wpa_s);
1946 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1947 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1948 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1949 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1950 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1951 /*
1952 * The driver will take care of RSN 4-way handshake, so we need
1953 * to allow EAPOL supplicant to complete its work without
1954 * waiting for WPA supplicant.
1955 */
1956 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1957 } else if (ft_completed) {
1958 /*
1959 * FT protocol completed - make sure EAPOL state machine ends
1960 * up in authenticated.
1961 */
1962 wpa_supplicant_cancel_auth_timeout(wpa_s);
1963 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1964 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1965 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1966 }
1967
Jouni Malinena05074c2012-12-21 21:35:35 +02001968 wpa_s->last_eapol_matches_bssid = 0;
1969
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001970 if (wpa_s->pending_eapol_rx) {
1971 struct os_time now, age;
1972 os_get_time(&now);
1973 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1974 if (age.sec == 0 && age.usec < 100000 &&
1975 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1976 0) {
1977 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1978 "frame that was received just before "
1979 "association notification");
1980 wpa_supplicant_rx_eapol(
1981 wpa_s, wpa_s->pending_eapol_rx_src,
1982 wpabuf_head(wpa_s->pending_eapol_rx),
1983 wpabuf_len(wpa_s->pending_eapol_rx));
1984 }
1985 wpabuf_free(wpa_s->pending_eapol_rx);
1986 wpa_s->pending_eapol_rx = NULL;
1987 }
1988
1989 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1990 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001991 wpa_s->current_ssid &&
1992 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993 /* Set static WEP keys again */
1994 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1995 }
1996
1997#ifdef CONFIG_IBSS_RSN
1998 if (wpa_s->current_ssid &&
1999 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2000 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2001 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2002 wpa_s->ibss_rsn == NULL) {
2003 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2004 if (!wpa_s->ibss_rsn) {
2005 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2006 wpa_supplicant_deauthenticate(
2007 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2008 return;
2009 }
2010
2011 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2012 }
2013#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002014
2015 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002016}
2017
2018
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002019static int disconnect_reason_recoverable(u16 reason_code)
2020{
2021 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2022 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2023 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2024}
2025
2026
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002027static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002028 u16 reason_code,
2029 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030{
2031 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002032
2033 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2034 /*
2035 * At least Host AP driver and a Prism3 card seemed to be
2036 * generating streams of disconnected events when configuring
2037 * IBSS for WPA-None. Ignore them for now.
2038 */
2039 return;
2040 }
2041
2042 bssid = wpa_s->bssid;
2043 if (is_zero_ether_addr(bssid))
2044 bssid = wpa_s->pending_bssid;
2045
2046 if (!is_zero_ether_addr(bssid) ||
2047 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2048 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2049 " reason=%d%s",
2050 MAC2STR(bssid), reason_code,
2051 locally_generated ? " locally_generated=1" : "");
2052 }
2053}
2054
2055
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002056static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2057 int locally_generated)
2058{
2059 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2060 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2061 return 0; /* Not in 4-way handshake with PSK */
2062
2063 /*
2064 * It looks like connection was lost while trying to go through PSK
2065 * 4-way handshake. Filter out known disconnection cases that are caused
2066 * by something else than PSK mismatch to avoid confusing reports.
2067 */
2068
2069 if (locally_generated) {
2070 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2071 return 0;
2072 }
2073
2074 return 1;
2075}
2076
2077
Jouni Malinen2b89da82012-08-31 22:04:41 +03002078static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2079 u16 reason_code,
2080 int locally_generated)
2081{
2082 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083 int authenticating;
2084 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002085 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002086#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002087 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002088#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002089 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090
2091 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2092 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2093
2094 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2095 /*
2096 * At least Host AP driver and a Prism3 card seemed to be
2097 * generating streams of disconnected events when configuring
2098 * IBSS for WPA-None. Ignore them for now.
2099 */
2100 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2101 "IBSS/WPA-None mode");
2102 return;
2103 }
2104
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002105 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2107 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002108 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2109 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002110 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002112 if (!wpa_s->disconnected &&
2113 (!wpa_s->auto_reconnect_disabled ||
2114 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002115 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2116 "reconnect (wps=%d wpa_state=%d)",
2117 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2118 wpa_s->wpa_state);
2119 if (wpa_s->wpa_state == WPA_COMPLETED &&
2120 wpa_s->current_ssid &&
2121 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002122 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002123 disconnect_reason_recoverable(reason_code)) {
2124 /*
2125 * It looks like the AP has dropped association with
2126 * us, but could allow us to get back in. Try to
2127 * reconnect to the same BSS without full scan to save
2128 * time for some common cases.
2129 */
2130 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002131#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002132 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002133#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002134 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002135 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002136 else
2137 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2138 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002139 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002140 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141 "try to re-connect");
2142 wpa_s->reassociate = 0;
2143 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002144 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 }
2146 bssid = wpa_s->bssid;
2147 if (is_zero_ether_addr(bssid))
2148 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002149 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2150 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002151 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002152 if (locally_generated)
2153 wpa_s->disconnect_reason = -reason_code;
2154 else
2155 wpa_s->disconnect_reason = reason_code;
2156 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002157 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2158 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2159 wpa_s->keys_cleared = 0;
2160 wpa_clear_keys(wpa_s, wpa_s->bssid);
2161 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002162 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163 wpa_supplicant_mark_disassoc(wpa_s);
2164
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002165 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002166 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002167 wpa_s->current_ssid = last_ssid;
2168 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002169
2170 if (fast_reconnect) {
2171#ifndef CONFIG_NO_SCAN_PROCESSING
2172 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2173 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2174 fast_reconnect_ssid) < 0) {
2175 /* Recover through full scan */
2176 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2177 }
2178#endif /* CONFIG_NO_SCAN_PROCESSING */
2179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002180}
2181
2182
2183#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002184void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002185{
2186 struct wpa_supplicant *wpa_s = eloop_ctx;
2187
2188 if (!wpa_s->pending_mic_error_report)
2189 return;
2190
2191 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2192 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2193 wpa_s->pending_mic_error_report = 0;
2194}
2195#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2196
2197
2198static void
2199wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2200 union wpa_event_data *data)
2201{
2202 int pairwise;
2203 struct os_time t;
2204
2205 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2206 pairwise = (data && data->michael_mic_failure.unicast);
2207 os_get_time(&t);
2208 if ((wpa_s->last_michael_mic_error &&
2209 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2210 wpa_s->pending_mic_error_report) {
2211 if (wpa_s->pending_mic_error_report) {
2212 /*
2213 * Send the pending MIC error report immediately since
2214 * we are going to start countermeasures and AP better
2215 * do the same.
2216 */
2217 wpa_sm_key_request(wpa_s->wpa, 1,
2218 wpa_s->pending_mic_error_pairwise);
2219 }
2220
2221 /* Send the new MIC error report immediately since we are going
2222 * to start countermeasures and AP better do the same.
2223 */
2224 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2225
2226 /* initialize countermeasures */
2227 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002228
2229 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2230
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2232
2233 /*
2234 * Need to wait for completion of request frame. We do not get
2235 * any callback for the message completion, so just wait a
2236 * short while and hope for the best. */
2237 os_sleep(0, 10000);
2238
2239 wpa_drv_set_countermeasures(wpa_s, 1);
2240 wpa_supplicant_deauthenticate(wpa_s,
2241 WLAN_REASON_MICHAEL_MIC_FAILURE);
2242 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2243 wpa_s, NULL);
2244 eloop_register_timeout(60, 0,
2245 wpa_supplicant_stop_countermeasures,
2246 wpa_s, NULL);
2247 /* TODO: mark the AP rejected for 60 second. STA is
2248 * allowed to associate with another AP.. */
2249 } else {
2250#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2251 if (wpa_s->mic_errors_seen) {
2252 /*
2253 * Reduce the effectiveness of Michael MIC error
2254 * reports as a means for attacking against TKIP if
2255 * more than one MIC failure is noticed with the same
2256 * PTK. We delay the transmission of the reports by a
2257 * random time between 0 and 60 seconds in order to
2258 * force the attacker wait 60 seconds before getting
2259 * the information on whether a frame resulted in a MIC
2260 * failure.
2261 */
2262 u8 rval[4];
2263 int sec;
2264
2265 if (os_get_random(rval, sizeof(rval)) < 0)
2266 sec = os_random() % 60;
2267 else
2268 sec = WPA_GET_BE32(rval) % 60;
2269 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2270 "report %d seconds", sec);
2271 wpa_s->pending_mic_error_report = 1;
2272 wpa_s->pending_mic_error_pairwise = pairwise;
2273 eloop_cancel_timeout(
2274 wpa_supplicant_delayed_mic_error_report,
2275 wpa_s, NULL);
2276 eloop_register_timeout(
2277 sec, os_random() % 1000000,
2278 wpa_supplicant_delayed_mic_error_report,
2279 wpa_s, NULL);
2280 } else {
2281 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2282 }
2283#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2284 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2285#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2286 }
2287 wpa_s->last_michael_mic_error = t.sec;
2288 wpa_s->mic_errors_seen++;
2289}
2290
2291
2292#ifdef CONFIG_TERMINATE_ONLASTIF
2293static int any_interfaces(struct wpa_supplicant *head)
2294{
2295 struct wpa_supplicant *wpa_s;
2296
2297 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2298 if (!wpa_s->interface_removed)
2299 return 1;
2300 return 0;
2301}
2302#endif /* CONFIG_TERMINATE_ONLASTIF */
2303
2304
2305static void
2306wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2307 union wpa_event_data *data)
2308{
2309 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2310 return;
2311
2312 switch (data->interface_status.ievent) {
2313 case EVENT_INTERFACE_ADDED:
2314 if (!wpa_s->interface_removed)
2315 break;
2316 wpa_s->interface_removed = 0;
2317 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2318 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2319 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2320 "driver after interface was added");
2321 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002322 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323 break;
2324 case EVENT_INTERFACE_REMOVED:
2325 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2326 wpa_s->interface_removed = 1;
2327 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002328 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329 l2_packet_deinit(wpa_s->l2);
2330 wpa_s->l2 = NULL;
2331#ifdef CONFIG_IBSS_RSN
2332 ibss_rsn_deinit(wpa_s->ibss_rsn);
2333 wpa_s->ibss_rsn = NULL;
2334#endif /* CONFIG_IBSS_RSN */
2335#ifdef CONFIG_TERMINATE_ONLASTIF
2336 /* check if last interface */
2337 if (!any_interfaces(wpa_s->global->ifaces))
2338 eloop_terminate();
2339#endif /* CONFIG_TERMINATE_ONLASTIF */
2340 break;
2341 }
2342}
2343
2344
2345#ifdef CONFIG_PEERKEY
2346static void
2347wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2348 union wpa_event_data *data)
2349{
2350 if (data == NULL)
2351 return;
2352 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2353}
2354#endif /* CONFIG_PEERKEY */
2355
2356
2357#ifdef CONFIG_TDLS
2358static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2359 union wpa_event_data *data)
2360{
2361 if (data == NULL)
2362 return;
2363 switch (data->tdls.oper) {
2364 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002365 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2366 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2367 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2368 else
2369 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370 break;
2371 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002372 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2373 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2374 data->tdls.reason_code);
2375 else
2376 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2377 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378 break;
2379 }
2380}
2381#endif /* CONFIG_TDLS */
2382
2383
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002384#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002385static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2386 union wpa_event_data *data)
2387{
2388 if (data == NULL)
2389 return;
2390 switch (data->wnm.oper) {
2391 case WNM_OPER_SLEEP:
2392 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2393 "(action=%d, intval=%d)",
2394 data->wnm.sleep_action, data->wnm.sleep_intval);
2395 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002396 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002397 break;
2398 }
2399}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002400#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002401
2402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002403#ifdef CONFIG_IEEE80211R
2404static void
2405wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2406 union wpa_event_data *data)
2407{
2408 if (data == NULL)
2409 return;
2410
2411 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2412 data->ft_ies.ies_len,
2413 data->ft_ies.ft_action,
2414 data->ft_ies.target_ap,
2415 data->ft_ies.ric_ies,
2416 data->ft_ies.ric_ies_len) < 0) {
2417 /* TODO: prevent MLME/driver from trying to associate? */
2418 }
2419}
2420#endif /* CONFIG_IEEE80211R */
2421
2422
2423#ifdef CONFIG_IBSS_RSN
2424static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2425 union wpa_event_data *data)
2426{
2427 struct wpa_ssid *ssid;
2428 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2429 return;
2430 if (data == NULL)
2431 return;
2432 ssid = wpa_s->current_ssid;
2433 if (ssid == NULL)
2434 return;
2435 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2436 return;
2437
2438 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2439}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002440
2441
2442static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2443 union wpa_event_data *data)
2444{
2445 struct wpa_ssid *ssid = wpa_s->current_ssid;
2446
2447 if (ssid == NULL)
2448 return;
2449
2450 /* check if the ssid is correctly configured as IBSS/RSN */
2451 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2452 return;
2453
2454 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2455 data->rx_mgmt.frame_len);
2456}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002457#endif /* CONFIG_IBSS_RSN */
2458
2459
2460#ifdef CONFIG_IEEE80211R
2461static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2462 size_t len)
2463{
2464 const u8 *sta_addr, *target_ap_addr;
2465 u16 status;
2466
2467 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2468 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2469 return; /* only SME case supported for now */
2470 if (len < 1 + 2 * ETH_ALEN + 2)
2471 return;
2472 if (data[0] != 2)
2473 return; /* Only FT Action Response is supported for now */
2474 sta_addr = data + 1;
2475 target_ap_addr = data + 1 + ETH_ALEN;
2476 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2477 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2478 MACSTR " TargetAP " MACSTR " status %u",
2479 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2480
2481 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2482 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2483 " in FT Action Response", MAC2STR(sta_addr));
2484 return;
2485 }
2486
2487 if (status) {
2488 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2489 "failure (status code %d)", status);
2490 /* TODO: report error to FT code(?) */
2491 return;
2492 }
2493
2494 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2495 len - (1 + 2 * ETH_ALEN + 2), 1,
2496 target_ap_addr, NULL, 0) < 0)
2497 return;
2498
2499#ifdef CONFIG_SME
2500 {
2501 struct wpa_bss *bss;
2502 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2503 if (bss)
2504 wpa_s->sme.freq = bss->freq;
2505 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2506 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2507 WLAN_AUTH_FT);
2508 }
2509#endif /* CONFIG_SME */
2510}
2511#endif /* CONFIG_IEEE80211R */
2512
2513
2514static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2515 struct unprot_deauth *e)
2516{
2517#ifdef CONFIG_IEEE80211W
2518 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2519 "dropped: " MACSTR " -> " MACSTR
2520 " (reason code %u)",
2521 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2522 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2523#endif /* CONFIG_IEEE80211W */
2524}
2525
2526
2527static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2528 struct unprot_disassoc *e)
2529{
2530#ifdef CONFIG_IEEE80211W
2531 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2532 "dropped: " MACSTR " -> " MACSTR
2533 " (reason code %u)",
2534 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2535 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2536#endif /* CONFIG_IEEE80211W */
2537}
2538
2539
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002540static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2541 u16 reason_code, int locally_generated,
2542 const u8 *ie, size_t ie_len, int deauth)
2543{
2544#ifdef CONFIG_AP
2545 if (wpa_s->ap_iface && addr) {
2546 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2547 return;
2548 }
2549
2550 if (wpa_s->ap_iface) {
2551 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2552 return;
2553 }
2554#endif /* CONFIG_AP */
2555
2556 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2557
2558 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2559 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2560 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2561 eapol_sm_failed(wpa_s->eapol)))
2562 wpas_auth_failed(wpa_s);
2563
2564#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002565 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002566 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2567 locally_generated) > 0) {
2568 /*
2569 * The interface was removed, so cannot continue
2570 * processing any additional operations after this.
2571 */
2572 return;
2573 }
2574 }
2575#endif /* CONFIG_P2P */
2576
2577 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2578 locally_generated);
2579}
2580
2581
2582static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2583 struct disassoc_info *info)
2584{
2585 u16 reason_code = 0;
2586 int locally_generated = 0;
2587 const u8 *addr = NULL;
2588 const u8 *ie = NULL;
2589 size_t ie_len = 0;
2590
2591 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2592
2593 if (info) {
2594 addr = info->addr;
2595 ie = info->ie;
2596 ie_len = info->ie_len;
2597 reason_code = info->reason_code;
2598 locally_generated = info->locally_generated;
2599 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2600 locally_generated ? " (locally generated)" : "");
2601 if (addr)
2602 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2603 MAC2STR(addr));
2604 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2605 ie, ie_len);
2606 }
2607
2608#ifdef CONFIG_AP
2609 if (wpa_s->ap_iface && info && info->addr) {
2610 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2611 return;
2612 }
2613
2614 if (wpa_s->ap_iface) {
2615 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2616 return;
2617 }
2618#endif /* CONFIG_AP */
2619
2620#ifdef CONFIG_P2P
2621 if (info) {
2622 wpas_p2p_disassoc_notif(
2623 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2624 locally_generated);
2625 }
2626#endif /* CONFIG_P2P */
2627
2628 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2629 sme_event_disassoc(wpa_s, info);
2630
2631 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2632 ie, ie_len, 0);
2633}
2634
2635
2636static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2637 struct deauth_info *info)
2638{
2639 u16 reason_code = 0;
2640 int locally_generated = 0;
2641 const u8 *addr = NULL;
2642 const u8 *ie = NULL;
2643 size_t ie_len = 0;
2644
2645 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2646
2647 if (info) {
2648 addr = info->addr;
2649 ie = info->ie;
2650 ie_len = info->ie_len;
2651 reason_code = info->reason_code;
2652 locally_generated = info->locally_generated;
2653 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2654 reason_code,
2655 locally_generated ? " (locally generated)" : "");
2656 if (addr) {
2657 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2658 MAC2STR(addr));
2659 }
2660 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2661 ie, ie_len);
2662 }
2663
2664 wpa_reset_ft_completed(wpa_s->wpa);
2665
2666 wpas_event_disconnect(wpa_s, addr, reason_code,
2667 locally_generated, ie, ie_len, 1);
2668}
2669
2670
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002671static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2672{
2673 const char *rn, *rn2;
2674 struct wpa_supplicant *ifs;
2675
2676 if (wpa_s->drv_priv == NULL)
2677 return; /* Ignore event during drv initialization */
2678
2679 free_hw_features(wpa_s);
2680 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2681 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2682
2683#ifdef CONFIG_P2P
2684 wpas_p2p_update_channel_list(wpa_s);
2685#endif /* CONFIG_P2P */
2686
2687 /*
2688 * Check other interfaces to see if they have the same radio-name. If
2689 * so, they get updated with this same hw mode info.
2690 */
2691 if (!wpa_s->driver->get_radio_name)
2692 return;
2693
2694 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2695 if (rn == NULL || rn[0] == '\0')
2696 return;
2697
2698 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2699 "sharing same radio (%s) in event_channel_list_change", rn);
2700
2701 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2702 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2703 continue;
2704
2705 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2706 if (rn2 && os_strcmp(rn, rn2) == 0) {
2707 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2708 ifs->ifname);
2709 free_hw_features(ifs);
2710 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2711 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2712 }
2713 }
2714}
2715
2716
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002717void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2718 union wpa_event_data *data)
2719{
2720 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721
2722 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2723 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002724 event != EVENT_INTERFACE_STATUS &&
2725 event != EVENT_SCHED_SCAN_STOPPED) {
2726 wpa_dbg(wpa_s, MSG_DEBUG,
2727 "Ignore event %s (%d) while interface is disabled",
2728 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002729 return;
2730 }
2731
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002732#ifndef CONFIG_NO_STDOUT_DEBUG
2733{
2734 int level = MSG_DEBUG;
2735
Dmitry Shmidt04949592012-07-19 12:16:46 -07002736 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002737 const struct ieee80211_hdr *hdr;
2738 u16 fc;
2739 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2740 fc = le_to_host16(hdr->frame_control);
2741 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2742 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2743 level = MSG_EXCESSIVE;
2744 }
2745
2746 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2747 event_to_string(event), event);
2748}
2749#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002750
2751 switch (event) {
2752 case EVENT_AUTH:
2753 sme_event_auth(wpa_s, data);
2754 break;
2755 case EVENT_ASSOC:
2756 wpa_supplicant_event_assoc(wpa_s, data);
2757 break;
2758 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002759 wpas_event_disassoc(wpa_s,
2760 data ? &data->disassoc_info : NULL);
2761 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002763 wpas_event_deauth(wpa_s,
2764 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002765 break;
2766 case EVENT_MICHAEL_MIC_FAILURE:
2767 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2768 break;
2769#ifndef CONFIG_NO_SCAN_PROCESSING
2770 case EVENT_SCAN_RESULTS:
2771 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002772 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2773 wpa_s->wpa_state != WPA_ASSOCIATING)
2774 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 break;
2776#endif /* CONFIG_NO_SCAN_PROCESSING */
2777 case EVENT_ASSOCINFO:
2778 wpa_supplicant_event_associnfo(wpa_s, data);
2779 break;
2780 case EVENT_INTERFACE_STATUS:
2781 wpa_supplicant_event_interface_status(wpa_s, data);
2782 break;
2783 case EVENT_PMKID_CANDIDATE:
2784 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2785 break;
2786#ifdef CONFIG_PEERKEY
2787 case EVENT_STKSTART:
2788 wpa_supplicant_event_stkstart(wpa_s, data);
2789 break;
2790#endif /* CONFIG_PEERKEY */
2791#ifdef CONFIG_TDLS
2792 case EVENT_TDLS:
2793 wpa_supplicant_event_tdls(wpa_s, data);
2794 break;
2795#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002796#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002797 case EVENT_WNM:
2798 wpa_supplicant_event_wnm(wpa_s, data);
2799 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002800#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002801#ifdef CONFIG_IEEE80211R
2802 case EVENT_FT_RESPONSE:
2803 wpa_supplicant_event_ft_response(wpa_s, data);
2804 break;
2805#endif /* CONFIG_IEEE80211R */
2806#ifdef CONFIG_IBSS_RSN
2807 case EVENT_IBSS_RSN_START:
2808 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2809 break;
2810#endif /* CONFIG_IBSS_RSN */
2811 case EVENT_ASSOC_REJECT:
2812 if (data->assoc_reject.bssid)
2813 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2814 "bssid=" MACSTR " status_code=%u",
2815 MAC2STR(data->assoc_reject.bssid),
2816 data->assoc_reject.status_code);
2817 else
2818 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2819 "status_code=%u",
2820 data->assoc_reject.status_code);
2821 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2822 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002823 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002824 const u8 *bssid = data->assoc_reject.bssid;
2825 if (bssid == NULL || is_zero_ether_addr(bssid))
2826 bssid = wpa_s->pending_bssid;
2827 wpas_connection_failed(wpa_s, bssid);
2828 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002829 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002830 break;
2831 case EVENT_AUTH_TIMED_OUT:
2832 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2833 sme_event_auth_timed_out(wpa_s, data);
2834 break;
2835 case EVENT_ASSOC_TIMED_OUT:
2836 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2837 sme_event_assoc_timed_out(wpa_s, data);
2838 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002839 case EVENT_TX_STATUS:
2840 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2841 " type=%d stype=%d",
2842 MAC2STR(data->tx_status.dst),
2843 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002844#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002846#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002847 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2848 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002849 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850 wpa_s, data->tx_status.dst,
2851 data->tx_status.data,
2852 data->tx_status.data_len,
2853 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002854 OFFCHANNEL_SEND_ACTION_SUCCESS :
2855 OFFCHANNEL_SEND_ACTION_NO_ACK);
2856#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002857 break;
2858 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002859#endif /* CONFIG_AP */
2860#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2862 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2863 /*
2864 * Catch TX status events for Action frames we sent via group
2865 * interface in GO mode.
2866 */
2867 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2868 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2869 os_memcmp(wpa_s->parent->pending_action_dst,
2870 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002871 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 wpa_s->parent, data->tx_status.dst,
2873 data->tx_status.data,
2874 data->tx_status.data_len,
2875 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002876 OFFCHANNEL_SEND_ACTION_SUCCESS :
2877 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 break;
2879 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002880#endif /* CONFIG_OFFCHANNEL */
2881#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002882 switch (data->tx_status.type) {
2883 case WLAN_FC_TYPE_MGMT:
2884 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2885 data->tx_status.data_len,
2886 data->tx_status.stype,
2887 data->tx_status.ack);
2888 break;
2889 case WLAN_FC_TYPE_DATA:
2890 ap_tx_status(wpa_s, data->tx_status.dst,
2891 data->tx_status.data,
2892 data->tx_status.data_len,
2893 data->tx_status.ack);
2894 break;
2895 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002896#endif /* CONFIG_AP */
2897 break;
2898#ifdef CONFIG_AP
2899 case EVENT_EAPOL_TX_STATUS:
2900 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2901 data->eapol_tx_status.data,
2902 data->eapol_tx_status.data_len,
2903 data->eapol_tx_status.ack);
2904 break;
2905 case EVENT_DRIVER_CLIENT_POLL_OK:
2906 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 break;
2908 case EVENT_RX_FROM_UNKNOWN:
2909 if (wpa_s->ap_iface == NULL)
2910 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002911 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2912 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002913 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002914 case EVENT_CH_SWITCH:
2915 if (!data)
2916 break;
2917 if (!wpa_s->ap_iface) {
2918 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2919 "event in non-AP mode");
2920 break;
2921 }
2922
Dmitry Shmidt04949592012-07-19 12:16:46 -07002923 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2924 data->ch_switch.ht_enabled,
2925 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002926 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002927#endif /* CONFIG_AP */
2928#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002929 case EVENT_RX_MGMT: {
2930 u16 fc, stype;
2931 const struct ieee80211_mgmt *mgmt;
2932
2933 mgmt = (const struct ieee80211_mgmt *)
2934 data->rx_mgmt.frame;
2935 fc = le_to_host16(mgmt->frame_control);
2936 stype = WLAN_FC_GET_STYPE(fc);
2937
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002938#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002940#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002941#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002942 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2943 data->rx_mgmt.frame_len > 24) {
2944 const u8 *src = mgmt->sa;
2945 const u8 *ie = mgmt->u.probe_req.variable;
2946 size_t ie_len = data->rx_mgmt.frame_len -
2947 (mgmt->u.probe_req.variable -
2948 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002949 wpas_p2p_probe_req_rx(
2950 wpa_s, src, mgmt->da,
2951 mgmt->bssid, ie, ie_len,
2952 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002953 break;
2954 }
2955#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002956#ifdef CONFIG_IBSS_RSN
2957 if (stype == WLAN_FC_STYPE_AUTH &&
2958 data->rx_mgmt.frame_len >= 30) {
2959 wpa_supplicant_event_ibss_auth(wpa_s, data);
2960 break;
2961 }
2962#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002963 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2964 "management frame in non-AP mode");
2965 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002966#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002967 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002968
2969 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2970 data->rx_mgmt.frame_len > 24) {
2971 const u8 *ie = mgmt->u.probe_req.variable;
2972 size_t ie_len = data->rx_mgmt.frame_len -
2973 (mgmt->u.probe_req.variable -
2974 data->rx_mgmt.frame);
2975
2976 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2977 mgmt->bssid, ie, ie_len,
2978 data->rx_mgmt.ssi_signal);
2979 }
2980
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002982#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002984 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002985#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002986 case EVENT_RX_ACTION:
2987 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2988 " Category=%u DataLen=%d freq=%d MHz",
2989 MAC2STR(data->rx_action.sa),
2990 data->rx_action.category, (int) data->rx_action.len,
2991 data->rx_action.freq);
2992#ifdef CONFIG_IEEE80211R
2993 if (data->rx_action.category == WLAN_ACTION_FT) {
2994 ft_rx_action(wpa_s, data->rx_action.data,
2995 data->rx_action.len);
2996 break;
2997 }
2998#endif /* CONFIG_IEEE80211R */
2999#ifdef CONFIG_IEEE80211W
3000#ifdef CONFIG_SME
3001 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3002 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3003 data->rx_action.data,
3004 data->rx_action.len);
3005 break;
3006 }
3007#endif /* CONFIG_SME */
3008#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003009#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003010 if (data->rx_action.category == WLAN_ACTION_WNM) {
3011 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3012 break;
3013 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003014#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003015#ifdef CONFIG_GAS
3016 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3017 gas_query_rx(wpa_s->gas, data->rx_action.da,
3018 data->rx_action.sa, data->rx_action.bssid,
3019 data->rx_action.data, data->rx_action.len,
3020 data->rx_action.freq) == 0)
3021 break;
3022#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003023#ifdef CONFIG_TDLS
3024 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3025 data->rx_action.len >= 4 &&
3026 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3027 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3028 "Response from " MACSTR,
3029 MAC2STR(data->rx_action.sa));
3030 break;
3031 }
3032#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003033#ifdef CONFIG_INTERWORKING
3034 if (data->rx_action.category == WLAN_ACTION_QOS &&
3035 data->rx_action.len >= 1 &&
3036 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003037 const u8 *pos = data->rx_action.data + 1;
3038 size_t len = data->rx_action.len - 1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003039 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3040 MACSTR, MAC2STR(data->rx_action.sa));
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003041 if (os_memcmp(data->rx_action.sa, wpa_s->bssid,
3042 ETH_ALEN) == 0 &&
3043 len > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3044 pos[1] <= len - 2 && pos[1] >= 16)
3045 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003046 break;
3047 }
3048#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003049#ifdef CONFIG_P2P
3050 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3051 data->rx_action.sa,
3052 data->rx_action.bssid,
3053 data->rx_action.category,
3054 data->rx_action.data,
3055 data->rx_action.len, data->rx_action.freq);
3056#endif /* CONFIG_P2P */
3057 break;
3058 case EVENT_RX_PROBE_REQ:
3059 if (data->rx_probe_req.sa == NULL ||
3060 data->rx_probe_req.ie == NULL)
3061 break;
3062#ifdef CONFIG_AP
3063 if (wpa_s->ap_iface) {
3064 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3065 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003066 data->rx_probe_req.da,
3067 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003068 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003069 data->rx_probe_req.ie_len,
3070 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003071 break;
3072 }
3073#endif /* CONFIG_AP */
3074#ifdef CONFIG_P2P
3075 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003076 data->rx_probe_req.da,
3077 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003078 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003079 data->rx_probe_req.ie_len,
3080 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081#endif /* CONFIG_P2P */
3082 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003083 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003084#ifdef CONFIG_OFFCHANNEL
3085 offchannel_remain_on_channel_cb(
3086 wpa_s, data->remain_on_channel.freq,
3087 data->remain_on_channel.duration);
3088#endif /* CONFIG_OFFCHANNEL */
3089#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003090 wpas_p2p_remain_on_channel_cb(
3091 wpa_s, data->remain_on_channel.freq,
3092 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003093#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094 break;
3095 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003096#ifdef CONFIG_OFFCHANNEL
3097 offchannel_cancel_remain_on_channel_cb(
3098 wpa_s, data->remain_on_channel.freq);
3099#endif /* CONFIG_OFFCHANNEL */
3100#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101 wpas_p2p_cancel_remain_on_channel_cb(
3102 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003103#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003104 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003105#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003106 case EVENT_P2P_DEV_FOUND: {
3107 struct p2p_peer_info peer_info;
3108
3109 os_memset(&peer_info, 0, sizeof(peer_info));
3110 if (data->p2p_dev_found.dev_addr)
3111 os_memcpy(peer_info.p2p_device_addr,
3112 data->p2p_dev_found.dev_addr, ETH_ALEN);
3113 if (data->p2p_dev_found.pri_dev_type)
3114 os_memcpy(peer_info.pri_dev_type,
3115 data->p2p_dev_found.pri_dev_type,
3116 sizeof(peer_info.pri_dev_type));
3117 if (data->p2p_dev_found.dev_name)
3118 os_strlcpy(peer_info.device_name,
3119 data->p2p_dev_found.dev_name,
3120 sizeof(peer_info.device_name));
3121 peer_info.config_methods = data->p2p_dev_found.config_methods;
3122 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3123 peer_info.group_capab = data->p2p_dev_found.group_capab;
3124
3125 /*
3126 * FIX: new_device=1 is not necessarily correct. We should
3127 * maintain a P2P peer database in wpa_supplicant and update
3128 * this information based on whether the peer is truly new.
3129 */
3130 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3131 break;
3132 }
3133 case EVENT_P2P_GO_NEG_REQ_RX:
3134 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3135 data->p2p_go_neg_req_rx.dev_passwd_id);
3136 break;
3137 case EVENT_P2P_GO_NEG_COMPLETED:
3138 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3139 break;
3140 case EVENT_P2P_PROV_DISC_REQUEST:
3141 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3142 data->p2p_prov_disc_req.config_methods,
3143 data->p2p_prov_disc_req.dev_addr,
3144 data->p2p_prov_disc_req.pri_dev_type,
3145 data->p2p_prov_disc_req.dev_name,
3146 data->p2p_prov_disc_req.supp_config_methods,
3147 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003148 data->p2p_prov_disc_req.group_capab,
3149 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003150 break;
3151 case EVENT_P2P_PROV_DISC_RESPONSE:
3152 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3153 data->p2p_prov_disc_resp.config_methods);
3154 break;
3155 case EVENT_P2P_SD_REQUEST:
3156 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3157 data->p2p_sd_req.sa,
3158 data->p2p_sd_req.dialog_token,
3159 data->p2p_sd_req.update_indic,
3160 data->p2p_sd_req.tlvs,
3161 data->p2p_sd_req.tlvs_len);
3162 break;
3163 case EVENT_P2P_SD_RESPONSE:
3164 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3165 data->p2p_sd_resp.update_indic,
3166 data->p2p_sd_resp.tlvs,
3167 data->p2p_sd_resp.tlvs_len);
3168 break;
3169#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003170 case EVENT_EAPOL_RX:
3171 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3172 data->eapol_rx.data,
3173 data->eapol_rx.data_len);
3174 break;
3175 case EVENT_SIGNAL_CHANGE:
3176 bgscan_notify_signal_change(
3177 wpa_s, data->signal_change.above_threshold,
3178 data->signal_change.current_signal,
3179 data->signal_change.current_noise,
3180 data->signal_change.current_txrate);
3181 break;
3182 case EVENT_INTERFACE_ENABLED:
3183 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3184 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003185 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003186#ifdef CONFIG_AP
3187 if (!wpa_s->ap_iface) {
3188 wpa_supplicant_set_state(wpa_s,
3189 WPA_DISCONNECTED);
3190 wpa_supplicant_req_scan(wpa_s, 0, 0);
3191 } else
3192 wpa_supplicant_set_state(wpa_s,
3193 WPA_COMPLETED);
3194#else /* CONFIG_AP */
3195 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3196 wpa_supplicant_req_scan(wpa_s, 0, 0);
3197#endif /* CONFIG_AP */
3198 }
3199 break;
3200 case EVENT_INTERFACE_DISABLED:
3201 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3202 wpa_supplicant_mark_disassoc(wpa_s);
3203 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3204 break;
3205 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003206 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003207 break;
3208 case EVENT_INTERFACE_UNAVAILABLE:
3209#ifdef CONFIG_P2P
3210 wpas_p2p_interface_unavailable(wpa_s);
3211#endif /* CONFIG_P2P */
3212 break;
3213 case EVENT_BEST_CHANNEL:
3214 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3215 "(%d %d %d)",
3216 data->best_chan.freq_24, data->best_chan.freq_5,
3217 data->best_chan.freq_overall);
3218 wpa_s->best_24_freq = data->best_chan.freq_24;
3219 wpa_s->best_5_freq = data->best_chan.freq_5;
3220 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3221#ifdef CONFIG_P2P
3222 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3223 data->best_chan.freq_5,
3224 data->best_chan.freq_overall);
3225#endif /* CONFIG_P2P */
3226 break;
3227 case EVENT_UNPROT_DEAUTH:
3228 wpa_supplicant_event_unprot_deauth(wpa_s,
3229 &data->unprot_deauth);
3230 break;
3231 case EVENT_UNPROT_DISASSOC:
3232 wpa_supplicant_event_unprot_disassoc(wpa_s,
3233 &data->unprot_disassoc);
3234 break;
3235 case EVENT_STATION_LOW_ACK:
3236#ifdef CONFIG_AP
3237 if (wpa_s->ap_iface && data)
3238 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3239 data->low_ack.addr);
3240#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003241#ifdef CONFIG_TDLS
3242 if (data)
3243 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3244#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003245 break;
3246 case EVENT_IBSS_PEER_LOST:
3247#ifdef CONFIG_IBSS_RSN
3248 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3249#endif /* CONFIG_IBSS_RSN */
3250 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003251 case EVENT_DRIVER_GTK_REKEY:
3252 if (os_memcmp(data->driver_gtk_rekey.bssid,
3253 wpa_s->bssid, ETH_ALEN))
3254 break;
3255 if (!wpa_s->wpa)
3256 break;
3257 wpa_sm_update_replay_ctr(wpa_s->wpa,
3258 data->driver_gtk_rekey.replay_ctr);
3259 break;
3260 case EVENT_SCHED_SCAN_STOPPED:
3261 wpa_s->sched_scanning = 0;
3262 wpa_supplicant_notify_scanning(wpa_s, 0);
3263
3264 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3265 break;
3266
3267 /*
3268 * If we timed out, start a new sched scan to continue
3269 * searching for more SSIDs.
3270 */
3271 if (wpa_s->sched_scan_timed_out)
3272 wpa_supplicant_req_sched_scan(wpa_s);
3273 break;
3274 case EVENT_WPS_BUTTON_PUSHED:
3275#ifdef CONFIG_WPS
3276 wpas_wps_start_pbc(wpa_s, NULL, 0);
3277#endif /* CONFIG_WPS */
3278 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003279 case EVENT_CONNECT_FAILED_REASON:
3280#ifdef CONFIG_AP
3281 if (!wpa_s->ap_iface || !data)
3282 break;
3283 hostapd_event_connect_failed_reason(
3284 wpa_s->ap_iface->bss[0],
3285 data->connect_failed_reason.addr,
3286 data->connect_failed_reason.code);
3287#endif /* CONFIG_AP */
3288 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003289 default:
3290 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3291 break;
3292 }
3293}