test: Use more shared code for driver wrapper AP and station modes
[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 "ap/config.h"
20
21 static inline int
22 hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
23 {
24         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
25                 return 0;
26         return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
27 }
28
29 static inline int
30 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
31 {
32         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
33                 return 0;
34         return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
35                                          enabled);
36 }
37
38 static inline int
39 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
40                    const u8 *addr, int idx, u8 *seq)
41 {
42         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
43                 return 0;
44         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
45                                         seq);
46 }
47
48 static inline int
49 hostapd_flush(struct hostapd_data *hapd)
50 {
51         if (hapd->driver == NULL || hapd->driver->flush == NULL)
52                 return 0;
53         return hapd->driver->flush(hapd->drv_priv);
54 }
55
56 static inline int
57 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
58                          size_t elem_len)
59 {
60         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
61                 return 0;
62         return hapd->driver->set_generic_elem(hapd->conf->iface,
63                                               hapd->drv_priv, elem, elem_len);
64 }
65
66 static inline int
67 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
68 {
69         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
70                 return 0;
71         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
72                                            buf, len);
73 }
74
75 static inline int
76 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
77 {
78         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
79                 return 0;
80         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
81                                            buf, len);
82 }
83
84 static inline int
85 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
86                  int ht_enabled, int sec_channel_offset)
87 {
88         struct hostapd_freq_params data;
89         if (hapd->driver == NULL)
90                 return 0;
91         if (hapd->driver->set_freq == NULL)
92                 return 0;
93         os_memset(&data, 0, sizeof(data));
94         data.mode = mode;
95         data.freq = freq;
96         data.channel = channel;
97         data.ht_enabled = ht_enabled;
98         data.sec_channel_offset = sec_channel_offset;
99         return hapd->driver->set_freq(hapd->drv_priv, &data);
100 }
101
102 static inline int
103 hostapd_set_rts(struct hostapd_data *hapd, int rts)
104 {
105         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
106                 return 0;
107         return hapd->driver->set_rts(hapd->drv_priv, rts);
108 }
109
110 static inline int
111 hostapd_set_frag(struct hostapd_data *hapd, int frag)
112 {
113         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
114                 return 0;
115         return hapd->driver->set_frag(hapd->drv_priv, frag);
116 }
117
118 static inline int
119 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
120                       int total_flags, int flags_or, int flags_and)
121 {
122         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
123                 return 0;
124         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
125                                            flags_or, flags_and);
126 }
127
128 static inline int
129 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
130                       int *basic_rates, int mode)
131 {
132         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
133                 return 0;
134         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
135                                            basic_rates, mode);
136 }
137
138 static inline int
139 hostapd_set_country(struct hostapd_data *hapd, const char *country)
140 {
141         if (hapd->driver == NULL ||
142             hapd->driver->set_country == NULL)
143                 return 0;
144         return hapd->driver->set_country(hapd->drv_priv, country);
145 }
146
147 static inline int
148 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
149 {
150         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
151                 return 0;
152         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
153 }
154
155 static inline int
156 hostapd_set_preamble(struct hostapd_data *hapd, int value)
157 {
158         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
159                 return 0;
160         return hapd->driver->set_preamble(hapd->drv_priv, value);
161 }
162
163 static inline int
164 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
165 {
166         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
167                 return 0;
168         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
169 }
170
171 static inline int
172 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
173                             int cw_min, int cw_max, int burst_time)
174 {
175         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
176                 return 0;
177         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
178                                                  cw_min, cw_max, burst_time);
179 }
180
181 static inline int
182 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
183                        const u8 *mask)
184 {
185         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
186                 return 1;
187         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
188 }
189
190 static inline int
191 hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
192                const char *ifname, const u8 *addr, void *bss_ctx)
193 {
194         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
195                 return -1;
196         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
197                                     ifname, addr, bss_ctx);
198 }
199
200 static inline int
201 hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
202                   const char *ifname)
203 {
204         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
205                 return -1;
206         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
207 }
208
209 static inline struct hostapd_hw_modes *
210 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
211                             u16 *flags)
212 {
213         if (hapd->driver == NULL ||
214             hapd->driver->get_hw_feature_data == NULL)
215                 return NULL;
216         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
217                                                  flags);
218 }
219
220 static inline int
221 hostapd_driver_commit(struct hostapd_data *hapd)
222 {
223         if (hapd->driver == NULL || hapd->driver->commit == NULL)
224                 return 0;
225         return hapd->driver->commit(hapd->drv_priv);
226 }
227
228 static inline int
229 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
230                       const u8 *ht_capab, size_t ht_capab_len,
231                       const u8 *ht_oper, size_t ht_oper_len)
232 {
233         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
234             ht_capab == NULL || ht_oper == NULL)
235                 return 0;
236         return hapd->driver->set_ht_params(
237                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
238                 ht_oper, ht_oper_len);
239 }
240
241 static inline int
242 hostapd_drv_none(struct hostapd_data *hapd)
243 {
244         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
245 }
246
247 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
248                                       struct wpa_driver_scan_params *params)
249 {
250         if (hapd->driver && hapd->driver->scan2)
251                 return hapd->driver->scan2(hapd->drv_priv, params);
252         return -1;
253 }
254
255 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
256         struct hostapd_data *hapd)
257 {
258         if (hapd->driver && hapd->driver->get_scan_results2)
259                 return hapd->driver->get_scan_results2(hapd->drv_priv);
260         return NULL;
261 }
262
263 #endif /* DRIVER_I_H */