/src/hostap/wpa_supplicant/wpas_glue.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * WPA Supplicant - Glue code to setup EAPOL and RSN modules |
3 | | * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi> |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
7 | | */ |
8 | | |
9 | | #include "includes.h" |
10 | | |
11 | | #include "common.h" |
12 | | #include "eapol_supp/eapol_supp_sm.h" |
13 | | #include "eap_peer/eap.h" |
14 | | #include "rsn_supp/wpa.h" |
15 | | #include "eloop.h" |
16 | | #include "config.h" |
17 | | #include "l2_packet/l2_packet.h" |
18 | | #include "common/wpa_common.h" |
19 | | #include "common/ptksa_cache.h" |
20 | | #include "wpa_supplicant_i.h" |
21 | | #include "driver_i.h" |
22 | | #include "rsn_supp/pmksa_cache.h" |
23 | | #include "sme.h" |
24 | | #include "common/ieee802_11_defs.h" |
25 | | #include "common/wpa_ctrl.h" |
26 | | #include "wpas_glue.h" |
27 | | #include "wps_supplicant.h" |
28 | | #include "bss.h" |
29 | | #include "scan.h" |
30 | | #include "notify.h" |
31 | | #include "wpas_kay.h" |
32 | | |
33 | | |
34 | | #ifndef CONFIG_NO_CONFIG_BLOBS |
35 | | #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) |
36 | | static void wpa_supplicant_set_config_blob(void *ctx, |
37 | | struct wpa_config_blob *blob) |
38 | 0 | { |
39 | 0 | struct wpa_supplicant *wpa_s = ctx; |
40 | 0 | wpa_config_set_blob(wpa_s->conf, blob); |
41 | 0 | if (wpa_s->conf->update_config) { |
42 | 0 | int ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
43 | 0 | if (ret) { |
44 | 0 | wpa_printf(MSG_DEBUG, "Failed to update config after " |
45 | 0 | "blob set"); |
46 | 0 | } |
47 | 0 | } |
48 | 0 | } |
49 | | |
50 | | |
51 | | static const struct wpa_config_blob * |
52 | | wpa_supplicant_get_config_blob(void *ctx, const char *name) |
53 | 0 | { |
54 | 0 | struct wpa_supplicant *wpa_s = ctx; |
55 | 0 | return wpa_config_get_blob(wpa_s->conf, name); |
56 | 0 | } |
57 | | #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */ |
58 | | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
59 | | |
60 | | |
61 | | #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) |
62 | | static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type, |
63 | | const void *data, u16 data_len, |
64 | | size_t *msg_len, void **data_pos) |
65 | 0 | { |
66 | 0 | struct ieee802_1x_hdr *hdr; |
67 | |
|
68 | 0 | *msg_len = sizeof(*hdr) + data_len; |
69 | 0 | hdr = os_malloc(*msg_len); |
70 | 0 | if (hdr == NULL) |
71 | 0 | return NULL; |
72 | | |
73 | 0 | hdr->version = wpa_s->conf->eapol_version; |
74 | 0 | hdr->type = type; |
75 | 0 | hdr->length = host_to_be16(data_len); |
76 | |
|
77 | 0 | if (data) |
78 | 0 | os_memcpy(hdr + 1, data, data_len); |
79 | 0 | else |
80 | 0 | os_memset(hdr + 1, 0, data_len); |
81 | |
|
82 | 0 | if (data_pos) |
83 | 0 | *data_pos = hdr + 1; |
84 | |
|
85 | 0 | return (u8 *) hdr; |
86 | 0 | } |
87 | | |
88 | | |
89 | | /** |
90 | | * wpa_ether_send - Send Ethernet frame |
91 | | * @wpa_s: Pointer to wpa_supplicant data |
92 | | * @dest: Destination MAC address |
93 | | * @proto: Ethertype in host byte order |
94 | | * @buf: Frame payload starting from IEEE 802.1X header |
95 | | * @len: Frame payload length |
96 | | * Returns: >=0 on success, <0 on failure |
97 | | */ |
98 | | int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest, |
99 | | u16 proto, const u8 *buf, size_t len) |
100 | 0 | { |
101 | | #ifdef CONFIG_TESTING_OPTIONS |
102 | | if (wpa_s->ext_eapol_frame_io && proto == ETH_P_EAPOL) { |
103 | | size_t hex_len = 2 * len + 1; |
104 | | char *hex = os_malloc(hex_len); |
105 | | |
106 | | if (hex == NULL) |
107 | | return -1; |
108 | | wpa_snprintf_hex(hex, hex_len, buf, len); |
109 | | wpa_msg(wpa_s, MSG_INFO, "EAPOL-TX " MACSTR " %s", |
110 | | MAC2STR(dest), hex); |
111 | | os_free(hex); |
112 | | return 0; |
113 | | } |
114 | | #endif /* CONFIG_TESTING_OPTIONS */ |
115 | |
|
116 | 0 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_CONTROL_PORT) { |
117 | 0 | int encrypt = wpa_s->wpa && |
118 | 0 | wpa_sm_has_ptk_installed(wpa_s->wpa); |
119 | |
|
120 | 0 | return wpa_drv_tx_control_port(wpa_s, dest, proto, buf, len, |
121 | 0 | !encrypt); |
122 | 0 | } |
123 | | |
124 | 0 | if (wpa_s->l2) { |
125 | 0 | return l2_packet_send(wpa_s->l2, dest, proto, buf, len); |
126 | 0 | } |
127 | | |
128 | 0 | return -1; |
129 | 0 | } |
130 | | #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */ |
131 | | |
132 | | |
133 | | #ifdef IEEE8021X_EAPOL |
134 | | |
135 | | /** |
136 | | * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator |
137 | | * @ctx: Pointer to wpa_supplicant data (wpa_s) |
138 | | * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*) |
139 | | * @buf: EAPOL payload (after IEEE 802.1X header) |
140 | | * @len: EAPOL payload length |
141 | | * Returns: >=0 on success, <0 on failure |
142 | | * |
143 | | * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame |
144 | | * to the current Authenticator. |
145 | | */ |
146 | | static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf, |
147 | | size_t len) |
148 | 0 | { |
149 | 0 | struct wpa_supplicant *wpa_s = ctx; |
150 | 0 | u8 *msg, *dst, bssid[ETH_ALEN]; |
151 | 0 | struct driver_sta_mlo_info drv_mlo; |
152 | 0 | size_t msglen; |
153 | 0 | int res; |
154 | | |
155 | | /* TODO: could add l2_packet_sendmsg that allows fragments to avoid |
156 | | * extra copy here */ |
157 | |
|
158 | 0 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
159 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
160 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || |
161 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) { |
162 | | /* Current SSID is not using IEEE 802.1X/EAP, so drop possible |
163 | | * EAPOL frames (mainly, EAPOL-Start) from EAPOL state |
164 | | * machines. */ |
165 | 0 | wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X " |
166 | 0 | "mode (type=%d len=%lu)", type, |
167 | 0 | (unsigned long) len); |
168 | 0 | return -1; |
169 | 0 | } |
170 | | |
171 | 0 | if (pmksa_cache_get_current(wpa_s->wpa) && |
172 | 0 | type == IEEE802_1X_TYPE_EAPOL_START) { |
173 | | /* |
174 | | * We were trying to use PMKSA caching and sending EAPOL-Start |
175 | | * would abort that and trigger full EAPOL authentication. |
176 | | * However, we've already waited for the AP/Authenticator to |
177 | | * start 4-way handshake or EAP authentication, and apparently |
178 | | * it has not done so since the startWhen timer has reached zero |
179 | | * to get the state machine sending EAPOL-Start. This is not |
180 | | * really supposed to happen, but an interoperability issue with |
181 | | * a deployed AP has been identified where the connection fails |
182 | | * due to that AP failing to operate correctly if PMKID is |
183 | | * included in the Association Request frame. To work around |
184 | | * this, assume PMKSA caching failed and try to initiate full |
185 | | * EAP authentication. |
186 | | */ |
187 | 0 | if (!wpa_s->current_ssid || |
188 | 0 | wpa_s->current_ssid->eap_workaround) { |
189 | 0 | wpa_printf(MSG_DEBUG, |
190 | 0 | "RSN: Timeout on waiting for the AP to initiate 4-way handshake for PMKSA caching or EAP authentication - try to force it to start EAP authentication"); |
191 | 0 | } else { |
192 | 0 | wpa_printf(MSG_DEBUG, |
193 | 0 | "RSN: PMKSA caching - do not send EAPOL-Start"); |
194 | 0 | return -1; |
195 | 0 | } |
196 | 0 | } |
197 | | |
198 | 0 | if (is_zero_ether_addr(wpa_s->bssid)) { |
199 | 0 | wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an " |
200 | 0 | "EAPOL frame"); |
201 | 0 | os_memset(&drv_mlo, 0, sizeof(drv_mlo)); |
202 | 0 | if (wpa_drv_get_bssid(wpa_s, bssid) == 0 && |
203 | 0 | (!wpa_s->valid_links || |
204 | 0 | wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo) == 0) && |
205 | 0 | !is_zero_ether_addr(bssid)) { |
206 | 0 | dst = drv_mlo.valid_links ? drv_mlo.ap_mld_addr : bssid; |
207 | 0 | wpa_printf(MSG_DEBUG, "Using current %s " MACSTR |
208 | 0 | " from the driver as the EAPOL destination", |
209 | 0 | drv_mlo.valid_links ? "AP MLD MAC address" : |
210 | 0 | "BSSID", |
211 | 0 | MAC2STR(dst)); |
212 | 0 | } else { |
213 | 0 | dst = wpa_s->last_eapol_src; |
214 | 0 | wpa_printf(MSG_DEBUG, "Using the source address of the" |
215 | 0 | " last received EAPOL frame " MACSTR " as " |
216 | 0 | "the EAPOL destination", |
217 | 0 | MAC2STR(dst)); |
218 | 0 | } |
219 | 0 | } else { |
220 | | /* BSSID was already set (from (Re)Assoc event, so use BSSID or |
221 | | * AP MLD MAC address (in the case of MLO connection) as the |
222 | | * EAPOL destination. */ |
223 | 0 | dst = wpa_s->valid_links ? wpa_s->ap_mld_addr : wpa_s->bssid; |
224 | 0 | } |
225 | |
|
226 | 0 | msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL); |
227 | 0 | if (msg == NULL) |
228 | 0 | return -1; |
229 | | |
230 | 0 | wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst)); |
231 | 0 | wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen); |
232 | 0 | res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen); |
233 | 0 | os_free(msg); |
234 | 0 | return res; |
235 | 0 | } |
236 | | |
237 | | |
238 | | #ifdef CONFIG_WEP |
239 | | /** |
240 | | * wpa_eapol_set_wep_key - set WEP key for the driver |
241 | | * @ctx: Pointer to wpa_supplicant data (wpa_s) |
242 | | * @unicast: 1 = individual unicast key, 0 = broadcast key |
243 | | * @keyidx: WEP key index (0..3) |
244 | | * @key: Pointer to key data |
245 | | * @keylen: Key length in bytes |
246 | | * Returns: 0 on success or < 0 on error. |
247 | | */ |
248 | | static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx, |
249 | | const u8 *key, size_t keylen) |
250 | | { |
251 | | struct wpa_supplicant *wpa_s = ctx; |
252 | | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
253 | | int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 : |
254 | | WPA_CIPHER_WEP104; |
255 | | if (unicast) |
256 | | wpa_s->pairwise_cipher = cipher; |
257 | | else |
258 | | wpa_s->group_cipher = cipher; |
259 | | } |
260 | | return wpa_drv_set_key(wpa_s, -1, WPA_ALG_WEP, |
261 | | unicast ? wpa_s->bssid : NULL, |
262 | | keyidx, unicast, NULL, 0, key, keylen, |
263 | | unicast ? KEY_FLAG_PAIRWISE_RX_TX : |
264 | | KEY_FLAG_GROUP_RX_TX_DEFAULT); |
265 | | } |
266 | | #endif /* CONFIG_WEP */ |
267 | | |
268 | | |
269 | | static void wpa_supplicant_aborted_cached(void *ctx) |
270 | 0 | { |
271 | 0 | struct wpa_supplicant *wpa_s = ctx; |
272 | 0 | wpa_sm_aborted_cached(wpa_s->wpa); |
273 | 0 | } |
274 | | |
275 | | |
276 | | static const char * result_str(enum eapol_supp_result result) |
277 | 0 | { |
278 | 0 | switch (result) { |
279 | 0 | case EAPOL_SUPP_RESULT_FAILURE: |
280 | 0 | return "FAILURE"; |
281 | 0 | case EAPOL_SUPP_RESULT_SUCCESS: |
282 | 0 | return "SUCCESS"; |
283 | 0 | case EAPOL_SUPP_RESULT_EXPECTED_FAILURE: |
284 | 0 | return "EXPECTED_FAILURE"; |
285 | 0 | } |
286 | 0 | return "?"; |
287 | 0 | } |
288 | | |
289 | | |
290 | | static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, |
291 | | enum eapol_supp_result result, |
292 | | void *ctx) |
293 | 0 | { |
294 | 0 | struct wpa_supplicant *wpa_s = ctx; |
295 | 0 | int res, pmk_len; |
296 | 0 | u8 pmk[PMK_LEN_MAX]; |
297 | |
|
298 | 0 | wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s", |
299 | 0 | result_str(result)); |
300 | |
|
301 | 0 | if (wpas_wps_eapol_cb(wpa_s) > 0) |
302 | 0 | return; |
303 | | |
304 | 0 | wpa_s->eap_expected_failure = result == |
305 | 0 | EAPOL_SUPP_RESULT_EXPECTED_FAILURE; |
306 | |
|
307 | 0 | if (result != EAPOL_SUPP_RESULT_SUCCESS) { |
308 | 0 | int timeout = 2; |
309 | | /* |
310 | | * Make sure we do not get stuck here waiting for long EAPOL |
311 | | * timeout if the AP does not disconnect in case of |
312 | | * authentication failure. |
313 | | */ |
314 | 0 | if (wpa_s->eapol_failed) { |
315 | 0 | wpa_printf(MSG_DEBUG, |
316 | 0 | "EAPOL authentication failed again and AP did not disconnect us"); |
317 | 0 | timeout = 0; |
318 | 0 | } |
319 | 0 | wpa_s->eapol_failed = 1; |
320 | 0 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
321 | 0 | } else { |
322 | 0 | wpa_s->eapol_failed = 0; |
323 | 0 | ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src); |
324 | 0 | } |
325 | |
|
326 | 0 | if (result != EAPOL_SUPP_RESULT_SUCCESS || |
327 | 0 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) |
328 | 0 | return; |
329 | | |
330 | 0 | if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) |
331 | 0 | return; |
332 | | |
333 | 0 | wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way " |
334 | 0 | "handshake"); |
335 | |
|
336 | 0 | if (wpa_key_mgmt_sha384(wpa_s->key_mgmt)) |
337 | 0 | pmk_len = PMK_LEN_SUITE_B_192; |
338 | 0 | else |
339 | 0 | pmk_len = PMK_LEN; |
340 | |
|
341 | 0 | if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) { |
342 | | #ifdef CONFIG_IEEE80211R |
343 | | u8 buf[2 * PMK_LEN]; |
344 | | wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for " |
345 | | "driver-based 4-way hs and FT"); |
346 | | res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN); |
347 | | if (res == 0) { |
348 | | if (wpa_key_mgmt_sha384(wpa_s->key_mgmt)) |
349 | | os_memcpy(pmk, buf, pmk_len); |
350 | | else |
351 | | os_memcpy(pmk, buf + PMK_LEN, PMK_LEN); |
352 | | os_memset(buf, 0, sizeof(buf)); |
353 | | } |
354 | | #else /* CONFIG_IEEE80211R */ |
355 | 0 | res = -1; |
356 | 0 | #endif /* CONFIG_IEEE80211R */ |
357 | 0 | } else { |
358 | 0 | res = eapol_sm_get_key(eapol, pmk, pmk_len); |
359 | 0 | if (res) { |
360 | | /* |
361 | | * EAP-LEAP is an exception from other EAP methods: it |
362 | | * uses only 16-byte PMK. |
363 | | */ |
364 | 0 | res = eapol_sm_get_key(eapol, pmk, 16); |
365 | 0 | pmk_len = 16; |
366 | 0 | } |
367 | 0 | } |
368 | |
|
369 | 0 | if (res) { |
370 | 0 | wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state " |
371 | 0 | "machines"); |
372 | 0 | return; |
373 | 0 | } |
374 | | |
375 | 0 | wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way " |
376 | 0 | "handshake", pmk, pmk_len); |
377 | |
|
378 | 0 | if (wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0, pmk, |
379 | 0 | pmk_len, KEY_FLAG_PMK)) { |
380 | 0 | wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver"); |
381 | 0 | } |
382 | |
|
383 | 0 | wpa_supplicant_cancel_scan(wpa_s); |
384 | 0 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
385 | 0 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
386 | |
|
387 | 0 | } |
388 | | |
389 | | |
390 | | static void wpa_supplicant_notify_eapol_done(void *ctx) |
391 | 0 | { |
392 | 0 | struct wpa_supplicant *wpa_s = ctx; |
393 | 0 | wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete"); |
394 | 0 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
395 | 0 | wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE); |
396 | 0 | } else { |
397 | 0 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
398 | 0 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
399 | 0 | } |
400 | 0 | } |
401 | | |
402 | | #endif /* IEEE8021X_EAPOL */ |
403 | | |
404 | | |
405 | | #ifndef CONFIG_NO_WPA |
406 | | |
407 | | static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s) |
408 | 0 | { |
409 | 0 | int ret = 0; |
410 | 0 | struct wpa_bss *curr = NULL, *bss; |
411 | 0 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
412 | 0 | const u8 *ie; |
413 | |
|
414 | 0 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
415 | 0 | if (!ether_addr_equal(bss->bssid, wpa_s->bssid)) |
416 | 0 | continue; |
417 | 0 | if (ssid == NULL || |
418 | 0 | ((bss->ssid_len == ssid->ssid_len && |
419 | 0 | os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) || |
420 | 0 | ssid->ssid_len == 0)) { |
421 | 0 | curr = bss; |
422 | 0 | break; |
423 | 0 | } |
424 | | #ifdef CONFIG_OWE |
425 | | if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
426 | | (bss->flags & WPA_BSS_OWE_TRANSITION)) { |
427 | | curr = bss; |
428 | | break; |
429 | | } |
430 | | #endif /* CONFIG_OWE */ |
431 | 0 | } |
432 | |
|
433 | 0 | if (curr) { |
434 | 0 | ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE); |
435 | 0 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0)) |
436 | 0 | ret = -1; |
437 | |
|
438 | 0 | ie = wpa_bss_get_ie(curr, WLAN_EID_RSN); |
439 | 0 | if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0)) |
440 | 0 | ret = -1; |
441 | |
|
442 | 0 | ie = wpa_bss_get_ie(curr, WLAN_EID_RSNX); |
443 | 0 | if (wpa_sm_set_ap_rsnxe(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0)) |
444 | 0 | ret = -1; |
445 | |
|
446 | 0 | ie = wpa_bss_get_vendor_ie(curr, RSNE_OVERRIDE_IE_VENDOR_TYPE); |
447 | 0 | if (wpa_sm_set_ap_rsne_override(wpa_s->wpa, ie, |
448 | 0 | ie ? 2 + ie[1] : 0)) |
449 | 0 | ret = -1; |
450 | |
|
451 | 0 | ie = wpa_bss_get_vendor_ie(curr, |
452 | 0 | RSNE_OVERRIDE_2_IE_VENDOR_TYPE); |
453 | 0 | if (wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, ie, |
454 | 0 | ie ? 2 + ie[1] : 0)) |
455 | 0 | ret = -1; |
456 | |
|
457 | 0 | ie = wpa_bss_get_vendor_ie(curr, RSNXE_OVERRIDE_IE_VENDOR_TYPE); |
458 | 0 | if (wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, ie, |
459 | 0 | ie ? 2 + ie[1] : 0)) |
460 | 0 | ret = -1; |
461 | 0 | } else { |
462 | 0 | ret = -1; |
463 | 0 | } |
464 | |
|
465 | 0 | return ret; |
466 | 0 | } |
467 | | |
468 | | |
469 | | static int wpa_supplicant_get_beacon_ie(void *ctx) |
470 | 0 | { |
471 | 0 | struct wpa_supplicant *wpa_s = ctx; |
472 | 0 | if (wpa_get_beacon_ie(wpa_s) == 0) { |
473 | 0 | return 0; |
474 | 0 | } |
475 | | |
476 | | /* No WPA/RSN IE found in the cached scan results. Try to get updated |
477 | | * scan results from the driver. */ |
478 | 0 | if (wpa_supplicant_update_scan_results(wpa_s, wpa_s->bssid) < 0) |
479 | 0 | return -1; |
480 | | |
481 | 0 | return wpa_get_beacon_ie(wpa_s); |
482 | 0 | } |
483 | | |
484 | | |
485 | | static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type, |
486 | | const void *data, u16 data_len, |
487 | | size_t *msg_len, void **data_pos) |
488 | 0 | { |
489 | 0 | return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos); |
490 | 0 | } |
491 | | |
492 | | |
493 | | static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto, |
494 | | const u8 *buf, size_t len) |
495 | 0 | { |
496 | 0 | return wpa_ether_send(wpa_s, dest, proto, buf, len); |
497 | 0 | } |
498 | | |
499 | | |
500 | | static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s) |
501 | 0 | { |
502 | 0 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
503 | 0 | } |
504 | | |
505 | | |
506 | | static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state) |
507 | 0 | { |
508 | 0 | wpa_supplicant_set_state(wpa_s, state); |
509 | 0 | } |
510 | | |
511 | | |
512 | | /** |
513 | | * wpa_supplicant_get_state - Get the connection state |
514 | | * @wpa_s: Pointer to wpa_supplicant data |
515 | | * Returns: The current connection state (WPA_*) |
516 | | */ |
517 | | static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s) |
518 | 0 | { |
519 | 0 | return wpa_s->wpa_state; |
520 | 0 | } |
521 | | |
522 | | |
523 | | static enum wpa_states _wpa_supplicant_get_state(void *wpa_s) |
524 | 0 | { |
525 | 0 | return wpa_supplicant_get_state(wpa_s); |
526 | 0 | } |
527 | | |
528 | | |
529 | | static void _wpa_supplicant_deauthenticate(void *wpa_s, u16 reason_code) |
530 | 0 | { |
531 | 0 | wpa_supplicant_deauthenticate(wpa_s, reason_code); |
532 | | /* Schedule a scan to make sure we continue looking for networks */ |
533 | 0 | wpa_supplicant_req_scan(wpa_s, 5, 0); |
534 | 0 | } |
535 | | |
536 | | |
537 | | static void _wpa_supplicant_reconnect(void *wpa_s) |
538 | 0 | { |
539 | 0 | wpa_supplicant_reconnect(wpa_s); |
540 | 0 | } |
541 | | |
542 | | |
543 | | static void * wpa_supplicant_get_network_ctx(void *wpa_s) |
544 | 0 | { |
545 | 0 | return wpa_supplicant_get_ssid(wpa_s); |
546 | 0 | } |
547 | | |
548 | | |
549 | | static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid) |
550 | 0 | { |
551 | 0 | struct wpa_supplicant *wpa_s = ctx; |
552 | 0 | return wpa_drv_get_bssid(wpa_s, bssid); |
553 | 0 | } |
554 | | |
555 | | |
556 | | static int wpa_supplicant_set_key(void *_wpa_s, int link_id, enum wpa_alg alg, |
557 | | const u8 *addr, int key_idx, int set_tx, |
558 | | const u8 *seq, size_t seq_len, |
559 | | const u8 *key, size_t key_len, |
560 | | enum key_flag key_flag) |
561 | 0 | { |
562 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
563 | 0 | int ret; |
564 | |
|
565 | 0 | if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) { |
566 | | /* Clear the MIC error counter when setting a new PTK. */ |
567 | 0 | wpa_s->mic_errors_seen = 0; |
568 | 0 | } |
569 | | #ifdef CONFIG_TESTING_GET_GTK |
570 | | if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) && |
571 | | alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) { |
572 | | os_memcpy(wpa_s->last_gtk, key, key_len); |
573 | | wpa_s->last_gtk_len = key_len; |
574 | | } |
575 | | #endif /* CONFIG_TESTING_GET_GTK */ |
576 | | #ifdef CONFIG_TESTING_OPTIONS |
577 | | if (addr && !is_broadcast_ether_addr(addr) && |
578 | | !(key_flag & KEY_FLAG_MODIFY)) { |
579 | | wpa_s->last_tk_alg = alg; |
580 | | os_memcpy(wpa_s->last_tk_addr, addr, ETH_ALEN); |
581 | | wpa_s->last_tk_key_idx = key_idx; |
582 | | if (key) |
583 | | os_memcpy(wpa_s->last_tk, key, key_len); |
584 | | wpa_s->last_tk_len = key_len; |
585 | | } |
586 | | #endif /* CONFIG_TESTING_OPTIONS */ |
587 | |
|
588 | 0 | ret = wpa_drv_set_key(wpa_s, link_id, alg, addr, key_idx, set_tx, seq, |
589 | 0 | seq_len, key, key_len, key_flag); |
590 | 0 | if (ret == 0 && (key_idx == 6 || key_idx == 7) && |
591 | 0 | alg != WPA_ALG_NONE && key_len > 0) |
592 | 0 | wpa_s->bigtk_set = true; |
593 | |
|
594 | 0 | return ret; |
595 | 0 | } |
596 | | |
597 | | |
598 | | static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr, |
599 | | int protection_type, |
600 | | int key_type) |
601 | 0 | { |
602 | 0 | return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type, |
603 | 0 | key_type); |
604 | 0 | } |
605 | | |
606 | | |
607 | | static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s, |
608 | | void *network_ctx) |
609 | 0 | { |
610 | 0 | struct wpa_ssid *ssid; |
611 | |
|
612 | 0 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
613 | 0 | if (network_ctx == ssid) |
614 | 0 | return ssid; |
615 | 0 | } |
616 | | |
617 | 0 | return NULL; |
618 | 0 | } |
619 | | |
620 | | |
621 | | static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx, |
622 | | const u8 *bssid, const u8 *pmkid, |
623 | | const u8 *fils_cache_id, |
624 | | const u8 *pmk, size_t pmk_len, |
625 | | u32 pmk_lifetime, u8 pmk_reauth_threshold, |
626 | | int akmp) |
627 | 0 | { |
628 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
629 | 0 | struct wpa_ssid *ssid; |
630 | 0 | struct wpa_pmkid_params params; |
631 | |
|
632 | 0 | os_memset(¶ms, 0, sizeof(params)); |
633 | 0 | ssid = wpas_get_network_ctx(wpa_s, network_ctx); |
634 | 0 | if (ssid) { |
635 | 0 | wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d", |
636 | 0 | MAC2STR(bssid), ssid->id); |
637 | 0 | if ((akmp == WPA_KEY_MGMT_FT_IEEE8021X || |
638 | 0 | akmp == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) && |
639 | 0 | !ssid->ft_eap_pmksa_caching) { |
640 | | /* Since we will not be using PMKSA caching for FT-EAP |
641 | | * within wpa_supplicant to avoid known interop issues |
642 | | * with APs, do not add this PMKID to the driver either |
643 | | * so that we won't be hitting those interop issues |
644 | | * with driver-based RSNE generation. */ |
645 | 0 | wpa_printf(MSG_DEBUG, |
646 | 0 | "FT: Do not add PMKID entry to the driver since FT-EAP PMKSA caching is not enabled in configuration"); |
647 | 0 | return 0; |
648 | 0 | } |
649 | 0 | } |
650 | 0 | if (ssid && fils_cache_id) { |
651 | 0 | params.ssid = ssid->ssid; |
652 | 0 | params.ssid_len = ssid->ssid_len; |
653 | 0 | params.fils_cache_id = fils_cache_id; |
654 | 0 | } else { |
655 | 0 | params.bssid = bssid; |
656 | 0 | } |
657 | |
|
658 | 0 | params.pmkid = pmkid; |
659 | 0 | params.pmk = pmk; |
660 | 0 | params.pmk_len = pmk_len; |
661 | 0 | params.pmk_lifetime = pmk_lifetime; |
662 | 0 | params.pmk_reauth_threshold = pmk_reauth_threshold; |
663 | |
|
664 | 0 | return wpa_drv_add_pmkid(wpa_s, ¶ms); |
665 | 0 | } |
666 | | |
667 | | |
668 | | static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx, |
669 | | const u8 *bssid, const u8 *pmkid, |
670 | | const u8 *fils_cache_id) |
671 | 0 | { |
672 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
673 | 0 | struct wpa_ssid *ssid; |
674 | 0 | struct wpa_pmkid_params params; |
675 | |
|
676 | 0 | os_memset(¶ms, 0, sizeof(params)); |
677 | 0 | ssid = wpas_get_network_ctx(wpa_s, network_ctx); |
678 | 0 | if (ssid) |
679 | 0 | wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d", |
680 | 0 | MAC2STR(bssid), ssid->id); |
681 | 0 | if (ssid && fils_cache_id) { |
682 | 0 | params.ssid = ssid->ssid; |
683 | 0 | params.ssid_len = ssid->ssid_len; |
684 | 0 | params.fils_cache_id = fils_cache_id; |
685 | 0 | } else { |
686 | 0 | params.bssid = bssid; |
687 | 0 | } |
688 | |
|
689 | 0 | params.pmkid = pmkid; |
690 | |
|
691 | 0 | return wpa_drv_remove_pmkid(wpa_s, ¶ms); |
692 | 0 | } |
693 | | |
694 | | |
695 | | #ifdef CONFIG_IEEE80211R |
696 | | static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md, |
697 | | const u8 *ies, size_t ies_len) |
698 | | { |
699 | | struct wpa_supplicant *wpa_s = ctx; |
700 | | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
701 | | return sme_update_ft_ies(wpa_s, md, ies, ies_len); |
702 | | return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len); |
703 | | } |
704 | | |
705 | | |
706 | | static int wpa_supplicant_send_ft_action(void *ctx, u8 action, |
707 | | const u8 *target_ap, |
708 | | const u8 *ies, size_t ies_len) |
709 | | { |
710 | | struct wpa_supplicant *wpa_s = ctx; |
711 | | int ret; |
712 | | u8 *data, *pos; |
713 | | size_t data_len; |
714 | | |
715 | | if (action != 1) { |
716 | | wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d", |
717 | | action); |
718 | | return -1; |
719 | | } |
720 | | |
721 | | /* |
722 | | * Action frame payload: |
723 | | * Category[1] = 6 (Fast BSS Transition) |
724 | | * Action[1] = 1 (Fast BSS Transition Request) |
725 | | * STA Address |
726 | | * Target AP Address |
727 | | * FT IEs |
728 | | */ |
729 | | |
730 | | data_len = 2 + 2 * ETH_ALEN + ies_len; |
731 | | data = os_malloc(data_len); |
732 | | if (data == NULL) |
733 | | return -1; |
734 | | pos = data; |
735 | | *pos++ = 0x06; /* FT Action category */ |
736 | | *pos++ = action; |
737 | | os_memcpy(pos, wpa_s->own_addr, ETH_ALEN); |
738 | | pos += ETH_ALEN; |
739 | | os_memcpy(pos, target_ap, ETH_ALEN); |
740 | | pos += ETH_ALEN; |
741 | | os_memcpy(pos, ies, ies_len); |
742 | | |
743 | | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, |
744 | | wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid, |
745 | | data, data_len, 0); |
746 | | os_free(data); |
747 | | |
748 | | return ret; |
749 | | } |
750 | | |
751 | | |
752 | | static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap) |
753 | | { |
754 | | struct wpa_supplicant *wpa_s = ctx; |
755 | | struct wpa_driver_auth_params params; |
756 | | struct wpa_bss *bss; |
757 | | |
758 | | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
759 | | if (bss == NULL) |
760 | | return -1; |
761 | | |
762 | | os_memset(¶ms, 0, sizeof(params)); |
763 | | params.bssid = target_ap; |
764 | | params.freq = bss->freq; |
765 | | params.ssid = bss->ssid; |
766 | | params.ssid_len = bss->ssid_len; |
767 | | params.auth_alg = WPA_AUTH_ALG_FT; |
768 | | params.local_state_change = 1; |
769 | | return wpa_drv_authenticate(wpa_s, ¶ms); |
770 | | } |
771 | | #endif /* CONFIG_IEEE80211R */ |
772 | | |
773 | | |
774 | | #ifdef CONFIG_TDLS |
775 | | |
776 | | static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported, |
777 | | int *tdls_ext_setup, |
778 | | int *tdls_chan_switch) |
779 | | { |
780 | | struct wpa_supplicant *wpa_s = ctx; |
781 | | |
782 | | *tdls_supported = 0; |
783 | | *tdls_ext_setup = 0; |
784 | | *tdls_chan_switch = 0; |
785 | | |
786 | | if (!wpa_s->drv_capa_known) |
787 | | return -1; |
788 | | |
789 | | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) |
790 | | *tdls_supported = 1; |
791 | | |
792 | | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP) |
793 | | *tdls_ext_setup = 1; |
794 | | |
795 | | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH) |
796 | | *tdls_chan_switch = 1; |
797 | | |
798 | | return 0; |
799 | | } |
800 | | |
801 | | |
802 | | static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst, |
803 | | u8 action_code, u8 dialog_token, |
804 | | u16 status_code, u32 peer_capab, |
805 | | int initiator, const u8 *buf, |
806 | | size_t len, int link_id) |
807 | | { |
808 | | struct wpa_supplicant *wpa_s = ctx; |
809 | | return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token, |
810 | | status_code, peer_capab, initiator, buf, |
811 | | len, link_id); |
812 | | } |
813 | | |
814 | | |
815 | | static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer) |
816 | | { |
817 | | struct wpa_supplicant *wpa_s = ctx; |
818 | | return wpa_drv_tdls_oper(wpa_s, oper, peer); |
819 | | } |
820 | | |
821 | | |
822 | | static int wpa_supplicant_tdls_peer_addset( |
823 | | void *ctx, const u8 *peer, int add, u16 aid, u16 capability, |
824 | | const u8 *supp_rates, size_t supp_rates_len, |
825 | | const struct ieee80211_ht_capabilities *ht_capab, |
826 | | const struct ieee80211_vht_capabilities *vht_capab, |
827 | | const struct ieee80211_he_capabilities *he_capab, |
828 | | size_t he_capab_len, |
829 | | const struct ieee80211_he_6ghz_band_cap *he_6ghz_he_capab, |
830 | | u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len, |
831 | | const u8 *supp_channels, size_t supp_channels_len, |
832 | | const u8 *supp_oper_classes, size_t supp_oper_classes_len, |
833 | | const struct ieee80211_eht_capabilities *eht_capab, |
834 | | size_t eht_capab_len, int mld_link_id) |
835 | | { |
836 | | struct wpa_supplicant *wpa_s = ctx; |
837 | | struct hostapd_sta_add_params params; |
838 | | |
839 | | os_memset(¶ms, 0, sizeof(params)); |
840 | | |
841 | | params.addr = peer; |
842 | | params.aid = aid; |
843 | | params.capability = capability; |
844 | | params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED; |
845 | | |
846 | | /* |
847 | | * Don't rely only on qosinfo for WMM capability. It may be 0 even when |
848 | | * present. Allow the WMM IE to also indicate QoS support. |
849 | | */ |
850 | | if (wmm || qosinfo) |
851 | | params.flags |= WPA_STA_WMM; |
852 | | |
853 | | params.ht_capabilities = ht_capab; |
854 | | params.vht_capabilities = vht_capab; |
855 | | params.he_capab = he_capab; |
856 | | params.he_capab_len = he_capab_len; |
857 | | params.he_6ghz_capab = he_6ghz_he_capab; |
858 | | params.qosinfo = qosinfo; |
859 | | params.listen_interval = 0; |
860 | | params.supp_rates = supp_rates; |
861 | | params.supp_rates_len = supp_rates_len; |
862 | | params.set = !add; |
863 | | params.ext_capab = ext_capab; |
864 | | params.ext_capab_len = ext_capab_len; |
865 | | params.supp_channels = supp_channels; |
866 | | params.supp_channels_len = supp_channels_len; |
867 | | params.supp_oper_classes = supp_oper_classes; |
868 | | params.supp_oper_classes_len = supp_oper_classes_len; |
869 | | params.eht_capab = eht_capab; |
870 | | params.eht_capab_len = eht_capab_len; |
871 | | params.mld_link_id = mld_link_id; |
872 | | |
873 | | return wpa_drv_sta_add(wpa_s, ¶ms); |
874 | | } |
875 | | |
876 | | |
877 | | static int wpa_supplicant_tdls_enable_channel_switch( |
878 | | void *ctx, const u8 *addr, u8 oper_class, |
879 | | const struct hostapd_freq_params *params) |
880 | | { |
881 | | struct wpa_supplicant *wpa_s = ctx; |
882 | | |
883 | | return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class, |
884 | | params); |
885 | | } |
886 | | |
887 | | |
888 | | static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr) |
889 | | { |
890 | | struct wpa_supplicant *wpa_s = ctx; |
891 | | |
892 | | return wpa_drv_tdls_disable_channel_switch(wpa_s, addr); |
893 | | } |
894 | | |
895 | | #endif /* CONFIG_TDLS */ |
896 | | |
897 | | #endif /* CONFIG_NO_WPA */ |
898 | | |
899 | | |
900 | | enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field) |
901 | 0 | { |
902 | 0 | if (os_strcmp(field, "IDENTITY") == 0) |
903 | 0 | return WPA_CTRL_REQ_EAP_IDENTITY; |
904 | 0 | else if (os_strcmp(field, "PASSWORD") == 0) |
905 | 0 | return WPA_CTRL_REQ_EAP_PASSWORD; |
906 | 0 | else if (os_strcmp(field, "NEW_PASSWORD") == 0) |
907 | 0 | return WPA_CTRL_REQ_EAP_NEW_PASSWORD; |
908 | 0 | else if (os_strcmp(field, "PIN") == 0) |
909 | 0 | return WPA_CTRL_REQ_EAP_PIN; |
910 | 0 | else if (os_strcmp(field, "OTP") == 0) |
911 | 0 | return WPA_CTRL_REQ_EAP_OTP; |
912 | 0 | else if (os_strcmp(field, "PASSPHRASE") == 0) |
913 | 0 | return WPA_CTRL_REQ_EAP_PASSPHRASE; |
914 | 0 | else if (os_strcmp(field, "SIM") == 0) |
915 | 0 | return WPA_CTRL_REQ_SIM; |
916 | 0 | else if (os_strcmp(field, "PSK_PASSPHRASE") == 0) |
917 | 0 | return WPA_CTRL_REQ_PSK_PASSPHRASE; |
918 | 0 | else if (os_strcmp(field, "EXT_CERT_CHECK") == 0) |
919 | 0 | return WPA_CTRL_REQ_EXT_CERT_CHECK; |
920 | 0 | return WPA_CTRL_REQ_UNKNOWN; |
921 | 0 | } |
922 | | |
923 | | |
924 | | const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field, |
925 | | const char *default_txt, |
926 | | const char **txt) |
927 | 0 | { |
928 | 0 | const char *ret = NULL; |
929 | |
|
930 | 0 | *txt = default_txt; |
931 | |
|
932 | 0 | switch (field) { |
933 | 0 | case WPA_CTRL_REQ_EAP_IDENTITY: |
934 | 0 | *txt = "Identity"; |
935 | 0 | ret = "IDENTITY"; |
936 | 0 | break; |
937 | 0 | case WPA_CTRL_REQ_EAP_PASSWORD: |
938 | 0 | *txt = "Password"; |
939 | 0 | ret = "PASSWORD"; |
940 | 0 | break; |
941 | 0 | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: |
942 | 0 | *txt = "New Password"; |
943 | 0 | ret = "NEW_PASSWORD"; |
944 | 0 | break; |
945 | 0 | case WPA_CTRL_REQ_EAP_PIN: |
946 | 0 | *txt = "PIN"; |
947 | 0 | ret = "PIN"; |
948 | 0 | break; |
949 | 0 | case WPA_CTRL_REQ_EAP_OTP: |
950 | 0 | ret = "OTP"; |
951 | 0 | break; |
952 | 0 | case WPA_CTRL_REQ_EAP_PASSPHRASE: |
953 | 0 | *txt = "Private key passphrase"; |
954 | 0 | ret = "PASSPHRASE"; |
955 | 0 | break; |
956 | 0 | case WPA_CTRL_REQ_SIM: |
957 | 0 | ret = "SIM"; |
958 | 0 | break; |
959 | 0 | case WPA_CTRL_REQ_PSK_PASSPHRASE: |
960 | 0 | *txt = "PSK or passphrase"; |
961 | 0 | ret = "PSK_PASSPHRASE"; |
962 | 0 | break; |
963 | 0 | case WPA_CTRL_REQ_EXT_CERT_CHECK: |
964 | 0 | *txt = "External server certificate validation"; |
965 | 0 | ret = "EXT_CERT_CHECK"; |
966 | 0 | break; |
967 | 0 | default: |
968 | 0 | break; |
969 | 0 | } |
970 | | |
971 | | /* txt needs to be something */ |
972 | 0 | if (*txt == NULL) { |
973 | 0 | wpa_printf(MSG_WARNING, "No message for request %d", field); |
974 | 0 | ret = NULL; |
975 | 0 | } |
976 | |
|
977 | 0 | return ret; |
978 | 0 | } |
979 | | |
980 | | |
981 | | void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
982 | | const char *field_name, const char *txt) |
983 | 0 | { |
984 | 0 | wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s-%d:%s needed for SSID %s", |
985 | 0 | field_name, ssid->id, txt, |
986 | 0 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
987 | 0 | } |
988 | | |
989 | | |
990 | | #ifdef IEEE8021X_EAPOL |
991 | | #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) |
992 | | static void wpa_supplicant_eap_param_needed(void *ctx, |
993 | | enum wpa_ctrl_req_type field, |
994 | | const char *default_txt) |
995 | 0 | { |
996 | 0 | struct wpa_supplicant *wpa_s = ctx; |
997 | 0 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
998 | 0 | const char *field_name, *txt = NULL; |
999 | |
|
1000 | 0 | if (ssid == NULL) |
1001 | 0 | return; |
1002 | | |
1003 | 0 | if (field == WPA_CTRL_REQ_EXT_CERT_CHECK) |
1004 | 0 | ssid->eap.pending_ext_cert_check = PENDING_CHECK; |
1005 | 0 | wpas_notify_network_request(wpa_s, ssid, field, default_txt); |
1006 | |
|
1007 | 0 | field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt, |
1008 | 0 | &txt); |
1009 | 0 | if (field_name == NULL) { |
1010 | 0 | wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed", |
1011 | 0 | field); |
1012 | 0 | return; |
1013 | 0 | } |
1014 | | |
1015 | 0 | wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name); |
1016 | |
|
1017 | 0 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); |
1018 | 0 | } |
1019 | | #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
1020 | | #define wpa_supplicant_eap_param_needed NULL |
1021 | | #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
1022 | | |
1023 | | |
1024 | | #ifdef CONFIG_EAP_PROXY |
1025 | | |
1026 | | static void wpa_supplicant_eap_proxy_cb(void *ctx) |
1027 | | { |
1028 | | struct wpa_supplicant *wpa_s = ctx; |
1029 | | size_t len; |
1030 | | |
1031 | | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1, |
1032 | | wpa_s->imsi, &len); |
1033 | | if (wpa_s->mnc_len > 0) { |
1034 | | wpa_s->imsi[len] = '\0'; |
1035 | | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)", |
1036 | | wpa_s->imsi, wpa_s->mnc_len); |
1037 | | } else { |
1038 | | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available"); |
1039 | | } |
1040 | | } |
1041 | | |
1042 | | |
1043 | | static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s) |
1044 | | { |
1045 | | int i; |
1046 | | struct wpa_ssid *ssid; |
1047 | | const struct eap_method_type *eap_methods; |
1048 | | |
1049 | | if (!wpa_s->conf) |
1050 | | return; |
1051 | | |
1052 | | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
1053 | | eap_methods = ssid->eap.eap_methods; |
1054 | | if (!eap_methods) |
1055 | | continue; |
1056 | | |
1057 | | for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) { |
1058 | | if (eap_methods[i].vendor == EAP_VENDOR_IETF && |
1059 | | (eap_methods[i].method == EAP_TYPE_SIM || |
1060 | | eap_methods[i].method == EAP_TYPE_AKA || |
1061 | | eap_methods[i].method == EAP_TYPE_AKA_PRIME)) { |
1062 | | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
1063 | | break; |
1064 | | } |
1065 | | } |
1066 | | } |
1067 | | } |
1068 | | |
1069 | | |
1070 | | static void |
1071 | | wpa_supplicant_eap_proxy_notify_sim_status(void *ctx, |
1072 | | enum eap_proxy_sim_state sim_state) |
1073 | | { |
1074 | | struct wpa_supplicant *wpa_s = ctx; |
1075 | | |
1076 | | wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state); |
1077 | | switch (sim_state) { |
1078 | | case SIM_STATE_ERROR: |
1079 | | wpa_sm_sim_state_error_handler(wpa_s); |
1080 | | break; |
1081 | | default: |
1082 | | wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown"); |
1083 | | break; |
1084 | | } |
1085 | | } |
1086 | | |
1087 | | #endif /* CONFIG_EAP_PROXY */ |
1088 | | |
1089 | | |
1090 | | static void wpa_supplicant_port_cb(void *ctx, int authorized) |
1091 | 0 | { |
1092 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1093 | | #ifdef CONFIG_AP |
1094 | | if (wpa_s->ap_iface) { |
1095 | | wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant " |
1096 | | "port status: %s", |
1097 | | authorized ? "Authorized" : "Unauthorized"); |
1098 | | return; |
1099 | | } |
1100 | | #endif /* CONFIG_AP */ |
1101 | 0 | wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s", |
1102 | 0 | authorized ? "Authorized" : "Unauthorized"); |
1103 | 0 | wpa_drv_set_supp_port(wpa_s, authorized); |
1104 | 0 | } |
1105 | | |
1106 | | |
1107 | | static void wpa_supplicant_cert_cb(void *ctx, struct tls_cert_data *cert, |
1108 | | const char *cert_hash) |
1109 | 0 | { |
1110 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1111 | |
|
1112 | 0 | wpas_notify_certification(wpa_s, cert, cert_hash); |
1113 | 0 | } |
1114 | | |
1115 | | |
1116 | | static void wpa_supplicant_status_cb(void *ctx, const char *status, |
1117 | | const char *parameter) |
1118 | 0 | { |
1119 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1120 | |
|
1121 | 0 | wpas_notify_eap_status(wpa_s, status, parameter); |
1122 | 0 | } |
1123 | | |
1124 | | |
1125 | | static void wpa_supplicant_eap_error_cb(void *ctx, int error_code) |
1126 | 0 | { |
1127 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1128 | |
|
1129 | 0 | wpas_notify_eap_error(wpa_s, error_code); |
1130 | 0 | } |
1131 | | |
1132 | | |
1133 | | static int wpa_supplicant_eap_auth_start_cb(void *ctx) |
1134 | 0 | { |
1135 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1136 | |
|
1137 | 0 | if (!wpa_s->new_connection && wpa_s->deny_ptk0_rekey && |
1138 | 0 | !wpa_sm_ext_key_id_active(wpa_s->wpa)) { |
1139 | 0 | wpa_msg(wpa_s, MSG_INFO, |
1140 | 0 | "WPA: PTK0 rekey not allowed, reconnecting"); |
1141 | 0 | wpa_supplicant_reconnect(wpa_s); |
1142 | 0 | return -1; |
1143 | 0 | } |
1144 | 0 | return 0; |
1145 | 0 | } |
1146 | | |
1147 | | |
1148 | | static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len) |
1149 | 0 | { |
1150 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1151 | 0 | char *str; |
1152 | 0 | int res; |
1153 | |
|
1154 | 0 | wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity", |
1155 | 0 | id, len); |
1156 | |
|
1157 | 0 | if (wpa_s->current_ssid == NULL) |
1158 | 0 | return; |
1159 | | |
1160 | 0 | if (id == NULL) { |
1161 | 0 | if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity", |
1162 | 0 | "NULL", 0) < 0) |
1163 | 0 | return; |
1164 | 0 | } else { |
1165 | 0 | str = os_malloc(len * 2 + 1); |
1166 | 0 | if (str == NULL) |
1167 | 0 | return; |
1168 | 0 | wpa_snprintf_hex(str, len * 2 + 1, id, len); |
1169 | 0 | res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity", |
1170 | 0 | str, 0); |
1171 | 0 | os_free(str); |
1172 | 0 | if (res < 0) |
1173 | 0 | return; |
1174 | 0 | } |
1175 | | |
1176 | 0 | if (wpa_s->conf->update_config) { |
1177 | 0 | res = wpa_config_write(wpa_s->confname, wpa_s->conf); |
1178 | 0 | if (res) { |
1179 | 0 | wpa_printf(MSG_DEBUG, "Failed to update config after " |
1180 | 0 | "anonymous_id update"); |
1181 | 0 | } |
1182 | 0 | } |
1183 | 0 | } |
1184 | | |
1185 | | |
1186 | | static bool wpas_encryption_required(void *ctx) |
1187 | 0 | { |
1188 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1189 | |
|
1190 | 0 | return wpa_s->wpa && |
1191 | 0 | wpa_sm_has_ptk_installed(wpa_s->wpa) && |
1192 | 0 | wpa_sm_pmf_enabled(wpa_s->wpa); |
1193 | 0 | } |
1194 | | |
1195 | | #endif /* IEEE8021X_EAPOL */ |
1196 | | |
1197 | | |
1198 | | int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s) |
1199 | 0 | { |
1200 | 0 | #ifdef IEEE8021X_EAPOL |
1201 | 0 | struct eapol_ctx *ctx; |
1202 | 0 | ctx = os_zalloc(sizeof(*ctx)); |
1203 | 0 | if (ctx == NULL) { |
1204 | 0 | wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context."); |
1205 | 0 | return -1; |
1206 | 0 | } |
1207 | | |
1208 | 0 | ctx->ctx = wpa_s; |
1209 | 0 | ctx->msg_ctx = wpa_s; |
1210 | 0 | ctx->eapol_send_ctx = wpa_s; |
1211 | 0 | ctx->preauth = 0; |
1212 | 0 | ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done; |
1213 | 0 | ctx->eapol_send = wpa_supplicant_eapol_send; |
1214 | | #ifdef CONFIG_WEP |
1215 | | ctx->set_wep_key = wpa_eapol_set_wep_key; |
1216 | | #endif /* CONFIG_WEP */ |
1217 | 0 | #ifndef CONFIG_NO_CONFIG_BLOBS |
1218 | 0 | ctx->set_config_blob = wpa_supplicant_set_config_blob; |
1219 | 0 | ctx->get_config_blob = wpa_supplicant_get_config_blob; |
1220 | 0 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
1221 | 0 | ctx->aborted_cached = wpa_supplicant_aborted_cached; |
1222 | 0 | #ifndef CONFIG_OPENSC_ENGINE_PATH |
1223 | 0 | ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path; |
1224 | 0 | #endif /* CONFIG_OPENSC_ENGINE_PATH */ |
1225 | 0 | #ifndef CONFIG_PKCS11_ENGINE_PATH |
1226 | 0 | ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path; |
1227 | 0 | #endif /* CONFIG_PKCS11_ENGINE_PATH */ |
1228 | 0 | #ifndef CONFIG_PKCS11_MODULE_PATH |
1229 | 0 | ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path; |
1230 | 0 | #endif /* CONFIG_PKCS11_MODULE_PATH */ |
1231 | 0 | ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers; |
1232 | 0 | ctx->wps = wpa_s->wps; |
1233 | 0 | ctx->eap_param_needed = wpa_supplicant_eap_param_needed; |
1234 | | #ifdef CONFIG_EAP_PROXY |
1235 | | ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb; |
1236 | | ctx->eap_proxy_notify_sim_status = |
1237 | | wpa_supplicant_eap_proxy_notify_sim_status; |
1238 | | #endif /* CONFIG_EAP_PROXY */ |
1239 | 0 | ctx->port_cb = wpa_supplicant_port_cb; |
1240 | 0 | ctx->cb = wpa_supplicant_eapol_cb; |
1241 | 0 | ctx->cert_cb = wpa_supplicant_cert_cb; |
1242 | 0 | ctx->cert_in_cb = wpa_s->conf->cert_in_cb; |
1243 | 0 | ctx->status_cb = wpa_supplicant_status_cb; |
1244 | 0 | ctx->eap_error_cb = wpa_supplicant_eap_error_cb; |
1245 | 0 | ctx->confirm_auth_cb = wpa_supplicant_eap_auth_start_cb; |
1246 | 0 | ctx->set_anon_id = wpa_supplicant_set_anon_id; |
1247 | 0 | ctx->encryption_required = wpas_encryption_required; |
1248 | 0 | ctx->cb_ctx = wpa_s; |
1249 | 0 | wpa_s->eapol = eapol_sm_init(ctx); |
1250 | 0 | if (wpa_s->eapol == NULL) { |
1251 | 0 | os_free(ctx); |
1252 | 0 | wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state " |
1253 | 0 | "machines."); |
1254 | 0 | return -1; |
1255 | 0 | } |
1256 | 0 | #endif /* IEEE8021X_EAPOL */ |
1257 | | |
1258 | 0 | return 0; |
1259 | 0 | } |
1260 | | |
1261 | | |
1262 | | #ifndef CONFIG_NO_WPA |
1263 | | |
1264 | | static void wpa_supplicant_set_rekey_offload(void *ctx, |
1265 | | const u8 *kek, size_t kek_len, |
1266 | | const u8 *kck, size_t kck_len, |
1267 | | const u8 *replay_ctr) |
1268 | 0 | { |
1269 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1270 | |
|
1271 | 0 | wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr); |
1272 | 0 | } |
1273 | | |
1274 | | |
1275 | | static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk, |
1276 | | size_t pmk_len) |
1277 | 0 | { |
1278 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1279 | |
|
1280 | 0 | if (wpa_s->conf->key_mgmt_offload && |
1281 | 0 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
1282 | 0 | return wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, |
1283 | 0 | NULL, 0, pmk, pmk_len, KEY_FLAG_PMK); |
1284 | 0 | else |
1285 | 0 | return 0; |
1286 | 0 | } |
1287 | | |
1288 | | |
1289 | | static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src, |
1290 | | const u8 *pkt, size_t pkt_len) |
1291 | 0 | { |
1292 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1293 | 0 | char *hex; |
1294 | 0 | size_t hexlen; |
1295 | |
|
1296 | 0 | hexlen = pkt_len * 2 + 1; |
1297 | 0 | hex = os_malloc(hexlen); |
1298 | 0 | if (!hex) |
1299 | 0 | return; |
1300 | 0 | wpa_snprintf_hex(hex, hexlen, pkt, pkt_len); |
1301 | 0 | wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR |
1302 | 0 | " frame=%s", MAC2STR(dst), MAC2STR(src), hex); |
1303 | 0 | os_free(hex); |
1304 | 0 | } |
1305 | | |
1306 | | |
1307 | | static int wpa_supplicant_channel_info(void *_wpa_s, |
1308 | | struct wpa_channel_info *ci) |
1309 | 0 | { |
1310 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
1311 | |
|
1312 | 0 | return wpa_drv_channel_info(wpa_s, ci); |
1313 | 0 | } |
1314 | | |
1315 | | |
1316 | | static void disable_wpa_wpa2(struct wpa_ssid *ssid) |
1317 | 0 | { |
1318 | 0 | ssid->proto &= ~WPA_PROTO_WPA; |
1319 | 0 | ssid->proto |= WPA_PROTO_RSN; |
1320 | 0 | ssid->key_mgmt &= ~(WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK | |
1321 | 0 | WPA_KEY_MGMT_PSK_SHA256); |
1322 | 0 | ssid->group_cipher &= ~WPA_CIPHER_TKIP; |
1323 | 0 | if (!(ssid->group_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
1324 | 0 | WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256))) |
1325 | 0 | ssid->group_cipher |= WPA_CIPHER_CCMP; |
1326 | 0 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
1327 | 0 | } |
1328 | | |
1329 | | |
1330 | | void wpas_transition_disable(struct wpa_supplicant *wpa_s, u8 bitmap) |
1331 | 0 | { |
1332 | 0 | struct wpa_ssid *ssid; |
1333 | 0 | int changed = 0; |
1334 | |
|
1335 | 0 | wpa_msg(wpa_s, MSG_INFO, TRANSITION_DISABLE "%02x", bitmap); |
1336 | |
|
1337 | 0 | ssid = wpa_s->current_ssid; |
1338 | 0 | if (!ssid) |
1339 | 0 | return; |
1340 | | |
1341 | | #ifdef CONFIG_SAE |
1342 | | if ((bitmap & TRANSITION_DISABLE_WPA3_PERSONAL) && |
1343 | | wpa_key_mgmt_sae(wpa_s->key_mgmt) && |
1344 | | wpa_key_mgmt_sae(ssid->key_mgmt) && |
1345 | | (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED || |
1346 | | (ssid->group_cipher & WPA_CIPHER_TKIP))) { |
1347 | | wpa_printf(MSG_DEBUG, |
1348 | | "WPA3-Personal transition mode disabled based on AP notification"); |
1349 | | disable_wpa_wpa2(ssid); |
1350 | | changed = 1; |
1351 | | } |
1352 | | |
1353 | | if ((bitmap & TRANSITION_DISABLE_SAE_PK) && |
1354 | | wpa_key_mgmt_sae(wpa_s->key_mgmt) && |
1355 | | #ifdef CONFIG_SME |
1356 | | wpa_s->sme.sae.state == SAE_ACCEPTED && |
1357 | | wpa_s->sme.sae.pk && |
1358 | | #endif /* CONFIG_SME */ |
1359 | | wpa_key_mgmt_sae(ssid->key_mgmt) && |
1360 | | (ssid->sae_pk != SAE_PK_MODE_ONLY || |
1361 | | ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED || |
1362 | | (ssid->group_cipher & WPA_CIPHER_TKIP))) { |
1363 | | wpa_printf(MSG_DEBUG, |
1364 | | "SAE-PK: SAE authentication without PK disabled based on AP notification"); |
1365 | | disable_wpa_wpa2(ssid); |
1366 | | ssid->sae_pk = SAE_PK_MODE_ONLY; |
1367 | | changed = 1; |
1368 | | } |
1369 | | #endif /* CONFIG_SAE */ |
1370 | | |
1371 | 0 | if ((bitmap & TRANSITION_DISABLE_WPA3_ENTERPRISE) && |
1372 | 0 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) && |
1373 | 0 | (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X | |
1374 | 0 | WPA_KEY_MGMT_FT_IEEE8021X | |
1375 | 0 | WPA_KEY_MGMT_IEEE8021X_SHA256 | |
1376 | 0 | WPA_KEY_MGMT_IEEE8021X_SHA384)) && |
1377 | 0 | (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED || |
1378 | 0 | (ssid->group_cipher & WPA_CIPHER_TKIP))) { |
1379 | 0 | disable_wpa_wpa2(ssid); |
1380 | 0 | changed = 1; |
1381 | 0 | } |
1382 | |
|
1383 | 0 | if ((bitmap & TRANSITION_DISABLE_ENHANCED_OPEN) && |
1384 | 0 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && |
1385 | 0 | (ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
1386 | 0 | !ssid->owe_only) { |
1387 | 0 | ssid->owe_only = 1; |
1388 | 0 | changed = 1; |
1389 | 0 | } |
1390 | |
|
1391 | 0 | if (!changed) |
1392 | 0 | return; |
1393 | | |
1394 | 0 | #ifndef CONFIG_NO_CONFIG_WRITE |
1395 | 0 | if (wpa_s->conf->update_config && |
1396 | 0 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
1397 | 0 | wpa_printf(MSG_DEBUG, "Failed to update configuration"); |
1398 | 0 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
1399 | 0 | } |
1400 | | |
1401 | | |
1402 | | static void wpa_supplicant_transition_disable(void *_wpa_s, u8 bitmap) |
1403 | 0 | { |
1404 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
1405 | 0 | wpas_transition_disable(wpa_s, bitmap); |
1406 | 0 | } |
1407 | | |
1408 | | |
1409 | | static void wpa_supplicant_store_ptk(void *ctx, const u8 *addr, int cipher, |
1410 | | u32 life_time, const struct wpa_ptk *ptk) |
1411 | 0 | { |
1412 | 0 | struct wpa_supplicant *wpa_s = ctx; |
1413 | |
|
1414 | 0 | ptksa_cache_add(wpa_s->ptksa, wpa_s->own_addr, addr, cipher, life_time, |
1415 | 0 | ptk, NULL, NULL, 0); |
1416 | 0 | } |
1417 | | |
1418 | | |
1419 | | #ifdef CONFIG_PASN |
1420 | | static int wpa_supplicant_set_ltf_keyseed(void *_wpa_s, const u8 *own_addr, |
1421 | | const u8 *peer_addr, |
1422 | | size_t ltf_keyseed_len, |
1423 | | const u8 *ltf_keyseed) |
1424 | | { |
1425 | | struct wpa_supplicant *wpa_s = _wpa_s; |
1426 | | |
1427 | | return wpa_drv_set_secure_ranging_ctx(wpa_s, own_addr, peer_addr, 0, 0, |
1428 | | NULL, ltf_keyseed_len, |
1429 | | ltf_keyseed, 0); |
1430 | | } |
1431 | | #endif /* CONFIG_PASN */ |
1432 | | |
1433 | | |
1434 | | static void |
1435 | | wpa_supplicant_notify_pmksa_cache_entry(void *_wpa_s, |
1436 | | struct rsn_pmksa_cache_entry *entry) |
1437 | 0 | { |
1438 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
1439 | |
|
1440 | 0 | wpas_notify_pmk_cache_added(wpa_s, entry); |
1441 | 0 | } |
1442 | | |
1443 | | |
1444 | | static void wpa_supplicant_ssid_verified(void *_wpa_s) |
1445 | 0 | { |
1446 | 0 | struct wpa_supplicant *wpa_s = _wpa_s; |
1447 | |
|
1448 | 0 | wpa_s->ssid_verified = true; |
1449 | 0 | wpa_msg(wpa_s, MSG_INFO, "RSN: SSID matched expected value"); |
1450 | 0 | } |
1451 | | |
1452 | | #endif /* CONFIG_NO_WPA */ |
1453 | | |
1454 | | |
1455 | | int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s) |
1456 | 0 | { |
1457 | 0 | #ifndef CONFIG_NO_WPA |
1458 | 0 | struct wpa_sm_ctx *ctx; |
1459 | |
|
1460 | 0 | wpa_s->ptksa = ptksa_cache_init(); |
1461 | 0 | if (!wpa_s->ptksa) { |
1462 | 0 | wpa_printf(MSG_ERROR, "Failed to allocate PTKSA"); |
1463 | 0 | return -1; |
1464 | 0 | } |
1465 | | |
1466 | 0 | ctx = os_zalloc(sizeof(*ctx)); |
1467 | 0 | if (ctx == NULL) { |
1468 | 0 | wpa_printf(MSG_ERROR, "Failed to allocate WPA context."); |
1469 | |
|
1470 | 0 | ptksa_cache_deinit(wpa_s->ptksa); |
1471 | 0 | wpa_s->ptksa = NULL; |
1472 | |
|
1473 | 0 | return -1; |
1474 | 0 | } |
1475 | | |
1476 | 0 | ctx->ctx = wpa_s; |
1477 | 0 | ctx->msg_ctx = wpa_s; |
1478 | 0 | ctx->set_state = _wpa_supplicant_set_state; |
1479 | 0 | ctx->get_state = _wpa_supplicant_get_state; |
1480 | 0 | ctx->deauthenticate = _wpa_supplicant_deauthenticate; |
1481 | 0 | ctx->reconnect = _wpa_supplicant_reconnect; |
1482 | 0 | ctx->set_key = wpa_supplicant_set_key; |
1483 | 0 | ctx->get_network_ctx = wpa_supplicant_get_network_ctx; |
1484 | 0 | ctx->get_bssid = wpa_supplicant_get_bssid; |
1485 | 0 | ctx->ether_send = _wpa_ether_send; |
1486 | 0 | ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie; |
1487 | 0 | ctx->alloc_eapol = _wpa_alloc_eapol; |
1488 | 0 | ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout; |
1489 | 0 | ctx->add_pmkid = wpa_supplicant_add_pmkid; |
1490 | 0 | ctx->remove_pmkid = wpa_supplicant_remove_pmkid; |
1491 | 0 | #ifndef CONFIG_NO_CONFIG_BLOBS |
1492 | 0 | ctx->set_config_blob = wpa_supplicant_set_config_blob; |
1493 | 0 | ctx->get_config_blob = wpa_supplicant_get_config_blob; |
1494 | 0 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
1495 | 0 | ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection; |
1496 | | #ifdef CONFIG_IEEE80211R |
1497 | | ctx->update_ft_ies = wpa_supplicant_update_ft_ies; |
1498 | | ctx->send_ft_action = wpa_supplicant_send_ft_action; |
1499 | | ctx->mark_authenticated = wpa_supplicant_mark_authenticated; |
1500 | | #endif /* CONFIG_IEEE80211R */ |
1501 | | #ifdef CONFIG_TDLS |
1502 | | ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa; |
1503 | | ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt; |
1504 | | ctx->tdls_oper = wpa_supplicant_tdls_oper; |
1505 | | ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset; |
1506 | | ctx->tdls_enable_channel_switch = |
1507 | | wpa_supplicant_tdls_enable_channel_switch; |
1508 | | ctx->tdls_disable_channel_switch = |
1509 | | wpa_supplicant_tdls_disable_channel_switch; |
1510 | | #endif /* CONFIG_TDLS */ |
1511 | 0 | ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload; |
1512 | 0 | ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk; |
1513 | 0 | ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx; |
1514 | 0 | ctx->channel_info = wpa_supplicant_channel_info; |
1515 | 0 | ctx->transition_disable = wpa_supplicant_transition_disable; |
1516 | 0 | ctx->store_ptk = wpa_supplicant_store_ptk; |
1517 | | #ifdef CONFIG_PASN |
1518 | | ctx->set_ltf_keyseed = wpa_supplicant_set_ltf_keyseed; |
1519 | | #endif /* CONFIG_PASN */ |
1520 | 0 | ctx->notify_pmksa_cache_entry = wpa_supplicant_notify_pmksa_cache_entry; |
1521 | 0 | ctx->ssid_verified = wpa_supplicant_ssid_verified; |
1522 | |
|
1523 | 0 | wpa_s->wpa = wpa_sm_init(ctx); |
1524 | 0 | if (wpa_s->wpa == NULL) { |
1525 | 0 | wpa_printf(MSG_ERROR, |
1526 | 0 | "Failed to initialize WPA state machine"); |
1527 | 0 | os_free(ctx); |
1528 | 0 | ptksa_cache_deinit(wpa_s->ptksa); |
1529 | 0 | wpa_s->ptksa = NULL; |
1530 | 0 | return -1; |
1531 | 0 | } |
1532 | 0 | #endif /* CONFIG_NO_WPA */ |
1533 | | |
1534 | 0 | return 0; |
1535 | 0 | } |
1536 | | |
1537 | | |
1538 | | void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s, |
1539 | | struct wpa_ssid *ssid) |
1540 | 0 | { |
1541 | 0 | struct rsn_supp_config conf; |
1542 | 0 | if (ssid) { |
1543 | 0 | os_memset(&conf, 0, sizeof(conf)); |
1544 | 0 | conf.network_ctx = ssid; |
1545 | 0 | conf.allowed_pairwise_cipher = ssid->pairwise_cipher; |
1546 | 0 | #ifdef IEEE8021X_EAPOL |
1547 | 0 | conf.proactive_key_caching = ssid->proactive_key_caching < 0 ? |
1548 | 0 | wpa_s->conf->okc : ssid->proactive_key_caching; |
1549 | 0 | conf.eap_workaround = ssid->eap_workaround; |
1550 | 0 | conf.eap_conf_ctx = &ssid->eap; |
1551 | 0 | #endif /* IEEE8021X_EAPOL */ |
1552 | 0 | conf.ssid = ssid->ssid; |
1553 | 0 | conf.ssid_len = ssid->ssid_len; |
1554 | 0 | conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey; |
1555 | 0 | conf.wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey; |
1556 | 0 | conf.owe_ptk_workaround = ssid->owe_ptk_workaround; |
1557 | | #ifdef CONFIG_P2P |
1558 | | if (ssid->p2p_group && wpa_s->current_bss && |
1559 | | !wpa_s->p2p_disable_ip_addr_req) { |
1560 | | struct wpabuf *p2p; |
1561 | | p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss, |
1562 | | P2P_IE_VENDOR_TYPE); |
1563 | | if (p2p) { |
1564 | | u8 group_capab; |
1565 | | group_capab = p2p_get_group_capab(p2p); |
1566 | | if (group_capab & |
1567 | | P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION) |
1568 | | conf.p2p = 1; |
1569 | | wpabuf_free(p2p); |
1570 | | } |
1571 | | } |
1572 | | #endif /* CONFIG_P2P */ |
1573 | 0 | conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation; |
1574 | | #ifdef CONFIG_FILS |
1575 | | if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) |
1576 | | conf.fils_cache_id = |
1577 | | wpa_bss_get_fils_cache_id(wpa_s->current_bss); |
1578 | | #endif /* CONFIG_FILS */ |
1579 | 0 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) || |
1580 | 0 | (wpa_s->drv_flags2 & |
1581 | 0 | WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT)) |
1582 | 0 | conf.beacon_prot = ssid->beacon_prot; |
1583 | |
|
1584 | | #ifdef CONFIG_PASN |
1585 | | #ifdef CONFIG_TESTING_OPTIONS |
1586 | | conf.force_kdk_derivation = wpa_s->conf->force_kdk_derivation; |
1587 | | #endif /* CONFIG_TESTING_OPTIONS */ |
1588 | | #endif /* CONFIG_PASN */ |
1589 | 0 | } |
1590 | 0 | wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL); |
1591 | 0 | } |