A Discrete-Event Network Simulator
API
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 
21 /*
22  * the following classes implements the 802.15.4 Mac Header
23  * There are 4 types of 802.15.4 Mac Headers Frames, and they have these fields
24  *
25  * Headers Frames : Fields
26  * -------------------------------------------------------------------------------------------
27  * Beacon : Frame Control, Sequence Number, Address Fields+, Auxiliary Security Header++.
28  * Data : Frame Control, Sequence Number, Address Fields++, Auxiliary Security Header++.
29  * Acknowledgment : Frame Control, Sequence Number.
30  * Command : Frame Control, Sequence Number, Address Fields++, Auxiliary Security Header++.
31  *
32  * + - The Address fields in Beacon frame is made up of the Source PAN Id and address only and size
33  * is 4 or 8 octets whereas the other frames may contain the Destination PAN Id and address as
34  * well. (see specs).
35  * ++ - These fields are optional and of variable size
36  */
37 
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 
53 class LrWpanMacHeader : public Header
54 {
55 
56 public:
57 
62  {
68  };
69 
74  {
75  NOADDR = 0,
76  RESADDR = 1,
77  SHORTADDR = 2,
78  EXTADDR = 3
79  };
80 
85  {
86  IMPLICIT = 0,
90  };
91 
92  LrWpanMacHeader (void);
93 
99  LrWpanMacHeader (enum LrWpanMacType wpanMacType, // Data, ACK, Control MAC Header must have
100  uint8_t seqNum); // frame control and sequence number.
101  // Beacon MAC Header must have frame control,
102  // sequence number, source PAN Id, source address.
103 
104  ~LrWpanMacHeader (void);
105 
110  enum LrWpanMacType GetType (void) const;
115  uint16_t GetFrameControl (void) const;
116 
121  bool IsSecEnable (void) const;
122 
127  bool IsFrmPend (void) const;
128 
133  bool IsAckReq (void) const;
134 
139  bool IsPanIdComp (void) const;
140 
145  uint8_t GetFrmCtrlRes (void) const;
146 
151  uint8_t GetDstAddrMode (void) const;
156  uint8_t GetFrameVer (void) const;
161  uint8_t GetSrcAddrMode (void) const;
162 
167  uint8_t GetSeqNum (void) const;
168 
173  uint16_t GetDstPanId (void) const;
178  Mac16Address GetShortDstAddr (void) const;
183  Mac64Address GetExtDstAddr (void) const;
188  uint16_t GetSrcPanId (void) const;
193  Mac16Address GetShortSrcAddr (void) const;
198  Mac64Address GetExtSrcAddr (void) const;
199 
204  uint8_t GetSecControl (void) const;
209  uint32_t GetFrmCounter (void) const;
210 
215  uint8_t GetSecLevel (void) const;
220  uint8_t GetKeyIdMode (void) const;
225  uint8_t GetSecCtrlReserved (void) const;
226 
231  uint32_t GetKeyIdSrc32 (void) const;
236  uint64_t GetKeyIdSrc64 (void) const;
241  uint8_t GetKeyIdIndex (void) const;
242 
247  bool IsBeacon (void) const;
252  bool IsData (void) const;
257  bool IsAcknowledgment (void) const;
262  bool IsCommand (void) const;
263 
268  void SetType (enum LrWpanMacType wpanMacType);
269 
274  void SetFrameControl (uint16_t frameControl);
275 
279  void SetSecEnable (void);
280 
284  void SetSecDisable (void);
285 
289  void SetFrmPend (void);
290 
294  void SetNoFrmPend (void);
295 
299  void SetAckReq (void);
300 
304  void SetNoAckReq (void);
305 
309  void SetPanIdComp (void);
310 
314  void SetNoPanIdComp (void);
315 
320  void SetFrmCtrlRes (uint8_t res);
325  void SetDstAddrMode (uint8_t addrMode);
330  void SetFrameVer (uint8_t ver);
335  void SetSrcAddrMode (uint8_t addrMode);
336 
341  void SetSeqNum (uint8_t seqNum);
342 
343  /* The Source/Destination Addressing fields are only set if SrcAddrMode/DstAddrMode are set */
349  void SetSrcAddrFields (uint16_t panId, Mac16Address addr);
355  void SetSrcAddrFields (uint16_t panId, Mac64Address addr);
361  void SetDstAddrFields (uint16_t panId, Mac16Address addr);
367  void SetDstAddrFields (uint16_t panId, Mac64Address addr);
368 
369  /* Auxiliary Security Header is only set if Sec Enable (SecU) field is set to 1 */
374  void SetSecControl (uint8_t secLevel);
379  void SetFrmCounter (uint32_t frmCntr);
380 
385  void SetSecLevel (uint8_t secLevel);
390  void SetKeyIdMode (uint8_t keyIdMode);
391 
396  void SetSecCtrlReserved (uint8_t res);
397 
398  /* Variable length will be dependent on Key Id Mode*/
403  void SetKeyId (uint8_t keyIndex);
409  void SetKeyId (uint32_t keySrc, uint8_t keyIndex);
415  void SetKeyId (uint64_t keySrc, uint8_t keyIndex);
416 
421  static TypeId GetTypeId (void);
422  virtual TypeId GetInstanceTypeId (void) const;
423 
424  void Print (std::ostream &os) const;
425  uint32_t GetSerializedSize (void) const;
426  void Serialize (Buffer::Iterator start) const;
428 
429 
430 private:
431  /* Frame Control 2 Octets */
432  /* Frame Control field - see 7.2.1.1 */
433  uint8_t m_fctrlFrmType;
434  uint8_t m_fctrlSecU;
436  uint8_t m_fctrlAckReq;
438  uint8_t m_fctrlReserved;
440  uint8_t m_fctrlFrmVer;
442 
443  /* Sequence Number */
444  uint8_t m_SeqNum;
445 
446  /* Addressing fields */
447  uint16_t m_addrDstPanId;
450  uint16_t m_addrSrcPanId;
453 
454  /* Auxiliary Security Header - See 7.6.2 - 0, 5, 6, 10 or 14 Octets */
455  // uint8_t m_auxSecCtrl; // 1 Octet see below
456  uint32_t m_auxFrmCntr;
457 
458  /* Security Control fields - See 7.6.2.2 */
461  // = 0 - Key is determined implicitly
462  // from originator and recipient
463  // = 1 - 1 Octet Key Index
464  // = 2 - 1 Octet Key Index and 4 oct Key src
465  // = 3 - 1 Octet Key Index and 8 oct Key src
466 
468 
469  union
470  {
473  };
474 
476 
477 }; //LrWpanMacHeader
478 
479 }; // namespace ns-3
480 
481 #endif /* LR_WPAN_MAC_HEADER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
void SetNoFrmPend(void)
Set the Frame Control field "Frame Pending" bit to false.
uint32_t GetFrmCounter(void) const
Get the Auxiliary Security Header - Frame Counter Octects.
uint8_t GetSeqNum(void) const
Get the frame Sequence number.
void SetSecDisable(void)
Set the Frame Control field "Security Enabled" bit to false.
uint8_t m_fctrlDstAddrMode
Frame Control field Bit 10-11 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr.
uint8_t m_fctrlSecU
Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present.
Mac16Address GetShortDstAddr(void) const
Get the Destination Short address.
Mac16Address GetShortSrcAddr(void) const
Get the Source Short address.
uint32_t GetSerializedSize(void) const
void SetKeyId(uint8_t keyIndex)
Set the Key Index.
uint16_t GetFrameControl(void) const
Get the Frame control field.
def start()
Definition: core.py:1844
bool IsData(void) const
Returns true if the header is a data.
void SetNoPanIdComp(void)
Set the Frame Control field "PAN ID Compression" bit to false.
KeyIdModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
void SetNoAckReq(void)
Set the Frame Control field "Ack. Request" bit to false.
uint8_t m_secctrlReserved
Auxiliary security header - Security Control field - Bit 5-7.
uint8_t m_secctrlKeyIdMode
Auxiliary security header - Security Control field - Bit 3-4 will indicate size of Key Id...
Mac16Address m_addrShortDstAddr
Dst Short addr (0 or 2 Octets)
AddrModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
void SetSeqNum(uint8_t seqNum)
Set the Sequence number.
Represent the Mac Header with the Frame Control and Sequence Number fields.
bool IsCommand(void) const
Returns true if the header is a command.
uint64_t GetKeyIdSrc64(void) const
Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octects)
uint16_t GetDstPanId(void) const
Get the Destination PAN ID.
uint16_t m_addrDstPanId
Dst PAN id (0 or 2 Octets)
uint8_t m_fctrlFrmPending
Frame Control field Bit 4.
LrWpanMacType
The possible MAC types, see IEEE 802.15.4-2006, Table 79.
uint16_t m_addrSrcPanId
Src PAN id (0 or 2 Octets)
void SetAckReq(void)
Set the Frame Control field "Ack. Request" bit to true.
void SetFrmCounter(uint32_t frmCntr)
Set the auxiliary security header "Frame Counter" octet.
uint8_t GetFrameVer(void) const
Get the Frame Version of Frame control field.
iterator in a Buffer instance
Definition: buffer.h:98
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
an EUI-64 address
Definition: mac64-address.h:43
void SetKeyIdMode(uint8_t keyIdMode)
Set the Security Control field "Key Identifier Mode" bits (2 bits)
bool IsPanIdComp(void) const
Check if PAN ID Compression bit of Frame Control is enabled.
bool IsFrmPend(void) const
Check if Frame Pending bit of Frame Control is enabled.
uint32_t m_auxKeyIdKeySrc32
Auxiliary security header - Key Source (4 Octets)
void SetSecCtrlReserved(uint8_t res)
Set the Security Control field "Reserved" bits (3 bits)
void SetSecEnable(void)
Set the Frame Control field "Security Enabled" bit to true.
uint8_t GetDstAddrMode(void) const
Get the Dest.
uint64_t m_auxKeyIdKeySrc64
Auxiliary security header - Key Source (8 Octets)
enum LrWpanMacType GetType(void) const
Get the header type.
Mac64Address m_addrExtDstAddr
Dst Ext addr (0 or 8 Octets)
void SetFrameVer(uint8_t ver)
Set the Frame version.
uint8_t m_SeqNum
Sequence Number (1 Octet)
bool IsAcknowledgment(void) const
Returns true if the header is an ack.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint8_t GetSecLevel(void) const
Get the Auxiliary Security Header - Security Control - Security Level bits.
uint8_t GetKeyIdMode(void) const
Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits.
void SetType(enum LrWpanMacType wpanMacType)
Set the Frame Control field "Frame Type" bits.
Mac64Address GetExtSrcAddr(void) const
Get the Source Extended address.
void SetFrmCtrlRes(uint8_t res)
Set the Frame Control field "Reserved" bits.
void SetPanIdComp(void)
Set the Frame Control field "PAN ID Compression" bit to true.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetSrcAddrMode(void) const
Get the Source Addressing Mode of Frame control field.
uint8_t m_auxKeyIdKeyIndex
Auxiliary security header - Key Index (1 Octet)
Mac16Address m_addrShortSrcAddr
Src Short addr (0 or 2 Octets)
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
uint8_t m_fctrlPanIdComp
Frame Control field Bit 6 = 0 - no compression, 1 - using only DstPanId for both Src and DstPanId...
bool IsAckReq(void) const
Check if Ack.
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
Mac64Address m_addrExtSrcAddr
Src Ext addr (0 or 8 Octets)
uint32_t GetKeyIdSrc32(void) const
Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octects)
uint8_t m_secctrlSecLevel
Auxiliary security header - Security Control field - Bit 0-2.
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
uint16_t GetSrcPanId(void) const
Get the Source PAN ID.
void SetSecControl(uint8_t secLevel)
Set the auxiliary security header "Security Control" octet.
bool IsBeacon(void) const
Returns true if the header is a beacon.
bool IsSecEnable(void) const
Check if Security Enabled bit of Frame Control is enabled.
uint32_t Deserialize(Buffer::Iterator start)
void SetFrmPend(void)
Set the Frame Control field "Frame Pending" bit to true.
uint8_t GetSecControl(void) const
Get the Auxiliary Security Header - Security Control Octect.
void SetFrameControl(uint16_t frameControl)
Set the whole Frame Control field.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
void Print(std::ostream &os) const
static TypeId GetTypeId(void)
Get the type ID.
uint8_t m_fctrlReserved
Frame Control field Bit 7-9.
uint32_t m_auxFrmCntr
Auxiliary security header - Frame Counter (4 Octets)
uint8_t m_fctrlSrcAddrMode
Frame Control field Bit 14-15 = 0 - No SrcAddr, 2 - ShtSrcAddr, 3 - ExtSrcAddr.
uint8_t m_fctrlFrmVer
Frame Control field Bit 12-13.
uint8_t m_fctrlAckReq
Frame Control field Bit 5.
void Serialize(Buffer::Iterator start) const
uint8_t GetKeyIdIndex(void) const
Get the Auxiliary Security Header - Key Identifier - Key Index.
uint8_t m_fctrlFrmType
Frame Control field Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 - Command.
void SetSecLevel(uint8_t secLevel)
Set the Security Control field "Security Level" bits (3 bits)
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t GetFrmCtrlRes(void) const
Get the Reserved bits of Frame control field.
uint8_t GetSecCtrlReserved(void) const
Get the Auxiliary Security Header - Security Control - Reserved bits.
Mac64Address GetExtDstAddr(void) const
Get the Destination Extended address.