hostapd: Remove unused bridge_packets configuration option
[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(const char *ifname, struct hostapd_data *hapd,
67                       int enabled)
68 {
69         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
70                 return 0;
71         return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
72 }
73
74 static inline int
75 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
76 {
77         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
78                 return 0;
79         return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
80                                          enabled);
81 }
82
83 static inline int
84 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
85                 wpa_alg alg, const u8 *addr, int key_idx,
86                 int set_tx, const u8 *seq, size_t seq_len,
87                 const u8 *key, size_t key_len)
88 {
89         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
90                 return 0;
91         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
92                                      key_idx, set_tx, seq, seq_len, key,
93                                      key_len);
94 }
95
96 static inline int
97 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
98                    const u8 *addr, int idx, u8 *seq)
99 {
100         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
101                 return 0;
102         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
103                                         seq);
104 }
105
106 static inline int
107 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
108                         const u8 *addr, int idx, u8 *seq)
109 {
110         if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
111                 return -1;
112         return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
113                                              seq);
114 }
115
116 static inline int
117 hostapd_flush(struct hostapd_data *hapd)
118 {
119         if (hapd->driver == NULL || hapd->driver->flush == NULL)
120                 return 0;
121         return hapd->driver->flush(hapd->drv_priv);
122 }
123
124 static inline int
125 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
126                          size_t elem_len)
127 {
128         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
129                 return 0;
130         return hapd->driver->set_generic_elem(hapd->conf->iface,
131                                               hapd->drv_priv, elem, elem_len);
132 }
133
134 static inline int
135 hostapd_read_sta_data(struct hostapd_data *hapd,
136                       struct hostap_sta_driver_data *data, const u8 *addr)
137 {
138         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
139                 return -1;
140         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
141 }
142
143 static inline int
144 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
145                    size_t data_len, int encrypt)
146 {
147         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
148                 return 0;
149         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
150                                              data_len, encrypt,
151                                              hapd->own_addr);
152 }
153
154 static inline int
155 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
156 {
157         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
158                 return 0;
159         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
160                                         reason);
161 }
162
163 static inline int
164 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
165 {
166         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
167                 return 0;
168         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
169                                           reason);
170 }
171
172 static inline int
173 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
174 {
175         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
176                 return 0;
177         return hapd->driver->sta_remove(hapd->drv_priv, addr);
178 }
179
180 static inline int
181 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
182 {
183         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
184                 return 0;
185         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
186                                            buf, len);
187 }
188
189 static inline int
190 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
191 {
192         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
193                 return 0;
194         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
195                                            buf, len);
196 }
197
198 static inline int
199 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
200 {
201         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
202                 return 0;
203         return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
204 }
205
206 static inline int
207 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
208 {
209         if (hapd->driver == NULL ||
210             hapd->driver->hapd_set_countermeasures == NULL)
211                 return 0;
212         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
213 }
214
215 static inline int
216 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
217                 u16 aid, u16 capability, const u8 *supp_rates,
218                 size_t supp_rates_len, int flags, u16 listen_interval,
219                 const struct ieee80211_ht_capabilities *ht_capabilities)
220 {
221         struct hostapd_sta_add_params params;
222
223         if (hapd->driver == NULL)
224                 return 0;
225         if (hapd->driver->sta_add == NULL)
226                 return 0;
227
228         os_memset(&params, 0, sizeof(params));
229         params.addr = addr;
230         params.aid = aid;
231         params.capability = capability;
232         params.supp_rates = supp_rates;
233         params.supp_rates_len = supp_rates_len;
234         params.flags = flags;
235         params.listen_interval = listen_interval;
236         params.ht_capabilities = ht_capabilities;
237         return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
238 }
239
240 static inline int
241 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
242 {
243         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
244                 return 0;
245         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
246 }
247
248 static inline int
249 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
250                  int ht_enabled, int sec_channel_offset)
251 {
252         struct hostapd_freq_params data;
253         if (hapd->driver == NULL)
254                 return 0;
255         if (hapd->driver->set_freq == NULL)
256                 return 0;
257         os_memset(&data, 0, sizeof(data));
258         data.mode = mode;
259         data.freq = freq;
260         data.channel = channel;
261         data.ht_enabled = ht_enabled;
262         data.sec_channel_offset = sec_channel_offset;
263         return hapd->driver->set_freq(hapd->drv_priv, &data);
264 }
265
266 static inline int
267 hostapd_set_rts(struct hostapd_data *hapd, int rts)
268 {
269         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
270                 return 0;
271         return hapd->driver->set_rts(hapd->drv_priv, rts);
272 }
273
274 static inline int
275 hostapd_set_frag(struct hostapd_data *hapd, int frag)
276 {
277         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
278                 return 0;
279         return hapd->driver->set_frag(hapd->drv_priv, frag);
280 }
281
282 static inline int
283 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
284                       int total_flags, int flags_or, int flags_and)
285 {
286         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
287                 return 0;
288         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
289                                            flags_or, flags_and);
290 }
291
292 static inline int
293 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
294                       int *basic_rates, int mode)
295 {
296         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
297                 return 0;
298         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
299                                            basic_rates, mode);
300 }
301
302 static inline int
303 hostapd_set_country(struct hostapd_data *hapd, const char *country)
304 {
305         if (hapd->driver == NULL ||
306             hapd->driver->set_country == NULL)
307                 return 0;
308         return hapd->driver->set_country(hapd->drv_priv, country);
309 }
310
311 static inline int
312 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
313 {
314         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
315                 return 0;
316         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
317 }
318
319 static inline int
320 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
321                    const u8 *head, size_t head_len,
322                    const u8 *tail, size_t tail_len, int dtim_period,
323                    int beacon_int)
324 {
325         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
326                 return 0;
327         return hapd->driver->set_beacon(ifname, hapd->drv_priv,
328                                         head, head_len, tail, tail_len,
329                                         dtim_period, beacon_int);
330 }
331
332 static inline int
333 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
334 {
335         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
336                 return 0;
337         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
338 }
339
340 static inline int
341 hostapd_set_preamble(struct hostapd_data *hapd, int value)
342 {
343         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
344                 return 0;
345         return hapd->driver->set_preamble(hapd->drv_priv, value);
346 }
347
348 static inline int
349 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
350 {
351         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
352                 return 0;
353         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
354 }
355
356 static inline int
357 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
358                             int cw_min, int cw_max, int burst_time)
359 {
360         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
361                 return 0;
362         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
363                                                  cw_min, cw_max, burst_time);
364 }
365
366 static inline int
367 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
368                        const u8 *mask)
369 {
370         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
371                 return 1;
372         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
373 }
374
375 static inline int
376 hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
377                const char *ifname, const u8 *addr)
378 {
379         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
380                 return -1;
381         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
382                                     ifname, addr);
383 }
384
385 static inline int
386 hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
387                   const char *ifname)
388 {
389         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
390                 return -1;
391         return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
392 }
393
394 static inline struct hostapd_hw_modes *
395 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
396                             u16 *flags)
397 {
398         if (hapd->driver == NULL ||
399             hapd->driver->get_hw_feature_data == NULL)
400                 return NULL;
401         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
402                                                  flags);
403 }
404
405 static inline int
406 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
407                      const u8 *addr, int vlan_id)
408 {
409         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
410                 return 0;
411         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
412 }
413
414 static inline int
415 hostapd_driver_commit(struct hostapd_data *hapd)
416 {
417         if (hapd->driver == NULL || hapd->driver->commit == NULL)
418                 return 0;
419         return hapd->driver->commit(hapd->drv_priv);
420 }
421
422 static inline int
423 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
424                             int accepted, u32 session_timeout)
425 {
426         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
427                 return 0;
428         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
429                                                  session_timeout);
430 }
431
432 static inline int
433 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
434 {
435         if (hapd->driver == NULL ||
436             hapd->driver->set_radius_acl_expire == NULL)
437                 return 0;
438         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
439 }
440
441 static inline int
442 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
443                       const u8 *ht_capab, size_t ht_capab_len,
444                       const u8 *ht_oper, size_t ht_oper_len)
445 {
446         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
447             ht_capab == NULL || ht_oper == NULL)
448                 return 0;
449         return hapd->driver->set_ht_params(
450                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
451                 ht_oper, ht_oper_len);
452 }
453
454 static inline int
455 hostapd_drv_none(struct hostapd_data *hapd)
456 {
457         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
458 }
459
460 static inline int
461 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
462 {
463         if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
464                 return 0;
465         return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
466                                                hapd->drv_priv, ie, len);
467 }
468
469 static inline int
470 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
471                               size_t len)
472 {
473         if (hapd->driver == NULL ||
474             hapd->driver->set_wps_probe_resp_ie == NULL)
475                 return 0;
476         return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
477                                                    hapd->drv_priv, ie, len);
478 }
479
480 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
481                                       struct wpa_driver_scan_params *params)
482 {
483         if (hapd->driver && hapd->driver->scan2)
484                 return hapd->driver->scan2(hapd->drv_priv, params);
485         return -1;
486 }
487
488 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
489         struct hostapd_data *hapd)
490 {
491         if (hapd->driver && hapd->driver->get_scan_results2)
492                 return hapd->driver->get_scan_results2(hapd->drv_priv);
493         return NULL;
494 }
495
496 #endif /* DRIVER_I_H */