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 "wps/wps_defs.h"
27 #include "ieee802_11.h"
30 #include "ap_config.h"
32 #include "p2p_hostapd.h"
33 #include "ap_drv_ops.h"
40 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
42 #ifdef CONFIG_TESTING_OPTIONS
43 if (hapd->conf->bss_load_test_set) {
46 *eid++ = WLAN_EID_BSS_LOAD;
48 os_memcpy(eid, hapd->conf->bss_load_test, 5);
51 #endif /* CONFIG_TESTING_OPTIONS */
56 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
60 if (hapd->iface->current_mode == NULL ||
61 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
64 if (hapd->iface->olbc)
65 erp |= ERP_INFO_USE_PROTECTION;
66 if (hapd->iface->num_sta_non_erp > 0) {
67 erp |= ERP_INFO_NON_ERP_PRESENT |
68 ERP_INFO_USE_PROTECTION;
70 if (hapd->iface->num_sta_no_short_preamble > 0 ||
71 hapd->iconf->preamble == LONG_PREAMBLE)
72 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
78 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
80 *eid++ = WLAN_EID_DS_PARAMS;
82 *eid++ = hapd->iconf->channel;
87 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
89 if (hapd->iface->current_mode == NULL ||
90 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
93 /* Set NonERP_present and use_protection bits if there
94 * are any associated NonERP stations. */
95 /* TODO: use_protection bit can be set to zero even if
96 * there are NonERP stations present. This optimization
97 * might be useful if NonERP stations are "quiet".
98 * See 802.11g/D6 E-1 for recommended practice.
99 * In addition, Non ERP present might be set, if AP detects Non ERP
100 * operation on other APs. */
102 /* Add ERP Information element */
103 *eid++ = WLAN_EID_ERP_INFO;
105 *eid++ = ieee802_11_erp_info(hapd);
111 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
112 struct hostapd_channel_data *start,
113 struct hostapd_channel_data *prev)
118 /* first channel number */
119 *pos++ = start->chan;
120 /* number of channels */
121 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
122 /* maximum transmit power level */
123 *pos++ = start->max_tx_power;
129 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
133 u8 *end = eid + max_len;
135 struct hostapd_hw_modes *mode;
136 struct hostapd_channel_data *start, *prev;
137 int chan_spacing = 1;
139 if (!hapd->iconf->ieee80211d || max_len < 6 ||
140 hapd->iface->current_mode == NULL)
143 *pos++ = WLAN_EID_COUNTRY;
144 pos++; /* length will be set later */
145 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
148 mode = hapd->iface->current_mode;
149 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
153 for (i = 0; i < mode->num_channels; i++) {
154 struct hostapd_channel_data *chan = &mode->channels[i];
155 if (chan->flag & HOSTAPD_CHAN_DISABLED)
158 prev->chan + chan_spacing == chan->chan &&
159 start->max_tx_power == chan->max_tx_power) {
161 continue; /* can use same entry */
165 pos = hostapd_eid_country_add(pos, end, chan_spacing,
170 /* Start new group */
175 pos = hostapd_eid_country_add(pos, end, chan_spacing,
179 if ((pos - eid) & 1) {
182 *pos++ = 0; /* pad for 16-bit alignment */
185 eid[1] = (pos - eid) - 2;
191 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
196 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
197 if (ie == NULL || ielen > len)
200 os_memcpy(eid, ie, ielen);
205 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
209 if (!hapd->iface->cs_freq_params.freq)
212 if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
216 *eid++ = WLAN_EID_CHANNEL_SWITCH;
218 *eid++ = hapd->iface->cs_block_tx;
220 *eid++ = hapd->iface->cs_count;
226 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
230 if (!hapd->iface->cs_freq_params.sec_channel_offset)
233 if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
234 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
235 else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
236 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
240 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
248 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
249 u8 *start, unsigned int *csa_counter_off)
253 if (!csa_counter_off)
256 *csa_counter_off = 0;
257 pos = hostapd_eid_csa(hapd, pos);
259 if (pos != old_pos) {
260 /* save an offset to the counter - should be last byte */
261 *csa_counter_off = pos - start - 1;
262 pos = hostapd_eid_secondary_channel(hapd, pos);
269 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
270 struct sta_info *sta,
271 const struct ieee80211_mgmt *req,
272 int is_p2p, size_t *resp_len)
274 struct ieee80211_mgmt *resp;
278 #define MAX_PROBERESP_LEN 768
279 buflen = MAX_PROBERESP_LEN;
281 if (hapd->wps_probe_resp_ie)
282 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
283 #endif /* CONFIG_WPS */
285 if (hapd->p2p_probe_resp_ie)
286 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
287 #endif /* CONFIG_P2P */
288 if (hapd->conf->vendor_elements)
289 buflen += wpabuf_len(hapd->conf->vendor_elements);
290 resp = os_zalloc(buflen);
294 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
296 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
297 WLAN_FC_STYPE_PROBE_RESP);
299 os_memcpy(resp->da, req->sa, ETH_ALEN);
300 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
302 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
303 resp->u.probe_resp.beacon_int =
304 host_to_le16(hapd->iconf->beacon_int);
306 /* hardware or low-level driver will setup seq_ctrl and timestamp */
307 resp->u.probe_resp.capab_info =
308 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
310 pos = resp->u.probe_resp.variable;
311 *pos++ = WLAN_EID_SSID;
312 *pos++ = hapd->conf->ssid.ssid_len;
313 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
314 pos += hapd->conf->ssid.ssid_len;
316 /* Supported rates */
317 pos = hostapd_eid_supp_rates(hapd, pos);
320 pos = hostapd_eid_ds_params(hapd, pos);
322 pos = hostapd_eid_country(hapd, pos, epos - pos);
324 /* ERP Information element */
325 pos = hostapd_eid_erp_info(hapd, pos);
327 /* Extended supported rates */
328 pos = hostapd_eid_ext_supp_rates(hapd, pos);
331 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
333 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
335 #ifdef CONFIG_IEEE80211N
336 pos = hostapd_eid_ht_capabilities(hapd, pos);
337 pos = hostapd_eid_ht_operation(hapd, pos);
338 #endif /* CONFIG_IEEE80211N */
340 pos = hostapd_eid_ext_capab(hapd, pos);
342 pos = hostapd_eid_time_adv(hapd, pos);
343 pos = hostapd_eid_time_zone(hapd, pos);
345 pos = hostapd_eid_interworking(hapd, pos);
346 pos = hostapd_eid_adv_proto(hapd, pos);
347 pos = hostapd_eid_roaming_consortium(hapd, pos);
349 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
350 &hapd->iface->cs_c_off_proberesp);
351 #ifdef CONFIG_IEEE80211AC
352 pos = hostapd_eid_vht_capabilities(hapd, pos);
353 pos = hostapd_eid_vht_operation(hapd, pos);
354 #endif /* CONFIG_IEEE80211AC */
356 /* Wi-Fi Alliance WMM */
357 pos = hostapd_eid_wmm(hapd, pos);
360 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
361 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
362 wpabuf_len(hapd->wps_probe_resp_ie));
363 pos += wpabuf_len(hapd->wps_probe_resp_ie);
365 #endif /* CONFIG_WPS */
368 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
369 hapd->p2p_probe_resp_ie) {
370 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
371 wpabuf_len(hapd->p2p_probe_resp_ie));
372 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
374 #endif /* CONFIG_P2P */
375 #ifdef CONFIG_P2P_MANAGER
376 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
378 pos = hostapd_eid_p2p_manage(hapd, pos);
379 #endif /* CONFIG_P2P_MANAGER */
382 pos = hostapd_eid_hs20_indication(hapd, pos);
383 #endif /* CONFIG_HS20 */
385 if (hapd->conf->vendor_elements) {
386 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
387 wpabuf_len(hapd->conf->vendor_elements));
388 pos += wpabuf_len(hapd->conf->vendor_elements);
391 *resp_len = pos - (u8 *) resp;
396 enum ssid_match_result {
402 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
403 const u8 *ssid, size_t ssid_len,
405 size_t ssid_list_len)
412 if (ssid_len == hapd->conf->ssid.ssid_len &&
413 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
414 return EXACT_SSID_MATCH;
416 if (ssid_list == NULL)
417 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
420 end = ssid_list + ssid_list_len;
421 while (pos + 1 <= end) {
422 if (pos + 2 + pos[1] > end)
426 if (pos[1] == hapd->conf->ssid.ssid_len &&
427 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
428 return EXACT_SSID_MATCH;
432 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
436 void handle_probe_req(struct hostapd_data *hapd,
437 const struct ieee80211_mgmt *mgmt, size_t len,
441 struct ieee802_11_elems elems;
444 struct sta_info *sta = NULL;
447 enum ssid_match_result res;
449 ie = mgmt->u.probe_req.variable;
450 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
452 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
454 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
455 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
456 mgmt->sa, mgmt->da, mgmt->bssid,
457 ie, ie_len, ssi_signal) > 0)
460 if (!hapd->iconf->send_probe_response)
463 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
464 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
469 if ((!elems.ssid || !elems.supp_rates)) {
470 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
471 "without SSID or supported rates element",
477 if (hapd->p2p && elems.wps_ie) {
479 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
480 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
481 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
482 "due to mismatch with Requested Device "
490 if (hapd->p2p && elems.p2p) {
492 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
493 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
494 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
495 "due to mismatch with Device ID");
501 #endif /* CONFIG_P2P */
503 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
504 elems.ssid_list_len == 0) {
505 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
506 "broadcast SSID ignored", MAC2STR(mgmt->sa));
510 sta = ap_get_sta(hapd, mgmt->sa);
513 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
514 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
515 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
516 P2P_WILDCARD_SSID_LEN) == 0) {
517 /* Process P2P Wildcard SSID like Wildcard SSID */
520 #endif /* CONFIG_P2P */
522 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
523 elems.ssid_list, elems.ssid_list_len);
524 if (res != NO_SSID_MATCH) {
526 sta->ssid_probe = &hapd->conf->ssid;
528 if (!(mgmt->da[0] & 0x01)) {
530 ieee802_11_print_ssid(ssid_txt, elems.ssid,
532 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
533 " for foreign SSID '%s' (DA " MACSTR ")%s",
534 MAC2STR(mgmt->sa), ssid_txt,
536 elems.ssid_list ? " (SSID list)" : "");
541 #ifdef CONFIG_INTERWORKING
542 if (elems.interworking && elems.interworking_len >= 1) {
543 u8 ant = elems.interworking[0] & 0x0f;
544 if (ant != INTERWORKING_ANT_WILDCARD &&
545 ant != hapd->conf->access_network_type) {
546 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
547 " for mismatching ANT %u ignored",
548 MAC2STR(mgmt->sa), ant);
553 if (elems.interworking &&
554 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
556 if (elems.interworking_len == 7)
557 hessid = elems.interworking + 1;
559 hessid = elems.interworking + 1 + 2;
560 if (!is_broadcast_ether_addr(hessid) &&
561 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
562 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
563 " for mismatching HESSID " MACSTR
565 MAC2STR(mgmt->sa), MAC2STR(hessid));
569 #endif /* CONFIG_INTERWORKING */
572 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
573 supp_rates_11b_only(&elems)) {
574 /* Indicates support for 11b rates only */
575 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
576 MACSTR " with only 802.11b rates",
580 #endif /* CONFIG_P2P */
582 /* TODO: verify that supp_rates contains at least one matching rate
583 * with AP configuration */
585 #ifdef CONFIG_TESTING_OPTIONS
586 if (hapd->iconf->ignore_probe_probability > 0.0d &&
587 drand48() < hapd->iconf->ignore_probe_probability) {
589 "TESTING: ignoring probe request from " MACSTR,
593 #endif /* CONFIG_TESTING_OPTIONS */
595 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
601 * If this is a broadcast probe request, apply no ack policy to avoid
604 noack = !!(res == WILDCARD_SSID_MATCH &&
605 is_broadcast_ether_addr(mgmt->da));
607 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
608 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
612 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
613 "SSID", MAC2STR(mgmt->sa),
614 elems.ssid_len == 0 ? "broadcast" : "our");
618 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
621 /* check probe response offloading caps and print warnings */
622 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
626 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
627 (!(hapd->iface->probe_resp_offloads &
628 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
629 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
630 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
631 "Probe Response while not supporting this");
632 #endif /* CONFIG_WPS */
635 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
636 !(hapd->iface->probe_resp_offloads &
637 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
638 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
639 "Probe Response while not supporting this");
640 #endif /* CONFIG_P2P */
642 if (hapd->conf->interworking &&
643 !(hapd->iface->probe_resp_offloads &
644 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
645 wpa_printf(MSG_WARNING, "Device is trying to offload "
646 "Interworking Probe Response while not supporting "
649 /* Generate a Probe Response template for the non-P2P case */
650 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
653 #endif /* NEED_AP_MLME */
656 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
657 struct wpa_driver_ap_params *params)
659 struct ieee80211_mgmt *head = NULL;
661 size_t head_len = 0, tail_len = 0;
668 #define BEACON_HEAD_BUF_SIZE 256
669 #define BEACON_TAIL_BUF_SIZE 512
670 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
671 tail_len = BEACON_TAIL_BUF_SIZE;
673 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
674 tail_len += wpabuf_len(hapd->wps_beacon_ie);
675 #endif /* CONFIG_WPS */
677 if (hapd->p2p_beacon_ie)
678 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
679 #endif /* CONFIG_P2P */
680 if (hapd->conf->vendor_elements)
681 tail_len += wpabuf_len(hapd->conf->vendor_elements);
682 tailpos = tail = os_malloc(tail_len);
683 if (head == NULL || tail == NULL) {
684 wpa_printf(MSG_ERROR, "Failed to set beacon data");
690 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
691 WLAN_FC_STYPE_BEACON);
692 head->duration = host_to_le16(0);
693 os_memset(head->da, 0xff, ETH_ALEN);
695 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
696 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
697 head->u.beacon.beacon_int =
698 host_to_le16(hapd->iconf->beacon_int);
700 /* hardware or low-level driver will setup seq_ctrl and timestamp */
701 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
702 head->u.beacon.capab_info = host_to_le16(capab_info);
703 pos = &head->u.beacon.variable[0];
706 *pos++ = WLAN_EID_SSID;
707 if (hapd->conf->ignore_broadcast_ssid == 2) {
708 /* clear the data, but keep the correct length of the SSID */
709 *pos++ = hapd->conf->ssid.ssid_len;
710 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
711 pos += hapd->conf->ssid.ssid_len;
712 } else if (hapd->conf->ignore_broadcast_ssid) {
713 *pos++ = 0; /* empty SSID */
715 *pos++ = hapd->conf->ssid.ssid_len;
716 os_memcpy(pos, hapd->conf->ssid.ssid,
717 hapd->conf->ssid.ssid_len);
718 pos += hapd->conf->ssid.ssid_len;
721 /* Supported rates */
722 pos = hostapd_eid_supp_rates(hapd, pos);
725 pos = hostapd_eid_ds_params(hapd, pos);
727 head_len = pos - (u8 *) head;
729 tailpos = hostapd_eid_country(hapd, tailpos,
730 tail + BEACON_TAIL_BUF_SIZE - tailpos);
732 /* ERP Information element */
733 tailpos = hostapd_eid_erp_info(hapd, tailpos);
735 /* Extended supported rates */
736 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
739 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
742 tailpos = hostapd_eid_bss_load(hapd, tailpos,
743 tail + BEACON_TAIL_BUF_SIZE - tailpos);
745 #ifdef CONFIG_IEEE80211N
746 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
747 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
748 #endif /* CONFIG_IEEE80211N */
750 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
753 * TODO: Time Advertisement element should only be included in some
754 * DTIM Beacon frames.
756 tailpos = hostapd_eid_time_adv(hapd, tailpos);
758 tailpos = hostapd_eid_interworking(hapd, tailpos);
759 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
760 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
761 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
762 &hapd->iface->cs_c_off_beacon);
763 #ifdef CONFIG_IEEE80211AC
764 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
765 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
766 #endif /* CONFIG_IEEE80211AC */
768 /* Wi-Fi Alliance WMM */
769 tailpos = hostapd_eid_wmm(hapd, tailpos);
772 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
773 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
774 wpabuf_len(hapd->wps_beacon_ie));
775 tailpos += wpabuf_len(hapd->wps_beacon_ie);
777 #endif /* CONFIG_WPS */
780 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
781 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
782 wpabuf_len(hapd->p2p_beacon_ie));
783 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
785 #endif /* CONFIG_P2P */
786 #ifdef CONFIG_P2P_MANAGER
787 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
789 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
790 #endif /* CONFIG_P2P_MANAGER */
793 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
794 #endif /* CONFIG_HS20 */
796 if (hapd->conf->vendor_elements) {
797 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
798 wpabuf_len(hapd->conf->vendor_elements));
799 tailpos += wpabuf_len(hapd->conf->vendor_elements);
802 tail_len = tailpos > tail ? tailpos - tail : 0;
804 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
805 #endif /* NEED_AP_MLME */
807 os_memset(params, 0, sizeof(*params));
808 params->head = (u8 *) head;
809 params->head_len = head_len;
811 params->tail_len = tail_len;
812 params->proberesp = resp;
813 params->proberesp_len = resp_len;
814 params->dtim_period = hapd->conf->dtim_period;
815 params->beacon_int = hapd->iconf->beacon_int;
816 params->basic_rates = hapd->iface->basic_rates;
817 params->ssid = hapd->conf->ssid.ssid;
818 params->ssid_len = hapd->conf->ssid.ssid_len;
819 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
820 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
821 params->group_cipher = hapd->conf->wpa_group;
822 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
823 params->auth_algs = hapd->conf->auth_algs;
824 params->wpa_version = hapd->conf->wpa;
825 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
826 (hapd->conf->ieee802_1x &&
827 (hapd->conf->default_wep_key_len ||
828 hapd->conf->individual_wep_key_len));
829 switch (hapd->conf->ignore_broadcast_ssid) {
831 params->hide_ssid = NO_SSID_HIDING;
834 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
837 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
840 params->isolate = hapd->conf->isolate;
842 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
843 ERP_INFO_USE_PROTECTION);
844 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
845 hapd->iconf->preamble == SHORT_PREAMBLE;
846 if (hapd->iface->current_mode &&
847 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
848 params->short_slot_time =
849 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
851 params->short_slot_time = -1;
852 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
853 params->ht_opmode = -1;
855 params->ht_opmode = hapd->iface->ht_op_mode;
856 #endif /* NEED_AP_MLME */
857 params->interworking = hapd->conf->interworking;
858 if (hapd->conf->interworking &&
859 !is_zero_ether_addr(hapd->conf->hessid))
860 params->hessid = hapd->conf->hessid;
861 params->access_network_type = hapd->conf->access_network_type;
862 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
864 params->disable_dgaf = hapd->conf->disable_dgaf;
865 #endif /* CONFIG_HS20 */
870 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
872 os_free(params->tail);
874 os_free(params->head);
876 os_free(params->proberesp);
877 params->proberesp = NULL;
881 int ieee802_11_set_beacon(struct hostapd_data *hapd)
883 struct wpa_driver_ap_params params;
884 struct wpabuf *beacon, *proberesp, *assocresp;
887 if (hapd->iface->csa_in_progress) {
888 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
892 hapd->beacon_set_done = 1;
894 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
897 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
901 params.beacon_ies = beacon;
902 params.proberesp_ies = proberesp;
903 params.assocresp_ies = assocresp;
905 res = hostapd_drv_set_ap(hapd, ¶ms);
906 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
908 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
912 ieee802_11_free_ap_params(¶ms);
917 int ieee802_11_set_beacons(struct hostapd_iface *iface)
922 for (i = 0; i < iface->num_bss; i++) {
923 if (iface->bss[i]->started &&
924 ieee802_11_set_beacon(iface->bss[i]) < 0)
932 /* only update beacons if started */
933 int ieee802_11_update_beacons(struct hostapd_iface *iface)
938 for (i = 0; i < iface->num_bss; i++) {
939 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
940 ieee802_11_set_beacon(iface->bss[i]) < 0)
947 #endif /* CONFIG_NATIVE_WINDOWS */