2 * hostapd - Driver operations
3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/hw_features_common.h"
17 #include "ieee802_11.h"
19 #include "ap_config.h"
20 #include "p2p_hostapd.h"
22 #include "ap_drv_ops.h"
25 u32 hostapd_sta_flags_to_drv(u32 flags)
28 if (flags & WLAN_STA_AUTHORIZED)
29 res |= WPA_STA_AUTHORIZED;
30 if (flags & WLAN_STA_WMM)
32 if (flags & WLAN_STA_SHORT_PREAMBLE)
33 res |= WPA_STA_SHORT_PREAMBLE;
34 if (flags & WLAN_STA_MFP)
36 if (flags & WLAN_STA_AUTH)
37 res |= WPA_STA_AUTHENTICATED;
38 if (flags & WLAN_STA_ASSOC)
39 res |= WPA_STA_ASSOCIATED;
44 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
45 struct wpabuf **beacon_ret,
46 struct wpabuf **proberesp_ret,
47 struct wpabuf **assocresp_ret)
49 struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
52 *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
55 pos = hostapd_eid_time_adv(hapd, pos);
57 if (wpabuf_resize(&beacon, pos - buf) != 0)
59 wpabuf_put_data(beacon, buf, pos - buf);
61 pos = hostapd_eid_time_zone(hapd, pos);
63 if (wpabuf_resize(&proberesp, pos - buf) != 0)
65 wpabuf_put_data(proberesp, buf, pos - buf);
69 pos = hostapd_eid_ext_capab(hapd, pos);
71 if (wpabuf_resize(&assocresp, pos - buf) != 0)
73 wpabuf_put_data(assocresp, buf, pos - buf);
75 pos = hostapd_eid_interworking(hapd, pos);
76 pos = hostapd_eid_adv_proto(hapd, pos);
77 pos = hostapd_eid_roaming_consortium(hapd, pos);
79 if (wpabuf_resize(&beacon, pos - buf) != 0)
81 wpabuf_put_data(beacon, buf, pos - buf);
83 if (wpabuf_resize(&proberesp, pos - buf) != 0)
85 wpabuf_put_data(proberesp, buf, pos - buf);
89 if (hapd->iface->fst_ies) {
90 size_t add = wpabuf_len(hapd->iface->fst_ies);
92 if (wpabuf_resize(&beacon, add) < 0)
94 wpabuf_put_buf(beacon, hapd->iface->fst_ies);
95 if (wpabuf_resize(&proberesp, add) < 0)
97 wpabuf_put_buf(proberesp, hapd->iface->fst_ies);
98 if (wpabuf_resize(&assocresp, add) < 0)
100 wpabuf_put_buf(assocresp, hapd->iface->fst_ies);
102 #endif /* CONFIG_FST */
104 if (hapd->wps_beacon_ie) {
105 if (wpabuf_resize(&beacon, wpabuf_len(hapd->wps_beacon_ie)) <
108 wpabuf_put_buf(beacon, hapd->wps_beacon_ie);
111 if (hapd->wps_probe_resp_ie) {
112 if (wpabuf_resize(&proberesp,
113 wpabuf_len(hapd->wps_probe_resp_ie)) < 0)
115 wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie);
119 if (hapd->p2p_beacon_ie) {
120 if (wpabuf_resize(&beacon, wpabuf_len(hapd->p2p_beacon_ie)) <
123 wpabuf_put_buf(beacon, hapd->p2p_beacon_ie);
126 if (hapd->p2p_probe_resp_ie) {
127 if (wpabuf_resize(&proberesp,
128 wpabuf_len(hapd->p2p_probe_resp_ie)) < 0)
130 wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie);
132 #endif /* CONFIG_P2P */
134 #ifdef CONFIG_P2P_MANAGER
135 if (hapd->conf->p2p & P2P_MANAGE) {
136 if (wpabuf_resize(&beacon, 100) == 0) {
138 start = wpabuf_put(beacon, 0);
139 p = hostapd_eid_p2p_manage(hapd, start);
140 wpabuf_put(beacon, p - start);
143 if (wpabuf_resize(&proberesp, 100) == 0) {
145 start = wpabuf_put(proberesp, 0);
146 p = hostapd_eid_p2p_manage(hapd, start);
147 wpabuf_put(proberesp, p - start);
150 #endif /* CONFIG_P2P_MANAGER */
153 if (hapd->conf->wps_state) {
154 struct wpabuf *a = wps_build_assoc_resp_ie();
155 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
156 wpabuf_put_buf(assocresp, a);
159 #endif /* CONFIG_WPS */
161 #ifdef CONFIG_P2P_MANAGER
162 if (hapd->conf->p2p & P2P_MANAGE) {
163 if (wpabuf_resize(&assocresp, 100) == 0) {
165 start = wpabuf_put(assocresp, 0);
166 p = hostapd_eid_p2p_manage(hapd, start);
167 wpabuf_put(assocresp, p - start);
170 #endif /* CONFIG_P2P_MANAGER */
172 #ifdef CONFIG_WIFI_DISPLAY
173 if (hapd->p2p_group) {
175 a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
176 if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
177 wpabuf_put_buf(assocresp, a);
180 #endif /* CONFIG_WIFI_DISPLAY */
184 pos = hostapd_eid_hs20_indication(hapd, pos);
186 if (wpabuf_resize(&beacon, pos - buf) != 0)
188 wpabuf_put_data(beacon, buf, pos - buf);
190 if (wpabuf_resize(&proberesp, pos - buf) != 0)
192 wpabuf_put_data(proberesp, buf, pos - buf);
195 pos = hostapd_eid_osen(hapd, buf);
197 if (wpabuf_resize(&beacon, pos - buf) != 0)
199 wpabuf_put_data(beacon, buf, pos - buf);
201 if (wpabuf_resize(&proberesp, pos - buf) != 0)
203 wpabuf_put_data(proberesp, buf, pos - buf);
205 #endif /* CONFIG_HS20 */
207 if (hapd->conf->vendor_elements) {
208 size_t add = wpabuf_len(hapd->conf->vendor_elements);
209 if (wpabuf_resize(&beacon, add) == 0)
210 wpabuf_put_buf(beacon, hapd->conf->vendor_elements);
211 if (wpabuf_resize(&proberesp, add) == 0)
212 wpabuf_put_buf(proberesp, hapd->conf->vendor_elements);
215 *beacon_ret = beacon;
216 *proberesp_ret = proberesp;
217 *assocresp_ret = assocresp;
223 wpabuf_free(proberesp);
224 wpabuf_free(assocresp);
229 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
230 struct wpabuf *beacon,
231 struct wpabuf *proberesp,
232 struct wpabuf *assocresp)
235 wpabuf_free(proberesp);
236 wpabuf_free(assocresp);
240 int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
242 if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
245 return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
249 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
251 struct wpabuf *beacon, *proberesp, *assocresp;
254 if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
257 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
261 ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
264 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
270 int hostapd_set_authorized(struct hostapd_data *hapd,
271 struct sta_info *sta, int authorized)
274 return hostapd_sta_set_flags(hapd, sta->addr,
275 hostapd_sta_flags_to_drv(
277 WPA_STA_AUTHORIZED, ~0);
280 return hostapd_sta_set_flags(hapd, sta->addr,
281 hostapd_sta_flags_to_drv(sta->flags),
282 0, ~WPA_STA_AUTHORIZED);
286 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
288 int set_flags, total_flags, flags_and, flags_or;
289 total_flags = hostapd_sta_flags_to_drv(sta->flags);
290 set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
291 if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
292 sta->auth_alg == WLAN_AUTH_FT) &&
293 sta->flags & WLAN_STA_AUTHORIZED)
294 set_flags |= WPA_STA_AUTHORIZED;
295 flags_or = total_flags & set_flags;
296 flags_and = total_flags | ~set_flags;
297 return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
298 flags_or, flags_and);
302 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
305 struct wpa_bss_params params;
306 os_memset(¶ms, 0, sizeof(params));
307 params.ifname = ifname;
308 params.enabled = enabled;
310 params.wpa = hapd->conf->wpa;
311 params.ieee802_1x = hapd->conf->ieee802_1x;
312 params.wpa_group = hapd->conf->wpa_group;
313 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
314 (WPA_PROTO_WPA | WPA_PROTO_RSN))
315 params.wpa_pairwise = hapd->conf->wpa_pairwise |
316 hapd->conf->rsn_pairwise;
317 else if (hapd->conf->wpa & WPA_PROTO_RSN)
318 params.wpa_pairwise = hapd->conf->rsn_pairwise;
319 else if (hapd->conf->wpa & WPA_PROTO_WPA)
320 params.wpa_pairwise = hapd->conf->wpa_pairwise;
321 params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
322 params.rsn_preauth = hapd->conf->rsn_preauth;
323 #ifdef CONFIG_IEEE80211W
324 params.ieee80211w = hapd->conf->ieee80211w;
325 #endif /* CONFIG_IEEE80211W */
327 return hostapd_set_ieee8021x(hapd, ¶ms);
331 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
333 char force_ifname[IFNAMSIZ];
334 u8 if_addr[ETH_ALEN];
335 return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
336 NULL, NULL, force_ifname, if_addr, NULL, 0);
340 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
342 return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
346 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
347 const u8 *addr, int aid, int val)
349 const char *bridge = NULL;
351 if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
353 if (hapd->conf->wds_bridge[0])
354 bridge = hapd->conf->wds_bridge;
355 else if (hapd->conf->bridge[0])
356 bridge = hapd->conf->bridge;
357 return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
362 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
365 if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
367 return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
371 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
372 u16 seq, u16 status, const u8 *ie, size_t len)
374 if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
376 return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr,
377 seq, status, ie, len);
381 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
382 int reassoc, u16 status, const u8 *ie, size_t len)
384 if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
386 return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
387 reassoc, status, ie, len);
391 int hostapd_sta_add(struct hostapd_data *hapd,
392 const u8 *addr, u16 aid, u16 capability,
393 const u8 *supp_rates, size_t supp_rates_len,
395 const struct ieee80211_ht_capabilities *ht_capab,
396 const struct ieee80211_vht_capabilities *vht_capab,
397 u32 flags, u8 qosinfo, u8 vht_opmode, int set)
399 struct hostapd_sta_add_params params;
401 if (hapd->driver == NULL)
403 if (hapd->driver->sta_add == NULL)
406 os_memset(¶ms, 0, sizeof(params));
409 params.capability = capability;
410 params.supp_rates = supp_rates;
411 params.supp_rates_len = supp_rates_len;
412 params.listen_interval = listen_interval;
413 params.ht_capabilities = ht_capab;
414 params.vht_capabilities = vht_capab;
415 params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
416 params.vht_opmode = vht_opmode;
417 params.flags = hostapd_sta_flags_to_drv(flags);
418 params.qosinfo = qosinfo;
420 return hapd->driver->sta_add(hapd->drv_priv, ¶ms);
424 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
425 u8 *tspec_ie, size_t tspec_ielen)
427 if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
429 return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
434 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
436 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
438 return hapd->driver->set_privacy(hapd->drv_priv, enabled);
442 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
445 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
447 return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
451 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
453 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
455 return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
459 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
461 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
463 return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
467 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
468 const char *ifname, const u8 *addr, void *bss_ctx,
469 void **drv_priv, char *force_ifname, u8 *if_addr,
470 const char *bridge, int use_existing)
472 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
474 return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
475 bss_ctx, drv_priv, force_ifname, if_addr,
476 bridge, use_existing, 1);
480 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
483 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
484 hapd->driver->if_remove == NULL)
486 return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
490 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
491 struct wpa_bss_params *params)
493 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
495 return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
499 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
500 const u8 *addr, int idx, u8 *seq)
502 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
504 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
509 int hostapd_flush(struct hostapd_data *hapd)
511 if (hapd->driver == NULL || hapd->driver->flush == NULL)
513 return hapd->driver->flush(hapd->drv_priv);
517 int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
518 int freq, int channel, int ht_enabled, int vht_enabled,
519 int sec_channel_offset, int vht_oper_chwidth,
520 int center_segment0, int center_segment1)
522 struct hostapd_freq_params data;
524 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
525 vht_enabled, sec_channel_offset,
527 center_segment0, center_segment1,
528 hapd->iface->current_mode ?
529 hapd->iface->current_mode->vht_capab : 0))
532 if (hapd->driver == NULL)
534 if (hapd->driver->set_freq == NULL)
536 return hapd->driver->set_freq(hapd->drv_priv, &data);
539 int hostapd_set_rts(struct hostapd_data *hapd, int rts)
541 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
543 return hapd->driver->set_rts(hapd->drv_priv, rts);
547 int hostapd_set_frag(struct hostapd_data *hapd, int frag)
549 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
551 return hapd->driver->set_frag(hapd->drv_priv, frag);
555 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
556 int total_flags, int flags_or, int flags_and)
558 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
560 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
561 flags_or, flags_and);
565 int hostapd_set_country(struct hostapd_data *hapd, const char *country)
567 if (hapd->driver == NULL ||
568 hapd->driver->set_country == NULL)
570 return hapd->driver->set_country(hapd->drv_priv, country);
574 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
575 int cw_min, int cw_max, int burst_time)
577 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
579 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
580 cw_min, cw_max, burst_time);
584 struct hostapd_hw_modes *
585 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
588 if (hapd->driver == NULL ||
589 hapd->driver->get_hw_feature_data == NULL)
591 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
596 int hostapd_driver_commit(struct hostapd_data *hapd)
598 if (hapd->driver == NULL || hapd->driver->commit == NULL)
600 return hapd->driver->commit(hapd->drv_priv);
604 int hostapd_drv_none(struct hostapd_data *hapd)
606 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
610 int hostapd_driver_scan(struct hostapd_data *hapd,
611 struct wpa_driver_scan_params *params)
613 if (hapd->driver && hapd->driver->scan2)
614 return hapd->driver->scan2(hapd->drv_priv, params);
619 struct wpa_scan_results * hostapd_driver_get_scan_results(
620 struct hostapd_data *hapd)
622 if (hapd->driver && hapd->driver->get_scan_results2)
623 return hapd->driver->get_scan_results2(hapd->drv_priv);
628 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
631 if (hapd->driver && hapd->driver->set_noa)
632 return hapd->driver->set_noa(hapd->drv_priv, count, start,
638 int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
639 enum wpa_alg alg, const u8 *addr,
640 int key_idx, int set_tx,
641 const u8 *seq, size_t seq_len,
642 const u8 *key, size_t key_len)
644 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
646 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
647 key_idx, set_tx, seq, seq_len, key,
652 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
653 const void *msg, size_t len, int noack)
655 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
657 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
662 int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
663 const void *msg, size_t len, int noack,
664 const u16 *csa_offs, size_t csa_offs_len)
666 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
668 return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
669 csa_offs, csa_offs_len);
673 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
674 const u8 *addr, int reason)
676 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
678 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
683 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
684 const u8 *addr, int reason)
686 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
688 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
693 int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
694 const u8 *peer, u8 *buf, u16 *buf_len)
696 if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
698 return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
703 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
704 unsigned int wait, const u8 *dst, const u8 *data,
707 if (hapd->driver == NULL || hapd->driver->send_action == NULL)
709 return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
710 hapd->own_addr, hapd->own_addr, data,
715 int hostapd_start_dfs_cac(struct hostapd_iface *iface,
716 enum hostapd_hw_mode mode, int freq,
717 int channel, int ht_enabled, int vht_enabled,
718 int sec_channel_offset, int vht_oper_chwidth,
719 int center_segment0, int center_segment1)
721 struct hostapd_data *hapd = iface->bss[0];
722 struct hostapd_freq_params data;
725 if (!hapd->driver || !hapd->driver->start_dfs_cac)
728 if (!iface->conf->ieee80211h) {
729 wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
734 if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
735 vht_enabled, sec_channel_offset,
736 vht_oper_chwidth, center_segment0,
738 iface->current_mode->vht_capab)) {
739 wpa_printf(MSG_ERROR, "Can't set freq params");
743 res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
745 iface->cac_started = 1;
746 os_get_reltime(&iface->dfs_cac_start);
753 int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
754 const u8 *qos_map_set, u8 qos_map_set_len)
756 if (hapd->driver == NULL || hapd->driver->set_qos_map == NULL)
758 return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
763 static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
764 struct hostapd_hw_modes *mode,
770 for (i = 0; i < mode->num_channels; i++) {
771 struct hostapd_channel_data *chan = &mode->channels[i];
773 if ((acs_ch_list_all ||
774 freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
776 !(chan->flag & HOSTAPD_CHAN_DISABLED))
777 int_array_add_unique(freq_list, chan->freq);
782 int hostapd_drv_do_acs(struct hostapd_data *hapd)
784 struct drv_acs_params params;
785 int ret, i, acs_ch_list_all = 0;
787 unsigned int num_channels = 0;
788 struct hostapd_hw_modes *mode;
789 int *freq_list = NULL;
791 if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
794 os_memset(¶ms, 0, sizeof(params));
795 params.hw_mode = hapd->iface->conf->hw_mode;
798 * If no chanlist config parameter is provided, include all enabled
799 * channels of the selected hw_mode.
801 if (!hapd->iface->conf->acs_ch_list.num)
804 mode = hapd->iface->current_mode;
806 channels = os_malloc(mode->num_channels);
807 if (channels == NULL)
810 for (i = 0; i < mode->num_channels; i++) {
811 struct hostapd_channel_data *chan = &mode->channels[i];
812 if (!acs_ch_list_all &&
813 !freq_range_list_includes(
814 &hapd->iface->conf->acs_ch_list,
817 if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
818 channels[num_channels++] = chan->chan;
819 int_array_add_unique(&freq_list, chan->freq);
823 for (i = 0; i < hapd->iface->num_hw_features; i++) {
824 mode = &hapd->iface->hw_features[i];
825 hostapd_get_hw_mode_any_channels(hapd, mode,
831 params.ch_list = channels;
832 params.ch_list_len = num_channels;
833 params.freq_list = freq_list;
835 params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
836 params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
837 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
838 params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
839 params.ch_width = 20;
840 if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
841 params.ch_width = 40;
843 /* Note: VHT20 is defined by combination of ht_capab & vht_oper_chwidth
845 if (hapd->iface->conf->ieee80211ac && params.ht40_enabled) {
846 if (hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
847 params.ch_width = 80;
848 else if (hapd->iface->conf->vht_oper_chwidth ==
849 VHT_CHANWIDTH_160MHZ ||
850 hapd->iface->conf->vht_oper_chwidth ==
851 VHT_CHANWIDTH_80P80MHZ)
852 params.ch_width = 160;
855 ret = hapd->driver->do_acs(hapd->drv_priv, ¶ms);