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 
23 #include "ns3/assert.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 
31 enum
32 {
33  TYPE_MGT = 0,
34  TYPE_CTL = 1,
36 };
37 
38 enum
39 {
40  //Reserved: 0 - 6
47 };
48 
50  : m_ctrlMoreData (0),
51  m_ctrlWep (0),
52  m_ctrlOrder (1),
53  m_amsduPresent (0)
54 {
55 }
56 
58 {
59 }
60 
61 void
63 {
64  m_ctrlFromDs = 1;
65 }
66 
67 void
69 {
70  m_ctrlFromDs = 0;
71 }
72 
73 void
75 {
76  m_ctrlToDs = 1;
77 }
78 
79 void
81 {
82  m_ctrlToDs = 0;
83 }
84 
85 void
87 {
88  m_addr1 = address;
89 }
90 
91 void
93 {
94  m_addr2 = address;
95 }
96 
97 void
99 {
100  m_addr3 = address;
101 }
102 
103 void
105 {
106  m_addr4 = address;
107 }
108 
109 void
111 {
113  m_ctrlSubtype = 0;
114 }
115 
116 void
118 {
120  m_ctrlSubtype = 1;
121 }
122 
123 void
125 {
127  m_ctrlSubtype = 4;
128 }
129 
130 void
132 {
134  m_ctrlSubtype = 5;
135 }
136 
137 void
139 {
141  m_ctrlSubtype = 8;
142 }
143 
144 void
146 {
148  m_ctrlSubtype = 8;
149 }
150 
151 void
153 {
155  m_ctrlSubtype = 9;
156 }
157 
158 void
160 {
162  m_ctrlSubtype = 0;
163 }
164 
165 void
167 {
169  m_ctrlSubtype = 0x0D;
170 }
171 
172 void
174 {
176  m_ctrlSubtype = 0x0F;
177 }
178 
179 void
181 {
182  switch (type)
183  {
187  break;
191  break;
195  break;
196  case WIFI_MAC_CTL_RTS:
199  break;
200  case WIFI_MAC_CTL_CTS:
203  break;
204  case WIFI_MAC_CTL_ACK:
207  break;
210  m_ctrlSubtype = 0;
211  break;
214  m_ctrlSubtype = 1;
215  break;
218  m_ctrlSubtype = 2;
219  break;
222  m_ctrlSubtype = 3;
223  break;
226  m_ctrlSubtype = 4;
227  break;
230  m_ctrlSubtype = 5;
231  break;
232  case WIFI_MAC_MGT_BEACON:
234  m_ctrlSubtype = 8;
235  break;
238  m_ctrlSubtype = 10;
239  break;
242  m_ctrlSubtype = 11;
243  break;
246  m_ctrlSubtype = 12;
247  break;
248  case WIFI_MAC_MGT_ACTION:
250  m_ctrlSubtype = 13;
251  break;
254  m_ctrlSubtype = 14;
255  break;
258  m_ctrlSubtype = 15;
259  break;
260  case WIFI_MAC_DATA:
262  m_ctrlSubtype = 0;
263  break;
264  case WIFI_MAC_DATA_CFACK:
266  m_ctrlSubtype = 1;
267  break;
270  m_ctrlSubtype = 2;
271  break;
274  m_ctrlSubtype = 3;
275  break;
276  case WIFI_MAC_DATA_NULL:
278  m_ctrlSubtype = 4;
279  break;
282  m_ctrlSubtype = 5;
283  break;
286  m_ctrlSubtype = 6;
287  break;
290  m_ctrlSubtype = 7;
291  break;
292  case WIFI_MAC_QOSDATA:
294  m_ctrlSubtype = 8;
295  break;
298  m_ctrlSubtype = 9;
299  break;
302  m_ctrlSubtype = 10;
303  break;
306  m_ctrlSubtype = 11;
307  break;
310  m_ctrlSubtype = 12;
311  break;
314  m_ctrlSubtype = 14;
315  break;
318  m_ctrlSubtype = 15;
319  break;
320  }
321  m_ctrlToDs = 0;
322  m_ctrlFromDs = 0;
323 }
324 
325 void
326 WifiMacHeader::SetRawDuration (uint16_t duration)
327 {
328  m_duration = duration;
329 }
330 
331 void
333 {
334  int64_t duration_us = ceil ((double)duration.GetNanoSeconds () / 1000);
335  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
336  m_duration = static_cast<uint16_t> (duration_us);
337 }
338 
339 void WifiMacHeader::SetId (uint16_t id)
340 {
341  m_duration = id;
342 }
343 
345 {
346  m_seqSeq = seq;
347 }
348 
350 {
351  m_seqFrag = frag;
352 }
353 
355 {
356  m_ctrlMoreFrag = 0;
357 }
358 
360 {
361  m_ctrlMoreFrag = 1;
362 }
363 
365 {
366  m_ctrlOrder = 1;
367 }
368 
370 {
371  m_ctrlOrder = 0;
372 }
373 
375 {
376  m_ctrlRetry = 1;
377 }
378 
380 {
381  m_ctrlRetry = 0;
382 }
383 
384 void WifiMacHeader::SetQosTid (uint8_t tid)
385 {
386  m_qosTid = tid;
387 }
388 
390 {
391  m_qosEosp = 1;
392 }
393 
395 {
396  m_qosEosp = 0;
397 }
398 
400 {
401  switch (policy)
402  {
403  case NORMAL_ACK:
404  m_qosAckPolicy = 0;
405  break;
406  case NO_ACK:
407  m_qosAckPolicy = 1;
408  break;
409  case NO_EXPLICIT_ACK:
410  m_qosAckPolicy = 2;
411  break;
412  case BLOCK_ACK:
413  m_qosAckPolicy = 3;
414  break;
415  }
416 }
417 
418 void
420 {
421  m_qosAckPolicy = 0;
422 }
423 
424 void
426 {
427  m_qosAckPolicy = 3;
428 }
429 
430 void
432 {
433  m_qosAckPolicy = 1;
434 }
435 
437 {
438  m_amsduPresent = 1;
439 }
440 
442 {
443  m_amsduPresent = 0;
444 }
445 
447 {
448  m_qosStuff = txop;
449 }
450 
452 {
453  //Mark bit 0 of this variable instead of bit 8, since m_qosStuff is
454  //shifted by one byte when serialized
455  m_qosStuff = m_qosStuff | 0x01; //bit 8 of QoS Control Field
456 }
457 
459 {
460  //Clear bit 0 of this variable instead of bit 8, since m_qosStuff is
461  //shifted by one byte when serialized
462  m_qosStuff = m_qosStuff & 0xfe; //bit 8 of QoS Control Field
463 }
464 
465 
468 {
469  return m_addr1;
470 }
471 
474 {
475  return m_addr2;
476 }
477 
480 {
481  return m_addr3;
482 }
483 
486 {
487  return m_addr4;
488 }
489 
490 enum WifiMacType
492 {
493  switch (m_ctrlType)
494  {
495  case TYPE_MGT:
496  switch (m_ctrlSubtype)
497  {
498  case 0:
500  break;
501  case 1:
503  break;
504  case 2:
506  break;
507  case 3:
509  break;
510  case 4:
512  break;
513  case 5:
515  break;
516  case 8:
517  return WIFI_MAC_MGT_BEACON;
518  break;
519  case 10:
521  break;
522  case 11:
524  break;
525  case 12:
527  break;
528  case 13:
529  return WIFI_MAC_MGT_ACTION;
530  break;
531  case 14:
533  break;
534  case 15:
536  break;
537  }
538  break;
539  case TYPE_CTL:
540  switch (m_ctrlSubtype)
541  {
542  case SUBTYPE_CTL_BACKREQ:
543  return WIFI_MAC_CTL_BACKREQ;
544  break;
546  return WIFI_MAC_CTL_BACKRESP;
547  break;
548  case SUBTYPE_CTL_RTS:
549  return WIFI_MAC_CTL_RTS;
550  break;
551  case SUBTYPE_CTL_CTS:
552  return WIFI_MAC_CTL_CTS;
553  break;
554  case SUBTYPE_CTL_ACK:
555  return WIFI_MAC_CTL_ACK;
556  break;
557  }
558  break;
559  case TYPE_DATA:
560  switch (m_ctrlSubtype)
561  {
562  case 0:
563  return WIFI_MAC_DATA;
564  break;
565  case 1:
566  return WIFI_MAC_DATA_CFACK;
567  break;
568  case 2:
569  return WIFI_MAC_DATA_CFPOLL;
570  break;
571  case 3:
573  break;
574  case 4:
575  return WIFI_MAC_DATA_NULL;
576  break;
577  case 5:
579  break;
580  case 6:
582  break;
583  case 7:
585  break;
586  case 8:
587  return WIFI_MAC_QOSDATA;
588  break;
589  case 9:
590  return WIFI_MAC_QOSDATA_CFACK;
591  break;
592  case 10:
594  break;
595  case 11:
597  break;
598  case 12:
599  return WIFI_MAC_QOSDATA_NULL;
600  break;
601  case 14:
603  break;
604  case 15:
606  break;
607  }
608  break;
609  }
610  // NOTREACHED
611  NS_ASSERT (false);
612  return (enum WifiMacType) -1;
613 }
614 
615 bool
617 {
618  return m_ctrlFromDs == 1;
619 }
620 
621 bool
623 {
624  return m_ctrlToDs == 1;
625 }
626 
627 bool
629 {
630  return (m_ctrlType == TYPE_DATA);
631 
632 }
633 
634 bool
636 {
637  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
638 }
639 
640 bool
642 {
643  return (m_ctrlType == TYPE_CTL);
644 }
645 
646 bool
648 {
649  return (m_ctrlType == TYPE_MGT);
650 }
651 
652 bool
654 {
655  switch (GetType ())
656  {
665  return true;
666  break;
667  default:
668  return false;
669  break;
670  }
671 }
672 
673 bool
675 {
676  return (GetType () == WIFI_MAC_CTL_RTS);
677 }
678 
679 bool
681 {
682  return (GetType () == WIFI_MAC_CTL_CTS);
683 }
684 
685 bool
687 {
688  return (GetType () == WIFI_MAC_CTL_ACK);
689 }
690 
691 bool
693 {
695 }
696 
697 bool
699 {
701 }
702 
703 bool
705 {
707 }
708 
709 bool
711 {
713 }
714 
715 bool
717 {
718  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
719 }
720 
721 bool
723 {
724  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
725 }
726 
727 bool
729 {
730  return (GetType () == WIFI_MAC_MGT_BEACON);
731 }
732 
733 bool
735 {
736  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
737 }
738 
739 bool
741 {
742  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
743 }
744 
745 bool
747 {
748  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
749 }
750 
751 bool
753 {
754  return (GetType () == WIFI_MAC_MGT_ACTION);
755 }
756 
757 bool
759 {
760  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
761 }
762 
763 bool
765 {
766  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
767 }
768 
769 bool
771 {
772  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
773 }
774 
775 uint16_t
777 {
778  return m_duration;
779 }
780 
781 Time
783 {
784  return MicroSeconds (m_duration);
785 }
786 
787 uint16_t
789 {
790  return (m_seqSeq << 4) | m_seqFrag;
791 }
792 
793 uint16_t
795 {
796  return m_seqSeq;
797 }
798 
799 uint16_t
801 {
802  return m_seqFrag;
803 }
804 
805 bool
807 {
808  return (m_ctrlRetry == 1);
809 }
810 
811 bool
813 {
814  return (m_ctrlMoreFrag == 1);
815 }
816 
817 bool
819 {
820  NS_ASSERT (IsQosData ());
821  return (m_qosAckPolicy == 3);
822 }
823 
824 bool
826 {
827  NS_ASSERT (IsQosData ());
828  return (m_qosAckPolicy == 1);
829 }
830 
831 bool
833 {
834  NS_ASSERT (IsQosData ());
835  return (m_qosAckPolicy == 0);
836 }
837 
838 bool
840 {
841  NS_ASSERT (IsQosData ());
842  return (m_qosEosp == 1);
843 }
844 
845 bool
847 {
848  NS_ASSERT (IsQosData ());
849  return (m_amsduPresent == 1);
850 }
851 
852 uint8_t
854 {
855  NS_ASSERT (IsQosData ());
856  return m_qosTid;
857 }
858 
861 {
862  switch (m_qosAckPolicy)
863  {
864  case 0:
865  return NORMAL_ACK;
866  break;
867  case 1:
868  return NO_ACK;
869  break;
870  case 2:
871  return NO_EXPLICIT_ACK;
872  break;
873  case 3:
874  return BLOCK_ACK;
875  break;
876  }
877  // NOTREACHED
878  NS_ASSERT (false);
879  return (enum QosAckPolicy) -1;
880 }
881 
882 uint8_t
884 {
885  NS_ASSERT (IsQosData ());
886  return m_qosStuff;
887 }
888 
889 uint16_t
891 {
892  uint16_t val = 0;
893  val |= (m_ctrlType << 2) & (0x3 << 2);
894  val |= (m_ctrlSubtype << 4) & (0xf << 4);
895  val |= (m_ctrlToDs << 8) & (0x1 << 8);
896  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
897  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
898  val |= (m_ctrlRetry << 11) & (0x1 << 11);
899  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
900  val |= (m_ctrlWep << 14) & (0x1 << 14);
901  val |= (m_ctrlOrder << 15) & (0x1 << 15);
902  return val;
903 }
904 
905 uint16_t
907 {
908  uint16_t val = 0;
909  val |= m_qosTid;
910  val |= m_qosEosp << 4;
911  val |= m_qosAckPolicy << 5;
912  val |= m_amsduPresent << 7;
913  val |= m_qosStuff << 8;
914  return val;
915 }
916 
917 void
919 {
920  m_ctrlType = (ctrl >> 2) & 0x03;
921  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
922  m_ctrlToDs = (ctrl >> 8) & 0x01;
923  m_ctrlFromDs = (ctrl >> 9) & 0x01;
924  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
925  m_ctrlRetry = (ctrl >> 11) & 0x01;
926  m_ctrlMoreData = (ctrl >> 13) & 0x01;
927  m_ctrlWep = (ctrl >> 14) & 0x01;
928  m_ctrlOrder = (ctrl >> 15) & 0x01;
929 }
930 void
932 {
933  m_seqFrag = seq & 0x0f;
934  m_seqSeq = (seq >> 4) & 0x0fff;
935 }
936 void
938 {
939  m_qosTid = qos & 0x000f;
940  m_qosEosp = (qos >> 4) & 0x0001;
941  m_qosAckPolicy = (qos >> 5) & 0x0003;
942  m_amsduPresent = (qos >> 7) & 0x0001;
943  m_qosStuff = (qos >> 8) & 0x00ff;
944 }
945 
946 uint32_t
948 {
949  uint32_t size = 0;
950  switch (m_ctrlType)
951  {
952  case TYPE_MGT:
953  size = 2 + 2 + 6 + 6 + 6 + 2;
954  break;
955  case TYPE_CTL:
956  switch (m_ctrlSubtype)
957  {
958  case SUBTYPE_CTL_RTS:
959  size = 2 + 2 + 6 + 6;
960  break;
961  case SUBTYPE_CTL_CTS:
962  case SUBTYPE_CTL_ACK:
963  size = 2 + 2 + 6;
964  break;
965  case SUBTYPE_CTL_BACKREQ:
967  size = 2 + 2 + 6 + 6;
968  break;
970  size = 2 + 2 + 6 + 2 + 4;
971  break;
972  }
973  break;
974  case TYPE_DATA:
975  size = 2 + 2 + 6 + 6 + 6 + 2;
976  if (m_ctrlToDs && m_ctrlFromDs)
977  {
978  size += 6;
979  }
980  if (m_ctrlSubtype & 0x08)
981  {
982  size += 2;
983  }
984  break;
985  }
986  return size;
987 }
988 
989 const char *
991 {
992 #define FOO(x) \
993 case WIFI_MAC_ ## x: \
994  return # x; \
995  break;
996 
997  switch (GetType ())
998  {
999  FOO (CTL_RTS);
1000  FOO (CTL_CTS);
1001  FOO (CTL_ACK);
1002  FOO (CTL_BACKREQ);
1003  FOO (CTL_BACKRESP);
1004 
1005  FOO (MGT_BEACON);
1006  FOO (MGT_ASSOCIATION_REQUEST);
1007  FOO (MGT_ASSOCIATION_RESPONSE);
1008  FOO (MGT_DISASSOCIATION);
1009  FOO (MGT_REASSOCIATION_REQUEST);
1010  FOO (MGT_REASSOCIATION_RESPONSE);
1011  FOO (MGT_PROBE_REQUEST);
1012  FOO (MGT_PROBE_RESPONSE);
1013  FOO (MGT_AUTHENTICATION);
1014  FOO (MGT_DEAUTHENTICATION);
1015  FOO (MGT_ACTION);
1016  FOO (MGT_ACTION_NO_ACK);
1017  FOO (MGT_MULTIHOP_ACTION);
1018 
1019  FOO (DATA);
1020  FOO (DATA_CFACK);
1021  FOO (DATA_CFPOLL);
1022  FOO (DATA_CFACK_CFPOLL);
1023  FOO (DATA_NULL);
1024  FOO (DATA_NULL_CFACK);
1025  FOO (DATA_NULL_CFPOLL);
1026  FOO (DATA_NULL_CFACK_CFPOLL);
1027  FOO (QOSDATA);
1028  FOO (QOSDATA_CFACK);
1029  FOO (QOSDATA_CFPOLL);
1030  FOO (QOSDATA_CFACK_CFPOLL);
1031  FOO (QOSDATA_NULL);
1032  FOO (QOSDATA_NULL_CFPOLL);
1033  FOO (QOSDATA_NULL_CFACK_CFPOLL);
1034  default:
1035  return "ERROR";
1036  }
1037 #undef FOO
1038  // needed to make gcc 4.0.1 ppc darwin happy.
1039  return "BIG_ERROR";
1040 }
1041 
1042 TypeId
1044 {
1045  static TypeId tid = TypeId ("ns3::WifiMacHeader")
1046  .SetParent<Header> ()
1047  .SetGroupName ("Wifi")
1048  .AddConstructor<WifiMacHeader> ()
1049  ;
1050  return tid;
1051 }
1052 
1053 TypeId
1055 {
1056  return GetTypeId ();
1057 }
1058 
1059 void
1060 WifiMacHeader::PrintFrameControl (std::ostream &os) const
1061 {
1062  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
1063  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
1064  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
1065  ;
1066 }
1067 
1068 void
1069 WifiMacHeader::Print (std::ostream &os) const
1070 {
1071  os << GetTypeString () << " ";
1072  switch (GetType ())
1073  {
1074  case WIFI_MAC_CTL_RTS:
1075  os << "Duration/ID=" << m_duration << "us"
1076  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1077  break;
1078  case WIFI_MAC_CTL_CTS:
1079  case WIFI_MAC_CTL_ACK:
1080  os << "Duration/ID=" << m_duration << "us"
1081  << ", RA=" << m_addr1;
1082  break;
1083  case WIFI_MAC_CTL_BACKREQ:
1084  break;
1085  case WIFI_MAC_CTL_BACKRESP:
1086  break;
1088  break;
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.