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,
41 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
42 if (hapd->conf->radio_measurements[i])
46 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
49 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
50 *eid++ = RRM_CAPABILITIES_IE_LEN;
51 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
53 return eid + RRM_CAPABILITIES_IE_LEN;
57 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
62 #ifdef CONFIG_TESTING_OPTIONS
63 if (hapd->conf->bss_load_test_set) {
64 *eid++ = WLAN_EID_BSS_LOAD;
66 os_memcpy(eid, hapd->conf->bss_load_test, 5);
70 #endif /* CONFIG_TESTING_OPTIONS */
71 if (hapd->conf->bss_load_update_period) {
72 *eid++ = WLAN_EID_BSS_LOAD;
74 WPA_PUT_LE16(eid, hapd->num_sta);
76 *eid++ = hapd->iface->channel_utilization;
77 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
84 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
88 if (hapd->iface->current_mode == NULL ||
89 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
92 if (hapd->iface->olbc)
93 erp |= ERP_INFO_USE_PROTECTION;
94 if (hapd->iface->num_sta_non_erp > 0) {
95 erp |= ERP_INFO_NON_ERP_PRESENT |
96 ERP_INFO_USE_PROTECTION;
98 if (hapd->iface->num_sta_no_short_preamble > 0 ||
99 hapd->iconf->preamble == LONG_PREAMBLE)
100 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
106 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
108 *eid++ = WLAN_EID_DS_PARAMS;
110 *eid++ = hapd->iconf->channel;
115 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
117 if (hapd->iface->current_mode == NULL ||
118 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
121 /* Set NonERP_present and use_protection bits if there
122 * are any associated NonERP stations. */
123 /* TODO: use_protection bit can be set to zero even if
124 * there are NonERP stations present. This optimization
125 * might be useful if NonERP stations are "quiet".
126 * See 802.11g/D6 E-1 for recommended practice.
127 * In addition, Non ERP present might be set, if AP detects Non ERP
128 * operation on other APs. */
130 /* Add ERP Information element */
131 *eid++ = WLAN_EID_ERP_INFO;
133 *eid++ = ieee802_11_erp_info(hapd);
139 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
142 u8 local_pwr_constraint = 0;
145 if (hapd->iface->current_mode == NULL ||
146 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
149 /* Let host drivers add this IE if DFS support is offloaded */
150 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
154 * There is no DFS support and power constraint was not directly
155 * requested by config option.
157 if (!hapd->iconf->ieee80211h &&
158 hapd->iconf->local_pwr_constraint == -1)
161 /* Check if DFS is required by regulatory. */
162 dfs = hostapd_is_dfs_required(hapd->iface);
164 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
169 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
173 * ieee80211h (DFS) is enabled so Power Constraint element shall
174 * be added when running on DFS channel whenever local_pwr_constraint
175 * is configured or not. In order to meet regulations when TPC is not
176 * implemented using a transmit power that is below the legal maximum
177 * (including any mitigation factor) should help. In this case,
178 * indicate 3 dB below maximum allowed transmit power.
180 if (hapd->iconf->local_pwr_constraint == -1)
181 local_pwr_constraint = 3;
184 * A STA that is not an AP shall use a transmit power less than or
185 * equal to the local maximum transmit power level for the channel.
186 * The local maximum transmit power can be calculated from the formula:
187 * local max TX pwr = max TX pwr - local pwr constraint
188 * Where max TX pwr is maximum transmit power level specified for
189 * channel in Country element and local pwr constraint is specified
190 * for channel in this Power Constraint element.
194 *pos++ = WLAN_EID_PWR_CONSTRAINT;
197 /* Local Power Constraint */
198 if (local_pwr_constraint)
199 *pos++ = local_pwr_constraint;
201 *pos++ = hapd->iconf->local_pwr_constraint;
207 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
208 struct hostapd_channel_data *start,
209 struct hostapd_channel_data *prev)
214 /* first channel number */
215 *pos++ = start->chan;
216 /* number of channels */
217 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
218 /* maximum transmit power level */
219 *pos++ = start->max_tx_power;
225 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
229 u8 *end = eid + max_len;
231 struct hostapd_hw_modes *mode;
232 struct hostapd_channel_data *start, *prev;
233 int chan_spacing = 1;
235 if (!hapd->iconf->ieee80211d || max_len < 6 ||
236 hapd->iface->current_mode == NULL)
239 *pos++ = WLAN_EID_COUNTRY;
240 pos++; /* length will be set later */
241 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
244 mode = hapd->iface->current_mode;
245 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
249 for (i = 0; i < mode->num_channels; i++) {
250 struct hostapd_channel_data *chan = &mode->channels[i];
251 if (chan->flag & HOSTAPD_CHAN_DISABLED)
254 prev->chan + chan_spacing == chan->chan &&
255 start->max_tx_power == chan->max_tx_power) {
257 continue; /* can use same entry */
261 pos = hostapd_eid_country_add(pos, end, chan_spacing,
266 /* Start new group */
271 pos = hostapd_eid_country_add(pos, end, chan_spacing,
275 if ((pos - eid) & 1) {
278 *pos++ = 0; /* pad for 16-bit alignment */
281 eid[1] = (pos - eid) - 2;
287 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
292 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
293 if (ie == NULL || ielen > len)
296 os_memcpy(eid, ie, ielen);
301 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
303 #ifdef CONFIG_TESTING_OPTIONS
304 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
306 #endif /* CONFIG_TESTING_OPTIONS */
308 if (!hapd->cs_freq_params.channel)
311 *eid++ = WLAN_EID_CHANNEL_SWITCH;
313 *eid++ = hapd->cs_block_tx;
314 *eid++ = hapd->cs_freq_params.channel;
315 *eid++ = hapd->cs_count;
321 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
323 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
326 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
328 *eid++ = hapd->cs_block_tx;
329 *eid++ = hapd->iface->cs_oper_class;
330 *eid++ = hapd->cs_freq_params.channel;
331 *eid++ = hapd->cs_count;
337 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
339 u8 op_class, channel;
341 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
345 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
346 hapd->iconf->secondary_channel,
347 hapd->iconf->vht_oper_chwidth,
348 &op_class, &channel) ==
352 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
355 /* Current Operating Class */
358 /* TODO: Advertise all the supported operating classes */
365 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
366 const struct ieee80211_mgmt *req,
367 int is_p2p, size_t *resp_len)
369 struct ieee80211_mgmt *resp;
370 u8 *pos, *epos, *csa_pos;
373 #define MAX_PROBERESP_LEN 768
374 buflen = MAX_PROBERESP_LEN;
376 if (hapd->wps_probe_resp_ie)
377 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
378 #endif /* CONFIG_WPS */
380 if (hapd->p2p_probe_resp_ie)
381 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
382 #endif /* CONFIG_P2P */
384 if (hapd->iface->fst_ies)
385 buflen += wpabuf_len(hapd->iface->fst_ies);
386 #endif /* CONFIG_FST */
387 if (hapd->conf->vendor_elements)
388 buflen += wpabuf_len(hapd->conf->vendor_elements);
389 if (hapd->conf->vendor_vht) {
390 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
391 2 + sizeof(struct ieee80211_vht_operation);
394 buflen += hostapd_mbo_ie_len(hapd);
396 resp = os_zalloc(buflen);
400 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
402 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
403 WLAN_FC_STYPE_PROBE_RESP);
405 os_memcpy(resp->da, req->sa, ETH_ALEN);
406 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
408 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
409 resp->u.probe_resp.beacon_int =
410 host_to_le16(hapd->iconf->beacon_int);
412 /* hardware or low-level driver will setup seq_ctrl and timestamp */
413 resp->u.probe_resp.capab_info =
414 host_to_le16(hostapd_own_capab_info(hapd));
416 pos = resp->u.probe_resp.variable;
417 *pos++ = WLAN_EID_SSID;
418 *pos++ = hapd->conf->ssid.ssid_len;
419 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
420 pos += hapd->conf->ssid.ssid_len;
422 /* Supported rates */
423 pos = hostapd_eid_supp_rates(hapd, pos);
426 pos = hostapd_eid_ds_params(hapd, pos);
428 pos = hostapd_eid_country(hapd, pos, epos - pos);
430 /* Power Constraint element */
431 pos = hostapd_eid_pwr_constraint(hapd, pos);
434 csa_pos = hostapd_eid_csa(hapd, pos);
436 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
439 /* ERP Information element */
440 pos = hostapd_eid_erp_info(hapd, pos);
442 /* Extended supported rates */
443 pos = hostapd_eid_ext_supp_rates(hapd, pos);
446 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
448 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
450 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
453 csa_pos = hostapd_eid_ecsa(hapd, pos);
455 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
458 pos = hostapd_eid_supported_op_classes(hapd, pos);
460 #ifdef CONFIG_IEEE80211N
461 /* Secondary Channel Offset element */
462 /* TODO: The standard doesn't specify a position for this element. */
463 pos = hostapd_eid_secondary_channel(hapd, pos);
465 pos = hostapd_eid_ht_capabilities(hapd, pos);
466 pos = hostapd_eid_ht_operation(hapd, pos);
467 #endif /* CONFIG_IEEE80211N */
469 pos = hostapd_eid_ext_capab(hapd, pos);
471 pos = hostapd_eid_time_adv(hapd, pos);
472 pos = hostapd_eid_time_zone(hapd, pos);
474 pos = hostapd_eid_interworking(hapd, pos);
475 pos = hostapd_eid_adv_proto(hapd, pos);
476 pos = hostapd_eid_roaming_consortium(hapd, pos);
479 if (hapd->iface->fst_ies) {
480 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
481 wpabuf_len(hapd->iface->fst_ies));
482 pos += wpabuf_len(hapd->iface->fst_ies);
484 #endif /* CONFIG_FST */
486 #ifdef CONFIG_IEEE80211AC
487 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
488 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
489 pos = hostapd_eid_vht_operation(hapd, pos);
490 pos = hostapd_eid_txpower_envelope(hapd, pos);
491 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
493 if (hapd->conf->vendor_vht)
494 pos = hostapd_eid_vendor_vht(hapd, pos);
495 #endif /* CONFIG_IEEE80211AC */
497 /* Wi-Fi Alliance WMM */
498 pos = hostapd_eid_wmm(hapd, pos);
501 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
502 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
503 wpabuf_len(hapd->wps_probe_resp_ie));
504 pos += wpabuf_len(hapd->wps_probe_resp_ie);
506 #endif /* CONFIG_WPS */
509 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
510 hapd->p2p_probe_resp_ie) {
511 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
512 wpabuf_len(hapd->p2p_probe_resp_ie));
513 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
515 #endif /* CONFIG_P2P */
516 #ifdef CONFIG_P2P_MANAGER
517 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
519 pos = hostapd_eid_p2p_manage(hapd, pos);
520 #endif /* CONFIG_P2P_MANAGER */
523 pos = hostapd_eid_hs20_indication(hapd, pos);
524 pos = hostapd_eid_osen(hapd, pos);
525 #endif /* CONFIG_HS20 */
527 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
529 if (hapd->conf->vendor_elements) {
530 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
531 wpabuf_len(hapd->conf->vendor_elements));
532 pos += wpabuf_len(hapd->conf->vendor_elements);
535 *resp_len = pos - (u8 *) resp;
540 enum ssid_match_result {
546 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
547 const u8 *ssid, size_t ssid_len,
549 size_t ssid_list_len)
556 if (ssid_len == hapd->conf->ssid.ssid_len &&
557 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
558 return EXACT_SSID_MATCH;
560 if (ssid_list == NULL)
561 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
564 end = ssid_list + ssid_list_len;
565 while (end - pos >= 1) {
566 if (2 + pos[1] > end - pos)
570 if (pos[1] == hapd->conf->ssid.ssid_len &&
571 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
572 return EXACT_SSID_MATCH;
576 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
580 void sta_track_expire(struct hostapd_iface *iface, int force)
582 struct os_reltime now;
583 struct hostapd_sta_info *info;
585 if (!iface->num_sta_seen)
588 os_get_reltime(&now);
589 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
592 !os_reltime_expired(&now, &info->last_seen,
593 iface->conf->track_sta_max_age))
597 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
598 MACSTR, iface->bss[0]->conf->iface,
599 MAC2STR(info->addr));
600 dl_list_del(&info->list);
601 iface->num_sta_seen--;
607 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
610 struct hostapd_sta_info *info;
612 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
613 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
620 void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
622 struct hostapd_sta_info *info;
624 info = sta_track_get(iface, addr);
626 /* Move the most recent entry to the end of the list */
627 dl_list_del(&info->list);
628 dl_list_add_tail(&iface->sta_seen, &info->list);
629 os_get_reltime(&info->last_seen);
633 /* Add a new entry */
634 info = os_zalloc(sizeof(*info));
637 os_memcpy(info->addr, addr, ETH_ALEN);
638 os_get_reltime(&info->last_seen);
640 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
641 /* Expire oldest entry to make room for a new one */
642 sta_track_expire(iface, 1);
645 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
646 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
647 dl_list_add_tail(&iface->sta_seen, &info->list);
648 iface->num_sta_seen++;
652 struct hostapd_data *
653 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
656 struct hapd_interfaces *interfaces = iface->interfaces;
659 for (i = 0; i < interfaces->count; i++) {
660 struct hostapd_data *hapd = NULL;
662 iface = interfaces->iface[i];
663 for (j = 0; j < iface->num_bss; j++) {
664 hapd = iface->bss[j];
665 if (os_strcmp(ifname, hapd->conf->iface) == 0)
670 if (hapd && sta_track_get(iface, addr))
678 void handle_probe_req(struct hostapd_data *hapd,
679 const struct ieee80211_mgmt *mgmt, size_t len,
683 struct ieee802_11_elems elems;
688 enum ssid_match_result res;
693 if (len < IEEE80211_HDRLEN)
695 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
696 if (hapd->iconf->track_sta_max_num)
697 sta_track_add(hapd->iface, mgmt->sa);
698 ie_len = len - IEEE80211_HDRLEN;
700 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
701 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
702 mgmt->sa, mgmt->da, mgmt->bssid,
703 ie, ie_len, ssi_signal) > 0)
706 if (!hapd->iconf->send_probe_response)
709 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
710 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
715 if ((!elems.ssid || !elems.supp_rates)) {
716 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
717 "without SSID or supported rates element",
723 * No need to reply if the Probe Request frame was sent on an adjacent
724 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
725 * AP with dot11RadioMeasurementActivated set to true, but strictly
726 * speaking does not allow such ignoring of Probe Request frames if
727 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
728 * number of unnecessary Probe Response frames for cases where the STA
729 * is less likely to see them (Probe Request frame sent on a
730 * neighboring, but partially overlapping, channel).
732 if (elems.ds_params &&
733 hapd->iface->current_mode &&
734 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
735 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
736 hapd->iconf->channel != elems.ds_params[0]) {
737 wpa_printf(MSG_DEBUG,
738 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
739 hapd->iconf->channel, elems.ds_params[0]);
744 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
746 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
747 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
748 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
749 "due to mismatch with Requested Device "
757 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
759 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
760 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
761 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
762 "due to mismatch with Device ID");
768 #endif /* CONFIG_P2P */
770 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
771 elems.ssid_list_len == 0) {
772 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
773 "broadcast SSID ignored", MAC2STR(mgmt->sa));
778 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
779 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
780 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
781 P2P_WILDCARD_SSID_LEN) == 0) {
782 /* Process P2P Wildcard SSID like Wildcard SSID */
785 #endif /* CONFIG_P2P */
787 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
788 elems.ssid_list, elems.ssid_list_len);
789 if (res == NO_SSID_MATCH) {
790 if (!(mgmt->da[0] & 0x01)) {
791 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
792 " for foreign SSID '%s' (DA " MACSTR ")%s",
794 wpa_ssid_txt(elems.ssid, elems.ssid_len),
796 elems.ssid_list ? " (SSID list)" : "");
801 #ifdef CONFIG_INTERWORKING
802 if (hapd->conf->interworking &&
803 elems.interworking && elems.interworking_len >= 1) {
804 u8 ant = elems.interworking[0] & 0x0f;
805 if (ant != INTERWORKING_ANT_WILDCARD &&
806 ant != hapd->conf->access_network_type) {
807 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
808 " for mismatching ANT %u ignored",
809 MAC2STR(mgmt->sa), ant);
814 if (hapd->conf->interworking && elems.interworking &&
815 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
817 if (elems.interworking_len == 7)
818 hessid = elems.interworking + 1;
820 hessid = elems.interworking + 1 + 2;
821 if (!is_broadcast_ether_addr(hessid) &&
822 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
823 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
824 " for mismatching HESSID " MACSTR
826 MAC2STR(mgmt->sa), MAC2STR(hessid));
830 #endif /* CONFIG_INTERWORKING */
833 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
834 supp_rates_11b_only(&elems)) {
835 /* Indicates support for 11b rates only */
836 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
837 MACSTR " with only 802.11b rates",
841 #endif /* CONFIG_P2P */
843 /* TODO: verify that supp_rates contains at least one matching rate
844 * with AP configuration */
846 if (hapd->conf->no_probe_resp_if_seen_on &&
847 is_multicast_ether_addr(mgmt->da) &&
848 is_multicast_ether_addr(mgmt->bssid) &&
849 sta_track_seen_on(hapd->iface, mgmt->sa,
850 hapd->conf->no_probe_resp_if_seen_on)) {
851 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
852 " since STA has been seen on %s",
853 hapd->conf->iface, MAC2STR(mgmt->sa),
854 hapd->conf->no_probe_resp_if_seen_on);
858 if (hapd->conf->no_probe_resp_if_max_sta &&
859 is_multicast_ether_addr(mgmt->da) &&
860 is_multicast_ether_addr(mgmt->bssid) &&
861 hapd->num_sta >= hapd->conf->max_num_sta &&
862 !ap_get_sta(hapd, mgmt->sa)) {
863 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
864 " since no room for additional STA",
865 hapd->conf->iface, MAC2STR(mgmt->sa));
869 #ifdef CONFIG_TESTING_OPTIONS
870 if (hapd->iconf->ignore_probe_probability > 0.0 &&
871 drand48() < hapd->iconf->ignore_probe_probability) {
873 "TESTING: ignoring probe request from " MACSTR,
877 #endif /* CONFIG_TESTING_OPTIONS */
879 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
885 * If this is a broadcast probe request, apply no ack policy to avoid
888 noack = !!(res == WILDCARD_SSID_MATCH &&
889 is_broadcast_ether_addr(mgmt->da));
892 if (hapd->csa_in_progress) {
893 if (hapd->cs_c_off_proberesp)
894 csa_offs[csa_offs_len++] =
895 hapd->cs_c_off_proberesp;
897 if (hapd->cs_c_off_ecsa_proberesp)
898 csa_offs[csa_offs_len++] =
899 hapd->cs_c_off_ecsa_proberesp;
902 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
903 csa_offs_len ? csa_offs : NULL,
907 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
911 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
912 "SSID", MAC2STR(mgmt->sa),
913 elems.ssid_len == 0 ? "broadcast" : "our");
917 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
920 /* check probe response offloading caps and print warnings */
921 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
925 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
926 (!(hapd->iface->probe_resp_offloads &
927 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
928 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
929 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
930 "Probe Response while not supporting this");
931 #endif /* CONFIG_WPS */
934 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
935 !(hapd->iface->probe_resp_offloads &
936 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
937 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
938 "Probe Response while not supporting this");
939 #endif /* CONFIG_P2P */
941 if (hapd->conf->interworking &&
942 !(hapd->iface->probe_resp_offloads &
943 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
944 wpa_printf(MSG_WARNING, "Device is trying to offload "
945 "Interworking Probe Response while not supporting "
948 /* Generate a Probe Response template for the non-P2P case */
949 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
952 #endif /* NEED_AP_MLME */
955 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
956 struct wpa_driver_ap_params *params)
958 struct ieee80211_mgmt *head = NULL;
960 size_t head_len = 0, tail_len = 0;
965 u8 *pos, *tailpos, *csa_pos;
967 #define BEACON_HEAD_BUF_SIZE 256
968 #define BEACON_TAIL_BUF_SIZE 512
969 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
970 tail_len = BEACON_TAIL_BUF_SIZE;
972 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
973 tail_len += wpabuf_len(hapd->wps_beacon_ie);
974 #endif /* CONFIG_WPS */
976 if (hapd->p2p_beacon_ie)
977 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
978 #endif /* CONFIG_P2P */
980 if (hapd->iface->fst_ies)
981 tail_len += wpabuf_len(hapd->iface->fst_ies);
982 #endif /* CONFIG_FST */
983 if (hapd->conf->vendor_elements)
984 tail_len += wpabuf_len(hapd->conf->vendor_elements);
986 #ifdef CONFIG_IEEE80211AC
987 if (hapd->conf->vendor_vht) {
988 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
989 2 + sizeof(struct ieee80211_vht_operation);
991 #endif /* CONFIG_IEEE80211AC */
993 tail_len += hostapd_mbo_ie_len(hapd);
995 tailpos = tail = os_malloc(tail_len);
996 if (head == NULL || tail == NULL) {
997 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1003 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1004 WLAN_FC_STYPE_BEACON);
1005 head->duration = host_to_le16(0);
1006 os_memset(head->da, 0xff, ETH_ALEN);
1008 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1009 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1010 head->u.beacon.beacon_int =
1011 host_to_le16(hapd->iconf->beacon_int);
1013 /* hardware or low-level driver will setup seq_ctrl and timestamp */
1014 capab_info = hostapd_own_capab_info(hapd);
1015 head->u.beacon.capab_info = host_to_le16(capab_info);
1016 pos = &head->u.beacon.variable[0];
1019 *pos++ = WLAN_EID_SSID;
1020 if (hapd->conf->ignore_broadcast_ssid == 2) {
1021 /* clear the data, but keep the correct length of the SSID */
1022 *pos++ = hapd->conf->ssid.ssid_len;
1023 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1024 pos += hapd->conf->ssid.ssid_len;
1025 } else if (hapd->conf->ignore_broadcast_ssid) {
1026 *pos++ = 0; /* empty SSID */
1028 *pos++ = hapd->conf->ssid.ssid_len;
1029 os_memcpy(pos, hapd->conf->ssid.ssid,
1030 hapd->conf->ssid.ssid_len);
1031 pos += hapd->conf->ssid.ssid_len;
1034 /* Supported rates */
1035 pos = hostapd_eid_supp_rates(hapd, pos);
1038 pos = hostapd_eid_ds_params(hapd, pos);
1040 head_len = pos - (u8 *) head;
1042 tailpos = hostapd_eid_country(hapd, tailpos,
1043 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1045 /* Power Constraint element */
1046 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1049 csa_pos = hostapd_eid_csa(hapd, tailpos);
1050 if (csa_pos != tailpos)
1051 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1054 /* ERP Information element */
1055 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1057 /* Extended supported rates */
1058 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1060 /* RSN, MDIE, WPA */
1061 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
1064 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1065 tail + BEACON_TAIL_BUF_SIZE -
1068 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1069 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1072 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1073 if (csa_pos != tailpos)
1074 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1077 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1079 #ifdef CONFIG_IEEE80211N
1080 /* Secondary Channel Offset element */
1081 /* TODO: The standard doesn't specify a position for this element. */
1082 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1084 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1085 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1086 #endif /* CONFIG_IEEE80211N */
1088 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1091 * TODO: Time Advertisement element should only be included in some
1092 * DTIM Beacon frames.
1094 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1096 tailpos = hostapd_eid_interworking(hapd, tailpos);
1097 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1098 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1101 if (hapd->iface->fst_ies) {
1102 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1103 wpabuf_len(hapd->iface->fst_ies));
1104 tailpos += wpabuf_len(hapd->iface->fst_ies);
1106 #endif /* CONFIG_FST */
1108 #ifdef CONFIG_IEEE80211AC
1109 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1110 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
1111 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1112 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1113 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1115 if (hapd->conf->vendor_vht)
1116 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1117 #endif /* CONFIG_IEEE80211AC */
1119 /* Wi-Fi Alliance WMM */
1120 tailpos = hostapd_eid_wmm(hapd, tailpos);
1123 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1124 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1125 wpabuf_len(hapd->wps_beacon_ie));
1126 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1128 #endif /* CONFIG_WPS */
1131 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1132 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1133 wpabuf_len(hapd->p2p_beacon_ie));
1134 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1136 #endif /* CONFIG_P2P */
1137 #ifdef CONFIG_P2P_MANAGER
1138 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1140 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1141 #endif /* CONFIG_P2P_MANAGER */
1144 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1145 tailpos = hostapd_eid_osen(hapd, tailpos);
1146 #endif /* CONFIG_HS20 */
1148 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1150 if (hapd->conf->vendor_elements) {
1151 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1152 wpabuf_len(hapd->conf->vendor_elements));
1153 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1156 tail_len = tailpos > tail ? tailpos - tail : 0;
1158 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1159 #endif /* NEED_AP_MLME */
1161 os_memset(params, 0, sizeof(*params));
1162 params->head = (u8 *) head;
1163 params->head_len = head_len;
1164 params->tail = tail;
1165 params->tail_len = tail_len;
1166 params->proberesp = resp;
1167 params->proberesp_len = resp_len;
1168 params->dtim_period = hapd->conf->dtim_period;
1169 params->beacon_int = hapd->iconf->beacon_int;
1170 params->basic_rates = hapd->iface->basic_rates;
1171 params->ssid = hapd->conf->ssid.ssid;
1172 params->ssid_len = hapd->conf->ssid.ssid_len;
1173 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1174 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1175 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1176 hapd->conf->rsn_pairwise;
1177 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1178 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1179 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1180 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1181 params->group_cipher = hapd->conf->wpa_group;
1182 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1183 params->auth_algs = hapd->conf->auth_algs;
1184 params->wpa_version = hapd->conf->wpa;
1185 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1186 (hapd->conf->ieee802_1x &&
1187 (hapd->conf->default_wep_key_len ||
1188 hapd->conf->individual_wep_key_len));
1189 switch (hapd->conf->ignore_broadcast_ssid) {
1191 params->hide_ssid = NO_SSID_HIDING;
1194 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1197 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1200 params->isolate = hapd->conf->isolate;
1201 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1203 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1204 ERP_INFO_USE_PROTECTION);
1205 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1206 hapd->iconf->preamble == SHORT_PREAMBLE;
1207 if (hapd->iface->current_mode &&
1208 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1209 params->short_slot_time =
1210 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1212 params->short_slot_time = -1;
1213 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1214 params->ht_opmode = -1;
1216 params->ht_opmode = hapd->iface->ht_op_mode;
1217 #endif /* NEED_AP_MLME */
1218 params->interworking = hapd->conf->interworking;
1219 if (hapd->conf->interworking &&
1220 !is_zero_ether_addr(hapd->conf->hessid))
1221 params->hessid = hapd->conf->hessid;
1222 params->access_network_type = hapd->conf->access_network_type;
1223 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1225 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1226 #endif /* CONFIG_P2P */
1228 params->disable_dgaf = hapd->conf->disable_dgaf;
1229 if (hapd->conf->osen) {
1230 params->privacy = 1;
1233 #endif /* CONFIG_HS20 */
1234 params->pbss = hapd->conf->pbss;
1239 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1241 os_free(params->tail);
1242 params->tail = NULL;
1243 os_free(params->head);
1244 params->head = NULL;
1245 os_free(params->proberesp);
1246 params->proberesp = NULL;
1250 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1252 struct wpa_driver_ap_params params;
1253 struct hostapd_freq_params freq;
1254 struct hostapd_iface *iface = hapd->iface;
1255 struct hostapd_config *iconf = iface->conf;
1256 struct wpabuf *beacon, *proberesp, *assocresp;
1259 if (hapd->csa_in_progress) {
1260 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1264 hapd->beacon_set_done = 1;
1266 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1269 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1273 params.beacon_ies = beacon;
1274 params.proberesp_ies = proberesp;
1275 params.assocresp_ies = assocresp;
1276 params.reenable = hapd->reenable_beacon;
1277 hapd->reenable_beacon = 0;
1279 if (iface->current_mode &&
1280 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1281 iconf->channel, iconf->ieee80211n,
1283 iconf->secondary_channel,
1284 iconf->vht_oper_chwidth,
1285 iconf->vht_oper_centr_freq_seg0_idx,
1286 iconf->vht_oper_centr_freq_seg1_idx,
1287 iface->current_mode->vht_capab) == 0)
1288 params.freq = &freq;
1290 res = hostapd_drv_set_ap(hapd, ¶ms);
1291 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1293 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1297 ieee802_11_free_ap_params(¶ms);
1302 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1307 for (i = 0; i < iface->num_bss; i++) {
1308 if (iface->bss[i]->started &&
1309 ieee802_11_set_beacon(iface->bss[i]) < 0)
1317 /* only update beacons if started */
1318 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1323 for (i = 0; i < iface->num_bss; i++) {
1324 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1325 ieee802_11_set_beacon(iface->bss[i]) < 0)
1332 #endif /* CONFIG_NATIVE_WINDOWS */