blob: ed8cd2360ff372186c8ff37e1926174c9b3a8e39 [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#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002136 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002137#else
2138 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2139#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002140 else
2141 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2142 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002144 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 "try to re-connect");
2146 wpa_s->reassociate = 0;
2147 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002148 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149 }
2150 bssid = wpa_s->bssid;
2151 if (is_zero_ether_addr(bssid))
2152 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002153 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2154 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002156 if (locally_generated)
2157 wpa_s->disconnect_reason = -reason_code;
2158 else
2159 wpa_s->disconnect_reason = reason_code;
2160 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2162 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2163 wpa_s->keys_cleared = 0;
2164 wpa_clear_keys(wpa_s, wpa_s->bssid);
2165 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002166 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167 wpa_supplicant_mark_disassoc(wpa_s);
2168
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002169 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002171 wpa_s->current_ssid = last_ssid;
2172 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002173
2174 if (fast_reconnect) {
2175#ifndef CONFIG_NO_SCAN_PROCESSING
2176 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2177 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2178 fast_reconnect_ssid) < 0) {
2179 /* Recover through full scan */
2180 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2181 }
2182#endif /* CONFIG_NO_SCAN_PROCESSING */
2183 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184}
2185
2186
2187#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002188void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002189{
2190 struct wpa_supplicant *wpa_s = eloop_ctx;
2191
2192 if (!wpa_s->pending_mic_error_report)
2193 return;
2194
2195 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2196 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2197 wpa_s->pending_mic_error_report = 0;
2198}
2199#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2200
2201
2202static void
2203wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2204 union wpa_event_data *data)
2205{
2206 int pairwise;
2207 struct os_time t;
2208
2209 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2210 pairwise = (data && data->michael_mic_failure.unicast);
2211 os_get_time(&t);
2212 if ((wpa_s->last_michael_mic_error &&
2213 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2214 wpa_s->pending_mic_error_report) {
2215 if (wpa_s->pending_mic_error_report) {
2216 /*
2217 * Send the pending MIC error report immediately since
2218 * we are going to start countermeasures and AP better
2219 * do the same.
2220 */
2221 wpa_sm_key_request(wpa_s->wpa, 1,
2222 wpa_s->pending_mic_error_pairwise);
2223 }
2224
2225 /* Send the new MIC error report immediately since we are going
2226 * to start countermeasures and AP better do the same.
2227 */
2228 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2229
2230 /* initialize countermeasures */
2231 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232
2233 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2236
2237 /*
2238 * Need to wait for completion of request frame. We do not get
2239 * any callback for the message completion, so just wait a
2240 * short while and hope for the best. */
2241 os_sleep(0, 10000);
2242
2243 wpa_drv_set_countermeasures(wpa_s, 1);
2244 wpa_supplicant_deauthenticate(wpa_s,
2245 WLAN_REASON_MICHAEL_MIC_FAILURE);
2246 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2247 wpa_s, NULL);
2248 eloop_register_timeout(60, 0,
2249 wpa_supplicant_stop_countermeasures,
2250 wpa_s, NULL);
2251 /* TODO: mark the AP rejected for 60 second. STA is
2252 * allowed to associate with another AP.. */
2253 } else {
2254#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2255 if (wpa_s->mic_errors_seen) {
2256 /*
2257 * Reduce the effectiveness of Michael MIC error
2258 * reports as a means for attacking against TKIP if
2259 * more than one MIC failure is noticed with the same
2260 * PTK. We delay the transmission of the reports by a
2261 * random time between 0 and 60 seconds in order to
2262 * force the attacker wait 60 seconds before getting
2263 * the information on whether a frame resulted in a MIC
2264 * failure.
2265 */
2266 u8 rval[4];
2267 int sec;
2268
2269 if (os_get_random(rval, sizeof(rval)) < 0)
2270 sec = os_random() % 60;
2271 else
2272 sec = WPA_GET_BE32(rval) % 60;
2273 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2274 "report %d seconds", sec);
2275 wpa_s->pending_mic_error_report = 1;
2276 wpa_s->pending_mic_error_pairwise = pairwise;
2277 eloop_cancel_timeout(
2278 wpa_supplicant_delayed_mic_error_report,
2279 wpa_s, NULL);
2280 eloop_register_timeout(
2281 sec, os_random() % 1000000,
2282 wpa_supplicant_delayed_mic_error_report,
2283 wpa_s, NULL);
2284 } else {
2285 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2286 }
2287#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2288 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2289#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2290 }
2291 wpa_s->last_michael_mic_error = t.sec;
2292 wpa_s->mic_errors_seen++;
2293}
2294
2295
2296#ifdef CONFIG_TERMINATE_ONLASTIF
2297static int any_interfaces(struct wpa_supplicant *head)
2298{
2299 struct wpa_supplicant *wpa_s;
2300
2301 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2302 if (!wpa_s->interface_removed)
2303 return 1;
2304 return 0;
2305}
2306#endif /* CONFIG_TERMINATE_ONLASTIF */
2307
2308
2309static void
2310wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2311 union wpa_event_data *data)
2312{
2313 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2314 return;
2315
2316 switch (data->interface_status.ievent) {
2317 case EVENT_INTERFACE_ADDED:
2318 if (!wpa_s->interface_removed)
2319 break;
2320 wpa_s->interface_removed = 0;
2321 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2322 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2323 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2324 "driver after interface was added");
2325 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002326 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002327 break;
2328 case EVENT_INTERFACE_REMOVED:
2329 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2330 wpa_s->interface_removed = 1;
2331 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002332 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 l2_packet_deinit(wpa_s->l2);
2334 wpa_s->l2 = NULL;
2335#ifdef CONFIG_IBSS_RSN
2336 ibss_rsn_deinit(wpa_s->ibss_rsn);
2337 wpa_s->ibss_rsn = NULL;
2338#endif /* CONFIG_IBSS_RSN */
2339#ifdef CONFIG_TERMINATE_ONLASTIF
2340 /* check if last interface */
2341 if (!any_interfaces(wpa_s->global->ifaces))
2342 eloop_terminate();
2343#endif /* CONFIG_TERMINATE_ONLASTIF */
2344 break;
2345 }
2346}
2347
2348
2349#ifdef CONFIG_PEERKEY
2350static void
2351wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2352 union wpa_event_data *data)
2353{
2354 if (data == NULL)
2355 return;
2356 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2357}
2358#endif /* CONFIG_PEERKEY */
2359
2360
2361#ifdef CONFIG_TDLS
2362static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2363 union wpa_event_data *data)
2364{
2365 if (data == NULL)
2366 return;
2367 switch (data->tdls.oper) {
2368 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002369 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2370 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2371 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2372 else
2373 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 break;
2375 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002376 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2377 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2378 data->tdls.reason_code);
2379 else
2380 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2381 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002382 break;
2383 }
2384}
2385#endif /* CONFIG_TDLS */
2386
2387
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002388#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002389static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2390 union wpa_event_data *data)
2391{
2392 if (data == NULL)
2393 return;
2394 switch (data->wnm.oper) {
2395 case WNM_OPER_SLEEP:
2396 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2397 "(action=%d, intval=%d)",
2398 data->wnm.sleep_action, data->wnm.sleep_intval);
2399 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002400 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002401 break;
2402 }
2403}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002404#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002405
2406
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407#ifdef CONFIG_IEEE80211R
2408static void
2409wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2410 union wpa_event_data *data)
2411{
2412 if (data == NULL)
2413 return;
2414
2415 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2416 data->ft_ies.ies_len,
2417 data->ft_ies.ft_action,
2418 data->ft_ies.target_ap,
2419 data->ft_ies.ric_ies,
2420 data->ft_ies.ric_ies_len) < 0) {
2421 /* TODO: prevent MLME/driver from trying to associate? */
2422 }
2423}
2424#endif /* CONFIG_IEEE80211R */
2425
2426
2427#ifdef CONFIG_IBSS_RSN
2428static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2429 union wpa_event_data *data)
2430{
2431 struct wpa_ssid *ssid;
2432 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2433 return;
2434 if (data == NULL)
2435 return;
2436 ssid = wpa_s->current_ssid;
2437 if (ssid == NULL)
2438 return;
2439 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2440 return;
2441
2442 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2443}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002444
2445
2446static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2447 union wpa_event_data *data)
2448{
2449 struct wpa_ssid *ssid = wpa_s->current_ssid;
2450
2451 if (ssid == NULL)
2452 return;
2453
2454 /* check if the ssid is correctly configured as IBSS/RSN */
2455 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2456 return;
2457
2458 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2459 data->rx_mgmt.frame_len);
2460}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461#endif /* CONFIG_IBSS_RSN */
2462
2463
2464#ifdef CONFIG_IEEE80211R
2465static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2466 size_t len)
2467{
2468 const u8 *sta_addr, *target_ap_addr;
2469 u16 status;
2470
2471 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2472 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2473 return; /* only SME case supported for now */
2474 if (len < 1 + 2 * ETH_ALEN + 2)
2475 return;
2476 if (data[0] != 2)
2477 return; /* Only FT Action Response is supported for now */
2478 sta_addr = data + 1;
2479 target_ap_addr = data + 1 + ETH_ALEN;
2480 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2481 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2482 MACSTR " TargetAP " MACSTR " status %u",
2483 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2484
2485 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2486 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2487 " in FT Action Response", MAC2STR(sta_addr));
2488 return;
2489 }
2490
2491 if (status) {
2492 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2493 "failure (status code %d)", status);
2494 /* TODO: report error to FT code(?) */
2495 return;
2496 }
2497
2498 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2499 len - (1 + 2 * ETH_ALEN + 2), 1,
2500 target_ap_addr, NULL, 0) < 0)
2501 return;
2502
2503#ifdef CONFIG_SME
2504 {
2505 struct wpa_bss *bss;
2506 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2507 if (bss)
2508 wpa_s->sme.freq = bss->freq;
2509 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2510 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2511 WLAN_AUTH_FT);
2512 }
2513#endif /* CONFIG_SME */
2514}
2515#endif /* CONFIG_IEEE80211R */
2516
2517
2518static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2519 struct unprot_deauth *e)
2520{
2521#ifdef CONFIG_IEEE80211W
2522 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2523 "dropped: " MACSTR " -> " MACSTR
2524 " (reason code %u)",
2525 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2526 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2527#endif /* CONFIG_IEEE80211W */
2528}
2529
2530
2531static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2532 struct unprot_disassoc *e)
2533{
2534#ifdef CONFIG_IEEE80211W
2535 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2536 "dropped: " MACSTR " -> " MACSTR
2537 " (reason code %u)",
2538 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2539 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2540#endif /* CONFIG_IEEE80211W */
2541}
2542
2543
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002544static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2545 u16 reason_code, int locally_generated,
2546 const u8 *ie, size_t ie_len, int deauth)
2547{
2548#ifdef CONFIG_AP
2549 if (wpa_s->ap_iface && addr) {
2550 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2551 return;
2552 }
2553
2554 if (wpa_s->ap_iface) {
2555 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2556 return;
2557 }
2558#endif /* CONFIG_AP */
2559
2560 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2561
2562 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2563 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2564 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2565 eapol_sm_failed(wpa_s->eapol)))
2566 wpas_auth_failed(wpa_s);
2567
2568#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002569 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002570 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2571 locally_generated) > 0) {
2572 /*
2573 * The interface was removed, so cannot continue
2574 * processing any additional operations after this.
2575 */
2576 return;
2577 }
2578 }
2579#endif /* CONFIG_P2P */
2580
2581 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2582 locally_generated);
2583}
2584
2585
2586static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2587 struct disassoc_info *info)
2588{
2589 u16 reason_code = 0;
2590 int locally_generated = 0;
2591 const u8 *addr = NULL;
2592 const u8 *ie = NULL;
2593 size_t ie_len = 0;
2594
2595 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2596
2597 if (info) {
2598 addr = info->addr;
2599 ie = info->ie;
2600 ie_len = info->ie_len;
2601 reason_code = info->reason_code;
2602 locally_generated = info->locally_generated;
2603 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2604 locally_generated ? " (locally generated)" : "");
2605 if (addr)
2606 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2607 MAC2STR(addr));
2608 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2609 ie, ie_len);
2610 }
2611
2612#ifdef CONFIG_AP
2613 if (wpa_s->ap_iface && info && info->addr) {
2614 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2615 return;
2616 }
2617
2618 if (wpa_s->ap_iface) {
2619 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2620 return;
2621 }
2622#endif /* CONFIG_AP */
2623
2624#ifdef CONFIG_P2P
2625 if (info) {
2626 wpas_p2p_disassoc_notif(
2627 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2628 locally_generated);
2629 }
2630#endif /* CONFIG_P2P */
2631
2632 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2633 sme_event_disassoc(wpa_s, info);
2634
2635 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2636 ie, ie_len, 0);
2637}
2638
2639
2640static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2641 struct deauth_info *info)
2642{
2643 u16 reason_code = 0;
2644 int locally_generated = 0;
2645 const u8 *addr = NULL;
2646 const u8 *ie = NULL;
2647 size_t ie_len = 0;
2648
2649 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2650
2651 if (info) {
2652 addr = info->addr;
2653 ie = info->ie;
2654 ie_len = info->ie_len;
2655 reason_code = info->reason_code;
2656 locally_generated = info->locally_generated;
2657 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2658 reason_code,
2659 locally_generated ? " (locally generated)" : "");
2660 if (addr) {
2661 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2662 MAC2STR(addr));
2663 }
2664 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2665 ie, ie_len);
2666 }
2667
2668 wpa_reset_ft_completed(wpa_s->wpa);
2669
2670 wpas_event_disconnect(wpa_s, addr, reason_code,
2671 locally_generated, ie, ie_len, 1);
2672}
2673
2674
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002675static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2676{
2677 const char *rn, *rn2;
2678 struct wpa_supplicant *ifs;
2679
2680 if (wpa_s->drv_priv == NULL)
2681 return; /* Ignore event during drv initialization */
2682
2683 free_hw_features(wpa_s);
2684 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2685 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2686
2687#ifdef CONFIG_P2P
2688 wpas_p2p_update_channel_list(wpa_s);
2689#endif /* CONFIG_P2P */
2690
2691 /*
2692 * Check other interfaces to see if they have the same radio-name. If
2693 * so, they get updated with this same hw mode info.
2694 */
2695 if (!wpa_s->driver->get_radio_name)
2696 return;
2697
2698 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
2699 if (rn == NULL || rn[0] == '\0')
2700 return;
2701
2702 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
2703 "sharing same radio (%s) in event_channel_list_change", rn);
2704
2705 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2706 if (ifs == wpa_s || !ifs->driver->get_radio_name)
2707 continue;
2708
2709 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
2710 if (rn2 && os_strcmp(rn, rn2) == 0) {
2711 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2712 ifs->ifname);
2713 free_hw_features(ifs);
2714 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2715 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2716 }
2717 }
2718}
2719
2720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2722 union wpa_event_data *data)
2723{
2724 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725
2726 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2727 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002728 event != EVENT_INTERFACE_STATUS &&
2729 event != EVENT_SCHED_SCAN_STOPPED) {
2730 wpa_dbg(wpa_s, MSG_DEBUG,
2731 "Ignore event %s (%d) while interface is disabled",
2732 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 return;
2734 }
2735
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002736#ifndef CONFIG_NO_STDOUT_DEBUG
2737{
2738 int level = MSG_DEBUG;
2739
Dmitry Shmidt04949592012-07-19 12:16:46 -07002740 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002741 const struct ieee80211_hdr *hdr;
2742 u16 fc;
2743 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2744 fc = le_to_host16(hdr->frame_control);
2745 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2746 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2747 level = MSG_EXCESSIVE;
2748 }
2749
2750 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2751 event_to_string(event), event);
2752}
2753#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002754
2755 switch (event) {
2756 case EVENT_AUTH:
2757 sme_event_auth(wpa_s, data);
2758 break;
2759 case EVENT_ASSOC:
2760 wpa_supplicant_event_assoc(wpa_s, data);
2761 break;
2762 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002763 wpas_event_disassoc(wpa_s,
2764 data ? &data->disassoc_info : NULL);
2765 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002766 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002767 wpas_event_deauth(wpa_s,
2768 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 break;
2770 case EVENT_MICHAEL_MIC_FAILURE:
2771 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2772 break;
2773#ifndef CONFIG_NO_SCAN_PROCESSING
2774 case EVENT_SCAN_RESULTS:
2775 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002776 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2777 wpa_s->wpa_state != WPA_ASSOCIATING)
2778 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 break;
2780#endif /* CONFIG_NO_SCAN_PROCESSING */
2781 case EVENT_ASSOCINFO:
2782 wpa_supplicant_event_associnfo(wpa_s, data);
2783 break;
2784 case EVENT_INTERFACE_STATUS:
2785 wpa_supplicant_event_interface_status(wpa_s, data);
2786 break;
2787 case EVENT_PMKID_CANDIDATE:
2788 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2789 break;
2790#ifdef CONFIG_PEERKEY
2791 case EVENT_STKSTART:
2792 wpa_supplicant_event_stkstart(wpa_s, data);
2793 break;
2794#endif /* CONFIG_PEERKEY */
2795#ifdef CONFIG_TDLS
2796 case EVENT_TDLS:
2797 wpa_supplicant_event_tdls(wpa_s, data);
2798 break;
2799#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002800#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002801 case EVENT_WNM:
2802 wpa_supplicant_event_wnm(wpa_s, data);
2803 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002804#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805#ifdef CONFIG_IEEE80211R
2806 case EVENT_FT_RESPONSE:
2807 wpa_supplicant_event_ft_response(wpa_s, data);
2808 break;
2809#endif /* CONFIG_IEEE80211R */
2810#ifdef CONFIG_IBSS_RSN
2811 case EVENT_IBSS_RSN_START:
2812 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2813 break;
2814#endif /* CONFIG_IBSS_RSN */
2815 case EVENT_ASSOC_REJECT:
2816 if (data->assoc_reject.bssid)
2817 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2818 "bssid=" MACSTR " status_code=%u",
2819 MAC2STR(data->assoc_reject.bssid),
2820 data->assoc_reject.status_code);
2821 else
2822 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2823 "status_code=%u",
2824 data->assoc_reject.status_code);
2825 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2826 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002827 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002828#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002829 if(!wpa_s->current_ssid) {
2830 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2831 break;
2832 }
2833 /* If assoc reject is reported by the driver, then avoid
2834 * waiting for the authentication timeout. Cancel the
2835 * authentication timeout and retry the assoc.
2836 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002837 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002838 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2839 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002840
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002841 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002842
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002843 /* Clear the states */
2844 wpa_sm_notify_disassoc(wpa_s->wpa);
2845 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2846
2847 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002848 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002849 const u8 *bl_bssid = data->assoc_reject.bssid;
2850 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2851 bl_bssid = wpa_s->pending_bssid;
2852 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002853 wpa_supplicant_req_scan(wpa_s, 0, 0);
2854 } else {
2855 wpa_supplicant_req_scan(wpa_s, 1, 0);
2856 }
2857 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002858 /* If we ASSOC_REJECT's hits threshold, disable the
2859 * network
2860 */
2861 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2862 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002863 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002864 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002865 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002866 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002867#else
2868 const u8 *bssid = data->assoc_reject.bssid;
2869 if (bssid == NULL || is_zero_ether_addr(bssid))
2870 bssid = wpa_s->pending_bssid;
2871 wpas_connection_failed(wpa_s, bssid);
2872 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002873#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002874 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875 break;
2876 case EVENT_AUTH_TIMED_OUT:
2877 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2878 sme_event_auth_timed_out(wpa_s, data);
2879 break;
2880 case EVENT_ASSOC_TIMED_OUT:
2881 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2882 sme_event_assoc_timed_out(wpa_s, data);
2883 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 case EVENT_TX_STATUS:
2885 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2886 " type=%d stype=%d",
2887 MAC2STR(data->tx_status.dst),
2888 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002889#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002890 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002891#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2893 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002894 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002895 wpa_s, data->tx_status.dst,
2896 data->tx_status.data,
2897 data->tx_status.data_len,
2898 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002899 OFFCHANNEL_SEND_ACTION_SUCCESS :
2900 OFFCHANNEL_SEND_ACTION_NO_ACK);
2901#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002902 break;
2903 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002904#endif /* CONFIG_AP */
2905#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002906 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2907 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2908 /*
2909 * Catch TX status events for Action frames we sent via group
2910 * interface in GO mode.
2911 */
2912 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2913 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2914 os_memcmp(wpa_s->parent->pending_action_dst,
2915 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002916 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002917 wpa_s->parent, data->tx_status.dst,
2918 data->tx_status.data,
2919 data->tx_status.data_len,
2920 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002921 OFFCHANNEL_SEND_ACTION_SUCCESS :
2922 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002923 break;
2924 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002925#endif /* CONFIG_OFFCHANNEL */
2926#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927 switch (data->tx_status.type) {
2928 case WLAN_FC_TYPE_MGMT:
2929 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2930 data->tx_status.data_len,
2931 data->tx_status.stype,
2932 data->tx_status.ack);
2933 break;
2934 case WLAN_FC_TYPE_DATA:
2935 ap_tx_status(wpa_s, data->tx_status.dst,
2936 data->tx_status.data,
2937 data->tx_status.data_len,
2938 data->tx_status.ack);
2939 break;
2940 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002941#endif /* CONFIG_AP */
2942 break;
2943#ifdef CONFIG_AP
2944 case EVENT_EAPOL_TX_STATUS:
2945 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2946 data->eapol_tx_status.data,
2947 data->eapol_tx_status.data_len,
2948 data->eapol_tx_status.ack);
2949 break;
2950 case EVENT_DRIVER_CLIENT_POLL_OK:
2951 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002952 break;
2953 case EVENT_RX_FROM_UNKNOWN:
2954 if (wpa_s->ap_iface == NULL)
2955 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002956 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2957 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002958 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002959 case EVENT_CH_SWITCH:
2960 if (!data)
2961 break;
2962 if (!wpa_s->ap_iface) {
2963 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2964 "event in non-AP mode");
2965 break;
2966 }
2967
Dmitry Shmidt04949592012-07-19 12:16:46 -07002968 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2969 data->ch_switch.ht_enabled,
2970 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002971 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002972#endif /* CONFIG_AP */
2973#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002974 case EVENT_RX_MGMT: {
2975 u16 fc, stype;
2976 const struct ieee80211_mgmt *mgmt;
2977
2978 mgmt = (const struct ieee80211_mgmt *)
2979 data->rx_mgmt.frame;
2980 fc = le_to_host16(mgmt->frame_control);
2981 stype = WLAN_FC_GET_STYPE(fc);
2982
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002983#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002984 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002985#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002986#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002987 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2988 data->rx_mgmt.frame_len > 24) {
2989 const u8 *src = mgmt->sa;
2990 const u8 *ie = mgmt->u.probe_req.variable;
2991 size_t ie_len = data->rx_mgmt.frame_len -
2992 (mgmt->u.probe_req.variable -
2993 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002994 wpas_p2p_probe_req_rx(
2995 wpa_s, src, mgmt->da,
2996 mgmt->bssid, ie, ie_len,
2997 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998 break;
2999 }
3000#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003001#ifdef CONFIG_IBSS_RSN
3002 if (stype == WLAN_FC_STYPE_AUTH &&
3003 data->rx_mgmt.frame_len >= 30) {
3004 wpa_supplicant_event_ibss_auth(wpa_s, data);
3005 break;
3006 }
3007#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003008 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3009 "management frame in non-AP mode");
3010 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003011#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003012 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003013
3014 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3015 data->rx_mgmt.frame_len > 24) {
3016 const u8 *ie = mgmt->u.probe_req.variable;
3017 size_t ie_len = data->rx_mgmt.frame_len -
3018 (mgmt->u.probe_req.variable -
3019 data->rx_mgmt.frame);
3020
3021 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3022 mgmt->bssid, ie, ie_len,
3023 data->rx_mgmt.ssi_signal);
3024 }
3025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003026 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003027#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003029 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003030#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031 case EVENT_RX_ACTION:
3032 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3033 " Category=%u DataLen=%d freq=%d MHz",
3034 MAC2STR(data->rx_action.sa),
3035 data->rx_action.category, (int) data->rx_action.len,
3036 data->rx_action.freq);
3037#ifdef CONFIG_IEEE80211R
3038 if (data->rx_action.category == WLAN_ACTION_FT) {
3039 ft_rx_action(wpa_s, data->rx_action.data,
3040 data->rx_action.len);
3041 break;
3042 }
3043#endif /* CONFIG_IEEE80211R */
3044#ifdef CONFIG_IEEE80211W
3045#ifdef CONFIG_SME
3046 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
3047 sme_sa_query_rx(wpa_s, data->rx_action.sa,
3048 data->rx_action.data,
3049 data->rx_action.len);
3050 break;
3051 }
3052#endif /* CONFIG_SME */
3053#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003054#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003055 if (data->rx_action.category == WLAN_ACTION_WNM) {
3056 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
3057 break;
3058 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003059#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003060#ifdef CONFIG_GAS
3061 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3062 gas_query_rx(wpa_s->gas, data->rx_action.da,
3063 data->rx_action.sa, data->rx_action.bssid,
3064 data->rx_action.data, data->rx_action.len,
3065 data->rx_action.freq) == 0)
3066 break;
3067#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003068#ifdef CONFIG_TDLS
3069 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3070 data->rx_action.len >= 4 &&
3071 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3072 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3073 "Response from " MACSTR,
3074 MAC2STR(data->rx_action.sa));
3075 break;
3076 }
3077#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003078#ifdef CONFIG_INTERWORKING
3079 if (data->rx_action.category == WLAN_ACTION_QOS &&
3080 data->rx_action.len >= 1 &&
3081 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003082 const u8 *pos = data->rx_action.data + 1;
3083 size_t len = data->rx_action.len - 1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003084 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3085 MACSTR, MAC2STR(data->rx_action.sa));
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003086 if (os_memcmp(data->rx_action.sa, wpa_s->bssid,
3087 ETH_ALEN) == 0 &&
3088 len > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3089 pos[1] <= len - 2 && pos[1] >= 16)
3090 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003091 break;
3092 }
3093#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003094#ifdef CONFIG_P2P
3095 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3096 data->rx_action.sa,
3097 data->rx_action.bssid,
3098 data->rx_action.category,
3099 data->rx_action.data,
3100 data->rx_action.len, data->rx_action.freq);
3101#endif /* CONFIG_P2P */
3102 break;
3103 case EVENT_RX_PROBE_REQ:
3104 if (data->rx_probe_req.sa == NULL ||
3105 data->rx_probe_req.ie == NULL)
3106 break;
3107#ifdef CONFIG_AP
3108 if (wpa_s->ap_iface) {
3109 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3110 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003111 data->rx_probe_req.da,
3112 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003114 data->rx_probe_req.ie_len,
3115 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003116 break;
3117 }
3118#endif /* CONFIG_AP */
3119#ifdef CONFIG_P2P
3120 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003121 data->rx_probe_req.da,
3122 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003123 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003124 data->rx_probe_req.ie_len,
3125 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126#endif /* CONFIG_P2P */
3127 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003128 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003129#ifdef CONFIG_OFFCHANNEL
3130 offchannel_remain_on_channel_cb(
3131 wpa_s, data->remain_on_channel.freq,
3132 data->remain_on_channel.duration);
3133#endif /* CONFIG_OFFCHANNEL */
3134#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003135 wpas_p2p_remain_on_channel_cb(
3136 wpa_s, data->remain_on_channel.freq,
3137 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003138#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139 break;
3140 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003141#ifdef CONFIG_OFFCHANNEL
3142 offchannel_cancel_remain_on_channel_cb(
3143 wpa_s, data->remain_on_channel.freq);
3144#endif /* CONFIG_OFFCHANNEL */
3145#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003146 wpas_p2p_cancel_remain_on_channel_cb(
3147 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003148#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003149 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003150#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003151 case EVENT_P2P_DEV_FOUND: {
3152 struct p2p_peer_info peer_info;
3153
3154 os_memset(&peer_info, 0, sizeof(peer_info));
3155 if (data->p2p_dev_found.dev_addr)
3156 os_memcpy(peer_info.p2p_device_addr,
3157 data->p2p_dev_found.dev_addr, ETH_ALEN);
3158 if (data->p2p_dev_found.pri_dev_type)
3159 os_memcpy(peer_info.pri_dev_type,
3160 data->p2p_dev_found.pri_dev_type,
3161 sizeof(peer_info.pri_dev_type));
3162 if (data->p2p_dev_found.dev_name)
3163 os_strlcpy(peer_info.device_name,
3164 data->p2p_dev_found.dev_name,
3165 sizeof(peer_info.device_name));
3166 peer_info.config_methods = data->p2p_dev_found.config_methods;
3167 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3168 peer_info.group_capab = data->p2p_dev_found.group_capab;
3169
3170 /*
3171 * FIX: new_device=1 is not necessarily correct. We should
3172 * maintain a P2P peer database in wpa_supplicant and update
3173 * this information based on whether the peer is truly new.
3174 */
3175 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3176 break;
3177 }
3178 case EVENT_P2P_GO_NEG_REQ_RX:
3179 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3180 data->p2p_go_neg_req_rx.dev_passwd_id);
3181 break;
3182 case EVENT_P2P_GO_NEG_COMPLETED:
3183 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3184 break;
3185 case EVENT_P2P_PROV_DISC_REQUEST:
3186 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3187 data->p2p_prov_disc_req.config_methods,
3188 data->p2p_prov_disc_req.dev_addr,
3189 data->p2p_prov_disc_req.pri_dev_type,
3190 data->p2p_prov_disc_req.dev_name,
3191 data->p2p_prov_disc_req.supp_config_methods,
3192 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003193 data->p2p_prov_disc_req.group_capab,
3194 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003195 break;
3196 case EVENT_P2P_PROV_DISC_RESPONSE:
3197 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3198 data->p2p_prov_disc_resp.config_methods);
3199 break;
3200 case EVENT_P2P_SD_REQUEST:
3201 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3202 data->p2p_sd_req.sa,
3203 data->p2p_sd_req.dialog_token,
3204 data->p2p_sd_req.update_indic,
3205 data->p2p_sd_req.tlvs,
3206 data->p2p_sd_req.tlvs_len);
3207 break;
3208 case EVENT_P2P_SD_RESPONSE:
3209 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3210 data->p2p_sd_resp.update_indic,
3211 data->p2p_sd_resp.tlvs,
3212 data->p2p_sd_resp.tlvs_len);
3213 break;
3214#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003215 case EVENT_EAPOL_RX:
3216 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3217 data->eapol_rx.data,
3218 data->eapol_rx.data_len);
3219 break;
3220 case EVENT_SIGNAL_CHANGE:
3221 bgscan_notify_signal_change(
3222 wpa_s, data->signal_change.above_threshold,
3223 data->signal_change.current_signal,
3224 data->signal_change.current_noise,
3225 data->signal_change.current_txrate);
3226 break;
3227 case EVENT_INTERFACE_ENABLED:
3228 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3229 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003230 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003231#ifdef CONFIG_AP
3232 if (!wpa_s->ap_iface) {
3233 wpa_supplicant_set_state(wpa_s,
3234 WPA_DISCONNECTED);
3235 wpa_supplicant_req_scan(wpa_s, 0, 0);
3236 } else
3237 wpa_supplicant_set_state(wpa_s,
3238 WPA_COMPLETED);
3239#else /* CONFIG_AP */
3240 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3241 wpa_supplicant_req_scan(wpa_s, 0, 0);
3242#endif /* CONFIG_AP */
3243 }
3244 break;
3245 case EVENT_INTERFACE_DISABLED:
3246 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3247 wpa_supplicant_mark_disassoc(wpa_s);
3248 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3249 break;
3250 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003251 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003252 break;
3253 case EVENT_INTERFACE_UNAVAILABLE:
3254#ifdef CONFIG_P2P
3255 wpas_p2p_interface_unavailable(wpa_s);
3256#endif /* CONFIG_P2P */
3257 break;
3258 case EVENT_BEST_CHANNEL:
3259 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3260 "(%d %d %d)",
3261 data->best_chan.freq_24, data->best_chan.freq_5,
3262 data->best_chan.freq_overall);
3263 wpa_s->best_24_freq = data->best_chan.freq_24;
3264 wpa_s->best_5_freq = data->best_chan.freq_5;
3265 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3266#ifdef CONFIG_P2P
3267 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3268 data->best_chan.freq_5,
3269 data->best_chan.freq_overall);
3270#endif /* CONFIG_P2P */
3271 break;
3272 case EVENT_UNPROT_DEAUTH:
3273 wpa_supplicant_event_unprot_deauth(wpa_s,
3274 &data->unprot_deauth);
3275 break;
3276 case EVENT_UNPROT_DISASSOC:
3277 wpa_supplicant_event_unprot_disassoc(wpa_s,
3278 &data->unprot_disassoc);
3279 break;
3280 case EVENT_STATION_LOW_ACK:
3281#ifdef CONFIG_AP
3282 if (wpa_s->ap_iface && data)
3283 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3284 data->low_ack.addr);
3285#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003286#ifdef CONFIG_TDLS
3287 if (data)
3288 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3289#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003290 break;
3291 case EVENT_IBSS_PEER_LOST:
3292#ifdef CONFIG_IBSS_RSN
3293 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3294#endif /* CONFIG_IBSS_RSN */
3295 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003296 case EVENT_DRIVER_GTK_REKEY:
3297 if (os_memcmp(data->driver_gtk_rekey.bssid,
3298 wpa_s->bssid, ETH_ALEN))
3299 break;
3300 if (!wpa_s->wpa)
3301 break;
3302 wpa_sm_update_replay_ctr(wpa_s->wpa,
3303 data->driver_gtk_rekey.replay_ctr);
3304 break;
3305 case EVENT_SCHED_SCAN_STOPPED:
3306 wpa_s->sched_scanning = 0;
3307 wpa_supplicant_notify_scanning(wpa_s, 0);
3308
3309 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3310 break;
3311
3312 /*
3313 * If we timed out, start a new sched scan to continue
3314 * searching for more SSIDs.
3315 */
3316 if (wpa_s->sched_scan_timed_out)
3317 wpa_supplicant_req_sched_scan(wpa_s);
3318 break;
3319 case EVENT_WPS_BUTTON_PUSHED:
3320#ifdef CONFIG_WPS
3321 wpas_wps_start_pbc(wpa_s, NULL, 0);
3322#endif /* CONFIG_WPS */
3323 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003324 case EVENT_CONNECT_FAILED_REASON:
3325#ifdef CONFIG_AP
3326 if (!wpa_s->ap_iface || !data)
3327 break;
3328 hostapd_event_connect_failed_reason(
3329 wpa_s->ap_iface->bss[0],
3330 data->connect_failed_reason.addr,
3331 data->connect_failed_reason.code);
3332#endif /* CONFIG_AP */
3333 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003334 default:
3335 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3336 break;
3337 }
3338}