/src/hostap/wpa_supplicant/wpa_supplicant.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * WPA Supplicant |
3 | | * Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi> |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
7 | | * |
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" |
14 | | #ifdef CONFIG_MATCH_IFACE |
15 | | #include <net/if.h> |
16 | | #include <fnmatch.h> |
17 | | #endif /* CONFIG_MATCH_IFACE */ |
18 | | |
19 | | #include "common.h" |
20 | | #include "crypto/crypto.h" |
21 | | #include "crypto/random.h" |
22 | | #include "crypto/sha1.h" |
23 | | #include "eapol_supp/eapol_supp_sm.h" |
24 | | #include "eap_peer/eap.h" |
25 | | #include "eap_peer/eap_proxy.h" |
26 | | #include "eap_server/eap_methods.h" |
27 | | #include "rsn_supp/wpa.h" |
28 | | #include "eloop.h" |
29 | | #include "config.h" |
30 | | #include "utils/ext_password.h" |
31 | | #include "l2_packet/l2_packet.h" |
32 | | #include "wpa_supplicant_i.h" |
33 | | #include "driver_i.h" |
34 | | #include "ctrl_iface.h" |
35 | | #include "pcsc_funcs.h" |
36 | | #include "common/version.h" |
37 | | #include "rsn_supp/preauth.h" |
38 | | #include "rsn_supp/pmksa_cache.h" |
39 | | #include "common/wpa_ctrl.h" |
40 | | #include "common/ieee802_11_common.h" |
41 | | #include "common/ieee802_11_defs.h" |
42 | | #include "common/hw_features_common.h" |
43 | | #include "common/gas_server.h" |
44 | | #include "common/dpp.h" |
45 | | #include "common/ptksa_cache.h" |
46 | | #include "p2p/p2p.h" |
47 | | #include "fst/fst.h" |
48 | | #include "bssid_ignore.h" |
49 | | #include "wpas_glue.h" |
50 | | #include "wps_supplicant.h" |
51 | | #include "ibss_rsn.h" |
52 | | #include "sme.h" |
53 | | #include "gas_query.h" |
54 | | #include "ap.h" |
55 | | #include "p2p_supplicant.h" |
56 | | #include "wifi_display.h" |
57 | | #include "notify.h" |
58 | | #include "bgscan.h" |
59 | | #include "autoscan.h" |
60 | | #include "bss.h" |
61 | | #include "scan.h" |
62 | | #include "offchannel.h" |
63 | | #include "hs20_supplicant.h" |
64 | | #include "wnm_sta.h" |
65 | | #include "wpas_kay.h" |
66 | | #include "mesh.h" |
67 | | #include "dpp_supplicant.h" |
68 | | #include "nan_usd.h" |
69 | | #ifdef CONFIG_MESH |
70 | | #include "ap/ap_config.h" |
71 | | #include "ap/hostapd.h" |
72 | | #endif /* CONFIG_MESH */ |
73 | | |
74 | | const char *const wpa_supplicant_version = |
75 | | "wpa_supplicant v" VERSION_STR "\n" |
76 | | "Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi> and contributors"; |
77 | | |
78 | | const char *const wpa_supplicant_license = |
79 | | "This software may be distributed under the terms of the BSD license.\n" |
80 | | "See README for more details.\n" |
81 | | #ifdef EAP_TLS_OPENSSL |
82 | | "\nThis product includes software developed by the OpenSSL Project\n" |
83 | | "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n" |
84 | | #endif /* EAP_TLS_OPENSSL */ |
85 | | ; |
86 | | |
87 | | #ifndef CONFIG_NO_STDOUT_DEBUG |
88 | | /* Long text divided into parts in order to fit in C89 strings size limits. */ |
89 | | const char *const wpa_supplicant_full_license1 = |
90 | | ""; |
91 | | const char *const wpa_supplicant_full_license2 = |
92 | | "This software may be distributed under the terms of the BSD license.\n" |
93 | | "\n" |
94 | | "Redistribution and use in source and binary forms, with or without\n" |
95 | | "modification, are permitted provided that the following conditions are\n" |
96 | | "met:\n" |
97 | | "\n"; |
98 | | const char *const wpa_supplicant_full_license3 = |
99 | | "1. Redistributions of source code must retain the above copyright\n" |
100 | | " notice, this list of conditions and the following disclaimer.\n" |
101 | | "\n" |
102 | | "2. Redistributions in binary form must reproduce the above copyright\n" |
103 | | " notice, this list of conditions and the following disclaimer in the\n" |
104 | | " documentation and/or other materials provided with the distribution.\n" |
105 | | "\n"; |
106 | | const char *const wpa_supplicant_full_license4 = |
107 | | "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n" |
108 | | " names of its contributors may be used to endorse or promote products\n" |
109 | | " derived from this software without specific prior written permission.\n" |
110 | | "\n" |
111 | | "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" |
112 | | "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" |
113 | | "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" |
114 | | "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"; |
115 | | const char *const wpa_supplicant_full_license5 = |
116 | | "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" |
117 | | "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" |
118 | | "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" |
119 | | "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" |
120 | | "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" |
121 | | "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" |
122 | | "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" |
123 | | "\n"; |
124 | | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
125 | | |
126 | | |
127 | | static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx); |
128 | | static void wpas_verify_ssid_beacon(void *eloop_ctx, void *timeout_ctx); |
129 | | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
130 | | static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s); |
131 | | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ |
132 | | #ifdef CONFIG_OWE |
133 | | static void wpas_update_owe_connect_params(struct wpa_supplicant *wpa_s); |
134 | | #endif /* CONFIG_OWE */ |
135 | | |
136 | | |
137 | | #ifdef CONFIG_WEP |
138 | | /* Configure default/group WEP keys for static WEP */ |
139 | | int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
140 | | { |
141 | | int i, set = 0; |
142 | | |
143 | | for (i = 0; i < NUM_WEP_KEYS; i++) { |
144 | | if (ssid->wep_key_len[i] == 0) |
145 | | continue; |
146 | | |
147 | | set = 1; |
148 | | wpa_drv_set_key(wpa_s, -1, WPA_ALG_WEP, NULL, |
149 | | i, i == ssid->wep_tx_keyidx, NULL, 0, |
150 | | ssid->wep_key[i], ssid->wep_key_len[i], |
151 | | i == ssid->wep_tx_keyidx ? |
152 | | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
153 | | KEY_FLAG_GROUP_RX_TX); |
154 | | } |
155 | | |
156 | | return set; |
157 | | } |
158 | | #endif /* CONFIG_WEP */ |
159 | | |
160 | | |
161 | | int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s, |
162 | | struct wpa_ssid *ssid) |
163 | 0 | { |
164 | 0 | u8 key[32]; |
165 | 0 | size_t keylen; |
166 | 0 | enum wpa_alg alg; |
167 | 0 | u8 seq[6] = { 0 }; |
168 | 0 | int ret; |
169 | | |
170 | | /* IBSS/WPA-None uses only one key (Group) for both receiving and |
171 | | * sending unicast and multicast packets. */ |
172 | |
|
173 | 0 | if (ssid->mode != WPAS_MODE_IBSS) { |
174 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not " |
175 | 0 | "IBSS/ad-hoc) for WPA-None", ssid->mode); |
176 | 0 | return -1; |
177 | 0 | } |
178 | | |
179 | 0 | if (!ssid->psk_set) { |
180 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for " |
181 | 0 | "WPA-None"); |
182 | 0 | return -1; |
183 | 0 | } |
184 | | |
185 | 0 | switch (wpa_s->group_cipher) { |
186 | 0 | case WPA_CIPHER_CCMP: |
187 | 0 | os_memcpy(key, ssid->psk, 16); |
188 | 0 | keylen = 16; |
189 | 0 | alg = WPA_ALG_CCMP; |
190 | 0 | break; |
191 | 0 | case WPA_CIPHER_GCMP: |
192 | 0 | os_memcpy(key, ssid->psk, 16); |
193 | 0 | keylen = 16; |
194 | 0 | alg = WPA_ALG_GCMP; |
195 | 0 | break; |
196 | 0 | case WPA_CIPHER_TKIP: |
197 | | /* WPA-None uses the same Michael MIC key for both TX and RX */ |
198 | 0 | os_memcpy(key, ssid->psk, 16 + 8); |
199 | 0 | os_memcpy(key + 16 + 8, ssid->psk + 16, 8); |
200 | 0 | keylen = 32; |
201 | 0 | alg = WPA_ALG_TKIP; |
202 | 0 | break; |
203 | 0 | default: |
204 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for " |
205 | 0 | "WPA-None", wpa_s->group_cipher); |
206 | 0 | return -1; |
207 | 0 | } |
208 | | |
209 | | /* TODO: should actually remember the previously used seq#, both for TX |
210 | | * and RX from each STA.. */ |
211 | | |
212 | 0 | ret = wpa_drv_set_key(wpa_s, -1, alg, NULL, 0, 1, seq, 6, key, keylen, |
213 | 0 | KEY_FLAG_GROUP_RX_TX_DEFAULT); |
214 | 0 | os_memset(key, 0, sizeof(key)); |
215 | 0 | return ret; |
216 | 0 | } |
217 | | |
218 | | |
219 | | static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx) |
220 | 0 | { |
221 | 0 | struct wpa_supplicant *wpa_s = eloop_ctx; |
222 | 0 | const u8 *bssid = wpa_s->bssid; |
223 | 0 | if (!is_zero_ether_addr(wpa_s->pending_bssid) && |
224 | 0 | (wpa_s->wpa_state == WPA_AUTHENTICATING || |
225 | 0 | wpa_s->wpa_state == WPA_ASSOCIATING)) |
226 | 0 | bssid = wpa_s->pending_bssid; |
227 | 0 | wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.", |
228 | 0 | MAC2STR(bssid)); |
229 | 0 | wpa_bssid_ignore_add(wpa_s, bssid); |
230 | 0 | wpa_sm_notify_disassoc(wpa_s->wpa); |
231 | 0 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
232 | 0 | wpa_s->reassociate = 1; |
233 | | |
234 | | /* |
235 | | * If we timed out, the AP or the local radio may be busy. |
236 | | * So, wait a second until scanning again. |
237 | | */ |
238 | 0 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
239 | 0 | } |
240 | | |
241 | | |
242 | | /** |
243 | | * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication |
244 | | * @wpa_s: Pointer to wpa_supplicant data |
245 | | * @sec: Number of seconds after which to time out authentication |
246 | | * @usec: Number of microseconds after which to time out authentication |
247 | | * |
248 | | * This function is used to schedule a timeout for the current authentication |
249 | | * attempt. |
250 | | */ |
251 | | void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s, |
252 | | int sec, int usec) |
253 | 0 | { |
254 | 0 | if (wpa_s->conf->ap_scan == 0 && |
255 | 0 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) |
256 | 0 | return; |
257 | | |
258 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec " |
259 | 0 | "%d usec", sec, usec); |
260 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
261 | 0 | wpa_s->last_auth_timeout_sec = sec; |
262 | 0 | eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL); |
263 | 0 | } |
264 | | |
265 | | |
266 | | /* |
267 | | * wpas_auth_timeout_restart - Restart and change timeout for authentication |
268 | | * @wpa_s: Pointer to wpa_supplicant data |
269 | | * @sec_diff: difference in seconds applied to original timeout value |
270 | | */ |
271 | | void wpas_auth_timeout_restart(struct wpa_supplicant *wpa_s, int sec_diff) |
272 | 0 | { |
273 | 0 | int new_sec = wpa_s->last_auth_timeout_sec + sec_diff; |
274 | |
|
275 | 0 | if (eloop_is_timeout_registered(wpa_supplicant_timeout, wpa_s, NULL)) { |
276 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
277 | 0 | "Authentication timeout restart: %d sec", new_sec); |
278 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
279 | 0 | eloop_register_timeout(new_sec, 0, wpa_supplicant_timeout, |
280 | 0 | wpa_s, NULL); |
281 | 0 | } |
282 | 0 | } |
283 | | |
284 | | |
285 | | /** |
286 | | * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout |
287 | | * @wpa_s: Pointer to wpa_supplicant data |
288 | | * |
289 | | * This function is used to cancel authentication timeout scheduled with |
290 | | * wpa_supplicant_req_auth_timeout() and it is called when authentication has |
291 | | * been completed. |
292 | | */ |
293 | | void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s) |
294 | 0 | { |
295 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout"); |
296 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
297 | 0 | wpa_bssid_ignore_del(wpa_s, wpa_s->bssid); |
298 | 0 | os_free(wpa_s->last_con_fail_realm); |
299 | 0 | wpa_s->last_con_fail_realm = NULL; |
300 | 0 | wpa_s->last_con_fail_realm_len = 0; |
301 | 0 | } |
302 | | |
303 | | |
304 | | /** |
305 | | * wpa_supplicant_initiate_eapol - Configure EAPOL state machine |
306 | | * @wpa_s: Pointer to wpa_supplicant data |
307 | | * |
308 | | * This function is used to configure EAPOL state machine based on the selected |
309 | | * authentication mode. |
310 | | */ |
311 | | void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s) |
312 | 0 | { |
313 | 0 | #ifdef IEEE8021X_EAPOL |
314 | 0 | struct eapol_config eapol_conf; |
315 | 0 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
316 | |
|
317 | | #ifdef CONFIG_IBSS_RSN |
318 | | if (ssid->mode == WPAS_MODE_IBSS && |
319 | | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
320 | | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { |
321 | | /* |
322 | | * RSN IBSS authentication is per-STA and we can disable the |
323 | | * per-BSSID EAPOL authentication. |
324 | | */ |
325 | | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); |
326 | | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
327 | | eapol_sm_notify_eap_fail(wpa_s->eapol, false); |
328 | | return; |
329 | | } |
330 | | #endif /* CONFIG_IBSS_RSN */ |
331 | |
|
332 | 0 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
333 | 0 | eapol_sm_notify_eap_fail(wpa_s->eapol, false); |
334 | |
|
335 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
336 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) |
337 | 0 | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); |
338 | 0 | else |
339 | 0 | eapol_sm_notify_portControl(wpa_s->eapol, Auto); |
340 | |
|
341 | 0 | os_memset(&eapol_conf, 0, sizeof(eapol_conf)); |
342 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
343 | 0 | eapol_conf.accept_802_1x_keys = 1; |
344 | 0 | eapol_conf.required_keys = 0; |
345 | 0 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) { |
346 | 0 | eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST; |
347 | 0 | } |
348 | 0 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) { |
349 | 0 | eapol_conf.required_keys |= |
350 | 0 | EAPOL_REQUIRE_KEY_BROADCAST; |
351 | 0 | } |
352 | |
|
353 | 0 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED) |
354 | 0 | eapol_conf.required_keys = 0; |
355 | 0 | } |
356 | 0 | eapol_conf.fast_reauth = wpa_s->conf->fast_reauth; |
357 | 0 | eapol_conf.workaround = ssid->eap_workaround; |
358 | 0 | eapol_conf.eap_disabled = |
359 | 0 | !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) && |
360 | 0 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
361 | 0 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPS; |
362 | 0 | eapol_conf.external_sim = wpa_s->conf->external_sim; |
363 | |
|
364 | | #ifdef CONFIG_WPS |
365 | | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { |
366 | | eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE; |
367 | | if (wpa_s->current_bss) { |
368 | | struct wpabuf *ie; |
369 | | ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss, |
370 | | WPS_IE_VENDOR_TYPE); |
371 | | if (ie) { |
372 | | if (wps_is_20(ie)) |
373 | | eapol_conf.wps |= |
374 | | EAPOL_PEER_IS_WPS20_AP; |
375 | | wpabuf_free(ie); |
376 | | } |
377 | | } |
378 | | } |
379 | | #endif /* CONFIG_WPS */ |
380 | |
|
381 | 0 | eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf); |
382 | |
|
383 | | #ifdef CONFIG_MACSEC |
384 | | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE && ssid->mka_psk_set) |
385 | | ieee802_1x_create_preshared_mka(wpa_s, ssid); |
386 | | else |
387 | | ieee802_1x_alloc_kay_sm(wpa_s, ssid); |
388 | | #endif /* CONFIG_MACSEC */ |
389 | 0 | #endif /* IEEE8021X_EAPOL */ |
390 | 0 | } |
391 | | |
392 | | |
393 | | /** |
394 | | * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode |
395 | | * @wpa_s: Pointer to wpa_supplicant data |
396 | | * @ssid: Configuration data for the network |
397 | | * |
398 | | * This function is used to configure WPA state machine and related parameters |
399 | | * to a mode where WPA is not enabled. This is called as part of the |
400 | | * authentication configuration when the selected network does not use WPA. |
401 | | */ |
402 | | void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s, |
403 | | struct wpa_ssid *ssid) |
404 | 0 | { |
405 | | #ifdef CONFIG_WEP |
406 | | int i; |
407 | | #endif /* CONFIG_WEP */ |
408 | 0 | struct wpa_sm_mlo mlo; |
409 | |
|
410 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
411 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPS; |
412 | 0 | else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) |
413 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; |
414 | 0 | else |
415 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; |
416 | 0 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); |
417 | 0 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); |
418 | 0 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0); |
419 | 0 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
420 | 0 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
421 | 0 | wpa_s->rsnxe_len = 0; |
422 | 0 | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; |
423 | 0 | wpa_s->group_cipher = WPA_CIPHER_NONE; |
424 | 0 | wpa_s->mgmt_group_cipher = 0; |
425 | |
|
426 | | #ifdef CONFIG_WEP |
427 | | for (i = 0; i < NUM_WEP_KEYS; i++) { |
428 | | if (ssid->wep_key_len[i] > 5) { |
429 | | wpa_s->pairwise_cipher = WPA_CIPHER_WEP104; |
430 | | wpa_s->group_cipher = WPA_CIPHER_WEP104; |
431 | | break; |
432 | | } else if (ssid->wep_key_len[i] > 0) { |
433 | | wpa_s->pairwise_cipher = WPA_CIPHER_WEP40; |
434 | | wpa_s->group_cipher = WPA_CIPHER_WEP40; |
435 | | break; |
436 | | } |
437 | | } |
438 | | #endif /* CONFIG_WEP */ |
439 | |
|
440 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0); |
441 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
442 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
443 | 0 | wpa_s->pairwise_cipher); |
444 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
445 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
446 | 0 | wpa_s->mgmt_group_cipher); |
447 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION, 0); |
448 | |
|
449 | 0 | pmksa_cache_clear_current(wpa_s->wpa); |
450 | 0 | os_memset(&mlo, 0, sizeof(mlo)); |
451 | 0 | wpa_sm_set_mlo_params(wpa_s->wpa, &mlo); |
452 | 0 | } |
453 | | |
454 | | |
455 | | void free_hw_features(struct wpa_supplicant *wpa_s) |
456 | 0 | { |
457 | 0 | int i; |
458 | 0 | if (wpa_s->hw.modes == NULL) |
459 | 0 | return; |
460 | | |
461 | 0 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
462 | 0 | os_free(wpa_s->hw.modes[i].channels); |
463 | 0 | os_free(wpa_s->hw.modes[i].rates); |
464 | 0 | } |
465 | |
|
466 | 0 | os_free(wpa_s->hw.modes); |
467 | 0 | wpa_s->hw.modes = NULL; |
468 | 0 | } |
469 | | |
470 | | |
471 | | static void remove_bss_tmp_disallowed_entry(struct wpa_supplicant *wpa_s, |
472 | | struct wpa_bss_tmp_disallowed *bss) |
473 | 0 | { |
474 | 0 | eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss); |
475 | 0 | dl_list_del(&bss->list); |
476 | 0 | os_free(bss); |
477 | 0 | } |
478 | | |
479 | | |
480 | | void free_bss_tmp_disallowed(struct wpa_supplicant *wpa_s) |
481 | 0 | { |
482 | 0 | struct wpa_bss_tmp_disallowed *bss, *prev; |
483 | |
|
484 | 0 | dl_list_for_each_safe(bss, prev, &wpa_s->bss_tmp_disallowed, |
485 | 0 | struct wpa_bss_tmp_disallowed, list) |
486 | 0 | remove_bss_tmp_disallowed_entry(wpa_s, bss); |
487 | 0 | } |
488 | | |
489 | | |
490 | | void wpas_flush_fils_hlp_req(struct wpa_supplicant *wpa_s) |
491 | 0 | { |
492 | 0 | struct fils_hlp_req *req; |
493 | |
|
494 | 0 | while ((req = dl_list_first(&wpa_s->fils_hlp_req, struct fils_hlp_req, |
495 | 0 | list)) != NULL) { |
496 | 0 | dl_list_del(&req->list); |
497 | 0 | wpabuf_free(req->pkt); |
498 | 0 | os_free(req); |
499 | 0 | } |
500 | 0 | } |
501 | | |
502 | | |
503 | | void wpas_clear_disabled_interface(void *eloop_ctx, void *timeout_ctx) |
504 | 0 | { |
505 | 0 | struct wpa_supplicant *wpa_s = eloop_ctx; |
506 | |
|
507 | 0 | if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) |
508 | 0 | return; |
509 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Clear cached state on disabled interface"); |
510 | 0 | wpa_bss_flush(wpa_s); |
511 | 0 | } |
512 | | |
513 | | |
514 | | #ifdef CONFIG_TESTING_OPTIONS |
515 | | void wpas_clear_driver_signal_override(struct wpa_supplicant *wpa_s) |
516 | | { |
517 | | struct driver_signal_override *dso; |
518 | | |
519 | | while ((dso = dl_list_first(&wpa_s->drv_signal_override, |
520 | | struct driver_signal_override, list))) { |
521 | | dl_list_del(&dso->list); |
522 | | os_free(dso); |
523 | | } |
524 | | } |
525 | | #endif /* CONFIG_TESTING_OPTIONS */ |
526 | | |
527 | | |
528 | | static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s) |
529 | 0 | { |
530 | 0 | int i; |
531 | |
|
532 | 0 | bgscan_deinit(wpa_s); |
533 | 0 | autoscan_deinit(wpa_s); |
534 | 0 | scard_deinit(wpa_s->scard); |
535 | 0 | wpa_s->scard = NULL; |
536 | 0 | wpa_sm_set_scard_ctx(wpa_s->wpa, NULL); |
537 | 0 | eapol_sm_register_scard_ctx(wpa_s->eapol, NULL); |
538 | 0 | l2_packet_deinit(wpa_s->l2); |
539 | 0 | wpa_s->l2 = NULL; |
540 | 0 | if (wpa_s->l2_br) { |
541 | 0 | l2_packet_deinit(wpa_s->l2_br); |
542 | 0 | wpa_s->l2_br = NULL; |
543 | 0 | } |
544 | | #ifdef CONFIG_TESTING_OPTIONS |
545 | | l2_packet_deinit(wpa_s->l2_test); |
546 | | wpa_s->l2_test = NULL; |
547 | | os_free(wpa_s->get_pref_freq_list_override); |
548 | | wpa_s->get_pref_freq_list_override = NULL; |
549 | | wpabuf_free(wpa_s->last_assoc_req_wpa_ie); |
550 | | wpa_s->last_assoc_req_wpa_ie = NULL; |
551 | | os_free(wpa_s->extra_sae_rejected_groups); |
552 | | wpa_s->extra_sae_rejected_groups = NULL; |
553 | | wpabuf_free(wpa_s->rsne_override_eapol); |
554 | | wpa_s->rsne_override_eapol = NULL; |
555 | | wpabuf_free(wpa_s->rsnxe_override_assoc); |
556 | | wpa_s->rsnxe_override_assoc = NULL; |
557 | | wpabuf_free(wpa_s->rsnxe_override_eapol); |
558 | | wpa_s->rsnxe_override_eapol = NULL; |
559 | | wpas_clear_driver_signal_override(wpa_s); |
560 | | #endif /* CONFIG_TESTING_OPTIONS */ |
561 | |
|
562 | 0 | if (wpa_s->conf != NULL) { |
563 | 0 | struct wpa_ssid *ssid; |
564 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
565 | 0 | wpas_notify_network_removed(wpa_s, ssid); |
566 | 0 | } |
567 | |
|
568 | 0 | os_free(wpa_s->confname); |
569 | 0 | wpa_s->confname = NULL; |
570 | |
|
571 | 0 | os_free(wpa_s->confanother); |
572 | 0 | wpa_s->confanother = NULL; |
573 | |
|
574 | 0 | os_free(wpa_s->last_con_fail_realm); |
575 | 0 | wpa_s->last_con_fail_realm = NULL; |
576 | 0 | wpa_s->last_con_fail_realm_len = 0; |
577 | |
|
578 | 0 | wpa_sm_set_eapol(wpa_s->wpa, NULL); |
579 | 0 | eapol_sm_deinit(wpa_s->eapol); |
580 | 0 | wpa_s->eapol = NULL; |
581 | |
|
582 | 0 | rsn_preauth_deinit(wpa_s->wpa); |
583 | |
|
584 | | #ifdef CONFIG_TDLS |
585 | | wpa_tdls_deinit(wpa_s->wpa); |
586 | | #endif /* CONFIG_TDLS */ |
587 | |
|
588 | 0 | #ifndef CONFIG_NO_WMM_AC |
589 | 0 | wmm_ac_clear_saved_tspecs(wpa_s); |
590 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
591 | 0 | pmksa_candidate_free(wpa_s->wpa); |
592 | 0 | ptksa_cache_deinit(wpa_s->ptksa); |
593 | 0 | wpa_s->ptksa = NULL; |
594 | 0 | wpa_sm_deinit(wpa_s->wpa); |
595 | 0 | wpa_s->wpa = NULL; |
596 | 0 | wpa_bssid_ignore_clear(wpa_s); |
597 | |
|
598 | | #ifdef CONFIG_PASN |
599 | | wpas_pasn_auth_stop(wpa_s); |
600 | | #endif /* CONFIG_PASN */ |
601 | |
|
602 | 0 | wpa_bss_deinit(wpa_s); |
603 | |
|
604 | 0 | wpa_supplicant_cancel_delayed_sched_scan(wpa_s); |
605 | 0 | wpa_supplicant_cancel_scan(wpa_s); |
606 | 0 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
607 | 0 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
608 | | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
609 | | eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report, |
610 | | wpa_s, NULL); |
611 | | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
612 | |
|
613 | 0 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
614 | 0 | eloop_cancel_timeout(wpas_clear_disabled_interface, wpa_s, NULL); |
615 | 0 | eloop_cancel_timeout(wpas_verify_ssid_beacon, wpa_s, NULL); |
616 | |
|
617 | 0 | wpas_wps_deinit(wpa_s); |
618 | |
|
619 | 0 | wpabuf_free(wpa_s->pending_eapol_rx); |
620 | 0 | wpa_s->pending_eapol_rx = NULL; |
621 | |
|
622 | | #ifdef CONFIG_IBSS_RSN |
623 | | ibss_rsn_deinit(wpa_s->ibss_rsn); |
624 | | wpa_s->ibss_rsn = NULL; |
625 | | #endif /* CONFIG_IBSS_RSN */ |
626 | |
|
627 | 0 | sme_deinit(wpa_s); |
628 | |
|
629 | | #ifdef CONFIG_AP |
630 | | wpa_supplicant_ap_deinit(wpa_s); |
631 | | #endif /* CONFIG_AP */ |
632 | |
|
633 | 0 | wpas_p2p_deinit(wpa_s); |
634 | |
|
635 | | #ifdef CONFIG_OFFCHANNEL |
636 | | offchannel_deinit(wpa_s); |
637 | | #endif /* CONFIG_OFFCHANNEL */ |
638 | |
|
639 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
640 | |
|
641 | 0 | os_free(wpa_s->next_scan_freqs); |
642 | 0 | wpa_s->next_scan_freqs = NULL; |
643 | |
|
644 | 0 | os_free(wpa_s->manual_scan_freqs); |
645 | 0 | wpa_s->manual_scan_freqs = NULL; |
646 | 0 | os_free(wpa_s->select_network_scan_freqs); |
647 | 0 | wpa_s->select_network_scan_freqs = NULL; |
648 | |
|
649 | 0 | os_free(wpa_s->manual_sched_scan_freqs); |
650 | 0 | wpa_s->manual_sched_scan_freqs = NULL; |
651 | |
|
652 | 0 | wpas_mac_addr_rand_scan_clear(wpa_s, MAC_ADDR_RAND_ALL); |
653 | | |
654 | | /* |
655 | | * Need to remove any pending gas-query radio work before the |
656 | | * gas_query_deinit() call because gas_query::work has not yet been set |
657 | | * for works that have not been started. gas_query_free() will be unable |
658 | | * to cancel such pending radio works and once the pending gas-query |
659 | | * radio work eventually gets removed, the deinit notification call to |
660 | | * gas_query_start_cb() would result in dereferencing freed memory. |
661 | | */ |
662 | 0 | if (wpa_s->radio) |
663 | 0 | radio_remove_works(wpa_s, "gas-query", 0); |
664 | 0 | gas_query_deinit(wpa_s->gas); |
665 | 0 | wpa_s->gas = NULL; |
666 | 0 | gas_server_deinit(wpa_s->gas_server); |
667 | 0 | wpa_s->gas_server = NULL; |
668 | |
|
669 | 0 | free_hw_features(wpa_s); |
670 | |
|
671 | 0 | ieee802_1x_dealloc_kay_sm(wpa_s); |
672 | |
|
673 | 0 | os_free(wpa_s->bssid_filter); |
674 | 0 | wpa_s->bssid_filter = NULL; |
675 | |
|
676 | 0 | os_free(wpa_s->disallow_aps_bssid); |
677 | 0 | wpa_s->disallow_aps_bssid = NULL; |
678 | 0 | os_free(wpa_s->disallow_aps_ssid); |
679 | 0 | wpa_s->disallow_aps_ssid = NULL; |
680 | |
|
681 | 0 | wnm_bss_keep_alive_deinit(wpa_s); |
682 | 0 | wnm_btm_reset(wpa_s); |
683 | |
|
684 | 0 | ext_password_deinit(wpa_s->ext_pw); |
685 | 0 | wpa_s->ext_pw = NULL; |
686 | |
|
687 | 0 | wpabuf_free(wpa_s->last_gas_resp); |
688 | 0 | wpa_s->last_gas_resp = NULL; |
689 | 0 | wpabuf_free(wpa_s->prev_gas_resp); |
690 | 0 | wpa_s->prev_gas_resp = NULL; |
691 | |
|
692 | 0 | os_free(wpa_s->last_scan_res); |
693 | 0 | wpa_s->last_scan_res = NULL; |
694 | |
|
695 | 0 | #ifdef CONFIG_HS20 |
696 | 0 | if (wpa_s->drv_priv) |
697 | 0 | wpa_drv_configure_frame_filters(wpa_s, 0); |
698 | 0 | hs20_deinit(wpa_s); |
699 | 0 | #endif /* CONFIG_HS20 */ |
700 | |
|
701 | 0 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { |
702 | 0 | wpabuf_free(wpa_s->vendor_elem[i]); |
703 | 0 | wpa_s->vendor_elem[i] = NULL; |
704 | 0 | } |
705 | |
|
706 | 0 | #ifndef CONFIG_NO_WMM_AC |
707 | 0 | wmm_ac_notify_disassoc(wpa_s); |
708 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
709 | |
|
710 | 0 | wpa_s->sched_scan_plans_num = 0; |
711 | 0 | os_free(wpa_s->sched_scan_plans); |
712 | 0 | wpa_s->sched_scan_plans = NULL; |
713 | |
|
714 | | #ifdef CONFIG_MBO |
715 | | wpa_s->non_pref_chan_num = 0; |
716 | | os_free(wpa_s->non_pref_chan); |
717 | | wpa_s->non_pref_chan = NULL; |
718 | | #endif /* CONFIG_MBO */ |
719 | |
|
720 | 0 | free_bss_tmp_disallowed(wpa_s); |
721 | |
|
722 | 0 | wpabuf_free(wpa_s->lci); |
723 | 0 | wpa_s->lci = NULL; |
724 | 0 | #ifndef CONFIG_NO_RRM |
725 | 0 | wpas_clear_beacon_rep_data(wpa_s); |
726 | 0 | #endif /* CONFIG_NO_RRM */ |
727 | |
|
728 | | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
729 | | #ifdef CONFIG_MESH |
730 | | { |
731 | | struct external_pmksa_cache *entry; |
732 | | |
733 | | while ((entry = dl_list_last(&wpa_s->mesh_external_pmksa_cache, |
734 | | struct external_pmksa_cache, |
735 | | list)) != NULL) { |
736 | | dl_list_del(&entry->list); |
737 | | os_free(entry->pmksa_cache); |
738 | | os_free(entry); |
739 | | } |
740 | | } |
741 | | #endif /* CONFIG_MESH */ |
742 | | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
743 | |
|
744 | 0 | wpas_flush_fils_hlp_req(wpa_s); |
745 | |
|
746 | 0 | wpabuf_free(wpa_s->ric_ies); |
747 | 0 | wpa_s->ric_ies = NULL; |
748 | |
|
749 | | #ifdef CONFIG_DPP |
750 | | wpas_dpp_deinit(wpa_s); |
751 | | dpp_global_deinit(wpa_s->dpp); |
752 | | wpa_s->dpp = NULL; |
753 | | #endif /* CONFIG_DPP */ |
754 | |
|
755 | | #ifdef CONFIG_NAN_USD |
756 | | wpas_nan_usd_deinit(wpa_s); |
757 | | #endif /* CONFIG_NAN_USD */ |
758 | |
|
759 | | #ifdef CONFIG_PASN |
760 | | wpas_pasn_auth_stop(wpa_s); |
761 | | #endif /* CONFIG_PASN */ |
762 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
763 | 0 | wpas_scs_deinit(wpa_s); |
764 | 0 | wpas_dscp_deinit(wpa_s); |
765 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
766 | |
|
767 | | #ifdef CONFIG_OWE |
768 | | os_free(wpa_s->owe_trans_scan_freq); |
769 | | wpa_s->owe_trans_scan_freq = NULL; |
770 | | #endif /* CONFIG_OWE */ |
771 | 0 | } |
772 | | |
773 | | |
774 | | /** |
775 | | * wpa_clear_keys - Clear keys configured for the driver |
776 | | * @wpa_s: Pointer to wpa_supplicant data |
777 | | * @addr: Previously used BSSID or %NULL if not available |
778 | | * |
779 | | * This function clears the encryption keys that has been previously configured |
780 | | * for the driver. |
781 | | */ |
782 | | void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr) |
783 | 0 | { |
784 | 0 | int i, max = 6; |
785 | | |
786 | | /* MLME-DELETEKEYS.request */ |
787 | 0 | for (i = 0; i < max; i++) { |
788 | 0 | if (wpa_s->keys_cleared & BIT(i)) |
789 | 0 | continue; |
790 | 0 | wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, i, 0, NULL, 0, |
791 | 0 | NULL, 0, KEY_FLAG_GROUP); |
792 | 0 | } |
793 | | /* Pairwise Key ID 1 for Extended Key ID is tracked in bit 15 */ |
794 | 0 | if (~wpa_s->keys_cleared & (BIT(0) | BIT(15)) && addr && |
795 | 0 | !is_zero_ether_addr(addr)) { |
796 | 0 | if (!(wpa_s->keys_cleared & BIT(0))) |
797 | 0 | wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, addr, 0, 0, |
798 | 0 | NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE); |
799 | 0 | if (!(wpa_s->keys_cleared & BIT(15))) |
800 | 0 | wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, addr, 1, 0, |
801 | 0 | NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE); |
802 | | /* MLME-SETPROTECTION.request(None) */ |
803 | 0 | wpa_drv_mlme_setprotection( |
804 | 0 | wpa_s, addr, |
805 | 0 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
806 | 0 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
807 | 0 | } |
808 | 0 | wpa_s->keys_cleared = (u32) -1; |
809 | 0 | } |
810 | | |
811 | | |
812 | | /** |
813 | | * wpa_supplicant_state_txt - Get the connection state name as a text string |
814 | | * @state: State (wpa_state; WPA_*) |
815 | | * Returns: The state name as a printable text string |
816 | | */ |
817 | | const char * wpa_supplicant_state_txt(enum wpa_states state) |
818 | 0 | { |
819 | 0 | switch (state) { |
820 | 0 | case WPA_DISCONNECTED: |
821 | 0 | return "DISCONNECTED"; |
822 | 0 | case WPA_INACTIVE: |
823 | 0 | return "INACTIVE"; |
824 | 0 | case WPA_INTERFACE_DISABLED: |
825 | 0 | return "INTERFACE_DISABLED"; |
826 | 0 | case WPA_SCANNING: |
827 | 0 | return "SCANNING"; |
828 | 0 | case WPA_AUTHENTICATING: |
829 | 0 | return "AUTHENTICATING"; |
830 | 0 | case WPA_ASSOCIATING: |
831 | 0 | return "ASSOCIATING"; |
832 | 0 | case WPA_ASSOCIATED: |
833 | 0 | return "ASSOCIATED"; |
834 | 0 | case WPA_4WAY_HANDSHAKE: |
835 | 0 | return "4WAY_HANDSHAKE"; |
836 | 0 | case WPA_GROUP_HANDSHAKE: |
837 | 0 | return "GROUP_HANDSHAKE"; |
838 | 0 | case WPA_COMPLETED: |
839 | 0 | return "COMPLETED"; |
840 | 0 | default: |
841 | 0 | return "UNKNOWN"; |
842 | 0 | } |
843 | 0 | } |
844 | | |
845 | | |
846 | | #ifdef CONFIG_BGSCAN |
847 | | |
848 | | static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) |
849 | | { |
850 | | if (wpa_s->bgscan_ssid) { |
851 | | bgscan_deinit(wpa_s); |
852 | | wpa_s->bgscan_ssid = NULL; |
853 | | } |
854 | | } |
855 | | |
856 | | |
857 | | /** |
858 | | * wpa_supplicant_reset_bgscan - Reset the bgscan for the current SSID. |
859 | | * @wpa_s: Pointer to the wpa_supplicant data |
860 | | * |
861 | | * Stop, start, or reconfigure the scan parameters depending on the method. |
862 | | */ |
863 | | void wpa_supplicant_reset_bgscan(struct wpa_supplicant *wpa_s) |
864 | | { |
865 | | const char *name; |
866 | | |
867 | | if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) |
868 | | name = wpa_s->current_ssid->bgscan; |
869 | | else |
870 | | name = wpa_s->conf->bgscan; |
871 | | if (!name || name[0] == '\0') { |
872 | | wpa_supplicant_stop_bgscan(wpa_s); |
873 | | return; |
874 | | } |
875 | | if (wpas_driver_bss_selection(wpa_s)) |
876 | | return; |
877 | | #ifdef CONFIG_P2P |
878 | | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
879 | | return; |
880 | | #endif /* CONFIG_P2P */ |
881 | | |
882 | | bgscan_deinit(wpa_s); |
883 | | if (wpa_s->current_ssid) { |
884 | | if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) { |
885 | | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " |
886 | | "bgscan"); |
887 | | /* |
888 | | * Live without bgscan; it is only used as a roaming |
889 | | * optimization, so the initial connection is not |
890 | | * affected. |
891 | | */ |
892 | | } else { |
893 | | struct wpa_scan_results *scan_res; |
894 | | wpa_s->bgscan_ssid = wpa_s->current_ssid; |
895 | | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, |
896 | | 0, NULL); |
897 | | if (scan_res) { |
898 | | bgscan_notify_scan(wpa_s, scan_res); |
899 | | wpa_scan_results_free(scan_res); |
900 | | } |
901 | | } |
902 | | } else |
903 | | wpa_s->bgscan_ssid = NULL; |
904 | | } |
905 | | |
906 | | #endif /* CONFIG_BGSCAN */ |
907 | | |
908 | | |
909 | | static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s) |
910 | 0 | { |
911 | 0 | if (autoscan_init(wpa_s, 0)) |
912 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan"); |
913 | 0 | } |
914 | | |
915 | | |
916 | | static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s) |
917 | 0 | { |
918 | 0 | autoscan_deinit(wpa_s); |
919 | 0 | } |
920 | | |
921 | | |
922 | | void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s) |
923 | 0 | { |
924 | 0 | if (wpa_s->wpa_state == WPA_DISCONNECTED || |
925 | 0 | wpa_s->wpa_state == WPA_SCANNING) { |
926 | 0 | autoscan_deinit(wpa_s); |
927 | 0 | wpa_supplicant_start_autoscan(wpa_s); |
928 | 0 | } |
929 | 0 | } |
930 | | |
931 | | |
932 | | static void wpas_verify_ssid_beacon(void *eloop_ctx, void *timeout_ctx) |
933 | 0 | { |
934 | 0 | struct wpa_supplicant *wpa_s = eloop_ctx; |
935 | 0 | struct wpa_bss *bss; |
936 | 0 | const u8 *ssid; |
937 | 0 | size_t ssid_len; |
938 | |
|
939 | 0 | if (!wpa_s->current_ssid || !wpa_s->current_bss) |
940 | 0 | return; |
941 | | |
942 | 0 | ssid = wpa_s->current_bss->ssid; |
943 | 0 | ssid_len = wpa_s->current_bss->ssid_len; |
944 | |
|
945 | 0 | if (wpa_s->current_ssid->ssid_len && |
946 | 0 | (wpa_s->current_ssid->ssid_len != ssid_len || |
947 | 0 | os_memcmp(wpa_s->current_ssid->ssid, ssid, ssid_len) != 0)) |
948 | 0 | return; |
949 | | |
950 | 0 | if (wpa_s->wpa_state < WPA_4WAY_HANDSHAKE || |
951 | 0 | !wpa_s->bigtk_set || wpa_s->ssid_verified) |
952 | 0 | return; |
953 | | |
954 | 0 | wpa_printf(MSG_DEBUG, |
955 | 0 | "SSID not yet verified; check if the driver has received a verified Beacon frame"); |
956 | 0 | if (wpa_supplicant_update_scan_results(wpa_s, wpa_s->bssid) < 0) |
957 | 0 | return; |
958 | | |
959 | 0 | bss = wpa_bss_get_bssid_latest(wpa_s, wpa_s->bssid); |
960 | 0 | if (!bss) |
961 | 0 | return; |
962 | 0 | wpa_printf(MSG_DEBUG, "The current beacon time stamp: 0x%llx", |
963 | 0 | (long long unsigned int) bss->tsf); |
964 | 0 | if (bss->tsf > wpa_s->first_beacon_tsf) { |
965 | 0 | const u8 *ie; |
966 | |
|
967 | 0 | wpa_printf(MSG_DEBUG, |
968 | 0 | "Verified Beacon frame has been received"); |
969 | 0 | wpa_s->beacons_checked++; |
970 | |
|
971 | 0 | ie = wpa_bss_get_ie_beacon(bss, WLAN_EID_SSID); |
972 | 0 | if (ie && ie[1] == ssid_len && |
973 | 0 | os_memcmp(&ie[2], ssid, ssid_len) == 0) { |
974 | 0 | wpa_printf(MSG_DEBUG, |
975 | 0 | "SSID verified based on a Beacon frame and beacon protection"); |
976 | 0 | wpa_s->ssid_verified = true; |
977 | 0 | return; |
978 | 0 | } |
979 | | |
980 | | /* TODO: Multiple BSSID element */ |
981 | 0 | } |
982 | | |
983 | 0 | if (wpa_s->beacons_checked < 16) { |
984 | 0 | eloop_register_timeout(wpa_s->next_beacon_check, 0, |
985 | 0 | wpas_verify_ssid_beacon, wpa_s, NULL); |
986 | 0 | wpa_s->next_beacon_check++; |
987 | 0 | } |
988 | 0 | } |
989 | | |
990 | | |
991 | | static void wpas_verify_ssid_beacon_prot(struct wpa_supplicant *wpa_s) |
992 | 0 | { |
993 | 0 | struct wpa_bss *bss; |
994 | |
|
995 | 0 | wpa_printf(MSG_DEBUG, |
996 | 0 | "SSID not yet verified; try to verify using beacon protection"); |
997 | | /* Fetch the current scan result which is likely based on not yet |
998 | | * verified payload since the current BIGTK was just received. Any |
999 | | * newer update in the future with a larger timestamp value is an |
1000 | | * indication that a verified Beacon frame has been received. */ |
1001 | 0 | if (wpa_supplicant_update_scan_results(wpa_s, wpa_s->bssid) < 0) |
1002 | 0 | return; |
1003 | | |
1004 | 0 | bss = wpa_bss_get_bssid_latest(wpa_s, wpa_s->bssid); |
1005 | 0 | if (!bss) |
1006 | 0 | return; |
1007 | 0 | wpa_printf(MSG_DEBUG, "The initial beacon time stamp: 0x%llx", |
1008 | 0 | (long long unsigned int) bss->tsf); |
1009 | 0 | wpa_s->first_beacon_tsf = bss->tsf; |
1010 | 0 | wpa_s->beacons_checked = 0; |
1011 | 0 | wpa_s->next_beacon_check = 1; |
1012 | 0 | eloop_cancel_timeout(wpas_verify_ssid_beacon, wpa_s, NULL); |
1013 | 0 | eloop_register_timeout(1, 0, wpas_verify_ssid_beacon, wpa_s, NULL); |
1014 | 0 | } |
1015 | | |
1016 | | |
1017 | | /** |
1018 | | * wpa_supplicant_set_state - Set current connection state |
1019 | | * @wpa_s: Pointer to wpa_supplicant data |
1020 | | * @state: The new connection state |
1021 | | * |
1022 | | * This function is called whenever the connection state changes, e.g., |
1023 | | * association is completed for WPA/WPA2 4-Way Handshake is started. |
1024 | | */ |
1025 | | void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, |
1026 | | enum wpa_states state) |
1027 | 0 | { |
1028 | 0 | enum wpa_states old_state = wpa_s->wpa_state; |
1029 | | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
1030 | | bool update_fils_connect_params = false; |
1031 | | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ |
1032 | |
|
1033 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s", |
1034 | 0 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
1035 | 0 | wpa_supplicant_state_txt(state)); |
1036 | |
|
1037 | 0 | if (state == WPA_COMPLETED && |
1038 | 0 | os_reltime_initialized(&wpa_s->roam_start)) { |
1039 | 0 | os_reltime_age(&wpa_s->roam_start, &wpa_s->roam_time); |
1040 | 0 | wpa_s->roam_start.sec = 0; |
1041 | 0 | wpa_s->roam_start.usec = 0; |
1042 | 0 | wpas_notify_auth_changed(wpa_s); |
1043 | 0 | wpas_notify_roam_time(wpa_s); |
1044 | 0 | wpas_notify_roam_complete(wpa_s); |
1045 | 0 | } else if (state == WPA_DISCONNECTED && |
1046 | 0 | os_reltime_initialized(&wpa_s->roam_start)) { |
1047 | 0 | wpa_s->roam_start.sec = 0; |
1048 | 0 | wpa_s->roam_start.usec = 0; |
1049 | 0 | wpa_s->roam_time.sec = 0; |
1050 | 0 | wpa_s->roam_time.usec = 0; |
1051 | 0 | wpas_notify_roam_complete(wpa_s); |
1052 | 0 | } |
1053 | |
|
1054 | 0 | if (state == WPA_INTERFACE_DISABLED) { |
1055 | | /* Assure normal scan when interface is restored */ |
1056 | 0 | wpa_s->normal_scans = 0; |
1057 | 0 | } |
1058 | |
|
1059 | 0 | if (state == WPA_COMPLETED) { |
1060 | 0 | wpas_connect_work_done(wpa_s); |
1061 | | /* Reinitialize normal_scan counter */ |
1062 | 0 | wpa_s->normal_scans = 0; |
1063 | 0 | } |
1064 | |
|
1065 | | #ifdef CONFIG_P2P |
1066 | | /* |
1067 | | * P2PS client has to reply to Probe Request frames received on the |
1068 | | * group operating channel. Enable Probe Request frame reporting for |
1069 | | * P2P connected client in case p2p_cli_probe configuration property is |
1070 | | * set to 1. |
1071 | | */ |
1072 | | if (wpa_s->conf->p2p_cli_probe && wpa_s->current_ssid && |
1073 | | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
1074 | | wpa_s->current_ssid->p2p_group) { |
1075 | | if (state == WPA_COMPLETED && !wpa_s->p2p_cli_probe) { |
1076 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1077 | | "P2P: Enable CLI Probe Request RX reporting"); |
1078 | | wpa_s->p2p_cli_probe = |
1079 | | wpa_drv_probe_req_report(wpa_s, 1) >= 0; |
1080 | | } else if (state != WPA_COMPLETED && wpa_s->p2p_cli_probe) { |
1081 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1082 | | "P2P: Disable CLI Probe Request RX reporting"); |
1083 | | wpa_s->p2p_cli_probe = 0; |
1084 | | wpa_drv_probe_req_report(wpa_s, 0); |
1085 | | } |
1086 | | } |
1087 | | #endif /* CONFIG_P2P */ |
1088 | |
|
1089 | 0 | if (state != WPA_SCANNING) |
1090 | 0 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1091 | |
|
1092 | 0 | if (state == WPA_COMPLETED && wpa_s->new_connection) { |
1093 | 0 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
1094 | 0 | int fils_hlp_sent = 0; |
1095 | 0 | char mld_addr[50]; |
1096 | |
|
1097 | 0 | mld_addr[0] = '\0'; |
1098 | 0 | if (wpa_s->valid_links) |
1099 | 0 | os_snprintf(mld_addr, sizeof(mld_addr), |
1100 | 0 | " ap_mld_addr=" MACSTR, |
1101 | 0 | MAC2STR(wpa_s->ap_mld_addr)); |
1102 | |
|
1103 | | #ifdef CONFIG_SME |
1104 | | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
1105 | | wpa_auth_alg_fils(wpa_s->sme.auth_alg)) |
1106 | | fils_hlp_sent = 1; |
1107 | | #endif /* CONFIG_SME */ |
1108 | 0 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
1109 | 0 | wpa_auth_alg_fils(wpa_s->auth_alg)) |
1110 | 0 | fils_hlp_sent = 1; |
1111 | |
|
1112 | 0 | #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) |
1113 | 0 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to " |
1114 | 0 | MACSTR " completed [id=%d id_str=%s%s]%s", |
1115 | 0 | MAC2STR(wpa_s->bssid), |
1116 | 0 | ssid ? ssid->id : -1, |
1117 | 0 | ssid && ssid->id_str ? ssid->id_str : "", |
1118 | 0 | fils_hlp_sent ? " FILS_HLP_SENT" : "", mld_addr); |
1119 | 0 | #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
1120 | 0 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
1121 | 0 | wpa_s->consecutive_conn_failures = 0; |
1122 | 0 | wpa_s->new_connection = 0; |
1123 | 0 | wpa_drv_set_operstate(wpa_s, 1); |
1124 | | #ifndef IEEE8021X_EAPOL |
1125 | | wpa_drv_set_supp_port(wpa_s, 1); |
1126 | | #endif /* IEEE8021X_EAPOL */ |
1127 | 0 | wpa_s->after_wps = 0; |
1128 | 0 | wpa_s->known_wps_freq = 0; |
1129 | 0 | wpas_p2p_completed(wpa_s); |
1130 | |
|
1131 | 0 | sme_sched_obss_scan(wpa_s, 1); |
1132 | |
|
1133 | | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
1134 | | if (!fils_hlp_sent && ssid && ssid->eap.erp) |
1135 | | update_fils_connect_params = true; |
1136 | | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ |
1137 | | #ifdef CONFIG_OWE |
1138 | | if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_OWE)) |
1139 | | wpas_update_owe_connect_params(wpa_s); |
1140 | | #endif /* CONFIG_OWE */ |
1141 | 0 | } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING || |
1142 | 0 | state == WPA_ASSOCIATED) { |
1143 | 0 | wpa_s->new_connection = 1; |
1144 | 0 | wpa_drv_set_operstate(wpa_s, 0); |
1145 | | #ifndef IEEE8021X_EAPOL |
1146 | | wpa_drv_set_supp_port(wpa_s, 0); |
1147 | | #endif /* IEEE8021X_EAPOL */ |
1148 | 0 | sme_sched_obss_scan(wpa_s, 0); |
1149 | 0 | } |
1150 | 0 | wpa_s->wpa_state = state; |
1151 | |
|
1152 | | #ifdef CONFIG_BGSCAN |
1153 | | if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid) |
1154 | | wpa_supplicant_reset_bgscan(wpa_s); |
1155 | | else if (state < WPA_ASSOCIATED) |
1156 | | wpa_supplicant_stop_bgscan(wpa_s); |
1157 | | #endif /* CONFIG_BGSCAN */ |
1158 | |
|
1159 | 0 | if (state > WPA_SCANNING) |
1160 | 0 | wpa_supplicant_stop_autoscan(wpa_s); |
1161 | |
|
1162 | 0 | if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) |
1163 | 0 | wpa_supplicant_start_autoscan(wpa_s); |
1164 | |
|
1165 | 0 | if (state == WPA_COMPLETED || state == WPA_INTERFACE_DISABLED || |
1166 | 0 | state == WPA_INACTIVE) |
1167 | 0 | wnm_btm_reset(wpa_s); |
1168 | |
|
1169 | 0 | #ifndef CONFIG_NO_WMM_AC |
1170 | 0 | if (old_state >= WPA_ASSOCIATED && wpa_s->wpa_state < WPA_ASSOCIATED) |
1171 | 0 | wmm_ac_notify_disassoc(wpa_s); |
1172 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
1173 | |
|
1174 | 0 | if (wpa_s->wpa_state != old_state) { |
1175 | 0 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); |
1176 | | |
1177 | | /* |
1178 | | * Notify the P2P Device interface about a state change in one |
1179 | | * of the interfaces. |
1180 | | */ |
1181 | 0 | wpas_p2p_indicate_state_change(wpa_s); |
1182 | |
|
1183 | 0 | if (wpa_s->wpa_state == WPA_COMPLETED || |
1184 | 0 | old_state == WPA_COMPLETED) |
1185 | 0 | wpas_notify_auth_changed(wpa_s); |
1186 | | #ifdef CONFIG_DPP2 |
1187 | | if (wpa_s->wpa_state == WPA_COMPLETED) |
1188 | | wpas_dpp_connected(wpa_s); |
1189 | | #endif /* CONFIG_DPP2 */ |
1190 | |
|
1191 | 0 | if (wpa_s->wpa_state == WPA_COMPLETED && |
1192 | 0 | wpa_s->bigtk_set && !wpa_s->ssid_verified) |
1193 | 0 | wpas_verify_ssid_beacon_prot(wpa_s); |
1194 | 0 | } |
1195 | | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
1196 | | if (update_fils_connect_params) |
1197 | | wpas_update_fils_connect_params(wpa_s); |
1198 | | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ |
1199 | 0 | } |
1200 | | |
1201 | | |
1202 | | void wpa_supplicant_terminate_proc(struct wpa_global *global) |
1203 | 0 | { |
1204 | 0 | int pending = 0; |
1205 | | #ifdef CONFIG_WPS |
1206 | | struct wpa_supplicant *wpa_s = global->ifaces; |
1207 | | while (wpa_s) { |
1208 | | struct wpa_supplicant *next = wpa_s->next; |
1209 | | if (wpas_wps_terminate_pending(wpa_s) == 1) |
1210 | | pending = 1; |
1211 | | #ifdef CONFIG_P2P |
1212 | | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE || |
1213 | | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group)) |
1214 | | wpas_p2p_disconnect(wpa_s); |
1215 | | #endif /* CONFIG_P2P */ |
1216 | | wpa_s = next; |
1217 | | } |
1218 | | #endif /* CONFIG_WPS */ |
1219 | 0 | if (pending) |
1220 | 0 | return; |
1221 | 0 | eloop_terminate(); |
1222 | 0 | } |
1223 | | |
1224 | | |
1225 | | static void wpa_supplicant_terminate(int sig, void *signal_ctx) |
1226 | 0 | { |
1227 | 0 | struct wpa_global *global = signal_ctx; |
1228 | 0 | wpa_supplicant_terminate_proc(global); |
1229 | 0 | } |
1230 | | |
1231 | | |
1232 | | void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s) |
1233 | 0 | { |
1234 | 0 | enum wpa_states old_state = wpa_s->wpa_state; |
1235 | 0 | enum wpa_states new_state; |
1236 | |
|
1237 | 0 | if (old_state == WPA_SCANNING) |
1238 | 0 | new_state = WPA_SCANNING; |
1239 | 0 | else |
1240 | 0 | new_state = WPA_DISCONNECTED; |
1241 | |
|
1242 | 0 | wpa_s->pairwise_cipher = 0; |
1243 | 0 | wpa_s->group_cipher = 0; |
1244 | 0 | wpa_s->mgmt_group_cipher = 0; |
1245 | 0 | wpa_s->key_mgmt = 0; |
1246 | 0 | wpa_s->allowed_key_mgmts = 0; |
1247 | 0 | if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) |
1248 | 0 | wpa_supplicant_set_state(wpa_s, new_state); |
1249 | |
|
1250 | 0 | if (wpa_s->wpa_state != old_state) |
1251 | 0 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); |
1252 | 0 | } |
1253 | | |
1254 | | |
1255 | | /** |
1256 | | * wpa_supplicant_reload_configuration - Reload configuration data |
1257 | | * @wpa_s: Pointer to wpa_supplicant data |
1258 | | * Returns: 0 on success or -1 if configuration parsing failed |
1259 | | * |
1260 | | * This function can be used to request that the configuration data is reloaded |
1261 | | * (e.g., after configuration file change). This function is reloading |
1262 | | * configuration only for one interface, so this may need to be called multiple |
1263 | | * times if %wpa_supplicant is controlling multiple interfaces and all |
1264 | | * interfaces need reconfiguration. |
1265 | | */ |
1266 | | int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s) |
1267 | 0 | { |
1268 | 0 | struct wpa_config *conf; |
1269 | 0 | int reconf_ctrl; |
1270 | 0 | int old_ap_scan; |
1271 | |
|
1272 | 0 | if (wpa_s->confname == NULL) |
1273 | 0 | return -1; |
1274 | 0 | conf = wpa_config_read(wpa_s->confname, NULL, false); |
1275 | 0 | if (conf == NULL) { |
1276 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration " |
1277 | 0 | "file '%s' - exiting", wpa_s->confname); |
1278 | 0 | return -1; |
1279 | 0 | } |
1280 | 0 | if (wpa_s->confanother && |
1281 | 0 | !wpa_config_read(wpa_s->confanother, conf, true)) { |
1282 | 0 | wpa_msg(wpa_s, MSG_ERROR, |
1283 | 0 | "Failed to parse the configuration file '%s' - exiting", |
1284 | 0 | wpa_s->confanother); |
1285 | 0 | return -1; |
1286 | 0 | } |
1287 | | |
1288 | 0 | conf->changed_parameters = (unsigned int) -1; |
1289 | |
|
1290 | 0 | reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface |
1291 | 0 | || (conf->ctrl_interface && wpa_s->conf->ctrl_interface && |
1292 | 0 | os_strcmp(conf->ctrl_interface, |
1293 | 0 | wpa_s->conf->ctrl_interface) != 0); |
1294 | |
|
1295 | 0 | if (reconf_ctrl) { |
1296 | 0 | wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface); |
1297 | 0 | wpa_s->ctrl_iface = NULL; |
1298 | 0 | } |
1299 | |
|
1300 | 0 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
1301 | 0 | if (wpa_s->current_ssid) { |
1302 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
1303 | 0 | wpa_s->own_disconnect_req = 1; |
1304 | 0 | wpa_supplicant_deauthenticate(wpa_s, |
1305 | 0 | WLAN_REASON_DEAUTH_LEAVING); |
1306 | 0 | } |
1307 | | |
1308 | | /* |
1309 | | * TODO: should notify EAPOL SM about changes in opensc_engine_path, |
1310 | | * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers. |
1311 | | */ |
1312 | 0 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
1313 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
1314 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) { |
1315 | | /* |
1316 | | * Clear forced success to clear EAP state for next |
1317 | | * authentication. |
1318 | | */ |
1319 | 0 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
1320 | 0 | } |
1321 | 0 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
1322 | 0 | wpa_sm_set_config(wpa_s->wpa, NULL); |
1323 | 0 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
1324 | 0 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); |
1325 | 0 | rsn_preauth_deinit(wpa_s->wpa); |
1326 | |
|
1327 | 0 | old_ap_scan = wpa_s->conf->ap_scan; |
1328 | 0 | wpa_config_free(wpa_s->conf); |
1329 | 0 | wpa_s->conf = conf; |
1330 | 0 | if (old_ap_scan != wpa_s->conf->ap_scan) |
1331 | 0 | wpas_notify_ap_scan_changed(wpa_s); |
1332 | |
|
1333 | 0 | if (reconf_ctrl) |
1334 | 0 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); |
1335 | |
|
1336 | 0 | wpa_supplicant_update_config(wpa_s); |
1337 | |
|
1338 | 0 | wpa_supplicant_clear_status(wpa_s); |
1339 | 0 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
1340 | 0 | wpa_s->reassociate = 1; |
1341 | 0 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
1342 | 0 | } |
1343 | 0 | wpa_bssid_ignore_clear(wpa_s); |
1344 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed"); |
1345 | 0 | return 0; |
1346 | 0 | } |
1347 | | |
1348 | | |
1349 | | static void wpa_supplicant_reconfig(int sig, void *signal_ctx) |
1350 | 0 | { |
1351 | 0 | struct wpa_global *global = signal_ctx; |
1352 | 0 | struct wpa_supplicant *wpa_s; |
1353 | 0 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
1354 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring", |
1355 | 0 | sig); |
1356 | 0 | if (wpa_supplicant_reload_configuration(wpa_s) < 0) { |
1357 | 0 | wpa_supplicant_terminate_proc(global); |
1358 | 0 | } |
1359 | 0 | } |
1360 | |
|
1361 | 0 | if (wpa_debug_reopen_file() < 0) { |
1362 | | /* Ignore errors since we cannot really do much to fix this */ |
1363 | 0 | wpa_printf(MSG_DEBUG, "Could not reopen debug log file"); |
1364 | 0 | } |
1365 | 0 | } |
1366 | | |
1367 | | |
1368 | | static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s, |
1369 | | struct wpa_ssid *ssid, |
1370 | | struct wpa_ie_data *ie) |
1371 | 0 | { |
1372 | 0 | int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie); |
1373 | 0 | if (ret) { |
1374 | 0 | if (ret == -2) { |
1375 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE " |
1376 | 0 | "from association info"); |
1377 | 0 | } |
1378 | 0 | return -1; |
1379 | 0 | } |
1380 | | |
1381 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set " |
1382 | 0 | "cipher suites"); |
1383 | 0 | if (!(ie->group_cipher & ssid->group_cipher)) { |
1384 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group " |
1385 | 0 | "cipher 0x%x (mask 0x%x) - reject", |
1386 | 0 | ie->group_cipher, ssid->group_cipher); |
1387 | 0 | return -1; |
1388 | 0 | } |
1389 | 0 | if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) { |
1390 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise " |
1391 | 0 | "cipher 0x%x (mask 0x%x) - reject", |
1392 | 0 | ie->pairwise_cipher, ssid->pairwise_cipher); |
1393 | 0 | return -1; |
1394 | 0 | } |
1395 | 0 | if (!(ie->key_mgmt & ssid->key_mgmt)) { |
1396 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key " |
1397 | 0 | "management 0x%x (mask 0x%x) - reject", |
1398 | 0 | ie->key_mgmt, ssid->key_mgmt); |
1399 | 0 | return -1; |
1400 | 0 | } |
1401 | | |
1402 | 0 | if (!(ie->capabilities & WPA_CAPABILITY_MFPC) && |
1403 | 0 | wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) { |
1404 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP " |
1405 | 0 | "that does not support management frame protection - " |
1406 | 0 | "reject"); |
1407 | 0 | return -1; |
1408 | 0 | } |
1409 | | |
1410 | 0 | return 0; |
1411 | 0 | } |
1412 | | |
1413 | | |
1414 | | static int matching_ciphers(struct wpa_ssid *ssid, struct wpa_ie_data *ie, |
1415 | | int freq) |
1416 | 0 | { |
1417 | 0 | if (!ie->has_group) |
1418 | 0 | ie->group_cipher = wpa_default_rsn_cipher(freq); |
1419 | 0 | if (!ie->has_pairwise) |
1420 | 0 | ie->pairwise_cipher = wpa_default_rsn_cipher(freq); |
1421 | 0 | return (ie->group_cipher & ssid->group_cipher) && |
1422 | 0 | (ie->pairwise_cipher & ssid->pairwise_cipher); |
1423 | 0 | } |
1424 | | |
1425 | | |
1426 | | void wpas_set_mgmt_group_cipher(struct wpa_supplicant *wpa_s, |
1427 | | struct wpa_ssid *ssid, struct wpa_ie_data *ie) |
1428 | 0 | { |
1429 | 0 | int sel; |
1430 | |
|
1431 | 0 | sel = ie->mgmt_group_cipher; |
1432 | 0 | if (ssid->group_mgmt_cipher) |
1433 | 0 | sel &= ssid->group_mgmt_cipher; |
1434 | 0 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION || |
1435 | 0 | !(ie->capabilities & WPA_CAPABILITY_MFPC)) |
1436 | 0 | sel = 0; |
1437 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1438 | 0 | "WPA: AP mgmt_group_cipher 0x%x network profile mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x", |
1439 | 0 | ie->mgmt_group_cipher, ssid->group_mgmt_cipher, sel); |
1440 | 0 | if (sel & WPA_CIPHER_AES_128_CMAC) { |
1441 | 0 | wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC; |
1442 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1443 | 0 | "WPA: using MGMT group cipher AES-128-CMAC"); |
1444 | 0 | } else if (sel & WPA_CIPHER_BIP_GMAC_128) { |
1445 | 0 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128; |
1446 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1447 | 0 | "WPA: using MGMT group cipher BIP-GMAC-128"); |
1448 | 0 | } else if (sel & WPA_CIPHER_BIP_GMAC_256) { |
1449 | 0 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256; |
1450 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1451 | 0 | "WPA: using MGMT group cipher BIP-GMAC-256"); |
1452 | 0 | } else if (sel & WPA_CIPHER_BIP_CMAC_256) { |
1453 | 0 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256; |
1454 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1455 | 0 | "WPA: using MGMT group cipher BIP-CMAC-256"); |
1456 | 0 | } else { |
1457 | 0 | wpa_s->mgmt_group_cipher = 0; |
1458 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher"); |
1459 | 0 | } |
1460 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
1461 | 0 | wpa_s->mgmt_group_cipher); |
1462 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, |
1463 | 0 | wpas_get_ssid_pmf(wpa_s, ssid)); |
1464 | 0 | } |
1465 | | |
1466 | | /** |
1467 | | * wpa_supplicant_get_psk - Get PSK from config or external database |
1468 | | * @wpa_s: Pointer to wpa_supplicant data |
1469 | | * @bss: Scan results for the selected BSS, or %NULL if not available |
1470 | | * @ssid: Configuration data for the selected network |
1471 | | * @psk: Buffer for the PSK |
1472 | | * Returns: 0 on success or -1 if configuration parsing failed |
1473 | | * |
1474 | | * This function obtains the PSK for a network, either included inline in the |
1475 | | * config or retrieved from an external database. |
1476 | | */ |
1477 | | static int wpa_supplicant_get_psk(struct wpa_supplicant *wpa_s, |
1478 | | struct wpa_bss *bss, struct wpa_ssid *ssid, |
1479 | | u8 *psk) |
1480 | 0 | { |
1481 | 0 | if (ssid->psk_set) { |
1482 | 0 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (set in config)", |
1483 | 0 | ssid->psk, PMK_LEN); |
1484 | 0 | os_memcpy(psk, ssid->psk, PMK_LEN); |
1485 | 0 | return 0; |
1486 | 0 | } |
1487 | | |
1488 | 0 | #ifndef CONFIG_NO_PBKDF2 |
1489 | 0 | if (bss && ssid->bssid_set && ssid->ssid_len == 0 && ssid->passphrase) { |
1490 | 0 | if (pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len, |
1491 | 0 | 4096, psk, PMK_LEN) != 0) { |
1492 | 0 | wpa_msg(wpa_s, MSG_WARNING, "Error in pbkdf2_sha1()"); |
1493 | 0 | return -1; |
1494 | 0 | } |
1495 | 0 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", |
1496 | 0 | psk, PMK_LEN); |
1497 | 0 | return 0; |
1498 | 0 | } |
1499 | 0 | #endif /* CONFIG_NO_PBKDF2 */ |
1500 | | |
1501 | | #ifdef CONFIG_EXT_PASSWORD |
1502 | | if (ssid->ext_psk) { |
1503 | | struct wpabuf *pw = ext_password_get(wpa_s->ext_pw, |
1504 | | ssid->ext_psk); |
1505 | | char pw_str[64 + 1]; |
1506 | | |
1507 | | if (!pw) { |
1508 | | wpa_msg(wpa_s, MSG_INFO, |
1509 | | "EXT PW: No PSK found from external storage"); |
1510 | | return -1; |
1511 | | } |
1512 | | |
1513 | | if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) { |
1514 | | wpa_msg(wpa_s, MSG_INFO, |
1515 | | "EXT PW: Unexpected PSK length %d in external storage", |
1516 | | (int) wpabuf_len(pw)); |
1517 | | ext_password_free(pw); |
1518 | | return -1; |
1519 | | } |
1520 | | |
1521 | | os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw)); |
1522 | | pw_str[wpabuf_len(pw)] = '\0'; |
1523 | | |
1524 | | #ifndef CONFIG_NO_PBKDF2 |
1525 | | if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss) |
1526 | | { |
1527 | | if (pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len, |
1528 | | 4096, psk, PMK_LEN) != 0) { |
1529 | | wpa_msg(wpa_s, MSG_WARNING, |
1530 | | "Error in pbkdf2_sha1()"); |
1531 | | forced_memzero(pw_str, sizeof(pw_str)); |
1532 | | ext_password_free(pw); |
1533 | | return -1; |
1534 | | } |
1535 | | wpa_hexdump_key(MSG_MSGDUMP, |
1536 | | "PSK (from external passphrase)", |
1537 | | psk, PMK_LEN); |
1538 | | } else |
1539 | | #endif /* CONFIG_NO_PBKDF2 */ |
1540 | | if (wpabuf_len(pw) == 2 * PMK_LEN) { |
1541 | | if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) { |
1542 | | wpa_msg(wpa_s, MSG_INFO, |
1543 | | "EXT PW: Invalid PSK hex string"); |
1544 | | forced_memzero(pw_str, sizeof(pw_str)); |
1545 | | ext_password_free(pw); |
1546 | | return -1; |
1547 | | } |
1548 | | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from external PSK)", |
1549 | | psk, PMK_LEN); |
1550 | | } else { |
1551 | | wpa_msg(wpa_s, MSG_INFO, |
1552 | | "EXT PW: No suitable PSK available"); |
1553 | | forced_memzero(pw_str, sizeof(pw_str)); |
1554 | | ext_password_free(pw); |
1555 | | return -1; |
1556 | | } |
1557 | | |
1558 | | forced_memzero(pw_str, sizeof(pw_str)); |
1559 | | ext_password_free(pw); |
1560 | | |
1561 | | return 0; |
1562 | | } |
1563 | | #endif /* CONFIG_EXT_PASSWORD */ |
1564 | | |
1565 | 0 | return -1; |
1566 | 0 | } |
1567 | | |
1568 | | |
1569 | | static void wpas_update_allowed_key_mgmt(struct wpa_supplicant *wpa_s, |
1570 | | struct wpa_ssid *ssid) |
1571 | 0 | { |
1572 | 0 | int akm_count = wpa_s->max_num_akms; |
1573 | 0 | u8 capab = 0; |
1574 | |
|
1575 | 0 | if (akm_count < 2) |
1576 | 0 | return; |
1577 | | |
1578 | 0 | akm_count--; |
1579 | 0 | wpa_s->allowed_key_mgmts = 0; |
1580 | 0 | switch (wpa_s->key_mgmt) { |
1581 | 0 | case WPA_KEY_MGMT_PSK: |
1582 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) { |
1583 | 0 | akm_count--; |
1584 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE; |
1585 | 0 | } |
1586 | 0 | if (!akm_count) |
1587 | 0 | break; |
1588 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) { |
1589 | 0 | akm_count--; |
1590 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY; |
1591 | 0 | } |
1592 | 0 | if (!akm_count) |
1593 | 0 | break; |
1594 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) |
1595 | 0 | wpa_s->allowed_key_mgmts |= |
1596 | 0 | WPA_KEY_MGMT_PSK_SHA256; |
1597 | 0 | break; |
1598 | 0 | case WPA_KEY_MGMT_PSK_SHA256: |
1599 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) { |
1600 | 0 | akm_count--; |
1601 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE; |
1602 | 0 | } |
1603 | 0 | if (!akm_count) |
1604 | 0 | break; |
1605 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) { |
1606 | 0 | akm_count--; |
1607 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY; |
1608 | 0 | } |
1609 | 0 | if (!akm_count) |
1610 | 0 | break; |
1611 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) |
1612 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK; |
1613 | 0 | break; |
1614 | 0 | case WPA_KEY_MGMT_SAE: |
1615 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) { |
1616 | 0 | akm_count--; |
1617 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK; |
1618 | 0 | } |
1619 | 0 | if (!akm_count) |
1620 | 0 | break; |
1621 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) { |
1622 | 0 | akm_count--; |
1623 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY; |
1624 | 0 | } |
1625 | 0 | if (!akm_count) |
1626 | 0 | break; |
1627 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) |
1628 | 0 | wpa_s->allowed_key_mgmts |= |
1629 | 0 | WPA_KEY_MGMT_PSK_SHA256; |
1630 | 0 | break; |
1631 | 0 | case WPA_KEY_MGMT_SAE_EXT_KEY: |
1632 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) { |
1633 | 0 | akm_count--; |
1634 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE; |
1635 | 0 | } |
1636 | 0 | if (!akm_count) |
1637 | 0 | break; |
1638 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) { |
1639 | 0 | akm_count--; |
1640 | 0 | wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK; |
1641 | 0 | } |
1642 | 0 | if (!akm_count) |
1643 | 0 | break; |
1644 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256) |
1645 | 0 | wpa_s->allowed_key_mgmts |= |
1646 | 0 | WPA_KEY_MGMT_PSK_SHA256; |
1647 | 0 | break; |
1648 | 0 | default: |
1649 | 0 | return; |
1650 | 0 | } |
1651 | | |
1652 | 0 | if (wpa_s->conf->sae_pwe != SAE_PWE_HUNT_AND_PECK && |
1653 | 0 | wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK) |
1654 | 0 | capab |= BIT(WLAN_RSNX_CAPAB_SAE_H2E); |
1655 | | #ifdef CONFIG_SAE_PK |
1656 | | if (ssid->sae_pk) |
1657 | | capab |= BIT(WLAN_RSNX_CAPAB_SAE_PK); |
1658 | | #endif /* CONFIG_SAE_PK */ |
1659 | |
|
1660 | 0 | if (!((wpa_s->allowed_key_mgmts & |
1661 | 0 | (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_SAE_EXT_KEY)) && capab)) |
1662 | 0 | return; |
1663 | | |
1664 | 0 | if (!wpa_s->rsnxe_len) { |
1665 | 0 | wpa_s->rsnxe_len = 3; |
1666 | 0 | wpa_s->rsnxe[0] = WLAN_EID_RSNX; |
1667 | 0 | wpa_s->rsnxe[1] = 1; |
1668 | 0 | wpa_s->rsnxe[2] = 0; |
1669 | 0 | } |
1670 | |
|
1671 | 0 | wpa_s->rsnxe[2] |= capab; |
1672 | 0 | } |
1673 | | |
1674 | | |
1675 | | /** |
1676 | | * wpa_supplicant_set_suites - Set authentication and encryption parameters |
1677 | | * @wpa_s: Pointer to wpa_supplicant data |
1678 | | * @bss: Scan results for the selected BSS, or %NULL if not available |
1679 | | * @ssid: Configuration data for the selected network |
1680 | | * @wpa_ie: Buffer for the WPA/RSN IE |
1681 | | * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the |
1682 | | * used buffer length in case the functions returns success. |
1683 | | * @skip_default_rsne: Whether to skip setting of the default RSNE/RSNXE |
1684 | | * Returns: 0 on success or -1 on failure |
1685 | | * |
1686 | | * This function is used to configure authentication and encryption parameters |
1687 | | * based on the network configuration and scan result for the selected BSS (if |
1688 | | * available). |
1689 | | */ |
1690 | | int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, |
1691 | | struct wpa_bss *bss, struct wpa_ssid *ssid, |
1692 | | u8 *wpa_ie, size_t *wpa_ie_len, |
1693 | | bool skip_default_rsne) |
1694 | 0 | { |
1695 | 0 | struct wpa_ie_data ie; |
1696 | 0 | int sel, proto; |
1697 | 0 | enum sae_pwe sae_pwe; |
1698 | 0 | const u8 *bss_wpa, *bss_rsn, *bss_rsnx, *bss_osen; |
1699 | 0 | bool wmm; |
1700 | |
|
1701 | 0 | if (bss) { |
1702 | 0 | bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
1703 | 0 | bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid, false); |
1704 | 0 | bss_rsnx = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false); |
1705 | 0 | bss_osen = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
1706 | 0 | } else { |
1707 | 0 | bss_wpa = bss_rsn = bss_rsnx = bss_osen = NULL; |
1708 | 0 | } |
1709 | |
|
1710 | 0 | if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) && |
1711 | 0 | wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 && |
1712 | 0 | matching_ciphers(ssid, &ie, bss->freq) && |
1713 | 0 | (ie.key_mgmt & ssid->key_mgmt)) { |
1714 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0"); |
1715 | 0 | proto = WPA_PROTO_RSN; |
1716 | 0 | } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) && |
1717 | 0 | wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 && |
1718 | 0 | (ie.group_cipher & ssid->group_cipher) && |
1719 | 0 | (ie.pairwise_cipher & ssid->pairwise_cipher) && |
1720 | 0 | (ie.key_mgmt & ssid->key_mgmt)) { |
1721 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0"); |
1722 | 0 | proto = WPA_PROTO_WPA; |
1723 | 0 | #ifdef CONFIG_HS20 |
1724 | 0 | } else if (bss_osen && (ssid->proto & WPA_PROTO_OSEN) && |
1725 | 0 | wpa_parse_wpa_ie(bss_osen, 2 + bss_osen[1], &ie) == 0 && |
1726 | 0 | (ie.group_cipher & ssid->group_cipher) && |
1727 | 0 | (ie.pairwise_cipher & ssid->pairwise_cipher) && |
1728 | 0 | (ie.key_mgmt & ssid->key_mgmt)) { |
1729 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using OSEN"); |
1730 | 0 | proto = WPA_PROTO_OSEN; |
1731 | 0 | } else if (bss_rsn && (ssid->proto & WPA_PROTO_OSEN) && |
1732 | 0 | wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 && |
1733 | 0 | (ie.group_cipher & ssid->group_cipher) && |
1734 | 0 | (ie.pairwise_cipher & ssid->pairwise_cipher) && |
1735 | 0 | (ie.key_mgmt & ssid->key_mgmt)) { |
1736 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using OSEN (within RSN)"); |
1737 | 0 | proto = WPA_PROTO_RSN; |
1738 | 0 | #endif /* CONFIG_HS20 */ |
1739 | 0 | } else if (bss) { |
1740 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN"); |
1741 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1742 | 0 | "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
1743 | 0 | ssid->proto, ssid->pairwise_cipher, ssid->group_cipher, |
1744 | 0 | ssid->key_mgmt); |
1745 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s%s", |
1746 | 0 | MAC2STR(bss->bssid), |
1747 | 0 | wpa_ssid_txt(bss->ssid, bss->ssid_len), |
1748 | 0 | bss_wpa ? " WPA" : "", |
1749 | 0 | bss_rsn ? " RSN" : "", |
1750 | 0 | bss_osen ? " OSEN" : ""); |
1751 | 0 | if (bss_rsn) { |
1752 | 0 | wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]); |
1753 | 0 | if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) { |
1754 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1755 | 0 | "Could not parse RSN element"); |
1756 | 0 | } else { |
1757 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1758 | 0 | "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
1759 | 0 | ie.pairwise_cipher, ie.group_cipher, |
1760 | 0 | ie.key_mgmt); |
1761 | 0 | } |
1762 | 0 | } |
1763 | 0 | if (bss_wpa) { |
1764 | 0 | wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]); |
1765 | 0 | if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) { |
1766 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1767 | 0 | "Could not parse WPA element"); |
1768 | 0 | } else { |
1769 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1770 | 0 | "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
1771 | 0 | ie.pairwise_cipher, ie.group_cipher, |
1772 | 0 | ie.key_mgmt); |
1773 | 0 | } |
1774 | 0 | } |
1775 | 0 | return -1; |
1776 | 0 | } else { |
1777 | 0 | if (ssid->proto & WPA_PROTO_OSEN) |
1778 | 0 | proto = WPA_PROTO_OSEN; |
1779 | 0 | else if (ssid->proto & WPA_PROTO_RSN) |
1780 | 0 | proto = WPA_PROTO_RSN; |
1781 | 0 | else |
1782 | 0 | proto = WPA_PROTO_WPA; |
1783 | 0 | if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) { |
1784 | 0 | os_memset(&ie, 0, sizeof(ie)); |
1785 | 0 | ie.group_cipher = ssid->group_cipher; |
1786 | 0 | ie.pairwise_cipher = ssid->pairwise_cipher; |
1787 | 0 | ie.key_mgmt = ssid->key_mgmt; |
1788 | 0 | ie.mgmt_group_cipher = 0; |
1789 | 0 | if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
1790 | 0 | if (ssid->group_mgmt_cipher & |
1791 | 0 | WPA_CIPHER_BIP_GMAC_256) |
1792 | 0 | ie.mgmt_group_cipher = |
1793 | 0 | WPA_CIPHER_BIP_GMAC_256; |
1794 | 0 | else if (ssid->group_mgmt_cipher & |
1795 | 0 | WPA_CIPHER_BIP_CMAC_256) |
1796 | 0 | ie.mgmt_group_cipher = |
1797 | 0 | WPA_CIPHER_BIP_CMAC_256; |
1798 | 0 | else if (ssid->group_mgmt_cipher & |
1799 | 0 | WPA_CIPHER_BIP_GMAC_128) |
1800 | 0 | ie.mgmt_group_cipher = |
1801 | 0 | WPA_CIPHER_BIP_GMAC_128; |
1802 | 0 | else |
1803 | 0 | ie.mgmt_group_cipher = |
1804 | 0 | WPA_CIPHER_AES_128_CMAC; |
1805 | 0 | } |
1806 | | #ifdef CONFIG_OWE |
1807 | | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
1808 | | !ssid->owe_only && |
1809 | | !bss_wpa && !bss_rsn && !bss_osen) { |
1810 | | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
1811 | | wpa_s->wpa_proto = 0; |
1812 | | *wpa_ie_len = 0; |
1813 | | return 0; |
1814 | | } |
1815 | | #endif /* CONFIG_OWE */ |
1816 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites " |
1817 | 0 | "based on configuration"); |
1818 | 0 | } else |
1819 | 0 | proto = ie.proto; |
1820 | 0 | } |
1821 | | |
1822 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d " |
1823 | 0 | "pairwise %d key_mgmt %d proto %d", |
1824 | 0 | ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto); |
1825 | 0 | if (ssid->ieee80211w) { |
1826 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d", |
1827 | 0 | ie.mgmt_group_cipher); |
1828 | 0 | } |
1829 | |
|
1830 | 0 | wpa_s->wpa_proto = proto; |
1831 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto); |
1832 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, |
1833 | 0 | !!(ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN))); |
1834 | |
|
1835 | 0 | if (bss || !wpa_s->ap_ies_from_associnfo) { |
1836 | 0 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, |
1837 | 0 | bss_wpa ? 2 + bss_wpa[1] : 0) || |
1838 | 0 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, |
1839 | 0 | bss_rsn ? 2 + bss_rsn[1] : 0) || |
1840 | 0 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx, |
1841 | 0 | bss_rsnx ? 2 + bss_rsnx[1] : 0)) |
1842 | 0 | return -1; |
1843 | 0 | } |
1844 | | |
1845 | | #ifdef CONFIG_NO_WPA |
1846 | | wpa_s->group_cipher = WPA_CIPHER_NONE; |
1847 | | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; |
1848 | | #else /* CONFIG_NO_WPA */ |
1849 | 0 | sel = ie.group_cipher & ssid->group_cipher; |
1850 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1851 | 0 | "WPA: AP group 0x%x network profile group 0x%x; available group 0x%x", |
1852 | 0 | ie.group_cipher, ssid->group_cipher, sel); |
1853 | 0 | wpa_s->group_cipher = wpa_pick_group_cipher(sel); |
1854 | 0 | if (wpa_s->group_cipher < 0) { |
1855 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group " |
1856 | 0 | "cipher"); |
1857 | 0 | return -1; |
1858 | 0 | } |
1859 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s", |
1860 | 0 | wpa_cipher_txt(wpa_s->group_cipher)); |
1861 | |
|
1862 | 0 | sel = ie.pairwise_cipher & ssid->pairwise_cipher; |
1863 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1864 | 0 | "WPA: AP pairwise 0x%x network profile pairwise 0x%x; available pairwise 0x%x", |
1865 | 0 | ie.pairwise_cipher, ssid->pairwise_cipher, sel); |
1866 | 0 | wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1); |
1867 | 0 | if (wpa_s->pairwise_cipher < 0) { |
1868 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise " |
1869 | 0 | "cipher"); |
1870 | 0 | return -1; |
1871 | 0 | } |
1872 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s", |
1873 | 0 | wpa_cipher_txt(wpa_s->pairwise_cipher)); |
1874 | 0 | #endif /* CONFIG_NO_WPA */ |
1875 | |
|
1876 | 0 | sel = ie.key_mgmt & ssid->key_mgmt; |
1877 | | #ifdef CONFIG_SAE |
1878 | | if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) && |
1879 | | !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA)) || |
1880 | | wpas_is_sae_avoided(wpa_s, ssid, &ie)) |
1881 | | sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_SAE_EXT_KEY | |
1882 | | WPA_KEY_MGMT_FT_SAE | WPA_KEY_MGMT_FT_SAE_EXT_KEY); |
1883 | | #endif /* CONFIG_SAE */ |
1884 | | #ifdef CONFIG_IEEE80211R |
1885 | | if (!(wpa_s->drv_flags & (WPA_DRIVER_FLAGS_SME | |
1886 | | WPA_DRIVER_FLAGS_UPDATE_FT_IES))) |
1887 | | sel &= ~WPA_KEY_MGMT_FT; |
1888 | | #endif /* CONFIG_IEEE80211R */ |
1889 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1890 | 0 | "WPA: AP key_mgmt 0x%x network profile key_mgmt 0x%x; available key_mgmt 0x%x", |
1891 | 0 | ie.key_mgmt, ssid->key_mgmt, sel); |
1892 | 0 | if (0) { |
1893 | | #ifdef CONFIG_IEEE80211R |
1894 | | #ifdef CONFIG_SHA384 |
1895 | | } else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) && |
1896 | | os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) { |
1897 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384; |
1898 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1899 | | "WPA: using KEY_MGMT FT/802.1X-SHA384"); |
1900 | | if (!ssid->ft_eap_pmksa_caching && |
1901 | | pmksa_cache_get_current(wpa_s->wpa)) { |
1902 | | /* PMKSA caching with FT may have interoperability |
1903 | | * issues, so disable that case by default for now. */ |
1904 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1905 | | "WPA: Disable PMKSA caching for FT/802.1X connection"); |
1906 | | pmksa_cache_clear_current(wpa_s->wpa); |
1907 | | } |
1908 | | #endif /* CONFIG_SHA384 */ |
1909 | | #endif /* CONFIG_IEEE80211R */ |
1910 | | #ifdef CONFIG_SUITEB192 |
1911 | | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
1912 | | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; |
1913 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1914 | | "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)"); |
1915 | | #endif /* CONFIG_SUITEB192 */ |
1916 | | #ifdef CONFIG_SUITEB |
1917 | | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
1918 | | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B; |
1919 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1920 | | "WPA: using KEY_MGMT 802.1X with Suite B"); |
1921 | | #endif /* CONFIG_SUITEB */ |
1922 | | #ifdef CONFIG_SHA384 |
1923 | | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA384) { |
1924 | | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA384; |
1925 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1926 | | "WPA: using KEY_MGMT 802.1X with SHA384"); |
1927 | | #endif /* CONFIG_SHA384 */ |
1928 | | #ifdef CONFIG_FILS |
1929 | | #ifdef CONFIG_IEEE80211R |
1930 | | } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA384) { |
1931 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384; |
1932 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA384"); |
1933 | | #endif /* CONFIG_IEEE80211R */ |
1934 | | } else if (sel & WPA_KEY_MGMT_FILS_SHA384) { |
1935 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA384; |
1936 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA384"); |
1937 | | #ifdef CONFIG_IEEE80211R |
1938 | | } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA256) { |
1939 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256; |
1940 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA256"); |
1941 | | #endif /* CONFIG_IEEE80211R */ |
1942 | | } else if (sel & WPA_KEY_MGMT_FILS_SHA256) { |
1943 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA256; |
1944 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA256"); |
1945 | | #endif /* CONFIG_FILS */ |
1946 | | #ifdef CONFIG_IEEE80211R |
1947 | | } else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X) && |
1948 | | os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) { |
1949 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X; |
1950 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X"); |
1951 | | if (!ssid->ft_eap_pmksa_caching && |
1952 | | pmksa_cache_get_current(wpa_s->wpa)) { |
1953 | | /* PMKSA caching with FT may have interoperability |
1954 | | * issues, so disable that case by default for now. */ |
1955 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1956 | | "WPA: Disable PMKSA caching for FT/802.1X connection"); |
1957 | | pmksa_cache_clear_current(wpa_s->wpa); |
1958 | | } |
1959 | | #endif /* CONFIG_IEEE80211R */ |
1960 | | #ifdef CONFIG_DPP |
1961 | | } else if (sel & WPA_KEY_MGMT_DPP) { |
1962 | | wpa_s->key_mgmt = WPA_KEY_MGMT_DPP; |
1963 | | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT DPP"); |
1964 | | #endif /* CONFIG_DPP */ |
1965 | | #ifdef CONFIG_SAE |
1966 | | } else if (sel & WPA_KEY_MGMT_FT_SAE_EXT_KEY) { |
1967 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE_EXT_KEY; |
1968 | | wpa_dbg(wpa_s, MSG_DEBUG, |
1969 | | "RSN: using KEY_MGMT FT/SAE (ext key)"); |
1970 | | } else if (sel & WPA_KEY_MGMT_SAE_EXT_KEY) { |
1971 | | wpa_s->key_mgmt = WPA_KEY_MGMT_SAE_EXT_KEY; |
1972 | | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE (ext key)"); |
1973 | | } else if (sel & WPA_KEY_MGMT_FT_SAE) { |
1974 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE; |
1975 | | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE"); |
1976 | | } else if (sel & WPA_KEY_MGMT_SAE) { |
1977 | | wpa_s->key_mgmt = WPA_KEY_MGMT_SAE; |
1978 | | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE"); |
1979 | | #endif /* CONFIG_SAE */ |
1980 | | #ifdef CONFIG_IEEE80211R |
1981 | | } else if (sel & WPA_KEY_MGMT_FT_PSK) { |
1982 | | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK; |
1983 | | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK"); |
1984 | | #endif /* CONFIG_IEEE80211R */ |
1985 | 0 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
1986 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256; |
1987 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1988 | 0 | "WPA: using KEY_MGMT 802.1X with SHA256"); |
1989 | 0 | } else if (sel & WPA_KEY_MGMT_PSK_SHA256) { |
1990 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256; |
1991 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
1992 | 0 | "WPA: using KEY_MGMT PSK with SHA256"); |
1993 | 0 | } else if (sel & WPA_KEY_MGMT_IEEE8021X) { |
1994 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X; |
1995 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X"); |
1996 | 0 | } else if (sel & WPA_KEY_MGMT_PSK) { |
1997 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; |
1998 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK"); |
1999 | 0 | } else if (sel & WPA_KEY_MGMT_WPA_NONE) { |
2000 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE; |
2001 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE"); |
2002 | 0 | #ifdef CONFIG_HS20 |
2003 | 0 | } else if (sel & WPA_KEY_MGMT_OSEN) { |
2004 | 0 | wpa_s->key_mgmt = WPA_KEY_MGMT_OSEN; |
2005 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using KEY_MGMT OSEN"); |
2006 | 0 | #endif /* CONFIG_HS20 */ |
2007 | | #ifdef CONFIG_OWE |
2008 | | } else if (sel & WPA_KEY_MGMT_OWE) { |
2009 | | wpa_s->key_mgmt = WPA_KEY_MGMT_OWE; |
2010 | | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT OWE"); |
2011 | | #endif /* CONFIG_OWE */ |
2012 | 0 | } else { |
2013 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select " |
2014 | 0 | "authenticated key management type"); |
2015 | 0 | return -1; |
2016 | 0 | } |
2017 | | |
2018 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
2019 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
2020 | 0 | wpa_s->pairwise_cipher); |
2021 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
2022 | |
|
2023 | 0 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
2024 | 0 | (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED || |
2025 | 0 | (bss && is_6ghz_freq(bss->freq)))) { |
2026 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2027 | 0 | "RSN: Management frame protection required but the selected AP does not enable it"); |
2028 | 0 | return -1; |
2029 | 0 | } |
2030 | | |
2031 | 0 | wpas_set_mgmt_group_cipher(wpa_s, ssid, &ie); |
2032 | | #ifdef CONFIG_OCV |
2033 | | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
2034 | | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) |
2035 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, ssid->ocv); |
2036 | | #endif /* CONFIG_OCV */ |
2037 | 0 | sae_pwe = wpa_s->conf->sae_pwe; |
2038 | 0 | if ((ssid->sae_password_id || |
2039 | 0 | wpa_key_mgmt_sae_ext_key(wpa_s->key_mgmt)) && |
2040 | 0 | sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK) |
2041 | 0 | sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
2042 | 0 | if (bss && is_6ghz_freq(bss->freq) && |
2043 | 0 | sae_pwe == SAE_PWE_HUNT_AND_PECK) { |
2044 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
2045 | 0 | "RSN: Enable SAE hash-to-element mode for 6 GHz BSS"); |
2046 | 0 | sae_pwe = SAE_PWE_BOTH; |
2047 | 0 | } |
2048 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SAE_PWE, sae_pwe); |
2049 | | #ifdef CONFIG_SAE_PK |
2050 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SAE_PK, |
2051 | | wpa_key_mgmt_sae(ssid->key_mgmt) && |
2052 | | ssid->sae_pk != SAE_PK_MODE_DISABLED && |
2053 | | ((ssid->sae_password && |
2054 | | sae_pk_valid_password(ssid->sae_password)) || |
2055 | | (!ssid->sae_password && ssid->passphrase && |
2056 | | sae_pk_valid_password(ssid->passphrase)))); |
2057 | | #endif /* CONFIG_SAE_PK */ |
2058 | 0 | if (bss && is_6ghz_freq(bss->freq) && |
2059 | 0 | wpas_get_ssid_pmf(wpa_s, ssid) != MGMT_FRAME_PROTECTION_REQUIRED) { |
2060 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: Force MFPR=1 on 6 GHz"); |
2061 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, |
2062 | 0 | MGMT_FRAME_PROTECTION_REQUIRED); |
2063 | 0 | } |
2064 | | #ifdef CONFIG_TESTING_OPTIONS |
2065 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_RSNXE_USED, |
2066 | | wpa_s->ft_rsnxe_used); |
2067 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL, |
2068 | | wpa_s->oci_freq_override_eapol); |
2069 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2, |
2070 | | wpa_s->oci_freq_override_eapol_g2); |
2071 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC, |
2072 | | wpa_s->oci_freq_override_ft_assoc); |
2073 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FILS_ASSOC, |
2074 | | wpa_s->oci_freq_override_fils_assoc); |
2075 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX, |
2076 | | wpa_s->disable_eapol_g2_tx); |
2077 | | #endif /* CONFIG_TESTING_OPTIONS */ |
2078 | | |
2079 | | /* Extended Key ID is only supported in infrastructure BSS so far */ |
2080 | 0 | if (ssid->mode == WPAS_MODE_INFRA && wpa_s->conf->extended_key_id && |
2081 | 0 | (ssid->proto & WPA_PROTO_RSN) && |
2082 | 0 | ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 | |
2083 | 0 | WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256) && |
2084 | 0 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_EXTENDED_KEY_ID)) { |
2085 | 0 | int use_ext_key_id = 0; |
2086 | |
|
2087 | 0 | wpa_msg(wpa_s, MSG_DEBUG, |
2088 | 0 | "WPA: Enable Extended Key ID support"); |
2089 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_EXT_KEY_ID, |
2090 | 0 | wpa_s->conf->extended_key_id); |
2091 | 0 | if (bss_rsn && |
2092 | 0 | wpa_s->conf->extended_key_id && |
2093 | 0 | wpa_s->pairwise_cipher != WPA_CIPHER_TKIP && |
2094 | 0 | (ie.capabilities & WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST)) |
2095 | 0 | use_ext_key_id = 1; |
2096 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_USE_EXT_KEY_ID, |
2097 | 0 | use_ext_key_id); |
2098 | 0 | } else { |
2099 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_EXT_KEY_ID, 0); |
2100 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_USE_EXT_KEY_ID, 0); |
2101 | 0 | } |
2102 | | |
2103 | | /* Mark WMM enabled for any HT/VHT/HE/EHT association to get more |
2104 | | * appropriate advertisement of the supported number of PTKSA receive |
2105 | | * counters. In theory, this could be based on a driver capability, but |
2106 | | * in practice all cases using WMM support at least eight replay |
2107 | | * counters, so use a hardcoded value for now since there is no explicit |
2108 | | * driver capability indication for this. |
2109 | | * |
2110 | | * In addition, claim WMM to be enabled if the AP supports it since it |
2111 | | * is far more likely for any current device to support WMM. */ |
2112 | 0 | wmm = wpa_s->connection_set && |
2113 | 0 | (wpa_s->connection_ht || wpa_s->connection_vht || |
2114 | 0 | wpa_s->connection_he || wpa_s->connection_eht); |
2115 | 0 | if (!wmm && bss) |
2116 | 0 | wmm = !!wpa_bss_get_vendor_ie(bss, WMM_IE_VENDOR_TYPE); |
2117 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_WMM_ENABLED, wmm); |
2118 | |
|
2119 | 0 | if (ssid->ssid_protection && proto == WPA_PROTO_RSN) { |
2120 | 0 | bool ssid_prot; |
2121 | | |
2122 | | /* Enable SSID protection based on the AP advertising support |
2123 | | * for it to avoid potential interoperability issues with |
2124 | | * incorrect AP behavior if we were to send an "unexpected" |
2125 | | * RSNXE with multiple octets of payload. */ |
2126 | 0 | ssid_prot = ieee802_11_rsnx_capab( |
2127 | 0 | bss_rsnx, WLAN_RSNX_CAPAB_SSID_PROTECTION); |
2128 | 0 | if (!skip_default_rsne) |
2129 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION, |
2130 | 0 | proto == WPA_PROTO_RSN && ssid_prot); |
2131 | 0 | } else { |
2132 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION, false); |
2133 | 0 | } |
2134 | |
|
2135 | 0 | if (!skip_default_rsne) { |
2136 | 0 | if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, |
2137 | 0 | wpa_ie_len)) { |
2138 | 0 | wpa_msg(wpa_s, MSG_WARNING, |
2139 | 0 | "RSN: Failed to generate RSNE/WPA IE"); |
2140 | 0 | return -1; |
2141 | 0 | } |
2142 | | |
2143 | 0 | wpa_s->rsnxe_len = sizeof(wpa_s->rsnxe); |
2144 | 0 | if (wpa_sm_set_assoc_rsnxe_default(wpa_s->wpa, wpa_s->rsnxe, |
2145 | 0 | &wpa_s->rsnxe_len)) { |
2146 | 0 | wpa_msg(wpa_s, MSG_WARNING, |
2147 | 0 | "RSN: Failed to generate RSNXE"); |
2148 | 0 | return -1; |
2149 | 0 | } |
2150 | 0 | } |
2151 | | |
2152 | 0 | if (0) { |
2153 | | #ifdef CONFIG_DPP |
2154 | | } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) { |
2155 | | /* Use PMK from DPP network introduction (PMKSA entry) */ |
2156 | | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
2157 | | #ifdef CONFIG_DPP2 |
2158 | | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DPP_PFS, ssid->dpp_pfs); |
2159 | | #endif /* CONFIG_DPP2 */ |
2160 | | #endif /* CONFIG_DPP */ |
2161 | 0 | } else if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) { |
2162 | 0 | int psk_set = 0; |
2163 | |
|
2164 | 0 | if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) { |
2165 | 0 | u8 psk[PMK_LEN]; |
2166 | |
|
2167 | 0 | if (wpa_supplicant_get_psk(wpa_s, bss, ssid, |
2168 | 0 | psk) == 0) { |
2169 | 0 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL, |
2170 | 0 | NULL); |
2171 | 0 | psk_set = 1; |
2172 | 0 | } |
2173 | 0 | forced_memzero(psk, sizeof(psk)); |
2174 | 0 | } |
2175 | |
|
2176 | 0 | if (wpa_key_mgmt_sae(ssid->key_mgmt) && |
2177 | 0 | (ssid->sae_password || ssid->passphrase || ssid->ext_psk)) |
2178 | 0 | psk_set = 1; |
2179 | |
|
2180 | 0 | if (!psk_set) { |
2181 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2182 | 0 | "No PSK available for association"); |
2183 | 0 | wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL); |
2184 | 0 | return -1; |
2185 | 0 | } |
2186 | | #ifdef CONFIG_OWE |
2187 | | } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) { |
2188 | | /* OWE Diffie-Hellman exchange in (Re)Association |
2189 | | * Request/Response frames set the PMK, so do not override it |
2190 | | * here. */ |
2191 | | #endif /* CONFIG_OWE */ |
2192 | 0 | } else |
2193 | 0 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
2194 | | |
2195 | 0 | if (ssid->mode != WPAS_MODE_IBSS && |
2196 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED) && |
2197 | 0 | (ssid->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_NEVER || |
2198 | 0 | (ssid->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_LOCAL_OK && |
2199 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS)))) { |
2200 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2201 | 0 | "Disable PTK0 rekey support - replaced with reconnect"); |
2202 | 0 | wpa_s->deny_ptk0_rekey = 1; |
2203 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DENY_PTK0_REKEY, 1); |
2204 | 0 | } else { |
2205 | 0 | wpa_s->deny_ptk0_rekey = 0; |
2206 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DENY_PTK0_REKEY, 0); |
2207 | 0 | } |
2208 | |
|
2209 | 0 | if (wpa_key_mgmt_cross_akm(wpa_s->key_mgmt) && |
2210 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
2211 | 0 | wpas_update_allowed_key_mgmt(wpa_s, ssid); |
2212 | |
|
2213 | 0 | return 0; |
2214 | 0 | } |
2215 | | |
2216 | | |
2217 | | static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx, |
2218 | | struct wpa_bss *bss) |
2219 | 0 | { |
2220 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
2221 | 0 | bool scs = true, mscs = true; |
2222 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
2223 | |
|
2224 | 0 | *pos = 0x00; |
2225 | |
|
2226 | 0 | switch (idx) { |
2227 | 0 | case 0: /* Bits 0-7 */ |
2228 | 0 | break; |
2229 | 0 | case 1: /* Bits 8-15 */ |
2230 | 0 | if (wpa_s->conf->coloc_intf_reporting) { |
2231 | | /* Bit 13 - Collocated Interference Reporting */ |
2232 | 0 | *pos |= 0x20; |
2233 | 0 | } |
2234 | 0 | break; |
2235 | 0 | case 2: /* Bits 16-23 */ |
2236 | 0 | #ifdef CONFIG_WNM |
2237 | 0 | *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */ |
2238 | 0 | if ((wpas_driver_bss_selection(wpa_s) || |
2239 | 0 | !wpa_s->disable_mbo_oce) && |
2240 | 0 | !wpa_s->conf->disable_btm) |
2241 | 0 | *pos |= 0x08; /* Bit 19 - BSS Transition */ |
2242 | 0 | #endif /* CONFIG_WNM */ |
2243 | 0 | break; |
2244 | 0 | case 3: /* Bits 24-31 */ |
2245 | 0 | #ifdef CONFIG_WNM |
2246 | 0 | *pos |= 0x02; /* Bit 25 - SSID List */ |
2247 | 0 | #endif /* CONFIG_WNM */ |
2248 | 0 | #ifdef CONFIG_INTERWORKING |
2249 | 0 | if (wpa_s->conf->interworking) |
2250 | 0 | *pos |= 0x80; /* Bit 31 - Interworking */ |
2251 | 0 | #endif /* CONFIG_INTERWORKING */ |
2252 | 0 | break; |
2253 | 0 | case 4: /* Bits 32-39 */ |
2254 | 0 | #ifdef CONFIG_INTERWORKING |
2255 | 0 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_QOS_MAPPING) |
2256 | 0 | *pos |= 0x01; /* Bit 32 - QoS Map */ |
2257 | 0 | #endif /* CONFIG_INTERWORKING */ |
2258 | 0 | break; |
2259 | 0 | case 5: /* Bits 40-47 */ |
2260 | 0 | #ifdef CONFIG_HS20 |
2261 | 0 | if (wpa_s->conf->hs20) |
2262 | 0 | *pos |= 0x40; /* Bit 46 - WNM-Notification */ |
2263 | 0 | #endif /* CONFIG_HS20 */ |
2264 | | #ifdef CONFIG_MBO |
2265 | | *pos |= 0x40; /* Bit 46 - WNM-Notification */ |
2266 | | #endif /* CONFIG_MBO */ |
2267 | 0 | break; |
2268 | 0 | case 6: /* Bits 48-55 */ |
2269 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
2270 | | #ifdef CONFIG_TESTING_OPTIONS |
2271 | | if (wpa_s->disable_scs_support) |
2272 | | scs = false; |
2273 | | #endif /* CONFIG_TESTING_OPTIONS */ |
2274 | 0 | if (bss && !wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_SCS)) { |
2275 | | /* Drop own SCS capability indication since the AP does |
2276 | | * not support it. This is needed to avoid |
2277 | | * interoperability issues with APs that get confused |
2278 | | * with Extended Capabilities element. */ |
2279 | 0 | scs = false; |
2280 | 0 | } |
2281 | 0 | if (scs) |
2282 | 0 | *pos |= 0x40; /* Bit 54 - SCS */ |
2283 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
2284 | 0 | break; |
2285 | 0 | case 7: /* Bits 56-63 */ |
2286 | 0 | break; |
2287 | 0 | case 8: /* Bits 64-71 */ |
2288 | 0 | if (wpa_s->conf->ftm_responder) |
2289 | 0 | *pos |= 0x40; /* Bit 70 - FTM responder */ |
2290 | 0 | if (wpa_s->conf->ftm_initiator) |
2291 | 0 | *pos |= 0x80; /* Bit 71 - FTM initiator */ |
2292 | 0 | break; |
2293 | 0 | case 9: /* Bits 72-79 */ |
2294 | | #ifdef CONFIG_FILS |
2295 | | if (!wpa_s->disable_fils) |
2296 | | *pos |= 0x01; |
2297 | | #endif /* CONFIG_FILS */ |
2298 | 0 | break; |
2299 | 0 | case 10: /* Bits 80-87 */ |
2300 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
2301 | | #ifdef CONFIG_TESTING_OPTIONS |
2302 | | if (wpa_s->disable_mscs_support) |
2303 | | mscs = false; |
2304 | | #endif /* CONFIG_TESTING_OPTIONS */ |
2305 | 0 | if (bss && !wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_MSCS)) { |
2306 | | /* Drop own MSCS capability indication since the AP does |
2307 | | * not support it. This is needed to avoid |
2308 | | * interoperability issues with APs that get confused |
2309 | | * with Extended Capabilities element. */ |
2310 | 0 | mscs = false; |
2311 | 0 | } |
2312 | 0 | if (mscs) |
2313 | 0 | *pos |= 0x20; /* Bit 85 - Mirrored SCS */ |
2314 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
2315 | 0 | break; |
2316 | 0 | } |
2317 | 0 | } |
2318 | | |
2319 | | |
2320 | | int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf, |
2321 | | size_t buflen, struct wpa_bss *bss) |
2322 | 0 | { |
2323 | 0 | u8 *pos = buf; |
2324 | 0 | u8 len = 11, i; |
2325 | |
|
2326 | 0 | if (len < wpa_s->extended_capa_len) |
2327 | 0 | len = wpa_s->extended_capa_len; |
2328 | 0 | if (buflen < (size_t) len + 2) { |
2329 | 0 | wpa_printf(MSG_INFO, |
2330 | 0 | "Not enough room for building extended capabilities element"); |
2331 | 0 | return -1; |
2332 | 0 | } |
2333 | | |
2334 | 0 | *pos++ = WLAN_EID_EXT_CAPAB; |
2335 | 0 | *pos++ = len; |
2336 | 0 | for (i = 0; i < len; i++, pos++) { |
2337 | 0 | wpas_ext_capab_byte(wpa_s, pos, i, bss); |
2338 | |
|
2339 | 0 | if (i < wpa_s->extended_capa_len) { |
2340 | 0 | *pos &= ~wpa_s->extended_capa_mask[i]; |
2341 | 0 | *pos |= wpa_s->extended_capa[i]; |
2342 | 0 | } |
2343 | 0 | } |
2344 | |
|
2345 | 0 | while (len > 0 && buf[1 + len] == 0) { |
2346 | 0 | len--; |
2347 | 0 | buf[1] = len; |
2348 | 0 | } |
2349 | 0 | if (len == 0) |
2350 | 0 | return 0; |
2351 | | |
2352 | 0 | return 2 + len; |
2353 | 0 | } |
2354 | | |
2355 | | |
2356 | | static int wpas_valid_bss(struct wpa_supplicant *wpa_s, |
2357 | | struct wpa_bss *test_bss) |
2358 | 0 | { |
2359 | 0 | struct wpa_bss *bss; |
2360 | |
|
2361 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
2362 | 0 | if (bss == test_bss) |
2363 | 0 | return 1; |
2364 | 0 | } |
2365 | | |
2366 | 0 | return 0; |
2367 | 0 | } |
2368 | | |
2369 | | |
2370 | | static int wpas_valid_ssid(struct wpa_supplicant *wpa_s, |
2371 | | struct wpa_ssid *test_ssid) |
2372 | 0 | { |
2373 | 0 | struct wpa_ssid *ssid; |
2374 | |
|
2375 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
2376 | 0 | if (ssid == test_ssid) |
2377 | 0 | return 1; |
2378 | 0 | } |
2379 | | |
2380 | 0 | return 0; |
2381 | 0 | } |
2382 | | |
2383 | | |
2384 | | int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss, |
2385 | | struct wpa_ssid *test_ssid) |
2386 | 0 | { |
2387 | 0 | if (test_bss && !wpas_valid_bss(wpa_s, test_bss)) |
2388 | 0 | return 0; |
2389 | | |
2390 | 0 | return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid); |
2391 | 0 | } |
2392 | | |
2393 | | |
2394 | | void wpas_connect_work_free(struct wpa_connect_work *cwork) |
2395 | 0 | { |
2396 | 0 | if (cwork == NULL) |
2397 | 0 | return; |
2398 | 0 | os_free(cwork); |
2399 | 0 | } |
2400 | | |
2401 | | |
2402 | | void wpas_connect_work_done(struct wpa_supplicant *wpa_s) |
2403 | 0 | { |
2404 | 0 | struct wpa_connect_work *cwork; |
2405 | 0 | struct wpa_radio_work *work = wpa_s->connect_work; |
2406 | |
|
2407 | 0 | if (!work) |
2408 | 0 | return; |
2409 | | |
2410 | 0 | wpa_s->connect_work = NULL; |
2411 | 0 | cwork = work->ctx; |
2412 | 0 | work->ctx = NULL; |
2413 | 0 | wpas_connect_work_free(cwork); |
2414 | 0 | radio_work_done(work); |
2415 | 0 | } |
2416 | | |
2417 | | |
2418 | | int wpas_update_random_addr(struct wpa_supplicant *wpa_s, |
2419 | | enum wpas_mac_addr_style style, |
2420 | | struct wpa_ssid *ssid) |
2421 | 0 | { |
2422 | 0 | struct os_reltime now; |
2423 | 0 | u8 addr[ETH_ALEN]; |
2424 | |
|
2425 | 0 | os_get_reltime(&now); |
2426 | | /* Random addresses are valid within a given ESS so check |
2427 | | * expiration/value only when continuing to use the same ESS. */ |
2428 | 0 | if (wpa_s->last_mac_addr_style == style && wpa_s->reassoc_same_ess) { |
2429 | 0 | if (style == WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS) { |
2430 | | /* Pregenerated addresses do not expire but their value |
2431 | | * might have changed, so let's check that. */ |
2432 | 0 | if (ether_addr_equal(wpa_s->own_addr, ssid->mac_value)) |
2433 | 0 | return 0; |
2434 | 0 | } else if ((wpa_s->last_mac_addr_change.sec != 0 || |
2435 | 0 | wpa_s->last_mac_addr_change.usec != 0) && |
2436 | 0 | !os_reltime_expired( |
2437 | 0 | &now, |
2438 | 0 | &wpa_s->last_mac_addr_change, |
2439 | 0 | wpa_s->conf->rand_addr_lifetime)) { |
2440 | 0 | wpa_msg(wpa_s, MSG_DEBUG, |
2441 | 0 | "Previously selected random MAC address has not yet expired"); |
2442 | 0 | return 0; |
2443 | 0 | } |
2444 | 0 | } |
2445 | | |
2446 | 0 | switch (style) { |
2447 | 0 | case WPAS_MAC_ADDR_STYLE_RANDOM: |
2448 | 0 | if (random_mac_addr(addr) < 0) |
2449 | 0 | return -1; |
2450 | 0 | break; |
2451 | 0 | case WPAS_MAC_ADDR_STYLE_RANDOM_SAME_OUI: |
2452 | 0 | os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN); |
2453 | 0 | if (random_mac_addr_keep_oui(addr) < 0) |
2454 | 0 | return -1; |
2455 | 0 | break; |
2456 | 0 | case WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS: |
2457 | 0 | if (!ssid) { |
2458 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2459 | 0 | "Invalid 'ssid' for address policy 3"); |
2460 | 0 | return -1; |
2461 | 0 | } |
2462 | 0 | os_memcpy(addr, ssid->mac_value, ETH_ALEN); |
2463 | 0 | break; |
2464 | 0 | default: |
2465 | 0 | return -1; |
2466 | 0 | } |
2467 | | |
2468 | 0 | if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) { |
2469 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2470 | 0 | "Failed to set random MAC address"); |
2471 | 0 | return -1; |
2472 | 0 | } |
2473 | | |
2474 | 0 | os_get_reltime(&wpa_s->last_mac_addr_change); |
2475 | 0 | wpa_s->mac_addr_changed = 1; |
2476 | 0 | wpa_s->last_mac_addr_style = style; |
2477 | |
|
2478 | 0 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { |
2479 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2480 | 0 | "Could not update MAC address information"); |
2481 | 0 | return -1; |
2482 | 0 | } |
2483 | | |
2484 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
2485 | 0 | MAC2STR(addr)); |
2486 | |
|
2487 | 0 | return 1; |
2488 | 0 | } |
2489 | | |
2490 | | |
2491 | | int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s) |
2492 | 0 | { |
2493 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING || |
2494 | 0 | !wpa_s->conf->preassoc_mac_addr) |
2495 | 0 | return 0; |
2496 | | |
2497 | 0 | return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr, |
2498 | 0 | NULL); |
2499 | 0 | } |
2500 | | |
2501 | | |
2502 | | void wpa_s_setup_sae_pt(struct wpa_config *conf, struct wpa_ssid *ssid, |
2503 | | bool force) |
2504 | 0 | { |
2505 | | #ifdef CONFIG_SAE |
2506 | | int *groups = conf->sae_groups; |
2507 | | int default_groups[] = { 19, 20, 21, 0 }; |
2508 | | const char *password; |
2509 | | |
2510 | | if (!groups || groups[0] <= 0) |
2511 | | groups = default_groups; |
2512 | | |
2513 | | password = ssid->sae_password; |
2514 | | if (!password) |
2515 | | password = ssid->passphrase; |
2516 | | |
2517 | | if (!password || |
2518 | | !wpa_key_mgmt_sae(ssid->key_mgmt) || |
2519 | | (conf->sae_pwe == SAE_PWE_HUNT_AND_PECK && !ssid->sae_password_id && |
2520 | | !wpa_key_mgmt_sae_ext_key(ssid->key_mgmt) && |
2521 | | !force && |
2522 | | !sae_pk_valid_password(password)) || |
2523 | | conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK) { |
2524 | | /* PT derivation not needed */ |
2525 | | sae_deinit_pt(ssid->pt); |
2526 | | ssid->pt = NULL; |
2527 | | return; |
2528 | | } |
2529 | | |
2530 | | if (ssid->pt) |
2531 | | return; /* PT already derived */ |
2532 | | ssid->pt = sae_derive_pt(groups, ssid->ssid, ssid->ssid_len, |
2533 | | (const u8 *) password, os_strlen(password), |
2534 | | ssid->sae_password_id); |
2535 | | #endif /* CONFIG_SAE */ |
2536 | 0 | } |
2537 | | |
2538 | | |
2539 | | void wpa_s_clear_sae_rejected(struct wpa_supplicant *wpa_s) |
2540 | 0 | { |
2541 | | #if defined(CONFIG_SAE) && defined(CONFIG_SME) |
2542 | | os_free(wpa_s->sme.sae_rejected_groups); |
2543 | | wpa_s->sme.sae_rejected_groups = NULL; |
2544 | | #ifdef CONFIG_TESTING_OPTIONS |
2545 | | if (wpa_s->extra_sae_rejected_groups) { |
2546 | | int i, *groups = wpa_s->extra_sae_rejected_groups; |
2547 | | |
2548 | | for (i = 0; groups[i]; i++) { |
2549 | | wpa_printf(MSG_DEBUG, |
2550 | | "TESTING: Indicate rejection of an extra SAE group %d", |
2551 | | groups[i]); |
2552 | | int_array_add_unique(&wpa_s->sme.sae_rejected_groups, |
2553 | | groups[i]); |
2554 | | } |
2555 | | } |
2556 | | #endif /* CONFIG_TESTING_OPTIONS */ |
2557 | | #endif /* CONFIG_SAE && CONFIG_SME */ |
2558 | 0 | } |
2559 | | |
2560 | | |
2561 | | int wpas_restore_permanent_mac_addr(struct wpa_supplicant *wpa_s) |
2562 | 0 | { |
2563 | 0 | if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) { |
2564 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2565 | 0 | "Could not restore permanent MAC address"); |
2566 | 0 | return -1; |
2567 | 0 | } |
2568 | 0 | wpa_s->mac_addr_changed = 0; |
2569 | 0 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { |
2570 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2571 | 0 | "Could not update MAC address information"); |
2572 | 0 | return -1; |
2573 | 0 | } |
2574 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address"); |
2575 | 0 | return 0; |
2576 | 0 | } |
2577 | | |
2578 | | |
2579 | | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit); |
2580 | | |
2581 | | /** |
2582 | | * wpa_supplicant_associate - Request association |
2583 | | * @wpa_s: Pointer to wpa_supplicant data |
2584 | | * @bss: Scan results for the selected BSS, or %NULL if not available |
2585 | | * @ssid: Configuration data for the selected network |
2586 | | * |
2587 | | * This function is used to request %wpa_supplicant to associate with a BSS. |
2588 | | */ |
2589 | | void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, |
2590 | | struct wpa_bss *bss, struct wpa_ssid *ssid) |
2591 | 0 | { |
2592 | 0 | bool clear_rejected = true; |
2593 | 0 | struct wpa_connect_work *cwork; |
2594 | 0 | enum wpas_mac_addr_style rand_style; |
2595 | |
|
2596 | 0 | wpa_s->own_disconnect_req = 0; |
2597 | 0 | wpa_s->own_reconnect_req = 0; |
2598 | | |
2599 | | /* |
2600 | | * If we are starting a new connection, any previously pending EAPOL |
2601 | | * RX cannot be valid anymore. |
2602 | | */ |
2603 | 0 | wpabuf_free(wpa_s->pending_eapol_rx); |
2604 | 0 | wpa_s->pending_eapol_rx = NULL; |
2605 | |
|
2606 | 0 | if (ssid->mac_addr == WPAS_MAC_ADDR_STYLE_NOT_SET) |
2607 | 0 | rand_style = wpa_s->conf->mac_addr; |
2608 | 0 | else |
2609 | 0 | rand_style = ssid->mac_addr; |
2610 | |
|
2611 | 0 | wpa_s->eapol_failed = 0; |
2612 | 0 | wpa_s->multi_ap_ie = 0; |
2613 | 0 | #ifndef CONFIG_NO_WMM_AC |
2614 | 0 | wmm_ac_clear_saved_tspecs(wpa_s); |
2615 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
2616 | 0 | #ifdef CONFIG_WNM |
2617 | 0 | wpa_s->wnm_mode = 0; |
2618 | 0 | wpa_s->wnm_target_bss = NULL; |
2619 | 0 | #endif /* CONFIG_WNM */ |
2620 | 0 | wpa_s->reassoc_same_bss = 0; |
2621 | 0 | wpa_s->reassoc_same_ess = 0; |
2622 | | #ifdef CONFIG_TESTING_OPTIONS |
2623 | | wpa_s->testing_resend_assoc = 0; |
2624 | | #endif /* CONFIG_TESTING_OPTIONS */ |
2625 | |
|
2626 | 0 | if (wpa_s->last_ssid == ssid) { |
2627 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS"); |
2628 | 0 | wpa_s->reassoc_same_ess = 1; |
2629 | 0 | if (wpa_s->current_bss && wpa_s->current_bss == bss) { |
2630 | 0 | #ifndef CONFIG_NO_WMM_AC |
2631 | 0 | wmm_ac_save_tspecs(wpa_s); |
2632 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
2633 | 0 | wpa_s->reassoc_same_bss = 1; |
2634 | 0 | clear_rejected = false; |
2635 | 0 | } else if (wpa_s->current_bss && wpa_s->current_bss != bss) { |
2636 | 0 | os_get_reltime(&wpa_s->roam_start); |
2637 | 0 | } |
2638 | 0 | } |
2639 | |
|
2640 | 0 | if (clear_rejected) |
2641 | 0 | wpa_s_clear_sae_rejected(wpa_s); |
2642 | |
|
2643 | | #ifdef CONFIG_SAE |
2644 | | wpa_s_setup_sae_pt(wpa_s->conf, ssid, false); |
2645 | | #endif /* CONFIG_SAE */ |
2646 | |
|
2647 | 0 | if (rand_style > WPAS_MAC_ADDR_STYLE_PERMANENT) { |
2648 | 0 | int status = wpas_update_random_addr(wpa_s, rand_style, ssid); |
2649 | |
|
2650 | 0 | if (status < 0) |
2651 | 0 | return; |
2652 | 0 | if (rand_style != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS && |
2653 | 0 | status > 0) /* MAC changed */ |
2654 | 0 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
2655 | 0 | } else if (rand_style == WPAS_MAC_ADDR_STYLE_PERMANENT && |
2656 | 0 | wpa_s->mac_addr_changed) { |
2657 | 0 | if (wpas_restore_permanent_mac_addr(wpa_s) < 0) |
2658 | 0 | return; |
2659 | 0 | } |
2660 | 0 | wpa_s->last_ssid = ssid; |
2661 | |
|
2662 | | #ifdef CONFIG_IBSS_RSN |
2663 | | ibss_rsn_deinit(wpa_s->ibss_rsn); |
2664 | | wpa_s->ibss_rsn = NULL; |
2665 | | #else /* CONFIG_IBSS_RSN */ |
2666 | 0 | if (ssid->mode == WPAS_MODE_IBSS && |
2667 | 0 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) { |
2668 | 0 | wpa_msg(wpa_s, MSG_INFO, |
2669 | 0 | "IBSS RSN not supported in the build"); |
2670 | 0 | return; |
2671 | 0 | } |
2672 | 0 | #endif /* CONFIG_IBSS_RSN */ |
2673 | | |
2674 | 0 | if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO || |
2675 | 0 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
2676 | | #ifdef CONFIG_AP |
2677 | | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) { |
2678 | | wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP " |
2679 | | "mode"); |
2680 | | return; |
2681 | | } |
2682 | | if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) { |
2683 | | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
2684 | | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
2685 | | wpas_p2p_ap_setup_failed(wpa_s); |
2686 | | return; |
2687 | | } |
2688 | | wpa_s->current_bss = bss; |
2689 | | #else /* CONFIG_AP */ |
2690 | 0 | wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in " |
2691 | 0 | "the build"); |
2692 | 0 | #endif /* CONFIG_AP */ |
2693 | 0 | return; |
2694 | 0 | } |
2695 | | |
2696 | 0 | if (ssid->mode == WPAS_MODE_MESH) { |
2697 | | #ifdef CONFIG_MESH |
2698 | | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) { |
2699 | | wpa_msg(wpa_s, MSG_INFO, |
2700 | | "Driver does not support mesh mode"); |
2701 | | return; |
2702 | | } |
2703 | | if (bss) |
2704 | | ssid->frequency = bss->freq; |
2705 | | if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) { |
2706 | | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
2707 | | wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh"); |
2708 | | return; |
2709 | | } |
2710 | | wpa_s->current_bss = bss; |
2711 | | #else /* CONFIG_MESH */ |
2712 | 0 | wpa_msg(wpa_s, MSG_ERROR, |
2713 | 0 | "mesh mode support not included in the build"); |
2714 | 0 | #endif /* CONFIG_MESH */ |
2715 | 0 | return; |
2716 | 0 | } |
2717 | | |
2718 | | /* |
2719 | | * Set WPA state machine configuration to match the selected network now |
2720 | | * so that the information is available before wpas_start_assoc_cb() |
2721 | | * gets called. This is needed at least for RSN pre-authentication where |
2722 | | * candidate APs are added to a list based on scan result processing |
2723 | | * before completion of the first association. |
2724 | | */ |
2725 | 0 | wpa_supplicant_rsn_supp_set_config(wpa_s, ssid); |
2726 | |
|
2727 | | #ifdef CONFIG_DPP |
2728 | | if (wpas_dpp_check_connect(wpa_s, ssid, bss) != 0) |
2729 | | return; |
2730 | | #endif /* CONFIG_DPP */ |
2731 | |
|
2732 | | #ifdef CONFIG_TDLS |
2733 | | if (bss) |
2734 | | wpa_tdls_ap_ies(wpa_s->wpa, wpa_bss_ie_ptr(bss), bss->ie_len); |
2735 | | #endif /* CONFIG_TDLS */ |
2736 | |
|
2737 | | #ifdef CONFIG_MBO |
2738 | | wpas_mbo_check_pmf(wpa_s, bss, ssid); |
2739 | | #endif /* CONFIG_MBO */ |
2740 | |
|
2741 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
2742 | 0 | ssid->mode == WPAS_MODE_INFRA) { |
2743 | 0 | sme_authenticate(wpa_s, bss, ssid); |
2744 | 0 | return; |
2745 | 0 | } |
2746 | | |
2747 | 0 | if (wpa_s->connect_work) { |
2748 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist"); |
2749 | 0 | return; |
2750 | 0 | } |
2751 | | |
2752 | 0 | if (radio_work_pending(wpa_s, "connect")) { |
2753 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist"); |
2754 | 0 | return; |
2755 | 0 | } |
2756 | | |
2757 | | #ifdef CONFIG_SME |
2758 | | if (ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) { |
2759 | | /* Clear possibly set auth_alg, if any, from last attempt. */ |
2760 | | wpa_s->sme.auth_alg = WPA_AUTH_ALG_OPEN; |
2761 | | } |
2762 | | #endif /* CONFIG_SME */ |
2763 | | |
2764 | 0 | wpas_abort_ongoing_scan(wpa_s); |
2765 | |
|
2766 | 0 | cwork = os_zalloc(sizeof(*cwork)); |
2767 | 0 | if (cwork == NULL) |
2768 | 0 | return; |
2769 | | |
2770 | 0 | cwork->bss = bss; |
2771 | 0 | cwork->ssid = ssid; |
2772 | |
|
2773 | 0 | if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1, |
2774 | 0 | wpas_start_assoc_cb, cwork) < 0) { |
2775 | 0 | os_free(cwork); |
2776 | 0 | } |
2777 | 0 | } |
2778 | | |
2779 | | |
2780 | | static int bss_is_ibss(struct wpa_bss *bss) |
2781 | 0 | { |
2782 | 0 | return (bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == |
2783 | 0 | IEEE80211_CAP_IBSS; |
2784 | 0 | } |
2785 | | |
2786 | | |
2787 | | static int drv_supports_vht(struct wpa_supplicant *wpa_s, |
2788 | | const struct wpa_ssid *ssid) |
2789 | 0 | { |
2790 | 0 | enum hostapd_hw_mode hw_mode; |
2791 | 0 | struct hostapd_hw_modes *mode = NULL; |
2792 | 0 | u8 channel; |
2793 | 0 | int i; |
2794 | |
|
2795 | 0 | hw_mode = ieee80211_freq_to_chan(ssid->frequency, &channel); |
2796 | 0 | if (hw_mode == NUM_HOSTAPD_MODES) |
2797 | 0 | return 0; |
2798 | 0 | for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) { |
2799 | 0 | if (wpa_s->hw.modes[i].mode == hw_mode) { |
2800 | 0 | mode = &wpa_s->hw.modes[i]; |
2801 | 0 | break; |
2802 | 0 | } |
2803 | 0 | } |
2804 | |
|
2805 | 0 | if (!mode) |
2806 | 0 | return 0; |
2807 | | |
2808 | 0 | return mode->vht_capab != 0; |
2809 | 0 | } |
2810 | | |
2811 | | |
2812 | | static bool ibss_mesh_is_80mhz_avail(int channel, struct hostapd_hw_modes *mode) |
2813 | 0 | { |
2814 | 0 | int i; |
2815 | |
|
2816 | 0 | for (i = channel; i < channel + 16; i += 4) { |
2817 | 0 | struct hostapd_channel_data *chan; |
2818 | |
|
2819 | 0 | chan = hw_get_channel_chan(mode, i, NULL); |
2820 | 0 | if (!chan || |
2821 | 0 | chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
2822 | 0 | return false; |
2823 | 0 | } |
2824 | | |
2825 | 0 | return true; |
2826 | 0 | } |
2827 | | |
2828 | | |
2829 | | static struct wpa_bss * ibss_find_existing_bss(struct wpa_supplicant *wpa_s, |
2830 | | const struct wpa_ssid *ssid) |
2831 | 0 | { |
2832 | 0 | unsigned int j; |
2833 | |
|
2834 | 0 | for (j = 0; j < wpa_s->last_scan_res_used; j++) { |
2835 | 0 | struct wpa_bss *bss = wpa_s->last_scan_res[j]; |
2836 | |
|
2837 | 0 | if (!bss_is_ibss(bss)) |
2838 | 0 | continue; |
2839 | | |
2840 | 0 | if (ssid->ssid_len == bss->ssid_len && |
2841 | 0 | os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) == 0) |
2842 | 0 | return bss; |
2843 | 0 | } |
2844 | 0 | return NULL; |
2845 | 0 | } |
2846 | | |
2847 | | |
2848 | | static bool ibss_mesh_can_use_ht(struct wpa_supplicant *wpa_s, |
2849 | | const struct wpa_ssid *ssid, |
2850 | | struct hostapd_hw_modes *mode) |
2851 | 0 | { |
2852 | | /* For IBSS check HT_IBSS flag */ |
2853 | 0 | if (ssid->mode == WPAS_MODE_IBSS && |
2854 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_HT_IBSS)) |
2855 | 0 | return false; |
2856 | | |
2857 | 0 | if (wpa_s->group_cipher == WPA_CIPHER_WEP40 || |
2858 | 0 | wpa_s->group_cipher == WPA_CIPHER_WEP104 || |
2859 | 0 | wpa_s->pairwise_cipher == WPA_CIPHER_TKIP) { |
2860 | 0 | wpa_printf(MSG_DEBUG, |
2861 | 0 | "IBSS: WEP/TKIP detected, do not try to enable HT"); |
2862 | 0 | return false; |
2863 | 0 | } |
2864 | | |
2865 | 0 | if (!ht_supported(mode)) |
2866 | 0 | return false; |
2867 | | |
2868 | | #ifdef CONFIG_HT_OVERRIDES |
2869 | | if (ssid->disable_ht) |
2870 | | return false; |
2871 | | #endif /* CONFIG_HT_OVERRIDES */ |
2872 | | |
2873 | 0 | return true; |
2874 | 0 | } |
2875 | | |
2876 | | |
2877 | | static bool ibss_mesh_can_use_vht(struct wpa_supplicant *wpa_s, |
2878 | | const struct wpa_ssid *ssid, |
2879 | | struct hostapd_hw_modes *mode) |
2880 | 0 | { |
2881 | 0 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
2882 | 0 | return false; |
2883 | | |
2884 | 0 | if (!drv_supports_vht(wpa_s, ssid)) |
2885 | 0 | return false; |
2886 | | |
2887 | | /* For IBSS check VHT_IBSS flag */ |
2888 | 0 | if (ssid->mode == WPAS_MODE_IBSS && |
2889 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_VHT_IBSS)) |
2890 | 0 | return false; |
2891 | | |
2892 | 0 | if (!vht_supported(mode)) |
2893 | 0 | return false; |
2894 | | |
2895 | | #ifdef CONFIG_VHT_OVERRIDES |
2896 | | if (ssid->disable_vht) |
2897 | | return false; |
2898 | | #endif /* CONFIG_VHT_OVERRIDES */ |
2899 | | |
2900 | 0 | return true; |
2901 | 0 | } |
2902 | | |
2903 | | |
2904 | | static bool ibss_mesh_can_use_he(struct wpa_supplicant *wpa_s, |
2905 | | const struct wpa_ssid *ssid, |
2906 | | const struct hostapd_hw_modes *mode, |
2907 | | int ieee80211_mode) |
2908 | 0 | { |
2909 | | #ifdef CONFIG_HE_OVERRIDES |
2910 | | if (ssid->disable_he) |
2911 | | return false; |
2912 | | #endif /* CONFIG_HE_OVERRIDES */ |
2913 | |
|
2914 | 0 | switch (mode->mode) { |
2915 | 0 | case HOSTAPD_MODE_IEEE80211G: |
2916 | 0 | case HOSTAPD_MODE_IEEE80211B: |
2917 | 0 | case HOSTAPD_MODE_IEEE80211A: |
2918 | 0 | return mode->he_capab[ieee80211_mode].he_supported; |
2919 | 0 | default: |
2920 | 0 | return false; |
2921 | 0 | } |
2922 | 0 | } |
2923 | | |
2924 | | |
2925 | | static bool ibss_mesh_can_use_eht(struct wpa_supplicant *wpa_s, |
2926 | | const struct wpa_ssid *ssid, |
2927 | | const struct hostapd_hw_modes *mode, |
2928 | | int ieee80211_mode) |
2929 | 0 | { |
2930 | 0 | if (ssid->disable_eht) |
2931 | 0 | return false; |
2932 | | |
2933 | 0 | switch(mode->mode) { |
2934 | 0 | case HOSTAPD_MODE_IEEE80211G: |
2935 | 0 | case HOSTAPD_MODE_IEEE80211B: |
2936 | 0 | case HOSTAPD_MODE_IEEE80211A: |
2937 | 0 | return mode->eht_capab[ieee80211_mode].eht_supported; |
2938 | 0 | default: |
2939 | 0 | return false; |
2940 | 0 | } |
2941 | 0 | } |
2942 | | |
2943 | | |
2944 | | static void ibss_mesh_select_40mhz(struct wpa_supplicant *wpa_s, |
2945 | | const struct wpa_ssid *ssid, |
2946 | | struct hostapd_hw_modes *mode, |
2947 | | struct hostapd_freq_params *freq, |
2948 | 0 | int obss_scan) { |
2949 | 0 | int chan_idx; |
2950 | 0 | struct hostapd_channel_data *pri_chan = NULL, *sec_chan = NULL; |
2951 | 0 | int i, res; |
2952 | 0 | unsigned int j; |
2953 | 0 | static const int ht40plus[] = { |
2954 | 0 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 140, |
2955 | 0 | 149, 157, 165, 173, 184, 192 |
2956 | 0 | }; |
2957 | 0 | int ht40 = -1; |
2958 | |
|
2959 | 0 | if (!freq->ht_enabled) |
2960 | 0 | return; |
2961 | | |
2962 | 0 | for (chan_idx = 0; chan_idx < mode->num_channels; chan_idx++) { |
2963 | 0 | pri_chan = &mode->channels[chan_idx]; |
2964 | 0 | if (pri_chan->chan == freq->channel) |
2965 | 0 | break; |
2966 | 0 | pri_chan = NULL; |
2967 | 0 | } |
2968 | 0 | if (!pri_chan) |
2969 | 0 | return; |
2970 | | |
2971 | | /* Check primary channel flags */ |
2972 | 0 | if (pri_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
2973 | 0 | return; |
2974 | | |
2975 | | #ifdef CONFIG_HT_OVERRIDES |
2976 | | if (ssid->disable_ht40) |
2977 | | return; |
2978 | | #endif |
2979 | | |
2980 | | /* Check/setup HT40+/HT40- */ |
2981 | 0 | for (j = 0; j < ARRAY_SIZE(ht40plus); j++) { |
2982 | 0 | if (ht40plus[j] == freq->channel) { |
2983 | 0 | ht40 = 1; |
2984 | 0 | break; |
2985 | 0 | } |
2986 | 0 | } |
2987 | | |
2988 | | /* Find secondary channel */ |
2989 | 0 | for (i = 0; i < mode->num_channels; i++) { |
2990 | 0 | sec_chan = &mode->channels[i]; |
2991 | 0 | if (sec_chan->chan == freq->channel + ht40 * 4) |
2992 | 0 | break; |
2993 | 0 | sec_chan = NULL; |
2994 | 0 | } |
2995 | 0 | if (!sec_chan) |
2996 | 0 | return; |
2997 | | |
2998 | | /* Check secondary channel flags */ |
2999 | 0 | if (sec_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
3000 | 0 | return; |
3001 | | |
3002 | 0 | if (ht40 == -1) { |
3003 | 0 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40MINUS)) |
3004 | 0 | return; |
3005 | 0 | } else { |
3006 | 0 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40PLUS)) |
3007 | 0 | return; |
3008 | 0 | } |
3009 | 0 | freq->sec_channel_offset = ht40; |
3010 | |
|
3011 | 0 | if (obss_scan) { |
3012 | 0 | struct wpa_scan_results *scan_res; |
3013 | |
|
3014 | 0 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0, |
3015 | 0 | NULL); |
3016 | 0 | if (scan_res == NULL) { |
3017 | | /* Back to HT20 */ |
3018 | 0 | freq->sec_channel_offset = 0; |
3019 | 0 | return; |
3020 | 0 | } |
3021 | | |
3022 | 0 | res = check_40mhz_5g(scan_res, pri_chan, sec_chan); |
3023 | 0 | switch (res) { |
3024 | 0 | case 0: |
3025 | | /* Back to HT20 */ |
3026 | 0 | freq->sec_channel_offset = 0; |
3027 | 0 | break; |
3028 | 0 | case 1: |
3029 | | /* Configuration allowed */ |
3030 | 0 | break; |
3031 | 0 | case 2: |
3032 | | /* Switch pri/sec channels */ |
3033 | 0 | freq->freq = hw_get_freq(mode, sec_chan->chan); |
3034 | 0 | freq->sec_channel_offset = -freq->sec_channel_offset; |
3035 | 0 | freq->channel = sec_chan->chan; |
3036 | 0 | break; |
3037 | 0 | default: |
3038 | 0 | freq->sec_channel_offset = 0; |
3039 | 0 | break; |
3040 | 0 | } |
3041 | | |
3042 | 0 | wpa_scan_results_free(scan_res); |
3043 | 0 | } |
3044 | | |
3045 | 0 | wpa_printf(MSG_DEBUG, |
3046 | 0 | "IBSS/mesh: setup freq channel %d, sec_channel_offset %d", |
3047 | 0 | freq->channel, freq->sec_channel_offset); |
3048 | 0 | } |
3049 | | |
3050 | | |
3051 | | static bool ibss_mesh_select_80_160mhz(struct wpa_supplicant *wpa_s, |
3052 | | const struct wpa_ssid *ssid, |
3053 | | struct hostapd_hw_modes *mode, |
3054 | | struct hostapd_freq_params *freq, |
3055 | 0 | int ieee80211_mode, bool is_6ghz) { |
3056 | 0 | static const int bw80[] = { |
3057 | 0 | 5180, 5260, 5500, 5580, 5660, 5745, 5825, |
3058 | 0 | 5955, 6035, 6115, 6195, 6275, 6355, 6435, |
3059 | 0 | 6515, 6595, 6675, 6755, 6835, 6915, 6995 |
3060 | 0 | }; |
3061 | 0 | static const int bw160[] = { |
3062 | 0 | 5955, 6115, 6275, 6435, 6595, 6755, 6915 |
3063 | 0 | }; |
3064 | 0 | struct hostapd_freq_params vht_freq; |
3065 | 0 | int i; |
3066 | 0 | unsigned int j, k; |
3067 | 0 | int chwidth, seg0, seg1; |
3068 | 0 | u32 vht_caps = 0; |
3069 | 0 | u8 channel = freq->channel; |
3070 | |
|
3071 | 0 | if (!freq->vht_enabled && !freq->he_enabled) |
3072 | 0 | return true; |
3073 | | |
3074 | 0 | vht_freq = *freq; |
3075 | |
|
3076 | 0 | chwidth = CONF_OPER_CHWIDTH_USE_HT; |
3077 | 0 | seg0 = freq->channel + 2 * freq->sec_channel_offset; |
3078 | 0 | seg1 = 0; |
3079 | 0 | if (freq->sec_channel_offset == 0) { |
3080 | 0 | seg0 = 0; |
3081 | | /* Don't try 80 MHz if 40 MHz failed, except in 6 GHz */ |
3082 | 0 | if (freq->ht_enabled && !is_6ghz) |
3083 | 0 | goto skip_80mhz; |
3084 | 0 | } |
3085 | 0 | if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_USE_HT) |
3086 | 0 | goto skip_80mhz; |
3087 | | |
3088 | | /* setup center_freq1, bandwidth */ |
3089 | 0 | for (j = 0; j < ARRAY_SIZE(bw80); j++) { |
3090 | 0 | if (freq->freq >= bw80[j] && |
3091 | 0 | freq->freq < bw80[j] + 80) |
3092 | 0 | break; |
3093 | 0 | } |
3094 | |
|
3095 | 0 | if (j == ARRAY_SIZE(bw80) || |
3096 | 0 | ieee80211_freq_to_chan(bw80[j], &channel) == NUM_HOSTAPD_MODES) |
3097 | 0 | goto skip_80mhz; |
3098 | | |
3099 | | /* Use 40 MHz if channel not usable */ |
3100 | 0 | if (!ibss_mesh_is_80mhz_avail(channel, mode)) |
3101 | 0 | goto skip_80mhz; |
3102 | | |
3103 | 0 | chwidth = CONF_OPER_CHWIDTH_80MHZ; |
3104 | 0 | seg0 = channel + 6; |
3105 | 0 | seg1 = 0; |
3106 | | |
3107 | | /* In 160 MHz, the initial four 20 MHz channels were validated |
3108 | | * above. If 160 MHz is supported, check the remaining four 20 MHz |
3109 | | * channels for the total of 160 MHz bandwidth for 6 GHz. |
3110 | | */ |
3111 | 0 | if ((mode->he_capab[ieee80211_mode].phy_cap[ |
3112 | 0 | HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] & |
3113 | 0 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G) && is_6ghz && |
3114 | 0 | ibss_mesh_is_80mhz_avail(channel + 16, mode)) { |
3115 | 0 | for (j = 0; j < ARRAY_SIZE(bw160); j++) { |
3116 | 0 | if (freq->freq == bw160[j]) { |
3117 | 0 | chwidth = CONF_OPER_CHWIDTH_160MHZ; |
3118 | 0 | seg0 = channel + 14; |
3119 | 0 | break; |
3120 | 0 | } |
3121 | 0 | } |
3122 | 0 | } |
3123 | |
|
3124 | 0 | if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ) { |
3125 | | /* setup center_freq2, bandwidth */ |
3126 | 0 | for (k = 0; k < ARRAY_SIZE(bw80); k++) { |
3127 | | /* Only accept 80 MHz segments separated by a gap */ |
3128 | 0 | if (j == k || abs(bw80[j] - bw80[k]) == 80) |
3129 | 0 | continue; |
3130 | | |
3131 | 0 | if (ieee80211_freq_to_chan(bw80[k], &channel) == |
3132 | 0 | NUM_HOSTAPD_MODES) |
3133 | 0 | break; |
3134 | | |
3135 | 0 | for (i = channel; i < channel + 16; i += 4) { |
3136 | 0 | struct hostapd_channel_data *chan; |
3137 | |
|
3138 | 0 | chan = hw_get_channel_chan(mode, i, NULL); |
3139 | 0 | if (!chan) |
3140 | 0 | continue; |
3141 | | |
3142 | 0 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | |
3143 | 0 | HOSTAPD_CHAN_NO_IR | |
3144 | 0 | HOSTAPD_CHAN_RADAR)) |
3145 | 0 | continue; |
3146 | | |
3147 | | /* Found a suitable second segment for 80+80 */ |
3148 | 0 | chwidth = CONF_OPER_CHWIDTH_80P80MHZ; |
3149 | 0 | if (!is_6ghz) |
3150 | 0 | vht_caps |= |
3151 | 0 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
3152 | 0 | seg1 = channel + 6; |
3153 | 0 | } |
3154 | |
|
3155 | 0 | if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ) |
3156 | 0 | break; |
3157 | 0 | } |
3158 | 0 | } else if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_160MHZ) { |
3159 | 0 | if (freq->freq == 5180) { |
3160 | 0 | chwidth = CONF_OPER_CHWIDTH_160MHZ; |
3161 | 0 | vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
3162 | 0 | seg0 = 50; |
3163 | 0 | } else if (freq->freq == 5520) { |
3164 | 0 | chwidth = CONF_OPER_CHWIDTH_160MHZ; |
3165 | 0 | vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
3166 | 0 | seg0 = 114; |
3167 | 0 | } |
3168 | 0 | } |
3169 | |
|
3170 | 0 | skip_80mhz: |
3171 | 0 | if (hostapd_set_freq_params(&vht_freq, mode->mode, freq->freq, |
3172 | 0 | freq->channel, ssid->enable_edmg, |
3173 | 0 | ssid->edmg_channel, freq->ht_enabled, |
3174 | 0 | freq->vht_enabled, freq->he_enabled, |
3175 | 0 | freq->eht_enabled, |
3176 | 0 | freq->sec_channel_offset, |
3177 | 0 | chwidth, seg0, seg1, vht_caps, |
3178 | 0 | &mode->he_capab[ieee80211_mode], |
3179 | 0 | &mode->eht_capab[ieee80211_mode], 0) != 0) |
3180 | 0 | return false; |
3181 | | |
3182 | 0 | *freq = vht_freq; |
3183 | |
|
3184 | 0 | wpa_printf(MSG_DEBUG, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d", |
3185 | 0 | freq->center_freq1, freq->center_freq2, freq->bandwidth); |
3186 | 0 | return true; |
3187 | 0 | } |
3188 | | |
3189 | | |
3190 | | void ibss_mesh_setup_freq(struct wpa_supplicant *wpa_s, |
3191 | | const struct wpa_ssid *ssid, |
3192 | | struct hostapd_freq_params *freq) |
3193 | 0 | { |
3194 | 0 | int ieee80211_mode = wpas_mode_to_ieee80211_mode(ssid->mode); |
3195 | 0 | enum hostapd_hw_mode hw_mode; |
3196 | 0 | struct hostapd_hw_modes *mode = NULL; |
3197 | 0 | int obss_scan = 1; |
3198 | 0 | u8 channel; |
3199 | 0 | bool is_6ghz, is_24ghz; |
3200 | |
|
3201 | 0 | freq->freq = ssid->frequency; |
3202 | |
|
3203 | 0 | if (ssid->mode == WPAS_MODE_IBSS && !ssid->fixed_freq) { |
3204 | 0 | struct wpa_bss *bss = ibss_find_existing_bss(wpa_s, ssid); |
3205 | |
|
3206 | 0 | if (bss) { |
3207 | 0 | wpa_printf(MSG_DEBUG, |
3208 | 0 | "IBSS already found in scan results, adjust control freq: %d", |
3209 | 0 | bss->freq); |
3210 | 0 | freq->freq = bss->freq; |
3211 | 0 | obss_scan = 0; |
3212 | 0 | } |
3213 | 0 | } |
3214 | |
|
3215 | 0 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
3216 | 0 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
3217 | 0 | hw_mode, is_6ghz_freq(ssid->frequency)); |
3218 | |
|
3219 | 0 | if (!mode) |
3220 | 0 | return; |
3221 | | |
3222 | 0 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
3223 | 0 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
3224 | |
|
3225 | 0 | is_6ghz = is_6ghz_freq(freq->freq); |
3226 | |
|
3227 | 0 | freq->ht_enabled = 0; |
3228 | 0 | freq->vht_enabled = 0; |
3229 | 0 | freq->he_enabled = 0; |
3230 | 0 | freq->eht_enabled = 0; |
3231 | |
|
3232 | 0 | if (!is_6ghz) |
3233 | 0 | freq->ht_enabled = ibss_mesh_can_use_ht(wpa_s, ssid, mode); |
3234 | 0 | if (freq->ht_enabled) |
3235 | 0 | freq->vht_enabled = ibss_mesh_can_use_vht(wpa_s, ssid, mode); |
3236 | 0 | if (freq->vht_enabled || (freq->ht_enabled && is_24ghz) || is_6ghz) |
3237 | 0 | freq->he_enabled = ibss_mesh_can_use_he(wpa_s, ssid, mode, |
3238 | 0 | ieee80211_mode); |
3239 | 0 | freq->channel = channel; |
3240 | | /* Setup higher BW only for 5 GHz */ |
3241 | 0 | if (mode->mode == HOSTAPD_MODE_IEEE80211A) { |
3242 | 0 | ibss_mesh_select_40mhz(wpa_s, ssid, mode, freq, obss_scan); |
3243 | 0 | if (!ibss_mesh_select_80_160mhz(wpa_s, ssid, mode, freq, |
3244 | 0 | ieee80211_mode, is_6ghz)) |
3245 | 0 | freq->he_enabled = freq->vht_enabled = false; |
3246 | 0 | } |
3247 | |
|
3248 | 0 | if (freq->he_enabled) |
3249 | 0 | freq->eht_enabled = ibss_mesh_can_use_eht(wpa_s, ssid, mode, |
3250 | 0 | ieee80211_mode); |
3251 | 0 | } |
3252 | | |
3253 | | |
3254 | | #ifdef CONFIG_FILS |
3255 | | static size_t wpas_add_fils_hlp_req(struct wpa_supplicant *wpa_s, u8 *ie_buf, |
3256 | | size_t ie_buf_len) |
3257 | | { |
3258 | | struct fils_hlp_req *req; |
3259 | | size_t rem_len, hdr_len, hlp_len, len, ie_len = 0; |
3260 | | const u8 *pos; |
3261 | | u8 *buf = ie_buf; |
3262 | | |
3263 | | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, |
3264 | | list) { |
3265 | | rem_len = ie_buf_len - ie_len; |
3266 | | pos = wpabuf_head(req->pkt); |
3267 | | hdr_len = 1 + 2 * ETH_ALEN + 6; |
3268 | | hlp_len = wpabuf_len(req->pkt); |
3269 | | |
3270 | | if (rem_len < 2 + hdr_len + hlp_len) { |
3271 | | wpa_printf(MSG_ERROR, |
3272 | | "FILS: Cannot fit HLP - rem_len=%lu to_fill=%lu", |
3273 | | (unsigned long) rem_len, |
3274 | | (unsigned long) (2 + hdr_len + hlp_len)); |
3275 | | break; |
3276 | | } |
3277 | | |
3278 | | len = (hdr_len + hlp_len) > 255 ? 255 : hdr_len + hlp_len; |
3279 | | /* Element ID */ |
3280 | | *buf++ = WLAN_EID_EXTENSION; |
3281 | | /* Length */ |
3282 | | *buf++ = len; |
3283 | | /* Element ID Extension */ |
3284 | | *buf++ = WLAN_EID_EXT_FILS_HLP_CONTAINER; |
3285 | | /* Destination MAC address */ |
3286 | | os_memcpy(buf, req->dst, ETH_ALEN); |
3287 | | buf += ETH_ALEN; |
3288 | | /* Source MAC address */ |
3289 | | os_memcpy(buf, wpa_s->own_addr, ETH_ALEN); |
3290 | | buf += ETH_ALEN; |
3291 | | /* LLC/SNAP Header */ |
3292 | | os_memcpy(buf, "\xaa\xaa\x03\x00\x00\x00", 6); |
3293 | | buf += 6; |
3294 | | /* HLP Packet */ |
3295 | | os_memcpy(buf, pos, len - hdr_len); |
3296 | | buf += len - hdr_len; |
3297 | | pos += len - hdr_len; |
3298 | | |
3299 | | hlp_len -= len - hdr_len; |
3300 | | ie_len += 2 + len; |
3301 | | rem_len -= 2 + len; |
3302 | | |
3303 | | while (hlp_len) { |
3304 | | len = (hlp_len > 255) ? 255 : hlp_len; |
3305 | | if (rem_len < 2 + len) |
3306 | | break; |
3307 | | *buf++ = WLAN_EID_FRAGMENT; |
3308 | | *buf++ = len; |
3309 | | os_memcpy(buf, pos, len); |
3310 | | buf += len; |
3311 | | pos += len; |
3312 | | |
3313 | | hlp_len -= len; |
3314 | | ie_len += 2 + len; |
3315 | | rem_len -= 2 + len; |
3316 | | } |
3317 | | } |
3318 | | |
3319 | | return ie_len; |
3320 | | } |
3321 | | |
3322 | | |
3323 | | int wpa_is_fils_supported(struct wpa_supplicant *wpa_s) |
3324 | | { |
3325 | | return (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
3326 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) || |
3327 | | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
3328 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD))); |
3329 | | } |
3330 | | |
3331 | | |
3332 | | int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant *wpa_s) |
3333 | | { |
3334 | | #ifdef CONFIG_FILS_SK_PFS |
3335 | | return (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
3336 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS); |
3337 | | #else /* CONFIG_FILS_SK_PFS */ |
3338 | | return 0; |
3339 | | #endif /* CONFIG_FILS_SK_PFS */ |
3340 | | } |
3341 | | |
3342 | | #endif /* CONFIG_FILS */ |
3343 | | |
3344 | | |
3345 | | bool wpa_is_non_eht_scs_traffic_desc_supported(struct wpa_bss *bss) |
3346 | 0 | { |
3347 | 0 | const u8 *wfa_capa; |
3348 | |
|
3349 | 0 | if (!bss) |
3350 | 0 | return false; |
3351 | | |
3352 | | /* Get WFA capability from Beacon or Probe Response frame elements */ |
3353 | 0 | wfa_capa = wpa_bss_get_vendor_ie(bss, WFA_CAPA_IE_VENDOR_TYPE); |
3354 | 0 | if (!wfa_capa) |
3355 | 0 | wfa_capa = wpa_bss_get_vendor_ie_beacon( |
3356 | 0 | bss, WFA_CAPA_IE_VENDOR_TYPE); |
3357 | |
|
3358 | 0 | if (!wfa_capa || wfa_capa[1] < 6 || wfa_capa[6] < 1 || |
3359 | 0 | !(wfa_capa[7] & WFA_CAPA_QM_NON_EHT_SCS_TRAFFIC_DESC)) { |
3360 | | /* AP does not enable QM non EHT traffic description policy */ |
3361 | 0 | return false; |
3362 | 0 | } |
3363 | | |
3364 | 0 | return true; |
3365 | 0 | } |
3366 | | |
3367 | | |
3368 | | static int wpas_populate_wfa_capa(struct wpa_supplicant *wpa_s, |
3369 | | struct wpa_bss *bss, |
3370 | | u8 *wpa_ie, size_t wpa_ie_len, |
3371 | | size_t max_wpa_ie_len) |
3372 | 0 | { |
3373 | 0 | struct wpabuf *wfa_ie = NULL; |
3374 | 0 | u8 wfa_capa[1]; |
3375 | 0 | size_t wfa_ie_len, buf_len; |
3376 | |
|
3377 | 0 | os_memset(wfa_capa, 0, sizeof(wfa_capa)); |
3378 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
3379 | 0 | if (wpa_s->enable_dscp_policy_capa) |
3380 | 0 | wfa_capa[0] |= WFA_CAPA_QM_DSCP_POLICY; |
3381 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
3382 | |
|
3383 | 0 | if (wpa_is_non_eht_scs_traffic_desc_supported(bss)) |
3384 | 0 | wfa_capa[0] |= WFA_CAPA_QM_NON_EHT_SCS_TRAFFIC_DESC; |
3385 | |
|
3386 | 0 | if (!wfa_capa[0]) |
3387 | 0 | return wpa_ie_len; |
3388 | | |
3389 | | /* Wi-Fi Alliance element */ |
3390 | 0 | buf_len = 1 + /* Element ID */ |
3391 | 0 | 1 + /* Length */ |
3392 | 0 | 3 + /* OUI */ |
3393 | 0 | 1 + /* OUI Type */ |
3394 | 0 | 1 + /* Capabilities Length */ |
3395 | 0 | sizeof(wfa_capa); /* Capabilities */ |
3396 | 0 | wfa_ie = wpabuf_alloc(buf_len); |
3397 | 0 | if (!wfa_ie) |
3398 | 0 | return wpa_ie_len; |
3399 | | |
3400 | 0 | wpabuf_put_u8(wfa_ie, WLAN_EID_VENDOR_SPECIFIC); |
3401 | 0 | wpabuf_put_u8(wfa_ie, buf_len - 2); |
3402 | 0 | wpabuf_put_be24(wfa_ie, OUI_WFA); |
3403 | 0 | wpabuf_put_u8(wfa_ie, WFA_CAPA_OUI_TYPE); |
3404 | 0 | wpabuf_put_u8(wfa_ie, sizeof(wfa_capa)); |
3405 | 0 | wpabuf_put_data(wfa_ie, wfa_capa, sizeof(wfa_capa)); |
3406 | |
|
3407 | 0 | wfa_ie_len = wpabuf_len(wfa_ie); |
3408 | 0 | if (wpa_ie_len + wfa_ie_len <= max_wpa_ie_len) { |
3409 | 0 | wpa_hexdump_buf(MSG_MSGDUMP, "WFA Capabilities element", |
3410 | 0 | wfa_ie); |
3411 | 0 | os_memcpy(wpa_ie + wpa_ie_len, wpabuf_head(wfa_ie), |
3412 | 0 | wfa_ie_len); |
3413 | 0 | wpa_ie_len += wfa_ie_len; |
3414 | 0 | } |
3415 | |
|
3416 | 0 | wpabuf_free(wfa_ie); |
3417 | 0 | return wpa_ie_len; |
3418 | 0 | } |
3419 | | |
3420 | | |
3421 | | static u8 * wpas_populate_assoc_ies( |
3422 | | struct wpa_supplicant *wpa_s, |
3423 | | struct wpa_bss *bss, struct wpa_ssid *ssid, |
3424 | | struct wpa_driver_associate_params *params, |
3425 | | enum wpa_drv_update_connect_params_mask *mask) |
3426 | 0 | { |
3427 | 0 | u8 *wpa_ie; |
3428 | 0 | size_t max_wpa_ie_len = 500; |
3429 | 0 | size_t wpa_ie_len; |
3430 | 0 | int algs = WPA_AUTH_ALG_OPEN; |
3431 | | #ifdef CONFIG_MBO |
3432 | | const u8 *mbo_ie; |
3433 | | #endif |
3434 | | #if defined(CONFIG_SAE) || defined(CONFIG_FILS) |
3435 | | int pmksa_cached = 0; |
3436 | | #endif /* CONFIG_SAE || CONFIG_FILS */ |
3437 | | #ifdef CONFIG_FILS |
3438 | | const u8 *realm, *username, *rrk; |
3439 | | size_t realm_len, username_len, rrk_len; |
3440 | | u16 next_seq_num; |
3441 | | struct fils_hlp_req *req; |
3442 | | |
3443 | | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, |
3444 | | list) { |
3445 | | max_wpa_ie_len += 3 + 2 * ETH_ALEN + 6 + wpabuf_len(req->pkt) + |
3446 | | 2 + 2 * wpabuf_len(req->pkt) / 255; |
3447 | | } |
3448 | | #endif /* CONFIG_FILS */ |
3449 | |
|
3450 | 0 | wpa_ie = os_malloc(max_wpa_ie_len); |
3451 | 0 | if (!wpa_ie) { |
3452 | 0 | wpa_printf(MSG_ERROR, |
3453 | 0 | "Failed to allocate connect IE buffer for %lu bytes", |
3454 | 0 | (unsigned long) max_wpa_ie_len); |
3455 | 0 | return NULL; |
3456 | 0 | } |
3457 | | |
3458 | 0 | if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
3459 | 0 | wpa_bss_get_rsne(wpa_s, bss, ssid, false)) && |
3460 | 0 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
3461 | 0 | int try_opportunistic; |
3462 | 0 | const u8 *cache_id = NULL; |
3463 | 0 | const u8 *addr = bss->bssid; |
3464 | |
|
3465 | 0 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
3466 | 0 | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) && |
3467 | 0 | !is_zero_ether_addr(bss->mld_addr)) |
3468 | 0 | addr = bss->mld_addr; |
3469 | |
|
3470 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
3471 | 0 | wpa_s->valid_links) |
3472 | 0 | addr = wpa_s->ap_mld_addr; |
3473 | |
|
3474 | 0 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
3475 | 0 | wpa_s->conf->okc : |
3476 | 0 | ssid->proactive_key_caching) && |
3477 | 0 | (ssid->proto & WPA_PROTO_RSN); |
3478 | | #ifdef CONFIG_FILS |
3479 | | if (wpa_key_mgmt_fils(ssid->key_mgmt)) |
3480 | | cache_id = wpa_bss_get_fils_cache_id(bss); |
3481 | | #endif /* CONFIG_FILS */ |
3482 | 0 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, addr, |
3483 | 0 | ssid, try_opportunistic, |
3484 | 0 | cache_id, 0, false) == 0) { |
3485 | 0 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
3486 | | #if defined(CONFIG_SAE) || defined(CONFIG_FILS) |
3487 | | pmksa_cached = 1; |
3488 | | #endif /* CONFIG_SAE || CONFIG_FILS */ |
3489 | 0 | } |
3490 | 0 | wpa_ie_len = max_wpa_ie_len; |
3491 | 0 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
3492 | 0 | wpa_ie, &wpa_ie_len, false)) { |
3493 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
3494 | 0 | "key management and encryption suites"); |
3495 | 0 | os_free(wpa_ie); |
3496 | 0 | return NULL; |
3497 | 0 | } |
3498 | 0 | #ifdef CONFIG_HS20 |
3499 | 0 | } else if (bss && wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE) && |
3500 | 0 | (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)) { |
3501 | | /* No PMKSA caching, but otherwise similar to RSN/WPA */ |
3502 | 0 | wpa_ie_len = max_wpa_ie_len; |
3503 | 0 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
3504 | 0 | wpa_ie, &wpa_ie_len, false)) { |
3505 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
3506 | 0 | "key management and encryption suites"); |
3507 | 0 | os_free(wpa_ie); |
3508 | 0 | return NULL; |
3509 | 0 | } |
3510 | 0 | #endif /* CONFIG_HS20 */ |
3511 | 0 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss && |
3512 | 0 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { |
3513 | | /* |
3514 | | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - |
3515 | | * use non-WPA since the scan results did not indicate that the |
3516 | | * AP is using WPA or WPA2. |
3517 | | */ |
3518 | 0 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
3519 | 0 | wpa_ie_len = 0; |
3520 | 0 | wpa_s->wpa_proto = 0; |
3521 | 0 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
3522 | 0 | wpa_ie_len = max_wpa_ie_len; |
3523 | 0 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
3524 | 0 | wpa_ie, &wpa_ie_len, false)) { |
3525 | 0 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
3526 | 0 | "key management and encryption suites (no " |
3527 | 0 | "scan results)"); |
3528 | 0 | os_free(wpa_ie); |
3529 | 0 | return NULL; |
3530 | 0 | } |
3531 | | #ifdef CONFIG_WPS |
3532 | | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
3533 | | struct wpabuf *wps_ie; |
3534 | | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); |
3535 | | if (wps_ie && wpabuf_len(wps_ie) <= max_wpa_ie_len) { |
3536 | | wpa_ie_len = wpabuf_len(wps_ie); |
3537 | | os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len); |
3538 | | } else |
3539 | | wpa_ie_len = 0; |
3540 | | wpabuf_free(wps_ie); |
3541 | | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
3542 | | if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY)) |
3543 | | params->wps = WPS_MODE_PRIVACY; |
3544 | | else |
3545 | | params->wps = WPS_MODE_OPEN; |
3546 | | wpa_s->wpa_proto = 0; |
3547 | | #endif /* CONFIG_WPS */ |
3548 | 0 | } else { |
3549 | 0 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
3550 | 0 | wpa_ie_len = 0; |
3551 | 0 | wpa_s->wpa_proto = 0; |
3552 | 0 | } |
3553 | | |
3554 | 0 | #ifdef IEEE8021X_EAPOL |
3555 | 0 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
3556 | 0 | if (ssid->leap) { |
3557 | 0 | if (ssid->non_leap == 0) |
3558 | 0 | algs = WPA_AUTH_ALG_LEAP; |
3559 | 0 | else |
3560 | 0 | algs |= WPA_AUTH_ALG_LEAP; |
3561 | 0 | } |
3562 | 0 | } |
3563 | |
|
3564 | | #ifdef CONFIG_FILS |
3565 | | /* Clear FILS association */ |
3566 | | wpa_sm_set_reset_fils_completed(wpa_s->wpa, 0); |
3567 | | |
3568 | | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) && |
3569 | | ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) && |
3570 | | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, &username, |
3571 | | &username_len, &realm, &realm_len, |
3572 | | &next_seq_num, &rrk, &rrk_len) == 0 && |
3573 | | (!wpa_s->last_con_fail_realm || |
3574 | | wpa_s->last_con_fail_realm_len != realm_len || |
3575 | | os_memcmp(wpa_s->last_con_fail_realm, realm, realm_len) != 0)) { |
3576 | | algs = WPA_AUTH_ALG_FILS; |
3577 | | params->fils_erp_username = username; |
3578 | | params->fils_erp_username_len = username_len; |
3579 | | params->fils_erp_realm = realm; |
3580 | | params->fils_erp_realm_len = realm_len; |
3581 | | params->fils_erp_next_seq_num = next_seq_num; |
3582 | | params->fils_erp_rrk = rrk; |
3583 | | params->fils_erp_rrk_len = rrk_len; |
3584 | | |
3585 | | if (mask) |
3586 | | *mask |= WPA_DRV_UPDATE_FILS_ERP_INFO; |
3587 | | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) && |
3588 | | ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) && |
3589 | | pmksa_cached) { |
3590 | | algs = WPA_AUTH_ALG_FILS; |
3591 | | } |
3592 | | #endif /* CONFIG_FILS */ |
3593 | 0 | #endif /* IEEE8021X_EAPOL */ |
3594 | | #ifdef CONFIG_SAE |
3595 | | if (wpa_key_mgmt_sae(wpa_s->key_mgmt)) |
3596 | | algs = WPA_AUTH_ALG_SAE; |
3597 | | #endif /* CONFIG_SAE */ |
3598 | |
|
3599 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs); |
3600 | 0 | if (ssid->auth_alg) { |
3601 | 0 | algs = ssid->auth_alg; |
3602 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
3603 | 0 | "Overriding auth_alg selection: 0x%x", algs); |
3604 | 0 | } |
3605 | |
|
3606 | | #ifdef CONFIG_SAE |
3607 | | if (pmksa_cached && algs == WPA_AUTH_ALG_SAE) { |
3608 | | wpa_dbg(wpa_s, MSG_DEBUG, |
3609 | | "SAE: Use WPA_AUTH_ALG_OPEN for PMKSA caching attempt"); |
3610 | | algs = WPA_AUTH_ALG_OPEN; |
3611 | | } |
3612 | | #endif /* CONFIG_SAE */ |
3613 | |
|
3614 | | #ifdef CONFIG_P2P |
3615 | | if (wpa_s->global->p2p) { |
3616 | | u8 *pos; |
3617 | | size_t len; |
3618 | | int res; |
3619 | | pos = wpa_ie + wpa_ie_len; |
3620 | | len = max_wpa_ie_len - wpa_ie_len; |
3621 | | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
3622 | | ssid->p2p_group); |
3623 | | if (res >= 0) |
3624 | | wpa_ie_len += res; |
3625 | | } |
3626 | | |
3627 | | wpa_s->cross_connect_disallowed = 0; |
3628 | | if (bss) { |
3629 | | struct wpabuf *p2p; |
3630 | | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
3631 | | if (p2p) { |
3632 | | wpa_s->cross_connect_disallowed = |
3633 | | p2p_get_cross_connect_disallowed(p2p); |
3634 | | wpabuf_free(p2p); |
3635 | | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross " |
3636 | | "connection", |
3637 | | wpa_s->cross_connect_disallowed ? |
3638 | | "disallows" : "allows"); |
3639 | | } |
3640 | | } |
3641 | | |
3642 | | os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info)); |
3643 | | #endif /* CONFIG_P2P */ |
3644 | |
|
3645 | 0 | #ifndef CONFIG_NO_RRM |
3646 | 0 | if (bss) { |
3647 | 0 | wpa_ie_len += wpas_supp_op_class_ie(wpa_s, ssid, bss, |
3648 | 0 | wpa_ie + wpa_ie_len, |
3649 | 0 | max_wpa_ie_len - |
3650 | 0 | wpa_ie_len); |
3651 | 0 | } |
3652 | 0 | #endif /* CONFIG_NO_RRM */ |
3653 | | |
3654 | | /* |
3655 | | * Workaround: Add Extended Capabilities element only if the AP |
3656 | | * included this element in Beacon/Probe Response frames. Some older |
3657 | | * APs seem to have interoperability issues if this element is |
3658 | | * included, so while the standard may require us to include the |
3659 | | * element in all cases, it is justifiable to skip it to avoid |
3660 | | * interoperability issues. |
3661 | | */ |
3662 | 0 | if (ssid->p2p_group) |
3663 | 0 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT); |
3664 | 0 | else |
3665 | 0 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); |
3666 | |
|
3667 | 0 | if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) { |
3668 | 0 | u8 ext_capab[18]; |
3669 | 0 | int ext_capab_len; |
3670 | 0 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
3671 | 0 | sizeof(ext_capab), bss); |
3672 | 0 | if (ext_capab_len > 0 && |
3673 | 0 | wpa_ie_len + ext_capab_len <= max_wpa_ie_len) { |
3674 | 0 | u8 *pos = wpa_ie; |
3675 | 0 | if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN) |
3676 | 0 | pos += 2 + pos[1]; |
3677 | 0 | os_memmove(pos + ext_capab_len, pos, |
3678 | 0 | wpa_ie_len - (pos - wpa_ie)); |
3679 | 0 | wpa_ie_len += ext_capab_len; |
3680 | 0 | os_memcpy(pos, ext_capab, ext_capab_len); |
3681 | 0 | } |
3682 | 0 | } |
3683 | |
|
3684 | 0 | if (ssid->max_idle && wpa_ie_len + 5 <= max_wpa_ie_len) { |
3685 | 0 | u8 *pos = wpa_ie; |
3686 | |
|
3687 | 0 | *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD; |
3688 | 0 | *pos++ = 3; |
3689 | 0 | WPA_PUT_LE16(pos, ssid->max_idle); |
3690 | 0 | pos += 2; |
3691 | 0 | *pos = 0; /* Idle Options */ |
3692 | 0 | wpa_ie_len += 5; |
3693 | 0 | } |
3694 | |
|
3695 | 0 | #ifdef CONFIG_HS20 |
3696 | 0 | if (is_hs20_network(wpa_s, ssid, bss)) { |
3697 | 0 | struct wpabuf *hs20; |
3698 | |
|
3699 | 0 | hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN); |
3700 | 0 | if (hs20) { |
3701 | 0 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); |
3702 | 0 | size_t len; |
3703 | |
|
3704 | 0 | wpas_hs20_add_indication(hs20, pps_mo_id, |
3705 | 0 | get_hs20_version(bss)); |
3706 | 0 | wpas_hs20_add_roam_cons_sel(hs20, ssid); |
3707 | 0 | len = max_wpa_ie_len - wpa_ie_len; |
3708 | 0 | if (wpabuf_len(hs20) <= len) { |
3709 | 0 | os_memcpy(wpa_ie + wpa_ie_len, |
3710 | 0 | wpabuf_head(hs20), wpabuf_len(hs20)); |
3711 | 0 | wpa_ie_len += wpabuf_len(hs20); |
3712 | 0 | } |
3713 | 0 | wpabuf_free(hs20); |
3714 | |
|
3715 | 0 | hs20_configure_frame_filters(wpa_s); |
3716 | 0 | } |
3717 | 0 | } |
3718 | 0 | #endif /* CONFIG_HS20 */ |
3719 | |
|
3720 | 0 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
3721 | 0 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; |
3722 | 0 | size_t len; |
3723 | |
|
3724 | 0 | len = max_wpa_ie_len - wpa_ie_len; |
3725 | 0 | if (wpabuf_len(buf) <= len) { |
3726 | 0 | os_memcpy(wpa_ie + wpa_ie_len, |
3727 | 0 | wpabuf_head(buf), wpabuf_len(buf)); |
3728 | 0 | wpa_ie_len += wpabuf_len(buf); |
3729 | 0 | } |
3730 | 0 | } |
3731 | |
|
3732 | | #ifdef CONFIG_FST |
3733 | | if (wpa_s->fst_ies) { |
3734 | | int fst_ies_len = wpabuf_len(wpa_s->fst_ies); |
3735 | | |
3736 | | if (wpa_ie_len + fst_ies_len <= max_wpa_ie_len) { |
3737 | | os_memcpy(wpa_ie + wpa_ie_len, |
3738 | | wpabuf_head(wpa_s->fst_ies), fst_ies_len); |
3739 | | wpa_ie_len += fst_ies_len; |
3740 | | } |
3741 | | } |
3742 | | #endif /* CONFIG_FST */ |
3743 | |
|
3744 | | #ifdef CONFIG_MBO |
3745 | | mbo_ie = bss ? wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE) : NULL; |
3746 | | if (!wpa_s->disable_mbo_oce && mbo_ie) { |
3747 | | int len; |
3748 | | |
3749 | | len = wpas_mbo_ie(wpa_s, wpa_ie + wpa_ie_len, |
3750 | | max_wpa_ie_len - wpa_ie_len, |
3751 | | !!mbo_attr_from_mbo_ie(mbo_ie, |
3752 | | OCE_ATTR_ID_CAPA_IND)); |
3753 | | if (len >= 0) |
3754 | | wpa_ie_len += len; |
3755 | | } |
3756 | | #endif /* CONFIG_MBO */ |
3757 | |
|
3758 | | #ifdef CONFIG_FILS |
3759 | | if (algs == WPA_AUTH_ALG_FILS) { |
3760 | | size_t len; |
3761 | | |
3762 | | len = wpas_add_fils_hlp_req(wpa_s, wpa_ie + wpa_ie_len, |
3763 | | max_wpa_ie_len - wpa_ie_len); |
3764 | | wpa_ie_len += len; |
3765 | | } |
3766 | | #endif /* CONFIG_FILS */ |
3767 | |
|
3768 | | #ifdef CONFIG_OWE |
3769 | | #ifdef CONFIG_TESTING_OPTIONS |
3770 | | if (get_ie_ext(wpa_ie, wpa_ie_len, WLAN_EID_EXT_OWE_DH_PARAM)) { |
3771 | | wpa_printf(MSG_INFO, "TESTING: Override OWE DH element"); |
3772 | | } else |
3773 | | #endif /* CONFIG_TESTING_OPTIONS */ |
3774 | | if (algs == WPA_AUTH_ALG_OPEN && |
3775 | | ssid->key_mgmt == WPA_KEY_MGMT_OWE && |
3776 | | !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA)) { |
3777 | | struct wpabuf *owe_ie; |
3778 | | u16 group; |
3779 | | |
3780 | | if (ssid->owe_group) { |
3781 | | group = ssid->owe_group; |
3782 | | } else if (wpa_s->assoc_status_code == |
3783 | | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { |
3784 | | if (wpa_s->last_owe_group == 19) |
3785 | | group = 20; |
3786 | | else if (wpa_s->last_owe_group == 20) |
3787 | | group = 21; |
3788 | | else |
3789 | | group = OWE_DH_GROUP; |
3790 | | } else { |
3791 | | group = OWE_DH_GROUP; |
3792 | | } |
3793 | | |
3794 | | wpa_s->last_owe_group = group; |
3795 | | wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group); |
3796 | | owe_ie = owe_build_assoc_req(wpa_s->wpa, group); |
3797 | | if (owe_ie && |
3798 | | wpabuf_len(owe_ie) <= max_wpa_ie_len - wpa_ie_len) { |
3799 | | os_memcpy(wpa_ie + wpa_ie_len, |
3800 | | wpabuf_head(owe_ie), wpabuf_len(owe_ie)); |
3801 | | wpa_ie_len += wpabuf_len(owe_ie); |
3802 | | } |
3803 | | wpabuf_free(owe_ie); |
3804 | | } |
3805 | | #endif /* CONFIG_OWE */ |
3806 | |
|
3807 | | #ifdef CONFIG_DPP2 |
3808 | | if (DPP_VERSION > 1 && |
3809 | | wpa_sm_get_key_mgmt(wpa_s->wpa) == WPA_KEY_MGMT_DPP && |
3810 | | ssid->dpp_netaccesskey && |
3811 | | ssid->dpp_pfs != 2 && !ssid->dpp_pfs_fallback) { |
3812 | | struct rsn_pmksa_cache_entry *pmksa; |
3813 | | |
3814 | | pmksa = pmksa_cache_get_current(wpa_s->wpa); |
3815 | | if (!pmksa || !pmksa->dpp_pfs) |
3816 | | goto pfs_fail; |
3817 | | |
3818 | | dpp_pfs_free(wpa_s->dpp_pfs); |
3819 | | wpa_s->dpp_pfs = dpp_pfs_init(ssid->dpp_netaccesskey, |
3820 | | ssid->dpp_netaccesskey_len); |
3821 | | if (!wpa_s->dpp_pfs) { |
3822 | | wpa_printf(MSG_DEBUG, "DPP: Could not initialize PFS"); |
3823 | | /* Try to continue without PFS */ |
3824 | | goto pfs_fail; |
3825 | | } |
3826 | | if (wpabuf_len(wpa_s->dpp_pfs->ie) <= |
3827 | | max_wpa_ie_len - wpa_ie_len) { |
3828 | | os_memcpy(wpa_ie + wpa_ie_len, |
3829 | | wpabuf_head(wpa_s->dpp_pfs->ie), |
3830 | | wpabuf_len(wpa_s->dpp_pfs->ie)); |
3831 | | wpa_ie_len += wpabuf_len(wpa_s->dpp_pfs->ie); |
3832 | | } |
3833 | | } |
3834 | | pfs_fail: |
3835 | | #endif /* CONFIG_DPP2 */ |
3836 | |
|
3837 | | #ifdef CONFIG_IEEE80211R |
3838 | | /* |
3839 | | * Add MDIE under these conditions: the network profile allows FT, |
3840 | | * the AP supports FT, and the mobility domain ID matches. |
3841 | | */ |
3842 | | if (bss && wpa_key_mgmt_ft(wpa_sm_get_key_mgmt(wpa_s->wpa))) { |
3843 | | const u8 *mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
3844 | | |
3845 | | if (mdie && mdie[1] >= MOBILITY_DOMAIN_ID_LEN) { |
3846 | | size_t len = 0; |
3847 | | const u8 *md = mdie + 2; |
3848 | | const u8 *wpa_md = wpa_sm_get_ft_md(wpa_s->wpa); |
3849 | | |
3850 | | if (os_memcmp(md, wpa_md, |
3851 | | MOBILITY_DOMAIN_ID_LEN) == 0) { |
3852 | | /* Add mobility domain IE */ |
3853 | | len = wpa_ft_add_mdie( |
3854 | | wpa_s->wpa, wpa_ie + wpa_ie_len, |
3855 | | max_wpa_ie_len - wpa_ie_len, mdie); |
3856 | | wpa_ie_len += len; |
3857 | | } |
3858 | | #ifdef CONFIG_SME |
3859 | | if (len > 0 && wpa_s->sme.ft_used && |
3860 | | wpa_sm_has_ft_keys(wpa_s->wpa, md)) { |
3861 | | wpa_dbg(wpa_s, MSG_DEBUG, |
3862 | | "SME: Trying to use FT over-the-air"); |
3863 | | algs |= WPA_AUTH_ALG_FT; |
3864 | | } |
3865 | | #endif /* CONFIG_SME */ |
3866 | | } |
3867 | | } |
3868 | | #endif /* CONFIG_IEEE80211R */ |
3869 | |
|
3870 | | #ifdef CONFIG_TESTING_OPTIONS |
3871 | | if (wpa_s->rsnxe_override_assoc && |
3872 | | wpabuf_len(wpa_s->rsnxe_override_assoc) <= |
3873 | | max_wpa_ie_len - wpa_ie_len) { |
3874 | | wpa_printf(MSG_DEBUG, "TESTING: RSNXE AssocReq override"); |
3875 | | os_memcpy(wpa_ie + wpa_ie_len, |
3876 | | wpabuf_head(wpa_s->rsnxe_override_assoc), |
3877 | | wpabuf_len(wpa_s->rsnxe_override_assoc)); |
3878 | | wpa_ie_len += wpabuf_len(wpa_s->rsnxe_override_assoc); |
3879 | | } else |
3880 | | #endif /* CONFIG_TESTING_OPTIONS */ |
3881 | 0 | if (wpa_s->rsnxe_len > 0 && |
3882 | 0 | wpa_s->rsnxe_len <= max_wpa_ie_len - wpa_ie_len) { |
3883 | 0 | os_memcpy(wpa_ie + wpa_ie_len, wpa_s->rsnxe, wpa_s->rsnxe_len); |
3884 | 0 | wpa_ie_len += wpa_s->rsnxe_len; |
3885 | 0 | } |
3886 | |
|
3887 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
3888 | | #ifdef CONFIG_TESTING_OPTIONS |
3889 | | if (wpa_s->disable_mscs_support) |
3890 | | goto mscs_end; |
3891 | | #endif /* CONFIG_TESTING_OPTIONS */ |
3892 | 0 | if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_MSCS) && |
3893 | 0 | wpa_s->robust_av.valid_config) { |
3894 | 0 | struct wpabuf *mscs_ie; |
3895 | 0 | size_t mscs_ie_len, buf_len; |
3896 | |
|
3897 | 0 | buf_len = 3 + /* MSCS descriptor IE header */ |
3898 | 0 | 1 + /* Request type */ |
3899 | 0 | 2 + /* User priority control */ |
3900 | 0 | 4 + /* Stream timeout */ |
3901 | 0 | 3 + /* TCLAS Mask IE header */ |
3902 | 0 | wpa_s->robust_av.frame_classifier_len; |
3903 | 0 | mscs_ie = wpabuf_alloc(buf_len); |
3904 | 0 | if (!mscs_ie) { |
3905 | 0 | wpa_printf(MSG_INFO, |
3906 | 0 | "MSCS: Failed to allocate MSCS IE"); |
3907 | 0 | goto mscs_end; |
3908 | 0 | } |
3909 | | |
3910 | 0 | wpas_populate_mscs_descriptor_ie(&wpa_s->robust_av, mscs_ie); |
3911 | 0 | if ((wpa_ie_len + wpabuf_len(mscs_ie)) <= max_wpa_ie_len) { |
3912 | 0 | wpa_hexdump_buf(MSG_MSGDUMP, "MSCS IE", mscs_ie); |
3913 | 0 | mscs_ie_len = wpabuf_len(mscs_ie); |
3914 | 0 | os_memcpy(wpa_ie + wpa_ie_len, wpabuf_head(mscs_ie), |
3915 | 0 | mscs_ie_len); |
3916 | 0 | wpa_ie_len += mscs_ie_len; |
3917 | 0 | } |
3918 | |
|
3919 | 0 | wpabuf_free(mscs_ie); |
3920 | 0 | } |
3921 | 0 | mscs_end: |
3922 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
3923 | |
|
3924 | 0 | wpa_ie_len = wpas_populate_wfa_capa(wpa_s, bss, wpa_ie, wpa_ie_len, |
3925 | 0 | max_wpa_ie_len); |
3926 | |
|
3927 | 0 | if (ssid->multi_ap_backhaul_sta) { |
3928 | 0 | size_t multi_ap_ie_len; |
3929 | 0 | struct multi_ap_params multi_ap = { 0 }; |
3930 | |
|
3931 | 0 | multi_ap.capability = MULTI_AP_BACKHAUL_STA; |
3932 | 0 | multi_ap.profile = ssid->multi_ap_profile; |
3933 | |
|
3934 | 0 | multi_ap_ie_len = add_multi_ap_ie(wpa_ie + wpa_ie_len, |
3935 | 0 | max_wpa_ie_len - wpa_ie_len, |
3936 | 0 | &multi_ap); |
3937 | 0 | if (multi_ap_ie_len == 0) { |
3938 | 0 | wpa_printf(MSG_ERROR, |
3939 | 0 | "Multi-AP: Failed to build Multi-AP IE"); |
3940 | 0 | os_free(wpa_ie); |
3941 | 0 | return NULL; |
3942 | 0 | } |
3943 | 0 | wpa_ie_len += multi_ap_ie_len; |
3944 | 0 | } |
3945 | | |
3946 | 0 | if (!wpas_driver_bss_selection(wpa_s) && |
3947 | 0 | wpas_rsn_overriding(wpa_s) && |
3948 | 0 | wpas_ap_supports_rsn_overriding(wpa_s, bss) && |
3949 | 0 | wpa_ie_len + 2 + 4 <= max_wpa_ie_len) { |
3950 | 0 | u8 *pos = wpa_ie + wpa_ie_len; |
3951 | 0 | u32 type = 0; |
3952 | 0 | const u8 *ie; |
3953 | |
|
3954 | 0 | ie = wpa_bss_get_rsne(wpa_s, bss, ssid, wpa_s->valid_links); |
3955 | 0 | if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4) |
3956 | 0 | type = WPA_GET_BE32(&ie[2]); |
3957 | |
|
3958 | 0 | if (type) { |
3959 | | /* Indicate support for RSN overriding */ |
3960 | 0 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
3961 | 0 | *pos++ = 4; |
3962 | 0 | WPA_PUT_BE32(pos, type); |
3963 | 0 | pos += 4; |
3964 | 0 | wpa_hexdump(MSG_MSGDUMP, "RSNE Override", wpa_ie, |
3965 | 0 | pos - wpa_ie); |
3966 | 0 | wpa_ie_len += 2 + 4; |
3967 | 0 | } |
3968 | 0 | } |
3969 | |
|
3970 | 0 | if (wpas_driver_bss_selection(wpa_s) && |
3971 | 0 | wpas_rsn_overriding(wpa_s)) { |
3972 | 0 | if (wpa_ie_len + 2 + 4 <= max_wpa_ie_len) { |
3973 | 0 | u8 *pos = wpa_ie + wpa_ie_len; |
3974 | |
|
3975 | 0 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
3976 | 0 | *pos++ = 4; |
3977 | 0 | WPA_PUT_BE32(pos, RSNE_OVERRIDE_IE_VENDOR_TYPE); |
3978 | 0 | pos += 4; |
3979 | 0 | wpa_hexdump(MSG_MSGDUMP, "RSNE Override", wpa_ie, |
3980 | 0 | pos - wpa_ie); |
3981 | 0 | wpa_ie_len += 2 + 4; |
3982 | 0 | } |
3983 | |
|
3984 | 0 | if (wpa_ie_len + 2 + 4 <= max_wpa_ie_len) { |
3985 | 0 | u8 *pos = wpa_ie + wpa_ie_len; |
3986 | |
|
3987 | 0 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
3988 | 0 | *pos++ = 4; |
3989 | 0 | WPA_PUT_BE32(pos, RSNE_OVERRIDE_2_IE_VENDOR_TYPE); |
3990 | 0 | pos += 4; |
3991 | 0 | wpa_hexdump(MSG_MSGDUMP, "RSNE Override 2", |
3992 | 0 | wpa_ie, pos - wpa_ie); |
3993 | 0 | wpa_ie_len += 2 + 4; |
3994 | 0 | } |
3995 | 0 | } |
3996 | |
|
3997 | 0 | params->wpa_ie = wpa_ie; |
3998 | 0 | params->wpa_ie_len = wpa_ie_len; |
3999 | 0 | params->auth_alg = algs; |
4000 | 0 | if (mask) |
4001 | 0 | *mask |= WPA_DRV_UPDATE_ASSOC_IES | WPA_DRV_UPDATE_AUTH_TYPE; |
4002 | |
|
4003 | 0 | return wpa_ie; |
4004 | 0 | } |
4005 | | |
4006 | | |
4007 | | #ifdef CONFIG_OWE |
4008 | | static void wpas_update_owe_connect_params(struct wpa_supplicant *wpa_s) |
4009 | | { |
4010 | | struct wpa_driver_associate_params params; |
4011 | | u8 *wpa_ie; |
4012 | | |
4013 | | os_memset(¶ms, 0, sizeof(params)); |
4014 | | wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss, |
4015 | | wpa_s->current_ssid, ¶ms, NULL); |
4016 | | if (!wpa_ie) |
4017 | | return; |
4018 | | |
4019 | | wpa_drv_update_connect_params(wpa_s, ¶ms, WPA_DRV_UPDATE_ASSOC_IES); |
4020 | | os_free(wpa_ie); |
4021 | | } |
4022 | | #endif /* CONFIG_OWE */ |
4023 | | |
4024 | | |
4025 | | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
4026 | | static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s) |
4027 | | { |
4028 | | struct wpa_driver_associate_params params; |
4029 | | enum wpa_drv_update_connect_params_mask mask = 0; |
4030 | | u8 *wpa_ie; |
4031 | | |
4032 | | if (wpa_s->auth_alg != WPA_AUTH_ALG_OPEN) |
4033 | | return; /* nothing to do */ |
4034 | | |
4035 | | os_memset(¶ms, 0, sizeof(params)); |
4036 | | wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss, |
4037 | | wpa_s->current_ssid, ¶ms, &mask); |
4038 | | if (!wpa_ie) |
4039 | | return; |
4040 | | |
4041 | | if (params.auth_alg == WPA_AUTH_ALG_FILS) { |
4042 | | wpa_s->auth_alg = params.auth_alg; |
4043 | | wpa_drv_update_connect_params(wpa_s, ¶ms, mask); |
4044 | | } |
4045 | | |
4046 | | os_free(wpa_ie); |
4047 | | } |
4048 | | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ |
4049 | | |
4050 | | |
4051 | | static u8 wpa_ie_get_edmg_oper_chans(const u8 *edmg_ie) |
4052 | 0 | { |
4053 | 0 | if (!edmg_ie || edmg_ie[1] < 6) |
4054 | 0 | return 0; |
4055 | 0 | return edmg_ie[EDMG_BSS_OPERATING_CHANNELS_OFFSET]; |
4056 | 0 | } |
4057 | | |
4058 | | |
4059 | | static u8 wpa_ie_get_edmg_oper_chan_width(const u8 *edmg_ie) |
4060 | 0 | { |
4061 | 0 | if (!edmg_ie || edmg_ie[1] < 6) |
4062 | 0 | return 0; |
4063 | 0 | return edmg_ie[EDMG_OPERATING_CHANNEL_WIDTH_OFFSET]; |
4064 | 0 | } |
4065 | | |
4066 | | |
4067 | | /* Returns the intersection of two EDMG configurations. |
4068 | | * Note: The current implementation is limited to CB2 only (CB1 included), |
4069 | | * i.e., the implementation supports up to 2 contiguous channels. |
4070 | | * For supporting non-contiguous (aggregated) channels and for supporting |
4071 | | * CB3 and above, this function will need to be extended. |
4072 | | */ |
4073 | | static struct ieee80211_edmg_config |
4074 | | get_edmg_intersection(struct ieee80211_edmg_config a, |
4075 | | struct ieee80211_edmg_config b, |
4076 | | u8 primary_channel) |
4077 | 0 | { |
4078 | 0 | struct ieee80211_edmg_config result; |
4079 | 0 | int i, contiguous = 0; |
4080 | 0 | int max_contiguous = 0; |
4081 | |
|
4082 | 0 | result.channels = b.channels & a.channels; |
4083 | 0 | if (!result.channels) { |
4084 | 0 | wpa_printf(MSG_DEBUG, |
4085 | 0 | "EDMG not possible: cannot intersect channels 0x%x and 0x%x", |
4086 | 0 | a.channels, b.channels); |
4087 | 0 | goto fail; |
4088 | 0 | } |
4089 | | |
4090 | 0 | if (!(result.channels & BIT(primary_channel - 1))) { |
4091 | 0 | wpa_printf(MSG_DEBUG, |
4092 | 0 | "EDMG not possible: the primary channel %d is not one of the intersected channels 0x%x", |
4093 | 0 | primary_channel, result.channels); |
4094 | 0 | goto fail; |
4095 | 0 | } |
4096 | | |
4097 | | /* Find max contiguous channels */ |
4098 | 0 | for (i = 0; i < 6; i++) { |
4099 | 0 | if (result.channels & BIT(i)) |
4100 | 0 | contiguous++; |
4101 | 0 | else |
4102 | 0 | contiguous = 0; |
4103 | |
|
4104 | 0 | if (contiguous > max_contiguous) |
4105 | 0 | max_contiguous = contiguous; |
4106 | 0 | } |
4107 | | |
4108 | | /* Assuming AP and STA supports ONLY contiguous channels, |
4109 | | * bw configuration can have value between 4-7. |
4110 | | */ |
4111 | 0 | if ((b.bw_config < a.bw_config)) |
4112 | 0 | result.bw_config = b.bw_config; |
4113 | 0 | else |
4114 | 0 | result.bw_config = a.bw_config; |
4115 | |
|
4116 | 0 | if ((max_contiguous >= 2 && result.bw_config < EDMG_BW_CONFIG_5) || |
4117 | 0 | (max_contiguous >= 1 && result.bw_config < EDMG_BW_CONFIG_4)) { |
4118 | 0 | wpa_printf(MSG_DEBUG, |
4119 | 0 | "EDMG not possible: not enough contiguous channels %d for supporting CB1 or CB2", |
4120 | 0 | max_contiguous); |
4121 | 0 | goto fail; |
4122 | 0 | } |
4123 | | |
4124 | 0 | return result; |
4125 | | |
4126 | 0 | fail: |
4127 | 0 | result.channels = 0; |
4128 | 0 | result.bw_config = 0; |
4129 | 0 | return result; |
4130 | 0 | } |
4131 | | |
4132 | | |
4133 | | static struct ieee80211_edmg_config |
4134 | | get_supported_edmg(struct wpa_supplicant *wpa_s, |
4135 | | struct hostapd_freq_params *freq, |
4136 | | struct ieee80211_edmg_config request_edmg) |
4137 | 0 | { |
4138 | 0 | enum hostapd_hw_mode hw_mode; |
4139 | 0 | struct hostapd_hw_modes *mode = NULL; |
4140 | 0 | u8 primary_channel; |
4141 | |
|
4142 | 0 | if (!wpa_s->hw.modes) |
4143 | 0 | goto fail; |
4144 | | |
4145 | 0 | hw_mode = ieee80211_freq_to_chan(freq->freq, &primary_channel); |
4146 | 0 | if (hw_mode == NUM_HOSTAPD_MODES) |
4147 | 0 | goto fail; |
4148 | | |
4149 | 0 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, hw_mode, false); |
4150 | 0 | if (!mode) |
4151 | 0 | goto fail; |
4152 | | |
4153 | 0 | return get_edmg_intersection(mode->edmg, request_edmg, primary_channel); |
4154 | | |
4155 | 0 | fail: |
4156 | 0 | request_edmg.channels = 0; |
4157 | 0 | request_edmg.bw_config = 0; |
4158 | 0 | return request_edmg; |
4159 | 0 | } |
4160 | | |
4161 | | |
4162 | | #ifdef CONFIG_MBO |
4163 | | void wpas_update_mbo_connect_params(struct wpa_supplicant *wpa_s) |
4164 | | { |
4165 | | struct wpa_driver_associate_params params; |
4166 | | u8 *wpa_ie; |
4167 | | |
4168 | | /* |
4169 | | * Update MBO connect params only in case of change of MBO attributes |
4170 | | * when connected, if the AP support MBO. |
4171 | | */ |
4172 | | |
4173 | | if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_ssid || |
4174 | | !wpa_s->current_bss || |
4175 | | !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE)) |
4176 | | return; |
4177 | | |
4178 | | os_memset(¶ms, 0, sizeof(params)); |
4179 | | wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss, |
4180 | | wpa_s->current_ssid, ¶ms, NULL); |
4181 | | if (!wpa_ie) |
4182 | | return; |
4183 | | |
4184 | | wpa_drv_update_connect_params(wpa_s, ¶ms, WPA_DRV_UPDATE_ASSOC_IES); |
4185 | | os_free(wpa_ie); |
4186 | | } |
4187 | | #endif /* CONFIG_MBO */ |
4188 | | |
4189 | | |
4190 | | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit) |
4191 | 0 | { |
4192 | 0 | struct wpa_connect_work *cwork = work->ctx; |
4193 | 0 | struct wpa_bss *bss = cwork->bss; |
4194 | 0 | struct wpa_ssid *ssid = cwork->ssid; |
4195 | 0 | struct wpa_supplicant *wpa_s = work->wpa_s; |
4196 | 0 | u8 *wpa_ie; |
4197 | 0 | const u8 *edmg_ie_oper; |
4198 | 0 | int use_crypt, ret, bssid_changed; |
4199 | 0 | unsigned int cipher_pairwise, cipher_group, cipher_group_mgmt; |
4200 | 0 | struct wpa_driver_associate_params params; |
4201 | 0 | u8 psk[PMK_LEN]; |
4202 | 0 | #if defined(CONFIG_WEP) || defined(IEEE8021X_EAPOL) |
4203 | 0 | int wep_keys_set = 0; |
4204 | 0 | #endif /* CONFIG_WEP || IEEE8021X_EAPOL */ |
4205 | 0 | int assoc_failed = 0; |
4206 | 0 | struct wpa_ssid *old_ssid; |
4207 | 0 | u8 prev_bssid[ETH_ALEN]; |
4208 | | #ifdef CONFIG_HT_OVERRIDES |
4209 | | struct ieee80211_ht_capabilities htcaps; |
4210 | | struct ieee80211_ht_capabilities htcaps_mask; |
4211 | | #endif /* CONFIG_HT_OVERRIDES */ |
4212 | | #ifdef CONFIG_VHT_OVERRIDES |
4213 | | struct ieee80211_vht_capabilities vhtcaps; |
4214 | | struct ieee80211_vht_capabilities vhtcaps_mask; |
4215 | | #endif /* CONFIG_VHT_OVERRIDES */ |
4216 | |
|
4217 | 0 | wpa_s->roam_in_progress = false; |
4218 | 0 | #ifdef CONFIG_WNM |
4219 | 0 | wpa_s->bss_trans_mgmt_in_progress = false; |
4220 | 0 | #endif /* CONFIG_WNM */ |
4221 | 0 | wpa_s->no_suitable_network = 0; |
4222 | |
|
4223 | 0 | if (deinit) { |
4224 | 0 | if (work->started) { |
4225 | 0 | wpa_s->connect_work = NULL; |
4226 | | |
4227 | | /* cancel possible auth. timeout */ |
4228 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, |
4229 | 0 | NULL); |
4230 | 0 | } |
4231 | 0 | wpas_connect_work_free(cwork); |
4232 | 0 | return; |
4233 | 0 | } |
4234 | | |
4235 | 0 | wpa_s->connect_work = work; |
4236 | |
|
4237 | 0 | if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid) || |
4238 | 0 | wpas_network_disabled(wpa_s, ssid)) { |
4239 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt"); |
4240 | 0 | wpas_connect_work_done(wpa_s); |
4241 | 0 | return; |
4242 | 0 | } |
4243 | | |
4244 | | /* |
4245 | | * Set the current AP's BSSID (for non-MLO connection) or MLD address |
4246 | | * (for MLO connection) as the previous BSSID for reassociation requests |
4247 | | * handled by SME-in-driver. If wpa_supplicant is in disconnected state, |
4248 | | * prev_bssid will be zero as both wpa_s->valid_links and wpa_s->bssid |
4249 | | * will be zero. |
4250 | | */ |
4251 | 0 | os_memcpy(prev_bssid, |
4252 | 0 | wpa_s->valid_links ? wpa_s->ap_mld_addr : wpa_s->bssid, |
4253 | 0 | ETH_ALEN); |
4254 | 0 | os_memset(¶ms, 0, sizeof(params)); |
4255 | 0 | wpa_s->reassociate = 0; |
4256 | 0 | wpa_s->eap_expected_failure = 0; |
4257 | | |
4258 | | /* Starting new association, so clear the possibly used WPA IE from the |
4259 | | * previous association. */ |
4260 | 0 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
4261 | 0 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
4262 | 0 | wpa_s->rsnxe_len = 0; |
4263 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
4264 | 0 | wpa_s->mscs_setup_done = false; |
4265 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
4266 | |
|
4267 | 0 | wpa_ie = wpas_populate_assoc_ies(wpa_s, bss, ssid, ¶ms, NULL); |
4268 | 0 | if (!wpa_ie) { |
4269 | 0 | wpas_connect_work_done(wpa_s); |
4270 | 0 | return; |
4271 | 0 | } |
4272 | | |
4273 | 0 | if (bss && |
4274 | 0 | (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) { |
4275 | | #ifdef CONFIG_IEEE80211R |
4276 | | const u8 *ie, *md = NULL; |
4277 | | #endif /* CONFIG_IEEE80211R */ |
4278 | 0 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR |
4279 | 0 | " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid), |
4280 | 0 | wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq); |
4281 | 0 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
4282 | 0 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
4283 | 0 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); |
4284 | 0 | if (bssid_changed) |
4285 | 0 | wpas_notify_bssid_changed(wpa_s); |
4286 | | #ifdef CONFIG_IEEE80211R |
4287 | | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
4288 | | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) |
4289 | | md = ie + 2; |
4290 | | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); |
4291 | | if (md) { |
4292 | | /* Prepare for the next transition */ |
4293 | | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); |
4294 | | } |
4295 | | #endif /* CONFIG_IEEE80211R */ |
4296 | | #ifdef CONFIG_WPS |
4297 | | } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) && |
4298 | | wpa_s->conf->ap_scan == 2 && |
4299 | | (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
4300 | | /* Use ap_scan==1 style network selection to find the network |
4301 | | */ |
4302 | | wpas_connect_work_done(wpa_s); |
4303 | | wpa_s->scan_req = MANUAL_SCAN_REQ; |
4304 | | wpa_s->reassociate = 1; |
4305 | | wpa_supplicant_req_scan(wpa_s, 0, 0); |
4306 | | os_free(wpa_ie); |
4307 | | return; |
4308 | | #endif /* CONFIG_WPS */ |
4309 | 0 | } else { |
4310 | 0 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'", |
4311 | 0 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
4312 | 0 | if (bss) |
4313 | 0 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); |
4314 | 0 | else |
4315 | 0 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
4316 | 0 | } |
4317 | 0 | if (!wpa_s->pno) |
4318 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
4319 | |
|
4320 | 0 | wpa_supplicant_cancel_scan(wpa_s); |
4321 | |
|
4322 | 0 | wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL); |
4323 | 0 | use_crypt = 1; |
4324 | 0 | cipher_pairwise = wpa_s->pairwise_cipher; |
4325 | 0 | cipher_group = wpa_s->group_cipher; |
4326 | 0 | cipher_group_mgmt = wpa_s->mgmt_group_cipher; |
4327 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
4328 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
4329 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) |
4330 | 0 | use_crypt = 0; |
4331 | | #ifdef CONFIG_WEP |
4332 | | if (wpa_set_wep_keys(wpa_s, ssid)) { |
4333 | | use_crypt = 1; |
4334 | | wep_keys_set = 1; |
4335 | | } |
4336 | | #endif /* CONFIG_WEP */ |
4337 | 0 | } |
4338 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) |
4339 | 0 | use_crypt = 0; |
4340 | |
|
4341 | 0 | #ifdef IEEE8021X_EAPOL |
4342 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
4343 | 0 | if ((ssid->eapol_flags & |
4344 | 0 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
4345 | 0 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 && |
4346 | 0 | !wep_keys_set) { |
4347 | 0 | use_crypt = 0; |
4348 | 0 | } else { |
4349 | | /* Assume that dynamic WEP-104 keys will be used and |
4350 | | * set cipher suites in order for drivers to expect |
4351 | | * encryption. */ |
4352 | 0 | cipher_pairwise = cipher_group = WPA_CIPHER_WEP104; |
4353 | 0 | } |
4354 | 0 | } |
4355 | 0 | #endif /* IEEE8021X_EAPOL */ |
4356 | |
|
4357 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
4358 | | /* Set the key before (and later after) association */ |
4359 | 0 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); |
4360 | 0 | } |
4361 | | |
4362 | | /* Set current_ssid before changing state to ASSOCIATING, so that the |
4363 | | * selected SSID is available to wpas_notify_state_changed(). */ |
4364 | 0 | old_ssid = wpa_s->current_ssid; |
4365 | 0 | wpa_s->current_ssid = ssid; |
4366 | |
|
4367 | 0 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); |
4368 | 0 | if (bss) { |
4369 | 0 | params.ssid = bss->ssid; |
4370 | 0 | params.ssid_len = bss->ssid_len; |
4371 | 0 | if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set || |
4372 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { |
4373 | 0 | wpa_printf(MSG_DEBUG, "Limit connection to BSSID " |
4374 | 0 | MACSTR " freq=%u MHz based on scan results " |
4375 | 0 | "(bssid_set=%d wps=%d)", |
4376 | 0 | MAC2STR(bss->bssid), bss->freq, |
4377 | 0 | ssid->bssid_set, |
4378 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); |
4379 | 0 | params.bssid = bss->bssid; |
4380 | 0 | params.freq.freq = bss->freq; |
4381 | 0 | } |
4382 | 0 | params.bssid_hint = bss->bssid; |
4383 | 0 | params.freq_hint = bss->freq; |
4384 | 0 | params.pbss = bss_is_pbss(bss); |
4385 | 0 | } else { |
4386 | 0 | if (ssid->bssid_hint_set) |
4387 | 0 | params.bssid_hint = ssid->bssid_hint; |
4388 | |
|
4389 | 0 | params.ssid = ssid->ssid; |
4390 | 0 | params.ssid_len = ssid->ssid_len; |
4391 | 0 | params.pbss = (ssid->pbss != 2) ? ssid->pbss : 0; |
4392 | 0 | } |
4393 | |
|
4394 | 0 | if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set && |
4395 | 0 | wpa_s->conf->ap_scan == 2) { |
4396 | 0 | params.bssid = ssid->bssid; |
4397 | 0 | params.fixed_bssid = 1; |
4398 | 0 | } |
4399 | | |
4400 | | /* Initial frequency for IBSS/mesh */ |
4401 | 0 | if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) && |
4402 | 0 | ssid->frequency > 0 && params.freq.freq == 0) |
4403 | 0 | ibss_mesh_setup_freq(wpa_s, ssid, ¶ms.freq); |
4404 | |
|
4405 | 0 | if (ssid->mode == WPAS_MODE_IBSS) { |
4406 | 0 | params.fixed_freq = ssid->fixed_freq; |
4407 | 0 | if (ssid->beacon_int) |
4408 | 0 | params.beacon_int = ssid->beacon_int; |
4409 | 0 | else |
4410 | 0 | params.beacon_int = wpa_s->conf->beacon_int; |
4411 | 0 | } |
4412 | |
|
4413 | 0 | if (bss && ssid->enable_edmg) |
4414 | 0 | edmg_ie_oper = wpa_bss_get_ie_ext(bss, |
4415 | 0 | WLAN_EID_EXT_EDMG_OPERATION); |
4416 | 0 | else |
4417 | 0 | edmg_ie_oper = NULL; |
4418 | |
|
4419 | 0 | if (edmg_ie_oper) { |
4420 | 0 | params.freq.edmg.channels = |
4421 | 0 | wpa_ie_get_edmg_oper_chans(edmg_ie_oper); |
4422 | 0 | params.freq.edmg.bw_config = |
4423 | 0 | wpa_ie_get_edmg_oper_chan_width(edmg_ie_oper); |
4424 | 0 | wpa_printf(MSG_DEBUG, |
4425 | 0 | "AP supports EDMG channels 0x%x, bw_config %d", |
4426 | 0 | params.freq.edmg.channels, |
4427 | 0 | params.freq.edmg.bw_config); |
4428 | | |
4429 | | /* User may ask for specific EDMG channel for EDMG connection |
4430 | | * (must be supported by AP) |
4431 | | */ |
4432 | 0 | if (ssid->edmg_channel) { |
4433 | 0 | struct ieee80211_edmg_config configured_edmg; |
4434 | 0 | enum hostapd_hw_mode hw_mode; |
4435 | 0 | u8 primary_channel; |
4436 | |
|
4437 | 0 | hw_mode = ieee80211_freq_to_chan(bss->freq, |
4438 | 0 | &primary_channel); |
4439 | 0 | if (hw_mode == NUM_HOSTAPD_MODES) |
4440 | 0 | goto edmg_fail; |
4441 | | |
4442 | 0 | hostapd_encode_edmg_chan(ssid->enable_edmg, |
4443 | 0 | ssid->edmg_channel, |
4444 | 0 | primary_channel, |
4445 | 0 | &configured_edmg); |
4446 | |
|
4447 | 0 | if (ieee802_edmg_is_allowed(params.freq.edmg, |
4448 | 0 | configured_edmg)) { |
4449 | 0 | params.freq.edmg = configured_edmg; |
4450 | 0 | wpa_printf(MSG_DEBUG, |
4451 | 0 | "Use EDMG channel %d for connection", |
4452 | 0 | ssid->edmg_channel); |
4453 | 0 | } else { |
4454 | 0 | edmg_fail: |
4455 | 0 | params.freq.edmg.channels = 0; |
4456 | 0 | params.freq.edmg.bw_config = 0; |
4457 | 0 | wpa_printf(MSG_WARNING, |
4458 | 0 | "EDMG channel %d not supported by AP, fallback to DMG", |
4459 | 0 | ssid->edmg_channel); |
4460 | 0 | } |
4461 | 0 | } |
4462 | | |
4463 | 0 | if (params.freq.edmg.channels) { |
4464 | 0 | wpa_printf(MSG_DEBUG, |
4465 | 0 | "EDMG before: channels 0x%x, bw_config %d", |
4466 | 0 | params.freq.edmg.channels, |
4467 | 0 | params.freq.edmg.bw_config); |
4468 | 0 | params.freq.edmg = get_supported_edmg(wpa_s, |
4469 | 0 | ¶ms.freq, |
4470 | 0 | params.freq.edmg); |
4471 | 0 | wpa_printf(MSG_DEBUG, |
4472 | 0 | "EDMG after: channels 0x%x, bw_config %d", |
4473 | 0 | params.freq.edmg.channels, |
4474 | 0 | params.freq.edmg.bw_config); |
4475 | 0 | } |
4476 | 0 | } |
4477 | | |
4478 | 0 | params.pairwise_suite = cipher_pairwise; |
4479 | 0 | params.group_suite = cipher_group; |
4480 | 0 | params.mgmt_group_suite = cipher_group_mgmt; |
4481 | 0 | params.key_mgmt_suite = wpa_s->key_mgmt; |
4482 | 0 | params.allowed_key_mgmts = wpa_s->allowed_key_mgmts; |
4483 | 0 | params.wpa_proto = wpa_s->wpa_proto; |
4484 | 0 | wpa_s->auth_alg = params.auth_alg; |
4485 | 0 | params.mode = ssid->mode; |
4486 | 0 | params.bg_scan_period = ssid->bg_scan_period; |
4487 | | #ifdef CONFIG_WEP |
4488 | | { |
4489 | | int i; |
4490 | | |
4491 | | for (i = 0; i < NUM_WEP_KEYS; i++) { |
4492 | | if (ssid->wep_key_len[i]) |
4493 | | params.wep_key[i] = ssid->wep_key[i]; |
4494 | | params.wep_key_len[i] = ssid->wep_key_len[i]; |
4495 | | } |
4496 | | params.wep_tx_keyidx = ssid->wep_tx_keyidx; |
4497 | | } |
4498 | | #endif /* CONFIG_WEP */ |
4499 | |
|
4500 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) && |
4501 | 0 | (params.key_mgmt_suite == WPA_KEY_MGMT_PSK || |
4502 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
4503 | 0 | (params.allowed_key_mgmts & |
4504 | 0 | (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK)))) { |
4505 | 0 | params.passphrase = ssid->passphrase; |
4506 | 0 | if (wpa_supplicant_get_psk(wpa_s, bss, ssid, psk) == 0) |
4507 | 0 | params.psk = psk; |
4508 | 0 | } |
4509 | |
|
4510 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) && |
4511 | 0 | (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4512 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
4513 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
4514 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
4515 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384)) |
4516 | 0 | params.req_handshake_offload = 1; |
4517 | |
|
4518 | 0 | if (wpa_s->conf->key_mgmt_offload) { |
4519 | 0 | if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4520 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
4521 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
4522 | 0 | params.key_mgmt_suite == |
4523 | 0 | WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
4524 | 0 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) |
4525 | 0 | params.req_key_mgmt_offload = |
4526 | 0 | ssid->proactive_key_caching < 0 ? |
4527 | 0 | wpa_s->conf->okc : ssid->proactive_key_caching; |
4528 | 0 | else |
4529 | 0 | params.req_key_mgmt_offload = 1; |
4530 | |
|
4531 | 0 | if ((wpa_key_mgmt_wpa_psk_no_sae(params.key_mgmt_suite) || |
4532 | 0 | wpa_key_mgmt_wpa_psk_no_sae(params.allowed_key_mgmts)) && |
4533 | 0 | wpa_supplicant_get_psk(wpa_s, bss, ssid, psk) == 0) |
4534 | 0 | params.psk = psk; |
4535 | 0 | } |
4536 | |
|
4537 | 0 | if ((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA) && |
4538 | 0 | wpa_key_mgmt_sae(params.key_mgmt_suite)) { |
4539 | 0 | params.auth_alg = WPA_AUTH_ALG_SAE; |
4540 | 0 | if (ssid->sae_password) { |
4541 | 0 | params.sae_password = ssid->sae_password; |
4542 | 0 | params.sae_password_id = ssid->sae_password_id; |
4543 | 0 | } else if (ssid->passphrase) { |
4544 | 0 | params.passphrase = ssid->passphrase; |
4545 | 0 | } |
4546 | 0 | } |
4547 | |
|
4548 | 0 | params.drop_unencrypted = use_crypt; |
4549 | |
|
4550 | 0 | params.mgmt_frame_protection = wpas_get_ssid_pmf(wpa_s, ssid); |
4551 | 0 | if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) { |
4552 | 0 | const u8 *rsn = wpa_bss_get_rsne(wpa_s, bss, ssid, false); |
4553 | 0 | struct wpa_ie_data ie; |
4554 | 0 | if (!wpas_driver_bss_selection(wpa_s) && rsn && |
4555 | 0 | wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 && |
4556 | 0 | ie.capabilities & |
4557 | 0 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { |
4558 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports " |
4559 | 0 | "MFP: require MFP"); |
4560 | 0 | params.mgmt_frame_protection = |
4561 | 0 | MGMT_FRAME_PROTECTION_REQUIRED; |
4562 | | #ifdef CONFIG_OWE |
4563 | | } else if (!rsn && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
4564 | | !ssid->owe_only) { |
4565 | | params.mgmt_frame_protection = NO_MGMT_FRAME_PROTECTION; |
4566 | | #endif /* CONFIG_OWE */ |
4567 | 0 | } |
4568 | 0 | } |
4569 | |
|
4570 | 0 | params.p2p = ssid->p2p_group; |
4571 | |
|
4572 | 0 | if (wpa_s->p2pdev->set_sta_uapsd) |
4573 | 0 | params.uapsd = wpa_s->p2pdev->sta_uapsd; |
4574 | 0 | else |
4575 | 0 | params.uapsd = -1; |
4576 | |
|
4577 | | #ifdef CONFIG_HT_OVERRIDES |
4578 | | os_memset(&htcaps, 0, sizeof(htcaps)); |
4579 | | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); |
4580 | | params.htcaps = (u8 *) &htcaps; |
4581 | | params.htcaps_mask = (u8 *) &htcaps_mask; |
4582 | | wpa_supplicant_apply_ht_overrides(wpa_s, ssid, ¶ms); |
4583 | | #endif /* CONFIG_HT_OVERRIDES */ |
4584 | | #ifdef CONFIG_VHT_OVERRIDES |
4585 | | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); |
4586 | | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); |
4587 | | params.vhtcaps = &vhtcaps; |
4588 | | params.vhtcaps_mask = &vhtcaps_mask; |
4589 | | wpa_supplicant_apply_vht_overrides(wpa_s, ssid, ¶ms); |
4590 | | #endif /* CONFIG_VHT_OVERRIDES */ |
4591 | | #ifdef CONFIG_HE_OVERRIDES |
4592 | | wpa_supplicant_apply_he_overrides(wpa_s, ssid, ¶ms); |
4593 | | #endif /* CONFIG_HE_OVERRIDES */ |
4594 | 0 | wpa_supplicant_apply_eht_overrides(wpa_s, ssid, ¶ms); |
4595 | |
|
4596 | | #ifdef CONFIG_P2P |
4597 | | /* |
4598 | | * If multi-channel concurrency is not supported, check for any |
4599 | | * frequency conflict. In case of any frequency conflict, remove the |
4600 | | * least prioritized connection. |
4601 | | */ |
4602 | | if (wpa_s->num_multichan_concurrent < 2) { |
4603 | | int freq, num; |
4604 | | num = get_shared_radio_freqs(wpa_s, &freq, 1, false); |
4605 | | if (num > 0 && freq > 0 && freq != params.freq.freq) { |
4606 | | wpa_printf(MSG_DEBUG, |
4607 | | "Assoc conflicting freq found (%d != %d)", |
4608 | | freq, params.freq.freq); |
4609 | | if (wpas_p2p_handle_frequency_conflicts( |
4610 | | wpa_s, params.freq.freq, ssid) < 0) { |
4611 | | wpas_connect_work_done(wpa_s); |
4612 | | os_free(wpa_ie); |
4613 | | return; |
4614 | | } |
4615 | | } |
4616 | | } |
4617 | | #endif /* CONFIG_P2P */ |
4618 | |
|
4619 | 0 | if (wpa_s->reassoc_same_ess && !is_zero_ether_addr(prev_bssid) && |
4620 | 0 | old_ssid) |
4621 | 0 | params.prev_bssid = prev_bssid; |
4622 | |
|
4623 | | #ifdef CONFIG_SAE |
4624 | | params.sae_pwe = wpa_s->conf->sae_pwe; |
4625 | | #endif /* CONFIG_SAE */ |
4626 | |
|
4627 | 0 | ret = wpa_drv_associate(wpa_s, ¶ms); |
4628 | 0 | forced_memzero(psk, sizeof(psk)); |
4629 | 0 | os_free(wpa_ie); |
4630 | 0 | if (ret < 0) { |
4631 | 0 | wpa_msg(wpa_s, MSG_INFO, "Association request to the driver " |
4632 | 0 | "failed"); |
4633 | 0 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_VALID_ERROR_CODES) { |
4634 | | /* |
4635 | | * The driver is known to mean what is saying, so we |
4636 | | * can stop right here; the association will not |
4637 | | * succeed. |
4638 | | */ |
4639 | 0 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid, |
4640 | 0 | NULL); |
4641 | 0 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
4642 | 0 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
4643 | 0 | return; |
4644 | 0 | } |
4645 | | /* try to continue anyway; new association will be tried again |
4646 | | * after timeout */ |
4647 | 0 | assoc_failed = 1; |
4648 | 0 | } |
4649 | | |
4650 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
4651 | | /* Set the key after the association just in case association |
4652 | | * cleared the previously configured key. */ |
4653 | 0 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); |
4654 | | /* No need to timeout authentication since there is no key |
4655 | | * management. */ |
4656 | 0 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
4657 | 0 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
4658 | | #ifdef CONFIG_IBSS_RSN |
4659 | | } else if (ssid->mode == WPAS_MODE_IBSS && |
4660 | | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
4661 | | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { |
4662 | | /* |
4663 | | * RSN IBSS authentication is per-STA and we can disable the |
4664 | | * per-BSSID authentication. |
4665 | | */ |
4666 | | wpa_supplicant_cancel_auth_timeout(wpa_s); |
4667 | | #endif /* CONFIG_IBSS_RSN */ |
4668 | 0 | } else { |
4669 | | /* Timeout for IEEE 802.11 authentication and association */ |
4670 | 0 | int timeout = 60; |
4671 | |
|
4672 | 0 | if (assoc_failed) { |
4673 | | /* give IBSS a bit more time */ |
4674 | 0 | timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5; |
4675 | 0 | } else if (wpa_s->conf->ap_scan == 1) { |
4676 | | /* give IBSS a bit more time */ |
4677 | 0 | timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10; |
4678 | 0 | } |
4679 | 0 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
4680 | 0 | } |
4681 | |
|
4682 | | #ifdef CONFIG_WEP |
4683 | | if (wep_keys_set && |
4684 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) { |
4685 | | /* Set static WEP keys again */ |
4686 | | wpa_set_wep_keys(wpa_s, ssid); |
4687 | | } |
4688 | | #endif /* CONFIG_WEP */ |
4689 | |
|
4690 | 0 | if (old_ssid && old_ssid != ssid) { |
4691 | | /* |
4692 | | * Do not allow EAP session resumption between different |
4693 | | * network configurations. |
4694 | | */ |
4695 | 0 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
4696 | 0 | } |
4697 | |
|
4698 | 0 | if (!wpas_driver_bss_selection(wpa_s) || |
4699 | | #ifdef CONFIG_P2P |
4700 | | wpa_s->p2p_in_invitation || |
4701 | | #endif /* CONFIG_P2P */ |
4702 | 0 | ssid->bssid_set) { |
4703 | 0 | wpa_s->current_bss = bss; |
4704 | 0 | #ifdef CONFIG_HS20 |
4705 | 0 | hs20_configure_frame_filters(wpa_s); |
4706 | 0 | #endif /* CONFIG_HS20 */ |
4707 | 0 | } |
4708 | |
|
4709 | 0 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
4710 | 0 | if (bss) |
4711 | 0 | wpa_sm_set_ssid(wpa_s->wpa, bss->ssid, bss->ssid_len); |
4712 | 0 | wpa_supplicant_initiate_eapol(wpa_s); |
4713 | 0 | if (old_ssid != wpa_s->current_ssid) |
4714 | 0 | wpas_notify_network_changed(wpa_s); |
4715 | 0 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
4716 | 0 | wpas_notify_auth_changed(wpa_s); |
4717 | 0 | } |
4718 | | |
4719 | | |
4720 | | static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s, |
4721 | | const u8 *addr) |
4722 | 0 | { |
4723 | 0 | struct wpa_ssid *old_ssid; |
4724 | |
|
4725 | 0 | wpa_s->ml_connect_probe_ssid = NULL; |
4726 | 0 | wpa_s->ml_connect_probe_bss = NULL; |
4727 | 0 | wpas_connect_work_done(wpa_s); |
4728 | 0 | wpa_clear_keys(wpa_s, addr); |
4729 | 0 | old_ssid = wpa_s->current_ssid; |
4730 | 0 | wpa_supplicant_mark_disassoc(wpa_s); |
4731 | 0 | wpa_sm_set_config(wpa_s->wpa, NULL); |
4732 | 0 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
4733 | 0 | if (old_ssid != wpa_s->current_ssid) |
4734 | 0 | wpas_notify_network_changed(wpa_s); |
4735 | |
|
4736 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
4737 | 0 | wpas_scs_deinit(wpa_s); |
4738 | 0 | wpas_dscp_deinit(wpa_s); |
4739 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
4740 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
4741 | 0 | } |
4742 | | |
4743 | | |
4744 | | /** |
4745 | | * wpa_supplicant_deauthenticate - Deauthenticate the current connection |
4746 | | * @wpa_s: Pointer to wpa_supplicant data |
4747 | | * @reason_code: IEEE 802.11 reason code for the deauthenticate frame |
4748 | | * |
4749 | | * This function is used to request %wpa_supplicant to deauthenticate from the |
4750 | | * current AP. |
4751 | | */ |
4752 | | void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s, |
4753 | | u16 reason_code) |
4754 | 0 | { |
4755 | 0 | u8 *addr = NULL; |
4756 | 0 | union wpa_event_data event; |
4757 | 0 | int zero_addr = 0; |
4758 | |
|
4759 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR |
4760 | 0 | " pending_bssid=" MACSTR |
4761 | 0 | " reason=%d (%s) state=%s valid_links=0x%x ap_mld_addr=" MACSTR, |
4762 | 0 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), |
4763 | 0 | reason_code, reason2str(reason_code), |
4764 | 0 | wpa_supplicant_state_txt(wpa_s->wpa_state), wpa_s->valid_links, |
4765 | 0 | MAC2STR(wpa_s->ap_mld_addr)); |
4766 | |
|
4767 | 0 | if (wpa_s->valid_links && !is_zero_ether_addr(wpa_s->ap_mld_addr)) |
4768 | 0 | addr = wpa_s->ap_mld_addr; |
4769 | 0 | else if (!is_zero_ether_addr(wpa_s->pending_bssid) && |
4770 | 0 | (wpa_s->wpa_state == WPA_AUTHENTICATING || |
4771 | 0 | wpa_s->wpa_state == WPA_ASSOCIATING)) |
4772 | 0 | addr = wpa_s->pending_bssid; |
4773 | 0 | else if (!is_zero_ether_addr(wpa_s->bssid)) |
4774 | 0 | addr = wpa_s->bssid; |
4775 | 0 | else if (wpa_s->wpa_state == WPA_ASSOCIATING) { |
4776 | | /* |
4777 | | * When using driver-based BSS selection, we may not know the |
4778 | | * BSSID with which we are currently trying to associate. We |
4779 | | * need to notify the driver of this disconnection even in such |
4780 | | * a case, so use the all zeros address here. |
4781 | | */ |
4782 | 0 | addr = wpa_s->bssid; |
4783 | 0 | zero_addr = 1; |
4784 | 0 | } |
4785 | |
|
4786 | 0 | if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0) |
4787 | 0 | wpa_s->enabled_4addr_mode = 0; |
4788 | |
|
4789 | | #ifdef CONFIG_TDLS |
4790 | | wpa_tdls_teardown_peers(wpa_s->wpa); |
4791 | | #endif /* CONFIG_TDLS */ |
4792 | |
|
4793 | | #ifdef CONFIG_MESH |
4794 | | if (wpa_s->ifmsh) { |
4795 | | struct mesh_conf *mconf; |
4796 | | |
4797 | | mconf = wpa_s->ifmsh->mconf; |
4798 | | wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s", |
4799 | | wpa_s->ifname); |
4800 | | wpas_notify_mesh_group_removed(wpa_s, mconf->meshid, |
4801 | | mconf->meshid_len, reason_code); |
4802 | | wpa_supplicant_leave_mesh(wpa_s, true); |
4803 | | } |
4804 | | #endif /* CONFIG_MESH */ |
4805 | |
|
4806 | 0 | if (addr) { |
4807 | 0 | wpa_drv_deauthenticate(wpa_s, addr, reason_code); |
4808 | 0 | os_memset(&event, 0, sizeof(event)); |
4809 | 0 | event.deauth_info.reason_code = reason_code; |
4810 | 0 | event.deauth_info.locally_generated = 1; |
4811 | 0 | wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event); |
4812 | 0 | if (zero_addr) |
4813 | 0 | addr = NULL; |
4814 | 0 | } |
4815 | |
|
4816 | 0 | wpa_supplicant_clear_connection(wpa_s, addr); |
4817 | 0 | } |
4818 | | |
4819 | | |
4820 | | void wpa_supplicant_reconnect(struct wpa_supplicant *wpa_s) |
4821 | 0 | { |
4822 | 0 | wpa_s->own_reconnect_req = 1; |
4823 | 0 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
4824 | |
|
4825 | 0 | } |
4826 | | |
4827 | | |
4828 | | static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s, |
4829 | | struct wpa_ssid *ssid) |
4830 | 0 | { |
4831 | 0 | if (!ssid || !ssid->disabled || ssid->disabled == 2) |
4832 | 0 | return; |
4833 | | |
4834 | 0 | ssid->disabled = 0; |
4835 | 0 | ssid->owe_transition_bss_select_count = 0; |
4836 | 0 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
4837 | 0 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
4838 | | |
4839 | | /* |
4840 | | * Try to reassociate since there is no current configuration and a new |
4841 | | * network was made available. |
4842 | | */ |
4843 | 0 | if (!wpa_s->current_ssid && !wpa_s->disconnected) |
4844 | 0 | wpa_s->reassociate = 1; |
4845 | 0 | } |
4846 | | |
4847 | | |
4848 | | /** |
4849 | | * wpa_supplicant_add_network - Add a new network |
4850 | | * @wpa_s: wpa_supplicant structure for a network interface |
4851 | | * Returns: The new network configuration or %NULL if operation failed |
4852 | | * |
4853 | | * This function performs the following operations: |
4854 | | * 1. Adds a new network. |
4855 | | * 2. Send network addition notification. |
4856 | | * 3. Marks the network disabled. |
4857 | | * 4. Set network default parameters. |
4858 | | */ |
4859 | | struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s) |
4860 | 0 | { |
4861 | 0 | struct wpa_ssid *ssid; |
4862 | |
|
4863 | 0 | ssid = wpa_config_add_network(wpa_s->conf); |
4864 | 0 | if (!ssid) |
4865 | 0 | return NULL; |
4866 | 0 | wpas_notify_network_added(wpa_s, ssid); |
4867 | 0 | ssid->disabled = 1; |
4868 | 0 | wpa_config_set_network_defaults(ssid); |
4869 | |
|
4870 | 0 | return ssid; |
4871 | 0 | } |
4872 | | |
4873 | | |
4874 | | /** |
4875 | | * wpa_supplicant_remove_network - Remove a configured network based on id |
4876 | | * @wpa_s: wpa_supplicant structure for a network interface |
4877 | | * @id: Unique network id to search for |
4878 | | * Returns: 0 on success, or -1 if the network was not found, -2 if the network |
4879 | | * could not be removed |
4880 | | * |
4881 | | * This function performs the following operations: |
4882 | | * 1. Removes the network. |
4883 | | * 2. Send network removal notification. |
4884 | | * 3. Update internal state machines. |
4885 | | * 4. Stop any running sched scans. |
4886 | | */ |
4887 | | int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id) |
4888 | 0 | { |
4889 | 0 | struct wpa_ssid *ssid, *prev = wpa_s->current_ssid; |
4890 | 0 | int was_disabled; |
4891 | |
|
4892 | 0 | ssid = wpa_config_get_network(wpa_s->conf, id); |
4893 | 0 | if (!ssid) |
4894 | 0 | return -1; |
4895 | 0 | wpas_notify_network_removed(wpa_s, ssid); |
4896 | |
|
4897 | 0 | if (ssid == prev || !prev) { |
4898 | | #ifdef CONFIG_SME |
4899 | | wpa_s->sme.prev_bssid_set = 0; |
4900 | | #endif /* CONFIG_SME */ |
4901 | | /* |
4902 | | * Invalidate the EAP session cache if the current or |
4903 | | * previously used network is removed. |
4904 | | */ |
4905 | 0 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
4906 | 0 | } |
4907 | |
|
4908 | 0 | if (ssid == prev) { |
4909 | 0 | wpa_sm_set_config(wpa_s->wpa, NULL); |
4910 | 0 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
4911 | |
|
4912 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
4913 | 0 | wpa_s->own_disconnect_req = 1; |
4914 | 0 | wpa_supplicant_deauthenticate(wpa_s, |
4915 | 0 | WLAN_REASON_DEAUTH_LEAVING); |
4916 | 0 | } |
4917 | |
|
4918 | 0 | was_disabled = ssid->disabled; |
4919 | |
|
4920 | 0 | if (wpa_config_remove_network(wpa_s->conf, id) < 0) |
4921 | 0 | return -2; |
4922 | | |
4923 | 0 | if (!was_disabled && wpa_s->sched_scanning) { |
4924 | 0 | wpa_printf(MSG_DEBUG, |
4925 | 0 | "Stop ongoing sched_scan to remove network from filters"); |
4926 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
4927 | 0 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
4928 | 0 | } |
4929 | |
|
4930 | 0 | return 0; |
4931 | 0 | } |
4932 | | |
4933 | | |
4934 | | /** |
4935 | | * wpa_supplicant_remove_all_networks - Remove all configured networks |
4936 | | * @wpa_s: wpa_supplicant structure for a network interface |
4937 | | * Returns: 0 on success (errors are currently ignored) |
4938 | | * |
4939 | | * This function performs the following operations: |
4940 | | * 1. Remove all networks. |
4941 | | * 2. Send network removal notifications. |
4942 | | * 3. Update internal state machines. |
4943 | | * 4. Stop any running sched scans. |
4944 | | */ |
4945 | | int wpa_supplicant_remove_all_networks(struct wpa_supplicant *wpa_s) |
4946 | 0 | { |
4947 | 0 | struct wpa_ssid *ssid; |
4948 | |
|
4949 | 0 | if (wpa_s->drv_flags2 & |
4950 | 0 | (WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA | |
4951 | 0 | WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA)) |
4952 | 0 | wpa_drv_flush_pmkid(wpa_s); |
4953 | |
|
4954 | 0 | if (wpa_s->sched_scanning) |
4955 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
4956 | |
|
4957 | 0 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
4958 | 0 | if (wpa_s->current_ssid) { |
4959 | | #ifdef CONFIG_SME |
4960 | | wpa_s->sme.prev_bssid_set = 0; |
4961 | | #endif /* CONFIG_SME */ |
4962 | 0 | wpa_sm_set_config(wpa_s->wpa, NULL); |
4963 | 0 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
4964 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
4965 | 0 | wpa_s->own_disconnect_req = 1; |
4966 | 0 | wpa_supplicant_deauthenticate( |
4967 | 0 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
4968 | 0 | } |
4969 | 0 | ssid = wpa_s->conf->ssid; |
4970 | 0 | while (ssid) { |
4971 | 0 | struct wpa_ssid *remove_ssid = ssid; |
4972 | 0 | int id; |
4973 | |
|
4974 | 0 | id = ssid->id; |
4975 | 0 | ssid = ssid->next; |
4976 | 0 | wpas_notify_network_removed(wpa_s, remove_ssid); |
4977 | 0 | wpa_config_remove_network(wpa_s->conf, id); |
4978 | 0 | } |
4979 | 0 | return 0; |
4980 | 0 | } |
4981 | | |
4982 | | |
4983 | | /** |
4984 | | * wpa_supplicant_enable_network - Mark a configured network as enabled |
4985 | | * @wpa_s: wpa_supplicant structure for a network interface |
4986 | | * @ssid: wpa_ssid structure for a configured network or %NULL |
4987 | | * |
4988 | | * Enables the specified network or all networks if no network specified. |
4989 | | */ |
4990 | | void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s, |
4991 | | struct wpa_ssid *ssid) |
4992 | 0 | { |
4993 | 0 | if (ssid == NULL) { |
4994 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
4995 | 0 | wpa_supplicant_enable_one_network(wpa_s, ssid); |
4996 | 0 | } else |
4997 | 0 | wpa_supplicant_enable_one_network(wpa_s, ssid); |
4998 | |
|
4999 | 0 | if (wpa_s->reassociate && !wpa_s->disconnected && |
5000 | 0 | (!wpa_s->current_ssid || |
5001 | 0 | wpa_s->wpa_state == WPA_DISCONNECTED || |
5002 | 0 | wpa_s->wpa_state == WPA_SCANNING)) { |
5003 | 0 | if (wpa_s->sched_scanning) { |
5004 | 0 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add " |
5005 | 0 | "new network to scan filters"); |
5006 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
5007 | 0 | } |
5008 | |
|
5009 | 0 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { |
5010 | 0 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
5011 | 0 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
5012 | 0 | } |
5013 | 0 | } |
5014 | 0 | } |
5015 | | |
5016 | | |
5017 | | /** |
5018 | | * wpa_supplicant_disable_network - Mark a configured network as disabled |
5019 | | * @wpa_s: wpa_supplicant structure for a network interface |
5020 | | * @ssid: wpa_ssid structure for a configured network or %NULL |
5021 | | * |
5022 | | * Disables the specified network or all networks if no network specified. |
5023 | | */ |
5024 | | void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s, |
5025 | | struct wpa_ssid *ssid) |
5026 | 0 | { |
5027 | 0 | struct wpa_ssid *other_ssid; |
5028 | 0 | int was_disabled; |
5029 | |
|
5030 | 0 | if (ssid == NULL) { |
5031 | 0 | if (wpa_s->sched_scanning) |
5032 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
5033 | |
|
5034 | 0 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
5035 | 0 | other_ssid = other_ssid->next) { |
5036 | 0 | was_disabled = other_ssid->disabled; |
5037 | 0 | if (was_disabled == 2) |
5038 | 0 | continue; /* do not change persistent P2P group |
5039 | | * data */ |
5040 | | |
5041 | 0 | other_ssid->disabled = 1; |
5042 | |
|
5043 | 0 | if (was_disabled != other_ssid->disabled) |
5044 | 0 | wpas_notify_network_enabled_changed( |
5045 | 0 | wpa_s, other_ssid); |
5046 | 0 | } |
5047 | 0 | if (wpa_s->current_ssid) { |
5048 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
5049 | 0 | wpa_s->own_disconnect_req = 1; |
5050 | 0 | wpa_supplicant_deauthenticate( |
5051 | 0 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
5052 | 0 | } |
5053 | 0 | } else if (ssid->disabled != 2) { |
5054 | 0 | if (ssid == wpa_s->current_ssid) { |
5055 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
5056 | 0 | wpa_s->own_disconnect_req = 1; |
5057 | 0 | wpa_supplicant_deauthenticate( |
5058 | 0 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
5059 | 0 | } |
5060 | |
|
5061 | 0 | was_disabled = ssid->disabled; |
5062 | |
|
5063 | 0 | ssid->disabled = 1; |
5064 | |
|
5065 | 0 | if (was_disabled != ssid->disabled) { |
5066 | 0 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
5067 | 0 | if (wpa_s->sched_scanning) { |
5068 | 0 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan " |
5069 | 0 | "to remove network from filters"); |
5070 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
5071 | 0 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
5072 | 0 | } |
5073 | 0 | } |
5074 | 0 | } |
5075 | 0 | } |
5076 | | |
5077 | | |
5078 | | /** |
5079 | | * wpa_supplicant_select_network - Attempt association with a network |
5080 | | * @wpa_s: wpa_supplicant structure for a network interface |
5081 | | * @ssid: wpa_ssid structure for a configured network or %NULL for any network |
5082 | | */ |
5083 | | void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, |
5084 | | struct wpa_ssid *ssid) |
5085 | 0 | { |
5086 | |
|
5087 | 0 | struct wpa_ssid *other_ssid; |
5088 | 0 | int disconnected = 0; |
5089 | 0 | bool request_new_scan = false; |
5090 | |
|
5091 | 0 | if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) { |
5092 | 0 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
5093 | 0 | wpa_s->own_disconnect_req = 1; |
5094 | 0 | wpa_supplicant_deauthenticate( |
5095 | 0 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
5096 | 0 | disconnected = 1; |
5097 | 0 | } |
5098 | |
|
5099 | 0 | if (ssid) |
5100 | 0 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
5101 | | |
5102 | | /* |
5103 | | * Mark all other networks disabled or mark all networks enabled if no |
5104 | | * network specified. |
5105 | | */ |
5106 | 0 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
5107 | 0 | other_ssid = other_ssid->next) { |
5108 | 0 | int was_disabled = other_ssid->disabled; |
5109 | 0 | if (was_disabled == 2) |
5110 | 0 | continue; /* do not change persistent P2P group data */ |
5111 | | |
5112 | 0 | other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0; |
5113 | 0 | if (was_disabled && !other_ssid->disabled) |
5114 | 0 | wpas_clear_temp_disabled(wpa_s, other_ssid, 0); |
5115 | |
|
5116 | 0 | if (was_disabled != other_ssid->disabled) |
5117 | 0 | wpas_notify_network_enabled_changed(wpa_s, other_ssid); |
5118 | 0 | } |
5119 | |
|
5120 | 0 | if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid && |
5121 | 0 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
5122 | | /* We are already associated with the selected network */ |
5123 | 0 | wpa_printf(MSG_DEBUG, "Already associated with the " |
5124 | 0 | "selected network - do nothing"); |
5125 | 0 | return; |
5126 | 0 | } |
5127 | | |
5128 | 0 | if (ssid) { |
5129 | 0 | wpa_s->current_ssid = ssid; |
5130 | 0 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
5131 | 0 | wpa_s->connect_without_scan = |
5132 | 0 | (ssid->mode == WPAS_MODE_MESH || |
5133 | 0 | ssid->mode == WPAS_MODE_AP) ? ssid : NULL; |
5134 | |
|
5135 | 0 | if (ssid->scan_ssid && |
5136 | 0 | (wpa_s->no_suitable_network || wpa_s->last_scan_external)) { |
5137 | 0 | wpa_printf(MSG_DEBUG, |
5138 | 0 | "Request a new scan for hidden network"); |
5139 | 0 | request_new_scan = true; |
5140 | 0 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
5141 | 0 | !ssid->owe_only) { |
5142 | 0 | wpa_printf(MSG_DEBUG, |
5143 | 0 | "Request a new scan for OWE transition SSID"); |
5144 | 0 | request_new_scan = true; |
5145 | 0 | } |
5146 | | |
5147 | | /* |
5148 | | * Don't optimize next scan freqs since a new ESS has been |
5149 | | * selected. |
5150 | | */ |
5151 | 0 | os_free(wpa_s->next_scan_freqs); |
5152 | 0 | wpa_s->next_scan_freqs = NULL; |
5153 | 0 | } else { |
5154 | 0 | wpa_s->connect_without_scan = NULL; |
5155 | 0 | } |
5156 | |
|
5157 | 0 | wpa_s->disconnected = 0; |
5158 | 0 | wpa_s->reassociate = 1; |
5159 | 0 | wpa_s_clear_sae_rejected(wpa_s); |
5160 | 0 | wpa_s->last_owe_group = 0; |
5161 | 0 | if (ssid) { |
5162 | 0 | ssid->owe_transition_bss_select_count = 0; |
5163 | 0 | wpa_s_setup_sae_pt(wpa_s->conf, ssid, false); |
5164 | 0 | } |
5165 | |
|
5166 | 0 | if (wpa_s->connect_without_scan || request_new_scan || |
5167 | 0 | wpa_supplicant_fast_associate(wpa_s) != 1) { |
5168 | 0 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
5169 | 0 | wpas_scan_reset_sched_scan(wpa_s); |
5170 | 0 | wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0); |
5171 | 0 | } |
5172 | |
|
5173 | 0 | if (ssid) |
5174 | 0 | wpas_notify_network_selected(wpa_s, ssid); |
5175 | 0 | } |
5176 | | |
5177 | | |
5178 | | /** |
5179 | | * wpas_remove_cred - Remove the specified credential and all the network |
5180 | | * entries created based on the removed credential |
5181 | | * @wpa_s: wpa_supplicant structure for a network interface |
5182 | | * @cred: The credential to remove |
5183 | | * Returns: 0 on success, -1 on failure |
5184 | | */ |
5185 | | int wpas_remove_cred(struct wpa_supplicant *wpa_s, struct wpa_cred *cred) |
5186 | 0 | { |
5187 | 0 | struct wpa_ssid *ssid, *next; |
5188 | 0 | int id; |
5189 | |
|
5190 | 0 | if (!cred) { |
5191 | 0 | wpa_printf(MSG_DEBUG, "Could not find cred"); |
5192 | 0 | return -1; |
5193 | 0 | } |
5194 | | |
5195 | 0 | id = cred->id; |
5196 | 0 | if (wpa_config_remove_cred(wpa_s->conf, id) < 0) { |
5197 | 0 | wpa_printf(MSG_DEBUG, "Could not find cred %d", id); |
5198 | 0 | return -1; |
5199 | 0 | } |
5200 | | |
5201 | 0 | wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id); |
5202 | | |
5203 | | /* Remove any network entry created based on the removed credential */ |
5204 | 0 | ssid = wpa_s->conf->ssid; |
5205 | 0 | while (ssid) { |
5206 | 0 | next = ssid->next; |
5207 | |
|
5208 | 0 | if (ssid->parent_cred == cred) { |
5209 | 0 | wpa_printf(MSG_DEBUG, |
5210 | 0 | "Remove network id %d since it used the removed credential", |
5211 | 0 | ssid->id); |
5212 | 0 | if (wpa_supplicant_remove_network(wpa_s, ssid->id) == |
5213 | 0 | -1) { |
5214 | 0 | wpa_printf(MSG_DEBUG, |
5215 | 0 | "Could not find network id=%d", |
5216 | 0 | ssid->id); |
5217 | 0 | } |
5218 | 0 | } |
5219 | |
|
5220 | 0 | ssid = next; |
5221 | 0 | } |
5222 | |
|
5223 | 0 | return 0; |
5224 | 0 | } |
5225 | | |
5226 | | |
5227 | | /** |
5228 | | * wpas_remove_cred - Remove all the Interworking credentials |
5229 | | * @wpa_s: wpa_supplicant structure for a network interface |
5230 | | * Returns: 0 on success, -1 on failure |
5231 | | */ |
5232 | | int wpas_remove_all_creds(struct wpa_supplicant *wpa_s) |
5233 | 0 | { |
5234 | 0 | int res, ret = 0; |
5235 | 0 | struct wpa_cred *cred, *prev; |
5236 | |
|
5237 | 0 | cred = wpa_s->conf->cred; |
5238 | 0 | while (cred) { |
5239 | 0 | prev = cred; |
5240 | 0 | cred = cred->next; |
5241 | 0 | res = wpas_remove_cred(wpa_s, prev); |
5242 | 0 | if (res < 0) { |
5243 | 0 | wpa_printf(MSG_DEBUG, |
5244 | 0 | "Removal of all credentials failed - failed to remove credential id=%d", |
5245 | 0 | prev->id); |
5246 | 0 | ret = -1; |
5247 | 0 | } |
5248 | 0 | } |
5249 | |
|
5250 | 0 | return ret; |
5251 | 0 | } |
5252 | | |
5253 | | |
5254 | | /** |
5255 | | * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path |
5256 | | * @wpa_s: wpa_supplicant structure for a network interface |
5257 | | * @pkcs11_engine_path: PKCS #11 engine path or NULL |
5258 | | * @pkcs11_module_path: PKCS #11 module path or NULL |
5259 | | * Returns: 0 on success; -1 on failure |
5260 | | * |
5261 | | * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid |
5262 | | * path. If resetting the EAPOL state machine with the new PKCS #11 engine and |
5263 | | * module path fails the paths will be reset to the default value (NULL). |
5264 | | */ |
5265 | | int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s, |
5266 | | const char *pkcs11_engine_path, |
5267 | | const char *pkcs11_module_path) |
5268 | 0 | { |
5269 | 0 | char *pkcs11_engine_path_copy = NULL; |
5270 | 0 | char *pkcs11_module_path_copy = NULL; |
5271 | |
|
5272 | 0 | if (pkcs11_engine_path != NULL) { |
5273 | 0 | pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path); |
5274 | 0 | if (pkcs11_engine_path_copy == NULL) |
5275 | 0 | return -1; |
5276 | 0 | } |
5277 | 0 | if (pkcs11_module_path != NULL) { |
5278 | 0 | pkcs11_module_path_copy = os_strdup(pkcs11_module_path); |
5279 | 0 | if (pkcs11_module_path_copy == NULL) { |
5280 | 0 | os_free(pkcs11_engine_path_copy); |
5281 | 0 | return -1; |
5282 | 0 | } |
5283 | 0 | } |
5284 | | |
5285 | 0 | #ifndef CONFIG_PKCS11_ENGINE_PATH |
5286 | 0 | os_free(wpa_s->conf->pkcs11_engine_path); |
5287 | 0 | wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy; |
5288 | 0 | #endif /* CONFIG_PKCS11_ENGINE_PATH */ |
5289 | 0 | #ifndef CONFIG_PKCS11_MODULE_PATH |
5290 | 0 | os_free(wpa_s->conf->pkcs11_module_path); |
5291 | 0 | wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy; |
5292 | 0 | #endif /* CONFIG_PKCS11_MODULE_PATH */ |
5293 | |
|
5294 | 0 | wpa_sm_set_eapol(wpa_s->wpa, NULL); |
5295 | 0 | eapol_sm_deinit(wpa_s->eapol); |
5296 | 0 | wpa_s->eapol = NULL; |
5297 | 0 | if (wpa_supplicant_init_eapol(wpa_s)) { |
5298 | | /* Error -> Reset paths to the default value (NULL) once. */ |
5299 | 0 | if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL) |
5300 | 0 | wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL, |
5301 | 0 | NULL); |
5302 | |
|
5303 | 0 | return -1; |
5304 | 0 | } |
5305 | 0 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); |
5306 | |
|
5307 | 0 | return 0; |
5308 | 0 | } |
5309 | | |
5310 | | |
5311 | | /** |
5312 | | * wpa_supplicant_set_ap_scan - Set AP scan mode for interface |
5313 | | * @wpa_s: wpa_supplicant structure for a network interface |
5314 | | * @ap_scan: AP scan mode |
5315 | | * Returns: 0 if succeed or -1 if ap_scan has an invalid value |
5316 | | * |
5317 | | */ |
5318 | | int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan) |
5319 | 0 | { |
5320 | |
|
5321 | 0 | int old_ap_scan; |
5322 | |
|
5323 | 0 | if (ap_scan < 0 || ap_scan > 2) |
5324 | 0 | return -1; |
5325 | | |
5326 | 0 | if (ap_scan == 2 && os_strcmp(wpa_s->driver->name, "nl80211") == 0) { |
5327 | 0 | wpa_printf(MSG_INFO, |
5328 | 0 | "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures"); |
5329 | 0 | } |
5330 | |
|
5331 | | #ifdef ANDROID |
5332 | | if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan && |
5333 | | wpa_s->wpa_state >= WPA_ASSOCIATING && |
5334 | | wpa_s->wpa_state < WPA_COMPLETED) { |
5335 | | wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while " |
5336 | | "associating", wpa_s->conf->ap_scan, ap_scan); |
5337 | | return 0; |
5338 | | } |
5339 | | #endif /* ANDROID */ |
5340 | |
|
5341 | 0 | old_ap_scan = wpa_s->conf->ap_scan; |
5342 | 0 | wpa_s->conf->ap_scan = ap_scan; |
5343 | |
|
5344 | 0 | if (old_ap_scan != wpa_s->conf->ap_scan) |
5345 | 0 | wpas_notify_ap_scan_changed(wpa_s); |
5346 | |
|
5347 | 0 | return 0; |
5348 | 0 | } |
5349 | | |
5350 | | |
5351 | | /** |
5352 | | * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age |
5353 | | * @wpa_s: wpa_supplicant structure for a network interface |
5354 | | * @expire_age: Expiration age in seconds |
5355 | | * Returns: 0 if succeed or -1 if expire_age has an invalid value |
5356 | | * |
5357 | | */ |
5358 | | int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s, |
5359 | | unsigned int bss_expire_age) |
5360 | 0 | { |
5361 | 0 | if (bss_expire_age < 10) { |
5362 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u", |
5363 | 0 | bss_expire_age); |
5364 | 0 | return -1; |
5365 | 0 | } |
5366 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec", |
5367 | 0 | bss_expire_age); |
5368 | 0 | wpa_s->conf->bss_expiration_age = bss_expire_age; |
5369 | |
|
5370 | 0 | return 0; |
5371 | 0 | } |
5372 | | |
5373 | | |
5374 | | /** |
5375 | | * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count |
5376 | | * @wpa_s: wpa_supplicant structure for a network interface |
5377 | | * @expire_count: number of scans after which an unseen BSS is reclaimed |
5378 | | * Returns: 0 if succeed or -1 if expire_count has an invalid value |
5379 | | * |
5380 | | */ |
5381 | | int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s, |
5382 | | unsigned int bss_expire_count) |
5383 | 0 | { |
5384 | 0 | if (bss_expire_count < 1) { |
5385 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u", |
5386 | 0 | bss_expire_count); |
5387 | 0 | return -1; |
5388 | 0 | } |
5389 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u", |
5390 | 0 | bss_expire_count); |
5391 | 0 | wpa_s->conf->bss_expiration_scan_count = bss_expire_count; |
5392 | |
|
5393 | 0 | return 0; |
5394 | 0 | } |
5395 | | |
5396 | | |
5397 | | /** |
5398 | | * wpa_supplicant_set_scan_interval - Set scan interval |
5399 | | * @wpa_s: wpa_supplicant structure for a network interface |
5400 | | * @scan_interval: scan interval in seconds |
5401 | | * Returns: 0 if succeed or -1 if scan_interval has an invalid value |
5402 | | * |
5403 | | */ |
5404 | | int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s, |
5405 | | int scan_interval) |
5406 | 0 | { |
5407 | 0 | if (scan_interval < 0) { |
5408 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d", |
5409 | 0 | scan_interval); |
5410 | 0 | return -1; |
5411 | 0 | } |
5412 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec", |
5413 | 0 | scan_interval); |
5414 | 0 | wpa_supplicant_update_scan_int(wpa_s, scan_interval); |
5415 | |
|
5416 | 0 | return 0; |
5417 | 0 | } |
5418 | | |
5419 | | |
5420 | | /** |
5421 | | * wpa_supplicant_set_debug_params - Set global debug params |
5422 | | * @global: wpa_global structure |
5423 | | * @debug_level: debug level |
5424 | | * @debug_timestamp: determines if show timestamp in debug data |
5425 | | * @debug_show_keys: determines if show keys in debug data |
5426 | | * Returns: 0 if succeed or -1 if debug_level has wrong value |
5427 | | */ |
5428 | | int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level, |
5429 | | int debug_timestamp, int debug_show_keys) |
5430 | 0 | { |
5431 | |
|
5432 | 0 | int old_level, old_timestamp, old_show_keys; |
5433 | | |
5434 | | /* check for allowed debuglevels */ |
5435 | 0 | if (debug_level != MSG_EXCESSIVE && |
5436 | 0 | debug_level != MSG_MSGDUMP && |
5437 | 0 | debug_level != MSG_DEBUG && |
5438 | 0 | debug_level != MSG_INFO && |
5439 | 0 | debug_level != MSG_WARNING && |
5440 | 0 | debug_level != MSG_ERROR) |
5441 | 0 | return -1; |
5442 | | |
5443 | 0 | old_level = wpa_debug_level; |
5444 | 0 | old_timestamp = wpa_debug_timestamp; |
5445 | 0 | old_show_keys = wpa_debug_show_keys; |
5446 | |
|
5447 | 0 | wpa_debug_level = debug_level; |
5448 | 0 | wpa_debug_timestamp = debug_timestamp ? 1 : 0; |
5449 | 0 | wpa_debug_show_keys = debug_show_keys ? 1 : 0; |
5450 | |
|
5451 | 0 | if (wpa_debug_level != old_level) |
5452 | 0 | wpas_notify_debug_level_changed(global); |
5453 | 0 | if (wpa_debug_timestamp != old_timestamp) |
5454 | 0 | wpas_notify_debug_timestamp_changed(global); |
5455 | 0 | if (wpa_debug_show_keys != old_show_keys) |
5456 | 0 | wpas_notify_debug_show_keys_changed(global); |
5457 | |
|
5458 | 0 | return 0; |
5459 | 0 | } |
5460 | | |
5461 | | |
5462 | | #ifdef CONFIG_OWE |
5463 | | static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid, |
5464 | | const u8 *entry_ssid, size_t entry_ssid_len) |
5465 | | { |
5466 | | const u8 *owe, *pos, *end; |
5467 | | u8 ssid_len; |
5468 | | struct wpa_bss *bss; |
5469 | | |
5470 | | /* Check network profile SSID aganst the SSID in the |
5471 | | * OWE Transition Mode element. */ |
5472 | | |
5473 | | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
5474 | | if (!bss) |
5475 | | return 0; |
5476 | | |
5477 | | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
5478 | | if (!owe) |
5479 | | return 0; |
5480 | | |
5481 | | pos = owe + 6; |
5482 | | end = owe + 2 + owe[1]; |
5483 | | |
5484 | | if (end - pos < ETH_ALEN + 1) |
5485 | | return 0; |
5486 | | pos += ETH_ALEN; |
5487 | | ssid_len = *pos++; |
5488 | | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) |
5489 | | return 0; |
5490 | | |
5491 | | return entry_ssid_len == ssid_len && |
5492 | | os_memcmp(pos, entry_ssid, ssid_len) == 0; |
5493 | | } |
5494 | | #endif /* CONFIG_OWE */ |
5495 | | |
5496 | | |
5497 | | /** |
5498 | | * wpa_supplicant_get_ssid - Get a pointer to the current network structure |
5499 | | * @wpa_s: Pointer to wpa_supplicant data |
5500 | | * Returns: A pointer to the current network structure or %NULL on failure |
5501 | | */ |
5502 | | struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s) |
5503 | 0 | { |
5504 | 0 | struct wpa_ssid *entry; |
5505 | 0 | u8 ssid[SSID_MAX_LEN]; |
5506 | 0 | int res; |
5507 | 0 | size_t ssid_len; |
5508 | 0 | u8 bssid[ETH_ALEN]; |
5509 | 0 | int wired; |
5510 | |
|
5511 | 0 | res = wpa_drv_get_ssid(wpa_s, ssid); |
5512 | 0 | if (res < 0) { |
5513 | 0 | wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from " |
5514 | 0 | "driver"); |
5515 | 0 | return NULL; |
5516 | 0 | } |
5517 | 0 | ssid_len = res; |
5518 | |
|
5519 | 0 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
5520 | 0 | wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from " |
5521 | 0 | "driver"); |
5522 | 0 | return NULL; |
5523 | 0 | } |
5524 | | |
5525 | 0 | wired = wpa_s->conf->ap_scan == 0 && |
5526 | 0 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED); |
5527 | |
|
5528 | 0 | entry = wpa_s->conf->ssid; |
5529 | 0 | while (entry) { |
5530 | 0 | if (!wpas_network_disabled(wpa_s, entry) && |
5531 | 0 | ((ssid_len == entry->ssid_len && |
5532 | 0 | (!entry->ssid || |
5533 | 0 | os_memcmp(ssid, entry->ssid, ssid_len) == 0)) || |
5534 | 0 | wired) && |
5535 | 0 | (!entry->bssid_set || |
5536 | 0 | ether_addr_equal(bssid, entry->bssid))) |
5537 | 0 | return entry; |
5538 | | #ifdef CONFIG_WPS |
5539 | | if (!wpas_network_disabled(wpa_s, entry) && |
5540 | | (entry->key_mgmt & WPA_KEY_MGMT_WPS) && |
5541 | | (entry->ssid == NULL || entry->ssid_len == 0) && |
5542 | | (!entry->bssid_set || |
5543 | | ether_addr_equal(bssid, entry->bssid))) |
5544 | | return entry; |
5545 | | #endif /* CONFIG_WPS */ |
5546 | | |
5547 | | #ifdef CONFIG_OWE |
5548 | | if (!wpas_network_disabled(wpa_s, entry) && |
5549 | | (entry->ssid && |
5550 | | owe_trans_ssid_match(wpa_s, bssid, entry->ssid, |
5551 | | entry->ssid_len)) && |
5552 | | (!entry->bssid_set || |
5553 | | ether_addr_equal(bssid, entry->bssid))) |
5554 | | return entry; |
5555 | | #endif /* CONFIG_OWE */ |
5556 | | |
5557 | 0 | if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set && |
5558 | 0 | entry->ssid_len == 0 && |
5559 | 0 | ether_addr_equal(bssid, entry->bssid)) |
5560 | 0 | return entry; |
5561 | | |
5562 | 0 | entry = entry->next; |
5563 | 0 | } |
5564 | | |
5565 | 0 | return NULL; |
5566 | 0 | } |
5567 | | |
5568 | | |
5569 | | static int select_driver(struct wpa_supplicant *wpa_s, int i) |
5570 | 0 | { |
5571 | 0 | struct wpa_global *global = wpa_s->global; |
5572 | |
|
5573 | 0 | if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) { |
5574 | 0 | global->drv_priv[i] = wpa_drivers[i]->global_init(global); |
5575 | 0 | if (global->drv_priv[i] == NULL) { |
5576 | 0 | wpa_printf(MSG_ERROR, "Failed to initialize driver " |
5577 | 0 | "'%s'", wpa_drivers[i]->name); |
5578 | 0 | return -1; |
5579 | 0 | } |
5580 | 0 | } |
5581 | | |
5582 | 0 | wpa_s->driver = wpa_drivers[i]; |
5583 | 0 | wpa_s->global_drv_priv = global->drv_priv[i]; |
5584 | |
|
5585 | 0 | return 0; |
5586 | 0 | } |
5587 | | |
5588 | | |
5589 | | static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, |
5590 | | const char *name) |
5591 | 0 | { |
5592 | 0 | int i; |
5593 | 0 | size_t len; |
5594 | 0 | const char *pos, *driver = name; |
5595 | |
|
5596 | 0 | if (wpa_s == NULL) |
5597 | 0 | return -1; |
5598 | | |
5599 | 0 | if (wpa_drivers[0] == NULL) { |
5600 | 0 | wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into " |
5601 | 0 | "wpa_supplicant"); |
5602 | 0 | return -1; |
5603 | 0 | } |
5604 | | |
5605 | 0 | if (name == NULL) { |
5606 | | /* Default to first successful driver in the list */ |
5607 | 0 | for (i = 0; wpa_drivers[i]; i++) { |
5608 | 0 | if (select_driver(wpa_s, i) == 0) |
5609 | 0 | return 0; |
5610 | 0 | } |
5611 | | /* Drivers have each reported failure, so no wpa_msg() here. */ |
5612 | 0 | return -1; |
5613 | 0 | } |
5614 | | |
5615 | 0 | do { |
5616 | 0 | pos = os_strchr(driver, ','); |
5617 | 0 | if (pos) |
5618 | 0 | len = pos - driver; |
5619 | 0 | else |
5620 | 0 | len = os_strlen(driver); |
5621 | |
|
5622 | 0 | for (i = 0; wpa_drivers[i]; i++) { |
5623 | 0 | if (os_strlen(wpa_drivers[i]->name) == len && |
5624 | 0 | os_strncmp(driver, wpa_drivers[i]->name, len) == |
5625 | 0 | 0) { |
5626 | | /* First driver that succeeds wins */ |
5627 | 0 | if (select_driver(wpa_s, i) == 0) |
5628 | 0 | return 0; |
5629 | 0 | } |
5630 | 0 | } |
5631 | | |
5632 | 0 | driver = pos + 1; |
5633 | 0 | } while (pos); |
5634 | | |
5635 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name); |
5636 | 0 | return -1; |
5637 | 0 | } |
5638 | | |
5639 | | |
5640 | | /** |
5641 | | * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant |
5642 | | * @ctx: Context pointer (wpa_s); this is the ctx variable registered |
5643 | | * with struct wpa_driver_ops::init() |
5644 | | * @src_addr: Source address of the EAPOL frame |
5645 | | * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header) |
5646 | | * @len: Length of the EAPOL data |
5647 | | * @encrypted: Whether the frame was encrypted |
5648 | | * |
5649 | | * This function is called for each received EAPOL frame. Most driver |
5650 | | * interfaces rely on more generic OS mechanism for receiving frames through |
5651 | | * l2_packet, but if such a mechanism is not available, the driver wrapper may |
5652 | | * take care of received EAPOL frames and deliver them to the core supplicant |
5653 | | * code by calling this function. |
5654 | | */ |
5655 | | void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr, |
5656 | | const u8 *buf, size_t len, |
5657 | | enum frame_encryption encrypted) |
5658 | 0 | { |
5659 | 0 | struct wpa_supplicant *wpa_s = ctx; |
5660 | 0 | const u8 *connected_addr = wpa_s->valid_links ? |
5661 | 0 | wpa_s->ap_mld_addr : wpa_s->bssid; |
5662 | |
|
5663 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " (encrypted=%d)", |
5664 | 0 | MAC2STR(src_addr), encrypted); |
5665 | 0 | wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len); |
5666 | |
|
5667 | 0 | if (wpa_s->own_disconnect_req) { |
5668 | 0 | wpa_printf(MSG_DEBUG, |
5669 | 0 | "Drop received EAPOL frame as we are disconnecting"); |
5670 | 0 | return; |
5671 | 0 | } |
5672 | | |
5673 | | #ifdef CONFIG_TESTING_OPTIONS |
5674 | | wpa_msg_ctrl(wpa_s, MSG_INFO, "EAPOL-RX " MACSTR " %zu", |
5675 | | MAC2STR(src_addr), len); |
5676 | | if (wpa_s->ignore_auth_resp) { |
5677 | | wpa_printf(MSG_INFO, "RX EAPOL - ignore_auth_resp active!"); |
5678 | | return; |
5679 | | } |
5680 | | #endif /* CONFIG_TESTING_OPTIONS */ |
5681 | | |
5682 | 0 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
5683 | 0 | (wpa_s->last_eapol_matches_bssid && |
5684 | | #ifdef CONFIG_AP |
5685 | | !wpa_s->ap_iface && |
5686 | | #endif /* CONFIG_AP */ |
5687 | 0 | !ether_addr_equal(src_addr, connected_addr))) { |
5688 | | /* |
5689 | | * There is possible race condition between receiving the |
5690 | | * association event and the EAPOL frame since they are coming |
5691 | | * through different paths from the driver. In order to avoid |
5692 | | * issues in trying to process the EAPOL frame before receiving |
5693 | | * association information, lets queue it for processing until |
5694 | | * the association event is received. This may also be needed in |
5695 | | * driver-based roaming case, so also use src_addr != BSSID as a |
5696 | | * trigger if we have previously confirmed that the |
5697 | | * Authenticator uses BSSID as the src_addr (which is not the |
5698 | | * case with wired IEEE 802.1X). |
5699 | | */ |
5700 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
5701 | 0 | "Not associated - Delay processing of received EAPOL frame (state=%s connected_addr=" |
5702 | 0 | MACSTR ")", |
5703 | 0 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
5704 | 0 | MAC2STR(connected_addr)); |
5705 | 0 | wpabuf_free(wpa_s->pending_eapol_rx); |
5706 | 0 | wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len); |
5707 | 0 | if (wpa_s->pending_eapol_rx) { |
5708 | 0 | os_get_reltime(&wpa_s->pending_eapol_rx_time); |
5709 | 0 | os_memcpy(wpa_s->pending_eapol_rx_src, src_addr, |
5710 | 0 | ETH_ALEN); |
5711 | 0 | wpa_s->pending_eapol_encrypted = encrypted; |
5712 | 0 | } |
5713 | 0 | return; |
5714 | 0 | } |
5715 | | |
5716 | 0 | wpa_s->last_eapol_matches_bssid = |
5717 | 0 | ether_addr_equal(src_addr, connected_addr); |
5718 | |
|
5719 | | #ifdef CONFIG_AP |
5720 | | if (wpa_s->ap_iface) { |
5721 | | wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len, |
5722 | | encrypted); |
5723 | | return; |
5724 | | } |
5725 | | #endif /* CONFIG_AP */ |
5726 | |
|
5727 | 0 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) { |
5728 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since " |
5729 | 0 | "no key management is configured"); |
5730 | 0 | return; |
5731 | 0 | } |
5732 | | |
5733 | 0 | if (wpa_s->eapol_received == 0 && |
5734 | 0 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) || |
5735 | 0 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
5736 | 0 | wpa_s->wpa_state != WPA_COMPLETED) && |
5737 | 0 | (wpa_s->current_ssid == NULL || |
5738 | 0 | wpa_s->current_ssid->mode != WPAS_MODE_IBSS)) { |
5739 | | /* Timeout for completing IEEE 802.1X and WPA authentication */ |
5740 | 0 | int timeout = 10; |
5741 | |
|
5742 | 0 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
5743 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA || |
5744 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { |
5745 | | /* Use longer timeout for IEEE 802.1X/EAP */ |
5746 | 0 | timeout = 70; |
5747 | 0 | } |
5748 | |
|
5749 | | #ifdef CONFIG_WPS |
5750 | | if (wpa_s->current_ssid && wpa_s->current_bss && |
5751 | | (wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
5752 | | eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) { |
5753 | | /* |
5754 | | * Use shorter timeout if going through WPS AP iteration |
5755 | | * for PIN config method with an AP that does not |
5756 | | * advertise Selected Registrar. |
5757 | | */ |
5758 | | struct wpabuf *wps_ie; |
5759 | | |
5760 | | wps_ie = wpa_bss_get_vendor_ie_multi( |
5761 | | wpa_s->current_bss, WPS_IE_VENDOR_TYPE); |
5762 | | if (wps_ie && |
5763 | | !wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) |
5764 | | timeout = 10; |
5765 | | wpabuf_free(wps_ie); |
5766 | | } |
5767 | | #endif /* CONFIG_WPS */ |
5768 | |
|
5769 | 0 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
5770 | 0 | } |
5771 | 0 | wpa_s->eapol_received++; |
5772 | |
|
5773 | 0 | if (wpa_s->countermeasures) { |
5774 | 0 | wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped " |
5775 | 0 | "EAPOL packet"); |
5776 | 0 | return; |
5777 | 0 | } |
5778 | | |
5779 | | #ifdef CONFIG_IBSS_RSN |
5780 | | if (wpa_s->current_ssid && |
5781 | | wpa_s->current_ssid->mode == WPAS_MODE_IBSS) { |
5782 | | ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len, |
5783 | | encrypted); |
5784 | | return; |
5785 | | } |
5786 | | #endif /* CONFIG_IBSS_RSN */ |
5787 | | |
5788 | | /* Source address of the incoming EAPOL frame could be compared to the |
5789 | | * current BSSID. However, it is possible that a centralized |
5790 | | * Authenticator could be using another MAC address than the BSSID of |
5791 | | * an AP, so just allow any address to be used for now. The replies are |
5792 | | * still sent to the current BSSID (if available), though. */ |
5793 | | |
5794 | 0 | os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN); |
5795 | 0 | if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) && |
5796 | 0 | wpa_s->key_mgmt != WPA_KEY_MGMT_OWE && |
5797 | 0 | wpa_s->key_mgmt != WPA_KEY_MGMT_DPP && |
5798 | 0 | eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len, |
5799 | 0 | encrypted) > 0) |
5800 | 0 | return; |
5801 | 0 | wpa_drv_poll(wpa_s); |
5802 | 0 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) |
5803 | 0 | wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len, encrypted); |
5804 | 0 | else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
5805 | | /* |
5806 | | * Set portValid = true here since we are going to skip 4-way |
5807 | | * handshake processing which would normally set portValid. We |
5808 | | * need this to allow the EAPOL state machines to be completed |
5809 | | * without going through EAPOL-Key handshake. |
5810 | | */ |
5811 | 0 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
5812 | 0 | } |
5813 | 0 | } |
5814 | | |
5815 | | |
5816 | | static void wpa_supplicant_rx_eapol_cb(void *ctx, const u8 *src_addr, |
5817 | | const u8 *buf, size_t len) |
5818 | 0 | { |
5819 | 0 | wpa_supplicant_rx_eapol(ctx, src_addr, buf, len, |
5820 | 0 | FRAME_ENCRYPTION_UNKNOWN); |
5821 | 0 | } |
5822 | | |
5823 | | |
5824 | | static int wpas_eapol_needs_l2_packet(struct wpa_supplicant *wpa_s) |
5825 | 0 | { |
5826 | 0 | return !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_CONTROL_PORT) || |
5827 | 0 | !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX); |
5828 | 0 | } |
5829 | | |
5830 | | |
5831 | | int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s) |
5832 | 0 | { |
5833 | 0 | u8 prev_mac_addr[ETH_ALEN]; |
5834 | |
|
5835 | 0 | os_memcpy(prev_mac_addr, wpa_s->own_addr, ETH_ALEN); |
5836 | |
|
5837 | 0 | if ((!wpa_s->p2p_mgmt || |
5838 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) && |
5839 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) { |
5840 | 0 | l2_packet_deinit(wpa_s->l2); |
5841 | 0 | wpa_s->l2 = l2_packet_init(wpa_s->ifname, |
5842 | 0 | wpa_drv_get_mac_addr(wpa_s), |
5843 | 0 | ETH_P_EAPOL, |
5844 | 0 | wpas_eapol_needs_l2_packet(wpa_s) ? |
5845 | 0 | wpa_supplicant_rx_eapol_cb : NULL, |
5846 | 0 | wpa_s, 0); |
5847 | 0 | if (wpa_s->l2 == NULL) |
5848 | 0 | return -1; |
5849 | | |
5850 | 0 | if (l2_packet_set_packet_filter(wpa_s->l2, |
5851 | 0 | L2_PACKET_FILTER_PKTTYPE)) |
5852 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
5853 | 0 | "Failed to attach pkt_type filter"); |
5854 | |
|
5855 | 0 | if (l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) { |
5856 | 0 | wpa_msg(wpa_s, MSG_ERROR, |
5857 | 0 | "Failed to get own L2 address"); |
5858 | 0 | return -1; |
5859 | 0 | } |
5860 | 0 | } else { |
5861 | 0 | const u8 *addr = wpa_drv_get_mac_addr(wpa_s); |
5862 | 0 | if (addr) |
5863 | 0 | os_memcpy(wpa_s->own_addr, addr, ETH_ALEN); |
5864 | 0 | } |
5865 | | |
5866 | 0 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
5867 | 0 | wpas_wps_update_mac_addr(wpa_s); |
5868 | |
|
5869 | | #ifdef CONFIG_FST |
5870 | | if (wpa_s->fst) |
5871 | | fst_update_mac_addr(wpa_s->fst, wpa_s->own_addr); |
5872 | | #endif /* CONFIG_FST */ |
5873 | |
|
5874 | 0 | if (!ether_addr_equal(prev_mac_addr, wpa_s->own_addr)) |
5875 | 0 | wpas_notify_mac_address_changed(wpa_s); |
5876 | |
|
5877 | 0 | return 0; |
5878 | 0 | } |
5879 | | |
5880 | | |
5881 | | static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr, |
5882 | | const u8 *buf, size_t len) |
5883 | 0 | { |
5884 | 0 | struct wpa_supplicant *wpa_s = ctx; |
5885 | 0 | const struct l2_ethhdr *eth; |
5886 | |
|
5887 | 0 | if (len < sizeof(*eth)) |
5888 | 0 | return; |
5889 | 0 | eth = (const struct l2_ethhdr *) buf; |
5890 | |
|
5891 | 0 | if (!ether_addr_equal(eth->h_dest, wpa_s->own_addr) && |
5892 | 0 | !(eth->h_dest[0] & 0x01)) { |
5893 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR |
5894 | 0 | " (bridge - not for this interface - ignore)", |
5895 | 0 | MAC2STR(src_addr), MAC2STR(eth->h_dest)); |
5896 | 0 | return; |
5897 | 0 | } |
5898 | | |
5899 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR |
5900 | 0 | " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest)); |
5901 | 0 | wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth), |
5902 | 0 | len - sizeof(*eth), FRAME_ENCRYPTION_UNKNOWN); |
5903 | 0 | } |
5904 | | |
5905 | | |
5906 | | int wpa_supplicant_update_bridge_ifname(struct wpa_supplicant *wpa_s, |
5907 | | const char *bridge_ifname) |
5908 | 0 | { |
5909 | 0 | if (wpa_s->wpa_state > WPA_SCANNING) |
5910 | 0 | return -EBUSY; |
5911 | | |
5912 | 0 | if (bridge_ifname && |
5913 | 0 | os_strlen(bridge_ifname) >= sizeof(wpa_s->bridge_ifname)) |
5914 | 0 | return -EINVAL; |
5915 | | |
5916 | 0 | if (!bridge_ifname) |
5917 | 0 | bridge_ifname = ""; |
5918 | |
|
5919 | 0 | if (os_strcmp(wpa_s->bridge_ifname, bridge_ifname) == 0) |
5920 | 0 | return 0; |
5921 | | |
5922 | 0 | if (wpa_s->l2_br) { |
5923 | 0 | l2_packet_deinit(wpa_s->l2_br); |
5924 | 0 | wpa_s->l2_br = NULL; |
5925 | 0 | } |
5926 | |
|
5927 | 0 | os_strlcpy(wpa_s->bridge_ifname, bridge_ifname, |
5928 | 0 | sizeof(wpa_s->bridge_ifname)); |
5929 | |
|
5930 | 0 | if (wpa_s->bridge_ifname[0]) { |
5931 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
5932 | 0 | "Receiving packets from bridge interface '%s'", |
5933 | 0 | wpa_s->bridge_ifname); |
5934 | 0 | wpa_s->l2_br = l2_packet_init_bridge( |
5935 | 0 | wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr, |
5936 | 0 | ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1); |
5937 | 0 | if (!wpa_s->l2_br) { |
5938 | 0 | wpa_msg(wpa_s, MSG_ERROR, |
5939 | 0 | "Failed to open l2_packet connection for the bridge interface '%s'", |
5940 | 0 | wpa_s->bridge_ifname); |
5941 | 0 | goto fail; |
5942 | 0 | } |
5943 | 0 | } |
5944 | | |
5945 | | #ifdef CONFIG_TDLS |
5946 | | if (!wpa_s->p2p_mgmt && wpa_tdls_init(wpa_s->wpa)) |
5947 | | goto fail; |
5948 | | #endif /* CONFIG_TDLS */ |
5949 | | |
5950 | 0 | return 0; |
5951 | 0 | fail: |
5952 | 0 | wpa_s->bridge_ifname[0] = 0; |
5953 | 0 | if (wpa_s->l2_br) { |
5954 | 0 | l2_packet_deinit(wpa_s->l2_br); |
5955 | 0 | wpa_s->l2_br = NULL; |
5956 | 0 | } |
5957 | | #ifdef CONFIG_TDLS |
5958 | | if (!wpa_s->p2p_mgmt) |
5959 | | wpa_tdls_init(wpa_s->wpa); |
5960 | | #endif /* CONFIG_TDLS */ |
5961 | 0 | return -EIO; |
5962 | 0 | } |
5963 | | |
5964 | | |
5965 | | /** |
5966 | | * wpa_supplicant_driver_init - Initialize driver interface parameters |
5967 | | * @wpa_s: Pointer to wpa_supplicant data |
5968 | | * Returns: 0 on success, -1 on failure |
5969 | | * |
5970 | | * This function is called to initialize driver interface parameters. |
5971 | | * wpa_drv_init() must have been called before this function to initialize the |
5972 | | * driver interface. |
5973 | | */ |
5974 | | int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s) |
5975 | 0 | { |
5976 | 0 | static int interface_count = 0; |
5977 | |
|
5978 | 0 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) |
5979 | 0 | return -1; |
5980 | | |
5981 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR, |
5982 | 0 | MAC2STR(wpa_s->own_addr)); |
5983 | 0 | os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN); |
5984 | 0 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
5985 | |
|
5986 | 0 | if (wpa_s->bridge_ifname[0] && wpas_eapol_needs_l2_packet(wpa_s)) { |
5987 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge " |
5988 | 0 | "interface '%s'", wpa_s->bridge_ifname); |
5989 | 0 | wpa_s->l2_br = l2_packet_init_bridge( |
5990 | 0 | wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr, |
5991 | 0 | ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1); |
5992 | 0 | if (wpa_s->l2_br == NULL) { |
5993 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet " |
5994 | 0 | "connection for the bridge interface '%s'", |
5995 | 0 | wpa_s->bridge_ifname); |
5996 | 0 | return -1; |
5997 | 0 | } |
5998 | 0 | } |
5999 | | |
6000 | 0 | if (wpa_s->conf->ap_scan == 2 && |
6001 | 0 | os_strcmp(wpa_s->driver->name, "nl80211") == 0) { |
6002 | 0 | wpa_printf(MSG_INFO, |
6003 | 0 | "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures"); |
6004 | 0 | } |
6005 | |
|
6006 | 0 | wpa_clear_keys(wpa_s, NULL); |
6007 | | |
6008 | | /* Make sure that TKIP countermeasures are not left enabled (could |
6009 | | * happen if wpa_supplicant is killed during countermeasures. */ |
6010 | 0 | wpa_drv_set_countermeasures(wpa_s, 0); |
6011 | |
|
6012 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver"); |
6013 | 0 | wpa_drv_flush_pmkid(wpa_s); |
6014 | |
|
6015 | 0 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
6016 | 0 | wpa_s->prev_scan_wildcard = 0; |
6017 | |
|
6018 | 0 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
6019 | 0 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
6020 | 0 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
6021 | 0 | interface_count = 0; |
6022 | 0 | } |
6023 | 0 | #ifndef ANDROID |
6024 | 0 | if (!wpa_s->p2p_mgmt && |
6025 | 0 | wpa_supplicant_delayed_sched_scan(wpa_s, |
6026 | 0 | interface_count % 3, |
6027 | 0 | 100000)) |
6028 | 0 | wpa_supplicant_req_scan(wpa_s, interface_count % 3, |
6029 | 0 | 100000); |
6030 | 0 | #endif /* ANDROID */ |
6031 | 0 | interface_count++; |
6032 | 0 | } else |
6033 | 0 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
6034 | |
|
6035 | 0 | return 0; |
6036 | 0 | } |
6037 | | |
6038 | | |
6039 | | static int wpa_supplicant_daemon(const char *pid_file) |
6040 | 0 | { |
6041 | 0 | wpa_printf(MSG_DEBUG, "Daemonize.."); |
6042 | 0 | return os_daemonize(pid_file); |
6043 | 0 | } |
6044 | | |
6045 | | |
6046 | | static struct wpa_supplicant * |
6047 | | wpa_supplicant_alloc(struct wpa_supplicant *parent) |
6048 | 0 | { |
6049 | 0 | struct wpa_supplicant *wpa_s; |
6050 | |
|
6051 | 0 | wpa_s = os_zalloc(sizeof(*wpa_s)); |
6052 | 0 | if (wpa_s == NULL) |
6053 | 0 | return NULL; |
6054 | 0 | wpa_s->scan_req = INITIAL_SCAN_REQ; |
6055 | 0 | wpa_s->scan_interval = 5; |
6056 | 0 | wpa_s->new_connection = 1; |
6057 | 0 | wpa_s->parent = parent ? parent : wpa_s; |
6058 | 0 | wpa_s->p2pdev = wpa_s->parent; |
6059 | 0 | wpa_s->sched_scanning = 0; |
6060 | 0 | wpa_s->setband_mask = WPA_SETBAND_AUTO; |
6061 | |
|
6062 | 0 | dl_list_init(&wpa_s->bss_tmp_disallowed); |
6063 | 0 | dl_list_init(&wpa_s->fils_hlp_req); |
6064 | | #ifdef CONFIG_TESTING_OPTIONS |
6065 | | dl_list_init(&wpa_s->drv_signal_override); |
6066 | | wpa_s->test_assoc_comeback_type = -1; |
6067 | | #endif /* CONFIG_TESTING_OPTIONS */ |
6068 | 0 | #ifndef CONFIG_NO_ROBUST_AV |
6069 | 0 | dl_list_init(&wpa_s->active_scs_ids); |
6070 | 0 | #endif /* CONFIG_NO_ROBUST_AV */ |
6071 | 0 | wpa_s->ml_probe_mld_id = -1; |
6072 | |
|
6073 | 0 | return wpa_s; |
6074 | 0 | } |
6075 | | |
6076 | | |
6077 | | #ifdef CONFIG_HT_OVERRIDES |
6078 | | |
6079 | | static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s, |
6080 | | struct ieee80211_ht_capabilities *htcaps, |
6081 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6082 | | const char *ht_mcs) |
6083 | | { |
6084 | | /* parse ht_mcs into hex array */ |
6085 | | int i; |
6086 | | const char *tmp = ht_mcs; |
6087 | | char *end = NULL; |
6088 | | |
6089 | | /* If ht_mcs is null, do not set anything */ |
6090 | | if (!ht_mcs) |
6091 | | return 0; |
6092 | | |
6093 | | /* This is what we are setting in the kernel */ |
6094 | | os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN); |
6095 | | |
6096 | | wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs); |
6097 | | |
6098 | | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
6099 | | long v; |
6100 | | |
6101 | | errno = 0; |
6102 | | v = strtol(tmp, &end, 16); |
6103 | | |
6104 | | if (errno == 0) { |
6105 | | wpa_msg(wpa_s, MSG_DEBUG, |
6106 | | "htcap value[%i]: %ld end: %p tmp: %p", |
6107 | | i, v, end, tmp); |
6108 | | if (end == tmp) |
6109 | | break; |
6110 | | |
6111 | | htcaps->supported_mcs_set[i] = v; |
6112 | | tmp = end; |
6113 | | } else { |
6114 | | wpa_msg(wpa_s, MSG_ERROR, |
6115 | | "Failed to parse ht-mcs: %s, error: %s\n", |
6116 | | ht_mcs, strerror(errno)); |
6117 | | return -1; |
6118 | | } |
6119 | | } |
6120 | | |
6121 | | /* |
6122 | | * If we were able to parse any values, then set mask for the MCS set. |
6123 | | */ |
6124 | | if (i) { |
6125 | | os_memset(&htcaps_mask->supported_mcs_set, 0xff, |
6126 | | IEEE80211_HT_MCS_MASK_LEN - 1); |
6127 | | /* skip the 3 reserved bits */ |
6128 | | htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] = |
6129 | | 0x1f; |
6130 | | } |
6131 | | |
6132 | | return 0; |
6133 | | } |
6134 | | |
6135 | | |
6136 | | static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s, |
6137 | | struct ieee80211_ht_capabilities *htcaps, |
6138 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6139 | | int disabled) |
6140 | | { |
6141 | | le16 msk; |
6142 | | |
6143 | | if (disabled == -1) |
6144 | | return 0; |
6145 | | |
6146 | | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled); |
6147 | | |
6148 | | msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE); |
6149 | | htcaps_mask->ht_capabilities_info |= msk; |
6150 | | if (disabled) |
6151 | | htcaps->ht_capabilities_info &= msk; |
6152 | | else |
6153 | | htcaps->ht_capabilities_info |= msk; |
6154 | | |
6155 | | return 0; |
6156 | | } |
6157 | | |
6158 | | |
6159 | | static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s, |
6160 | | struct ieee80211_ht_capabilities *htcaps, |
6161 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6162 | | int factor) |
6163 | | { |
6164 | | if (factor == -1) |
6165 | | return 0; |
6166 | | |
6167 | | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor); |
6168 | | |
6169 | | if (factor < 0 || factor > 3) { |
6170 | | wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. " |
6171 | | "Must be 0-3 or -1", factor); |
6172 | | return -EINVAL; |
6173 | | } |
6174 | | |
6175 | | htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */ |
6176 | | htcaps->a_mpdu_params &= ~0x3; |
6177 | | htcaps->a_mpdu_params |= factor & 0x3; |
6178 | | |
6179 | | return 0; |
6180 | | } |
6181 | | |
6182 | | |
6183 | | static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s, |
6184 | | struct ieee80211_ht_capabilities *htcaps, |
6185 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6186 | | int density) |
6187 | | { |
6188 | | if (density == -1) |
6189 | | return 0; |
6190 | | |
6191 | | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density); |
6192 | | |
6193 | | if (density < 0 || density > 7) { |
6194 | | wpa_msg(wpa_s, MSG_ERROR, |
6195 | | "ampdu_density: %d out of range. Must be 0-7 or -1.", |
6196 | | density); |
6197 | | return -EINVAL; |
6198 | | } |
6199 | | |
6200 | | htcaps_mask->a_mpdu_params |= 0x1C; |
6201 | | htcaps->a_mpdu_params &= ~(0x1C); |
6202 | | htcaps->a_mpdu_params |= (density << 2) & 0x1C; |
6203 | | |
6204 | | return 0; |
6205 | | } |
6206 | | |
6207 | | |
6208 | | static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s, |
6209 | | struct ieee80211_ht_capabilities *htcaps, |
6210 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6211 | | int disabled) |
6212 | | { |
6213 | | if (disabled) |
6214 | | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled); |
6215 | | |
6216 | | set_disable_ht40(htcaps, disabled); |
6217 | | set_disable_ht40(htcaps_mask, 0); |
6218 | | |
6219 | | return 0; |
6220 | | } |
6221 | | |
6222 | | |
6223 | | static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s, |
6224 | | struct ieee80211_ht_capabilities *htcaps, |
6225 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6226 | | int disabled) |
6227 | | { |
6228 | | /* Masking these out disables SGI */ |
6229 | | le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ | |
6230 | | HT_CAP_INFO_SHORT_GI40MHZ); |
6231 | | |
6232 | | if (disabled) |
6233 | | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled); |
6234 | | |
6235 | | if (disabled) |
6236 | | htcaps->ht_capabilities_info &= ~msk; |
6237 | | else |
6238 | | htcaps->ht_capabilities_info |= msk; |
6239 | | |
6240 | | htcaps_mask->ht_capabilities_info |= msk; |
6241 | | |
6242 | | return 0; |
6243 | | } |
6244 | | |
6245 | | |
6246 | | static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s, |
6247 | | struct ieee80211_ht_capabilities *htcaps, |
6248 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6249 | | int disabled) |
6250 | | { |
6251 | | /* Masking these out disables LDPC */ |
6252 | | le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP); |
6253 | | |
6254 | | if (disabled) |
6255 | | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled); |
6256 | | |
6257 | | if (disabled) |
6258 | | htcaps->ht_capabilities_info &= ~msk; |
6259 | | else |
6260 | | htcaps->ht_capabilities_info |= msk; |
6261 | | |
6262 | | htcaps_mask->ht_capabilities_info |= msk; |
6263 | | |
6264 | | return 0; |
6265 | | } |
6266 | | |
6267 | | |
6268 | | static int wpa_set_tx_stbc(struct wpa_supplicant *wpa_s, |
6269 | | struct ieee80211_ht_capabilities *htcaps, |
6270 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6271 | | int tx_stbc) |
6272 | | { |
6273 | | le16 msk = host_to_le16(HT_CAP_INFO_TX_STBC); |
6274 | | |
6275 | | if (tx_stbc == -1) |
6276 | | return 0; |
6277 | | |
6278 | | wpa_msg(wpa_s, MSG_DEBUG, "set_tx_stbc: %d", tx_stbc); |
6279 | | |
6280 | | if (tx_stbc < 0 || tx_stbc > 1) { |
6281 | | wpa_msg(wpa_s, MSG_ERROR, |
6282 | | "tx_stbc: %d out of range. Must be 0-1 or -1", tx_stbc); |
6283 | | return -EINVAL; |
6284 | | } |
6285 | | |
6286 | | htcaps_mask->ht_capabilities_info |= msk; |
6287 | | htcaps->ht_capabilities_info &= ~msk; |
6288 | | htcaps->ht_capabilities_info |= (tx_stbc << 7) & msk; |
6289 | | |
6290 | | return 0; |
6291 | | } |
6292 | | |
6293 | | |
6294 | | static int wpa_set_rx_stbc(struct wpa_supplicant *wpa_s, |
6295 | | struct ieee80211_ht_capabilities *htcaps, |
6296 | | struct ieee80211_ht_capabilities *htcaps_mask, |
6297 | | int rx_stbc) |
6298 | | { |
6299 | | le16 msk = host_to_le16(HT_CAP_INFO_RX_STBC_MASK); |
6300 | | |
6301 | | if (rx_stbc == -1) |
6302 | | return 0; |
6303 | | |
6304 | | wpa_msg(wpa_s, MSG_DEBUG, "set_rx_stbc: %d", rx_stbc); |
6305 | | |
6306 | | if (rx_stbc < 0 || rx_stbc > 3) { |
6307 | | wpa_msg(wpa_s, MSG_ERROR, |
6308 | | "rx_stbc: %d out of range. Must be 0-3 or -1", rx_stbc); |
6309 | | return -EINVAL; |
6310 | | } |
6311 | | |
6312 | | htcaps_mask->ht_capabilities_info |= msk; |
6313 | | htcaps->ht_capabilities_info &= ~msk; |
6314 | | htcaps->ht_capabilities_info |= (rx_stbc << 8) & msk; |
6315 | | |
6316 | | return 0; |
6317 | | } |
6318 | | |
6319 | | |
6320 | | void wpa_supplicant_apply_ht_overrides( |
6321 | | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
6322 | | struct wpa_driver_associate_params *params) |
6323 | | { |
6324 | | struct ieee80211_ht_capabilities *htcaps; |
6325 | | struct ieee80211_ht_capabilities *htcaps_mask; |
6326 | | |
6327 | | if (!ssid) |
6328 | | return; |
6329 | | |
6330 | | params->disable_ht = ssid->disable_ht; |
6331 | | if (!params->htcaps || !params->htcaps_mask) |
6332 | | return; |
6333 | | |
6334 | | htcaps = (struct ieee80211_ht_capabilities *) params->htcaps; |
6335 | | htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask; |
6336 | | wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs); |
6337 | | wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask, |
6338 | | ssid->disable_max_amsdu); |
6339 | | wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor); |
6340 | | wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density); |
6341 | | wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40); |
6342 | | wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi); |
6343 | | wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc); |
6344 | | wpa_set_rx_stbc(wpa_s, htcaps, htcaps_mask, ssid->rx_stbc); |
6345 | | wpa_set_tx_stbc(wpa_s, htcaps, htcaps_mask, ssid->tx_stbc); |
6346 | | |
6347 | | if (ssid->ht40_intolerant) { |
6348 | | le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT); |
6349 | | htcaps->ht_capabilities_info |= bit; |
6350 | | htcaps_mask->ht_capabilities_info |= bit; |
6351 | | } |
6352 | | } |
6353 | | |
6354 | | #endif /* CONFIG_HT_OVERRIDES */ |
6355 | | |
6356 | | |
6357 | | #ifdef CONFIG_VHT_OVERRIDES |
6358 | | void wpa_supplicant_apply_vht_overrides( |
6359 | | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
6360 | | struct wpa_driver_associate_params *params) |
6361 | | { |
6362 | | struct ieee80211_vht_capabilities *vhtcaps; |
6363 | | struct ieee80211_vht_capabilities *vhtcaps_mask; |
6364 | | |
6365 | | if (!ssid) |
6366 | | return; |
6367 | | |
6368 | | params->disable_vht = ssid->disable_vht; |
6369 | | |
6370 | | vhtcaps = (void *) params->vhtcaps; |
6371 | | vhtcaps_mask = (void *) params->vhtcaps_mask; |
6372 | | |
6373 | | if (!vhtcaps || !vhtcaps_mask) |
6374 | | return; |
6375 | | |
6376 | | vhtcaps->vht_capabilities_info = host_to_le32(ssid->vht_capa); |
6377 | | vhtcaps_mask->vht_capabilities_info = host_to_le32(ssid->vht_capa_mask); |
6378 | | |
6379 | | #ifdef CONFIG_HT_OVERRIDES |
6380 | | if (ssid->disable_sgi) { |
6381 | | vhtcaps_mask->vht_capabilities_info |= (VHT_CAP_SHORT_GI_80 | |
6382 | | VHT_CAP_SHORT_GI_160); |
6383 | | vhtcaps->vht_capabilities_info &= ~(VHT_CAP_SHORT_GI_80 | |
6384 | | VHT_CAP_SHORT_GI_160); |
6385 | | wpa_msg(wpa_s, MSG_DEBUG, |
6386 | | "disable-sgi override specified, vht-caps: 0x%x", |
6387 | | vhtcaps->vht_capabilities_info); |
6388 | | } |
6389 | | |
6390 | | /* if max ampdu is <= 3, we have to make the HT cap the same */ |
6391 | | if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) { |
6392 | | int max_ampdu; |
6393 | | |
6394 | | max_ampdu = (ssid->vht_capa & |
6395 | | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >> |
6396 | | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT; |
6397 | | |
6398 | | max_ampdu = max_ampdu < 3 ? max_ampdu : 3; |
6399 | | wpa_set_ampdu_factor(wpa_s, |
6400 | | (void *) params->htcaps, |
6401 | | (void *) params->htcaps_mask, |
6402 | | max_ampdu); |
6403 | | } |
6404 | | #endif /* CONFIG_HT_OVERRIDES */ |
6405 | | |
6406 | | #define OVERRIDE_MCS(i) \ |
6407 | | if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \ |
6408 | | vhtcaps_mask->vht_supported_mcs_set.tx_map |= \ |
6409 | | host_to_le16(3 << 2 * (i - 1)); \ |
6410 | | vhtcaps->vht_supported_mcs_set.tx_map |= \ |
6411 | | host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \ |
6412 | | 2 * (i - 1)); \ |
6413 | | } \ |
6414 | | if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \ |
6415 | | vhtcaps_mask->vht_supported_mcs_set.rx_map |= \ |
6416 | | host_to_le16(3 << 2 * (i - 1)); \ |
6417 | | vhtcaps->vht_supported_mcs_set.rx_map |= \ |
6418 | | host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \ |
6419 | | 2 * (i - 1)); \ |
6420 | | } |
6421 | | |
6422 | | OVERRIDE_MCS(1); |
6423 | | OVERRIDE_MCS(2); |
6424 | | OVERRIDE_MCS(3); |
6425 | | OVERRIDE_MCS(4); |
6426 | | OVERRIDE_MCS(5); |
6427 | | OVERRIDE_MCS(6); |
6428 | | OVERRIDE_MCS(7); |
6429 | | OVERRIDE_MCS(8); |
6430 | | } |
6431 | | #endif /* CONFIG_VHT_OVERRIDES */ |
6432 | | |
6433 | | |
6434 | | #ifdef CONFIG_HE_OVERRIDES |
6435 | | void wpa_supplicant_apply_he_overrides( |
6436 | | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
6437 | | struct wpa_driver_associate_params *params) |
6438 | | { |
6439 | | if (!ssid) |
6440 | | return; |
6441 | | |
6442 | | params->disable_he = ssid->disable_he; |
6443 | | } |
6444 | | #endif /* CONFIG_HE_OVERRIDES */ |
6445 | | |
6446 | | |
6447 | | void wpa_supplicant_apply_eht_overrides( |
6448 | | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
6449 | | struct wpa_driver_associate_params *params) |
6450 | 0 | { |
6451 | 0 | if (!ssid) |
6452 | 0 | return; |
6453 | | |
6454 | 0 | params->disable_eht = ssid->disable_eht; |
6455 | 0 | } |
6456 | | |
6457 | | |
6458 | | static int pcsc_reader_init(struct wpa_supplicant *wpa_s) |
6459 | 0 | { |
6460 | | #ifdef PCSC_FUNCS |
6461 | | size_t len; |
6462 | | |
6463 | | if (!wpa_s->conf->pcsc_reader) |
6464 | | return 0; |
6465 | | |
6466 | | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
6467 | | if (!wpa_s->scard) |
6468 | | return 1; |
6469 | | |
6470 | | if (wpa_s->conf->pcsc_pin && |
6471 | | scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) { |
6472 | | scard_deinit(wpa_s->scard); |
6473 | | wpa_s->scard = NULL; |
6474 | | wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed"); |
6475 | | return -1; |
6476 | | } |
6477 | | |
6478 | | len = sizeof(wpa_s->imsi) - 1; |
6479 | | if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) { |
6480 | | scard_deinit(wpa_s->scard); |
6481 | | wpa_s->scard = NULL; |
6482 | | wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI"); |
6483 | | return -1; |
6484 | | } |
6485 | | wpa_s->imsi[len] = '\0'; |
6486 | | |
6487 | | wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard); |
6488 | | |
6489 | | wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)", |
6490 | | wpa_s->imsi, wpa_s->mnc_len); |
6491 | | |
6492 | | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); |
6493 | | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); |
6494 | | #endif /* PCSC_FUNCS */ |
6495 | |
|
6496 | 0 | return 0; |
6497 | 0 | } |
6498 | | |
6499 | | |
6500 | | int wpas_init_ext_pw(struct wpa_supplicant *wpa_s) |
6501 | 0 | { |
6502 | 0 | char *val, *pos; |
6503 | |
|
6504 | 0 | ext_password_deinit(wpa_s->ext_pw); |
6505 | 0 | wpa_s->ext_pw = NULL; |
6506 | 0 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL); |
6507 | |
|
6508 | 0 | if (!wpa_s->conf->ext_password_backend) |
6509 | 0 | return 0; |
6510 | | |
6511 | 0 | val = os_strdup(wpa_s->conf->ext_password_backend); |
6512 | 0 | if (val == NULL) |
6513 | 0 | return -1; |
6514 | 0 | pos = os_strchr(val, ':'); |
6515 | 0 | if (pos) |
6516 | 0 | *pos++ = '\0'; |
6517 | |
|
6518 | 0 | wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val); |
6519 | |
|
6520 | 0 | wpa_s->ext_pw = ext_password_init(val, pos); |
6521 | 0 | os_free(val); |
6522 | 0 | if (wpa_s->ext_pw == NULL) { |
6523 | 0 | wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend"); |
6524 | 0 | return -1; |
6525 | 0 | } |
6526 | 0 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw); |
6527 | |
|
6528 | 0 | return 0; |
6529 | 0 | } |
6530 | | |
6531 | | |
6532 | | #ifdef CONFIG_FST |
6533 | | |
6534 | | static const u8 * wpas_fst_get_bssid_cb(void *ctx) |
6535 | | { |
6536 | | struct wpa_supplicant *wpa_s = ctx; |
6537 | | |
6538 | | return (is_zero_ether_addr(wpa_s->bssid) || |
6539 | | wpa_s->wpa_state != WPA_COMPLETED) ? NULL : wpa_s->bssid; |
6540 | | } |
6541 | | |
6542 | | |
6543 | | static void wpas_fst_get_channel_info_cb(void *ctx, |
6544 | | enum hostapd_hw_mode *hw_mode, |
6545 | | u8 *channel) |
6546 | | { |
6547 | | struct wpa_supplicant *wpa_s = ctx; |
6548 | | |
6549 | | if (wpa_s->current_bss) { |
6550 | | *hw_mode = ieee80211_freq_to_chan(wpa_s->current_bss->freq, |
6551 | | channel); |
6552 | | } else if (wpa_s->hw.num_modes) { |
6553 | | *hw_mode = wpa_s->hw.modes[0].mode; |
6554 | | } else { |
6555 | | WPA_ASSERT(0); |
6556 | | *hw_mode = 0; |
6557 | | } |
6558 | | } |
6559 | | |
6560 | | |
6561 | | static int wpas_fst_get_hw_modes(void *ctx, struct hostapd_hw_modes **modes) |
6562 | | { |
6563 | | struct wpa_supplicant *wpa_s = ctx; |
6564 | | |
6565 | | *modes = wpa_s->hw.modes; |
6566 | | return wpa_s->hw.num_modes; |
6567 | | } |
6568 | | |
6569 | | |
6570 | | static void wpas_fst_set_ies_cb(void *ctx, const struct wpabuf *fst_ies) |
6571 | | { |
6572 | | struct wpa_supplicant *wpa_s = ctx; |
6573 | | |
6574 | | wpa_hexdump_buf(MSG_DEBUG, "FST: Set IEs", fst_ies); |
6575 | | wpa_s->fst_ies = fst_ies; |
6576 | | } |
6577 | | |
6578 | | |
6579 | | static int wpas_fst_send_action_cb(void *ctx, const u8 *da, struct wpabuf *data) |
6580 | | { |
6581 | | struct wpa_supplicant *wpa_s = ctx; |
6582 | | |
6583 | | if (!ether_addr_equal(wpa_s->bssid, da)) { |
6584 | | wpa_printf(MSG_INFO, "FST:%s:bssid=" MACSTR " != da=" MACSTR, |
6585 | | __func__, MAC2STR(wpa_s->bssid), MAC2STR(da)); |
6586 | | return -1; |
6587 | | } |
6588 | | return wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
6589 | | wpa_s->own_addr, wpa_s->bssid, |
6590 | | wpabuf_head(data), wpabuf_len(data), |
6591 | | 0); |
6592 | | } |
6593 | | |
6594 | | |
6595 | | static const struct wpabuf * wpas_fst_get_mb_ie_cb(void *ctx, const u8 *addr) |
6596 | | { |
6597 | | struct wpa_supplicant *wpa_s = ctx; |
6598 | | |
6599 | | WPA_ASSERT(ether_addr_equal(wpa_s->bssid, addr)); |
6600 | | return wpa_s->received_mb_ies; |
6601 | | } |
6602 | | |
6603 | | |
6604 | | static void wpas_fst_update_mb_ie_cb(void *ctx, const u8 *addr, |
6605 | | const u8 *buf, size_t size) |
6606 | | { |
6607 | | struct wpa_supplicant *wpa_s = ctx; |
6608 | | struct mb_ies_info info; |
6609 | | |
6610 | | WPA_ASSERT(ether_addr_equal(wpa_s->bssid, addr)); |
6611 | | |
6612 | | if (!mb_ies_info_by_ies(&info, buf, size)) { |
6613 | | wpabuf_free(wpa_s->received_mb_ies); |
6614 | | wpa_s->received_mb_ies = mb_ies_by_info(&info); |
6615 | | } |
6616 | | } |
6617 | | |
6618 | | |
6619 | | static const u8 * wpas_fst_get_peer_first(void *ctx, |
6620 | | struct fst_get_peer_ctx **get_ctx, |
6621 | | bool mb_only) |
6622 | | { |
6623 | | struct wpa_supplicant *wpa_s = ctx; |
6624 | | |
6625 | | *get_ctx = NULL; |
6626 | | if (!is_zero_ether_addr(wpa_s->bssid)) |
6627 | | return (wpa_s->received_mb_ies || !mb_only) ? |
6628 | | wpa_s->bssid : NULL; |
6629 | | return NULL; |
6630 | | } |
6631 | | |
6632 | | |
6633 | | static const u8 * wpas_fst_get_peer_next(void *ctx, |
6634 | | struct fst_get_peer_ctx **get_ctx, |
6635 | | bool mb_only) |
6636 | | { |
6637 | | return NULL; |
6638 | | } |
6639 | | |
6640 | | void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant *wpa_s, |
6641 | | struct fst_wpa_obj *iface_obj) |
6642 | | { |
6643 | | os_memset(iface_obj, 0, sizeof(*iface_obj)); |
6644 | | iface_obj->ctx = wpa_s; |
6645 | | iface_obj->get_bssid = wpas_fst_get_bssid_cb; |
6646 | | iface_obj->get_channel_info = wpas_fst_get_channel_info_cb; |
6647 | | iface_obj->get_hw_modes = wpas_fst_get_hw_modes; |
6648 | | iface_obj->set_ies = wpas_fst_set_ies_cb; |
6649 | | iface_obj->send_action = wpas_fst_send_action_cb; |
6650 | | iface_obj->get_mb_ie = wpas_fst_get_mb_ie_cb; |
6651 | | iface_obj->update_mb_ie = wpas_fst_update_mb_ie_cb; |
6652 | | iface_obj->get_peer_first = wpas_fst_get_peer_first; |
6653 | | iface_obj->get_peer_next = wpas_fst_get_peer_next; |
6654 | | } |
6655 | | #endif /* CONFIG_FST */ |
6656 | | |
6657 | | static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s, |
6658 | | const struct wpa_driver_capa *capa) |
6659 | 0 | { |
6660 | 0 | struct wowlan_triggers *triggers; |
6661 | 0 | int ret = 0; |
6662 | |
|
6663 | 0 | if (!wpa_s->conf->wowlan_triggers) |
6664 | 0 | return 0; |
6665 | | |
6666 | 0 | triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa); |
6667 | 0 | if (triggers) { |
6668 | 0 | ret = wpa_drv_wowlan(wpa_s, triggers); |
6669 | 0 | os_free(triggers); |
6670 | 0 | } |
6671 | 0 | return ret; |
6672 | 0 | } |
6673 | | |
6674 | | |
6675 | | enum wpa_radio_work_band wpas_freq_to_band(int freq) |
6676 | 0 | { |
6677 | 0 | if (freq < 3000) |
6678 | 0 | return BAND_2_4_GHZ; |
6679 | 0 | if (freq > 50000) |
6680 | 0 | return BAND_60_GHZ; |
6681 | 0 | return BAND_5_GHZ; |
6682 | 0 | } |
6683 | | |
6684 | | |
6685 | | unsigned int wpas_get_bands(struct wpa_supplicant *wpa_s, const int *freqs) |
6686 | 0 | { |
6687 | 0 | int i; |
6688 | 0 | unsigned int band = 0; |
6689 | |
|
6690 | 0 | if (freqs) { |
6691 | | /* freqs are specified for the radio work */ |
6692 | 0 | for (i = 0; freqs[i]; i++) |
6693 | 0 | band |= wpas_freq_to_band(freqs[i]); |
6694 | 0 | } else { |
6695 | | /* |
6696 | | * freqs are not specified, implies all |
6697 | | * the supported freqs by HW |
6698 | | */ |
6699 | 0 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
6700 | 0 | if (wpa_s->hw.modes[i].num_channels != 0) { |
6701 | 0 | if (wpa_s->hw.modes[i].mode == |
6702 | 0 | HOSTAPD_MODE_IEEE80211B || |
6703 | 0 | wpa_s->hw.modes[i].mode == |
6704 | 0 | HOSTAPD_MODE_IEEE80211G) |
6705 | 0 | band |= BAND_2_4_GHZ; |
6706 | 0 | else if (wpa_s->hw.modes[i].mode == |
6707 | 0 | HOSTAPD_MODE_IEEE80211A) |
6708 | 0 | band |= BAND_5_GHZ; |
6709 | 0 | else if (wpa_s->hw.modes[i].mode == |
6710 | 0 | HOSTAPD_MODE_IEEE80211AD) |
6711 | 0 | band |= BAND_60_GHZ; |
6712 | 0 | else if (wpa_s->hw.modes[i].mode == |
6713 | 0 | HOSTAPD_MODE_IEEE80211ANY) |
6714 | 0 | band = BAND_2_4_GHZ | BAND_5_GHZ | |
6715 | 0 | BAND_60_GHZ; |
6716 | 0 | } |
6717 | 0 | } |
6718 | 0 | } |
6719 | |
|
6720 | 0 | return band; |
6721 | 0 | } |
6722 | | |
6723 | | |
6724 | | static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s, |
6725 | | const char *rn) |
6726 | 0 | { |
6727 | 0 | struct wpa_supplicant *iface = wpa_s->global->ifaces; |
6728 | 0 | struct wpa_radio *radio; |
6729 | |
|
6730 | 0 | while (rn && iface) { |
6731 | 0 | radio = iface->radio; |
6732 | 0 | if (radio && os_strcmp(rn, radio->name) == 0) { |
6733 | 0 | wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s", |
6734 | 0 | wpa_s->ifname, rn); |
6735 | 0 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); |
6736 | 0 | return radio; |
6737 | 0 | } |
6738 | | |
6739 | 0 | iface = iface->next; |
6740 | 0 | } |
6741 | | |
6742 | 0 | wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s", |
6743 | 0 | wpa_s->ifname, rn ? rn : "N/A"); |
6744 | 0 | radio = os_zalloc(sizeof(*radio)); |
6745 | 0 | if (radio == NULL) |
6746 | 0 | return NULL; |
6747 | | |
6748 | 0 | if (rn) |
6749 | 0 | os_strlcpy(radio->name, rn, sizeof(radio->name)); |
6750 | 0 | dl_list_init(&radio->ifaces); |
6751 | 0 | dl_list_init(&radio->work); |
6752 | 0 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); |
6753 | |
|
6754 | 0 | return radio; |
6755 | 0 | } |
6756 | | |
6757 | | |
6758 | | static void radio_work_free(struct wpa_radio_work *work) |
6759 | 0 | { |
6760 | 0 | if (work->wpa_s->scan_work == work) { |
6761 | | /* This should not really happen. */ |
6762 | 0 | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work", |
6763 | 0 | work->type, work, work->started); |
6764 | 0 | work->wpa_s->scan_work = NULL; |
6765 | 0 | } |
6766 | |
|
6767 | | #ifdef CONFIG_P2P |
6768 | | if (work->wpa_s->p2p_scan_work == work) { |
6769 | | /* This should not really happen. */ |
6770 | | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work", |
6771 | | work->type, work, work->started); |
6772 | | work->wpa_s->p2p_scan_work = NULL; |
6773 | | } |
6774 | | #endif /* CONFIG_P2P */ |
6775 | |
|
6776 | 0 | if (work->started) { |
6777 | 0 | work->wpa_s->radio->num_active_works--; |
6778 | 0 | wpa_dbg(work->wpa_s, MSG_DEBUG, |
6779 | 0 | "radio_work_free('%s'@%p): num_active_works --> %u", |
6780 | 0 | work->type, work, |
6781 | 0 | work->wpa_s->radio->num_active_works); |
6782 | 0 | } |
6783 | |
|
6784 | 0 | dl_list_del(&work->list); |
6785 | 0 | os_free(work); |
6786 | 0 | } |
6787 | | |
6788 | | |
6789 | | static int radio_work_is_connect(struct wpa_radio_work *work) |
6790 | 0 | { |
6791 | 0 | return os_strcmp(work->type, "sme-connect") == 0 || |
6792 | 0 | os_strcmp(work->type, "connect") == 0; |
6793 | 0 | } |
6794 | | |
6795 | | |
6796 | | static int radio_work_is_scan(struct wpa_radio_work *work) |
6797 | 0 | { |
6798 | 0 | return os_strcmp(work->type, "scan") == 0 || |
6799 | 0 | os_strcmp(work->type, "p2p-scan") == 0; |
6800 | 0 | } |
6801 | | |
6802 | | |
6803 | | static struct wpa_radio_work * radio_work_get_next_work(struct wpa_radio *radio) |
6804 | 0 | { |
6805 | 0 | struct wpa_radio_work *active_work = NULL; |
6806 | 0 | struct wpa_radio_work *tmp; |
6807 | | |
6808 | | /* Get the active work to know the type and band. */ |
6809 | 0 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) { |
6810 | 0 | if (tmp->started) { |
6811 | 0 | active_work = tmp; |
6812 | 0 | break; |
6813 | 0 | } |
6814 | 0 | } |
6815 | |
|
6816 | 0 | if (!active_work) { |
6817 | | /* No active work, start one */ |
6818 | 0 | radio->num_active_works = 0; |
6819 | 0 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, |
6820 | 0 | list) { |
6821 | 0 | if (os_strcmp(tmp->type, "scan") == 0 && |
6822 | 0 | external_scan_running(radio) && |
6823 | 0 | (((struct wpa_driver_scan_params *) |
6824 | 0 | tmp->ctx)->only_new_results || |
6825 | 0 | tmp->wpa_s->clear_driver_scan_cache)) |
6826 | 0 | continue; |
6827 | 0 | return tmp; |
6828 | 0 | } |
6829 | 0 | return NULL; |
6830 | 0 | } |
6831 | | |
6832 | 0 | if (radio_work_is_connect(active_work)) { |
6833 | | /* |
6834 | | * If the active work is either connect or sme-connect, |
6835 | | * do not parallelize them with other radio works. |
6836 | | */ |
6837 | 0 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, |
6838 | 0 | "Do not parallelize radio work with %s", |
6839 | 0 | active_work->type); |
6840 | 0 | return NULL; |
6841 | 0 | } |
6842 | | |
6843 | 0 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) { |
6844 | 0 | if (tmp->started) |
6845 | 0 | continue; |
6846 | | |
6847 | | /* |
6848 | | * If connect or sme-connect are enqueued, parallelize only |
6849 | | * those operations ahead of them in the queue. |
6850 | | */ |
6851 | 0 | if (radio_work_is_connect(tmp)) |
6852 | 0 | break; |
6853 | | |
6854 | | /* Serialize parallel scan and p2p_scan operations on the same |
6855 | | * interface since the driver_nl80211 mechanism for tracking |
6856 | | * scan cookies does not yet have support for this. */ |
6857 | 0 | if (active_work->wpa_s == tmp->wpa_s && |
6858 | 0 | radio_work_is_scan(active_work) && |
6859 | 0 | radio_work_is_scan(tmp)) { |
6860 | 0 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, |
6861 | 0 | "Do not start work '%s' when another work '%s' is already scheduled", |
6862 | 0 | tmp->type, active_work->type); |
6863 | 0 | continue; |
6864 | 0 | } |
6865 | | /* |
6866 | | * Check that the radio works are distinct and |
6867 | | * on different bands. |
6868 | | */ |
6869 | 0 | if (os_strcmp(active_work->type, tmp->type) != 0 && |
6870 | 0 | (active_work->bands != tmp->bands)) { |
6871 | | /* |
6872 | | * If a scan has to be scheduled through nl80211 scan |
6873 | | * interface and if an external scan is already running, |
6874 | | * do not schedule the scan since it is likely to get |
6875 | | * rejected by kernel. |
6876 | | */ |
6877 | 0 | if (os_strcmp(tmp->type, "scan") == 0 && |
6878 | 0 | external_scan_running(radio) && |
6879 | 0 | (((struct wpa_driver_scan_params *) |
6880 | 0 | tmp->ctx)->only_new_results || |
6881 | 0 | tmp->wpa_s->clear_driver_scan_cache)) |
6882 | 0 | continue; |
6883 | | |
6884 | 0 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, |
6885 | 0 | "active_work:%s new_work:%s", |
6886 | 0 | active_work->type, tmp->type); |
6887 | 0 | return tmp; |
6888 | 0 | } |
6889 | 0 | } |
6890 | | |
6891 | | /* Did not find a radio work to schedule in parallel. */ |
6892 | 0 | return NULL; |
6893 | 0 | } |
6894 | | |
6895 | | |
6896 | | static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx) |
6897 | 0 | { |
6898 | 0 | struct wpa_radio *radio = eloop_ctx; |
6899 | 0 | struct wpa_radio_work *work; |
6900 | 0 | struct os_reltime now, diff; |
6901 | 0 | struct wpa_supplicant *wpa_s; |
6902 | |
|
6903 | 0 | work = dl_list_first(&radio->work, struct wpa_radio_work, list); |
6904 | 0 | if (work == NULL) { |
6905 | 0 | radio->num_active_works = 0; |
6906 | 0 | return; |
6907 | 0 | } |
6908 | | |
6909 | 0 | wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant, |
6910 | 0 | radio_list); |
6911 | |
|
6912 | 0 | if (!(wpa_s && |
6913 | 0 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)) { |
6914 | 0 | if (work->started) |
6915 | 0 | return; /* already started and still in progress */ |
6916 | | |
6917 | 0 | if (wpa_s && external_scan_running(wpa_s->radio)) { |
6918 | 0 | wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes"); |
6919 | 0 | return; |
6920 | 0 | } |
6921 | 0 | } else { |
6922 | 0 | work = NULL; |
6923 | 0 | if (radio->num_active_works < MAX_ACTIVE_WORKS) { |
6924 | | /* get the work to schedule next */ |
6925 | 0 | work = radio_work_get_next_work(radio); |
6926 | 0 | } |
6927 | 0 | if (!work) |
6928 | 0 | return; |
6929 | 0 | } |
6930 | | |
6931 | 0 | wpa_s = work->wpa_s; |
6932 | 0 | os_get_reltime(&now); |
6933 | 0 | os_reltime_sub(&now, &work->time, &diff); |
6934 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
6935 | 0 | "Starting radio work '%s'@%p after %ld.%06ld second wait", |
6936 | 0 | work->type, work, diff.sec, diff.usec); |
6937 | 0 | work->started = 1; |
6938 | 0 | work->time = now; |
6939 | 0 | radio->num_active_works++; |
6940 | |
|
6941 | 0 | work->cb(work, 0); |
6942 | |
|
6943 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) && |
6944 | 0 | radio->num_active_works < MAX_ACTIVE_WORKS) |
6945 | 0 | radio_work_check_next(wpa_s); |
6946 | 0 | } |
6947 | | |
6948 | | |
6949 | | /* |
6950 | | * This function removes both started and pending radio works running on |
6951 | | * the provided interface's radio. |
6952 | | * Prior to the removal of the radio work, its callback (cb) is called with |
6953 | | * deinit set to be 1. Each work's callback is responsible for clearing its |
6954 | | * internal data and restoring to a correct state. |
6955 | | * @wpa_s: wpa_supplicant data |
6956 | | * @type: type of works to be removed |
6957 | | * @remove_all: 1 to remove all the works on this radio, 0 to remove only |
6958 | | * this interface's works. |
6959 | | */ |
6960 | | void radio_remove_works(struct wpa_supplicant *wpa_s, |
6961 | | const char *type, int remove_all) |
6962 | 0 | { |
6963 | 0 | struct wpa_radio_work *work, *tmp; |
6964 | 0 | struct wpa_radio *radio = wpa_s->radio; |
6965 | |
|
6966 | 0 | dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work, |
6967 | 0 | list) { |
6968 | 0 | if (type && os_strcmp(type, work->type) != 0) |
6969 | 0 | continue; |
6970 | | |
6971 | | /* skip other ifaces' works */ |
6972 | 0 | if (!remove_all && work->wpa_s != wpa_s) |
6973 | 0 | continue; |
6974 | | |
6975 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s", |
6976 | 0 | work->type, work, work->started ? " (started)" : ""); |
6977 | 0 | work->cb(work, 1); |
6978 | 0 | radio_work_free(work); |
6979 | 0 | } |
6980 | | |
6981 | | /* in case we removed the started work */ |
6982 | 0 | radio_work_check_next(wpa_s); |
6983 | 0 | } |
6984 | | |
6985 | | |
6986 | | void radio_remove_pending_work(struct wpa_supplicant *wpa_s, void *ctx) |
6987 | 0 | { |
6988 | 0 | struct wpa_radio_work *work; |
6989 | 0 | struct wpa_radio *radio = wpa_s->radio; |
6990 | |
|
6991 | 0 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { |
6992 | 0 | if (work->ctx != ctx) |
6993 | 0 | continue; |
6994 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Free pending radio work '%s'@%p%s", |
6995 | 0 | work->type, work, work->started ? " (started)" : ""); |
6996 | 0 | radio_work_free(work); |
6997 | 0 | break; |
6998 | 0 | } |
6999 | 0 | } |
7000 | | |
7001 | | |
7002 | | static void radio_remove_interface(struct wpa_supplicant *wpa_s) |
7003 | 0 | { |
7004 | 0 | struct wpa_radio *radio = wpa_s->radio; |
7005 | |
|
7006 | 0 | if (!radio) |
7007 | 0 | return; |
7008 | | |
7009 | 0 | wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s", |
7010 | 0 | wpa_s->ifname, radio->name); |
7011 | 0 | dl_list_del(&wpa_s->radio_list); |
7012 | 0 | radio_remove_works(wpa_s, NULL, 0); |
7013 | | /* If the interface that triggered the external scan was removed, the |
7014 | | * external scan is no longer running. */ |
7015 | 0 | if (wpa_s == radio->external_scan_req_interface) |
7016 | 0 | radio->external_scan_req_interface = NULL; |
7017 | 0 | wpa_s->radio = NULL; |
7018 | 0 | if (!dl_list_empty(&radio->ifaces)) |
7019 | 0 | return; /* Interfaces remain for this radio */ |
7020 | | |
7021 | 0 | wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name); |
7022 | 0 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
7023 | 0 | os_free(radio); |
7024 | 0 | } |
7025 | | |
7026 | | |
7027 | | void radio_work_check_next(struct wpa_supplicant *wpa_s) |
7028 | 0 | { |
7029 | 0 | struct wpa_radio *radio = wpa_s->radio; |
7030 | |
|
7031 | 0 | if (dl_list_empty(&radio->work)) |
7032 | 0 | return; |
7033 | 0 | if (wpa_s->ext_work_in_progress) { |
7034 | 0 | wpa_printf(MSG_DEBUG, |
7035 | 0 | "External radio work in progress - delay start of pending item"); |
7036 | 0 | return; |
7037 | 0 | } |
7038 | 0 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
7039 | 0 | eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL); |
7040 | 0 | } |
7041 | | |
7042 | | |
7043 | | /** |
7044 | | * radio_add_work - Add a radio work item |
7045 | | * @wpa_s: Pointer to wpa_supplicant data |
7046 | | * @freq: Frequency of the offchannel operation in MHz or 0 |
7047 | | * @type: Unique identifier for each type of work |
7048 | | * @next: Force as the next work to be executed |
7049 | | * @cb: Callback function for indicating when radio is available |
7050 | | * @ctx: Context pointer for the work (work->ctx in cb()) |
7051 | | * Returns: 0 on success, -1 on failure |
7052 | | * |
7053 | | * This function is used to request time for an operation that requires |
7054 | | * exclusive radio control. Once the radio is available, the registered callback |
7055 | | * function will be called. radio_work_done() must be called once the exclusive |
7056 | | * radio operation has been completed, so that the radio is freed for other |
7057 | | * operations. The special case of deinit=1 is used to free the context data |
7058 | | * during interface removal. That does not allow the callback function to start |
7059 | | * the radio operation, i.e., it must free any resources allocated for the radio |
7060 | | * work and return. |
7061 | | * |
7062 | | * The @freq parameter can be used to indicate a single channel on which the |
7063 | | * offchannel operation will occur. This may allow multiple radio work |
7064 | | * operations to be performed in parallel if they apply for the same channel. |
7065 | | * Setting this to 0 indicates that the work item may use multiple channels or |
7066 | | * requires exclusive control of the radio. |
7067 | | */ |
7068 | | int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq, |
7069 | | const char *type, int next, |
7070 | | void (*cb)(struct wpa_radio_work *work, int deinit), |
7071 | | void *ctx) |
7072 | 0 | { |
7073 | 0 | struct wpa_radio *radio = wpa_s->radio; |
7074 | 0 | struct wpa_radio_work *work; |
7075 | 0 | int was_empty; |
7076 | |
|
7077 | 0 | work = os_zalloc(sizeof(*work)); |
7078 | 0 | if (work == NULL) |
7079 | 0 | return -1; |
7080 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work); |
7081 | 0 | os_get_reltime(&work->time); |
7082 | 0 | work->freq = freq; |
7083 | 0 | work->type = type; |
7084 | 0 | work->wpa_s = wpa_s; |
7085 | 0 | work->cb = cb; |
7086 | 0 | work->ctx = ctx; |
7087 | |
|
7088 | 0 | if (freq) |
7089 | 0 | work->bands = wpas_freq_to_band(freq); |
7090 | 0 | else if (os_strcmp(type, "scan") == 0 || |
7091 | 0 | os_strcmp(type, "p2p-scan") == 0) |
7092 | 0 | work->bands = wpas_get_bands(wpa_s, |
7093 | 0 | ((struct wpa_driver_scan_params *) |
7094 | 0 | ctx)->freqs); |
7095 | 0 | else |
7096 | 0 | work->bands = wpas_get_bands(wpa_s, NULL); |
7097 | |
|
7098 | 0 | was_empty = dl_list_empty(&wpa_s->radio->work); |
7099 | 0 | if (next) |
7100 | 0 | dl_list_add(&wpa_s->radio->work, &work->list); |
7101 | 0 | else |
7102 | 0 | dl_list_add_tail(&wpa_s->radio->work, &work->list); |
7103 | 0 | if (was_empty) { |
7104 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately"); |
7105 | 0 | radio_work_check_next(wpa_s); |
7106 | 0 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) |
7107 | 0 | && radio->num_active_works < MAX_ACTIVE_WORKS) { |
7108 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
7109 | 0 | "Try to schedule a radio work (num_active_works=%u)", |
7110 | 0 | radio->num_active_works); |
7111 | 0 | radio_work_check_next(wpa_s); |
7112 | 0 | } |
7113 | |
|
7114 | 0 | return 0; |
7115 | 0 | } |
7116 | | |
7117 | | |
7118 | | /** |
7119 | | * radio_work_done - Indicate that a radio work item has been completed |
7120 | | * @work: Completed work |
7121 | | * |
7122 | | * This function is called once the callback function registered with |
7123 | | * radio_add_work() has completed its work. |
7124 | | */ |
7125 | | void radio_work_done(struct wpa_radio_work *work) |
7126 | 0 | { |
7127 | 0 | struct wpa_supplicant *wpa_s = work->wpa_s; |
7128 | 0 | struct os_reltime now, diff; |
7129 | 0 | unsigned int started = work->started; |
7130 | |
|
7131 | 0 | os_get_reltime(&now); |
7132 | 0 | os_reltime_sub(&now, &work->time, &diff); |
7133 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds", |
7134 | 0 | work->type, work, started ? "done" : "canceled", |
7135 | 0 | diff.sec, diff.usec); |
7136 | 0 | radio_work_free(work); |
7137 | 0 | if (started) |
7138 | 0 | radio_work_check_next(wpa_s); |
7139 | 0 | } |
7140 | | |
7141 | | |
7142 | | struct wpa_radio_work * |
7143 | | radio_work_pending(struct wpa_supplicant *wpa_s, const char *type) |
7144 | 0 | { |
7145 | 0 | struct wpa_radio_work *work; |
7146 | 0 | struct wpa_radio *radio = wpa_s->radio; |
7147 | |
|
7148 | 0 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { |
7149 | 0 | if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0) |
7150 | 0 | return work; |
7151 | 0 | } |
7152 | | |
7153 | 0 | return NULL; |
7154 | 0 | } |
7155 | | |
7156 | | |
7157 | | static int wpas_init_driver(struct wpa_supplicant *wpa_s, |
7158 | | const struct wpa_interface *iface) |
7159 | 0 | { |
7160 | 0 | const char *ifname, *driver, *rn; |
7161 | |
|
7162 | 0 | driver = iface->driver; |
7163 | 0 | next_driver: |
7164 | 0 | if (wpa_supplicant_set_driver(wpa_s, driver) < 0) |
7165 | 0 | return -1; |
7166 | | |
7167 | 0 | wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname); |
7168 | 0 | if (wpa_s->drv_priv == NULL) { |
7169 | 0 | const char *pos; |
7170 | 0 | int level = MSG_ERROR; |
7171 | |
|
7172 | 0 | pos = driver ? os_strchr(driver, ',') : NULL; |
7173 | 0 | if (pos) { |
7174 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " |
7175 | 0 | "driver interface - try next driver wrapper"); |
7176 | 0 | driver = pos + 1; |
7177 | 0 | goto next_driver; |
7178 | 0 | } |
7179 | | |
7180 | | #ifdef CONFIG_MATCH_IFACE |
7181 | | if (wpa_s->matched == WPA_IFACE_MATCHED_NULL) |
7182 | | level = MSG_DEBUG; |
7183 | | #endif /* CONFIG_MATCH_IFACE */ |
7184 | 0 | wpa_msg(wpa_s, level, "Failed to initialize driver interface"); |
7185 | 0 | return -1; |
7186 | 0 | } |
7187 | 0 | if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) { |
7188 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected " |
7189 | 0 | "driver_param '%s'", wpa_s->conf->driver_param); |
7190 | 0 | return -1; |
7191 | 0 | } |
7192 | | |
7193 | 0 | ifname = wpa_drv_get_ifname(wpa_s); |
7194 | 0 | if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) { |
7195 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced " |
7196 | 0 | "interface name with '%s'", ifname); |
7197 | 0 | os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname)); |
7198 | 0 | } |
7199 | |
|
7200 | 0 | rn = wpa_driver_get_radio_name(wpa_s); |
7201 | 0 | if (rn && rn[0] == '\0') |
7202 | 0 | rn = NULL; |
7203 | |
|
7204 | 0 | wpa_s->radio = radio_add_interface(wpa_s, rn); |
7205 | 0 | if (wpa_s->radio == NULL) |
7206 | 0 | return -1; |
7207 | | |
7208 | 0 | return 0; |
7209 | 0 | } |
7210 | | |
7211 | | |
7212 | | #ifdef CONFIG_GAS_SERVER |
7213 | | |
7214 | | static void wpas_gas_server_tx_status(struct wpa_supplicant *wpa_s, |
7215 | | unsigned int freq, const u8 *dst, |
7216 | | const u8 *src, const u8 *bssid, |
7217 | | const u8 *data, size_t data_len, |
7218 | | enum offchannel_send_action_result result) |
7219 | | { |
7220 | | wpa_printf(MSG_DEBUG, "GAS: TX status: freq=%u dst=" MACSTR |
7221 | | " result=%s", |
7222 | | freq, MAC2STR(dst), |
7223 | | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : |
7224 | | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : |
7225 | | "FAILED")); |
7226 | | gas_server_tx_status(wpa_s->gas_server, dst, data, data_len, |
7227 | | result == OFFCHANNEL_SEND_ACTION_SUCCESS); |
7228 | | } |
7229 | | |
7230 | | |
7231 | | static void wpas_gas_server_tx(void *ctx, int freq, const u8 *da, |
7232 | | struct wpabuf *buf, unsigned int wait_time) |
7233 | | { |
7234 | | struct wpa_supplicant *wpa_s = ctx; |
7235 | | const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
7236 | | |
7237 | | if (wait_time > wpa_s->max_remain_on_chan) |
7238 | | wait_time = wpa_s->max_remain_on_chan; |
7239 | | |
7240 | | offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, broadcast, |
7241 | | wpabuf_head(buf), wpabuf_len(buf), |
7242 | | wait_time, wpas_gas_server_tx_status, 0); |
7243 | | } |
7244 | | |
7245 | | #endif /* CONFIG_GAS_SERVER */ |
7246 | | |
7247 | | static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s, |
7248 | | const struct wpa_interface *iface) |
7249 | 0 | { |
7250 | 0 | struct wpa_driver_capa capa; |
7251 | 0 | int capa_res; |
7252 | 0 | u8 dfs_domain; |
7253 | |
|
7254 | 0 | wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver " |
7255 | 0 | "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname, |
7256 | 0 | iface->confname ? iface->confname : "N/A", |
7257 | 0 | iface->driver ? iface->driver : "default", |
7258 | 0 | iface->ctrl_interface ? iface->ctrl_interface : "N/A", |
7259 | 0 | iface->bridge_ifname ? iface->bridge_ifname : "N/A"); |
7260 | |
|
7261 | 0 | if (iface->confname) { |
7262 | | #ifdef CONFIG_BACKEND_FILE |
7263 | | wpa_s->confname = os_rel2abs_path(iface->confname); |
7264 | | if (wpa_s->confname == NULL) { |
7265 | | wpa_printf(MSG_ERROR, "Failed to get absolute path " |
7266 | | "for configuration file '%s'.", |
7267 | | iface->confname); |
7268 | | return -1; |
7269 | | } |
7270 | | wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'", |
7271 | | iface->confname, wpa_s->confname); |
7272 | | #else /* CONFIG_BACKEND_FILE */ |
7273 | 0 | wpa_s->confname = os_strdup(iface->confname); |
7274 | 0 | #endif /* CONFIG_BACKEND_FILE */ |
7275 | 0 | wpa_s->conf = wpa_config_read(wpa_s->confname, NULL, false); |
7276 | 0 | if (wpa_s->conf == NULL) { |
7277 | 0 | wpa_printf(MSG_ERROR, "Failed to read or parse " |
7278 | 0 | "configuration '%s'.", wpa_s->confname); |
7279 | 0 | return -1; |
7280 | 0 | } |
7281 | 0 | wpa_s->confanother = os_rel2abs_path(iface->confanother); |
7282 | 0 | if (wpa_s->confanother && |
7283 | 0 | !wpa_config_read(wpa_s->confanother, wpa_s->conf, true)) { |
7284 | 0 | wpa_printf(MSG_ERROR, |
7285 | 0 | "Failed to read or parse configuration '%s'.", |
7286 | 0 | wpa_s->confanother); |
7287 | 0 | return -1; |
7288 | 0 | } |
7289 | | |
7290 | | /* |
7291 | | * Override ctrl_interface and driver_param if set on command |
7292 | | * line. |
7293 | | */ |
7294 | 0 | if (iface->ctrl_interface) { |
7295 | 0 | os_free(wpa_s->conf->ctrl_interface); |
7296 | 0 | wpa_s->conf->ctrl_interface = |
7297 | 0 | os_strdup(iface->ctrl_interface); |
7298 | 0 | if (!wpa_s->conf->ctrl_interface) { |
7299 | 0 | wpa_printf(MSG_ERROR, |
7300 | 0 | "Failed to duplicate control interface '%s'.", |
7301 | 0 | iface->ctrl_interface); |
7302 | 0 | return -1; |
7303 | 0 | } |
7304 | 0 | } |
7305 | | |
7306 | 0 | if (iface->driver_param) { |
7307 | 0 | os_free(wpa_s->conf->driver_param); |
7308 | 0 | wpa_s->conf->driver_param = |
7309 | 0 | os_strdup(iface->driver_param); |
7310 | 0 | if (!wpa_s->conf->driver_param) { |
7311 | 0 | wpa_printf(MSG_ERROR, |
7312 | 0 | "Failed to duplicate driver param '%s'.", |
7313 | 0 | iface->driver_param); |
7314 | 0 | return -1; |
7315 | 0 | } |
7316 | 0 | } |
7317 | | |
7318 | 0 | if (iface->p2p_mgmt && !iface->ctrl_interface) { |
7319 | 0 | os_free(wpa_s->conf->ctrl_interface); |
7320 | 0 | wpa_s->conf->ctrl_interface = NULL; |
7321 | 0 | } |
7322 | 0 | } else |
7323 | 0 | wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface, |
7324 | 0 | iface->driver_param); |
7325 | | |
7326 | 0 | if (wpa_s->conf == NULL) { |
7327 | 0 | wpa_printf(MSG_ERROR, "\nNo configuration found."); |
7328 | 0 | return -1; |
7329 | 0 | } |
7330 | | |
7331 | 0 | if (iface->ifname == NULL) { |
7332 | 0 | wpa_printf(MSG_ERROR, "\nInterface name is required."); |
7333 | 0 | return -1; |
7334 | 0 | } |
7335 | 0 | if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) { |
7336 | 0 | wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.", |
7337 | 0 | iface->ifname); |
7338 | 0 | return -1; |
7339 | 0 | } |
7340 | 0 | os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname)); |
7341 | | #ifdef CONFIG_MATCH_IFACE |
7342 | | wpa_s->matched = iface->matched; |
7343 | | #endif /* CONFIG_MATCH_IFACE */ |
7344 | |
|
7345 | 0 | if (iface->bridge_ifname) { |
7346 | 0 | if (os_strlen(iface->bridge_ifname) >= |
7347 | 0 | sizeof(wpa_s->bridge_ifname)) { |
7348 | 0 | wpa_printf(MSG_ERROR, "\nToo long bridge interface " |
7349 | 0 | "name '%s'.", iface->bridge_ifname); |
7350 | 0 | return -1; |
7351 | 0 | } |
7352 | 0 | os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname, |
7353 | 0 | sizeof(wpa_s->bridge_ifname)); |
7354 | 0 | } |
7355 | | |
7356 | | /* RSNA Supplicant Key Management - INITIALIZE */ |
7357 | 0 | eapol_sm_notify_portEnabled(wpa_s->eapol, false); |
7358 | 0 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
7359 | | |
7360 | | /* Initialize driver interface and register driver event handler before |
7361 | | * L2 receive handler so that association events are processed before |
7362 | | * EAPOL-Key packets if both become available for the same select() |
7363 | | * call. */ |
7364 | 0 | if (wpas_init_driver(wpa_s, iface) < 0) |
7365 | 0 | return -1; |
7366 | | |
7367 | 0 | if (wpa_supplicant_init_wpa(wpa_s) < 0) |
7368 | 0 | return -1; |
7369 | | |
7370 | 0 | wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname, |
7371 | 0 | wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname : |
7372 | 0 | NULL); |
7373 | 0 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); |
7374 | |
|
7375 | 0 | if (wpa_s->conf->dot11RSNAConfigPMKLifetime && |
7376 | 0 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
7377 | 0 | wpa_s->conf->dot11RSNAConfigPMKLifetime)) { |
7378 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
7379 | 0 | "dot11RSNAConfigPMKLifetime"); |
7380 | 0 | return -1; |
7381 | 0 | } |
7382 | | |
7383 | 0 | if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold && |
7384 | 0 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
7385 | 0 | wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) { |
7386 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
7387 | 0 | "dot11RSNAConfigPMKReauthThreshold"); |
7388 | 0 | return -1; |
7389 | 0 | } |
7390 | | |
7391 | 0 | if (wpa_s->conf->dot11RSNAConfigSATimeout && |
7392 | 0 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
7393 | 0 | wpa_s->conf->dot11RSNAConfigSATimeout)) { |
7394 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
7395 | 0 | "dot11RSNAConfigSATimeout"); |
7396 | 0 | return -1; |
7397 | 0 | } |
7398 | | |
7399 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_PREPEND_PMKID, |
7400 | 0 | wpa_s->conf->ft_prepend_pmkid); |
7401 | |
|
7402 | 0 | wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s, |
7403 | 0 | &wpa_s->hw.num_modes, |
7404 | 0 | &wpa_s->hw.flags, |
7405 | 0 | &dfs_domain); |
7406 | 0 | if (wpa_s->hw.modes) { |
7407 | 0 | u16 i; |
7408 | |
|
7409 | 0 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
7410 | 0 | if (wpa_s->hw.modes[i].vht_capab) { |
7411 | 0 | wpa_s->hw_capab = CAPAB_VHT; |
7412 | 0 | break; |
7413 | 0 | } |
7414 | | |
7415 | 0 | if (wpa_s->hw.modes[i].ht_capab & |
7416 | 0 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) |
7417 | 0 | wpa_s->hw_capab = CAPAB_HT40; |
7418 | 0 | else if (wpa_s->hw.modes[i].ht_capab && |
7419 | 0 | wpa_s->hw_capab == CAPAB_NO_HT_VHT) |
7420 | 0 | wpa_s->hw_capab = CAPAB_HT; |
7421 | 0 | } |
7422 | 0 | wpa_s->support_6ghz = wpas_is_6ghz_supported(wpa_s, false); |
7423 | 0 | } |
7424 | |
|
7425 | 0 | capa_res = wpa_drv_get_capa(wpa_s, &capa); |
7426 | 0 | if (capa_res == 0) { |
7427 | 0 | wpa_s->drv_capa_known = 1; |
7428 | 0 | wpa_s->drv_flags = capa.flags; |
7429 | 0 | wpa_s->drv_flags2 = capa.flags2; |
7430 | 0 | wpa_s->drv_enc = capa.enc; |
7431 | 0 | wpa_s->drv_key_mgmt = capa.key_mgmt; |
7432 | 0 | wpa_s->drv_rrm_flags = capa.rrm_flags; |
7433 | 0 | wpa_s->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs; |
7434 | 0 | wpa_s->probe_resp_offloads = capa.probe_resp_offloads; |
7435 | 0 | wpa_s->max_scan_ssids = capa.max_scan_ssids; |
7436 | 0 | wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids; |
7437 | 0 | wpa_s->max_sched_scan_plans = capa.max_sched_scan_plans; |
7438 | 0 | wpa_s->max_sched_scan_plan_interval = |
7439 | 0 | capa.max_sched_scan_plan_interval; |
7440 | 0 | wpa_s->max_sched_scan_plan_iterations = |
7441 | 0 | capa.max_sched_scan_plan_iterations; |
7442 | 0 | wpa_s->sched_scan_supported = capa.sched_scan_supported; |
7443 | 0 | wpa_s->max_match_sets = capa.max_match_sets; |
7444 | 0 | wpa_s->max_remain_on_chan = capa.max_remain_on_chan; |
7445 | 0 | wpa_s->max_stations = capa.max_stations; |
7446 | 0 | wpa_s->extended_capa = capa.extended_capa; |
7447 | 0 | wpa_s->extended_capa_mask = capa.extended_capa_mask; |
7448 | 0 | wpa_s->extended_capa_len = capa.extended_capa_len; |
7449 | 0 | wpa_s->num_multichan_concurrent = |
7450 | 0 | capa.num_multichan_concurrent; |
7451 | 0 | #ifndef CONFIG_NO_WMM_AC |
7452 | 0 | wpa_s->wmm_ac_supported = capa.wmm_ac_supported; |
7453 | 0 | #endif /* CONFIG_NO_WMM_AC */ |
7454 | 0 | wpa_s->max_num_akms = capa.max_num_akms; |
7455 | |
|
7456 | 0 | if (capa.mac_addr_rand_scan_supported) |
7457 | 0 | wpa_s->mac_addr_rand_supported |= MAC_ADDR_RAND_SCAN; |
7458 | 0 | if (wpa_s->sched_scan_supported && |
7459 | 0 | capa.mac_addr_rand_sched_scan_supported) |
7460 | 0 | wpa_s->mac_addr_rand_supported |= |
7461 | 0 | (MAC_ADDR_RAND_SCHED_SCAN | MAC_ADDR_RAND_PNO); |
7462 | |
|
7463 | 0 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); |
7464 | 0 | if (wpa_s->extended_capa && |
7465 | 0 | wpa_s->extended_capa_len >= 3 && |
7466 | 0 | wpa_s->extended_capa[2] & 0x40) |
7467 | 0 | wpa_s->multi_bss_support = 1; |
7468 | 0 | } |
7469 | | #ifdef CONFIG_PASN |
7470 | | wpa_pasn_sm_set_caps(wpa_s->wpa, wpa_s->drv_flags2); |
7471 | | #endif /* CONFIG_PASN */ |
7472 | 0 | wpa_sm_set_driver_bss_selection(wpa_s->wpa, |
7473 | 0 | !!(wpa_s->drv_flags & |
7474 | 0 | WPA_DRIVER_FLAGS_BSS_SELECTION)); |
7475 | 0 | if (wpa_s->max_remain_on_chan == 0) |
7476 | 0 | wpa_s->max_remain_on_chan = 1000; |
7477 | | |
7478 | | /* |
7479 | | * Only take p2p_mgmt parameters when P2P Device is supported. |
7480 | | * Doing it here as it determines whether l2_packet_init() will be done |
7481 | | * during wpa_supplicant_driver_init(). |
7482 | | */ |
7483 | 0 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) |
7484 | 0 | wpa_s->p2p_mgmt = iface->p2p_mgmt; |
7485 | |
|
7486 | 0 | if (wpa_s->num_multichan_concurrent == 0) |
7487 | 0 | wpa_s->num_multichan_concurrent = 1; |
7488 | |
|
7489 | 0 | if (wpa_supplicant_driver_init(wpa_s) < 0) |
7490 | 0 | return -1; |
7491 | | |
7492 | | #ifdef CONFIG_TDLS |
7493 | | if (!iface->p2p_mgmt && wpa_tdls_init(wpa_s->wpa)) |
7494 | | return -1; |
7495 | | #endif /* CONFIG_TDLS */ |
7496 | | |
7497 | 0 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1] && |
7498 | 0 | wpa_drv_set_country(wpa_s, wpa_s->conf->country)) { |
7499 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country"); |
7500 | 0 | return -1; |
7501 | 0 | } |
7502 | | |
7503 | | #ifdef CONFIG_FST |
7504 | | if (wpa_s->conf->fst_group_id) { |
7505 | | struct fst_iface_cfg cfg; |
7506 | | struct fst_wpa_obj iface_obj; |
7507 | | |
7508 | | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); |
7509 | | os_strlcpy(cfg.group_id, wpa_s->conf->fst_group_id, |
7510 | | sizeof(cfg.group_id)); |
7511 | | cfg.priority = wpa_s->conf->fst_priority; |
7512 | | cfg.llt = wpa_s->conf->fst_llt; |
7513 | | |
7514 | | wpa_s->fst = fst_attach(wpa_s->ifname, wpa_s->own_addr, |
7515 | | &iface_obj, &cfg); |
7516 | | if (!wpa_s->fst) { |
7517 | | wpa_msg(wpa_s, MSG_ERROR, |
7518 | | "FST: Cannot attach iface %s to group %s", |
7519 | | wpa_s->ifname, cfg.group_id); |
7520 | | return -1; |
7521 | | } |
7522 | | } |
7523 | | #endif /* CONFIG_FST */ |
7524 | | |
7525 | 0 | if (wpas_wps_init(wpa_s)) |
7526 | 0 | return -1; |
7527 | | |
7528 | | #ifdef CONFIG_GAS_SERVER |
7529 | | wpa_s->gas_server = gas_server_init(wpa_s, wpas_gas_server_tx); |
7530 | | if (!wpa_s->gas_server) { |
7531 | | wpa_printf(MSG_ERROR, "Failed to initialize GAS server"); |
7532 | | return -1; |
7533 | | } |
7534 | | #endif /* CONFIG_GAS_SERVER */ |
7535 | | |
7536 | | #ifdef CONFIG_DPP |
7537 | | if (wpas_dpp_init(wpa_s) < 0) |
7538 | | return -1; |
7539 | | #endif /* CONFIG_DPP */ |
7540 | | |
7541 | | #ifdef CONFIG_NAN_USD |
7542 | | if (wpas_nan_usd_init(wpa_s) < 0) |
7543 | | return -1; |
7544 | | #endif /* CONFIG_NAN_USD */ |
7545 | | |
7546 | 0 | if (wpa_supplicant_init_eapol(wpa_s) < 0) |
7547 | 0 | return -1; |
7548 | 0 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); |
7549 | |
|
7550 | 0 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); |
7551 | 0 | if (wpa_s->ctrl_iface == NULL) { |
7552 | 0 | wpa_printf(MSG_ERROR, |
7553 | 0 | "Failed to initialize control interface '%s'.\n" |
7554 | 0 | "You may have another wpa_supplicant process " |
7555 | 0 | "already running or the file was\n" |
7556 | 0 | "left by an unclean termination of wpa_supplicant " |
7557 | 0 | "in which case you will need\n" |
7558 | 0 | "to manually remove this file before starting " |
7559 | 0 | "wpa_supplicant again.\n", |
7560 | 0 | wpa_s->conf->ctrl_interface); |
7561 | 0 | return -1; |
7562 | 0 | } |
7563 | | |
7564 | 0 | wpa_s->gas = gas_query_init(wpa_s); |
7565 | 0 | if (wpa_s->gas == NULL) { |
7566 | 0 | wpa_printf(MSG_ERROR, "Failed to initialize GAS query"); |
7567 | 0 | return -1; |
7568 | 0 | } |
7569 | | |
7570 | 0 | if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) || |
7571 | 0 | wpa_s->p2p_mgmt) && |
7572 | 0 | wpas_p2p_init(wpa_s->global, wpa_s) < 0) { |
7573 | 0 | wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P"); |
7574 | 0 | return -1; |
7575 | 0 | } |
7576 | | |
7577 | 0 | if (wpa_bss_init(wpa_s) < 0) |
7578 | 0 | return -1; |
7579 | | |
7580 | | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
7581 | | #ifdef CONFIG_MESH |
7582 | | dl_list_init(&wpa_s->mesh_external_pmksa_cache); |
7583 | | #endif /* CONFIG_MESH */ |
7584 | | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
7585 | | |
7586 | | /* |
7587 | | * Set Wake-on-WLAN triggers, if configured. |
7588 | | * Note: We don't restore/remove the triggers on shutdown (it doesn't |
7589 | | * have effect anyway when the interface is down). |
7590 | | */ |
7591 | 0 | if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0) |
7592 | 0 | return -1; |
7593 | | |
7594 | | #ifdef CONFIG_EAP_PROXY |
7595 | | { |
7596 | | size_t len; |
7597 | | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1, |
7598 | | wpa_s->imsi, &len); |
7599 | | if (wpa_s->mnc_len > 0) { |
7600 | | wpa_s->imsi[len] = '\0'; |
7601 | | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)", |
7602 | | wpa_s->imsi, wpa_s->mnc_len); |
7603 | | } else { |
7604 | | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available"); |
7605 | | } |
7606 | | } |
7607 | | #endif /* CONFIG_EAP_PROXY */ |
7608 | | |
7609 | 0 | if (pcsc_reader_init(wpa_s) < 0) |
7610 | 0 | return -1; |
7611 | | |
7612 | 0 | if (wpas_init_ext_pw(wpa_s) < 0) |
7613 | 0 | return -1; |
7614 | | |
7615 | 0 | #ifndef CONFIG_NO_RRM |
7616 | 0 | wpas_rrm_reset(wpa_s); |
7617 | 0 | #endif /* CONFIG_NO_RRM */ |
7618 | |
|
7619 | 0 | wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans); |
7620 | |
|
7621 | 0 | #ifdef CONFIG_HS20 |
7622 | 0 | hs20_init(wpa_s); |
7623 | 0 | #endif /* CONFIG_HS20 */ |
7624 | | #ifdef CONFIG_MBO |
7625 | | if (!wpa_s->disable_mbo_oce && wpa_s->conf->oce) { |
7626 | | if ((wpa_s->conf->oce & OCE_STA) && |
7627 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) |
7628 | | wpa_s->enable_oce = OCE_STA; |
7629 | | if ((wpa_s->conf->oce & OCE_STA_CFON) && |
7630 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA_CFON)) { |
7631 | | /* TODO: Need to add STA-CFON support */ |
7632 | | wpa_printf(MSG_ERROR, |
7633 | | "OCE STA-CFON feature is not yet supported"); |
7634 | | } |
7635 | | } |
7636 | | wpas_mbo_update_non_pref_chan(wpa_s, wpa_s->conf->non_pref_chan); |
7637 | | #endif /* CONFIG_MBO */ |
7638 | |
|
7639 | 0 | wpa_supplicant_set_default_scan_ies(wpa_s); |
7640 | |
|
7641 | 0 | return 0; |
7642 | 0 | } |
7643 | | |
7644 | | |
7645 | | static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s, |
7646 | | int notify, int terminate) |
7647 | 0 | { |
7648 | 0 | struct wpa_global *global = wpa_s->global; |
7649 | 0 | struct wpa_supplicant *iface, *prev; |
7650 | |
|
7651 | 0 | if (wpa_s == wpa_s->parent) |
7652 | 0 | wpas_p2p_group_remove(wpa_s, "*"); |
7653 | |
|
7654 | 0 | iface = global->ifaces; |
7655 | 0 | while (iface) { |
7656 | 0 | if (iface->p2pdev == wpa_s) |
7657 | 0 | iface->p2pdev = iface->parent; |
7658 | 0 | if (iface == wpa_s || iface->parent != wpa_s) { |
7659 | 0 | iface = iface->next; |
7660 | 0 | continue; |
7661 | 0 | } |
7662 | 0 | wpa_printf(MSG_DEBUG, |
7663 | 0 | "Remove remaining child interface %s from parent %s", |
7664 | 0 | iface->ifname, wpa_s->ifname); |
7665 | 0 | prev = iface; |
7666 | 0 | iface = iface->next; |
7667 | 0 | wpa_supplicant_remove_iface(global, prev, terminate); |
7668 | 0 | } |
7669 | |
|
7670 | 0 | wpa_s->disconnected = 1; |
7671 | 0 | if (wpa_s->drv_priv) { |
7672 | | /* |
7673 | | * Don't deauthenticate if WoWLAN is enable and not explicitly |
7674 | | * been configured to disconnect. |
7675 | | */ |
7676 | 0 | if (!wpa_drv_get_wowlan(wpa_s) || |
7677 | 0 | wpa_s->conf->wowlan_disconnect_on_deinit) { |
7678 | 0 | wpa_supplicant_deauthenticate( |
7679 | 0 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
7680 | |
|
7681 | 0 | wpa_drv_set_countermeasures(wpa_s, 0); |
7682 | 0 | wpa_clear_keys(wpa_s, NULL); |
7683 | 0 | } else { |
7684 | 0 | wpa_msg(wpa_s, MSG_INFO, |
7685 | 0 | "Do not deauthenticate as part of interface deinit since WoWLAN is enabled"); |
7686 | 0 | } |
7687 | 0 | } |
7688 | |
|
7689 | 0 | wpa_supplicant_cleanup(wpa_s); |
7690 | 0 | wpas_p2p_deinit_iface(wpa_s); |
7691 | |
|
7692 | 0 | wpas_ctrl_radio_work_flush(wpa_s); |
7693 | 0 | radio_remove_interface(wpa_s); |
7694 | |
|
7695 | | #ifdef CONFIG_FST |
7696 | | if (wpa_s->fst) { |
7697 | | fst_detach(wpa_s->fst); |
7698 | | wpa_s->fst = NULL; |
7699 | | } |
7700 | | if (wpa_s->received_mb_ies) { |
7701 | | wpabuf_free(wpa_s->received_mb_ies); |
7702 | | wpa_s->received_mb_ies = NULL; |
7703 | | } |
7704 | | #endif /* CONFIG_FST */ |
7705 | |
|
7706 | 0 | if (wpa_s->drv_priv) |
7707 | 0 | wpa_drv_deinit(wpa_s); |
7708 | |
|
7709 | 0 | if (notify) |
7710 | 0 | wpas_notify_iface_removed(wpa_s); |
7711 | |
|
7712 | 0 | if (terminate) |
7713 | 0 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING); |
7714 | |
|
7715 | 0 | wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface); |
7716 | 0 | wpa_s->ctrl_iface = NULL; |
7717 | |
|
7718 | | #ifdef CONFIG_MESH |
7719 | | if (wpa_s->ifmsh) { |
7720 | | wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh, true); |
7721 | | wpa_s->ifmsh = NULL; |
7722 | | } |
7723 | | #endif /* CONFIG_MESH */ |
7724 | |
|
7725 | 0 | if (wpa_s->conf != NULL) { |
7726 | 0 | wpa_config_free(wpa_s->conf); |
7727 | 0 | wpa_s->conf = NULL; |
7728 | 0 | } |
7729 | |
|
7730 | 0 | os_free(wpa_s->ssids_from_scan_req); |
7731 | 0 | os_free(wpa_s->last_scan_freqs); |
7732 | |
|
7733 | 0 | os_free(wpa_s); |
7734 | 0 | } |
7735 | | |
7736 | | |
7737 | | #ifdef CONFIG_MATCH_IFACE |
7738 | | |
7739 | | /** |
7740 | | * wpa_supplicant_match_iface - Match an interface description to a name |
7741 | | * @global: Pointer to global data from wpa_supplicant_init() |
7742 | | * @ifname: Name of the interface to match |
7743 | | * Returns: Pointer to the created interface description or %NULL on failure |
7744 | | */ |
7745 | | struct wpa_interface * wpa_supplicant_match_iface(struct wpa_global *global, |
7746 | | const char *ifname) |
7747 | | { |
7748 | | int i; |
7749 | | struct wpa_interface *iface, *miface; |
7750 | | |
7751 | | for (i = 0; i < global->params.match_iface_count; i++) { |
7752 | | miface = &global->params.match_ifaces[i]; |
7753 | | if (!miface->ifname || |
7754 | | fnmatch(miface->ifname, ifname, 0) == 0) { |
7755 | | iface = os_zalloc(sizeof(*iface)); |
7756 | | if (!iface) |
7757 | | return NULL; |
7758 | | *iface = *miface; |
7759 | | if (!miface->ifname) |
7760 | | iface->matched = WPA_IFACE_MATCHED_NULL; |
7761 | | else |
7762 | | iface->matched = WPA_IFACE_MATCHED; |
7763 | | iface->ifname = ifname; |
7764 | | return iface; |
7765 | | } |
7766 | | } |
7767 | | |
7768 | | return NULL; |
7769 | | } |
7770 | | |
7771 | | |
7772 | | /** |
7773 | | * wpa_supplicant_match_existing - Match existing interfaces |
7774 | | * @global: Pointer to global data from wpa_supplicant_init() |
7775 | | * Returns: 0 on success, -1 on failure |
7776 | | */ |
7777 | | static int wpa_supplicant_match_existing(struct wpa_global *global) |
7778 | | { |
7779 | | struct if_nameindex *ifi, *ifp; |
7780 | | struct wpa_supplicant *wpa_s; |
7781 | | struct wpa_interface *iface; |
7782 | | |
7783 | | ifp = if_nameindex(); |
7784 | | if (!ifp) { |
7785 | | wpa_printf(MSG_ERROR, "if_nameindex: %s", strerror(errno)); |
7786 | | return -1; |
7787 | | } |
7788 | | |
7789 | | for (ifi = ifp; ifi->if_name; ifi++) { |
7790 | | wpa_s = wpa_supplicant_get_iface(global, ifi->if_name); |
7791 | | if (wpa_s) |
7792 | | continue; |
7793 | | iface = wpa_supplicant_match_iface(global, ifi->if_name); |
7794 | | if (iface) { |
7795 | | wpa_supplicant_add_iface(global, iface, NULL); |
7796 | | os_free(iface); |
7797 | | } |
7798 | | } |
7799 | | |
7800 | | if_freenameindex(ifp); |
7801 | | return 0; |
7802 | | } |
7803 | | |
7804 | | #endif /* CONFIG_MATCH_IFACE */ |
7805 | | |
7806 | | |
7807 | | /** |
7808 | | * wpa_supplicant_add_iface - Add a new network interface |
7809 | | * @global: Pointer to global data from wpa_supplicant_init() |
7810 | | * @iface: Interface configuration options |
7811 | | * @parent: Parent interface or %NULL to assign new interface as parent |
7812 | | * Returns: Pointer to the created interface or %NULL on failure |
7813 | | * |
7814 | | * This function is used to add new network interfaces for %wpa_supplicant. |
7815 | | * This can be called before wpa_supplicant_run() to add interfaces before the |
7816 | | * main event loop has been started. In addition, new interfaces can be added |
7817 | | * dynamically while %wpa_supplicant is already running. This could happen, |
7818 | | * e.g., when a hotplug network adapter is inserted. |
7819 | | */ |
7820 | | struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global, |
7821 | | struct wpa_interface *iface, |
7822 | | struct wpa_supplicant *parent) |
7823 | 0 | { |
7824 | 0 | struct wpa_supplicant *wpa_s; |
7825 | 0 | struct wpa_interface t_iface; |
7826 | 0 | struct wpa_ssid *ssid; |
7827 | |
|
7828 | 0 | if (global == NULL || iface == NULL) |
7829 | 0 | return NULL; |
7830 | | |
7831 | 0 | wpa_s = wpa_supplicant_alloc(parent); |
7832 | 0 | if (wpa_s == NULL) |
7833 | 0 | return NULL; |
7834 | | |
7835 | 0 | wpa_s->global = global; |
7836 | |
|
7837 | 0 | t_iface = *iface; |
7838 | 0 | if (global->params.override_driver) { |
7839 | 0 | wpa_printf(MSG_DEBUG, "Override interface parameter: driver " |
7840 | 0 | "('%s' -> '%s')", |
7841 | 0 | iface->driver, global->params.override_driver); |
7842 | 0 | t_iface.driver = global->params.override_driver; |
7843 | 0 | } |
7844 | 0 | if (global->params.override_ctrl_interface) { |
7845 | 0 | wpa_printf(MSG_DEBUG, "Override interface parameter: " |
7846 | 0 | "ctrl_interface ('%s' -> '%s')", |
7847 | 0 | iface->ctrl_interface, |
7848 | 0 | global->params.override_ctrl_interface); |
7849 | 0 | t_iface.ctrl_interface = |
7850 | 0 | global->params.override_ctrl_interface; |
7851 | 0 | } |
7852 | 0 | if (wpa_supplicant_init_iface(wpa_s, &t_iface)) { |
7853 | 0 | wpa_printf(MSG_DEBUG, "Failed to add interface %s", |
7854 | 0 | iface->ifname); |
7855 | 0 | wpa_supplicant_deinit_iface(wpa_s, 0, 0); |
7856 | 0 | return NULL; |
7857 | 0 | } |
7858 | | |
7859 | 0 | if (iface->p2p_mgmt == 0) { |
7860 | | /* Notify the control interfaces about new iface */ |
7861 | 0 | if (wpas_notify_iface_added(wpa_s)) { |
7862 | 0 | wpa_supplicant_deinit_iface(wpa_s, 1, 0); |
7863 | 0 | return NULL; |
7864 | 0 | } |
7865 | | |
7866 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
7867 | 0 | wpas_notify_network_added(wpa_s, ssid); |
7868 | 0 | } |
7869 | | |
7870 | 0 | wpa_s->next = global->ifaces; |
7871 | 0 | global->ifaces = wpa_s; |
7872 | |
|
7873 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname); |
7874 | 0 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
7875 | |
|
7876 | | #ifdef CONFIG_P2P |
7877 | | if (wpa_s->global->p2p == NULL && |
7878 | | !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled && |
7879 | | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
7880 | | wpas_p2p_add_p2pdev_interface( |
7881 | | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { |
7882 | | wpa_printf(MSG_INFO, |
7883 | | "P2P: Failed to enable P2P Device interface"); |
7884 | | /* Try to continue without. P2P will be disabled. */ |
7885 | | } |
7886 | | #endif /* CONFIG_P2P */ |
7887 | |
|
7888 | 0 | return wpa_s; |
7889 | 0 | } |
7890 | | |
7891 | | |
7892 | | /** |
7893 | | * wpa_supplicant_remove_iface - Remove a network interface |
7894 | | * @global: Pointer to global data from wpa_supplicant_init() |
7895 | | * @wpa_s: Pointer to the network interface to be removed |
7896 | | * Returns: 0 if interface was removed, -1 if interface was not found |
7897 | | * |
7898 | | * This function can be used to dynamically remove network interfaces from |
7899 | | * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In |
7900 | | * addition, this function is used to remove all remaining interfaces when |
7901 | | * %wpa_supplicant is terminated. |
7902 | | */ |
7903 | | int wpa_supplicant_remove_iface(struct wpa_global *global, |
7904 | | struct wpa_supplicant *wpa_s, |
7905 | | int terminate) |
7906 | 0 | { |
7907 | 0 | struct wpa_supplicant *prev; |
7908 | | #ifdef CONFIG_MESH |
7909 | | unsigned int mesh_if_created = wpa_s->mesh_if_created; |
7910 | | char *ifname = NULL; |
7911 | | struct wpa_supplicant *parent = wpa_s->parent; |
7912 | | #endif /* CONFIG_MESH */ |
7913 | | |
7914 | | /* Remove interface from the global list of interfaces */ |
7915 | 0 | prev = global->ifaces; |
7916 | 0 | if (prev == wpa_s) { |
7917 | 0 | global->ifaces = wpa_s->next; |
7918 | 0 | } else { |
7919 | 0 | while (prev && prev->next != wpa_s) |
7920 | 0 | prev = prev->next; |
7921 | 0 | if (prev == NULL) |
7922 | 0 | return -1; |
7923 | 0 | prev->next = wpa_s->next; |
7924 | 0 | } |
7925 | | |
7926 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname); |
7927 | |
|
7928 | | #ifdef CONFIG_MESH |
7929 | | if (mesh_if_created) { |
7930 | | ifname = os_strdup(wpa_s->ifname); |
7931 | | if (ifname == NULL) { |
7932 | | wpa_dbg(wpa_s, MSG_ERROR, |
7933 | | "mesh: Failed to malloc ifname"); |
7934 | | return -1; |
7935 | | } |
7936 | | } |
7937 | | #endif /* CONFIG_MESH */ |
7938 | |
|
7939 | 0 | if (global->p2p_group_formation == wpa_s) |
7940 | 0 | global->p2p_group_formation = NULL; |
7941 | 0 | if (global->p2p_invite_group == wpa_s) |
7942 | 0 | global->p2p_invite_group = NULL; |
7943 | 0 | wpa_supplicant_deinit_iface(wpa_s, 1, terminate); |
7944 | |
|
7945 | | #ifdef CONFIG_MESH |
7946 | | if (mesh_if_created) { |
7947 | | wpa_drv_if_remove(parent, WPA_IF_MESH, ifname); |
7948 | | os_free(ifname); |
7949 | | } |
7950 | | #endif /* CONFIG_MESH */ |
7951 | |
|
7952 | 0 | return 0; |
7953 | 0 | } |
7954 | | |
7955 | | |
7956 | | /** |
7957 | | * wpa_supplicant_get_eap_mode - Get the current EAP mode |
7958 | | * @wpa_s: Pointer to the network interface |
7959 | | * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found |
7960 | | */ |
7961 | | const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s) |
7962 | 0 | { |
7963 | 0 | const char *eapol_method; |
7964 | |
|
7965 | 0 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 && |
7966 | 0 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
7967 | 0 | return "NO-EAP"; |
7968 | 0 | } |
7969 | | |
7970 | 0 | eapol_method = eapol_sm_get_method_name(wpa_s->eapol); |
7971 | 0 | if (eapol_method == NULL) |
7972 | 0 | return "UNKNOWN-EAP"; |
7973 | | |
7974 | 0 | return eapol_method; |
7975 | 0 | } |
7976 | | |
7977 | | |
7978 | | /** |
7979 | | * wpa_supplicant_get_iface - Get a new network interface |
7980 | | * @global: Pointer to global data from wpa_supplicant_init() |
7981 | | * @ifname: Interface name |
7982 | | * Returns: Pointer to the interface or %NULL if not found |
7983 | | */ |
7984 | | struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global, |
7985 | | const char *ifname) |
7986 | 0 | { |
7987 | 0 | struct wpa_supplicant *wpa_s; |
7988 | |
|
7989 | 0 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
7990 | 0 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
7991 | 0 | return wpa_s; |
7992 | 0 | } |
7993 | 0 | return NULL; |
7994 | 0 | } |
7995 | | |
7996 | | |
7997 | | #ifndef CONFIG_NO_WPA_MSG |
7998 | | static const char * wpa_supplicant_msg_ifname_cb(void *ctx) |
7999 | 0 | { |
8000 | 0 | struct wpa_supplicant *wpa_s = ctx; |
8001 | 0 | if (wpa_s == NULL) |
8002 | 0 | return NULL; |
8003 | 0 | return wpa_s->ifname; |
8004 | 0 | } |
8005 | | #endif /* CONFIG_NO_WPA_MSG */ |
8006 | | |
8007 | | |
8008 | | #ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL |
8009 | 0 | #define WPA_SUPPLICANT_CLEANUP_INTERVAL 10 |
8010 | | #endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */ |
8011 | | |
8012 | | /* Periodic cleanup tasks */ |
8013 | | static void wpas_periodic(void *eloop_ctx, void *timeout_ctx) |
8014 | 0 | { |
8015 | 0 | struct wpa_global *global = eloop_ctx; |
8016 | 0 | struct wpa_supplicant *wpa_s; |
8017 | |
|
8018 | 0 | eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, |
8019 | 0 | wpas_periodic, global, NULL); |
8020 | |
|
8021 | | #ifdef CONFIG_P2P |
8022 | | if (global->p2p) |
8023 | | p2p_expire_peers(global->p2p); |
8024 | | #endif /* CONFIG_P2P */ |
8025 | |
|
8026 | 0 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
8027 | 0 | wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age); |
8028 | | #ifdef CONFIG_AP |
8029 | | ap_periodic(wpa_s); |
8030 | | #endif /* CONFIG_AP */ |
8031 | 0 | } |
8032 | 0 | } |
8033 | | |
8034 | | |
8035 | | /** |
8036 | | * wpa_supplicant_init - Initialize %wpa_supplicant |
8037 | | * @params: Parameters for %wpa_supplicant |
8038 | | * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure |
8039 | | * |
8040 | | * This function is used to initialize %wpa_supplicant. After successful |
8041 | | * initialization, the returned data pointer can be used to add and remove |
8042 | | * network interfaces, and eventually, to deinitialize %wpa_supplicant. |
8043 | | */ |
8044 | | struct wpa_global * wpa_supplicant_init(struct wpa_params *params) |
8045 | 0 | { |
8046 | 0 | struct wpa_global *global; |
8047 | 0 | int ret, i; |
8048 | |
|
8049 | 0 | if (params == NULL) |
8050 | 0 | return NULL; |
8051 | | |
8052 | | #ifdef CONFIG_DRIVER_NDIS |
8053 | | { |
8054 | | void driver_ndis_init_ops(void); |
8055 | | driver_ndis_init_ops(); |
8056 | | } |
8057 | | #endif /* CONFIG_DRIVER_NDIS */ |
8058 | | |
8059 | 0 | #ifndef CONFIG_NO_WPA_MSG |
8060 | 0 | wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb); |
8061 | 0 | #endif /* CONFIG_NO_WPA_MSG */ |
8062 | |
|
8063 | 0 | if (params->wpa_debug_file_path) |
8064 | 0 | wpa_debug_open_file(params->wpa_debug_file_path); |
8065 | 0 | if (!params->wpa_debug_file_path && !params->wpa_debug_syslog) |
8066 | 0 | wpa_debug_setup_stdout(); |
8067 | 0 | if (params->wpa_debug_syslog) |
8068 | 0 | wpa_debug_open_syslog(); |
8069 | 0 | if (params->wpa_debug_tracing) { |
8070 | 0 | ret = wpa_debug_open_linux_tracing(); |
8071 | 0 | if (ret) { |
8072 | 0 | wpa_printf(MSG_ERROR, |
8073 | 0 | "Failed to enable trace logging"); |
8074 | 0 | return NULL; |
8075 | 0 | } |
8076 | 0 | } |
8077 | | |
8078 | 0 | ret = eap_register_methods(); |
8079 | 0 | if (ret) { |
8080 | 0 | wpa_printf(MSG_ERROR, "Failed to register EAP methods"); |
8081 | 0 | if (ret == -2) |
8082 | 0 | wpa_printf(MSG_ERROR, "Two or more EAP methods used " |
8083 | 0 | "the same EAP type."); |
8084 | 0 | return NULL; |
8085 | 0 | } |
8086 | | |
8087 | 0 | global = os_zalloc(sizeof(*global)); |
8088 | 0 | if (global == NULL) |
8089 | 0 | return NULL; |
8090 | 0 | dl_list_init(&global->p2p_srv_bonjour); |
8091 | 0 | dl_list_init(&global->p2p_srv_upnp); |
8092 | 0 | global->params.daemonize = params->daemonize; |
8093 | 0 | global->params.wait_for_monitor = params->wait_for_monitor; |
8094 | 0 | global->params.dbus_ctrl_interface = params->dbus_ctrl_interface; |
8095 | |
|
8096 | 0 | if (params->pid_file) { |
8097 | 0 | global->params.pid_file = os_strdup(params->pid_file); |
8098 | 0 | if (!global->params.pid_file) { |
8099 | 0 | wpa_supplicant_deinit(global); |
8100 | 0 | return NULL; |
8101 | 0 | } |
8102 | 0 | } |
8103 | | |
8104 | 0 | if (params->ctrl_interface) { |
8105 | 0 | global->params.ctrl_interface = |
8106 | 0 | os_strdup(params->ctrl_interface); |
8107 | 0 | if (!global->params.ctrl_interface) { |
8108 | 0 | wpa_supplicant_deinit(global); |
8109 | 0 | return NULL; |
8110 | 0 | } |
8111 | 0 | } |
8112 | | |
8113 | 0 | if (params->ctrl_interface_group) { |
8114 | 0 | global->params.ctrl_interface_group = |
8115 | 0 | os_strdup(params->ctrl_interface_group); |
8116 | 0 | if (!global->params.ctrl_interface_group) { |
8117 | 0 | wpa_supplicant_deinit(global); |
8118 | 0 | return NULL; |
8119 | 0 | } |
8120 | 0 | } |
8121 | | |
8122 | 0 | if (params->override_driver) { |
8123 | 0 | global->params.override_driver = |
8124 | 0 | os_strdup(params->override_driver); |
8125 | 0 | if (!global->params.override_driver) { |
8126 | 0 | wpa_supplicant_deinit(global); |
8127 | 0 | return NULL; |
8128 | 0 | } |
8129 | 0 | } |
8130 | | |
8131 | 0 | if (params->override_ctrl_interface) { |
8132 | 0 | global->params.override_ctrl_interface = |
8133 | 0 | os_strdup(params->override_ctrl_interface); |
8134 | 0 | if (!global->params.override_ctrl_interface) { |
8135 | 0 | wpa_supplicant_deinit(global); |
8136 | 0 | return NULL; |
8137 | 0 | } |
8138 | 0 | } |
8139 | | |
8140 | | #ifdef CONFIG_MATCH_IFACE |
8141 | | global->params.match_iface_count = params->match_iface_count; |
8142 | | if (params->match_iface_count) { |
8143 | | global->params.match_ifaces = |
8144 | | os_calloc(params->match_iface_count, |
8145 | | sizeof(struct wpa_interface)); |
8146 | | if (!global->params.match_ifaces) { |
8147 | | wpa_printf(MSG_ERROR, |
8148 | | "Failed to allocate match interfaces"); |
8149 | | wpa_supplicant_deinit(global); |
8150 | | return NULL; |
8151 | | } |
8152 | | os_memcpy(global->params.match_ifaces, |
8153 | | params->match_ifaces, |
8154 | | params->match_iface_count * |
8155 | | sizeof(struct wpa_interface)); |
8156 | | } |
8157 | | #endif /* CONFIG_MATCH_IFACE */ |
8158 | | #ifdef CONFIG_P2P |
8159 | | if (params->conf_p2p_dev) { |
8160 | | global->params.conf_p2p_dev = |
8161 | | os_strdup(params->conf_p2p_dev); |
8162 | | if (!global->params.conf_p2p_dev) { |
8163 | | wpa_printf(MSG_ERROR, "Failed to allocate conf p2p"); |
8164 | | wpa_supplicant_deinit(global); |
8165 | | return NULL; |
8166 | | } |
8167 | | } |
8168 | | #endif /* CONFIG_P2P */ |
8169 | 0 | wpa_debug_level = global->params.wpa_debug_level = |
8170 | 0 | params->wpa_debug_level; |
8171 | 0 | wpa_debug_show_keys = global->params.wpa_debug_show_keys = |
8172 | 0 | params->wpa_debug_show_keys; |
8173 | 0 | wpa_debug_timestamp = global->params.wpa_debug_timestamp = |
8174 | 0 | params->wpa_debug_timestamp; |
8175 | |
|
8176 | 0 | wpa_printf(MSG_DEBUG, "wpa_supplicant v%s", VERSION_STR); |
8177 | |
|
8178 | 0 | if (eloop_init()) { |
8179 | 0 | wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |
8180 | 0 | wpa_supplicant_deinit(global); |
8181 | 0 | return NULL; |
8182 | 0 | } |
8183 | | |
8184 | 0 | random_init(params->entropy_file); |
8185 | |
|
8186 | 0 | global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global); |
8187 | 0 | if (global->ctrl_iface == NULL) { |
8188 | 0 | wpa_supplicant_deinit(global); |
8189 | 0 | return NULL; |
8190 | 0 | } |
8191 | | |
8192 | 0 | if (wpas_notify_supplicant_initialized(global)) { |
8193 | 0 | wpa_supplicant_deinit(global); |
8194 | 0 | return NULL; |
8195 | 0 | } |
8196 | | |
8197 | 0 | for (i = 0; wpa_drivers[i]; i++) |
8198 | 0 | global->drv_count++; |
8199 | 0 | if (global->drv_count == 0) { |
8200 | 0 | wpa_printf(MSG_ERROR, "No drivers enabled"); |
8201 | 0 | wpa_supplicant_deinit(global); |
8202 | 0 | return NULL; |
8203 | 0 | } |
8204 | 0 | global->drv_priv = os_calloc(global->drv_count, sizeof(void *)); |
8205 | 0 | if (global->drv_priv == NULL) { |
8206 | 0 | wpa_supplicant_deinit(global); |
8207 | 0 | return NULL; |
8208 | 0 | } |
8209 | | |
8210 | | #ifdef CONFIG_WIFI_DISPLAY |
8211 | | if (wifi_display_init(global) < 0) { |
8212 | | wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display"); |
8213 | | wpa_supplicant_deinit(global); |
8214 | | return NULL; |
8215 | | } |
8216 | | #endif /* CONFIG_WIFI_DISPLAY */ |
8217 | | |
8218 | 0 | eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, |
8219 | 0 | wpas_periodic, global, NULL); |
8220 | |
|
8221 | 0 | return global; |
8222 | 0 | } |
8223 | | |
8224 | | |
8225 | | /** |
8226 | | * wpa_supplicant_run - Run the %wpa_supplicant main event loop |
8227 | | * @global: Pointer to global data from wpa_supplicant_init() |
8228 | | * Returns: 0 after successful event loop run, -1 on failure |
8229 | | * |
8230 | | * This function starts the main event loop and continues running as long as |
8231 | | * there are any remaining events. In most cases, this function is running as |
8232 | | * long as the %wpa_supplicant process in still in use. |
8233 | | */ |
8234 | | int wpa_supplicant_run(struct wpa_global *global) |
8235 | 0 | { |
8236 | 0 | struct wpa_supplicant *wpa_s; |
8237 | |
|
8238 | 0 | if (global->params.daemonize && |
8239 | 0 | (wpa_supplicant_daemon(global->params.pid_file) || |
8240 | 0 | eloop_sock_requeue())) |
8241 | 0 | return -1; |
8242 | | |
8243 | | #ifdef CONFIG_MATCH_IFACE |
8244 | | if (wpa_supplicant_match_existing(global)) |
8245 | | return -1; |
8246 | | #endif |
8247 | | |
8248 | 0 | if (global->params.wait_for_monitor) { |
8249 | 0 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) |
8250 | 0 | if (wpa_s->ctrl_iface && !wpa_s->p2p_mgmt) |
8251 | 0 | wpa_supplicant_ctrl_iface_wait( |
8252 | 0 | wpa_s->ctrl_iface); |
8253 | 0 | } |
8254 | |
|
8255 | 0 | eloop_register_signal_terminate(wpa_supplicant_terminate, global); |
8256 | 0 | eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); |
8257 | |
|
8258 | 0 | eloop_run(); |
8259 | |
|
8260 | 0 | return 0; |
8261 | 0 | } |
8262 | | |
8263 | | |
8264 | | /** |
8265 | | * wpa_supplicant_deinit - Deinitialize %wpa_supplicant |
8266 | | * @global: Pointer to global data from wpa_supplicant_init() |
8267 | | * |
8268 | | * This function is called to deinitialize %wpa_supplicant and to free all |
8269 | | * allocated resources. Remaining network interfaces will also be removed. |
8270 | | */ |
8271 | | void wpa_supplicant_deinit(struct wpa_global *global) |
8272 | 0 | { |
8273 | 0 | int i; |
8274 | |
|
8275 | 0 | if (global == NULL) |
8276 | 0 | return; |
8277 | | |
8278 | 0 | eloop_cancel_timeout(wpas_periodic, global, NULL); |
8279 | |
|
8280 | | #ifdef CONFIG_WIFI_DISPLAY |
8281 | | wifi_display_deinit(global); |
8282 | | #endif /* CONFIG_WIFI_DISPLAY */ |
8283 | |
|
8284 | 0 | while (global->ifaces) |
8285 | 0 | wpa_supplicant_remove_iface(global, global->ifaces, 1); |
8286 | |
|
8287 | 0 | if (global->ctrl_iface) |
8288 | 0 | wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface); |
8289 | |
|
8290 | 0 | wpas_notify_supplicant_deinitialized(global); |
8291 | |
|
8292 | 0 | eap_peer_unregister_methods(); |
8293 | | #ifdef CONFIG_AP |
8294 | | eap_server_unregister_methods(); |
8295 | | #endif /* CONFIG_AP */ |
8296 | |
|
8297 | 0 | for (i = 0; wpa_drivers[i] && global->drv_priv; i++) { |
8298 | 0 | if (!global->drv_priv[i]) |
8299 | 0 | continue; |
8300 | 0 | wpa_drivers[i]->global_deinit(global->drv_priv[i]); |
8301 | 0 | } |
8302 | 0 | os_free(global->drv_priv); |
8303 | |
|
8304 | 0 | random_deinit(); |
8305 | |
|
8306 | 0 | eloop_destroy(); |
8307 | |
|
8308 | 0 | if (global->params.pid_file) { |
8309 | 0 | os_daemonize_terminate(global->params.pid_file); |
8310 | 0 | os_free(global->params.pid_file); |
8311 | 0 | } |
8312 | 0 | os_free(global->params.ctrl_interface); |
8313 | 0 | os_free(global->params.ctrl_interface_group); |
8314 | 0 | os_free(global->params.override_driver); |
8315 | 0 | os_free(global->params.override_ctrl_interface); |
8316 | | #ifdef CONFIG_MATCH_IFACE |
8317 | | os_free(global->params.match_ifaces); |
8318 | | #endif /* CONFIG_MATCH_IFACE */ |
8319 | | #ifdef CONFIG_P2P |
8320 | | os_free(global->params.conf_p2p_dev); |
8321 | | #endif /* CONFIG_P2P */ |
8322 | |
|
8323 | 0 | os_free(global->p2p_disallow_freq.range); |
8324 | 0 | os_free(global->p2p_go_avoid_freq.range); |
8325 | 0 | os_free(global->add_psk); |
8326 | |
|
8327 | 0 | os_free(global); |
8328 | 0 | wpa_debug_close_syslog(); |
8329 | 0 | wpa_debug_close_file(); |
8330 | 0 | wpa_debug_close_linux_tracing(); |
8331 | 0 | } |
8332 | | |
8333 | | |
8334 | | void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s) |
8335 | 0 | { |
8336 | 0 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
8337 | 0 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
8338 | 0 | char country[3]; |
8339 | 0 | country[0] = wpa_s->conf->country[0]; |
8340 | 0 | country[1] = wpa_s->conf->country[1]; |
8341 | 0 | country[2] = '\0'; |
8342 | 0 | if (wpa_drv_set_country(wpa_s, country) < 0) { |
8343 | 0 | wpa_printf(MSG_ERROR, "Failed to set country code " |
8344 | 0 | "'%s'", country); |
8345 | 0 | } |
8346 | 0 | } |
8347 | |
|
8348 | 0 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND) |
8349 | 0 | wpas_init_ext_pw(wpa_s); |
8350 | |
|
8351 | 0 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SCHED_SCAN_PLANS) |
8352 | 0 | wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans); |
8353 | |
|
8354 | 0 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WOWLAN_TRIGGERS) { |
8355 | 0 | struct wpa_driver_capa capa; |
8356 | 0 | int res = wpa_drv_get_capa(wpa_s, &capa); |
8357 | |
|
8358 | 0 | if (res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0) |
8359 | 0 | wpa_printf(MSG_ERROR, |
8360 | 0 | "Failed to update wowlan_triggers to '%s'", |
8361 | 0 | wpa_s->conf->wowlan_triggers); |
8362 | 0 | } |
8363 | |
|
8364 | 0 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DISABLE_BTM) |
8365 | 0 | wpa_supplicant_set_default_scan_ies(wpa_s); |
8366 | |
|
8367 | 0 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_FT_PREPEND_PMKID) |
8368 | 0 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_PREPEND_PMKID, |
8369 | 0 | wpa_s->conf->ft_prepend_pmkid); |
8370 | |
|
8371 | | #ifdef CONFIG_BGSCAN |
8372 | | /* |
8373 | | * We default to global bgscan parameters only when per-network bgscan |
8374 | | * parameters aren't set. Only bother resetting bgscan parameters if |
8375 | | * this is the case. |
8376 | | */ |
8377 | | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_BGSCAN) && |
8378 | | wpa_s->current_ssid && !wpa_s->current_ssid->bgscan && |
8379 | | wpa_s->wpa_state == WPA_COMPLETED) |
8380 | | wpa_supplicant_reset_bgscan(wpa_s); |
8381 | | #endif /* CONFIG_BGSCAN */ |
8382 | |
|
8383 | | #ifdef CONFIG_WPS |
8384 | | wpas_wps_update_config(wpa_s); |
8385 | | #endif /* CONFIG_WPS */ |
8386 | 0 | wpas_p2p_update_config(wpa_s); |
8387 | 0 | wpa_s->conf->changed_parameters = 0; |
8388 | 0 | } |
8389 | | |
8390 | | |
8391 | | void add_freq(int *freqs, int *num_freqs, int freq) |
8392 | 0 | { |
8393 | 0 | int i; |
8394 | |
|
8395 | 0 | for (i = 0; i < *num_freqs; i++) { |
8396 | 0 | if (freqs[i] == freq) |
8397 | 0 | return; |
8398 | 0 | } |
8399 | | |
8400 | 0 | freqs[*num_freqs] = freq; |
8401 | 0 | (*num_freqs)++; |
8402 | 0 | } |
8403 | | |
8404 | | |
8405 | | static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s) |
8406 | 0 | { |
8407 | 0 | struct wpa_bss *bss, *cbss; |
8408 | 0 | const int max_freqs = 10; |
8409 | 0 | int *freqs; |
8410 | 0 | int num_freqs = 0; |
8411 | |
|
8412 | 0 | freqs = os_calloc(max_freqs + 1, sizeof(int)); |
8413 | 0 | if (freqs == NULL) |
8414 | 0 | return NULL; |
8415 | | |
8416 | 0 | cbss = wpa_s->current_bss; |
8417 | |
|
8418 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
8419 | 0 | if (bss == cbss) |
8420 | 0 | continue; |
8421 | 0 | if (bss->ssid_len == cbss->ssid_len && |
8422 | 0 | os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 && |
8423 | 0 | !wpa_bssid_ignore_is_listed(wpa_s, bss->bssid)) { |
8424 | 0 | add_freq(freqs, &num_freqs, bss->freq); |
8425 | 0 | if (num_freqs == max_freqs) |
8426 | 0 | break; |
8427 | 0 | } |
8428 | 0 | } |
8429 | |
|
8430 | 0 | if (num_freqs == 0) { |
8431 | 0 | os_free(freqs); |
8432 | 0 | freqs = NULL; |
8433 | 0 | } |
8434 | |
|
8435 | 0 | return freqs; |
8436 | 0 | } |
8437 | | |
8438 | | |
8439 | | void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid, |
8440 | | const u8 **link_bssids) |
8441 | 0 | { |
8442 | 0 | int timeout; |
8443 | 0 | int count; |
8444 | 0 | int *freqs = NULL; |
8445 | |
|
8446 | 0 | wpas_connect_work_done(wpa_s); |
8447 | | |
8448 | | /* |
8449 | | * Remove possible authentication timeout since the connection failed. |
8450 | | */ |
8451 | 0 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
8452 | | |
8453 | | /* |
8454 | | * There is no point in ignoring the AP temporarily if this event is |
8455 | | * generated based on local request to disconnect. |
8456 | | */ |
8457 | 0 | if (wpa_s->own_disconnect_req || wpa_s->own_reconnect_req) { |
8458 | 0 | wpa_s->own_disconnect_req = 0; |
8459 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
8460 | 0 | "Ignore connection failure due to local request to disconnect"); |
8461 | 0 | return; |
8462 | 0 | } |
8463 | 0 | if (wpa_s->disconnected) { |
8464 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure " |
8465 | 0 | "indication since interface has been put into " |
8466 | 0 | "disconnected state"); |
8467 | 0 | return; |
8468 | 0 | } |
8469 | | |
8470 | | /* Also mark links as failed */ |
8471 | 0 | while (link_bssids && *link_bssids) { |
8472 | 0 | wpa_bssid_ignore_add(wpa_s, *link_bssids); |
8473 | 0 | link_bssids++; |
8474 | 0 | } |
8475 | | |
8476 | | /* |
8477 | | * Add the failed BSSID into the ignore list and speed up next scan |
8478 | | * attempt if there could be other APs that could accept association. |
8479 | | */ |
8480 | 0 | count = wpa_bssid_ignore_add(wpa_s, bssid); |
8481 | 0 | if (count == 1 && wpa_s->current_bss) { |
8482 | | /* |
8483 | | * This BSS was not in the ignore list before. If there is |
8484 | | * another BSS available for the same ESS, we should try that |
8485 | | * next. Otherwise, we may as well try this one once more |
8486 | | * before allowing other, likely worse, ESSes to be considered. |
8487 | | */ |
8488 | 0 | freqs = get_bss_freqs_in_ess(wpa_s); |
8489 | 0 | if (freqs) { |
8490 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS " |
8491 | 0 | "has been seen; try it next"); |
8492 | 0 | wpa_bssid_ignore_add(wpa_s, bssid); |
8493 | | /* |
8494 | | * On the next scan, go through only the known channels |
8495 | | * used in this ESS based on previous scans to speed up |
8496 | | * common load balancing use case. |
8497 | | */ |
8498 | 0 | os_free(wpa_s->next_scan_freqs); |
8499 | 0 | wpa_s->next_scan_freqs = freqs; |
8500 | 0 | } |
8501 | 0 | } |
8502 | |
|
8503 | 0 | wpa_s->consecutive_conn_failures++; |
8504 | |
|
8505 | 0 | if (wpa_s->consecutive_conn_failures > 3 && wpa_s->current_ssid) { |
8506 | 0 | wpa_printf(MSG_DEBUG, "Continuous association failures - " |
8507 | 0 | "consider temporary network disabling"); |
8508 | 0 | wpas_auth_failed(wpa_s, "CONN_FAILED", bssid); |
8509 | 0 | } |
8510 | | /* |
8511 | | * Multiple consecutive connection failures mean that other APs are |
8512 | | * either not available or have already been tried, so we can start |
8513 | | * increasing the delay here to avoid constant scanning. |
8514 | | */ |
8515 | 0 | switch (wpa_s->consecutive_conn_failures) { |
8516 | 0 | case 1: |
8517 | 0 | timeout = 100; |
8518 | 0 | break; |
8519 | 0 | case 2: |
8520 | 0 | timeout = 500; |
8521 | 0 | break; |
8522 | 0 | case 3: |
8523 | 0 | timeout = 1000; |
8524 | 0 | break; |
8525 | 0 | case 4: |
8526 | 0 | timeout = 5000; |
8527 | 0 | break; |
8528 | 0 | default: |
8529 | 0 | timeout = 10000; |
8530 | 0 | break; |
8531 | 0 | } |
8532 | | |
8533 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
8534 | 0 | "Consecutive connection failures: %d --> request scan in %d ms", |
8535 | 0 | wpa_s->consecutive_conn_failures, timeout); |
8536 | | |
8537 | | /* |
8538 | | * TODO: if more than one possible AP is available in scan results, |
8539 | | * could try the other ones before requesting a new scan. |
8540 | | */ |
8541 | | |
8542 | | /* speed up the connection attempt with normal scan */ |
8543 | 0 | wpa_s->normal_scans = 0; |
8544 | 0 | wpa_supplicant_req_scan(wpa_s, timeout / 1000, |
8545 | 0 | 1000 * (timeout % 1000)); |
8546 | 0 | } |
8547 | | |
8548 | | |
8549 | | #ifdef CONFIG_FILS |
8550 | | |
8551 | | void fils_pmksa_cache_flush(struct wpa_supplicant *wpa_s) |
8552 | | { |
8553 | | struct wpa_ssid *ssid = wpa_s->current_ssid; |
8554 | | const u8 *realm, *username, *rrk; |
8555 | | size_t realm_len, username_len, rrk_len; |
8556 | | u16 next_seq_num; |
8557 | | |
8558 | | /* Clear the PMKSA cache entry if FILS authentication was rejected. |
8559 | | * Check for ERP keys existing to limit when this can be done since |
8560 | | * the rejection response is not protected and such triggers should |
8561 | | * really not allow internal state to be modified unless required to |
8562 | | * avoid significant issues in functionality. In addition, drop |
8563 | | * externally configure PMKSA entries even without ERP keys since it |
8564 | | * is possible for an external component to add PMKSA entries for FILS |
8565 | | * authentication without restoring previously generated ERP keys. |
8566 | | * |
8567 | | * In this case, this is needed to allow recovery from cases where the |
8568 | | * AP or authentication server has dropped PMKSAs and ERP keys. */ |
8569 | | if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt)) |
8570 | | return; |
8571 | | |
8572 | | if (eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, |
8573 | | &username, &username_len, |
8574 | | &realm, &realm_len, &next_seq_num, |
8575 | | &rrk, &rrk_len) != 0 || |
8576 | | !realm) { |
8577 | | wpa_dbg(wpa_s, MSG_DEBUG, |
8578 | | "FILS: Drop external PMKSA cache entry"); |
8579 | | wpa_sm_aborted_external_cached(wpa_s->wpa); |
8580 | | wpa_sm_external_pmksa_cache_flush(wpa_s->wpa, ssid); |
8581 | | return; |
8582 | | } |
8583 | | |
8584 | | wpa_dbg(wpa_s, MSG_DEBUG, "FILS: Drop PMKSA cache entry"); |
8585 | | wpa_sm_aborted_cached(wpa_s->wpa); |
8586 | | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
8587 | | } |
8588 | | |
8589 | | |
8590 | | void fils_connection_failure(struct wpa_supplicant *wpa_s) |
8591 | | { |
8592 | | struct wpa_ssid *ssid = wpa_s->current_ssid; |
8593 | | const u8 *realm, *username, *rrk; |
8594 | | size_t realm_len, username_len, rrk_len; |
8595 | | u16 next_seq_num; |
8596 | | |
8597 | | if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt) || |
8598 | | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, |
8599 | | &username, &username_len, |
8600 | | &realm, &realm_len, &next_seq_num, |
8601 | | &rrk, &rrk_len) != 0 || |
8602 | | !realm) |
8603 | | return; |
8604 | | |
8605 | | wpa_hexdump_ascii(MSG_DEBUG, |
8606 | | "FILS: Store last connection failure realm", |
8607 | | realm, realm_len); |
8608 | | os_free(wpa_s->last_con_fail_realm); |
8609 | | wpa_s->last_con_fail_realm = os_malloc(realm_len); |
8610 | | if (wpa_s->last_con_fail_realm) { |
8611 | | wpa_s->last_con_fail_realm_len = realm_len; |
8612 | | os_memcpy(wpa_s->last_con_fail_realm, realm, realm_len); |
8613 | | } |
8614 | | } |
8615 | | #endif /* CONFIG_FILS */ |
8616 | | |
8617 | | |
8618 | | int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s) |
8619 | 0 | { |
8620 | 0 | return wpa_s->conf->ap_scan == 2 || |
8621 | 0 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION); |
8622 | 0 | } |
8623 | | |
8624 | | |
8625 | | static bool wpas_driver_rsn_override(struct wpa_supplicant *wpa_s) |
8626 | 0 | { |
8627 | 0 | return !!(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_RSN_OVERRIDE_STA); |
8628 | 0 | } |
8629 | | |
8630 | | |
8631 | | bool wpas_rsn_overriding(struct wpa_supplicant *wpa_s) |
8632 | 0 | { |
8633 | 0 | if (wpa_s->conf->rsn_overriding == RSN_OVERRIDING_DISABLED) |
8634 | 0 | return false; |
8635 | | |
8636 | 0 | if (wpa_s->conf->rsn_overriding == RSN_OVERRIDING_ENABLED) |
8637 | 0 | return true; |
8638 | | |
8639 | 0 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
8640 | 0 | wpas_driver_bss_selection(wpa_s)) |
8641 | 0 | return wpas_driver_rsn_override(wpa_s); |
8642 | | |
8643 | 0 | return true; |
8644 | 0 | } |
8645 | | |
8646 | | |
8647 | | #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW) |
8648 | | int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s, |
8649 | | struct wpa_ssid *ssid, |
8650 | | const char *field, |
8651 | | const char *value) |
8652 | | { |
8653 | | #ifdef IEEE8021X_EAPOL |
8654 | | struct eap_peer_config *eap = &ssid->eap; |
8655 | | |
8656 | | wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field); |
8657 | | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value", |
8658 | | (const u8 *) value, os_strlen(value)); |
8659 | | |
8660 | | switch (wpa_supplicant_ctrl_req_from_string(field)) { |
8661 | | case WPA_CTRL_REQ_EAP_IDENTITY: |
8662 | | os_free(eap->identity); |
8663 | | eap->identity = (u8 *) os_strdup(value); |
8664 | | if (!eap->identity) |
8665 | | return -1; |
8666 | | eap->identity_len = os_strlen(value); |
8667 | | eap->pending_req_identity = 0; |
8668 | | if (ssid == wpa_s->current_ssid) |
8669 | | wpa_s->reassociate = 1; |
8670 | | break; |
8671 | | case WPA_CTRL_REQ_EAP_PASSWORD: |
8672 | | bin_clear_free(eap->password, eap->password_len); |
8673 | | eap->password = (u8 *) os_strdup(value); |
8674 | | if (!eap->password) |
8675 | | return -1; |
8676 | | eap->password_len = os_strlen(value); |
8677 | | eap->pending_req_password = 0; |
8678 | | if (ssid == wpa_s->current_ssid) |
8679 | | wpa_s->reassociate = 1; |
8680 | | break; |
8681 | | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: |
8682 | | bin_clear_free(eap->new_password, eap->new_password_len); |
8683 | | eap->new_password = (u8 *) os_strdup(value); |
8684 | | if (!eap->new_password) |
8685 | | return -1; |
8686 | | eap->new_password_len = os_strlen(value); |
8687 | | eap->pending_req_new_password = 0; |
8688 | | if (ssid == wpa_s->current_ssid) |
8689 | | wpa_s->reassociate = 1; |
8690 | | break; |
8691 | | case WPA_CTRL_REQ_EAP_PIN: |
8692 | | str_clear_free(eap->cert.pin); |
8693 | | eap->cert.pin = os_strdup(value); |
8694 | | if (!eap->cert.pin) |
8695 | | return -1; |
8696 | | eap->pending_req_pin = 0; |
8697 | | if (ssid == wpa_s->current_ssid) |
8698 | | wpa_s->reassociate = 1; |
8699 | | break; |
8700 | | case WPA_CTRL_REQ_EAP_OTP: |
8701 | | bin_clear_free(eap->otp, eap->otp_len); |
8702 | | eap->otp = (u8 *) os_strdup(value); |
8703 | | if (!eap->otp) |
8704 | | return -1; |
8705 | | eap->otp_len = os_strlen(value); |
8706 | | os_free(eap->pending_req_otp); |
8707 | | eap->pending_req_otp = NULL; |
8708 | | eap->pending_req_otp_len = 0; |
8709 | | break; |
8710 | | case WPA_CTRL_REQ_EAP_PASSPHRASE: |
8711 | | str_clear_free(eap->cert.private_key_passwd); |
8712 | | eap->cert.private_key_passwd = os_strdup(value); |
8713 | | if (!eap->cert.private_key_passwd) |
8714 | | return -1; |
8715 | | eap->pending_req_passphrase = 0; |
8716 | | if (ssid == wpa_s->current_ssid) |
8717 | | wpa_s->reassociate = 1; |
8718 | | break; |
8719 | | case WPA_CTRL_REQ_SIM: |
8720 | | str_clear_free(eap->external_sim_resp); |
8721 | | eap->external_sim_resp = os_strdup(value); |
8722 | | if (!eap->external_sim_resp) |
8723 | | return -1; |
8724 | | eap->pending_req_sim = 0; |
8725 | | break; |
8726 | | case WPA_CTRL_REQ_PSK_PASSPHRASE: |
8727 | | if (wpa_config_set(ssid, "psk", value, 0) < 0) |
8728 | | return -1; |
8729 | | ssid->mem_only_psk = 1; |
8730 | | if (ssid->passphrase) |
8731 | | wpa_config_update_psk(ssid); |
8732 | | if (wpa_s->wpa_state == WPA_SCANNING && !wpa_s->scanning) |
8733 | | wpa_supplicant_req_scan(wpa_s, 0, 0); |
8734 | | break; |
8735 | | case WPA_CTRL_REQ_EXT_CERT_CHECK: |
8736 | | if (eap->pending_ext_cert_check != PENDING_CHECK) |
8737 | | return -1; |
8738 | | if (os_strcmp(value, "good") == 0) |
8739 | | eap->pending_ext_cert_check = EXT_CERT_CHECK_GOOD; |
8740 | | else if (os_strcmp(value, "bad") == 0) |
8741 | | eap->pending_ext_cert_check = EXT_CERT_CHECK_BAD; |
8742 | | else |
8743 | | return -1; |
8744 | | break; |
8745 | | default: |
8746 | | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field); |
8747 | | return -1; |
8748 | | } |
8749 | | |
8750 | | return 0; |
8751 | | #else /* IEEE8021X_EAPOL */ |
8752 | | wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included"); |
8753 | | return -1; |
8754 | | #endif /* IEEE8021X_EAPOL */ |
8755 | | } |
8756 | | #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */ |
8757 | | |
8758 | | |
8759 | | int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
8760 | 0 | { |
8761 | | #ifdef CONFIG_WEP |
8762 | | int i; |
8763 | | unsigned int drv_enc; |
8764 | | #endif /* CONFIG_WEP */ |
8765 | |
|
8766 | 0 | if (wpa_s->p2p_mgmt) |
8767 | 0 | return 1; /* no normal network profiles on p2p_mgmt interface */ |
8768 | | |
8769 | 0 | if (ssid == NULL) |
8770 | 0 | return 1; |
8771 | | |
8772 | 0 | if (ssid->disabled) |
8773 | 0 | return 1; |
8774 | | |
8775 | | #ifdef CONFIG_WEP |
8776 | | if (wpa_s->drv_capa_known) |
8777 | | drv_enc = wpa_s->drv_enc; |
8778 | | else |
8779 | | drv_enc = (unsigned int) -1; |
8780 | | |
8781 | | for (i = 0; i < NUM_WEP_KEYS; i++) { |
8782 | | size_t len = ssid->wep_key_len[i]; |
8783 | | if (len == 0) |
8784 | | continue; |
8785 | | if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40)) |
8786 | | continue; |
8787 | | if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104)) |
8788 | | continue; |
8789 | | if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128)) |
8790 | | continue; |
8791 | | return 1; /* invalid WEP key */ |
8792 | | } |
8793 | | #endif /* CONFIG_WEP */ |
8794 | | |
8795 | 0 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set && |
8796 | 0 | (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk && |
8797 | 0 | !(wpa_key_mgmt_sae(ssid->key_mgmt) && ssid->sae_password) && |
8798 | 0 | !ssid->mem_only_psk) |
8799 | 0 | return 1; |
8800 | | |
8801 | 0 | #ifdef IEEE8021X_EAPOL |
8802 | | #ifdef CRYPTO_RSA_OAEP_SHA256 |
8803 | | if (ssid->eap.imsi_privacy_cert) { |
8804 | | struct crypto_rsa_key *key; |
8805 | | bool failed = false; |
8806 | | |
8807 | | key = crypto_rsa_key_read(ssid->eap.imsi_privacy_cert, false); |
8808 | | if (!key) |
8809 | | failed = true; |
8810 | | crypto_rsa_key_free(key); |
8811 | | if (failed) { |
8812 | | wpa_printf(MSG_DEBUG, |
8813 | | "Invalid imsi_privacy_cert (%s) - disable network", |
8814 | | ssid->eap.imsi_privacy_cert); |
8815 | | return 1; |
8816 | | } |
8817 | | } |
8818 | | #endif /* CRYPTO_RSA_OAEP_SHA256 */ |
8819 | 0 | #endif /* IEEE8021X_EAPOL */ |
8820 | | |
8821 | 0 | return 0; |
8822 | 0 | } |
8823 | | |
8824 | | |
8825 | | int wpas_get_ssid_pmf(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
8826 | 0 | { |
8827 | 0 | if (ssid == NULL || ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) { |
8828 | 0 | if (wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_OPTIONAL && |
8829 | 0 | !(wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)) { |
8830 | | /* |
8831 | | * Driver does not support BIP -- ignore pmf=1 default |
8832 | | * since the connection with PMF would fail and the |
8833 | | * configuration does not require PMF to be enabled. |
8834 | | */ |
8835 | 0 | return NO_MGMT_FRAME_PROTECTION; |
8836 | 0 | } |
8837 | | |
8838 | 0 | if (ssid && |
8839 | 0 | (ssid->key_mgmt & |
8840 | 0 | ~(WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPS | |
8841 | 0 | WPA_KEY_MGMT_IEEE8021X_NO_WPA)) == 0) { |
8842 | | /* |
8843 | | * Do not use the default PMF value for non-RSN networks |
8844 | | * since PMF is available only with RSN and pmf=2 |
8845 | | * configuration would otherwise prevent connections to |
8846 | | * all open networks. |
8847 | | */ |
8848 | 0 | return NO_MGMT_FRAME_PROTECTION; |
8849 | 0 | } |
8850 | | |
8851 | | #ifdef CONFIG_OCV |
8852 | | /* Enable PMF if OCV is being enabled */ |
8853 | | if (wpa_s->conf->pmf == NO_MGMT_FRAME_PROTECTION && |
8854 | | ssid && ssid->ocv) |
8855 | | return MGMT_FRAME_PROTECTION_OPTIONAL; |
8856 | | #endif /* CONFIG_OCV */ |
8857 | | |
8858 | 0 | return wpa_s->conf->pmf; |
8859 | 0 | } |
8860 | | |
8861 | 0 | return ssid->ieee80211w; |
8862 | 0 | } |
8863 | | |
8864 | | |
8865 | | #ifdef CONFIG_SAE |
8866 | | bool wpas_is_sae_avoided(struct wpa_supplicant *wpa_s, |
8867 | | struct wpa_ssid *ssid, |
8868 | | const struct wpa_ie_data *ie) |
8869 | | { |
8870 | | return wpa_s->conf->sae_check_mfp && |
8871 | | (!(ie->capabilities & |
8872 | | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) || |
8873 | | wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION); |
8874 | | } |
8875 | | #endif /* CONFIG_SAE */ |
8876 | | |
8877 | | |
8878 | | int pmf_in_use(struct wpa_supplicant *wpa_s, const u8 *addr) |
8879 | 0 | { |
8880 | 0 | if (wpa_s->current_ssid == NULL || |
8881 | 0 | wpa_s->wpa_state < WPA_4WAY_HANDSHAKE) |
8882 | 0 | return 0; |
8883 | 0 | if (wpa_s->valid_links) { |
8884 | 0 | if (!ether_addr_equal(addr, wpa_s->ap_mld_addr) && |
8885 | 0 | !wpas_ap_link_address(wpa_s, addr)) |
8886 | 0 | return 0; |
8887 | 0 | } else { |
8888 | 0 | if (!ether_addr_equal(addr, wpa_s->bssid)) |
8889 | 0 | return 0; |
8890 | 0 | } |
8891 | 0 | return wpa_sm_pmf_enabled(wpa_s->wpa); |
8892 | 0 | } |
8893 | | |
8894 | | |
8895 | | int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s) |
8896 | 0 | { |
8897 | 0 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P) |
8898 | 0 | return 1; |
8899 | 0 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA) |
8900 | 0 | return 0; |
8901 | 0 | return -1; |
8902 | 0 | } |
8903 | | |
8904 | | |
8905 | | void wpas_auth_failed(struct wpa_supplicant *wpa_s, const char *reason, |
8906 | | const u8 *bssid) |
8907 | 0 | { |
8908 | 0 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
8909 | 0 | int dur; |
8910 | 0 | struct os_reltime now; |
8911 | |
|
8912 | 0 | if (ssid == NULL) { |
8913 | 0 | wpa_printf(MSG_DEBUG, "Authentication failure but no known " |
8914 | 0 | "SSID block"); |
8915 | 0 | return; |
8916 | 0 | } |
8917 | | |
8918 | 0 | if (ssid->key_mgmt == WPA_KEY_MGMT_WPS) |
8919 | 0 | return; |
8920 | | |
8921 | 0 | ssid->auth_failures++; |
8922 | |
|
8923 | | #ifdef CONFIG_P2P |
8924 | | if (ssid->p2p_group && |
8925 | | (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) { |
8926 | | /* |
8927 | | * Skip the wait time since there is a short timeout on the |
8928 | | * connection to a P2P group. |
8929 | | */ |
8930 | | return; |
8931 | | } |
8932 | | #endif /* CONFIG_P2P */ |
8933 | |
|
8934 | 0 | if (ssid->auth_failures > 50) |
8935 | 0 | dur = 300; |
8936 | 0 | else if (ssid->auth_failures > 10) |
8937 | 0 | dur = 120; |
8938 | 0 | else if (ssid->auth_failures > 5) |
8939 | 0 | dur = 90; |
8940 | 0 | else if (ssid->auth_failures > 3) |
8941 | 0 | dur = 60; |
8942 | 0 | else if (ssid->auth_failures > 2) |
8943 | 0 | dur = 30; |
8944 | 0 | else if (ssid->auth_failures > 1) |
8945 | 0 | dur = 20; |
8946 | 0 | else |
8947 | 0 | dur = 10; |
8948 | |
|
8949 | 0 | if (ssid->auth_failures > 1 && |
8950 | 0 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) |
8951 | 0 | dur += os_random() % (ssid->auth_failures * 10); |
8952 | |
|
8953 | 0 | os_get_reltime(&now); |
8954 | 0 | if (now.sec + dur <= ssid->disabled_until.sec) |
8955 | 0 | return; |
8956 | | |
8957 | 0 | ssid->disabled_until.sec = now.sec + dur; |
8958 | |
|
8959 | 0 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED |
8960 | 0 | "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s", |
8961 | 0 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len), |
8962 | 0 | ssid->auth_failures, dur, reason); |
8963 | |
|
8964 | 0 | if (bssid) |
8965 | 0 | os_memcpy(ssid->disabled_due_to, bssid, ETH_ALEN); |
8966 | 0 | } |
8967 | | |
8968 | | |
8969 | | void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s, |
8970 | | struct wpa_ssid *ssid, int clear_failures) |
8971 | 0 | { |
8972 | 0 | if (ssid == NULL) |
8973 | 0 | return; |
8974 | | |
8975 | 0 | if (ssid->disabled_until.sec) { |
8976 | 0 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED |
8977 | 0 | "id=%d ssid=\"%s\"", |
8978 | 0 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
8979 | 0 | } |
8980 | 0 | ssid->disabled_until.sec = 0; |
8981 | 0 | ssid->disabled_until.usec = 0; |
8982 | 0 | if (clear_failures) { |
8983 | 0 | ssid->auth_failures = 0; |
8984 | 0 | } else if (!is_zero_ether_addr(ssid->disabled_due_to)) { |
8985 | 0 | wpa_printf(MSG_DEBUG, "Mark BSSID " MACSTR |
8986 | 0 | " ignored to allow a lower priority BSS, if any, to be tried next", |
8987 | 0 | MAC2STR(ssid->disabled_due_to)); |
8988 | 0 | wpa_bssid_ignore_add(wpa_s, ssid->disabled_due_to); |
8989 | 0 | os_memset(ssid->disabled_due_to, 0, ETH_ALEN); |
8990 | 0 | } |
8991 | 0 | } |
8992 | | |
8993 | | |
8994 | | int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid) |
8995 | 0 | { |
8996 | 0 | size_t i; |
8997 | |
|
8998 | 0 | if (wpa_s->disallow_aps_bssid == NULL) |
8999 | 0 | return 0; |
9000 | | |
9001 | 0 | for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) { |
9002 | 0 | if (ether_addr_equal(wpa_s->disallow_aps_bssid + i * ETH_ALEN, |
9003 | 0 | bssid)) |
9004 | 0 | return 1; |
9005 | 0 | } |
9006 | | |
9007 | 0 | return 0; |
9008 | 0 | } |
9009 | | |
9010 | | |
9011 | | int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid, |
9012 | | size_t ssid_len) |
9013 | 0 | { |
9014 | 0 | size_t i; |
9015 | |
|
9016 | 0 | if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL) |
9017 | 0 | return 0; |
9018 | | |
9019 | 0 | for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) { |
9020 | 0 | struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i]; |
9021 | 0 | if (ssid_len == s->ssid_len && |
9022 | 0 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
9023 | 0 | return 1; |
9024 | 0 | } |
9025 | | |
9026 | 0 | return 0; |
9027 | 0 | } |
9028 | | |
9029 | | |
9030 | | /** |
9031 | | * wpas_request_connection - Request a new connection |
9032 | | * @wpa_s: Pointer to the network interface |
9033 | | * |
9034 | | * This function is used to request a new connection to be found. It will mark |
9035 | | * the interface to allow reassociation and request a new scan to find a |
9036 | | * suitable network to connect to. |
9037 | | */ |
9038 | | void wpas_request_connection(struct wpa_supplicant *wpa_s) |
9039 | 0 | { |
9040 | 0 | wpa_s->normal_scans = 0; |
9041 | 0 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
9042 | 0 | wpa_supplicant_reinit_autoscan(wpa_s); |
9043 | 0 | wpa_s->disconnected = 0; |
9044 | 0 | wpa_s->reassociate = 1; |
9045 | 0 | wpa_s->last_owe_group = 0; |
9046 | |
|
9047 | 0 | if (wpa_supplicant_fast_associate(wpa_s) != 1) |
9048 | 0 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
9049 | 0 | else |
9050 | 0 | wpa_s->reattach = 0; |
9051 | 0 | } |
9052 | | |
9053 | | |
9054 | | /** |
9055 | | * wpas_request_disconnection - Request disconnection |
9056 | | * @wpa_s: Pointer to the network interface |
9057 | | * |
9058 | | * This function is used to request disconnection from the currently connected |
9059 | | * network. This will stop any ongoing scans and initiate deauthentication. |
9060 | | */ |
9061 | | void wpas_request_disconnection(struct wpa_supplicant *wpa_s) |
9062 | 0 | { |
9063 | | #ifdef CONFIG_SME |
9064 | | wpa_s->sme.prev_bssid_set = 0; |
9065 | | #endif /* CONFIG_SME */ |
9066 | 0 | wpa_s->reassociate = 0; |
9067 | 0 | wpa_s->disconnected = 1; |
9068 | 0 | wpa_supplicant_cancel_sched_scan(wpa_s); |
9069 | 0 | wpa_supplicant_cancel_scan(wpa_s); |
9070 | 0 | wpas_abort_ongoing_scan(wpa_s); |
9071 | 0 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
9072 | 0 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
9073 | 0 | radio_remove_works(wpa_s, "connect", 0); |
9074 | 0 | radio_remove_works(wpa_s, "sme-connect", 0); |
9075 | 0 | wpa_s->roam_in_progress = false; |
9076 | 0 | #ifdef CONFIG_WNM |
9077 | 0 | wpa_s->bss_trans_mgmt_in_progress = false; |
9078 | 0 | #endif /* CONFIG_WNM */ |
9079 | 0 | } |
9080 | | |
9081 | | |
9082 | | void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title, |
9083 | | struct wpa_used_freq_data *freqs_data, |
9084 | | unsigned int len) |
9085 | 0 | { |
9086 | 0 | unsigned int i; |
9087 | |
|
9088 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s", |
9089 | 0 | len, title); |
9090 | 0 | for (i = 0; i < len; i++) { |
9091 | 0 | struct wpa_used_freq_data *cur = &freqs_data[i]; |
9092 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X", |
9093 | 0 | i, cur->freq, cur->flags); |
9094 | 0 | } |
9095 | 0 | } |
9096 | | |
9097 | | |
9098 | | /* |
9099 | | * Find the operating frequencies of any of the virtual interfaces that |
9100 | | * are using the same radio as the current interface, and in addition, get |
9101 | | * information about the interface types that are using the frequency. |
9102 | | */ |
9103 | | int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s, |
9104 | | struct wpa_used_freq_data *freqs_data, |
9105 | | unsigned int len, bool exclude_current) |
9106 | 0 | { |
9107 | 0 | struct wpa_supplicant *ifs; |
9108 | 0 | u8 bssid[ETH_ALEN]; |
9109 | 0 | int freq; |
9110 | 0 | unsigned int idx = 0, i; |
9111 | |
|
9112 | 0 | wpa_dbg(wpa_s, MSG_DEBUG, |
9113 | 0 | "Determining shared radio frequencies (max len %u)", len); |
9114 | 0 | os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len); |
9115 | |
|
9116 | 0 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
9117 | 0 | radio_list) { |
9118 | 0 | if (idx == len) |
9119 | 0 | break; |
9120 | | |
9121 | 0 | if (exclude_current && ifs == wpa_s) |
9122 | 0 | continue; |
9123 | | |
9124 | 0 | if (ifs->current_ssid == NULL || ifs->assoc_freq == 0) |
9125 | 0 | continue; |
9126 | | |
9127 | 0 | if (ifs->current_ssid->mode == WPAS_MODE_AP || |
9128 | 0 | ifs->current_ssid->mode == WPAS_MODE_P2P_GO || |
9129 | 0 | ifs->current_ssid->mode == WPAS_MODE_MESH) |
9130 | 0 | freq = ifs->current_ssid->frequency; |
9131 | 0 | else if (wpa_drv_get_bssid(ifs, bssid) == 0) |
9132 | 0 | freq = ifs->assoc_freq; |
9133 | 0 | else |
9134 | 0 | continue; |
9135 | | |
9136 | | /* Hold only distinct freqs */ |
9137 | 0 | for (i = 0; i < idx; i++) |
9138 | 0 | if (freqs_data[i].freq == freq) |
9139 | 0 | break; |
9140 | |
|
9141 | 0 | if (i == idx) |
9142 | 0 | freqs_data[idx++].freq = freq; |
9143 | |
|
9144 | 0 | if (ifs->current_ssid->mode == WPAS_MODE_INFRA) { |
9145 | 0 | freqs_data[i].flags |= ifs->current_ssid->p2p_group ? |
9146 | 0 | WPA_FREQ_USED_BY_P2P_CLIENT : |
9147 | 0 | WPA_FREQ_USED_BY_INFRA_STATION; |
9148 | 0 | } |
9149 | 0 | } |
9150 | |
|
9151 | 0 | dump_freq_data(wpa_s, "completed iteration", freqs_data, idx); |
9152 | 0 | return idx; |
9153 | 0 | } |
9154 | | |
9155 | | |
9156 | | /* |
9157 | | * Find the operating frequencies of any of the virtual interfaces that |
9158 | | * are using the same radio as the current interface. |
9159 | | */ |
9160 | | int get_shared_radio_freqs(struct wpa_supplicant *wpa_s, |
9161 | | int *freq_array, unsigned int len, |
9162 | | bool exclude_current) |
9163 | 0 | { |
9164 | 0 | struct wpa_used_freq_data *freqs_data; |
9165 | 0 | int num, i; |
9166 | |
|
9167 | 0 | os_memset(freq_array, 0, sizeof(int) * len); |
9168 | |
|
9169 | 0 | freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data)); |
9170 | 0 | if (!freqs_data) |
9171 | 0 | return -1; |
9172 | | |
9173 | 0 | num = get_shared_radio_freqs_data(wpa_s, freqs_data, len, |
9174 | 0 | exclude_current); |
9175 | 0 | for (i = 0; i < num; i++) |
9176 | 0 | freq_array[i] = freqs_data[i].freq; |
9177 | |
|
9178 | 0 | os_free(freqs_data); |
9179 | |
|
9180 | 0 | return num; |
9181 | 0 | } |
9182 | | |
9183 | | |
9184 | | struct wpa_supplicant * |
9185 | | wpas_vendor_elem(struct wpa_supplicant *wpa_s, enum wpa_vendor_elem_frame frame) |
9186 | 0 | { |
9187 | 0 | switch (frame) { |
9188 | | #ifdef CONFIG_P2P |
9189 | | case VENDOR_ELEM_PROBE_REQ_P2P: |
9190 | | case VENDOR_ELEM_PROBE_RESP_P2P: |
9191 | | case VENDOR_ELEM_PROBE_RESP_P2P_GO: |
9192 | | case VENDOR_ELEM_BEACON_P2P_GO: |
9193 | | case VENDOR_ELEM_P2P_PD_REQ: |
9194 | | case VENDOR_ELEM_P2P_PD_RESP: |
9195 | | case VENDOR_ELEM_P2P_GO_NEG_REQ: |
9196 | | case VENDOR_ELEM_P2P_GO_NEG_RESP: |
9197 | | case VENDOR_ELEM_P2P_GO_NEG_CONF: |
9198 | | case VENDOR_ELEM_P2P_INV_REQ: |
9199 | | case VENDOR_ELEM_P2P_INV_RESP: |
9200 | | case VENDOR_ELEM_P2P_ASSOC_REQ: |
9201 | | case VENDOR_ELEM_P2P_ASSOC_RESP: |
9202 | | return wpa_s->p2pdev; |
9203 | | #endif /* CONFIG_P2P */ |
9204 | 0 | default: |
9205 | 0 | return wpa_s; |
9206 | 0 | } |
9207 | 0 | } |
9208 | | |
9209 | | |
9210 | | void wpas_vendor_elem_update(struct wpa_supplicant *wpa_s) |
9211 | 0 | { |
9212 | 0 | unsigned int i; |
9213 | 0 | char buf[30]; |
9214 | |
|
9215 | 0 | wpa_printf(MSG_DEBUG, "Update vendor elements"); |
9216 | |
|
9217 | 0 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { |
9218 | 0 | if (wpa_s->vendor_elem[i]) { |
9219 | 0 | int res; |
9220 | |
|
9221 | 0 | res = os_snprintf(buf, sizeof(buf), "frame[%u]", i); |
9222 | 0 | if (!os_snprintf_error(sizeof(buf), res)) { |
9223 | 0 | wpa_hexdump_buf(MSG_DEBUG, buf, |
9224 | 0 | wpa_s->vendor_elem[i]); |
9225 | 0 | } |
9226 | 0 | } |
9227 | 0 | } |
9228 | |
|
9229 | | #ifdef CONFIG_P2P |
9230 | | if (wpa_s->parent == wpa_s && |
9231 | | wpa_s->global->p2p && |
9232 | | !wpa_s->global->p2p_disabled) |
9233 | | p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem); |
9234 | | #endif /* CONFIG_P2P */ |
9235 | 0 | } |
9236 | | |
9237 | | |
9238 | | int wpas_vendor_elem_remove(struct wpa_supplicant *wpa_s, int frame, |
9239 | | const u8 *elem, size_t len) |
9240 | 0 | { |
9241 | 0 | u8 *ie, *end; |
9242 | |
|
9243 | 0 | ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]); |
9244 | 0 | end = ie + wpabuf_len(wpa_s->vendor_elem[frame]); |
9245 | |
|
9246 | 0 | for (; ie + 1 < end; ie += 2 + ie[1]) { |
9247 | 0 | if (ie + len > end) |
9248 | 0 | break; |
9249 | 0 | if (os_memcmp(ie, elem, len) != 0) |
9250 | 0 | continue; |
9251 | | |
9252 | 0 | if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) { |
9253 | 0 | wpabuf_free(wpa_s->vendor_elem[frame]); |
9254 | 0 | wpa_s->vendor_elem[frame] = NULL; |
9255 | 0 | } else { |
9256 | 0 | os_memmove(ie, ie + len, end - (ie + len)); |
9257 | 0 | wpa_s->vendor_elem[frame]->used -= len; |
9258 | 0 | } |
9259 | 0 | wpas_vendor_elem_update(wpa_s); |
9260 | 0 | return 0; |
9261 | 0 | } |
9262 | | |
9263 | 0 | return -1; |
9264 | 0 | } |
9265 | | |
9266 | | |
9267 | | struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes, |
9268 | | u16 num_modes, enum hostapd_hw_mode mode, |
9269 | | bool is_6ghz) |
9270 | 0 | { |
9271 | 0 | u16 i; |
9272 | |
|
9273 | 0 | if (!modes) |
9274 | 0 | return NULL; |
9275 | | |
9276 | 0 | for (i = 0; i < num_modes; i++) { |
9277 | 0 | if (modes[i].mode != mode || |
9278 | 0 | !modes[i].num_channels || !modes[i].channels) |
9279 | 0 | continue; |
9280 | 0 | if (is_6ghz == modes[i].is_6ghz) |
9281 | 0 | return &modes[i]; |
9282 | 0 | } |
9283 | | |
9284 | 0 | return NULL; |
9285 | 0 | } |
9286 | | |
9287 | | |
9288 | | struct hostapd_hw_modes * get_mode_with_freq(struct hostapd_hw_modes *modes, |
9289 | | u16 num_modes, int freq) |
9290 | 0 | { |
9291 | 0 | int i, j; |
9292 | |
|
9293 | 0 | for (i = 0; i < num_modes; i++) { |
9294 | 0 | for (j = 0; j < modes[i].num_channels; j++) { |
9295 | 0 | if (freq == modes[i].channels[j].freq) |
9296 | 0 | return &modes[i]; |
9297 | 0 | } |
9298 | 0 | } |
9299 | | |
9300 | 0 | return NULL; |
9301 | 0 | } |
9302 | | |
9303 | | |
9304 | | static struct |
9305 | | wpa_bss_tmp_disallowed * wpas_get_disallowed_bss(struct wpa_supplicant *wpa_s, |
9306 | | const u8 *bssid) |
9307 | 0 | { |
9308 | 0 | struct wpa_bss_tmp_disallowed *bss; |
9309 | |
|
9310 | 0 | dl_list_for_each(bss, &wpa_s->bss_tmp_disallowed, |
9311 | 0 | struct wpa_bss_tmp_disallowed, list) { |
9312 | 0 | if (ether_addr_equal(bssid, bss->bssid)) |
9313 | 0 | return bss; |
9314 | 0 | } |
9315 | | |
9316 | 0 | return NULL; |
9317 | 0 | } |
9318 | | |
9319 | | |
9320 | | static int wpa_set_driver_tmp_disallow_list(struct wpa_supplicant *wpa_s) |
9321 | 0 | { |
9322 | 0 | struct wpa_bss_tmp_disallowed *tmp; |
9323 | 0 | unsigned int num_bssid = 0; |
9324 | 0 | u8 *bssids; |
9325 | 0 | int ret; |
9326 | |
|
9327 | 0 | bssids = os_malloc(dl_list_len(&wpa_s->bss_tmp_disallowed) * ETH_ALEN); |
9328 | 0 | if (!bssids) |
9329 | 0 | return -1; |
9330 | 0 | dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed, |
9331 | 0 | struct wpa_bss_tmp_disallowed, list) { |
9332 | 0 | os_memcpy(&bssids[num_bssid * ETH_ALEN], tmp->bssid, |
9333 | 0 | ETH_ALEN); |
9334 | 0 | num_bssid++; |
9335 | 0 | } |
9336 | 0 | ret = wpa_drv_set_bssid_tmp_disallow(wpa_s, num_bssid, bssids); |
9337 | 0 | os_free(bssids); |
9338 | 0 | return ret; |
9339 | 0 | } |
9340 | | |
9341 | | |
9342 | | static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx) |
9343 | 0 | { |
9344 | 0 | struct wpa_supplicant *wpa_s = eloop_ctx; |
9345 | 0 | struct wpa_bss_tmp_disallowed *tmp, *bss = timeout_ctx; |
9346 | | |
9347 | | /* Make sure the bss is not already freed */ |
9348 | 0 | dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed, |
9349 | 0 | struct wpa_bss_tmp_disallowed, list) { |
9350 | 0 | if (bss == tmp) { |
9351 | 0 | remove_bss_tmp_disallowed_entry(wpa_s, tmp); |
9352 | 0 | wpa_set_driver_tmp_disallow_list(wpa_s); |
9353 | 0 | break; |
9354 | 0 | } |
9355 | 0 | } |
9356 | 0 | } |
9357 | | |
9358 | | |
9359 | | void wpa_bss_tmp_disallow(struct wpa_supplicant *wpa_s, const u8 *bssid, |
9360 | | unsigned int sec, int rssi_threshold) |
9361 | 0 | { |
9362 | 0 | struct wpa_bss_tmp_disallowed *bss; |
9363 | |
|
9364 | 0 | bss = wpas_get_disallowed_bss(wpa_s, bssid); |
9365 | 0 | if (bss) { |
9366 | 0 | eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss); |
9367 | 0 | goto finish; |
9368 | 0 | } |
9369 | | |
9370 | 0 | bss = os_malloc(sizeof(*bss)); |
9371 | 0 | if (!bss) { |
9372 | 0 | wpa_printf(MSG_DEBUG, |
9373 | 0 | "Failed to allocate memory for temp disallow BSS"); |
9374 | 0 | return; |
9375 | 0 | } |
9376 | | |
9377 | 0 | os_memcpy(bss->bssid, bssid, ETH_ALEN); |
9378 | 0 | dl_list_add(&wpa_s->bss_tmp_disallowed, &bss->list); |
9379 | 0 | wpa_set_driver_tmp_disallow_list(wpa_s); |
9380 | |
|
9381 | 0 | finish: |
9382 | 0 | bss->rssi_threshold = rssi_threshold; |
9383 | 0 | eloop_register_timeout(sec, 0, wpa_bss_tmp_disallow_timeout, |
9384 | 0 | wpa_s, bss); |
9385 | 0 | } |
9386 | | |
9387 | | |
9388 | | int wpa_is_bss_tmp_disallowed(struct wpa_supplicant *wpa_s, |
9389 | | struct wpa_bss *bss) |
9390 | 0 | { |
9391 | 0 | struct wpa_bss_tmp_disallowed *disallowed = NULL, *tmp, *prev; |
9392 | |
|
9393 | 0 | dl_list_for_each_safe(tmp, prev, &wpa_s->bss_tmp_disallowed, |
9394 | 0 | struct wpa_bss_tmp_disallowed, list) { |
9395 | 0 | if (ether_addr_equal(bss->bssid, tmp->bssid)) { |
9396 | 0 | disallowed = tmp; |
9397 | 0 | break; |
9398 | 0 | } |
9399 | 0 | } |
9400 | 0 | if (!disallowed) |
9401 | 0 | return 0; |
9402 | | |
9403 | 0 | if (disallowed->rssi_threshold != 0 && |
9404 | 0 | bss->level > disallowed->rssi_threshold) { |
9405 | 0 | remove_bss_tmp_disallowed_entry(wpa_s, disallowed); |
9406 | 0 | wpa_set_driver_tmp_disallow_list(wpa_s); |
9407 | 0 | return 0; |
9408 | 0 | } |
9409 | | |
9410 | 0 | return 1; |
9411 | 0 | } |
9412 | | |
9413 | | |
9414 | | int wpas_enable_mac_addr_randomization(struct wpa_supplicant *wpa_s, |
9415 | | unsigned int type, const u8 *addr, |
9416 | | const u8 *mask) |
9417 | 0 | { |
9418 | 0 | if ((addr && !mask) || (!addr && mask)) { |
9419 | 0 | wpa_printf(MSG_INFO, |
9420 | 0 | "MAC_ADDR_RAND_SCAN invalid addr/mask combination"); |
9421 | 0 | return -1; |
9422 | 0 | } |
9423 | | |
9424 | 0 | if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) { |
9425 | 0 | wpa_printf(MSG_INFO, |
9426 | 0 | "MAC_ADDR_RAND_SCAN cannot allow multicast address"); |
9427 | 0 | return -1; |
9428 | 0 | } |
9429 | | |
9430 | 0 | if (type & MAC_ADDR_RAND_SCAN) { |
9431 | 0 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN, |
9432 | 0 | addr, mask)) |
9433 | 0 | return -1; |
9434 | 0 | } |
9435 | | |
9436 | 0 | if (type & MAC_ADDR_RAND_SCHED_SCAN) { |
9437 | 0 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN, |
9438 | 0 | addr, mask)) |
9439 | 0 | return -1; |
9440 | | |
9441 | 0 | if (wpa_s->sched_scanning && !wpa_s->pno) |
9442 | 0 | wpas_scan_restart_sched_scan(wpa_s); |
9443 | 0 | } |
9444 | | |
9445 | 0 | if (type & MAC_ADDR_RAND_PNO) { |
9446 | 0 | if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO, |
9447 | 0 | addr, mask)) |
9448 | 0 | return -1; |
9449 | | |
9450 | 0 | if (wpa_s->pno) { |
9451 | 0 | wpas_stop_pno(wpa_s); |
9452 | 0 | wpas_start_pno(wpa_s); |
9453 | 0 | } |
9454 | 0 | } |
9455 | | |
9456 | 0 | return 0; |
9457 | 0 | } |
9458 | | |
9459 | | |
9460 | | int wpas_disable_mac_addr_randomization(struct wpa_supplicant *wpa_s, |
9461 | | unsigned int type) |
9462 | 0 | { |
9463 | 0 | wpas_mac_addr_rand_scan_clear(wpa_s, type); |
9464 | 0 | if (wpa_s->pno) { |
9465 | 0 | if (type & MAC_ADDR_RAND_PNO) { |
9466 | 0 | wpas_stop_pno(wpa_s); |
9467 | 0 | wpas_start_pno(wpa_s); |
9468 | 0 | } |
9469 | 0 | } else if (wpa_s->sched_scanning && (type & MAC_ADDR_RAND_SCHED_SCAN)) { |
9470 | 0 | wpas_scan_restart_sched_scan(wpa_s); |
9471 | 0 | } |
9472 | |
|
9473 | 0 | return 0; |
9474 | 0 | } |
9475 | | |
9476 | | |
9477 | | int wpa_drv_signal_poll(struct wpa_supplicant *wpa_s, |
9478 | | struct wpa_signal_info *si) |
9479 | 0 | { |
9480 | 0 | int res; |
9481 | |
|
9482 | 0 | if (!wpa_s->driver->signal_poll) |
9483 | 0 | return -1; |
9484 | | |
9485 | 0 | res = wpa_s->driver->signal_poll(wpa_s->drv_priv, si); |
9486 | |
|
9487 | | #ifdef CONFIG_TESTING_OPTIONS |
9488 | | if (res == 0) { |
9489 | | struct driver_signal_override *dso; |
9490 | | |
9491 | | dl_list_for_each(dso, &wpa_s->drv_signal_override, |
9492 | | struct driver_signal_override, list) { |
9493 | | if (!ether_addr_equal(wpa_s->bssid, dso->bssid)) |
9494 | | continue; |
9495 | | wpa_printf(MSG_DEBUG, |
9496 | | "Override driver signal_poll information: current_signal: %d->%d avg_signal: %d->%d avg_beacon_signal: %d->%d current_noise: %d->%d", |
9497 | | si->data.signal, |
9498 | | dso->si_current_signal, |
9499 | | si->data.avg_signal, |
9500 | | dso->si_avg_signal, |
9501 | | si->data.avg_beacon_signal, |
9502 | | dso->si_avg_beacon_signal, |
9503 | | si->current_noise, |
9504 | | dso->si_current_noise); |
9505 | | si->data.signal = dso->si_current_signal; |
9506 | | si->data.avg_signal = dso->si_avg_signal; |
9507 | | si->data.avg_beacon_signal = dso->si_avg_beacon_signal; |
9508 | | si->current_noise = dso->si_current_noise; |
9509 | | break; |
9510 | | } |
9511 | | } |
9512 | | #endif /* CONFIG_TESTING_OPTIONS */ |
9513 | |
|
9514 | 0 | return res; |
9515 | 0 | } |
9516 | | |
9517 | | |
9518 | | struct wpa_scan_results * |
9519 | | wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s, const u8 *bssid) |
9520 | 948 | { |
9521 | 948 | struct wpa_scan_results *scan_res; |
9522 | | #ifdef CONFIG_TESTING_OPTIONS |
9523 | | size_t idx; |
9524 | | #endif /* CONFIG_TESTING_OPTIONS */ |
9525 | | |
9526 | 948 | if (wpa_s->driver->get_scan_results) |
9527 | 0 | scan_res = wpa_s->driver->get_scan_results(wpa_s->drv_priv, |
9528 | 0 | bssid); |
9529 | 948 | else if (wpa_s->driver->get_scan_results2) |
9530 | 0 | scan_res = wpa_s->driver->get_scan_results2(wpa_s->drv_priv); |
9531 | 948 | else |
9532 | 948 | return NULL; |
9533 | | |
9534 | | |
9535 | | #ifdef CONFIG_TESTING_OPTIONS |
9536 | | for (idx = 0; scan_res && idx < scan_res->num; idx++) { |
9537 | | struct driver_signal_override *dso; |
9538 | | struct wpa_scan_res *res = scan_res->res[idx]; |
9539 | | |
9540 | | dl_list_for_each(dso, &wpa_s->drv_signal_override, |
9541 | | struct driver_signal_override, list) { |
9542 | | if (!ether_addr_equal(res->bssid, dso->bssid)) |
9543 | | continue; |
9544 | | wpa_printf(MSG_DEBUG, |
9545 | | "Override driver scan signal level %d->%d for " |
9546 | | MACSTR, |
9547 | | res->level, dso->scan_level, |
9548 | | MAC2STR(res->bssid)); |
9549 | | res->flags |= WPA_SCAN_QUAL_INVALID; |
9550 | | if (dso->scan_level < 0) |
9551 | | res->flags |= WPA_SCAN_LEVEL_DBM; |
9552 | | else |
9553 | | res->flags &= ~WPA_SCAN_LEVEL_DBM; |
9554 | | res->level = dso->scan_level; |
9555 | | break; |
9556 | | } |
9557 | | } |
9558 | | #endif /* CONFIG_TESTING_OPTIONS */ |
9559 | | |
9560 | 0 | return scan_res; |
9561 | 948 | } |
9562 | | |
9563 | | |
9564 | | bool wpas_ap_link_address(struct wpa_supplicant *wpa_s, const u8 *addr) |
9565 | 0 | { |
9566 | 0 | int i; |
9567 | |
|
9568 | 0 | if (!wpa_s->valid_links) |
9569 | 0 | return false; |
9570 | | |
9571 | 0 | for_each_link(wpa_s->valid_links, i) { |
9572 | 0 | if (ether_addr_equal(wpa_s->links[i].bssid, addr)) |
9573 | 0 | return true; |
9574 | 0 | } |
9575 | | |
9576 | 0 | return false; |
9577 | 0 | } |
9578 | | |
9579 | | |
9580 | | int wpa_drv_send_action(struct wpa_supplicant *wpa_s, unsigned int freq, |
9581 | | unsigned int wait, const u8 *dst, const u8 *src, |
9582 | | const u8 *bssid, const u8 *data, size_t data_len, |
9583 | | int no_cck) |
9584 | 49 | { |
9585 | 49 | if (!wpa_s->driver->send_action) |
9586 | 49 | return -1; |
9587 | | |
9588 | 0 | if (data_len > 0 && data[0] != WLAN_ACTION_PUBLIC) { |
9589 | 0 | if (wpas_ap_link_address(wpa_s, dst)) |
9590 | 0 | dst = wpa_s->ap_mld_addr; |
9591 | |
|
9592 | 0 | if (wpas_ap_link_address(wpa_s, bssid)) |
9593 | 0 | bssid = wpa_s->ap_mld_addr; |
9594 | 0 | } |
9595 | |
|
9596 | 0 | return wpa_s->driver->send_action(wpa_s->drv_priv, freq, wait, dst, src, |
9597 | 0 | bssid, data, data_len, no_cck); |
9598 | 49 | } |
9599 | | |
9600 | | |
9601 | | bool wpas_is_6ghz_supported(struct wpa_supplicant *wpa_s, bool only_enabled) |
9602 | 0 | { |
9603 | 0 | struct hostapd_channel_data *chnl; |
9604 | 0 | int i, j; |
9605 | |
|
9606 | 0 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
9607 | 0 | if (wpa_s->hw.modes[i].mode == HOSTAPD_MODE_IEEE80211A) { |
9608 | 0 | chnl = wpa_s->hw.modes[i].channels; |
9609 | 0 | for (j = 0; j < wpa_s->hw.modes[i].num_channels; j++) { |
9610 | 0 | if (only_enabled && |
9611 | 0 | (chnl[j].flag & HOSTAPD_CHAN_DISABLED)) |
9612 | 0 | continue; |
9613 | 0 | if (is_6ghz_freq(chnl[j].freq)) |
9614 | 0 | return true; |
9615 | 0 | } |
9616 | 0 | } |
9617 | 0 | } |
9618 | | |
9619 | 0 | return false; |
9620 | 0 | } |
9621 | | |
9622 | | |
9623 | | bool wpas_ap_supports_rsn_overriding(struct wpa_supplicant *wpa_s, |
9624 | | struct wpa_bss *bss) |
9625 | 0 | { |
9626 | 0 | int i; |
9627 | |
|
9628 | 0 | if (!bss) |
9629 | 0 | return false; |
9630 | 0 | if (wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_IE_VENDOR_TYPE) || |
9631 | 0 | wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE)) |
9632 | 0 | return true; |
9633 | | |
9634 | 0 | if (!wpa_s->valid_links) |
9635 | 0 | return false; |
9636 | | |
9637 | 0 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
9638 | 0 | if (!(wpa_s->valid_links & BIT(i))) |
9639 | 0 | continue; |
9640 | 0 | if (wpa_s->links[i].bss && |
9641 | 0 | (wpa_bss_get_vendor_ie(wpa_s->links[i].bss, |
9642 | 0 | RSNE_OVERRIDE_IE_VENDOR_TYPE) || |
9643 | 0 | wpa_bss_get_vendor_ie(wpa_s->links[i].bss, |
9644 | 0 | RSNE_OVERRIDE_2_IE_VENDOR_TYPE))) |
9645 | 0 | return true; |
9646 | 0 | } |
9647 | | |
9648 | 0 | return false; |
9649 | 0 | } |
9650 | | |
9651 | | |
9652 | | bool wpas_ap_supports_rsn_overriding_2(struct wpa_supplicant *wpa_s, |
9653 | | struct wpa_bss *bss) |
9654 | 0 | { |
9655 | 0 | int i; |
9656 | |
|
9657 | 0 | if (!bss) |
9658 | 0 | return false; |
9659 | 0 | if (wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE)) |
9660 | 0 | return true; |
9661 | | |
9662 | 0 | if (!wpa_s->valid_links) |
9663 | 0 | return false; |
9664 | | |
9665 | 0 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
9666 | 0 | if (!(wpa_s->valid_links & BIT(i))) |
9667 | 0 | continue; |
9668 | 0 | if (wpa_s->links[i].bss && |
9669 | 0 | wpa_bss_get_vendor_ie(wpa_s->links[i].bss, |
9670 | 0 | RSNE_OVERRIDE_2_IE_VENDOR_TYPE)) |
9671 | 0 | return true; |
9672 | 0 | } |
9673 | | |
9674 | 0 | return false; |
9675 | 0 | } |