driver_i.h 8.6 KB

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