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)
116 /* Let host drivers add this IE if DFS support is offloaded */
117 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
121 * There is no DFS support and power constraint was not directly
122 * requested by config option.
124 if (!hapd->iconf->ieee80211h &&
125 hapd->iconf->local_pwr_constraint == -1)
128 /* Check if DFS is required by regulatory. */
129 dfs = hostapd_is_dfs_required(hapd->iface);
131 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
136 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
140 * ieee80211h (DFS) is enabled so Power Constraint element shall
141 * be added when running on DFS channel whenever local_pwr_constraint
142 * is configured or not. In order to meet regulations when TPC is not
143 * implemented using a transmit power that is below the legal maximum
144 * (including any mitigation factor) should help. In this case,
145 * indicate 3 dB below maximum allowed transmit power.
147 if (hapd->iconf->local_pwr_constraint == -1)
148 local_pwr_constraint = 3;
151 * A STA that is not an AP shall use a transmit power less than or
152 * equal to the local maximum transmit power level for the channel.
153 * The local maximum transmit power can be calculated from the formula:
154 * local max TX pwr = max TX pwr - local pwr constraint
155 * Where max TX pwr is maximum transmit power level specified for
156 * channel in Country element and local pwr constraint is specified
157 * for channel in this Power Constraint element.
161 *pos++ = WLAN_EID_PWR_CONSTRAINT;
164 /* Local Power Constraint */
165 if (local_pwr_constraint)
166 *pos++ = local_pwr_constraint;
168 *pos++ = hapd->iconf->local_pwr_constraint;
174 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
175 struct hostapd_channel_data *start,
176 struct hostapd_channel_data *prev)
181 /* first channel number */
182 *pos++ = start->chan;
183 /* number of channels */
184 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
185 /* maximum transmit power level */
186 *pos++ = start->max_tx_power;
192 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
196 u8 *end = eid + max_len;
198 struct hostapd_hw_modes *mode;
199 struct hostapd_channel_data *start, *prev;
200 int chan_spacing = 1;
202 if (!hapd->iconf->ieee80211d || max_len < 6 ||
203 hapd->iface->current_mode == NULL)
206 *pos++ = WLAN_EID_COUNTRY;
207 pos++; /* length will be set later */
208 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
211 mode = hapd->iface->current_mode;
212 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
216 for (i = 0; i < mode->num_channels; i++) {
217 struct hostapd_channel_data *chan = &mode->channels[i];
218 if (chan->flag & HOSTAPD_CHAN_DISABLED)
221 prev->chan + chan_spacing == chan->chan &&
222 start->max_tx_power == chan->max_tx_power) {
224 continue; /* can use same entry */
228 pos = hostapd_eid_country_add(pos, end, chan_spacing,
233 /* Start new group */
238 pos = hostapd_eid_country_add(pos, end, chan_spacing,
242 if ((pos - eid) & 1) {
245 *pos++ = 0; /* pad for 16-bit alignment */
248 eid[1] = (pos - eid) - 2;
254 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
259 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
260 if (ie == NULL || ielen > len)
263 os_memcpy(eid, ie, ielen);
268 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
272 if (!hapd->cs_freq_params.freq)
275 if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) ==
279 *eid++ = WLAN_EID_CHANNEL_SWITCH;
281 *eid++ = hapd->cs_block_tx;
283 *eid++ = hapd->cs_count;
289 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
293 if (!hapd->cs_freq_params.sec_channel_offset)
296 if (hapd->cs_freq_params.sec_channel_offset == -1)
297 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
298 else if (hapd->cs_freq_params.sec_channel_offset == 1)
299 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
303 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
311 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
312 u8 *start, unsigned int *csa_counter_off)
316 if (!csa_counter_off)
319 *csa_counter_off = 0;
320 pos = hostapd_eid_csa(hapd, pos);
322 if (pos != old_pos) {
323 /* save an offset to the counter - should be last byte */
324 *csa_counter_off = pos - start - 1;
325 pos = hostapd_eid_secondary_channel(hapd, pos);
332 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
333 struct sta_info *sta,
334 const struct ieee80211_mgmt *req,
335 int is_p2p, size_t *resp_len)
337 struct ieee80211_mgmt *resp;
341 #define MAX_PROBERESP_LEN 768
342 buflen = MAX_PROBERESP_LEN;
344 if (hapd->wps_probe_resp_ie)
345 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
346 #endif /* CONFIG_WPS */
348 if (hapd->p2p_probe_resp_ie)
349 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
350 #endif /* CONFIG_P2P */
351 if (hapd->conf->vendor_elements)
352 buflen += wpabuf_len(hapd->conf->vendor_elements);
353 resp = os_zalloc(buflen);
357 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
359 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
360 WLAN_FC_STYPE_PROBE_RESP);
362 os_memcpy(resp->da, req->sa, ETH_ALEN);
363 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
365 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
366 resp->u.probe_resp.beacon_int =
367 host_to_le16(hapd->iconf->beacon_int);
369 /* hardware or low-level driver will setup seq_ctrl and timestamp */
370 resp->u.probe_resp.capab_info =
371 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
373 pos = resp->u.probe_resp.variable;
374 *pos++ = WLAN_EID_SSID;
375 *pos++ = hapd->conf->ssid.ssid_len;
376 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
377 pos += hapd->conf->ssid.ssid_len;
379 /* Supported rates */
380 pos = hostapd_eid_supp_rates(hapd, pos);
383 pos = hostapd_eid_ds_params(hapd, pos);
385 pos = hostapd_eid_country(hapd, pos, epos - pos);
387 /* Power Constraint element */
388 pos = hostapd_eid_pwr_constraint(hapd, pos);
390 /* ERP Information element */
391 pos = hostapd_eid_erp_info(hapd, pos);
393 /* Extended supported rates */
394 pos = hostapd_eid_ext_supp_rates(hapd, pos);
397 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
399 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
401 #ifdef CONFIG_IEEE80211N
402 pos = hostapd_eid_ht_capabilities(hapd, pos);
403 pos = hostapd_eid_ht_operation(hapd, pos);
404 #endif /* CONFIG_IEEE80211N */
406 pos = hostapd_eid_ext_capab(hapd, pos);
408 pos = hostapd_eid_time_adv(hapd, pos);
409 pos = hostapd_eid_time_zone(hapd, pos);
411 pos = hostapd_eid_interworking(hapd, pos);
412 pos = hostapd_eid_adv_proto(hapd, pos);
413 pos = hostapd_eid_roaming_consortium(hapd, pos);
415 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
416 &hapd->cs_c_off_proberesp);
417 #ifdef CONFIG_IEEE80211AC
418 pos = hostapd_eid_vht_capabilities(hapd, pos);
419 pos = hostapd_eid_vht_operation(hapd, pos);
420 #endif /* CONFIG_IEEE80211AC */
422 /* Wi-Fi Alliance WMM */
423 pos = hostapd_eid_wmm(hapd, pos);
426 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
427 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
428 wpabuf_len(hapd->wps_probe_resp_ie));
429 pos += wpabuf_len(hapd->wps_probe_resp_ie);
431 #endif /* CONFIG_WPS */
434 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
435 hapd->p2p_probe_resp_ie) {
436 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
437 wpabuf_len(hapd->p2p_probe_resp_ie));
438 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
440 #endif /* CONFIG_P2P */
441 #ifdef CONFIG_P2P_MANAGER
442 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
444 pos = hostapd_eid_p2p_manage(hapd, pos);
445 #endif /* CONFIG_P2P_MANAGER */
448 pos = hostapd_eid_hs20_indication(hapd, pos);
449 pos = hostapd_eid_osen(hapd, pos);
450 #endif /* CONFIG_HS20 */
452 if (hapd->conf->vendor_elements) {
453 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
454 wpabuf_len(hapd->conf->vendor_elements));
455 pos += wpabuf_len(hapd->conf->vendor_elements);
458 *resp_len = pos - (u8 *) resp;
463 enum ssid_match_result {
469 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
470 const u8 *ssid, size_t ssid_len,
472 size_t ssid_list_len)
479 if (ssid_len == hapd->conf->ssid.ssid_len &&
480 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
481 return EXACT_SSID_MATCH;
483 if (ssid_list == NULL)
484 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
487 end = ssid_list + ssid_list_len;
488 while (pos + 1 <= end) {
489 if (pos + 2 + pos[1] > end)
493 if (pos[1] == hapd->conf->ssid.ssid_len &&
494 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
495 return EXACT_SSID_MATCH;
499 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
503 void handle_probe_req(struct hostapd_data *hapd,
504 const struct ieee80211_mgmt *mgmt, size_t len,
508 struct ieee802_11_elems elems;
511 struct sta_info *sta = NULL;
514 enum ssid_match_result res;
516 ie = mgmt->u.probe_req.variable;
517 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
519 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
521 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
522 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
523 mgmt->sa, mgmt->da, mgmt->bssid,
524 ie, ie_len, ssi_signal) > 0)
527 if (!hapd->iconf->send_probe_response)
530 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
531 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
536 if ((!elems.ssid || !elems.supp_rates)) {
537 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
538 "without SSID or supported rates element",
544 if (hapd->p2p && elems.wps_ie) {
546 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
547 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
548 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
549 "due to mismatch with Requested Device "
557 if (hapd->p2p && elems.p2p) {
559 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
560 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
561 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
562 "due to mismatch with Device ID");
568 #endif /* CONFIG_P2P */
570 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
571 elems.ssid_list_len == 0) {
572 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
573 "broadcast SSID ignored", MAC2STR(mgmt->sa));
577 sta = ap_get_sta(hapd, mgmt->sa);
580 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
581 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
582 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
583 P2P_WILDCARD_SSID_LEN) == 0) {
584 /* Process P2P Wildcard SSID like Wildcard SSID */
587 #endif /* CONFIG_P2P */
589 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
590 elems.ssid_list, elems.ssid_list_len);
591 if (res != NO_SSID_MATCH) {
593 sta->ssid_probe = &hapd->conf->ssid;
595 if (!(mgmt->da[0] & 0x01)) {
596 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
597 " for foreign SSID '%s' (DA " MACSTR ")%s",
599 wpa_ssid_txt(elems.ssid, elems.ssid_len),
601 elems.ssid_list ? " (SSID list)" : "");
606 #ifdef CONFIG_INTERWORKING
607 if (hapd->conf->interworking &&
608 elems.interworking && elems.interworking_len >= 1) {
609 u8 ant = elems.interworking[0] & 0x0f;
610 if (ant != INTERWORKING_ANT_WILDCARD &&
611 ant != hapd->conf->access_network_type) {
612 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
613 " for mismatching ANT %u ignored",
614 MAC2STR(mgmt->sa), ant);
619 if (hapd->conf->interworking && elems.interworking &&
620 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
622 if (elems.interworking_len == 7)
623 hessid = elems.interworking + 1;
625 hessid = elems.interworking + 1 + 2;
626 if (!is_broadcast_ether_addr(hessid) &&
627 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
628 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
629 " for mismatching HESSID " MACSTR
631 MAC2STR(mgmt->sa), MAC2STR(hessid));
635 #endif /* CONFIG_INTERWORKING */
638 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
639 supp_rates_11b_only(&elems)) {
640 /* Indicates support for 11b rates only */
641 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
642 MACSTR " with only 802.11b rates",
646 #endif /* CONFIG_P2P */
648 /* TODO: verify that supp_rates contains at least one matching rate
649 * with AP configuration */
651 #ifdef CONFIG_TESTING_OPTIONS
652 if (hapd->iconf->ignore_probe_probability > 0.0 &&
653 drand48() < hapd->iconf->ignore_probe_probability) {
655 "TESTING: ignoring probe request from " MACSTR,
659 #endif /* CONFIG_TESTING_OPTIONS */
661 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
667 * If this is a broadcast probe request, apply no ack policy to avoid
670 noack = !!(res == WILDCARD_SSID_MATCH &&
671 is_broadcast_ether_addr(mgmt->da));
673 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
674 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
678 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
679 "SSID", MAC2STR(mgmt->sa),
680 elems.ssid_len == 0 ? "broadcast" : "our");
684 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
687 /* check probe response offloading caps and print warnings */
688 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
692 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
693 (!(hapd->iface->probe_resp_offloads &
694 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
695 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
696 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
697 "Probe Response while not supporting this");
698 #endif /* CONFIG_WPS */
701 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
702 !(hapd->iface->probe_resp_offloads &
703 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
704 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
705 "Probe Response while not supporting this");
706 #endif /* CONFIG_P2P */
708 if (hapd->conf->interworking &&
709 !(hapd->iface->probe_resp_offloads &
710 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
711 wpa_printf(MSG_WARNING, "Device is trying to offload "
712 "Interworking Probe Response while not supporting "
715 /* Generate a Probe Response template for the non-P2P case */
716 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
719 #endif /* NEED_AP_MLME */
722 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
723 struct wpa_driver_ap_params *params)
725 struct ieee80211_mgmt *head = NULL;
727 size_t head_len = 0, tail_len = 0;
734 #define BEACON_HEAD_BUF_SIZE 256
735 #define BEACON_TAIL_BUF_SIZE 512
736 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
737 tail_len = BEACON_TAIL_BUF_SIZE;
739 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
740 tail_len += wpabuf_len(hapd->wps_beacon_ie);
741 #endif /* CONFIG_WPS */
743 if (hapd->p2p_beacon_ie)
744 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
745 #endif /* CONFIG_P2P */
746 if (hapd->conf->vendor_elements)
747 tail_len += wpabuf_len(hapd->conf->vendor_elements);
748 tailpos = tail = os_malloc(tail_len);
749 if (head == NULL || tail == NULL) {
750 wpa_printf(MSG_ERROR, "Failed to set beacon data");
756 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
757 WLAN_FC_STYPE_BEACON);
758 head->duration = host_to_le16(0);
759 os_memset(head->da, 0xff, ETH_ALEN);
761 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
762 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
763 head->u.beacon.beacon_int =
764 host_to_le16(hapd->iconf->beacon_int);
766 /* hardware or low-level driver will setup seq_ctrl and timestamp */
767 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
768 head->u.beacon.capab_info = host_to_le16(capab_info);
769 pos = &head->u.beacon.variable[0];
772 *pos++ = WLAN_EID_SSID;
773 if (hapd->conf->ignore_broadcast_ssid == 2) {
774 /* clear the data, but keep the correct length of the SSID */
775 *pos++ = hapd->conf->ssid.ssid_len;
776 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
777 pos += hapd->conf->ssid.ssid_len;
778 } else if (hapd->conf->ignore_broadcast_ssid) {
779 *pos++ = 0; /* empty SSID */
781 *pos++ = hapd->conf->ssid.ssid_len;
782 os_memcpy(pos, hapd->conf->ssid.ssid,
783 hapd->conf->ssid.ssid_len);
784 pos += hapd->conf->ssid.ssid_len;
787 /* Supported rates */
788 pos = hostapd_eid_supp_rates(hapd, pos);
791 pos = hostapd_eid_ds_params(hapd, pos);
793 head_len = pos - (u8 *) head;
795 tailpos = hostapd_eid_country(hapd, tailpos,
796 tail + BEACON_TAIL_BUF_SIZE - tailpos);
798 /* Power Constraint element */
799 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
801 /* ERP Information element */
802 tailpos = hostapd_eid_erp_info(hapd, tailpos);
804 /* Extended supported rates */
805 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
808 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
811 tailpos = hostapd_eid_bss_load(hapd, tailpos,
812 tail + BEACON_TAIL_BUF_SIZE - tailpos);
814 #ifdef CONFIG_IEEE80211N
815 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
816 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
817 #endif /* CONFIG_IEEE80211N */
819 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
822 * TODO: Time Advertisement element should only be included in some
823 * DTIM Beacon frames.
825 tailpos = hostapd_eid_time_adv(hapd, tailpos);
827 tailpos = hostapd_eid_interworking(hapd, tailpos);
828 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
829 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
830 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
831 &hapd->cs_c_off_beacon);
832 #ifdef CONFIG_IEEE80211AC
833 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
834 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
835 #endif /* CONFIG_IEEE80211AC */
837 /* Wi-Fi Alliance WMM */
838 tailpos = hostapd_eid_wmm(hapd, tailpos);
841 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
842 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
843 wpabuf_len(hapd->wps_beacon_ie));
844 tailpos += wpabuf_len(hapd->wps_beacon_ie);
846 #endif /* CONFIG_WPS */
849 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
850 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
851 wpabuf_len(hapd->p2p_beacon_ie));
852 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
854 #endif /* CONFIG_P2P */
855 #ifdef CONFIG_P2P_MANAGER
856 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
858 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
859 #endif /* CONFIG_P2P_MANAGER */
862 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
863 tailpos = hostapd_eid_osen(hapd, tailpos);
864 #endif /* CONFIG_HS20 */
866 if (hapd->conf->vendor_elements) {
867 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
868 wpabuf_len(hapd->conf->vendor_elements));
869 tailpos += wpabuf_len(hapd->conf->vendor_elements);
872 tail_len = tailpos > tail ? tailpos - tail : 0;
874 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
875 #endif /* NEED_AP_MLME */
877 os_memset(params, 0, sizeof(*params));
878 params->head = (u8 *) head;
879 params->head_len = head_len;
881 params->tail_len = tail_len;
882 params->proberesp = resp;
883 params->proberesp_len = resp_len;
884 params->dtim_period = hapd->conf->dtim_period;
885 params->beacon_int = hapd->iconf->beacon_int;
886 params->basic_rates = hapd->iface->basic_rates;
887 params->ssid = hapd->conf->ssid.ssid;
888 params->ssid_len = hapd->conf->ssid.ssid_len;
889 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
890 hapd->conf->rsn_pairwise;
891 params->group_cipher = hapd->conf->wpa_group;
892 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
893 params->auth_algs = hapd->conf->auth_algs;
894 params->wpa_version = hapd->conf->wpa;
895 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
896 (hapd->conf->ieee802_1x &&
897 (hapd->conf->default_wep_key_len ||
898 hapd->conf->individual_wep_key_len));
899 switch (hapd->conf->ignore_broadcast_ssid) {
901 params->hide_ssid = NO_SSID_HIDING;
904 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
907 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
910 params->isolate = hapd->conf->isolate;
912 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
913 ERP_INFO_USE_PROTECTION);
914 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
915 hapd->iconf->preamble == SHORT_PREAMBLE;
916 if (hapd->iface->current_mode &&
917 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
918 params->short_slot_time =
919 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
921 params->short_slot_time = -1;
922 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
923 params->ht_opmode = -1;
925 params->ht_opmode = hapd->iface->ht_op_mode;
926 #endif /* NEED_AP_MLME */
927 params->interworking = hapd->conf->interworking;
928 if (hapd->conf->interworking &&
929 !is_zero_ether_addr(hapd->conf->hessid))
930 params->hessid = hapd->conf->hessid;
931 params->access_network_type = hapd->conf->access_network_type;
932 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
934 params->disable_dgaf = hapd->conf->disable_dgaf;
935 if (hapd->conf->osen) {
939 #endif /* CONFIG_HS20 */
944 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
946 os_free(params->tail);
948 os_free(params->head);
950 os_free(params->proberesp);
951 params->proberesp = NULL;
955 int ieee802_11_set_beacon(struct hostapd_data *hapd)
957 struct wpa_driver_ap_params params;
958 struct hostapd_freq_params freq;
959 struct hostapd_iface *iface = hapd->iface;
960 struct hostapd_config *iconf = iface->conf;
961 struct wpabuf *beacon, *proberesp, *assocresp;
964 if (hapd->csa_in_progress) {
965 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
969 hapd->beacon_set_done = 1;
971 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
974 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
978 params.beacon_ies = beacon;
979 params.proberesp_ies = proberesp;
980 params.assocresp_ies = assocresp;
982 if (iface->current_mode &&
983 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
984 iconf->channel, iconf->ieee80211n,
986 iconf->secondary_channel,
987 iconf->vht_oper_chwidth,
988 iconf->vht_oper_centr_freq_seg0_idx,
989 iconf->vht_oper_centr_freq_seg1_idx,
990 iface->current_mode->vht_capab) == 0)
993 res = hostapd_drv_set_ap(hapd, ¶ms);
994 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
996 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1000 ieee802_11_free_ap_params(¶ms);
1005 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1010 for (i = 0; i < iface->num_bss; i++) {
1011 if (iface->bss[i]->started &&
1012 ieee802_11_set_beacon(iface->bss[i]) < 0)
1020 /* only update beacons if started */
1021 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1026 for (i = 0; i < iface->num_bss; i++) {
1027 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1028 ieee802_11_set_beacon(iface->bss[i]) < 0)
1035 #endif /* CONFIG_NATIVE_WINDOWS */