Removed hostapd_new_assoc_sta() from driver wrapper API
[libeap.git] / hostapd / driver_i.h
1 /*
2  * hostapd - internal driver interface wrappers
3  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
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
18 #include "drivers/driver.h"
19 #include "config.h"
20
21 static inline void *
22 hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
23 {
24         struct wpa_init_params params;
25         void *ret;
26         size_t i;
27
28         if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
29                 return NULL;
30
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;
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)
42                 return NULL;
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         }
48
49         params.own_addr = hapd->own_addr;
50
51         ret = hapd->driver->hapd_init(hapd, &params);
52         os_free(params.bridge);
53
54         return ret;
55 }
56
57 static inline void
58 hostapd_driver_deinit(struct hostapd_data *hapd)
59 {
60         if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
61                 return;
62         hapd->driver->hapd_deinit(hapd->drv_priv);
63 }
64
65 static inline int
66 hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
67 {
68         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
69                 return 0;
70         return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
71 }
72
73 static inline int
74 hostapd_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
82 static inline int
83 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
84                    const u8 *addr, int idx, u8 *seq)
85 {
86         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
87                 return 0;
88         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
89                                         seq);
90 }
91
92 static inline int
93 hostapd_flush(struct hostapd_data *hapd)
94 {
95         if (hapd->driver == NULL || hapd->driver->flush == NULL)
96                 return 0;
97         return hapd->driver->flush(hapd->drv_priv);
98 }
99
100 static inline int
101 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
102                          size_t elem_len)
103 {
104         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
105                 return 0;
106         return hapd->driver->set_generic_elem(hapd->conf->iface,
107                                               hapd->drv_priv, elem, elem_len);
108 }
109
110 static inline int
111 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
112 {
113         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
114                 return 0;
115         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
116                                         reason);
117 }
118
119 static inline int
120 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
121 {
122         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
123                 return 0;
124         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
125                                           reason);
126 }
127
128 static inline int
129 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
130 {
131         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
132                 return 0;
133         return hapd->driver->sta_remove(hapd->drv_priv, addr);
134 }
135
136 static inline int
137 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
138 {
139         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
140                 return 0;
141         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
142                                            buf, len);
143 }
144
145 static inline int
146 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
147 {
148         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
149                 return 0;
150         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
151                                            buf, len);
152 }
153
154 static inline int
155 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
156 {
157         if (hapd->driver == NULL ||
158             hapd->driver->hapd_set_countermeasures == NULL)
159                 return 0;
160         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
161 }
162
163 static inline int
164 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
165                 u16 aid, u16 capability, const u8 *supp_rates,
166                 size_t supp_rates_len, u16 listen_interval,
167                 const struct ieee80211_ht_capabilities *ht_capabilities)
168 {
169         struct hostapd_sta_add_params params;
170
171         if (hapd->driver == NULL)
172                 return 0;
173         if (hapd->driver->sta_add == NULL)
174                 return 0;
175
176         os_memset(&params, 0, sizeof(params));
177         params.addr = addr;
178         params.aid = aid;
179         params.capability = capability;
180         params.supp_rates = supp_rates;
181         params.supp_rates_len = supp_rates_len;
182         params.listen_interval = listen_interval;
183         params.ht_capabilities = ht_capabilities;
184         return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
185 }
186
187 static inline int
188 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
189 {
190         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
191                 return 0;
192         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
193 }
194
195 static inline int
196 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
197                  int ht_enabled, int sec_channel_offset)
198 {
199         struct hostapd_freq_params data;
200         if (hapd->driver == NULL)
201                 return 0;
202         if (hapd->driver->set_freq == NULL)
203                 return 0;
204         os_memset(&data, 0, sizeof(data));
205         data.mode = mode;
206         data.freq = freq;
207         data.channel = channel;
208         data.ht_enabled = ht_enabled;
209         data.sec_channel_offset = sec_channel_offset;
210         return hapd->driver->set_freq(hapd->drv_priv, &data);
211 }
212
213 static inline int
214 hostapd_set_rts(struct hostapd_data *hapd, int rts)
215 {
216         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
217                 return 0;
218         return hapd->driver->set_rts(hapd->drv_priv, rts);
219 }
220
221 static inline int
222 hostapd_set_frag(struct hostapd_data *hapd, int frag)
223 {
224         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
225                 return 0;
226         return hapd->driver->set_frag(hapd->drv_priv, frag);
227 }
228
229 static inline int
230 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
231                       int total_flags, int flags_or, int flags_and)
232 {
233         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
234                 return 0;
235         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
236                                            flags_or, flags_and);
237 }
238
239 static inline int
240 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
241                       int *basic_rates, int mode)
242 {
243         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
244                 return 0;
245         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
246                                            basic_rates, mode);
247 }
248
249 static inline int
250 hostapd_set_country(struct hostapd_data *hapd, const char *country)
251 {
252         if (hapd->driver == NULL ||
253             hapd->driver->set_country == NULL)
254                 return 0;
255         return hapd->driver->set_country(hapd->drv_priv, country);
256 }
257
258 static inline int
259 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
260                    const u8 *head, size_t head_len,
261                    const u8 *tail, size_t tail_len, int dtim_period,
262                    int beacon_int)
263 {
264         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
265                 return 0;
266         return hapd->driver->set_beacon(ifname, hapd->drv_priv,
267                                         head, head_len, tail, tail_len,
268                                         dtim_period, beacon_int);
269 }
270
271 static inline int
272 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
273 {
274         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
275                 return 0;
276         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
277 }
278
279 static inline int
280 hostapd_set_preamble(struct hostapd_data *hapd, int value)
281 {
282         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
283                 return 0;
284         return hapd->driver->set_preamble(hapd->drv_priv, value);
285 }
286
287 static inline int
288 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
289 {
290         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
291                 return 0;
292         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
293 }
294
295 static inline int
296 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
297                             int cw_min, int cw_max, int burst_time)
298 {
299         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
300                 return 0;
301         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
302                                                  cw_min, cw_max, burst_time);
303 }
304
305 static inline int
306 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
307                        const u8 *mask)
308 {
309         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
310                 return 1;
311         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
312 }
313
314 static inline int
315 hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
316                const char *ifname, const u8 *addr, void *bss_ctx)
317 {
318         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
319                 return -1;
320         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
321                                     ifname, addr, bss_ctx);
322 }
323
324 static inline int
325 hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
326                   const char *ifname)
327 {
328         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
329                 return -1;
330         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
331 }
332
333 static inline struct hostapd_hw_modes *
334 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
335                             u16 *flags)
336 {
337         if (hapd->driver == NULL ||
338             hapd->driver->get_hw_feature_data == NULL)
339                 return NULL;
340         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
341                                                  flags);
342 }
343
344 static inline int
345 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
346                      const u8 *addr, int vlan_id)
347 {
348         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
349                 return 0;
350         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
351 }
352
353 static inline int
354 hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr, int aid,
355                     int val)
356 {
357         if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
358                 return 0;
359         return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val);
360 }
361
362 static inline int
363 hostapd_driver_commit(struct hostapd_data *hapd)
364 {
365         if (hapd->driver == NULL || hapd->driver->commit == NULL)
366                 return 0;
367         return hapd->driver->commit(hapd->drv_priv);
368 }
369
370 static inline int
371 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
372                             int accepted, u32 session_timeout)
373 {
374         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
375                 return 0;
376         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
377                                                  session_timeout);
378 }
379
380 static inline int
381 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
382 {
383         if (hapd->driver == NULL ||
384             hapd->driver->set_radius_acl_expire == NULL)
385                 return 0;
386         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
387 }
388
389 static inline int
390 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
391                       const u8 *ht_capab, size_t ht_capab_len,
392                       const u8 *ht_oper, size_t ht_oper_len)
393 {
394         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
395             ht_capab == NULL || ht_oper == NULL)
396                 return 0;
397         return hapd->driver->set_ht_params(
398                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
399                 ht_oper, ht_oper_len);
400 }
401
402 static inline int
403 hostapd_drv_none(struct hostapd_data *hapd)
404 {
405         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
406 }
407
408 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
409                                       struct wpa_driver_scan_params *params)
410 {
411         if (hapd->driver && hapd->driver->scan2)
412                 return hapd->driver->scan2(hapd->drv_priv, params);
413         return -1;
414 }
415
416 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
417         struct hostapd_data *hapd)
418 {
419         if (hapd->driver && hapd->driver->get_scan_results2)
420                 return hapd->driver->get_scan_results2(hapd->drv_priv);
421         return NULL;
422 }
423
424 #endif /* DRIVER_I_H */