]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant | |
8c2715b3 | 3 | * Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
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" | |
2e997eec RM |
14 | #ifdef CONFIG_MATCH_IFACE |
15 | #include <net/if.h> | |
16 | #include <fnmatch.h> | |
17 | #endif /* CONFIG_MATCH_IFACE */ | |
6fc6879b JM |
18 | |
19 | #include "common.h" | |
d47fa330 | 20 | #include "crypto/random.h" |
7d232e23 | 21 | #include "crypto/sha1.h" |
6fc6879b JM |
22 | #include "eapol_supp/eapol_supp_sm.h" |
23 | #include "eap_peer/eap.h" | |
ec7b97ab | 24 | #include "eap_peer/eap_proxy.h" |
3ec97afe | 25 | #include "eap_server/eap_methods.h" |
3acb5005 | 26 | #include "rsn_supp/wpa.h" |
6fc6879b | 27 | #include "eloop.h" |
6fc6879b | 28 | #include "config.h" |
306ae225 | 29 | #include "utils/ext_password.h" |
6fc6879b JM |
30 | #include "l2_packet/l2_packet.h" |
31 | #include "wpa_supplicant_i.h" | |
2d5b792d | 32 | #include "driver_i.h" |
6fc6879b | 33 | #include "ctrl_iface.h" |
6fc6879b | 34 | #include "pcsc_funcs.h" |
90973fb2 | 35 | #include "common/version.h" |
3acb5005 JM |
36 | #include "rsn_supp/preauth.h" |
37 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 38 | #include "common/wpa_ctrl.h" |
90973fb2 | 39 | #include "common/ieee802_11_defs.h" |
6b8b0774 | 40 | #include "common/hw_features_common.h" |
461d39af | 41 | #include "common/gas_server.h" |
72044390 | 42 | #include "p2p/p2p.h" |
b36a3a65 | 43 | #include "fst/fst.h" |
6fc6879b JM |
44 | #include "blacklist.h" |
45 | #include "wpas_glue.h" | |
116654ce | 46 | #include "wps_supplicant.h" |
11ef8d35 | 47 | #include "ibss_rsn.h" |
c2a04078 | 48 | #include "sme.h" |
04ea7b79 | 49 | #include "gas_query.h" |
1f1b62a0 | 50 | #include "ap.h" |
b22128ef | 51 | #include "p2p_supplicant.h" |
9675ce35 | 52 | #include "wifi_display.h" |
8bac466b | 53 | #include "notify.h" |
60b94c98 | 54 | #include "bgscan.h" |
7c865c68 | 55 | #include "autoscan.h" |
83922c2d | 56 | #include "bss.h" |
9ba9fa07 | 57 | #include "scan.h" |
24f6497c | 58 | #include "offchannel.h" |
cb418324 | 59 | #include "hs20_supplicant.h" |
e27d20bb | 60 | #include "wnm_sta.h" |
dd10abcc | 61 | #include "wpas_kay.h" |
603a3f34 | 62 | #include "mesh.h" |
be27e185 | 63 | #include "dpp_supplicant.h" |
a39b040b SB |
64 | #ifdef CONFIG_MESH |
65 | #include "ap/ap_config.h" | |
66 | #include "ap/hostapd.h" | |
67 | #endif /* CONFIG_MESH */ | |
6fc6879b | 68 | |
8b423edb | 69 | const char *const wpa_supplicant_version = |
6fc6879b | 70 | "wpa_supplicant v" VERSION_STR "\n" |
c2c6c01b | 71 | "Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi> and contributors"; |
6fc6879b | 72 | |
8b423edb | 73 | const char *const wpa_supplicant_license = |
331f89ff JM |
74 | "This software may be distributed under the terms of the BSD license.\n" |
75 | "See README for more details.\n" | |
6fc6879b JM |
76 | #ifdef EAP_TLS_OPENSSL |
77 | "\nThis product includes software developed by the OpenSSL Project\n" | |
78 | "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n" | |
79 | #endif /* EAP_TLS_OPENSSL */ | |
80 | ; | |
81 | ||
82 | #ifndef CONFIG_NO_STDOUT_DEBUG | |
83 | /* Long text divided into parts in order to fit in C89 strings size limits. */ | |
8b423edb | 84 | const char *const wpa_supplicant_full_license1 = |
331f89ff | 85 | ""; |
8b423edb | 86 | const char *const wpa_supplicant_full_license2 = |
331f89ff | 87 | "This software may be distributed under the terms of the BSD license.\n" |
6fc6879b JM |
88 | "\n" |
89 | "Redistribution and use in source and binary forms, with or without\n" | |
90 | "modification, are permitted provided that the following conditions are\n" | |
91 | "met:\n" | |
92 | "\n"; | |
8b423edb | 93 | const char *const wpa_supplicant_full_license3 = |
6fc6879b JM |
94 | "1. Redistributions of source code must retain the above copyright\n" |
95 | " notice, this list of conditions and the following disclaimer.\n" | |
96 | "\n" | |
97 | "2. Redistributions in binary form must reproduce the above copyright\n" | |
98 | " notice, this list of conditions and the following disclaimer in the\n" | |
99 | " documentation and/or other materials provided with the distribution.\n" | |
100 | "\n"; | |
8b423edb | 101 | const char *const wpa_supplicant_full_license4 = |
6fc6879b JM |
102 | "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n" |
103 | " names of its contributors may be used to endorse or promote products\n" | |
104 | " derived from this software without specific prior written permission.\n" | |
105 | "\n" | |
106 | "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" | |
107 | "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" | |
108 | "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" | |
109 | "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"; | |
8b423edb | 110 | const char *const wpa_supplicant_full_license5 = |
6fc6879b JM |
111 | "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" |
112 | "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" | |
113 | "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" | |
114 | "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" | |
115 | "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" | |
116 | "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" | |
117 | "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" | |
118 | "\n"; | |
119 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
120 | ||
b04854ce AP |
121 | |
122 | static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx); | |
6338c99e VK |
123 | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
124 | static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s); | |
125 | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ | |
b04854ce AP |
126 | |
127 | ||
6fc6879b | 128 | /* Configure default/group WEP keys for static WEP */ |
0194fedb | 129 | int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
6fc6879b JM |
130 | { |
131 | int i, set = 0; | |
132 | ||
133 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
134 | if (ssid->wep_key_len[i] == 0) | |
135 | continue; | |
136 | ||
137 | set = 1; | |
0382097e | 138 | wpa_drv_set_key(wpa_s, WPA_ALG_WEP, NULL, |
da64c266 | 139 | i, i == ssid->wep_tx_keyidx, NULL, 0, |
6fc6879b JM |
140 | ssid->wep_key[i], ssid->wep_key_len[i]); |
141 | } | |
142 | ||
143 | return set; | |
144 | } | |
145 | ||
146 | ||
6ea1f413 JM |
147 | int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s, |
148 | struct wpa_ssid *ssid) | |
6fc6879b JM |
149 | { |
150 | u8 key[32]; | |
151 | size_t keylen; | |
71934751 | 152 | enum wpa_alg alg; |
6fc6879b | 153 | u8 seq[6] = { 0 }; |
658da804 | 154 | int ret; |
6fc6879b JM |
155 | |
156 | /* IBSS/WPA-None uses only one key (Group) for both receiving and | |
157 | * sending unicast and multicast packets. */ | |
158 | ||
d7dcba70 | 159 | if (ssid->mode != WPAS_MODE_IBSS) { |
f049052b BG |
160 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not " |
161 | "IBSS/ad-hoc) for WPA-None", ssid->mode); | |
6fc6879b JM |
162 | return -1; |
163 | } | |
164 | ||
165 | if (!ssid->psk_set) { | |
f049052b BG |
166 | wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for " |
167 | "WPA-None"); | |
6fc6879b JM |
168 | return -1; |
169 | } | |
170 | ||
171 | switch (wpa_s->group_cipher) { | |
172 | case WPA_CIPHER_CCMP: | |
173 | os_memcpy(key, ssid->psk, 16); | |
174 | keylen = 16; | |
175 | alg = WPA_ALG_CCMP; | |
176 | break; | |
eb7719ff JM |
177 | case WPA_CIPHER_GCMP: |
178 | os_memcpy(key, ssid->psk, 16); | |
179 | keylen = 16; | |
180 | alg = WPA_ALG_GCMP; | |
181 | break; | |
6fc6879b JM |
182 | case WPA_CIPHER_TKIP: |
183 | /* WPA-None uses the same Michael MIC key for both TX and RX */ | |
184 | os_memcpy(key, ssid->psk, 16 + 8); | |
185 | os_memcpy(key + 16 + 8, ssid->psk + 16, 8); | |
186 | keylen = 32; | |
187 | alg = WPA_ALG_TKIP; | |
188 | break; | |
189 | default: | |
f049052b BG |
190 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for " |
191 | "WPA-None", wpa_s->group_cipher); | |
6fc6879b JM |
192 | return -1; |
193 | } | |
194 | ||
195 | /* TODO: should actually remember the previously used seq#, both for TX | |
196 | * and RX from each STA.. */ | |
197 | ||
658da804 JM |
198 | ret = wpa_drv_set_key(wpa_s, alg, NULL, 0, 1, seq, 6, key, keylen); |
199 | os_memset(key, 0, sizeof(key)); | |
200 | return ret; | |
6fc6879b JM |
201 | } |
202 | ||
203 | ||
204 | static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx) | |
205 | { | |
206 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
207 | const u8 *bssid = wpa_s->bssid; | |
04e3d815 MK |
208 | if (!is_zero_ether_addr(wpa_s->pending_bssid) && |
209 | (wpa_s->wpa_state == WPA_AUTHENTICATING || | |
210 | wpa_s->wpa_state == WPA_ASSOCIATING)) | |
6fc6879b JM |
211 | bssid = wpa_s->pending_bssid; |
212 | wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.", | |
213 | MAC2STR(bssid)); | |
214 | wpa_blacklist_add(wpa_s, bssid); | |
215 | wpa_sm_notify_disassoc(wpa_s->wpa); | |
07783eaa | 216 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
6fc6879b | 217 | wpa_s->reassociate = 1; |
48b84f18 BG |
218 | |
219 | /* | |
220 | * If we timed out, the AP or the local radio may be busy. | |
221 | * So, wait a second until scanning again. | |
222 | */ | |
223 | wpa_supplicant_req_scan(wpa_s, 1, 0); | |
6fc6879b JM |
224 | } |
225 | ||
226 | ||
227 | /** | |
228 | * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication | |
229 | * @wpa_s: Pointer to wpa_supplicant data | |
230 | * @sec: Number of seconds after which to time out authentication | |
231 | * @usec: Number of microseconds after which to time out authentication | |
232 | * | |
233 | * This function is used to schedule a timeout for the current authentication | |
234 | * attempt. | |
235 | */ | |
236 | void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s, | |
237 | int sec, int usec) | |
238 | { | |
a2a535f8 | 239 | if (wpa_s->conf->ap_scan == 0 && |
c2a04078 | 240 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) |
6fc6879b JM |
241 | return; |
242 | ||
f049052b | 243 | wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec " |
6fc6879b JM |
244 | "%d usec", sec, usec); |
245 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); | |
37547ad6 | 246 | wpa_s->last_auth_timeout_sec = sec; |
6fc6879b JM |
247 | eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL); |
248 | } | |
249 | ||
250 | ||
37547ad6 DL |
251 | /* |
252 | * wpas_auth_timeout_restart - Restart and change timeout for authentication | |
253 | * @wpa_s: Pointer to wpa_supplicant data | |
254 | * @sec_diff: difference in seconds applied to original timeout value | |
255 | */ | |
256 | void wpas_auth_timeout_restart(struct wpa_supplicant *wpa_s, int sec_diff) | |
257 | { | |
258 | int new_sec = wpa_s->last_auth_timeout_sec + sec_diff; | |
259 | ||
260 | if (eloop_is_timeout_registered(wpa_supplicant_timeout, wpa_s, NULL)) { | |
261 | wpa_dbg(wpa_s, MSG_DEBUG, | |
262 | "Authentication timeout restart: %d sec", new_sec); | |
263 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); | |
264 | eloop_register_timeout(new_sec, 0, wpa_supplicant_timeout, | |
265 | wpa_s, NULL); | |
266 | } | |
267 | } | |
268 | ||
269 | ||
6fc6879b JM |
270 | /** |
271 | * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout | |
272 | * @wpa_s: Pointer to wpa_supplicant data | |
273 | * | |
274 | * This function is used to cancel authentication timeout scheduled with | |
275 | * wpa_supplicant_req_auth_timeout() and it is called when authentication has | |
276 | * been completed. | |
277 | */ | |
278 | void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s) | |
279 | { | |
f049052b | 280 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout"); |
6fc6879b JM |
281 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
282 | wpa_blacklist_del(wpa_s, wpa_s->bssid); | |
af835d75 AB |
283 | os_free(wpa_s->last_con_fail_realm); |
284 | wpa_s->last_con_fail_realm = NULL; | |
285 | wpa_s->last_con_fail_realm_len = 0; | |
6fc6879b JM |
286 | } |
287 | ||
288 | ||
289 | /** | |
290 | * wpa_supplicant_initiate_eapol - Configure EAPOL state machine | |
291 | * @wpa_s: Pointer to wpa_supplicant data | |
292 | * | |
293 | * This function is used to configure EAPOL state machine based on the selected | |
294 | * authentication mode. | |
295 | */ | |
296 | void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s) | |
297 | { | |
298 | #ifdef IEEE8021X_EAPOL | |
299 | struct eapol_config eapol_conf; | |
300 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
301 | ||
53895c3b | 302 | #ifdef CONFIG_IBSS_RSN |
d7dcba70 | 303 | if (ssid->mode == WPAS_MODE_IBSS && |
53895c3b JM |
304 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
305 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { | |
306 | /* | |
307 | * RSN IBSS authentication is per-STA and we can disable the | |
308 | * per-BSSID EAPOL authentication. | |
309 | */ | |
310 | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); | |
311 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
312 | eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE); | |
313 | return; | |
314 | } | |
315 | #endif /* CONFIG_IBSS_RSN */ | |
316 | ||
0a40ec6a JM |
317 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
318 | eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE); | |
319 | ||
6fc6879b JM |
320 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
321 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
322 | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); | |
323 | else | |
324 | eapol_sm_notify_portControl(wpa_s->eapol, Auto); | |
325 | ||
326 | os_memset(&eapol_conf, 0, sizeof(eapol_conf)); | |
327 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
328 | eapol_conf.accept_802_1x_keys = 1; | |
329 | eapol_conf.required_keys = 0; | |
330 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) { | |
331 | eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST; | |
332 | } | |
333 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) { | |
334 | eapol_conf.required_keys |= | |
335 | EAPOL_REQUIRE_KEY_BROADCAST; | |
336 | } | |
337 | ||
a2a535f8 | 338 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED) |
6fc6879b | 339 | eapol_conf.required_keys = 0; |
6fc6879b | 340 | } |
a2a535f8 | 341 | eapol_conf.fast_reauth = wpa_s->conf->fast_reauth; |
6fc6879b | 342 | eapol_conf.workaround = ssid->eap_workaround; |
56586197 JM |
343 | eapol_conf.eap_disabled = |
344 | !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) && | |
ad08c363 JM |
345 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
346 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPS; | |
a5d44ac0 | 347 | eapol_conf.external_sim = wpa_s->conf->external_sim; |
3f7ac058 JS |
348 | |
349 | #ifdef CONFIG_WPS | |
350 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
351 | eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE; | |
352 | if (wpa_s->current_bss) { | |
353 | struct wpabuf *ie; | |
354 | ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss, | |
355 | WPS_IE_VENDOR_TYPE); | |
356 | if (ie) { | |
357 | if (wps_is_20(ie)) | |
358 | eapol_conf.wps |= | |
359 | EAPOL_PEER_IS_WPS20_AP; | |
360 | wpabuf_free(ie); | |
361 | } | |
362 | } | |
363 | } | |
364 | #endif /* CONFIG_WPS */ | |
365 | ||
6fc6879b | 366 | eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf); |
dd10abcc | 367 | |
ad51731a SD |
368 | #ifdef CONFIG_MACSEC |
369 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE && ssid->mka_psk_set) | |
370 | ieee802_1x_create_preshared_mka(wpa_s, ssid); | |
371 | else | |
372 | ieee802_1x_alloc_kay_sm(wpa_s, ssid); | |
373 | #endif /* CONFIG_MACSEC */ | |
cd3153a9 | 374 | #endif /* IEEE8021X_EAPOL */ |
6fc6879b JM |
375 | } |
376 | ||
377 | ||
378 | /** | |
379 | * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode | |
380 | * @wpa_s: Pointer to wpa_supplicant data | |
381 | * @ssid: Configuration data for the network | |
382 | * | |
383 | * This function is used to configure WPA state machine and related parameters | |
384 | * to a mode where WPA is not enabled. This is called as part of the | |
385 | * authentication configuration when the selected network does not use WPA. | |
386 | */ | |
387 | void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s, | |
388 | struct wpa_ssid *ssid) | |
389 | { | |
390 | int i; | |
391 | ||
ad08c363 JM |
392 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
393 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPS; | |
394 | else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) | |
6fc6879b JM |
395 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; |
396 | else | |
397 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; | |
398 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
399 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
400 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
401 | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; | |
402 | wpa_s->group_cipher = WPA_CIPHER_NONE; | |
403 | wpa_s->mgmt_group_cipher = 0; | |
404 | ||
405 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
406 | if (ssid->wep_key_len[i] > 5) { | |
407 | wpa_s->pairwise_cipher = WPA_CIPHER_WEP104; | |
408 | wpa_s->group_cipher = WPA_CIPHER_WEP104; | |
409 | break; | |
410 | } else if (ssid->wep_key_len[i] > 0) { | |
411 | wpa_s->pairwise_cipher = WPA_CIPHER_WEP40; | |
412 | wpa_s->group_cipher = WPA_CIPHER_WEP40; | |
413 | break; | |
414 | } | |
415 | } | |
416 | ||
417 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0); | |
418 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); | |
419 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, | |
420 | wpa_s->pairwise_cipher); | |
421 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); | |
422 | #ifdef CONFIG_IEEE80211W | |
423 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, | |
424 | wpa_s->mgmt_group_cipher); | |
425 | #endif /* CONFIG_IEEE80211W */ | |
426 | ||
427 | pmksa_cache_clear_current(wpa_s->wpa); | |
428 | } | |
429 | ||
430 | ||
6979582c | 431 | void free_hw_features(struct wpa_supplicant *wpa_s) |
6bf731e8 CL |
432 | { |
433 | int i; | |
434 | if (wpa_s->hw.modes == NULL) | |
435 | return; | |
436 | ||
437 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
438 | os_free(wpa_s->hw.modes[i].channels); | |
439 | os_free(wpa_s->hw.modes[i].rates); | |
440 | } | |
441 | ||
442 | os_free(wpa_s->hw.modes); | |
443 | wpa_s->hw.modes = NULL; | |
444 | } | |
445 | ||
446 | ||
dd599908 AS |
447 | static void free_bss_tmp_disallowed(struct wpa_supplicant *wpa_s) |
448 | { | |
449 | struct wpa_bss_tmp_disallowed *bss, *prev; | |
450 | ||
451 | dl_list_for_each_safe(bss, prev, &wpa_s->bss_tmp_disallowed, | |
452 | struct wpa_bss_tmp_disallowed, list) { | |
b04854ce | 453 | eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss); |
dd599908 AS |
454 | dl_list_del(&bss->list); |
455 | os_free(bss); | |
456 | } | |
457 | } | |
458 | ||
459 | ||
5732b770 JM |
460 | void wpas_flush_fils_hlp_req(struct wpa_supplicant *wpa_s) |
461 | { | |
462 | struct fils_hlp_req *req; | |
463 | ||
464 | while ((req = dl_list_first(&wpa_s->fils_hlp_req, struct fils_hlp_req, | |
465 | list)) != NULL) { | |
466 | dl_list_del(&req->list); | |
467 | wpabuf_free(req->pkt); | |
468 | os_free(req); | |
469 | } | |
470 | } | |
471 | ||
472 | ||
6fc6879b JM |
473 | static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s) |
474 | { | |
86bd36f0 JM |
475 | int i; |
476 | ||
60b94c98 | 477 | bgscan_deinit(wpa_s); |
7c865c68 | 478 | autoscan_deinit(wpa_s); |
6fc6879b JM |
479 | scard_deinit(wpa_s->scard); |
480 | wpa_s->scard = NULL; | |
481 | wpa_sm_set_scard_ctx(wpa_s->wpa, NULL); | |
482 | eapol_sm_register_scard_ctx(wpa_s->eapol, NULL); | |
483 | l2_packet_deinit(wpa_s->l2); | |
484 | wpa_s->l2 = NULL; | |
485 | if (wpa_s->l2_br) { | |
486 | l2_packet_deinit(wpa_s->l2_br); | |
487 | wpa_s->l2_br = NULL; | |
488 | } | |
4a6cc862 JM |
489 | #ifdef CONFIG_TESTING_OPTIONS |
490 | l2_packet_deinit(wpa_s->l2_test); | |
491 | wpa_s->l2_test = NULL; | |
c06fca04 JM |
492 | os_free(wpa_s->get_pref_freq_list_override); |
493 | wpa_s->get_pref_freq_list_override = NULL; | |
daa40960 JM |
494 | wpabuf_free(wpa_s->last_assoc_req_wpa_ie); |
495 | wpa_s->last_assoc_req_wpa_ie = NULL; | |
4a6cc862 | 496 | #endif /* CONFIG_TESTING_OPTIONS */ |
6fc6879b | 497 | |
6fc6879b | 498 | if (wpa_s->conf != NULL) { |
8e56d189 JM |
499 | struct wpa_ssid *ssid; |
500 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) | |
501 | wpas_notify_network_removed(wpa_s, ssid); | |
6fc6879b JM |
502 | } |
503 | ||
504 | os_free(wpa_s->confname); | |
505 | wpa_s->confname = NULL; | |
506 | ||
e6304cad DS |
507 | os_free(wpa_s->confanother); |
508 | wpa_s->confanother = NULL; | |
509 | ||
af835d75 AB |
510 | os_free(wpa_s->last_con_fail_realm); |
511 | wpa_s->last_con_fail_realm = NULL; | |
512 | wpa_s->last_con_fail_realm_len = 0; | |
513 | ||
6fc6879b JM |
514 | wpa_sm_set_eapol(wpa_s->wpa, NULL); |
515 | eapol_sm_deinit(wpa_s->eapol); | |
516 | wpa_s->eapol = NULL; | |
517 | ||
518 | rsn_preauth_deinit(wpa_s->wpa); | |
519 | ||
281ff0aa GP |
520 | #ifdef CONFIG_TDLS |
521 | wpa_tdls_deinit(wpa_s->wpa); | |
522 | #endif /* CONFIG_TDLS */ | |
523 | ||
8c42b369 | 524 | wmm_ac_clear_saved_tspecs(wpa_s); |
6fc6879b JM |
525 | pmksa_candidate_free(wpa_s->wpa); |
526 | wpa_sm_deinit(wpa_s->wpa); | |
527 | wpa_s->wpa = NULL; | |
528 | wpa_blacklist_clear(wpa_s); | |
529 | ||
83922c2d | 530 | wpa_bss_deinit(wpa_s); |
6fc6879b | 531 | |
831770bf | 532 | wpa_supplicant_cancel_delayed_sched_scan(wpa_s); |
6fc6879b JM |
533 | wpa_supplicant_cancel_scan(wpa_s); |
534 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
01a17491 JM |
535 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
536 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
537 | eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report, | |
538 | wpa_s, NULL); | |
539 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b | 540 | |
9bd566a3 AS |
541 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
542 | ||
116654ce | 543 | wpas_wps_deinit(wpa_s); |
11ef8d35 | 544 | |
1ff73338 JM |
545 | wpabuf_free(wpa_s->pending_eapol_rx); |
546 | wpa_s->pending_eapol_rx = NULL; | |
547 | ||
11ef8d35 JM |
548 | #ifdef CONFIG_IBSS_RSN |
549 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
550 | wpa_s->ibss_rsn = NULL; | |
551 | #endif /* CONFIG_IBSS_RSN */ | |
c2a04078 | 552 | |
e29853bb | 553 | sme_deinit(wpa_s); |
2d5b792d JM |
554 | |
555 | #ifdef CONFIG_AP | |
556 | wpa_supplicant_ap_deinit(wpa_s); | |
557 | #endif /* CONFIG_AP */ | |
b22128ef | 558 | |
b22128ef | 559 | wpas_p2p_deinit(wpa_s); |
f47d639d | 560 | |
24f6497c JM |
561 | #ifdef CONFIG_OFFCHANNEL |
562 | offchannel_deinit(wpa_s); | |
563 | #endif /* CONFIG_OFFCHANNEL */ | |
564 | ||
a4cba8f1 LC |
565 | wpa_supplicant_cancel_sched_scan(wpa_s); |
566 | ||
f47d639d JM |
567 | os_free(wpa_s->next_scan_freqs); |
568 | wpa_s->next_scan_freqs = NULL; | |
fee52342 JM |
569 | |
570 | os_free(wpa_s->manual_scan_freqs); | |
571 | wpa_s->manual_scan_freqs = NULL; | |
88a44755 JM |
572 | os_free(wpa_s->select_network_scan_freqs); |
573 | wpa_s->select_network_scan_freqs = NULL; | |
04ea7b79 | 574 | |
d3c9c35f DS |
575 | os_free(wpa_s->manual_sched_scan_freqs); |
576 | wpa_s->manual_sched_scan_freqs = NULL; | |
577 | ||
56c76fa5 IP |
578 | wpas_mac_addr_rand_scan_clear(wpa_s, MAC_ADDR_RAND_ALL); |
579 | ||
57e832de IP |
580 | /* |
581 | * Need to remove any pending gas-query radio work before the | |
582 | * gas_query_deinit() call because gas_query::work has not yet been set | |
583 | * for works that have not been started. gas_query_free() will be unable | |
584 | * to cancel such pending radio works and once the pending gas-query | |
585 | * radio work eventually gets removed, the deinit notification call to | |
586 | * gas_query_start_cb() would result in dereferencing freed memory. | |
587 | */ | |
588 | if (wpa_s->radio) | |
589 | radio_remove_works(wpa_s, "gas-query", 0); | |
04ea7b79 JM |
590 | gas_query_deinit(wpa_s->gas); |
591 | wpa_s->gas = NULL; | |
461d39af JM |
592 | gas_server_deinit(wpa_s->gas_server); |
593 | wpa_s->gas_server = NULL; | |
6bf731e8 CL |
594 | |
595 | free_hw_features(wpa_s); | |
d445a5cd | 596 | |
dd10abcc HW |
597 | ieee802_1x_dealloc_kay_sm(wpa_s); |
598 | ||
d445a5cd JM |
599 | os_free(wpa_s->bssid_filter); |
600 | wpa_s->bssid_filter = NULL; | |
b6668734 | 601 | |
6407f413 JM |
602 | os_free(wpa_s->disallow_aps_bssid); |
603 | wpa_s->disallow_aps_bssid = NULL; | |
604 | os_free(wpa_s->disallow_aps_ssid); | |
605 | wpa_s->disallow_aps_ssid = NULL; | |
606 | ||
b6668734 | 607 | wnm_bss_keep_alive_deinit(wpa_s); |
e27d20bb VK |
608 | #ifdef CONFIG_WNM |
609 | wnm_deallocate_memory(wpa_s); | |
610 | #endif /* CONFIG_WNM */ | |
306ae225 JM |
611 | |
612 | ext_password_deinit(wpa_s->ext_pw); | |
613 | wpa_s->ext_pw = NULL; | |
b1f12296 JM |
614 | |
615 | wpabuf_free(wpa_s->last_gas_resp); | |
b6a9590b JM |
616 | wpa_s->last_gas_resp = NULL; |
617 | wpabuf_free(wpa_s->prev_gas_resp); | |
618 | wpa_s->prev_gas_resp = NULL; | |
a297201d JM |
619 | |
620 | os_free(wpa_s->last_scan_res); | |
621 | wpa_s->last_scan_res = NULL; | |
b572df86 JM |
622 | |
623 | #ifdef CONFIG_HS20 | |
ece4ac5f MG |
624 | if (wpa_s->drv_priv) |
625 | wpa_drv_configure_frame_filters(wpa_s, 0); | |
fb2ac53d | 626 | hs20_deinit(wpa_s); |
b572df86 | 627 | #endif /* CONFIG_HS20 */ |
86bd36f0 JM |
628 | |
629 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { | |
630 | wpabuf_free(wpa_s->vendor_elem[i]); | |
631 | wpa_s->vendor_elem[i] = NULL; | |
632 | } | |
3882a708 JM |
633 | |
634 | wmm_ac_notify_disassoc(wpa_s); | |
32c02261 AS |
635 | |
636 | wpa_s->sched_scan_plans_num = 0; | |
637 | os_free(wpa_s->sched_scan_plans); | |
638 | wpa_s->sched_scan_plans = NULL; | |
92c6e2e3 DS |
639 | |
640 | #ifdef CONFIG_MBO | |
641 | wpa_s->non_pref_chan_num = 0; | |
642 | os_free(wpa_s->non_pref_chan); | |
643 | wpa_s->non_pref_chan = NULL; | |
644 | #endif /* CONFIG_MBO */ | |
dd599908 AS |
645 | |
646 | free_bss_tmp_disallowed(wpa_s); | |
4a742011 DS |
647 | |
648 | wpabuf_free(wpa_s->lci); | |
649 | wpa_s->lci = NULL; | |
76196ddb | 650 | wpas_clear_beacon_rep_data(wpa_s); |
4d77d80e MH |
651 | |
652 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL | |
653 | #ifdef CONFIG_MESH | |
654 | { | |
655 | struct external_pmksa_cache *entry; | |
656 | ||
657 | while ((entry = dl_list_last(&wpa_s->mesh_external_pmksa_cache, | |
658 | struct external_pmksa_cache, | |
659 | list)) != NULL) { | |
660 | dl_list_del(&entry->list); | |
661 | os_free(entry->pmksa_cache); | |
662 | os_free(entry); | |
663 | } | |
664 | } | |
665 | #endif /* CONFIG_MESH */ | |
666 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ | |
5732b770 JM |
667 | |
668 | wpas_flush_fils_hlp_req(wpa_s); | |
c6c41f6e JM |
669 | |
670 | wpabuf_free(wpa_s->ric_ies); | |
671 | wpa_s->ric_ies = NULL; | |
be27e185 JM |
672 | |
673 | #ifdef CONFIG_DPP | |
674 | wpas_dpp_deinit(wpa_s); | |
675 | #endif /* CONFIG_DPP */ | |
6fc6879b JM |
676 | } |
677 | ||
678 | ||
679 | /** | |
680 | * wpa_clear_keys - Clear keys configured for the driver | |
681 | * @wpa_s: Pointer to wpa_supplicant data | |
682 | * @addr: Previously used BSSID or %NULL if not available | |
683 | * | |
684 | * This function clears the encryption keys that has been previously configured | |
685 | * for the driver. | |
686 | */ | |
687 | void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr) | |
688 | { | |
2f30cac3 | 689 | int i, max; |
6fc6879b | 690 | |
0e27f655 | 691 | #ifdef CONFIG_IEEE80211W |
2f30cac3 JM |
692 | max = 6; |
693 | #else /* CONFIG_IEEE80211W */ | |
694 | max = 4; | |
0e27f655 | 695 | #endif /* CONFIG_IEEE80211W */ |
2f30cac3 JM |
696 | |
697 | /* MLME-DELETEKEYS.request */ | |
698 | for (i = 0; i < max; i++) { | |
699 | if (wpa_s->keys_cleared & BIT(i)) | |
700 | continue; | |
701 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, i, 0, NULL, 0, | |
702 | NULL, 0); | |
703 | } | |
704 | if (!(wpa_s->keys_cleared & BIT(0)) && addr && | |
705 | !is_zero_ether_addr(addr)) { | |
6fc6879b JM |
706 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL, |
707 | 0); | |
708 | /* MLME-SETPROTECTION.request(None) */ | |
709 | wpa_drv_mlme_setprotection( | |
710 | wpa_s, addr, | |
711 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, | |
712 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); | |
713 | } | |
2f30cac3 | 714 | wpa_s->keys_cleared = (u32) -1; |
6fc6879b JM |
715 | } |
716 | ||
717 | ||
718 | /** | |
719 | * wpa_supplicant_state_txt - Get the connection state name as a text string | |
720 | * @state: State (wpa_state; WPA_*) | |
721 | * Returns: The state name as a printable text string | |
722 | */ | |
71934751 | 723 | const char * wpa_supplicant_state_txt(enum wpa_states state) |
6fc6879b JM |
724 | { |
725 | switch (state) { | |
726 | case WPA_DISCONNECTED: | |
727 | return "DISCONNECTED"; | |
728 | case WPA_INACTIVE: | |
729 | return "INACTIVE"; | |
8401a6b0 JM |
730 | case WPA_INTERFACE_DISABLED: |
731 | return "INTERFACE_DISABLED"; | |
6fc6879b JM |
732 | case WPA_SCANNING: |
733 | return "SCANNING"; | |
c2a04078 JM |
734 | case WPA_AUTHENTICATING: |
735 | return "AUTHENTICATING"; | |
6fc6879b JM |
736 | case WPA_ASSOCIATING: |
737 | return "ASSOCIATING"; | |
738 | case WPA_ASSOCIATED: | |
739 | return "ASSOCIATED"; | |
740 | case WPA_4WAY_HANDSHAKE: | |
741 | return "4WAY_HANDSHAKE"; | |
742 | case WPA_GROUP_HANDSHAKE: | |
743 | return "GROUP_HANDSHAKE"; | |
744 | case WPA_COMPLETED: | |
745 | return "COMPLETED"; | |
746 | default: | |
747 | return "UNKNOWN"; | |
748 | } | |
749 | } | |
750 | ||
751 | ||
cfe53c9a PS |
752 | #ifdef CONFIG_BGSCAN |
753 | ||
754 | static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s) | |
755 | { | |
31392709 HD |
756 | const char *name; |
757 | ||
758 | if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) | |
759 | name = wpa_s->current_ssid->bgscan; | |
760 | else | |
761 | name = wpa_s->conf->bgscan; | |
268043d5 | 762 | if (name == NULL || name[0] == '\0') |
31392709 | 763 | return; |
0096c427 JM |
764 | if (wpas_driver_bss_selection(wpa_s)) |
765 | return; | |
cfe53c9a PS |
766 | if (wpa_s->current_ssid == wpa_s->bgscan_ssid) |
767 | return; | |
aa109830 DS |
768 | #ifdef CONFIG_P2P |
769 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) | |
770 | return; | |
771 | #endif /* CONFIG_P2P */ | |
cfe53c9a PS |
772 | |
773 | bgscan_deinit(wpa_s); | |
31392709 HD |
774 | if (wpa_s->current_ssid) { |
775 | if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) { | |
cfe53c9a PS |
776 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " |
777 | "bgscan"); | |
778 | /* | |
779 | * Live without bgscan; it is only used as a roaming | |
780 | * optimization, so the initial connection is not | |
781 | * affected. | |
782 | */ | |
6409b7a7 YD |
783 | } else { |
784 | struct wpa_scan_results *scan_res; | |
cfe53c9a | 785 | wpa_s->bgscan_ssid = wpa_s->current_ssid; |
6409b7a7 YD |
786 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, |
787 | 0); | |
788 | if (scan_res) { | |
789 | bgscan_notify_scan(wpa_s, scan_res); | |
790 | wpa_scan_results_free(scan_res); | |
791 | } | |
792 | } | |
cfe53c9a PS |
793 | } else |
794 | wpa_s->bgscan_ssid = NULL; | |
795 | } | |
796 | ||
797 | ||
798 | static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) | |
799 | { | |
800 | if (wpa_s->bgscan_ssid != NULL) { | |
801 | bgscan_deinit(wpa_s); | |
802 | wpa_s->bgscan_ssid = NULL; | |
803 | } | |
804 | } | |
805 | ||
806 | #endif /* CONFIG_BGSCAN */ | |
807 | ||
808 | ||
7c865c68 TB |
809 | static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s) |
810 | { | |
99218999 | 811 | if (autoscan_init(wpa_s, 0)) |
7c865c68 TB |
812 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan"); |
813 | } | |
814 | ||
815 | ||
816 | static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s) | |
817 | { | |
818 | autoscan_deinit(wpa_s); | |
819 | } | |
820 | ||
821 | ||
c3d12238 JM |
822 | void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s) |
823 | { | |
824 | if (wpa_s->wpa_state == WPA_DISCONNECTED || | |
825 | wpa_s->wpa_state == WPA_SCANNING) { | |
826 | autoscan_deinit(wpa_s); | |
827 | wpa_supplicant_start_autoscan(wpa_s); | |
828 | } | |
829 | } | |
830 | ||
831 | ||
6fc6879b JM |
832 | /** |
833 | * wpa_supplicant_set_state - Set current connection state | |
834 | * @wpa_s: Pointer to wpa_supplicant data | |
835 | * @state: The new connection state | |
836 | * | |
837 | * This function is called whenever the connection state changes, e.g., | |
838 | * association is completed for WPA/WPA2 4-Way Handshake is started. | |
839 | */ | |
71934751 JM |
840 | void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, |
841 | enum wpa_states state) | |
6fc6879b | 842 | { |
27f43d8d MH |
843 | enum wpa_states old_state = wpa_s->wpa_state; |
844 | ||
f049052b BG |
845 | wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s", |
846 | wpa_supplicant_state_txt(wpa_s->wpa_state), | |
847 | wpa_supplicant_state_txt(state)); | |
6fc6879b | 848 | |
5ddd07cb AS |
849 | if (state == WPA_INTERFACE_DISABLED) { |
850 | /* Assure normal scan when interface is restored */ | |
851 | wpa_s->normal_scans = 0; | |
852 | } | |
853 | ||
0cf24fda | 854 | if (state == WPA_COMPLETED) { |
6ac4b15e | 855 | wpas_connect_work_done(wpa_s); |
0cf24fda LC |
856 | /* Reinitialize normal_scan counter */ |
857 | wpa_s->normal_scans = 0; | |
858 | } | |
6ac4b15e | 859 | |
07c1e987 MS |
860 | #ifdef CONFIG_P2P |
861 | /* | |
862 | * P2PS client has to reply to Probe Request frames received on the | |
863 | * group operating channel. Enable Probe Request frame reporting for | |
864 | * P2P connected client in case p2p_cli_probe configuration property is | |
865 | * set to 1. | |
866 | */ | |
867 | if (wpa_s->conf->p2p_cli_probe && wpa_s->current_ssid && | |
868 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
869 | wpa_s->current_ssid->p2p_group) { | |
870 | if (state == WPA_COMPLETED && !wpa_s->p2p_cli_probe) { | |
871 | wpa_dbg(wpa_s, MSG_DEBUG, | |
872 | "P2P: Enable CLI Probe Request RX reporting"); | |
873 | wpa_s->p2p_cli_probe = | |
874 | wpa_drv_probe_req_report(wpa_s, 1) >= 0; | |
875 | } else if (state != WPA_COMPLETED && wpa_s->p2p_cli_probe) { | |
876 | wpa_dbg(wpa_s, MSG_DEBUG, | |
877 | "P2P: Disable CLI Probe Request RX reporting"); | |
878 | wpa_s->p2p_cli_probe = 0; | |
879 | wpa_drv_probe_req_report(wpa_s, 0); | |
880 | } | |
881 | } | |
882 | #endif /* CONFIG_P2P */ | |
883 | ||
cb8564b1 DW |
884 | if (state != WPA_SCANNING) |
885 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
886 | ||
6fc6879b | 887 | if (state == WPA_COMPLETED && wpa_s->new_connection) { |
6fc6879b | 888 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
da6a28ba VK |
889 | int fils_hlp_sent = 0; |
890 | ||
891 | #ifdef CONFIG_SME | |
892 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
893 | wpa_auth_alg_fils(wpa_s->sme.auth_alg)) | |
894 | fils_hlp_sent = 1; | |
895 | #endif /* CONFIG_SME */ | |
896 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
897 | wpa_auth_alg_fils(wpa_s->auth_alg)) | |
898 | fils_hlp_sent = 1; | |
899 | ||
7d37a357 | 900 | #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) |
6fc6879b | 901 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to " |
da6a28ba | 902 | MACSTR " completed [id=%d id_str=%s%s]", |
1cfc6787 | 903 | MAC2STR(wpa_s->bssid), |
6fc6879b | 904 | ssid ? ssid->id : -1, |
da6a28ba VK |
905 | ssid && ssid->id_str ? ssid->id_str : "", |
906 | fils_hlp_sent ? " FILS_HLP_SENT" : ""); | |
6fc6879b | 907 | #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
00e5e3d5 | 908 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
a20a3616 | 909 | wpa_blacklist_clear(wpa_s); |
f1a52633 | 910 | wpa_s->extra_blacklist_count = 0; |
6fc6879b | 911 | wpa_s->new_connection = 0; |
6fc6879b | 912 | wpa_drv_set_operstate(wpa_s, 1); |
99ac2913 FF |
913 | #ifndef IEEE8021X_EAPOL |
914 | wpa_drv_set_supp_port(wpa_s, 1); | |
915 | #endif /* IEEE8021X_EAPOL */ | |
17a4734d | 916 | wpa_s->after_wps = 0; |
4d9fb08d | 917 | wpa_s->known_wps_freq = 0; |
b22128ef | 918 | wpas_p2p_completed(wpa_s); |
c3701c66 RM |
919 | |
920 | sme_sched_obss_scan(wpa_s, 1); | |
6338c99e VK |
921 | |
922 | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) | |
923 | if (!fils_hlp_sent && ssid && ssid->eap.erp) | |
924 | wpas_update_fils_connect_params(wpa_s); | |
925 | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ | |
6fc6879b JM |
926 | } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING || |
927 | state == WPA_ASSOCIATED) { | |
928 | wpa_s->new_connection = 1; | |
929 | wpa_drv_set_operstate(wpa_s, 0); | |
99ac2913 FF |
930 | #ifndef IEEE8021X_EAPOL |
931 | wpa_drv_set_supp_port(wpa_s, 0); | |
932 | #endif /* IEEE8021X_EAPOL */ | |
c3701c66 | 933 | sme_sched_obss_scan(wpa_s, 0); |
6fc6879b JM |
934 | } |
935 | wpa_s->wpa_state = state; | |
27f43d8d | 936 | |
cfe53c9a PS |
937 | #ifdef CONFIG_BGSCAN |
938 | if (state == WPA_COMPLETED) | |
939 | wpa_supplicant_start_bgscan(wpa_s); | |
37271232 | 940 | else if (state < WPA_ASSOCIATED) |
cfe53c9a PS |
941 | wpa_supplicant_stop_bgscan(wpa_s); |
942 | #endif /* CONFIG_BGSCAN */ | |
943 | ||
7c865c68 TB |
944 | if (state == WPA_AUTHENTICATING) |
945 | wpa_supplicant_stop_autoscan(wpa_s); | |
946 | ||
947 | if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) | |
948 | wpa_supplicant_start_autoscan(wpa_s); | |
949 | ||
fecc2bb5 EP |
950 | if (old_state >= WPA_ASSOCIATED && wpa_s->wpa_state < WPA_ASSOCIATED) |
951 | wmm_ac_notify_disassoc(wpa_s); | |
952 | ||
5bbf9f10 | 953 | if (wpa_s->wpa_state != old_state) { |
27f43d8d | 954 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); |
5bbf9f10 | 955 | |
e3bd6e9d IP |
956 | /* |
957 | * Notify the P2P Device interface about a state change in one | |
958 | * of the interfaces. | |
959 | */ | |
960 | wpas_p2p_indicate_state_change(wpa_s); | |
e3bd6e9d | 961 | |
5bbf9f10 PS |
962 | if (wpa_s->wpa_state == WPA_COMPLETED || |
963 | old_state == WPA_COMPLETED) | |
964 | wpas_notify_auth_changed(wpa_s); | |
965 | } | |
6fc6879b JM |
966 | } |
967 | ||
968 | ||
1a1bf008 JM |
969 | void wpa_supplicant_terminate_proc(struct wpa_global *global) |
970 | { | |
971 | int pending = 0; | |
972 | #ifdef CONFIG_WPS | |
973 | struct wpa_supplicant *wpa_s = global->ifaces; | |
974 | while (wpa_s) { | |
ab41595f | 975 | struct wpa_supplicant *next = wpa_s->next; |
5516ed32 EA |
976 | if (wpas_wps_terminate_pending(wpa_s) == 1) |
977 | pending = 1; | |
20625e97 JM |
978 | #ifdef CONFIG_P2P |
979 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE || | |
980 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group)) | |
981 | wpas_p2p_disconnect(wpa_s); | |
982 | #endif /* CONFIG_P2P */ | |
ab41595f | 983 | wpa_s = next; |
1a1bf008 JM |
984 | } |
985 | #endif /* CONFIG_WPS */ | |
986 | if (pending) | |
987 | return; | |
988 | eloop_terminate(); | |
989 | } | |
990 | ||
991 | ||
0456ea16 | 992 | static void wpa_supplicant_terminate(int sig, void *signal_ctx) |
6fc6879b | 993 | { |
0456ea16 | 994 | struct wpa_global *global = signal_ctx; |
1a1bf008 | 995 | wpa_supplicant_terminate_proc(global); |
6fc6879b JM |
996 | } |
997 | ||
998 | ||
b22128ef | 999 | void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s) |
6fc6879b | 1000 | { |
71934751 | 1001 | enum wpa_states old_state = wpa_s->wpa_state; |
27f43d8d | 1002 | |
6fc6879b JM |
1003 | wpa_s->pairwise_cipher = 0; |
1004 | wpa_s->group_cipher = 0; | |
1005 | wpa_s->mgmt_group_cipher = 0; | |
1006 | wpa_s->key_mgmt = 0; | |
8401a6b0 | 1007 | if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) |
99218999 | 1008 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
27f43d8d MH |
1009 | |
1010 | if (wpa_s->wpa_state != old_state) | |
1011 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); | |
6fc6879b JM |
1012 | } |
1013 | ||
1014 | ||
1015 | /** | |
1016 | * wpa_supplicant_reload_configuration - Reload configuration data | |
1017 | * @wpa_s: Pointer to wpa_supplicant data | |
1018 | * Returns: 0 on success or -1 if configuration parsing failed | |
1019 | * | |
1020 | * This function can be used to request that the configuration data is reloaded | |
1021 | * (e.g., after configuration file change). This function is reloading | |
1022 | * configuration only for one interface, so this may need to be called multiple | |
1023 | * times if %wpa_supplicant is controlling multiple interfaces and all | |
1024 | * interfaces need reconfiguration. | |
1025 | */ | |
1026 | int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s) | |
1027 | { | |
1028 | struct wpa_config *conf; | |
1029 | int reconf_ctrl; | |
8bac466b JM |
1030 | int old_ap_scan; |
1031 | ||
6fc6879b JM |
1032 | if (wpa_s->confname == NULL) |
1033 | return -1; | |
e6304cad | 1034 | conf = wpa_config_read(wpa_s->confname, NULL); |
6fc6879b JM |
1035 | if (conf == NULL) { |
1036 | wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration " | |
1037 | "file '%s' - exiting", wpa_s->confname); | |
1038 | return -1; | |
1039 | } | |
3bd35b68 JM |
1040 | if (wpa_s->confanother && |
1041 | !wpa_config_read(wpa_s->confanother, conf)) { | |
1042 | wpa_msg(wpa_s, MSG_ERROR, | |
1043 | "Failed to parse the configuration file '%s' - exiting", | |
1044 | wpa_s->confanother); | |
1045 | return -1; | |
1046 | } | |
e6304cad | 1047 | |
611aea7d | 1048 | conf->changed_parameters = (unsigned int) -1; |
6fc6879b JM |
1049 | |
1050 | reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface | |
1051 | || (conf->ctrl_interface && wpa_s->conf->ctrl_interface && | |
1052 | os_strcmp(conf->ctrl_interface, | |
1053 | wpa_s->conf->ctrl_interface) != 0); | |
1054 | ||
1055 | if (reconf_ctrl && wpa_s->ctrl_iface) { | |
1056 | wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface); | |
1057 | wpa_s->ctrl_iface = NULL; | |
1058 | } | |
1059 | ||
1060 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
7b7ce8aa | 1061 | if (wpa_s->current_ssid) { |
e66bcedd JM |
1062 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
1063 | wpa_s->own_disconnect_req = 1; | |
7b7ce8aa JM |
1064 | wpa_supplicant_deauthenticate(wpa_s, |
1065 | WLAN_REASON_DEAUTH_LEAVING); | |
1066 | } | |
8bac466b | 1067 | |
6fc6879b JM |
1068 | /* |
1069 | * TODO: should notify EAPOL SM about changes in opensc_engine_path, | |
07e2de31 | 1070 | * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers. |
6fc6879b | 1071 | */ |
a1ea1b45 | 1072 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
567da5bb JM |
1073 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
1074 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) { | |
6fc6879b JM |
1075 | /* |
1076 | * Clear forced success to clear EAP state for next | |
1077 | * authentication. | |
1078 | */ | |
1079 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); | |
1080 | } | |
1081 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
1082 | wpa_sm_set_config(wpa_s->wpa, NULL); | |
d8a790b9 | 1083 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
6fc6879b JM |
1084 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); |
1085 | rsn_preauth_deinit(wpa_s->wpa); | |
8bac466b JM |
1086 | |
1087 | old_ap_scan = wpa_s->conf->ap_scan; | |
6fc6879b JM |
1088 | wpa_config_free(wpa_s->conf); |
1089 | wpa_s->conf = conf; | |
8bac466b JM |
1090 | if (old_ap_scan != wpa_s->conf->ap_scan) |
1091 | wpas_notify_ap_scan_changed(wpa_s); | |
1092 | ||
6fc6879b JM |
1093 | if (reconf_ctrl) |
1094 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); | |
1095 | ||
611aea7d JM |
1096 | wpa_supplicant_update_config(wpa_s); |
1097 | ||
6fc6879b | 1098 | wpa_supplicant_clear_status(wpa_s); |
349493bd | 1099 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
43a38635 JM |
1100 | wpa_s->reassociate = 1; |
1101 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
1102 | } | |
f049052b | 1103 | wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed"); |
6fc6879b JM |
1104 | return 0; |
1105 | } | |
1106 | ||
1107 | ||
0456ea16 | 1108 | static void wpa_supplicant_reconfig(int sig, void *signal_ctx) |
6fc6879b | 1109 | { |
0456ea16 | 1110 | struct wpa_global *global = signal_ctx; |
6fc6879b | 1111 | struct wpa_supplicant *wpa_s; |
6fc6879b | 1112 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
f049052b BG |
1113 | wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring", |
1114 | sig); | |
6fc6879b | 1115 | if (wpa_supplicant_reload_configuration(wpa_s) < 0) { |
1a1bf008 | 1116 | wpa_supplicant_terminate_proc(global); |
6fc6879b JM |
1117 | } |
1118 | } | |
1248e584 LR |
1119 | |
1120 | if (wpa_debug_reopen_file() < 0) { | |
1121 | /* Ignore errors since we cannot really do much to fix this */ | |
1122 | wpa_printf(MSG_DEBUG, "Could not reopen debug log file"); | |
1123 | } | |
6fc6879b JM |
1124 | } |
1125 | ||
1126 | ||
6fc6879b JM |
1127 | static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s, |
1128 | struct wpa_ssid *ssid, | |
1129 | struct wpa_ie_data *ie) | |
1130 | { | |
1131 | int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie); | |
1132 | if (ret) { | |
1133 | if (ret == -2) { | |
1134 | wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE " | |
1135 | "from association info"); | |
1136 | } | |
1137 | return -1; | |
1138 | } | |
1139 | ||
f049052b BG |
1140 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set " |
1141 | "cipher suites"); | |
6fc6879b JM |
1142 | if (!(ie->group_cipher & ssid->group_cipher)) { |
1143 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group " | |
1144 | "cipher 0x%x (mask 0x%x) - reject", | |
1145 | ie->group_cipher, ssid->group_cipher); | |
1146 | return -1; | |
1147 | } | |
1148 | if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) { | |
1149 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise " | |
1150 | "cipher 0x%x (mask 0x%x) - reject", | |
1151 | ie->pairwise_cipher, ssid->pairwise_cipher); | |
1152 | return -1; | |
1153 | } | |
1154 | if (!(ie->key_mgmt & ssid->key_mgmt)) { | |
1155 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key " | |
1156 | "management 0x%x (mask 0x%x) - reject", | |
1157 | ie->key_mgmt, ssid->key_mgmt); | |
1158 | return -1; | |
1159 | } | |
1160 | ||
1161 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 1162 | if (!(ie->capabilities & WPA_CAPABILITY_MFPC) && |
3f56a2b7 | 1163 | wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) { |
6fc6879b JM |
1164 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP " |
1165 | "that does not support management frame protection - " | |
1166 | "reject"); | |
1167 | return -1; | |
1168 | } | |
1169 | #endif /* CONFIG_IEEE80211W */ | |
1170 | ||
1171 | return 0; | |
1172 | } | |
1173 | ||
1174 | ||
1175 | /** | |
1176 | * wpa_supplicant_set_suites - Set authentication and encryption parameters | |
1177 | * @wpa_s: Pointer to wpa_supplicant data | |
1178 | * @bss: Scan results for the selected BSS, or %NULL if not available | |
1179 | * @ssid: Configuration data for the selected network | |
1180 | * @wpa_ie: Buffer for the WPA/RSN IE | |
1181 | * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the | |
1182 | * used buffer length in case the functions returns success. | |
1183 | * Returns: 0 on success or -1 on failure | |
1184 | * | |
1185 | * This function is used to configure authentication and encryption parameters | |
1186 | * based on the network configuration and scan result for the selected BSS (if | |
1187 | * available). | |
1188 | */ | |
1189 | int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, | |
6fa81a3b | 1190 | struct wpa_bss *bss, struct wpa_ssid *ssid, |
6fc6879b JM |
1191 | u8 *wpa_ie, size_t *wpa_ie_len) |
1192 | { | |
1193 | struct wpa_ie_data ie; | |
1194 | int sel, proto; | |
df0f01d9 | 1195 | const u8 *bss_wpa, *bss_rsn, *bss_osen; |
6fc6879b JM |
1196 | |
1197 | if (bss) { | |
6fa81a3b JM |
1198 | bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
1199 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
df0f01d9 | 1200 | bss_osen = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
6fc6879b | 1201 | } else |
df0f01d9 | 1202 | bss_wpa = bss_rsn = bss_osen = NULL; |
6fc6879b JM |
1203 | |
1204 | if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) && | |
1205 | wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 && | |
1206 | (ie.group_cipher & ssid->group_cipher) && | |
1207 | (ie.pairwise_cipher & ssid->pairwise_cipher) && | |
1208 | (ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b | 1209 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0"); |
6fc6879b JM |
1210 | proto = WPA_PROTO_RSN; |
1211 | } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) && | |
267ac3bc | 1212 | wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 && |
6fc6879b JM |
1213 | (ie.group_cipher & ssid->group_cipher) && |
1214 | (ie.pairwise_cipher & ssid->pairwise_cipher) && | |
1215 | (ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b | 1216 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0"); |
6fc6879b | 1217 | proto = WPA_PROTO_WPA; |
df0f01d9 | 1218 | #ifdef CONFIG_HS20 |
dc673aec JM |
1219 | } else if (bss_osen && (ssid->proto & WPA_PROTO_OSEN) && |
1220 | wpa_parse_wpa_ie(bss_osen, 2 + bss_osen[1], &ie) == 0 && | |
1221 | (ie.group_cipher & ssid->group_cipher) && | |
1222 | (ie.pairwise_cipher & ssid->pairwise_cipher) && | |
1223 | (ie.key_mgmt & ssid->key_mgmt)) { | |
df0f01d9 | 1224 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using OSEN"); |
df0f01d9 | 1225 | proto = WPA_PROTO_OSEN; |
f5a60216 JM |
1226 | } else if (bss_rsn && (ssid->proto & WPA_PROTO_OSEN) && |
1227 | wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 && | |
1228 | (ie.group_cipher & ssid->group_cipher) && | |
1229 | (ie.pairwise_cipher & ssid->pairwise_cipher) && | |
1230 | (ie.key_mgmt & ssid->key_mgmt)) { | |
1231 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using OSEN (within RSN)"); | |
1232 | proto = WPA_PROTO_RSN; | |
df0f01d9 | 1233 | #endif /* CONFIG_HS20 */ |
6fc6879b JM |
1234 | } else if (bss) { |
1235 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN"); | |
267ac3bc JM |
1236 | wpa_dbg(wpa_s, MSG_DEBUG, |
1237 | "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", | |
1238 | ssid->proto, ssid->pairwise_cipher, ssid->group_cipher, | |
1239 | ssid->key_mgmt); | |
1240 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s%s", | |
1241 | MAC2STR(bss->bssid), | |
1242 | wpa_ssid_txt(bss->ssid, bss->ssid_len), | |
1243 | bss_wpa ? " WPA" : "", | |
1244 | bss_rsn ? " RSN" : "", | |
1245 | bss_osen ? " OSEN" : ""); | |
1246 | if (bss_rsn) { | |
1247 | wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]); | |
1248 | if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) { | |
1249 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1250 | "Could not parse RSN element"); | |
1251 | } else { | |
1252 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1253 | "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", | |
1254 | ie.pairwise_cipher, ie.group_cipher, | |
1255 | ie.key_mgmt); | |
1256 | } | |
1257 | } | |
1258 | if (bss_wpa) { | |
1259 | wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]); | |
1260 | if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) { | |
1261 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1262 | "Could not parse WPA element"); | |
1263 | } else { | |
1264 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1265 | "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", | |
1266 | ie.pairwise_cipher, ie.group_cipher, | |
1267 | ie.key_mgmt); | |
1268 | } | |
1269 | } | |
6fc6879b JM |
1270 | return -1; |
1271 | } else { | |
df0f01d9 JM |
1272 | if (ssid->proto & WPA_PROTO_OSEN) |
1273 | proto = WPA_PROTO_OSEN; | |
1274 | else if (ssid->proto & WPA_PROTO_RSN) | |
6fc6879b JM |
1275 | proto = WPA_PROTO_RSN; |
1276 | else | |
1277 | proto = WPA_PROTO_WPA; | |
1278 | if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) { | |
1279 | os_memset(&ie, 0, sizeof(ie)); | |
1280 | ie.group_cipher = ssid->group_cipher; | |
1281 | ie.pairwise_cipher = ssid->pairwise_cipher; | |
1282 | ie.key_mgmt = ssid->key_mgmt; | |
1283 | #ifdef CONFIG_IEEE80211W | |
61a56c14 JM |
1284 | ie.mgmt_group_cipher = 0; |
1285 | if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) { | |
1286 | if (ssid->group_mgmt_cipher & | |
1287 | WPA_CIPHER_BIP_GMAC_256) | |
1288 | ie.mgmt_group_cipher = | |
1289 | WPA_CIPHER_BIP_GMAC_256; | |
1290 | else if (ssid->group_mgmt_cipher & | |
1291 | WPA_CIPHER_BIP_CMAC_256) | |
1292 | ie.mgmt_group_cipher = | |
1293 | WPA_CIPHER_BIP_CMAC_256; | |
1294 | else if (ssid->group_mgmt_cipher & | |
1295 | WPA_CIPHER_BIP_GMAC_128) | |
1296 | ie.mgmt_group_cipher = | |
1297 | WPA_CIPHER_BIP_GMAC_128; | |
1298 | else | |
1299 | ie.mgmt_group_cipher = | |
1300 | WPA_CIPHER_AES_128_CMAC; | |
1301 | } | |
6fc6879b | 1302 | #endif /* CONFIG_IEEE80211W */ |
c1790a5f JM |
1303 | #ifdef CONFIG_OWE |
1304 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && | |
1305 | !ssid->owe_only && | |
1306 | !bss_wpa && !bss_rsn && !bss_osen) { | |
1307 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
1308 | wpa_s->wpa_proto = 0; | |
9f8d459d | 1309 | *wpa_ie_len = 0; |
c1790a5f JM |
1310 | return 0; |
1311 | } | |
1312 | #endif /* CONFIG_OWE */ | |
f049052b BG |
1313 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites " |
1314 | "based on configuration"); | |
6fc6879b JM |
1315 | } else |
1316 | proto = ie.proto; | |
1317 | } | |
1318 | ||
f049052b BG |
1319 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d " |
1320 | "pairwise %d key_mgmt %d proto %d", | |
1321 | ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto); | |
6fc6879b JM |
1322 | #ifdef CONFIG_IEEE80211W |
1323 | if (ssid->ieee80211w) { | |
f049052b BG |
1324 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d", |
1325 | ie.mgmt_group_cipher); | |
6fc6879b JM |
1326 | } |
1327 | #endif /* CONFIG_IEEE80211W */ | |
1328 | ||
64fa840a | 1329 | wpa_s->wpa_proto = proto; |
6fc6879b JM |
1330 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto); |
1331 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, | |
df0f01d9 | 1332 | !!(ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN))); |
6fc6879b JM |
1333 | |
1334 | if (bss || !wpa_s->ap_ies_from_associnfo) { | |
1335 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
1336 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
1337 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
1338 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
1339 | return -1; | |
1340 | } | |
1341 | ||
9e68742e JM |
1342 | #ifdef CONFIG_NO_WPA |
1343 | wpa_s->group_cipher = WPA_CIPHER_NONE; | |
1344 | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; | |
1345 | #else /* CONFIG_NO_WPA */ | |
6fc6879b | 1346 | sel = ie.group_cipher & ssid->group_cipher; |
edbd2a19 JM |
1347 | wpa_s->group_cipher = wpa_pick_group_cipher(sel); |
1348 | if (wpa_s->group_cipher < 0) { | |
f049052b BG |
1349 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group " |
1350 | "cipher"); | |
6fc6879b JM |
1351 | return -1; |
1352 | } | |
edbd2a19 JM |
1353 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s", |
1354 | wpa_cipher_txt(wpa_s->group_cipher)); | |
6fc6879b JM |
1355 | |
1356 | sel = ie.pairwise_cipher & ssid->pairwise_cipher; | |
edbd2a19 JM |
1357 | wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1); |
1358 | if (wpa_s->pairwise_cipher < 0) { | |
f049052b BG |
1359 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise " |
1360 | "cipher"); | |
6fc6879b JM |
1361 | return -1; |
1362 | } | |
edbd2a19 JM |
1363 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s", |
1364 | wpa_cipher_txt(wpa_s->pairwise_cipher)); | |
9e68742e | 1365 | #endif /* CONFIG_NO_WPA */ |
6fc6879b JM |
1366 | |
1367 | sel = ie.key_mgmt & ssid->key_mgmt; | |
c10347f2 JM |
1368 | #ifdef CONFIG_SAE |
1369 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) | |
1370 | sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE); | |
1371 | #endif /* CONFIG_SAE */ | |
6fc6879b | 1372 | if (0) { |
5e3b5197 JM |
1373 | #ifdef CONFIG_SUITEB192 |
1374 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { | |
1375 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; | |
1376 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1377 | "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)"); | |
1378 | #endif /* CONFIG_SUITEB192 */ | |
1379 | #ifdef CONFIG_SUITEB | |
666497c8 JM |
1380 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
1381 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B; | |
1382 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1383 | "WPA: using KEY_MGMT 802.1X with Suite B"); | |
5e3b5197 | 1384 | #endif /* CONFIG_SUITEB */ |
b8ae56e4 JM |
1385 | #ifdef CONFIG_FILS |
1386 | #ifdef CONFIG_IEEE80211R | |
1387 | } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA384) { | |
1388 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384; | |
1389 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA384"); | |
1390 | } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA256) { | |
1391 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256; | |
1392 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA256"); | |
1393 | #endif /* CONFIG_IEEE80211R */ | |
1394 | } else if (sel & WPA_KEY_MGMT_FILS_SHA384) { | |
1395 | wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA384; | |
1396 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA384"); | |
1397 | } else if (sel & WPA_KEY_MGMT_FILS_SHA256) { | |
1398 | wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA256; | |
1399 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA256"); | |
1400 | #endif /* CONFIG_FILS */ | |
6fc6879b | 1401 | #ifdef CONFIG_IEEE80211R |
8c2715b3 JM |
1402 | #ifdef CONFIG_SHA384 |
1403 | } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) { | |
1404 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384; | |
1405 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1406 | "WPA: using KEY_MGMT FT/802.1X-SHA384"); | |
1407 | if (pmksa_cache_get_current(wpa_s->wpa)) { | |
1408 | /* PMKSA caching with FT is not fully functional, so | |
1409 | * disable the case for now. */ | |
1410 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1411 | "WPA: Disable PMKSA caching for FT/802.1X connection"); | |
1412 | pmksa_cache_clear_current(wpa_s->wpa); | |
1413 | } | |
1414 | #endif /* CONFIG_SHA384 */ | |
6fc6879b JM |
1415 | } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) { |
1416 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X; | |
f049052b | 1417 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X"); |
833bb2ab JM |
1418 | if (pmksa_cache_get_current(wpa_s->wpa)) { |
1419 | /* PMKSA caching with FT is not fully functional, so | |
1420 | * disable the case for now. */ | |
1421 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1422 | "WPA: Disable PMKSA caching for FT/802.1X connection"); | |
1423 | pmksa_cache_clear_current(wpa_s->wpa); | |
1424 | } | |
6fc6879b JM |
1425 | } else if (sel & WPA_KEY_MGMT_FT_PSK) { |
1426 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK; | |
f049052b | 1427 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK"); |
6fc6879b | 1428 | #endif /* CONFIG_IEEE80211R */ |
c10347f2 JM |
1429 | #ifdef CONFIG_SAE |
1430 | } else if (sel & WPA_KEY_MGMT_SAE) { | |
1431 | wpa_s->key_mgmt = WPA_KEY_MGMT_SAE; | |
1432 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE"); | |
1433 | } else if (sel & WPA_KEY_MGMT_FT_SAE) { | |
1434 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE; | |
1435 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE"); | |
1436 | #endif /* CONFIG_SAE */ | |
56586197 JM |
1437 | #ifdef CONFIG_IEEE80211W |
1438 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) { | |
1439 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256; | |
f049052b | 1440 | wpa_dbg(wpa_s, MSG_DEBUG, |
56586197 JM |
1441 | "WPA: using KEY_MGMT 802.1X with SHA256"); |
1442 | } else if (sel & WPA_KEY_MGMT_PSK_SHA256) { | |
1443 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256; | |
f049052b | 1444 | wpa_dbg(wpa_s, MSG_DEBUG, |
56586197 JM |
1445 | "WPA: using KEY_MGMT PSK with SHA256"); |
1446 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b JM |
1447 | } else if (sel & WPA_KEY_MGMT_IEEE8021X) { |
1448 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X; | |
f049052b | 1449 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X"); |
6fc6879b JM |
1450 | } else if (sel & WPA_KEY_MGMT_PSK) { |
1451 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; | |
f049052b | 1452 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK"); |
6fc6879b JM |
1453 | } else if (sel & WPA_KEY_MGMT_WPA_NONE) { |
1454 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE; | |
f049052b | 1455 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE"); |
df0f01d9 JM |
1456 | #ifdef CONFIG_HS20 |
1457 | } else if (sel & WPA_KEY_MGMT_OSEN) { | |
1458 | wpa_s->key_mgmt = WPA_KEY_MGMT_OSEN; | |
1459 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using KEY_MGMT OSEN"); | |
1460 | #endif /* CONFIG_HS20 */ | |
a1ea1b45 JM |
1461 | #ifdef CONFIG_OWE |
1462 | } else if (sel & WPA_KEY_MGMT_OWE) { | |
1463 | wpa_s->key_mgmt = WPA_KEY_MGMT_OWE; | |
1464 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT OWE"); | |
1465 | #endif /* CONFIG_OWE */ | |
567da5bb JM |
1466 | #ifdef CONFIG_DPP |
1467 | } else if (sel & WPA_KEY_MGMT_DPP) { | |
1468 | wpa_s->key_mgmt = WPA_KEY_MGMT_DPP; | |
1469 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT DPP"); | |
1470 | #endif /* CONFIG_DPP */ | |
6fc6879b | 1471 | } else { |
f049052b BG |
1472 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select " |
1473 | "authenticated key management type"); | |
6fc6879b JM |
1474 | return -1; |
1475 | } | |
1476 | ||
1477 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); | |
1478 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, | |
1479 | wpa_s->pairwise_cipher); | |
1480 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); | |
1481 | ||
1482 | #ifdef CONFIG_IEEE80211W | |
1483 | sel = ie.mgmt_group_cipher; | |
61a56c14 JM |
1484 | if (ssid->group_mgmt_cipher) |
1485 | sel &= ssid->group_mgmt_cipher; | |
3f56a2b7 | 1486 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION || |
0b60b0aa | 1487 | !(ie.capabilities & WPA_CAPABILITY_MFPC)) |
6fc6879b JM |
1488 | sel = 0; |
1489 | if (sel & WPA_CIPHER_AES_128_CMAC) { | |
1490 | wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC; | |
f049052b | 1491 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " |
6fc6879b | 1492 | "AES-128-CMAC"); |
8dd9f9cd JM |
1493 | } else if (sel & WPA_CIPHER_BIP_GMAC_128) { |
1494 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128; | |
1495 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " | |
1496 | "BIP-GMAC-128"); | |
1497 | } else if (sel & WPA_CIPHER_BIP_GMAC_256) { | |
1498 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256; | |
1499 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " | |
1500 | "BIP-GMAC-256"); | |
1501 | } else if (sel & WPA_CIPHER_BIP_CMAC_256) { | |
1502 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256; | |
1503 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " | |
1504 | "BIP-CMAC-256"); | |
6fc6879b JM |
1505 | } else { |
1506 | wpa_s->mgmt_group_cipher = 0; | |
f049052b | 1507 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher"); |
6fc6879b JM |
1508 | } |
1509 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, | |
1510 | wpa_s->mgmt_group_cipher); | |
62d49803 | 1511 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, |
3f56a2b7 | 1512 | wpas_get_ssid_pmf(wpa_s, ssid)); |
6fc6879b JM |
1513 | #endif /* CONFIG_IEEE80211W */ |
1514 | ||
1515 | if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) { | |
f049052b | 1516 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to generate WPA IE"); |
6fc6879b JM |
1517 | return -1; |
1518 | } | |
1519 | ||
0bf927a0 | 1520 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) { |
a52410c2 | 1521 | int psk_set = 0; |
06b1a104 | 1522 | int sae_only; |
a52410c2 | 1523 | |
06b1a104 JM |
1524 | sae_only = (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | |
1525 | WPA_KEY_MGMT_FT_PSK | | |
1526 | WPA_KEY_MGMT_PSK_SHA256)) == 0; | |
1527 | ||
1528 | if (ssid->psk_set && !sae_only) { | |
66dbc8d9 JM |
1529 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (set in config)", |
1530 | ssid->psk, PMK_LEN); | |
70c93963 MH |
1531 | wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, |
1532 | NULL); | |
a52410c2 JM |
1533 | psk_set = 1; |
1534 | } | |
a34ca59e | 1535 | |
06b1a104 JM |
1536 | if (wpa_key_mgmt_sae(ssid->key_mgmt) && |
1537 | (ssid->sae_password || ssid->passphrase)) | |
a34ca59e JM |
1538 | psk_set = 1; |
1539 | ||
7d232e23 ZC |
1540 | #ifndef CONFIG_NO_PBKDF2 |
1541 | if (bss && ssid->bssid_set && ssid->ssid_len == 0 && | |
06b1a104 | 1542 | ssid->passphrase && !sae_only) { |
7d232e23 | 1543 | u8 psk[PMK_LEN]; |
986de33d JM |
1544 | pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len, |
1545 | 4096, psk, PMK_LEN); | |
7d232e23 ZC |
1546 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", |
1547 | psk, PMK_LEN); | |
70c93963 | 1548 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL, NULL); |
a52410c2 | 1549 | psk_set = 1; |
e886c88e | 1550 | os_memset(psk, 0, sizeof(psk)); |
7d232e23 ZC |
1551 | } |
1552 | #endif /* CONFIG_NO_PBKDF2 */ | |
9173b16f | 1553 | #ifdef CONFIG_EXT_PASSWORD |
06b1a104 | 1554 | if (ssid->ext_psk && !sae_only) { |
9173b16f JM |
1555 | struct wpabuf *pw = ext_password_get(wpa_s->ext_pw, |
1556 | ssid->ext_psk); | |
1557 | char pw_str[64 + 1]; | |
1558 | u8 psk[PMK_LEN]; | |
1559 | ||
1560 | if (pw == NULL) { | |
1561 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: No PSK " | |
1562 | "found from external storage"); | |
1563 | return -1; | |
1564 | } | |
1565 | ||
1566 | if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) { | |
1567 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: Unexpected " | |
1568 | "PSK length %d in external storage", | |
1569 | (int) wpabuf_len(pw)); | |
1570 | ext_password_free(pw); | |
1571 | return -1; | |
1572 | } | |
1573 | ||
1574 | os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw)); | |
1575 | pw_str[wpabuf_len(pw)] = '\0'; | |
1576 | ||
1577 | #ifndef CONFIG_NO_PBKDF2 | |
1578 | if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss) | |
1579 | { | |
986de33d JM |
1580 | pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len, |
1581 | 4096, psk, PMK_LEN); | |
9173b16f JM |
1582 | os_memset(pw_str, 0, sizeof(pw_str)); |
1583 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from " | |
1584 | "external passphrase)", | |
1585 | psk, PMK_LEN); | |
70c93963 MH |
1586 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL, |
1587 | NULL); | |
a52410c2 | 1588 | psk_set = 1; |
e886c88e | 1589 | os_memset(psk, 0, sizeof(psk)); |
9173b16f JM |
1590 | } else |
1591 | #endif /* CONFIG_NO_PBKDF2 */ | |
1592 | if (wpabuf_len(pw) == 2 * PMK_LEN) { | |
1593 | if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) { | |
1594 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: " | |
1595 | "Invalid PSK hex string"); | |
1596 | os_memset(pw_str, 0, sizeof(pw_str)); | |
1597 | ext_password_free(pw); | |
1598 | return -1; | |
1599 | } | |
66dbc8d9 JM |
1600 | wpa_hexdump_key(MSG_MSGDUMP, |
1601 | "PSK (from external PSK)", | |
1602 | psk, PMK_LEN); | |
70c93963 MH |
1603 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL, |
1604 | NULL); | |
a52410c2 | 1605 | psk_set = 1; |
e886c88e | 1606 | os_memset(psk, 0, sizeof(psk)); |
9173b16f JM |
1607 | } else { |
1608 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: No suitable " | |
1609 | "PSK available"); | |
1610 | os_memset(pw_str, 0, sizeof(pw_str)); | |
1611 | ext_password_free(pw); | |
1612 | return -1; | |
1613 | } | |
1614 | ||
1615 | os_memset(pw_str, 0, sizeof(pw_str)); | |
1616 | ext_password_free(pw); | |
1617 | } | |
1618 | #endif /* CONFIG_EXT_PASSWORD */ | |
a52410c2 JM |
1619 | |
1620 | if (!psk_set) { | |
1621 | wpa_msg(wpa_s, MSG_INFO, | |
1622 | "No PSK available for association"); | |
06b1a104 | 1623 | wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE"); |
a52410c2 JM |
1624 | return -1; |
1625 | } | |
675112df JM |
1626 | #ifdef CONFIG_OWE |
1627 | } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) { | |
1628 | /* OWE Diffie-Hellman exchange in (Re)Association | |
1629 | * Request/Response frames set the PMK, so do not override it | |
1630 | * here. */ | |
1631 | #endif /* CONFIG_OWE */ | |
7d232e23 | 1632 | } else |
6fc6879b JM |
1633 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
1634 | ||
1635 | return 0; | |
1636 | } | |
1637 | ||
1638 | ||
8cd6b7bc | 1639 | static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx) |
03e47c9c | 1640 | { |
8cd6b7bc | 1641 | *pos = 0x00; |
03e47c9c | 1642 | |
8cd6b7bc JB |
1643 | switch (idx) { |
1644 | case 0: /* Bits 0-7 */ | |
1645 | break; | |
1646 | case 1: /* Bits 8-15 */ | |
d514b502 JM |
1647 | if (wpa_s->conf->coloc_intf_reporting) { |
1648 | /* Bit 13 - Collocated Interference Reporting */ | |
1649 | *pos |= 0x20; | |
1650 | } | |
8cd6b7bc JB |
1651 | break; |
1652 | case 2: /* Bits 16-23 */ | |
1653 | #ifdef CONFIG_WNM | |
1654 | *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */ | |
1655 | *pos |= 0x08; /* Bit 19 - BSS Transition */ | |
1656 | #endif /* CONFIG_WNM */ | |
1657 | break; | |
1658 | case 3: /* Bits 24-31 */ | |
1659 | #ifdef CONFIG_WNM | |
1660 | *pos |= 0x02; /* Bit 25 - SSID List */ | |
1661 | #endif /* CONFIG_WNM */ | |
03e47c9c | 1662 | #ifdef CONFIG_INTERWORKING |
8cd6b7bc JB |
1663 | if (wpa_s->conf->interworking) |
1664 | *pos |= 0x80; /* Bit 31 - Interworking */ | |
03e47c9c | 1665 | #endif /* CONFIG_INTERWORKING */ |
8cd6b7bc JB |
1666 | break; |
1667 | case 4: /* Bits 32-39 */ | |
56f5af48 | 1668 | #ifdef CONFIG_INTERWORKING |
1e1245bc | 1669 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_QOS_MAPPING) |
429dd9af | 1670 | *pos |= 0x01; /* Bit 32 - QoS Map */ |
56f5af48 | 1671 | #endif /* CONFIG_INTERWORKING */ |
8cd6b7bc JB |
1672 | break; |
1673 | case 5: /* Bits 40-47 */ | |
95a3ea94 JM |
1674 | #ifdef CONFIG_HS20 |
1675 | if (wpa_s->conf->hs20) | |
1676 | *pos |= 0x40; /* Bit 46 - WNM-Notification */ | |
1677 | #endif /* CONFIG_HS20 */ | |
92c6e2e3 DS |
1678 | #ifdef CONFIG_MBO |
1679 | *pos |= 0x40; /* Bit 46 - WNM-Notification */ | |
1680 | #endif /* CONFIG_MBO */ | |
8cd6b7bc JB |
1681 | break; |
1682 | case 6: /* Bits 48-55 */ | |
1683 | break; | |
d1723c55 LD |
1684 | case 7: /* Bits 56-63 */ |
1685 | break; | |
1686 | case 8: /* Bits 64-71 */ | |
1687 | if (wpa_s->conf->ftm_responder) | |
1688 | *pos |= 0x40; /* Bit 70 - FTM responder */ | |
1689 | if (wpa_s->conf->ftm_initiator) | |
1690 | *pos |= 0x80; /* Bit 71 - FTM initiator */ | |
1691 | break; | |
e4d2ce1b JM |
1692 | case 9: /* Bits 72-79 */ |
1693 | #ifdef CONFIG_FILS | |
d98038bb | 1694 | if (!wpa_s->disable_fils) |
1695 | *pos |= 0x01; | |
e4d2ce1b JM |
1696 | #endif /* CONFIG_FILS */ |
1697 | break; | |
8cd6b7bc JB |
1698 | } |
1699 | } | |
03e47c9c | 1700 | |
03e47c9c | 1701 | |
0bbaa9b9 | 1702 | int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf, size_t buflen) |
8cd6b7bc JB |
1703 | { |
1704 | u8 *pos = buf; | |
e4d2ce1b | 1705 | u8 len = 10, i; |
8cd6b7bc JB |
1706 | |
1707 | if (len < wpa_s->extended_capa_len) | |
1708 | len = wpa_s->extended_capa_len; | |
0bbaa9b9 JM |
1709 | if (buflen < (size_t) len + 2) { |
1710 | wpa_printf(MSG_INFO, | |
1711 | "Not enough room for building extended capabilities element"); | |
1712 | return -1; | |
1713 | } | |
03e47c9c JM |
1714 | |
1715 | *pos++ = WLAN_EID_EXT_CAPAB; | |
8cd6b7bc JB |
1716 | *pos++ = len; |
1717 | for (i = 0; i < len; i++, pos++) { | |
1718 | wpas_ext_capab_byte(wpa_s, pos, i); | |
1719 | ||
1720 | if (i < wpa_s->extended_capa_len) { | |
1721 | *pos &= ~wpa_s->extended_capa_mask[i]; | |
1722 | *pos |= wpa_s->extended_capa[i]; | |
1723 | } | |
1724 | } | |
03e47c9c | 1725 | |
3db5439a JM |
1726 | while (len > 0 && buf[1 + len] == 0) { |
1727 | len--; | |
1728 | buf[1] = len; | |
1729 | } | |
1730 | if (len == 0) | |
1731 | return 0; | |
1732 | ||
1733 | return 2 + len; | |
03e47c9c JM |
1734 | } |
1735 | ||
1736 | ||
6ac4b15e JM |
1737 | static int wpas_valid_bss(struct wpa_supplicant *wpa_s, |
1738 | struct wpa_bss *test_bss) | |
1739 | { | |
1740 | struct wpa_bss *bss; | |
1741 | ||
1742 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { | |
1743 | if (bss == test_bss) | |
1744 | return 1; | |
1745 | } | |
1746 | ||
1747 | return 0; | |
1748 | } | |
1749 | ||
1750 | ||
1751 | static int wpas_valid_ssid(struct wpa_supplicant *wpa_s, | |
1752 | struct wpa_ssid *test_ssid) | |
1753 | { | |
1754 | struct wpa_ssid *ssid; | |
1755 | ||
1756 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
1757 | if (ssid == test_ssid) | |
1758 | return 1; | |
1759 | } | |
1760 | ||
1761 | return 0; | |
1762 | } | |
1763 | ||
1764 | ||
1765 | int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss, | |
1766 | struct wpa_ssid *test_ssid) | |
1767 | { | |
1768 | if (test_bss && !wpas_valid_bss(wpa_s, test_bss)) | |
1769 | return 0; | |
1770 | ||
1771 | return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid); | |
1772 | } | |
1773 | ||
1774 | ||
1775 | void wpas_connect_work_free(struct wpa_connect_work *cwork) | |
1776 | { | |
1777 | if (cwork == NULL) | |
1778 | return; | |
1779 | os_free(cwork); | |
1780 | } | |
1781 | ||
1782 | ||
1783 | void wpas_connect_work_done(struct wpa_supplicant *wpa_s) | |
1784 | { | |
1785 | struct wpa_connect_work *cwork; | |
1786 | struct wpa_radio_work *work = wpa_s->connect_work; | |
1787 | ||
1788 | if (!work) | |
1789 | return; | |
1790 | ||
1791 | wpa_s->connect_work = NULL; | |
1792 | cwork = work->ctx; | |
1793 | work->ctx = NULL; | |
1794 | wpas_connect_work_free(cwork); | |
1795 | radio_work_done(work); | |
1796 | } | |
1797 | ||
1798 | ||
a313d17d | 1799 | int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style) |
c267753b JM |
1800 | { |
1801 | struct os_reltime now; | |
1802 | u8 addr[ETH_ALEN]; | |
1803 | ||
1804 | os_get_reltime(&now); | |
a313d17d JM |
1805 | if (wpa_s->last_mac_addr_style == style && |
1806 | wpa_s->last_mac_addr_change.sec != 0 && | |
c267753b JM |
1807 | !os_reltime_expired(&now, &wpa_s->last_mac_addr_change, |
1808 | wpa_s->conf->rand_addr_lifetime)) { | |
1809 | wpa_msg(wpa_s, MSG_DEBUG, | |
1810 | "Previously selected random MAC address has not yet expired"); | |
1811 | return 0; | |
1812 | } | |
1813 | ||
a313d17d JM |
1814 | switch (style) { |
1815 | case 1: | |
1816 | if (random_mac_addr(addr) < 0) | |
1817 | return -1; | |
1818 | break; | |
1819 | case 2: | |
1820 | os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN); | |
1821 | if (random_mac_addr_keep_oui(addr) < 0) | |
1822 | return -1; | |
1823 | break; | |
1824 | default: | |
c267753b | 1825 | return -1; |
a313d17d | 1826 | } |
c267753b JM |
1827 | |
1828 | if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) { | |
1829 | wpa_msg(wpa_s, MSG_INFO, | |
1830 | "Failed to set random MAC address"); | |
1831 | return -1; | |
1832 | } | |
1833 | ||
1834 | os_get_reltime(&wpa_s->last_mac_addr_change); | |
1835 | wpa_s->mac_addr_changed = 1; | |
a313d17d | 1836 | wpa_s->last_mac_addr_style = style; |
c267753b JM |
1837 | |
1838 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { | |
1839 | wpa_msg(wpa_s, MSG_INFO, | |
1840 | "Could not update MAC address information"); | |
1841 | return -1; | |
1842 | } | |
1843 | ||
1844 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, | |
1845 | MAC2STR(addr)); | |
1846 | ||
1847 | return 0; | |
1848 | } | |
1849 | ||
1850 | ||
1851 | int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s) | |
1852 | { | |
1853 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING || | |
1854 | !wpa_s->conf->preassoc_mac_addr) | |
1855 | return 0; | |
1856 | ||
a313d17d | 1857 | return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr); |
c267753b JM |
1858 | } |
1859 | ||
1860 | ||
6ac4b15e JM |
1861 | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit); |
1862 | ||
6fc6879b JM |
1863 | /** |
1864 | * wpa_supplicant_associate - Request association | |
1865 | * @wpa_s: Pointer to wpa_supplicant data | |
1866 | * @bss: Scan results for the selected BSS, or %NULL if not available | |
1867 | * @ssid: Configuration data for the selected network | |
1868 | * | |
1869 | * This function is used to request %wpa_supplicant to associate with a BSS. | |
1870 | */ | |
1871 | void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, | |
6fa81a3b | 1872 | struct wpa_bss *bss, struct wpa_ssid *ssid) |
6fc6879b | 1873 | { |
6ac4b15e | 1874 | struct wpa_connect_work *cwork; |
a313d17d JM |
1875 | int rand_style; |
1876 | ||
a8412ec9 JM |
1877 | wpa_s->own_disconnect_req = 0; |
1878 | ||
e7160bd8 JM |
1879 | /* |
1880 | * If we are starting a new connection, any previously pending EAPOL | |
1881 | * RX cannot be valid anymore. | |
1882 | */ | |
1883 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1884 | wpa_s->pending_eapol_rx = NULL; | |
1885 | ||
a313d17d JM |
1886 | if (ssid->mac_addr == -1) |
1887 | rand_style = wpa_s->conf->mac_addr; | |
1888 | else | |
1889 | rand_style = ssid->mac_addr; | |
6fc6879b | 1890 | |
8c42b369 EP |
1891 | wmm_ac_clear_saved_tspecs(wpa_s); |
1892 | wpa_s->reassoc_same_bss = 0; | |
6a5ee810 | 1893 | wpa_s->reassoc_same_ess = 0; |
daa40960 JM |
1894 | #ifdef CONFIG_TESTING_OPTIONS |
1895 | wpa_s->testing_resend_assoc = 0; | |
1896 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8c42b369 | 1897 | |
c267753b JM |
1898 | if (wpa_s->last_ssid == ssid) { |
1899 | wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS"); | |
6a5ee810 | 1900 | wpa_s->reassoc_same_ess = 1; |
8c42b369 EP |
1901 | if (wpa_s->current_bss && wpa_s->current_bss == bss) { |
1902 | wmm_ac_save_tspecs(wpa_s); | |
1903 | wpa_s->reassoc_same_bss = 1; | |
1904 | } | |
5d30f927 BR |
1905 | } |
1906 | ||
1907 | if (rand_style > 0 && !wpa_s->reassoc_same_ess) { | |
a313d17d | 1908 | if (wpas_update_random_addr(wpa_s, rand_style) < 0) |
c267753b JM |
1909 | return; |
1910 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); | |
5d30f927 | 1911 | } else if (rand_style == 0 && wpa_s->mac_addr_changed) { |
c267753b JM |
1912 | if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) { |
1913 | wpa_msg(wpa_s, MSG_INFO, | |
1914 | "Could not restore permanent MAC address"); | |
1915 | return; | |
1916 | } | |
1917 | wpa_s->mac_addr_changed = 0; | |
1918 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { | |
1919 | wpa_msg(wpa_s, MSG_INFO, | |
1920 | "Could not update MAC address information"); | |
1921 | return; | |
1922 | } | |
1923 | wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address"); | |
1924 | } | |
1925 | wpa_s->last_ssid = ssid; | |
1926 | ||
78177a00 JM |
1927 | #ifdef CONFIG_IBSS_RSN |
1928 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
1929 | wpa_s->ibss_rsn = NULL; | |
81a10a94 JM |
1930 | #else /* CONFIG_IBSS_RSN */ |
1931 | if (ssid->mode == WPAS_MODE_IBSS && | |
1932 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) { | |
1933 | wpa_msg(wpa_s, MSG_INFO, | |
1934 | "IBSS RSN not supported in the build"); | |
1935 | return; | |
1936 | } | |
78177a00 JM |
1937 | #endif /* CONFIG_IBSS_RSN */ |
1938 | ||
2c5d725c JM |
1939 | if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO || |
1940 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { | |
1581b38b JM |
1941 | #ifdef CONFIG_AP |
1942 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) { | |
f049052b BG |
1943 | wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP " |
1944 | "mode"); | |
1581b38b JM |
1945 | return; |
1946 | } | |
8c981d17 DW |
1947 | if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) { |
1948 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
b2b688d1 VKE |
1949 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
1950 | wpas_p2p_ap_setup_failed(wpa_s); | |
8c981d17 DW |
1951 | return; |
1952 | } | |
8f770587 | 1953 | wpa_s->current_bss = bss; |
1581b38b | 1954 | #else /* CONFIG_AP */ |
f049052b BG |
1955 | wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in " |
1956 | "the build"); | |
1581b38b JM |
1957 | #endif /* CONFIG_AP */ |
1958 | return; | |
1959 | } | |
1960 | ||
603a3f34 JL |
1961 | if (ssid->mode == WPAS_MODE_MESH) { |
1962 | #ifdef CONFIG_MESH | |
1963 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) { | |
1964 | wpa_msg(wpa_s, MSG_INFO, | |
1965 | "Driver does not support mesh mode"); | |
1966 | return; | |
1967 | } | |
1968 | if (bss) | |
1969 | ssid->frequency = bss->freq; | |
1970 | if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) { | |
1971 | wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh"); | |
1972 | return; | |
1973 | } | |
1974 | wpa_s->current_bss = bss; | |
6174de66 JM |
1975 | wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_STARTED "ssid=\"%s\" id=%d", |
1976 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len), | |
1977 | ssid->id); | |
89e9cd25 | 1978 | wpas_notify_mesh_group_started(wpa_s, ssid); |
603a3f34 JL |
1979 | #else /* CONFIG_MESH */ |
1980 | wpa_msg(wpa_s, MSG_ERROR, | |
1981 | "mesh mode support not included in the build"); | |
1982 | #endif /* CONFIG_MESH */ | |
1983 | return; | |
1984 | } | |
1985 | ||
2efc6720 JM |
1986 | /* |
1987 | * Set WPA state machine configuration to match the selected network now | |
1988 | * so that the information is available before wpas_start_assoc_cb() | |
1989 | * gets called. This is needed at least for RSN pre-authentication where | |
1990 | * candidate APs are added to a list based on scan result processing | |
1991 | * before completion of the first association. | |
1992 | */ | |
1993 | wpa_supplicant_rsn_supp_set_config(wpa_s, ssid); | |
1994 | ||
a0d5c56f JM |
1995 | #ifdef CONFIG_DPP |
1996 | if (wpas_dpp_check_connect(wpa_s, ssid, bss) != 0) | |
1997 | return; | |
1998 | #endif /* CONFIG_DPP */ | |
1999 | ||
52c9e6f3 | 2000 | #ifdef CONFIG_TDLS |
95cb2d88 JM |
2001 | if (bss) |
2002 | wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1), | |
2003 | bss->ie_len); | |
52c9e6f3 JM |
2004 | #endif /* CONFIG_TDLS */ |
2005 | ||
5cc4d64b JM |
2006 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
2007 | ssid->mode == IEEE80211_MODE_INFRA) { | |
c2a04078 JM |
2008 | sme_authenticate(wpa_s, bss, ssid); |
2009 | return; | |
2010 | } | |
2011 | ||
6ac4b15e JM |
2012 | if (wpa_s->connect_work) { |
2013 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist"); | |
2014 | return; | |
2015 | } | |
2016 | ||
f0e30c84 JM |
2017 | if (radio_work_pending(wpa_s, "connect")) { |
2018 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist"); | |
2019 | return; | |
2020 | } | |
2021 | ||
a1836de6 JM |
2022 | #ifdef CONFIG_SME |
2023 | if (ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) { | |
2024 | /* Clear possibly set auth_alg, if any, from last attempt. */ | |
2025 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_OPEN; | |
2026 | } | |
2027 | #endif /* CONFIG_SME */ | |
2028 | ||
4ead7cfd KV |
2029 | wpas_abort_ongoing_scan(wpa_s); |
2030 | ||
6ac4b15e JM |
2031 | cwork = os_zalloc(sizeof(*cwork)); |
2032 | if (cwork == NULL) | |
2033 | return; | |
2034 | ||
2035 | cwork->bss = bss; | |
2036 | cwork->ssid = ssid; | |
2037 | ||
2038 | if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1, | |
2039 | wpas_start_assoc_cb, cwork) < 0) { | |
2040 | os_free(cwork); | |
2041 | } | |
2042 | } | |
2043 | ||
2044 | ||
98479dc9 JD |
2045 | static int bss_is_ibss(struct wpa_bss *bss) |
2046 | { | |
2047 | return (bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == | |
2048 | IEEE80211_CAP_IBSS; | |
2049 | } | |
2050 | ||
2051 | ||
a65efbfb PO |
2052 | static int drv_supports_vht(struct wpa_supplicant *wpa_s, |
2053 | const struct wpa_ssid *ssid) | |
2054 | { | |
2055 | enum hostapd_hw_mode hw_mode; | |
2056 | struct hostapd_hw_modes *mode = NULL; | |
2057 | u8 channel; | |
2058 | int i; | |
2059 | ||
a65efbfb PO |
2060 | hw_mode = ieee80211_freq_to_chan(ssid->frequency, &channel); |
2061 | if (hw_mode == NUM_HOSTAPD_MODES) | |
2062 | return 0; | |
2063 | for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) { | |
2064 | if (wpa_s->hw.modes[i].mode == hw_mode) { | |
2065 | mode = &wpa_s->hw.modes[i]; | |
2066 | break; | |
2067 | } | |
2068 | } | |
2069 | ||
2070 | if (!mode) | |
2071 | return 0; | |
2072 | ||
2073 | return mode->vht_capab != 0; | |
2074 | } | |
2075 | ||
2076 | ||
54fe48b9 JM |
2077 | void ibss_mesh_setup_freq(struct wpa_supplicant *wpa_s, |
2078 | const struct wpa_ssid *ssid, | |
2079 | struct hostapd_freq_params *freq) | |
1830817e JD |
2080 | { |
2081 | enum hostapd_hw_mode hw_mode; | |
2082 | struct hostapd_hw_modes *mode = NULL; | |
6b8b0774 JD |
2083 | int ht40plus[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, |
2084 | 184, 192 }; | |
563ee183 | 2085 | int vht80[] = { 36, 52, 100, 116, 132, 149 }; |
6b8b0774 | 2086 | struct hostapd_channel_data *pri_chan = NULL, *sec_chan = NULL; |
1830817e | 2087 | u8 channel; |
98479dc9 | 2088 | int i, chan_idx, ht40 = -1, res, obss_scan = 1; |
0f29bc68 | 2089 | unsigned int j, k; |
563ee183 | 2090 | struct hostapd_freq_params vht_freq; |
0f29bc68 AK |
2091 | int chwidth, seg0, seg1; |
2092 | u32 vht_caps = 0; | |
1830817e JD |
2093 | |
2094 | freq->freq = ssid->frequency; | |
2095 | ||
98479dc9 JD |
2096 | for (j = 0; j < wpa_s->last_scan_res_used; j++) { |
2097 | struct wpa_bss *bss = wpa_s->last_scan_res[j]; | |
2098 | ||
2099 | if (ssid->mode != WPAS_MODE_IBSS) | |
2100 | break; | |
2101 | ||
2102 | /* Don't adjust control freq in case of fixed_freq */ | |
2103 | if (ssid->fixed_freq) | |
2104 | break; | |
2105 | ||
2106 | if (!bss_is_ibss(bss)) | |
2107 | continue; | |
2108 | ||
2109 | if (ssid->ssid_len == bss->ssid_len && | |
2110 | os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) == 0) { | |
2111 | wpa_printf(MSG_DEBUG, | |
2112 | "IBSS already found in scan results, adjust control freq: %d", | |
2113 | bss->freq); | |
2114 | freq->freq = bss->freq; | |
2115 | obss_scan = 0; | |
2116 | break; | |
2117 | } | |
2118 | } | |
2119 | ||
1830817e JD |
2120 | /* For IBSS check HT_IBSS flag */ |
2121 | if (ssid->mode == WPAS_MODE_IBSS && | |
2122 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_HT_IBSS)) | |
2123 | return; | |
2124 | ||
d9a9bc04 JD |
2125 | if (wpa_s->group_cipher == WPA_CIPHER_WEP40 || |
2126 | wpa_s->group_cipher == WPA_CIPHER_WEP104 || | |
2127 | wpa_s->pairwise_cipher == WPA_CIPHER_TKIP) { | |
2128 | wpa_printf(MSG_DEBUG, | |
2129 | "IBSS: WEP/TKIP detected, do not try to enable HT"); | |
2130 | return; | |
2131 | } | |
2132 | ||
98479dc9 | 2133 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
1830817e JD |
2134 | for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) { |
2135 | if (wpa_s->hw.modes[i].mode == hw_mode) { | |
2136 | mode = &wpa_s->hw.modes[i]; | |
2137 | break; | |
2138 | } | |
2139 | } | |
2140 | ||
2141 | if (!mode) | |
2142 | return; | |
2143 | ||
3388e7b9 MH |
2144 | #ifdef CONFIG_HT_OVERRIDES |
2145 | if (ssid->disable_ht) { | |
2146 | freq->ht_enabled = 0; | |
2147 | return; | |
2148 | } | |
2149 | #endif /* CONFIG_HT_OVERRIDES */ | |
2150 | ||
1830817e | 2151 | freq->ht_enabled = ht_supported(mode); |
6b8b0774 JD |
2152 | if (!freq->ht_enabled) |
2153 | return; | |
2154 | ||
2155 | /* Setup higher BW only for 5 GHz */ | |
2156 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) | |
2157 | return; | |
2158 | ||
2159 | for (chan_idx = 0; chan_idx < mode->num_channels; chan_idx++) { | |
2160 | pri_chan = &mode->channels[chan_idx]; | |
2161 | if (pri_chan->chan == channel) | |
2162 | break; | |
2163 | pri_chan = NULL; | |
2164 | } | |
2165 | if (!pri_chan) | |
2166 | return; | |
2167 | ||
2168 | /* Check primary channel flags */ | |
2169 | if (pri_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) | |
2170 | return; | |
2171 | ||
05aed438 MH |
2172 | #ifdef CONFIG_HT_OVERRIDES |
2173 | if (ssid->disable_ht40) | |
2174 | return; | |
2175 | #endif /* CONFIG_HT_OVERRIDES */ | |
2176 | ||
6b8b0774 JD |
2177 | /* Check/setup HT40+/HT40- */ |
2178 | for (j = 0; j < ARRAY_SIZE(ht40plus); j++) { | |
2179 | if (ht40plus[j] == channel) { | |
2180 | ht40 = 1; | |
2181 | break; | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | /* Find secondary channel */ | |
2186 | for (i = 0; i < mode->num_channels; i++) { | |
2187 | sec_chan = &mode->channels[i]; | |
2188 | if (sec_chan->chan == channel + ht40 * 4) | |
2189 | break; | |
2190 | sec_chan = NULL; | |
2191 | } | |
2192 | if (!sec_chan) | |
2193 | return; | |
2194 | ||
2195 | /* Check secondary channel flags */ | |
2196 | if (sec_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) | |
2197 | return; | |
2198 | ||
2199 | freq->channel = pri_chan->chan; | |
2200 | ||
ecba4509 | 2201 | if (ht40 == -1) { |
6b8b0774 JD |
2202 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40MINUS)) |
2203 | return; | |
ecba4509 | 2204 | } else { |
6b8b0774 JD |
2205 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40PLUS)) |
2206 | return; | |
6b8b0774 | 2207 | } |
ecba4509 | 2208 | freq->sec_channel_offset = ht40; |
6b8b0774 | 2209 | |
ecba4509 | 2210 | if (obss_scan) { |
6b8b0774 JD |
2211 | struct wpa_scan_results *scan_res; |
2212 | ||
2213 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0); | |
2214 | if (scan_res == NULL) { | |
2215 | /* Back to HT20 */ | |
2216 | freq->sec_channel_offset = 0; | |
2217 | return; | |
2218 | } | |
2219 | ||
2220 | res = check_40mhz_5g(mode, scan_res, pri_chan->chan, | |
2221 | sec_chan->chan); | |
2222 | switch (res) { | |
2223 | case 0: | |
2224 | /* Back to HT20 */ | |
2225 | freq->sec_channel_offset = 0; | |
2226 | break; | |
2227 | case 1: | |
2228 | /* Configuration allowed */ | |
2229 | break; | |
2230 | case 2: | |
2231 | /* Switch pri/sec channels */ | |
2232 | freq->freq = hw_get_freq(mode, sec_chan->chan); | |
2233 | freq->sec_channel_offset = -freq->sec_channel_offset; | |
2234 | freq->channel = sec_chan->chan; | |
2235 | break; | |
2236 | default: | |
2237 | freq->sec_channel_offset = 0; | |
2238 | break; | |
2239 | } | |
2240 | ||
2241 | wpa_scan_results_free(scan_res); | |
2242 | } | |
2243 | ||
2244 | wpa_printf(MSG_DEBUG, | |
2245 | "IBSS/mesh: setup freq channel %d, sec_channel_offset %d", | |
2246 | freq->channel, freq->sec_channel_offset); | |
563ee183 | 2247 | |
a65efbfb | 2248 | if (!drv_supports_vht(wpa_s, ssid)) |
563ee183 JD |
2249 | return; |
2250 | ||
2251 | /* For IBSS check VHT_IBSS flag */ | |
a65efbfb PO |
2252 | if (ssid->mode == WPAS_MODE_IBSS && |
2253 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_VHT_IBSS)) | |
563ee183 JD |
2254 | return; |
2255 | ||
2256 | vht_freq = *freq; | |
2257 | ||
b301f54e JM |
2258 | #ifdef CONFIG_VHT_OVERRIDES |
2259 | if (ssid->disable_vht) { | |
2260 | freq->vht_enabled = 0; | |
2261 | return; | |
2262 | } | |
2263 | #endif /* CONFIG_VHT_OVERRIDES */ | |
2264 | ||
563ee183 JD |
2265 | vht_freq.vht_enabled = vht_supported(mode); |
2266 | if (!vht_freq.vht_enabled) | |
2267 | return; | |
2268 | ||
2269 | /* setup center_freq1, bandwidth */ | |
2270 | for (j = 0; j < ARRAY_SIZE(vht80); j++) { | |
2271 | if (freq->channel >= vht80[j] && | |
2272 | freq->channel < vht80[j] + 16) | |
2273 | break; | |
2274 | } | |
2275 | ||
2276 | if (j == ARRAY_SIZE(vht80)) | |
2277 | return; | |
2278 | ||
2279 | for (i = vht80[j]; i < vht80[j] + 16; i += 4) { | |
2280 | struct hostapd_channel_data *chan; | |
2281 | ||
2282 | chan = hw_get_channel_chan(mode, i, NULL); | |
2283 | if (!chan) | |
2284 | return; | |
2285 | ||
2286 | /* Back to HT configuration if channel not usable */ | |
2287 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) | |
2288 | return; | |
2289 | } | |
2290 | ||
0f29bc68 AK |
2291 | chwidth = VHT_CHANWIDTH_80MHZ; |
2292 | seg0 = vht80[j] + 6; | |
2293 | seg1 = 0; | |
2294 | ||
2295 | if (ssid->max_oper_chwidth == VHT_CHANWIDTH_80P80MHZ) { | |
2296 | /* setup center_freq2, bandwidth */ | |
2297 | for (k = 0; k < ARRAY_SIZE(vht80); k++) { | |
2298 | /* Only accept 80 MHz segments separated by a gap */ | |
2299 | if (j == k || abs(vht80[j] - vht80[k]) == 16) | |
2300 | continue; | |
2301 | for (i = vht80[k]; i < vht80[k] + 16; i += 4) { | |
2302 | struct hostapd_channel_data *chan; | |
2303 | ||
2304 | chan = hw_get_channel_chan(mode, i, NULL); | |
2305 | if (!chan) | |
2306 | continue; | |
2307 | ||
2308 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | | |
2309 | HOSTAPD_CHAN_NO_IR | | |
2310 | HOSTAPD_CHAN_RADAR)) | |
2311 | continue; | |
2312 | ||
2313 | /* Found a suitable second segment for 80+80 */ | |
2314 | chwidth = VHT_CHANWIDTH_80P80MHZ; | |
2315 | vht_caps |= | |
2316 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; | |
2317 | seg1 = vht80[k] + 6; | |
2318 | } | |
2319 | ||
2320 | if (chwidth == VHT_CHANWIDTH_80P80MHZ) | |
2321 | break; | |
2322 | } | |
331f0774 JM |
2323 | } else if (ssid->max_oper_chwidth == VHT_CHANWIDTH_160MHZ) { |
2324 | if (freq->freq == 5180) { | |
2325 | chwidth = VHT_CHANWIDTH_160MHZ; | |
2326 | vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; | |
2327 | seg0 = 50; | |
2328 | } else if (freq->freq == 5520) { | |
2329 | chwidth = VHT_CHANWIDTH_160MHZ; | |
2330 | vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; | |
2331 | seg0 = 114; | |
2332 | } | |
0f29bc68 AK |
2333 | } |
2334 | ||
563ee183 JD |
2335 | if (hostapd_set_freq_params(&vht_freq, mode->mode, freq->freq, |
2336 | freq->channel, freq->ht_enabled, | |
2337 | vht_freq.vht_enabled, | |
2338 | freq->sec_channel_offset, | |
0f29bc68 | 2339 | chwidth, seg0, seg1, vht_caps) != 0) |
563ee183 JD |
2340 | return; |
2341 | ||
2342 | *freq = vht_freq; | |
2343 | ||
2344 | wpa_printf(MSG_DEBUG, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d", | |
2345 | freq->center_freq1, freq->center_freq2, freq->bandwidth); | |
1830817e JD |
2346 | } |
2347 | ||
2348 | ||
a38090b1 VK |
2349 | #ifdef CONFIG_FILS |
2350 | static size_t wpas_add_fils_hlp_req(struct wpa_supplicant *wpa_s, u8 *ie_buf, | |
2351 | size_t ie_buf_len) | |
2352 | { | |
2353 | struct fils_hlp_req *req; | |
2354 | size_t rem_len, hdr_len, hlp_len, len, ie_len = 0; | |
2355 | const u8 *pos; | |
2356 | u8 *buf = ie_buf; | |
2357 | ||
2358 | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, | |
2359 | list) { | |
2360 | rem_len = ie_buf_len - ie_len; | |
2361 | pos = wpabuf_head(req->pkt); | |
2362 | hdr_len = 1 + 2 * ETH_ALEN + 6; | |
2363 | hlp_len = wpabuf_len(req->pkt); | |
2364 | ||
2365 | if (rem_len < 2 + hdr_len + hlp_len) { | |
2366 | wpa_printf(MSG_ERROR, | |
2367 | "FILS: Cannot fit HLP - rem_len=%lu to_fill=%lu", | |
2368 | (unsigned long) rem_len, | |
2369 | (unsigned long) (2 + hdr_len + hlp_len)); | |
2370 | break; | |
2371 | } | |
2372 | ||
2373 | len = (hdr_len + hlp_len) > 255 ? 255 : hdr_len + hlp_len; | |
2374 | /* Element ID */ | |
2375 | *buf++ = WLAN_EID_EXTENSION; | |
2376 | /* Length */ | |
2377 | *buf++ = len; | |
2378 | /* Element ID Extension */ | |
2379 | *buf++ = WLAN_EID_EXT_FILS_HLP_CONTAINER; | |
2380 | /* Destination MAC address */ | |
2381 | os_memcpy(buf, req->dst, ETH_ALEN); | |
2382 | buf += ETH_ALEN; | |
2383 | /* Source MAC address */ | |
2384 | os_memcpy(buf, wpa_s->own_addr, ETH_ALEN); | |
2385 | buf += ETH_ALEN; | |
2386 | /* LLC/SNAP Header */ | |
2387 | os_memcpy(buf, "\xaa\xaa\x03\x00\x00\x00", 6); | |
2388 | buf += 6; | |
2389 | /* HLP Packet */ | |
2390 | os_memcpy(buf, pos, len - hdr_len); | |
2391 | buf += len - hdr_len; | |
2392 | pos += len - hdr_len; | |
2393 | ||
2394 | hlp_len -= len - hdr_len; | |
2395 | ie_len += 2 + len; | |
2396 | rem_len -= 2 + len; | |
2397 | ||
2398 | while (hlp_len) { | |
2399 | len = (hlp_len > 255) ? 255 : hlp_len; | |
2400 | if (rem_len < 2 + len) | |
2401 | break; | |
2402 | *buf++ = WLAN_EID_FRAGMENT; | |
2403 | *buf++ = len; | |
2404 | os_memcpy(buf, pos, len); | |
2405 | buf += len; | |
2406 | pos += len; | |
2407 | ||
2408 | hlp_len -= len; | |
2409 | ie_len += 2 + len; | |
2410 | rem_len -= 2 + len; | |
2411 | } | |
2412 | } | |
2413 | ||
2414 | return ie_len; | |
2415 | } | |
e4802127 MH |
2416 | |
2417 | ||
2418 | int wpa_is_fils_supported(struct wpa_supplicant *wpa_s) | |
2419 | { | |
2420 | return (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
2421 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) || | |
2422 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
2423 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD))); | |
2424 | } | |
2425 | ||
2426 | ||
2427 | int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant *wpa_s) | |
2428 | { | |
2429 | #ifdef CONFIG_FILS_SK_PFS | |
2430 | return (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
2431 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS); | |
2432 | #else /* CONFIG_FILS_SK_PFS */ | |
2433 | return 0; | |
2434 | #endif /* CONFIG_FILS_SK_PFS */ | |
2435 | } | |
2436 | ||
a38090b1 VK |
2437 | #endif /* CONFIG_FILS */ |
2438 | ||
2439 | ||
d2ba0d71 VK |
2440 | static u8 * wpas_populate_assoc_ies( |
2441 | struct wpa_supplicant *wpa_s, | |
2442 | struct wpa_bss *bss, struct wpa_ssid *ssid, | |
6338c99e VK |
2443 | struct wpa_driver_associate_params *params, |
2444 | enum wpa_drv_update_connect_params_mask *mask) | |
6ac4b15e | 2445 | { |
1e6780bd | 2446 | u8 *wpa_ie; |
10970465 | 2447 | size_t max_wpa_ie_len = 500; |
6ac4b15e | 2448 | size_t wpa_ie_len; |
6ac4b15e | 2449 | int algs = WPA_AUTH_ALG_OPEN; |
077232f6 BL |
2450 | #ifdef CONFIG_MBO |
2451 | const u8 *mbo_ie; | |
2452 | #endif | |
8b0a6dba VK |
2453 | #ifdef CONFIG_FILS |
2454 | const u8 *realm, *username, *rrk; | |
2455 | size_t realm_len, username_len, rrk_len; | |
2456 | u16 next_seq_num; | |
b377ec25 | 2457 | struct fils_hlp_req *req; |
6fc6879b | 2458 | |
b377ec25 VK |
2459 | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, |
2460 | list) { | |
2461 | max_wpa_ie_len += 3 + 2 * ETH_ALEN + 6 + wpabuf_len(req->pkt) + | |
2462 | 2 + 2 * wpabuf_len(req->pkt) / 255; | |
8b0a6dba VK |
2463 | } |
2464 | #endif /* CONFIG_FILS */ | |
8b0a6dba | 2465 | |
1e6780bd VK |
2466 | wpa_ie = os_malloc(max_wpa_ie_len); |
2467 | if (!wpa_ie) { | |
2468 | wpa_printf(MSG_ERROR, | |
2469 | "Failed to allocate connect IE buffer for %lu bytes", | |
2470 | (unsigned long) max_wpa_ie_len); | |
d2ba0d71 | 2471 | return NULL; |
1e6780bd VK |
2472 | } |
2473 | ||
6fa81a3b JM |
2474 | if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
2475 | wpa_bss_get_ie(bss, WLAN_EID_RSN)) && | |
0bf927a0 | 2476 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
6fc6879b | 2477 | int try_opportunistic; |
79f3121b VK |
2478 | const u8 *cache_id = NULL; |
2479 | ||
6e202021 JM |
2480 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
2481 | wpa_s->conf->okc : | |
2482 | ssid->proactive_key_caching) && | |
6fc6879b | 2483 | (ssid->proto & WPA_PROTO_RSN); |
79f3121b VK |
2484 | #ifdef CONFIG_FILS |
2485 | if (wpa_key_mgmt_fils(ssid->key_mgmt)) | |
2486 | cache_id = wpa_bss_get_fils_cache_id(bss); | |
2487 | #endif /* CONFIG_FILS */ | |
6fc6879b | 2488 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
79f3121b | 2489 | ssid, try_opportunistic, |
852b2f27 | 2490 | cache_id, 0) == 0) |
ba422613 | 2491 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
1e6780bd | 2492 | wpa_ie_len = max_wpa_ie_len; |
6fc6879b JM |
2493 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
2494 | wpa_ie, &wpa_ie_len)) { | |
f049052b BG |
2495 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
2496 | "key management and encryption suites"); | |
1e6780bd | 2497 | os_free(wpa_ie); |
d2ba0d71 | 2498 | return NULL; |
6fc6879b | 2499 | } |
dc673aec JM |
2500 | #ifdef CONFIG_HS20 |
2501 | } else if (bss && wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE) && | |
2502 | (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)) { | |
2503 | /* No PMKSA caching, but otherwise similar to RSN/WPA */ | |
2504 | wpa_ie_len = max_wpa_ie_len; | |
2505 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, | |
2506 | wpa_ie, &wpa_ie_len)) { | |
2507 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " | |
2508 | "key management and encryption suites"); | |
2509 | os_free(wpa_ie); | |
2510 | return NULL; | |
2511 | } | |
2512 | #endif /* CONFIG_HS20 */ | |
a3f7e518 JM |
2513 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss && |
2514 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { | |
2515 | /* | |
2516 | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - | |
2517 | * use non-WPA since the scan results did not indicate that the | |
2518 | * AP is using WPA or WPA2. | |
2519 | */ | |
2520 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
2521 | wpa_ie_len = 0; | |
2522 | wpa_s->wpa_proto = 0; | |
0bf927a0 | 2523 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
1e6780bd | 2524 | wpa_ie_len = max_wpa_ie_len; |
6fc6879b JM |
2525 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
2526 | wpa_ie, &wpa_ie_len)) { | |
f049052b BG |
2527 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
2528 | "key management and encryption suites (no " | |
2529 | "scan results)"); | |
1e6780bd | 2530 | os_free(wpa_ie); |
d2ba0d71 | 2531 | return NULL; |
6fc6879b | 2532 | } |
ad08c363 JM |
2533 | #ifdef CONFIG_WPS |
2534 | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { | |
b01c18a8 JM |
2535 | struct wpabuf *wps_ie; |
2536 | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); | |
1e6780bd | 2537 | if (wps_ie && wpabuf_len(wps_ie) <= max_wpa_ie_len) { |
ad08c363 JM |
2538 | wpa_ie_len = wpabuf_len(wps_ie); |
2539 | os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len); | |
24386985 JM |
2540 | } else |
2541 | wpa_ie_len = 0; | |
ad08c363 JM |
2542 | wpabuf_free(wps_ie); |
2543 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
0c80427d | 2544 | if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY)) |
d2ba0d71 | 2545 | params->wps = WPS_MODE_PRIVACY; |
0c80427d | 2546 | else |
d2ba0d71 | 2547 | params->wps = WPS_MODE_OPEN; |
cf546f1a | 2548 | wpa_s->wpa_proto = 0; |
ad08c363 | 2549 | #endif /* CONFIG_WPS */ |
6fc6879b JM |
2550 | } else { |
2551 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
2552 | wpa_ie_len = 0; | |
cf546f1a | 2553 | wpa_s->wpa_proto = 0; |
6fc6879b JM |
2554 | } |
2555 | ||
b377ec25 VK |
2556 | #ifdef IEEE8021X_EAPOL |
2557 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
2558 | if (ssid->leap) { | |
2559 | if (ssid->non_leap == 0) | |
2560 | algs = WPA_AUTH_ALG_LEAP; | |
2561 | else | |
2562 | algs |= WPA_AUTH_ALG_LEAP; | |
2563 | } | |
2564 | } | |
2565 | ||
2566 | #ifdef CONFIG_FILS | |
2567 | /* Clear FILS association */ | |
2568 | wpa_sm_set_reset_fils_completed(wpa_s->wpa, 0); | |
2569 | ||
2570 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) && | |
2571 | ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) && | |
2572 | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, &username, | |
2573 | &username_len, &realm, &realm_len, | |
af835d75 AB |
2574 | &next_seq_num, &rrk, &rrk_len) == 0 && |
2575 | (!wpa_s->last_con_fail_realm || | |
2576 | wpa_s->last_con_fail_realm_len != realm_len || | |
2577 | os_memcmp(wpa_s->last_con_fail_realm, realm, realm_len) != 0)) { | |
b377ec25 | 2578 | algs = WPA_AUTH_ALG_FILS; |
d2ba0d71 VK |
2579 | params->fils_erp_username = username; |
2580 | params->fils_erp_username_len = username_len; | |
2581 | params->fils_erp_realm = realm; | |
2582 | params->fils_erp_realm_len = realm_len; | |
2583 | params->fils_erp_next_seq_num = next_seq_num; | |
2584 | params->fils_erp_rrk = rrk; | |
2585 | params->fils_erp_rrk_len = rrk_len; | |
6338c99e VK |
2586 | |
2587 | if (mask) | |
2588 | *mask |= WPA_DRV_UPDATE_FILS_ERP_INFO; | |
b377ec25 VK |
2589 | } |
2590 | #endif /* CONFIG_FILS */ | |
2591 | #endif /* IEEE8021X_EAPOL */ | |
5ff39c13 SD |
2592 | #ifdef CONFIG_SAE |
2593 | if (wpa_s->key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE)) | |
2594 | algs = WPA_AUTH_ALG_SAE; | |
2595 | #endif /* CONFIG_SAE */ | |
b377ec25 VK |
2596 | |
2597 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs); | |
2598 | if (ssid->auth_alg) { | |
2599 | algs = ssid->auth_alg; | |
2600 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2601 | "Overriding auth_alg selection: 0x%x", algs); | |
2602 | } | |
2603 | ||
5f3a6aa0 JM |
2604 | #ifdef CONFIG_P2P |
2605 | if (wpa_s->global->p2p) { | |
2606 | u8 *pos; | |
2607 | size_t len; | |
2608 | int res; | |
5f3a6aa0 | 2609 | pos = wpa_ie + wpa_ie_len; |
1e6780bd | 2610 | len = max_wpa_ie_len - wpa_ie_len; |
b8a8d677 JM |
2611 | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
2612 | ssid->p2p_group); | |
5f3a6aa0 JM |
2613 | if (res >= 0) |
2614 | wpa_ie_len += res; | |
2615 | } | |
72044390 JM |
2616 | |
2617 | wpa_s->cross_connect_disallowed = 0; | |
2618 | if (bss) { | |
2619 | struct wpabuf *p2p; | |
2620 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); | |
2621 | if (p2p) { | |
2622 | wpa_s->cross_connect_disallowed = | |
2623 | p2p_get_cross_connect_disallowed(p2p); | |
2624 | wpabuf_free(p2p); | |
f049052b BG |
2625 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross " |
2626 | "connection", | |
2627 | wpa_s->cross_connect_disallowed ? | |
2628 | "disallows" : "allows"); | |
72044390 JM |
2629 | } |
2630 | } | |
25ef8529 JM |
2631 | |
2632 | os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info)); | |
5f3a6aa0 JM |
2633 | #endif /* CONFIG_P2P */ |
2634 | ||
5e57ba25 | 2635 | if (bss) { |
065c029a | 2636 | wpa_ie_len += wpas_supp_op_class_ie(wpa_s, bss->freq, |
2637 | wpa_ie + wpa_ie_len, | |
1e6780bd | 2638 | max_wpa_ie_len - |
065c029a | 2639 | wpa_ie_len); |
5e57ba25 | 2640 | } |
5e57ba25 | 2641 | |
8b3b803a AH |
2642 | /* |
2643 | * Workaround: Add Extended Capabilities element only if the AP | |
2644 | * included this element in Beacon/Probe Response frames. Some older | |
2645 | * APs seem to have interoperability issues if this element is | |
2646 | * included, so while the standard may require us to include the | |
2647 | * element in all cases, it is justifiable to skip it to avoid | |
2648 | * interoperability issues. | |
2649 | */ | |
cc9a2575 KV |
2650 | if (ssid->p2p_group) |
2651 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT); | |
2652 | else | |
2653 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); | |
2654 | ||
8b3b803a | 2655 | if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) { |
0bbaa9b9 | 2656 | u8 ext_capab[18]; |
8b3b803a | 2657 | int ext_capab_len; |
0bbaa9b9 JM |
2658 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
2659 | sizeof(ext_capab)); | |
2c66c7d1 AA |
2660 | if (ext_capab_len > 0 && |
2661 | wpa_ie_len + ext_capab_len <= max_wpa_ie_len) { | |
8b3b803a AH |
2662 | u8 *pos = wpa_ie; |
2663 | if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN) | |
2664 | pos += 2 + pos[1]; | |
2665 | os_memmove(pos + ext_capab_len, pos, | |
2666 | wpa_ie_len - (pos - wpa_ie)); | |
2667 | wpa_ie_len += ext_capab_len; | |
2668 | os_memcpy(pos, ext_capab, ext_capab_len); | |
2669 | } | |
92cbcf91 | 2670 | } |
92cbcf91 | 2671 | |
c484b198 AS |
2672 | #ifdef CONFIG_HS20 |
2673 | if (is_hs20_network(wpa_s, ssid, bss)) { | |
2674 | struct wpabuf *hs20; | |
2675 | ||
4204669c | 2676 | hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN); |
c484b198 AS |
2677 | if (hs20) { |
2678 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); | |
2679 | size_t len; | |
2680 | ||
ec2cf403 JM |
2681 | wpas_hs20_add_indication(hs20, pps_mo_id, |
2682 | get_hs20_version(bss)); | |
4204669c | 2683 | wpas_hs20_add_roam_cons_sel(hs20, ssid); |
1e6780bd | 2684 | len = max_wpa_ie_len - wpa_ie_len; |
c484b198 AS |
2685 | if (wpabuf_len(hs20) <= len) { |
2686 | os_memcpy(wpa_ie + wpa_ie_len, | |
2687 | wpabuf_head(hs20), wpabuf_len(hs20)); | |
2688 | wpa_ie_len += wpabuf_len(hs20); | |
2689 | } | |
2690 | wpabuf_free(hs20); | |
ece4ac5f MG |
2691 | |
2692 | hs20_configure_frame_filters(wpa_s); | |
c484b198 AS |
2693 | } |
2694 | } | |
2695 | #endif /* CONFIG_HS20 */ | |
2696 | ||
d29fa3a7 JM |
2697 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
2698 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; | |
2699 | size_t len; | |
2700 | ||
1e6780bd | 2701 | len = max_wpa_ie_len - wpa_ie_len; |
d29fa3a7 JM |
2702 | if (wpabuf_len(buf) <= len) { |
2703 | os_memcpy(wpa_ie + wpa_ie_len, | |
2704 | wpabuf_head(buf), wpabuf_len(buf)); | |
2705 | wpa_ie_len += wpabuf_len(buf); | |
2706 | } | |
2707 | } | |
2708 | ||
b36a3a65 AN |
2709 | #ifdef CONFIG_FST |
2710 | if (wpa_s->fst_ies) { | |
2711 | int fst_ies_len = wpabuf_len(wpa_s->fst_ies); | |
2712 | ||
1e6780bd | 2713 | if (wpa_ie_len + fst_ies_len <= max_wpa_ie_len) { |
b36a3a65 AN |
2714 | os_memcpy(wpa_ie + wpa_ie_len, |
2715 | wpabuf_head(wpa_s->fst_ies), fst_ies_len); | |
2716 | wpa_ie_len += fst_ies_len; | |
2717 | } | |
2718 | } | |
2719 | #endif /* CONFIG_FST */ | |
2720 | ||
92c6e2e3 | 2721 | #ifdef CONFIG_MBO |
077232f6 BL |
2722 | mbo_ie = bss ? wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE) : NULL; |
2723 | if (mbo_ie) { | |
5e57ba25 | 2724 | int len; |
92c6e2e3 | 2725 | |
5e57ba25 | 2726 | len = wpas_mbo_ie(wpa_s, wpa_ie + wpa_ie_len, |
077232f6 BL |
2727 | max_wpa_ie_len - wpa_ie_len, |
2728 | !!mbo_attr_from_mbo_ie(mbo_ie, | |
2729 | OCE_ATTR_ID_CAPA_IND)); | |
5e57ba25 AS |
2730 | if (len >= 0) |
2731 | wpa_ie_len += len; | |
92c6e2e3 DS |
2732 | } |
2733 | #endif /* CONFIG_MBO */ | |
2734 | ||
a38090b1 VK |
2735 | #ifdef CONFIG_FILS |
2736 | if (algs == WPA_AUTH_ALG_FILS) { | |
2737 | size_t len; | |
2738 | ||
2739 | len = wpas_add_fils_hlp_req(wpa_s, wpa_ie + wpa_ie_len, | |
2740 | max_wpa_ie_len - wpa_ie_len); | |
2741 | wpa_ie_len += len; | |
2742 | } | |
2743 | #endif /* CONFIG_FILS */ | |
2744 | ||
10970465 | 2745 | #ifdef CONFIG_OWE |
5f30b69c JM |
2746 | #ifdef CONFIG_TESTING_OPTIONS |
2747 | if (get_ie_ext(wpa_ie, wpa_ie_len, WLAN_EID_EXT_OWE_DH_PARAM)) { | |
2748 | wpa_printf(MSG_INFO, "TESTING: Override OWE DH element"); | |
2749 | } else | |
2750 | #endif /* CONFIG_TESTING_OPTIONS */ | |
10970465 JM |
2751 | if (algs == WPA_AUTH_ALG_OPEN && |
2752 | ssid->key_mgmt == WPA_KEY_MGMT_OWE) { | |
2753 | struct wpabuf *owe_ie; | |
2cb40e9f | 2754 | u16 group; |
10970465 | 2755 | |
2cb40e9f | 2756 | if (ssid->owe_group) { |
10970465 | 2757 | group = ssid->owe_group; |
698c9e20 AK |
2758 | } else if (wpa_s->assoc_status_code == |
2759 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { | |
2cb40e9f JM |
2760 | if (wpa_s->last_owe_group == 19) |
2761 | group = 20; | |
2762 | else if (wpa_s->last_owe_group == 20) | |
2763 | group = 21; | |
2764 | else | |
2765 | group = OWE_DH_GROUP; | |
698c9e20 AK |
2766 | } else { |
2767 | group = OWE_DH_GROUP; | |
2cb40e9f | 2768 | } |
698c9e20 | 2769 | |
2cb40e9f JM |
2770 | wpa_s->last_owe_group = group; |
2771 | wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group); | |
10970465 JM |
2772 | owe_ie = owe_build_assoc_req(wpa_s->wpa, group); |
2773 | if (owe_ie && | |
2774 | wpabuf_len(owe_ie) <= max_wpa_ie_len - wpa_ie_len) { | |
2775 | os_memcpy(wpa_ie + wpa_ie_len, | |
2776 | wpabuf_head(owe_ie), wpabuf_len(owe_ie)); | |
2777 | wpa_ie_len += wpabuf_len(owe_ie); | |
2778 | wpabuf_free(owe_ie); | |
2779 | } | |
2780 | } | |
2781 | #endif /* CONFIG_OWE */ | |
2782 | ||
3dc3afe2 AM |
2783 | #ifdef CONFIG_IEEE80211R |
2784 | /* | |
2785 | * Add MDIE under these conditions: the network profile allows FT, | |
2786 | * the AP supports FT, and the mobility domain ID matches. | |
2787 | */ | |
88bf44be | 2788 | if (bss && wpa_key_mgmt_ft(wpa_sm_get_key_mgmt(wpa_s->wpa))) { |
3dc3afe2 AM |
2789 | const u8 *mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
2790 | ||
2791 | if (mdie && mdie[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
86c998d3 | 2792 | size_t len = 0; |
3dc3afe2 AM |
2793 | const u8 *md = mdie + 2; |
2794 | const u8 *wpa_md = wpa_sm_get_ft_md(wpa_s->wpa); | |
2795 | ||
2796 | if (os_memcmp(md, wpa_md, | |
2797 | MOBILITY_DOMAIN_ID_LEN) == 0) { | |
2798 | /* Add mobility domain IE */ | |
86c998d3 | 2799 | len = wpa_ft_add_mdie( |
3dc3afe2 AM |
2800 | wpa_s->wpa, wpa_ie + wpa_ie_len, |
2801 | max_wpa_ie_len - wpa_ie_len, mdie); | |
86c998d3 | 2802 | wpa_ie_len += len; |
3dc3afe2 | 2803 | } |
86c998d3 AM |
2804 | #ifdef CONFIG_SME |
2805 | if (len > 0 && wpa_s->sme.ft_used && | |
2806 | wpa_sm_has_ptk(wpa_s->wpa)) { | |
2807 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2808 | "SME: Trying to use FT over-the-air"); | |
2809 | algs |= WPA_AUTH_ALG_FT; | |
2810 | } | |
2811 | #endif /* CONFIG_SME */ | |
3dc3afe2 AM |
2812 | } |
2813 | } | |
2814 | #endif /* CONFIG_IEEE80211R */ | |
2815 | ||
d2ba0d71 VK |
2816 | params->wpa_ie = wpa_ie; |
2817 | params->wpa_ie_len = wpa_ie_len; | |
2818 | params->auth_alg = algs; | |
6338c99e VK |
2819 | if (mask) |
2820 | *mask |= WPA_DRV_UPDATE_ASSOC_IES | WPA_DRV_UPDATE_AUTH_TYPE; | |
d2ba0d71 VK |
2821 | |
2822 | return wpa_ie; | |
2823 | } | |
2824 | ||
2825 | ||
6338c99e VK |
2826 | #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL) |
2827 | static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s) | |
2828 | { | |
2829 | struct wpa_driver_associate_params params; | |
2830 | enum wpa_drv_update_connect_params_mask mask = 0; | |
2831 | u8 *wpa_ie; | |
2832 | ||
2833 | if (wpa_s->auth_alg != WPA_AUTH_ALG_OPEN) | |
2834 | return; /* nothing to do */ | |
2835 | ||
2836 | os_memset(¶ms, 0, sizeof(params)); | |
2837 | wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss, | |
2838 | wpa_s->current_ssid, ¶ms, &mask); | |
2839 | if (!wpa_ie) | |
2840 | return; | |
2841 | ||
2842 | if (params.auth_alg != WPA_AUTH_ALG_FILS) { | |
2843 | os_free(wpa_ie); | |
2844 | return; | |
2845 | } | |
2846 | ||
2847 | wpa_s->auth_alg = params.auth_alg; | |
2848 | wpa_drv_update_connect_params(wpa_s, ¶ms, mask); | |
2849 | os_free(wpa_ie); | |
2850 | } | |
2851 | #endif /* CONFIG_FILS && IEEE8021X_EAPOL */ | |
2852 | ||
2853 | ||
d2ba0d71 VK |
2854 | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit) |
2855 | { | |
2856 | struct wpa_connect_work *cwork = work->ctx; | |
2857 | struct wpa_bss *bss = cwork->bss; | |
2858 | struct wpa_ssid *ssid = cwork->ssid; | |
2859 | struct wpa_supplicant *wpa_s = work->wpa_s; | |
2860 | u8 *wpa_ie; | |
2861 | int use_crypt, ret, i, bssid_changed; | |
2862 | unsigned int cipher_pairwise, cipher_group, cipher_group_mgmt; | |
2863 | struct wpa_driver_associate_params params; | |
2864 | int wep_keys_set = 0; | |
2865 | int assoc_failed = 0; | |
2866 | struct wpa_ssid *old_ssid; | |
2867 | u8 prev_bssid[ETH_ALEN]; | |
2868 | #ifdef CONFIG_HT_OVERRIDES | |
2869 | struct ieee80211_ht_capabilities htcaps; | |
2870 | struct ieee80211_ht_capabilities htcaps_mask; | |
2871 | #endif /* CONFIG_HT_OVERRIDES */ | |
2872 | #ifdef CONFIG_VHT_OVERRIDES | |
2873 | struct ieee80211_vht_capabilities vhtcaps; | |
2874 | struct ieee80211_vht_capabilities vhtcaps_mask; | |
2875 | #endif /* CONFIG_VHT_OVERRIDES */ | |
2876 | ||
2877 | if (deinit) { | |
2878 | if (work->started) { | |
2879 | wpa_s->connect_work = NULL; | |
2880 | ||
2881 | /* cancel possible auth. timeout */ | |
2882 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, | |
2883 | NULL); | |
2884 | } | |
2885 | wpas_connect_work_free(cwork); | |
2886 | return; | |
2887 | } | |
2888 | ||
2889 | wpa_s->connect_work = work; | |
2890 | ||
2891 | if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid) || | |
2892 | wpas_network_disabled(wpa_s, ssid)) { | |
2893 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt"); | |
2894 | wpas_connect_work_done(wpa_s); | |
2895 | return; | |
2896 | } | |
2897 | ||
2898 | os_memcpy(prev_bssid, wpa_s->bssid, ETH_ALEN); | |
2899 | os_memset(¶ms, 0, sizeof(params)); | |
2900 | wpa_s->reassociate = 0; | |
2901 | wpa_s->eap_expected_failure = 0; | |
2902 | if (bss && | |
2903 | (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) { | |
2904 | #ifdef CONFIG_IEEE80211R | |
2905 | const u8 *ie, *md = NULL; | |
2906 | #endif /* CONFIG_IEEE80211R */ | |
2907 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR | |
2908 | " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid), | |
2909 | wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq); | |
2910 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); | |
2911 | os_memset(wpa_s->bssid, 0, ETH_ALEN); | |
2912 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); | |
2913 | if (bssid_changed) | |
2914 | wpas_notify_bssid_changed(wpa_s); | |
2915 | #ifdef CONFIG_IEEE80211R | |
2916 | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); | |
2917 | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) | |
2918 | md = ie + 2; | |
2919 | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); | |
2920 | if (md) { | |
2921 | /* Prepare for the next transition */ | |
2922 | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); | |
2923 | } | |
2924 | #endif /* CONFIG_IEEE80211R */ | |
2925 | #ifdef CONFIG_WPS | |
2926 | } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) && | |
2927 | wpa_s->conf->ap_scan == 2 && | |
2928 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
2929 | /* Use ap_scan==1 style network selection to find the network | |
2930 | */ | |
2931 | wpas_connect_work_done(wpa_s); | |
2932 | wpa_s->scan_req = MANUAL_SCAN_REQ; | |
2933 | wpa_s->reassociate = 1; | |
2934 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2935 | return; | |
2936 | #endif /* CONFIG_WPS */ | |
2937 | } else { | |
2938 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'", | |
2939 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
2940 | if (bss) | |
2941 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); | |
2942 | else | |
2943 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
2944 | } | |
2945 | if (!wpa_s->pno) | |
2946 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
2947 | ||
2948 | wpa_supplicant_cancel_scan(wpa_s); | |
2949 | ||
2950 | /* Starting new association, so clear the possibly used WPA IE from the | |
2951 | * previous association. */ | |
2952 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
2953 | ||
6338c99e | 2954 | wpa_ie = wpas_populate_assoc_ies(wpa_s, bss, ssid, ¶ms, NULL); |
d2ba0d71 VK |
2955 | if (!wpa_ie) { |
2956 | wpas_connect_work_done(wpa_s); | |
2957 | return; | |
2958 | } | |
2959 | ||
6fc6879b JM |
2960 | wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL); |
2961 | use_crypt = 1; | |
4848a38d JM |
2962 | cipher_pairwise = wpa_s->pairwise_cipher; |
2963 | cipher_group = wpa_s->group_cipher; | |
61a56c14 | 2964 | cipher_group_mgmt = wpa_s->mgmt_group_cipher; |
6fc6879b JM |
2965 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
2966 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
2967 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) | |
2968 | use_crypt = 0; | |
2969 | if (wpa_set_wep_keys(wpa_s, ssid)) { | |
2970 | use_crypt = 1; | |
2971 | wep_keys_set = 1; | |
2972 | } | |
2973 | } | |
ad08c363 JM |
2974 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) |
2975 | use_crypt = 0; | |
6fc6879b JM |
2976 | |
2977 | #ifdef IEEE8021X_EAPOL | |
2978 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
2979 | if ((ssid->eapol_flags & | |
2980 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
2981 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 && | |
2982 | !wep_keys_set) { | |
2983 | use_crypt = 0; | |
2984 | } else { | |
2985 | /* Assume that dynamic WEP-104 keys will be used and | |
2986 | * set cipher suites in order for drivers to expect | |
2987 | * encryption. */ | |
4848a38d | 2988 | cipher_pairwise = cipher_group = WPA_CIPHER_WEP104; |
6fc6879b JM |
2989 | } |
2990 | } | |
2991 | #endif /* IEEE8021X_EAPOL */ | |
2992 | ||
2993 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2994 | /* Set the key before (and later after) association */ | |
2995 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); | |
2996 | } | |
2997 | ||
6fc6879b | 2998 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); |
6fc6879b | 2999 | if (bss) { |
6fa81a3b JM |
3000 | params.ssid = bss->ssid; |
3001 | params.ssid_len = bss->ssid_len; | |
4b5b8a53 JM |
3002 | if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set || |
3003 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
f15854d1 JM |
3004 | wpa_printf(MSG_DEBUG, "Limit connection to BSSID " |
3005 | MACSTR " freq=%u MHz based on scan results " | |
4b5b8a53 | 3006 | "(bssid_set=%d wps=%d)", |
f15854d1 | 3007 | MAC2STR(bss->bssid), bss->freq, |
4b5b8a53 JM |
3008 | ssid->bssid_set, |
3009 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); | |
22628eca | 3010 | params.bssid = bss->bssid; |
4ec68377 | 3011 | params.freq.freq = bss->freq; |
22628eca | 3012 | } |
7ac7fd43 DS |
3013 | params.bssid_hint = bss->bssid; |
3014 | params.freq_hint = bss->freq; | |
b9074912 | 3015 | params.pbss = bss_is_pbss(bss); |
6fc6879b | 3016 | } else { |
43a356b2 PK |
3017 | if (ssid->bssid_hint_set) |
3018 | params.bssid_hint = ssid->bssid_hint; | |
3019 | ||
6fc6879b JM |
3020 | params.ssid = ssid->ssid; |
3021 | params.ssid_len = ssid->ssid_len; | |
90f14962 | 3022 | params.pbss = (ssid->pbss != 2) ? ssid->pbss : 0; |
6fc6879b | 3023 | } |
9e2af29f NC |
3024 | |
3025 | if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set && | |
3026 | wpa_s->conf->ap_scan == 2) { | |
3027 | params.bssid = ssid->bssid; | |
3028 | params.fixed_bssid = 1; | |
3029 | } | |
3030 | ||
603a3f34 JL |
3031 | /* Initial frequency for IBSS/mesh */ |
3032 | if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) && | |
1830817e JD |
3033 | ssid->frequency > 0 && params.freq.freq == 0) |
3034 | ibss_mesh_setup_freq(wpa_s, ssid, ¶ms.freq); | |
dc152f32 | 3035 | |
8f05577d | 3036 | if (ssid->mode == WPAS_MODE_IBSS) { |
4d9e6fba | 3037 | params.fixed_freq = ssid->fixed_freq; |
8f05577d JM |
3038 | if (ssid->beacon_int) |
3039 | params.beacon_int = ssid->beacon_int; | |
3040 | else | |
3041 | params.beacon_int = wpa_s->conf->beacon_int; | |
3042 | } | |
3043 | ||
6fc6879b JM |
3044 | params.pairwise_suite = cipher_pairwise; |
3045 | params.group_suite = cipher_group; | |
61a56c14 | 3046 | params.mgmt_group_suite = cipher_group_mgmt; |
4848a38d | 3047 | params.key_mgmt_suite = wpa_s->key_mgmt; |
64fa840a | 3048 | params.wpa_proto = wpa_s->wpa_proto; |
5538fc93 | 3049 | wpa_s->auth_alg = params.auth_alg; |
6fc6879b | 3050 | params.mode = ssid->mode; |
1f6c0ab8 | 3051 | params.bg_scan_period = ssid->bg_scan_period; |
6fc6879b JM |
3052 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
3053 | if (ssid->wep_key_len[i]) | |
3054 | params.wep_key[i] = ssid->wep_key[i]; | |
3055 | params.wep_key_len[i] = ssid->wep_key_len[i]; | |
3056 | } | |
3057 | params.wep_tx_keyidx = ssid->wep_tx_keyidx; | |
3058 | ||
c2a04078 | 3059 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
4848a38d JM |
3060 | (params.key_mgmt_suite == WPA_KEY_MGMT_PSK || |
3061 | params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
6fc6879b JM |
3062 | params.passphrase = ssid->passphrase; |
3063 | if (ssid->psk_set) | |
3064 | params.psk = ssid->psk; | |
b41f2684 CL |
3065 | } |
3066 | ||
3067 | if (wpa_s->conf->key_mgmt_offload) { | |
3068 | if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || | |
666497c8 | 3069 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
5e3b5197 JM |
3070 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
3071 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) | |
b41f2684 CL |
3072 | params.req_key_mgmt_offload = |
3073 | ssid->proactive_key_caching < 0 ? | |
3074 | wpa_s->conf->okc : ssid->proactive_key_caching; | |
3075 | else | |
3076 | params.req_key_mgmt_offload = 1; | |
3077 | ||
3078 | if ((params.key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
3079 | params.key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
3080 | params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK) && | |
3081 | ssid->psk_set) | |
3082 | params.psk = ssid->psk; | |
6fc6879b JM |
3083 | } |
3084 | ||
36b15723 JM |
3085 | params.drop_unencrypted = use_crypt; |
3086 | ||
6fc6879b | 3087 | #ifdef CONFIG_IEEE80211W |
3f56a2b7 | 3088 | params.mgmt_frame_protection = wpas_get_ssid_pmf(wpa_s, ssid); |
62d49803 | 3089 | if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) { |
6fa81a3b | 3090 | const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
97d3497e JM |
3091 | struct wpa_ie_data ie; |
3092 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 && | |
3093 | ie.capabilities & | |
3094 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { | |
f049052b BG |
3095 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports " |
3096 | "MFP: require MFP"); | |
97d3497e JM |
3097 | params.mgmt_frame_protection = |
3098 | MGMT_FRAME_PROTECTION_REQUIRED; | |
cf94626c PK |
3099 | #ifdef CONFIG_OWE |
3100 | } else if (!rsn && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) && | |
3101 | !ssid->owe_only) { | |
3102 | params.mgmt_frame_protection = NO_MGMT_FRAME_PROTECTION; | |
3103 | #endif /* CONFIG_OWE */ | |
97d3497e JM |
3104 | } |
3105 | } | |
6fc6879b JM |
3106 | #endif /* CONFIG_IEEE80211W */ |
3107 | ||
ffad8858 | 3108 | params.p2p = ssid->p2p_group; |
6e3f4b89 | 3109 | |
ba307f85 LD |
3110 | if (wpa_s->p2pdev->set_sta_uapsd) |
3111 | params.uapsd = wpa_s->p2pdev->sta_uapsd; | |
eea2fd9e JM |
3112 | else |
3113 | params.uapsd = -1; | |
3114 | ||
80e8a5ee BG |
3115 | #ifdef CONFIG_HT_OVERRIDES |
3116 | os_memset(&htcaps, 0, sizeof(htcaps)); | |
3117 | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); | |
3118 | params.htcaps = (u8 *) &htcaps; | |
3119 | params.htcaps_mask = (u8 *) &htcaps_mask; | |
3120 | wpa_supplicant_apply_ht_overrides(wpa_s, ssid, ¶ms); | |
3121 | #endif /* CONFIG_HT_OVERRIDES */ | |
6aa1cd4e PS |
3122 | #ifdef CONFIG_VHT_OVERRIDES |
3123 | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); | |
3124 | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); | |
3125 | params.vhtcaps = &vhtcaps; | |
3126 | params.vhtcaps_mask = &vhtcaps_mask; | |
95ff3069 | 3127 | wpa_supplicant_apply_vht_overrides(wpa_s, ssid, ¶ms); |
6aa1cd4e | 3128 | #endif /* CONFIG_VHT_OVERRIDES */ |
80e8a5ee | 3129 | |
8567866d JJ |
3130 | #ifdef CONFIG_P2P |
3131 | /* | |
3132 | * If multi-channel concurrency is not supported, check for any | |
3133 | * frequency conflict. In case of any frequency conflict, remove the | |
3134 | * least prioritized connection. | |
3135 | */ | |
3136 | if (wpa_s->num_multichan_concurrent < 2) { | |
d0df6437 IP |
3137 | int freq, num; |
3138 | num = get_shared_radio_freqs(wpa_s, &freq, 1); | |
4ec68377 | 3139 | if (num > 0 && freq > 0 && freq != params.freq.freq) { |
d0df6437 IP |
3140 | wpa_printf(MSG_DEBUG, |
3141 | "Assoc conflicting freq found (%d != %d)", | |
4ec68377 JD |
3142 | freq, params.freq.freq); |
3143 | if (wpas_p2p_handle_frequency_conflicts( | |
74656400 SD |
3144 | wpa_s, params.freq.freq, ssid) < 0) { |
3145 | wpas_connect_work_done(wpa_s); | |
1e6780bd | 3146 | os_free(wpa_ie); |
8567866d | 3147 | return; |
74656400 | 3148 | } |
8567866d JJ |
3149 | } |
3150 | } | |
3151 | #endif /* CONFIG_P2P */ | |
3152 | ||
6a5ee810 JM |
3153 | if (wpa_s->reassoc_same_ess && !is_zero_ether_addr(prev_bssid) && |
3154 | wpa_s->current_ssid) | |
3155 | params.prev_bssid = prev_bssid; | |
3156 | ||
17fbb751 | 3157 | ret = wpa_drv_associate(wpa_s, ¶ms); |
1e6780bd | 3158 | os_free(wpa_ie); |
6fc6879b JM |
3159 | if (ret < 0) { |
3160 | wpa_msg(wpa_s, MSG_INFO, "Association request to the driver " | |
3161 | "failed"); | |
871f4dd0 JM |
3162 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SANE_ERROR_CODES) { |
3163 | /* | |
3164 | * The driver is known to mean what is saying, so we | |
3165 | * can stop right here; the association will not | |
3166 | * succeed. | |
3167 | */ | |
3168 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
c1c02342 | 3169 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
871f4dd0 JM |
3170 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
3171 | return; | |
3172 | } | |
6fc6879b JM |
3173 | /* try to continue anyway; new association will be tried again |
3174 | * after timeout */ | |
3175 | assoc_failed = 1; | |
3176 | } | |
3177 | ||
3178 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
3179 | /* Set the key after the association just in case association | |
3180 | * cleared the previously configured key. */ | |
3181 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); | |
3182 | /* No need to timeout authentication since there is no key | |
3183 | * management. */ | |
3184 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
3185 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
53895c3b | 3186 | #ifdef CONFIG_IBSS_RSN |
d7dcba70 | 3187 | } else if (ssid->mode == WPAS_MODE_IBSS && |
53895c3b JM |
3188 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
3189 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { | |
3190 | /* | |
3191 | * RSN IBSS authentication is per-STA and we can disable the | |
3192 | * per-BSSID authentication. | |
3193 | */ | |
3194 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
53895c3b | 3195 | #endif /* CONFIG_IBSS_RSN */ |
6fc6879b JM |
3196 | } else { |
3197 | /* Timeout for IEEE 802.11 authentication and association */ | |
1d3c75b3 DW |
3198 | int timeout = 60; |
3199 | ||
3200 | if (assoc_failed) { | |
3201 | /* give IBSS a bit more time */ | |
d7dcba70 | 3202 | timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5; |
1d3c75b3 DW |
3203 | } else if (wpa_s->conf->ap_scan == 1) { |
3204 | /* give IBSS a bit more time */ | |
d7dcba70 | 3205 | timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10; |
1d3c75b3 | 3206 | } |
6fc6879b JM |
3207 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
3208 | } | |
3209 | ||
66562e9c JM |
3210 | if (wep_keys_set && |
3211 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) { | |
6fc6879b JM |
3212 | /* Set static WEP keys again */ |
3213 | wpa_set_wep_keys(wpa_s, ssid); | |
3214 | } | |
3215 | ||
3216 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) { | |
3217 | /* | |
3218 | * Do not allow EAP session resumption between different | |
3219 | * network configurations. | |
3220 | */ | |
3221 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
3222 | } | |
8bac466b | 3223 | old_ssid = wpa_s->current_ssid; |
6fc6879b | 3224 | wpa_s->current_ssid = ssid; |
ece4ac5f MG |
3225 | |
3226 | if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) { | |
4d3be9cd | 3227 | wpa_s->current_bss = bss; |
ece4ac5f MG |
3228 | #ifdef CONFIG_HS20 |
3229 | hs20_configure_frame_filters(wpa_s); | |
3230 | #endif /* CONFIG_HS20 */ | |
3231 | } | |
3232 | ||
6fc6879b JM |
3233 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
3234 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
3235 | if (old_ssid != wpa_s->current_ssid) |
3236 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
3237 | } |
3238 | ||
3239 | ||
09f58c09 JM |
3240 | static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s, |
3241 | const u8 *addr) | |
3242 | { | |
3243 | struct wpa_ssid *old_ssid; | |
3244 | ||
c155305f | 3245 | wpas_connect_work_done(wpa_s); |
09f58c09 | 3246 | wpa_clear_keys(wpa_s, addr); |
09f58c09 | 3247 | old_ssid = wpa_s->current_ssid; |
0d30cc24 | 3248 | wpa_supplicant_mark_disassoc(wpa_s); |
09f58c09 JM |
3249 | wpa_sm_set_config(wpa_s->wpa, NULL); |
3250 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
3251 | if (old_ssid != wpa_s->current_ssid) | |
3252 | wpas_notify_network_changed(wpa_s); | |
3253 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); | |
3254 | } | |
3255 | ||
3256 | ||
6fc6879b JM |
3257 | /** |
3258 | * wpa_supplicant_deauthenticate - Deauthenticate the current connection | |
3259 | * @wpa_s: Pointer to wpa_supplicant data | |
3260 | * @reason_code: IEEE 802.11 reason code for the deauthenticate frame | |
3261 | * | |
073ab58f | 3262 | * This function is used to request %wpa_supplicant to deauthenticate from the |
6fc6879b JM |
3263 | * current AP. |
3264 | */ | |
3265 | void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s, | |
3266 | int reason_code) | |
3267 | { | |
3268 | u8 *addr = NULL; | |
ef48ff94 | 3269 | union wpa_event_data event; |
42d23547 | 3270 | int zero_addr = 0; |
8bac466b | 3271 | |
42d23547 JM |
3272 | wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR |
3273 | " pending_bssid=" MACSTR " reason=%d state=%s", | |
3274 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
3275 | reason_code, wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
3276 | ||
04e3d815 MK |
3277 | if (!is_zero_ether_addr(wpa_s->pending_bssid) && |
3278 | (wpa_s->wpa_state == WPA_AUTHENTICATING || | |
3279 | wpa_s->wpa_state == WPA_ASSOCIATING)) | |
42d23547 | 3280 | addr = wpa_s->pending_bssid; |
04e3d815 MK |
3281 | else if (!is_zero_ether_addr(wpa_s->bssid)) |
3282 | addr = wpa_s->bssid; | |
42d23547 JM |
3283 | else if (wpa_s->wpa_state == WPA_ASSOCIATING) { |
3284 | /* | |
3285 | * When using driver-based BSS selection, we may not know the | |
3286 | * BSSID with which we are currently trying to associate. We | |
3287 | * need to notify the driver of this disconnection even in such | |
3288 | * a case, so use the all zeros address here. | |
3289 | */ | |
6fc6879b | 3290 | addr = wpa_s->bssid; |
42d23547 JM |
3291 | zero_addr = 1; |
3292 | } | |
3293 | ||
7b44ff2c SD |
3294 | #ifdef CONFIG_TDLS |
3295 | wpa_tdls_teardown_peers(wpa_s->wpa); | |
3296 | #endif /* CONFIG_TDLS */ | |
3297 | ||
603a3f34 JL |
3298 | #ifdef CONFIG_MESH |
3299 | if (wpa_s->ifmsh) { | |
a39b040b SB |
3300 | struct mesh_conf *mconf; |
3301 | ||
3302 | mconf = wpa_s->ifmsh->mconf; | |
6174de66 JM |
3303 | wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s", |
3304 | wpa_s->ifname); | |
a39b040b SB |
3305 | wpas_notify_mesh_group_removed(wpa_s, mconf->meshid, |
3306 | mconf->meshid_len, reason_code); | |
603a3f34 JL |
3307 | wpa_supplicant_leave_mesh(wpa_s); |
3308 | } | |
3309 | #endif /* CONFIG_MESH */ | |
3310 | ||
42d23547 JM |
3311 | if (addr) { |
3312 | wpa_drv_deauthenticate(wpa_s, addr, reason_code); | |
ef48ff94 JM |
3313 | os_memset(&event, 0, sizeof(event)); |
3314 | event.deauth_info.reason_code = (u16) reason_code; | |
3315 | event.deauth_info.locally_generated = 1; | |
3316 | wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event); | |
42d23547 JM |
3317 | if (zero_addr) |
3318 | addr = NULL; | |
6fc6879b | 3319 | } |
09f58c09 JM |
3320 | |
3321 | wpa_supplicant_clear_connection(wpa_s, addr); | |
6fc6879b JM |
3322 | } |
3323 | ||
dca1a511 DS |
3324 | static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s, |
3325 | struct wpa_ssid *ssid) | |
3326 | { | |
3327 | if (!ssid || !ssid->disabled || ssid->disabled == 2) | |
3328 | return; | |
3329 | ||
3330 | ssid->disabled = 0; | |
91073cca | 3331 | ssid->owe_transition_bss_select_count = 0; |
dca1a511 DS |
3332 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
3333 | wpas_notify_network_enabled_changed(wpa_s, ssid); | |
3334 | ||
3335 | /* | |
3336 | * Try to reassociate since there is no current configuration and a new | |
3337 | * network was made available. | |
3338 | */ | |
d2592497 | 3339 | if (!wpa_s->current_ssid && !wpa_s->disconnected) |
dca1a511 DS |
3340 | wpa_s->reassociate = 1; |
3341 | } | |
3342 | ||
6fc6879b | 3343 | |
d015bb05 RP |
3344 | /** |
3345 | * wpa_supplicant_add_network - Add a new network | |
3346 | * @wpa_s: wpa_supplicant structure for a network interface | |
3347 | * Returns: The new network configuration or %NULL if operation failed | |
3348 | * | |
3349 | * This function performs the following operations: | |
3350 | * 1. Adds a new network. | |
3351 | * 2. Send network addition notification. | |
3352 | * 3. Marks the network disabled. | |
3353 | * 4. Set network default parameters. | |
3354 | */ | |
3355 | struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s) | |
3356 | { | |
3357 | struct wpa_ssid *ssid; | |
3358 | ||
3359 | ssid = wpa_config_add_network(wpa_s->conf); | |
3360 | if (!ssid) | |
3361 | return NULL; | |
3362 | wpas_notify_network_added(wpa_s, ssid); | |
3363 | ssid->disabled = 1; | |
3364 | wpa_config_set_network_defaults(ssid); | |
3365 | ||
3366 | return ssid; | |
3367 | } | |
3368 | ||
3369 | ||
3370 | /** | |
3371 | * wpa_supplicant_remove_network - Remove a configured network based on id | |
3372 | * @wpa_s: wpa_supplicant structure for a network interface | |
3373 | * @id: Unique network id to search for | |
3374 | * Returns: 0 on success, or -1 if the network was not found, -2 if the network | |
3375 | * could not be removed | |
3376 | * | |
3377 | * This function performs the following operations: | |
3378 | * 1. Removes the network. | |
3379 | * 2. Send network removal notification. | |
3380 | * 3. Update internal state machines. | |
3381 | * 4. Stop any running sched scans. | |
3382 | */ | |
3383 | int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id) | |
3384 | { | |
3385 | struct wpa_ssid *ssid; | |
3386 | int was_disabled; | |
3387 | ||
3388 | ssid = wpa_config_get_network(wpa_s->conf, id); | |
3389 | if (!ssid) | |
3390 | return -1; | |
3391 | wpas_notify_network_removed(wpa_s, ssid); | |
3392 | ||
3393 | if (wpa_s->last_ssid == ssid) | |
3394 | wpa_s->last_ssid = NULL; | |
3395 | ||
3396 | if (ssid == wpa_s->current_ssid || !wpa_s->current_ssid) { | |
3397 | #ifdef CONFIG_SME | |
3398 | wpa_s->sme.prev_bssid_set = 0; | |
3399 | #endif /* CONFIG_SME */ | |
3400 | /* | |
3401 | * Invalidate the EAP session cache if the current or | |
3402 | * previously used network is removed. | |
3403 | */ | |
3404 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
3405 | } | |
3406 | ||
3407 | if (ssid == wpa_s->current_ssid) { | |
3408 | wpa_sm_set_config(wpa_s->wpa, NULL); | |
3409 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | |
3410 | ||
3411 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) | |
3412 | wpa_s->own_disconnect_req = 1; | |
3413 | wpa_supplicant_deauthenticate(wpa_s, | |
3414 | WLAN_REASON_DEAUTH_LEAVING); | |
3415 | } | |
3416 | ||
3417 | was_disabled = ssid->disabled; | |
3418 | ||
3419 | if (wpa_config_remove_network(wpa_s->conf, id) < 0) | |
3420 | return -2; | |
3421 | ||
3422 | if (!was_disabled && wpa_s->sched_scanning) { | |
3423 | wpa_printf(MSG_DEBUG, | |
3424 | "Stop ongoing sched_scan to remove network from filters"); | |
3425 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3426 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3427 | } | |
3428 | ||
3429 | return 0; | |
3430 | } | |
3431 | ||
3432 | ||
86b89452 WS |
3433 | /** |
3434 | * wpa_supplicant_enable_network - Mark a configured network as enabled | |
3435 | * @wpa_s: wpa_supplicant structure for a network interface | |
3436 | * @ssid: wpa_ssid structure for a configured network or %NULL | |
3437 | * | |
3438 | * Enables the specified network or all networks if no network specified. | |
3439 | */ | |
3440 | void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s, | |
3441 | struct wpa_ssid *ssid) | |
3442 | { | |
86b89452 | 3443 | if (ssid == NULL) { |
14f79078 JM |
3444 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
3445 | wpa_supplicant_enable_one_network(wpa_s, ssid); | |
dca1a511 DS |
3446 | } else |
3447 | wpa_supplicant_enable_one_network(wpa_s, ssid); | |
86b89452 | 3448 | |
5a1d9d1a JM |
3449 | if (wpa_s->reassociate && !wpa_s->disconnected && |
3450 | (!wpa_s->current_ssid || | |
3451 | wpa_s->wpa_state == WPA_DISCONNECTED || | |
3452 | wpa_s->wpa_state == WPA_SCANNING)) { | |
dca1a511 DS |
3453 | if (wpa_s->sched_scanning) { |
3454 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add " | |
3455 | "new network to scan filters"); | |
3456 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3457 | } | |
86b89452 | 3458 | |
35d40309 JM |
3459 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { |
3460 | wpa_s->scan_req = NORMAL_SCAN_REQ; | |
dad153d1 | 3461 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
35d40309 | 3462 | } |
86b89452 WS |
3463 | } |
3464 | } | |
3465 | ||
3466 | ||
3467 | /** | |
3468 | * wpa_supplicant_disable_network - Mark a configured network as disabled | |
3469 | * @wpa_s: wpa_supplicant structure for a network interface | |
3470 | * @ssid: wpa_ssid structure for a configured network or %NULL | |
3471 | * | |
3472 | * Disables the specified network or all networks if no network specified. | |
3473 | */ | |
3474 | void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s, | |
3475 | struct wpa_ssid *ssid) | |
3476 | { | |
3477 | struct wpa_ssid *other_ssid; | |
3478 | int was_disabled; | |
3479 | ||
3480 | if (ssid == NULL) { | |
725fc39e DS |
3481 | if (wpa_s->sched_scanning) |
3482 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3483 | ||
4dac0245 JM |
3484 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
3485 | other_ssid = other_ssid->next) { | |
86b89452 | 3486 | was_disabled = other_ssid->disabled; |
4dac0245 JM |
3487 | if (was_disabled == 2) |
3488 | continue; /* do not change persistent P2P group | |
3489 | * data */ | |
86b89452 WS |
3490 | |
3491 | other_ssid->disabled = 1; | |
3492 | ||
3493 | if (was_disabled != other_ssid->disabled) | |
3494 | wpas_notify_network_enabled_changed( | |
3495 | wpa_s, other_ssid); | |
86b89452 | 3496 | } |
0661163e SD |
3497 | if (wpa_s->current_ssid) { |
3498 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) | |
3499 | wpa_s->own_disconnect_req = 1; | |
07783eaa | 3500 | wpa_supplicant_deauthenticate( |
86b89452 | 3501 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
0661163e | 3502 | } |
4dac0245 | 3503 | } else if (ssid->disabled != 2) { |
0661163e SD |
3504 | if (ssid == wpa_s->current_ssid) { |
3505 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) | |
3506 | wpa_s->own_disconnect_req = 1; | |
07783eaa | 3507 | wpa_supplicant_deauthenticate( |
86b89452 | 3508 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
0661163e | 3509 | } |
86b89452 WS |
3510 | |
3511 | was_disabled = ssid->disabled; | |
3512 | ||
3513 | ssid->disabled = 1; | |
3514 | ||
725fc39e | 3515 | if (was_disabled != ssid->disabled) { |
86b89452 | 3516 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
725fc39e DS |
3517 | if (wpa_s->sched_scanning) { |
3518 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan " | |
3519 | "to remove network from filters"); | |
3520 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
3521 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3522 | } | |
3523 | } | |
86b89452 WS |
3524 | } |
3525 | } | |
3526 | ||
3527 | ||
3528 | /** | |
3529 | * wpa_supplicant_select_network - Attempt association with a network | |
3530 | * @wpa_s: wpa_supplicant structure for a network interface | |
3531 | * @ssid: wpa_ssid structure for a configured network or %NULL for any network | |
3532 | */ | |
3533 | void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, | |
3534 | struct wpa_ssid *ssid) | |
3535 | { | |
3536 | ||
3537 | struct wpa_ssid *other_ssid; | |
d93dfbd5 | 3538 | int disconnected = 0; |
86b89452 | 3539 | |
d93dfbd5 | 3540 | if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) { |
e66bcedd JM |
3541 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
3542 | wpa_s->own_disconnect_req = 1; | |
07783eaa | 3543 | wpa_supplicant_deauthenticate( |
86b89452 | 3544 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
d93dfbd5 JM |
3545 | disconnected = 1; |
3546 | } | |
86b89452 | 3547 | |
00e5e3d5 JM |
3548 | if (ssid) |
3549 | wpas_clear_temp_disabled(wpa_s, ssid, 1); | |
3550 | ||
86b89452 WS |
3551 | /* |
3552 | * Mark all other networks disabled or mark all networks enabled if no | |
3553 | * network specified. | |
3554 | */ | |
4dac0245 JM |
3555 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
3556 | other_ssid = other_ssid->next) { | |
86b89452 | 3557 | int was_disabled = other_ssid->disabled; |
4dac0245 JM |
3558 | if (was_disabled == 2) |
3559 | continue; /* do not change persistent P2P group data */ | |
86b89452 WS |
3560 | |
3561 | other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0; | |
00e5e3d5 JM |
3562 | if (was_disabled && !other_ssid->disabled) |
3563 | wpas_clear_temp_disabled(wpa_s, other_ssid, 0); | |
86b89452 WS |
3564 | |
3565 | if (was_disabled != other_ssid->disabled) | |
3566 | wpas_notify_network_enabled_changed(wpa_s, other_ssid); | |
86b89452 | 3567 | } |
2a6f78fb | 3568 | |
d38c7be0 JM |
3569 | if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid && |
3570 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
2a6f78fb JJ |
3571 | /* We are already associated with the selected network */ |
3572 | wpa_printf(MSG_DEBUG, "Already associated with the " | |
3573 | "selected network - do nothing"); | |
3574 | return; | |
3575 | } | |
3576 | ||
25a8f9e3 | 3577 | if (ssid) { |
96efeeb6 | 3578 | wpa_s->current_ssid = ssid; |
25a8f9e3 | 3579 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
603a3f34 JL |
3580 | wpa_s->connect_without_scan = |
3581 | (ssid->mode == WPAS_MODE_MESH) ? ssid : NULL; | |
701f3961 AS |
3582 | |
3583 | /* | |
3584 | * Don't optimize next scan freqs since a new ESS has been | |
3585 | * selected. | |
3586 | */ | |
3587 | os_free(wpa_s->next_scan_freqs); | |
3588 | wpa_s->next_scan_freqs = NULL; | |
603a3f34 JL |
3589 | } else { |
3590 | wpa_s->connect_without_scan = NULL; | |
25a8f9e3 | 3591 | } |
603a3f34 | 3592 | |
86b89452 WS |
3593 | wpa_s->disconnected = 0; |
3594 | wpa_s->reassociate = 1; | |
2cb40e9f | 3595 | wpa_s->last_owe_group = 0; |
91073cca SD |
3596 | if (ssid) |
3597 | ssid->owe_transition_bss_select_count = 0; | |
cecdddc1 | 3598 | |
e4a35f07 | 3599 | if (wpa_s->connect_without_scan || |
35d40309 JM |
3600 | wpa_supplicant_fast_associate(wpa_s) != 1) { |
3601 | wpa_s->scan_req = NORMAL_SCAN_REQ; | |
be7ebd89 | 3602 | wpas_scan_reset_sched_scan(wpa_s); |
cecdddc1 | 3603 | wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0); |
35d40309 | 3604 | } |
86b89452 | 3605 | |
a1641d26 JM |
3606 | if (ssid) |
3607 | wpas_notify_network_selected(wpa_s, ssid); | |
86b89452 WS |
3608 | } |
3609 | ||
3610 | ||
bdec7ee5 MS |
3611 | /** |
3612 | * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path | |
3613 | * @wpa_s: wpa_supplicant structure for a network interface | |
3614 | * @pkcs11_engine_path: PKCS #11 engine path or NULL | |
3615 | * @pkcs11_module_path: PKCS #11 module path or NULL | |
3616 | * Returns: 0 on success; -1 on failure | |
3617 | * | |
3618 | * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid | |
3619 | * path. If resetting the EAPOL state machine with the new PKCS #11 engine and | |
3620 | * module path fails the paths will be reset to the default value (NULL). | |
3621 | */ | |
3622 | int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s, | |
3623 | const char *pkcs11_engine_path, | |
3624 | const char *pkcs11_module_path) | |
3625 | { | |
3626 | char *pkcs11_engine_path_copy = NULL; | |
3627 | char *pkcs11_module_path_copy = NULL; | |
3628 | ||
3629 | if (pkcs11_engine_path != NULL) { | |
3630 | pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path); | |
3631 | if (pkcs11_engine_path_copy == NULL) | |
3632 | return -1; | |
3633 | } | |
3634 | if (pkcs11_module_path != NULL) { | |
3635 | pkcs11_module_path_copy = os_strdup(pkcs11_module_path); | |
04c366cb | 3636 | if (pkcs11_module_path_copy == NULL) { |
bdec7ee5 MS |
3637 | os_free(pkcs11_engine_path_copy); |
3638 | return -1; | |
3639 | } | |
3640 | } | |
3641 | ||
3642 | os_free(wpa_s->conf->pkcs11_engine_path); | |
3643 | os_free(wpa_s->conf->pkcs11_module_path); | |
3644 | wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy; | |
3645 | wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy; | |
3646 | ||
3647 | wpa_sm_set_eapol(wpa_s->wpa, NULL); | |
3648 | eapol_sm_deinit(wpa_s->eapol); | |
3649 | wpa_s->eapol = NULL; | |
3650 | if (wpa_supplicant_init_eapol(wpa_s)) { | |
3651 | /* Error -> Reset paths to the default value (NULL) once. */ | |
3652 | if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL) | |
3653 | wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL, | |
3654 | NULL); | |
3655 | ||
3656 | return -1; | |
3657 | } | |
3658 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); | |
3659 | ||
3660 | return 0; | |
3661 | } | |
3662 | ||
3663 | ||
86b89452 WS |
3664 | /** |
3665 | * wpa_supplicant_set_ap_scan - Set AP scan mode for interface | |
3666 | * @wpa_s: wpa_supplicant structure for a network interface | |
3667 | * @ap_scan: AP scan mode | |
3668 | * Returns: 0 if succeed or -1 if ap_scan has an invalid value | |
3669 | * | |
3670 | */ | |
3671 | int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan) | |
3672 | { | |
3673 | ||
3674 | int old_ap_scan; | |
3675 | ||
3676 | if (ap_scan < 0 || ap_scan > 2) | |
3677 | return -1; | |
3678 | ||
8406cd35 JM |
3679 | if (ap_scan == 2 && os_strcmp(wpa_s->driver->name, "nl80211") == 0) { |
3680 | wpa_printf(MSG_INFO, | |
3681 | "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures"); | |
3682 | } | |
3683 | ||
48f8e036 DS |
3684 | #ifdef ANDROID |
3685 | if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan && | |
3686 | wpa_s->wpa_state >= WPA_ASSOCIATING && | |
3687 | wpa_s->wpa_state < WPA_COMPLETED) { | |
3688 | wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while " | |
3689 | "associating", wpa_s->conf->ap_scan, ap_scan); | |
3690 | return 0; | |
3691 | } | |
3692 | #endif /* ANDROID */ | |
3693 | ||
86b89452 WS |
3694 | old_ap_scan = wpa_s->conf->ap_scan; |
3695 | wpa_s->conf->ap_scan = ap_scan; | |
3696 | ||
3697 | if (old_ap_scan != wpa_s->conf->ap_scan) | |
3698 | wpas_notify_ap_scan_changed(wpa_s); | |
3699 | ||
3700 | return 0; | |
3701 | } | |
3702 | ||
3703 | ||
78633c37 SL |
3704 | /** |
3705 | * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age | |
3706 | * @wpa_s: wpa_supplicant structure for a network interface | |
3707 | * @expire_age: Expiration age in seconds | |
3708 | * Returns: 0 if succeed or -1 if expire_age has an invalid value | |
3709 | * | |
3710 | */ | |
3711 | int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s, | |
3712 | unsigned int bss_expire_age) | |
3713 | { | |
3714 | if (bss_expire_age < 10) { | |
3715 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u", | |
3716 | bss_expire_age); | |
3717 | return -1; | |
3718 | } | |
3719 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec", | |
3720 | bss_expire_age); | |
3721 | wpa_s->conf->bss_expiration_age = bss_expire_age; | |
3722 | ||
3723 | return 0; | |
3724 | } | |
3725 | ||
3726 | ||
3727 | /** | |
3728 | * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count | |
3729 | * @wpa_s: wpa_supplicant structure for a network interface | |
3730 | * @expire_count: number of scans after which an unseen BSS is reclaimed | |
3731 | * Returns: 0 if succeed or -1 if expire_count has an invalid value | |
3732 | * | |
3733 | */ | |
3734 | int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s, | |
3735 | unsigned int bss_expire_count) | |
3736 | { | |
3737 | if (bss_expire_count < 1) { | |
3738 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u", | |
3739 | bss_expire_count); | |
3740 | return -1; | |
3741 | } | |
3742 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u", | |
3743 | bss_expire_count); | |
3744 | wpa_s->conf->bss_expiration_scan_count = bss_expire_count; | |
3745 | ||
3746 | return 0; | |
3747 | } | |
3748 | ||
3749 | ||
c6e86b63 MA |
3750 | /** |
3751 | * wpa_supplicant_set_scan_interval - Set scan interval | |
3752 | * @wpa_s: wpa_supplicant structure for a network interface | |
3753 | * @scan_interval: scan interval in seconds | |
3754 | * Returns: 0 if succeed or -1 if scan_interval has an invalid value | |
3755 | * | |
3756 | */ | |
3757 | int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s, | |
3758 | int scan_interval) | |
3759 | { | |
3760 | if (scan_interval < 0) { | |
3761 | wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d", | |
3762 | scan_interval); | |
3763 | return -1; | |
3764 | } | |
3765 | wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec", | |
3766 | scan_interval); | |
9e737f08 | 3767 | wpa_supplicant_update_scan_int(wpa_s, scan_interval); |
c6e86b63 MA |
3768 | |
3769 | return 0; | |
3770 | } | |
3771 | ||
3772 | ||
86b89452 WS |
3773 | /** |
3774 | * wpa_supplicant_set_debug_params - Set global debug params | |
3775 | * @global: wpa_global structure | |
3776 | * @debug_level: debug level | |
3777 | * @debug_timestamp: determines if show timestamp in debug data | |
3778 | * @debug_show_keys: determines if show keys in debug data | |
3779 | * Returns: 0 if succeed or -1 if debug_level has wrong value | |
3780 | */ | |
3781 | int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level, | |
3782 | int debug_timestamp, int debug_show_keys) | |
3783 | { | |
3784 | ||
3785 | int old_level, old_timestamp, old_show_keys; | |
3786 | ||
3787 | /* check for allowed debuglevels */ | |
14dc0011 PS |
3788 | if (debug_level != MSG_EXCESSIVE && |
3789 | debug_level != MSG_MSGDUMP && | |
86b89452 WS |
3790 | debug_level != MSG_DEBUG && |
3791 | debug_level != MSG_INFO && | |
3792 | debug_level != MSG_WARNING && | |
3793 | debug_level != MSG_ERROR) | |
3794 | return -1; | |
3795 | ||
3796 | old_level = wpa_debug_level; | |
3797 | old_timestamp = wpa_debug_timestamp; | |
3798 | old_show_keys = wpa_debug_show_keys; | |
3799 | ||
3800 | wpa_debug_level = debug_level; | |
3801 | wpa_debug_timestamp = debug_timestamp ? 1 : 0; | |
3802 | wpa_debug_show_keys = debug_show_keys ? 1 : 0; | |
3803 | ||
db9133ac WS |
3804 | if (wpa_debug_level != old_level) |
3805 | wpas_notify_debug_level_changed(global); | |
3806 | if (wpa_debug_timestamp != old_timestamp) | |
3807 | wpas_notify_debug_timestamp_changed(global); | |
3808 | if (wpa_debug_show_keys != old_show_keys) | |
3809 | wpas_notify_debug_show_keys_changed(global); | |
86b89452 WS |
3810 | |
3811 | return 0; | |
3812 | } | |
3813 | ||
3814 | ||
e8b96490 JM |
3815 | #ifdef CONFIG_OWE |
3816 | static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid, | |
3817 | const u8 *entry_ssid, size_t entry_ssid_len) | |
3818 | { | |
3819 | const u8 *owe, *pos, *end; | |
3820 | u8 ssid_len; | |
3821 | struct wpa_bss *bss; | |
3822 | ||
3823 | /* Check network profile SSID aganst the SSID in the | |
3824 | * OWE Transition Mode element. */ | |
3825 | ||
3826 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); | |
3827 | if (!bss) | |
3828 | return 0; | |
3829 | ||
3830 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); | |
3831 | if (!owe) | |
3832 | return 0; | |
3833 | ||
3834 | pos = owe + 6; | |
3835 | end = owe + 2 + owe[1]; | |
3836 | ||
3837 | if (end - pos < ETH_ALEN + 1) | |
3838 | return 0; | |
3839 | pos += ETH_ALEN; | |
3840 | ssid_len = *pos++; | |
3841 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) | |
3842 | return 0; | |
3843 | ||
3844 | return entry_ssid_len == ssid_len && | |
3845 | os_memcmp(pos, entry_ssid, ssid_len) == 0; | |
3846 | } | |
3847 | #endif /* CONFIG_OWE */ | |
3848 | ||
3849 | ||
6fc6879b JM |
3850 | /** |
3851 | * wpa_supplicant_get_ssid - Get a pointer to the current network structure | |
3852 | * @wpa_s: Pointer to wpa_supplicant data | |
3853 | * Returns: A pointer to the current network structure or %NULL on failure | |
3854 | */ | |
3855 | struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s) | |
3856 | { | |
3857 | struct wpa_ssid *entry; | |
eaa8eefe | 3858 | u8 ssid[SSID_MAX_LEN]; |
6fc6879b JM |
3859 | int res; |
3860 | size_t ssid_len; | |
3861 | u8 bssid[ETH_ALEN]; | |
3862 | int wired; | |
3863 | ||
17fbb751 JM |
3864 | res = wpa_drv_get_ssid(wpa_s, ssid); |
3865 | if (res < 0) { | |
3866 | wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from " | |
3867 | "driver"); | |
3868 | return NULL; | |
6fc6879b | 3869 | } |
17fbb751 | 3870 | ssid_len = res; |
6fc6879b | 3871 | |
17fbb751 | 3872 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
f049052b BG |
3873 | wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from " |
3874 | "driver"); | |
6fc6879b JM |
3875 | return NULL; |
3876 | } | |
3877 | ||
c2a04078 JM |
3878 | wired = wpa_s->conf->ap_scan == 0 && |
3879 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED); | |
6fc6879b JM |
3880 | |
3881 | entry = wpa_s->conf->ssid; | |
3882 | while (entry) { | |
349493bd | 3883 | if (!wpas_network_disabled(wpa_s, entry) && |
6fc6879b JM |
3884 | ((ssid_len == entry->ssid_len && |
3885 | os_memcmp(ssid, entry->ssid, ssid_len) == 0) || wired) && | |
3886 | (!entry->bssid_set || | |
3887 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)) | |
3888 | return entry; | |
24c23d1b | 3889 | #ifdef CONFIG_WPS |
349493bd | 3890 | if (!wpas_network_disabled(wpa_s, entry) && |
24c23d1b JM |
3891 | (entry->key_mgmt & WPA_KEY_MGMT_WPS) && |
3892 | (entry->ssid == NULL || entry->ssid_len == 0) && | |
3893 | (!entry->bssid_set || | |
3894 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)) | |
3895 | return entry; | |
3896 | #endif /* CONFIG_WPS */ | |
7d232e23 | 3897 | |
e8b96490 JM |
3898 | #ifdef CONFIG_OWE |
3899 | if (!wpas_network_disabled(wpa_s, entry) && | |
3900 | owe_trans_ssid_match(wpa_s, bssid, entry->ssid, | |
3901 | entry->ssid_len) && | |
3902 | (!entry->bssid_set || | |
3903 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)) | |
3904 | return entry; | |
3905 | #endif /* CONFIG_OWE */ | |
3906 | ||
349493bd | 3907 | if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set && |
7d232e23 ZC |
3908 | entry->ssid_len == 0 && |
3909 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0) | |
3910 | return entry; | |
3911 | ||
6fc6879b JM |
3912 | entry = entry->next; |
3913 | } | |
3914 | ||
3915 | return NULL; | |
3916 | } | |
3917 | ||
3918 | ||
7756114f JM |
3919 | static int select_driver(struct wpa_supplicant *wpa_s, int i) |
3920 | { | |
3921 | struct wpa_global *global = wpa_s->global; | |
3922 | ||
3923 | if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) { | |
45e3fc72 | 3924 | global->drv_priv[i] = wpa_drivers[i]->global_init(global); |
7756114f JM |
3925 | if (global->drv_priv[i] == NULL) { |
3926 | wpa_printf(MSG_ERROR, "Failed to initialize driver " | |
3927 | "'%s'", wpa_drivers[i]->name); | |
3928 | return -1; | |
3929 | } | |
3930 | } | |
3931 | ||
3932 | wpa_s->driver = wpa_drivers[i]; | |
3933 | wpa_s->global_drv_priv = global->drv_priv[i]; | |
3934 | ||
3935 | return 0; | |
3936 | } | |
3937 | ||
3938 | ||
6fc6879b JM |
3939 | static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, |
3940 | const char *name) | |
3941 | { | |
3942 | int i; | |
362f781e | 3943 | size_t len; |
74b1c84a | 3944 | const char *pos, *driver = name; |
6fc6879b JM |
3945 | |
3946 | if (wpa_s == NULL) | |
3947 | return -1; | |
3948 | ||
c5121837 | 3949 | if (wpa_drivers[0] == NULL) { |
f049052b BG |
3950 | wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into " |
3951 | "wpa_supplicant"); | |
6fc6879b JM |
3952 | return -1; |
3953 | } | |
3954 | ||
3955 | if (name == NULL) { | |
3956 | /* default to first driver in the list */ | |
7756114f | 3957 | return select_driver(wpa_s, 0); |
6fc6879b JM |
3958 | } |
3959 | ||
74b1c84a SO |
3960 | do { |
3961 | pos = os_strchr(driver, ','); | |
3962 | if (pos) | |
3963 | len = pos - driver; | |
3964 | else | |
3965 | len = os_strlen(driver); | |
3966 | ||
3967 | for (i = 0; wpa_drivers[i]; i++) { | |
3968 | if (os_strlen(wpa_drivers[i]->name) == len && | |
3969 | os_strncmp(driver, wpa_drivers[i]->name, len) == | |
0f4668ce DW |
3970 | 0) { |
3971 | /* First driver that succeeds wins */ | |
3972 | if (select_driver(wpa_s, i) == 0) | |
3973 | return 0; | |
3974 | } | |
6fc6879b | 3975 | } |
74b1c84a SO |
3976 | |
3977 | driver = pos + 1; | |
3978 | } while (pos); | |
6fc6879b | 3979 | |
f049052b | 3980 | wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name); |
6fc6879b JM |
3981 | return -1; |
3982 | } | |
3983 | ||
3984 | ||
a8e0505b JM |
3985 | /** |
3986 | * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant | |
3987 | * @ctx: Context pointer (wpa_s); this is the ctx variable registered | |
3988 | * with struct wpa_driver_ops::init() | |
3989 | * @src_addr: Source address of the EAPOL frame | |
3990 | * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header) | |
3991 | * @len: Length of the EAPOL data | |
3992 | * | |
3993 | * This function is called for each received EAPOL frame. Most driver | |
3994 | * interfaces rely on more generic OS mechanism for receiving frames through | |
3995 | * l2_packet, but if such a mechanism is not available, the driver wrapper may | |
3996 | * take care of received EAPOL frames and deliver them to the core supplicant | |
3997 | * code by calling this function. | |
3998 | */ | |
6fc6879b JM |
3999 | void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr, |
4000 | const u8 *buf, size_t len) | |
4001 | { | |
4002 | struct wpa_supplicant *wpa_s = ctx; | |
4003 | ||
f049052b | 4004 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr)); |
6fc6879b JM |
4005 | wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len); |
4006 | ||
02adead5 MK |
4007 | #ifdef CONFIG_TESTING_OPTIONS |
4008 | if (wpa_s->ignore_auth_resp) { | |
4009 | wpa_printf(MSG_INFO, "RX EAPOL - ignore_auth_resp active!"); | |
4010 | return; | |
4011 | } | |
4012 | #endif /* CONFIG_TESTING_OPTIONS */ | |
4013 | ||
3ab35a66 JM |
4014 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
4015 | (wpa_s->last_eapol_matches_bssid && | |
4016 | #ifdef CONFIG_AP | |
4017 | !wpa_s->ap_iface && | |
4018 | #endif /* CONFIG_AP */ | |
4019 | os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) != 0)) { | |
1ff73338 JM |
4020 | /* |
4021 | * There is possible race condition between receiving the | |
4022 | * association event and the EAPOL frame since they are coming | |
4023 | * through different paths from the driver. In order to avoid | |
4024 | * issues in trying to process the EAPOL frame before receiving | |
4025 | * association information, lets queue it for processing until | |
3ab35a66 JM |
4026 | * the association event is received. This may also be needed in |
4027 | * driver-based roaming case, so also use src_addr != BSSID as a | |
4028 | * trigger if we have previously confirmed that the | |
4029 | * Authenticator uses BSSID as the src_addr (which is not the | |
4030 | * case with wired IEEE 802.1X). | |
1ff73338 | 4031 | */ |
f049052b | 4032 | wpa_dbg(wpa_s, MSG_DEBUG, "Not associated - Delay processing " |
3ab35a66 JM |
4033 | "of received EAPOL frame (state=%s bssid=" MACSTR ")", |
4034 | wpa_supplicant_state_txt(wpa_s->wpa_state), | |
4035 | MAC2STR(wpa_s->bssid)); | |
1ff73338 JM |
4036 | wpabuf_free(wpa_s->pending_eapol_rx); |
4037 | wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len); | |
4038 | if (wpa_s->pending_eapol_rx) { | |
c2be937c | 4039 | os_get_reltime(&wpa_s->pending_eapol_rx_time); |
1ff73338 JM |
4040 | os_memcpy(wpa_s->pending_eapol_rx_src, src_addr, |
4041 | ETH_ALEN); | |
4042 | } | |
4043 | return; | |
4044 | } | |
4045 | ||
3ab35a66 JM |
4046 | wpa_s->last_eapol_matches_bssid = |
4047 | os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) == 0; | |
4048 | ||
db149ac9 JM |
4049 | #ifdef CONFIG_AP |
4050 | if (wpa_s->ap_iface) { | |
4051 | wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len); | |
4052 | return; | |
4053 | } | |
4054 | #endif /* CONFIG_AP */ | |
4055 | ||
6fc6879b | 4056 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) { |
f049052b BG |
4057 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since " |
4058 | "no key management is configured"); | |
6fc6879b JM |
4059 | return; |
4060 | } | |
4061 | ||
4062 | if (wpa_s->eapol_received == 0 && | |
c2a04078 | 4063 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) || |
56586197 | 4064 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
9c972abb JM |
4065 | wpa_s->wpa_state != WPA_COMPLETED) && |
4066 | (wpa_s->current_ssid == NULL || | |
4067 | wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) { | |
6fc6879b | 4068 | /* Timeout for completing IEEE 802.1X and WPA authentication */ |
5add4101 JM |
4069 | int timeout = 10; |
4070 | ||
4071 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | |
4072 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA || | |
4073 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
4074 | /* Use longer timeout for IEEE 802.1X/EAP */ | |
4075 | timeout = 70; | |
4076 | } | |
4077 | ||
c7dafdf9 | 4078 | #ifdef CONFIG_WPS |
5add4101 JM |
4079 | if (wpa_s->current_ssid && wpa_s->current_bss && |
4080 | (wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
4081 | eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) { | |
4082 | /* | |
4083 | * Use shorter timeout if going through WPS AP iteration | |
4084 | * for PIN config method with an AP that does not | |
4085 | * advertise Selected Registrar. | |
4086 | */ | |
4087 | struct wpabuf *wps_ie; | |
4088 | ||
4089 | wps_ie = wpa_bss_get_vendor_ie_multi( | |
4090 | wpa_s->current_bss, WPS_IE_VENDOR_TYPE); | |
0ef1e290 JM |
4091 | if (wps_ie && |
4092 | !wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) | |
5add4101 JM |
4093 | timeout = 10; |
4094 | wpabuf_free(wps_ie); | |
4095 | } | |
c7dafdf9 | 4096 | #endif /* CONFIG_WPS */ |
5add4101 JM |
4097 | |
4098 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); | |
6fc6879b JM |
4099 | } |
4100 | wpa_s->eapol_received++; | |
4101 | ||
4102 | if (wpa_s->countermeasures) { | |
f049052b BG |
4103 | wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped " |
4104 | "EAPOL packet"); | |
6fc6879b JM |
4105 | return; |
4106 | } | |
4107 | ||
8be18440 JM |
4108 | #ifdef CONFIG_IBSS_RSN |
4109 | if (wpa_s->current_ssid && | |
d7dcba70 | 4110 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS) { |
8be18440 JM |
4111 | ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len); |
4112 | return; | |
4113 | } | |
4114 | #endif /* CONFIG_IBSS_RSN */ | |
4115 | ||
6fc6879b JM |
4116 | /* Source address of the incoming EAPOL frame could be compared to the |
4117 | * current BSSID. However, it is possible that a centralized | |
4118 | * Authenticator could be using another MAC address than the BSSID of | |
4119 | * an AP, so just allow any address to be used for now. The replies are | |
4120 | * still sent to the current BSSID (if available), though. */ | |
4121 | ||
4122 | os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN); | |
56586197 | 4123 | if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) && |
a1ea1b45 | 4124 | wpa_s->key_mgmt != WPA_KEY_MGMT_OWE && |
567da5bb | 4125 | wpa_s->key_mgmt != WPA_KEY_MGMT_DPP && |
6fc6879b JM |
4126 | eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0) |
4127 | return; | |
4128 | wpa_drv_poll(wpa_s); | |
c2a04078 | 4129 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
6fc6879b | 4130 | wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len); |
56586197 | 4131 | else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
6fc6879b JM |
4132 | /* |
4133 | * Set portValid = TRUE here since we are going to skip 4-way | |
4134 | * handshake processing which would normally set portValid. We | |
4135 | * need this to allow the EAPOL state machines to be completed | |
4136 | * without going through EAPOL-Key handshake. | |
4137 | */ | |
4138 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
4139 | } | |
4140 | } | |
4141 | ||
4142 | ||
bfba8deb | 4143 | int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s) |
6fc6879b | 4144 | { |
2961bfa8 JM |
4145 | if ((!wpa_s->p2p_mgmt || |
4146 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) && | |
4147 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) { | |
bfba8deb | 4148 | l2_packet_deinit(wpa_s->l2); |
6fc6879b JM |
4149 | wpa_s->l2 = l2_packet_init(wpa_s->ifname, |
4150 | wpa_drv_get_mac_addr(wpa_s), | |
4151 | ETH_P_EAPOL, | |
4152 | wpa_supplicant_rx_eapol, wpa_s, 0); | |
4153 | if (wpa_s->l2 == NULL) | |
4154 | return -1; | |
d89edb61 DC |
4155 | |
4156 | if (l2_packet_set_packet_filter(wpa_s->l2, | |
4157 | L2_PACKET_FILTER_PKTTYPE)) | |
4158 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4159 | "Failed to attach pkt_type filter"); | |
fdadd5fe JM |
4160 | } else { |
4161 | const u8 *addr = wpa_drv_get_mac_addr(wpa_s); | |
4162 | if (addr) | |
4163 | os_memcpy(wpa_s->own_addr, addr, ETH_ALEN); | |
6fc6879b JM |
4164 | } |
4165 | ||
4166 | if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) { | |
f049052b | 4167 | wpa_msg(wpa_s, MSG_ERROR, "Failed to get own L2 address"); |
6fc6879b JM |
4168 | return -1; |
4169 | } | |
4170 | ||
c267753b JM |
4171 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
4172 | ||
bfba8deb JM |
4173 | return 0; |
4174 | } | |
4175 | ||
4176 | ||
25f839c6 JM |
4177 | static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr, |
4178 | const u8 *buf, size_t len) | |
4179 | { | |
4180 | struct wpa_supplicant *wpa_s = ctx; | |
4181 | const struct l2_ethhdr *eth; | |
4182 | ||
4183 | if (len < sizeof(*eth)) | |
4184 | return; | |
4185 | eth = (const struct l2_ethhdr *) buf; | |
4186 | ||
4187 | if (os_memcmp(eth->h_dest, wpa_s->own_addr, ETH_ALEN) != 0 && | |
4188 | !(eth->h_dest[0] & 0x01)) { | |
4189 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR | |
4190 | " (bridge - not for this interface - ignore)", | |
4191 | MAC2STR(src_addr), MAC2STR(eth->h_dest)); | |
4192 | return; | |
4193 | } | |
4194 | ||
4195 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR | |
4196 | " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest)); | |
4197 | wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth), | |
4198 | len - sizeof(*eth)); | |
4199 | } | |
4200 | ||
4201 | ||
bfba8deb JM |
4202 | /** |
4203 | * wpa_supplicant_driver_init - Initialize driver interface parameters | |
4204 | * @wpa_s: Pointer to wpa_supplicant data | |
4205 | * Returns: 0 on success, -1 on failure | |
4206 | * | |
4207 | * This function is called to initialize driver interface parameters. | |
4208 | * wpa_drv_init() must have been called before this function to initialize the | |
4209 | * driver interface. | |
4210 | */ | |
4211 | int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s) | |
4212 | { | |
4213 | static int interface_count = 0; | |
4214 | ||
4215 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) | |
4216 | return -1; | |
4217 | ||
c68f6200 AS |
4218 | wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR, |
4219 | MAC2STR(wpa_s->own_addr)); | |
a313d17d | 4220 | os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN); |
c68f6200 AS |
4221 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
4222 | ||
6fc6879b | 4223 | if (wpa_s->bridge_ifname[0]) { |
f049052b BG |
4224 | wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge " |
4225 | "interface '%s'", wpa_s->bridge_ifname); | |
e6dd8196 JM |
4226 | wpa_s->l2_br = l2_packet_init_bridge( |
4227 | wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr, | |
4228 | ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1); | |
6fc6879b | 4229 | if (wpa_s->l2_br == NULL) { |
f049052b BG |
4230 | wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet " |
4231 | "connection for the bridge interface '%s'", | |
4232 | wpa_s->bridge_ifname); | |
6fc6879b JM |
4233 | return -1; |
4234 | } | |
4235 | } | |
4236 | ||
8406cd35 JM |
4237 | if (wpa_s->conf->ap_scan == 2 && |
4238 | os_strcmp(wpa_s->driver->name, "nl80211") == 0) { | |
4239 | wpa_printf(MSG_INFO, | |
4240 | "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures"); | |
4241 | } | |
4242 | ||
6fc6879b JM |
4243 | wpa_clear_keys(wpa_s, NULL); |
4244 | ||
4245 | /* Make sure that TKIP countermeasures are not left enabled (could | |
4246 | * happen if wpa_supplicant is killed during countermeasures. */ | |
4247 | wpa_drv_set_countermeasures(wpa_s, 0); | |
4248 | ||
f049052b | 4249 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver"); |
6fc6879b JM |
4250 | wpa_drv_flush_pmkid(wpa_s); |
4251 | ||
ba2a573c | 4252 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
b3aa456b ES |
4253 | wpa_s->prev_scan_wildcard = 0; |
4254 | ||
349493bd | 4255 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
a0e9d892 AS |
4256 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
4257 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
4258 | interface_count = 0; | |
4259 | } | |
ee82e33d | 4260 | #ifndef ANDROID |
3a94adbf | 4261 | if (!wpa_s->p2p_mgmt && |
5d0d72a3 BG |
4262 | wpa_supplicant_delayed_sched_scan(wpa_s, |
4263 | interface_count % 3, | |
6a90053c | 4264 | 100000)) |
5d0d72a3 | 4265 | wpa_supplicant_req_scan(wpa_s, interface_count % 3, |
a4cba8f1 | 4266 | 100000); |
ee82e33d | 4267 | #endif /* ANDROID */ |
74e259ec JM |
4268 | interface_count++; |
4269 | } else | |
4270 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
6fc6879b JM |
4271 | |
4272 | return 0; | |
4273 | } | |
4274 | ||
4275 | ||
4276 | static int wpa_supplicant_daemon(const char *pid_file) | |
4277 | { | |
4278 | wpa_printf(MSG_DEBUG, "Daemonize.."); | |
4279 | return os_daemonize(pid_file); | |
4280 | } | |
4281 | ||
4282 | ||
1772d348 JM |
4283 | static struct wpa_supplicant * |
4284 | wpa_supplicant_alloc(struct wpa_supplicant *parent) | |
6fc6879b JM |
4285 | { |
4286 | struct wpa_supplicant *wpa_s; | |
4287 | ||
4288 | wpa_s = os_zalloc(sizeof(*wpa_s)); | |
4289 | if (wpa_s == NULL) | |
4290 | return NULL; | |
4115303b | 4291 | wpa_s->scan_req = INITIAL_SCAN_REQ; |
67b9bd08 | 4292 | wpa_s->scan_interval = 5; |
c302f207 | 4293 | wpa_s->new_connection = 1; |
1772d348 | 4294 | wpa_s->parent = parent ? parent : wpa_s; |
ba307f85 | 4295 | wpa_s->p2pdev = wpa_s->parent; |
cbdf3507 | 4296 | wpa_s->sched_scanning = 0; |
6fc6879b | 4297 | |
dd599908 | 4298 | dl_list_init(&wpa_s->bss_tmp_disallowed); |
5732b770 | 4299 | dl_list_init(&wpa_s->fils_hlp_req); |
dd599908 | 4300 | |
6fc6879b JM |
4301 | return wpa_s; |
4302 | } | |
4303 | ||
4304 | ||
80e8a5ee BG |
4305 | #ifdef CONFIG_HT_OVERRIDES |
4306 | ||
4307 | static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s, | |
4308 | struct ieee80211_ht_capabilities *htcaps, | |
4309 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4310 | const char *ht_mcs) | |
4311 | { | |
4312 | /* parse ht_mcs into hex array */ | |
4313 | int i; | |
4314 | const char *tmp = ht_mcs; | |
4315 | char *end = NULL; | |
4316 | ||
4317 | /* If ht_mcs is null, do not set anything */ | |
4318 | if (!ht_mcs) | |
4319 | return 0; | |
4320 | ||
4321 | /* This is what we are setting in the kernel */ | |
4322 | os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN); | |
4323 | ||
4324 | wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs); | |
4325 | ||
4326 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
30eddf35 JB |
4327 | long v; |
4328 | ||
80e8a5ee | 4329 | errno = 0; |
30eddf35 JB |
4330 | v = strtol(tmp, &end, 16); |
4331 | ||
80e8a5ee BG |
4332 | if (errno == 0) { |
4333 | wpa_msg(wpa_s, MSG_DEBUG, | |
4334 | "htcap value[%i]: %ld end: %p tmp: %p", | |
4335 | i, v, end, tmp); | |
4336 | if (end == tmp) | |
4337 | break; | |
4338 | ||
4339 | htcaps->supported_mcs_set[i] = v; | |
4340 | tmp = end; | |
4341 | } else { | |
4342 | wpa_msg(wpa_s, MSG_ERROR, | |
4343 | "Failed to parse ht-mcs: %s, error: %s\n", | |
4344 | ht_mcs, strerror(errno)); | |
4345 | return -1; | |
4346 | } | |
4347 | } | |
4348 | ||
4349 | /* | |
4350 | * If we were able to parse any values, then set mask for the MCS set. | |
4351 | */ | |
4352 | if (i) { | |
4353 | os_memset(&htcaps_mask->supported_mcs_set, 0xff, | |
4354 | IEEE80211_HT_MCS_MASK_LEN - 1); | |
4355 | /* skip the 3 reserved bits */ | |
4356 | htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] = | |
4357 | 0x1f; | |
4358 | } | |
4359 | ||
4360 | return 0; | |
4361 | } | |
4362 | ||
4363 | ||
4364 | static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s, | |
4365 | struct ieee80211_ht_capabilities *htcaps, | |
4366 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4367 | int disabled) | |
4368 | { | |
5bc28571 | 4369 | le16 msk; |
80e8a5ee BG |
4370 | |
4371 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled); | |
4372 | ||
4373 | if (disabled == -1) | |
4374 | return 0; | |
4375 | ||
4376 | msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE); | |
4377 | htcaps_mask->ht_capabilities_info |= msk; | |
4378 | if (disabled) | |
4379 | htcaps->ht_capabilities_info &= msk; | |
4380 | else | |
4381 | htcaps->ht_capabilities_info |= msk; | |
4382 | ||
4383 | return 0; | |
4384 | } | |
4385 | ||
4386 | ||
4387 | static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s, | |
4388 | struct ieee80211_ht_capabilities *htcaps, | |
4389 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4390 | int factor) | |
4391 | { | |
4392 | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor); | |
4393 | ||
4394 | if (factor == -1) | |
4395 | return 0; | |
4396 | ||
4397 | if (factor < 0 || factor > 3) { | |
4398 | wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. " | |
4399 | "Must be 0-3 or -1", factor); | |
4400 | return -EINVAL; | |
4401 | } | |
4402 | ||
4403 | htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */ | |
4404 | htcaps->a_mpdu_params &= ~0x3; | |
4405 | htcaps->a_mpdu_params |= factor & 0x3; | |
4406 | ||
4407 | return 0; | |
4408 | } | |
4409 | ||
4410 | ||
4411 | static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s, | |
4412 | struct ieee80211_ht_capabilities *htcaps, | |
4413 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4414 | int density) | |
4415 | { | |
4416 | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density); | |
4417 | ||
4418 | if (density == -1) | |
4419 | return 0; | |
4420 | ||
4421 | if (density < 0 || density > 7) { | |
4422 | wpa_msg(wpa_s, MSG_ERROR, | |
4423 | "ampdu_density: %d out of range. Must be 0-7 or -1.", | |
4424 | density); | |
4425 | return -EINVAL; | |
4426 | } | |
4427 | ||
4428 | htcaps_mask->a_mpdu_params |= 0x1C; | |
4429 | htcaps->a_mpdu_params &= ~(0x1C); | |
4430 | htcaps->a_mpdu_params |= (density << 2) & 0x1C; | |
4431 | ||
4432 | return 0; | |
4433 | } | |
4434 | ||
4435 | ||
4436 | static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s, | |
4437 | struct ieee80211_ht_capabilities *htcaps, | |
4438 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4439 | int disabled) | |
4440 | { | |
80e8a5ee BG |
4441 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled); |
4442 | ||
9eb5757a MH |
4443 | set_disable_ht40(htcaps, disabled); |
4444 | set_disable_ht40(htcaps_mask, 0); | |
80e8a5ee BG |
4445 | |
4446 | return 0; | |
4447 | } | |
4448 | ||
4449 | ||
a90497f8 BG |
4450 | static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s, |
4451 | struct ieee80211_ht_capabilities *htcaps, | |
4452 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4453 | int disabled) | |
4454 | { | |
4455 | /* Masking these out disables SGI */ | |
5bc28571 JM |
4456 | le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ | |
4457 | HT_CAP_INFO_SHORT_GI40MHZ); | |
a90497f8 BG |
4458 | |
4459 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled); | |
4460 | ||
4461 | if (disabled) | |
4462 | htcaps->ht_capabilities_info &= ~msk; | |
4463 | else | |
4464 | htcaps->ht_capabilities_info |= msk; | |
4465 | ||
4466 | htcaps_mask->ht_capabilities_info |= msk; | |
4467 | ||
4468 | return 0; | |
4469 | } | |
4470 | ||
4471 | ||
39a5800f PK |
4472 | static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s, |
4473 | struct ieee80211_ht_capabilities *htcaps, | |
4474 | struct ieee80211_ht_capabilities *htcaps_mask, | |
4475 | int disabled) | |
4476 | { | |
4477 | /* Masking these out disables LDPC */ | |
5bc28571 | 4478 | le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP); |
39a5800f PK |
4479 | |
4480 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled); | |
4481 | ||
4482 | if (disabled) | |
4483 | htcaps->ht_capabilities_info &= ~msk; | |
4484 | else | |
4485 | htcaps->ht_capabilities_info |= msk; | |
4486 | ||
4487 | htcaps_mask->ht_capabilities_info |= msk; | |
4488 | ||
4489 | return 0; | |
4490 | } | |
4491 | ||
4492 | ||
80e8a5ee BG |
4493 | void wpa_supplicant_apply_ht_overrides( |
4494 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
4495 | struct wpa_driver_associate_params *params) | |
4496 | { | |
4497 | struct ieee80211_ht_capabilities *htcaps; | |
4498 | struct ieee80211_ht_capabilities *htcaps_mask; | |
4499 | ||
4500 | if (!ssid) | |
4501 | return; | |
4502 | ||
4503 | params->disable_ht = ssid->disable_ht; | |
4504 | if (!params->htcaps || !params->htcaps_mask) | |
4505 | return; | |
4506 | ||
4507 | htcaps = (struct ieee80211_ht_capabilities *) params->htcaps; | |
4508 | htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask; | |
4509 | wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs); | |
4510 | wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask, | |
4511 | ssid->disable_max_amsdu); | |
4512 | wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor); | |
4513 | wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density); | |
4514 | wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40); | |
a90497f8 | 4515 | wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi); |
39a5800f | 4516 | wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc); |
d41cc8cc JM |
4517 | |
4518 | if (ssid->ht40_intolerant) { | |
5bc28571 | 4519 | le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT); |
d41cc8cc JM |
4520 | htcaps->ht_capabilities_info |= bit; |
4521 | htcaps_mask->ht_capabilities_info |= bit; | |
4522 | } | |
80e8a5ee BG |
4523 | } |
4524 | ||
4525 | #endif /* CONFIG_HT_OVERRIDES */ | |
4526 | ||
4527 | ||
e9ee8dc3 JB |
4528 | #ifdef CONFIG_VHT_OVERRIDES |
4529 | void wpa_supplicant_apply_vht_overrides( | |
4530 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, | |
4531 | struct wpa_driver_associate_params *params) | |
4532 | { | |
4533 | struct ieee80211_vht_capabilities *vhtcaps; | |
4534 | struct ieee80211_vht_capabilities *vhtcaps_mask; | |
4535 | ||
4536 | if (!ssid) | |
4537 | return; | |
4538 | ||
4539 | params->disable_vht = ssid->disable_vht; | |
4540 | ||
4541 | vhtcaps = (void *) params->vhtcaps; | |
4542 | vhtcaps_mask = (void *) params->vhtcaps_mask; | |
4543 | ||
4544 | if (!vhtcaps || !vhtcaps_mask) | |
4545 | return; | |
4546 | ||
4d8d710f JM |
4547 | vhtcaps->vht_capabilities_info = host_to_le32(ssid->vht_capa); |
4548 | vhtcaps_mask->vht_capabilities_info = host_to_le32(ssid->vht_capa_mask); | |
e9ee8dc3 | 4549 | |
4f560cde EP |
4550 | #ifdef CONFIG_HT_OVERRIDES |
4551 | /* if max ampdu is <= 3, we have to make the HT cap the same */ | |
b0f33467 JM |
4552 | if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) { |
4553 | int max_ampdu; | |
4554 | ||
4555 | max_ampdu = (ssid->vht_capa & | |
4556 | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >> | |
4557 | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT; | |
4f560cde EP |
4558 | |
4559 | max_ampdu = max_ampdu < 3 ? max_ampdu : 3; | |
4560 | wpa_set_ampdu_factor(wpa_s, | |
4561 | (void *) params->htcaps, | |
4562 | (void *) params->htcaps_mask, | |
4563 | max_ampdu); | |
4564 | } | |
4565 | #endif /* CONFIG_HT_OVERRIDES */ | |
4566 | ||
e9ee8dc3 JB |
4567 | #define OVERRIDE_MCS(i) \ |
4568 | if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \ | |
4569 | vhtcaps_mask->vht_supported_mcs_set.tx_map |= \ | |
4d8d710f | 4570 | host_to_le16(3 << 2 * (i - 1)); \ |
e9ee8dc3 | 4571 | vhtcaps->vht_supported_mcs_set.tx_map |= \ |
4d8d710f JM |
4572 | host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \ |
4573 | 2 * (i - 1)); \ | |
e9ee8dc3 JB |
4574 | } \ |
4575 | if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \ | |
4576 | vhtcaps_mask->vht_supported_mcs_set.rx_map |= \ | |
4d8d710f | 4577 | host_to_le16(3 << 2 * (i - 1)); \ |
e9ee8dc3 | 4578 | vhtcaps->vht_supported_mcs_set.rx_map |= \ |
4d8d710f JM |
4579 | host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \ |
4580 | 2 * (i - 1)); \ | |
e9ee8dc3 JB |
4581 | } |
4582 | ||
4583 | OVERRIDE_MCS(1); | |
4584 | OVERRIDE_MCS(2); | |
4585 | OVERRIDE_MCS(3); | |
4586 | OVERRIDE_MCS(4); | |
4587 | OVERRIDE_MCS(5); | |
4588 | OVERRIDE_MCS(6); | |
4589 | OVERRIDE_MCS(7); | |
4590 | OVERRIDE_MCS(8); | |
4591 | } | |
4592 | #endif /* CONFIG_VHT_OVERRIDES */ | |
4593 | ||
4594 | ||
f64adcd7 JM |
4595 | static int pcsc_reader_init(struct wpa_supplicant *wpa_s) |
4596 | { | |
4597 | #ifdef PCSC_FUNCS | |
4598 | size_t len; | |
4599 | ||
4600 | if (!wpa_s->conf->pcsc_reader) | |
4601 | return 0; | |
4602 | ||
22cf7d73 | 4603 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
f64adcd7 JM |
4604 | if (!wpa_s->scard) |
4605 | return 1; | |
4606 | ||
4607 | if (wpa_s->conf->pcsc_pin && | |
4608 | scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) { | |
4609 | scard_deinit(wpa_s->scard); | |
4610 | wpa_s->scard = NULL; | |
4611 | wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed"); | |
4612 | return -1; | |
4613 | } | |
4614 | ||
4615 | len = sizeof(wpa_s->imsi) - 1; | |
4616 | if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) { | |
4617 | scard_deinit(wpa_s->scard); | |
4618 | wpa_s->scard = NULL; | |
4619 | wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI"); | |
4620 | return -1; | |
4621 | } | |
4622 | wpa_s->imsi[len] = '\0'; | |
4623 | ||
4624 | wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard); | |
4625 | ||
4626 | wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)", | |
4627 | wpa_s->imsi, wpa_s->mnc_len); | |
4628 | ||
4629 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
4630 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
4631 | #endif /* PCSC_FUNCS */ | |
4632 | ||
4633 | return 0; | |
4634 | } | |
4635 | ||
4636 | ||
306ae225 JM |
4637 | int wpas_init_ext_pw(struct wpa_supplicant *wpa_s) |
4638 | { | |
4639 | char *val, *pos; | |
4640 | ||
4641 | ext_password_deinit(wpa_s->ext_pw); | |
4642 | wpa_s->ext_pw = NULL; | |
4643 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL); | |
4644 | ||
4645 | if (!wpa_s->conf->ext_password_backend) | |
4646 | return 0; | |
4647 | ||
4648 | val = os_strdup(wpa_s->conf->ext_password_backend); | |
4649 | if (val == NULL) | |
4650 | return -1; | |
4651 | pos = os_strchr(val, ':'); | |
4652 | if (pos) | |
4653 | *pos++ = '\0'; | |
4654 | ||
4655 | wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val); | |
4656 | ||
4657 | wpa_s->ext_pw = ext_password_init(val, pos); | |
4658 | os_free(val); | |
4659 | if (wpa_s->ext_pw == NULL) { | |
4660 | wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend"); | |
4661 | return -1; | |
4662 | } | |
4663 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw); | |
4664 | ||
4665 | return 0; | |
4666 | } | |
4667 | ||
4668 | ||
b36a3a65 AN |
4669 | #ifdef CONFIG_FST |
4670 | ||
4671 | static const u8 * wpas_fst_get_bssid_cb(void *ctx) | |
4672 | { | |
4673 | struct wpa_supplicant *wpa_s = ctx; | |
4674 | ||
4675 | return (is_zero_ether_addr(wpa_s->bssid) || | |
4676 | wpa_s->wpa_state != WPA_COMPLETED) ? NULL : wpa_s->bssid; | |
4677 | } | |
4678 | ||
4679 | ||
4680 | static void wpas_fst_get_channel_info_cb(void *ctx, | |
4681 | enum hostapd_hw_mode *hw_mode, | |
4682 | u8 *channel) | |
4683 | { | |
4684 | struct wpa_supplicant *wpa_s = ctx; | |
4685 | ||
4686 | if (wpa_s->current_bss) { | |
4687 | *hw_mode = ieee80211_freq_to_chan(wpa_s->current_bss->freq, | |
4688 | channel); | |
4689 | } else if (wpa_s->hw.num_modes) { | |
4690 | *hw_mode = wpa_s->hw.modes[0].mode; | |
4691 | } else { | |
4692 | WPA_ASSERT(0); | |
4693 | *hw_mode = 0; | |
4694 | } | |
4695 | } | |
4696 | ||
4697 | ||
4698 | static int wpas_fst_get_hw_modes(void *ctx, struct hostapd_hw_modes **modes) | |
4699 | { | |
4700 | struct wpa_supplicant *wpa_s = ctx; | |
4701 | ||
4702 | *modes = wpa_s->hw.modes; | |
4703 | return wpa_s->hw.num_modes; | |
4704 | } | |
4705 | ||
4706 | ||
84bcb4e7 | 4707 | static void wpas_fst_set_ies_cb(void *ctx, const struct wpabuf *fst_ies) |
b36a3a65 AN |
4708 | { |
4709 | struct wpa_supplicant *wpa_s = ctx; | |
4710 | ||
b7a07937 | 4711 | wpa_hexdump_buf(MSG_DEBUG, "FST: Set IEs", fst_ies); |
b36a3a65 AN |
4712 | wpa_s->fst_ies = fst_ies; |
4713 | } | |
4714 | ||
4715 | ||
4716 | static int wpas_fst_send_action_cb(void *ctx, const u8 *da, struct wpabuf *data) | |
4717 | { | |
4718 | struct wpa_supplicant *wpa_s = ctx; | |
4719 | ||
0da35523 JM |
4720 | if (os_memcmp(wpa_s->bssid, da, ETH_ALEN) != 0) { |
4721 | wpa_printf(MSG_INFO, "FST:%s:bssid=" MACSTR " != da=" MACSTR, | |
4722 | __func__, MAC2STR(wpa_s->bssid), MAC2STR(da)); | |
4723 | return -1; | |
4724 | } | |
b36a3a65 | 4725 | return wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
0da35523 JM |
4726 | wpa_s->own_addr, wpa_s->bssid, |
4727 | wpabuf_head(data), wpabuf_len(data), | |
b36a3a65 AN |
4728 | 0); |
4729 | } | |
4730 | ||
4731 | ||
a0f04da5 | 4732 | static const struct wpabuf * wpas_fst_get_mb_ie_cb(void *ctx, const u8 *addr) |
b36a3a65 AN |
4733 | { |
4734 | struct wpa_supplicant *wpa_s = ctx; | |
4735 | ||
4736 | WPA_ASSERT(os_memcmp(wpa_s->bssid, addr, ETH_ALEN) == 0); | |
4737 | return wpa_s->received_mb_ies; | |
4738 | } | |
4739 | ||
4740 | ||
4741 | static void wpas_fst_update_mb_ie_cb(void *ctx, const u8 *addr, | |
4742 | const u8 *buf, size_t size) | |
4743 | { | |
4744 | struct wpa_supplicant *wpa_s = ctx; | |
4745 | struct mb_ies_info info; | |
4746 | ||
4747 | WPA_ASSERT(os_memcmp(wpa_s->bssid, addr, ETH_ALEN) == 0); | |
4748 | ||
4749 | if (!mb_ies_info_by_ies(&info, buf, size)) { | |
4750 | wpabuf_free(wpa_s->received_mb_ies); | |
4751 | wpa_s->received_mb_ies = mb_ies_by_info(&info); | |
4752 | } | |
4753 | } | |
4754 | ||
4755 | ||
39cdd3a0 JM |
4756 | static const u8 * wpas_fst_get_peer_first(void *ctx, |
4757 | struct fst_get_peer_ctx **get_ctx, | |
4758 | Boolean mb_only) | |
b36a3a65 AN |
4759 | { |
4760 | struct wpa_supplicant *wpa_s = ctx; | |
4761 | ||
4762 | *get_ctx = NULL; | |
4763 | if (!is_zero_ether_addr(wpa_s->bssid)) | |
4764 | return (wpa_s->received_mb_ies || !mb_only) ? | |
4765 | wpa_s->bssid : NULL; | |
4766 | return NULL; | |
4767 | } | |
4768 | ||
4769 | ||
39cdd3a0 JM |
4770 | static const u8 * wpas_fst_get_peer_next(void *ctx, |
4771 | struct fst_get_peer_ctx **get_ctx, | |
4772 | Boolean mb_only) | |
b36a3a65 AN |
4773 | { |
4774 | return NULL; | |
4775 | } | |
4776 | ||
4777 | void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant *wpa_s, | |
4778 | struct fst_wpa_obj *iface_obj) | |
4779 | { | |
4780 | iface_obj->ctx = wpa_s; | |
4781 | iface_obj->get_bssid = wpas_fst_get_bssid_cb; | |
4782 | iface_obj->get_channel_info = wpas_fst_get_channel_info_cb; | |
4783 | iface_obj->get_hw_modes = wpas_fst_get_hw_modes; | |
4784 | iface_obj->set_ies = wpas_fst_set_ies_cb; | |
4785 | iface_obj->send_action = wpas_fst_send_action_cb; | |
4786 | iface_obj->get_mb_ie = wpas_fst_get_mb_ie_cb; | |
4787 | iface_obj->update_mb_ie = wpas_fst_update_mb_ie_cb; | |
4788 | iface_obj->get_peer_first = wpas_fst_get_peer_first; | |
4789 | iface_obj->get_peer_next = wpas_fst_get_peer_next; | |
4790 | } | |
4791 | #endif /* CONFIG_FST */ | |
4792 | ||
a520bf4a | 4793 | static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s, |
6cbdb0c5 | 4794 | const struct wpa_driver_capa *capa) |
e4fa8b12 | 4795 | { |
88cb27c7 DS |
4796 | struct wowlan_triggers *triggers; |
4797 | int ret = 0; | |
e4fa8b12 EP |
4798 | |
4799 | if (!wpa_s->conf->wowlan_triggers) | |
4800 | return 0; | |
4801 | ||
88cb27c7 DS |
4802 | triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa); |
4803 | if (triggers) { | |
4804 | ret = wpa_drv_wowlan(wpa_s, triggers); | |
4805 | os_free(triggers); | |
e4fa8b12 | 4806 | } |
e4fa8b12 EP |
4807 | return ret; |
4808 | } | |
4809 | ||
4810 | ||
2b6e9f91 | 4811 | enum wpa_radio_work_band wpas_freq_to_band(int freq) |
e903d32d KV |
4812 | { |
4813 | if (freq < 3000) | |
4814 | return BAND_2_4_GHZ; | |
4815 | if (freq > 50000) | |
4816 | return BAND_60_GHZ; | |
4817 | return BAND_5_GHZ; | |
4818 | } | |
4819 | ||
4820 | ||
2b6e9f91 | 4821 | unsigned int wpas_get_bands(struct wpa_supplicant *wpa_s, const int *freqs) |
e903d32d KV |
4822 | { |
4823 | int i; | |
4824 | unsigned int band = 0; | |
4825 | ||
4826 | if (freqs) { | |
4827 | /* freqs are specified for the radio work */ | |
4828 | for (i = 0; freqs[i]; i++) | |
4829 | band |= wpas_freq_to_band(freqs[i]); | |
4830 | } else { | |
4831 | /* | |
4832 | * freqs are not specified, implies all | |
4833 | * the supported freqs by HW | |
4834 | */ | |
4835 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
4836 | if (wpa_s->hw.modes[i].num_channels != 0) { | |
4837 | if (wpa_s->hw.modes[i].mode == | |
4838 | HOSTAPD_MODE_IEEE80211B || | |
4839 | wpa_s->hw.modes[i].mode == | |
4840 | HOSTAPD_MODE_IEEE80211G) | |
4841 | band |= BAND_2_4_GHZ; | |
4842 | else if (wpa_s->hw.modes[i].mode == | |
4843 | HOSTAPD_MODE_IEEE80211A) | |
4844 | band |= BAND_5_GHZ; | |
4845 | else if (wpa_s->hw.modes[i].mode == | |
4846 | HOSTAPD_MODE_IEEE80211AD) | |
4847 | band |= BAND_60_GHZ; | |
4848 | else if (wpa_s->hw.modes[i].mode == | |
4849 | HOSTAPD_MODE_IEEE80211ANY) | |
4850 | band = BAND_2_4_GHZ | BAND_5_GHZ | | |
4851 | BAND_60_GHZ; | |
4852 | } | |
4853 | } | |
4854 | } | |
4855 | ||
4856 | return band; | |
4857 | } | |
4858 | ||
4859 | ||
202dec2a JM |
4860 | static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s, |
4861 | const char *rn) | |
4862 | { | |
4863 | struct wpa_supplicant *iface = wpa_s->global->ifaces; | |
4864 | struct wpa_radio *radio; | |
4865 | ||
4866 | while (rn && iface) { | |
4867 | radio = iface->radio; | |
4868 | if (radio && os_strcmp(rn, radio->name) == 0) { | |
4869 | wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s", | |
4870 | wpa_s->ifname, rn); | |
4871 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); | |
4872 | return radio; | |
4873 | } | |
b154a24e TB |
4874 | |
4875 | iface = iface->next; | |
202dec2a JM |
4876 | } |
4877 | ||
4878 | wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s", | |
4879 | wpa_s->ifname, rn ? rn : "N/A"); | |
4880 | radio = os_zalloc(sizeof(*radio)); | |
4881 | if (radio == NULL) | |
4882 | return NULL; | |
4883 | ||
4884 | if (rn) | |
4885 | os_strlcpy(radio->name, rn, sizeof(radio->name)); | |
4886 | dl_list_init(&radio->ifaces); | |
b1ae396f | 4887 | dl_list_init(&radio->work); |
202dec2a JM |
4888 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); |
4889 | ||
4890 | return radio; | |
4891 | } | |
4892 | ||
4893 | ||
b1ae396f JM |
4894 | static void radio_work_free(struct wpa_radio_work *work) |
4895 | { | |
d12a51b5 JM |
4896 | if (work->wpa_s->scan_work == work) { |
4897 | /* This should not really happen. */ | |
4898 | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work", | |
4899 | work->type, work, work->started); | |
4900 | work->wpa_s->scan_work = NULL; | |
4901 | } | |
4902 | ||
1b5d4714 JM |
4903 | #ifdef CONFIG_P2P |
4904 | if (work->wpa_s->p2p_scan_work == work) { | |
4905 | /* This should not really happen. */ | |
4906 | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work", | |
4907 | work->type, work, work->started); | |
4908 | work->wpa_s->p2p_scan_work = NULL; | |
4909 | } | |
4910 | #endif /* CONFIG_P2P */ | |
4911 | ||
e903d32d KV |
4912 | if (work->started) { |
4913 | work->wpa_s->radio->num_active_works--; | |
4914 | wpa_dbg(work->wpa_s, MSG_DEBUG, | |
7ed5337d | 4915 | "radio_work_free('%s'@%p): num_active_works --> %u", |
e903d32d KV |
4916 | work->type, work, |
4917 | work->wpa_s->radio->num_active_works); | |
4918 | } | |
4919 | ||
b1ae396f JM |
4920 | dl_list_del(&work->list); |
4921 | os_free(work); | |
4922 | } | |
4923 | ||
4924 | ||
4c6f450c JM |
4925 | static int radio_work_is_connect(struct wpa_radio_work *work) |
4926 | { | |
4927 | return os_strcmp(work->type, "sme-connect") == 0 || | |
4928 | os_strcmp(work->type, "connect") == 0; | |
4929 | } | |
4930 | ||
4931 | ||
85b6b6b6 SD |
4932 | static int radio_work_is_scan(struct wpa_radio_work *work) |
4933 | { | |
4934 | return os_strcmp(work->type, "scan") == 0 || | |
4935 | os_strcmp(work->type, "p2p-scan") == 0; | |
4936 | } | |
4937 | ||
4938 | ||
e903d32d KV |
4939 | static struct wpa_radio_work * radio_work_get_next_work(struct wpa_radio *radio) |
4940 | { | |
4941 | struct wpa_radio_work *active_work = NULL; | |
4942 | struct wpa_radio_work *tmp; | |
4943 | ||
4944 | /* Get the active work to know the type and band. */ | |
4945 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) { | |
4946 | if (tmp->started) { | |
4947 | active_work = tmp; | |
4948 | break; | |
4949 | } | |
4950 | } | |
4951 | ||
4952 | if (!active_work) { | |
4953 | /* No active work, start one */ | |
4954 | radio->num_active_works = 0; | |
4955 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, | |
4956 | list) { | |
4957 | if (os_strcmp(tmp->type, "scan") == 0 && | |
4958 | radio->external_scan_running && | |
4959 | (((struct wpa_driver_scan_params *) | |
4960 | tmp->ctx)->only_new_results || | |
4961 | tmp->wpa_s->clear_driver_scan_cache)) | |
4962 | continue; | |
4963 | return tmp; | |
4964 | } | |
4965 | return NULL; | |
4966 | } | |
4967 | ||
4c6f450c | 4968 | if (radio_work_is_connect(active_work)) { |
e903d32d KV |
4969 | /* |
4970 | * If the active work is either connect or sme-connect, | |
4971 | * do not parallelize them with other radio works. | |
4972 | */ | |
4973 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, | |
4974 | "Do not parallelize radio work with %s", | |
4975 | active_work->type); | |
4976 | return NULL; | |
4977 | } | |
4978 | ||
4979 | dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) { | |
4980 | if (tmp->started) | |
4981 | continue; | |
4982 | ||
4983 | /* | |
4984 | * If connect or sme-connect are enqueued, parallelize only | |
4985 | * those operations ahead of them in the queue. | |
4986 | */ | |
4c6f450c | 4987 | if (radio_work_is_connect(tmp)) |
e903d32d KV |
4988 | break; |
4989 | ||
85b6b6b6 SD |
4990 | /* Serialize parallel scan and p2p_scan operations on the same |
4991 | * interface since the driver_nl80211 mechanism for tracking | |
4992 | * scan cookies does not yet have support for this. */ | |
4993 | if (active_work->wpa_s == tmp->wpa_s && | |
4994 | radio_work_is_scan(active_work) && | |
4995 | radio_work_is_scan(tmp)) { | |
4996 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, | |
4997 | "Do not start work '%s' when another work '%s' is already scheduled", | |
4998 | tmp->type, active_work->type); | |
4999 | continue; | |
5000 | } | |
e903d32d KV |
5001 | /* |
5002 | * Check that the radio works are distinct and | |
5003 | * on different bands. | |
5004 | */ | |
5005 | if (os_strcmp(active_work->type, tmp->type) != 0 && | |
5006 | (active_work->bands != tmp->bands)) { | |
5007 | /* | |
5008 | * If a scan has to be scheduled through nl80211 scan | |
5009 | * interface and if an external scan is already running, | |
5010 | * do not schedule the scan since it is likely to get | |
5011 | * rejected by kernel. | |
5012 | */ | |
5013 | if (os_strcmp(tmp->type, "scan") == 0 && | |
5014 | radio->external_scan_running && | |
5015 | (((struct wpa_driver_scan_params *) | |
5016 | tmp->ctx)->only_new_results || | |
5017 | tmp->wpa_s->clear_driver_scan_cache)) | |
5018 | continue; | |
5019 | ||
5020 | wpa_dbg(active_work->wpa_s, MSG_DEBUG, | |
5021 | "active_work:%s new_work:%s", | |
5022 | active_work->type, tmp->type); | |
5023 | return tmp; | |
5024 | } | |
5025 | } | |
5026 | ||
5027 | /* Did not find a radio work to schedule in parallel. */ | |
5028 | return NULL; | |
5029 | } | |
5030 | ||
5031 | ||
b1ae396f JM |
5032 | static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx) |
5033 | { | |
5034 | struct wpa_radio *radio = eloop_ctx; | |
5035 | struct wpa_radio_work *work; | |
5036 | struct os_reltime now, diff; | |
6428d0a7 | 5037 | struct wpa_supplicant *wpa_s; |
b1ae396f JM |
5038 | |
5039 | work = dl_list_first(&radio->work, struct wpa_radio_work, list); | |
e903d32d KV |
5040 | if (work == NULL) { |
5041 | radio->num_active_works = 0; | |
b1ae396f | 5042 | return; |
e903d32d | 5043 | } |
b1ae396f | 5044 | |
6428d0a7 JM |
5045 | wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant, |
5046 | radio_list); | |
e903d32d KV |
5047 | |
5048 | if (!(wpa_s && | |
5049 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)) { | |
5050 | if (work->started) | |
5051 | return; /* already started and still in progress */ | |
5052 | ||
5053 | if (wpa_s && wpa_s->radio->external_scan_running) { | |
5054 | wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes"); | |
5055 | return; | |
5056 | } | |
5057 | } else { | |
5058 | work = NULL; | |
5059 | if (radio->num_active_works < MAX_ACTIVE_WORKS) { | |
5060 | /* get the work to schedule next */ | |
5061 | work = radio_work_get_next_work(radio); | |
5062 | } | |
5063 | if (!work) | |
5064 | return; | |
6428d0a7 JM |
5065 | } |
5066 | ||
e903d32d | 5067 | wpa_s = work->wpa_s; |
b1ae396f JM |
5068 | os_get_reltime(&now); |
5069 | os_reltime_sub(&now, &work->time, &diff); | |
e903d32d KV |
5070 | wpa_dbg(wpa_s, MSG_DEBUG, |
5071 | "Starting radio work '%s'@%p after %ld.%06ld second wait", | |
b1ae396f JM |
5072 | work->type, work, diff.sec, diff.usec); |
5073 | work->started = 1; | |
5074 | work->time = now; | |
e903d32d KV |
5075 | radio->num_active_works++; |
5076 | ||
b1ae396f | 5077 | work->cb(work, 0); |
e903d32d KV |
5078 | |
5079 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) && | |
5080 | radio->num_active_works < MAX_ACTIVE_WORKS) | |
5081 | radio_work_check_next(wpa_s); | |
b1ae396f JM |
5082 | } |
5083 | ||
5084 | ||
b3253ebb AO |
5085 | /* |
5086 | * This function removes both started and pending radio works running on | |
5087 | * the provided interface's radio. | |
5088 | * Prior to the removal of the radio work, its callback (cb) is called with | |
5089 | * deinit set to be 1. Each work's callback is responsible for clearing its | |
5090 | * internal data and restoring to a correct state. | |
5091 | * @wpa_s: wpa_supplicant data | |
5092 | * @type: type of works to be removed | |
5093 | * @remove_all: 1 to remove all the works on this radio, 0 to remove only | |
5094 | * this interface's works. | |
5095 | */ | |
5096 | void radio_remove_works(struct wpa_supplicant *wpa_s, | |
5097 | const char *type, int remove_all) | |
b1ae396f JM |
5098 | { |
5099 | struct wpa_radio_work *work, *tmp; | |
5100 | struct wpa_radio *radio = wpa_s->radio; | |
5101 | ||
5102 | dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work, | |
5103 | list) { | |
b3253ebb | 5104 | if (type && os_strcmp(type, work->type) != 0) |
b1ae396f | 5105 | continue; |
b3253ebb AO |
5106 | |
5107 | /* skip other ifaces' works */ | |
5108 | if (!remove_all && work->wpa_s != wpa_s) | |
b1ae396f | 5109 | continue; |
b3253ebb AO |
5110 | |
5111 | wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s", | |
5112 | work->type, work, work->started ? " (started)" : ""); | |
b1ae396f JM |
5113 | work->cb(work, 1); |
5114 | radio_work_free(work); | |
5115 | } | |
b3253ebb AO |
5116 | |
5117 | /* in case we removed the started work */ | |
5118 | radio_work_check_next(wpa_s); | |
b1ae396f JM |
5119 | } |
5120 | ||
5121 | ||
6a252ece JM |
5122 | void radio_remove_pending_work(struct wpa_supplicant *wpa_s, void *ctx) |
5123 | { | |
5124 | struct wpa_radio_work *work; | |
5125 | struct wpa_radio *radio = wpa_s->radio; | |
5126 | ||
5127 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { | |
5128 | if (work->ctx != ctx) | |
5129 | continue; | |
5130 | wpa_dbg(wpa_s, MSG_DEBUG, "Free pending radio work '%s'@%p%s", | |
5131 | work->type, work, work->started ? " (started)" : ""); | |
5132 | radio_work_free(work); | |
5133 | break; | |
5134 | } | |
5135 | } | |
5136 | ||
5137 | ||
202dec2a JM |
5138 | static void radio_remove_interface(struct wpa_supplicant *wpa_s) |
5139 | { | |
5140 | struct wpa_radio *radio = wpa_s->radio; | |
5141 | ||
5142 | if (!radio) | |
5143 | return; | |
5144 | ||
5145 | wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s", | |
5146 | wpa_s->ifname, radio->name); | |
5147 | dl_list_del(&wpa_s->radio_list); | |
c46235aa AO |
5148 | radio_remove_works(wpa_s, NULL, 0); |
5149 | wpa_s->radio = NULL; | |
5150 | if (!dl_list_empty(&radio->ifaces)) | |
202dec2a JM |
5151 | return; /* Interfaces remain for this radio */ |
5152 | ||
5153 | wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name); | |
b1ae396f | 5154 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
202dec2a JM |
5155 | os_free(radio); |
5156 | } | |
5157 | ||
5158 | ||
6428d0a7 | 5159 | void radio_work_check_next(struct wpa_supplicant *wpa_s) |
b1ae396f JM |
5160 | { |
5161 | struct wpa_radio *radio = wpa_s->radio; | |
5162 | ||
5163 | if (dl_list_empty(&radio->work)) | |
5164 | return; | |
e3745228 JM |
5165 | if (wpa_s->ext_work_in_progress) { |
5166 | wpa_printf(MSG_DEBUG, | |
5167 | "External radio work in progress - delay start of pending item"); | |
5168 | return; | |
5169 | } | |
b1ae396f JM |
5170 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
5171 | eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL); | |
5172 | } | |
5173 | ||
5174 | ||
5175 | /** | |
5176 | * radio_add_work - Add a radio work item | |
5177 | * @wpa_s: Pointer to wpa_supplicant data | |
5178 | * @freq: Frequency of the offchannel operation in MHz or 0 | |
5179 | * @type: Unique identifier for each type of work | |
5180 | * @next: Force as the next work to be executed | |
5181 | * @cb: Callback function for indicating when radio is available | |
5182 | * @ctx: Context pointer for the work (work->ctx in cb()) | |
5183 | * Returns: 0 on success, -1 on failure | |
5184 | * | |
5185 | * This function is used to request time for an operation that requires | |
5186 | * exclusive radio control. Once the radio is available, the registered callback | |
5187 | * function will be called. radio_work_done() must be called once the exclusive | |
5188 | * radio operation has been completed, so that the radio is freed for other | |
5189 | * operations. The special case of deinit=1 is used to free the context data | |
5190 | * during interface removal. That does not allow the callback function to start | |
5191 | * the radio operation, i.e., it must free any resources allocated for the radio | |
5192 | * work and return. | |
5193 | * | |
5194 | * The @freq parameter can be used to indicate a single channel on which the | |
5195 | * offchannel operation will occur. This may allow multiple radio work | |
5196 | * operations to be performed in parallel if they apply for the same channel. | |
5197 | * Setting this to 0 indicates that the work item may use multiple channels or | |
5198 | * requires exclusive control of the radio. | |
5199 | */ | |
5200 | int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq, | |
5201 | const char *type, int next, | |
5202 | void (*cb)(struct wpa_radio_work *work, int deinit), | |
5203 | void *ctx) | |
5204 | { | |
e903d32d | 5205 | struct wpa_radio *radio = wpa_s->radio; |
b1ae396f JM |
5206 | struct wpa_radio_work *work; |
5207 | int was_empty; | |
5208 | ||
5209 | work = os_zalloc(sizeof(*work)); | |
5210 | if (work == NULL) | |
5211 | return -1; | |
5212 | wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work); | |
5213 | os_get_reltime(&work->time); | |
5214 | work->freq = freq; | |
5215 | work->type = type; | |
5216 | work->wpa_s = wpa_s; | |
5217 | work->cb = cb; | |
5218 | work->ctx = ctx; | |
5219 | ||
e903d32d KV |
5220 | if (freq) |
5221 | work->bands = wpas_freq_to_band(freq); | |
5222 | else if (os_strcmp(type, "scan") == 0 || | |
5223 | os_strcmp(type, "p2p-scan") == 0) | |
5224 | work->bands = wpas_get_bands(wpa_s, | |
5225 | ((struct wpa_driver_scan_params *) | |
5226 | ctx)->freqs); | |
5227 | else | |
5228 | work->bands = wpas_get_bands(wpa_s, NULL); | |
5229 | ||
b1ae396f JM |
5230 | was_empty = dl_list_empty(&wpa_s->radio->work); |
5231 | if (next) | |
5232 | dl_list_add(&wpa_s->radio->work, &work->list); | |
5233 | else | |
5234 | dl_list_add_tail(&wpa_s->radio->work, &work->list); | |
5235 | if (was_empty) { | |
5236 | wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately"); | |
5237 | radio_work_check_next(wpa_s); | |
e903d32d KV |
5238 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) |
5239 | && radio->num_active_works < MAX_ACTIVE_WORKS) { | |
5240 | wpa_dbg(wpa_s, MSG_DEBUG, | |
5241 | "Try to schedule a radio work (num_active_works=%u)", | |
5242 | radio->num_active_works); | |
5243 | radio_work_check_next(wpa_s); | |
b1ae396f JM |
5244 | } |
5245 | ||
5246 | return 0; | |
5247 | } | |
5248 | ||
5249 | ||
5250 | /** | |
5251 | * radio_work_done - Indicate that a radio work item has been completed | |
5252 | * @work: Completed work | |
5253 | * | |
5254 | * This function is called once the callback function registered with | |
5255 | * radio_add_work() has completed its work. | |
5256 | */ | |
5257 | void radio_work_done(struct wpa_radio_work *work) | |
5258 | { | |
5259 | struct wpa_supplicant *wpa_s = work->wpa_s; | |
5260 | struct os_reltime now, diff; | |
1f965e62 | 5261 | unsigned int started = work->started; |
b1ae396f JM |
5262 | |
5263 | os_get_reltime(&now); | |
5264 | os_reltime_sub(&now, &work->time, &diff); | |
1f965e62 JM |
5265 | wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds", |
5266 | work->type, work, started ? "done" : "canceled", | |
5267 | diff.sec, diff.usec); | |
b1ae396f | 5268 | radio_work_free(work); |
1f965e62 JM |
5269 | if (started) |
5270 | radio_work_check_next(wpa_s); | |
b1ae396f JM |
5271 | } |
5272 | ||
5273 | ||
a7f5271d JM |
5274 | struct wpa_radio_work * |
5275 | radio_work_pending(struct wpa_supplicant *wpa_s, const char *type) | |
f0e30c84 JM |
5276 | { |
5277 | struct wpa_radio_work *work; | |
5278 | struct wpa_radio *radio = wpa_s->radio; | |
5279 | ||
5280 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { | |
5281 | if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0) | |
a7f5271d | 5282 | return work; |
f0e30c84 JM |
5283 | } |
5284 | ||
a7f5271d | 5285 | return NULL; |
f0e30c84 JM |
5286 | } |
5287 | ||
5288 | ||
73c00fd7 | 5289 | static int wpas_init_driver(struct wpa_supplicant *wpa_s, |
8fb2b357 | 5290 | const struct wpa_interface *iface) |
73c00fd7 | 5291 | { |
202dec2a | 5292 | const char *ifname, *driver, *rn; |
73c00fd7 JM |
5293 | |
5294 | driver = iface->driver; | |
5295 | next_driver: | |
5296 | if (wpa_supplicant_set_driver(wpa_s, driver) < 0) | |
5297 | return -1; | |
5298 | ||
5299 | wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname); | |
5300 | if (wpa_s->drv_priv == NULL) { | |
5301 | const char *pos; | |
5302 | pos = driver ? os_strchr(driver, ',') : NULL; | |
5303 | if (pos) { | |
5304 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " | |
5305 | "driver interface - try next driver wrapper"); | |
5306 | driver = pos + 1; | |
5307 | goto next_driver; | |
5308 | } | |
5309 | wpa_msg(wpa_s, MSG_ERROR, "Failed to initialize driver " | |
5310 | "interface"); | |
5311 | return -1; | |
5312 | } | |
5313 | if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) { | |
5314 | wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected " | |
5315 | "driver_param '%s'", wpa_s->conf->driver_param); | |
5316 | return -1; | |
5317 | } | |
5318 | ||
5319 | ifname = wpa_drv_get_ifname(wpa_s); | |
5320 | if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) { | |
5321 | wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced " | |
5322 | "interface name with '%s'", ifname); | |
5323 | os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname)); | |
5324 | } | |
5325 | ||
95bf699f | 5326 | rn = wpa_driver_get_radio_name(wpa_s); |
202dec2a JM |
5327 | if (rn && rn[0] == '\0') |
5328 | rn = NULL; | |
5329 | ||
5330 | wpa_s->radio = radio_add_interface(wpa_s, rn); | |
5331 | if (wpa_s->radio == NULL) | |
5332 | return -1; | |
5333 | ||
73c00fd7 JM |
5334 | return 0; |
5335 | } | |
5336 | ||
5337 | ||
461d39af JM |
5338 | #ifdef CONFIG_GAS_SERVER |
5339 | ||
5340 | static void wpas_gas_server_tx_status(struct wpa_supplicant *wpa_s, | |
5341 | unsigned int freq, const u8 *dst, | |
5342 | const u8 *src, const u8 *bssid, | |
5343 | const u8 *data, size_t data_len, | |
5344 | enum offchannel_send_action_result result) | |
5345 | { | |
5346 | wpa_printf(MSG_DEBUG, "GAS: TX status: freq=%u dst=" MACSTR | |
5347 | " result=%s", | |
5348 | freq, MAC2STR(dst), | |
5349 | result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" : | |
5350 | (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" : | |
5351 | "FAILED")); | |
5352 | gas_server_tx_status(wpa_s->gas_server, dst, data, data_len, | |
5353 | result == OFFCHANNEL_SEND_ACTION_SUCCESS); | |
5354 | } | |
5355 | ||
5356 | ||
5357 | static void wpas_gas_server_tx(void *ctx, int freq, const u8 *da, | |
5358 | struct wpabuf *buf, unsigned int wait_time) | |
5359 | { | |
5360 | struct wpa_supplicant *wpa_s = ctx; | |
5361 | const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
5362 | ||
5363 | if (wait_time > wpa_s->max_remain_on_chan) | |
5364 | wait_time = wpa_s->max_remain_on_chan; | |
5365 | ||
5366 | offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, broadcast, | |
5367 | wpabuf_head(buf), wpabuf_len(buf), | |
5368 | wait_time, wpas_gas_server_tx_status, 0); | |
5369 | } | |
5370 | ||
5371 | #endif /* CONFIG_GAS_SERVER */ | |
5372 | ||
6fc6879b | 5373 | static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s, |
8fb2b357 | 5374 | const struct wpa_interface *iface) |
6fc6879b | 5375 | { |
362f781e | 5376 | struct wpa_driver_capa capa; |
6cbdb0c5 | 5377 | int capa_res; |
aa56e36d | 5378 | u8 dfs_domain; |
362f781e | 5379 | |
6fc6879b JM |
5380 | wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver " |
5381 | "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname, | |
5382 | iface->confname ? iface->confname : "N/A", | |
5383 | iface->driver ? iface->driver : "default", | |
5384 | iface->ctrl_interface ? iface->ctrl_interface : "N/A", | |
5385 | iface->bridge_ifname ? iface->bridge_ifname : "N/A"); | |
5386 | ||
6fc6879b JM |
5387 | if (iface->confname) { |
5388 | #ifdef CONFIG_BACKEND_FILE | |
5389 | wpa_s->confname = os_rel2abs_path(iface->confname); | |
5390 | if (wpa_s->confname == NULL) { | |
5391 | wpa_printf(MSG_ERROR, "Failed to get absolute path " | |
5392 | "for configuration file '%s'.", | |
5393 | iface->confname); | |
5394 | return -1; | |
5395 | } | |
5396 | wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'", | |
5397 | iface->confname, wpa_s->confname); | |
5398 | #else /* CONFIG_BACKEND_FILE */ | |
5399 | wpa_s->confname = os_strdup(iface->confname); | |
5400 | #endif /* CONFIG_BACKEND_FILE */ | |
e6304cad | 5401 | wpa_s->conf = wpa_config_read(wpa_s->confname, NULL); |
6fc6879b JM |
5402 | if (wpa_s->conf == NULL) { |
5403 | wpa_printf(MSG_ERROR, "Failed to read or parse " | |
5404 | "configuration '%s'.", wpa_s->confname); | |
5405 | return -1; | |
5406 | } | |
e6304cad | 5407 | wpa_s->confanother = os_rel2abs_path(iface->confanother); |
3bd35b68 JM |
5408 | if (wpa_s->confanother && |
5409 | !wpa_config_read(wpa_s->confanother, wpa_s->conf)) { | |
5410 | wpa_printf(MSG_ERROR, | |
5411 | "Failed to read or parse configuration '%s'.", | |
5412 | wpa_s->confanother); | |
5413 | return -1; | |
5414 | } | |
6fc6879b JM |
5415 | |
5416 | /* | |
5417 | * Override ctrl_interface and driver_param if set on command | |
5418 | * line. | |
5419 | */ | |
5420 | if (iface->ctrl_interface) { | |
5421 | os_free(wpa_s->conf->ctrl_interface); | |
5422 | wpa_s->conf->ctrl_interface = | |
5423 | os_strdup(iface->ctrl_interface); | |
5424 | } | |
5425 | ||
5426 | if (iface->driver_param) { | |
5427 | os_free(wpa_s->conf->driver_param); | |
5428 | wpa_s->conf->driver_param = | |
5429 | os_strdup(iface->driver_param); | |
5430 | } | |
78f79fe5 JM |
5431 | |
5432 | if (iface->p2p_mgmt && !iface->ctrl_interface) { | |
5433 | os_free(wpa_s->conf->ctrl_interface); | |
5434 | wpa_s->conf->ctrl_interface = NULL; | |
5435 | } | |
6fc6879b JM |
5436 | } else |
5437 | wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface, | |
5438 | iface->driver_param); | |
5439 | ||
5440 | if (wpa_s->conf == NULL) { | |
5441 | wpa_printf(MSG_ERROR, "\nNo configuration found."); | |
5442 | return -1; | |
5443 | } | |
5444 | ||
5445 | if (iface->ifname == NULL) { | |
5446 | wpa_printf(MSG_ERROR, "\nInterface name is required."); | |
5447 | return -1; | |
5448 | } | |
5449 | if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) { | |
5450 | wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.", | |
5451 | iface->ifname); | |
5452 | return -1; | |
5453 | } | |
5454 | os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname)); | |
5455 | ||
5456 | if (iface->bridge_ifname) { | |
5457 | if (os_strlen(iface->bridge_ifname) >= | |
5458 | sizeof(wpa_s->bridge_ifname)) { | |
5459 | wpa_printf(MSG_ERROR, "\nToo long bridge interface " | |
5460 | "name '%s'.", iface->bridge_ifname); | |
5461 | return -1; | |
5462 | } | |
5463 | os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname, | |
5464 | sizeof(wpa_s->bridge_ifname)); | |
5465 | } | |
5466 | ||
6fc6879b JM |
5467 | /* RSNA Supplicant Key Management - INITIALIZE */ |
5468 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
5469 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
5470 | ||
5471 | /* Initialize driver interface and register driver event handler before | |
5472 | * L2 receive handler so that association events are processed before | |
5473 | * EAPOL-Key packets if both become available for the same select() | |
5474 | * call. */ | |
73c00fd7 | 5475 | if (wpas_init_driver(wpa_s, iface) < 0) |
362f781e JM |
5476 | return -1; |
5477 | ||
6fc6879b JM |
5478 | if (wpa_supplicant_init_wpa(wpa_s) < 0) |
5479 | return -1; | |
5480 | ||
5481 | wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname, | |
5482 | wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname : | |
5483 | NULL); | |
5484 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); | |
5485 | ||
5486 | if (wpa_s->conf->dot11RSNAConfigPMKLifetime && | |
5487 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, | |
5488 | wpa_s->conf->dot11RSNAConfigPMKLifetime)) { | |
f049052b BG |
5489 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
5490 | "dot11RSNAConfigPMKLifetime"); | |
6fc6879b JM |
5491 | return -1; |
5492 | } | |
5493 | ||
5494 | if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold && | |
5495 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, | |
5496 | wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) { | |
f049052b | 5497 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
6fc6879b JM |
5498 | "dot11RSNAConfigPMKReauthThreshold"); |
5499 | return -1; | |
5500 | } | |
5501 | ||
5502 | if (wpa_s->conf->dot11RSNAConfigSATimeout && | |
5503 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, | |
5504 | wpa_s->conf->dot11RSNAConfigSATimeout)) { | |
f049052b BG |
5505 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
5506 | "dot11RSNAConfigSATimeout"); | |
6fc6879b JM |
5507 | return -1; |
5508 | } | |
5509 | ||
6bf731e8 CL |
5510 | wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s, |
5511 | &wpa_s->hw.num_modes, | |
aa56e36d VT |
5512 | &wpa_s->hw.flags, |
5513 | &dfs_domain); | |
a1b790eb JM |
5514 | if (wpa_s->hw.modes) { |
5515 | u16 i; | |
5516 | ||
5517 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
5518 | if (wpa_s->hw.modes[i].vht_capab) { | |
5519 | wpa_s->hw_capab = CAPAB_VHT; | |
5520 | break; | |
5521 | } | |
5522 | ||
5523 | if (wpa_s->hw.modes[i].ht_capab & | |
5524 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) | |
5525 | wpa_s->hw_capab = CAPAB_HT40; | |
5526 | else if (wpa_s->hw.modes[i].ht_capab && | |
5527 | wpa_s->hw_capab == CAPAB_NO_HT_VHT) | |
5528 | wpa_s->hw_capab = CAPAB_HT; | |
5529 | } | |
5530 | } | |
6bf731e8 | 5531 | |
6cbdb0c5 JM |
5532 | capa_res = wpa_drv_get_capa(wpa_s, &capa); |
5533 | if (capa_res == 0) { | |
c58ab8f2 | 5534 | wpa_s->drv_capa_known = 1; |
814782b9 | 5535 | wpa_s->drv_flags = capa.flags; |
349493bd | 5536 | wpa_s->drv_enc = capa.enc; |
04ee647d | 5537 | wpa_s->drv_smps_modes = capa.smps_modes; |
f936b73c | 5538 | wpa_s->drv_rrm_flags = capa.rrm_flags; |
4f73d88a | 5539 | wpa_s->probe_resp_offloads = capa.probe_resp_offloads; |
814782b9 | 5540 | wpa_s->max_scan_ssids = capa.max_scan_ssids; |
cbdf3507 | 5541 | wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids; |
32c02261 AS |
5542 | wpa_s->max_sched_scan_plans = capa.max_sched_scan_plans; |
5543 | wpa_s->max_sched_scan_plan_interval = | |
5544 | capa.max_sched_scan_plan_interval; | |
5545 | wpa_s->max_sched_scan_plan_iterations = | |
5546 | capa.max_sched_scan_plan_iterations; | |
cbdf3507 | 5547 | wpa_s->sched_scan_supported = capa.sched_scan_supported; |
b59e6f26 | 5548 | wpa_s->max_match_sets = capa.max_match_sets; |
814782b9 | 5549 | wpa_s->max_remain_on_chan = capa.max_remain_on_chan; |
c4ea4c5c | 5550 | wpa_s->max_stations = capa.max_stations; |
8cd6b7bc JB |
5551 | wpa_s->extended_capa = capa.extended_capa; |
5552 | wpa_s->extended_capa_mask = capa.extended_capa_mask; | |
5553 | wpa_s->extended_capa_len = capa.extended_capa_len; | |
4752147d IP |
5554 | wpa_s->num_multichan_concurrent = |
5555 | capa.num_multichan_concurrent; | |
471cd6e1 | 5556 | wpa_s->wmm_ac_supported = capa.wmm_ac_supported; |
56c76fa5 IP |
5557 | |
5558 | if (capa.mac_addr_rand_scan_supported) | |
5559 | wpa_s->mac_addr_rand_supported |= MAC_ADDR_RAND_SCAN; | |
5560 | if (wpa_s->sched_scan_supported && | |
5561 | capa.mac_addr_rand_sched_scan_supported) | |
5562 | wpa_s->mac_addr_rand_supported |= | |
5563 | (MAC_ADDR_RAND_SCHED_SCAN | MAC_ADDR_RAND_PNO); | |
814782b9 JM |
5564 | } |
5565 | if (wpa_s->max_remain_on_chan == 0) | |
5566 | wpa_s->max_remain_on_chan = 1000; | |
5567 | ||
c68f6200 AS |
5568 | /* |
5569 | * Only take p2p_mgmt parameters when P2P Device is supported. | |
5570 | * Doing it here as it determines whether l2_packet_init() will be done | |
5571 | * during wpa_supplicant_driver_init(). | |
5572 | */ | |
5573 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) | |
5574 | wpa_s->p2p_mgmt = iface->p2p_mgmt; | |
c68f6200 | 5575 | |
4752147d IP |
5576 | if (wpa_s->num_multichan_concurrent == 0) |
5577 | wpa_s->num_multichan_concurrent = 1; | |
5578 | ||
6fc6879b JM |
5579 | if (wpa_supplicant_driver_init(wpa_s) < 0) |
5580 | return -1; | |
5581 | ||
281ff0aa | 5582 | #ifdef CONFIG_TDLS |
8fb2b357 | 5583 | if (!iface->p2p_mgmt && wpa_tdls_init(wpa_s->wpa)) |
281ff0aa GP |
5584 | return -1; |
5585 | #endif /* CONFIG_TDLS */ | |
5586 | ||
315ce40a JM |
5587 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1] && |
5588 | wpa_drv_set_country(wpa_s, wpa_s->conf->country)) { | |
f049052b | 5589 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country"); |
6d158490 LR |
5590 | return -1; |
5591 | } | |
5592 | ||
b36a3a65 AN |
5593 | #ifdef CONFIG_FST |
5594 | if (wpa_s->conf->fst_group_id) { | |
5595 | struct fst_iface_cfg cfg; | |
5596 | struct fst_wpa_obj iface_obj; | |
5597 | ||
5598 | fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj); | |
5599 | os_strlcpy(cfg.group_id, wpa_s->conf->fst_group_id, | |
5600 | sizeof(cfg.group_id)); | |
5601 | cfg.priority = wpa_s->conf->fst_priority; | |
5602 | cfg.llt = wpa_s->conf->fst_llt; | |
5603 | ||
5604 | wpa_s->fst = fst_attach(wpa_s->ifname, wpa_s->own_addr, | |
5605 | &iface_obj, &cfg); | |
5606 | if (!wpa_s->fst) { | |
5607 | wpa_msg(wpa_s, MSG_ERROR, | |
5608 | "FST: Cannot attach iface %s to group %s", | |
5609 | wpa_s->ifname, cfg.group_id); | |
5610 | return -1; | |
5611 | } | |
5612 | } | |
5613 | #endif /* CONFIG_FST */ | |
5614 | ||
116654ce JM |
5615 | if (wpas_wps_init(wpa_s)) |
5616 | return -1; | |
5617 | ||
461d39af JM |
5618 | #ifdef CONFIG_GAS_SERVER |
5619 | wpa_s->gas_server = gas_server_init(wpa_s, wpas_gas_server_tx); | |
5620 | if (!wpa_s->gas_server) { | |
5621 | wpa_printf(MSG_ERROR, "Failed to initialize GAS server"); | |
5622 | return -1; | |
5623 | } | |
5624 | #endif /* CONFIG_GAS_SERVER */ | |
5625 | ||
be27e185 JM |
5626 | #ifdef CONFIG_DPP |
5627 | if (wpas_dpp_init(wpa_s) < 0) | |
5628 | return -1; | |
5629 | #endif /* CONFIG_DPP */ | |
5630 | ||
6fc6879b JM |
5631 | if (wpa_supplicant_init_eapol(wpa_s) < 0) |
5632 | return -1; | |
5633 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); | |
5634 | ||
5635 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); | |
5636 | if (wpa_s->ctrl_iface == NULL) { | |
5637 | wpa_printf(MSG_ERROR, | |
5638 | "Failed to initialize control interface '%s'.\n" | |
5639 | "You may have another wpa_supplicant process " | |
5640 | "already running or the file was\n" | |
5641 | "left by an unclean termination of wpa_supplicant " | |
5642 | "in which case you will need\n" | |
5643 | "to manually remove this file before starting " | |
5644 | "wpa_supplicant again.\n", | |
5645 | wpa_s->conf->ctrl_interface); | |
5646 | return -1; | |
5647 | } | |
5648 | ||
04ea7b79 JM |
5649 | wpa_s->gas = gas_query_init(wpa_s); |
5650 | if (wpa_s->gas == NULL) { | |
5651 | wpa_printf(MSG_ERROR, "Failed to initialize GAS query"); | |
5652 | return -1; | |
5653 | } | |
5654 | ||
8fb2b357 VV |
5655 | if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) || |
5656 | wpa_s->p2p_mgmt) && | |
5657 | wpas_p2p_init(wpa_s->global, wpa_s) < 0) { | |
f049052b | 5658 | wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P"); |
b22128ef JM |
5659 | return -1; |
5660 | } | |
b22128ef | 5661 | |
83922c2d JM |
5662 | if (wpa_bss_init(wpa_s) < 0) |
5663 | return -1; | |
83922c2d | 5664 | |
4d77d80e MH |
5665 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
5666 | #ifdef CONFIG_MESH | |
5667 | dl_list_init(&wpa_s->mesh_external_pmksa_cache); | |
5668 | #endif /* CONFIG_MESH */ | |
5669 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ | |
5670 | ||
e4fa8b12 EP |
5671 | /* |
5672 | * Set Wake-on-WLAN triggers, if configured. | |
5673 | * Note: We don't restore/remove the triggers on shutdown (it doesn't | |
5674 | * have effect anyway when the interface is down). | |
5675 | */ | |
6cbdb0c5 | 5676 | if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0) |
e4fa8b12 EP |
5677 | return -1; |
5678 | ||
ec7b97ab JM |
5679 | #ifdef CONFIG_EAP_PROXY |
5680 | { | |
5681 | size_t len; | |
b5db6e5d VK |
5682 | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1, |
5683 | wpa_s->imsi, &len); | |
ec7b97ab JM |
5684 | if (wpa_s->mnc_len > 0) { |
5685 | wpa_s->imsi[len] = '\0'; | |
5686 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)", | |
5687 | wpa_s->imsi, wpa_s->mnc_len); | |
5688 | } else { | |
5689 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available"); | |
5690 | } | |
5691 | } | |
5692 | #endif /* CONFIG_EAP_PROXY */ | |
5693 | ||
f64adcd7 JM |
5694 | if (pcsc_reader_init(wpa_s) < 0) |
5695 | return -1; | |
5696 | ||
306ae225 JM |
5697 | if (wpas_init_ext_pw(wpa_s) < 0) |
5698 | return -1; | |
5699 | ||
b361d580 AK |
5700 | wpas_rrm_reset(wpa_s); |
5701 | ||
32c02261 AS |
5702 | wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans); |
5703 | ||
ca9968a0 JM |
5704 | #ifdef CONFIG_HS20 |
5705 | hs20_init(wpa_s); | |
5706 | #endif /* CONFIG_HS20 */ | |
92c6e2e3 | 5707 | #ifdef CONFIG_MBO |
332aadb8 AP |
5708 | if (wpa_s->conf->oce) { |
5709 | if ((wpa_s->conf->oce & OCE_STA) && | |
5710 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA)) | |
5711 | wpa_s->enable_oce = OCE_STA; | |
5712 | if ((wpa_s->conf->oce & OCE_STA_CFON) && | |
5713 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA_CFON)) { | |
5714 | /* TODO: Need to add STA-CFON support */ | |
5715 | wpa_printf(MSG_ERROR, | |
5716 | "OCE STA-CFON feature is not yet supported"); | |
5717 | } | |
5718 | } | |
92c6e2e3 DS |
5719 | wpas_mbo_update_non_pref_chan(wpa_s, wpa_s->conf->non_pref_chan); |
5720 | #endif /* CONFIG_MBO */ | |
ca9968a0 | 5721 | |
cc9985d1 | 5722 | wpa_supplicant_set_default_scan_ies(wpa_s); |
5723 | ||
6fc6879b JM |
5724 | return 0; |
5725 | } | |
5726 | ||
5727 | ||
2ee055b3 | 5728 | static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s, |
df509539 | 5729 | int notify, int terminate) |
6fc6879b | 5730 | { |
26fc96e8 JM |
5731 | struct wpa_global *global = wpa_s->global; |
5732 | struct wpa_supplicant *iface, *prev; | |
5733 | ||
5734 | if (wpa_s == wpa_s->parent) | |
5735 | wpas_p2p_group_remove(wpa_s, "*"); | |
5736 | ||
5737 | iface = global->ifaces; | |
5738 | while (iface) { | |
96a26ab7 LD |
5739 | if (iface->p2pdev == wpa_s) |
5740 | iface->p2pdev = iface->parent; | |
26fc96e8 JM |
5741 | if (iface == wpa_s || iface->parent != wpa_s) { |
5742 | iface = iface->next; | |
5743 | continue; | |
5744 | } | |
5745 | wpa_printf(MSG_DEBUG, | |
5746 | "Remove remaining child interface %s from parent %s", | |
5747 | iface->ifname, wpa_s->ifname); | |
5748 | prev = iface; | |
5749 | iface = iface->next; | |
5750 | wpa_supplicant_remove_iface(global, prev, terminate); | |
5751 | } | |
5752 | ||
e679f140 | 5753 | wpa_s->disconnected = 1; |
6fc6879b JM |
5754 | if (wpa_s->drv_priv) { |
5755 | wpa_supplicant_deauthenticate(wpa_s, | |
5756 | WLAN_REASON_DEAUTH_LEAVING); | |
5757 | ||
6fc6879b JM |
5758 | wpa_drv_set_countermeasures(wpa_s, 0); |
5759 | wpa_clear_keys(wpa_s, NULL); | |
5760 | } | |
5761 | ||
8e56d189 | 5762 | wpa_supplicant_cleanup(wpa_s); |
bd10d938 | 5763 | wpas_p2p_deinit_iface(wpa_s); |
ab28911d | 5764 | |
1f965e62 | 5765 | wpas_ctrl_radio_work_flush(wpa_s); |
202dec2a JM |
5766 | radio_remove_interface(wpa_s); |
5767 | ||
b36a3a65 AN |
5768 | #ifdef CONFIG_FST |
5769 | if (wpa_s->fst) { | |
5770 | fst_detach(wpa_s->fst); | |
5771 | wpa_s->fst = NULL; | |
5772 | } | |
5773 | if (wpa_s->received_mb_ies) { | |
5774 | wpabuf_free(wpa_s->received_mb_ies); | |
5775 | wpa_s->received_mb_ies = NULL; | |
5776 | } | |
5777 | #endif /* CONFIG_FST */ | |
5778 | ||
6fc6879b JM |
5779 | if (wpa_s->drv_priv) |
5780 | wpa_drv_deinit(wpa_s); | |
2523ff6e DS |
5781 | |
5782 | if (notify) | |
5783 | wpas_notify_iface_removed(wpa_s); | |
f0811516 DS |
5784 | |
5785 | if (terminate) | |
5786 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING); | |
5787 | ||
5788 | if (wpa_s->ctrl_iface) { | |
5789 | wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface); | |
5790 | wpa_s->ctrl_iface = NULL; | |
5791 | } | |
5792 | ||
603a3f34 JL |
5793 | #ifdef CONFIG_MESH |
5794 | if (wpa_s->ifmsh) { | |
5795 | wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh); | |
5796 | wpa_s->ifmsh = NULL; | |
5797 | } | |
5798 | #endif /* CONFIG_MESH */ | |
5799 | ||
f0811516 DS |
5800 | if (wpa_s->conf != NULL) { |
5801 | wpa_config_free(wpa_s->conf); | |
5802 | wpa_s->conf = NULL; | |
5803 | } | |
18e00b5e | 5804 | |
a80651d0 KV |
5805 | os_free(wpa_s->ssids_from_scan_req); |
5806 | ||
18e00b5e | 5807 | os_free(wpa_s); |
6fc6879b JM |
5808 | } |
5809 | ||
5810 | ||
2e997eec RM |
5811 | #ifdef CONFIG_MATCH_IFACE |
5812 | ||
5813 | /** | |
5814 | * wpa_supplicant_match_iface - Match an interface description to a name | |
5815 | * @global: Pointer to global data from wpa_supplicant_init() | |
5816 | * @ifname: Name of the interface to match | |
5817 | * Returns: Pointer to the created interface description or %NULL on failure | |
5818 | */ | |
5819 | struct wpa_interface * wpa_supplicant_match_iface(struct wpa_global *global, | |
5820 | const char *ifname) | |
5821 | { | |
5822 | int i; | |
5823 | struct wpa_interface *iface, *miface; | |
5824 | ||
5825 | for (i = 0; i < global->params.match_iface_count; i++) { | |
5826 | miface = &global->params.match_ifaces[i]; | |
5827 | if (!miface->ifname || | |
5828 | fnmatch(miface->ifname, ifname, 0) == 0) { | |
5829 | iface = os_zalloc(sizeof(*iface)); | |
5830 | if (!iface) | |
5831 | return NULL; | |
5832 | *iface = *miface; | |
5833 | iface->ifname = ifname; | |
5834 | return iface; | |
5835 | } | |
5836 | } | |
5837 | ||
5838 | return NULL; | |
5839 | } | |
5840 | ||
5841 | ||
5842 | /** | |
5843 | * wpa_supplicant_match_existing - Match existing interfaces | |
5844 | * @global: Pointer to global data from wpa_supplicant_init() | |
5845 | * Returns: 0 on success, -1 on failure | |
5846 | */ | |
5847 | static int wpa_supplicant_match_existing(struct wpa_global *global) | |
5848 | { | |
5849 | struct if_nameindex *ifi, *ifp; | |
5850 | struct wpa_supplicant *wpa_s; | |
5851 | struct wpa_interface *iface; | |
5852 | ||
5853 | ifp = if_nameindex(); | |
5854 | if (!ifp) { | |
5855 | wpa_printf(MSG_ERROR, "if_nameindex: %s", strerror(errno)); | |
5856 | return -1; | |
5857 | } | |
5858 | ||
5859 | for (ifi = ifp; ifi->if_name; ifi++) { | |
5860 | wpa_s = wpa_supplicant_get_iface(global, ifi->if_name); | |
5861 | if (wpa_s) | |
5862 | continue; | |
5863 | iface = wpa_supplicant_match_iface(global, ifi->if_name); | |
5864 | if (iface) { | |
5865 | wpa_s = wpa_supplicant_add_iface(global, iface, NULL); | |
5866 | os_free(iface); | |
5867 | if (wpa_s) | |
5868 | wpa_s->matched = 1; | |
5869 | } | |
5870 | } | |
5871 | ||
5872 | if_freenameindex(ifp); | |
5873 | return 0; | |
5874 | } | |
5875 | ||
5876 | #endif /* CONFIG_MATCH_IFACE */ | |
5877 | ||
5878 | ||
6fc6879b JM |
5879 | /** |
5880 | * wpa_supplicant_add_iface - Add a new network interface | |
5881 | * @global: Pointer to global data from wpa_supplicant_init() | |
5882 | * @iface: Interface configuration options | |
1772d348 | 5883 | * @parent: Parent interface or %NULL to assign new interface as parent |
6fc6879b JM |
5884 | * Returns: Pointer to the created interface or %NULL on failure |
5885 | * | |
5886 | * This function is used to add new network interfaces for %wpa_supplicant. | |
5887 | * This can be called before wpa_supplicant_run() to add interfaces before the | |
5888 | * main event loop has been started. In addition, new interfaces can be added | |
5889 | * dynamically while %wpa_supplicant is already running. This could happen, | |
5890 | * e.g., when a hotplug network adapter is inserted. | |
5891 | */ | |
5892 | struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global, | |
1772d348 JM |
5893 | struct wpa_interface *iface, |
5894 | struct wpa_supplicant *parent) | |
6fc6879b JM |
5895 | { |
5896 | struct wpa_supplicant *wpa_s; | |
d27df100 | 5897 | struct wpa_interface t_iface; |
8e56d189 | 5898 | struct wpa_ssid *ssid; |
6fc6879b JM |
5899 | |
5900 | if (global == NULL || iface == NULL) | |
5901 | return NULL; | |
5902 | ||
1772d348 | 5903 | wpa_s = wpa_supplicant_alloc(parent); |
6fc6879b JM |
5904 | if (wpa_s == NULL) |
5905 | return NULL; | |
5906 | ||
d8222ae3 JM |
5907 | wpa_s->global = global; |
5908 | ||
d27df100 JM |
5909 | t_iface = *iface; |
5910 | if (global->params.override_driver) { | |
5911 | wpa_printf(MSG_DEBUG, "Override interface parameter: driver " | |
5912 | "('%s' -> '%s')", | |
5913 | iface->driver, global->params.override_driver); | |
5914 | t_iface.driver = global->params.override_driver; | |
5915 | } | |
5916 | if (global->params.override_ctrl_interface) { | |
5917 | wpa_printf(MSG_DEBUG, "Override interface parameter: " | |
5918 | "ctrl_interface ('%s' -> '%s')", | |
5919 | iface->ctrl_interface, | |
5920 | global->params.override_ctrl_interface); | |
5921 | t_iface.ctrl_interface = | |
5922 | global->params.override_ctrl_interface; | |
5923 | } | |
5924 | if (wpa_supplicant_init_iface(wpa_s, &t_iface)) { | |
6fc6879b JM |
5925 | wpa_printf(MSG_DEBUG, "Failed to add interface %s", |
5926 | iface->ifname); | |
df509539 | 5927 | wpa_supplicant_deinit_iface(wpa_s, 0, 0); |
6fc6879b JM |
5928 | return NULL; |
5929 | } | |
5930 | ||
21efc940 TB |
5931 | if (iface->p2p_mgmt == 0) { |
5932 | /* Notify the control interfaces about new iface */ | |
5933 | if (wpas_notify_iface_added(wpa_s)) { | |
5934 | wpa_supplicant_deinit_iface(wpa_s, 1, 0); | |
5935 | return NULL; | |
5936 | } | |
1bd3f426 | 5937 | |
21efc940 TB |
5938 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
5939 | wpas_notify_network_added(wpa_s, ssid); | |
5940 | } | |
8e56d189 | 5941 | |
6fc6879b JM |
5942 | wpa_s->next = global->ifaces; |
5943 | global->ifaces = wpa_s; | |
5944 | ||
f049052b | 5945 | wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname); |
99218999 | 5946 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
6fc6879b | 5947 | |
c3c4b3ed JM |
5948 | #ifdef CONFIG_P2P |
5949 | if (wpa_s->global->p2p == NULL && | |
74802c09 | 5950 | !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled && |
c3c4b3ed | 5951 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
f43c1ae7 IP |
5952 | wpas_p2p_add_p2pdev_interface( |
5953 | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { | |
c3c4b3ed JM |
5954 | wpa_printf(MSG_INFO, |
5955 | "P2P: Failed to enable P2P Device interface"); | |
5956 | /* Try to continue without. P2P will be disabled. */ | |
5957 | } | |
5958 | #endif /* CONFIG_P2P */ | |
5959 | ||
6fc6879b JM |
5960 | return wpa_s; |
5961 | } | |
5962 | ||
5963 | ||
5964 | /** | |
5965 | * wpa_supplicant_remove_iface - Remove a network interface | |
5966 | * @global: Pointer to global data from wpa_supplicant_init() | |
5967 | * @wpa_s: Pointer to the network interface to be removed | |
5968 | * Returns: 0 if interface was removed, -1 if interface was not found | |
5969 | * | |
5970 | * This function can be used to dynamically remove network interfaces from | |
5971 | * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In | |
5972 | * addition, this function is used to remove all remaining interfaces when | |
5973 | * %wpa_supplicant is terminated. | |
5974 | */ | |
5975 | int wpa_supplicant_remove_iface(struct wpa_global *global, | |
df509539 DS |
5976 | struct wpa_supplicant *wpa_s, |
5977 | int terminate) | |
6fc6879b JM |
5978 | { |
5979 | struct wpa_supplicant *prev; | |
5b78493f MH |
5980 | #ifdef CONFIG_MESH |
5981 | unsigned int mesh_if_created = wpa_s->mesh_if_created; | |
5982 | char *ifname = NULL; | |
9b170991 | 5983 | struct wpa_supplicant *parent = wpa_s->parent; |
5b78493f | 5984 | #endif /* CONFIG_MESH */ |
6fc6879b JM |
5985 | |
5986 | /* Remove interface from the global list of interfaces */ | |
5987 | prev = global->ifaces; | |
5988 | if (prev == wpa_s) { | |
5989 | global->ifaces = wpa_s->next; | |
5990 | } else { | |
5991 | while (prev && prev->next != wpa_s) | |
5992 | prev = prev->next; | |
5993 | if (prev == NULL) | |
5994 | return -1; | |
5995 | prev->next = wpa_s->next; | |
5996 | } | |
5997 | ||
f049052b | 5998 | wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname); |
6fc6879b | 5999 | |
5b78493f MH |
6000 | #ifdef CONFIG_MESH |
6001 | if (mesh_if_created) { | |
6002 | ifname = os_strdup(wpa_s->ifname); | |
6003 | if (ifname == NULL) { | |
6004 | wpa_dbg(wpa_s, MSG_ERROR, | |
6005 | "mesh: Failed to malloc ifname"); | |
6006 | return -1; | |
6007 | } | |
6008 | } | |
6009 | #endif /* CONFIG_MESH */ | |
6010 | ||
b22128ef JM |
6011 | if (global->p2p_group_formation == wpa_s) |
6012 | global->p2p_group_formation = NULL; | |
dbca75f8 JM |
6013 | if (global->p2p_invite_group == wpa_s) |
6014 | global->p2p_invite_group = NULL; | |
df509539 | 6015 | wpa_supplicant_deinit_iface(wpa_s, 1, terminate); |
6fc6879b | 6016 | |
5b78493f MH |
6017 | #ifdef CONFIG_MESH |
6018 | if (mesh_if_created) { | |
9b170991 | 6019 | wpa_drv_if_remove(parent, WPA_IF_MESH, ifname); |
5b78493f MH |
6020 | os_free(ifname); |
6021 | } | |
6022 | #endif /* CONFIG_MESH */ | |
6023 | ||
6fc6879b JM |
6024 | return 0; |
6025 | } | |
6026 | ||
6027 | ||
cf83fb0b PS |
6028 | /** |
6029 | * wpa_supplicant_get_eap_mode - Get the current EAP mode | |
6030 | * @wpa_s: Pointer to the network interface | |
6031 | * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found | |
6032 | */ | |
6033 | const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s) | |
6034 | { | |
6035 | const char *eapol_method; | |
6036 | ||
6037 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 && | |
6038 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
6039 | return "NO-EAP"; | |
6040 | } | |
6041 | ||
6042 | eapol_method = eapol_sm_get_method_name(wpa_s->eapol); | |
6043 | if (eapol_method == NULL) | |
6044 | return "UNKNOWN-EAP"; | |
6045 | ||
6046 | return eapol_method; | |
6047 | } | |
6048 | ||
6049 | ||
6fc6879b JM |
6050 | /** |
6051 | * wpa_supplicant_get_iface - Get a new network interface | |
6052 | * @global: Pointer to global data from wpa_supplicant_init() | |
6053 | * @ifname: Interface name | |
6054 | * Returns: Pointer to the interface or %NULL if not found | |
6055 | */ | |
6056 | struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global, | |
6057 | const char *ifname) | |
6058 | { | |
6059 | struct wpa_supplicant *wpa_s; | |
6060 | ||
6061 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | |
6062 | if (os_strcmp(wpa_s->ifname, ifname) == 0) | |
6063 | return wpa_s; | |
6064 | } | |
6065 | return NULL; | |
6066 | } | |
6067 | ||
6068 | ||
50b16da1 | 6069 | #ifndef CONFIG_NO_WPA_MSG |
4f1495ae BG |
6070 | static const char * wpa_supplicant_msg_ifname_cb(void *ctx) |
6071 | { | |
6072 | struct wpa_supplicant *wpa_s = ctx; | |
6073 | if (wpa_s == NULL) | |
6074 | return NULL; | |
6075 | return wpa_s->ifname; | |
6076 | } | |
50b16da1 | 6077 | #endif /* CONFIG_NO_WPA_MSG */ |
4f1495ae BG |
6078 | |
6079 | ||
8c0d0ff2 JM |
6080 | #ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL |
6081 | #define WPA_SUPPLICANT_CLEANUP_INTERVAL 10 | |
6082 | #endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */ | |
6083 | ||
6084 | /* Periodic cleanup tasks */ | |
6085 | static void wpas_periodic(void *eloop_ctx, void *timeout_ctx) | |
6086 | { | |
6087 | struct wpa_global *global = eloop_ctx; | |
6088 | struct wpa_supplicant *wpa_s; | |
6089 | ||
6090 | eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, | |
6091 | wpas_periodic, global, NULL); | |
6092 | ||
6093 | #ifdef CONFIG_P2P | |
6094 | if (global->p2p) | |
6095 | p2p_expire_peers(global->p2p); | |
6096 | #endif /* CONFIG_P2P */ | |
6097 | ||
3188aaba | 6098 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
8c0d0ff2 | 6099 | wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age); |
3188aaba JM |
6100 | #ifdef CONFIG_AP |
6101 | ap_periodic(wpa_s); | |
6102 | #endif /* CONFIG_AP */ | |
6103 | } | |
8c0d0ff2 JM |
6104 | } |
6105 | ||
6106 | ||
6fc6879b JM |
6107 | /** |
6108 | * wpa_supplicant_init - Initialize %wpa_supplicant | |
6109 | * @params: Parameters for %wpa_supplicant | |
6110 | * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure | |
6111 | * | |
6112 | * This function is used to initialize %wpa_supplicant. After successful | |
6113 | * initialization, the returned data pointer can be used to add and remove | |
6114 | * network interfaces, and eventually, to deinitialize %wpa_supplicant. | |
6115 | */ | |
6116 | struct wpa_global * wpa_supplicant_init(struct wpa_params *params) | |
6117 | { | |
6118 | struct wpa_global *global; | |
ac305589 | 6119 | int ret, i; |
6fc6879b JM |
6120 | |
6121 | if (params == NULL) | |
6122 | return NULL; | |
6123 | ||
39e7d718 JM |
6124 | #ifdef CONFIG_DRIVER_NDIS |
6125 | { | |
6126 | void driver_ndis_init_ops(void); | |
6127 | driver_ndis_init_ops(); | |
6128 | } | |
6129 | #endif /* CONFIG_DRIVER_NDIS */ | |
6130 | ||
50b16da1 | 6131 | #ifndef CONFIG_NO_WPA_MSG |
4f1495ae | 6132 | wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb); |
50b16da1 | 6133 | #endif /* CONFIG_NO_WPA_MSG */ |
4f1495ae | 6134 | |
f4637fe0 JM |
6135 | if (params->wpa_debug_file_path) |
6136 | wpa_debug_open_file(params->wpa_debug_file_path); | |
6137 | else | |
6138 | wpa_debug_setup_stdout(); | |
daa70d49 SL |
6139 | if (params->wpa_debug_syslog) |
6140 | wpa_debug_open_syslog(); | |
4f68895e JB |
6141 | if (params->wpa_debug_tracing) { |
6142 | ret = wpa_debug_open_linux_tracing(); | |
6143 | if (ret) { | |
6144 | wpa_printf(MSG_ERROR, | |
6145 | "Failed to enable trace logging"); | |
6146 | return NULL; | |
6147 | } | |
6148 | } | |
6fc6879b | 6149 | |
12760815 | 6150 | ret = eap_register_methods(); |
6fc6879b JM |
6151 | if (ret) { |
6152 | wpa_printf(MSG_ERROR, "Failed to register EAP methods"); | |
6153 | if (ret == -2) | |
6154 | wpa_printf(MSG_ERROR, "Two or more EAP methods used " | |
6155 | "the same EAP type."); | |
6156 | return NULL; | |
6157 | } | |
6158 | ||
6159 | global = os_zalloc(sizeof(*global)); | |
6160 | if (global == NULL) | |
6161 | return NULL; | |
b22128ef JM |
6162 | dl_list_init(&global->p2p_srv_bonjour); |
6163 | dl_list_init(&global->p2p_srv_upnp); | |
6fc6879b JM |
6164 | global->params.daemonize = params->daemonize; |
6165 | global->params.wait_for_monitor = params->wait_for_monitor; | |
6166 | global->params.dbus_ctrl_interface = params->dbus_ctrl_interface; | |
6167 | if (params->pid_file) | |
6168 | global->params.pid_file = os_strdup(params->pid_file); | |
6169 | if (params->ctrl_interface) | |
6170 | global->params.ctrl_interface = | |
6171 | os_strdup(params->ctrl_interface); | |
29257565 JM |
6172 | if (params->ctrl_interface_group) |
6173 | global->params.ctrl_interface_group = | |
6174 | os_strdup(params->ctrl_interface_group); | |
d27df100 JM |
6175 | if (params->override_driver) |
6176 | global->params.override_driver = | |
6177 | os_strdup(params->override_driver); | |
6178 | if (params->override_ctrl_interface) | |
6179 | global->params.override_ctrl_interface = | |
6180 | os_strdup(params->override_ctrl_interface); | |
2e997eec RM |
6181 | #ifdef CONFIG_MATCH_IFACE |
6182 | global->params.match_iface_count = params->match_iface_count; | |
6183 | if (params->match_iface_count) { | |
6184 | global->params.match_ifaces = | |
6185 | os_calloc(params->match_iface_count, | |
6186 | sizeof(struct wpa_interface)); | |
6187 | os_memcpy(global->params.match_ifaces, | |
6188 | params->match_ifaces, | |
6189 | params->match_iface_count * | |
6190 | sizeof(struct wpa_interface)); | |
6191 | } | |
6192 | #endif /* CONFIG_MATCH_IFACE */ | |
d4e59795 G |
6193 | #ifdef CONFIG_P2P |
6194 | if (params->conf_p2p_dev) | |
6195 | global->params.conf_p2p_dev = | |
6196 | os_strdup(params->conf_p2p_dev); | |
6197 | #endif /* CONFIG_P2P */ | |
6fc6879b JM |
6198 | wpa_debug_level = global->params.wpa_debug_level = |
6199 | params->wpa_debug_level; | |
6200 | wpa_debug_show_keys = global->params.wpa_debug_show_keys = | |
6201 | params->wpa_debug_show_keys; | |
6202 | wpa_debug_timestamp = global->params.wpa_debug_timestamp = | |
6203 | params->wpa_debug_timestamp; | |
6204 | ||
f19858f5 JM |
6205 | wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR); |
6206 | ||
0456ea16 | 6207 | if (eloop_init()) { |
6fc6879b JM |
6208 | wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |
6209 | wpa_supplicant_deinit(global); | |
6210 | return NULL; | |
6211 | } | |
6212 | ||
38e24575 | 6213 | random_init(params->entropy_file); |
d47fa330 | 6214 | |
6fc6879b JM |
6215 | global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global); |
6216 | if (global->ctrl_iface == NULL) { | |
6217 | wpa_supplicant_deinit(global); | |
6218 | return NULL; | |
6219 | } | |
6220 | ||
dc461de4 WS |
6221 | if (wpas_notify_supplicant_initialized(global)) { |
6222 | wpa_supplicant_deinit(global); | |
6223 | return NULL; | |
6fc6879b JM |
6224 | } |
6225 | ||
c5121837 | 6226 | for (i = 0; wpa_drivers[i]; i++) |
ac305589 JM |
6227 | global->drv_count++; |
6228 | if (global->drv_count == 0) { | |
6229 | wpa_printf(MSG_ERROR, "No drivers enabled"); | |
6230 | wpa_supplicant_deinit(global); | |
6231 | return NULL; | |
6232 | } | |
faebdeaa | 6233 | global->drv_priv = os_calloc(global->drv_count, sizeof(void *)); |
ac305589 JM |
6234 | if (global->drv_priv == NULL) { |
6235 | wpa_supplicant_deinit(global); | |
6236 | return NULL; | |
6237 | } | |
ac305589 | 6238 | |
9675ce35 JM |
6239 | #ifdef CONFIG_WIFI_DISPLAY |
6240 | if (wifi_display_init(global) < 0) { | |
6241 | wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display"); | |
6242 | wpa_supplicant_deinit(global); | |
6243 | return NULL; | |
6244 | } | |
6245 | #endif /* CONFIG_WIFI_DISPLAY */ | |
6246 | ||
8c0d0ff2 JM |
6247 | eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0, |
6248 | wpas_periodic, global, NULL); | |
6249 | ||
6fc6879b JM |
6250 | return global; |
6251 | } | |
6252 | ||
6253 | ||
6254 | /** | |
6255 | * wpa_supplicant_run - Run the %wpa_supplicant main event loop | |
6256 | * @global: Pointer to global data from wpa_supplicant_init() | |
6257 | * Returns: 0 after successful event loop run, -1 on failure | |
6258 | * | |
6259 | * This function starts the main event loop and continues running as long as | |
6260 | * there are any remaining events. In most cases, this function is running as | |
6261 | * long as the %wpa_supplicant process in still in use. | |
6262 | */ | |
6263 | int wpa_supplicant_run(struct wpa_global *global) | |
6264 | { | |
6265 | struct wpa_supplicant *wpa_s; | |
6266 | ||
6267 | if (global->params.daemonize && | |
2e69bdd1 RM |
6268 | (wpa_supplicant_daemon(global->params.pid_file) || |
6269 | eloop_sock_requeue())) | |
6fc6879b JM |
6270 | return -1; |
6271 | ||
2e997eec RM |
6272 | #ifdef CONFIG_MATCH_IFACE |
6273 | if (wpa_supplicant_match_existing(global)) | |
6274 | return -1; | |
6275 | #endif | |
6276 | ||
6fc6879b JM |
6277 | if (global->params.wait_for_monitor) { |
6278 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) | |
ede77701 | 6279 | if (wpa_s->ctrl_iface && !wpa_s->p2p_mgmt) |
6fc6879b JM |
6280 | wpa_supplicant_ctrl_iface_wait( |
6281 | wpa_s->ctrl_iface); | |
6282 | } | |
6283 | ||
0456ea16 JM |
6284 | eloop_register_signal_terminate(wpa_supplicant_terminate, global); |
6285 | eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); | |
6fc6879b JM |
6286 | |
6287 | eloop_run(); | |
6288 | ||
6289 | return 0; | |
6290 | } | |
6291 | ||
6292 | ||
6293 | /** | |
6294 | * wpa_supplicant_deinit - Deinitialize %wpa_supplicant | |
6295 | * @global: Pointer to global data from wpa_supplicant_init() | |
6296 | * | |
6297 | * This function is called to deinitialize %wpa_supplicant and to free all | |
6298 | * allocated resources. Remaining network interfaces will also be removed. | |
6299 | */ | |
6300 | void wpa_supplicant_deinit(struct wpa_global *global) | |
6301 | { | |
ac305589 JM |
6302 | int i; |
6303 | ||
6fc6879b JM |
6304 | if (global == NULL) |
6305 | return; | |
6306 | ||
8c0d0ff2 JM |
6307 | eloop_cancel_timeout(wpas_periodic, global, NULL); |
6308 | ||
9675ce35 JM |
6309 | #ifdef CONFIG_WIFI_DISPLAY |
6310 | wifi_display_deinit(global); | |
6311 | #endif /* CONFIG_WIFI_DISPLAY */ | |
b22128ef | 6312 | |
6fc6879b | 6313 | while (global->ifaces) |
df509539 | 6314 | wpa_supplicant_remove_iface(global, global->ifaces, 1); |
6fc6879b JM |
6315 | |
6316 | if (global->ctrl_iface) | |
6317 | wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface); | |
dc461de4 WS |
6318 | |
6319 | wpas_notify_supplicant_deinitialized(global); | |
6fc6879b JM |
6320 | |
6321 | eap_peer_unregister_methods(); | |
3ec97afe JM |
6322 | #ifdef CONFIG_AP |
6323 | eap_server_unregister_methods(); | |
6324 | #endif /* CONFIG_AP */ | |
6fc6879b | 6325 | |
c5121837 | 6326 | for (i = 0; wpa_drivers[i] && global->drv_priv; i++) { |
ac305589 JM |
6327 | if (!global->drv_priv[i]) |
6328 | continue; | |
c5121837 | 6329 | wpa_drivers[i]->global_deinit(global->drv_priv[i]); |
ac305589 JM |
6330 | } |
6331 | os_free(global->drv_priv); | |
6332 | ||
d47fa330 JM |
6333 | random_deinit(); |
6334 | ||
6fc6879b JM |
6335 | eloop_destroy(); |
6336 | ||
6337 | if (global->params.pid_file) { | |
6338 | os_daemonize_terminate(global->params.pid_file); | |
6339 | os_free(global->params.pid_file); | |
6340 | } | |
6341 | os_free(global->params.ctrl_interface); | |
29257565 | 6342 | os_free(global->params.ctrl_interface_group); |
d27df100 JM |
6343 | os_free(global->params.override_driver); |
6344 | os_free(global->params.override_ctrl_interface); | |
2e997eec RM |
6345 | #ifdef CONFIG_MATCH_IFACE |
6346 | os_free(global->params.match_ifaces); | |
6347 | #endif /* CONFIG_MATCH_IFACE */ | |
d4e59795 G |
6348 | #ifdef CONFIG_P2P |
6349 | os_free(global->params.conf_p2p_dev); | |
6350 | #endif /* CONFIG_P2P */ | |
6fc6879b | 6351 | |
af8a827b | 6352 | os_free(global->p2p_disallow_freq.range); |
253f2e37 | 6353 | os_free(global->p2p_go_avoid_freq.range); |
01a57fe4 | 6354 | os_free(global->add_psk); |
6f3bc72b | 6355 | |
6fc6879b | 6356 | os_free(global); |
daa70d49 | 6357 | wpa_debug_close_syslog(); |
6fc6879b | 6358 | wpa_debug_close_file(); |
4f68895e | 6359 | wpa_debug_close_linux_tracing(); |
6fc6879b | 6360 | } |
611aea7d JM |
6361 | |
6362 | ||
6363 | void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s) | |
6364 | { | |
849b5dc7 JM |
6365 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
6366 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { | |
6367 | char country[3]; | |
6368 | country[0] = wpa_s->conf->country[0]; | |
6369 | country[1] = wpa_s->conf->country[1]; | |
6370 | country[2] = '\0'; | |
6371 | if (wpa_drv_set_country(wpa_s, country) < 0) { | |
6372 | wpa_printf(MSG_ERROR, "Failed to set country code " | |
6373 | "'%s'", country); | |
6374 | } | |
6375 | } | |
6376 | ||
306ae225 JM |
6377 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND) |
6378 | wpas_init_ext_pw(wpa_s); | |
6379 | ||
bea48f77 JM |
6380 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SCHED_SCAN_PLANS) |
6381 | wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans); | |
6382 | ||
3c7863f8 LD |
6383 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WOWLAN_TRIGGERS) { |
6384 | struct wpa_driver_capa capa; | |
6385 | int res = wpa_drv_get_capa(wpa_s, &capa); | |
6386 | ||
6387 | if (res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0) | |
6388 | wpa_printf(MSG_ERROR, | |
6389 | "Failed to update wowlan_triggers to '%s'", | |
6390 | wpa_s->conf->wowlan_triggers); | |
6391 | } | |
6392 | ||
611aea7d JM |
6393 | #ifdef CONFIG_WPS |
6394 | wpas_wps_update_config(wpa_s); | |
6395 | #endif /* CONFIG_WPS */ | |
b22128ef | 6396 | wpas_p2p_update_config(wpa_s); |
611aea7d JM |
6397 | wpa_s->conf->changed_parameters = 0; |
6398 | } | |
2f9c6aa6 JM |
6399 | |
6400 | ||
e1117c1c | 6401 | void add_freq(int *freqs, int *num_freqs, int freq) |
0fb337c1 JM |
6402 | { |
6403 | int i; | |
6404 | ||
6405 | for (i = 0; i < *num_freqs; i++) { | |
6406 | if (freqs[i] == freq) | |
6407 | return; | |
6408 | } | |
6409 | ||
6410 | freqs[*num_freqs] = freq; | |
6411 | (*num_freqs)++; | |
6412 | } | |
6413 | ||
6414 | ||
6415 | static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s) | |
6416 | { | |
6417 | struct wpa_bss *bss, *cbss; | |
6418 | const int max_freqs = 10; | |
6419 | int *freqs; | |
6420 | int num_freqs = 0; | |
6421 | ||
faebdeaa | 6422 | freqs = os_calloc(max_freqs + 1, sizeof(int)); |
0fb337c1 JM |
6423 | if (freqs == NULL) |
6424 | return NULL; | |
6425 | ||
6426 | cbss = wpa_s->current_bss; | |
6427 | ||
6428 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { | |
6429 | if (bss == cbss) | |
6430 | continue; | |
6431 | if (bss->ssid_len == cbss->ssid_len && | |
6432 | os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 && | |
6433 | wpa_blacklist_get(wpa_s, bss->bssid) == NULL) { | |
6434 | add_freq(freqs, &num_freqs, bss->freq); | |
6435 | if (num_freqs == max_freqs) | |
6436 | break; | |
6437 | } | |
6438 | } | |
6439 | ||
6440 | if (num_freqs == 0) { | |
6441 | os_free(freqs); | |
6442 | freqs = NULL; | |
6443 | } | |
6444 | ||
6445 | return freqs; | |
6446 | } | |
6447 | ||
6448 | ||
6449 | void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid) | |
6450 | { | |
6451 | int timeout; | |
6452 | int count; | |
6453 | int *freqs = NULL; | |
6454 | ||
6ac4b15e JM |
6455 | wpas_connect_work_done(wpa_s); |
6456 | ||
5fd9fb27 JM |
6457 | /* |
6458 | * Remove possible authentication timeout since the connection failed. | |
6459 | */ | |
6460 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); | |
6461 | ||
c2805909 JM |
6462 | /* |
6463 | * There is no point in blacklisting the AP if this event is | |
6464 | * generated based on local request to disconnect. | |
6465 | */ | |
6466 | if (wpa_s->own_disconnect_req) { | |
6467 | wpa_s->own_disconnect_req = 0; | |
6468 | wpa_dbg(wpa_s, MSG_DEBUG, | |
6469 | "Ignore connection failure due to local request to disconnect"); | |
6470 | return; | |
6471 | } | |
0cdb93fe | 6472 | if (wpa_s->disconnected) { |
0cdb93fe JM |
6473 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure " |
6474 | "indication since interface has been put into " | |
6475 | "disconnected state"); | |
6476 | return; | |
6477 | } | |
6478 | ||
0fb337c1 JM |
6479 | /* |
6480 | * Add the failed BSSID into the blacklist and speed up next scan | |
6481 | * attempt if there could be other APs that could accept association. | |
6482 | * The current blacklist count indicates how many times we have tried | |
6483 | * connecting to this AP and multiple attempts mean that other APs are | |
6484 | * either not available or has already been tried, so that we can start | |
6485 | * increasing the delay here to avoid constant scanning. | |
6486 | */ | |
6487 | count = wpa_blacklist_add(wpa_s, bssid); | |
6488 | if (count == 1 && wpa_s->current_bss) { | |
6489 | /* | |
6490 | * This BSS was not in the blacklist before. If there is | |
6491 | * another BSS available for the same ESS, we should try that | |
6492 | * next. Otherwise, we may as well try this one once more | |
6493 | * before allowing other, likely worse, ESSes to be considered. | |
6494 | */ | |
6495 | freqs = get_bss_freqs_in_ess(wpa_s); | |
6496 | if (freqs) { | |
f049052b BG |
6497 | wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS " |
6498 | "has been seen; try it next"); | |
0fb337c1 JM |
6499 | wpa_blacklist_add(wpa_s, bssid); |
6500 | /* | |
6501 | * On the next scan, go through only the known channels | |
6502 | * used in this ESS based on previous scans to speed up | |
6503 | * common load balancing use case. | |
6504 | */ | |
6505 | os_free(wpa_s->next_scan_freqs); | |
6506 | wpa_s->next_scan_freqs = freqs; | |
6507 | } | |
6508 | } | |
6509 | ||
f1a52633 JM |
6510 | /* |
6511 | * Add previous failure count in case the temporary blacklist was | |
6512 | * cleared due to no other BSSes being available. | |
6513 | */ | |
6514 | count += wpa_s->extra_blacklist_count; | |
6515 | ||
dd579704 JM |
6516 | if (count > 3 && wpa_s->current_ssid) { |
6517 | wpa_printf(MSG_DEBUG, "Continuous association failures - " | |
6518 | "consider temporary network disabling"); | |
b19c098e | 6519 | wpas_auth_failed(wpa_s, "CONN_FAILED"); |
dd579704 JM |
6520 | } |
6521 | ||
0fb337c1 JM |
6522 | switch (count) { |
6523 | case 1: | |
6524 | timeout = 100; | |
6525 | break; | |
6526 | case 2: | |
6527 | timeout = 500; | |
6528 | break; | |
6529 | case 3: | |
6530 | timeout = 1000; | |
6531 | break; | |
f1a52633 | 6532 | case 4: |
0fb337c1 | 6533 | timeout = 5000; |
f1a52633 JM |
6534 | break; |
6535 | default: | |
6536 | timeout = 10000; | |
6537 | break; | |
0fb337c1 JM |
6538 | } |
6539 | ||
f1a52633 JM |
6540 | wpa_dbg(wpa_s, MSG_DEBUG, "Blacklist count %d --> request scan in %d " |
6541 | "ms", count, timeout); | |
6542 | ||
0fb337c1 JM |
6543 | /* |
6544 | * TODO: if more than one possible AP is available in scan results, | |
6545 | * could try the other ones before requesting a new scan. | |
6546 | */ | |
6547 | wpa_supplicant_req_scan(wpa_s, timeout / 1000, | |
6548 | 1000 * (timeout % 1000)); | |
6549 | } | |
22628eca JM |
6550 | |
6551 | ||
af835d75 AB |
6552 | #ifdef CONFIG_FILS |
6553 | void fils_connection_failure(struct wpa_supplicant *wpa_s) | |
6554 | { | |
6555 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
6556 | const u8 *realm, *username, *rrk; | |
6557 | size_t realm_len, username_len, rrk_len; | |
6558 | u16 next_seq_num; | |
6559 | ||
6560 | if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt) || | |
6561 | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, | |
6562 | &username, &username_len, | |
6563 | &realm, &realm_len, &next_seq_num, | |
6564 | &rrk, &rrk_len) != 0 || | |
6565 | !realm) | |
6566 | return; | |
6567 | ||
6568 | wpa_hexdump_ascii(MSG_DEBUG, | |
6569 | "FILS: Store last connection failure realm", | |
6570 | realm, realm_len); | |
6571 | os_free(wpa_s->last_con_fail_realm); | |
6572 | wpa_s->last_con_fail_realm = os_malloc(realm_len); | |
6573 | if (wpa_s->last_con_fail_realm) { | |
6574 | wpa_s->last_con_fail_realm_len = realm_len; | |
6575 | os_memcpy(wpa_s->last_con_fail_realm, realm, realm_len); | |
6576 | } | |
6577 | } | |
6578 | #endif /* CONFIG_FILS */ | |
6579 | ||
6580 | ||
22628eca JM |
6581 | int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s) |
6582 | { | |
6583 | return wpa_s->conf->ap_scan == 2 || | |
6584 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION); | |
6585 | } | |
d2118814 JM |
6586 | |
6587 | ||
6588 | #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW) | |
6589 | int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s, | |
6590 | struct wpa_ssid *ssid, | |
6591 | const char *field, | |
6592 | const char *value) | |
6593 | { | |
6594 | #ifdef IEEE8021X_EAPOL | |
6595 | struct eap_peer_config *eap = &ssid->eap; | |
6596 | ||
6597 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field); | |
6598 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value", | |
6599 | (const u8 *) value, os_strlen(value)); | |
6600 | ||
6601 | switch (wpa_supplicant_ctrl_req_from_string(field)) { | |
6602 | case WPA_CTRL_REQ_EAP_IDENTITY: | |
6603 | os_free(eap->identity); | |
6604 | eap->identity = (u8 *) os_strdup(value); | |
6605 | eap->identity_len = os_strlen(value); | |
6606 | eap->pending_req_identity = 0; | |
6607 | if (ssid == wpa_s->current_ssid) | |
6608 | wpa_s->reassociate = 1; | |
6609 | break; | |
6610 | case WPA_CTRL_REQ_EAP_PASSWORD: | |
19c48da0 | 6611 | bin_clear_free(eap->password, eap->password_len); |
d2118814 JM |
6612 | eap->password = (u8 *) os_strdup(value); |
6613 | eap->password_len = os_strlen(value); | |
6614 | eap->pending_req_password = 0; | |
6615 | if (ssid == wpa_s->current_ssid) | |
6616 | wpa_s->reassociate = 1; | |
6617 | break; | |
6618 | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: | |
19c48da0 | 6619 | bin_clear_free(eap->new_password, eap->new_password_len); |
d2118814 JM |
6620 | eap->new_password = (u8 *) os_strdup(value); |
6621 | eap->new_password_len = os_strlen(value); | |
6622 | eap->pending_req_new_password = 0; | |
6623 | if (ssid == wpa_s->current_ssid) | |
6624 | wpa_s->reassociate = 1; | |
6625 | break; | |
6626 | case WPA_CTRL_REQ_EAP_PIN: | |
19c48da0 | 6627 | str_clear_free(eap->pin); |
d2118814 JM |
6628 | eap->pin = os_strdup(value); |
6629 | eap->pending_req_pin = 0; | |
6630 | if (ssid == wpa_s->current_ssid) | |
6631 | wpa_s->reassociate = 1; | |
6632 | break; | |
6633 | case WPA_CTRL_REQ_EAP_OTP: | |
19c48da0 | 6634 | bin_clear_free(eap->otp, eap->otp_len); |
d2118814 JM |
6635 | eap->otp = (u8 *) os_strdup(value); |
6636 | eap->otp_len = os_strlen(value); | |
6637 | os_free(eap->pending_req_otp); | |
6638 | eap->pending_req_otp = NULL; | |
6639 | eap->pending_req_otp_len = 0; | |
6640 | break; | |
6641 | case WPA_CTRL_REQ_EAP_PASSPHRASE: | |
19c48da0 JM |
6642 | str_clear_free(eap->private_key_passwd); |
6643 | eap->private_key_passwd = os_strdup(value); | |
d2118814 JM |
6644 | eap->pending_req_passphrase = 0; |
6645 | if (ssid == wpa_s->current_ssid) | |
6646 | wpa_s->reassociate = 1; | |
6647 | break; | |
a5d44ac0 | 6648 | case WPA_CTRL_REQ_SIM: |
19c48da0 | 6649 | str_clear_free(eap->external_sim_resp); |
a5d44ac0 | 6650 | eap->external_sim_resp = os_strdup(value); |
ed9b1c16 | 6651 | eap->pending_req_sim = 0; |
a5d44ac0 | 6652 | break; |
a52410c2 JM |
6653 | case WPA_CTRL_REQ_PSK_PASSPHRASE: |
6654 | if (wpa_config_set(ssid, "psk", value, 0) < 0) | |
6655 | return -1; | |
6656 | ssid->mem_only_psk = 1; | |
6657 | if (ssid->passphrase) | |
6658 | wpa_config_update_psk(ssid); | |
6659 | if (wpa_s->wpa_state == WPA_SCANNING && !wpa_s->scanning) | |
6660 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
6661 | break; | |
3c108b75 JM |
6662 | case WPA_CTRL_REQ_EXT_CERT_CHECK: |
6663 | if (eap->pending_ext_cert_check != PENDING_CHECK) | |
6664 | return -1; | |
6665 | if (os_strcmp(value, "good") == 0) | |
6666 | eap->pending_ext_cert_check = EXT_CERT_CHECK_GOOD; | |
6667 | else if (os_strcmp(value, "bad") == 0) | |
6668 | eap->pending_ext_cert_check = EXT_CERT_CHECK_BAD; | |
6669 | else | |
6670 | return -1; | |
6671 | break; | |
d2118814 JM |
6672 | default: |
6673 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field); | |
6674 | return -1; | |
6675 | } | |
6676 | ||
6677 | return 0; | |
6678 | #else /* IEEE8021X_EAPOL */ | |
6679 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included"); | |
6680 | return -1; | |
6681 | #endif /* IEEE8021X_EAPOL */ | |
6682 | } | |
6683 | #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */ | |
349493bd JM |
6684 | |
6685 | ||
6686 | int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) | |
6687 | { | |
6688 | int i; | |
6689 | unsigned int drv_enc; | |
6690 | ||
44b9ea5b JM |
6691 | if (wpa_s->p2p_mgmt) |
6692 | return 1; /* no normal network profiles on p2p_mgmt interface */ | |
6693 | ||
349493bd JM |
6694 | if (ssid == NULL) |
6695 | return 1; | |
6696 | ||
6697 | if (ssid->disabled) | |
6698 | return 1; | |
6699 | ||
9feadba1 | 6700 | if (wpa_s->drv_capa_known) |
349493bd JM |
6701 | drv_enc = wpa_s->drv_enc; |
6702 | else | |
6703 | drv_enc = (unsigned int) -1; | |
6704 | ||
6705 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
6706 | size_t len = ssid->wep_key_len[i]; | |
6707 | if (len == 0) | |
6708 | continue; | |
6709 | if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40)) | |
6710 | continue; | |
6711 | if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104)) | |
6712 | continue; | |
6713 | if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128)) | |
6714 | continue; | |
6715 | return 1; /* invalid WEP key */ | |
6716 | } | |
6717 | ||
9173b16f | 6718 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set && |
a52410c2 | 6719 | (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk && |
a34ca59e | 6720 | !(wpa_key_mgmt_sae(ssid->key_mgmt) && ssid->sae_password) && |
a52410c2 | 6721 | !ssid->mem_only_psk) |
2518aad3 JM |
6722 | return 1; |
6723 | ||
349493bd JM |
6724 | return 0; |
6725 | } | |
b9cfc09a JJ |
6726 | |
6727 | ||
3f56a2b7 JM |
6728 | int wpas_get_ssid_pmf(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
6729 | { | |
6730 | #ifdef CONFIG_IEEE80211W | |
6731 | if (ssid == NULL || ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) { | |
6732 | if (wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_OPTIONAL && | |
6733 | !(wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)) { | |
6734 | /* | |
6735 | * Driver does not support BIP -- ignore pmf=1 default | |
6736 | * since the connection with PMF would fail and the | |
6737 | * configuration does not require PMF to be enabled. | |
6738 | */ | |
6739 | return NO_MGMT_FRAME_PROTECTION; | |
6740 | } | |
6741 | ||
22950049 JM |
6742 | if (ssid && |
6743 | (ssid->key_mgmt & | |
6744 | ~(WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPS | | |
6745 | WPA_KEY_MGMT_IEEE8021X_NO_WPA)) == 0) { | |
6746 | /* | |
6747 | * Do not use the default PMF value for non-RSN networks | |
6748 | * since PMF is available only with RSN and pmf=2 | |
6749 | * configuration would otherwise prevent connections to | |
6750 | * all open networks. | |
6751 | */ | |
6752 | return NO_MGMT_FRAME_PROTECTION; | |
6753 | } | |
6754 | ||
3f56a2b7 JM |
6755 | return wpa_s->conf->pmf; |
6756 | } | |
6757 | ||
6758 | return ssid->ieee80211w; | |
6759 | #else /* CONFIG_IEEE80211W */ | |
6760 | return NO_MGMT_FRAME_PROTECTION; | |
6761 | #endif /* CONFIG_IEEE80211W */ | |
6762 | } | |
6763 | ||
6764 | ||
b9cfc09a JJ |
6765 | int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s) |
6766 | { | |
6767 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P) | |
6768 | return 1; | |
6769 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA) | |
6770 | return 0; | |
6771 | return -1; | |
6772 | } | |
00e5e3d5 JM |
6773 | |
6774 | ||
b19c098e | 6775 | void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason) |
00e5e3d5 JM |
6776 | { |
6777 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
6778 | int dur; | |
4e1eae1d | 6779 | struct os_reltime now; |
00e5e3d5 JM |
6780 | |
6781 | if (ssid == NULL) { | |
6782 | wpa_printf(MSG_DEBUG, "Authentication failure but no known " | |
6783 | "SSID block"); | |
6784 | return; | |
6785 | } | |
6786 | ||
6787 | if (ssid->key_mgmt == WPA_KEY_MGMT_WPS) | |
6788 | return; | |
6789 | ||
6790 | ssid->auth_failures++; | |
cbf41ca7 SL |
6791 | |
6792 | #ifdef CONFIG_P2P | |
6793 | if (ssid->p2p_group && | |
6794 | (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) { | |
6795 | /* | |
6796 | * Skip the wait time since there is a short timeout on the | |
6797 | * connection to a P2P group. | |
6798 | */ | |
6799 | return; | |
6800 | } | |
6801 | #endif /* CONFIG_P2P */ | |
6802 | ||
00e5e3d5 JM |
6803 | if (ssid->auth_failures > 50) |
6804 | dur = 300; | |
00e5e3d5 | 6805 | else if (ssid->auth_failures > 10) |
8a77f1be | 6806 | dur = 120; |
00e5e3d5 | 6807 | else if (ssid->auth_failures > 5) |
8a77f1be JM |
6808 | dur = 90; |
6809 | else if (ssid->auth_failures > 3) | |
6810 | dur = 60; | |
6811 | else if (ssid->auth_failures > 2) | |
00e5e3d5 JM |
6812 | dur = 30; |
6813 | else if (ssid->auth_failures > 1) | |
6814 | dur = 20; | |
6815 | else | |
6816 | dur = 10; | |
6817 | ||
8a77f1be JM |
6818 | if (ssid->auth_failures > 1 && |
6819 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) | |
6820 | dur += os_random() % (ssid->auth_failures * 10); | |
6821 | ||
4e1eae1d | 6822 | os_get_reltime(&now); |
00e5e3d5 JM |
6823 | if (now.sec + dur <= ssid->disabled_until.sec) |
6824 | return; | |
6825 | ||
6826 | ssid->disabled_until.sec = now.sec + dur; | |
6827 | ||
6828 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED | |
b19c098e | 6829 | "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s", |
00e5e3d5 | 6830 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len), |
b19c098e | 6831 | ssid->auth_failures, dur, reason); |
00e5e3d5 JM |
6832 | } |
6833 | ||
6834 | ||
6835 | void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s, | |
6836 | struct wpa_ssid *ssid, int clear_failures) | |
6837 | { | |
6838 | if (ssid == NULL) | |
6839 | return; | |
6840 | ||
6841 | if (ssid->disabled_until.sec) { | |
6842 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED | |
6843 | "id=%d ssid=\"%s\"", | |
6844 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | |
6845 | } | |
6846 | ssid->disabled_until.sec = 0; | |
6847 | ssid->disabled_until.usec = 0; | |
6848 | if (clear_failures) | |
6849 | ssid->auth_failures = 0; | |
6850 | } | |
6407f413 JM |
6851 | |
6852 | ||
6853 | int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid) | |
6854 | { | |
6855 | size_t i; | |
6856 | ||
6857 | if (wpa_s->disallow_aps_bssid == NULL) | |
6858 | return 0; | |
6859 | ||
6860 | for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) { | |
6861 | if (os_memcmp(wpa_s->disallow_aps_bssid + i * ETH_ALEN, | |
6862 | bssid, ETH_ALEN) == 0) | |
6863 | return 1; | |
6864 | } | |
6865 | ||
6866 | return 0; | |
6867 | } | |
6868 | ||
6869 | ||
6870 | int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid, | |
6871 | size_t ssid_len) | |
6872 | { | |
6873 | size_t i; | |
6874 | ||
6875 | if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL) | |
6876 | return 0; | |
6877 | ||
6878 | for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) { | |
6879 | struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i]; | |
6880 | if (ssid_len == s->ssid_len && | |
6881 | os_memcmp(ssid, s->ssid, ssid_len) == 0) | |
6882 | return 1; | |
6883 | } | |
6884 | ||
6885 | return 0; | |
6886 | } | |
9796a86c JM |
6887 | |
6888 | ||
6889 | /** | |
6890 | * wpas_request_connection - Request a new connection | |
6891 | * @wpa_s: Pointer to the network interface | |
6892 | * | |
6893 | * This function is used to request a new connection to be found. It will mark | |
6894 | * the interface to allow reassociation and request a new scan to find a | |
6895 | * suitable network to connect to. | |
6896 | */ | |
6897 | void wpas_request_connection(struct wpa_supplicant *wpa_s) | |
6898 | { | |
6899 | wpa_s->normal_scans = 0; | |
5214f4fa | 6900 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
9796a86c JM |
6901 | wpa_supplicant_reinit_autoscan(wpa_s); |
6902 | wpa_s->extra_blacklist_count = 0; | |
6903 | wpa_s->disconnected = 0; | |
6904 | wpa_s->reassociate = 1; | |
2cb40e9f | 6905 | wpa_s->last_owe_group = 0; |
5e24beae MH |
6906 | |
6907 | if (wpa_supplicant_fast_associate(wpa_s) != 1) | |
6908 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
0c5f01fd B |
6909 | else |
6910 | wpa_s->reattach = 0; | |
9796a86c | 6911 | } |
36b9883d DG |
6912 | |
6913 | ||
5f040be4 RP |
6914 | /** |
6915 | * wpas_request_disconnection - Request disconnection | |
6916 | * @wpa_s: Pointer to the network interface | |
6917 | * | |
6918 | * This function is used to request disconnection from the currently connected | |
6919 | * network. This will stop any ongoing scans and initiate deauthentication. | |
6920 | */ | |
6921 | void wpas_request_disconnection(struct wpa_supplicant *wpa_s) | |
6922 | { | |
6923 | #ifdef CONFIG_SME | |
6924 | wpa_s->sme.prev_bssid_set = 0; | |
6925 | #endif /* CONFIG_SME */ | |
6926 | wpa_s->reassociate = 0; | |
6927 | wpa_s->disconnected = 1; | |
6928 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
6929 | wpa_supplicant_cancel_scan(wpa_s); | |
6930 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
6931 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
6932 | } | |
6933 | ||
6934 | ||
a0c90bb0 IP |
6935 | void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title, |
6936 | struct wpa_used_freq_data *freqs_data, | |
6937 | unsigned int len) | |
6938 | { | |
6939 | unsigned int i; | |
6940 | ||
6941 | wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s", | |
6942 | len, title); | |
6943 | for (i = 0; i < len; i++) { | |
6944 | struct wpa_used_freq_data *cur = &freqs_data[i]; | |
6945 | wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X", | |
6946 | i, cur->freq, cur->flags); | |
6947 | } | |
6948 | } | |
6949 | ||
6950 | ||
53c5dfc2 IP |
6951 | /* |
6952 | * Find the operating frequencies of any of the virtual interfaces that | |
a0c90bb0 IP |
6953 | * are using the same radio as the current interface, and in addition, get |
6954 | * information about the interface types that are using the frequency. | |
53c5dfc2 | 6955 | */ |
a0c90bb0 IP |
6956 | int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s, |
6957 | struct wpa_used_freq_data *freqs_data, | |
6958 | unsigned int len) | |
53c5dfc2 | 6959 | { |
53c5dfc2 IP |
6960 | struct wpa_supplicant *ifs; |
6961 | u8 bssid[ETH_ALEN]; | |
6962 | int freq; | |
6963 | unsigned int idx = 0, i; | |
6964 | ||
217cf499 JM |
6965 | wpa_dbg(wpa_s, MSG_DEBUG, |
6966 | "Determining shared radio frequencies (max len %u)", len); | |
a0c90bb0 | 6967 | os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len); |
53c5dfc2 | 6968 | |
0ad3b9c4 JM |
6969 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
6970 | radio_list) { | |
a0c90bb0 IP |
6971 | if (idx == len) |
6972 | break; | |
6973 | ||
53c5dfc2 IP |
6974 | if (ifs->current_ssid == NULL || ifs->assoc_freq == 0) |
6975 | continue; | |
6976 | ||
6977 | if (ifs->current_ssid->mode == WPAS_MODE_AP || | |
241c3333 MH |
6978 | ifs->current_ssid->mode == WPAS_MODE_P2P_GO || |
6979 | ifs->current_ssid->mode == WPAS_MODE_MESH) | |
53c5dfc2 IP |
6980 | freq = ifs->current_ssid->frequency; |
6981 | else if (wpa_drv_get_bssid(ifs, bssid) == 0) | |
6982 | freq = ifs->assoc_freq; | |
6983 | else | |
6984 | continue; | |
6985 | ||
6986 | /* Hold only distinct freqs */ | |
6987 | for (i = 0; i < idx; i++) | |
a0c90bb0 | 6988 | if (freqs_data[i].freq == freq) |
53c5dfc2 IP |
6989 | break; |
6990 | ||
6991 | if (i == idx) | |
a0c90bb0 IP |
6992 | freqs_data[idx++].freq = freq; |
6993 | ||
6994 | if (ifs->current_ssid->mode == WPAS_MODE_INFRA) { | |
22264b3c | 6995 | freqs_data[i].flags |= ifs->current_ssid->p2p_group ? |
a0c90bb0 IP |
6996 | WPA_FREQ_USED_BY_P2P_CLIENT : |
6997 | WPA_FREQ_USED_BY_INFRA_STATION; | |
6998 | } | |
53c5dfc2 | 6999 | } |
217cf499 | 7000 | |
a0c90bb0 | 7001 | dump_freq_data(wpa_s, "completed iteration", freqs_data, idx); |
53c5dfc2 IP |
7002 | return idx; |
7003 | } | |
a0c90bb0 IP |
7004 | |
7005 | ||
7006 | /* | |
7007 | * Find the operating frequencies of any of the virtual interfaces that | |
7008 | * are using the same radio as the current interface. | |
7009 | */ | |
7010 | int get_shared_radio_freqs(struct wpa_supplicant *wpa_s, | |
7011 | int *freq_array, unsigned int len) | |
7012 | { | |
7013 | struct wpa_used_freq_data *freqs_data; | |
7014 | int num, i; | |
7015 | ||
7016 | os_memset(freq_array, 0, sizeof(int) * len); | |
7017 | ||
7018 | freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data)); | |
7019 | if (!freqs_data) | |
7020 | return -1; | |
7021 | ||
7022 | num = get_shared_radio_freqs_data(wpa_s, freqs_data, len); | |
7023 | for (i = 0; i < num; i++) | |
7024 | freq_array[i] = freqs_data[i].freq; | |
7025 | ||
7026 | os_free(freqs_data); | |
7027 | ||
7028 | return num; | |
7029 | } | |
b361d580 AK |
7030 | |
7031 | ||
af041f99 AA |
7032 | struct wpa_supplicant * |
7033 | wpas_vendor_elem(struct wpa_supplicant *wpa_s, enum wpa_vendor_elem_frame frame) | |
7034 | { | |
7035 | switch (frame) { | |
7036 | #ifdef CONFIG_P2P | |
7037 | case VENDOR_ELEM_PROBE_REQ_P2P: | |
7038 | case VENDOR_ELEM_PROBE_RESP_P2P: | |
7039 | case VENDOR_ELEM_PROBE_RESP_P2P_GO: | |
7040 | case VENDOR_ELEM_BEACON_P2P_GO: | |
7041 | case VENDOR_ELEM_P2P_PD_REQ: | |
7042 | case VENDOR_ELEM_P2P_PD_RESP: | |
7043 | case VENDOR_ELEM_P2P_GO_NEG_REQ: | |
7044 | case VENDOR_ELEM_P2P_GO_NEG_RESP: | |
7045 | case VENDOR_ELEM_P2P_GO_NEG_CONF: | |
7046 | case VENDOR_ELEM_P2P_INV_REQ: | |
7047 | case VENDOR_ELEM_P2P_INV_RESP: | |
7048 | case VENDOR_ELEM_P2P_ASSOC_REQ: | |
7049 | case VENDOR_ELEM_P2P_ASSOC_RESP: | |
ba307f85 | 7050 | return wpa_s->p2pdev; |
af041f99 AA |
7051 | #endif /* CONFIG_P2P */ |
7052 | default: | |
7053 | return wpa_s; | |
7054 | } | |
7055 | } | |
7056 | ||
7057 | ||
7058 | void wpas_vendor_elem_update(struct wpa_supplicant *wpa_s) | |
7059 | { | |
7060 | unsigned int i; | |
7061 | char buf[30]; | |
7062 | ||
7063 | wpa_printf(MSG_DEBUG, "Update vendor elements"); | |
7064 | ||
7065 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { | |
7066 | if (wpa_s->vendor_elem[i]) { | |
7067 | int res; | |
7068 | ||
7069 | res = os_snprintf(buf, sizeof(buf), "frame[%u]", i); | |
7070 | if (!os_snprintf_error(sizeof(buf), res)) { | |
7071 | wpa_hexdump_buf(MSG_DEBUG, buf, | |
7072 | wpa_s->vendor_elem[i]); | |
7073 | } | |
7074 | } | |
7075 | } | |
7076 | ||
7077 | #ifdef CONFIG_P2P | |
7078 | if (wpa_s->parent == wpa_s && | |
7079 | wpa_s->global->p2p && | |
7080 | !wpa_s->global->p2p_disabled) | |
7081 | p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem); | |
7082 | #endif /* CONFIG_P2P */ | |
7083 | } | |
7084 | ||
7085 | ||
7086 | int wpas_vendor_elem_remove(struct wpa_supplicant *wpa_s, int frame, | |
7087 | const u8 *elem, size_t len) | |
7088 | { | |
7089 | u8 *ie, *end; | |
7090 | ||
7091 | ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]); | |
7092 | end = ie + wpabuf_len(wpa_s->vendor_elem[frame]); | |
7093 | ||
7094 | for (; ie + 1 < end; ie += 2 + ie[1]) { | |
7095 | if (ie + len > end) | |
7096 | break; | |
7097 | if (os_memcmp(ie, elem, len) != 0) | |
7098 | continue; | |
7099 | ||
7100 | if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) { | |
7101 | wpabuf_free(wpa_s->vendor_elem[frame]); | |
7102 | wpa_s->vendor_elem[frame] = NULL; | |
7103 | } else { | |
7104 | os_memmove(ie, ie + len, end - (ie + len)); | |
7105 | wpa_s->vendor_elem[frame]->used -= len; | |
7106 | } | |
7107 | wpas_vendor_elem_update(wpa_s); | |
7108 | return 0; | |
7109 | } | |
7110 | ||
7111 | return -1; | |
7112 | } | |
ea69d973 AS |
7113 | |
7114 | ||
7115 | struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes, | |
7116 | u16 num_modes, enum hostapd_hw_mode mode) | |
7117 | { | |
7118 | u16 i; | |
7119 | ||
7120 | for (i = 0; i < num_modes; i++) { | |
7121 | if (modes[i].mode == mode) | |
7122 | return &modes[i]; | |
7123 | } | |
7124 | ||
7125 | return NULL; | |
7126 | } | |
dd599908 AS |
7127 | |
7128 | ||
7129 | static struct | |
7130 | wpa_bss_tmp_disallowed * wpas_get_disallowed_bss(struct wpa_supplicant *wpa_s, | |
7131 | const u8 *bssid) | |
7132 | { | |
7133 | struct wpa_bss_tmp_disallowed *bss; | |
7134 | ||
7135 | dl_list_for_each(bss, &wpa_s->bss_tmp_disallowed, | |
7136 | struct wpa_bss_tmp_disallowed, list) { | |
7137 | if (os_memcmp(bssid, bss->bssid, ETH_ALEN) == 0) | |
7138 | return bss; | |
7139 | } | |
7140 | ||
7141 | return NULL; | |
7142 | } | |
7143 | ||
7144 | ||
b04854ce AP |
7145 | static int wpa_set_driver_tmp_disallow_list(struct wpa_supplicant *wpa_s) |
7146 | { | |
7147 | struct wpa_bss_tmp_disallowed *tmp; | |
7148 | unsigned int num_bssid = 0; | |
7149 | u8 *bssids; | |
7150 | int ret; | |
7151 | ||
7152 | bssids = os_malloc(dl_list_len(&wpa_s->bss_tmp_disallowed) * ETH_ALEN); | |
7153 | if (!bssids) | |
7154 | return -1; | |
7155 | dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed, | |
7156 | struct wpa_bss_tmp_disallowed, list) { | |
7157 | os_memcpy(&bssids[num_bssid * ETH_ALEN], tmp->bssid, | |
7158 | ETH_ALEN); | |
7159 | num_bssid++; | |
7160 | } | |
7161 | ret = wpa_drv_set_bssid_blacklist(wpa_s, num_bssid, bssids); | |
7162 | os_free(bssids); | |
7163 | return ret; | |
7164 | } | |
7165 | ||
7166 | ||
7167 | static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx) | |
7168 | { | |
7169 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
7170 | struct wpa_bss_tmp_disallowed *tmp, *bss = timeout_ctx; | |
7171 | ||
7172 | /* Make sure the bss is not already freed */ | |
7173 | dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed, | |
7174 | struct wpa_bss_tmp_disallowed, list) { | |
7175 | if (bss == tmp) { | |
7176 | dl_list_del(&tmp->list); | |
7177 | os_free(tmp); | |
7178 | wpa_set_driver_tmp_disallow_list(wpa_s); | |
7179 | break; | |
7180 | } | |
7181 | } | |
7182 | } | |
7183 | ||
7184 | ||
dd599908 AS |
7185 | void wpa_bss_tmp_disallow(struct wpa_supplicant *wpa_s, const u8 *bssid, |
7186 | unsigned int sec) | |
7187 | { | |
7188 | struct wpa_bss_tmp_disallowed *bss; | |
dd599908 AS |
7189 | |
7190 | bss = wpas_get_disallowed_bss(wpa_s, bssid); | |
7191 | if (bss) { | |
b04854ce AP |
7192 | eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss); |
7193 | eloop_register_timeout(sec, 0, wpa_bss_tmp_disallow_timeout, | |
7194 | wpa_s, bss); | |
dd599908 AS |
7195 | return; |
7196 | } | |
7197 | ||
7198 | bss = os_malloc(sizeof(*bss)); | |
7199 | if (!bss) { | |
7200 | wpa_printf(MSG_DEBUG, | |
7201 | "Failed to allocate memory for temp disallow BSS"); | |
7202 | return; | |
7203 | } | |
7204 | ||
dd599908 AS |
7205 | os_memcpy(bss->bssid, bssid, ETH_ALEN); |
7206 | dl_list_add(&wpa_s->bss_tmp_disallowed, &bss->list); | |
b04854ce AP |
7207 | wpa_set_driver_tmp_disallow_list(wpa_s); |
7208 | eloop_register_timeout(sec, 0, wpa_bss_tmp_disallow_timeout, | |
7209 | wpa_s, bss); | |
dd599908 AS |
7210 | } |
7211 | ||
7212 | ||
7213 | int wpa_is_bss_tmp_disallowed(struct wpa_supplicant *wpa_s, const u8 *bssid) | |
7214 | { | |
d010048c | 7215 | struct wpa_bss_tmp_disallowed *bss = NULL, *tmp, *prev; |
dd599908 | 7216 | |
d010048c JM |
7217 | dl_list_for_each_safe(tmp, prev, &wpa_s->bss_tmp_disallowed, |
7218 | struct wpa_bss_tmp_disallowed, list) { | |
d010048c JM |
7219 | if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) { |
7220 | bss = tmp; | |
7221 | break; | |
7222 | } | |
7223 | } | |
dd599908 AS |
7224 | if (!bss) |
7225 | return 0; | |
7226 | ||
d010048c | 7227 | return 1; |
dd599908 | 7228 | } |