aboutsummaryrefslogtreecommitdiff
path: root/sys/net80211
diff options
context:
space:
mode:
authorAdrian Chadd <adrian@FreeBSD.org>2025-01-15 05:09:27 +0000
committerAdrian Chadd <adrian@FreeBSD.org>2025-02-26 19:31:25 +0000
commitff0e22f88d041da2a146d70140a535c57b40c16d (patch)
tree54a5ca9aa0b7fada2df9028626498b6c3400b16f /sys/net80211
parent4b2c7dfe768d341336f58db3cced9b097e1a6d2d (diff)
net80211: add ieee80211_phy_vht_get_mcs_kbit()
Add ieee80211_phy_vht_get_mcs_kbit(), which calculates the VHT rate in kbit/sec. Differential Revision: https://reviews.freebsd.org/D48612
Diffstat (limited to 'sys/net80211')
-rw-r--r--sys/net80211/ieee80211_phy.c85
-rw-r--r--sys/net80211/ieee80211_phy.h2
2 files changed, 87 insertions, 0 deletions
diff --git a/sys/net80211/ieee80211_phy.c b/sys/net80211/ieee80211_phy.c
index 9c2b1197564a..eb96d74a2bd9 100644
--- a/sys/net80211/ieee80211_phy.c
+++ b/sys/net80211/ieee80211_phy.c
@@ -707,3 +707,88 @@ ieee80211_phy_vht_validate_mcs(enum ieee80211_sta_rx_bw bw, uint8_t nss,
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 */
+};
+
+/*
+ * These parameters are taken from 802.11-2020 Table 21-29
+ * (VHT-MCSs for Mandatory 20 MHZ, Nss=1).
+ *
+ * n_sym corresponds to "Nbpscs", cod_n/cod_d corresponds to
+ * "R".
+ */
+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
+ *
+ * See 802.11-2020 Table 21-5 (Timing-related constraints.)
+ */
+ if (is_shortgi)
+ sym_len = 36;
+ else
+ sym_len = 40;
+
+ /*
+ * Calculate the number of carriers for the given channel bandwidth
+ *
+ * See 802.11-2020 Table 21-5 (Timing-related constraints.)
+ */
+ 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));
+}
diff --git a/sys/net80211/ieee80211_phy.h b/sys/net80211/ieee80211_phy.h
index 466f59584f2c..749b082e34e9 100644
--- a/sys/net80211/ieee80211_phy.h
+++ b/sys/net80211/ieee80211_phy.h
@@ -227,6 +227,8 @@ uint16_t ieee80211_phy_vht_get_mcs_mask(enum ieee80211_sta_rx_bw,
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_ */