Bug 1848 - yans-wifi-phy can receive frames sent using unsupported mode
authorDaniel Lertpratchya <nikkipui@gmail.com>
Fri, 31 Jan 2014 12:00:31 -0500
changeset 10600 48c3c6b355a1
parent 10599 f80b2ef21ac5
child 10601 9e7ff25053ed
Bug 1848 - yans-wifi-phy can receive frames sent using unsupported mode
src/wifi/model/yans-wifi-phy.cc
src/wifi/model/yans-wifi-phy.h
--- a/src/wifi/model/yans-wifi-phy.cc	Thu Jan 30 12:18:29 2014 -0800
+++ b/src/wifi/model/yans-wifi-phy.cc	Fri Jan 31 12:00:31 2014 -0500
@@ -452,7 +452,7 @@
   rxPowerDbm += m_rxGainDb;
   double rxPowerW = DbmToW (rxPowerDbm);
   Time rxDuration = CalculateTxDuration (packet->GetSize (), txVector, preamble);
-WifiMode txMode=txVector.GetMode();
+  WifiMode txMode = txVector.GetMode();
   Time endRx = Simulator::Now () + rxDuration;
 
   Ptr<InterferenceHelper::Event> event;
@@ -509,15 +509,24 @@
     case YansWifiPhy::IDLE:
       if (rxPowerW > m_edThresholdW)
         {
-          NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
-          // sync to signal
-          m_state->SwitchToRx (rxDuration);
-          NS_ASSERT (m_endRxEvent.IsExpired ());
-          NotifyRxBegin (packet);
-          m_interference.NotifyRxStart ();
-          m_endRxEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndReceive, this,
-                                              packet,
-                                              event);
+          if (IsModeSupported (txMode))
+            {
+              NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
+              // sync to signal
+              m_state->SwitchToRx (rxDuration);
+              NS_ASSERT (m_endRxEvent.IsExpired ());
+              NotifyRxBegin (packet);
+              m_interference.NotifyRxStart ();
+              m_endRxEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndReceive, this,
+                                                  packet,
+                                                  event);
+            }
+          else
+            {
+              NS_LOG_DEBUG ("drop packet because it was sent using an unsupported mode (" << txMode << ")");
+              NotifyRxDrop (packet);
+              goto maybeCcaBusy;
+            }
         }
       else
         {
@@ -580,6 +589,18 @@
 {
   return m_deviceRateSet[mode];
 }
+bool
+YansWifiPhy::IsModeSupported (WifiMode mode) const
+{
+  for (uint32_t i = 0; i < GetNModes (); i++)
+    {
+      if (mode == GetMode (i))
+        {
+          return true;
+        }
+    }
+  return false;
+}
 uint32_t
 YansWifiPhy::GetNTxPower (void) const
 {
--- a/src/wifi/model/yans-wifi-phy.h	Thu Jan 30 12:18:29 2014 -0800
+++ b/src/wifi/model/yans-wifi-phy.h	Fri Jan 31 12:00:31 2014 -0500
@@ -260,6 +260,7 @@
   virtual Time GetLastRxStartTime (void) const;
   virtual uint32_t GetNModes (void) const;
   virtual WifiMode GetMode (uint32_t mode) const;
+  virtual bool IsModeSupported (WifiMode mode) const;
   virtual double CalculateSnr (WifiMode txMode, double ber) const;
   virtual Ptr<WifiChannel> GetChannel (void) const;