ap_drv_ops.c 18 KB

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