ap_drv_ops.c 22 KB

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