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/nstime.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 
32 enum
33 {
34  TYPE_MGT = 0,
35  TYPE_CTL = 1,
37 };
38 
40 enum
41 {
42  //Reserved: 0 - 6
51 };
52 
54  : m_ctrlMoreData (0),
55  m_ctrlWep (0),
56  m_ctrlOrder (0),
57  m_amsduPresent (0)
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68  m_ctrlFromDs = 1;
69 }
70 
71 void
73 {
74  m_ctrlFromDs = 0;
75 }
76 
77 void
79 {
80  m_ctrlToDs = 1;
81 }
82 
83 void
85 {
86  m_ctrlToDs = 0;
87 }
88 
89 void
91 {
92  m_addr1 = address;
93 }
94 
95 void
97 {
98  m_addr2 = address;
99 }
100 
101 void
103 {
104  m_addr3 = address;
105 }
106 
107 void
109 {
110  m_addr4 = address;
111 }
112 
113 void
114 WifiMacHeader::SetType (WifiMacType type, bool resetToDsFromDs)
115 {
116  switch (type)
117  {
121  break;
125  break;
129  break;
130  case WIFI_MAC_CTL_RTS:
133  break;
134  case WIFI_MAC_CTL_CTS:
137  break;
138  case WIFI_MAC_CTL_ACK:
141  break;
142  case WIFI_MAC_CTL_END:
145  break;
149  break;
152  m_ctrlSubtype = 0;
153  break;
156  m_ctrlSubtype = 1;
157  break;
160  m_ctrlSubtype = 2;
161  break;
164  m_ctrlSubtype = 3;
165  break;
168  m_ctrlSubtype = 4;
169  break;
172  m_ctrlSubtype = 5;
173  break;
174  case WIFI_MAC_MGT_BEACON:
176  m_ctrlSubtype = 8;
177  break;
180  m_ctrlSubtype = 10;
181  break;
184  m_ctrlSubtype = 11;
185  break;
188  m_ctrlSubtype = 12;
189  break;
190  case WIFI_MAC_MGT_ACTION:
192  m_ctrlSubtype = 13;
193  break;
196  m_ctrlSubtype = 14;
197  break;
200  m_ctrlSubtype = 15;
201  break;
202  case WIFI_MAC_DATA:
204  m_ctrlSubtype = 0;
205  break;
206  case WIFI_MAC_DATA_CFACK:
208  m_ctrlSubtype = 1;
209  break;
212  m_ctrlSubtype = 2;
213  break;
216  m_ctrlSubtype = 3;
217  break;
218  case WIFI_MAC_DATA_NULL:
220  m_ctrlSubtype = 4;
221  break;
224  m_ctrlSubtype = 5;
225  break;
228  m_ctrlSubtype = 6;
229  break;
232  m_ctrlSubtype = 7;
233  break;
234  case WIFI_MAC_QOSDATA:
236  m_ctrlSubtype = 8;
237  break;
240  m_ctrlSubtype = 9;
241  break;
244  m_ctrlSubtype = 10;
245  break;
248  m_ctrlSubtype = 11;
249  break;
252  m_ctrlSubtype = 12;
253  break;
256  m_ctrlSubtype = 14;
257  break;
260  m_ctrlSubtype = 15;
261  break;
262  }
263  if (resetToDsFromDs)
264  {
265  m_ctrlToDs = 0;
266  m_ctrlFromDs = 0;
267  }
268 }
269 
270 void
271 WifiMacHeader::SetRawDuration (uint16_t duration)
272 {
273  NS_ASSERT (duration <= 32768);
274  m_duration = duration;
275 }
276 
277 void
279 {
280  int64_t duration_us = static_cast<int64_t> (ceil (static_cast<double> (duration.GetNanoSeconds ()) / 1000));
281  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
282  m_duration = static_cast<uint16_t> (duration_us);
283 }
284 
285 void WifiMacHeader::SetId (uint16_t id)
286 {
287  m_duration = id;
288 }
289 
291 {
292  m_seqSeq = seq;
293 }
294 
296 {
297  m_seqFrag = frag;
298 }
299 
301 {
302  m_ctrlMoreFrag = 0;
303 }
304 
306 {
307  m_ctrlMoreFrag = 1;
308 }
309 
311 {
312  m_ctrlOrder = 1;
313 }
314 
316 {
317  m_ctrlOrder = 0;
318 }
319 
321 {
322  m_ctrlRetry = 1;
323 }
324 
326 {
327  m_ctrlRetry = 0;
328 }
329 
330 void WifiMacHeader::SetQosTid (uint8_t tid)
331 {
332  m_qosTid = tid;
333 }
334 
336 {
337  m_qosEosp = 1;
338 }
339 
341 {
342  m_qosEosp = 0;
343 }
344 
346 {
347  switch (policy)
348  {
349  case NORMAL_ACK:
350  m_qosAckPolicy = 0;
351  break;
352  case NO_ACK:
353  m_qosAckPolicy = 1;
354  break;
355  case NO_EXPLICIT_ACK:
356  m_qosAckPolicy = 2;
357  break;
358  case BLOCK_ACK:
359  m_qosAckPolicy = 3;
360  break;
361  }
362 }
363 
365 {
366  m_amsduPresent = 1;
367 }
368 
370 {
371  m_amsduPresent = 0;
372 }
373 
375 {
376  m_qosStuff = txop;
377 }
378 
380 {
381  //Mark bit 0 of this variable instead of bit 8, since m_qosStuff is
382  //shifted by one byte when serialized
383  m_qosStuff = m_qosStuff | 0x01; //bit 8 of QoS Control Field
384 }
385 
387 {
388  //Clear bit 0 of this variable instead of bit 8, since m_qosStuff is
389  //shifted by one byte when serialized
390  m_qosStuff = m_qosStuff & 0xfe; //bit 8 of QoS Control Field
391 }
392 
393 
396 {
397  return m_addr1;
398 }
399 
402 {
403  return m_addr2;
404 }
405 
408 {
409  return m_addr3;
410 }
411 
414 {
415  return m_addr4;
416 }
417 
420 {
421  switch (m_ctrlType)
422  {
423  case TYPE_MGT:
424  switch (m_ctrlSubtype)
425  {
426  case 0:
428  case 1:
430  case 2:
432  case 3:
434  case 4:
436  case 5:
438  case 8:
439  return WIFI_MAC_MGT_BEACON;
440  case 10:
442  case 11:
444  case 12:
446  case 13:
447  return WIFI_MAC_MGT_ACTION;
448  case 14:
450  case 15:
452  }
453  break;
454  case TYPE_CTL:
455  switch (m_ctrlSubtype)
456  {
457  case SUBTYPE_CTL_BACKREQ:
458  return WIFI_MAC_CTL_BACKREQ;
460  return WIFI_MAC_CTL_BACKRESP;
461  case SUBTYPE_CTL_RTS:
462  return WIFI_MAC_CTL_RTS;
463  case SUBTYPE_CTL_CTS:
464  return WIFI_MAC_CTL_CTS;
465  case SUBTYPE_CTL_ACK:
466  return WIFI_MAC_CTL_ACK;
467  case SUBTYPE_CTL_END:
468  return WIFI_MAC_CTL_END;
469  case SUBTYPE_CTL_END_ACK:
470  return WIFI_MAC_CTL_END_ACK;
471  }
472  break;
473  case TYPE_DATA:
474  switch (m_ctrlSubtype)
475  {
476  case 0:
477  return WIFI_MAC_DATA;
478  case 1:
479  return WIFI_MAC_DATA_CFACK;
480  case 2:
481  return WIFI_MAC_DATA_CFPOLL;
482  case 3:
484  case 4:
485  return WIFI_MAC_DATA_NULL;
486  case 5:
488  case 6:
490  case 7:
492  case 8:
493  return WIFI_MAC_QOSDATA;
494  case 9:
495  return WIFI_MAC_QOSDATA_CFACK;
496  case 10:
498  case 11:
500  case 12:
501  return WIFI_MAC_QOSDATA_NULL;
502  case 14:
504  case 15:
506  }
507  break;
508  }
509  // NOTREACHED
510  NS_ASSERT (false);
511  return (WifiMacType) - 1;
512 }
513 
514 bool
516 {
517  return m_ctrlFromDs == 1;
518 }
519 
520 bool
522 {
523  return m_ctrlToDs == 1;
524 }
525 
526 bool
528 {
529  return (m_ctrlType == TYPE_DATA);
530 
531 }
532 
533 bool
535 {
536  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
537 }
538 
539 bool
541 {
542  return (m_ctrlType == TYPE_CTL);
543 }
544 
545 bool
547 {
548  return (m_ctrlType == TYPE_MGT);
549 }
550 
551 bool
553 {
554  switch (GetType ())
555  {
564  return true;
565  default:
566  return false;
567  }
568 }
569 
570 bool
572 {
573  switch (GetType ())
574  {
575  case WIFI_MAC_CTL_END:
577  return true;
578  default:
579  return false;
580  }
581 }
582 
583 bool
585 {
586  switch (GetType ())
587  {
588  case WIFI_MAC_DATA_CFACK:
593  return true;
594  default:
595  return false;
596  break;
597  }
598 }
599 
600 bool
602 {
603  switch (GetType ())
604  {
605  case WIFI_MAC_DATA:
606  case WIFI_MAC_DATA_CFACK:
609  case WIFI_MAC_QOSDATA:
613  return true;
614  default:
615  return false;
616  }
617 }
618 
619 bool
621 {
622  return (GetType () == WIFI_MAC_CTL_RTS);
623 }
624 
625 bool
627 {
628  return (GetType () == WIFI_MAC_CTL_CTS);
629 }
630 
631 bool
633 {
634  return (GetType () == WIFI_MAC_CTL_ACK);
635 }
636 
637 bool
639 {
641 }
642 
643 bool
645 {
647 }
648 
649 bool
651 {
653 }
654 
655 bool
657 {
659 }
660 
661 bool
663 {
664  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
665 }
666 
667 bool
669 {
670  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
671 }
672 
673 bool
675 {
676  return (GetType () == WIFI_MAC_MGT_BEACON);
677 }
678 
679 bool
681 {
682  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
683 }
684 
685 bool
687 {
688  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
689 }
690 
691 bool
693 {
694  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
695 }
696 
697 bool
699 {
700  return (GetType () == WIFI_MAC_MGT_ACTION);
701 }
702 
703 bool
705 {
706  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
707 }
708 
709 bool
711 {
712  return (GetType () == WIFI_MAC_CTL_BACKREQ) ? true : false;
713 }
714 
715 bool
717 {
718  return (GetType () == WIFI_MAC_CTL_BACKRESP) ? true : false;
719 }
720 
721 uint16_t
723 {
724  return m_duration;
725 }
726 
727 Time
729 {
730  return MicroSeconds (m_duration);
731 }
732 
733 uint16_t
735 {
736  return (m_seqSeq << 4) | m_seqFrag;
737 }
738 
739 uint16_t
741 {
742  return m_seqSeq;
743 }
744 
745 uint8_t
747 {
748  return m_seqFrag;
749 }
750 
751 bool
753 {
754  return (m_ctrlRetry == 1);
755 }
756 
757 bool
759 {
760  return (m_ctrlMoreFrag == 1);
761 }
762 
763 bool
765 {
766  NS_ASSERT (IsQosData ());
767  return (m_qosAckPolicy == 3);
768 }
769 
770 bool
772 {
773  NS_ASSERT (IsQosData ());
774  return (m_qosAckPolicy == 1);
775 }
776 
777 bool
779 {
780  NS_ASSERT (IsQosData ());
781  return (m_qosAckPolicy == 0);
782 }
783 
784 bool
786 {
787  NS_ASSERT (IsQosData ());
788  return (m_qosEosp == 1);
789 }
790 
793 {
794  NS_ASSERT (IsQosData ());
795  QosAckPolicy policy;
796 
797  switch (m_qosAckPolicy)
798  {
799  case 0:
800  policy = NORMAL_ACK;
801  break;
802  case 1:
803  policy = NO_ACK;
804  break;
805  case 2:
806  policy = NO_EXPLICIT_ACK;
807  break;
808  case 3:
809  policy = BLOCK_ACK;
810  break;
811  default:
812  NS_ABORT_MSG ("Unknown QoS Ack policy");
813  }
814  return policy;
815 }
816 
817 bool
819 {
820  NS_ASSERT (IsQosData ());
821  return (m_amsduPresent == 1);
822 }
823 
824 uint8_t
826 {
827  NS_ASSERT (IsQosData ());
828  return m_qosTid;
829 }
830 
831 uint16_t
833 {
834  uint16_t val = 0;
835  val |= (m_ctrlType << 2) & (0x3 << 2);
836  val |= (m_ctrlSubtype << 4) & (0xf << 4);
837  val |= (m_ctrlToDs << 8) & (0x1 << 8);
838  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
839  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
840  val |= (m_ctrlRetry << 11) & (0x1 << 11);
841  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
842  val |= (m_ctrlWep << 14) & (0x1 << 14);
843  val |= (m_ctrlOrder << 15) & (0x1 << 15);
844  return val;
845 }
846 
847 uint16_t
849 {
850  uint16_t val = 0;
851  val |= m_qosTid;
852  val |= m_qosEosp << 4;
853  val |= m_qosAckPolicy << 5;
854  val |= m_amsduPresent << 7;
855  val |= m_qosStuff << 8;
856  return val;
857 }
858 
859 void
861 {
862  m_ctrlType = (ctrl >> 2) & 0x03;
863  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
864  m_ctrlToDs = (ctrl >> 8) & 0x01;
865  m_ctrlFromDs = (ctrl >> 9) & 0x01;
866  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
867  m_ctrlRetry = (ctrl >> 11) & 0x01;
868  m_ctrlMoreData = (ctrl >> 13) & 0x01;
869  m_ctrlWep = (ctrl >> 14) & 0x01;
870  m_ctrlOrder = (ctrl >> 15) & 0x01;
871 }
872 void
874 {
875  m_seqFrag = seq & 0x0f;
876  m_seqSeq = (seq >> 4) & 0x0fff;
877 }
878 void
880 {
881  m_qosTid = qos & 0x000f;
882  m_qosEosp = (qos >> 4) & 0x0001;
883  m_qosAckPolicy = (qos >> 5) & 0x0003;
884  m_amsduPresent = (qos >> 7) & 0x0001;
885  m_qosStuff = (qos >> 8) & 0x00ff;
886 }
887 
888 uint32_t
890 {
891  uint32_t size = 0;
892  switch (m_ctrlType)
893  {
894  case TYPE_MGT:
895  size = 2 + 2 + 6 + 6 + 6 + 2;
896  break;
897  case TYPE_CTL:
898  switch (m_ctrlSubtype)
899  {
900  case SUBTYPE_CTL_RTS:
901  case SUBTYPE_CTL_BACKREQ:
903  case SUBTYPE_CTL_END:
904  case SUBTYPE_CTL_END_ACK:
905  size = 2 + 2 + 6 + 6;
906  break;
907  case SUBTYPE_CTL_CTS:
908  case SUBTYPE_CTL_ACK:
909  size = 2 + 2 + 6;
910  break;
912  size = 2 + 2 + 6 + 2 + 4;
913  break;
914  }
915  break;
916  case TYPE_DATA:
917  size = 2 + 2 + 6 + 6 + 6 + 2;
918  if (m_ctrlToDs && m_ctrlFromDs)
919  {
920  size += 6;
921  }
922  if (m_ctrlSubtype & 0x08)
923  {
924  size += 2;
925  }
926  break;
927  }
928  return size;
929 }
930 
931 const char *
933 {
934 #define FOO(x) \
935 case WIFI_MAC_ ## x: \
936  return # x; \
937  break;
938 
939  switch (GetType ())
940  {
941  FOO (CTL_RTS);
942  FOO (CTL_CTS);
943  FOO (CTL_ACK);
944  FOO (CTL_BACKREQ);
945  FOO (CTL_BACKRESP);
946  FOO (CTL_END);
947  FOO (CTL_END_ACK);
948 
949  FOO (MGT_BEACON);
950  FOO (MGT_ASSOCIATION_REQUEST);
951  FOO (MGT_ASSOCIATION_RESPONSE);
952  FOO (MGT_DISASSOCIATION);
953  FOO (MGT_REASSOCIATION_REQUEST);
954  FOO (MGT_REASSOCIATION_RESPONSE);
955  FOO (MGT_PROBE_REQUEST);
956  FOO (MGT_PROBE_RESPONSE);
957  FOO (MGT_AUTHENTICATION);
958  FOO (MGT_DEAUTHENTICATION);
959  FOO (MGT_ACTION);
960  FOO (MGT_ACTION_NO_ACK);
961  FOO (MGT_MULTIHOP_ACTION);
962 
963  FOO (DATA);
964  FOO (DATA_CFACK);
965  FOO (DATA_CFPOLL);
966  FOO (DATA_CFACK_CFPOLL);
967  FOO (DATA_NULL);
968  FOO (DATA_NULL_CFACK);
969  FOO (DATA_NULL_CFPOLL);
970  FOO (DATA_NULL_CFACK_CFPOLL);
971  FOO (QOSDATA);
972  FOO (QOSDATA_CFACK);
973  FOO (QOSDATA_CFPOLL);
974  FOO (QOSDATA_CFACK_CFPOLL);
975  FOO (QOSDATA_NULL);
976  FOO (QOSDATA_NULL_CFPOLL);
977  FOO (QOSDATA_NULL_CFACK_CFPOLL);
978  default:
979  return "ERROR";
980  }
981 #undef FOO
982 #ifndef _WIN32
983  // needed to make gcc 4.0.1 ppc darwin happy.
984  return "BIG_ERROR";
985 #endif
986 }
987 
988 TypeId
990 {
991  static TypeId tid = TypeId ("ns3::WifiMacHeader")
992  .SetParent<Header> ()
993  .SetGroupName ("Wifi")
994  .AddConstructor<WifiMacHeader> ()
995  ;
996  return tid;
997 }
998 
999 TypeId
1001 {
1002  return GetTypeId ();
1003 }
1004 
1005 void
1006 WifiMacHeader::PrintFrameControl (std::ostream &os) const
1007 {
1008  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
1009  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
1010  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
1011  ;
1012 }
1013 
1014 void
1015 WifiMacHeader::Print (std::ostream &os) const
1016 {
1017  os << GetTypeString () << " ";
1018  switch (GetType ())
1019  {
1020  case WIFI_MAC_CTL_RTS:
1021  os << "Duration/ID=" << m_duration << "us"
1022  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1023  break;
1024  case WIFI_MAC_CTL_CTS:
1025  case WIFI_MAC_CTL_ACK:
1026  os << "Duration/ID=" << m_duration << "us"
1027  << ", RA=" << m_addr1;
1028  break;
1029  case WIFI_MAC_MGT_BEACON:
1039  PrintFrameControl (os);
1040  os << " Duration/ID=" << m_duration << "us"
1041  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1042  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1043  << ", SeqNumber=" << m_seqSeq;
1044  break;
1045  case WIFI_MAC_MGT_ACTION:
1047  PrintFrameControl (os);
1048  os << " Duration/ID=" << m_duration << "us"
1049  << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1050  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1051  break;
1053  os << " Duration/ID=" << m_duration << "us"
1054  << ", RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1055  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1056  break;
1057  case WIFI_MAC_DATA:
1058  PrintFrameControl (os);
1059  os << " Duration/ID=" << m_duration << "us";
1060  if (!m_ctrlToDs && !m_ctrlFromDs)
1061  {
1062  os << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1063  }
1064  else if (!m_ctrlToDs && m_ctrlFromDs)
1065  {
1066  os << ", DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1067  }
1068  else if (m_ctrlToDs && !m_ctrlFromDs)
1069  {
1070  os << ", DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1071  }
1072  else if (m_ctrlToDs && m_ctrlFromDs)
1073  {
1074  os << ", DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1075  }
1076  else
1077  {
1078  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1079  }
1080  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1081  << ", SeqNumber=" << m_seqSeq;
1082  break;
1083  case WIFI_MAC_CTL_BACKREQ:
1084  case WIFI_MAC_CTL_BACKRESP:
1086  case WIFI_MAC_CTL_END:
1087  case WIFI_MAC_CTL_END_ACK:
1088  case WIFI_MAC_DATA_CFACK:
1089  case WIFI_MAC_DATA_CFPOLL:
1091  case WIFI_MAC_DATA_NULL:
1095  case WIFI_MAC_QOSDATA:
1099  case WIFI_MAC_QOSDATA_NULL:
1102  default:
1103  break;
1104  }
1105 }
1106 
1107 uint32_t
1109 {
1110  return GetSize ();
1111 }
1112 
1113 void
1115 {
1118  WriteTo (i, m_addr1);
1119  switch (m_ctrlType)
1120  {
1121  case TYPE_MGT:
1122  WriteTo (i, m_addr2);
1123  WriteTo (i, m_addr3);
1125  break;
1126  case TYPE_CTL:
1127  switch (m_ctrlSubtype)
1128  {
1129  case SUBTYPE_CTL_RTS:
1130  case SUBTYPE_CTL_BACKREQ:
1131  case SUBTYPE_CTL_BACKRESP:
1132  case SUBTYPE_CTL_END:
1133  case SUBTYPE_CTL_END_ACK:
1134  WriteTo (i, m_addr2);
1135  break;
1136  case SUBTYPE_CTL_CTS:
1137  case SUBTYPE_CTL_ACK:
1138  break;
1139  default:
1140  //NOTREACHED
1141  NS_ASSERT (false);
1142  break;
1143  }
1144  break;
1145  case TYPE_DATA:
1146  {
1147  WriteTo (i, m_addr2);
1148  WriteTo (i, m_addr3);
1150  if (m_ctrlToDs && m_ctrlFromDs)
1151  {
1152  WriteTo (i, m_addr4);
1153  }
1154  if (m_ctrlSubtype & 0x08)
1155  {
1157  }
1158  } break;
1159  default:
1160  //NOTREACHED
1161  NS_ASSERT (false);
1162  break;
1163  }
1164 }
1165 
1166 uint32_t
1168 {
1169  Buffer::Iterator i = start;
1170  uint16_t frame_control = i.ReadLsbtohU16 ();
1171  SetFrameControl (frame_control);
1172  m_duration = i.ReadLsbtohU16 ();
1173  ReadFrom (i, m_addr1);
1174  switch (m_ctrlType)
1175  {
1176  case TYPE_MGT:
1177  ReadFrom (i, m_addr2);
1178  ReadFrom (i, m_addr3);
1180  break;
1181  case TYPE_CTL:
1182  switch (m_ctrlSubtype)
1183  {
1184  case SUBTYPE_CTL_RTS:
1185  case SUBTYPE_CTL_BACKREQ:
1186  case SUBTYPE_CTL_BACKRESP:
1187  case SUBTYPE_CTL_END:
1188  case SUBTYPE_CTL_END_ACK:
1189  ReadFrom (i, m_addr2);
1190  break;
1191  case SUBTYPE_CTL_CTS:
1192  case SUBTYPE_CTL_ACK:
1193  break;
1194  }
1195  break;
1196  case TYPE_DATA:
1197  ReadFrom (i, m_addr2);
1198  ReadFrom (i, m_addr3);
1200  if (m_ctrlToDs && m_ctrlFromDs)
1201  {
1202  ReadFrom (i, m_addr4);
1203  }
1204  if (m_ctrlSubtype & 0x08)
1205  {
1207  }
1208  break;
1209  }
1210  return i.GetDistanceFrom (start);
1211 }
1212 
1213 } //namespace ns3
uint8_t m_ctrlMoreData
control more data
Protocol header serialization and deserialization.
Definition: header.h:42
bool IsRetry(void) const
Return if the Retry bit is set.
void SetRetry(void)
Set the Retry bit in the Frame Control field.
bool IsCfEnd(void) const
Return true if the header is a CF-END header.
bool IsDisassociation(void) const
Return true if the header is a Disassociation header.
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
uint16_t GetFrameControl(void) const
Return the raw Frame 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.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetDuration(Time duration)
Set the Duration/ID field with the given duration (Time object).
bool IsCtl(void) const
Return true if the Type is Control.
uint8_t m_ctrlType
control type
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1858
Mac48Address m_addr2
address 2
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
void SetNoMoreFragments(void)
Un-set the More Fragment bit in the Frame Control Field.
uint8_t m_qosAckPolicy
QOS ack policy.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 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
bool IsQosEosp(void) const
Return if the end of service period (EOSP) is set.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint8_t m_qosEosp
QOS EOSP.
void Print(std::ostream &os) const
void SetId(uint16_t id)
Set the Duration/ID field with the given ID.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
void SetQosControl(uint16_t qos)
Set the QoS Control field with the given raw value.
const char * GetTypeString(void) const
Return a string corresponds to the header type.
bool IsCfPoll(void) const
Return true if the Type/Subtype is one of the possible CF-Poll headers.
uint8_t m_seqFrag
sequence fragment
Mac48Address m_addr1
address 1
Mac48Address m_addr3
address 3
iterator in a Buffer instance
Definition: buffer.h:98
bool IsBlockAck(void) const
Return true if the header is a Block ACK header.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
bool IsBlockAckReq(void) const
Return true if the header is a Block ACK Request header.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
uint8_t m_ctrlToDs
control to DS
bool IsQosNoAck(void) const
Return if the QoS ACK policy is No ACK.
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
bool IsBeacon(void) const
Return true if the header is a Beacon header.
void SetAddr4(Mac48Address address)
Fill the Address 4 field with the given address.
WifiMacType
Combination of valid MAC header type/subtype.
bool IsMultihopAction() const
Check if the header is a Multihop action header.
void SetOrder(void)
Set order bit in the frame control field.
bool IsFromDs(void) const
Mac48Address GetAddr3(void) const
Return the address in the Address 3 field.
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
bool IsCts(void) const
Return true if the header is a CTS header.
void Serialize(Buffer::Iterator start) const
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 IsAssocResp(void) const
Return true if the header is an Association Response header.
bool IsQosAck(void) const
Return if the QoS ACK policy is Normal ACK.
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
uint8_t m_ctrlOrder
control order (set to 1 for QoS Data and Management frames to signify that HT/VHT/HE control field is...
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Mac48Address GetAddr4(void) const
Return the address in the Address 4 field.
void SetSequenceControl(uint16_t seq)
Set the Sequence Control field with the given raw value.
bool IsCfAck(void) const
Return true if the header is a CF-ACK header.
void SetNoRetry(void)
Un-set the Retry bit in the Frame Control field.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
bool IsData(void) const
Return true if the Type is DATA.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
address
Definition: first.py:37
uint16_t m_seqSeq
sequence sequence
uint8_t m_qosStuff
QOS stuff.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
Time GetDuration(void) const
Return the duration from the Duration/ID field (Time object).
bool IsProbeReq(void) const
Return true if the header is a Probe Request header.
an EUI-48 address
Definition: mac48-address.h:43
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
QosAckPolicy
ACK policy for QoS frames.
#define FOO(x)
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:910
bool IsMoreFragments(void) const
Return if the More Fragment bit is set.
uint16_t m_duration
duration
uint16_t GetRawDuration(void) const
Return the raw duration from the Duration/ID field.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
uint8_t m_ctrlRetry
control retry
bool IsQosBlockAck(void) const
Return if the QoS ACK policy is Block ACK.
uint16_t GetQosControl(void) const
Return the raw QoS Control field.
bool IsDeauthentication(void) const
Return true if the header is a Deauthentication header.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
bool IsMgt(void) const
Return true if the Type is Management.
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
bool IsProbeResp(void) const
Return true if the header is a Probe Response header.
uint32_t GetSerializedSize(void) const
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
bool IsReassocReq(void) const
Return true if the header is a Reassociation Request header.
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
void SetQosEosp()
Set the end of service period (EOSP) bit in the QoS control field.
bool IsRts(void) const
Return true if the header is a RTS header.
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.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1065
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
bool IsAck(void) const
Return true if the header is an ACK header.
bool IsAction() const
Return true if the header is an Action header.
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 SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
static TypeId GetTypeId(void)
Get the type ID.
bool IsAuthentication(void) const
Return true if the header is an Authentication header.
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetQosAmsdu(void)
Set that A-MSDU is present.
void PrintFrameControl(std::ostream &os) const
Print the Frame Control field to the output stream.
Implements the IEEE 802.11 MAC header.
bool IsToDs(void) const
uint8_t m_ctrlWep
control WEP
bool IsReassocResp(void) const
Return true if the header is a Reassociation Response header.
bool HasData(void) const
Return true if the header type is DATA and is not DATA_NULL.
QosAckPolicy GetQosAckPolicy(void) const
Return the QoS ACK policy in the QoS control field.
uint16_t GetSequenceControl(void) const
Return the raw Sequence Control field.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.