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