Merge wpa_supplicant and hostapd driver wrapper implementations
[wpasupplicant] / hostapd / driver_i.h
1 /*
2  * hostapd - internal driver interface wrappers
3  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2007-2008, Intel Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Alternatively, this software may be distributed under the terms of BSD
11  * license.
12  *
13  * See README and COPYING for more details.
14  */
15
16 #ifndef DRIVER_I_H
17 #define DRIVER_I_H
18
19 #include "drivers/driver.h"
20 #include "config.h"
21
22 static inline void *
23 hostapd_driver_init(struct hostapd_data *hapd)
24 {
25         if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
26                 return NULL;
27         return hapd->driver->hapd_init(hapd);
28 }
29
30 static inline void *
31 hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
32 {
33         if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
34                 return NULL;
35         return hapd->driver->init_bssid(hapd, bssid);
36 }
37
38 static inline void
39 hostapd_driver_deinit(struct hostapd_data *hapd)
40 {
41         if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
42                 return;
43         hapd->driver->hapd_deinit(hapd->drv_priv);
44 }
45
46 static inline int
47 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
48                       int enabled)
49 {
50         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
51                 return 0;
52         return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
53 }
54
55 static inline int
56 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
57 {
58         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
59                 return 0;
60         return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
61                                          enabled);
62 }
63
64 static inline int
65 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
66                 wpa_alg alg, const u8 *addr, int key_idx,
67                 int set_tx, const u8 *seq, size_t seq_len,
68                 const u8 *key, size_t key_len)
69 {
70         if (hapd->driver == NULL || hapd->driver->hapd_set_key == NULL)
71                 return 0;
72         return hapd->driver->hapd_set_key(ifname, hapd->drv_priv, alg, addr,
73                                           key_idx, set_tx, seq, seq_len, key,
74                                           key_len);
75 }
76
77 static inline int
78 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
79                    const u8 *addr, int idx, u8 *seq)
80 {
81         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
82                 return 0;
83         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
84                                         seq);
85 }
86
87 static inline int
88 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
89                         const u8 *addr, int idx, u8 *seq)
90 {
91         if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
92                 return -1;
93         return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
94                                              seq);
95 }
96
97 static inline int
98 hostapd_flush(struct hostapd_data *hapd)
99 {
100         if (hapd->driver == NULL || hapd->driver->flush == NULL)
101                 return 0;
102         return hapd->driver->flush(hapd->drv_priv);
103 }
104
105 static inline int
106 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
107                          size_t elem_len)
108 {
109         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
110                 return 0;
111         return hapd->driver->set_generic_elem(hapd->conf->iface,
112                                               hapd->drv_priv, elem, elem_len);
113 }
114
115 static inline int
116 hostapd_read_sta_data(struct hostapd_data *hapd,
117                       struct hostap_sta_driver_data *data, const u8 *addr)
118 {
119         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
120                 return -1;
121         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
122 }
123
124 static inline int
125 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
126                    size_t data_len, int encrypt)
127 {
128         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
129                 return 0;
130         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
131                                              data_len, encrypt,
132                                              hapd->own_addr);
133 }
134
135 static inline int
136 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
137 {
138         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
139                 return 0;
140         return hapd->driver->sta_deauth(hapd->drv_priv, addr, reason);
141 }
142
143 static inline int
144 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
145 {
146         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
147                 return 0;
148         return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
149 }
150
151 static inline int
152 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
153 {
154         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
155                 return 0;
156         return hapd->driver->sta_remove(hapd->drv_priv, addr);
157 }
158
159 static inline int
160 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
161 {
162         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
163                 return 0;
164         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
165                                            buf, len);
166 }
167
168 static inline int
169 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
170 {
171         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
172                 return 0;
173         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
174                                            buf, len);
175 }
176
177 static inline int
178 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
179                         int flags)
180 {
181         if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
182                 return 0;
183         return hapd->driver->send_mgmt_frame(hapd->drv_priv, msg, len, flags);
184 }
185
186 static inline int
187 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
188 {
189         if (hapd->driver == NULL ||
190             hapd->driver->hapd_set_countermeasures == NULL)
191                 return 0;
192         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
193 }
194
195 static inline int
196 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
197                 u16 aid, u16 capability, const u8 *supp_rates,
198                 size_t supp_rates_len, int flags, u16 listen_interval,
199                 const struct ht_cap_ie *ht_capabilities)
200 {
201         struct hostapd_sta_add_params params;
202
203         if (hapd->driver == NULL)
204                 return 0;
205         if (hapd->driver->sta_add == NULL)
206                 return 0;
207
208         os_memset(&params, 0, sizeof(params));
209         params.addr = addr;
210         params.aid = aid;
211         params.capability = capability;
212         params.supp_rates = supp_rates;
213         params.supp_rates_len = supp_rates_len;
214         params.flags = flags;
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_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
264 {
265         if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
266                 return 0;
267         return hapd->driver->set_retry(hapd->drv_priv, short_retry,
268                                        long_retry);
269 }
270
271 static inline int
272 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
273                       int total_flags, int flags_or, int flags_and)
274 {
275         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
276                 return 0;
277         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
278                                            flags_or, flags_and);
279 }
280
281 static inline int
282 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
283                       int *basic_rates, int mode)
284 {
285         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
286                 return 0;
287         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
288                                            basic_rates, mode);
289 }
290
291 static inline int
292 hostapd_set_country(struct hostapd_data *hapd, const char *country)
293 {
294         if (hapd->driver == NULL ||
295             hapd->driver->hapd_set_country == NULL)
296                 return 0;
297         return hapd->driver->hapd_set_country(hapd->drv_priv, country);
298 }
299
300 static inline int
301 hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
302 {
303         if (hapd->driver == NULL ||
304             hapd->driver->set_ieee80211d == NULL)
305                 return 0;
306         return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
307 }
308
309 static inline int
310 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
311 {
312         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
313                 return 0;
314         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
315 }
316
317 static inline int
318 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
319                    const u8 *head, size_t head_len,
320                    const u8 *tail, size_t tail_len, int dtim_period)
321 {
322         if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
323                 return 0;
324         return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
325                                              head, head_len,
326                                              tail, tail_len, dtim_period);
327 }
328
329 static inline int
330 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
331 {
332         if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
333                 return 0;
334         return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
335 }
336
337 static inline int
338 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
339 {
340         if (hapd->driver == NULL || hapd->driver->hapd_set_beacon_int == NULL)
341                 return 0;
342         return hapd->driver->hapd_set_beacon_int(hapd->drv_priv, value);
343 }
344
345 static inline int
346 hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
347 {
348         if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
349                 return 0;
350         return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
351 }
352
353 static inline int
354 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
355 {
356         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
357                 return 0;
358         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
359 }
360
361 static inline int
362 hostapd_set_preamble(struct hostapd_data *hapd, int value)
363 {
364         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
365                 return 0;
366         return hapd->driver->set_preamble(hapd->drv_priv, value);
367 }
368
369 static inline int
370 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
371 {
372         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
373                 return 0;
374         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
375 }
376
377 static inline int
378 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
379                             int cw_min, int cw_max, int burst_time)
380 {
381         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
382                 return 0;
383         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
384                                                  cw_min, cw_max, burst_time);
385 }
386
387 static inline int
388 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
389 {
390         if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
391                 return 0;
392         return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
393 }
394
395 static inline int
396 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
397 {
398         if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
399                 return 0;
400         return hapd->driver->bss_remove(hapd->drv_priv, ifname);
401 }
402
403 static inline int
404 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
405                        const u8 *mask)
406 {
407         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
408                 return 1;
409         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
410 }
411
412 static inline int
413 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
414                char *ifname, const u8 *addr)
415 {
416         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
417                 return -1;
418         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
419                                     ifname, addr);
420 }
421
422 static inline int
423 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
424                   char *ifname, const u8 *addr)
425 {
426         if (hapd->driver == NULL || hapd->driver->if_update == NULL)
427                 return -1;
428         return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
429 }
430
431 static inline int
432 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
433                   char *ifname, const u8 *addr)
434 {
435         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
436                 return -1;
437         return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
438 }
439
440 static inline int
441 hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
442                      int interval, int _listen, int *channel,
443                      int *last_rx)
444 {
445         if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
446                 return -1;
447         return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
448                                           interval, _listen, channel, last_rx);
449 }
450
451 static inline struct hostapd_hw_modes *
452 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
453                             u16 *flags)
454 {
455         if (hapd->driver == NULL ||
456             hapd->driver->hapd_get_hw_feature_data == NULL)
457                 return NULL;
458         return hapd->driver->hapd_get_hw_feature_data(hapd->drv_priv,
459                                                       num_modes,
460                                                       flags);
461 }
462
463 static inline int
464 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
465                      const u8 *addr, int vlan_id)
466 {
467         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
468                 return 0;
469         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
470 }
471
472 static inline int
473 hostapd_driver_commit(struct hostapd_data *hapd)
474 {
475         if (hapd->driver == NULL || hapd->driver->commit == NULL)
476                 return 0;
477         return hapd->driver->commit(hapd->drv_priv);
478 }
479
480 static inline int
481 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
482                             int accepted, u32 session_timeout)
483 {
484         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
485                 return 0;
486         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
487                                                  session_timeout);
488 }
489
490 static inline int
491 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
492 {
493         if (hapd->driver == NULL ||
494             hapd->driver->set_radius_acl_expire == NULL)
495                 return 0;
496         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
497 }
498
499 #ifdef CONFIG_IEEE80211N
500 static inline int
501 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
502                       const u8 *ht_capab, size_t ht_capab_len,
503                       const u8 *ht_oper, size_t ht_oper_len)
504 {
505         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
506             ht_capab == NULL || ht_oper == NULL)
507                 return 0;
508         return hapd->driver->set_ht_params(
509                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
510                 ht_oper, ht_oper_len);
511 }
512 #endif /* CONFIG_IEEE80211N */
513
514 static inline int
515 hostapd_drv_none(struct hostapd_data *hapd)
516 {
517         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
518 }
519
520 static inline int
521 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
522 {
523         if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
524                 return 0;
525         return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
526                                                hapd->drv_priv, ie, len);
527 }
528
529 static inline int
530 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
531                               size_t len)
532 {
533         if (hapd->driver == NULL ||
534             hapd->driver->set_wps_probe_resp_ie == NULL)
535                 return 0;
536         return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
537                                                    hapd->drv_priv, ie, len);
538 }
539
540 static inline const struct hostapd_neighbor_bss *
541 hostapd_driver_get_neighbor_bss(struct hostapd_data *hapd, size_t *num)
542 {
543         if (hapd->driver == NULL || hapd->driver->get_neighbor_bss == NULL)
544                 return NULL;
545         return hapd->driver->get_neighbor_bss(hapd->drv_priv, num);
546 }
547
548 #endif /* DRIVER_I_H */