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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #include "ns3/assert.h"
23 #include "ns3/address-utils.h"
24 #include "wifi-mac-header.h"
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (WifiMacHeader);
29 
30 enum
31 {
32  TYPE_MGT = 0,
33  TYPE_CTL = 1,
35 };
36 
37 enum
38 {
45 
46 };
47 
49  : m_ctrlMoreData (0),
50  m_ctrlWep (0),
51  m_ctrlOrder (1),
52  m_amsduPresent (0)
53 {
54 }
56 {
57 }
58 
59 void
61 {
62  m_ctrlFromDs = 1;
63 }
64 
65 void
67 {
68  m_ctrlFromDs = 0;
69 }
70 
71 void
73 {
74  m_ctrlToDs = 1;
75 }
76 
77 void
79 {
80  m_ctrlToDs = 0;
81 }
82 
83 void
85 {
86  m_addr1 = address;
87 }
88 
89 void
91 {
92  m_addr2 = address;
93 }
94 
95 void
97 {
98  m_addr3 = address;
99 }
100 
101 void
103 {
104  m_addr4 = address;
105 }
106 
107 void
109 {
111  m_ctrlSubtype = 0;
112 }
113 
114 void
116 {
118  m_ctrlSubtype = 1;
119 }
120 
121 void
123 {
125  m_ctrlSubtype = 4;
126 }
127 
128 void
130 {
132  m_ctrlSubtype = 5;
133 }
134 
135 void
137 {
139  m_ctrlSubtype = 8;
140 }
141 
142 void
144 {
146  m_ctrlSubtype = 8;
147 }
148 
149 void
151 {
153  m_ctrlSubtype = 9;
154 }
155 
156 void
158 {
160  m_ctrlSubtype = 0;
161 }
162 
163 void
165 {
167  m_ctrlSubtype = 0x0D;
168 }
169 
170 void
172 {
174  m_ctrlSubtype = 0x0F;
175 }
176 
177 void
179 {
180  switch (type)
181  {
185  break;
189  break;
190  case WIFI_MAC_CTL_RTS:
193  break;
194  case WIFI_MAC_CTL_CTS:
197  break;
198  case WIFI_MAC_CTL_ACK:
201  break;
205  break;
208  m_ctrlSubtype = 0;
209  break;
212  m_ctrlSubtype = 1;
213  break;
216  m_ctrlSubtype = 2;
217  break;
220  m_ctrlSubtype = 3;
221  break;
224  m_ctrlSubtype = 4;
225  break;
228  m_ctrlSubtype = 5;
229  break;
230  case WIFI_MAC_MGT_BEACON:
232  m_ctrlSubtype = 8;
233  break;
236  m_ctrlSubtype = 10;
237  break;
240  m_ctrlSubtype = 11;
241  break;
244  m_ctrlSubtype = 12;
245  break;
246  case WIFI_MAC_MGT_ACTION:
248  m_ctrlSubtype = 13;
249  break;
252  m_ctrlSubtype = 14;
253  break;
256  m_ctrlSubtype = 15;
257  break;
258 
259  case WIFI_MAC_DATA:
261  m_ctrlSubtype = 0;
262  break;
263  case WIFI_MAC_DATA_CFACK:
265  m_ctrlSubtype = 1;
266  break;
269  m_ctrlSubtype = 2;
270  break;
273  m_ctrlSubtype = 3;
274  break;
275  case WIFI_MAC_DATA_NULL:
277  m_ctrlSubtype = 4;
278  break;
281  m_ctrlSubtype = 5;
282  break;
285  m_ctrlSubtype = 6;
286  break;
289  m_ctrlSubtype = 7;
290  break;
291  case WIFI_MAC_QOSDATA:
293  m_ctrlSubtype = 8;
294  break;
297  m_ctrlSubtype = 9;
298  break;
301  m_ctrlSubtype = 10;
302  break;
305  m_ctrlSubtype = 11;
306  break;
309  m_ctrlSubtype = 12;
310  break;
313  m_ctrlSubtype = 14;
314  break;
317  m_ctrlSubtype = 15;
318  break;
319  }
320  m_ctrlToDs = 0;
321  m_ctrlFromDs = 0;
322 }
323 
324 void
325 WifiMacHeader::SetRawDuration (uint16_t duration)
326 {
327  m_duration = duration;
328 }
329 
330 void
332 {
333  int64_t duration_us = ceil ((double)duration.GetNanoSeconds () / 1000);
334  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
335  m_duration = static_cast<uint16_t> (duration_us);
336 }
337 
338 void WifiMacHeader::SetId (uint16_t id)
339 {
340  m_duration = id;
341 }
342 
344 {
345  m_seqSeq = seq;
346 }
347 
349 {
350  m_seqFrag = frag;
351 }
352 
354 {
355  m_ctrlMoreFrag = 0;
356 }
357 
359 {
360  m_ctrlMoreFrag = 1;
361 }
362 
364 {
365  m_ctrlOrder = 1;
366 }
367 
369 {
370  m_ctrlOrder = 0;
371 }
372 
374 {
375  m_ctrlRetry = 1;
376 }
377 
379 {
380  m_ctrlRetry = 0;
381 }
382 
383 void WifiMacHeader::SetQosTid (uint8_t tid)
384 {
385  m_qosTid = tid;
386 }
387 
389 {
390  m_qosEosp = 1;
391 }
392 
394 {
395  m_qosEosp = 0;
396 }
397 
399 {
400  switch (policy)
401  {
402  case NORMAL_ACK:
403  m_qosAckPolicy = 0;
404  break;
405  case NO_ACK:
406  m_qosAckPolicy = 1;
407  break;
408  case NO_EXPLICIT_ACK:
409  m_qosAckPolicy = 2;
410  break;
411  case BLOCK_ACK:
412  m_qosAckPolicy = 3;
413  break;
414  }
415 }
416 
417 void
419 {
420  m_qosAckPolicy = 0;
421 }
422 
423 void
425 {
426  m_qosAckPolicy = 3;
427 }
428 
429 void
431 {
432  m_qosAckPolicy = 1;
433 }
434 
436 {
437  m_amsduPresent = 1;
438 }
439 
441 {
442  m_amsduPresent = 0;
443 }
444 
446 {
447  m_qosStuff = txop;
448 }
449 
451 {
452  // mark bit 0 of this variable instead of bit 8, since m_qosStuff is
453  // shifted by one byte when serialized
454  m_qosStuff = m_qosStuff | 0x01; // bit 8 of QoS Control Field
455 }
456 
458 {
459  // clear bit 0 of this variable instead of bit 8, since m_qosStuff is
460  // shifted by one byte when serialized
461  m_qosStuff = m_qosStuff & 0xfe; // bit 8 of QoS Control Field
462 }
463 
464 
467 {
468  return m_addr1;
469 }
470 
473 {
474  return m_addr2;
475 }
476 
479 {
480  return m_addr3;
481 }
482 
485 {
486  return m_addr4;
487 }
488 
489 enum WifiMacType
491 {
492  switch (m_ctrlType)
493  {
494  case TYPE_MGT:
495  switch (m_ctrlSubtype)
496  {
497  case 0:
499  break;
500  case 1:
502  break;
503  case 2:
505  break;
506  case 3:
508  break;
509  case 4:
511  break;
512  case 5:
514  break;
515  case 8:
516  return WIFI_MAC_MGT_BEACON;
517  break;
518  case 10:
520  break;
521  case 11:
523  break;
524  case 12:
526  break;
527  case 13:
528  return WIFI_MAC_MGT_ACTION;
529  break;
530  case 14:
532  break;
533  case 15:
535  break;
536  }
537  break;
538  case TYPE_CTL:
539  switch (m_ctrlSubtype)
540  {
541  case SUBTYPE_CTL_BACKREQ:
542  return WIFI_MAC_CTL_BACKREQ;
543  break;
545  return WIFI_MAC_CTL_BACKRESP;
546  break;
547  case SUBTYPE_CTL_RTS:
548  return WIFI_MAC_CTL_RTS;
549  break;
550  case SUBTYPE_CTL_CTS:
551  return WIFI_MAC_CTL_CTS;
552  break;
553  case SUBTYPE_CTL_ACK:
554  return WIFI_MAC_CTL_ACK;
555  break;
556  }
557  break;
558  case TYPE_DATA:
559  switch (m_ctrlSubtype)
560  {
561  case 0:
562  return WIFI_MAC_DATA;
563  break;
564  case 1:
565  return WIFI_MAC_DATA_CFACK;
566  break;
567  case 2:
568  return WIFI_MAC_DATA_CFPOLL;
569  break;
570  case 3:
572  break;
573  case 4:
574  return WIFI_MAC_DATA_NULL;
575  break;
576  case 5:
578  break;
579  case 6:
581  break;
582  case 7:
584  break;
585  case 8:
586  return WIFI_MAC_QOSDATA;
587  break;
588  case 9:
589  return WIFI_MAC_QOSDATA_CFACK;
590  break;
591  case 10:
593  break;
594  case 11:
596  break;
597  case 12:
598  return WIFI_MAC_QOSDATA_NULL;
599  break;
600  case 14:
602  break;
603  case 15:
605  break;
606  }
607  break;
608  }
609  // NOTREACHED
610  NS_ASSERT (false);
611  return (enum WifiMacType) -1;
612 }
613 
614 bool
616 {
617  return m_ctrlFromDs == 1;
618 }
619 
620 bool
622 {
623  return m_ctrlToDs == 1;
624 }
625 
626 bool
628 {
629  return (m_ctrlType == TYPE_DATA);
630 
631 }
632 
633 bool
635 {
636  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
637 }
638 
639 bool
641 {
642  return (m_ctrlType == TYPE_CTL);
643 }
644 
645 bool
647 {
648  return (m_ctrlType == TYPE_MGT);
649 }
650 
651 bool
653 {
654  switch (GetType ())
655  {
664  return true;
665  break;
666  default:
667  return false;
668  break;
669  }
670 }
671 
672 bool
674 {
675  return (GetType () == WIFI_MAC_CTL_RTS);
676 }
677 
678 bool
680 {
681  return (GetType () == WIFI_MAC_CTL_CTS);
682 }
683 
684 bool
686 {
687  return (GetType () == WIFI_MAC_CTL_ACK);
688 }
689 
690 bool
692 {
694 }
695 
696 bool
698 {
700 }
701 
702 bool
704 {
706 }
707 
708 bool
710 {
712 }
713 
714 bool
716 {
717  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
718 }
719 
720 bool
722 {
723  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
724 }
725 
726 bool
728 {
729  return (GetType () == WIFI_MAC_MGT_BEACON);
730 }
731 
732 bool
734 {
735  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
736 }
737 
738 bool
740 {
741  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
742 }
743 
744 bool
746 {
747  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
748 }
749 
750 bool
752 {
753  return (GetType () == WIFI_MAC_MGT_ACTION);
754 }
755 
756 bool
758 {
759  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
760 }
761 
762 bool
764 {
765  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
766 }
767 
768 bool
770 {
771  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
772 }
773 
774 uint16_t
776 {
777  return m_duration;
778 }
779 
780 Time
782 {
783  return MicroSeconds (m_duration);
784 }
785 
786 uint16_t
788 {
789  return (m_seqSeq << 4) | m_seqFrag;
790 }
791 
792 uint16_t
794 {
795  return m_seqSeq;
796 }
797 
798 uint16_t
800 {
801  return m_seqFrag;
802 }
803 
804 bool
806 {
807  return (m_ctrlRetry == 1);
808 }
809 
810 bool
812 {
813  return (m_ctrlMoreFrag == 1);
814 }
815 
816 bool
818 {
819  NS_ASSERT (IsQosData ());
820  return (m_qosAckPolicy == 3);
821 }
822 
823 bool
825 {
826  NS_ASSERT (IsQosData ());
827  return (m_qosAckPolicy == 1);
828 }
829 
830 bool
832 {
833  NS_ASSERT (IsQosData ());
834  return (m_qosAckPolicy == 0);
835 }
836 
837 bool
839 {
840  NS_ASSERT (IsQosData ());
841  return (m_qosEosp == 1);
842 }
843 
844 bool
846 {
847  NS_ASSERT (IsQosData ());
848  return (m_amsduPresent == 1);
849 }
850 
851 uint8_t
853 {
854  NS_ASSERT (IsQosData ());
855  return m_qosTid;
856 }
857 
860 {
861  switch (m_qosAckPolicy)
862  {
863  case 0:
864  return NORMAL_ACK;
865  break;
866  case 1:
867  return NO_ACK;
868  break;
869  case 2:
870  return NO_EXPLICIT_ACK;
871  break;
872  case 3:
873  return BLOCK_ACK;
874  break;
875  }
876  // NOTREACHED
877  NS_ASSERT (false);
878  return (enum QosAckPolicy) -1;
879 }
880 
881 uint8_t
883 {
884  NS_ASSERT (IsQosData ());
885  return m_qosStuff;
886 }
887 
888 uint16_t
890 {
891  uint16_t val = 0;
892  val |= (m_ctrlType << 2) & (0x3 << 2);
893  val |= (m_ctrlSubtype << 4) & (0xf << 4);
894  val |= (m_ctrlToDs << 8) & (0x1 << 8);
895  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
896  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
897  val |= (m_ctrlRetry << 11) & (0x1 << 11);
898  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
899  val |= (m_ctrlWep << 14) & (0x1 << 14);
900  val |= (m_ctrlOrder << 15) & (0x1 << 15);
901  return val;
902 }
903 
904 uint16_t
906 {
907  uint16_t val = 0;
908  val |= m_qosTid;
909  val |= m_qosEosp << 4;
910  val |= m_qosAckPolicy << 5;
911  val |= m_amsduPresent << 7;
912  val |= m_qosStuff << 8;
913  return val;
914 }
915 
916 void
918 {
919  m_ctrlType = (ctrl >> 2) & 0x03;
920  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
921  m_ctrlToDs = (ctrl >> 8) & 0x01;
922  m_ctrlFromDs = (ctrl >> 9) & 0x01;
923  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
924  m_ctrlRetry = (ctrl >> 11) & 0x01;
925  m_ctrlMoreData = (ctrl >> 13) & 0x01;
926  m_ctrlWep = (ctrl >> 14) & 0x01;
927  m_ctrlOrder = (ctrl >> 15) & 0x01;
928 }
929 void
931 {
932  m_seqFrag = seq & 0x0f;
933  m_seqSeq = (seq >> 4) & 0x0fff;
934 }
935 void
937 {
938  m_qosTid = qos & 0x000f;
939  m_qosEosp = (qos >> 4) & 0x0001;
940  m_qosAckPolicy = (qos >> 5) & 0x0003;
941  m_amsduPresent = (qos >> 7) & 0x0001;
942  m_qosStuff = (qos >> 8) & 0x00ff;
943 }
944 
945 uint32_t
947 {
948  uint32_t size = 0;
949  switch (m_ctrlType)
950  {
951  case TYPE_MGT:
952  size = 2 + 2 + 6 + 6 + 6 + 2;
953  break;
954  case TYPE_CTL:
955  switch (m_ctrlSubtype)
956  {
957  case SUBTYPE_CTL_RTS:
958  size = 2 + 2 + 6 + 6;
959  break;
960  case SUBTYPE_CTL_CTS:
961  case SUBTYPE_CTL_ACK:
962  size = 2 + 2 + 6;
963  break;
964  case SUBTYPE_CTL_BACKREQ:
966  size = 2 + 2 + 6 + 6;
967  break;
969  size = 2 + 2 + 6 + 2 + 4;
970  break;
971  }
972  break;
973  case TYPE_DATA:
974  size = 2 + 2 + 6 + 6 + 6 + 2;
975  if (m_ctrlToDs && m_ctrlFromDs)
976  {
977  size += 6;
978  }
979  if (m_ctrlSubtype & 0x08)
980  {
981  size += 2;
982  }
983  break;
984  }
985  return size;
986 }
987 
988 const char *
990 {
991 #define FOO(x) \
992 case WIFI_MAC_ ## x: \
993  return # x; \
994  break;
995 
996  switch (GetType ())
997  {
998  FOO (CTL_RTS);
999  FOO (CTL_CTS);
1000  FOO (CTL_ACK);
1001  FOO (CTL_BACKREQ);
1002  FOO (CTL_BACKRESP);
1003 
1004  FOO (MGT_BEACON);
1005  FOO (MGT_ASSOCIATION_REQUEST);
1006  FOO (MGT_ASSOCIATION_RESPONSE);
1007  FOO (MGT_DISASSOCIATION);
1008  FOO (MGT_REASSOCIATION_REQUEST);
1009  FOO (MGT_REASSOCIATION_RESPONSE);
1010  FOO (MGT_PROBE_REQUEST);
1011  FOO (MGT_PROBE_RESPONSE);
1012  FOO (MGT_AUTHENTICATION);
1013  FOO (MGT_DEAUTHENTICATION);
1014  FOO (MGT_ACTION);
1015  FOO (MGT_ACTION_NO_ACK);
1016  FOO (MGT_MULTIHOP_ACTION);
1017 
1018  FOO (DATA);
1019  FOO (DATA_CFACK);
1020  FOO (DATA_CFPOLL);
1021  FOO (DATA_CFACK_CFPOLL);
1022  FOO (DATA_NULL);
1023  FOO (DATA_NULL_CFACK);
1024  FOO (DATA_NULL_CFPOLL);
1025  FOO (DATA_NULL_CFACK_CFPOLL);
1026  FOO (QOSDATA);
1027  FOO (QOSDATA_CFACK);
1028  FOO (QOSDATA_CFPOLL);
1029  FOO (QOSDATA_CFACK_CFPOLL);
1030  FOO (QOSDATA_NULL);
1031  FOO (QOSDATA_NULL_CFPOLL);
1032  FOO (QOSDATA_NULL_CFACK_CFPOLL);
1033  default:
1034  return "ERROR";
1035  }
1036 #undef FOO
1037  // needed to make gcc 4.0.1 ppc darwin happy.
1038  return "BIG_ERROR";
1039 }
1040 
1041 TypeId
1043 {
1044  static TypeId tid = TypeId ("ns3::WifiMacHeader")
1045  .SetParent<Header> ()
1046  .SetGroupName ("Wifi")
1047  .AddConstructor<WifiMacHeader> ()
1048  ;
1049  return tid;
1050 }
1051 
1052 TypeId
1054 {
1055  return GetTypeId ();
1056 }
1057 
1058 void
1059 WifiMacHeader::PrintFrameControl (std::ostream &os) const
1060 {
1061  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
1062  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
1063  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
1064  ;
1065 }
1066 
1067 void
1068 WifiMacHeader::Print (std::ostream &os) const
1069 {
1070  os << GetTypeString () << " ";
1071  switch (GetType ())
1072  {
1073  case WIFI_MAC_CTL_RTS:
1074  os << "Duration/ID=" << m_duration << "us"
1075  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1076  break;
1077  case WIFI_MAC_CTL_CTS:
1078  case WIFI_MAC_CTL_ACK:
1079  os << "Duration/ID=" << m_duration << "us"
1080  << ", RA=" << m_addr1;
1081  break;
1082  case WIFI_MAC_CTL_BACKREQ:
1083  break;
1084  case WIFI_MAC_CTL_BACKRESP:
1085  break;
1087  break;
1088 
1089  case WIFI_MAC_MGT_BEACON:
1099  PrintFrameControl (os);
1100  os << " Duration/ID=" << m_duration << "us"
1101  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1102  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1103  << ", SeqNumber=" << m_seqSeq;
1104  break;
1105  case WIFI_MAC_MGT_ACTION:
1107  PrintFrameControl (os);
1108  os << " Duration/ID=" << m_duration << "us"
1109  << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1110  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1111  break;
1113  os << " Duration/ID=" << m_duration << "us"
1114  << ", RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1115  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1116  break;
1117  case WIFI_MAC_DATA:
1118  PrintFrameControl (os);
1119  os << " Duration/ID=" << m_duration << "us";
1120  if (!m_ctrlToDs && !m_ctrlFromDs)
1121  {
1122  os << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1123  }
1124  else if (!m_ctrlToDs && m_ctrlFromDs)
1125  {
1126  os << ", DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1127  }
1128  else if (m_ctrlToDs && !m_ctrlFromDs)
1129  {
1130  os << ", DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1131  }
1132  else if (m_ctrlToDs && m_ctrlFromDs)
1133  {
1134  os << ", DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1135  }
1136  else
1137  {
1138  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1139  }
1140  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1141  << ", SeqNumber=" << m_seqSeq;
1142  break;
1143  case WIFI_MAC_DATA_CFACK:
1144  case WIFI_MAC_DATA_CFPOLL:
1146  case WIFI_MAC_DATA_NULL:
1150  case WIFI_MAC_QOSDATA:
1154  case WIFI_MAC_QOSDATA_NULL:
1157  break;
1158  }
1159 }
1160 
1161 uint32_t
1163 {
1164  return GetSize ();
1165 }
1166 
1167 void
1169 {
1172  WriteTo (i, m_addr1);
1173  switch (m_ctrlType)
1174  {
1175  case TYPE_MGT:
1176  WriteTo (i, m_addr2);
1177  WriteTo (i, m_addr3);
1179  break;
1180  case TYPE_CTL:
1181  switch (m_ctrlSubtype)
1182  {
1183  case SUBTYPE_CTL_RTS:
1184  WriteTo (i, m_addr2);
1185  break;
1186  case SUBTYPE_CTL_CTS:
1187  case SUBTYPE_CTL_ACK:
1188  break;
1189  case SUBTYPE_CTL_BACKREQ:
1190  case SUBTYPE_CTL_BACKRESP:
1191  WriteTo (i, m_addr2);
1192  break;
1193  default:
1194  //NOTREACHED
1195  NS_ASSERT (false);
1196  break;
1197  }
1198  break;
1199  case TYPE_DATA:
1200  {
1201  WriteTo (i, m_addr2);
1202  WriteTo (i, m_addr3);
1204  if (m_ctrlToDs && m_ctrlFromDs)
1205  {
1206  WriteTo (i, m_addr4);
1207  }
1208  if (m_ctrlSubtype & 0x08)
1209  {
1211  }
1212  } break;
1213  default:
1214  //NOTREACHED
1215  NS_ASSERT (false);
1216  break;
1217  }
1218 }
1219 
1220 uint32_t
1222 {
1223  Buffer::Iterator i = start;
1224  uint16_t frame_control = i.ReadLsbtohU16 ();
1225  SetFrameControl (frame_control);
1226  m_duration = i.ReadLsbtohU16 ();
1227  ReadFrom (i, m_addr1);
1228  switch (m_ctrlType)
1229  {
1230  case TYPE_MGT:
1231  ReadFrom (i, m_addr2);
1232  ReadFrom (i, m_addr3);
1234  break;
1235  case TYPE_CTL:
1236  switch (m_ctrlSubtype)
1237  {
1238  case SUBTYPE_CTL_RTS:
1239  ReadFrom (i, m_addr2);
1240  break;
1241  case SUBTYPE_CTL_CTS:
1242  case SUBTYPE_CTL_ACK:
1243  break;
1244  case SUBTYPE_CTL_BACKREQ:
1245  case SUBTYPE_CTL_BACKRESP:
1246  ReadFrom (i, m_addr2);
1247  break;
1248  }
1249  break;
1250  case TYPE_DATA:
1251  ReadFrom (i, m_addr2);
1252  ReadFrom (i, m_addr3);
1254  if (m_ctrlToDs && m_ctrlFromDs)
1255  {
1256  ReadFrom (i, m_addr4);
1257  }
1258  if (m_ctrlSubtype & 0x08)
1259  {
1261  }
1262  break;
1263  }
1264  return i.GetDistanceFrom (start);
1265 }
1266 
1267 } //namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
bool IsBeacon(void) const
Return true if the header is a Beacon header.
void SetAction()
Set Type/Subtype values for an action header.
void SetRetry(void)
Set the Retry bit in the Frame Control field.
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
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
uint16_t GetFragmentNumber(void) const
Return the fragment number of the header.
void SetQosAckPolicy(enum QosAckPolicy policy)
Set the QoS ACK policy in the QoS 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.
bool IsReassocResp(void) const
Return true if the header is a Reassociation Response header.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void SetProbeReq(void)
Set Type/Subtype values for a probe request header.
uint16_t GetRawDuration(void) const
Return the raw duration from the Duration/ID field.
void SetDuration(Time duration)
Set the Duration/ID field with the given duration (Time object).
bool IsAction() const
Return true if the header is an Action header.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1482
Mac48Address m_addr2
Mac48Address GetAddr3(void) const
Return the address in the Address 3 field.
void SetNoMoreFragments(void)
Un-set the More Fragment bit in the Frame Control Field.
Mac48Address GetAddr4(void) const
Return the address in the Address 4 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
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
enum WifiMacType GetType(void) const
Return the type (enum WifiMacType)
void SetId(uint16_t id)
Set the Duration/ID field with the given ID.
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
uint16_t GetQosControl(void) const
Return the raw QoS Control field.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
bool IsBlockAck(void) const
Return true if the header is a Block ACK header.
bool IsAssocResp(void) const
Return true if the header is an Association Response header.
void SetQosControl(uint16_t qos)
Set the QoS Control field with the given raw value.
uint16_t GetFrameControl(void) const
Return the raw Frame Control field.
bool IsCtl(void) const
Return true if the Type is Control.
void SetProbeResp(void)
Set Type/Subtype values for a probe response header.
void SetQosNoAck(void)
Set the QoS ACK policy in the QoS control field to no ACK.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
bool IsProbeResp(void) const
Return true if the header is a Probe Response header.
Mac48Address m_addr1
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
Mac48Address m_addr3
iterator in a Buffer instance
Definition: buffer.h:98
bool IsCfpoll(void) const
Return true if the Type/Subtype is one of the possible CF-Poll headers.
bool IsMoreFragments(void) const
Return if the More Fragment bit is set.
Time GetDuration(void) const
Return the duration from the Duration/ID field (Time object).
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
bool IsReassocReq(void) const
Return true if the header is a Reassociation Request header.
virtual uint32_t GetSerializedSize(void) const
uint8_t GetQosTxopLimit(void) const
Return the TXOP limit.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetBeacon(void)
Set Type/Subtype values for a beacon header.
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
void SetAddr4(Mac48Address address)
Fill the Address 4 field with the given address.
WifiMacType
Combination of valid MAC header type/subtype.
uint16_t GetSequenceControl(void) const
Return the raw Sequence Control field.
bool IsProbeReq(void) const
Return true if the header is a Probe Request header.
virtual void Print(std::ostream &os) const
void SetOrder(void)
Set order bit in the frame control field.
bool IsAuthentication(void) const
Return true if the header is an Authentication header.
bool IsQosBlockAck(void) const
Return if the QoS ACK policy is Block ACK.
Mac48Address m_addr4
bool IsMgt(void) const
Return true if the Type is Management.
void SetAssocReq(void)
Set Type/Subtype values for an association request header.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetSequenceControl(uint16_t seq)
Set the Sequence Control field with the given raw value.
void SetNoRetry(void)
Un-set the Retry bit in the Frame Control field.
bool IsToDs(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsDisassociation(void) const
Return true if the header is a Disassociation header.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
QosAckPolicy
ACK policy for QoS frames.
an EUI-48 address
Definition: mac48-address.h:43
void SetBlockAck(void)
Set Type/Subtype values for a Block Ack header.
void PrintFrameControl(std::ostream &os) const
Print the Frame Control field to the output stream.
const char * GetTypeString(void) const
Return a string corresponds to the header type.
#define FOO(x)
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:910
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
void SetAssocResp(void)
Set Type/Subtype values for an association response header.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
bool IsData(void) const
Return true if the Type is DATA.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
bool IsBlockAckReq(void) const
Return true if the header is a Block ACK Request header.
void SetQosNormalAck(void)
Set the QoS ACK policy in the QoS control field to normal ACK.
void SetTypeData(void)
Set Type/Subtype values for a data packet with no subtype equal to 0.
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
virtual void Serialize(Buffer::Iterator start) const
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
bool IsFromDs(void) const
void SetQosEosp()
Set the end of service period (EOSP) bit in the QoS control field.
bool IsQosEosp(void) const
Return if the end of service period (EOSP) is set.
virtual 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.
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1065
bool IsMultihopAction() const
Check if the header is a Multihop action header.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
void SetType(enum WifiMacType type)
Set Type/Subtype values with the correct values depending on the given type.
bool IsCts(void) const
Return true if the header is a CTS header.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
tuple address
Definition: first.py:37
void SetQosMeshControlPresent()
Set the Mesh Control Present flag for the QoS header.
void SetQosNoMeshControlPresent()
Clear the Mesh Control Present flag for the QoS header.
void SetMultihopAction()
Set Type/Subtype values for a multihop action header.
bool IsDeauthentication(void) const
Return true if the header is a Deauthentication header.
bool IsRts(void) const
Return true if the header is a RTS header.
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
bool IsAck(void) const
Return true if the header is an ACK header.
static TypeId GetTypeId(void)
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
void SetBlockAckReq(void)
Set Type/Subtype values for a Block Ack Request header.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
void SetQosAmsdu(void)
Set that A-MSDU is present.
enum QosAckPolicy GetQosAckPolicy(void) const
Return the QoS ACK Policy of a QoS header.
bool IsRetry(void) const
Return if the Retry bit is set.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
bool IsQosNoAck(void) const
Return if the QoS ACK policy is No ACK.
void SetQosBlockAck(void)
Set the QoS ACK policy in the QoS control field to block ACK.
bool IsQosAck(void) const
Return if the QoS ACK policy is Normal ACK.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.