76e1990ae654bb6e3027371b110f969816dd3405
[libeap.git] / hostapd / driver.h
1 /*
2  * hostapd - driver interface definition
3  * Copyright (c) 2002-2007, 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_H
17 #define DRIVER_H
18
19 struct hostapd_sta_add_params {
20         const u8 *addr;
21         u16 aid;
22         u16 capability;
23         const u8 *supp_rates;
24         size_t supp_rates_len;
25         int flags;
26         u16 listen_interval;
27         const struct ht_cap_ie *ht_capabilities;
28 };
29
30 enum hostapd_driver_if_type {
31         HOSTAPD_IF_VLAN, HOSTAPD_IF_WDS
32 };
33
34 struct wpa_driver_ops {
35         const char *name;               /* as appears in the config file */
36
37         void * (*init)(struct hostapd_data *hapd);
38         void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid);
39         void (*deinit)(void *priv);
40
41         int (*wireless_event_init)(void *priv);
42         void (*wireless_event_deinit)(void *priv);
43
44         /**
45          * set_8021x - enable/disable IEEE 802.1X support
46          * @ifname: Interface name (for multi-SSID/VLAN support)
47          * @priv: driver private data
48          * @enabled: 1 = enable, 0 = disable
49          *
50          * Returns: 0 on success, -1 on failure
51          *
52          * Configure the kernel driver to enable/disable 802.1X support.
53          * This may be an empty function if 802.1X support is always enabled.
54          */
55         int (*set_ieee8021x)(const char *ifname, void *priv, int enabled);
56
57         /**
58          * set_privacy - enable/disable privacy
59          * @priv: driver private data
60          * @enabled: 1 = privacy enabled, 0 = disabled
61          *
62          * Return: 0 on success, -1 on failure
63          *
64          * Configure privacy.
65          */
66         int (*set_privacy)(const char *ifname, void *priv, int enabled);
67
68         int (*set_encryption)(const char *ifname, void *priv, const char *alg,
69                               const u8 *addr, int idx,
70                               const u8 *key, size_t key_len, int txkey);
71         int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
72                           int idx, u8 *seq);
73         int (*get_seqnum_igtk)(const char *ifname, void *priv, const u8 *addr,
74                                int idx, u8 *seq);
75         int (*flush)(void *priv);
76         int (*set_generic_elem)(const char *ifname, void *priv, const u8 *elem,
77                                 size_t elem_len);
78
79         int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
80                              const u8 *addr);
81         int (*send_eapol)(void *priv, const u8 *addr, const u8 *data,
82                           size_t data_len, int encrypt, const u8 *own_addr);
83         int (*sta_deauth)(void *priv, const u8 *addr, int reason);
84         int (*sta_disassoc)(void *priv, const u8 *addr, int reason);
85         int (*sta_remove)(void *priv, const u8 *addr);
86         int (*get_ssid)(const char *ifname, void *priv, u8 *buf, int len);
87         int (*set_ssid)(const char *ifname, void *priv, const u8 *buf,
88                         int len);
89         int (*set_countermeasures)(void *priv, int enabled);
90         int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
91                                int flags);
92         int (*set_assoc_ap)(void *priv, const u8 *addr);
93         /* note: sta_add() is deprecated; use sta_add2() instead */
94         int (*sta_add)(const char *ifname, void *priv, const u8 *addr, u16 aid,
95                        u16 capability, u8 *supp_rates, size_t supp_rates_len,
96                        int flags, u16 listen_interval);
97         int (*sta_add2)(const char *ifname, void *priv,
98                         struct hostapd_sta_add_params *params);
99         int (*get_inact_sec)(void *priv, const u8 *addr);
100         int (*sta_clear_stats)(void *priv, const u8 *addr);
101
102         int (*set_freq)(void *priv, int mode, int freq);
103         int (*set_rts)(void *priv, int rts);
104         int (*get_rts)(void *priv, int *rts);
105         int (*set_frag)(void *priv, int frag);
106         int (*get_frag)(void *priv, int *frag);
107         int (*set_retry)(void *priv, int short_retry, int long_retry);
108         int (*get_retry)(void *priv, int *short_retry, int *long_retry);
109
110         int (*sta_set_flags)(void *priv, const u8 *addr,
111                              int total_flags, int flags_or, int flags_and);
112         int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
113                              int mode);
114         int (*set_regulatory_domain)(void *priv, unsigned int rd);
115         int (*set_country)(void *priv, const char *country);
116         int (*set_ieee80211d)(void *priv, int enabled);
117         int (*set_beacon)(const char *ifname, void *priv,
118                           u8 *head, size_t head_len,
119                           u8 *tail, size_t tail_len);
120
121         /* Configure internal bridge:
122          * 0 = disabled, i.e., client separation is enabled (no bridging of
123          *     packets between associated STAs
124          * 1 = enabled, i.e., bridge packets between associated STAs (default)
125          */
126         int (*set_internal_bridge)(void *priv, int value);
127         int (*set_beacon_int)(void *priv, int value);
128         int (*set_dtim_period)(const char *ifname, void *priv, int value);
129         /* Configure broadcast SSID mode:
130          * 0 = include SSID in Beacon frames and reply to Probe Request frames
131          *     that use broadcast SSID
132          * 1 = hide SSID from Beacon frames and ignore Probe Request frames for
133          *     broadcast SSID
134          */
135         int (*set_broadcast_ssid)(void *priv, int value);
136         int (*set_cts_protect)(void *priv, int value);
137         int (*set_key_tx_rx_threshold)(void *priv, int value);
138         int (*set_preamble)(void *priv, int value);
139         int (*set_short_slot_time)(void *priv, int value);
140         int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
141                                    int cw_max, int burst_time);
142         int (*bss_add)(void *priv, const char *ifname, const u8 *bssid);
143         int (*bss_remove)(void *priv, const char *ifname);
144         int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
145         int (*passive_scan)(void *priv, int now, int our_mode_only,
146                             int interval, int _listen, int *channel,
147                             int *last_rx);
148         struct hostapd_hw_modes * (*get_hw_feature_data)(void *priv,
149                                                          u16 *num_modes,
150                                                          u16 *flags);
151         int (*if_add)(const char *iface, void *priv,
152                       enum hostapd_driver_if_type type, char *ifname,
153                       const u8 *addr);
154         int (*if_update)(void *priv, enum hostapd_driver_if_type type,
155                          char *ifname, const u8 *addr);
156         int (*if_remove)(void *priv, enum hostapd_driver_if_type type,
157                          const char *ifname, const u8 *addr);
158         int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
159                             int vlan_id);
160         /**
161          * commit - Optional commit changes handler
162          * @priv: driver private data
163          * Returns: 0 on success, -1 on failure
164          *
165          * This optional handler function can be registered if the driver
166          * interface implementation needs to commit changes (e.g., by setting
167          * network interface up) at the end of initial configuration. If set,
168          * this handler will be called after initial setup has been completed.
169          */
170         int (*commit)(void *priv);
171
172         int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
173                           const u8 *data, size_t data_len);
174
175         int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted, 
176                                    u32 session_timeout);
177         int (*set_radius_acl_expire)(void *priv, const u8 *mac);
178
179         int (*set_ht_capability)(const char *ifname, void *priv,
180                                  const u8 *data, size_t data_len);
181         int (*set_ht_operation)(const char *ifname, void *priv,
182                                 const u8 *data, size_t data_len);
183 };
184
185 static inline void *
186 hostapd_driver_init(struct hostapd_data *hapd)
187 {
188         if (hapd->driver == NULL || hapd->driver->init == NULL)
189                 return NULL;
190         return hapd->driver->init(hapd);
191 }
192
193 static inline void *
194 hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
195 {
196         if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
197                 return NULL;
198         return hapd->driver->init_bssid(hapd, bssid);
199 }
200
201 static inline void
202 hostapd_driver_deinit(struct hostapd_data *hapd)
203 {
204         if (hapd->driver == NULL || hapd->driver->deinit == NULL)
205                 return;
206         hapd->driver->deinit(hapd->drv_priv);
207 }
208
209 static inline int
210 hostapd_wireless_event_init(struct hostapd_data *hapd)
211 {
212         if (hapd->driver == NULL ||
213             hapd->driver->wireless_event_init == NULL)
214                 return 0;
215         return hapd->driver->wireless_event_init(hapd->drv_priv);
216 }
217
218 static inline void
219 hostapd_wireless_event_deinit(struct hostapd_data *hapd)
220 {
221         if (hapd->driver == NULL ||
222             hapd->driver->wireless_event_deinit == NULL)
223                 return;
224         hapd->driver->wireless_event_deinit(hapd->drv_priv);
225 }
226
227 static inline int
228 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
229                       int enabled)
230 {
231         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
232                 return 0;
233         return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
234 }
235
236 static inline int
237 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
238 {
239         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
240                 return 0;
241         return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
242                                          enabled);
243 }
244
245 static inline int
246 hostapd_set_encryption(const char *ifname, struct hostapd_data *hapd,
247                        const char *alg, const u8 *addr, int idx,
248                        u8 *key, size_t key_len, int txkey)
249 {
250         if (hapd->driver == NULL || hapd->driver->set_encryption == NULL)
251                 return 0;
252         return hapd->driver->set_encryption(ifname, hapd->drv_priv, alg, addr,
253                                             idx, key, key_len, txkey);
254 }
255
256 static inline int
257 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
258                    const u8 *addr, int idx, u8 *seq)
259 {
260         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
261                 return 0;
262         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
263                                         seq);
264 }
265
266 static inline int
267 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
268                         const u8 *addr, int idx, u8 *seq)
269 {
270         if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
271                 return -1;
272         return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
273                                              seq);
274 }
275
276 static inline int
277 hostapd_flush(struct hostapd_data *hapd)
278 {
279         if (hapd->driver == NULL || hapd->driver->flush == NULL)
280                 return 0;
281         return hapd->driver->flush(hapd->drv_priv);
282 }
283
284 static inline int
285 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
286                          size_t elem_len)
287 {
288         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
289                 return 0;
290         return hapd->driver->set_generic_elem(hapd->conf->iface,
291                                               hapd->drv_priv, elem, elem_len);
292 }
293
294 static inline int
295 hostapd_read_sta_data(struct hostapd_data *hapd,
296                       struct hostap_sta_driver_data *data, const u8 *addr)
297 {
298         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
299                 return -1;
300         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
301 }
302
303 static inline int
304 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
305                    size_t data_len, int encrypt)
306 {
307         if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
308                 return 0;
309         return hapd->driver->send_eapol(hapd->drv_priv, addr, data, data_len,
310                                         encrypt, hapd->own_addr);
311 }
312
313 static inline int
314 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
315 {
316         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
317                 return 0;
318         return hapd->driver->sta_deauth(hapd->drv_priv, addr, reason);
319 }
320
321 static inline int
322 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
323 {
324         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
325                 return 0;
326         return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
327 }
328
329 static inline int
330 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
331 {
332         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
333                 return 0;
334         return hapd->driver->sta_remove(hapd->drv_priv, addr);
335 }
336
337 static inline int
338 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
339 {
340         if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
341                 return 0;
342         return hapd->driver->get_ssid(hapd->conf->iface, hapd->drv_priv, buf,
343                                       len);
344 }
345
346 static inline int
347 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
348 {
349         if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
350                 return 0;
351         return hapd->driver->set_ssid(hapd->conf->iface, hapd->drv_priv, buf,
352                                       len);
353 }
354
355 static inline int
356 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
357                         int flags)
358 {
359         if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
360                 return 0;
361         return hapd->driver->send_mgmt_frame(hapd->drv_priv, msg, len, flags);
362 }
363
364 static inline int
365 hostapd_set_assoc_ap(struct hostapd_data *hapd, const u8 *addr)
366 {
367         if (hapd->driver == NULL || hapd->driver->set_assoc_ap == NULL)
368                 return 0;
369         return hapd->driver->set_assoc_ap(hapd->drv_priv, addr);
370 }
371
372 static inline int
373 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
374 {
375         if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
376                 return 0;
377         return hapd->driver->set_countermeasures(hapd->drv_priv, enabled);
378 }
379
380 static inline int
381 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
382                 u16 aid, u16 capability, const u8 *supp_rates,
383                 size_t supp_rates_len, int flags, u16 listen_interval,
384                 const struct ht_cap_ie *ht_capabilities)
385 {
386         if (hapd->driver == NULL)
387                 return 0;
388
389         if (hapd->driver->sta_add2) {
390                 struct hostapd_sta_add_params params;
391                 os_memset(&params, 0, sizeof(params));
392                 params.addr = addr;
393                 params.aid = aid;
394                 params.capability = capability;
395                 params.supp_rates = supp_rates;
396                 params.supp_rates_len = supp_rates_len;
397                 params.flags = flags;
398                 params.listen_interval = listen_interval;
399                 params.ht_capabilities = ht_capabilities;
400                 return hapd->driver->sta_add2(ifname, hapd->drv_priv, &params);
401         }
402
403         if (hapd->driver->sta_add == NULL)
404                 return 0;
405         return hapd->driver->sta_add(ifname, hapd->drv_priv, addr, aid,
406                                      capability, (u8 *) supp_rates,
407                                      supp_rates_len,
408                                      flags, listen_interval);
409 }
410
411 static inline int
412 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
413 {
414         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
415                 return 0;
416         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
417 }
418
419 static inline int
420 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq)
421 {
422         if (hapd->driver == NULL || hapd->driver->set_freq == NULL)
423                 return 0;
424         return hapd->driver->set_freq(hapd->drv_priv, mode, freq);
425 }
426
427 static inline int
428 hostapd_set_rts(struct hostapd_data *hapd, int rts)
429 {
430         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
431                 return 0;
432         return hapd->driver->set_rts(hapd->drv_priv, rts);
433 }
434
435 static inline int
436 hostapd_get_rts(struct hostapd_data *hapd, int *rts)
437 {
438         if (hapd->driver == NULL || hapd->driver->get_rts == NULL)
439                 return 0;
440         return hapd->driver->get_rts(hapd->drv_priv, rts);
441 }
442
443 static inline int
444 hostapd_set_frag(struct hostapd_data *hapd, int frag)
445 {
446         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
447                 return 0;
448         return hapd->driver->set_frag(hapd->drv_priv, frag);
449 }
450
451 static inline int
452 hostapd_get_frag(struct hostapd_data *hapd, int *frag)
453 {
454         if (hapd->driver == NULL || hapd->driver->get_frag == NULL)
455                 return 0;
456         return hapd->driver->get_frag(hapd->drv_priv, frag);
457 }
458
459 static inline int
460 hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
461 {
462         if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
463                 return 0;
464         return hapd->driver->set_retry(hapd->drv_priv, short_retry,
465                                        long_retry);
466 }
467
468 static inline int
469 hostapd_get_retry(struct hostapd_data *hapd, int *short_retry, int *long_retry)
470 {
471         if (hapd->driver == NULL || hapd->driver->get_retry == NULL)
472                 return 0;
473         return hapd->driver->get_retry(hapd->drv_priv, short_retry,
474                                        long_retry);
475 }
476
477 static inline int
478 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
479                       int total_flags, int flags_or, int flags_and)
480 {
481         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
482                 return 0;
483         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
484                                            flags_or, flags_and);
485 }
486
487 static inline int
488 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
489                       int *basic_rates, int mode)
490 {
491         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
492                 return 0;
493         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
494                                            basic_rates, mode);
495 }
496
497 static inline int
498 hostapd_set_regulatory_domain(struct hostapd_data *hapd, unsigned int rd)
499 {
500         if (hapd->driver == NULL ||
501             hapd->driver->set_regulatory_domain == NULL)
502                 return 0;
503         return hapd->driver->set_regulatory_domain(hapd->drv_priv, rd);
504 }
505
506 static inline int
507 hostapd_set_country(struct hostapd_data *hapd, const char *country)
508 {
509         if (hapd->driver == NULL ||
510             hapd->driver->set_country == NULL)
511                 return 0;
512         return hapd->driver->set_country(hapd->drv_priv, country);
513 }
514
515 static inline int
516 hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
517 {
518         if (hapd->driver == NULL ||
519             hapd->driver->set_ieee80211d == NULL)
520                 return 0;
521         return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
522 }
523
524 static inline int
525 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
526 {
527         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
528                 return 0;
529         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
530 }
531
532 static inline int
533 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
534                    u8 *head, size_t head_len,
535                    u8 *tail, size_t tail_len)
536 {
537         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
538                 return 0;
539         return hapd->driver->set_beacon(ifname, hapd->drv_priv, head, head_len,
540                                         tail, tail_len);
541 }
542
543 static inline int
544 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
545 {
546         if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
547                 return 0;
548         return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
549 }
550
551 static inline int
552 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
553 {
554         if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
555                 return 0;
556         return hapd->driver->set_beacon_int(hapd->drv_priv, value);
557 }
558
559 static inline int
560 hostapd_set_dtim_period(struct hostapd_data *hapd, int value)
561 {
562         if (hapd->driver == NULL || hapd->driver->set_dtim_period == NULL)
563                 return 0;
564         return hapd->driver->set_dtim_period(hapd->conf->iface, hapd->drv_priv,
565                                              value);
566 }
567
568 static inline int
569 hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
570 {
571         if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
572                 return 0;
573         return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
574 }
575
576 static inline int
577 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
578 {
579         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
580                 return 0;
581         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
582 }
583
584 static inline int
585 hostapd_set_key_tx_rx_threshold(struct hostapd_data *hapd, int value)
586 {
587         if (hapd->driver == NULL ||
588             hapd->driver->set_key_tx_rx_threshold == NULL)
589                 return 0;
590         return hapd->driver->set_key_tx_rx_threshold(hapd->drv_priv, value);
591 }
592
593 static inline int
594 hostapd_set_preamble(struct hostapd_data *hapd, int value)
595 {
596         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
597                 return 0;
598         return hapd->driver->set_preamble(hapd->drv_priv, value);
599 }
600
601 static inline int
602 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
603 {
604         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
605                 return 0;
606         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
607 }
608
609 static inline int
610 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
611                             int cw_min, int cw_max, int burst_time)
612 {
613         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
614                 return 0;
615         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
616                                                  cw_min, cw_max, burst_time);
617 }
618
619 static inline int
620 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
621 {
622         if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
623                 return 0;
624         return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
625 }
626
627 static inline int
628 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
629 {
630         if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
631                 return 0;
632         return hapd->driver->bss_remove(hapd->drv_priv, ifname);
633 }
634
635 static inline int
636 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
637                        const u8 *mask)
638 {
639         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
640                 return 1;
641         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
642 }
643
644 static inline int
645 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
646                char *ifname, const u8 *addr)
647 {
648         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
649                 return -1;
650         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
651                                     ifname, addr);
652 }
653
654 static inline int
655 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
656                   char *ifname, const u8 *addr)
657 {
658         if (hapd->driver == NULL || hapd->driver->if_update == NULL)
659                 return -1;
660         return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
661 }
662
663 static inline int
664 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
665                   char *ifname, const u8 *addr)
666 {
667         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
668                 return -1;
669         return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
670 }
671
672 static inline int
673 hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
674                      int interval, int _listen, int *channel,
675                      int *last_rx)
676 {
677         if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
678                 return -1;
679         return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
680                                           interval, _listen, channel, last_rx);
681 }
682
683 static inline struct hostapd_hw_modes *
684 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
685                             u16 *flags)
686 {
687         if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
688                 return NULL;
689         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
690                                                  flags);
691 }
692
693 static inline int
694 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
695                      const u8 *addr, int vlan_id)
696 {
697         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
698                 return 0;
699         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
700 }
701
702 static inline int
703 hostapd_driver_commit(struct hostapd_data *hapd)
704 {
705         if (hapd->driver == NULL || hapd->driver->commit == NULL)
706                 return 0;
707         return hapd->driver->commit(hapd->drv_priv);
708 }
709
710 static inline int
711 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
712                             int accepted, u32 session_timeout)
713 {
714         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
715                 return 0;
716         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
717                                                  session_timeout);
718 }
719
720 static inline int
721 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
722 {
723         if (hapd->driver == NULL ||
724             hapd->driver->set_radius_acl_expire == NULL)
725                 return 0;
726         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
727 }
728
729 #ifdef CONFIG_IEEE80211N
730 static inline int
731 hostapd_set_ht_capability(const char *ifname, struct hostapd_data *hapd,
732                           const u8 *ht_cap)
733 {
734         if (hapd->driver == NULL || hapd->driver->set_ht_capability == NULL ||
735             ht_cap == NULL)
736                 return 0;
737         return hapd->driver->set_ht_capability(
738                 ifname, hapd->drv_priv, ht_cap,
739                 sizeof(struct ieee80211_ht_capability));
740 }
741
742 static inline int
743 hostapd_set_ht_operation(const char *ifname, struct hostapd_data *hapd,
744                          const u8 *ht_operation)
745 {
746         if (hapd->driver == NULL || hapd->driver->set_ht_operation == NULL ||
747             ht_operation == NULL)
748                 return 0;
749         return hapd->driver->set_ht_operation(
750                 ifname, hapd->drv_priv, ht_operation,
751                 sizeof(struct ieee80211_ht_operation));
752 }
753 #endif /* CONFIG_IEEE80211N */
754
755 static inline int
756 hostapd_drv_none(struct hostapd_data *hapd)
757 {
758         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
759 }
760
761 #endif /* DRIVER_H */