Index: sys/net80211/ieee80211.c =================================================================== --- sys/net80211/ieee80211.c (revision 311042) +++ sys/net80211/ieee80211.c (working copy) @@ -54,6 +54,7 @@ #include #endif #include +#include #include @@ -70,6 +71,8 @@ [IEEE80211_MODE_QUARTER] = "quarter", [IEEE80211_MODE_11NA] = "11na", [IEEE80211_MODE_11NG] = "11ng", + [IEEE80211_MODE_VHT_2GHZ] = "11ac2", + [IEEE80211_MODE_VHT_5GHZ] = "11ac", }; /* map ieee80211_opmode to the corresponding capability bit */ const int ieee80211_opcap[IEEE80211_OPMODE_MAX] = { @@ -90,6 +93,7 @@ static void ieee80211_syncflag_locked(struct ieee80211com *ic, int flag); static void ieee80211_syncflag_ht_locked(struct ieee80211com *ic, int flag); static void ieee80211_syncflag_ext_locked(struct ieee80211com *ic, int flag); +static void ieee80211_syncflag_vht_locked(struct ieee80211com *ic, int flag); static int ieee80211_media_setup(struct ieee80211com *ic, struct ifmedia *media, int caps, int addsta, ifm_change_cb_t media_change, ifm_stat_cb_t media_stat); @@ -116,6 +120,8 @@ { 12, { B(2), B(4), B(11), B(22), 12, 18, 24, 36, 48, 72, 96, 108 } }; #undef B +static int set_vht_extchan(struct ieee80211_channel *c); + /* * Fill in 802.11 available channel set, mark * all available channels as active, and pick @@ -147,10 +153,20 @@ */ if (c->ic_ieee == 0) c->ic_ieee = ieee80211_mhz2ieee(c->ic_freq,c->ic_flags); + + /* + * Setup the HT40/VHT40 upper/lower bits. + * The VHT80 math is done elsewhere. + */ if (IEEE80211_IS_CHAN_HT40(c) && c->ic_extieee == 0) c->ic_extieee = ieee80211_mhz2ieee(c->ic_freq + (IEEE80211_IS_CHAN_HT40U(c) ? 20 : -20), c->ic_flags); + + /* Update VHT math */ + /* XXX again, note that this assumes VHT80 channels are legit already */ + set_vht_extchan(c); + /* default max tx power to max regulatory */ if (c->ic_maxpower == 0) c->ic_maxpower = 2*c->ic_maxregpower; @@ -180,6 +196,10 @@ setbit(ic->ic_modecaps, IEEE80211_MODE_11NA); if (IEEE80211_IS_CHAN_HTG(c)) setbit(ic->ic_modecaps, IEEE80211_MODE_11NG); + if (IEEE80211_IS_CHAN_VHTA(c)) + setbit(ic->ic_modecaps, IEEE80211_MODE_VHT_5GHZ); + if (IEEE80211_IS_CHAN_VHTG(c)) + setbit(ic->ic_modecaps, IEEE80211_MODE_VHT_2GHZ); } /* initialize candidate channels to all available */ memcpy(ic->ic_chan_active, ic->ic_chan_avail, @@ -207,6 +227,8 @@ DEFAULTRATES(IEEE80211_MODE_QUARTER, ieee80211_rateset_quarter); DEFAULTRATES(IEEE80211_MODE_11NA, ieee80211_rateset_11a); DEFAULTRATES(IEEE80211_MODE_11NG, ieee80211_rateset_11g); + DEFAULTRATES(IEEE80211_MODE_VHT_5GHZ, ieee80211_rateset_11a); + DEFAULTRATES(IEEE80211_MODE_VHT_2GHZ, ieee80211_rateset_11g); /* * Setup required information to fill the mcsset field, if driver did @@ -334,6 +356,7 @@ ieee80211_superg_attach(ic); #endif ieee80211_ht_attach(ic); + ieee80211_vht_attach(ic); ieee80211_scan_attach(ic); ieee80211_regdomain_attach(ic); ieee80211_dfs_attach(ic); @@ -377,6 +400,7 @@ #ifdef IEEE80211_SUPPORT_SUPERG ieee80211_superg_detach(ic); #endif + ieee80211_vht_detach(ic); ieee80211_ht_detach(ic); /* NB: must be called before ieee80211_node_detach */ ieee80211_proto_detach(ic); @@ -506,8 +530,15 @@ vap->iv_flags_ext = ic->ic_flags_ext; vap->iv_flags_ven = ic->ic_flags_ven; vap->iv_caps = ic->ic_caps &~ IEEE80211_C_OPMODE; + + /* 11n capabilities - XXX methodize */ vap->iv_htcaps = ic->ic_htcaps; vap->iv_htextcaps = ic->ic_htextcaps; + + /* 11ac capabilities - XXX methodize */ + vap->iv_vhtcaps = ic->ic_vhtcaps; + vap->iv_vhtextcaps = ic->ic_vhtextcaps; + vap->iv_opmode = opmode; vap->iv_caps |= ieee80211_opcap[opmode]; IEEE80211_ADDR_COPY(vap->iv_myaddr, ic->ic_macaddr); @@ -592,6 +623,7 @@ ieee80211_superg_vattach(vap); #endif ieee80211_ht_vattach(vap); + ieee80211_vht_vattach(vap); ieee80211_scan_vattach(vap); ieee80211_regdomain_vattach(vap); ieee80211_radiotap_vattach(vap); @@ -652,6 +684,12 @@ ieee80211_syncflag_locked(ic, IEEE80211_F_BURST); ieee80211_syncflag_ht_locked(ic, IEEE80211_FHT_HT); ieee80211_syncflag_ht_locked(ic, IEEE80211_FHT_USEHT40); + + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_VHT); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT40); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT80); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT80P80); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT160); IEEE80211_UNLOCK(ic); return 1; @@ -699,6 +737,13 @@ ieee80211_syncflag_locked(ic, IEEE80211_F_BURST); ieee80211_syncflag_ht_locked(ic, IEEE80211_FHT_HT); ieee80211_syncflag_ht_locked(ic, IEEE80211_FHT_USEHT40); + + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_VHT); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT40); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT80); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT80P80); + ieee80211_syncflag_vht_locked(ic, IEEE80211_FVHT_USEVHT160); + /* NB: this handles the bpfdetach done below */ ieee80211_syncflag_ext_locked(ic, IEEE80211_FEXT_BPF); if (vap->iv_ifflags & IFF_PROMISC) @@ -715,6 +760,7 @@ #ifdef IEEE80211_SUPPORT_SUPERG ieee80211_superg_vdetach(vap); #endif + ieee80211_vht_vdetach(vap); ieee80211_ht_vdetach(vap); /* NB: must be before ieee80211_node_vdetach */ ieee80211_proto_vdetach(vap); @@ -853,6 +899,50 @@ } /* + * Synchronize flags_vht bit state in the com structure + * according to the state of all vap's. This is used, + * for example, to handle state changes via ioctls. + */ +static void +ieee80211_syncflag_vht_locked(struct ieee80211com *ic, int flag) +{ + struct ieee80211vap *vap; + int bit; + + IEEE80211_LOCK_ASSERT(ic); + + bit = 0; + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) + if (vap->iv_flags_vht & flag) { + bit = 1; + break; + } + if (bit) + ic->ic_flags_vht |= flag; + else + ic->ic_flags_vht &= ~flag; +} + +void +ieee80211_syncflag_vht(struct ieee80211vap *vap, int flag) +{ + struct ieee80211com *ic = vap->iv_ic; + + printf("%s: called; flag=%d\n", __func__, flag); + + IEEE80211_LOCK(ic); + if (flag < 0) { + flag = -flag; + vap->iv_flags_vht &= ~flag; + } else + vap->iv_flags_vht |= flag; + ieee80211_syncflag_vht_locked(ic, flag); + IEEE80211_UNLOCK(ic); + + printf("%s: called; iv_flags_vht is now 0x%08x\n", __func__, vap->iv_flags_vht); +} + +/* * Synchronize flags_ext bit state in the com structure * according to the state of all vap's. This is used, * for example, to handle state changes via ioctls. @@ -1019,7 +1109,111 @@ c->ic_extieee = 0; } +/* + * Populate the freq1/freq2 fields as appropriate for VHT channels. + * + * This for now uses a hard-coded list of 80MHz wide channels. + * + * For HT20/HT40, freq1 just is the centre frequency of the 40MHz + * wide channel we've already decided upon. + * + * For VHT80 and VHT160, there are only a small number of fixed + * 80/160MHz wide channels, so we just use those. + * + * This is all likely very very wrong - both the regulatory code + * and this code needs to ensure that all four channels are + * available and valid before the VHT80 (and eight for VHT160) channel + * is created. + */ + +struct vht_chan_range { + uint16_t freq_start; + uint16_t freq_end; +}; + +struct vht_chan_range vht80_chan_ranges[] = { + { 5170, 5250 }, + { 5250, 5330 }, + { 5490, 5570 }, + { 5570, 5650 }, + { 5650, 5730 }, + { 5735, 5815 }, + { 0, 0, } +}; + static int +set_vht_extchan(struct ieee80211_channel *c) +{ + int i; + + if (! IEEE80211_IS_CHAN_VHT(c)) { + return (0); + } + + if (IEEE80211_IS_CHAN_VHT20(c)) { + c->ic_vht_ch_freq1 = c->ic_ieee; + return (1); + } + + if (IEEE80211_IS_CHAN_VHT40(c)) { + if (IEEE80211_IS_CHAN_HT40U(c)) + c->ic_vht_ch_freq1 = c->ic_ieee + 2; + else if (IEEE80211_IS_CHAN_HT40D(c)) + c->ic_vht_ch_freq1 = c->ic_ieee - 2; + else + return (0); + return (1); + } + + if (IEEE80211_IS_CHAN_VHT80(c)) { + for (i = 0; vht80_chan_ranges[i].freq_start != 0; i++) { + if (c->ic_freq >= vht80_chan_ranges[i].freq_start && + c->ic_freq < vht80_chan_ranges[i].freq_end) { + int midpoint; + + midpoint = vht80_chan_ranges[i].freq_start + 40; + c->ic_vht_ch_freq1 = + ieee80211_mhz2ieee(midpoint, c->ic_flags); + printf("%s: %d, freq=%d, midpoint=%d, freq1=%d\n", + __func__, c->ic_ieee, c->ic_freq, midpoint, + c->ic_vht_ch_freq1); + return (1); + } + } + return (0); + } + + printf("%s: unknown VHT channel type (ieee=%d, flags=0x%08x)\n", + __func__, + c->ic_ieee, + c->ic_flags); + + return (0); +} + +/* + * Return whether the current channel could possibly be a part of + * a VHT80 channel. + * + * This doesn't check that the whole range is in the allowed list + * according to regulatory. + */ +static int +is_vht80_valid_freq(uint16_t freq) +{ + int i; + for (i = 0; vht80_chan_ranges[i].freq_start != 0; i++) { + if (freq >= vht80_chan_ranges[i].freq_start && + freq < vht80_chan_ranges[i].freq_end) + return (1); + } + return (0); +} + +/* + * XXX VHT + */ +static int addchan(struct ieee80211_channel chans[], int maxchans, int *nchans, uint8_t ieee, uint16_t freq, int8_t maxregpower, uint32_t flags) { @@ -1028,6 +1222,13 @@ if (*nchans >= maxchans) return (ENOBUFS); + printf("%s: %d: ieee=%d, freq=%d, flags=0x%08x\n", + __func__, + *nchans, + ieee, + freq, + flags); + c = &chans[(*nchans)++]; c->ic_ieee = ieee; c->ic_freq = freq != 0 ? freq : ieee80211_ieee2mhz(ieee, flags); @@ -1034,7 +1235,12 @@ c->ic_maxregpower = maxregpower; c->ic_maxpower = 2 * maxregpower; c->ic_flags = flags; + c->ic_vht_ch_freq1 = 0; + c->ic_vht_ch_freq2 = 0; + /* XXX VHT */ set_extchan(c); + set_vht_extchan(c); + printf("%s: %d, freq=%d, freq1=%d\n", __func__, c->ic_ieee, c->ic_freq, c->ic_vht_ch_freq1); return (0); } @@ -1050,14 +1256,27 @@ if (*nchans >= maxchans) return (ENOBUFS); + + printf("%s: %d: flags=0x%08x\n", + __func__, + *nchans, + flags); + c = &chans[(*nchans)++]; c[0] = c[-1]; c->ic_flags = flags; + c->ic_vht_ch_freq1 = 0; + c->ic_vht_ch_freq2 = 0; set_extchan(c); + set_vht_extchan(c); + printf("%s: %d, freq=%d, freq1=%d\n", __func__, c->ic_ieee, c->ic_freq, c->ic_vht_ch_freq1); return (0); } +/* + * XXX VHT-2GHz + */ static void getflags_2ghz(const uint8_t bands[], uint32_t flags[], int ht40) { @@ -1077,36 +1296,77 @@ flags[nmodes] = 0; } +/* + * XXX VHT-5GHz + */ static void -getflags_5ghz(const uint8_t bands[], uint32_t flags[], int ht40) +getflags_5ghz(const uint8_t bands[], uint32_t flags[], int ht40, int vht80) { int nmodes; + /* + * the addchan_list function seems to expect the flags array to + * be in channel width order, so the VHT bits are interspersed + * as appropriate to maintain said order. + * + * It also assumes HT40U is before HT40D. + */ nmodes = 0; + + /* 20MHz */ if (isset(bands, IEEE80211_MODE_11A)) flags[nmodes++] = IEEE80211_CHAN_A; if (isset(bands, IEEE80211_MODE_11NA)) flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT20; + if (isset(bands, IEEE80211_MODE_VHT_5GHZ)) { + flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 | + IEEE80211_CHAN_VHT20; + + /* 40MHz */ if (ht40) { flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U; + } + if (ht40 && isset(bands, IEEE80211_MODE_VHT_5GHZ)) { + flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U + | IEEE80211_CHAN_VHT40U; + } + if (ht40) { flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D; } + if (ht40 && isset(bands, IEEE80211_MODE_VHT_5GHZ)) { + flags[nmodes++] = IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D + | IEEE80211_CHAN_VHT40D; + } + + /* 80MHz */ + if (vht80 && isset(bands, IEEE80211_MODE_VHT_5GHZ)) { + flags[nmodes++] = IEEE80211_CHAN_A | + IEEE80211_CHAN_HT40U | IEEE80211_CHAN_VHT80; + flags[nmodes++] = IEEE80211_CHAN_A | + IEEE80211_CHAN_HT40D | IEEE80211_CHAN_VHT80; + } + } + + /* XXX VHT80+80 */ + /* XXX VHT160 */ flags[nmodes] = 0; } static void -getflags(const uint8_t bands[], uint32_t flags[], int ht40) +getflags(const uint8_t bands[], uint32_t flags[], int ht40, int vht80) { flags[0] = 0; if (isset(bands, IEEE80211_MODE_11A) || - isset(bands, IEEE80211_MODE_11NA)) { + isset(bands, IEEE80211_MODE_11NA) || + isset(bands, IEEE80211_MODE_VHT_5GHZ)) { if (isset(bands, IEEE80211_MODE_11B) || isset(bands, IEEE80211_MODE_11G) || - isset(bands, IEEE80211_MODE_11NG)) + isset(bands, IEEE80211_MODE_11NG) || + isset(bands, IEEE80211_MODE_VHT_2GHZ)) return; - getflags_5ghz(bands, flags, ht40); + getflags_5ghz(bands, flags, ht40, vht80); } else getflags_2ghz(bands, flags, ht40); } @@ -1122,7 +1382,7 @@ uint32_t flags[IEEE80211_MODE_MAX]; int i, error; - getflags(bands, flags, 0); + getflags(bands, flags, 0, 0); KASSERT(flags[0] != 0, ("%s: no correct mode provided\n", __func__)); error = addchan(chans, maxchans, nchans, ieee, freq, maxregpower, @@ -1156,6 +1416,7 @@ /* * Add 40 MHz channel pair into specified channel list. */ +/* XXX VHT */ int ieee80211_add_channel_ht40(struct ieee80211_channel chans[], int maxchans, int *nchans, uint8_t ieee, int8_t maxregpower, uint32_t flags) @@ -1218,6 +1479,13 @@ ieee80211_get_channel_center_freq1(const struct ieee80211_channel *c) { + /* + * VHT - use the pre-calculated centre frequency + * of the given channel. + */ + if (IEEE80211_IS_CHAN_VHT(c)) + return (ieee80211_ieee2mhz(c->ic_vht_ch_freq1, c->ic_flags)); + if (IEEE80211_IS_CHAN_HT40U(c)) { return (c->ic_freq + 10); } @@ -1229,12 +1497,15 @@ } /* - * For now, no 80+80 support; this is zero. + * For now, no 80+80 support; it will likely always return 0. */ uint32_t ieee80211_get_channel_center_freq2(const struct ieee80211_channel *c) { + if (IEEE80211_IS_CHAN_VHT(c)) + return (c->ic_vht_ch_freq2); + return (0); } @@ -1242,6 +1513,7 @@ * Adds channels into specified channel list (ieee[] array must be sorted). * Channels are already sorted. */ +/* XXX VHT? */ static int add_chanlist(struct ieee80211_channel chans[], int maxchans, int *nchans, const uint8_t ieee[], int nieee, uint32_t flags[]) @@ -1248,16 +1520,70 @@ { uint16_t freq; int i, j, error; + int is_vht; for (i = 0; i < nieee; i++) { freq = ieee80211_ieee2mhz(ieee[i], flags[0]); for (j = 0; flags[j] != 0; j++) { + /* + * Notes: + * + HT40 and VHT40 channels occur together, so + * we need to be careful that we actually allow that. + * + VHT80, VHT160 will coexist with HT40/VHT40, so + * make sure it's not skipped because of the overlap + * check used for (V)HT40. + */ + is_vht = !! (flags[j] & IEEE80211_CHAN_VHT); + + /* + * Test for VHT80. + * XXX This is all very broken right now. + * What we /should/ do is: + * + * + check that the frequency is in the list of + * allowed VHT80 ranges; and + * + the other 3 channels in the list are actually + * also available. + */ + if (is_vht && flags[j] & IEEE80211_CHAN_VHT80) + if (! is_vht80_valid_freq(freq)) + continue; + + /* + * Test for (V)HT40. + * + * This is also a fall through from VHT80; as we only + * allow a VHT80 channel if the VHT40 combination is + * also valid. If the VHT40 form is not valid then + * we certainly can't do VHT80.. + */ if (flags[j] & IEEE80211_CHAN_HT40D) + /* + * Can't have a "lower" channel if we are the + * first channel. + * + * Can't have a "lower" channel if it's below/ + * within 20MHz of the first channel. + * + * Can't have a "lower" channel if the channel + * below it is not 20MHz away. + */ if (i == 0 || ieee[i] < ieee[0] + 4 || freq - 20 != ieee80211_ieee2mhz(ieee[i] - 4, flags[j])) continue; if (flags[j] & IEEE80211_CHAN_HT40U) + /* + * Can't have an "upper" channel if we are + * the last channel. + * + * Can't have an "upper" channel be above the + * last channel in the list. + * + * Can't have an "upper" channel if the next + * channel according to the math isn't 20MHz + * away. (Likely for channel 13/14.) + */ if (i == nieee - 1 || ieee[i] + 4 > ieee[nieee - 1] || freq + 20 != @@ -1286,6 +1612,7 @@ { uint32_t flags[IEEE80211_MODE_MAX]; + /* XXX no VHT80 for now */ getflags_2ghz(bands, flags, ht40); KASSERT(flags[0] != 0, ("%s: no correct mode provided\n", __func__)); @@ -1298,8 +1625,15 @@ int ht40) { uint32_t flags[IEEE80211_MODE_MAX]; + int vht80 = 0; - getflags_5ghz(bands, flags, ht40); + /* + * For now, assume VHT == VHT80 support. + */ + if (isset(bands, IEEE80211_MODE_VHT_5GHZ)) + vht80 = 1; + + getflags_5ghz(bands, flags, ht40, vht80); KASSERT(flags[0] != 0, ("%s: no correct mode provided\n", __func__)); return (add_chanlist(chans, maxchans, nchans, ieee, nieee, flags)); @@ -1438,6 +1772,8 @@ [IEEE80211_MODE_QUARTER] = IFM_IEEE80211_11A, /* XXX */ [IEEE80211_MODE_11NA] = IFM_IEEE80211_11NA, [IEEE80211_MODE_11NG] = IFM_IEEE80211_11NG, + [IEEE80211_MODE_VHT_2GHZ] = IFM_IEEE80211_VHT2G, + [IEEE80211_MODE_VHT_5GHZ] = IFM_IEEE80211_VHT5G, }; u_int mopt; @@ -1550,6 +1886,19 @@ if (rate > maxrate) maxrate = rate; } + + /* + * Add VHT media. + */ + for (; mode <= IEEE80211_MODE_VHT_5GHZ; mode++) { + if (isclr(ic->ic_modecaps, mode)) + continue; + addmedia(media, caps, addsta, mode, IFM_AUTO); + addmedia(media, caps, addsta, mode, IFM_IEEE80211_VHT); + + /* XXX TODO: VHT maxrate */ + } + return maxrate; } @@ -1585,6 +1934,7 @@ printf("\n"); } ieee80211_ht_announce(ic); + ieee80211_vht_announce(ic); } void Index: sys/net80211/ieee80211.h =================================================================== --- sys/net80211/ieee80211.h (revision 311042) +++ sys/net80211/ieee80211.h (working copy) @@ -737,16 +737,6 @@ * 802.11ac definitions - 802.11ac-2013 . */ -/* VHT opmode bits */ -#define IEEE80211_VHT_OPMODE_CHANWIDTH_MASK 3 -#define IEEE80211_VHT_OPMODE_CHANWIDTH_20MHZ 0 -#define IEEE80211_VHT_OPMODE_CHANWIDTH_40MHZ 1 -#define IEEE80211_VHT_OPMODE_CHANWIDTH_80MHZ 2 -#define IEEE80211_VHT_OPMODE_CHANWIDTH_160MHZ 3 -#define IEEE80211_VHT_OPMODE_RX_NSS_MASK 0x70 -#define IEEE80211_VHT_OPMODE_RX_NSS_SHIFT 4 -#define IEEE80211_VHT_OPMODE_RX_NSS_TYPE_BF 0x80 - /* * Maximum length of A-MPDU that the STA can RX in VHT. * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) @@ -787,6 +777,7 @@ struct ieee80211_vht_mcs_info supp_mcs; } __packed; +/* VHT operation mode subfields - 802.11ac-2013 Table 8.183x */ #define IEEE80211_VHT_CHANWIDTH_USE_HT 0 /* Use HT IE for chw */ #define IEEE80211_VHT_CHANWIDTH_80MHZ 1 /* 80MHz */ #define IEEE80211_VHT_CHANWIDTH_160MHZ 2 /* 160MHz */ @@ -839,6 +830,11 @@ #define IEEE80211_VHTCAP_RX_ANTENNA_PATTERN 0x10000000 #define IEEE80211_VHTCAP_TX_ANTENNA_PATTERN 0x20000000 +#define IEEE80211_VHTCAP_BITS \ + "\20\1MPDU7991\2MPDU11454\3CHAN160\4CHAN8080\5RXLDPC\6SHORTGI80" \ + "\7SHORTGI160\10RXSTBC1\11RXSTBC2\12RXSTBC3\13RXSTBC4\14BFERCAP" \ + "\15BFEECAP\27VHT" + /* * VHT Transmit Power Envelope element - 802.11ac-2013 8.4.2.164 * Index: sys/net80211/ieee80211_adhoc.c =================================================================== --- sys/net80211/ieee80211_adhoc.c (revision 311042) +++ sys/net80211/ieee80211_adhoc.c (working copy) @@ -822,10 +822,14 @@ #if 0 if (scan.htcap != NULL && scan.htinfo != NULL && (vap->iv_flags_ht & IEEE80211_FHT_HT)) { - if (ieee80211_ht_updateparams(ni, + ieee80211_ht_updateparams(ni, scan.htcap, scan.htinfo)) + if (ieee80211_ht_updateparams_final(ni, + scan.htcap, scan.htinfo)) ht_state_change = 1; } + + /* XXX same for VHT? */ #endif if (ni != NULL) { IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); Index: sys/net80211/ieee80211_hostap.c =================================================================== --- sys/net80211/ieee80211_hostap.c (revision 311042) +++ sys/net80211/ieee80211_hostap.c (working copy) @@ -62,6 +62,7 @@ #include #endif #include +#include #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) @@ -1745,6 +1746,7 @@ struct ieee80211_frame *wh; uint8_t *frm, *efrm, *sfrm; uint8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath, *htcap; + uint8_t *vhtcap, *vhtinfo; int reassoc, resp; uint8_t rate; @@ -2042,6 +2044,7 @@ if (reassoc) frm += 6; /* ignore current AP info */ ssid = rates = xrates = wpa = rsn = wme = ath = htcap = NULL; + vhtcap = vhtinfo = NULL; sfrm = frm; while (efrm - frm > 1) { IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); @@ -2061,6 +2064,12 @@ case IEEE80211_ELEMID_HTCAP: htcap = frm; break; + case IEEE80211_ELEMID_VHT_CAP: + vhtcap = frm; + break; + case IEEE80211_ELEMID_VHT_OPMODE: + vhtinfo = frm; + break; case IEEE80211_ELEMID_VENDOR: if (iswpaoui(frm)) wpa = frm; @@ -2135,10 +2144,22 @@ vap->iv_stats.is_rx_assoc_norate++; return; } + /* * Do HT rate set handling and setup HT node state. */ ni->ni_chan = vap->iv_bss->ni_chan; + + /* VHT */ + if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { + /* XXX TODO; see below */ + printf("%s: VHT TODO!\n", __func__); + ieee80211_vht_node_init(ni); + ieee80211_vht_update_cap(ni, vhtcap, vhtinfo); + } else if (ni->ni_flags & IEEE80211_NODE_VHT) + ieee80211_vht_node_cleanup(ni); + + /* HT */ if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) { rate = ieee80211_setup_htrates(ni, htcap, IEEE80211_F_DOFMCS | IEEE80211_F_DONEGO | @@ -2153,6 +2174,12 @@ ieee80211_ht_updatehtcap(ni, htcap); } else if (ni->ni_flags & IEEE80211_NODE_HT) ieee80211_ht_node_cleanup(ni); + + /* Finally - this will use HT/VHT info to change node channel */ + if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) { + ieee80211_ht_updatehtcap_final(ni, htcap); + } + #ifdef IEEE80211_SUPPORT_SUPERG /* Always do ff node cleanup; for A-MSDU */ ieee80211_ff_node_cleanup(ni); Index: sys/net80211/ieee80211_ht.c =================================================================== --- sys/net80211/ieee80211_ht.c (revision 311042) +++ sys/net80211/ieee80211_ht.c (working copy) @@ -1497,6 +1497,12 @@ * channel only; the caller is responsible for insuring any * required channel change is done (e.g. in sta mode when * parsing the contents of a beacon frame). + * + * XXX TODO VHT: In 11ac mode, what should be done here? + * We don't want to fall back to HT only channels when + * operating in VHT mode. + * + * XXX TODO VHT: this is required to be taught about VHT or every (V)HT setup call will degrade to HT! */ static int htinfo_update_chw(struct ieee80211_node *ni, int htflags) @@ -1506,7 +1512,12 @@ int chanflags; int ret = 0; - chanflags = (ni->ni_chan->ic_flags &~ IEEE80211_CHAN_HT) | htflags; + /* + * First step - do HT only channel lookup based on operating mode + * flags. + */ + chanflags = (ni->ni_chan->ic_flags &~ (IEEE80211_CHAN_HT | IEEE80211_CHAN_VHT)) | htflags; + c = NULL; if (chanflags != ni->ni_chan->ic_flags) { /* XXX not right for ht40- */ c = ieee80211_find_channel(ic, ni->ni_chan->ic_freq, chanflags); @@ -1524,18 +1535,71 @@ #endif /* XXX stat */ } - if (c != NULL && c != ni->ni_chan) { - IEEE80211_NOTE(ni->ni_vap, - IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni, - "switch station to HT%d channel %u/0x%x", - IEEE80211_IS_CHAN_HT40(c) ? 40 : 20, - c->ic_freq, c->ic_flags); - ni->ni_chan = c; - ret = 1; + } + + /* Nothing found - leave it alone */ + if (c == NULL) + c = ni->ni_chan; + + /* + * If it's non-HT, then bail out now. + */ + if (! IEEE80211_IS_CHAN_HT(c)) { + IEEE80211_NOTE(ni->ni_vap, + IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni, + "not HT; skipping VHT check (%u/0x%x)", + c->ic_freq, c->ic_flags); + return (0); + } + + /* + * Next step - look at the current VHT flags and determine + * if we need to upgrade. + */ + /* + * XXX TODO: the HT handling does something slightly different + * in AP versus STA mode. This needs to be double-checked for + * VHT operation. + * + * XXX TODO: assume 80MHz is possible; just try a find first. + * + * XXX TODO: I should likely be looking at the local vht capability + * as well as the advertised node one before making this choice. + */ + if (ni->ni_vhtcap != 0) { + chanflags = (c->ic_flags &~ IEEE80211_CHAN_VHT); +// printf("%s: VHT; chanwidth=0x%02x\n", __func__, ni->ni_vht_chanwidth); + if ((ni->ni_vht_chanwidth & 0x3) == IEEE80211_VHT_CHANWIDTH_USE_HT) { + if (IEEE80211_IS_CHAN_HT40U(c)) + chanflags |= IEEE80211_CHAN_VHT40U; + if (IEEE80211_IS_CHAN_HT40D(c)) + chanflags |= IEEE80211_CHAN_VHT40D; } - /* NB: caller responsible for forcing any channel change */ + if ((ni->ni_vht_chanwidth & 0x3) == IEEE80211_VHT_CHANWIDTH_80MHZ) { + chanflags |= IEEE80211_CHAN_VHT80; + } + + /* XXX VHT TODO 80+80, 160MHz */ +// printf("%s: VHT; trying lookup for %d/0x%08x\n", __func__, c->ic_freq, chanflags); + c = ieee80211_find_channel(ic, c->ic_freq, chanflags); } - /* update node's tx channel width */ + + /* Finally, if it's changed */ + if (c != NULL && c != ni->ni_chan) { + IEEE80211_NOTE(ni->ni_vap, + IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni, + "switch station to %s%d channel %u/0x%x", + IEEE80211_IS_CHAN_VHT(c) ? "VHT" : "HT", + IEEE80211_IS_CHAN_VHT80(c) ? 80 : + (IEEE80211_IS_CHAN_HT40(c) ? 40 : 20), + c->ic_freq, c->ic_flags); + ni->ni_chan = c; + ret = 1; + } + /* NB: caller responsible for forcing any channel change */ + + /* update node's (11n) tx channel width */ + /* I think this is just for debug, and can become 80/160 too */ ni->ni_chw = IEEE80211_IS_CHAN_HT40(ni->ni_chan)? 40 : 20; return (ret); } @@ -1588,14 +1652,12 @@ * Parse and update HT-related state extracted from * the HT cap and info ie's. */ -int +void ieee80211_ht_updateparams(struct ieee80211_node *ni, const uint8_t *htcapie, const uint8_t *htinfoie) { struct ieee80211vap *vap = ni->ni_vap; const struct ieee80211_ie_htinfo *htinfo; - int htflags; - int ret = 0; ieee80211_parse_htcap(ni, htcapie); if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS) @@ -1607,8 +1669,44 @@ htinfo = (const struct ieee80211_ie_htinfo *) htinfoie; htinfo_parse(ni, htinfo); + /* + * Defer the node channel change; we need to now + * update VHT parameters before we do it. + */ + + if ((htinfo->hi_byte1 & IEEE80211_HTINFO_RIFSMODE_PERM) && + (vap->iv_flags_ht & IEEE80211_FHT_RIFS)) + ni->ni_flags |= IEEE80211_NODE_RIFS; + else + ni->ni_flags &= ~IEEE80211_NODE_RIFS; +} + +/* + * Final part of updating the HT parameters. + * + * This is done after a call to ieee80211_ht_updateparams() + * because it (and the upcoming VHT version of updateparams) + * needs to ensure everything is parsed before htinfo_update_chw() + * is called - which will change the channel config for the + * node for us. + * + * XXX TODO: rely on the node htcap/htinfo (and VHT versions) + * being setup and remove the passed in versions. + */ +int +ieee80211_ht_updateparams_final(struct ieee80211_node *ni, + const uint8_t *htcapie, const uint8_t *htinfoie) +{ + struct ieee80211vap *vap = ni->ni_vap; + const struct ieee80211_ie_htinfo *htinfo; + int htflags; + int ret = 0; + + htinfo = (const struct ieee80211_ie_htinfo *) htinfoie; + htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ? IEEE80211_CHAN_HT20 : 0; + /* NB: honor operating mode constraint */ if ((htinfo->hi_byte1 & IEEE80211_HTINFO_TXWIDTH_2040) && (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)) { @@ -1620,12 +1718,6 @@ if (htinfo_update_chw(ni, htflags)) ret = 1; - if ((htinfo->hi_byte1 & IEEE80211_HTINFO_RIFSMODE_PERM) && - (vap->iv_flags_ht & IEEE80211_FHT_RIFS)) - ni->ni_flags |= IEEE80211_NODE_RIFS; - else - ni->ni_flags &= ~IEEE80211_NODE_RIFS; - return (ret); } @@ -1637,13 +1729,19 @@ ieee80211_ht_updatehtcap(struct ieee80211_node *ni, const uint8_t *htcapie) { struct ieee80211vap *vap = ni->ni_vap; - int htflags; ieee80211_parse_htcap(ni, htcapie); if (vap->iv_htcaps & IEEE80211_HTCAP_SMPS) htcap_update_mimo_ps(ni); htcap_update_shortgi(ni); +} +void +ieee80211_ht_updatehtcap_final(struct ieee80211_node *ni, const uint8_t *htcapie) +{ + struct ieee80211vap *vap = ni->ni_vap; + int htflags; + /* NB: honor operating mode constraint */ /* XXX 40 MHz intolerant */ htflags = (vap->iv_flags_ht & IEEE80211_FHT_HT) ? @@ -2229,6 +2327,10 @@ dialogtoken = (tokens+1) % 63; /* XXX */ tid = tap->txa_tid; + + /* + * XXX TODO: This is racy with any other parallel TX going on. :( + */ tap->txa_start = ni->ni_txseqs[tid]; args[0] = dialogtoken; Index: sys/net80211/ieee80211_ht.h =================================================================== --- sys/net80211/ieee80211_ht.h (revision 311042) +++ sys/net80211/ieee80211_ht.h (working copy) @@ -201,9 +201,12 @@ void ieee80211_ht_timeout(struct ieee80211com *); void ieee80211_parse_htcap(struct ieee80211_node *, const uint8_t *); void ieee80211_parse_htinfo(struct ieee80211_node *, const uint8_t *); -int ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *, +void ieee80211_ht_updateparams(struct ieee80211_node *, const uint8_t *, const uint8_t *); +int ieee80211_ht_updateparams_final(struct ieee80211_node *, const uint8_t *, + const uint8_t *); void ieee80211_ht_updatehtcap(struct ieee80211_node *, const uint8_t *); +void ieee80211_ht_updatehtcap_final(struct ieee80211_node *, const uint8_t *); int ieee80211_ampdu_request(struct ieee80211_node *, struct ieee80211_tx_ampdu *); void ieee80211_ampdu_stop(struct ieee80211_node *, Index: sys/net80211/ieee80211_input.c =================================================================== --- sys/net80211/ieee80211_input.c (revision 311042) +++ sys/net80211/ieee80211_input.c (working copy) @@ -494,6 +494,8 @@ scan->status = 0; /* * beacon/probe response frame format + * + * XXX Update from 802.11-2012 - eg where HT is * [8] time stamp * [2] beacon interval * [2] capability information @@ -508,6 +510,8 @@ * [tlv] WPA or RSN * [tlv] HT capabilities * [tlv] HT information + * [tlv] VHT capabilities + * [tlv] VHT information * [tlv] Atheros capabilities * [tlv] Mesh ID * [tlv] Mesh Configuration @@ -585,6 +589,12 @@ case IEEE80211_ELEMID_HTCAP: scan->htcap = frm; break; + case IEEE80211_ELEMID_VHT_CAP: + scan->vhtcap = frm; + break; + case IEEE80211_ELEMID_VHT_OPMODE: + scan->vhtopmode = frm; + break; case IEEE80211_ELEMID_RSN: scan->rsn = frm; break; @@ -718,6 +728,19 @@ sizeof(struct ieee80211_ie_htinfo)-2, scan->htinfo = NULL); } + + /* Process VHT IEs */ + if (scan->vhtcap != NULL) { + IEEE80211_VERIFY_LENGTH(scan->vhtcap[1], + sizeof(struct ieee80211_ie_vhtcap) - 2, + scan->vhtcap = NULL); + } + if (scan->vhtopmode != NULL) { + IEEE80211_VERIFY_LENGTH(scan->vhtopmode[1], + sizeof(struct ieee80211_ie_vht_operation) - 2, + scan->vhtopmode = NULL); + } + return scan->status; } @@ -838,6 +861,9 @@ } break; #endif + case IEEE80211_ACTION_CAT_VHT: + printf("%s: TODO: VHT handling!\n", __func__); + break; } return 0; } Index: sys/net80211/ieee80211_ioctl.c =================================================================== --- sys/net80211/ieee80211_ioctl.c (revision 311042) +++ sys/net80211/ieee80211_ioctl.c (working copy) @@ -710,6 +710,7 @@ dc->dc_drivercaps = ic->ic_caps; dc->dc_cryptocaps = ic->ic_cryptocaps; dc->dc_htcaps = ic->ic_htcaps; + dc->dc_vhtcaps = ic->ic_vhtcaps; ci = &dc->dc_chaninfo; ic->ic_getradiocaps(ic, maxchans, &ci->ic_nchans, ci->ic_chans); KASSERT(ci->ic_nchans <= maxchans, @@ -1135,6 +1136,22 @@ if (vap->iv_flags_ht & IEEE80211_FHT_STBC_RX) ireq->i_val |= 2; break; + + /* VHT */ + case IEEE80211_IOC_VHTCONF: + ireq->i_val = 0; + if (vap->iv_flags_vht & IEEE80211_FVHT_VHT) + ireq->i_val |= 1; + if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT40) + ireq->i_val |= 2; + if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80) + ireq->i_val |= 4; + if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80P80) + ireq->i_val |= 8; + if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT160) + ireq->i_val |= 16; + break; + default: error = ieee80211_ioctl_getdefault(vap, ireq); break; @@ -1547,9 +1564,14 @@ lookup.esslen = ssid_len; lookup.essid = ssid; ieee80211_scan_iterate(vap, mlmelookup, &lookup); - if (lookup.se == NULL) + if (lookup.se == NULL) { + printf("%s: couldn't find a scan entry\n", __func__); return ENOENT; + } mlmedebug(vap, mac, IEEE80211_MLME_ASSOC, 0); + printf("%s: found channel; se_chan=%d/0x%08x\n", __func__, + lookup.se->se_chan->ic_freq, + lookup.se->se_chan->ic_flags); if (!ieee80211_sta_join(vap, lookup.se->se_chan, lookup.se)) return EIO; /* XXX unique but could be better */ return 0; @@ -1869,6 +1891,7 @@ /* NB: handled specially below */ [IEEE80211_MODE_11NA] = IEEE80211_CHAN_A, [IEEE80211_MODE_11NG] = IEEE80211_CHAN_G, + [IEEE80211_MODE_VHT_5GHZ] = IEEE80211_CHAN_A, }; u_int modeflags; int i; @@ -1893,11 +1916,27 @@ !find11gchannel(ic, i, c->ic_freq)) return c; } else { - /* must check HT specially */ + /* must check VHT specifically */ + if ((mode == IEEE80211_MODE_VHT_5GHZ || + mode == IEEE80211_MODE_VHT_2GHZ) && + !IEEE80211_IS_CHAN_VHT(c)) + continue; + + /* + * Must check HT specially - only match on HT, + * not HT+VHT channels + */ if ((mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) && !IEEE80211_IS_CHAN_HT(c)) continue; + + if ((mode == IEEE80211_MODE_11NA || + mode == IEEE80211_MODE_11NG) && + IEEE80211_IS_CHAN_VHT(c)) + continue; + + /* Check that the modeflags above match */ if ((c->ic_flags & modeflags) == modeflags) return c; } @@ -1960,6 +1999,9 @@ vap->iv_bss->ni_chan == c) return 0; /* NB: nothing to do */ } + + printf("%s: called; freq=%d/0x%08x\n", __func__, c->ic_freq, c->ic_flags); + vap->iv_des_chan = c; error = 0; @@ -2021,6 +2063,13 @@ if (c == NULL) return EINVAL; } + + printf("%s: i_val=%d, desmode=%d, found %c/0x%08x\n", + __func__, + ireq->i_val, + vap->iv_des_mode, + c->ic_freq, + c->ic_flags); /* * Fine tune channel selection based on desired mode: * if 11b is requested, find the 11b version of any @@ -2031,6 +2080,8 @@ * 11a channel returned, * if 11ng is requested, find the ht version of any * 11g channel returned, + * TODO: if 11ac is requested, find the 11ac version + * of any 11a/11na channel returned, * otherwise we should be ok with what we've got. */ switch (vap->iv_des_mode) { @@ -2067,6 +2118,15 @@ c = c2; } break; + /* XXX TODO: VHT_2GHZ */ + case IEEE80211_MODE_VHT_5GHZ: + if (IEEE80211_IS_CHAN_A(c)) { + c2 = findchannel(ic, ireq->i_val, + IEEE80211_MODE_VHT_5GHZ); + if (c2 != NULL) + c = c2; + } + break; default: /* NB: no static turboG */ break; } @@ -2092,6 +2152,12 @@ error = copyin(ireq->i_data, &chan, sizeof(chan)); if (error != 0) return error; + + printf("%s: called; c=%d/0x%08x\n", + __func__, + chan.ic_freq, + chan.ic_flags); + /* XXX 0xffff overflows 16-bit signed */ if (chan.ic_freq == 0 || chan.ic_freq == IEEE80211_CHAN_ANY) { c = IEEE80211_CHAN_ANYC; @@ -2099,6 +2165,10 @@ c = ieee80211_find_channel(ic, chan.ic_freq, chan.ic_flags); if (c == NULL) return EINVAL; + printf("%s: found; c=%d/0x%08x\n", + __func__, + c->ic_freq, + c->ic_flags); } return setcurchan(vap, c); } @@ -3321,6 +3391,37 @@ if (isvapht(vap)) error = ERESTART; break; + + /* VHT */ + case IEEE80211_IOC_VHTCONF: + if (ireq->i_val & 1) + ieee80211_syncflag_vht(vap, IEEE80211_FVHT_VHT); + else + ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_VHT); + + if (ireq->i_val & 2) + ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT40); + else + ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT40); + + if (ireq->i_val & 4) + ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80); + else + ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80); + + if (ireq->i_val & 8) + ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80P80); + else + ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80P80); + + if (ireq->i_val & 16) + ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT160); + else + ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT160); + + error = ENETRESET; + break; + default: error = ieee80211_ioctl_setdefault(vap, ireq); break; Index: sys/net80211/ieee80211_ioctl.h =================================================================== --- sys/net80211/ieee80211_ioctl.h (revision 311042) +++ sys/net80211/ieee80211_ioctl.h (working copy) @@ -556,6 +556,7 @@ uint32_t dc_drivercaps; /* general driver caps */ uint32_t dc_cryptocaps; /* hardware crypto support */ uint32_t dc_htcaps; /* HT/802.11n support */ + uint32_t dc_vhtcaps; /* VHT/802.11ac capabilities */ struct ieee80211req_chaninfo dc_chaninfo; }; #define IEEE80211_DEVCAPS_SIZE(_nchan) \ @@ -704,6 +705,9 @@ #define IEEE80211_IOC_STBC 113 /* STBC Tx/RX (on, off) */ #define IEEE80211_IOC_LDPC 114 /* LDPC Tx/RX (on, off) */ +/* VHT */ +#define IEEE80211_IOC_VHTCONF 130 /* VHT config (off, on (TBD: widths) */ + #define IEEE80211_IOC_MESH_ID 170 /* mesh identifier */ #define IEEE80211_IOC_MESH_AP 171 /* accepting peerings */ #define IEEE80211_IOC_MESH_FWRD 172 /* forward frames */ Index: sys/net80211/ieee80211_node.c =================================================================== --- sys/net80211/ieee80211_node.c (revision 311042) +++ sys/net80211/ieee80211_node.c (working copy) @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -412,9 +413,13 @@ /* XXX TODO: other bits and pieces - eg fast-frames? */ /* If we're an 11n channel then initialise the 11n bits */ - if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) { + if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { /* XXX what else? */ ieee80211_ht_node_init(ni); + ieee80211_vht_node_init(ni); + } else if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) { + /* XXX what else? */ + ieee80211_ht_node_init(ni); } (void) ieee80211_sta_join1(ieee80211_ref_node(ni)); @@ -708,6 +713,38 @@ } /* + * Calculate VHT channel promotion flags for all vaps. + * This assumes ni_chan have been setup for each vap. + */ +static int +getvhtadjustflags(struct ieee80211com *ic) +{ + struct ieee80211vap *vap; + int flags; + + flags = 0; + /* XXX locking */ + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { + if (vap->iv_state < IEEE80211_S_RUN) + continue; + switch (vap->iv_opmode) { + case IEEE80211_M_WDS: + case IEEE80211_M_STA: + case IEEE80211_M_AHDEMO: + case IEEE80211_M_HOSTAP: + case IEEE80211_M_IBSS: + case IEEE80211_M_MBSS: + printf("%s: chan=%d/0x%08x\n", __func__, vap->iv_bss->ni_chan->ic_freq, vap->iv_bss->ni_chan->ic_flags); + flags |= ieee80211_vhtchanflags(vap->iv_bss->ni_chan); + break; + default: + break; + } + } + return flags; +} + +/* * Check if the current channel needs to change based on whether * any vap's are using HT20/HT40. This is used to sync the state * of ic_curchan after a channel width change on a running vap. @@ -717,7 +754,11 @@ { struct ieee80211_channel *c; + /* XXX VHT? */ c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, gethtadjustflags(ic)); + printf("%s: vhtflags=0x%08x\n", __func__, getvhtadjustflags(ic)); + c = ieee80211_vht_adjust_channel(ic, c, getvhtadjustflags(ic)); + if (c != ic->ic_curchan) { ic->ic_curchan = c; ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan); @@ -743,10 +784,23 @@ * set of running vap's. This assumes we are called * after ni_chan is setup for each vap. */ + /* XXX VHT? */ /* NB: this assumes IEEE80211_FHT_USEHT40 > IEEE80211_FHT_HT */ if (flags > ieee80211_htchanflags(c)) c = ieee80211_ht_adjust_channel(ic, c, flags); } + + /* + * VHT promotion - this will at least promote to VHT20/40 + * based on what HT has done; it may further promote the + * channel to VHT80 or above. + */ + if (ic->ic_vhtcaps != 0) { + int flags = getvhtadjustflags(ic); + if (flags > ieee80211_vhtchanflags(c)) + c = ieee80211_vht_adjust_channel(ic, c, flags); + } + ic->ic_bsschan = ic->ic_curchan = c; ic->ic_curmode = ieee80211_chan2mode(ic->ic_curchan); ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan); @@ -849,6 +903,7 @@ { struct ieee80211com *ic = vap->iv_ic; struct ieee80211_node *ni; + int do_ht = 0; ni = ieee80211_alloc_node(&ic->ic_sta, vap, se->se_macaddr); if (ni == NULL) { @@ -896,9 +951,13 @@ if (ni->ni_ies.tdma_ie != NULL) ieee80211_parse_tdma(ni, ni->ni_ies.tdma_ie); #endif + if (ni->ni_ies.vhtcap_ie != NULL) + ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie); + if (ni->ni_ies.vhtopmode_ie != NULL) + ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie); - /* XXX parse VHT IEs */ /* XXX parse BSSLOAD IE */ + /* XXX parse TXPWRENV IE */ /* XXX parse APCHANREP IE */ } @@ -911,6 +970,15 @@ if (ieee80211_iserp_rateset(&ni->ni_rates)) ni->ni_flags |= IEEE80211_NODE_ERP; + printf("%s: called; chan=%d/0x%08x, htinfo %p/%p vhtinfo %p/%p\n", + __func__, + chan->ic_freq, + chan->ic_flags, + ni->ni_ies.htcap_ie, + ni->ni_ies.htinfo_ie, + ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + /* * Setup HT state for this node if it's available, otherwise * non-STA modes won't pick this state up. @@ -929,7 +997,31 @@ ieee80211_setup_htrates(ni, ni->ni_ies.htcap_ie, IEEE80211_F_JOIN | IEEE80211_F_DOBRS); ieee80211_setup_basic_htrates(ni, ni->ni_ies.htinfo_ie); + do_ht = 1; } + + /* + * Setup VHT state for this node if it's available. + * Same as the above. + */ + if (ni->ni_ies.vhtopmode_ie != NULL && + ni->ni_ies.vhtcap_ie != NULL && + vap->iv_flags_vht & IEEE80211_FVHT_VHT) { + ieee80211_vht_node_init(ni); + ieee80211_vht_updateparams(ni, + ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + ieee80211_setup_vht_rates(ni, ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + do_ht = 1; + } + + /* Finally do the node channel change */ + if (do_ht) + ieee80211_ht_updateparams_final(ni, + ni->ni_ies.htcap_ie, + ni->ni_ies.htinfo_ie); + /* XXX else check for ath FF? */ /* XXX QoS? Difficult given that WME config is specific to a master */ @@ -1102,8 +1194,10 @@ "power save mode off, %u sta's in ps mode", vap->iv_ps_sta); } /* - * Cleanup any HT-related state. + * Cleanup any VHT and HT-related state. */ + if (ni->ni_flags & IEEE80211_NODE_VHT) + ieee80211_vht_node_cleanup(ni); if (ni->ni_flags & IEEE80211_NODE_HT) ieee80211_ht_node_cleanup(ni); #ifdef IEEE80211_SUPPORT_SUPERG @@ -1423,6 +1517,7 @@ if (vap->iv_flags & IEEE80211_F_FF) ni->ni_flags |= IEEE80211_NODE_FF; #endif + /* XXX VHT */ if ((ic->ic_htcaps & IEEE80211_HTC_HT) && (vap->iv_flags_ht & IEEE80211_FHT_HT)) { /* @@ -1431,6 +1526,9 @@ * ni_chan will be adjusted to an HT channel. */ ieee80211_ht_wds_init(ni); + if (vap->iv_flags_vht & IEEE80211_FVHT_VHT) { + printf("%s: TODO: vht_wds_init\n", __func__); + } } else { struct ieee80211_channel *c = ni->ni_chan; /* @@ -1638,7 +1736,7 @@ const struct ieee80211_frame *wh, const struct ieee80211_scanparams *sp) { - int do_ht_setup = 0; + int do_ht_setup = 0, do_vht_setup = 0; ni->ni_esslen = sp->ssid[1]; memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]); @@ -1670,11 +1768,23 @@ if (ni->ni_ies.htinfo_ie != NULL) ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie); + if (ni->ni_ies.vhtcap_ie != NULL) + ieee80211_parse_vhtcap(ni, ni->ni_ies.vhtcap_ie); + if (ni->ni_ies.vhtopmode_ie != NULL) + ieee80211_parse_vhtopmode(ni, ni->ni_ies.vhtopmode_ie); + if ((ni->ni_ies.htcap_ie != NULL) && (ni->ni_ies.htinfo_ie != NULL) && (ni->ni_vap->iv_flags_ht & IEEE80211_FHT_HT)) { do_ht_setup = 1; } + + if ((ni->ni_ies.vhtcap_ie != NULL) && + (ni->ni_ies.vhtopmode_ie != NULL) && + (ni->ni_vap->iv_flags_vht & IEEE80211_FVHT_VHT)) { + do_vht_setup = 1; + } + } /* NB: must be after ni_chan is setup */ @@ -1697,10 +1807,29 @@ IEEE80211_F_JOIN | IEEE80211_F_DOBRS); ieee80211_setup_basic_htrates(ni, ni->ni_ies.htinfo_ie); + + if (do_vht_setup) { + ieee80211_vht_node_init(ni); + ieee80211_vht_updateparams(ni, + ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + ieee80211_setup_vht_rates(ni, + ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + } + + /* + * Finally do the channel upgrade/change based + * on the HT/VHT configuration. + */ + ieee80211_ht_updateparams_final(ni, + ni->ni_ies.vhtcap_ie, + ni->ni_ies.vhtopmode_ie); + ieee80211_node_setuptxparms(ni); ieee80211_ratectl_node_init(ni); - /* Reassociate; we're now 11n */ + /* Reassociate; we're now 11n/11ac */ /* * XXX TODO: this is the wrong thing to do - * we're calling it with isnew=1 so the ath(4) @@ -2365,6 +2494,7 @@ IEEE80211_LOCK(ic); ieee80211_erp_timeout(ic); ieee80211_ht_timeout(ic); + ieee80211_vht_timeout(ic); IEEE80211_UNLOCK(ic); } callout_reset(&ic->ic_inact, IEEE80211_INACT_WAIT*hz, @@ -2594,6 +2724,8 @@ if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan)) ieee80211_ht_node_join(ni); + if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan)) + ieee80211_vht_node_join(ni); if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) && IEEE80211_IS_CHAN_FULL(ic->ic_bsschan)) ieee80211_node_join_11g(ni); @@ -2774,6 +2906,8 @@ vap->iv_sta_assoc--; ic->ic_sta_assoc--; + if (IEEE80211_IS_CHAN_VHT(ic->ic_bsschan)) + ieee80211_vht_node_leave(ni); if (IEEE80211_IS_CHAN_HT(ic->ic_bsschan)) ieee80211_ht_node_leave(ni); if (IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) && Index: sys/net80211/ieee80211_node.h =================================================================== --- sys/net80211/ieee80211_node.h (revision 311042) +++ sys/net80211/ieee80211_node.h (working copy) @@ -142,6 +142,7 @@ #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ +#define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */ uint16_t ni_associd; /* association ID */ uint16_t ni_vlan; /* vlan tag */ uint16_t ni_txpower; /* current transmit power */ @@ -226,11 +227,13 @@ /* VHT state */ uint32_t ni_vhtcap; - uint32_t ni_vhtinfo; + uint16_t ni_vht_basicmcs; + uint16_t ni_vht_pad2; struct ieee80211_vht_mcs_info ni_vht_mcsinfo; uint8_t ni_vht_chan1; /* 20/40/80/160 - VHT chan1 */ uint8_t ni_vht_chan2; /* 80+80 - VHT chan2 */ - uint16_t ni_vht_pad1; + uint8_t ni_vht_chanwidth; /* IEEE80211_VHT_CHANWIDTH_ */ + uint8_t ni_vht_pad1; uint32_t ni_vht_spare[8]; /* fast-frames state */ Index: sys/net80211/ieee80211_output.c =================================================================== --- sys/net80211/ieee80211_output.c (revision 311042) +++ sys/net80211/ieee80211_output.c (working copy) @@ -58,6 +58,7 @@ #endif #include #include +#include #if defined(INET) || defined(INET6) #include @@ -764,6 +765,16 @@ } *(uint16_t *)&wh->i_dur[0] = 0; + /* + * XXX TODO: this is what the TX lock is for. + * Here we're incrementing sequence numbers, and they + * need to be in lock-step with what the driver is doing + * both in TX ordering and crypto encap (IV increment.) + * + * If the driver does seqno itself, then we can skip + * assigning sequence numbers here, and we can avoid + * requiring the TX lock. + */ tap = &ni->ni_tx_ampdu[tid]; if (tid != IEEE80211_NONQOS_TID && IEEE80211_AMPDU_RUNNING(tap)) m->m_flags |= M_AMPDU_MPDU; @@ -1542,6 +1553,11 @@ if (is_amsdu) qos[0] |= IEEE80211_QOS_AMSDU; + /* + * XXX TODO TX lock is needed for atomic updates of sequence + * numbers. If the driver does it, then don't do it here; + * and we don't need the TX lock held. + */ if ((m->m_flags & M_AMPDU_MPDU) == 0) { /* * NB: don't assign a sequence # to potential @@ -1561,6 +1577,11 @@ M_SEQNO_SET(m, seqno); } } else { + /* + * XXX TODO TX lock is needed for atomic updates of sequence + * numbers. If the driver does it, then don't do it here; + * and we don't need the TX lock held. + */ seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++; *(uint16_t *)wh->i_seq = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); @@ -2065,6 +2086,7 @@ * Send a probe request frame with the specified ssid * and any optional information element data. */ +/* XXX VHT? */ int ieee80211_send_probereq(struct ieee80211_node *ni, const uint8_t sa[IEEE80211_ADDR_LEN], @@ -2111,6 +2133,7 @@ * [tlv] RSN (optional) * [tlv] extended supported rates * [tlv] HT cap (optional) + * [tlv] VHT cap (optional) * [tlv] WPA (optional) * [tlv] user-specified ie's */ @@ -2119,7 +2142,8 @@ 2 + IEEE80211_NWID_LEN + 2 + IEEE80211_RATE_SIZE + sizeof(struct ieee80211_ie_htcap) - + sizeof(struct ieee80211_ie_htinfo) + + sizeof(struct ieee80211_ie_vhtcap) + + sizeof(struct ieee80211_ie_htinfo) /* XXX not needed? */ + sizeof(struct ieee80211_ie_wpa) + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + sizeof(struct ieee80211_ie_wpa) @@ -2159,6 +2183,21 @@ frm = ieee80211_add_htcap_ch(frm, vap, c); } + /* + * XXX TODO: need to figure out what/how to update the + * VHT channel. + */ +#if 0 + (vap->iv_flags_vht & IEEE80211_FVHT_VHT) { + struct ieee80211_channel *c; + + c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan, + vap->iv_flags_ht); + c = ieee80211_vht_adjust_channel(ic, c, vap->iv_flags_vht); + frm = ieee80211_add_vhtcap_ch(frm, vap, c); + } +#endif + frm = ieee80211_add_wpa(frm, vap); if (vap->iv_appie_probereq != NULL) frm = add_appie(frm, vap->iv_appie_probereq); @@ -2357,6 +2396,7 @@ case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: + /* XXX VHT? */ /* * asreq frame format * [2] capability information @@ -2368,6 +2408,7 @@ * [4] power capability (optional) * [28] supported channels (optional) * [tlv] HT capabilities + * [tlv] VHT capabilities * [tlv] WME (optional) * [tlv] Vendor OUI HT capabilities (optional) * [tlv] Atheros capabilities (if negotiated) @@ -2385,6 +2426,7 @@ + 2 + 26 + sizeof(struct ieee80211_wme_info) + sizeof(struct ieee80211_ie_htcap) + + sizeof(struct ieee80211_ie_vhtcap) + 4 + sizeof(struct ieee80211_ie_htcap) #ifdef IEEE80211_SUPPORT_SUPERG + sizeof(struct ieee80211_ath_ie) @@ -2449,6 +2491,14 @@ ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_HTCAP) { frm = ieee80211_add_htcap(frm, ni); } + + if ((vap->iv_flags_vht & IEEE80211_FVHT_VHT) && + IEEE80211_IS_CHAN_VHT(ni->ni_chan) && + ni->ni_ies.vhtcap_ie != NULL && + ni->ni_ies.vhtcap_ie[0] == IEEE80211_ELEMID_VHT_CAP) { + frm = ieee80211_add_vhtcap(frm, ni); + } + frm = ieee80211_add_wpa(frm, vap); if ((ic->ic_flags & IEEE80211_F_WME) && ni->ni_ies.wme_ie != NULL) @@ -2492,6 +2542,8 @@ * [tlv] extended supported rates * [tlv] HT capabilities (standard, if STA enabled) * [tlv] HT information (standard, if STA enabled) + * [tlv] VHT capabilities (standard, if STA enabled) + * [tlv] VHT information (standard, if STA enabled) * [tlv] WME (if configured and STA enabled) * [tlv] HT capabilities (vendor OUI, if STA enabled) * [tlv] HT information (vendor OUI, if STA enabled) @@ -2507,6 +2559,8 @@ + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + sizeof(struct ieee80211_ie_htcap) + 4 + sizeof(struct ieee80211_ie_htinfo) + 4 + + sizeof(struct ieee80211_ie_vhtcap) + + sizeof(struct ieee80211_ie_vht_operation) + sizeof(struct ieee80211_wme_param) #ifdef IEEE80211_SUPPORT_SUPERG + sizeof(struct ieee80211_ath_ie) @@ -2545,6 +2599,10 @@ frm = ieee80211_add_htcap_vendor(frm, ni); frm = ieee80211_add_htinfo_vendor(frm, ni); } + if (ni->ni_flags & IEEE80211_NODE_VHT) { + frm = ieee80211_add_vhtcap(frm, ni); + frm = ieee80211_add_vhtinfo(frm, ni); + } #ifdef IEEE80211_SUPPORT_SUPERG if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS)) frm = ieee80211_add_ath(frm, @@ -2600,6 +2658,7 @@ * Space is left to prepend and 802.11 header at the * front but it's left to the caller to fill in. */ +/* XXX VHT? */ struct mbuf * ieee80211_alloc_proberesp(struct ieee80211_node *bss, int legacy) { @@ -2934,6 +2993,7 @@ } } +/* XXX VHT? */ static void ieee80211_beacon_construct(struct mbuf *m, uint8_t *frm, struct ieee80211_node *ni) @@ -2946,6 +3006,10 @@ /* * beacon frame format + * + * TODO: update to 802.11-2012; a lot of stuff has changed; + * vendor extensions should be at the end, etc. + * * [8] time stamp * [2] beacon interval * [2] cabability information @@ -2957,11 +3021,34 @@ * [tlv] country (optional) * [3] power control (optional) * [5] channel switch announcement (CSA) (optional) + * XXX TODO: Quiet + * XXX TODO: IBSS DFS + * XXX TODO: TPC report * [tlv] extended rate phy (ERP) * [tlv] extended supported rates * [tlv] RSN parameters + * XXX TODO: BSSLOAD + * (XXX EDCA parameter set, QoS capability?) + * XXX TODO: AP channel report + * * [tlv] HT capabilities * [tlv] HT information + * XXX TODO: 20/40 BSS coexistence + * Mesh: + * XXX TODO: Meshid + * XXX TODO: mesh config + * XXX TODO: mesh awake window + * XXX TODO: beacon timing (mesh, etc) + * XXX TODO: MCCAOP Advertisement Overview + * XXX TODO: MCCAOP Advertisement + * XXX TODO: Mesh channel switch parameters + * VHT: + * XXX TODO: VHT capabilities + * XXX TODO: VHT operation + * XXX TODO: VHT transmit power envelope + * XXX TODO: channel switch wrapper element + * XXX TODO: extended BSS load element + * * XXX Vendor-specific OIDs (e.g. Atheros) * [tlv] WPA parameters * [tlv] WME parameters @@ -3055,6 +3142,16 @@ bo->bo_htinfo = frm; frm = ieee80211_add_htinfo(frm, ni); } + + if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) { + frm = ieee80211_add_vhtcap(frm, ni); + bo->bo_vhtinfo = frm; + frm = ieee80211_add_vhtinfo(frm, ni); + /* Transmit power envelope */ + /* Channel switch wrapper element */ + /* Extended bss load element */ + } + frm = ieee80211_add_wpa(frm, vap); if (vap->iv_flags & IEEE80211_F_WME) { bo->bo_wme = frm; @@ -3065,6 +3162,7 @@ frm = ieee80211_add_htcap_vendor(frm, ni); frm = ieee80211_add_htinfo_vendor(frm, ni); } + #ifdef IEEE80211_SUPPORT_SUPERG if (vap->iv_flags & IEEE80211_F_ATHEROS) { bo->bo_ath = frm; @@ -3082,6 +3180,8 @@ bo->bo_appie_len = vap->iv_appie_beacon->ie_len; frm = add_appie(frm, vap->iv_appie_beacon); } + + /* XXX TODO: move meshid/meshconf up to before vendor extensions? */ #ifdef IEEE80211_SUPPORT_MESH if (vap->iv_opmode == IEEE80211_M_MBSS) { frm = ieee80211_add_meshid(frm, vap); @@ -3097,6 +3197,7 @@ /* * Allocate a beacon frame and fillin the appropriate bits. */ +/* XXX VHT? */ struct mbuf * ieee80211_beacon_alloc(struct ieee80211_node *ni) { @@ -3110,6 +3211,9 @@ /* * beacon frame format + * + * Note: This needs updating for 802.11-2012. + * * [8] time stamp * [2] beacon interval * [2] cabability information @@ -3126,6 +3230,8 @@ * [tlv] RSN parameters * [tlv] HT capabilities * [tlv] HT information + * [tlv] VHT capabilities + * [tlv] VHT operation * [tlv] Vendor OUI HT capabilities (optional) * [tlv] Vendor OUI HT information (optional) * XXX Vendor-specific OIDs (e.g. Atheros) @@ -3138,6 +3244,7 @@ * NB: we allocate the max space required for the TIM bitmap. * XXX how big is this? */ + /* XXX VHT? */ pktlen = 8 /* time stamp */ + sizeof(uint16_t) /* beacon interval */ + sizeof(uint16_t) /* capabilities */ @@ -3157,6 +3264,8 @@ /* XXX conditional? */ + 4+2*sizeof(struct ieee80211_ie_htcap)/* HT caps */ + 4+2*sizeof(struct ieee80211_ie_htinfo)/* HT info */ + + sizeof(struct ieee80211_ie_vhtcap)/* VHT caps */ + + sizeof(struct ieee80211_ie_vht_operation)/* VHT info */ + (vap->iv_caps & IEEE80211_C_WME ? /* WME */ sizeof(struct ieee80211_wme_param) : 0) #ifdef IEEE80211_SUPPORT_SUPERG @@ -3242,6 +3351,15 @@ } wh = mtod(m, struct ieee80211_frame *); + + /* + * XXX TODO Strictly speaking this should be incremented with the TX + * lock held so as to serialise access to the non-qos TID sequence + * number space. + * + * If the driver identifies it does its own TX seqno management then + * we can skip this (and still not do the TX seqno.) + */ seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++; *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT); @@ -3347,6 +3465,10 @@ timoff = 0; timlen = 1; } + + /* + * TODO: validate this! + */ if (timlen != bo->bo_tim_len) { /* copy up/down trailer */ int adjust = tie->tim_bitmap+timlen @@ -3357,6 +3479,7 @@ bo->bo_tim_trailer += adjust; bo->bo_erp += adjust; bo->bo_htinfo += adjust; + bo->bo_vhtinfo += adjust; #ifdef IEEE80211_SUPPORT_SUPERG bo->bo_ath += adjust; #endif @@ -3411,6 +3534,7 @@ memmove(&csa[1], csa, bo->bo_csa_trailer_len); bo->bo_erp += sizeof(*csa); bo->bo_htinfo += sizeof(*csa); + bo->bo_vhtinfo += sizeof(*csa); bo->bo_wme += sizeof(*csa); #ifdef IEEE80211_SUPPORT_SUPERG bo->bo_ath += sizeof(*csa); Index: sys/net80211/ieee80211_proto.h =================================================================== --- sys/net80211/ieee80211_proto.h (revision 311042) +++ sys/net80211/ieee80211_proto.h (working copy) @@ -77,6 +77,7 @@ void ieee80211_allmulti(struct ieee80211vap *, bool); void ieee80211_syncflag(struct ieee80211vap *, int flag); void ieee80211_syncflag_ht(struct ieee80211vap *, int flag); +void ieee80211_syncflag_vht(struct ieee80211vap *, int flag); void ieee80211_syncflag_ext(struct ieee80211vap *, int flag); #define ieee80211_input(ni, m, rssi, nf) \ @@ -361,7 +362,8 @@ uint8_t *bo_csa; /* start of CSA element */ uint8_t *bo_quiet; /* start of Quiet element */ uint8_t *bo_meshconf; /* start of MESHCONF element */ - uint8_t *bo_spare[3]; + uint8_t *bo_vhtinfo; /* start of VHT info element (XXX VHTCAP?) */ + uint8_t *bo_spare[2]; }; struct mbuf *ieee80211_beacon_alloc(struct ieee80211_node *); Index: sys/net80211/ieee80211_scan.h =================================================================== --- sys/net80211/ieee80211_scan.h (revision 311042) +++ sys/net80211/ieee80211_scan.h (working copy) @@ -250,7 +250,9 @@ uint8_t *quiet; uint8_t *meshid; uint8_t *meshconf; - uint8_t *spare[3]; + uint8_t *vhtcap; + uint8_t *vhtopmode; + uint8_t *spare[1]; }; /* Index: sys/net80211/ieee80211_scan_sta.c =================================================================== --- sys/net80211/ieee80211_scan_sta.c (revision 311042) +++ sys/net80211/ieee80211_scan_sta.c (working copy) @@ -55,6 +55,7 @@ #include #endif #include +#include #include @@ -325,6 +326,19 @@ } } else ise->se_chan = curchan; + + /* VHT demotion */ + if (IEEE80211_IS_CHAN_VHT(ise->se_chan) && sp->vhtcap == NULL) { + printf("%s: demoting %d/0x%08x, sp->vhtcap==NULL\n", __func__, ise->se_chan->ic_freq, ise->se_chan->ic_flags); + /* Demote legacy networks to a non-VHT channel. */ + c = ieee80211_find_channel(ic, ise->se_chan->ic_freq, + ise->se_chan->ic_flags & ~IEEE80211_CHAN_VHT); + KASSERT(c != NULL, + ("no non-VHT channel %u", ise->se_chan->ic_ieee)); + ise->se_chan = c; + } + + /* HT demotion */ if (IEEE80211_IS_CHAN_HT(ise->se_chan) && sp->htcap == NULL) { /* Demote legacy networks to a non-HT channel. */ c = ieee80211_find_channel(ic, ise->se_chan->ic_freq, @@ -333,6 +347,7 @@ ("no legacy channel %u", ise->se_chan->ic_ieee)); ise->se_chan = c; } + ise->se_fhdwell = sp->fhdwell; ise->se_fhindex = sp->fhindex; ise->se_erp = sp->erp; @@ -531,10 +546,11 @@ /* * Ignore dynamic turbo channels; we scan them * in normal mode (i.e. not boosted). Likewise - * for HT channels, they get scanned using + * for HT/VHT channels, they get scanned using * legacy rates. */ - if (IEEE80211_IS_CHAN_DTURBO(c) || IEEE80211_IS_CHAN_HT(c)) + if (IEEE80211_IS_CHAN_DTURBO(c) || IEEE80211_IS_CHAN_HT(c) || + IEEE80211_IS_CHAN_VHT(c)) continue; /* @@ -819,6 +835,9 @@ * that we assume compatibility/usability has already been checked * so we don't need to (e.g. validate whether privacy is supported). * Used to select the best scan candidate for association in a BSS. + * + * TODO: should we take 11n, 11ac into account when selecting the + * best? Right now it just compares frequency band and RSSI. */ static int sta_compare(const struct sta_entry *a, const struct sta_entry *b) @@ -1626,6 +1645,8 @@ */ chan = ieee80211_ht_adjust_channel(ic, chan, vap->iv_flags_ht); + chan = ieee80211_vht_adjust_channel(ic, + chan, vap->iv_flags_vht); ieee80211_create_ibss(vap, chan); return 1; } @@ -1657,6 +1678,8 @@ */ chan = ieee80211_ht_adjust_channel(ic, chan, vap->iv_flags_ht); + chan = ieee80211_vht_adjust_channel(ic, + chan, vap->iv_flags_vht); if (!ieee80211_sta_join(vap, chan, &selbs->base)) goto notfound; return 1; /* terminate scan */ @@ -1776,7 +1799,7 @@ ap_end(struct ieee80211_scan_state *ss, struct ieee80211vap *vap) { struct ieee80211com *ic = vap->iv_ic; - struct ieee80211_channel *bestchan; + struct ieee80211_channel *bestchan, *chan; KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP, ("wrong opmode %u", vap->iv_opmode)); @@ -1808,8 +1831,10 @@ ss->ss_flags &= ~IEEE80211_SCAN_NOPICK; return 1; } - ieee80211_create_ibss(vap, - ieee80211_ht_adjust_channel(ic, bestchan, vap->iv_flags_ht)); + chan = ieee80211_ht_adjust_channel(ic, bestchan, vap->iv_flags_ht); + chan = ieee80211_vht_adjust_channel(ic, chan, vap->iv_flags_vht); + ieee80211_create_ibss(vap, chan); + return 1; } @@ -1881,10 +1906,14 @@ IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) { struct ieee80211com *ic = vap->iv_ic; + /* XXX VHT */ chan = adhoc_pick_channel(ss, 0); - if (chan != NULL) + if (chan != NULL) { chan = ieee80211_ht_adjust_channel(ic, chan, vap->iv_flags_ht); + chan = ieee80211_vht_adjust_channel(ic, + chan, vap->iv_flags_vht); + } } else chan = vap->iv_des_chan; if (chan != NULL) { Index: sys/net80211/ieee80211_sta.c =================================================================== --- sys/net80211/ieee80211_sta.c (revision 311042) +++ sys/net80211/ieee80211_sta.c (working copy) @@ -64,6 +64,7 @@ #endif #include #include +#include #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) @@ -1330,8 +1331,9 @@ struct ieee80211_frame *wh; uint8_t *frm, *efrm; uint8_t *rates, *xrates, *wme, *htcap, *htinfo; + uint8_t *vhtcap, *vhtopmode; uint8_t rate; - int ht_state_change = 0; + int ht_state_change = 0, do_ht = 0; wh = mtod(m0, struct ieee80211_frame *); frm = (uint8_t *)&wh[1]; @@ -1430,10 +1432,23 @@ if (scan.htcap != NULL && scan.htinfo != NULL && (vap->iv_flags_ht & IEEE80211_FHT_HT)) { /* XXX state changes? */ - if (ieee80211_ht_updateparams(ni, + ieee80211_ht_updateparams(ni, + scan.htcap, scan.htinfo); + do_ht = 1; + } + if (scan.vhtcap != NULL && scan.vhtopmode != NULL && + (vap->iv_flags_vht & IEEE80211_FVHT_VHT)) { + /* XXX state changes? */ + ieee80211_vht_updateparams(ni, + scan.vhtcap, scan.vhtopmode); + do_ht = 1; + } + if (do_ht) { + if (ieee80211_ht_updateparams_final(ni, scan.htcap, scan.htinfo)) ht_state_change = 1; } + if (scan.quiet) ic->ic_set_quiet(ni, scan.quiet); @@ -1660,6 +1675,7 @@ frm += 2; rates = xrates = wme = htcap = htinfo = NULL; + vhtcap = vhtopmode = NULL; while (efrm - frm > 1) { IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); switch (*frm) { @@ -1693,6 +1709,12 @@ } /* XXX Atheros OUI support */ break; + case IEEE80211_ELEMID_VHT_CAP: + vhtcap = frm; + break; + case IEEE80211_ELEMID_VHT_OPMODE: + vhtopmode = frm; + break; } frm += frm[1] + 2; } @@ -1740,6 +1762,16 @@ ieee80211_setup_htrates(ni, htcap, IEEE80211_F_JOIN | IEEE80211_F_DOBRS); ieee80211_setup_basic_htrates(ni, htinfo); + + if ((vhtcap != NULL) && (vhtopmode != NULL) & + (vap->iv_flags_vht & IEEE80211_FVHT_VHT)) { + ieee80211_vht_node_init(ni); + ieee80211_vht_updateparams(ni, vhtcap, vhtopmode); + ieee80211_setup_vht_rates(ni, vhtcap, vhtopmode); + } + + ieee80211_ht_updateparams_final(ni, htcap, htinfo); + ieee80211_node_setuptxparms(ni); ieee80211_ratectl_node_init(ni); } Index: sys/net80211/ieee80211_var.h =================================================================== --- sys/net80211/ieee80211_var.h (revision 311363) +++ sys/net80211/ieee80211_var.h (working copy) @@ -653,8 +653,12 @@ #define IEEE80211_FVEN_BITS "\20" #define IEEE80211_FVHT_VHT 0x000000001 /* CONF: VHT supported */ +#define IEEE80211_FVHT_USEVHT40 0x000000002 /* CONF: Use VHT40 */ +#define IEEE80211_FVHT_USEVHT80 0x000000004 /* CONF: Use VHT80 */ +#define IEEE80211_FVHT_USEVHT80P80 0x000000008 /* CONF: Use VHT 80+80 */ +#define IEEE80211_FVHT_USEVHT160 0x000000010 /* CONF: Use VHT160 */ #define IEEE80211_VFHT_BITS \ - "\20\1VHT" + "\20\1VHT\2VHT40\3VHT80\4VHT80P80\5VHT160" int ic_printf(struct ieee80211com *, const char *, ...) __printflike(2, 3); void ieee80211_ifattach(struct ieee80211com *); @@ -830,6 +834,27 @@ } /* + * Calculate VHT channel promotion flags for a channel. + * XXX belongs in ieee80211_ht.h but needs IEEE80211_FHT_* + */ +static __inline int +ieee80211_vhtchanflags(const struct ieee80211_channel *c) +{ + + if (IEEE80211_IS_CHAN_VHT160(c)) + return IEEE80211_FVHT_USEVHT160; + if (IEEE80211_IS_CHAN_VHT80_80(c)) + return IEEE80211_FVHT_USEVHT80P80; + if (IEEE80211_IS_CHAN_VHT80(c)) + return IEEE80211_FVHT_USEVHT80; + if (IEEE80211_IS_CHAN_VHT40(c)) + return IEEE80211_FVHT_USEVHT40; + if (IEEE80211_IS_CHAN_VHT(c)) + return IEEE80211_FVHT_VHT; + return (0); +} + +/* * Fetch the current TX power (cap) for the given node. * * This includes the node and ic/vap TX power limit as needed, Index: sys/net80211/ieee80211_vht.c =================================================================== --- sys/net80211/ieee80211_vht.c (nonexistent) +++ sys/net80211/ieee80211_vht.c (working copy) @@ -0,0 +1,406 @@ +/*- + * Copyright (c) 2016 Adrian Chadd + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifdef __FreeBSD__ +__FBSDID("$FreeBSD$"); +#endif + +/* + * IEEE 802.11ac-2013 protocol support. + */ + +#include "opt_inet.h" +#include "opt_wlan.h" + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +/* define here, used throughout file */ +#define MS(_v, _f) (((_v) & _f) >> _f##_S) +#define SM(_v, _f) (((_v) << _f##_S) & _f) + +#define ADDSHORT(frm, v) do { \ + frm[0] = (v) & 0xff; \ + frm[1] = (v) >> 8; \ + frm += 2; \ +} while (0) +#define ADDWORD(frm, v) do { \ + frm[0] = (v) & 0xff; \ + frm[1] = ((v) >> 8) & 0xff; \ + frm[2] = ((v) >> 16) & 0xff; \ + frm[3] = ((v) >> 24) & 0xff; \ + frm += 4; \ +} while (0) + +static void +ieee80211_vht_init(void) +{ +} + +SYSINIT(wlan_vht, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_vht_init, NULL); + +void +ieee80211_vht_attach(struct ieee80211com *ic) +{ +} + +void +ieee80211_vht_detach(struct ieee80211com *ic) +{ +} + +void +ieee80211_vht_vattach(struct ieee80211vap *vap) +{ + struct ieee80211com *ic = vap->iv_ic; + + /* XXX TODO: vht support flag */ + if (ic->ic_vhtcaps == 0) + return; + + vap->iv_vhtcaps = ic->ic_vhtcaps; + vap->iv_vhtextcaps = ic->ic_vhtextcaps; + + /* XXX assumes VHT80 support; should really check vhtcaps */ + vap->iv_flags_vht = + IEEE80211_FVHT_VHT + | IEEE80211_FVHT_USEVHT40 + | IEEE80211_FVHT_USEVHT80; + /* XXX TODO: enable VHT80, VHT160 capabilities */ + + memcpy(&vap->iv_vht_mcsinfo, &ic->ic_vht_mcsinfo, + sizeof(struct ieee80211_vht_mcs_info)); +} + +void +ieee80211_vht_vdetach(struct ieee80211vap *vap) +{ +} + +#if 0 +static void +vht_announce(struct ieee80211com *ic, enum ieee80211_phymode mode) +{ +} +#endif + +void +ieee80211_vht_announce(struct ieee80211com *ic) +{ + /* XXX TODO */ +} + +void +ieee80211_vht_node_init(struct ieee80211_node *ni) +{ + + printf("%s: called\n", __func__); + ni->ni_flags |= IEEE80211_NODE_VHT; +} + +void +ieee80211_vht_node_cleanup(struct ieee80211_node *ni) +{ + + printf("%s: called\n", __func__); + ni->ni_flags &= ~IEEE80211_NODE_VHT; + ni->ni_vhtcap = 0; + bzero(&ni->ni_vht_mcsinfo, sizeof(struct ieee80211_vht_mcs_info)); +} + +/* + * Parse an 802.11ac VHT operation IE. + */ +void +ieee80211_parse_vhtopmode(struct ieee80211_node *ni, const uint8_t *ie) +{ + /* vht operation */ + ni->ni_vht_chanwidth = ie[2]; + ni->ni_vht_chan1 = ie[3]; + ni->ni_vht_chan2 = ie[4]; + ni->ni_vht_basicmcs = le16dec(ie + 5); + +#if 0 + printf("%s: chan1=%d, chan2=%d, chanwidth=%d, basicmcs=0x%04x\n", + __func__, + ni->ni_vht_chan1, + ni->ni_vht_chan2, + ni->ni_vht_chanwidth, + ni->ni_vht_basicmcs); +#endif +} + +/* + * Parse an 802.11ac VHT capability IE. + */ +void +ieee80211_parse_vhtcap(struct ieee80211_node *ni, const uint8_t *ie) +{ + + /* vht capability */ + ni->ni_vhtcap = le32dec(ie + 2); + + /* suppmcs */ + ni->ni_vht_mcsinfo.rx_mcs_map = le16dec(ie + 6); + ni->ni_vht_mcsinfo.rx_highest = le16dec(ie + 8); + ni->ni_vht_mcsinfo.tx_mcs_map = le16dec(ie + 10); + ni->ni_vht_mcsinfo.tx_highest = le16dec(ie + 12); +} + +int +ieee80211_vht_updateparams(struct ieee80211_node *ni, + const uint8_t *vhtcap_ie, + const uint8_t *vhtop_ie) +{ + + //printf("%s: called\n", __func__); + + ieee80211_parse_vhtcap(ni, vhtcap_ie); + ieee80211_parse_vhtopmode(ni, vhtop_ie); + return (0); +} + +void +ieee80211_setup_vht_rates(struct ieee80211_node *ni, + const uint8_t *vhtcap_ie, + const uint8_t *vhtop_ie) +{ + + //printf("%s: called\n", __func__); + /* XXX TODO */ +} + +void +ieee80211_vht_timeout(struct ieee80211com *ic) +{ +} + +void +ieee80211_vht_node_join(struct ieee80211_node *ni) +{ + + printf("%s: called\n", __func__); +} + +void +ieee80211_vht_node_leave(struct ieee80211_node *ni) +{ + + printf("%s: called\n", __func__); +} + +uint8_t * +ieee80211_add_vhtcap(uint8_t *frm, struct ieee80211_node *ni) +{ + uint32_t cap; + + memset(frm, '\0', sizeof(struct ieee80211_ie_vhtcap)); + + frm[0] = IEEE80211_ELEMID_VHT_CAP; + frm[1] = sizeof(struct ieee80211_ie_vhtcap) - 2; + frm += 2; + + /* + * For now, don't do any configuration. + * Just populate the node configuration. + * We can worry about making it configurable later. + */ + + cap = ni->ni_vhtcap; + + /* + * XXX TODO: any capability changes required by + * configuration. + */ + + /* 32-bit VHT capability */ + ADDWORD(frm, cap); + + /* suppmcs */ + ADDSHORT(frm, ni->ni_vht_mcsinfo.rx_mcs_map); + ADDSHORT(frm, ni->ni_vht_mcsinfo.rx_highest); + ADDSHORT(frm, ni->ni_vht_mcsinfo.tx_mcs_map); + ADDSHORT(frm, ni->ni_vht_mcsinfo.tx_highest); + + return (frm); +} + +static uint8_t +ieee80211_vht_get_chwidth_ie(struct ieee80211_channel *c) +{ + + /* + * XXX TODO: look at the node configuration as + * well? + */ + + if (IEEE80211_IS_CHAN_VHT160(c)) { + return IEEE80211_VHT_CHANWIDTH_160MHZ; + } + if (IEEE80211_IS_CHAN_VHT80_80(c)) { + return IEEE80211_VHT_CHANWIDTH_80P80MHZ; + } + if (IEEE80211_IS_CHAN_VHT80(c)) { + return IEEE80211_VHT_CHANWIDTH_80MHZ; + } + if (IEEE80211_IS_CHAN_VHT40(c)) { + return IEEE80211_VHT_CHANWIDTH_USE_HT; + } + if (IEEE80211_IS_CHAN_VHT20(c)) { + return IEEE80211_VHT_CHANWIDTH_USE_HT; + } + + /* We shouldn't get here */ + printf("%s: called on a non-VHT channel (freq=%d, flags=0x%08x\n", + __func__, + (int) c->ic_freq, + c->ic_flags); + return IEEE80211_VHT_CHANWIDTH_USE_HT; +} + +/* + * Note: this just uses the current channel information; + * it doesn't use the node info after parsing. + */ +uint8_t * +ieee80211_add_vhtinfo(uint8_t *frm, struct ieee80211_node *ni) +{ + memset(frm, '\0', sizeof(struct ieee80211_ie_vht_operation)); + + frm[0] = IEEE80211_ELEMID_VHT_OPMODE; + frm[1] = sizeof(struct ieee80211_ie_vht_operation) - 2; + frm += 2; + + /* + * XXX if it's a station, then see if we have a node + * channel or ANYC. If it's ANYC then assume we're + * scanning, and announce our capabilities. + * + * This should set the "20/40/80/160MHz wide config"; + * the 80/80 or 160MHz wide config is done in VHTCAP. + * + * Other modes - just limit it to the channel. + */ + + /* 8-bit chanwidth */ + *frm++ = ieee80211_vht_get_chwidth_ie(ni->ni_chan); + + /* 8-bit freq1 */ + *frm++ = ni->ni_chan->ic_vht_ch_freq1; + + /* 8-bit freq2 */ + *frm++ = ni->ni_chan->ic_vht_ch_freq1; + + /* 16-bit basic MCS set - just MCS0..7 for NSS=1 for now */ + ADDSHORT(frm, 0xfffc); + + return (frm); +} + +void +ieee80211_vht_update_cap(struct ieee80211_node *ni, const uint8_t *vhtcap_ie, + const uint8_t *vhtop_ie) +{ + + ieee80211_parse_vhtcap(ni, vhtcap_ie); + ieee80211_parse_vhtopmode(ni, vhtop_ie); +} + +static struct ieee80211_channel * +findvhtchan(struct ieee80211com *ic, struct ieee80211_channel *c, int vhtflags) +{ + + return (ieee80211_find_channel(ic, c->ic_freq, + (c->ic_flags & ~IEEE80211_CHAN_VHT) | vhtflags)); +} + +/* + * Handle channel promotion to VHT, similar to ieee80211_ht_adjust_channel(). + */ +struct ieee80211_channel * +ieee80211_vht_adjust_channel(struct ieee80211com *ic, + struct ieee80211_channel *chan, int flags) +{ + struct ieee80211_channel *c; + + /* First case - handle channel demotion */ + if (flags == 0) { + printf("%s: demoting channel %d/0x%08x\n", __func__, + chan->ic_ieee, chan->ic_flags); + c = ieee80211_find_channel(ic, chan->ic_freq, + chan->ic_flags & ~IEEE80211_CHAN_VHT); + if (c == NULL) + c = chan; + printf("%s: .. to %d/0x%08x\n", __func__, + c->ic_ieee, c->ic_flags); + return (c); + } + + /* + * We can upgrade to VHT - attempt to do so + * + * Note: we don't clear the HT flags, these are the hints + * for HT40U/HT40D when selecting VHT40 or larger channels. + */ + /* Start with VHT80 */ + c = NULL; + if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT160)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80); + + if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80P80)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80_80); + + if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT80)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT80); + + if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40U); + if ((c == NULL) && (flags & IEEE80211_FVHT_USEVHT40)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT40D); + if ((c == NULL) && (flags & IEEE80211_FVHT_VHT)) + c = findvhtchan(ic, chan, IEEE80211_CHAN_VHT20); + + if (c != NULL) + chan = c; + + printf("%s: selected %d/0x%08x\n", __func__, c->ic_ieee, c->ic_flags); + return (chan); +} Property changes on: sys/net80211/ieee80211_vht.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: sys/net80211/ieee80211_vht.h =================================================================== --- sys/net80211/ieee80211_vht.h (nonexistent) +++ sys/net80211/ieee80211_vht.h (working copy) @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2016 Adrian Chadd + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#ifndef _NET80211_IEEE80211_VHT_H_ +#define _NET80211_IEEE80211_VHT_H_ + +void ieee80211_vht_attach(struct ieee80211com *); +void ieee80211_vht_detach(struct ieee80211com *); +void ieee80211_vht_vattach(struct ieee80211vap *); +void ieee80211_vht_vdetach(struct ieee80211vap *); + +void ieee80211_vht_announce(struct ieee80211com *); + +void ieee80211_vht_node_init(struct ieee80211_node *); +void ieee80211_vht_node_cleanup(struct ieee80211_node *); + +void ieee80211_parse_vhtopmode(struct ieee80211_node *, const uint8_t *); +void ieee80211_parse_vhtcap(struct ieee80211_node *, const uint8_t *); + +int ieee80211_vht_updateparams(struct ieee80211_node *, + const uint8_t *, const uint8_t *); +void ieee80211_setup_vht_rates(struct ieee80211_node *, + const uint8_t *, const uint8_t *); + +void ieee80211_vht_timeout(struct ieee80211com *ic); + +void ieee80211_vht_node_join(struct ieee80211_node *ni); +void ieee80211_vht_node_leave(struct ieee80211_node *ni); + +uint8_t * ieee80211_add_vhtcap(uint8_t *frm, struct ieee80211_node *); +uint8_t * ieee80211_add_vhtinfo(uint8_t *frm, struct ieee80211_node *); + +void ieee80211_vht_update_cap(struct ieee80211_node *, + const uint8_t *, const uint8_t *); + +struct ieee80211_channel * + ieee80211_vht_adjust_channel(struct ieee80211com *, + struct ieee80211_channel *, int); + +#endif /* _NET80211_IEEE80211_VHT_H_ */ Property changes on: sys/net80211/ieee80211_vht.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: sbin/ifconfig/ifieee80211.c =================================================================== --- sbin/ifconfig/ifieee80211.c (revision 311042) +++ sbin/ifconfig/ifieee80211.c (working copy) @@ -119,6 +119,7 @@ #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ +#define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */ #endif #define MAXCHAN 1536 /* max 1.5K channels */ @@ -143,7 +144,9 @@ [IEEE80211_MODE_11NA] = "11na", [IEEE80211_MODE_11NG] = "11ng", [IEEE80211_MODE_HALF] = "half", - [IEEE80211_MODE_QUARTER] = "quarter" + [IEEE80211_MODE_QUARTER] = "quarter", + [IEEE80211_MODE_VHT_2GHZ] = "11ac2", + [IEEE80211_MODE_VHT_5GHZ] = "11ac", }; static void set80211(int s, int type, int val, int len, void *data); @@ -183,6 +186,20 @@ gothtconf = 1; } +/* VHT */ +static int vhtconf = 0; +static int gotvhtconf = 0; + +static void +getvhtconf(int s) +{ + if (gotvhtconf) + return; + if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) + warn("unable to get VHT configuration information"); + gotvhtconf = 1; +} + /* * Collect channel info from the kernel. We use this (mostly) * to handle mapping between frequency and IEEE channel number. @@ -200,6 +217,7 @@ err(1, "unable to get channel information"); ifmr = ifmedia_getstate(s); gethtconf(s); + getvhtconf(s); } static struct regdata * @@ -221,6 +239,9 @@ * allows the caller to look for promotion; e.g. from * 11b > 11g. */ +/* + * XXX VHT + */ static int canpromote(int i, int from, int to) { @@ -255,6 +276,9 @@ * channe list (e.g. mode 11a); we want to honor that to avoid * confusing behaviour. */ +/* + * XXX VHT + */ static int promote(int i) { @@ -361,6 +385,10 @@ static enum ieee80211_phymode chan2mode(const struct ieee80211_channel *c) { + if (IEEE80211_IS_CHAN_VHTA(c)) + return IEEE80211_MODE_VHT_5GHZ; + if (IEEE80211_IS_CHAN_VHTG(c)) + return IEEE80211_MODE_VHT_2GHZ; if (IEEE80211_IS_CHAN_HTA(c)) return IEEE80211_MODE_11NA; if (IEEE80211_IS_CHAN_HTG(c)) @@ -502,9 +530,12 @@ printf("drivercaps: 0x%x\n", dc->dc_drivercaps); printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps); printf("htcaps : 0x%x\n", dc->dc_htcaps); + printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps); +#if 0 memcpy(chaninfo, &dc->dc_chaninfo, IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/); +#endif } #endif req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans)); @@ -610,6 +641,9 @@ * The result is not validated here; it's assumed to be * checked against the channel table fetched from the kernel. */ +/* + * XXX VHT + */ static int getchannelflags(const char *val, int freq) { @@ -616,6 +650,7 @@ #define _CHAN_HT 0x80000000 const char *cp; int flags; + int is_vht = 0; flags = 0; @@ -636,6 +671,9 @@ case 'g': /* 802.11g */ flags |= IEEE80211_CHAN_G; break; + case 'v': + is_vht = 1; + /* Fallthrough */ case 'h': /* ht = 802.11n */ case 'n': /* 802.11n */ flags |= _CHAN_HT; /* NB: private */ @@ -674,6 +712,15 @@ flags |= IEEE80211_CHAN_HT20; break; case 40: + case 80: + case 160: + /* Handle the 80/160 VHT flag */ + if (cw == 80) + flags |= IEEE80211_CHAN_VHT80; + else if (cw == 160) + flags |= IEEE80211_CHAN_VHT160; + + /* Fallthrough */ if (ep != NULL && *ep == '+') flags |= IEEE80211_CHAN_HT40U; else if (ep != NULL && *ep == '-') @@ -683,6 +730,7 @@ errx(-1, "%s: Invalid channel width\n", val); } } + /* * Cleanup specifications. */ @@ -695,6 +743,7 @@ * are also usable for legacy operation; e.g. freq:n/40. */ flags &= ~IEEE80211_CHAN_HT; + flags &= ~IEEE80211_CHAN_VHT; } else { /* * Remove private indicator that this is an HT channel @@ -714,6 +763,25 @@ mapchan(&chan, freq, 0); flags |= (chan.ic_flags & IEEE80211_CHAN_HT); } + + /* + * If VHT is enabled, then also set the VHT flag and the + * relevant channel up/down. + */ + if (is_vht && (flags & IEEE80211_CHAN_HT)) { + /* + * XXX yes, maybe we should just have VHT, and reuse + * HT20/HT40U/HT40D + */ + if (flags & IEEE80211_CHAN_VHT80) + ; + else if (flags & IEEE80211_CHAN_HT20) + flags |= IEEE80211_CHAN_VHT20; + else if (flags & IEEE80211_CHAN_HT40U) + flags |= IEEE80211_CHAN_VHT40U; + else if (flags & IEEE80211_CHAN_HT40D) + flags |= IEEE80211_CHAN_VHT40D; + } } return flags; #undef _CHAN_HT @@ -1447,6 +1515,10 @@ case 'q': /* 1/4-width channels */ flags |= IEEE80211_CHAN_QUARTER; break; + case 'v': + /* XXX set HT too? */ + flags |= IEEE80211_CHAN_VHT; + break; default: errx(-1, "%s: Invalid mode attribute %c\n", val, *cp); @@ -1456,6 +1528,7 @@ return flags; } +/* XXX VHT */ #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ) #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ) @@ -1863,6 +1936,21 @@ set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL); } +static void +set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp) +{ + if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) + errx(-1, "cannot set VHT setting"); + printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d); + if (d < 0) { + d = -d; + vhtconf &= ~d; + } else + vhtconf |= d; + printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf); + set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL); +} + static DECL_CMD_FUNC(set80211tdmaslot, val, d) { @@ -1975,6 +2063,7 @@ /* * Check channel compatibility. */ +/* XXX VHT */ static int checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags) { @@ -2019,6 +2108,7 @@ } } +/* XXX VHT */ static void regdomain_addchans(struct ieee80211req_chaninfo *ci, const netband_head *bands, @@ -2035,6 +2125,7 @@ hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0; lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0; channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40; + LIST_FOREACH(nb, bands, next) { b = nb->band; if (verbose) { @@ -2045,6 +2136,9 @@ putchar('\n'); } prev = NULL; + + /* XXX TODO: yes, take VHT80, VHT80+80, VHT160 into account */ + for (freq = b->freqStart + lo_adj; freq <= b->freqEnd + hi_adj; freq += b->chanSep) { /* @@ -2055,6 +2149,38 @@ * then constrained according by channel separation. */ flags = nb->flags | b->flags; + + /* + * VHT first - HT is a subset. + */ + if (flags & IEEE80211_CHAN_VHT) { + if ((chanFlags & IEEE80211_CHAN_VHT20) && + (flags & IEEE80211_CHAN_VHT20) == 0) { + if (verbose) + printf("%u: skip, not a " + "VHT20 channel\n", freq); + continue; + } + if ((chanFlags & IEEE80211_CHAN_VHT40) && + (flags & IEEE80211_CHAN_VHT40) == 0) { + if (verbose) + printf("%u: skip, not a " + "VHT40 channel\n", freq); + continue; + } + if ((chanFlags & IEEE80211_CHAN_VHT80) && + (flags & IEEE80211_CHAN_VHT80) == 0) { + if (verbose) + printf("%u: skip, not a " + "VHT80 channel\n", freq); + continue; + } + + flags &= ~IEEE80211_CHAN_VHT; + flags |= chanFlags & IEEE80211_CHAN_VHT; + } + + /* Now, constrain HT */ if (flags & IEEE80211_CHAN_HT) { /* * HT channels are generated specially; we're @@ -2127,7 +2253,7 @@ memset(c, 0, sizeof(*c)); c->ic_freq = freq; c->ic_flags = flags; - if (c->ic_flags & IEEE80211_CHAN_DFS) + if (c->ic_flags & IEEE80211_CHAN_DFS) c->ic_maxregpower = nb->maxPowerDFS; else c->ic_maxregpower = nb->maxPower; @@ -2204,6 +2330,38 @@ &dc->dc_chaninfo); } } + if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) { + regdomain_addchans(ci, &rd->bands_11ac, reg, + IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 | + IEEE80211_CHAN_VHT20, + &dc->dc_chaninfo); + + /* VHT40 is a function of HT40.. */ + if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { + regdomain_addchans(ci, &rd->bands_11ac, reg, + IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | + IEEE80211_CHAN_VHT40U, + &dc->dc_chaninfo); + regdomain_addchans(ci, &rd->bands_11ac, reg, + IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | + IEEE80211_CHAN_VHT40D, + &dc->dc_chaninfo); + } + + /* VHT80 */ + /* XXX dc_vhtcap? */ + if (1) { + regdomain_addchans(ci, &rd->bands_11ac, reg, + IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | + IEEE80211_CHAN_VHT80, + &dc->dc_chaninfo); + regdomain_addchans(ci, &rd->bands_11ac, reg, + IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | + IEEE80211_CHAN_VHT80, + &dc->dc_chaninfo); + } + } + if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) { regdomain_addchans(ci, &rd->bands_11ng, reg, IEEE80211_CHAN_G | IEEE80211_CHAN_HT20, @@ -2435,6 +2593,8 @@ if (flags & IEEE80211_NODE_HTCOMPAT) *cp++ = '+'; } + if (flags & IEEE80211_NODE_VHT) + *cp++ = 'V'; if (flags & IEEE80211_NODE_WPS) *cp++ = 'W'; if (flags & IEEE80211_NODE_TSN) @@ -3574,7 +3734,22 @@ if (IEEE80211_IS_CHAN_TURBO(c)) strlcat(buf, " Turbo", bsize); if (precise) { - if (IEEE80211_IS_CHAN_HT20(c)) + /* XXX should make VHT80U, VHT80D */ + if (IEEE80211_IS_CHAN_VHT80(c) && + IEEE80211_IS_CHAN_HT40D(c)) + strlcat(buf, " vht/80-", bsize); + else if (IEEE80211_IS_CHAN_VHT80(c) && + IEEE80211_IS_CHAN_HT40U(c)) + strlcat(buf, " vht/80+", bsize); + else if (IEEE80211_IS_CHAN_VHT80(c)) + strlcat(buf, " vht/80", bsize); + else if (IEEE80211_IS_CHAN_VHT40D(c)) + strlcat(buf, " vht/40-", bsize); + else if (IEEE80211_IS_CHAN_VHT40U(c)) + strlcat(buf, " vht/40+", bsize); + else if (IEEE80211_IS_CHAN_VHT20(c)) + strlcat(buf, " vht/20", bsize); + else if (IEEE80211_IS_CHAN_HT20(c)) strlcat(buf, " ht/20", bsize); else if (IEEE80211_IS_CHAN_HT40D(c)) strlcat(buf, " ht/40-", bsize); @@ -3581,7 +3756,9 @@ else if (IEEE80211_IS_CHAN_HT40U(c)) strlcat(buf, " ht/40+", bsize); } else { - if (IEEE80211_IS_CHAN_HT(c)) + if (IEEE80211_IS_CHAN_VHT(c)) + strlcat(buf, " vht", bsize); + else if (IEEE80211_IS_CHAN_HT(c)) strlcat(buf, " ht", bsize); } return buf; @@ -3612,6 +3789,12 @@ static int chanpref(const struct ieee80211_channel *c) { + if (IEEE80211_IS_CHAN_VHT80(c)) + return 70; + if (IEEE80211_IS_CHAN_VHT40(c)) + return 60; + if (IEEE80211_IS_CHAN_VHT20(c)) + return 50; if (IEEE80211_IS_CHAN_HT40(c)) return 40; if (IEEE80211_IS_CHAN_HT20(c)) @@ -3807,6 +3990,11 @@ putchar('\n'); printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS); } + if (dc->dc_vhtcaps != 0 || verbose) { + putchar('\n'); + printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS); + } + putchar('\n'); if (verbose) { chaninfo = &dc->dc_chaninfo; /* XXX */ @@ -4847,6 +5035,30 @@ } } + if (IEEE80211_IS_CHAN_VHT(c) || verbose) { + getvhtconf(s); + if (vhtconf & 0x1) + LINE_CHECK("vht"); + else + LINE_CHECK("-vht"); + if (vhtconf & 0x2) + LINE_CHECK("vht40"); + else + LINE_CHECK("-vht40"); + if (vhtconf & 0x4) + LINE_CHECK("vht80"); + else + LINE_CHECK("-vht80"); + if (vhtconf & 0x8) + LINE_CHECK("vht80p80"); + else + LINE_CHECK("-vht80p80"); + if (vhtconf & 0x10) + LINE_CHECK("vht160"); + else + LINE_CHECK("-vht160"); + } + if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) { if (wme) LINE_CHECK("wme"); @@ -5426,6 +5638,16 @@ DEF_CMD("-ht40", 0, set80211htconf), DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */ DEF_CMD("-ht", 0, set80211htconf), + DEF_CMD("vht", 1, set80211vhtconf), + DEF_CMD("-vht", 0, set80211vhtconf), + DEF_CMD("vht40", 2, set80211vhtconf), + DEF_CMD("-vht40", -2, set80211vhtconf), + DEF_CMD("vht80", 4, set80211vhtconf), + DEF_CMD("-vht80", -4, set80211vhtconf), + DEF_CMD("vht80p80", 8, set80211vhtconf), + DEF_CMD("-vht80p80", -8, set80211vhtconf), + DEF_CMD("vht160", 16, set80211vhtconf), + DEF_CMD("-vht160", -16, set80211vhtconf), DEF_CMD("rifs", 1, set80211rifs), DEF_CMD("-rifs", 0, set80211rifs), DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps), Index: etc/regdomain.xml =================================================================== --- etc/regdomain.xml (revision 311042) +++ etc/regdomain.xml (working copy) @@ -111,6 +111,47 @@ IEEE80211_CHAN_HT40 + + + + + 17 + IEEE80211_CHAN_HT20 + IEEE80211_CHAN_VHT20 + + + + 17 + IEEE80211_CHAN_HT40 + IEEE80211_CHAN_VHT40 + + + + 17 + IEEE80211_CHAN_HT40 + IEEE80211_CHAN_VHT80 + + + + 17 + IEEE80211_CHAN_HT20 + IEEE80211_CHAN_VHT20 + + + + 17 + IEEE80211_CHAN_HT40 + IEEE80211_CHAN_VHT40 + + + + 17 + IEEE80211_CHAN_HT40 + IEEE80211_CHAN_VHT80 + + @@ -1735,6 +1776,21 @@ 20 20 IEEE80211_CHAN_A + + 5180 5240 + 20 20 + IEEE80211_CHAN_A + + + 5180 5240 + 40 20 + IEEE80211_CHAN_A + + + 5180 5240 + 80 20 + IEEE80211_CHAN_A + 5180 5240 40 20 @@ -1825,6 +1881,21 @@ 20 20 IEEE80211_CHAN_A + + 5745 5805 + 20 20 + IEEE80211_CHAN_A + + + 5745 5805 + 40 20 + IEEE80211_CHAN_A + + + 5745 5805 + 80 20 + IEEE80211_CHAN_A + 5745 5805 40 20 Index: lib/lib80211/lib80211_regdomain.c =================================================================== --- lib/lib80211/lib80211_regdomain.c (revision 311042) +++ lib/lib80211/lib80211_regdomain.c (working copy) @@ -123,6 +123,8 @@ mt->curband = &mt->rd->bands_11ng; else if (iseq(mode, "11na")) mt->curband = &mt->rd->bands_11na; + else if (iseq(mode, "11ac")) + mt->curband = &mt->rd->bands_11ac; else warnx("unknown mode \"%s\" at line %ld", __DECONST(char *, mode), @@ -184,6 +186,9 @@ FLAG(IEEE80211_CHAN_G), FLAG(IEEE80211_CHAN_HT20), FLAG(IEEE80211_CHAN_HT40), + FLAG(IEEE80211_CHAN_VHT20), + FLAG(IEEE80211_CHAN_VHT40), + FLAG(IEEE80211_CHAN_VHT80), FLAG(IEEE80211_CHAN_ST), FLAG(IEEE80211_CHAN_TURBO), FLAG(IEEE80211_CHAN_PASSIVE), @@ -515,6 +520,15 @@ } nb->band = id; } + LIST_FOREACH(nb, &dp->bands_11ac, next) { + id = findid(rdp, nb->band, FREQBAND); + if (id == NULL) { + warnx("undefined 11ac band \"%s\"", + __DECONST(char *, nb->band)); + errors++; + } + nb->band = id; + } } LIST_FOREACH(cp, &rdp->countries, next) { id = cp->rd; @@ -562,6 +576,7 @@ cleanup_bands(&dp->bands_11a); cleanup_bands(&dp->bands_11ng); cleanup_bands(&dp->bands_11na); + cleanup_bands(&dp->bands_11ac); if (dp->name != NULL) free(__DECONST(char *, dp->name)); } Index: lib/lib80211/lib80211_regdomain.h =================================================================== --- lib/lib80211/lib80211_regdomain.h (revision 311042) +++ lib/lib80211/lib80211_regdomain.h (working copy) @@ -75,6 +75,7 @@ netband_head bands_11a; /* 11a operation */ netband_head bands_11ng;/* 11ng operation */ netband_head bands_11na;/* 11na operation */ + netband_head bands_11ac;/* 11ac 5GHz operation */ LIST_ENTRY(regdomain) next; };