driver_i.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * hostapd - internal driver interface wrappers
  3. * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2007-2008, Intel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #ifndef DRIVER_I_H
  16. #define DRIVER_I_H
  17. #include "driver.h"
  18. #include "config.h"
  19. static inline void *
  20. hostapd_driver_init(struct hostapd_data *hapd)
  21. {
  22. if (hapd->driver == NULL || hapd->driver->init == NULL)
  23. return NULL;
  24. return hapd->driver->init(hapd);
  25. }
  26. static inline void *
  27. hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
  28. {
  29. if (hapd->driver == NULL || hapd->driver->init_bssid == NULL)
  30. return NULL;
  31. return hapd->driver->init_bssid(hapd, bssid);
  32. }
  33. static inline void
  34. hostapd_driver_deinit(struct hostapd_data *hapd)
  35. {
  36. if (hapd->driver == NULL || hapd->driver->deinit == NULL)
  37. return;
  38. hapd->driver->deinit(hapd->drv_priv);
  39. }
  40. static inline int
  41. hostapd_wireless_event_init(struct hostapd_data *hapd)
  42. {
  43. if (hapd->driver == NULL ||
  44. hapd->driver->wireless_event_init == NULL)
  45. return 0;
  46. return hapd->driver->wireless_event_init(hapd->drv_priv);
  47. }
  48. static inline void
  49. hostapd_wireless_event_deinit(struct hostapd_data *hapd)
  50. {
  51. if (hapd->driver == NULL ||
  52. hapd->driver->wireless_event_deinit == NULL)
  53. return;
  54. hapd->driver->wireless_event_deinit(hapd->drv_priv);
  55. }
  56. static inline int
  57. hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
  58. int enabled)
  59. {
  60. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  61. return 0;
  62. return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
  63. }
  64. static inline int
  65. hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  66. {
  67. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  68. return 0;
  69. return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
  70. enabled);
  71. }
  72. static inline int
  73. hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  74. wpa_alg alg, const u8 *addr, int key_idx,
  75. int set_tx, const u8 *seq, size_t seq_len,
  76. const u8 *key, size_t key_len)
  77. {
  78. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  79. return 0;
  80. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  81. key_idx, set_tx, seq, seq_len, key,
  82. key_len);
  83. }
  84. static inline int
  85. hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  86. const u8 *addr, int idx, u8 *seq)
  87. {
  88. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  89. return 0;
  90. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  91. seq);
  92. }
  93. static inline int
  94. hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
  95. const u8 *addr, int idx, u8 *seq)
  96. {
  97. if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
  98. return -1;
  99. return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
  100. seq);
  101. }
  102. static inline int
  103. hostapd_flush(struct hostapd_data *hapd)
  104. {
  105. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  106. return 0;
  107. return hapd->driver->flush(hapd->drv_priv);
  108. }
  109. static inline int
  110. hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  111. size_t elem_len)
  112. {
  113. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  114. return 0;
  115. return hapd->driver->set_generic_elem(hapd->conf->iface,
  116. hapd->drv_priv, elem, elem_len);
  117. }
  118. static inline int
  119. hostapd_read_sta_data(struct hostapd_data *hapd,
  120. struct hostap_sta_driver_data *data, const u8 *addr)
  121. {
  122. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  123. return -1;
  124. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  125. }
  126. static inline int
  127. hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
  128. size_t data_len, int encrypt)
  129. {
  130. if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
  131. return 0;
  132. return hapd->driver->send_eapol(hapd->drv_priv, addr, data, data_len,
  133. encrypt, hapd->own_addr);
  134. }
  135. static inline int
  136. hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr, int reason)
  137. {
  138. if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
  139. return 0;
  140. return hapd->driver->sta_deauth(hapd->drv_priv, addr, 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, addr, reason);
  148. }
  149. static inline int
  150. hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
  151. {
  152. if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
  153. return 0;
  154. return hapd->driver->sta_remove(hapd->drv_priv, addr);
  155. }
  156. static inline int
  157. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  158. {
  159. if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
  160. return 0;
  161. return hapd->driver->get_ssid(hapd->conf->iface, hapd->drv_priv, buf,
  162. len);
  163. }
  164. static inline int
  165. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  166. {
  167. if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
  168. return 0;
  169. return hapd->driver->set_ssid(hapd->conf->iface, hapd->drv_priv, buf,
  170. len);
  171. }
  172. static inline int
  173. hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
  174. int flags)
  175. {
  176. if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
  177. return 0;
  178. return hapd->driver->send_mgmt_frame(hapd->drv_priv, msg, len, flags);
  179. }
  180. static inline int
  181. hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  182. {
  183. if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
  184. return 0;
  185. return hapd->driver->set_countermeasures(hapd->drv_priv, enabled);
  186. }
  187. static inline int
  188. hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
  189. u16 aid, u16 capability, const u8 *supp_rates,
  190. size_t supp_rates_len, int flags, u16 listen_interval,
  191. const struct ht_cap_ie *ht_capabilities)
  192. {
  193. struct hostapd_sta_add_params params;
  194. if (hapd->driver == NULL)
  195. return 0;
  196. if (hapd->driver->sta_add == NULL)
  197. return 0;
  198. os_memset(&params, 0, sizeof(params));
  199. params.addr = addr;
  200. params.aid = aid;
  201. params.capability = capability;
  202. params.supp_rates = supp_rates;
  203. params.supp_rates_len = supp_rates_len;
  204. params.flags = flags;
  205. params.listen_interval = listen_interval;
  206. params.ht_capabilities = ht_capabilities;
  207. return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
  208. }
  209. static inline int
  210. hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
  211. {
  212. if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
  213. return 0;
  214. return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
  215. }
  216. static inline int
  217. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  218. int ht_enabled, int sec_channel_offset)
  219. {
  220. struct hostapd_freq_params data;
  221. if (hapd->driver == NULL)
  222. return 0;
  223. if (hapd->driver->set_freq == NULL)
  224. return 0;
  225. os_memset(&data, 0, sizeof(data));
  226. data.mode = mode;
  227. data.freq = freq;
  228. data.channel = channel;
  229. data.ht_enabled = ht_enabled;
  230. data.sec_channel_offset = sec_channel_offset;
  231. return hapd->driver->set_freq(hapd->drv_priv, &data);
  232. }
  233. static inline int
  234. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  235. {
  236. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  237. return 0;
  238. return hapd->driver->set_rts(hapd->drv_priv, rts);
  239. }
  240. static inline int
  241. hostapd_get_rts(struct hostapd_data *hapd, int *rts)
  242. {
  243. if (hapd->driver == NULL || hapd->driver->get_rts == NULL)
  244. return 0;
  245. return hapd->driver->get_rts(hapd->drv_priv, rts);
  246. }
  247. static inline int
  248. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  249. {
  250. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  251. return 0;
  252. return hapd->driver->set_frag(hapd->drv_priv, frag);
  253. }
  254. static inline int
  255. hostapd_get_frag(struct hostapd_data *hapd, int *frag)
  256. {
  257. if (hapd->driver == NULL || hapd->driver->get_frag == NULL)
  258. return 0;
  259. return hapd->driver->get_frag(hapd->drv_priv, frag);
  260. }
  261. static inline int
  262. hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
  263. {
  264. if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
  265. return 0;
  266. return hapd->driver->set_retry(hapd->drv_priv, short_retry,
  267. long_retry);
  268. }
  269. static inline int
  270. hostapd_get_retry(struct hostapd_data *hapd, int *short_retry, int *long_retry)
  271. {
  272. if (hapd->driver == NULL || hapd->driver->get_retry == NULL)
  273. return 0;
  274. return hapd->driver->get_retry(hapd->drv_priv, short_retry,
  275. long_retry);
  276. }
  277. static inline int
  278. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  279. int total_flags, int flags_or, int flags_and)
  280. {
  281. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  282. return 0;
  283. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  284. flags_or, flags_and);
  285. }
  286. static inline int
  287. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  288. int *basic_rates, int mode)
  289. {
  290. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  291. return 0;
  292. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  293. basic_rates, mode);
  294. }
  295. static inline int
  296. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  297. {
  298. if (hapd->driver == NULL ||
  299. hapd->driver->set_country == NULL)
  300. return 0;
  301. return hapd->driver->set_country(hapd->drv_priv, country);
  302. }
  303. static inline int
  304. hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
  305. {
  306. if (hapd->driver == NULL ||
  307. hapd->driver->set_ieee80211d == NULL)
  308. return 0;
  309. return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
  310. }
  311. static inline int
  312. hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  313. {
  314. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  315. return 0;
  316. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  317. }
  318. static inline int
  319. hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
  320. const u8 *head, size_t head_len,
  321. const u8 *tail, size_t tail_len, int dtim_period)
  322. {
  323. if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
  324. return 0;
  325. return hapd->driver->set_beacon(ifname, hapd->drv_priv, head, head_len,
  326. tail, tail_len, dtim_period);
  327. }
  328. static inline int
  329. hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
  330. {
  331. if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
  332. return 0;
  333. return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
  334. }
  335. static inline int
  336. hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
  337. {
  338. if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
  339. return 0;
  340. return hapd->driver->set_beacon_int(hapd->drv_priv, value);
  341. }
  342. static inline int
  343. hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
  344. {
  345. if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
  346. return 0;
  347. return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
  348. }
  349. static inline int
  350. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  351. {
  352. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  353. return 0;
  354. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  355. }
  356. static inline int
  357. hostapd_set_key_tx_rx_threshold(struct hostapd_data *hapd, int value)
  358. {
  359. if (hapd->driver == NULL ||
  360. hapd->driver->set_key_tx_rx_threshold == NULL)
  361. return 0;
  362. return hapd->driver->set_key_tx_rx_threshold(hapd->drv_priv, value);
  363. }
  364. static inline int
  365. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  366. {
  367. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  368. return 0;
  369. return hapd->driver->set_preamble(hapd->drv_priv, value);
  370. }
  371. static inline int
  372. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  373. {
  374. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  375. return 0;
  376. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  377. }
  378. static inline int
  379. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  380. int cw_min, int cw_max, int burst_time)
  381. {
  382. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  383. return 0;
  384. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  385. cw_min, cw_max, burst_time);
  386. }
  387. static inline int
  388. hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
  389. {
  390. if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
  391. return 0;
  392. return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
  393. }
  394. static inline int
  395. hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
  396. {
  397. if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
  398. return 0;
  399. return hapd->driver->bss_remove(hapd->drv_priv, ifname);
  400. }
  401. static inline int
  402. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  403. const u8 *mask)
  404. {
  405. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  406. return 1;
  407. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  408. }
  409. static inline int
  410. hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  411. char *ifname, const u8 *addr)
  412. {
  413. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  414. return -1;
  415. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  416. ifname, addr);
  417. }
  418. static inline int
  419. hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  420. char *ifname, const u8 *addr)
  421. {
  422. if (hapd->driver == NULL || hapd->driver->if_update == NULL)
  423. return -1;
  424. return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
  425. }
  426. static inline int
  427. hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  428. char *ifname, const u8 *addr)
  429. {
  430. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  431. return -1;
  432. return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
  433. }
  434. static inline int
  435. hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
  436. int interval, int _listen, int *channel,
  437. int *last_rx)
  438. {
  439. if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
  440. return -1;
  441. return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
  442. interval, _listen, channel, last_rx);
  443. }
  444. static inline struct hostapd_hw_modes *
  445. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  446. u16 *flags)
  447. {
  448. if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
  449. return NULL;
  450. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  451. flags);
  452. }
  453. static inline int
  454. hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  455. const u8 *addr, int vlan_id)
  456. {
  457. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  458. return 0;
  459. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
  460. }
  461. static inline int
  462. hostapd_driver_commit(struct hostapd_data *hapd)
  463. {
  464. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  465. return 0;
  466. return hapd->driver->commit(hapd->drv_priv);
  467. }
  468. static inline int
  469. hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
  470. int accepted, u32 session_timeout)
  471. {
  472. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  473. return 0;
  474. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  475. session_timeout);
  476. }
  477. static inline int
  478. hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
  479. {
  480. if (hapd->driver == NULL ||
  481. hapd->driver->set_radius_acl_expire == NULL)
  482. return 0;
  483. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  484. }
  485. #ifdef CONFIG_IEEE80211N
  486. static inline int
  487. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  488. const u8 *ht_capab, size_t ht_capab_len,
  489. const u8 *ht_oper, size_t ht_oper_len)
  490. {
  491. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  492. ht_capab == NULL || ht_oper == NULL)
  493. return 0;
  494. return hapd->driver->set_ht_params(
  495. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  496. ht_oper, ht_oper_len);
  497. }
  498. #endif /* CONFIG_IEEE80211N */
  499. static inline int
  500. hostapd_drv_none(struct hostapd_data *hapd)
  501. {
  502. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  503. }
  504. static inline int
  505. hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
  506. {
  507. if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
  508. return 0;
  509. return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
  510. hapd->drv_priv, ie, len);
  511. }
  512. static inline int
  513. hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
  514. size_t len)
  515. {
  516. if (hapd->driver == NULL ||
  517. hapd->driver->set_wps_probe_resp_ie == NULL)
  518. return 0;
  519. return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
  520. hapd->drv_priv, ie, len);
  521. }
  522. static inline const struct hostapd_neighbor_bss *
  523. hostapd_driver_get_neighbor_bss(struct hostapd_data *hapd, size_t *num)
  524. {
  525. if (hapd->driver == NULL || hapd->driver->get_neighbor_bss == NULL)
  526. return NULL;
  527. return hapd->driver->get_neighbor_bss(hapd->drv_priv, num);
  528. }
  529. #endif /* DRIVER_I_H */