diff --git a/src/wifi/model/wifi-phy-operating-channel.cc b/src/wifi/model/wifi-phy-operating-channel.cc index c32a5f4e9..88af6bffa 100644 --- a/src/wifi/model/wifi-phy-operating-channel.cc +++ b/src/wifi/model/wifi-phy-operating-channel.cc @@ -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 { diff --git a/src/wifi/model/wifi-phy-operating-channel.h b/src/wifi/model/wifi-phy-operating-channel.h index 177c88e2a..b3ae3df7b 100644 --- a/src/wifi/model/wifi-phy-operating-channel.h +++ b/src/wifi/model/wifi-phy-operating-channel.h @@ -356,6 +356,22 @@ class WifiPhyOperatingChannel */ std::set 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.