ieee802_11_vht.c revision 68d0e3ed07847339aedfac8e02f50db68c702e52
1/*
2 * hostapd / IEEE 802.11ac VHT
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of BSD license
7 *
8 * See README and COPYING for more details.
9 */
10
11#include "utils/includes.h"
12
13#include "utils/common.h"
14#include "common/ieee802_11_defs.h"
15#include "drivers/driver.h"
16#include "hostapd.h"
17#include "ap_config.h"
18#include "sta_info.h"
19#include "beacon.h"
20#include "ieee802_11.h"
21
22
23u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
24{
25	struct ieee80211_vht_capabilities *cap;
26	u8 *pos = eid;
27
28	if (!hapd->iconf->ieee80211ac || !hapd->iface->current_mode ||
29	    hapd->conf->disable_11ac)
30		return eid;
31
32	*pos++ = WLAN_EID_VHT_CAP;
33	*pos++ = sizeof(*cap);
34
35	cap = (struct ieee80211_vht_capabilities *) pos;
36	os_memset(cap, 0, sizeof(*cap));
37	cap->vht_capabilities_info = host_to_le32(
38		hapd->iface->current_mode->vht_capab);
39
40	/* Supported MCS set comes from hw */
41	os_memcpy(&cap->vht_supported_mcs_set,
42	          hapd->iface->current_mode->vht_mcs_set, 8);
43
44	pos += sizeof(*cap);
45
46	return pos;
47}
48
49
50u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
51{
52	struct ieee80211_vht_operation *oper;
53	u8 *pos = eid;
54
55	if (!hapd->iconf->ieee80211ac || hapd->conf->disable_11ac)
56		return eid;
57
58	*pos++ = WLAN_EID_VHT_OPERATION;
59	*pos++ = sizeof(*oper);
60
61	oper = (struct ieee80211_vht_operation *) pos;
62	os_memset(oper, 0, sizeof(*oper));
63
64	/*
65	 * center freq = 5 GHz + (5 * index)
66	 * So index 42 gives center freq 5.210 GHz
67	 * which is channel 42 in 5G band
68	 */
69	oper->vht_op_info_chan_center_freq_seg0_idx =
70		hapd->iconf->vht_oper_centr_freq_seg0_idx;
71	oper->vht_op_info_chan_center_freq_seg1_idx =
72		hapd->iconf->vht_oper_centr_freq_seg1_idx;
73
74	oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
75
76	/* VHT Basic MCS set comes from hw */
77	/* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
78	oper->vht_basic_mcs_set = host_to_le16(0xfffc);
79	pos += sizeof(*oper);
80
81	return pos;
82}
83
84
85u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
86		       const u8 *vht_capab, size_t vht_capab_len)
87{
88	/* Disable VHT caps for STAs associated to no-VHT BSSes. */
89	if (!vht_capab ||
90	    vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
91	    hapd->conf->disable_11ac) {
92		sta->flags &= ~WLAN_STA_VHT;
93		os_free(sta->vht_capabilities);
94		sta->vht_capabilities = NULL;
95		return WLAN_STATUS_SUCCESS;
96	}
97
98	if (sta->vht_capabilities == NULL) {
99		sta->vht_capabilities =
100			os_zalloc(sizeof(struct ieee80211_vht_capabilities));
101		if (sta->vht_capabilities == NULL)
102			return WLAN_STATUS_UNSPECIFIED_FAILURE;
103	}
104
105	sta->flags |= WLAN_STA_VHT;
106	os_memcpy(sta->vht_capabilities, vht_capab,
107		  sizeof(struct ieee80211_vht_capabilities));
108
109	return WLAN_STATUS_SUCCESS;
110}
111
112void hostapd_get_vht_capab(struct hostapd_data *hapd,
113			   struct ieee80211_vht_capabilities *vht_cap,
114			   struct ieee80211_vht_capabilities *neg_vht_cap)
115{
116	u32 cap, own_cap, sym_caps;
117
118	if (vht_cap == NULL)
119		return;
120	os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
121
122	cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
123	own_cap = hapd->iconf->vht_capab;
124
125	/* mask out symmetric VHT capabilities we don't support */
126	sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
127	cap &= ~sym_caps | (own_cap & sym_caps);
128
129	/* mask out beamformer/beamformee caps if not supported */
130	if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
131		cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
132			 VHT_CAP_BEAMFORMEE_STS_MAX);
133
134	if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
135		cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
136			 VHT_CAP_SOUNDING_DIMENSION_MAX);
137
138	if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
139		cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
140
141	if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
142		cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
143
144	/* mask channel widths we don't support */
145	switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
146	case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
147		break;
148	case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
149		if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
150			cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
151			cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
152		}
153		break;
154	default:
155		cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
156		break;
157	}
158
159	if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
160		cap &= ~VHT_CAP_SHORT_GI_160;
161
162	/*
163	 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
164	 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
165	 */
166	if (!(own_cap & VHT_CAP_RXSTBC_MASK))
167		cap &= ~VHT_CAP_TXSTBC;
168	if (!(own_cap & VHT_CAP_TXSTBC))
169		cap &= ~VHT_CAP_RXSTBC_MASK;
170
171	neg_vht_cap->vht_capabilities_info = host_to_le32(cap);
172}
173