A Discrete-Event Network Simulator
API
wifi-mac-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  */
22 
23 #include "ns3/nstime.h"
24 #include "ns3/address-utils.h"
25 #include "wifi-mac-header.h"
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (WifiMacHeader);
30 
32 enum
33 {
34  TYPE_MGT = 0,
35  TYPE_CTL = 1,
37 };
38 
40 enum
41 {
42  //Reserved: 0 - 6
51 };
52 
54  : m_ctrlMoreData (0),
55  m_ctrlWep (0),
56  m_ctrlOrder (0),
57  m_amsduPresent (0)
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68  m_ctrlFromDs = 1;
69 }
70 
71 void
73 {
74  m_ctrlFromDs = 0;
75 }
76 
77 void
79 {
80  m_ctrlToDs = 1;
81 }
82 
83 void
85 {
86  m_ctrlToDs = 0;
87 }
88 
89 void
91 {
92  m_addr1 = address;
93 }
94 
95 void
97 {
98  m_addr2 = address;
99 }
100 
101 void
103 {
104  m_addr3 = address;
105 }
106 
107 void
109 {
110  m_addr4 = address;
111 }
112 
113 void
114 WifiMacHeader::SetType (WifiMacType type, bool resetToDsFromDs)
115 {
116  switch (type)
117  {
121  break;
125  break;
129  break;
130  case WIFI_MAC_CTL_RTS:
133  break;
134  case WIFI_MAC_CTL_CTS:
137  break;
138  case WIFI_MAC_CTL_ACK:
141  break;
142  case WIFI_MAC_CTL_END:
145  break;
149  break;
152  m_ctrlSubtype = 0;
153  break;
156  m_ctrlSubtype = 1;
157  break;
160  m_ctrlSubtype = 2;
161  break;
164  m_ctrlSubtype = 3;
165  break;
168  m_ctrlSubtype = 4;
169  break;
172  m_ctrlSubtype = 5;
173  break;
174  case WIFI_MAC_MGT_BEACON:
176  m_ctrlSubtype = 8;
177  break;
180  m_ctrlSubtype = 10;
181  break;
184  m_ctrlSubtype = 11;
185  break;
188  m_ctrlSubtype = 12;
189  break;
190  case WIFI_MAC_MGT_ACTION:
192  m_ctrlSubtype = 13;
193  break;
196  m_ctrlSubtype = 14;
197  break;
200  m_ctrlSubtype = 15;
201  break;
202  case WIFI_MAC_DATA:
204  m_ctrlSubtype = 0;
205  break;
206  case WIFI_MAC_DATA_CFACK:
208  m_ctrlSubtype = 1;
209  break;
212  m_ctrlSubtype = 2;
213  break;
216  m_ctrlSubtype = 3;
217  break;
218  case WIFI_MAC_DATA_NULL:
220  m_ctrlSubtype = 4;
221  break;
224  m_ctrlSubtype = 5;
225  break;
228  m_ctrlSubtype = 6;
229  break;
232  m_ctrlSubtype = 7;
233  break;
234  case WIFI_MAC_QOSDATA:
236  m_ctrlSubtype = 8;
237  break;
240  m_ctrlSubtype = 9;
241  break;
244  m_ctrlSubtype = 10;
245  break;
248  m_ctrlSubtype = 11;
249  break;
252  m_ctrlSubtype = 12;
253  break;
256  m_ctrlSubtype = 14;
257  break;
260  m_ctrlSubtype = 15;
261  break;
262  }
263  if (resetToDsFromDs)
264  {
265  m_ctrlToDs = 0;
266  m_ctrlFromDs = 0;
267  }
268 }
269 
270 void
271 WifiMacHeader::SetRawDuration (uint16_t duration)
272 {
273  NS_ASSERT (duration <= 32768);
274  m_duration = duration;
275 }
276 
277 void
279 {
280  int64_t duration_us = static_cast<int64_t> (ceil (static_cast<double> (duration.GetNanoSeconds ()) / 1000));
281  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
282  m_duration = static_cast<uint16_t> (duration_us);
283 }
284 
285 void WifiMacHeader::SetId (uint16_t id)
286 {
287  m_duration = id;
288 }
289 
291 {
292  m_seqSeq = seq;
293 }
294 
296 {
297  m_seqFrag = frag;
298 }
299 
301 {
302  m_ctrlMoreFrag = 0;
303 }
304 
306 {
307  m_ctrlMoreFrag = 1;
308 }
309 
311 {
312  m_ctrlOrder = 1;
313 }
314 
316 {
317  m_ctrlOrder = 0;
318 }
319 
321 {
322  m_ctrlRetry = 1;
323 }
324 
326 {
327  m_ctrlRetry = 0;
328 }
329 
330 void WifiMacHeader::SetQosTid (uint8_t tid)
331 {
332  m_qosTid = tid;
333 }
334 
336 {
337  m_qosEosp = 1;
338 }
339 
341 {
342  m_qosEosp = 0;
343 }
344 
346 {
347  switch (policy)
348  {
349  case NORMAL_ACK:
350  m_qosAckPolicy = 0;
351  break;
352  case NO_ACK:
353  m_qosAckPolicy = 1;
354  break;
355  case NO_EXPLICIT_ACK:
356  m_qosAckPolicy = 2;
357  break;
358  case BLOCK_ACK:
359  m_qosAckPolicy = 3;
360  break;
361  }
362 }
363 
365 {
366  m_amsduPresent = 1;
367 }
368 
370 {
371  m_amsduPresent = 0;
372 }
373 
375 {
376  m_qosStuff = txop;
377 }
378 
380 {
381  //Mark bit 0 of this variable instead of bit 8, since m_qosStuff is
382  //shifted by one byte when serialized
383  m_qosStuff = m_qosStuff | 0x01; //bit 8 of QoS Control Field
384 }
385 
387 {
388  //Clear bit 0 of this variable instead of bit 8, since m_qosStuff is
389  //shifted by one byte when serialized
390  m_qosStuff = m_qosStuff & 0xfe; //bit 8 of QoS Control Field
391 }
392 
393 
396 {
397  return m_addr1;
398 }
399 
402 {
403  return m_addr2;
404 }
405 
408 {
409  return m_addr3;
410 }
411 
414 {
415  return m_addr4;
416 }
417 
420 {
421  switch (m_ctrlType)
422  {
423  case TYPE_MGT:
424  switch (m_ctrlSubtype)
425  {
426  case 0:
428  case 1:
430  case 2:
432  case 3:
434  case 4:
436  case 5:
438  case 8:
439  return WIFI_MAC_MGT_BEACON;
440  case 10:
442  case 11:
444  case 12:
446  case 13:
447  return WIFI_MAC_MGT_ACTION;
448  case 14:
450  case 15:
452  }
453  break;
454  case TYPE_CTL:
455  switch (m_ctrlSubtype)
456  {
457  case SUBTYPE_CTL_BACKREQ:
458  return WIFI_MAC_CTL_BACKREQ;
460  return WIFI_MAC_CTL_BACKRESP;
461  case SUBTYPE_CTL_RTS:
462  return WIFI_MAC_CTL_RTS;
463  case SUBTYPE_CTL_CTS:
464  return WIFI_MAC_CTL_CTS;
465  case SUBTYPE_CTL_ACK:
466  return WIFI_MAC_CTL_ACK;
467  case SUBTYPE_CTL_END:
468  return WIFI_MAC_CTL_END;
469  case SUBTYPE_CTL_END_ACK:
470  return WIFI_MAC_CTL_END_ACK;
471  }
472  break;
473  case TYPE_DATA:
474  switch (m_ctrlSubtype)
475  {
476  case 0:
477  return WIFI_MAC_DATA;
478  case 1:
479  return WIFI_MAC_DATA_CFACK;
480  case 2:
481  return WIFI_MAC_DATA_CFPOLL;
482  case 3:
484  case 4:
485  return WIFI_MAC_DATA_NULL;
486  case 5:
488  case 6:
490  case 7:
492  case 8:
493  return WIFI_MAC_QOSDATA;
494  case 9:
495  return WIFI_MAC_QOSDATA_CFACK;
496  case 10:
498  case 11:
500  case 12:
501  return WIFI_MAC_QOSDATA_NULL;
502  case 14:
504  case 15:
506  }
507  break;
508  }
509  // NOTREACHED
510  NS_ASSERT (false);
511  return (WifiMacType) - 1;
512 }
513 
514 bool
516 {
517  return m_ctrlFromDs == 1;
518 }
519 
520 bool
522 {
523  return m_ctrlToDs == 1;
524 }
525 
526 bool
528 {
529  return (m_ctrlType == TYPE_DATA);
530 
531 }
532 
533 bool
535 {
536  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
537 }
538 
539 bool
541 {
542  return (m_ctrlType == TYPE_CTL);
543 }
544 
545 bool
547 {
548  return (m_ctrlType == TYPE_MGT);
549 }
550 
551 bool
553 {
554  switch (GetType ())
555  {
564  return true;
565  default:
566  return false;
567  }
568 }
569 
570 bool
572 {
573  switch (GetType ())
574  {
575  case WIFI_MAC_CTL_END:
577  return true;
578  default:
579  return false;
580  }
581 }
582 
583 bool
585 {
586  switch (GetType ())
587  {
588  case WIFI_MAC_DATA_CFACK:
593  return true;
594  default:
595  return false;
596  break;
597  }
598 }
599 
600 bool
602 {
603  switch (GetType ())
604  {
605  case WIFI_MAC_DATA:
606  case WIFI_MAC_DATA_CFACK:
609  case WIFI_MAC_QOSDATA:
613  return true;
614  default:
615  return false;
616  }
617 }
618 
619 bool
621 {
622  return (GetType () == WIFI_MAC_CTL_RTS);
623 }
624 
625 bool
627 {
628  return (GetType () == WIFI_MAC_CTL_CTS);
629 }
630 
631 bool
633 {
634  return (GetType () == WIFI_MAC_CTL_ACK);
635 }
636 
637 bool
639 {
641 }
642 
643 bool
645 {
647 }
648 
649 bool
651 {
653 }
654 
655 bool
657 {
659 }
660 
661 bool
663 {
664  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
665 }
666 
667 bool
669 {
670  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
671 }
672 
673 bool
675 {
676  return (GetType () == WIFI_MAC_MGT_BEACON);
677 }
678 
679 bool
681 {
682  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
683 }
684 
685 bool
687 {
688  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
689 }
690 
691 bool
693 {
694  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
695 }
696 
697 bool
699 {
700  return (GetType () == WIFI_MAC_MGT_ACTION);
701 }
702 
703 bool
705 {
706  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
707 }
708 
709 bool
711 {
712  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
713 }
714 
715 bool
717 {
718  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
719 }
720 
721 uint16_t
723 {
724  return m_duration;
725 }
726 
727 Time
729 {
730  return MicroSeconds (m_duration);
731 }
732 
733 uint16_t
735 {
736  return (m_seqSeq << 4) | m_seqFrag;
737 }
738 
739 uint16_t
741 {
742  return m_seqSeq;
743 }
744 
745 uint8_t
747 {
748  return m_seqFrag;
749 }
750 
751 bool
753 {
754  return (m_ctrlRetry == 1);
755 }
756 
757 bool
759 {
760  return (m_ctrlMoreFrag == 1);
761 }
762 
763 bool
765 {
766  NS_ASSERT (IsQosData ());
767  return (m_qosAckPolicy == 3);
768 }
769 
770 bool
772 {
773  NS_ASSERT (IsQosData ());
774  return (m_qosAckPolicy == 1);
775 }
776 
777 bool
779 {
780  NS_ASSERT (IsQosData ());
781  return (m_qosAckPolicy == 0);
782 }
783 
784 bool
786 {
787  NS_ASSERT (IsQosData ());
788  return (m_qosEosp == 1);
789 }
790 
791 bool
793 {
794  NS_ASSERT (IsQosData ());
795  return (m_amsduPresent == 1);
796 }
797 
798 uint8_t
800 {
801  NS_ASSERT (IsQosData ());
802  return m_qosTid;
803 }
804 
805 uint16_t
807 {
808  uint16_t val = 0;
809  val |= (m_ctrlType << 2) & (0x3 << 2);
810  val |= (m_ctrlSubtype << 4) & (0xf << 4);
811  val |= (m_ctrlToDs << 8) & (0x1 << 8);
812  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
813  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
814  val |= (m_ctrlRetry << 11) & (0x1 << 11);
815  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
816  val |= (m_ctrlWep << 14) & (0x1 << 14);
817  val |= (m_ctrlOrder << 15) & (0x1 << 15);
818  return val;
819 }
820 
821 uint16_t
823 {
824  uint16_t val = 0;
825  val |= m_qosTid;
826  val |= m_qosEosp << 4;
827  val |= m_qosAckPolicy << 5;
828  val |= m_amsduPresent << 7;
829  val |= m_qosStuff << 8;
830  return val;
831 }
832 
833 void
835 {
836  m_ctrlType = (ctrl >> 2) & 0x03;
837  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
838  m_ctrlToDs = (ctrl >> 8) & 0x01;
839  m_ctrlFromDs = (ctrl >> 9) & 0x01;
840  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
841  m_ctrlRetry = (ctrl >> 11) & 0x01;
842  m_ctrlMoreData = (ctrl >> 13) & 0x01;
843  m_ctrlWep = (ctrl >> 14) & 0x01;
844  m_ctrlOrder = (ctrl >> 15) & 0x01;
845 }
846 void
848 {
849  m_seqFrag = seq & 0x0f;
850  m_seqSeq = (seq >> 4) & 0x0fff;
851 }
852 void
854 {
855  m_qosTid = qos & 0x000f;
856  m_qosEosp = (qos >> 4) & 0x0001;
857  m_qosAckPolicy = (qos >> 5) & 0x0003;
858  m_amsduPresent = (qos >> 7) & 0x0001;
859  m_qosStuff = (qos >> 8) & 0x00ff;
860 }
861 
862 uint32_t
864 {
865  uint32_t size = 0;
866  switch (m_ctrlType)
867  {
868  case TYPE_MGT:
869  size = 2 + 2 + 6 + 6 + 6 + 2;
870  break;
871  case TYPE_CTL:
872  switch (m_ctrlSubtype)
873  {
874  case SUBTYPE_CTL_RTS:
875  case SUBTYPE_CTL_BACKREQ:
877  case SUBTYPE_CTL_END:
878  case SUBTYPE_CTL_END_ACK:
879  size = 2 + 2 + 6 + 6;
880  break;
881  case SUBTYPE_CTL_CTS:
882  case SUBTYPE_CTL_ACK:
883  size = 2 + 2 + 6;
884  break;
886  size = 2 + 2 + 6 + 2 + 4;
887  break;
888  }
889  break;
890  case TYPE_DATA:
891  size = 2 + 2 + 6 + 6 + 6 + 2;
892  if (m_ctrlToDs && m_ctrlFromDs)
893  {
894  size += 6;
895  }
896  if (m_ctrlSubtype & 0x08)
897  {
898  size += 2;
899  }
900  break;
901  }
902  return size;
903 }
904 
905 const char *
907 {
908 #define FOO(x) \
909 case WIFI_MAC_ ## x: \
910  return # x; \
911  break;
912 
913  switch (GetType ())
914  {
915  FOO (CTL_RTS);
916  FOO (CTL_CTS);
917  FOO (CTL_ACK);
918  FOO (CTL_BACKREQ);
919  FOO (CTL_BACKRESP);
920  FOO (CTL_END);
921  FOO (CTL_END_ACK);
922 
923  FOO (MGT_BEACON);
924  FOO (MGT_ASSOCIATION_REQUEST);
925  FOO (MGT_ASSOCIATION_RESPONSE);
926  FOO (MGT_DISASSOCIATION);
927  FOO (MGT_REASSOCIATION_REQUEST);
928  FOO (MGT_REASSOCIATION_RESPONSE);
929  FOO (MGT_PROBE_REQUEST);
930  FOO (MGT_PROBE_RESPONSE);
931  FOO (MGT_AUTHENTICATION);
932  FOO (MGT_DEAUTHENTICATION);
933  FOO (MGT_ACTION);
934  FOO (MGT_ACTION_NO_ACK);
935  FOO (MGT_MULTIHOP_ACTION);
936 
937  FOO (DATA);
938  FOO (DATA_CFACK);
939  FOO (DATA_CFPOLL);
940  FOO (DATA_CFACK_CFPOLL);
941  FOO (DATA_NULL);
942  FOO (DATA_NULL_CFACK);
943  FOO (DATA_NULL_CFPOLL);
944  FOO (DATA_NULL_CFACK_CFPOLL);
945  FOO (QOSDATA);
946  FOO (QOSDATA_CFACK);
947  FOO (QOSDATA_CFPOLL);
948  FOO (QOSDATA_CFACK_CFPOLL);
949  FOO (QOSDATA_NULL);
950  FOO (QOSDATA_NULL_CFPOLL);
951  FOO (QOSDATA_NULL_CFACK_CFPOLL);
952  default:
953  return "ERROR";
954  }
955 #undef FOO
956 #ifndef _WIN32
957  // needed to make gcc 4.0.1 ppc darwin happy.
958  return "BIG_ERROR";
959 #endif
960 }
961 
962 TypeId
964 {
965  static TypeId tid = TypeId ("ns3::WifiMacHeader")
966  .SetParent<Header> ()
967  .SetGroupName ("Wifi")
968  .AddConstructor<WifiMacHeader> ()
969  ;
970  return tid;
971 }
972 
973 TypeId
975 {
976  return GetTypeId ();
977 }
978 
979 void
980 WifiMacHeader::PrintFrameControl (std::ostream &os) const
981 {
982  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
983  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
984  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
985  ;
986 }
987 
988 void
989 WifiMacHeader::Print (std::ostream &os) const
990 {
991  os << GetTypeString () << " ";
992  switch (GetType ())
993  {
994  case WIFI_MAC_CTL_RTS:
995  os << "Duration/ID=" << m_duration << "us"
996  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
997  break;
998  case WIFI_MAC_CTL_CTS:
999  case WIFI_MAC_CTL_ACK:
1000  os << "Duration/ID=" << m_duration << "us"
1001  << ", RA=" << m_addr1;
1002  break;
1003  case WIFI_MAC_MGT_BEACON:
1013  PrintFrameControl (os);
1014  os << " Duration/ID=" << m_duration << "us"
1015  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1016  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1017  << ", SeqNumber=" << m_seqSeq;
1018  break;
1019  case WIFI_MAC_MGT_ACTION:
1021  PrintFrameControl (os);
1022  os << " Duration/ID=" << m_duration << "us"
1023  << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1024  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1025  break;
1027  os << " Duration/ID=" << m_duration << "us"
1028  << ", RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1029  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1030  break;
1031  case WIFI_MAC_DATA:
1032  PrintFrameControl (os);
1033  os << " Duration/ID=" << m_duration << "us";
1034  if (!m_ctrlToDs && !m_ctrlFromDs)
1035  {
1036  os << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1037  }
1038  else if (!m_ctrlToDs && m_ctrlFromDs)
1039  {
1040  os << ", DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1041  }
1042  else if (m_ctrlToDs && !m_ctrlFromDs)
1043  {
1044  os << ", DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1045  }
1046  else if (m_ctrlToDs && m_ctrlFromDs)
1047  {
1048  os << ", DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1049  }
1050  else
1051  {
1052  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1053  }
1054  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1055  << ", SeqNumber=" << m_seqSeq;
1056  break;
1057  case WIFI_MAC_CTL_BACKREQ:
1058  case WIFI_MAC_CTL_BACKRESP:
1060  case WIFI_MAC_CTL_END:
1061  case WIFI_MAC_CTL_END_ACK:
1062  case WIFI_MAC_DATA_CFACK:
1063  case WIFI_MAC_DATA_CFPOLL:
1065  case WIFI_MAC_DATA_NULL:
1069  case WIFI_MAC_QOSDATA:
1073  case WIFI_MAC_QOSDATA_NULL:
1076  default:
1077  break;
1078  }
1079 }
1080 
1081 uint32_t
1083 {
1084  return GetSize ();
1085 }
1086 
1087 void
1089 {
1092  WriteTo (i, m_addr1);
1093  switch (m_ctrlType)
1094  {
1095  case TYPE_MGT:
1096  WriteTo (i, m_addr2);
1097  WriteTo (i, m_addr3);
1099  break;
1100  case TYPE_CTL:
1101  switch (m_ctrlSubtype)
1102  {
1103  case SUBTYPE_CTL_RTS:
1104  case SUBTYPE_CTL_BACKREQ:
1105  case SUBTYPE_CTL_BACKRESP:
1106  case SUBTYPE_CTL_END:
1107  case SUBTYPE_CTL_END_ACK:
1108  WriteTo (i, m_addr2);
1109  break;
1110  case SUBTYPE_CTL_CTS:
1111  case SUBTYPE_CTL_ACK:
1112  break;
1113  default:
1114  //NOTREACHED
1115  NS_ASSERT (false);
1116  break;
1117  }
1118  break;
1119  case TYPE_DATA:
1120  {
1121  WriteTo (i, m_addr2);
1122  WriteTo (i, m_addr3);
1124  if (m_ctrlToDs && m_ctrlFromDs)
1125  {
1126  WriteTo (i, m_addr4);
1127  }
1128  if (m_ctrlSubtype & 0x08)
1129  {
1131  }
1132  } break;
1133  default:
1134  //NOTREACHED
1135  NS_ASSERT (false);
1136  break;
1137  }
1138 }
1139 
1140 uint32_t
1142 {
1143  Buffer::Iterator i = start;
1144  uint16_t frame_control = i.ReadLsbtohU16 ();
1145  SetFrameControl (frame_control);
1146  m_duration = i.ReadLsbtohU16 ();
1147  ReadFrom (i, m_addr1);
1148  switch (m_ctrlType)
1149  {
1150  case TYPE_MGT:
1151  ReadFrom (i, m_addr2);
1152  ReadFrom (i, m_addr3);
1154  break;
1155  case TYPE_CTL:
1156  switch (m_ctrlSubtype)
1157  {
1158  case SUBTYPE_CTL_RTS:
1159  case SUBTYPE_CTL_BACKREQ:
1160  case SUBTYPE_CTL_BACKRESP:
1161  case SUBTYPE_CTL_END:
1162  case SUBTYPE_CTL_END_ACK:
1163  ReadFrom (i, m_addr2);
1164  break;
1165  case SUBTYPE_CTL_CTS:
1166  case SUBTYPE_CTL_ACK:
1167  break;
1168  }
1169  break;
1170  case TYPE_DATA:
1171  ReadFrom (i, m_addr2);
1172  ReadFrom (i, m_addr3);
1174  if (m_ctrlToDs && m_ctrlFromDs)
1175  {
1176  ReadFrom (i, m_addr4);
1177  }
1178  if (m_ctrlSubtype & 0x08)
1179  {
1181  }
1182  break;
1183  }
1184  return i.GetDistanceFrom (start);
1185 }
1186 
1187 } //namespace ns3
uint8_t m_ctrlMoreData
control more data
Protocol header serialization and deserialization.
Definition: header.h:42
bool IsRetry(void) const
Return if the Retry bit is set.
void SetRetry(void)
Set the Retry bit in the Frame Control field.
bool IsCfEnd(void) const
Return true if the header is a CF-END header.
bool IsDisassociation(void) const
Return true if the header is a Disassociation header.
void SetMoreFragments(void)
Set the More Fragment bit in the Frame Control field.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint16_t GetFrameControl(void) const
Return the raw Frame Control field.
void SetRawDuration(uint16_t duration)
Set the Duration/ID field with the given raw uint16_t value.
void SetFrameControl(uint16_t control)
Set the Frame Control field with the given raw value.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetDuration(Time duration)
Set the Duration/ID field with the given duration (Time object).
bool IsCtl(void) const
Return true if the Type is Control.
uint8_t m_ctrlType
control type
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1844
Mac48Address m_addr2
address 2
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
void SetNoMoreFragments(void)
Un-set the More Fragment bit in the Frame Control Field.
uint8_t m_qosAckPolicy
QOS ack policy.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#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
bool IsQosEosp(void) const
Return if the end of service period (EOSP) is set.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint8_t m_qosEosp
QOS EOSP.
void Print(std::ostream &os) const
void SetId(uint16_t id)
Set the Duration/ID field with the given ID.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
void SetQosControl(uint16_t qos)
Set the QoS Control field with the given raw value.
const char * GetTypeString(void) const
Return a string corresponds to the header type.
bool IsCfPoll(void) const
Return true if the Type/Subtype is one of the possible CF-Poll headers.
uint8_t m_seqFrag
sequence fragment
Mac48Address m_addr1
address 1
Mac48Address m_addr3
address 3
iterator in a Buffer instance
Definition: buffer.h:98
bool IsBlockAck(void) const
Return true if the header is a Block ACK header.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
bool IsBlockAckReq(void) const
Return true if the header is a Block ACK Request header.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
uint8_t m_ctrlToDs
control to DS
bool IsQosNoAck(void) const
Return if the QoS ACK policy is No ACK.
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
bool IsBeacon(void) const
Return true if the header is a Beacon header.
void SetAddr4(Mac48Address address)
Fill the Address 4 field with the given address.
WifiMacType
Combination of valid MAC header type/subtype.
bool IsMultihopAction() const
Check if the header is a Multihop action header.
void SetOrder(void)
Set order bit in the frame control field.
bool IsFromDs(void) const
Mac48Address GetAddr3(void) const
Return the address in the Address 3 field.
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
bool IsCts(void) const
Return true if the header is a CTS header.
void Serialize(Buffer::Iterator start) const
uint8_t m_amsduPresent
AMSDU present.
Mac48Address m_addr4
address 4
uint8_t m_ctrlMoreFrag
control more fragments
uint8_t m_ctrlFromDs
control from DS
bool IsAssocResp(void) const
Return true if the header is an Association Response header.
bool IsQosAck(void) const
Return if the QoS ACK policy is Normal ACK.
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
uint8_t m_ctrlOrder
control order (set to 1 for QoS Data and Management frames to signify that HT/VHT/HE control field is...
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Mac48Address GetAddr4(void) const
Return the address in the Address 4 field.
void SetSequenceControl(uint16_t seq)
Set the Sequence Control field with the given raw value.
bool IsCfAck(void) const
Return true if the header is a CF-ACK header.
void SetNoRetry(void)
Un-set the Retry bit in the Frame Control field.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
bool IsData(void) const
Return true if the Type is DATA.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
address
Definition: first.py:37
uint16_t m_seqSeq
sequence sequence
uint8_t m_qosStuff
QOS stuff.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
Time GetDuration(void) const
Return the duration from the Duration/ID field (Time object).
bool IsProbeReq(void) const
Return true if the header is a Probe Request header.
an EUI-48 address
Definition: mac48-address.h:43
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
QosAckPolicy
ACK policy for QoS frames.
#define FOO(x)
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:910
bool IsMoreFragments(void) const
Return if the More Fragment bit is set.
uint16_t m_duration
duration
uint16_t GetRawDuration(void) const
Return the raw duration from the Duration/ID field.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
uint8_t m_ctrlRetry
control retry
bool IsQosBlockAck(void) const
Return if the QoS ACK policy is Block ACK.
uint16_t GetQosControl(void) const
Return the raw QoS Control field.
bool IsDeauthentication(void) const
Return true if the header is a Deauthentication header.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
bool IsMgt(void) const
Return true if the Type is Management.
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
bool IsProbeResp(void) const
Return true if the header is a Probe Response header.
uint32_t GetSerializedSize(void) const
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
bool IsReassocReq(void) const
Return true if the header is a Reassociation Request header.
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
void SetQosEosp()
Set the end of service period (EOSP) bit in the QoS control field.
bool IsRts(void) const
Return true if the header is a RTS header.
uint32_t Deserialize(Buffer::Iterator start)
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
void SetNoOrder(void)
Unset order bit in the frame control field.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1065
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
bool IsAck(void) const
Return true if the header is an ACK header.
bool IsAction() const
Return true if the header is an Action header.
uint8_t m_qosTid
QOS TID.
void SetQosMeshControlPresent()
Set the Mesh Control Present flag for the QoS header.
void SetQosNoMeshControlPresent()
Clear the Mesh Control Present flag for the QoS header.
uint8_t m_ctrlSubtype
control subtype
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
static TypeId GetTypeId(void)
Get the type ID.
bool IsAuthentication(void) const
Return true if the header is an Authentication header.
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetQosAmsdu(void)
Set that A-MSDU is present.
void PrintFrameControl(std::ostream &os) const
Print the Frame Control field to the output stream.
Implements the IEEE 802.11 MAC header.
bool IsToDs(void) const
uint8_t m_ctrlWep
control WEP
bool IsReassocResp(void) const
Return true if the header is a Reassociation Response header.
bool HasData(void) const
Return true if the header type is DATA and is not DATA_NULL.
uint16_t GetSequenceControl(void) const
Return the raw Sequence Control field.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.