]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/ap_drv_ops.c
HE: Enable ACS similarly to VHT
[thirdparty/hostap.git] / src / ap / ap_drv_ops.c
CommitLineData
bf65bc63
JM
1/*
2 * hostapd - Driver operations
ef580012 3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
bf65bc63 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
bf65bc63
JM
7 */
8
8b06c1ed 9#include "utils/includes.h"
bf65bc63 10
8b06c1ed 11#include "utils/common.h"
ef580012 12#include "common/ieee802_11_defs.h"
ada157f3 13#include "common/hw_features_common.h"
0e2e565a 14#include "wps/wps.h"
9675ce35 15#include "p2p/p2p.h"
8b06c1ed
JM
16#include "hostapd.h"
17#include "ieee802_11.h"
18#include "sta_info.h"
19#include "ap_config.h"
dce044cc 20#include "p2p_hostapd.h"
19a8ad99 21#include "hs20.h"
8acbf85f 22#include "wpa_auth.h"
a4f21109 23#include "ap_drv_ops.h"
bf65bc63
JM
24
25
4378fc14 26u32 hostapd_sta_flags_to_drv(u32 flags)
4c2ddda4
JM
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;
bb598c3b
AB
37 if (flags & WLAN_STA_AUTH)
38 res |= WPA_STA_AUTHENTICATED;
39 if (flags & WLAN_STA_ASSOC)
40 res |= WPA_STA_ASSOCIATED;
4c2ddda4
JM
41 return res;
42}
43
44
990b7b6f
JM
45static 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
56static 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
fb91db56 67int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
c2ff13c5
JM
68 struct wpabuf **beacon_ret,
69 struct wpabuf **proberesp_ret,
70 struct wpabuf **assocresp_ret)
bf65bc63 71{
c2ff13c5 72 struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
4b2a77ab 73 u8 buf[200], *pos;
c2ff13c5
JM
74
75 *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
76
39b97072
JM
77 pos = buf;
78 pos = hostapd_eid_time_adv(hapd, pos);
990b7b6f
JM
79 if (add_buf_data(&beacon, buf, pos - buf) < 0)
80 goto fail;
39b97072 81 pos = hostapd_eid_time_zone(hapd, pos);
990b7b6f
JM
82 if (add_buf_data(&proberesp, buf, pos - buf) < 0)
83 goto fail;
39b97072 84
a194b06c
JM
85 pos = buf;
86 pos = hostapd_eid_ext_capab(hapd, pos);
990b7b6f
JM
87 if (add_buf_data(&assocresp, buf, pos - buf) < 0)
88 goto fail;
a194b06c 89 pos = hostapd_eid_interworking(hapd, pos);
c7c178e1 90 pos = hostapd_eid_adv_proto(hapd, pos);
4b2a77ab 91 pos = hostapd_eid_roaming_consortium(hapd, pos);
990b7b6f
JM
92 if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
93 add_buf_data(&proberesp, buf, pos - buf) < 0)
94 goto fail;
a194b06c 95
347827ff 96#ifdef CONFIG_FST
990b7b6f
JM
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;
347827ff
AN
101#endif /* CONFIG_FST */
102
d5444aac
JM
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
990b7b6f
JM
110 if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
111 add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
112 goto fail;
b3db190f 113
c2af2afb 114#ifdef CONFIG_P2P
990b7b6f
JM
115 if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
116 add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
117 goto fail;
c2af2afb
JM
118#endif /* CONFIG_P2P */
119
dce044cc
JM
120#ifdef CONFIG_P2P_MANAGER
121 if (hapd->conf->p2p & P2P_MANAGE) {
c2ff13c5 122 if (wpabuf_resize(&beacon, 100) == 0) {
dce044cc 123 u8 *start, *p;
c2ff13c5 124 start = wpabuf_put(beacon, 0);
dce044cc 125 p = hostapd_eid_p2p_manage(hapd, start);
c2ff13c5 126 wpabuf_put(beacon, p - start);
dce044cc
JM
127 }
128
c2ff13c5 129 if (wpabuf_resize(&proberesp, 100) == 0) {
dce044cc 130 u8 *start, *p;
c2ff13c5 131 start = wpabuf_put(proberesp, 0);
dce044cc 132 p = hostapd_eid_p2p_manage(hapd, start);
c2ff13c5 133 wpabuf_put(proberesp, p - start);
dce044cc
JM
134 }
135 }
136#endif /* CONFIG_P2P_MANAGER */
137
c201f93a 138#ifdef CONFIG_WPS
c2ff13c5
JM
139 if (hapd->conf->wps_state) {
140 struct wpabuf *a = wps_build_assoc_resp_ie();
990b7b6f 141 add_buf(&assocresp, a);
c2ff13c5
JM
142 wpabuf_free(a);
143 }
c201f93a 144#endif /* CONFIG_WPS */
0e2e565a 145
dce044cc
JM
146#ifdef CONFIG_P2P_MANAGER
147 if (hapd->conf->p2p & P2P_MANAGE) {
c2ff13c5 148 if (wpabuf_resize(&assocresp, 100) == 0) {
dce044cc 149 u8 *start, *p;
c2ff13c5 150 start = wpabuf_put(assocresp, 0);
dce044cc 151 p = hostapd_eid_p2p_manage(hapd, start);
c2ff13c5 152 wpabuf_put(assocresp, p - start);
dce044cc
JM
153 }
154 }
155#endif /* CONFIG_P2P_MANAGER */
156
9675ce35
JM
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);
990b7b6f 161 add_buf(&assocresp, a);
9675ce35
JM
162 wpabuf_free(a);
163 }
164#endif /* CONFIG_WIFI_DISPLAY */
165
19a8ad99 166#ifdef CONFIG_HS20
990b7b6f
JM
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;
a14896e8
JM
171
172 pos = hostapd_eid_osen(hapd, buf);
990b7b6f
JM
173 if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
174 add_buf_data(&proberesp, buf, pos - buf) < 0)
175 goto fail;
19a8ad99
JK
176#endif /* CONFIG_HS20 */
177
fb9a1c3e 178#ifdef CONFIG_MBO
0f0aa2a6
AB
179 if (hapd->conf->mbo_enabled ||
180 OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
fb9a1c3e 181 pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
990b7b6f
JM
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;
fb9a1c3e
AS
186 }
187#endif /* CONFIG_MBO */
188
18e3e9c6
AP
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
990b7b6f
JM
196 add_buf(&beacon, hapd->conf->vendor_elements);
197 add_buf(&proberesp, hapd->conf->vendor_elements);
a9112270 198 add_buf(&assocresp, hapd->conf->assocresp_elements);
b084df8b 199
c2ff13c5
JM
200 *beacon_ret = beacon;
201 *proberesp_ret = proberesp;
202 *assocresp_ret = assocresp;
203
fb91db56 204 return 0;
c2ff13c5
JM
205
206fail:
207 wpabuf_free(beacon);
208 wpabuf_free(proberesp);
209 wpabuf_free(assocresp);
210 return -1;
fb91db56
JM
211}
212
b3db190f 213
c2ff13c5
JM
214void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
215 struct wpabuf *beacon,
fb91db56
JM
216 struct wpabuf *proberesp,
217 struct wpabuf *assocresp)
218{
c2ff13c5
JM
219 wpabuf_free(beacon);
220 wpabuf_free(proberesp);
0e2e565a 221 wpabuf_free(assocresp);
fb91db56
JM
222}
223
224
1de07100
AKP
225int 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
fb91db56
JM
234int 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);
c2af2afb 250
b3db190f 251 return ret;
bf65bc63
JM
252}
253
254
0e8a96a9
JM
255int hostapd_set_authorized(struct hostapd_data *hapd,
256 struct sta_info *sta, int authorized)
45cefa0b
JM
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
0e8a96a9 271int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
4c2ddda4
JM
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;
ef580012
JM
276 if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
277 sta->auth_alg == WLAN_AUTH_FT) &&
4c2ddda4
JM
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
0e8a96a9
JM
287int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
288 int enabled)
010401fe
JM
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;
e19c1d2c
JM
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;
010401fe
JM
306 params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
307 params.rsn_preauth = hapd->conf->rsn_preauth;
a1ca0292
MP
308#ifdef CONFIG_IEEE80211W
309 params.ieee80211w = hapd->conf->ieee80211w;
310#endif /* CONFIG_IEEE80211W */
010401fe
JM
311 }
312 return hostapd_set_ieee8021x(hapd, &params);
313}
314
315
0e8a96a9 316int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
36592d31 317{
f3585c8a
JM
318 char force_ifname[IFNAMSIZ];
319 u8 if_addr[ETH_ALEN];
e926bcff 320 return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
2aec4f3c 321 NULL, NULL, force_ifname, if_addr, NULL, 0);
36592d31
JM
322}
323
0e8a96a9
JM
324
325int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
36592d31
JM
326{
327 return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
328}
329
330
69dd2967
SM
331int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
332 const u8 *addr, int aid, int val)
bdee6fce 333{
d38ae2ea
FF
334 const char *bridge = NULL;
335
bdee6fce 336 if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
69dd2967 337 return -1;
d38ae2ea
FF
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;
0e8a96a9 342 return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
69dd2967 343 bridge, ifname_wds);
bdee6fce
JM
344}
345
346
a52eba0f
SP
347int 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
356int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
357 u16 seq, u16 status, const u8 *ie, size_t len)
358{
6b128fb2 359 struct wpa_driver_sta_auth_params params;
8acbf85f
JM
360#ifdef CONFIG_FILS
361 struct sta_info *sta;
362#endif /* CONFIG_FILS */
6b128fb2 363
a52eba0f
SP
364 if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
365 return 0;
6b128fb2
JM
366
367 os_memset(&params, 0, sizeof(params));
368
8acbf85f
JM
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
6b128fb2
JM
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);
a52eba0f
SP
397}
398
399
400int 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
0e8a96a9
JM
410int 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,
d83ab1fe 414 const struct ieee80211_ht_capabilities *ht_capab,
a9a1d0f0 415 const struct ieee80211_vht_capabilities *vht_capab,
78d35b16
JC
416 const struct ieee80211_he_capabilities *he_capab,
417 size_t he_capab_len,
ae33239c
AB
418 u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
419 int set)
2ce86d9d
JM
420{
421 struct hostapd_sta_add_params params;
422
423 if (hapd->driver == NULL)
424 return 0;
425 if (hapd->driver->sta_add == NULL)
426 return 0;
427
428 os_memset(&params, 0, sizeof(params));
429 params.addr = addr;
430 params.aid = aid;
431 params.capability = capability;
432 params.supp_rates = supp_rates;
433 params.supp_rates_len = supp_rates_len;
434 params.listen_interval = listen_interval;
435 params.ht_capabilities = ht_capab;
a9a1d0f0 436 params.vht_capabilities = vht_capab;
78d35b16
JC
437 params.he_capab = he_capab;
438 params.he_capab_len = he_capab_len;
8a458116
MK
439 params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
440 params.vht_opmode = vht_opmode;
d83ab1fe 441 params.flags = hostapd_sta_flags_to_drv(flags);
5d061637 442 params.qosinfo = qosinfo;
ae33239c 443 params.support_p2p_ps = supp_p2p_ps;
bb598c3b 444 params.set = set;
62847751 445 return hapd->driver->sta_add(hapd->drv_priv, &params);
2ce86d9d
JM
446}
447
448
a52eba0f
SP
449int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
450 u8 *tspec_ie, size_t tspec_ielen)
451{
452 if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
453 return 0;
454 return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
455 tspec_ielen);
456}
457
458
8b06c1ed
JM
459int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
460{
461 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
462 return 0;
d5dd016a 463 return hapd->driver->set_privacy(hapd->drv_priv, enabled);
8b06c1ed
JM
464}
465
466
467int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
468 size_t elem_len)
469{
470 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
471 return 0;
aa484516 472 return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
8b06c1ed
JM
473}
474
475
476int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
477{
478 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
479 return 0;
8709de1a 480 return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
8b06c1ed
JM
481}
482
483
484int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
485{
486 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
487 return 0;
8709de1a 488 return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
8b06c1ed
JM
489}
490
491
492int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
a2e40bb6 493 const char *ifname, const u8 *addr, void *bss_ctx,
e17a2477 494 void **drv_priv, char *force_ifname, u8 *if_addr,
2aec4f3c 495 const char *bridge, int use_existing)
8b06c1ed
JM
496{
497 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
498 return -1;
7ab68865 499 return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
e17a2477 500 bss_ctx, drv_priv, force_ifname, if_addr,
d8a3b66d 501 bridge, use_existing, 1);
8b06c1ed
JM
502}
503
504
505int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
506 const char *ifname)
507{
71cdf6b6
JM
508 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
509 hapd->driver->if_remove == NULL)
8b06c1ed
JM
510 return -1;
511 return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
512}
6e6e8c31
JM
513
514
515int hostapd_set_ieee8021x(struct hostapd_data *hapd,
516 struct wpa_bss_params *params)
517{
518 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
519 return 0;
520 return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
521}
522
523
524int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
525 const u8 *addr, int idx, u8 *seq)
526{
527 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
528 return 0;
529 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
530 seq);
531}
532
533
534int hostapd_flush(struct hostapd_data *hapd)
535{
536 if (hapd->driver == NULL || hapd->driver->flush == NULL)
537 return 0;
538 return hapd->driver->flush(hapd->drv_priv);
539}
540
541
4e8f31e2
JM
542int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
543 int freq, int channel, int ht_enabled, int vht_enabled,
88005ee9 544 int he_enabled,
b04e4308 545 int sec_channel_offset, int oper_chwidth,
72c753d7
JD
546 int center_segment0, int center_segment1)
547{
548 struct hostapd_freq_params data;
549
550 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
88005ee9 551 vht_enabled, he_enabled, sec_channel_offset,
b04e4308 552 oper_chwidth,
7f0303d5 553 center_segment0, center_segment1,
e9b783d5 554 hapd->iface->current_mode ?
88005ee9
JC
555 hapd->iface->current_mode->vht_capab : 0,
556 &hapd->iface->current_mode->he_capab))
72c753d7
JD
557 return -1;
558
fa476336
JB
559 if (hapd->driver == NULL)
560 return 0;
561 if (hapd->driver->set_freq == NULL)
562 return 0;
6e6e8c31
JM
563 return hapd->driver->set_freq(hapd->drv_priv, &data);
564}
565
566int hostapd_set_rts(struct hostapd_data *hapd, int rts)
567{
568 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
569 return 0;
570 return hapd->driver->set_rts(hapd->drv_priv, rts);
571}
572
573
574int hostapd_set_frag(struct hostapd_data *hapd, int frag)
575{
576 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
577 return 0;
578 return hapd->driver->set_frag(hapd->drv_priv, frag);
579}
580
581
582int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
583 int total_flags, int flags_or, int flags_and)
584{
585 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
586 return 0;
3234cba4 587 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
6e6e8c31
JM
588 flags_or, flags_and);
589}
590
591
6720b948
THJ
592int hostapd_sta_set_airtime_weight(struct hostapd_data *hapd, const u8 *addr,
593 unsigned int weight)
594{
595 if (!hapd->driver || !hapd->driver->sta_set_airtime_weight)
596 return 0;
597 return hapd->driver->sta_set_airtime_weight(hapd->drv_priv, addr,
598 weight);
599}
600
601
6e6e8c31
JM
602int hostapd_set_country(struct hostapd_data *hapd, const char *country)
603{
604 if (hapd->driver == NULL ||
605 hapd->driver->set_country == NULL)
606 return 0;
607 return hapd->driver->set_country(hapd->drv_priv, country);
608}
609
610
6e6e8c31
JM
611int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
612 int cw_min, int cw_max, int burst_time)
613{
614 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
615 return 0;
616 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
617 cw_min, cw_max, burst_time);
618}
619
620
6e6e8c31
JM
621struct hostapd_hw_modes *
622hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
aa56e36d 623 u16 *flags, u8 *dfs_domain)
6e6e8c31
JM
624{
625 if (hapd->driver == NULL ||
626 hapd->driver->get_hw_feature_data == NULL)
627 return NULL;
628 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
aa56e36d 629 flags, dfs_domain);
6e6e8c31
JM
630}
631
632
633int hostapd_driver_commit(struct hostapd_data *hapd)
634{
635 if (hapd->driver == NULL || hapd->driver->commit == NULL)
636 return 0;
637 return hapd->driver->commit(hapd->drv_priv);
638}
639
640
6e6e8c31
JM
641int hostapd_drv_none(struct hostapd_data *hapd)
642{
643 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
644}
645
646
647int hostapd_driver_scan(struct hostapd_data *hapd,
648 struct wpa_driver_scan_params *params)
649{
650 if (hapd->driver && hapd->driver->scan2)
651 return hapd->driver->scan2(hapd->drv_priv, params);
652 return -1;
653}
654
655
656struct wpa_scan_results * hostapd_driver_get_scan_results(
657 struct hostapd_data *hapd)
658{
659 if (hapd->driver && hapd->driver->get_scan_results2)
660 return hapd->driver->get_scan_results2(hapd->drv_priv);
661 return NULL;
662}
aefb53bd
JM
663
664
665int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
666 int duration)
667{
668 if (hapd->driver && hapd->driver->set_noa)
669 return hapd->driver->set_noa(hapd->drv_priv, count, start,
670 duration);
671 return -1;
672}
7392f11e
JM
673
674
675int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
676 enum wpa_alg alg, const u8 *addr,
677 int key_idx, int set_tx,
678 const u8 *seq, size_t seq_len,
679 const u8 *key, size_t key_len)
680{
681 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
682 return 0;
683 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
684 key_idx, set_tx, seq, seq_len, key,
685 key_len);
686}
687
688
689int hostapd_drv_send_mlme(struct hostapd_data *hapd,
8cfa3527 690 const void *msg, size_t len, int noack)
7392f11e 691{
1f3b8b4e 692 if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
7392f11e 693 return 0;
2d3943ce
AO
694 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
695 NULL, 0);
696}
697
698
699int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
700 const void *msg, size_t len, int noack,
701 const u16 *csa_offs, size_t csa_offs_len)
702{
703 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
704 return 0;
705 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
706 csa_offs, csa_offs_len);
7392f11e
JM
707}
708
709
710int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
711 const u8 *addr, int reason)
712{
1f3b8b4e 713 if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
7392f11e
JM
714 return 0;
715 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
716 reason);
717}
718
719
720int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
721 const u8 *addr, int reason)
722{
1f3b8b4e 723 if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
7392f11e
JM
724 return 0;
725 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
726 reason);
727}
fb80e86e
JK
728
729
a884be9d
XC
730int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
731 const u8 *peer, u8 *buf, u16 *buf_len)
732{
733 if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
47768978 734 return -1;
a884be9d
XC
735 return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
736 buf_len);
737}
738
739
fb80e86e
JK
740int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
741 unsigned int wait, const u8 *dst, const u8 *data,
742 size_t len)
78a36327
JM
743{
744 const u8 *bssid;
745 const u8 wildcard_bssid[ETH_ALEN] = {
746 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
747 };
748
1f3b8b4e 749 if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
78a36327
JM
750 return 0;
751 bssid = hapd->own_addr;
752 if (!is_multicast_ether_addr(dst) &&
753 len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
754 struct sta_info *sta;
755
756 /*
757 * Public Action frames to a STA that is not a member of the BSS
758 * shall use wildcard BSSID value.
759 */
760 sta = ap_get_sta(hapd, dst);
761 if (!sta || !(sta->flags & WLAN_STA_ASSOC))
762 bssid = wildcard_bssid;
92b6e0c5
AP
763 } else if (is_broadcast_ether_addr(dst) &&
764 len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
765 /*
766 * The only current use case of Public Action frames with
767 * broadcast destination address is DPP PKEX. That case is
768 * directing all devices and not just the STAs within the BSS,
769 * so have to use the wildcard BSSID value.
770 */
771 bssid = wildcard_bssid;
78a36327
JM
772 }
773 return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
774 hapd->own_addr, bssid, data, len, 0);
775}
776
777
778int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
779 unsigned int freq,
780 unsigned int wait, const u8 *dst,
781 const u8 *data, size_t len)
fb80e86e
JK
782{
783 if (hapd->driver == NULL || hapd->driver->send_action == NULL)
784 return 0;
785 return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
786 hapd->own_addr, hapd->own_addr, data,
787 len, 0);
788}
e76da505 789
dc036d9e 790
4e8f31e2
JM
791int hostapd_start_dfs_cac(struct hostapd_iface *iface,
792 enum hostapd_hw_mode mode, int freq,
58b73e3d 793 int channel, int ht_enabled, int vht_enabled,
88005ee9 794 int he_enabled,
b04e4308 795 int sec_channel_offset, int oper_chwidth,
58b73e3d 796 int center_segment0, int center_segment1)
e76da505 797{
dc036d9e 798 struct hostapd_data *hapd = iface->bss[0];
04e8003c 799 struct hostapd_freq_params data;
2e946249 800 int res;
04e8003c 801
e76da505
JD
802 if (!hapd->driver || !hapd->driver->start_dfs_cac)
803 return 0;
804
dc036d9e 805 if (!iface->conf->ieee80211h) {
e76da505
JD
806 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
807 "is not enabled");
808 return -1;
809 }
810
58b73e3d 811 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
88005ee9 812 vht_enabled, he_enabled, sec_channel_offset,
b04e4308 813 oper_chwidth, center_segment0,
7f0303d5 814 center_segment1,
88005ee9
JC
815 iface->current_mode->vht_capab,
816 &iface->current_mode->he_capab)) {
1f374834 817 wpa_printf(MSG_ERROR, "Can't set freq params");
04e8003c 818 return -1;
1f374834 819 }
04e8003c 820
2e946249 821 res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
bbbacbf2 822 if (!res) {
dc036d9e 823 iface->cac_started = 1;
bbbacbf2
JD
824 os_get_reltime(&iface->dfs_cac_start);
825 }
2e946249
JD
826
827 return res;
e76da505 828}
c551700f
KP
829
830
831int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
832 const u8 *qos_map_set, u8 qos_map_set_len)
833{
1f3b8b4e 834 if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
c551700f
KP
835 return 0;
836 return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
837 qos_map_set_len);
838}
16689c7c
PX
839
840
d0cdccd3
PX
841static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
842 struct hostapd_hw_modes *mode,
843 int acs_ch_list_all,
844 int **freq_list)
845{
846 int i;
847
848 for (i = 0; i < mode->num_channels; i++) {
849 struct hostapd_channel_data *chan = &mode->channels[i];
850
851 if ((acs_ch_list_all ||
852 freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
853 chan->chan)) &&
2d18ab40
SD
854 !(chan->flag & HOSTAPD_CHAN_DISABLED) &&
855 !(hapd->iface->conf->acs_exclude_dfs &&
856 (chan->flag & HOSTAPD_CHAN_RADAR)))
d0cdccd3
PX
857 int_array_add_unique(freq_list, chan->freq);
858 }
859}
860
861
cc9a2575
KV
862void hostapd_get_ext_capa(struct hostapd_iface *iface)
863{
864 struct hostapd_data *hapd = iface->bss[0];
865
866 if (!hapd->driver || !hapd->driver->get_ext_capab)
867 return;
868
869 hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
870 &iface->extended_capa,
871 &iface->extended_capa_mask,
872 &iface->extended_capa_len);
873}
874
875
16689c7c
PX
876int hostapd_drv_do_acs(struct hostapd_data *hapd)
877{
878 struct drv_acs_params params;
857d9422
MM
879 int ret, i, acs_ch_list_all = 0;
880 u8 *channels = NULL;
881 unsigned int num_channels = 0;
882 struct hostapd_hw_modes *mode;
d0cdccd3 883 int *freq_list = NULL;
16689c7c
PX
884
885 if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
886 return 0;
857d9422 887
16689c7c
PX
888 os_memset(&params, 0, sizeof(params));
889 params.hw_mode = hapd->iface->conf->hw_mode;
857d9422
MM
890
891 /*
892 * If no chanlist config parameter is provided, include all enabled
893 * channels of the selected hw_mode.
894 */
895 if (!hapd->iface->conf->acs_ch_list.num)
896 acs_ch_list_all = 1;
897
898 mode = hapd->iface->current_mode;
d0cdccd3
PX
899 if (mode) {
900 channels = os_malloc(mode->num_channels);
901 if (channels == NULL)
902 return -1;
903
904 for (i = 0; i < mode->num_channels; i++) {
905 struct hostapd_channel_data *chan = &mode->channels[i];
906 if (!acs_ch_list_all &&
907 !freq_range_list_includes(
908 &hapd->iface->conf->acs_ch_list,
909 chan->chan))
910 continue;
2d18ab40
SD
911 if (hapd->iface->conf->acs_exclude_dfs &&
912 (chan->flag & HOSTAPD_CHAN_RADAR))
913 continue;
d0cdccd3
PX
914 if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
915 channels[num_channels++] = chan->chan;
916 int_array_add_unique(&freq_list, chan->freq);
917 }
918 }
919 } else {
920 for (i = 0; i < hapd->iface->num_hw_features; i++) {
921 mode = &hapd->iface->hw_features[i];
922 hostapd_get_hw_mode_any_channels(hapd, mode,
923 acs_ch_list_all,
924 &freq_list);
925 }
857d9422
MM
926 }
927
928 params.ch_list = channels;
929 params.ch_list_len = num_channels;
d0cdccd3 930 params.freq_list = freq_list;
857d9422 931
16689c7c 932 params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
5085ffb8 933 params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
16689c7c 934 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
857d9422
MM
935 params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
936 params.ch_width = 20;
937 if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
938 params.ch_width = 40;
939
c6b7ac07 940 /* Note: VHT20 is defined by combination of ht_capab & oper_chwidth
857d9422 941 */
1d2c45ec
JC
942 if ((hapd->iface->conf->ieee80211ax ||
943 hapd->iface->conf->ieee80211ac) &&
944 params.ht40_enabled) {
c6b7ac07
JC
945 u8 oper_chwidth = hostapd_get_oper_chwidth(hapd->iface->conf);
946
947 if (oper_chwidth == CHANWIDTH_80MHZ)
857d9422 948 params.ch_width = 80;
c6b7ac07
JC
949 else if (oper_chwidth == CHANWIDTH_160MHZ ||
950 oper_chwidth == CHANWIDTH_80P80MHZ)
857d9422
MM
951 params.ch_width = 160;
952 }
953
954 ret = hapd->driver->do_acs(hapd->drv_priv, &params);
955 os_free(channels);
956
957 return ret;
16689c7c 958}