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
46namespace ns3 {
47
48
53class LrWpanMacHeader : public Header
54{
55
56public:
61 {
67 };
68
73 {
74 NOADDR = 0,
77 EXTADDR = 3
78 };
79
84 {
89 };
90
91 LrWpanMacHeader (void);
92
98 LrWpanMacHeader (enum LrWpanMacType wpanMacType, // Data, ACK, Control MAC Header must have
99 uint8_t seqNum); // frame control and sequence number.
100 // Beacon MAC Header must have frame control,
101 // sequence number, source PAN Id, source address.
102
103 ~LrWpanMacHeader (void);
104
109 enum LrWpanMacType GetType (void) const;
114 uint16_t GetFrameControl (void) const;
119 bool IsSecEnable (void) const;
124 bool IsFrmPend (void) const;
129 bool IsAckReq (void) const;
134 bool IsPanIdComp (void) const;
139 uint8_t GetFrmCtrlRes (void) const;
144 uint8_t GetDstAddrMode (void) const;
149 uint8_t GetFrameVer (void) const;
154 uint8_t GetSrcAddrMode (void) const;
159 uint8_t GetSeqNum (void) const;
164 uint16_t GetDstPanId (void) const;
169 Mac16Address GetShortDstAddr (void) const;
174 Mac64Address GetExtDstAddr (void) const;
179 uint16_t GetSrcPanId (void) const;
184 Mac16Address GetShortSrcAddr (void) const;
189 Mac64Address GetExtSrcAddr (void) const;
194 uint8_t GetSecControl (void) const;
199 uint32_t GetFrmCounter (void) const;
200
205 uint8_t GetSecLevel (void) const;
210 uint8_t GetKeyIdMode (void) const;
215 uint8_t GetSecCtrlReserved (void) const;
220 uint32_t GetKeyIdSrc32 (void) const;
225 uint64_t GetKeyIdSrc64 (void) const;
230 uint8_t GetKeyIdIndex (void) const;
235 bool IsBeacon (void) const;
240 bool IsData (void) const;
245 bool IsAcknowledgment (void) const;
250 bool IsCommand (void) const;
255 void SetType (enum LrWpanMacType wpanMacType);
260 void SetFrameControl (uint16_t frameControl);
264 void SetSecEnable (void);
268 void SetSecDisable (void);
272 void SetFrmPend (void);
276 void SetNoFrmPend (void);
280 void SetAckReq (void);
284 void SetNoAckReq (void);
288 void SetPanIdComp (void);
292 void SetNoPanIdComp (void);
297 void SetFrmCtrlRes (uint8_t res);
302 void SetDstAddrMode (uint8_t addrMode);
307 void SetFrameVer (uint8_t ver);
312 void SetSrcAddrMode (uint8_t addrMode);
317 void SetSeqNum (uint8_t seqNum);
318 /* The Source/Destination Addressing fields are only set if SrcAddrMode/DstAddrMode are set */
324 void SetSrcAddrFields (uint16_t panId, Mac16Address addr);
330 void SetSrcAddrFields (uint16_t panId, Mac64Address addr);
336 void SetDstAddrFields (uint16_t panId, Mac16Address addr);
342 void SetDstAddrFields (uint16_t panId, Mac64Address addr);
343
344 /* Auxiliary Security Header is only set if Sec Enable (SecU) field is set to 1 */
349 void SetSecControl (uint8_t secLevel);
354 void SetFrmCounter (uint32_t frmCntr);
359 void SetSecLevel (uint8_t secLevel);
364 void SetKeyIdMode (uint8_t keyIdMode);
369 void SetSecCtrlReserved (uint8_t res);
370 /* Variable length will be dependent on Key Id Mode*/
375 void SetKeyId (uint8_t keyIndex);
381 void SetKeyId (uint32_t keySrc, uint8_t keyIndex);
387 void SetKeyId (uint64_t keySrc, uint8_t keyIndex);
392 static TypeId GetTypeId (void);
393 virtual TypeId GetInstanceTypeId (void) const;
394
395 void Print (std::ostream &os) const;
396 uint32_t GetSerializedSize (void) const;
397 void Serialize (Buffer::Iterator start) const;
399
400
401private:
402 /* Frame Control 2 Octets */
403 /* Frame Control field - see 7.2.1.1 */
405 uint8_t m_fctrlSecU;
413
414 /* Sequence Number */
415 uint8_t m_SeqNum;
416
417 /* Addressing fields */
418 uint16_t m_addrDstPanId;
421 uint16_t m_addrSrcPanId;
424
425 /* Auxiliary Security Header - See 7.6.2 - 0, 5, 6, 10 or 14 Octets */
426 // uint8_t m_auxSecCtrl; // 1 Octet see below
428
429 /* Security Control fields - See 7.6.2.2 */
432 // = 0 - Key is determined implicitly
433 // from originator and recipient
434 // = 1 - 1 Octet Key Index
435 // = 2 - 1 Octet Key Index and 4 oct Key src
436 // = 3 - 1 Octet Key Index and 8 oct Key src
437
439
440 union
441 {
444 };
445
447
448}; //LrWpanMacHeader
449
450}; // namespace ns-3
451
452#endif /* LR_WPAN_MAC_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
Represent the Mac Header with the Frame Control and Sequence Number fields.
void SetNoAckReq(void)
Set the Frame Control field "Ack. Request" bit to false.
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)
void Print(std::ostream &os) const
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.
void SetSecEnable(void)
Set the Frame Control field "Security Enabled" bit to true.
uint8_t m_fctrlReserved
Frame Control field Bit 7-9.
uint8_t m_SeqNum
Sequence Number (1 Octet)
uint32_t m_auxKeyIdKeySrc32
Auxiliary security header - Key Source (4 Octets)
Mac64Address GetExtSrcAddr(void) const
Get the Source Extended address.
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)
uint8_t m_secctrlReserved
Auxiliary security header - Security Control field - Bit 5-7.
void SetFrmCtrlRes(uint8_t res)
Set the Frame Control field "Reserved" bits.
void SetFrmPend(void)
Set the Frame Control field "Frame Pending" bit to true.
void SetAckReq(void)
Set the Frame Control field "Ack. Request" bit to true.
void SetSeqNum(uint8_t seqNum)
Set the Sequence number.
void SetPanIdComp(void)
Set the Frame Control field "PAN ID Compression" bit to true.
uint8_t GetSrcAddrMode(void) const
Get the Source Addressing Mode of Frame control field.
bool IsBeacon(void) const
Returns true if the header is a beacon.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
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.
bool IsFrmPend(void) const
Check if Frame Pending bit of Frame Control is enabled.
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Mac64Address GetExtDstAddr(void) const
Get the Destination Extended address.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetSeqNum(void) const
Get the frame Sequence number.
void SetType(enum LrWpanMacType wpanMacType)
Set the Frame Control field "Frame Type" bits.
uint16_t GetDstPanId(void) const
Get the Destination PAN ID.
enum LrWpanMacType GetType(void) const
Get the header type.
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(void) const
Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits.
uint8_t GetSecLevel(void) const
Get the Auxiliary Security Header - Security Control - Security Level bits.
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
uint32_t GetFrmCounter(void) const
Get the Auxiliary Security Header - Frame Counter Octects.
Mac16Address GetShortSrcAddr(void) const
Get the Source Short address.
void SetFrmCounter(uint32_t frmCntr)
Set the auxiliary security header "Frame Counter" octet.
bool IsData(void) const
Returns true if the header is a data.
uint8_t m_secctrlKeyIdMode
Auxiliary security header - Security Control field - Bit 3-4 will indicate size of Key Id.
uint64_t m_auxKeyIdKeySrc64
Auxiliary security header - Key Source (8 Octets)
AddrModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
uint32_t GetSerializedSize(void) const
void Serialize(Buffer::Iterator start) const
uint8_t GetSecControl(void) const
Get the Auxiliary Security Header - Security Control Octect.
uint8_t GetFrmCtrlRes(void) const
Get the Reserved bits of Frame control field.
bool IsSecEnable(void) const
Check if Security Enabled bit of Frame Control is enabled.
uint8_t m_fctrlFrmPending
Frame Control field Bit 4.
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)
uint32_t Deserialize(Buffer::Iterator start)
uint8_t GetFrameVer(void) const
Get the Frame Version of Frame control field.
Mac16Address GetShortDstAddr(void) const
Get the Destination Short address.
bool IsCommand(void) const
Returns true if the header is a command.
void SetNoPanIdComp(void)
Set the Frame Control field "PAN ID Compression" bit to false.
void SetSecLevel(uint8_t secLevel)
Set the Security Control field "Security Level" bits (3 bits)
bool IsAckReq(void) const
Check if Ack.
uint16_t GetFrameControl(void) const
Get the Frame control field.
void SetKeyId(uint8_t keyIndex)
Set the Key Index.
void SetSecDisable(void)
Set the Frame Control field "Security Enabled" bit to false.
uint8_t GetSecCtrlReserved(void) const
Get the Auxiliary Security Header - Security Control - Reserved bits.
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 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 IsAcknowledgment(void) const
Returns true if the header is an ack.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint64_t GetKeyIdSrc64(void) const
Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octects)
uint16_t GetSrcPanId(void) const
Get the Source PAN ID.
bool IsPanIdComp(void) const
Check if PAN ID Compression bit of Frame Control is enabled.
uint8_t GetDstAddrMode(void) const
Get the Dest.
uint8_t m_fctrlSecU
Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present.
uint8_t GetKeyIdIndex(void) const
Get the Auxiliary Security Header - Key Identifier - Key Index.
uint32_t GetKeyIdSrc32(void) const
Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octects)
void SetSecControl(uint8_t secLevel)
Set the auxiliary security header "Security Control" octet.
void SetNoFrmPend(void)
Set the Frame Control field "Frame Pending" bit to false.
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
an EUI-64 address
Definition: mac64-address.h:44
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852