A Discrete-Event Network Simulator
API
ht-capabilities.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Ghada Badawy <gbadawy@rim.com>
19  */
20 
21 #include "ht-capabilities.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("HtCapabilities");
29 
31  : m_ldpc(0),
32  m_supportedChannelWidth(0),
33  m_smPowerSave(0),
34  m_greenField(0),
35  m_shortGuardInterval20(0),
36  m_shortGuardInterval40(0),
37  m_txStbc(0),
38  m_rxStbc(0),
39  m_htDelayedBlockAck(0),
40  m_maxAmsduLength(0),
41  m_dssMode40(0),
42  m_reserved(0),
43  m_fortyMhzIntolerant(0),
44  m_lsigProtectionSupport(0),
45  m_maxAmpduLength(0),
46  m_minMpduStartSpace(0),
47  m_ampduReserved(0),
48  m_reservedMcsSet1(0),
49  m_rxHighestSupportedDataRate(0),
50  m_reservedMcsSet2(0),
51  m_txMcsSetDefined(0),
52  m_txRxMcsSetUnequal(0),
53  m_txMaxNSpatialStreams(0),
54  m_txUnequalModulation(0),
55  m_reservedMcsSet3(7),
56  m_htSupported(0)
57 {
58  for (uint32_t k=0; k < MAX_SUPPORTED_MCS ;k++)
59  {
60  m_rxMcsBitmask[k]=0;
61  }
62 }
63 
64 
67 {
68  return IE_HT_CAPABILITIES;
69 }
70 
71 void
72 HtCapabilities::SetHtSupported(uint8_t htsupported)
73 {
74  m_htSupported = htsupported;
75 }
76 void
78 {
79  m_ldpc=ldpc;
80 }
81 
82 void
83 HtCapabilities::SetSupportedChannelWidth (uint8_t supportedchannelwidth)
84 {
85  m_supportedChannelWidth=supportedchannelwidth;
86 }
87 
88 void
89 HtCapabilities::SetGreenfield (uint8_t greenfield)
90 {
91  m_greenField=greenfield;
92 }
93 
94 void
95 HtCapabilities::SetShortGuardInterval20 (uint8_t shortguardinterval)
96 {
97  m_shortGuardInterval20=shortguardinterval;
98 }
99 void
101 {
102  m_rxMcsBitmask[index]=1;
103 }
104 
105 uint8_t*
107 {
108  uint8_t* p;
109  p= m_rxMcsBitmask;
110  return p;
111 }
112 
113 bool
115 {
116  if (m_rxMcsBitmask[mcs] == 1)
117  {
118  return true;
119  }
120  return false;
121 
122 }
123 uint8_t
125 {
126  return m_ldpc;
127 }
128 
129 uint8_t
131 {
133 }
134 
135 uint8_t
137 {
138  return m_greenField;
139 }
140 uint8_t
142 {
143  return m_shortGuardInterval20;
144 }
145 
146 uint8_t
148 {
149  // we should not be here if ht is not supported
150  NS_ASSERT (m_htSupported > 0);
151  return 19;
152 }
155 {
156  if (m_htSupported< 1)
157  {
158  return i;
159  }
161 }
162 uint16_t
164 {
165  if (m_htSupported < 1)
166  {
167  return 0;
168  }
170 }
171 
172 uint16_t
174 {
175  uint16_t val = 0;
176  val |= m_ldpc;
177  val |= (m_supportedChannelWidth << 1)& (0x1 << 1);
178  val |= (m_smPowerSave << 2)& (0x3 << 2) ;
179  val |= (m_greenField << 4)& (0x1 << 4) ;
180  val |= (m_shortGuardInterval20 << 5)& (0x1 << 5);
181  val |= (m_shortGuardInterval40 << 6)& (0x1 << 6);
182  val |= (m_txStbc << 7)& (0x1 << 7);
183  val |= (m_rxStbc << 8)& (0x3 << 8);
184  val |= (m_htDelayedBlockAck << 10)& (0x1 << 10);
185  val |= (m_maxAmsduLength << 11)& (0x1 << 11);
186  val |= (m_dssMode40 << 12)& (0x1 << 12);
187  val |= (m_reserved<< 13)& (0x1 << 13);
188  val |= (m_fortyMhzIntolerant << 14)& (0x1 << 14);
189  val |= (m_lsigProtectionSupport << 15)& (0x1 << 15);
190  return val;
191 }
192 
193 void
195 {
196  m_ldpc = ctrl & 0x01;
197  m_supportedChannelWidth = (ctrl >> 1) & 0x01;
198  m_smPowerSave = (ctrl >> 2) & 0x03;
199  m_greenField = (ctrl >> 4) & 0x01;
200  m_shortGuardInterval20 = (ctrl >> 5) & 0x01;
201  m_shortGuardInterval40 = (ctrl >> 6) & 0x01;
202  m_txStbc = (ctrl >> 7) & 0x01;
203  m_rxStbc = (ctrl >> 8) & 0x03;
204  m_htDelayedBlockAck = (ctrl >> 10) & 0x01;
205  m_maxAmsduLength = (ctrl >> 11) & 0x01;
206  m_dssMode40= (ctrl >> 12) & 0x01;
207  m_reserved= (ctrl >> 13) & 0x01;
208  m_fortyMhzIntolerant= (ctrl >> 14) & 0x01;
209  m_lsigProtectionSupport= (ctrl >> 15) & 0x01;
210 }
211 uint8_t
213 {
214  uint8_t val = 0;
215  val |= m_maxAmpduLength & 0x3;
216  val |= ( m_minMpduStartSpace << 2)& (0x7 << 2);
217  val |= (m_ampduReserved << 5)& (0x7 << 5) ;
218  return val;
219 }
220 
221 void
223 {
224  m_maxAmpduLength = ctrl & 0x03;
225  m_minMpduStartSpace = (ctrl >> 2) & 0x07;
226  m_ampduReserved =(ctrl >> 5) & 0x07;
227 }
228 
229 void
230 HtCapabilities::SetSupportedMcsSet (uint64_t ctrl2, uint64_t ctrl1)
231 {
232  for(uint64_t i=0 ; i < 77;i++)
233  {
234  if (i < 64)
235  {
236  m_rxMcsBitmask[i]=(ctrl1 >> i) & 0x01;
237  }
238  else
239  {
240  m_rxMcsBitmask[i]=( ctrl2 >> (i-64))& 0x01 ;
241  }
242  }
243  m_reservedMcsSet1 = (ctrl2 >> 12) & 0x07;
244  m_rxHighestSupportedDataRate = (ctrl2 >> 15) & 0x03ff;
245  m_reservedMcsSet2 = (ctrl2 >> 25) & 0x3f;
246  m_txMcsSetDefined = (ctrl2 >> 31) & 0x01;
247  m_txRxMcsSetUnequal = (ctrl2 >> 32) & 0x01;
248  m_txMaxNSpatialStreams = (ctrl2 >> 33) & 0x03;
249  m_txUnequalModulation = (ctrl2 >> 35) & 0x01;
250  m_reservedMcsSet3 = (ctrl2 >> 36) & 0x07ffffff;
251 }
252 uint64_t
254 {
255  uint64_t val=0;
256  for(uint64_t i=63 ; i >0 ;i--)
257  {
258  val = (val << 1) | (m_rxMcsBitmask[i] & 0x01);
259  }
260  val = (val << 1) | (m_rxMcsBitmask[0] & 0x01);
261  return val;
262 }
263 uint64_t
265 {
266  uint64_t val=0;
267  val = val | (m_reservedMcsSet3 & 0x07ffffff);
268  val = (val << 1) | (m_txUnequalModulation & 0x01);
269  val = (val << 2) | (m_txMaxNSpatialStreams & 0x03);
270  val = (val << 1) | (m_txRxMcsSetUnequal & 0x01);
271  val = (val << 1) | (m_txMcsSetDefined & 0x01);
272  val = (val << 6) | (m_reservedMcsSet2 & 0x3f);
273  val = (val << 10) |(m_rxHighestSupportedDataRate & 0x3ff);
274  val = (val << 3) |(m_reservedMcsSet1 & 0x07);
275 
276  for (uint64_t i=12; i>0;i--)
277  {
278  val = (val << 1)|( m_rxMcsBitmask[i+64] & 0x01);
279  }
280  return val;
281 }
282 
283 void
285 {
286  if (m_htSupported == 1)
287  {
288  // write the corresponding value for each bit
289  start. WriteHtolsbU16 (GetHtCapabilitiesInfo());
290  start. WriteU8 (GetAmpduParameters());
291  start. WriteHtolsbU64 (GetSupportedMcsSet2());
292  start. WriteHtolsbU64 (GetSupportedMcsSet1());
293  }
294 }
295 
296 uint8_t
298  uint8_t length)
299 {
301  uint16_t htinfo = i.ReadLsbtohU16 ();
302  uint8_t ampduparam = i.ReadU8 ();
303  uint64_t mcsset1=i.ReadLsbtohU64 ();
304  uint64_t mcsset2 = i.ReadLsbtohU64 ();
305  SetHtCapabilitiesInfo(htinfo);
306  SetAmpduParameters(ampduparam);
307  SetSupportedMcsSet(mcsset1,mcsset2);
308  return length;
309 }
310 
312 
313 std::ostream &
314 operator << (std::ostream &os, const HtCapabilities &htcapabilities)
315 {
316  os << bool (htcapabilities.GetLdpc ())
317  << "|" << bool (htcapabilities.GetSupportedChannelWidth ())
318  << "|" << bool (htcapabilities.GetGreenfield ())
319  << "|" << bool (htcapabilities.GetShortGuardInterval20 ());
320 
321  return os;
322 }
323 
324 std::istream &operator >> (std::istream &is,HtCapabilities &htcapabilities)
325 {
326  bool c1, c2, c3,c4;
327  is >> c1 >> c2 >> c3 >>c4;
328  htcapabilities.SetLdpc (c1);
329  htcapabilities.SetSupportedChannelWidth (c2);
330  htcapabilities.SetGreenfield (c3);
331  htcapabilities.SetShortGuardInterval20 (c4);
332 
333  return is;
334 }
335 
336 } // namespace ns3
uint8_t m_rxMcsBitmask[MAX_SUPPORTED_MCS]
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
void SetGreenfield(uint8_t greenfield)
uint8_t m_supportedChannelWidth
#define MAX_SUPPORTED_MCS
This defines the maximum number of supported MCSs that a STA is allowed to have.
void SetHtSupported(uint8_t htsupported)
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
uint64_t GetSupportedMcsSet2(void) const
void SetRxMcsBitmask(uint8_t index)
def start()
Definition: core.py:1482
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
The HT Capabilities Information ElementThis class knows how to serialise and deserialise the HT Capab...
uint8_t GetSupportedChannelWidth(void) const
void SetAmpduParameters(uint8_t ctrl)
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
iterator in a Buffer instance
Definition: buffer.h:98
#define IE_HT_CAPABILITIES
void SetShortGuardInterval20(uint8_t shortguardinterval)
uint8_t GetGreenfield(void) const
uint64_t GetSupportedMcsSet1(void) const
uint16_t m_rxHighestSupportedDataRate
uint8_t GetShortGuardInterval20(void) const
bool IsSupportedMcs(uint8_t mcs)
WifiInformationElementId ElementId() const
Own unique Element ID.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetAmpduParameters(void) const
void SerializeInformationField(Buffer::Iterator start) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
void SetSupportedMcsSet(uint64_t ctrl1, uint64_t ctrl2)
uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint8_t GetLdpc(void) const
void SetHtCapabilitiesInfo(uint16_t ctrl)
uint16_t GetHtCapabilitiesInfo(void) const
void SetLdpc(uint8_t ldpc)
uint8_t ReadU8(void)
Definition: buffer.h:1028
uint8_t * GetRxMcsBitmask()
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1094
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
uint64_t ReadLsbtohU64(void)
Definition: buffer.cc:1122
uint16_t GetSerializedSize() const
Return the serialized size of this HT capability information element.
Buffer::Iterator Serialize(Buffer::Iterator start) const
This information element is a bit special in that it is only included if the STA is an HT STA...
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
void SetSupportedChannelWidth(uint8_t supportedchannelwidth)