ap_drv_ops.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /*
  2. * hostapd - Driver operations
  3. * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "common/hw_features_common.h"
  12. #include "wps/wps.h"
  13. #include "p2p/p2p.h"
  14. #include "hostapd.h"
  15. #include "ieee802_11.h"
  16. #include "sta_info.h"
  17. #include "ap_config.h"
  18. #include "p2p_hostapd.h"
  19. #include "hs20.h"
  20. #include "ap_drv_ops.h"
  21. u32 hostapd_sta_flags_to_drv(u32 flags)
  22. {
  23. int res = 0;
  24. if (flags & WLAN_STA_AUTHORIZED)
  25. res |= WPA_STA_AUTHORIZED;
  26. if (flags & WLAN_STA_WMM)
  27. res |= WPA_STA_WMM;
  28. if (flags & WLAN_STA_SHORT_PREAMBLE)
  29. res |= WPA_STA_SHORT_PREAMBLE;
  30. if (flags & WLAN_STA_MFP)
  31. res |= WPA_STA_MFP;
  32. if (flags & WLAN_STA_AUTH)
  33. res |= WPA_STA_AUTHENTICATED;
  34. if (flags & WLAN_STA_ASSOC)
  35. res |= WPA_STA_ASSOCIATED;
  36. return res;
  37. }
  38. static int add_buf(struct wpabuf **dst, const struct wpabuf *src)
  39. {
  40. if (!src)
  41. return 0;
  42. if (wpabuf_resize(dst, wpabuf_len(src)) != 0)
  43. return -1;
  44. wpabuf_put_buf(*dst, src);
  45. return 0;
  46. }
  47. static int add_buf_data(struct wpabuf **dst, const u8 *data, size_t len)
  48. {
  49. if (!data || !len)
  50. return 0;
  51. if (wpabuf_resize(dst, len) != 0)
  52. return -1;
  53. wpabuf_put_data(*dst, data, len);
  54. return 0;
  55. }
  56. int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
  57. struct wpabuf **beacon_ret,
  58. struct wpabuf **proberesp_ret,
  59. struct wpabuf **assocresp_ret)
  60. {
  61. struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
  62. u8 buf[200], *pos;
  63. *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
  64. pos = buf;
  65. pos = hostapd_eid_time_adv(hapd, pos);
  66. if (add_buf_data(&beacon, buf, pos - buf) < 0)
  67. goto fail;
  68. pos = hostapd_eid_time_zone(hapd, pos);
  69. if (add_buf_data(&proberesp, buf, pos - buf) < 0)
  70. goto fail;
  71. pos = buf;
  72. pos = hostapd_eid_ext_capab(hapd, pos);
  73. if (add_buf_data(&assocresp, buf, pos - buf) < 0)
  74. goto fail;
  75. pos = hostapd_eid_interworking(hapd, pos);
  76. pos = hostapd_eid_adv_proto(hapd, pos);
  77. pos = hostapd_eid_roaming_consortium(hapd, pos);
  78. if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
  79. add_buf_data(&proberesp, buf, pos - buf) < 0)
  80. goto fail;
  81. #ifdef CONFIG_FST
  82. if (add_buf(&beacon, hapd->iface->fst_ies) < 0 ||
  83. add_buf(&proberesp, hapd->iface->fst_ies) < 0 ||
  84. add_buf(&assocresp, hapd->iface->fst_ies) < 0)
  85. goto fail;
  86. #endif /* CONFIG_FST */
  87. #ifdef CONFIG_FILS
  88. pos = hostapd_eid_fils_indic(hapd, buf, 0);
  89. if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
  90. add_buf_data(&proberesp, buf, pos - buf) < 0)
  91. goto fail;
  92. #endif /* CONFIG_FILS */
  93. if (add_buf(&beacon, hapd->wps_beacon_ie) < 0 ||
  94. add_buf(&proberesp, hapd->wps_probe_resp_ie) < 0)
  95. goto fail;
  96. #ifdef CONFIG_P2P
  97. if (add_buf(&beacon, hapd->p2p_beacon_ie) < 0 ||
  98. add_buf(&proberesp, hapd->p2p_probe_resp_ie) < 0)
  99. goto fail;
  100. #endif /* CONFIG_P2P */
  101. #ifdef CONFIG_P2P_MANAGER
  102. if (hapd->conf->p2p & P2P_MANAGE) {
  103. if (wpabuf_resize(&beacon, 100) == 0) {
  104. u8 *start, *p;
  105. start = wpabuf_put(beacon, 0);
  106. p = hostapd_eid_p2p_manage(hapd, start);
  107. wpabuf_put(beacon, p - start);
  108. }
  109. if (wpabuf_resize(&proberesp, 100) == 0) {
  110. u8 *start, *p;
  111. start = wpabuf_put(proberesp, 0);
  112. p = hostapd_eid_p2p_manage(hapd, start);
  113. wpabuf_put(proberesp, p - start);
  114. }
  115. }
  116. #endif /* CONFIG_P2P_MANAGER */
  117. #ifdef CONFIG_WPS
  118. if (hapd->conf->wps_state) {
  119. struct wpabuf *a = wps_build_assoc_resp_ie();
  120. add_buf(&assocresp, a);
  121. wpabuf_free(a);
  122. }
  123. #endif /* CONFIG_WPS */
  124. #ifdef CONFIG_P2P_MANAGER
  125. if (hapd->conf->p2p & P2P_MANAGE) {
  126. if (wpabuf_resize(&assocresp, 100) == 0) {
  127. u8 *start, *p;
  128. start = wpabuf_put(assocresp, 0);
  129. p = hostapd_eid_p2p_manage(hapd, start);
  130. wpabuf_put(assocresp, p - start);
  131. }
  132. }
  133. #endif /* CONFIG_P2P_MANAGER */
  134. #ifdef CONFIG_WIFI_DISPLAY
  135. if (hapd->p2p_group) {
  136. struct wpabuf *a;
  137. a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
  138. add_buf(&assocresp, a);
  139. wpabuf_free(a);
  140. }
  141. #endif /* CONFIG_WIFI_DISPLAY */
  142. #ifdef CONFIG_HS20
  143. pos = hostapd_eid_hs20_indication(hapd, buf);
  144. if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
  145. add_buf_data(&proberesp, buf, pos - buf) < 0)
  146. goto fail;
  147. pos = hostapd_eid_osen(hapd, buf);
  148. if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
  149. add_buf_data(&proberesp, buf, pos - buf) < 0)
  150. goto fail;
  151. #endif /* CONFIG_HS20 */
  152. #ifdef CONFIG_MBO
  153. if (hapd->conf->mbo_enabled) {
  154. pos = hostapd_eid_mbo(hapd, buf, sizeof(buf));
  155. if (add_buf_data(&beacon, buf, pos - buf) < 0 ||
  156. add_buf_data(&proberesp, buf, pos - buf) < 0 ||
  157. add_buf_data(&assocresp, buf, pos - buf) < 0)
  158. goto fail;
  159. }
  160. #endif /* CONFIG_MBO */
  161. add_buf(&beacon, hapd->conf->vendor_elements);
  162. add_buf(&proberesp, hapd->conf->vendor_elements);
  163. add_buf(&assocresp, hapd->conf->assocresp_elements);
  164. *beacon_ret = beacon;
  165. *proberesp_ret = proberesp;
  166. *assocresp_ret = assocresp;
  167. return 0;
  168. fail:
  169. wpabuf_free(beacon);
  170. wpabuf_free(proberesp);
  171. wpabuf_free(assocresp);
  172. return -1;
  173. }
  174. void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
  175. struct wpabuf *beacon,
  176. struct wpabuf *proberesp,
  177. struct wpabuf *assocresp)
  178. {
  179. wpabuf_free(beacon);
  180. wpabuf_free(proberesp);
  181. wpabuf_free(assocresp);
  182. }
  183. int hostapd_reset_ap_wps_ie(struct hostapd_data *hapd)
  184. {
  185. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  186. return 0;
  187. return hapd->driver->set_ap_wps_ie(hapd->drv_priv, NULL, NULL, NULL);
  188. }
  189. int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
  190. {
  191. struct wpabuf *beacon, *proberesp, *assocresp;
  192. int ret;
  193. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  194. return 0;
  195. if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
  196. 0)
  197. return -1;
  198. ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
  199. assocresp);
  200. hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
  201. return ret;
  202. }
  203. int hostapd_set_authorized(struct hostapd_data *hapd,
  204. struct sta_info *sta, int authorized)
  205. {
  206. if (authorized) {
  207. return hostapd_sta_set_flags(hapd, sta->addr,
  208. hostapd_sta_flags_to_drv(
  209. sta->flags),
  210. WPA_STA_AUTHORIZED, ~0);
  211. }
  212. return hostapd_sta_set_flags(hapd, sta->addr,
  213. hostapd_sta_flags_to_drv(sta->flags),
  214. 0, ~WPA_STA_AUTHORIZED);
  215. }
  216. int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
  217. {
  218. int set_flags, total_flags, flags_and, flags_or;
  219. total_flags = hostapd_sta_flags_to_drv(sta->flags);
  220. set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
  221. if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
  222. sta->auth_alg == WLAN_AUTH_FT) &&
  223. sta->flags & WLAN_STA_AUTHORIZED)
  224. set_flags |= WPA_STA_AUTHORIZED;
  225. flags_or = total_flags & set_flags;
  226. flags_and = total_flags | ~set_flags;
  227. return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
  228. flags_or, flags_and);
  229. }
  230. int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
  231. int enabled)
  232. {
  233. struct wpa_bss_params params;
  234. os_memset(&params, 0, sizeof(params));
  235. params.ifname = ifname;
  236. params.enabled = enabled;
  237. if (enabled) {
  238. params.wpa = hapd->conf->wpa;
  239. params.ieee802_1x = hapd->conf->ieee802_1x;
  240. params.wpa_group = hapd->conf->wpa_group;
  241. if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
  242. (WPA_PROTO_WPA | WPA_PROTO_RSN))
  243. params.wpa_pairwise = hapd->conf->wpa_pairwise |
  244. hapd->conf->rsn_pairwise;
  245. else if (hapd->conf->wpa & WPA_PROTO_RSN)
  246. params.wpa_pairwise = hapd->conf->rsn_pairwise;
  247. else if (hapd->conf->wpa & WPA_PROTO_WPA)
  248. params.wpa_pairwise = hapd->conf->wpa_pairwise;
  249. params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
  250. params.rsn_preauth = hapd->conf->rsn_preauth;
  251. #ifdef CONFIG_IEEE80211W
  252. params.ieee80211w = hapd->conf->ieee80211w;
  253. #endif /* CONFIG_IEEE80211W */
  254. }
  255. return hostapd_set_ieee8021x(hapd, &params);
  256. }
  257. int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
  258. {
  259. char force_ifname[IFNAMSIZ];
  260. u8 if_addr[ETH_ALEN];
  261. return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
  262. NULL, NULL, force_ifname, if_addr, NULL, 0);
  263. }
  264. int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
  265. {
  266. return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
  267. }
  268. int hostapd_set_wds_sta(struct hostapd_data *hapd, char *ifname_wds,
  269. const u8 *addr, int aid, int val)
  270. {
  271. const char *bridge = NULL;
  272. if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
  273. return -1;
  274. if (hapd->conf->wds_bridge[0])
  275. bridge = hapd->conf->wds_bridge;
  276. else if (hapd->conf->bridge[0])
  277. bridge = hapd->conf->bridge;
  278. return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
  279. bridge, ifname_wds);
  280. }
  281. int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
  282. u16 auth_alg)
  283. {
  284. if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
  285. return 0;
  286. return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
  287. }
  288. int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
  289. u16 seq, u16 status, const u8 *ie, size_t len)
  290. {
  291. struct wpa_driver_sta_auth_params params;
  292. if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
  293. return 0;
  294. os_memset(&params, 0, sizeof(params));
  295. params.own_addr = hapd->own_addr;
  296. params.addr = addr;
  297. params.seq = seq;
  298. params.status = status;
  299. params.ie = ie;
  300. params.len = len;
  301. return hapd->driver->sta_auth(hapd->drv_priv, &params);
  302. }
  303. int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
  304. int reassoc, u16 status, const u8 *ie, size_t len)
  305. {
  306. if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
  307. return 0;
  308. return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
  309. reassoc, status, ie, len);
  310. }
  311. int hostapd_sta_add(struct hostapd_data *hapd,
  312. const u8 *addr, u16 aid, u16 capability,
  313. const u8 *supp_rates, size_t supp_rates_len,
  314. u16 listen_interval,
  315. const struct ieee80211_ht_capabilities *ht_capab,
  316. const struct ieee80211_vht_capabilities *vht_capab,
  317. u32 flags, u8 qosinfo, u8 vht_opmode, int supp_p2p_ps,
  318. int set)
  319. {
  320. struct hostapd_sta_add_params params;
  321. if (hapd->driver == NULL)
  322. return 0;
  323. if (hapd->driver->sta_add == NULL)
  324. return 0;
  325. os_memset(&params, 0, sizeof(params));
  326. params.addr = addr;
  327. params.aid = aid;
  328. params.capability = capability;
  329. params.supp_rates = supp_rates;
  330. params.supp_rates_len = supp_rates_len;
  331. params.listen_interval = listen_interval;
  332. params.ht_capabilities = ht_capab;
  333. params.vht_capabilities = vht_capab;
  334. params.vht_opmode_enabled = !!(flags & WLAN_STA_VHT_OPMODE_ENABLED);
  335. params.vht_opmode = vht_opmode;
  336. params.flags = hostapd_sta_flags_to_drv(flags);
  337. params.qosinfo = qosinfo;
  338. params.support_p2p_ps = supp_p2p_ps;
  339. params.set = set;
  340. return hapd->driver->sta_add(hapd->drv_priv, &params);
  341. }
  342. int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
  343. u8 *tspec_ie, size_t tspec_ielen)
  344. {
  345. if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
  346. return 0;
  347. return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
  348. tspec_ielen);
  349. }
  350. int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  351. {
  352. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  353. return 0;
  354. return hapd->driver->set_privacy(hapd->drv_priv, enabled);
  355. }
  356. int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  357. size_t elem_len)
  358. {
  359. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  360. return 0;
  361. return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
  362. }
  363. int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  364. {
  365. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  366. return 0;
  367. return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
  368. }
  369. int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  370. {
  371. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  372. return 0;
  373. return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
  374. }
  375. int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  376. const char *ifname, const u8 *addr, void *bss_ctx,
  377. void **drv_priv, char *force_ifname, u8 *if_addr,
  378. const char *bridge, int use_existing)
  379. {
  380. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  381. return -1;
  382. return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
  383. bss_ctx, drv_priv, force_ifname, if_addr,
  384. bridge, use_existing, 1);
  385. }
  386. int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  387. const char *ifname)
  388. {
  389. if (hapd->driver == NULL || hapd->drv_priv == NULL ||
  390. hapd->driver->if_remove == NULL)
  391. return -1;
  392. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  393. }
  394. int hostapd_set_ieee8021x(struct hostapd_data *hapd,
  395. struct wpa_bss_params *params)
  396. {
  397. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  398. return 0;
  399. return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
  400. }
  401. int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  402. const u8 *addr, int idx, u8 *seq)
  403. {
  404. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  405. return 0;
  406. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  407. seq);
  408. }
  409. int hostapd_flush(struct hostapd_data *hapd)
  410. {
  411. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  412. return 0;
  413. return hapd->driver->flush(hapd->drv_priv);
  414. }
  415. int hostapd_set_freq(struct hostapd_data *hapd, enum hostapd_hw_mode mode,
  416. int freq, int channel, int ht_enabled, int vht_enabled,
  417. int sec_channel_offset, int vht_oper_chwidth,
  418. int center_segment0, int center_segment1)
  419. {
  420. struct hostapd_freq_params data;
  421. if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
  422. vht_enabled, sec_channel_offset,
  423. vht_oper_chwidth,
  424. center_segment0, center_segment1,
  425. hapd->iface->current_mode ?
  426. hapd->iface->current_mode->vht_capab : 0))
  427. return -1;
  428. if (hapd->driver == NULL)
  429. return 0;
  430. if (hapd->driver->set_freq == NULL)
  431. return 0;
  432. return hapd->driver->set_freq(hapd->drv_priv, &data);
  433. }
  434. int hostapd_set_rts(struct hostapd_data *hapd, int rts)
  435. {
  436. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  437. return 0;
  438. return hapd->driver->set_rts(hapd->drv_priv, rts);
  439. }
  440. int hostapd_set_frag(struct hostapd_data *hapd, int frag)
  441. {
  442. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  443. return 0;
  444. return hapd->driver->set_frag(hapd->drv_priv, frag);
  445. }
  446. int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  447. int total_flags, int flags_or, int flags_and)
  448. {
  449. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  450. return 0;
  451. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  452. flags_or, flags_and);
  453. }
  454. int hostapd_set_country(struct hostapd_data *hapd, const char *country)
  455. {
  456. if (hapd->driver == NULL ||
  457. hapd->driver->set_country == NULL)
  458. return 0;
  459. return hapd->driver->set_country(hapd->drv_priv, country);
  460. }
  461. int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  462. int cw_min, int cw_max, int burst_time)
  463. {
  464. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  465. return 0;
  466. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  467. cw_min, cw_max, burst_time);
  468. }
  469. struct hostapd_hw_modes *
  470. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  471. u16 *flags)
  472. {
  473. if (hapd->driver == NULL ||
  474. hapd->driver->get_hw_feature_data == NULL)
  475. return NULL;
  476. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  477. flags);
  478. }
  479. int hostapd_driver_commit(struct hostapd_data *hapd)
  480. {
  481. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  482. return 0;
  483. return hapd->driver->commit(hapd->drv_priv);
  484. }
  485. int hostapd_drv_none(struct hostapd_data *hapd)
  486. {
  487. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  488. }
  489. int hostapd_driver_scan(struct hostapd_data *hapd,
  490. struct wpa_driver_scan_params *params)
  491. {
  492. if (hapd->driver && hapd->driver->scan2)
  493. return hapd->driver->scan2(hapd->drv_priv, params);
  494. return -1;
  495. }
  496. struct wpa_scan_results * hostapd_driver_get_scan_results(
  497. struct hostapd_data *hapd)
  498. {
  499. if (hapd->driver && hapd->driver->get_scan_results2)
  500. return hapd->driver->get_scan_results2(hapd->drv_priv);
  501. return NULL;
  502. }
  503. int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
  504. int duration)
  505. {
  506. if (hapd->driver && hapd->driver->set_noa)
  507. return hapd->driver->set_noa(hapd->drv_priv, count, start,
  508. duration);
  509. return -1;
  510. }
  511. int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
  512. enum wpa_alg alg, const u8 *addr,
  513. int key_idx, int set_tx,
  514. const u8 *seq, size_t seq_len,
  515. const u8 *key, size_t key_len)
  516. {
  517. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  518. return 0;
  519. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  520. key_idx, set_tx, seq, seq_len, key,
  521. key_len);
  522. }
  523. int hostapd_drv_send_mlme(struct hostapd_data *hapd,
  524. const void *msg, size_t len, int noack)
  525. {
  526. if (!hapd->driver || !hapd->driver->send_mlme || !hapd->drv_priv)
  527. return 0;
  528. return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
  529. NULL, 0);
  530. }
  531. int hostapd_drv_send_mlme_csa(struct hostapd_data *hapd,
  532. const void *msg, size_t len, int noack,
  533. const u16 *csa_offs, size_t csa_offs_len)
  534. {
  535. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  536. return 0;
  537. return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack, 0,
  538. csa_offs, csa_offs_len);
  539. }
  540. int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
  541. const u8 *addr, int reason)
  542. {
  543. if (!hapd->driver || !hapd->driver->sta_deauth || !hapd->drv_priv)
  544. return 0;
  545. return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
  546. reason);
  547. }
  548. int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
  549. const u8 *addr, int reason)
  550. {
  551. if (!hapd->driver || !hapd->driver->sta_disassoc || !hapd->drv_priv)
  552. return 0;
  553. return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
  554. reason);
  555. }
  556. int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
  557. const u8 *peer, u8 *buf, u16 *buf_len)
  558. {
  559. if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
  560. return -1;
  561. return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
  562. buf_len);
  563. }
  564. int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
  565. unsigned int wait, const u8 *dst, const u8 *data,
  566. size_t len)
  567. {
  568. const u8 *bssid;
  569. const u8 wildcard_bssid[ETH_ALEN] = {
  570. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  571. };
  572. if (!hapd->driver || !hapd->driver->send_action || !hapd->drv_priv)
  573. return 0;
  574. bssid = hapd->own_addr;
  575. if (!is_multicast_ether_addr(dst) &&
  576. len > 0 && data[0] == WLAN_ACTION_PUBLIC) {
  577. struct sta_info *sta;
  578. /*
  579. * Public Action frames to a STA that is not a member of the BSS
  580. * shall use wildcard BSSID value.
  581. */
  582. sta = ap_get_sta(hapd, dst);
  583. if (!sta || !(sta->flags & WLAN_STA_ASSOC))
  584. bssid = wildcard_bssid;
  585. }
  586. return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
  587. hapd->own_addr, bssid, data, len, 0);
  588. }
  589. int hostapd_drv_send_action_addr3_ap(struct hostapd_data *hapd,
  590. unsigned int freq,
  591. unsigned int wait, const u8 *dst,
  592. const u8 *data, size_t len)
  593. {
  594. if (hapd->driver == NULL || hapd->driver->send_action == NULL)
  595. return 0;
  596. return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
  597. hapd->own_addr, hapd->own_addr, data,
  598. len, 0);
  599. }
  600. int hostapd_start_dfs_cac(struct hostapd_iface *iface,
  601. enum hostapd_hw_mode mode, int freq,
  602. int channel, int ht_enabled, int vht_enabled,
  603. int sec_channel_offset, int vht_oper_chwidth,
  604. int center_segment0, int center_segment1)
  605. {
  606. struct hostapd_data *hapd = iface->bss[0];
  607. struct hostapd_freq_params data;
  608. int res;
  609. if (!hapd->driver || !hapd->driver->start_dfs_cac)
  610. return 0;
  611. if (!iface->conf->ieee80211h) {
  612. wpa_printf(MSG_ERROR, "Can't start DFS CAC, DFS functionality "
  613. "is not enabled");
  614. return -1;
  615. }
  616. if (hostapd_set_freq_params(&data, mode, freq, channel, ht_enabled,
  617. vht_enabled, sec_channel_offset,
  618. vht_oper_chwidth, center_segment0,
  619. center_segment1,
  620. iface->current_mode->vht_capab)) {
  621. wpa_printf(MSG_ERROR, "Can't set freq params");
  622. return -1;
  623. }
  624. res = hapd->driver->start_dfs_cac(hapd->drv_priv, &data);
  625. if (!res) {
  626. iface->cac_started = 1;
  627. os_get_reltime(&iface->dfs_cac_start);
  628. }
  629. return res;
  630. }
  631. int hostapd_drv_set_qos_map(struct hostapd_data *hapd,
  632. const u8 *qos_map_set, u8 qos_map_set_len)
  633. {
  634. if (!hapd->driver || !hapd->driver->set_qos_map || !hapd->drv_priv)
  635. return 0;
  636. return hapd->driver->set_qos_map(hapd->drv_priv, qos_map_set,
  637. qos_map_set_len);
  638. }
  639. static void hostapd_get_hw_mode_any_channels(struct hostapd_data *hapd,
  640. struct hostapd_hw_modes *mode,
  641. int acs_ch_list_all,
  642. int **freq_list)
  643. {
  644. int i;
  645. for (i = 0; i < mode->num_channels; i++) {
  646. struct hostapd_channel_data *chan = &mode->channels[i];
  647. if ((acs_ch_list_all ||
  648. freq_range_list_includes(&hapd->iface->conf->acs_ch_list,
  649. chan->chan)) &&
  650. !(chan->flag & HOSTAPD_CHAN_DISABLED))
  651. int_array_add_unique(freq_list, chan->freq);
  652. }
  653. }
  654. void hostapd_get_ext_capa(struct hostapd_iface *iface)
  655. {
  656. struct hostapd_data *hapd = iface->bss[0];
  657. if (!hapd->driver || !hapd->driver->get_ext_capab)
  658. return;
  659. hapd->driver->get_ext_capab(hapd->drv_priv, WPA_IF_AP_BSS,
  660. &iface->extended_capa,
  661. &iface->extended_capa_mask,
  662. &iface->extended_capa_len);
  663. }
  664. int hostapd_drv_do_acs(struct hostapd_data *hapd)
  665. {
  666. struct drv_acs_params params;
  667. int ret, i, acs_ch_list_all = 0;
  668. u8 *channels = NULL;
  669. unsigned int num_channels = 0;
  670. struct hostapd_hw_modes *mode;
  671. int *freq_list = NULL;
  672. if (hapd->driver == NULL || hapd->driver->do_acs == NULL)
  673. return 0;
  674. os_memset(&params, 0, sizeof(params));
  675. params.hw_mode = hapd->iface->conf->hw_mode;
  676. /*
  677. * If no chanlist config parameter is provided, include all enabled
  678. * channels of the selected hw_mode.
  679. */
  680. if (!hapd->iface->conf->acs_ch_list.num)
  681. acs_ch_list_all = 1;
  682. mode = hapd->iface->current_mode;
  683. if (mode) {
  684. channels = os_malloc(mode->num_channels);
  685. if (channels == NULL)
  686. return -1;
  687. for (i = 0; i < mode->num_channels; i++) {
  688. struct hostapd_channel_data *chan = &mode->channels[i];
  689. if (!acs_ch_list_all &&
  690. !freq_range_list_includes(
  691. &hapd->iface->conf->acs_ch_list,
  692. chan->chan))
  693. continue;
  694. if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) {
  695. channels[num_channels++] = chan->chan;
  696. int_array_add_unique(&freq_list, chan->freq);
  697. }
  698. }
  699. } else {
  700. for (i = 0; i < hapd->iface->num_hw_features; i++) {
  701. mode = &hapd->iface->hw_features[i];
  702. hostapd_get_hw_mode_any_channels(hapd, mode,
  703. acs_ch_list_all,
  704. &freq_list);
  705. }
  706. }
  707. params.ch_list = channels;
  708. params.ch_list_len = num_channels;
  709. params.freq_list = freq_list;
  710. params.ht_enabled = !!(hapd->iface->conf->ieee80211n);
  711. params.ht40_enabled = !!(hapd->iface->conf->ht_capab &
  712. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET);
  713. params.vht_enabled = !!(hapd->iface->conf->ieee80211ac);
  714. params.ch_width = 20;
  715. if (hapd->iface->conf->ieee80211n && params.ht40_enabled)
  716. params.ch_width = 40;
  717. /* Note: VHT20 is defined by combination of ht_capab & vht_oper_chwidth
  718. */
  719. if (hapd->iface->conf->ieee80211ac && params.ht40_enabled) {
  720. if (hapd->iface->conf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
  721. params.ch_width = 80;
  722. else if (hapd->iface->conf->vht_oper_chwidth ==
  723. VHT_CHANWIDTH_160MHZ ||
  724. hapd->iface->conf->vht_oper_chwidth ==
  725. VHT_CHANWIDTH_80P80MHZ)
  726. params.ch_width = 160;
  727. }
  728. ret = hapd->driver->do_acs(hapd->drv_priv, &params);
  729. os_free(channels);
  730. return ret;
  731. }