xref: /freebsd/contrib/wpa/src/ap/wpa_auth_glue.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1e28a4053SRui Paulo /*
2e28a4053SRui Paulo  * hostapd / WPA authenticator glue code
3*a90b9d01SCy Schubert  * Copyright (c) 2002-2022, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
7e28a4053SRui Paulo  */
8e28a4053SRui Paulo 
9e28a4053SRui Paulo #include "utils/includes.h"
10e28a4053SRui Paulo 
11e28a4053SRui Paulo #include "utils/common.h"
1285732ac8SCy Schubert #include "utils/eloop.h"
1385732ac8SCy Schubert #include "utils/list.h"
14e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
155b9c547cSRui Paulo #include "common/sae.h"
16325151a3SRui Paulo #include "common/wpa_ctrl.h"
17c1d255d3SCy Schubert #include "common/ptksa_cache.h"
18780fb4a2SCy Schubert #include "crypto/sha1.h"
19e28a4053SRui Paulo #include "eapol_auth/eapol_auth_sm.h"
20e28a4053SRui Paulo #include "eapol_auth/eapol_auth_sm_i.h"
21e28a4053SRui Paulo #include "eap_server/eap.h"
22e28a4053SRui Paulo #include "l2_packet/l2_packet.h"
2385732ac8SCy Schubert #include "eth_p_oui.h"
24e28a4053SRui Paulo #include "hostapd.h"
25e28a4053SRui Paulo #include "ieee802_1x.h"
26e28a4053SRui Paulo #include "preauth_auth.h"
27e28a4053SRui Paulo #include "sta_info.h"
28e28a4053SRui Paulo #include "tkip_countermeasures.h"
29e28a4053SRui Paulo #include "ap_drv_ops.h"
30e28a4053SRui Paulo #include "ap_config.h"
314bc52338SCy Schubert #include "ieee802_11.h"
32*a90b9d01SCy Schubert #include "ieee802_11_auth.h"
3385732ac8SCy Schubert #include "pmksa_cache_auth.h"
34e28a4053SRui Paulo #include "wpa_auth.h"
35f05cddf9SRui Paulo #include "wpa_auth_glue.h"
36e28a4053SRui Paulo 
37e28a4053SRui Paulo 
hostapd_wpa_auth_conf(struct hostapd_bss_config * conf,struct hostapd_config * iconf,struct wpa_auth_config * wconf)38e28a4053SRui Paulo static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
395b9c547cSRui Paulo 				  struct hostapd_config *iconf,
40e28a4053SRui Paulo 				  struct wpa_auth_config *wconf)
41e28a4053SRui Paulo {
42c1d255d3SCy Schubert 	int sae_pw_id;
43c1d255d3SCy Schubert 
44f05cddf9SRui Paulo 	os_memset(wconf, 0, sizeof(*wconf));
45e28a4053SRui Paulo 	wconf->wpa = conf->wpa;
46c1d255d3SCy Schubert 	wconf->extended_key_id = conf->extended_key_id;
47e28a4053SRui Paulo 	wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
48e28a4053SRui Paulo 	wconf->wpa_pairwise = conf->wpa_pairwise;
49e28a4053SRui Paulo 	wconf->wpa_group = conf->wpa_group;
50e28a4053SRui Paulo 	wconf->wpa_group_rekey = conf->wpa_group_rekey;
51e28a4053SRui Paulo 	wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
52e28a4053SRui Paulo 	wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
53e28a4053SRui Paulo 	wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
5485732ac8SCy Schubert 	wconf->wpa_group_update_count = conf->wpa_group_update_count;
5585732ac8SCy Schubert 	wconf->wpa_disable_eapol_key_retries =
5685732ac8SCy Schubert 		conf->wpa_disable_eapol_key_retries;
5785732ac8SCy Schubert 	wconf->wpa_pairwise_update_count = conf->wpa_pairwise_update_count;
58e28a4053SRui Paulo 	wconf->rsn_pairwise = conf->rsn_pairwise;
59e28a4053SRui Paulo 	wconf->rsn_preauth = conf->rsn_preauth;
60e28a4053SRui Paulo 	wconf->eapol_version = conf->eapol_version;
61206b73d0SCy Schubert #ifdef CONFIG_MACSEC
62206b73d0SCy Schubert 	if (wconf->eapol_version > 2)
63206b73d0SCy Schubert 		wconf->eapol_version = 2;
64206b73d0SCy Schubert #endif /* CONFIG_MACSEC */
65e28a4053SRui Paulo 	wconf->wmm_enabled = conf->wmm_enabled;
66e28a4053SRui Paulo 	wconf->wmm_uapsd = conf->wmm_uapsd;
67f05cddf9SRui Paulo 	wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
684bc52338SCy Schubert #ifdef CONFIG_OCV
694bc52338SCy Schubert 	wconf->ocv = conf->ocv;
704bc52338SCy Schubert #endif /* CONFIG_OCV */
71e28a4053SRui Paulo 	wconf->okc = conf->okc;
72e28a4053SRui Paulo 	wconf->ieee80211w = conf->ieee80211w;
73c1d255d3SCy Schubert 	wconf->beacon_prot = conf->beacon_prot;
745b9c547cSRui Paulo 	wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
7585732ac8SCy Schubert 	wconf->sae_require_mfp = conf->sae_require_mfp;
76*a90b9d01SCy Schubert 	wconf->ssid_protection = conf->ssid_protection;
77e28a4053SRui Paulo 	wconf->ssid_len = conf->ssid.ssid_len;
78325151a3SRui Paulo 	if (wconf->ssid_len > SSID_MAX_LEN)
79325151a3SRui Paulo 		wconf->ssid_len = SSID_MAX_LEN;
80e28a4053SRui Paulo 	os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
81*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211R_AP
82e28a4053SRui Paulo 	os_memcpy(wconf->mobility_domain, conf->mobility_domain,
83e28a4053SRui Paulo 		  MOBILITY_DOMAIN_ID_LEN);
84e28a4053SRui Paulo 	if (conf->nas_identifier &&
85e28a4053SRui Paulo 	    os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
86e28a4053SRui Paulo 		wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
87e28a4053SRui Paulo 		os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
88e28a4053SRui Paulo 			  wconf->r0_key_holder_len);
89e28a4053SRui Paulo 	}
90e28a4053SRui Paulo 	os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
91e28a4053SRui Paulo 	wconf->r0_key_lifetime = conf->r0_key_lifetime;
9285732ac8SCy Schubert 	wconf->r1_max_key_lifetime = conf->r1_max_key_lifetime;
93e28a4053SRui Paulo 	wconf->reassociation_deadline = conf->reassociation_deadline;
9485732ac8SCy Schubert 	wconf->rkh_pos_timeout = conf->rkh_pos_timeout;
9585732ac8SCy Schubert 	wconf->rkh_neg_timeout = conf->rkh_neg_timeout;
9685732ac8SCy Schubert 	wconf->rkh_pull_timeout = conf->rkh_pull_timeout;
9785732ac8SCy Schubert 	wconf->rkh_pull_retries = conf->rkh_pull_retries;
9885732ac8SCy Schubert 	wconf->r0kh_list = &conf->r0kh_list;
9985732ac8SCy Schubert 	wconf->r1kh_list = &conf->r1kh_list;
100e28a4053SRui Paulo 	wconf->pmk_r1_push = conf->pmk_r1_push;
101f05cddf9SRui Paulo 	wconf->ft_over_ds = conf->ft_over_ds;
10285732ac8SCy Schubert 	wconf->ft_psk_generate_local = conf->ft_psk_generate_local;
10385732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
104f05cddf9SRui Paulo #ifdef CONFIG_HS20
105f05cddf9SRui Paulo 	wconf->disable_gtk = conf->disable_dgaf;
1065b9c547cSRui Paulo 	if (conf->osen) {
1075b9c547cSRui Paulo 		wconf->disable_gtk = 1;
1085b9c547cSRui Paulo 		wconf->wpa = WPA_PROTO_OSEN;
1095b9c547cSRui Paulo 		wconf->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
1105b9c547cSRui Paulo 		wconf->wpa_pairwise = 0;
1115b9c547cSRui Paulo 		wconf->wpa_group = WPA_CIPHER_CCMP;
1125b9c547cSRui Paulo 		wconf->rsn_pairwise = WPA_CIPHER_CCMP;
1135b9c547cSRui Paulo 		wconf->rsn_preauth = 0;
1145b9c547cSRui Paulo 		wconf->disable_pmksa_caching = 1;
1155b9c547cSRui Paulo 		wconf->ieee80211w = 1;
1165b9c547cSRui Paulo 	}
117f05cddf9SRui Paulo #endif /* CONFIG_HS20 */
1185b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
1195b9c547cSRui Paulo 	wconf->corrupt_gtk_rekey_mic_probability =
1205b9c547cSRui Paulo 		iconf->corrupt_gtk_rekey_mic_probability;
121*a90b9d01SCy Schubert 	wconf->delay_eapol_tx = iconf->delay_eapol_tx;
122325151a3SRui Paulo 	if (conf->own_ie_override &&
123325151a3SRui Paulo 	    wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
124325151a3SRui Paulo 		wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
125325151a3SRui Paulo 		os_memcpy(wconf->own_ie_override,
126325151a3SRui Paulo 			  wpabuf_head(conf->own_ie_override),
127325151a3SRui Paulo 			  wconf->own_ie_override_len);
128325151a3SRui Paulo 	}
129c1d255d3SCy Schubert 	if (conf->rsne_override_eapol &&
130c1d255d3SCy Schubert 	    wpabuf_len(conf->rsne_override_eapol) <= MAX_OWN_IE_OVERRIDE) {
131c1d255d3SCy Schubert 		wconf->rsne_override_eapol_set = 1;
132c1d255d3SCy Schubert 		wconf->rsne_override_eapol_len =
133c1d255d3SCy Schubert 			wpabuf_len(conf->rsne_override_eapol);
134c1d255d3SCy Schubert 		os_memcpy(wconf->rsne_override_eapol,
135c1d255d3SCy Schubert 			  wpabuf_head(conf->rsne_override_eapol),
136c1d255d3SCy Schubert 			  wconf->rsne_override_eapol_len);
137c1d255d3SCy Schubert 	}
138c1d255d3SCy Schubert 	if (conf->rsnxe_override_eapol &&
139c1d255d3SCy Schubert 	    wpabuf_len(conf->rsnxe_override_eapol) <= MAX_OWN_IE_OVERRIDE) {
140c1d255d3SCy Schubert 		wconf->rsnxe_override_eapol_set = 1;
141c1d255d3SCy Schubert 		wconf->rsnxe_override_eapol_len =
142c1d255d3SCy Schubert 			wpabuf_len(conf->rsnxe_override_eapol);
143c1d255d3SCy Schubert 		os_memcpy(wconf->rsnxe_override_eapol,
144c1d255d3SCy Schubert 			  wpabuf_head(conf->rsnxe_override_eapol),
145c1d255d3SCy Schubert 			  wconf->rsnxe_override_eapol_len);
146c1d255d3SCy Schubert 	}
147c1d255d3SCy Schubert 	if (conf->rsne_override_ft &&
148c1d255d3SCy Schubert 	    wpabuf_len(conf->rsne_override_ft) <= MAX_OWN_IE_OVERRIDE) {
149c1d255d3SCy Schubert 		wconf->rsne_override_ft_set = 1;
150c1d255d3SCy Schubert 		wconf->rsne_override_ft_len =
151c1d255d3SCy Schubert 			wpabuf_len(conf->rsne_override_ft);
152c1d255d3SCy Schubert 		os_memcpy(wconf->rsne_override_ft,
153c1d255d3SCy Schubert 			  wpabuf_head(conf->rsne_override_ft),
154c1d255d3SCy Schubert 			  wconf->rsne_override_ft_len);
155c1d255d3SCy Schubert 	}
156c1d255d3SCy Schubert 	if (conf->rsnxe_override_ft &&
157c1d255d3SCy Schubert 	    wpabuf_len(conf->rsnxe_override_ft) <= MAX_OWN_IE_OVERRIDE) {
158c1d255d3SCy Schubert 		wconf->rsnxe_override_ft_set = 1;
159c1d255d3SCy Schubert 		wconf->rsnxe_override_ft_len =
160c1d255d3SCy Schubert 			wpabuf_len(conf->rsnxe_override_ft);
161c1d255d3SCy Schubert 		os_memcpy(wconf->rsnxe_override_ft,
162c1d255d3SCy Schubert 			  wpabuf_head(conf->rsnxe_override_ft),
163c1d255d3SCy Schubert 			  wconf->rsnxe_override_ft_len);
164c1d255d3SCy Schubert 	}
165c1d255d3SCy Schubert 	if (conf->gtk_rsc_override &&
166c1d255d3SCy Schubert 	    wpabuf_len(conf->gtk_rsc_override) > 0 &&
167c1d255d3SCy Schubert 	    wpabuf_len(conf->gtk_rsc_override) <= WPA_KEY_RSC_LEN) {
168c1d255d3SCy Schubert 		os_memcpy(wconf->gtk_rsc_override,
169c1d255d3SCy Schubert 			  wpabuf_head(conf->gtk_rsc_override),
170c1d255d3SCy Schubert 			  wpabuf_len(conf->gtk_rsc_override));
171c1d255d3SCy Schubert 		wconf->gtk_rsc_override_set = 1;
172c1d255d3SCy Schubert 	}
173c1d255d3SCy Schubert 	if (conf->igtk_rsc_override &&
174c1d255d3SCy Schubert 	    wpabuf_len(conf->igtk_rsc_override) > 0 &&
175c1d255d3SCy Schubert 	    wpabuf_len(conf->igtk_rsc_override) <= WPA_KEY_RSC_LEN) {
176c1d255d3SCy Schubert 		os_memcpy(wconf->igtk_rsc_override,
177c1d255d3SCy Schubert 			  wpabuf_head(conf->igtk_rsc_override),
178c1d255d3SCy Schubert 			  wpabuf_len(conf->igtk_rsc_override));
179c1d255d3SCy Schubert 		wconf->igtk_rsc_override_set = 1;
180c1d255d3SCy Schubert 	}
181c1d255d3SCy Schubert 	wconf->ft_rsnxe_used = conf->ft_rsnxe_used;
182c1d255d3SCy Schubert 	wconf->oci_freq_override_eapol_m3 = conf->oci_freq_override_eapol_m3;
183c1d255d3SCy Schubert 	wconf->oci_freq_override_eapol_g1 = conf->oci_freq_override_eapol_g1;
184c1d255d3SCy Schubert 	wconf->oci_freq_override_ft_assoc = conf->oci_freq_override_ft_assoc;
185c1d255d3SCy Schubert 	wconf->oci_freq_override_fils_assoc =
186c1d255d3SCy Schubert 		conf->oci_freq_override_fils_assoc;
187*a90b9d01SCy Schubert 
188*a90b9d01SCy Schubert 	if (conf->eapol_m1_elements)
189*a90b9d01SCy Schubert 		wconf->eapol_m1_elements = wpabuf_dup(conf->eapol_m1_elements);
190*a90b9d01SCy Schubert 	if (conf->eapol_m3_elements)
191*a90b9d01SCy Schubert 		wconf->eapol_m3_elements = wpabuf_dup(conf->eapol_m3_elements);
192*a90b9d01SCy Schubert 	wconf->eapol_m3_no_encrypt = conf->eapol_m3_no_encrypt;
1935b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
1945b9c547cSRui Paulo #ifdef CONFIG_P2P
1955b9c547cSRui Paulo 	os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
1965b9c547cSRui Paulo 	os_memcpy(wconf->ip_addr_mask, conf->ip_addr_mask, 4);
1975b9c547cSRui Paulo 	os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
1985b9c547cSRui Paulo 	os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
1995b9c547cSRui Paulo #endif /* CONFIG_P2P */
20085732ac8SCy Schubert #ifdef CONFIG_FILS
20185732ac8SCy Schubert 	wconf->fils_cache_id_set = conf->fils_cache_id_set;
20285732ac8SCy Schubert 	os_memcpy(wconf->fils_cache_id, conf->fils_cache_id,
20385732ac8SCy Schubert 		  FILS_CACHE_ID_LEN);
20485732ac8SCy Schubert #endif /* CONFIG_FILS */
205c1d255d3SCy Schubert 	wconf->sae_pwe = conf->sae_pwe;
206c1d255d3SCy Schubert 	sae_pw_id = hostapd_sae_pw_id_in_use(conf);
207*a90b9d01SCy Schubert 	if (sae_pw_id == 2 && wconf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK)
208*a90b9d01SCy Schubert 		wconf->sae_pwe = SAE_PWE_HASH_TO_ELEMENT;
209*a90b9d01SCy Schubert 	else if (sae_pw_id == 1 && wconf->sae_pwe == SAE_PWE_HUNT_AND_PECK)
210*a90b9d01SCy Schubert 		wconf->sae_pwe = SAE_PWE_BOTH;
211c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK
212c1d255d3SCy Schubert 	wconf->sae_pk = hostapd_sae_pk_in_use(conf);
213c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */
214c1d255d3SCy Schubert #ifdef CONFIG_OWE
215c1d255d3SCy Schubert 	wconf->owe_ptk_workaround = conf->owe_ptk_workaround;
216c1d255d3SCy Schubert #endif /* CONFIG_OWE */
217c1d255d3SCy Schubert 	wconf->transition_disable = conf->transition_disable;
218c1d255d3SCy Schubert #ifdef CONFIG_DPP2
219c1d255d3SCy Schubert 	wconf->dpp_pfs = conf->dpp_pfs;
220c1d255d3SCy Schubert #endif /* CONFIG_DPP2 */
221c1d255d3SCy Schubert #ifdef CONFIG_PASN
222c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
223c1d255d3SCy Schubert 	wconf->force_kdk_derivation = conf->force_kdk_derivation;
224c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
225c1d255d3SCy Schubert #endif /* CONFIG_PASN */
226*a90b9d01SCy Schubert 
227*a90b9d01SCy Schubert 	wconf->radius_psk = conf->wpa_psk_radius == PSK_RADIUS_DURING_4WAY_HS;
228*a90b9d01SCy Schubert 	wconf->no_disconnect_on_group_keyerror =
229*a90b9d01SCy Schubert 		conf->bss_max_idle && conf->ap_max_inactivity &&
230*a90b9d01SCy Schubert 		conf->no_disconnect_on_group_keyerror;
231e28a4053SRui Paulo }
232e28a4053SRui Paulo 
233e28a4053SRui Paulo 
hostapd_wpa_auth_logger(void * ctx,const u8 * addr,logger_level level,const char * txt)234e28a4053SRui Paulo static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
235e28a4053SRui Paulo 				    logger_level level, const char *txt)
236e28a4053SRui Paulo {
237e28a4053SRui Paulo #ifndef CONFIG_NO_HOSTAPD_LOGGER
238e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
239e28a4053SRui Paulo 	int hlevel;
240e28a4053SRui Paulo 
241e28a4053SRui Paulo 	switch (level) {
242e28a4053SRui Paulo 	case LOGGER_WARNING:
243e28a4053SRui Paulo 		hlevel = HOSTAPD_LEVEL_WARNING;
244e28a4053SRui Paulo 		break;
245e28a4053SRui Paulo 	case LOGGER_INFO:
246e28a4053SRui Paulo 		hlevel = HOSTAPD_LEVEL_INFO;
247e28a4053SRui Paulo 		break;
248e28a4053SRui Paulo 	case LOGGER_DEBUG:
249e28a4053SRui Paulo 	default:
250e28a4053SRui Paulo 		hlevel = HOSTAPD_LEVEL_DEBUG;
251e28a4053SRui Paulo 		break;
252e28a4053SRui Paulo 	}
253e28a4053SRui Paulo 
254e28a4053SRui Paulo 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
255e28a4053SRui Paulo #endif /* CONFIG_NO_HOSTAPD_LOGGER */
256e28a4053SRui Paulo }
257e28a4053SRui Paulo 
258e28a4053SRui Paulo 
hostapd_wpa_auth_disconnect(void * ctx,const u8 * addr,u16 reason)259e28a4053SRui Paulo static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
260e28a4053SRui Paulo 					u16 reason)
261e28a4053SRui Paulo {
262e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
263e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
264e28a4053SRui Paulo 		   "STA " MACSTR " reason %d",
265e28a4053SRui Paulo 		   __func__, MAC2STR(addr), reason);
266e28a4053SRui Paulo 	ap_sta_disconnect(hapd, NULL, addr, reason);
267e28a4053SRui Paulo }
268e28a4053SRui Paulo 
269e28a4053SRui Paulo 
hostapd_wpa_auth_mic_failure_report(void * ctx,const u8 * addr)270f05cddf9SRui Paulo static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
271e28a4053SRui Paulo {
272e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
273f05cddf9SRui Paulo 	return michael_mic_failure(hapd, addr, 0);
274e28a4053SRui Paulo }
275e28a4053SRui Paulo 
276e28a4053SRui Paulo 
hostapd_wpa_auth_psk_failure_report(void * ctx,const u8 * addr)277325151a3SRui Paulo static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
278325151a3SRui Paulo {
279325151a3SRui Paulo 	struct hostapd_data *hapd = ctx;
280325151a3SRui Paulo 	wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
281325151a3SRui Paulo 		MAC2STR(addr));
282325151a3SRui Paulo }
283325151a3SRui Paulo 
284325151a3SRui Paulo 
hostapd_wpa_auth_set_eapol(void * ctx,const u8 * addr,wpa_eapol_variable var,int value)285e28a4053SRui Paulo static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
286e28a4053SRui Paulo 				       wpa_eapol_variable var, int value)
287e28a4053SRui Paulo {
288e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
289e28a4053SRui Paulo 	struct sta_info *sta = ap_get_sta(hapd, addr);
290e28a4053SRui Paulo 	if (sta == NULL)
291e28a4053SRui Paulo 		return;
292e28a4053SRui Paulo 	switch (var) {
293e28a4053SRui Paulo 	case WPA_EAPOL_portEnabled:
294e28a4053SRui Paulo 		ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
295e28a4053SRui Paulo 		break;
296e28a4053SRui Paulo 	case WPA_EAPOL_portValid:
297e28a4053SRui Paulo 		ieee802_1x_notify_port_valid(sta->eapol_sm, value);
298e28a4053SRui Paulo 		break;
299e28a4053SRui Paulo 	case WPA_EAPOL_authorized:
300e28a4053SRui Paulo 		ieee802_1x_set_sta_authorized(hapd, sta, value);
301e28a4053SRui Paulo 		break;
302e28a4053SRui Paulo 	case WPA_EAPOL_portControl_Auto:
303e28a4053SRui Paulo 		if (sta->eapol_sm)
304e28a4053SRui Paulo 			sta->eapol_sm->portControl = Auto;
305e28a4053SRui Paulo 		break;
306e28a4053SRui Paulo 	case WPA_EAPOL_keyRun:
307e28a4053SRui Paulo 		if (sta->eapol_sm)
308c1d255d3SCy Schubert 			sta->eapol_sm->keyRun = value;
309e28a4053SRui Paulo 		break;
310e28a4053SRui Paulo 	case WPA_EAPOL_keyAvailable:
311e28a4053SRui Paulo 		if (sta->eapol_sm)
312c1d255d3SCy Schubert 			sta->eapol_sm->eap_if->eapKeyAvailable = value;
313e28a4053SRui Paulo 		break;
314e28a4053SRui Paulo 	case WPA_EAPOL_keyDone:
315e28a4053SRui Paulo 		if (sta->eapol_sm)
316c1d255d3SCy Schubert 			sta->eapol_sm->keyDone = value;
317e28a4053SRui Paulo 		break;
318e28a4053SRui Paulo 	case WPA_EAPOL_inc_EapolFramesTx:
319e28a4053SRui Paulo 		if (sta->eapol_sm)
320e28a4053SRui Paulo 			sta->eapol_sm->dot1xAuthEapolFramesTx++;
321e28a4053SRui Paulo 		break;
322e28a4053SRui Paulo 	}
323e28a4053SRui Paulo }
324e28a4053SRui Paulo 
325e28a4053SRui Paulo 
hostapd_wpa_auth_get_eapol(void * ctx,const u8 * addr,wpa_eapol_variable var)326e28a4053SRui Paulo static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
327e28a4053SRui Paulo 				      wpa_eapol_variable var)
328e28a4053SRui Paulo {
329e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
330e28a4053SRui Paulo 	struct sta_info *sta = ap_get_sta(hapd, addr);
331e28a4053SRui Paulo 	if (sta == NULL || sta->eapol_sm == NULL)
332e28a4053SRui Paulo 		return -1;
333e28a4053SRui Paulo 	switch (var) {
334e28a4053SRui Paulo 	case WPA_EAPOL_keyRun:
335e28a4053SRui Paulo 		return sta->eapol_sm->keyRun;
336e28a4053SRui Paulo 	case WPA_EAPOL_keyAvailable:
337e28a4053SRui Paulo 		return sta->eapol_sm->eap_if->eapKeyAvailable;
338e28a4053SRui Paulo 	default:
339e28a4053SRui Paulo 		return -1;
340e28a4053SRui Paulo 	}
341e28a4053SRui Paulo }
342e28a4053SRui Paulo 
343e28a4053SRui Paulo 
hostapd_wpa_auth_get_psk(void * ctx,const u8 * addr,const u8 * p2p_dev_addr,const u8 * prev_psk,size_t * psk_len,int * vlan_id)344e28a4053SRui Paulo static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
3455b9c547cSRui Paulo 					   const u8 *p2p_dev_addr,
3464bc52338SCy Schubert 					   const u8 *prev_psk, size_t *psk_len,
3474bc52338SCy Schubert 					   int *vlan_id)
348e28a4053SRui Paulo {
349e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
350f05cddf9SRui Paulo 	struct sta_info *sta = ap_get_sta(hapd, addr);
3515b9c547cSRui Paulo 	const u8 *psk;
3525b9c547cSRui Paulo 
3534bc52338SCy Schubert 	if (vlan_id)
3544bc52338SCy Schubert 		*vlan_id = 0;
35585732ac8SCy Schubert 	if (psk_len)
35685732ac8SCy Schubert 		*psk_len = PMK_LEN;
35785732ac8SCy Schubert 
3585b9c547cSRui Paulo #ifdef CONFIG_SAE
3595b9c547cSRui Paulo 	if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
3605b9c547cSRui Paulo 		if (!sta->sae || prev_psk)
3615b9c547cSRui Paulo 			return NULL;
362*a90b9d01SCy Schubert 		if (psk_len)
363*a90b9d01SCy Schubert 			*psk_len = sta->sae->pmk_len;
3645b9c547cSRui Paulo 		return sta->sae->pmk;
3655b9c547cSRui Paulo 	}
36685732ac8SCy Schubert 	if (sta && wpa_auth_uses_sae(sta->wpa_sm)) {
36785732ac8SCy Schubert 		wpa_printf(MSG_DEBUG,
36885732ac8SCy Schubert 			   "No PSK for STA trying to use SAE with PMKSA caching");
36985732ac8SCy Schubert 		return NULL;
37085732ac8SCy Schubert 	}
3715b9c547cSRui Paulo #endif /* CONFIG_SAE */
3725b9c547cSRui Paulo 
37385732ac8SCy Schubert #ifdef CONFIG_OWE
37485732ac8SCy Schubert 	if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
37585732ac8SCy Schubert 	    sta && sta->owe_pmk) {
37685732ac8SCy Schubert 		if (psk_len)
37785732ac8SCy Schubert 			*psk_len = sta->owe_pmk_len;
37885732ac8SCy Schubert 		return sta->owe_pmk;
37985732ac8SCy Schubert 	}
38085732ac8SCy Schubert 	if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && sta) {
38185732ac8SCy Schubert 		struct rsn_pmksa_cache_entry *sa;
38285732ac8SCy Schubert 
38385732ac8SCy Schubert 		sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
38485732ac8SCy Schubert 		if (sa && sa->akmp == WPA_KEY_MGMT_OWE) {
38585732ac8SCy Schubert 			if (psk_len)
38685732ac8SCy Schubert 				*psk_len = sa->pmk_len;
38785732ac8SCy Schubert 			return sa->pmk;
38885732ac8SCy Schubert 		}
38985732ac8SCy Schubert 	}
39085732ac8SCy Schubert #endif /* CONFIG_OWE */
39185732ac8SCy Schubert 
3924bc52338SCy Schubert 	psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk,
3934bc52338SCy Schubert 			      vlan_id);
394f05cddf9SRui Paulo 	/*
395f05cddf9SRui Paulo 	 * This is about to iterate over all psks, prev_psk gives the last
396f05cddf9SRui Paulo 	 * returned psk which should not be returned again.
397f05cddf9SRui Paulo 	 * logic list (all hostapd_get_psk; all sta->psk)
398f05cddf9SRui Paulo 	 */
399f05cddf9SRui Paulo 	if (sta && sta->psk && !psk) {
400f05cddf9SRui Paulo 		struct hostapd_sta_wpa_psk_short *pos;
4014bc52338SCy Schubert 
4024bc52338SCy Schubert 		if (vlan_id)
4034bc52338SCy Schubert 			*vlan_id = 0;
404f05cddf9SRui Paulo 		psk = sta->psk->psk;
405f05cddf9SRui Paulo 		for (pos = sta->psk; pos; pos = pos->next) {
406780fb4a2SCy Schubert 			if (pos->is_passphrase) {
407*a90b9d01SCy Schubert 				if (pbkdf2_sha1(pos->passphrase,
408780fb4a2SCy Schubert 						hapd->conf->ssid.ssid,
409780fb4a2SCy Schubert 						hapd->conf->ssid.ssid_len, 4096,
410*a90b9d01SCy Schubert 						pos->psk, PMK_LEN) != 0) {
411*a90b9d01SCy Schubert 					wpa_printf(MSG_WARNING,
412*a90b9d01SCy Schubert 						   "Error in pbkdf2_sha1()");
413*a90b9d01SCy Schubert 					continue;
414*a90b9d01SCy Schubert 				}
415780fb4a2SCy Schubert 				pos->is_passphrase = 0;
416780fb4a2SCy Schubert 			}
417f05cddf9SRui Paulo 			if (pos->psk == prev_psk) {
418f05cddf9SRui Paulo 				psk = pos->next ? pos->next->psk : NULL;
419f05cddf9SRui Paulo 				break;
420f05cddf9SRui Paulo 			}
421f05cddf9SRui Paulo 		}
422f05cddf9SRui Paulo 	}
423f05cddf9SRui Paulo 	return psk;
424e28a4053SRui Paulo }
425e28a4053SRui Paulo 
426e28a4053SRui Paulo 
hostapd_wpa_auth_get_msk(void * ctx,const u8 * addr,u8 * msk,size_t * len)427e28a4053SRui Paulo static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
428e28a4053SRui Paulo 				    size_t *len)
429e28a4053SRui Paulo {
430e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
431e28a4053SRui Paulo 	const u8 *key;
432e28a4053SRui Paulo 	size_t keylen;
433e28a4053SRui Paulo 	struct sta_info *sta;
434e28a4053SRui Paulo 
435e28a4053SRui Paulo 	sta = ap_get_sta(hapd, addr);
4365b9c547cSRui Paulo 	if (sta == NULL) {
4375b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
438e28a4053SRui Paulo 		return -1;
4395b9c547cSRui Paulo 	}
440e28a4053SRui Paulo 
441e28a4053SRui Paulo 	key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
4425b9c547cSRui Paulo 	if (key == NULL) {
4435b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
4445b9c547cSRui Paulo 			   sta->eapol_sm);
445e28a4053SRui Paulo 		return -1;
4465b9c547cSRui Paulo 	}
447e28a4053SRui Paulo 
448e28a4053SRui Paulo 	if (keylen > *len)
449e28a4053SRui Paulo 		keylen = *len;
450e28a4053SRui Paulo 	os_memcpy(msk, key, keylen);
451e28a4053SRui Paulo 	*len = keylen;
452e28a4053SRui Paulo 
453e28a4053SRui Paulo 	return 0;
454e28a4053SRui Paulo }
455e28a4053SRui Paulo 
456e28a4053SRui Paulo 
hostapd_wpa_auth_set_key(void * ctx,int vlan_id,enum wpa_alg alg,const u8 * addr,int idx,u8 * key,size_t key_len,enum key_flag key_flag)457e28a4053SRui Paulo static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
458e28a4053SRui Paulo 				    const u8 *addr, int idx, u8 *key,
459c1d255d3SCy Schubert 				    size_t key_len, enum key_flag key_flag)
460e28a4053SRui Paulo {
461e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
462e28a4053SRui Paulo 	const char *ifname = hapd->conf->iface;
463e28a4053SRui Paulo 
464e28a4053SRui Paulo 	if (vlan_id > 0) {
465e28a4053SRui Paulo 		ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
466c1d255d3SCy Schubert 		if (!ifname) {
467c1d255d3SCy Schubert 			if (!(hapd->iface->drv_flags &
468c1d255d3SCy Schubert 			      WPA_DRIVER_FLAGS_VLAN_OFFLOAD))
469e28a4053SRui Paulo 				return -1;
470c1d255d3SCy Schubert 			ifname = hapd->conf->iface;
471c1d255d3SCy Schubert 		}
472e28a4053SRui Paulo 	}
473e28a4053SRui Paulo 
47485732ac8SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
475c1d255d3SCy Schubert 	if (key_flag & KEY_FLAG_MODIFY) {
476c1d255d3SCy Schubert 		/* We are updating an already installed key. Don't overwrite
477c1d255d3SCy Schubert 		 * the already stored key information with zeros.
478c1d255d3SCy Schubert 		 */
479c1d255d3SCy Schubert 	} else if (addr && !is_broadcast_ether_addr(addr)) {
48085732ac8SCy Schubert 		struct sta_info *sta;
48185732ac8SCy Schubert 
48285732ac8SCy Schubert 		sta = ap_get_sta(hapd, addr);
48385732ac8SCy Schubert 		if (sta) {
48485732ac8SCy Schubert 			sta->last_tk_alg = alg;
48585732ac8SCy Schubert 			sta->last_tk_key_idx = idx;
48685732ac8SCy Schubert 			if (key)
48785732ac8SCy Schubert 				os_memcpy(sta->last_tk, key, key_len);
48885732ac8SCy Schubert 			sta->last_tk_len = key_len;
48985732ac8SCy Schubert 		}
490c1d255d3SCy Schubert 	} else if (alg == WPA_ALG_BIP_CMAC_128 ||
49185732ac8SCy Schubert 		   alg == WPA_ALG_BIP_GMAC_128 ||
49285732ac8SCy Schubert 		   alg == WPA_ALG_BIP_GMAC_256 ||
49385732ac8SCy Schubert 		   alg == WPA_ALG_BIP_CMAC_256) {
494c1d255d3SCy Schubert 		if (idx == 4 || idx == 5) {
49585732ac8SCy Schubert 			hapd->last_igtk_alg = alg;
49685732ac8SCy Schubert 			hapd->last_igtk_key_idx = idx;
49785732ac8SCy Schubert 			if (key)
49885732ac8SCy Schubert 				os_memcpy(hapd->last_igtk, key, key_len);
49985732ac8SCy Schubert 			hapd->last_igtk_len = key_len;
500c1d255d3SCy Schubert 		} else if (idx == 6 || idx == 7) {
501c1d255d3SCy Schubert 			hapd->last_bigtk_alg = alg;
502c1d255d3SCy Schubert 			hapd->last_bigtk_key_idx = idx;
503c1d255d3SCy Schubert 			if (key)
504c1d255d3SCy Schubert 				os_memcpy(hapd->last_bigtk, key, key_len);
505c1d255d3SCy Schubert 			hapd->last_bigtk_len = key_len;
506c1d255d3SCy Schubert 		}
50785732ac8SCy Schubert 	} else {
50885732ac8SCy Schubert 		hapd->last_gtk_alg = alg;
50985732ac8SCy Schubert 		hapd->last_gtk_key_idx = idx;
51085732ac8SCy Schubert 		if (key)
51185732ac8SCy Schubert 			os_memcpy(hapd->last_gtk, key, key_len);
51285732ac8SCy Schubert 		hapd->last_gtk_len = key_len;
51385732ac8SCy Schubert 	}
51485732ac8SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
515c1d255d3SCy Schubert 	return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, vlan_id, 1,
516c1d255d3SCy Schubert 				   NULL, 0, key, key_len, key_flag);
517e28a4053SRui Paulo }
518e28a4053SRui Paulo 
519e28a4053SRui Paulo 
hostapd_wpa_auth_get_seqnum(void * ctx,const u8 * addr,int idx,u8 * seq)520e28a4053SRui Paulo static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
521e28a4053SRui Paulo 				       u8 *seq)
522e28a4053SRui Paulo {
523e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
524*a90b9d01SCy Schubert 	int link_id = -1;
525*a90b9d01SCy Schubert 
526*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
527*a90b9d01SCy Schubert 	if (hapd->conf->mld_ap && idx)
528*a90b9d01SCy Schubert 		link_id = hapd->mld_link_id;
529*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
530*a90b9d01SCy Schubert 	return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, link_id,
531*a90b9d01SCy Schubert 				  seq);
532e28a4053SRui Paulo }
533e28a4053SRui Paulo 
534e28a4053SRui Paulo 
hostapd_wpa_auth_send_eapol(void * ctx,const u8 * addr,const u8 * data,size_t data_len,int encrypt)535c1d255d3SCy Schubert int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
536e28a4053SRui Paulo 				const u8 *data, size_t data_len,
537e28a4053SRui Paulo 				int encrypt)
538e28a4053SRui Paulo {
539e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
540f05cddf9SRui Paulo 	struct sta_info *sta;
541f05cddf9SRui Paulo 	u32 flags = 0;
542*a90b9d01SCy Schubert 	int link_id = -1;
543*a90b9d01SCy Schubert 
544*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
545*a90b9d01SCy Schubert 	link_id = hapd->conf->mld_ap ? hapd->mld_link_id : -1;
546*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
547f05cddf9SRui Paulo 
5485b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
5495b9c547cSRui Paulo 	if (hapd->ext_eapol_frame_io) {
5505b9c547cSRui Paulo 		size_t hex_len = 2 * data_len + 1;
5515b9c547cSRui Paulo 		char *hex = os_malloc(hex_len);
5525b9c547cSRui Paulo 
5535b9c547cSRui Paulo 		if (hex == NULL)
5545b9c547cSRui Paulo 			return -1;
5555b9c547cSRui Paulo 		wpa_snprintf_hex(hex, hex_len, data, data_len);
5565b9c547cSRui Paulo 		wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
5575b9c547cSRui Paulo 			MAC2STR(addr), hex);
5585b9c547cSRui Paulo 		os_free(hex);
5595b9c547cSRui Paulo 		return 0;
5605b9c547cSRui Paulo 	}
5615b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
5625b9c547cSRui Paulo 
563f05cddf9SRui Paulo 	sta = ap_get_sta(hapd, addr);
564*a90b9d01SCy Schubert 	if (sta) {
565f05cddf9SRui Paulo 		flags = hostapd_sta_flags_to_drv(sta->flags);
566*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
567*a90b9d01SCy Schubert 		if (ap_sta_is_mld(hapd, sta) &&
568*a90b9d01SCy Schubert 		    (sta->flags & WLAN_STA_AUTHORIZED))
569*a90b9d01SCy Schubert 			link_id = -1;
570*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
571*a90b9d01SCy Schubert 	}
572f05cddf9SRui Paulo 
573f05cddf9SRui Paulo 	return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
574*a90b9d01SCy Schubert 					   encrypt, flags, link_id);
575*a90b9d01SCy Schubert }
576*a90b9d01SCy Schubert 
577*a90b9d01SCy Schubert 
hostapd_wpa_auth_get_sta_count(void * ctx)578*a90b9d01SCy Schubert static int hostapd_wpa_auth_get_sta_count(void *ctx)
579*a90b9d01SCy Schubert {
580*a90b9d01SCy Schubert 	struct hostapd_data *hapd = ctx;
581*a90b9d01SCy Schubert 
582*a90b9d01SCy Schubert 	return hapd->num_sta;
583e28a4053SRui Paulo }
584e28a4053SRui Paulo 
585e28a4053SRui Paulo 
hostapd_wpa_auth_for_each_sta(void * ctx,int (* cb)(struct wpa_state_machine * sm,void * ctx),void * cb_ctx)586e28a4053SRui Paulo static int hostapd_wpa_auth_for_each_sta(
587e28a4053SRui Paulo 	void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
588e28a4053SRui Paulo 	void *cb_ctx)
589e28a4053SRui Paulo {
590e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
591e28a4053SRui Paulo 	struct sta_info *sta;
592e28a4053SRui Paulo 
593e28a4053SRui Paulo 	for (sta = hapd->sta_list; sta; sta = sta->next) {
594e28a4053SRui Paulo 		if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
595e28a4053SRui Paulo 			return 1;
596e28a4053SRui Paulo 	}
597e28a4053SRui Paulo 	return 0;
598e28a4053SRui Paulo }
599e28a4053SRui Paulo 
600e28a4053SRui Paulo 
601e28a4053SRui Paulo struct wpa_auth_iface_iter_data {
602e28a4053SRui Paulo 	int (*cb)(struct wpa_authenticator *sm, void *ctx);
603e28a4053SRui Paulo 	void *cb_ctx;
604e28a4053SRui Paulo };
605e28a4053SRui Paulo 
wpa_auth_iface_iter(struct hostapd_iface * iface,void * ctx)606e28a4053SRui Paulo static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
607e28a4053SRui Paulo {
608e28a4053SRui Paulo 	struct wpa_auth_iface_iter_data *data = ctx;
609e28a4053SRui Paulo 	size_t i;
610e28a4053SRui Paulo 	for (i = 0; i < iface->num_bss; i++) {
611e28a4053SRui Paulo 		if (iface->bss[i]->wpa_auth &&
612e28a4053SRui Paulo 		    data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
613e28a4053SRui Paulo 			return 1;
614e28a4053SRui Paulo 	}
615e28a4053SRui Paulo 	return 0;
616e28a4053SRui Paulo }
617e28a4053SRui Paulo 
618e28a4053SRui Paulo 
hostapd_wpa_auth_for_each_auth(void * ctx,int (* cb)(struct wpa_authenticator * sm,void * ctx),void * cb_ctx)619e28a4053SRui Paulo static int hostapd_wpa_auth_for_each_auth(
620e28a4053SRui Paulo 	void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
621e28a4053SRui Paulo 	void *cb_ctx)
622e28a4053SRui Paulo {
623e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
624e28a4053SRui Paulo 	struct wpa_auth_iface_iter_data data;
625f05cddf9SRui Paulo 	if (hapd->iface->interfaces == NULL ||
626f05cddf9SRui Paulo 	    hapd->iface->interfaces->for_each_interface == NULL)
627e28a4053SRui Paulo 		return -1;
628e28a4053SRui Paulo 	data.cb = cb;
629e28a4053SRui Paulo 	data.cb_ctx = cb_ctx;
630f05cddf9SRui Paulo 	return hapd->iface->interfaces->for_each_interface(
631f05cddf9SRui Paulo 		hapd->iface->interfaces, wpa_auth_iface_iter, &data);
632e28a4053SRui Paulo }
633e28a4053SRui Paulo 
634e28a4053SRui Paulo 
63585732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
63685732ac8SCy Schubert 
63785732ac8SCy Schubert struct wpa_ft_rrb_rx_later_data {
63885732ac8SCy Schubert 	struct dl_list list;
63985732ac8SCy Schubert 	u8 addr[ETH_ALEN];
64085732ac8SCy Schubert 	size_t data_len;
64185732ac8SCy Schubert 	/* followed by data_len octets of data */
64285732ac8SCy Schubert };
64385732ac8SCy Schubert 
hostapd_wpa_ft_rrb_rx_later(void * eloop_ctx,void * timeout_ctx)64485732ac8SCy Schubert static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx, void *timeout_ctx)
64585732ac8SCy Schubert {
64685732ac8SCy Schubert 	struct hostapd_data *hapd = eloop_ctx;
64785732ac8SCy Schubert 	struct wpa_ft_rrb_rx_later_data *data, *n;
64885732ac8SCy Schubert 
64985732ac8SCy Schubert 	dl_list_for_each_safe(data, n, &hapd->l2_queue,
65085732ac8SCy Schubert 			      struct wpa_ft_rrb_rx_later_data, list) {
65185732ac8SCy Schubert 		if (hapd->wpa_auth) {
65285732ac8SCy Schubert 			wpa_ft_rrb_rx(hapd->wpa_auth, data->addr,
65385732ac8SCy Schubert 				      (const u8 *) (data + 1),
65485732ac8SCy Schubert 				      data->data_len);
65585732ac8SCy Schubert 		}
65685732ac8SCy Schubert 		dl_list_del(&data->list);
65785732ac8SCy Schubert 		os_free(data);
65885732ac8SCy Schubert 	}
65985732ac8SCy Schubert }
66085732ac8SCy Schubert 
661e28a4053SRui Paulo 
662e28a4053SRui Paulo struct wpa_auth_ft_iface_iter_data {
663e28a4053SRui Paulo 	struct hostapd_data *src_hapd;
664e28a4053SRui Paulo 	const u8 *dst;
665e28a4053SRui Paulo 	const u8 *data;
666e28a4053SRui Paulo 	size_t data_len;
667e28a4053SRui Paulo };
668e28a4053SRui Paulo 
669e28a4053SRui Paulo 
hostapd_wpa_auth_ft_iter(struct hostapd_iface * iface,void * ctx)670e28a4053SRui Paulo static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
671e28a4053SRui Paulo {
672e28a4053SRui Paulo 	struct wpa_auth_ft_iface_iter_data *idata = ctx;
67385732ac8SCy Schubert 	struct wpa_ft_rrb_rx_later_data *data;
674e28a4053SRui Paulo 	struct hostapd_data *hapd;
675e28a4053SRui Paulo 	size_t j;
676e28a4053SRui Paulo 
677e28a4053SRui Paulo 	for (j = 0; j < iface->num_bss; j++) {
678e28a4053SRui Paulo 		hapd = iface->bss[j];
67985732ac8SCy Schubert 		if (hapd == idata->src_hapd ||
68085732ac8SCy Schubert 		    !hapd->wpa_auth ||
681*a90b9d01SCy Schubert 		    !ether_addr_equal(hapd->own_addr, idata->dst))
682e28a4053SRui Paulo 			continue;
68385732ac8SCy Schubert 
68485732ac8SCy Schubert 		wpa_printf(MSG_DEBUG,
68585732ac8SCy Schubert 			   "FT: Send RRB data directly to locally managed BSS "
68685732ac8SCy Schubert 			   MACSTR "@%s -> " MACSTR "@%s",
687e28a4053SRui Paulo 			   MAC2STR(idata->src_hapd->own_addr),
688e28a4053SRui Paulo 			   idata->src_hapd->conf->iface,
689e28a4053SRui Paulo 			   MAC2STR(hapd->own_addr), hapd->conf->iface);
69085732ac8SCy Schubert 
69185732ac8SCy Schubert 		/* Defer wpa_ft_rrb_rx() until next eloop step as this is
69285732ac8SCy Schubert 		 * when it would be triggered when reading from a socket.
69385732ac8SCy Schubert 		 * This avoids
69485732ac8SCy Schubert 		 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
69585732ac8SCy Schubert 		 * that is calling hapd0:recv handler from within
69685732ac8SCy Schubert 		 * hapd0:send directly.
69785732ac8SCy Schubert 		 */
69885732ac8SCy Schubert 		data = os_zalloc(sizeof(*data) + idata->data_len);
69985732ac8SCy Schubert 		if (!data)
700e28a4053SRui Paulo 			return 1;
70185732ac8SCy Schubert 
70285732ac8SCy Schubert 		os_memcpy(data->addr, idata->src_hapd->own_addr, ETH_ALEN);
70385732ac8SCy Schubert 		os_memcpy(data + 1, idata->data, idata->data_len);
70485732ac8SCy Schubert 		data->data_len = idata->data_len;
70585732ac8SCy Schubert 
70685732ac8SCy Schubert 		dl_list_add(&hapd->l2_queue, &data->list);
70785732ac8SCy Schubert 
70885732ac8SCy Schubert 		if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later,
70985732ac8SCy Schubert 						 hapd, NULL))
71085732ac8SCy Schubert 			eloop_register_timeout(0, 0,
71185732ac8SCy Schubert 					       hostapd_wpa_ft_rrb_rx_later,
71285732ac8SCy Schubert 					       hapd, NULL);
71385732ac8SCy Schubert 
71485732ac8SCy Schubert 		return 1;
715e28a4053SRui Paulo 	}
716e28a4053SRui Paulo 
717e28a4053SRui Paulo 	return 0;
718e28a4053SRui Paulo }
719e28a4053SRui Paulo 
72085732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
721e28a4053SRui Paulo 
722e28a4053SRui Paulo 
hostapd_wpa_auth_send_ether(void * ctx,const u8 * dst,u16 proto,const u8 * data,size_t data_len)723e28a4053SRui Paulo static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
724e28a4053SRui Paulo 				       const u8 *data, size_t data_len)
725e28a4053SRui Paulo {
726e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
727f05cddf9SRui Paulo 	struct l2_ethhdr *buf;
728f05cddf9SRui Paulo 	int ret;
729e28a4053SRui Paulo 
7305b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
7315b9c547cSRui Paulo 	if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
7325b9c547cSRui Paulo 		size_t hex_len = 2 * data_len + 1;
7335b9c547cSRui Paulo 		char *hex = os_malloc(hex_len);
7345b9c547cSRui Paulo 
7355b9c547cSRui Paulo 		if (hex == NULL)
7365b9c547cSRui Paulo 			return -1;
7375b9c547cSRui Paulo 		wpa_snprintf_hex(hex, hex_len, data, data_len);
7385b9c547cSRui Paulo 		wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
7395b9c547cSRui Paulo 			MAC2STR(dst), hex);
7405b9c547cSRui Paulo 		os_free(hex);
7415b9c547cSRui Paulo 		return 0;
7425b9c547cSRui Paulo 	}
7435b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
7445b9c547cSRui Paulo 
74585732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
746f05cddf9SRui Paulo 	if (proto == ETH_P_RRB && hapd->iface->interfaces &&
747f05cddf9SRui Paulo 	    hapd->iface->interfaces->for_each_interface) {
748e28a4053SRui Paulo 		int res;
749e28a4053SRui Paulo 		struct wpa_auth_ft_iface_iter_data idata;
750e28a4053SRui Paulo 		idata.src_hapd = hapd;
751e28a4053SRui Paulo 		idata.dst = dst;
752e28a4053SRui Paulo 		idata.data = data;
753e28a4053SRui Paulo 		idata.data_len = data_len;
754f05cddf9SRui Paulo 		res = hapd->iface->interfaces->for_each_interface(
755f05cddf9SRui Paulo 			hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
756e28a4053SRui Paulo 			&idata);
757e28a4053SRui Paulo 		if (res == 1)
758e28a4053SRui Paulo 			return data_len;
759e28a4053SRui Paulo 	}
76085732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
761e28a4053SRui Paulo 
762e28a4053SRui Paulo 	if (hapd->l2 == NULL)
763e28a4053SRui Paulo 		return -1;
764f05cddf9SRui Paulo 
765f05cddf9SRui Paulo 	buf = os_malloc(sizeof(*buf) + data_len);
766f05cddf9SRui Paulo 	if (buf == NULL)
767f05cddf9SRui Paulo 		return -1;
768f05cddf9SRui Paulo 	os_memcpy(buf->h_dest, dst, ETH_ALEN);
769f05cddf9SRui Paulo 	os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
770f05cddf9SRui Paulo 	buf->h_proto = host_to_be16(proto);
771f05cddf9SRui Paulo 	os_memcpy(buf + 1, data, data_len);
772f05cddf9SRui Paulo 	ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
773f05cddf9SRui Paulo 			     sizeof(*buf) + data_len);
774f05cddf9SRui Paulo 	os_free(buf);
775f05cddf9SRui Paulo 	return ret;
776e28a4053SRui Paulo }
777e28a4053SRui Paulo 
778e28a4053SRui Paulo 
77985732ac8SCy Schubert #ifdef CONFIG_ETH_P_OUI
hostapd_wpa_get_oui(struct hostapd_data * hapd,u8 oui_suffix)78085732ac8SCy Schubert static struct eth_p_oui_ctx * hostapd_wpa_get_oui(struct hostapd_data *hapd,
78185732ac8SCy Schubert 						  u8 oui_suffix)
78285732ac8SCy Schubert {
78385732ac8SCy Schubert 	switch (oui_suffix) {
78485732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
78585732ac8SCy Schubert 	case FT_PACKET_R0KH_R1KH_PULL:
78685732ac8SCy Schubert 		return hapd->oui_pull;
78785732ac8SCy Schubert 	case FT_PACKET_R0KH_R1KH_RESP:
78885732ac8SCy Schubert 		return hapd->oui_resp;
78985732ac8SCy Schubert 	case FT_PACKET_R0KH_R1KH_PUSH:
79085732ac8SCy Schubert 		return hapd->oui_push;
79185732ac8SCy Schubert 	case FT_PACKET_R0KH_R1KH_SEQ_REQ:
79285732ac8SCy Schubert 		return hapd->oui_sreq;
79385732ac8SCy Schubert 	case FT_PACKET_R0KH_R1KH_SEQ_RESP:
79485732ac8SCy Schubert 		return hapd->oui_sresp;
79585732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
79685732ac8SCy Schubert 	default:
79785732ac8SCy Schubert 		return NULL;
79885732ac8SCy Schubert 	}
79985732ac8SCy Schubert }
80085732ac8SCy Schubert #endif /* CONFIG_ETH_P_OUI */
80185732ac8SCy Schubert 
80285732ac8SCy Schubert 
80385732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
80485732ac8SCy Schubert 
80585732ac8SCy Schubert struct oui_deliver_later_data {
80685732ac8SCy Schubert 	struct dl_list list;
80785732ac8SCy Schubert 	u8 src_addr[ETH_ALEN];
80885732ac8SCy Schubert 	u8 dst_addr[ETH_ALEN];
80985732ac8SCy Schubert 	size_t data_len;
81085732ac8SCy Schubert 	u8 oui_suffix;
81185732ac8SCy Schubert 	/* followed by data_len octets of data */
81285732ac8SCy Schubert };
81385732ac8SCy Schubert 
hostapd_oui_deliver_later(void * eloop_ctx,void * timeout_ctx)81485732ac8SCy Schubert static void hostapd_oui_deliver_later(void *eloop_ctx, void *timeout_ctx)
81585732ac8SCy Schubert {
81685732ac8SCy Schubert 	struct hostapd_data *hapd = eloop_ctx;
81785732ac8SCy Schubert 	struct oui_deliver_later_data *data, *n;
81885732ac8SCy Schubert 	struct eth_p_oui_ctx *oui_ctx;
81985732ac8SCy Schubert 
82085732ac8SCy Schubert 	dl_list_for_each_safe(data, n, &hapd->l2_oui_queue,
82185732ac8SCy Schubert 			      struct oui_deliver_later_data, list) {
82285732ac8SCy Schubert 		oui_ctx = hostapd_wpa_get_oui(hapd, data->oui_suffix);
823c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG, "RRB(%s): %s src=" MACSTR " dst=" MACSTR
824c1d255d3SCy Schubert 			   " oui_suffix=%u data_len=%u data=%p",
825c1d255d3SCy Schubert 			   hapd->conf->iface, __func__,
826c1d255d3SCy Schubert 			   MAC2STR(data->src_addr), MAC2STR(data->dst_addr),
827c1d255d3SCy Schubert 			   data->oui_suffix, (unsigned int) data->data_len,
828c1d255d3SCy Schubert 			   data);
82985732ac8SCy Schubert 		if (hapd->wpa_auth && oui_ctx) {
83085732ac8SCy Schubert 			eth_p_oui_deliver(oui_ctx, data->src_addr,
83185732ac8SCy Schubert 					  data->dst_addr,
83285732ac8SCy Schubert 					  (const u8 *) (data + 1),
83385732ac8SCy Schubert 					  data->data_len);
83485732ac8SCy Schubert 		}
83585732ac8SCy Schubert 		dl_list_del(&data->list);
83685732ac8SCy Schubert 		os_free(data);
83785732ac8SCy Schubert 	}
83885732ac8SCy Schubert }
83985732ac8SCy Schubert 
84085732ac8SCy Schubert 
84185732ac8SCy Schubert struct wpa_auth_oui_iface_iter_data {
84285732ac8SCy Schubert 	struct hostapd_data *src_hapd;
84385732ac8SCy Schubert 	const u8 *dst_addr;
84485732ac8SCy Schubert 	const u8 *data;
84585732ac8SCy Schubert 	size_t data_len;
84685732ac8SCy Schubert 	u8 oui_suffix;
84785732ac8SCy Schubert };
84885732ac8SCy Schubert 
hostapd_wpa_auth_oui_iter(struct hostapd_iface * iface,void * ctx)84985732ac8SCy Schubert static int hostapd_wpa_auth_oui_iter(struct hostapd_iface *iface, void *ctx)
85085732ac8SCy Schubert {
85185732ac8SCy Schubert 	struct wpa_auth_oui_iface_iter_data *idata = ctx;
85285732ac8SCy Schubert 	struct oui_deliver_later_data *data;
853c1d255d3SCy Schubert 	struct hostapd_data *hapd, *src_hapd = idata->src_hapd;
85485732ac8SCy Schubert 	size_t j;
85585732ac8SCy Schubert 
85685732ac8SCy Schubert 	for (j = 0; j < iface->num_bss; j++) {
85785732ac8SCy Schubert 		hapd = iface->bss[j];
858c1d255d3SCy Schubert 		if (hapd == src_hapd)
859c1d255d3SCy Schubert 			continue; /* don't deliver back to same interface */
860c1d255d3SCy Schubert 		if (!wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) ||
861c1d255d3SCy Schubert 		    hapd->conf->ssid.ssid_len !=
862c1d255d3SCy Schubert 		    src_hapd->conf->ssid.ssid_len ||
863c1d255d3SCy Schubert 		    os_memcmp(hapd->conf->ssid.ssid,
864c1d255d3SCy Schubert 			      src_hapd->conf->ssid.ssid,
865c1d255d3SCy Schubert 			      hapd->conf->ssid.ssid_len) != 0 ||
866c1d255d3SCy Schubert 		    os_memcmp(hapd->conf->mobility_domain,
867c1d255d3SCy Schubert 			      src_hapd->conf->mobility_domain,
868c1d255d3SCy Schubert 			      MOBILITY_DOMAIN_ID_LEN) != 0)
869c1d255d3SCy Schubert 			continue; /* no matching FT SSID/mobility domain */
87085732ac8SCy Schubert 		if (!is_multicast_ether_addr(idata->dst_addr) &&
871*a90b9d01SCy Schubert 		    !ether_addr_equal(hapd->own_addr, idata->dst_addr))
872c1d255d3SCy Schubert 			continue; /* destination address does not match */
87385732ac8SCy Schubert 
87485732ac8SCy Schubert 		/* defer eth_p_oui_deliver until next eloop step as this is
87585732ac8SCy Schubert 		 * when it would be triggerd from reading from sock
87685732ac8SCy Schubert 		 * This avoids
87785732ac8SCy Schubert 		 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
87885732ac8SCy Schubert 		 * that is calling hapd0:recv handler from within
87985732ac8SCy Schubert 		 * hapd0:send directly.
88085732ac8SCy Schubert 		 */
88185732ac8SCy Schubert 		data = os_zalloc(sizeof(*data) + idata->data_len);
88285732ac8SCy Schubert 		if (!data)
88385732ac8SCy Schubert 			return 1;
884c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG,
885c1d255d3SCy Schubert 			   "RRB(%s): local delivery to %s dst=" MACSTR
886c1d255d3SCy Schubert 			   " oui_suffix=%u data_len=%u data=%p",
887c1d255d3SCy Schubert 			   src_hapd->conf->iface, hapd->conf->iface,
888c1d255d3SCy Schubert 			   MAC2STR(idata->dst_addr), idata->oui_suffix,
889c1d255d3SCy Schubert 			   (unsigned int) idata->data_len, data);
89085732ac8SCy Schubert 
891c1d255d3SCy Schubert 		os_memcpy(data->src_addr, src_hapd->own_addr, ETH_ALEN);
89285732ac8SCy Schubert 		os_memcpy(data->dst_addr, idata->dst_addr, ETH_ALEN);
89385732ac8SCy Schubert 		os_memcpy(data + 1, idata->data, idata->data_len);
89485732ac8SCy Schubert 		data->data_len = idata->data_len;
89585732ac8SCy Schubert 		data->oui_suffix = idata->oui_suffix;
89685732ac8SCy Schubert 
897c1d255d3SCy Schubert 		dl_list_add_tail(&hapd->l2_oui_queue, &data->list);
89885732ac8SCy Schubert 
89985732ac8SCy Schubert 		if (!eloop_is_timeout_registered(hostapd_oui_deliver_later,
90085732ac8SCy Schubert 						 hapd, NULL))
90185732ac8SCy Schubert 			eloop_register_timeout(0, 0,
90285732ac8SCy Schubert 					       hostapd_oui_deliver_later,
90385732ac8SCy Schubert 					       hapd, NULL);
90485732ac8SCy Schubert 
905c1d255d3SCy Schubert 		/* If dst_addr is a multicast address, do not return any
906c1d255d3SCy Schubert 		 * non-zero value here. Otherwise, the iteration of
907c1d255d3SCy Schubert 		 * for_each_interface() will be stopped. */
908c1d255d3SCy Schubert 		if (!is_multicast_ether_addr(idata->dst_addr))
90985732ac8SCy Schubert 			return 1;
91085732ac8SCy Schubert 	}
91185732ac8SCy Schubert 
91285732ac8SCy Schubert 	return 0;
91385732ac8SCy Schubert }
91485732ac8SCy Schubert 
91585732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
91685732ac8SCy Schubert 
91785732ac8SCy Schubert 
hostapd_wpa_auth_send_oui(void * ctx,const u8 * dst,u8 oui_suffix,const u8 * data,size_t data_len)91885732ac8SCy Schubert static int hostapd_wpa_auth_send_oui(void *ctx, const u8 *dst, u8 oui_suffix,
91985732ac8SCy Schubert 				     const u8 *data, size_t data_len)
92085732ac8SCy Schubert {
92185732ac8SCy Schubert #ifdef CONFIG_ETH_P_OUI
92285732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
92385732ac8SCy Schubert 	struct eth_p_oui_ctx *oui_ctx;
92485732ac8SCy Schubert 
925c1d255d3SCy Schubert 	wpa_printf(MSG_DEBUG, "RRB(%s): send to dst=" MACSTR
926c1d255d3SCy Schubert 		   " oui_suffix=%u data_len=%u",
927c1d255d3SCy Schubert 		   hapd->conf->iface, MAC2STR(dst), oui_suffix,
928c1d255d3SCy Schubert 		   (unsigned int) data_len);
92985732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
93085732ac8SCy Schubert 	if (hapd->iface->interfaces &&
93185732ac8SCy Schubert 	    hapd->iface->interfaces->for_each_interface) {
93285732ac8SCy Schubert 		struct wpa_auth_oui_iface_iter_data idata;
93385732ac8SCy Schubert 		int res;
93485732ac8SCy Schubert 
93585732ac8SCy Schubert 		idata.src_hapd = hapd;
93685732ac8SCy Schubert 		idata.dst_addr = dst;
93785732ac8SCy Schubert 		idata.data = data;
93885732ac8SCy Schubert 		idata.data_len = data_len;
93985732ac8SCy Schubert 		idata.oui_suffix = oui_suffix;
94085732ac8SCy Schubert 		res = hapd->iface->interfaces->for_each_interface(
94185732ac8SCy Schubert 			hapd->iface->interfaces, hostapd_wpa_auth_oui_iter,
94285732ac8SCy Schubert 			&idata);
94385732ac8SCy Schubert 		if (res == 1)
94485732ac8SCy Schubert 			return data_len;
94585732ac8SCy Schubert 	}
94685732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
94785732ac8SCy Schubert 
94885732ac8SCy Schubert 	oui_ctx = hostapd_wpa_get_oui(hapd, oui_suffix);
94985732ac8SCy Schubert 	if (!oui_ctx)
95085732ac8SCy Schubert 		return -1;
95185732ac8SCy Schubert 
95285732ac8SCy Schubert 	return eth_p_oui_send(oui_ctx, hapd->own_addr, dst, data, data_len);
95385732ac8SCy Schubert #else /* CONFIG_ETH_P_OUI */
95485732ac8SCy Schubert 	return -1;
95585732ac8SCy Schubert #endif /* CONFIG_ETH_P_OUI */
95685732ac8SCy Schubert }
95785732ac8SCy Schubert 
95885732ac8SCy Schubert 
hostapd_channel_info(void * ctx,struct wpa_channel_info * ci)9594bc52338SCy Schubert static int hostapd_channel_info(void *ctx, struct wpa_channel_info *ci)
9604bc52338SCy Schubert {
9614bc52338SCy Schubert 	struct hostapd_data *hapd = ctx;
9624bc52338SCy Schubert 
9634bc52338SCy Schubert 	return hostapd_drv_channel_info(hapd, ci);
9644bc52338SCy Schubert }
9654bc52338SCy Schubert 
9664bc52338SCy Schubert 
967c1d255d3SCy Schubert #ifdef CONFIG_PASN
968c1d255d3SCy Schubert 
hostapd_store_ptksa(void * ctx,const u8 * addr,int cipher,u32 life_time,const struct wpa_ptk * ptk)969c1d255d3SCy Schubert static void hostapd_store_ptksa(void *ctx, const u8 *addr,int cipher,
970c1d255d3SCy Schubert 				u32 life_time, const struct wpa_ptk *ptk)
971c1d255d3SCy Schubert {
972c1d255d3SCy Schubert 	struct hostapd_data *hapd = ctx;
973c1d255d3SCy Schubert 
974*a90b9d01SCy Schubert 	ptksa_cache_add(hapd->ptksa, hapd->own_addr, addr, cipher, life_time,
975*a90b9d01SCy Schubert 			ptk, NULL, NULL, 0);
976c1d255d3SCy Schubert }
977c1d255d3SCy Schubert 
978c1d255d3SCy Schubert 
hostapd_clear_ptksa(void * ctx,const u8 * addr,int cipher)979c1d255d3SCy Schubert static void hostapd_clear_ptksa(void *ctx, const u8 *addr, int cipher)
980c1d255d3SCy Schubert {
981c1d255d3SCy Schubert 	struct hostapd_data *hapd = ctx;
982c1d255d3SCy Schubert 
983c1d255d3SCy Schubert 	ptksa_cache_flush(hapd->ptksa, addr, cipher);
984c1d255d3SCy Schubert }
985c1d255d3SCy Schubert 
986c1d255d3SCy Schubert #endif /* CONFIG_PASN */
987c1d255d3SCy Schubert 
988c1d255d3SCy Schubert 
hostapd_wpa_auth_update_vlan(void * ctx,const u8 * addr,int vlan_id)9894bc52338SCy Schubert static int hostapd_wpa_auth_update_vlan(void *ctx, const u8 *addr, int vlan_id)
9904bc52338SCy Schubert {
9914bc52338SCy Schubert #ifndef CONFIG_NO_VLAN
9924bc52338SCy Schubert 	struct hostapd_data *hapd = ctx;
9934bc52338SCy Schubert 	struct sta_info *sta;
9944bc52338SCy Schubert 
9954bc52338SCy Schubert 	sta = ap_get_sta(hapd, addr);
9964bc52338SCy Schubert 	if (!sta)
9974bc52338SCy Schubert 		return -1;
9984bc52338SCy Schubert 
999c1d255d3SCy Schubert 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
1000c1d255d3SCy Schubert 		struct vlan_description vlan_desc;
1001c1d255d3SCy Schubert 
10024bc52338SCy Schubert 		os_memset(&vlan_desc, 0, sizeof(vlan_desc));
10034bc52338SCy Schubert 		vlan_desc.notempty = 1;
10044bc52338SCy Schubert 		vlan_desc.untagged = vlan_id;
10054bc52338SCy Schubert 		if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
1006c1d255d3SCy Schubert 			wpa_printf(MSG_INFO,
1007c1d255d3SCy Schubert 				   "Invalid VLAN ID %d in wpa_psk_file",
10084bc52338SCy Schubert 				   vlan_id);
10094bc52338SCy Schubert 			return -1;
10104bc52338SCy Schubert 		}
10114bc52338SCy Schubert 
10124bc52338SCy Schubert 		if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0) {
10134bc52338SCy Schubert 			wpa_printf(MSG_INFO,
10144bc52338SCy Schubert 				   "Failed to assign VLAN ID %d from wpa_psk_file to "
10154bc52338SCy Schubert 				   MACSTR, vlan_id, MAC2STR(sta->addr));
10164bc52338SCy Schubert 			return -1;
10174bc52338SCy Schubert 		}
1018c1d255d3SCy Schubert 	} else {
1019c1d255d3SCy Schubert 		sta->vlan_id = vlan_id;
1020c1d255d3SCy Schubert 	}
10214bc52338SCy Schubert 
10224bc52338SCy Schubert 	wpa_printf(MSG_INFO,
10234bc52338SCy Schubert 		   "Assigned VLAN ID %d from wpa_psk_file to " MACSTR,
10244bc52338SCy Schubert 		   vlan_id, MAC2STR(sta->addr));
10254bc52338SCy Schubert 	if ((sta->flags & WLAN_STA_ASSOC) &&
10264bc52338SCy Schubert 	    ap_sta_bind_vlan(hapd, sta) < 0)
10274bc52338SCy Schubert 		return -1;
10284bc52338SCy Schubert #endif /* CONFIG_NO_VLAN */
10294bc52338SCy Schubert 
10304bc52338SCy Schubert 	return 0;
10314bc52338SCy Schubert }
10324bc52338SCy Schubert 
10334bc52338SCy Schubert 
10344bc52338SCy Schubert #ifdef CONFIG_OCV
hostapd_get_sta_tx_params(void * ctx,const u8 * addr,int ap_max_chanwidth,int ap_seg1_idx,int * bandwidth,int * seg1_idx)10354bc52338SCy Schubert static int hostapd_get_sta_tx_params(void *ctx, const u8 *addr,
10364bc52338SCy Schubert 				     int ap_max_chanwidth, int ap_seg1_idx,
10374bc52338SCy Schubert 				     int *bandwidth, int *seg1_idx)
10384bc52338SCy Schubert {
10394bc52338SCy Schubert 	struct hostapd_data *hapd = ctx;
10404bc52338SCy Schubert 	struct sta_info *sta;
10414bc52338SCy Schubert 
10424bc52338SCy Schubert 	sta = ap_get_sta(hapd, addr);
10434bc52338SCy Schubert 	if (!sta) {
10444bc52338SCy Schubert 		hostapd_wpa_auth_logger(hapd, addr, LOGGER_INFO,
10454bc52338SCy Schubert 					"Failed to get STA info to validate received OCI");
10464bc52338SCy Schubert 		return -1;
10474bc52338SCy Schubert 	}
10484bc52338SCy Schubert 
10494bc52338SCy Schubert 	return get_tx_parameters(sta, ap_max_chanwidth, ap_seg1_idx, bandwidth,
10504bc52338SCy Schubert 				 seg1_idx);
10514bc52338SCy Schubert }
10524bc52338SCy Schubert #endif /* CONFIG_OCV */
10534bc52338SCy Schubert 
10544bc52338SCy Schubert 
105585732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
1056e28a4053SRui Paulo 
hostapd_wpa_auth_send_ft_action(void * ctx,const u8 * dst,const u8 * data,size_t data_len)1057e28a4053SRui Paulo static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
1058e28a4053SRui Paulo 					   const u8 *data, size_t data_len)
1059e28a4053SRui Paulo {
1060e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
1061e28a4053SRui Paulo 	int res;
1062e28a4053SRui Paulo 	struct ieee80211_mgmt *m;
1063e28a4053SRui Paulo 	size_t mlen;
1064e28a4053SRui Paulo 	struct sta_info *sta;
1065e28a4053SRui Paulo 
1066e28a4053SRui Paulo 	sta = ap_get_sta(hapd, dst);
1067e28a4053SRui Paulo 	if (sta == NULL || sta->wpa_sm == NULL)
1068e28a4053SRui Paulo 		return -1;
1069e28a4053SRui Paulo 
1070e28a4053SRui Paulo 	m = os_zalloc(sizeof(*m) + data_len);
1071e28a4053SRui Paulo 	if (m == NULL)
1072e28a4053SRui Paulo 		return -1;
1073e28a4053SRui Paulo 	mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
1074e28a4053SRui Paulo 	m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1075e28a4053SRui Paulo 					WLAN_FC_STYPE_ACTION);
1076e28a4053SRui Paulo 	os_memcpy(m->da, dst, ETH_ALEN);
1077e28a4053SRui Paulo 	os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
1078e28a4053SRui Paulo 	os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
1079e28a4053SRui Paulo 	os_memcpy(&m->u, data, data_len);
1080e28a4053SRui Paulo 
1081c1d255d3SCy Schubert 	res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0, NULL, 0, 0);
1082e28a4053SRui Paulo 	os_free(m);
1083e28a4053SRui Paulo 	return res;
1084e28a4053SRui Paulo }
1085e28a4053SRui Paulo 
1086e28a4053SRui Paulo 
1087e28a4053SRui Paulo static struct wpa_state_machine *
hostapd_wpa_auth_add_sta(void * ctx,const u8 * sta_addr)1088e28a4053SRui Paulo hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
1089e28a4053SRui Paulo {
1090e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
1091e28a4053SRui Paulo 	struct sta_info *sta;
1092c1d255d3SCy Schubert 	int ret;
1093e28a4053SRui Paulo 
10944bc52338SCy Schubert 	wpa_printf(MSG_DEBUG, "Add station entry for " MACSTR
10954bc52338SCy Schubert 		   " based on WPA authenticator callback",
10964bc52338SCy Schubert 		   MAC2STR(sta_addr));
1097c1d255d3SCy Schubert 	ret = hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT);
1098c1d255d3SCy Schubert 
1099c1d255d3SCy Schubert 	/*
1100c1d255d3SCy Schubert 	 * The expected return values from hostapd_add_sta_node() are
1101c1d255d3SCy Schubert 	 * 0: successfully added STA entry
1102c1d255d3SCy Schubert 	 * -EOPNOTSUPP: driver or driver wrapper does not support/need this
1103c1d255d3SCy Schubert 	 *	operations
1104c1d255d3SCy Schubert 	 * any other negative value: error in adding the STA entry */
1105c1d255d3SCy Schubert 	if (ret < 0 && ret != -EOPNOTSUPP)
1106f05cddf9SRui Paulo 		return NULL;
1107f05cddf9SRui Paulo 
1108e28a4053SRui Paulo 	sta = ap_sta_add(hapd, sta_addr);
1109e28a4053SRui Paulo 	if (sta == NULL)
1110e28a4053SRui Paulo 		return NULL;
1111c1d255d3SCy Schubert 	if (ret == 0)
11124bc52338SCy Schubert 		sta->added_unassoc = 1;
1113c1d255d3SCy Schubert 
11144bc52338SCy Schubert 	sta->ft_over_ds = 1;
1115e28a4053SRui Paulo 	if (sta->wpa_sm) {
1116e28a4053SRui Paulo 		sta->auth_alg = WLAN_AUTH_FT;
1117e28a4053SRui Paulo 		return sta->wpa_sm;
1118e28a4053SRui Paulo 	}
1119e28a4053SRui Paulo 
11205b9c547cSRui Paulo 	sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
1121e28a4053SRui Paulo 	if (sta->wpa_sm == NULL) {
1122e28a4053SRui Paulo 		ap_free_sta(hapd, sta);
1123e28a4053SRui Paulo 		return NULL;
1124e28a4053SRui Paulo 	}
1125e28a4053SRui Paulo 	sta->auth_alg = WLAN_AUTH_FT;
1126e28a4053SRui Paulo 
1127e28a4053SRui Paulo 	return sta->wpa_sm;
1128e28a4053SRui Paulo }
1129e28a4053SRui Paulo 
1130e28a4053SRui Paulo 
hostapd_wpa_auth_add_sta_ft(void * ctx,const u8 * sta_addr)1131c1d255d3SCy Schubert static int hostapd_wpa_auth_add_sta_ft(void *ctx, const u8 *sta_addr)
1132c1d255d3SCy Schubert {
1133c1d255d3SCy Schubert 	struct hostapd_data *hapd = ctx;
1134c1d255d3SCy Schubert 	struct sta_info *sta;
1135c1d255d3SCy Schubert 
1136c1d255d3SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
1137c1d255d3SCy Schubert 	if (!sta)
1138c1d255d3SCy Schubert 		return -1;
1139c1d255d3SCy Schubert 
1140c1d255d3SCy Schubert 	if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1141c1d255d3SCy Schubert 	    (sta->flags & WLAN_STA_MFP) && ap_sta_is_authorized(sta) &&
1142c1d255d3SCy Schubert 	    !(hapd->conf->mesh & MESH_ENABLED) && !(sta->added_unassoc)) {
1143c1d255d3SCy Schubert 		/* We could not do this in handle_auth() since there was a
1144c1d255d3SCy Schubert 		 * PMF-enabled association for the STA and the new
1145c1d255d3SCy Schubert 		 * authentication attempt was not yet fully processed. Now that
1146c1d255d3SCy Schubert 		 * we are ready to configure the TK to the driver,
1147c1d255d3SCy Schubert 		 * authentication has succeeded and we can clean up the driver
1148c1d255d3SCy Schubert 		 * STA entry to avoid issues with any maintained state from the
1149c1d255d3SCy Schubert 		 * previous association. */
1150c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG,
1151c1d255d3SCy Schubert 			   "FT: Remove and re-add driver STA entry after successful FT authentication");
1152c1d255d3SCy Schubert 		return ap_sta_re_add(hapd, sta);
1153c1d255d3SCy Schubert 	}
1154c1d255d3SCy Schubert 
1155c1d255d3SCy Schubert 	return 0;
1156c1d255d3SCy Schubert }
1157c1d255d3SCy Schubert 
1158c1d255d3SCy Schubert 
hostapd_wpa_auth_set_vlan(void * ctx,const u8 * sta_addr,struct vlan_description * vlan)115985732ac8SCy Schubert static int hostapd_wpa_auth_set_vlan(void *ctx, const u8 *sta_addr,
116085732ac8SCy Schubert 				     struct vlan_description *vlan)
116185732ac8SCy Schubert {
116285732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
116385732ac8SCy Schubert 	struct sta_info *sta;
116485732ac8SCy Schubert 
116585732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
116685732ac8SCy Schubert 	if (!sta || !sta->wpa_sm)
116785732ac8SCy Schubert 		return -1;
116885732ac8SCy Schubert 
1169*a90b9d01SCy Schubert 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
117085732ac8SCy Schubert 		if (vlan->notempty &&
117185732ac8SCy Schubert 		    !hostapd_vlan_valid(hapd->conf->vlan, vlan)) {
1172*a90b9d01SCy Schubert 			hostapd_logger(hapd, sta->addr,
1173*a90b9d01SCy Schubert 				       HOSTAPD_MODULE_IEEE80211,
117485732ac8SCy Schubert 				       HOSTAPD_LEVEL_INFO,
117585732ac8SCy Schubert 				       "Invalid VLAN %d%s received from FT",
1176*a90b9d01SCy Schubert 				       vlan->untagged, vlan->tagged[0] ?
1177*a90b9d01SCy Schubert 				       "+" : "");
117885732ac8SCy Schubert 			return -1;
117985732ac8SCy Schubert 		}
118085732ac8SCy Schubert 
118185732ac8SCy Schubert 		if (ap_sta_set_vlan(hapd, sta, vlan) < 0)
118285732ac8SCy Schubert 			return -1;
1183*a90b9d01SCy Schubert 
1184*a90b9d01SCy Schubert 	} else {
1185*a90b9d01SCy Schubert 		if (vlan->notempty)
1186*a90b9d01SCy Schubert 			sta->vlan_id = vlan->untagged;
1187*a90b9d01SCy Schubert 	}
118885732ac8SCy Schubert 	/* Configure wpa_group for GTK but ignore error due to driver not
118985732ac8SCy Schubert 	 * knowing this STA. */
119085732ac8SCy Schubert 	ap_sta_bind_vlan(hapd, sta);
119185732ac8SCy Schubert 
119285732ac8SCy Schubert 	if (sta->vlan_id)
119385732ac8SCy Schubert 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
119485732ac8SCy Schubert 			       HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
119585732ac8SCy Schubert 
119685732ac8SCy Schubert 	return 0;
119785732ac8SCy Schubert }
119885732ac8SCy Schubert 
119985732ac8SCy Schubert 
hostapd_wpa_auth_get_vlan(void * ctx,const u8 * sta_addr,struct vlan_description * vlan)120085732ac8SCy Schubert static int hostapd_wpa_auth_get_vlan(void *ctx, const u8 *sta_addr,
120185732ac8SCy Schubert 				     struct vlan_description *vlan)
120285732ac8SCy Schubert {
120385732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
120485732ac8SCy Schubert 	struct sta_info *sta;
120585732ac8SCy Schubert 
120685732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
120785732ac8SCy Schubert 	if (!sta)
120885732ac8SCy Schubert 		return -1;
120985732ac8SCy Schubert 
1210*a90b9d01SCy Schubert 	if (sta->vlan_desc) {
121185732ac8SCy Schubert 		*vlan = *sta->vlan_desc;
1212*a90b9d01SCy Schubert 	} else if ((hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) &&
1213*a90b9d01SCy Schubert 		   sta->vlan_id) {
1214*a90b9d01SCy Schubert 		vlan->notempty = 1;
1215*a90b9d01SCy Schubert 		vlan->untagged = sta->vlan_id;
1216*a90b9d01SCy Schubert 	} else {
121785732ac8SCy Schubert 		os_memset(vlan, 0, sizeof(*vlan));
1218*a90b9d01SCy Schubert 	}
121985732ac8SCy Schubert 
122085732ac8SCy Schubert 	return 0;
122185732ac8SCy Schubert }
122285732ac8SCy Schubert 
122385732ac8SCy Schubert 
122485732ac8SCy Schubert static int
hostapd_wpa_auth_set_identity(void * ctx,const u8 * sta_addr,const u8 * identity,size_t identity_len)122585732ac8SCy Schubert hostapd_wpa_auth_set_identity(void *ctx, const u8 *sta_addr,
122685732ac8SCy Schubert 			      const u8 *identity, size_t identity_len)
122785732ac8SCy Schubert {
122885732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
122985732ac8SCy Schubert 	struct sta_info *sta;
123085732ac8SCy Schubert 
123185732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
123285732ac8SCy Schubert 	if (!sta)
123385732ac8SCy Schubert 		return -1;
123485732ac8SCy Schubert 
123585732ac8SCy Schubert 	os_free(sta->identity);
123685732ac8SCy Schubert 	sta->identity = NULL;
123785732ac8SCy Schubert 
123885732ac8SCy Schubert 	if (sta->eapol_sm) {
123985732ac8SCy Schubert 		os_free(sta->eapol_sm->identity);
124085732ac8SCy Schubert 		sta->eapol_sm->identity = NULL;
124185732ac8SCy Schubert 		sta->eapol_sm->identity_len = 0;
124285732ac8SCy Schubert 	}
124385732ac8SCy Schubert 
124485732ac8SCy Schubert 	if (!identity_len)
124585732ac8SCy Schubert 		return 0;
124685732ac8SCy Schubert 
124785732ac8SCy Schubert 	/* sta->identity is NULL terminated */
124885732ac8SCy Schubert 	sta->identity = os_zalloc(identity_len + 1);
124985732ac8SCy Schubert 	if (!sta->identity)
125085732ac8SCy Schubert 		return -1;
125185732ac8SCy Schubert 	os_memcpy(sta->identity, identity, identity_len);
125285732ac8SCy Schubert 
125385732ac8SCy Schubert 	if (sta->eapol_sm) {
125485732ac8SCy Schubert 		sta->eapol_sm->identity = os_zalloc(identity_len);
125585732ac8SCy Schubert 		if (!sta->eapol_sm->identity)
125685732ac8SCy Schubert 			return -1;
125785732ac8SCy Schubert 		os_memcpy(sta->eapol_sm->identity, identity, identity_len);
125885732ac8SCy Schubert 		sta->eapol_sm->identity_len = identity_len;
125985732ac8SCy Schubert 	}
126085732ac8SCy Schubert 
126185732ac8SCy Schubert 	return 0;
126285732ac8SCy Schubert }
126385732ac8SCy Schubert 
126485732ac8SCy Schubert 
126585732ac8SCy Schubert static size_t
hostapd_wpa_auth_get_identity(void * ctx,const u8 * sta_addr,const u8 ** buf)126685732ac8SCy Schubert hostapd_wpa_auth_get_identity(void *ctx, const u8 *sta_addr, const u8 **buf)
126785732ac8SCy Schubert {
126885732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
126985732ac8SCy Schubert 	struct sta_info *sta;
127085732ac8SCy Schubert 	size_t len;
127185732ac8SCy Schubert 	char *identity;
127285732ac8SCy Schubert 
127385732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
127485732ac8SCy Schubert 	if (!sta)
127585732ac8SCy Schubert 		return 0;
127685732ac8SCy Schubert 
127785732ac8SCy Schubert 	*buf = ieee802_1x_get_identity(sta->eapol_sm, &len);
127885732ac8SCy Schubert 	if (*buf && len)
127985732ac8SCy Schubert 		return len;
128085732ac8SCy Schubert 
128185732ac8SCy Schubert 	if (!sta->identity) {
128285732ac8SCy Schubert 		*buf = NULL;
128385732ac8SCy Schubert 		return 0;
128485732ac8SCy Schubert 	}
128585732ac8SCy Schubert 
128685732ac8SCy Schubert 	identity = sta->identity;
128785732ac8SCy Schubert 	len = os_strlen(identity);
128885732ac8SCy Schubert 	*buf = (u8 *) identity;
128985732ac8SCy Schubert 
129085732ac8SCy Schubert 	return len;
129185732ac8SCy Schubert }
129285732ac8SCy Schubert 
129385732ac8SCy Schubert 
129485732ac8SCy Schubert static int
hostapd_wpa_auth_set_radius_cui(void * ctx,const u8 * sta_addr,const u8 * radius_cui,size_t radius_cui_len)129585732ac8SCy Schubert hostapd_wpa_auth_set_radius_cui(void *ctx, const u8 *sta_addr,
129685732ac8SCy Schubert 				const u8 *radius_cui, size_t radius_cui_len)
129785732ac8SCy Schubert {
129885732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
129985732ac8SCy Schubert 	struct sta_info *sta;
130085732ac8SCy Schubert 
130185732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
130285732ac8SCy Schubert 	if (!sta)
130385732ac8SCy Schubert 		return -1;
130485732ac8SCy Schubert 
130585732ac8SCy Schubert 	os_free(sta->radius_cui);
130685732ac8SCy Schubert 	sta->radius_cui = NULL;
130785732ac8SCy Schubert 
130885732ac8SCy Schubert 	if (sta->eapol_sm) {
130985732ac8SCy Schubert 		wpabuf_free(sta->eapol_sm->radius_cui);
131085732ac8SCy Schubert 		sta->eapol_sm->radius_cui = NULL;
131185732ac8SCy Schubert 	}
131285732ac8SCy Schubert 
131385732ac8SCy Schubert 	if (!radius_cui)
131485732ac8SCy Schubert 		return 0;
131585732ac8SCy Schubert 
131685732ac8SCy Schubert 	/* sta->radius_cui is NULL terminated */
131785732ac8SCy Schubert 	sta->radius_cui = os_zalloc(radius_cui_len + 1);
131885732ac8SCy Schubert 	if (!sta->radius_cui)
131985732ac8SCy Schubert 		return -1;
132085732ac8SCy Schubert 	os_memcpy(sta->radius_cui, radius_cui, radius_cui_len);
132185732ac8SCy Schubert 
132285732ac8SCy Schubert 	if (sta->eapol_sm) {
132385732ac8SCy Schubert 		sta->eapol_sm->radius_cui = wpabuf_alloc_copy(radius_cui,
132485732ac8SCy Schubert 							      radius_cui_len);
132585732ac8SCy Schubert 		if (!sta->eapol_sm->radius_cui)
132685732ac8SCy Schubert 			return -1;
132785732ac8SCy Schubert 	}
132885732ac8SCy Schubert 
132985732ac8SCy Schubert 	return 0;
133085732ac8SCy Schubert }
133185732ac8SCy Schubert 
133285732ac8SCy Schubert 
133385732ac8SCy Schubert static size_t
hostapd_wpa_auth_get_radius_cui(void * ctx,const u8 * sta_addr,const u8 ** buf)133485732ac8SCy Schubert hostapd_wpa_auth_get_radius_cui(void *ctx, const u8 *sta_addr, const u8 **buf)
133585732ac8SCy Schubert {
133685732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
133785732ac8SCy Schubert 	struct sta_info *sta;
133885732ac8SCy Schubert 	struct wpabuf *b;
133985732ac8SCy Schubert 	size_t len;
134085732ac8SCy Schubert 	char *radius_cui;
134185732ac8SCy Schubert 
134285732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
134385732ac8SCy Schubert 	if (!sta)
134485732ac8SCy Schubert 		return 0;
134585732ac8SCy Schubert 
134685732ac8SCy Schubert 	b = ieee802_1x_get_radius_cui(sta->eapol_sm);
134785732ac8SCy Schubert 	if (b) {
134885732ac8SCy Schubert 		len = wpabuf_len(b);
134985732ac8SCy Schubert 		*buf = wpabuf_head(b);
135085732ac8SCy Schubert 		return len;
135185732ac8SCy Schubert 	}
135285732ac8SCy Schubert 
135385732ac8SCy Schubert 	if (!sta->radius_cui) {
135485732ac8SCy Schubert 		*buf = NULL;
135585732ac8SCy Schubert 		return 0;
135685732ac8SCy Schubert 	}
135785732ac8SCy Schubert 
135885732ac8SCy Schubert 	radius_cui = sta->radius_cui;
135985732ac8SCy Schubert 	len = os_strlen(radius_cui);
136085732ac8SCy Schubert 	*buf = (u8 *) radius_cui;
136185732ac8SCy Schubert 
136285732ac8SCy Schubert 	return len;
136385732ac8SCy Schubert }
136485732ac8SCy Schubert 
136585732ac8SCy Schubert 
hostapd_wpa_auth_set_session_timeout(void * ctx,const u8 * sta_addr,int session_timeout)136685732ac8SCy Schubert static void hostapd_wpa_auth_set_session_timeout(void *ctx, const u8 *sta_addr,
136785732ac8SCy Schubert 						 int session_timeout)
136885732ac8SCy Schubert {
136985732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
137085732ac8SCy Schubert 	struct sta_info *sta;
137185732ac8SCy Schubert 
137285732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
137385732ac8SCy Schubert 	if (!sta)
137485732ac8SCy Schubert 		return;
137585732ac8SCy Schubert 
137685732ac8SCy Schubert 	if (session_timeout) {
137785732ac8SCy Schubert 		os_get_reltime(&sta->session_timeout);
137885732ac8SCy Schubert 		sta->session_timeout.sec += session_timeout;
137985732ac8SCy Schubert 		sta->session_timeout_set = 1;
138085732ac8SCy Schubert 		ap_sta_session_timeout(hapd, sta, session_timeout);
138185732ac8SCy Schubert 	} else {
138285732ac8SCy Schubert 		sta->session_timeout_set = 0;
138385732ac8SCy Schubert 		ap_sta_no_session_timeout(hapd, sta);
138485732ac8SCy Schubert 	}
138585732ac8SCy Schubert }
138685732ac8SCy Schubert 
138785732ac8SCy Schubert 
hostapd_wpa_auth_get_session_timeout(void * ctx,const u8 * sta_addr)138885732ac8SCy Schubert static int hostapd_wpa_auth_get_session_timeout(void *ctx, const u8 *sta_addr)
138985732ac8SCy Schubert {
139085732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
139185732ac8SCy Schubert 	struct sta_info *sta;
139285732ac8SCy Schubert 	struct os_reltime now, remaining;
139385732ac8SCy Schubert 
139485732ac8SCy Schubert 	sta = ap_get_sta(hapd, sta_addr);
139585732ac8SCy Schubert 	if (!sta || !sta->session_timeout_set)
139685732ac8SCy Schubert 		return 0;
139785732ac8SCy Schubert 
139885732ac8SCy Schubert 	os_get_reltime(&now);
139985732ac8SCy Schubert 	if (os_reltime_before(&sta->session_timeout, &now)) {
140085732ac8SCy Schubert 		/* already expired, return >0 as timeout was set */
140185732ac8SCy Schubert 		return 1;
140285732ac8SCy Schubert 	}
140385732ac8SCy Schubert 
140485732ac8SCy Schubert 	os_reltime_sub(&sta->session_timeout, &now, &remaining);
140585732ac8SCy Schubert 
140685732ac8SCy Schubert 	return (remaining.sec > 0) ? remaining.sec : 1;
140785732ac8SCy Schubert }
140885732ac8SCy Schubert 
140985732ac8SCy Schubert 
hostapd_rrb_receive(void * ctx,const u8 * src_addr,const u8 * buf,size_t len)1410e28a4053SRui Paulo static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
1411e28a4053SRui Paulo 				size_t len)
1412e28a4053SRui Paulo {
1413e28a4053SRui Paulo 	struct hostapd_data *hapd = ctx;
1414f05cddf9SRui Paulo 	struct l2_ethhdr *ethhdr;
1415f05cddf9SRui Paulo 	if (len < sizeof(*ethhdr))
1416f05cddf9SRui Paulo 		return;
1417f05cddf9SRui Paulo 	ethhdr = (struct l2_ethhdr *) buf;
1418f05cddf9SRui Paulo 	wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
1419f05cddf9SRui Paulo 		   MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
1420780fb4a2SCy Schubert 	if (!is_multicast_ether_addr(ethhdr->h_dest) &&
1421*a90b9d01SCy Schubert 	    !ether_addr_equal(hapd->own_addr, ethhdr->h_dest))
1422780fb4a2SCy Schubert 		return;
1423f05cddf9SRui Paulo 	wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
1424f05cddf9SRui Paulo 		      len - sizeof(*ethhdr));
1425f05cddf9SRui Paulo }
1426f05cddf9SRui Paulo 
1427f05cddf9SRui Paulo 
hostapd_rrb_oui_receive(void * ctx,const u8 * src_addr,const u8 * dst_addr,u8 oui_suffix,const u8 * buf,size_t len)142885732ac8SCy Schubert static void hostapd_rrb_oui_receive(void *ctx, const u8 *src_addr,
142985732ac8SCy Schubert 				    const u8 *dst_addr, u8 oui_suffix,
143085732ac8SCy Schubert 				    const u8 *buf, size_t len)
143185732ac8SCy Schubert {
143285732ac8SCy Schubert 	struct hostapd_data *hapd = ctx;
143385732ac8SCy Schubert 
143485732ac8SCy Schubert 	wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
143585732ac8SCy Schubert 		   MACSTR, MAC2STR(src_addr), MAC2STR(dst_addr));
143685732ac8SCy Schubert 	if (!is_multicast_ether_addr(dst_addr) &&
1437*a90b9d01SCy Schubert 	    !ether_addr_equal(hapd->own_addr, dst_addr))
143885732ac8SCy Schubert 		return;
143985732ac8SCy Schubert 	wpa_ft_rrb_oui_rx(hapd->wpa_auth, src_addr, dst_addr, oui_suffix, buf,
144085732ac8SCy Schubert 			  len);
144185732ac8SCy Schubert }
144285732ac8SCy Schubert 
144385732ac8SCy Schubert 
hostapd_wpa_auth_add_tspec(void * ctx,const u8 * sta_addr,u8 * tspec_ie,size_t tspec_ielen)1444f05cddf9SRui Paulo static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
1445f05cddf9SRui Paulo 				      u8 *tspec_ie, size_t tspec_ielen)
1446f05cddf9SRui Paulo {
1447f05cddf9SRui Paulo 	struct hostapd_data *hapd = ctx;
1448f05cddf9SRui Paulo 	return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
1449e28a4053SRui Paulo }
1450e28a4053SRui Paulo 
145185732ac8SCy Schubert 
145285732ac8SCy Schubert 
hostapd_wpa_register_ft_oui(struct hostapd_data * hapd,const char * ft_iface)145385732ac8SCy Schubert static int hostapd_wpa_register_ft_oui(struct hostapd_data *hapd,
145485732ac8SCy Schubert 				       const char *ft_iface)
145585732ac8SCy Schubert {
145685732ac8SCy Schubert 	hapd->oui_pull = eth_p_oui_register(hapd, ft_iface,
145785732ac8SCy Schubert 					    FT_PACKET_R0KH_R1KH_PULL,
145885732ac8SCy Schubert 					    hostapd_rrb_oui_receive, hapd);
145985732ac8SCy Schubert 	if (!hapd->oui_pull)
146085732ac8SCy Schubert 		return -1;
146185732ac8SCy Schubert 
146285732ac8SCy Schubert 	hapd->oui_resp = eth_p_oui_register(hapd, ft_iface,
146385732ac8SCy Schubert 					    FT_PACKET_R0KH_R1KH_RESP,
146485732ac8SCy Schubert 					    hostapd_rrb_oui_receive, hapd);
146585732ac8SCy Schubert 	if (!hapd->oui_resp)
146685732ac8SCy Schubert 		return -1;
146785732ac8SCy Schubert 
146885732ac8SCy Schubert 	hapd->oui_push = eth_p_oui_register(hapd, ft_iface,
146985732ac8SCy Schubert 					    FT_PACKET_R0KH_R1KH_PUSH,
147085732ac8SCy Schubert 					    hostapd_rrb_oui_receive, hapd);
147185732ac8SCy Schubert 	if (!hapd->oui_push)
147285732ac8SCy Schubert 		return -1;
147385732ac8SCy Schubert 
147485732ac8SCy Schubert 	hapd->oui_sreq = eth_p_oui_register(hapd, ft_iface,
147585732ac8SCy Schubert 					    FT_PACKET_R0KH_R1KH_SEQ_REQ,
147685732ac8SCy Schubert 					    hostapd_rrb_oui_receive, hapd);
147785732ac8SCy Schubert 	if (!hapd->oui_sreq)
147885732ac8SCy Schubert 		return -1;
147985732ac8SCy Schubert 
148085732ac8SCy Schubert 	hapd->oui_sresp = eth_p_oui_register(hapd, ft_iface,
148185732ac8SCy Schubert 					     FT_PACKET_R0KH_R1KH_SEQ_RESP,
148285732ac8SCy Schubert 					     hostapd_rrb_oui_receive, hapd);
148385732ac8SCy Schubert 	if (!hapd->oui_sresp)
148485732ac8SCy Schubert 		return -1;
148585732ac8SCy Schubert 
148685732ac8SCy Schubert 	return 0;
148785732ac8SCy Schubert }
148885732ac8SCy Schubert 
148985732ac8SCy Schubert 
hostapd_wpa_unregister_ft_oui(struct hostapd_data * hapd)149085732ac8SCy Schubert static void hostapd_wpa_unregister_ft_oui(struct hostapd_data *hapd)
149185732ac8SCy Schubert {
149285732ac8SCy Schubert 	eth_p_oui_unregister(hapd->oui_pull);
149385732ac8SCy Schubert 	hapd->oui_pull = NULL;
149485732ac8SCy Schubert 	eth_p_oui_unregister(hapd->oui_resp);
149585732ac8SCy Schubert 	hapd->oui_resp = NULL;
149685732ac8SCy Schubert 	eth_p_oui_unregister(hapd->oui_push);
149785732ac8SCy Schubert 	hapd->oui_push = NULL;
149885732ac8SCy Schubert 	eth_p_oui_unregister(hapd->oui_sreq);
149985732ac8SCy Schubert 	hapd->oui_sreq = NULL;
150085732ac8SCy Schubert 	eth_p_oui_unregister(hapd->oui_sresp);
150185732ac8SCy Schubert 	hapd->oui_sresp = NULL;
150285732ac8SCy Schubert }
150385732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
1504e28a4053SRui Paulo 
1505e28a4053SRui Paulo 
1506*a90b9d01SCy Schubert #ifndef CONFIG_NO_RADIUS
hostapd_request_radius_psk(void * ctx,const u8 * addr,int key_mgmt,const u8 * anonce,const u8 * eapol,size_t eapol_len)1507*a90b9d01SCy Schubert static void hostapd_request_radius_psk(void *ctx, const u8 *addr, int key_mgmt,
1508*a90b9d01SCy Schubert 				       const u8 *anonce,
1509*a90b9d01SCy Schubert 				       const u8 *eapol, size_t eapol_len)
1510*a90b9d01SCy Schubert {
1511*a90b9d01SCy Schubert 	struct hostapd_data *hapd = ctx;
1512*a90b9d01SCy Schubert 
1513*a90b9d01SCy Schubert 	wpa_printf(MSG_DEBUG, "RADIUS PSK request for " MACSTR " key_mgmt=0x%x",
1514*a90b9d01SCy Schubert 		   MAC2STR(addr), key_mgmt);
1515*a90b9d01SCy Schubert 	wpa_hexdump(MSG_DEBUG, "ANonce", anonce, WPA_NONCE_LEN);
1516*a90b9d01SCy Schubert 	wpa_hexdump(MSG_DEBUG, "EAPOL", eapol, eapol_len);
1517*a90b9d01SCy Schubert 	hostapd_acl_req_radius_psk(hapd, addr, key_mgmt, anonce, eapol,
1518*a90b9d01SCy Schubert 				   eapol_len);
1519*a90b9d01SCy Schubert }
1520*a90b9d01SCy Schubert #endif /* CONFIG_NO_RADIUS */
1521*a90b9d01SCy Schubert 
1522*a90b9d01SCy Schubert 
1523*a90b9d01SCy Schubert #ifdef CONFIG_PASN
hostapd_set_ltf_keyseed(void * ctx,const u8 * peer_addr,const u8 * ltf_keyseed,size_t ltf_keyseed_len)1524*a90b9d01SCy Schubert static int hostapd_set_ltf_keyseed(void *ctx, const u8 *peer_addr,
1525*a90b9d01SCy Schubert 				   const u8 *ltf_keyseed,
1526*a90b9d01SCy Schubert 				   size_t ltf_keyseed_len)
1527*a90b9d01SCy Schubert {
1528*a90b9d01SCy Schubert 	struct hostapd_data *hapd = ctx;
1529*a90b9d01SCy Schubert 
1530*a90b9d01SCy Schubert 	return hostapd_drv_set_secure_ranging_ctx(hapd, hapd->own_addr,
1531*a90b9d01SCy Schubert 						  peer_addr, 0, 0, NULL,
1532*a90b9d01SCy Schubert 						  ltf_keyseed_len,
1533*a90b9d01SCy Schubert 						  ltf_keyseed, 0);
1534*a90b9d01SCy Schubert }
1535*a90b9d01SCy Schubert #endif /* CONFIG_PASN */
1536*a90b9d01SCy Schubert 
1537*a90b9d01SCy Schubert 
1538*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1539*a90b9d01SCy Schubert 
hostapd_wpa_auth_get_ml_key_info(void * ctx,struct wpa_auth_ml_key_info * info)1540*a90b9d01SCy Schubert static int hostapd_wpa_auth_get_ml_key_info(void *ctx,
1541*a90b9d01SCy Schubert 					    struct wpa_auth_ml_key_info *info)
1542*a90b9d01SCy Schubert {
1543*a90b9d01SCy Schubert 	struct hostapd_data *hapd = ctx;
1544*a90b9d01SCy Schubert 	unsigned int i;
1545*a90b9d01SCy Schubert 
1546*a90b9d01SCy Schubert 	wpa_printf(MSG_DEBUG, "WPA_AUTH: MLD: Get key info CB: n_mld_links=%u",
1547*a90b9d01SCy Schubert 		   info->n_mld_links);
1548*a90b9d01SCy Schubert 
1549*a90b9d01SCy Schubert 	if (!hapd->conf->mld_ap || !hapd->iface || !hapd->iface->interfaces)
1550*a90b9d01SCy Schubert 		return -1;
1551*a90b9d01SCy Schubert 
1552*a90b9d01SCy Schubert 	for (i = 0; i < info->n_mld_links; i++) {
1553*a90b9d01SCy Schubert 		struct hostapd_data *bss;
1554*a90b9d01SCy Schubert 		u8 link_id = info->links[i].link_id;
1555*a90b9d01SCy Schubert 		bool link_bss_found = false;
1556*a90b9d01SCy Schubert 
1557*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
1558*a90b9d01SCy Schubert 			   "WPA_AUTH: MLD: Get link info CB: link_id=%u",
1559*a90b9d01SCy Schubert 			   link_id);
1560*a90b9d01SCy Schubert 
1561*a90b9d01SCy Schubert 		if (hapd->mld_link_id == link_id) {
1562*a90b9d01SCy Schubert 			wpa_auth_ml_get_key_info(hapd->wpa_auth,
1563*a90b9d01SCy Schubert 						 &info->links[i],
1564*a90b9d01SCy Schubert 						 info->mgmt_frame_prot,
1565*a90b9d01SCy Schubert 						 info->beacon_prot);
1566*a90b9d01SCy Schubert 			continue;
1567*a90b9d01SCy Schubert 		}
1568*a90b9d01SCy Schubert 
1569*a90b9d01SCy Schubert 		for_each_mld_link(bss, hapd) {
1570*a90b9d01SCy Schubert 			if (bss == hapd || bss->mld_link_id != link_id)
1571*a90b9d01SCy Schubert 				continue;
1572*a90b9d01SCy Schubert 
1573*a90b9d01SCy Schubert 			wpa_auth_ml_get_key_info(bss->wpa_auth,
1574*a90b9d01SCy Schubert 						 &info->links[i],
1575*a90b9d01SCy Schubert 						 info->mgmt_frame_prot,
1576*a90b9d01SCy Schubert 						 info->beacon_prot);
1577*a90b9d01SCy Schubert 			link_bss_found = true;
1578*a90b9d01SCy Schubert 			break;
1579*a90b9d01SCy Schubert 		}
1580*a90b9d01SCy Schubert 
1581*a90b9d01SCy Schubert 		if (!link_bss_found)
1582*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
1583*a90b9d01SCy Schubert 				   "WPA_AUTH: MLD: link=%u not found", link_id);
1584*a90b9d01SCy Schubert 	}
1585*a90b9d01SCy Schubert 
1586*a90b9d01SCy Schubert 	return 0;
1587*a90b9d01SCy Schubert }
1588*a90b9d01SCy Schubert 
1589*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1590*a90b9d01SCy Schubert 
1591*a90b9d01SCy Schubert 
hostapd_wpa_auth_get_drv_flags(void * ctx,u64 * drv_flags,u64 * drv_flags2)1592*a90b9d01SCy Schubert static int hostapd_wpa_auth_get_drv_flags(void *ctx,
1593*a90b9d01SCy Schubert 					  u64 *drv_flags, u64 *drv_flags2)
1594*a90b9d01SCy Schubert {
1595*a90b9d01SCy Schubert 	struct hostapd_data *hapd = ctx;
1596*a90b9d01SCy Schubert 
1597*a90b9d01SCy Schubert 	if (drv_flags)
1598*a90b9d01SCy Schubert 		*drv_flags = hapd->iface->drv_flags;
1599*a90b9d01SCy Schubert 	if (drv_flags2)
1600*a90b9d01SCy Schubert 		*drv_flags2 = hapd->iface->drv_flags2;
1601*a90b9d01SCy Schubert 
1602*a90b9d01SCy Schubert 	return 0;
1603*a90b9d01SCy Schubert }
1604*a90b9d01SCy Schubert 
1605*a90b9d01SCy Schubert 
hostapd_setup_wpa(struct hostapd_data * hapd)1606e28a4053SRui Paulo int hostapd_setup_wpa(struct hostapd_data *hapd)
1607e28a4053SRui Paulo {
1608e28a4053SRui Paulo 	struct wpa_auth_config _conf;
160985732ac8SCy Schubert 	static const struct wpa_auth_callbacks cb = {
161085732ac8SCy Schubert 		.logger = hostapd_wpa_auth_logger,
161185732ac8SCy Schubert 		.disconnect = hostapd_wpa_auth_disconnect,
161285732ac8SCy Schubert 		.mic_failure_report = hostapd_wpa_auth_mic_failure_report,
161385732ac8SCy Schubert 		.psk_failure_report = hostapd_wpa_auth_psk_failure_report,
161485732ac8SCy Schubert 		.set_eapol = hostapd_wpa_auth_set_eapol,
161585732ac8SCy Schubert 		.get_eapol = hostapd_wpa_auth_get_eapol,
161685732ac8SCy Schubert 		.get_psk = hostapd_wpa_auth_get_psk,
161785732ac8SCy Schubert 		.get_msk = hostapd_wpa_auth_get_msk,
161885732ac8SCy Schubert 		.set_key = hostapd_wpa_auth_set_key,
161985732ac8SCy Schubert 		.get_seqnum = hostapd_wpa_auth_get_seqnum,
162085732ac8SCy Schubert 		.send_eapol = hostapd_wpa_auth_send_eapol,
1621*a90b9d01SCy Schubert 		.get_sta_count = hostapd_wpa_auth_get_sta_count,
162285732ac8SCy Schubert 		.for_each_sta = hostapd_wpa_auth_for_each_sta,
162385732ac8SCy Schubert 		.for_each_auth = hostapd_wpa_auth_for_each_auth,
162485732ac8SCy Schubert 		.send_ether = hostapd_wpa_auth_send_ether,
162585732ac8SCy Schubert 		.send_oui = hostapd_wpa_auth_send_oui,
16264bc52338SCy Schubert 		.channel_info = hostapd_channel_info,
16274bc52338SCy Schubert 		.update_vlan = hostapd_wpa_auth_update_vlan,
1628c1d255d3SCy Schubert #ifdef CONFIG_PASN
1629c1d255d3SCy Schubert 		.store_ptksa = hostapd_store_ptksa,
1630c1d255d3SCy Schubert 		.clear_ptksa = hostapd_clear_ptksa,
1631c1d255d3SCy Schubert #endif /* CONFIG_PASN */
1632c1d255d3SCy Schubert 
16334bc52338SCy Schubert #ifdef CONFIG_OCV
16344bc52338SCy Schubert 		.get_sta_tx_params = hostapd_get_sta_tx_params,
16354bc52338SCy Schubert #endif /* CONFIG_OCV */
163685732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
163785732ac8SCy Schubert 		.send_ft_action = hostapd_wpa_auth_send_ft_action,
163885732ac8SCy Schubert 		.add_sta = hostapd_wpa_auth_add_sta,
1639c1d255d3SCy Schubert 		.add_sta_ft = hostapd_wpa_auth_add_sta_ft,
164085732ac8SCy Schubert 		.add_tspec = hostapd_wpa_auth_add_tspec,
164185732ac8SCy Schubert 		.set_vlan = hostapd_wpa_auth_set_vlan,
164285732ac8SCy Schubert 		.get_vlan = hostapd_wpa_auth_get_vlan,
164385732ac8SCy Schubert 		.set_identity = hostapd_wpa_auth_set_identity,
164485732ac8SCy Schubert 		.get_identity = hostapd_wpa_auth_get_identity,
164585732ac8SCy Schubert 		.set_radius_cui = hostapd_wpa_auth_set_radius_cui,
164685732ac8SCy Schubert 		.get_radius_cui = hostapd_wpa_auth_get_radius_cui,
164785732ac8SCy Schubert 		.set_session_timeout = hostapd_wpa_auth_set_session_timeout,
164885732ac8SCy Schubert 		.get_session_timeout = hostapd_wpa_auth_get_session_timeout,
164985732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
1650*a90b9d01SCy Schubert #ifndef CONFIG_NO_RADIUS
1651*a90b9d01SCy Schubert 		.request_radius_psk = hostapd_request_radius_psk,
1652*a90b9d01SCy Schubert #endif /* CONFIG_NO_RADIUS */
1653*a90b9d01SCy Schubert #ifdef CONFIG_PASN
1654*a90b9d01SCy Schubert 		.set_ltf_keyseed = hostapd_set_ltf_keyseed,
1655*a90b9d01SCy Schubert #endif /* CONFIG_PASN */
1656*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1657*a90b9d01SCy Schubert 		.get_ml_key_info = hostapd_wpa_auth_get_ml_key_info,
1658*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1659*a90b9d01SCy Schubert 		.get_drv_flags = hostapd_wpa_auth_get_drv_flags,
166085732ac8SCy Schubert 	};
1661e28a4053SRui Paulo 	const u8 *wpa_ie;
1662e28a4053SRui Paulo 	size_t wpa_ie_len;
1663*a90b9d01SCy Schubert 	struct hostapd_data *tx_bss;
1664e28a4053SRui Paulo 
16655b9c547cSRui Paulo 	hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
1666c1d255d3SCy Schubert 	_conf.msg_ctx = hapd->msg_ctx;
1667*a90b9d01SCy Schubert 	tx_bss = hostapd_mbssid_get_tx_bss(hapd);
1668*a90b9d01SCy Schubert 	if (tx_bss != hapd)
1669*a90b9d01SCy Schubert 		_conf.tx_bss_auth = tx_bss->wpa_auth;
1670f05cddf9SRui Paulo 	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
1671f05cddf9SRui Paulo 		_conf.tx_status = 1;
1672f05cddf9SRui Paulo 	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
1673f05cddf9SRui Paulo 		_conf.ap_mlme = 1;
1674c1d255d3SCy Schubert 
1675c1d255d3SCy Schubert 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) &&
1676c1d255d3SCy Schubert 	    (hapd->conf->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_NEVER ||
1677c1d255d3SCy Schubert 	     (hapd->conf->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_LOCAL_OK &&
1678c1d255d3SCy Schubert 	      !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS)))) {
1679c1d255d3SCy Schubert 		wpa_msg(hapd->msg_ctx, MSG_INFO,
1680c1d255d3SCy Schubert 			"Disable PTK0 rekey support - replaced with disconnect");
1681c1d255d3SCy Schubert 		_conf.wpa_deny_ptk0_rekey = 1;
1682c1d255d3SCy Schubert 	}
1683c1d255d3SCy Schubert 
1684c1d255d3SCy Schubert 	if (_conf.extended_key_id &&
1685c1d255d3SCy Schubert 	    (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EXTENDED_KEY_ID))
1686c1d255d3SCy Schubert 		wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Extended Key ID supported");
1687c1d255d3SCy Schubert 	else
1688c1d255d3SCy Schubert 		_conf.extended_key_id = 0;
1689c1d255d3SCy Schubert 
1690c1d255d3SCy Schubert 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION))
1691c1d255d3SCy Schubert 		_conf.beacon_prot = 0;
1692c1d255d3SCy Schubert 
1693c1d255d3SCy Schubert #ifdef CONFIG_OCV
1694c1d255d3SCy Schubert 	if (!(hapd->iface->drv_flags2 &
1695c1d255d3SCy Schubert 	      (WPA_DRIVER_FLAGS2_AP_SME | WPA_DRIVER_FLAGS2_OCV)))
1696c1d255d3SCy Schubert 		_conf.ocv = 0;
1697c1d255d3SCy Schubert #endif /* CONFIG_OCV */
1698c1d255d3SCy Schubert 
1699c1d255d3SCy Schubert 	_conf.secure_ltf =
1700*a90b9d01SCy Schubert 		!!(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_LTF_AP);
1701c1d255d3SCy Schubert 	_conf.secure_rtt =
1702*a90b9d01SCy Schubert 		!!(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_RTT_AP);
1703c1d255d3SCy Schubert 	_conf.prot_range_neg =
1704*a90b9d01SCy Schubert 		!!(hapd->iface->drv_flags2 &
1705*a90b9d01SCy Schubert 		   WPA_DRIVER_FLAGS2_PROT_RANGE_NEG_AP);
1706*a90b9d01SCy Schubert 
1707*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1708*a90b9d01SCy Schubert 	_conf.mld_addr = NULL;
1709*a90b9d01SCy Schubert 	_conf.link_id = -1;
1710*a90b9d01SCy Schubert 	_conf.first_link_auth = NULL;
1711*a90b9d01SCy Schubert 
1712*a90b9d01SCy Schubert 	if (hapd->conf->mld_ap) {
1713*a90b9d01SCy Schubert 		struct hostapd_data *lhapd;
1714*a90b9d01SCy Schubert 
1715*a90b9d01SCy Schubert 		_conf.mld_addr = hapd->mld->mld_addr;
1716*a90b9d01SCy Schubert 		_conf.link_id = hapd->mld_link_id;
1717*a90b9d01SCy Schubert 
1718*a90b9d01SCy Schubert 		for_each_mld_link(lhapd, hapd) {
1719*a90b9d01SCy Schubert 			if (lhapd == hapd)
1720*a90b9d01SCy Schubert 				continue;
1721*a90b9d01SCy Schubert 
1722*a90b9d01SCy Schubert 			if (lhapd->wpa_auth)
1723*a90b9d01SCy Schubert 				_conf.first_link_auth = lhapd->wpa_auth;
1724*a90b9d01SCy Schubert 		}
1725*a90b9d01SCy Schubert 	}
1726*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1727c1d255d3SCy Schubert 
172885732ac8SCy Schubert 	hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb, hapd);
1729e28a4053SRui Paulo 	if (hapd->wpa_auth == NULL) {
1730e28a4053SRui Paulo 		wpa_printf(MSG_ERROR, "WPA initialization failed.");
1731e28a4053SRui Paulo 		return -1;
1732e28a4053SRui Paulo 	}
1733e28a4053SRui Paulo 
1734e28a4053SRui Paulo 	if (hostapd_set_privacy(hapd, 1)) {
1735e28a4053SRui Paulo 		wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
1736e28a4053SRui Paulo 			   "for interface %s", hapd->conf->iface);
1737e28a4053SRui Paulo 		return -1;
1738e28a4053SRui Paulo 	}
1739e28a4053SRui Paulo 
1740e28a4053SRui Paulo 	wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
1741e28a4053SRui Paulo 	if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
1742e28a4053SRui Paulo 		wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
1743e28a4053SRui Paulo 			   "the kernel driver.");
1744e28a4053SRui Paulo 		return -1;
1745e28a4053SRui Paulo 	}
1746e28a4053SRui Paulo 
1747e28a4053SRui Paulo 	if (rsn_preauth_iface_init(hapd)) {
1748e28a4053SRui Paulo 		wpa_printf(MSG_ERROR, "Initialization of RSN "
1749e28a4053SRui Paulo 			   "pre-authentication failed.");
1750e28a4053SRui Paulo 		return -1;
1751e28a4053SRui Paulo 	}
1752e28a4053SRui Paulo 
1753c1d255d3SCy Schubert 	if (!hapd->ptksa)
1754c1d255d3SCy Schubert 		hapd->ptksa = ptksa_cache_init();
1755c1d255d3SCy Schubert 	if (!hapd->ptksa) {
1756c1d255d3SCy Schubert 		wpa_printf(MSG_ERROR, "Failed to allocate PTKSA cache");
1757c1d255d3SCy Schubert 		return -1;
1758c1d255d3SCy Schubert 	}
1759c1d255d3SCy Schubert 
176085732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
1761780fb4a2SCy Schubert 	if (!hostapd_drv_none(hapd) &&
1762325151a3SRui Paulo 	    wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
176385732ac8SCy Schubert 		const char *ft_iface;
176485732ac8SCy Schubert 
176585732ac8SCy Schubert 		ft_iface = hapd->conf->bridge[0] ? hapd->conf->bridge :
176685732ac8SCy Schubert 			   hapd->conf->iface;
176785732ac8SCy Schubert 		hapd->l2 = l2_packet_init(ft_iface, NULL, ETH_P_RRB,
1768f05cddf9SRui Paulo 					  hostapd_rrb_receive, hapd, 1);
1769c1d255d3SCy Schubert 		if (!hapd->l2) {
1770e28a4053SRui Paulo 			wpa_printf(MSG_ERROR, "Failed to open l2_packet "
1771e28a4053SRui Paulo 				   "interface");
1772e28a4053SRui Paulo 			return -1;
1773e28a4053SRui Paulo 		}
177485732ac8SCy Schubert 
177585732ac8SCy Schubert 		if (hostapd_wpa_register_ft_oui(hapd, ft_iface)) {
177685732ac8SCy Schubert 			wpa_printf(MSG_ERROR,
177785732ac8SCy Schubert 				   "Failed to open ETH_P_OUI interface");
177885732ac8SCy Schubert 			return -1;
1779e28a4053SRui Paulo 		}
178085732ac8SCy Schubert 	}
178185732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
1782e28a4053SRui Paulo 
1783e28a4053SRui Paulo 	return 0;
1784e28a4053SRui Paulo 
1785e28a4053SRui Paulo }
1786e28a4053SRui Paulo 
1787e28a4053SRui Paulo 
hostapd_reconfig_wpa(struct hostapd_data * hapd)1788e28a4053SRui Paulo void hostapd_reconfig_wpa(struct hostapd_data *hapd)
1789e28a4053SRui Paulo {
1790e28a4053SRui Paulo 	struct wpa_auth_config wpa_auth_conf;
17915b9c547cSRui Paulo 	hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
1792e28a4053SRui Paulo 	wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
1793e28a4053SRui Paulo }
1794e28a4053SRui Paulo 
1795e28a4053SRui Paulo 
hostapd_deinit_wpa(struct hostapd_data * hapd)1796e28a4053SRui Paulo void hostapd_deinit_wpa(struct hostapd_data *hapd)
1797e28a4053SRui Paulo {
1798f05cddf9SRui Paulo 	ieee80211_tkip_countermeasures_deinit(hapd);
1799c1d255d3SCy Schubert 	ptksa_cache_deinit(hapd->ptksa);
1800c1d255d3SCy Schubert 	hapd->ptksa = NULL;
1801c1d255d3SCy Schubert 
1802e28a4053SRui Paulo 	rsn_preauth_iface_deinit(hapd);
1803e28a4053SRui Paulo 	if (hapd->wpa_auth) {
1804e28a4053SRui Paulo 		wpa_deinit(hapd->wpa_auth);
1805e28a4053SRui Paulo 		hapd->wpa_auth = NULL;
1806e28a4053SRui Paulo 
1807780fb4a2SCy Schubert 		if (hapd->drv_priv && hostapd_set_privacy(hapd, 0)) {
1808e28a4053SRui Paulo 			wpa_printf(MSG_DEBUG, "Could not disable "
1809e28a4053SRui Paulo 				   "PrivacyInvoked for interface %s",
1810e28a4053SRui Paulo 				   hapd->conf->iface);
1811e28a4053SRui Paulo 		}
1812e28a4053SRui Paulo 
1813780fb4a2SCy Schubert 		if (hapd->drv_priv &&
1814780fb4a2SCy Schubert 		    hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
1815e28a4053SRui Paulo 			wpa_printf(MSG_DEBUG, "Could not remove generic "
1816e28a4053SRui Paulo 				   "information element from interface %s",
1817e28a4053SRui Paulo 				   hapd->conf->iface);
1818e28a4053SRui Paulo 		}
1819e28a4053SRui Paulo 	}
1820e28a4053SRui Paulo 	ieee802_1x_deinit(hapd);
1821e28a4053SRui Paulo 
182285732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
182385732ac8SCy Schubert 	eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later, hapd, ELOOP_ALL_CTX);
182485732ac8SCy Schubert 	hostapd_wpa_ft_rrb_rx_later(hapd, NULL); /* flush without delivering */
182585732ac8SCy Schubert 	eloop_cancel_timeout(hostapd_oui_deliver_later, hapd, ELOOP_ALL_CTX);
182685732ac8SCy Schubert 	hostapd_oui_deliver_later(hapd, NULL); /* flush without delivering */
1827e28a4053SRui Paulo 	l2_packet_deinit(hapd->l2);
18285b9c547cSRui Paulo 	hapd->l2 = NULL;
182985732ac8SCy Schubert 	hostapd_wpa_unregister_ft_oui(hapd);
183085732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
1831*a90b9d01SCy Schubert 
1832*a90b9d01SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
1833*a90b9d01SCy Schubert 	forced_memzero(hapd->last_gtk, WPA_GTK_MAX_LEN);
1834*a90b9d01SCy Schubert 	forced_memzero(hapd->last_igtk, WPA_IGTK_MAX_LEN);
1835*a90b9d01SCy Schubert 	forced_memzero(hapd->last_bigtk, WPA_BIGTK_MAX_LEN);
1836*a90b9d01SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
1837e28a4053SRui Paulo }
1838