1 /*
2  * hostapd - Driver operations
3  * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "utils/includes.h"
10 
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/ieee802_11_common.h"
14 #include "common/hw_features_common.h"
15 #include "wps/wps.h"
16 #include "p2p/p2p.h"
17 #include "hostapd.h"
18 #include "ieee802_11.h"
19 #include "sta_info.h"
20 #include "ap_config.h"
21 #include "p2p_hostapd.h"
22 #include "hs20.h"
23 #include "wpa_auth.h"
24 #include "ap_drv_ops.h"
25 
26 
hostapd_sta_flags_to_drv(u32 flags)27 u32 hostapd_sta_flags_to_drv(u32 flags)
28 {
29 	int res = 0;
30 	if (flags & WLAN_STA_AUTHORIZED)
31 		res |= WPA_STA_AUTHORIZED;
32 	if (flags & WLAN_STA_WMM)
33 		res |= WPA_STA_WMM;
34 	if (flags & WLAN_STA_SHORT_PREAMBLE)
35 		res |= WPA_STA_SHORT_PREAMBLE;
36 	if (flags & WLAN_STA_MFP)
37 		res |= WPA_STA_MFP;
38 	if (flags & WLAN_STA_AUTH)
39 		res |= WPA_STA_AUTHENTICATED;
40 	if (flags & WLAN_STA_ASSOC)
41 		res |= WPA_STA_ASSOCIATED;
42 	if (flags & WLAN_STA_SPP_AMSDU)
43 		res |= WPA_STA_SPP_AMSDU;
44 	return res;
45 }
46 
47 
add_buf(struct wpabuf ** dst,const struct wpabuf * src)48 static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
49 {
50 	if (!src)
51 		return 0;
52 	if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
53 		return -1;
54 	wpabuf_put_buf(*dst, src);
55 	return 0;
56 }
57 
58 
add_buf_data(struct wpabuf ** dst,const u8 * data,size_t len)59 static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
60 {
61 	if (!data || !len)
62 		return 0;
63 	if (wpabuf_resize(dst, len) != 0)
64 		return -1;
65 	wpabuf_put_data(*dst, data, len);
66 	return 0;
67 }
68 
69 
hostapd_build_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf ** beacon_ret,struct wpabuf ** proberesp_ret,struct wpabuf ** assocresp_ret)70 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
71 			       struct wpabuf **beacon_ret,
72 			       struct wpabuf **proberesp_ret,
73 			       struct wpabuf **assocresp_ret)
74 {
75 	struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
76 	u8 buf[200], *pos;
77 
78 	*beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
79 
80 #ifdef NEED_AP_MLME
81 	pos = buf;
82 	pos = hostapd_eid_rm_enabled_capab(hapd, pos, sizeof(buf));
83 	if (add_buf_data(&assocresp, buf, pos - buf) < 0 ||
84 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
85 		goto fail;
86 #endif /* NEED_AP_MLME */
87 
88 	pos = buf;
89 	pos = hostapd_eid_time_adv(hapd, pos);
90 	if (add_buf_data(&beacon, buf, pos - buf) < 0)
91 		goto fail;
92 	pos = hostapd_eid_time_zone(hapd, pos);
93 	if (add_buf_data(&proberesp, buf, pos - buf) < 0)
94 		goto fail;
95 
96 	pos = buf;
97 	pos = hostapd_eid_ext_capab(hapd, pos, false);
98 	if (add_buf_data(&assocresp, buf, pos - buf) < 0)
99 		goto fail;
100 	pos = hostapd_eid_interworking(hapd, pos);
101 	pos = hostapd_eid_adv_proto(hapd, pos);
102 	pos = hostapd_eid_roaming_consortium(hapd, pos);
103 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
104 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
105 		goto fail;
106 
107 #ifdef CONFIG_FST
108 	if (add_buf(&beacon, hapd->iface->fst_ies) < 0 ||
109 	    add_buf(&proberesp, hapd->iface->fst_ies) < 0 ||
110 	    add_buf(&assocresp, hapd->iface->fst_ies) < 0)
111 		goto fail;
112 #endif /* CONFIG_FST */
113 
114 #ifdef CONFIG_FILS
115 	pos = hostapd_eid_fils_indic(hapd, buf, 0);
116 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
117 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
118 		goto fail;
119 #endif /* CONFIG_FILS */
120 
121 	if (!hapd->conf->rsn_override_omit_rsnxe) {
122 		pos = hostapd_eid_rsnxe(hapd, buf, sizeof(buf));
123 		if (add_buf_data(&assocresp, buf, pos - buf) < 0)
124 			goto fail;
125 	}
126 
127 	if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
128 	    add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
129 		goto fail;
130 
131 #ifdef CONFIG_P2P
132 	if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
133 	    add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
134 		goto fail;
135 #endif /* CONFIG_P2P */
136 
137 #ifdef CONFIG_P2P_MANAGER
138 	if (hapd->conf->p2p & P2P_MANAGE) {
139 		if (wpabuf_resize(&beacon, 100) == 0) {
140 			u8 *start, *p;
141 			start = wpabuf_put(beacon, 0);
142 			p = hostapd_eid_p2p_manage(hapd, start);
143 			wpabuf_put(beacon, p - start);
144 		}
145 
146 		if (wpabuf_resize(&proberesp, 100) == 0) {
147 			u8 *start, *p;
148 			start = wpabuf_put(proberesp, 0);
149 			p = hostapd_eid_p2p_manage(hapd, start);
150 			wpabuf_put(proberesp, p - start);
151 		}
152 	}
153 #endif /* CONFIG_P2P_MANAGER */
154 
155 #ifdef CONFIG_WPS
156 	if (hapd->conf->wps_state) {
157 		struct wpabuf *a = wps_build_assoc_resp_ie();
158 		add_buf(&assocresp, a);
159 		wpabuf_free(a);
160 	}
161 #endif /* CONFIG_WPS */
162 
163 #ifdef CONFIG_P2P_MANAGER
164 	if (hapd->conf->p2p & P2P_MANAGE) {
165 		if (wpabuf_resize(&assocresp, 100) == 0) {
166 			u8 *start, *p;
167 			start = wpabuf_put(assocresp, 0);
168 			p = hostapd_eid_p2p_manage(hapd, start);
169 			wpabuf_put(assocresp, p - start);
170 		}
171 	}
172 #endif /* CONFIG_P2P_MANAGER */
173 
174 #ifdef CONFIG_WIFI_DISPLAY
175 	if (hapd->p2p_group) {
176 		struct wpabuf *a;
177 		a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
178 		add_buf(&assocresp, a);
179 		wpabuf_free(a);
180 	}
181 #endif /* CONFIG_WIFI_DISPLAY */
182 
183 #ifdef CONFIG_HS20
184 	pos = hostapd_eid_hs20_indication(hapd, buf);
185 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
186 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
187 		goto fail;
188 #endif /* CONFIG_HS20 */
189 
190 #ifdef CONFIG_MBO
191 	if (hapd->conf->mbo_enabled ||
192 	    OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
193 		pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
194 		if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
195 		    add_buf_data(&proberesp, buf, pos - buf) < 0 ||
196 		    add_buf_data(&assocresp, buf, pos - buf) < 0)
197 			goto fail;
198 	}
199 #endif /* CONFIG_MBO */
200 
201 #ifdef CONFIG_OWE
202 	pos = hostapd_eid_owe_trans(hapd, buf, sizeof(buf));
203 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
204 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
205 		goto fail;
206 #endif /* CONFIG_OWE */
207 
208 	add_buf(&beacon, hapd->conf->vendor_elements);
209 	add_buf(&proberesp, hapd->conf->vendor_elements);
210 #ifdef CONFIG_TESTING_OPTIONS
211 	add_buf(&proberesp, hapd->conf->presp_elements);
212 #endif /* CONFIG_TESTING_OPTIONS */
213 	add_buf(&assocresp, hapd->conf->assocresp_elements);
214 
215 	*beacon_ret = beacon;
216 	*proberesp_ret = proberesp;
217 	*assocresp_ret = assocresp;
218 
219 	return 0;
220 
221 fail:
222 	wpabuf_free(beacon);
223 	wpabuf_free(proberesp);
224 	wpabuf_free(assocresp);
225 	return -1;
226 }
227 
228 
hostapd_free_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf * beacon,struct wpabuf * proberesp,struct wpabuf * assocresp)229 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
230 			       struct wpabuf *beacon,
231 			       struct wpabuf *proberesp,
232 			       struct wpabuf *assocresp)
233 {
234 	wpabuf_free(beacon);
235 	wpabuf_free(proberesp);
236 	wpabuf_free(assocresp);
237 }
238 
239 
hostapd_reset_ap_wps_ie(struct hostapd_data * hapd)240 int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
241 {
242 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
243 		return 0;
244 
245 	return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
246 }
247 
248 
hostapd_set_ap_wps_ie(struct hostapd_data * hapd)249 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
250 {
251 	struct wpabuf *beacon, *proberesp, *assocresp;
252 	int ret;
253 
254 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
255 		return 0;
256 
257 	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
258 	    0)
259 		return -1;
260 
261 	ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
262 					  assocresp);
263 
264 	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
265 
266 	return ret;
267 }
268 
269 
hostapd_sta_is_link_sta(struct hostapd_data * hapd,struct sta_info * sta)270 bool hostapd_sta_is_link_sta(struct hostapd_data *hapd,
271 			     struct sta_info *sta)
272 {
273 #ifdef CONFIG_IEEE80211BE
274 	if (ap_sta_is_mld(hapd, sta) &&
275 	    sta->mld_assoc_link_id != hapd->mld_link_id)
276 		return true;
277 #endif /* CONFIG_IEEE80211BE */
278 
279 	return false;
280 }
281 
282 
hostapd_set_authorized(struct hostapd_data * hapd,struct sta_info * sta,int authorized)283 int hostapd_set_authorized(struct hostapd_data *hapd,
284 			   struct sta_info *sta, int authorized)
285 {
286 	/*
287 	 * The WPA_STA_AUTHORIZED flag is relevant only for the MLD station and
288 	 * not to the link stations (as the authorization is done between the
289 	 * MLD peers). Thus, do not propagate the change to the driver for the
290 	 * link stations.
291 	 */
292 	if (hostapd_sta_is_link_sta(hapd, sta)) {
293 		wpa_printf(MSG_DEBUG,
294 			   "%s: Do not update link station flags (" MACSTR ")",
295 			   __func__, MAC2STR(sta->addr));
296 		return 0;
297 	}
298 
299 	if (authorized) {
300 		return hostapd_sta_set_flags(hapd, sta->addr,
301 					     hostapd_sta_flags_to_drv(
302 						     sta->flags),
303 					     WPA_STA_AUTHORIZED, ~0);
304 	}
305 
306 	return hostapd_sta_set_flags(hapd, sta->addr,
307 				     hostapd_sta_flags_to_drv(sta->flags),
308 				     0, ~WPA_STA_AUTHORIZED);
309 }
310 
311 
hostapd_set_sta_flags(struct hostapd_data * hapd,struct sta_info * sta)312 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
313 {
314 	int set_flags, total_flags, flags_and, flags_or;
315 	total_flags = hostapd_sta_flags_to_drv(sta->flags);
316 	set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP |
317 		WPA_STA_AUTHORIZED;
318 
319 	/*
320 	 * All the station flags other than WPA_STA_SHORT_PREAMBLE are relevant
321 	 * only for the MLD station and not to the link stations (as these flags
322 	 * are related to the MLD state and not the link state). As for the
323 	 * WPA_STA_SHORT_PREAMBLE, since the station is an EHT station, it must
324 	 * support short preamble. Thus, do not propagate the change to the
325 	 * driver for the link stations.
326 	 */
327 	if (hostapd_sta_is_link_sta(hapd, sta)) {
328 		wpa_printf(MSG_DEBUG,
329 			   "%s: Do not update link station flags (" MACSTR ")",
330 			   __func__, MAC2STR(sta->addr));
331 		return 0;
332 	}
333 
334 	flags_or = total_flags & set_flags;
335 	flags_and = total_flags | ~set_flags;
336 	return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
337 				     flags_or, flags_and);
338 }
339 
340 
hostapd_set_drv_ieee8021x(struct hostapd_data * hapd,const char * ifname,int enabled)341 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
342 			      int enabled)
343 {
344 	struct wpa_bss_params params;
345 	os_memset(&params, 0, sizeof(params));
346 	params.ifname = ifname;
347 	params.enabled = enabled;
348 	if (enabled) {
349 		params.wpa = hapd->conf->wpa;
350 		params.ieee802_1x = hapd->conf->ieee802_1x;
351 		params.wpa_group = hapd->conf->wpa_group;
352 		if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
353 		    (WPA_PROTO_WPA | WPA_PROTO_RSN))
354 			params.wpa_pairwise = hapd->conf->wpa_pairwise |
355 				hapd->conf->rsn_pairwise;
356 		else if (hapd->conf->wpa & WPA_PROTO_RSN)
357 			params.wpa_pairwise = hapd->conf->rsn_pairwise;
358 		else if (hapd->conf->wpa & WPA_PROTO_WPA)
359 			params.wpa_pairwise = hapd->conf->wpa_pairwise;
360 		params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
361 		params.rsn_preauth = hapd->conf->rsn_preauth;
362 		params.ieee80211w = hapd->conf->ieee80211w;
363 	}
364 	return hostapd_set_ieee8021x(hapd, &params);
365 }
366 
367 
hostapd_vlan_if_add(struct hostapd_data * hapd,const char * ifname)368 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
369 {
370 	char force_ifname[IFNAMSIZ];
371 	u8 if_addr[ETH_ALEN];
372 	return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
373 			      NULL, NULL, force_ifname, if_addr, NULL, 0);
374 }
375 
376 
hostapd_vlan_if_remove(struct hostapd_data * hapd,const char * ifname)377 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
378 {
379 	return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
380 }
381 
382 
hostapd_set_wds_sta(struct hostapd_data * hapd,char * ifname_wds,const u8 * addr,int aid,int val)383 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
384 			const u8 *addr, int aid, int val)
385 {
386 	const char *bridge = NULL;
387 
388 	if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
389 		return -1;
390 	if (hapd->conf->wds_bridge[0])
391 		bridge = hapd->conf->wds_bridge;
392 	else if (hapd->conf->bridge[0])
393 		bridge = hapd->conf->bridge;
394 	return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
395 					 bridge, ifname_wds);
396 }
397 
398 
hostapd_add_sta_node(struct hostapd_data * hapd,const u8 * addr,u16 auth_alg)399 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
400 			 u16 auth_alg)
401 {
402 	if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
403 		return -EOPNOTSUPP;
404 	return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
405 }
406 
407 
hostapd_sta_auth(struct hostapd_data * hapd,const u8 * addr,u16 seq,u16 status,const u8 * ie,size_t len)408 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
409 		     u16 seq, u16 status, const u8 *ie, size_t len)
410 {
411 	struct wpa_driver_sta_auth_params params;
412 #ifdef CONFIG_FILS
413 	struct sta_info *sta;
414 #endif /* CONFIG_FILS */
415 
416 	if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
417 		return 0;
418 
419 	os_memset(&params, 0, sizeof(params));
420 
421 #ifdef CONFIG_FILS
422 	sta = ap_get_sta(hapd, addr);
423 	if (!sta) {
424 		wpa_printf(MSG_DEBUG, "Station " MACSTR
425 			   " not found for sta_auth processing",
426 			   MAC2STR(addr));
427 		return 0;
428 	}
429 
430 	if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
431 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
432 	    sta->auth_alg == WLAN_AUTH_FILS_PK) {
433 		params.fils_auth = 1;
434 		wpa_auth_get_fils_aead_params(sta->wpa_sm, params.fils_anonce,
435 					      params.fils_snonce,
436 					      params.fils_kek,
437 					      &params.fils_kek_len);
438 	}
439 #endif /* CONFIG_FILS */
440 
441 	params.own_addr = hapd->own_addr;
442 	params.addr = addr;
443 	params.seq = seq;
444 	params.status = status;
445 	params.ie = ie;
446 	params.len = len;
447 
448 	return hapd->driver->sta_auth(hapd->drv_priv, &params);
449 }
450 
451 
hostapd_sta_assoc(struct hostapd_data * hapd,const u8 * addr,int reassoc,u16 status,const u8 * ie,size_t len)452 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
453 		      int reassoc, u16 status, const u8 *ie, size_t len)
454 {
455 	if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
456 		return 0;
457 	return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
458 				       reassoc, status, ie, len);
459 }
460 
461 
hostapd_sta_add(struct hostapd_data * hapd,const u8 * addr,u16 aid,u16 capability,const u8 * supp_rates,size_t supp_rates_len,u16 listen_interval,const struct ieee80211_ht_capabilities * ht_capab,const struct ieee80211_vht_capabilities * vht_capab,const struct ieee80211_he_capabilities * he_capab,size_t he_capab_len,const struct ieee80211_eht_capabilities * eht_capab,size_t eht_capab_len,const struct ieee80211_he_6ghz_band_cap * he_6ghz_capab,u32 flags,u8 qosinfo,u8 vht_opmode,int supp_p2p_ps,int set,const u8 * link_addr,bool mld_link_sta,u16 eml_cap)462 int hostapd_sta_add(struct hostapd_data *hapd,
463 		    const u8 *addr, u16 aid, u16 capability,
464 		    const u8 *supp_rates, size_t supp_rates_len,
465 		    u16 listen_interval,
466 		    const struct ieee80211_ht_capabilities *ht_capab,
467 		    const struct ieee80211_vht_capabilities *vht_capab,
468 		    const struct ieee80211_he_capabilities *he_capab,
469 		    size_t he_capab_len,
470 		    const struct ieee80211_eht_capabilities *eht_capab,
471 		    size_t eht_capab_len,
472 		    const struct ieee80211_he_6ghz_band_cap *he_6ghz_capab,
473 		    u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
474 		    int set, const u8 *link_addr, bool mld_link_sta,
475 		    u16 eml_cap)
476 {
477 	struct hostapd_sta_add_params params;
478 
479 	if (hapd->driver == NULL)
480 		return 0;
481 	if (hapd->driver->sta_add == NULL)
482 		return 0;
483 
484 	os_memset(&params, 0, sizeof(params));
485 	params.addr = addr;
486 	params.aid = aid;
487 	params.capability = capability;
488 	params.supp_rates = supp_rates;
489 	params.supp_rates_len = supp_rates_len;
490 	params.listen_interval = listen_interval;
491 	params.ht_capabilities = ht_capab;
492 	params.vht_capabilities = vht_capab;
493 	params.he_capab = he_capab;
494 	params.he_capab_len = he_capab_len;
495 	params.eht_capab = eht_capab;
496 	params.eht_capab_len = eht_capab_len;
497 	params.he_6ghz_capab = he_6ghz_capab;
498 	params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
499 	params.vht_opmode = vht_opmode;
500 	params.flags = hostapd_sta_flags_to_drv(flags);
501 	params.qosinfo = qosinfo;
502 	params.support_p2p_ps = supp_p2p_ps;
503 	params.set = set;
504 	params.mld_link_id = -1;
505 
506 #ifdef CONFIG_IEEE80211BE
507 	/*
508 	 * An AP MLD needs to always specify to what link the station needs
509 	 * to be added.
510 	 */
511 	if (hapd->conf->mld_ap) {
512 		params.mld_link_id = hapd->mld_link_id;
513 		params.mld_link_addr = link_addr;
514 		params.mld_link_sta = mld_link_sta;
515 		/* Copy EML capabilities of ML STA */
516 		if (link_addr)
517 			params.eml_cap = eml_cap;
518 	}
519 #endif /* CONFIG_IEEE80211BE */
520 
521 	return hapd->driver->sta_add(hapd->drv_priv, &params);
522 }
523 
524 
hostapd_add_tspec(struct hostapd_data * hapd,const u8 * addr,u8 * tspec_ie,size_t tspec_ielen)525 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
526 		      u8 *tspec_ie, size_t tspec_ielen)
527 {
528 	if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
529 		return 0;
530 	return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
531 				       tspec_ielen);
532 }
533 
534 
hostapd_set_privacy(struct hostapd_data * hapd,int enabled)535 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
536 {
537 	if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
538 		return 0;
539 	return hapd->driver->set_privacy(hapd->drv_priv, enabled);
540 }
541 
542 
hostapd_set_generic_elem(struct hostapd_data * hapd,const u8 * elem,size_t elem_len)543 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
544 			     size_t elem_len)
545 {
546 	if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
547 		return 0;
548 	return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
549 }
550 
551 
hostapd_get_ssid(struct hostapd_data * hapd,u8 * buf,size_t len)552 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
553 {
554 	if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
555 		return 0;
556 	return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
557 }
558 
559 
hostapd_set_ssid(struct hostapd_data * hapd,const u8 * buf,size_t len)560 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
561 {
562 	if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
563 		return 0;
564 	return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
565 }
566 
567 
hostapd_if_add(struct hostapd_data * hapd,enum wpa_driver_if_type type,const char * ifname,const u8 * addr,void * bss_ctx,void ** drv_priv,char * force_ifname,u8 * if_addr,const char * bridge,int use_existing)568 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
569 		   const char *ifname, const u8 *addr, void *bss_ctx,
570 		   void **drv_priv, char *force_ifname, u8 *if_addr,
571 		   const char *bridge, int use_existing)
572 {
573 	if (hapd->driver == NULL || hapd->driver->if_add == NULL)
574 		return -1;
575 	return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
576 				    bss_ctx, drv_priv, force_ifname, if_addr,
577 				    bridge, use_existing, 1);
578 }
579 
580 
581 #ifdef CONFIG_IEEE80211BE
hostapd_if_link_remove(struct hostapd_data * hapd,enum wpa_driver_if_type type,const char * ifname,u8 link_id)582 int hostapd_if_link_remove(struct hostapd_data *hapd,
583 			   enum wpa_driver_if_type type,
584 			   const char *ifname, u8 link_id)
585 {
586 	if (!hapd->driver || !hapd->drv_priv || !hapd->driver->link_remove)
587 		return -1;
588 
589 	return hapd->driver->link_remove(hapd->drv_priv, type, ifname,
590 					 hapd->mld_link_id);
591 }
592 #endif /* CONFIG_IEEE80211BE */
593 
594 
hostapd_if_remove(struct hostapd_data * hapd,enum wpa_driver_if_type type,const char * ifname)595 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
596 		      const char *ifname)
597 {
598 	if (hapd->driver == NULL || hapd->drv_priv == NULL ||
599 	    hapd->driver->if_remove == NULL)
600 		return -1;
601 
602 #ifdef CONFIG_IEEE80211BE
603 	if (hapd->conf->mld_ap)
604 		return hostapd_if_link_remove(hapd, type, ifname,
605 					      hapd->mld_link_id);
606 #endif /* CONFIG_IEEE80211BE */
607 
608 	return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
609 }
610 
611 
hostapd_set_ieee8021x(struct hostapd_data * hapd,struct wpa_bss_params * params)612 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
613 			  struct wpa_bss_params *params)
614 {
615 	if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
616 		return 0;
617 	return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
618 }
619 
620 
hostapd_get_seqnum(const char * ifname,struct hostapd_data * hapd,const u8 * addr,int idx,int link_id,u8 * seq)621 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
622 		       const u8 *addr, int idx, int link_id, u8 *seq)
623 {
624 	if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
625 		return 0;
626 	return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
627 					link_id, seq);
628 }
629 
630 
hostapd_flush(struct hostapd_data * hapd)631 int hostapd_flush(struct hostapd_data *hapd)
632 {
633 	int link_id = -1;
634 
635 	if (hapd->driver == NULL || hapd->driver->flush == NULL)
636 		return 0;
637 
638 #ifdef CONFIG_IEEE80211BE
639 	if (hapd->conf && hapd->conf->mld_ap)
640 		link_id = hapd->mld_link_id;
641 #endif /* CONFIG_IEEE80211BE */
642 
643 	return hapd->driver->flush(hapd->drv_priv, link_id);
644 }
645 
646 
hostapd_set_freq(struct hostapd_data * hapd,enum hostapd_hw_mode mode,int freq,int channel,int edmg,u8 edmg_channel,int ht_enabled,int vht_enabled,int he_enabled,bool eht_enabled,int sec_channel_offset,int oper_chwidth,int center_segment0,int center_segment1)647 int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
648 		     int freq, int channel, int edmg, u8 edmg_channel,
649 		     int ht_enabled, int vht_enabled,
650 		     int he_enabled, bool eht_enabled,
651 		     int sec_channel_offset, int oper_chwidth,
652 		     int center_segment0, int center_segment1)
653 {
654 	struct hostapd_freq_params data;
655 	struct hostapd_hw_modes *cmode = hapd->iface->current_mode;
656 
657 	if (hostapd_set_freq_params(&data, mode, freq, channel, edmg,
658 				    edmg_channel, ht_enabled,
659 				    vht_enabled, he_enabled, eht_enabled,
660 				    sec_channel_offset, oper_chwidth,
661 				    center_segment0, center_segment1,
662 				    cmode ? cmode->vht_capab : 0,
663 				    cmode ?
664 				    &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
665 				    cmode ?
666 				    &cmode->eht_capab[IEEE80211_MODE_AP] :
667 				    NULL, hostapd_get_punct_bitmap(hapd)))
668 		return -1;
669 
670 	if (hapd->driver == NULL)
671 		return 0;
672 	if (hapd->driver->set_freq == NULL)
673 		return 0;
674 
675 	data.link_id = -1;
676 
677 #ifdef CONFIG_IEEE80211BE
678 	if (hapd->conf->mld_ap) {
679 		data.link_id = hapd->mld_link_id;
680 		wpa_printf(MSG_DEBUG,
681 			   "hostapd_set_freq: link_id=%d", data.link_id);
682 	}
683 #endif /* CONFIG_IEEE80211BE */
684 
685 	return hapd->driver->set_freq(hapd->drv_priv, &data);
686 }
687 
hostapd_set_rts(struct hostapd_data * hapd,int rts)688 int hostapd_set_rts(struct hostapd_data *hapd, int rts)
689 {
690 	if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
691 		return 0;
692 	return hapd->driver->set_rts(hapd->drv_priv, rts);
693 }
694 
695 
hostapd_set_frag(struct hostapd_data * hapd,int frag)696 int hostapd_set_frag(struct hostapd_data *hapd, int frag)
697 {
698 	if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
699 		return 0;
700 	return hapd->driver->set_frag(hapd->drv_priv, frag);
701 }
702 
703 
hostapd_sta_set_flags(struct hostapd_data * hapd,u8 * addr,int total_flags,int flags_or,int flags_and)704 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
705 			  int total_flags, int flags_or, int flags_and)
706 {
707 	if (!hapd->driver || !hapd->drv_priv || !hapd->driver->sta_set_flags)
708 		return 0;
709 	return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
710 					   flags_or, flags_and);
711 }
712 
713 
hostapd_sta_set_airtime_weight(struct hostapd_data * hapd,const u8 * addr,unsigned int weight)714 int hostapd_sta_set_airtime_weight(struct hostapd_data *hapd, const u8 *addr,
715 				   unsigned int weight)
716 {
717 	if (!hapd->driver || !hapd->driver->sta_set_airtime_weight)
718 		return 0;
719 	return hapd->driver->sta_set_airtime_weight(hapd->drv_priv, addr,
720 						    weight);
721 }
722 
723 
hostapd_set_country(struct hostapd_data * hapd,const char * country)724 int hostapd_set_country(struct hostapd_data *hapd, const char *country)
725 {
726 	if (hapd->driver == NULL ||
727 	    hapd->driver->set_country == NULL)
728 		return 0;
729 	return hapd->driver->set_country(hapd->drv_priv, country);
730 }
731 
732 
hostapd_set_tx_queue_params(struct hostapd_data * hapd,int queue,int aifs,int cw_min,int cw_max,int burst_time)733 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
734 				int cw_min, int cw_max, int burst_time)
735 {
736 	int link_id = -1;
737 
738 	if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
739 		return 0;
740 
741 #ifdef CONFIG_IEEE80211BE
742 	if (hapd->conf->mld_ap)
743 		link_id = hapd->mld_link_id;
744 #endif /* CONFIG_IEEE80211BE */
745 
746 	return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
747 						 cw_min, cw_max, burst_time,
748 						 link_id);
749 }
750 
751 
752 struct hostapd_hw_modes *
hostapd_get_hw_feature_data(struct hostapd_data * hapd,u16 * num_modes,u16 * flags,u8 * dfs_domain)753 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
754 			    u16 *flags, u8 *dfs_domain)
755 {
756 	if (!hapd->driver || !hapd->driver->get_hw_feature_data ||
757 	    !hapd->drv_priv)
758 		return NULL;
759 	return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
760 						 flags, dfs_domain);
761 }
762 
763 
hostapd_driver_commit(struct hostapd_data * hapd)764 int hostapd_driver_commit(struct hostapd_data *hapd)
765 {
766 	if (hapd->driver == NULL || hapd->driver->commit == NULL)
767 		return 0;
768 	return hapd->driver->commit(hapd->drv_priv);
769 }
770 
771 
hostapd_drv_none(struct hostapd_data * hapd)772 int hostapd_drv_none(struct hostapd_data *hapd)
773 {
774 	return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
775 }
776 
777 
hostapd_drv_nl80211(struct hostapd_data * hapd)778 bool hostapd_drv_nl80211(struct hostapd_data *hapd)
779 {
780 	return hapd->driver && os_strcmp(hapd->driver->name, "nl80211") == 0;
781 }
782 
783 
hostapd_driver_scan(struct hostapd_data * hapd,struct wpa_driver_scan_params * params)784 int hostapd_driver_scan(struct hostapd_data *hapd,
785 			struct wpa_driver_scan_params *params)
786 {
787 	params->link_id = -1;
788 #ifdef CONFIG_IEEE80211BE
789 	if (hapd->conf->mld_ap)
790 		params->link_id = hapd->mld_link_id;
791 #endif /* CONFIG_IEEE80211BE */
792 
793 	if (hapd->driver && hapd->driver->scan2)
794 		return hapd->driver->scan2(hapd->drv_priv, params);
795 	return -1;
796 }
797 
798 
hostapd_driver_get_scan_results(struct hostapd_data * hapd)799 struct wpa_scan_results * hostapd_driver_get_scan_results(
800 	struct hostapd_data *hapd)
801 {
802 	if (hapd->driver && hapd->driver->get_scan_results)
803 		return hapd->driver->get_scan_results(hapd->drv_priv, NULL);
804 	if (hapd->driver && hapd->driver->get_scan_results2)
805 		return hapd->driver->get_scan_results2(hapd->drv_priv);
806 	return NULL;
807 }
808 
809 
hostapd_driver_set_noa(struct hostapd_data * hapd,u8 count,int start,int duration)810 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
811 			   int duration)
812 {
813 	if (hapd->driver && hapd->driver->set_noa)
814 		return hapd->driver->set_noa(hapd->drv_priv, count, start,
815 					     duration);
816 	return -1;
817 }
818 
819 
hostapd_drv_set_key(const char * ifname,struct hostapd_data * hapd,enum wpa_alg alg,const u8 * addr,int key_idx,int vlan_id,int set_tx,const u8 * seq,size_t seq_len,const u8 * key,size_t key_len,enum key_flag key_flag)820 int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
821 			enum wpa_alg alg, const u8 *addr,
822 			int key_idx, int vlan_id, int set_tx,
823 			const u8 *seq, size_t seq_len,
824 			const u8 *key, size_t key_len, enum key_flag key_flag)
825 {
826 	struct wpa_driver_set_key_params params;
827 
828 	if (hapd->driver == NULL || hapd->driver->set_key == NULL)
829 		return 0;
830 
831 	os_memset(&params, 0, sizeof(params));
832 	params.ifname = ifname;
833 	params.alg = alg;
834 	params.addr = addr;
835 	params.key_idx = key_idx;
836 	params.set_tx = set_tx;
837 	params.seq = seq;
838 	params.seq_len = seq_len;
839 	params.key = key;
840 	params.key_len = key_len;
841 	params.vlan_id = vlan_id;
842 	params.key_flag = key_flag;
843 	params.link_id = -1;
844 
845 #ifdef CONFIG_IEEE80211BE
846 	if (hapd->conf->mld_ap && !(key_flag & KEY_FLAG_PAIRWISE))
847 		params.link_id = hapd->mld_link_id;
848 #endif /* CONFIG_IEEE80211BE */
849 
850 	return hapd->driver->set_key(hapd->drv_priv, &params);
851 }
852 
853 
hostapd_drv_send_mlme(struct hostapd_data * hapd,const void * msg,size_t len,int noack,const u16 * csa_offs,size_t csa_offs_len,int no_encrypt)854 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
855 			  const void *msg, size_t len, int noack,
856 			  const u16 *csa_offs, size_t csa_offs_len,
857 			  int no_encrypt)
858 {
859 	int link_id = -1;
860 
861 #ifdef CONFIG_IEEE80211BE
862 	if (hapd->conf->mld_ap)
863 		link_id = hapd->mld_link_id;
864 #endif /* CONFIG_IEEE80211BE */
865 
866 	if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
867 		return 0;
868 	return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
869 				       csa_offs, csa_offs_len, no_encrypt, 0,
870 				       link_id);
871 }
872 
873 
hostapd_drv_sta_deauth(struct hostapd_data * hapd,const u8 * addr,int reason)874 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
875 			   const u8 *addr, int reason)
876 {
877 	int link_id = -1;
878 	const u8 *own_addr = hapd->own_addr;
879 
880 #ifdef CONFIG_IEEE80211BE
881 	if (hapd->conf->mld_ap) {
882 		struct sta_info *sta = ap_get_sta(hapd, addr);
883 
884 		link_id = hapd->mld_link_id;
885 		if (ap_sta_is_mld(hapd, sta))
886 			own_addr = hapd->mld->mld_addr;
887 	}
888 #endif /* CONFIG_IEEE80211BE */
889 
890 	if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
891 		return 0;
892 	return hapd->driver->sta_deauth(hapd->drv_priv, own_addr, addr,
893 					reason, link_id);
894 }
895 
896 
hostapd_drv_sta_disassoc(struct hostapd_data * hapd,const u8 * addr,int reason)897 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
898 			     const u8 *addr, int reason)
899 {
900 	const u8 *own_addr = hapd->own_addr;
901 
902 #ifdef CONFIG_IEEE80211BE
903 	if (hapd->conf->mld_ap) {
904 		struct sta_info *sta = ap_get_sta(hapd, addr);
905 
906 		if (ap_sta_is_mld(hapd, sta))
907 			own_addr = hapd->mld->mld_addr;
908 	}
909 #endif /* CONFIG_IEEE80211BE */
910 
911 	if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
912 		return 0;
913 	return hapd->driver->sta_disassoc(hapd->drv_priv, own_addr, addr,
914 					  reason);
915 }
916 
917 
hostapd_drv_wnm_oper(struct hostapd_data * hapd,enum wnm_oper oper,const u8 * peer,u8 * buf,u16 * buf_len)918 int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
919 			 const u8 *peer, u8 *buf, u16 *buf_len)
920 {
921 	if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
922 		return -1;
923 	return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
924 				      buf_len);
925 }
926 
927 
928 #ifdef CONFIG_IEEE80211BE
hostapd_is_action_frame_link_agnostic(u8 category,u8 sub_category)929 static bool hostapd_is_action_frame_link_agnostic(u8 category, u8 sub_category)
930 {
931 	/* As per IEEE P802.11be/D7.0, 35.3.14 (MLD individually addressed
932 	 * Management frame delivery), between an AP MLD and a non-AP MLD, the
933 	 * following individually addressed MMPDUs shall be intended for an MLD.
934 	 */
935 	switch (category) {
936 	case WLAN_ACTION_BLOCK_ACK:
937 	case WLAN_ACTION_FT:
938 	case WLAN_ACTION_SA_QUERY:
939 	case WLAN_ACTION_WNM:
940 		switch (sub_category) {
941 		case WNM_BSS_TRANS_MGMT_REQ:
942 		case WNM_BSS_TRANS_MGMT_RESP:
943 		case WNM_SLEEP_MODE_REQ:
944 		case WNM_SLEEP_MODE_RESP:
945 			return true;
946 		default:
947 			return false;
948 		}
949 	case WLAN_ACTION_ROBUST_AV_STREAMING:
950 		switch (sub_category) {
951 		case ROBUST_AV_SCS_REQ:
952 		case ROBUST_AV_SCS_RESP:
953 		case ROBUST_AV_MSCS_REQ:
954 		case ROBUST_AV_MSCS_RESP:
955 			return true;
956 		default:
957 			return false;
958 		}
959 	/* TODO: Handle EHT/EPCS related action frames once the support is
960 	 * added. */
961 	default:
962 		return false;
963 	}
964 }
965 #endif /* CONFIG_IEEE80211BE */
966 
967 
hapd_drv_send_action(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * data,size_t len,bool addr3_ap,const u8 * forced_a3)968 static int hapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
969 				unsigned int wait, const u8 *dst,
970 				const u8 *data, size_t len, bool addr3_ap,
971 				const u8 *forced_a3)
972 {
973 	const u8 *own_addr = hapd->own_addr;
974 	const u8 *bssid;
975 	const u8 wildcard_bssid[ETH_ALEN] = {
976 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
977 	};
978 	struct sta_info *sta;
979 	int link_id = -1;
980 
981 	if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
982 		return 0;
983 	bssid = hapd->own_addr;
984 	if (forced_a3) {
985 		bssid = forced_a3;
986 	} else if (!addr3_ap && !is_multicast_ether_addr(dst) &&
987 		   len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
988 		/*
989 		 * Public Action frames to a STA that is not a member of the BSS
990 		 * shall use wildcard BSSID value.
991 		 */
992 		sta = ap_get_sta(hapd, dst);
993 		if (!sta || !(sta->flags & WLAN_STA_ASSOC))
994 			bssid = wildcard_bssid;
995 	} else if (!addr3_ap && is_broadcast_ether_addr(dst) &&
996 		   len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
997 		/*
998 		 * The only current use case of Public Action frames with
999 		 * broadcast destination address is DPP PKEX. That case is
1000 		 * directing all devices and not just the STAs within the BSS,
1001 		 * so have to use the wildcard BSSID value.
1002 		 */
1003 		bssid = wildcard_bssid;
1004 #ifdef CONFIG_IEEE80211BE
1005 	} else if (hapd->conf->mld_ap) {
1006 		sta = ap_get_sta(hapd, dst);
1007 
1008 		if (ap_sta_is_mld(hapd, sta)) {
1009 			own_addr = hapd->mld->mld_addr;
1010 			bssid = own_addr;
1011 		}
1012 
1013 		if (!hostapd_is_action_frame_link_agnostic(data[0], data[1]))
1014 			link_id = hapd->mld_link_id;
1015 #endif /* CONFIG_IEEE80211BE */
1016 	}
1017 
1018 	return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
1019 					 own_addr, bssid, data, len, 0,
1020 					 link_id);
1021 }
1022 
1023 
hostapd_drv_send_action(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * data,size_t len)1024 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
1025 			    unsigned int wait, const u8 *dst, const u8 *data,
1026 			    size_t len)
1027 {
1028 	return hapd_drv_send_action(hapd, freq, wait, dst, data, len, false,
1029 				    NULL);
1030 }
1031 
1032 
hostapd_drv_send_action_addr3_ap(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * data,size_t len)1033 int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
1034 				     unsigned int freq,
1035 				     unsigned int wait, const u8 *dst,
1036 				     const u8 *data, size_t len)
1037 {
1038 	return hapd_drv_send_action(hapd, freq, wait, dst, data, len, true,
1039 				    NULL);
1040 }
1041 
1042 
hostapd_drv_send_action_forced_addr3(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * a3,const u8 * data,size_t len)1043 int hostapd_drv_send_action_forced_addr3(struct hostapd_data *hapd,
1044 					 unsigned int freq,
1045 					 unsigned int wait, const u8 *dst,
1046 					 const u8 *a3,
1047 					 const u8 *data, size_t len)
1048 {
1049 	return hapd_drv_send_action(hapd, freq, wait, dst, data, len, false,
1050 				    a3);
1051 }
1052 
1053 
hostapd_start_dfs_cac(struct hostapd_iface * iface,enum hostapd_hw_mode mode,int freq,int channel,int ht_enabled,int vht_enabled,int he_enabled,bool eht_enabled,int sec_channel_offset,int oper_chwidth,int center_segment0,int center_segment1,bool radar_background)1054 int hostapd_start_dfs_cac(struct hostapd_iface *iface,
1055 			  enum hostapd_hw_mode mode, int freq,
1056 			  int channel, int ht_enabled, int vht_enabled,
1057 			  int he_enabled, bool eht_enabled,
1058 			  int sec_channel_offset, int oper_chwidth,
1059 			  int center_segment0, int center_segment1,
1060 			  bool radar_background)
1061 {
1062 	struct hostapd_data *hapd = iface->bss[0];
1063 	struct hostapd_freq_params data;
1064 	int res;
1065 	struct hostapd_hw_modes *cmode = iface->current_mode;
1066 
1067 	if (!hapd->driver || !hapd->driver->start_dfs_cac || !cmode)
1068 		return 0;
1069 
1070 	if (!iface->conf->ieee80211h) {
1071 		wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
1072 			   "is not enabled");
1073 		return -1;
1074 	}
1075 
1076 	if (hostapd_set_freq_params(&data, mode, freq, channel, 0, 0,
1077 				    ht_enabled,
1078 				    vht_enabled, he_enabled, eht_enabled,
1079 				    sec_channel_offset,
1080 				    oper_chwidth, center_segment0,
1081 				    center_segment1,
1082 				    cmode->vht_capab,
1083 				    &cmode->he_capab[IEEE80211_MODE_AP],
1084 				    &cmode->eht_capab[IEEE80211_MODE_AP],
1085 				    hostapd_get_punct_bitmap(hapd))) {
1086 		wpa_printf(MSG_ERROR, "Can't set freq params");
1087 		return -1;
1088 	}
1089 	data.radar_background = radar_background;
1090 
1091 	data.link_id = -1;
1092 #ifdef CONFIG_IEEE80211BE
1093 	if (hapd->conf->mld_ap)
1094 		data.link_id = hapd->mld_link_id;
1095 #endif /* CONFIG_IEEE80211BE */
1096 
1097 	res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
1098 	if (!res) {
1099 		if (radar_background)
1100 			iface->radar_background.cac_started = 1;
1101 		else
1102 			iface->cac_started = 1;
1103 		os_get_reltime(&iface->dfs_cac_start);
1104 	}
1105 
1106 	return res;
1107 }
1108 
1109 
hostapd_drv_set_qos_map(struct hostapd_data * hapd,const u8 * qos_map_set,u8 qos_map_set_len)1110 int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
1111 			    const u8 *qos_map_set, u8 qos_map_set_len)
1112 {
1113 	if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv ||
1114 	    !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_QOS_MAPPING))
1115 		return 0;
1116 	return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
1117 					 qos_map_set_len);
1118 }
1119 
1120 
hostapd_get_hw_mode_any_channels(struct hostapd_data * hapd,struct hostapd_hw_modes * mode,int acs_ch_list_all,bool allow_disabled,int ** freq_list)1121 void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
1122 				      struct hostapd_hw_modes *mode,
1123 				      int acs_ch_list_all, bool allow_disabled,
1124 				      int **freq_list)
1125 {
1126 	int i;
1127 	bool is_no_ir = false;
1128 
1129 	for (i = 0; i < mode->num_channels; i++) {
1130 		struct hostapd_channel_data *chan = &mode->channels[i];
1131 
1132 		if (!acs_ch_list_all &&
1133 		    (hapd->iface->conf->acs_freq_list.num &&
1134 		     !freq_range_list_includes(
1135 			     &hapd->iface->conf->acs_freq_list,
1136 			     chan->freq)))
1137 			continue;
1138 		if (!acs_ch_list_all &&
1139 		    (!hapd->iface->conf->acs_freq_list_present &&
1140 		     hapd->iface->conf->acs_ch_list.num &&
1141 		     !freq_range_list_includes(
1142 			     &hapd->iface->conf->acs_ch_list,
1143 			     chan->chan)))
1144 			continue;
1145 		if (is_6ghz_freq(chan->freq) &&
1146 		    ((hapd->iface->conf->acs_exclude_6ghz_non_psc &&
1147 		      !is_6ghz_psc_frequency(chan->freq)) ||
1148 		     (!hapd->iface->conf->ieee80211ax &&
1149 		      !hapd->iface->conf->ieee80211be)))
1150 			continue;
1151 		if ((!(chan->flag & HOSTAPD_CHAN_DISABLED) || allow_disabled) &&
1152 		    !(hapd->iface->conf->acs_exclude_dfs &&
1153 		      (chan->flag & HOSTAPD_CHAN_RADAR)) &&
1154 		    !(chan->max_tx_power < hapd->iface->conf->min_tx_power))
1155 			int_array_add_unique(freq_list, chan->freq);
1156 		else if ((chan->flag & HOSTAPD_CHAN_NO_IR) &&
1157 			 is_6ghz_freq(chan->freq))
1158 			is_no_ir = true;
1159 	}
1160 
1161 	hapd->iface->is_no_ir = is_no_ir;
1162 }
1163 
1164 
hostapd_get_ext_capa(struct hostapd_iface * iface)1165 void hostapd_get_ext_capa(struct hostapd_iface *iface)
1166 {
1167 	struct hostapd_data *hapd = iface->bss[0];
1168 
1169 	if (!hapd->driver || !hapd->driver->get_ext_capab)
1170 		return;
1171 
1172 	hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
1173 				    &iface->extended_capa,
1174 				    &iface->extended_capa_mask,
1175 				    &iface->extended_capa_len);
1176 }
1177 
1178 
hostapd_get_mld_capa(struct hostapd_iface * iface)1179 void hostapd_get_mld_capa(struct hostapd_iface *iface)
1180 {
1181 	struct hostapd_data *hapd = iface->bss[0];
1182 
1183 	if (!hapd->driver || !hapd->driver->get_mld_capab)
1184 		return;
1185 
1186 	hapd->driver->get_mld_capab(hapd->drv_priv, WPA_IF_AP_BSS,
1187 				    &iface->mld_eml_capa,
1188 				    &iface->mld_mld_capa);
1189 }
1190 
1191 
1192 /**
1193  * hostapd_drv_do_acs - Start automatic channel selection
1194  * @hapd: BSS data for the device initiating ACS
1195  * Returns: 0 on success, -1 on failure, 1 on failure due to NO_IR (AFC)
1196  */
hostapd_drv_do_acs(struct hostapd_data * hapd)1197 int hostapd_drv_do_acs(struct hostapd_data *hapd)
1198 {
1199 	struct drv_acs_params params;
1200 	int ret, i, acs_ch_list_all = 0;
1201 	struct hostapd_hw_modes *mode;
1202 	int *freq_list = NULL;
1203 	enum hostapd_hw_mode selected_mode;
1204 
1205 	if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
1206 		return 0;
1207 
1208 	os_memset(&params, 0, sizeof(params));
1209 	params.hw_mode = hapd->iface->conf->hw_mode;
1210 	params.link_id = -1;
1211 #ifdef CONFIG_IEEE80211BE
1212 	if (hapd->conf->mld_ap && hapd->iconf->ieee80211be &&
1213 	    !hapd->conf->disable_11be)
1214 		params.link_id = hapd->mld_link_id;
1215 #endif /* CONFIG_IEEE80211BE */
1216 
1217 	/*
1218 	 * If no chanlist config parameter is provided, include all enabled
1219 	 * channels of the selected hw_mode.
1220 	 */
1221 	if (hapd->iface->conf->acs_freq_list_present)
1222 		acs_ch_list_all = !hapd->iface->conf->acs_freq_list.num;
1223 	else
1224 		acs_ch_list_all = !hapd->iface->conf->acs_ch_list.num;
1225 
1226 	if (hapd->iface->current_mode)
1227 		selected_mode = hapd->iface->current_mode->mode;
1228 	else
1229 		selected_mode = HOSTAPD_MODE_IEEE80211ANY;
1230 
1231 	for (i = 0; i < hapd->iface->num_hw_features; i++) {
1232 		mode = &hapd->iface->hw_features[i];
1233 		if (selected_mode != HOSTAPD_MODE_IEEE80211ANY &&
1234 		    selected_mode != mode->mode)
1235 			continue;
1236 		hostapd_get_hw_mode_any_channels(hapd, mode, acs_ch_list_all,
1237 						 false, &freq_list);
1238 	}
1239 
1240 	if (!freq_list && hapd->iface->is_no_ir) {
1241 		wpa_printf(MSG_ERROR,
1242 			   "NO_IR: Interface freq_list is empty. Failing do_acs.");
1243 		return 1;
1244 	}
1245 
1246 	params.freq_list = freq_list;
1247 	params.edmg_enabled = hapd->iface->conf->enable_edmg;
1248 
1249 	params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
1250 	params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
1251 				 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
1252 	params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
1253 	params.eht_enabled = !!(hapd->iface->conf->ieee80211be);
1254 	params.ch_width = 20;
1255 	if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
1256 		params.ch_width = 40;
1257 
1258 	/* Note: VHT20 is defined by combination of ht_capab & oper_chwidth
1259 	 */
1260 	if ((hapd->iface->conf->ieee80211be ||
1261 	     hapd->iface->conf->ieee80211ax ||
1262 	     hapd->iface->conf->ieee80211ac) &&
1263 	    params.ht40_enabled) {
1264 		enum oper_chan_width oper_chwidth;
1265 
1266 		oper_chwidth = hostapd_get_oper_chwidth(hapd->iface->conf);
1267 		if (oper_chwidth == CONF_OPER_CHWIDTH_80MHZ)
1268 			params.ch_width = 80;
1269 		else if (oper_chwidth == CONF_OPER_CHWIDTH_160MHZ ||
1270 			 oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
1271 			params.ch_width = 160;
1272 		else if (oper_chwidth == CONF_OPER_CHWIDTH_320MHZ)
1273 			params.ch_width = 320;
1274 	}
1275 
1276 	if (hapd->iface->conf->op_class)
1277 		params.ch_width = op_class_to_bandwidth(
1278 			hapd->iface->conf->op_class);
1279 	ret = hapd->driver->do_acs(hapd->drv_priv, &params);
1280 	os_free(freq_list);
1281 
1282 	return ret;
1283 }
1284 
1285 
hostapd_drv_update_dh_ie(struct hostapd_data * hapd,const u8 * peer,u16 reason_code,const u8 * ie,size_t ielen)1286 int hostapd_drv_update_dh_ie(struct hostapd_data *hapd, const u8 *peer,
1287 			     u16 reason_code, const u8 *ie, size_t ielen)
1288 {
1289 	if (!hapd->driver || !hapd->driver->update_dh_ie || !hapd->drv_priv)
1290 		return 0;
1291 	return hapd->driver->update_dh_ie(hapd->drv_priv, peer, reason_code,
1292 					  ie, ielen);
1293 }
1294 
1295 
hostapd_drv_dpp_listen(struct hostapd_data * hapd,bool enable)1296 int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable)
1297 {
1298 	if (!hapd->driver || !hapd->driver->dpp_listen || !hapd->drv_priv)
1299 		return 0;
1300 	return hapd->driver->dpp_listen(hapd->drv_priv, enable);
1301 }
1302 
1303 
1304 #ifdef CONFIG_PASN
hostapd_drv_set_secure_ranging_ctx(struct hostapd_data * hapd,const u8 * own_addr,const u8 * peer_addr,u32 cipher,u8 tk_len,const u8 * tk,u8 ltf_keyseed_len,const u8 * ltf_keyseed,u32 action)1305 int hostapd_drv_set_secure_ranging_ctx(struct hostapd_data *hapd,
1306 				       const u8 *own_addr, const u8 *peer_addr,
1307 				       u32 cipher, u8 tk_len, const u8 *tk,
1308 				       u8 ltf_keyseed_len,
1309 				       const u8 *ltf_keyseed, u32 action)
1310 {
1311 	struct secure_ranging_params params;
1312 
1313 	if (!hapd->driver || !hapd->driver->set_secure_ranging_ctx)
1314 		return 0;
1315 
1316 	os_memset(&params, 0, sizeof(params));
1317 	params.own_addr = own_addr;
1318 	params.peer_addr = peer_addr;
1319 	params.cipher = cipher;
1320 	params.tk_len = tk_len;
1321 	params.tk = tk;
1322 	params.ltf_keyseed_len = ltf_keyseed_len;
1323 	params.ltf_keyseed = ltf_keyseed;
1324 	params.action = action;
1325 
1326 	return hapd->driver->set_secure_ranging_ctx(hapd->drv_priv, &params);
1327 }
1328 #endif /* CONFIG_PASN */
1329 
1330 
1331 struct hostapd_multi_hw_info *
hostapd_get_multi_hw_info(struct hostapd_data * hapd,unsigned int * num_multi_hws)1332 hostapd_get_multi_hw_info(struct hostapd_data *hapd,
1333 			  unsigned int *num_multi_hws)
1334 {
1335 	if (!hapd->driver || !hapd->driver->get_multi_hw_info)
1336 		return NULL;
1337 
1338 	return hapd->driver->get_multi_hw_info(hapd->drv_priv, num_multi_hws);
1339 }
1340 
1341 
hostapd_drv_add_pmkid(struct hostapd_data * hapd,struct wpa_pmkid_params * params)1342 int hostapd_drv_add_pmkid(struct hostapd_data *hapd,
1343 			  struct wpa_pmkid_params *params)
1344 {
1345 	if (!hapd->driver || !hapd->driver->add_pmkid || !hapd->drv_priv)
1346 		return 0;
1347 	return hapd->driver->add_pmkid(hapd->drv_priv, params);
1348 }
1349 
1350 
hostapd_add_pmkid(struct hostapd_data * hapd,const u8 * bssid,const u8 * pmk,size_t pmk_len,const u8 * pmkid,int akmp)1351 int hostapd_add_pmkid(struct hostapd_data *hapd, const u8 *bssid, const u8 *pmk,
1352 		      size_t pmk_len, const u8 *pmkid, int akmp)
1353 {
1354 	struct wpa_pmkid_params params;
1355 
1356 	os_memset(&params, 0, sizeof(params));
1357 	params.bssid = bssid;
1358 	params.pmkid = pmkid;
1359 	params.pmk = pmk;
1360 	params.pmk_len = pmk_len;
1361 
1362 	return hostapd_drv_add_pmkid(hapd, &params);
1363 }
1364