beacon.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /*
  2. * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
  3. * Copyright (c) 2002-2004, Instant802 Networks, Inc.
  4. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  5. * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "utils/includes.h"
  17. #ifndef CONFIG_NATIVE_WINDOWS
  18. #include "utils/common.h"
  19. #include "common/ieee802_11_defs.h"
  20. #include "common/ieee802_11_common.h"
  21. #include "drivers/driver.h"
  22. #include "wps/wps_defs.h"
  23. #include "p2p/p2p.h"
  24. #include "hostapd.h"
  25. #include "ieee802_11.h"
  26. #include "wpa_auth.h"
  27. #include "wmm.h"
  28. #include "ap_config.h"
  29. #include "sta_info.h"
  30. #include "p2p_hostapd.h"
  31. #include "ap_drv_ops.h"
  32. #include "beacon.h"
  33. #ifdef NEED_AP_MLME
  34. static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
  35. {
  36. u8 erp = 0;
  37. if (hapd->iface->current_mode == NULL ||
  38. hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
  39. return 0;
  40. if (hapd->iface->olbc)
  41. erp |= ERP_INFO_USE_PROTECTION;
  42. if (hapd->iface->num_sta_non_erp > 0) {
  43. erp |= ERP_INFO_NON_ERP_PRESENT |
  44. ERP_INFO_USE_PROTECTION;
  45. }
  46. if (hapd->iface->num_sta_no_short_preamble > 0 ||
  47. hapd->iconf->preamble == LONG_PREAMBLE)
  48. erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
  49. return erp;
  50. }
  51. static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
  52. {
  53. *eid++ = WLAN_EID_DS_PARAMS;
  54. *eid++ = 1;
  55. *eid++ = hapd->iconf->channel;
  56. return eid;
  57. }
  58. static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
  59. {
  60. if (hapd->iface->current_mode == NULL ||
  61. hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
  62. return eid;
  63. /* Set NonERP_present and use_protection bits if there
  64. * are any associated NonERP stations. */
  65. /* TODO: use_protection bit can be set to zero even if
  66. * there are NonERP stations present. This optimization
  67. * might be useful if NonERP stations are "quiet".
  68. * See 802.11g/D6 E-1 for recommended practice.
  69. * In addition, Non ERP present might be set, if AP detects Non ERP
  70. * operation on other APs. */
  71. /* Add ERP Information element */
  72. *eid++ = WLAN_EID_ERP_INFO;
  73. *eid++ = 1;
  74. *eid++ = ieee802_11_erp_info(hapd);
  75. return eid;
  76. }
  77. static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
  78. struct hostapd_channel_data *start,
  79. struct hostapd_channel_data *prev)
  80. {
  81. if (end - pos < 3)
  82. return pos;
  83. /* first channel number */
  84. *pos++ = start->chan;
  85. /* number of channels */
  86. *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
  87. /* maximum transmit power level */
  88. *pos++ = start->max_tx_power;
  89. return pos;
  90. }
  91. static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
  92. int max_len)
  93. {
  94. u8 *pos = eid;
  95. u8 *end = eid + max_len;
  96. int i;
  97. struct hostapd_hw_modes *mode;
  98. struct hostapd_channel_data *start, *prev;
  99. int chan_spacing = 1;
  100. if (!hapd->iconf->ieee80211d || max_len < 6 ||
  101. hapd->iface->current_mode == NULL)
  102. return eid;
  103. *pos++ = WLAN_EID_COUNTRY;
  104. pos++; /* length will be set later */
  105. os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
  106. pos += 3;
  107. mode = hapd->iface->current_mode;
  108. if (mode->mode == HOSTAPD_MODE_IEEE80211A)
  109. chan_spacing = 4;
  110. start = prev = NULL;
  111. for (i = 0; i < mode->num_channels; i++) {
  112. struct hostapd_channel_data *chan = &mode->channels[i];
  113. if (chan->flag & HOSTAPD_CHAN_DISABLED)
  114. continue;
  115. if (start && prev &&
  116. prev->chan + chan_spacing == chan->chan &&
  117. start->max_tx_power == chan->max_tx_power) {
  118. prev = chan;
  119. continue; /* can use same entry */
  120. }
  121. if (start) {
  122. pos = hostapd_eid_country_add(pos, end, chan_spacing,
  123. start, prev);
  124. start = NULL;
  125. }
  126. /* Start new group */
  127. start = prev = chan;
  128. }
  129. if (start) {
  130. pos = hostapd_eid_country_add(pos, end, chan_spacing,
  131. start, prev);
  132. }
  133. if ((pos - eid) & 1) {
  134. if (end - pos < 1)
  135. return eid;
  136. *pos++ = 0; /* pad for 16-bit alignment */
  137. }
  138. eid[1] = (pos - eid) - 2;
  139. return pos;
  140. }
  141. static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
  142. {
  143. const u8 *ie;
  144. size_t ielen;
  145. ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
  146. if (ie == NULL || ielen > len)
  147. return eid;
  148. os_memcpy(eid, ie, ielen);
  149. return eid + ielen;
  150. }
  151. static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
  152. struct sta_info *sta,
  153. const struct ieee80211_mgmt *req,
  154. int is_p2p, size_t *resp_len)
  155. {
  156. struct ieee80211_mgmt *resp;
  157. u8 *pos, *epos;
  158. size_t buflen;
  159. #define MAX_PROBERESP_LEN 768
  160. buflen = MAX_PROBERESP_LEN;
  161. #ifdef CONFIG_WPS
  162. if (hapd->wps_probe_resp_ie)
  163. buflen += wpabuf_len(hapd->wps_probe_resp_ie);
  164. #endif /* CONFIG_WPS */
  165. #ifdef CONFIG_P2P
  166. if (hapd->p2p_probe_resp_ie)
  167. buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
  168. #endif /* CONFIG_P2P */
  169. resp = os_zalloc(buflen);
  170. if (resp == NULL)
  171. return NULL;
  172. epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
  173. resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  174. WLAN_FC_STYPE_PROBE_RESP);
  175. if (req)
  176. os_memcpy(resp->da, req->sa, ETH_ALEN);
  177. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  178. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  179. resp->u.probe_resp.beacon_int =
  180. host_to_le16(hapd->iconf->beacon_int);
  181. /* hardware or low-level driver will setup seq_ctrl and timestamp */
  182. resp->u.probe_resp.capab_info =
  183. host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
  184. pos = resp->u.probe_resp.variable;
  185. *pos++ = WLAN_EID_SSID;
  186. *pos++ = hapd->conf->ssid.ssid_len;
  187. os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
  188. pos += hapd->conf->ssid.ssid_len;
  189. /* Supported rates */
  190. pos = hostapd_eid_supp_rates(hapd, pos);
  191. /* DS Params */
  192. pos = hostapd_eid_ds_params(hapd, pos);
  193. pos = hostapd_eid_country(hapd, pos, epos - pos);
  194. /* ERP Information element */
  195. pos = hostapd_eid_erp_info(hapd, pos);
  196. /* Extended supported rates */
  197. pos = hostapd_eid_ext_supp_rates(hapd, pos);
  198. /* RSN, MDIE, WPA */
  199. pos = hostapd_eid_wpa(hapd, pos, epos - pos);
  200. #ifdef CONFIG_IEEE80211N
  201. pos = hostapd_eid_ht_capabilities(hapd, pos);
  202. pos = hostapd_eid_ht_operation(hapd, pos);
  203. #endif /* CONFIG_IEEE80211N */
  204. pos = hostapd_eid_ext_capab(hapd, pos);
  205. pos = hostapd_eid_time_adv(hapd, pos);
  206. pos = hostapd_eid_time_zone(hapd, pos);
  207. pos = hostapd_eid_interworking(hapd, pos);
  208. pos = hostapd_eid_adv_proto(hapd, pos);
  209. pos = hostapd_eid_roaming_consortium(hapd, pos);
  210. #ifdef CONFIG_IEEE80211AC
  211. pos = hostapd_eid_vht_capabilities(hapd, pos);
  212. pos = hostapd_eid_vht_operation(hapd, pos);
  213. #endif /* CONFIG_IEEE80211AC */
  214. /* Wi-Fi Alliance WMM */
  215. pos = hostapd_eid_wmm(hapd, pos);
  216. #ifdef CONFIG_WPS
  217. if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
  218. os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
  219. wpabuf_len(hapd->wps_probe_resp_ie));
  220. pos += wpabuf_len(hapd->wps_probe_resp_ie);
  221. }
  222. #endif /* CONFIG_WPS */
  223. #ifdef CONFIG_P2P
  224. if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
  225. hapd->p2p_probe_resp_ie) {
  226. os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
  227. wpabuf_len(hapd->p2p_probe_resp_ie));
  228. pos += wpabuf_len(hapd->p2p_probe_resp_ie);
  229. }
  230. #endif /* CONFIG_P2P */
  231. #ifdef CONFIG_P2P_MANAGER
  232. if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
  233. P2P_MANAGE)
  234. pos = hostapd_eid_p2p_manage(hapd, pos);
  235. #endif /* CONFIG_P2P_MANAGER */
  236. *resp_len = pos - (u8 *) resp;
  237. return (u8 *) resp;
  238. }
  239. void handle_probe_req(struct hostapd_data *hapd,
  240. const struct ieee80211_mgmt *mgmt, size_t len,
  241. int ssi_signal)
  242. {
  243. u8 *resp;
  244. struct ieee802_11_elems elems;
  245. const u8 *ie;
  246. size_t ie_len;
  247. struct sta_info *sta = NULL;
  248. size_t i, resp_len;
  249. int noack;
  250. ie = mgmt->u.probe_req.variable;
  251. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
  252. return;
  253. ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
  254. for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
  255. if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
  256. mgmt->sa, mgmt->da, mgmt->bssid,
  257. ie, ie_len, ssi_signal) > 0)
  258. return;
  259. if (!hapd->iconf->send_probe_response)
  260. return;
  261. if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
  262. wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
  263. MAC2STR(mgmt->sa));
  264. return;
  265. }
  266. if ((!elems.ssid || !elems.supp_rates)) {
  267. wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
  268. "without SSID or supported rates element",
  269. MAC2STR(mgmt->sa));
  270. return;
  271. }
  272. #ifdef CONFIG_P2P
  273. if (hapd->p2p && elems.wps_ie) {
  274. struct wpabuf *wps;
  275. wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
  276. if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
  277. wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
  278. "due to mismatch with Requested Device "
  279. "Type");
  280. wpabuf_free(wps);
  281. return;
  282. }
  283. wpabuf_free(wps);
  284. }
  285. if (hapd->p2p && elems.p2p) {
  286. struct wpabuf *p2p;
  287. p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
  288. if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
  289. wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
  290. "due to mismatch with Device ID");
  291. wpabuf_free(p2p);
  292. return;
  293. }
  294. wpabuf_free(p2p);
  295. }
  296. #endif /* CONFIG_P2P */
  297. if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0) {
  298. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
  299. "broadcast SSID ignored", MAC2STR(mgmt->sa));
  300. return;
  301. }
  302. sta = ap_get_sta(hapd, mgmt->sa);
  303. #ifdef CONFIG_P2P
  304. if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  305. elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
  306. os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
  307. P2P_WILDCARD_SSID_LEN) == 0) {
  308. /* Process P2P Wildcard SSID like Wildcard SSID */
  309. elems.ssid_len = 0;
  310. }
  311. #endif /* CONFIG_P2P */
  312. if (elems.ssid_len == 0 ||
  313. (elems.ssid_len == hapd->conf->ssid.ssid_len &&
  314. os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) ==
  315. 0)) {
  316. if (sta)
  317. sta->ssid_probe = &hapd->conf->ssid;
  318. } else {
  319. if (!(mgmt->da[0] & 0x01)) {
  320. char ssid_txt[33];
  321. ieee802_11_print_ssid(ssid_txt, elems.ssid,
  322. elems.ssid_len);
  323. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  324. " for foreign SSID '%s' (DA " MACSTR ")",
  325. MAC2STR(mgmt->sa), ssid_txt,
  326. MAC2STR(mgmt->da));
  327. }
  328. return;
  329. }
  330. #ifdef CONFIG_INTERWORKING
  331. if (elems.interworking && elems.interworking_len >= 1) {
  332. u8 ant = elems.interworking[0] & 0x0f;
  333. if (ant != INTERWORKING_ANT_WILDCARD &&
  334. ant != hapd->conf->access_network_type) {
  335. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  336. " for mismatching ANT %u ignored",
  337. MAC2STR(mgmt->sa), ant);
  338. return;
  339. }
  340. }
  341. if (elems.interworking &&
  342. (elems.interworking_len == 7 || elems.interworking_len == 9)) {
  343. const u8 *hessid;
  344. if (elems.interworking_len == 7)
  345. hessid = elems.interworking + 1;
  346. else
  347. hessid = elems.interworking + 1 + 2;
  348. if (!is_broadcast_ether_addr(hessid) &&
  349. os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
  350. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  351. " for mismatching HESSID " MACSTR
  352. " ignored",
  353. MAC2STR(mgmt->sa), MAC2STR(hessid));
  354. return;
  355. }
  356. }
  357. #endif /* CONFIG_INTERWORKING */
  358. /* TODO: verify that supp_rates contains at least one matching rate
  359. * with AP configuration */
  360. resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
  361. &resp_len);
  362. if (resp == NULL)
  363. return;
  364. /*
  365. * If this is a broadcast probe request, apply no ack policy to avoid
  366. * excessive retries.
  367. */
  368. noack = !!(elems.ssid_len == 0 && is_broadcast_ether_addr(mgmt->da));
  369. if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
  370. perror("handle_probe_req: send");
  371. os_free(resp);
  372. wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
  373. "SSID", MAC2STR(mgmt->sa),
  374. elems.ssid_len == 0 ? "broadcast" : "our");
  375. }
  376. static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
  377. size_t *resp_len)
  378. {
  379. /* check probe response offloading caps and print warnings */
  380. if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
  381. return NULL;
  382. #ifdef CONFIG_WPS
  383. if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
  384. (!(hapd->iface->probe_resp_offloads &
  385. (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
  386. WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
  387. wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
  388. "Probe Response while not supporting this");
  389. #endif /* CONFIG_WPS */
  390. #ifdef CONFIG_P2P
  391. if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
  392. !(hapd->iface->probe_resp_offloads &
  393. WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
  394. wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
  395. "Probe Response while not supporting this");
  396. #endif /* CONFIG_P2P */
  397. if (hapd->conf->interworking &&
  398. !(hapd->iface->probe_resp_offloads &
  399. WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
  400. wpa_printf(MSG_WARNING, "Device is trying to offload "
  401. "Interworking Probe Response while not supporting "
  402. "this");
  403. /* Generate a Probe Response template for the non-P2P case */
  404. return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
  405. }
  406. #endif /* NEED_AP_MLME */
  407. void ieee802_11_set_beacon(struct hostapd_data *hapd)
  408. {
  409. struct ieee80211_mgmt *head = NULL;
  410. u8 *tail = NULL;
  411. size_t head_len = 0, tail_len = 0;
  412. u8 *resp = NULL;
  413. size_t resp_len = 0;
  414. struct wpa_driver_ap_params params;
  415. struct wpabuf *beacon, *proberesp, *assocresp;
  416. #ifdef NEED_AP_MLME
  417. u16 capab_info;
  418. u8 *pos, *tailpos;
  419. #endif /* NEED_AP_MLME */
  420. hapd->beacon_set_done = 1;
  421. #ifdef NEED_AP_MLME
  422. #define BEACON_HEAD_BUF_SIZE 256
  423. #define BEACON_TAIL_BUF_SIZE 512
  424. head = os_zalloc(BEACON_HEAD_BUF_SIZE);
  425. tail_len = BEACON_TAIL_BUF_SIZE;
  426. #ifdef CONFIG_WPS
  427. if (hapd->conf->wps_state && hapd->wps_beacon_ie)
  428. tail_len += wpabuf_len(hapd->wps_beacon_ie);
  429. #endif /* CONFIG_WPS */
  430. #ifdef CONFIG_P2P
  431. if (hapd->p2p_beacon_ie)
  432. tail_len += wpabuf_len(hapd->p2p_beacon_ie);
  433. #endif /* CONFIG_P2P */
  434. tailpos = tail = os_malloc(tail_len);
  435. if (head == NULL || tail == NULL) {
  436. wpa_printf(MSG_ERROR, "Failed to set beacon data");
  437. os_free(head);
  438. os_free(tail);
  439. return;
  440. }
  441. head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  442. WLAN_FC_STYPE_BEACON);
  443. head->duration = host_to_le16(0);
  444. os_memset(head->da, 0xff, ETH_ALEN);
  445. os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
  446. os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
  447. head->u.beacon.beacon_int =
  448. host_to_le16(hapd->iconf->beacon_int);
  449. /* hardware or low-level driver will setup seq_ctrl and timestamp */
  450. capab_info = hostapd_own_capab_info(hapd, NULL, 0);
  451. head->u.beacon.capab_info = host_to_le16(capab_info);
  452. pos = &head->u.beacon.variable[0];
  453. /* SSID */
  454. *pos++ = WLAN_EID_SSID;
  455. if (hapd->conf->ignore_broadcast_ssid == 2) {
  456. /* clear the data, but keep the correct length of the SSID */
  457. *pos++ = hapd->conf->ssid.ssid_len;
  458. os_memset(pos, 0, hapd->conf->ssid.ssid_len);
  459. pos += hapd->conf->ssid.ssid_len;
  460. } else if (hapd->conf->ignore_broadcast_ssid) {
  461. *pos++ = 0; /* empty SSID */
  462. } else {
  463. *pos++ = hapd->conf->ssid.ssid_len;
  464. os_memcpy(pos, hapd->conf->ssid.ssid,
  465. hapd->conf->ssid.ssid_len);
  466. pos += hapd->conf->ssid.ssid_len;
  467. }
  468. /* Supported rates */
  469. pos = hostapd_eid_supp_rates(hapd, pos);
  470. /* DS Params */
  471. pos = hostapd_eid_ds_params(hapd, pos);
  472. head_len = pos - (u8 *) head;
  473. tailpos = hostapd_eid_country(hapd, tailpos,
  474. tail + BEACON_TAIL_BUF_SIZE - tailpos);
  475. /* ERP Information element */
  476. tailpos = hostapd_eid_erp_info(hapd, tailpos);
  477. /* Extended supported rates */
  478. tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
  479. /* RSN, MDIE, WPA */
  480. tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
  481. tailpos);
  482. #ifdef CONFIG_IEEE80211N
  483. tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
  484. tailpos = hostapd_eid_ht_operation(hapd, tailpos);
  485. #endif /* CONFIG_IEEE80211N */
  486. tailpos = hostapd_eid_ext_capab(hapd, tailpos);
  487. /*
  488. * TODO: Time Advertisement element should only be included in some
  489. * DTIM Beacon frames.
  490. */
  491. tailpos = hostapd_eid_time_adv(hapd, tailpos);
  492. tailpos = hostapd_eid_interworking(hapd, tailpos);
  493. tailpos = hostapd_eid_adv_proto(hapd, tailpos);
  494. tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
  495. #ifdef CONFIG_IEEE80211AC
  496. tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
  497. tailpos = hostapd_eid_vht_operation(hapd, tailpos);
  498. #endif /* CONFIG_IEEE80211AC */
  499. /* Wi-Fi Alliance WMM */
  500. tailpos = hostapd_eid_wmm(hapd, tailpos);
  501. #ifdef CONFIG_WPS
  502. if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
  503. os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
  504. wpabuf_len(hapd->wps_beacon_ie));
  505. tailpos += wpabuf_len(hapd->wps_beacon_ie);
  506. }
  507. #endif /* CONFIG_WPS */
  508. #ifdef CONFIG_P2P
  509. if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
  510. os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
  511. wpabuf_len(hapd->p2p_beacon_ie));
  512. tailpos += wpabuf_len(hapd->p2p_beacon_ie);
  513. }
  514. #endif /* CONFIG_P2P */
  515. #ifdef CONFIG_P2P_MANAGER
  516. if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
  517. P2P_MANAGE)
  518. tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
  519. #endif /* CONFIG_P2P_MANAGER */
  520. tail_len = tailpos > tail ? tailpos - tail : 0;
  521. resp = hostapd_probe_resp_offloads(hapd, &resp_len);
  522. #endif /* NEED_AP_MLME */
  523. os_memset(&params, 0, sizeof(params));
  524. params.head = (u8 *) head;
  525. params.head_len = head_len;
  526. params.tail = tail;
  527. params.tail_len = tail_len;
  528. params.proberesp = resp;
  529. params.proberesp_len = resp_len;
  530. params.dtim_period = hapd->conf->dtim_period;
  531. params.beacon_int = hapd->iconf->beacon_int;
  532. params.basic_rates = hapd->iconf->basic_rates;
  533. params.ssid = (u8 *) hapd->conf->ssid.ssid;
  534. params.ssid_len = hapd->conf->ssid.ssid_len;
  535. params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
  536. hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
  537. params.group_cipher = hapd->conf->wpa_group;
  538. params.key_mgmt_suites = hapd->conf->wpa_key_mgmt;
  539. params.auth_algs = hapd->conf->auth_algs;
  540. params.wpa_version = hapd->conf->wpa;
  541. params.privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
  542. (hapd->conf->ieee802_1x &&
  543. (hapd->conf->default_wep_key_len ||
  544. hapd->conf->individual_wep_key_len));
  545. switch (hapd->conf->ignore_broadcast_ssid) {
  546. case 0:
  547. params.hide_ssid = NO_SSID_HIDING;
  548. break;
  549. case 1:
  550. params.hide_ssid = HIDDEN_SSID_ZERO_LEN;
  551. break;
  552. case 2:
  553. params.hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
  554. break;
  555. }
  556. hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp);
  557. params.beacon_ies = beacon;
  558. params.proberesp_ies = proberesp;
  559. params.assocresp_ies = assocresp;
  560. params.isolate = hapd->conf->isolate;
  561. #ifdef NEED_AP_MLME
  562. params.cts_protect = !!(ieee802_11_erp_info(hapd) &
  563. ERP_INFO_USE_PROTECTION);
  564. params.preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
  565. hapd->iconf->preamble == SHORT_PREAMBLE;
  566. if (hapd->iface->current_mode &&
  567. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  568. params.short_slot_time =
  569. hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
  570. else
  571. params.short_slot_time = -1;
  572. if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
  573. params.ht_opmode = -1;
  574. else
  575. params.ht_opmode = hapd->iface->ht_op_mode;
  576. #endif /* NEED_AP_MLME */
  577. params.interworking = hapd->conf->interworking;
  578. if (hapd->conf->interworking &&
  579. !is_zero_ether_addr(hapd->conf->hessid))
  580. params.hessid = hapd->conf->hessid;
  581. params.access_network_type = hapd->conf->access_network_type;
  582. params.ap_max_inactivity = hapd->conf->ap_max_inactivity;
  583. if (hostapd_drv_set_ap(hapd, &params))
  584. wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
  585. hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
  586. os_free(tail);
  587. os_free(head);
  588. os_free(resp);
  589. }
  590. void ieee802_11_set_beacons(struct hostapd_iface *iface)
  591. {
  592. size_t i;
  593. for (i = 0; i < iface->num_bss; i++)
  594. ieee802_11_set_beacon(iface->bss[i]);
  595. }
  596. /* only update beacons if started */
  597. void ieee802_11_update_beacons(struct hostapd_iface *iface)
  598. {
  599. size_t i;
  600. for (i = 0; i < iface->num_bss; i++)
  601. if (iface->bss[i]->beacon_set_done)
  602. ieee802_11_set_beacon(iface->bss[i]);
  603. }
  604. #endif /* CONFIG_NATIVE_WINDOWS */