2 * Copyright (c) 2017 Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 * IEEE 802.11ac-2013 protocol support.
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/systm.h>
42 #include <sys/endian.h>
44 #include <sys/socket.h>
47 #include <net/if_var.h>
48 #include <net/if_media.h>
49 #include <net/ethernet.h>
51 #include <net80211/ieee80211_var.h>
52 #include <net80211/ieee80211_action.h>
53 #include <net80211/ieee80211_input.h>
54 #include <net80211/ieee80211_vht.h>
56 #define ADDSHORT(frm, v) do { \
57 frm[0] = (v) & 0xff; \
61 #define ADDWORD(frm, v) do { \
62 frm[0] = (v) & 0xff; \
63 frm[1] = ((v) >> 8) & 0xff; \
64 frm[2] = ((v) >> 16) & 0xff; \
65 frm[3] = ((v) >> 24) & 0xff; \
72 * + handle WLAN_ACTION_VHT_OPMODE_NOTIF and other VHT action frames
73 * + ensure vhtinfo/vhtcap parameters correctly use the negotiated
74 * capabilities and ratesets
75 * + group ID management operation
79 * XXX TODO: handle WLAN_ACTION_VHT_OPMODE_NOTIF
81 * Look at mac80211/vht.c:ieee80211_vht_handle_opmode() for further details.
85 vht_recv_action_placeholder(struct ieee80211_node *ni,
86 const struct ieee80211_frame *wh,
87 const uint8_t *frm, const uint8_t *efrm)
90 #ifdef IEEE80211_DEBUG
91 ieee80211_note(ni->ni_vap, "%s: called; fc=0x%.2x/0x%.2x",
92 __func__, wh->i_fc[0], wh->i_fc[1]);
98 vht_send_action_placeholder(struct ieee80211_node *ni,
99 int category, int action, void *arg0)
102 #ifdef IEEE80211_DEBUG
103 ieee80211_note(ni->ni_vap, "%s: called; category=%d, action=%d",
104 __func__, category, action);
110 ieee80211_vht_init(void)
113 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
114 WLAN_ACTION_VHT_COMPRESSED_BF, vht_recv_action_placeholder);
115 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
116 WLAN_ACTION_VHT_GROUPID_MGMT, vht_recv_action_placeholder);
117 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
118 WLAN_ACTION_VHT_OPMODE_NOTIF, vht_recv_action_placeholder);
120 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
121 WLAN_ACTION_VHT_COMPRESSED_BF, vht_send_action_placeholder);
122 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
123 WLAN_ACTION_VHT_GROUPID_MGMT, vht_send_action_placeholder);
124 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
125 WLAN_ACTION_VHT_OPMODE_NOTIF, vht_send_action_placeholder);
128 SYSINIT(wlan_vht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_vht_init, NULL);
131 ieee80211_vht_attach(struct ieee80211com *ic)
136 ieee80211_vht_detach(struct ieee80211com *ic)
141 ieee80211_vht_vattach(struct ieee80211vap *vap)
143 struct ieee80211com *ic = vap->iv_ic;
145 if (! IEEE80211_CONF_VHT(ic))
148 vap->iv_vhtcaps = ic->ic_vhtcaps;
149 vap->iv_vhtextcaps = ic->ic_vhtextcaps;
151 /* XXX assume VHT80 support; should really check vhtcaps */
154 | IEEE80211_FVHT_USEVHT40
155 | IEEE80211_FVHT_USEVHT80;
156 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(vap->iv_vhtcaps))
157 vap->iv_flags_vht |= IEEE80211_FVHT_USEVHT160;
158 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(vap->iv_vhtcaps))
159 vap->iv_flags_vht |= IEEE80211_FVHT_USEVHT80P80;
161 memcpy(&vap->iv_vht_mcsinfo, &ic->ic_vht_mcsinfo,
162 sizeof(struct ieee80211_vht_mcs_info));
166 ieee80211_vht_vdetach(struct ieee80211vap *vap)
172 vht_announce(struct ieee80211com *ic, enum ieee80211_phymode mode)
178 vht_mcs_to_num(int m)
182 case IEEE80211_VHT_MCS_SUPPORT_0_7:
184 case IEEE80211_VHT_MCS_SUPPORT_0_8:
186 case IEEE80211_VHT_MCS_SUPPORT_0_9:
194 ieee80211_vht_announce(struct ieee80211com *ic)
198 if (! IEEE80211_CONF_VHT(ic))
202 ic_printf(ic, "[VHT] Channel Widths: 20MHz, 40MHz, 80MHz%s%s\n",
203 (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(ic->ic_vhtcaps)) ?
205 (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(ic->ic_vhtcaps)) ?
208 ic_printf(ic, "[VHT] Features: %b\n", ic->ic_vhtcaps,
209 IEEE80211_VHTCAP_BITS);
211 /* For now, just 5GHz VHT. Worry about 2GHz VHT later */
212 for (i = 0; i < 8; i++) {
213 /* Each stream is 2 bits */
214 tx = (ic->ic_vht_mcsinfo.tx_mcs_map >> (2*i)) & 0x3;
215 rx = (ic->ic_vht_mcsinfo.rx_mcs_map >> (2*i)) & 0x3;
216 if (tx == 3 && rx == 3)
218 ic_printf(ic, "[VHT] NSS %d: TX MCS 0..%d, RX MCS 0..%d\n",
219 i + 1, vht_mcs_to_num(tx), vht_mcs_to_num(rx));
224 ieee80211_vht_node_init(struct ieee80211_node *ni)
227 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
228 "%s: called", __func__);
229 ni->ni_flags |= IEEE80211_NODE_VHT;
233 ieee80211_vht_node_cleanup(struct ieee80211_node *ni)
236 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
237 "%s: called", __func__);
238 ni->ni_flags &= ~IEEE80211_NODE_VHT;
240 bzero(&ni->ni_vht_mcsinfo, sizeof(struct ieee80211_vht_mcs_info));
244 * Parse an 802.11ac VHT operation IE.
247 ieee80211_parse_vhtopmode(struct ieee80211_node *ni, const uint8_t *ie)
250 ni->ni_vht_chanwidth = ie[2];
251 ni->ni_vht_chan1 = ie[3];
252 ni->ni_vht_chan2 = ie[4];
253 ni->ni_vht_basicmcs = le16dec(ie + 5);
256 printf("%s: chan1=%d, chan2=%d, chanwidth=%d, basicmcs=0x%04x\n",
257 __func__, ni->ni_vht_chan1, ni->ni_vht_chan2, ni->ni_vht_chanwidth,
258 ni->ni_vht_basicmcs);
263 * Parse an 802.11ac VHT capability IE.
266 ieee80211_parse_vhtcap(struct ieee80211_node *ni, const uint8_t *ie)
270 ni->ni_vhtcap = le32dec(ie + 2);
273 ni->ni_vht_mcsinfo.rx_mcs_map = le16dec(ie + 6);
274 ni->ni_vht_mcsinfo.rx_highest = le16dec(ie + 8);
275 ni->ni_vht_mcsinfo.tx_mcs_map = le16dec(ie + 10);
276 ni->ni_vht_mcsinfo.tx_highest = le16dec(ie + 12);
280 ieee80211_vht_updateparams(struct ieee80211_node *ni,
281 const uint8_t *vhtcap_ie,
282 const uint8_t *vhtop_ie)
285 //printf("%s: called\n", __func__);
287 ieee80211_parse_vhtcap(ni, vhtcap_ie);
288 ieee80211_parse_vhtopmode(ni, vhtop_ie);
293 ieee80211_setup_vht_rates(struct ieee80211_node *ni,
294 const uint8_t *vhtcap_ie,
295 const uint8_t *vhtop_ie)
298 //printf("%s: called\n", __func__);
303 ieee80211_vht_timeout(struct ieee80211vap *vap)
308 ieee80211_vht_node_join(struct ieee80211_node *ni)
311 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
312 "%s: called", __func__);
316 ieee80211_vht_node_leave(struct ieee80211_node *ni)
319 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
320 "%s: called", __func__);
324 * Calculate the VHTCAP IE for a given node.
326 * This includes calculating the capability intersection based on the
327 * current operating mode and intersection of the TX/RX MCS maps.
329 * The standard only makes it clear about MCS rate negotiation
330 * and MCS basic rates (which must be a subset of the general
331 * negotiated rates). It doesn't make it clear that the AP should
332 * figure out the minimum functional overlap with the STA and
335 * Note: this is in host order, not in 802.11 endian order.
337 * TODO: ensure I re-read 9.7.11 Rate Selection for VHT STAs.
339 * TODO: investigate what we should negotiate for MU-MIMO beamforming
342 * opmode is '1' for "vhtcap as if I'm a STA", 0 otherwise.
345 ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
346 struct ieee80211_ie_vhtcap *vhtcap, int opmode)
348 struct ieee80211vap *vap = ni->ni_vap;
349 // struct ieee80211com *ic = vap->iv_ic;
350 uint32_t val, val1, val2;
354 vhtcap->ie = IEEE80211_ELEMID_VHT_CAP;
355 vhtcap->len = sizeof(struct ieee80211_ie_vhtcap) - 2;
358 * Capabilities - it depends on whether we are a station
364 * Station - use our desired configuration based on
365 * local config, local device bits and the already-learnt
366 * vhtcap/vhtinfo IE in the node.
369 /* Limit MPDU size to the smaller of the two */
370 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
371 IEEE80211_VHTCAP_MAX_MPDU_MASK);
373 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
374 IEEE80211_VHTCAP_MAX_MPDU_MASK);
376 val = MIN(val1, val2);
377 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_MAX_MPDU_MASK);
379 /* Limit supp channel config */
380 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
381 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
383 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
384 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
387 ((vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80P80) == 0))
390 ((vap->iv_flags_vht & IEEE80211_FVHT_USEVHT160) == 0))
392 val = MIN(val1, val2);
393 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
394 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
397 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
398 IEEE80211_VHTCAP_RXLDPC);
400 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
401 IEEE80211_VHTCAP_RXLDPC);
403 val = MIN(val1, val2);
404 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_RXLDPC);
407 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
408 IEEE80211_VHTCAP_SHORT_GI_80);
410 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
411 IEEE80211_VHTCAP_SHORT_GI_80);
413 val = MIN(val1, val2);
414 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_SHORT_GI_80);
417 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
418 IEEE80211_VHTCAP_SHORT_GI_160);
420 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
421 IEEE80211_VHTCAP_SHORT_GI_160);
423 val = MIN(val1, val2);
424 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_SHORT_GI_160);
427 * STBC is slightly more complicated.
429 * In non-STA mode, we just announce our capabilities and that
432 * In STA mode, we should calculate our capabilities based on
433 * local capabilities /and/ what the remote says. So:
435 * + Only TX STBC if we support it and the remote supports RX STBC;
436 * + Only announce RX STBC if we support it and the remote supports
438 * + RX STBC should be the minimum of local and remote RX STBC;
442 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
443 IEEE80211_VHTCAP_TXSTBC);
445 /* STA mode - enable it only if node RXSTBC is non-zero */
446 val2 = !! _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
447 IEEE80211_VHTCAP_RXSTBC_MASK);
449 val = MIN(val1, val2);
450 /* XXX For now, use the 11n config flag */
451 if ((vap->iv_flags_ht & IEEE80211_FHT_STBC_TX) == 0)
453 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_TXSTBC);
456 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
457 IEEE80211_VHTCAP_RXSTBC_MASK);
459 /* STA mode - enable it only if node TXSTBC is non-zero */
460 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
461 IEEE80211_VHTCAP_TXSTBC);
463 val = MIN(val1, val2);
464 /* XXX For now, use the 11n config flag */
465 if ((vap->iv_flags_ht & IEEE80211_FHT_STBC_RX) == 0)
467 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_RXSTBC_MASK);
470 * Finally - if RXSTBC is 0, then don't enable TXSTBC.
471 * Strictly speaking a device can TXSTBC and not RXSTBC, but
475 new_vhtcap &= ~IEEE80211_VHTCAP_TXSTBC;
478 * Some of these fields require other fields to exist.
479 * So before using it, the parent field needs to be checked
480 * otherwise the overridden value may be wrong.
482 * For example, if SU beamformee is set to 0, then BF STS
486 /* SU Beamformer capable */
487 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
488 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
490 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
491 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
493 val = MIN(val1, val2);
494 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
495 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
497 /* SU Beamformee capable */
498 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
499 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
501 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
502 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
504 val = MIN(val1, val2);
505 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
506 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
508 /* Beamformee STS capability - only if SU beamformee capable */
509 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
510 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
512 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
513 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
515 val = MIN(val1, val2);
516 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE) == 0)
518 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
519 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
521 /* Sounding dimensions - only if SU beamformer capable */
522 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
523 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
525 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
526 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
527 val = MIN(val1, val2);
528 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE) == 0)
530 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
531 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
534 * MU Beamformer capable - only if SU BFF capable, MU BFF capable
537 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
538 IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE);
540 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
541 IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE);
542 val = MIN(val1, val2);
543 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE) == 0)
545 if (opmode != 1) /* Only enable for STA mode */
547 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
548 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
551 * MU Beamformee capable - only if SU BFE capable, MU BFE capable
554 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
555 IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE);
557 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
558 IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE);
559 val = MIN(val1, val2);
560 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE) == 0)
562 if (opmode != 0) /* Only enable for AP mode */
564 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
565 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
568 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
569 IEEE80211_VHTCAP_VHT_TXOP_PS);
571 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
572 IEEE80211_VHTCAP_VHT_TXOP_PS);
573 val = MIN(val1, val2);
574 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_VHT_TXOP_PS);
577 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
578 IEEE80211_VHTCAP_HTC_VHT);
580 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
581 IEEE80211_VHTCAP_HTC_VHT);
582 val = MIN(val1, val2);
583 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_HTC_VHT);
585 /* A-MPDU length max */
586 /* XXX TODO: we need a userland config knob for this */
587 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
588 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
590 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
591 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
592 val = MIN(val1, val2);
593 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
594 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
597 * Link adaptation is only valid if HTC-VHT capable is 1.
598 * Otherwise, always set it to 0.
600 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
601 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
603 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
604 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
605 val = MIN(val1, val2);
606 if ((new_vhtcap & IEEE80211_VHTCAP_HTC_VHT) == 0)
608 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
609 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
612 * The following two options are 0 if the pattern may change, 1 if it
613 * does not change. So, downgrade to the higher value.
616 /* RX antenna pattern */
617 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
618 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
620 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
621 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
622 val = MAX(val1, val2);
623 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
624 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
626 /* TX antenna pattern */
627 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
628 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
630 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
631 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
632 val = MAX(val1, val2);
633 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
634 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
637 * MCS set - again, we announce what we want to use
638 * based on configuration, device capabilities and
639 * already-learnt vhtcap/vhtinfo IE information.
642 /* MCS set - start with whatever the device supports */
643 vhtcap->supp_mcs.rx_mcs_map = vap->iv_vht_mcsinfo.rx_mcs_map;
644 vhtcap->supp_mcs.rx_highest = 0;
645 vhtcap->supp_mcs.tx_mcs_map = vap->iv_vht_mcsinfo.tx_mcs_map;
646 vhtcap->supp_mcs.tx_highest = 0;
648 vhtcap->vht_cap_info = new_vhtcap;
651 * Now, if we're a STA, mask off whatever the AP doesn't support.
652 * Ie, we continue to state we can receive whatever we can do,
653 * but we only announce that we will transmit rates that meet
654 * the AP requirement.
656 * Note: 0 - MCS0..7; 1 - MCS0..8; 2 - MCS0..9; 3 = not supported.
657 * We can't just use MIN() because '3' means "no", so special case it.
660 for (i = 0; i < 8; i++) {
661 val1 = (vhtcap->supp_mcs.tx_mcs_map >> (i*2)) & 0x3;
662 val2 = (ni->ni_vht_mcsinfo.tx_mcs_map >> (i*2)) & 0x3;
663 val = MIN(val1, val2);
664 if (val1 == 3 || val2 == 3)
666 vhtcap->supp_mcs.tx_mcs_map &= ~(0x3 << (i*2));
667 vhtcap->supp_mcs.tx_mcs_map |= (val << (i*2));
673 * Add a VHTCAP field.
675 * If in station mode, we announce what we would like our
676 * desired configuration to be.
678 * Else, we announce our capabilities based on our current
682 ieee80211_add_vhtcap(uint8_t *frm, struct ieee80211_node *ni)
684 struct ieee80211_ie_vhtcap vhtcap;
688 if (ni->ni_vap->iv_opmode == IEEE80211_M_STA)
691 ieee80211_vht_get_vhtcap_ie(ni, &vhtcap, opmode);
693 memset(frm, '\0', sizeof(struct ieee80211_ie_vhtcap));
695 frm[0] = IEEE80211_ELEMID_VHT_CAP;
696 frm[1] = sizeof(struct ieee80211_ie_vhtcap) - 2;
699 /* 32-bit VHT capability */
700 ADDWORD(frm, vhtcap.vht_cap_info);
703 ADDSHORT(frm, vhtcap.supp_mcs.rx_mcs_map);
704 ADDSHORT(frm, vhtcap.supp_mcs.rx_highest);
705 ADDSHORT(frm, vhtcap.supp_mcs.tx_mcs_map);
706 ADDSHORT(frm, vhtcap.supp_mcs.tx_highest);
712 ieee80211_vht_get_chwidth_ie(struct ieee80211_channel *c)
716 * XXX TODO: look at the node configuration as
720 if (IEEE80211_IS_CHAN_VHT80P80(c))
721 return IEEE80211_VHT_CHANWIDTH_80P80MHZ;
722 if (IEEE80211_IS_CHAN_VHT160(c))
723 return IEEE80211_VHT_CHANWIDTH_160MHZ;
724 if (IEEE80211_IS_CHAN_VHT80(c))
725 return IEEE80211_VHT_CHANWIDTH_80MHZ;
726 if (IEEE80211_IS_CHAN_VHT40(c))
727 return IEEE80211_VHT_CHANWIDTH_USE_HT;
728 if (IEEE80211_IS_CHAN_VHT20(c))
729 return IEEE80211_VHT_CHANWIDTH_USE_HT;
731 /* We shouldn't get here */
732 printf("%s: called on a non-VHT channel (freq=%d, flags=0x%08x\n",
733 __func__, (int) c->ic_freq, c->ic_flags);
734 return IEEE80211_VHT_CHANWIDTH_USE_HT;
738 * Note: this just uses the current channel information;
739 * it doesn't use the node info after parsing.
741 * XXX TODO: need to make the basic MCS set configurable.
742 * XXX TODO: read 802.11-2013 to determine what to set
743 * chwidth to when scanning. I have a feeling
744 * it isn't involved in scanning and we shouldn't
745 * be sending it; and I don't yet know what to set
746 * it to for IBSS or hostap where the peer may be
747 * a completely different channel width to us.
750 ieee80211_add_vhtinfo(uint8_t *frm, struct ieee80211_node *ni)
752 memset(frm, '\0', sizeof(struct ieee80211_ie_vht_operation));
754 frm[0] = IEEE80211_ELEMID_VHT_OPMODE;
755 frm[1] = sizeof(struct ieee80211_ie_vht_operation) - 2;
758 /* 8-bit chanwidth */
759 *frm++ = ieee80211_vht_get_chwidth_ie(ni->ni_chan);
762 *frm++ = ni->ni_chan->ic_vht_ch_freq1;
765 *frm++ = ni->ni_chan->ic_vht_ch_freq2;
767 /* 16-bit basic MCS set - just MCS0..7 for NSS=1 for now */
768 ADDSHORT(frm, 0xfffc);
774 ieee80211_vht_update_cap(struct ieee80211_node *ni, const uint8_t *vhtcap_ie,
775 const uint8_t *vhtop_ie)
778 ieee80211_parse_vhtcap(ni, vhtcap_ie);
779 ieee80211_parse_vhtopmode(ni, vhtop_ie);
782 static struct ieee80211_channel *
783 findvhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int vhtflags)
786 return (ieee80211_find_channel(ic, c->ic_freq,
787 (c->ic_flags & ~IEEE80211_CHAN_VHT) | vhtflags));
791 * Handle channel promotion to VHT, similar to ieee80211_ht_adjust_channel().
793 struct ieee80211_channel *
794 ieee80211_vht_adjust_channel(struct ieee80211com *ic,
795 struct ieee80211_channel *chan, int flags)
797 struct ieee80211_channel *c;
799 /* First case - handle channel demotion - if VHT isn't set */
800 if ((flags & IEEE80211_FVHT_VHT) == 0) {
802 printf("%s: demoting channel %d/0x%08x\n", __func__,
803 chan->ic_ieee, chan->ic_flags);
805 c = ieee80211_find_channel(ic, chan->ic_freq,
806 chan->ic_flags & ~IEEE80211_CHAN_VHT);
810 printf("%s: .. to %d/0x%08x\n", __func__,
811 c->ic_ieee, c->ic_flags);
817 * We can upgrade to VHT - attempt to do so
819 * Note: we don't clear the HT flags, these are the hints
820 * for HT40U/HT40D when selecting VHT40 or larger channels.
822 /* Start with VHT80 */
824 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT160))
825 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80);
827 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80P80))
828 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80P80);
830 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80))
831 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80);
833 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40))
834 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40U);
835 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40))
836 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40D);
838 * If we get here, VHT20 is always possible because we checked
839 * for IEEE80211_FVHT_VHT above.
842 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT20);
848 printf("%s: selected %d/0x%08x\n", __func__, c->ic_ieee, c->ic_flags);
854 * Calculate the VHT operation IE for a given node.
856 * This includes calculating the suitable channel width/parameters
859 * TODO: ensure I read 9.7.11 Rate Selection for VHT STAs.
860 * TODO: ensure I read 10.39.7 - BSS Basic VHT-MCS and NSS set operation.
863 ieee80211_vht_get_vhtinfo_ie(struct ieee80211_node *ni,
864 struct ieee80211_ie_vht_operation *vhtop, int opmode)
866 printf("%s: called; TODO!\n", __func__);