A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
31 enum
32 {
33  TYPE_MGT = 0,
34  TYPE_CTL = 1,
36 };
37 
38 enum
39 {
46 
47 };
48 
50  :
51  m_ctrlMoreData (0),
52  m_ctrlWep (0),
53  m_ctrlOrder (1),
54  m_amsduPresent (0)
55 {
56 }
58 {
59 }
60 
61 void
63 {
64  m_ctrlFromDs = 1;
65 }
66 void
68 {
69  m_ctrlFromDs = 0;
70 }
71 void
73 {
74  m_ctrlToDs = 1;
75 }
76 void
78 {
79  m_ctrlToDs = 0;
80 }
81 
82 void
84 {
85  m_addr1 = address;
86 }
87 void
89 {
90  m_addr2 = address;
91 }
92 void
94 {
95  m_addr3 = address;
96 }
97 void
99 {
100  m_addr4 = address;
101 }
102 void
104 {
106  m_ctrlSubtype = 0;
107 }
108 void
110 {
112  m_ctrlSubtype = 1;
113 }
114 void
116 {
118  m_ctrlSubtype = 4;
119 }
120 void
122 {
124  m_ctrlSubtype = 5;
125 }
126 void
128 {
130  m_ctrlSubtype = 8;
131 }
132 void
134 {
136  m_ctrlSubtype = 8;
137 }
138 void
140 {
142  m_ctrlSubtype = 9;
143 }
144 
145 void
147 {
149  m_ctrlSubtype = 0;
150 }
151 void
153 {
155  m_ctrlSubtype = 0x0D;
156 }
157 void
159 {
161  m_ctrlSubtype = 0x0F;
162 }
163 void
165 {
166  switch (type)
167  {
171  break;
175  break;
176  case WIFI_MAC_CTL_RTS:
179  break;
180  case WIFI_MAC_CTL_CTS:
183  break;
184  case WIFI_MAC_CTL_ACK:
187  break;
191  break;
194  m_ctrlSubtype = 0;
195  break;
198  m_ctrlSubtype = 1;
199  break;
202  m_ctrlSubtype = 2;
203  break;
206  m_ctrlSubtype = 3;
207  break;
210  m_ctrlSubtype = 4;
211  break;
214  m_ctrlSubtype = 5;
215  break;
216  case WIFI_MAC_MGT_BEACON:
218  m_ctrlSubtype = 8;
219  break;
222  m_ctrlSubtype = 10;
223  break;
226  m_ctrlSubtype = 11;
227  break;
230  m_ctrlSubtype = 12;
231  break;
232  case WIFI_MAC_MGT_ACTION:
234  m_ctrlSubtype = 13;
235  break;
238  m_ctrlSubtype = 14;
239  break;
242  m_ctrlSubtype = 15;
243  break;
244 
245  case WIFI_MAC_DATA:
247  m_ctrlSubtype = 0;
248  break;
249  case WIFI_MAC_DATA_CFACK:
251  m_ctrlSubtype = 1;
252  break;
255  m_ctrlSubtype = 2;
256  break;
259  m_ctrlSubtype = 3;
260  break;
261  case WIFI_MAC_DATA_NULL:
263  m_ctrlSubtype = 4;
264  break;
267  m_ctrlSubtype = 5;
268  break;
271  m_ctrlSubtype = 6;
272  break;
275  m_ctrlSubtype = 7;
276  break;
277  case WIFI_MAC_QOSDATA:
279  m_ctrlSubtype = 8;
280  break;
283  m_ctrlSubtype = 9;
284  break;
287  m_ctrlSubtype = 10;
288  break;
291  m_ctrlSubtype = 11;
292  break;
295  m_ctrlSubtype = 12;
296  break;
299  m_ctrlSubtype = 14;
300  break;
303  m_ctrlSubtype = 15;
304  break;
305  }
306  m_ctrlToDs = 0;
307  m_ctrlFromDs = 0;
308 }
309 void
310 WifiMacHeader::SetRawDuration (uint16_t duration)
311 {
312  m_duration = duration;
313 }
314 void
316 {
317  int64_t duration_us = duration.GetMicroSeconds ();
318  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
319  m_duration = static_cast<uint16_t> (duration_us);
320 }
321 
322 void WifiMacHeader::SetId (uint16_t id)
323 {
324  m_duration = id;
325 }
327 {
328  m_seqSeq = seq;
329 }
331 {
332  m_seqFrag = frag;
333 }
335 {
336  m_ctrlMoreFrag = 0;
337 }
339 {
340  m_ctrlMoreFrag = 1;
341 }
343 {
344  m_ctrlOrder = 1;
345 }
347 {
348  m_ctrlOrder = 0;
349 }
351 {
352  m_ctrlRetry = 1;
353 }
355 {
356  m_ctrlRetry = 0;
357 }
358 void WifiMacHeader::SetQosTid (uint8_t tid)
359 {
360  m_qosTid = tid;
361 }
363 {
364  m_qosEosp = 1;
365 }
367 {
368  m_qosEosp = 0;
369 }
371 {
372  switch (policy)
373  {
374  case NORMAL_ACK:
375  m_qosAckPolicy = 0;
376  break;
377  case NO_ACK:
378  m_qosAckPolicy = 1;
379  break;
380  case NO_EXPLICIT_ACK:
381  m_qosAckPolicy = 2;
382  break;
383  case BLOCK_ACK:
384  m_qosAckPolicy = 3;
385  break;
386  }
387 }
388 void
390 {
391  m_qosAckPolicy = 0;
392 }
393 void
395 {
396  m_qosAckPolicy = 3;
397 }
398 void
400 {
401  m_qosAckPolicy = 1;
402 }
404 {
405  m_amsduPresent = 1;
406 }
408 {
409  m_amsduPresent = 0;
410 }
412 {
413  m_qosStuff = txop;
414 }
415 
418 {
419  return m_addr1;
420 }
423 {
424  return m_addr2;
425 }
428 {
429  return m_addr3;
430 }
433 {
434  return m_addr4;
435 }
436 
437 enum WifiMacType
439 {
440  switch (m_ctrlType)
441  {
442  case TYPE_MGT:
443  switch (m_ctrlSubtype)
444  {
445  case 0:
447  break;
448  case 1:
450  break;
451  case 2:
453  break;
454  case 3:
456  break;
457  case 4:
459  break;
460  case 5:
462  break;
463  case 8:
464  return WIFI_MAC_MGT_BEACON;
465  break;
466  case 10:
468  break;
469  case 11:
471  break;
472  case 12:
474  break;
475  case 13:
476  return WIFI_MAC_MGT_ACTION;
477  break;
478  case 14:
480  break;
481  case 15:
483  break;
484 
485  }
486  break;
487  case TYPE_CTL:
488  switch (m_ctrlSubtype)
489  {
490  case SUBTYPE_CTL_BACKREQ:
491  return WIFI_MAC_CTL_BACKREQ;
492  break;
494  return WIFI_MAC_CTL_BACKRESP;
495  break;
496  case SUBTYPE_CTL_RTS:
497  return WIFI_MAC_CTL_RTS;
498  break;
499  case SUBTYPE_CTL_CTS:
500  return WIFI_MAC_CTL_CTS;
501  break;
502  case SUBTYPE_CTL_ACK:
503  return WIFI_MAC_CTL_ACK;
504  break;
505  }
506  break;
507  case TYPE_DATA:
508  switch (m_ctrlSubtype)
509  {
510  case 0:
511  return WIFI_MAC_DATA;
512  break;
513  case 1:
514  return WIFI_MAC_DATA_CFACK;
515  break;
516  case 2:
517  return WIFI_MAC_DATA_CFPOLL;
518  break;
519  case 3:
521  break;
522  case 4:
523  return WIFI_MAC_DATA_NULL;
524  break;
525  case 5:
527  break;
528  case 6:
530  break;
531  case 7:
533  break;
534  case 8:
535  return WIFI_MAC_QOSDATA;
536  break;
537  case 9:
538  return WIFI_MAC_QOSDATA_CFACK;
539  break;
540  case 10:
542  break;
543  case 11:
545  break;
546  case 12:
547  return WIFI_MAC_QOSDATA_NULL;
548  break;
549  case 14:
551  break;
552  case 15:
554  break;
555 
556  }
557  break;
558  }
559  // NOTREACHED
560  NS_ASSERT (false);
561  return (enum WifiMacType)-1;
562 }
563 bool
565 {
566  return m_ctrlFromDs == 1;
567 }
568 bool
570 {
571  return m_ctrlToDs == 1;
572 }
573 
574 bool
576 {
577  return (m_ctrlType == TYPE_DATA);
578 
579 }
580 bool
582 {
583  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
584 }
585 bool
587 {
588  return (m_ctrlType == TYPE_CTL);
589 }
590 bool
592 {
593  return (m_ctrlType == TYPE_MGT);
594 }
595 bool
597 {
598  switch (GetType ())
599  {
608  return true;
609  break;
610  default:
611  return false;
612  break;
613  }
614 }
615 bool
617 {
618  return (GetType () == WIFI_MAC_CTL_RTS);
619 }
620 bool
622 {
623  return (GetType () == WIFI_MAC_CTL_CTS);
624 }
625 bool
627 {
628  return (GetType () == WIFI_MAC_CTL_ACK);
629 }
630 bool
632 {
634 }
635 bool
637 {
639 }
640 bool
642 {
644 }
645 bool
647 {
649 }
650 bool
652 {
653  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
654 }
655 bool
657 {
658  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
659 }
660 bool
662 {
663  return (GetType () == WIFI_MAC_MGT_BEACON);
664 }
665 bool
667 {
668  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
669 }
670 bool
672 {
673  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
674 }
675 bool
677 {
678  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
679 }
680 bool
682 {
683  return (GetType () == WIFI_MAC_MGT_ACTION);
684 }
685 bool
687 {
688  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
689 }
690 bool
692 {
693  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
694 }
695 bool
697 {
698  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
699 }
700 
701 
702 uint16_t
704 {
705  return m_duration;
706 }
707 Time
709 {
710  return MicroSeconds (m_duration);
711 }
712 uint16_t
714 {
715  return (m_seqSeq << 4) | m_seqFrag;
716 }
717 uint16_t
719 {
720  return m_seqSeq;
721 }
722 uint16_t
724 {
725  return m_seqFrag;
726 }
727 bool
729 {
730  return (m_ctrlRetry == 1);
731 }
732 bool
734 {
735  return (m_ctrlMoreFrag == 1);
736 }
737 bool
739 {
740  NS_ASSERT (IsQosData ());
741  return (m_qosAckPolicy == 3);
742 }
743 bool
745 {
746  NS_ASSERT (IsQosData ());
747  return (m_qosAckPolicy == 1);
748 }
749 bool
751 {
752  NS_ASSERT (IsQosData ());
753  return (m_qosAckPolicy == 0);
754 }
755 bool
757 {
758  NS_ASSERT (IsQosData ());
759  return (m_qosEosp == 1);
760 }
761 bool
763 {
764  NS_ASSERT (IsQosData ());
765  return (m_amsduPresent == 1);
766 }
767 uint8_t
769 {
770  NS_ASSERT (IsQosData ());
771  return m_qosTid;
772 }
775 {
776  switch (m_qosAckPolicy)
777  {
778  case 0:
779  return NORMAL_ACK;
780  break;
781  case 1:
782  return NO_ACK;
783  break;
784  case 2:
785  return NO_EXPLICIT_ACK;
786  break;
787  case 3:
788  return BLOCK_ACK;
789  break;
790  }
791  // NOTREACHED
792  NS_ASSERT (false);
793  return (enum QosAckPolicy)-1;
794 }
795 
796 uint8_t
798 {
799  NS_ASSERT (IsQosData ());
800  return m_qosStuff;
801 }
802 
803 uint16_t
805 {
806  uint16_t val = 0;
807  val |= (m_ctrlType << 2) & (0x3 << 2);
808  val |= (m_ctrlSubtype << 4) & (0xf << 4);
809  val |= (m_ctrlToDs << 8) & (0x1 << 8);
810  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
811  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
812  val |= (m_ctrlRetry << 11) & (0x1 << 11);
813  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
814  val |= (m_ctrlWep << 14) & (0x1 << 14);
815  val |= (m_ctrlOrder << 15) & (0x1 << 15);
816  return val;
817 }
818 
819 uint16_t
821 {
822  uint16_t val = 0;
823  val |= m_qosTid;
824  val |= m_qosEosp << 4;
825  val |= m_qosAckPolicy << 5;
826  val |= m_amsduPresent << 7;
827  val |= m_qosStuff << 8;
828  return val;
829 }
830 
831 void
833 {
834  m_ctrlType = (ctrl >> 2) & 0x03;
835  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
836  m_ctrlToDs = (ctrl >> 8) & 0x01;
837  m_ctrlFromDs = (ctrl >> 9) & 0x01;
838  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
839  m_ctrlRetry = (ctrl >> 11) & 0x01;
840  m_ctrlMoreData = (ctrl >> 13) & 0x01;
841  m_ctrlWep = (ctrl >> 14) & 0x01;
842  m_ctrlOrder = (ctrl >> 15) & 0x01;
843 }
844 void
846 {
847  m_seqFrag = seq & 0x0f;
848  m_seqSeq = (seq >> 4) & 0x0fff;
849 }
850 void
852 {
853  m_qosTid = qos & 0x000f;
854  m_qosEosp = (qos >> 4) & 0x0001;
855  m_qosAckPolicy = (qos >> 5) & 0x0003;
856  m_amsduPresent = (qos >> 7) & 0x0001;
857  m_qosStuff = (qos >> 8) & 0x00ff;
858 }
859 
860 uint32_t
862 {
863  uint32_t size = 0;
864  switch (m_ctrlType)
865  {
866  case TYPE_MGT:
867  size = 2 + 2 + 6 + 6 + 6 + 2;
868  break;
869  case TYPE_CTL:
870  switch (m_ctrlSubtype)
871  {
872  case SUBTYPE_CTL_RTS:
873  size = 2 + 2 + 6 + 6;
874  break;
875  case SUBTYPE_CTL_CTS:
876  case SUBTYPE_CTL_ACK:
877  size = 2 + 2 + 6;
878  break;
879  case SUBTYPE_CTL_BACKREQ:
881  size = 2 + 2 + 6 + 6;
882  break;
884  size = 2 +2 +6 +2 +4;
885  break;
886  }
887  break;
888  case TYPE_DATA:
889  size = 2 + 2 + 6 + 6 + 6 + 2;
890  if (m_ctrlToDs && m_ctrlFromDs)
891  {
892  size += 6;
893  }
894  if (m_ctrlSubtype & 0x08)
895  {
896  size += 2;
897  }
898  break;
899  }
900  return size;
901 }
902 const char *
904 {
905 #define FOO(x) \
906 case WIFI_MAC_ ## x: \
907  return # x; \
908  break;
909 
910  switch (GetType ())
911  {
912  FOO (CTL_RTS);
913  FOO (CTL_CTS);
914  FOO (CTL_ACK);
915  FOO (CTL_BACKREQ);
916  FOO (CTL_BACKRESP);
917 
918  FOO (MGT_BEACON);
919  FOO (MGT_ASSOCIATION_REQUEST);
920  FOO (MGT_ASSOCIATION_RESPONSE);
921  FOO (MGT_DISASSOCIATION);
922  FOO (MGT_REASSOCIATION_REQUEST);
923  FOO (MGT_REASSOCIATION_RESPONSE);
924  FOO (MGT_PROBE_REQUEST);
925  FOO (MGT_PROBE_RESPONSE);
926  FOO (MGT_AUTHENTICATION);
927  FOO (MGT_DEAUTHENTICATION);
928  FOO (MGT_ACTION);
929  FOO (MGT_ACTION_NO_ACK);
930  FOO (MGT_MULTIHOP_ACTION);
931 
932  FOO (DATA);
933  FOO (DATA_CFACK);
934  FOO (DATA_CFPOLL);
935  FOO (DATA_CFACK_CFPOLL);
936  FOO (DATA_NULL);
937  FOO (DATA_NULL_CFACK);
938  FOO (DATA_NULL_CFPOLL);
939  FOO (DATA_NULL_CFACK_CFPOLL);
940  FOO (QOSDATA);
941  FOO (QOSDATA_CFACK);
942  FOO (QOSDATA_CFPOLL);
943  FOO (QOSDATA_CFACK_CFPOLL);
944  FOO (QOSDATA_NULL);
945  FOO (QOSDATA_NULL_CFPOLL);
946  FOO (QOSDATA_NULL_CFACK_CFPOLL);
947  default:
948  return "ERROR";
949  }
950 #undef FOO
951  // needed to make gcc 4.0.1 ppc darwin happy.
952  return "BIG_ERROR";
953 }
954 
955 TypeId
957 {
958  static TypeId tid = TypeId ("ns3::WifiMacHeader")
959  .SetParent<Header> ()
960  .AddConstructor<WifiMacHeader> ()
961  ;
962  return tid;
963 }
964 
965 TypeId
967 {
968  return GetTypeId ();
969 }
970 
971 void
972 WifiMacHeader::PrintFrameControl (std::ostream &os) const
973 {
974  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
975  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
976  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
977  ;
978 }
979 
980 void
981 WifiMacHeader::Print (std::ostream &os) const
982 {
983  os << GetTypeString () << " ";
984  switch (GetType ())
985  {
986  case WIFI_MAC_CTL_RTS:
987  os << "Duration/ID=" << m_duration << "us"
988  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
989  break;
990  case WIFI_MAC_CTL_CTS:
991  case WIFI_MAC_CTL_ACK:
992  os << "Duration/ID=" << m_duration << "us"
993  << ", RA=" << m_addr1;
994  break;
996  break;
998  break;
1000  break;
1001 
1002  case WIFI_MAC_MGT_BEACON:
1012  PrintFrameControl (os);
1013  os << " Duration/ID=" << m_duration << "us"
1014  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1015  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1016  << ", SeqNumber=" << m_seqSeq;
1017  break;
1018  case WIFI_MAC_MGT_ACTION:
1020  PrintFrameControl (os);
1021  os << " Duration/ID=" << m_duration << "us"
1022  << "DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1023  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1024  break;
1026  os << " Duration/ID=" << m_duration << "us"
1027  << "RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1028  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1029  break;
1030  case WIFI_MAC_DATA:
1031  PrintFrameControl (os);
1032  os << " Duration/ID=" << m_duration << "us";
1033  if (!m_ctrlToDs && !m_ctrlFromDs)
1034  {
1035  os << "DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1036  }
1037  else if (!m_ctrlToDs && m_ctrlFromDs)
1038  {
1039  os << "DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1040  }
1041  else if (m_ctrlToDs && !m_ctrlFromDs)
1042  {
1043  os << "DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1044  }
1045  else if (m_ctrlToDs && m_ctrlFromDs)
1046  {
1047  os << "DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1048  }
1049  else
1050  {
1051  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1052  }
1053  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1054  << ", SeqNumber=" << m_seqSeq;
1055  break;
1056  case WIFI_MAC_DATA_CFACK:
1057  case WIFI_MAC_DATA_CFPOLL:
1059  case WIFI_MAC_DATA_NULL:
1063  case WIFI_MAC_QOSDATA:
1067  case WIFI_MAC_QOSDATA_NULL:
1070  break;
1071  }
1072 }
1073 uint32_t
1075 {
1076  return GetSize ();
1077 }
1078 void
1080 {
1083  WriteTo (i, m_addr1);
1084  switch (m_ctrlType)
1085  {
1086  case TYPE_MGT:
1087  WriteTo (i, m_addr2);
1088  WriteTo (i, m_addr3);
1090  break;
1091  case TYPE_CTL:
1092  switch (m_ctrlSubtype)
1093  {
1094  case SUBTYPE_CTL_RTS:
1095  WriteTo (i, m_addr2);
1096  break;
1097  case SUBTYPE_CTL_CTS:
1098  case SUBTYPE_CTL_ACK:
1099  break;
1100  case SUBTYPE_CTL_BACKREQ:
1101  case SUBTYPE_CTL_BACKRESP:
1102  WriteTo (i, m_addr2);
1103  break;
1104  default:
1105  //NOTREACHED
1106  NS_ASSERT (false);
1107  break;
1108  }
1109  break;
1110  case TYPE_DATA:
1111  {
1112  WriteTo (i, m_addr2);
1113  WriteTo (i, m_addr3);
1115  if (m_ctrlToDs && m_ctrlFromDs)
1116  {
1117  WriteTo (i, m_addr4);
1118  }
1119  if (m_ctrlSubtype & 0x08)
1120  {
1122  }
1123  } break;
1124  default:
1125  //NOTREACHED
1126  NS_ASSERT (false);
1127  break;
1128  }
1129 }
1130 uint32_t
1132 {
1133  Buffer::Iterator i = start;
1134  uint16_t frame_control = i.ReadLsbtohU16 ();
1135  SetFrameControl (frame_control);
1136  m_duration = i.ReadLsbtohU16 ();
1137  ReadFrom (i, m_addr1);
1138  switch (m_ctrlType)
1139  {
1140  case TYPE_MGT:
1141  ReadFrom (i, m_addr2);
1142  ReadFrom (i, m_addr3);
1144  break;
1145  case TYPE_CTL:
1146  switch (m_ctrlSubtype)
1147  {
1148  case SUBTYPE_CTL_RTS:
1149  ReadFrom (i, m_addr2);
1150  break;
1151  case SUBTYPE_CTL_CTS:
1152  case SUBTYPE_CTL_ACK:
1153  break;
1154  case SUBTYPE_CTL_BACKREQ:
1155  case SUBTYPE_CTL_BACKRESP:
1156  ReadFrom (i, m_addr2);
1157  break;
1158  }
1159  break;
1160  case TYPE_DATA:
1161  ReadFrom (i, m_addr2);
1162  ReadFrom (i, m_addr3);
1164  if (m_ctrlToDs && m_ctrlFromDs)
1165  {
1166  ReadFrom (i, m_addr4);
1167  }
1168  if (m_ctrlSubtype & 0x08)
1169  {
1171  }
1172  break;
1173  }
1174  return i.GetDistanceFrom (start);
1175 }
1176 
1177 } // 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.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
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.
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.
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)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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.
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:807
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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.
int64_t GetMicroSeconds(void) const
Definition: nstime.h:291
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
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
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.
an EUI-48 address
Definition: mac48-address.h:41
void SetBlockAck(void)
Set Type/Subtype values for a Block Ack header.
QosAckPolicy
ACK policy for QoS frames.
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:935
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:1090
bool IsMultihopAction() const
Check if the header is a Multihop action header.
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 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:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
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.
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.