A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lr-wpan-mac-header.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: kwong yin <kwong-sang.yin@boeing.com>
19  */
20 
38 #ifndef LR_WPAN_MAC_HEADER_H
39 #define LR_WPAN_MAC_HEADER_H
40 
41 #include <ns3/header.h>
42 #include <ns3/mac16-address.h>
43 #include <ns3/mac64-address.h>
44 
45 
46 namespace ns3 {
47 
48 
49 /*
50  * \ingroup lr-wpan
51  * Represent the Mac Header with the Frame Control and Sequence Number fields
52  */
53 class LrWpanMacHeader : public Header
54 {
55 
56 public:
58  {
64  };
65 
67  {
68  NOADDR = 0,
69  RESADDR = 1,
70  SHORTADDR = 2,
71  EXTADDR = 3
72  };
73 
75  {
76  IMPLICIT = 0,
80  };
81 
82  LrWpanMacHeader (void);
83 
84  LrWpanMacHeader (enum LrWpanMacType wpanMacType, // Data, ACK, Control MAC Header must have
85  uint8_t seqNum); // frame control and sequence number.
86  // Beacon MAC Header must have frame control,
87  // sequence number, source PAN Id, source address.
88 
89  ~LrWpanMacHeader (void);
90 
91 
92  enum LrWpanMacType GetType (void) const;
93  uint16_t GetFrameControl (void) const;
94  bool IsSecEnable (void) const;
95  bool IsSecDisable (void) const;
96  bool IsFrmPend (void) const;
97  bool IsNoFrmPend (void) const;
98  bool IsAckReq (void) const;
99  bool IsNoAckReq (void) const;
100  bool IsPanIdComp (void) const;
101  bool IsNoPanIdComp (void) const;
102  uint8_t GetFrmCtrlRes (void) const;
103  uint8_t GetDstAddrMode (void) const;
104  uint8_t GetFrameVer (void) const;
105  uint8_t GetSrcAddrMode (void) const;
106 
107  uint8_t GetSeqNum (void) const;
108 
109  uint16_t GetDstPanId (void) const;
110  Mac16Address GetShortDstAddr (void) const;
111  Mac64Address GetExtDstAddr (void) const;
112  uint16_t GetSrcPanId (void) const;
113  Mac16Address GetShortSrcAddr (void) const;
114  Mac64Address GetExtSrcAddr (void) const;
115 
116  uint8_t GetSecControl (void) const;
117  uint32_t GetFrmCounter (void) const;
118 
119  uint8_t GetSecLevel (void) const;
120  uint8_t GetKeyIdMode (void) const;
121  uint8_t GetsecctrlReserved (void) const;
122 
123  uint32_t GetKeyIdSrc32 (void) const;
124  uint64_t GetKeyIdSrc64 (void) const;
125  uint8_t GetKeyIdIndex (void) const;
126 
127 
128  bool IsBeacon (void) const;
129  bool IsData (void) const;
130  bool IsAcknowledgment (void) const;
131  bool IsCommand (void) const;
132 
133 
134  void SetType (enum LrWpanMacType wpanMacType);
135  void SetFrameControl (uint16_t frameControl);
136  void SetSecEnable (void);
137  void SetSecDisable (void);
138  void SetFrmPend (void);
139  void SetNoFrmPend (void);
140  void SetAckReq (void);
141  void SetNoAckReq (void);
142  void SetPanIdComp (void);
143  void SetNoPanIdComp (void);
144  void SetFrmCtrlRes (uint8_t res);
145  void SetDstAddrMode (uint8_t addrMode);
146  void SetFrameVer (uint8_t ver);
147  void SetSrcAddrMode (uint8_t addrMode);
148 
149  void SetSeqNum (uint8_t seqNum);
150 
151  /* The Source/Destination Addressing fields are only set if SrcAddrMode/DstAddrMode are set */
152  void SetSrcAddrFields (uint16_t panId,
153  Mac16Address addr);
154  void SetSrcAddrFields (uint16_t panId,
155  Mac64Address addr);
156  void SetDstAddrFields (uint16_t panId,
157  Mac16Address addr);
158  void SetDstAddrFields (uint16_t panId,
159  Mac64Address addr);
160 
161  /* Auxiliary Security Header is only set if Sec Enable (SecU) field is set to 1 */
162  void SetSecControl (uint8_t secLevel);
163  void SetFrmCounter (uint32_t frmCntr);
164 
165  void SetSecLevel (uint8_t secLevel);
166  void SetKeyIdMode (uint8_t keyIdMode);
167  void SetsecctrlReserved (uint8_t res);
168 
169  /* Variable length will be dependent on Key Id Mode*/
170  void SetKeyId (uint8_t keyIndex);
171  void SetKeyId (uint32_t keySrc,
172  uint8_t keyIndex);
173  void SetKeyId (uint64_t keySrc,
174  uint8_t keyIndex);
175 
176 
177  std::string GetName (void) const;
178  static TypeId GetTypeId (void);
179  virtual TypeId GetInstanceTypeId (void) const;
180  void PrintFrameControl (std::ostream &os) const;
181  void Print (std::ostream &os) const;
182  uint32_t GetSerializedSize (void) const;
183  void Serialize (Buffer::Iterator start) const;
185 
186 
187 private:
188  /* Frame Control 2 Octets */
189  /* Frame Control fields */
190  uint8_t m_fctrlFrmType; // Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 - Command
191  uint8_t m_fctrlSecU; // Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present
192  uint8_t m_fctrlFrmPending; // Bit 4
193  uint8_t m_fctrlAckReq; // Bit 5
194  uint8_t m_fctrlPanIdComp; // Bit 6 = 0 - no compression, 1 - using only DstPanId for both Src and DstPanId
195  uint8_t m_fctrlReserved; // Bit 7-9
196  uint8_t m_fctrlDstAddrMode; // Bit 10-11 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr
197  uint8_t m_fctrlFrmVer; // Bit 12-13
198  uint8_t m_fctrlSrcAddrMode; // Bit 14-15 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr
199 
200  /* Sequence Number */
201  uint8_t m_SeqNum; // 1 Octet
202 
203  /* Addressing fields */
204  uint16_t m_addrDstPanId; // 0 or 2 Octet
207  uint16_t m_addrSrcPanId; // 0 or 2 Octet
210 
211  /* Auxiliary Security Header // 0, 5, 6, 10 or 14 Octets */
212  // uint8_t m_auxSecCtrl; // 1 Octet see below
213  uint32_t m_auxFrmCntr; // 4 Octet
214 
215  /* Security Control fields */
216  uint8_t m_secctrlSecLevel; // Bit 0-2
217  uint8_t m_secctrlKeyIdMode; // Bit 3-4 will indicate size of Key Id
218  // = 0 - Key is determined implicitly
219  // from originator and receipient
220  // = 1 - 1 Octet Key Index
221  // = 2 - 1 octet Key Index and 4 oct Key src
222  // = 3 - 1 octet Key Index and 8 oct Key src
223 
224  uint8_t m_secctrlReserved; // Bit 5-7
225 
226  union
227  {
228  uint32_t m_auxKeyIdKeySrc32; // 4 octets
229  uint64_t m_auxKeyIdKeySrc64; // 8 octets
230  };
231 
232  uint8_t m_auxKeyIdKeyIndex; // 1 octet
233 
234 }; //LrWpanMacHeader
235 
236 }; // namespace ns-3
237 
238 #endif /* LR_WPAN_MAC_HEADER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
std::string GetName(void) const
bool IsPanIdComp(void) const
uint8_t GetKeyIdMode(void) const
void SetKeyId(uint8_t keyIndex)
uint32_t GetKeyIdSrc32(void) const
uint8_t GetSecLevel(void) const
Mac16Address m_addrShortDstAddr
void SetSeqNum(uint8_t seqNum)
Doxygen introspection did not find any typical Config paths.
bool IsBeacon(void) const
Mac16Address GetShortSrcAddr(void) const
void SetFrmCounter(uint32_t frmCntr)
bool IsNoAckReq(void) const
iterator in a Buffer instance
Definition: buffer.h:98
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
an EUI-64 address
Definition: mac64-address.h:41
bool IsData(void) const
void SetKeyIdMode(uint8_t keyIdMode)
uint8_t GetFrmCtrlRes(void) const
void Serialize(Buffer::Iterator start) const
void PrintFrameControl(std::ostream &os) const
uint8_t GetsecctrlReserved(void) const
uint16_t GetFrameControl(void) const
Mac64Address GetExtDstAddr(void) const
uint32_t GetSerializedSize(void) const
void SetFrameVer(uint8_t ver)
uint8_t GetSecControl(void) const
bool IsSecEnable(void) const
bool IsAckReq(void) const
void SetType(enum LrWpanMacType wpanMacType)
void SetFrmCtrlRes(uint8_t res)
uint8_t GetSrcAddrMode(void) const
Mac16Address m_addrShortSrcAddr
void SetDstAddrMode(uint8_t addrMode)
void Print(std::ostream &os) const
bool IsAcknowledgment(void) const
Mac16Address GetShortDstAddr(void) const
uint16_t GetSrcPanId(void) const
bool IsNoPanIdComp(void) const
uint64_t GetKeyIdSrc64(void) const
bool IsFrmPend(void) const
This class can contain 16 bit addresses.
Definition: mac16-address.h:39
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
void SetSecControl(uint8_t secLevel)
uint8_t GetFrameVer(void) const
virtual TypeId GetInstanceTypeId(void) const
Mac64Address GetExtSrcAddr(void) const
uint8_t GetKeyIdIndex(void) const
uint32_t Deserialize(Buffer::Iterator start)
uint32_t GetFrmCounter(void) const
void SetsecctrlReserved(uint8_t res)
void SetFrameControl(uint16_t frameControl)
bool IsCommand(void) const
void SetSrcAddrMode(uint8_t addrMode)
static TypeId GetTypeId(void)
uint8_t GetSeqNum(void) const
bool IsNoFrmPend(void) const
enum LrWpanMacType GetType(void) const
bool IsSecDisable(void) const
void SetSecLevel(uint8_t secLevel)
a unique identifier for an interface.
Definition: type-id.h:49
uint8_t GetDstAddrMode(void) const
uint16_t GetDstPanId(void) const