blob: e13ea8f61cf9788ac5ba6a7e6251ca562b220f78 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Glue code to setup EAPOL and RSN modules
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080013#include "eap_peer/eap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#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"
Hai Shalom60840252021-02-19 19:02:11 -080019#include "common/ptksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "wpa_supplicant_i.h"
21#include "driver_i.h"
22#include "rsn_supp/pmksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#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"
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070030#include "notify.h"
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -070031#include "wpas_kay.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032
33
34#ifndef CONFIG_NO_CONFIG_BLOBS
35#if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
36static void wpa_supplicant_set_config_blob(void *ctx,
37 struct wpa_config_blob *blob)
38{
39 struct wpa_supplicant *wpa_s = ctx;
40 wpa_config_set_blob(wpa_s->conf, blob);
41 if (wpa_s->conf->update_config) {
42 int ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
43 if (ret) {
44 wpa_printf(MSG_DEBUG, "Failed to update config after "
45 "blob set");
46 }
47 }
48}
49
50
51static const struct wpa_config_blob *
52wpa_supplicant_get_config_blob(void *ctx, const char *name)
53{
54 struct wpa_supplicant *wpa_s = ctx;
55 return wpa_config_get_blob(wpa_s->conf, name);
56}
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)
62static 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{
66 struct ieee802_1x_hdr *hdr;
67
68 *msg_len = sizeof(*hdr) + data_len;
69 hdr = os_malloc(*msg_len);
70 if (hdr == NULL)
71 return NULL;
72
73 hdr->version = wpa_s->conf->eapol_version;
74 hdr->type = type;
75 hdr->length = host_to_be16(data_len);
76
77 if (data)
78 os_memcpy(hdr + 1, data, data_len);
79 else
80 os_memset(hdr + 1, 0, data_len);
81
82 if (data_pos)
83 *data_pos = hdr + 1;
84
85 return (u8 *) hdr;
86}
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 */
Hai Shalomc1a21442022-02-04 13:43:00 -080098int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
99 u16 proto, const u8 *buf, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800101#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
Hai Shalomfdcde762020-04-02 11:19:20 -0700116 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_CONTROL_PORT) {
117 int encrypt = wpa_s->wpa &&
118 wpa_sm_has_ptk_installed(wpa_s->wpa);
119
120 return wpa_drv_tx_control_port(wpa_s, dest, proto, buf, len,
121 !encrypt);
122 }
123
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700124 if (wpa_s->l2) {
125 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
126 }
127
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800128 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700129}
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 */
146static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
147 size_t len)
148{
149 struct wpa_supplicant *wpa_s = ctx;
150 u8 *msg, *dst, bssid[ETH_ALEN];
151 size_t msglen;
152 int res;
153
154 /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
155 * extra copy here */
156
157 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700158 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
159 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160 wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
161 /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
162 * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
163 * machines. */
164 wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
165 "mode (type=%d len=%lu)", type,
166 (unsigned long) len);
167 return -1;
168 }
169
170 if (pmksa_cache_get_current(wpa_s->wpa) &&
171 type == IEEE802_1X_TYPE_EAPOL_START) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700172 /*
173 * We were trying to use PMKSA caching and sending EAPOL-Start
174 * would abort that and trigger full EAPOL authentication.
175 * However, we've already waited for the AP/Authenticator to
176 * start 4-way handshake or EAP authentication, and apparently
177 * it has not done so since the startWhen timer has reached zero
178 * to get the state machine sending EAPOL-Start. This is not
179 * really supposed to happen, but an interoperability issue with
180 * a deployed AP has been identified where the connection fails
181 * due to that AP failing to operate correctly if PMKID is
182 * included in the Association Request frame. To work around
183 * this, assume PMKSA caching failed and try to initiate full
184 * EAP authentication.
185 */
186 if (!wpa_s->current_ssid ||
187 wpa_s->current_ssid->eap_workaround) {
188 wpa_printf(MSG_DEBUG,
189 "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");
190 } else {
191 wpa_printf(MSG_DEBUG,
192 "RSN: PMKSA caching - do not send EAPOL-Start");
193 return -1;
194 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195 }
196
197 if (is_zero_ether_addr(wpa_s->bssid)) {
198 wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
199 "EAPOL frame");
200 if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
201 !is_zero_ether_addr(bssid)) {
202 dst = bssid;
203 wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
204 " from the driver as the EAPOL destination",
205 MAC2STR(dst));
206 } else {
207 dst = wpa_s->last_eapol_src;
208 wpa_printf(MSG_DEBUG, "Using the source address of the"
209 " last received EAPOL frame " MACSTR " as "
210 "the EAPOL destination",
211 MAC2STR(dst));
212 }
213 } else {
214 /* BSSID was already set (from (Re)Assoc event, so use it as
215 * the EAPOL destination. */
216 dst = wpa_s->bssid;
217 }
218
219 msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
220 if (msg == NULL)
221 return -1;
222
223 wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
224 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
225 res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
226 os_free(msg);
227 return res;
228}
229
230
Hai Shalomfdcde762020-04-02 11:19:20 -0700231#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232/**
233 * wpa_eapol_set_wep_key - set WEP key for the driver
234 * @ctx: Pointer to wpa_supplicant data (wpa_s)
235 * @unicast: 1 = individual unicast key, 0 = broadcast key
236 * @keyidx: WEP key index (0..3)
237 * @key: Pointer to key data
238 * @keylen: Key length in bytes
239 * Returns: 0 on success or < 0 on error.
240 */
241static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
242 const u8 *key, size_t keylen)
243{
244 struct wpa_supplicant *wpa_s = ctx;
245 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
246 int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
247 WPA_CIPHER_WEP104;
248 if (unicast)
249 wpa_s->pairwise_cipher = cipher;
250 else
251 wpa_s->group_cipher = cipher;
252 }
253 return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
254 unicast ? wpa_s->bssid : NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -0700255 keyidx, unicast, NULL, 0, key, keylen,
256 unicast ? KEY_FLAG_PAIRWISE_RX_TX :
257 KEY_FLAG_GROUP_RX_TX_DEFAULT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258}
Hai Shalomfdcde762020-04-02 11:19:20 -0700259#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260
261
262static void wpa_supplicant_aborted_cached(void *ctx)
263{
264 struct wpa_supplicant *wpa_s = ctx;
265 wpa_sm_aborted_cached(wpa_s->wpa);
266}
267
268
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800269static const char * result_str(enum eapol_supp_result result)
270{
271 switch (result) {
272 case EAPOL_SUPP_RESULT_FAILURE:
273 return "FAILURE";
274 case EAPOL_SUPP_RESULT_SUCCESS:
275 return "SUCCESS";
276 case EAPOL_SUPP_RESULT_EXPECTED_FAILURE:
277 return "EXPECTED_FAILURE";
278 }
279 return "?";
280}
281
282
283static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol,
284 enum eapol_supp_result result,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 void *ctx)
286{
287 struct wpa_supplicant *wpa_s = ctx;
288 int res, pmk_len;
Vinayak Yadawadf49b1692022-06-16 16:39:46 +0530289 u8 pmk[PMK_LEN_MAX];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800291 wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
292 result_str(result));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293
294 if (wpas_wps_eapol_cb(wpa_s) > 0)
295 return;
296
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800297 wpa_s->eap_expected_failure = result ==
298 EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
299
300 if (result != EAPOL_SUPP_RESULT_SUCCESS) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700301 int timeout = 2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 /*
303 * Make sure we do not get stuck here waiting for long EAPOL
304 * timeout if the AP does not disconnect in case of
305 * authentication failure.
306 */
Sunil Ravia04bd252022-05-02 22:54:18 -0700307 if (wpa_s->eapol_failed) {
308 wpa_printf(MSG_DEBUG,
309 "EAPOL authentication failed again and AP did not disconnect us");
310 timeout = 0;
311 }
312 wpa_s->eapol_failed = 1;
313 wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700314 } else {
Sunil Ravia04bd252022-05-02 22:54:18 -0700315 wpa_s->eapol_failed = 0;
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700316 ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317 }
318
Andy Kuoaba17c12022-04-14 16:05:31 +0800319#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +0530320 if (result != EAPOL_SUPP_RESULT_SUCCESS)
321#else
322 if (result != EAPOL_SUPP_RESULT_SUCCESS ||
323 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X))
Andy Kuoaba17c12022-04-14 16:05:31 +0800324#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Mir Alieaaf04e2021-06-07 12:17:29 +0530325 return;
326
Andy Kuoaba17c12022-04-14 16:05:31 +0800327#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Alieaaf04e2021-06-07 12:17:29 +0530328 if (wpa_ft_is_ft_protocol(wpa_s->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 return;
Mir Alieaaf04e2021-06-07 12:17:29 +0530330 }
Andy Kuoaba17c12022-04-14 16:05:31 +0800331#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332
333 if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
334 return;
335
336 wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
337 "handshake");
338
Vinayak Yadawadf49b1692022-06-16 16:39:46 +0530339 if (wpa_key_mgmt_sha384(wpa_s->key_mgmt))
340 pmk_len = PMK_LEN_SUITE_B_192;
341 else
342 pmk_len = PMK_LEN;
343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344 if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
345#ifdef CONFIG_IEEE80211R
346 u8 buf[2 * PMK_LEN];
347 wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
348 "driver-based 4-way hs and FT");
349 res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
350 if (res == 0) {
351 os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
352 os_memset(buf, 0, sizeof(buf));
353 }
354#else /* CONFIG_IEEE80211R */
355 res = -1;
356#endif /* CONFIG_IEEE80211R */
357 } else {
Vinayak Yadawadf49b1692022-06-16 16:39:46 +0530358 res = eapol_sm_get_key(eapol, pmk, pmk_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 if (res) {
360 /*
361 * EAP-LEAP is an exception from other EAP methods: it
362 * uses only 16-byte PMK.
363 */
364 res = eapol_sm_get_key(eapol, pmk, 16);
365 pmk_len = 16;
366 }
367 }
368
369 if (res) {
370 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
371 "machines");
372 return;
373 }
374
375 wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
376 "handshake", pmk, pmk_len);
377
Hai Shalomfdcde762020-04-02 11:19:20 -0700378 if (wpa_drv_set_key(wpa_s, 0, NULL, 0, 0, NULL, 0, pmk,
379 pmk_len, KEY_FLAG_PMK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
381 }
382
383 wpa_supplicant_cancel_scan(wpa_s);
384 wpa_supplicant_cancel_auth_timeout(wpa_s);
385 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
386
387}
388
389
390static void wpa_supplicant_notify_eapol_done(void *ctx)
391{
392 struct wpa_supplicant *wpa_s = ctx;
393 wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
394 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
395 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
396 } else {
397 wpa_supplicant_cancel_auth_timeout(wpa_s);
398 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
399 }
400}
401
402#endif /* IEEE8021X_EAPOL */
403
404
405#ifndef CONFIG_NO_WPA
406
407static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
408{
409 int ret = 0;
410 struct wpa_bss *curr = NULL, *bss;
411 struct wpa_ssid *ssid = wpa_s->current_ssid;
412 const u8 *ie;
413
414 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
415 if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
416 continue;
417 if (ssid == NULL ||
418 ((bss->ssid_len == ssid->ssid_len &&
419 os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
420 ssid->ssid_len == 0)) {
421 curr = bss;
422 break;
423 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700424#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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 }
432
433 if (curr) {
434 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
435 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
436 ret = -1;
437
438 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
439 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
440 ret = -1;
Hai Shalomc3565922019-10-28 11:58:20 -0700441
442 ie = wpa_bss_get_ie(curr, WLAN_EID_RSNX);
443 if (wpa_sm_set_ap_rsnxe(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
444 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 } else {
446 ret = -1;
447 }
448
449 return ret;
450}
451
452
453static int wpa_supplicant_get_beacon_ie(void *ctx)
454{
455 struct wpa_supplicant *wpa_s = ctx;
456 if (wpa_get_beacon_ie(wpa_s) == 0) {
457 return 0;
458 }
459
460 /* No WPA/RSN IE found in the cached scan results. Try to get updated
461 * scan results from the driver. */
462 if (wpa_supplicant_update_scan_results(wpa_s) < 0)
463 return -1;
464
465 return wpa_get_beacon_ie(wpa_s);
466}
467
468
469static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
470 const void *data, u16 data_len,
471 size_t *msg_len, void **data_pos)
472{
473 return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
474}
475
476
477static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
478 const u8 *buf, size_t len)
479{
480 return wpa_ether_send(wpa_s, dest, proto, buf, len);
481}
482
483
484static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
485{
486 wpa_supplicant_cancel_auth_timeout(wpa_s);
487}
488
489
490static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
491{
492 wpa_supplicant_set_state(wpa_s, state);
493}
494
495
496/**
497 * wpa_supplicant_get_state - Get the connection state
498 * @wpa_s: Pointer to wpa_supplicant data
499 * Returns: The current connection state (WPA_*)
500 */
501static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
502{
503 return wpa_s->wpa_state;
504}
505
506
507static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
508{
509 return wpa_supplicant_get_state(wpa_s);
510}
511
512
Hai Shalom81f62d82019-07-22 12:10:00 -0700513static void _wpa_supplicant_deauthenticate(void *wpa_s, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514{
515 wpa_supplicant_deauthenticate(wpa_s, reason_code);
516 /* Schedule a scan to make sure we continue looking for networks */
517 wpa_supplicant_req_scan(wpa_s, 5, 0);
518}
519
520
Hai Shalomfdcde762020-04-02 11:19:20 -0700521static void _wpa_supplicant_reconnect(void *wpa_s)
522{
523 wpa_supplicant_reconnect(wpa_s);
524}
525
526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527static void * wpa_supplicant_get_network_ctx(void *wpa_s)
528{
529 return wpa_supplicant_get_ssid(wpa_s);
530}
531
532
533static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
534{
535 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 return wpa_drv_get_bssid(wpa_s, bssid);
537}
538
539
540static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
541 const u8 *addr, int key_idx, int set_tx,
542 const u8 *seq, size_t seq_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700543 const u8 *key, size_t key_len,
544 enum key_flag key_flag)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545{
546 struct wpa_supplicant *wpa_s = _wpa_s;
547 if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
548 /* Clear the MIC error counter when setting a new PTK. */
549 wpa_s->mic_errors_seen = 0;
550 }
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700551#ifdef CONFIG_TESTING_GET_GTK
552 if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
553 alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
554 os_memcpy(wpa_s->last_gtk, key, key_len);
555 wpa_s->last_gtk_len = key_len;
556 }
557#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700558#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -0700559 if (addr && !is_broadcast_ether_addr(addr) &&
560 !(key_flag & KEY_FLAG_MODIFY)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700561 wpa_s->last_tk_alg = alg;
562 os_memcpy(wpa_s->last_tk_addr, addr, ETH_ALEN);
563 wpa_s->last_tk_key_idx = key_idx;
564 if (key)
565 os_memcpy(wpa_s->last_tk, key, key_len);
566 wpa_s->last_tk_len = key_len;
567 }
568#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569 return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700570 key, key_len, key_flag);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700571}
572
573
574static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
575 int protection_type,
576 int key_type)
577{
578 return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
579 key_type);
580}
581
582
Dmitry Shmidt29333592017-01-09 12:27:11 -0800583static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s,
584 void *network_ctx)
585{
586 struct wpa_ssid *ssid;
587
588 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
589 if (network_ctx == ssid)
590 return ssid;
591 }
592
593 return NULL;
594}
595
596
597static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700598 const u8 *bssid, const u8 *pmkid,
599 const u8 *fils_cache_id,
Hai Shalomfdcde762020-04-02 11:19:20 -0700600 const u8 *pmk, size_t pmk_len,
Hai Shalom899fcc72020-10-19 14:38:18 -0700601 u32 pmk_lifetime, u8 pmk_reauth_threshold,
602 int akmp)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800604 struct wpa_supplicant *wpa_s = _wpa_s;
605 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700606 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800607
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700608 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800609 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
Hai Shalom899fcc72020-10-19 14:38:18 -0700610 if (ssid) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800611 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
612 MAC2STR(bssid), ssid->id);
Hai Shalom899fcc72020-10-19 14:38:18 -0700613 if ((akmp == WPA_KEY_MGMT_FT_IEEE8021X ||
614 akmp == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) &&
615 !ssid->ft_eap_pmksa_caching) {
616 /* Since we will not be using PMKSA caching for FT-EAP
617 * within wpa_supplicant to avoid known interop issues
618 * with APs, do not add this PMKID to the driver either
619 * so that we won't be hitting those interop issues
620 * with driver-based RSNE generation. */
621 wpa_printf(MSG_DEBUG,
622 "FT: Do not add PMKID entry to the driver since FT-EAP PMKSA caching is not enabled in configuration");
623 return 0;
624 }
625 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700626 if (ssid && fils_cache_id) {
627 params.ssid = ssid->ssid;
628 params.ssid_len = ssid->ssid_len;
629 params.fils_cache_id = fils_cache_id;
630 } else {
631 params.bssid = bssid;
632 }
633
634 params.pmkid = pmkid;
635 params.pmk = pmk;
636 params.pmk_len = pmk_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700637 params.pmk_lifetime = pmk_lifetime;
638 params.pmk_reauth_threshold = pmk_reauth_threshold;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700639
640 return wpa_drv_add_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641}
642
643
Dmitry Shmidt29333592017-01-09 12:27:11 -0800644static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700645 const u8 *bssid, const u8 *pmkid,
646 const u8 *fils_cache_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800648 struct wpa_supplicant *wpa_s = _wpa_s;
649 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700650 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800651
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700652 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800653 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
654 if (ssid)
655 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
656 MAC2STR(bssid), ssid->id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700657 if (ssid && fils_cache_id) {
658 params.ssid = ssid->ssid;
659 params.ssid_len = ssid->ssid_len;
660 params.fils_cache_id = fils_cache_id;
661 } else {
662 params.bssid = bssid;
663 }
664
665 params.pmkid = pmkid;
666
667 return wpa_drv_remove_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668}
669
670
671#ifdef CONFIG_IEEE80211R
672static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
673 const u8 *ies, size_t ies_len)
674{
675 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
677 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
678 return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
679}
680
681
682static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
683 const u8 *target_ap,
684 const u8 *ies, size_t ies_len)
685{
686 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800687 int ret;
688 u8 *data, *pos;
689 size_t data_len;
690
691 if (action != 1) {
692 wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
693 action);
694 return -1;
695 }
696
697 /*
698 * Action frame payload:
699 * Category[1] = 6 (Fast BSS Transition)
700 * Action[1] = 1 (Fast BSS Transition Request)
701 * STA Address
702 * Target AP Address
703 * FT IEs
704 */
705
706 data_len = 2 + 2 * ETH_ALEN + ies_len;
707 data = os_malloc(data_len);
708 if (data == NULL)
709 return -1;
710 pos = data;
711 *pos++ = 0x06; /* FT Action category */
712 *pos++ = action;
713 os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
714 pos += ETH_ALEN;
715 os_memcpy(pos, target_ap, ETH_ALEN);
716 pos += ETH_ALEN;
717 os_memcpy(pos, ies, ies_len);
718
719 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
720 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
721 data, data_len, 0);
722 os_free(data);
723
724 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725}
726
727
728static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
729{
730 struct wpa_supplicant *wpa_s = ctx;
731 struct wpa_driver_auth_params params;
732 struct wpa_bss *bss;
733
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 bss = wpa_bss_get_bssid(wpa_s, target_ap);
735 if (bss == NULL)
736 return -1;
737
738 os_memset(&params, 0, sizeof(params));
739 params.bssid = target_ap;
740 params.freq = bss->freq;
741 params.ssid = bss->ssid;
742 params.ssid_len = bss->ssid_len;
743 params.auth_alg = WPA_AUTH_ALG_FT;
744 params.local_state_change = 1;
745 return wpa_drv_authenticate(wpa_s, &params);
746}
747#endif /* CONFIG_IEEE80211R */
748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749
750#ifdef CONFIG_TDLS
751
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800752static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800753 int *tdls_ext_setup,
754 int *tdls_chan_switch)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800755{
756 struct wpa_supplicant *wpa_s = ctx;
757
758 *tdls_supported = 0;
759 *tdls_ext_setup = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800760 *tdls_chan_switch = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761
762 if (!wpa_s->drv_capa_known)
763 return -1;
764
765 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
766 *tdls_supported = 1;
767
768 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
769 *tdls_ext_setup = 1;
770
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800771 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
772 *tdls_chan_switch = 1;
773
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800774 return 0;
775}
776
777
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
779 u8 action_code, u8 dialog_token,
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700780 u16 status_code, u32 peer_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700781 int initiator, const u8 *buf,
782 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783{
784 struct wpa_supplicant *wpa_s = ctx;
785 return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700786 status_code, peer_capab, initiator, buf,
787 len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788}
789
790
791static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
792{
793 struct wpa_supplicant *wpa_s = ctx;
794 return wpa_drv_tdls_oper(wpa_s, oper, peer);
795}
796
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800797
798static int wpa_supplicant_tdls_peer_addset(
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700799 void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800800 const u8 *supp_rates, size_t supp_rates_len,
801 const struct ieee80211_ht_capabilities *ht_capab,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800802 const struct ieee80211_vht_capabilities *vht_capab,
Hai Shalomc1a21442022-02-04 13:43:00 -0800803 const struct ieee80211_he_capabilities *he_capab,
804 size_t he_capab_len,
805 const struct ieee80211_he_6ghz_band_cap *he_6ghz_he_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700806 u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800807 const u8 *supp_channels, size_t supp_channels_len,
808 const u8 *supp_oper_classes, size_t supp_oper_classes_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809{
810 struct wpa_supplicant *wpa_s = ctx;
811 struct hostapd_sta_add_params params;
812
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800813 os_memset(&params, 0, sizeof(params));
814
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800815 params.addr = peer;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700816 params.aid = aid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800817 params.capability = capability;
818 params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800819
820 /*
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700821 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
822 * present. Allow the WMM IE to also indicate QoS support.
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800823 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700824 if (wmm || qosinfo)
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800825 params.flags |= WPA_STA_WMM;
826
827 params.ht_capabilities = ht_capab;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800828 params.vht_capabilities = vht_capab;
Hai Shalomc1a21442022-02-04 13:43:00 -0800829 params.he_capab = he_capab;
830 params.he_capab_len = he_capab_len;
831 params.he_6ghz_capab = he_6ghz_he_capab;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800832 params.qosinfo = qosinfo;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800833 params.listen_interval = 0;
834 params.supp_rates = supp_rates;
835 params.supp_rates_len = supp_rates_len;
836 params.set = !add;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800837 params.ext_capab = ext_capab;
838 params.ext_capab_len = ext_capab_len;
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800839 params.supp_channels = supp_channels;
840 params.supp_channels_len = supp_channels_len;
841 params.supp_oper_classes = supp_oper_classes;
842 params.supp_oper_classes_len = supp_oper_classes_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800843
844 return wpa_drv_sta_add(wpa_s, &params);
845}
846
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800847
848static int wpa_supplicant_tdls_enable_channel_switch(
849 void *ctx, const u8 *addr, u8 oper_class,
850 const struct hostapd_freq_params *params)
851{
852 struct wpa_supplicant *wpa_s = ctx;
853
854 return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
855 params);
856}
857
858
859static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
860{
861 struct wpa_supplicant *wpa_s = ctx;
862
863 return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
864}
865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866#endif /* CONFIG_TDLS */
867
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700868#endif /* CONFIG_NO_WPA */
869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800871enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
872{
873 if (os_strcmp(field, "IDENTITY") == 0)
874 return WPA_CTRL_REQ_EAP_IDENTITY;
875 else if (os_strcmp(field, "PASSWORD") == 0)
876 return WPA_CTRL_REQ_EAP_PASSWORD;
877 else if (os_strcmp(field, "NEW_PASSWORD") == 0)
878 return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
879 else if (os_strcmp(field, "PIN") == 0)
880 return WPA_CTRL_REQ_EAP_PIN;
881 else if (os_strcmp(field, "OTP") == 0)
882 return WPA_CTRL_REQ_EAP_OTP;
883 else if (os_strcmp(field, "PASSPHRASE") == 0)
884 return WPA_CTRL_REQ_EAP_PASSPHRASE;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700885 else if (os_strcmp(field, "SIM") == 0)
886 return WPA_CTRL_REQ_SIM;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700887 else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
888 return WPA_CTRL_REQ_PSK_PASSPHRASE;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800889 else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
890 return WPA_CTRL_REQ_EXT_CERT_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800891 return WPA_CTRL_REQ_UNKNOWN;
892}
893
894
895const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
896 const char *default_txt,
897 const char **txt)
898{
899 const char *ret = NULL;
900
901 *txt = default_txt;
902
903 switch (field) {
904 case WPA_CTRL_REQ_EAP_IDENTITY:
905 *txt = "Identity";
906 ret = "IDENTITY";
907 break;
908 case WPA_CTRL_REQ_EAP_PASSWORD:
909 *txt = "Password";
910 ret = "PASSWORD";
911 break;
912 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
913 *txt = "New Password";
914 ret = "NEW_PASSWORD";
915 break;
916 case WPA_CTRL_REQ_EAP_PIN:
917 *txt = "PIN";
918 ret = "PIN";
919 break;
920 case WPA_CTRL_REQ_EAP_OTP:
921 ret = "OTP";
922 break;
923 case WPA_CTRL_REQ_EAP_PASSPHRASE:
924 *txt = "Private key passphrase";
925 ret = "PASSPHRASE";
926 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700927 case WPA_CTRL_REQ_SIM:
928 ret = "SIM";
929 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700930 case WPA_CTRL_REQ_PSK_PASSPHRASE:
931 *txt = "PSK or passphrase";
932 ret = "PSK_PASSPHRASE";
933 break;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800934 case WPA_CTRL_REQ_EXT_CERT_CHECK:
935 *txt = "External server certificate validation";
936 ret = "EXT_CERT_CHECK";
937 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800938 default:
939 break;
940 }
941
942 /* txt needs to be something */
943 if (*txt == NULL) {
944 wpa_printf(MSG_WARNING, "No message for request %d", field);
945 ret = NULL;
946 }
947
948 return ret;
949}
950
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700951
952void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
953 const char *field_name, const char *txt)
954{
955 char *buf;
956 size_t buflen;
957 int len;
958
959 buflen = 100 + os_strlen(txt) + ssid->ssid_len;
960 buf = os_malloc(buflen);
961 if (buf == NULL)
962 return;
963 len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
964 field_name, ssid->id, txt);
965 if (os_snprintf_error(buflen, len)) {
966 os_free(buf);
967 return;
968 }
969 if (ssid->ssid && buflen > len + ssid->ssid_len) {
970 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
971 len += ssid->ssid_len;
972 buf[len] = '\0';
973 }
974 buf[buflen - 1] = '\0';
975 wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
976 os_free(buf);
977}
978
979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980#ifdef IEEE8021X_EAPOL
981#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800982static void wpa_supplicant_eap_param_needed(void *ctx,
983 enum wpa_ctrl_req_type field,
984 const char *default_txt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985{
986 struct wpa_supplicant *wpa_s = ctx;
987 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800988 const char *field_name, *txt = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989
990 if (ssid == NULL)
991 return;
992
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800993 if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
994 ssid->eap.pending_ext_cert_check = PENDING_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 wpas_notify_network_request(wpa_s, ssid, field, default_txt);
996
997 field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
998 &txt);
999 if (field_name == NULL) {
1000 wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
1001 field);
1002 return;
1003 }
1004
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001005 wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
1006
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001007 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008}
1009#else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1010#define wpa_supplicant_eap_param_needed NULL
1011#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1012
1013
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001014#ifdef CONFIG_EAP_PROXY
Dmitry Shmidt29333592017-01-09 12:27:11 -08001015
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001016static void wpa_supplicant_eap_proxy_cb(void *ctx)
1017{
1018 struct wpa_supplicant *wpa_s = ctx;
1019 size_t len;
1020
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001021 wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001022 wpa_s->imsi, &len);
1023 if (wpa_s->mnc_len > 0) {
1024 wpa_s->imsi[len] = '\0';
1025 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
1026 wpa_s->imsi, wpa_s->mnc_len);
1027 } else {
1028 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
1029 }
1030}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001031
1032
1033static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
1034{
1035 int i;
1036 struct wpa_ssid *ssid;
1037 const struct eap_method_type *eap_methods;
1038
1039 if (!wpa_s->conf)
1040 return;
1041
1042 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1043 eap_methods = ssid->eap.eap_methods;
1044 if (!eap_methods)
1045 continue;
1046
1047 for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
1048 if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
1049 (eap_methods[i].method == EAP_TYPE_SIM ||
1050 eap_methods[i].method == EAP_TYPE_AKA ||
1051 eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
1052 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
1053 break;
1054 }
1055 }
1056 }
1057}
1058
1059
1060static void
1061wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
1062 enum eap_proxy_sim_state sim_state)
1063{
1064 struct wpa_supplicant *wpa_s = ctx;
1065
1066 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
1067 switch (sim_state) {
1068 case SIM_STATE_ERROR:
1069 wpa_sm_sim_state_error_handler(wpa_s);
1070 break;
1071 default:
1072 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
1073 break;
1074 }
1075}
1076
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001077#endif /* CONFIG_EAP_PROXY */
1078
1079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080static void wpa_supplicant_port_cb(void *ctx, int authorized)
1081{
1082 struct wpa_supplicant *wpa_s = ctx;
1083#ifdef CONFIG_AP
1084 if (wpa_s->ap_iface) {
1085 wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
1086 "port status: %s",
1087 authorized ? "Authorized" : "Unauthorized");
1088 return;
1089 }
1090#endif /* CONFIG_AP */
1091 wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
1092 authorized ? "Authorized" : "Unauthorized");
1093 wpa_drv_set_supp_port(wpa_s, authorized);
1094}
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001095
1096
Hai Shalom81f62d82019-07-22 12:10:00 -07001097static void wpa_supplicant_cert_cb(void *ctx, struct tls_cert_data *cert,
1098 const char *cert_hash)
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001099{
1100 struct wpa_supplicant *wpa_s = ctx;
1101
Hai Shalom81f62d82019-07-22 12:10:00 -07001102 wpas_notify_certification(wpa_s, cert, cert_hash);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001103}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001104
1105
1106static void wpa_supplicant_status_cb(void *ctx, const char *status,
1107 const char *parameter)
1108{
1109 struct wpa_supplicant *wpa_s = ctx;
1110
1111 wpas_notify_eap_status(wpa_s, status, parameter);
1112}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001113
Roshan Pius3a1667e2018-07-03 15:17:14 -07001114
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001115static void wpa_supplicant_eap_error_cb(void *ctx, int error_code)
1116{
1117 struct wpa_supplicant *wpa_s = ctx;
1118
1119 wpas_notify_eap_error(wpa_s, error_code);
1120}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001121
Roshan Pius3a1667e2018-07-03 15:17:14 -07001122
Hai Shalomfdcde762020-04-02 11:19:20 -07001123static int wpa_supplicant_eap_auth_start_cb(void *ctx)
1124{
1125 struct wpa_supplicant *wpa_s = ctx;
1126
1127 if (!wpa_s->new_connection && wpa_s->deny_ptk0_rekey &&
1128 !wpa_sm_ext_key_id_active(wpa_s->wpa)) {
1129 wpa_msg(wpa_s, MSG_INFO,
1130 "WPA: PTK0 rekey not allowed, reconnecting");
1131 wpa_supplicant_reconnect(wpa_s);
1132 return -1;
1133 }
1134 return 0;
1135}
1136
1137
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001138static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
1139{
1140 struct wpa_supplicant *wpa_s = ctx;
1141 char *str;
1142 int res;
1143
1144 wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
1145 id, len);
1146
1147 if (wpa_s->current_ssid == NULL)
1148 return;
1149
1150 if (id == NULL) {
1151 if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1152 "NULL", 0) < 0)
1153 return;
1154 } else {
1155 str = os_malloc(len * 2 + 1);
1156 if (str == NULL)
1157 return;
1158 wpa_snprintf_hex(str, len * 2 + 1, id, len);
1159 res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1160 str, 0);
1161 os_free(str);
1162 if (res < 0)
1163 return;
1164 }
1165
1166 if (wpa_s->conf->update_config) {
1167 res = wpa_config_write(wpa_s->confname, wpa_s->conf);
1168 if (res) {
1169 wpa_printf(MSG_DEBUG, "Failed to update config after "
1170 "anonymous_id update");
1171 }
1172 }
1173}
Gabriel Biren3a2ec2c2022-03-07 17:59:41 +00001174
1175static void wpa_supplicant_eap_method_selected_cb(void *ctx,
1176 const char* reason_string)
1177{
1178 struct wpa_supplicant *wpa_s = ctx;
1179
1180 wpas_notify_eap_method_selected(wpa_s, reason_string);
1181}
1182
1183static void wpa_supplicant_open_ssl_failure_cb(void *ctx,
1184 const char* reason_string)
1185{
1186 struct wpa_supplicant *wpa_s = ctx;
1187
1188 wpas_notify_open_ssl_failure(wpa_s, reason_string);
1189}
Sunil8cd6f4d2022-06-28 18:40:46 +00001190
1191static bool wpas_encryption_required(void *ctx)
1192{
1193 struct wpa_supplicant *wpa_s = ctx;
1194
1195 return wpa_s->wpa &&
1196 wpa_sm_has_ptk_installed(wpa_s->wpa) &&
1197 wpa_sm_pmf_enabled(wpa_s->wpa);
1198}
1199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200#endif /* IEEE8021X_EAPOL */
1201
1202
1203int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
1204{
1205#ifdef IEEE8021X_EAPOL
1206 struct eapol_ctx *ctx;
1207 ctx = os_zalloc(sizeof(*ctx));
1208 if (ctx == NULL) {
1209 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
1210 return -1;
1211 }
1212
1213 ctx->ctx = wpa_s;
1214 ctx->msg_ctx = wpa_s;
1215 ctx->eapol_send_ctx = wpa_s;
1216 ctx->preauth = 0;
1217 ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
1218 ctx->eapol_send = wpa_supplicant_eapol_send;
Hai Shalomfdcde762020-04-02 11:19:20 -07001219#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220 ctx->set_wep_key = wpa_eapol_set_wep_key;
Hai Shalomfdcde762020-04-02 11:19:20 -07001221#endif /* CONFIG_WEP */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001222#ifndef CONFIG_NO_CONFIG_BLOBS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1224 ctx->get_config_blob = wpa_supplicant_get_config_blob;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001225#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 ctx->aborted_cached = wpa_supplicant_aborted_cached;
1227 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
1228 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
1229 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001230 ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 ctx->wps = wpa_s->wps;
1232 ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001233#ifdef CONFIG_EAP_PROXY
1234 ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001235 ctx->eap_proxy_notify_sim_status =
1236 wpa_supplicant_eap_proxy_notify_sim_status;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001237#endif /* CONFIG_EAP_PROXY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 ctx->port_cb = wpa_supplicant_port_cb;
1239 ctx->cb = wpa_supplicant_eapol_cb;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001240 ctx->cert_cb = wpa_supplicant_cert_cb;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001241 ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001242 ctx->status_cb = wpa_supplicant_status_cb;
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001243 ctx->eap_error_cb = wpa_supplicant_eap_error_cb;
Hai Shalomfdcde762020-04-02 11:19:20 -07001244 ctx->confirm_auth_cb = wpa_supplicant_eap_auth_start_cb;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001245 ctx->set_anon_id = wpa_supplicant_set_anon_id;
Gabriel Biren3a2ec2c2022-03-07 17:59:41 +00001246 ctx->eap_method_selected_cb = wpa_supplicant_eap_method_selected_cb;
1247 ctx->open_ssl_failure_cb = wpa_supplicant_open_ssl_failure_cb;
Sunil8cd6f4d2022-06-28 18:40:46 +00001248 ctx->encryption_required = wpas_encryption_required;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249 ctx->cb_ctx = wpa_s;
1250 wpa_s->eapol = eapol_sm_init(ctx);
1251 if (wpa_s->eapol == NULL) {
1252 os_free(ctx);
1253 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
1254 "machines.");
1255 return -1;
1256 }
1257#endif /* IEEE8021X_EAPOL */
1258
1259 return 0;
1260}
1261
1262
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001263#ifndef CONFIG_NO_WPA
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001264
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001265static void wpa_supplicant_set_rekey_offload(void *ctx,
1266 const u8 *kek, size_t kek_len,
1267 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001268 const u8 *replay_ctr)
1269{
1270 struct wpa_supplicant *wpa_s = ctx;
1271
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001272 wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001273}
1274
1275
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001276static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
1277 size_t pmk_len)
1278{
1279 struct wpa_supplicant *wpa_s = ctx;
1280
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001281 if (wpa_s->conf->key_mgmt_offload &&
1282 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
Hai Shalomfdcde762020-04-02 11:19:20 -07001283 return wpa_drv_set_key(wpa_s, 0, NULL, 0, 0,
1284 NULL, 0, pmk, pmk_len, KEY_FLAG_PMK);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001285 else
1286 return 0;
1287}
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001288
1289
1290static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
1291 const u8 *pkt, size_t pkt_len)
1292{
1293 struct wpa_supplicant *wpa_s = ctx;
1294 char *hex;
1295 size_t hexlen;
1296
1297 hexlen = pkt_len * 2 + 1;
1298 hex = os_malloc(hexlen);
1299 if (!hex)
1300 return;
1301 wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
1302 wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
1303 " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
1304 os_free(hex);
1305}
1306
Hai Shalom74f70d42019-02-11 14:42:39 -08001307
1308static int wpa_supplicant_channel_info(void *_wpa_s,
1309 struct wpa_channel_info *ci)
1310{
1311 struct wpa_supplicant *wpa_s = _wpa_s;
1312
1313 return wpa_drv_channel_info(wpa_s, ci);
1314}
1315
Hai Shalomfdcde762020-04-02 11:19:20 -07001316
1317static void disable_wpa_wpa2(struct wpa_ssid *ssid)
1318{
1319 ssid->proto &= ~WPA_PROTO_WPA;
1320 ssid->proto |= WPA_PROTO_RSN;
1321 ssid->key_mgmt &= ~(WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK |
1322 WPA_KEY_MGMT_PSK_SHA256);
1323 ssid->group_cipher &= ~WPA_CIPHER_TKIP;
1324 if (!(ssid->group_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1325 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)))
1326 ssid->group_cipher |= WPA_CIPHER_CCMP;
1327 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1328}
1329
1330
1331static void wpa_supplicant_transition_disable(void *_wpa_s, u8 bitmap)
1332{
1333 struct wpa_supplicant *wpa_s = _wpa_s;
1334 struct wpa_ssid *ssid;
1335 int changed = 0;
1336
1337 wpa_msg(wpa_s, MSG_INFO, TRANSITION_DISABLE "%02x", bitmap);
1338
1339 ssid = wpa_s->current_ssid;
1340 if (!ssid)
1341 return;
1342
Hai Shalom899fcc72020-10-19 14:38:18 -07001343#ifdef CONFIG_SAE
Hai Shalomfdcde762020-04-02 11:19:20 -07001344 if ((bitmap & TRANSITION_DISABLE_WPA3_PERSONAL) &&
1345 wpa_key_mgmt_sae(wpa_s->key_mgmt) &&
Sunil Ravi89eba102022-09-13 21:04:37 -07001346 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001347 (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1348 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1349 wpa_printf(MSG_DEBUG,
1350 "WPA3-Personal transition mode disabled based on AP notification");
1351 disable_wpa_wpa2(ssid);
1352 changed = 1;
1353 }
1354
Hai Shalom899fcc72020-10-19 14:38:18 -07001355 if ((bitmap & TRANSITION_DISABLE_SAE_PK) &&
1356 wpa_key_mgmt_sae(wpa_s->key_mgmt) &&
1357#ifdef CONFIG_SME
1358 wpa_s->sme.sae.state == SAE_ACCEPTED &&
1359 wpa_s->sme.sae.pk &&
1360#endif /* CONFIG_SME */
Sunil Ravi89eba102022-09-13 21:04:37 -07001361 wpa_key_mgmt_sae(ssid->key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -07001362 (ssid->sae_pk != SAE_PK_MODE_ONLY ||
1363 ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1364 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1365 wpa_printf(MSG_DEBUG,
1366 "SAE-PK: SAE authentication without PK disabled based on AP notification");
1367 disable_wpa_wpa2(ssid);
1368 ssid->sae_pk = SAE_PK_MODE_ONLY;
1369 changed = 1;
1370 }
1371#endif /* CONFIG_SAE */
1372
Hai Shalomfdcde762020-04-02 11:19:20 -07001373 if ((bitmap & TRANSITION_DISABLE_WPA3_ENTERPRISE) &&
1374 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
1375 (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X |
1376 WPA_KEY_MGMT_FT_IEEE8021X |
1377 WPA_KEY_MGMT_IEEE8021X_SHA256)) &&
1378 (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1379 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1380 disable_wpa_wpa2(ssid);
1381 changed = 1;
1382 }
1383
1384 if ((bitmap & TRANSITION_DISABLE_ENHANCED_OPEN) &&
1385 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
1386 (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1387 !ssid->owe_only) {
1388 ssid->owe_only = 1;
1389 changed = 1;
1390 }
1391
Vinayak Yadawade62409f2022-01-20 12:32:07 +05301392#ifdef CONFIG_DRIVER_NL80211_BRCM
1393 /* driver call for transition disable */
1394 {
1395 struct wpa_driver_associate_params params;
1396
1397 os_memset(&params, 0, sizeof(params));
1398 params.td_policy = bitmap;
1399 wpa_drv_update_connect_params(wpa_s, &params, WPA_DRV_UPDATE_TD_POLICY);
1400 }
1401#endif /* CONFIG_DRIVER_NL80211_BRCM */
1402
Jimmy Chen39deead2020-10-14 23:47:20 +08001403 wpas_notify_transition_disable(wpa_s, ssid, bitmap);
1404
Hai Shalomfdcde762020-04-02 11:19:20 -07001405 if (!changed)
1406 return;
1407
1408#ifndef CONFIG_NO_CONFIG_WRITE
1409 if (wpa_s->conf->update_config &&
1410 wpa_config_write(wpa_s->confname, wpa_s->conf))
1411 wpa_printf(MSG_DEBUG, "Failed to update configuration");
1412#endif /* CONFIG_NO_CONFIG_WRITE */
1413}
1414
Hai Shalom60840252021-02-19 19:02:11 -08001415
1416static void wpa_supplicant_store_ptk(void *ctx, u8 *addr, int cipher,
1417 u32 life_time, const struct wpa_ptk *ptk)
1418{
1419 struct wpa_supplicant *wpa_s = ctx;
1420
Sunil Ravi89eba102022-09-13 21:04:37 -07001421 ptksa_cache_add(wpa_s->ptksa, wpa_s->own_addr, addr, cipher, life_time,
1422 ptk, NULL, NULL);
Hai Shalom60840252021-02-19 19:02:11 -08001423}
1424
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001425#endif /* CONFIG_NO_WPA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001426
1427
Sunil Ravi89eba102022-09-13 21:04:37 -07001428#ifdef CONFIG_PASN
1429static int wpa_supplicant_set_ltf_keyseed(void *_wpa_s, const u8 *own_addr,
1430 const u8 *peer_addr,
1431 size_t ltf_keyseed_len,
1432 const u8 *ltf_keyseed)
1433{
1434 struct wpa_supplicant *wpa_s = _wpa_s;
1435
1436 return wpa_drv_set_secure_ranging_ctx(wpa_s, own_addr, peer_addr, 0, 0,
1437 NULL, ltf_keyseed_len,
1438 ltf_keyseed, 0);
1439}
1440#endif /* CONFIG_PASN */
1441
1442
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
1444{
1445#ifndef CONFIG_NO_WPA
1446 struct wpa_sm_ctx *ctx;
Hai Shalom60840252021-02-19 19:02:11 -08001447
1448 wpa_s->ptksa = ptksa_cache_init();
1449 if (!wpa_s->ptksa) {
1450 wpa_printf(MSG_ERROR, "Failed to allocate PTKSA");
1451 return -1;
1452 }
1453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001454 ctx = os_zalloc(sizeof(*ctx));
1455 if (ctx == NULL) {
1456 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
Hai Shalom60840252021-02-19 19:02:11 -08001457
1458 ptksa_cache_deinit(wpa_s->ptksa);
1459 wpa_s->ptksa = NULL;
1460
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001461 return -1;
1462 }
1463
1464 ctx->ctx = wpa_s;
1465 ctx->msg_ctx = wpa_s;
1466 ctx->set_state = _wpa_supplicant_set_state;
1467 ctx->get_state = _wpa_supplicant_get_state;
1468 ctx->deauthenticate = _wpa_supplicant_deauthenticate;
Hai Shalomfdcde762020-04-02 11:19:20 -07001469 ctx->reconnect = _wpa_supplicant_reconnect;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001470 ctx->set_key = wpa_supplicant_set_key;
1471 ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
1472 ctx->get_bssid = wpa_supplicant_get_bssid;
1473 ctx->ether_send = _wpa_ether_send;
1474 ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
1475 ctx->alloc_eapol = _wpa_alloc_eapol;
1476 ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
1477 ctx->add_pmkid = wpa_supplicant_add_pmkid;
1478 ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
1479#ifndef CONFIG_NO_CONFIG_BLOBS
1480 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1481 ctx->get_config_blob = wpa_supplicant_get_config_blob;
1482#endif /* CONFIG_NO_CONFIG_BLOBS */
1483 ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
1484#ifdef CONFIG_IEEE80211R
1485 ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
1486 ctx->send_ft_action = wpa_supplicant_send_ft_action;
1487 ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
1488#endif /* CONFIG_IEEE80211R */
1489#ifdef CONFIG_TDLS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001490 ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491 ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
1492 ctx->tdls_oper = wpa_supplicant_tdls_oper;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001493 ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001494 ctx->tdls_enable_channel_switch =
1495 wpa_supplicant_tdls_enable_channel_switch;
1496 ctx->tdls_disable_channel_switch =
1497 wpa_supplicant_tdls_disable_channel_switch;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001498#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001499 ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001500 ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001501 ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
Hai Shalom74f70d42019-02-11 14:42:39 -08001502 ctx->channel_info = wpa_supplicant_channel_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001503 ctx->transition_disable = wpa_supplicant_transition_disable;
Hai Shalom60840252021-02-19 19:02:11 -08001504 ctx->store_ptk = wpa_supplicant_store_ptk;
Sunil Ravi89eba102022-09-13 21:04:37 -07001505#ifdef CONFIG_PASN
1506 ctx->set_ltf_keyseed = wpa_supplicant_set_ltf_keyseed;
1507#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508
1509 wpa_s->wpa = wpa_sm_init(ctx);
1510 if (wpa_s->wpa == NULL) {
Hai Shalom60840252021-02-19 19:02:11 -08001511 wpa_printf(MSG_ERROR,
1512 "Failed to initialize WPA state machine");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001513 os_free(ctx);
Hai Shalom60840252021-02-19 19:02:11 -08001514 ptksa_cache_deinit(wpa_s->ptksa);
1515 wpa_s->ptksa = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001516 return -1;
1517 }
1518#endif /* CONFIG_NO_WPA */
1519
1520 return 0;
1521}
1522
1523
1524void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
1525 struct wpa_ssid *ssid)
1526{
1527 struct rsn_supp_config conf;
1528 if (ssid) {
1529 os_memset(&conf, 0, sizeof(conf));
1530 conf.network_ctx = ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
1532#ifdef IEEE8021X_EAPOL
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001533 conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
1534 wpa_s->conf->okc : ssid->proactive_key_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 conf.eap_workaround = ssid->eap_workaround;
1536 conf.eap_conf_ctx = &ssid->eap;
1537#endif /* IEEE8021X_EAPOL */
1538 conf.ssid = ssid->ssid;
1539 conf.ssid_len = ssid->ssid_len;
1540 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
Hai Shalomfdcde762020-04-02 11:19:20 -07001541 conf.wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
1542 conf.owe_ptk_workaround = ssid->owe_ptk_workaround;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001543#ifdef CONFIG_P2P
1544 if (ssid->p2p_group && wpa_s->current_bss &&
1545 !wpa_s->p2p_disable_ip_addr_req) {
1546 struct wpabuf *p2p;
1547 p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
1548 P2P_IE_VENDOR_TYPE);
1549 if (p2p) {
1550 u8 group_capab;
1551 group_capab = p2p_get_group_capab(p2p);
1552 if (group_capab &
1553 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
1554 conf.p2p = 1;
1555 wpabuf_free(p2p);
1556 }
1557 }
1558#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001559 conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001560#ifdef CONFIG_FILS
1561 if (wpa_key_mgmt_fils(wpa_s->key_mgmt))
1562 conf.fils_cache_id =
1563 wpa_bss_get_fils_cache_id(wpa_s->current_bss);
1564#endif /* CONFIG_FILS */
Hai Shalom60840252021-02-19 19:02:11 -08001565 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
1566 (wpa_s->drv_flags2 &
1567 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
1568 conf.beacon_prot = ssid->beacon_prot;
1569
1570#ifdef CONFIG_PASN
1571#ifdef CONFIG_TESTING_OPTIONS
1572 conf.force_kdk_derivation = wpa_s->conf->force_kdk_derivation;
1573#endif /* CONFIG_TESTING_OPTIONS */
1574#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 }
1576 wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
1577}