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  :
50  m_ctrlMoreData (0),
51  m_ctrlWep (0),
52  m_ctrlOrder (1),
53  m_amsduPresent (0)
54 {
55 }
57 {
58 }
59 
60 void
62 {
63  m_ctrlFromDs = 1;
64 }
65 void
67 {
68  m_ctrlFromDs = 0;
69 }
70 void
72 {
73  m_ctrlToDs = 1;
74 }
75 void
77 {
78  m_ctrlToDs = 0;
79 }
80 
81 void
83 {
84  m_addr1 = address;
85 }
86 void
88 {
89  m_addr2 = address;
90 }
91 void
93 {
94  m_addr3 = address;
95 }
96 void
98 {
99  m_addr4 = address;
100 }
101 void
103 {
105  m_ctrlSubtype = 0;
106 }
107 void
109 {
111  m_ctrlSubtype = 1;
112 }
113 void
115 {
117  m_ctrlSubtype = 4;
118 }
119 void
121 {
123  m_ctrlSubtype = 5;
124 }
125 void
127 {
129  m_ctrlSubtype = 8;
130 }
131 void
133 {
135  m_ctrlSubtype = 8;
136 }
137 void
139 {
141  m_ctrlSubtype = 9;
142 }
143 
144 void
146 {
148  m_ctrlSubtype = 0;
149 }
150 void
152 {
154  m_ctrlSubtype = 0x0D;
155 }
156 void
158 {
160  m_ctrlSubtype = 0x0F;
161 }
162 void
164 {
165  switch (type)
166  {
170  break;
174  break;
175  case WIFI_MAC_CTL_RTS:
178  break;
179  case WIFI_MAC_CTL_CTS:
182  break;
183  case WIFI_MAC_CTL_ACK:
186  break;
190  break;
193  m_ctrlSubtype = 0;
194  break;
197  m_ctrlSubtype = 1;
198  break;
201  m_ctrlSubtype = 2;
202  break;
205  m_ctrlSubtype = 3;
206  break;
209  m_ctrlSubtype = 4;
210  break;
213  m_ctrlSubtype = 5;
214  break;
215  case WIFI_MAC_MGT_BEACON:
217  m_ctrlSubtype = 8;
218  break;
221  m_ctrlSubtype = 10;
222  break;
225  m_ctrlSubtype = 11;
226  break;
229  m_ctrlSubtype = 12;
230  break;
231  case WIFI_MAC_MGT_ACTION:
233  m_ctrlSubtype = 13;
234  break;
237  m_ctrlSubtype = 14;
238  break;
241  m_ctrlSubtype = 15;
242  break;
243 
244  case WIFI_MAC_DATA:
246  m_ctrlSubtype = 0;
247  break;
248  case WIFI_MAC_DATA_CFACK:
250  m_ctrlSubtype = 1;
251  break;
254  m_ctrlSubtype = 2;
255  break;
258  m_ctrlSubtype = 3;
259  break;
260  case WIFI_MAC_DATA_NULL:
262  m_ctrlSubtype = 4;
263  break;
266  m_ctrlSubtype = 5;
267  break;
270  m_ctrlSubtype = 6;
271  break;
274  m_ctrlSubtype = 7;
275  break;
276  case WIFI_MAC_QOSDATA:
278  m_ctrlSubtype = 8;
279  break;
282  m_ctrlSubtype = 9;
283  break;
286  m_ctrlSubtype = 10;
287  break;
290  m_ctrlSubtype = 11;
291  break;
294  m_ctrlSubtype = 12;
295  break;
298  m_ctrlSubtype = 14;
299  break;
302  m_ctrlSubtype = 15;
303  break;
304  }
305  m_ctrlToDs = 0;
306  m_ctrlFromDs = 0;
307 }
308 void
309 WifiMacHeader::SetRawDuration (uint16_t duration)
310 {
311  m_duration = duration;
312 }
313 void
315 {
316  int64_t duration_us = ceil((double)duration.GetNanoSeconds ()/1000);
317  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
318  m_duration = static_cast<uint16_t> (duration_us);
319 }
320 
321 void WifiMacHeader::SetId (uint16_t id)
322 {
323  m_duration = id;
324 }
326 {
327  m_seqSeq = seq;
328 }
330 {
331  m_seqFrag = frag;
332 }
334 {
335  m_ctrlMoreFrag = 0;
336 }
338 {
339  m_ctrlMoreFrag = 1;
340 }
342 {
343  m_ctrlOrder = 1;
344 }
346 {
347  m_ctrlOrder = 0;
348 }
350 {
351  m_ctrlRetry = 1;
352 }
354 {
355  m_ctrlRetry = 0;
356 }
357 void WifiMacHeader::SetQosTid (uint8_t tid)
358 {
359  m_qosTid = tid;
360 }
362 {
363  m_qosEosp = 1;
364 }
366 {
367  m_qosEosp = 0;
368 }
370 {
371  switch (policy)
372  {
373  case NORMAL_ACK:
374  m_qosAckPolicy = 0;
375  break;
376  case NO_ACK:
377  m_qosAckPolicy = 1;
378  break;
379  case NO_EXPLICIT_ACK:
380  m_qosAckPolicy = 2;
381  break;
382  case BLOCK_ACK:
383  m_qosAckPolicy = 3;
384  break;
385  }
386 }
387 void
389 {
390  m_qosAckPolicy = 0;
391 }
392 void
394 {
395  m_qosAckPolicy = 3;
396 }
397 void
399 {
400  m_qosAckPolicy = 1;
401 }
403 {
404  m_amsduPresent = 1;
405 }
407 {
408  m_amsduPresent = 0;
409 }
411 {
412  m_qosStuff = txop;
413 }
414 
417 {
418  return m_addr1;
419 }
422 {
423  return m_addr2;
424 }
427 {
428  return m_addr3;
429 }
432 {
433  return m_addr4;
434 }
435 
436 enum WifiMacType
438 {
439  switch (m_ctrlType)
440  {
441  case TYPE_MGT:
442  switch (m_ctrlSubtype)
443  {
444  case 0:
446  break;
447  case 1:
449  break;
450  case 2:
452  break;
453  case 3:
455  break;
456  case 4:
458  break;
459  case 5:
461  break;
462  case 8:
463  return WIFI_MAC_MGT_BEACON;
464  break;
465  case 10:
467  break;
468  case 11:
470  break;
471  case 12:
473  break;
474  case 13:
475  return WIFI_MAC_MGT_ACTION;
476  break;
477  case 14:
479  break;
480  case 15:
482  break;
483 
484  }
485  break;
486  case TYPE_CTL:
487  switch (m_ctrlSubtype)
488  {
489  case SUBTYPE_CTL_BACKREQ:
490  return WIFI_MAC_CTL_BACKREQ;
491  break;
493  return WIFI_MAC_CTL_BACKRESP;
494  break;
495  case SUBTYPE_CTL_RTS:
496  return WIFI_MAC_CTL_RTS;
497  break;
498  case SUBTYPE_CTL_CTS:
499  return WIFI_MAC_CTL_CTS;
500  break;
501  case SUBTYPE_CTL_ACK:
502  return WIFI_MAC_CTL_ACK;
503  break;
504  }
505  break;
506  case TYPE_DATA:
507  switch (m_ctrlSubtype)
508  {
509  case 0:
510  return WIFI_MAC_DATA;
511  break;
512  case 1:
513  return WIFI_MAC_DATA_CFACK;
514  break;
515  case 2:
516  return WIFI_MAC_DATA_CFPOLL;
517  break;
518  case 3:
520  break;
521  case 4:
522  return WIFI_MAC_DATA_NULL;
523  break;
524  case 5:
526  break;
527  case 6:
529  break;
530  case 7:
532  break;
533  case 8:
534  return WIFI_MAC_QOSDATA;
535  break;
536  case 9:
537  return WIFI_MAC_QOSDATA_CFACK;
538  break;
539  case 10:
541  break;
542  case 11:
544  break;
545  case 12:
546  return WIFI_MAC_QOSDATA_NULL;
547  break;
548  case 14:
550  break;
551  case 15:
553  break;
554 
555  }
556  break;
557  }
558  // NOTREACHED
559  NS_ASSERT (false);
560  return (enum WifiMacType)-1;
561 }
562 bool
564 {
565  return m_ctrlFromDs == 1;
566 }
567 bool
569 {
570  return m_ctrlToDs == 1;
571 }
572 
573 bool
575 {
576  return (m_ctrlType == TYPE_DATA);
577 
578 }
579 bool
581 {
582  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
583 }
584 bool
586 {
587  return (m_ctrlType == TYPE_CTL);
588 }
589 bool
591 {
592  return (m_ctrlType == TYPE_MGT);
593 }
594 bool
596 {
597  switch (GetType ())
598  {
607  return true;
608  break;
609  default:
610  return false;
611  break;
612  }
613 }
614 bool
616 {
617  return (GetType () == WIFI_MAC_CTL_RTS);
618 }
619 bool
621 {
622  return (GetType () == WIFI_MAC_CTL_CTS);
623 }
624 bool
626 {
627  return (GetType () == WIFI_MAC_CTL_ACK);
628 }
629 bool
631 {
633 }
634 bool
636 {
638 }
639 bool
641 {
643 }
644 bool
646 {
648 }
649 bool
651 {
652  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
653 }
654 bool
656 {
657  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
658 }
659 bool
661 {
662  return (GetType () == WIFI_MAC_MGT_BEACON);
663 }
664 bool
666 {
667  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
668 }
669 bool
671 {
672  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
673 }
674 bool
676 {
677  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
678 }
679 bool
681 {
682  return (GetType () == WIFI_MAC_MGT_ACTION);
683 }
684 bool
686 {
687  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
688 }
689 bool
691 {
692  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
693 }
694 bool
696 {
697  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
698 }
699 
700 
701 uint16_t
703 {
704  return m_duration;
705 }
706 Time
708 {
709  return MicroSeconds (m_duration);
710 }
711 uint16_t
713 {
714  return (m_seqSeq << 4) | m_seqFrag;
715 }
716 uint16_t
718 {
719  return m_seqSeq;
720 }
721 uint16_t
723 {
724  return m_seqFrag;
725 }
726 bool
728 {
729  return (m_ctrlRetry == 1);
730 }
731 bool
733 {
734  return (m_ctrlMoreFrag == 1);
735 }
736 bool
738 {
739  NS_ASSERT (IsQosData ());
740  return (m_qosAckPolicy == 3);
741 }
742 bool
744 {
745  NS_ASSERT (IsQosData ());
746  return (m_qosAckPolicy == 1);
747 }
748 bool
750 {
751  NS_ASSERT (IsQosData ());
752  return (m_qosAckPolicy == 0);
753 }
754 bool
756 {
757  NS_ASSERT (IsQosData ());
758  return (m_qosEosp == 1);
759 }
760 bool
762 {
763  NS_ASSERT (IsQosData ());
764  return (m_amsduPresent == 1);
765 }
766 uint8_t
768 {
769  NS_ASSERT (IsQosData ());
770  return m_qosTid;
771 }
774 {
775  switch (m_qosAckPolicy)
776  {
777  case 0:
778  return NORMAL_ACK;
779  break;
780  case 1:
781  return NO_ACK;
782  break;
783  case 2:
784  return NO_EXPLICIT_ACK;
785  break;
786  case 3:
787  return BLOCK_ACK;
788  break;
789  }
790  // NOTREACHED
791  NS_ASSERT (false);
792  return (enum QosAckPolicy)-1;
793 }
794 
795 uint8_t
797 {
798  NS_ASSERT (IsQosData ());
799  return m_qosStuff;
800 }
801 
802 uint16_t
804 {
805  uint16_t val = 0;
806  val |= (m_ctrlType << 2) & (0x3 << 2);
807  val |= (m_ctrlSubtype << 4) & (0xf << 4);
808  val |= (m_ctrlToDs << 8) & (0x1 << 8);
809  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
810  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
811  val |= (m_ctrlRetry << 11) & (0x1 << 11);
812  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
813  val |= (m_ctrlWep << 14) & (0x1 << 14);
814  val |= (m_ctrlOrder << 15) & (0x1 << 15);
815  return val;
816 }
817 
818 uint16_t
820 {
821  uint16_t val = 0;
822  val |= m_qosTid;
823  val |= m_qosEosp << 4;
824  val |= m_qosAckPolicy << 5;
825  val |= m_amsduPresent << 7;
826  val |= m_qosStuff << 8;
827  return val;
828 }
829 
830 void
832 {
833  m_ctrlType = (ctrl >> 2) & 0x03;
834  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
835  m_ctrlToDs = (ctrl >> 8) & 0x01;
836  m_ctrlFromDs = (ctrl >> 9) & 0x01;
837  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
838  m_ctrlRetry = (ctrl >> 11) & 0x01;
839  m_ctrlMoreData = (ctrl >> 13) & 0x01;
840  m_ctrlWep = (ctrl >> 14) & 0x01;
841  m_ctrlOrder = (ctrl >> 15) & 0x01;
842 }
843 void
845 {
846  m_seqFrag = seq & 0x0f;
847  m_seqSeq = (seq >> 4) & 0x0fff;
848 }
849 void
851 {
852  m_qosTid = qos & 0x000f;
853  m_qosEosp = (qos >> 4) & 0x0001;
854  m_qosAckPolicy = (qos >> 5) & 0x0003;
855  m_amsduPresent = (qos >> 7) & 0x0001;
856  m_qosStuff = (qos >> 8) & 0x00ff;
857 }
858 
859 uint32_t
861 {
862  uint32_t size = 0;
863  switch (m_ctrlType)
864  {
865  case TYPE_MGT:
866  size = 2 + 2 + 6 + 6 + 6 + 2;
867  break;
868  case TYPE_CTL:
869  switch (m_ctrlSubtype)
870  {
871  case SUBTYPE_CTL_RTS:
872  size = 2 + 2 + 6 + 6;
873  break;
874  case SUBTYPE_CTL_CTS:
875  case SUBTYPE_CTL_ACK:
876  size = 2 + 2 + 6;
877  break;
878  case SUBTYPE_CTL_BACKREQ:
880  size = 2 + 2 + 6 + 6;
881  break;
883  size = 2 +2 +6 +2 +4;
884  break;
885  }
886  break;
887  case TYPE_DATA:
888  size = 2 + 2 + 6 + 6 + 6 + 2;
889  if (m_ctrlToDs && m_ctrlFromDs)
890  {
891  size += 6;
892  }
893  if (m_ctrlSubtype & 0x08)
894  {
895  size += 2;
896  }
897  break;
898  }
899  return size;
900 }
901 const char *
903 {
904 #define FOO(x) \
905 case WIFI_MAC_ ## x: \
906  return # x; \
907  break;
908 
909  switch (GetType ())
910  {
911  FOO (CTL_RTS);
912  FOO (CTL_CTS);
913  FOO (CTL_ACK);
914  FOO (CTL_BACKREQ);
915  FOO (CTL_BACKRESP);
916 
917  FOO (MGT_BEACON);
918  FOO (MGT_ASSOCIATION_REQUEST);
919  FOO (MGT_ASSOCIATION_RESPONSE);
920  FOO (MGT_DISASSOCIATION);
921  FOO (MGT_REASSOCIATION_REQUEST);
922  FOO (MGT_REASSOCIATION_RESPONSE);
923  FOO (MGT_PROBE_REQUEST);
924  FOO (MGT_PROBE_RESPONSE);
925  FOO (MGT_AUTHENTICATION);
926  FOO (MGT_DEAUTHENTICATION);
927  FOO (MGT_ACTION);
928  FOO (MGT_ACTION_NO_ACK);
929  FOO (MGT_MULTIHOP_ACTION);
930 
931  FOO (DATA);
932  FOO (DATA_CFACK);
933  FOO (DATA_CFPOLL);
934  FOO (DATA_CFACK_CFPOLL);
935  FOO (DATA_NULL);
936  FOO (DATA_NULL_CFACK);
937  FOO (DATA_NULL_CFPOLL);
938  FOO (DATA_NULL_CFACK_CFPOLL);
939  FOO (QOSDATA);
940  FOO (QOSDATA_CFACK);
941  FOO (QOSDATA_CFPOLL);
942  FOO (QOSDATA_CFACK_CFPOLL);
943  FOO (QOSDATA_NULL);
944  FOO (QOSDATA_NULL_CFPOLL);
945  FOO (QOSDATA_NULL_CFACK_CFPOLL);
946  default:
947  return "ERROR";
948  }
949 #undef FOO
950  // needed to make gcc 4.0.1 ppc darwin happy.
951  return "BIG_ERROR";
952 }
953 
954 TypeId
956 {
957  static TypeId tid = TypeId ("ns3::WifiMacHeader")
958  .SetParent<Header> ()
959  .SetGroupName ("Wifi")
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.
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)
Fatal error handling.
Definition: fatal-error.h:100
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:811
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:939
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:346
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:1094
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:882
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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
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.