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/address-utils.h"
24 #include "wifi-mac-header.h"
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (WifiMacHeader);
29 
31 enum
32 {
33  TYPE_MGT = 0,
34  TYPE_CTL = 1,
36 };
37 
39 enum
40 {
41  //Reserved: 0 - 6
48 };
49 
51  : m_ctrlMoreData (0),
52  m_ctrlWep (0),
53  m_ctrlOrder (1),
54  m_amsduPresent (0)
55 {
56 }
57 
59 {
60 }
61 
62 void
64 {
65  m_ctrlFromDs = 1;
66 }
67 
68 void
70 {
71  m_ctrlFromDs = 0;
72 }
73 
74 void
76 {
77  m_ctrlToDs = 1;
78 }
79 
80 void
82 {
83  m_ctrlToDs = 0;
84 }
85 
86 void
88 {
89  m_addr1 = address;
90 }
91 
92 void
94 {
95  m_addr2 = address;
96 }
97 
98 void
100 {
101  m_addr3 = address;
102 }
103 
104 void
106 {
107  m_addr4 = address;
108 }
109 
110 void
112 {
114  m_ctrlSubtype = 0;
115 }
116 
117 void
119 {
121  m_ctrlSubtype = 1;
122 }
123 
124 void
126 {
128  m_ctrlSubtype = 4;
129 }
130 
131 void
133 {
135  m_ctrlSubtype = 5;
136 }
137 
138 void
140 {
142  m_ctrlSubtype = 8;
143 }
144 
145 void
147 {
149  m_ctrlSubtype = 8;
150 }
151 
152 void
154 {
156  m_ctrlSubtype = 9;
157 }
158 
159 void
161 {
163  m_ctrlSubtype = 0;
164 }
165 
166 void
168 {
170  m_ctrlSubtype = 0x0D;
171 }
172 
173 void
175 {
177  m_ctrlSubtype = 0x0F;
178 }
179 
180 void
182 {
183  switch (type)
184  {
188  break;
192  break;
196  break;
197  case WIFI_MAC_CTL_RTS:
200  break;
201  case WIFI_MAC_CTL_CTS:
204  break;
205  case WIFI_MAC_CTL_ACK:
208  break;
211  m_ctrlSubtype = 0;
212  break;
215  m_ctrlSubtype = 1;
216  break;
219  m_ctrlSubtype = 2;
220  break;
223  m_ctrlSubtype = 3;
224  break;
227  m_ctrlSubtype = 4;
228  break;
231  m_ctrlSubtype = 5;
232  break;
233  case WIFI_MAC_MGT_BEACON:
235  m_ctrlSubtype = 8;
236  break;
239  m_ctrlSubtype = 10;
240  break;
243  m_ctrlSubtype = 11;
244  break;
247  m_ctrlSubtype = 12;
248  break;
249  case WIFI_MAC_MGT_ACTION:
251  m_ctrlSubtype = 13;
252  break;
255  m_ctrlSubtype = 14;
256  break;
259  m_ctrlSubtype = 15;
260  break;
261  case WIFI_MAC_DATA:
263  m_ctrlSubtype = 0;
264  break;
265  case WIFI_MAC_DATA_CFACK:
267  m_ctrlSubtype = 1;
268  break;
271  m_ctrlSubtype = 2;
272  break;
275  m_ctrlSubtype = 3;
276  break;
277  case WIFI_MAC_DATA_NULL:
279  m_ctrlSubtype = 4;
280  break;
283  m_ctrlSubtype = 5;
284  break;
287  m_ctrlSubtype = 6;
288  break;
291  m_ctrlSubtype = 7;
292  break;
293  case WIFI_MAC_QOSDATA:
295  m_ctrlSubtype = 8;
296  break;
299  m_ctrlSubtype = 9;
300  break;
303  m_ctrlSubtype = 10;
304  break;
307  m_ctrlSubtype = 11;
308  break;
311  m_ctrlSubtype = 12;
312  break;
315  m_ctrlSubtype = 14;
316  break;
319  m_ctrlSubtype = 15;
320  break;
321  }
322  m_ctrlToDs = 0;
323  m_ctrlFromDs = 0;
324 }
325 
326 void
327 WifiMacHeader::SetRawDuration (uint16_t duration)
328 {
329  m_duration = duration;
330 }
331 
332 void
334 {
335  int64_t duration_us = ceil ((double)duration.GetNanoSeconds () / 1000);
336  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
337  m_duration = static_cast<uint16_t> (duration_us);
338 }
339 
340 void WifiMacHeader::SetId (uint16_t id)
341 {
342  m_duration = id;
343 }
344 
346 {
347  m_seqSeq = seq;
348 }
349 
351 {
352  m_seqFrag = frag;
353 }
354 
356 {
357  m_ctrlMoreFrag = 0;
358 }
359 
361 {
362  m_ctrlMoreFrag = 1;
363 }
364 
366 {
367  m_ctrlOrder = 1;
368 }
369 
371 {
372  m_ctrlOrder = 0;
373 }
374 
376 {
377  m_ctrlRetry = 1;
378 }
379 
381 {
382  m_ctrlRetry = 0;
383 }
384 
385 void WifiMacHeader::SetQosTid (uint8_t tid)
386 {
387  m_qosTid = tid;
388 }
389 
391 {
392  m_qosEosp = 1;
393 }
394 
396 {
397  m_qosEosp = 0;
398 }
399 
401 {
402  switch (policy)
403  {
404  case NORMAL_ACK:
405  m_qosAckPolicy = 0;
406  break;
407  case NO_ACK:
408  m_qosAckPolicy = 1;
409  break;
410  case NO_EXPLICIT_ACK:
411  m_qosAckPolicy = 2;
412  break;
413  case BLOCK_ACK:
414  m_qosAckPolicy = 3;
415  break;
416  }
417 }
418 
419 void
421 {
422  m_qosAckPolicy = 0;
423 }
424 
425 void
427 {
428  m_qosAckPolicy = 3;
429 }
430 
431 void
433 {
434  m_qosAckPolicy = 1;
435 }
436 
438 {
439  m_amsduPresent = 1;
440 }
441 
443 {
444  m_amsduPresent = 0;
445 }
446 
448 {
449  m_qosStuff = txop;
450 }
451 
453 {
454  //Mark bit 0 of this variable instead of bit 8, since m_qosStuff is
455  //shifted by one byte when serialized
456  m_qosStuff = m_qosStuff | 0x01; //bit 8 of QoS Control Field
457 }
458 
460 {
461  //Clear bit 0 of this variable instead of bit 8, since m_qosStuff is
462  //shifted by one byte when serialized
463  m_qosStuff = m_qosStuff & 0xfe; //bit 8 of QoS Control Field
464 }
465 
466 
469 {
470  return m_addr1;
471 }
472 
475 {
476  return m_addr2;
477 }
478 
481 {
482  return m_addr3;
483 }
484 
487 {
488  return m_addr4;
489 }
490 
493 {
494  switch (m_ctrlType)
495  {
496  case TYPE_MGT:
497  switch (m_ctrlSubtype)
498  {
499  case 0:
501  case 1:
503  case 2:
505  case 3:
507  case 4:
509  case 5:
511  case 8:
512  return WIFI_MAC_MGT_BEACON;
513  case 10:
515  case 11:
517  case 12:
519  case 13:
520  return WIFI_MAC_MGT_ACTION;
521  case 14:
523  case 15:
525  }
526  break;
527  case TYPE_CTL:
528  switch (m_ctrlSubtype)
529  {
530  case SUBTYPE_CTL_BACKREQ:
531  return WIFI_MAC_CTL_BACKREQ;
533  return WIFI_MAC_CTL_BACKRESP;
534  case SUBTYPE_CTL_RTS:
535  return WIFI_MAC_CTL_RTS;
536  case SUBTYPE_CTL_CTS:
537  return WIFI_MAC_CTL_CTS;
538  case SUBTYPE_CTL_ACK:
539  return WIFI_MAC_CTL_ACK;
540  }
541  break;
542  case TYPE_DATA:
543  switch (m_ctrlSubtype)
544  {
545  case 0:
546  return WIFI_MAC_DATA;
547  case 1:
548  return WIFI_MAC_DATA_CFACK;
549  case 2:
550  return WIFI_MAC_DATA_CFPOLL;
551  case 3:
553  case 4:
554  return WIFI_MAC_DATA_NULL;
555  case 5:
557  case 6:
559  case 7:
561  case 8:
562  return WIFI_MAC_QOSDATA;
563  case 9:
564  return WIFI_MAC_QOSDATA_CFACK;
565  case 10:
567  case 11:
569  case 12:
570  return WIFI_MAC_QOSDATA_NULL;
571  case 14:
573  case 15:
575  }
576  break;
577  }
578  // NOTREACHED
579  NS_ASSERT (false);
580  return (WifiMacType) - 1;
581 }
582 
583 bool
585 {
586  return m_ctrlFromDs == 1;
587 }
588 
589 bool
591 {
592  return m_ctrlToDs == 1;
593 }
594 
595 bool
597 {
598  return (m_ctrlType == TYPE_DATA);
599 
600 }
601 
602 bool
604 {
605  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
606 }
607 
608 bool
610 {
611  return (m_ctrlType == TYPE_CTL);
612 }
613 
614 bool
616 {
617  return (m_ctrlType == TYPE_MGT);
618 }
619 
620 bool
622 {
623  switch (GetType ())
624  {
633  return true;
634  default:
635  return false;
636  }
637 }
638 
639 bool
641 {
642  return (GetType () == WIFI_MAC_CTL_RTS);
643 }
644 
645 bool
647 {
648  return (GetType () == WIFI_MAC_CTL_CTS);
649 }
650 
651 bool
653 {
654  return (GetType () == WIFI_MAC_CTL_ACK);
655 }
656 
657 bool
659 {
661 }
662 
663 bool
665 {
667 }
668 
669 bool
671 {
673 }
674 
675 bool
677 {
679 }
680 
681 bool
683 {
684  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
685 }
686 
687 bool
689 {
690  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
691 }
692 
693 bool
695 {
696  return (GetType () == WIFI_MAC_MGT_BEACON);
697 }
698 
699 bool
701 {
702  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
703 }
704 
705 bool
707 {
708  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
709 }
710 
711 bool
713 {
714  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
715 }
716 
717 bool
719 {
720  return (GetType () == WIFI_MAC_MGT_ACTION);
721 }
722 
723 bool
725 {
726  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
727 }
728 
729 bool
731 {
732  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
733 }
734 
735 bool
737 {
738  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
739 }
740 
741 uint16_t
743 {
744  return m_duration;
745 }
746 
747 Time
749 {
750  return MicroSeconds (m_duration);
751 }
752 
753 uint16_t
755 {
756  return (m_seqSeq << 4) | m_seqFrag;
757 }
758 
759 uint16_t
761 {
762  return m_seqSeq;
763 }
764 
765 uint16_t
767 {
768  return m_seqFrag;
769 }
770 
771 bool
773 {
774  return (m_ctrlRetry == 1);
775 }
776 
777 bool
779 {
780  return (m_ctrlMoreFrag == 1);
781 }
782 
783 bool
785 {
786  NS_ASSERT (IsQosData ());
787  return (m_qosAckPolicy == 3);
788 }
789 
790 bool
792 {
793  NS_ASSERT (IsQosData ());
794  return (m_qosAckPolicy == 1);
795 }
796 
797 bool
799 {
800  NS_ASSERT (IsQosData ());
801  return (m_qosAckPolicy == 0);
802 }
803 
804 bool
806 {
807  NS_ASSERT (IsQosData ());
808  return (m_qosEosp == 1);
809 }
810 
811 bool
813 {
814  NS_ASSERT (IsQosData ());
815  return (m_amsduPresent == 1);
816 }
817 
818 uint8_t
820 {
821  NS_ASSERT (IsQosData ());
822  return m_qosTid;
823 }
824 
827 {
828  switch (m_qosAckPolicy)
829  {
830  case 0:
831  return NORMAL_ACK;
832  case 1:
833  return NO_ACK;
834  case 2:
835  return NO_EXPLICIT_ACK;
836  case 3:
837  return BLOCK_ACK;
838  }
839  // NOTREACHED
840  NS_ASSERT (false);
841  return (QosAckPolicy) - 1;
842 }
843 
844 uint8_t
846 {
847  NS_ASSERT (IsQosData ());
848  return m_qosStuff;
849 }
850 
851 uint16_t
853 {
854  uint16_t val = 0;
855  val |= (m_ctrlType << 2) & (0x3 << 2);
856  val |= (m_ctrlSubtype << 4) & (0xf << 4);
857  val |= (m_ctrlToDs << 8) & (0x1 << 8);
858  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
859  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
860  val |= (m_ctrlRetry << 11) & (0x1 << 11);
861  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
862  val |= (m_ctrlWep << 14) & (0x1 << 14);
863  val |= (m_ctrlOrder << 15) & (0x1 << 15);
864  return val;
865 }
866 
867 uint16_t
869 {
870  uint16_t val = 0;
871  val |= m_qosTid;
872  val |= m_qosEosp << 4;
873  val |= m_qosAckPolicy << 5;
874  val |= m_amsduPresent << 7;
875  val |= m_qosStuff << 8;
876  return val;
877 }
878 
879 void
881 {
882  m_ctrlType = (ctrl >> 2) & 0x03;
883  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
884  m_ctrlToDs = (ctrl >> 8) & 0x01;
885  m_ctrlFromDs = (ctrl >> 9) & 0x01;
886  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
887  m_ctrlRetry = (ctrl >> 11) & 0x01;
888  m_ctrlMoreData = (ctrl >> 13) & 0x01;
889  m_ctrlWep = (ctrl >> 14) & 0x01;
890  m_ctrlOrder = (ctrl >> 15) & 0x01;
891 }
892 void
894 {
895  m_seqFrag = seq & 0x0f;
896  m_seqSeq = (seq >> 4) & 0x0fff;
897 }
898 void
900 {
901  m_qosTid = qos & 0x000f;
902  m_qosEosp = (qos >> 4) & 0x0001;
903  m_qosAckPolicy = (qos >> 5) & 0x0003;
904  m_amsduPresent = (qos >> 7) & 0x0001;
905  m_qosStuff = (qos >> 8) & 0x00ff;
906 }
907 
908 uint32_t
910 {
911  uint32_t size = 0;
912  switch (m_ctrlType)
913  {
914  case TYPE_MGT:
915  size = 2 + 2 + 6 + 6 + 6 + 2;
916  break;
917  case TYPE_CTL:
918  switch (m_ctrlSubtype)
919  {
920  case SUBTYPE_CTL_RTS:
921  size = 2 + 2 + 6 + 6;
922  break;
923  case SUBTYPE_CTL_CTS:
924  case SUBTYPE_CTL_ACK:
925  size = 2 + 2 + 6;
926  break;
927  case SUBTYPE_CTL_BACKREQ:
929  size = 2 + 2 + 6 + 6;
930  break;
932  size = 2 + 2 + 6 + 2 + 4;
933  break;
934  }
935  break;
936  case TYPE_DATA:
937  size = 2 + 2 + 6 + 6 + 6 + 2;
938  if (m_ctrlToDs && m_ctrlFromDs)
939  {
940  size += 6;
941  }
942  if (m_ctrlSubtype & 0x08)
943  {
944  size += 2;
945  }
946  break;
947  }
948  return size;
949 }
950 
951 const char *
953 {
954 #define FOO(x) \
955 case WIFI_MAC_ ## x: \
956  return # x; \
957  break;
958 
959  switch (GetType ())
960  {
961  FOO (CTL_RTS);
962  FOO (CTL_CTS);
963  FOO (CTL_ACK);
964  FOO (CTL_BACKREQ);
965  FOO (CTL_BACKRESP);
966 
967  FOO (MGT_BEACON);
968  FOO (MGT_ASSOCIATION_REQUEST);
969  FOO (MGT_ASSOCIATION_RESPONSE);
970  FOO (MGT_DISASSOCIATION);
971  FOO (MGT_REASSOCIATION_REQUEST);
972  FOO (MGT_REASSOCIATION_RESPONSE);
973  FOO (MGT_PROBE_REQUEST);
974  FOO (MGT_PROBE_RESPONSE);
975  FOO (MGT_AUTHENTICATION);
976  FOO (MGT_DEAUTHENTICATION);
977  FOO (MGT_ACTION);
978  FOO (MGT_ACTION_NO_ACK);
979  FOO (MGT_MULTIHOP_ACTION);
980 
981  FOO (DATA);
982  FOO (DATA_CFACK);
983  FOO (DATA_CFPOLL);
984  FOO (DATA_CFACK_CFPOLL);
985  FOO (DATA_NULL);
986  FOO (DATA_NULL_CFACK);
987  FOO (DATA_NULL_CFPOLL);
988  FOO (DATA_NULL_CFACK_CFPOLL);
989  FOO (QOSDATA);
990  FOO (QOSDATA_CFACK);
991  FOO (QOSDATA_CFPOLL);
992  FOO (QOSDATA_CFACK_CFPOLL);
993  FOO (QOSDATA_NULL);
994  FOO (QOSDATA_NULL_CFPOLL);
995  FOO (QOSDATA_NULL_CFACK_CFPOLL);
996  default:
997  return "ERROR";
998  }
999 #undef FOO
1000  // needed to make gcc 4.0.1 ppc darwin happy.
1001  return "BIG_ERROR";
1002 }
1003 
1004 TypeId
1006 {
1007  static TypeId tid = TypeId ("ns3::WifiMacHeader")
1008  .SetParent<Header> ()
1009  .SetGroupName ("Wifi")
1010  .AddConstructor<WifiMacHeader> ()
1011  ;
1012  return tid;
1013 }
1014 
1015 TypeId
1017 {
1018  return GetTypeId ();
1019 }
1020 
1021 void
1022 WifiMacHeader::PrintFrameControl (std::ostream &os) const
1023 {
1024  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
1025  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
1026  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
1027  ;
1028 }
1029 
1030 void
1031 WifiMacHeader::Print (std::ostream &os) const
1032 {
1033  os << GetTypeString () << " ";
1034  switch (GetType ())
1035  {
1036  case WIFI_MAC_CTL_RTS:
1037  os << "Duration/ID=" << m_duration << "us"
1038  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1039  break;
1040  case WIFI_MAC_CTL_CTS:
1041  case WIFI_MAC_CTL_ACK:
1042  os << "Duration/ID=" << m_duration << "us"
1043  << ", RA=" << m_addr1;
1044  break;
1045  case WIFI_MAC_CTL_BACKREQ:
1046  break;
1047  case WIFI_MAC_CTL_BACKRESP:
1048  break;
1050  break;
1051  case WIFI_MAC_MGT_BEACON:
1061  PrintFrameControl (os);
1062  os << " Duration/ID=" << m_duration << "us"
1063  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1064  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1065  << ", SeqNumber=" << m_seqSeq;
1066  break;
1067  case WIFI_MAC_MGT_ACTION:
1069  PrintFrameControl (os);
1070  os << " Duration/ID=" << m_duration << "us"
1071  << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1072  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1073  break;
1075  os << " Duration/ID=" << m_duration << "us"
1076  << ", RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1077  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1078  break;
1079  case WIFI_MAC_DATA:
1080  PrintFrameControl (os);
1081  os << " Duration/ID=" << m_duration << "us";
1082  if (!m_ctrlToDs && !m_ctrlFromDs)
1083  {
1084  os << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1085  }
1086  else if (!m_ctrlToDs && m_ctrlFromDs)
1087  {
1088  os << ", DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1089  }
1090  else if (m_ctrlToDs && !m_ctrlFromDs)
1091  {
1092  os << ", DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1093  }
1094  else if (m_ctrlToDs && m_ctrlFromDs)
1095  {
1096  os << ", DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1097  }
1098  else
1099  {
1100  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1101  }
1102  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1103  << ", SeqNumber=" << m_seqSeq;
1104  break;
1105  case WIFI_MAC_DATA_CFACK:
1106  case WIFI_MAC_DATA_CFPOLL:
1108  case WIFI_MAC_DATA_NULL:
1112  case WIFI_MAC_QOSDATA:
1116  case WIFI_MAC_QOSDATA_NULL:
1119  break;
1120  }
1121 }
1122 
1123 uint32_t
1125 {
1126  return GetSize ();
1127 }
1128 
1129 void
1131 {
1134  WriteTo (i, m_addr1);
1135  switch (m_ctrlType)
1136  {
1137  case TYPE_MGT:
1138  WriteTo (i, m_addr2);
1139  WriteTo (i, m_addr3);
1141  break;
1142  case TYPE_CTL:
1143  switch (m_ctrlSubtype)
1144  {
1145  case SUBTYPE_CTL_RTS:
1146  WriteTo (i, m_addr2);
1147  break;
1148  case SUBTYPE_CTL_CTS:
1149  case SUBTYPE_CTL_ACK:
1150  break;
1151  case SUBTYPE_CTL_BACKREQ:
1152  case SUBTYPE_CTL_BACKRESP:
1153  WriteTo (i, m_addr2);
1154  break;
1155  default:
1156  //NOTREACHED
1157  NS_ASSERT (false);
1158  break;
1159  }
1160  break;
1161  case TYPE_DATA:
1162  {
1163  WriteTo (i, m_addr2);
1164  WriteTo (i, m_addr3);
1166  if (m_ctrlToDs && m_ctrlFromDs)
1167  {
1168  WriteTo (i, m_addr4);
1169  }
1170  if (m_ctrlSubtype & 0x08)
1171  {
1173  }
1174  } break;
1175  default:
1176  //NOTREACHED
1177  NS_ASSERT (false);
1178  break;
1179  }
1180 }
1181 
1182 uint32_t
1184 {
1185  Buffer::Iterator i = start;
1186  uint16_t frame_control = i.ReadLsbtohU16 ();
1187  SetFrameControl (frame_control);
1188  m_duration = i.ReadLsbtohU16 ();
1189  ReadFrom (i, m_addr1);
1190  switch (m_ctrlType)
1191  {
1192  case TYPE_MGT:
1193  ReadFrom (i, m_addr2);
1194  ReadFrom (i, m_addr3);
1196  break;
1197  case TYPE_CTL:
1198  switch (m_ctrlSubtype)
1199  {
1200  case SUBTYPE_CTL_RTS:
1201  ReadFrom (i, m_addr2);
1202  break;
1203  case SUBTYPE_CTL_CTS:
1204  case SUBTYPE_CTL_ACK:
1205  break;
1206  case SUBTYPE_CTL_BACKREQ:
1207  case SUBTYPE_CTL_BACKRESP:
1208  ReadFrom (i, m_addr2);
1209  break;
1210  }
1211  break;
1212  case TYPE_DATA:
1213  ReadFrom (i, m_addr2);
1214  ReadFrom (i, m_addr3);
1216  if (m_ctrlToDs && m_ctrlFromDs)
1217  {
1218  ReadFrom (i, m_addr4);
1219  }
1220  if (m_ctrlSubtype & 0x08)
1221  {
1223  }
1224  break;
1225  }
1226  return i.GetDistanceFrom (start);
1227 }
1228 
1229 } //namespace ns3
uint8_t m_ctrlMoreData
control more data
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 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.
void SetType(WifiMacType type)
Set Type/Subtype values with the correct values depending on the given type.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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).
uint8_t m_ctrlType
control type
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:1790
Mac48Address m_addr2
address 2
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.
uint8_t m_qosAckPolicy
QOS ack policy.
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.
uint8_t m_qosEosp
QOS EOSP.
QosAckPolicy GetQosAckPolicy(void) const
Return the QoS ACK Policy of a QoS header.
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:162
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.
uint8_t m_seqFrag
sequence fragment
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
address 1
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:786
Mac48Address m_addr3
address 3
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.
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.
uint8_t m_ctrlToDs
control to DS
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.
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.
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 IsMgt(void) const
Return true if the Type is Management.
void SetAssocReq(void)
Set Type/Subtype values for an association request header.
uint8_t m_ctrlOrder
control order
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
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.
uint16_t m_seqSeq
sequence sequence
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:913
uint16_t m_duration
duration
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.
uint8_t m_ctrlRetry
control retry
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
uint16_t m_qosStuff
QOS stuff.
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.
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
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.
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.
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:1068
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:1009
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
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 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)
Get the type ID.
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:914
void SetQosAmsdu(void)
Set that A-MSDU is present.
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.
uint8_t m_ctrlWep
control WEP
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.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.