Use hostapd driver op wrapper for send_mgmt_frame
[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_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)
87 {
88         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
89                 return 0;
90         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
91                                      key_idx, set_tx, seq, seq_len, key,
92                                      key_len);
93 }
94
95 static inline int
96 hostapd_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
105 static inline int
106 hostapd_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
113 static inline int
114 hostapd_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
123 static inline int
124 hostapd_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
132 static inline int
133 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
134                    size_t data_len, int encrypt)
135 {
136         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
137                 return 0;
138         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
139                                              data_len, encrypt,
140                                              hapd->own_addr);
141 }
142
143 static inline int
144 hostapd_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;
148         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
149                                         reason);
150 }
151
152 static inline int
153 hostapd_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;
157         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
158                                           reason);
159 }
160
161 static inline int
162 hostapd_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
169 static inline int
170 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
171 {
172         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
173                 return 0;
174         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
175                                            buf, len);
176 }
177
178 static inline int
179 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
180 {
181         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
182                 return 0;
183         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
184                                            buf, len);
185 }
186
187 static inline int
188 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
189 {
190         if (hapd->driver == NULL ||
191             hapd->driver->hapd_set_countermeasures == NULL)
192                 return 0;
193         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
194 }
195
196 static inline int
197 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
198                 u16 aid, u16 capability, const u8 *supp_rates,
199                 size_t supp_rates_len, u16 listen_interval,
200                 const struct ieee80211_ht_capabilities *ht_capabilities)
201 {
202         struct hostapd_sta_add_params params;
203
204         if (hapd->driver == NULL)
205                 return 0;
206         if (hapd->driver->sta_add == NULL)
207                 return 0;
208
209         os_memset(&params, 0, sizeof(params));
210         params.addr = addr;
211         params.aid = aid;
212         params.capability = capability;
213         params.supp_rates = supp_rates;
214         params.supp_rates_len = supp_rates_len;
215         params.listen_interval = listen_interval;
216         params.ht_capabilities = ht_capabilities;
217         return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
218 }
219
220 static inline int
221 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
222 {
223         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
224                 return 0;
225         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
226 }
227
228 static inline int
229 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
230                  int ht_enabled, int sec_channel_offset)
231 {
232         struct hostapd_freq_params data;
233         if (hapd->driver == NULL)
234                 return 0;
235         if (hapd->driver->set_freq == NULL)
236                 return 0;
237         os_memset(&data, 0, sizeof(data));
238         data.mode = mode;
239         data.freq = freq;
240         data.channel = channel;
241         data.ht_enabled = ht_enabled;
242         data.sec_channel_offset = sec_channel_offset;
243         return hapd->driver->set_freq(hapd->drv_priv, &data);
244 }
245
246 static inline int
247 hostapd_set_rts(struct hostapd_data *hapd, int rts)
248 {
249         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
250                 return 0;
251         return hapd->driver->set_rts(hapd->drv_priv, rts);
252 }
253
254 static inline int
255 hostapd_set_frag(struct hostapd_data *hapd, int frag)
256 {
257         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
258                 return 0;
259         return hapd->driver->set_frag(hapd->drv_priv, frag);
260 }
261
262 static inline int
263 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
264                       int total_flags, int flags_or, int flags_and)
265 {
266         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
267                 return 0;
268         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
269                                            flags_or, flags_and);
270 }
271
272 static inline int
273 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
274                       int *basic_rates, int mode)
275 {
276         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
277                 return 0;
278         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
279                                            basic_rates, mode);
280 }
281
282 static inline int
283 hostapd_set_country(struct hostapd_data *hapd, const char *country)
284 {
285         if (hapd->driver == NULL ||
286             hapd->driver->set_country == NULL)
287                 return 0;
288         return hapd->driver->set_country(hapd->drv_priv, country);
289 }
290
291 static inline int
292 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
293 {
294         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
295                 return 0;
296         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
297 }
298
299 static inline int
300 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
301                    const u8 *head, size_t head_len,
302                    const u8 *tail, size_t tail_len, int dtim_period,
303                    int beacon_int)
304 {
305         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
306                 return 0;
307         return hapd->driver->set_beacon(ifname, hapd->drv_priv,
308                                         head, head_len, tail, tail_len,
309                                         dtim_period, beacon_int);
310 }
311
312 static inline int
313 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
314 {
315         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
316                 return 0;
317         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
318 }
319
320 static inline int
321 hostapd_set_preamble(struct hostapd_data *hapd, int value)
322 {
323         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
324                 return 0;
325         return hapd->driver->set_preamble(hapd->drv_priv, value);
326 }
327
328 static inline int
329 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
330 {
331         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
332                 return 0;
333         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
334 }
335
336 static inline int
337 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
338                             int cw_min, int cw_max, int burst_time)
339 {
340         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
341                 return 0;
342         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
343                                                  cw_min, cw_max, burst_time);
344 }
345
346 static inline int
347 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
348                        const u8 *mask)
349 {
350         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
351                 return 1;
352         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
353 }
354
355 static inline int
356 hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
357                const char *ifname, const u8 *addr, void *bss_ctx)
358 {
359         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
360                 return -1;
361         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
362                                     ifname, addr, bss_ctx);
363 }
364
365 static inline int
366 hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
367                   const char *ifname)
368 {
369         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
370                 return -1;
371         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
372 }
373
374 static inline struct hostapd_hw_modes *
375 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
376                             u16 *flags)
377 {
378         if (hapd->driver == NULL ||
379             hapd->driver->get_hw_feature_data == NULL)
380                 return NULL;
381         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
382                                                  flags);
383 }
384
385 static inline int
386 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
387                      const u8 *addr, int vlan_id)
388 {
389         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
390                 return 0;
391         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
392 }
393
394 static inline int
395 hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr, int aid,
396                     int val)
397 {
398         if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
399                 return 0;
400         return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val);
401 }
402
403 static inline int
404 hostapd_driver_commit(struct hostapd_data *hapd)
405 {
406         if (hapd->driver == NULL || hapd->driver->commit == NULL)
407                 return 0;
408         return hapd->driver->commit(hapd->drv_priv);
409 }
410
411 static inline int
412 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
413                             int accepted, u32 session_timeout)
414 {
415         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
416                 return 0;
417         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
418                                                  session_timeout);
419 }
420
421 static inline int
422 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
423 {
424         if (hapd->driver == NULL ||
425             hapd->driver->set_radius_acl_expire == NULL)
426                 return 0;
427         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
428 }
429
430 static inline int
431 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
432                       const u8 *ht_capab, size_t ht_capab_len,
433                       const u8 *ht_oper, size_t ht_oper_len)
434 {
435         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
436             ht_capab == NULL || ht_oper == NULL)
437                 return 0;
438         return hapd->driver->set_ht_params(
439                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
440                 ht_oper, ht_oper_len);
441 }
442
443 static inline int
444 hostapd_drv_none(struct hostapd_data *hapd)
445 {
446         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
447 }
448
449 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
450                                       struct wpa_driver_scan_params *params)
451 {
452         if (hapd->driver && hapd->driver->scan2)
453                 return hapd->driver->scan2(hapd->drv_priv, params);
454         return -1;
455 }
456
457 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
458         struct hostapd_data *hapd)
459 {
460         if (hapd->driver && hapd->driver->get_scan_results2)
461                 return hapd->driver->get_scan_results2(hapd->drv_priv);
462         return NULL;
463 }
464
465 #endif /* DRIVER_I_H */