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