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