A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-mac-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: kwong yin <kwong-sang.yin@boeing.com>
7 */
8
9/*
10 * the following classes implements the 802.15.4 Mac Header
11 * There are 4 types of 802.15.4 Mac Headers Frames, and they have these fields
12 *
13 * Headers Frames : Fields
14 * -------------------------------------------------------------------------------------------
15 * Beacon : Frame Control, Sequence Number, Address Fields+, Auxiliary Security
16 * Header++. Data : Frame Control, Sequence Number, Address Fields++, Auxiliary Security
17 * Header++. Acknowledgment : Frame Control, Sequence Number. Command : Frame Control,
18 * Sequence Number, Address Fields++, Auxiliary Security Header++.
19 *
20 * + - The Address fields in Beacon frame is made up of the Source PAN Id and address only and
21 * size is 4 or 8 octets whereas the other frames may contain the Destination PAN Id and address as
22 * well. (see specs).
23 * ++ - These fields are optional and of variable size
24 */
25
26#ifndef LR_WPAN_MAC_HEADER_H
27#define LR_WPAN_MAC_HEADER_H
28
29#include <ns3/header.h>
30#include <ns3/mac16-address.h>
31#include <ns3/mac64-address.h>
32
33namespace ns3
34{
35namespace lrwpan
36{
37
38/**
39 * \ingroup lr-wpan
40 * Represent the Mac Header with the Frame Control and Sequence Number fields
41 */
42class LrWpanMacHeader : public Header
43{
44 public:
45 /**
46 * The possible MAC types, see IEEE 802.15.4-2006, Table 79.
47 */
49 {
50 LRWPAN_MAC_BEACON = 0, //!< LRWPAN_MAC_BEACON
51 LRWPAN_MAC_DATA = 1, //!< LRWPAN_MAC_DATA
52 LRWPAN_MAC_ACKNOWLEDGMENT = 2, //!< LRWPAN_MAC_ACKNOWLEDGMENT
53 LRWPAN_MAC_COMMAND = 3, //!< LRWPAN_MAC_COMMAND
54 LRWPAN_MAC_RESERVED //!< LRWPAN_MAC_RESERVED
55 };
56
57 /**
58 * The addressing mode types, see IEEE 802.15.4-2006, Table 80.
59 */
61 {
62 NOADDR = 0,
65 EXTADDR = 3
66 };
67
68 /**
69 * The addressing mode types, see IEEE 802.15.4-2006, Table 80.
70 */
78
80
81 /**
82 * Constructor
83 * \param wpanMacType the header MAC type
84 * \param seqNum the sequence number
85 *
86 * \internal
87 * Data, ACK, Control MAC Header must have frame control and sequence number.
88 * Beacon MAC Header must have frame control, sequence number, source PAN Id, source address.
89 */
90 LrWpanMacHeader(LrWpanMacType wpanMacType, uint8_t seqNum);
91
92 ~LrWpanMacHeader() override;
93
94 /**
95 * Get the header type
96 * \return the header type
97 */
98 LrWpanMacType GetType() const;
99 /**
100 * Get the Frame control field
101 * \return the Frame control field
102 */
103 uint16_t GetFrameControl() const;
104 /**
105 * Check if Security Enabled bit of Frame Control is enabled
106 * \return true if Security Enabled bit is enabled
107 */
108 bool IsSecEnable() const;
109 /**
110 * Check if Frame Pending bit of Frame Control is enabled
111 * \return true if Frame Pending bit is enabled
112 */
113 bool IsFrmPend() const;
114 /**
115 * Check if Ack. Request bit of Frame Control is enabled
116 * \return true if Ack. Request bit is enabled
117 */
118 bool IsAckReq() const;
119 /**
120 * Check if PAN ID Compression bit of Frame Control is enabled
121 * \return true if PAN ID Compression bit is enabled
122 */
123 bool IsPanIdComp() const;
124 /**
125 * Get the Reserved bits of Frame control field
126 * \return the Reserved bits
127 */
128 uint8_t GetFrmCtrlRes() const;
129 /**
130 * Get the Dest. Addressing Mode of Frame control field
131 * \return the Dest. Addressing Mode bits
132 */
133 uint8_t GetDstAddrMode() const;
134 /**
135 * Get the Frame Version of Frame control field
136 * \return the Frame Version bits
137 */
138 uint8_t GetFrameVer() const;
139 /**
140 * Get the Source Addressing Mode of Frame control field
141 * \return the Source Addressing Mode bits
142 */
143 uint8_t GetSrcAddrMode() const;
144 /**
145 * Get the frame Sequence number
146 * \return the sequence number
147 */
148 uint8_t GetSeqNum() const;
149 /**
150 * Get the Destination PAN ID
151 * \return the Destination PAN ID
152 */
153 uint16_t GetDstPanId() const;
154 /**
155 * Get the Destination Short address
156 * \return the Destination Short address
157 */
159 /**
160 * Get the Destination Extended address
161 * \return the Destination Extended address
162 */
164 /**
165 * Get the Source PAN ID
166 * \return the Source PAN ID
167 */
168 uint16_t GetSrcPanId() const;
169 /**
170 * Get the Source Short address
171 * \return the Source Short address
172 */
174 /**
175 * Get the Source Extended address
176 * \return the Source Extended address
177 */
179 /**
180 * Get the Auxiliary Security Header - Security Control Octet
181 * \return the Auxiliary Security Header - Security Control Octet
182 */
183 uint8_t GetSecControl() const;
184 /**
185 * Get the Auxiliary Security Header - Frame Counter Octets
186 * \return the Auxiliary Security Header - Frame Counter Octets
187 */
188 uint32_t GetFrmCounter() const;
189
190 /**
191 * Get the Auxiliary Security Header - Security Control - Security Level bits
192 * \return the Auxiliary Security Header - Security Control - Security Level bits
193 */
194 uint8_t GetSecLevel() const;
195 /**
196 * Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits
197 * \return the Auxiliary Security Header - Security Control - Key Identifier Mode bits
198 */
199 uint8_t GetKeyIdMode() const;
200 /**
201 * Get the Auxiliary Security Header - Security Control - Reserved bits
202 * \return the Auxiliary Security Header - Security Control - Reserved bits
203 */
204 uint8_t GetSecCtrlReserved() const;
205 /**
206 * Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octets)
207 * \return the Auxiliary Security Header - Key Identifier - Key Source (2 Octets)
208 */
209 uint32_t GetKeyIdSrc32() const;
210 /**
211 * Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octets)
212 * \return the Auxiliary Security Header - Key Identifier - Key Source (4 Octets)
213 */
214 uint64_t GetKeyIdSrc64() const;
215 /**
216 * Get the Auxiliary Security Header - Key Identifier - Key Index
217 * \return the Auxiliary Security Header - Key Identifier - Key Index
218 */
219 uint8_t GetKeyIdIndex() const;
220 /**
221 * Returns true if the header is a beacon
222 * \return true if the header is a beacon
223 */
224 bool IsBeacon() const;
225 /**
226 * Returns true if the header is a data
227 * \return true if the header is a data
228 */
229 bool IsData() const;
230 /**
231 * Returns true if the header is an ack
232 * \return true if the header is an ack
233 */
234 bool IsAcknowledgment() const;
235 /**
236 * Returns true if the header is a command
237 * \return true if the header is a command
238 */
239 bool IsCommand() const;
240 /**
241 * Set the Frame Control field "Frame Type" bits
242 * \param wpanMacType the frame type
243 */
244 void SetType(LrWpanMacType wpanMacType);
245 /**
246 * Set the whole Frame Control field
247 * \param frameControl the Frame Control field
248 */
249 void SetFrameControl(uint16_t frameControl);
250 /**
251 * Set the Frame Control field "Security Enabled" bit to true
252 */
253 void SetSecEnable();
254 /**
255 * Set the Frame Control field "Security Enabled" bit to false
256 */
257 void SetSecDisable();
258 /**
259 * Set the Frame Control field "Frame Pending" bit to true
260 */
261 void SetFrmPend();
262 /**
263 * Set the Frame Control field "Frame Pending" bit to false
264 */
265 void SetNoFrmPend();
266 /**
267 * Set the Frame Control field "Ack. Request" bit to true
268 */
269 void SetAckReq();
270 /**
271 * Set the Frame Control field "Ack. Request" bit to false
272 */
273 void SetNoAckReq();
274 /**
275 * Set the Frame Control field "PAN ID Compression" bit to true
276 */
277 void SetPanIdComp();
278 /**
279 * Set the Frame Control field "PAN ID Compression" bit to false
280 */
281 void SetNoPanIdComp();
282 /**
283 * Set the Frame Control field "Reserved" bits
284 * \param res reserved bits
285 */
286 void SetFrmCtrlRes(uint8_t res);
287 /**
288 * Set the Destination address mode
289 * \param addrMode Destination address mode
290 */
291 void SetDstAddrMode(uint8_t addrMode);
292 /**
293 * Set the Frame version
294 * \param ver frame version
295 */
296 void SetFrameVer(uint8_t ver);
297 /**
298 * Set the Source address mode
299 * \param addrMode Source address mode
300 */
301 void SetSrcAddrMode(uint8_t addrMode);
302 /**
303 * Set the Sequence number
304 * \param seqNum sequence number
305 */
306 void SetSeqNum(uint8_t seqNum);
307 /* The Source/Destination Addressing fields are only set if SrcAddrMode/DstAddrMode are set */
308 /**
309 * Set Source address fields
310 * \param panId source PAN ID
311 * \param addr source address (16 bit)
312 */
313 void SetSrcAddrFields(uint16_t panId, Mac16Address addr);
314 /**
315 * Set Source address fields
316 * \param panId source PAN ID
317 * \param addr source address (64 bit)
318 */
319 void SetSrcAddrFields(uint16_t panId, Mac64Address addr);
320 /**
321 * Set Destination address fields
322 * \param panId destination PAN ID
323 * \param addr destination address (16 bit)
324 */
325 void SetDstAddrFields(uint16_t panId, Mac16Address addr);
326 /**
327 * Set Destination address fields
328 * \param panId destination PAN ID
329 * \param addr destination address (64 bit)
330 */
331 void SetDstAddrFields(uint16_t panId, Mac64Address addr);
332
333 /* Auxiliary Security Header is only set if Sec Enable (SecU) field is set to 1 */
334 /**
335 * Set the auxiliary security header "Security Control" octet
336 * \param secLevel the "Security Control" octet
337 */
338 void SetSecControl(uint8_t secLevel);
339 /**
340 * Set the auxiliary security header "Frame Counter" octet
341 * \param frmCntr the "Frame Counter" octet
342 */
343 void SetFrmCounter(uint32_t frmCntr);
344 /**
345 * Set the Security Control field "Security Level" bits (3 bits)
346 * \param secLevel the "Security Level" bits
347 */
348 void SetSecLevel(uint8_t secLevel);
349 /**
350 * Set the Security Control field "Key Identifier Mode" bits (2 bits)
351 * \param keyIdMode the "Key Identifier Mode" bits
352 */
353 void SetKeyIdMode(uint8_t keyIdMode);
354 /**
355 * Set the Security Control field "Reserved" bits (3 bits)
356 * \param res the "Reserved" bits
357 */
358 void SetSecCtrlReserved(uint8_t res);
359 /* Variable length will be dependent on Key Id Mode*/
360 /**
361 * Set the Key Index
362 * \param keyIndex the Key index
363 */
364 void SetKeyId(uint8_t keyIndex);
365 /**
366 * Set the Key Index and originator
367 * \param keySrc the originator of a group key
368 * \param keyIndex the Key index
369 */
370 void SetKeyId(uint32_t keySrc, uint8_t keyIndex);
371 /**
372 * Set the Key Index and originator
373 * \param keySrc the originator of a group key
374 * \param keyIndex the Key index
375 */
376 void SetKeyId(uint64_t keySrc, uint8_t keyIndex);
377 /**
378 * \brief Get the type ID.
379 * \return the object TypeId
380 */
381 static TypeId GetTypeId();
382 TypeId GetInstanceTypeId() const override;
383
384 void Print(std::ostream& os) const override;
385 uint32_t GetSerializedSize() const override;
386 void Serialize(Buffer::Iterator start) const override;
387 uint32_t Deserialize(Buffer::Iterator start) override;
388
389 private:
390 /* Frame Control 2 Octets */
391 /* Frame Control field - see 7.2.1.1 */
392 uint8_t m_fctrlFrmType; //!< Frame Control field Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 -
393 //!< Command
394 uint8_t m_fctrlSecU; //!< Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security
395 //!< enabled AuxSecHdr present
396 uint8_t m_fctrlFrmPending; //!< Frame Control field Bit 4
397 uint8_t m_fctrlAckReq; //!< Frame Control field Bit 5
398 uint8_t m_fctrlPanIdComp; //!< Frame Control field Bit 6 = 0 - no compression, 1 - using
399 //!< only DstPanId for both Src and DstPanId
400 uint8_t m_fctrlReserved; //!< Frame Control field Bit 7-9
401 uint8_t m_fctrlDstAddrMode; //!< Frame Control field Bit 10-11 = 0 - No DstAddr, 2 -
402 //!< ShtDstAddr, 3 - ExtDstAddr
403 uint8_t m_fctrlFrmVer; //!< Frame Control field Bit 12-13
404 uint8_t m_fctrlSrcAddrMode; //!< Frame Control field Bit 14-15 = 0 - No SrcAddr, 2 -
405 //!< ShtSrcAddr, 3 - ExtSrcAddr
406
407 /* Sequence Number */
408 uint8_t m_SeqNum; //!< Sequence Number (1 Octet)
409
410 /* Addressing fields */
411 uint16_t m_addrDstPanId; //!< Dst PAN id (0 or 2 Octets)
412 Mac16Address m_addrShortDstAddr; //!< Dst Short addr (0 or 2 Octets)
413 Mac64Address m_addrExtDstAddr; //!< Dst Ext addr (0 or 8 Octets)
414 uint16_t m_addrSrcPanId; //!< Src PAN id (0 or 2 Octets)
415 Mac16Address m_addrShortSrcAddr; //!< Src Short addr (0 or 2 Octets)
416 Mac64Address m_addrExtSrcAddr; //!< Src Ext addr (0 or 8 Octets)
417
418 /* Auxiliary Security Header - See 7.6.2 - 0, 5, 6, 10 or 14 Octets */
419 // uint8_t m_auxSecCtrl; // 1 Octet see below
420 uint32_t m_auxFrmCntr; //!< Auxiliary security header - Frame Counter (4 Octets)
421
422 /* Security Control fields - See 7.6.2.2 */
423 uint8_t m_secctrlSecLevel; //!< Auxiliary security header - Security Control field - Bit 0-2
424 uint8_t m_secctrlKeyIdMode; //!< Auxiliary security header - Security Control field - Bit 3-4
425 //!< will indicate size of Key Id
426 // = 0 - Key is determined implicitly
427 // from originator and recipient
428 // = 1 - 1 Octet Key Index
429 // = 2 - 1 Octet Key Index and 4 oct Key src
430 // = 3 - 1 Octet Key Index and 8 oct Key src
431
432 uint8_t m_secctrlReserved; //!< Auxiliary security header - Security Control field - Bit 5-7
433
434 union {
435 uint32_t m_auxKeyIdKeySrc32; //!< Auxiliary security header - Key Source (4 Octets)
436 uint64_t m_auxKeyIdKeySrc64; //!< Auxiliary security header - Key Source (8 Octets)
437 }; //!< Auxiliary security header
438
439 uint8_t m_auxKeyIdKeyIndex; //!< Auxiliary security header - Key Index (1 Octet)
440
441}; // LrWpanMacHeader
442
443} // namespace lrwpan
444} // namespace ns3
445
446#endif /* LR_WPAN_MAC_HEADER_H */
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
This class can contain 16 bit addresses.
an EUI-64 address
a unique identifier for an interface.
Definition type-id.h:48
Represent the Mac Header with the Frame Control and Sequence Number fields.
uint8_t GetSecControl() const
Get the Auxiliary Security Header - Security Control Octet.
void SetFrmPend()
Set the Frame Control field "Frame Pending" bit to true.
uint32_t GetSerializedSize() const override
void SetSecLevel(uint8_t secLevel)
Set the Security Control field "Security Level" bits (3 bits)
LrWpanMacType GetType() const
Get the header type.
uint8_t m_fctrlReserved
Frame Control field Bit 7-9.
bool IsSecEnable() const
Check if Security Enabled bit of Frame Control is enabled.
uint8_t GetKeyIdIndex() const
Get the Auxiliary Security Header - Key Identifier - Key Index.
uint8_t m_secctrlKeyIdMode
Auxiliary security header - Security Control field - Bit 3-4 will indicate size of Key Id.
uint8_t m_auxKeyIdKeyIndex
Auxiliary security header - Key Index (1 Octet)
void SetSecControl(uint8_t secLevel)
Set the auxiliary security header "Security Control" octet.
uint64_t m_auxKeyIdKeySrc64
Auxiliary security header - Key Source (8 Octets)
Mac16Address GetShortSrcAddr() const
Get the Source Short address.
void SetType(LrWpanMacType wpanMacType)
Set the Frame Control field "Frame Type" bits.
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
uint16_t m_addrDstPanId
Dst PAN id (0 or 2 Octets)
void SetNoAckReq()
Set the Frame Control field "Ack. Request" bit to false.
uint8_t GetSecLevel() const
Get the Auxiliary Security Header - Security Control - Security Level bits.
void SetSecCtrlReserved(uint8_t res)
Set the Security Control field "Reserved" bits (3 bits)
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
Mac64Address GetExtSrcAddr() const
Get the Source Extended address.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_auxKeyIdKeySrc32
Auxiliary security header - Key Source (4 Octets)
uint32_t Deserialize(Buffer::Iterator start) override
AddrModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
bool IsData() const
Returns true if the header is a data.
KeyIdModeType
The addressing mode types, see IEEE 802.15.4-2006, Table 80.
uint8_t m_fctrlFrmType
Frame Control field Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 - Command.
uint64_t GetKeyIdSrc64() const
Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octets)
void SetFrameControl(uint16_t frameControl)
Set the whole Frame Control field.
Mac16Address m_addrShortDstAddr
Dst Short addr (0 or 2 Octets)
uint8_t m_SeqNum
Sequence Number (1 Octet)
bool IsBeacon() const
Returns true if the header is a beacon.
void Print(std::ostream &os) const override
LrWpanMacType
The possible MAC types, see IEEE 802.15.4-2006, Table 79.
@ LRWPAN_MAC_ACKNOWLEDGMENT
LRWPAN_MAC_ACKNOWLEDGMENT.
@ LRWPAN_MAC_RESERVED
LRWPAN_MAC_RESERVED.
@ LRWPAN_MAC_COMMAND
LRWPAN_MAC_COMMAND.
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
uint32_t GetFrmCounter() const
Get the Auxiliary Security Header - Frame Counter Octets.
void SetPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to true.
Mac16Address GetShortDstAddr() const
Get the Destination Short address.
void Serialize(Buffer::Iterator start) const override
Mac16Address m_addrShortSrcAddr
Src Short addr (0 or 2 Octets)
uint16_t GetFrameControl() const
Get the Frame control field.
uint8_t GetKeyIdMode() const
Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
bool IsCommand() const
Returns true if the header is a command.
uint16_t m_addrSrcPanId
Src PAN id (0 or 2 Octets)
uint32_t GetKeyIdSrc32() const
Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octets)
uint8_t GetSecCtrlReserved() const
Get the Auxiliary Security Header - Security Control - Reserved bits.
void SetFrmCtrlRes(uint8_t res)
Set the Frame Control field "Reserved" bits.
void SetKeyId(uint8_t keyIndex)
Set the Key Index.
uint8_t GetSeqNum() const
Get the frame Sequence number.
void SetFrameVer(uint8_t ver)
Set the Frame version.
uint8_t m_secctrlSecLevel
Auxiliary security header - Security Control field - Bit 0-2.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetFrameVer() const
Get the Frame Version of Frame control field.
void SetFrmCounter(uint32_t frmCntr)
Set the auxiliary security header "Frame Counter" octet.
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Mac64Address m_addrExtDstAddr
Dst Ext addr (0 or 8 Octets)
uint8_t m_fctrlDstAddrMode
Frame Control field Bit 10-11 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr.
Mac64Address m_addrExtSrcAddr
Src Ext addr (0 or 8 Octets)
bool IsFrmPend() const
Check if Frame Pending bit of Frame Control is enabled.
uint8_t m_secctrlReserved
Auxiliary security header - Security Control field - Bit 5-7.
uint16_t GetSrcPanId() const
Get the Source PAN ID.
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
uint8_t m_fctrlSrcAddrMode
Frame Control field Bit 14-15 = 0 - No SrcAddr, 2 - ShtSrcAddr, 3 - ExtSrcAddr.
uint16_t GetDstPanId() const
Get the Destination PAN ID.
uint8_t m_fctrlFrmPending
Frame Control field Bit 4.
uint8_t m_fctrlPanIdComp
Frame Control field Bit 6 = 0 - no compression, 1 - using only DstPanId for both Src and DstPanId.
uint8_t m_fctrlFrmVer
Frame Control field Bit 12-13.
uint8_t m_fctrlAckReq
Frame Control field Bit 5.
void SetNoFrmPend()
Set the Frame Control field "Frame Pending" bit to false.
uint32_t m_auxFrmCntr
Auxiliary security header - Frame Counter (4 Octets)
void SetAckReq()
Set the Frame Control field "Ack. Request" bit to true.
bool IsAckReq() const
Check if Ack.
uint8_t GetDstAddrMode() const
Get the Dest.
uint8_t m_fctrlSecU
Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present.
void SetSecEnable()
Set the Frame Control field "Security Enabled" bit to true.
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
Mac64Address GetExtDstAddr() const
Get the Destination Extended address.
bool IsAcknowledgment() const
Returns true if the header is an ack.
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 SetSeqNum(uint8_t seqNum)
Set the Sequence number.
uint8_t GetFrmCtrlRes() const
Get the Reserved bits of Frame control field.
void SetKeyIdMode(uint8_t keyIdMode)
Set the Security Control field "Key Identifier Mode" bits (2 bits)
Every class exported by the ns3 library is enclosed in the ns3 namespace.