driver_i.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
  96. {
  97. if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
  98. return 0;
  99. return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
  100. reason);
  101. }
  102. static inline int
  103. hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
  104. {
  105. if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
  106. return 0;
  107. return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
  108. reason);
  109. }
  110. static inline int
  111. hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
  112. {
  113. if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
  114. return 0;
  115. return hapd->driver->sta_remove(hapd->drv_priv, addr);
  116. }
  117. static inline int
  118. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  119. {
  120. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  121. return 0;
  122. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  123. buf, len);
  124. }
  125. static inline int
  126. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  127. {
  128. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  129. return 0;
  130. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  131. buf, len);
  132. }
  133. static inline int
  134. hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  135. {
  136. if (hapd->driver == NULL ||
  137. hapd->driver->hapd_set_countermeasures == NULL)
  138. return 0;
  139. return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
  140. }
  141. static inline int
  142. hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
  143. u16 aid, u16 capability, const u8 *supp_rates,
  144. size_t supp_rates_len, u16 listen_interval,
  145. const struct ieee80211_ht_capabilities *ht_capabilities)
  146. {
  147. struct hostapd_sta_add_params params;
  148. if (hapd->driver == NULL)
  149. return 0;
  150. if (hapd->driver->sta_add == NULL)
  151. return 0;
  152. os_memset(&params, 0, sizeof(params));
  153. params.addr = addr;
  154. params.aid = aid;
  155. params.capability = capability;
  156. params.supp_rates = supp_rates;
  157. params.supp_rates_len = supp_rates_len;
  158. params.listen_interval = listen_interval;
  159. params.ht_capabilities = ht_capabilities;
  160. return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
  161. }
  162. static inline int
  163. hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
  164. {
  165. if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
  166. return 0;
  167. return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
  168. }
  169. static inline int
  170. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  171. int ht_enabled, int sec_channel_offset)
  172. {
  173. struct hostapd_freq_params data;
  174. if (hapd->driver == NULL)
  175. return 0;
  176. if (hapd->driver->set_freq == NULL)
  177. return 0;
  178. os_memset(&data, 0, sizeof(data));
  179. data.mode = mode;
  180. data.freq = freq;
  181. data.channel = channel;
  182. data.ht_enabled = ht_enabled;
  183. data.sec_channel_offset = sec_channel_offset;
  184. return hapd->driver->set_freq(hapd->drv_priv, &data);
  185. }
  186. static inline int
  187. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  188. {
  189. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  190. return 0;
  191. return hapd->driver->set_rts(hapd->drv_priv, rts);
  192. }
  193. static inline int
  194. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  195. {
  196. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  197. return 0;
  198. return hapd->driver->set_frag(hapd->drv_priv, frag);
  199. }
  200. static inline int
  201. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  202. int total_flags, int flags_or, int flags_and)
  203. {
  204. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  205. return 0;
  206. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  207. flags_or, flags_and);
  208. }
  209. static inline int
  210. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  211. int *basic_rates, int mode)
  212. {
  213. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  214. return 0;
  215. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  216. basic_rates, mode);
  217. }
  218. static inline int
  219. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  220. {
  221. if (hapd->driver == NULL ||
  222. hapd->driver->set_country == NULL)
  223. return 0;
  224. return hapd->driver->set_country(hapd->drv_priv, country);
  225. }
  226. static inline int
  227. hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
  228. const u8 *head, size_t head_len,
  229. const u8 *tail, size_t tail_len, int dtim_period,
  230. int beacon_int)
  231. {
  232. if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
  233. return 0;
  234. return hapd->driver->set_beacon(ifname, hapd->drv_priv,
  235. head, head_len, tail, tail_len,
  236. dtim_period, beacon_int);
  237. }
  238. static inline int
  239. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  240. {
  241. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  242. return 0;
  243. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  244. }
  245. static inline int
  246. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  247. {
  248. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  249. return 0;
  250. return hapd->driver->set_preamble(hapd->drv_priv, value);
  251. }
  252. static inline int
  253. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  254. {
  255. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  256. return 0;
  257. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  258. }
  259. static inline int
  260. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  261. int cw_min, int cw_max, int burst_time)
  262. {
  263. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  264. return 0;
  265. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  266. cw_min, cw_max, burst_time);
  267. }
  268. static inline int
  269. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  270. const u8 *mask)
  271. {
  272. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  273. return 1;
  274. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  275. }
  276. static inline int
  277. hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  278. const char *ifname, const u8 *addr, void *bss_ctx)
  279. {
  280. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  281. return -1;
  282. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  283. ifname, addr, bss_ctx);
  284. }
  285. static inline int
  286. hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  287. const char *ifname)
  288. {
  289. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  290. return -1;
  291. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  292. }
  293. static inline struct hostapd_hw_modes *
  294. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  295. u16 *flags)
  296. {
  297. if (hapd->driver == NULL ||
  298. hapd->driver->get_hw_feature_data == NULL)
  299. return NULL;
  300. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  301. flags);
  302. }
  303. static inline int
  304. hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  305. const u8 *addr, int vlan_id)
  306. {
  307. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  308. return 0;
  309. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
  310. }
  311. static inline int
  312. hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr, int aid,
  313. int val)
  314. {
  315. if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
  316. return 0;
  317. return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val);
  318. }
  319. static inline int
  320. hostapd_driver_commit(struct hostapd_data *hapd)
  321. {
  322. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  323. return 0;
  324. return hapd->driver->commit(hapd->drv_priv);
  325. }
  326. static inline int
  327. hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
  328. int accepted, u32 session_timeout)
  329. {
  330. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  331. return 0;
  332. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  333. session_timeout);
  334. }
  335. static inline int
  336. hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
  337. {
  338. if (hapd->driver == NULL ||
  339. hapd->driver->set_radius_acl_expire == NULL)
  340. return 0;
  341. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  342. }
  343. static inline int
  344. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  345. const u8 *ht_capab, size_t ht_capab_len,
  346. const u8 *ht_oper, size_t ht_oper_len)
  347. {
  348. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  349. ht_capab == NULL || ht_oper == NULL)
  350. return 0;
  351. return hapd->driver->set_ht_params(
  352. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  353. ht_oper, ht_oper_len);
  354. }
  355. static inline int
  356. hostapd_drv_none(struct hostapd_data *hapd)
  357. {
  358. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  359. }
  360. static inline int hostapd_driver_scan(struct hostapd_data *hapd,
  361. struct wpa_driver_scan_params *params)
  362. {
  363. if (hapd->driver && hapd->driver->scan2)
  364. return hapd->driver->scan2(hapd->drv_priv, params);
  365. return -1;
  366. }
  367. static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
  368. struct hostapd_data *hapd)
  369. {
  370. if (hapd->driver && hapd->driver->get_scan_results2)
  371. return hapd->driver->get_scan_results2(hapd->drv_priv);
  372. return NULL;
  373. }
  374. #endif /* DRIVER_I_H */