13ff40c12SJohn Marino /*
23ff40c12SJohn Marino * hostapd - Driver operations
33ff40c12SJohn Marino * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
43ff40c12SJohn Marino *
53ff40c12SJohn Marino * This software may be distributed under the terms of the BSD license.
63ff40c12SJohn Marino * See README for more details.
73ff40c12SJohn Marino */
83ff40c12SJohn Marino
93ff40c12SJohn Marino #include "utils/includes.h"
103ff40c12SJohn Marino
113ff40c12SJohn Marino #include "utils/common.h"
123ff40c12SJohn Marino #include "common/ieee802_11_defs.h"
13*a1157835SDaniel Fojt #include "common/hw_features_common.h"
143ff40c12SJohn Marino #include "wps/wps.h"
153ff40c12SJohn Marino #include "p2p/p2p.h"
163ff40c12SJohn Marino #include "hostapd.h"
173ff40c12SJohn Marino #include "ieee802_11.h"
183ff40c12SJohn Marino #include "sta_info.h"
193ff40c12SJohn Marino #include "ap_config.h"
203ff40c12SJohn Marino #include "p2p_hostapd.h"
213ff40c12SJohn Marino #include "hs20.h"
22*a1157835SDaniel Fojt #include "wpa_auth.h"
233ff40c12SJohn Marino #include "ap_drv_ops.h"
243ff40c12SJohn Marino
253ff40c12SJohn Marino
hostapd_sta_flags_to_drv(u32 flags)263ff40c12SJohn Marino u32 hostapd_sta_flags_to_drv(u32 flags)
273ff40c12SJohn Marino {
283ff40c12SJohn Marino int res = 0;
293ff40c12SJohn Marino if (flags & WLAN_STA_AUTHORIZED)
303ff40c12SJohn Marino res |= WPA_STA_AUTHORIZED;
313ff40c12SJohn Marino if (flags & WLAN_STA_WMM)
323ff40c12SJohn Marino res |= WPA_STA_WMM;
333ff40c12SJohn Marino if (flags & WLAN_STA_SHORT_PREAMBLE)
343ff40c12SJohn Marino res |= WPA_STA_SHORT_PREAMBLE;
353ff40c12SJohn Marino if (flags & WLAN_STA_MFP)
363ff40c12SJohn Marino res |= WPA_STA_MFP;
37*a1157835SDaniel Fojt if (flags & WLAN_STA_AUTH)
38*a1157835SDaniel Fojt res |= WPA_STA_AUTHENTICATED;
39*a1157835SDaniel Fojt if (flags & WLAN_STA_ASSOC)
40*a1157835SDaniel Fojt res |= WPA_STA_ASSOCIATED;
413ff40c12SJohn Marino return res;
423ff40c12SJohn Marino }
433ff40c12SJohn Marino
443ff40c12SJohn Marino
add_buf(struct wpabuf ** dst,const struct wpabuf * src)45*a1157835SDaniel Fojt static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
46*a1157835SDaniel Fojt {
47*a1157835SDaniel Fojt if (!src)
48*a1157835SDaniel Fojt return 0;
49*a1157835SDaniel Fojt if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
50*a1157835SDaniel Fojt return -1;
51*a1157835SDaniel Fojt wpabuf_put_buf(*dst, src);
52*a1157835SDaniel Fojt return 0;
53*a1157835SDaniel Fojt }
54*a1157835SDaniel Fojt
55*a1157835SDaniel Fojt
add_buf_data(struct wpabuf ** dst,const u8 * data,size_t len)56*a1157835SDaniel Fojt static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
57*a1157835SDaniel Fojt {
58*a1157835SDaniel Fojt if (!data || !len)
59*a1157835SDaniel Fojt return 0;
60*a1157835SDaniel Fojt if (wpabuf_resize(dst, len) != 0)
61*a1157835SDaniel Fojt return -1;
62*a1157835SDaniel Fojt wpabuf_put_data(*dst, data, len);
63*a1157835SDaniel Fojt return 0;
64*a1157835SDaniel Fojt }
65*a1157835SDaniel Fojt
66*a1157835SDaniel Fojt
hostapd_build_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf ** beacon_ret,struct wpabuf ** proberesp_ret,struct wpabuf ** assocresp_ret)673ff40c12SJohn Marino int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
683ff40c12SJohn Marino struct wpabuf **beacon_ret,
693ff40c12SJohn Marino struct wpabuf **proberesp_ret,
703ff40c12SJohn Marino struct wpabuf **assocresp_ret)
713ff40c12SJohn Marino {
723ff40c12SJohn Marino struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
733ff40c12SJohn Marino u8 buf[200], *pos;
743ff40c12SJohn Marino
753ff40c12SJohn Marino *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
763ff40c12SJohn Marino
773ff40c12SJohn Marino pos = buf;
783ff40c12SJohn Marino pos = hostapd_eid_time_adv(hapd, pos);
79*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0)
803ff40c12SJohn Marino goto fail;
813ff40c12SJohn Marino pos = hostapd_eid_time_zone(hapd, pos);
82*a1157835SDaniel Fojt if (add_buf_data(&proberesp, buf, pos - buf) < 0)
833ff40c12SJohn Marino goto fail;
843ff40c12SJohn Marino
853ff40c12SJohn Marino pos = buf;
863ff40c12SJohn Marino pos = hostapd_eid_ext_capab(hapd, pos);
87*a1157835SDaniel Fojt if (add_buf_data(&assocresp, buf, pos - buf) < 0)
883ff40c12SJohn Marino goto fail;
893ff40c12SJohn Marino pos = hostapd_eid_interworking(hapd, pos);
903ff40c12SJohn Marino pos = hostapd_eid_adv_proto(hapd, pos);
913ff40c12SJohn Marino pos = hostapd_eid_roaming_consortium(hapd, pos);
92*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
93*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0)
943ff40c12SJohn Marino goto fail;
953ff40c12SJohn Marino
96*a1157835SDaniel Fojt #ifdef CONFIG_FST
97*a1157835SDaniel Fojt if (add_buf(&beacon, hapd->iface->fst_ies) < 0 ||
98*a1157835SDaniel Fojt add_buf(&proberesp, hapd->iface->fst_ies) < 0 ||
99*a1157835SDaniel Fojt add_buf(&assocresp, hapd->iface->fst_ies) < 0)
1003ff40c12SJohn Marino goto fail;
101*a1157835SDaniel Fojt #endif /* CONFIG_FST */
1023ff40c12SJohn Marino
103*a1157835SDaniel Fojt #ifdef CONFIG_FILS
104*a1157835SDaniel Fojt pos = hostapd_eid_fils_indic(hapd, buf, 0);
105*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
106*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0)
1073ff40c12SJohn Marino goto fail;
108*a1157835SDaniel Fojt #endif /* CONFIG_FILS */
1093ff40c12SJohn Marino
110*a1157835SDaniel Fojt if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
111*a1157835SDaniel Fojt add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
1123ff40c12SJohn Marino goto fail;
1133ff40c12SJohn Marino
1143ff40c12SJohn Marino #ifdef CONFIG_P2P
115*a1157835SDaniel Fojt if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
116*a1157835SDaniel Fojt add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
1173ff40c12SJohn Marino goto fail;
1183ff40c12SJohn Marino #endif /* CONFIG_P2P */
1193ff40c12SJohn Marino
1203ff40c12SJohn Marino #ifdef CONFIG_P2P_MANAGER
1213ff40c12SJohn Marino if (hapd->conf->p2p & P2P_MANAGE) {
1223ff40c12SJohn Marino if (wpabuf_resize(&beacon, 100) == 0) {
1233ff40c12SJohn Marino u8 *start, *p;
1243ff40c12SJohn Marino start = wpabuf_put(beacon, 0);
1253ff40c12SJohn Marino p = hostapd_eid_p2p_manage(hapd, start);
1263ff40c12SJohn Marino wpabuf_put(beacon, p - start);
1273ff40c12SJohn Marino }
1283ff40c12SJohn Marino
1293ff40c12SJohn Marino if (wpabuf_resize(&proberesp, 100) == 0) {
1303ff40c12SJohn Marino u8 *start, *p;
1313ff40c12SJohn Marino start = wpabuf_put(proberesp, 0);
1323ff40c12SJohn Marino p = hostapd_eid_p2p_manage(hapd, start);
1333ff40c12SJohn Marino wpabuf_put(proberesp, p - start);
1343ff40c12SJohn Marino }
1353ff40c12SJohn Marino }
1363ff40c12SJohn Marino #endif /* CONFIG_P2P_MANAGER */
1373ff40c12SJohn Marino
138*a1157835SDaniel Fojt #ifdef CONFIG_WPS
1393ff40c12SJohn Marino if (hapd->conf->wps_state) {
1403ff40c12SJohn Marino struct wpabuf *a = wps_build_assoc_resp_ie();
141*a1157835SDaniel Fojt add_buf(&assocresp, a);
1423ff40c12SJohn Marino wpabuf_free(a);
1433ff40c12SJohn Marino }
144*a1157835SDaniel Fojt #endif /* CONFIG_WPS */
1453ff40c12SJohn Marino
1463ff40c12SJohn Marino #ifdef CONFIG_P2P_MANAGER
1473ff40c12SJohn Marino if (hapd->conf->p2p & P2P_MANAGE) {
1483ff40c12SJohn Marino if (wpabuf_resize(&assocresp, 100) == 0) {
1493ff40c12SJohn Marino u8 *start, *p;
1503ff40c12SJohn Marino start = wpabuf_put(assocresp, 0);
1513ff40c12SJohn Marino p = hostapd_eid_p2p_manage(hapd, start);
1523ff40c12SJohn Marino wpabuf_put(assocresp, p - start);
1533ff40c12SJohn Marino }
1543ff40c12SJohn Marino }
1553ff40c12SJohn Marino #endif /* CONFIG_P2P_MANAGER */
1563ff40c12SJohn Marino
1573ff40c12SJohn Marino #ifdef CONFIG_WIFI_DISPLAY
1583ff40c12SJohn Marino if (hapd->p2p_group) {
1593ff40c12SJohn Marino struct wpabuf *a;
1603ff40c12SJohn Marino a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
161*a1157835SDaniel Fojt add_buf(&assocresp, a);
1623ff40c12SJohn Marino wpabuf_free(a);
1633ff40c12SJohn Marino }
1643ff40c12SJohn Marino #endif /* CONFIG_WIFI_DISPLAY */
1653ff40c12SJohn Marino
1663ff40c12SJohn Marino #ifdef CONFIG_HS20
167*a1157835SDaniel Fojt pos = hostapd_eid_hs20_indication(hapd, buf);
168*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
169*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0)
1703ff40c12SJohn Marino goto fail;
1713ff40c12SJohn Marino
172*a1157835SDaniel Fojt pos = hostapd_eid_osen(hapd, buf);
173*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
174*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0)
1753ff40c12SJohn Marino goto fail;
1763ff40c12SJohn Marino #endif /* CONFIG_HS20 */
1773ff40c12SJohn Marino
178*a1157835SDaniel Fojt #ifdef CONFIG_MBO
179*a1157835SDaniel Fojt if (hapd->conf->mbo_enabled ||
180*a1157835SDaniel Fojt OCE_STA_CFON_ENABLED(hapd) || OCE_AP_ENABLED(hapd)) {
181*a1157835SDaniel Fojt pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
182*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
183*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0 ||
184*a1157835SDaniel Fojt add_buf_data(&assocresp, buf, pos - buf) < 0)
185*a1157835SDaniel Fojt goto fail;
1863ff40c12SJohn Marino }
187*a1157835SDaniel Fojt #endif /* CONFIG_MBO */
188*a1157835SDaniel Fojt
189*a1157835SDaniel Fojt #ifdef CONFIG_OWE
190*a1157835SDaniel Fojt pos = hostapd_eid_owe_trans(hapd, buf, sizeof(buf));
191*a1157835SDaniel Fojt if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
192*a1157835SDaniel Fojt add_buf_data(&proberesp, buf, pos - buf) < 0)
193*a1157835SDaniel Fojt goto fail;
194*a1157835SDaniel Fojt #endif /* CONFIG_OWE */
195*a1157835SDaniel Fojt
196*a1157835SDaniel Fojt add_buf(&beacon, hapd->conf->vendor_elements);
197*a1157835SDaniel Fojt add_buf(&proberesp, hapd->conf->vendor_elements);
198*a1157835SDaniel Fojt add_buf(&assocresp, hapd->conf->assocresp_elements);
1993ff40c12SJohn Marino
2003ff40c12SJohn Marino *beacon_ret = beacon;
2013ff40c12SJohn Marino *proberesp_ret = proberesp;
2023ff40c12SJohn Marino *assocresp_ret = assocresp;
2033ff40c12SJohn Marino
2043ff40c12SJohn Marino return 0;
2053ff40c12SJohn Marino
2063ff40c12SJohn Marino fail:
2073ff40c12SJohn Marino wpabuf_free(beacon);
2083ff40c12SJohn Marino wpabuf_free(proberesp);
2093ff40c12SJohn Marino wpabuf_free(assocresp);
2103ff40c12SJohn Marino return -1;
2113ff40c12SJohn Marino }
2123ff40c12SJohn Marino
2133ff40c12SJohn Marino
hostapd_free_ap_extra_ies(struct hostapd_data * hapd,struct wpabuf * beacon,struct wpabuf * proberesp,struct wpabuf * assocresp)2143ff40c12SJohn Marino void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
2153ff40c12SJohn Marino struct wpabuf *beacon,
2163ff40c12SJohn Marino struct wpabuf *proberesp,
2173ff40c12SJohn Marino struct wpabuf *assocresp)
2183ff40c12SJohn Marino {
2193ff40c12SJohn Marino wpabuf_free(beacon);
2203ff40c12SJohn Marino wpabuf_free(proberesp);
2213ff40c12SJohn Marino wpabuf_free(assocresp);
2223ff40c12SJohn Marino }
2233ff40c12SJohn Marino
2243ff40c12SJohn Marino
hostapd_reset_ap_wps_ie(struct hostapd_data * hapd)225*a1157835SDaniel Fojt int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
226*a1157835SDaniel Fojt {
227*a1157835SDaniel Fojt if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
228*a1157835SDaniel Fojt return 0;
229*a1157835SDaniel Fojt
230*a1157835SDaniel Fojt return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
231*a1157835SDaniel Fojt }
232*a1157835SDaniel Fojt
233*a1157835SDaniel Fojt
hostapd_set_ap_wps_ie(struct hostapd_data * hapd)2343ff40c12SJohn Marino int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
2353ff40c12SJohn Marino {
2363ff40c12SJohn Marino struct wpabuf *beacon, *proberesp, *assocresp;
2373ff40c12SJohn Marino int ret;
2383ff40c12SJohn Marino
2393ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
2403ff40c12SJohn Marino return 0;
2413ff40c12SJohn Marino
2423ff40c12SJohn Marino if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2433ff40c12SJohn Marino 0)
2443ff40c12SJohn Marino return -1;
2453ff40c12SJohn Marino
2463ff40c12SJohn Marino ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
2473ff40c12SJohn Marino assocresp);
2483ff40c12SJohn Marino
2493ff40c12SJohn Marino hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
2503ff40c12SJohn Marino
2513ff40c12SJohn Marino return ret;
2523ff40c12SJohn Marino }
2533ff40c12SJohn Marino
2543ff40c12SJohn Marino
hostapd_set_authorized(struct hostapd_data * hapd,struct sta_info * sta,int authorized)2553ff40c12SJohn Marino int hostapd_set_authorized(struct hostapd_data *hapd,
2563ff40c12SJohn Marino struct sta_info *sta, int authorized)
2573ff40c12SJohn Marino {
2583ff40c12SJohn Marino if (authorized) {
2593ff40c12SJohn Marino return hostapd_sta_set_flags(hapd, sta->addr,
2603ff40c12SJohn Marino hostapd_sta_flags_to_drv(
2613ff40c12SJohn Marino sta->flags),
2623ff40c12SJohn Marino WPA_STA_AUTHORIZED, ~0);
2633ff40c12SJohn Marino }
2643ff40c12SJohn Marino
2653ff40c12SJohn Marino return hostapd_sta_set_flags(hapd, sta->addr,
2663ff40c12SJohn Marino hostapd_sta_flags_to_drv(sta->flags),
2673ff40c12SJohn Marino 0, ~WPA_STA_AUTHORIZED);
2683ff40c12SJohn Marino }
2693ff40c12SJohn Marino
2703ff40c12SJohn Marino
hostapd_set_sta_flags(struct hostapd_data * hapd,struct sta_info * sta)2713ff40c12SJohn Marino int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
2723ff40c12SJohn Marino {
2733ff40c12SJohn Marino int set_flags, total_flags, flags_and, flags_or;
2743ff40c12SJohn Marino total_flags = hostapd_sta_flags_to_drv(sta->flags);
2753ff40c12SJohn Marino set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
2763ff40c12SJohn Marino if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
2773ff40c12SJohn Marino sta->auth_alg == WLAN_AUTH_FT) &&
2783ff40c12SJohn Marino sta->flags & WLAN_STA_AUTHORIZED)
2793ff40c12SJohn Marino set_flags |= WPA_STA_AUTHORIZED;
2803ff40c12SJohn Marino flags_or = total_flags & set_flags;
2813ff40c12SJohn Marino flags_and = total_flags | ~set_flags;
2823ff40c12SJohn Marino return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
2833ff40c12SJohn Marino flags_or, flags_and);
2843ff40c12SJohn Marino }
2853ff40c12SJohn Marino
2863ff40c12SJohn Marino
hostapd_set_drv_ieee8021x(struct hostapd_data * hapd,const char * ifname,int enabled)2873ff40c12SJohn Marino int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
2883ff40c12SJohn Marino int enabled)
2893ff40c12SJohn Marino {
2903ff40c12SJohn Marino struct wpa_bss_params params;
2913ff40c12SJohn Marino os_memset(¶ms, 0, sizeof(params));
2923ff40c12SJohn Marino params.ifname = ifname;
2933ff40c12SJohn Marino params.enabled = enabled;
2943ff40c12SJohn Marino if (enabled) {
2953ff40c12SJohn Marino params.wpa = hapd->conf->wpa;
2963ff40c12SJohn Marino params.ieee802_1x = hapd->conf->ieee802_1x;
2973ff40c12SJohn Marino params.wpa_group = hapd->conf->wpa_group;
298*a1157835SDaniel Fojt if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
299*a1157835SDaniel Fojt (WPA_PROTO_WPA | WPA_PROTO_RSN))
300*a1157835SDaniel Fojt params.wpa_pairwise = hapd->conf->wpa_pairwise |
301*a1157835SDaniel Fojt hapd->conf->rsn_pairwise;
302*a1157835SDaniel Fojt else if (hapd->conf->wpa & WPA_PROTO_RSN)
303*a1157835SDaniel Fojt params.wpa_pairwise = hapd->conf->rsn_pairwise;
304*a1157835SDaniel Fojt else if (hapd->conf->wpa & WPA_PROTO_WPA)
3053ff40c12SJohn Marino params.wpa_pairwise = hapd->conf->wpa_pairwise;
3063ff40c12SJohn Marino params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
3073ff40c12SJohn Marino params.rsn_preauth = hapd->conf->rsn_preauth;
3083ff40c12SJohn Marino #ifdef CONFIG_IEEE80211W
3093ff40c12SJohn Marino params.ieee80211w = hapd->conf->ieee80211w;
3103ff40c12SJohn Marino #endif /* CONFIG_IEEE80211W */
3113ff40c12SJohn Marino }
3123ff40c12SJohn Marino return hostapd_set_ieee8021x(hapd, ¶ms);
3133ff40c12SJohn Marino }
3143ff40c12SJohn Marino
3153ff40c12SJohn Marino
hostapd_vlan_if_add(struct hostapd_data * hapd,const char * ifname)3163ff40c12SJohn Marino int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
3173ff40c12SJohn Marino {
3183ff40c12SJohn Marino char force_ifname[IFNAMSIZ];
3193ff40c12SJohn Marino u8 if_addr[ETH_ALEN];
3203ff40c12SJohn Marino return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
3213ff40c12SJohn Marino NULL, NULL, force_ifname, if_addr, NULL, 0);
3223ff40c12SJohn Marino }
3233ff40c12SJohn Marino
3243ff40c12SJohn Marino
hostapd_vlan_if_remove(struct hostapd_data * hapd,const char * ifname)3253ff40c12SJohn Marino int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
3263ff40c12SJohn Marino {
3273ff40c12SJohn Marino return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
3283ff40c12SJohn Marino }
3293ff40c12SJohn Marino
3303ff40c12SJohn Marino
hostapd_set_wds_sta(struct hostapd_data * hapd,char * ifname_wds,const u8 * addr,int aid,int val)3313ff40c12SJohn Marino int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
3323ff40c12SJohn Marino const u8 *addr, int aid, int val)
3333ff40c12SJohn Marino {
3343ff40c12SJohn Marino const char *bridge = NULL;
3353ff40c12SJohn Marino
3363ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
3373ff40c12SJohn Marino return -1;
3383ff40c12SJohn Marino if (hapd->conf->wds_bridge[0])
3393ff40c12SJohn Marino bridge = hapd->conf->wds_bridge;
3403ff40c12SJohn Marino else if (hapd->conf->bridge[0])
3413ff40c12SJohn Marino bridge = hapd->conf->bridge;
3423ff40c12SJohn Marino return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
3433ff40c12SJohn Marino bridge, ifname_wds);
3443ff40c12SJohn Marino }
3453ff40c12SJohn Marino
3463ff40c12SJohn Marino
hostapd_add_sta_node(struct hostapd_data * hapd,const u8 * addr,u16 auth_alg)3473ff40c12SJohn Marino int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
3483ff40c12SJohn Marino u16 auth_alg)
3493ff40c12SJohn Marino {
3503ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
3513ff40c12SJohn Marino return 0;
3523ff40c12SJohn Marino return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
3533ff40c12SJohn Marino }
3543ff40c12SJohn Marino
3553ff40c12SJohn Marino
hostapd_sta_auth(struct hostapd_data * hapd,const u8 * addr,u16 seq,u16 status,const u8 * ie,size_t len)3563ff40c12SJohn Marino int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
3573ff40c12SJohn Marino u16 seq, u16 status, const u8 *ie, size_t len)
3583ff40c12SJohn Marino {
359*a1157835SDaniel Fojt struct wpa_driver_sta_auth_params params;
360*a1157835SDaniel Fojt #ifdef CONFIG_FILS
361*a1157835SDaniel Fojt struct sta_info *sta;
362*a1157835SDaniel Fojt #endif /* CONFIG_FILS */
363*a1157835SDaniel Fojt
3643ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
3653ff40c12SJohn Marino return 0;
366*a1157835SDaniel Fojt
367*a1157835SDaniel Fojt os_memset(¶ms, 0, sizeof(params));
368*a1157835SDaniel Fojt
369*a1157835SDaniel Fojt #ifdef CONFIG_FILS
370*a1157835SDaniel Fojt sta = ap_get_sta(hapd, addr);
371*a1157835SDaniel Fojt if (!sta) {
372*a1157835SDaniel Fojt wpa_printf(MSG_DEBUG, "Station " MACSTR
373*a1157835SDaniel Fojt " not found for sta_auth processing",
374*a1157835SDaniel Fojt MAC2STR(addr));
375*a1157835SDaniel Fojt return 0;
376*a1157835SDaniel Fojt }
377*a1157835SDaniel Fojt
378*a1157835SDaniel Fojt if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
379*a1157835SDaniel Fojt sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
380*a1157835SDaniel Fojt sta->auth_alg == WLAN_AUTH_FILS_PK) {
381*a1157835SDaniel Fojt params.fils_auth = 1;
382*a1157835SDaniel Fojt wpa_auth_get_fils_aead_params(sta->wpa_sm, params.fils_anonce,
383*a1157835SDaniel Fojt params.fils_snonce,
384*a1157835SDaniel Fojt params.fils_kek,
385*a1157835SDaniel Fojt ¶ms.fils_kek_len);
386*a1157835SDaniel Fojt }
387*a1157835SDaniel Fojt #endif /* CONFIG_FILS */
388*a1157835SDaniel Fojt
389*a1157835SDaniel Fojt params.own_addr = hapd->own_addr;
390*a1157835SDaniel Fojt params.addr = addr;
391*a1157835SDaniel Fojt params.seq = seq;
392*a1157835SDaniel Fojt params.status = status;
393*a1157835SDaniel Fojt params.ie = ie;
394*a1157835SDaniel Fojt params.len = len;
395*a1157835SDaniel Fojt
396*a1157835SDaniel Fojt return hapd->driver->sta_auth(hapd->drv_priv, ¶ms);
3973ff40c12SJohn Marino }
3983ff40c12SJohn Marino
3993ff40c12SJohn Marino
hostapd_sta_assoc(struct hostapd_data * hapd,const u8 * addr,int reassoc,u16 status,const u8 * ie,size_t len)4003ff40c12SJohn Marino int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
4013ff40c12SJohn Marino int reassoc, u16 status, const u8 *ie, size_t len)
4023ff40c12SJohn Marino {
4033ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
4043ff40c12SJohn Marino return 0;
4053ff40c12SJohn Marino return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
4063ff40c12SJohn Marino reassoc, status, ie, len);
4073ff40c12SJohn Marino }
4083ff40c12SJohn Marino
4093ff40c12SJohn Marino
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,u32 flags,u8 qosinfo,u8 vht_opmode,int supp_p2p_ps,int set)4103ff40c12SJohn Marino int hostapd_sta_add(struct hostapd_data *hapd,
4113ff40c12SJohn Marino const u8 *addr, u16 aid, u16 capability,
4123ff40c12SJohn Marino const u8 *supp_rates, size_t supp_rates_len,
4133ff40c12SJohn Marino u16 listen_interval,
4143ff40c12SJohn Marino const struct ieee80211_ht_capabilities *ht_capab,
4153ff40c12SJohn Marino const struct ieee80211_vht_capabilities *vht_capab,
416*a1157835SDaniel Fojt const struct ieee80211_he_capabilities *he_capab,
417*a1157835SDaniel Fojt size_t he_capab_len,
418*a1157835SDaniel Fojt u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
419*a1157835SDaniel Fojt int set)
4203ff40c12SJohn Marino {
4213ff40c12SJohn Marino struct hostapd_sta_add_params params;
4223ff40c12SJohn Marino
4233ff40c12SJohn Marino if (hapd->driver == NULL)
4243ff40c12SJohn Marino return 0;
4253ff40c12SJohn Marino if (hapd->driver->sta_add == NULL)
4263ff40c12SJohn Marino return 0;
4273ff40c12SJohn Marino
4283ff40c12SJohn Marino os_memset(¶ms, 0, sizeof(params));
4293ff40c12SJohn Marino params.addr = addr;
4303ff40c12SJohn Marino params.aid = aid;
4313ff40c12SJohn Marino params.capability = capability;
4323ff40c12SJohn Marino params.supp_rates = supp_rates;
4333ff40c12SJohn Marino params.supp_rates_len = supp_rates_len;
4343ff40c12SJohn Marino params.listen_interval = listen_interval;
4353ff40c12SJohn Marino params.ht_capabilities = ht_capab;
4363ff40c12SJohn Marino params.vht_capabilities = vht_capab;
437*a1157835SDaniel Fojt params.he_capab = he_capab;
438*a1157835SDaniel Fojt params.he_capab_len = he_capab_len;
439*a1157835SDaniel Fojt params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
440*a1157835SDaniel Fojt params.vht_opmode = vht_opmode;
4413ff40c12SJohn Marino params.flags = hostapd_sta_flags_to_drv(flags);
4423ff40c12SJohn Marino params.qosinfo = qosinfo;
443*a1157835SDaniel Fojt params.support_p2p_ps = supp_p2p_ps;
444*a1157835SDaniel Fojt params.set = set;
4453ff40c12SJohn Marino return hapd->driver->sta_add(hapd->drv_priv, ¶ms);
4463ff40c12SJohn Marino }
4473ff40c12SJohn Marino
4483ff40c12SJohn Marino
hostapd_add_tspec(struct hostapd_data * hapd,const u8 * addr,u8 * tspec_ie,size_t tspec_ielen)4493ff40c12SJohn Marino int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
4503ff40c12SJohn Marino u8 *tspec_ie, size_t tspec_ielen)
4513ff40c12SJohn Marino {
4523ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
4533ff40c12SJohn Marino return 0;
4543ff40c12SJohn Marino return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
4553ff40c12SJohn Marino tspec_ielen);
4563ff40c12SJohn Marino }
4573ff40c12SJohn Marino
4583ff40c12SJohn Marino
hostapd_set_privacy(struct hostapd_data * hapd,int enabled)4593ff40c12SJohn Marino int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
4603ff40c12SJohn Marino {
4613ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
4623ff40c12SJohn Marino return 0;
4633ff40c12SJohn Marino return hapd->driver->set_privacy(hapd->drv_priv, enabled);
4643ff40c12SJohn Marino }
4653ff40c12SJohn Marino
4663ff40c12SJohn Marino
hostapd_set_generic_elem(struct hostapd_data * hapd,const u8 * elem,size_t elem_len)4673ff40c12SJohn Marino int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
4683ff40c12SJohn Marino size_t elem_len)
4693ff40c12SJohn Marino {
4703ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
4713ff40c12SJohn Marino return 0;
4723ff40c12SJohn Marino return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
4733ff40c12SJohn Marino }
4743ff40c12SJohn Marino
4753ff40c12SJohn Marino
hostapd_get_ssid(struct hostapd_data * hapd,u8 * buf,size_t len)4763ff40c12SJohn Marino int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
4773ff40c12SJohn Marino {
4783ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
4793ff40c12SJohn Marino return 0;
4803ff40c12SJohn Marino return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
4813ff40c12SJohn Marino }
4823ff40c12SJohn Marino
4833ff40c12SJohn Marino
hostapd_set_ssid(struct hostapd_data * hapd,const u8 * buf,size_t len)4843ff40c12SJohn Marino int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
4853ff40c12SJohn Marino {
4863ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
4873ff40c12SJohn Marino return 0;
4883ff40c12SJohn Marino return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
4893ff40c12SJohn Marino }
4903ff40c12SJohn Marino
4913ff40c12SJohn Marino
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)4923ff40c12SJohn Marino int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
4933ff40c12SJohn Marino const char *ifname, const u8 *addr, void *bss_ctx,
4943ff40c12SJohn Marino void **drv_priv, char *force_ifname, u8 *if_addr,
4953ff40c12SJohn Marino const char *bridge, int use_existing)
4963ff40c12SJohn Marino {
4973ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->if_add == NULL)
4983ff40c12SJohn Marino return -1;
4993ff40c12SJohn Marino return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
5003ff40c12SJohn Marino bss_ctx, drv_priv, force_ifname, if_addr,
501*a1157835SDaniel Fojt bridge, use_existing, 1);
5023ff40c12SJohn Marino }
5033ff40c12SJohn Marino
5043ff40c12SJohn Marino
hostapd_if_remove(struct hostapd_data * hapd,enum wpa_driver_if_type type,const char * ifname)5053ff40c12SJohn Marino int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
5063ff40c12SJohn Marino const char *ifname)
5073ff40c12SJohn Marino {
5083ff40c12SJohn Marino if (hapd->driver == NULL || hapd->drv_priv == NULL ||
5093ff40c12SJohn Marino hapd->driver->if_remove == NULL)
5103ff40c12SJohn Marino return -1;
5113ff40c12SJohn Marino return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
5123ff40c12SJohn Marino }
5133ff40c12SJohn Marino
5143ff40c12SJohn Marino
hostapd_set_ieee8021x(struct hostapd_data * hapd,struct wpa_bss_params * params)5153ff40c12SJohn Marino int hostapd_set_ieee8021x(struct hostapd_data *hapd,
5163ff40c12SJohn Marino struct wpa_bss_params *params)
5173ff40c12SJohn Marino {
5183ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
5193ff40c12SJohn Marino return 0;
5203ff40c12SJohn Marino return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
5213ff40c12SJohn Marino }
5223ff40c12SJohn Marino
5233ff40c12SJohn Marino
hostapd_get_seqnum(const char * ifname,struct hostapd_data * hapd,const u8 * addr,int idx,u8 * seq)5243ff40c12SJohn Marino int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
5253ff40c12SJohn Marino const u8 *addr, int idx, u8 *seq)
5263ff40c12SJohn Marino {
5273ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
5283ff40c12SJohn Marino return 0;
5293ff40c12SJohn Marino return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
5303ff40c12SJohn Marino seq);
5313ff40c12SJohn Marino }
5323ff40c12SJohn Marino
5333ff40c12SJohn Marino
hostapd_flush(struct hostapd_data * hapd)5343ff40c12SJohn Marino int hostapd_flush(struct hostapd_data *hapd)
5353ff40c12SJohn Marino {
5363ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->flush == NULL)
5373ff40c12SJohn Marino return 0;
5383ff40c12SJohn Marino return hapd->driver->flush(hapd->drv_priv);
5393ff40c12SJohn Marino }
5403ff40c12SJohn Marino
5413ff40c12SJohn Marino
hostapd_set_freq(struct hostapd_data * hapd,enum hostapd_hw_mode mode,int freq,int channel,int ht_enabled,int vht_enabled,int he_enabled,int sec_channel_offset,int oper_chwidth,int center_segment0,int center_segment1)542*a1157835SDaniel Fojt int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
543*a1157835SDaniel Fojt int freq, int channel, int ht_enabled, int vht_enabled,
544*a1157835SDaniel Fojt int he_enabled,
545*a1157835SDaniel Fojt int sec_channel_offset, int oper_chwidth,
5463ff40c12SJohn Marino int center_segment0, int center_segment1)
5473ff40c12SJohn Marino {
5483ff40c12SJohn Marino struct hostapd_freq_params data;
549*a1157835SDaniel Fojt struct hostapd_hw_modes *cmode = hapd->iface->current_mode;
5503ff40c12SJohn Marino
5513ff40c12SJohn Marino if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
552*a1157835SDaniel Fojt vht_enabled, he_enabled, sec_channel_offset,
553*a1157835SDaniel Fojt oper_chwidth,
5543ff40c12SJohn Marino center_segment0, center_segment1,
555*a1157835SDaniel Fojt cmode ? cmode->vht_capab : 0,
556*a1157835SDaniel Fojt cmode ?
557*a1157835SDaniel Fojt &cmode->he_capab[IEEE80211_MODE_AP] : NULL))
5583ff40c12SJohn Marino return -1;
5593ff40c12SJohn Marino
5603ff40c12SJohn Marino if (hapd->driver == NULL)
5613ff40c12SJohn Marino return 0;
5623ff40c12SJohn Marino if (hapd->driver->set_freq == NULL)
5633ff40c12SJohn Marino return 0;
5643ff40c12SJohn Marino return hapd->driver->set_freq(hapd->drv_priv, &data);
5653ff40c12SJohn Marino }
5663ff40c12SJohn Marino
hostapd_set_rts(struct hostapd_data * hapd,int rts)5673ff40c12SJohn Marino int hostapd_set_rts(struct hostapd_data *hapd, int rts)
5683ff40c12SJohn Marino {
5693ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
5703ff40c12SJohn Marino return 0;
5713ff40c12SJohn Marino return hapd->driver->set_rts(hapd->drv_priv, rts);
5723ff40c12SJohn Marino }
5733ff40c12SJohn Marino
5743ff40c12SJohn Marino
hostapd_set_frag(struct hostapd_data * hapd,int frag)5753ff40c12SJohn Marino int hostapd_set_frag(struct hostapd_data *hapd, int frag)
5763ff40c12SJohn Marino {
5773ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
5783ff40c12SJohn Marino return 0;
5793ff40c12SJohn Marino return hapd->driver->set_frag(hapd->drv_priv, frag);
5803ff40c12SJohn Marino }
5813ff40c12SJohn Marino
5823ff40c12SJohn Marino
hostapd_sta_set_flags(struct hostapd_data * hapd,u8 * addr,int total_flags,int flags_or,int flags_and)5833ff40c12SJohn Marino int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
5843ff40c12SJohn Marino int total_flags, int flags_or, int flags_and)
5853ff40c12SJohn Marino {
5863ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
5873ff40c12SJohn Marino return 0;
5883ff40c12SJohn Marino return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
5893ff40c12SJohn Marino flags_or, flags_and);
5903ff40c12SJohn Marino }
5913ff40c12SJohn Marino
5923ff40c12SJohn Marino
hostapd_sta_set_airtime_weight(struct hostapd_data * hapd,const u8 * addr,unsigned int weight)593*a1157835SDaniel Fojt int hostapd_sta_set_airtime_weight(struct hostapd_data *hapd, const u8 *addr,
594*a1157835SDaniel Fojt unsigned int weight)
595*a1157835SDaniel Fojt {
596*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->sta_set_airtime_weight)
597*a1157835SDaniel Fojt return 0;
598*a1157835SDaniel Fojt return hapd->driver->sta_set_airtime_weight(hapd->drv_priv, addr,
599*a1157835SDaniel Fojt weight);
600*a1157835SDaniel Fojt }
601*a1157835SDaniel Fojt
602*a1157835SDaniel Fojt
hostapd_set_country(struct hostapd_data * hapd,const char * country)6033ff40c12SJohn Marino int hostapd_set_country(struct hostapd_data *hapd, const char *country)
6043ff40c12SJohn Marino {
6053ff40c12SJohn Marino if (hapd->driver == NULL ||
6063ff40c12SJohn Marino hapd->driver->set_country == NULL)
6073ff40c12SJohn Marino return 0;
6083ff40c12SJohn Marino return hapd->driver->set_country(hapd->drv_priv, country);
6093ff40c12SJohn Marino }
6103ff40c12SJohn Marino
6113ff40c12SJohn Marino
hostapd_set_tx_queue_params(struct hostapd_data * hapd,int queue,int aifs,int cw_min,int cw_max,int burst_time)6123ff40c12SJohn Marino int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
6133ff40c12SJohn Marino int cw_min, int cw_max, int burst_time)
6143ff40c12SJohn Marino {
6153ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
6163ff40c12SJohn Marino return 0;
6173ff40c12SJohn Marino return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
6183ff40c12SJohn Marino cw_min, cw_max, burst_time);
6193ff40c12SJohn Marino }
6203ff40c12SJohn Marino
6213ff40c12SJohn Marino
6223ff40c12SJohn Marino struct hostapd_hw_modes *
hostapd_get_hw_feature_data(struct hostapd_data * hapd,u16 * num_modes,u16 * flags,u8 * dfs_domain)6233ff40c12SJohn Marino hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
624*a1157835SDaniel Fojt u16 *flags, u8 *dfs_domain)
6253ff40c12SJohn Marino {
6263ff40c12SJohn Marino if (hapd->driver == NULL ||
6273ff40c12SJohn Marino hapd->driver->get_hw_feature_data == NULL)
6283ff40c12SJohn Marino return NULL;
6293ff40c12SJohn Marino return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
630*a1157835SDaniel Fojt flags, dfs_domain);
6313ff40c12SJohn Marino }
6323ff40c12SJohn Marino
6333ff40c12SJohn Marino
hostapd_driver_commit(struct hostapd_data * hapd)6343ff40c12SJohn Marino int hostapd_driver_commit(struct hostapd_data *hapd)
6353ff40c12SJohn Marino {
6363ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->commit == NULL)
6373ff40c12SJohn Marino return 0;
6383ff40c12SJohn Marino return hapd->driver->commit(hapd->drv_priv);
6393ff40c12SJohn Marino }
6403ff40c12SJohn Marino
6413ff40c12SJohn Marino
hostapd_drv_none(struct hostapd_data * hapd)6423ff40c12SJohn Marino int hostapd_drv_none(struct hostapd_data *hapd)
6433ff40c12SJohn Marino {
6443ff40c12SJohn Marino return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
6453ff40c12SJohn Marino }
6463ff40c12SJohn Marino
6473ff40c12SJohn Marino
hostapd_driver_scan(struct hostapd_data * hapd,struct wpa_driver_scan_params * params)6483ff40c12SJohn Marino int hostapd_driver_scan(struct hostapd_data *hapd,
6493ff40c12SJohn Marino struct wpa_driver_scan_params *params)
6503ff40c12SJohn Marino {
6513ff40c12SJohn Marino if (hapd->driver && hapd->driver->scan2)
6523ff40c12SJohn Marino return hapd->driver->scan2(hapd->drv_priv, params);
6533ff40c12SJohn Marino return -1;
6543ff40c12SJohn Marino }
6553ff40c12SJohn Marino
6563ff40c12SJohn Marino
hostapd_driver_get_scan_results(struct hostapd_data * hapd)6573ff40c12SJohn Marino struct wpa_scan_results * hostapd_driver_get_scan_results(
6583ff40c12SJohn Marino struct hostapd_data *hapd)
6593ff40c12SJohn Marino {
6603ff40c12SJohn Marino if (hapd->driver && hapd->driver->get_scan_results2)
6613ff40c12SJohn Marino return hapd->driver->get_scan_results2(hapd->drv_priv);
6623ff40c12SJohn Marino return NULL;
6633ff40c12SJohn Marino }
6643ff40c12SJohn Marino
6653ff40c12SJohn Marino
hostapd_driver_set_noa(struct hostapd_data * hapd,u8 count,int start,int duration)6663ff40c12SJohn Marino int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
6673ff40c12SJohn Marino int duration)
6683ff40c12SJohn Marino {
6693ff40c12SJohn Marino if (hapd->driver && hapd->driver->set_noa)
6703ff40c12SJohn Marino return hapd->driver->set_noa(hapd->drv_priv, count, start,
6713ff40c12SJohn Marino duration);
6723ff40c12SJohn Marino return -1;
6733ff40c12SJohn Marino }
6743ff40c12SJohn Marino
6753ff40c12SJohn Marino
hostapd_drv_set_key(const char * ifname,struct hostapd_data * hapd,enum wpa_alg alg,const u8 * addr,int key_idx,int set_tx,const u8 * seq,size_t seq_len,const u8 * key,size_t key_len)6763ff40c12SJohn Marino int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
6773ff40c12SJohn Marino enum wpa_alg alg, const u8 *addr,
6783ff40c12SJohn Marino int key_idx, int set_tx,
6793ff40c12SJohn Marino const u8 *seq, size_t seq_len,
6803ff40c12SJohn Marino const u8 *key, size_t key_len)
6813ff40c12SJohn Marino {
6823ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->set_key == NULL)
6833ff40c12SJohn Marino return 0;
6843ff40c12SJohn Marino return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
6853ff40c12SJohn Marino key_idx, set_tx, seq, seq_len, key,
6863ff40c12SJohn Marino key_len);
6873ff40c12SJohn Marino }
6883ff40c12SJohn Marino
6893ff40c12SJohn Marino
hostapd_drv_send_mlme(struct hostapd_data * hapd,const void * msg,size_t len,int noack)6903ff40c12SJohn Marino int hostapd_drv_send_mlme(struct hostapd_data *hapd,
6913ff40c12SJohn Marino const void *msg, size_t len, int noack)
6923ff40c12SJohn Marino {
693*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
694*a1157835SDaniel Fojt return 0;
695*a1157835SDaniel Fojt return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
696*a1157835SDaniel Fojt NULL, 0);
697*a1157835SDaniel Fojt }
698*a1157835SDaniel Fojt
699*a1157835SDaniel Fojt
hostapd_drv_send_mlme_csa(struct hostapd_data * hapd,const void * msg,size_t len,int noack,const u16 * csa_offs,size_t csa_offs_len)700*a1157835SDaniel Fojt int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
701*a1157835SDaniel Fojt const void *msg, size_t len, int noack,
702*a1157835SDaniel Fojt const u16 *csa_offs, size_t csa_offs_len)
703*a1157835SDaniel Fojt {
7043ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
7053ff40c12SJohn Marino return 0;
706*a1157835SDaniel Fojt return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
707*a1157835SDaniel Fojt csa_offs, csa_offs_len);
7083ff40c12SJohn Marino }
7093ff40c12SJohn Marino
7103ff40c12SJohn Marino
hostapd_drv_sta_deauth(struct hostapd_data * hapd,const u8 * addr,int reason)7113ff40c12SJohn Marino int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
7123ff40c12SJohn Marino const u8 *addr, int reason)
7133ff40c12SJohn Marino {
714*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
7153ff40c12SJohn Marino return 0;
7163ff40c12SJohn Marino return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
7173ff40c12SJohn Marino reason);
7183ff40c12SJohn Marino }
7193ff40c12SJohn Marino
7203ff40c12SJohn Marino
hostapd_drv_sta_disassoc(struct hostapd_data * hapd,const u8 * addr,int reason)7213ff40c12SJohn Marino int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
7223ff40c12SJohn Marino const u8 *addr, int reason)
7233ff40c12SJohn Marino {
724*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
7253ff40c12SJohn Marino return 0;
7263ff40c12SJohn Marino return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
7273ff40c12SJohn Marino reason);
7283ff40c12SJohn Marino }
7293ff40c12SJohn Marino
7303ff40c12SJohn Marino
hostapd_drv_wnm_oper(struct hostapd_data * hapd,enum wnm_oper oper,const u8 * peer,u8 * buf,u16 * buf_len)7313ff40c12SJohn Marino int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
7323ff40c12SJohn Marino const u8 *peer, u8 *buf, u16 *buf_len)
7333ff40c12SJohn Marino {
7343ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
7353ff40c12SJohn Marino return -1;
7363ff40c12SJohn Marino return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
7373ff40c12SJohn Marino buf_len);
7383ff40c12SJohn Marino }
7393ff40c12SJohn Marino
7403ff40c12SJohn Marino
hostapd_drv_send_action(struct hostapd_data * hapd,unsigned int freq,unsigned int wait,const u8 * dst,const u8 * data,size_t len)7413ff40c12SJohn Marino int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
7423ff40c12SJohn Marino unsigned int wait, const u8 *dst, const u8 *data,
7433ff40c12SJohn Marino size_t len)
7443ff40c12SJohn Marino {
745*a1157835SDaniel Fojt const u8 *bssid;
746*a1157835SDaniel Fojt const u8 wildcard_bssid[ETH_ALEN] = {
747*a1157835SDaniel Fojt 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
748*a1157835SDaniel Fojt };
749*a1157835SDaniel Fojt
750*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
751*a1157835SDaniel Fojt return 0;
752*a1157835SDaniel Fojt bssid = hapd->own_addr;
753*a1157835SDaniel Fojt if (!is_multicast_ether_addr(dst) &&
754*a1157835SDaniel Fojt len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
755*a1157835SDaniel Fojt struct sta_info *sta;
756*a1157835SDaniel Fojt
757*a1157835SDaniel Fojt /*
758*a1157835SDaniel Fojt * Public Action frames to a STA that is not a member of the BSS
759*a1157835SDaniel Fojt * shall use wildcard BSSID value.
760*a1157835SDaniel Fojt */
761*a1157835SDaniel Fojt sta = ap_get_sta(hapd, dst);
762*a1157835SDaniel Fojt if (!sta || !(sta->flags & WLAN_STA_ASSOC))
763*a1157835SDaniel Fojt bssid = wildcard_bssid;
764*a1157835SDaniel Fojt } else if (is_broadcast_ether_addr(dst) &&
765*a1157835SDaniel Fojt len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
766*a1157835SDaniel Fojt /*
767*a1157835SDaniel Fojt * The only current use case of Public Action frames with
768*a1157835SDaniel Fojt * broadcast destination address is DPP PKEX. That case is
769*a1157835SDaniel Fojt * directing all devices and not just the STAs within the BSS,
770*a1157835SDaniel Fojt * so have to use the wildcard BSSID value.
771*a1157835SDaniel Fojt */
772*a1157835SDaniel Fojt bssid = wildcard_bssid;
773*a1157835SDaniel Fojt }
774*a1157835SDaniel Fojt return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
775*a1157835SDaniel Fojt hapd->own_addr, bssid, data, len, 0);
776*a1157835SDaniel Fojt }
777*a1157835SDaniel Fojt
778*a1157835SDaniel Fojt
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)779*a1157835SDaniel Fojt int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
780*a1157835SDaniel Fojt unsigned int freq,
781*a1157835SDaniel Fojt unsigned int wait, const u8 *dst,
782*a1157835SDaniel Fojt const u8 *data, size_t len)
783*a1157835SDaniel Fojt {
7843ff40c12SJohn Marino if (hapd->driver == NULL || hapd->driver->send_action == NULL)
7853ff40c12SJohn Marino return 0;
7863ff40c12SJohn Marino return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
7873ff40c12SJohn Marino hapd->own_addr, hapd->own_addr, data,
7883ff40c12SJohn Marino len, 0);
7893ff40c12SJohn Marino }
7903ff40c12SJohn Marino
7913ff40c12SJohn Marino
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,int sec_channel_offset,int oper_chwidth,int center_segment0,int center_segment1)792*a1157835SDaniel Fojt int hostapd_start_dfs_cac(struct hostapd_iface *iface,
793*a1157835SDaniel Fojt enum hostapd_hw_mode mode, int freq,
7943ff40c12SJohn Marino int channel, int ht_enabled, int vht_enabled,
795*a1157835SDaniel Fojt int he_enabled,
796*a1157835SDaniel Fojt int sec_channel_offset, int oper_chwidth,
7973ff40c12SJohn Marino int center_segment0, int center_segment1)
7983ff40c12SJohn Marino {
7993ff40c12SJohn Marino struct hostapd_data *hapd = iface->bss[0];
8003ff40c12SJohn Marino struct hostapd_freq_params data;
8013ff40c12SJohn Marino int res;
802*a1157835SDaniel Fojt struct hostapd_hw_modes *cmode = iface->current_mode;
8033ff40c12SJohn Marino
804*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->start_dfs_cac || !cmode)
8053ff40c12SJohn Marino return 0;
8063ff40c12SJohn Marino
8073ff40c12SJohn Marino if (!iface->conf->ieee80211h) {
8083ff40c12SJohn Marino wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
8093ff40c12SJohn Marino "is not enabled");
8103ff40c12SJohn Marino return -1;
8113ff40c12SJohn Marino }
8123ff40c12SJohn Marino
8133ff40c12SJohn Marino if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
814*a1157835SDaniel Fojt vht_enabled, he_enabled, sec_channel_offset,
815*a1157835SDaniel Fojt oper_chwidth, center_segment0,
8163ff40c12SJohn Marino center_segment1,
817*a1157835SDaniel Fojt cmode->vht_capab,
818*a1157835SDaniel Fojt &cmode->he_capab[IEEE80211_MODE_AP])) {
819*a1157835SDaniel Fojt wpa_printf(MSG_ERROR, "Can't set freq params");
8203ff40c12SJohn Marino return -1;
821*a1157835SDaniel Fojt }
8223ff40c12SJohn Marino
8233ff40c12SJohn Marino res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
824*a1157835SDaniel Fojt if (!res) {
8253ff40c12SJohn Marino iface->cac_started = 1;
826*a1157835SDaniel Fojt os_get_reltime(&iface->dfs_cac_start);
827*a1157835SDaniel Fojt }
8283ff40c12SJohn Marino
8293ff40c12SJohn Marino return res;
8303ff40c12SJohn Marino }
8313ff40c12SJohn Marino
8323ff40c12SJohn Marino
hostapd_drv_set_qos_map(struct hostapd_data * hapd,const u8 * qos_map_set,u8 qos_map_set_len)8333ff40c12SJohn Marino int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
8343ff40c12SJohn Marino const u8 *qos_map_set, u8 qos_map_set_len)
8353ff40c12SJohn Marino {
836*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
8373ff40c12SJohn Marino return 0;
8383ff40c12SJohn Marino return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
8393ff40c12SJohn Marino qos_map_set_len);
8403ff40c12SJohn Marino }
841*a1157835SDaniel Fojt
842*a1157835SDaniel Fojt
hostapd_get_hw_mode_any_channels(struct hostapd_data * hapd,struct hostapd_hw_modes * mode,int acs_ch_list_all,int ** freq_list)843*a1157835SDaniel Fojt static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
844*a1157835SDaniel Fojt struct hostapd_hw_modes *mode,
845*a1157835SDaniel Fojt int acs_ch_list_all,
846*a1157835SDaniel Fojt int **freq_list)
847*a1157835SDaniel Fojt {
848*a1157835SDaniel Fojt int i;
849*a1157835SDaniel Fojt
850*a1157835SDaniel Fojt for (i = 0; i < mode->num_channels; i++) {
851*a1157835SDaniel Fojt struct hostapd_channel_data *chan = &mode->channels[i];
852*a1157835SDaniel Fojt
853*a1157835SDaniel Fojt if ((acs_ch_list_all ||
854*a1157835SDaniel Fojt freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
855*a1157835SDaniel Fojt chan->chan)) &&
856*a1157835SDaniel Fojt !(chan->flag & HOSTAPD_CHAN_DISABLED) &&
857*a1157835SDaniel Fojt !(hapd->iface->conf->acs_exclude_dfs &&
858*a1157835SDaniel Fojt (chan->flag & HOSTAPD_CHAN_RADAR)))
859*a1157835SDaniel Fojt int_array_add_unique(freq_list, chan->freq);
860*a1157835SDaniel Fojt }
861*a1157835SDaniel Fojt }
862*a1157835SDaniel Fojt
863*a1157835SDaniel Fojt
hostapd_get_ext_capa(struct hostapd_iface * iface)864*a1157835SDaniel Fojt void hostapd_get_ext_capa(struct hostapd_iface *iface)
865*a1157835SDaniel Fojt {
866*a1157835SDaniel Fojt struct hostapd_data *hapd = iface->bss[0];
867*a1157835SDaniel Fojt
868*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->get_ext_capab)
869*a1157835SDaniel Fojt return;
870*a1157835SDaniel Fojt
871*a1157835SDaniel Fojt hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
872*a1157835SDaniel Fojt &iface->extended_capa,
873*a1157835SDaniel Fojt &iface->extended_capa_mask,
874*a1157835SDaniel Fojt &iface->extended_capa_len);
875*a1157835SDaniel Fojt }
876*a1157835SDaniel Fojt
877*a1157835SDaniel Fojt
hostapd_drv_do_acs(struct hostapd_data * hapd)878*a1157835SDaniel Fojt int hostapd_drv_do_acs(struct hostapd_data *hapd)
879*a1157835SDaniel Fojt {
880*a1157835SDaniel Fojt struct drv_acs_params params;
881*a1157835SDaniel Fojt int ret, i, acs_ch_list_all = 0;
882*a1157835SDaniel Fojt u8 *channels = NULL;
883*a1157835SDaniel Fojt unsigned int num_channels = 0;
884*a1157835SDaniel Fojt struct hostapd_hw_modes *mode;
885*a1157835SDaniel Fojt int *freq_list = NULL;
886*a1157835SDaniel Fojt
887*a1157835SDaniel Fojt if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
888*a1157835SDaniel Fojt return 0;
889*a1157835SDaniel Fojt
890*a1157835SDaniel Fojt os_memset(¶ms, 0, sizeof(params));
891*a1157835SDaniel Fojt params.hw_mode = hapd->iface->conf->hw_mode;
892*a1157835SDaniel Fojt
893*a1157835SDaniel Fojt /*
894*a1157835SDaniel Fojt * If no chanlist config parameter is provided, include all enabled
895*a1157835SDaniel Fojt * channels of the selected hw_mode.
896*a1157835SDaniel Fojt */
897*a1157835SDaniel Fojt if (!hapd->iface->conf->acs_ch_list.num)
898*a1157835SDaniel Fojt acs_ch_list_all = 1;
899*a1157835SDaniel Fojt
900*a1157835SDaniel Fojt mode = hapd->iface->current_mode;
901*a1157835SDaniel Fojt if (mode) {
902*a1157835SDaniel Fojt channels = os_malloc(mode->num_channels);
903*a1157835SDaniel Fojt if (channels == NULL)
904*a1157835SDaniel Fojt return -1;
905*a1157835SDaniel Fojt
906*a1157835SDaniel Fojt for (i = 0; i < mode->num_channels; i++) {
907*a1157835SDaniel Fojt struct hostapd_channel_data *chan = &mode->channels[i];
908*a1157835SDaniel Fojt if (!acs_ch_list_all &&
909*a1157835SDaniel Fojt !freq_range_list_includes(
910*a1157835SDaniel Fojt &hapd->iface->conf->acs_ch_list,
911*a1157835SDaniel Fojt chan->chan))
912*a1157835SDaniel Fojt continue;
913*a1157835SDaniel Fojt if (hapd->iface->conf->acs_exclude_dfs &&
914*a1157835SDaniel Fojt (chan->flag & HOSTAPD_CHAN_RADAR))
915*a1157835SDaniel Fojt continue;
916*a1157835SDaniel Fojt if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
917*a1157835SDaniel Fojt channels[num_channels++] = chan->chan;
918*a1157835SDaniel Fojt int_array_add_unique(&freq_list, chan->freq);
919*a1157835SDaniel Fojt }
920*a1157835SDaniel Fojt }
921*a1157835SDaniel Fojt } else {
922*a1157835SDaniel Fojt for (i = 0; i < hapd->iface->num_hw_features; i++) {
923*a1157835SDaniel Fojt mode = &hapd->iface->hw_features[i];
924*a1157835SDaniel Fojt hostapd_get_hw_mode_any_channels(hapd, mode,
925*a1157835SDaniel Fojt acs_ch_list_all,
926*a1157835SDaniel Fojt &freq_list);
927*a1157835SDaniel Fojt }
928*a1157835SDaniel Fojt }
929*a1157835SDaniel Fojt
930*a1157835SDaniel Fojt params.ch_list = channels;
931*a1157835SDaniel Fojt params.ch_list_len = num_channels;
932*a1157835SDaniel Fojt params.freq_list = freq_list;
933*a1157835SDaniel Fojt
934*a1157835SDaniel Fojt params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
935*a1157835SDaniel Fojt params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
936*a1157835SDaniel Fojt HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
937*a1157835SDaniel Fojt params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
938*a1157835SDaniel Fojt params.ch_width = 20;
939*a1157835SDaniel Fojt if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
940*a1157835SDaniel Fojt params.ch_width = 40;
941*a1157835SDaniel Fojt
942*a1157835SDaniel Fojt /* Note: VHT20 is defined by combination of ht_capab & oper_chwidth
943*a1157835SDaniel Fojt */
944*a1157835SDaniel Fojt if ((hapd->iface->conf->ieee80211ax ||
945*a1157835SDaniel Fojt hapd->iface->conf->ieee80211ac) &&
946*a1157835SDaniel Fojt params.ht40_enabled) {
947*a1157835SDaniel Fojt u8 oper_chwidth = hostapd_get_oper_chwidth(hapd->iface->conf);
948*a1157835SDaniel Fojt
949*a1157835SDaniel Fojt if (oper_chwidth == CHANWIDTH_80MHZ)
950*a1157835SDaniel Fojt params.ch_width = 80;
951*a1157835SDaniel Fojt else if (oper_chwidth == CHANWIDTH_160MHZ ||
952*a1157835SDaniel Fojt oper_chwidth == CHANWIDTH_80P80MHZ)
953*a1157835SDaniel Fojt params.ch_width = 160;
954*a1157835SDaniel Fojt }
955*a1157835SDaniel Fojt
956*a1157835SDaniel Fojt ret = hapd->driver->do_acs(hapd->drv_priv, ¶ms);
957*a1157835SDaniel Fojt os_free(channels);
958*a1157835SDaniel Fojt
959*a1157835SDaniel Fojt return ret;
960*a1157835SDaniel Fojt }
961*a1157835SDaniel Fojt
962*a1157835SDaniel Fojt
hostapd_drv_update_dh_ie(struct hostapd_data * hapd,const u8 * peer,u16 reason_code,const u8 * ie,size_t ielen)963*a1157835SDaniel Fojt int hostapd_drv_update_dh_ie(struct hostapd_data *hapd, const u8 *peer,
964*a1157835SDaniel Fojt u16 reason_code, const u8 *ie, size_t ielen)
965*a1157835SDaniel Fojt {
966*a1157835SDaniel Fojt if (!hapd->driver || !hapd->driver->update_dh_ie || !hapd->drv_priv)
967*a1157835SDaniel Fojt return 0;
968*a1157835SDaniel Fojt return hapd->driver->update_dh_ie(hapd->drv_priv, peer, reason_code,
969*a1157835SDaniel Fojt ie, ielen);
970*a1157835SDaniel Fojt }
971