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