driver_i.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * hostapd - internal driver interface wrappers
  3. * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef DRIVER_I_H
  15. #define DRIVER_I_H
  16. #include "drivers/driver.h"
  17. #include "ap/config.h"
  18. static inline int
  19. hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
  20. {
  21. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  22. return 0;
  23. return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
  24. }
  25. static inline int
  26. hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  27. {
  28. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  29. return 0;
  30. return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
  31. enabled);
  32. }
  33. static inline int
  34. hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  35. const u8 *addr, int idx, u8 *seq)
  36. {
  37. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  38. return 0;
  39. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  40. seq);
  41. }
  42. static inline int
  43. hostapd_flush(struct hostapd_data *hapd)
  44. {
  45. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  46. return 0;
  47. return hapd->driver->flush(hapd->drv_priv);
  48. }
  49. static inline int
  50. hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  51. size_t elem_len)
  52. {
  53. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  54. return 0;
  55. return hapd->driver->set_generic_elem(hapd->conf->iface,
  56. hapd->drv_priv, elem, elem_len);
  57. }
  58. static inline int
  59. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  60. {
  61. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  62. return 0;
  63. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  64. buf, len);
  65. }
  66. static inline int
  67. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  68. {
  69. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  70. return 0;
  71. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  72. buf, len);
  73. }
  74. static inline int
  75. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  76. int ht_enabled, int sec_channel_offset)
  77. {
  78. struct hostapd_freq_params data;
  79. if (hapd->driver == NULL)
  80. return 0;
  81. if (hapd->driver->set_freq == NULL)
  82. return 0;
  83. os_memset(&data, 0, sizeof(data));
  84. data.mode = mode;
  85. data.freq = freq;
  86. data.channel = channel;
  87. data.ht_enabled = ht_enabled;
  88. data.sec_channel_offset = sec_channel_offset;
  89. return hapd->driver->set_freq(hapd->drv_priv, &data);
  90. }
  91. static inline int
  92. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  93. {
  94. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  95. return 0;
  96. return hapd->driver->set_rts(hapd->drv_priv, rts);
  97. }
  98. static inline int
  99. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  100. {
  101. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  102. return 0;
  103. return hapd->driver->set_frag(hapd->drv_priv, frag);
  104. }
  105. static inline int
  106. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  107. int total_flags, int flags_or, int flags_and)
  108. {
  109. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  110. return 0;
  111. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  112. flags_or, flags_and);
  113. }
  114. static inline int
  115. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  116. int *basic_rates, int mode)
  117. {
  118. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  119. return 0;
  120. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  121. basic_rates, mode);
  122. }
  123. static inline int
  124. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  125. {
  126. if (hapd->driver == NULL ||
  127. hapd->driver->set_country == NULL)
  128. return 0;
  129. return hapd->driver->set_country(hapd->drv_priv, country);
  130. }
  131. static inline int
  132. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  133. {
  134. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  135. return 0;
  136. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  137. }
  138. static inline int
  139. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  140. {
  141. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  142. return 0;
  143. return hapd->driver->set_preamble(hapd->drv_priv, value);
  144. }
  145. static inline int
  146. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  147. {
  148. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  149. return 0;
  150. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  151. }
  152. static inline int
  153. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  154. int cw_min, int cw_max, int burst_time)
  155. {
  156. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  157. return 0;
  158. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  159. cw_min, cw_max, burst_time);
  160. }
  161. static inline int
  162. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  163. const u8 *mask)
  164. {
  165. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  166. return 1;
  167. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  168. }
  169. static inline int
  170. hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  171. const char *ifname, const u8 *addr, void *bss_ctx)
  172. {
  173. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  174. return -1;
  175. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  176. ifname, addr, bss_ctx);
  177. }
  178. static inline int
  179. hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  180. const char *ifname)
  181. {
  182. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  183. return -1;
  184. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  185. }
  186. static inline struct hostapd_hw_modes *
  187. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  188. u16 *flags)
  189. {
  190. if (hapd->driver == NULL ||
  191. hapd->driver->get_hw_feature_data == NULL)
  192. return NULL;
  193. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  194. flags);
  195. }
  196. static inline int
  197. hostapd_driver_commit(struct hostapd_data *hapd)
  198. {
  199. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  200. return 0;
  201. return hapd->driver->commit(hapd->drv_priv);
  202. }
  203. static inline int
  204. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  205. const u8 *ht_capab, size_t ht_capab_len,
  206. const u8 *ht_oper, size_t ht_oper_len)
  207. {
  208. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  209. ht_capab == NULL || ht_oper == NULL)
  210. return 0;
  211. return hapd->driver->set_ht_params(
  212. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  213. ht_oper, ht_oper_len);
  214. }
  215. static inline int
  216. hostapd_drv_none(struct hostapd_data *hapd)
  217. {
  218. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  219. }
  220. static inline int hostapd_driver_scan(struct hostapd_data *hapd,
  221. struct wpa_driver_scan_params *params)
  222. {
  223. if (hapd->driver && hapd->driver->scan2)
  224. return hapd->driver->scan2(hapd->drv_priv, params);
  225. return -1;
  226. }
  227. static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
  228. struct hostapd_data *hapd)
  229. {
  230. if (hapd->driver && hapd->driver->get_scan_results2)
  231. return hapd->driver->get_scan_results2(hapd->drv_priv);
  232. return NULL;
  233. }
  234. #endif /* DRIVER_I_H */