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 software may be distributed under the terms of the BSD license.
8 * See README for more details.
11 #include "utils/includes.h"
13 #ifndef CONFIG_NATIVE_WINDOWS
15 #include "utils/common.h"
16 #include "common/ieee802_11_defs.h"
17 #include "common/ieee802_11_common.h"
18 #include "wps/wps_defs.h"
21 #include "ieee802_11.h"
24 #include "ap_config.h"
26 #include "p2p_hostapd.h"
27 #include "ap_drv_ops.h"
35 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
37 #ifdef CONFIG_TESTING_OPTIONS
38 if (hapd->conf->bss_load_test_set) {
41 *eid++ = WLAN_EID_BSS_LOAD;
43 os_memcpy(eid, hapd->conf->bss_load_test, 5);
46 #endif /* CONFIG_TESTING_OPTIONS */
51 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
55 if (hapd->iface->current_mode == NULL ||
56 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
59 if (hapd->iface->olbc)
60 erp |= ERP_INFO_USE_PROTECTION;
61 if (hapd->iface->num_sta_non_erp > 0) {
62 erp |= ERP_INFO_NON_ERP_PRESENT |
63 ERP_INFO_USE_PROTECTION;
65 if (hapd->iface->num_sta_no_short_preamble > 0 ||
66 hapd->iconf->preamble == LONG_PREAMBLE)
67 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
73 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
75 *eid++ = WLAN_EID_DS_PARAMS;
77 *eid++ = hapd->iconf->channel;
82 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
84 if (hapd->iface->current_mode == NULL ||
85 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
88 /* Set NonERP_present and use_protection bits if there
89 * are any associated NonERP stations. */
90 /* TODO: use_protection bit can be set to zero even if
91 * there are NonERP stations present. This optimization
92 * might be useful if NonERP stations are "quiet".
93 * See 802.11g/D6 E-1 for recommended practice.
94 * In addition, Non ERP present might be set, if AP detects Non ERP
95 * operation on other APs. */
97 /* Add ERP Information element */
98 *eid++ = WLAN_EID_ERP_INFO;
100 *eid++ = ieee802_11_erp_info(hapd);
106 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
109 u8 local_pwr_constraint = 0;
112 if (hapd->iface->current_mode == NULL ||
113 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
117 * There is no DFS support and power constraint was not directly
118 * requested by config option.
120 if (!hapd->iconf->ieee80211h &&
121 hapd->iconf->local_pwr_constraint == -1)
124 /* Check if DFS is required by regulatory. */
125 dfs = hostapd_is_dfs_required(hapd->iface);
127 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
132 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
136 * ieee80211h (DFS) is enabled so Power Constraint element shall
137 * be added when running on DFS channel whenever local_pwr_constraint
138 * is configured or not. In order to meet regulations when TPC is not
139 * implemented using a transmit power that is below the legal maximum
140 * (including any mitigation factor) should help. In this case,
141 * indicate 3 dB below maximum allowed transmit power.
143 if (hapd->iconf->local_pwr_constraint == -1)
144 local_pwr_constraint = 3;
147 * A STA that is not an AP shall use a transmit power less than or
148 * equal to the local maximum transmit power level for the channel.
149 * The local maximum transmit power can be calculated from the formula:
150 * local max TX pwr = max TX pwr - local pwr constraint
151 * Where max TX pwr is maximum transmit power level specified for
152 * channel in Country element and local pwr constraint is specified
153 * for channel in this Power Constraint element.
157 *pos++ = WLAN_EID_PWR_CONSTRAINT;
160 /* Local Power Constraint */
161 if (local_pwr_constraint)
162 *pos++ = local_pwr_constraint;
164 *pos++ = hapd->iconf->local_pwr_constraint;
170 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
171 struct hostapd_channel_data *start,
172 struct hostapd_channel_data *prev)
177 /* first channel number */
178 *pos++ = start->chan;
179 /* number of channels */
180 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
181 /* maximum transmit power level */
182 *pos++ = start->max_tx_power;
188 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
192 u8 *end = eid + max_len;
194 struct hostapd_hw_modes *mode;
195 struct hostapd_channel_data *start, *prev;
196 int chan_spacing = 1;
198 if (!hapd->iconf->ieee80211d || max_len < 6 ||
199 hapd->iface->current_mode == NULL)
202 *pos++ = WLAN_EID_COUNTRY;
203 pos++; /* length will be set later */
204 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
207 mode = hapd->iface->current_mode;
208 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
212 for (i = 0; i < mode->num_channels; i++) {
213 struct hostapd_channel_data *chan = &mode->channels[i];
214 if (chan->flag & HOSTAPD_CHAN_DISABLED)
217 prev->chan + chan_spacing == chan->chan &&
218 start->max_tx_power == chan->max_tx_power) {
220 continue; /* can use same entry */
224 pos = hostapd_eid_country_add(pos, end, chan_spacing,
229 /* Start new group */
234 pos = hostapd_eid_country_add(pos, end, chan_spacing,
238 if ((pos - eid) & 1) {
241 *pos++ = 0; /* pad for 16-bit alignment */
244 eid[1] = (pos - eid) - 2;
250 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
255 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
256 if (ie == NULL || ielen > len)
259 os_memcpy(eid, ie, ielen);
264 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
268 if (!hapd->iface->cs_freq_params.freq)
271 if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
275 *eid++ = WLAN_EID_CHANNEL_SWITCH;
277 *eid++ = hapd->iface->cs_block_tx;
279 *eid++ = hapd->iface->cs_count;
285 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
289 if (!hapd->iface->cs_freq_params.sec_channel_offset)
292 if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
293 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
294 else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
295 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
299 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
307 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
308 u8 *start, unsigned int *csa_counter_off)
312 if (!csa_counter_off)
315 *csa_counter_off = 0;
316 pos = hostapd_eid_csa(hapd, pos);
318 if (pos != old_pos) {
319 /* save an offset to the counter - should be last byte */
320 *csa_counter_off = pos - start - 1;
321 pos = hostapd_eid_secondary_channel(hapd, pos);
328 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
329 struct sta_info *sta,
330 const struct ieee80211_mgmt *req,
331 int is_p2p, size_t *resp_len)
333 struct ieee80211_mgmt *resp;
337 #define MAX_PROBERESP_LEN 768
338 buflen = MAX_PROBERESP_LEN;
340 if (hapd->wps_probe_resp_ie)
341 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
342 #endif /* CONFIG_WPS */
344 if (hapd->p2p_probe_resp_ie)
345 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
346 #endif /* CONFIG_P2P */
347 if (hapd->conf->vendor_elements)
348 buflen += wpabuf_len(hapd->conf->vendor_elements);
349 resp = os_zalloc(buflen);
353 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
355 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
356 WLAN_FC_STYPE_PROBE_RESP);
358 os_memcpy(resp->da, req->sa, ETH_ALEN);
359 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
361 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
362 resp->u.probe_resp.beacon_int =
363 host_to_le16(hapd->iconf->beacon_int);
365 /* hardware or low-level driver will setup seq_ctrl and timestamp */
366 resp->u.probe_resp.capab_info =
367 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
369 pos = resp->u.probe_resp.variable;
370 *pos++ = WLAN_EID_SSID;
371 *pos++ = hapd->conf->ssid.ssid_len;
372 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
373 pos += hapd->conf->ssid.ssid_len;
375 /* Supported rates */
376 pos = hostapd_eid_supp_rates(hapd, pos);
379 pos = hostapd_eid_ds_params(hapd, pos);
381 pos = hostapd_eid_country(hapd, pos, epos - pos);
383 /* Power Constraint element */
384 pos = hostapd_eid_pwr_constraint(hapd, pos);
386 /* ERP Information element */
387 pos = hostapd_eid_erp_info(hapd, pos);
389 /* Extended supported rates */
390 pos = hostapd_eid_ext_supp_rates(hapd, pos);
393 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
395 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
397 #ifdef CONFIG_IEEE80211N
398 pos = hostapd_eid_ht_capabilities(hapd, pos);
399 pos = hostapd_eid_ht_operation(hapd, pos);
400 #endif /* CONFIG_IEEE80211N */
402 pos = hostapd_eid_ext_capab(hapd, pos);
404 pos = hostapd_eid_time_adv(hapd, pos);
405 pos = hostapd_eid_time_zone(hapd, pos);
407 pos = hostapd_eid_interworking(hapd, pos);
408 pos = hostapd_eid_adv_proto(hapd, pos);
409 pos = hostapd_eid_roaming_consortium(hapd, pos);
411 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
412 &hapd->iface->cs_c_off_proberesp);
413 #ifdef CONFIG_IEEE80211AC
414 pos = hostapd_eid_vht_capabilities(hapd, pos);
415 pos = hostapd_eid_vht_operation(hapd, pos);
416 #endif /* CONFIG_IEEE80211AC */
418 /* Wi-Fi Alliance WMM */
419 pos = hostapd_eid_wmm(hapd, pos);
422 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
423 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
424 wpabuf_len(hapd->wps_probe_resp_ie));
425 pos += wpabuf_len(hapd->wps_probe_resp_ie);
427 #endif /* CONFIG_WPS */
430 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
431 hapd->p2p_probe_resp_ie) {
432 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
433 wpabuf_len(hapd->p2p_probe_resp_ie));
434 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
436 #endif /* CONFIG_P2P */
437 #ifdef CONFIG_P2P_MANAGER
438 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
440 pos = hostapd_eid_p2p_manage(hapd, pos);
441 #endif /* CONFIG_P2P_MANAGER */
444 pos = hostapd_eid_hs20_indication(hapd, pos);
445 #endif /* CONFIG_HS20 */
447 if (hapd->conf->vendor_elements) {
448 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
449 wpabuf_len(hapd->conf->vendor_elements));
450 pos += wpabuf_len(hapd->conf->vendor_elements);
453 *resp_len = pos - (u8 *) resp;
458 enum ssid_match_result {
464 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
465 const u8 *ssid, size_t ssid_len,
467 size_t ssid_list_len)
474 if (ssid_len == hapd->conf->ssid.ssid_len &&
475 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
476 return EXACT_SSID_MATCH;
478 if (ssid_list == NULL)
479 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
482 end = ssid_list + ssid_list_len;
483 while (pos + 1 <= end) {
484 if (pos + 2 + pos[1] > end)
488 if (pos[1] == hapd->conf->ssid.ssid_len &&
489 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
490 return EXACT_SSID_MATCH;
494 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
498 void handle_probe_req(struct hostapd_data *hapd,
499 const struct ieee80211_mgmt *mgmt, size_t len,
503 struct ieee802_11_elems elems;
506 struct sta_info *sta = NULL;
509 enum ssid_match_result res;
511 ie = mgmt->u.probe_req.variable;
512 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
514 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
516 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
517 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
518 mgmt->sa, mgmt->da, mgmt->bssid,
519 ie, ie_len, ssi_signal) > 0)
522 if (!hapd->iconf->send_probe_response)
525 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
526 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
531 if ((!elems.ssid || !elems.supp_rates)) {
532 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
533 "without SSID or supported rates element",
539 if (hapd->p2p && elems.wps_ie) {
541 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
542 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
543 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
544 "due to mismatch with Requested Device "
552 if (hapd->p2p && elems.p2p) {
554 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
555 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
556 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
557 "due to mismatch with Device ID");
563 #endif /* CONFIG_P2P */
565 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
566 elems.ssid_list_len == 0) {
567 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
568 "broadcast SSID ignored", MAC2STR(mgmt->sa));
572 sta = ap_get_sta(hapd, mgmt->sa);
575 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
576 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
577 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
578 P2P_WILDCARD_SSID_LEN) == 0) {
579 /* Process P2P Wildcard SSID like Wildcard SSID */
582 #endif /* CONFIG_P2P */
584 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
585 elems.ssid_list, elems.ssid_list_len);
586 if (res != NO_SSID_MATCH) {
588 sta->ssid_probe = &hapd->conf->ssid;
590 if (!(mgmt->da[0] & 0x01)) {
591 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
592 " for foreign SSID '%s' (DA " MACSTR ")%s",
594 wpa_ssid_txt(elems.ssid, elems.ssid_len),
596 elems.ssid_list ? " (SSID list)" : "");
601 #ifdef CONFIG_INTERWORKING
602 if (elems.interworking && elems.interworking_len >= 1) {
603 u8 ant = elems.interworking[0] & 0x0f;
604 if (ant != INTERWORKING_ANT_WILDCARD &&
605 ant != hapd->conf->access_network_type) {
606 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
607 " for mismatching ANT %u ignored",
608 MAC2STR(mgmt->sa), ant);
613 if (elems.interworking &&
614 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
616 if (elems.interworking_len == 7)
617 hessid = elems.interworking + 1;
619 hessid = elems.interworking + 1 + 2;
620 if (!is_broadcast_ether_addr(hessid) &&
621 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
622 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
623 " for mismatching HESSID " MACSTR
625 MAC2STR(mgmt->sa), MAC2STR(hessid));
629 #endif /* CONFIG_INTERWORKING */
632 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
633 supp_rates_11b_only(&elems)) {
634 /* Indicates support for 11b rates only */
635 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
636 MACSTR " with only 802.11b rates",
640 #endif /* CONFIG_P2P */
642 /* TODO: verify that supp_rates contains at least one matching rate
643 * with AP configuration */
645 #ifdef CONFIG_TESTING_OPTIONS
646 if (hapd->iconf->ignore_probe_probability > 0.0d &&
647 drand48() < hapd->iconf->ignore_probe_probability) {
649 "TESTING: ignoring probe request from " MACSTR,
653 #endif /* CONFIG_TESTING_OPTIONS */
655 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
661 * If this is a broadcast probe request, apply no ack policy to avoid
664 noack = !!(res == WILDCARD_SSID_MATCH &&
665 is_broadcast_ether_addr(mgmt->da));
667 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
668 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
672 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
673 "SSID", MAC2STR(mgmt->sa),
674 elems.ssid_len == 0 ? "broadcast" : "our");
678 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
681 /* check probe response offloading caps and print warnings */
682 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
686 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
687 (!(hapd->iface->probe_resp_offloads &
688 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
689 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
690 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
691 "Probe Response while not supporting this");
692 #endif /* CONFIG_WPS */
695 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
696 !(hapd->iface->probe_resp_offloads &
697 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
698 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
699 "Probe Response while not supporting this");
700 #endif /* CONFIG_P2P */
702 if (hapd->conf->interworking &&
703 !(hapd->iface->probe_resp_offloads &
704 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
705 wpa_printf(MSG_WARNING, "Device is trying to offload "
706 "Interworking Probe Response while not supporting "
709 /* Generate a Probe Response template for the non-P2P case */
710 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
713 #endif /* NEED_AP_MLME */
716 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
717 struct wpa_driver_ap_params *params)
719 struct ieee80211_mgmt *head = NULL;
721 size_t head_len = 0, tail_len = 0;
728 #define BEACON_HEAD_BUF_SIZE 256
729 #define BEACON_TAIL_BUF_SIZE 512
730 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
731 tail_len = BEACON_TAIL_BUF_SIZE;
733 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
734 tail_len += wpabuf_len(hapd->wps_beacon_ie);
735 #endif /* CONFIG_WPS */
737 if (hapd->p2p_beacon_ie)
738 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
739 #endif /* CONFIG_P2P */
740 if (hapd->conf->vendor_elements)
741 tail_len += wpabuf_len(hapd->conf->vendor_elements);
742 tailpos = tail = os_malloc(tail_len);
743 if (head == NULL || tail == NULL) {
744 wpa_printf(MSG_ERROR, "Failed to set beacon data");
750 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
751 WLAN_FC_STYPE_BEACON);
752 head->duration = host_to_le16(0);
753 os_memset(head->da, 0xff, ETH_ALEN);
755 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
756 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
757 head->u.beacon.beacon_int =
758 host_to_le16(hapd->iconf->beacon_int);
760 /* hardware or low-level driver will setup seq_ctrl and timestamp */
761 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
762 head->u.beacon.capab_info = host_to_le16(capab_info);
763 pos = &head->u.beacon.variable[0];
766 *pos++ = WLAN_EID_SSID;
767 if (hapd->conf->ignore_broadcast_ssid == 2) {
768 /* clear the data, but keep the correct length of the SSID */
769 *pos++ = hapd->conf->ssid.ssid_len;
770 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
771 pos += hapd->conf->ssid.ssid_len;
772 } else if (hapd->conf->ignore_broadcast_ssid) {
773 *pos++ = 0; /* empty SSID */
775 *pos++ = hapd->conf->ssid.ssid_len;
776 os_memcpy(pos, hapd->conf->ssid.ssid,
777 hapd->conf->ssid.ssid_len);
778 pos += hapd->conf->ssid.ssid_len;
781 /* Supported rates */
782 pos = hostapd_eid_supp_rates(hapd, pos);
785 pos = hostapd_eid_ds_params(hapd, pos);
787 head_len = pos - (u8 *) head;
789 tailpos = hostapd_eid_country(hapd, tailpos,
790 tail + BEACON_TAIL_BUF_SIZE - tailpos);
792 /* Power Constraint element */
793 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
795 /* ERP Information element */
796 tailpos = hostapd_eid_erp_info(hapd, tailpos);
798 /* Extended supported rates */
799 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
802 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
805 tailpos = hostapd_eid_bss_load(hapd, tailpos,
806 tail + BEACON_TAIL_BUF_SIZE - tailpos);
808 #ifdef CONFIG_IEEE80211N
809 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
810 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
811 #endif /* CONFIG_IEEE80211N */
813 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
816 * TODO: Time Advertisement element should only be included in some
817 * DTIM Beacon frames.
819 tailpos = hostapd_eid_time_adv(hapd, tailpos);
821 tailpos = hostapd_eid_interworking(hapd, tailpos);
822 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
823 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
824 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
825 &hapd->iface->cs_c_off_beacon);
826 #ifdef CONFIG_IEEE80211AC
827 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
828 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
829 #endif /* CONFIG_IEEE80211AC */
831 /* Wi-Fi Alliance WMM */
832 tailpos = hostapd_eid_wmm(hapd, tailpos);
835 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
836 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
837 wpabuf_len(hapd->wps_beacon_ie));
838 tailpos += wpabuf_len(hapd->wps_beacon_ie);
840 #endif /* CONFIG_WPS */
843 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
844 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
845 wpabuf_len(hapd->p2p_beacon_ie));
846 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
848 #endif /* CONFIG_P2P */
849 #ifdef CONFIG_P2P_MANAGER
850 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
852 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
853 #endif /* CONFIG_P2P_MANAGER */
856 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
857 #endif /* CONFIG_HS20 */
859 if (hapd->conf->vendor_elements) {
860 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
861 wpabuf_len(hapd->conf->vendor_elements));
862 tailpos += wpabuf_len(hapd->conf->vendor_elements);
865 tail_len = tailpos > tail ? tailpos - tail : 0;
867 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
868 #endif /* NEED_AP_MLME */
870 os_memset(params, 0, sizeof(*params));
871 params->head = (u8 *) head;
872 params->head_len = head_len;
874 params->tail_len = tail_len;
875 params->proberesp = resp;
876 params->proberesp_len = resp_len;
877 params->dtim_period = hapd->conf->dtim_period;
878 params->beacon_int = hapd->iconf->beacon_int;
879 params->basic_rates = hapd->iface->basic_rates;
880 params->ssid = hapd->conf->ssid.ssid;
881 params->ssid_len = hapd->conf->ssid.ssid_len;
882 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
883 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
884 params->group_cipher = hapd->conf->wpa_group;
885 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
886 params->auth_algs = hapd->conf->auth_algs;
887 params->wpa_version = hapd->conf->wpa;
888 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
889 (hapd->conf->ieee802_1x &&
890 (hapd->conf->default_wep_key_len ||
891 hapd->conf->individual_wep_key_len));
892 switch (hapd->conf->ignore_broadcast_ssid) {
894 params->hide_ssid = NO_SSID_HIDING;
897 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
900 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
903 params->isolate = hapd->conf->isolate;
905 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
906 ERP_INFO_USE_PROTECTION);
907 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
908 hapd->iconf->preamble == SHORT_PREAMBLE;
909 if (hapd->iface->current_mode &&
910 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
911 params->short_slot_time =
912 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
914 params->short_slot_time = -1;
915 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
916 params->ht_opmode = -1;
918 params->ht_opmode = hapd->iface->ht_op_mode;
919 #endif /* NEED_AP_MLME */
920 params->interworking = hapd->conf->interworking;
921 if (hapd->conf->interworking &&
922 !is_zero_ether_addr(hapd->conf->hessid))
923 params->hessid = hapd->conf->hessid;
924 params->access_network_type = hapd->conf->access_network_type;
925 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
927 params->disable_dgaf = hapd->conf->disable_dgaf;
928 #endif /* CONFIG_HS20 */
933 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
935 os_free(params->tail);
937 os_free(params->head);
939 os_free(params->proberesp);
940 params->proberesp = NULL;
944 int ieee802_11_set_beacon(struct hostapd_data *hapd)
946 struct wpa_driver_ap_params params;
947 struct wpabuf *beacon, *proberesp, *assocresp;
950 if (hapd->iface->csa_in_progress) {
951 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
955 hapd->beacon_set_done = 1;
957 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
960 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
964 params.beacon_ies = beacon;
965 params.proberesp_ies = proberesp;
966 params.assocresp_ies = assocresp;
968 res = hostapd_drv_set_ap(hapd, ¶ms);
969 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
971 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
975 ieee802_11_free_ap_params(¶ms);
980 int ieee802_11_set_beacons(struct hostapd_iface *iface)
985 for (i = 0; i < iface->num_bss; i++) {
986 if (iface->bss[i]->started &&
987 ieee802_11_set_beacon(iface->bss[i]) < 0)
995 /* only update beacons if started */
996 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1001 for (i = 0; i < iface->num_bss; i++) {
1002 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1003 ieee802_11_set_beacon(iface->bss[i]) < 0)
1010 #endif /* CONFIG_NATIVE_WINDOWS */