xref: /netbsd-src/external/bsd/wpa/dist/src/ap/ap_drv_ops.c (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
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/hw_features_common.h"
14 #include "wps/wps.h"
15 #include "p2p/p2p.h"
16 #include "hostapd.h"
17 #include "ieee802_11.h"
18 #include "sta_info.h"
19 #include "ap_config.h"
20 #include "p2p_hostapd.h"
21 #include "hs20.h"
22 #include "wpa_auth.h"
23 #include "ap_drv_ops.h"
24 
25 
26 u32 hostapd_sta_flags_to_drv(u32 flags)
27 {
28 	int res = 0;
29 	if (flags & WLAN_STA_AUTHORIZED)
30 		res |= WPA_STA_AUTHORIZED;
31 	if (flags & WLAN_STA_WMM)
32 		res |= WPA_STA_WMM;
33 	if (flags & WLAN_STA_SHORT_PREAMBLE)
34 		res |= WPA_STA_SHORT_PREAMBLE;
35 	if (flags & WLAN_STA_MFP)
36 		res |= WPA_STA_MFP;
37 	if (flags & WLAN_STA_AUTH)
38 		res |= WPA_STA_AUTHENTICATED;
39 	if (flags & WLAN_STA_ASSOC)
40 		res |= WPA_STA_ASSOCIATED;
41 	return res;
42 }
43 
44 
45 static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
46 {
47 	if (!src)
48 		return 0;
49 	if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
50 		return -1;
51 	wpabuf_put_buf(*dst, src);
52 	return 0;
53 }
54 
55 
56 static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
57 {
58 	if (!data || !len)
59 		return 0;
60 	if (wpabuf_resize(dst, len) != 0)
61 		return -1;
62 	wpabuf_put_data(*dst, data, len);
63 	return 0;
64 }
65 
66 
67 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
68 			       struct wpabuf **beacon_ret,
69 			       struct wpabuf **proberesp_ret,
70 			       struct wpabuf **assocresp_ret)
71 {
72 	struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
73 	u8 buf[200], *pos;
74 
75 	*beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
76 
77 	pos = buf;
78 	pos = hostapd_eid_time_adv(hapd, pos);
79 	if (add_buf_data(&beacon, buf, pos - buf) < 0)
80 		goto fail;
81 	pos = hostapd_eid_time_zone(hapd, pos);
82 	if (add_buf_data(&proberesp, buf, pos - buf) < 0)
83 		goto fail;
84 
85 	pos = buf;
86 	pos = hostapd_eid_ext_capab(hapd, pos);
87 	if (add_buf_data(&assocresp, buf, pos - buf) < 0)
88 		goto fail;
89 	pos = hostapd_eid_interworking(hapd, pos);
90 	pos = hostapd_eid_adv_proto(hapd, pos);
91 	pos = hostapd_eid_roaming_consortium(hapd, pos);
92 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
93 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
94 		goto fail;
95 
96 #ifdef CONFIG_FST
97 	if (add_buf(&beacon, hapd->iface->fst_ies) < 0 ||
98 	    add_buf(&proberesp, hapd->iface->fst_ies) < 0 ||
99 	    add_buf(&assocresp, hapd->iface->fst_ies) < 0)
100 		goto fail;
101 #endif /* CONFIG_FST */
102 
103 #ifdef CONFIG_FILS
104 	pos = hostapd_eid_fils_indic(hapd, buf, 0);
105 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
106 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
107 		goto fail;
108 #endif /* CONFIG_FILS */
109 
110 	if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
111 	    add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
112 		goto fail;
113 
114 #ifdef CONFIG_P2P
115 	if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
116 	    add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
117 		goto fail;
118 #endif /* CONFIG_P2P */
119 
120 #ifdef CONFIG_P2P_MANAGER
121 	if (hapd->conf->p2p & P2P_MANAGE) {
122 		if (wpabuf_resize(&beacon, 100) == 0) {
123 			u8 *start, *p;
124 			start = wpabuf_put(beacon, 0);
125 			p = hostapd_eid_p2p_manage(hapd, start);
126 			wpabuf_put(beacon, p - start);
127 		}
128 
129 		if (wpabuf_resize(&proberesp, 100) == 0) {
130 			u8 *start, *p;
131 			start = wpabuf_put(proberesp, 0);
132 			p = hostapd_eid_p2p_manage(hapd, start);
133 			wpabuf_put(proberesp, p - start);
134 		}
135 	}
136 #endif /* CONFIG_P2P_MANAGER */
137 
138 #ifdef CONFIG_WPS
139 	if (hapd->conf->wps_state) {
140 		struct wpabuf *a = wps_build_assoc_resp_ie();
141 		add_buf(&assocresp, a);
142 		wpabuf_free(a);
143 	}
144 #endif /* CONFIG_WPS */
145 
146 #ifdef CONFIG_P2P_MANAGER
147 	if (hapd->conf->p2p & P2P_MANAGE) {
148 		if (wpabuf_resize(&assocresp, 100) == 0) {
149 			u8 *start, *p;
150 			start = wpabuf_put(assocresp, 0);
151 			p = hostapd_eid_p2p_manage(hapd, start);
152 			wpabuf_put(assocresp, p - start);
153 		}
154 	}
155 #endif /* CONFIG_P2P_MANAGER */
156 
157 #ifdef CONFIG_WIFI_DISPLAY
158 	if (hapd->p2p_group) {
159 		struct wpabuf *a;
160 		a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
161 		add_buf(&assocresp, a);
162 		wpabuf_free(a);
163 	}
164 #endif /* CONFIG_WIFI_DISPLAY */
165 
166 #ifdef CONFIG_HS20
167 	pos = hostapd_eid_hs20_indication(hapd, buf);
168 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
169 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
170 		goto fail;
171 
172 	pos = hostapd_eid_osen(hapd, buf);
173 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
174 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
175 		goto fail;
176 #endif /* CONFIG_HS20 */
177 
178 #ifdef CONFIG_MBO
179 	if (hapd->conf->mbo_enabled ||
180 	    OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
181 		pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
182 		if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
183 		    add_buf_data(&proberesp, buf, pos - buf) < 0 ||
184 		    add_buf_data(&assocresp, buf, pos - buf) < 0)
185 			goto fail;
186 	}
187 #endif /* CONFIG_MBO */
188 
189 #ifdef CONFIG_OWE
190 	pos = hostapd_eid_owe_trans(hapd, buf, sizeof(buf));
191 	if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
192 	    add_buf_data(&proberesp, buf, pos - buf) < 0)
193 		goto fail;
194 #endif /* CONFIG_OWE */
195 
196 	add_buf(&beacon, hapd->conf->vendor_elements);
197 	add_buf(&proberesp, hapd->conf->vendor_elements);
198 	add_buf(&assocresp, hapd->conf->assocresp_elements);
199 
200 	*beacon_ret = beacon;
201 	*proberesp_ret = proberesp;
202 	*assocresp_ret = assocresp;
203 
204 	return 0;
205 
206 fail:
207 	wpabuf_free(beacon);
208 	wpabuf_free(proberesp);
209 	wpabuf_free(assocresp);
210 	return -1;
211 }
212 
213 
214 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
215 			       struct wpabuf *beacon,
216 			       struct wpabuf *proberesp,
217 			       struct wpabuf *assocresp)
218 {
219 	wpabuf_free(beacon);
220 	wpabuf_free(proberesp);
221 	wpabuf_free(assocresp);
222 }
223 
224 
225 int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
226 {
227 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
228 		return 0;
229 
230 	return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
231 }
232 
233 
234 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
235 {
236 	struct wpabuf *beacon, *proberesp, *assocresp;
237 	int ret;
238 
239 	if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
240 		return 0;
241 
242 	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
243 	    0)
244 		return -1;
245 
246 	ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
247 					  assocresp);
248 
249 	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
250 
251 	return ret;
252 }
253 
254 
255 int hostapd_set_authorized(struct hostapd_data *hapd,
256 			   struct sta_info *sta, int authorized)
257 {
258 	if (authorized) {
259 		return hostapd_sta_set_flags(hapd, sta->addr,
260 					     hostapd_sta_flags_to_drv(
261 						     sta->flags),
262 					     WPA_STA_AUTHORIZED, ~0);
263 	}
264 
265 	return hostapd_sta_set_flags(hapd, sta->addr,
266 				     hostapd_sta_flags_to_drv(sta->flags),
267 				     0, ~WPA_STA_AUTHORIZED);
268 }
269 
270 
271 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
272 {
273 	int set_flags, total_flags, flags_and, flags_or;
274 	total_flags = hostapd_sta_flags_to_drv(sta->flags);
275 	set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
276 	if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
277 	     sta->auth_alg == WLAN_AUTH_FT) &&
278 	    sta->flags & WLAN_STA_AUTHORIZED)
279 		set_flags |= WPA_STA_AUTHORIZED;
280 	flags_or = total_flags & set_flags;
281 	flags_and = total_flags | ~set_flags;
282 	return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
283 				     flags_or, flags_and);
284 }
285 
286 
287 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
288 			      int enabled)
289 {
290 	struct wpa_bss_params params;
291 	os_memset(&params, 0, sizeof(params));
292 	params.ifname = ifname;
293 	params.enabled = enabled;
294 	if (enabled) {
295 		params.wpa = hapd->conf->wpa;
296 		params.ieee802_1x = hapd->conf->ieee802_1x;
297 		params.wpa_group = hapd->conf->wpa_group;
298 		if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
299 		    (WPA_PROTO_WPA | WPA_PROTO_RSN))
300 			params.wpa_pairwise = hapd->conf->wpa_pairwise |
301 				hapd->conf->rsn_pairwise;
302 		else if (hapd->conf->wpa & WPA_PROTO_RSN)
303 			params.wpa_pairwise = hapd->conf->rsn_pairwise;
304 		else if (hapd->conf->wpa & WPA_PROTO_WPA)
305 			params.wpa_pairwise = hapd->conf->wpa_pairwise;
306 		params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
307 		params.rsn_preauth = hapd->conf->rsn_preauth;
308 #ifdef CONFIG_IEEE80211W
309 		params.ieee80211w = hapd->conf->ieee80211w;
310 #endif /* CONFIG_IEEE80211W */
311 	}
312 	return hostapd_set_ieee8021x(hapd, &params);
313 }
314 
315 
316 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
317 {
318 	char force_ifname[IFNAMSIZ];
319 	u8 if_addr[ETH_ALEN];
320 	return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
321 			      NULL, NULL, force_ifname, if_addr, NULL, 0);
322 }
323 
324 
325 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
326 {
327 	return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
328 }
329 
330 
331 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
332 			const u8 *addr, int aid, int val)
333 {
334 	const char *bridge = NULL;
335 
336 	if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
337 		return -1;
338 	if (hapd->conf->wds_bridge[0])
339 		bridge = hapd->conf->wds_bridge;
340 	else if (hapd->conf->bridge[0])
341 		bridge = hapd->conf->bridge;
342 	return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
343 					 bridge, ifname_wds);
344 }
345 
346 
347 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
348 			 u16 auth_alg)
349 {
350 	if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
351 		return 0;
352 	return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
353 }
354 
355 
356 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
357 		     u16 seq, u16 status, const u8 *ie, size_t len)
358 {
359 	struct wpa_driver_sta_auth_params params;
360 #ifdef CONFIG_FILS
361 	struct sta_info *sta;
362 #endif /* CONFIG_FILS */
363 
364 	if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
365 		return 0;
366 
367 	os_memset(&params, 0, sizeof(params));
368 
369 #ifdef CONFIG_FILS
370 	sta = ap_get_sta(hapd, addr);
371 	if (!sta) {
372 		wpa_printf(MSG_DEBUG, "Station " MACSTR
373 			   " not found for sta_auth processing",
374 			   MAC2STR(addr));
375 		return 0;
376 	}
377 
378 	if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
379 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
380 	    sta->auth_alg == WLAN_AUTH_FILS_PK) {
381 		params.fils_auth = 1;
382 		wpa_auth_get_fils_aead_params(sta->wpa_sm, params.fils_anonce,
383 					      params.fils_snonce,
384 					      params.fils_kek,
385 					      &params.fils_kek_len);
386 	}
387 #endif /* CONFIG_FILS */
388 
389 	params.own_addr = hapd->own_addr;
390 	params.addr = addr;
391 	params.seq = seq;
392 	params.status = status;
393 	params.ie = ie;
394 	params.len = len;
395 
396 	return hapd->driver->sta_auth(hapd->drv_priv, &params);
397 }
398 
399 
400 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
401 		      int reassoc, u16 status, const u8 *ie, size_t len)
402 {
403 	if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
404 		return 0;
405 	return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
406 				       reassoc, status, ie, len);
407 }
408 
409 
410 int hostapd_sta_add(struct hostapd_data *hapd,
411 		    const u8 *addr, u16 aid, u16 capability,
412 		    const u8 *supp_rates, size_t supp_rates_len,
413 		    u16 listen_interval,
414 		    const struct ieee80211_ht_capabilities *ht_capab,
415 		    const struct ieee80211_vht_capabilities *vht_capab,
416 		    u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
417 		    int set)
418 {
419 	struct hostapd_sta_add_params params;
420 
421 	if (hapd->driver == NULL)
422 		return 0;
423 	if (hapd->driver->sta_add == NULL)
424 		return 0;
425 
426 	os_memset(&params, 0, sizeof(params));
427 	params.addr = addr;
428 	params.aid = aid;
429 	params.capability = capability;
430 	params.supp_rates = supp_rates;
431 	params.supp_rates_len = supp_rates_len;
432 	params.listen_interval = listen_interval;
433 	params.ht_capabilities = ht_capab;
434 	params.vht_capabilities = vht_capab;
435 	params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
436 	params.vht_opmode = vht_opmode;
437 	params.flags = hostapd_sta_flags_to_drv(flags);
438 	params.qosinfo = qosinfo;
439 	params.support_p2p_ps = supp_p2p_ps;
440 	params.set = set;
441 	return hapd->driver->sta_add(hapd->drv_priv, &params);
442 }
443 
444 
445 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
446 		      u8 *tspec_ie, size_t tspec_ielen)
447 {
448 	if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
449 		return 0;
450 	return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
451 				       tspec_ielen);
452 }
453 
454 
455 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
456 {
457 	if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
458 		return 0;
459 	return hapd->driver->set_privacy(hapd->drv_priv, enabled);
460 }
461 
462 
463 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
464 			     size_t elem_len)
465 {
466 	if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
467 		return 0;
468 	return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
469 }
470 
471 
472 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
473 {
474 	if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
475 		return 0;
476 	return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
477 }
478 
479 
480 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
481 {
482 	if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
483 		return 0;
484 	return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
485 }
486 
487 
488 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
489 		   const char *ifname, const u8 *addr, void *bss_ctx,
490 		   void **drv_priv, char *force_ifname, u8 *if_addr,
491 		   const char *bridge, int use_existing)
492 {
493 	if (hapd->driver == NULL || hapd->driver->if_add == NULL)
494 		return -1;
495 	return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
496 				    bss_ctx, drv_priv, force_ifname, if_addr,
497 				    bridge, use_existing, 1);
498 }
499 
500 
501 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
502 		      const char *ifname)
503 {
504 	if (hapd->driver == NULL || hapd->drv_priv == NULL ||
505 	    hapd->driver->if_remove == NULL)
506 		return -1;
507 	return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
508 }
509 
510 
511 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
512 			  struct wpa_bss_params *params)
513 {
514 	if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
515 		return 0;
516 	return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
517 }
518 
519 
520 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
521 		       const u8 *addr, int idx, u8 *seq)
522 {
523 	if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
524 		return 0;
525 	return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
526 					seq);
527 }
528 
529 
530 int hostapd_flush(struct hostapd_data *hapd)
531 {
532 	if (hapd->driver == NULL || hapd->driver->flush == NULL)
533 		return 0;
534 	return hapd->driver->flush(hapd->drv_priv);
535 }
536 
537 
538 int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
539 		     int freq, int channel, int ht_enabled, int vht_enabled,
540 		     int sec_channel_offset, int vht_oper_chwidth,
541 		     int center_segment0, int center_segment1)
542 {
543 	struct hostapd_freq_params data;
544 
545 	if (hapd->iface->current_mode &&
546 	    hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
547 				    vht_enabled, sec_channel_offset,
548 				    vht_oper_chwidth,
549 				    center_segment0, center_segment1,
550 				    hapd->iface->current_mode ?
551 				    hapd->iface->current_mode->vht_capab : 0))
552 		return -1;
553 
554 	if (hapd->driver == NULL)
555 		return 0;
556 	if (hapd->driver->set_freq == NULL)
557 		return 0;
558 	return hapd->driver->set_freq(hapd->drv_priv, &data);
559 }
560 
561 int hostapd_set_rts(struct hostapd_data *hapd, int rts)
562 {
563 	if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
564 		return 0;
565 	return hapd->driver->set_rts(hapd->drv_priv, rts);
566 }
567 
568 
569 int hostapd_set_frag(struct hostapd_data *hapd, int frag)
570 {
571 	if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
572 		return 0;
573 	return hapd->driver->set_frag(hapd->drv_priv, frag);
574 }
575 
576 
577 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
578 			  int total_flags, int flags_or, int flags_and)
579 {
580 	if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
581 		return 0;
582 	return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
583 					   flags_or, flags_and);
584 }
585 
586 
587 int hostapd_set_country(struct hostapd_data *hapd, const char *country)
588 {
589 	if (hapd->driver == NULL ||
590 	    hapd->driver->set_country == NULL)
591 		return 0;
592 	return hapd->driver->set_country(hapd->drv_priv, country);
593 }
594 
595 
596 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
597 				int cw_min, int cw_max, int burst_time)
598 {
599 	if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
600 		return 0;
601 	return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
602 						 cw_min, cw_max, burst_time);
603 }
604 
605 
606 struct hostapd_hw_modes *
607 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
608 			    u16 *flags, u8 *dfs_domain)
609 {
610 	if (hapd->driver == NULL ||
611 	    hapd->driver->get_hw_feature_data == NULL)
612 		return NULL;
613 	return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
614 						 flags, dfs_domain);
615 }
616 
617 
618 int hostapd_driver_commit(struct hostapd_data *hapd)
619 {
620 	if (hapd->driver == NULL || hapd->driver->commit == NULL)
621 		return 0;
622 	return hapd->driver->commit(hapd->drv_priv);
623 }
624 
625 
626 int hostapd_drv_none(struct hostapd_data *hapd)
627 {
628 	return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
629 }
630 
631 
632 int hostapd_driver_scan(struct hostapd_data *hapd,
633 			struct wpa_driver_scan_params *params)
634 {
635 	if (hapd->driver && hapd->driver->scan2)
636 		return hapd->driver->scan2(hapd->drv_priv, params);
637 	return -1;
638 }
639 
640 
641 struct wpa_scan_results * hostapd_driver_get_scan_results(
642 	struct hostapd_data *hapd)
643 {
644 	if (hapd->driver && hapd->driver->get_scan_results2)
645 		return hapd->driver->get_scan_results2(hapd->drv_priv);
646 	return NULL;
647 }
648 
649 
650 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
651 			   int duration)
652 {
653 	if (hapd->driver && hapd->driver->set_noa)
654 		return hapd->driver->set_noa(hapd->drv_priv, count, start,
655 					     duration);
656 	return -1;
657 }
658 
659 
660 int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
661 			enum wpa_alg alg, const u8 *addr,
662 			int key_idx, int set_tx,
663 			const u8 *seq, size_t seq_len,
664 			const u8 *key, size_t key_len)
665 {
666 	if (hapd->driver == NULL || hapd->driver->set_key == NULL)
667 		return 0;
668 	return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
669 				     key_idx, set_tx, seq, seq_len, key,
670 				     key_len);
671 }
672 
673 
674 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
675 			  const void *msg, size_t len, int noack)
676 {
677 	if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
678 		return 0;
679 	return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
680 				       NULL, 0);
681 }
682 
683 
684 int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
685 			      const void *msg, size_t len, int noack,
686 			      const u16 *csa_offs, size_t csa_offs_len)
687 {
688 	if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
689 		return 0;
690 	return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
691 				       csa_offs, csa_offs_len);
692 }
693 
694 
695 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
696 			   const u8 *addr, int reason)
697 {
698 	if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
699 		return 0;
700 	return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
701 					reason);
702 }
703 
704 
705 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
706 			     const u8 *addr, int reason)
707 {
708 	if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
709 		return 0;
710 	return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
711 					  reason);
712 }
713 
714 
715 int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
716 			 const u8 *peer, u8 *buf, u16 *buf_len)
717 {
718 	if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
719 		return -1;
720 	return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
721 				      buf_len);
722 }
723 
724 
725 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
726 			    unsigned int wait, const u8 *dst, const u8 *data,
727 			    size_t len)
728 {
729 	const u8 *bssid;
730 	const u8 wildcard_bssid[ETH_ALEN] = {
731 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
732 	};
733 
734 	if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
735 		return 0;
736 	bssid = hapd->own_addr;
737 	if (!is_multicast_ether_addr(dst) &&
738 	    len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
739 		struct sta_info *sta;
740 
741 		/*
742 		 * Public Action frames to a STA that is not a member of the BSS
743 		 * shall use wildcard BSSID value.
744 		 */
745 		sta = ap_get_sta(hapd, dst);
746 		if (!sta || !(sta->flags & WLAN_STA_ASSOC))
747 			bssid = wildcard_bssid;
748 	} else if (is_broadcast_ether_addr(dst) &&
749 		   len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
750 		/*
751 		 * The only current use case of Public Action frames with
752 		 * broadcast destination address is DPP PKEX. That case is
753 		 * directing all devices and not just the STAs within the BSS,
754 		 * so have to use the wildcard BSSID value.
755 		 */
756 		bssid = wildcard_bssid;
757 	}
758 	return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
759 					 hapd->own_addr, bssid, data, len, 0);
760 }
761 
762 
763 int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
764 				     unsigned int freq,
765 				     unsigned int wait, const u8 *dst,
766 				     const u8 *data, size_t len)
767 {
768 	if (hapd->driver == NULL || hapd->driver->send_action == NULL)
769 		return 0;
770 	return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
771 					 hapd->own_addr, hapd->own_addr, data,
772 					 len, 0);
773 }
774 
775 
776 int hostapd_start_dfs_cac(struct hostapd_iface *iface,
777 			  enum hostapd_hw_mode mode, int freq,
778 			  int channel, int ht_enabled, int vht_enabled,
779 			  int sec_channel_offset, int vht_oper_chwidth,
780 			  int center_segment0, int center_segment1)
781 {
782 	struct hostapd_data *hapd = iface->bss[0];
783 	struct hostapd_freq_params data;
784 	int res;
785 
786 	if (!hapd->driver || !hapd->driver->start_dfs_cac)
787 		return 0;
788 
789 	if (!iface->conf->ieee80211h) {
790 		wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
791 			   "is not enabled");
792 		return -1;
793 	}
794 
795 	if (iface->current_mode &&
796 	    hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
797 				    vht_enabled, sec_channel_offset,
798 				    vht_oper_chwidth, center_segment0,
799 				    center_segment1,
800 				    iface->current_mode->vht_capab)) {
801 		wpa_printf(MSG_ERROR, "Can't set freq params");
802 		return -1;
803 	}
804 
805 	res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
806 	if (!res) {
807 		iface->cac_started = 1;
808 		os_get_reltime(&iface->dfs_cac_start);
809 	}
810 
811 	return res;
812 }
813 
814 
815 int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
816 			    const u8 *qos_map_set, u8 qos_map_set_len)
817 {
818 	if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
819 		return 0;
820 	return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
821 					 qos_map_set_len);
822 }
823 
824 
825 static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
826 					     struct hostapd_hw_modes *mode,
827 					     int acs_ch_list_all,
828 					     int **freq_list)
829 {
830 	int i;
831 
832 	for (i = 0; i < mode->num_channels; i++) {
833 		struct hostapd_channel_data *chan = &mode->channels[i];
834 
835 		if ((acs_ch_list_all ||
836 		     freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
837 					      chan->chan)) &&
838 		    !(chan->flag & HOSTAPD_CHAN_DISABLED) &&
839 		    !(hapd->iface->conf->acs_exclude_dfs &&
840 		      (chan->flag & HOSTAPD_CHAN_RADAR)))
841 			int_array_add_unique(freq_list, chan->freq);
842 	}
843 }
844 
845 
846 void hostapd_get_ext_capa(struct hostapd_iface *iface)
847 {
848 	struct hostapd_data *hapd = iface->bss[0];
849 
850 	if (!hapd->driver || !hapd->driver->get_ext_capab)
851 		return;
852 
853 	hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
854 				    &iface->extended_capa,
855 				    &iface->extended_capa_mask,
856 				    &iface->extended_capa_len);
857 }
858 
859 
860 int hostapd_drv_do_acs(struct hostapd_data *hapd)
861 {
862 	struct drv_acs_params params;
863 	int ret, i, acs_ch_list_all = 0;
864 	u8 *channels = NULL;
865 	unsigned int num_channels = 0;
866 	struct hostapd_hw_modes *mode;
867 	int *freq_list = NULL;
868 
869 	if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
870 		return 0;
871 
872 	os_memset(&params, 0, sizeof(params));
873 	params.hw_mode = hapd->iface->conf->hw_mode;
874 
875 	/*
876 	 * If no chanlist config parameter is provided, include all enabled
877 	 * channels of the selected hw_mode.
878 	 */
879 	if (!hapd->iface->conf->acs_ch_list.num)
880 		acs_ch_list_all = 1;
881 
882 	mode = hapd->iface->current_mode;
883 	if (mode) {
884 		channels = os_malloc(mode->num_channels);
885 		if (channels == NULL)
886 			return -1;
887 
888 		for (i = 0; i < mode->num_channels; i++) {
889 			struct hostapd_channel_data *chan = &mode->channels[i];
890 			if (!acs_ch_list_all &&
891 			    !freq_range_list_includes(
892 				    &hapd->iface->conf->acs_ch_list,
893 				    chan->chan))
894 				continue;
895 			if (hapd->iface->conf->acs_exclude_dfs &&
896 			    (chan->flag & HOSTAPD_CHAN_RADAR))
897 				continue;
898 			if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
899 				channels[num_channels++] = chan->chan;
900 				int_array_add_unique(&freq_list, chan->freq);
901 			}
902 		}
903 	} else {
904 		for (i = 0; i < hapd->iface->num_hw_features; i++) {
905 			mode = &hapd->iface->hw_features[i];
906 			hostapd_get_hw_mode_any_channels(hapd, mode,
907 							 acs_ch_list_all,
908 							 &freq_list);
909 		}
910 	}
911 
912 	params.ch_list = channels;
913 	params.ch_list_len = num_channels;
914 	params.freq_list = freq_list;
915 
916 	params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
917 	params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
918 				 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
919 	params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
920 	params.ch_width = 20;
921 	if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
922 		params.ch_width = 40;
923 
924 	/* Note: VHT20 is defined by combination of ht_capab & vht_oper_chwidth
925 	 */
926 	if (hapd->iface->conf->ieee80211ac && params.ht40_enabled) {
927 		if (hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
928 			params.ch_width = 80;
929 		else if (hapd->iface->conf->vht_oper_chwidth ==
930 			 VHT_CHANWIDTH_160MHZ ||
931 			 hapd->iface->conf->vht_oper_chwidth ==
932 			 VHT_CHANWIDTH_80P80MHZ)
933 			params.ch_width = 160;
934 	}
935 
936 	ret = hapd->driver->do_acs(hapd->drv_priv, &params);
937 	os_free(channels);
938 
939 	return ret;
940 }
941