driver_i.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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.ht_40mhz_scan = hapd->iconf->secondary_channel != 0;
  35. params.num_bridge = hapd->iface->num_bss;
  36. params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
  37. if (params.bridge == NULL)
  38. return NULL;
  39. for (i = 0; i < hapd->iface->num_bss; i++) {
  40. struct hostapd_data *bss = hapd->iface->bss[i];
  41. if (bss->conf->bridge[0])
  42. params.bridge[i] = bss->conf->bridge;
  43. }
  44. ret = hapd->driver->hapd_init(hapd, &params);
  45. os_free(params.bridge);
  46. return ret;
  47. }
  48. static inline void
  49. hostapd_driver_deinit(struct hostapd_data *hapd)
  50. {
  51. if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
  52. return;
  53. hapd->driver->hapd_deinit(hapd->drv_priv);
  54. }
  55. static inline int
  56. hostapd_set_ieee8021x(const char *ifname, struct hostapd_data *hapd,
  57. int enabled)
  58. {
  59. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  60. return 0;
  61. return hapd->driver->set_ieee8021x(ifname, hapd->drv_priv, enabled);
  62. }
  63. static inline int
  64. hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  65. {
  66. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  67. return 0;
  68. return hapd->driver->set_privacy(hapd->conf->iface, hapd->drv_priv,
  69. enabled);
  70. }
  71. static inline int
  72. hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  73. wpa_alg alg, const u8 *addr, int key_idx,
  74. int set_tx, const u8 *seq, size_t seq_len,
  75. const u8 *key, size_t key_len)
  76. {
  77. if (hapd->driver == NULL || hapd->driver->hapd_set_key == NULL)
  78. return 0;
  79. return hapd->driver->hapd_set_key(ifname, hapd->drv_priv, alg, addr,
  80. key_idx, set_tx, seq, seq_len, key,
  81. key_len);
  82. }
  83. static inline int
  84. hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  85. const u8 *addr, int idx, u8 *seq)
  86. {
  87. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  88. return 0;
  89. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  90. seq);
  91. }
  92. static inline int
  93. hostapd_get_seqnum_igtk(const char *ifname, struct hostapd_data *hapd,
  94. const u8 *addr, int idx, u8 *seq)
  95. {
  96. if (hapd->driver == NULL || hapd->driver->get_seqnum_igtk == NULL)
  97. return -1;
  98. return hapd->driver->get_seqnum_igtk(ifname, hapd->drv_priv, addr, idx,
  99. seq);
  100. }
  101. static inline int
  102. hostapd_flush(struct hostapd_data *hapd)
  103. {
  104. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  105. return 0;
  106. return hapd->driver->flush(hapd->drv_priv);
  107. }
  108. static inline int
  109. hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  110. size_t elem_len)
  111. {
  112. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  113. return 0;
  114. return hapd->driver->set_generic_elem(hapd->conf->iface,
  115. hapd->drv_priv, elem, elem_len);
  116. }
  117. static inline int
  118. hostapd_read_sta_data(struct hostapd_data *hapd,
  119. struct hostap_sta_driver_data *data, const u8 *addr)
  120. {
  121. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  122. return -1;
  123. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  124. }
  125. static inline int
  126. hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
  127. size_t data_len, int encrypt)
  128. {
  129. if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
  130. return 0;
  131. return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
  132. data_len, encrypt,
  133. 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->hapd_get_ssid == NULL)
  160. return 0;
  161. return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
  162. buf, 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->hapd_set_ssid == NULL)
  168. return 0;
  169. return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
  170. buf, len);
  171. }
  172. static inline int
  173. hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len)
  174. {
  175. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  176. return 0;
  177. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  178. }
  179. static inline int
  180. hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  181. {
  182. if (hapd->driver == NULL ||
  183. hapd->driver->hapd_set_countermeasures == NULL)
  184. return 0;
  185. return hapd->driver->hapd_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_set_frag(struct hostapd_data *hapd, int frag)
  242. {
  243. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  244. return 0;
  245. return hapd->driver->set_frag(hapd->drv_priv, frag);
  246. }
  247. static inline int
  248. hostapd_set_retry(struct hostapd_data *hapd, int short_retry, int long_retry)
  249. {
  250. if (hapd->driver == NULL || hapd->driver->set_retry == NULL)
  251. return 0;
  252. return hapd->driver->set_retry(hapd->drv_priv, short_retry,
  253. long_retry);
  254. }
  255. static inline int
  256. hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  257. int total_flags, int flags_or, int flags_and)
  258. {
  259. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  260. return 0;
  261. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  262. flags_or, flags_and);
  263. }
  264. static inline int
  265. hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  266. int *basic_rates, int mode)
  267. {
  268. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  269. return 0;
  270. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  271. basic_rates, mode);
  272. }
  273. static inline int
  274. hostapd_set_country(struct hostapd_data *hapd, const char *country)
  275. {
  276. if (hapd->driver == NULL ||
  277. hapd->driver->set_country == NULL)
  278. return 0;
  279. return hapd->driver->set_country(hapd->drv_priv, country);
  280. }
  281. static inline int
  282. hostapd_set_ieee80211d(struct hostapd_data *hapd, int enabled)
  283. {
  284. if (hapd->driver == NULL ||
  285. hapd->driver->set_ieee80211d == NULL)
  286. return 0;
  287. return hapd->driver->set_ieee80211d(hapd->drv_priv, enabled);
  288. }
  289. static inline int
  290. hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  291. {
  292. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  293. return 0;
  294. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  295. }
  296. static inline int
  297. hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
  298. const u8 *head, size_t head_len,
  299. const u8 *tail, size_t tail_len, int dtim_period)
  300. {
  301. if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
  302. return 0;
  303. return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
  304. head, head_len,
  305. tail, tail_len, dtim_period);
  306. }
  307. static inline int
  308. hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
  309. {
  310. if (hapd->driver == NULL || hapd->driver->set_internal_bridge == NULL)
  311. return 0;
  312. return hapd->driver->set_internal_bridge(hapd->drv_priv, value);
  313. }
  314. static inline int
  315. hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
  316. {
  317. if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
  318. return 0;
  319. return hapd->driver->set_beacon_int(hapd->drv_priv, value);
  320. }
  321. static inline int
  322. hostapd_set_broadcast_ssid(struct hostapd_data *hapd, int value)
  323. {
  324. if (hapd->driver == NULL || hapd->driver->set_broadcast_ssid == NULL)
  325. return 0;
  326. return hapd->driver->set_broadcast_ssid(hapd->drv_priv, value);
  327. }
  328. static inline int
  329. hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  330. {
  331. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  332. return 0;
  333. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  334. }
  335. static inline int
  336. hostapd_set_preamble(struct hostapd_data *hapd, int value)
  337. {
  338. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  339. return 0;
  340. return hapd->driver->set_preamble(hapd->drv_priv, value);
  341. }
  342. static inline int
  343. hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  344. {
  345. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  346. return 0;
  347. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  348. }
  349. static inline int
  350. hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  351. int cw_min, int cw_max, int burst_time)
  352. {
  353. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  354. return 0;
  355. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  356. cw_min, cw_max, burst_time);
  357. }
  358. static inline int
  359. hostapd_bss_add(struct hostapd_data *hapd, const char *ifname, const u8 *bssid)
  360. {
  361. if (hapd->driver == NULL || hapd->driver->bss_add == NULL)
  362. return 0;
  363. return hapd->driver->bss_add(hapd->drv_priv, ifname, bssid);
  364. }
  365. static inline int
  366. hostapd_bss_remove(struct hostapd_data *hapd, const char *ifname)
  367. {
  368. if (hapd->driver == NULL || hapd->driver->bss_remove == NULL)
  369. return 0;
  370. return hapd->driver->bss_remove(hapd->drv_priv, ifname);
  371. }
  372. static inline int
  373. hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  374. const u8 *mask)
  375. {
  376. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  377. return 1;
  378. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  379. }
  380. static inline int
  381. hostapd_if_add(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  382. char *ifname, const u8 *addr)
  383. {
  384. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  385. return -1;
  386. return hapd->driver->if_add(hapd->conf->iface, hapd->drv_priv, type,
  387. ifname, addr);
  388. }
  389. static inline int
  390. hostapd_if_update(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  391. char *ifname, const u8 *addr)
  392. {
  393. if (hapd->driver == NULL || hapd->driver->if_update == NULL)
  394. return -1;
  395. return hapd->driver->if_update(hapd->drv_priv, type, ifname, addr);
  396. }
  397. static inline int
  398. hostapd_if_remove(struct hostapd_data *hapd, enum hostapd_driver_if_type type,
  399. char *ifname, const u8 *addr)
  400. {
  401. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  402. return -1;
  403. return hapd->driver->if_remove(hapd->drv_priv, type, ifname, addr);
  404. }
  405. static inline int
  406. hostapd_passive_scan(struct hostapd_data *hapd, int now, int our_mode_only,
  407. int interval, int _listen, int *channel,
  408. int *last_rx)
  409. {
  410. if (hapd->driver == NULL || hapd->driver->passive_scan == NULL)
  411. return -1;
  412. return hapd->driver->passive_scan(hapd->drv_priv, now, our_mode_only,
  413. interval, _listen, channel, last_rx);
  414. }
  415. static inline struct hostapd_hw_modes *
  416. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  417. u16 *flags)
  418. {
  419. if (hapd->driver == NULL ||
  420. hapd->driver->get_hw_feature_data == NULL)
  421. return NULL;
  422. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  423. flags);
  424. }
  425. static inline int
  426. hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  427. const u8 *addr, int vlan_id)
  428. {
  429. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  430. return 0;
  431. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname, vlan_id);
  432. }
  433. static inline int
  434. hostapd_driver_commit(struct hostapd_data *hapd)
  435. {
  436. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  437. return 0;
  438. return hapd->driver->commit(hapd->drv_priv);
  439. }
  440. static inline int
  441. hostapd_set_radius_acl_auth(struct hostapd_data *hapd, const u8 *mac,
  442. int accepted, u32 session_timeout)
  443. {
  444. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  445. return 0;
  446. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  447. session_timeout);
  448. }
  449. static inline int
  450. hostapd_set_radius_acl_expire(struct hostapd_data *hapd, const u8 *mac)
  451. {
  452. if (hapd->driver == NULL ||
  453. hapd->driver->set_radius_acl_expire == NULL)
  454. return 0;
  455. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  456. }
  457. #ifdef CONFIG_IEEE80211N
  458. static inline int
  459. hostapd_set_ht_params(const char *ifname, struct hostapd_data *hapd,
  460. const u8 *ht_capab, size_t ht_capab_len,
  461. const u8 *ht_oper, size_t ht_oper_len)
  462. {
  463. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  464. ht_capab == NULL || ht_oper == NULL)
  465. return 0;
  466. return hapd->driver->set_ht_params(
  467. ifname, hapd->drv_priv, ht_capab, ht_capab_len,
  468. ht_oper, ht_oper_len);
  469. }
  470. #endif /* CONFIG_IEEE80211N */
  471. static inline int
  472. hostapd_drv_none(struct hostapd_data *hapd)
  473. {
  474. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  475. }
  476. static inline int
  477. hostapd_set_wps_beacon_ie(struct hostapd_data *hapd, const u8 *ie, size_t len)
  478. {
  479. if (hapd->driver == NULL || hapd->driver->set_wps_beacon_ie == NULL)
  480. return 0;
  481. return hapd->driver->set_wps_beacon_ie(hapd->conf->iface,
  482. hapd->drv_priv, ie, len);
  483. }
  484. static inline int
  485. hostapd_set_wps_probe_resp_ie(struct hostapd_data *hapd, const u8 *ie,
  486. size_t len)
  487. {
  488. if (hapd->driver == NULL ||
  489. hapd->driver->set_wps_probe_resp_ie == NULL)
  490. return 0;
  491. return hapd->driver->set_wps_probe_resp_ie(hapd->conf->iface,
  492. hapd->drv_priv, ie, len);
  493. }
  494. static inline const struct hostapd_neighbor_bss *
  495. hostapd_driver_get_neighbor_bss(struct hostapd_data *hapd, size_t *num)
  496. {
  497. if (hapd->driver == NULL || hapd->driver->get_neighbor_bss == NULL)
  498. return NULL;
  499. return hapd->driver->get_neighbor_bss(hapd->drv_priv, num);
  500. }
  501. #endif /* DRIVER_I_H */