src/devices/wifi/mac-high-nqap.cc
changeset 2010 e2e16c1712c8
parent 1964 041240a915f8
child 2012 54dd9789c670
equal deleted inserted replaced
2009:afed751cc0b5 2010:e2e16c1712c8
    21 #include "mac-stations.h"
    21 #include "mac-stations.h"
    22 #include "dca-txop.h"
    22 #include "dca-txop.h"
    23 #include "wifi-net-device.h"
    23 #include "wifi-net-device.h"
    24 #include "wifi-mac-header.h"
    24 #include "wifi-mac-header.h"
    25 #include "mgt-headers.h"
    25 #include "mgt-headers.h"
       
    26 #include "wifi-phy.h"
    26 #include "ns3/assert.h"
    27 #include "ns3/assert.h"
    27 
    28 
    28 #define noNQAP_DEBUG 1
    29 #define noNQAP_DEBUG 1
    29 
    30 
    30 #ifdef NQAP_DEBUG
    31 #ifdef NQAP_DEBUG
    60 void 
    61 void 
    61 MacHighNqap::SetStations (MacStations *stations)
    62 MacHighNqap::SetStations (MacStations *stations)
    62 {
    63 {
    63   m_stations = stations;
    64   m_stations = stations;
    64 }
    65 }
       
    66 void
       
    67 MacHighNqap::SetPhy (WifiPhy *phy)
       
    68 {
       
    69   m_phy = phy;
       
    70 }
    65 void 
    71 void 
    66 MacHighNqap::SetForwardCallback (ForwardCallback callback)
    72 MacHighNqap::SetForwardCallback (ForwardCallback callback)
    67 {
    73 {
    68   m_forwardUp = callback;
    74   m_forwardUp = callback;
    69 }
       
    70 void 
       
    71 MacHighNqap::SetSupportedRates (SupportedRates rates)
       
    72 {
       
    73   m_rates = rates;
       
    74 }
    75 }
    75 void 
    76 void 
    76 MacHighNqap::SetBeaconIntervalUs (uint64_t us)
    77 MacHighNqap::SetBeaconIntervalUs (uint64_t us)
    77 {
    78 {
    78   m_beaconIntervalUs = us;
    79   m_beaconIntervalUs = us;
    91 }
    92 }
    92 void 
    93 void 
    93 MacHighNqap::Queue (Packet packet, Mac48Address to)
    94 MacHighNqap::Queue (Packet packet, Mac48Address to)
    94 {
    95 {
    95   ForwardDown (packet, m_device->GetSelfAddress (), to);
    96   ForwardDown (packet, m_device->GetSelfAddress (), to);
    96 }
       
    97 SupportedRates
       
    98 MacHighNqap::GetSupportedRates (void)
       
    99 {
       
   100   return m_rates;
       
   101 }
    97 }
   102 void
    98 void
   103 MacHighNqap::SendProbeResp (Mac48Address to)
    99 MacHighNqap::SendProbeResp (Mac48Address to)
   104 {
   100 {
   105   TRACE ("send probe response to="<<to);
   101   TRACE ("send probe response to="<<to);
   111   hdr.SetDsNotFrom ();
   107   hdr.SetDsNotFrom ();
   112   hdr.SetDsNotTo ();
   108   hdr.SetDsNotTo ();
   113   Packet packet;
   109   Packet packet;
   114   MgtProbeResponseHeader probe;
   110   MgtProbeResponseHeader probe;
   115   probe.SetSsid (m_device->GetSsid ());
   111   probe.SetSsid (m_device->GetSsid ());
   116   SupportedRates rates = GetSupportedRates ();
   112   // send the set of supported rates and make sure that we indicate
       
   113   // the Basic Rate set in this set of supported rates.
       
   114   SupportedRates rates;
       
   115   for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
       
   116     {
       
   117       WifiMode mode = m_phy->GetMode (i);
       
   118       rates.AddSupportedRate (mode.GetPhyRate ());
       
   119     }
       
   120   // set the basic rates
       
   121   for (uint32_t j = 0; j < m_stations->GetNBasicModes (); j++)
       
   122     {
       
   123       WifiMode mode = m_stations->GetBasicMode (j);
       
   124       rates.SetBasicRate (mode.GetPhyRate ());
       
   125     }
   117   probe.SetSupportedRates (rates);
   126   probe.SetSupportedRates (rates);
   118   probe.SetBeaconIntervalUs (m_beaconIntervalUs);
   127   probe.SetBeaconIntervalUs (m_beaconIntervalUs);
   119   packet.AddHeader (probe);
   128   packet.AddHeader (probe);
   120   
   129   
   121   m_dca->Queue (packet, hdr);
   130   m_dca->Queue (packet, hdr);
   122 }
   131 }
   123 void
   132 void
   124 MacHighNqap::SendAssocResp (Mac48Address to)
   133 MacHighNqap::SendAssocResp (Mac48Address to, bool success)
   125 {
   134 {
   126   TRACE ("send assoc response to="<<to);
   135   TRACE ("send assoc response to="<<to);
   127   WifiMacHeader hdr;
   136   WifiMacHeader hdr;
   128   hdr.SetAssocResp ();
   137   hdr.SetAssocResp ();
   129   hdr.SetAddr1 (to);
   138   hdr.SetAddr1 (to);
   132   hdr.SetDsNotFrom ();
   141   hdr.SetDsNotFrom ();
   133   hdr.SetDsNotTo ();
   142   hdr.SetDsNotTo ();
   134   Packet packet;
   143   Packet packet;
   135   MgtAssocResponseHeader assoc;
   144   MgtAssocResponseHeader assoc;
   136   StatusCode code;
   145   StatusCode code;
   137   code.SetSuccess ();
   146   if (success)
       
   147     {
       
   148       code.SetSuccess ();
       
   149     }
       
   150   else
       
   151     {
       
   152       code.SetFailure ();
       
   153     }
   138   assoc.SetStatusCode (code);
   154   assoc.SetStatusCode (code);
   139   packet.AddHeader (assoc);
   155   packet.AddHeader (assoc);
   140   
   156   
   141   m_dca->Queue (packet, hdr);
   157   m_dca->Queue (packet, hdr);
   142 }
   158 }
   207         } 
   223         } 
   208       else if (hdr->GetAddr1 () == m_device->GetSelfAddress ()) 
   224       else if (hdr->GetAddr1 () == m_device->GetSelfAddress ()) 
   209         {
   225         {
   210           if (hdr->IsAssocReq ()) 
   226           if (hdr->IsAssocReq ()) 
   211             {
   227             {
   212               station->RecordWaitAssocTxOk ();
   228               // first, verify that the the station's supported
   213               SendAssocResp (hdr->GetAddr2 ());
   229               // rate set is compatible with our Basic Rate set
       
   230               MgtAssocRequestHeader assocReq;
       
   231               packet.RemoveHeader (assocReq);
       
   232               SupportedRates rates = assocReq.GetSupportedRates ();
       
   233               bool problem = false;
       
   234               for (uint32_t i = 0; i < m_stations->GetNBasicModes (); i++)
       
   235                 {
       
   236                   WifiMode mode = m_stations->GetBasicMode (i);
       
   237                   if (!rates.IsSupportedRate (mode.GetPhyRate ()))
       
   238                     {
       
   239                       problem = true;
       
   240                       break;
       
   241                     }
       
   242                 }
       
   243               if (problem)
       
   244                 {
       
   245                   // one of the Basic Rate set mode is not
       
   246                   // supported by the station. So, we return an assoc
       
   247                   // response with an error status.
       
   248                   SendAssocResp (hdr->GetAddr2 (), false);
       
   249                 }
       
   250               else
       
   251                 {
       
   252                   // station supports all rates in Basic Rate Set.
       
   253                   // record all its supported modes in its associated MacStation
       
   254                   for (uint32_t j = 0; j < m_phy->GetNModes (); j++)
       
   255                     {
       
   256                       WifiMode mode = m_phy->GetMode (j);
       
   257                       if (rates.IsSupportedRate (mode.GetPhyRate ()))
       
   258                         {
       
   259                           station->AddSupportedMode (mode);
       
   260                         }
       
   261                     }
       
   262                   station->RecordWaitAssocTxOk ();
       
   263                   // send assoc response with success status.
       
   264                   SendAssocResp (hdr->GetAddr2 (), true);
       
   265                 }
   214             } 
   266             } 
   215           else if (hdr->IsDisassociation ()) 
   267           else if (hdr->IsDisassociation ()) 
   216             {
   268             {
   217               station->RecordDisassociated ();
   269               station->RecordDisassociated ();
   218             } 
   270             }