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 #ifdef CONFIG_TESTING_OPTIONS
301 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
303 #endif /* CONFIG_TESTING_OPTIONS */
305 if (!hapd->cs_freq_params.channel)
308 *eid++ = WLAN_EID_CHANNEL_SWITCH;
310 *eid++ = hapd->cs_block_tx;
311 *eid++ = hapd->cs_freq_params.channel;
312 *eid++ = hapd->cs_count;
318 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
320 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
323 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
325 *eid++ = hapd->cs_block_tx;
326 *eid++ = hapd->iface->cs_oper_class;
327 *eid++ = hapd->cs_freq_params.channel;
328 *eid++ = hapd->cs_count;
334 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
336 u8 op_class, channel;
338 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
342 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
343 hapd->iconf->secondary_channel,
344 hapd->iconf->vht_oper_chwidth,
345 &op_class, &channel) ==
349 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
352 /* Current Operating Class */
355 /* TODO: Advertise all the supported operating classes */
362 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
363 const struct ieee80211_mgmt *req,
364 int is_p2p, size_t *resp_len)
366 struct ieee80211_mgmt *resp;
367 u8 *pos, *epos, *csa_pos;
370 #define MAX_PROBERESP_LEN 768
371 buflen = MAX_PROBERESP_LEN;
373 if (hapd->wps_probe_resp_ie)
374 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
375 #endif /* CONFIG_WPS */
377 if (hapd->p2p_probe_resp_ie)
378 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
379 #endif /* CONFIG_P2P */
381 if (hapd->iface->fst_ies)
382 buflen += wpabuf_len(hapd->iface->fst_ies);
383 #endif /* CONFIG_FST */
384 if (hapd->conf->vendor_elements)
385 buflen += wpabuf_len(hapd->conf->vendor_elements);
386 if (hapd->conf->vendor_vht) {
387 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
388 2 + sizeof(struct ieee80211_vht_operation);
390 resp = os_zalloc(buflen);
394 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
396 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
397 WLAN_FC_STYPE_PROBE_RESP);
399 os_memcpy(resp->da, req->sa, ETH_ALEN);
400 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
402 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
403 resp->u.probe_resp.beacon_int =
404 host_to_le16(hapd->iconf->beacon_int);
406 /* hardware or low-level driver will setup seq_ctrl and timestamp */
407 resp->u.probe_resp.capab_info =
408 host_to_le16(hostapd_own_capab_info(hapd));
410 pos = resp->u.probe_resp.variable;
411 *pos++ = WLAN_EID_SSID;
412 *pos++ = hapd->conf->ssid.ssid_len;
413 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
414 pos += hapd->conf->ssid.ssid_len;
416 /* Supported rates */
417 pos = hostapd_eid_supp_rates(hapd, pos);
420 pos = hostapd_eid_ds_params(hapd, pos);
422 pos = hostapd_eid_country(hapd, pos, epos - pos);
424 /* Power Constraint element */
425 pos = hostapd_eid_pwr_constraint(hapd, pos);
428 csa_pos = hostapd_eid_csa(hapd, pos);
430 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
433 /* ERP Information element */
434 pos = hostapd_eid_erp_info(hapd, pos);
436 /* Extended supported rates */
437 pos = hostapd_eid_ext_supp_rates(hapd, pos);
440 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
442 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
444 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
447 csa_pos = hostapd_eid_ecsa(hapd, pos);
449 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
452 pos = hostapd_eid_supported_op_classes(hapd, pos);
454 #ifdef CONFIG_IEEE80211N
455 /* Secondary Channel Offset element */
456 /* TODO: The standard doesn't specify a position for this element. */
457 pos = hostapd_eid_secondary_channel(hapd, pos);
459 pos = hostapd_eid_ht_capabilities(hapd, pos);
460 pos = hostapd_eid_ht_operation(hapd, pos);
461 #endif /* CONFIG_IEEE80211N */
463 pos = hostapd_eid_ext_capab(hapd, pos);
465 pos = hostapd_eid_time_adv(hapd, pos);
466 pos = hostapd_eid_time_zone(hapd, pos);
468 pos = hostapd_eid_interworking(hapd, pos);
469 pos = hostapd_eid_adv_proto(hapd, pos);
470 pos = hostapd_eid_roaming_consortium(hapd, pos);
473 if (hapd->iface->fst_ies) {
474 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
475 wpabuf_len(hapd->iface->fst_ies));
476 pos += wpabuf_len(hapd->iface->fst_ies);
478 #endif /* CONFIG_FST */
480 #ifdef CONFIG_IEEE80211AC
481 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
482 pos = hostapd_eid_vht_capabilities(hapd, pos);
483 pos = hostapd_eid_vht_operation(hapd, pos);
484 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
486 if (hapd->conf->vendor_vht)
487 pos = hostapd_eid_vendor_vht(hapd, pos);
488 #endif /* CONFIG_IEEE80211AC */
490 /* Wi-Fi Alliance WMM */
491 pos = hostapd_eid_wmm(hapd, pos);
494 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
495 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
496 wpabuf_len(hapd->wps_probe_resp_ie));
497 pos += wpabuf_len(hapd->wps_probe_resp_ie);
499 #endif /* CONFIG_WPS */
502 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
503 hapd->p2p_probe_resp_ie) {
504 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
505 wpabuf_len(hapd->p2p_probe_resp_ie));
506 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
508 #endif /* CONFIG_P2P */
509 #ifdef CONFIG_P2P_MANAGER
510 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
512 pos = hostapd_eid_p2p_manage(hapd, pos);
513 #endif /* CONFIG_P2P_MANAGER */
516 pos = hostapd_eid_hs20_indication(hapd, pos);
517 pos = hostapd_eid_osen(hapd, pos);
518 #endif /* CONFIG_HS20 */
520 if (hapd->conf->vendor_elements) {
521 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
522 wpabuf_len(hapd->conf->vendor_elements));
523 pos += wpabuf_len(hapd->conf->vendor_elements);
526 *resp_len = pos - (u8 *) resp;
531 enum ssid_match_result {
537 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
538 const u8 *ssid, size_t ssid_len,
540 size_t ssid_list_len)
547 if (ssid_len == hapd->conf->ssid.ssid_len &&
548 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
549 return EXACT_SSID_MATCH;
551 if (ssid_list == NULL)
552 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
555 end = ssid_list + ssid_list_len;
556 while (pos + 1 <= end) {
557 if (pos + 2 + pos[1] > end)
561 if (pos[1] == hapd->conf->ssid.ssid_len &&
562 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
563 return EXACT_SSID_MATCH;
567 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
571 void sta_track_expire(struct hostapd_iface *iface, int force)
573 struct os_reltime now;
574 struct hostapd_sta_info *info;
576 if (!iface->num_sta_seen)
579 os_get_reltime(&now);
580 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
583 !os_reltime_expired(&now, &info->last_seen,
584 iface->conf->track_sta_max_age))
588 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
589 MACSTR, iface->bss[0]->conf->iface,
590 MAC2STR(info->addr));
591 dl_list_del(&info->list);
592 iface->num_sta_seen--;
598 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
601 struct hostapd_sta_info *info;
603 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
604 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
611 void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
613 struct hostapd_sta_info *info;
615 info = sta_track_get(iface, addr);
617 /* Move the most recent entry to the end of the list */
618 dl_list_del(&info->list);
619 dl_list_add_tail(&iface->sta_seen, &info->list);
620 os_get_reltime(&info->last_seen);
624 /* Add a new entry */
625 info = os_zalloc(sizeof(*info));
626 os_memcpy(info->addr, addr, ETH_ALEN);
627 os_get_reltime(&info->last_seen);
629 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
630 /* Expire oldest entry to make room for a new one */
631 sta_track_expire(iface, 1);
634 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
635 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
636 dl_list_add_tail(&iface->sta_seen, &info->list);
637 iface->num_sta_seen++;
641 struct hostapd_data *
642 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
645 struct hapd_interfaces *interfaces = iface->interfaces;
648 for (i = 0; i < interfaces->count; i++) {
649 struct hostapd_data *hapd = NULL;
651 iface = interfaces->iface[i];
652 for (j = 0; j < iface->num_bss; j++) {
653 hapd = iface->bss[j];
654 if (os_strcmp(ifname, hapd->conf->iface) == 0)
659 if (hapd && sta_track_get(iface, addr))
667 void handle_probe_req(struct hostapd_data *hapd,
668 const struct ieee80211_mgmt *mgmt, size_t len,
672 struct ieee802_11_elems elems;
677 enum ssid_match_result res;
682 ie = mgmt->u.probe_req.variable;
683 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
685 if (hapd->iconf->track_sta_max_num)
686 sta_track_add(hapd->iface, mgmt->sa);
687 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
689 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
690 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
691 mgmt->sa, mgmt->da, mgmt->bssid,
692 ie, ie_len, ssi_signal) > 0)
695 if (!hapd->iconf->send_probe_response)
698 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
699 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
704 if ((!elems.ssid || !elems.supp_rates)) {
705 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
706 "without SSID or supported rates element",
712 * No need to reply if the Probe Request frame was sent on an adjacent
713 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
714 * AP with dot11RadioMeasurementActivated set to true, but strictly
715 * speaking does not allow such ignoring of Probe Request frames if
716 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
717 * number of unnecessary Probe Response frames for cases where the STA
718 * is less likely to see them (Probe Request frame sent on a
719 * neighboring, but partially overlapping, channel).
721 if (elems.ds_params &&
722 hapd->iface->current_mode &&
723 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
724 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
725 hapd->iconf->channel != elems.ds_params[0]) {
726 wpa_printf(MSG_DEBUG,
727 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
728 hapd->iconf->channel, elems.ds_params[0]);
733 if (hapd->p2p && elems.wps_ie) {
735 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
736 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
737 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
738 "due to mismatch with Requested Device "
746 if (hapd->p2p && elems.p2p) {
748 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
749 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
750 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
751 "due to mismatch with Device ID");
757 #endif /* CONFIG_P2P */
759 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
760 elems.ssid_list_len == 0) {
761 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
762 "broadcast SSID ignored", MAC2STR(mgmt->sa));
767 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
768 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
769 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
770 P2P_WILDCARD_SSID_LEN) == 0) {
771 /* Process P2P Wildcard SSID like Wildcard SSID */
774 #endif /* CONFIG_P2P */
776 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
777 elems.ssid_list, elems.ssid_list_len);
778 if (res == NO_SSID_MATCH) {
779 if (!(mgmt->da[0] & 0x01)) {
780 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
781 " for foreign SSID '%s' (DA " MACSTR ")%s",
783 wpa_ssid_txt(elems.ssid, elems.ssid_len),
785 elems.ssid_list ? " (SSID list)" : "");
790 #ifdef CONFIG_INTERWORKING
791 if (hapd->conf->interworking &&
792 elems.interworking && elems.interworking_len >= 1) {
793 u8 ant = elems.interworking[0] & 0x0f;
794 if (ant != INTERWORKING_ANT_WILDCARD &&
795 ant != hapd->conf->access_network_type) {
796 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
797 " for mismatching ANT %u ignored",
798 MAC2STR(mgmt->sa), ant);
803 if (hapd->conf->interworking && elems.interworking &&
804 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
806 if (elems.interworking_len == 7)
807 hessid = elems.interworking + 1;
809 hessid = elems.interworking + 1 + 2;
810 if (!is_broadcast_ether_addr(hessid) &&
811 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
812 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
813 " for mismatching HESSID " MACSTR
815 MAC2STR(mgmt->sa), MAC2STR(hessid));
819 #endif /* CONFIG_INTERWORKING */
822 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
823 supp_rates_11b_only(&elems)) {
824 /* Indicates support for 11b rates only */
825 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
826 MACSTR " with only 802.11b rates",
830 #endif /* CONFIG_P2P */
832 /* TODO: verify that supp_rates contains at least one matching rate
833 * with AP configuration */
835 if (hapd->conf->no_probe_resp_if_seen_on &&
836 is_multicast_ether_addr(mgmt->da) &&
837 is_multicast_ether_addr(mgmt->bssid) &&
838 sta_track_seen_on(hapd->iface, mgmt->sa,
839 hapd->conf->no_probe_resp_if_seen_on)) {
840 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
841 " since STA has been seen on %s",
842 hapd->conf->iface, MAC2STR(mgmt->sa),
843 hapd->conf->no_probe_resp_if_seen_on);
847 #ifdef CONFIG_TESTING_OPTIONS
848 if (hapd->iconf->ignore_probe_probability > 0.0 &&
849 drand48() < hapd->iconf->ignore_probe_probability) {
851 "TESTING: ignoring probe request from " MACSTR,
855 #endif /* CONFIG_TESTING_OPTIONS */
857 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
863 * If this is a broadcast probe request, apply no ack policy to avoid
866 noack = !!(res == WILDCARD_SSID_MATCH &&
867 is_broadcast_ether_addr(mgmt->da));
870 if (hapd->csa_in_progress) {
871 if (hapd->cs_c_off_proberesp)
872 csa_offs[csa_offs_len++] =
873 hapd->cs_c_off_proberesp;
875 if (hapd->cs_c_off_ecsa_proberesp)
876 csa_offs[csa_offs_len++] =
877 hapd->cs_c_off_ecsa_proberesp;
880 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
881 csa_offs_len ? csa_offs : NULL,
885 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
889 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
890 "SSID", MAC2STR(mgmt->sa),
891 elems.ssid_len == 0 ? "broadcast" : "our");
895 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
898 /* check probe response offloading caps and print warnings */
899 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
903 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
904 (!(hapd->iface->probe_resp_offloads &
905 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
906 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
907 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
908 "Probe Response while not supporting this");
909 #endif /* CONFIG_WPS */
912 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
913 !(hapd->iface->probe_resp_offloads &
914 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
915 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
916 "Probe Response while not supporting this");
917 #endif /* CONFIG_P2P */
919 if (hapd->conf->interworking &&
920 !(hapd->iface->probe_resp_offloads &
921 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
922 wpa_printf(MSG_WARNING, "Device is trying to offload "
923 "Interworking Probe Response while not supporting "
926 /* Generate a Probe Response template for the non-P2P case */
927 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
930 #endif /* NEED_AP_MLME */
933 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
934 struct wpa_driver_ap_params *params)
936 struct ieee80211_mgmt *head = NULL;
938 size_t head_len = 0, tail_len = 0;
943 u8 *pos, *tailpos, *csa_pos;
945 #define BEACON_HEAD_BUF_SIZE 256
946 #define BEACON_TAIL_BUF_SIZE 512
947 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
948 tail_len = BEACON_TAIL_BUF_SIZE;
950 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
951 tail_len += wpabuf_len(hapd->wps_beacon_ie);
952 #endif /* CONFIG_WPS */
954 if (hapd->p2p_beacon_ie)
955 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
956 #endif /* CONFIG_P2P */
958 if (hapd->iface->fst_ies)
959 tail_len += wpabuf_len(hapd->iface->fst_ies);
960 #endif /* CONFIG_FST */
961 if (hapd->conf->vendor_elements)
962 tail_len += wpabuf_len(hapd->conf->vendor_elements);
964 #ifdef CONFIG_IEEE80211AC
965 if (hapd->conf->vendor_vht) {
966 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
967 2 + sizeof(struct ieee80211_vht_operation);
969 #endif /* CONFIG_IEEE80211AC */
971 tailpos = tail = os_malloc(tail_len);
972 if (head == NULL || tail == NULL) {
973 wpa_printf(MSG_ERROR, "Failed to set beacon data");
979 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
980 WLAN_FC_STYPE_BEACON);
981 head->duration = host_to_le16(0);
982 os_memset(head->da, 0xff, ETH_ALEN);
984 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
985 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
986 head->u.beacon.beacon_int =
987 host_to_le16(hapd->iconf->beacon_int);
989 /* hardware or low-level driver will setup seq_ctrl and timestamp */
990 capab_info = hostapd_own_capab_info(hapd);
991 head->u.beacon.capab_info = host_to_le16(capab_info);
992 pos = &head->u.beacon.variable[0];
995 *pos++ = WLAN_EID_SSID;
996 if (hapd->conf->ignore_broadcast_ssid == 2) {
997 /* clear the data, but keep the correct length of the SSID */
998 *pos++ = hapd->conf->ssid.ssid_len;
999 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1000 pos += hapd->conf->ssid.ssid_len;
1001 } else if (hapd->conf->ignore_broadcast_ssid) {
1002 *pos++ = 0; /* empty SSID */
1004 *pos++ = hapd->conf->ssid.ssid_len;
1005 os_memcpy(pos, hapd->conf->ssid.ssid,
1006 hapd->conf->ssid.ssid_len);
1007 pos += hapd->conf->ssid.ssid_len;
1010 /* Supported rates */
1011 pos = hostapd_eid_supp_rates(hapd, pos);
1014 pos = hostapd_eid_ds_params(hapd, pos);
1016 head_len = pos - (u8 *) head;
1018 tailpos = hostapd_eid_country(hapd, tailpos,
1019 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1021 /* Power Constraint element */
1022 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1025 csa_pos = hostapd_eid_csa(hapd, tailpos);
1026 if (csa_pos != tailpos)
1027 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1030 /* ERP Information element */
1031 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1033 /* Extended supported rates */
1034 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1036 /* RSN, MDIE, WPA */
1037 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
1040 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1041 tail + BEACON_TAIL_BUF_SIZE -
1044 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1045 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1048 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1049 if (csa_pos != tailpos)
1050 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1053 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1055 #ifdef CONFIG_IEEE80211N
1056 /* Secondary Channel Offset element */
1057 /* TODO: The standard doesn't specify a position for this element. */
1058 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1060 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1061 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1062 #endif /* CONFIG_IEEE80211N */
1064 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1067 * TODO: Time Advertisement element should only be included in some
1068 * DTIM Beacon frames.
1070 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1072 tailpos = hostapd_eid_interworking(hapd, tailpos);
1073 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1074 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1077 if (hapd->iface->fst_ies) {
1078 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1079 wpabuf_len(hapd->iface->fst_ies));
1080 tailpos += wpabuf_len(hapd->iface->fst_ies);
1082 #endif /* CONFIG_FST */
1084 #ifdef CONFIG_IEEE80211AC
1085 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1086 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
1087 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1088 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1090 if (hapd->conf->vendor_vht)
1091 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1092 #endif /* CONFIG_IEEE80211AC */
1094 /* Wi-Fi Alliance WMM */
1095 tailpos = hostapd_eid_wmm(hapd, tailpos);
1098 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1099 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1100 wpabuf_len(hapd->wps_beacon_ie));
1101 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1103 #endif /* CONFIG_WPS */
1106 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1107 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1108 wpabuf_len(hapd->p2p_beacon_ie));
1109 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1111 #endif /* CONFIG_P2P */
1112 #ifdef CONFIG_P2P_MANAGER
1113 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1115 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1116 #endif /* CONFIG_P2P_MANAGER */
1119 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1120 tailpos = hostapd_eid_osen(hapd, tailpos);
1121 #endif /* CONFIG_HS20 */
1123 if (hapd->conf->vendor_elements) {
1124 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1125 wpabuf_len(hapd->conf->vendor_elements));
1126 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1129 tail_len = tailpos > tail ? tailpos - tail : 0;
1131 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1132 #endif /* NEED_AP_MLME */
1134 os_memset(params, 0, sizeof(*params));
1135 params->head = (u8 *) head;
1136 params->head_len = head_len;
1137 params->tail = tail;
1138 params->tail_len = tail_len;
1139 params->proberesp = resp;
1140 params->proberesp_len = resp_len;
1141 params->dtim_period = hapd->conf->dtim_period;
1142 params->beacon_int = hapd->iconf->beacon_int;
1143 params->basic_rates = hapd->iface->basic_rates;
1144 params->ssid = hapd->conf->ssid.ssid;
1145 params->ssid_len = hapd->conf->ssid.ssid_len;
1146 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1147 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1148 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1149 hapd->conf->rsn_pairwise;
1150 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1151 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1152 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1153 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1154 params->group_cipher = hapd->conf->wpa_group;
1155 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1156 params->auth_algs = hapd->conf->auth_algs;
1157 params->wpa_version = hapd->conf->wpa;
1158 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1159 (hapd->conf->ieee802_1x &&
1160 (hapd->conf->default_wep_key_len ||
1161 hapd->conf->individual_wep_key_len));
1162 switch (hapd->conf->ignore_broadcast_ssid) {
1164 params->hide_ssid = NO_SSID_HIDING;
1167 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1170 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1173 params->isolate = hapd->conf->isolate;
1174 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1176 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1177 ERP_INFO_USE_PROTECTION);
1178 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1179 hapd->iconf->preamble == SHORT_PREAMBLE;
1180 if (hapd->iface->current_mode &&
1181 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1182 params->short_slot_time =
1183 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1185 params->short_slot_time = -1;
1186 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1187 params->ht_opmode = -1;
1189 params->ht_opmode = hapd->iface->ht_op_mode;
1190 #endif /* NEED_AP_MLME */
1191 params->interworking = hapd->conf->interworking;
1192 if (hapd->conf->interworking &&
1193 !is_zero_ether_addr(hapd->conf->hessid))
1194 params->hessid = hapd->conf->hessid;
1195 params->access_network_type = hapd->conf->access_network_type;
1196 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1198 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1199 #endif /* CONFIG_P2P */
1201 params->disable_dgaf = hapd->conf->disable_dgaf;
1202 if (hapd->conf->osen) {
1203 params->privacy = 1;
1206 #endif /* CONFIG_HS20 */
1211 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1213 os_free(params->tail);
1214 params->tail = NULL;
1215 os_free(params->head);
1216 params->head = NULL;
1217 os_free(params->proberesp);
1218 params->proberesp = NULL;
1222 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1224 struct wpa_driver_ap_params params;
1225 struct hostapd_freq_params freq;
1226 struct hostapd_iface *iface = hapd->iface;
1227 struct hostapd_config *iconf = iface->conf;
1228 struct wpabuf *beacon, *proberesp, *assocresp;
1231 if (hapd->csa_in_progress) {
1232 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1236 hapd->beacon_set_done = 1;
1238 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1241 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1245 params.beacon_ies = beacon;
1246 params.proberesp_ies = proberesp;
1247 params.assocresp_ies = assocresp;
1248 params.reenable = hapd->reenable_beacon;
1249 hapd->reenable_beacon = 0;
1251 if (iface->current_mode &&
1252 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1253 iconf->channel, iconf->ieee80211n,
1255 iconf->secondary_channel,
1256 iconf->vht_oper_chwidth,
1257 iconf->vht_oper_centr_freq_seg0_idx,
1258 iconf->vht_oper_centr_freq_seg1_idx,
1259 iface->current_mode->vht_capab) == 0)
1260 params.freq = &freq;
1262 res = hostapd_drv_set_ap(hapd, ¶ms);
1263 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1265 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1269 ieee802_11_free_ap_params(¶ms);
1274 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1279 for (i = 0; i < iface->num_bss; i++) {
1280 if (iface->bss[i]->started &&
1281 ieee802_11_set_beacon(iface->bss[i]) < 0)
1289 /* only update beacons if started */
1290 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1295 for (i = 0; i < iface->num_bss; i++) {
1296 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1297 ieee802_11_set_beacon(iface->bss[i]) < 0)
1304 #endif /* CONFIG_NATIVE_WINDOWS */