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