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 pos = hostapd_eid_osen(hapd, pos);
446 #endif /* CONFIG_HS20 */
448 if (hapd->conf->vendor_elements) {
449 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
450 wpabuf_len(hapd->conf->vendor_elements));
451 pos += wpabuf_len(hapd->conf->vendor_elements);
454 *resp_len = pos - (u8 *) resp;
459 enum ssid_match_result {
465 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
466 const u8 *ssid, size_t ssid_len,
468 size_t ssid_list_len)
475 if (ssid_len == hapd->conf->ssid.ssid_len &&
476 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
477 return EXACT_SSID_MATCH;
479 if (ssid_list == NULL)
480 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
483 end = ssid_list + ssid_list_len;
484 while (pos + 1 <= end) {
485 if (pos + 2 + pos[1] > end)
489 if (pos[1] == hapd->conf->ssid.ssid_len &&
490 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
491 return EXACT_SSID_MATCH;
495 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
499 void handle_probe_req(struct hostapd_data *hapd,
500 const struct ieee80211_mgmt *mgmt, size_t len,
504 struct ieee802_11_elems elems;
507 struct sta_info *sta = NULL;
510 enum ssid_match_result res;
512 ie = mgmt->u.probe_req.variable;
513 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
515 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
517 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
518 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
519 mgmt->sa, mgmt->da, mgmt->bssid,
520 ie, ie_len, ssi_signal) > 0)
523 if (!hapd->iconf->send_probe_response)
526 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
527 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
532 if ((!elems.ssid || !elems.supp_rates)) {
533 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
534 "without SSID or supported rates element",
540 if (hapd->p2p && elems.wps_ie) {
542 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
543 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
544 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
545 "due to mismatch with Requested Device "
553 if (hapd->p2p && elems.p2p) {
555 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
556 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
557 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
558 "due to mismatch with Device ID");
564 #endif /* CONFIG_P2P */
566 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
567 elems.ssid_list_len == 0) {
568 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
569 "broadcast SSID ignored", MAC2STR(mgmt->sa));
573 sta = ap_get_sta(hapd, mgmt->sa);
576 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
577 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
578 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
579 P2P_WILDCARD_SSID_LEN) == 0) {
580 /* Process P2P Wildcard SSID like Wildcard SSID */
583 #endif /* CONFIG_P2P */
585 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
586 elems.ssid_list, elems.ssid_list_len);
587 if (res != NO_SSID_MATCH) {
589 sta->ssid_probe = &hapd->conf->ssid;
591 if (!(mgmt->da[0] & 0x01)) {
592 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
593 " for foreign SSID '%s' (DA " MACSTR ")%s",
595 wpa_ssid_txt(elems.ssid, elems.ssid_len),
597 elems.ssid_list ? " (SSID list)" : "");
602 #ifdef CONFIG_INTERWORKING
603 if (hapd->conf->interworking &&
604 elems.interworking && elems.interworking_len >= 1) {
605 u8 ant = elems.interworking[0] & 0x0f;
606 if (ant != INTERWORKING_ANT_WILDCARD &&
607 ant != hapd->conf->access_network_type) {
608 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
609 " for mismatching ANT %u ignored",
610 MAC2STR(mgmt->sa), ant);
615 if (hapd->conf->interworking && elems.interworking &&
616 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
618 if (elems.interworking_len == 7)
619 hessid = elems.interworking + 1;
621 hessid = elems.interworking + 1 + 2;
622 if (!is_broadcast_ether_addr(hessid) &&
623 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
624 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
625 " for mismatching HESSID " MACSTR
627 MAC2STR(mgmt->sa), MAC2STR(hessid));
631 #endif /* CONFIG_INTERWORKING */
634 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
635 supp_rates_11b_only(&elems)) {
636 /* Indicates support for 11b rates only */
637 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
638 MACSTR " with only 802.11b rates",
642 #endif /* CONFIG_P2P */
644 /* TODO: verify that supp_rates contains at least one matching rate
645 * with AP configuration */
647 #ifdef CONFIG_TESTING_OPTIONS
648 if (hapd->iconf->ignore_probe_probability > 0.0d &&
649 drand48() < hapd->iconf->ignore_probe_probability) {
651 "TESTING: ignoring probe request from " MACSTR,
655 #endif /* CONFIG_TESTING_OPTIONS */
657 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
663 * If this is a broadcast probe request, apply no ack policy to avoid
666 noack = !!(res == WILDCARD_SSID_MATCH &&
667 is_broadcast_ether_addr(mgmt->da));
669 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
670 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
674 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
675 "SSID", MAC2STR(mgmt->sa),
676 elems.ssid_len == 0 ? "broadcast" : "our");
680 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
683 /* check probe response offloading caps and print warnings */
684 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
688 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
689 (!(hapd->iface->probe_resp_offloads &
690 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
691 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
692 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
693 "Probe Response while not supporting this");
694 #endif /* CONFIG_WPS */
697 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
698 !(hapd->iface->probe_resp_offloads &
699 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
700 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
701 "Probe Response while not supporting this");
702 #endif /* CONFIG_P2P */
704 if (hapd->conf->interworking &&
705 !(hapd->iface->probe_resp_offloads &
706 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
707 wpa_printf(MSG_WARNING, "Device is trying to offload "
708 "Interworking Probe Response while not supporting "
711 /* Generate a Probe Response template for the non-P2P case */
712 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
715 #endif /* NEED_AP_MLME */
718 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
719 struct wpa_driver_ap_params *params)
721 struct ieee80211_mgmt *head = NULL;
723 size_t head_len = 0, tail_len = 0;
730 #define BEACON_HEAD_BUF_SIZE 256
731 #define BEACON_TAIL_BUF_SIZE 512
732 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
733 tail_len = BEACON_TAIL_BUF_SIZE;
735 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
736 tail_len += wpabuf_len(hapd->wps_beacon_ie);
737 #endif /* CONFIG_WPS */
739 if (hapd->p2p_beacon_ie)
740 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
741 #endif /* CONFIG_P2P */
742 if (hapd->conf->vendor_elements)
743 tail_len += wpabuf_len(hapd->conf->vendor_elements);
744 tailpos = tail = os_malloc(tail_len);
745 if (head == NULL || tail == NULL) {
746 wpa_printf(MSG_ERROR, "Failed to set beacon data");
752 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
753 WLAN_FC_STYPE_BEACON);
754 head->duration = host_to_le16(0);
755 os_memset(head->da, 0xff, ETH_ALEN);
757 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
758 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
759 head->u.beacon.beacon_int =
760 host_to_le16(hapd->iconf->beacon_int);
762 /* hardware or low-level driver will setup seq_ctrl and timestamp */
763 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
764 head->u.beacon.capab_info = host_to_le16(capab_info);
765 pos = &head->u.beacon.variable[0];
768 *pos++ = WLAN_EID_SSID;
769 if (hapd->conf->ignore_broadcast_ssid == 2) {
770 /* clear the data, but keep the correct length of the SSID */
771 *pos++ = hapd->conf->ssid.ssid_len;
772 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
773 pos += hapd->conf->ssid.ssid_len;
774 } else if (hapd->conf->ignore_broadcast_ssid) {
775 *pos++ = 0; /* empty SSID */
777 *pos++ = hapd->conf->ssid.ssid_len;
778 os_memcpy(pos, hapd->conf->ssid.ssid,
779 hapd->conf->ssid.ssid_len);
780 pos += hapd->conf->ssid.ssid_len;
783 /* Supported rates */
784 pos = hostapd_eid_supp_rates(hapd, pos);
787 pos = hostapd_eid_ds_params(hapd, pos);
789 head_len = pos - (u8 *) head;
791 tailpos = hostapd_eid_country(hapd, tailpos,
792 tail + BEACON_TAIL_BUF_SIZE - tailpos);
794 /* Power Constraint element */
795 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
797 /* ERP Information element */
798 tailpos = hostapd_eid_erp_info(hapd, tailpos);
800 /* Extended supported rates */
801 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
804 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
807 tailpos = hostapd_eid_bss_load(hapd, tailpos,
808 tail + BEACON_TAIL_BUF_SIZE - tailpos);
810 #ifdef CONFIG_IEEE80211N
811 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
812 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
813 #endif /* CONFIG_IEEE80211N */
815 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
818 * TODO: Time Advertisement element should only be included in some
819 * DTIM Beacon frames.
821 tailpos = hostapd_eid_time_adv(hapd, tailpos);
823 tailpos = hostapd_eid_interworking(hapd, tailpos);
824 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
825 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
826 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
827 &hapd->iface->cs_c_off_beacon);
828 #ifdef CONFIG_IEEE80211AC
829 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
830 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
831 #endif /* CONFIG_IEEE80211AC */
833 /* Wi-Fi Alliance WMM */
834 tailpos = hostapd_eid_wmm(hapd, tailpos);
837 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
838 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
839 wpabuf_len(hapd->wps_beacon_ie));
840 tailpos += wpabuf_len(hapd->wps_beacon_ie);
842 #endif /* CONFIG_WPS */
845 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
846 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
847 wpabuf_len(hapd->p2p_beacon_ie));
848 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
850 #endif /* CONFIG_P2P */
851 #ifdef CONFIG_P2P_MANAGER
852 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
854 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
855 #endif /* CONFIG_P2P_MANAGER */
858 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
859 tailpos = hostapd_eid_osen(hapd, tailpos);
860 #endif /* CONFIG_HS20 */
862 if (hapd->conf->vendor_elements) {
863 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
864 wpabuf_len(hapd->conf->vendor_elements));
865 tailpos += wpabuf_len(hapd->conf->vendor_elements);
868 tail_len = tailpos > tail ? tailpos - tail : 0;
870 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
871 #endif /* NEED_AP_MLME */
873 os_memset(params, 0, sizeof(*params));
874 params->head = (u8 *) head;
875 params->head_len = head_len;
877 params->tail_len = tail_len;
878 params->proberesp = resp;
879 params->proberesp_len = resp_len;
880 params->dtim_period = hapd->conf->dtim_period;
881 params->beacon_int = hapd->iconf->beacon_int;
882 params->basic_rates = hapd->iface->basic_rates;
883 params->ssid = hapd->conf->ssid.ssid;
884 params->ssid_len = hapd->conf->ssid.ssid_len;
885 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
886 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
887 params->group_cipher = hapd->conf->wpa_group;
888 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
889 params->auth_algs = hapd->conf->auth_algs;
890 params->wpa_version = hapd->conf->wpa;
891 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
892 (hapd->conf->ieee802_1x &&
893 (hapd->conf->default_wep_key_len ||
894 hapd->conf->individual_wep_key_len));
895 switch (hapd->conf->ignore_broadcast_ssid) {
897 params->hide_ssid = NO_SSID_HIDING;
900 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
903 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
906 params->isolate = hapd->conf->isolate;
908 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
909 ERP_INFO_USE_PROTECTION);
910 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
911 hapd->iconf->preamble == SHORT_PREAMBLE;
912 if (hapd->iface->current_mode &&
913 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
914 params->short_slot_time =
915 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
917 params->short_slot_time = -1;
918 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
919 params->ht_opmode = -1;
921 params->ht_opmode = hapd->iface->ht_op_mode;
922 #endif /* NEED_AP_MLME */
923 params->interworking = hapd->conf->interworking;
924 if (hapd->conf->interworking &&
925 !is_zero_ether_addr(hapd->conf->hessid))
926 params->hessid = hapd->conf->hessid;
927 params->access_network_type = hapd->conf->access_network_type;
928 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
930 params->disable_dgaf = hapd->conf->disable_dgaf;
931 if (hapd->conf->osen) {
935 #endif /* CONFIG_HS20 */
940 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
942 os_free(params->tail);
944 os_free(params->head);
946 os_free(params->proberesp);
947 params->proberesp = NULL;
951 int ieee802_11_set_beacon(struct hostapd_data *hapd)
953 struct wpa_driver_ap_params params;
954 struct wpabuf *beacon, *proberesp, *assocresp;
957 if (hapd->iface->csa_in_progress) {
958 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
962 hapd->beacon_set_done = 1;
964 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
967 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
971 params.beacon_ies = beacon;
972 params.proberesp_ies = proberesp;
973 params.assocresp_ies = assocresp;
975 res = hostapd_drv_set_ap(hapd, ¶ms);
976 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
978 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
982 ieee802_11_free_ap_params(¶ms);
987 int ieee802_11_set_beacons(struct hostapd_iface *iface)
992 for (i = 0; i < iface->num_bss; i++) {
993 if (iface->bss[i]->started &&
994 ieee802_11_set_beacon(iface->bss[i]) < 0)
1002 /* only update beacons if started */
1003 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1008 for (i = 0; i < iface->num_bss; i++) {
1009 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1010 ieee802_11_set_beacon(iface->bss[i]) < 0)
1017 #endif /* CONFIG_NATIVE_WINDOWS */