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