ap_drv_ops.c 22 KB

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