ap_drv_ops.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * hostapd - Driver operations
  3. * Copyright (c) 2009-2010, 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. #include "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "drivers/driver.h"
  17. #include "common/ieee802_11_defs.h"
  18. #include "wps/wps.h"
  19. #include "hostapd.h"
  20. #include "ieee802_11.h"
  21. #include "sta_info.h"
  22. #include "ap_config.h"
  23. #include "p2p_hostapd.h"
  24. #include "ap_drv_ops.h"
  25. static int hostapd_sta_flags_to_drv(int flags)
  26. {
  27. int res = 0;
  28. if (flags & WLAN_STA_AUTHORIZED)
  29. res |= WPA_STA_AUTHORIZED;
  30. if (flags & WLAN_STA_WMM)
  31. res |= WPA_STA_WMM;
  32. if (flags & WLAN_STA_SHORT_PREAMBLE)
  33. res |= WPA_STA_SHORT_PREAMBLE;
  34. if (flags & WLAN_STA_MFP)
  35. res |= WPA_STA_MFP;
  36. return res;
  37. }
  38. static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
  39. {
  40. struct wpabuf *beacon, *proberesp, *assocresp = NULL;
  41. int ret;
  42. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  43. return 0;
  44. beacon = hapd->wps_beacon_ie;
  45. proberesp = hapd->wps_probe_resp_ie;
  46. #ifdef CONFIG_P2P
  47. if (hapd->wps_beacon_ie == NULL && hapd->p2p_beacon_ie == NULL)
  48. beacon = NULL;
  49. else {
  50. beacon = wpabuf_alloc((hapd->wps_beacon_ie ?
  51. wpabuf_len(hapd->wps_beacon_ie) : 0) +
  52. (hapd->p2p_beacon_ie ?
  53. wpabuf_len(hapd->p2p_beacon_ie) : 0));
  54. if (beacon == NULL)
  55. return -1;
  56. if (hapd->wps_beacon_ie)
  57. wpabuf_put_buf(beacon, hapd->wps_beacon_ie);
  58. if (hapd->p2p_beacon_ie)
  59. wpabuf_put_buf(beacon, hapd->p2p_beacon_ie);
  60. }
  61. if (hapd->wps_probe_resp_ie == NULL && hapd->p2p_probe_resp_ie == NULL)
  62. proberesp = NULL;
  63. else {
  64. proberesp = wpabuf_alloc(
  65. (hapd->wps_probe_resp_ie ?
  66. wpabuf_len(hapd->wps_probe_resp_ie) : 0) +
  67. (hapd->p2p_probe_resp_ie ?
  68. wpabuf_len(hapd->p2p_probe_resp_ie) : 0));
  69. if (proberesp == NULL) {
  70. wpabuf_free(beacon);
  71. return -1;
  72. }
  73. if (hapd->wps_probe_resp_ie)
  74. wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie);
  75. if (hapd->p2p_probe_resp_ie)
  76. wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie);
  77. }
  78. #endif /* CONFIG_P2P */
  79. #ifdef CONFIG_P2P_MANAGER
  80. if (hapd->conf->p2p & P2P_MANAGE) {
  81. struct wpabuf *a;
  82. a = wpabuf_alloc(100 + (beacon ? wpabuf_len(beacon) : 0));
  83. if (a) {
  84. u8 *start, *p;
  85. if (beacon)
  86. wpabuf_put_buf(a, beacon);
  87. if (beacon != hapd->wps_beacon_ie)
  88. wpabuf_free(beacon);
  89. start = wpabuf_put(a, 0);
  90. p = hostapd_eid_p2p_manage(hapd, start);
  91. wpabuf_put(a, p - start);
  92. beacon = a;
  93. }
  94. a = wpabuf_alloc(100 + (proberesp ? wpabuf_len(proberesp) :
  95. 0));
  96. if (a) {
  97. u8 *start, *p;
  98. if (proberesp)
  99. wpabuf_put_buf(a, proberesp);
  100. if (proberesp != hapd->wps_probe_resp_ie)
  101. wpabuf_free(proberesp);
  102. start = wpabuf_put(a, 0);
  103. p = hostapd_eid_p2p_manage(hapd, start);
  104. wpabuf_put(a, p - start);
  105. proberesp = a;
  106. }
  107. }
  108. #endif /* CONFIG_P2P_MANAGER */
  109. #ifdef CONFIG_WPS2
  110. if (hapd->conf->wps_state)
  111. assocresp = wps_build_assoc_resp_ie();
  112. #endif /* CONFIG_WPS2 */
  113. #ifdef CONFIG_P2P_MANAGER
  114. if (hapd->conf->p2p & P2P_MANAGE) {
  115. struct wpabuf *a;
  116. a = wpabuf_alloc(100 + (assocresp ? wpabuf_len(assocresp) :
  117. 0));
  118. if (a) {
  119. u8 *start, *p;
  120. start = wpabuf_put(a, 0);
  121. p = hostapd_eid_p2p_manage(hapd, start);
  122. wpabuf_put(a, p - start);
  123. if (assocresp) {
  124. wpabuf_put_buf(a, assocresp);
  125. wpabuf_free(assocresp);
  126. }
  127. assocresp = a;
  128. }
  129. }
  130. #endif /* CONFIG_P2P_MANAGER */
  131. ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
  132. assocresp);
  133. if (beacon != hapd->wps_beacon_ie)
  134. wpabuf_free(beacon);
  135. if (proberesp != hapd->wps_probe_resp_ie)
  136. wpabuf_free(proberesp);
  137. wpabuf_free(assocresp);
  138. return ret;
  139. }
  140. static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
  141. size_t len)
  142. {
  143. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  144. return 0;
  145. return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
  146. }
  147. static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
  148. const u8 *data, size_t data_len, int encrypt)
  149. {
  150. if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
  151. return 0;
  152. return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
  153. data_len, encrypt,
  154. hapd->own_addr);
  155. }
  156. static int hostapd_set_authorized(struct hostapd_data *hapd,
  157. struct sta_info *sta, int authorized)
  158. {
  159. if (authorized) {
  160. return hostapd_sta_set_flags(hapd, sta->addr,
  161. hostapd_sta_flags_to_drv(
  162. sta->flags),
  163. WPA_STA_AUTHORIZED, ~0);
  164. }
  165. return hostapd_sta_set_flags(hapd, sta->addr,
  166. hostapd_sta_flags_to_drv(sta->flags),
  167. 0, ~WPA_STA_AUTHORIZED);
  168. }
  169. static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
  170. enum wpa_alg alg, const u8 *addr, int key_idx,
  171. int set_tx, const u8 *seq, size_t seq_len,
  172. const u8 *key, size_t key_len)
  173. {
  174. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  175. return 0;
  176. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  177. key_idx, set_tx, seq, seq_len, key,
  178. key_len);
  179. }
  180. static int hostapd_read_sta_data(struct hostapd_data *hapd,
  181. struct hostap_sta_driver_data *data,
  182. const u8 *addr)
  183. {
  184. if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
  185. return -1;
  186. return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
  187. }
  188. static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
  189. {
  190. if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
  191. return 0;
  192. return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
  193. }
  194. static int hostapd_set_sta_flags(struct hostapd_data *hapd,
  195. struct sta_info *sta)
  196. {
  197. int set_flags, total_flags, flags_and, flags_or;
  198. total_flags = hostapd_sta_flags_to_drv(sta->flags);
  199. set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
  200. if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
  201. sta->auth_alg == WLAN_AUTH_FT) &&
  202. sta->flags & WLAN_STA_AUTHORIZED)
  203. set_flags |= WPA_STA_AUTHORIZED;
  204. flags_or = total_flags & set_flags;
  205. flags_and = total_flags | ~set_flags;
  206. return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
  207. flags_or, flags_and);
  208. }
  209. static int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd,
  210. const char *ifname, int enabled)
  211. {
  212. struct wpa_bss_params params;
  213. os_memset(&params, 0, sizeof(params));
  214. params.ifname = ifname;
  215. params.enabled = enabled;
  216. if (enabled) {
  217. params.wpa = hapd->conf->wpa;
  218. params.ieee802_1x = hapd->conf->ieee802_1x;
  219. params.wpa_group = hapd->conf->wpa_group;
  220. params.wpa_pairwise = hapd->conf->wpa_pairwise;
  221. params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
  222. params.rsn_preauth = hapd->conf->rsn_preauth;
  223. }
  224. return hostapd_set_ieee8021x(hapd, &params);
  225. }
  226. static int hostapd_set_radius_acl_auth(struct hostapd_data *hapd,
  227. const u8 *mac, int accepted,
  228. u32 session_timeout)
  229. {
  230. if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
  231. return 0;
  232. return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
  233. session_timeout);
  234. }
  235. static int hostapd_set_radius_acl_expire(struct hostapd_data *hapd,
  236. const u8 *mac)
  237. {
  238. if (hapd->driver == NULL ||
  239. hapd->driver->set_radius_acl_expire == NULL)
  240. return 0;
  241. return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
  242. }
  243. static int hostapd_set_ap_isolate(struct hostapd_data *hapd, int value)
  244. {
  245. if (hapd->driver == NULL || hapd->driver->set_intra_bss == NULL)
  246. return 0;
  247. return hapd->driver->set_intra_bss(hapd->drv_priv, !value);
  248. }
  249. static int hostapd_set_bss_params(struct hostapd_data *hapd,
  250. int use_protection)
  251. {
  252. int ret = 0;
  253. int preamble;
  254. #ifdef CONFIG_IEEE80211N
  255. u8 buf[60], *ht_capab, *ht_oper, *pos;
  256. pos = buf;
  257. ht_capab = pos;
  258. pos = hostapd_eid_ht_capabilities(hapd, pos);
  259. ht_oper = pos;
  260. pos = hostapd_eid_ht_operation(hapd, pos);
  261. if (pos > ht_oper && ht_oper > ht_capab &&
  262. hostapd_set_ht_params(hapd, ht_capab + 2, ht_capab[1],
  263. ht_oper + 2, ht_oper[1])) {
  264. wpa_printf(MSG_ERROR, "Could not set HT capabilities "
  265. "for kernel driver");
  266. ret = -1;
  267. }
  268. #endif /* CONFIG_IEEE80211N */
  269. if (hostapd_set_cts_protect(hapd, use_protection)) {
  270. wpa_printf(MSG_ERROR, "Failed to set CTS protect in kernel "
  271. "driver");
  272. ret = -1;
  273. }
  274. if (hapd->iface->current_mode &&
  275. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
  276. hostapd_set_short_slot_time(hapd,
  277. hapd->iface->num_sta_no_short_slot_time
  278. > 0 ? 0 : 1)) {
  279. wpa_printf(MSG_ERROR, "Failed to set Short Slot Time option "
  280. "in kernel driver");
  281. ret = -1;
  282. }
  283. if (hapd->iface->num_sta_no_short_preamble == 0 &&
  284. hapd->iconf->preamble == SHORT_PREAMBLE)
  285. preamble = SHORT_PREAMBLE;
  286. else
  287. preamble = LONG_PREAMBLE;
  288. if (hostapd_set_preamble(hapd, preamble)) {
  289. wpa_printf(MSG_ERROR, "Could not set preamble for kernel "
  290. "driver");
  291. ret = -1;
  292. }
  293. if (hostapd_set_ap_isolate(hapd, hapd->conf->isolate) &&
  294. hapd->conf->isolate) {
  295. wpa_printf(MSG_ERROR, "Could not enable AP isolation in "
  296. "kernel driver");
  297. ret = -1;
  298. }
  299. return ret;
  300. }
  301. static int hostapd_set_beacon(struct hostapd_data *hapd,
  302. const u8 *head, size_t head_len,
  303. const u8 *tail, size_t tail_len, int dtim_period,
  304. int beacon_int)
  305. {
  306. if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
  307. return 0;
  308. return hapd->driver->set_beacon(hapd->drv_priv,
  309. head, head_len, tail, tail_len,
  310. dtim_period, beacon_int);
  311. }
  312. static int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
  313. {
  314. char force_ifname[IFNAMSIZ];
  315. u8 if_addr[ETH_ALEN];
  316. return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, NULL, NULL, NULL,
  317. force_ifname, if_addr);
  318. }
  319. static int hostapd_vlan_if_remove(struct hostapd_data *hapd,
  320. const char *ifname)
  321. {
  322. return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
  323. }
  324. static int hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr,
  325. int aid, int val)
  326. {
  327. const char *bridge = NULL;
  328. if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
  329. return 0;
  330. if (hapd->conf->wds_bridge[0])
  331. bridge = hapd->conf->wds_bridge;
  332. else if (hapd->conf->bridge[0])
  333. bridge = hapd->conf->bridge;
  334. return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val, bridge);
  335. }
  336. static int hostapd_set_sta_vlan(const char *ifname, struct hostapd_data *hapd,
  337. const u8 *addr, int vlan_id)
  338. {
  339. if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
  340. return 0;
  341. return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname,
  342. vlan_id);
  343. }
  344. static int hostapd_get_inact_sec(struct hostapd_data *hapd, const u8 *addr)
  345. {
  346. if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
  347. return 0;
  348. return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
  349. }
  350. static int hostapd_sta_deauth(struct hostapd_data *hapd, const u8 *addr,
  351. int reason)
  352. {
  353. if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
  354. return 0;
  355. return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
  356. reason);
  357. }
  358. static int hostapd_sta_disassoc(struct hostapd_data *hapd, const u8 *addr,
  359. int reason)
  360. {
  361. if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
  362. return 0;
  363. return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
  364. reason);
  365. }
  366. static int hostapd_sta_add(struct hostapd_data *hapd,
  367. const u8 *addr, u16 aid, u16 capability,
  368. const u8 *supp_rates, size_t supp_rates_len,
  369. u16 listen_interval,
  370. const struct ieee80211_ht_capabilities *ht_capab)
  371. {
  372. struct hostapd_sta_add_params params;
  373. if (hapd->driver == NULL)
  374. return 0;
  375. if (hapd->driver->sta_add == NULL)
  376. return 0;
  377. os_memset(&params, 0, sizeof(params));
  378. params.addr = addr;
  379. params.aid = aid;
  380. params.capability = capability;
  381. params.supp_rates = supp_rates;
  382. params.supp_rates_len = supp_rates_len;
  383. params.listen_interval = listen_interval;
  384. params.ht_capabilities = ht_capab;
  385. return hapd->driver->sta_add(hapd->drv_priv, &params);
  386. }
  387. static int hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
  388. {
  389. if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
  390. return 0;
  391. return hapd->driver->sta_remove(hapd->drv_priv, addr);
  392. }
  393. static int hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
  394. {
  395. if (hapd->driver == NULL ||
  396. hapd->driver->hapd_set_countermeasures == NULL)
  397. return 0;
  398. return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
  399. }
  400. void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
  401. {
  402. ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
  403. ops->send_mgmt_frame = hostapd_send_mgmt_frame;
  404. ops->send_eapol = hostapd_send_eapol;
  405. ops->set_authorized = hostapd_set_authorized;
  406. ops->set_key = hostapd_set_key;
  407. ops->read_sta_data = hostapd_read_sta_data;
  408. ops->sta_clear_stats = hostapd_sta_clear_stats;
  409. ops->set_sta_flags = hostapd_set_sta_flags;
  410. ops->set_drv_ieee8021x = hostapd_set_drv_ieee8021x;
  411. ops->set_radius_acl_auth = hostapd_set_radius_acl_auth;
  412. ops->set_radius_acl_expire = hostapd_set_radius_acl_expire;
  413. ops->set_bss_params = hostapd_set_bss_params;
  414. ops->set_beacon = hostapd_set_beacon;
  415. ops->vlan_if_add = hostapd_vlan_if_add;
  416. ops->vlan_if_remove = hostapd_vlan_if_remove;
  417. ops->set_wds_sta = hostapd_set_wds_sta;
  418. ops->set_sta_vlan = hostapd_set_sta_vlan;
  419. ops->get_inact_sec = hostapd_get_inact_sec;
  420. ops->sta_deauth = hostapd_sta_deauth;
  421. ops->sta_disassoc = hostapd_sta_disassoc;
  422. ops->sta_add = hostapd_sta_add;
  423. ops->sta_remove = hostapd_sta_remove;
  424. ops->set_countermeasures = hostapd_set_countermeasures;
  425. }
  426. int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  427. {
  428. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  429. return 0;
  430. return hapd->driver->set_privacy(hapd->drv_priv, enabled);
  431. }
  432. int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  433. size_t elem_len)
  434. {
  435. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  436. return 0;
  437. return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
  438. }
  439. int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  440. {
  441. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  442. return 0;
  443. return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
  444. }
  445. int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  446. {
  447. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  448. return 0;
  449. return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
  450. }
  451. int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  452. const char *ifname, const u8 *addr, void *bss_ctx,
  453. void **drv_priv, char *force_ifname, u8 *if_addr)
  454. {
  455. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  456. return -1;
  457. return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
  458. bss_ctx, drv_priv, force_ifname, if_addr);
  459. }
  460. int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  461. const char *ifname)
  462. {
  463. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  464. return -1;
  465. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  466. }
  467. int hostapd_set_ieee8021x(struct hostapd_data *hapd,
  468. struct wpa_bss_params *params)
  469. {
  470. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  471. return 0;
  472. return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
  473. }
  474. int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  475. const u8 *addr, int idx, u8 *seq)
  476. {
  477. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  478. return 0;
  479. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  480. seq);
  481. }
  482. int hostapd_flush(struct hostapd_data *hapd)
  483. {
  484. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  485. return 0;
  486. return hapd->driver->flush(hapd->drv_priv);
  487. }
  488. int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
  489. int channel, int ht_enabled, int sec_channel_offset)
  490. {
  491. struct hostapd_freq_params data;
  492. if (hapd->driver == NULL)
  493. return 0;
  494. if (hapd->driver->set_freq == NULL)
  495. return 0;
  496. os_memset(&data, 0, sizeof(data));
  497. data.mode = mode;
  498. data.freq = freq;
  499. data.channel = channel;
  500. data.ht_enabled = ht_enabled;
  501. data.sec_channel_offset = sec_channel_offset;
  502. return hapd->driver->set_freq(hapd->drv_priv, &data);
  503. }
  504. int hostapd_set_rts(struct hostapd_data *hapd, int rts)
  505. {
  506. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  507. return 0;
  508. return hapd->driver->set_rts(hapd->drv_priv, rts);
  509. }
  510. int hostapd_set_frag(struct hostapd_data *hapd, int frag)
  511. {
  512. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  513. return 0;
  514. return hapd->driver->set_frag(hapd->drv_priv, frag);
  515. }
  516. int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  517. int total_flags, int flags_or, int flags_and)
  518. {
  519. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  520. return 0;
  521. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  522. flags_or, flags_and);
  523. }
  524. int hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
  525. int *basic_rates, int mode)
  526. {
  527. if (hapd->driver == NULL || hapd->driver->set_rate_sets == NULL)
  528. return 0;
  529. return hapd->driver->set_rate_sets(hapd->drv_priv, supp_rates,
  530. basic_rates, mode);
  531. }
  532. int hostapd_set_country(struct hostapd_data *hapd, const char *country)
  533. {
  534. if (hapd->driver == NULL ||
  535. hapd->driver->set_country == NULL)
  536. return 0;
  537. return hapd->driver->set_country(hapd->drv_priv, country);
  538. }
  539. int hostapd_set_cts_protect(struct hostapd_data *hapd, int value)
  540. {
  541. if (hapd->driver == NULL || hapd->driver->set_cts_protect == NULL)
  542. return 0;
  543. return hapd->driver->set_cts_protect(hapd->drv_priv, value);
  544. }
  545. int hostapd_set_preamble(struct hostapd_data *hapd, int value)
  546. {
  547. if (hapd->driver == NULL || hapd->driver->set_preamble == NULL)
  548. return 0;
  549. return hapd->driver->set_preamble(hapd->drv_priv, value);
  550. }
  551. int hostapd_set_short_slot_time(struct hostapd_data *hapd, int value)
  552. {
  553. if (hapd->driver == NULL || hapd->driver->set_short_slot_time == NULL)
  554. return 0;
  555. return hapd->driver->set_short_slot_time(hapd->drv_priv, value);
  556. }
  557. int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  558. int cw_min, int cw_max, int burst_time)
  559. {
  560. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  561. return 0;
  562. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  563. cw_min, cw_max, burst_time);
  564. }
  565. int hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
  566. const u8 *mask)
  567. {
  568. if (hapd->driver == NULL || hapd->driver->valid_bss_mask == NULL)
  569. return 1;
  570. return hapd->driver->valid_bss_mask(hapd->drv_priv, addr, mask);
  571. }
  572. struct hostapd_hw_modes *
  573. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  574. u16 *flags)
  575. {
  576. if (hapd->driver == NULL ||
  577. hapd->driver->get_hw_feature_data == NULL)
  578. return NULL;
  579. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  580. flags);
  581. }
  582. int hostapd_driver_commit(struct hostapd_data *hapd)
  583. {
  584. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  585. return 0;
  586. return hapd->driver->commit(hapd->drv_priv);
  587. }
  588. int hostapd_set_ht_params(struct hostapd_data *hapd,
  589. const u8 *ht_capab, size_t ht_capab_len,
  590. const u8 *ht_oper, size_t ht_oper_len)
  591. {
  592. if (hapd->driver == NULL || hapd->driver->set_ht_params == NULL ||
  593. ht_capab == NULL || ht_oper == NULL)
  594. return 0;
  595. return hapd->driver->set_ht_params(hapd->drv_priv,
  596. ht_capab, ht_capab_len,
  597. ht_oper, ht_oper_len);
  598. }
  599. int hostapd_drv_none(struct hostapd_data *hapd)
  600. {
  601. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  602. }
  603. int hostapd_driver_scan(struct hostapd_data *hapd,
  604. struct wpa_driver_scan_params *params)
  605. {
  606. if (hapd->driver && hapd->driver->scan2)
  607. return hapd->driver->scan2(hapd->drv_priv, params);
  608. return -1;
  609. }
  610. struct wpa_scan_results * hostapd_driver_get_scan_results(
  611. struct hostapd_data *hapd)
  612. {
  613. if (hapd->driver && hapd->driver->get_scan_results2)
  614. return hapd->driver->get_scan_results2(hapd->drv_priv);
  615. return NULL;
  616. }
  617. int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
  618. int duration)
  619. {
  620. if (hapd->driver && hapd->driver->set_noa)
  621. return hapd->driver->set_noa(hapd->drv_priv, count, start,
  622. duration);
  623. return -1;
  624. }