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