beacon.c revision 09f57babfc1e4473db20ced4f58a4c9f082c8ed8
195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley/* 295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response 395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * Copyright (c) 2002-2004, Instant802 Networks, Inc. 495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * Copyright (c) 2005-2006, Devicescape Software, Inc. 595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi> 695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * 795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * This software may be distributed under the terms of the BSD license. 895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * See README for more details. 995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley */ 1095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 1195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "utils/includes.h" 1295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 1395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifndef CONFIG_NATIVE_WINDOWS 1495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 1595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "utils/common.h" 1695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "common/ieee802_11_defs.h" 1795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "common/ieee802_11_common.h" 1895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "wps/wps_defs.h" 1995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "p2p/p2p.h" 2095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "hostapd.h" 2195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "ieee802_11.h" 2295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "wpa_auth.h" 2395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "wmm.h" 2495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "ap_config.h" 2595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "sta_info.h" 2695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "p2p_hostapd.h" 2795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "ap_drv_ops.h" 2895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "beacon.h" 2995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "hs20.h" 3095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#include "dfs.h" 3195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 3295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 3395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef NEED_AP_MLME 3495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 3595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len) 3695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 3795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_TESTING_OPTIONS 3895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->conf->bss_load_test_set) { 3995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (2 + 5 > len) 4095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 4195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = WLAN_EID_BSS_LOAD; 4295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = 5; 4395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcpy(eid, hapd->conf->bss_load_test, 5); 4495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley eid += 5; 4595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 4695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#endif /* CONFIG_TESTING_OPTIONS */ 4795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 4895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 4995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 5095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 5195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 ieee802_11_erp_info(struct hostapd_data *hapd) 5295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 5395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 erp = 0; 5495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 5595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->current_mode == NULL || 5695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) 5795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return 0; 5895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 5995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->olbc) 6095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley erp |= ERP_INFO_USE_PROTECTION; 6195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->num_sta_non_erp > 0) { 6295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley erp |= ERP_INFO_NON_ERP_PRESENT | 6395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley ERP_INFO_USE_PROTECTION; 6495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 6595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->num_sta_no_short_preamble > 0 || 6695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iconf->preamble == LONG_PREAMBLE) 6795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley erp |= ERP_INFO_BARKER_PREAMBLE_MODE; 6895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 6995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return erp; 7095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 7195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 7295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 7395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid) 7495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 7595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = WLAN_EID_DS_PARAMS; 7695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = 1; 7795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = hapd->iconf->channel; 7895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 7995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 8095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 8195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 8295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid) 8395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 8495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->current_mode == NULL || 8595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) 8695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 8795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 8895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Set NonERP_present and use_protection bits if there 8995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * are any associated NonERP stations. */ 9095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* TODO: use_protection bit can be set to zero even if 9195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * there are NonERP stations present. This optimization 9295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * might be useful if NonERP stations are "quiet". 9395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * See 802.11g/D6 E-1 for recommended practice. 9495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * In addition, Non ERP present might be set, if AP detects Non ERP 9595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * operation on other APs. */ 9695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 9795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Add ERP Information element */ 9895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = WLAN_EID_ERP_INFO; 9995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = 1; 10095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = ieee802_11_erp_info(hapd); 10195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 10295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 10395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 10495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 10595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 10695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) 10795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 10895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *pos = eid; 10995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 local_pwr_constraint = 0; 11095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int dfs; 11195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 11295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->current_mode == NULL || 11395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) 11495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 11595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 11695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* 11795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * There is no DFS support and power constraint was not directly 11895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * requested by config option. 11995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley */ 12095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (!hapd->iconf->ieee80211h && 12195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iconf->local_pwr_constraint == -1) 12295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 12395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 12430ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin /* Check if DFS is required by regulatory. */ 12530ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin dfs = hostapd_is_dfs_required(hapd->iface); 12630ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin if (dfs < 0) { 12730ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", 12830ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin dfs); 12930ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin dfs = 0; 13030ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin } 13195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 13295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1) 13395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 13495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 13595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* 13695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * ieee80211h (DFS) is enabled so Power Constraint element shall 13795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * be added when running on DFS channel whenever local_pwr_constraint 13895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * is configured or not. In order to meet regulations when TPC is not 13995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * implemented using a transmit power that is below the legal maximum 14095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * (including any mitigation factor) should help. In this case, 14195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * indicate 3 dB below maximum allowed transmit power. 14295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley */ 14395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iconf->local_pwr_constraint == -1) 14495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley local_pwr_constraint = 3; 14595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 14695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* 14795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * A STA that is not an AP shall use a transmit power less than or 14895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * equal to the local maximum transmit power level for the channel. 14995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * The local maximum transmit power can be calculated from the formula: 15095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * local max TX pwr = max TX pwr - local pwr constraint 15195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * Where max TX pwr is maximum transmit power level specified for 15295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * channel in Country element and local pwr constraint is specified 15395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley * for channel in this Power Constraint element. 15495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley */ 15595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 15695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Element ID */ 15795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = WLAN_EID_PWR_CONSTRAINT; 15895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Length */ 15995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = 1; 16095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Local Power Constraint */ 16195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (local_pwr_constraint) 16295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = local_pwr_constraint; 16395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley else 16495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = hapd->iconf->local_pwr_constraint; 16595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 16695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 16795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 16895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 16995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 17095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing, 17195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct hostapd_channel_data *start, 17295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct hostapd_channel_data *prev) 17395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 17495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (end - pos < 3) 17595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 17695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 17795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* first channel number */ 17895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = start->chan; 17995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* number of channels */ 18095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = (prev->chan - start->chan) / chan_spacing + 1; 18195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* maximum transmit power level */ 18295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = start->max_tx_power; 18395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 18495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 18595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 18695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 18795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 18895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid, 18995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int max_len) 19095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 19195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *pos = eid; 19295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *end = eid + max_len; 19395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int i; 19495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct hostapd_hw_modes *mode; 19595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct hostapd_channel_data *start, *prev; 19695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int chan_spacing = 1; 19795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 19895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (!hapd->iconf->ieee80211d || max_len < 6 || 19995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley hapd->iface->current_mode == NULL) 20095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 20195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 20295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = WLAN_EID_COUNTRY; 20395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos++; /* length will be set later */ 20495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */ 20595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos += 3; 20695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 20795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley mode = hapd->iface->current_mode; 20895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (mode->mode == HOSTAPD_MODE_IEEE80211A) 20995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley chan_spacing = 4; 21095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 21195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start = prev = NULL; 21295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley for (i = 0; i < mode->num_channels; i++) { 21395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct hostapd_channel_data *chan = &mode->channels[i]; 21495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (chan->flag & HOSTAPD_CHAN_DISABLED) 21595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley continue; 21695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (start && prev && 21795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley prev->chan + chan_spacing == chan->chan && 21895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start->max_tx_power == chan->max_tx_power) { 21995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley prev = chan; 22095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley continue; /* can use same entry */ 22195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 22295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 22395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (start && prev) { 22495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_country_add(pos, end, chan_spacing, 22595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start, prev); 22695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start = NULL; 22795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 22895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 22995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Start new group */ 23095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start = prev = chan; 23195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 23295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 23395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (start) { 23495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_country_add(pos, end, chan_spacing, 23595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley start, prev); 23695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 23795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 23895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if ((pos - eid) & 1) { 23995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (end - pos < 1) 24095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 24195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *pos++ = 0; /* pad for 16-bit alignment */ 24295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 24395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 24495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley eid[1] = (pos - eid) - 2; 24595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 24695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 24795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 24895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 24995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 25095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len) 25195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 25295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const u8 *ie; 25395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley size_t ielen; 25495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 25595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen); 25695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ie == NULL || ielen > len) 25795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 25895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 25995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcpy(eid, ie, ielen); 26095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid + ielen; 26195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 26295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 26395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 26495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) 26595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 26695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 chan; 26795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 2680eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin if (!hapd->iface->cs_freq_params.freq) 26995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 27095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 27195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) == 27295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley NUM_HOSTAPD_MODES) 27395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 27495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 27595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = WLAN_EID_CHANNEL_SWITCH; 27695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = 3; 27795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = hapd->iface->cs_block_tx; 27895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = chan; 27995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = hapd->iface->cs_count; 28095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 28195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 2827f520dbd8d4e0006f6c8279c681ee149c961c104David Benjamin} 28395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 28495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 28595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid) 28695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 28795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 sec_ch; 28895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 28995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (!hapd->iface->cs_freq_params.sec_channel_offset) 29095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return eid; 29195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 29295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->iface->cs_freq_params.sec_channel_offset == -1) 29395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW; 29495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley else if (hapd->iface->cs_freq_params.sec_channel_offset == 1) 29595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE; 29695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley else 29730ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin return eid; 29830ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 29995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; 30030ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin *eid++ = 1; 30130ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin *eid++ = sec_ch; 30230ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 30330ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin return eid; 30430ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin} 30530ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 30630ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 30795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos, 30895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *start, unsigned int *csa_counter_off) 30995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 31095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *old_pos = pos; 31195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 31295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (!csa_counter_off) 31395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 31495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 31595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *csa_counter_off = 0; 31695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_csa(hapd, pos); 31795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 31895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (pos != old_pos) { 31995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* save an offset to the counter - should be last byte */ 32095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley *csa_counter_off = pos - start - 1; 32195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_secondary_channel(hapd, pos); 32295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 32395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 32495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return pos; 32595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 32695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 32795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 32895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd, 32995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct sta_info *sta, 33095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const struct ieee80211_mgmt *req, 33195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int is_p2p, size_t *resp_len) 33295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 33395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct ieee80211_mgmt *resp; 33495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *pos, *epos; 33595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley size_t buflen; 33695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 33795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#define MAX_PROBERESP_LEN 768 33895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley buflen = MAX_PROBERESP_LEN; 33995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_WPS 34095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->wps_probe_resp_ie) 34195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley buflen += wpabuf_len(hapd->wps_probe_resp_ie); 34295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#endif /* CONFIG_WPS */ 34395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_P2P 34495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->p2p_probe_resp_ie) 34595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley buflen += wpabuf_len(hapd->p2p_probe_resp_ie); 3460eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#endif /* CONFIG_P2P */ 34795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->conf->vendor_elements) 3480eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin buflen += wpabuf_len(hapd->conf->vendor_elements); 3490eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin resp = os_zalloc(buflen); 3500eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin if (resp == NULL) 3510eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin return NULL; 3520eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 35395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley epos = ((u8 *) resp) + MAX_PROBERESP_LEN; 3540eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3550eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 35695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley WLAN_FC_STYPE_PROBE_RESP); 3570eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin if (req) 3580eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin os_memcpy(resp->da, req->sa, ETH_ALEN); 3590eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); 36095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 36130ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); 36230ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin resp->u.probe_resp.beacon_int = 36330ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin host_to_le16(hapd->iconf->beacon_int); 36430ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 36530ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin /* hardware or low-level driver will setup seq_ctrl and timestamp */ 36630ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin resp->u.probe_resp.capab_info = 36730ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin host_to_le16(hostapd_own_capab_info(hapd, sta, 1)); 36830ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 36930ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin pos = resp->u.probe_resp.variable; 37030ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin *pos++ = WLAN_EID_SSID; 37130ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin *pos++ = hapd->conf->ssid.ssid_len; 37230ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); 37330ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin pos += hapd->conf->ssid.ssid_len; 37430ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 37530ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin /* Supported rates */ 37630ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin pos = hostapd_eid_supp_rates(hapd, pos); 37795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 3780eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* DS Params */ 37939482a13aca033b72118807fadd152207e0fad8aDavid Benjamin pos = hostapd_eid_ds_params(hapd, pos); 3800eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3810eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_country(hapd, pos, epos - pos); 3820eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3830eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* Power Constraint element */ 3840eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_pwr_constraint(hapd, pos); 3850eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3860eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* ERP Information element */ 38795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_erp_info(hapd, pos); 3880eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3890eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* Extended supported rates */ 3900eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_ext_supp_rates(hapd, pos); 39195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 3920eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* RSN, MDIE, WPA */ 3930eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_wpa(hapd, pos, epos - pos); 3940eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3950eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_bss_load(hapd, pos, epos - pos); 3960eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 3970eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#ifdef CONFIG_IEEE80211N 398b0c235ed366d10674542db784668fe3e13f23709Adam Langley pos = hostapd_eid_ht_capabilities(hapd, pos); 3990eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_ht_operation(hapd, pos); 4000eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#endif /* CONFIG_IEEE80211N */ 4010eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4020eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_ext_capab(hapd, pos); 4030eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4040eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_time_adv(hapd, pos); 4050eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_time_zone(hapd, pos); 4060eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 40795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_interworking(hapd, pos); 4080eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_adv_proto(hapd, pos); 40995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_roaming_consortium(hapd, pos); 4100eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4110eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp, 4120eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin &hapd->iface->cs_c_off_proberesp); 4130eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#ifdef CONFIG_IEEE80211AC 41495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_vht_capabilities(hapd, pos); 4150eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_vht_operation(hapd, pos); 41695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#endif /* CONFIG_IEEE80211AC */ 4170eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4180eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin /* Wi-Fi Alliance WMM */ 4190eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_wmm(hapd, pos); 4200eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 42195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_WPS 42295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { 4230eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), 4240eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin wpabuf_len(hapd->wps_probe_resp_ie)); 4250eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos += wpabuf_len(hapd->wps_probe_resp_ie); 4260eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin } 4270eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#endif /* CONFIG_WPS */ 4280eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4290eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#ifdef CONFIG_P2P 4300eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && 4310eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin hapd->p2p_probe_resp_ie) { 4320eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), 4330eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin wpabuf_len(hapd->p2p_probe_resp_ie)); 4340eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos += wpabuf_len(hapd->p2p_probe_resp_ie); 4350eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin } 4360eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#endif /* CONFIG_P2P */ 4370eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#ifdef CONFIG_P2P_MANAGER 4380eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == 4390eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin P2P_MANAGE) 4400eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin pos = hostapd_eid_p2p_manage(hapd, pos); 4410eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin#endif /* CONFIG_P2P_MANAGER */ 44295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 44395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_HS20 44495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_hs20_indication(hapd, pos); 44595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = hostapd_eid_osen(hapd, pos); 44695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#endif /* CONFIG_HS20 */ 44795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 44895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->conf->vendor_elements) { 44995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), 45095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpabuf_len(hapd->conf->vendor_elements)); 45195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos += wpabuf_len(hapd->conf->vendor_elements); 45295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 4530eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin 4540eb17906ab03bd3f8d2e83bc08abf94caf0ff489David Benjamin *resp_len = pos - (u8 *) resp; 45595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return (u8 *) resp; 45695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 45795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 45895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 45995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleyenum ssid_match_result { 46095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley NO_SSID_MATCH, 46195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley EXACT_SSID_MATCH, 46295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley WILDCARD_SSID_MATCH 46395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley}; 46495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 46595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleystatic enum ssid_match_result ssid_match(struct hostapd_data *hapd, 46695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const u8 *ssid, size_t ssid_len, 46795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const u8 *ssid_list, 46895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley size_t ssid_list_len) 46995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 47095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const u8 *pos, *end; 47195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int wildcard = 0; 47295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 47395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ssid_len == 0) 47495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wildcard = 1; 47595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ssid_len == hapd->conf->ssid.ssid_len && 47695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) 47795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return EXACT_SSID_MATCH; 47895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 47995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ssid_list == NULL) 48095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; 48195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 48295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos = ssid_list; 48395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley end = ssid_list + ssid_list_len; 48495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley while (pos + 1 <= end) { 48595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (pos + 2 + pos[1] > end) 48695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley break; 48795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (pos[1] == 0) 48895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wildcard = 1; 48995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (pos[1] == hapd->conf->ssid.ssid_len && 49095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0) 49195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return EXACT_SSID_MATCH; 49295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley pos += 2 + pos[1]; 49395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 49495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 49595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; 49695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley} 49795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 49895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 49995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langleyvoid handle_probe_req(struct hostapd_data *hapd, 50095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const struct ieee80211_mgmt *mgmt, size_t len, 50195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int ssi_signal) 50295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley{ 50395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley u8 *resp; 50495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct ieee802_11_elems elems; 50595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley const u8 *ie; 50695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley size_t ie_len; 50795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct sta_info *sta = NULL; 50895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley size_t i, resp_len; 50995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley int noack; 51095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley enum ssid_match_result res; 51195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 51295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley ie = mgmt->u.probe_req.variable; 51395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)) 51495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 51595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)); 51695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 51795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) 51895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, 51995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley mgmt->sa, mgmt->da, mgmt->bssid, 52095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley ie, ie_len, ssi_signal) > 0) 52195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 52295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 52395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (!hapd->iconf->send_probe_response) 52495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 52595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 52695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { 52795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, 52895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley MAC2STR(mgmt->sa)); 52995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 53095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 53195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 53295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if ((!elems.ssid || !elems.supp_rates)) { 53395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " 53495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley "without SSID or supported rates element", 53595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley MAC2STR(mgmt->sa)); 53695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 53795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 53895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 53995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#ifdef CONFIG_P2P 54095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->p2p && elems.wps_ie) { 54195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct wpabuf *wps; 54295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); 54395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { 54495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " 54595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley "due to mismatch with Requested Device " 54695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley "Type"); 54795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpabuf_free(wps); 54895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 54995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 55095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpabuf_free(wps); 55195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 55295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 55395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->p2p && elems.p2p) { 55495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley struct wpabuf *p2p; 55595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); 55695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { 55795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " 55895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley "due to mismatch with Device ID"); 55995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpabuf_free(p2p); 56095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 56195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 56295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpabuf_free(p2p); 56395c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 56495c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley#endif /* CONFIG_P2P */ 56595c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 56695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && 56795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley elems.ssid_list_len == 0) { 56895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " 56995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley "broadcast SSID ignored", MAC2STR(mgmt->sa)); 57095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley return; 57195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley } 57295c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley 57330ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin sta = ap_get_sta(hapd, mgmt->sa); 57430ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin 57530ddb434bfb845356fbacb6b2bd51f8814c7043cDavid Benjamin#ifdef CONFIG_P2P 57695c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley if ((hapd->conf->p2p & P2P_GROUP_OWNER) && 57795c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley elems.ssid_len == P2P_WILDCARD_SSID_LEN && 57895c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley os_memcmp(elems.ssid, P2P_WILDCARD_SSID, 57995c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley P2P_WILDCARD_SSID_LEN) == 0) { 58095c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley /* Process P2P Wildcard SSID like Wildcard SSID */ 58195c29f3cd1f6c08c6c0927868683392eea727ccAdam Langley elems.ssid_len = 0; 582 } 583#endif /* CONFIG_P2P */ 584 585 res = ssid_match(hapd, elems.ssid, elems.ssid_len, 586 elems.ssid_list, elems.ssid_list_len); 587 if (res != NO_SSID_MATCH) { 588 if (sta) 589 sta->ssid_probe = &hapd->conf->ssid; 590 } else { 591 if (!(mgmt->da[0] & 0x01)) { 592 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 593 " for foreign SSID '%s' (DA " MACSTR ")%s", 594 MAC2STR(mgmt->sa), 595 wpa_ssid_txt(elems.ssid, elems.ssid_len), 596 MAC2STR(mgmt->da), 597 elems.ssid_list ? " (SSID list)" : ""); 598 } 599 return; 600 } 601 602#ifdef CONFIG_INTERWORKING 603 if (hapd->conf->interworking && 604 elems.interworking && elems.interworking_len >= 1) { 605 u8 ant = elems.interworking[0] & 0x0f; 606 if (ant != INTERWORKING_ANT_WILDCARD && 607 ant != hapd->conf->access_network_type) { 608 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 609 " for mismatching ANT %u ignored", 610 MAC2STR(mgmt->sa), ant); 611 return; 612 } 613 } 614 615 if (hapd->conf->interworking && elems.interworking && 616 (elems.interworking_len == 7 || elems.interworking_len == 9)) { 617 const u8 *hessid; 618 if (elems.interworking_len == 7) 619 hessid = elems.interworking + 1; 620 else 621 hessid = elems.interworking + 1 + 2; 622 if (!is_broadcast_ether_addr(hessid) && 623 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { 624 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 625 " for mismatching HESSID " MACSTR 626 " ignored", 627 MAC2STR(mgmt->sa), MAC2STR(hessid)); 628 return; 629 } 630 } 631#endif /* CONFIG_INTERWORKING */ 632 633#ifdef CONFIG_P2P 634 if ((hapd->conf->p2p & P2P_GROUP_OWNER) && 635 supp_rates_11b_only(&elems)) { 636 /* Indicates support for 11b rates only */ 637 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " 638 MACSTR " with only 802.11b rates", 639 MAC2STR(mgmt->sa)); 640 return; 641 } 642#endif /* CONFIG_P2P */ 643 644 /* TODO: verify that supp_rates contains at least one matching rate 645 * with AP configuration */ 646 647#ifdef CONFIG_TESTING_OPTIONS 648 if (hapd->iconf->ignore_probe_probability > 0.0 && 649 drand48() < hapd->iconf->ignore_probe_probability) { 650 wpa_printf(MSG_INFO, 651 "TESTING: ignoring probe request from " MACSTR, 652 MAC2STR(mgmt->sa)); 653 return; 654 } 655#endif /* CONFIG_TESTING_OPTIONS */ 656 657 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL, 658 &resp_len); 659 if (resp == NULL) 660 return; 661 662 /* 663 * If this is a broadcast probe request, apply no ack policy to avoid 664 * excessive retries. 665 */ 666 noack = !!(res == WILDCARD_SSID_MATCH && 667 is_broadcast_ether_addr(mgmt->da)); 668 669 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0) 670 wpa_printf(MSG_INFO, "handle_probe_req: send failed"); 671 672 os_free(resp); 673 674 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " 675 "SSID", MAC2STR(mgmt->sa), 676 elems.ssid_len == 0 ? "broadcast" : "our"); 677} 678 679 680static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, 681 size_t *resp_len) 682{ 683 /* check probe response offloading caps and print warnings */ 684 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) 685 return NULL; 686 687#ifdef CONFIG_WPS 688 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && 689 (!(hapd->iface->probe_resp_offloads & 690 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | 691 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) 692 wpa_printf(MSG_WARNING, "Device is trying to offload WPS " 693 "Probe Response while not supporting this"); 694#endif /* CONFIG_WPS */ 695 696#ifdef CONFIG_P2P 697 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && 698 !(hapd->iface->probe_resp_offloads & 699 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) 700 wpa_printf(MSG_WARNING, "Device is trying to offload P2P " 701 "Probe Response while not supporting this"); 702#endif /* CONFIG_P2P */ 703 704 if (hapd->conf->interworking && 705 !(hapd->iface->probe_resp_offloads & 706 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) 707 wpa_printf(MSG_WARNING, "Device is trying to offload " 708 "Interworking Probe Response while not supporting " 709 "this"); 710 711 /* Generate a Probe Response template for the non-P2P case */ 712 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len); 713} 714 715#endif /* NEED_AP_MLME */ 716 717 718int ieee802_11_build_ap_params(struct hostapd_data *hapd, 719 struct wpa_driver_ap_params *params) 720{ 721 struct ieee80211_mgmt *head = NULL; 722 u8 *tail = NULL; 723 size_t head_len = 0, tail_len = 0; 724 u8 *resp = NULL; 725 size_t resp_len = 0; 726#ifdef NEED_AP_MLME 727 u16 capab_info; 728 u8 *pos, *tailpos; 729 730#define BEACON_HEAD_BUF_SIZE 256 731#define BEACON_TAIL_BUF_SIZE 512 732 head = os_zalloc(BEACON_HEAD_BUF_SIZE); 733 tail_len = BEACON_TAIL_BUF_SIZE; 734#ifdef CONFIG_WPS 735 if (hapd->conf->wps_state && hapd->wps_beacon_ie) 736 tail_len += wpabuf_len(hapd->wps_beacon_ie); 737#endif /* CONFIG_WPS */ 738#ifdef CONFIG_P2P 739 if (hapd->p2p_beacon_ie) 740 tail_len += wpabuf_len(hapd->p2p_beacon_ie); 741#endif /* CONFIG_P2P */ 742 if (hapd->conf->vendor_elements) 743 tail_len += wpabuf_len(hapd->conf->vendor_elements); 744 tailpos = tail = os_malloc(tail_len); 745 if (head == NULL || tail == NULL) { 746 wpa_printf(MSG_ERROR, "Failed to set beacon data"); 747 os_free(head); 748 os_free(tail); 749 return -1; 750 } 751 752 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 753 WLAN_FC_STYPE_BEACON); 754 head->duration = host_to_le16(0); 755 os_memset(head->da, 0xff, ETH_ALEN); 756 757 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); 758 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); 759 head->u.beacon.beacon_int = 760 host_to_le16(hapd->iconf->beacon_int); 761 762 /* hardware or low-level driver will setup seq_ctrl and timestamp */ 763 capab_info = hostapd_own_capab_info(hapd, NULL, 0); 764 head->u.beacon.capab_info = host_to_le16(capab_info); 765 pos = &head->u.beacon.variable[0]; 766 767 /* SSID */ 768 *pos++ = WLAN_EID_SSID; 769 if (hapd->conf->ignore_broadcast_ssid == 2) { 770 /* clear the data, but keep the correct length of the SSID */ 771 *pos++ = hapd->conf->ssid.ssid_len; 772 os_memset(pos, 0, hapd->conf->ssid.ssid_len); 773 pos += hapd->conf->ssid.ssid_len; 774 } else if (hapd->conf->ignore_broadcast_ssid) { 775 *pos++ = 0; /* empty SSID */ 776 } else { 777 *pos++ = hapd->conf->ssid.ssid_len; 778 os_memcpy(pos, hapd->conf->ssid.ssid, 779 hapd->conf->ssid.ssid_len); 780 pos += hapd->conf->ssid.ssid_len; 781 } 782 783 /* Supported rates */ 784 pos = hostapd_eid_supp_rates(hapd, pos); 785 786 /* DS Params */ 787 pos = hostapd_eid_ds_params(hapd, pos); 788 789 head_len = pos - (u8 *) head; 790 791 tailpos = hostapd_eid_country(hapd, tailpos, 792 tail + BEACON_TAIL_BUF_SIZE - tailpos); 793 794 /* Power Constraint element */ 795 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); 796 797 /* ERP Information element */ 798 tailpos = hostapd_eid_erp_info(hapd, tailpos); 799 800 /* Extended supported rates */ 801 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); 802 803 /* RSN, MDIE, WPA */ 804 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - 805 tailpos); 806 807 tailpos = hostapd_eid_bss_load(hapd, tailpos, 808 tail + BEACON_TAIL_BUF_SIZE - tailpos); 809 810#ifdef CONFIG_IEEE80211N 811 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); 812 tailpos = hostapd_eid_ht_operation(hapd, tailpos); 813#endif /* CONFIG_IEEE80211N */ 814 815 tailpos = hostapd_eid_ext_capab(hapd, tailpos); 816 817 /* 818 * TODO: Time Advertisement element should only be included in some 819 * DTIM Beacon frames. 820 */ 821 tailpos = hostapd_eid_time_adv(hapd, tailpos); 822 823 tailpos = hostapd_eid_interworking(hapd, tailpos); 824 tailpos = hostapd_eid_adv_proto(hapd, tailpos); 825 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); 826 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail, 827 &hapd->iface->cs_c_off_beacon); 828#ifdef CONFIG_IEEE80211AC 829 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos); 830 tailpos = hostapd_eid_vht_operation(hapd, tailpos); 831#endif /* CONFIG_IEEE80211AC */ 832 833 /* Wi-Fi Alliance WMM */ 834 tailpos = hostapd_eid_wmm(hapd, tailpos); 835 836#ifdef CONFIG_WPS 837 if (hapd->conf->wps_state && hapd->wps_beacon_ie) { 838 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), 839 wpabuf_len(hapd->wps_beacon_ie)); 840 tailpos += wpabuf_len(hapd->wps_beacon_ie); 841 } 842#endif /* CONFIG_WPS */ 843 844#ifdef CONFIG_P2P 845 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { 846 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), 847 wpabuf_len(hapd->p2p_beacon_ie)); 848 tailpos += wpabuf_len(hapd->p2p_beacon_ie); 849 } 850#endif /* CONFIG_P2P */ 851#ifdef CONFIG_P2P_MANAGER 852 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == 853 P2P_MANAGE) 854 tailpos = hostapd_eid_p2p_manage(hapd, tailpos); 855#endif /* CONFIG_P2P_MANAGER */ 856 857#ifdef CONFIG_HS20 858 tailpos = hostapd_eid_hs20_indication(hapd, tailpos); 859 tailpos = hostapd_eid_osen(hapd, tailpos); 860#endif /* CONFIG_HS20 */ 861 862 if (hapd->conf->vendor_elements) { 863 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), 864 wpabuf_len(hapd->conf->vendor_elements)); 865 tailpos += wpabuf_len(hapd->conf->vendor_elements); 866 } 867 868 tail_len = tailpos > tail ? tailpos - tail : 0; 869 870 resp = hostapd_probe_resp_offloads(hapd, &resp_len); 871#endif /* NEED_AP_MLME */ 872 873 os_memset(params, 0, sizeof(*params)); 874 params->head = (u8 *) head; 875 params->head_len = head_len; 876 params->tail = tail; 877 params->tail_len = tail_len; 878 params->proberesp = resp; 879 params->proberesp_len = resp_len; 880 params->dtim_period = hapd->conf->dtim_period; 881 params->beacon_int = hapd->iconf->beacon_int; 882 params->basic_rates = hapd->iface->basic_rates; 883 params->ssid = hapd->conf->ssid.ssid; 884 params->ssid_len = hapd->conf->ssid.ssid_len; 885 params->pairwise_ciphers = hapd->conf->wpa_pairwise | 886 hapd->conf->rsn_pairwise; 887 params->group_cipher = hapd->conf->wpa_group; 888 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; 889 params->auth_algs = hapd->conf->auth_algs; 890 params->wpa_version = hapd->conf->wpa; 891 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa || 892 (hapd->conf->ieee802_1x && 893 (hapd->conf->default_wep_key_len || 894 hapd->conf->individual_wep_key_len)); 895 switch (hapd->conf->ignore_broadcast_ssid) { 896 case 0: 897 params->hide_ssid = NO_SSID_HIDING; 898 break; 899 case 1: 900 params->hide_ssid = HIDDEN_SSID_ZERO_LEN; 901 break; 902 case 2: 903 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; 904 break; 905 } 906 params->isolate = hapd->conf->isolate; 907#ifdef NEED_AP_MLME 908 params->cts_protect = !!(ieee802_11_erp_info(hapd) & 909 ERP_INFO_USE_PROTECTION); 910 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && 911 hapd->iconf->preamble == SHORT_PREAMBLE; 912 if (hapd->iface->current_mode && 913 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) 914 params->short_slot_time = 915 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; 916 else 917 params->short_slot_time = -1; 918 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) 919 params->ht_opmode = -1; 920 else 921 params->ht_opmode = hapd->iface->ht_op_mode; 922#endif /* NEED_AP_MLME */ 923 params->interworking = hapd->conf->interworking; 924 if (hapd->conf->interworking && 925 !is_zero_ether_addr(hapd->conf->hessid)) 926 params->hessid = hapd->conf->hessid; 927 params->access_network_type = hapd->conf->access_network_type; 928 params->ap_max_inactivity = hapd->conf->ap_max_inactivity; 929#ifdef CONFIG_HS20 930 params->disable_dgaf = hapd->conf->disable_dgaf; 931 if (hapd->conf->osen) { 932 params->privacy = 1; 933 params->osen = 1; 934 } 935#endif /* CONFIG_HS20 */ 936 return 0; 937} 938 939 940void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) 941{ 942 os_free(params->tail); 943 params->tail = NULL; 944 os_free(params->head); 945 params->head = NULL; 946 os_free(params->proberesp); 947 params->proberesp = NULL; 948} 949 950 951int ieee802_11_set_beacon(struct hostapd_data *hapd) 952{ 953 struct wpa_driver_ap_params params; 954 struct hostapd_freq_params freq; 955 struct hostapd_iface *iface = hapd->iface; 956 struct hostapd_config *iconf = iface->conf; 957 struct wpabuf *beacon, *proberesp, *assocresp; 958 int res, ret = -1; 959 960 if (hapd->iface->csa_in_progress) { 961 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); 962 return -1; 963 } 964 965 hapd->beacon_set_done = 1; 966 967 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) 968 return -1; 969 970 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 971 0) 972 goto fail; 973 974 params.beacon_ies = beacon; 975 params.proberesp_ies = proberesp; 976 params.assocresp_ies = assocresp; 977 978 if (iface->current_mode && 979 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, 980 iconf->channel, iconf->ieee80211n, 981 iconf->ieee80211ac, 982 iconf->secondary_channel, 983 iconf->vht_oper_chwidth, 984 iconf->vht_oper_centr_freq_seg0_idx, 985 iconf->vht_oper_centr_freq_seg1_idx, 986 iface->current_mode->vht_capab) == 0) 987 params.freq = &freq; 988 989 res = hostapd_drv_set_ap(hapd, ¶ms); 990 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); 991 if (res) 992 wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); 993 else 994 ret = 0; 995fail: 996 ieee802_11_free_ap_params(¶ms); 997 return ret; 998} 999 1000 1001int ieee802_11_set_beacons(struct hostapd_iface *iface) 1002{ 1003 size_t i; 1004 int ret = 0; 1005 1006 for (i = 0; i < iface->num_bss; i++) { 1007 if (iface->bss[i]->started && 1008 ieee802_11_set_beacon(iface->bss[i]) < 0) 1009 ret = -1; 1010 } 1011 1012 return ret; 1013} 1014 1015 1016/* only update beacons if started */ 1017int ieee802_11_update_beacons(struct hostapd_iface *iface) 1018{ 1019 size_t i; 1020 int ret = 0; 1021 1022 for (i = 0; i < iface->num_bss; i++) { 1023 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && 1024 ieee802_11_set_beacon(iface->bss[i]) < 0) 1025 ret = -1; 1026 } 1027 1028 return ret; 1029} 1030 1031#endif /* CONFIG_NATIVE_WINDOWS */ 1032