2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
17 #include "utils/includes.h"
19 #ifndef CONFIG_NATIVE_WINDOWS
21 #include "utils/common.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/ieee802_11_common.h"
24 #include "drivers/driver.h"
25 #include "wps/wps_defs.h"
28 #include "ieee802_11.h"
31 #include "ap_config.h"
33 #include "p2p_hostapd.h"
34 #include "ap_drv_ops.h"
41 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
43 #ifdef CONFIG_TESTING_OPTIONS
44 if (hapd->conf->bss_load_test_set) {
47 *eid++ = WLAN_EID_BSS_LOAD;
49 os_memcpy(eid, hapd->conf->bss_load_test, 5);
52 #endif /* CONFIG_TESTING_OPTIONS */
57 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
61 if (hapd->iface->current_mode == NULL ||
62 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
65 if (hapd->iface->olbc)
66 erp |= ERP_INFO_USE_PROTECTION;
67 if (hapd->iface->num_sta_non_erp > 0) {
68 erp |= ERP_INFO_NON_ERP_PRESENT |
69 ERP_INFO_USE_PROTECTION;
71 if (hapd->iface->num_sta_no_short_preamble > 0 ||
72 hapd->iconf->preamble == LONG_PREAMBLE)
73 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
79 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
81 *eid++ = WLAN_EID_DS_PARAMS;
83 *eid++ = hapd->iconf->channel;
88 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
90 if (hapd->iface->current_mode == NULL ||
91 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
94 /* Set NonERP_present and use_protection bits if there
95 * are any associated NonERP stations. */
96 /* TODO: use_protection bit can be set to zero even if
97 * there are NonERP stations present. This optimization
98 * might be useful if NonERP stations are "quiet".
99 * See 802.11g/D6 E-1 for recommended practice.
100 * In addition, Non ERP present might be set, if AP detects Non ERP
101 * operation on other APs. */
103 /* Add ERP Information element */
104 *eid++ = WLAN_EID_ERP_INFO;
106 *eid++ = ieee802_11_erp_info(hapd);
112 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
113 struct hostapd_channel_data *start,
114 struct hostapd_channel_data *prev)
119 /* first channel number */
120 *pos++ = start->chan;
121 /* number of channels */
122 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
123 /* maximum transmit power level */
124 *pos++ = start->max_tx_power;
130 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
134 u8 *end = eid + max_len;
136 struct hostapd_hw_modes *mode;
137 struct hostapd_channel_data *start, *prev;
138 int chan_spacing = 1;
140 if (!hapd->iconf->ieee80211d || max_len < 6 ||
141 hapd->iface->current_mode == NULL)
144 *pos++ = WLAN_EID_COUNTRY;
145 pos++; /* length will be set later */
146 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
149 mode = hapd->iface->current_mode;
150 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
154 for (i = 0; i < mode->num_channels; i++) {
155 struct hostapd_channel_data *chan = &mode->channels[i];
156 if (chan->flag & HOSTAPD_CHAN_DISABLED)
159 prev->chan + chan_spacing == chan->chan &&
160 start->max_tx_power == chan->max_tx_power) {
162 continue; /* can use same entry */
166 pos = hostapd_eid_country_add(pos, end, chan_spacing,
171 /* Start new group */
176 pos = hostapd_eid_country_add(pos, end, chan_spacing,
180 if ((pos - eid) & 1) {
183 *pos++ = 0; /* pad for 16-bit alignment */
186 eid[1] = (pos - eid) - 2;
192 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
197 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
198 if (ie == NULL || ielen > len)
201 os_memcpy(eid, ie, ielen);
206 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
210 if (!hapd->iface->cs_freq)
213 if (ieee80211_freq_to_chan(hapd->iface->cs_freq, &chan) ==
217 *eid++ = WLAN_EID_CHANNEL_SWITCH;
219 *eid++ = hapd->iface->cs_block_tx;
221 *eid++ = hapd->iface->cs_count;
227 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
228 struct sta_info *sta,
229 const struct ieee80211_mgmt *req,
230 int is_p2p, size_t *resp_len)
232 struct ieee80211_mgmt *resp;
233 u8 *pos, *epos, *old_pos;
236 #define MAX_PROBERESP_LEN 768
237 buflen = MAX_PROBERESP_LEN;
239 if (hapd->wps_probe_resp_ie)
240 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
241 #endif /* CONFIG_WPS */
243 if (hapd->p2p_probe_resp_ie)
244 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
245 #endif /* CONFIG_P2P */
246 if (hapd->conf->vendor_elements)
247 buflen += wpabuf_len(hapd->conf->vendor_elements);
248 resp = os_zalloc(buflen);
252 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
254 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
255 WLAN_FC_STYPE_PROBE_RESP);
257 os_memcpy(resp->da, req->sa, ETH_ALEN);
258 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
260 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
261 resp->u.probe_resp.beacon_int =
262 host_to_le16(hapd->iconf->beacon_int);
264 /* hardware or low-level driver will setup seq_ctrl and timestamp */
265 resp->u.probe_resp.capab_info =
266 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
268 pos = resp->u.probe_resp.variable;
269 *pos++ = WLAN_EID_SSID;
270 *pos++ = hapd->conf->ssid.ssid_len;
271 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
272 pos += hapd->conf->ssid.ssid_len;
274 /* Supported rates */
275 pos = hostapd_eid_supp_rates(hapd, pos);
278 pos = hostapd_eid_ds_params(hapd, pos);
280 pos = hostapd_eid_country(hapd, pos, epos - pos);
282 /* ERP Information element */
283 pos = hostapd_eid_erp_info(hapd, pos);
285 /* Extended supported rates */
286 pos = hostapd_eid_ext_supp_rates(hapd, pos);
289 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
291 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
293 #ifdef CONFIG_IEEE80211N
294 pos = hostapd_eid_ht_capabilities(hapd, pos);
295 pos = hostapd_eid_ht_operation(hapd, pos);
296 #endif /* CONFIG_IEEE80211N */
298 pos = hostapd_eid_ext_capab(hapd, pos);
300 pos = hostapd_eid_time_adv(hapd, pos);
301 pos = hostapd_eid_time_zone(hapd, pos);
303 pos = hostapd_eid_interworking(hapd, pos);
304 pos = hostapd_eid_adv_proto(hapd, pos);
305 pos = hostapd_eid_roaming_consortium(hapd, pos);
308 pos = hostapd_eid_csa(hapd, pos);
310 /* save an offset to the counter - should be last byte */
311 hapd->iface->cs_c_off_proberesp = (pos != old_pos) ?
312 pos - (u8 *) resp - 1 : 0;
314 #ifdef CONFIG_IEEE80211AC
315 pos = hostapd_eid_vht_capabilities(hapd, pos);
316 pos = hostapd_eid_vht_operation(hapd, pos);
317 #endif /* CONFIG_IEEE80211AC */
319 /* Wi-Fi Alliance WMM */
320 pos = hostapd_eid_wmm(hapd, pos);
323 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
324 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
325 wpabuf_len(hapd->wps_probe_resp_ie));
326 pos += wpabuf_len(hapd->wps_probe_resp_ie);
328 #endif /* CONFIG_WPS */
331 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
332 hapd->p2p_probe_resp_ie) {
333 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
334 wpabuf_len(hapd->p2p_probe_resp_ie));
335 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
337 #endif /* CONFIG_P2P */
338 #ifdef CONFIG_P2P_MANAGER
339 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
341 pos = hostapd_eid_p2p_manage(hapd, pos);
342 #endif /* CONFIG_P2P_MANAGER */
345 pos = hostapd_eid_hs20_indication(hapd, pos);
346 #endif /* CONFIG_HS20 */
348 if (hapd->conf->vendor_elements) {
349 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
350 wpabuf_len(hapd->conf->vendor_elements));
351 pos += wpabuf_len(hapd->conf->vendor_elements);
354 *resp_len = pos - (u8 *) resp;
359 enum ssid_match_result {
365 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
366 const u8 *ssid, size_t ssid_len,
368 size_t ssid_list_len)
375 if (ssid_len == hapd->conf->ssid.ssid_len &&
376 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
377 return EXACT_SSID_MATCH;
379 if (ssid_list == NULL)
380 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
383 end = ssid_list + ssid_list_len;
384 while (pos + 1 <= end) {
385 if (pos + 2 + pos[1] > end)
389 if (pos[1] == hapd->conf->ssid.ssid_len &&
390 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
391 return EXACT_SSID_MATCH;
395 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
399 void handle_probe_req(struct hostapd_data *hapd,
400 const struct ieee80211_mgmt *mgmt, size_t len,
404 struct ieee802_11_elems elems;
407 struct sta_info *sta = NULL;
410 enum ssid_match_result res;
412 ie = mgmt->u.probe_req.variable;
413 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
415 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
417 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
418 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
419 mgmt->sa, mgmt->da, mgmt->bssid,
420 ie, ie_len, ssi_signal) > 0)
423 if (!hapd->iconf->send_probe_response)
426 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
427 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
432 if ((!elems.ssid || !elems.supp_rates)) {
433 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
434 "without SSID or supported rates element",
440 if (hapd->p2p && elems.wps_ie) {
442 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
443 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
444 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
445 "due to mismatch with Requested Device "
453 if (hapd->p2p && elems.p2p) {
455 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
456 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
457 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
458 "due to mismatch with Device ID");
464 #endif /* CONFIG_P2P */
466 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
467 elems.ssid_list_len == 0) {
468 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
469 "broadcast SSID ignored", MAC2STR(mgmt->sa));
473 sta = ap_get_sta(hapd, mgmt->sa);
476 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
477 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
478 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
479 P2P_WILDCARD_SSID_LEN) == 0) {
480 /* Process P2P Wildcard SSID like Wildcard SSID */
483 #endif /* CONFIG_P2P */
485 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
486 elems.ssid_list, elems.ssid_list_len);
487 if (res != NO_SSID_MATCH) {
489 sta->ssid_probe = &hapd->conf->ssid;
491 if (!(mgmt->da[0] & 0x01)) {
493 ieee802_11_print_ssid(ssid_txt, elems.ssid,
495 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
496 " for foreign SSID '%s' (DA " MACSTR ")%s",
497 MAC2STR(mgmt->sa), ssid_txt,
499 elems.ssid_list ? " (SSID list)" : "");
504 #ifdef CONFIG_INTERWORKING
505 if (elems.interworking && elems.interworking_len >= 1) {
506 u8 ant = elems.interworking[0] & 0x0f;
507 if (ant != INTERWORKING_ANT_WILDCARD &&
508 ant != hapd->conf->access_network_type) {
509 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
510 " for mismatching ANT %u ignored",
511 MAC2STR(mgmt->sa), ant);
516 if (elems.interworking &&
517 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
519 if (elems.interworking_len == 7)
520 hessid = elems.interworking + 1;
522 hessid = elems.interworking + 1 + 2;
523 if (!is_broadcast_ether_addr(hessid) &&
524 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
525 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
526 " for mismatching HESSID " MACSTR
528 MAC2STR(mgmt->sa), MAC2STR(hessid));
532 #endif /* CONFIG_INTERWORKING */
535 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
536 supp_rates_11b_only(&elems)) {
537 /* Indicates support for 11b rates only */
538 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
539 MACSTR " with only 802.11b rates",
543 #endif /* CONFIG_P2P */
545 /* TODO: verify that supp_rates contains at least one matching rate
546 * with AP configuration */
548 #ifdef CONFIG_TESTING_OPTIONS
549 if (hapd->iconf->ignore_probe_probability > 0.0d &&
550 drand48() < hapd->iconf->ignore_probe_probability) {
552 "TESTING: ignoring probe request from " MACSTR,
556 #endif /* CONFIG_TESTING_OPTIONS */
558 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
564 * If this is a broadcast probe request, apply no ack policy to avoid
567 noack = !!(res == WILDCARD_SSID_MATCH &&
568 is_broadcast_ether_addr(mgmt->da));
570 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
571 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
575 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
576 "SSID", MAC2STR(mgmt->sa),
577 elems.ssid_len == 0 ? "broadcast" : "our");
581 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
584 /* check probe response offloading caps and print warnings */
585 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
589 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
590 (!(hapd->iface->probe_resp_offloads &
591 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
592 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
593 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
594 "Probe Response while not supporting this");
595 #endif /* CONFIG_WPS */
598 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
599 !(hapd->iface->probe_resp_offloads &
600 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
601 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
602 "Probe Response while not supporting this");
603 #endif /* CONFIG_P2P */
605 if (hapd->conf->interworking &&
606 !(hapd->iface->probe_resp_offloads &
607 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
608 wpa_printf(MSG_WARNING, "Device is trying to offload "
609 "Interworking Probe Response while not supporting "
612 /* Generate a Probe Response template for the non-P2P case */
613 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
616 #endif /* NEED_AP_MLME */
619 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
620 struct wpa_driver_ap_params *params)
622 struct ieee80211_mgmt *head = NULL;
624 size_t head_len = 0, tail_len = 0;
629 u8 *pos, *tailpos, *old_pos;
631 #define BEACON_HEAD_BUF_SIZE 256
632 #define BEACON_TAIL_BUF_SIZE 512
633 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
634 tail_len = BEACON_TAIL_BUF_SIZE;
636 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
637 tail_len += wpabuf_len(hapd->wps_beacon_ie);
638 #endif /* CONFIG_WPS */
640 if (hapd->p2p_beacon_ie)
641 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
642 #endif /* CONFIG_P2P */
643 if (hapd->conf->vendor_elements)
644 tail_len += wpabuf_len(hapd->conf->vendor_elements);
645 tailpos = tail = os_malloc(tail_len);
646 if (head == NULL || tail == NULL) {
647 wpa_printf(MSG_ERROR, "Failed to set beacon data");
653 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
654 WLAN_FC_STYPE_BEACON);
655 head->duration = host_to_le16(0);
656 os_memset(head->da, 0xff, ETH_ALEN);
658 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
659 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
660 head->u.beacon.beacon_int =
661 host_to_le16(hapd->iconf->beacon_int);
663 /* hardware or low-level driver will setup seq_ctrl and timestamp */
664 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
665 head->u.beacon.capab_info = host_to_le16(capab_info);
666 pos = &head->u.beacon.variable[0];
669 *pos++ = WLAN_EID_SSID;
670 if (hapd->conf->ignore_broadcast_ssid == 2) {
671 /* clear the data, but keep the correct length of the SSID */
672 *pos++ = hapd->conf->ssid.ssid_len;
673 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
674 pos += hapd->conf->ssid.ssid_len;
675 } else if (hapd->conf->ignore_broadcast_ssid) {
676 *pos++ = 0; /* empty SSID */
678 *pos++ = hapd->conf->ssid.ssid_len;
679 os_memcpy(pos, hapd->conf->ssid.ssid,
680 hapd->conf->ssid.ssid_len);
681 pos += hapd->conf->ssid.ssid_len;
684 /* Supported rates */
685 pos = hostapd_eid_supp_rates(hapd, pos);
688 pos = hostapd_eid_ds_params(hapd, pos);
690 head_len = pos - (u8 *) head;
692 tailpos = hostapd_eid_country(hapd, tailpos,
693 tail + BEACON_TAIL_BUF_SIZE - tailpos);
695 /* ERP Information element */
696 tailpos = hostapd_eid_erp_info(hapd, tailpos);
698 /* Extended supported rates */
699 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
702 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
705 tailpos = hostapd_eid_bss_load(hapd, tailpos,
706 tail + BEACON_TAIL_BUF_SIZE - tailpos);
708 #ifdef CONFIG_IEEE80211N
709 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
710 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
711 #endif /* CONFIG_IEEE80211N */
713 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
716 * TODO: Time Advertisement element should only be included in some
717 * DTIM Beacon frames.
719 tailpos = hostapd_eid_time_adv(hapd, tailpos);
721 tailpos = hostapd_eid_interworking(hapd, tailpos);
722 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
723 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
725 tailpos = hostapd_eid_csa(hapd, tailpos);
726 hapd->iface->cs_c_off_beacon = (old_pos != tailpos) ?
727 tailpos - tail - 1 : 0;
729 #ifdef CONFIG_IEEE80211AC
730 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
731 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
732 #endif /* CONFIG_IEEE80211AC */
734 /* Wi-Fi Alliance WMM */
735 tailpos = hostapd_eid_wmm(hapd, tailpos);
738 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
739 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
740 wpabuf_len(hapd->wps_beacon_ie));
741 tailpos += wpabuf_len(hapd->wps_beacon_ie);
743 #endif /* CONFIG_WPS */
746 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
747 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
748 wpabuf_len(hapd->p2p_beacon_ie));
749 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
751 #endif /* CONFIG_P2P */
752 #ifdef CONFIG_P2P_MANAGER
753 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
755 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
756 #endif /* CONFIG_P2P_MANAGER */
759 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
760 #endif /* CONFIG_HS20 */
762 if (hapd->conf->vendor_elements) {
763 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
764 wpabuf_len(hapd->conf->vendor_elements));
765 tailpos += wpabuf_len(hapd->conf->vendor_elements);
768 tail_len = tailpos > tail ? tailpos - tail : 0;
770 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
771 #endif /* NEED_AP_MLME */
773 os_memset(params, 0, sizeof(*params));
774 params->head = (u8 *) head;
775 params->head_len = head_len;
777 params->tail_len = tail_len;
778 params->proberesp = resp;
779 params->proberesp_len = resp_len;
780 params->dtim_period = hapd->conf->dtim_period;
781 params->beacon_int = hapd->iconf->beacon_int;
782 params->basic_rates = hapd->iface->basic_rates;
783 params->ssid = hapd->conf->ssid.ssid;
784 params->ssid_len = hapd->conf->ssid.ssid_len;
785 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
786 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
787 params->group_cipher = hapd->conf->wpa_group;
788 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
789 params->auth_algs = hapd->conf->auth_algs;
790 params->wpa_version = hapd->conf->wpa;
791 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
792 (hapd->conf->ieee802_1x &&
793 (hapd->conf->default_wep_key_len ||
794 hapd->conf->individual_wep_key_len));
795 switch (hapd->conf->ignore_broadcast_ssid) {
797 params->hide_ssid = NO_SSID_HIDING;
800 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
803 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
806 params->isolate = hapd->conf->isolate;
808 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
809 ERP_INFO_USE_PROTECTION);
810 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
811 hapd->iconf->preamble == SHORT_PREAMBLE;
812 if (hapd->iface->current_mode &&
813 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
814 params->short_slot_time =
815 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
817 params->short_slot_time = -1;
818 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
819 params->ht_opmode = -1;
821 params->ht_opmode = hapd->iface->ht_op_mode;
822 #endif /* NEED_AP_MLME */
823 params->interworking = hapd->conf->interworking;
824 if (hapd->conf->interworking &&
825 !is_zero_ether_addr(hapd->conf->hessid))
826 params->hessid = hapd->conf->hessid;
827 params->access_network_type = hapd->conf->access_network_type;
828 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
830 params->disable_dgaf = hapd->conf->disable_dgaf;
831 #endif /* CONFIG_HS20 */
836 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
838 os_free(params->tail);
840 os_free(params->head);
842 os_free(params->proberesp);
843 params->proberesp = NULL;
847 void ieee802_11_set_beacon(struct hostapd_data *hapd)
849 struct wpa_driver_ap_params params;
850 struct wpabuf *beacon, *proberesp, *assocresp;
852 if (hapd->iface->csa_in_progress) {
853 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
857 hapd->beacon_set_done = 1;
859 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
862 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
866 params.beacon_ies = beacon;
867 params.proberesp_ies = proberesp;
868 params.assocresp_ies = assocresp;
870 if (hostapd_drv_set_ap(hapd, ¶ms))
871 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
872 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
874 ieee802_11_free_ap_params(¶ms);
878 void ieee802_11_set_beacons(struct hostapd_iface *iface)
881 for (i = 0; i < iface->num_bss; i++) {
882 if (iface->bss[i]->started)
883 ieee802_11_set_beacon(iface->bss[i]);
888 /* only update beacons if started */
889 void ieee802_11_update_beacons(struct hostapd_iface *iface)
892 for (i = 0; i < iface->num_bss; i++)
893 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started)
894 ieee802_11_set_beacon(iface->bss[i]);
897 #endif /* CONFIG_NATIVE_WINDOWS */