From 9e4319a86cd72ff29dd70e668c873a99549fbee4 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Fri, 13 Oct 2023 13:14:48 +0200 Subject: [PATCH] wifi: Avoid hitting an assert when switching PHY to sleep at RX end --- src/wifi/model/wifi-phy.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index 26661cec0..abf8138da 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -1362,7 +1362,13 @@ WifiPhy::SetSleepMode() // The PHY object may be in CCA_BUSY state because it is receiving a preamble. Cancel // preamble events before switching to sleep state Reset(); - m_state->SwitchToSleep(); + // It may happen that we request to switch to sleep at the same time the reception of + // a PPDU ends. In such a case, WifiPhyStateHelper::GetState() does not return RX + // (m_endRx equals now), we get here and set the state to SLEEP. However, + // WifiPhyStateHelper::DoSwitchFromRx() may be called after this function (at the same + // simulation time), thus hitting the assert that checks that the state is IDLE or + // CCA_BUSY. + Simulator::ScheduleNow(&WifiPhyStateHelper::SwitchToSleep, m_state); break; case WifiPhyState::SLEEP: NS_LOG_DEBUG("already in sleep mode");