ap_drv_ops.c 20 KB

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