handle the BasicRateSet in the AP
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 18 Oct 2007 17:19:53 +0200
changeset 2010 e2e16c1712c8
parent 2009 afed751cc0b5
child 2011 fdf7fc62025e
handle the BasicRateSet in the AP
src/devices/wifi/mac-high-nqap.cc
src/devices/wifi/mac-high-nqap.h
src/devices/wifi/wifi-net-device.cc
--- a/src/devices/wifi/mac-high-nqap.cc	Thu Oct 18 15:59:33 2007 +0200
+++ b/src/devices/wifi/mac-high-nqap.cc	Thu Oct 18 17:19:53 2007 +0200
@@ -23,6 +23,7 @@
 #include "wifi-net-device.h"
 #include "wifi-mac-header.h"
 #include "mgt-headers.h"
+#include "wifi-phy.h"
 #include "ns3/assert.h"
 
 #define noNQAP_DEBUG 1
@@ -62,17 +63,17 @@
 {
   m_stations = stations;
 }
+void
+MacHighNqap::SetPhy (WifiPhy *phy)
+{
+  m_phy = phy;
+}
 void 
 MacHighNqap::SetForwardCallback (ForwardCallback callback)
 {
   m_forwardUp = callback;
 }
 void 
-MacHighNqap::SetSupportedRates (SupportedRates rates)
-{
-  m_rates = rates;
-}
-void 
 MacHighNqap::SetBeaconIntervalUs (uint64_t us)
 {
   m_beaconIntervalUs = us;
@@ -94,11 +95,6 @@
 {
   ForwardDown (packet, m_device->GetSelfAddress (), to);
 }
-SupportedRates
-MacHighNqap::GetSupportedRates (void)
-{
-  return m_rates;
-}
 void
 MacHighNqap::SendProbeResp (Mac48Address to)
 {
@@ -113,7 +109,20 @@
   Packet packet;
   MgtProbeResponseHeader probe;
   probe.SetSsid (m_device->GetSsid ());
-  SupportedRates rates = GetSupportedRates ();
+  // send the set of supported rates and make sure that we indicate
+  // the Basic Rate set in this set of supported rates.
+  SupportedRates rates;
+  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
+    {
+      WifiMode mode = m_phy->GetMode (i);
+      rates.AddSupportedRate (mode.GetPhyRate ());
+    }
+  // set the basic rates
+  for (uint32_t j = 0; j < m_stations->GetNBasicModes (); j++)
+    {
+      WifiMode mode = m_stations->GetBasicMode (j);
+      rates.SetBasicRate (mode.GetPhyRate ());
+    }
   probe.SetSupportedRates (rates);
   probe.SetBeaconIntervalUs (m_beaconIntervalUs);
   packet.AddHeader (probe);
@@ -121,7 +130,7 @@
   m_dca->Queue (packet, hdr);
 }
 void
-MacHighNqap::SendAssocResp (Mac48Address to)
+MacHighNqap::SendAssocResp (Mac48Address to, bool success)
 {
   TRACE ("send assoc response to="<<to);
   WifiMacHeader hdr;
@@ -134,7 +143,14 @@
   Packet packet;
   MgtAssocResponseHeader assoc;
   StatusCode code;
-  code.SetSuccess ();
+  if (success)
+    {
+      code.SetSuccess ();
+    }
+  else
+    {
+      code.SetFailure ();
+    }
   assoc.SetStatusCode (code);
   packet.AddHeader (assoc);
   
@@ -209,8 +225,44 @@
         {
           if (hdr->IsAssocReq ()) 
             {
-              station->RecordWaitAssocTxOk ();
-              SendAssocResp (hdr->GetAddr2 ());
+              // first, verify that the the station's supported
+              // rate set is compatible with our Basic Rate set
+              MgtAssocRequestHeader assocReq;
+              packet.RemoveHeader (assocReq);
+              SupportedRates rates = assocReq.GetSupportedRates ();
+              bool problem = false;
+              for (uint32_t i = 0; i < m_stations->GetNBasicModes (); i++)
+                {
+                  WifiMode mode = m_stations->GetBasicMode (i);
+                  if (!rates.IsSupportedRate (mode.GetPhyRate ()))
+                    {
+                      problem = true;
+                      break;
+                    }
+                }
+              if (problem)
+                {
+                  // one of the Basic Rate set mode is not
+                  // supported by the station. So, we return an assoc
+                  // response with an error status.
+                  SendAssocResp (hdr->GetAddr2 (), false);
+                }
+              else
+                {
+                  // station supports all rates in Basic Rate Set.
+                  // record all its supported modes in its associated MacStation
+                  for (uint32_t j = 0; j < m_phy->GetNModes (); j++)
+                    {
+                      WifiMode mode = m_phy->GetMode (j);
+                      if (rates.IsSupportedRate (mode.GetPhyRate ()))
+                        {
+                          station->AddSupportedMode (mode);
+                        }
+                    }
+                  station->RecordWaitAssocTxOk ();
+                  // send assoc response with success status.
+                  SendAssocResp (hdr->GetAddr2 (), true);
+                }
             } 
           else if (hdr->IsDisassociation ()) 
             {
--- a/src/devices/wifi/mac-high-nqap.h	Thu Oct 18 15:59:33 2007 +0200
+++ b/src/devices/wifi/mac-high-nqap.h	Thu Oct 18 17:19:53 2007 +0200
@@ -24,7 +24,6 @@
 #include "ns3/mac48-address.h"
 #include "ns3/callback.h"
 #include "ns3/packet.h"
-#include "supported-rates.h"
 
 namespace ns3 {
 
@@ -32,6 +31,7 @@
 class WifiNetDevice;
 class DcaTxop;
 class MacStations;
+class WifiPhy;
 
 class MacHighNqap {
 public:
@@ -43,8 +43,8 @@
   void SetDcaTxop (DcaTxop *dca);
   void SetDevice (WifiNetDevice *device);
   void SetStations (MacStations *stations);
+  void SetPhy (WifiPhy *phy);
   void SetForwardCallback (ForwardCallback callback);
-  void SetSupportedRates (SupportedRates rates);
   void SetBeaconIntervalUs (uint64_t us);
 
   void Queue (Packet packet, Mac48Address to);
@@ -55,14 +55,13 @@
   void TxOk (WifiMacHeader const &hdr);
   void TxFailed (WifiMacHeader const &hdr);
   void SendProbeResp (Mac48Address to);
-  void SendAssocResp (Mac48Address to);
-  SupportedRates GetSupportedRates (void);
+  void SendAssocResp (Mac48Address to, bool success);
 
   DcaTxop *m_dca;
   WifiNetDevice *m_device;
   MacStations *m_stations;
+  WifiPhy *m_phy;
   ForwardCallback m_forwardUp;
-  SupportedRates m_rates;
   uint64_t m_beaconIntervalUs;
 };
 
--- a/src/devices/wifi/wifi-net-device.cc	Thu Oct 18 15:59:33 2007 +0200
+++ b/src/devices/wifi/wifi-net-device.cc	Thu Oct 18 17:19:53 2007 +0200
@@ -389,20 +389,25 @@
 
   m_dca = CreateDca (15, 1023);
 
-  SupportedRates rates;
-  for (uint32_t i = 0; i < m_phy->GetNModes (); i++) 
+  // By default, we configure the Basic Rate Set to be the set
+  // of rates we support which are mandatory.
+  // This could be trivially made user-configurable
+  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
     {
       WifiMode mode = m_phy->GetMode (i);
-      rates.AddSupportedRate (mode.GetPhyRate ());
-    }
+      if (mode.IsMandatory ())
+        {
+          m_stations->AddBasicMode (mode);
+        }
+    }  
 
   MacHighNqap *high = new MacHighNqap ();
   high->SetDevice (this);
   high->SetDcaTxop (m_dca);
   high->SetStations (m_stations);
+  high->SetPhy (m_phy);
   high->SetForwardCallback (MakeCallback (&NqapWifiNetDevice::DoForwardUp, 
                                           this));
-  high->SetSupportedRates (rates);
   m_rxMiddle->SetForwardCallback (MakeCallback (&MacHighNqap::Receive, high));
   m_high = high;
 }