ap_drv_ops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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 "drivers/driver.h"
  11. #include "common/ieee802_11_defs.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. return res;
  33. }
  34. int hostapd_build_ap_extra_ies(struct hostapd_data *hapd,
  35. struct wpabuf **beacon_ret,
  36. struct wpabuf **proberesp_ret,
  37. struct wpabuf **assocresp_ret)
  38. {
  39. struct wpabuf *beacon = NULL, *proberesp = NULL, *assocresp = NULL;
  40. u8 buf[200], *pos;
  41. *beacon_ret = *proberesp_ret = *assocresp_ret = NULL;
  42. pos = buf;
  43. pos = hostapd_eid_time_adv(hapd, pos);
  44. if (pos != buf) {
  45. if (wpabuf_resize(&beacon, pos - buf) != 0)
  46. goto fail;
  47. wpabuf_put_data(beacon, buf, pos - buf);
  48. }
  49. pos = hostapd_eid_time_zone(hapd, pos);
  50. if (pos != buf) {
  51. if (wpabuf_resize(&proberesp, pos - buf) != 0)
  52. goto fail;
  53. wpabuf_put_data(proberesp, buf, pos - buf);
  54. }
  55. pos = buf;
  56. pos = hostapd_eid_ext_capab(hapd, pos);
  57. if (pos != buf) {
  58. if (wpabuf_resize(&assocresp, pos - buf) != 0)
  59. goto fail;
  60. wpabuf_put_data(assocresp, buf, pos - buf);
  61. }
  62. pos = hostapd_eid_interworking(hapd, pos);
  63. pos = hostapd_eid_adv_proto(hapd, pos);
  64. pos = hostapd_eid_roaming_consortium(hapd, pos);
  65. if (pos != buf) {
  66. if (wpabuf_resize(&beacon, pos - buf) != 0)
  67. goto fail;
  68. wpabuf_put_data(beacon, buf, pos - buf);
  69. if (wpabuf_resize(&proberesp, pos - buf) != 0)
  70. goto fail;
  71. wpabuf_put_data(proberesp, buf, pos - buf);
  72. }
  73. if (hapd->wps_beacon_ie) {
  74. if (wpabuf_resize(&beacon, wpabuf_len(hapd->wps_beacon_ie)) <
  75. 0)
  76. goto fail;
  77. wpabuf_put_buf(beacon, hapd->wps_beacon_ie);
  78. }
  79. if (hapd->wps_probe_resp_ie) {
  80. if (wpabuf_resize(&proberesp,
  81. wpabuf_len(hapd->wps_probe_resp_ie)) < 0)
  82. goto fail;
  83. wpabuf_put_buf(proberesp, hapd->wps_probe_resp_ie);
  84. }
  85. #ifdef CONFIG_P2P
  86. if (hapd->p2p_beacon_ie) {
  87. if (wpabuf_resize(&beacon, wpabuf_len(hapd->p2p_beacon_ie)) <
  88. 0)
  89. goto fail;
  90. wpabuf_put_buf(beacon, hapd->p2p_beacon_ie);
  91. }
  92. if (hapd->p2p_probe_resp_ie) {
  93. if (wpabuf_resize(&proberesp,
  94. wpabuf_len(hapd->p2p_probe_resp_ie)) < 0)
  95. goto fail;
  96. wpabuf_put_buf(proberesp, hapd->p2p_probe_resp_ie);
  97. }
  98. #endif /* CONFIG_P2P */
  99. #ifdef CONFIG_P2P_MANAGER
  100. if (hapd->conf->p2p & P2P_MANAGE) {
  101. if (wpabuf_resize(&beacon, 100) == 0) {
  102. u8 *start, *p;
  103. start = wpabuf_put(beacon, 0);
  104. p = hostapd_eid_p2p_manage(hapd, start);
  105. wpabuf_put(beacon, p - start);
  106. }
  107. if (wpabuf_resize(&proberesp, 100) == 0) {
  108. u8 *start, *p;
  109. start = wpabuf_put(proberesp, 0);
  110. p = hostapd_eid_p2p_manage(hapd, start);
  111. wpabuf_put(proberesp, p - start);
  112. }
  113. }
  114. #endif /* CONFIG_P2P_MANAGER */
  115. #ifdef CONFIG_WPS2
  116. if (hapd->conf->wps_state) {
  117. struct wpabuf *a = wps_build_assoc_resp_ie();
  118. if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
  119. wpabuf_put_buf(assocresp, a);
  120. wpabuf_free(a);
  121. }
  122. #endif /* CONFIG_WPS2 */
  123. #ifdef CONFIG_P2P_MANAGER
  124. if (hapd->conf->p2p & P2P_MANAGE) {
  125. if (wpabuf_resize(&assocresp, 100) == 0) {
  126. u8 *start, *p;
  127. start = wpabuf_put(assocresp, 0);
  128. p = hostapd_eid_p2p_manage(hapd, start);
  129. wpabuf_put(assocresp, p - start);
  130. }
  131. }
  132. #endif /* CONFIG_P2P_MANAGER */
  133. #ifdef CONFIG_WIFI_DISPLAY
  134. if (hapd->p2p_group) {
  135. struct wpabuf *a;
  136. a = p2p_group_assoc_resp_ie(hapd->p2p_group, P2P_SC_SUCCESS);
  137. if (a && wpabuf_resize(&assocresp, wpabuf_len(a)) == 0)
  138. wpabuf_put_buf(assocresp, a);
  139. wpabuf_free(a);
  140. }
  141. #endif /* CONFIG_WIFI_DISPLAY */
  142. #ifdef CONFIG_HS20
  143. pos = buf;
  144. pos = hostapd_eid_hs20_indication(hapd, pos);
  145. if (pos != buf) {
  146. if (wpabuf_resize(&beacon, pos - buf) != 0)
  147. goto fail;
  148. wpabuf_put_data(beacon, buf, pos - buf);
  149. if (wpabuf_resize(&proberesp, pos - buf) != 0)
  150. goto fail;
  151. wpabuf_put_data(proberesp, buf, pos - buf);
  152. }
  153. #endif /* CONFIG_HS20 */
  154. *beacon_ret = beacon;
  155. *proberesp_ret = proberesp;
  156. *assocresp_ret = assocresp;
  157. return 0;
  158. fail:
  159. wpabuf_free(beacon);
  160. wpabuf_free(proberesp);
  161. wpabuf_free(assocresp);
  162. return -1;
  163. }
  164. void hostapd_free_ap_extra_ies(struct hostapd_data *hapd,
  165. struct wpabuf *beacon,
  166. struct wpabuf *proberesp,
  167. struct wpabuf *assocresp)
  168. {
  169. wpabuf_free(beacon);
  170. wpabuf_free(proberesp);
  171. wpabuf_free(assocresp);
  172. }
  173. int hostapd_set_ap_wps_ie(struct hostapd_data *hapd)
  174. {
  175. struct wpabuf *beacon, *proberesp, *assocresp;
  176. int ret;
  177. if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
  178. return 0;
  179. if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
  180. 0)
  181. return -1;
  182. ret = hapd->driver->set_ap_wps_ie(hapd->drv_priv, beacon, proberesp,
  183. assocresp);
  184. hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
  185. return ret;
  186. }
  187. int hostapd_set_authorized(struct hostapd_data *hapd,
  188. struct sta_info *sta, int authorized)
  189. {
  190. if (authorized) {
  191. return hostapd_sta_set_flags(hapd, sta->addr,
  192. hostapd_sta_flags_to_drv(
  193. sta->flags),
  194. WPA_STA_AUTHORIZED, ~0);
  195. }
  196. return hostapd_sta_set_flags(hapd, sta->addr,
  197. hostapd_sta_flags_to_drv(sta->flags),
  198. 0, ~WPA_STA_AUTHORIZED);
  199. }
  200. int hostapd_set_sta_flags(struct hostapd_data *hapd, struct sta_info *sta)
  201. {
  202. int set_flags, total_flags, flags_and, flags_or;
  203. total_flags = hostapd_sta_flags_to_drv(sta->flags);
  204. set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
  205. if (((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
  206. sta->auth_alg == WLAN_AUTH_FT) &&
  207. sta->flags & WLAN_STA_AUTHORIZED)
  208. set_flags |= WPA_STA_AUTHORIZED;
  209. flags_or = total_flags & set_flags;
  210. flags_and = total_flags | ~set_flags;
  211. return hostapd_sta_set_flags(hapd, sta->addr, total_flags,
  212. flags_or, flags_and);
  213. }
  214. int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
  215. int enabled)
  216. {
  217. struct wpa_bss_params params;
  218. os_memset(&params, 0, sizeof(params));
  219. params.ifname = ifname;
  220. params.enabled = enabled;
  221. if (enabled) {
  222. params.wpa = hapd->conf->wpa;
  223. params.ieee802_1x = hapd->conf->ieee802_1x;
  224. params.wpa_group = hapd->conf->wpa_group;
  225. params.wpa_pairwise = hapd->conf->wpa_pairwise;
  226. params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
  227. params.rsn_preauth = hapd->conf->rsn_preauth;
  228. #ifdef CONFIG_IEEE80211W
  229. params.ieee80211w = hapd->conf->ieee80211w;
  230. #endif /* CONFIG_IEEE80211W */
  231. }
  232. return hostapd_set_ieee8021x(hapd, &params);
  233. }
  234. int hostapd_vlan_if_add(struct hostapd_data *hapd, const char *ifname)
  235. {
  236. char force_ifname[IFNAMSIZ];
  237. u8 if_addr[ETH_ALEN];
  238. return hostapd_if_add(hapd, WPA_IF_AP_VLAN, ifname, hapd->own_addr,
  239. NULL, NULL, force_ifname, if_addr, NULL);
  240. }
  241. int hostapd_vlan_if_remove(struct hostapd_data *hapd, const char *ifname)
  242. {
  243. return hostapd_if_remove(hapd, WPA_IF_AP_VLAN, ifname);
  244. }
  245. int hostapd_set_wds_sta(struct hostapd_data *hapd, const u8 *addr, int aid,
  246. int val)
  247. {
  248. const char *bridge = NULL;
  249. if (hapd->driver == NULL || hapd->driver->set_wds_sta == NULL)
  250. return 0;
  251. if (hapd->conf->wds_bridge[0])
  252. bridge = hapd->conf->wds_bridge;
  253. else if (hapd->conf->bridge[0])
  254. bridge = hapd->conf->bridge;
  255. return hapd->driver->set_wds_sta(hapd->drv_priv, addr, aid, val,
  256. bridge);
  257. }
  258. int hostapd_add_sta_node(struct hostapd_data *hapd, const u8 *addr,
  259. u16 auth_alg)
  260. {
  261. if (hapd->driver == NULL || hapd->driver->add_sta_node == NULL)
  262. return 0;
  263. return hapd->driver->add_sta_node(hapd->drv_priv, addr, auth_alg);
  264. }
  265. int hostapd_sta_auth(struct hostapd_data *hapd, const u8 *addr,
  266. u16 seq, u16 status, const u8 *ie, size_t len)
  267. {
  268. if (hapd->driver == NULL || hapd->driver->sta_auth == NULL)
  269. return 0;
  270. return hapd->driver->sta_auth(hapd->drv_priv, hapd->own_addr, addr,
  271. seq, status, ie, len);
  272. }
  273. int hostapd_sta_assoc(struct hostapd_data *hapd, const u8 *addr,
  274. int reassoc, u16 status, const u8 *ie, size_t len)
  275. {
  276. if (hapd->driver == NULL || hapd->driver->sta_assoc == NULL)
  277. return 0;
  278. return hapd->driver->sta_assoc(hapd->drv_priv, hapd->own_addr, addr,
  279. reassoc, status, ie, len);
  280. }
  281. int hostapd_sta_add(struct hostapd_data *hapd,
  282. const u8 *addr, u16 aid, u16 capability,
  283. const u8 *supp_rates, size_t supp_rates_len,
  284. u16 listen_interval,
  285. const struct ieee80211_ht_capabilities *ht_capab,
  286. const struct ieee80211_vht_capabilities *vht_capab,
  287. u32 flags, u8 qosinfo)
  288. {
  289. struct hostapd_sta_add_params params;
  290. if (hapd->driver == NULL)
  291. return 0;
  292. if (hapd->driver->sta_add == NULL)
  293. return 0;
  294. os_memset(&params, 0, sizeof(params));
  295. params.addr = addr;
  296. params.aid = aid;
  297. params.capability = capability;
  298. params.supp_rates = supp_rates;
  299. params.supp_rates_len = supp_rates_len;
  300. params.listen_interval = listen_interval;
  301. params.ht_capabilities = ht_capab;
  302. params.vht_capabilities = vht_capab;
  303. params.flags = hostapd_sta_flags_to_drv(flags);
  304. params.qosinfo = qosinfo;
  305. return hapd->driver->sta_add(hapd->drv_priv, &params);
  306. }
  307. int hostapd_add_tspec(struct hostapd_data *hapd, const u8 *addr,
  308. u8 *tspec_ie, size_t tspec_ielen)
  309. {
  310. if (hapd->driver == NULL || hapd->driver->add_tspec == NULL)
  311. return 0;
  312. return hapd->driver->add_tspec(hapd->drv_priv, addr, tspec_ie,
  313. tspec_ielen);
  314. }
  315. int hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
  316. {
  317. if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
  318. return 0;
  319. return hapd->driver->set_privacy(hapd->drv_priv, enabled);
  320. }
  321. int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
  322. size_t elem_len)
  323. {
  324. if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
  325. return 0;
  326. return hapd->driver->set_generic_elem(hapd->drv_priv, elem, elem_len);
  327. }
  328. int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
  329. {
  330. if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
  331. return 0;
  332. return hapd->driver->hapd_get_ssid(hapd->drv_priv, buf, len);
  333. }
  334. int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
  335. {
  336. if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
  337. return 0;
  338. return hapd->driver->hapd_set_ssid(hapd->drv_priv, buf, len);
  339. }
  340. int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  341. const char *ifname, const u8 *addr, void *bss_ctx,
  342. void **drv_priv, char *force_ifname, u8 *if_addr,
  343. const char *bridge)
  344. {
  345. if (hapd->driver == NULL || hapd->driver->if_add == NULL)
  346. return -1;
  347. return hapd->driver->if_add(hapd->drv_priv, type, ifname, addr,
  348. bss_ctx, drv_priv, force_ifname, if_addr,
  349. bridge);
  350. }
  351. int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
  352. const char *ifname)
  353. {
  354. if (hapd->driver == NULL || hapd->driver->if_remove == NULL)
  355. return -1;
  356. return hapd->driver->if_remove(hapd->drv_priv, type, ifname);
  357. }
  358. int hostapd_set_ieee8021x(struct hostapd_data *hapd,
  359. struct wpa_bss_params *params)
  360. {
  361. if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
  362. return 0;
  363. return hapd->driver->set_ieee8021x(hapd->drv_priv, params);
  364. }
  365. int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
  366. const u8 *addr, int idx, u8 *seq)
  367. {
  368. if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
  369. return 0;
  370. return hapd->driver->get_seqnum(ifname, hapd->drv_priv, addr, idx,
  371. seq);
  372. }
  373. int hostapd_flush(struct hostapd_data *hapd)
  374. {
  375. if (hapd->driver == NULL || hapd->driver->flush == NULL)
  376. return 0;
  377. return hapd->driver->flush(hapd->drv_priv);
  378. }
  379. int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
  380. int channel, int ht_enabled, int vht_enabled,
  381. int sec_channel_offset, int vht_oper_chwidth,
  382. int center_segment0, int center_segment1)
  383. {
  384. struct hostapd_freq_params data;
  385. int tmp;
  386. os_memset(&data, 0, sizeof(data));
  387. data.mode = mode;
  388. data.freq = freq;
  389. data.channel = channel;
  390. data.ht_enabled = ht_enabled;
  391. data.vht_enabled = vht_enabled;
  392. data.sec_channel_offset = sec_channel_offset;
  393. data.center_freq1 = freq + sec_channel_offset * 10;
  394. data.center_freq2 = 0;
  395. data.bandwidth = sec_channel_offset ? 40 : 20;
  396. /*
  397. * This validation code is probably misplaced, maybe it should be
  398. * in src/ap/hw_features.c and check the hardware support as well.
  399. */
  400. if (data.vht_enabled) switch (vht_oper_chwidth) {
  401. case VHT_CHANWIDTH_USE_HT:
  402. if (center_segment1)
  403. return -1;
  404. if (5000 + center_segment0 * 5 != data.center_freq1)
  405. return -1;
  406. break;
  407. case VHT_CHANWIDTH_80P80MHZ:
  408. if (center_segment1 == center_segment0 + 4 ||
  409. center_segment1 == center_segment0 - 4)
  410. return -1;
  411. data.center_freq2 = 5000 + center_segment1 * 5;
  412. /* fall through */
  413. case VHT_CHANWIDTH_80MHZ:
  414. data.bandwidth = 80;
  415. if (vht_oper_chwidth == 1 && center_segment1)
  416. return -1;
  417. if (vht_oper_chwidth == 3 && !center_segment1)
  418. return -1;
  419. if (!sec_channel_offset)
  420. return -1;
  421. /* primary 40 part must match the HT configuration */
  422. tmp = (30 + freq - 5000 - center_segment0 * 5)/20;
  423. tmp /= 2;
  424. if (data.center_freq1 != 5000 +
  425. center_segment0 * 5 - 20 + 40 * tmp)
  426. return -1;
  427. data.center_freq1 = 5000 + center_segment0 * 5;
  428. break;
  429. case VHT_CHANWIDTH_160MHZ:
  430. data.bandwidth = 160;
  431. if (center_segment1)
  432. return -1;
  433. if (!sec_channel_offset)
  434. return -1;
  435. /* primary 40 part must match the HT configuration */
  436. tmp = (70 + freq - 5000 - center_segment0 * 5)/20;
  437. tmp /= 2;
  438. if (data.center_freq1 != 5000 +
  439. center_segment0 * 5 - 60 + 40 * tmp)
  440. return -1;
  441. data.center_freq1 = 5000 + center_segment0 * 5;
  442. break;
  443. }
  444. if (hapd->driver == NULL)
  445. return 0;
  446. if (hapd->driver->set_freq == NULL)
  447. return 0;
  448. return hapd->driver->set_freq(hapd->drv_priv, &data);
  449. }
  450. int hostapd_set_rts(struct hostapd_data *hapd, int rts)
  451. {
  452. if (hapd->driver == NULL || hapd->driver->set_rts == NULL)
  453. return 0;
  454. return hapd->driver->set_rts(hapd->drv_priv, rts);
  455. }
  456. int hostapd_set_frag(struct hostapd_data *hapd, int frag)
  457. {
  458. if (hapd->driver == NULL || hapd->driver->set_frag == NULL)
  459. return 0;
  460. return hapd->driver->set_frag(hapd->drv_priv, frag);
  461. }
  462. int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
  463. int total_flags, int flags_or, int flags_and)
  464. {
  465. if (hapd->driver == NULL || hapd->driver->sta_set_flags == NULL)
  466. return 0;
  467. return hapd->driver->sta_set_flags(hapd->drv_priv, addr, total_flags,
  468. flags_or, flags_and);
  469. }
  470. int hostapd_set_country(struct hostapd_data *hapd, const char *country)
  471. {
  472. if (hapd->driver == NULL ||
  473. hapd->driver->set_country == NULL)
  474. return 0;
  475. return hapd->driver->set_country(hapd->drv_priv, country);
  476. }
  477. int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
  478. int cw_min, int cw_max, int burst_time)
  479. {
  480. if (hapd->driver == NULL || hapd->driver->set_tx_queue_params == NULL)
  481. return 0;
  482. return hapd->driver->set_tx_queue_params(hapd->drv_priv, queue, aifs,
  483. cw_min, cw_max, burst_time);
  484. }
  485. struct hostapd_hw_modes *
  486. hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
  487. u16 *flags)
  488. {
  489. if (hapd->driver == NULL ||
  490. hapd->driver->get_hw_feature_data == NULL)
  491. return NULL;
  492. return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
  493. flags);
  494. }
  495. int hostapd_driver_commit(struct hostapd_data *hapd)
  496. {
  497. if (hapd->driver == NULL || hapd->driver->commit == NULL)
  498. return 0;
  499. return hapd->driver->commit(hapd->drv_priv);
  500. }
  501. int hostapd_drv_none(struct hostapd_data *hapd)
  502. {
  503. return hapd->driver && os_strcmp(hapd->driver->name, "none") == 0;
  504. }
  505. int hostapd_driver_scan(struct hostapd_data *hapd,
  506. struct wpa_driver_scan_params *params)
  507. {
  508. if (hapd->driver && hapd->driver->scan2)
  509. return hapd->driver->scan2(hapd->drv_priv, params);
  510. return -1;
  511. }
  512. struct wpa_scan_results * hostapd_driver_get_scan_results(
  513. struct hostapd_data *hapd)
  514. {
  515. if (hapd->driver && hapd->driver->get_scan_results2)
  516. return hapd->driver->get_scan_results2(hapd->drv_priv);
  517. return NULL;
  518. }
  519. int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
  520. int duration)
  521. {
  522. if (hapd->driver && hapd->driver->set_noa)
  523. return hapd->driver->set_noa(hapd->drv_priv, count, start,
  524. duration);
  525. return -1;
  526. }
  527. int hostapd_drv_set_key(const char *ifname, struct hostapd_data *hapd,
  528. enum wpa_alg alg, const u8 *addr,
  529. int key_idx, int set_tx,
  530. const u8 *seq, size_t seq_len,
  531. const u8 *key, size_t key_len)
  532. {
  533. if (hapd->driver == NULL || hapd->driver->set_key == NULL)
  534. return 0;
  535. return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
  536. key_idx, set_tx, seq, seq_len, key,
  537. key_len);
  538. }
  539. int hostapd_drv_send_mlme(struct hostapd_data *hapd,
  540. const void *msg, size_t len, int noack)
  541. {
  542. if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
  543. return 0;
  544. return hapd->driver->send_mlme(hapd->drv_priv, msg, len, noack);
  545. }
  546. int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
  547. const u8 *addr, int reason)
  548. {
  549. if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
  550. return 0;
  551. return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
  552. reason);
  553. }
  554. int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
  555. const u8 *addr, int reason)
  556. {
  557. if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
  558. return 0;
  559. return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
  560. reason);
  561. }
  562. int hostapd_drv_wnm_oper(struct hostapd_data *hapd, enum wnm_oper oper,
  563. const u8 *peer, u8 *buf, u16 *buf_len)
  564. {
  565. if (hapd->driver == NULL || hapd->driver->wnm_oper == NULL)
  566. return 0;
  567. return hapd->driver->wnm_oper(hapd->drv_priv, oper, peer, buf,
  568. buf_len);
  569. }
  570. int hostapd_drv_send_action(struct hostapd_data *hapd, unsigned int freq,
  571. unsigned int wait, const u8 *dst, const u8 *data,
  572. size_t len)
  573. {
  574. if (hapd->driver == NULL || hapd->driver->send_action == NULL)
  575. return 0;
  576. return hapd->driver->send_action(hapd->drv_priv, freq, wait, dst,
  577. hapd->own_addr, hapd->own_addr, data,
  578. len, 0);
  579. }