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