Skip to content

Commit

Permalink
Parse VHT capabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jan 16, 2024
1 parent c297a97 commit 71687d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
28 changes: 24 additions & 4 deletions src/linux/libnl-helpers/Netlink80211WiphyBand.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include <array>
#include <format>
#include <sstream>

Expand All @@ -11,10 +10,12 @@

using namespace Microsoft::Net::Netlink::Nl80211;

Nl80211WiphyBand::Nl80211WiphyBand(std::vector<WiphyBandFrequency> frequencies, std::vector<uint32_t> bitRates, uint16_t htCapabilities) noexcept :
Nl80211WiphyBand::Nl80211WiphyBand(std::vector<WiphyBandFrequency> frequencies, std::vector<uint32_t> bitRates, uint16_t htCapabilities, uint32_t VhtCapabilities, std::optional<std::array<uint8_t, VhtMcsSetNumBytes>> vhtMcsSetOpt) noexcept :
Frequencies(std::move(frequencies)),
Bitrates(std::move(bitRates)),
HtCapabilities(htCapabilities)
HtCapabilities(htCapabilities),
VhtCapabilities(VhtCapabilities),
VhtMcsSet(std::move(vhtMcsSetOpt))
{
}

Expand All @@ -35,6 +36,17 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept
htCapabilities = nla_get_u16(wiphyBandAttributes[NL80211_BAND_ATTR_HT_CAPA]);
}

uint32_t vhtCapabilities{ 0 };
std::optional<std::array<uint8_t, VhtMcsSetNumBytes>> vhtMcsSetOpt{};
if (wiphyBandAttributes[NL80211_BAND_ATTR_VHT_CAPA] != nullptr) {
vhtCapabilities = nla_get_u32(wiphyBandAttributes[NL80211_BAND_ATTR_VHT_CAPA]);
if (wiphyBandAttributes[NL80211_BAND_ATTR_VHT_MCS_SET] != nullptr) {
vhtMcsSetOpt.emplace();
auto& vhtMcsSet = vhtMcsSetOpt.value();
std::copy_n(static_cast<uint8_t *>(nla_data(wiphyBandAttributes[NL80211_BAND_ATTR_VHT_MCS_SET])), std::size(vhtMcsSet), std::begin(vhtMcsSet));
}
}

std::vector<WiphyBandFrequency> frequencies{};
if (wiphyBandAttributes[NL80211_BAND_ATTR_FREQS] != nullptr) {
struct nlattr *wiphyBandFrequency;
Expand Down Expand Up @@ -68,7 +80,7 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept
}
}

return Nl80211WiphyBand(std::move(frequencies), std::move(bitRates), htCapabilities);
return Nl80211WiphyBand(std::move(frequencies), std::move(bitRates), htCapabilities, vhtCapabilities, std::move(vhtMcsSetOpt));
}

std::string
Expand All @@ -77,6 +89,14 @@ Nl80211WiphyBand::ToString() const
std::ostringstream ss;

ss << " HT Capabilities: " << std::format("0x{:04x}\n", HtCapabilities);
ss << " VHT Capabilities: " << std::format("0x{:08x}\n", VhtCapabilities);
if (VhtMcsSet.has_value()) {
ss << " VHT MCS Set: 0x";
for (const auto &mcs : VhtMcsSet.value()) {
ss << std::format("{:02x}", mcs);
}
ss << '\n';
}
ss << " Frequencies:\n";
for (const auto &frequency : Frequencies) {
ss << std::format(" {}\n", frequency.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef NETLINK_80211_WIPHY_BAND_HXX
#define NETLINK_80211_WIPHY_BAND_HXX

#include <array>
#include <cstdint>
#include <optional>
#include <string>
Expand All @@ -22,6 +23,11 @@ struct Nl80211WiphyBand
std::vector<WiphyBandFrequency> Frequencies;
std::vector<uint32_t> Bitrates;
uint16_t HtCapabilities;
uint32_t VhtCapabilities;

// From documentation in nl80211.h under nl80211_band_attr defintion.
static constexpr auto VhtMcsSetNumBytes{ 32 };
std::optional<std::array<uint8_t, VhtMcsSetNumBytes>> VhtMcsSet;

/**
* @brief Parses a netlink attribute into a Nl80211WiphyBand.
Expand Down Expand Up @@ -53,8 +59,9 @@ private:
* @param frequencies The frequencies supported by this band.
* @param bitRates The bitrates supported by this band.
* @param htCapabilities The high-throughput ('HT' aka 802.11n) capabilities of this band.
* @param vhtCapabilities The very-high-throughput ('VHT' aka 802.11ac) capabilities of this band.
*/
Nl80211WiphyBand(std::vector<WiphyBandFrequency> frequencies, std::vector<uint32_t> bitRates, uint16_t htCapabilities) noexcept;
Nl80211WiphyBand(std::vector<WiphyBandFrequency> frequencies, std::vector<uint32_t> bitRates, uint16_t htCapabilities, uint32_t vhtCapabilities, std::optional<std::array<uint8_t, VhtMcsSetNumBytes>> vhtMcsSet) noexcept;
};
} // namespace Microsoft::Net::Netlink::Nl80211

Expand Down

0 comments on commit 71687d9

Please sign in to comment.