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 "common/hw_features_common.h"
19 #include "wps/wps_defs.h"
22 #include "ieee802_11.h"
25 #include "ap_config.h"
27 #include "p2p_hostapd.h"
28 #include "ap_drv_ops.h"
36 static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
39 if (!hapd->conf->radio_measurements || len < 2 + 4)
42 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
44 *eid++ = (hapd->conf->radio_measurements & BIT(0)) ?
45 WLAN_RRM_CAPS_NEIGHBOR_REPORT : 0x00;
54 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
59 #ifdef CONFIG_TESTING_OPTIONS
60 if (hapd->conf->bss_load_test_set) {
61 *eid++ = WLAN_EID_BSS_LOAD;
63 os_memcpy(eid, hapd->conf->bss_load_test, 5);
67 #endif /* CONFIG_TESTING_OPTIONS */
68 if (hapd->conf->bss_load_update_period) {
69 *eid++ = WLAN_EID_BSS_LOAD;
71 WPA_PUT_LE16(eid, hapd->num_sta);
73 *eid++ = hapd->iface->channel_utilization;
74 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
81 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
85 if (hapd->iface->current_mode == NULL ||
86 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
89 if (hapd->iface->olbc)
90 erp |= ERP_INFO_USE_PROTECTION;
91 if (hapd->iface->num_sta_non_erp > 0) {
92 erp |= ERP_INFO_NON_ERP_PRESENT |
93 ERP_INFO_USE_PROTECTION;
95 if (hapd->iface->num_sta_no_short_preamble > 0 ||
96 hapd->iconf->preamble == LONG_PREAMBLE)
97 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
103 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
105 *eid++ = WLAN_EID_DS_PARAMS;
107 *eid++ = hapd->iconf->channel;
112 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
114 if (hapd->iface->current_mode == NULL ||
115 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
118 /* Set NonERP_present and use_protection bits if there
119 * are any associated NonERP stations. */
120 /* TODO: use_protection bit can be set to zero even if
121 * there are NonERP stations present. This optimization
122 * might be useful if NonERP stations are "quiet".
123 * See 802.11g/D6 E-1 for recommended practice.
124 * In addition, Non ERP present might be set, if AP detects Non ERP
125 * operation on other APs. */
127 /* Add ERP Information element */
128 *eid++ = WLAN_EID_ERP_INFO;
130 *eid++ = ieee802_11_erp_info(hapd);
136 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
139 u8 local_pwr_constraint = 0;
142 if (hapd->iface->current_mode == NULL ||
143 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
146 /* Let host drivers add this IE if DFS support is offloaded */
147 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
151 * There is no DFS support and power constraint was not directly
152 * requested by config option.
154 if (!hapd->iconf->ieee80211h &&
155 hapd->iconf->local_pwr_constraint == -1)
158 /* Check if DFS is required by regulatory. */
159 dfs = hostapd_is_dfs_required(hapd->iface);
161 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
166 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
170 * ieee80211h (DFS) is enabled so Power Constraint element shall
171 * be added when running on DFS channel whenever local_pwr_constraint
172 * is configured or not. In order to meet regulations when TPC is not
173 * implemented using a transmit power that is below the legal maximum
174 * (including any mitigation factor) should help. In this case,
175 * indicate 3 dB below maximum allowed transmit power.
177 if (hapd->iconf->local_pwr_constraint == -1)
178 local_pwr_constraint = 3;
181 * A STA that is not an AP shall use a transmit power less than or
182 * equal to the local maximum transmit power level for the channel.
183 * The local maximum transmit power can be calculated from the formula:
184 * local max TX pwr = max TX pwr - local pwr constraint
185 * Where max TX pwr is maximum transmit power level specified for
186 * channel in Country element and local pwr constraint is specified
187 * for channel in this Power Constraint element.
191 *pos++ = WLAN_EID_PWR_CONSTRAINT;
194 /* Local Power Constraint */
195 if (local_pwr_constraint)
196 *pos++ = local_pwr_constraint;
198 *pos++ = hapd->iconf->local_pwr_constraint;
204 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
205 struct hostapd_channel_data *start,
206 struct hostapd_channel_data *prev)
211 /* first channel number */
212 *pos++ = start->chan;
213 /* number of channels */
214 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
215 /* maximum transmit power level */
216 *pos++ = start->max_tx_power;
222 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
226 u8 *end = eid + max_len;
228 struct hostapd_hw_modes *mode;
229 struct hostapd_channel_data *start, *prev;
230 int chan_spacing = 1;
232 if (!hapd->iconf->ieee80211d || max_len < 6 ||
233 hapd->iface->current_mode == NULL)
236 *pos++ = WLAN_EID_COUNTRY;
237 pos++; /* length will be set later */
238 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
241 mode = hapd->iface->current_mode;
242 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
246 for (i = 0; i < mode->num_channels; i++) {
247 struct hostapd_channel_data *chan = &mode->channels[i];
248 if (chan->flag & HOSTAPD_CHAN_DISABLED)
251 prev->chan + chan_spacing == chan->chan &&
252 start->max_tx_power == chan->max_tx_power) {
254 continue; /* can use same entry */
258 pos = hostapd_eid_country_add(pos, end, chan_spacing,
263 /* Start new group */
268 pos = hostapd_eid_country_add(pos, end, chan_spacing,
272 if ((pos - eid) & 1) {
275 *pos++ = 0; /* pad for 16-bit alignment */
278 eid[1] = (pos - eid) - 2;
284 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
289 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
290 if (ie == NULL || ielen > len)
293 os_memcpy(eid, ie, ielen);
298 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
300 if (!hapd->cs_freq_params.channel)
303 *eid++ = WLAN_EID_CHANNEL_SWITCH;
305 *eid++ = hapd->cs_block_tx;
306 *eid++ = hapd->cs_freq_params.channel;
307 *eid++ = hapd->cs_count;
313 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
317 if (!hapd->cs_freq_params.sec_channel_offset)
320 if (hapd->cs_freq_params.sec_channel_offset == -1)
321 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
322 else if (hapd->cs_freq_params.sec_channel_offset == 1)
323 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
327 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
335 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
336 u8 *start, unsigned int *csa_counter_off)
340 if (!csa_counter_off)
343 *csa_counter_off = 0;
344 pos = hostapd_eid_csa(hapd, pos);
346 if (pos != old_pos) {
347 /* save an offset to the counter - should be last byte */
348 *csa_counter_off = pos - start - 1;
349 pos = hostapd_eid_secondary_channel(hapd, pos);
350 #ifdef CONFIG_IEEE80211AC
351 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
352 #endif /* CONFIG_IEEE80211AC */
359 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
360 const struct ieee80211_mgmt *req,
361 int is_p2p, size_t *resp_len)
363 struct ieee80211_mgmt *resp;
367 #define MAX_PROBERESP_LEN 768
368 buflen = MAX_PROBERESP_LEN;
370 if (hapd->wps_probe_resp_ie)
371 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
372 #endif /* CONFIG_WPS */
374 if (hapd->p2p_probe_resp_ie)
375 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
376 #endif /* CONFIG_P2P */
378 if (hapd->iface->fst_ies)
379 buflen += wpabuf_len(hapd->iface->fst_ies);
380 #endif /* CONFIG_FST */
381 if (hapd->conf->vendor_elements)
382 buflen += wpabuf_len(hapd->conf->vendor_elements);
383 if (hapd->conf->vendor_vht) {
384 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
385 2 + sizeof(struct ieee80211_vht_operation);
387 resp = os_zalloc(buflen);
391 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
393 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
394 WLAN_FC_STYPE_PROBE_RESP);
396 os_memcpy(resp->da, req->sa, ETH_ALEN);
397 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
399 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
400 resp->u.probe_resp.beacon_int =
401 host_to_le16(hapd->iconf->beacon_int);
403 /* hardware or low-level driver will setup seq_ctrl and timestamp */
404 resp->u.probe_resp.capab_info =
405 host_to_le16(hostapd_own_capab_info(hapd));
407 pos = resp->u.probe_resp.variable;
408 *pos++ = WLAN_EID_SSID;
409 *pos++ = hapd->conf->ssid.ssid_len;
410 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
411 pos += hapd->conf->ssid.ssid_len;
413 /* Supported rates */
414 pos = hostapd_eid_supp_rates(hapd, pos);
417 pos = hostapd_eid_ds_params(hapd, pos);
419 pos = hostapd_eid_country(hapd, pos, epos - pos);
421 /* Power Constraint element */
422 pos = hostapd_eid_pwr_constraint(hapd, pos);
424 /* ERP Information element */
425 pos = hostapd_eid_erp_info(hapd, pos);
427 /* Extended supported rates */
428 pos = hostapd_eid_ext_supp_rates(hapd, pos);
431 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
433 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
435 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
437 #ifdef CONFIG_IEEE80211N
438 pos = hostapd_eid_ht_capabilities(hapd, pos);
439 pos = hostapd_eid_ht_operation(hapd, pos);
440 #endif /* CONFIG_IEEE80211N */
442 pos = hostapd_eid_ext_capab(hapd, pos);
444 pos = hostapd_eid_time_adv(hapd, pos);
445 pos = hostapd_eid_time_zone(hapd, pos);
447 pos = hostapd_eid_interworking(hapd, pos);
448 pos = hostapd_eid_adv_proto(hapd, pos);
449 pos = hostapd_eid_roaming_consortium(hapd, pos);
451 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
452 &hapd->cs_c_off_proberesp);
455 if (hapd->iface->fst_ies) {
456 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
457 wpabuf_len(hapd->iface->fst_ies));
458 pos += wpabuf_len(hapd->iface->fst_ies);
460 #endif /* CONFIG_FST */
462 #ifdef CONFIG_IEEE80211AC
463 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
464 pos = hostapd_eid_vht_capabilities(hapd, pos);
465 pos = hostapd_eid_vht_operation(hapd, pos);
467 if (hapd->conf->vendor_vht)
468 pos = hostapd_eid_vendor_vht(hapd, pos);
469 #endif /* CONFIG_IEEE80211AC */
471 /* Wi-Fi Alliance WMM */
472 pos = hostapd_eid_wmm(hapd, pos);
475 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
476 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
477 wpabuf_len(hapd->wps_probe_resp_ie));
478 pos += wpabuf_len(hapd->wps_probe_resp_ie);
480 #endif /* CONFIG_WPS */
483 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
484 hapd->p2p_probe_resp_ie) {
485 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
486 wpabuf_len(hapd->p2p_probe_resp_ie));
487 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
489 #endif /* CONFIG_P2P */
490 #ifdef CONFIG_P2P_MANAGER
491 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
493 pos = hostapd_eid_p2p_manage(hapd, pos);
494 #endif /* CONFIG_P2P_MANAGER */
497 pos = hostapd_eid_hs20_indication(hapd, pos);
498 pos = hostapd_eid_osen(hapd, pos);
499 #endif /* CONFIG_HS20 */
501 if (hapd->conf->vendor_elements) {
502 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
503 wpabuf_len(hapd->conf->vendor_elements));
504 pos += wpabuf_len(hapd->conf->vendor_elements);
507 *resp_len = pos - (u8 *) resp;
512 enum ssid_match_result {
518 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
519 const u8 *ssid, size_t ssid_len,
521 size_t ssid_list_len)
528 if (ssid_len == hapd->conf->ssid.ssid_len &&
529 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
530 return EXACT_SSID_MATCH;
532 if (ssid_list == NULL)
533 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
536 end = ssid_list + ssid_list_len;
537 while (pos + 1 <= end) {
538 if (pos + 2 + pos[1] > end)
542 if (pos[1] == hapd->conf->ssid.ssid_len &&
543 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
544 return EXACT_SSID_MATCH;
548 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
552 void sta_track_expire(struct hostapd_iface *iface, int force)
554 struct os_reltime now;
555 struct hostapd_sta_info *info;
557 if (!iface->num_sta_seen)
560 os_get_reltime(&now);
561 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
564 !os_reltime_expired(&now, &info->last_seen,
565 iface->conf->track_sta_max_age))
569 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
570 MACSTR, iface->bss[0]->conf->iface,
571 MAC2STR(info->addr));
572 dl_list_del(&info->list);
573 iface->num_sta_seen--;
579 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
582 struct hostapd_sta_info *info;
584 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
585 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
592 void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
594 struct hostapd_sta_info *info;
596 info = sta_track_get(iface, addr);
598 /* Move the most recent entry to the end of the list */
599 dl_list_del(&info->list);
600 dl_list_add_tail(&iface->sta_seen, &info->list);
601 os_get_reltime(&info->last_seen);
605 /* Add a new entry */
606 info = os_zalloc(sizeof(*info));
607 os_memcpy(info->addr, addr, ETH_ALEN);
608 os_get_reltime(&info->last_seen);
610 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
611 /* Expire oldest entry to make room for a new one */
612 sta_track_expire(iface, 1);
615 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
616 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
617 dl_list_add_tail(&iface->sta_seen, &info->list);
618 iface->num_sta_seen++;
622 struct hostapd_data *
623 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
626 struct hapd_interfaces *interfaces = iface->interfaces;
629 for (i = 0; i < interfaces->count; i++) {
630 struct hostapd_data *hapd = NULL;
632 iface = interfaces->iface[i];
633 for (j = 0; j < iface->num_bss; j++) {
634 hapd = iface->bss[j];
635 if (os_strcmp(ifname, hapd->conf->iface) == 0)
640 if (hapd && sta_track_get(iface, addr))
648 void handle_probe_req(struct hostapd_data *hapd,
649 const struct ieee80211_mgmt *mgmt, size_t len,
653 struct ieee802_11_elems elems;
658 enum ssid_match_result res;
660 ie = mgmt->u.probe_req.variable;
661 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
663 if (hapd->iconf->track_sta_max_num)
664 sta_track_add(hapd->iface, mgmt->sa);
665 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
667 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
668 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
669 mgmt->sa, mgmt->da, mgmt->bssid,
670 ie, ie_len, ssi_signal) > 0)
673 if (!hapd->iconf->send_probe_response)
676 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
677 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
682 if ((!elems.ssid || !elems.supp_rates)) {
683 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
684 "without SSID or supported rates element",
690 * No need to reply if the Probe Request frame was sent on an adjacent
691 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
692 * AP with dot11RadioMeasurementActivated set to true, but strictly
693 * speaking does not allow such ignoring of Probe Request frames if
694 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
695 * number of unnecessary Probe Response frames for cases where the STA
696 * is less likely to see them (Probe Request frame sent on a
697 * neighboring, but partially overlapping, channel).
699 if (elems.ds_params &&
700 hapd->iface->current_mode &&
701 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
702 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
703 hapd->iconf->channel != elems.ds_params[0]) {
704 wpa_printf(MSG_DEBUG,
705 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
706 hapd->iconf->channel, elems.ds_params[0]);
711 if (hapd->p2p && elems.wps_ie) {
713 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
714 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
715 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
716 "due to mismatch with Requested Device "
724 if (hapd->p2p && elems.p2p) {
726 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
727 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
728 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
729 "due to mismatch with Device ID");
735 #endif /* CONFIG_P2P */
737 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
738 elems.ssid_list_len == 0) {
739 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
740 "broadcast SSID ignored", MAC2STR(mgmt->sa));
745 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
746 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
747 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
748 P2P_WILDCARD_SSID_LEN) == 0) {
749 /* Process P2P Wildcard SSID like Wildcard SSID */
752 #endif /* CONFIG_P2P */
754 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
755 elems.ssid_list, elems.ssid_list_len);
756 if (res == NO_SSID_MATCH) {
757 if (!(mgmt->da[0] & 0x01)) {
758 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
759 " for foreign SSID '%s' (DA " MACSTR ")%s",
761 wpa_ssid_txt(elems.ssid, elems.ssid_len),
763 elems.ssid_list ? " (SSID list)" : "");
768 #ifdef CONFIG_INTERWORKING
769 if (hapd->conf->interworking &&
770 elems.interworking && elems.interworking_len >= 1) {
771 u8 ant = elems.interworking[0] & 0x0f;
772 if (ant != INTERWORKING_ANT_WILDCARD &&
773 ant != hapd->conf->access_network_type) {
774 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
775 " for mismatching ANT %u ignored",
776 MAC2STR(mgmt->sa), ant);
781 if (hapd->conf->interworking && elems.interworking &&
782 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
784 if (elems.interworking_len == 7)
785 hessid = elems.interworking + 1;
787 hessid = elems.interworking + 1 + 2;
788 if (!is_broadcast_ether_addr(hessid) &&
789 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
790 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
791 " for mismatching HESSID " MACSTR
793 MAC2STR(mgmt->sa), MAC2STR(hessid));
797 #endif /* CONFIG_INTERWORKING */
800 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
801 supp_rates_11b_only(&elems)) {
802 /* Indicates support for 11b rates only */
803 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
804 MACSTR " with only 802.11b rates",
808 #endif /* CONFIG_P2P */
810 /* TODO: verify that supp_rates contains at least one matching rate
811 * with AP configuration */
813 if (hapd->conf->no_probe_resp_if_seen_on &&
814 is_multicast_ether_addr(mgmt->da) &&
815 is_multicast_ether_addr(mgmt->bssid) &&
816 sta_track_seen_on(hapd->iface, mgmt->sa,
817 hapd->conf->no_probe_resp_if_seen_on)) {
818 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
819 " since STA has been seen on %s",
820 hapd->conf->iface, MAC2STR(mgmt->sa),
821 hapd->conf->no_probe_resp_if_seen_on);
825 #ifdef CONFIG_TESTING_OPTIONS
826 if (hapd->iconf->ignore_probe_probability > 0.0 &&
827 drand48() < hapd->iconf->ignore_probe_probability) {
829 "TESTING: ignoring probe request from " MACSTR,
833 #endif /* CONFIG_TESTING_OPTIONS */
835 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
841 * If this is a broadcast probe request, apply no ack policy to avoid
844 noack = !!(res == WILDCARD_SSID_MATCH &&
845 is_broadcast_ether_addr(mgmt->da));
847 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
848 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
852 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
853 "SSID", MAC2STR(mgmt->sa),
854 elems.ssid_len == 0 ? "broadcast" : "our");
858 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
861 /* check probe response offloading caps and print warnings */
862 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
866 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
867 (!(hapd->iface->probe_resp_offloads &
868 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
869 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
870 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
871 "Probe Response while not supporting this");
872 #endif /* CONFIG_WPS */
875 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
876 !(hapd->iface->probe_resp_offloads &
877 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
878 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
879 "Probe Response while not supporting this");
880 #endif /* CONFIG_P2P */
882 if (hapd->conf->interworking &&
883 !(hapd->iface->probe_resp_offloads &
884 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
885 wpa_printf(MSG_WARNING, "Device is trying to offload "
886 "Interworking Probe Response while not supporting "
889 /* Generate a Probe Response template for the non-P2P case */
890 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
893 #endif /* NEED_AP_MLME */
896 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
897 struct wpa_driver_ap_params *params)
899 struct ieee80211_mgmt *head = NULL;
901 size_t head_len = 0, tail_len = 0;
908 #define BEACON_HEAD_BUF_SIZE 256
909 #define BEACON_TAIL_BUF_SIZE 512
910 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
911 tail_len = BEACON_TAIL_BUF_SIZE;
913 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
914 tail_len += wpabuf_len(hapd->wps_beacon_ie);
915 #endif /* CONFIG_WPS */
917 if (hapd->p2p_beacon_ie)
918 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
919 #endif /* CONFIG_P2P */
921 if (hapd->iface->fst_ies)
922 tail_len += wpabuf_len(hapd->iface->fst_ies);
923 #endif /* CONFIG_FST */
924 if (hapd->conf->vendor_elements)
925 tail_len += wpabuf_len(hapd->conf->vendor_elements);
927 #ifdef CONFIG_IEEE80211AC
928 if (hapd->conf->vendor_vht) {
929 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
930 2 + sizeof(struct ieee80211_vht_operation);
932 #endif /* CONFIG_IEEE80211AC */
934 tailpos = tail = os_malloc(tail_len);
935 if (head == NULL || tail == NULL) {
936 wpa_printf(MSG_ERROR, "Failed to set beacon data");
942 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
943 WLAN_FC_STYPE_BEACON);
944 head->duration = host_to_le16(0);
945 os_memset(head->da, 0xff, ETH_ALEN);
947 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
948 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
949 head->u.beacon.beacon_int =
950 host_to_le16(hapd->iconf->beacon_int);
952 /* hardware or low-level driver will setup seq_ctrl and timestamp */
953 capab_info = hostapd_own_capab_info(hapd);
954 head->u.beacon.capab_info = host_to_le16(capab_info);
955 pos = &head->u.beacon.variable[0];
958 *pos++ = WLAN_EID_SSID;
959 if (hapd->conf->ignore_broadcast_ssid == 2) {
960 /* clear the data, but keep the correct length of the SSID */
961 *pos++ = hapd->conf->ssid.ssid_len;
962 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
963 pos += hapd->conf->ssid.ssid_len;
964 } else if (hapd->conf->ignore_broadcast_ssid) {
965 *pos++ = 0; /* empty SSID */
967 *pos++ = hapd->conf->ssid.ssid_len;
968 os_memcpy(pos, hapd->conf->ssid.ssid,
969 hapd->conf->ssid.ssid_len);
970 pos += hapd->conf->ssid.ssid_len;
973 /* Supported rates */
974 pos = hostapd_eid_supp_rates(hapd, pos);
977 pos = hostapd_eid_ds_params(hapd, pos);
979 head_len = pos - (u8 *) head;
981 tailpos = hostapd_eid_country(hapd, tailpos,
982 tail + BEACON_TAIL_BUF_SIZE - tailpos);
984 /* Power Constraint element */
985 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
987 /* ERP Information element */
988 tailpos = hostapd_eid_erp_info(hapd, tailpos);
990 /* Extended supported rates */
991 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
994 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
997 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
998 tail + BEACON_TAIL_BUF_SIZE -
1001 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1002 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1004 #ifdef CONFIG_IEEE80211N
1005 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1006 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1007 #endif /* CONFIG_IEEE80211N */
1009 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1012 * TODO: Time Advertisement element should only be included in some
1013 * DTIM Beacon frames.
1015 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1017 tailpos = hostapd_eid_interworking(hapd, tailpos);
1018 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1019 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1020 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
1021 &hapd->cs_c_off_beacon);
1024 if (hapd->iface->fst_ies) {
1025 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1026 wpabuf_len(hapd->iface->fst_ies));
1027 tailpos += wpabuf_len(hapd->iface->fst_ies);
1029 #endif /* CONFIG_FST */
1031 #ifdef CONFIG_IEEE80211AC
1032 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1033 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
1034 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1036 if (hapd->conf->vendor_vht)
1037 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1038 #endif /* CONFIG_IEEE80211AC */
1040 /* Wi-Fi Alliance WMM */
1041 tailpos = hostapd_eid_wmm(hapd, tailpos);
1044 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1045 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1046 wpabuf_len(hapd->wps_beacon_ie));
1047 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1049 #endif /* CONFIG_WPS */
1052 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1053 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1054 wpabuf_len(hapd->p2p_beacon_ie));
1055 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1057 #endif /* CONFIG_P2P */
1058 #ifdef CONFIG_P2P_MANAGER
1059 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1061 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1062 #endif /* CONFIG_P2P_MANAGER */
1065 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1066 tailpos = hostapd_eid_osen(hapd, tailpos);
1067 #endif /* CONFIG_HS20 */
1069 if (hapd->conf->vendor_elements) {
1070 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1071 wpabuf_len(hapd->conf->vendor_elements));
1072 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1075 tail_len = tailpos > tail ? tailpos - tail : 0;
1077 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1078 #endif /* NEED_AP_MLME */
1080 os_memset(params, 0, sizeof(*params));
1081 params->head = (u8 *) head;
1082 params->head_len = head_len;
1083 params->tail = tail;
1084 params->tail_len = tail_len;
1085 params->proberesp = resp;
1086 params->proberesp_len = resp_len;
1087 params->dtim_period = hapd->conf->dtim_period;
1088 params->beacon_int = hapd->iconf->beacon_int;
1089 params->basic_rates = hapd->iface->basic_rates;
1090 params->ssid = hapd->conf->ssid.ssid;
1091 params->ssid_len = hapd->conf->ssid.ssid_len;
1092 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1093 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1094 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1095 hapd->conf->rsn_pairwise;
1096 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1097 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1098 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1099 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1100 params->group_cipher = hapd->conf->wpa_group;
1101 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1102 params->auth_algs = hapd->conf->auth_algs;
1103 params->wpa_version = hapd->conf->wpa;
1104 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1105 (hapd->conf->ieee802_1x &&
1106 (hapd->conf->default_wep_key_len ||
1107 hapd->conf->individual_wep_key_len));
1108 switch (hapd->conf->ignore_broadcast_ssid) {
1110 params->hide_ssid = NO_SSID_HIDING;
1113 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1116 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1119 params->isolate = hapd->conf->isolate;
1120 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1122 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1123 ERP_INFO_USE_PROTECTION);
1124 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1125 hapd->iconf->preamble == SHORT_PREAMBLE;
1126 if (hapd->iface->current_mode &&
1127 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1128 params->short_slot_time =
1129 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1131 params->short_slot_time = -1;
1132 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1133 params->ht_opmode = -1;
1135 params->ht_opmode = hapd->iface->ht_op_mode;
1136 #endif /* NEED_AP_MLME */
1137 params->interworking = hapd->conf->interworking;
1138 if (hapd->conf->interworking &&
1139 !is_zero_ether_addr(hapd->conf->hessid))
1140 params->hessid = hapd->conf->hessid;
1141 params->access_network_type = hapd->conf->access_network_type;
1142 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1144 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1145 #endif /* CONFIG_P2P */
1147 params->disable_dgaf = hapd->conf->disable_dgaf;
1148 if (hapd->conf->osen) {
1149 params->privacy = 1;
1152 #endif /* CONFIG_HS20 */
1157 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1159 os_free(params->tail);
1160 params->tail = NULL;
1161 os_free(params->head);
1162 params->head = NULL;
1163 os_free(params->proberesp);
1164 params->proberesp = NULL;
1168 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1170 struct wpa_driver_ap_params params;
1171 struct hostapd_freq_params freq;
1172 struct hostapd_iface *iface = hapd->iface;
1173 struct hostapd_config *iconf = iface->conf;
1174 struct wpabuf *beacon, *proberesp, *assocresp;
1177 if (hapd->csa_in_progress) {
1178 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1182 hapd->beacon_set_done = 1;
1184 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1187 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1191 params.beacon_ies = beacon;
1192 params.proberesp_ies = proberesp;
1193 params.assocresp_ies = assocresp;
1194 params.reenable = hapd->reenable_beacon;
1195 hapd->reenable_beacon = 0;
1197 if (iface->current_mode &&
1198 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1199 iconf->channel, iconf->ieee80211n,
1201 iconf->secondary_channel,
1202 iconf->vht_oper_chwidth,
1203 iconf->vht_oper_centr_freq_seg0_idx,
1204 iconf->vht_oper_centr_freq_seg1_idx,
1205 iface->current_mode->vht_capab) == 0)
1206 params.freq = &freq;
1208 res = hostapd_drv_set_ap(hapd, ¶ms);
1209 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1211 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1215 ieee802_11_free_ap_params(¶ms);
1220 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1225 for (i = 0; i < iface->num_bss; i++) {
1226 if (iface->bss[i]->started &&
1227 ieee802_11_set_beacon(iface->bss[i]) < 0)
1235 /* only update beacons if started */
1236 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1241 for (i = 0; i < iface->num_bss; i++) {
1242 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1243 ieee802_11_set_beacon(iface->bss[i]) < 0)
1250 #endif /* CONFIG_NATIVE_WINDOWS */