xref: /freebsd/contrib/wpa/src/ap/ieee802_11_vht.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1f05cddf9SRui Paulo /*
2f05cddf9SRui Paulo  * hostapd / IEEE 802.11ac VHT
3f05cddf9SRui Paulo  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4f05cddf9SRui Paulo  *
5f05cddf9SRui Paulo  * This program is free software; you can redistribute it and/or modify
6f05cddf9SRui Paulo  * it under the terms of BSD license
7f05cddf9SRui Paulo  *
8f05cddf9SRui Paulo  * See README and COPYING for more details.
9f05cddf9SRui Paulo  */
10f05cddf9SRui Paulo 
11f05cddf9SRui Paulo #include "utils/includes.h"
12f05cddf9SRui Paulo 
13f05cddf9SRui Paulo #include "utils/common.h"
14f05cddf9SRui Paulo #include "common/ieee802_11_defs.h"
15*a90b9d01SCy Schubert #include "common/hw_features_common.h"
16f05cddf9SRui Paulo #include "hostapd.h"
17f05cddf9SRui Paulo #include "ap_config.h"
18f05cddf9SRui Paulo #include "sta_info.h"
19f05cddf9SRui Paulo #include "beacon.h"
20f05cddf9SRui Paulo #include "ieee802_11.h"
21780fb4a2SCy Schubert #include "dfs.h"
22f05cddf9SRui Paulo 
23f05cddf9SRui Paulo 
hostapd_eid_vht_capabilities(struct hostapd_data * hapd,u8 * eid,u32 nsts)24780fb4a2SCy Schubert u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid, u32 nsts)
25f05cddf9SRui Paulo {
26f05cddf9SRui Paulo 	struct ieee80211_vht_capabilities *cap;
275b9c547cSRui Paulo 	struct hostapd_hw_modes *mode = hapd->iface->current_mode;
28f05cddf9SRui Paulo 	u8 *pos = eid;
29f05cddf9SRui Paulo 
30c1d255d3SCy Schubert 	if (!mode || is_6ghz_op_class(hapd->iconf->op_class))
31f05cddf9SRui Paulo 		return eid;
32f05cddf9SRui Paulo 
335b9c547cSRui Paulo 	if (mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->conf->vendor_vht &&
345b9c547cSRui Paulo 	    mode->vht_capab == 0 && hapd->iface->hw_features) {
355b9c547cSRui Paulo 		int i;
365b9c547cSRui Paulo 
375b9c547cSRui Paulo 		for (i = 0; i < hapd->iface->num_hw_features; i++) {
385b9c547cSRui Paulo 			if (hapd->iface->hw_features[i].mode ==
395b9c547cSRui Paulo 			    HOSTAPD_MODE_IEEE80211A) {
405b9c547cSRui Paulo 				mode = &hapd->iface->hw_features[i];
415b9c547cSRui Paulo 				break;
425b9c547cSRui Paulo 			}
435b9c547cSRui Paulo 		}
445b9c547cSRui Paulo 	}
455b9c547cSRui Paulo 
46f05cddf9SRui Paulo 	*pos++ = WLAN_EID_VHT_CAP;
47f05cddf9SRui Paulo 	*pos++ = sizeof(*cap);
48f05cddf9SRui Paulo 
49f05cddf9SRui Paulo 	cap = (struct ieee80211_vht_capabilities *) pos;
50f05cddf9SRui Paulo 	os_memset(cap, 0, sizeof(*cap));
51f05cddf9SRui Paulo 	cap->vht_capabilities_info = host_to_le32(
525b9c547cSRui Paulo 		hapd->iface->conf->vht_capab);
53f05cddf9SRui Paulo 
54780fb4a2SCy Schubert 	if (nsts != 0) {
55780fb4a2SCy Schubert 		u32 hapd_nsts;
56780fb4a2SCy Schubert 
57780fb4a2SCy Schubert 		hapd_nsts = le_to_host32(cap->vht_capabilities_info);
58780fb4a2SCy Schubert 		hapd_nsts = (hapd_nsts >> VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
59780fb4a2SCy Schubert 		cap->vht_capabilities_info &=
60780fb4a2SCy Schubert 			~(host_to_le32(hapd_nsts <<
61780fb4a2SCy Schubert 				       VHT_CAP_BEAMFORMEE_STS_OFFSET));
62780fb4a2SCy Schubert 		cap->vht_capabilities_info |=
63780fb4a2SCy Schubert 			host_to_le32(nsts << VHT_CAP_BEAMFORMEE_STS_OFFSET);
64780fb4a2SCy Schubert 	}
65780fb4a2SCy Schubert 
66f05cddf9SRui Paulo 	/* Supported MCS set comes from hw */
675b9c547cSRui Paulo 	os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
68f05cddf9SRui Paulo 
69f05cddf9SRui Paulo 	pos += sizeof(*cap);
70f05cddf9SRui Paulo 
71f05cddf9SRui Paulo 	return pos;
72f05cddf9SRui Paulo }
73f05cddf9SRui Paulo 
74f05cddf9SRui Paulo 
hostapd_eid_vht_operation(struct hostapd_data * hapd,u8 * eid)75f05cddf9SRui Paulo u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
76f05cddf9SRui Paulo {
77f05cddf9SRui Paulo 	struct ieee80211_vht_operation *oper;
78f05cddf9SRui Paulo 	u8 *pos = eid;
79*a90b9d01SCy Schubert 	enum oper_chan_width oper_chwidth =
80*a90b9d01SCy Schubert 		hostapd_get_oper_chwidth(hapd->iconf);
81*a90b9d01SCy Schubert 	u8 seg0 = hapd->iconf->vht_oper_centr_freq_seg0_idx;
82*a90b9d01SCy Schubert 	u8 seg1 = hapd->iconf->vht_oper_centr_freq_seg1_idx;
83*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
84*a90b9d01SCy Schubert 	u16 punct_bitmap = hostapd_get_punct_bitmap(hapd);
85*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
86f05cddf9SRui Paulo 
87c1d255d3SCy Schubert 	if (is_6ghz_op_class(hapd->iconf->op_class))
88c1d255d3SCy Schubert 		return eid;
89c1d255d3SCy Schubert 
90f05cddf9SRui Paulo 	*pos++ = WLAN_EID_VHT_OPERATION;
91f05cddf9SRui Paulo 	*pos++ = sizeof(*oper);
92f05cddf9SRui Paulo 
93f05cddf9SRui Paulo 	oper = (struct ieee80211_vht_operation *) pos;
94f05cddf9SRui Paulo 	os_memset(oper, 0, sizeof(*oper));
95f05cddf9SRui Paulo 
96*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
97*a90b9d01SCy Schubert 	if (punct_bitmap) {
98*a90b9d01SCy Schubert 		punct_update_legacy_bw(punct_bitmap,
99*a90b9d01SCy Schubert 				       hapd->iconf->channel,
100*a90b9d01SCy Schubert 				       &oper_chwidth, &seg0, &seg1);
101*a90b9d01SCy Schubert 	}
102*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
103*a90b9d01SCy Schubert 
104f05cddf9SRui Paulo 	/*
105f05cddf9SRui Paulo 	 * center freq = 5 GHz + (5 * index)
106f05cddf9SRui Paulo 	 * So index 42 gives center freq 5.210 GHz
107f05cddf9SRui Paulo 	 * which is channel 42 in 5G band
108f05cddf9SRui Paulo 	 */
109*a90b9d01SCy Schubert 	oper->vht_op_info_chan_center_freq_seg0_idx = seg0;
110*a90b9d01SCy Schubert 	oper->vht_op_info_chan_center_freq_seg1_idx = seg1;
111f05cddf9SRui Paulo 
112*a90b9d01SCy Schubert 	oper->vht_op_info_chwidth = oper_chwidth;
113*a90b9d01SCy Schubert 	if (oper_chwidth == CONF_OPER_CHWIDTH_160MHZ) {
114780fb4a2SCy Schubert 		/*
115780fb4a2SCy Schubert 		 * Convert 160 MHz channel width to new style as interop
116780fb4a2SCy Schubert 		 * workaround.
117780fb4a2SCy Schubert 		 */
118*a90b9d01SCy Schubert 		oper->vht_op_info_chwidth = CHANWIDTH_80MHZ;
119780fb4a2SCy Schubert 		oper->vht_op_info_chan_center_freq_seg1_idx =
120780fb4a2SCy Schubert 			oper->vht_op_info_chan_center_freq_seg0_idx;
121780fb4a2SCy Schubert 		if (hapd->iconf->channel <
122780fb4a2SCy Schubert 		    hapd->iconf->vht_oper_centr_freq_seg0_idx)
123780fb4a2SCy Schubert 			oper->vht_op_info_chan_center_freq_seg0_idx -= 8;
124780fb4a2SCy Schubert 		else
125780fb4a2SCy Schubert 			oper->vht_op_info_chan_center_freq_seg0_idx += 8;
126*a90b9d01SCy Schubert 	} else if (oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ) {
127780fb4a2SCy Schubert 		/*
128780fb4a2SCy Schubert 		 * Convert 80+80 MHz channel width to new style as interop
129780fb4a2SCy Schubert 		 * workaround.
130780fb4a2SCy Schubert 		 */
131*a90b9d01SCy Schubert 		oper->vht_op_info_chwidth = CHANWIDTH_80MHZ;
132780fb4a2SCy Schubert 	}
133f05cddf9SRui Paulo 
134f05cddf9SRui Paulo 	/* VHT Basic MCS set comes from hw */
135f05cddf9SRui Paulo 	/* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
136f05cddf9SRui Paulo 	oper->vht_basic_mcs_set = host_to_le16(0xfffc);
137f05cddf9SRui Paulo 	pos += sizeof(*oper);
138f05cddf9SRui Paulo 
139f05cddf9SRui Paulo 	return pos;
140f05cddf9SRui Paulo }
141f05cddf9SRui Paulo 
142f05cddf9SRui Paulo 
check_valid_vht_mcs(struct hostapd_hw_modes * mode,const u8 * sta_vht_capab)1435b9c547cSRui Paulo static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
1445b9c547cSRui Paulo 			       const u8 *sta_vht_capab)
1455b9c547cSRui Paulo {
1465b9c547cSRui Paulo 	const struct ieee80211_vht_capabilities *vht_cap;
1475b9c547cSRui Paulo 	struct ieee80211_vht_capabilities ap_vht_cap;
1485b9c547cSRui Paulo 	u16 sta_rx_mcs_set, ap_tx_mcs_set;
1495b9c547cSRui Paulo 	int i;
1505b9c547cSRui Paulo 
1515b9c547cSRui Paulo 	if (!mode)
1525b9c547cSRui Paulo 		return 1;
1535b9c547cSRui Paulo 
1545b9c547cSRui Paulo 	/*
1555b9c547cSRui Paulo 	 * Disable VHT caps for STAs for which there is not even a single
1565b9c547cSRui Paulo 	 * allowed MCS in any supported number of streams, i.e., STA is
1575b9c547cSRui Paulo 	 * advertising 3 (not supported) as VHT MCS rates for all supported
1585b9c547cSRui Paulo 	 * stream cases.
1595b9c547cSRui Paulo 	 */
1605b9c547cSRui Paulo 	os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
1615b9c547cSRui Paulo 		  sizeof(ap_vht_cap.vht_supported_mcs_set));
1625b9c547cSRui Paulo 	vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
1635b9c547cSRui Paulo 
1645b9c547cSRui Paulo 	/* AP Tx MCS map vs. STA Rx MCS map */
1655b9c547cSRui Paulo 	sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
1665b9c547cSRui Paulo 	ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
1675b9c547cSRui Paulo 
1685b9c547cSRui Paulo 	for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
1695b9c547cSRui Paulo 		if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
1705b9c547cSRui Paulo 			continue;
1715b9c547cSRui Paulo 
1725b9c547cSRui Paulo 		if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
1735b9c547cSRui Paulo 			continue;
1745b9c547cSRui Paulo 
1755b9c547cSRui Paulo 		return 1;
1765b9c547cSRui Paulo 	}
1775b9c547cSRui Paulo 
1785b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG,
1795b9c547cSRui Paulo 		   "No matching VHT MCS found between AP TX and STA RX");
1805b9c547cSRui Paulo 	return 0;
1815b9c547cSRui Paulo }
1825b9c547cSRui Paulo 
1835b9c547cSRui Paulo 
copy_sta_vht_capab(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_capab)184f05cddf9SRui Paulo u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
185325151a3SRui Paulo 		       const u8 *vht_capab)
186f05cddf9SRui Paulo {
187f05cddf9SRui Paulo 	/* Disable VHT caps for STAs associated to no-VHT BSSes. */
188c1d255d3SCy Schubert 	if (!vht_capab || !(sta->flags & WLAN_STA_WMM) ||
18985732ac8SCy Schubert 	    !hapd->iconf->ieee80211ac || hapd->conf->disable_11ac ||
1905b9c547cSRui Paulo 	    !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
191f05cddf9SRui Paulo 		sta->flags &= ~WLAN_STA_VHT;
192f05cddf9SRui Paulo 		os_free(sta->vht_capabilities);
193f05cddf9SRui Paulo 		sta->vht_capabilities = NULL;
194f05cddf9SRui Paulo 		return WLAN_STATUS_SUCCESS;
195f05cddf9SRui Paulo 	}
196f05cddf9SRui Paulo 
197f05cddf9SRui Paulo 	if (sta->vht_capabilities == NULL) {
198f05cddf9SRui Paulo 		sta->vht_capabilities =
199f05cddf9SRui Paulo 			os_zalloc(sizeof(struct ieee80211_vht_capabilities));
200f05cddf9SRui Paulo 		if (sta->vht_capabilities == NULL)
201f05cddf9SRui Paulo 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
202f05cddf9SRui Paulo 	}
203f05cddf9SRui Paulo 
204f05cddf9SRui Paulo 	sta->flags |= WLAN_STA_VHT;
205f05cddf9SRui Paulo 	os_memcpy(sta->vht_capabilities, vht_capab,
206f05cddf9SRui Paulo 		  sizeof(struct ieee80211_vht_capabilities));
207f05cddf9SRui Paulo 
208f05cddf9SRui Paulo 	return WLAN_STATUS_SUCCESS;
209f05cddf9SRui Paulo }
2105b9c547cSRui Paulo 
2115b9c547cSRui Paulo 
copy_sta_vht_oper(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_oper)2124bc52338SCy Schubert u16 copy_sta_vht_oper(struct hostapd_data *hapd, struct sta_info *sta,
2134bc52338SCy Schubert 		      const u8 *vht_oper)
2144bc52338SCy Schubert {
2154bc52338SCy Schubert 	if (!vht_oper) {
2164bc52338SCy Schubert 		os_free(sta->vht_operation);
2174bc52338SCy Schubert 		sta->vht_operation = NULL;
2184bc52338SCy Schubert 		return WLAN_STATUS_SUCCESS;
2194bc52338SCy Schubert 	}
2204bc52338SCy Schubert 
2214bc52338SCy Schubert 	if (!sta->vht_operation) {
2224bc52338SCy Schubert 		sta->vht_operation =
2234bc52338SCy Schubert 			os_zalloc(sizeof(struct ieee80211_vht_operation));
2244bc52338SCy Schubert 		if (!sta->vht_operation)
2254bc52338SCy Schubert 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
2264bc52338SCy Schubert 	}
2274bc52338SCy Schubert 
2284bc52338SCy Schubert 	os_memcpy(sta->vht_operation, vht_oper,
2294bc52338SCy Schubert 		  sizeof(struct ieee80211_vht_operation));
2304bc52338SCy Schubert 
2314bc52338SCy Schubert 	return WLAN_STATUS_SUCCESS;
2324bc52338SCy Schubert }
2334bc52338SCy Schubert 
2344bc52338SCy Schubert 
copy_sta_vendor_vht(struct hostapd_data * hapd,struct sta_info * sta,const u8 * ie,size_t len)2355b9c547cSRui Paulo u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
2365b9c547cSRui Paulo 			const u8 *ie, size_t len)
2375b9c547cSRui Paulo {
2385b9c547cSRui Paulo 	const u8 *vht_capab;
2395b9c547cSRui Paulo 	unsigned int vht_capab_len;
2405b9c547cSRui Paulo 
2415b9c547cSRui Paulo 	if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
2425b9c547cSRui Paulo 	    hapd->conf->disable_11ac)
2435b9c547cSRui Paulo 		goto no_capab;
2445b9c547cSRui Paulo 
2455b9c547cSRui Paulo 	/* The VHT Capabilities element embedded in vendor VHT */
2465b9c547cSRui Paulo 	vht_capab = ie + 5;
2475b9c547cSRui Paulo 	if (vht_capab[0] != WLAN_EID_VHT_CAP)
2485b9c547cSRui Paulo 		goto no_capab;
2495b9c547cSRui Paulo 	vht_capab_len = vht_capab[1];
2505b9c547cSRui Paulo 	if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
2515b9c547cSRui Paulo 	    (int) vht_capab_len > ie + len - vht_capab - 2)
2525b9c547cSRui Paulo 		goto no_capab;
2535b9c547cSRui Paulo 	vht_capab += 2;
2545b9c547cSRui Paulo 
2555b9c547cSRui Paulo 	if (sta->vht_capabilities == NULL) {
2565b9c547cSRui Paulo 		sta->vht_capabilities =
2575b9c547cSRui Paulo 			os_zalloc(sizeof(struct ieee80211_vht_capabilities));
2585b9c547cSRui Paulo 		if (sta->vht_capabilities == NULL)
2595b9c547cSRui Paulo 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
2605b9c547cSRui Paulo 	}
2615b9c547cSRui Paulo 
2625b9c547cSRui Paulo 	sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
2635b9c547cSRui Paulo 	os_memcpy(sta->vht_capabilities, vht_capab,
2645b9c547cSRui Paulo 		  sizeof(struct ieee80211_vht_capabilities));
2655b9c547cSRui Paulo 	return WLAN_STATUS_SUCCESS;
2665b9c547cSRui Paulo 
2675b9c547cSRui Paulo no_capab:
2685b9c547cSRui Paulo 	sta->flags &= ~WLAN_STA_VENDOR_VHT;
2695b9c547cSRui Paulo 	return WLAN_STATUS_SUCCESS;
2705b9c547cSRui Paulo }
2715b9c547cSRui Paulo 
2725b9c547cSRui Paulo 
hostapd_eid_vendor_vht(struct hostapd_data * hapd,u8 * eid)2735b9c547cSRui Paulo u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
2745b9c547cSRui Paulo {
2755b9c547cSRui Paulo 	u8 *pos = eid;
2765b9c547cSRui Paulo 
277c1d255d3SCy Schubert 	/* Vendor VHT is applicable only to 2.4 GHz */
278c1d255d3SCy Schubert 	if (!hapd->iface->current_mode ||
279c1d255d3SCy Schubert 	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
2805b9c547cSRui Paulo 		return eid;
2815b9c547cSRui Paulo 
2825b9c547cSRui Paulo 	*pos++ = WLAN_EID_VENDOR_SPECIFIC;
2835b9c547cSRui Paulo 	*pos++ = (5 +		/* The Vendor OUI, type and subtype */
2845b9c547cSRui Paulo 		  2 + sizeof(struct ieee80211_vht_capabilities) +
2855b9c547cSRui Paulo 		  2 + sizeof(struct ieee80211_vht_operation));
2865b9c547cSRui Paulo 
2875b9c547cSRui Paulo 	WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
2885b9c547cSRui Paulo 	pos += 4;
2895b9c547cSRui Paulo 	*pos++ = VENDOR_VHT_SUBTYPE;
290780fb4a2SCy Schubert 	pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
2915b9c547cSRui Paulo 	pos = hostapd_eid_vht_operation(hapd, pos);
2925b9c547cSRui Paulo 
2935b9c547cSRui Paulo 	return pos;
2945b9c547cSRui Paulo }
2955b9c547cSRui Paulo 
2965b9c547cSRui Paulo 
set_sta_vht_opmode(struct hostapd_data * hapd,struct sta_info * sta,const u8 * vht_oper_notif)2975b9c547cSRui Paulo u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
2985b9c547cSRui Paulo 		       const u8 *vht_oper_notif)
2995b9c547cSRui Paulo {
3005b9c547cSRui Paulo 	if (!vht_oper_notif) {
3015b9c547cSRui Paulo 		sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
3025b9c547cSRui Paulo 		return WLAN_STATUS_SUCCESS;
3035b9c547cSRui Paulo 	}
3045b9c547cSRui Paulo 
3055b9c547cSRui Paulo 	sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
3065b9c547cSRui Paulo 	sta->vht_opmode = *vht_oper_notif;
3075b9c547cSRui Paulo 	return WLAN_STATUS_SUCCESS;
3085b9c547cSRui Paulo }
3095b9c547cSRui Paulo 
3105b9c547cSRui Paulo 
hostapd_get_vht_capab(struct hostapd_data * hapd,struct ieee80211_vht_capabilities * vht_cap,struct ieee80211_vht_capabilities * neg_vht_cap)3115b9c547cSRui Paulo void hostapd_get_vht_capab(struct hostapd_data *hapd,
3125b9c547cSRui Paulo 			   struct ieee80211_vht_capabilities *vht_cap,
3135b9c547cSRui Paulo 			   struct ieee80211_vht_capabilities *neg_vht_cap)
3145b9c547cSRui Paulo {
3155b9c547cSRui Paulo 	u32 cap, own_cap, sym_caps;
3165b9c547cSRui Paulo 
3175b9c547cSRui Paulo 	if (vht_cap == NULL)
3185b9c547cSRui Paulo 		return;
3195b9c547cSRui Paulo 	os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
3205b9c547cSRui Paulo 
3215b9c547cSRui Paulo 	cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
3225b9c547cSRui Paulo 	own_cap = hapd->iconf->vht_capab;
3235b9c547cSRui Paulo 
3245b9c547cSRui Paulo 	/* mask out symmetric VHT capabilities we don't support */
3255b9c547cSRui Paulo 	sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
3265b9c547cSRui Paulo 	cap &= ~sym_caps | (own_cap & sym_caps);
3275b9c547cSRui Paulo 
3285b9c547cSRui Paulo 	/* mask out beamformer/beamformee caps if not supported */
3295b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
3305b9c547cSRui Paulo 		cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
3315b9c547cSRui Paulo 			 VHT_CAP_BEAMFORMEE_STS_MAX);
3325b9c547cSRui Paulo 
3335b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
3345b9c547cSRui Paulo 		cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
3355b9c547cSRui Paulo 			 VHT_CAP_SOUNDING_DIMENSION_MAX);
3365b9c547cSRui Paulo 
3375b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
3385b9c547cSRui Paulo 		cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
3395b9c547cSRui Paulo 
3405b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
3415b9c547cSRui Paulo 		cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
3425b9c547cSRui Paulo 
3435b9c547cSRui Paulo 	/* mask channel widths we don't support */
3445b9c547cSRui Paulo 	switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
3455b9c547cSRui Paulo 	case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
3465b9c547cSRui Paulo 		break;
3475b9c547cSRui Paulo 	case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
3485b9c547cSRui Paulo 		if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
3495b9c547cSRui Paulo 			cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
3505b9c547cSRui Paulo 			cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
3515b9c547cSRui Paulo 		}
3525b9c547cSRui Paulo 		break;
3535b9c547cSRui Paulo 	default:
3545b9c547cSRui Paulo 		cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
3555b9c547cSRui Paulo 		break;
3565b9c547cSRui Paulo 	}
3575b9c547cSRui Paulo 
3585b9c547cSRui Paulo 	if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
3595b9c547cSRui Paulo 		cap &= ~VHT_CAP_SHORT_GI_160;
3605b9c547cSRui Paulo 
3615b9c547cSRui Paulo 	/*
3625b9c547cSRui Paulo 	 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
3635b9c547cSRui Paulo 	 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
3645b9c547cSRui Paulo 	 */
3655b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_RXSTBC_MASK))
3665b9c547cSRui Paulo 		cap &= ~VHT_CAP_TXSTBC;
3675b9c547cSRui Paulo 	if (!(own_cap & VHT_CAP_TXSTBC))
3685b9c547cSRui Paulo 		cap &= ~VHT_CAP_RXSTBC_MASK;
3695b9c547cSRui Paulo 
3705b9c547cSRui Paulo 	neg_vht_cap->vht_capabilities_info = host_to_le32(cap);
3715b9c547cSRui Paulo }
372