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