driver_i.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 void
  19. hostapd_driver_deinit(struct hostapd_data *hapd)
  20. {
  21. if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
  22. return;
  23. hapd->driver->hapd_deinit(hapd->drv_priv);
  24. }
  25. static inline int
  26. hostapd_set_ieee8021x(struct hostapd_data *hapd, struct wpa_bss_params *params)
  27. {
  28. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  29. return 0;
  30. return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
  31. }
  32. static inline int
  33. hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  34. {
  35. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  36. return 0;
  37. return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
  38. enabled);
  39. }
  40. static inline int
  41. hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  42. const u8 *addr, int idx, u8 *seq)
  43. {
  44. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  45. return 0;
  46. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  47. seq);
  48. }
  49. static inline int
  50. hostapd_flush(struct hostapd_data *hapd)
  51. {
  52. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  53. return 0;
  54. return hapd->driver->flush(hapd->drv_priv);
  55. }
  56. static inline int
  57. hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  58. size_t elem_len)
  59. {
  60. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  61. return 0;
  62. return hapd->driver->set_generic_elem(hapd->conf->iface,
  63. hapd->drv_priv, elem, elem_len);
  64. }
  65. static inline int
  66. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  67. {
  68. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  69. return 0;
  70. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  71. buf, len);
  72. }
  73. static inline int
  74. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  75. {
  76. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  77. return 0;
  78. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  79. buf, len);
  80. }
  81. static inline int
  82. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  83. int ht_enabled, int sec_channel_offset)
  84. {
  85. struct hostapd_freq_params data;
  86. if (hapd->driver == NULL)
  87. return 0;
  88. if (hapd->driver->set_freq == NULL)
  89. return 0;
  90. os_memset(&data, 0, sizeof(data));
  91. data.mode = mode;
  92. data.freq = freq;
  93. data.channel = channel;
  94. data.ht_enabled = ht_enabled;
  95. data.sec_channel_offset = sec_channel_offset;
  96. return hapd->driver->set_freq(hapd->drv_priv, &data);
  97. }
  98. static inline int
  99. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  100. {
  101. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  102. return 0;
  103. return hapd->driver->set_rts(hapd->drv_priv, rts);
  104. }
  105. static inline int
  106. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  107. {
  108. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  109. return 0;
  110. return hapd->driver->set_frag(hapd->drv_priv, frag);
  111. }
  112. static inline int
  113. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  114. int total_flags, int flags_or, int flags_and)
  115. {
  116. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  117. return 0;
  118. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  119. flags_or, flags_and);
  120. }
  121. static inline int
  122. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  123. int *basic_rates, int mode)
  124. {
  125. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  126. return 0;
  127. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  128. basic_rates, mode);
  129. }
  130. static inline int
  131. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  132. {
  133. if (hapd->driver == NULL ||
  134. hapd->driver->set_country == NULL)
  135. return 0;
  136. return hapd->driver->set_country(hapd->drv_priv, country);
  137. }
  138. static inline int
  139. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  140. {
  141. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  142. return 0;
  143. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  144. }
  145. static inline int
  146. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  147. {
  148. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  149. return 0;
  150. return hapd->driver->set_preamble(hapd->drv_priv, value);
  151. }
  152. static inline int
  153. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  154. {
  155. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  156. return 0;
  157. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  158. }
  159. static inline int
  160. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  161. int cw_min, int cw_max, int burst_time)
  162. {
  163. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  164. return 0;
  165. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  166. cw_min, cw_max, burst_time);
  167. }
  168. static inline int
  169. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  170. const u8 *mask)
  171. {
  172. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  173. return 1;
  174. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  175. }
  176. static inline int
  177. hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  178. const char *ifname, const u8 *addr, void *bss_ctx)
  179. {
  180. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  181. return -1;
  182. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  183. ifname, addr, bss_ctx);
  184. }
  185. static inline int
  186. hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  187. const char *ifname)
  188. {
  189. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  190. return -1;
  191. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  192. }
  193. static inline struct hostapd_hw_modes *
  194. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  195. u16 *flags)
  196. {
  197. if (hapd->driver == NULL ||
  198. hapd->driver->get_hw_feature_data == NULL)
  199. return NULL;
  200. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  201. flags);
  202. }
  203. static inline int
  204. hostapd_driver_commit(struct hostapd_data *hapd)
  205. {
  206. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  207. return 0;
  208. return hapd->driver->commit(hapd->drv_priv);
  209. }
  210. static inline int
  211. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  212. const u8 *ht_capab, size_t ht_capab_len,
  213. const u8 *ht_oper, size_t ht_oper_len)
  214. {
  215. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  216. ht_capab == NULL || ht_oper == NULL)
  217. return 0;
  218. return hapd->driver->set_ht_params(
  219. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  220. ht_oper, ht_oper_len);
  221. }
  222. static inline int
  223. hostapd_drv_none(struct hostapd_data *hapd)
  224. {
  225. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  226. }
  227. static inline int hostapd_driver_scan(struct hostapd_data *hapd,
  228. struct wpa_driver_scan_params *params)
  229. {
  230. if (hapd->driver && hapd->driver->scan2)
  231. return hapd->driver->scan2(hapd->drv_priv, params);
  232. return -1;
  233. }
  234. static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
  235. struct hostapd_data *hapd)
  236. {
  237. if (hapd->driver && hapd->driver->get_scan_results2)
  238. return hapd->driver->get_scan_results2(hapd->drv_priv);
  239. return NULL;
  240. }
  241. #endif /* DRIVER_I_H */