blob: 1ac177e81e85e617d9c251d60199ffe93c14abad [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, 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 Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
31#include "crypto/random.h"
32#include "blacklist.h"
33#include "wpas_glue.h"
34#include "wps_supplicant.h"
35#include "ibss_rsn.h"
36#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "p2p_supplicant.h"
39#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070040#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "ap.h"
42#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070045#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080046#include "mesh.h"
47#include "mesh_mpm.h"
48#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049
50
Dmitry Shmidt34af3062013-07-11 10:46:32 -070051#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070052static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080053 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070054#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080055
56
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
59{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080060 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070061
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
63 return 0;
64
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080065 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
68
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
70
71 return 0;
72}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073
74
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080075#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070076/**
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
81 *
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
85 */
86static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
87{
88 struct wpa_ssid *ssid;
89 int disabled_for, res = 0;
90
91#ifdef CONFIG_INTERWORKING
92 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
93 wpa_s->conf->cred)
94 return 0;
95#endif /* CONFIG_INTERWORKING */
96
97 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
98 if (ssid->disabled)
99 continue;
100
101 disabled_for = wpas_temp_disabled(wpa_s, ssid);
102 if (!disabled_for)
103 return 0;
104
105 if (!res || disabled_for < res)
106 res = disabled_for;
107 }
108
109 return res;
110}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800111#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700112
113
114void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
115{
116 struct wpa_supplicant *wpa_s = eloop_ctx;
117
118 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
119 return;
120
121 wpa_dbg(wpa_s, MSG_DEBUG,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s);
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
126 }
127}
128
129
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800130static struct wpa_bss * wpa_supplicant_get_new_bss(
131 struct wpa_supplicant *wpa_s, const u8 *bssid)
132{
133 struct wpa_bss *bss = NULL;
134 struct wpa_ssid *ssid = wpa_s->current_ssid;
135
136 if (ssid->ssid_len > 0)
137 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
138 if (!bss)
139 bss = wpa_bss_get_bssid(wpa_s, bssid);
140
141 return bss;
142}
143
144
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700145static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
146{
147 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148
149 if (!bss) {
150 wpa_supplicant_update_scan_results(wpa_s);
151
152 /* Get the BSS from the new scan results */
153 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
154 }
155
156 if (bss)
157 wpa_s->current_bss = bss;
158}
159
160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
162{
163 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700164 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700165 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700166 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
169 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700170
171 if (wpa_s->current_ssid->ssid_len == 0)
172 return 0; /* current profile still in use */
173 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
174 if (res < 0) {
175 wpa_msg(wpa_s, MSG_INFO,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
178 }
179 drv_ssid_len = res;
180
181 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
182 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
183 drv_ssid_len) == 0)
184 return 0; /* current profile still in use */
185
186 wpa_msg(wpa_s, MSG_DEBUG,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid, drv_ssid_len));
189 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700190 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191
192 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
193 "information");
194 ssid = wpa_supplicant_get_ssid(wpa_s);
195 if (ssid == NULL) {
196 wpa_msg(wpa_s, MSG_INFO,
197 "No network configuration found for the current AP");
198 return -1;
199 }
200
Dmitry Shmidt04949592012-07-19 12:16:46 -0700201 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
203 return -1;
204 }
205
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800206 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
207 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
208 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
209 return -1;
210 }
211
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700212 res = wpas_temp_disabled(wpa_s, ssid);
213 if (res > 0) {
214 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
215 "disabled for %d second(s)", res);
216 return -1;
217 }
218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
220 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800221 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 u8 wpa_ie[80];
223 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800224 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
225 wpa_ie, &wpa_ie_len) < 0)
226 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 } else {
228 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
229 }
230
231 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
232 eapol_sm_invalidate_cached_session(wpa_s->eapol);
233 old_ssid = wpa_s->current_ssid;
234 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800235
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700236 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
239 wpa_supplicant_initiate_eapol(wpa_s);
240 if (old_ssid != wpa_s->current_ssid)
241 wpas_notify_network_changed(wpa_s);
242
243 return 0;
244}
245
246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800247void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248{
249 struct wpa_supplicant *wpa_s = eloop_ctx;
250
251 if (wpa_s->countermeasures) {
252 wpa_s->countermeasures = 0;
253 wpa_drv_set_countermeasures(wpa_s, 0);
254 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800255
256 /*
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
262 */
263 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 wpa_supplicant_req_scan(wpa_s, 0, 0);
265 }
266}
267
268
269void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
270{
271 int bssid_changed;
272
Dmitry Shmidt04949592012-07-19 12:16:46 -0700273 wnm_bss_keep_alive_deinit(wpa_s);
274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275#ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s->ibss_rsn);
277 wpa_s->ibss_rsn = NULL;
278#endif /* CONFIG_IBSS_RSN */
279
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700280#ifdef CONFIG_AP
281 wpa_supplicant_ap_deinit(wpa_s);
282#endif /* CONFIG_AP */
283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
285 return;
286
287 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
288 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
289 os_memset(wpa_s->bssid, 0, ETH_ALEN);
290 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800291 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 wpa_s->current_bss = NULL;
293 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 if (bssid_changed)
296 wpas_notify_bssid_changed(wpa_s);
297
298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
300 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
301 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
302 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700303 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700304 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700305 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800306
307 wpas_rrm_reset(wpa_s);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -0800308 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309}
310
311
312static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
313{
314 struct wpa_ie_data ie;
315 int pmksa_set = -1;
316 size_t i;
317
318 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
319 ie.pmkid == NULL)
320 return;
321
322 for (i = 0; i < ie.num_pmkid; i++) {
323 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
324 ie.pmkid + i * PMKID_LEN,
325 NULL, NULL, 0);
326 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800327 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 break;
329 }
330 }
331
332 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
333 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
334}
335
336
337static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
338 union wpa_event_data *data)
339{
340 if (data == NULL) {
341 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
342 "event");
343 return;
344 }
345 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
346 " index=%d preauth=%d",
347 MAC2STR(data->pmkid_candidate.bssid),
348 data->pmkid_candidate.index,
349 data->pmkid_candidate.preauth);
350
351 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
352 data->pmkid_candidate.index,
353 data->pmkid_candidate.preauth);
354}
355
356
357static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
358{
359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
360 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
361 return 0;
362
363#ifdef IEEE8021X_EAPOL
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
365 wpa_s->current_ssid &&
366 !(wpa_s->current_ssid->eapol_flags &
367 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
368 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
369 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
370 * plaintext or static WEP keys). */
371 return 0;
372 }
373#endif /* IEEE8021X_EAPOL */
374
375 return 1;
376}
377
378
379/**
380 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
381 * @wpa_s: pointer to wpa_supplicant data
382 * @ssid: Configuration data for the network
383 * Returns: 0 on success, -1 on failure
384 *
385 * This function is called when starting authentication with a network that is
386 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
387 */
388int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
389 struct wpa_ssid *ssid)
390{
391#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800392#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700393 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700395 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
396 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 return 0;
398
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700399 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 sim = 1;
401 aka = 1;
402 } else {
403 struct eap_method_type *eap = ssid->eap.eap_methods;
404 while (eap->vendor != EAP_VENDOR_IETF ||
405 eap->method != EAP_TYPE_NONE) {
406 if (eap->vendor == EAP_VENDOR_IETF) {
407 if (eap->method == EAP_TYPE_SIM)
408 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700409 else if (eap->method == EAP_TYPE_AKA ||
410 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 aka = 1;
412 }
413 eap++;
414 }
415 }
416
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
418 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700419 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
420 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
421 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 aka = 0;
423
424 if (!sim && !aka) {
425 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
426 "use SIM, but neither EAP-SIM nor EAP-AKA are "
427 "enabled");
428 return 0;
429 }
430
431 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
432 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700434 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435 if (wpa_s->scard == NULL) {
436 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
437 "(pcsc-lite)");
438 return -1;
439 }
440 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
441 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443#endif /* IEEE8021X_EAPOL */
444
445 return 0;
446}
447
448
449#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700450
451static int has_wep_key(struct wpa_ssid *ssid)
452{
453 int i;
454
455 for (i = 0; i < NUM_WEP_KEYS; i++) {
456 if (ssid->wep_key_len[i])
457 return 1;
458 }
459
460 return 0;
461}
462
463
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700464static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 struct wpa_ssid *ssid)
466{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700467 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468
469 if (ssid->mixed_cell)
470 return 1;
471
472#ifdef CONFIG_WPS
473 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
474 return 1;
475#endif /* CONFIG_WPS */
476
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700477 if (has_wep_key(ssid))
478 privacy = 1;
479
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480#ifdef IEEE8021X_EAPOL
481 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
482 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
483 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
484 privacy = 1;
485#endif /* IEEE8021X_EAPOL */
486
Jouni Malinen75ecf522011-06-27 15:19:46 -0700487 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
488 privacy = 1;
489
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800490 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
491 privacy = 1;
492
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 if (bss->caps & IEEE80211_CAP_PRIVACY)
494 return privacy;
495 return !privacy;
496}
497
498
499static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700501 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502{
503 struct wpa_ie_data ie;
504 int proto_match = 0;
505 const u8 *rsn_ie, *wpa_ie;
506 int ret;
507 int wep_ok;
508
509 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
510 if (ret >= 0)
511 return ret;
512
513 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
514 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
515 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
516 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
517 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
518
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700519 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
521 proto_match++;
522
523 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
524 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
525 "failed");
526 break;
527 }
528
529 if (wep_ok &&
530 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
531 {
532 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
533 "in RSN IE");
534 return 1;
535 }
536
537 if (!(ie.proto & ssid->proto)) {
538 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
539 "mismatch");
540 break;
541 }
542
543 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
544 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
545 "cipher mismatch");
546 break;
547 }
548
549 if (!(ie.group_cipher & ssid->group_cipher)) {
550 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
551 "cipher mismatch");
552 break;
553 }
554
555 if (!(ie.key_mgmt & ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
557 "mismatch");
558 break;
559 }
560
561#ifdef CONFIG_IEEE80211W
562 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800563 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800564 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
566 "frame protection");
567 break;
568 }
569#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800570 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
571 wpas_get_ssid_pmf(wpa_s, ssid) ==
572 NO_MGMT_FRAME_PROTECTION) {
573 wpa_dbg(wpa_s, MSG_DEBUG,
574 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
575 break;
576 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577
578 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
579 return 1;
580 }
581
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700582 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700583 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
584 proto_match++;
585
586 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
587 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
588 "failed");
589 break;
590 }
591
592 if (wep_ok &&
593 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
594 {
595 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
596 "in WPA IE");
597 return 1;
598 }
599
600 if (!(ie.proto & ssid->proto)) {
601 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
602 "mismatch");
603 break;
604 }
605
606 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
607 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
608 "cipher mismatch");
609 break;
610 }
611
612 if (!(ie.group_cipher & ssid->group_cipher)) {
613 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
614 "cipher mismatch");
615 break;
616 }
617
618 if (!(ie.key_mgmt & ssid->key_mgmt)) {
619 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
620 "mismatch");
621 break;
622 }
623
624 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
625 return 1;
626 }
627
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700628 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
629 !rsn_ie) {
630 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
631 return 1;
632 }
633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
635 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
636 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
637 return 0;
638 }
639
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800640 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
641 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
642 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
643 return 1;
644 }
645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
647 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
648 return 1;
649 }
650
651 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
652 "WPA/WPA2");
653
654 return 0;
655}
656
657
658static int freq_allowed(int *freqs, int freq)
659{
660 int i;
661
662 if (freqs == NULL)
663 return 1;
664
665 for (i = 0; freqs[i]; i++)
666 if (freqs[i] == freq)
667 return 1;
668 return 0;
669}
670
671
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700672static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800673{
674 const struct hostapd_hw_modes *mode = NULL, *modes;
675 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
676 const u8 *rate_ie;
677 int i, j, k;
678
679 if (bss->freq == 0)
680 return 1; /* Cannot do matching without knowing band */
681
682 modes = wpa_s->hw.modes;
683 if (modes == NULL) {
684 /*
685 * The driver does not provide any additional information
686 * about the utilized hardware, so allow the connection attempt
687 * to continue.
688 */
689 return 1;
690 }
691
692 for (i = 0; i < wpa_s->hw.num_modes; i++) {
693 for (j = 0; j < modes[i].num_channels; j++) {
694 int freq = modes[i].channels[j].freq;
695 if (freq == bss->freq) {
696 if (mode &&
697 mode->mode == HOSTAPD_MODE_IEEE80211G)
698 break; /* do not allow 802.11b replace
699 * 802.11g */
700 mode = &modes[i];
701 break;
702 }
703 }
704 }
705
706 if (mode == NULL)
707 return 0;
708
709 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700710 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711 if (rate_ie == NULL)
712 continue;
713
714 for (j = 2; j < rate_ie[1] + 2; j++) {
715 int flagged = !!(rate_ie[j] & 0x80);
716 int r = (rate_ie[j] & 0x7f) * 5;
717
718 /*
719 * IEEE Std 802.11n-2009 7.3.2.2:
720 * The new BSS Membership selector value is encoded
721 * like a legacy basic rate, but it is not a rate and
722 * only indicates if the BSS members are required to
723 * support the mandatory features of Clause 20 [HT PHY]
724 * in order to join the BSS.
725 */
726 if (flagged && ((rate_ie[j] & 0x7f) ==
727 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
728 if (!ht_supported(mode)) {
729 wpa_dbg(wpa_s, MSG_DEBUG,
730 " hardware does not support "
731 "HT PHY");
732 return 0;
733 }
734 continue;
735 }
736
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700737 /* There's also a VHT selector for 802.11ac */
738 if (flagged && ((rate_ie[j] & 0x7f) ==
739 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
740 if (!vht_supported(mode)) {
741 wpa_dbg(wpa_s, MSG_DEBUG,
742 " hardware does not support "
743 "VHT PHY");
744 return 0;
745 }
746 continue;
747 }
748
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800749 if (!flagged)
750 continue;
751
752 /* check for legacy basic rates */
753 for (k = 0; k < mode->num_rates; k++) {
754 if (mode->rates[k] == r)
755 break;
756 }
757 if (k == mode->num_rates) {
758 /*
759 * IEEE Std 802.11-2007 7.3.2.2 demands that in
760 * order to join a BSS all required rates
761 * have to be supported by the hardware.
762 */
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -0700763 wpa_dbg(wpa_s, MSG_DEBUG,
764 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
765 r / 10, r % 10,
766 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800767 return 0;
768 }
769 }
770 }
771
772 return 1;
773}
774
775
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800776/*
777 * Test whether BSS is in an ESS.
778 * This is done differently in DMG (60 GHz) and non-DMG bands
779 */
780static int bss_is_ess(struct wpa_bss *bss)
781{
782 if (bss_is_dmg(bss)) {
783 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
784 IEEE80211_CAP_DMG_AP;
785 }
786
787 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
788 IEEE80211_CAP_ESS);
789}
790
791
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800792static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
793{
794 size_t i;
795
796 for (i = 0; i < ETH_ALEN; i++) {
797 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
798 return 0;
799 }
800 return 1;
801}
802
803
804static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
805{
806 size_t i;
807
808 for (i = 0; i < num; i++) {
809 const u8 *a = list + i * ETH_ALEN * 2;
810 const u8 *m = a + ETH_ALEN;
811
812 if (match_mac_mask(a, addr, m))
813 return 1;
814 }
815 return 0;
816}
817
818
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700820 int i, struct wpa_bss *bss,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800821 struct wpa_ssid *group,
822 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700824 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825 int wpa;
826 struct wpa_blacklist *e;
827 const u8 *ie;
828 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800829 int osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700831 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 wpa_ie_len = ie ? ie[1] : 0;
833
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700834 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 rsn_ie_len = ie ? ie[1] : 0;
836
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800837 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
838 osen = ie != NULL;
839
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800841 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700842 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800843 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700844 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
845 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
846 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800847 " p2p" : "",
848 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849
850 e = wpa_blacklist_get(wpa_s, bss->bssid);
851 if (e) {
852 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700853 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 /*
855 * When only a single network is enabled, we can
856 * trigger blacklisting on the first failure. This
857 * should not be done with multiple enabled networks to
858 * avoid getting forced to move into a worse ESS on
859 * single error if there are no other BSSes of the
860 * current ESS.
861 */
862 limit = 0;
863 }
864 if (e->count > limit) {
865 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
866 "(count=%d limit=%d)", e->count, limit);
867 return NULL;
868 }
869 }
870
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700871 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
873 return NULL;
874 }
875
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800876 if (disallowed_bssid(wpa_s, bss->bssid)) {
877 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
878 return NULL;
879 }
880
881 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
882 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
883 return NULL;
884 }
885
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
887
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800888 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700890 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891
Dmitry Shmidt04949592012-07-19 12:16:46 -0700892 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
894 continue;
895 }
896
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700897 res = wpas_temp_disabled(wpa_s, ssid);
898 if (res > 0) {
899 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
900 "temporarily for %d second(s)", res);
901 continue;
902 }
903
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904#ifdef CONFIG_WPS
905 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
907 "(WPS)");
908 continue;
909 }
910
911 if (wpa && ssid->ssid_len == 0 &&
912 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
913 check_ssid = 0;
914
915 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
916 /* Only allow wildcard SSID match if an AP
917 * advertises active WPS operation that matches
918 * with our mode. */
919 check_ssid = 1;
920 if (ssid->ssid_len == 0 &&
921 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
922 check_ssid = 0;
923 }
924#endif /* CONFIG_WPS */
925
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926 if (ssid->bssid_set && ssid->ssid_len == 0 &&
927 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
928 check_ssid = 0;
929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700931 (bss->ssid_len != ssid->ssid_len ||
932 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
934 continue;
935 }
936
937 if (ssid->bssid_set &&
938 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
939 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
940 continue;
941 }
942
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800943 /* check blacklist */
944 if (ssid->num_bssid_blacklist &&
945 addr_in_list(bss->bssid, ssid->bssid_blacklist,
946 ssid->num_bssid_blacklist)) {
947 wpa_dbg(wpa_s, MSG_DEBUG,
948 " skip - BSSID blacklisted");
949 continue;
950 }
951
952 /* if there is a whitelist, only accept those APs */
953 if (ssid->num_bssid_whitelist &&
954 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
955 ssid->num_bssid_whitelist)) {
956 wpa_dbg(wpa_s, MSG_DEBUG,
957 " skip - BSSID not in whitelist");
958 continue;
959 }
960
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
962 continue;
963
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800964 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
966 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
967 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
968 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
969 "not allowed");
970 continue;
971 }
972
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700973 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
974 has_wep_key(ssid)) {
975 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
976 continue;
977 }
978
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800979 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
980 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
981 "not allowed");
982 continue;
983 }
984
Jouni Malinen75ecf522011-06-27 15:19:46 -0700985 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
987 "mismatch");
988 continue;
989 }
990
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800991 if (!bss_is_ess(bss)) {
992 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993 continue;
994 }
995
996 if (!freq_allowed(ssid->freq_list, bss->freq)) {
997 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
998 "allowed");
999 continue;
1000 }
1001
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 if (!rate_match(wpa_s, bss)) {
1003 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1004 "not match");
1005 continue;
1006 }
1007
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001009 if (ssid->p2p_group &&
1010 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1011 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1012 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1013 continue;
1014 }
1015
Dmitry Shmidt54605472013-11-08 11:10:19 -08001016 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1017 struct wpabuf *p2p_ie;
1018 u8 dev_addr[ETH_ALEN];
1019
1020 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1021 if (ie == NULL) {
1022 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1023 continue;
1024 }
1025 p2p_ie = wpa_bss_get_vendor_ie_multi(
1026 bss, P2P_IE_VENDOR_TYPE);
1027 if (p2p_ie == NULL) {
1028 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1029 continue;
1030 }
1031
1032 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1033 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1034 ETH_ALEN) != 0) {
1035 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1036 wpabuf_free(p2p_ie);
1037 continue;
1038 }
1039 wpabuf_free(p2p_ie);
1040 }
1041
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042 /*
1043 * TODO: skip the AP if its P2P IE has Group Formation
1044 * bit set in the P2P Group Capability Bitmap and we
1045 * are not in Group Formation with that device.
1046 */
1047#endif /* CONFIG_P2P */
1048
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001049 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1050 {
1051 struct os_reltime diff;
1052
1053 os_reltime_sub(&wpa_s->scan_min_time,
1054 &bss->last_update, &diff);
1055 wpa_dbg(wpa_s, MSG_DEBUG,
1056 " skip - scan result not recent enough (%u.%06u seconds too old)",
1057 (unsigned int) diff.sec,
1058 (unsigned int) diff.usec);
1059 continue;
1060 }
1061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 /* Matching configuration found */
1063 return ssid;
1064 }
1065
1066 /* No matching configuration found */
1067 return NULL;
1068}
1069
1070
1071static struct wpa_bss *
1072wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001074 struct wpa_ssid **selected_ssid,
1075 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001077 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001079 if (only_first_ssid)
1080 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1081 group->id);
1082 else
1083 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1084 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001086 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1087 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001088 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1089 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090 if (!*selected_ssid)
1091 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1093 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001094 MAC2STR(bss->bssid),
1095 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1096 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097 }
1098
1099 return NULL;
1100}
1101
1102
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001103struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1104 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105{
1106 struct wpa_bss *selected = NULL;
1107 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001108 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001109 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001111 if (wpa_s->last_scan_res == NULL ||
1112 wpa_s->last_scan_res_used == 0)
1113 return NULL; /* no scan results from last update */
1114
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001115 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001116 /* check that next_ssid is still valid */
1117 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1118 if (ssid == wpa_s->next_ssid)
1119 break;
1120 }
1121 next_ssid = ssid;
1122 wpa_s->next_ssid = NULL;
1123 }
1124
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001126 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1127 if (next_ssid && next_ssid->priority ==
1128 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001129 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001130 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001131 if (selected)
1132 break;
1133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001135 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001136 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001137 if (selected)
1138 break;
1139 }
1140
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001141 if (selected == NULL && wpa_s->blacklist &&
1142 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001143 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1144 "blacklist and try again");
1145 wpa_blacklist_clear(wpa_s);
1146 wpa_s->blacklist_cleared++;
1147 } else if (selected == NULL)
1148 break;
1149 }
1150
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001151 ssid = *selected_ssid;
1152 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1153 !ssid->passphrase && !ssid->ext_psk) {
1154 const char *field_name, *txt = NULL;
1155
1156 wpa_dbg(wpa_s, MSG_DEBUG,
1157 "PSK/passphrase not yet available for the selected network");
1158
1159 wpas_notify_network_request(wpa_s, ssid,
1160 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1161
1162 field_name = wpa_supplicant_ctrl_req_to_string(
1163 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1164 if (field_name == NULL)
1165 return NULL;
1166
1167 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1168
1169 selected = NULL;
1170 }
1171
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172 return selected;
1173}
1174
1175
1176static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1177 int timeout_sec, int timeout_usec)
1178{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001179 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180 /*
1181 * No networks are enabled; short-circuit request so
1182 * we don't wait timeout seconds before transitioning
1183 * to INACTIVE state.
1184 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001185 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1186 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1188 return;
1189 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001190
1191 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1193}
1194
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001196int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 struct wpa_bss *selected,
1198 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199{
1200 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1201 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1202 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001203 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001205 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1206 wpa_s->p2p_in_provisioning) {
1207 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1208 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001209 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001210 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001211#endif /* CONFIG_P2P */
1212
1213#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001214 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215 wpas_wps_cancel(wpa_s);
1216#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001217 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 }
1219
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001220 wpa_msg(wpa_s, MSG_DEBUG,
1221 "Considering connect request: reassociate: %d selected: "
1222 MACSTR " bssid: " MACSTR " pending: " MACSTR
1223 " wpa_state: %s ssid=%p current_ssid=%p",
1224 wpa_s->reassociate, MAC2STR(selected->bssid),
1225 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1226 wpa_supplicant_state_txt(wpa_s->wpa_state),
1227 ssid, wpa_s->current_ssid);
1228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 /*
1230 * Do not trigger new association unless the BSSID has changed or if
1231 * reassociation is requested. If we are in process of associating with
1232 * the selected BSSID, do not trigger new attempt.
1233 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001234 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1236 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1237 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001238 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1239 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1240 0) ||
1241 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1242 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1244 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001245 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001247 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1248 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249 wpa_supplicant_associate(wpa_s, selected, ssid);
1250 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001251 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1252 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001253 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001254
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001255 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256}
1257
1258
1259static struct wpa_ssid *
1260wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1261{
1262 int prio;
1263 struct wpa_ssid *ssid;
1264
1265 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1266 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1267 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001268 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001269 continue;
1270 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001271 ssid->mode == IEEE80211_MODE_AP ||
1272 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273 return ssid;
1274 }
1275 }
1276 return NULL;
1277}
1278
1279
1280/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1281 * on BSS added and BSS changed events */
1282static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001283 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001284{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001285 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001286
1287 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1288 return;
1289
Jouni Malinen87fd2792011-05-16 18:35:42 +03001290 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292
Jouni Malinen87fd2792011-05-16 18:35:42 +03001293 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294 if (ssid == NULL)
1295 continue;
1296
Jouni Malinen87fd2792011-05-16 18:35:42 +03001297 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001298 if (rsn == NULL)
1299 continue;
1300
Jouni Malinen87fd2792011-05-16 18:35:42 +03001301 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302 }
1303
1304}
1305
1306
1307static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1308 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001309 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001310{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001311 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001312#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313 int min_diff;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001314#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315
1316 if (wpa_s->reassociate)
1317 return 1; /* explicit request to reassociate */
1318 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1319 return 1; /* we are not associated; continue */
1320 if (wpa_s->current_ssid == NULL)
1321 return 1; /* unknown current SSID */
1322 if (wpa_s->current_ssid != ssid)
1323 return 1; /* different network block */
1324
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001325 if (wpas_driver_bss_selection(wpa_s))
1326 return 0; /* Driver-based roaming */
1327
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001328 if (wpa_s->current_ssid->ssid)
1329 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1330 wpa_s->current_ssid->ssid,
1331 wpa_s->current_ssid->ssid_len);
1332 if (!current_bss)
1333 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001334
1335 if (!current_bss)
1336 return 1; /* current BSS not seen in scan results */
1337
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001338 if (current_bss == selected)
1339 return 0;
1340
1341 if (selected->last_update_idx > current_bss->last_update_idx)
1342 return 1; /* current BSS not seen in the last scan */
1343
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001344#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001346 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1347 " level=%d snr=%d est_throughput=%u",
1348 MAC2STR(current_bss->bssid), current_bss->level,
1349 current_bss->snr, current_bss->est_throughput);
1350 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1351 " level=%d snr=%d est_throughput=%u",
1352 MAC2STR(selected->bssid), selected->level,
1353 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001354
1355 if (wpa_s->current_ssid->bssid_set &&
1356 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1357 0) {
1358 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1359 "has preferred BSSID");
1360 return 1;
1361 }
1362
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001363 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1364 wpa_dbg(wpa_s, MSG_DEBUG,
1365 "Allow reassociation - selected BSS has better estimated throughput");
1366 return 1;
1367 }
1368
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001369 if (current_bss->level < 0 && current_bss->level > selected->level) {
1370 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1371 "signal level");
1372 return 0;
1373 }
1374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375 min_diff = 2;
1376 if (current_bss->level < 0) {
1377 if (current_bss->level < -85)
1378 min_diff = 1;
1379 else if (current_bss->level < -80)
1380 min_diff = 2;
1381 else if (current_bss->level < -75)
1382 min_diff = 3;
1383 else if (current_bss->level < -70)
1384 min_diff = 4;
1385 else
1386 min_diff = 5;
1387 }
1388 if (abs(current_bss->level - selected->level) < min_diff) {
1389 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1390 "in signal level");
1391 return 0;
1392 }
1393
1394 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001395#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001396 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001397#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001398}
1399
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001400
Jouni Malinen89ca7022012-09-14 13:03:12 -07001401/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001402 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001403static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001404 union wpa_event_data *data,
1405 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001407 struct wpa_scan_results *scan_res = NULL;
1408 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001410#ifndef CONFIG_NO_RANDOM_POOL
1411 size_t i, num;
1412#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413
1414#ifdef CONFIG_AP
1415 if (wpa_s->ap_iface)
1416 ap = 1;
1417#endif /* CONFIG_AP */
1418
1419 wpa_supplicant_notify_scanning(wpa_s, 0);
1420
1421 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1422 data ? &data->scan_info :
1423 NULL, 1);
1424 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001425 if (wpa_s->conf->ap_scan == 2 || ap ||
1426 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001428 if (!own_request)
1429 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001430 if (data && data->scan_info.external_scan)
1431 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1433 "scanning again");
1434 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001435 ret = -1;
1436 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437 }
1438
1439#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001440 num = scan_res->num;
1441 if (num > 10)
1442 num = 10;
1443 for (i = 0; i < num; i++) {
1444 u8 buf[5];
1445 struct wpa_scan_res *res = scan_res->res[i];
1446 buf[0] = res->bssid[5];
1447 buf[1] = res->qual & 0xff;
1448 buf[2] = res->noise & 0xff;
1449 buf[3] = res->level & 0xff;
1450 buf[4] = res->tsf & 0xff;
1451 random_add_randomness(buf, sizeof(buf));
1452 }
1453#endif /* CONFIG_NO_RANDOM_POOL */
1454
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001455 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001456 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1458 struct wpa_scan_results *scan_res);
1459
1460 scan_res_handler = wpa_s->scan_res_handler;
1461 wpa_s->scan_res_handler = NULL;
1462 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001463 ret = -2;
1464 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001465 }
1466
1467 if (ap) {
1468 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1469#ifdef CONFIG_AP
1470 if (wpa_s->ap_iface->scan_cb)
1471 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1472#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001473 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001475
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001476 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001477 wpa_s->own_scan_running,
1478 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001479 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001480 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1481 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001482 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1483 wpa_s->manual_scan_id);
1484 wpa_s->manual_scan_use_id = 0;
1485 } else {
1486 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1487 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001488 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001489
1490 wpas_notify_scan_done(wpa_s, 1);
1491
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001492 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001493 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001494 wpa_scan_results_free(scan_res);
1495 return 0;
1496 }
1497
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001498 if (wnm_scan_process(wpa_s, 1) > 0)
1499 goto scan_work_done;
1500
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001501 if (sme_proc_obss_scan(wpa_s) > 0)
1502 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001503
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001504 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1505 goto scan_work_done;
1506
1507 if (autoscan_notify_scan(wpa_s, scan_res))
1508 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001509
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510 if (wpa_s->disconnected) {
1511 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001512 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513 }
1514
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001515 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001516 bgscan_notify_scan(wpa_s, scan_res) == 1)
1517 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001518
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001519 wpas_wps_update_ap_info(wpa_s, scan_res);
1520
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001521 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1522 wpa_s->wpa_state < WPA_COMPLETED)
1523 goto scan_work_done;
1524
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001525 wpa_scan_results_free(scan_res);
1526
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001527 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001528 struct wpa_radio_work *work = wpa_s->scan_work;
1529 wpa_s->scan_work = NULL;
1530 radio_work_done(work);
1531 }
1532
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001533 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001534
1535scan_work_done:
1536 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001537 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001538 struct wpa_radio_work *work = wpa_s->scan_work;
1539 wpa_s->scan_work = NULL;
1540 radio_work_done(work);
1541 }
1542 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001543}
1544
1545
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001546static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001547 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001548{
1549 struct wpa_bss *selected;
1550 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001551 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1552
1553 if (time_to_reenable > 0) {
1554 wpa_dbg(wpa_s, MSG_DEBUG,
1555 "Postpone network selection by %d seconds since all networks are disabled",
1556 time_to_reenable);
1557 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1558 eloop_register_timeout(time_to_reenable, 0,
1559 wpas_network_reenabled, wpa_s, NULL);
1560 return 0;
1561 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001562
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001563 if (wpa_s->p2p_mgmt)
1564 return 0; /* no normal connection on p2p_mgmt interface */
1565
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001566 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567
1568 if (selected) {
1569 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001570 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001571 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001572 if (new_scan)
1573 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001574 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001575 }
1576
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001577 if (ssid != wpa_s->current_ssid &&
1578 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1579 wpa_s->own_disconnect_req = 1;
1580 wpa_supplicant_deauthenticate(
1581 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1582 }
1583
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001584 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001585 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001586 return -1;
1587 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001588 if (new_scan)
1589 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001590 /*
1591 * Do not notify other virtual radios of scan results since we do not
1592 * want them to start other associations at the same time.
1593 */
1594 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001595 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001596#ifdef CONFIG_MESH
1597 if (wpa_s->ifmsh) {
1598 wpa_msg(wpa_s, MSG_INFO,
1599 "Avoiding join because we already joined a mesh group");
1600 return 0;
1601 }
1602#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001603 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1604 ssid = wpa_supplicant_pick_new_network(wpa_s);
1605 if (ssid) {
1606 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1607 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001608 if (new_scan)
1609 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001610 } else if (own_request) {
1611 /*
1612 * No SSID found. If SCAN results are as a result of
1613 * own scan request and not due to a scan request on
1614 * another shared interface, try another scan.
1615 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001616 int timeout_sec = wpa_s->scan_interval;
1617 int timeout_usec = 0;
1618#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001619 int res;
1620
1621 res = wpas_p2p_scan_no_go_seen(wpa_s);
1622 if (res == 2)
1623 return 2;
1624 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001625 return 0;
1626
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001627 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001628 wpa_s->show_group_started ||
1629 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630 /*
1631 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001632 * state and during P2P join-a-group operation
1633 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 */
1635 timeout_sec = 0;
1636 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001637 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1638 timeout_usec);
1639 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640 }
1641#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001642#ifdef CONFIG_INTERWORKING
1643 if (wpa_s->conf->auto_interworking &&
1644 wpa_s->conf->interworking &&
1645 wpa_s->conf->cred) {
1646 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1647 "start ANQP fetch since no matching "
1648 "networks found");
1649 wpa_s->network_select = 1;
1650 wpa_s->auto_network_select = 1;
1651 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001652 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001653 }
1654#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001655#ifdef CONFIG_WPS
1656 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1657 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1658 timeout_sec = 0;
1659 timeout_usec = 500000;
1660 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1661 timeout_usec);
1662 return 0;
1663 }
1664#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001665 if (wpa_supplicant_req_sched_scan(wpa_s))
1666 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1667 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07001668
1669 wpa_msg_ctrl(wpa_s, MSG_INFO,
1670 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 }
1672 }
1673 return 0;
1674}
1675
1676
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001677static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1678 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001679{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001681 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001682
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001683 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1684 if (res == 2) {
1685 /*
1686 * Interface may have been removed, so must not dereference
1687 * wpa_s after this.
1688 */
1689 return 1;
1690 }
1691 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692 /*
1693 * If no scan results could be fetched, then no need to
1694 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001695 * this scan. Similarly, if scan results started a new operation on this
1696 * interface, do not notify other interfaces to avoid concurrent
1697 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001698 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001699 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001700 }
1701
1702 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001703 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001704 * so, they get updated with this same scan info.
1705 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001706 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1707 radio_list) {
1708 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001709 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1710 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001711 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001712 }
1713 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001714
1715 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001716}
1717
1718#endif /* CONFIG_NO_SCAN_PROCESSING */
1719
1720
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001721int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1722{
1723#ifdef CONFIG_NO_SCAN_PROCESSING
1724 return -1;
1725#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001726 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001727
Dmitry Shmidt41712582015-06-29 11:02:15 -07001728 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001729 return -1;
1730
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001731 os_get_reltime(&now);
1732 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001733 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1734 return -1;
1735 }
1736
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001737 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001738#endif /* CONFIG_NO_SCAN_PROCESSING */
1739}
1740
Dmitry Shmidt04949592012-07-19 12:16:46 -07001741#ifdef CONFIG_WNM
1742
1743static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1744{
1745 struct wpa_supplicant *wpa_s = eloop_ctx;
1746
1747 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1748 return;
1749
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001750 if (!wpa_s->no_keep_alive) {
1751 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1752 MAC2STR(wpa_s->bssid));
1753 /* TODO: could skip this if normal data traffic has been sent */
1754 /* TODO: Consider using some more appropriate data frame for
1755 * this */
1756 if (wpa_s->l2)
1757 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1758 (u8 *) "", 0);
1759 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001760
1761#ifdef CONFIG_SME
1762 if (wpa_s->sme.bss_max_idle_period) {
1763 unsigned int msec;
1764 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1765 if (msec > 100)
1766 msec -= 100;
1767 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1768 wnm_bss_keep_alive, wpa_s, NULL);
1769 }
1770#endif /* CONFIG_SME */
1771}
1772
1773
1774static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1775 const u8 *ies, size_t ies_len)
1776{
1777 struct ieee802_11_elems elems;
1778
1779 if (ies == NULL)
1780 return;
1781
1782 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1783 return;
1784
1785#ifdef CONFIG_SME
1786 if (elems.bss_max_idle_period) {
1787 unsigned int msec;
1788 wpa_s->sme.bss_max_idle_period =
1789 WPA_GET_LE16(elems.bss_max_idle_period);
1790 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1791 "TU)%s", wpa_s->sme.bss_max_idle_period,
1792 (elems.bss_max_idle_period[2] & 0x01) ?
1793 " (protected keep-live required)" : "");
1794 if (wpa_s->sme.bss_max_idle_period == 0)
1795 wpa_s->sme.bss_max_idle_period = 1;
1796 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1797 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1798 /* msec times 1000 */
1799 msec = wpa_s->sme.bss_max_idle_period * 1024;
1800 if (msec > 100)
1801 msec -= 100;
1802 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1803 wnm_bss_keep_alive, wpa_s,
1804 NULL);
1805 }
1806 }
1807#endif /* CONFIG_SME */
1808}
1809
1810#endif /* CONFIG_WNM */
1811
1812
1813void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1814{
1815#ifdef CONFIG_WNM
1816 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1817#endif /* CONFIG_WNM */
1818}
1819
1820
Dmitry Shmidt051af732013-10-22 13:52:46 -07001821#ifdef CONFIG_INTERWORKING
1822
1823static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1824 size_t len)
1825{
1826 int res;
1827
1828 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1829 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1830 if (res) {
1831 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1832 }
1833
1834 return res;
1835}
1836
1837
1838static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1839 const u8 *ies, size_t ies_len)
1840{
1841 struct ieee802_11_elems elems;
1842
1843 if (ies == NULL)
1844 return;
1845
1846 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1847 return;
1848
1849 if (elems.qos_map_set) {
1850 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1851 elems.qos_map_set_len);
1852 }
1853}
1854
1855#endif /* CONFIG_INTERWORKING */
1856
1857
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001858#ifdef CONFIG_FST
1859static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1860 const u8 *ie, size_t ie_len)
1861{
1862 struct mb_ies_info mb_ies;
1863
1864 if (!ie || !ie_len || !wpa_s->fst)
1865 return -ENOENT;
1866
1867 os_memset(&mb_ies, 0, sizeof(mb_ies));
1868
1869 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1870 size_t len;
1871
1872 len = 2 + ie[1];
1873 if (len > ie_len) {
1874 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1875 ie, ie_len);
1876 break;
1877 }
1878
1879 if (ie[0] == WLAN_EID_MULTI_BAND) {
1880 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1881 (unsigned int) len);
1882 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1883 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1884 mb_ies.nof_ies++;
1885 }
1886
1887 ie_len -= len;
1888 ie += len;
1889 }
1890
1891 if (mb_ies.nof_ies > 0) {
1892 wpabuf_free(wpa_s->received_mb_ies);
1893 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1894 return 0;
1895 }
1896
1897 return -ENOENT;
1898}
1899#endif /* CONFIG_FST */
1900
1901
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001902static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1903 union wpa_event_data *data)
1904{
1905 int l, len, found = 0, wpa_found, rsn_found;
1906 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001907#ifdef CONFIG_IEEE80211R
1908 u8 bssid[ETH_ALEN];
1909#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910
1911 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1912 if (data->assoc_info.req_ies)
1913 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1914 data->assoc_info.req_ies_len);
1915 if (data->assoc_info.resp_ies) {
1916 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1917 data->assoc_info.resp_ies_len);
1918#ifdef CONFIG_TDLS
1919 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1920 data->assoc_info.resp_ies_len);
1921#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001922#ifdef CONFIG_WNM
1923 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1924 data->assoc_info.resp_ies_len);
1925#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001926#ifdef CONFIG_INTERWORKING
1927 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1928 data->assoc_info.resp_ies_len);
1929#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930 }
1931 if (data->assoc_info.beacon_ies)
1932 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1933 data->assoc_info.beacon_ies,
1934 data->assoc_info.beacon_ies_len);
1935 if (data->assoc_info.freq)
1936 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1937 data->assoc_info.freq);
1938
1939 p = data->assoc_info.req_ies;
1940 l = data->assoc_info.req_ies_len;
1941
1942 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1943 while (p && l >= 2) {
1944 len = p[1] + 2;
1945 if (len > l) {
1946 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1947 p, l);
1948 break;
1949 }
1950 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1951 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1952 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1953 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1954 break;
1955 found = 1;
1956 wpa_find_assoc_pmkid(wpa_s);
1957 break;
1958 }
1959 l -= len;
1960 p += len;
1961 }
1962 if (!found && data->assoc_info.req_ies)
1963 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1964
1965#ifdef CONFIG_IEEE80211R
1966#ifdef CONFIG_SME
1967 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001968 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1969 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1970 data->assoc_info.resp_ies,
1971 data->assoc_info.resp_ies_len,
1972 bssid) < 0) {
1973 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1974 "Reassociation Response failed");
1975 wpa_supplicant_deauthenticate(
1976 wpa_s, WLAN_REASON_INVALID_IE);
1977 return -1;
1978 }
1979 }
1980
1981 p = data->assoc_info.resp_ies;
1982 l = data->assoc_info.resp_ies_len;
1983
1984#ifdef CONFIG_WPS_STRICT
1985 if (p && wpa_s->current_ssid &&
1986 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1987 struct wpabuf *wps;
1988 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1989 if (wps == NULL) {
1990 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1991 "include WPS IE in (Re)Association Response");
1992 return -1;
1993 }
1994
1995 if (wps_validate_assoc_resp(wps) < 0) {
1996 wpabuf_free(wps);
1997 wpa_supplicant_deauthenticate(
1998 wpa_s, WLAN_REASON_INVALID_IE);
1999 return -1;
2000 }
2001 wpabuf_free(wps);
2002 }
2003#endif /* CONFIG_WPS_STRICT */
2004
2005 /* Go through the IEs and make a copy of the MDIE, if present. */
2006 while (p && l >= 2) {
2007 len = p[1] + 2;
2008 if (len > l) {
2009 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2010 p, l);
2011 break;
2012 }
2013 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2014 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2015 wpa_s->sme.ft_used = 1;
2016 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2017 MOBILITY_DOMAIN_ID_LEN);
2018 break;
2019 }
2020 l -= len;
2021 p += len;
2022 }
2023#endif /* CONFIG_SME */
2024
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002025 /* Process FT when SME is in the driver */
2026 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2027 wpa_ft_is_completed(wpa_s->wpa)) {
2028 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2029 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2030 data->assoc_info.resp_ies,
2031 data->assoc_info.resp_ies_len,
2032 bssid) < 0) {
2033 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2034 "Reassociation Response failed");
2035 wpa_supplicant_deauthenticate(
2036 wpa_s, WLAN_REASON_INVALID_IE);
2037 return -1;
2038 }
2039 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2040 }
2041
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2043 data->assoc_info.resp_ies_len);
2044#endif /* CONFIG_IEEE80211R */
2045
2046 /* WPA/RSN IE from Beacon/ProbeResp */
2047 p = data->assoc_info.beacon_ies;
2048 l = data->assoc_info.beacon_ies_len;
2049
2050 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2051 */
2052 wpa_found = rsn_found = 0;
2053 while (p && l >= 2) {
2054 len = p[1] + 2;
2055 if (len > l) {
2056 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2057 p, l);
2058 break;
2059 }
2060 if (!wpa_found &&
2061 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2062 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2063 wpa_found = 1;
2064 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2065 }
2066
2067 if (!rsn_found &&
2068 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2069 rsn_found = 1;
2070 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2071 }
2072
2073 l -= len;
2074 p += len;
2075 }
2076
2077 if (!wpa_found && data->assoc_info.beacon_ies)
2078 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2079 if (!rsn_found && data->assoc_info.beacon_ies)
2080 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2081 if (wpa_found || rsn_found)
2082 wpa_s->ap_ies_from_associnfo = 1;
2083
Jouni Malinen87fd2792011-05-16 18:35:42 +03002084 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2085 wpa_s->assoc_freq != data->assoc_info.freq) {
2086 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2087 "%u to %u MHz",
2088 wpa_s->assoc_freq, data->assoc_info.freq);
2089 wpa_supplicant_update_scan_results(wpa_s);
2090 }
2091
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002092 wpa_s->assoc_freq = data->assoc_info.freq;
2093
2094 return 0;
2095}
2096
2097
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002098static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2099{
2100 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2101
2102 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2103 return -1;
2104
2105 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2106 return 0;
2107
2108 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2109 WPA_IE_VENDOR_TYPE);
2110 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2111
2112 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2113 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2114 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2115 bss_rsn ? 2 + bss_rsn[1] : 0))
2116 return -1;
2117
2118 return 0;
2119}
2120
2121
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002122static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2123 union wpa_event_data *data)
2124{
2125#ifdef CONFIG_FST
2126 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2127 struct wpa_bss *bss = wpa_s->current_bss;
2128 const u8 *ieprb, *iebcn;
2129
2130 wpabuf_free(wpa_s->received_mb_ies);
2131 wpa_s->received_mb_ies = NULL;
2132
2133 if (ai &&
2134 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2135 wpa_printf(MSG_DEBUG,
2136 "FST: MB IEs updated from Association Response frame");
2137 return;
2138 }
2139
2140 if (ai &&
2141 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2142 wpa_printf(MSG_DEBUG,
2143 "FST: MB IEs updated from association event Beacon IEs");
2144 return;
2145 }
2146
2147 if (!bss)
2148 return;
2149
2150 ieprb = (const u8 *) (bss + 1);
2151 iebcn = ieprb + bss->ie_len;
2152
2153 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2154 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2155 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2156 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2157#endif /* CONFIG_FST */
2158}
2159
2160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2162 union wpa_event_data *data)
2163{
2164 u8 bssid[ETH_ALEN];
2165 int ft_completed;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002166 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167
2168#ifdef CONFIG_AP
2169 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002170 if (!data)
2171 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2173 data->assoc_info.addr,
2174 data->assoc_info.req_ies,
2175 data->assoc_info.req_ies_len,
2176 data->assoc_info.reassoc);
2177 return;
2178 }
2179#endif /* CONFIG_AP */
2180
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002181 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2182
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2184 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2185 return;
2186
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002187 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2188 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002189 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002190 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2191 return;
2192 }
2193
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002194 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002195 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002196 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2197 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002198 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002199 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2201 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002202 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002203
2204 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2205 wpa_clear_keys(wpa_s, bssid);
2206 }
2207 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002208 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2210 return;
2211 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002212 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002213
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002214#ifdef ANDROID
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002215 if (wpa_s->conf->ap_scan == 1) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002216#else
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002217 if (wpa_s->conf->ap_scan == 1 &&
2218 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002219#endif
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002220 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2221 wpa_msg(wpa_s, MSG_WARNING,
2222 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002223 }
2224
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002225 wpas_fst_update_mb_assoc(wpa_s, data);
2226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227#ifdef CONFIG_SME
2228 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2229 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002230 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231#endif /* CONFIG_SME */
2232
2233 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2234 if (wpa_s->current_ssid) {
2235 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2236 * initialized before association, but for other modes,
2237 * initialize PC/SC here, if the current configuration needs
2238 * smartcard or SIM/USIM. */
2239 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2240 }
2241 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2242 if (wpa_s->l2)
2243 l2_packet_notify_auth_start(wpa_s->l2);
2244
2245 /*
2246 * Set portEnabled first to FALSE in order to get EAP state machine out
2247 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2248 * state machine may transit to AUTHENTICATING state based on obsolete
2249 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2250 * AUTHENTICATED without ever giving chance to EAP state machine to
2251 * reset the state.
2252 */
2253 if (!ft_completed) {
2254 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2255 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2256 }
2257 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2258 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2259 /* 802.1X::portControl = Auto */
2260 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2261 wpa_s->eapol_received = 0;
2262 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2263 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2264 (wpa_s->current_ssid &&
2265 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002266 if (wpa_s->current_ssid &&
2267 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002268 (wpa_s->drv_flags &
2269 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2270 /*
2271 * Set the key after having received joined-IBSS event
2272 * from the driver.
2273 */
2274 wpa_supplicant_set_wpa_none_key(wpa_s,
2275 wpa_s->current_ssid);
2276 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 wpa_supplicant_cancel_auth_timeout(wpa_s);
2278 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2279 } else if (!ft_completed) {
2280 /* Timeout for receiving the first EAPOL packet */
2281 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2282 }
2283 wpa_supplicant_cancel_scan(wpa_s);
2284
2285 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2286 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2287 /*
2288 * We are done; the driver will take care of RSN 4-way
2289 * handshake.
2290 */
2291 wpa_supplicant_cancel_auth_timeout(wpa_s);
2292 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2293 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2294 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2295 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2296 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2297 /*
2298 * The driver will take care of RSN 4-way handshake, so we need
2299 * to allow EAPOL supplicant to complete its work without
2300 * waiting for WPA supplicant.
2301 */
2302 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2303 } else if (ft_completed) {
2304 /*
2305 * FT protocol completed - make sure EAPOL state machine ends
2306 * up in authenticated.
2307 */
2308 wpa_supplicant_cancel_auth_timeout(wpa_s);
2309 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2310 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2311 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2312 }
2313
Jouni Malinena05074c2012-12-21 21:35:35 +02002314 wpa_s->last_eapol_matches_bssid = 0;
2315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002317 struct os_reltime now, age;
2318 os_get_reltime(&now);
2319 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002320 if (age.sec == 0 && age.usec < 100000 &&
2321 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2322 0) {
2323 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2324 "frame that was received just before "
2325 "association notification");
2326 wpa_supplicant_rx_eapol(
2327 wpa_s, wpa_s->pending_eapol_rx_src,
2328 wpabuf_head(wpa_s->pending_eapol_rx),
2329 wpabuf_len(wpa_s->pending_eapol_rx));
2330 }
2331 wpabuf_free(wpa_s->pending_eapol_rx);
2332 wpa_s->pending_eapol_rx = NULL;
2333 }
2334
2335 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2336 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002337 wpa_s->current_ssid &&
2338 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002339 /* Set static WEP keys again */
2340 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2341 }
2342
2343#ifdef CONFIG_IBSS_RSN
2344 if (wpa_s->current_ssid &&
2345 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2346 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2347 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2348 wpa_s->ibss_rsn == NULL) {
2349 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2350 if (!wpa_s->ibss_rsn) {
2351 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2352 wpa_supplicant_deauthenticate(
2353 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2354 return;
2355 }
2356
2357 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2358 }
2359#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002360
2361 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002362
2363 if (data) {
2364 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2365 data->assoc_info.resp_ies_len,
2366 &data->assoc_info.wmm_params);
2367
2368 if (wpa_s->reassoc_same_bss)
2369 wmm_ac_restore_tspecs(wpa_s);
2370 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002371}
2372
2373
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002374static int disconnect_reason_recoverable(u16 reason_code)
2375{
2376 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2377 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2378 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2379}
2380
2381
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002382static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002383 u16 reason_code,
2384 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385{
2386 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002387
2388 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2389 /*
2390 * At least Host AP driver and a Prism3 card seemed to be
2391 * generating streams of disconnected events when configuring
2392 * IBSS for WPA-None. Ignore them for now.
2393 */
2394 return;
2395 }
2396
2397 bssid = wpa_s->bssid;
2398 if (is_zero_ether_addr(bssid))
2399 bssid = wpa_s->pending_bssid;
2400
2401 if (!is_zero_ether_addr(bssid) ||
2402 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2403 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2404 " reason=%d%s",
2405 MAC2STR(bssid), reason_code,
2406 locally_generated ? " locally_generated=1" : "");
2407 }
2408}
2409
2410
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002411static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2412 int locally_generated)
2413{
2414 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2415 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2416 return 0; /* Not in 4-way handshake with PSK */
2417
2418 /*
2419 * It looks like connection was lost while trying to go through PSK
2420 * 4-way handshake. Filter out known disconnection cases that are caused
2421 * by something else than PSK mismatch to avoid confusing reports.
2422 */
2423
2424 if (locally_generated) {
2425 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2426 return 0;
2427 }
2428
2429 return 1;
2430}
2431
2432
Jouni Malinen2b89da82012-08-31 22:04:41 +03002433static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2434 u16 reason_code,
2435 int locally_generated)
2436{
2437 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 int authenticating;
2439 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002440 struct wpa_bss *fast_reconnect = NULL;
2441 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002442 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002443
2444 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2445 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2446
2447 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2448 /*
2449 * At least Host AP driver and a Prism3 card seemed to be
2450 * generating streams of disconnected events when configuring
2451 * IBSS for WPA-None. Ignore them for now.
2452 */
2453 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2454 "IBSS/WPA-None mode");
2455 return;
2456 }
2457
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002458 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2460 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002461 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2462 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002463 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002464 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002465 if (!wpa_s->disconnected &&
2466 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002467 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002468 wpas_wps_searching(wpa_s) ||
2469 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002470 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002471 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002472 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002473 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002474 wpa_s->wpa_state);
2475 if (wpa_s->wpa_state == WPA_COMPLETED &&
2476 wpa_s->current_ssid &&
2477 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002478 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002479 disconnect_reason_recoverable(reason_code)) {
2480 /*
2481 * It looks like the AP has dropped association with
2482 * us, but could allow us to get back in. Try to
2483 * reconnect to the same BSS without full scan to save
2484 * time for some common cases.
2485 */
2486 fast_reconnect = wpa_s->current_bss;
2487 fast_reconnect_ssid = wpa_s->current_ssid;
2488 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002489 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002490 else
2491 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2492 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002493 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002494 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002495 "try to re-connect");
2496 wpa_s->reassociate = 0;
2497 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002498 if (!wpa_s->pno)
2499 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 }
2501 bssid = wpa_s->bssid;
2502 if (is_zero_ether_addr(bssid))
2503 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002504 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2505 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002507 if (locally_generated)
2508 wpa_s->disconnect_reason = -reason_code;
2509 else
2510 wpa_s->disconnect_reason = reason_code;
2511 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002512 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2513 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002514 wpa_clear_keys(wpa_s, wpa_s->bssid);
2515 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002516 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002517 wpa_supplicant_mark_disassoc(wpa_s);
2518
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002519 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002521 wpa_s->current_ssid = last_ssid;
2522 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002523
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002524 if (fast_reconnect &&
2525 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2526 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2527 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2528 fast_reconnect->ssid_len) &&
2529 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002530#ifndef CONFIG_NO_SCAN_PROCESSING
2531 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2532 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2533 fast_reconnect_ssid) < 0) {
2534 /* Recover through full scan */
2535 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2536 }
2537#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002538 } else if (fast_reconnect) {
2539 /*
2540 * Could not reconnect to the same BSS due to network being
2541 * disabled. Use a new scan to match the alternative behavior
2542 * above, i.e., to continue automatic reconnection attempt in a
2543 * way that enforces disabled network rules.
2544 */
2545 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002546 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002547}
2548
2549
2550#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002551void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002552{
2553 struct wpa_supplicant *wpa_s = eloop_ctx;
2554
2555 if (!wpa_s->pending_mic_error_report)
2556 return;
2557
2558 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2559 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2560 wpa_s->pending_mic_error_report = 0;
2561}
2562#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2563
2564
2565static void
2566wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2567 union wpa_event_data *data)
2568{
2569 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002570 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002571
2572 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2573 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002574 os_get_reltime(&t);
2575 if ((wpa_s->last_michael_mic_error.sec &&
2576 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 wpa_s->pending_mic_error_report) {
2578 if (wpa_s->pending_mic_error_report) {
2579 /*
2580 * Send the pending MIC error report immediately since
2581 * we are going to start countermeasures and AP better
2582 * do the same.
2583 */
2584 wpa_sm_key_request(wpa_s->wpa, 1,
2585 wpa_s->pending_mic_error_pairwise);
2586 }
2587
2588 /* Send the new MIC error report immediately since we are going
2589 * to start countermeasures and AP better do the same.
2590 */
2591 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2592
2593 /* initialize countermeasures */
2594 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002595
2596 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2597
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2599
2600 /*
2601 * Need to wait for completion of request frame. We do not get
2602 * any callback for the message completion, so just wait a
2603 * short while and hope for the best. */
2604 os_sleep(0, 10000);
2605
2606 wpa_drv_set_countermeasures(wpa_s, 1);
2607 wpa_supplicant_deauthenticate(wpa_s,
2608 WLAN_REASON_MICHAEL_MIC_FAILURE);
2609 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2610 wpa_s, NULL);
2611 eloop_register_timeout(60, 0,
2612 wpa_supplicant_stop_countermeasures,
2613 wpa_s, NULL);
2614 /* TODO: mark the AP rejected for 60 second. STA is
2615 * allowed to associate with another AP.. */
2616 } else {
2617#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2618 if (wpa_s->mic_errors_seen) {
2619 /*
2620 * Reduce the effectiveness of Michael MIC error
2621 * reports as a means for attacking against TKIP if
2622 * more than one MIC failure is noticed with the same
2623 * PTK. We delay the transmission of the reports by a
2624 * random time between 0 and 60 seconds in order to
2625 * force the attacker wait 60 seconds before getting
2626 * the information on whether a frame resulted in a MIC
2627 * failure.
2628 */
2629 u8 rval[4];
2630 int sec;
2631
2632 if (os_get_random(rval, sizeof(rval)) < 0)
2633 sec = os_random() % 60;
2634 else
2635 sec = WPA_GET_BE32(rval) % 60;
2636 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2637 "report %d seconds", sec);
2638 wpa_s->pending_mic_error_report = 1;
2639 wpa_s->pending_mic_error_pairwise = pairwise;
2640 eloop_cancel_timeout(
2641 wpa_supplicant_delayed_mic_error_report,
2642 wpa_s, NULL);
2643 eloop_register_timeout(
2644 sec, os_random() % 1000000,
2645 wpa_supplicant_delayed_mic_error_report,
2646 wpa_s, NULL);
2647 } else {
2648 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2649 }
2650#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2651 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2652#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2653 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002654 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002655 wpa_s->mic_errors_seen++;
2656}
2657
2658
2659#ifdef CONFIG_TERMINATE_ONLASTIF
2660static int any_interfaces(struct wpa_supplicant *head)
2661{
2662 struct wpa_supplicant *wpa_s;
2663
2664 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2665 if (!wpa_s->interface_removed)
2666 return 1;
2667 return 0;
2668}
2669#endif /* CONFIG_TERMINATE_ONLASTIF */
2670
2671
2672static void
2673wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2674 union wpa_event_data *data)
2675{
2676 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2677 return;
2678
2679 switch (data->interface_status.ievent) {
2680 case EVENT_INTERFACE_ADDED:
2681 if (!wpa_s->interface_removed)
2682 break;
2683 wpa_s->interface_removed = 0;
2684 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2685 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2686 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2687 "driver after interface was added");
2688 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002689
2690#ifdef CONFIG_P2P
2691 if (!wpa_s->global->p2p &&
2692 !wpa_s->global->p2p_disabled &&
2693 !wpa_s->conf->p2p_disabled &&
2694 (wpa_s->drv_flags &
2695 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2696 wpas_p2p_add_p2pdev_interface(
2697 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2698 wpa_printf(MSG_INFO,
2699 "P2P: Failed to enable P2P Device interface");
2700 /* Try to continue without. P2P will be disabled. */
2701 }
2702#endif /* CONFIG_P2P */
2703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 break;
2705 case EVENT_INTERFACE_REMOVED:
2706 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2707 wpa_s->interface_removed = 1;
2708 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002709 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002710 l2_packet_deinit(wpa_s->l2);
2711 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002712
2713#ifdef CONFIG_P2P
2714 if (wpa_s->global->p2p &&
2715 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2716 (wpa_s->drv_flags &
2717 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2718 wpa_dbg(wpa_s, MSG_DEBUG,
2719 "Removing P2P Device interface");
2720 wpa_supplicant_remove_iface(
2721 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2722 0);
2723 wpa_s->global->p2p_init_wpa_s = NULL;
2724 }
2725#endif /* CONFIG_P2P */
2726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727#ifdef CONFIG_TERMINATE_ONLASTIF
2728 /* check if last interface */
2729 if (!any_interfaces(wpa_s->global->ifaces))
2730 eloop_terminate();
2731#endif /* CONFIG_TERMINATE_ONLASTIF */
2732 break;
2733 }
2734}
2735
2736
2737#ifdef CONFIG_PEERKEY
2738static void
2739wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2740 union wpa_event_data *data)
2741{
2742 if (data == NULL)
2743 return;
2744 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2745}
2746#endif /* CONFIG_PEERKEY */
2747
2748
2749#ifdef CONFIG_TDLS
2750static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2751 union wpa_event_data *data)
2752{
2753 if (data == NULL)
2754 return;
2755 switch (data->tdls.oper) {
2756 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002757 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2758 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2759 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2760 else
2761 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 break;
2763 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002764 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2765 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2766 data->tdls.reason_code);
2767 else
2768 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2769 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002770 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07002771 case TDLS_REQUEST_DISCOVER:
2772 wpa_tdls_send_discovery_request(wpa_s->wpa,
2773 data->tdls.peer);
2774 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 }
2776}
2777#endif /* CONFIG_TDLS */
2778
2779
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002780#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002781static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2782 union wpa_event_data *data)
2783{
2784 if (data == NULL)
2785 return;
2786 switch (data->wnm.oper) {
2787 case WNM_OPER_SLEEP:
2788 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2789 "(action=%d, intval=%d)",
2790 data->wnm.sleep_action, data->wnm.sleep_intval);
2791 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002792 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002793 break;
2794 }
2795}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002796#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002797
2798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799#ifdef CONFIG_IEEE80211R
2800static void
2801wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2802 union wpa_event_data *data)
2803{
2804 if (data == NULL)
2805 return;
2806
2807 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2808 data->ft_ies.ies_len,
2809 data->ft_ies.ft_action,
2810 data->ft_ies.target_ap,
2811 data->ft_ies.ric_ies,
2812 data->ft_ies.ric_ies_len) < 0) {
2813 /* TODO: prevent MLME/driver from trying to associate? */
2814 }
2815}
2816#endif /* CONFIG_IEEE80211R */
2817
2818
2819#ifdef CONFIG_IBSS_RSN
2820static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2821 union wpa_event_data *data)
2822{
2823 struct wpa_ssid *ssid;
2824 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2825 return;
2826 if (data == NULL)
2827 return;
2828 ssid = wpa_s->current_ssid;
2829 if (ssid == NULL)
2830 return;
2831 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2832 return;
2833
2834 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2835}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002836
2837
2838static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2839 union wpa_event_data *data)
2840{
2841 struct wpa_ssid *ssid = wpa_s->current_ssid;
2842
2843 if (ssid == NULL)
2844 return;
2845
2846 /* check if the ssid is correctly configured as IBSS/RSN */
2847 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2848 return;
2849
2850 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2851 data->rx_mgmt.frame_len);
2852}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002853#endif /* CONFIG_IBSS_RSN */
2854
2855
2856#ifdef CONFIG_IEEE80211R
2857static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2858 size_t len)
2859{
2860 const u8 *sta_addr, *target_ap_addr;
2861 u16 status;
2862
2863 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2864 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2865 return; /* only SME case supported for now */
2866 if (len < 1 + 2 * ETH_ALEN + 2)
2867 return;
2868 if (data[0] != 2)
2869 return; /* Only FT Action Response is supported for now */
2870 sta_addr = data + 1;
2871 target_ap_addr = data + 1 + ETH_ALEN;
2872 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2873 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2874 MACSTR " TargetAP " MACSTR " status %u",
2875 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2876
2877 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2878 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2879 " in FT Action Response", MAC2STR(sta_addr));
2880 return;
2881 }
2882
2883 if (status) {
2884 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2885 "failure (status code %d)", status);
2886 /* TODO: report error to FT code(?) */
2887 return;
2888 }
2889
2890 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2891 len - (1 + 2 * ETH_ALEN + 2), 1,
2892 target_ap_addr, NULL, 0) < 0)
2893 return;
2894
2895#ifdef CONFIG_SME
2896 {
2897 struct wpa_bss *bss;
2898 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2899 if (bss)
2900 wpa_s->sme.freq = bss->freq;
2901 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2902 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2903 WLAN_AUTH_FT);
2904 }
2905#endif /* CONFIG_SME */
2906}
2907#endif /* CONFIG_IEEE80211R */
2908
2909
2910static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2911 struct unprot_deauth *e)
2912{
2913#ifdef CONFIG_IEEE80211W
2914 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2915 "dropped: " MACSTR " -> " MACSTR
2916 " (reason code %u)",
2917 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2918 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2919#endif /* CONFIG_IEEE80211W */
2920}
2921
2922
2923static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2924 struct unprot_disassoc *e)
2925{
2926#ifdef CONFIG_IEEE80211W
2927 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2928 "dropped: " MACSTR " -> " MACSTR
2929 " (reason code %u)",
2930 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2931 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2932#endif /* CONFIG_IEEE80211W */
2933}
2934
2935
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002936static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2937 u16 reason_code, int locally_generated,
2938 const u8 *ie, size_t ie_len, int deauth)
2939{
2940#ifdef CONFIG_AP
2941 if (wpa_s->ap_iface && addr) {
2942 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2943 return;
2944 }
2945
2946 if (wpa_s->ap_iface) {
2947 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2948 return;
2949 }
2950#endif /* CONFIG_AP */
2951
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002952 if (!locally_generated)
2953 wpa_s->own_disconnect_req = 0;
2954
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002955 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2956
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002957 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2958 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2959 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2960 eapol_sm_failed(wpa_s->eapol))) &&
2961 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002962 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002963
2964#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002965 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002966 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2967 locally_generated) > 0) {
2968 /*
2969 * The interface was removed, so cannot continue
2970 * processing any additional operations after this.
2971 */
2972 return;
2973 }
2974 }
2975#endif /* CONFIG_P2P */
2976
2977 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2978 locally_generated);
2979}
2980
2981
2982static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2983 struct disassoc_info *info)
2984{
2985 u16 reason_code = 0;
2986 int locally_generated = 0;
2987 const u8 *addr = NULL;
2988 const u8 *ie = NULL;
2989 size_t ie_len = 0;
2990
2991 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2992
2993 if (info) {
2994 addr = info->addr;
2995 ie = info->ie;
2996 ie_len = info->ie_len;
2997 reason_code = info->reason_code;
2998 locally_generated = info->locally_generated;
2999 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3000 locally_generated ? " (locally generated)" : "");
3001 if (addr)
3002 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3003 MAC2STR(addr));
3004 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3005 ie, ie_len);
3006 }
3007
3008#ifdef CONFIG_AP
3009 if (wpa_s->ap_iface && info && info->addr) {
3010 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3011 return;
3012 }
3013
3014 if (wpa_s->ap_iface) {
3015 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3016 return;
3017 }
3018#endif /* CONFIG_AP */
3019
3020#ifdef CONFIG_P2P
3021 if (info) {
3022 wpas_p2p_disassoc_notif(
3023 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3024 locally_generated);
3025 }
3026#endif /* CONFIG_P2P */
3027
3028 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3029 sme_event_disassoc(wpa_s, info);
3030
3031 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3032 ie, ie_len, 0);
3033}
3034
3035
3036static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3037 struct deauth_info *info)
3038{
3039 u16 reason_code = 0;
3040 int locally_generated = 0;
3041 const u8 *addr = NULL;
3042 const u8 *ie = NULL;
3043 size_t ie_len = 0;
3044
3045 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3046
3047 if (info) {
3048 addr = info->addr;
3049 ie = info->ie;
3050 ie_len = info->ie_len;
3051 reason_code = info->reason_code;
3052 locally_generated = info->locally_generated;
3053 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3054 reason_code,
3055 locally_generated ? " (locally generated)" : "");
3056 if (addr) {
3057 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3058 MAC2STR(addr));
3059 }
3060 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3061 ie, ie_len);
3062 }
3063
3064 wpa_reset_ft_completed(wpa_s->wpa);
3065
3066 wpas_event_disconnect(wpa_s, addr, reason_code,
3067 locally_generated, ie, ie_len, 1);
3068}
3069
3070
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003071static const char * reg_init_str(enum reg_change_initiator init)
3072{
3073 switch (init) {
3074 case REGDOM_SET_BY_CORE:
3075 return "CORE";
3076 case REGDOM_SET_BY_USER:
3077 return "USER";
3078 case REGDOM_SET_BY_DRIVER:
3079 return "DRIVER";
3080 case REGDOM_SET_BY_COUNTRY_IE:
3081 return "COUNTRY_IE";
3082 case REGDOM_BEACON_HINT:
3083 return "BEACON_HINT";
3084 }
3085 return "?";
3086}
3087
3088
3089static const char * reg_type_str(enum reg_type type)
3090{
3091 switch (type) {
3092 case REGDOM_TYPE_UNKNOWN:
3093 return "UNKNOWN";
3094 case REGDOM_TYPE_COUNTRY:
3095 return "COUNTRY";
3096 case REGDOM_TYPE_WORLD:
3097 return "WORLD";
3098 case REGDOM_TYPE_CUSTOM_WORLD:
3099 return "CUSTOM_WORLD";
3100 case REGDOM_TYPE_INTERSECTION:
3101 return "INTERSECTION";
3102 }
3103 return "?";
3104}
3105
3106
3107static void wpa_supplicant_update_channel_list(
3108 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003109{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003110 struct wpa_supplicant *ifs;
3111
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003112 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07003113 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003114 info->alpha2[0] ? " alpha2=" : "",
3115 info->alpha2[0] ? info->alpha2 : "");
3116
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003117 if (wpa_s->drv_priv == NULL)
3118 return; /* Ignore event during drv initialization */
3119
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003120 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3121 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003122 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3123 ifs->ifname);
3124 free_hw_features(ifs);
3125 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3126 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003127 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003128
3129 /* Restart sched_scan with updated channel list */
3130 if (wpa_s->sched_scanning) {
3131 wpa_dbg(wpa_s, MSG_DEBUG,
3132 "Channel list changed restart sched scan.");
3133 wpa_supplicant_cancel_sched_scan(wpa_s);
3134 wpa_supplicant_req_scan(wpa_s, 0, 0);
3135 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003136
3137 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003138}
3139
3140
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003141static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003142 const u8 *frame, size_t len, int freq,
3143 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003144{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003145 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003146 const u8 *payload;
3147 size_t plen;
3148 u8 category;
3149
3150 if (len < IEEE80211_HDRLEN + 2)
3151 return;
3152
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003153 mgmt = (const struct ieee80211_mgmt *) frame;
3154 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003155 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003156 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003157
3158 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3159 " Category=%u DataLen=%d freq=%d MHz",
3160 MAC2STR(mgmt->sa), category, (int) plen, freq);
3161
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003162 if (category == WLAN_ACTION_WMM) {
3163 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3164 return;
3165 }
3166
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003167#ifdef CONFIG_IEEE80211R
3168 if (category == WLAN_ACTION_FT) {
3169 ft_rx_action(wpa_s, payload, plen);
3170 return;
3171 }
3172#endif /* CONFIG_IEEE80211R */
3173
3174#ifdef CONFIG_IEEE80211W
3175#ifdef CONFIG_SME
3176 if (category == WLAN_ACTION_SA_QUERY) {
3177 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3178 return;
3179 }
3180#endif /* CONFIG_SME */
3181#endif /* CONFIG_IEEE80211W */
3182
3183#ifdef CONFIG_WNM
3184 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3185 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3186 return;
3187 }
3188#endif /* CONFIG_WNM */
3189
3190#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003191 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3192 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003193 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003194 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003195 payload, plen, freq) == 0)
3196 return;
3197#endif /* CONFIG_GAS */
3198
3199#ifdef CONFIG_TDLS
3200 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3201 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3202 wpa_dbg(wpa_s, MSG_DEBUG,
3203 "TDLS: Received Discovery Response from " MACSTR,
3204 MAC2STR(mgmt->sa));
3205 return;
3206 }
3207#endif /* CONFIG_TDLS */
3208
3209#ifdef CONFIG_INTERWORKING
3210 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3211 payload[0] == QOS_QOS_MAP_CONFIG) {
3212 const u8 *pos = payload + 1;
3213 size_t qlen = plen - 1;
3214 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3215 MACSTR, MAC2STR(mgmt->sa));
3216 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3217 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3218 pos[1] <= qlen - 2 && pos[1] >= 16)
3219 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3220 return;
3221 }
3222#endif /* CONFIG_INTERWORKING */
3223
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003224 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3225 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3226 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3227 return;
3228 }
3229
3230 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3231 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3232 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3233 payload + 1, plen - 1,
3234 rssi);
3235 return;
3236 }
3237
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003238#ifdef CONFIG_FST
3239 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3240 fst_rx_action(wpa_s->fst, mgmt, len);
3241 return;
3242 }
3243#endif /* CONFIG_FST */
3244
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003245 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3246 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003247 if (wpa_s->ifmsh)
3248 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003249}
3250
3251
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003252static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3253 union wpa_event_data *event)
3254{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003255 struct wpa_freq_range_list *list;
3256 char *str = NULL;
3257
3258 list = &event->freq_range;
3259
3260 if (list->num)
3261 str = freq_range_list_str(list);
3262 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3263 str ? str : "");
3264
3265#ifdef CONFIG_P2P
3266 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3267 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3268 __func__);
3269 } else {
3270 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003271
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003272 /*
3273 * The update channel flow will also take care of moving a GO
3274 * from the unsafe frequency if needed.
3275 */
3276 wpas_p2p_update_channel_list(wpa_s,
3277 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003278 }
3279#endif /* CONFIG_P2P */
3280
3281 os_free(str);
3282}
3283
3284
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003285static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3286 union wpa_event_data *data)
3287{
3288 wpa_dbg(wpa_s, MSG_DEBUG,
3289 "Connection authorized by device, previous state %d",
3290 wpa_s->wpa_state);
3291 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3292 wpa_supplicant_cancel_auth_timeout(wpa_s);
3293 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3294 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3295 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3296 }
3297 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3298 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003299 data->assoc_info.ptk_kck_len,
3300 data->assoc_info.ptk_kek,
3301 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003302}
3303
3304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003305void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3306 union wpa_event_data *data)
3307{
3308 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003309 int resched;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003310
3311 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3312 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003313 event != EVENT_INTERFACE_STATUS &&
3314 event != EVENT_SCHED_SCAN_STOPPED) {
3315 wpa_dbg(wpa_s, MSG_DEBUG,
3316 "Ignore event %s (%d) while interface is disabled",
3317 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003318 return;
3319 }
3320
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003321#ifndef CONFIG_NO_STDOUT_DEBUG
3322{
3323 int level = MSG_DEBUG;
3324
Dmitry Shmidt04949592012-07-19 12:16:46 -07003325 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003326 const struct ieee80211_hdr *hdr;
3327 u16 fc;
3328 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3329 fc = le_to_host16(hdr->frame_control);
3330 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3331 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3332 level = MSG_EXCESSIVE;
3333 }
3334
3335 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3336 event_to_string(event), event);
3337}
3338#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003339
3340 switch (event) {
3341 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003342#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08003343 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3344 data->auth.ies_len))
3345 wpa_printf(MSG_DEBUG,
3346 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003347#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003348 sme_event_auth(wpa_s, data);
3349 break;
3350 case EVENT_ASSOC:
3351 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003352 if (data && data->assoc_info.authorized)
3353 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003354 if (data) {
3355 wpa_msg(wpa_s, MSG_INFO,
3356 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3357 data->assoc_info.subnet_status);
3358 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359 break;
3360 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003361 wpas_event_disassoc(wpa_s,
3362 data ? &data->disassoc_info : NULL);
3363 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003364 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003365 wpas_event_deauth(wpa_s,
3366 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003367 break;
3368 case EVENT_MICHAEL_MIC_FAILURE:
3369 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3370 break;
3371#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003372 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003373 if (wpa_s->own_scan_requested ||
3374 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003375 struct os_reltime diff;
3376
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003377 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003378 os_reltime_sub(&wpa_s->scan_start_time,
3379 &wpa_s->scan_trigger_time, &diff);
3380 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3381 diff.sec, diff.usec);
3382 wpa_s->own_scan_requested = 0;
3383 wpa_s->own_scan_running = 1;
3384 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3385 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003386 wpa_msg_ctrl(wpa_s, MSG_INFO,
3387 WPA_EVENT_SCAN_STARTED "id=%u",
3388 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003389 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003390 wpa_msg_ctrl(wpa_s, MSG_INFO,
3391 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003392 }
3393 } else {
3394 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003395 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003396 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003397 }
3398 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399 case EVENT_SCAN_RESULTS:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003400 if (!(data && data->scan_info.external_scan) &&
3401 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003402 struct os_reltime now, diff;
3403 os_get_reltime(&now);
3404 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3405 wpa_s->scan_start_time.sec = 0;
3406 wpa_s->scan_start_time.usec = 0;
3407 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3408 diff.sec, diff.usec);
3409 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003410 if (wpa_supplicant_event_scan_results(wpa_s, data))
3411 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003412 if (!(data && data->scan_info.external_scan))
3413 wpa_s->own_scan_running = 0;
3414 if (data && data->scan_info.nl_scan_event)
3415 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003416 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417 break;
3418#endif /* CONFIG_NO_SCAN_PROCESSING */
3419 case EVENT_ASSOCINFO:
3420 wpa_supplicant_event_associnfo(wpa_s, data);
3421 break;
3422 case EVENT_INTERFACE_STATUS:
3423 wpa_supplicant_event_interface_status(wpa_s, data);
3424 break;
3425 case EVENT_PMKID_CANDIDATE:
3426 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3427 break;
3428#ifdef CONFIG_PEERKEY
3429 case EVENT_STKSTART:
3430 wpa_supplicant_event_stkstart(wpa_s, data);
3431 break;
3432#endif /* CONFIG_PEERKEY */
3433#ifdef CONFIG_TDLS
3434 case EVENT_TDLS:
3435 wpa_supplicant_event_tdls(wpa_s, data);
3436 break;
3437#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003438#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003439 case EVENT_WNM:
3440 wpa_supplicant_event_wnm(wpa_s, data);
3441 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003442#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443#ifdef CONFIG_IEEE80211R
3444 case EVENT_FT_RESPONSE:
3445 wpa_supplicant_event_ft_response(wpa_s, data);
3446 break;
3447#endif /* CONFIG_IEEE80211R */
3448#ifdef CONFIG_IBSS_RSN
3449 case EVENT_IBSS_RSN_START:
3450 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3451 break;
3452#endif /* CONFIG_IBSS_RSN */
3453 case EVENT_ASSOC_REJECT:
3454 if (data->assoc_reject.bssid)
3455 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3456 "bssid=" MACSTR " status_code=%u",
3457 MAC2STR(data->assoc_reject.bssid),
3458 data->assoc_reject.status_code);
3459 else
3460 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3461 "status_code=%u",
3462 data->assoc_reject.status_code);
3463 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3464 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003465 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003466 const u8 *bssid = data->assoc_reject.bssid;
3467 if (bssid == NULL || is_zero_ether_addr(bssid))
3468 bssid = wpa_s->pending_bssid;
3469 wpas_connection_failed(wpa_s, bssid);
3470 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003471 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003472 break;
3473 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003474 /* It is possible to get this event from earlier connection */
3475 if (wpa_s->current_ssid &&
3476 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3477 wpa_dbg(wpa_s, MSG_DEBUG,
3478 "Ignore AUTH_TIMED_OUT in mesh configuration");
3479 break;
3480 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003481 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3482 sme_event_auth_timed_out(wpa_s, data);
3483 break;
3484 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003485 /* It is possible to get this event from earlier connection */
3486 if (wpa_s->current_ssid &&
3487 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3488 wpa_dbg(wpa_s, MSG_DEBUG,
3489 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3490 break;
3491 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003492 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3493 sme_event_assoc_timed_out(wpa_s, data);
3494 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 case EVENT_TX_STATUS:
3496 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3497 " type=%d stype=%d",
3498 MAC2STR(data->tx_status.dst),
3499 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003500#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003501 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003502#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003503 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3504 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003505 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 wpa_s, data->tx_status.dst,
3507 data->tx_status.data,
3508 data->tx_status.data_len,
3509 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003510 OFFCHANNEL_SEND_ACTION_SUCCESS :
3511 OFFCHANNEL_SEND_ACTION_NO_ACK);
3512#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003513 break;
3514 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003515#endif /* CONFIG_AP */
3516#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003517 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3518 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3519 /*
3520 * Catch TX status events for Action frames we sent via group
3521 * interface in GO mode.
3522 */
3523 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3524 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3525 os_memcmp(wpa_s->parent->pending_action_dst,
3526 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003527 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 wpa_s->parent, data->tx_status.dst,
3529 data->tx_status.data,
3530 data->tx_status.data_len,
3531 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003532 OFFCHANNEL_SEND_ACTION_SUCCESS :
3533 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003534 break;
3535 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003536#endif /* CONFIG_OFFCHANNEL */
3537#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003538 switch (data->tx_status.type) {
3539 case WLAN_FC_TYPE_MGMT:
3540 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3541 data->tx_status.data_len,
3542 data->tx_status.stype,
3543 data->tx_status.ack);
3544 break;
3545 case WLAN_FC_TYPE_DATA:
3546 ap_tx_status(wpa_s, data->tx_status.dst,
3547 data->tx_status.data,
3548 data->tx_status.data_len,
3549 data->tx_status.ack);
3550 break;
3551 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003552#endif /* CONFIG_AP */
3553 break;
3554#ifdef CONFIG_AP
3555 case EVENT_EAPOL_TX_STATUS:
3556 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3557 data->eapol_tx_status.data,
3558 data->eapol_tx_status.data_len,
3559 data->eapol_tx_status.ack);
3560 break;
3561 case EVENT_DRIVER_CLIENT_POLL_OK:
3562 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003563 break;
3564 case EVENT_RX_FROM_UNKNOWN:
3565 if (wpa_s->ap_iface == NULL)
3566 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003567 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3568 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003570 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003571 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003572 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003573
3574 wpa_s->assoc_freq = data->ch_switch.freq;
3575 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3576
3577 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3578 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3579 wpa_s->current_ssid->mode ==
3580 WPAS_MODE_P2P_GROUP_FORMATION) {
3581 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3582 data->ch_switch.ht_enabled,
3583 data->ch_switch.ch_offset,
3584 data->ch_switch.ch_width,
3585 data->ch_switch.cf1,
3586 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003587 }
3588
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003589 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003590 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003591#ifdef NEED_AP_MLME
3592 case EVENT_DFS_RADAR_DETECTED:
3593 if (data)
3594 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3595 break;
3596 case EVENT_DFS_CAC_STARTED:
3597 if (data)
3598 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3599 break;
3600 case EVENT_DFS_CAC_FINISHED:
3601 if (data)
3602 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3603 break;
3604 case EVENT_DFS_CAC_ABORTED:
3605 if (data)
3606 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3607 break;
3608 case EVENT_DFS_NOP_FINISHED:
3609 if (data)
3610 wpas_event_dfs_cac_nop_finished(wpa_s,
3611 &data->dfs_event);
3612 break;
3613#endif /* NEED_AP_MLME */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003614#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003615 case EVENT_RX_MGMT: {
3616 u16 fc, stype;
3617 const struct ieee80211_mgmt *mgmt;
3618
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003619#ifdef CONFIG_TESTING_OPTIONS
3620 if (wpa_s->ext_mgmt_frame_handling) {
3621 struct rx_mgmt *rx = &data->rx_mgmt;
3622 size_t hex_len = 2 * rx->frame_len + 1;
3623 char *hex = os_malloc(hex_len);
3624 if (hex) {
3625 wpa_snprintf_hex(hex, hex_len,
3626 rx->frame, rx->frame_len);
3627 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3628 rx->freq, rx->datarate, rx->ssi_signal,
3629 hex);
3630 os_free(hex);
3631 }
3632 break;
3633 }
3634#endif /* CONFIG_TESTING_OPTIONS */
3635
Dmitry Shmidt04949592012-07-19 12:16:46 -07003636 mgmt = (const struct ieee80211_mgmt *)
3637 data->rx_mgmt.frame;
3638 fc = le_to_host16(mgmt->frame_control);
3639 stype = WLAN_FC_GET_STYPE(fc);
3640
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003641#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003642 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003643#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003644#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003645 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3646 data->rx_mgmt.frame_len > 24) {
3647 const u8 *src = mgmt->sa;
3648 const u8 *ie = mgmt->u.probe_req.variable;
3649 size_t ie_len = data->rx_mgmt.frame_len -
3650 (mgmt->u.probe_req.variable -
3651 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003652 wpas_p2p_probe_req_rx(
3653 wpa_s, src, mgmt->da,
3654 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003655 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003656 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657 break;
3658 }
3659#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003660#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003661 if (wpa_s->current_ssid &&
3662 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3663 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003664 data->rx_mgmt.frame_len >= 30) {
3665 wpa_supplicant_event_ibss_auth(wpa_s, data);
3666 break;
3667 }
3668#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003669
3670 if (stype == WLAN_FC_STYPE_ACTION) {
3671 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003672 wpa_s, data->rx_mgmt.frame,
3673 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003674 data->rx_mgmt.freq,
3675 data->rx_mgmt.ssi_signal);
3676 break;
3677 }
3678
3679 if (wpa_s->ifmsh) {
3680 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003681 break;
3682 }
3683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3685 "management frame in non-AP mode");
3686 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003687#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003688 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003689
3690 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3691 data->rx_mgmt.frame_len > 24) {
3692 const u8 *ie = mgmt->u.probe_req.variable;
3693 size_t ie_len = data->rx_mgmt.frame_len -
3694 (mgmt->u.probe_req.variable -
3695 data->rx_mgmt.frame);
3696
3697 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3698 mgmt->bssid, ie, ie_len,
3699 data->rx_mgmt.ssi_signal);
3700 }
3701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003702 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003703#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003704 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003705 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003706 case EVENT_RX_PROBE_REQ:
3707 if (data->rx_probe_req.sa == NULL ||
3708 data->rx_probe_req.ie == NULL)
3709 break;
3710#ifdef CONFIG_AP
3711 if (wpa_s->ap_iface) {
3712 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3713 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003714 data->rx_probe_req.da,
3715 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003716 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003717 data->rx_probe_req.ie_len,
3718 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003719 break;
3720 }
3721#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003722 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003723 data->rx_probe_req.da,
3724 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003725 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003726 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003727 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003728 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003729 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003730 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003731#ifdef CONFIG_OFFCHANNEL
3732 offchannel_remain_on_channel_cb(
3733 wpa_s, data->remain_on_channel.freq,
3734 data->remain_on_channel.duration);
3735#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003736 wpas_p2p_remain_on_channel_cb(
3737 wpa_s, data->remain_on_channel.freq,
3738 data->remain_on_channel.duration);
3739 break;
3740 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003741#ifdef CONFIG_OFFCHANNEL
3742 offchannel_cancel_remain_on_channel_cb(
3743 wpa_s, data->remain_on_channel.freq);
3744#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003745 wpas_p2p_cancel_remain_on_channel_cb(
3746 wpa_s, data->remain_on_channel.freq);
3747 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003748 case EVENT_EAPOL_RX:
3749 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3750 data->eapol_rx.data,
3751 data->eapol_rx.data_len);
3752 break;
3753 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003754 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3755 "above=%d signal=%d noise=%d txrate=%d",
3756 data->signal_change.above_threshold,
3757 data->signal_change.current_signal,
3758 data->signal_change.current_noise,
3759 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003760 wpa_bss_update_level(wpa_s->current_bss,
3761 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003762 bgscan_notify_signal_change(
3763 wpa_s, data->signal_change.above_threshold,
3764 data->signal_change.current_signal,
3765 data->signal_change.current_noise,
3766 data->signal_change.current_txrate);
3767 break;
3768 case EVENT_INTERFACE_ENABLED:
3769 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3770 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003771 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003772 if (wpa_s->p2p_mgmt) {
3773 wpa_supplicant_set_state(wpa_s,
3774 WPA_DISCONNECTED);
3775 break;
3776 }
3777
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003778#ifdef CONFIG_AP
3779 if (!wpa_s->ap_iface) {
3780 wpa_supplicant_set_state(wpa_s,
3781 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003782 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003783 wpa_supplicant_req_scan(wpa_s, 0, 0);
3784 } else
3785 wpa_supplicant_set_state(wpa_s,
3786 WPA_COMPLETED);
3787#else /* CONFIG_AP */
3788 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3789 wpa_supplicant_req_scan(wpa_s, 0, 0);
3790#endif /* CONFIG_AP */
3791 }
3792 break;
3793 case EVENT_INTERFACE_DISABLED:
3794 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003795#ifdef CONFIG_P2P
3796 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3797 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3798 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3799 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003800 * Mark interface disabled if this happens to end up not
3801 * being removed as a separate P2P group interface.
3802 */
3803 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3804 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003805 * The interface was externally disabled. Remove
3806 * it assuming an external entity will start a
3807 * new session if needed.
3808 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003809 if (wpa_s->current_ssid &&
3810 wpa_s->current_ssid->p2p_group)
3811 wpas_p2p_interface_unavailable(wpa_s);
3812 else
3813 wpas_p2p_disconnect(wpa_s);
3814 /*
3815 * wpa_s instance may have been freed, so must not use
3816 * it here anymore.
3817 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003818 break;
3819 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003820 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3821 p2p_in_progress(wpa_s->global->p2p) > 1) {
3822 /* This radio work will be cancelled, so clear P2P
3823 * state as well.
3824 */
3825 p2p_stop_find(wpa_s->global->p2p);
3826 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003827#endif /* CONFIG_P2P */
3828
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003829 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3830 /*
3831 * Indicate disconnection to keep ctrl_iface events
3832 * consistent.
3833 */
3834 wpa_supplicant_event_disassoc(
3835 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3836 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003837 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003838 radio_remove_works(wpa_s, NULL, 0);
3839
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003840 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3841 break;
3842 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003843 wpa_supplicant_update_channel_list(
3844 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003845 break;
3846 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003847 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003848 break;
3849 case EVENT_BEST_CHANNEL:
3850 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3851 "(%d %d %d)",
3852 data->best_chan.freq_24, data->best_chan.freq_5,
3853 data->best_chan.freq_overall);
3854 wpa_s->best_24_freq = data->best_chan.freq_24;
3855 wpa_s->best_5_freq = data->best_chan.freq_5;
3856 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003857 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3858 data->best_chan.freq_5,
3859 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003860 break;
3861 case EVENT_UNPROT_DEAUTH:
3862 wpa_supplicant_event_unprot_deauth(wpa_s,
3863 &data->unprot_deauth);
3864 break;
3865 case EVENT_UNPROT_DISASSOC:
3866 wpa_supplicant_event_unprot_disassoc(wpa_s,
3867 &data->unprot_disassoc);
3868 break;
3869 case EVENT_STATION_LOW_ACK:
3870#ifdef CONFIG_AP
3871 if (wpa_s->ap_iface && data)
3872 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3873 data->low_ack.addr);
3874#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003875#ifdef CONFIG_TDLS
3876 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003877 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3878 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003879#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003880 break;
3881 case EVENT_IBSS_PEER_LOST:
3882#ifdef CONFIG_IBSS_RSN
3883 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3884#endif /* CONFIG_IBSS_RSN */
3885 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003886 case EVENT_DRIVER_GTK_REKEY:
3887 if (os_memcmp(data->driver_gtk_rekey.bssid,
3888 wpa_s->bssid, ETH_ALEN))
3889 break;
3890 if (!wpa_s->wpa)
3891 break;
3892 wpa_sm_update_replay_ctr(wpa_s->wpa,
3893 data->driver_gtk_rekey.replay_ctr);
3894 break;
3895 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003896 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003897 wpa_s->sched_scanning = 0;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003898 resched = wpa_s->scanning;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003899 wpa_supplicant_notify_scanning(wpa_s, 0);
3900
3901 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3902 break;
3903
3904 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003905 * Start a new sched scan to continue searching for more SSIDs
3906 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003907 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003908 if (wpa_s->sched_scan_timed_out) {
3909 wpa_supplicant_req_sched_scan(wpa_s);
3910 } else if (wpa_s->pno_sched_pending) {
3911 wpa_s->pno_sched_pending = 0;
3912 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003913 } else if (resched) {
3914 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003915 }
3916
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003917 break;
3918 case EVENT_WPS_BUTTON_PUSHED:
3919#ifdef CONFIG_WPS
3920 wpas_wps_start_pbc(wpa_s, NULL, 0);
3921#endif /* CONFIG_WPS */
3922 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003923 case EVENT_AVOID_FREQUENCIES:
3924 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3925 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003926 case EVENT_CONNECT_FAILED_REASON:
3927#ifdef CONFIG_AP
3928 if (!wpa_s->ap_iface || !data)
3929 break;
3930 hostapd_event_connect_failed_reason(
3931 wpa_s->ap_iface->bss[0],
3932 data->connect_failed_reason.addr,
3933 data->connect_failed_reason.code);
3934#endif /* CONFIG_AP */
3935 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003936 case EVENT_NEW_PEER_CANDIDATE:
3937#ifdef CONFIG_MESH
3938 if (!wpa_s->ifmsh || !data)
3939 break;
3940 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3941 data->mesh_peer.ies,
3942 data->mesh_peer.ie_len);
3943#endif /* CONFIG_MESH */
3944 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003945 default:
3946 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3947 break;
3948 }
3949}