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