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"
34 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
36 #ifdef CONFIG_TESTING_OPTIONS
37 if (hapd->conf->bss_load_test_set) {
40 *eid++ = WLAN_EID_BSS_LOAD;
42 os_memcpy(eid, hapd->conf->bss_load_test, 5);
45 #endif /* CONFIG_TESTING_OPTIONS */
50 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
54 if (hapd->iface->current_mode == NULL ||
55 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
58 if (hapd->iface->olbc)
59 erp |= ERP_INFO_USE_PROTECTION;
60 if (hapd->iface->num_sta_non_erp > 0) {
61 erp |= ERP_INFO_NON_ERP_PRESENT |
62 ERP_INFO_USE_PROTECTION;
64 if (hapd->iface->num_sta_no_short_preamble > 0 ||
65 hapd->iconf->preamble == LONG_PREAMBLE)
66 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
72 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
74 *eid++ = WLAN_EID_DS_PARAMS;
76 *eid++ = hapd->iconf->channel;
81 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
83 if (hapd->iface->current_mode == NULL ||
84 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
87 /* Set NonERP_present and use_protection bits if there
88 * are any associated NonERP stations. */
89 /* TODO: use_protection bit can be set to zero even if
90 * there are NonERP stations present. This optimization
91 * might be useful if NonERP stations are "quiet".
92 * See 802.11g/D6 E-1 for recommended practice.
93 * In addition, Non ERP present might be set, if AP detects Non ERP
94 * operation on other APs. */
96 /* Add ERP Information element */
97 *eid++ = WLAN_EID_ERP_INFO;
99 *eid++ = ieee802_11_erp_info(hapd);
105 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
106 struct hostapd_channel_data *start,
107 struct hostapd_channel_data *prev)
112 /* first channel number */
113 *pos++ = start->chan;
114 /* number of channels */
115 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
116 /* maximum transmit power level */
117 *pos++ = start->max_tx_power;
123 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
127 u8 *end = eid + max_len;
129 struct hostapd_hw_modes *mode;
130 struct hostapd_channel_data *start, *prev;
131 int chan_spacing = 1;
133 if (!hapd->iconf->ieee80211d || max_len < 6 ||
134 hapd->iface->current_mode == NULL)
137 *pos++ = WLAN_EID_COUNTRY;
138 pos++; /* length will be set later */
139 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
142 mode = hapd->iface->current_mode;
143 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
147 for (i = 0; i < mode->num_channels; i++) {
148 struct hostapd_channel_data *chan = &mode->channels[i];
149 if (chan->flag & HOSTAPD_CHAN_DISABLED)
152 prev->chan + chan_spacing == chan->chan &&
153 start->max_tx_power == chan->max_tx_power) {
155 continue; /* can use same entry */
159 pos = hostapd_eid_country_add(pos, end, chan_spacing,
164 /* Start new group */
169 pos = hostapd_eid_country_add(pos, end, chan_spacing,
173 if ((pos - eid) & 1) {
176 *pos++ = 0; /* pad for 16-bit alignment */
179 eid[1] = (pos - eid) - 2;
185 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
190 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
191 if (ie == NULL || ielen > len)
194 os_memcpy(eid, ie, ielen);
199 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
203 if (!hapd->iface->cs_freq_params.freq)
206 if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
210 *eid++ = WLAN_EID_CHANNEL_SWITCH;
212 *eid++ = hapd->iface->cs_block_tx;
214 *eid++ = hapd->iface->cs_count;
220 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
224 if (!hapd->iface->cs_freq_params.sec_channel_offset)
227 if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
228 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
229 else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
230 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
234 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
242 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
243 u8 *start, unsigned int *csa_counter_off)
247 if (!csa_counter_off)
250 *csa_counter_off = 0;
251 pos = hostapd_eid_csa(hapd, pos);
253 if (pos != old_pos) {
254 /* save an offset to the counter - should be last byte */
255 *csa_counter_off = pos - start - 1;
256 pos = hostapd_eid_secondary_channel(hapd, pos);
263 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
264 struct sta_info *sta,
265 const struct ieee80211_mgmt *req,
266 int is_p2p, size_t *resp_len)
268 struct ieee80211_mgmt *resp;
272 #define MAX_PROBERESP_LEN 768
273 buflen = MAX_PROBERESP_LEN;
275 if (hapd->wps_probe_resp_ie)
276 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
277 #endif /* CONFIG_WPS */
279 if (hapd->p2p_probe_resp_ie)
280 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
281 #endif /* CONFIG_P2P */
282 if (hapd->conf->vendor_elements)
283 buflen += wpabuf_len(hapd->conf->vendor_elements);
284 resp = os_zalloc(buflen);
288 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
290 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
291 WLAN_FC_STYPE_PROBE_RESP);
293 os_memcpy(resp->da, req->sa, ETH_ALEN);
294 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
296 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
297 resp->u.probe_resp.beacon_int =
298 host_to_le16(hapd->iconf->beacon_int);
300 /* hardware or low-level driver will setup seq_ctrl and timestamp */
301 resp->u.probe_resp.capab_info =
302 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
304 pos = resp->u.probe_resp.variable;
305 *pos++ = WLAN_EID_SSID;
306 *pos++ = hapd->conf->ssid.ssid_len;
307 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
308 pos += hapd->conf->ssid.ssid_len;
310 /* Supported rates */
311 pos = hostapd_eid_supp_rates(hapd, pos);
314 pos = hostapd_eid_ds_params(hapd, pos);
316 pos = hostapd_eid_country(hapd, pos, epos - pos);
318 /* ERP Information element */
319 pos = hostapd_eid_erp_info(hapd, pos);
321 /* Extended supported rates */
322 pos = hostapd_eid_ext_supp_rates(hapd, pos);
325 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
327 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
329 #ifdef CONFIG_IEEE80211N
330 pos = hostapd_eid_ht_capabilities(hapd, pos);
331 pos = hostapd_eid_ht_operation(hapd, pos);
332 #endif /* CONFIG_IEEE80211N */
334 pos = hostapd_eid_ext_capab(hapd, pos);
336 pos = hostapd_eid_time_adv(hapd, pos);
337 pos = hostapd_eid_time_zone(hapd, pos);
339 pos = hostapd_eid_interworking(hapd, pos);
340 pos = hostapd_eid_adv_proto(hapd, pos);
341 pos = hostapd_eid_roaming_consortium(hapd, pos);
343 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
344 &hapd->iface->cs_c_off_proberesp);
345 #ifdef CONFIG_IEEE80211AC
346 pos = hostapd_eid_vht_capabilities(hapd, pos);
347 pos = hostapd_eid_vht_operation(hapd, pos);
348 #endif /* CONFIG_IEEE80211AC */
350 /* Wi-Fi Alliance WMM */
351 pos = hostapd_eid_wmm(hapd, pos);
354 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
355 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
356 wpabuf_len(hapd->wps_probe_resp_ie));
357 pos += wpabuf_len(hapd->wps_probe_resp_ie);
359 #endif /* CONFIG_WPS */
362 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
363 hapd->p2p_probe_resp_ie) {
364 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
365 wpabuf_len(hapd->p2p_probe_resp_ie));
366 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
368 #endif /* CONFIG_P2P */
369 #ifdef CONFIG_P2P_MANAGER
370 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
372 pos = hostapd_eid_p2p_manage(hapd, pos);
373 #endif /* CONFIG_P2P_MANAGER */
376 pos = hostapd_eid_hs20_indication(hapd, pos);
377 #endif /* CONFIG_HS20 */
379 if (hapd->conf->vendor_elements) {
380 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
381 wpabuf_len(hapd->conf->vendor_elements));
382 pos += wpabuf_len(hapd->conf->vendor_elements);
385 *resp_len = pos - (u8 *) resp;
390 enum ssid_match_result {
396 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
397 const u8 *ssid, size_t ssid_len,
399 size_t ssid_list_len)
406 if (ssid_len == hapd->conf->ssid.ssid_len &&
407 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
408 return EXACT_SSID_MATCH;
410 if (ssid_list == NULL)
411 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
414 end = ssid_list + ssid_list_len;
415 while (pos + 1 <= end) {
416 if (pos + 2 + pos[1] > end)
420 if (pos[1] == hapd->conf->ssid.ssid_len &&
421 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
422 return EXACT_SSID_MATCH;
426 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
430 void handle_probe_req(struct hostapd_data *hapd,
431 const struct ieee80211_mgmt *mgmt, size_t len,
435 struct ieee802_11_elems elems;
438 struct sta_info *sta = NULL;
441 enum ssid_match_result res;
443 ie = mgmt->u.probe_req.variable;
444 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
446 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
448 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
449 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
450 mgmt->sa, mgmt->da, mgmt->bssid,
451 ie, ie_len, ssi_signal) > 0)
454 if (!hapd->iconf->send_probe_response)
457 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
458 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
463 if ((!elems.ssid || !elems.supp_rates)) {
464 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
465 "without SSID or supported rates element",
471 if (hapd->p2p && elems.wps_ie) {
473 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
474 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
475 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
476 "due to mismatch with Requested Device "
484 if (hapd->p2p && elems.p2p) {
486 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
487 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
488 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
489 "due to mismatch with Device ID");
495 #endif /* CONFIG_P2P */
497 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
498 elems.ssid_list_len == 0) {
499 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
500 "broadcast SSID ignored", MAC2STR(mgmt->sa));
504 sta = ap_get_sta(hapd, mgmt->sa);
507 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
508 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
509 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
510 P2P_WILDCARD_SSID_LEN) == 0) {
511 /* Process P2P Wildcard SSID like Wildcard SSID */
514 #endif /* CONFIG_P2P */
516 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
517 elems.ssid_list, elems.ssid_list_len);
518 if (res != NO_SSID_MATCH) {
520 sta->ssid_probe = &hapd->conf->ssid;
522 if (!(mgmt->da[0] & 0x01)) {
524 ieee802_11_print_ssid(ssid_txt, elems.ssid,
526 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
527 " for foreign SSID '%s' (DA " MACSTR ")%s",
528 MAC2STR(mgmt->sa), ssid_txt,
530 elems.ssid_list ? " (SSID list)" : "");
535 #ifdef CONFIG_INTERWORKING
536 if (elems.interworking && elems.interworking_len >= 1) {
537 u8 ant = elems.interworking[0] & 0x0f;
538 if (ant != INTERWORKING_ANT_WILDCARD &&
539 ant != hapd->conf->access_network_type) {
540 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
541 " for mismatching ANT %u ignored",
542 MAC2STR(mgmt->sa), ant);
547 if (elems.interworking &&
548 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
550 if (elems.interworking_len == 7)
551 hessid = elems.interworking + 1;
553 hessid = elems.interworking + 1 + 2;
554 if (!is_broadcast_ether_addr(hessid) &&
555 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
556 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
557 " for mismatching HESSID " MACSTR
559 MAC2STR(mgmt->sa), MAC2STR(hessid));
563 #endif /* CONFIG_INTERWORKING */
566 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
567 supp_rates_11b_only(&elems)) {
568 /* Indicates support for 11b rates only */
569 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
570 MACSTR " with only 802.11b rates",
574 #endif /* CONFIG_P2P */
576 /* TODO: verify that supp_rates contains at least one matching rate
577 * with AP configuration */
579 #ifdef CONFIG_TESTING_OPTIONS
580 if (hapd->iconf->ignore_probe_probability > 0.0d &&
581 drand48() < hapd->iconf->ignore_probe_probability) {
583 "TESTING: ignoring probe request from " MACSTR,
587 #endif /* CONFIG_TESTING_OPTIONS */
589 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
595 * If this is a broadcast probe request, apply no ack policy to avoid
598 noack = !!(res == WILDCARD_SSID_MATCH &&
599 is_broadcast_ether_addr(mgmt->da));
601 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
602 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
606 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
607 "SSID", MAC2STR(mgmt->sa),
608 elems.ssid_len == 0 ? "broadcast" : "our");
612 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
615 /* check probe response offloading caps and print warnings */
616 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
620 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
621 (!(hapd->iface->probe_resp_offloads &
622 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
623 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
624 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
625 "Probe Response while not supporting this");
626 #endif /* CONFIG_WPS */
629 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
630 !(hapd->iface->probe_resp_offloads &
631 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
632 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
633 "Probe Response while not supporting this");
634 #endif /* CONFIG_P2P */
636 if (hapd->conf->interworking &&
637 !(hapd->iface->probe_resp_offloads &
638 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
639 wpa_printf(MSG_WARNING, "Device is trying to offload "
640 "Interworking Probe Response while not supporting "
643 /* Generate a Probe Response template for the non-P2P case */
644 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
647 #endif /* NEED_AP_MLME */
650 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
651 struct wpa_driver_ap_params *params)
653 struct ieee80211_mgmt *head = NULL;
655 size_t head_len = 0, tail_len = 0;
662 #define BEACON_HEAD_BUF_SIZE 256
663 #define BEACON_TAIL_BUF_SIZE 512
664 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
665 tail_len = BEACON_TAIL_BUF_SIZE;
667 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
668 tail_len += wpabuf_len(hapd->wps_beacon_ie);
669 #endif /* CONFIG_WPS */
671 if (hapd->p2p_beacon_ie)
672 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
673 #endif /* CONFIG_P2P */
674 if (hapd->conf->vendor_elements)
675 tail_len += wpabuf_len(hapd->conf->vendor_elements);
676 tailpos = tail = os_malloc(tail_len);
677 if (head == NULL || tail == NULL) {
678 wpa_printf(MSG_ERROR, "Failed to set beacon data");
684 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
685 WLAN_FC_STYPE_BEACON);
686 head->duration = host_to_le16(0);
687 os_memset(head->da, 0xff, ETH_ALEN);
689 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
690 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
691 head->u.beacon.beacon_int =
692 host_to_le16(hapd->iconf->beacon_int);
694 /* hardware or low-level driver will setup seq_ctrl and timestamp */
695 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
696 head->u.beacon.capab_info = host_to_le16(capab_info);
697 pos = &head->u.beacon.variable[0];
700 *pos++ = WLAN_EID_SSID;
701 if (hapd->conf->ignore_broadcast_ssid == 2) {
702 /* clear the data, but keep the correct length of the SSID */
703 *pos++ = hapd->conf->ssid.ssid_len;
704 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
705 pos += hapd->conf->ssid.ssid_len;
706 } else if (hapd->conf->ignore_broadcast_ssid) {
707 *pos++ = 0; /* empty SSID */
709 *pos++ = hapd->conf->ssid.ssid_len;
710 os_memcpy(pos, hapd->conf->ssid.ssid,
711 hapd->conf->ssid.ssid_len);
712 pos += hapd->conf->ssid.ssid_len;
715 /* Supported rates */
716 pos = hostapd_eid_supp_rates(hapd, pos);
719 pos = hostapd_eid_ds_params(hapd, pos);
721 head_len = pos - (u8 *) head;
723 tailpos = hostapd_eid_country(hapd, tailpos,
724 tail + BEACON_TAIL_BUF_SIZE - tailpos);
726 /* ERP Information element */
727 tailpos = hostapd_eid_erp_info(hapd, tailpos);
729 /* Extended supported rates */
730 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
733 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
736 tailpos = hostapd_eid_bss_load(hapd, tailpos,
737 tail + BEACON_TAIL_BUF_SIZE - tailpos);
739 #ifdef CONFIG_IEEE80211N
740 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
741 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
742 #endif /* CONFIG_IEEE80211N */
744 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
747 * TODO: Time Advertisement element should only be included in some
748 * DTIM Beacon frames.
750 tailpos = hostapd_eid_time_adv(hapd, tailpos);
752 tailpos = hostapd_eid_interworking(hapd, tailpos);
753 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
754 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
755 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
756 &hapd->iface->cs_c_off_beacon);
757 #ifdef CONFIG_IEEE80211AC
758 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
759 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
760 #endif /* CONFIG_IEEE80211AC */
762 /* Wi-Fi Alliance WMM */
763 tailpos = hostapd_eid_wmm(hapd, tailpos);
766 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
767 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
768 wpabuf_len(hapd->wps_beacon_ie));
769 tailpos += wpabuf_len(hapd->wps_beacon_ie);
771 #endif /* CONFIG_WPS */
774 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
775 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
776 wpabuf_len(hapd->p2p_beacon_ie));
777 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
779 #endif /* CONFIG_P2P */
780 #ifdef CONFIG_P2P_MANAGER
781 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
783 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
784 #endif /* CONFIG_P2P_MANAGER */
787 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
788 #endif /* CONFIG_HS20 */
790 if (hapd->conf->vendor_elements) {
791 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
792 wpabuf_len(hapd->conf->vendor_elements));
793 tailpos += wpabuf_len(hapd->conf->vendor_elements);
796 tail_len = tailpos > tail ? tailpos - tail : 0;
798 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
799 #endif /* NEED_AP_MLME */
801 os_memset(params, 0, sizeof(*params));
802 params->head = (u8 *) head;
803 params->head_len = head_len;
805 params->tail_len = tail_len;
806 params->proberesp = resp;
807 params->proberesp_len = resp_len;
808 params->dtim_period = hapd->conf->dtim_period;
809 params->beacon_int = hapd->iconf->beacon_int;
810 params->basic_rates = hapd->iface->basic_rates;
811 params->ssid = hapd->conf->ssid.ssid;
812 params->ssid_len = hapd->conf->ssid.ssid_len;
813 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
814 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
815 params->group_cipher = hapd->conf->wpa_group;
816 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
817 params->auth_algs = hapd->conf->auth_algs;
818 params->wpa_version = hapd->conf->wpa;
819 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
820 (hapd->conf->ieee802_1x &&
821 (hapd->conf->default_wep_key_len ||
822 hapd->conf->individual_wep_key_len));
823 switch (hapd->conf->ignore_broadcast_ssid) {
825 params->hide_ssid = NO_SSID_HIDING;
828 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
831 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
834 params->isolate = hapd->conf->isolate;
836 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
837 ERP_INFO_USE_PROTECTION);
838 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
839 hapd->iconf->preamble == SHORT_PREAMBLE;
840 if (hapd->iface->current_mode &&
841 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
842 params->short_slot_time =
843 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
845 params->short_slot_time = -1;
846 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
847 params->ht_opmode = -1;
849 params->ht_opmode = hapd->iface->ht_op_mode;
850 #endif /* NEED_AP_MLME */
851 params->interworking = hapd->conf->interworking;
852 if (hapd->conf->interworking &&
853 !is_zero_ether_addr(hapd->conf->hessid))
854 params->hessid = hapd->conf->hessid;
855 params->access_network_type = hapd->conf->access_network_type;
856 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
858 params->disable_dgaf = hapd->conf->disable_dgaf;
859 #endif /* CONFIG_HS20 */
864 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
866 os_free(params->tail);
868 os_free(params->head);
870 os_free(params->proberesp);
871 params->proberesp = NULL;
875 int ieee802_11_set_beacon(struct hostapd_data *hapd)
877 struct wpa_driver_ap_params params;
878 struct wpabuf *beacon, *proberesp, *assocresp;
881 if (hapd->iface->csa_in_progress) {
882 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
886 hapd->beacon_set_done = 1;
888 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
891 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
895 params.beacon_ies = beacon;
896 params.proberesp_ies = proberesp;
897 params.assocresp_ies = assocresp;
899 res = hostapd_drv_set_ap(hapd, ¶ms);
900 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
902 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
906 ieee802_11_free_ap_params(¶ms);
911 int ieee802_11_set_beacons(struct hostapd_iface *iface)
916 for (i = 0; i < iface->num_bss; i++) {
917 if (iface->bss[i]->started &&
918 ieee802_11_set_beacon(iface->bss[i]) < 0)
926 /* only update beacons if started */
927 int ieee802_11_update_beacons(struct hostapd_iface *iface)
932 for (i = 0; i < iface->num_bss; i++) {
933 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
934 ieee802_11_set_beacon(iface->bss[i]) < 0)
941 #endif /* CONFIG_NATIVE_WINDOWS */