driver_i.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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(const char *ifname, struct hostapd_data *hapd,
  56. int enabled)
  57. {
  58. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  59. return 0;
  60. return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
  61. }
  62. static inline int
  63. hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  64. {
  65. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  66. return 0;
  67. return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
  68. enabled);
  69. }
  70. static inline int
  71. hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  72. wpa_alg alg, const u8 *addr, int key_idx,
  73. int set_tx, const u8 *seq, size_t seq_len,
  74. const u8 *key, size_t key_len)
  75. {
  76. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  77. return 0;
  78. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  79. key_idx, set_tx, seq, seq_len, key,
  80. key_len);
  81. }
  82. static inline int
  83. hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  84. const u8 *addr, int idx, u8 *seq)
  85. {
  86. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  87. return 0;
  88. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  89. seq);
  90. }
  91. static inline int
  92. hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
  93. const u8 *addr, int idx, u8 *seq)
  94. {
  95. if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
  96. return -1;
  97. return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
  98. seq);
  99. }
  100. static inline int
  101. hostapd_flush(struct hostapd_data *hapd)
  102. {
  103. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  104. return 0;
  105. return hapd->driver->flush(hapd->drv_priv);
  106. }
  107. static inline int
  108. hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  109. size_t elem_len)
  110. {
  111. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  112. return 0;
  113. return hapd->driver->set_generic_elem(hapd->conf->iface,
  114. hapd->drv_priv, elem, elem_len);
  115. }
  116. static inline int
  117. hostapd_read_sta_data(struct hostapd_data *hapd,
  118. struct hostap_sta_driver_data *data, const u8 *addr)
  119. {
  120. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  121. return -1;
  122. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  123. }
  124. static inline int
  125. hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
  126. size_t data_len, int encrypt)
  127. {
  128. if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
  129. return 0;
  130. return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
  131. data_len, encrypt,
  132. hapd->own_addr);
  133. }
  134. static inline int
  135. hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
  136. {
  137. if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
  138. return 0;
  139. return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
  140. reason);
  141. }
  142. static inline int
  143. hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
  144. {
  145. if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
  146. return 0;
  147. return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
  148. reason);
  149. }
  150. static inline int
  151. hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
  152. {
  153. if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
  154. return 0;
  155. return hapd->driver->sta_remove(hapd->drv_priv, addr);
  156. }
  157. static inline int
  158. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  159. {
  160. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  161. return 0;
  162. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  163. buf, len);
  164. }
  165. static inline int
  166. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  167. {
  168. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  169. return 0;
  170. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  171. buf, len);
  172. }
  173. static inline int
  174. hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
  175. {
  176. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  177. return 0;
  178. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  179. }
  180. static inline int
  181. hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  182. {
  183. if (hapd->driver == NULL ||
  184. hapd->driver->hapd_set_countermeasures == NULL)
  185. return 0;
  186. return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
  187. }
  188. static inline int
  189. hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
  190. u16 aid, u16 capability, const u8 *supp_rates,
  191. size_t supp_rates_len, int flags, u16 listen_interval,
  192. const struct ieee80211_ht_capabilities *ht_capabilities)
  193. {
  194. struct hostapd_sta_add_params params;
  195. if (hapd->driver == NULL)
  196. return 0;
  197. if (hapd->driver->sta_add == NULL)
  198. return 0;
  199. os_memset(&params, 0, sizeof(params));
  200. params.addr = addr;
  201. params.aid = aid;
  202. params.capability = capability;
  203. params.supp_rates = supp_rates;
  204. params.supp_rates_len = supp_rates_len;
  205. params.flags = flags;
  206. params.listen_interval = listen_interval;
  207. params.ht_capabilities = ht_capabilities;
  208. return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
  209. }
  210. static inline int
  211. hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
  212. {
  213. if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
  214. return 0;
  215. return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
  216. }
  217. static inline int
  218. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  219. int ht_enabled, int sec_channel_offset)
  220. {
  221. struct hostapd_freq_params data;
  222. if (hapd->driver == NULL)
  223. return 0;
  224. if (hapd->driver->set_freq == NULL)
  225. return 0;
  226. os_memset(&data, 0, sizeof(data));
  227. data.mode = mode;
  228. data.freq = freq;
  229. data.channel = channel;
  230. data.ht_enabled = ht_enabled;
  231. data.sec_channel_offset = sec_channel_offset;
  232. return hapd->driver->set_freq(hapd->drv_priv, &data);
  233. }
  234. static inline int
  235. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  236. {
  237. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  238. return 0;
  239. return hapd->driver->set_rts(hapd->drv_priv, rts);
  240. }
  241. static inline int
  242. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  243. {
  244. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  245. return 0;
  246. return hapd->driver->set_frag(hapd->drv_priv, frag);
  247. }
  248. static inline int
  249. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  250. int total_flags, int flags_or, int flags_and)
  251. {
  252. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  253. return 0;
  254. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  255. flags_or, flags_and);
  256. }
  257. static inline int
  258. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  259. int *basic_rates, int mode)
  260. {
  261. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  262. return 0;
  263. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  264. basic_rates, mode);
  265. }
  266. static inline int
  267. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  268. {
  269. if (hapd->driver == NULL ||
  270. hapd->driver->set_country == NULL)
  271. return 0;
  272. return hapd->driver->set_country(hapd->drv_priv, country);
  273. }
  274. static inline int
  275. hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  276. {
  277. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  278. return 0;
  279. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  280. }
  281. static inline int
  282. hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
  283. const u8 *head, size_t head_len,
  284. const u8 *tail, size_t tail_len, int dtim_period,
  285. int beacon_int)
  286. {
  287. if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
  288. return 0;
  289. return hapd->driver->set_beacon(ifname, hapd->drv_priv,
  290. head, head_len, tail, tail_len,
  291. dtim_period, beacon_int);
  292. }
  293. static inline int
  294. hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
  295. {
  296. if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
  297. return 0;
  298. return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
  299. }
  300. static inline int
  301. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  302. {
  303. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  304. return 0;
  305. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  306. }
  307. static inline int
  308. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  309. {
  310. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  311. return 0;
  312. return hapd->driver->set_preamble(hapd->drv_priv, value);
  313. }
  314. static inline int
  315. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  316. {
  317. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  318. return 0;
  319. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  320. }
  321. static inline int
  322. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  323. int cw_min, int cw_max, int burst_time)
  324. {
  325. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  326. return 0;
  327. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  328. cw_min, cw_max, burst_time);
  329. }
  330. static inline int
  331. hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
  332. {
  333. if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
  334. return 0;
  335. return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
  336. }
  337. static inline int
  338. hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
  339. {
  340. if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
  341. return 0;
  342. return hapd->driver->bss_remove(hapd->drv_priv, ifname);
  343. }
  344. static inline int
  345. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  346. const u8 *mask)
  347. {
  348. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  349. return 1;
  350. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  351. }
  352. static inline int
  353. hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  354. char *ifname, const u8 *addr)
  355. {
  356. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  357. return -1;
  358. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  359. ifname, addr);
  360. }
  361. static inline int
  362. hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  363. char *ifname, const u8 *addr)
  364. {
  365. if (hapd->driver == NULL || hapd->driver->if_update == NULL)
  366. return -1;
  367. return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
  368. }
  369. static inline int
  370. hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  371. char *ifname, const u8 *addr)
  372. {
  373. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  374. return -1;
  375. return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
  376. }
  377. static inline struct hostapd_hw_modes *
  378. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  379. u16 *flags)
  380. {
  381. if (hapd->driver == NULL ||
  382. hapd->driver->get_hw_feature_data == NULL)
  383. return NULL;
  384. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  385. flags);
  386. }
  387. static inline int
  388. hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  389. const u8 *addr, int vlan_id)
  390. {
  391. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  392. return 0;
  393. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
  394. }
  395. static inline int
  396. hostapd_driver_commit(struct hostapd_data *hapd)
  397. {
  398. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  399. return 0;
  400. return hapd->driver->commit(hapd->drv_priv);
  401. }
  402. static inline int
  403. hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
  404. int accepted, u32 session_timeout)
  405. {
  406. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  407. return 0;
  408. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  409. session_timeout);
  410. }
  411. static inline int
  412. hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
  413. {
  414. if (hapd->driver == NULL ||
  415. hapd->driver->set_radius_acl_expire == NULL)
  416. return 0;
  417. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  418. }
  419. static inline int
  420. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  421. const u8 *ht_capab, size_t ht_capab_len,
  422. const u8 *ht_oper, size_t ht_oper_len)
  423. {
  424. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  425. ht_capab == NULL || ht_oper == NULL)
  426. return 0;
  427. return hapd->driver->set_ht_params(
  428. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  429. ht_oper, ht_oper_len);
  430. }
  431. static inline int
  432. hostapd_drv_none(struct hostapd_data *hapd)
  433. {
  434. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  435. }
  436. static inline int
  437. hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
  438. {
  439. if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
  440. return 0;
  441. return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
  442. hapd->drv_priv, ie, len);
  443. }
  444. static inline int
  445. hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
  446. size_t len)
  447. {
  448. if (hapd->driver == NULL ||
  449. hapd->driver->set_wps_probe_resp_ie == NULL)
  450. return 0;
  451. return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
  452. hapd->drv_priv, ie, len);
  453. }
  454. static inline int hostapd_driver_scan(struct hostapd_data *hapd,
  455. struct wpa_driver_scan_params *params)
  456. {
  457. if (hapd->driver && hapd->driver->scan2)
  458. return hapd->driver->scan2(hapd->drv_priv, params);
  459. return -1;
  460. }
  461. static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
  462. struct hostapd_data *hapd)
  463. {
  464. if (hapd->driver && hapd->driver->get_scan_results2)
  465. return hapd->driver->get_scan_results2(hapd->drv_priv);
  466. return NULL;
  467. }
  468. #endif /* DRIVER_I_H */