From 48ae785d1659d69887dec1c13c8209013ace364f Mon Sep 17 00:00:00 2001 From: Deronne Sebastien Date: Wed, 15 May 2019 12:59:50 +0200 Subject: [PATCH] wifi: Add check on length value set in L-SIG --- src/wifi/model/wifi-phy-header.cc | 1 + src/wifi/model/wifi-phy.cc | 40 +++++++++++++++++-------------- src/wifi/test/wifi-test.cc | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/wifi/model/wifi-phy-header.cc b/src/wifi/model/wifi-phy-header.cc index 0eeac7ebb..eeaccfb9c 100644 --- a/src/wifi/model/wifi-phy-header.cc +++ b/src/wifi/model/wifi-phy-header.cc @@ -293,6 +293,7 @@ LSigHeader::GetRate (uint16_t channelWidth) const void LSigHeader::SetLength (uint16_t length) { + NS_ASSERT_MSG (length < 4096, "Invalid length"); m_length = length; } diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index 35bf99ecd..6f2b3460b 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -2624,25 +2624,29 @@ WifiPhy::SendPacket (Ptr packet, WifiTxVector txVector) LSigHeader sig; if ((txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_OFDM) || (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM)) { - sig.SetRate (txVector.GetMode ().GetDataRate (GetChannelWidth ()), GetChannelWidth ()); + sig.SetRate (txVector.GetMode ().GetDataRate (txVector), GetChannelWidth ()); + sig.SetLength (packet->GetSize ()); } - uint8_t sigExtention = 0; - if (Is2_4Ghz (GetFrequency ())) - { - sigExtention = 6; - } - uint8_t m = 0; - if (txVector.GetPreambleType () == WIFI_PREAMBLE_HE_SU) - { - m = 2; - } - else if (txVector.GetPreambleType () == WIFI_PREAMBLE_HE_MU) - { - m = 1; - } - //Equation 27-11 of IEEE P802.11/D4.0 - uint16_t length = ((ceil ((static_cast (txDuration.GetNanoSeconds () - (20 * 1000) - (sigExtention * 1000)) / 1000) / 4.0) * 3) - 3 - m); - sig.SetLength (length); + else //HT, VHT or HE + { + uint8_t sigExtention = 0; + if (Is2_4Ghz (GetFrequency ())) + { + sigExtention = 6; + } + uint8_t m = 0; + if (txVector.GetPreambleType () == WIFI_PREAMBLE_HE_SU) + { + m = 2; + } + else if (txVector.GetPreambleType () == WIFI_PREAMBLE_HE_MU) + { + m = 1; + } + //Equation 27-11 of IEEE P802.11/D4.0 + uint16_t length = ((ceil ((static_cast (txDuration.GetNanoSeconds () - (20 * 1000) - (sigExtention * 1000)) / 1000) / 4.0) * 3) - 3 - m); + sig.SetLength (length); + } newPacket->AddHeader (sig); } diff --git a/src/wifi/test/wifi-test.cc b/src/wifi/test/wifi-test.cc index bdf0db05d..9aa5eaa70 100644 --- a/src/wifi/test/wifi-test.cc +++ b/src/wifi/test/wifi-test.cc @@ -284,7 +284,7 @@ InterferenceHelperSequenceTest::InterferenceHelperSequenceTest () void InterferenceHelperSequenceTest::SendOnePacket (Ptr dev) { - Ptr p = Create (9999); + Ptr p = Create (1000); dev->Send (p, dev->GetBroadcast (), 1); }