1 /*
2 * hostapd - Driver operations
3 * Copyright (c) 2009-2014, 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 #ifndef AP_DRV_OPS
10 #define AP_DRV_OPS
11 #include "hostapd.h"
12
13 enum wpa_driver_if_type;
14 struct wpa_bss_params;
15 struct wpa_driver_scan_params;
16 struct ieee80211_ht_capabilities;
17 struct ieee80211_vht_capabilities;
18 struct hostapd_freq_params;
19
20 u32 hostapd_sta_flags_to_drv(u32 flags);
21 int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
22 struct wpabuf **beacon,
23 struct wpabuf **proberesp,
24 struct wpabuf **assocresp);
25 void hostapd_free_ap_extra_ies(struct hostapd_data *hapd, struct wpabuf *beacon,
26 struct wpabuf *proberesp,
27 struct wpabuf *assocresp);
28 int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd);
29 int hostapd_set_ap_wps_ie(struct hostapd_data *hapd);
30 int hostapd_set_authorized(struct hostapd_data *hapd,
31 struct sta_info *sta, int authorized);
32 int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta);
33 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
34 int enabled);
35 int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname);
36 int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname);
37 int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
38 const u8 *addr, int aid, int val);
39 int hostapd_sta_add(struct hostapd_data *hapd,
40 const u8 *addr, u16 aid, u16 capability,
41 const u8 *supp_rates, size_t supp_rates_len,
42 u16 listen_interval,
43 const struct ieee80211_ht_capabilities *ht_capab,
44 const struct ieee80211_vht_capabilities *vht_capab,
45 const struct ieee80211_he_capabilities *he_capab,
46 size_t he_capab_len,
47 const struct ieee80211_he_6ghz_band_cap *he_6ghz_capab,
48 u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
49 int set);
50 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled);
51 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
52 size_t elem_len);
53 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len);
54 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len);
55 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
56 const char *ifname, const u8 *addr, void *bss_ctx,
57 void **drv_priv, char *force_ifname, u8 *if_addr,
58 const char *bridge, int use_existing);
59 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
60 const char *ifname);
61 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
62 struct wpa_bss_params *params);
63 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
64 const u8 *addr, int idx, u8 *seq);
65 int hostapd_flush(struct hostapd_data *hapd);
66 int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
67 int freq, int channel, int edmg, u8 edmg_channel,
68 int ht_enabled, int vht_enabled,
69 int he_enabled, int sec_channel_offset, int oper_chwidth,
70 int center_segment0, int center_segment1);
71 int hostapd_set_rts(struct hostapd_data *hapd, int rts);
72 int hostapd_set_frag(struct hostapd_data *hapd, int frag);
73 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
74 int total_flags, int flags_or, int flags_and);
75 int hostapd_sta_set_airtime_weight(struct hostapd_data *hapd, const u8 *addr,
76 unsigned int weight);
77 int hostapd_set_country(struct hostapd_data *hapd, const char *country);
78 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
79 int cw_min, int cw_max, int burst_time);
80 struct hostapd_hw_modes *
81 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
82 u16 *flags, u8 *dfs_domain);
83 int hostapd_driver_commit(struct hostapd_data *hapd);
84 int hostapd_drv_none(struct hostapd_data *hapd);
85 bool hostapd_drv_nl80211(struct hostapd_data *hapd);
86 int hostapd_driver_scan(struct hostapd_data *hapd,
87 struct wpa_driver_scan_params *params);
88 struct wpa_scan_results * hostapd_driver_get_scan_results(
89 struct hostapd_data *hapd);
90 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
91 int duration);
92 int hostapd_drv_set_key(const char *ifname,
93 struct hostapd_data *hapd,
94 enum wpa_alg alg, const u8 *addr,
95 int key_idx, int vlan_id, int set_tx,
96 const u8 *seq, size_t seq_len,
97 const u8 *key, size_t key_len, enum key_flag key_flag);
98 int hostapd_drv_send_mlme(struct hostapd_data *hapd,
99 const void *msg, size_t len, int noack,
100 const u16 *csa_offs, size_t csa_offs_len,
101 int no_encrypt);
102 int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
103 const u8 *addr, int reason);
104 int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
105 const u8 *addr, int reason);
106 int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
107 unsigned int wait, const u8 *dst, const u8 *data,
108 size_t len);
109 int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
110 unsigned int freq,
111 unsigned int wait, const u8 *dst,
112 const u8 *data, size_t len);
113 static inline void
hostapd_drv_send_action_cancel_wait(struct hostapd_data * hapd)114 hostapd_drv_send_action_cancel_wait(struct hostapd_data *hapd)
115 {
116 if (!hapd->driver || !hapd->driver->send_action_cancel_wait ||
117 !hapd->drv_priv)
118 return;
119 hapd->driver->send_action_cancel_wait(hapd->drv_priv);
120 }
121 int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
122 u16 auth_alg);
123 int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
124 u16 seq, u16 status, const u8 *ie, size_t len);
125 int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
126 int reassoc, u16 status, const u8 *ie, size_t len);
127 int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
128 u8 *tspec_ie, size_t tspec_ielen);
129 int hostapd_start_dfs_cac(struct hostapd_iface *iface,
130 enum hostapd_hw_mode mode, int freq,
131 int channel, int ht_enabled, int vht_enabled,
132 int he_enabled,
133 int sec_channel_offset, int oper_chwidth,
134 int center_segment0, int center_segment1);
135 int hostapd_drv_do_acs(struct hostapd_data *hapd);
136 int hostapd_drv_update_dh_ie(struct hostapd_data *hapd, const u8 *peer,
137 u16 reason_code, const u8 *ie, size_t ielen);
138 int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable);
139 int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len);
140
141
142 #include "drivers/driver.h"
143
144 int hostapd_drv_wnm_oper(struct hostapd_data *hapd,
145 enum wnm_oper oper, const u8 *peer,
146 u8 *buf, u16 *buf_len);
147
148 int hostapd_drv_set_qos_map(struct hostapd_data *hapd, const u8 *qos_map_set,
149 u8 qos_map_set_len);
150
151 void hostapd_get_ext_capa(struct hostapd_iface *iface);
152
hostapd_drv_set_countermeasures(struct hostapd_data * hapd,int enabled)153 static inline int hostapd_drv_set_countermeasures(struct hostapd_data *hapd,
154 int enabled)
155 {
156 if (hapd->driver == NULL ||
157 hapd->driver->hapd_set_countermeasures == NULL)
158 return 0;
159 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
160 }
161
hostapd_drv_set_sta_vlan(const char * ifname,struct hostapd_data * hapd,const u8 * addr,int vlan_id)162 static inline int hostapd_drv_set_sta_vlan(const char *ifname,
163 struct hostapd_data *hapd,
164 const u8 *addr, int vlan_id)
165 {
166 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
167 return 0;
168 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname,
169 vlan_id);
170 }
171
hostapd_drv_get_inact_sec(struct hostapd_data * hapd,const u8 * addr)172 static inline int hostapd_drv_get_inact_sec(struct hostapd_data *hapd,
173 const u8 *addr)
174 {
175 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
176 return 0;
177 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
178 }
179
hostapd_drv_sta_remove(struct hostapd_data * hapd,const u8 * addr)180 static inline int hostapd_drv_sta_remove(struct hostapd_data *hapd,
181 const u8 *addr)
182 {
183 if (!hapd->driver || !hapd->driver->sta_remove || !hapd->drv_priv)
184 return 0;
185 return hapd->driver->sta_remove(hapd->drv_priv, addr);
186 }
187
hostapd_drv_hapd_send_eapol(struct hostapd_data * hapd,const u8 * addr,const u8 * data,size_t data_len,int encrypt,u32 flags)188 static inline int hostapd_drv_hapd_send_eapol(struct hostapd_data *hapd,
189 const u8 *addr, const u8 *data,
190 size_t data_len, int encrypt,
191 u32 flags)
192 {
193 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
194 return 0;
195 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
196 data_len, encrypt,
197 hapd->own_addr, flags);
198 }
199
hostapd_drv_read_sta_data(struct hostapd_data * hapd,struct hostap_sta_driver_data * data,const u8 * addr)200 static inline int hostapd_drv_read_sta_data(
201 struct hostapd_data *hapd, struct hostap_sta_driver_data *data,
202 const u8 *addr)
203 {
204 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
205 return -1;
206 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
207 }
208
hostapd_drv_sta_clear_stats(struct hostapd_data * hapd,const u8 * addr)209 static inline int hostapd_drv_sta_clear_stats(struct hostapd_data *hapd,
210 const u8 *addr)
211 {
212 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
213 return 0;
214 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
215 }
216
hostapd_drv_set_acl(struct hostapd_data * hapd,struct hostapd_acl_params * params)217 static inline int hostapd_drv_set_acl(struct hostapd_data *hapd,
218 struct hostapd_acl_params *params)
219 {
220 if (hapd->driver == NULL || hapd->driver->set_acl == NULL)
221 return 0;
222 return hapd->driver->set_acl(hapd->drv_priv, params);
223 }
224
hostapd_drv_set_ap(struct hostapd_data * hapd,struct wpa_driver_ap_params * params)225 static inline int hostapd_drv_set_ap(struct hostapd_data *hapd,
226 struct wpa_driver_ap_params *params)
227 {
228 if (hapd->driver == NULL || hapd->driver->set_ap == NULL)
229 return 0;
230 return hapd->driver->set_ap(hapd->drv_priv, params);
231 }
232
hostapd_drv_set_radius_acl_auth(struct hostapd_data * hapd,const u8 * mac,int accepted,u32 session_timeout)233 static inline int hostapd_drv_set_radius_acl_auth(struct hostapd_data *hapd,
234 const u8 *mac, int accepted,
235 u32 session_timeout)
236 {
237 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
238 return 0;
239 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
240 session_timeout);
241 }
242
hostapd_drv_set_radius_acl_expire(struct hostapd_data * hapd,const u8 * mac)243 static inline int hostapd_drv_set_radius_acl_expire(struct hostapd_data *hapd,
244 const u8 *mac)
245 {
246 if (hapd->driver == NULL ||
247 hapd->driver->set_radius_acl_expire == NULL)
248 return 0;
249 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
250 }
251
hostapd_drv_set_authmode(struct hostapd_data * hapd,int auth_algs)252 static inline int hostapd_drv_set_authmode(struct hostapd_data *hapd,
253 int auth_algs)
254 {
255 if (hapd->driver == NULL || hapd->driver->set_authmode == NULL)
256 return 0;
257 return hapd->driver->set_authmode(hapd->drv_priv, auth_algs);
258 }
259
hostapd_drv_poll_client(struct hostapd_data * hapd,const u8 * own_addr,const u8 * addr,int qos)260 static inline void hostapd_drv_poll_client(struct hostapd_data *hapd,
261 const u8 *own_addr, const u8 *addr,
262 int qos)
263 {
264 if (hapd->driver == NULL || hapd->driver->poll_client == NULL)
265 return;
266 hapd->driver->poll_client(hapd->drv_priv, own_addr, addr, qos);
267 }
268
hostapd_drv_get_survey(struct hostapd_data * hapd,unsigned int freq)269 static inline int hostapd_drv_get_survey(struct hostapd_data *hapd,
270 unsigned int freq)
271 {
272 if (hapd->driver == NULL)
273 return -1;
274 if (!hapd->driver->get_survey)
275 return -1;
276 return hapd->driver->get_survey(hapd->drv_priv, freq);
277 }
278
hostapd_get_country(struct hostapd_data * hapd,char * alpha2)279 static inline int hostapd_get_country(struct hostapd_data *hapd, char *alpha2)
280 {
281 if (hapd->driver == NULL || hapd->driver->get_country == NULL)
282 return -1;
283 return hapd->driver->get_country(hapd->drv_priv, alpha2);
284 }
285
hostapd_drv_get_radio_name(struct hostapd_data * hapd)286 static inline const char * hostapd_drv_get_radio_name(struct hostapd_data *hapd)
287 {
288 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
289 hapd->driver->get_radio_name == NULL)
290 return NULL;
291 return hapd->driver->get_radio_name(hapd->drv_priv);
292 }
293
hostapd_drv_switch_channel(struct hostapd_data * hapd,struct csa_settings * settings)294 static inline int hostapd_drv_switch_channel(struct hostapd_data *hapd,
295 struct csa_settings *settings)
296 {
297 if (hapd->driver == NULL || hapd->driver->switch_channel == NULL ||
298 hapd->drv_priv == NULL)
299 return -1;
300
301 return hapd->driver->switch_channel(hapd->drv_priv, settings);
302 }
303
hostapd_drv_status(struct hostapd_data * hapd,char * buf,size_t buflen)304 static inline int hostapd_drv_status(struct hostapd_data *hapd, char *buf,
305 size_t buflen)
306 {
307 if (!hapd->driver || !hapd->driver->status || !hapd->drv_priv)
308 return -1;
309 return hapd->driver->status(hapd->drv_priv, buf, buflen);
310 }
311
hostapd_drv_br_add_ip_neigh(struct hostapd_data * hapd,int version,const u8 * ipaddr,int prefixlen,const u8 * addr)312 static inline int hostapd_drv_br_add_ip_neigh(struct hostapd_data *hapd,
313 int version, const u8 *ipaddr,
314 int prefixlen, const u8 *addr)
315 {
316 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
317 hapd->driver->br_add_ip_neigh == NULL)
318 return -1;
319 return hapd->driver->br_add_ip_neigh(hapd->drv_priv, version, ipaddr,
320 prefixlen, addr);
321 }
322
hostapd_drv_br_delete_ip_neigh(struct hostapd_data * hapd,u8 version,const u8 * ipaddr)323 static inline int hostapd_drv_br_delete_ip_neigh(struct hostapd_data *hapd,
324 u8 version, const u8 *ipaddr)
325 {
326 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
327 hapd->driver->br_delete_ip_neigh == NULL)
328 return -1;
329 return hapd->driver->br_delete_ip_neigh(hapd->drv_priv, version,
330 ipaddr);
331 }
332
hostapd_drv_br_port_set_attr(struct hostapd_data * hapd,enum drv_br_port_attr attr,unsigned int val)333 static inline int hostapd_drv_br_port_set_attr(struct hostapd_data *hapd,
334 enum drv_br_port_attr attr,
335 unsigned int val)
336 {
337 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
338 hapd->driver->br_port_set_attr == NULL)
339 return -1;
340 return hapd->driver->br_port_set_attr(hapd->drv_priv, attr, val);
341 }
342
hostapd_drv_br_set_net_param(struct hostapd_data * hapd,enum drv_br_net_param param,unsigned int val)343 static inline int hostapd_drv_br_set_net_param(struct hostapd_data *hapd,
344 enum drv_br_net_param param,
345 unsigned int val)
346 {
347 if (hapd->driver == NULL || hapd->drv_priv == NULL ||
348 hapd->driver->br_set_net_param == NULL)
349 return -1;
350 return hapd->driver->br_set_net_param(hapd->drv_priv, param, val);
351 }
352
hostapd_drv_vendor_cmd(struct hostapd_data * hapd,int vendor_id,int subcmd,const u8 * data,size_t data_len,enum nested_attr nested_attr_flag,struct wpabuf * buf)353 static inline int hostapd_drv_vendor_cmd(struct hostapd_data *hapd,
354 int vendor_id, int subcmd,
355 const u8 *data, size_t data_len,
356 enum nested_attr nested_attr_flag,
357 struct wpabuf *buf)
358 {
359 if (hapd->driver == NULL || hapd->driver->vendor_cmd == NULL)
360 return -1;
361 return hapd->driver->vendor_cmd(hapd->drv_priv, vendor_id, subcmd, data,
362 data_len, nested_attr_flag, buf);
363 }
364
hostapd_drv_stop_ap(struct hostapd_data * hapd)365 static inline int hostapd_drv_stop_ap(struct hostapd_data *hapd)
366 {
367 if (!hapd->driver || !hapd->driver->stop_ap || !hapd->drv_priv)
368 return 0;
369 return hapd->driver->stop_ap(hapd->drv_priv);
370 }
371
hostapd_drv_channel_info(struct hostapd_data * hapd,struct wpa_channel_info * ci)372 static inline int hostapd_drv_channel_info(struct hostapd_data *hapd,
373 struct wpa_channel_info *ci)
374 {
375 if (!hapd->driver || !hapd->driver->channel_info)
376 return -1;
377 return hapd->driver->channel_info(hapd->drv_priv, ci);
378 }
379
380 static inline int
hostapd_drv_send_external_auth_status(struct hostapd_data * hapd,struct external_auth * params)381 hostapd_drv_send_external_auth_status(struct hostapd_data *hapd,
382 struct external_auth *params)
383 {
384 if (!hapd->driver || !hapd->drv_priv ||
385 !hapd->driver->send_external_auth_status)
386 return -1;
387 return hapd->driver->send_external_auth_status(hapd->drv_priv, params);
388 }
389
390 static inline int
hostapd_drv_set_band(struct hostapd_data * hapd,u32 band_mask)391 hostapd_drv_set_band(struct hostapd_data *hapd, u32 band_mask)
392 {
393 if (!hapd->driver || !hapd->drv_priv || !hapd->driver->set_band)
394 return -1;
395 return hapd->driver->set_band(hapd->drv_priv, band_mask);
396 }
397
398 #ifdef ANDROID
hostapd_drv_driver_cmd(struct hostapd_data * hapd,char * cmd,char * buf,size_t buf_len)399 static inline int hostapd_drv_driver_cmd(struct hostapd_data *hapd,
400 char *cmd, char *buf, size_t buf_len)
401 {
402 if (!hapd->driver->driver_cmd)
403 return -1;
404 return hapd->driver->driver_cmd(hapd->drv_priv, cmd, buf, buf_len);
405 }
406 #endif /* ANDROID */
407
408 #ifdef CONFIG_TESTING_OPTIONS
409 static inline int
hostapd_drv_register_frame(struct hostapd_data * hapd,u16 type,const u8 * match,size_t match_len,bool multicast)410 hostapd_drv_register_frame(struct hostapd_data *hapd, u16 type,
411 const u8 *match, size_t match_len,
412 bool multicast)
413 {
414 if (!hapd->driver || !hapd->drv_priv || !hapd->driver->register_frame)
415 return -1;
416 return hapd->driver->register_frame(hapd->drv_priv, type, match,
417 match_len, multicast);
418 }
419 #endif /* CONFIG_TESTING_OPTIONS */
420
421 #endif /* AP_DRV_OPS */
422