ce0eb77aa0dafea9fb89dfacb89e3dc594858cd0
[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 "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->init == NULL)
26                 return NULL;
27         return hapd->driver->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->deinit == NULL)
42                 return;
43         hapd->driver->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->set_key == NULL)
71                 return 0;
72         return hapd->driver->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->send_eapol == NULL)
129                 return 0;
130         return hapd->driver->send_eapol(hapd->drv_priv, addr, data, data_len,
131                                         encrypt, hapd->own_addr);
132 }
133
134 static inline int
135 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
136 {
137         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
138                 return 0;
139         return hapd->driver->sta_deauth(hapd->drv_priv, addr, reason);
140 }
141
142 static inline int
143 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
144 {
145         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
146                 return 0;
147         return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
148 }
149
150 static inline int
151 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
152 {
153         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
154                 return 0;
155         return hapd->driver->sta_remove(hapd->drv_priv, addr);
156 }
157
158 static inline int
159 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
160 {
161         if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
162                 return 0;
163         return hapd->driver->get_ssid(hapd->conf->iface, hapd->drv_priv, buf,
164                                       len);
165 }
166
167 static inline int
168 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
169 {
170         if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
171                 return 0;
172         return hapd->driver->set_ssid(hapd->conf->iface, hapd->drv_priv, buf,
173                                       len);
174 }
175
176 static inline int
177 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
178                         int flags)
179 {
180         if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
181                 return 0;
182         return hapd->driver->send_mgmt_frame(hapd->drv_priv, msg, len, flags);
183 }
184
185 static inline int
186 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
187 {
188         if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
189                 return 0;
190         return hapd->driver->set_countermeasures(hapd->drv_priv, enabled);
191 }
192
193 static inline int
194 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
195                 u16 aid, u16 capability, const u8 *supp_rates,
196                 size_t supp_rates_len, int flags, u16 listen_interval,
197                 const struct ht_cap_ie *ht_capabilities)
198 {
199         struct hostapd_sta_add_params params;
200
201         if (hapd->driver == NULL)
202                 return 0;
203         if (hapd->driver->sta_add == NULL)
204                 return 0;
205
206         os_memset(&params, 0, sizeof(params));
207         params.addr = addr;
208         params.aid = aid;
209         params.capability = capability;
210         params.supp_rates = supp_rates;
211         params.supp_rates_len = supp_rates_len;
212         params.flags = flags;
213         params.listen_interval = listen_interval;
214         params.ht_capabilities = ht_capabilities;
215         return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
216 }
217
218 static inline int
219 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
220 {
221         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
222                 return 0;
223         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
224 }
225
226 static inline int
227 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
228                  int ht_enabled, int sec_channel_offset)
229 {
230         struct hostapd_freq_params data;
231         if (hapd->driver == NULL)
232                 return 0;
233         if (hapd->driver->set_freq == NULL)
234                 return 0;
235         os_memset(&data, 0, sizeof(data));
236         data.mode = mode;
237         data.freq = freq;
238         data.channel = channel;
239         data.ht_enabled = ht_enabled;
240         data.sec_channel_offset = sec_channel_offset;
241         return hapd->driver->set_freq(hapd->drv_priv, &data);
242 }
243
244 static inline int
245 hostapd_set_rts(struct hostapd_data *hapd, int rts)
246 {
247         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
248                 return 0;
249         return hapd->driver->set_rts(hapd->drv_priv, rts);
250 }
251
252 static inline int
253 hostapd_set_frag(struct hostapd_data *hapd, int frag)
254 {
255         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
256                 return 0;
257         return hapd->driver->set_frag(hapd->drv_priv, frag);
258 }
259
260 static inline int
261 hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
262 {
263         if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
264                 return 0;
265         return hapd->driver->set_retry(hapd->drv_priv, short_retry,
266                                        long_retry);
267 }
268
269 static inline int
270 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
271                       int total_flags, int flags_or, int flags_and)
272 {
273         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
274                 return 0;
275         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
276                                            flags_or, flags_and);
277 }
278
279 static inline int
280 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
281                       int *basic_rates, int mode)
282 {
283         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
284                 return 0;
285         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
286                                            basic_rates, mode);
287 }
288
289 static inline int
290 hostapd_set_country(struct hostapd_data *hapd, const char *country)
291 {
292         if (hapd->driver == NULL ||
293             hapd->driver->set_country == NULL)
294                 return 0;
295         return hapd->driver->set_country(hapd->drv_priv, country);
296 }
297
298 static inline int
299 hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
300 {
301         if (hapd->driver == NULL ||
302             hapd->driver->set_ieee80211d == NULL)
303                 return 0;
304         return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
305 }
306
307 static inline int
308 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
309 {
310         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
311                 return 0;
312         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
313 }
314
315 static inline int
316 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
317                    const u8 *head, size_t head_len,
318                    const u8 *tail, size_t tail_len, int dtim_period)
319 {
320         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
321                 return 0;
322         return hapd->driver->set_beacon(ifname, hapd->drv_priv, head, head_len,
323                                         tail, tail_len, dtim_period);
324 }
325
326 static inline int
327 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
328 {
329         if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
330                 return 0;
331         return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
332 }
333
334 static inline int
335 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
336 {
337         if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
338                 return 0;
339         return hapd->driver->set_beacon_int(hapd->drv_priv, value);
340 }
341
342 static inline int
343 hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
344 {
345         if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
346                 return 0;
347         return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
348 }
349
350 static inline int
351 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
352 {
353         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
354                 return 0;
355         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
356 }
357
358 static inline int
359 hostapd_set_preamble(struct hostapd_data *hapd, int value)
360 {
361         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
362                 return 0;
363         return hapd->driver->set_preamble(hapd->drv_priv, value);
364 }
365
366 static inline int
367 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
368 {
369         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
370                 return 0;
371         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
372 }
373
374 static inline int
375 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
376                             int cw_min, int cw_max, int burst_time)
377 {
378         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
379                 return 0;
380         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
381                                                  cw_min, cw_max, burst_time);
382 }
383
384 static inline int
385 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
386 {
387         if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
388                 return 0;
389         return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
390 }
391
392 static inline int
393 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
394 {
395         if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
396                 return 0;
397         return hapd->driver->bss_remove(hapd->drv_priv, ifname);
398 }
399
400 static inline int
401 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
402                        const u8 *mask)
403 {
404         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
405                 return 1;
406         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
407 }
408
409 static inline int
410 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
411                char *ifname, const u8 *addr)
412 {
413         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
414                 return -1;
415         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
416                                     ifname, addr);
417 }
418
419 static inline int
420 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
421                   char *ifname, const u8 *addr)
422 {
423         if (hapd->driver == NULL || hapd->driver->if_update == NULL)
424                 return -1;
425         return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
426 }
427
428 static inline int
429 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
430                   char *ifname, const u8 *addr)
431 {
432         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
433                 return -1;
434         return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
435 }
436
437 static inline int
438 hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
439                      int interval, int _listen, int *channel,
440                      int *last_rx)
441 {
442         if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
443                 return -1;
444         return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
445                                           interval, _listen, channel, last_rx);
446 }
447
448 static inline struct hostapd_hw_modes *
449 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
450                             u16 *flags)
451 {
452         if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
453                 return NULL;
454         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
455                                                  flags);
456 }
457
458 static inline int
459 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
460                      const u8 *addr, int vlan_id)
461 {
462         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
463                 return 0;
464         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
465 }
466
467 static inline int
468 hostapd_driver_commit(struct hostapd_data *hapd)
469 {
470         if (hapd->driver == NULL || hapd->driver->commit == NULL)
471                 return 0;
472         return hapd->driver->commit(hapd->drv_priv);
473 }
474
475 static inline int
476 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
477                             int accepted, u32 session_timeout)
478 {
479         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
480                 return 0;
481         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
482                                                  session_timeout);
483 }
484
485 static inline int
486 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
487 {
488         if (hapd->driver == NULL ||
489             hapd->driver->set_radius_acl_expire == NULL)
490                 return 0;
491         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
492 }
493
494 #ifdef CONFIG_IEEE80211N
495 static inline int
496 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
497                       const u8 *ht_capab, size_t ht_capab_len,
498                       const u8 *ht_oper, size_t ht_oper_len)
499 {
500         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
501             ht_capab == NULL || ht_oper == NULL)
502                 return 0;
503         return hapd->driver->set_ht_params(
504                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
505                 ht_oper, ht_oper_len);
506 }
507 #endif /* CONFIG_IEEE80211N */
508
509 static inline int
510 hostapd_drv_none(struct hostapd_data *hapd)
511 {
512         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
513 }
514
515 static inline int
516 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
517 {
518         if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
519                 return 0;
520         return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
521                                                hapd->drv_priv, ie, len);
522 }
523
524 static inline int
525 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
526                               size_t len)
527 {
528         if (hapd->driver == NULL ||
529             hapd->driver->set_wps_probe_resp_ie == NULL)
530                 return 0;
531         return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
532                                                    hapd->drv_priv, ie, len);
533 }
534
535 static inline const struct hostapd_neighbor_bss *
536 hostapd_driver_get_neighbor_bss(struct hostapd_data *hapd, size_t *num)
537 {
538         if (hapd->driver == NULL || hapd->driver->get_neighbor_bss == NULL)
539                 return NULL;
540         return hapd->driver->get_neighbor_bss(hapd->drv_priv, num);
541 }
542
543 #endif /* DRIVER_I_H */