driver_i.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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 "drivers/driver.h"
  18. #include "config.h"
  19. static inline void *
  20. hostapd_driver_init(struct hostapd_data *hapd, const u8 *bssid)
  21. {
  22. struct wpa_init_params params;
  23. void *ret;
  24. size_t i;
  25. if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
  26. return NULL;
  27. os_memset(&params, 0, sizeof(params));
  28. params.bssid = bssid;
  29. params.ifname = hapd->conf->iface;
  30. params.ssid = (const u8 *) hapd->conf->ssid.ssid;
  31. params.ssid_len = hapd->conf->ssid.ssid_len;
  32. params.test_socket = hapd->conf->test_socket;
  33. params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
  34. params.num_bridge = hapd->iface->num_bss;
  35. params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
  36. if (params.bridge == NULL)
  37. return NULL;
  38. for (i = 0; i < hapd->iface->num_bss; i++) {
  39. struct hostapd_data *bss = hapd->iface->bss[i];
  40. if (bss->conf->bridge[0])
  41. params.bridge[i] = bss->conf->bridge;
  42. }
  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->hapd_set_key == NULL)
  77. return 0;
  78. return hapd->driver->hapd_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, addr, reason);
  140. }
  141. static inline int
  142. hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr, int reason)
  143. {
  144. if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
  145. return 0;
  146. return hapd->driver->sta_disassoc(hapd->drv_priv, addr, reason);
  147. }
  148. static inline int
  149. hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
  150. {
  151. if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
  152. return 0;
  153. return hapd->driver->sta_remove(hapd->drv_priv, addr);
  154. }
  155. static inline int
  156. hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  157. {
  158. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  159. return 0;
  160. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  161. buf, len);
  162. }
  163. static inline int
  164. hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  165. {
  166. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  167. return 0;
  168. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  169. buf, len);
  170. }
  171. static inline int
  172. hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
  173. {
  174. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  175. return 0;
  176. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  177. }
  178. static inline int
  179. hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  180. {
  181. if (hapd->driver == NULL ||
  182. hapd->driver->hapd_set_countermeasures == NULL)
  183. return 0;
  184. return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
  185. }
  186. static inline int
  187. hostapd_sta_add(const char *ifname, struct hostapd_data *hapd, const u8 *addr,
  188. u16 aid, u16 capability, const u8 *supp_rates,
  189. size_t supp_rates_len, int flags, u16 listen_interval,
  190. const struct ht_cap_ie *ht_capabilities)
  191. {
  192. struct hostapd_sta_add_params params;
  193. if (hapd->driver == NULL)
  194. return 0;
  195. if (hapd->driver->sta_add == NULL)
  196. return 0;
  197. os_memset(&params, 0, sizeof(params));
  198. params.addr = addr;
  199. params.aid = aid;
  200. params.capability = capability;
  201. params.supp_rates = supp_rates;
  202. params.supp_rates_len = supp_rates_len;
  203. params.flags = flags;
  204. params.listen_interval = listen_interval;
  205. params.ht_capabilities = ht_capabilities;
  206. return hapd->driver->sta_add(ifname, hapd->drv_priv, &params);
  207. }
  208. static inline int
  209. hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
  210. {
  211. if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
  212. return 0;
  213. return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
  214. }
  215. static inline int
  216. hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq, int channel,
  217. int ht_enabled, int sec_channel_offset)
  218. {
  219. struct hostapd_freq_params data;
  220. if (hapd->driver == NULL)
  221. return 0;
  222. if (hapd->driver->set_freq == NULL)
  223. return 0;
  224. os_memset(&data, 0, sizeof(data));
  225. data.mode = mode;
  226. data.freq = freq;
  227. data.channel = channel;
  228. data.ht_enabled = ht_enabled;
  229. data.sec_channel_offset = sec_channel_offset;
  230. return hapd->driver->set_freq(hapd->drv_priv, &data);
  231. }
  232. static inline int
  233. hostapd_set_rts(struct hostapd_data *hapd, int rts)
  234. {
  235. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  236. return 0;
  237. return hapd->driver->set_rts(hapd->drv_priv, rts);
  238. }
  239. static inline int
  240. hostapd_set_frag(struct hostapd_data *hapd, int frag)
  241. {
  242. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  243. return 0;
  244. return hapd->driver->set_frag(hapd->drv_priv, frag);
  245. }
  246. static inline int
  247. hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
  248. {
  249. if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
  250. return 0;
  251. return hapd->driver->set_retry(hapd->drv_priv, short_retry,
  252. long_retry);
  253. }
  254. static inline int
  255. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  256. int total_flags, int flags_or, int flags_and)
  257. {
  258. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  259. return 0;
  260. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  261. flags_or, flags_and);
  262. }
  263. static inline int
  264. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  265. int *basic_rates, int mode)
  266. {
  267. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  268. return 0;
  269. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  270. basic_rates, mode);
  271. }
  272. static inline int
  273. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  274. {
  275. if (hapd->driver == NULL ||
  276. hapd->driver->set_country == NULL)
  277. return 0;
  278. return hapd->driver->set_country(hapd->drv_priv, country);
  279. }
  280. static inline int
  281. hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
  282. {
  283. if (hapd->driver == NULL ||
  284. hapd->driver->set_ieee80211d == NULL)
  285. return 0;
  286. return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
  287. }
  288. static inline int
  289. hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  290. {
  291. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  292. return 0;
  293. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  294. }
  295. static inline int
  296. hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
  297. const u8 *head, size_t head_len,
  298. const u8 *tail, size_t tail_len, int dtim_period)
  299. {
  300. if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
  301. return 0;
  302. return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
  303. head, head_len,
  304. tail, tail_len, dtim_period);
  305. }
  306. static inline int
  307. hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
  308. {
  309. if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
  310. return 0;
  311. return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
  312. }
  313. static inline int
  314. hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
  315. {
  316. if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
  317. return 0;
  318. return hapd->driver->set_beacon_int(hapd->drv_priv, value);
  319. }
  320. static inline int
  321. hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
  322. {
  323. if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
  324. return 0;
  325. return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
  326. }
  327. static inline int
  328. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  329. {
  330. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  331. return 0;
  332. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  333. }
  334. static inline int
  335. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  336. {
  337. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  338. return 0;
  339. return hapd->driver->set_preamble(hapd->drv_priv, value);
  340. }
  341. static inline int
  342. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  343. {
  344. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  345. return 0;
  346. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  347. }
  348. static inline int
  349. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  350. int cw_min, int cw_max, int burst_time)
  351. {
  352. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  353. return 0;
  354. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  355. cw_min, cw_max, burst_time);
  356. }
  357. static inline int
  358. hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
  359. {
  360. if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
  361. return 0;
  362. return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
  363. }
  364. static inline int
  365. hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
  366. {
  367. if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
  368. return 0;
  369. return hapd->driver->bss_remove(hapd->drv_priv, ifname);
  370. }
  371. static inline int
  372. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  373. const u8 *mask)
  374. {
  375. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  376. return 1;
  377. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  378. }
  379. static inline int
  380. hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  381. char *ifname, const u8 *addr)
  382. {
  383. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  384. return -1;
  385. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  386. ifname, addr);
  387. }
  388. static inline int
  389. hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  390. char *ifname, const u8 *addr)
  391. {
  392. if (hapd->driver == NULL || hapd->driver->if_update == NULL)
  393. return -1;
  394. return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
  395. }
  396. static inline int
  397. hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  398. char *ifname, const u8 *addr)
  399. {
  400. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  401. return -1;
  402. return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
  403. }
  404. static inline int
  405. hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
  406. int interval, int _listen, int *channel,
  407. int *last_rx)
  408. {
  409. if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
  410. return -1;
  411. return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
  412. interval, _listen, channel, last_rx);
  413. }
  414. static inline struct hostapd_hw_modes *
  415. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  416. u16 *flags)
  417. {
  418. if (hapd->driver == NULL ||
  419. hapd->driver->get_hw_feature_data == NULL)
  420. return NULL;
  421. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  422. flags);
  423. }
  424. static inline int
  425. hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  426. const u8 *addr, int vlan_id)
  427. {
  428. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  429. return 0;
  430. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
  431. }
  432. static inline int
  433. hostapd_driver_commit(struct hostapd_data *hapd)
  434. {
  435. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  436. return 0;
  437. return hapd->driver->commit(hapd->drv_priv);
  438. }
  439. static inline int
  440. hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
  441. int accepted, u32 session_timeout)
  442. {
  443. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  444. return 0;
  445. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  446. session_timeout);
  447. }
  448. static inline int
  449. hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
  450. {
  451. if (hapd->driver == NULL ||
  452. hapd->driver->set_radius_acl_expire == NULL)
  453. return 0;
  454. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  455. }
  456. #ifdef CONFIG_IEEE80211N
  457. static inline int
  458. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  459. const u8 *ht_capab, size_t ht_capab_len,
  460. const u8 *ht_oper, size_t ht_oper_len)
  461. {
  462. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  463. ht_capab == NULL || ht_oper == NULL)
  464. return 0;
  465. return hapd->driver->set_ht_params(
  466. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  467. ht_oper, ht_oper_len);
  468. }
  469. #endif /* CONFIG_IEEE80211N */
  470. static inline int
  471. hostapd_drv_none(struct hostapd_data *hapd)
  472. {
  473. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  474. }
  475. static inline int
  476. hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
  477. {
  478. if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
  479. return 0;
  480. return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
  481. hapd->drv_priv, ie, len);
  482. }
  483. static inline int
  484. hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
  485. size_t len)
  486. {
  487. if (hapd->driver == NULL ||
  488. hapd->driver->set_wps_probe_resp_ie == NULL)
  489. return 0;
  490. return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
  491. hapd->drv_priv, ie, len);
  492. }
  493. static inline int hostapd_driver_set_mode(struct hostapd_data *hapd, int mode)
  494. {
  495. if (hapd->driver == NULL || hapd->driver->set_mode == NULL)
  496. return 0;
  497. return hapd->driver->set_mode(hapd->drv_priv, mode);
  498. }
  499. static inline int hostapd_driver_scan(struct hostapd_data *hapd,
  500. struct wpa_driver_scan_params *params)
  501. {
  502. if (hapd->driver && hapd->driver->scan2)
  503. return hapd->driver->scan2(hapd->drv_priv, params);
  504. return -1;
  505. }
  506. static inline struct wpa_scan_results * hostapd_driver_get_scan_results(
  507. struct hostapd_data *hapd)
  508. {
  509. if (hapd->driver && hapd->driver->get_scan_results2)
  510. return hapd->driver->get_scan_results2(hapd->drv_priv);
  511. return NULL;
  512. }
  513. #endif /* DRIVER_I_H */