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