A Discrete-Event Network Simulator
API
lr-wpan-mac-header.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 The Boeing Company
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: kwong yin <kwong-sang.yin@boeing.com>
18  */
19 
20 /*
21  * the following classes implements the 802.15.4 Mac Header
22  * There are 4 types of 802.15.4 Mac Headers Frames, and they have these fields
23  *
24  * Headers Frames : Fields
25  * -------------------------------------------------------------------------------------------
26  * Beacon : Frame Control, Sequence Number, Address Fields+, Auxiliary Security
27  * Header++. Data : Frame Control, Sequence Number, Address Fields++, Auxiliary Security
28  * Header++. Acknowledgment : Frame Control, Sequence Number. Command : Frame Control,
29  * Sequence Number, Address Fields++, Auxiliary Security Header++.
30  *
31  * + - The Address fields in Beacon frame is made up of the Source PAN Id and address only and
32  * size is 4 or 8 octets whereas the other frames may contain the Destination PAN Id and address as
33  * well. (see specs).
34  * ++ - These fields are optional and of variable size
35  */
36 
37 #ifndef LR_WPAN_MAC_HEADER_H
38 #define LR_WPAN_MAC_HEADER_H
39 
40 #include <ns3/header.h>
41 #include <ns3/mac16-address.h>
42 #include <ns3/mac64-address.h>
43 
44 namespace ns3
45 {
46 
51 class LrWpanMacHeader : public Header
52 {
53  public:
58  {
64  };
65 
70  {
71  NOADDR = 0,
72  RESADDR = 1,
73  SHORTADDR = 2,
74  EXTADDR = 3
75  };
76 
81  {
82  IMPLICIT = 0,
85  LONGKEYSOURCE = 3
86  };
87 
89 
99  LrWpanMacHeader(LrWpanMacType wpanMacType, uint8_t seqNum);
100 
101  ~LrWpanMacHeader() override;
102 
107  LrWpanMacType GetType() const;
112  uint16_t GetFrameControl() const;
117  bool IsSecEnable() const;
122  bool IsFrmPend() const;
127  bool IsAckReq() const;
132  bool IsPanIdComp() const;
137  uint8_t GetFrmCtrlRes() const;
142  uint8_t GetDstAddrMode() const;
147  uint8_t GetFrameVer() const;
152  uint8_t GetSrcAddrMode() const;
157  uint8_t GetSeqNum() const;
162  uint16_t GetDstPanId() const;
172  Mac64Address GetExtDstAddr() const;
177  uint16_t GetSrcPanId() const;
187  Mac64Address GetExtSrcAddr() const;
192  uint8_t GetSecControl() const;
197  uint32_t GetFrmCounter() const;
198 
203  uint8_t GetSecLevel() const;
208  uint8_t GetKeyIdMode() const;
213  uint8_t GetSecCtrlReserved() const;
218  uint32_t GetKeyIdSrc32() const;
223  uint64_t GetKeyIdSrc64() const;
228  uint8_t GetKeyIdIndex() const;
233  bool IsBeacon() const;
238  bool IsData() const;
243  bool IsAcknowledgment() const;
248  bool IsCommand() const;
253  void SetType(LrWpanMacType wpanMacType);
258  void SetFrameControl(uint16_t frameControl);
262  void SetSecEnable();
266  void SetSecDisable();
270  void SetFrmPend();
274  void SetNoFrmPend();
278  void SetAckReq();
282  void SetNoAckReq();
286  void SetPanIdComp();
290  void SetNoPanIdComp();
295  void SetFrmCtrlRes(uint8_t res);
300  void SetDstAddrMode(uint8_t addrMode);
305  void SetFrameVer(uint8_t ver);
310  void SetSrcAddrMode(uint8_t addrMode);
315  void SetSeqNum(uint8_t seqNum);
316  /* The Source/Destination Addressing fields are only set if SrcAddrMode/DstAddrMode are set */
322  void SetSrcAddrFields(uint16_t panId, Mac16Address addr);
328  void SetSrcAddrFields(uint16_t panId, Mac64Address addr);
334  void SetDstAddrFields(uint16_t panId, Mac16Address addr);
340  void SetDstAddrFields(uint16_t panId, Mac64Address addr);
341 
342  /* Auxiliary Security Header is only set if Sec Enable (SecU) field is set to 1 */
347  void SetSecControl(uint8_t secLevel);
352  void SetFrmCounter(uint32_t frmCntr);
357  void SetSecLevel(uint8_t secLevel);
362  void SetKeyIdMode(uint8_t keyIdMode);
367  void SetSecCtrlReserved(uint8_t res);
368  /* Variable length will be dependent on Key Id Mode*/
373  void SetKeyId(uint8_t keyIndex);
379  void SetKeyId(uint32_t keySrc, uint8_t keyIndex);
385  void SetKeyId(uint64_t keySrc, uint8_t keyIndex);
390  static TypeId GetTypeId();
391  TypeId GetInstanceTypeId() const override;
392 
393  void Print(std::ostream& os) const override;
394  uint32_t GetSerializedSize() const override;
395  void Serialize(Buffer::Iterator start) const override;
396  uint32_t Deserialize(Buffer::Iterator start) override;
397 
398  private:
399  /* Frame Control 2 Octets */
400  /* Frame Control field - see 7.2.1.1 */
401  uint8_t m_fctrlFrmType;
403  uint8_t m_fctrlSecU;
406  uint8_t m_fctrlAckReq;
409  uint8_t m_fctrlReserved;
412  uint8_t m_fctrlFrmVer;
415 
416  /* Sequence Number */
417  uint8_t m_SeqNum;
418 
419  /* Addressing fields */
420  uint16_t m_addrDstPanId;
423  uint16_t m_addrSrcPanId;
426 
427  /* Auxiliary Security Header - See 7.6.2 - 0, 5, 6, 10 or 14 Octets */
428  // uint8_t m_auxSecCtrl; // 1 Octet see below
429  uint32_t m_auxFrmCntr;
430 
431  /* Security Control fields - See 7.6.2.2 */
435  // = 0 - Key is determined implicitly
436  // from originator and recipient
437  // = 1 - 1 Octet Key Index
438  // = 2 - 1 Octet Key Index and 4 oct Key src
439  // = 3 - 1 Octet Key Index and 8 oct Key src
440 
442 
443  union {
446  };
447 
449 
450 }; // LrWpanMacHeader
451 
452 }; // namespace ns3
453 
454 #endif /* LR_WPAN_MAC_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Represent the Mac Header with the Frame Control and Sequence Number fields.
uint8_t m_secctrlSecLevel
Auxiliary security header - Security Control field - Bit 0-2.
uint8_t m_fctrlDstAddrMode
Frame Control field Bit 10-11 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr.
uint32_t m_auxFrmCntr
Auxiliary security header - Frame Counter (4 Octets)
uint8_t GetSecControl() const
Get the Auxiliary Security Header - Security Control Octet.
Mac16Address GetShortSrcAddr() const
Get the Source Short address.
LrWpanMacType
The possible MAC types, see IEEE 802.15.4-2006, Table 79.
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
@ LRWPAN_MAC_COMMAND
LRWPAN_MAC_COMMAND.
@ LRWPAN_MAC_DATA
LRWPAN_MAC_DATA.
@ LRWPAN_MAC_ACKNOWLEDGMENT
LRWPAN_MAC_ACKNOWLEDGMENT.
@ LRWPAN_MAC_RESERVED
LRWPAN_MAC_RESERVED.
static TypeId GetTypeId()
Get the type ID.
bool IsCommand() const
Returns true if the header is a command.
uint8_t m_fctrlReserved
Frame Control field Bit 7-9.
uint8_t m_SeqNum
Sequence Number (1 Octet)
void SetSecEnable()
Set the Frame Control field "Security Enabled" bit to true.
uint32_t m_auxKeyIdKeySrc32
Auxiliary security header - Key Source (4 Octets)
bool IsBeacon() const
Returns true if the header is a beacon.
void SetKeyIdMode(uint8_t keyIdMode)
Set the Security Control field "Key Identifier Mode" bits (2 bits)
Mac16Address m_addrShortSrcAddr
Src Short addr (0 or 2 Octets)
Mac64Address GetExtSrcAddr() const
Get the Source Extended address.
uint8_t m_secctrlReserved
Auxiliary security header - Security Control field - Bit 5-7.
void SetType(LrWpanMacType wpanMacType)
Set the Frame Control field "Frame Type" bits.
void SetFrmCtrlRes(uint8_t res)
Set the Frame Control field "Reserved" bits.
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
uint8_t GetKeyIdIndex() const
Get the Auxiliary Security Header - Key Identifier - Key Index.
void SetSeqNum(uint8_t seqNum)
Set the Sequence number.
uint8_t GetSrcAddrMode() const
Get the Source Addressing Mode of Frame control field.
bool IsPanIdComp() const
Check if PAN ID Compression bit of Frame Control is enabled.
void SetPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to true.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
void SetFrmPend()
Set the Frame Control field "Frame Pending" bit to true.
uint32_t GetFrmCounter() const
Get the Auxiliary Security Header - Frame Counter Octets.
uint8_t GetFrmCtrlRes() const
Get the Reserved bits of Frame control field.
uint8_t m_fctrlAckReq
Frame Control field Bit 5.
uint8_t m_fctrlPanIdComp
Frame Control field Bit 6 = 0 - no compression, 1 - using only DstPanId for both Src and DstPanId.
uint8_t GetDstAddrMode() const
Get the Dest.
void SetNoFrmPend()
Set the Frame Control field "Frame Pending" bit to false.
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
uint16_t GetFrameControl() const
Get the Frame control field.
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
void Print(std::ostream &os) const override
uint64_t GetKeyIdSrc64() const
Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octets)
bool IsFrmPend() const
Check if Frame Pending bit of Frame Control is enabled.
uint32_t GetSerializedSize() const override
bool IsAcknowledgment() const
Returns true if the header is an ack.
bool IsData() const
Returns true if the header is a data.
uint8_t m_fctrlSrcAddrMode
Frame Control field Bit 14-15 = 0 - No SrcAddr, 2 - ShtSrcAddr, 3 - ExtSrcAddr.
uint8_t m_fctrlFrmType
Frame Control field Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 - Command.
uint8_t GetKeyIdMode() const
Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits.
uint32_t GetKeyIdSrc32() const
Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octets)
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
uint8_t GetSeqNum() const
Get the frame Sequence number.
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
void SetFrmCounter(uint32_t frmCntr)
Set the auxiliary security header "Frame Counter" octet.
uint8_t m_secctrlKeyIdMode
Auxiliary security header - Security Control field - Bit 3-4 will indicate size of Key Id.
void SetNoAckReq()
Set the Frame Control field "Ack. Request" bit to false.
uint64_t m_auxKeyIdKeySrc64
Auxiliary security header - Key Source (8 Octets)
AddrModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
Mac64Address GetExtDstAddr() const
Get the Destination Extended address.
bool IsSecEnable() const
Check if Security Enabled bit of Frame Control is enabled.
uint8_t m_fctrlFrmPending
Frame Control field Bit 4.
void Serialize(Buffer::Iterator start) const override
void SetFrameControl(uint16_t frameControl)
Set the whole Frame Control field.
void SetSecCtrlReserved(uint8_t res)
Set the Security Control field "Reserved" bits (3 bits)
uint8_t GetSecLevel() const
Get the Auxiliary Security Header - Security Control - Security Level bits.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetSecLevel(uint8_t secLevel)
Set the Security Control field "Security Level" bits (3 bits)
uint8_t GetSecCtrlReserved() const
Get the Auxiliary Security Header - Security Control - Reserved bits.
LrWpanMacType GetType() const
Get the header type.
uint16_t GetDstPanId() const
Get the Destination PAN ID.
uint8_t GetFrameVer() const
Get the Frame Version of Frame control field.
void SetKeyId(uint8_t keyIndex)
Set the Key Index.
Mac64Address m_addrExtSrcAddr
Src Ext addr (0 or 8 Octets)
Mac64Address m_addrExtDstAddr
Dst Ext addr (0 or 8 Octets)
uint16_t m_addrDstPanId
Dst PAN id (0 or 2 Octets)
void SetFrameVer(uint8_t ver)
Set the Frame version.
Mac16Address m_addrShortDstAddr
Dst Short addr (0 or 2 Octets)
uint16_t GetSrcPanId() const
Get the Source PAN ID.
uint16_t m_addrSrcPanId
Src PAN id (0 or 2 Octets)
uint8_t m_fctrlFrmVer
Frame Control field Bit 12-13.
KeyIdModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
uint8_t m_auxKeyIdKeyIndex
Auxiliary security header - Key Index (1 Octet)
bool IsAckReq() const
Check if Ack.
uint8_t m_fctrlSecU
Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present.
void SetSecControl(uint8_t secLevel)
Set the auxiliary security header "Security Control" octet.
Mac16Address GetShortDstAddr() const
Get the Destination Short address.
void SetAckReq()
Set the Frame Control field "Ack. Request" bit to true.
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
an EUI-64 address
Definition: mac64-address.h:46
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.