diff --git a/sys/net80211/ieee80211_phy.h b/sys/net80211/ieee80211_phy.h --- a/sys/net80211/ieee80211_phy.h +++ b/sys/net80211/ieee80211_phy.h @@ -227,6 +227,8 @@ uint8_t); bool ieee80211_phy_vht_validate_mcs(enum ieee80211_sta_rx_bw, uint8_t, uint8_t); +uint32_t ieee80211_phy_vht_get_mcs_kbit(enum ieee80211_sta_rx_bw, + uint8_t, uint8_t, bool); #endif /* _KERNEL */ #endif /* !_NET80211_IEEE80211_PHY_H_ */ diff --git a/sys/net80211/ieee80211_phy.c b/sys/net80211/ieee80211_phy.c --- a/sys/net80211/ieee80211_phy.c +++ b/sys/net80211/ieee80211_phy.c @@ -707,3 +707,73 @@ return ((mask & (1 << mcs)) != 0); } + +struct mcs_entry { + int n_sym; /* Number of bits per symbol */ + int cod_n; /* Coding rate numerator */ + int cod_d; /* Coding rate denominator */ +}; + +static struct mcs_entry mcs_entries[] = { + { 1, 1, 2 }, /* MCS0 */ + { 2, 1, 2 }, + { 2, 3, 4 }, + { 4, 1, 2 }, + { 4, 3, 4 }, + { 6, 2, 3 }, + { 6, 3, 4 }, + { 6, 5, 6 }, + { 8, 3, 4 }, + { 8, 5, 6 }, /* MCS9 */ +}; + +/** + * @brief Calculate the bitrate of the given VHT MCS rate. + * + * @param bw Channel bandwidth (enum ieee80211_sta_rx_bw) + * @param nss Number of spatial streams, 1..8 + * @param mcs MCS, 0..9 + * @param is_shortgi True if short guard-interval (400nS) + * false otherwise (800nS) + * + * @returns The bitrate in kbit/sec. + */ +uint32_t +ieee80211_phy_vht_get_mcs_kbit(enum ieee80211_sta_rx_bw bw, + uint8_t nss, uint8_t mcs, bool is_shortgi) +{ + uint32_t sym_len, n_carriers; + + /* Validate MCS 0..9, NSS 1..8 */ + if (mcs > 9) + return (0); + if (nss == 0 || nss > 8) + return (0); + + /* Short-GI - 3.6uS symbol time, long-GI - 4.0uS symbol time */ + if (is_shortgi) + sym_len = 36; + else + sym_len = 40; + + /* Calculate the number of carriers for the given channel bandwidth */ + switch (bw) { + case IEEE80211_STA_RX_BW_20: + n_carriers = 52; + break; + case IEEE80211_STA_RX_BW_40: + n_carriers = 108; + break; + case IEEE80211_STA_RX_BW_80: + n_carriers = 234; + break; + case IEEE80211_STA_RX_BW_160: + n_carriers = 468; + break; + default: + return (0); + } + + return ((n_carriers * mcs_entries[mcs].n_sym * mcs_entries[mcs].cod_n * + nss * 10000) / (mcs_entries[mcs].cod_d * sym_len)); +}