blob: 0f7b85de0b7c11f95fd3d88bb5fa89b804c0e412 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant
Hai Shalom74f70d42019-02-11 14:42:39 -08003 * Copyright (c) 2003-2019, 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 * This file implements functions for registering and unregistering
9 * %wpa_supplicant interfaces. In addition, this file contains number of
10 * functions for managing network connections.
11 */
12
13#include "includes.h"
Dmitry Shmidte4663042016-04-04 10:07:49 -070014#ifdef CONFIG_MATCH_IFACE
15#include <net/if.h>
16#include <fnmatch.h>
17#endif /* CONFIG_MATCH_IFACE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018
19#include "common.h"
20#include "crypto/random.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080021#include "crypto/sha1.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "eapol_supp/eapol_supp_sm.h"
23#include "eap_peer/eap.h"
Dmitry Shmidt34af3062013-07-11 10:46:32 -070024#include "eap_peer/eap_proxy.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "eap_server/eap_methods.h"
26#include "rsn_supp/wpa.h"
27#include "eloop.h"
28#include "config.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029#include "utils/ext_password.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "l2_packet/l2_packet.h"
31#include "wpa_supplicant_i.h"
32#include "driver_i.h"
33#include "ctrl_iface.h"
34#include "pcsc_funcs.h"
35#include "common/version.h"
36#include "rsn_supp/preauth.h"
37#include "rsn_supp/pmksa_cache.h"
38#include "common/wpa_ctrl.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#include "common/ieee802_11_defs.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080040#include "common/hw_features_common.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070041#include "common/gas_server.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070042#include "common/dpp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080044#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045#include "blacklist.h"
46#include "wpas_glue.h"
47#include "wps_supplicant.h"
48#include "ibss_rsn.h"
49#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070051#include "ap.h"
52#include "p2p_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070054#include "notify.h"
55#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070056#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070057#include "bss.h"
58#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080059#include "offchannel.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070060#include "hs20_supplicant.h"
Dmitry Shmidt44c95782013-05-17 09:51:35 -070061#include "wnm_sta.h"
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -070062#include "wpas_kay.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080063#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070064#include "dpp_supplicant.h"
65#ifdef CONFIG_MESH
66#include "ap/ap_config.h"
67#include "ap/hostapd.h"
68#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070070const char *const wpa_supplicant_version =
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071"wpa_supplicant v" VERSION_STR "\n"
Hai Shalom74f70d42019-02-11 14:42:39 -080072"Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi> and contributors";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070074const char *const wpa_supplicant_license =
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080075"This software may be distributed under the terms of the BSD license.\n"
76"See README for more details.\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077#ifdef EAP_TLS_OPENSSL
78"\nThis product includes software developed by the OpenSSL Project\n"
79"for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
80#endif /* EAP_TLS_OPENSSL */
81;
82
83#ifndef CONFIG_NO_STDOUT_DEBUG
84/* Long text divided into parts in order to fit in C89 strings size limits. */
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070085const char *const wpa_supplicant_full_license1 =
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080086"";
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070087const char *const wpa_supplicant_full_license2 =
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080088"This software may be distributed under the terms of the BSD license.\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089"\n"
90"Redistribution and use in source and binary forms, with or without\n"
91"modification, are permitted provided that the following conditions are\n"
92"met:\n"
93"\n";
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070094const char *const wpa_supplicant_full_license3 =
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095"1. Redistributions of source code must retain the above copyright\n"
96" notice, this list of conditions and the following disclaimer.\n"
97"\n"
98"2. Redistributions in binary form must reproduce the above copyright\n"
99" notice, this list of conditions and the following disclaimer in the\n"
100" documentation and/or other materials provided with the distribution.\n"
101"\n";
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700102const char *const wpa_supplicant_full_license4 =
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103"3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
104" names of its contributors may be used to endorse or promote products\n"
105" derived from this software without specific prior written permission.\n"
106"\n"
107"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
108"\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
109"LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
110"A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700111const char *const wpa_supplicant_full_license5 =
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112"OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
113"SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
114"LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
115"DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
116"THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
117"(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
118"OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
119"\n";
120#endif /* CONFIG_NO_STDOUT_DEBUG */
121
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700122
123static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx);
124#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
125static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s);
126#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
127
128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700129/* Configure default/group WEP keys for static WEP */
130int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
131{
132 int i, set = 0;
133
134 for (i = 0; i < NUM_WEP_KEYS; i++) {
135 if (ssid->wep_key_len[i] == 0)
136 continue;
137
138 set = 1;
139 wpa_drv_set_key(wpa_s, WPA_ALG_WEP, NULL,
140 i, i == ssid->wep_tx_keyidx, NULL, 0,
141 ssid->wep_key[i], ssid->wep_key_len[i]);
142 }
143
144 return set;
145}
146
147
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700148int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
149 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150{
151 u8 key[32];
152 size_t keylen;
153 enum wpa_alg alg;
154 u8 seq[6] = { 0 };
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800155 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156
157 /* IBSS/WPA-None uses only one key (Group) for both receiving and
158 * sending unicast and multicast packets. */
159
160 if (ssid->mode != WPAS_MODE_IBSS) {
161 wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not "
162 "IBSS/ad-hoc) for WPA-None", ssid->mode);
163 return -1;
164 }
165
166 if (!ssid->psk_set) {
167 wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for "
168 "WPA-None");
169 return -1;
170 }
171
172 switch (wpa_s->group_cipher) {
173 case WPA_CIPHER_CCMP:
174 os_memcpy(key, ssid->psk, 16);
175 keylen = 16;
176 alg = WPA_ALG_CCMP;
177 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700178 case WPA_CIPHER_GCMP:
179 os_memcpy(key, ssid->psk, 16);
180 keylen = 16;
181 alg = WPA_ALG_GCMP;
182 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 case WPA_CIPHER_TKIP:
184 /* WPA-None uses the same Michael MIC key for both TX and RX */
185 os_memcpy(key, ssid->psk, 16 + 8);
186 os_memcpy(key + 16 + 8, ssid->psk + 16, 8);
187 keylen = 32;
188 alg = WPA_ALG_TKIP;
189 break;
190 default:
191 wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for "
192 "WPA-None", wpa_s->group_cipher);
193 return -1;
194 }
195
196 /* TODO: should actually remember the previously used seq#, both for TX
197 * and RX from each STA.. */
198
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800199 ret = wpa_drv_set_key(wpa_s, alg, NULL, 0, 1, seq, 6, key, keylen);
200 os_memset(key, 0, sizeof(key));
201 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202}
203
204
205static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
206{
207 struct wpa_supplicant *wpa_s = eloop_ctx;
208 const u8 *bssid = wpa_s->bssid;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700209 if (!is_zero_ether_addr(wpa_s->pending_bssid) &&
210 (wpa_s->wpa_state == WPA_AUTHENTICATING ||
211 wpa_s->wpa_state == WPA_ASSOCIATING))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212 bssid = wpa_s->pending_bssid;
213 wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
214 MAC2STR(bssid));
215 wpa_blacklist_add(wpa_s, bssid);
216 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800217 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 wpa_s->reassociate = 1;
Roshan Pius38e96762017-01-23 14:52:00 -0800219 wpas_notify_auth_timeout(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220
221 /*
222 * If we timed out, the AP or the local radio may be busy.
223 * So, wait a second until scanning again.
224 */
225 wpa_supplicant_req_scan(wpa_s, 1, 0);
226}
227
228
229/**
230 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
231 * @wpa_s: Pointer to wpa_supplicant data
232 * @sec: Number of seconds after which to time out authentication
233 * @usec: Number of microseconds after which to time out authentication
234 *
235 * This function is used to schedule a timeout for the current authentication
236 * attempt.
237 */
238void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
239 int sec, int usec)
240{
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700241 if (wpa_s->conf->ap_scan == 0 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
243 return;
244
245 wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
246 "%d usec", sec, usec);
247 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700248 wpa_s->last_auth_timeout_sec = sec;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249 eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL);
250}
251
252
Roshan Pius3a1667e2018-07-03 15:17:14 -0700253/*
254 * wpas_auth_timeout_restart - Restart and change timeout for authentication
255 * @wpa_s: Pointer to wpa_supplicant data
256 * @sec_diff: difference in seconds applied to original timeout value
257 */
258void wpas_auth_timeout_restart(struct wpa_supplicant *wpa_s, int sec_diff)
259{
260 int new_sec = wpa_s->last_auth_timeout_sec + sec_diff;
261
262 if (eloop_is_timeout_registered(wpa_supplicant_timeout, wpa_s, NULL)) {
263 wpa_dbg(wpa_s, MSG_DEBUG,
264 "Authentication timeout restart: %d sec", new_sec);
265 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
266 eloop_register_timeout(new_sec, 0, wpa_supplicant_timeout,
267 wpa_s, NULL);
268 }
269}
270
271
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272/**
273 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
274 * @wpa_s: Pointer to wpa_supplicant data
275 *
276 * This function is used to cancel authentication timeout scheduled with
277 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
278 * been completed.
279 */
280void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s)
281{
282 wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout");
283 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
284 wpa_blacklist_del(wpa_s, wpa_s->bssid);
Hai Shalomce48b4a2018-09-05 11:41:35 -0700285 os_free(wpa_s->last_con_fail_realm);
286 wpa_s->last_con_fail_realm = NULL;
287 wpa_s->last_con_fail_realm_len = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700288}
289
290
291/**
292 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
293 * @wpa_s: Pointer to wpa_supplicant data
294 *
295 * This function is used to configure EAPOL state machine based on the selected
296 * authentication mode.
297 */
298void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
299{
300#ifdef IEEE8021X_EAPOL
301 struct eapol_config eapol_conf;
302 struct wpa_ssid *ssid = wpa_s->current_ssid;
303
304#ifdef CONFIG_IBSS_RSN
305 if (ssid->mode == WPAS_MODE_IBSS &&
306 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
307 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
308 /*
309 * RSN IBSS authentication is per-STA and we can disable the
310 * per-BSSID EAPOL authentication.
311 */
312 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
313 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
314 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
315 return;
316 }
317#endif /* CONFIG_IBSS_RSN */
318
319 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
320 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
321
322 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
323 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
324 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
325 else
326 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
327
328 os_memset(&eapol_conf, 0, sizeof(eapol_conf));
329 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
330 eapol_conf.accept_802_1x_keys = 1;
331 eapol_conf.required_keys = 0;
332 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) {
333 eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST;
334 }
335 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) {
336 eapol_conf.required_keys |=
337 EAPOL_REQUIRE_KEY_BROADCAST;
338 }
339
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700340 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 eapol_conf.required_keys = 0;
342 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700343 eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344 eapol_conf.workaround = ssid->eap_workaround;
345 eapol_conf.eap_disabled =
346 !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
347 wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
348 wpa_s->key_mgmt != WPA_KEY_MGMT_WPS;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700349 eapol_conf.external_sim = wpa_s->conf->external_sim;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800350
351#ifdef CONFIG_WPS
352 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
353 eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE;
354 if (wpa_s->current_bss) {
355 struct wpabuf *ie;
356 ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
357 WPS_IE_VENDOR_TYPE);
358 if (ie) {
359 if (wps_is_20(ie))
360 eapol_conf.wps |=
361 EAPOL_PEER_IS_WPS20_AP;
362 wpabuf_free(ie);
363 }
364 }
365 }
366#endif /* CONFIG_WPS */
367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700368 eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700369
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800370#ifdef CONFIG_MACSEC
371 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE && ssid->mka_psk_set)
372 ieee802_1x_create_preshared_mka(wpa_s, ssid);
373 else
374 ieee802_1x_alloc_kay_sm(wpa_s, ssid);
375#endif /* CONFIG_MACSEC */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800376#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377}
378
379
380/**
381 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
382 * @wpa_s: Pointer to wpa_supplicant data
383 * @ssid: Configuration data for the network
384 *
385 * This function is used to configure WPA state machine and related parameters
386 * to a mode where WPA is not enabled. This is called as part of the
387 * authentication configuration when the selected network does not use WPA.
388 */
389void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
390 struct wpa_ssid *ssid)
391{
392 int i;
393
394 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
395 wpa_s->key_mgmt = WPA_KEY_MGMT_WPS;
396 else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)
397 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
398 else
399 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
400 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
401 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
402 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
403 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
404 wpa_s->group_cipher = WPA_CIPHER_NONE;
405 wpa_s->mgmt_group_cipher = 0;
406
407 for (i = 0; i < NUM_WEP_KEYS; i++) {
408 if (ssid->wep_key_len[i] > 5) {
409 wpa_s->pairwise_cipher = WPA_CIPHER_WEP104;
410 wpa_s->group_cipher = WPA_CIPHER_WEP104;
411 break;
412 } else if (ssid->wep_key_len[i] > 0) {
413 wpa_s->pairwise_cipher = WPA_CIPHER_WEP40;
414 wpa_s->group_cipher = WPA_CIPHER_WEP40;
415 break;
416 }
417 }
418
419 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0);
420 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
421 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
422 wpa_s->pairwise_cipher);
423 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
424#ifdef CONFIG_IEEE80211W
425 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
426 wpa_s->mgmt_group_cipher);
427#endif /* CONFIG_IEEE80211W */
428
429 pmksa_cache_clear_current(wpa_s->wpa);
430}
431
432
Dmitry Shmidt04949592012-07-19 12:16:46 -0700433void free_hw_features(struct wpa_supplicant *wpa_s)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800434{
435 int i;
436 if (wpa_s->hw.modes == NULL)
437 return;
438
439 for (i = 0; i < wpa_s->hw.num_modes; i++) {
440 os_free(wpa_s->hw.modes[i].channels);
441 os_free(wpa_s->hw.modes[i].rates);
442 }
443
444 os_free(wpa_s->hw.modes);
445 wpa_s->hw.modes = NULL;
446}
447
448
Hai Shalom74f70d42019-02-11 14:42:39 -0800449void free_bss_tmp_disallowed(struct wpa_supplicant *wpa_s)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800450{
451 struct wpa_bss_tmp_disallowed *bss, *prev;
452
453 dl_list_for_each_safe(bss, prev, &wpa_s->bss_tmp_disallowed,
454 struct wpa_bss_tmp_disallowed, list) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700455 eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800456 dl_list_del(&bss->list);
457 os_free(bss);
458 }
459}
460
461
Paul Stewart092955c2017-02-06 09:13:09 -0800462void wpas_flush_fils_hlp_req(struct wpa_supplicant *wpa_s)
463{
464 struct fils_hlp_req *req;
465
466 while ((req = dl_list_first(&wpa_s->fils_hlp_req, struct fils_hlp_req,
467 list)) != NULL) {
468 dl_list_del(&req->list);
469 wpabuf_free(req->pkt);
470 os_free(req);
471 }
472}
473
474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700475static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
476{
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700477 int i;
478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 bgscan_deinit(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700480 autoscan_deinit(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 scard_deinit(wpa_s->scard);
482 wpa_s->scard = NULL;
483 wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
484 eapol_sm_register_scard_ctx(wpa_s->eapol, NULL);
485 l2_packet_deinit(wpa_s->l2);
486 wpa_s->l2 = NULL;
487 if (wpa_s->l2_br) {
488 l2_packet_deinit(wpa_s->l2_br);
489 wpa_s->l2_br = NULL;
490 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800491#ifdef CONFIG_TESTING_OPTIONS
492 l2_packet_deinit(wpa_s->l2_test);
493 wpa_s->l2_test = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800494 os_free(wpa_s->get_pref_freq_list_override);
495 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700496 wpabuf_free(wpa_s->last_assoc_req_wpa_ie);
497 wpa_s->last_assoc_req_wpa_ie = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800498#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700500 if (wpa_s->conf != NULL) {
501 struct wpa_ssid *ssid;
502 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
503 wpas_notify_network_removed(wpa_s, ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 }
505
506 os_free(wpa_s->confname);
507 wpa_s->confname = NULL;
508
Jouni Malinen5d1c8ad2013-04-23 12:34:56 -0700509 os_free(wpa_s->confanother);
510 wpa_s->confanother = NULL;
511
Hai Shalomce48b4a2018-09-05 11:41:35 -0700512 os_free(wpa_s->last_con_fail_realm);
513 wpa_s->last_con_fail_realm = NULL;
514 wpa_s->last_con_fail_realm_len = 0;
515
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 wpa_sm_set_eapol(wpa_s->wpa, NULL);
517 eapol_sm_deinit(wpa_s->eapol);
518 wpa_s->eapol = NULL;
519
520 rsn_preauth_deinit(wpa_s->wpa);
521
522#ifdef CONFIG_TDLS
523 wpa_tdls_deinit(wpa_s->wpa);
524#endif /* CONFIG_TDLS */
525
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800526 wmm_ac_clear_saved_tspecs(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 pmksa_candidate_free(wpa_s->wpa);
528 wpa_sm_deinit(wpa_s->wpa);
529 wpa_s->wpa = NULL;
530 wpa_blacklist_clear(wpa_s);
531
532 wpa_bss_deinit(wpa_s);
533
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700534 wpa_supplicant_cancel_delayed_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 wpa_supplicant_cancel_scan(wpa_s);
536 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
538#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
539 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report,
540 wpa_s, NULL);
541#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700543 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545 wpas_wps_deinit(wpa_s);
546
547 wpabuf_free(wpa_s->pending_eapol_rx);
548 wpa_s->pending_eapol_rx = NULL;
549
550#ifdef CONFIG_IBSS_RSN
551 ibss_rsn_deinit(wpa_s->ibss_rsn);
552 wpa_s->ibss_rsn = NULL;
553#endif /* CONFIG_IBSS_RSN */
554
555 sme_deinit(wpa_s);
556
557#ifdef CONFIG_AP
558 wpa_supplicant_ap_deinit(wpa_s);
559#endif /* CONFIG_AP */
560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 wpas_p2p_deinit(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563#ifdef CONFIG_OFFCHANNEL
564 offchannel_deinit(wpa_s);
565#endif /* CONFIG_OFFCHANNEL */
566
567 wpa_supplicant_cancel_sched_scan(wpa_s);
568
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569 os_free(wpa_s->next_scan_freqs);
570 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800571
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800572 os_free(wpa_s->manual_scan_freqs);
573 wpa_s->manual_scan_freqs = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700574 os_free(wpa_s->select_network_scan_freqs);
575 wpa_s->select_network_scan_freqs = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800576
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700577 os_free(wpa_s->manual_sched_scan_freqs);
578 wpa_s->manual_sched_scan_freqs = NULL;
579
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800580 wpas_mac_addr_rand_scan_clear(wpa_s, MAC_ADDR_RAND_ALL);
581
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700582 /*
583 * Need to remove any pending gas-query radio work before the
584 * gas_query_deinit() call because gas_query::work has not yet been set
585 * for works that have not been started. gas_query_free() will be unable
586 * to cancel such pending radio works and once the pending gas-query
587 * radio work eventually gets removed, the deinit notification call to
588 * gas_query_start_cb() would result in dereferencing freed memory.
589 */
590 if (wpa_s->radio)
591 radio_remove_works(wpa_s, "gas-query", 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800592 gas_query_deinit(wpa_s->gas);
593 wpa_s->gas = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700594 gas_server_deinit(wpa_s->gas_server);
595 wpa_s->gas_server = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800596
597 free_hw_features(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700598
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700599 ieee802_1x_dealloc_kay_sm(wpa_s);
600
Dmitry Shmidt04949592012-07-19 12:16:46 -0700601 os_free(wpa_s->bssid_filter);
602 wpa_s->bssid_filter = NULL;
603
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800604 os_free(wpa_s->disallow_aps_bssid);
605 wpa_s->disallow_aps_bssid = NULL;
606 os_free(wpa_s->disallow_aps_ssid);
607 wpa_s->disallow_aps_ssid = NULL;
608
Dmitry Shmidt04949592012-07-19 12:16:46 -0700609 wnm_bss_keep_alive_deinit(wpa_s);
Dmitry Shmidt44c95782013-05-17 09:51:35 -0700610#ifdef CONFIG_WNM
611 wnm_deallocate_memory(wpa_s);
612#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700613
614 ext_password_deinit(wpa_s->ext_pw);
615 wpa_s->ext_pw = NULL;
616
617 wpabuf_free(wpa_s->last_gas_resp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800618 wpa_s->last_gas_resp = NULL;
619 wpabuf_free(wpa_s->prev_gas_resp);
620 wpa_s->prev_gas_resp = NULL;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700621
622 os_free(wpa_s->last_scan_res);
623 wpa_s->last_scan_res = NULL;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800624
625#ifdef CONFIG_HS20
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700626 if (wpa_s->drv_priv)
627 wpa_drv_configure_frame_filters(wpa_s, 0);
Dmitry Shmidt684785c2014-05-12 13:34:29 -0700628 hs20_deinit(wpa_s);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800629#endif /* CONFIG_HS20 */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -0700630
631 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
632 wpabuf_free(wpa_s->vendor_elem[i]);
633 wpa_s->vendor_elem[i] = NULL;
634 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800635
636 wmm_ac_notify_disassoc(wpa_s);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800637
638 wpa_s->sched_scan_plans_num = 0;
639 os_free(wpa_s->sched_scan_plans);
640 wpa_s->sched_scan_plans = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800641
642#ifdef CONFIG_MBO
643 wpa_s->non_pref_chan_num = 0;
644 os_free(wpa_s->non_pref_chan);
645 wpa_s->non_pref_chan = NULL;
646#endif /* CONFIG_MBO */
647
648 free_bss_tmp_disallowed(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700649
650 wpabuf_free(wpa_s->lci);
651 wpa_s->lci = NULL;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800652 wpas_clear_beacon_rep_data(wpa_s);
Paul Stewart092955c2017-02-06 09:13:09 -0800653
654#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
655#ifdef CONFIG_MESH
656 {
657 struct external_pmksa_cache *entry;
658
659 while ((entry = dl_list_last(&wpa_s->mesh_external_pmksa_cache,
660 struct external_pmksa_cache,
661 list)) != NULL) {
662 dl_list_del(&entry->list);
663 os_free(entry->pmksa_cache);
664 os_free(entry);
665 }
666 }
667#endif /* CONFIG_MESH */
668#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
669
670 wpas_flush_fils_hlp_req(wpa_s);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800671
672 wpabuf_free(wpa_s->ric_ies);
673 wpa_s->ric_ies = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700674
675#ifdef CONFIG_DPP
676 wpas_dpp_deinit(wpa_s);
Hai Shalom021b0b52019-04-10 11:17:58 -0700677 dpp_global_deinit(wpa_s->dpp);
678 wpa_s->dpp = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700679#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680}
681
682
683/**
684 * wpa_clear_keys - Clear keys configured for the driver
685 * @wpa_s: Pointer to wpa_supplicant data
686 * @addr: Previously used BSSID or %NULL if not available
687 *
688 * This function clears the encryption keys that has been previously configured
689 * for the driver.
690 */
691void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
692{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800693 int i, max;
694
695#ifdef CONFIG_IEEE80211W
696 max = 6;
697#else /* CONFIG_IEEE80211W */
698 max = 4;
699#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700
701 /* MLME-DELETEKEYS.request */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800702 for (i = 0; i < max; i++) {
703 if (wpa_s->keys_cleared & BIT(i))
704 continue;
705 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, i, 0, NULL, 0,
706 NULL, 0);
707 }
708 if (!(wpa_s->keys_cleared & BIT(0)) && addr &&
709 !is_zero_ether_addr(addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL,
711 0);
712 /* MLME-SETPROTECTION.request(None) */
713 wpa_drv_mlme_setprotection(
714 wpa_s, addr,
715 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
716 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
717 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800718 wpa_s->keys_cleared = (u32) -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719}
720
721
722/**
723 * wpa_supplicant_state_txt - Get the connection state name as a text string
724 * @state: State (wpa_state; WPA_*)
725 * Returns: The state name as a printable text string
726 */
727const char * wpa_supplicant_state_txt(enum wpa_states state)
728{
729 switch (state) {
730 case WPA_DISCONNECTED:
731 return "DISCONNECTED";
732 case WPA_INACTIVE:
733 return "INACTIVE";
734 case WPA_INTERFACE_DISABLED:
735 return "INTERFACE_DISABLED";
736 case WPA_SCANNING:
737 return "SCANNING";
738 case WPA_AUTHENTICATING:
739 return "AUTHENTICATING";
740 case WPA_ASSOCIATING:
741 return "ASSOCIATING";
742 case WPA_ASSOCIATED:
743 return "ASSOCIATED";
744 case WPA_4WAY_HANDSHAKE:
745 return "4WAY_HANDSHAKE";
746 case WPA_GROUP_HANDSHAKE:
747 return "GROUP_HANDSHAKE";
748 case WPA_COMPLETED:
749 return "COMPLETED";
750 default:
751 return "UNKNOWN";
752 }
753}
754
755
756#ifdef CONFIG_BGSCAN
757
758static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s)
759{
Dmitry Shmidtb96dad42013-11-05 10:07:29 -0800760 const char *name;
761
762 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan)
763 name = wpa_s->current_ssid->bgscan;
764 else
765 name = wpa_s->conf->bgscan;
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800766 if (name == NULL || name[0] == '\0')
Dmitry Shmidtb96dad42013-11-05 10:07:29 -0800767 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800768 if (wpas_driver_bss_selection(wpa_s))
769 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 if (wpa_s->current_ssid == wpa_s->bgscan_ssid)
771 return;
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800772#ifdef CONFIG_P2P
773 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
774 return;
775#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776
777 bgscan_deinit(wpa_s);
Dmitry Shmidtb96dad42013-11-05 10:07:29 -0800778 if (wpa_s->current_ssid) {
779 if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
781 "bgscan");
782 /*
783 * Live without bgscan; it is only used as a roaming
784 * optimization, so the initial connection is not
785 * affected.
786 */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700787 } else {
788 struct wpa_scan_results *scan_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 wpa_s->bgscan_ssid = wpa_s->current_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700790 scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL,
791 0);
792 if (scan_res) {
793 bgscan_notify_scan(wpa_s, scan_res);
794 wpa_scan_results_free(scan_res);
795 }
796 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 } else
798 wpa_s->bgscan_ssid = NULL;
799}
800
801
802static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s)
803{
804 if (wpa_s->bgscan_ssid != NULL) {
805 bgscan_deinit(wpa_s);
806 wpa_s->bgscan_ssid = NULL;
807 }
808}
809
810#endif /* CONFIG_BGSCAN */
811
812
Dmitry Shmidt04949592012-07-19 12:16:46 -0700813static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s)
814{
815 if (autoscan_init(wpa_s, 0))
816 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan");
817}
818
819
820static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s)
821{
822 autoscan_deinit(wpa_s);
823}
824
825
826void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s)
827{
828 if (wpa_s->wpa_state == WPA_DISCONNECTED ||
829 wpa_s->wpa_state == WPA_SCANNING) {
830 autoscan_deinit(wpa_s);
831 wpa_supplicant_start_autoscan(wpa_s);
832 }
833}
834
835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836/**
837 * wpa_supplicant_set_state - Set current connection state
838 * @wpa_s: Pointer to wpa_supplicant data
839 * @state: The new connection state
840 *
841 * This function is called whenever the connection state changes, e.g.,
842 * association is completed for WPA/WPA2 4-Way Handshake is started.
843 */
844void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
845 enum wpa_states state)
846{
847 enum wpa_states old_state = wpa_s->wpa_state;
848
849 wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s",
850 wpa_supplicant_state_txt(wpa_s->wpa_state),
851 wpa_supplicant_state_txt(state));
852
Hai Shalom74f70d42019-02-11 14:42:39 -0800853 if (state == WPA_COMPLETED &&
854 os_reltime_initialized(&wpa_s->roam_start)) {
855 os_reltime_age(&wpa_s->roam_start, &wpa_s->roam_time);
856 wpa_s->roam_start.sec = 0;
857 wpa_s->roam_start.usec = 0;
858 wpas_notify_auth_changed(wpa_s);
859 wpas_notify_roam_time(wpa_s);
860 wpas_notify_roam_complete(wpa_s);
861 } else if (state == WPA_DISCONNECTED &&
862 os_reltime_initialized(&wpa_s->roam_start)) {
863 wpa_s->roam_start.sec = 0;
864 wpa_s->roam_start.usec = 0;
865 wpa_s->roam_time.sec = 0;
866 wpa_s->roam_time.usec = 0;
867 wpas_notify_roam_complete(wpa_s);
868 }
869
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -0800870 if (state == WPA_INTERFACE_DISABLED) {
871 /* Assure normal scan when interface is restored */
872 wpa_s->normal_scans = 0;
873 }
874
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700875 if (state == WPA_COMPLETED) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800876 wpas_connect_work_done(wpa_s);
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700877 /* Reinitialize normal_scan counter */
878 wpa_s->normal_scans = 0;
879 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800880
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700881#ifdef CONFIG_P2P
882 /*
883 * P2PS client has to reply to Probe Request frames received on the
884 * group operating channel. Enable Probe Request frame reporting for
885 * P2P connected client in case p2p_cli_probe configuration property is
886 * set to 1.
887 */
888 if (wpa_s->conf->p2p_cli_probe && wpa_s->current_ssid &&
889 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
890 wpa_s->current_ssid->p2p_group) {
891 if (state == WPA_COMPLETED && !wpa_s->p2p_cli_probe) {
892 wpa_dbg(wpa_s, MSG_DEBUG,
893 "P2P: Enable CLI Probe Request RX reporting");
894 wpa_s->p2p_cli_probe =
895 wpa_drv_probe_req_report(wpa_s, 1) >= 0;
896 } else if (state != WPA_COMPLETED && wpa_s->p2p_cli_probe) {
897 wpa_dbg(wpa_s, MSG_DEBUG,
898 "P2P: Disable CLI Probe Request RX reporting");
899 wpa_s->p2p_cli_probe = 0;
900 wpa_drv_probe_req_report(wpa_s, 0);
901 }
902 }
903#endif /* CONFIG_P2P */
904
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905 if (state != WPA_SCANNING)
906 wpa_supplicant_notify_scanning(wpa_s, 0);
907
908 if (state == WPA_COMPLETED && wpa_s->new_connection) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700910 int fils_hlp_sent = 0;
911
912#ifdef CONFIG_SME
913 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
914 wpa_auth_alg_fils(wpa_s->sme.auth_alg))
915 fils_hlp_sent = 1;
916#endif /* CONFIG_SME */
917 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
918 wpa_auth_alg_fils(wpa_s->auth_alg))
919 fils_hlp_sent = 1;
920
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700921#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to "
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700923 MACSTR " completed [id=%d id_str=%s%s]",
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800924 MAC2STR(wpa_s->bssid),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 ssid ? ssid->id : -1,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700926 ssid && ssid->id_str ? ssid->id_str : "",
927 fils_hlp_sent ? " FILS_HLP_SENT" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700929 wpas_clear_temp_disabled(wpa_s, ssid, 1);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700930 wpa_blacklist_clear(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800931 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 wpa_s->new_connection = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933 wpa_drv_set_operstate(wpa_s, 1);
934#ifndef IEEE8021X_EAPOL
935 wpa_drv_set_supp_port(wpa_s, 1);
936#endif /* IEEE8021X_EAPOL */
937 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700938 wpa_s->known_wps_freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939 wpas_p2p_completed(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700940
941 sme_sched_obss_scan(wpa_s, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700942
943#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
944 if (!fils_hlp_sent && ssid && ssid->eap.erp)
945 wpas_update_fils_connect_params(wpa_s);
946#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
948 state == WPA_ASSOCIATED) {
949 wpa_s->new_connection = 1;
950 wpa_drv_set_operstate(wpa_s, 0);
951#ifndef IEEE8021X_EAPOL
952 wpa_drv_set_supp_port(wpa_s, 0);
953#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700954 sme_sched_obss_scan(wpa_s, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 }
956 wpa_s->wpa_state = state;
957
958#ifdef CONFIG_BGSCAN
959 if (state == WPA_COMPLETED)
960 wpa_supplicant_start_bgscan(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800961 else if (state < WPA_ASSOCIATED)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 wpa_supplicant_stop_bgscan(wpa_s);
963#endif /* CONFIG_BGSCAN */
964
Dmitry Shmidt04949592012-07-19 12:16:46 -0700965 if (state == WPA_AUTHENTICATING)
966 wpa_supplicant_stop_autoscan(wpa_s);
967
968 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
969 wpa_supplicant_start_autoscan(wpa_s);
970
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800971 if (old_state >= WPA_ASSOCIATED && wpa_s->wpa_state < WPA_ASSOCIATED)
972 wmm_ac_notify_disassoc(wpa_s);
973
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974 if (wpa_s->wpa_state != old_state) {
975 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
976
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700977 /*
978 * Notify the P2P Device interface about a state change in one
979 * of the interfaces.
980 */
981 wpas_p2p_indicate_state_change(wpa_s);
982
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983 if (wpa_s->wpa_state == WPA_COMPLETED ||
984 old_state == WPA_COMPLETED)
985 wpas_notify_auth_changed(wpa_s);
986 }
987}
988
989
990void wpa_supplicant_terminate_proc(struct wpa_global *global)
991{
992 int pending = 0;
993#ifdef CONFIG_WPS
994 struct wpa_supplicant *wpa_s = global->ifaces;
995 while (wpa_s) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800996 struct wpa_supplicant *next = wpa_s->next;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -0700997 if (wpas_wps_terminate_pending(wpa_s) == 1)
998 pending = 1;
Dmitry Shmidt56052862013-10-04 10:23:25 -0700999#ifdef CONFIG_P2P
1000 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE ||
1001 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group))
1002 wpas_p2p_disconnect(wpa_s);
1003#endif /* CONFIG_P2P */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001004 wpa_s = next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 }
1006#endif /* CONFIG_WPS */
1007 if (pending)
1008 return;
1009 eloop_terminate();
1010}
1011
1012
1013static void wpa_supplicant_terminate(int sig, void *signal_ctx)
1014{
1015 struct wpa_global *global = signal_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016 wpa_supplicant_terminate_proc(global);
1017}
1018
1019
1020void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
1021{
1022 enum wpa_states old_state = wpa_s->wpa_state;
1023
1024 wpa_s->pairwise_cipher = 0;
1025 wpa_s->group_cipher = 0;
1026 wpa_s->mgmt_group_cipher = 0;
1027 wpa_s->key_mgmt = 0;
1028 if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001029 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030
1031 if (wpa_s->wpa_state != old_state)
1032 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
1033}
1034
1035
1036/**
1037 * wpa_supplicant_reload_configuration - Reload configuration data
1038 * @wpa_s: Pointer to wpa_supplicant data
1039 * Returns: 0 on success or -1 if configuration parsing failed
1040 *
1041 * This function can be used to request that the configuration data is reloaded
1042 * (e.g., after configuration file change). This function is reloading
1043 * configuration only for one interface, so this may need to be called multiple
1044 * times if %wpa_supplicant is controlling multiple interfaces and all
1045 * interfaces need reconfiguration.
1046 */
1047int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
1048{
1049 struct wpa_config *conf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 int reconf_ctrl;
1051 int old_ap_scan;
1052
1053 if (wpa_s->confname == NULL)
1054 return -1;
Dmitry Shmidt64f47c52013-04-16 10:41:54 -07001055 conf = wpa_config_read(wpa_s->confname, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 if (conf == NULL) {
1057 wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration "
1058 "file '%s' - exiting", wpa_s->confname);
1059 return -1;
1060 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001061 if (wpa_s->confanother &&
1062 !wpa_config_read(wpa_s->confanother, conf)) {
1063 wpa_msg(wpa_s, MSG_ERROR,
1064 "Failed to parse the configuration file '%s' - exiting",
1065 wpa_s->confanother);
1066 return -1;
1067 }
Dmitry Shmidt64f47c52013-04-16 10:41:54 -07001068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 conf->changed_parameters = (unsigned int) -1;
1070
1071 reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface
1072 || (conf->ctrl_interface && wpa_s->conf->ctrl_interface &&
1073 os_strcmp(conf->ctrl_interface,
1074 wpa_s->conf->ctrl_interface) != 0);
1075
1076 if (reconf_ctrl && wpa_s->ctrl_iface) {
1077 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
1078 wpa_s->ctrl_iface = NULL;
1079 }
1080
1081 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001082 if (wpa_s->current_ssid) {
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001083 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1084 wpa_s->own_disconnect_req = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001085 wpa_supplicant_deauthenticate(wpa_s,
1086 WLAN_REASON_DEAUTH_LEAVING);
1087 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
1089 /*
1090 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001091 * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001093 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
1094 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
1095 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 /*
1097 * Clear forced success to clear EAP state for next
1098 * authentication.
1099 */
1100 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1101 }
1102 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1103 wpa_sm_set_config(wpa_s->wpa, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001104 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
1106 rsn_preauth_deinit(wpa_s->wpa);
1107
1108 old_ap_scan = wpa_s->conf->ap_scan;
1109 wpa_config_free(wpa_s->conf);
1110 wpa_s->conf = conf;
1111 if (old_ap_scan != wpa_s->conf->ap_scan)
1112 wpas_notify_ap_scan_changed(wpa_s);
1113
1114 if (reconf_ctrl)
1115 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
1116
1117 wpa_supplicant_update_config(wpa_s);
1118
1119 wpa_supplicant_clear_status(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001120 if (wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 wpa_s->reassociate = 1;
1122 wpa_supplicant_req_scan(wpa_s, 0, 0);
1123 }
1124 wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed");
1125 return 0;
1126}
1127
1128
1129static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
1130{
1131 struct wpa_global *global = signal_ctx;
1132 struct wpa_supplicant *wpa_s;
1133 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
1134 wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring",
1135 sig);
1136 if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
1137 wpa_supplicant_terminate_proc(global);
1138 }
1139 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001140
1141 if (wpa_debug_reopen_file() < 0) {
1142 /* Ignore errors since we cannot really do much to fix this */
1143 wpa_printf(MSG_DEBUG, "Could not reopen debug log file");
1144 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145}
1146
1147
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
1149 struct wpa_ssid *ssid,
1150 struct wpa_ie_data *ie)
1151{
1152 int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie);
1153 if (ret) {
1154 if (ret == -2) {
1155 wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE "
1156 "from association info");
1157 }
1158 return -1;
1159 }
1160
1161 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set "
1162 "cipher suites");
1163 if (!(ie->group_cipher & ssid->group_cipher)) {
1164 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group "
1165 "cipher 0x%x (mask 0x%x) - reject",
1166 ie->group_cipher, ssid->group_cipher);
1167 return -1;
1168 }
1169 if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) {
1170 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise "
1171 "cipher 0x%x (mask 0x%x) - reject",
1172 ie->pairwise_cipher, ssid->pairwise_cipher);
1173 return -1;
1174 }
1175 if (!(ie->key_mgmt & ssid->key_mgmt)) {
1176 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key "
1177 "management 0x%x (mask 0x%x) - reject",
1178 ie->key_mgmt, ssid->key_mgmt);
1179 return -1;
1180 }
1181
1182#ifdef CONFIG_IEEE80211W
1183 if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001184 wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
1186 "that does not support management frame protection - "
1187 "reject");
1188 return -1;
1189 }
1190#endif /* CONFIG_IEEE80211W */
1191
1192 return 0;
1193}
1194
1195
Hai Shalom021b0b52019-04-10 11:17:58 -07001196static int matching_ciphers(struct wpa_ssid *ssid, struct wpa_ie_data *ie,
1197 int freq)
1198{
1199 if (!ie->has_group)
1200 ie->group_cipher = wpa_default_rsn_cipher(freq);
1201 if (!ie->has_pairwise)
1202 ie->pairwise_cipher = wpa_default_rsn_cipher(freq);
1203 return (ie->group_cipher & ssid->group_cipher) &&
1204 (ie->pairwise_cipher & ssid->pairwise_cipher);
1205}
1206
1207
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208/**
1209 * wpa_supplicant_set_suites - Set authentication and encryption parameters
1210 * @wpa_s: Pointer to wpa_supplicant data
1211 * @bss: Scan results for the selected BSS, or %NULL if not available
1212 * @ssid: Configuration data for the selected network
1213 * @wpa_ie: Buffer for the WPA/RSN IE
1214 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
1215 * used buffer length in case the functions returns success.
1216 * Returns: 0 on success or -1 on failure
1217 *
1218 * This function is used to configure authentication and encryption parameters
1219 * based on the network configuration and scan result for the selected BSS (if
1220 * available).
1221 */
1222int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
1223 struct wpa_bss *bss, struct wpa_ssid *ssid,
1224 u8 *wpa_ie, size_t *wpa_ie_len)
1225{
1226 struct wpa_ie_data ie;
1227 int sel, proto;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001228 const u8 *bss_wpa, *bss_rsn, *bss_osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229
1230 if (bss) {
1231 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1232 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001233 bss_osen = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 } else
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001235 bss_wpa = bss_rsn = bss_osen = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236
1237 if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) &&
1238 wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
Hai Shalom021b0b52019-04-10 11:17:58 -07001239 matching_ciphers(ssid, &ie, bss->freq) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 (ie.key_mgmt & ssid->key_mgmt)) {
1241 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0");
1242 proto = WPA_PROTO_RSN;
1243 } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244 wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 (ie.group_cipher & ssid->group_cipher) &&
1246 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
1247 (ie.key_mgmt & ssid->key_mgmt)) {
1248 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0");
1249 proto = WPA_PROTO_WPA;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001250#ifdef CONFIG_HS20
Hai Shalom74f70d42019-02-11 14:42:39 -08001251 } else if (bss_osen && (ssid->proto & WPA_PROTO_OSEN) &&
1252 wpa_parse_wpa_ie(bss_osen, 2 + bss_osen[1], &ie) == 0 &&
1253 (ie.group_cipher & ssid->group_cipher) &&
1254 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
1255 (ie.key_mgmt & ssid->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001256 wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using OSEN");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001257 proto = WPA_PROTO_OSEN;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001258 } else if (bss_rsn && (ssid->proto & WPA_PROTO_OSEN) &&
1259 wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
1260 (ie.group_cipher & ssid->group_cipher) &&
1261 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
1262 (ie.key_mgmt & ssid->key_mgmt)) {
1263 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using OSEN (within RSN)");
1264 proto = WPA_PROTO_RSN;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001265#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266 } else if (bss) {
1267 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001268 wpa_dbg(wpa_s, MSG_DEBUG,
1269 "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1270 ssid->proto, ssid->pairwise_cipher, ssid->group_cipher,
1271 ssid->key_mgmt);
1272 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s%s",
1273 MAC2STR(bss->bssid),
1274 wpa_ssid_txt(bss->ssid, bss->ssid_len),
1275 bss_wpa ? " WPA" : "",
1276 bss_rsn ? " RSN" : "",
1277 bss_osen ? " OSEN" : "");
1278 if (bss_rsn) {
1279 wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]);
1280 if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) {
1281 wpa_dbg(wpa_s, MSG_DEBUG,
1282 "Could not parse RSN element");
1283 } else {
1284 wpa_dbg(wpa_s, MSG_DEBUG,
1285 "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1286 ie.pairwise_cipher, ie.group_cipher,
1287 ie.key_mgmt);
1288 }
1289 }
1290 if (bss_wpa) {
1291 wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]);
1292 if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) {
1293 wpa_dbg(wpa_s, MSG_DEBUG,
1294 "Could not parse WPA element");
1295 } else {
1296 wpa_dbg(wpa_s, MSG_DEBUG,
1297 "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1298 ie.pairwise_cipher, ie.group_cipher,
1299 ie.key_mgmt);
1300 }
1301 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302 return -1;
1303 } else {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001304 if (ssid->proto & WPA_PROTO_OSEN)
1305 proto = WPA_PROTO_OSEN;
1306 else if (ssid->proto & WPA_PROTO_RSN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 proto = WPA_PROTO_RSN;
1308 else
1309 proto = WPA_PROTO_WPA;
1310 if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) {
1311 os_memset(&ie, 0, sizeof(ie));
1312 ie.group_cipher = ssid->group_cipher;
1313 ie.pairwise_cipher = ssid->pairwise_cipher;
1314 ie.key_mgmt = ssid->key_mgmt;
1315#ifdef CONFIG_IEEE80211W
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001316 ie.mgmt_group_cipher = 0;
1317 if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1318 if (ssid->group_mgmt_cipher &
1319 WPA_CIPHER_BIP_GMAC_256)
1320 ie.mgmt_group_cipher =
1321 WPA_CIPHER_BIP_GMAC_256;
1322 else if (ssid->group_mgmt_cipher &
1323 WPA_CIPHER_BIP_CMAC_256)
1324 ie.mgmt_group_cipher =
1325 WPA_CIPHER_BIP_CMAC_256;
1326 else if (ssid->group_mgmt_cipher &
1327 WPA_CIPHER_BIP_GMAC_128)
1328 ie.mgmt_group_cipher =
1329 WPA_CIPHER_BIP_GMAC_128;
1330 else
1331 ie.mgmt_group_cipher =
1332 WPA_CIPHER_AES_128_CMAC;
1333 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001334#endif /* CONFIG_IEEE80211W */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001335#ifdef CONFIG_OWE
1336 if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1337 !ssid->owe_only &&
1338 !bss_wpa && !bss_rsn && !bss_osen) {
1339 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1340 wpa_s->wpa_proto = 0;
1341 *wpa_ie_len = 0;
1342 return 0;
1343 }
1344#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites "
1346 "based on configuration");
1347 } else
1348 proto = ie.proto;
1349 }
1350
1351 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d "
1352 "pairwise %d key_mgmt %d proto %d",
1353 ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto);
1354#ifdef CONFIG_IEEE80211W
1355 if (ssid->ieee80211w) {
1356 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d",
1357 ie.mgmt_group_cipher);
1358 }
1359#endif /* CONFIG_IEEE80211W */
1360
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001361 wpa_s->wpa_proto = proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto);
1363 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001364 !!(ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365
1366 if (bss || !wpa_s->ap_ies_from_associnfo) {
1367 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1368 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1369 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1370 bss_rsn ? 2 + bss_rsn[1] : 0))
1371 return -1;
1372 }
1373
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001374#ifdef CONFIG_NO_WPA
1375 wpa_s->group_cipher = WPA_CIPHER_NONE;
1376 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
1377#else /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378 sel = ie.group_cipher & ssid->group_cipher;
Hai Shalom021b0b52019-04-10 11:17:58 -07001379 wpa_dbg(wpa_s, MSG_DEBUG,
1380 "WPA: AP group 0x%x network profile group 0x%x; available group 0x%x",
1381 ie.group_cipher, ssid->group_cipher, sel);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001382 wpa_s->group_cipher = wpa_pick_group_cipher(sel);
1383 if (wpa_s->group_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group "
1385 "cipher");
1386 return -1;
1387 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001388 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
1389 wpa_cipher_txt(wpa_s->group_cipher));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001390
1391 sel = ie.pairwise_cipher & ssid->pairwise_cipher;
Hai Shalom021b0b52019-04-10 11:17:58 -07001392 wpa_dbg(wpa_s, MSG_DEBUG,
1393 "WPA: AP pairwise 0x%x network profile pairwise 0x%x; available pairwise 0x%x",
1394 ie.pairwise_cipher, ssid->pairwise_cipher, sel);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001395 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1);
1396 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001397 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise "
1398 "cipher");
1399 return -1;
1400 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001401 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
1402 wpa_cipher_txt(wpa_s->pairwise_cipher));
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001403#endif /* CONFIG_NO_WPA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404
1405 sel = ie.key_mgmt & ssid->key_mgmt;
Hai Shalom021b0b52019-04-10 11:17:58 -07001406 wpa_dbg(wpa_s, MSG_DEBUG,
1407 "WPA: AP key_mgmt 0x%x network profile key_mgmt 0x%x; available key_mgmt 0x%x",
1408 ie.key_mgmt, ssid->key_mgmt, sel);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001409#ifdef CONFIG_SAE
1410 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE))
1411 sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE);
1412#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413 if (0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001414#ifdef CONFIG_IEEE80211R
1415#ifdef CONFIG_SHA384
1416 } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) {
1417 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
1418 wpa_dbg(wpa_s, MSG_DEBUG,
1419 "WPA: using KEY_MGMT FT/802.1X-SHA384");
1420 if (pmksa_cache_get_current(wpa_s->wpa)) {
1421 /* PMKSA caching with FT is not fully functional, so
1422 * disable the case for now. */
1423 wpa_dbg(wpa_s, MSG_DEBUG,
1424 "WPA: Disable PMKSA caching for FT/802.1X connection");
1425 pmksa_cache_clear_current(wpa_s->wpa);
1426 }
1427#endif /* CONFIG_SHA384 */
1428#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001429#ifdef CONFIG_SUITEB192
1430 } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
1431 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
1432 wpa_dbg(wpa_s, MSG_DEBUG,
1433 "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)");
1434#endif /* CONFIG_SUITEB192 */
1435#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001436 } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
1437 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B;
1438 wpa_dbg(wpa_s, MSG_DEBUG,
1439 "WPA: using KEY_MGMT 802.1X with Suite B");
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001440#endif /* CONFIG_SUITEB */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001441#ifdef CONFIG_FILS
1442#ifdef CONFIG_IEEE80211R
1443 } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA384) {
1444 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384;
1445 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA384");
1446 } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA256) {
1447 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256;
1448 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA256");
1449#endif /* CONFIG_IEEE80211R */
1450 } else if (sel & WPA_KEY_MGMT_FILS_SHA384) {
1451 wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA384;
1452 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA384");
1453 } else if (sel & WPA_KEY_MGMT_FILS_SHA256) {
1454 wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA256;
1455 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA256");
1456#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457#ifdef CONFIG_IEEE80211R
1458 } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) {
1459 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
1460 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001461 if (pmksa_cache_get_current(wpa_s->wpa)) {
1462 /* PMKSA caching with FT is not fully functional, so
1463 * disable the case for now. */
1464 wpa_dbg(wpa_s, MSG_DEBUG,
1465 "WPA: Disable PMKSA caching for FT/802.1X connection");
1466 pmksa_cache_clear_current(wpa_s->wpa);
1467 }
Hai Shalom021b0b52019-04-10 11:17:58 -07001468#endif /* CONFIG_IEEE80211R */
1469#ifdef CONFIG_DPP
1470 } else if (sel & WPA_KEY_MGMT_DPP) {
1471 wpa_s->key_mgmt = WPA_KEY_MGMT_DPP;
1472 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT DPP");
1473#endif /* CONFIG_DPP */
1474#ifdef CONFIG_SAE
1475 } else if (sel & WPA_KEY_MGMT_FT_SAE) {
1476 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE;
1477 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE");
1478 } else if (sel & WPA_KEY_MGMT_SAE) {
1479 wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
1480 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE");
1481#endif /* CONFIG_SAE */
1482#ifdef CONFIG_IEEE80211R
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001483 } else if (sel & WPA_KEY_MGMT_FT_PSK) {
1484 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK;
1485 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK");
1486#endif /* CONFIG_IEEE80211R */
1487#ifdef CONFIG_IEEE80211W
1488 } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1489 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
1490 wpa_dbg(wpa_s, MSG_DEBUG,
1491 "WPA: using KEY_MGMT 802.1X with SHA256");
1492 } else if (sel & WPA_KEY_MGMT_PSK_SHA256) {
1493 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
1494 wpa_dbg(wpa_s, MSG_DEBUG,
1495 "WPA: using KEY_MGMT PSK with SHA256");
1496#endif /* CONFIG_IEEE80211W */
1497 } else if (sel & WPA_KEY_MGMT_IEEE8021X) {
1498 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
1499 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X");
1500 } else if (sel & WPA_KEY_MGMT_PSK) {
1501 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
1502 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK");
1503 } else if (sel & WPA_KEY_MGMT_WPA_NONE) {
1504 wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE;
1505 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001506#ifdef CONFIG_HS20
1507 } else if (sel & WPA_KEY_MGMT_OSEN) {
1508 wpa_s->key_mgmt = WPA_KEY_MGMT_OSEN;
1509 wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using KEY_MGMT OSEN");
1510#endif /* CONFIG_HS20 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001511#ifdef CONFIG_OWE
1512 } else if (sel & WPA_KEY_MGMT_OWE) {
1513 wpa_s->key_mgmt = WPA_KEY_MGMT_OWE;
1514 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT OWE");
1515#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001516 } else {
1517 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select "
1518 "authenticated key management type");
1519 return -1;
1520 }
1521
1522 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
1523 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
1524 wpa_s->pairwise_cipher);
1525 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
1526
1527#ifdef CONFIG_IEEE80211W
1528 sel = ie.mgmt_group_cipher;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001529 if (ssid->group_mgmt_cipher)
1530 sel &= ssid->group_mgmt_cipher;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001531 if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001532 !(ie.capabilities & WPA_CAPABILITY_MFPC))
1533 sel = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -07001534 wpa_dbg(wpa_s, MSG_DEBUG,
1535 "WPA: AP mgmt_group_cipher 0x%x network profile mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
1536 ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537 if (sel & WPA_CIPHER_AES_128_CMAC) {
1538 wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
1539 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1540 "AES-128-CMAC");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001541 } else if (sel & WPA_CIPHER_BIP_GMAC_128) {
1542 wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128;
1543 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1544 "BIP-GMAC-128");
1545 } else if (sel & WPA_CIPHER_BIP_GMAC_256) {
1546 wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256;
1547 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1548 "BIP-GMAC-256");
1549 } else if (sel & WPA_CIPHER_BIP_CMAC_256) {
1550 wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256;
1551 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1552 "BIP-CMAC-256");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001553 } else {
1554 wpa_s->mgmt_group_cipher = 0;
1555 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
1556 }
1557 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
1558 wpa_s->mgmt_group_cipher);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001559 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001560 wpas_get_ssid_pmf(wpa_s, ssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561#endif /* CONFIG_IEEE80211W */
Hai Shalom74f70d42019-02-11 14:42:39 -08001562#ifdef CONFIG_OCV
1563 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, ssid->ocv);
1564#endif /* CONFIG_OCV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565
1566 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
1567 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to generate WPA IE");
1568 return -1;
1569 }
1570
Hai Shalom021b0b52019-04-10 11:17:58 -07001571 if (0) {
1572#ifdef CONFIG_DPP
1573 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) {
1574 /* Use PMK from DPP network introduction (PMKSA entry) */
1575 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
1576#endif /* CONFIG_DPP */
1577 } else if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001578 int psk_set = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001579 int sae_only;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001580
Roshan Pius3a1667e2018-07-03 15:17:14 -07001581 sae_only = (ssid->key_mgmt & (WPA_KEY_MGMT_PSK |
1582 WPA_KEY_MGMT_FT_PSK |
1583 WPA_KEY_MGMT_PSK_SHA256)) == 0;
1584
1585 if (ssid->psk_set && !sae_only) {
1586 wpa_hexdump_key(MSG_MSGDUMP, "PSK (set in config)",
1587 ssid->psk, PMK_LEN);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001588 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL,
1589 NULL);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001590 psk_set = 1;
1591 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001592
Roshan Pius3a1667e2018-07-03 15:17:14 -07001593 if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
1594 (ssid->sae_password || ssid->passphrase))
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001595 psk_set = 1;
1596
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001597#ifndef CONFIG_NO_PBKDF2
1598 if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
Roshan Pius3a1667e2018-07-03 15:17:14 -07001599 ssid->passphrase && !sae_only) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001600 u8 psk[PMK_LEN];
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001601 pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len,
1602 4096, psk, PMK_LEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001603 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
1604 psk, PMK_LEN);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001605 wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL, NULL);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001606 psk_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001607 os_memset(psk, 0, sizeof(psk));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001608 }
1609#endif /* CONFIG_NO_PBKDF2 */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001610#ifdef CONFIG_EXT_PASSWORD
Roshan Pius3a1667e2018-07-03 15:17:14 -07001611 if (ssid->ext_psk && !sae_only) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001612 struct wpabuf *pw = ext_password_get(wpa_s->ext_pw,
1613 ssid->ext_psk);
1614 char pw_str[64 + 1];
1615 u8 psk[PMK_LEN];
1616
1617 if (pw == NULL) {
1618 wpa_msg(wpa_s, MSG_INFO, "EXT PW: No PSK "
1619 "found from external storage");
1620 return -1;
1621 }
1622
1623 if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) {
1624 wpa_msg(wpa_s, MSG_INFO, "EXT PW: Unexpected "
1625 "PSK length %d in external storage",
1626 (int) wpabuf_len(pw));
1627 ext_password_free(pw);
1628 return -1;
1629 }
1630
1631 os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw));
1632 pw_str[wpabuf_len(pw)] = '\0';
1633
1634#ifndef CONFIG_NO_PBKDF2
1635 if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
1636 {
1637 pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len,
1638 4096, psk, PMK_LEN);
1639 os_memset(pw_str, 0, sizeof(pw_str));
1640 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from "
1641 "external passphrase)",
1642 psk, PMK_LEN);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001643 wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL,
1644 NULL);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001645 psk_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001646 os_memset(psk, 0, sizeof(psk));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001647 } else
1648#endif /* CONFIG_NO_PBKDF2 */
1649 if (wpabuf_len(pw) == 2 * PMK_LEN) {
1650 if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) {
1651 wpa_msg(wpa_s, MSG_INFO, "EXT PW: "
1652 "Invalid PSK hex string");
1653 os_memset(pw_str, 0, sizeof(pw_str));
1654 ext_password_free(pw);
1655 return -1;
1656 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001657 wpa_hexdump_key(MSG_MSGDUMP,
1658 "PSK (from external PSK)",
1659 psk, PMK_LEN);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001660 wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL,
1661 NULL);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001662 psk_set = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001663 os_memset(psk, 0, sizeof(psk));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001664 } else {
1665 wpa_msg(wpa_s, MSG_INFO, "EXT PW: No suitable "
1666 "PSK available");
1667 os_memset(pw_str, 0, sizeof(pw_str));
1668 ext_password_free(pw);
1669 return -1;
1670 }
1671
1672 os_memset(pw_str, 0, sizeof(pw_str));
1673 ext_password_free(pw);
1674 }
1675#endif /* CONFIG_EXT_PASSWORD */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001676
1677 if (!psk_set) {
1678 wpa_msg(wpa_s, MSG_INFO,
1679 "No PSK available for association");
Roshan Pius3a1667e2018-07-03 15:17:14 -07001680 wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE");
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001681 return -1;
1682 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001683#ifdef CONFIG_OWE
1684 } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) {
1685 /* OWE Diffie-Hellman exchange in (Re)Association
1686 * Request/Response frames set the PMK, so do not override it
1687 * here. */
1688#endif /* CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001689 } else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
1691
1692 return 0;
1693}
1694
1695
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001696static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx)
1697{
1698 *pos = 0x00;
1699
1700 switch (idx) {
1701 case 0: /* Bits 0-7 */
1702 break;
1703 case 1: /* Bits 8-15 */
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001704 if (wpa_s->conf->coloc_intf_reporting) {
1705 /* Bit 13 - Collocated Interference Reporting */
1706 *pos |= 0x20;
1707 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001708 break;
1709 case 2: /* Bits 16-23 */
1710#ifdef CONFIG_WNM
1711 *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
1712 *pos |= 0x08; /* Bit 19 - BSS Transition */
1713#endif /* CONFIG_WNM */
1714 break;
1715 case 3: /* Bits 24-31 */
1716#ifdef CONFIG_WNM
1717 *pos |= 0x02; /* Bit 25 - SSID List */
1718#endif /* CONFIG_WNM */
1719#ifdef CONFIG_INTERWORKING
1720 if (wpa_s->conf->interworking)
1721 *pos |= 0x80; /* Bit 31 - Interworking */
1722#endif /* CONFIG_INTERWORKING */
1723 break;
1724 case 4: /* Bits 32-39 */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001725#ifdef CONFIG_INTERWORKING
Hai Shalomce48b4a2018-09-05 11:41:35 -07001726 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_QOS_MAPPING)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001727 *pos |= 0x01; /* Bit 32 - QoS Map */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001728#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001729 break;
1730 case 5: /* Bits 40-47 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001731#ifdef CONFIG_HS20
1732 if (wpa_s->conf->hs20)
1733 *pos |= 0x40; /* Bit 46 - WNM-Notification */
1734#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001735#ifdef CONFIG_MBO
1736 *pos |= 0x40; /* Bit 46 - WNM-Notification */
1737#endif /* CONFIG_MBO */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001738 break;
1739 case 6: /* Bits 48-55 */
1740 break;
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001741 case 7: /* Bits 56-63 */
1742 break;
1743 case 8: /* Bits 64-71 */
1744 if (wpa_s->conf->ftm_responder)
1745 *pos |= 0x40; /* Bit 70 - FTM responder */
1746 if (wpa_s->conf->ftm_initiator)
1747 *pos |= 0x80; /* Bit 71 - FTM initiator */
1748 break;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001749 case 9: /* Bits 72-79 */
1750#ifdef CONFIG_FILS
Roshan Pius3a1667e2018-07-03 15:17:14 -07001751 if (!wpa_s->disable_fils)
1752 *pos |= 0x01;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001753#endif /* CONFIG_FILS */
1754 break;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001755 }
1756}
1757
1758
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001759int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf, size_t buflen)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001760{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001761 u8 *pos = buf;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001762 u8 len = 10, i;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001763
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001764 if (len < wpa_s->extended_capa_len)
1765 len = wpa_s->extended_capa_len;
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001766 if (buflen < (size_t) len + 2) {
1767 wpa_printf(MSG_INFO,
1768 "Not enough room for building extended capabilities element");
1769 return -1;
1770 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001771
1772 *pos++ = WLAN_EID_EXT_CAPAB;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001773 *pos++ = len;
1774 for (i = 0; i < len; i++, pos++) {
1775 wpas_ext_capab_byte(wpa_s, pos, i);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001776
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001777 if (i < wpa_s->extended_capa_len) {
1778 *pos &= ~wpa_s->extended_capa_mask[i];
1779 *pos |= wpa_s->extended_capa[i];
1780 }
1781 }
1782
1783 while (len > 0 && buf[1 + len] == 0) {
1784 len--;
1785 buf[1] = len;
1786 }
1787 if (len == 0)
1788 return 0;
1789
1790 return 2 + len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001791}
1792
1793
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001794static int wpas_valid_bss(struct wpa_supplicant *wpa_s,
1795 struct wpa_bss *test_bss)
1796{
1797 struct wpa_bss *bss;
1798
1799 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1800 if (bss == test_bss)
1801 return 1;
1802 }
1803
1804 return 0;
1805}
1806
1807
1808static int wpas_valid_ssid(struct wpa_supplicant *wpa_s,
1809 struct wpa_ssid *test_ssid)
1810{
1811 struct wpa_ssid *ssid;
1812
1813 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1814 if (ssid == test_ssid)
1815 return 1;
1816 }
1817
1818 return 0;
1819}
1820
1821
1822int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss,
1823 struct wpa_ssid *test_ssid)
1824{
1825 if (test_bss && !wpas_valid_bss(wpa_s, test_bss))
1826 return 0;
1827
1828 return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid);
1829}
1830
1831
1832void wpas_connect_work_free(struct wpa_connect_work *cwork)
1833{
1834 if (cwork == NULL)
1835 return;
1836 os_free(cwork);
1837}
1838
1839
1840void wpas_connect_work_done(struct wpa_supplicant *wpa_s)
1841{
1842 struct wpa_connect_work *cwork;
1843 struct wpa_radio_work *work = wpa_s->connect_work;
1844
1845 if (!work)
1846 return;
1847
1848 wpa_s->connect_work = NULL;
1849 cwork = work->ctx;
1850 work->ctx = NULL;
1851 wpas_connect_work_free(cwork);
1852 radio_work_done(work);
1853}
1854
1855
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001856int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style)
1857{
1858 struct os_reltime now;
1859 u8 addr[ETH_ALEN];
1860
1861 os_get_reltime(&now);
1862 if (wpa_s->last_mac_addr_style == style &&
1863 wpa_s->last_mac_addr_change.sec != 0 &&
1864 !os_reltime_expired(&now, &wpa_s->last_mac_addr_change,
1865 wpa_s->conf->rand_addr_lifetime)) {
1866 wpa_msg(wpa_s, MSG_DEBUG,
1867 "Previously selected random MAC address has not yet expired");
1868 return 0;
1869 }
1870
1871 switch (style) {
1872 case 1:
1873 if (random_mac_addr(addr) < 0)
1874 return -1;
1875 break;
1876 case 2:
1877 os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN);
1878 if (random_mac_addr_keep_oui(addr) < 0)
1879 return -1;
1880 break;
1881 default:
1882 return -1;
1883 }
1884
1885 if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) {
1886 wpa_msg(wpa_s, MSG_INFO,
1887 "Failed to set random MAC address");
1888 return -1;
1889 }
1890
1891 os_get_reltime(&wpa_s->last_mac_addr_change);
1892 wpa_s->mac_addr_changed = 1;
1893 wpa_s->last_mac_addr_style = style;
1894
1895 if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
1896 wpa_msg(wpa_s, MSG_INFO,
1897 "Could not update MAC address information");
1898 return -1;
1899 }
1900
1901 wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR,
1902 MAC2STR(addr));
1903
1904 return 0;
1905}
1906
1907
1908int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s)
1909{
1910 if (wpa_s->wpa_state >= WPA_AUTHENTICATING ||
1911 !wpa_s->conf->preassoc_mac_addr)
1912 return 0;
1913
1914 return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr);
1915}
1916
1917
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001918static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit);
1919
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001920/**
1921 * wpa_supplicant_associate - Request association
1922 * @wpa_s: Pointer to wpa_supplicant data
1923 * @bss: Scan results for the selected BSS, or %NULL if not available
1924 * @ssid: Configuration data for the selected network
1925 *
1926 * This function is used to request %wpa_supplicant to associate with a BSS.
1927 */
1928void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
1929 struct wpa_bss *bss, struct wpa_ssid *ssid)
1930{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001931 struct wpa_connect_work *cwork;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001932 int rand_style;
1933
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001934 wpa_s->own_disconnect_req = 0;
1935
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001936 /*
1937 * If we are starting a new connection, any previously pending EAPOL
1938 * RX cannot be valid anymore.
1939 */
1940 wpabuf_free(wpa_s->pending_eapol_rx);
1941 wpa_s->pending_eapol_rx = NULL;
1942
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001943 if (ssid->mac_addr == -1)
1944 rand_style = wpa_s->conf->mac_addr;
1945 else
1946 rand_style = ssid->mac_addr;
1947
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001948 wmm_ac_clear_saved_tspecs(wpa_s);
1949 wpa_s->reassoc_same_bss = 0;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001950 wpa_s->reassoc_same_ess = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001951#ifdef CONFIG_TESTING_OPTIONS
1952 wpa_s->testing_resend_assoc = 0;
1953#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001954
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001955 if (wpa_s->last_ssid == ssid) {
1956 wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS");
Dmitry Shmidte4663042016-04-04 10:07:49 -07001957 wpa_s->reassoc_same_ess = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001958 if (wpa_s->current_bss && wpa_s->current_bss == bss) {
1959 wmm_ac_save_tspecs(wpa_s);
1960 wpa_s->reassoc_same_bss = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08001961 } else if (wpa_s->current_bss && wpa_s->current_bss != bss) {
1962 os_get_reltime(&wpa_s->roam_start);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001963 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001964 }
1965
1966 if (rand_style > 0 && !wpa_s->reassoc_same_ess) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001967 if (wpas_update_random_addr(wpa_s, rand_style) < 0)
1968 return;
1969 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001970 } else if (rand_style == 0 && wpa_s->mac_addr_changed) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001971 if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) {
1972 wpa_msg(wpa_s, MSG_INFO,
1973 "Could not restore permanent MAC address");
1974 return;
1975 }
1976 wpa_s->mac_addr_changed = 0;
1977 if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
1978 wpa_msg(wpa_s, MSG_INFO,
1979 "Could not update MAC address information");
1980 return;
1981 }
1982 wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address");
1983 }
1984 wpa_s->last_ssid = ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001985
1986#ifdef CONFIG_IBSS_RSN
1987 ibss_rsn_deinit(wpa_s->ibss_rsn);
1988 wpa_s->ibss_rsn = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001989#else /* CONFIG_IBSS_RSN */
1990 if (ssid->mode == WPAS_MODE_IBSS &&
1991 !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1992 wpa_msg(wpa_s, MSG_INFO,
1993 "IBSS RSN not supported in the build");
1994 return;
1995 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001996#endif /* CONFIG_IBSS_RSN */
1997
1998 if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO ||
1999 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
2000#ifdef CONFIG_AP
2001 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
2002 wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP "
2003 "mode");
2004 return;
2005 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002006 if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) {
2007 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002008 if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
2009 wpas_p2p_ap_setup_failed(wpa_s);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002010 return;
2011 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 wpa_s->current_bss = bss;
2013#else /* CONFIG_AP */
2014 wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in "
2015 "the build");
2016#endif /* CONFIG_AP */
2017 return;
2018 }
2019
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002020 if (ssid->mode == WPAS_MODE_MESH) {
2021#ifdef CONFIG_MESH
2022 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) {
2023 wpa_msg(wpa_s, MSG_INFO,
2024 "Driver does not support mesh mode");
2025 return;
2026 }
2027 if (bss)
2028 ssid->frequency = bss->freq;
2029 if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) {
2030 wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh");
2031 return;
2032 }
2033 wpa_s->current_bss = bss;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08002034 wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_STARTED "ssid=\"%s\" id=%d",
2035 wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
2036 ssid->id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002037 wpas_notify_mesh_group_started(wpa_s, ssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002038#else /* CONFIG_MESH */
2039 wpa_msg(wpa_s, MSG_ERROR,
2040 "mesh mode support not included in the build");
2041#endif /* CONFIG_MESH */
2042 return;
2043 }
2044
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002045 /*
2046 * Set WPA state machine configuration to match the selected network now
2047 * so that the information is available before wpas_start_assoc_cb()
2048 * gets called. This is needed at least for RSN pre-authentication where
2049 * candidate APs are added to a list based on scan result processing
2050 * before completion of the first association.
2051 */
2052 wpa_supplicant_rsn_supp_set_config(wpa_s, ssid);
2053
2054#ifdef CONFIG_DPP
2055 if (wpas_dpp_check_connect(wpa_s, ssid, bss) != 0)
2056 return;
2057#endif /* CONFIG_DPP */
2058
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002059#ifdef CONFIG_TDLS
2060 if (bss)
2061 wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1),
2062 bss->ie_len);
2063#endif /* CONFIG_TDLS */
2064
2065 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2066 ssid->mode == IEEE80211_MODE_INFRA) {
2067 sme_authenticate(wpa_s, bss, ssid);
2068 return;
2069 }
2070
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002071 if (wpa_s->connect_work) {
2072 wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist");
2073 return;
2074 }
2075
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002076 if (radio_work_pending(wpa_s, "connect")) {
2077 wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist");
2078 return;
2079 }
2080
Dmitry Shmidt29333592017-01-09 12:27:11 -08002081#ifdef CONFIG_SME
2082 if (ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) {
2083 /* Clear possibly set auth_alg, if any, from last attempt. */
2084 wpa_s->sme.auth_alg = WPA_AUTH_ALG_OPEN;
2085 }
2086#endif /* CONFIG_SME */
2087
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002088 wpas_abort_ongoing_scan(wpa_s);
2089
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002090 cwork = os_zalloc(sizeof(*cwork));
2091 if (cwork == NULL)
2092 return;
2093
2094 cwork->bss = bss;
2095 cwork->ssid = ssid;
2096
2097 if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1,
2098 wpas_start_assoc_cb, cwork) < 0) {
2099 os_free(cwork);
2100 }
2101}
2102
2103
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002104static int bss_is_ibss(struct wpa_bss *bss)
2105{
2106 return (bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
2107 IEEE80211_CAP_IBSS;
2108}
2109
2110
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002111static int drv_supports_vht(struct wpa_supplicant *wpa_s,
2112 const struct wpa_ssid *ssid)
2113{
2114 enum hostapd_hw_mode hw_mode;
2115 struct hostapd_hw_modes *mode = NULL;
2116 u8 channel;
2117 int i;
2118
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002119 hw_mode = ieee80211_freq_to_chan(ssid->frequency, &channel);
2120 if (hw_mode == NUM_HOSTAPD_MODES)
2121 return 0;
2122 for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) {
2123 if (wpa_s->hw.modes[i].mode == hw_mode) {
2124 mode = &wpa_s->hw.modes[i];
2125 break;
2126 }
2127 }
2128
2129 if (!mode)
2130 return 0;
2131
2132 return mode->vht_capab != 0;
2133}
2134
2135
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002136void ibss_mesh_setup_freq(struct wpa_supplicant *wpa_s,
2137 const struct wpa_ssid *ssid,
2138 struct hostapd_freq_params *freq)
2139{
2140 enum hostapd_hw_mode hw_mode;
2141 struct hostapd_hw_modes *mode = NULL;
2142 int ht40plus[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
2143 184, 192 };
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002144 int vht80[] = { 36, 52, 100, 116, 132, 149 };
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002145 struct hostapd_channel_data *pri_chan = NULL, *sec_chan = NULL;
2146 u8 channel;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002147 int i, chan_idx, ht40 = -1, res, obss_scan = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002148 unsigned int j, k;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002149 struct hostapd_freq_params vht_freq;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002150 int chwidth, seg0, seg1;
2151 u32 vht_caps = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002152
2153 freq->freq = ssid->frequency;
2154
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002155 for (j = 0; j < wpa_s->last_scan_res_used; j++) {
2156 struct wpa_bss *bss = wpa_s->last_scan_res[j];
2157
2158 if (ssid->mode != WPAS_MODE_IBSS)
2159 break;
2160
2161 /* Don't adjust control freq in case of fixed_freq */
2162 if (ssid->fixed_freq)
2163 break;
2164
2165 if (!bss_is_ibss(bss))
2166 continue;
2167
2168 if (ssid->ssid_len == bss->ssid_len &&
2169 os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) == 0) {
2170 wpa_printf(MSG_DEBUG,
2171 "IBSS already found in scan results, adjust control freq: %d",
2172 bss->freq);
2173 freq->freq = bss->freq;
2174 obss_scan = 0;
2175 break;
2176 }
2177 }
2178
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002179 /* For IBSS check HT_IBSS flag */
2180 if (ssid->mode == WPAS_MODE_IBSS &&
2181 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_HT_IBSS))
2182 return;
2183
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002184 if (wpa_s->group_cipher == WPA_CIPHER_WEP40 ||
2185 wpa_s->group_cipher == WPA_CIPHER_WEP104 ||
2186 wpa_s->pairwise_cipher == WPA_CIPHER_TKIP) {
2187 wpa_printf(MSG_DEBUG,
2188 "IBSS: WEP/TKIP detected, do not try to enable HT");
2189 return;
2190 }
2191
2192 hw_mode = ieee80211_freq_to_chan(freq->freq, &channel);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002193 for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) {
2194 if (wpa_s->hw.modes[i].mode == hw_mode) {
2195 mode = &wpa_s->hw.modes[i];
2196 break;
2197 }
2198 }
2199
2200 if (!mode)
2201 return;
2202
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07002203#ifdef CONFIG_HT_OVERRIDES
2204 if (ssid->disable_ht) {
2205 freq->ht_enabled = 0;
2206 return;
2207 }
2208#endif /* CONFIG_HT_OVERRIDES */
2209
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002210 freq->ht_enabled = ht_supported(mode);
2211 if (!freq->ht_enabled)
2212 return;
2213
2214 /* Setup higher BW only for 5 GHz */
2215 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
2216 return;
2217
2218 for (chan_idx = 0; chan_idx < mode->num_channels; chan_idx++) {
2219 pri_chan = &mode->channels[chan_idx];
2220 if (pri_chan->chan == channel)
2221 break;
2222 pri_chan = NULL;
2223 }
2224 if (!pri_chan)
2225 return;
2226
2227 /* Check primary channel flags */
2228 if (pri_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
2229 return;
2230
Hai Shalom74f70d42019-02-11 14:42:39 -08002231 freq->channel = pri_chan->chan;
2232
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002233#ifdef CONFIG_HT_OVERRIDES
Hai Shalom74f70d42019-02-11 14:42:39 -08002234 if (ssid->disable_ht40) {
2235 if (ssid->disable_vht)
2236 return;
2237 goto skip_ht40;
2238 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002239#endif /* CONFIG_HT_OVERRIDES */
2240
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002241 /* Check/setup HT40+/HT40- */
2242 for (j = 0; j < ARRAY_SIZE(ht40plus); j++) {
2243 if (ht40plus[j] == channel) {
2244 ht40 = 1;
2245 break;
2246 }
2247 }
2248
2249 /* Find secondary channel */
2250 for (i = 0; i < mode->num_channels; i++) {
2251 sec_chan = &mode->channels[i];
2252 if (sec_chan->chan == channel + ht40 * 4)
2253 break;
2254 sec_chan = NULL;
2255 }
2256 if (!sec_chan)
2257 return;
2258
2259 /* Check secondary channel flags */
2260 if (sec_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
2261 return;
2262
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002263 if (ht40 == -1) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002264 if (!(pri_chan->flag & HOSTAPD_CHAN_HT40MINUS))
2265 return;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002266 } else {
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002267 if (!(pri_chan->flag & HOSTAPD_CHAN_HT40PLUS))
2268 return;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002269 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002270 freq->sec_channel_offset = ht40;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002271
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07002272 if (obss_scan) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002273 struct wpa_scan_results *scan_res;
2274
2275 scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0);
2276 if (scan_res == NULL) {
2277 /* Back to HT20 */
2278 freq->sec_channel_offset = 0;
2279 return;
2280 }
2281
2282 res = check_40mhz_5g(mode, scan_res, pri_chan->chan,
2283 sec_chan->chan);
2284 switch (res) {
2285 case 0:
2286 /* Back to HT20 */
2287 freq->sec_channel_offset = 0;
2288 break;
2289 case 1:
2290 /* Configuration allowed */
2291 break;
2292 case 2:
2293 /* Switch pri/sec channels */
2294 freq->freq = hw_get_freq(mode, sec_chan->chan);
2295 freq->sec_channel_offset = -freq->sec_channel_offset;
2296 freq->channel = sec_chan->chan;
2297 break;
2298 default:
2299 freq->sec_channel_offset = 0;
2300 break;
2301 }
2302
2303 wpa_scan_results_free(scan_res);
2304 }
2305
Hai Shalom74f70d42019-02-11 14:42:39 -08002306#ifdef CONFIG_HT_OVERRIDES
2307skip_ht40:
2308#endif /* CONFIG_HT_OVERRIDES */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002309 wpa_printf(MSG_DEBUG,
2310 "IBSS/mesh: setup freq channel %d, sec_channel_offset %d",
2311 freq->channel, freq->sec_channel_offset);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002312
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002313 if (!drv_supports_vht(wpa_s, ssid))
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002314 return;
2315
2316 /* For IBSS check VHT_IBSS flag */
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002317 if (ssid->mode == WPAS_MODE_IBSS &&
2318 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_VHT_IBSS))
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002319 return;
2320
2321 vht_freq = *freq;
2322
Paul Stewart092955c2017-02-06 09:13:09 -08002323#ifdef CONFIG_VHT_OVERRIDES
2324 if (ssid->disable_vht) {
2325 freq->vht_enabled = 0;
2326 return;
2327 }
2328#endif /* CONFIG_VHT_OVERRIDES */
2329
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002330 vht_freq.vht_enabled = vht_supported(mode);
2331 if (!vht_freq.vht_enabled)
2332 return;
2333
2334 /* setup center_freq1, bandwidth */
2335 for (j = 0; j < ARRAY_SIZE(vht80); j++) {
2336 if (freq->channel >= vht80[j] &&
2337 freq->channel < vht80[j] + 16)
2338 break;
2339 }
2340
2341 if (j == ARRAY_SIZE(vht80))
2342 return;
2343
2344 for (i = vht80[j]; i < vht80[j] + 16; i += 4) {
2345 struct hostapd_channel_data *chan;
2346
2347 chan = hw_get_channel_chan(mode, i, NULL);
2348 if (!chan)
2349 return;
2350
2351 /* Back to HT configuration if channel not usable */
2352 if (chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
2353 return;
2354 }
2355
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002356 chwidth = VHT_CHANWIDTH_80MHZ;
2357 seg0 = vht80[j] + 6;
2358 seg1 = 0;
2359
2360 if (ssid->max_oper_chwidth == VHT_CHANWIDTH_80P80MHZ) {
2361 /* setup center_freq2, bandwidth */
2362 for (k = 0; k < ARRAY_SIZE(vht80); k++) {
2363 /* Only accept 80 MHz segments separated by a gap */
2364 if (j == k || abs(vht80[j] - vht80[k]) == 16)
2365 continue;
2366 for (i = vht80[k]; i < vht80[k] + 16; i += 4) {
2367 struct hostapd_channel_data *chan;
2368
2369 chan = hw_get_channel_chan(mode, i, NULL);
2370 if (!chan)
2371 continue;
2372
2373 if (chan->flag & (HOSTAPD_CHAN_DISABLED |
2374 HOSTAPD_CHAN_NO_IR |
2375 HOSTAPD_CHAN_RADAR))
2376 continue;
2377
2378 /* Found a suitable second segment for 80+80 */
2379 chwidth = VHT_CHANWIDTH_80P80MHZ;
2380 vht_caps |=
2381 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
2382 seg1 = vht80[k] + 6;
2383 }
2384
2385 if (chwidth == VHT_CHANWIDTH_80P80MHZ)
2386 break;
2387 }
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002388 } else if (ssid->max_oper_chwidth == VHT_CHANWIDTH_160MHZ) {
2389 if (freq->freq == 5180) {
2390 chwidth = VHT_CHANWIDTH_160MHZ;
2391 vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
2392 seg0 = 50;
2393 } else if (freq->freq == 5520) {
2394 chwidth = VHT_CHANWIDTH_160MHZ;
2395 vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
2396 seg0 = 114;
2397 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002398 } else if (ssid->max_oper_chwidth == VHT_CHANWIDTH_USE_HT) {
2399 chwidth = VHT_CHANWIDTH_USE_HT;
2400 seg0 = vht80[j] + 2;
2401#ifdef CONFIG_HT_OVERRIDES
2402 if (ssid->disable_ht40)
2403 seg0 = 0;
2404#endif /* CONFIG_HT_OVERRIDES */
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002405 }
2406
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002407 if (hostapd_set_freq_params(&vht_freq, mode->mode, freq->freq,
2408 freq->channel, freq->ht_enabled,
2409 vht_freq.vht_enabled,
2410 freq->sec_channel_offset,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002411 chwidth, seg0, seg1, vht_caps) != 0)
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002412 return;
2413
2414 *freq = vht_freq;
2415
2416 wpa_printf(MSG_DEBUG, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d",
2417 freq->center_freq1, freq->center_freq2, freq->bandwidth);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002418}
2419
2420
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002421#ifdef CONFIG_FILS
2422static size_t wpas_add_fils_hlp_req(struct wpa_supplicant *wpa_s, u8 *ie_buf,
2423 size_t ie_buf_len)
2424{
2425 struct fils_hlp_req *req;
2426 size_t rem_len, hdr_len, hlp_len, len, ie_len = 0;
2427 const u8 *pos;
2428 u8 *buf = ie_buf;
2429
2430 dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req,
2431 list) {
2432 rem_len = ie_buf_len - ie_len;
2433 pos = wpabuf_head(req->pkt);
2434 hdr_len = 1 + 2 * ETH_ALEN + 6;
2435 hlp_len = wpabuf_len(req->pkt);
2436
2437 if (rem_len < 2 + hdr_len + hlp_len) {
2438 wpa_printf(MSG_ERROR,
2439 "FILS: Cannot fit HLP - rem_len=%lu to_fill=%lu",
2440 (unsigned long) rem_len,
2441 (unsigned long) (2 + hdr_len + hlp_len));
2442 break;
2443 }
2444
2445 len = (hdr_len + hlp_len) > 255 ? 255 : hdr_len + hlp_len;
2446 /* Element ID */
2447 *buf++ = WLAN_EID_EXTENSION;
2448 /* Length */
2449 *buf++ = len;
2450 /* Element ID Extension */
2451 *buf++ = WLAN_EID_EXT_FILS_HLP_CONTAINER;
2452 /* Destination MAC address */
2453 os_memcpy(buf, req->dst, ETH_ALEN);
2454 buf += ETH_ALEN;
2455 /* Source MAC address */
2456 os_memcpy(buf, wpa_s->own_addr, ETH_ALEN);
2457 buf += ETH_ALEN;
2458 /* LLC/SNAP Header */
2459 os_memcpy(buf, "\xaa\xaa\x03\x00\x00\x00", 6);
2460 buf += 6;
2461 /* HLP Packet */
2462 os_memcpy(buf, pos, len - hdr_len);
2463 buf += len - hdr_len;
2464 pos += len - hdr_len;
2465
2466 hlp_len -= len - hdr_len;
2467 ie_len += 2 + len;
2468 rem_len -= 2 + len;
2469
2470 while (hlp_len) {
2471 len = (hlp_len > 255) ? 255 : hlp_len;
2472 if (rem_len < 2 + len)
2473 break;
2474 *buf++ = WLAN_EID_FRAGMENT;
2475 *buf++ = len;
2476 os_memcpy(buf, pos, len);
2477 buf += len;
2478 pos += len;
2479
2480 hlp_len -= len;
2481 ie_len += 2 + len;
2482 rem_len -= 2 + len;
2483 }
2484 }
2485
2486 return ie_len;
2487}
Roshan Pius3a1667e2018-07-03 15:17:14 -07002488
2489
2490int wpa_is_fils_supported(struct wpa_supplicant *wpa_s)
2491{
2492 return (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2493 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) ||
2494 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2495 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)));
2496}
2497
2498
2499int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant *wpa_s)
2500{
2501#ifdef CONFIG_FILS_SK_PFS
2502 return (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2503 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS);
2504#else /* CONFIG_FILS_SK_PFS */
2505 return 0;
2506#endif /* CONFIG_FILS_SK_PFS */
2507}
2508
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002509#endif /* CONFIG_FILS */
2510
2511
2512static u8 * wpas_populate_assoc_ies(
2513 struct wpa_supplicant *wpa_s,
2514 struct wpa_bss *bss, struct wpa_ssid *ssid,
2515 struct wpa_driver_associate_params *params,
2516 enum wpa_drv_update_connect_params_mask *mask)
2517{
2518 u8 *wpa_ie;
2519 size_t max_wpa_ie_len = 500;
2520 size_t wpa_ie_len;
2521 int algs = WPA_AUTH_ALG_OPEN;
Hai Shalomce48b4a2018-09-05 11:41:35 -07002522#ifdef CONFIG_MBO
2523 const u8 *mbo_ie;
2524#endif
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002525#ifdef CONFIG_FILS
2526 const u8 *realm, *username, *rrk;
2527 size_t realm_len, username_len, rrk_len;
2528 u16 next_seq_num;
2529 struct fils_hlp_req *req;
2530
2531 dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req,
2532 list) {
2533 max_wpa_ie_len += 3 + 2 * ETH_ALEN + 6 + wpabuf_len(req->pkt) +
2534 2 + 2 * wpabuf_len(req->pkt) / 255;
2535 }
2536#endif /* CONFIG_FILS */
2537
2538 wpa_ie = os_malloc(max_wpa_ie_len);
2539 if (!wpa_ie) {
2540 wpa_printf(MSG_ERROR,
2541 "Failed to allocate connect IE buffer for %lu bytes",
2542 (unsigned long) max_wpa_ie_len);
2543 return NULL;
2544 }
2545
2546 if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
2547 wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
2548 wpa_key_mgmt_wpa(ssid->key_mgmt)) {
2549 int try_opportunistic;
2550 const u8 *cache_id = NULL;
2551
2552 try_opportunistic = (ssid->proactive_key_caching < 0 ?
2553 wpa_s->conf->okc :
2554 ssid->proactive_key_caching) &&
2555 (ssid->proto & WPA_PROTO_RSN);
2556#ifdef CONFIG_FILS
2557 if (wpa_key_mgmt_fils(ssid->key_mgmt))
2558 cache_id = wpa_bss_get_fils_cache_id(bss);
2559#endif /* CONFIG_FILS */
2560 if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
2561 ssid, try_opportunistic,
Roshan Pius3a1667e2018-07-03 15:17:14 -07002562 cache_id, 0) == 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002563 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
2564 wpa_ie_len = max_wpa_ie_len;
2565 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
2566 wpa_ie, &wpa_ie_len)) {
2567 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
2568 "key management and encryption suites");
2569 os_free(wpa_ie);
2570 return NULL;
2571 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002572#ifdef CONFIG_HS20
2573 } else if (bss && wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE) &&
2574 (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)) {
2575 /* No PMKSA caching, but otherwise similar to RSN/WPA */
2576 wpa_ie_len = max_wpa_ie_len;
2577 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
2578 wpa_ie, &wpa_ie_len)) {
2579 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
2580 "key management and encryption suites");
2581 os_free(wpa_ie);
2582 return NULL;
2583 }
2584#endif /* CONFIG_HS20 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002585 } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss &&
2586 wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) {
2587 /*
2588 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
2589 * use non-WPA since the scan results did not indicate that the
2590 * AP is using WPA or WPA2.
2591 */
2592 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
2593 wpa_ie_len = 0;
2594 wpa_s->wpa_proto = 0;
2595 } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
2596 wpa_ie_len = max_wpa_ie_len;
2597 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
2598 wpa_ie, &wpa_ie_len)) {
2599 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
2600 "key management and encryption suites (no "
2601 "scan results)");
2602 os_free(wpa_ie);
2603 return NULL;
2604 }
2605#ifdef CONFIG_WPS
2606 } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
2607 struct wpabuf *wps_ie;
2608 wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
2609 if (wps_ie && wpabuf_len(wps_ie) <= max_wpa_ie_len) {
2610 wpa_ie_len = wpabuf_len(wps_ie);
2611 os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len);
2612 } else
2613 wpa_ie_len = 0;
2614 wpabuf_free(wps_ie);
2615 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
2616 if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY))
2617 params->wps = WPS_MODE_PRIVACY;
2618 else
2619 params->wps = WPS_MODE_OPEN;
2620 wpa_s->wpa_proto = 0;
2621#endif /* CONFIG_WPS */
2622 } else {
2623 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
2624 wpa_ie_len = 0;
2625 wpa_s->wpa_proto = 0;
2626 }
2627
2628#ifdef IEEE8021X_EAPOL
2629 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2630 if (ssid->leap) {
2631 if (ssid->non_leap == 0)
2632 algs = WPA_AUTH_ALG_LEAP;
2633 else
2634 algs |= WPA_AUTH_ALG_LEAP;
2635 }
2636 }
2637
2638#ifdef CONFIG_FILS
2639 /* Clear FILS association */
2640 wpa_sm_set_reset_fils_completed(wpa_s->wpa, 0);
2641
2642 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) &&
2643 ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) &&
2644 eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, &username,
2645 &username_len, &realm, &realm_len,
Hai Shalomce48b4a2018-09-05 11:41:35 -07002646 &next_seq_num, &rrk, &rrk_len) == 0 &&
2647 (!wpa_s->last_con_fail_realm ||
2648 wpa_s->last_con_fail_realm_len != realm_len ||
2649 os_memcmp(wpa_s->last_con_fail_realm, realm, realm_len) != 0)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002650 algs = WPA_AUTH_ALG_FILS;
2651 params->fils_erp_username = username;
2652 params->fils_erp_username_len = username_len;
2653 params->fils_erp_realm = realm;
2654 params->fils_erp_realm_len = realm_len;
2655 params->fils_erp_next_seq_num = next_seq_num;
2656 params->fils_erp_rrk = rrk;
2657 params->fils_erp_rrk_len = rrk_len;
2658
2659 if (mask)
2660 *mask |= WPA_DRV_UPDATE_FILS_ERP_INFO;
2661 }
2662#endif /* CONFIG_FILS */
2663#endif /* IEEE8021X_EAPOL */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002664#ifdef CONFIG_SAE
2665 if (wpa_s->key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE))
2666 algs = WPA_AUTH_ALG_SAE;
2667#endif /* CONFIG_SAE */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002668
2669 wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
2670 if (ssid->auth_alg) {
2671 algs = ssid->auth_alg;
2672 wpa_dbg(wpa_s, MSG_DEBUG,
2673 "Overriding auth_alg selection: 0x%x", algs);
2674 }
2675
2676#ifdef CONFIG_P2P
2677 if (wpa_s->global->p2p) {
2678 u8 *pos;
2679 size_t len;
2680 int res;
2681 pos = wpa_ie + wpa_ie_len;
2682 len = max_wpa_ie_len - wpa_ie_len;
2683 res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len,
2684 ssid->p2p_group);
2685 if (res >= 0)
2686 wpa_ie_len += res;
2687 }
2688
2689 wpa_s->cross_connect_disallowed = 0;
2690 if (bss) {
2691 struct wpabuf *p2p;
2692 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
2693 if (p2p) {
2694 wpa_s->cross_connect_disallowed =
2695 p2p_get_cross_connect_disallowed(p2p);
2696 wpabuf_free(p2p);
2697 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross "
2698 "connection",
2699 wpa_s->cross_connect_disallowed ?
2700 "disallows" : "allows");
2701 }
2702 }
2703
2704 os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info));
2705#endif /* CONFIG_P2P */
2706
2707 if (bss) {
Hai Shalom74f70d42019-02-11 14:42:39 -08002708 wpa_ie_len += wpas_supp_op_class_ie(wpa_s, ssid, bss->freq,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002709 wpa_ie + wpa_ie_len,
2710 max_wpa_ie_len -
2711 wpa_ie_len);
2712 }
2713
2714 /*
2715 * Workaround: Add Extended Capabilities element only if the AP
2716 * included this element in Beacon/Probe Response frames. Some older
2717 * APs seem to have interoperability issues if this element is
2718 * included, so while the standard may require us to include the
2719 * element in all cases, it is justifiable to skip it to avoid
2720 * interoperability issues.
2721 */
2722 if (ssid->p2p_group)
2723 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT);
2724 else
2725 wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION);
2726
2727 if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) {
2728 u8 ext_capab[18];
2729 int ext_capab_len;
2730 ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab,
2731 sizeof(ext_capab));
2732 if (ext_capab_len > 0 &&
2733 wpa_ie_len + ext_capab_len <= max_wpa_ie_len) {
2734 u8 *pos = wpa_ie;
2735 if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN)
2736 pos += 2 + pos[1];
2737 os_memmove(pos + ext_capab_len, pos,
2738 wpa_ie_len - (pos - wpa_ie));
2739 wpa_ie_len += ext_capab_len;
2740 os_memcpy(pos, ext_capab, ext_capab_len);
2741 }
2742 }
2743
2744#ifdef CONFIG_HS20
2745 if (is_hs20_network(wpa_s, ssid, bss)) {
2746 struct wpabuf *hs20;
2747
Roshan Pius3a1667e2018-07-03 15:17:14 -07002748 hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002749 if (hs20) {
2750 int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid);
2751 size_t len;
2752
Hai Shalom74f70d42019-02-11 14:42:39 -08002753 wpas_hs20_add_indication(hs20, pps_mo_id,
2754 get_hs20_version(bss));
Roshan Pius3a1667e2018-07-03 15:17:14 -07002755 wpas_hs20_add_roam_cons_sel(hs20, ssid);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002756 len = max_wpa_ie_len - wpa_ie_len;
2757 if (wpabuf_len(hs20) <= len) {
2758 os_memcpy(wpa_ie + wpa_ie_len,
2759 wpabuf_head(hs20), wpabuf_len(hs20));
2760 wpa_ie_len += wpabuf_len(hs20);
2761 }
2762 wpabuf_free(hs20);
2763
2764 hs20_configure_frame_filters(wpa_s);
2765 }
2766 }
2767#endif /* CONFIG_HS20 */
2768
2769 if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) {
2770 struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ];
2771 size_t len;
2772
2773 len = max_wpa_ie_len - wpa_ie_len;
2774 if (wpabuf_len(buf) <= len) {
2775 os_memcpy(wpa_ie + wpa_ie_len,
2776 wpabuf_head(buf), wpabuf_len(buf));
2777 wpa_ie_len += wpabuf_len(buf);
2778 }
2779 }
2780
2781#ifdef CONFIG_FST
2782 if (wpa_s->fst_ies) {
2783 int fst_ies_len = wpabuf_len(wpa_s->fst_ies);
2784
2785 if (wpa_ie_len + fst_ies_len <= max_wpa_ie_len) {
2786 os_memcpy(wpa_ie + wpa_ie_len,
2787 wpabuf_head(wpa_s->fst_ies), fst_ies_len);
2788 wpa_ie_len += fst_ies_len;
2789 }
2790 }
2791#endif /* CONFIG_FST */
2792
2793#ifdef CONFIG_MBO
Hai Shalomce48b4a2018-09-05 11:41:35 -07002794 mbo_ie = bss ? wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE) : NULL;
2795 if (mbo_ie) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002796 int len;
2797
2798 len = wpas_mbo_ie(wpa_s, wpa_ie + wpa_ie_len,
Hai Shalomce48b4a2018-09-05 11:41:35 -07002799 max_wpa_ie_len - wpa_ie_len,
2800 !!mbo_attr_from_mbo_ie(mbo_ie,
2801 OCE_ATTR_ID_CAPA_IND));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002802 if (len >= 0)
2803 wpa_ie_len += len;
2804 }
2805#endif /* CONFIG_MBO */
2806
2807#ifdef CONFIG_FILS
2808 if (algs == WPA_AUTH_ALG_FILS) {
2809 size_t len;
2810
2811 len = wpas_add_fils_hlp_req(wpa_s, wpa_ie + wpa_ie_len,
2812 max_wpa_ie_len - wpa_ie_len);
2813 wpa_ie_len += len;
2814 }
2815#endif /* CONFIG_FILS */
2816
2817#ifdef CONFIG_OWE
Roshan Pius3a1667e2018-07-03 15:17:14 -07002818#ifdef CONFIG_TESTING_OPTIONS
2819 if (get_ie_ext(wpa_ie, wpa_ie_len, WLAN_EID_EXT_OWE_DH_PARAM)) {
2820 wpa_printf(MSG_INFO, "TESTING: Override OWE DH element");
2821 } else
2822#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002823 if (algs == WPA_AUTH_ALG_OPEN &&
2824 ssid->key_mgmt == WPA_KEY_MGMT_OWE) {
2825 struct wpabuf *owe_ie;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002826 u16 group;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002827
Roshan Pius3a1667e2018-07-03 15:17:14 -07002828 if (ssid->owe_group) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002829 group = ssid->owe_group;
Hai Shalom74f70d42019-02-11 14:42:39 -08002830 } else if (wpa_s->assoc_status_code ==
2831 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002832 if (wpa_s->last_owe_group == 19)
2833 group = 20;
2834 else if (wpa_s->last_owe_group == 20)
2835 group = 21;
2836 else
2837 group = OWE_DH_GROUP;
Hai Shalom74f70d42019-02-11 14:42:39 -08002838 } else {
2839 group = OWE_DH_GROUP;
Roshan Pius3a1667e2018-07-03 15:17:14 -07002840 }
Hai Shalom74f70d42019-02-11 14:42:39 -08002841
Roshan Pius3a1667e2018-07-03 15:17:14 -07002842 wpa_s->last_owe_group = group;
2843 wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002844 owe_ie = owe_build_assoc_req(wpa_s->wpa, group);
2845 if (owe_ie &&
2846 wpabuf_len(owe_ie) <= max_wpa_ie_len - wpa_ie_len) {
2847 os_memcpy(wpa_ie + wpa_ie_len,
2848 wpabuf_head(owe_ie), wpabuf_len(owe_ie));
2849 wpa_ie_len += wpabuf_len(owe_ie);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002850 }
Hai Shalom021b0b52019-04-10 11:17:58 -07002851 wpabuf_free(owe_ie);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002852 }
2853#endif /* CONFIG_OWE */
2854
Hai Shalom021b0b52019-04-10 11:17:58 -07002855#ifdef CONFIG_DPP2
2856 if (wpa_sm_get_key_mgmt(wpa_s->wpa) == WPA_KEY_MGMT_DPP &&
2857 ssid->dpp_netaccesskey) {
2858 dpp_pfs_free(wpa_s->dpp_pfs);
2859 wpa_s->dpp_pfs = dpp_pfs_init(ssid->dpp_netaccesskey,
2860 ssid->dpp_netaccesskey_len);
2861 if (!wpa_s->dpp_pfs) {
2862 wpa_printf(MSG_DEBUG, "DPP: Could not initialize PFS");
2863 /* Try to continue without PFS */
2864 goto pfs_fail;
2865 }
2866 if (wpabuf_len(wpa_s->dpp_pfs->ie) <=
2867 max_wpa_ie_len - wpa_ie_len) {
2868 os_memcpy(wpa_ie + wpa_ie_len,
2869 wpabuf_head(wpa_s->dpp_pfs->ie),
2870 wpabuf_len(wpa_s->dpp_pfs->ie));
2871 wpa_ie_len += wpabuf_len(wpa_s->dpp_pfs->ie);
2872 }
2873 }
2874pfs_fail:
2875#endif /* CONFIG_DPP2 */
2876
Roshan Pius3a1667e2018-07-03 15:17:14 -07002877#ifdef CONFIG_IEEE80211R
2878 /*
2879 * Add MDIE under these conditions: the network profile allows FT,
2880 * the AP supports FT, and the mobility domain ID matches.
2881 */
2882 if (bss && wpa_key_mgmt_ft(wpa_sm_get_key_mgmt(wpa_s->wpa))) {
2883 const u8 *mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
2884
2885 if (mdie && mdie[1] >= MOBILITY_DOMAIN_ID_LEN) {
2886 size_t len = 0;
2887 const u8 *md = mdie + 2;
2888 const u8 *wpa_md = wpa_sm_get_ft_md(wpa_s->wpa);
2889
2890 if (os_memcmp(md, wpa_md,
2891 MOBILITY_DOMAIN_ID_LEN) == 0) {
2892 /* Add mobility domain IE */
2893 len = wpa_ft_add_mdie(
2894 wpa_s->wpa, wpa_ie + wpa_ie_len,
2895 max_wpa_ie_len - wpa_ie_len, mdie);
2896 wpa_ie_len += len;
2897 }
2898#ifdef CONFIG_SME
2899 if (len > 0 && wpa_s->sme.ft_used &&
2900 wpa_sm_has_ptk(wpa_s->wpa)) {
2901 wpa_dbg(wpa_s, MSG_DEBUG,
2902 "SME: Trying to use FT over-the-air");
2903 algs |= WPA_AUTH_ALG_FT;
2904 }
2905#endif /* CONFIG_SME */
2906 }
2907 }
2908#endif /* CONFIG_IEEE80211R */
2909
Hai Shalom74f70d42019-02-11 14:42:39 -08002910 if (ssid->multi_ap_backhaul_sta) {
2911 size_t multi_ap_ie_len;
2912
2913 multi_ap_ie_len = add_multi_ap_ie(wpa_ie + wpa_ie_len,
2914 max_wpa_ie_len - wpa_ie_len,
2915 MULTI_AP_BACKHAUL_STA);
2916 if (multi_ap_ie_len == 0) {
2917 wpa_printf(MSG_ERROR,
2918 "Multi-AP: Failed to build Multi-AP IE");
2919 os_free(wpa_ie);
2920 return NULL;
2921 }
2922 wpa_ie_len += multi_ap_ie_len;
2923 }
2924
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002925 params->wpa_ie = wpa_ie;
2926 params->wpa_ie_len = wpa_ie_len;
2927 params->auth_alg = algs;
2928 if (mask)
2929 *mask |= WPA_DRV_UPDATE_ASSOC_IES | WPA_DRV_UPDATE_AUTH_TYPE;
2930
2931 return wpa_ie;
2932}
2933
2934
2935#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
2936static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s)
2937{
2938 struct wpa_driver_associate_params params;
2939 enum wpa_drv_update_connect_params_mask mask = 0;
2940 u8 *wpa_ie;
2941
2942 if (wpa_s->auth_alg != WPA_AUTH_ALG_OPEN)
2943 return; /* nothing to do */
2944
2945 os_memset(&params, 0, sizeof(params));
2946 wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss,
2947 wpa_s->current_ssid, &params, &mask);
2948 if (!wpa_ie)
2949 return;
2950
2951 if (params.auth_alg != WPA_AUTH_ALG_FILS) {
2952 os_free(wpa_ie);
2953 return;
2954 }
2955
2956 wpa_s->auth_alg = params.auth_alg;
2957 wpa_drv_update_connect_params(wpa_s, &params, mask);
2958 os_free(wpa_ie);
2959}
2960#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
2961
2962
Hai Shalom021b0b52019-04-10 11:17:58 -07002963#ifdef CONFIG_MBO
2964void wpas_update_mbo_connect_params(struct wpa_supplicant *wpa_s)
2965{
2966 struct wpa_driver_associate_params params;
2967 u8 *wpa_ie;
2968
2969 /*
2970 * Update MBO connect params only in case of change of MBO attributes
2971 * when connected, if the AP support MBO.
2972 */
2973
2974 if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_ssid ||
2975 !wpa_s->current_bss ||
2976 !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
2977 return;
2978
2979 os_memset(&params, 0, sizeof(params));
2980 wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss,
2981 wpa_s->current_ssid, &params, NULL);
2982 if (!wpa_ie)
2983 return;
2984
2985 wpa_drv_update_connect_params(wpa_s, &params, WPA_DRV_UPDATE_ASSOC_IES);
2986 os_free(wpa_ie);
2987}
2988#endif /* CONFIG_MBO */
2989
2990
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002991static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit)
2992{
2993 struct wpa_connect_work *cwork = work->ctx;
2994 struct wpa_bss *bss = cwork->bss;
2995 struct wpa_ssid *ssid = cwork->ssid;
2996 struct wpa_supplicant *wpa_s = work->wpa_s;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002997 u8 *wpa_ie;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002998 int use_crypt, ret, i, bssid_changed;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002999 unsigned int cipher_pairwise, cipher_group, cipher_group_mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003000 struct wpa_driver_associate_params params;
3001 int wep_keys_set = 0;
3002 int assoc_failed = 0;
3003 struct wpa_ssid *old_ssid;
Dmitry Shmidte4663042016-04-04 10:07:49 -07003004 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003005#ifdef CONFIG_HT_OVERRIDES
3006 struct ieee80211_ht_capabilities htcaps;
3007 struct ieee80211_ht_capabilities htcaps_mask;
3008#endif /* CONFIG_HT_OVERRIDES */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003009#ifdef CONFIG_VHT_OVERRIDES
3010 struct ieee80211_vht_capabilities vhtcaps;
3011 struct ieee80211_vht_capabilities vhtcaps_mask;
3012#endif /* CONFIG_VHT_OVERRIDES */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003013
3014 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003015 if (work->started) {
3016 wpa_s->connect_work = NULL;
3017
3018 /* cancel possible auth. timeout */
3019 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s,
3020 NULL);
3021 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003022 wpas_connect_work_free(cwork);
3023 return;
3024 }
3025
3026 wpa_s->connect_work = work;
3027
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003028 if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid) ||
3029 wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003030 wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt");
3031 wpas_connect_work_done(wpa_s);
3032 return;
3033 }
3034
Dmitry Shmidte4663042016-04-04 10:07:49 -07003035 os_memcpy(prev_bssid, wpa_s->bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003036 os_memset(&params, 0, sizeof(params));
3037 wpa_s->reassociate = 0;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003038 wpa_s->eap_expected_failure = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003039 if (bss &&
3040 (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003041#ifdef CONFIG_IEEE80211R
3042 const u8 *ie, *md = NULL;
3043#endif /* CONFIG_IEEE80211R */
3044 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
3045 " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
3046 wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
3047 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
3048 os_memset(wpa_s->bssid, 0, ETH_ALEN);
3049 os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
3050 if (bssid_changed)
3051 wpas_notify_bssid_changed(wpa_s);
3052#ifdef CONFIG_IEEE80211R
3053 ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
3054 if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
3055 md = ie + 2;
3056 wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
3057 if (md) {
3058 /* Prepare for the next transition */
3059 wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
3060 }
3061#endif /* CONFIG_IEEE80211R */
3062#ifdef CONFIG_WPS
3063 } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) &&
3064 wpa_s->conf->ap_scan == 2 &&
3065 (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
3066 /* Use ap_scan==1 style network selection to find the network
3067 */
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08003068 wpas_connect_work_done(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003069 wpa_s->scan_req = MANUAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 wpa_s->reassociate = 1;
3071 wpa_supplicant_req_scan(wpa_s, 0, 0);
3072 return;
3073#endif /* CONFIG_WPS */
3074 } else {
3075 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'",
3076 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003077 if (bss)
3078 os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
3079 else
3080 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003082 if (!wpa_s->pno)
3083 wpa_supplicant_cancel_sched_scan(wpa_s);
3084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085 wpa_supplicant_cancel_scan(wpa_s);
3086
3087 /* Starting new association, so clear the possibly used WPA IE from the
3088 * previous association. */
3089 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
3090
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003091 wpa_ie = wpas_populate_assoc_ies(wpa_s, bss, ssid, &params, NULL);
3092 if (!wpa_ie) {
3093 wpas_connect_work_done(wpa_s);
3094 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003095 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003096
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003097 wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL);
3098 use_crypt = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003099 cipher_pairwise = wpa_s->pairwise_cipher;
3100 cipher_group = wpa_s->group_cipher;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003101 cipher_group_mgmt = wpa_s->mgmt_group_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003102 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
3103 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
3104 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE)
3105 use_crypt = 0;
3106 if (wpa_set_wep_keys(wpa_s, ssid)) {
3107 use_crypt = 1;
3108 wep_keys_set = 1;
3109 }
3110 }
3111 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)
3112 use_crypt = 0;
3113
3114#ifdef IEEE8021X_EAPOL
3115 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
3116 if ((ssid->eapol_flags &
3117 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
3118 EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 &&
3119 !wep_keys_set) {
3120 use_crypt = 0;
3121 } else {
3122 /* Assume that dynamic WEP-104 keys will be used and
3123 * set cipher suites in order for drivers to expect
3124 * encryption. */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003125 cipher_pairwise = cipher_group = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126 }
3127 }
3128#endif /* IEEE8021X_EAPOL */
3129
3130 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3131 /* Set the key before (and later after) association */
3132 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
3133 }
3134
3135 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
3136 if (bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137 params.ssid = bss->ssid;
3138 params.ssid_len = bss->ssid_len;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003139 if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set ||
3140 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003141 wpa_printf(MSG_DEBUG, "Limit connection to BSSID "
3142 MACSTR " freq=%u MHz based on scan results "
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003143 "(bssid_set=%d wps=%d)",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003144 MAC2STR(bss->bssid), bss->freq,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003145 ssid->bssid_set,
3146 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003147 params.bssid = bss->bssid;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07003148 params.freq.freq = bss->freq;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003149 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08003150 params.bssid_hint = bss->bssid;
3151 params.freq_hint = bss->freq;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003152 params.pbss = bss_is_pbss(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003153 } else {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003154 if (ssid->bssid_hint_set)
3155 params.bssid_hint = ssid->bssid_hint;
3156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003157 params.ssid = ssid->ssid;
3158 params.ssid_len = ssid->ssid_len;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003159 params.pbss = (ssid->pbss != 2) ? ssid->pbss : 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003160 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003161
3162 if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set &&
3163 wpa_s->conf->ap_scan == 2) {
3164 params.bssid = ssid->bssid;
3165 params.fixed_bssid = 1;
3166 }
3167
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003168 /* Initial frequency for IBSS/mesh */
3169 if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003170 ssid->frequency > 0 && params.freq.freq == 0)
3171 ibss_mesh_setup_freq(wpa_s, ssid, &params.freq);
Dmitry Shmidt2ac5f602014-03-07 10:08:21 -08003172
3173 if (ssid->mode == WPAS_MODE_IBSS) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003174 params.fixed_freq = ssid->fixed_freq;
Dmitry Shmidt2ac5f602014-03-07 10:08:21 -08003175 if (ssid->beacon_int)
3176 params.beacon_int = ssid->beacon_int;
3177 else
3178 params.beacon_int = wpa_s->conf->beacon_int;
3179 }
3180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003181 params.pairwise_suite = cipher_pairwise;
3182 params.group_suite = cipher_group;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003183 params.mgmt_group_suite = cipher_group_mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003184 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003185 params.wpa_proto = wpa_s->wpa_proto;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003186 wpa_s->auth_alg = params.auth_alg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 params.mode = ssid->mode;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003188 params.bg_scan_period = ssid->bg_scan_period;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003189 for (i = 0; i < NUM_WEP_KEYS; i++) {
3190 if (ssid->wep_key_len[i])
3191 params.wep_key[i] = ssid->wep_key[i];
3192 params.wep_key_len[i] = ssid->wep_key_len[i];
3193 }
3194 params.wep_tx_keyidx = ssid->wep_tx_keyidx;
3195
Hai Shalom74f70d42019-02-11 14:42:39 -08003196 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003197 (params.key_mgmt_suite == WPA_KEY_MGMT_PSK ||
3198 params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199 params.passphrase = ssid->passphrase;
3200 if (ssid->psk_set)
3201 params.psk = ssid->psk;
3202 }
3203
Hai Shalom74f70d42019-02-11 14:42:39 -08003204 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
3205 (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
3206 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
3207 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
3208 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192))
3209 params.req_key_mgmt_offload = 1;
3210
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003211 if (wpa_s->conf->key_mgmt_offload) {
3212 if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
3213 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003214 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
3215 params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003216 params.req_key_mgmt_offload =
3217 ssid->proactive_key_caching < 0 ?
3218 wpa_s->conf->okc : ssid->proactive_key_caching;
3219 else
3220 params.req_key_mgmt_offload = 1;
3221
3222 if ((params.key_mgmt_suite == WPA_KEY_MGMT_PSK ||
3223 params.key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
3224 params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK) &&
3225 ssid->psk_set)
3226 params.psk = ssid->psk;
3227 }
3228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003229 params.drop_unencrypted = use_crypt;
3230
3231#ifdef CONFIG_IEEE80211W
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003232 params.mgmt_frame_protection = wpas_get_ssid_pmf(wpa_s, ssid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003233 if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003234 const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3235 struct wpa_ie_data ie;
3236 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
3237 ie.capabilities &
3238 (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
3239 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports "
3240 "MFP: require MFP");
3241 params.mgmt_frame_protection =
3242 MGMT_FRAME_PROTECTION_REQUIRED;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003243#ifdef CONFIG_OWE
3244 } else if (!rsn && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
3245 !ssid->owe_only) {
3246 params.mgmt_frame_protection = NO_MGMT_FRAME_PROTECTION;
3247#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003248 }
3249 }
3250#endif /* CONFIG_IEEE80211W */
3251
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003252 params.p2p = ssid->p2p_group;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003253
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003254 if (wpa_s->p2pdev->set_sta_uapsd)
3255 params.uapsd = wpa_s->p2pdev->sta_uapsd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003256 else
3257 params.uapsd = -1;
3258
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003259#ifdef CONFIG_HT_OVERRIDES
3260 os_memset(&htcaps, 0, sizeof(htcaps));
3261 os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
3262 params.htcaps = (u8 *) &htcaps;
3263 params.htcaps_mask = (u8 *) &htcaps_mask;
3264 wpa_supplicant_apply_ht_overrides(wpa_s, ssid, &params);
3265#endif /* CONFIG_HT_OVERRIDES */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003266#ifdef CONFIG_VHT_OVERRIDES
3267 os_memset(&vhtcaps, 0, sizeof(vhtcaps));
3268 os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask));
3269 params.vhtcaps = &vhtcaps;
3270 params.vhtcaps_mask = &vhtcaps_mask;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003271 wpa_supplicant_apply_vht_overrides(wpa_s, ssid, &params);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07003272#endif /* CONFIG_VHT_OVERRIDES */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003273
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003274#ifdef CONFIG_P2P
3275 /*
3276 * If multi-channel concurrency is not supported, check for any
3277 * frequency conflict. In case of any frequency conflict, remove the
3278 * least prioritized connection.
3279 */
3280 if (wpa_s->num_multichan_concurrent < 2) {
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07003281 int freq, num;
3282 num = get_shared_radio_freqs(wpa_s, &freq, 1);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07003283 if (num > 0 && freq > 0 && freq != params.freq.freq) {
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07003284 wpa_printf(MSG_DEBUG,
3285 "Assoc conflicting freq found (%d != %d)",
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07003286 freq, params.freq.freq);
3287 if (wpas_p2p_handle_frequency_conflicts(
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08003288 wpa_s, params.freq.freq, ssid) < 0) {
3289 wpas_connect_work_done(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003290 os_free(wpa_ie);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003291 return;
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08003292 }
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003293 }
3294 }
3295#endif /* CONFIG_P2P */
3296
Dmitry Shmidte4663042016-04-04 10:07:49 -07003297 if (wpa_s->reassoc_same_ess && !is_zero_ether_addr(prev_bssid) &&
3298 wpa_s->current_ssid)
3299 params.prev_bssid = prev_bssid;
3300
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003301 ret = wpa_drv_associate(wpa_s, &params);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003302 os_free(wpa_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003303 if (ret < 0) {
3304 wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
3305 "failed");
3306 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SANE_ERROR_CODES) {
3307 /*
3308 * The driver is known to mean what is saying, so we
3309 * can stop right here; the association will not
3310 * succeed.
3311 */
3312 wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003313 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003314 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
3315 return;
3316 }
3317 /* try to continue anyway; new association will be tried again
3318 * after timeout */
3319 assoc_failed = 1;
3320 }
3321
3322 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
3323 /* Set the key after the association just in case association
3324 * cleared the previously configured key. */
3325 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
3326 /* No need to timeout authentication since there is no key
3327 * management. */
3328 wpa_supplicant_cancel_auth_timeout(wpa_s);
3329 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3330#ifdef CONFIG_IBSS_RSN
3331 } else if (ssid->mode == WPAS_MODE_IBSS &&
3332 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
3333 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
3334 /*
3335 * RSN IBSS authentication is per-STA and we can disable the
3336 * per-BSSID authentication.
3337 */
3338 wpa_supplicant_cancel_auth_timeout(wpa_s);
3339#endif /* CONFIG_IBSS_RSN */
3340 } else {
3341 /* Timeout for IEEE 802.11 authentication and association */
3342 int timeout = 60;
3343
3344 if (assoc_failed) {
3345 /* give IBSS a bit more time */
3346 timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
3347 } else if (wpa_s->conf->ap_scan == 1) {
3348 /* give IBSS a bit more time */
3349 timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
3350 }
3351 wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
3352 }
3353
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003354 if (wep_keys_set &&
3355 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003356 /* Set static WEP keys again */
3357 wpa_set_wep_keys(wpa_s, ssid);
3358 }
3359
3360 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) {
3361 /*
3362 * Do not allow EAP session resumption between different
3363 * network configurations.
3364 */
3365 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3366 }
3367 old_ssid = wpa_s->current_ssid;
3368 wpa_s->current_ssid = ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003369
3370 if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) {
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07003371 wpa_s->current_bss = bss;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003372#ifdef CONFIG_HS20
3373 hs20_configure_frame_filters(wpa_s);
3374#endif /* CONFIG_HS20 */
3375 }
3376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
3378 wpa_supplicant_initiate_eapol(wpa_s);
3379 if (old_ssid != wpa_s->current_ssid)
3380 wpas_notify_network_changed(wpa_s);
3381}
3382
3383
3384static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s,
3385 const u8 *addr)
3386{
3387 struct wpa_ssid *old_ssid;
3388
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003389 wpas_connect_work_done(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003390 wpa_clear_keys(wpa_s, addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003391 old_ssid = wpa_s->current_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003392 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003393 wpa_sm_set_config(wpa_s->wpa, NULL);
3394 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
3395 if (old_ssid != wpa_s->current_ssid)
3396 wpas_notify_network_changed(wpa_s);
3397 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
3398}
3399
3400
3401/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003402 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
3403 * @wpa_s: Pointer to wpa_supplicant data
3404 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
3405 *
3406 * This function is used to request %wpa_supplicant to deauthenticate from the
3407 * current AP.
3408 */
3409void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
3410 int reason_code)
3411{
3412 u8 *addr = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003413 union wpa_event_data event;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003414 int zero_addr = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003415
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003416 wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR
3417 " pending_bssid=" MACSTR " reason=%d state=%s",
3418 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
3419 reason_code, wpa_supplicant_state_txt(wpa_s->wpa_state));
3420
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003421 if (!is_zero_ether_addr(wpa_s->pending_bssid) &&
3422 (wpa_s->wpa_state == WPA_AUTHENTICATING ||
3423 wpa_s->wpa_state == WPA_ASSOCIATING))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003424 addr = wpa_s->pending_bssid;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003425 else if (!is_zero_ether_addr(wpa_s->bssid))
3426 addr = wpa_s->bssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003427 else if (wpa_s->wpa_state == WPA_ASSOCIATING) {
3428 /*
3429 * When using driver-based BSS selection, we may not know the
3430 * BSSID with which we are currently trying to associate. We
3431 * need to notify the driver of this disconnection even in such
3432 * a case, so use the all zeros address here.
3433 */
3434 addr = wpa_s->bssid;
3435 zero_addr = 1;
3436 }
3437
Hai Shalom74f70d42019-02-11 14:42:39 -08003438 if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
3439 wpa_s->enabled_4addr_mode = 0;
3440
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003441#ifdef CONFIG_TDLS
3442 wpa_tdls_teardown_peers(wpa_s->wpa);
3443#endif /* CONFIG_TDLS */
3444
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003445#ifdef CONFIG_MESH
3446 if (wpa_s->ifmsh) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003447 struct mesh_conf *mconf;
3448
3449 mconf = wpa_s->ifmsh->mconf;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08003450 wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s",
3451 wpa_s->ifname);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003452 wpas_notify_mesh_group_removed(wpa_s, mconf->meshid,
3453 mconf->meshid_len, reason_code);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003454 wpa_supplicant_leave_mesh(wpa_s);
3455 }
3456#endif /* CONFIG_MESH */
3457
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003458 if (addr) {
3459 wpa_drv_deauthenticate(wpa_s, addr, reason_code);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003460 os_memset(&event, 0, sizeof(event));
3461 event.deauth_info.reason_code = (u16) reason_code;
3462 event.deauth_info.locally_generated = 1;
3463 wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003464 if (zero_addr)
3465 addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003466 }
3467
3468 wpa_supplicant_clear_connection(wpa_s, addr);
3469}
3470
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003471static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s,
3472 struct wpa_ssid *ssid)
3473{
3474 if (!ssid || !ssid->disabled || ssid->disabled == 2)
3475 return;
3476
3477 ssid->disabled = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003478 ssid->owe_transition_bss_select_count = 0;
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003479 wpas_clear_temp_disabled(wpa_s, ssid, 1);
3480 wpas_notify_network_enabled_changed(wpa_s, ssid);
3481
3482 /*
3483 * Try to reassociate since there is no current configuration and a new
3484 * network was made available.
3485 */
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07003486 if (!wpa_s->current_ssid && !wpa_s->disconnected)
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003487 wpa_s->reassociate = 1;
3488}
3489
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003490
Roshan Pius950bec92016-07-19 09:49:24 -07003491/**
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003492 * wpa_supplicant_add_network - Add a new network
Roshan Pius950bec92016-07-19 09:49:24 -07003493 * @wpa_s: wpa_supplicant structure for a network interface
3494 * Returns: The new network configuration or %NULL if operation failed
3495 *
3496 * This function performs the following operations:
3497 * 1. Adds a new network.
3498 * 2. Send network addition notification.
3499 * 3. Marks the network disabled.
3500 * 4. Set network default parameters.
3501 */
3502struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s)
3503{
3504 struct wpa_ssid *ssid;
3505
3506 ssid = wpa_config_add_network(wpa_s->conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003507 if (!ssid)
Roshan Pius950bec92016-07-19 09:49:24 -07003508 return NULL;
Roshan Pius950bec92016-07-19 09:49:24 -07003509 wpas_notify_network_added(wpa_s, ssid);
3510 ssid->disabled = 1;
3511 wpa_config_set_network_defaults(ssid);
3512
3513 return ssid;
3514}
3515
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003516
Roshan Pius950bec92016-07-19 09:49:24 -07003517/**
3518 * wpa_supplicant_remove_network - Remove a configured network based on id
3519 * @wpa_s: wpa_supplicant structure for a network interface
3520 * @id: Unique network id to search for
3521 * Returns: 0 on success, or -1 if the network was not found, -2 if the network
3522 * could not be removed
3523 *
3524 * This function performs the following operations:
3525 * 1. Removes the network.
3526 * 2. Send network removal notification.
3527 * 3. Update internal state machines.
3528 * 4. Stop any running sched scans.
3529 */
3530int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id)
3531{
3532 struct wpa_ssid *ssid;
3533 int was_disabled;
3534
3535 ssid = wpa_config_get_network(wpa_s->conf, id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003536 if (!ssid)
Roshan Pius950bec92016-07-19 09:49:24 -07003537 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003538 wpas_notify_network_removed(wpa_s, ssid);
Roshan Pius950bec92016-07-19 09:49:24 -07003539
3540 if (wpa_s->last_ssid == ssid)
3541 wpa_s->last_ssid = NULL;
3542
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003543 if (ssid == wpa_s->current_ssid || !wpa_s->current_ssid) {
Roshan Pius950bec92016-07-19 09:49:24 -07003544#ifdef CONFIG_SME
3545 wpa_s->sme.prev_bssid_set = 0;
3546#endif /* CONFIG_SME */
3547 /*
3548 * Invalidate the EAP session cache if the current or
3549 * previously used network is removed.
3550 */
3551 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3552 }
3553
3554 if (ssid == wpa_s->current_ssid) {
3555 wpa_sm_set_config(wpa_s->wpa, NULL);
3556 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
3557
3558 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3559 wpa_s->own_disconnect_req = 1;
3560 wpa_supplicant_deauthenticate(wpa_s,
3561 WLAN_REASON_DEAUTH_LEAVING);
3562 }
3563
3564 was_disabled = ssid->disabled;
3565
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003566 if (wpa_config_remove_network(wpa_s->conf, id) < 0)
Roshan Pius950bec92016-07-19 09:49:24 -07003567 return -2;
Roshan Pius950bec92016-07-19 09:49:24 -07003568
3569 if (!was_disabled && wpa_s->sched_scanning) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003570 wpa_printf(MSG_DEBUG,
3571 "Stop ongoing sched_scan to remove network from filters");
Roshan Pius950bec92016-07-19 09:49:24 -07003572 wpa_supplicant_cancel_sched_scan(wpa_s);
3573 wpa_supplicant_req_scan(wpa_s, 0, 0);
3574 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003575
Roshan Pius950bec92016-07-19 09:49:24 -07003576 return 0;
3577}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580/**
3581 * wpa_supplicant_enable_network - Mark a configured network as enabled
3582 * @wpa_s: wpa_supplicant structure for a network interface
3583 * @ssid: wpa_ssid structure for a configured network or %NULL
3584 *
3585 * Enables the specified network or all networks if no network specified.
3586 */
3587void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
3588 struct wpa_ssid *ssid)
3589{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003590 if (ssid == NULL) {
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003591 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
3592 wpa_supplicant_enable_one_network(wpa_s, ssid);
3593 } else
3594 wpa_supplicant_enable_one_network(wpa_s, ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003595
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003596 if (wpa_s->reassociate && !wpa_s->disconnected &&
3597 (!wpa_s->current_ssid ||
3598 wpa_s->wpa_state == WPA_DISCONNECTED ||
3599 wpa_s->wpa_state == WPA_SCANNING)) {
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003600 if (wpa_s->sched_scanning) {
3601 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add "
3602 "new network to scan filters");
3603 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003604 }
3605
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003606 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
3607 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003608 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003609 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610 }
3611}
3612
3613
3614/**
3615 * wpa_supplicant_disable_network - Mark a configured network as disabled
3616 * @wpa_s: wpa_supplicant structure for a network interface
3617 * @ssid: wpa_ssid structure for a configured network or %NULL
3618 *
3619 * Disables the specified network or all networks if no network specified.
3620 */
3621void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
3622 struct wpa_ssid *ssid)
3623{
3624 struct wpa_ssid *other_ssid;
3625 int was_disabled;
3626
3627 if (ssid == NULL) {
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003628 if (wpa_s->sched_scanning)
3629 wpa_supplicant_cancel_sched_scan(wpa_s);
3630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 for (other_ssid = wpa_s->conf->ssid; other_ssid;
3632 other_ssid = other_ssid->next) {
3633 was_disabled = other_ssid->disabled;
3634 if (was_disabled == 2)
3635 continue; /* do not change persistent P2P group
3636 * data */
3637
3638 other_ssid->disabled = 1;
3639
3640 if (was_disabled != other_ssid->disabled)
3641 wpas_notify_network_enabled_changed(
3642 wpa_s, other_ssid);
3643 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003644 if (wpa_s->current_ssid) {
3645 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3646 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003647 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003648 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003649 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003650 } else if (ssid->disabled != 2) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003651 if (ssid == wpa_s->current_ssid) {
3652 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3653 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003654 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003655 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003656 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657
3658 was_disabled = ssid->disabled;
3659
3660 ssid->disabled = 1;
3661
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003662 if (was_disabled != ssid->disabled) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003663 wpas_notify_network_enabled_changed(wpa_s, ssid);
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003664 if (wpa_s->sched_scanning) {
3665 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan "
3666 "to remove network from filters");
3667 wpa_supplicant_cancel_sched_scan(wpa_s);
3668 wpa_supplicant_req_scan(wpa_s, 0, 0);
3669 }
3670 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003671 }
3672}
3673
3674
3675/**
3676 * wpa_supplicant_select_network - Attempt association with a network
3677 * @wpa_s: wpa_supplicant structure for a network interface
3678 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
3679 */
3680void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
3681 struct wpa_ssid *ssid)
3682{
3683
3684 struct wpa_ssid *other_ssid;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003685 int disconnected = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003686
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003687 if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) {
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003688 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3689 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003690 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003691 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003692 disconnected = 1;
3693 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003695 if (ssid)
3696 wpas_clear_temp_disabled(wpa_s, ssid, 1);
3697
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003698 /*
3699 * Mark all other networks disabled or mark all networks enabled if no
3700 * network specified.
3701 */
3702 for (other_ssid = wpa_s->conf->ssid; other_ssid;
3703 other_ssid = other_ssid->next) {
3704 int was_disabled = other_ssid->disabled;
3705 if (was_disabled == 2)
3706 continue; /* do not change persistent P2P group data */
3707
3708 other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003709 if (was_disabled && !other_ssid->disabled)
3710 wpas_clear_temp_disabled(wpa_s, other_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003711
3712 if (was_disabled != other_ssid->disabled)
3713 wpas_notify_network_enabled_changed(wpa_s, other_ssid);
3714 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003715
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003716 if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid &&
3717 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003718 /* We are already associated with the selected network */
3719 wpa_printf(MSG_DEBUG, "Already associated with the "
3720 "selected network - do nothing");
3721 return;
3722 }
3723
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003724 if (ssid) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003725 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003726 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003727 wpa_s->connect_without_scan =
3728 (ssid->mode == WPAS_MODE_MESH) ? ssid : NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003729
3730 /*
3731 * Don't optimize next scan freqs since a new ESS has been
3732 * selected.
3733 */
3734 os_free(wpa_s->next_scan_freqs);
3735 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003736 } else {
3737 wpa_s->connect_without_scan = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003738 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003740 wpa_s->disconnected = 0;
3741 wpa_s->reassociate = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003742 wpa_s->last_owe_group = 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003743 if (ssid)
3744 ssid->owe_transition_bss_select_count = 0;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003745
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003746 if (wpa_s->connect_without_scan ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003747 wpa_supplicant_fast_associate(wpa_s) != 1) {
3748 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003749 wpas_scan_reset_sched_scan(wpa_s);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003750 wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003751 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003752
3753 if (ssid)
3754 wpas_notify_network_selected(wpa_s, ssid);
3755}
3756
3757
3758/**
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003759 * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
3760 * @wpa_s: wpa_supplicant structure for a network interface
3761 * @pkcs11_engine_path: PKCS #11 engine path or NULL
3762 * @pkcs11_module_path: PKCS #11 module path or NULL
3763 * Returns: 0 on success; -1 on failure
3764 *
3765 * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
3766 * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
3767 * module path fails the paths will be reset to the default value (NULL).
3768 */
3769int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
3770 const char *pkcs11_engine_path,
3771 const char *pkcs11_module_path)
3772{
3773 char *pkcs11_engine_path_copy = NULL;
3774 char *pkcs11_module_path_copy = NULL;
3775
3776 if (pkcs11_engine_path != NULL) {
3777 pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path);
3778 if (pkcs11_engine_path_copy == NULL)
3779 return -1;
3780 }
3781 if (pkcs11_module_path != NULL) {
3782 pkcs11_module_path_copy = os_strdup(pkcs11_module_path);
Dmitry Shmidt97672262014-02-03 13:02:54 -08003783 if (pkcs11_module_path_copy == NULL) {
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003784 os_free(pkcs11_engine_path_copy);
3785 return -1;
3786 }
3787 }
3788
3789 os_free(wpa_s->conf->pkcs11_engine_path);
3790 os_free(wpa_s->conf->pkcs11_module_path);
3791 wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy;
3792 wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy;
3793
3794 wpa_sm_set_eapol(wpa_s->wpa, NULL);
3795 eapol_sm_deinit(wpa_s->eapol);
3796 wpa_s->eapol = NULL;
3797 if (wpa_supplicant_init_eapol(wpa_s)) {
3798 /* Error -> Reset paths to the default value (NULL) once. */
3799 if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL)
3800 wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL,
3801 NULL);
3802
3803 return -1;
3804 }
3805 wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
3806
3807 return 0;
3808}
3809
3810
3811/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003812 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
3813 * @wpa_s: wpa_supplicant structure for a network interface
3814 * @ap_scan: AP scan mode
3815 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
3816 *
3817 */
3818int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
3819{
3820
3821 int old_ap_scan;
3822
3823 if (ap_scan < 0 || ap_scan > 2)
3824 return -1;
3825
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003826 if (ap_scan == 2 && os_strcmp(wpa_s->driver->name, "nl80211") == 0) {
3827 wpa_printf(MSG_INFO,
3828 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
3829 }
3830
Dmitry Shmidt114c3862011-08-16 11:52:06 -07003831#ifdef ANDROID
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003832 if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan &&
3833 wpa_s->wpa_state >= WPA_ASSOCIATING &&
3834 wpa_s->wpa_state < WPA_COMPLETED) {
3835 wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while "
3836 "associating", wpa_s->conf->ap_scan, ap_scan);
Dmitry Shmidt114c3862011-08-16 11:52:06 -07003837 return 0;
3838 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003839#endif /* ANDROID */
Dmitry Shmidt114c3862011-08-16 11:52:06 -07003840
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003841 old_ap_scan = wpa_s->conf->ap_scan;
3842 wpa_s->conf->ap_scan = ap_scan;
3843
3844 if (old_ap_scan != wpa_s->conf->ap_scan)
3845 wpas_notify_ap_scan_changed(wpa_s);
3846
3847 return 0;
3848}
3849
3850
3851/**
3852 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
3853 * @wpa_s: wpa_supplicant structure for a network interface
3854 * @expire_age: Expiration age in seconds
3855 * Returns: 0 if succeed or -1 if expire_age has an invalid value
3856 *
3857 */
3858int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,
3859 unsigned int bss_expire_age)
3860{
3861 if (bss_expire_age < 10) {
3862 wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u",
3863 bss_expire_age);
3864 return -1;
3865 }
3866 wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec",
3867 bss_expire_age);
3868 wpa_s->conf->bss_expiration_age = bss_expire_age;
3869
3870 return 0;
3871}
3872
3873
3874/**
3875 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
3876 * @wpa_s: wpa_supplicant structure for a network interface
3877 * @expire_count: number of scans after which an unseen BSS is reclaimed
3878 * Returns: 0 if succeed or -1 if expire_count has an invalid value
3879 *
3880 */
3881int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s,
3882 unsigned int bss_expire_count)
3883{
3884 if (bss_expire_count < 1) {
3885 wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u",
3886 bss_expire_count);
3887 return -1;
3888 }
3889 wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u",
3890 bss_expire_count);
3891 wpa_s->conf->bss_expiration_scan_count = bss_expire_count;
3892
3893 return 0;
3894}
3895
3896
3897/**
Dmitry Shmidt04949592012-07-19 12:16:46 -07003898 * wpa_supplicant_set_scan_interval - Set scan interval
3899 * @wpa_s: wpa_supplicant structure for a network interface
3900 * @scan_interval: scan interval in seconds
3901 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
3902 *
3903 */
3904int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
3905 int scan_interval)
3906{
3907 if (scan_interval < 0) {
3908 wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d",
3909 scan_interval);
3910 return -1;
3911 }
3912 wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec",
3913 scan_interval);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003914 wpa_supplicant_update_scan_int(wpa_s, scan_interval);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003915
3916 return 0;
3917}
3918
3919
3920/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003921 * wpa_supplicant_set_debug_params - Set global debug params
3922 * @global: wpa_global structure
3923 * @debug_level: debug level
3924 * @debug_timestamp: determines if show timestamp in debug data
3925 * @debug_show_keys: determines if show keys in debug data
3926 * Returns: 0 if succeed or -1 if debug_level has wrong value
3927 */
3928int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
3929 int debug_timestamp, int debug_show_keys)
3930{
3931
3932 int old_level, old_timestamp, old_show_keys;
3933
3934 /* check for allowed debuglevels */
3935 if (debug_level != MSG_EXCESSIVE &&
3936 debug_level != MSG_MSGDUMP &&
3937 debug_level != MSG_DEBUG &&
3938 debug_level != MSG_INFO &&
3939 debug_level != MSG_WARNING &&
3940 debug_level != MSG_ERROR)
3941 return -1;
3942
3943 old_level = wpa_debug_level;
3944 old_timestamp = wpa_debug_timestamp;
3945 old_show_keys = wpa_debug_show_keys;
3946
3947 wpa_debug_level = debug_level;
3948 wpa_debug_timestamp = debug_timestamp ? 1 : 0;
3949 wpa_debug_show_keys = debug_show_keys ? 1 : 0;
3950
3951 if (wpa_debug_level != old_level)
3952 wpas_notify_debug_level_changed(global);
3953 if (wpa_debug_timestamp != old_timestamp)
3954 wpas_notify_debug_timestamp_changed(global);
3955 if (wpa_debug_show_keys != old_show_keys)
3956 wpas_notify_debug_show_keys_changed(global);
3957
3958 return 0;
3959}
3960
3961
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003962#ifdef CONFIG_OWE
3963static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
3964 const u8 *entry_ssid, size_t entry_ssid_len)
3965{
3966 const u8 *owe, *pos, *end;
3967 u8 ssid_len;
3968 struct wpa_bss *bss;
3969
3970 /* Check network profile SSID aganst the SSID in the
3971 * OWE Transition Mode element. */
3972
3973 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3974 if (!bss)
3975 return 0;
3976
3977 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3978 if (!owe)
3979 return 0;
3980
3981 pos = owe + 6;
3982 end = owe + 2 + owe[1];
3983
3984 if (end - pos < ETH_ALEN + 1)
3985 return 0;
3986 pos += ETH_ALEN;
3987 ssid_len = *pos++;
3988 if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
3989 return 0;
3990
3991 return entry_ssid_len == ssid_len &&
3992 os_memcmp(pos, entry_ssid, ssid_len) == 0;
3993}
3994#endif /* CONFIG_OWE */
3995
3996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003997/**
3998 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
3999 * @wpa_s: Pointer to wpa_supplicant data
4000 * Returns: A pointer to the current network structure or %NULL on failure
4001 */
4002struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
4003{
4004 struct wpa_ssid *entry;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07004005 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004006 int res;
4007 size_t ssid_len;
4008 u8 bssid[ETH_ALEN];
4009 int wired;
4010
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004011 res = wpa_drv_get_ssid(wpa_s, ssid);
4012 if (res < 0) {
4013 wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from "
4014 "driver");
4015 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004016 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004017 ssid_len = res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004018
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004019 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004020 wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from "
4021 "driver");
4022 return NULL;
4023 }
4024
4025 wired = wpa_s->conf->ap_scan == 0 &&
4026 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
4027
4028 entry = wpa_s->conf->ssid;
4029 while (entry) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07004030 if (!wpas_network_disabled(wpa_s, entry) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031 ((ssid_len == entry->ssid_len &&
Hai Shalom021b0b52019-04-10 11:17:58 -07004032 (!entry->ssid ||
4033 os_memcmp(ssid, entry->ssid, ssid_len) == 0)) ||
4034 wired) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035 (!entry->bssid_set ||
4036 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
4037 return entry;
4038#ifdef CONFIG_WPS
Dmitry Shmidt04949592012-07-19 12:16:46 -07004039 if (!wpas_network_disabled(wpa_s, entry) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004040 (entry->key_mgmt & WPA_KEY_MGMT_WPS) &&
4041 (entry->ssid == NULL || entry->ssid_len == 0) &&
4042 (!entry->bssid_set ||
4043 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
4044 return entry;
4045#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004046
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004047#ifdef CONFIG_OWE
4048 if (!wpas_network_disabled(wpa_s, entry) &&
4049 owe_trans_ssid_match(wpa_s, bssid, entry->ssid,
4050 entry->ssid_len) &&
4051 (!entry->bssid_set ||
4052 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
4053 return entry;
4054#endif /* CONFIG_OWE */
4055
Dmitry Shmidt04949592012-07-19 12:16:46 -07004056 if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004057 entry->ssid_len == 0 &&
4058 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)
4059 return entry;
4060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004061 entry = entry->next;
4062 }
4063
4064 return NULL;
4065}
4066
4067
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004068static int select_driver(struct wpa_supplicant *wpa_s, int i)
4069{
4070 struct wpa_global *global = wpa_s->global;
4071
4072 if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07004073 global->drv_priv[i] = wpa_drivers[i]->global_init(global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004074 if (global->drv_priv[i] == NULL) {
4075 wpa_printf(MSG_ERROR, "Failed to initialize driver "
4076 "'%s'", wpa_drivers[i]->name);
4077 return -1;
4078 }
4079 }
4080
4081 wpa_s->driver = wpa_drivers[i];
4082 wpa_s->global_drv_priv = global->drv_priv[i];
4083
4084 return 0;
4085}
4086
4087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004088static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
4089 const char *name)
4090{
4091 int i;
4092 size_t len;
4093 const char *pos, *driver = name;
4094
4095 if (wpa_s == NULL)
4096 return -1;
4097
4098 if (wpa_drivers[0] == NULL) {
4099 wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into "
4100 "wpa_supplicant");
4101 return -1;
4102 }
4103
4104 if (name == NULL) {
4105 /* default to first driver in the list */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004106 return select_driver(wpa_s, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004107 }
4108
4109 do {
4110 pos = os_strchr(driver, ',');
4111 if (pos)
4112 len = pos - driver;
4113 else
4114 len = os_strlen(driver);
4115
4116 for (i = 0; wpa_drivers[i]; i++) {
4117 if (os_strlen(wpa_drivers[i]->name) == len &&
4118 os_strncmp(driver, wpa_drivers[i]->name, len) ==
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004119 0) {
4120 /* First driver that succeeds wins */
4121 if (select_driver(wpa_s, i) == 0)
4122 return 0;
4123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004124 }
4125
4126 driver = pos + 1;
4127 } while (pos);
4128
4129 wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name);
4130 return -1;
4131}
4132
4133
4134/**
4135 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
4136 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
4137 * with struct wpa_driver_ops::init()
4138 * @src_addr: Source address of the EAPOL frame
4139 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
4140 * @len: Length of the EAPOL data
4141 *
4142 * This function is called for each received EAPOL frame. Most driver
4143 * interfaces rely on more generic OS mechanism for receiving frames through
4144 * l2_packet, but if such a mechanism is not available, the driver wrapper may
4145 * take care of received EAPOL frames and deliver them to the core supplicant
4146 * code by calling this function.
4147 */
4148void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
4149 const u8 *buf, size_t len)
4150{
4151 struct wpa_supplicant *wpa_s = ctx;
4152
4153 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
4154 wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
4155
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07004156#ifdef CONFIG_TESTING_OPTIONS
4157 if (wpa_s->ignore_auth_resp) {
4158 wpa_printf(MSG_INFO, "RX EAPOL - ignore_auth_resp active!");
4159 return;
4160 }
4161#endif /* CONFIG_TESTING_OPTIONS */
4162
Jouni Malinena05074c2012-12-21 21:35:35 +02004163 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
4164 (wpa_s->last_eapol_matches_bssid &&
4165#ifdef CONFIG_AP
4166 !wpa_s->ap_iface &&
4167#endif /* CONFIG_AP */
4168 os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 /*
4170 * There is possible race condition between receiving the
4171 * association event and the EAPOL frame since they are coming
4172 * through different paths from the driver. In order to avoid
4173 * issues in trying to process the EAPOL frame before receiving
4174 * association information, lets queue it for processing until
Jouni Malinena05074c2012-12-21 21:35:35 +02004175 * the association event is received. This may also be needed in
4176 * driver-based roaming case, so also use src_addr != BSSID as a
4177 * trigger if we have previously confirmed that the
4178 * Authenticator uses BSSID as the src_addr (which is not the
4179 * case with wired IEEE 802.1X).
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004180 */
4181 wpa_dbg(wpa_s, MSG_DEBUG, "Not associated - Delay processing "
Jouni Malinena05074c2012-12-21 21:35:35 +02004182 "of received EAPOL frame (state=%s bssid=" MACSTR ")",
4183 wpa_supplicant_state_txt(wpa_s->wpa_state),
4184 MAC2STR(wpa_s->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 wpabuf_free(wpa_s->pending_eapol_rx);
4186 wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len);
4187 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004188 os_get_reltime(&wpa_s->pending_eapol_rx_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004189 os_memcpy(wpa_s->pending_eapol_rx_src, src_addr,
4190 ETH_ALEN);
4191 }
4192 return;
4193 }
4194
Jouni Malinena05074c2012-12-21 21:35:35 +02004195 wpa_s->last_eapol_matches_bssid =
4196 os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) == 0;
4197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198#ifdef CONFIG_AP
4199 if (wpa_s->ap_iface) {
4200 wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len);
4201 return;
4202 }
4203#endif /* CONFIG_AP */
4204
4205 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
4206 wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since "
4207 "no key management is configured");
4208 return;
4209 }
4210
4211 if (wpa_s->eapol_received == 0 &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004212 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004213 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4214 wpa_s->wpa_state != WPA_COMPLETED) &&
4215 (wpa_s->current_ssid == NULL ||
4216 wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
4217 /* Timeout for completing IEEE 802.1X and WPA authentication */
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004218 int timeout = 10;
4219
4220 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
4221 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA ||
4222 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
4223 /* Use longer timeout for IEEE 802.1X/EAP */
4224 timeout = 70;
4225 }
4226
Dmitry Shmidt8bd70b72015-05-26 16:02:19 -07004227#ifdef CONFIG_WPS
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004228 if (wpa_s->current_ssid && wpa_s->current_bss &&
4229 (wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
4230 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
4231 /*
4232 * Use shorter timeout if going through WPS AP iteration
4233 * for PIN config method with an AP that does not
4234 * advertise Selected Registrar.
4235 */
4236 struct wpabuf *wps_ie;
4237
4238 wps_ie = wpa_bss_get_vendor_ie_multi(
4239 wpa_s->current_bss, WPS_IE_VENDOR_TYPE);
4240 if (wps_ie &&
4241 !wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1))
4242 timeout = 10;
4243 wpabuf_free(wps_ie);
4244 }
Dmitry Shmidt8bd70b72015-05-26 16:02:19 -07004245#endif /* CONFIG_WPS */
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07004246
4247 wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004248 }
4249 wpa_s->eapol_received++;
4250
4251 if (wpa_s->countermeasures) {
4252 wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped "
4253 "EAPOL packet");
4254 return;
4255 }
4256
4257#ifdef CONFIG_IBSS_RSN
4258 if (wpa_s->current_ssid &&
4259 wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
4260 ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
4261 return;
4262 }
4263#endif /* CONFIG_IBSS_RSN */
4264
4265 /* Source address of the incoming EAPOL frame could be compared to the
4266 * current BSSID. However, it is possible that a centralized
4267 * Authenticator could be using another MAC address than the BSSID of
4268 * an AP, so just allow any address to be used for now. The replies are
4269 * still sent to the current BSSID (if available), though. */
4270
4271 os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN);
4272 if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004273 wpa_s->key_mgmt != WPA_KEY_MGMT_OWE &&
4274 wpa_s->key_mgmt != WPA_KEY_MGMT_DPP &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004275 eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
4276 return;
4277 wpa_drv_poll(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08004278 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004279 wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
4280 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4281 /*
4282 * Set portValid = TRUE here since we are going to skip 4-way
4283 * handshake processing which would normally set portValid. We
4284 * need this to allow the EAPOL state machines to be completed
4285 * without going through EAPOL-Key handshake.
4286 */
4287 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
4288 }
4289}
4290
4291
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004292int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004293{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004294 if ((!wpa_s->p2p_mgmt ||
4295 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) &&
4296 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004297 l2_packet_deinit(wpa_s->l2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004298 wpa_s->l2 = l2_packet_init(wpa_s->ifname,
4299 wpa_drv_get_mac_addr(wpa_s),
4300 ETH_P_EAPOL,
4301 wpa_supplicant_rx_eapol, wpa_s, 0);
4302 if (wpa_s->l2 == NULL)
4303 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07004304
4305 if (l2_packet_set_packet_filter(wpa_s->l2,
4306 L2_PACKET_FILTER_PKTTYPE))
4307 wpa_dbg(wpa_s, MSG_DEBUG,
4308 "Failed to attach pkt_type filter");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004309 } else {
4310 const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
4311 if (addr)
4312 os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
4313 }
4314
4315 if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
4316 wpa_msg(wpa_s, MSG_ERROR, "Failed to get own L2 address");
4317 return -1;
4318 }
4319
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004320 wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
4321
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004322 return 0;
4323}
4324
4325
Dmitry Shmidt04949592012-07-19 12:16:46 -07004326static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr,
4327 const u8 *buf, size_t len)
4328{
4329 struct wpa_supplicant *wpa_s = ctx;
4330 const struct l2_ethhdr *eth;
4331
4332 if (len < sizeof(*eth))
4333 return;
4334 eth = (const struct l2_ethhdr *) buf;
4335
4336 if (os_memcmp(eth->h_dest, wpa_s->own_addr, ETH_ALEN) != 0 &&
4337 !(eth->h_dest[0] & 0x01)) {
4338 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
4339 " (bridge - not for this interface - ignore)",
4340 MAC2STR(src_addr), MAC2STR(eth->h_dest));
4341 return;
4342 }
4343
4344 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
4345 " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest));
4346 wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth),
4347 len - sizeof(*eth));
4348}
4349
4350
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004351/**
4352 * wpa_supplicant_driver_init - Initialize driver interface parameters
4353 * @wpa_s: Pointer to wpa_supplicant data
4354 * Returns: 0 on success, -1 on failure
4355 *
4356 * This function is called to initialize driver interface parameters.
4357 * wpa_drv_init() must have been called before this function to initialize the
4358 * driver interface.
4359 */
4360int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
4361{
4362 static int interface_count = 0;
4363
4364 if (wpa_supplicant_update_mac_addr(wpa_s) < 0)
4365 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004366
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004367 wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR,
4368 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004369 os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004370 wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
4371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004372 if (wpa_s->bridge_ifname[0]) {
4373 wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge "
4374 "interface '%s'", wpa_s->bridge_ifname);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08004375 wpa_s->l2_br = l2_packet_init_bridge(
4376 wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr,
4377 ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004378 if (wpa_s->l2_br == NULL) {
4379 wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet "
4380 "connection for the bridge interface '%s'",
4381 wpa_s->bridge_ifname);
4382 return -1;
4383 }
4384 }
4385
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004386 if (wpa_s->conf->ap_scan == 2 &&
4387 os_strcmp(wpa_s->driver->name, "nl80211") == 0) {
4388 wpa_printf(MSG_INFO,
4389 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
4390 }
4391
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004392 wpa_clear_keys(wpa_s, NULL);
4393
4394 /* Make sure that TKIP countermeasures are not left enabled (could
4395 * happen if wpa_supplicant is killed during countermeasures. */
4396 wpa_drv_set_countermeasures(wpa_s, 0);
4397
4398 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver");
4399 wpa_drv_flush_pmkid(wpa_s);
4400
4401 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004402 wpa_s->prev_scan_wildcard = 0;
4403
Dmitry Shmidt04949592012-07-19 12:16:46 -07004404 if (wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -08004405 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4406 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
4407 interface_count = 0;
4408 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004409#ifndef ANDROID
Dmitry Shmidta38abf92014-03-06 13:38:44 -08004410 if (!wpa_s->p2p_mgmt &&
Dmitry Shmidt98660862014-03-11 17:26:21 -07004411 wpa_supplicant_delayed_sched_scan(wpa_s,
4412 interface_count % 3,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004413 100000))
Dmitry Shmidt98660862014-03-11 17:26:21 -07004414 wpa_supplicant_req_scan(wpa_s, interface_count % 3,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004415 100000);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004416#endif /* ANDROID */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004417 interface_count++;
4418 } else
4419 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
4420
4421 return 0;
4422}
4423
4424
4425static int wpa_supplicant_daemon(const char *pid_file)
4426{
4427 wpa_printf(MSG_DEBUG, "Daemonize..");
4428 return os_daemonize(pid_file);
4429}
4430
4431
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004432static struct wpa_supplicant *
4433wpa_supplicant_alloc(struct wpa_supplicant *parent)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434{
4435 struct wpa_supplicant *wpa_s;
4436
4437 wpa_s = os_zalloc(sizeof(*wpa_s));
4438 if (wpa_s == NULL)
4439 return NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004440 wpa_s->scan_req = INITIAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 wpa_s->scan_interval = 5;
4442 wpa_s->new_connection = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004443 wpa_s->parent = parent ? parent : wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004444 wpa_s->p2pdev = wpa_s->parent;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004445 wpa_s->sched_scanning = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004447 dl_list_init(&wpa_s->bss_tmp_disallowed);
Paul Stewart092955c2017-02-06 09:13:09 -08004448 dl_list_init(&wpa_s->fils_hlp_req);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004449
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450 return wpa_s;
4451}
4452
4453
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004454#ifdef CONFIG_HT_OVERRIDES
4455
4456static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s,
4457 struct ieee80211_ht_capabilities *htcaps,
4458 struct ieee80211_ht_capabilities *htcaps_mask,
4459 const char *ht_mcs)
4460{
4461 /* parse ht_mcs into hex array */
4462 int i;
4463 const char *tmp = ht_mcs;
4464 char *end = NULL;
4465
4466 /* If ht_mcs is null, do not set anything */
4467 if (!ht_mcs)
4468 return 0;
4469
4470 /* This is what we are setting in the kernel */
4471 os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN);
4472
4473 wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs);
4474
4475 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Paul Stewart092955c2017-02-06 09:13:09 -08004476 long v;
4477
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004478 errno = 0;
Paul Stewart092955c2017-02-06 09:13:09 -08004479 v = strtol(tmp, &end, 16);
4480
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004481 if (errno == 0) {
4482 wpa_msg(wpa_s, MSG_DEBUG,
4483 "htcap value[%i]: %ld end: %p tmp: %p",
4484 i, v, end, tmp);
4485 if (end == tmp)
4486 break;
4487
4488 htcaps->supported_mcs_set[i] = v;
4489 tmp = end;
4490 } else {
4491 wpa_msg(wpa_s, MSG_ERROR,
4492 "Failed to parse ht-mcs: %s, error: %s\n",
4493 ht_mcs, strerror(errno));
4494 return -1;
4495 }
4496 }
4497
4498 /*
4499 * If we were able to parse any values, then set mask for the MCS set.
4500 */
4501 if (i) {
4502 os_memset(&htcaps_mask->supported_mcs_set, 0xff,
4503 IEEE80211_HT_MCS_MASK_LEN - 1);
4504 /* skip the 3 reserved bits */
4505 htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] =
4506 0x1f;
4507 }
4508
4509 return 0;
4510}
4511
4512
4513static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s,
4514 struct ieee80211_ht_capabilities *htcaps,
4515 struct ieee80211_ht_capabilities *htcaps_mask,
4516 int disabled)
4517{
Dmitry Shmidtc2817022014-07-02 10:32:10 -07004518 le16 msk;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004519
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004520 if (disabled == -1)
4521 return 0;
4522
Hai Shalom74f70d42019-02-11 14:42:39 -08004523 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled);
4524
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004525 msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE);
4526 htcaps_mask->ht_capabilities_info |= msk;
4527 if (disabled)
4528 htcaps->ht_capabilities_info &= msk;
4529 else
4530 htcaps->ht_capabilities_info |= msk;
4531
4532 return 0;
4533}
4534
4535
4536static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s,
4537 struct ieee80211_ht_capabilities *htcaps,
4538 struct ieee80211_ht_capabilities *htcaps_mask,
4539 int factor)
4540{
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004541 if (factor == -1)
4542 return 0;
4543
Hai Shalom74f70d42019-02-11 14:42:39 -08004544 wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor);
4545
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004546 if (factor < 0 || factor > 3) {
4547 wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. "
4548 "Must be 0-3 or -1", factor);
4549 return -EINVAL;
4550 }
4551
4552 htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */
4553 htcaps->a_mpdu_params &= ~0x3;
4554 htcaps->a_mpdu_params |= factor & 0x3;
4555
4556 return 0;
4557}
4558
4559
4560static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s,
4561 struct ieee80211_ht_capabilities *htcaps,
4562 struct ieee80211_ht_capabilities *htcaps_mask,
4563 int density)
4564{
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004565 if (density == -1)
4566 return 0;
4567
Hai Shalom74f70d42019-02-11 14:42:39 -08004568 wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density);
4569
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004570 if (density < 0 || density > 7) {
4571 wpa_msg(wpa_s, MSG_ERROR,
4572 "ampdu_density: %d out of range. Must be 0-7 or -1.",
4573 density);
4574 return -EINVAL;
4575 }
4576
4577 htcaps_mask->a_mpdu_params |= 0x1C;
4578 htcaps->a_mpdu_params &= ~(0x1C);
4579 htcaps->a_mpdu_params |= (density << 2) & 0x1C;
4580
4581 return 0;
4582}
4583
4584
4585static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s,
4586 struct ieee80211_ht_capabilities *htcaps,
4587 struct ieee80211_ht_capabilities *htcaps_mask,
4588 int disabled)
4589{
Hai Shalom74f70d42019-02-11 14:42:39 -08004590 if (disabled)
4591 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004592
Paul Stewart092955c2017-02-06 09:13:09 -08004593 set_disable_ht40(htcaps, disabled);
4594 set_disable_ht40(htcaps_mask, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004595
4596 return 0;
4597}
4598
4599
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004600static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s,
4601 struct ieee80211_ht_capabilities *htcaps,
4602 struct ieee80211_ht_capabilities *htcaps_mask,
4603 int disabled)
4604{
4605 /* Masking these out disables SGI */
Dmitry Shmidtc2817022014-07-02 10:32:10 -07004606 le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ |
4607 HT_CAP_INFO_SHORT_GI40MHZ);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004608
Hai Shalom74f70d42019-02-11 14:42:39 -08004609 if (disabled)
4610 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004611
4612 if (disabled)
4613 htcaps->ht_capabilities_info &= ~msk;
4614 else
4615 htcaps->ht_capabilities_info |= msk;
4616
4617 htcaps_mask->ht_capabilities_info |= msk;
4618
4619 return 0;
4620}
4621
4622
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004623static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s,
4624 struct ieee80211_ht_capabilities *htcaps,
4625 struct ieee80211_ht_capabilities *htcaps_mask,
4626 int disabled)
4627{
4628 /* Masking these out disables LDPC */
Dmitry Shmidtc2817022014-07-02 10:32:10 -07004629 le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004630
Hai Shalom74f70d42019-02-11 14:42:39 -08004631 if (disabled)
4632 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004633
4634 if (disabled)
4635 htcaps->ht_capabilities_info &= ~msk;
4636 else
4637 htcaps->ht_capabilities_info |= msk;
4638
4639 htcaps_mask->ht_capabilities_info |= msk;
4640
4641 return 0;
4642}
4643
4644
Hai Shalom74f70d42019-02-11 14:42:39 -08004645static int wpa_set_tx_stbc(struct wpa_supplicant *wpa_s,
4646 struct ieee80211_ht_capabilities *htcaps,
4647 struct ieee80211_ht_capabilities *htcaps_mask,
4648 int tx_stbc)
4649{
4650 le16 msk = host_to_le16(HT_CAP_INFO_TX_STBC);
4651
4652 if (tx_stbc == -1)
4653 return 0;
4654
4655 wpa_msg(wpa_s, MSG_DEBUG, "set_tx_stbc: %d", tx_stbc);
4656
4657 if (tx_stbc < 0 || tx_stbc > 1) {
4658 wpa_msg(wpa_s, MSG_ERROR,
4659 "tx_stbc: %d out of range. Must be 0-1 or -1", tx_stbc);
4660 return -EINVAL;
4661 }
4662
4663 htcaps_mask->ht_capabilities_info |= msk;
4664 htcaps->ht_capabilities_info &= ~msk;
4665 htcaps->ht_capabilities_info |= (tx_stbc << 7) & msk;
4666
4667 return 0;
4668}
4669
4670
4671static int wpa_set_rx_stbc(struct wpa_supplicant *wpa_s,
4672 struct ieee80211_ht_capabilities *htcaps,
4673 struct ieee80211_ht_capabilities *htcaps_mask,
4674 int rx_stbc)
4675{
4676 le16 msk = host_to_le16(HT_CAP_INFO_RX_STBC_MASK);
4677
4678 if (rx_stbc == -1)
4679 return 0;
4680
4681 wpa_msg(wpa_s, MSG_DEBUG, "set_rx_stbc: %d", rx_stbc);
4682
4683 if (rx_stbc < 0 || rx_stbc > 3) {
4684 wpa_msg(wpa_s, MSG_ERROR,
4685 "rx_stbc: %d out of range. Must be 0-3 or -1", rx_stbc);
4686 return -EINVAL;
4687 }
4688
4689 htcaps_mask->ht_capabilities_info |= msk;
4690 htcaps->ht_capabilities_info &= ~msk;
4691 htcaps->ht_capabilities_info |= (rx_stbc << 8) & msk;
4692
4693 return 0;
4694}
4695
4696
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004697void wpa_supplicant_apply_ht_overrides(
4698 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
4699 struct wpa_driver_associate_params *params)
4700{
4701 struct ieee80211_ht_capabilities *htcaps;
4702 struct ieee80211_ht_capabilities *htcaps_mask;
4703
4704 if (!ssid)
4705 return;
4706
4707 params->disable_ht = ssid->disable_ht;
4708 if (!params->htcaps || !params->htcaps_mask)
4709 return;
4710
4711 htcaps = (struct ieee80211_ht_capabilities *) params->htcaps;
4712 htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask;
4713 wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs);
4714 wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask,
4715 ssid->disable_max_amsdu);
4716 wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor);
4717 wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density);
4718 wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004719 wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004720 wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc);
Hai Shalom74f70d42019-02-11 14:42:39 -08004721 wpa_set_rx_stbc(wpa_s, htcaps, htcaps_mask, ssid->rx_stbc);
4722 wpa_set_tx_stbc(wpa_s, htcaps, htcaps_mask, ssid->tx_stbc);
Dmitry Shmidt61593f02014-04-21 16:27:35 -07004723
4724 if (ssid->ht40_intolerant) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07004725 le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT);
Dmitry Shmidt61593f02014-04-21 16:27:35 -07004726 htcaps->ht_capabilities_info |= bit;
4727 htcaps_mask->ht_capabilities_info |= bit;
4728 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004729}
4730
4731#endif /* CONFIG_HT_OVERRIDES */
4732
4733
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004734#ifdef CONFIG_VHT_OVERRIDES
4735void wpa_supplicant_apply_vht_overrides(
4736 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
4737 struct wpa_driver_associate_params *params)
4738{
4739 struct ieee80211_vht_capabilities *vhtcaps;
4740 struct ieee80211_vht_capabilities *vhtcaps_mask;
4741
4742 if (!ssid)
4743 return;
4744
4745 params->disable_vht = ssid->disable_vht;
4746
4747 vhtcaps = (void *) params->vhtcaps;
4748 vhtcaps_mask = (void *) params->vhtcaps_mask;
4749
4750 if (!vhtcaps || !vhtcaps_mask)
4751 return;
4752
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004753 vhtcaps->vht_capabilities_info = host_to_le32(ssid->vht_capa);
4754 vhtcaps_mask->vht_capabilities_info = host_to_le32(ssid->vht_capa_mask);
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004755
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004756#ifdef CONFIG_HT_OVERRIDES
Hai Shalom74f70d42019-02-11 14:42:39 -08004757 if (ssid->disable_sgi) {
4758 vhtcaps_mask->vht_capabilities_info |= (VHT_CAP_SHORT_GI_80 |
4759 VHT_CAP_SHORT_GI_160);
4760 vhtcaps->vht_capabilities_info &= ~(VHT_CAP_SHORT_GI_80 |
4761 VHT_CAP_SHORT_GI_160);
4762 wpa_msg(wpa_s, MSG_DEBUG,
4763 "disable-sgi override specified, vht-caps: 0x%x",
4764 vhtcaps->vht_capabilities_info);
4765 }
4766
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004767 /* if max ampdu is <= 3, we have to make the HT cap the same */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004768 if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) {
4769 int max_ampdu;
4770
4771 max_ampdu = (ssid->vht_capa &
4772 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >>
4773 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004774
4775 max_ampdu = max_ampdu < 3 ? max_ampdu : 3;
4776 wpa_set_ampdu_factor(wpa_s,
4777 (void *) params->htcaps,
4778 (void *) params->htcaps_mask,
4779 max_ampdu);
4780 }
4781#endif /* CONFIG_HT_OVERRIDES */
4782
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004783#define OVERRIDE_MCS(i) \
4784 if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \
4785 vhtcaps_mask->vht_supported_mcs_set.tx_map |= \
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004786 host_to_le16(3 << 2 * (i - 1)); \
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004787 vhtcaps->vht_supported_mcs_set.tx_map |= \
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004788 host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \
4789 2 * (i - 1)); \
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004790 } \
4791 if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \
4792 vhtcaps_mask->vht_supported_mcs_set.rx_map |= \
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004793 host_to_le16(3 << 2 * (i - 1)); \
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004794 vhtcaps->vht_supported_mcs_set.rx_map |= \
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004795 host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \
4796 2 * (i - 1)); \
Dmitry Shmidt2f023192013-03-12 12:44:17 -07004797 }
4798
4799 OVERRIDE_MCS(1);
4800 OVERRIDE_MCS(2);
4801 OVERRIDE_MCS(3);
4802 OVERRIDE_MCS(4);
4803 OVERRIDE_MCS(5);
4804 OVERRIDE_MCS(6);
4805 OVERRIDE_MCS(7);
4806 OVERRIDE_MCS(8);
4807}
4808#endif /* CONFIG_VHT_OVERRIDES */
4809
4810
Dmitry Shmidt04949592012-07-19 12:16:46 -07004811static int pcsc_reader_init(struct wpa_supplicant *wpa_s)
4812{
4813#ifdef PCSC_FUNCS
4814 size_t len;
4815
4816 if (!wpa_s->conf->pcsc_reader)
4817 return 0;
4818
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08004819 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004820 if (!wpa_s->scard)
4821 return 1;
4822
4823 if (wpa_s->conf->pcsc_pin &&
4824 scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) {
4825 scard_deinit(wpa_s->scard);
4826 wpa_s->scard = NULL;
4827 wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed");
4828 return -1;
4829 }
4830
4831 len = sizeof(wpa_s->imsi) - 1;
4832 if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) {
4833 scard_deinit(wpa_s->scard);
4834 wpa_s->scard = NULL;
4835 wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI");
4836 return -1;
4837 }
4838 wpa_s->imsi[len] = '\0';
4839
4840 wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard);
4841
4842 wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)",
4843 wpa_s->imsi, wpa_s->mnc_len);
4844
4845 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
4846 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
4847#endif /* PCSC_FUNCS */
4848
4849 return 0;
4850}
4851
4852
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004853int wpas_init_ext_pw(struct wpa_supplicant *wpa_s)
4854{
4855 char *val, *pos;
4856
4857 ext_password_deinit(wpa_s->ext_pw);
4858 wpa_s->ext_pw = NULL;
4859 eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL);
4860
4861 if (!wpa_s->conf->ext_password_backend)
4862 return 0;
4863
4864 val = os_strdup(wpa_s->conf->ext_password_backend);
4865 if (val == NULL)
4866 return -1;
4867 pos = os_strchr(val, ':');
4868 if (pos)
4869 *pos++ = '\0';
4870
4871 wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val);
4872
4873 wpa_s->ext_pw = ext_password_init(val, pos);
4874 os_free(val);
4875 if (wpa_s->ext_pw == NULL) {
4876 wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend");
4877 return -1;
4878 }
4879 eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw);
4880
4881 return 0;
4882}
4883
4884
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004885#ifdef CONFIG_FST
4886
4887static const u8 * wpas_fst_get_bssid_cb(void *ctx)
4888{
4889 struct wpa_supplicant *wpa_s = ctx;
4890
4891 return (is_zero_ether_addr(wpa_s->bssid) ||
4892 wpa_s->wpa_state != WPA_COMPLETED) ? NULL : wpa_s->bssid;
4893}
4894
4895
4896static void wpas_fst_get_channel_info_cb(void *ctx,
4897 enum hostapd_hw_mode *hw_mode,
4898 u8 *channel)
4899{
4900 struct wpa_supplicant *wpa_s = ctx;
4901
4902 if (wpa_s->current_bss) {
4903 *hw_mode = ieee80211_freq_to_chan(wpa_s->current_bss->freq,
4904 channel);
4905 } else if (wpa_s->hw.num_modes) {
4906 *hw_mode = wpa_s->hw.modes[0].mode;
4907 } else {
4908 WPA_ASSERT(0);
4909 *hw_mode = 0;
4910 }
4911}
4912
4913
4914static int wpas_fst_get_hw_modes(void *ctx, struct hostapd_hw_modes **modes)
4915{
4916 struct wpa_supplicant *wpa_s = ctx;
4917
4918 *modes = wpa_s->hw.modes;
4919 return wpa_s->hw.num_modes;
4920}
4921
4922
4923static void wpas_fst_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
4924{
4925 struct wpa_supplicant *wpa_s = ctx;
4926
4927 wpa_hexdump_buf(MSG_DEBUG, "FST: Set IEs", fst_ies);
4928 wpa_s->fst_ies = fst_ies;
4929}
4930
4931
4932static int wpas_fst_send_action_cb(void *ctx, const u8 *da, struct wpabuf *data)
4933{
4934 struct wpa_supplicant *wpa_s = ctx;
4935
Paul Stewart092955c2017-02-06 09:13:09 -08004936 if (os_memcmp(wpa_s->bssid, da, ETH_ALEN) != 0) {
4937 wpa_printf(MSG_INFO, "FST:%s:bssid=" MACSTR " != da=" MACSTR,
4938 __func__, MAC2STR(wpa_s->bssid), MAC2STR(da));
4939 return -1;
4940 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004941 return wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
Paul Stewart092955c2017-02-06 09:13:09 -08004942 wpa_s->own_addr, wpa_s->bssid,
4943 wpabuf_head(data), wpabuf_len(data),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004944 0);
4945}
4946
4947
4948static const struct wpabuf * wpas_fst_get_mb_ie_cb(void *ctx, const u8 *addr)
4949{
4950 struct wpa_supplicant *wpa_s = ctx;
4951
4952 WPA_ASSERT(os_memcmp(wpa_s->bssid, addr, ETH_ALEN) == 0);
4953 return wpa_s->received_mb_ies;
4954}
4955
4956
4957static void wpas_fst_update_mb_ie_cb(void *ctx, const u8 *addr,
4958 const u8 *buf, size_t size)
4959{
4960 struct wpa_supplicant *wpa_s = ctx;
4961 struct mb_ies_info info;
4962
4963 WPA_ASSERT(os_memcmp(wpa_s->bssid, addr, ETH_ALEN) == 0);
4964
4965 if (!mb_ies_info_by_ies(&info, buf, size)) {
4966 wpabuf_free(wpa_s->received_mb_ies);
4967 wpa_s->received_mb_ies = mb_ies_by_info(&info);
4968 }
4969}
4970
4971
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004972static const u8 * wpas_fst_get_peer_first(void *ctx,
4973 struct fst_get_peer_ctx **get_ctx,
4974 Boolean mb_only)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004975{
4976 struct wpa_supplicant *wpa_s = ctx;
4977
4978 *get_ctx = NULL;
4979 if (!is_zero_ether_addr(wpa_s->bssid))
4980 return (wpa_s->received_mb_ies || !mb_only) ?
4981 wpa_s->bssid : NULL;
4982 return NULL;
4983}
4984
4985
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07004986static const u8 * wpas_fst_get_peer_next(void *ctx,
4987 struct fst_get_peer_ctx **get_ctx,
4988 Boolean mb_only)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004989{
4990 return NULL;
4991}
4992
4993void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant *wpa_s,
4994 struct fst_wpa_obj *iface_obj)
4995{
4996 iface_obj->ctx = wpa_s;
4997 iface_obj->get_bssid = wpas_fst_get_bssid_cb;
4998 iface_obj->get_channel_info = wpas_fst_get_channel_info_cb;
4999 iface_obj->get_hw_modes = wpas_fst_get_hw_modes;
5000 iface_obj->set_ies = wpas_fst_set_ies_cb;
5001 iface_obj->send_action = wpas_fst_send_action_cb;
5002 iface_obj->get_mb_ie = wpas_fst_get_mb_ie_cb;
5003 iface_obj->update_mb_ie = wpas_fst_update_mb_ie_cb;
5004 iface_obj->get_peer_first = wpas_fst_get_peer_first;
5005 iface_obj->get_peer_next = wpas_fst_get_peer_next;
5006}
5007#endif /* CONFIG_FST */
5008
Dmitry Shmidtc2817022014-07-02 10:32:10 -07005009static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005010 const struct wpa_driver_capa *capa)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005011{
Dmitry Shmidt0207e232014-09-03 14:58:37 -07005012 struct wowlan_triggers *triggers;
5013 int ret = 0;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005014
5015 if (!wpa_s->conf->wowlan_triggers)
5016 return 0;
5017
Dmitry Shmidt0207e232014-09-03 14:58:37 -07005018 triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa);
5019 if (triggers) {
5020 ret = wpa_drv_wowlan(wpa_s, triggers);
5021 os_free(triggers);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005022 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005023 return ret;
5024}
5025
5026
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005027enum wpa_radio_work_band wpas_freq_to_band(int freq)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005028{
5029 if (freq < 3000)
5030 return BAND_2_4_GHZ;
5031 if (freq > 50000)
5032 return BAND_60_GHZ;
5033 return BAND_5_GHZ;
5034}
5035
5036
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005037unsigned int wpas_get_bands(struct wpa_supplicant *wpa_s, const int *freqs)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005038{
5039 int i;
5040 unsigned int band = 0;
5041
5042 if (freqs) {
5043 /* freqs are specified for the radio work */
5044 for (i = 0; freqs[i]; i++)
5045 band |= wpas_freq_to_band(freqs[i]);
5046 } else {
5047 /*
5048 * freqs are not specified, implies all
5049 * the supported freqs by HW
5050 */
5051 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5052 if (wpa_s->hw.modes[i].num_channels != 0) {
5053 if (wpa_s->hw.modes[i].mode ==
5054 HOSTAPD_MODE_IEEE80211B ||
5055 wpa_s->hw.modes[i].mode ==
5056 HOSTAPD_MODE_IEEE80211G)
5057 band |= BAND_2_4_GHZ;
5058 else if (wpa_s->hw.modes[i].mode ==
5059 HOSTAPD_MODE_IEEE80211A)
5060 band |= BAND_5_GHZ;
5061 else if (wpa_s->hw.modes[i].mode ==
5062 HOSTAPD_MODE_IEEE80211AD)
5063 band |= BAND_60_GHZ;
5064 else if (wpa_s->hw.modes[i].mode ==
5065 HOSTAPD_MODE_IEEE80211ANY)
5066 band = BAND_2_4_GHZ | BAND_5_GHZ |
5067 BAND_60_GHZ;
5068 }
5069 }
5070 }
5071
5072 return band;
5073}
5074
5075
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005076static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s,
5077 const char *rn)
5078{
5079 struct wpa_supplicant *iface = wpa_s->global->ifaces;
5080 struct wpa_radio *radio;
5081
5082 while (rn && iface) {
5083 radio = iface->radio;
5084 if (radio && os_strcmp(rn, radio->name) == 0) {
5085 wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s",
5086 wpa_s->ifname, rn);
5087 dl_list_add(&radio->ifaces, &wpa_s->radio_list);
5088 return radio;
5089 }
Dmitry Shmidt3cf6f792013-12-18 13:12:19 -08005090
5091 iface = iface->next;
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005092 }
5093
5094 wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s",
5095 wpa_s->ifname, rn ? rn : "N/A");
5096 radio = os_zalloc(sizeof(*radio));
5097 if (radio == NULL)
5098 return NULL;
5099
5100 if (rn)
5101 os_strlcpy(radio->name, rn, sizeof(radio->name));
5102 dl_list_init(&radio->ifaces);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005103 dl_list_init(&radio->work);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005104 dl_list_add(&radio->ifaces, &wpa_s->radio_list);
5105
5106 return radio;
5107}
5108
5109
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005110static void radio_work_free(struct wpa_radio_work *work)
5111{
5112 if (work->wpa_s->scan_work == work) {
5113 /* This should not really happen. */
5114 wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
5115 work->type, work, work->started);
5116 work->wpa_s->scan_work = NULL;
5117 }
5118
5119#ifdef CONFIG_P2P
5120 if (work->wpa_s->p2p_scan_work == work) {
5121 /* This should not really happen. */
5122 wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
5123 work->type, work, work->started);
5124 work->wpa_s->p2p_scan_work = NULL;
5125 }
5126#endif /* CONFIG_P2P */
5127
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005128 if (work->started) {
5129 work->wpa_s->radio->num_active_works--;
5130 wpa_dbg(work->wpa_s, MSG_DEBUG,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005131 "radio_work_free('%s'@%p): num_active_works --> %u",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005132 work->type, work,
5133 work->wpa_s->radio->num_active_works);
5134 }
5135
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005136 dl_list_del(&work->list);
5137 os_free(work);
5138}
5139
5140
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08005141static int radio_work_is_connect(struct wpa_radio_work *work)
5142{
5143 return os_strcmp(work->type, "sme-connect") == 0 ||
5144 os_strcmp(work->type, "connect") == 0;
5145}
5146
5147
5148static int radio_work_is_scan(struct wpa_radio_work *work)
5149{
5150 return os_strcmp(work->type, "scan") == 0 ||
5151 os_strcmp(work->type, "p2p-scan") == 0;
5152}
5153
5154
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005155static struct wpa_radio_work * radio_work_get_next_work(struct wpa_radio *radio)
5156{
5157 struct wpa_radio_work *active_work = NULL;
5158 struct wpa_radio_work *tmp;
5159
5160 /* Get the active work to know the type and band. */
5161 dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) {
5162 if (tmp->started) {
5163 active_work = tmp;
5164 break;
5165 }
5166 }
5167
5168 if (!active_work) {
5169 /* No active work, start one */
5170 radio->num_active_works = 0;
5171 dl_list_for_each(tmp, &radio->work, struct wpa_radio_work,
5172 list) {
5173 if (os_strcmp(tmp->type, "scan") == 0 &&
5174 radio->external_scan_running &&
5175 (((struct wpa_driver_scan_params *)
5176 tmp->ctx)->only_new_results ||
5177 tmp->wpa_s->clear_driver_scan_cache))
5178 continue;
5179 return tmp;
5180 }
5181 return NULL;
5182 }
5183
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08005184 if (radio_work_is_connect(active_work)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005185 /*
5186 * If the active work is either connect or sme-connect,
5187 * do not parallelize them with other radio works.
5188 */
5189 wpa_dbg(active_work->wpa_s, MSG_DEBUG,
5190 "Do not parallelize radio work with %s",
5191 active_work->type);
5192 return NULL;
5193 }
5194
5195 dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) {
5196 if (tmp->started)
5197 continue;
5198
5199 /*
5200 * If connect or sme-connect are enqueued, parallelize only
5201 * those operations ahead of them in the queue.
5202 */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08005203 if (radio_work_is_connect(tmp))
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005204 break;
5205
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08005206 /* Serialize parallel scan and p2p_scan operations on the same
5207 * interface since the driver_nl80211 mechanism for tracking
5208 * scan cookies does not yet have support for this. */
5209 if (active_work->wpa_s == tmp->wpa_s &&
5210 radio_work_is_scan(active_work) &&
5211 radio_work_is_scan(tmp)) {
5212 wpa_dbg(active_work->wpa_s, MSG_DEBUG,
5213 "Do not start work '%s' when another work '%s' is already scheduled",
5214 tmp->type, active_work->type);
5215 continue;
5216 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005217 /*
5218 * Check that the radio works are distinct and
5219 * on different bands.
5220 */
5221 if (os_strcmp(active_work->type, tmp->type) != 0 &&
5222 (active_work->bands != tmp->bands)) {
5223 /*
5224 * If a scan has to be scheduled through nl80211 scan
5225 * interface and if an external scan is already running,
5226 * do not schedule the scan since it is likely to get
5227 * rejected by kernel.
5228 */
5229 if (os_strcmp(tmp->type, "scan") == 0 &&
5230 radio->external_scan_running &&
5231 (((struct wpa_driver_scan_params *)
5232 tmp->ctx)->only_new_results ||
5233 tmp->wpa_s->clear_driver_scan_cache))
5234 continue;
5235
5236 wpa_dbg(active_work->wpa_s, MSG_DEBUG,
5237 "active_work:%s new_work:%s",
5238 active_work->type, tmp->type);
5239 return tmp;
5240 }
5241 }
5242
5243 /* Did not find a radio work to schedule in parallel. */
5244 return NULL;
5245}
5246
5247
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005248static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx)
5249{
5250 struct wpa_radio *radio = eloop_ctx;
5251 struct wpa_radio_work *work;
5252 struct os_reltime now, diff;
5253 struct wpa_supplicant *wpa_s;
5254
5255 work = dl_list_first(&radio->work, struct wpa_radio_work, list);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005256 if (work == NULL) {
5257 radio->num_active_works = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005258 return;
5259 }
5260
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005261 wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant,
5262 radio_list);
5263
5264 if (!(wpa_s &&
5265 wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)) {
5266 if (work->started)
5267 return; /* already started and still in progress */
5268
5269 if (wpa_s && wpa_s->radio->external_scan_running) {
5270 wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes");
5271 return;
5272 }
5273 } else {
5274 work = NULL;
5275 if (radio->num_active_works < MAX_ACTIVE_WORKS) {
5276 /* get the work to schedule next */
5277 work = radio_work_get_next_work(radio);
5278 }
5279 if (!work)
5280 return;
5281 }
5282
5283 wpa_s = work->wpa_s;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005284 os_get_reltime(&now);
5285 os_reltime_sub(&now, &work->time, &diff);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005286 wpa_dbg(wpa_s, MSG_DEBUG,
5287 "Starting radio work '%s'@%p after %ld.%06ld second wait",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005288 work->type, work, diff.sec, diff.usec);
5289 work->started = 1;
5290 work->time = now;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005291 radio->num_active_works++;
5292
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005293 work->cb(work, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005294
5295 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) &&
5296 radio->num_active_works < MAX_ACTIVE_WORKS)
5297 radio_work_check_next(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005298}
5299
5300
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005301/*
5302 * This function removes both started and pending radio works running on
5303 * the provided interface's radio.
5304 * Prior to the removal of the radio work, its callback (cb) is called with
5305 * deinit set to be 1. Each work's callback is responsible for clearing its
5306 * internal data and restoring to a correct state.
5307 * @wpa_s: wpa_supplicant data
5308 * @type: type of works to be removed
5309 * @remove_all: 1 to remove all the works on this radio, 0 to remove only
5310 * this interface's works.
5311 */
5312void radio_remove_works(struct wpa_supplicant *wpa_s,
5313 const char *type, int remove_all)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005314{
5315 struct wpa_radio_work *work, *tmp;
5316 struct wpa_radio *radio = wpa_s->radio;
5317
5318 dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work,
5319 list) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005320 if (type && os_strcmp(type, work->type) != 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005321 continue;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005322
5323 /* skip other ifaces' works */
5324 if (!remove_all && work->wpa_s != wpa_s)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005325 continue;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005326
5327 wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s",
5328 work->type, work, work->started ? " (started)" : "");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005329 work->cb(work, 1);
5330 radio_work_free(work);
5331 }
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08005332
5333 /* in case we removed the started work */
5334 radio_work_check_next(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005335}
5336
5337
Roshan Pius3a1667e2018-07-03 15:17:14 -07005338void radio_remove_pending_work(struct wpa_supplicant *wpa_s, void *ctx)
5339{
5340 struct wpa_radio_work *work;
5341 struct wpa_radio *radio = wpa_s->radio;
5342
5343 dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
5344 if (work->ctx != ctx)
5345 continue;
5346 wpa_dbg(wpa_s, MSG_DEBUG, "Free pending radio work '%s'@%p%s",
5347 work->type, work, work->started ? " (started)" : "");
5348 radio_work_free(work);
5349 break;
5350 }
5351}
5352
5353
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005354static void radio_remove_interface(struct wpa_supplicant *wpa_s)
5355{
5356 struct wpa_radio *radio = wpa_s->radio;
5357
5358 if (!radio)
5359 return;
5360
5361 wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s",
5362 wpa_s->ifname, radio->name);
5363 dl_list_del(&wpa_s->radio_list);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005364 radio_remove_works(wpa_s, NULL, 0);
5365 wpa_s->radio = NULL;
5366 if (!dl_list_empty(&radio->ifaces))
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005367 return; /* Interfaces remain for this radio */
5368
5369 wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005370 eloop_cancel_timeout(radio_start_next_work, radio, NULL);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005371 os_free(radio);
5372}
5373
5374
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005375void radio_work_check_next(struct wpa_supplicant *wpa_s)
5376{
5377 struct wpa_radio *radio = wpa_s->radio;
5378
5379 if (dl_list_empty(&radio->work))
5380 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005381 if (wpa_s->ext_work_in_progress) {
5382 wpa_printf(MSG_DEBUG,
5383 "External radio work in progress - delay start of pending item");
5384 return;
5385 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005386 eloop_cancel_timeout(radio_start_next_work, radio, NULL);
5387 eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL);
5388}
5389
5390
5391/**
5392 * radio_add_work - Add a radio work item
5393 * @wpa_s: Pointer to wpa_supplicant data
5394 * @freq: Frequency of the offchannel operation in MHz or 0
5395 * @type: Unique identifier for each type of work
5396 * @next: Force as the next work to be executed
5397 * @cb: Callback function for indicating when radio is available
5398 * @ctx: Context pointer for the work (work->ctx in cb())
5399 * Returns: 0 on success, -1 on failure
5400 *
5401 * This function is used to request time for an operation that requires
5402 * exclusive radio control. Once the radio is available, the registered callback
5403 * function will be called. radio_work_done() must be called once the exclusive
5404 * radio operation has been completed, so that the radio is freed for other
5405 * operations. The special case of deinit=1 is used to free the context data
5406 * during interface removal. That does not allow the callback function to start
5407 * the radio operation, i.e., it must free any resources allocated for the radio
5408 * work and return.
5409 *
5410 * The @freq parameter can be used to indicate a single channel on which the
5411 * offchannel operation will occur. This may allow multiple radio work
5412 * operations to be performed in parallel if they apply for the same channel.
5413 * Setting this to 0 indicates that the work item may use multiple channels or
5414 * requires exclusive control of the radio.
5415 */
5416int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
5417 const char *type, int next,
5418 void (*cb)(struct wpa_radio_work *work, int deinit),
5419 void *ctx)
5420{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005421 struct wpa_radio *radio = wpa_s->radio;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005422 struct wpa_radio_work *work;
5423 int was_empty;
5424
5425 work = os_zalloc(sizeof(*work));
5426 if (work == NULL)
5427 return -1;
5428 wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work);
5429 os_get_reltime(&work->time);
5430 work->freq = freq;
5431 work->type = type;
5432 work->wpa_s = wpa_s;
5433 work->cb = cb;
5434 work->ctx = ctx;
5435
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005436 if (freq)
5437 work->bands = wpas_freq_to_band(freq);
5438 else if (os_strcmp(type, "scan") == 0 ||
5439 os_strcmp(type, "p2p-scan") == 0)
5440 work->bands = wpas_get_bands(wpa_s,
5441 ((struct wpa_driver_scan_params *)
5442 ctx)->freqs);
5443 else
5444 work->bands = wpas_get_bands(wpa_s, NULL);
5445
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005446 was_empty = dl_list_empty(&wpa_s->radio->work);
5447 if (next)
5448 dl_list_add(&wpa_s->radio->work, &work->list);
5449 else
5450 dl_list_add_tail(&wpa_s->radio->work, &work->list);
5451 if (was_empty) {
5452 wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately");
5453 radio_work_check_next(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005454 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)
5455 && radio->num_active_works < MAX_ACTIVE_WORKS) {
5456 wpa_dbg(wpa_s, MSG_DEBUG,
5457 "Try to schedule a radio work (num_active_works=%u)",
5458 radio->num_active_works);
5459 radio_work_check_next(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005460 }
5461
5462 return 0;
5463}
5464
5465
5466/**
5467 * radio_work_done - Indicate that a radio work item has been completed
5468 * @work: Completed work
5469 *
5470 * This function is called once the callback function registered with
5471 * radio_add_work() has completed its work.
5472 */
5473void radio_work_done(struct wpa_radio_work *work)
5474{
5475 struct wpa_supplicant *wpa_s = work->wpa_s;
5476 struct os_reltime now, diff;
5477 unsigned int started = work->started;
5478
5479 os_get_reltime(&now);
5480 os_reltime_sub(&now, &work->time, &diff);
5481 wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds",
5482 work->type, work, started ? "done" : "canceled",
5483 diff.sec, diff.usec);
5484 radio_work_free(work);
5485 if (started)
5486 radio_work_check_next(wpa_s);
5487}
5488
5489
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08005490struct wpa_radio_work *
5491radio_work_pending(struct wpa_supplicant *wpa_s, const char *type)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005492{
5493 struct wpa_radio_work *work;
5494 struct wpa_radio *radio = wpa_s->radio;
5495
5496 dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
5497 if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0)
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08005498 return work;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005499 }
5500
Dmitry Shmidt2e425d62014-11-10 11:18:27 -08005501 return NULL;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005502}
5503
5504
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005505static int wpas_init_driver(struct wpa_supplicant *wpa_s,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005506 const struct wpa_interface *iface)
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005507{
5508 const char *ifname, *driver, *rn;
5509
5510 driver = iface->driver;
5511next_driver:
5512 if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
5513 return -1;
5514
5515 wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
5516 if (wpa_s->drv_priv == NULL) {
5517 const char *pos;
5518 pos = driver ? os_strchr(driver, ',') : NULL;
5519 if (pos) {
5520 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
5521 "driver interface - try next driver wrapper");
5522 driver = pos + 1;
5523 goto next_driver;
5524 }
5525 wpa_msg(wpa_s, MSG_ERROR, "Failed to initialize driver "
5526 "interface");
5527 return -1;
5528 }
5529 if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) {
5530 wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected "
5531 "driver_param '%s'", wpa_s->conf->driver_param);
5532 return -1;
5533 }
5534
5535 ifname = wpa_drv_get_ifname(wpa_s);
5536 if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) {
5537 wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced "
5538 "interface name with '%s'", ifname);
5539 os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname));
5540 }
5541
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005542 rn = wpa_driver_get_radio_name(wpa_s);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005543 if (rn && rn[0] == '\0')
5544 rn = NULL;
5545
5546 wpa_s->radio = radio_add_interface(wpa_s, rn);
5547 if (wpa_s->radio == NULL)
5548 return -1;
5549
5550 return 0;
5551}
5552
5553
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005554#ifdef CONFIG_GAS_SERVER
5555
5556static void wpas_gas_server_tx_status(struct wpa_supplicant *wpa_s,
5557 unsigned int freq, const u8 *dst,
5558 const u8 *src, const u8 *bssid,
5559 const u8 *data, size_t data_len,
5560 enum offchannel_send_action_result result)
5561{
5562 wpa_printf(MSG_DEBUG, "GAS: TX status: freq=%u dst=" MACSTR
5563 " result=%s",
5564 freq, MAC2STR(dst),
5565 result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
5566 (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
5567 "FAILED"));
5568 gas_server_tx_status(wpa_s->gas_server, dst, data, data_len,
5569 result == OFFCHANNEL_SEND_ACTION_SUCCESS);
5570}
5571
5572
5573static void wpas_gas_server_tx(void *ctx, int freq, const u8 *da,
5574 struct wpabuf *buf, unsigned int wait_time)
5575{
5576 struct wpa_supplicant *wpa_s = ctx;
5577 const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5578
5579 if (wait_time > wpa_s->max_remain_on_chan)
5580 wait_time = wpa_s->max_remain_on_chan;
5581
5582 offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, broadcast,
5583 wpabuf_head(buf), wpabuf_len(buf),
5584 wait_time, wpas_gas_server_tx_status, 0);
5585}
5586
5587#endif /* CONFIG_GAS_SERVER */
5588
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005589static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
Roshan Pius3a1667e2018-07-03 15:17:14 -07005590 const struct wpa_interface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005591{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005592 struct wpa_driver_capa capa;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005593 int capa_res;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005594 u8 dfs_domain;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005595
5596 wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
5597 "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
5598 iface->confname ? iface->confname : "N/A",
5599 iface->driver ? iface->driver : "default",
5600 iface->ctrl_interface ? iface->ctrl_interface : "N/A",
5601 iface->bridge_ifname ? iface->bridge_ifname : "N/A");
5602
5603 if (iface->confname) {
5604#ifdef CONFIG_BACKEND_FILE
5605 wpa_s->confname = os_rel2abs_path(iface->confname);
5606 if (wpa_s->confname == NULL) {
5607 wpa_printf(MSG_ERROR, "Failed to get absolute path "
5608 "for configuration file '%s'.",
5609 iface->confname);
5610 return -1;
5611 }
5612 wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'",
5613 iface->confname, wpa_s->confname);
5614#else /* CONFIG_BACKEND_FILE */
5615 wpa_s->confname = os_strdup(iface->confname);
5616#endif /* CONFIG_BACKEND_FILE */
Dmitry Shmidt64f47c52013-04-16 10:41:54 -07005617 wpa_s->conf = wpa_config_read(wpa_s->confname, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005618 if (wpa_s->conf == NULL) {
5619 wpa_printf(MSG_ERROR, "Failed to read or parse "
5620 "configuration '%s'.", wpa_s->confname);
5621 return -1;
5622 }
Dmitry Shmidt64f47c52013-04-16 10:41:54 -07005623 wpa_s->confanother = os_rel2abs_path(iface->confanother);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005624 if (wpa_s->confanother &&
5625 !wpa_config_read(wpa_s->confanother, wpa_s->conf)) {
5626 wpa_printf(MSG_ERROR,
5627 "Failed to read or parse configuration '%s'.",
5628 wpa_s->confanother);
5629 return -1;
5630 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005631
5632 /*
5633 * Override ctrl_interface and driver_param if set on command
5634 * line.
5635 */
5636 if (iface->ctrl_interface) {
5637 os_free(wpa_s->conf->ctrl_interface);
5638 wpa_s->conf->ctrl_interface =
5639 os_strdup(iface->ctrl_interface);
5640 }
5641
5642 if (iface->driver_param) {
5643 os_free(wpa_s->conf->driver_param);
5644 wpa_s->conf->driver_param =
5645 os_strdup(iface->driver_param);
5646 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005647
5648 if (iface->p2p_mgmt && !iface->ctrl_interface) {
5649 os_free(wpa_s->conf->ctrl_interface);
5650 wpa_s->conf->ctrl_interface = NULL;
5651 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005652 } else
5653 wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface,
5654 iface->driver_param);
5655
5656 if (wpa_s->conf == NULL) {
5657 wpa_printf(MSG_ERROR, "\nNo configuration found.");
5658 return -1;
5659 }
5660
5661 if (iface->ifname == NULL) {
5662 wpa_printf(MSG_ERROR, "\nInterface name is required.");
5663 return -1;
5664 }
5665 if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) {
5666 wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.",
5667 iface->ifname);
5668 return -1;
5669 }
5670 os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname));
5671
5672 if (iface->bridge_ifname) {
5673 if (os_strlen(iface->bridge_ifname) >=
5674 sizeof(wpa_s->bridge_ifname)) {
5675 wpa_printf(MSG_ERROR, "\nToo long bridge interface "
5676 "name '%s'.", iface->bridge_ifname);
5677 return -1;
5678 }
5679 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
5680 sizeof(wpa_s->bridge_ifname));
5681 }
5682
5683 /* RSNA Supplicant Key Management - INITIALIZE */
5684 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
5685 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
5686
5687 /* Initialize driver interface and register driver event handler before
5688 * L2 receive handler so that association events are processed before
5689 * EAPOL-Key packets if both become available for the same select()
5690 * call. */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005691 if (wpas_init_driver(wpa_s, iface) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692 return -1;
5693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005694 if (wpa_supplicant_init_wpa(wpa_s) < 0)
5695 return -1;
5696
5697 wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname,
5698 wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname :
5699 NULL);
5700 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
5701
5702 if (wpa_s->conf->dot11RSNAConfigPMKLifetime &&
5703 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
5704 wpa_s->conf->dot11RSNAConfigPMKLifetime)) {
5705 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
5706 "dot11RSNAConfigPMKLifetime");
5707 return -1;
5708 }
5709
5710 if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold &&
5711 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
5712 wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) {
5713 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
5714 "dot11RSNAConfigPMKReauthThreshold");
5715 return -1;
5716 }
5717
5718 if (wpa_s->conf->dot11RSNAConfigSATimeout &&
5719 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
5720 wpa_s->conf->dot11RSNAConfigSATimeout)) {
5721 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
5722 "dot11RSNAConfigSATimeout");
5723 return -1;
5724 }
5725
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005726 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s,
5727 &wpa_s->hw.num_modes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005728 &wpa_s->hw.flags,
5729 &dfs_domain);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005730 if (wpa_s->hw.modes) {
5731 u16 i;
5732
5733 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5734 if (wpa_s->hw.modes[i].vht_capab) {
5735 wpa_s->hw_capab = CAPAB_VHT;
5736 break;
5737 }
5738
5739 if (wpa_s->hw.modes[i].ht_capab &
5740 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
5741 wpa_s->hw_capab = CAPAB_HT40;
5742 else if (wpa_s->hw.modes[i].ht_capab &&
5743 wpa_s->hw_capab == CAPAB_NO_HT_VHT)
5744 wpa_s->hw_capab = CAPAB_HT;
5745 }
5746 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005747
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005748 capa_res = wpa_drv_get_capa(wpa_s, &capa);
5749 if (capa_res == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005750 wpa_s->drv_capa_known = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005751 wpa_s->drv_flags = capa.flags;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005752 wpa_s->drv_enc = capa.enc;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005753 wpa_s->drv_smps_modes = capa.smps_modes;
5754 wpa_s->drv_rrm_flags = capa.rrm_flags;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005755 wpa_s->probe_resp_offloads = capa.probe_resp_offloads;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005756 wpa_s->max_scan_ssids = capa.max_scan_ssids;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005757 wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005758 wpa_s->max_sched_scan_plans = capa.max_sched_scan_plans;
5759 wpa_s->max_sched_scan_plan_interval =
5760 capa.max_sched_scan_plan_interval;
5761 wpa_s->max_sched_scan_plan_iterations =
5762 capa.max_sched_scan_plan_iterations;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005763 wpa_s->sched_scan_supported = capa.sched_scan_supported;
5764 wpa_s->max_match_sets = capa.max_match_sets;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005765 wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
5766 wpa_s->max_stations = capa.max_stations;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005767 wpa_s->extended_capa = capa.extended_capa;
5768 wpa_s->extended_capa_mask = capa.extended_capa_mask;
5769 wpa_s->extended_capa_len = capa.extended_capa_len;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005770 wpa_s->num_multichan_concurrent =
5771 capa.num_multichan_concurrent;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005772 wpa_s->wmm_ac_supported = capa.wmm_ac_supported;
5773
5774 if (capa.mac_addr_rand_scan_supported)
5775 wpa_s->mac_addr_rand_supported |= MAC_ADDR_RAND_SCAN;
5776 if (wpa_s->sched_scan_supported &&
5777 capa.mac_addr_rand_sched_scan_supported)
5778 wpa_s->mac_addr_rand_supported |=
5779 (MAC_ADDR_RAND_SCHED_SCAN | MAC_ADDR_RAND_PNO);
Hai Shalom74f70d42019-02-11 14:42:39 -08005780
5781 wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION);
5782 if (wpa_s->extended_capa &&
5783 wpa_s->extended_capa_len >= 3 &&
5784 wpa_s->extended_capa[2] & 0x40)
5785 wpa_s->multi_bss_support = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005786 }
5787 if (wpa_s->max_remain_on_chan == 0)
5788 wpa_s->max_remain_on_chan = 1000;
5789
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005790 /*
5791 * Only take p2p_mgmt parameters when P2P Device is supported.
5792 * Doing it here as it determines whether l2_packet_init() will be done
5793 * during wpa_supplicant_driver_init().
5794 */
5795 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
5796 wpa_s->p2p_mgmt = iface->p2p_mgmt;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005797
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005798 if (wpa_s->num_multichan_concurrent == 0)
5799 wpa_s->num_multichan_concurrent = 1;
5800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005801 if (wpa_supplicant_driver_init(wpa_s) < 0)
5802 return -1;
5803
5804#ifdef CONFIG_TDLS
Roshan Pius3a1667e2018-07-03 15:17:14 -07005805 if (!iface->p2p_mgmt && wpa_tdls_init(wpa_s->wpa))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005806 return -1;
5807#endif /* CONFIG_TDLS */
5808
5809 if (wpa_s->conf->country[0] && wpa_s->conf->country[1] &&
5810 wpa_drv_set_country(wpa_s, wpa_s->conf->country)) {
5811 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country");
5812 return -1;
5813 }
5814
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005815#ifdef CONFIG_FST
5816 if (wpa_s->conf->fst_group_id) {
5817 struct fst_iface_cfg cfg;
5818 struct fst_wpa_obj iface_obj;
5819
5820 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
5821 os_strlcpy(cfg.group_id, wpa_s->conf->fst_group_id,
5822 sizeof(cfg.group_id));
5823 cfg.priority = wpa_s->conf->fst_priority;
5824 cfg.llt = wpa_s->conf->fst_llt;
5825
5826 wpa_s->fst = fst_attach(wpa_s->ifname, wpa_s->own_addr,
5827 &iface_obj, &cfg);
5828 if (!wpa_s->fst) {
5829 wpa_msg(wpa_s, MSG_ERROR,
5830 "FST: Cannot attach iface %s to group %s",
5831 wpa_s->ifname, cfg.group_id);
5832 return -1;
5833 }
5834 }
5835#endif /* CONFIG_FST */
5836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005837 if (wpas_wps_init(wpa_s))
5838 return -1;
5839
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005840#ifdef CONFIG_GAS_SERVER
5841 wpa_s->gas_server = gas_server_init(wpa_s, wpas_gas_server_tx);
5842 if (!wpa_s->gas_server) {
5843 wpa_printf(MSG_ERROR, "Failed to initialize GAS server");
5844 return -1;
5845 }
5846#endif /* CONFIG_GAS_SERVER */
5847
5848#ifdef CONFIG_DPP
5849 if (wpas_dpp_init(wpa_s) < 0)
5850 return -1;
5851#endif /* CONFIG_DPP */
5852
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005853 if (wpa_supplicant_init_eapol(wpa_s) < 0)
5854 return -1;
5855 wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
5856
5857 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
5858 if (wpa_s->ctrl_iface == NULL) {
5859 wpa_printf(MSG_ERROR,
5860 "Failed to initialize control interface '%s'.\n"
5861 "You may have another wpa_supplicant process "
5862 "already running or the file was\n"
5863 "left by an unclean termination of wpa_supplicant "
5864 "in which case you will need\n"
5865 "to manually remove this file before starting "
5866 "wpa_supplicant again.\n",
5867 wpa_s->conf->ctrl_interface);
5868 return -1;
5869 }
5870
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005871 wpa_s->gas = gas_query_init(wpa_s);
5872 if (wpa_s->gas == NULL) {
5873 wpa_printf(MSG_ERROR, "Failed to initialize GAS query");
5874 return -1;
5875 }
5876
Roshan Pius3a1667e2018-07-03 15:17:14 -07005877 if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) ||
5878 wpa_s->p2p_mgmt) &&
5879 wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005880 wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
5881 return -1;
5882 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005883
5884 if (wpa_bss_init(wpa_s) < 0)
5885 return -1;
5886
Paul Stewart092955c2017-02-06 09:13:09 -08005887#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
5888#ifdef CONFIG_MESH
5889 dl_list_init(&wpa_s->mesh_external_pmksa_cache);
5890#endif /* CONFIG_MESH */
5891#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
5892
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005893 /*
5894 * Set Wake-on-WLAN triggers, if configured.
5895 * Note: We don't restore/remove the triggers on shutdown (it doesn't
5896 * have effect anyway when the interface is down).
5897 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005898 if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07005899 return -1;
5900
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005901#ifdef CONFIG_EAP_PROXY
5902{
5903 size_t len;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005904 wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
5905 wpa_s->imsi, &len);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005906 if (wpa_s->mnc_len > 0) {
5907 wpa_s->imsi[len] = '\0';
5908 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
5909 wpa_s->imsi, wpa_s->mnc_len);
5910 } else {
5911 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
5912 }
5913}
5914#endif /* CONFIG_EAP_PROXY */
5915
Dmitry Shmidt04949592012-07-19 12:16:46 -07005916 if (pcsc_reader_init(wpa_s) < 0)
5917 return -1;
5918
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005919 if (wpas_init_ext_pw(wpa_s) < 0)
5920 return -1;
5921
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005922 wpas_rrm_reset(wpa_s);
5923
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005924 wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans);
5925
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08005926#ifdef CONFIG_HS20
5927 hs20_init(wpa_s);
5928#endif /* CONFIG_HS20 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005929#ifdef CONFIG_MBO
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005930 if (wpa_s->conf->oce) {
5931 if ((wpa_s->conf->oce & OCE_STA) &&
5932 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
5933 wpa_s->enable_oce = OCE_STA;
5934 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
5935 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
5936 /* TODO: Need to add STA-CFON support */
5937 wpa_printf(MSG_ERROR,
5938 "OCE STA-CFON feature is not yet supported");
5939 }
5940 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005941 wpas_mbo_update_non_pref_chan(wpa_s, wpa_s->conf->non_pref_chan);
5942#endif /* CONFIG_MBO */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08005943
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07005944 wpa_supplicant_set_default_scan_ies(wpa_s);
5945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946 return 0;
5947}
5948
5949
5950static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07005951 int notify, int terminate)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005952{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005953 struct wpa_global *global = wpa_s->global;
5954 struct wpa_supplicant *iface, *prev;
5955
5956 if (wpa_s == wpa_s->parent)
5957 wpas_p2p_group_remove(wpa_s, "*");
5958
5959 iface = global->ifaces;
5960 while (iface) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005961 if (iface->p2pdev == wpa_s)
5962 iface->p2pdev = iface->parent;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005963 if (iface == wpa_s || iface->parent != wpa_s) {
5964 iface = iface->next;
5965 continue;
5966 }
5967 wpa_printf(MSG_DEBUG,
5968 "Remove remaining child interface %s from parent %s",
5969 iface->ifname, wpa_s->ifname);
5970 prev = iface;
5971 iface = iface->next;
5972 wpa_supplicant_remove_iface(global, prev, terminate);
5973 }
5974
Dmitry Shmidtea69e842013-05-13 14:52:28 -07005975 wpa_s->disconnected = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005976 if (wpa_s->drv_priv) {
5977 wpa_supplicant_deauthenticate(wpa_s,
5978 WLAN_REASON_DEAUTH_LEAVING);
5979
5980 wpa_drv_set_countermeasures(wpa_s, 0);
5981 wpa_clear_keys(wpa_s, NULL);
5982 }
5983
5984 wpa_supplicant_cleanup(wpa_s);
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005985 wpas_p2p_deinit_iface(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005986
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005987 wpas_ctrl_radio_work_flush(wpa_s);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08005988 radio_remove_interface(wpa_s);
5989
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005990#ifdef CONFIG_FST
5991 if (wpa_s->fst) {
5992 fst_detach(wpa_s->fst);
5993 wpa_s->fst = NULL;
5994 }
5995 if (wpa_s->received_mb_ies) {
5996 wpabuf_free(wpa_s->received_mb_ies);
5997 wpa_s->received_mb_ies = NULL;
5998 }
5999#endif /* CONFIG_FST */
6000
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006001 if (wpa_s->drv_priv)
6002 wpa_drv_deinit(wpa_s);
Irfan Sheriff622b66d2011-08-03 09:11:49 -07006003
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006004 if (notify)
6005 wpas_notify_iface_removed(wpa_s);
6006
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006007 if (terminate)
6008 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
Irfan Sheriff622b66d2011-08-03 09:11:49 -07006009
6010 if (wpa_s->ctrl_iface) {
6011 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
6012 wpa_s->ctrl_iface = NULL;
6013 }
6014
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006015#ifdef CONFIG_MESH
6016 if (wpa_s->ifmsh) {
6017 wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh);
6018 wpa_s->ifmsh = NULL;
6019 }
6020#endif /* CONFIG_MESH */
6021
Irfan Sheriff622b66d2011-08-03 09:11:49 -07006022 if (wpa_s->conf != NULL) {
Irfan Sheriff622b66d2011-08-03 09:11:49 -07006023 wpa_config_free(wpa_s->conf);
6024 wpa_s->conf = NULL;
6025 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006026
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07006027 os_free(wpa_s->ssids_from_scan_req);
6028
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006029 os_free(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006030}
6031
6032
Dmitry Shmidte4663042016-04-04 10:07:49 -07006033#ifdef CONFIG_MATCH_IFACE
6034
6035/**
6036 * wpa_supplicant_match_iface - Match an interface description to a name
6037 * @global: Pointer to global data from wpa_supplicant_init()
6038 * @ifname: Name of the interface to match
6039 * Returns: Pointer to the created interface description or %NULL on failure
6040 */
6041struct wpa_interface * wpa_supplicant_match_iface(struct wpa_global *global,
6042 const char *ifname)
6043{
6044 int i;
6045 struct wpa_interface *iface, *miface;
6046
6047 for (i = 0; i < global->params.match_iface_count; i++) {
6048 miface = &global->params.match_ifaces[i];
6049 if (!miface->ifname ||
6050 fnmatch(miface->ifname, ifname, 0) == 0) {
6051 iface = os_zalloc(sizeof(*iface));
6052 if (!iface)
6053 return NULL;
6054 *iface = *miface;
6055 iface->ifname = ifname;
6056 return iface;
6057 }
6058 }
6059
6060 return NULL;
6061}
6062
6063
6064/**
6065 * wpa_supplicant_match_existing - Match existing interfaces
6066 * @global: Pointer to global data from wpa_supplicant_init()
6067 * Returns: 0 on success, -1 on failure
6068 */
6069static int wpa_supplicant_match_existing(struct wpa_global *global)
6070{
6071 struct if_nameindex *ifi, *ifp;
6072 struct wpa_supplicant *wpa_s;
6073 struct wpa_interface *iface;
6074
6075 ifp = if_nameindex();
6076 if (!ifp) {
6077 wpa_printf(MSG_ERROR, "if_nameindex: %s", strerror(errno));
6078 return -1;
6079 }
6080
6081 for (ifi = ifp; ifi->if_name; ifi++) {
6082 wpa_s = wpa_supplicant_get_iface(global, ifi->if_name);
6083 if (wpa_s)
6084 continue;
6085 iface = wpa_supplicant_match_iface(global, ifi->if_name);
6086 if (iface) {
6087 wpa_s = wpa_supplicant_add_iface(global, iface, NULL);
6088 os_free(iface);
6089 if (wpa_s)
6090 wpa_s->matched = 1;
6091 }
6092 }
6093
6094 if_freenameindex(ifp);
6095 return 0;
6096}
6097
6098#endif /* CONFIG_MATCH_IFACE */
6099
6100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006101/**
6102 * wpa_supplicant_add_iface - Add a new network interface
6103 * @global: Pointer to global data from wpa_supplicant_init()
6104 * @iface: Interface configuration options
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006105 * @parent: Parent interface or %NULL to assign new interface as parent
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106 * Returns: Pointer to the created interface or %NULL on failure
6107 *
6108 * This function is used to add new network interfaces for %wpa_supplicant.
6109 * This can be called before wpa_supplicant_run() to add interfaces before the
6110 * main event loop has been started. In addition, new interfaces can be added
6111 * dynamically while %wpa_supplicant is already running. This could happen,
6112 * e.g., when a hotplug network adapter is inserted.
6113 */
6114struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006115 struct wpa_interface *iface,
6116 struct wpa_supplicant *parent)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006117{
6118 struct wpa_supplicant *wpa_s;
6119 struct wpa_interface t_iface;
6120 struct wpa_ssid *ssid;
6121
6122 if (global == NULL || iface == NULL)
6123 return NULL;
6124
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006125 wpa_s = wpa_supplicant_alloc(parent);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006126 if (wpa_s == NULL)
6127 return NULL;
6128
6129 wpa_s->global = global;
6130
6131 t_iface = *iface;
6132 if (global->params.override_driver) {
6133 wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
6134 "('%s' -> '%s')",
6135 iface->driver, global->params.override_driver);
6136 t_iface.driver = global->params.override_driver;
6137 }
6138 if (global->params.override_ctrl_interface) {
6139 wpa_printf(MSG_DEBUG, "Override interface parameter: "
6140 "ctrl_interface ('%s' -> '%s')",
6141 iface->ctrl_interface,
6142 global->params.override_ctrl_interface);
6143 t_iface.ctrl_interface =
6144 global->params.override_ctrl_interface;
6145 }
6146 if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
6147 wpa_printf(MSG_DEBUG, "Failed to add interface %s",
6148 iface->ifname);
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006149 wpa_supplicant_deinit_iface(wpa_s, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006150 return NULL;
6151 }
6152
Roshan Piusd6d8b8d2016-11-08 14:45:26 -08006153 /* Notify the control interfaces about new iface */
6154 if (wpas_notify_iface_added(wpa_s)) {
6155 wpa_supplicant_deinit_iface(wpa_s, 1, 0);
6156 return NULL;
6157 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006158
Roshan Piusd6d8b8d2016-11-08 14:45:26 -08006159 /* Notify the control interfaces about new networks for non p2p mgmt
6160 * ifaces. */
6161 if (iface->p2p_mgmt == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006162 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
6163 wpas_notify_network_added(wpa_s, ssid);
6164 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006165
6166 wpa_s->next = global->ifaces;
6167 global->ifaces = wpa_s;
6168
6169 wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006170 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006171
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006172#ifdef CONFIG_P2P
6173 if (wpa_s->global->p2p == NULL &&
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006174 !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006175 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006176 wpas_p2p_add_p2pdev_interface(
6177 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006178 wpa_printf(MSG_INFO,
6179 "P2P: Failed to enable P2P Device interface");
6180 /* Try to continue without. P2P will be disabled. */
6181 }
6182#endif /* CONFIG_P2P */
6183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006184 return wpa_s;
6185}
6186
6187
6188/**
6189 * wpa_supplicant_remove_iface - Remove a network interface
6190 * @global: Pointer to global data from wpa_supplicant_init()
6191 * @wpa_s: Pointer to the network interface to be removed
6192 * Returns: 0 if interface was removed, -1 if interface was not found
6193 *
6194 * This function can be used to dynamically remove network interfaces from
6195 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
6196 * addition, this function is used to remove all remaining interfaces when
6197 * %wpa_supplicant is terminated.
6198 */
6199int wpa_supplicant_remove_iface(struct wpa_global *global,
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006200 struct wpa_supplicant *wpa_s,
6201 int terminate)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006202{
6203 struct wpa_supplicant *prev;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006204#ifdef CONFIG_MESH
6205 unsigned int mesh_if_created = wpa_s->mesh_if_created;
6206 char *ifname = NULL;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006207 struct wpa_supplicant *parent = wpa_s->parent;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006208#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006209
6210 /* Remove interface from the global list of interfaces */
6211 prev = global->ifaces;
6212 if (prev == wpa_s) {
6213 global->ifaces = wpa_s->next;
6214 } else {
6215 while (prev && prev->next != wpa_s)
6216 prev = prev->next;
6217 if (prev == NULL)
6218 return -1;
6219 prev->next = wpa_s->next;
6220 }
6221
6222 wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
6223
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006224#ifdef CONFIG_MESH
6225 if (mesh_if_created) {
6226 ifname = os_strdup(wpa_s->ifname);
6227 if (ifname == NULL) {
6228 wpa_dbg(wpa_s, MSG_ERROR,
6229 "mesh: Failed to malloc ifname");
6230 return -1;
6231 }
6232 }
6233#endif /* CONFIG_MESH */
6234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006235 if (global->p2p_group_formation == wpa_s)
6236 global->p2p_group_formation = NULL;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07006237 if (global->p2p_invite_group == wpa_s)
6238 global->p2p_invite_group = NULL;
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006239 wpa_supplicant_deinit_iface(wpa_s, 1, terminate);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006240
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006241#ifdef CONFIG_MESH
6242 if (mesh_if_created) {
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006243 wpa_drv_if_remove(parent, WPA_IF_MESH, ifname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006244 os_free(ifname);
6245 }
6246#endif /* CONFIG_MESH */
6247
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006248 return 0;
6249}
6250
6251
6252/**
6253 * wpa_supplicant_get_eap_mode - Get the current EAP mode
6254 * @wpa_s: Pointer to the network interface
6255 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
6256 */
6257const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s)
6258{
6259 const char *eapol_method;
6260
6261 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 &&
6262 wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
6263 return "NO-EAP";
6264 }
6265
6266 eapol_method = eapol_sm_get_method_name(wpa_s->eapol);
6267 if (eapol_method == NULL)
6268 return "UNKNOWN-EAP";
6269
6270 return eapol_method;
6271}
6272
6273
6274/**
6275 * wpa_supplicant_get_iface - Get a new network interface
6276 * @global: Pointer to global data from wpa_supplicant_init()
6277 * @ifname: Interface name
6278 * Returns: Pointer to the interface or %NULL if not found
6279 */
6280struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
6281 const char *ifname)
6282{
6283 struct wpa_supplicant *wpa_s;
6284
6285 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6286 if (os_strcmp(wpa_s->ifname, ifname) == 0)
6287 return wpa_s;
6288 }
6289 return NULL;
6290}
6291
6292
6293#ifndef CONFIG_NO_WPA_MSG
6294static const char * wpa_supplicant_msg_ifname_cb(void *ctx)
6295{
6296 struct wpa_supplicant *wpa_s = ctx;
6297 if (wpa_s == NULL)
6298 return NULL;
6299 return wpa_s->ifname;
6300}
6301#endif /* CONFIG_NO_WPA_MSG */
6302
6303
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006304#ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL
6305#define WPA_SUPPLICANT_CLEANUP_INTERVAL 10
6306#endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */
6307
6308/* Periodic cleanup tasks */
6309static void wpas_periodic(void *eloop_ctx, void *timeout_ctx)
6310{
6311 struct wpa_global *global = eloop_ctx;
6312 struct wpa_supplicant *wpa_s;
6313
6314 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
6315 wpas_periodic, global, NULL);
6316
6317#ifdef CONFIG_P2P
6318 if (global->p2p)
6319 p2p_expire_peers(global->p2p);
6320#endif /* CONFIG_P2P */
6321
6322 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6323 wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age);
6324#ifdef CONFIG_AP
6325 ap_periodic(wpa_s);
6326#endif /* CONFIG_AP */
6327 }
6328}
6329
6330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006331/**
6332 * wpa_supplicant_init - Initialize %wpa_supplicant
6333 * @params: Parameters for %wpa_supplicant
6334 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
6335 *
6336 * This function is used to initialize %wpa_supplicant. After successful
6337 * initialization, the returned data pointer can be used to add and remove
6338 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
6339 */
6340struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
6341{
6342 struct wpa_global *global;
6343 int ret, i;
6344
6345 if (params == NULL)
6346 return NULL;
6347
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006348#ifdef CONFIG_DRIVER_NDIS
6349 {
6350 void driver_ndis_init_ops(void);
6351 driver_ndis_init_ops();
6352 }
6353#endif /* CONFIG_DRIVER_NDIS */
6354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006355#ifndef CONFIG_NO_WPA_MSG
6356 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
6357#endif /* CONFIG_NO_WPA_MSG */
6358
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006359 if (params->wpa_debug_file_path)
6360 wpa_debug_open_file(params->wpa_debug_file_path);
6361 else
6362 wpa_debug_setup_stdout();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006363 if (params->wpa_debug_syslog)
6364 wpa_debug_open_syslog();
Dmitry Shmidt04949592012-07-19 12:16:46 -07006365 if (params->wpa_debug_tracing) {
6366 ret = wpa_debug_open_linux_tracing();
6367 if (ret) {
6368 wpa_printf(MSG_ERROR,
6369 "Failed to enable trace logging");
6370 return NULL;
6371 }
6372 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006373
6374 ret = eap_register_methods();
6375 if (ret) {
6376 wpa_printf(MSG_ERROR, "Failed to register EAP methods");
6377 if (ret == -2)
6378 wpa_printf(MSG_ERROR, "Two or more EAP methods used "
6379 "the same EAP type.");
6380 return NULL;
6381 }
6382
6383 global = os_zalloc(sizeof(*global));
6384 if (global == NULL)
6385 return NULL;
6386 dl_list_init(&global->p2p_srv_bonjour);
6387 dl_list_init(&global->p2p_srv_upnp);
6388 global->params.daemonize = params->daemonize;
6389 global->params.wait_for_monitor = params->wait_for_monitor;
6390 global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
6391 if (params->pid_file)
6392 global->params.pid_file = os_strdup(params->pid_file);
6393 if (params->ctrl_interface)
6394 global->params.ctrl_interface =
6395 os_strdup(params->ctrl_interface);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006396 if (params->ctrl_interface_group)
6397 global->params.ctrl_interface_group =
6398 os_strdup(params->ctrl_interface_group);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006399 if (params->override_driver)
6400 global->params.override_driver =
6401 os_strdup(params->override_driver);
6402 if (params->override_ctrl_interface)
6403 global->params.override_ctrl_interface =
6404 os_strdup(params->override_ctrl_interface);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006405#ifdef CONFIG_MATCH_IFACE
6406 global->params.match_iface_count = params->match_iface_count;
6407 if (params->match_iface_count) {
6408 global->params.match_ifaces =
6409 os_calloc(params->match_iface_count,
6410 sizeof(struct wpa_interface));
6411 os_memcpy(global->params.match_ifaces,
6412 params->match_ifaces,
6413 params->match_iface_count *
6414 sizeof(struct wpa_interface));
6415 }
6416#endif /* CONFIG_MATCH_IFACE */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006417#ifdef CONFIG_P2P
Sasha Levitskiydaa60e52015-08-05 13:02:59 -07006418 if (params->conf_p2p_dev)
6419 global->params.conf_p2p_dev =
6420 os_strdup(params->conf_p2p_dev);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006421#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006422 wpa_debug_level = global->params.wpa_debug_level =
6423 params->wpa_debug_level;
6424 wpa_debug_show_keys = global->params.wpa_debug_show_keys =
6425 params->wpa_debug_show_keys;
6426 wpa_debug_timestamp = global->params.wpa_debug_timestamp =
6427 params->wpa_debug_timestamp;
6428
6429 wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR);
6430
6431 if (eloop_init()) {
6432 wpa_printf(MSG_ERROR, "Failed to initialize event loop");
6433 wpa_supplicant_deinit(global);
6434 return NULL;
6435 }
6436
Jouni Malinen75ecf522011-06-27 15:19:46 -07006437 random_init(params->entropy_file);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006438
6439 global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
6440 if (global->ctrl_iface == NULL) {
6441 wpa_supplicant_deinit(global);
6442 return NULL;
6443 }
6444
6445 if (wpas_notify_supplicant_initialized(global)) {
6446 wpa_supplicant_deinit(global);
6447 return NULL;
6448 }
6449
6450 for (i = 0; wpa_drivers[i]; i++)
6451 global->drv_count++;
6452 if (global->drv_count == 0) {
6453 wpa_printf(MSG_ERROR, "No drivers enabled");
6454 wpa_supplicant_deinit(global);
6455 return NULL;
6456 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006457 global->drv_priv = os_calloc(global->drv_count, sizeof(void *));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006458 if (global->drv_priv == NULL) {
6459 wpa_supplicant_deinit(global);
6460 return NULL;
6461 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006462
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006463#ifdef CONFIG_WIFI_DISPLAY
6464 if (wifi_display_init(global) < 0) {
6465 wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display");
6466 wpa_supplicant_deinit(global);
6467 return NULL;
6468 }
6469#endif /* CONFIG_WIFI_DISPLAY */
6470
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006471 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
6472 wpas_periodic, global, NULL);
6473
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006474 return global;
6475}
6476
6477
6478/**
6479 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
6480 * @global: Pointer to global data from wpa_supplicant_init()
6481 * Returns: 0 after successful event loop run, -1 on failure
6482 *
6483 * This function starts the main event loop and continues running as long as
6484 * there are any remaining events. In most cases, this function is running as
6485 * long as the %wpa_supplicant process in still in use.
6486 */
6487int wpa_supplicant_run(struct wpa_global *global)
6488{
6489 struct wpa_supplicant *wpa_s;
6490
6491 if (global->params.daemonize &&
Dmitry Shmidtb97e4282016-02-08 10:16:07 -08006492 (wpa_supplicant_daemon(global->params.pid_file) ||
6493 eloop_sock_requeue()))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006494 return -1;
6495
Dmitry Shmidte4663042016-04-04 10:07:49 -07006496#ifdef CONFIG_MATCH_IFACE
6497 if (wpa_supplicant_match_existing(global))
6498 return -1;
6499#endif
6500
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006501 if (global->params.wait_for_monitor) {
6502 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08006503 if (wpa_s->ctrl_iface && !wpa_s->p2p_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006504 wpa_supplicant_ctrl_iface_wait(
6505 wpa_s->ctrl_iface);
6506 }
6507
6508 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
6509 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
6510
6511 eloop_run();
6512
6513 return 0;
6514}
6515
6516
6517/**
6518 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
6519 * @global: Pointer to global data from wpa_supplicant_init()
6520 *
6521 * This function is called to deinitialize %wpa_supplicant and to free all
6522 * allocated resources. Remaining network interfaces will also be removed.
6523 */
6524void wpa_supplicant_deinit(struct wpa_global *global)
6525{
6526 int i;
6527
6528 if (global == NULL)
6529 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006530
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006531 eloop_cancel_timeout(wpas_periodic, global, NULL);
6532
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006533#ifdef CONFIG_WIFI_DISPLAY
6534 wifi_display_deinit(global);
6535#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006536
6537 while (global->ifaces)
Dmitry Shmidte15c7b52011-08-03 15:04:35 -07006538 wpa_supplicant_remove_iface(global, global->ifaces, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006539
6540 if (global->ctrl_iface)
6541 wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
6542
6543 wpas_notify_supplicant_deinitialized(global);
6544
6545 eap_peer_unregister_methods();
6546#ifdef CONFIG_AP
6547 eap_server_unregister_methods();
6548#endif /* CONFIG_AP */
6549
6550 for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
6551 if (!global->drv_priv[i])
6552 continue;
6553 wpa_drivers[i]->global_deinit(global->drv_priv[i]);
6554 }
6555 os_free(global->drv_priv);
6556
6557 random_deinit();
6558
6559 eloop_destroy();
6560
6561 if (global->params.pid_file) {
6562 os_daemonize_terminate(global->params.pid_file);
6563 os_free(global->params.pid_file);
6564 }
6565 os_free(global->params.ctrl_interface);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07006566 os_free(global->params.ctrl_interface_group);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006567 os_free(global->params.override_driver);
6568 os_free(global->params.override_ctrl_interface);
Dmitry Shmidte4663042016-04-04 10:07:49 -07006569#ifdef CONFIG_MATCH_IFACE
6570 os_free(global->params.match_ifaces);
6571#endif /* CONFIG_MATCH_IFACE */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006572#ifdef CONFIG_P2P
Sasha Levitskiydaa60e52015-08-05 13:02:59 -07006573 os_free(global->params.conf_p2p_dev);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006574#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006575
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006576 os_free(global->p2p_disallow_freq.range);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006577 os_free(global->p2p_go_avoid_freq.range);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006578 os_free(global->add_psk);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006580 os_free(global);
6581 wpa_debug_close_syslog();
6582 wpa_debug_close_file();
Dmitry Shmidt04949592012-07-19 12:16:46 -07006583 wpa_debug_close_linux_tracing();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006584}
6585
6586
6587void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s)
6588{
6589 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
6590 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
6591 char country[3];
6592 country[0] = wpa_s->conf->country[0];
6593 country[1] = wpa_s->conf->country[1];
6594 country[2] = '\0';
6595 if (wpa_drv_set_country(wpa_s, country) < 0) {
6596 wpa_printf(MSG_ERROR, "Failed to set country code "
6597 "'%s'", country);
6598 }
6599 }
6600
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006601 if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND)
6602 wpas_init_ext_pw(wpa_s);
6603
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006604 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SCHED_SCAN_PLANS)
6605 wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans);
6606
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006607 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WOWLAN_TRIGGERS) {
6608 struct wpa_driver_capa capa;
6609 int res = wpa_drv_get_capa(wpa_s, &capa);
6610
6611 if (res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0)
6612 wpa_printf(MSG_ERROR,
6613 "Failed to update wowlan_triggers to '%s'",
6614 wpa_s->conf->wowlan_triggers);
6615 }
6616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006617#ifdef CONFIG_WPS
6618 wpas_wps_update_config(wpa_s);
6619#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006620 wpas_p2p_update_config(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006621 wpa_s->conf->changed_parameters = 0;
6622}
6623
6624
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006625void add_freq(int *freqs, int *num_freqs, int freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006626{
6627 int i;
6628
6629 for (i = 0; i < *num_freqs; i++) {
6630 if (freqs[i] == freq)
6631 return;
6632 }
6633
6634 freqs[*num_freqs] = freq;
6635 (*num_freqs)++;
6636}
6637
6638
6639static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s)
6640{
6641 struct wpa_bss *bss, *cbss;
6642 const int max_freqs = 10;
6643 int *freqs;
6644 int num_freqs = 0;
6645
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006646 freqs = os_calloc(max_freqs + 1, sizeof(int));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006647 if (freqs == NULL)
6648 return NULL;
6649
6650 cbss = wpa_s->current_bss;
6651
6652 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
6653 if (bss == cbss)
6654 continue;
6655 if (bss->ssid_len == cbss->ssid_len &&
6656 os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 &&
6657 wpa_blacklist_get(wpa_s, bss->bssid) == NULL) {
6658 add_freq(freqs, &num_freqs, bss->freq);
6659 if (num_freqs == max_freqs)
6660 break;
6661 }
6662 }
6663
6664 if (num_freqs == 0) {
6665 os_free(freqs);
6666 freqs = NULL;
6667 }
6668
6669 return freqs;
6670}
6671
6672
6673void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid)
6674{
6675 int timeout;
6676 int count;
6677 int *freqs = NULL;
6678
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006679 wpas_connect_work_done(wpa_s);
6680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006681 /*
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006682 * Remove possible authentication timeout since the connection failed.
6683 */
6684 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
6685
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006686 /*
6687 * There is no point in blacklisting the AP if this event is
6688 * generated based on local request to disconnect.
6689 */
6690 if (wpa_s->own_disconnect_req) {
6691 wpa_s->own_disconnect_req = 0;
6692 wpa_dbg(wpa_s, MSG_DEBUG,
6693 "Ignore connection failure due to local request to disconnect");
6694 return;
6695 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006696 if (wpa_s->disconnected) {
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006697 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure "
6698 "indication since interface has been put into "
6699 "disconnected state");
6700 return;
6701 }
Roshan Piusb1ae0fe2019-02-15 08:05:38 -08006702 if (wpa_s->auto_reconnect_disabled) {
6703 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure "
6704 "indication since auto connect is disabled");
6705 return;
6706 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006707
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006708 /*
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006709 * Add the failed BSSID into the blacklist and speed up next scan
6710 * attempt if there could be other APs that could accept association.
6711 * The current blacklist count indicates how many times we have tried
6712 * connecting to this AP and multiple attempts mean that other APs are
6713 * either not available or has already been tried, so that we can start
6714 * increasing the delay here to avoid constant scanning.
6715 */
6716 count = wpa_blacklist_add(wpa_s, bssid);
6717 if (count == 1 && wpa_s->current_bss) {
6718 /*
6719 * This BSS was not in the blacklist before. If there is
6720 * another BSS available for the same ESS, we should try that
6721 * next. Otherwise, we may as well try this one once more
6722 * before allowing other, likely worse, ESSes to be considered.
6723 */
6724 freqs = get_bss_freqs_in_ess(wpa_s);
6725 if (freqs) {
6726 wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS "
6727 "has been seen; try it next");
6728 wpa_blacklist_add(wpa_s, bssid);
6729 /*
6730 * On the next scan, go through only the known channels
6731 * used in this ESS based on previous scans to speed up
6732 * common load balancing use case.
6733 */
6734 os_free(wpa_s->next_scan_freqs);
6735 wpa_s->next_scan_freqs = freqs;
6736 }
6737 }
6738
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006739 /*
6740 * Add previous failure count in case the temporary blacklist was
6741 * cleared due to no other BSSes being available.
6742 */
6743 count += wpa_s->extra_blacklist_count;
6744
Dmitry Shmidt4b060592013-04-29 16:42:49 -07006745 if (count > 3 && wpa_s->current_ssid) {
6746 wpa_printf(MSG_DEBUG, "Continuous association failures - "
6747 "consider temporary network disabling");
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006748 wpas_auth_failed(wpa_s, "CONN_FAILED");
Dmitry Shmidt4b060592013-04-29 16:42:49 -07006749 }
6750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006751 switch (count) {
6752 case 1:
6753 timeout = 100;
6754 break;
6755 case 2:
6756 timeout = 500;
6757 break;
6758 case 3:
6759 timeout = 1000;
6760 break;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006761 case 4:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006762 timeout = 5000;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006763 break;
6764 default:
6765 timeout = 10000;
6766 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006767 }
6768
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006769 wpa_dbg(wpa_s, MSG_DEBUG, "Blacklist count %d --> request scan in %d "
6770 "ms", count, timeout);
6771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006772 /*
6773 * TODO: if more than one possible AP is available in scan results,
6774 * could try the other ones before requesting a new scan.
6775 */
Hai Shalom021b0b52019-04-10 11:17:58 -07006776
6777 /* speed up the connection attempt with normal scan */
6778 wpa_s->normal_scans = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006779 wpa_supplicant_req_scan(wpa_s, timeout / 1000,
6780 1000 * (timeout % 1000));
6781}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006782
6783
Hai Shalomce48b4a2018-09-05 11:41:35 -07006784#ifdef CONFIG_FILS
6785void fils_connection_failure(struct wpa_supplicant *wpa_s)
6786{
6787 struct wpa_ssid *ssid = wpa_s->current_ssid;
6788 const u8 *realm, *username, *rrk;
6789 size_t realm_len, username_len, rrk_len;
6790 u16 next_seq_num;
6791
6792 if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt) ||
6793 eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap,
6794 &username, &username_len,
6795 &realm, &realm_len, &next_seq_num,
6796 &rrk, &rrk_len) != 0 ||
6797 !realm)
6798 return;
6799
6800 wpa_hexdump_ascii(MSG_DEBUG,
6801 "FILS: Store last connection failure realm",
6802 realm, realm_len);
6803 os_free(wpa_s->last_con_fail_realm);
6804 wpa_s->last_con_fail_realm = os_malloc(realm_len);
6805 if (wpa_s->last_con_fail_realm) {
6806 wpa_s->last_con_fail_realm_len = realm_len;
6807 os_memcpy(wpa_s->last_con_fail_realm, realm, realm_len);
6808 }
6809}
6810#endif /* CONFIG_FILS */
6811
6812
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006813int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s)
6814{
6815 return wpa_s->conf->ap_scan == 2 ||
6816 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION);
6817}
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006818
Dmitry Shmidt04949592012-07-19 12:16:46 -07006819
Roshan Pius57ffbcf2016-09-27 09:12:46 -07006820#if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW) || defined (CONFIG_CTRL_IFACE_HIDL)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006821int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
6822 struct wpa_ssid *ssid,
6823 const char *field,
6824 const char *value)
6825{
6826#ifdef IEEE8021X_EAPOL
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006827 enum wpa_ctrl_req_type rtype;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006828
6829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field);
6830 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value",
6831 (const u8 *) value, os_strlen(value));
6832
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006833 rtype = wpa_supplicant_ctrl_req_from_string(field);
pkanwareb9203e2017-10-26 16:00:35 -07006834 return wpa_supplicant_ctrl_rsp_handle(wpa_s, ssid, rtype, value, strlen(value));
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006835#else /* IEEE8021X_EAPOL */
6836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included");
6837 return -1;
6838#endif /* IEEE8021X_EAPOL */
6839}
6840
6841int wpa_supplicant_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
6842 struct wpa_ssid *ssid,
6843 enum wpa_ctrl_req_type rtype,
pkanwareb9203e2017-10-26 16:00:35 -07006844 const char *value, int value_len)
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006845{
6846#ifdef IEEE8021X_EAPOL
6847 struct eap_peer_config *eap = &ssid->eap;
Ecco Park00a7b212018-01-26 13:44:44 -08006848 char *identity, *imsi_identity;
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006849
6850 switch (rtype) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07006851 case WPA_CTRL_REQ_EAP_IDENTITY:
6852 os_free(eap->identity);
Ecco Park00a7b212018-01-26 13:44:44 -08006853 os_free(eap->imsi_identity);
6854 if (value == NULL)
6855 return -1;
6856 identity = os_strchr(value, ':');
6857 if (identity == NULL) {
6858 /* plain identity */
6859 eap->identity = (u8 *)os_strdup(value);
6860 eap->identity_len = os_strlen(value);
6861 } else {
6862 /* have both plain identity and encrypted identity */
6863 imsi_identity = value;
6864 *identity++ = '\0';
6865 /* plain identity */
6866 eap->imsi_identity = (u8 *)dup_binstr(imsi_identity, strlen(imsi_identity));
6867 eap->imsi_identity_len = strlen(imsi_identity);
6868 /* encrypted identity */
6869 eap->identity = (u8 *)dup_binstr(identity,
6870 value_len - strlen(imsi_identity) - 1);
6871 eap->identity_len = value_len - strlen(imsi_identity) - 1;
6872 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006873 eap->pending_req_identity = 0;
6874 if (ssid == wpa_s->current_ssid)
6875 wpa_s->reassociate = 1;
6876 break;
6877 case WPA_CTRL_REQ_EAP_PASSWORD:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006878 bin_clear_free(eap->password, eap->password_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006879 eap->password = (u8 *) os_strdup(value);
pkanwareb9203e2017-10-26 16:00:35 -07006880 eap->password_len = value_len;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006881 eap->pending_req_password = 0;
6882 if (ssid == wpa_s->current_ssid)
6883 wpa_s->reassociate = 1;
6884 break;
6885 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006886 bin_clear_free(eap->new_password, eap->new_password_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006887 eap->new_password = (u8 *) os_strdup(value);
pkanwareb9203e2017-10-26 16:00:35 -07006888 eap->new_password_len = value_len;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006889 eap->pending_req_new_password = 0;
6890 if (ssid == wpa_s->current_ssid)
6891 wpa_s->reassociate = 1;
6892 break;
6893 case WPA_CTRL_REQ_EAP_PIN:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006894 str_clear_free(eap->pin);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006895 eap->pin = os_strdup(value);
6896 eap->pending_req_pin = 0;
6897 if (ssid == wpa_s->current_ssid)
6898 wpa_s->reassociate = 1;
6899 break;
6900 case WPA_CTRL_REQ_EAP_OTP:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006901 bin_clear_free(eap->otp, eap->otp_len);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006902 eap->otp = (u8 *) os_strdup(value);
pkanwareb9203e2017-10-26 16:00:35 -07006903 eap->otp_len = value_len;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006904 os_free(eap->pending_req_otp);
6905 eap->pending_req_otp = NULL;
6906 eap->pending_req_otp_len = 0;
6907 break;
6908 case WPA_CTRL_REQ_EAP_PASSPHRASE:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006909 str_clear_free(eap->private_key_passwd);
6910 eap->private_key_passwd = os_strdup(value);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006911 eap->pending_req_passphrase = 0;
6912 if (ssid == wpa_s->current_ssid)
6913 wpa_s->reassociate = 1;
6914 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07006915 case WPA_CTRL_REQ_SIM:
Dmitry Shmidtc2817022014-07-02 10:32:10 -07006916 str_clear_free(eap->external_sim_resp);
Dmitry Shmidt051af732013-10-22 13:52:46 -07006917 eap->external_sim_resp = os_strdup(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006918 eap->pending_req_sim = 0;
Dmitry Shmidt051af732013-10-22 13:52:46 -07006919 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07006920 case WPA_CTRL_REQ_PSK_PASSPHRASE:
6921 if (wpa_config_set(ssid, "psk", value, 0) < 0)
6922 return -1;
6923 ssid->mem_only_psk = 1;
6924 if (ssid->passphrase)
6925 wpa_config_update_psk(ssid);
6926 if (wpa_s->wpa_state == WPA_SCANNING && !wpa_s->scanning)
6927 wpa_supplicant_req_scan(wpa_s, 0, 0);
6928 break;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08006929 case WPA_CTRL_REQ_EXT_CERT_CHECK:
6930 if (eap->pending_ext_cert_check != PENDING_CHECK)
6931 return -1;
6932 if (os_strcmp(value, "good") == 0)
6933 eap->pending_ext_cert_check = EXT_CERT_CHECK_GOOD;
6934 else if (os_strcmp(value, "bad") == 0)
6935 eap->pending_ext_cert_check = EXT_CERT_CHECK_BAD;
6936 else
6937 return -1;
6938 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006939 default:
Roshan Pius71a6b8a2016-08-17 13:04:08 -07006940 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown type %d", rtype);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006941 return -1;
6942 }
6943
6944 return 0;
6945#else /* IEEE8021X_EAPOL */
6946 wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included");
6947 return -1;
6948#endif /* IEEE8021X_EAPOL */
6949}
Roshan Pius57ffbcf2016-09-27 09:12:46 -07006950#endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW || CONFIG_CTRL_IFACE_HIDL */
Dmitry Shmidt04949592012-07-19 12:16:46 -07006951
6952
6953int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
6954{
6955 int i;
6956 unsigned int drv_enc;
6957
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006958 if (wpa_s->p2p_mgmt)
6959 return 1; /* no normal network profiles on p2p_mgmt interface */
6960
Dmitry Shmidt04949592012-07-19 12:16:46 -07006961 if (ssid == NULL)
6962 return 1;
6963
6964 if (ssid->disabled)
6965 return 1;
6966
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006967 if (wpa_s->drv_capa_known)
Dmitry Shmidt04949592012-07-19 12:16:46 -07006968 drv_enc = wpa_s->drv_enc;
6969 else
6970 drv_enc = (unsigned int) -1;
6971
6972 for (i = 0; i < NUM_WEP_KEYS; i++) {
6973 size_t len = ssid->wep_key_len[i];
6974 if (len == 0)
6975 continue;
6976 if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40))
6977 continue;
6978 if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104))
6979 continue;
6980 if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128))
6981 continue;
6982 return 1; /* invalid WEP key */
6983 }
6984
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006985 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set &&
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07006986 (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006987 !(wpa_key_mgmt_sae(ssid->key_mgmt) && ssid->sae_password) &&
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07006988 !ssid->mem_only_psk)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006989 return 1;
6990
Dmitry Shmidt04949592012-07-19 12:16:46 -07006991 return 0;
6992}
6993
6994
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006995int wpas_get_ssid_pmf(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
6996{
6997#ifdef CONFIG_IEEE80211W
6998 if (ssid == NULL || ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) {
6999 if (wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_OPTIONAL &&
7000 !(wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)) {
7001 /*
7002 * Driver does not support BIP -- ignore pmf=1 default
7003 * since the connection with PMF would fail and the
7004 * configuration does not require PMF to be enabled.
7005 */
7006 return NO_MGMT_FRAME_PROTECTION;
7007 }
7008
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007009 if (ssid &&
7010 (ssid->key_mgmt &
7011 ~(WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPS |
7012 WPA_KEY_MGMT_IEEE8021X_NO_WPA)) == 0) {
7013 /*
7014 * Do not use the default PMF value for non-RSN networks
7015 * since PMF is available only with RSN and pmf=2
7016 * configuration would otherwise prevent connections to
7017 * all open networks.
7018 */
7019 return NO_MGMT_FRAME_PROTECTION;
7020 }
7021
Dmitry Shmidt807291d2015-01-27 13:40:23 -08007022 return wpa_s->conf->pmf;
7023 }
7024
7025 return ssid->ieee80211w;
7026#else /* CONFIG_IEEE80211W */
7027 return NO_MGMT_FRAME_PROTECTION;
7028#endif /* CONFIG_IEEE80211W */
7029}
7030
7031
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007032int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007033{
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007034 if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007035 return 1;
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007036 if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA)
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007037 return 0;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007038 return -1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007039}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007040
7041
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07007042void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007043{
7044 struct wpa_ssid *ssid = wpa_s->current_ssid;
7045 int dur;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007046 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007047
7048 if (ssid == NULL) {
7049 wpa_printf(MSG_DEBUG, "Authentication failure but no known "
7050 "SSID block");
7051 return;
7052 }
7053
7054 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS)
7055 return;
7056
7057 ssid->auth_failures++;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07007058
7059#ifdef CONFIG_P2P
7060 if (ssid->p2p_group &&
7061 (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) {
7062 /*
7063 * Skip the wait time since there is a short timeout on the
7064 * connection to a P2P group.
7065 */
7066 return;
7067 }
7068#endif /* CONFIG_P2P */
7069
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007070 if (ssid->auth_failures > 50)
7071 dur = 300;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007072 else if (ssid->auth_failures > 10)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007073 dur = 120;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007074 else if (ssid->auth_failures > 5)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007075 dur = 90;
7076 else if (ssid->auth_failures > 3)
7077 dur = 60;
7078 else if (ssid->auth_failures > 2)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007079 dur = 30;
7080 else if (ssid->auth_failures > 1)
7081 dur = 20;
7082 else
7083 dur = 10;
7084
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007085 if (ssid->auth_failures > 1 &&
7086 wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt))
7087 dur += os_random() % (ssid->auth_failures * 10);
7088
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007089 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007090 if (now.sec + dur <= ssid->disabled_until.sec)
7091 return;
7092
7093 ssid->disabled_until.sec = now.sec + dur;
7094
7095 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07007096 "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007097 ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07007098 ssid->auth_failures, dur, reason);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007099}
7100
7101
7102void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s,
7103 struct wpa_ssid *ssid, int clear_failures)
7104{
7105 if (ssid == NULL)
7106 return;
7107
7108 if (ssid->disabled_until.sec) {
7109 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED
7110 "id=%d ssid=\"%s\"",
7111 ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
7112 }
7113 ssid->disabled_until.sec = 0;
7114 ssid->disabled_until.usec = 0;
7115 if (clear_failures)
7116 ssid->auth_failures = 0;
7117}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007118
7119
7120int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid)
7121{
7122 size_t i;
7123
7124 if (wpa_s->disallow_aps_bssid == NULL)
7125 return 0;
7126
7127 for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) {
7128 if (os_memcmp(wpa_s->disallow_aps_bssid + i * ETH_ALEN,
7129 bssid, ETH_ALEN) == 0)
7130 return 1;
7131 }
7132
7133 return 0;
7134}
7135
7136
7137int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid,
7138 size_t ssid_len)
7139{
7140 size_t i;
7141
7142 if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL)
7143 return 0;
7144
7145 for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) {
7146 struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i];
7147 if (ssid_len == s->ssid_len &&
7148 os_memcmp(ssid, s->ssid, ssid_len) == 0)
7149 return 1;
7150 }
7151
7152 return 0;
7153}
7154
7155
7156/**
7157 * wpas_request_connection - Request a new connection
7158 * @wpa_s: Pointer to the network interface
7159 *
7160 * This function is used to request a new connection to be found. It will mark
7161 * the interface to allow reassociation and request a new scan to find a
7162 * suitable network to connect to.
7163 */
7164void wpas_request_connection(struct wpa_supplicant *wpa_s)
7165{
7166 wpa_s->normal_scans = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007167 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007168 wpa_supplicant_reinit_autoscan(wpa_s);
7169 wpa_s->extra_blacklist_count = 0;
7170 wpa_s->disconnected = 0;
7171 wpa_s->reassociate = 1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007172 wpa_s->last_owe_group = 0;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08007173
7174 if (wpa_supplicant_fast_associate(wpa_s) != 1)
7175 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007176 else
7177 wpa_s->reattach = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007178}
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007179
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007180
Roshan Pius02242d72016-08-09 15:31:48 -07007181/**
7182 * wpas_request_disconnection - Request disconnection
7183 * @wpa_s: Pointer to the network interface
7184 *
7185 * This function is used to request disconnection from the currently connected
7186 * network. This will stop any ongoing scans and initiate deauthentication.
7187 */
7188void wpas_request_disconnection(struct wpa_supplicant *wpa_s)
7189{
7190#ifdef CONFIG_SME
7191 wpa_s->sme.prev_bssid_set = 0;
7192#endif /* CONFIG_SME */
7193 wpa_s->reassociate = 0;
7194 wpa_s->disconnected = 1;
7195 wpa_supplicant_cancel_sched_scan(wpa_s);
7196 wpa_supplicant_cancel_scan(wpa_s);
7197 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
7198 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Hai Shalom021b0b52019-04-10 11:17:58 -07007199 radio_remove_works(wpa_s, "connect", 0);
7200 radio_remove_works(wpa_s, "sme-connect", 0);
Roshan Pius02242d72016-08-09 15:31:48 -07007201}
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007202
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07007203
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007204void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title,
7205 struct wpa_used_freq_data *freqs_data,
7206 unsigned int len)
Dmitry Shmidtb96dad42013-11-05 10:07:29 -08007207{
7208 unsigned int i;
7209
7210 wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s",
7211 len, title);
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007212 for (i = 0; i < len; i++) {
7213 struct wpa_used_freq_data *cur = &freqs_data[i];
7214 wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X",
7215 i, cur->freq, cur->flags);
7216 }
Dmitry Shmidtb96dad42013-11-05 10:07:29 -08007217}
7218
7219
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007220/*
7221 * Find the operating frequencies of any of the virtual interfaces that
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007222 * are using the same radio as the current interface, and in addition, get
7223 * information about the interface types that are using the frequency.
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007224 */
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007225int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s,
7226 struct wpa_used_freq_data *freqs_data,
7227 unsigned int len)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007228{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007229 struct wpa_supplicant *ifs;
7230 u8 bssid[ETH_ALEN];
7231 int freq;
7232 unsigned int idx = 0, i;
7233
Dmitry Shmidtb96dad42013-11-05 10:07:29 -08007234 wpa_dbg(wpa_s, MSG_DEBUG,
7235 "Determining shared radio frequencies (max len %u)", len);
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007236 os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007237
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08007238 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
7239 radio_list) {
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007240 if (idx == len)
7241 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007242
7243 if (ifs->current_ssid == NULL || ifs->assoc_freq == 0)
7244 continue;
7245
7246 if (ifs->current_ssid->mode == WPAS_MODE_AP ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007247 ifs->current_ssid->mode == WPAS_MODE_P2P_GO ||
7248 ifs->current_ssid->mode == WPAS_MODE_MESH)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007249 freq = ifs->current_ssid->frequency;
7250 else if (wpa_drv_get_bssid(ifs, bssid) == 0)
7251 freq = ifs->assoc_freq;
7252 else
7253 continue;
7254
7255 /* Hold only distinct freqs */
7256 for (i = 0; i < idx; i++)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007257 if (freqs_data[i].freq == freq)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007258 break;
7259
7260 if (i == idx)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007261 freqs_data[idx++].freq = freq;
7262
7263 if (ifs->current_ssid->mode == WPAS_MODE_INFRA) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007264 freqs_data[i].flags |= ifs->current_ssid->p2p_group ?
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007265 WPA_FREQ_USED_BY_P2P_CLIENT :
7266 WPA_FREQ_USED_BY_INFRA_STATION;
7267 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007268 }
Dmitry Shmidtb96dad42013-11-05 10:07:29 -08007269
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007270 dump_freq_data(wpa_s, "completed iteration", freqs_data, idx);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07007271 return idx;
7272}
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07007273
7274
7275/*
7276 * Find the operating frequencies of any of the virtual interfaces that
7277 * are using the same radio as the current interface.
7278 */
7279int get_shared_radio_freqs(struct wpa_supplicant *wpa_s,
7280 int *freq_array, unsigned int len)
7281{
7282 struct wpa_used_freq_data *freqs_data;
7283 int num, i;
7284
7285 os_memset(freq_array, 0, sizeof(int) * len);
7286
7287 freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data));
7288 if (!freqs_data)
7289 return -1;
7290
7291 num = get_shared_radio_freqs_data(wpa_s, freqs_data, len);
7292 for (i = 0; i < num; i++)
7293 freq_array[i] = freqs_data[i].freq;
7294
7295 os_free(freqs_data);
7296
7297 return num;
7298}
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007299
7300
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08007301struct wpa_supplicant *
7302wpas_vendor_elem(struct wpa_supplicant *wpa_s, enum wpa_vendor_elem_frame frame)
7303{
7304 switch (frame) {
7305#ifdef CONFIG_P2P
7306 case VENDOR_ELEM_PROBE_REQ_P2P:
7307 case VENDOR_ELEM_PROBE_RESP_P2P:
7308 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
7309 case VENDOR_ELEM_BEACON_P2P_GO:
7310 case VENDOR_ELEM_P2P_PD_REQ:
7311 case VENDOR_ELEM_P2P_PD_RESP:
7312 case VENDOR_ELEM_P2P_GO_NEG_REQ:
7313 case VENDOR_ELEM_P2P_GO_NEG_RESP:
7314 case VENDOR_ELEM_P2P_GO_NEG_CONF:
7315 case VENDOR_ELEM_P2P_INV_REQ:
7316 case VENDOR_ELEM_P2P_INV_RESP:
7317 case VENDOR_ELEM_P2P_ASSOC_REQ:
7318 case VENDOR_ELEM_P2P_ASSOC_RESP:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08007319 return wpa_s->p2pdev;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08007320#endif /* CONFIG_P2P */
7321 default:
7322 return wpa_s;
7323 }
7324}
7325
7326
7327void wpas_vendor_elem_update(struct wpa_supplicant *wpa_s)
7328{
7329 unsigned int i;
7330 char buf[30];
7331
7332 wpa_printf(MSG_DEBUG, "Update vendor elements");
7333
7334 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
7335 if (wpa_s->vendor_elem[i]) {
7336 int res;
7337
7338 res = os_snprintf(buf, sizeof(buf), "frame[%u]", i);
7339 if (!os_snprintf_error(sizeof(buf), res)) {
7340 wpa_hexdump_buf(MSG_DEBUG, buf,
7341 wpa_s->vendor_elem[i]);
7342 }
7343 }
7344 }
7345
7346#ifdef CONFIG_P2P
7347 if (wpa_s->parent == wpa_s &&
7348 wpa_s->global->p2p &&
7349 !wpa_s->global->p2p_disabled)
7350 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
7351#endif /* CONFIG_P2P */
7352}
7353
7354
7355int wpas_vendor_elem_remove(struct wpa_supplicant *wpa_s, int frame,
7356 const u8 *elem, size_t len)
7357{
7358 u8 *ie, *end;
7359
7360 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
7361 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
7362
7363 for (; ie + 1 < end; ie += 2 + ie[1]) {
7364 if (ie + len > end)
7365 break;
7366 if (os_memcmp(ie, elem, len) != 0)
7367 continue;
7368
7369 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
7370 wpabuf_free(wpa_s->vendor_elem[frame]);
7371 wpa_s->vendor_elem[frame] = NULL;
7372 } else {
7373 os_memmove(ie, ie + len, end - (ie + len));
7374 wpa_s->vendor_elem[frame]->used -= len;
7375 }
7376 wpas_vendor_elem_update(wpa_s);
7377 return 0;
7378 }
7379
7380 return -1;
7381}
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007382
7383
7384struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
7385 u16 num_modes, enum hostapd_hw_mode mode)
7386{
7387 u16 i;
7388
7389 for (i = 0; i < num_modes; i++) {
7390 if (modes[i].mode == mode)
7391 return &modes[i];
7392 }
7393
7394 return NULL;
7395}
7396
7397
7398static struct
7399wpa_bss_tmp_disallowed * wpas_get_disallowed_bss(struct wpa_supplicant *wpa_s,
7400 const u8 *bssid)
7401{
7402 struct wpa_bss_tmp_disallowed *bss;
7403
7404 dl_list_for_each(bss, &wpa_s->bss_tmp_disallowed,
7405 struct wpa_bss_tmp_disallowed, list) {
7406 if (os_memcmp(bssid, bss->bssid, ETH_ALEN) == 0)
7407 return bss;
7408 }
7409
7410 return NULL;
7411}
7412
7413
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007414static int wpa_set_driver_tmp_disallow_list(struct wpa_supplicant *wpa_s)
7415{
7416 struct wpa_bss_tmp_disallowed *tmp;
7417 unsigned int num_bssid = 0;
7418 u8 *bssids;
7419 int ret;
7420
7421 bssids = os_malloc(dl_list_len(&wpa_s->bss_tmp_disallowed) * ETH_ALEN);
7422 if (!bssids)
7423 return -1;
7424 dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed,
7425 struct wpa_bss_tmp_disallowed, list) {
7426 os_memcpy(&bssids[num_bssid * ETH_ALEN], tmp->bssid,
7427 ETH_ALEN);
7428 num_bssid++;
7429 }
7430 ret = wpa_drv_set_bssid_blacklist(wpa_s, num_bssid, bssids);
7431 os_free(bssids);
7432 return ret;
7433}
7434
7435
7436static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx)
7437{
7438 struct wpa_supplicant *wpa_s = eloop_ctx;
7439 struct wpa_bss_tmp_disallowed *tmp, *bss = timeout_ctx;
7440
7441 /* Make sure the bss is not already freed */
7442 dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed,
7443 struct wpa_bss_tmp_disallowed, list) {
7444 if (bss == tmp) {
7445 dl_list_del(&tmp->list);
7446 os_free(tmp);
7447 wpa_set_driver_tmp_disallow_list(wpa_s);
7448 break;
7449 }
7450 }
7451}
7452
7453
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007454void wpa_bss_tmp_disallow(struct wpa_supplicant *wpa_s, const u8 *bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -08007455 unsigned int sec, int rssi_threshold)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007456{
7457 struct wpa_bss_tmp_disallowed *bss;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007458
7459 bss = wpas_get_disallowed_bss(wpa_s, bssid);
7460 if (bss) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007461 eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss);
Hai Shalom74f70d42019-02-11 14:42:39 -08007462 goto finish;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007463 }
7464
7465 bss = os_malloc(sizeof(*bss));
7466 if (!bss) {
7467 wpa_printf(MSG_DEBUG,
7468 "Failed to allocate memory for temp disallow BSS");
7469 return;
7470 }
7471
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007472 os_memcpy(bss->bssid, bssid, ETH_ALEN);
7473 dl_list_add(&wpa_s->bss_tmp_disallowed, &bss->list);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007474 wpa_set_driver_tmp_disallow_list(wpa_s);
Hai Shalom74f70d42019-02-11 14:42:39 -08007475
7476finish:
7477 bss->rssi_threshold = rssi_threshold;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007478 eloop_register_timeout(sec, 0, wpa_bss_tmp_disallow_timeout,
7479 wpa_s, bss);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007480}
7481
7482
Hai Shalom74f70d42019-02-11 14:42:39 -08007483int wpa_is_bss_tmp_disallowed(struct wpa_supplicant *wpa_s,
7484 struct wpa_bss *bss)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007485{
Hai Shalom74f70d42019-02-11 14:42:39 -08007486 struct wpa_bss_tmp_disallowed *disallowed = NULL, *tmp, *prev;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007487
7488 dl_list_for_each_safe(tmp, prev, &wpa_s->bss_tmp_disallowed,
7489 struct wpa_bss_tmp_disallowed, list) {
Hai Shalom74f70d42019-02-11 14:42:39 -08007490 if (os_memcmp(bss->bssid, tmp->bssid, ETH_ALEN) == 0) {
7491 disallowed = tmp;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007492 break;
7493 }
7494 }
Hai Shalom74f70d42019-02-11 14:42:39 -08007495 if (!disallowed)
7496 return 0;
7497
7498 if (disallowed->rssi_threshold != 0 &&
7499 bss->level > disallowed->rssi_threshold)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007500 return 0;
7501
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007502 return 1;
7503}