• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	return res;
43 }
44 
45 
add_buf(struct wpabuf ** dst,const struct wpabuf * src)46 static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
47 {
48 	if (!src)
49 		return 0;
50 	if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
51 		return -1;
52 	wpabuf_put_buf(*dst, src);
53 	return 0;
54 }
55 
56 
add_buf_data(struct wpabuf ** dst,const u8 * data,size_t len)57 static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
58 {
59 	if (!data || !len)
60 		return 0;
61 	if (wpabuf_resize(dst, len) != 0)
62 		return -1;
63 	wpabuf_put_data(*dst, data, len);
64 	return 0;
65 }
66 
67 
hostapd_build_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf ** beacon_ret,struct wpabuf ** proberesp_ret,struct wpabuf ** assocresp_ret)68 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
69 			       struct wpabuf **beacon_ret,
70 			       struct wpabuf **proberesp_ret,
71 			       struct wpabuf **assocresp_ret)
72 {
73 	struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
74 	u8 buf[200], *pos;
75 
76 	*beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
77 
78 #ifdef NEED_AP_MLME
79 	pos = buf;
80 	pos = hostapd_eid_rm_enabled_capab(hapd, pos, sizeof(buf));
81 	if (add_buf_data(&assocresp, buf, pos - buf) < 0 ||
82 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
83 		goto fail;
84 #endif /* NEED_AP_MLME */
85 
86 	pos = buf;
87 	pos = hostapd_eid_time_adv(hapd, pos);
88 	if (add_buf_data(&beacon, buf, pos - buf) < 0)
89 		goto fail;
90 	pos = hostapd_eid_time_zone(hapd, pos);
91 	if (add_buf_data(&proberesp, buf, pos - buf) < 0)
92 		goto fail;
93 
94 	pos = buf;
95 	pos = hostapd_eid_ext_capab(hapd, pos, false);
96 	if (add_buf_data(&assocresp, buf, pos - buf) < 0)
97 		goto fail;
98 	pos = hostapd_eid_interworking(hapd, pos);
99 	pos = hostapd_eid_adv_proto(hapd, pos);
100 	pos = hostapd_eid_roaming_consortium(hapd, pos);
101 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
102 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
103 		goto fail;
104 
105 #ifdef CONFIG_FST
106 	if (add_buf(&beacon, hapd->iface->fst_ies) < 0 ||
107 	    add_buf(&proberesp, hapd->iface->fst_ies) < 0 ||
108 	    add_buf(&assocresp, hapd->iface->fst_ies) < 0)
109 		goto fail;
110 #endif /* CONFIG_FST */
111 
112 #ifdef CONFIG_FILS
113 	pos = hostapd_eid_fils_indic(hapd, buf, 0);
114 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
115 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
116 		goto fail;
117 #endif /* CONFIG_FILS */
118 
119 	pos = hostapd_eid_rsnxe(hapd, buf, sizeof(buf));
120 	if (add_buf_data(&assocresp, buf, pos - buf) < 0)
121 		goto fail;
122 
123 	if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
124 	    add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
125 		goto fail;
126 
127 #ifdef CONFIG_P2P
128 	if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
129 	    add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
130 		goto fail;
131 #endif /* CONFIG_P2P */
132 
133 #ifdef CONFIG_P2P_MANAGER
134 	if (hapd->conf->p2p & P2P_MANAGE) {
135 		if (wpabuf_resize(&beacon, 100) == 0) {
136 			u8 *start, *p;
137 			start = wpabuf_put(beacon, 0);
138 			p = hostapd_eid_p2p_manage(hapd, start);
139 			wpabuf_put(beacon, p - start);
140 		}
141 
142 		if (wpabuf_resize(&proberesp, 100) == 0) {
143 			u8 *start, *p;
144 			start = wpabuf_put(proberesp, 0);
145 			p = hostapd_eid_p2p_manage(hapd, start);
146 			wpabuf_put(proberesp, p - start);
147 		}
148 	}
149 #endif /* CONFIG_P2P_MANAGER */
150 
151 #ifdef CONFIG_WPS
152 	if (hapd->conf->wps_state) {
153 		struct wpabuf *a = wps_build_assoc_resp_ie();
154 		add_buf(&assocresp, a);
155 		wpabuf_free(a);
156 	}
157 #endif /* CONFIG_WPS */
158 
159 #ifdef CONFIG_P2P_MANAGER
160 	if (hapd->conf->p2p & P2P_MANAGE) {
161 		if (wpabuf_resize(&assocresp, 100) == 0) {
162 			u8 *start, *p;
163 			start = wpabuf_put(assocresp, 0);
164 			p = hostapd_eid_p2p_manage(hapd, start);
165 			wpabuf_put(assocresp, p - start);
166 		}
167 	}
168 #endif /* CONFIG_P2P_MANAGER */
169 
170 #ifdef CONFIG_WIFI_DISPLAY
171 	if (hapd->p2p_group) {
172 		struct wpabuf *a;
173 		a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
174 		add_buf(&assocresp, a);
175 		wpabuf_free(a);
176 	}
177 #endif /* CONFIG_WIFI_DISPLAY */
178 
179 #ifdef CONFIG_HS20
180 	pos = hostapd_eid_hs20_indication(hapd, buf);
181 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
182 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
183 		goto fail;
184 
185 	pos = hostapd_eid_osen(hapd, buf);
186 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
187 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
188 		goto fail;
189 #endif /* CONFIG_HS20 */
190 
191 #ifdef CONFIG_MBO
192 	if (hapd->conf->mbo_enabled ||
193 	    OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
194 		pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
195 		if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
196 		    add_buf_data(&proberesp, buf, pos - buf) < 0 ||
197 		    add_buf_data(&assocresp, buf, pos - buf) < 0)
198 			goto fail;
199 	}
200 #endif /* CONFIG_MBO */
201 
202 #ifdef CONFIG_OWE
203 	pos = hostapd_eid_owe_trans(hapd, buf, sizeof(buf));
204 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
205 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
206 		goto fail;
207 #endif /* CONFIG_OWE */
208 
209 	add_buf(&beacon, hapd->conf->vendor_elements);
210 	add_buf(&proberesp, hapd->conf->vendor_elements);
211 	add_buf(&assocresp, hapd->conf->assocresp_elements);
212 
213 	*beacon_ret = beacon;
214 	*proberesp_ret = proberesp;
215 	*assocresp_ret = assocresp;
216 
217 	return 0;
218 
219 fail:
220 	wpabuf_free(beacon);
221 	wpabuf_free(proberesp);
222 	wpabuf_free(assocresp);
223 	return -1;
224 }
225 
226 
hostapd_free_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf * beacon,struct wpabuf * proberesp,struct wpabuf * assocresp)227 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
228 			       struct wpabuf *beacon,
229 			       struct wpabuf *proberesp,
230 			       struct wpabuf *assocresp)
231 {
232 	wpabuf_free(beacon);
233 	wpabuf_free(proberesp);
234 	wpabuf_free(assocresp);
235 }
236 
237 
hostapd_reset_ap_wps_ie(struct hostapd_data * hapd)238 int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
239 {
240 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
241 		return 0;
242 
243 	return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
244 }
245 
246 
hostapd_set_ap_wps_ie(struct hostapd_data * hapd)247 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
248 {
249 	struct wpabuf *beacon, *proberesp, *assocresp;
250 	int ret;
251 
252 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
253 		return 0;
254 
255 	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
256 	    0)
257 		return -1;
258 
259 	ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
260 					  assocresp);
261 
262 	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
263 
264 	return ret;
265 }
266 
267 
hostapd_set_authorized(struct hostapd_data * hapd,struct sta_info * sta,int authorized)268 int hostapd_set_authorized(struct hostapd_data *hapd,
269 			   struct sta_info *sta, int authorized)
270 {
271 	if (authorized) {
272 		return hostapd_sta_set_flags(hapd, sta->addr,
273 					     hostapd_sta_flags_to_drv(
274 						     sta->flags),
275 					     WPA_STA_AUTHORIZED, ~0);
276 	}
277 
278 	return hostapd_sta_set_flags(hapd, sta->addr,
279 				     hostapd_sta_flags_to_drv(sta->flags),
280 				     0, ~WPA_STA_AUTHORIZED);
281 }
282 
283 
hostapd_set_sta_flags(struct hostapd_data * hapd,struct sta_info * sta)284 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
285 {
286 	int set_flags, total_flags, flags_and, flags_or;
287 	total_flags = hostapd_sta_flags_to_drv(sta->flags);
288 	set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
289 	if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
290 	     sta->auth_alg == WLAN_AUTH_FT) &&
291 	    sta->flags & WLAN_STA_AUTHORIZED)
292 		set_flags |= WPA_STA_AUTHORIZED;
293 	flags_or = total_flags & set_flags;
294 	flags_and = total_flags | ~set_flags;
295 	return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
296 				     flags_or, flags_and);
297 }
298 
299 
hostapd_set_drv_ieee8021x(struct hostapd_data * hapd,const char * ifname,int enabled)300 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
301 			      int enabled)
302 {
303 	struct wpa_bss_params params;
304 	os_memset(&params, 0, sizeof(params));
305 	params.ifname = ifname;
306 	params.enabled = enabled;
307 	if (enabled) {
308 		params.wpa = hapd->conf->wpa;
309 		params.ieee802_1x = hapd->conf->ieee802_1x;
310 		params.wpa_group = hapd->conf->wpa_group;
311 		if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
312 		    (WPA_PROTO_WPA | WPA_PROTO_RSN))
313 			params.wpa_pairwise = hapd->conf->wpa_pairwise |
314 				hapd->conf->rsn_pairwise;
315 		else if (hapd->conf->wpa & WPA_PROTO_RSN)
316 			params.wpa_pairwise = hapd->conf->rsn_pairwise;
317 		else if (hapd->conf->wpa & WPA_PROTO_WPA)
318 			params.wpa_pairwise = hapd->conf->wpa_pairwise;
319 		params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
320 		params.rsn_preauth = hapd->conf->rsn_preauth;
321 		params.ieee80211w = hapd->conf->ieee80211w;
322 	}
323 	return hostapd_set_ieee8021x(hapd, &params);
324 }
325 
326 
hostapd_vlan_if_add(struct hostapd_data * hapd,const char * ifname)327 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
328 {
329 	char force_ifname[IFNAMSIZ];
330 	u8 if_addr[ETH_ALEN];
331 	return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
332 			      NULL, NULL, force_ifname, if_addr, NULL, 0);
333 }
334 
335 
hostapd_vlan_if_remove(struct hostapd_data * hapd,const char * ifname)336 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
337 {
338 	return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
339 }
340 
341 
hostapd_set_wds_sta(struct hostapd_data * hapd,char * ifname_wds,const u8 * addr,int aid,int val)342 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
343 			const u8 *addr, int aid, int val)
344 {
345 	const char *bridge = NULL;
346 
347 	if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
348 		return -1;
349 	if (hapd->conf->wds_bridge[0])
350 		bridge = hapd->conf->wds_bridge;
351 	else if (hapd->conf->bridge[0])
352 		bridge = hapd->conf->bridge;
353 	return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
354 					 bridge, ifname_wds);
355 }
356 
357 
hostapd_add_sta_node(struct hostapd_data * hapd,const u8 * addr,u16 auth_alg)358 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
359 			 u16 auth_alg)
360 {
361 	if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
362 		return -EOPNOTSUPP;
363 	return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
364 }
365 
366 
hostapd_sta_auth(struct hostapd_data * hapd,const u8 * addr,u16 seq,u16 status,const u8 * ie,size_t len)367 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
368 		     u16 seq, u16 status, const u8 *ie, size_t len)
369 {
370 	struct wpa_driver_sta_auth_params params;
371 #ifdef CONFIG_FILS
372 	struct sta_info *sta;
373 #endif /* CONFIG_FILS */
374 
375 	if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
376 		return 0;
377 
378 	os_memset(&params, 0, sizeof(params));
379 
380 #ifdef CONFIG_FILS
381 	sta = ap_get_sta(hapd, addr);
382 	if (!sta) {
383 		wpa_printf(MSG_DEBUG, "Station " MACSTR
384 			   " not found for sta_auth processing",
385 			   MAC2STR(addr));
386 		return 0;
387 	}
388 
389 	if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
390 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
391 	    sta->auth_alg == WLAN_AUTH_FILS_PK) {
392 		params.fils_auth = 1;
393 		wpa_auth_get_fils_aead_params(sta->wpa_sm, params.fils_anonce,
394 					      params.fils_snonce,
395 					      params.fils_kek,
396 					      &params.fils_kek_len);
397 	}
398 #endif /* CONFIG_FILS */
399 
400 	params.own_addr = hapd->own_addr;
401 	params.addr = addr;
402 	params.seq = seq;
403 	params.status = status;
404 	params.ie = ie;
405 	params.len = len;
406 
407 	return hapd->driver->sta_auth(hapd->drv_priv, &params);
408 }
409 
410 
hostapd_sta_assoc(struct hostapd_data * hapd,const u8 * addr,int reassoc,u16 status,const u8 * ie,size_t len)411 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
412 		      int reassoc, u16 status, const u8 *ie, size_t len)
413 {
414 	if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
415 		return 0;
416 	return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
417 				       reassoc, status, ie, len);
418 }
419 
420 
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)421 int hostapd_sta_add(struct hostapd_data *hapd,
422 		    const u8 *addr, u16 aid, u16 capability,
423 		    const u8 *supp_rates, size_t supp_rates_len,
424 		    u16 listen_interval,
425 		    const struct ieee80211_ht_capabilities *ht_capab,
426 		    const struct ieee80211_vht_capabilities *vht_capab,
427 		    const struct ieee80211_he_capabilities *he_capab,
428 		    size_t he_capab_len,
429 		    const struct ieee80211_eht_capabilities *eht_capab,
430 		    size_t eht_capab_len,
431 		    const struct ieee80211_he_6ghz_band_cap *he_6ghz_capab,
432 		    u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
433 		    int set, const u8 *link_addr, bool mld_link_sta)
434 {
435 	struct hostapd_sta_add_params params;
436 
437 	if (hapd->driver == NULL)
438 		return 0;
439 	if (hapd->driver->sta_add == NULL)
440 		return 0;
441 
442 	os_memset(&params, 0, sizeof(params));
443 	params.addr = addr;
444 	params.aid = aid;
445 	params.capability = capability;
446 	params.supp_rates = supp_rates;
447 	params.supp_rates_len = supp_rates_len;
448 	params.listen_interval = listen_interval;
449 	params.ht_capabilities = ht_capab;
450 	params.vht_capabilities = vht_capab;
451 	params.he_capab = he_capab;
452 	params.he_capab_len = he_capab_len;
453 	params.eht_capab = eht_capab;
454 	params.eht_capab_len = eht_capab_len;
455 	params.he_6ghz_capab = he_6ghz_capab;
456 	params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
457 	params.vht_opmode = vht_opmode;
458 	params.flags = hostapd_sta_flags_to_drv(flags);
459 	params.qosinfo = qosinfo;
460 	params.support_p2p_ps = supp_p2p_ps;
461 	params.set = set;
462 	params.mld_link_id = -1;
463 
464 #ifdef CONFIG_IEEE80211BE
465 	/*
466 	 * An AP MLD needs to always specify to what link the station needs
467 	 * to be added.
468 	 */
469 	if (hapd->conf->mld_ap) {
470 		params.mld_link_id = hapd->mld_link_id;
471 		params.mld_link_addr = link_addr;
472 		params.mld_link_sta = mld_link_sta;
473 	}
474 #endif /* CONFIG_IEEE80211BE */
475 
476 	return hapd->driver->sta_add(hapd->drv_priv, &params);
477 }
478 
479 
hostapd_add_tspec(struct hostapd_data * hapd,const u8 * addr,u8 * tspec_ie,size_t tspec_ielen)480 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
481 		      u8 *tspec_ie, size_t tspec_ielen)
482 {
483 	if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
484 		return 0;
485 	return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
486 				       tspec_ielen);
487 }
488 
489 
hostapd_set_privacy(struct hostapd_data * hapd,int enabled)490 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
491 {
492 	if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
493 		return 0;
494 	return hapd->driver->set_privacy(hapd->drv_priv, enabled);
495 }
496 
497 
hostapd_set_generic_elem(struct hostapd_data * hapd,const u8 * elem,size_t elem_len)498 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
499 			     size_t elem_len)
500 {
501 	if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
502 		return 0;
503 	return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
504 }
505 
506 
hostapd_get_ssid(struct hostapd_data * hapd,u8 * buf,size_t len)507 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
508 {
509 	if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
510 		return 0;
511 	return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
512 }
513 
514 
hostapd_set_ssid(struct hostapd_data * hapd,const u8 * buf,size_t len)515 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
516 {
517 	if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
518 		return 0;
519 	return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
520 }
521 
522 
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)523 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
524 		   const char *ifname, const u8 *addr, void *bss_ctx,
525 		   void **drv_priv, char *force_ifname, u8 *if_addr,
526 		   const char *bridge, int use_existing)
527 {
528 	if (hapd->driver == NULL || hapd->driver->if_add == NULL)
529 		return -1;
530 	return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
531 				    bss_ctx, drv_priv, force_ifname, if_addr,
532 				    bridge, use_existing, 1);
533 }
534 
535 
hostapd_if_remove(struct hostapd_data * hapd,enum wpa_driver_if_type type,const char * ifname)536 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
537 		      const char *ifname)
538 {
539 	if (hapd->driver == NULL || hapd->drv_priv == NULL ||
540 	    hapd->driver->if_remove == NULL)
541 		return -1;
542 	return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
543 }
544 
545 
hostapd_set_ieee8021x(struct hostapd_data * hapd,struct wpa_bss_params * params)546 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
547 			  struct wpa_bss_params *params)
548 {
549 	if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
550 		return 0;
551 	return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
552 }
553 
554 
hostapd_get_seqnum(const char * ifname,struct hostapd_data * hapd,const u8 * addr,int idx,int link_id,u8 * seq)555 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
556 		       const u8 *addr, int idx, int link_id, u8 *seq)
557 {
558 	if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
559 		return 0;
560 	return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
561 					link_id, seq);
562 }
563 
564 
hostapd_flush(struct hostapd_data * hapd)565 int hostapd_flush(struct hostapd_data *hapd)
566 {
567 	if (hapd->driver == NULL || hapd->driver->flush == NULL)
568 		return 0;
569 	return hapd->driver->flush(hapd->drv_priv);
570 }
571 
572 
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)573 int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
574 		     int freq, int channel, int edmg, u8 edmg_channel,
575 		     int ht_enabled, int vht_enabled,
576 		     int he_enabled, bool eht_enabled,
577 		     int sec_channel_offset, int oper_chwidth,
578 		     int center_segment0, int center_segment1)
579 {
580 	struct hostapd_freq_params data;
581 	struct hostapd_hw_modes *cmode = hapd->iface->current_mode;
582 
583 	if (hostapd_set_freq_params(&data, mode, freq, channel, edmg,
584 				    edmg_channel, ht_enabled,
585 				    vht_enabled, he_enabled, eht_enabled,
586 				    sec_channel_offset, oper_chwidth,
587 				    center_segment0, center_segment1,
588 				    cmode ? cmode->vht_capab : 0,
589 				    cmode ?
590 				    &cmode->he_capab[IEEE80211_MODE_AP] : NULL,
591 				    cmode ?
592 				    &cmode->eht_capab[IEEE80211_MODE_AP] :
593 				    NULL))
594 		return -1;
595 
596 	if (hapd->driver == NULL)
597 		return 0;
598 	if (hapd->driver->set_freq == NULL)
599 		return 0;
600 
601 	data.link_id = -1;
602 
603 #ifdef CONFIG_IEEE80211BE
604 	if (hapd->conf->mld_ap) {
605 		data.link_id = hapd->mld_link_id;
606 		wpa_printf(MSG_DEBUG,
607 			   "hostapd_set_freq: link_id=%d", data.link_id);
608 	}
609 #endif /* CONFIG_IEEE80211BE */
610 
611 	return hapd->driver->set_freq(hapd->drv_priv, &data);
612 }
613 
hostapd_set_rts(struct hostapd_data * hapd,int rts)614 int hostapd_set_rts(struct hostapd_data *hapd, int rts)
615 {
616 	if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
617 		return 0;
618 	return hapd->driver->set_rts(hapd->drv_priv, rts);
619 }
620 
621 
hostapd_set_frag(struct hostapd_data * hapd,int frag)622 int hostapd_set_frag(struct hostapd_data *hapd, int frag)
623 {
624 	if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
625 		return 0;
626 	return hapd->driver->set_frag(hapd->drv_priv, frag);
627 }
628 
629 
hostapd_sta_set_flags(struct hostapd_data * hapd,u8 * addr,int total_flags,int flags_or,int flags_and)630 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
631 			  int total_flags, int flags_or, int flags_and)
632 {
633 	if (!hapd->driver || !hapd->drv_priv || !hapd->driver->sta_set_flags)
634 		return 0;
635 	return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
636 					   flags_or, flags_and);
637 }
638 
639 
hostapd_sta_set_airtime_weight(struct hostapd_data * hapd,const u8 * addr,unsigned int weight)640 int hostapd_sta_set_airtime_weight(struct hostapd_data *hapd, const u8 *addr,
641 				   unsigned int weight)
642 {
643 	if (!hapd->driver || !hapd->driver->sta_set_airtime_weight)
644 		return 0;
645 	return hapd->driver->sta_set_airtime_weight(hapd->drv_priv, addr,
646 						    weight);
647 }
648 
649 
hostapd_set_country(struct hostapd_data * hapd,const char * country)650 int hostapd_set_country(struct hostapd_data *hapd, const char *country)
651 {
652 	if (hapd->driver == NULL ||
653 	    hapd->driver->set_country == NULL)
654 		return 0;
655 	return hapd->driver->set_country(hapd->drv_priv, country);
656 }
657 
658 
hostapd_set_tx_queue_params(struct hostapd_data * hapd,int queue,int aifs,int cw_min,int cw_max,int burst_time)659 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
660 				int cw_min, int cw_max, int burst_time)
661 {
662 	int link_id = -1;
663 
664 	if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
665 		return 0;
666 
667 #ifdef CONFIG_IEEE80211BE
668 	if (hapd->conf->mld_ap)
669 		link_id = hapd->mld_link_id;
670 #endif /* CONFIG_IEEE80211BE */
671 
672 	return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
673 						 cw_min, cw_max, burst_time,
674 						 link_id);
675 }
676 
677 
678 struct hostapd_hw_modes *
hostapd_get_hw_feature_data(struct hostapd_data * hapd,u16 * num_modes,u16 * flags,u8 * dfs_domain)679 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
680 			    u16 *flags, u8 *dfs_domain)
681 {
682 	if (!hapd->driver || !hapd->driver->get_hw_feature_data ||
683 	    !hapd->drv_priv)
684 		return NULL;
685 	return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
686 						 flags, dfs_domain);
687 }
688 
689 
hostapd_driver_commit(struct hostapd_data * hapd)690 int hostapd_driver_commit(struct hostapd_data *hapd)
691 {
692 	if (hapd->driver == NULL || hapd->driver->commit == NULL)
693 		return 0;
694 	return hapd->driver->commit(hapd->drv_priv);
695 }
696 
697 
hostapd_drv_none(struct hostapd_data * hapd)698 int hostapd_drv_none(struct hostapd_data *hapd)
699 {
700 	return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
701 }
702 
703 
hostapd_drv_nl80211(struct hostapd_data * hapd)704 bool hostapd_drv_nl80211(struct hostapd_data *hapd)
705 {
706 	return hapd->driver && os_strcmp(hapd->driver->name, "nl80211") == 0;
707 }
708 
709 
hostapd_driver_scan(struct hostapd_data * hapd,struct wpa_driver_scan_params * params)710 int hostapd_driver_scan(struct hostapd_data *hapd,
711 			struct wpa_driver_scan_params *params)
712 {
713 	if (hapd->driver && hapd->driver->scan2)
714 		return hapd->driver->scan2(hapd->drv_priv, params);
715 	return -1;
716 }
717 
718 
hostapd_driver_get_scan_results(struct hostapd_data * hapd)719 struct wpa_scan_results * hostapd_driver_get_scan_results(
720 	struct hostapd_data *hapd)
721 {
722 	if (hapd->driver && hapd->driver->get_scan_results2)
723 		return hapd->driver->get_scan_results2(hapd->drv_priv);
724 	return NULL;
725 }
726 
727 
hostapd_driver_set_noa(struct hostapd_data * hapd,u8 count,int start,int duration)728 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
729 			   int duration)
730 {
731 	if (hapd->driver && hapd->driver->set_noa)
732 		return hapd->driver->set_noa(hapd->drv_priv, count, start,
733 					     duration);
734 	return -1;
735 }
736 
737 
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)738 int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
739 			enum wpa_alg alg, const u8 *addr,
740 			int key_idx, int vlan_id, int set_tx,
741 			const u8 *seq, size_t seq_len,
742 			const u8 *key, size_t key_len, enum key_flag key_flag)
743 {
744 	struct wpa_driver_set_key_params params;
745 
746 	if (hapd->driver == NULL || hapd->driver->set_key == NULL)
747 		return 0;
748 
749 	os_memset(&params, 0, sizeof(params));
750 	params.ifname = ifname;
751 	params.alg = alg;
752 	params.addr = addr;
753 	params.key_idx = key_idx;
754 	params.set_tx = set_tx;
755 	params.seq = seq;
756 	params.seq_len = seq_len;
757 	params.key = key;
758 	params.key_len = key_len;
759 	params.vlan_id = vlan_id;
760 	params.key_flag = key_flag;
761 	params.link_id = -1;
762 
763 #ifdef CONFIG_IEEE80211BE
764 	if (hapd->conf->mld_ap && !(key_flag & KEY_FLAG_PAIRWISE))
765 		params.link_id = hapd->mld_link_id;
766 #endif /* CONFIG_IEEE80211BE */
767 
768 	return hapd->driver->set_key(hapd->drv_priv, &params);
769 }
770 
771 
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)772 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
773 			  const void *msg, size_t len, int noack,
774 			  const u16 *csa_offs, size_t csa_offs_len,
775 			  int no_encrypt)
776 {
777 	int link_id = -1;
778 
779 #ifdef CONFIG_IEEE80211BE
780 	if (hapd->conf->mld_ap)
781 		link_id = hapd->mld_link_id;
782 #endif /* CONFIG_IEEE80211BE */
783 
784 	if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
785 		return 0;
786 	return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
787 				       csa_offs, csa_offs_len, no_encrypt, 0,
788 				       link_id);
789 }
790 
791 
hostapd_drv_sta_deauth(struct hostapd_data * hapd,const u8 * addr,int reason)792 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
793 			   const u8 *addr, int reason)
794 {
795 	int link_id = -1;
796 
797 #ifdef CONFIG_IEEE80211BE
798 	if (hapd->conf->mld_ap)
799 		link_id = hapd->mld_link_id;
800 #endif /* CONFIG_IEEE80211BE */
801 
802 	if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
803 		return 0;
804 	return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
805 					reason, link_id);
806 }
807 
808 
hostapd_drv_sta_disassoc(struct hostapd_data * hapd,const u8 * addr,int reason)809 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
810 			     const u8 *addr, int reason)
811 {
812 	if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
813 		return 0;
814 	return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
815 					  reason);
816 }
817 
818 
hostapd_drv_wnm_oper(struct hostapd_data * hapd,enum wnm_oper oper,const u8 * peer,u8 * buf,u16 * buf_len)819 int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
820 			 const u8 *peer, u8 *buf, u16 *buf_len)
821 {
822 	if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
823 		return -1;
824 	return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
825 				      buf_len);
826 }
827 
828 
hostapd_drv_send_action(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * data,size_t len)829 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
830 			    unsigned int wait, const u8 *dst, const u8 *data,
831 			    size_t len)
832 {
833 	const u8 *bssid;
834 	const u8 wildcard_bssid[ETH_ALEN] = {
835 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
836 	};
837 
838 	if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
839 		return 0;
840 	bssid = hapd->own_addr;
841 	if (!is_multicast_ether_addr(dst) &&
842 	    len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
843 		struct sta_info *sta;
844 
845 		/*
846 		 * Public Action frames to a STA that is not a member of the BSS
847 		 * shall use wildcard BSSID value.
848 		 */
849 		sta = ap_get_sta(hapd, dst);
850 		if (!sta || !(sta->flags & WLAN_STA_ASSOC))
851 			bssid = wildcard_bssid;
852 	} else if (is_broadcast_ether_addr(dst) &&
853 		   len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
854 		/*
855 		 * The only current use case of Public Action frames with
856 		 * broadcast destination address is DPP PKEX. That case is
857 		 * directing all devices and not just the STAs within the BSS,
858 		 * so have to use the wildcard BSSID value.
859 		 */
860 		bssid = wildcard_bssid;
861 	}
862 	return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
863 					 hapd->own_addr, bssid, data, len, 0);
864 }
865 
866 
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)867 int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
868 				     unsigned int freq,
869 				     unsigned int wait, const u8 *dst,
870 				     const u8 *data, size_t len)
871 {
872 	if (hapd->driver == NULL || hapd->driver->send_action == NULL)
873 		return 0;
874 	return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
875 					 hapd->own_addr, hapd->own_addr, data,
876 					 len, 0);
877 }
878 
879 
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)880 int hostapd_start_dfs_cac(struct hostapd_iface *iface,
881 			  enum hostapd_hw_mode mode, int freq,
882 			  int channel, int ht_enabled, int vht_enabled,
883 			  int he_enabled, bool eht_enabled,
884 			  int sec_channel_offset, int oper_chwidth,
885 			  int center_segment0, int center_segment1,
886 			  bool radar_background)
887 {
888 	struct hostapd_data *hapd = iface->bss[0];
889 	struct hostapd_freq_params data;
890 	int res;
891 	struct hostapd_hw_modes *cmode = iface->current_mode;
892 
893 	if (!hapd->driver || !hapd->driver->start_dfs_cac || !cmode)
894 		return 0;
895 
896 	if (!iface->conf->ieee80211h) {
897 		wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
898 			   "is not enabled");
899 		return -1;
900 	}
901 
902 	if (hostapd_set_freq_params(&data, mode, freq, channel, 0, 0,
903 				    ht_enabled,
904 				    vht_enabled, he_enabled, eht_enabled,
905 				    sec_channel_offset,
906 				    oper_chwidth, center_segment0,
907 				    center_segment1,
908 				    cmode->vht_capab,
909 				    &cmode->he_capab[IEEE80211_MODE_AP],
910 				    &cmode->eht_capab[IEEE80211_MODE_AP])) {
911 		wpa_printf(MSG_ERROR, "Can't set freq params");
912 		return -1;
913 	}
914 	data.radar_background = radar_background;
915 
916 	res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
917 	if (!res) {
918 		if (radar_background)
919 			iface->radar_background.cac_started = 1;
920 		else
921 			iface->cac_started = 1;
922 		os_get_reltime(&iface->dfs_cac_start);
923 	}
924 
925 	return res;
926 }
927 
928 
hostapd_drv_set_qos_map(struct hostapd_data * hapd,const u8 * qos_map_set,u8 qos_map_set_len)929 int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
930 			    const u8 *qos_map_set, u8 qos_map_set_len)
931 {
932 	if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
933 		return 0;
934 	return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
935 					 qos_map_set_len);
936 }
937 
938 
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)939 void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
940 				      struct hostapd_hw_modes *mode,
941 				      int acs_ch_list_all, bool allow_disabled,
942 				      int **freq_list)
943 {
944 	int i;
945 	bool is_no_ir = false;
946 
947 	for (i = 0; i < mode->num_channels; i++) {
948 		struct hostapd_channel_data *chan = &mode->channels[i];
949 
950 		if (!acs_ch_list_all &&
951 		    (hapd->iface->conf->acs_freq_list.num &&
952 		     !freq_range_list_includes(
953 			     &hapd->iface->conf->acs_freq_list,
954 			     chan->freq)))
955 			continue;
956 		if (!acs_ch_list_all &&
957 		    (!hapd->iface->conf->acs_freq_list_present &&
958 		     hapd->iface->conf->acs_ch_list.num &&
959 		     !freq_range_list_includes(
960 			     &hapd->iface->conf->acs_ch_list,
961 			     chan->chan)))
962 			continue;
963 		if (is_6ghz_freq(chan->freq) &&
964 		    ((hapd->iface->conf->acs_exclude_6ghz_non_psc &&
965 		      !is_6ghz_psc_frequency(chan->freq)) ||
966 		     (!hapd->iface->conf->ieee80211ax &&
967 		      !hapd->iface->conf->ieee80211be)))
968 			continue;
969 		if ((!(chan->flag & HOSTAPD_CHAN_DISABLED) || allow_disabled) &&
970 		    !(hapd->iface->conf->acs_exclude_dfs &&
971 		      (chan->flag & HOSTAPD_CHAN_RADAR)) &&
972 		    !(chan->max_tx_power < hapd->iface->conf->min_tx_power))
973 			int_array_add_unique(freq_list, chan->freq);
974 		else if ((chan->flag & HOSTAPD_CHAN_NO_IR) &&
975 			 is_6ghz_freq(chan->freq))
976 			is_no_ir = true;
977 	}
978 
979 	hapd->iface->is_no_ir = is_no_ir;
980 }
981 
982 
hostapd_get_ext_capa(struct hostapd_iface * iface)983 void hostapd_get_ext_capa(struct hostapd_iface *iface)
984 {
985 	struct hostapd_data *hapd = iface->bss[0];
986 
987 	if (!hapd->driver || !hapd->driver->get_ext_capab)
988 		return;
989 
990 	hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
991 				    &iface->extended_capa,
992 				    &iface->extended_capa_mask,
993 				    &iface->extended_capa_len);
994 }
995 
996 
hostapd_get_mld_capa(struct hostapd_iface * iface)997 void hostapd_get_mld_capa(struct hostapd_iface *iface)
998 {
999 	struct hostapd_data *hapd = iface->bss[0];
1000 
1001 	if (!hapd->driver || !hapd->driver->get_mld_capab)
1002 		return;
1003 
1004 	hapd->driver->get_mld_capab(hapd->drv_priv, WPA_IF_AP_BSS,
1005 				    &iface->mld_eml_capa,
1006 				    &iface->mld_mld_capa);
1007 }
1008 
1009 
1010 /**
1011  * hostapd_drv_do_acs - Start automatic channel selection
1012  * @hapd: BSS data for the device initiating ACS
1013  * Returns: 0 on success, -1 on failure, 1 on failure due to NO_IR (AFC)
1014  */
hostapd_drv_do_acs(struct hostapd_data * hapd)1015 int hostapd_drv_do_acs(struct hostapd_data *hapd)
1016 {
1017 	struct drv_acs_params params;
1018 	int ret, i, acs_ch_list_all = 0;
1019 	struct hostapd_hw_modes *mode;
1020 	int *freq_list = NULL;
1021 	enum hostapd_hw_mode selected_mode;
1022 
1023 	if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
1024 		return 0;
1025 
1026 	os_memset(&params, 0, sizeof(params));
1027 	params.hw_mode = hapd->iface->conf->hw_mode;
1028 
1029 	/*
1030 	 * If no chanlist config parameter is provided, include all enabled
1031 	 * channels of the selected hw_mode.
1032 	 */
1033 	if (hapd->iface->conf->acs_freq_list_present)
1034 		acs_ch_list_all = !hapd->iface->conf->acs_freq_list.num;
1035 	else
1036 		acs_ch_list_all = !hapd->iface->conf->acs_ch_list.num;
1037 
1038 	if (hapd->iface->current_mode)
1039 		selected_mode = hapd->iface->current_mode->mode;
1040 	else
1041 		selected_mode = HOSTAPD_MODE_IEEE80211ANY;
1042 
1043 	for (i = 0; i < hapd->iface->num_hw_features; i++) {
1044 		mode = &hapd->iface->hw_features[i];
1045 		if (selected_mode != HOSTAPD_MODE_IEEE80211ANY &&
1046 		    selected_mode != mode->mode)
1047 			continue;
1048 		hostapd_get_hw_mode_any_channels(hapd, mode, acs_ch_list_all,
1049 						 false, &freq_list);
1050 	}
1051 
1052 	if (!freq_list && hapd->iface->is_no_ir) {
1053 		wpa_printf(MSG_ERROR,
1054 			   "NO_IR: Interface freq_list is empty. Failing do_acs.");
1055 		return 1;
1056 	}
1057 
1058 	params.freq_list = freq_list;
1059 	params.edmg_enabled = hapd->iface->conf->enable_edmg;
1060 
1061 	params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
1062 	params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
1063 				 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
1064 	params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
1065 	params.eht_enabled = !!(hapd->iface->conf->ieee80211be);
1066 	params.ch_width = 20;
1067 	if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
1068 		params.ch_width = 40;
1069 
1070 	/* Note: VHT20 is defined by combination of ht_capab & oper_chwidth
1071 	 */
1072 	if ((hapd->iface->conf->ieee80211be ||
1073 	     hapd->iface->conf->ieee80211ax ||
1074 	     hapd->iface->conf->ieee80211ac) &&
1075 	    params.ht40_enabled) {
1076 		enum oper_chan_width oper_chwidth;
1077 
1078 		oper_chwidth = hostapd_get_oper_chwidth(hapd->iface->conf);
1079 		if (oper_chwidth == CONF_OPER_CHWIDTH_80MHZ)
1080 			params.ch_width = 80;
1081 		else if (oper_chwidth == CONF_OPER_CHWIDTH_160MHZ ||
1082 			 oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
1083 			params.ch_width = 160;
1084 		else if (oper_chwidth == CONF_OPER_CHWIDTH_320MHZ)
1085 			params.ch_width = 320;
1086 	}
1087 
1088 	if (hapd->iface->conf->op_class)
1089 		params.ch_width = op_class_to_bandwidth(
1090 			hapd->iface->conf->op_class);
1091 	ret = hapd->driver->do_acs(hapd->drv_priv, &params);
1092 	os_free(freq_list);
1093 
1094 	return ret;
1095 }
1096 
1097 
hostapd_drv_update_dh_ie(struct hostapd_data * hapd,const u8 * peer,u16 reason_code,const u8 * ie,size_t ielen)1098 int hostapd_drv_update_dh_ie(struct hostapd_data *hapd, const u8 *peer,
1099 			     u16 reason_code, const u8 *ie, size_t ielen)
1100 {
1101 	if (!hapd->driver || !hapd->driver->update_dh_ie || !hapd->drv_priv)
1102 		return 0;
1103 	return hapd->driver->update_dh_ie(hapd->drv_priv, peer, reason_code,
1104 					  ie, ielen);
1105 }
1106 
1107 
hostapd_drv_dpp_listen(struct hostapd_data * hapd,bool enable)1108 int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable)
1109 {
1110 	if (!hapd->driver || !hapd->driver->dpp_listen || !hapd->drv_priv)
1111 		return 0;
1112 	return hapd->driver->dpp_listen(hapd->drv_priv, enable);
1113 }
1114 
1115 
1116 #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)1117 int hostapd_drv_set_secure_ranging_ctx(struct hostapd_data *hapd,
1118 				       const u8 *own_addr, const u8 *peer_addr,
1119 				       u32 cipher, u8 tk_len, const u8 *tk,
1120 				       u8 ltf_keyseed_len,
1121 				       const u8 *ltf_keyseed, u32 action)
1122 {
1123 	struct secure_ranging_params params;
1124 
1125 	if (!hapd->driver || !hapd->driver->set_secure_ranging_ctx)
1126 		return 0;
1127 
1128 	os_memset(&params, 0, sizeof(params));
1129 	params.own_addr = own_addr;
1130 	params.peer_addr = peer_addr;
1131 	params.cipher = cipher;
1132 	params.tk_len = tk_len;
1133 	params.tk = tk;
1134 	params.ltf_keyseed_len = ltf_keyseed_len;
1135 	params.ltf_keyseed = ltf_keyseed;
1136 	params.action = action;
1137 
1138 	return hapd->driver->set_secure_ranging_ctx(hapd->drv_priv, &params);
1139 }
1140 #endif /* CONFIG_PASN */
1141