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>
31 * IEEE 802.11ac-2013 protocol support.
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/systm.h>
41 #include <sys/endian.h>
43 #include <sys/socket.h>
46 #include <net/if_var.h>
47 #include <net/if_media.h>
48 #include <net/ethernet.h>
50 #include <net80211/ieee80211_var.h>
51 #include <net80211/ieee80211_action.h>
52 #include <net80211/ieee80211_input.h>
53 #include <net80211/ieee80211_vht.h>
55 #define ADDSHORT(frm, v) do { \
56 frm[0] = (v) & 0xff; \
60 #define ADDWORD(frm, v) do { \
61 frm[0] = (v) & 0xff; \
62 frm[1] = ((v) >> 8) & 0xff; \
63 frm[2] = ((v) >> 16) & 0xff; \
64 frm[3] = ((v) >> 24) & 0xff; \
71 * + handle WLAN_ACTION_VHT_OPMODE_NOTIF and other VHT action frames
72 * + ensure vhtinfo/vhtcap parameters correctly use the negotiated
73 * capabilities and ratesets
74 * + group ID management operation
78 * XXX TODO: handle WLAN_ACTION_VHT_OPMODE_NOTIF
80 * Look at mac80211/vht.c:ieee80211_vht_handle_opmode() for further details.
84 vht_recv_action_placeholder(struct ieee80211_node *ni,
85 const struct ieee80211_frame *wh,
86 const uint8_t *frm, const uint8_t *efrm)
89 #ifdef IEEE80211_DEBUG
90 ieee80211_note(ni->ni_vap, "%s: called; fc=0x%.2x/0x%.2x",
91 __func__, wh->i_fc[0], wh->i_fc[1]);
97 vht_send_action_placeholder(struct ieee80211_node *ni,
98 int category, int action, void *arg0)
101 #ifdef IEEE80211_DEBUG
102 ieee80211_note(ni->ni_vap, "%s: called; category=%d, action=%d",
103 __func__, category, action);
109 ieee80211_vht_init(void)
112 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
113 WLAN_ACTION_VHT_COMPRESSED_BF, vht_recv_action_placeholder);
114 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
115 WLAN_ACTION_VHT_GROUPID_MGMT, vht_recv_action_placeholder);
116 ieee80211_recv_action_register(IEEE80211_ACTION_CAT_VHT,
117 WLAN_ACTION_VHT_OPMODE_NOTIF, vht_recv_action_placeholder);
119 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
120 WLAN_ACTION_VHT_COMPRESSED_BF, vht_send_action_placeholder);
121 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
122 WLAN_ACTION_VHT_GROUPID_MGMT, vht_send_action_placeholder);
123 ieee80211_send_action_register(IEEE80211_ACTION_CAT_VHT,
124 WLAN_ACTION_VHT_OPMODE_NOTIF, vht_send_action_placeholder);
127 SYSINIT(wlan_vht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_vht_init, NULL);
130 ieee80211_vht_attach(struct ieee80211com *ic)
135 ieee80211_vht_detach(struct ieee80211com *ic)
140 ieee80211_vht_vattach(struct ieee80211vap *vap)
142 struct ieee80211com *ic = vap->iv_ic;
144 if (! IEEE80211_CONF_VHT(ic))
147 vap->iv_vhtcaps = ic->ic_vhtcaps;
148 vap->iv_vhtextcaps = ic->ic_vhtextcaps;
150 /* XXX assume VHT80 support; should really check vhtcaps */
153 | IEEE80211_FVHT_USEVHT40
154 | IEEE80211_FVHT_USEVHT80;
155 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(vap->iv_vhtcaps))
156 vap->iv_flags_vht |= IEEE80211_FVHT_USEVHT160;
157 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(vap->iv_vhtcaps))
158 vap->iv_flags_vht |= IEEE80211_FVHT_USEVHT80P80;
160 memcpy(&vap->iv_vht_mcsinfo, &ic->ic_vht_mcsinfo,
161 sizeof(struct ieee80211_vht_mcs_info));
165 ieee80211_vht_vdetach(struct ieee80211vap *vap)
171 vht_announce(struct ieee80211com *ic, enum ieee80211_phymode mode)
177 vht_mcs_to_num(int m)
181 case IEEE80211_VHT_MCS_SUPPORT_0_7:
183 case IEEE80211_VHT_MCS_SUPPORT_0_8:
185 case IEEE80211_VHT_MCS_SUPPORT_0_9:
193 ieee80211_vht_announce(struct ieee80211com *ic)
197 if (! IEEE80211_CONF_VHT(ic))
201 ic_printf(ic, "[VHT] Channel Widths: 20MHz, 40MHz, 80MHz%s%s\n",
202 (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(ic->ic_vhtcaps)) ?
204 (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(ic->ic_vhtcaps)) ?
207 ic_printf(ic, "[VHT] Features: %b\n", ic->ic_vhtcaps,
208 IEEE80211_VHTCAP_BITS);
210 /* For now, just 5GHz VHT. Worry about 2GHz VHT later */
211 for (i = 0; i < 8; i++) {
212 /* Each stream is 2 bits */
213 tx = (ic->ic_vht_mcsinfo.tx_mcs_map >> (2*i)) & 0x3;
214 rx = (ic->ic_vht_mcsinfo.rx_mcs_map >> (2*i)) & 0x3;
215 if (tx == 3 && rx == 3)
217 ic_printf(ic, "[VHT] NSS %d: TX MCS 0..%d, RX MCS 0..%d\n",
218 i + 1, vht_mcs_to_num(tx), vht_mcs_to_num(rx));
223 ieee80211_vht_node_init(struct ieee80211_node *ni)
226 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
227 "%s: called", __func__);
228 ni->ni_flags |= IEEE80211_NODE_VHT;
232 ieee80211_vht_node_cleanup(struct ieee80211_node *ni)
235 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
236 "%s: called", __func__);
237 ni->ni_flags &= ~IEEE80211_NODE_VHT;
239 bzero(&ni->ni_vht_mcsinfo, sizeof(struct ieee80211_vht_mcs_info));
243 * Parse an 802.11ac VHT operation IE.
246 ieee80211_parse_vhtopmode(struct ieee80211_node *ni, const uint8_t *ie)
249 ni->ni_vht_chanwidth = ie[2];
250 ni->ni_vht_chan1 = ie[3];
251 ni->ni_vht_chan2 = ie[4];
252 ni->ni_vht_basicmcs = le16dec(ie + 5);
255 printf("%s: chan1=%d, chan2=%d, chanwidth=%d, basicmcs=0x%04x\n",
256 __func__, ni->ni_vht_chan1, ni->ni_vht_chan2, ni->ni_vht_chanwidth,
257 ni->ni_vht_basicmcs);
262 * Parse an 802.11ac VHT capability IE.
265 ieee80211_parse_vhtcap(struct ieee80211_node *ni, const uint8_t *ie)
269 ni->ni_vhtcap = le32dec(ie + 2);
272 ni->ni_vht_mcsinfo.rx_mcs_map = le16dec(ie + 6);
273 ni->ni_vht_mcsinfo.rx_highest = le16dec(ie + 8);
274 ni->ni_vht_mcsinfo.tx_mcs_map = le16dec(ie + 10);
275 ni->ni_vht_mcsinfo.tx_highest = le16dec(ie + 12);
279 ieee80211_vht_updateparams(struct ieee80211_node *ni,
280 const uint8_t *vhtcap_ie,
281 const uint8_t *vhtop_ie)
284 //printf("%s: called\n", __func__);
286 ieee80211_parse_vhtcap(ni, vhtcap_ie);
287 ieee80211_parse_vhtopmode(ni, vhtop_ie);
292 ieee80211_setup_vht_rates(struct ieee80211_node *ni,
293 const uint8_t *vhtcap_ie,
294 const uint8_t *vhtop_ie)
297 //printf("%s: called\n", __func__);
302 ieee80211_vht_timeout(struct ieee80211vap *vap)
307 ieee80211_vht_node_join(struct ieee80211_node *ni)
310 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
311 "%s: called", __func__);
315 ieee80211_vht_node_leave(struct ieee80211_node *ni)
318 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_11N, ni,
319 "%s: called", __func__);
323 * Calculate the VHTCAP IE for a given node.
325 * This includes calculating the capability intersection based on the
326 * current operating mode and intersection of the TX/RX MCS maps.
328 * The standard only makes it clear about MCS rate negotiation
329 * and MCS basic rates (which must be a subset of the general
330 * negotiated rates). It doesn't make it clear that the AP should
331 * figure out the minimum functional overlap with the STA and
334 * Note: this is in host order, not in 802.11 endian order.
336 * TODO: ensure I re-read 9.7.11 Rate Selection for VHT STAs.
338 * TODO: investigate what we should negotiate for MU-MIMO beamforming
341 * opmode is '1' for "vhtcap as if I'm a STA", 0 otherwise.
344 ieee80211_vht_get_vhtcap_ie(struct ieee80211_node *ni,
345 struct ieee80211_ie_vhtcap *vhtcap, int opmode)
347 struct ieee80211vap *vap = ni->ni_vap;
348 // struct ieee80211com *ic = vap->iv_ic;
349 uint32_t val, val1, val2;
353 vhtcap->ie = IEEE80211_ELEMID_VHT_CAP;
354 vhtcap->len = sizeof(struct ieee80211_ie_vhtcap) - 2;
357 * Capabilities - it depends on whether we are a station
363 * Station - use our desired configuration based on
364 * local config, local device bits and the already-learnt
365 * vhtcap/vhtinfo IE in the node.
368 /* Limit MPDU size to the smaller of the two */
369 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
370 IEEE80211_VHTCAP_MAX_MPDU_MASK);
372 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
373 IEEE80211_VHTCAP_MAX_MPDU_MASK);
375 val = MIN(val1, val2);
376 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_MAX_MPDU_MASK);
378 /* Limit supp channel config */
379 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
380 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
382 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
383 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
386 ((vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80P80) == 0))
389 ((vap->iv_flags_vht & IEEE80211_FVHT_USEVHT160) == 0))
391 val = MIN(val1, val2);
392 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
393 IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK);
396 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
397 IEEE80211_VHTCAP_RXLDPC);
399 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
400 IEEE80211_VHTCAP_RXLDPC);
402 val = MIN(val1, val2);
403 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_RXLDPC);
406 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
407 IEEE80211_VHTCAP_SHORT_GI_80);
409 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
410 IEEE80211_VHTCAP_SHORT_GI_80);
412 val = MIN(val1, val2);
413 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_SHORT_GI_80);
416 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
417 IEEE80211_VHTCAP_SHORT_GI_160);
419 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
420 IEEE80211_VHTCAP_SHORT_GI_160);
422 val = MIN(val1, val2);
423 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_SHORT_GI_160);
426 * STBC is slightly more complicated.
428 * In non-STA mode, we just announce our capabilities and that
431 * In STA mode, we should calculate our capabilities based on
432 * local capabilities /and/ what the remote says. So:
434 * + Only TX STBC if we support it and the remote supports RX STBC;
435 * + Only announce RX STBC if we support it and the remote supports
437 * + RX STBC should be the minimum of local and remote RX STBC;
441 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
442 IEEE80211_VHTCAP_TXSTBC);
444 /* STA mode - enable it only if node RXSTBC is non-zero */
445 val2 = !! _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
446 IEEE80211_VHTCAP_RXSTBC_MASK);
448 val = MIN(val1, val2);
449 /* XXX For now, use the 11n config flag */
450 if ((vap->iv_flags_ht & IEEE80211_FHT_STBC_TX) == 0)
452 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_TXSTBC);
455 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
456 IEEE80211_VHTCAP_RXSTBC_MASK);
458 /* STA mode - enable it only if node TXSTBC is non-zero */
459 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
460 IEEE80211_VHTCAP_TXSTBC);
462 val = MIN(val1, val2);
463 /* XXX For now, use the 11n config flag */
464 if ((vap->iv_flags_ht & IEEE80211_FHT_STBC_RX) == 0)
466 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_RXSTBC_MASK);
469 * Finally - if RXSTBC is 0, then don't enable TXSTBC.
470 * Strictly speaking a device can TXSTBC and not RXSTBC, but
474 new_vhtcap &= ~IEEE80211_VHTCAP_TXSTBC;
477 * Some of these fields require other fields to exist.
478 * So before using it, the parent field needs to be checked
479 * otherwise the overridden value may be wrong.
481 * For example, if SU beamformee is set to 0, then BF STS
485 /* SU Beamformer capable */
486 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
487 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
489 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
490 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
492 val = MIN(val1, val2);
493 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
494 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
496 /* SU Beamformee capable */
497 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
498 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
500 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
501 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
503 val = MIN(val1, val2);
504 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
505 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
507 /* Beamformee STS capability - only if SU beamformee capable */
508 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
509 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
511 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
512 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
514 val = MIN(val1, val2);
515 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE) == 0)
517 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
518 IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK);
520 /* Sounding dimensions - only if SU beamformer capable */
521 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
522 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
524 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
525 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
526 val = MIN(val1, val2);
527 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE) == 0)
529 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
530 IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK);
533 * MU Beamformer capable - only if SU BFF capable, MU BFF capable
536 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
537 IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE);
539 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
540 IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE);
541 val = MIN(val1, val2);
542 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE) == 0)
544 if (opmode != 1) /* Only enable for STA mode */
546 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
547 IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE);
550 * MU Beamformee capable - only if SU BFE capable, MU BFE capable
553 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
554 IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE);
556 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
557 IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE);
558 val = MIN(val1, val2);
559 if ((new_vhtcap & IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE) == 0)
561 if (opmode != 0) /* Only enable for AP mode */
563 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
564 IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE);
567 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
568 IEEE80211_VHTCAP_VHT_TXOP_PS);
570 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
571 IEEE80211_VHTCAP_VHT_TXOP_PS);
572 val = MIN(val1, val2);
573 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_VHT_TXOP_PS);
576 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
577 IEEE80211_VHTCAP_HTC_VHT);
579 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
580 IEEE80211_VHTCAP_HTC_VHT);
581 val = MIN(val1, val2);
582 new_vhtcap |= _IEEE80211_SHIFTMASK(val, IEEE80211_VHTCAP_HTC_VHT);
584 /* A-MPDU length max */
585 /* XXX TODO: we need a userland config knob for this */
586 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
587 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
589 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
590 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
591 val = MIN(val1, val2);
592 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
593 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
596 * Link adaptation is only valid if HTC-VHT capable is 1.
597 * Otherwise, always set it to 0.
599 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
600 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
602 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
603 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
604 val = MIN(val1, val2);
605 if ((new_vhtcap & IEEE80211_VHTCAP_HTC_VHT) == 0)
607 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
608 IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK);
611 * The following two options are 0 if the pattern may change, 1 if it
612 * does not change. So, downgrade to the higher value.
615 /* RX antenna pattern */
616 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
617 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
619 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
620 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
621 val = MAX(val1, val2);
622 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
623 IEEE80211_VHTCAP_RX_ANTENNA_PATTERN);
625 /* TX antenna pattern */
626 val2 = val1 = _IEEE80211_MASKSHIFT(vap->iv_vhtcaps,
627 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
629 val2 = _IEEE80211_MASKSHIFT(ni->ni_vhtcap,
630 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
631 val = MAX(val1, val2);
632 new_vhtcap |= _IEEE80211_SHIFTMASK(val,
633 IEEE80211_VHTCAP_TX_ANTENNA_PATTERN);
636 * MCS set - again, we announce what we want to use
637 * based on configuration, device capabilities and
638 * already-learnt vhtcap/vhtinfo IE information.
641 /* MCS set - start with whatever the device supports */
642 vhtcap->supp_mcs.rx_mcs_map = vap->iv_vht_mcsinfo.rx_mcs_map;
643 vhtcap->supp_mcs.rx_highest = 0;
644 vhtcap->supp_mcs.tx_mcs_map = vap->iv_vht_mcsinfo.tx_mcs_map;
645 vhtcap->supp_mcs.tx_highest = 0;
647 vhtcap->vht_cap_info = new_vhtcap;
650 * Now, if we're a STA, mask off whatever the AP doesn't support.
651 * Ie, we continue to state we can receive whatever we can do,
652 * but we only announce that we will transmit rates that meet
653 * the AP requirement.
655 * Note: 0 - MCS0..7; 1 - MCS0..8; 2 - MCS0..9; 3 = not supported.
656 * We can't just use MIN() because '3' means "no", so special case it.
659 for (i = 0; i < 8; i++) {
660 val1 = (vhtcap->supp_mcs.tx_mcs_map >> (i*2)) & 0x3;
661 val2 = (ni->ni_vht_mcsinfo.tx_mcs_map >> (i*2)) & 0x3;
662 val = MIN(val1, val2);
663 if (val1 == 3 || val2 == 3)
665 vhtcap->supp_mcs.tx_mcs_map &= ~(0x3 << (i*2));
666 vhtcap->supp_mcs.tx_mcs_map |= (val << (i*2));
672 * Add a VHTCAP field.
674 * If in station mode, we announce what we would like our
675 * desired configuration to be.
677 * Else, we announce our capabilities based on our current
681 ieee80211_add_vhtcap(uint8_t *frm, struct ieee80211_node *ni)
683 struct ieee80211_ie_vhtcap vhtcap;
687 if (ni->ni_vap->iv_opmode == IEEE80211_M_STA)
690 ieee80211_vht_get_vhtcap_ie(ni, &vhtcap, opmode);
692 memset(frm, '\0', sizeof(struct ieee80211_ie_vhtcap));
694 frm[0] = IEEE80211_ELEMID_VHT_CAP;
695 frm[1] = sizeof(struct ieee80211_ie_vhtcap) - 2;
698 /* 32-bit VHT capability */
699 ADDWORD(frm, vhtcap.vht_cap_info);
702 ADDSHORT(frm, vhtcap.supp_mcs.rx_mcs_map);
703 ADDSHORT(frm, vhtcap.supp_mcs.rx_highest);
704 ADDSHORT(frm, vhtcap.supp_mcs.tx_mcs_map);
705 ADDSHORT(frm, vhtcap.supp_mcs.tx_highest);
711 ieee80211_vht_get_chwidth_ie(struct ieee80211_channel *c)
715 * XXX TODO: look at the node configuration as
719 if (IEEE80211_IS_CHAN_VHT80P80(c))
720 return IEEE80211_VHT_CHANWIDTH_80P80MHZ;
721 if (IEEE80211_IS_CHAN_VHT160(c))
722 return IEEE80211_VHT_CHANWIDTH_160MHZ;
723 if (IEEE80211_IS_CHAN_VHT80(c))
724 return IEEE80211_VHT_CHANWIDTH_80MHZ;
725 if (IEEE80211_IS_CHAN_VHT40(c))
726 return IEEE80211_VHT_CHANWIDTH_USE_HT;
727 if (IEEE80211_IS_CHAN_VHT20(c))
728 return IEEE80211_VHT_CHANWIDTH_USE_HT;
730 /* We shouldn't get here */
731 printf("%s: called on a non-VHT channel (freq=%d, flags=0x%08x\n",
732 __func__, (int) c->ic_freq, c->ic_flags);
733 return IEEE80211_VHT_CHANWIDTH_USE_HT;
737 * Note: this just uses the current channel information;
738 * it doesn't use the node info after parsing.
740 * XXX TODO: need to make the basic MCS set configurable.
741 * XXX TODO: read 802.11-2013 to determine what to set
742 * chwidth to when scanning. I have a feeling
743 * it isn't involved in scanning and we shouldn't
744 * be sending it; and I don't yet know what to set
745 * it to for IBSS or hostap where the peer may be
746 * a completely different channel width to us.
749 ieee80211_add_vhtinfo(uint8_t *frm, struct ieee80211_node *ni)
751 memset(frm, '\0', sizeof(struct ieee80211_ie_vht_operation));
753 frm[0] = IEEE80211_ELEMID_VHT_OPMODE;
754 frm[1] = sizeof(struct ieee80211_ie_vht_operation) - 2;
757 /* 8-bit chanwidth */
758 *frm++ = ieee80211_vht_get_chwidth_ie(ni->ni_chan);
761 *frm++ = ni->ni_chan->ic_vht_ch_freq1;
764 *frm++ = ni->ni_chan->ic_vht_ch_freq2;
766 /* 16-bit basic MCS set - just MCS0..7 for NSS=1 for now */
767 ADDSHORT(frm, 0xfffc);
773 ieee80211_vht_update_cap(struct ieee80211_node *ni, const uint8_t *vhtcap_ie,
774 const uint8_t *vhtop_ie)
777 ieee80211_parse_vhtcap(ni, vhtcap_ie);
778 ieee80211_parse_vhtopmode(ni, vhtop_ie);
781 static struct ieee80211_channel *
782 findvhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int vhtflags)
785 return (ieee80211_find_channel(ic, c->ic_freq,
786 (c->ic_flags & ~IEEE80211_CHAN_VHT) | vhtflags));
790 * Handle channel promotion to VHT, similar to ieee80211_ht_adjust_channel().
792 struct ieee80211_channel *
793 ieee80211_vht_adjust_channel(struct ieee80211com *ic,
794 struct ieee80211_channel *chan, int flags)
796 struct ieee80211_channel *c;
798 /* First case - handle channel demotion - if VHT isn't set */
799 if ((flags & IEEE80211_FVHT_MASK) == 0) {
801 printf("%s: demoting channel %d/0x%08x\n", __func__,
802 chan->ic_ieee, chan->ic_flags);
804 c = ieee80211_find_channel(ic, chan->ic_freq,
805 chan->ic_flags & ~IEEE80211_CHAN_VHT);
809 printf("%s: .. to %d/0x%08x\n", __func__,
810 c->ic_ieee, c->ic_flags);
816 * We can upgrade to VHT - attempt to do so
818 * Note: we don't clear the HT flags, these are the hints
819 * for HT40U/HT40D when selecting VHT40 or larger channels.
822 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT160))
823 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT160);
825 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80P80))
826 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80P80);
828 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80))
829 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80);
831 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40))
832 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40U);
833 if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40))
834 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40D);
836 * If we get here, VHT20 is always possible because we checked
837 * for IEEE80211_FVHT_VHT above.
840 c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT20);
846 printf("%s: selected %d/0x%08x\n", __func__, c->ic_ieee, c->ic_flags);
852 * Calculate the VHT operation IE for a given node.
854 * This includes calculating the suitable channel width/parameters
857 * TODO: ensure I read 9.7.11 Rate Selection for VHT STAs.
858 * TODO: ensure I read 10.39.7 - BSS Basic VHT-MCS and NSS set operation.
861 ieee80211_vht_get_vhtinfo_ie(struct ieee80211_node *ni,
862 struct ieee80211_ie_vht_operation *vhtop, int opmode)
864 printf("%s: called; TODO!\n", __func__);