Line data Source code
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 "hostapd.h"
16 : #include "ap_config.h"
17 : #include "sta_info.h"
18 : #include "beacon.h"
19 : #include "ieee802_11.h"
20 : #include "dfs.h"
21 :
22 :
23 138 : u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid, u32 nsts)
24 : {
25 : struct ieee80211_vht_capabilities *cap;
26 138 : struct hostapd_hw_modes *mode = hapd->iface->current_mode;
27 138 : u8 *pos = eid;
28 :
29 138 : if (!mode)
30 0 : return eid;
31 :
32 142 : if (mode->mode == HOSTAPD_MODE_IEEE80211G && hapd->conf->vendor_vht &&
33 8 : mode->vht_capab == 0 && hapd->iface->hw_features) {
34 : int i;
35 :
36 8 : for (i = 0; i < hapd->iface->num_hw_features; i++) {
37 8 : if (hapd->iface->hw_features[i].mode ==
38 : HOSTAPD_MODE_IEEE80211A) {
39 4 : mode = &hapd->iface->hw_features[i];
40 4 : break;
41 : }
42 : }
43 : }
44 :
45 138 : *pos++ = WLAN_EID_VHT_CAP;
46 138 : *pos++ = sizeof(*cap);
47 :
48 138 : cap = (struct ieee80211_vht_capabilities *) pos;
49 138 : os_memset(cap, 0, sizeof(*cap));
50 138 : cap->vht_capabilities_info = host_to_le32(
51 : hapd->iface->conf->vht_capab);
52 :
53 138 : if (nsts != 0) {
54 : u32 hapd_nsts;
55 :
56 0 : hapd_nsts = le_to_host32(cap->vht_capabilities_info);
57 0 : hapd_nsts = (hapd_nsts >> VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
58 0 : cap->vht_capabilities_info &=
59 0 : ~(host_to_le32(hapd_nsts <<
60 : VHT_CAP_BEAMFORMEE_STS_OFFSET));
61 0 : cap->vht_capabilities_info |=
62 0 : host_to_le32(nsts << VHT_CAP_BEAMFORMEE_STS_OFFSET);
63 : }
64 :
65 : /* Supported MCS set comes from hw */
66 138 : os_memcpy(&cap->vht_supported_mcs_set, mode->vht_mcs_set, 8);
67 :
68 138 : pos += sizeof(*cap);
69 :
70 138 : return pos;
71 : }
72 :
73 :
74 138 : u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
75 : {
76 : struct ieee80211_vht_operation *oper;
77 138 : u8 *pos = eid;
78 :
79 138 : *pos++ = WLAN_EID_VHT_OPERATION;
80 138 : *pos++ = sizeof(*oper);
81 :
82 138 : oper = (struct ieee80211_vht_operation *) pos;
83 138 : os_memset(oper, 0, sizeof(*oper));
84 :
85 : /*
86 : * center freq = 5 GHz + (5 * index)
87 : * So index 42 gives center freq 5.210 GHz
88 : * which is channel 42 in 5G band
89 : */
90 138 : oper->vht_op_info_chan_center_freq_seg0_idx =
91 138 : hapd->iconf->vht_oper_centr_freq_seg0_idx;
92 138 : oper->vht_op_info_chan_center_freq_seg1_idx =
93 138 : hapd->iconf->vht_oper_centr_freq_seg1_idx;
94 :
95 138 : oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
96 138 : if (hapd->iconf->vht_oper_chwidth == 2) {
97 : /*
98 : * Convert 160 MHz channel width to new style as interop
99 : * workaround.
100 : */
101 13 : oper->vht_op_info_chwidth = 1;
102 13 : oper->vht_op_info_chan_center_freq_seg1_idx =
103 13 : oper->vht_op_info_chan_center_freq_seg0_idx;
104 26 : if (hapd->iconf->channel <
105 13 : hapd->iconf->vht_oper_centr_freq_seg0_idx)
106 13 : oper->vht_op_info_chan_center_freq_seg0_idx -= 8;
107 : else
108 0 : oper->vht_op_info_chan_center_freq_seg0_idx += 8;
109 125 : } else if (hapd->iconf->vht_oper_chwidth == 3) {
110 : /*
111 : * Convert 80+80 MHz channel width to new style as interop
112 : * workaround.
113 : */
114 39 : oper->vht_op_info_chwidth = 1;
115 : }
116 :
117 : /* VHT Basic MCS set comes from hw */
118 : /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
119 138 : oper->vht_basic_mcs_set = host_to_le16(0xfffc);
120 138 : pos += sizeof(*oper);
121 :
122 138 : return pos;
123 : }
124 :
125 :
126 40 : static int check_valid_vht_mcs(struct hostapd_hw_modes *mode,
127 : const u8 *sta_vht_capab)
128 : {
129 : const struct ieee80211_vht_capabilities *vht_cap;
130 : struct ieee80211_vht_capabilities ap_vht_cap;
131 : u16 sta_rx_mcs_set, ap_tx_mcs_set;
132 : int i;
133 :
134 40 : if (!mode)
135 0 : return 1;
136 :
137 : /*
138 : * Disable VHT caps for STAs for which there is not even a single
139 : * allowed MCS in any supported number of streams, i.e., STA is
140 : * advertising 3 (not supported) as VHT MCS rates for all supported
141 : * stream cases.
142 : */
143 40 : os_memcpy(&ap_vht_cap.vht_supported_mcs_set, mode->vht_mcs_set,
144 : sizeof(ap_vht_cap.vht_supported_mcs_set));
145 40 : vht_cap = (const struct ieee80211_vht_capabilities *) sta_vht_capab;
146 :
147 : /* AP Tx MCS map vs. STA Rx MCS map */
148 40 : sta_rx_mcs_set = le_to_host16(vht_cap->vht_supported_mcs_set.rx_map);
149 40 : ap_tx_mcs_set = le_to_host16(ap_vht_cap.vht_supported_mcs_set.tx_map);
150 :
151 40 : for (i = 0; i < VHT_RX_NSS_MAX_STREAMS; i++) {
152 40 : if ((ap_tx_mcs_set & (0x3 << (i * 2))) == 3)
153 0 : continue;
154 :
155 40 : if ((sta_rx_mcs_set & (0x3 << (i * 2))) == 3)
156 0 : continue;
157 :
158 40 : return 1;
159 : }
160 :
161 0 : wpa_printf(MSG_DEBUG,
162 : "No matching VHT MCS found between AP TX and STA RX");
163 0 : return 0;
164 : }
165 :
166 :
167 87 : u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid)
168 : {
169 87 : u8 bw, chan1, chan2 = 0;
170 : int freq1;
171 :
172 89 : if (!hapd->cs_freq_params.channel ||
173 2 : !hapd->cs_freq_params.vht_enabled)
174 86 : return eid;
175 :
176 : /* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80 */
177 1 : switch (hapd->cs_freq_params.bandwidth) {
178 : case 40:
179 0 : bw = 0;
180 0 : break;
181 : case 80:
182 : /* check if it's 80+80 */
183 1 : if (!hapd->cs_freq_params.center_freq2)
184 1 : bw = 1;
185 : else
186 0 : bw = 3;
187 1 : break;
188 : case 160:
189 0 : bw = 2;
190 0 : break;
191 : default:
192 : /* not valid VHT bandwidth or not in CSA */
193 0 : return eid;
194 : }
195 :
196 2 : freq1 = hapd->cs_freq_params.center_freq1 ?
197 1 : hapd->cs_freq_params.center_freq1 :
198 : hapd->cs_freq_params.freq;
199 1 : if (ieee80211_freq_to_chan(freq1, &chan1) !=
200 : HOSTAPD_MODE_IEEE80211A)
201 0 : return eid;
202 :
203 1 : if (hapd->cs_freq_params.center_freq2 &&
204 0 : ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2,
205 : &chan2) != HOSTAPD_MODE_IEEE80211A)
206 0 : return eid;
207 :
208 1 : *eid++ = WLAN_EID_VHT_CHANNEL_SWITCH_WRAPPER;
209 1 : *eid++ = 5; /* Length of Channel Switch Wrapper */
210 1 : *eid++ = WLAN_EID_VHT_WIDE_BW_CHSWITCH;
211 1 : *eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */
212 1 : *eid++ = bw; /* New Channel Width */
213 1 : *eid++ = chan1; /* New Channel Center Frequency Segment 0 */
214 1 : *eid++ = chan2; /* New Channel Center Frequency Segment 1 */
215 :
216 1 : return eid;
217 : }
218 :
219 :
220 87 : u8 * hostapd_eid_txpower_envelope(struct hostapd_data *hapd, u8 *eid)
221 : {
222 87 : struct hostapd_iface *iface = hapd->iface;
223 87 : struct hostapd_config *iconf = iface->conf;
224 87 : struct hostapd_hw_modes *mode = iface->current_mode;
225 : struct hostapd_channel_data *chan;
226 : int dfs, i;
227 : u8 channel, tx_pwr_count, local_pwr_constraint;
228 : int max_tx_power;
229 : u8 tx_pwr;
230 :
231 87 : if (!mode)
232 0 : return eid;
233 :
234 87 : if (ieee80211_freq_to_chan(iface->freq, &channel) == NUM_HOSTAPD_MODES)
235 1 : return eid;
236 :
237 285 : for (i = 0; i < mode->num_channels; i++) {
238 285 : if (mode->channels[i].freq == iface->freq)
239 86 : break;
240 : }
241 86 : if (i == mode->num_channels)
242 0 : return eid;
243 :
244 86 : switch (iface->conf->vht_oper_chwidth) {
245 : case VHT_CHANWIDTH_USE_HT:
246 14 : if (iconf->secondary_channel == 0) {
247 : /* Max Transmit Power count = 0 (20 MHz) */
248 10 : tx_pwr_count = 0;
249 : } else {
250 : /* Max Transmit Power count = 1 (20, 40 MHz) */
251 4 : tx_pwr_count = 1;
252 : }
253 14 : break;
254 : case VHT_CHANWIDTH_80MHZ:
255 : /* Max Transmit Power count = 2 (20, 40, and 80 MHz) */
256 38 : tx_pwr_count = 2;
257 38 : break;
258 : case VHT_CHANWIDTH_80P80MHZ:
259 : case VHT_CHANWIDTH_160MHZ:
260 : /* Max Transmit Power count = 3 (20, 40, 80, 160/80+80 MHz) */
261 34 : tx_pwr_count = 3;
262 34 : break;
263 : default:
264 0 : return eid;
265 : }
266 :
267 : /*
268 : * Below local_pwr_constraint logic is referred from
269 : * hostapd_eid_pwr_constraint.
270 : *
271 : * Check if DFS is required by regulatory.
272 : */
273 86 : dfs = hostapd_is_dfs_required(hapd->iface);
274 86 : if (dfs < 0)
275 0 : dfs = 0;
276 :
277 : /*
278 : * In order to meet regulations when TPC is not implemented using
279 : * a transmit power that is below the legal maximum (including any
280 : * mitigation factor) should help. In this case, indicate 3 dB below
281 : * maximum allowed transmit power.
282 : */
283 86 : if (hapd->iconf->local_pwr_constraint == -1)
284 84 : local_pwr_constraint = (dfs == 0) ? 0 : 3;
285 : else
286 2 : local_pwr_constraint = hapd->iconf->local_pwr_constraint;
287 :
288 : /*
289 : * A STA that is not an AP shall use a transmit power less than or
290 : * equal to the local maximum transmit power level for the channel.
291 : * The local maximum transmit power can be calculated from the formula:
292 : * local max TX pwr = max TX pwr - local pwr constraint
293 : * Where max TX pwr is maximum transmit power level specified for
294 : * channel in Country element and local pwr constraint is specified
295 : * for channel in this Power Constraint element.
296 : */
297 86 : chan = &mode->channels[i];
298 86 : max_tx_power = chan->max_tx_power - local_pwr_constraint;
299 :
300 : /*
301 : * Local Maximum Transmit power is encoded as two's complement
302 : * with a 0.5 dB step.
303 : */
304 86 : max_tx_power *= 2; /* in 0.5 dB steps */
305 86 : if (max_tx_power > 127) {
306 : /* 63.5 has special meaning of 63.5 dBm or higher */
307 0 : max_tx_power = 127;
308 : }
309 86 : if (max_tx_power < -128)
310 0 : max_tx_power = -128;
311 86 : if (max_tx_power < 0)
312 0 : tx_pwr = 0x80 + max_tx_power + 128;
313 : else
314 86 : tx_pwr = max_tx_power;
315 :
316 86 : *eid++ = WLAN_EID_VHT_TRANSMIT_POWER_ENVELOPE;
317 86 : *eid++ = 2 + tx_pwr_count;
318 :
319 : /*
320 : * Max Transmit Power count and
321 : * Max Transmit Power units = 0 (EIRP)
322 : */
323 86 : *eid++ = tx_pwr_count;
324 :
325 354 : for (i = 0; i <= tx_pwr_count; i++)
326 268 : *eid++ = tx_pwr;
327 :
328 86 : return eid;
329 : }
330 :
331 :
332 193 : u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
333 : const u8 *vht_capab)
334 : {
335 : /* Disable VHT caps for STAs associated to no-VHT BSSes. */
336 233 : if (!vht_capab ||
337 80 : hapd->conf->disable_11ac ||
338 40 : !check_valid_vht_mcs(hapd->iface->current_mode, vht_capab)) {
339 153 : sta->flags &= ~WLAN_STA_VHT;
340 153 : os_free(sta->vht_capabilities);
341 153 : sta->vht_capabilities = NULL;
342 153 : return WLAN_STATUS_SUCCESS;
343 : }
344 :
345 40 : if (sta->vht_capabilities == NULL) {
346 40 : sta->vht_capabilities =
347 40 : os_zalloc(sizeof(struct ieee80211_vht_capabilities));
348 40 : if (sta->vht_capabilities == NULL)
349 0 : return WLAN_STATUS_UNSPECIFIED_FAILURE;
350 : }
351 :
352 40 : sta->flags |= WLAN_STA_VHT;
353 40 : os_memcpy(sta->vht_capabilities, vht_capab,
354 : sizeof(struct ieee80211_vht_capabilities));
355 :
356 40 : return WLAN_STATUS_SUCCESS;
357 : }
358 :
359 :
360 2 : u16 copy_sta_vendor_vht(struct hostapd_data *hapd, struct sta_info *sta,
361 : const u8 *ie, size_t len)
362 : {
363 : const u8 *vht_capab;
364 : unsigned int vht_capab_len;
365 :
366 3 : if (!ie || len < 5 + 2 + sizeof(struct ieee80211_vht_capabilities) ||
367 1 : hapd->conf->disable_11ac)
368 : goto no_capab;
369 :
370 : /* The VHT Capabilities element embedded in vendor VHT */
371 1 : vht_capab = ie + 5;
372 1 : if (vht_capab[0] != WLAN_EID_VHT_CAP)
373 0 : goto no_capab;
374 1 : vht_capab_len = vht_capab[1];
375 2 : if (vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
376 1 : (int) vht_capab_len > ie + len - vht_capab - 2)
377 : goto no_capab;
378 1 : vht_capab += 2;
379 :
380 1 : if (sta->vht_capabilities == NULL) {
381 1 : sta->vht_capabilities =
382 1 : os_zalloc(sizeof(struct ieee80211_vht_capabilities));
383 1 : if (sta->vht_capabilities == NULL)
384 0 : return WLAN_STATUS_UNSPECIFIED_FAILURE;
385 : }
386 :
387 1 : sta->flags |= WLAN_STA_VHT | WLAN_STA_VENDOR_VHT;
388 1 : os_memcpy(sta->vht_capabilities, vht_capab,
389 : sizeof(struct ieee80211_vht_capabilities));
390 1 : return WLAN_STATUS_SUCCESS;
391 :
392 : no_capab:
393 1 : sta->flags &= ~WLAN_STA_VENDOR_VHT;
394 1 : return WLAN_STATUS_SUCCESS;
395 : }
396 :
397 :
398 4 : u8 * hostapd_eid_vendor_vht(struct hostapd_data *hapd, u8 *eid)
399 : {
400 4 : u8 *pos = eid;
401 :
402 4 : if (!hapd->iface->current_mode)
403 0 : return eid;
404 :
405 4 : *pos++ = WLAN_EID_VENDOR_SPECIFIC;
406 4 : *pos++ = (5 + /* The Vendor OUI, type and subtype */
407 : 2 + sizeof(struct ieee80211_vht_capabilities) +
408 : 2 + sizeof(struct ieee80211_vht_operation));
409 :
410 4 : WPA_PUT_BE32(pos, (OUI_BROADCOM << 8) | VENDOR_VHT_TYPE);
411 4 : pos += 4;
412 4 : *pos++ = VENDOR_VHT_SUBTYPE;
413 4 : pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
414 4 : pos = hostapd_eid_vht_operation(hapd, pos);
415 :
416 4 : return pos;
417 : }
418 :
419 :
420 193 : u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
421 : const u8 *vht_oper_notif)
422 : {
423 193 : if (!vht_oper_notif) {
424 193 : sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
425 193 : return WLAN_STATUS_SUCCESS;
426 : }
427 :
428 0 : sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
429 0 : sta->vht_opmode = *vht_oper_notif;
430 0 : return WLAN_STATUS_SUCCESS;
431 : }
432 :
433 :
434 35 : void hostapd_get_vht_capab(struct hostapd_data *hapd,
435 : struct ieee80211_vht_capabilities *vht_cap,
436 : struct ieee80211_vht_capabilities *neg_vht_cap)
437 : {
438 : u32 cap, own_cap, sym_caps;
439 :
440 35 : if (vht_cap == NULL)
441 35 : return;
442 35 : os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
443 :
444 35 : cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
445 35 : own_cap = hapd->iconf->vht_capab;
446 :
447 : /* mask out symmetric VHT capabilities we don't support */
448 35 : sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
449 35 : cap &= ~sym_caps | (own_cap & sym_caps);
450 :
451 : /* mask out beamformer/beamformee caps if not supported */
452 35 : if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
453 35 : cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
454 : VHT_CAP_BEAMFORMEE_STS_MAX);
455 :
456 35 : if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
457 35 : cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
458 : VHT_CAP_SOUNDING_DIMENSION_MAX);
459 :
460 35 : if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
461 35 : cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
462 :
463 35 : if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
464 35 : cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
465 :
466 : /* mask channel widths we don't support */
467 35 : switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
468 : case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
469 0 : break;
470 : case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
471 0 : if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
472 0 : cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
473 0 : cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
474 : }
475 0 : break;
476 : default:
477 35 : cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
478 35 : break;
479 : }
480 :
481 35 : if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
482 35 : cap &= ~VHT_CAP_SHORT_GI_160;
483 :
484 : /*
485 : * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
486 : * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
487 : */
488 35 : if (!(own_cap & VHT_CAP_RXSTBC_MASK))
489 34 : cap &= ~VHT_CAP_TXSTBC;
490 35 : if (!(own_cap & VHT_CAP_TXSTBC))
491 34 : cap &= ~VHT_CAP_RXSTBC_MASK;
492 :
493 35 : neg_vht_cap->vht_capabilities_info = host_to_le32(cap);
494 : }
|