A Discrete-Event Network Simulator
API
ht-operation.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Sébastien Deronne
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18  */
19 
20 #include "ht-operation.h"
21 
22 namespace ns3
23 {
24 
26  : m_primaryChannel(0),
27  m_secondaryChannelOffset(0),
28  m_staChannelWidth(0),
29  m_rifsMode(0),
30  m_reservedInformationSubset1(0),
31  m_htProtection(0),
32  m_nonGfHtStasPresent(1),
33  m_reservedInformationSubset2_1(0),
34  m_obssNonHtStasPresent(0),
35  m_reservedInformationSubset2_2(0),
36  m_reservedInformationSubset3_1(0),
37  m_dualBeacon(0),
38  m_dualCtsProtection(0),
39  m_stbcBeacon(0),
40  m_lSigTxopProtectionFullSupport(0),
41  m_pcoActive(0),
42  m_pcoPhase(0),
43  m_reservedInformationSubset3_2(0),
44  m_reservedMcsSet1(0),
45  m_rxHighestSupportedDataRate(0),
46  m_reservedMcsSet2(0),
47  m_txMcsSetDefined(0),
48  m_txRxMcsSetUnequal(0),
49  m_txMaxNSpatialStreams(0),
50  m_txUnequalModulation(0),
51  m_reservedMcsSet3(0)
52 {
53  for (uint8_t k = 0; k < MAX_SUPPORTED_MCS; k++)
54  {
55  m_rxMcsBitmask[k] = 0;
56  }
57 }
58 
61 {
62  return IE_HT_OPERATION;
63 }
64 
65 void
66 HtOperation::Print(std::ostream& os) const
67 {
68  os << "HT Operation=" << bool(GetPrimaryChannel()) << "|" << +GetSecondaryChannelOffset() << "|"
69  << bool(GetStaChannelWidth()) << "|" << bool(GetRifsMode()) << "|" << +GetHtProtection()
70  << "|" << bool(GetNonGfHtStasPresent()) << "|" << bool(GetObssNonHtStasPresent()) << "|"
71  << bool(GetDualBeacon()) << "|" << bool(GetDualCtsProtection()) << "|"
72  << bool(GetStbcBeacon()) << "|" << bool(GetLSigTxopProtectionFullSupport()) << "|"
73  << bool(GetPcoActive()) << "|" << bool(GetPhase()) << "|" << GetRxHighestSupportedDataRate()
74  << "|" << bool(GetTxMcsSetDefined()) << "|" << bool(GetTxRxMcsSetUnequal()) << "|"
75  << +GetTxMaxNSpatialStreams() << "|" << bool(GetTxUnequalModulation()) << "|";
76  for (uint8_t i = 0; i < MAX_SUPPORTED_MCS; i++)
77  {
78  os << IsSupportedMcs(i) << " ";
79  }
80 }
81 
82 uint16_t
84 {
85  return 22;
86 }
87 
88 void
90 {
91  m_primaryChannel = ctrl;
92 }
93 
94 void
95 HtOperation::SetSecondaryChannelOffset(uint8_t secondaryChannelOffset)
96 {
97  m_secondaryChannelOffset = secondaryChannelOffset;
98 }
99 
100 void
101 HtOperation::SetStaChannelWidth(uint8_t staChannelWidth)
102 {
103  m_staChannelWidth = staChannelWidth;
104 }
105 
106 void
107 HtOperation::SetRifsMode(uint8_t rifsMode)
108 {
109  m_rifsMode = rifsMode;
110 }
111 
112 void
113 HtOperation::SetHtProtection(uint8_t htProtection)
114 {
115  m_htProtection = htProtection;
116 }
117 
118 void
119 HtOperation::SetNonGfHtStasPresent(uint8_t nonGfHtStasPresent)
120 {
121  m_nonGfHtStasPresent = nonGfHtStasPresent;
122 }
123 
124 void
125 HtOperation::SetObssNonHtStasPresent(uint8_t obssNonHtStasPresent)
126 {
127  m_obssNonHtStasPresent = obssNonHtStasPresent;
128 }
129 
130 void
131 HtOperation::SetDualBeacon(uint8_t dualBeacon)
132 {
133  m_dualBeacon = dualBeacon;
134 }
135 
136 void
137 HtOperation::SetDualCtsProtection(uint8_t dualCtsProtection)
138 {
139  m_dualCtsProtection = dualCtsProtection;
140 }
141 
142 void
143 HtOperation::SetStbcBeacon(uint8_t stbcBeacon)
144 {
145  m_stbcBeacon = stbcBeacon;
146 }
147 
148 void
149 HtOperation::SetLSigTxopProtectionFullSupport(uint8_t lSigTxopProtectionFullSupport)
150 {
151  m_lSigTxopProtectionFullSupport = lSigTxopProtectionFullSupport;
152 }
153 
154 void
155 HtOperation::SetPcoActive(uint8_t pcoActive)
156 {
157  m_pcoActive = pcoActive;
158 }
159 
160 void
161 HtOperation::SetPhase(uint8_t pcoPhase)
162 {
163  m_pcoPhase = pcoPhase;
164 }
165 
166 void
168 {
169  m_rxMcsBitmask[index] = 1;
170 }
171 
172 void
174 {
175  m_rxHighestSupportedDataRate = maxSupportedRate;
176 }
177 
178 void
179 HtOperation::SetTxMcsSetDefined(uint8_t txMcsSetDefined)
180 {
181  m_txMcsSetDefined = txMcsSetDefined;
182 }
183 
184 void
185 HtOperation::SetTxRxMcsSetUnequal(uint8_t txRxMcsSetUnequal)
186 {
187  m_txRxMcsSetUnequal = txRxMcsSetUnequal;
188 }
189 
190 void
191 HtOperation::SetTxMaxNSpatialStreams(uint8_t maxTxSpatialStreams)
192 {
193  m_txMaxNSpatialStreams = maxTxSpatialStreams - 1; // 0 for 1 SS, 1 for 2 SSs, etc
194 }
195 
196 void
197 HtOperation::SetTxUnequalModulation(uint8_t txUnequalModulation)
198 {
199  m_txUnequalModulation = txUnequalModulation;
200 }
201 
202 uint8_t
204 {
205  return m_primaryChannel;
206 }
207 
208 uint8_t
210 {
212 }
213 
214 uint8_t
216 {
217  return m_staChannelWidth;
218 }
219 
220 uint8_t
222 {
223  return m_rifsMode;
224 }
225 
226 uint8_t
228 {
229  return m_htProtection;
230 }
231 
232 uint8_t
234 {
235  return m_nonGfHtStasPresent;
236 }
237 
238 uint8_t
240 {
241  return m_obssNonHtStasPresent;
242 }
243 
244 uint8_t
246 {
247  return m_dualBeacon;
248 }
249 
250 uint8_t
252 {
253  return m_dualCtsProtection;
254 }
255 
256 uint8_t
258 {
259  return m_stbcBeacon;
260 }
261 
262 uint8_t
264 {
266 }
267 
268 uint8_t
270 {
271  return m_pcoActive;
272 }
273 
274 uint8_t
276 {
277  return m_pcoPhase;
278 }
279 
280 bool
281 HtOperation::IsSupportedMcs(uint8_t mcs) const
282 {
283  return m_rxMcsBitmask[mcs] == 1;
284 }
285 
286 uint16_t
288 {
290 }
291 
292 uint8_t
294 {
295  return m_txMcsSetDefined;
296 }
297 
298 uint8_t
300 {
301  return m_txRxMcsSetUnequal;
302 }
303 
304 uint8_t
306 {
307  return m_txMaxNSpatialStreams;
308 }
309 
310 uint8_t
312 {
313  return m_txUnequalModulation;
314 }
315 
316 uint8_t
318 {
319  uint8_t val = 0;
320  val |= m_secondaryChannelOffset & 0x03;
321  val |= (m_staChannelWidth & 0x01) << 2;
322  val |= (m_rifsMode & 0x01) << 3;
323  val |= (m_reservedInformationSubset1 & 0x0f) << 4;
324  return val;
325 }
326 
327 void
329 {
330  m_secondaryChannelOffset = ctrl & 0x03;
331  m_staChannelWidth = (ctrl >> 2) & 0x01;
332  m_rifsMode = (ctrl >> 3) & 0x01;
333  m_reservedInformationSubset1 = (ctrl >> 4) & 0x0f;
334 }
335 
336 uint16_t
338 {
339  uint16_t val = 0;
340  val |= m_htProtection & 0x03;
341  val |= (m_nonGfHtStasPresent & 0x01) << 2;
342  val |= (m_reservedInformationSubset2_1 & 0x01) << 3;
343  val |= (m_obssNonHtStasPresent & 0x01) << 4;
344  val |= (m_reservedInformationSubset2_2 & 0x07ff) << 5;
345  return val;
346 }
347 
348 void
350 {
351  m_htProtection = ctrl & 0x03;
352  m_nonGfHtStasPresent = (ctrl >> 2) & 0x01;
353  m_reservedInformationSubset2_1 = (ctrl >> 3) & 0x01;
354  m_obssNonHtStasPresent = (ctrl >> 4) & 0x01;
355  m_reservedInformationSubset2_2 = static_cast<uint8_t>((ctrl >> 5) & 0x07ff);
356 }
357 
358 uint16_t
360 {
361  uint16_t val = 0;
362  val |= m_reservedInformationSubset3_1 & 0x3f;
363  val |= (m_dualBeacon & 0x01) << 6;
364  val |= (m_dualCtsProtection & 0x01) << 7;
365  val |= (m_stbcBeacon & 0x01) << 8;
366  val |= (m_lSigTxopProtectionFullSupport & 0x01) << 9;
367  val |= (m_pcoActive & 0x01) << 10;
368  val |= (m_pcoPhase & 0x01) << 11;
369  val |= (m_reservedInformationSubset3_2 & 0x0f) << 12;
370  return val;
371 }
372 
373 void
375 {
376  m_reservedInformationSubset3_1 = ctrl & 0x3f;
377  m_dualBeacon = (ctrl >> 6) & 0x01;
378  m_dualCtsProtection = (ctrl >> 7) & 0x01;
379  m_stbcBeacon = (ctrl >> 8) & 0x01;
380  m_lSigTxopProtectionFullSupport = (ctrl >> 9) & 0x01;
381  m_pcoActive = (ctrl >> 10) & 0x01;
382  m_pcoPhase = (ctrl >> 11) & 0x01;
383  m_reservedInformationSubset3_2 = (ctrl >> 12) & 0x0f;
384 }
385 
386 void
387 HtOperation::SetBasicMcsSet(uint64_t ctrl1, uint64_t ctrl2)
388 {
389  for (uint64_t i = 0; i < 77; i++)
390  {
391  if (i < 64)
392  {
393  m_rxMcsBitmask[i] = (ctrl1 >> i) & 0x01;
394  }
395  else
396  {
397  m_rxMcsBitmask[i] = (ctrl2 >> (i - 64)) & 0x01;
398  }
399  }
400  m_reservedMcsSet1 = (ctrl2 >> 13) & 0x07;
401  m_rxHighestSupportedDataRate = (ctrl2 >> 16) & 0x03ff;
402  m_reservedMcsSet2 = (ctrl2 >> 26) & 0x3f;
403  m_txMcsSetDefined = (ctrl2 >> 32) & 0x01;
404  m_txRxMcsSetUnequal = (ctrl2 >> 33) & 0x01;
405  m_txMaxNSpatialStreams = (ctrl2 >> 34) & 0x03;
406  m_txUnequalModulation = (ctrl2 >> 36) & 0x01;
407  m_reservedMcsSet3 = (ctrl2 >> 37) & 0x07ffffff;
408 }
409 
410 uint64_t
412 {
413  uint64_t val = 0;
414  for (uint64_t i = 63; i > 0; i--)
415  {
416  val = (val << 1) | (m_rxMcsBitmask[i] & 0x01);
417  }
418  val = (val << 1) | (m_rxMcsBitmask[0] & 0x01);
419  return val;
420 }
421 
422 uint64_t
424 {
425  uint64_t val = 0;
426  val = val | (m_reservedMcsSet3 & 0x07ffffff);
427  val = (val << 1) | (m_txUnequalModulation & 0x01);
428  val = (val << 2) | (m_txMaxNSpatialStreams & 0x03);
429  val = (val << 1) | (m_txRxMcsSetUnequal & 0x01);
430  val = (val << 1) | (m_txMcsSetDefined & 0x01);
431  val = (val << 6) | (m_reservedMcsSet2 & 0x3f);
432  val = (val << 10) | (m_rxHighestSupportedDataRate & 0x3ff);
433  val = (val << 3) | (m_reservedMcsSet1 & 0x07);
434 
435  for (uint64_t i = 13; i > 0; i--)
436  {
437  val = (val << 1) | (m_rxMcsBitmask[i + 63] & 0x01);
438  }
439  return val;
440 }
441 
442 void
444 {
445  // write the corresponding value for each bit
446  start.WriteU8(GetPrimaryChannel());
447  start.WriteU8(GetInformationSubset1());
448  start.WriteU16(GetInformationSubset2());
449  start.WriteU16(GetInformationSubset3());
450  start.WriteHtolsbU64(GetBasicMcsSet1());
451  start.WriteHtolsbU64(GetBasicMcsSet2());
452 }
453 
454 uint16_t
456 {
458  uint8_t primarychannel = i.ReadU8();
459  uint8_t informationsubset1 = i.ReadU8();
460  uint16_t informationsubset2 = i.ReadU16();
461  uint16_t informationsubset3 = i.ReadU16();
462  uint64_t mcsset1 = i.ReadLsbtohU64();
463  uint64_t mcsset2 = i.ReadLsbtohU64();
464  SetPrimaryChannel(primarychannel);
465  SetInformationSubset1(informationsubset1);
466  SetInformationSubset2(informationsubset2);
467  SetInformationSubset3(informationsubset3);
468  SetBasicMcsSet(mcsset1, mcsset2);
469  return length;
470 }
471 
472 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
uint64_t ReadLsbtohU64()
Definition: buffer.cc:1094
uint16_t ReadU16()
Definition: buffer.h:1035
uint8_t GetTxRxMcsSetUnequal() const
Return transmit / receive MCS set unequal.
void SetObssNonHtStasPresent(uint8_t obssNonHtStasPresent)
Set the OBSS non HT STAs present.
uint8_t m_reservedInformationSubset1
reserved information subset 1
Definition: ht-operation.h:367
uint8_t GetDualBeacon() const
Return dual beacon.
void SetRifsMode(uint8_t rifsMode)
Set the RIFS mode.
uint8_t GetRifsMode() const
Return the RIFS mode.
uint8_t m_obssNonHtStasPresent
OBSS NON HT STAs present.
Definition: ht-operation.h:373
void SetBasicMcsSet(uint64_t ctrl1, uint64_t ctrl2)
Set the Basic MCS Set field in the HT Operation information element.
uint8_t GetLSigTxopProtectionFullSupport() const
Return LSIG TXOP protection full support.
void SetSecondaryChannelOffset(uint8_t secondaryChannelOffset)
Set the secondary channel offset.
Definition: ht-operation.cc:95
uint8_t GetInformationSubset1() const
Return the Information Subset 1 field in the HT Operation information element.
uint8_t m_reservedInformationSubset3_1
reserved information subset 3-1
Definition: ht-operation.h:377
uint8_t m_stbcBeacon
STBC beacon.
Definition: ht-operation.h:380
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
void SetInformationSubset2(uint16_t ctrl)
Set the Information Subset 2 field in the HT Operation information element.
uint64_t GetBasicMcsSet1() const
Return the first 64 bytes of the Basic MCS Set field in the HT Operation information element.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
Definition: ht-operation.cc:83
uint8_t m_reservedInformationSubset3_2
reserved information subset 3-2
Definition: ht-operation.h:384
void SetPcoActive(uint8_t pcoActive)
Set the PCO active.
void SetTxUnequalModulation(uint8_t txUnequalModulation)
Set the transmit unequal modulation.
uint8_t m_rifsMode
RIFS mode.
Definition: ht-operation.h:366
uint8_t m_secondaryChannelOffset
secondary channel offset
Definition: ht-operation.h:364
uint8_t m_rxMcsBitmask[MAX_SUPPORTED_MCS]
receive MCS bitmask
Definition: ht-operation.h:395
uint16_t m_rxHighestSupportedDataRate
receive highest supported data rate
Definition: ht-operation.h:388
void SetInformationSubset3(uint16_t ctrl)
Set the Information Subset 3 field in the HT Operation information element.
void SetHtProtection(uint8_t htProtection)
Set the HT protection.
uint8_t GetTxMcsSetDefined() const
Return transmit MCS set defined.
uint8_t m_staChannelWidth
STA channel width.
Definition: ht-operation.h:365
uint8_t GetPrimaryChannel() const
Return the Primary Channel field in the HT Operation information element.
void SetTxMaxNSpatialStreams(uint8_t maxTxSpatialStreams)
Set the transmit maximum number spatial streams.
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint8_t m_txUnequalModulation
transmit unequal modulation
Definition: ht-operation.h:393
uint16_t GetRxHighestSupportedDataRate() const
Return receive highest supported data rate.
void SetTxRxMcsSetUnequal(uint8_t txRxMcsSetUnequal)
Set the transmit / receive MCS set unequal.
uint8_t m_reservedMcsSet1
reserved MCS set 1
Definition: ht-operation.h:387
uint8_t m_txMaxNSpatialStreams
transmit maximum number spatial streams
Definition: ht-operation.h:392
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
Definition: ht-operation.cc:60
uint8_t GetPcoActive() const
Return PCO active.
uint16_t GetInformationSubset3() const
Return the Information Subset 3 field in the HT Operation information element.
uint8_t GetStbcBeacon() const
Return STBC beacon.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
Definition: ht-operation.cc:66
uint8_t m_reservedInformationSubset2_1
reserved information subset 2-1
Definition: ht-operation.h:372
void SetDualBeacon(uint8_t dualBeacon)
Set the dual beacon.
uint8_t m_dualBeacon
dual beacon
Definition: ht-operation.h:378
uint8_t m_txMcsSetDefined
transmit MCS set defined
Definition: ht-operation.h:390
void SetNonGfHtStasPresent(uint8_t nonGfHtStasPresent)
Set the non GF HT STAs present.
uint64_t GetBasicMcsSet2() const
Return the last 64 bytes of the Basic MCS Set field in the HT Operation information element.
uint8_t m_dualCtsProtection
dual CTS protection
Definition: ht-operation.h:379
uint8_t m_lSigTxopProtectionFullSupport
L-SIG TXOP protection full support.
Definition: ht-operation.h:381
void SetTxMcsSetDefined(uint8_t txMcsSetDefined)
Set the transmit MCS set defined.
uint8_t GetHtProtection() const
Return the HT protection.
uint8_t m_reservedInformationSubset2_2
reserved information subset 2-2
Definition: ht-operation.h:374
uint8_t GetDualCtsProtection() const
Return dual CTS protection.
uint8_t m_reservedMcsSet2
reserved MCS set2
Definition: ht-operation.h:389
uint8_t GetStaChannelWidth() const
Return the STA channel width.
void SetLSigTxopProtectionFullSupport(uint8_t lSigTxopProtectionFullSupport)
Set the LSIG TXOP protection full support.
void SetStaChannelWidth(uint8_t staChannelWidth)
Set the STA channel width.
uint8_t GetSecondaryChannelOffset() const
Return the secondary channel offset.
void SetInformationSubset1(uint8_t ctrl)
Set the Information Subset 1 field in the HT Operation information element.
uint16_t GetInformationSubset2() const
Return the Information Subset 2 field in the HT Operation information element.
void SetRxHighestSupportedDataRate(uint16_t maxSupportedRate)
Set the receive highest supported data rate.
uint8_t m_pcoActive
PCO active.
Definition: ht-operation.h:382
uint8_t GetTxUnequalModulation() const
Return transmit unequal modulation.
void SetRxMcsBitmask(uint8_t index)
Set the receive MCS bitmask.
uint32_t m_reservedMcsSet3
reserved MCS set 3
Definition: ht-operation.h:394
void SetPrimaryChannel(uint8_t ctrl)
Set the Primary Channel field in the HT Operation information element.
Definition: ht-operation.cc:89
uint8_t GetObssNonHtStasPresent() const
Return the OBSS non HT STAs present.
void SetDualCtsProtection(uint8_t dualCtsProtection)
Set the dual CTS protection.
uint8_t m_htProtection
HT protection.
Definition: ht-operation.h:370
void SetPhase(uint8_t pcoPhase)
Set the PCO phase.
bool IsSupportedMcs(uint8_t mcs) const
Return MCS is supported.
uint8_t m_txRxMcsSetUnequal
transmit / receive MCS set unequal
Definition: ht-operation.h:391
uint8_t GetTxMaxNSpatialStreams() const
Return transmit maximum number spatial streams.
uint8_t GetPhase() const
Return phase.
uint8_t GetNonGfHtStasPresent() const
Return the non GF HT STAs present.
uint8_t m_pcoPhase
PCO phase.
Definition: ht-operation.h:383
uint8_t m_primaryChannel
primary channel
Definition: ht-operation.h:361
void SetStbcBeacon(uint8_t stbcBeacon)
Set the STBC beacon.
uint8_t m_nonGfHtStasPresent
non GF HT STAs present
Definition: ht-operation.h:371
#define MAX_SUPPORTED_MCS
This defines the maximum number of supported MCSs that a STA is allowed to have.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_HT_OPERATION