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