|
|
| 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2016 Sébastien Deronne |
| 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: Sébastien Deronne <sebastien.deronne@gmail.com> |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "ht-operations.h" |
| 22 |
#include "ns3/assert.h" |
| 23 |
#include "ns3/log.h" |
| 24 |
|
| 25 |
namespace ns3 { |
| 26 |
|
| 27 |
NS_LOG_COMPONENT_DEFINE ("HtOperations"); |
| 28 |
|
| 29 |
HtOperations::HtOperations () |
| 30 |
: m_primaryChannel (0), |
| 31 |
m_secondaryChannelOffset (0), |
| 32 |
m_staChannelWidth (0), |
| 33 |
m_rifsMode (0), |
| 34 |
m_reservedInformationSubset1 (0), |
| 35 |
m_htProtection (0), |
| 36 |
m_nonGfHtStasPresent (0), |
| 37 |
m_reservedInformationSubset2_1 (0), |
| 38 |
m_obssNonHtStasPresent (0), |
| 39 |
m_reservedInformationSubset2_2 (0), |
| 40 |
m_reservedInformationSubset3_1 (0), |
| 41 |
m_dualBeacon (0), |
| 42 |
m_dualCtsProtection (0), |
| 43 |
m_stbcBeacon (0), |
| 44 |
m_lSigTxopProtectionFullSupport (0), |
| 45 |
m_pcoActive (0), |
| 46 |
m_pcoPhase (0), |
| 47 |
m_reservedInformationSubset3_2 (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 (0), |
| 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 |
WifiInformationElementId |
| 65 |
HtOperations::ElementId () const |
| 66 |
{ |
| 67 |
return IE_HT_OPERATIONS; |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
HtOperations::SetHtSupported (uint8_t htsupported) |
| 72 |
{ |
| 73 |
m_htSupported = htsupported; |
| 74 |
} |
| 75 |
|
| 76 |
uint8_t |
| 77 |
HtOperations::GetInformationFieldSize () const |
| 78 |
{ |
| 79 |
//we should not be here if ht is not supported |
| 80 |
NS_ASSERT (m_htSupported > 0); |
| 81 |
return 22; |
| 82 |
} |
| 83 |
|
| 84 |
void |
| 85 |
HtOperations::SetPrimaryChannel (uint8_t ctrl) |
| 86 |
{ |
| 87 |
m_primaryChannel = ctrl; |
| 88 |
} |
| 89 |
|
| 90 |
void |
| 91 |
HtOperations::SetSecondaryChannelOffset (uint8_t secondarychanneloffset) |
| 92 |
{ |
| 93 |
m_secondaryChannelOffset = secondarychanneloffset; |
| 94 |
} |
| 95 |
|
| 96 |
void |
| 97 |
HtOperations::SetStaChannelWidth (uint8_t stachannelwidth) |
| 98 |
{ |
| 99 |
m_staChannelWidth = stachannelwidth; |
| 100 |
} |
| 101 |
|
| 102 |
void |
| 103 |
HtOperations::SetRifsMode (uint8_t rifsmode) |
| 104 |
{ |
| 105 |
m_rifsMode = rifsmode; |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
HtOperations::SetHtProtection (uint8_t htprotection) |
| 110 |
{ |
| 111 |
m_htProtection = htprotection; |
| 112 |
} |
| 113 |
|
| 114 |
void |
| 115 |
HtOperations::SetNonGfHtStasPresent (uint8_t nongfhtstaspresent) |
| 116 |
{ |
| 117 |
m_nonGfHtStasPresent = nongfhtstaspresent; |
| 118 |
} |
| 119 |
|
| 120 |
void |
| 121 |
HtOperations::SetObssNonHtStasPresent (uint8_t obssnonhtstaspresent) |
| 122 |
{ |
| 123 |
m_obssNonHtStasPresent = obssnonhtstaspresent; |
| 124 |
} |
| 125 |
|
| 126 |
void |
| 127 |
HtOperations::SetDualBeacon (uint8_t dualbeacon) |
| 128 |
{ |
| 129 |
m_dualBeacon = dualbeacon; |
| 130 |
} |
| 131 |
|
| 132 |
void |
| 133 |
HtOperations::SetDualCtsProtection (uint8_t dualctsprotection) |
| 134 |
{ |
| 135 |
m_dualCtsProtection = dualctsprotection; |
| 136 |
} |
| 137 |
|
| 138 |
void |
| 139 |
HtOperations::SetStbcBeacon (uint8_t stbcbeacon) |
| 140 |
{ |
| 141 |
m_stbcBeacon = stbcbeacon; |
| 142 |
} |
| 143 |
|
| 144 |
void |
| 145 |
HtOperations::SetLSigTxopProtectionFullSupport (uint8_t lsigtxopprotectionfullsupport) |
| 146 |
{ |
| 147 |
m_lSigTxopProtectionFullSupport = lsigtxopprotectionfullsupport; |
| 148 |
} |
| 149 |
|
| 150 |
void |
| 151 |
HtOperations::SetPcoActive (uint8_t pcoactive) |
| 152 |
{ |
| 153 |
m_pcoActive = pcoactive; |
| 154 |
} |
| 155 |
|
| 156 |
void |
| 157 |
HtOperations::SetPhase (uint8_t pcophase) |
| 158 |
{ |
| 159 |
m_pcoPhase = pcophase; |
| 160 |
} |
| 161 |
|
| 162 |
void |
| 163 |
HtOperations::SetRxMcsBitmask (uint8_t index) |
| 164 |
{ |
| 165 |
m_rxMcsBitmask[index] = 1; |
| 166 |
} |
| 167 |
|
| 168 |
void |
| 169 |
HtOperations::SetRxHighestSupportedDataRate (uint16_t maxsupportedrate) |
| 170 |
{ |
| 171 |
m_rxHighestSupportedDataRate = maxsupportedrate; |
| 172 |
} |
| 173 |
|
| 174 |
void |
| 175 |
HtOperations::SetTxMcsSetDefined (uint8_t txmcssetdefined) |
| 176 |
{ |
| 177 |
m_txMcsSetDefined = txmcssetdefined; |
| 178 |
} |
| 179 |
|
| 180 |
void |
| 181 |
HtOperations::SetTxRxMcsSetUnequal (uint8_t txrxmcssetunequal) |
| 182 |
{ |
| 183 |
m_txRxMcsSetUnequal = txrxmcssetunequal; |
| 184 |
} |
| 185 |
|
| 186 |
void |
| 187 |
HtOperations::SetTxMaxNSpatialStreams (uint8_t maxtxspatialstreams) |
| 188 |
{ |
| 189 |
m_txMaxNSpatialStreams = maxtxspatialstreams; |
| 190 |
} |
| 191 |
|
| 192 |
void |
| 193 |
HtOperations::SetTxUnequalModulation (uint8_t txunequalmodulation) |
| 194 |
{ |
| 195 |
m_txUnequalModulation = txunequalmodulation; |
| 196 |
} |
| 197 |
|
| 198 |
uint8_t |
| 199 |
HtOperations::GetPrimaryChannel (void) const |
| 200 |
{ |
| 201 |
return m_primaryChannel; |
| 202 |
} |
| 203 |
|
| 204 |
uint8_t |
| 205 |
HtOperations::GetSecondaryChannelOffset (void) const |
| 206 |
{ |
| 207 |
return m_secondaryChannelOffset; |
| 208 |
} |
| 209 |
|
| 210 |
uint8_t |
| 211 |
HtOperations::GetStaChannelWidth (void) const |
| 212 |
{ |
| 213 |
return m_staChannelWidth; |
| 214 |
} |
| 215 |
|
| 216 |
uint8_t |
| 217 |
HtOperations::GetRifsMode (void) const |
| 218 |
{ |
| 219 |
return m_rifsMode; |
| 220 |
} |
| 221 |
|
| 222 |
uint8_t |
| 223 |
HtOperations::GetHtProtection (void) const |
| 224 |
{ |
| 225 |
return m_htProtection; |
| 226 |
} |
| 227 |
|
| 228 |
uint8_t |
| 229 |
HtOperations::GetNonGfHtStasPresent (void) const |
| 230 |
{ |
| 231 |
return m_nonGfHtStasPresent; |
| 232 |
} |
| 233 |
|
| 234 |
uint8_t |
| 235 |
HtOperations::GetObssNonHtStasPresent (void) const |
| 236 |
{ |
| 237 |
return m_obssNonHtStasPresent; |
| 238 |
} |
| 239 |
|
| 240 |
uint8_t |
| 241 |
HtOperations::GetDualBeacon (void) const |
| 242 |
{ |
| 243 |
return m_dualBeacon; |
| 244 |
} |
| 245 |
|
| 246 |
uint8_t |
| 247 |
HtOperations::GetDualCtsProtection (void) const |
| 248 |
{ |
| 249 |
return m_dualCtsProtection; |
| 250 |
} |
| 251 |
|
| 252 |
uint8_t |
| 253 |
HtOperations::GetStbcBeacon (void) const |
| 254 |
{ |
| 255 |
return m_stbcBeacon; |
| 256 |
} |
| 257 |
|
| 258 |
uint8_t |
| 259 |
HtOperations::GetLSigTxopProtectionFullSupport (void) const |
| 260 |
{ |
| 261 |
return m_lSigTxopProtectionFullSupport; |
| 262 |
} |
| 263 |
|
| 264 |
uint8_t |
| 265 |
HtOperations::GetPcoActive (void) const |
| 266 |
{ |
| 267 |
return m_pcoActive; |
| 268 |
} |
| 269 |
|
| 270 |
uint8_t |
| 271 |
HtOperations::GetPhase (void) const |
| 272 |
{ |
| 273 |
return m_pcoPhase; |
| 274 |
} |
| 275 |
|
| 276 |
bool |
| 277 |
HtOperations::IsSupportedMcs (uint8_t mcs) |
| 278 |
{ |
| 279 |
if (m_rxMcsBitmask[mcs] == 1) |
| 280 |
{ |
| 281 |
return true; |
| 282 |
} |
| 283 |
return false; |
| 284 |
} |
| 285 |
|
| 286 |
uint16_t |
| 287 |
HtOperations::GetRxHighestSupportedDataRate (void) const |
| 288 |
{ |
| 289 |
return m_rxHighestSupportedDataRate; |
| 290 |
} |
| 291 |
|
| 292 |
uint8_t |
| 293 |
HtOperations::GetTxMcsSetDefined (void) const |
| 294 |
{ |
| 295 |
return m_txMcsSetDefined; |
| 296 |
} |
| 297 |
|
| 298 |
uint8_t |
| 299 |
HtOperations::GetTxRxMcsSetUnequal (void) const |
| 300 |
{ |
| 301 |
return m_txRxMcsSetUnequal; |
| 302 |
} |
| 303 |
|
| 304 |
uint8_t |
| 305 |
HtOperations::GetTxMaxNSpatialStreams (void) const |
| 306 |
{ |
| 307 |
return m_txMaxNSpatialStreams; |
| 308 |
} |
| 309 |
|
| 310 |
uint8_t |
| 311 |
HtOperations::GetTxUnequalModulation (void) const |
| 312 |
{ |
| 313 |
return m_txUnequalModulation; |
| 314 |
} |
| 315 |
|
| 316 |
Buffer::Iterator |
| 317 |
HtOperations::Serialize (Buffer::Iterator i) const |
| 318 |
{ |
| 319 |
if (m_htSupported < 1) |
| 320 |
{ |
| 321 |
return i; |
| 322 |
} |
| 323 |
return WifiInformationElement::Serialize (i); |
| 324 |
} |
| 325 |
|
| 326 |
uint16_t |
| 327 |
HtOperations::GetSerializedSize () const |
| 328 |
{ |
| 329 |
if (m_htSupported < 1) |
| 330 |
{ |
| 331 |
return 0; |
| 332 |
} |
| 333 |
return WifiInformationElement::GetSerializedSize (); |
| 334 |
} |
| 335 |
|
| 336 |
uint8_t |
| 337 |
HtOperations::GetInformationSubset1 (void) const |
| 338 |
{ |
| 339 |
uint16_t val = 0; |
| 340 |
val |= m_secondaryChannelOffset & 0x03; |
| 341 |
val |= (m_staChannelWidth & 0x01) << 2; |
| 342 |
val |= (m_rifsMode & 0x01) << 3; |
| 343 |
val |= (m_reservedInformationSubset1 & 0x0f) << 4; |
| 344 |
return val; |
| 345 |
} |
| 346 |
|
| 347 |
void |
| 348 |
HtOperations::SetInformationSubset1 (uint8_t ctrl) |
| 349 |
{ |
| 350 |
m_secondaryChannelOffset = ctrl & 0x03; |
| 351 |
m_staChannelWidth = (ctrl >> 2) & 0x01; |
| 352 |
m_rifsMode = (ctrl >> 3) & 0x01; |
| 353 |
m_reservedInformationSubset1 = (ctrl >> 4) & 0x0f; |
| 354 |
} |
| 355 |
|
| 356 |
uint16_t |
| 357 |
HtOperations::GetInformationSubset2 (void) const |
| 358 |
{ |
| 359 |
uint16_t val = 0; |
| 360 |
val |= m_htProtection & 0x03; |
| 361 |
val |= (m_nonGfHtStasPresent & 0x01) << 2; |
| 362 |
val |= (m_reservedInformationSubset2_1 & 0x01) << 3; |
| 363 |
val |= (m_obssNonHtStasPresent & 0x01) << 4; |
| 364 |
val |= (m_reservedInformationSubset2_1 & 0x07ff) << 5; |
| 365 |
return val; |
| 366 |
} |
| 367 |
|
| 368 |
void |
| 369 |
HtOperations::SetInformationSubset2 (uint16_t ctrl) |
| 370 |
{ |
| 371 |
m_htProtection = ctrl & 0x03; |
| 372 |
m_nonGfHtStasPresent = (ctrl >> 2) & 0x01; |
| 373 |
m_reservedInformationSubset2_1 = (ctrl >> 3) & 0x01; |
| 374 |
m_obssNonHtStasPresent = (ctrl >> 4) & 0x01; |
| 375 |
m_reservedInformationSubset2_1 = (ctrl >> 5) & 0x07ff; |
| 376 |
} |
| 377 |
|
| 378 |
uint16_t |
| 379 |
HtOperations::GetInformationSubset3 (void) const |
| 380 |
{ |
| 381 |
uint16_t val = 0; |
| 382 |
val |= m_reservedInformationSubset3_1 & 0x3f; |
| 383 |
val |= (m_dualBeacon & 0x01) << 6; |
| 384 |
val |= (m_dualCtsProtection & 0x01) << 7; |
| 385 |
val |= (m_stbcBeacon & 0x01) << 8; |
| 386 |
val |= (m_lSigTxopProtectionFullSupport & 0x01) << 9; |
| 387 |
val |= (m_pcoActive & 0x01) << 10; |
| 388 |
val |= (m_pcoPhase & 0x01) << 11; |
| 389 |
val |= (m_reservedInformationSubset3_2 & 0x0f) << 12; |
| 390 |
return val; |
| 391 |
} |
| 392 |
|
| 393 |
void |
| 394 |
HtOperations::SetInformationSubset3 (uint16_t ctrl) |
| 395 |
{ |
| 396 |
m_reservedInformationSubset3_1 = ctrl & 0x3f; |
| 397 |
m_dualBeacon = (ctrl >> 6) & 0x01; |
| 398 |
m_dualCtsProtection = (ctrl >> 7) & 0x01; |
| 399 |
m_stbcBeacon = (ctrl >> 8) & 0x01; |
| 400 |
m_lSigTxopProtectionFullSupport = (ctrl >> 9) & 0x01; |
| 401 |
m_pcoActive = (ctrl >> 10) & 0x01; |
| 402 |
m_pcoPhase = (ctrl >> 11) & 0x01; |
| 403 |
m_reservedInformationSubset3_2 = (ctrl >> 12) & 0x0f; |
| 404 |
} |
| 405 |
|
| 406 |
void |
| 407 |
HtOperations::SetBasicMcsSet (uint64_t ctrl1, uint64_t ctrl2) |
| 408 |
{ |
| 409 |
for (uint64_t i = 0; i < 77; i++) |
| 410 |
{ |
| 411 |
if (i < 64) |
| 412 |
{ |
| 413 |
m_rxMcsBitmask[i] = (ctrl1 >> i) & 0x01; |
| 414 |
} |
| 415 |
else |
| 416 |
{ |
| 417 |
m_rxMcsBitmask[i] = (ctrl2 >> (i - 64)) & 0x01; |
| 418 |
} |
| 419 |
} |
| 420 |
m_reservedMcsSet1 = (ctrl2 >> 13) & 0x07; |
| 421 |
m_rxHighestSupportedDataRate = (ctrl2 >> 16) & 0x03ff; |
| 422 |
m_reservedMcsSet2 = (ctrl2 >> 26) & 0x3f; |
| 423 |
m_txMcsSetDefined = (ctrl2 >> 32) & 0x01; |
| 424 |
m_txRxMcsSetUnequal = (ctrl2 >> 33) & 0x01; |
| 425 |
m_txMaxNSpatialStreams = (ctrl2 >> 34) & 0x03; |
| 426 |
m_txUnequalModulation = (ctrl2 >> 36) & 0x01; |
| 427 |
m_reservedMcsSet3 = (ctrl2 >> 37) & 0x07ffffff; |
| 428 |
} |
| 429 |
|
| 430 |
uint64_t |
| 431 |
HtOperations::GetBasicMcsSet1 (void) const |
| 432 |
{ |
| 433 |
uint64_t val = 0; |
| 434 |
for (uint64_t i = 63; i > 0; i--) |
| 435 |
{ |
| 436 |
val = (val << 1) | (m_rxMcsBitmask[i] & 0x01); |
| 437 |
} |
| 438 |
val = (val << 1) | (m_rxMcsBitmask[0] & 0x01); |
| 439 |
return val; |
| 440 |
} |
| 441 |
|
| 442 |
uint64_t |
| 443 |
HtOperations::GetBasicMcsSet2 (void) const |
| 444 |
{ |
| 445 |
uint64_t val = 0; |
| 446 |
val = val | (m_reservedMcsSet3 & 0x07ffffff); |
| 447 |
val = (val << 1) | (m_txUnequalModulation & 0x01); |
| 448 |
val = (val << 2) | (m_txMaxNSpatialStreams & 0x03); |
| 449 |
val = (val << 1) | (m_txRxMcsSetUnequal & 0x01); |
| 450 |
val = (val << 1) | (m_txMcsSetDefined & 0x01); |
| 451 |
val = (val << 6) | (m_reservedMcsSet2 & 0x3f); |
| 452 |
val = (val << 10) | (m_rxHighestSupportedDataRate & 0x3ff); |
| 453 |
val = (val << 3) | (m_reservedMcsSet1 & 0x07); |
| 454 |
|
| 455 |
for (uint64_t i = 13; i > 0; i--) |
| 456 |
{ |
| 457 |
val = (val << 1) | ( m_rxMcsBitmask[i + 63] & 0x01); |
| 458 |
} |
| 459 |
return val; |
| 460 |
} |
| 461 |
|
| 462 |
void |
| 463 |
HtOperations::SerializeInformationField (Buffer::Iterator start) const |
| 464 |
{ |
| 465 |
if (m_htSupported == 1) |
| 466 |
{ |
| 467 |
//write the corresponding value for each bit |
| 468 |
start.WriteU8 (GetPrimaryChannel ()); |
| 469 |
start.WriteU8 (GetInformationSubset1 ()); |
| 470 |
start.WriteU16 (GetInformationSubset2 ()); |
| 471 |
start.WriteU16 (GetInformationSubset3 ()); |
| 472 |
start.WriteHtolsbU64 (GetBasicMcsSet1 ()); |
| 473 |
start.WriteHtolsbU64 (GetBasicMcsSet2 ()); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
uint8_t |
| 478 |
HtOperations::DeserializeInformationField (Buffer::Iterator start, |
| 479 |
uint8_t length) |
| 480 |
{ |
| 481 |
Buffer::Iterator i = start; |
| 482 |
uint8_t primarychannel = i.ReadU8 (); |
| 483 |
uint8_t informationsubset1 = i.ReadU8 (); |
| 484 |
uint8_t informationsubset2 = i.ReadU16 (); |
| 485 |
uint8_t informationsubset3 = i.ReadU16 (); |
| 486 |
uint64_t mcsset1 = i.ReadLsbtohU64 (); |
| 487 |
uint64_t mcsset2 = i.ReadLsbtohU64 (); |
| 488 |
SetPrimaryChannel (primarychannel); |
| 489 |
SetInformationSubset1 (informationsubset1); |
| 490 |
SetInformationSubset2 (informationsubset2); |
| 491 |
SetInformationSubset3 (informationsubset3); |
| 492 |
SetBasicMcsSet (mcsset1, mcsset2); |
| 493 |
return length; |
| 494 |
} |
| 495 |
|
| 496 |
ATTRIBUTE_HELPER_CPP (HtOperations); |
| 497 |
|
| 498 |
std::ostream & |
| 499 |
operator << (std::ostream &os, const HtOperations &htoperations) |
| 500 |
{ |
| 501 |
os << bool (htoperations.GetStaChannelWidth ()) |
| 502 |
<< "|" << bool (htoperations.GetRifsMode ()) |
| 503 |
<< "|" << bool (htoperations.GetDualCtsProtection()); |
| 504 |
|
| 505 |
return os; |
| 506 |
} |
| 507 |
|
| 508 |
std::istream &operator >> (std::istream &is, HtOperations &htoperations) |
| 509 |
{ |
| 510 |
bool c1, c2, c3; |
| 511 |
is >> c1 >> c2 >> c3; |
| 512 |
htoperations.SetStaChannelWidth (c1); |
| 513 |
htoperations.SetRifsMode (c2); |
| 514 |
htoperations.SetDualCtsProtection (c3); |
| 515 |
|
| 516 |
return is; |
| 517 |
} |
| 518 |
|
| 519 |
} //namespace ns3 |