dc2ea2b9e8b25123fb8cfb48fedd8d8bdc0404a1
[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, const u8 *bssid)
24 {
25         struct wpa_init_params params;
26         void *ret;
27         size_t i;
28
29         if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
30                 return NULL;
31
32         os_memset(&params, 0, sizeof(params));
33         params.bssid = bssid;
34         params.ifname = hapd->conf->iface;
35         params.ssid = (const u8 *) hapd->conf->ssid.ssid;
36         params.ssid_len = hapd->conf->ssid.ssid_len;
37         params.test_socket = hapd->conf->test_socket;
38         params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
39
40         params.num_bridge = hapd->iface->num_bss;
41         params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
42         if (params.bridge == NULL)
43                 return NULL;
44         for (i = 0; i < hapd->iface->num_bss; i++) {
45                 struct hostapd_data *bss = hapd->iface->bss[i];
46                 if (bss->conf->bridge[0])
47                         params.bridge[i] = bss->conf->bridge;
48         }
49         ret = hapd->driver->hapd_init(hapd, &params);
50         os_free(params.bridge);
51
52         return ret;
53 }
54
55 static inline void
56 hostapd_driver_deinit(struct hostapd_data *hapd)
57 {
58         if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
59                 return;
60         hapd->driver->hapd_deinit(hapd->drv_priv);
61 }
62
63 static inline int
64 hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
65                       int enabled)
66 {
67         if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
68                 return 0;
69         return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
70 }
71
72 static inline int
73 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
74 {
75         if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
76                 return 0;
77         return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
78                                          enabled);
79 }
80
81 static inline int
82 hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
83                 wpa_alg alg, const u8 *addr, int key_idx,
84                 int set_tx, const u8 *seq, size_t seq_len,
85                 const u8 *key, size_t key_len)
86 {
87         if (hapd->driver == NULL || hapd->driver->hapd_set_key == NULL)
88                 return 0;
89         return hapd->driver->hapd_set_key(ifname, hapd->drv_priv, alg, addr,
90                                           key_idx, set_tx, seq, seq_len, key,
91                                           key_len);
92 }
93
94 static inline int
95 hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
96                    const u8 *addr, int idx, u8 *seq)
97 {
98         if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
99                 return 0;
100         return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
101                                         seq);
102 }
103
104 static inline int
105 hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
106                         const u8 *addr, int idx, u8 *seq)
107 {
108         if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
109                 return -1;
110         return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
111                                              seq);
112 }
113
114 static inline int
115 hostapd_flush(struct hostapd_data *hapd)
116 {
117         if (hapd->driver == NULL || hapd->driver->flush == NULL)
118                 return 0;
119         return hapd->driver->flush(hapd->drv_priv);
120 }
121
122 static inline int
123 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
124                          size_t elem_len)
125 {
126         if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
127                 return 0;
128         return hapd->driver->set_generic_elem(hapd->conf->iface,
129                                               hapd->drv_priv, elem, elem_len);
130 }
131
132 static inline int
133 hostapd_read_sta_data(struct hostapd_data *hapd,
134                       struct hostap_sta_driver_data *data, const u8 *addr)
135 {
136         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
137                 return -1;
138         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
139 }
140
141 static inline int
142 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
143                    size_t data_len, int encrypt)
144 {
145         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
146                 return 0;
147         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
148                                              data_len, encrypt,
149                                              hapd->own_addr);
150 }
151
152 static inline int
153 hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
154 {
155         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
156                 return 0;
157         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
158                                         reason);
159 }
160
161 static inline int
162 hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
163 {
164         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
165                 return 0;
166         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
167                                           reason);
168 }
169
170 static inline int
171 hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
172 {
173         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
174                 return 0;
175         return hapd->driver->sta_remove(hapd->drv_priv, addr);
176 }
177
178 static inline int
179 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
180 {
181         if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
182                 return 0;
183         return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
184                                            buf, len);
185 }
186
187 static inline int
188 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
189 {
190         if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
191                 return 0;
192         return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
193                                            buf, len);
194 }
195
196 static inline int
197 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
198 {
199         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
200                 return 0;
201         return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
202 }
203
204 static inline int
205 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
206 {
207         if (hapd->driver == NULL ||
208             hapd->driver->hapd_set_countermeasures == NULL)
209                 return 0;
210         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
211 }
212
213 static inline int
214 hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
215                 u16 aid, u16 capability, const u8 *supp_rates,
216                 size_t supp_rates_len, int flags, u16 listen_interval,
217                 const struct ht_cap_ie *ht_capabilities)
218 {
219         struct hostapd_sta_add_params params;
220
221         if (hapd->driver == NULL)
222                 return 0;
223         if (hapd->driver->sta_add == NULL)
224                 return 0;
225
226         os_memset(&params, 0, sizeof(params));
227         params.addr = addr;
228         params.aid = aid;
229         params.capability = capability;
230         params.supp_rates = supp_rates;
231         params.supp_rates_len = supp_rates_len;
232         params.flags = flags;
233         params.listen_interval = listen_interval;
234         params.ht_capabilities = ht_capabilities;
235         return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
236 }
237
238 static inline int
239 hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
240 {
241         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
242                 return 0;
243         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
244 }
245
246 static inline int
247 hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
248                  int ht_enabled, int sec_channel_offset)
249 {
250         struct hostapd_freq_params data;
251         if (hapd->driver == NULL)
252                 return 0;
253         if (hapd->driver->set_freq == NULL)
254                 return 0;
255         os_memset(&data, 0, sizeof(data));
256         data.mode = mode;
257         data.freq = freq;
258         data.channel = channel;
259         data.ht_enabled = ht_enabled;
260         data.sec_channel_offset = sec_channel_offset;
261         return hapd->driver->set_freq(hapd->drv_priv, &data);
262 }
263
264 static inline int
265 hostapd_set_rts(struct hostapd_data *hapd, int rts)
266 {
267         if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
268                 return 0;
269         return hapd->driver->set_rts(hapd->drv_priv, rts);
270 }
271
272 static inline int
273 hostapd_set_frag(struct hostapd_data *hapd, int frag)
274 {
275         if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
276                 return 0;
277         return hapd->driver->set_frag(hapd->drv_priv, frag);
278 }
279
280 static inline int
281 hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
282 {
283         if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
284                 return 0;
285         return hapd->driver->set_retry(hapd->drv_priv, short_retry,
286                                        long_retry);
287 }
288
289 static inline int
290 hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
291                       int total_flags, int flags_or, int flags_and)
292 {
293         if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
294                 return 0;
295         return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
296                                            flags_or, flags_and);
297 }
298
299 static inline int
300 hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
301                       int *basic_rates, int mode)
302 {
303         if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
304                 return 0;
305         return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
306                                            basic_rates, mode);
307 }
308
309 static inline int
310 hostapd_set_country(struct hostapd_data *hapd, const char *country)
311 {
312         if (hapd->driver == NULL ||
313             hapd->driver->set_country == NULL)
314                 return 0;
315         return hapd->driver->set_country(hapd->drv_priv, country);
316 }
317
318 static inline int
319 hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
320 {
321         if (hapd->driver == NULL ||
322             hapd->driver->set_ieee80211d == NULL)
323                 return 0;
324         return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
325 }
326
327 static inline int
328 hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
329 {
330         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
331                 return 0;
332         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
333 }
334
335 static inline int
336 hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
337                    const u8 *head, size_t head_len,
338                    const u8 *tail, size_t tail_len, int dtim_period)
339 {
340         if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
341                 return 0;
342         return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
343                                              head, head_len,
344                                              tail, tail_len, dtim_period);
345 }
346
347 static inline int
348 hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
349 {
350         if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
351                 return 0;
352         return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
353 }
354
355 static inline int
356 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
357 {
358         if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
359                 return 0;
360         return hapd->driver->set_beacon_int(hapd->drv_priv, value);
361 }
362
363 static inline int
364 hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
365 {
366         if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
367                 return 0;
368         return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
369 }
370
371 static inline int
372 hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
373 {
374         if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
375                 return 0;
376         return hapd->driver->set_cts_protect(hapd->drv_priv, value);
377 }
378
379 static inline int
380 hostapd_set_preamble(struct hostapd_data *hapd, int value)
381 {
382         if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
383                 return 0;
384         return hapd->driver->set_preamble(hapd->drv_priv, value);
385 }
386
387 static inline int
388 hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
389 {
390         if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
391                 return 0;
392         return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
393 }
394
395 static inline int
396 hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
397                             int cw_min, int cw_max, int burst_time)
398 {
399         if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
400                 return 0;
401         return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
402                                                  cw_min, cw_max, burst_time);
403 }
404
405 static inline int
406 hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
407 {
408         if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
409                 return 0;
410         return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
411 }
412
413 static inline int
414 hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
415 {
416         if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
417                 return 0;
418         return hapd->driver->bss_remove(hapd->drv_priv, ifname);
419 }
420
421 static inline int
422 hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
423                        const u8 *mask)
424 {
425         if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
426                 return 1;
427         return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
428 }
429
430 static inline int
431 hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
432                char *ifname, const u8 *addr)
433 {
434         if (hapd->driver == NULL || hapd->driver->if_add == NULL)
435                 return -1;
436         return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
437                                     ifname, addr);
438 }
439
440 static inline int
441 hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
442                   char *ifname, const u8 *addr)
443 {
444         if (hapd->driver == NULL || hapd->driver->if_update == NULL)
445                 return -1;
446         return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
447 }
448
449 static inline int
450 hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
451                   char *ifname, const u8 *addr)
452 {
453         if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
454                 return -1;
455         return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
456 }
457
458 static inline int
459 hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
460                      int interval, int _listen, int *channel,
461                      int *last_rx)
462 {
463         if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
464                 return -1;
465         return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
466                                           interval, _listen, channel, last_rx);
467 }
468
469 static inline struct hostapd_hw_modes *
470 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
471                             u16 *flags)
472 {
473         if (hapd->driver == NULL ||
474             hapd->driver->get_hw_feature_data == NULL)
475                 return NULL;
476         return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
477                                                  flags);
478 }
479
480 static inline int
481 hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
482                      const u8 *addr, int vlan_id)
483 {
484         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
485                 return 0;
486         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
487 }
488
489 static inline int
490 hostapd_driver_commit(struct hostapd_data *hapd)
491 {
492         if (hapd->driver == NULL || hapd->driver->commit == NULL)
493                 return 0;
494         return hapd->driver->commit(hapd->drv_priv);
495 }
496
497 static inline int
498 hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
499                             int accepted, u32 session_timeout)
500 {
501         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
502                 return 0;
503         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
504                                                  session_timeout);
505 }
506
507 static inline int
508 hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
509 {
510         if (hapd->driver == NULL ||
511             hapd->driver->set_radius_acl_expire == NULL)
512                 return 0;
513         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
514 }
515
516 #ifdef CONFIG_IEEE80211N
517 static inline int
518 hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
519                       const u8 *ht_capab, size_t ht_capab_len,
520                       const u8 *ht_oper, size_t ht_oper_len)
521 {
522         if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
523             ht_capab == NULL || ht_oper == NULL)
524                 return 0;
525         return hapd->driver->set_ht_params(
526                 ifname, hapd->drv_priv, ht_capab, ht_capab_len,
527                 ht_oper, ht_oper_len);
528 }
529 #endif /* CONFIG_IEEE80211N */
530
531 static inline int
532 hostapd_drv_none(struct hostapd_data *hapd)
533 {
534         return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
535 }
536
537 static inline int
538 hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
539 {
540         if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
541                 return 0;
542         return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
543                                                hapd->drv_priv, ie, len);
544 }
545
546 static inline int
547 hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
548                               size_t len)
549 {
550         if (hapd->driver == NULL ||
551             hapd->driver->set_wps_probe_resp_ie == NULL)
552                 return 0;
553         return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
554                                                    hapd->drv_priv, ie, len);
555 }
556
557 static inline int hostapd_driver_set_mode(struct hostapd_data *hapd, int mode)
558 {
559         if (hapd->driver == NULL || hapd->driver->set_mode == NULL)
560                 return 0;
561         return hapd->driver->set_mode(hapd->drv_priv, mode);
562 }
563
564 static inline int hostapd_driver_scan(struct hostapd_data *hapd,
565                                       struct wpa_driver_scan_params *params)
566 {
567         if (hapd->driver && hapd->driver->scan2)
568                 return hapd->driver->scan2(hapd->drv_priv, params);
569         return -1;
570 }
571
572 static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
573         struct hostapd_data *hapd)
574 {
575         if (hapd->driver && hapd->driver->get_scan_results2)
576                 return hapd->driver->get_scan_results2(hapd->drv_priv);
577         return NULL;
578 }
579
580 #endif /* DRIVER_I_H */