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