wifi: Add functions to retrieve the segment that contains the primary or secondary channel

This commit is contained in:
Sébastien Deronne
2023-06-11 10:49:32 +02:00
parent 5072136c8b
commit 8e86b469d3
2 changed files with 44 additions and 0 deletions

View File

@@ -553,6 +553,34 @@ WifiPhyOperatingChannel::SetPrimary20Index(uint8_t index)
m_primary20Index = index;
}
uint8_t
WifiPhyOperatingChannel::GetPrimarySegmentIndex(ChannelWidthMhz primaryChannelWidth) const
{
if (m_channelIts.size() < 2)
{
return 0;
}
// Note: this function assumes no more than 2 segments are used
const auto numIndices = GetTotalWidth() / primaryChannelWidth;
const auto primaryIndex = GetPrimaryChannelIndex(primaryChannelWidth);
return (primaryIndex >= (numIndices / 2)) ? 1 : 0;
}
uint8_t
WifiPhyOperatingChannel::GetSecondarySegmentIndex(ChannelWidthMhz primaryChannelWidth) const
{
NS_ABORT_MSG_IF(primaryChannelWidth > GetWidth(),
"Primary channel width cannot be larger than the width of a frequency segment");
if (m_channelIts.size() < 2)
{
return 0;
}
// Note: this function assumes no more than 2 segments are used
const auto numIndices = GetTotalWidth() / primaryChannelWidth;
const auto secondaryIndex = GetSecondaryChannelIndex(primaryChannelWidth);
return (secondaryIndex >= (numIndices / 2)) ? 1 : 0;
}
uint16_t
WifiPhyOperatingChannel::GetPrimaryChannelCenterFrequency(ChannelWidthMhz primaryChannelWidth) const
{

View File

@@ -356,6 +356,22 @@ class WifiPhyOperatingChannel
*/
std::set<uint8_t> Get20MHzIndicesCoveringRu(HeRu::RuSpec ru, ChannelWidthMhz width) const;
/**
* Get the index of the segment that contains a given primary channel (in MHz).
*
* \param primaryChannelWidth the width of the primary channel in MHz
* \return the index of the segment that contains the primary channel
*/
uint8_t GetPrimarySegmentIndex(ChannelWidthMhz primaryChannelWidth) const;
/**
* Get the index of the segment that contains a given secondary channel (in MHz).
*
* \param secondaryChannelWidth the width of the secondary channel in MHz
* \return the index of the segment that contains the secondary channel
*/
uint8_t GetSecondarySegmentIndex(ChannelWidthMhz secondaryChannelWidth) const;
private:
/**
* Sort the segments by increasing frequencies.