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