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-2012, Jouni Malinen <j@w1.fi>
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.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
17 #include "utils/includes.h"
19 #ifndef CONFIG_NATIVE_WINDOWS
21 #include "utils/common.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/ieee802_11_common.h"
24 #include "drivers/driver.h"
25 #include "wps/wps_defs.h"
28 #include "ieee802_11.h"
31 #include "ap_config.h"
33 #include "p2p_hostapd.h"
34 #include "ap_drv_ops.h"
41 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
43 #ifdef CONFIG_TESTING_OPTIONS
44 if (hapd->conf->bss_load_test_set) {
47 *eid++ = WLAN_EID_BSS_LOAD;
49 os_memcpy(eid, hapd->conf->bss_load_test, 5);
52 #endif /* CONFIG_TESTING_OPTIONS */
57 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
61 if (hapd->iface->current_mode == NULL ||
62 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
65 if (hapd->iface->olbc)
66 erp |= ERP_INFO_USE_PROTECTION;
67 if (hapd->iface->num_sta_non_erp > 0) {
68 erp |= ERP_INFO_NON_ERP_PRESENT |
69 ERP_INFO_USE_PROTECTION;
71 if (hapd->iface->num_sta_no_short_preamble > 0 ||
72 hapd->iconf->preamble == LONG_PREAMBLE)
73 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
79 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
81 *eid++ = WLAN_EID_DS_PARAMS;
83 *eid++ = hapd->iconf->channel;
88 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
90 if (hapd->iface->current_mode == NULL ||
91 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
94 /* Set NonERP_present and use_protection bits if there
95 * are any associated NonERP stations. */
96 /* TODO: use_protection bit can be set to zero even if
97 * there are NonERP stations present. This optimization
98 * might be useful if NonERP stations are "quiet".
99 * See 802.11g/D6 E-1 for recommended practice.
100 * In addition, Non ERP present might be set, if AP detects Non ERP
101 * operation on other APs. */
103 /* Add ERP Information element */
104 *eid++ = WLAN_EID_ERP_INFO;
106 *eid++ = ieee802_11_erp_info(hapd);
112 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
113 struct hostapd_channel_data *start,
114 struct hostapd_channel_data *prev)
119 /* first channel number */
120 *pos++ = start->chan;
121 /* number of channels */
122 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
123 /* maximum transmit power level */
124 *pos++ = start->max_tx_power;
130 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
134 u8 *end = eid + max_len;
136 struct hostapd_hw_modes *mode;
137 struct hostapd_channel_data *start, *prev;
138 int chan_spacing = 1;
140 if (!hapd->iconf->ieee80211d || max_len < 6 ||
141 hapd->iface->current_mode == NULL)
144 *pos++ = WLAN_EID_COUNTRY;
145 pos++; /* length will be set later */
146 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
149 mode = hapd->iface->current_mode;
150 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
154 for (i = 0; i < mode->num_channels; i++) {
155 struct hostapd_channel_data *chan = &mode->channels[i];
156 if (chan->flag & HOSTAPD_CHAN_DISABLED)
159 prev->chan + chan_spacing == chan->chan &&
160 start->max_tx_power == chan->max_tx_power) {
162 continue; /* can use same entry */
166 pos = hostapd_eid_country_add(pos, end, chan_spacing,
171 /* Start new group */
176 pos = hostapd_eid_country_add(pos, end, chan_spacing,
180 if ((pos - eid) & 1) {
183 *pos++ = 0; /* pad for 16-bit alignment */
186 eid[1] = (pos - eid) - 2;
192 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
197 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
198 if (ie == NULL || ielen > len)
201 os_memcpy(eid, ie, ielen);
206 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
207 struct sta_info *sta,
208 const struct ieee80211_mgmt *req,
209 int is_p2p, size_t *resp_len)
211 struct ieee80211_mgmt *resp;
215 #define MAX_PROBERESP_LEN 768
216 buflen = MAX_PROBERESP_LEN;
218 if (hapd->wps_probe_resp_ie)
219 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
220 #endif /* CONFIG_WPS */
222 if (hapd->p2p_probe_resp_ie)
223 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
224 #endif /* CONFIG_P2P */
225 if (hapd->conf->vendor_elements)
226 buflen += wpabuf_len(hapd->conf->vendor_elements);
227 resp = os_zalloc(buflen);
231 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
233 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
234 WLAN_FC_STYPE_PROBE_RESP);
236 os_memcpy(resp->da, req->sa, ETH_ALEN);
237 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
239 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
240 resp->u.probe_resp.beacon_int =
241 host_to_le16(hapd->iconf->beacon_int);
243 /* hardware or low-level driver will setup seq_ctrl and timestamp */
244 resp->u.probe_resp.capab_info =
245 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
247 pos = resp->u.probe_resp.variable;
248 *pos++ = WLAN_EID_SSID;
249 *pos++ = hapd->conf->ssid.ssid_len;
250 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
251 pos += hapd->conf->ssid.ssid_len;
253 /* Supported rates */
254 pos = hostapd_eid_supp_rates(hapd, pos);
257 pos = hostapd_eid_ds_params(hapd, pos);
259 pos = hostapd_eid_country(hapd, pos, epos - pos);
261 /* ERP Information element */
262 pos = hostapd_eid_erp_info(hapd, pos);
264 /* Extended supported rates */
265 pos = hostapd_eid_ext_supp_rates(hapd, pos);
268 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
270 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
272 #ifdef CONFIG_IEEE80211N
273 pos = hostapd_eid_ht_capabilities(hapd, pos);
274 pos = hostapd_eid_ht_operation(hapd, pos);
275 #endif /* CONFIG_IEEE80211N */
277 pos = hostapd_eid_ext_capab(hapd, pos);
279 pos = hostapd_eid_time_adv(hapd, pos);
280 pos = hostapd_eid_time_zone(hapd, pos);
282 pos = hostapd_eid_interworking(hapd, pos);
283 pos = hostapd_eid_adv_proto(hapd, pos);
284 pos = hostapd_eid_roaming_consortium(hapd, pos);
286 #ifdef CONFIG_IEEE80211AC
287 pos = hostapd_eid_vht_capabilities(hapd, pos);
288 pos = hostapd_eid_vht_operation(hapd, pos);
289 #endif /* CONFIG_IEEE80211AC */
291 /* Wi-Fi Alliance WMM */
292 pos = hostapd_eid_wmm(hapd, pos);
295 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
296 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
297 wpabuf_len(hapd->wps_probe_resp_ie));
298 pos += wpabuf_len(hapd->wps_probe_resp_ie);
300 #endif /* CONFIG_WPS */
303 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
304 hapd->p2p_probe_resp_ie) {
305 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
306 wpabuf_len(hapd->p2p_probe_resp_ie));
307 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
309 #endif /* CONFIG_P2P */
310 #ifdef CONFIG_P2P_MANAGER
311 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
313 pos = hostapd_eid_p2p_manage(hapd, pos);
314 #endif /* CONFIG_P2P_MANAGER */
317 pos = hostapd_eid_hs20_indication(hapd, pos);
318 #endif /* CONFIG_HS20 */
320 if (hapd->conf->vendor_elements) {
321 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
322 wpabuf_len(hapd->conf->vendor_elements));
323 pos += wpabuf_len(hapd->conf->vendor_elements);
326 *resp_len = pos - (u8 *) resp;
331 enum ssid_match_result {
337 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
338 const u8 *ssid, size_t ssid_len,
340 size_t ssid_list_len)
347 if (ssid_len == hapd->conf->ssid.ssid_len &&
348 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
349 return EXACT_SSID_MATCH;
351 if (ssid_list == NULL)
352 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
355 end = ssid_list + ssid_list_len;
356 while (pos + 1 <= end) {
357 if (pos + 2 + pos[1] > end)
361 if (pos[1] == hapd->conf->ssid.ssid_len &&
362 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
363 return EXACT_SSID_MATCH;
367 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
371 void handle_probe_req(struct hostapd_data *hapd,
372 const struct ieee80211_mgmt *mgmt, size_t len,
376 struct ieee802_11_elems elems;
379 struct sta_info *sta = NULL;
382 enum ssid_match_result res;
384 ie = mgmt->u.probe_req.variable;
385 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
387 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
389 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
390 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
391 mgmt->sa, mgmt->da, mgmt->bssid,
392 ie, ie_len, ssi_signal) > 0)
395 if (!hapd->iconf->send_probe_response)
398 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
399 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
404 if ((!elems.ssid || !elems.supp_rates)) {
405 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
406 "without SSID or supported rates element",
412 if (hapd->p2p && elems.wps_ie) {
414 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
415 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
416 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
417 "due to mismatch with Requested Device "
425 if (hapd->p2p && elems.p2p) {
427 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
428 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
429 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
430 "due to mismatch with Device ID");
436 #endif /* CONFIG_P2P */
438 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
439 elems.ssid_list_len == 0) {
440 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
441 "broadcast SSID ignored", MAC2STR(mgmt->sa));
445 sta = ap_get_sta(hapd, mgmt->sa);
448 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
449 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
450 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
451 P2P_WILDCARD_SSID_LEN) == 0) {
452 /* Process P2P Wildcard SSID like Wildcard SSID */
455 #endif /* CONFIG_P2P */
457 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
458 elems.ssid_list, elems.ssid_list_len);
459 if (res != NO_SSID_MATCH) {
461 sta->ssid_probe = &hapd->conf->ssid;
463 if (!(mgmt->da[0] & 0x01)) {
465 ieee802_11_print_ssid(ssid_txt, elems.ssid,
467 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
468 " for foreign SSID '%s' (DA " MACSTR ")%s",
469 MAC2STR(mgmt->sa), ssid_txt,
471 elems.ssid_list ? " (SSID list)" : "");
476 #ifdef CONFIG_INTERWORKING
477 if (elems.interworking && elems.interworking_len >= 1) {
478 u8 ant = elems.interworking[0] & 0x0f;
479 if (ant != INTERWORKING_ANT_WILDCARD &&
480 ant != hapd->conf->access_network_type) {
481 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
482 " for mismatching ANT %u ignored",
483 MAC2STR(mgmt->sa), ant);
488 if (elems.interworking &&
489 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
491 if (elems.interworking_len == 7)
492 hessid = elems.interworking + 1;
494 hessid = elems.interworking + 1 + 2;
495 if (!is_broadcast_ether_addr(hessid) &&
496 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
497 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
498 " for mismatching HESSID " MACSTR
500 MAC2STR(mgmt->sa), MAC2STR(hessid));
504 #endif /* CONFIG_INTERWORKING */
507 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
508 supp_rates_11b_only(&elems)) {
509 /* Indicates support for 11b rates only */
510 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
511 MACSTR " with only 802.11b rates",
515 #endif /* CONFIG_P2P */
517 /* TODO: verify that supp_rates contains at least one matching rate
518 * with AP configuration */
520 #ifdef CONFIG_TESTING_OPTIONS
521 if (hapd->iconf->ignore_probe_probability > 0.0d &&
522 drand48() < hapd->iconf->ignore_probe_probability) {
524 "TESTING: ignoring probe request from " MACSTR,
528 #endif /* CONFIG_TESTING_OPTIONS */
530 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
536 * If this is a broadcast probe request, apply no ack policy to avoid
539 noack = !!(res == WILDCARD_SSID_MATCH &&
540 is_broadcast_ether_addr(mgmt->da));
542 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
543 perror("handle_probe_req: send");
547 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
548 "SSID", MAC2STR(mgmt->sa),
549 elems.ssid_len == 0 ? "broadcast" : "our");
553 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
556 /* check probe response offloading caps and print warnings */
557 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
561 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
562 (!(hapd->iface->probe_resp_offloads &
563 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
564 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
565 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
566 "Probe Response while not supporting this");
567 #endif /* CONFIG_WPS */
570 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
571 !(hapd->iface->probe_resp_offloads &
572 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
573 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
574 "Probe Response while not supporting this");
575 #endif /* CONFIG_P2P */
577 if (hapd->conf->interworking &&
578 !(hapd->iface->probe_resp_offloads &
579 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
580 wpa_printf(MSG_WARNING, "Device is trying to offload "
581 "Interworking Probe Response while not supporting "
584 /* Generate a Probe Response template for the non-P2P case */
585 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
588 #endif /* NEED_AP_MLME */
591 void ieee802_11_set_beacon(struct hostapd_data *hapd)
593 struct ieee80211_mgmt *head = NULL;
595 size_t head_len = 0, tail_len = 0;
598 struct wpa_driver_ap_params params;
599 struct wpabuf *beacon, *proberesp, *assocresp;
603 #endif /* NEED_AP_MLME */
605 hapd->beacon_set_done = 1;
609 #define BEACON_HEAD_BUF_SIZE 256
610 #define BEACON_TAIL_BUF_SIZE 512
611 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
612 tail_len = BEACON_TAIL_BUF_SIZE;
614 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
615 tail_len += wpabuf_len(hapd->wps_beacon_ie);
616 #endif /* CONFIG_WPS */
618 if (hapd->p2p_beacon_ie)
619 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
620 #endif /* CONFIG_P2P */
621 if (hapd->conf->vendor_elements)
622 tail_len += wpabuf_len(hapd->conf->vendor_elements);
623 tailpos = tail = os_malloc(tail_len);
624 if (head == NULL || tail == NULL) {
625 wpa_printf(MSG_ERROR, "Failed to set beacon data");
631 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
632 WLAN_FC_STYPE_BEACON);
633 head->duration = host_to_le16(0);
634 os_memset(head->da, 0xff, ETH_ALEN);
636 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
637 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
638 head->u.beacon.beacon_int =
639 host_to_le16(hapd->iconf->beacon_int);
641 /* hardware or low-level driver will setup seq_ctrl and timestamp */
642 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
643 head->u.beacon.capab_info = host_to_le16(capab_info);
644 pos = &head->u.beacon.variable[0];
647 *pos++ = WLAN_EID_SSID;
648 if (hapd->conf->ignore_broadcast_ssid == 2) {
649 /* clear the data, but keep the correct length of the SSID */
650 *pos++ = hapd->conf->ssid.ssid_len;
651 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
652 pos += hapd->conf->ssid.ssid_len;
653 } else if (hapd->conf->ignore_broadcast_ssid) {
654 *pos++ = 0; /* empty SSID */
656 *pos++ = hapd->conf->ssid.ssid_len;
657 os_memcpy(pos, hapd->conf->ssid.ssid,
658 hapd->conf->ssid.ssid_len);
659 pos += hapd->conf->ssid.ssid_len;
662 /* Supported rates */
663 pos = hostapd_eid_supp_rates(hapd, pos);
666 pos = hostapd_eid_ds_params(hapd, pos);
668 head_len = pos - (u8 *) head;
670 tailpos = hostapd_eid_country(hapd, tailpos,
671 tail + BEACON_TAIL_BUF_SIZE - tailpos);
673 /* ERP Information element */
674 tailpos = hostapd_eid_erp_info(hapd, tailpos);
676 /* Extended supported rates */
677 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
680 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
683 tailpos = hostapd_eid_bss_load(hapd, tailpos,
684 tail + BEACON_TAIL_BUF_SIZE - tailpos);
686 #ifdef CONFIG_IEEE80211N
687 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
688 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
689 #endif /* CONFIG_IEEE80211N */
691 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
694 * TODO: Time Advertisement element should only be included in some
695 * DTIM Beacon frames.
697 tailpos = hostapd_eid_time_adv(hapd, tailpos);
699 tailpos = hostapd_eid_interworking(hapd, tailpos);
700 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
701 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
703 #ifdef CONFIG_IEEE80211AC
704 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
705 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
706 #endif /* CONFIG_IEEE80211AC */
708 /* Wi-Fi Alliance WMM */
709 tailpos = hostapd_eid_wmm(hapd, tailpos);
712 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
713 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
714 wpabuf_len(hapd->wps_beacon_ie));
715 tailpos += wpabuf_len(hapd->wps_beacon_ie);
717 #endif /* CONFIG_WPS */
720 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
721 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
722 wpabuf_len(hapd->p2p_beacon_ie));
723 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
725 #endif /* CONFIG_P2P */
726 #ifdef CONFIG_P2P_MANAGER
727 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
729 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
730 #endif /* CONFIG_P2P_MANAGER */
733 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
734 #endif /* CONFIG_HS20 */
736 if (hapd->conf->vendor_elements) {
737 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
738 wpabuf_len(hapd->conf->vendor_elements));
739 tailpos += wpabuf_len(hapd->conf->vendor_elements);
742 tail_len = tailpos > tail ? tailpos - tail : 0;
744 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
745 #endif /* NEED_AP_MLME */
747 os_memset(¶ms, 0, sizeof(params));
748 params.head = (u8 *) head;
749 params.head_len = head_len;
751 params.tail_len = tail_len;
752 params.proberesp = resp;
753 params.proberesp_len = resp_len;
754 params.dtim_period = hapd->conf->dtim_period;
755 params.beacon_int = hapd->iconf->beacon_int;
756 params.basic_rates = hapd->iface->basic_rates;
757 params.ssid = hapd->conf->ssid.ssid;
758 params.ssid_len = hapd->conf->ssid.ssid_len;
759 params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
760 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
761 params.group_cipher = hapd->conf->wpa_group;
762 params.key_mgmt_suites = hapd->conf->wpa_key_mgmt;
763 params.auth_algs = hapd->conf->auth_algs;
764 params.wpa_version = hapd->conf->wpa;
765 params.privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
766 (hapd->conf->ieee802_1x &&
767 (hapd->conf->default_wep_key_len ||
768 hapd->conf->individual_wep_key_len));
769 switch (hapd->conf->ignore_broadcast_ssid) {
771 params.hide_ssid = NO_SSID_HIDING;
774 params.hide_ssid = HIDDEN_SSID_ZERO_LEN;
777 params.hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
780 hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp);
781 params.beacon_ies = beacon;
782 params.proberesp_ies = proberesp;
783 params.assocresp_ies = assocresp;
784 params.isolate = hapd->conf->isolate;
786 params.cts_protect = !!(ieee802_11_erp_info(hapd) &
787 ERP_INFO_USE_PROTECTION);
788 params.preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
789 hapd->iconf->preamble == SHORT_PREAMBLE;
790 if (hapd->iface->current_mode &&
791 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
792 params.short_slot_time =
793 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
795 params.short_slot_time = -1;
796 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
797 params.ht_opmode = -1;
799 params.ht_opmode = hapd->iface->ht_op_mode;
800 #endif /* NEED_AP_MLME */
801 params.interworking = hapd->conf->interworking;
802 if (hapd->conf->interworking &&
803 !is_zero_ether_addr(hapd->conf->hessid))
804 params.hessid = hapd->conf->hessid;
805 params.access_network_type = hapd->conf->access_network_type;
806 params.ap_max_inactivity = hapd->conf->ap_max_inactivity;
808 params.disable_dgaf = hapd->conf->disable_dgaf;
809 #endif /* CONFIG_HS20 */
810 if (hostapd_drv_set_ap(hapd, ¶ms))
811 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
812 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
820 void ieee802_11_set_beacons(struct hostapd_iface *iface)
823 for (i = 0; i < iface->num_bss; i++)
824 ieee802_11_set_beacon(iface->bss[i]);
828 /* only update beacons if started */
829 void ieee802_11_update_beacons(struct hostapd_iface *iface)
832 for (i = 0; i < iface->num_bss; i++)
833 if (iface->bss[i]->beacon_set_done)
834 ieee802_11_set_beacon(iface->bss[i]);
837 #endif /* CONFIG_NATIVE_WINDOWS */