]> git.ipfire.org Git - thirdparty/hostap.git/blame - hostapd/driver_i.h
Merge driver ops set_wps_beacon_ie and set_wps_probe_resp_ie
[thirdparty/hostap.git] / hostapd / driver_i.h
CommitLineData
bfddd95c
JM
1/*
2 * hostapd - internal driver interface wrappers
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
bfddd95c
JM
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
15#ifndef DRIVER_I_H
16#define DRIVER_I_H
17
c5121837 18#include "drivers/driver.h"
b1c0e297 19#include "config.h"
bfddd95c
JM
20
21static inline void *
92f475b4 22hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
bfddd95c 23{
92f475b4
JM
24 struct wpa_init_params params;
25 void *ret;
26 size_t i;
27
c5121837 28 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
bfddd95c 29 return NULL;
bfddd95c 30
92f475b4
JM
31 os_memset(&params, 0, sizeof(params));
32 params.bssid = bssid;
33 params.ifname = hapd->conf->iface;
34 params.ssid = (const u8 *) hapd->conf->ssid.ssid;
35 params.ssid_len = hapd->conf->ssid.ssid_len;
36 params.test_socket = hapd->conf->test_socket;
37 params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
92f475b4
JM
38
39 params.num_bridge = hapd->iface->num_bss;
40 params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
41 if (params.bridge == NULL)
bfddd95c 42 return NULL;
92f475b4
JM
43 for (i = 0; i < hapd->iface->num_bss; i++) {
44 struct hostapd_data *bss = hapd->iface->bss[i];
45 if (bss->conf->bridge[0])
46 params.bridge[i] = bss->conf->bridge;
47 }
412036f5
JM
48
49 params.own_addr = hapd->own_addr;
50
92f475b4
JM
51 ret = hapd->driver->hapd_init(hapd, &params);
52 os_free(params.bridge);
53
54 return ret;
bfddd95c
JM
55}
56
57static inline void
58hostapd_driver_deinit(struct hostapd_data *hapd)
59{
c5121837 60 if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
bfddd95c 61 return;
c5121837 62 hapd->driver->hapd_deinit(hapd->drv_priv);
bfddd95c
JM
63}
64
bfddd95c 65static inline int
e3bd3912 66hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
bfddd95c
JM
67{
68 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
69 return 0;
e3bd3912 70 return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
bfddd95c
JM
71}
72
73static inline int
74hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
75{
76 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
77 return 0;
78 return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
79 enabled);
80}
81
82static inline int
89d39d9d
JM
83hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
84 wpa_alg alg, const u8 *addr, int key_idx,
85 int set_tx, const u8 *seq, size_t seq_len,
86 const u8 *key, size_t key_len)
bfddd95c 87{
642187d6 88 if (hapd->driver == NULL || hapd->driver->set_key == NULL)
bfddd95c 89 return 0;
642187d6
JM
90 return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
91 key_idx, set_tx, seq, seq_len, key,
92 key_len);
bfddd95c
JM
93}
94
95static inline int
96hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
97 const u8 *addr, int idx, u8 *seq)
98{
99 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
100 return 0;
101 return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
102 seq);
103}
104
bfddd95c
JM
105static inline int
106hostapd_flush(struct hostapd_data *hapd)
107{
108 if (hapd->driver == NULL || hapd->driver->flush == NULL)
109 return 0;
110 return hapd->driver->flush(hapd->drv_priv);
111}
112
113static inline int
114hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
115 size_t elem_len)
116{
117 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
118 return 0;
119 return hapd->driver->set_generic_elem(hapd->conf->iface,
120 hapd->drv_priv, elem, elem_len);
121}
122
123static inline int
124hostapd_read_sta_data(struct hostapd_data *hapd,
125 struct hostap_sta_driver_data *data, const u8 *addr)
126{
127 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
128 return -1;
129 return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
130}
131
132static inline int
133hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
134 size_t data_len, int encrypt)
135{
c5121837 136 if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
bfddd95c 137 return 0;
c5121837
JM
138 return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
139 data_len, encrypt,
140 hapd->own_addr);
bfddd95c
JM
141}
142
143static inline int
144hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
145{
146 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
147 return 0;
731723a5
JM
148 return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
149 reason);
bfddd95c
JM
150}
151
152static inline int
153hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
154{
155 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
156 return 0;
731723a5
JM
157 return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
158 reason);
bfddd95c
JM
159}
160
161static inline int
162hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
163{
164 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
165 return 0;
166 return hapd->driver->sta_remove(hapd->drv_priv, addr);
167}
168
169static inline int
170hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
171{
c5121837 172 if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
bfddd95c 173 return 0;
c5121837
JM
174 return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
175 buf, len);
bfddd95c
JM
176}
177
178static inline int
179hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
180{
c5121837 181 if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
bfddd95c 182 return 0;
c5121837
JM
183 return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
184 buf, len);
bfddd95c
JM
185}
186
187static inline int
83421302 188hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
bfddd95c 189{
9f324b61 190 if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
bfddd95c 191 return 0;
9f324b61 192 return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
bfddd95c
JM
193}
194
bfddd95c
JM
195static inline int
196hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
197{
c5121837
JM
198 if (hapd->driver == NULL ||
199 hapd->driver->hapd_set_countermeasures == NULL)
bfddd95c 200 return 0;
c5121837 201 return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
bfddd95c
JM
202}
203
204static inline int
205hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
206 u16 aid, u16 capability, const u8 *supp_rates,
60c8cfb4 207 size_t supp_rates_len, u16 listen_interval,
fc4e2d95 208 const struct ieee80211_ht_capabilities *ht_capabilities)
bfddd95c 209{
fb86519d
JM
210 struct hostapd_sta_add_params params;
211
bfddd95c
JM
212 if (hapd->driver == NULL)
213 return 0;
bfddd95c
JM
214 if (hapd->driver->sta_add == NULL)
215 return 0;
fb86519d
JM
216
217 os_memset(&params, 0, sizeof(params));
218 params.addr = addr;
219 params.aid = aid;
220 params.capability = capability;
221 params.supp_rates = supp_rates;
222 params.supp_rates_len = supp_rates_len;
fb86519d
JM
223 params.listen_interval = listen_interval;
224 params.ht_capabilities = ht_capabilities;
225 return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
bfddd95c
JM
226}
227
228static inline int
229hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
230{
231 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
232 return 0;
233 return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
234}
235
236static inline int
9c6d8e1d
JM
237hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
238 int ht_enabled, int sec_channel_offset)
bfddd95c 239{
909a6ef0 240 struct hostapd_freq_params data;
bfddd95c
JM
241 if (hapd->driver == NULL)
242 return 0;
bfddd95c
JM
243 if (hapd->driver->set_freq == NULL)
244 return 0;
909a6ef0
JM
245 os_memset(&data, 0, sizeof(data));
246 data.mode = mode;
247 data.freq = freq;
9c6d8e1d 248 data.channel = channel;
909a6ef0
JM
249 data.ht_enabled = ht_enabled;
250 data.sec_channel_offset = sec_channel_offset;
251 return hapd->driver->set_freq(hapd->drv_priv, &data);
bfddd95c
JM
252}
253
254static inline int
255hostapd_set_rts(struct hostapd_data *hapd, int rts)
256{
257 if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
258 return 0;
259 return hapd->driver->set_rts(hapd->drv_priv, rts);
260}
261
bfddd95c
JM
262static inline int
263hostapd_set_frag(struct hostapd_data *hapd, int frag)
264{
265 if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
266 return 0;
267 return hapd->driver->set_frag(hapd->drv_priv, frag);
268}
269
bfddd95c
JM
270static inline int
271hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
272 int total_flags, int flags_or, int flags_and)
273{
274 if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
275 return 0;
276 return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
277 flags_or, flags_and);
278}
279
280static inline int
281hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
282 int *basic_rates, int mode)
283{
284 if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
285 return 0;
286 return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
287 basic_rates, mode);
288}
289
bfddd95c
JM
290static inline int
291hostapd_set_country(struct hostapd_data *hapd, const char *country)
292{
293 if (hapd->driver == NULL ||
e785c2ba 294 hapd->driver->set_country == NULL)
bfddd95c 295 return 0;
e785c2ba 296 return hapd->driver->set_country(hapd->drv_priv, country);
bfddd95c
JM
297}
298
bfddd95c
JM
299static inline int
300hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
301{
302 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
303 return 0;
304 return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
305}
306
307static inline int
308hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
74f2ad32 309 const u8 *head, size_t head_len,
5d674872
JM
310 const u8 *tail, size_t tail_len, int dtim_period,
311 int beacon_int)
bfddd95c 312{
5d674872 313 if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
bfddd95c 314 return 0;
5d674872
JM
315 return hapd->driver->set_beacon(ifname, hapd->drv_priv,
316 head, head_len, tail, tail_len,
317 dtim_period, beacon_int);
bfddd95c
JM
318}
319
bfddd95c
JM
320static inline int
321hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
322{
323 if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
324 return 0;
325 return hapd->driver->set_cts_protect(hapd->drv_priv, value);
326}
327
bfddd95c
JM
328static inline int
329hostapd_set_preamble(struct hostapd_data *hapd, int value)
330{
331 if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
332 return 0;
333 return hapd->driver->set_preamble(hapd->drv_priv, value);
334}
335
336static inline int
337hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
338{
339 if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
340 return 0;
341 return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
342}
343
344static inline int
345hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
346 int cw_min, int cw_max, int burst_time)
347{
348 if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
349 return 0;
350 return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
351 cw_min, cw_max, burst_time);
352}
353
bfddd95c
JM
354static inline int
355hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
356 const u8 *mask)
357{
358 if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
359 return 1;
360 return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
361}
362
363static inline int
22a7c9d7 364hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
8043e725 365 const char *ifname, const u8 *addr, void *bss_ctx)
bfddd95c
JM
366{
367 if (hapd->driver == NULL || hapd->driver->if_add == NULL)
368 return -1;
369 return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
8043e725 370 ifname, addr, bss_ctx);
bfddd95c
JM
371}
372
bfddd95c 373static inline int
22a7c9d7
JM
374hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
375 const char *ifname)
bfddd95c
JM
376{
377 if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
378 return -1;
22a7c9d7 379 return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
bfddd95c
JM
380}
381
bfddd95c
JM
382static inline struct hostapd_hw_modes *
383hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
384 u16 *flags)
385{
c5121837 386 if (hapd->driver == NULL ||
c3965310 387 hapd->driver->get_hw_feature_data == NULL)
bfddd95c 388 return NULL;
c3965310
JM
389 return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
390 flags);
bfddd95c
JM
391}
392
393static inline int
394hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
395 const u8 *addr, int vlan_id)
396{
397 if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
398 return 0;
399 return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
400}
401
fbbfcbac
FF
402static inline int
403hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr, int aid,
404 int val)
405{
406 if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
407 return 0;
408 return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val);
409}
410
bfddd95c
JM
411static inline int
412hostapd_driver_commit(struct hostapd_data *hapd)
413{
414 if (hapd->driver == NULL || hapd->driver->commit == NULL)
415 return 0;
416 return hapd->driver->commit(hapd->drv_priv);
417}
418
419static inline int
420hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
421 int accepted, u32 session_timeout)
422{
423 if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
424 return 0;
425 return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
426 session_timeout);
427}
428
429static inline int
430hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
431{
432 if (hapd->driver == NULL ||
433 hapd->driver->set_radius_acl_expire == NULL)
434 return 0;
435 return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
436}
437
bfddd95c
JM
438static inline int
439hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
440 const u8 *ht_capab, size_t ht_capab_len,
441 const u8 *ht_oper, size_t ht_oper_len)
442{
443 if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
444 ht_capab == NULL || ht_oper == NULL)
445 return 0;
446 return hapd->driver->set_ht_params(
447 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
448 ht_oper, ht_oper_len);
449}
bfddd95c
JM
450
451static inline int
452hostapd_drv_none(struct hostapd_data *hapd)
453{
454 return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
455}
456
ad1e68e6
JM
457static inline int hostapd_driver_scan(struct hostapd_data *hapd,
458 struct wpa_driver_scan_params *params)
459{
460 if (hapd->driver && hapd->driver->scan2)
461 return hapd->driver->scan2(hapd->drv_priv, params);
462 return -1;
463}
464
465static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
466 struct hostapd_data *hapd)
467{
468 if (hapd->driver && hapd->driver->get_scan_results2)
469 return hapd->driver->get_scan_results2(hapd->drv_priv);
470 return NULL;
5eb4e3d0
JM
471}
472
bfddd95c 473#endif /* DRIVER_I_H */