blob: 8a0fe8defec1a7e5e95e8fe3b2da45231ad99b11 [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;
289 u8 pmk[PMK_LEN];
290
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
339 pmk_len = PMK_LEN;
340 if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
341#ifdef CONFIG_IEEE80211R
342 u8 buf[2 * PMK_LEN];
343 wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
344 "driver-based 4-way hs and FT");
345 res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
346 if (res == 0) {
347 os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
348 os_memset(buf, 0, sizeof(buf));
349 }
350#else /* CONFIG_IEEE80211R */
351 res = -1;
352#endif /* CONFIG_IEEE80211R */
353 } else {
354 res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
355 if (res) {
356 /*
357 * EAP-LEAP is an exception from other EAP methods: it
358 * uses only 16-byte PMK.
359 */
360 res = eapol_sm_get_key(eapol, pmk, 16);
361 pmk_len = 16;
362 }
363 }
364
365 if (res) {
366 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
367 "machines");
368 return;
369 }
370
371 wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
372 "handshake", pmk, pmk_len);
373
Hai Shalomfdcde762020-04-02 11:19:20 -0700374 if (wpa_drv_set_key(wpa_s, 0, NULL, 0, 0, NULL, 0, pmk,
375 pmk_len, KEY_FLAG_PMK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
377 }
378
379 wpa_supplicant_cancel_scan(wpa_s);
380 wpa_supplicant_cancel_auth_timeout(wpa_s);
381 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
382
383}
384
385
386static void wpa_supplicant_notify_eapol_done(void *ctx)
387{
388 struct wpa_supplicant *wpa_s = ctx;
389 wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
390 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
391 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
392 } else {
393 wpa_supplicant_cancel_auth_timeout(wpa_s);
394 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
395 }
396}
397
398#endif /* IEEE8021X_EAPOL */
399
400
401#ifndef CONFIG_NO_WPA
402
403static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
404{
405 int ret = 0;
406 struct wpa_bss *curr = NULL, *bss;
407 struct wpa_ssid *ssid = wpa_s->current_ssid;
408 const u8 *ie;
409
410 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
411 if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
412 continue;
413 if (ssid == NULL ||
414 ((bss->ssid_len == ssid->ssid_len &&
415 os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
416 ssid->ssid_len == 0)) {
417 curr = bss;
418 break;
419 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700420#ifdef CONFIG_OWE
421 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
422 (bss->flags & WPA_BSS_OWE_TRANSITION)) {
423 curr = bss;
424 break;
425 }
426#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 }
428
429 if (curr) {
430 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
431 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
432 ret = -1;
433
434 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
435 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
436 ret = -1;
Hai Shalomc3565922019-10-28 11:58:20 -0700437
438 ie = wpa_bss_get_ie(curr, WLAN_EID_RSNX);
439 if (wpa_sm_set_ap_rsnxe(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
440 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 } else {
442 ret = -1;
443 }
444
445 return ret;
446}
447
448
449static int wpa_supplicant_get_beacon_ie(void *ctx)
450{
451 struct wpa_supplicant *wpa_s = ctx;
452 if (wpa_get_beacon_ie(wpa_s) == 0) {
453 return 0;
454 }
455
456 /* No WPA/RSN IE found in the cached scan results. Try to get updated
457 * scan results from the driver. */
458 if (wpa_supplicant_update_scan_results(wpa_s) < 0)
459 return -1;
460
461 return wpa_get_beacon_ie(wpa_s);
462}
463
464
465static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
466 const void *data, u16 data_len,
467 size_t *msg_len, void **data_pos)
468{
469 return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
470}
471
472
473static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
474 const u8 *buf, size_t len)
475{
476 return wpa_ether_send(wpa_s, dest, proto, buf, len);
477}
478
479
480static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
481{
482 wpa_supplicant_cancel_auth_timeout(wpa_s);
483}
484
485
486static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
487{
488 wpa_supplicant_set_state(wpa_s, state);
489}
490
491
492/**
493 * wpa_supplicant_get_state - Get the connection state
494 * @wpa_s: Pointer to wpa_supplicant data
495 * Returns: The current connection state (WPA_*)
496 */
497static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
498{
499 return wpa_s->wpa_state;
500}
501
502
503static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
504{
505 return wpa_supplicant_get_state(wpa_s);
506}
507
508
Hai Shalom81f62d82019-07-22 12:10:00 -0700509static void _wpa_supplicant_deauthenticate(void *wpa_s, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510{
511 wpa_supplicant_deauthenticate(wpa_s, reason_code);
512 /* Schedule a scan to make sure we continue looking for networks */
513 wpa_supplicant_req_scan(wpa_s, 5, 0);
514}
515
516
Hai Shalomfdcde762020-04-02 11:19:20 -0700517static void _wpa_supplicant_reconnect(void *wpa_s)
518{
519 wpa_supplicant_reconnect(wpa_s);
520}
521
522
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523static void * wpa_supplicant_get_network_ctx(void *wpa_s)
524{
525 return wpa_supplicant_get_ssid(wpa_s);
526}
527
528
529static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
530{
531 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 return wpa_drv_get_bssid(wpa_s, bssid);
533}
534
535
536static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
537 const u8 *addr, int key_idx, int set_tx,
538 const u8 *seq, size_t seq_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700539 const u8 *key, size_t key_len,
540 enum key_flag key_flag)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541{
542 struct wpa_supplicant *wpa_s = _wpa_s;
543 if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
544 /* Clear the MIC error counter when setting a new PTK. */
545 wpa_s->mic_errors_seen = 0;
546 }
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700547#ifdef CONFIG_TESTING_GET_GTK
548 if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
549 alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
550 os_memcpy(wpa_s->last_gtk, key, key_len);
551 wpa_s->last_gtk_len = key_len;
552 }
553#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700554#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -0700555 if (addr && !is_broadcast_ether_addr(addr) &&
556 !(key_flag & KEY_FLAG_MODIFY)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700557 wpa_s->last_tk_alg = alg;
558 os_memcpy(wpa_s->last_tk_addr, addr, ETH_ALEN);
559 wpa_s->last_tk_key_idx = key_idx;
560 if (key)
561 os_memcpy(wpa_s->last_tk, key, key_len);
562 wpa_s->last_tk_len = key_len;
563 }
564#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565 return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700566 key, key_len, key_flag);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567}
568
569
570static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
571 int protection_type,
572 int key_type)
573{
574 return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
575 key_type);
576}
577
578
Dmitry Shmidt29333592017-01-09 12:27:11 -0800579static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s,
580 void *network_ctx)
581{
582 struct wpa_ssid *ssid;
583
584 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
585 if (network_ctx == ssid)
586 return ssid;
587 }
588
589 return NULL;
590}
591
592
593static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700594 const u8 *bssid, const u8 *pmkid,
595 const u8 *fils_cache_id,
Hai Shalomfdcde762020-04-02 11:19:20 -0700596 const u8 *pmk, size_t pmk_len,
Hai Shalom899fcc72020-10-19 14:38:18 -0700597 u32 pmk_lifetime, u8 pmk_reauth_threshold,
598 int akmp)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800600 struct wpa_supplicant *wpa_s = _wpa_s;
601 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700602 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800603
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700604 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800605 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
Hai Shalom899fcc72020-10-19 14:38:18 -0700606 if (ssid) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800607 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
608 MAC2STR(bssid), ssid->id);
Hai Shalom899fcc72020-10-19 14:38:18 -0700609 if ((akmp == WPA_KEY_MGMT_FT_IEEE8021X ||
610 akmp == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) &&
611 !ssid->ft_eap_pmksa_caching) {
612 /* Since we will not be using PMKSA caching for FT-EAP
613 * within wpa_supplicant to avoid known interop issues
614 * with APs, do not add this PMKID to the driver either
615 * so that we won't be hitting those interop issues
616 * with driver-based RSNE generation. */
617 wpa_printf(MSG_DEBUG,
618 "FT: Do not add PMKID entry to the driver since FT-EAP PMKSA caching is not enabled in configuration");
619 return 0;
620 }
621 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700622 if (ssid && fils_cache_id) {
623 params.ssid = ssid->ssid;
624 params.ssid_len = ssid->ssid_len;
625 params.fils_cache_id = fils_cache_id;
626 } else {
627 params.bssid = bssid;
628 }
629
630 params.pmkid = pmkid;
631 params.pmk = pmk;
632 params.pmk_len = pmk_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700633 params.pmk_lifetime = pmk_lifetime;
634 params.pmk_reauth_threshold = pmk_reauth_threshold;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700635
636 return wpa_drv_add_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637}
638
639
Dmitry Shmidt29333592017-01-09 12:27:11 -0800640static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700641 const u8 *bssid, const u8 *pmkid,
642 const u8 *fils_cache_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800644 struct wpa_supplicant *wpa_s = _wpa_s;
645 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700646 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800647
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700648 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800649 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
650 if (ssid)
651 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
652 MAC2STR(bssid), ssid->id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700653 if (ssid && fils_cache_id) {
654 params.ssid = ssid->ssid;
655 params.ssid_len = ssid->ssid_len;
656 params.fils_cache_id = fils_cache_id;
657 } else {
658 params.bssid = bssid;
659 }
660
661 params.pmkid = pmkid;
662
663 return wpa_drv_remove_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664}
665
666
667#ifdef CONFIG_IEEE80211R
668static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
669 const u8 *ies, size_t ies_len)
670{
671 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
673 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
674 return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
675}
676
677
678static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
679 const u8 *target_ap,
680 const u8 *ies, size_t ies_len)
681{
682 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800683 int ret;
684 u8 *data, *pos;
685 size_t data_len;
686
687 if (action != 1) {
688 wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
689 action);
690 return -1;
691 }
692
693 /*
694 * Action frame payload:
695 * Category[1] = 6 (Fast BSS Transition)
696 * Action[1] = 1 (Fast BSS Transition Request)
697 * STA Address
698 * Target AP Address
699 * FT IEs
700 */
701
702 data_len = 2 + 2 * ETH_ALEN + ies_len;
703 data = os_malloc(data_len);
704 if (data == NULL)
705 return -1;
706 pos = data;
707 *pos++ = 0x06; /* FT Action category */
708 *pos++ = action;
709 os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
710 pos += ETH_ALEN;
711 os_memcpy(pos, target_ap, ETH_ALEN);
712 pos += ETH_ALEN;
713 os_memcpy(pos, ies, ies_len);
714
715 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
716 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
717 data, data_len, 0);
718 os_free(data);
719
720 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721}
722
723
724static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
725{
726 struct wpa_supplicant *wpa_s = ctx;
727 struct wpa_driver_auth_params params;
728 struct wpa_bss *bss;
729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 bss = wpa_bss_get_bssid(wpa_s, target_ap);
731 if (bss == NULL)
732 return -1;
733
734 os_memset(&params, 0, sizeof(params));
735 params.bssid = target_ap;
736 params.freq = bss->freq;
737 params.ssid = bss->ssid;
738 params.ssid_len = bss->ssid_len;
739 params.auth_alg = WPA_AUTH_ALG_FT;
740 params.local_state_change = 1;
741 return wpa_drv_authenticate(wpa_s, &params);
742}
743#endif /* CONFIG_IEEE80211R */
744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745
746#ifdef CONFIG_TDLS
747
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800748static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800749 int *tdls_ext_setup,
750 int *tdls_chan_switch)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800751{
752 struct wpa_supplicant *wpa_s = ctx;
753
754 *tdls_supported = 0;
755 *tdls_ext_setup = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800756 *tdls_chan_switch = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800757
758 if (!wpa_s->drv_capa_known)
759 return -1;
760
761 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
762 *tdls_supported = 1;
763
764 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
765 *tdls_ext_setup = 1;
766
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800767 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
768 *tdls_chan_switch = 1;
769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770 return 0;
771}
772
773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
775 u8 action_code, u8 dialog_token,
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700776 u16 status_code, u32 peer_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700777 int initiator, const u8 *buf,
778 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779{
780 struct wpa_supplicant *wpa_s = ctx;
781 return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700782 status_code, peer_capab, initiator, buf,
783 len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784}
785
786
787static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
788{
789 struct wpa_supplicant *wpa_s = ctx;
790 return wpa_drv_tdls_oper(wpa_s, oper, peer);
791}
792
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800793
794static int wpa_supplicant_tdls_peer_addset(
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700795 void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800796 const u8 *supp_rates, size_t supp_rates_len,
797 const struct ieee80211_ht_capabilities *ht_capab,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800798 const struct ieee80211_vht_capabilities *vht_capab,
Hai Shalomc1a21442022-02-04 13:43:00 -0800799 const struct ieee80211_he_capabilities *he_capab,
800 size_t he_capab_len,
801 const struct ieee80211_he_6ghz_band_cap *he_6ghz_he_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700802 u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800803 const u8 *supp_channels, size_t supp_channels_len,
804 const u8 *supp_oper_classes, size_t supp_oper_classes_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800805{
806 struct wpa_supplicant *wpa_s = ctx;
807 struct hostapd_sta_add_params params;
808
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800809 os_memset(&params, 0, sizeof(params));
810
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800811 params.addr = peer;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700812 params.aid = aid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800813 params.capability = capability;
814 params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800815
816 /*
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700817 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
818 * present. Allow the WMM IE to also indicate QoS support.
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800819 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700820 if (wmm || qosinfo)
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800821 params.flags |= WPA_STA_WMM;
822
823 params.ht_capabilities = ht_capab;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800824 params.vht_capabilities = vht_capab;
Hai Shalomc1a21442022-02-04 13:43:00 -0800825 params.he_capab = he_capab;
826 params.he_capab_len = he_capab_len;
827 params.he_6ghz_capab = he_6ghz_he_capab;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800828 params.qosinfo = qosinfo;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800829 params.listen_interval = 0;
830 params.supp_rates = supp_rates;
831 params.supp_rates_len = supp_rates_len;
832 params.set = !add;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800833 params.ext_capab = ext_capab;
834 params.ext_capab_len = ext_capab_len;
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800835 params.supp_channels = supp_channels;
836 params.supp_channels_len = supp_channels_len;
837 params.supp_oper_classes = supp_oper_classes;
838 params.supp_oper_classes_len = supp_oper_classes_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839
840 return wpa_drv_sta_add(wpa_s, &params);
841}
842
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800843
844static int wpa_supplicant_tdls_enable_channel_switch(
845 void *ctx, const u8 *addr, u8 oper_class,
846 const struct hostapd_freq_params *params)
847{
848 struct wpa_supplicant *wpa_s = ctx;
849
850 return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
851 params);
852}
853
854
855static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
856{
857 struct wpa_supplicant *wpa_s = ctx;
858
859 return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
860}
861
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862#endif /* CONFIG_TDLS */
863
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700864#endif /* CONFIG_NO_WPA */
865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800867enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
868{
869 if (os_strcmp(field, "IDENTITY") == 0)
870 return WPA_CTRL_REQ_EAP_IDENTITY;
871 else if (os_strcmp(field, "PASSWORD") == 0)
872 return WPA_CTRL_REQ_EAP_PASSWORD;
873 else if (os_strcmp(field, "NEW_PASSWORD") == 0)
874 return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
875 else if (os_strcmp(field, "PIN") == 0)
876 return WPA_CTRL_REQ_EAP_PIN;
877 else if (os_strcmp(field, "OTP") == 0)
878 return WPA_CTRL_REQ_EAP_OTP;
879 else if (os_strcmp(field, "PASSPHRASE") == 0)
880 return WPA_CTRL_REQ_EAP_PASSPHRASE;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700881 else if (os_strcmp(field, "SIM") == 0)
882 return WPA_CTRL_REQ_SIM;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700883 else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
884 return WPA_CTRL_REQ_PSK_PASSPHRASE;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800885 else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
886 return WPA_CTRL_REQ_EXT_CERT_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800887 return WPA_CTRL_REQ_UNKNOWN;
888}
889
890
891const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
892 const char *default_txt,
893 const char **txt)
894{
895 const char *ret = NULL;
896
897 *txt = default_txt;
898
899 switch (field) {
900 case WPA_CTRL_REQ_EAP_IDENTITY:
901 *txt = "Identity";
902 ret = "IDENTITY";
903 break;
904 case WPA_CTRL_REQ_EAP_PASSWORD:
905 *txt = "Password";
906 ret = "PASSWORD";
907 break;
908 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
909 *txt = "New Password";
910 ret = "NEW_PASSWORD";
911 break;
912 case WPA_CTRL_REQ_EAP_PIN:
913 *txt = "PIN";
914 ret = "PIN";
915 break;
916 case WPA_CTRL_REQ_EAP_OTP:
917 ret = "OTP";
918 break;
919 case WPA_CTRL_REQ_EAP_PASSPHRASE:
920 *txt = "Private key passphrase";
921 ret = "PASSPHRASE";
922 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700923 case WPA_CTRL_REQ_SIM:
924 ret = "SIM";
925 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700926 case WPA_CTRL_REQ_PSK_PASSPHRASE:
927 *txt = "PSK or passphrase";
928 ret = "PSK_PASSPHRASE";
929 break;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800930 case WPA_CTRL_REQ_EXT_CERT_CHECK:
931 *txt = "External server certificate validation";
932 ret = "EXT_CERT_CHECK";
933 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800934 default:
935 break;
936 }
937
938 /* txt needs to be something */
939 if (*txt == NULL) {
940 wpa_printf(MSG_WARNING, "No message for request %d", field);
941 ret = NULL;
942 }
943
944 return ret;
945}
946
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700947
948void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
949 const char *field_name, const char *txt)
950{
951 char *buf;
952 size_t buflen;
953 int len;
954
955 buflen = 100 + os_strlen(txt) + ssid->ssid_len;
956 buf = os_malloc(buflen);
957 if (buf == NULL)
958 return;
959 len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
960 field_name, ssid->id, txt);
961 if (os_snprintf_error(buflen, len)) {
962 os_free(buf);
963 return;
964 }
965 if (ssid->ssid && buflen > len + ssid->ssid_len) {
966 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
967 len += ssid->ssid_len;
968 buf[len] = '\0';
969 }
970 buf[buflen - 1] = '\0';
971 wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
972 os_free(buf);
973}
974
975
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700976#ifdef IEEE8021X_EAPOL
977#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800978static void wpa_supplicant_eap_param_needed(void *ctx,
979 enum wpa_ctrl_req_type field,
980 const char *default_txt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981{
982 struct wpa_supplicant *wpa_s = ctx;
983 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800984 const char *field_name, *txt = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985
986 if (ssid == NULL)
987 return;
988
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800989 if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
990 ssid->eap.pending_ext_cert_check = PENDING_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991 wpas_notify_network_request(wpa_s, ssid, field, default_txt);
992
993 field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
994 &txt);
995 if (field_name == NULL) {
996 wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
997 field);
998 return;
999 }
1000
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001001 wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
1002
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001003 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004}
1005#else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1006#define wpa_supplicant_eap_param_needed NULL
1007#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1008
1009
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001010#ifdef CONFIG_EAP_PROXY
Dmitry Shmidt29333592017-01-09 12:27:11 -08001011
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001012static void wpa_supplicant_eap_proxy_cb(void *ctx)
1013{
1014 struct wpa_supplicant *wpa_s = ctx;
1015 size_t len;
1016
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001017 wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001018 wpa_s->imsi, &len);
1019 if (wpa_s->mnc_len > 0) {
1020 wpa_s->imsi[len] = '\0';
1021 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
1022 wpa_s->imsi, wpa_s->mnc_len);
1023 } else {
1024 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
1025 }
1026}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001027
1028
1029static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
1030{
1031 int i;
1032 struct wpa_ssid *ssid;
1033 const struct eap_method_type *eap_methods;
1034
1035 if (!wpa_s->conf)
1036 return;
1037
1038 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1039 eap_methods = ssid->eap.eap_methods;
1040 if (!eap_methods)
1041 continue;
1042
1043 for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
1044 if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
1045 (eap_methods[i].method == EAP_TYPE_SIM ||
1046 eap_methods[i].method == EAP_TYPE_AKA ||
1047 eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
1048 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
1049 break;
1050 }
1051 }
1052 }
1053}
1054
1055
1056static void
1057wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
1058 enum eap_proxy_sim_state sim_state)
1059{
1060 struct wpa_supplicant *wpa_s = ctx;
1061
1062 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
1063 switch (sim_state) {
1064 case SIM_STATE_ERROR:
1065 wpa_sm_sim_state_error_handler(wpa_s);
1066 break;
1067 default:
1068 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
1069 break;
1070 }
1071}
1072
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001073#endif /* CONFIG_EAP_PROXY */
1074
1075
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076static void wpa_supplicant_port_cb(void *ctx, int authorized)
1077{
1078 struct wpa_supplicant *wpa_s = ctx;
1079#ifdef CONFIG_AP
1080 if (wpa_s->ap_iface) {
1081 wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
1082 "port status: %s",
1083 authorized ? "Authorized" : "Unauthorized");
1084 return;
1085 }
1086#endif /* CONFIG_AP */
1087 wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
1088 authorized ? "Authorized" : "Unauthorized");
1089 wpa_drv_set_supp_port(wpa_s, authorized);
1090}
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001091
1092
Hai Shalom81f62d82019-07-22 12:10:00 -07001093static void wpa_supplicant_cert_cb(void *ctx, struct tls_cert_data *cert,
1094 const char *cert_hash)
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001095{
1096 struct wpa_supplicant *wpa_s = ctx;
1097
Hai Shalom81f62d82019-07-22 12:10:00 -07001098 wpas_notify_certification(wpa_s, cert, cert_hash);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001099}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001100
1101
1102static void wpa_supplicant_status_cb(void *ctx, const char *status,
1103 const char *parameter)
1104{
1105 struct wpa_supplicant *wpa_s = ctx;
1106
1107 wpas_notify_eap_status(wpa_s, status, parameter);
1108}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001109
Roshan Pius3a1667e2018-07-03 15:17:14 -07001110
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001111static void wpa_supplicant_eap_error_cb(void *ctx, int error_code)
1112{
1113 struct wpa_supplicant *wpa_s = ctx;
1114
1115 wpas_notify_eap_error(wpa_s, error_code);
1116}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001117
Roshan Pius3a1667e2018-07-03 15:17:14 -07001118
Hai Shalomfdcde762020-04-02 11:19:20 -07001119static int wpa_supplicant_eap_auth_start_cb(void *ctx)
1120{
1121 struct wpa_supplicant *wpa_s = ctx;
1122
1123 if (!wpa_s->new_connection && wpa_s->deny_ptk0_rekey &&
1124 !wpa_sm_ext_key_id_active(wpa_s->wpa)) {
1125 wpa_msg(wpa_s, MSG_INFO,
1126 "WPA: PTK0 rekey not allowed, reconnecting");
1127 wpa_supplicant_reconnect(wpa_s);
1128 return -1;
1129 }
1130 return 0;
1131}
1132
1133
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001134static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
1135{
1136 struct wpa_supplicant *wpa_s = ctx;
1137 char *str;
1138 int res;
1139
1140 wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
1141 id, len);
1142
1143 if (wpa_s->current_ssid == NULL)
1144 return;
1145
1146 if (id == NULL) {
1147 if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1148 "NULL", 0) < 0)
1149 return;
1150 } else {
1151 str = os_malloc(len * 2 + 1);
1152 if (str == NULL)
1153 return;
1154 wpa_snprintf_hex(str, len * 2 + 1, id, len);
1155 res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1156 str, 0);
1157 os_free(str);
1158 if (res < 0)
1159 return;
1160 }
1161
1162 if (wpa_s->conf->update_config) {
1163 res = wpa_config_write(wpa_s->confname, wpa_s->conf);
1164 if (res) {
1165 wpa_printf(MSG_DEBUG, "Failed to update config after "
1166 "anonymous_id update");
1167 }
1168 }
1169}
Gabriel Biren3a2ec2c2022-03-07 17:59:41 +00001170
1171static void wpa_supplicant_eap_method_selected_cb(void *ctx,
1172 const char* reason_string)
1173{
1174 struct wpa_supplicant *wpa_s = ctx;
1175
1176 wpas_notify_eap_method_selected(wpa_s, reason_string);
1177}
1178
1179static void wpa_supplicant_open_ssl_failure_cb(void *ctx,
1180 const char* reason_string)
1181{
1182 struct wpa_supplicant *wpa_s = ctx;
1183
1184 wpas_notify_open_ssl_failure(wpa_s, reason_string);
1185}
Sunil8cd6f4d2022-06-28 18:40:46 +00001186
1187static bool wpas_encryption_required(void *ctx)
1188{
1189 struct wpa_supplicant *wpa_s = ctx;
1190
1191 return wpa_s->wpa &&
1192 wpa_sm_has_ptk_installed(wpa_s->wpa) &&
1193 wpa_sm_pmf_enabled(wpa_s->wpa);
1194}
1195
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001196#endif /* IEEE8021X_EAPOL */
1197
1198
1199int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
1200{
1201#ifdef IEEE8021X_EAPOL
1202 struct eapol_ctx *ctx;
1203 ctx = os_zalloc(sizeof(*ctx));
1204 if (ctx == NULL) {
1205 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
1206 return -1;
1207 }
1208
1209 ctx->ctx = wpa_s;
1210 ctx->msg_ctx = wpa_s;
1211 ctx->eapol_send_ctx = wpa_s;
1212 ctx->preauth = 0;
1213 ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
1214 ctx->eapol_send = wpa_supplicant_eapol_send;
Hai Shalomfdcde762020-04-02 11:19:20 -07001215#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 ctx->set_wep_key = wpa_eapol_set_wep_key;
Hai Shalomfdcde762020-04-02 11:19:20 -07001217#endif /* CONFIG_WEP */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001218#ifndef CONFIG_NO_CONFIG_BLOBS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1220 ctx->get_config_blob = wpa_supplicant_get_config_blob;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001221#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 ctx->aborted_cached = wpa_supplicant_aborted_cached;
1223 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
1224 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
1225 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001226 ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 ctx->wps = wpa_s->wps;
1228 ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001229#ifdef CONFIG_EAP_PROXY
1230 ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001231 ctx->eap_proxy_notify_sim_status =
1232 wpa_supplicant_eap_proxy_notify_sim_status;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001233#endif /* CONFIG_EAP_PROXY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 ctx->port_cb = wpa_supplicant_port_cb;
1235 ctx->cb = wpa_supplicant_eapol_cb;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001236 ctx->cert_cb = wpa_supplicant_cert_cb;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001237 ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001238 ctx->status_cb = wpa_supplicant_status_cb;
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001239 ctx->eap_error_cb = wpa_supplicant_eap_error_cb;
Hai Shalomfdcde762020-04-02 11:19:20 -07001240 ctx->confirm_auth_cb = wpa_supplicant_eap_auth_start_cb;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001241 ctx->set_anon_id = wpa_supplicant_set_anon_id;
Gabriel Biren3a2ec2c2022-03-07 17:59:41 +00001242 ctx->eap_method_selected_cb = wpa_supplicant_eap_method_selected_cb;
1243 ctx->open_ssl_failure_cb = wpa_supplicant_open_ssl_failure_cb;
Sunil8cd6f4d2022-06-28 18:40:46 +00001244 ctx->encryption_required = wpas_encryption_required;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 ctx->cb_ctx = wpa_s;
1246 wpa_s->eapol = eapol_sm_init(ctx);
1247 if (wpa_s->eapol == NULL) {
1248 os_free(ctx);
1249 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
1250 "machines.");
1251 return -1;
1252 }
1253#endif /* IEEE8021X_EAPOL */
1254
1255 return 0;
1256}
1257
1258
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001259#ifndef CONFIG_NO_WPA
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001260
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001261static void wpa_supplicant_set_rekey_offload(void *ctx,
1262 const u8 *kek, size_t kek_len,
1263 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001264 const u8 *replay_ctr)
1265{
1266 struct wpa_supplicant *wpa_s = ctx;
1267
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001268 wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269}
1270
1271
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001272static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
1273 size_t pmk_len)
1274{
1275 struct wpa_supplicant *wpa_s = ctx;
1276
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001277 if (wpa_s->conf->key_mgmt_offload &&
1278 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
Hai Shalomfdcde762020-04-02 11:19:20 -07001279 return wpa_drv_set_key(wpa_s, 0, NULL, 0, 0,
1280 NULL, 0, pmk, pmk_len, KEY_FLAG_PMK);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001281 else
1282 return 0;
1283}
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001284
1285
1286static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
1287 const u8 *pkt, size_t pkt_len)
1288{
1289 struct wpa_supplicant *wpa_s = ctx;
1290 char *hex;
1291 size_t hexlen;
1292
1293 hexlen = pkt_len * 2 + 1;
1294 hex = os_malloc(hexlen);
1295 if (!hex)
1296 return;
1297 wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
1298 wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
1299 " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
1300 os_free(hex);
1301}
1302
Hai Shalom74f70d42019-02-11 14:42:39 -08001303
1304static int wpa_supplicant_channel_info(void *_wpa_s,
1305 struct wpa_channel_info *ci)
1306{
1307 struct wpa_supplicant *wpa_s = _wpa_s;
1308
1309 return wpa_drv_channel_info(wpa_s, ci);
1310}
1311
Hai Shalomfdcde762020-04-02 11:19:20 -07001312
1313static void disable_wpa_wpa2(struct wpa_ssid *ssid)
1314{
1315 ssid->proto &= ~WPA_PROTO_WPA;
1316 ssid->proto |= WPA_PROTO_RSN;
1317 ssid->key_mgmt &= ~(WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK |
1318 WPA_KEY_MGMT_PSK_SHA256);
1319 ssid->group_cipher &= ~WPA_CIPHER_TKIP;
1320 if (!(ssid->group_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1321 WPA_CIPHER_GCMP_256 | WPA_CIPHER_CCMP_256)))
1322 ssid->group_cipher |= WPA_CIPHER_CCMP;
1323 ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1324}
1325
1326
1327static void wpa_supplicant_transition_disable(void *_wpa_s, u8 bitmap)
1328{
1329 struct wpa_supplicant *wpa_s = _wpa_s;
1330 struct wpa_ssid *ssid;
1331 int changed = 0;
1332
1333 wpa_msg(wpa_s, MSG_INFO, TRANSITION_DISABLE "%02x", bitmap);
1334
1335 ssid = wpa_s->current_ssid;
1336 if (!ssid)
1337 return;
1338
Hai Shalom899fcc72020-10-19 14:38:18 -07001339#ifdef CONFIG_SAE
Hai Shalomfdcde762020-04-02 11:19:20 -07001340 if ((bitmap & TRANSITION_DISABLE_WPA3_PERSONAL) &&
1341 wpa_key_mgmt_sae(wpa_s->key_mgmt) &&
1342 (ssid->key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE)) &&
1343 (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1344 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1345 wpa_printf(MSG_DEBUG,
1346 "WPA3-Personal transition mode disabled based on AP notification");
1347 disable_wpa_wpa2(ssid);
1348 changed = 1;
1349 }
1350
Hai Shalom899fcc72020-10-19 14:38:18 -07001351 if ((bitmap & TRANSITION_DISABLE_SAE_PK) &&
1352 wpa_key_mgmt_sae(wpa_s->key_mgmt) &&
1353#ifdef CONFIG_SME
1354 wpa_s->sme.sae.state == SAE_ACCEPTED &&
1355 wpa_s->sme.sae.pk &&
1356#endif /* CONFIG_SME */
1357 (ssid->key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE)) &&
1358 (ssid->sae_pk != SAE_PK_MODE_ONLY ||
1359 ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1360 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1361 wpa_printf(MSG_DEBUG,
1362 "SAE-PK: SAE authentication without PK disabled based on AP notification");
1363 disable_wpa_wpa2(ssid);
1364 ssid->sae_pk = SAE_PK_MODE_ONLY;
1365 changed = 1;
1366 }
1367#endif /* CONFIG_SAE */
1368
Hai Shalomfdcde762020-04-02 11:19:20 -07001369 if ((bitmap & TRANSITION_DISABLE_WPA3_ENTERPRISE) &&
1370 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
1371 (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X |
1372 WPA_KEY_MGMT_FT_IEEE8021X |
1373 WPA_KEY_MGMT_IEEE8021X_SHA256)) &&
1374 (ssid->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED ||
1375 (ssid->group_cipher & WPA_CIPHER_TKIP))) {
1376 disable_wpa_wpa2(ssid);
1377 changed = 1;
1378 }
1379
1380 if ((bitmap & TRANSITION_DISABLE_ENHANCED_OPEN) &&
1381 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
1382 (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1383 !ssid->owe_only) {
1384 ssid->owe_only = 1;
1385 changed = 1;
1386 }
1387
Vinayak Yadawade62409f2022-01-20 12:32:07 +05301388#ifdef CONFIG_DRIVER_NL80211_BRCM
1389 /* driver call for transition disable */
1390 {
1391 struct wpa_driver_associate_params params;
1392
1393 os_memset(&params, 0, sizeof(params));
1394 params.td_policy = bitmap;
1395 wpa_drv_update_connect_params(wpa_s, &params, WPA_DRV_UPDATE_TD_POLICY);
1396 }
1397#endif /* CONFIG_DRIVER_NL80211_BRCM */
1398
Jimmy Chen39deead2020-10-14 23:47:20 +08001399 wpas_notify_transition_disable(wpa_s, ssid, bitmap);
1400
Hai Shalomfdcde762020-04-02 11:19:20 -07001401 if (!changed)
1402 return;
1403
1404#ifndef CONFIG_NO_CONFIG_WRITE
1405 if (wpa_s->conf->update_config &&
1406 wpa_config_write(wpa_s->confname, wpa_s->conf))
1407 wpa_printf(MSG_DEBUG, "Failed to update configuration");
1408#endif /* CONFIG_NO_CONFIG_WRITE */
1409}
1410
Hai Shalom60840252021-02-19 19:02:11 -08001411
1412static void wpa_supplicant_store_ptk(void *ctx, u8 *addr, int cipher,
1413 u32 life_time, const struct wpa_ptk *ptk)
1414{
1415 struct wpa_supplicant *wpa_s = ctx;
1416
1417 ptksa_cache_add(wpa_s->ptksa, addr, cipher, life_time, ptk);
1418}
1419
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001420#endif /* CONFIG_NO_WPA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001421
1422
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001423int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
1424{
1425#ifndef CONFIG_NO_WPA
1426 struct wpa_sm_ctx *ctx;
Hai Shalom60840252021-02-19 19:02:11 -08001427
1428 wpa_s->ptksa = ptksa_cache_init();
1429 if (!wpa_s->ptksa) {
1430 wpa_printf(MSG_ERROR, "Failed to allocate PTKSA");
1431 return -1;
1432 }
1433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434 ctx = os_zalloc(sizeof(*ctx));
1435 if (ctx == NULL) {
1436 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
Hai Shalom60840252021-02-19 19:02:11 -08001437
1438 ptksa_cache_deinit(wpa_s->ptksa);
1439 wpa_s->ptksa = NULL;
1440
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001441 return -1;
1442 }
1443
1444 ctx->ctx = wpa_s;
1445 ctx->msg_ctx = wpa_s;
1446 ctx->set_state = _wpa_supplicant_set_state;
1447 ctx->get_state = _wpa_supplicant_get_state;
1448 ctx->deauthenticate = _wpa_supplicant_deauthenticate;
Hai Shalomfdcde762020-04-02 11:19:20 -07001449 ctx->reconnect = _wpa_supplicant_reconnect;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001450 ctx->set_key = wpa_supplicant_set_key;
1451 ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
1452 ctx->get_bssid = wpa_supplicant_get_bssid;
1453 ctx->ether_send = _wpa_ether_send;
1454 ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
1455 ctx->alloc_eapol = _wpa_alloc_eapol;
1456 ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
1457 ctx->add_pmkid = wpa_supplicant_add_pmkid;
1458 ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
1459#ifndef CONFIG_NO_CONFIG_BLOBS
1460 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1461 ctx->get_config_blob = wpa_supplicant_get_config_blob;
1462#endif /* CONFIG_NO_CONFIG_BLOBS */
1463 ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
1464#ifdef CONFIG_IEEE80211R
1465 ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
1466 ctx->send_ft_action = wpa_supplicant_send_ft_action;
1467 ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
1468#endif /* CONFIG_IEEE80211R */
1469#ifdef CONFIG_TDLS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001470 ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001471 ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
1472 ctx->tdls_oper = wpa_supplicant_tdls_oper;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001473 ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001474 ctx->tdls_enable_channel_switch =
1475 wpa_supplicant_tdls_enable_channel_switch;
1476 ctx->tdls_disable_channel_switch =
1477 wpa_supplicant_tdls_disable_channel_switch;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001478#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001479 ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001480 ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001481 ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
Hai Shalom74f70d42019-02-11 14:42:39 -08001482 ctx->channel_info = wpa_supplicant_channel_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001483 ctx->transition_disable = wpa_supplicant_transition_disable;
Hai Shalom60840252021-02-19 19:02:11 -08001484 ctx->store_ptk = wpa_supplicant_store_ptk;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485
1486 wpa_s->wpa = wpa_sm_init(ctx);
1487 if (wpa_s->wpa == NULL) {
Hai Shalom60840252021-02-19 19:02:11 -08001488 wpa_printf(MSG_ERROR,
1489 "Failed to initialize WPA state machine");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001490 os_free(ctx);
Hai Shalom60840252021-02-19 19:02:11 -08001491 ptksa_cache_deinit(wpa_s->ptksa);
1492 wpa_s->ptksa = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001493 return -1;
1494 }
1495#endif /* CONFIG_NO_WPA */
1496
1497 return 0;
1498}
1499
1500
1501void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
1502 struct wpa_ssid *ssid)
1503{
1504 struct rsn_supp_config conf;
1505 if (ssid) {
1506 os_memset(&conf, 0, sizeof(conf));
1507 conf.network_ctx = ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
1509#ifdef IEEE8021X_EAPOL
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001510 conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
1511 wpa_s->conf->okc : ssid->proactive_key_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 conf.eap_workaround = ssid->eap_workaround;
1513 conf.eap_conf_ctx = &ssid->eap;
1514#endif /* IEEE8021X_EAPOL */
1515 conf.ssid = ssid->ssid;
1516 conf.ssid_len = ssid->ssid_len;
1517 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
Hai Shalomfdcde762020-04-02 11:19:20 -07001518 conf.wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
1519 conf.owe_ptk_workaround = ssid->owe_ptk_workaround;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001520#ifdef CONFIG_P2P
1521 if (ssid->p2p_group && wpa_s->current_bss &&
1522 !wpa_s->p2p_disable_ip_addr_req) {
1523 struct wpabuf *p2p;
1524 p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
1525 P2P_IE_VENDOR_TYPE);
1526 if (p2p) {
1527 u8 group_capab;
1528 group_capab = p2p_get_group_capab(p2p);
1529 if (group_capab &
1530 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
1531 conf.p2p = 1;
1532 wpabuf_free(p2p);
1533 }
1534 }
1535#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001536 conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001537#ifdef CONFIG_FILS
1538 if (wpa_key_mgmt_fils(wpa_s->key_mgmt))
1539 conf.fils_cache_id =
1540 wpa_bss_get_fils_cache_id(wpa_s->current_bss);
1541#endif /* CONFIG_FILS */
Hai Shalom60840252021-02-19 19:02:11 -08001542 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
1543 (wpa_s->drv_flags2 &
1544 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
1545 conf.beacon_prot = ssid->beacon_prot;
1546
1547#ifdef CONFIG_PASN
1548#ifdef CONFIG_TESTING_OPTIONS
1549 conf.force_kdk_derivation = wpa_s->conf->force_kdk_derivation;
1550#endif /* CONFIG_TESTING_OPTIONS */
1551#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001552 }
1553 wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
1554}