A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lr-wpan-mac-header.cc
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
#include "
lr-wpan-mac-header.h
"
20
21
#include <ns3/address-utils.h>
22
23
namespace
ns3
24
{
25
namespace
lrwpan
26
{
27
28
NS_OBJECT_ENSURE_REGISTERED
(
LrWpanMacHeader
);
29
30
// TODO: Test Compressed PAN Id, Security Enabled, different size Key
31
32
LrWpanMacHeader::LrWpanMacHeader
()
33
{
34
SetType
(
LRWPAN_MAC_DATA
);
// Assume Data frame
35
SetSecDisable
();
// Assume there is No Aux Sec but
36
SetNoFrmPend
();
// No Frame Pending
37
SetNoAckReq
();
// No Ack Frame will be expected from recipient
38
SetNoPanIdComp
();
// No PAN Id Compression since no addresses
39
SetFrmCtrlRes
(0);
// Initialize the 3 reserved bits to 0
40
SetDstAddrMode
(
NOADDR
);
// Assume there will be no src and dst address
41
SetSrcAddrMode
(
NOADDR
);
42
SetFrameVer
(1);
// Indicates an IEEE 802.15.4 frame
43
}
44
45
LrWpanMacHeader::LrWpanMacHeader
(
LrWpanMacType
wpanMacType, uint8_t seqNum)
46
{
47
SetType
(wpanMacType);
48
SetSeqNum
(seqNum);
49
SetSecDisable
();
// Assume there is No Aux Sec but
50
SetNoFrmPend
();
// No Frame Pending
51
SetNoAckReq
();
// No Ack Frame will be expected from recipient
52
SetNoPanIdComp
();
// No PAN Id Compression since no addresses
53
SetFrmCtrlRes
(0);
// Initialize the 3 reserved bits to 0
54
SetDstAddrMode
(
NOADDR
);
// Assume there will be no src and dst address
55
SetSrcAddrMode
(
NOADDR
);
56
SetFrameVer
(1);
// Indicates an IEEE 802.15.4 frame
57
}
58
59
LrWpanMacHeader::~LrWpanMacHeader
()
60
{
61
}
62
63
LrWpanMacHeader::LrWpanMacType
64
LrWpanMacHeader::GetType
()
const
65
{
66
switch
(
m_fctrlFrmType
)
67
{
68
case
0:
69
return
LRWPAN_MAC_BEACON
;
70
case
1:
71
return
LRWPAN_MAC_DATA
;
72
case
2:
73
return
LRWPAN_MAC_ACKNOWLEDGMENT
;
74
case
3:
75
return
LRWPAN_MAC_COMMAND
;
76
default
:
77
return
LRWPAN_MAC_RESERVED
;
78
}
79
}
80
81
uint16_t
82
LrWpanMacHeader::GetFrameControl
()
const
83
{
84
uint16_t val = 0;
85
86
val =
m_fctrlFrmType
& (0x07);
// Bit 0-2
87
val |= (
m_fctrlSecU
<< 3) & (0x01 << 3);
// Bit 3
88
val |= (
m_fctrlFrmPending
<< 4) & (0x01 << 4);
// Bit 4
89
val |= (
m_fctrlAckReq
<< 5) & (0x01 << 5);
// Bit 5
90
val |= (
m_fctrlPanIdComp
<< 6) & (0x01 << 6);
// Bit 6
91
val |= (
m_fctrlReserved
<< 7) & (0x07 << 7);
// Bit 7-9
92
val |= (
m_fctrlDstAddrMode
<< 10) & (0x03 << 10);
// Bit 10-11
93
val |= (
m_fctrlFrmVer
<< 12) & (0x03 << 12);
// Bit 12-13
94
val |= (
m_fctrlSrcAddrMode
<< 14) & (0x03 << 14);
// Bit 14-15
95
return
val;
96
}
97
98
bool
99
LrWpanMacHeader::IsSecEnable
()
const
100
{
101
return
(
m_fctrlSecU
== 1);
102
}
103
104
bool
105
LrWpanMacHeader::IsFrmPend
()
const
106
{
107
return
(
m_fctrlFrmPending
== 1);
108
}
109
110
bool
111
LrWpanMacHeader::IsAckReq
()
const
112
{
113
return
(
m_fctrlAckReq
== 1);
114
}
115
116
bool
117
LrWpanMacHeader::IsPanIdComp
()
const
118
{
119
return
(
m_fctrlPanIdComp
== 1);
120
}
121
122
uint8_t
123
LrWpanMacHeader::GetFrmCtrlRes
()
const
124
{
125
return
m_fctrlReserved
;
126
}
127
128
uint8_t
129
LrWpanMacHeader::GetDstAddrMode
()
const
130
{
131
return
m_fctrlDstAddrMode
;
132
}
133
134
uint8_t
135
LrWpanMacHeader::GetFrameVer
()
const
136
{
137
return
m_fctrlFrmVer
;
138
}
139
140
uint8_t
141
LrWpanMacHeader::GetSrcAddrMode
()
const
142
{
143
return
m_fctrlSrcAddrMode
;
144
}
145
146
uint8_t
147
LrWpanMacHeader::GetSeqNum
()
const
148
{
149
return
m_SeqNum
;
150
}
151
152
uint16_t
153
LrWpanMacHeader::GetDstPanId
()
const
154
{
155
return
m_addrDstPanId
;
156
}
157
158
Mac16Address
159
LrWpanMacHeader::GetShortDstAddr
()
const
160
{
161
return
m_addrShortDstAddr
;
162
}
163
164
Mac64Address
165
LrWpanMacHeader::GetExtDstAddr
()
const
166
{
167
return
m_addrExtDstAddr
;
168
}
169
170
uint16_t
171
LrWpanMacHeader::GetSrcPanId
()
const
172
{
173
return
m_addrSrcPanId
;
174
}
175
176
Mac16Address
177
LrWpanMacHeader::GetShortSrcAddr
()
const
178
{
179
return
m_addrShortSrcAddr
;
180
}
181
182
Mac64Address
183
LrWpanMacHeader::GetExtSrcAddr
()
const
184
{
185
return
m_addrExtSrcAddr
;
186
}
187
188
uint8_t
189
LrWpanMacHeader::GetSecControl
()
const
190
{
191
uint8_t val = 0;
192
193
val =
m_secctrlSecLevel
& (0x7);
// Bit 0-2
194
val |= (
m_secctrlKeyIdMode
<< 3) & (0x3 << 3);
// Bit 3-4
195
val |= (
m_secctrlReserved
<< 5) & (0x7 << 5);
// Bit 5-7
196
197
return
val;
198
}
199
200
uint32_t
201
LrWpanMacHeader::GetFrmCounter
()
const
202
{
203
return
m_auxFrmCntr
;
204
}
205
206
uint8_t
207
LrWpanMacHeader::GetSecLevel
()
const
208
{
209
return
m_secctrlSecLevel
;
210
}
211
212
uint8_t
213
LrWpanMacHeader::GetKeyIdMode
()
const
214
{
215
return
m_secctrlKeyIdMode
;
216
}
217
218
uint8_t
219
LrWpanMacHeader::GetSecCtrlReserved
()
const
220
{
221
return
m_secctrlReserved
;
222
}
223
224
uint32_t
225
LrWpanMacHeader::GetKeyIdSrc32
()
const
226
{
227
return
m_auxKeyIdKeySrc32
;
228
}
229
230
uint64_t
231
LrWpanMacHeader::GetKeyIdSrc64
()
const
232
{
233
return
m_auxKeyIdKeySrc64
;
234
}
235
236
uint8_t
237
LrWpanMacHeader::GetKeyIdIndex
()
const
238
{
239
return
m_auxKeyIdKeyIndex
;
240
}
241
242
bool
243
LrWpanMacHeader::IsBeacon
()
const
244
{
245
return
(
m_fctrlFrmType
==
LRWPAN_MAC_BEACON
);
246
}
247
248
bool
249
LrWpanMacHeader::IsData
()
const
250
{
251
return
(
m_fctrlFrmType
==
LRWPAN_MAC_DATA
);
252
}
253
254
bool
255
LrWpanMacHeader::IsAcknowledgment
()
const
256
{
257
return
(
m_fctrlFrmType
==
LRWPAN_MAC_ACKNOWLEDGMENT
);
258
}
259
260
bool
261
LrWpanMacHeader::IsCommand
()
const
262
{
263
return
(
m_fctrlFrmType
==
LRWPAN_MAC_COMMAND
);
264
}
265
266
void
267
LrWpanMacHeader::SetType
(
LrWpanMacType
wpanMacType)
268
{
269
m_fctrlFrmType
= wpanMacType;
270
}
271
272
void
273
LrWpanMacHeader::SetFrameControl
(uint16_t frameControl)
274
{
275
m_fctrlFrmType
= (frameControl) & (0x07);
// Bit 0-2
276
m_fctrlSecU
= (frameControl >> 3) & (0x01);
// Bit 3
277
m_fctrlFrmPending
= (frameControl >> 4) & (0x01);
// Bit 4
278
m_fctrlAckReq
= (frameControl >> 5) & (0x01);
// Bit 5
279
m_fctrlPanIdComp
= (frameControl >> 6) & (0x01);
// Bit 6
280
m_fctrlReserved
= (frameControl >> 7) & (0x07);
// Bit 7-9
281
m_fctrlDstAddrMode
= (frameControl >> 10) & (0x03);
// Bit 10-11
282
m_fctrlFrmVer
= (frameControl >> 12) & (0x03);
// Bit 12-13
283
m_fctrlSrcAddrMode
= (frameControl >> 14) & (0x03);
// Bit 14-15
284
}
285
286
void
287
LrWpanMacHeader::SetSecEnable
()
288
{
289
m_fctrlSecU
= 1;
290
}
291
292
void
293
LrWpanMacHeader::SetSecDisable
()
294
{
295
m_fctrlSecU
= 0;
296
}
297
298
void
299
LrWpanMacHeader::SetFrmPend
()
300
{
301
m_fctrlFrmPending
= 1;
302
}
303
304
void
305
LrWpanMacHeader::SetNoFrmPend
()
306
{
307
m_fctrlFrmPending
= 0;
308
}
309
310
void
311
LrWpanMacHeader::SetAckReq
()
312
{
313
m_fctrlAckReq
= 1;
314
}
315
316
void
317
LrWpanMacHeader::SetNoAckReq
()
318
{
319
m_fctrlAckReq
= 0;
320
}
321
322
void
323
LrWpanMacHeader::SetPanIdComp
()
324
{
325
m_fctrlPanIdComp
= 1;
326
}
327
328
void
329
LrWpanMacHeader::SetNoPanIdComp
()
330
{
331
m_fctrlPanIdComp
= 0;
332
}
333
334
void
335
LrWpanMacHeader::SetFrmCtrlRes
(uint8_t res)
336
{
337
m_fctrlReserved
= res;
338
}
339
340
void
341
LrWpanMacHeader::SetDstAddrMode
(uint8_t addrMode)
342
{
343
m_fctrlDstAddrMode
= addrMode;
344
}
345
346
void
347
LrWpanMacHeader::SetFrameVer
(uint8_t ver)
348
{
349
m_fctrlFrmVer
= ver;
350
}
351
352
void
353
LrWpanMacHeader::SetSrcAddrMode
(uint8_t addrMode)
354
{
355
m_fctrlSrcAddrMode
= addrMode;
356
}
357
358
void
359
LrWpanMacHeader::SetSeqNum
(uint8_t seqNum)
360
{
361
m_SeqNum
= seqNum;
362
}
363
364
void
365
LrWpanMacHeader::SetSrcAddrFields
(uint16_t panId,
Mac16Address
addr)
366
{
367
m_addrSrcPanId
= panId;
368
m_addrShortSrcAddr
= addr;
369
}
370
371
void
372
LrWpanMacHeader::SetSrcAddrFields
(uint16_t panId,
Mac64Address
addr)
373
{
374
m_addrSrcPanId
= panId;
375
m_addrExtSrcAddr
= addr;
376
}
377
378
void
379
LrWpanMacHeader::SetDstAddrFields
(uint16_t panId,
Mac16Address
addr)
380
{
381
m_addrDstPanId
= panId;
382
m_addrShortDstAddr
= addr;
383
}
384
385
void
386
LrWpanMacHeader::SetDstAddrFields
(uint16_t panId,
Mac64Address
addr)
387
{
388
m_addrDstPanId
= panId;
389
m_addrExtDstAddr
= addr;
390
}
391
392
void
393
LrWpanMacHeader::SetSecControl
(uint8_t secControl)
394
{
395
m_secctrlSecLevel
= (secControl) & (0x07);
// Bit 0-2
396
m_secctrlKeyIdMode
= (secControl >> 3) & (0x03);
// Bit 3-4
397
m_secctrlReserved
= (secControl >> 5) & (0x07);
// Bit 5-7
398
}
399
400
void
401
LrWpanMacHeader::SetFrmCounter
(
uint32_t
frmCntr)
402
{
403
m_auxFrmCntr
= frmCntr;
404
}
405
406
void
407
LrWpanMacHeader::SetSecLevel
(uint8_t secLevel)
408
{
409
m_secctrlSecLevel
= secLevel;
410
}
411
412
void
413
LrWpanMacHeader::SetKeyIdMode
(uint8_t keyIdMode)
414
{
415
m_secctrlKeyIdMode
= keyIdMode;
416
}
417
418
void
419
LrWpanMacHeader::SetSecCtrlReserved
(uint8_t res)
420
{
421
m_secctrlReserved
= res;
422
}
423
424
void
425
LrWpanMacHeader::SetKeyId
(uint8_t keyIndex)
426
{
427
m_auxKeyIdKeyIndex
= keyIndex;
428
}
429
430
void
431
LrWpanMacHeader::SetKeyId
(
uint32_t
keySrc, uint8_t keyIndex)
432
{
433
m_auxKeyIdKeyIndex
= keyIndex;
434
m_auxKeyIdKeySrc32
= keySrc;
435
}
436
437
void
438
LrWpanMacHeader::SetKeyId
(uint64_t keySrc, uint8_t keyIndex)
439
{
440
m_auxKeyIdKeyIndex
= keyIndex;
441
m_auxKeyIdKeySrc64
= keySrc;
442
}
443
444
TypeId
445
LrWpanMacHeader::GetTypeId
()
446
{
447
static
TypeId
tid =
TypeId
(
"ns3::LrWpanMacHeader"
)
448
.
SetParent
<
Header
>()
449
.SetGroupName(
"LrWpan"
)
450
.AddConstructor<
LrWpanMacHeader
>();
451
return
tid;
452
}
453
454
TypeId
455
LrWpanMacHeader::GetInstanceTypeId
()
const
456
{
457
return
GetTypeId
();
458
}
459
460
void
461
LrWpanMacHeader::Print
(std::ostream& os)
const
462
{
463
os <<
" Frame Type = "
<< (
uint32_t
)
m_fctrlFrmType
464
<<
", Sec Enable = "
<< (
uint32_t
)
m_fctrlSecU
465
<<
", Frame Pending = "
<< (
uint32_t
)
m_fctrlFrmPending
466
<<
", Ack Request = "
<< (
uint32_t
)
m_fctrlAckReq
467
<<
", PAN ID Compress = "
<< (
uint32_t
)
m_fctrlPanIdComp
468
<<
", Frame Vers = "
<< (
uint32_t
)
m_fctrlFrmVer
469
<<
", Dst Addrs Mode = "
<< (
uint32_t
)
m_fctrlDstAddrMode
470
<<
", Src Addr Mode = "
<< (
uint32_t
)
m_fctrlSrcAddrMode
;
471
472
os <<
", Sequence Num = "
<<
static_cast<
uint16_t
>
(
m_SeqNum
);
473
474
switch
(
m_fctrlDstAddrMode
)
475
{
476
case
NOADDR
:
477
break
;
478
case
SHORTADDR
:
479
os <<
", Dst Addr Pan ID = "
<<
static_cast<
uint16_t
>
(
m_addrDstPanId
)
480
<<
", m_addrShortDstAddr = "
<<
m_addrShortDstAddr
;
481
break
;
482
case
EXTADDR
:
483
os <<
", Dst Addr Pan ID = "
<<
static_cast<
uint16_t
>
(
m_addrDstPanId
)
484
<<
", m_addrExtDstAddr = "
<<
m_addrExtDstAddr
;
485
break
;
486
}
487
488
switch
(
m_fctrlSrcAddrMode
)
489
{
490
case
NOADDR
:
491
break
;
492
case
SHORTADDR
:
493
os <<
", Src Addr Pan ID = "
<<
static_cast<
uint16_t
>
(
m_addrSrcPanId
)
494
<<
", m_addrShortSrcAddr = "
<<
m_addrShortSrcAddr
;
495
break
;
496
case
EXTADDR
:
497
os <<
", Src Addr Pan ID = "
<<
static_cast<
uint32_t
>
(
m_addrSrcPanId
)
498
<<
", m_addrExtSrcAddr = "
<<
m_addrExtDstAddr
;
499
break
;
500
}
501
502
if
(
IsSecEnable
())
503
{
504
os <<
" Security Level = "
<<
static_cast<
uint32_t
>
(
m_secctrlSecLevel
)
505
<<
", Key Id Mode = "
<<
static_cast<
uint32_t
>
(
m_secctrlKeyIdMode
)
506
<<
", Frame Counter = "
<<
static_cast<
uint32_t
>
(
m_auxFrmCntr
);
507
508
switch
(
m_secctrlKeyIdMode
)
509
{
510
case
IMPLICIT
:
511
break
;
512
case
NOKEYSOURCE
:
513
os <<
", Key Id - Key Index = "
<<
static_cast<
uint32_t
>
(
m_auxKeyIdKeyIndex
);
514
break
;
515
case
SHORTKEYSOURCE
:
516
os <<
", Key Id - Key Source 32 ="
<<
static_cast<
uint32_t
>
(
m_auxKeyIdKeySrc32
)
517
<<
", Key Id - Key Index = "
<<
static_cast<
uint32_t
>
(
m_auxKeyIdKeyIndex
);
518
break
;
519
case
LONGKEYSOURCE
:
520
os <<
", Key Id - Key Source 64 ="
<<
static_cast<
uint64_t
>
(
m_auxKeyIdKeySrc64
)
521
<<
", Key Id - Key Index = "
<<
static_cast<
uint32_t
>
(
m_auxKeyIdKeyIndex
);
522
break
;
523
}
524
}
525
}
526
527
uint32_t
528
LrWpanMacHeader::GetSerializedSize
()
const
529
{
530
/*
531
* Each mac header will have
532
* Frame Control : 2 octet
533
* Sequence Number : 1 Octet
534
* Dst PAN Id : 0/2 Octet
535
* Dst Address : 0/2/8 octet
536
* Src PAN Id : 0/2 octet
537
* Src Address : 0/2/8 octet
538
* Aux Sec Header : 0/5/6/10/14 octet
539
*/
540
541
uint32_t
size = 3;
542
543
switch
(
m_fctrlDstAddrMode
)
544
{
545
case
NOADDR
:
546
break
;
547
case
SHORTADDR
:
548
size += 4;
549
break
;
550
case
EXTADDR
:
551
size += 10;
552
break
;
553
}
554
555
switch
(
m_fctrlSrcAddrMode
)
556
{
557
case
NOADDR
:
558
break
;
559
case
SHORTADDR
:
560
// check if PAN Id compression is enabled
561
if
(!
IsPanIdComp
())
562
{
563
size += 4;
564
}
565
else
566
{
567
size += 2;
568
}
569
break
;
570
case
EXTADDR
:
571
// check if PAN Id compression is enabled
572
if
(!
IsPanIdComp
())
573
{
574
size += 10;
575
}
576
else
577
{
578
size += 8;
579
}
580
break
;
581
}
582
583
// check if security is enabled
584
if
(
IsSecEnable
())
585
{
586
size += 5;
587
switch
(
m_secctrlKeyIdMode
)
588
{
589
case
IMPLICIT
:
590
break
;
591
case
NOKEYSOURCE
:
592
size += 1;
593
break
;
594
case
SHORTKEYSOURCE
:
595
size += 5;
596
break
;
597
case
LONGKEYSOURCE
:
598
size += 9;
599
break
;
600
}
601
}
602
return
size;
603
}
604
605
void
606
LrWpanMacHeader::Serialize
(
Buffer::Iterator
start)
const
607
{
608
Buffer::Iterator
i = start;
609
uint16_t frameControl =
GetFrameControl
();
610
611
i.
WriteHtolsbU16
(frameControl);
612
i.
WriteU8
(
GetSeqNum
());
613
614
switch
(
m_fctrlDstAddrMode
)
615
{
616
case
NOADDR
:
617
break
;
618
case
SHORTADDR
:
619
i.
WriteHtolsbU16
(
GetDstPanId
());
620
WriteTo
(i,
m_addrShortDstAddr
);
621
break
;
622
case
EXTADDR
:
623
i.
WriteHtolsbU16
(
GetDstPanId
());
624
WriteTo
(i,
m_addrExtDstAddr
);
625
break
;
626
}
627
628
switch
(
m_fctrlSrcAddrMode
)
629
{
630
case
NOADDR
:
631
break
;
632
case
SHORTADDR
:
633
if
(!
IsPanIdComp
())
634
{
635
i.
WriteHtolsbU16
(
GetSrcPanId
());
636
}
637
WriteTo
(i,
m_addrShortSrcAddr
);
638
break
;
639
case
EXTADDR
:
640
if
(!
IsPanIdComp
())
641
{
642
i.
WriteHtolsbU16
(
GetSrcPanId
());
643
}
644
WriteTo
(i,
m_addrExtSrcAddr
);
645
break
;
646
}
647
648
if
(
IsSecEnable
())
649
{
650
i.
WriteU8
(
GetSecControl
());
651
i.
WriteHtolsbU32
(
GetFrmCounter
());
652
653
switch
(
m_secctrlKeyIdMode
)
654
{
655
case
IMPLICIT
:
656
break
;
657
case
NOKEYSOURCE
:
658
i.
WriteU8
(
GetKeyIdIndex
());
659
break
;
660
case
SHORTKEYSOURCE
:
661
i.
WriteHtolsbU32
(
GetKeyIdSrc32
());
662
i.
WriteU8
(
GetKeyIdIndex
());
663
break
;
664
case
LONGKEYSOURCE
:
665
i.
WriteHtolsbU64
(
GetKeyIdSrc64
());
666
i.
WriteU8
(
GetKeyIdIndex
());
667
break
;
668
}
669
}
670
}
671
672
uint32_t
673
LrWpanMacHeader::Deserialize
(
Buffer::Iterator
start)
674
{
675
Buffer::Iterator
i = start;
676
uint16_t frameControl = i.
ReadLsbtohU16
();
677
SetFrameControl
(frameControl);
678
679
SetSeqNum
(i.
ReadU8
());
680
switch
(
m_fctrlDstAddrMode
)
681
{
682
case
NOADDR
:
683
break
;
684
case
SHORTADDR
:
685
m_addrDstPanId
= i.
ReadLsbtohU16
();
686
ReadFrom
(i,
m_addrShortDstAddr
);
687
break
;
688
case
EXTADDR
:
689
m_addrDstPanId
= i.
ReadLsbtohU16
();
690
ReadFrom
(i,
m_addrExtDstAddr
);
691
break
;
692
}
693
694
switch
(
m_fctrlSrcAddrMode
)
695
{
696
case
NOADDR
:
697
break
;
698
case
SHORTADDR
:
699
if
(!
IsPanIdComp
())
700
{
701
m_addrSrcPanId
= i.
ReadLsbtohU16
();
702
}
703
else
704
{
705
if
(
m_fctrlDstAddrMode
> 0)
706
{
707
m_addrSrcPanId
=
m_addrDstPanId
;
708
}
709
}
710
ReadFrom
(i,
m_addrShortSrcAddr
);
711
break
;
712
case
EXTADDR
:
713
if
(!
IsPanIdComp
())
714
{
715
m_addrSrcPanId
= i.
ReadLsbtohU16
();
716
}
717
else
718
{
719
if
(
m_fctrlDstAddrMode
> 0)
720
{
721
m_addrSrcPanId
=
m_addrDstPanId
;
722
}
723
}
724
ReadFrom
(i,
m_addrExtSrcAddr
);
725
break
;
726
}
727
728
if
(
IsSecEnable
())
729
{
730
SetSecControl
(i.
ReadU8
());
731
SetFrmCounter
(i.
ReadLsbtohU32
());
732
733
switch
(
m_secctrlKeyIdMode
)
734
{
735
case
IMPLICIT
:
736
break
;
737
case
NOKEYSOURCE
:
738
SetKeyId
(i.
ReadU8
());
739
break
;
740
case
SHORTKEYSOURCE
:
741
SetKeyId
(i.
ReadLsbtohU32
(), i.
ReadU8
());
742
break
;
743
case
LONGKEYSOURCE
:
744
SetKeyId
(i.
ReadLsbtohU64
(), i.
ReadU8
());
745
break
;
746
}
747
}
748
return
i.
GetDistanceFrom
(start);
749
}
750
751
}
// namespace lrwpan
752
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Buffer::Iterator::WriteHtolsbU16
void WriteHtolsbU16(uint16_t data)
Definition:
buffer.cc:902
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition:
buffer.h:1027
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:881
ns3::Buffer::Iterator::WriteHtolsbU32
void WriteHtolsbU32(uint32_t data)
Definition:
buffer.cc:910
ns3::Buffer::Iterator::ReadLsbtohU16
uint16_t ReadLsbtohU16()
Definition:
buffer.cc:1064
ns3::Buffer::Iterator::ReadLsbtohU64
uint64_t ReadLsbtohU64()
Definition:
buffer.cc:1094
ns3::Buffer::Iterator::WriteHtolsbU64
void WriteHtolsbU64(uint64_t data)
Definition:
buffer.cc:920
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(const Iterator &o) const
Definition:
buffer.cc:780
ns3::Buffer::Iterator::ReadLsbtohU32
uint32_t ReadLsbtohU32()
Definition:
buffer.cc:1076
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
LrWpanMacHeader
Introspection did not find any typical Config paths.
ns3::Mac16Address
This class can contain 16 bit addresses.
Definition:
mac16-address.h:44
ns3::Mac64Address
an EUI-64 address
Definition:
mac64-address.h:46
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:932
ns3::lrwpan::LrWpanMacHeader
Represent the Mac Header with the Frame Control and Sequence Number fields.
Definition:
lr-wpan-mac-header.h:54
ns3::lrwpan::LrWpanMacHeader::GetSecControl
uint8_t GetSecControl() const
Get the Auxiliary Security Header - Security Control Octet.
Definition:
lr-wpan-mac-header.cc:189
ns3::lrwpan::LrWpanMacHeader::SetFrmPend
void SetFrmPend()
Set the Frame Control field "Frame Pending" bit to true.
Definition:
lr-wpan-mac-header.cc:299
ns3::lrwpan::LrWpanMacHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
lr-wpan-mac-header.cc:528
ns3::lrwpan::LrWpanMacHeader::SetSecLevel
void SetSecLevel(uint8_t secLevel)
Set the Security Control field "Security Level" bits (3 bits)
Definition:
lr-wpan-mac-header.cc:407
ns3::lrwpan::LrWpanMacHeader::GetType
LrWpanMacType GetType() const
Get the header type.
Definition:
lr-wpan-mac-header.cc:64
ns3::lrwpan::LrWpanMacHeader::~LrWpanMacHeader
~LrWpanMacHeader() override
Definition:
lr-wpan-mac-header.cc:59
ns3::lrwpan::LrWpanMacHeader::m_fctrlReserved
uint8_t m_fctrlReserved
Frame Control field Bit 7-9.
Definition:
lr-wpan-mac-header.h:411
ns3::lrwpan::LrWpanMacHeader::IsSecEnable
bool IsSecEnable() const
Check if Security Enabled bit of Frame Control is enabled.
Definition:
lr-wpan-mac-header.cc:99
ns3::lrwpan::LrWpanMacHeader::GetKeyIdIndex
uint8_t GetKeyIdIndex() const
Get the Auxiliary Security Header - Key Identifier - Key Index.
Definition:
lr-wpan-mac-header.cc:237
ns3::lrwpan::LrWpanMacHeader::m_secctrlKeyIdMode
uint8_t m_secctrlKeyIdMode
Auxiliary security header - Security Control field - Bit 3-4 will indicate size of Key Id.
Definition:
lr-wpan-mac-header.h:435
ns3::lrwpan::LrWpanMacHeader::m_auxKeyIdKeyIndex
uint8_t m_auxKeyIdKeyIndex
Auxiliary security header - Key Index (1 Octet)
Definition:
lr-wpan-mac-header.h:450
ns3::lrwpan::LrWpanMacHeader::SetSecControl
void SetSecControl(uint8_t secLevel)
Set the auxiliary security header "Security Control" octet.
Definition:
lr-wpan-mac-header.cc:393
ns3::lrwpan::LrWpanMacHeader::m_auxKeyIdKeySrc64
uint64_t m_auxKeyIdKeySrc64
Auxiliary security header - Key Source (8 Octets)
Definition:
lr-wpan-mac-header.h:447
ns3::lrwpan::LrWpanMacHeader::GetShortSrcAddr
Mac16Address GetShortSrcAddr() const
Get the Source Short address.
Definition:
lr-wpan-mac-header.cc:177
ns3::lrwpan::LrWpanMacHeader::SetType
void SetType(LrWpanMacType wpanMacType)
Set the Frame Control field "Frame Type" bits.
Definition:
lr-wpan-mac-header.cc:267
ns3::lrwpan::LrWpanMacHeader::SetDstAddrMode
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
Definition:
lr-wpan-mac-header.cc:341
ns3::lrwpan::LrWpanMacHeader::m_addrDstPanId
uint16_t m_addrDstPanId
Dst PAN id (0 or 2 Octets)
Definition:
lr-wpan-mac-header.h:422
ns3::lrwpan::LrWpanMacHeader::SetNoAckReq
void SetNoAckReq()
Set the Frame Control field "Ack. Request" bit to false.
Definition:
lr-wpan-mac-header.cc:317
ns3::lrwpan::LrWpanMacHeader::GetSecLevel
uint8_t GetSecLevel() const
Get the Auxiliary Security Header - Security Control - Security Level bits.
Definition:
lr-wpan-mac-header.cc:207
ns3::lrwpan::LrWpanMacHeader::SetSecCtrlReserved
void SetSecCtrlReserved(uint8_t res)
Set the Security Control field "Reserved" bits (3 bits)
Definition:
lr-wpan-mac-header.cc:419
ns3::lrwpan::LrWpanMacHeader::SetDstAddrFields
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
Definition:
lr-wpan-mac-header.cc:379
ns3::lrwpan::LrWpanMacHeader::GetExtSrcAddr
Mac64Address GetExtSrcAddr() const
Get the Source Extended address.
Definition:
lr-wpan-mac-header.cc:183
ns3::lrwpan::LrWpanMacHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
lr-wpan-mac-header.cc:445
ns3::lrwpan::LrWpanMacHeader::m_auxKeyIdKeySrc32
uint32_t m_auxKeyIdKeySrc32
Auxiliary security header - Key Source (4 Octets)
Definition:
lr-wpan-mac-header.h:446
ns3::lrwpan::LrWpanMacHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition:
lr-wpan-mac-header.cc:673
ns3::lrwpan::LrWpanMacHeader::SHORTADDR
@ SHORTADDR
Definition:
lr-wpan-mac-header.h:75
ns3::lrwpan::LrWpanMacHeader::EXTADDR
@ EXTADDR
Definition:
lr-wpan-mac-header.h:76
ns3::lrwpan::LrWpanMacHeader::NOADDR
@ NOADDR
Definition:
lr-wpan-mac-header.h:73
ns3::lrwpan::LrWpanMacHeader::IsData
bool IsData() const
Returns true if the header is a data.
Definition:
lr-wpan-mac-header.cc:249
ns3::lrwpan::LrWpanMacHeader::IMPLICIT
@ IMPLICIT
Definition:
lr-wpan-mac-header.h:84
ns3::lrwpan::LrWpanMacHeader::LONGKEYSOURCE
@ LONGKEYSOURCE
Definition:
lr-wpan-mac-header.h:87
ns3::lrwpan::LrWpanMacHeader::SHORTKEYSOURCE
@ SHORTKEYSOURCE
Definition:
lr-wpan-mac-header.h:86
ns3::lrwpan::LrWpanMacHeader::NOKEYSOURCE
@ NOKEYSOURCE
Definition:
lr-wpan-mac-header.h:85
ns3::lrwpan::LrWpanMacHeader::m_fctrlFrmType
uint8_t m_fctrlFrmType
Frame Control field Bit 0-2 = 0 - Beacon, 1 - Data, 2 - Ack, 3 - Command.
Definition:
lr-wpan-mac-header.h:403
ns3::lrwpan::LrWpanMacHeader::GetKeyIdSrc64
uint64_t GetKeyIdSrc64() const
Get the Auxiliary Security Header - Key Identifier - Key Source (4 Octets)
Definition:
lr-wpan-mac-header.cc:231
ns3::lrwpan::LrWpanMacHeader::SetFrameControl
void SetFrameControl(uint16_t frameControl)
Set the whole Frame Control field.
Definition:
lr-wpan-mac-header.cc:273
ns3::lrwpan::LrWpanMacHeader::m_addrShortDstAddr
Mac16Address m_addrShortDstAddr
Dst Short addr (0 or 2 Octets)
Definition:
lr-wpan-mac-header.h:423
ns3::lrwpan::LrWpanMacHeader::m_SeqNum
uint8_t m_SeqNum
Sequence Number (1 Octet)
Definition:
lr-wpan-mac-header.h:419
ns3::lrwpan::LrWpanMacHeader::IsBeacon
bool IsBeacon() const
Returns true if the header is a beacon.
Definition:
lr-wpan-mac-header.cc:243
ns3::lrwpan::LrWpanMacHeader::Print
void Print(std::ostream &os) const override
Definition:
lr-wpan-mac-header.cc:461
ns3::lrwpan::LrWpanMacHeader::LrWpanMacType
LrWpanMacType
The possible MAC types, see IEEE 802.15.4-2006, Table 79.
Definition:
lr-wpan-mac-header.h:60
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_ACKNOWLEDGMENT
@ LRWPAN_MAC_ACKNOWLEDGMENT
LRWPAN_MAC_ACKNOWLEDGMENT.
Definition:
lr-wpan-mac-header.h:63
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_RESERVED
@ LRWPAN_MAC_RESERVED
LRWPAN_MAC_RESERVED.
Definition:
lr-wpan-mac-header.h:65
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_COMMAND
@ LRWPAN_MAC_COMMAND
LRWPAN_MAC_COMMAND.
Definition:
lr-wpan-mac-header.h:64
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_BEACON
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
Definition:
lr-wpan-mac-header.h:61
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_DATA
@ LRWPAN_MAC_DATA
LRWPAN_MAC_DATA.
Definition:
lr-wpan-mac-header.h:62
ns3::lrwpan::LrWpanMacHeader::GetFrmCounter
uint32_t GetFrmCounter() const
Get the Auxiliary Security Header - Frame Counter Octets.
Definition:
lr-wpan-mac-header.cc:201
ns3::lrwpan::LrWpanMacHeader::SetPanIdComp
void SetPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to true.
Definition:
lr-wpan-mac-header.cc:323
ns3::lrwpan::LrWpanMacHeader::GetShortDstAddr
Mac16Address GetShortDstAddr() const
Get the Destination Short address.
Definition:
lr-wpan-mac-header.cc:159
ns3::lrwpan::LrWpanMacHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
lr-wpan-mac-header.cc:606
ns3::lrwpan::LrWpanMacHeader::m_addrShortSrcAddr
Mac16Address m_addrShortSrcAddr
Src Short addr (0 or 2 Octets)
Definition:
lr-wpan-mac-header.h:426
ns3::lrwpan::LrWpanMacHeader::GetFrameControl
uint16_t GetFrameControl() const
Get the Frame control field.
Definition:
lr-wpan-mac-header.cc:82
ns3::lrwpan::LrWpanMacHeader::GetKeyIdMode
uint8_t GetKeyIdMode() const
Get the Auxiliary Security Header - Security Control - Key Identifier Mode bits.
Definition:
lr-wpan-mac-header.cc:213
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrMode
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
Definition:
lr-wpan-mac-header.cc:353
ns3::lrwpan::LrWpanMacHeader::IsCommand
bool IsCommand() const
Returns true if the header is a command.
Definition:
lr-wpan-mac-header.cc:261
ns3::lrwpan::LrWpanMacHeader::m_addrSrcPanId
uint16_t m_addrSrcPanId
Src PAN id (0 or 2 Octets)
Definition:
lr-wpan-mac-header.h:425
ns3::lrwpan::LrWpanMacHeader::GetKeyIdSrc32
uint32_t GetKeyIdSrc32() const
Get the Auxiliary Security Header - Key Identifier - Key Source (2 Octets)
Definition:
lr-wpan-mac-header.cc:225
ns3::lrwpan::LrWpanMacHeader::GetSecCtrlReserved
uint8_t GetSecCtrlReserved() const
Get the Auxiliary Security Header - Security Control - Reserved bits.
Definition:
lr-wpan-mac-header.cc:219
ns3::lrwpan::LrWpanMacHeader::SetFrmCtrlRes
void SetFrmCtrlRes(uint8_t res)
Set the Frame Control field "Reserved" bits.
Definition:
lr-wpan-mac-header.cc:335
ns3::lrwpan::LrWpanMacHeader::SetKeyId
void SetKeyId(uint8_t keyIndex)
Set the Key Index.
Definition:
lr-wpan-mac-header.cc:425
ns3::lrwpan::LrWpanMacHeader::GetSeqNum
uint8_t GetSeqNum() const
Get the frame Sequence number.
Definition:
lr-wpan-mac-header.cc:147
ns3::lrwpan::LrWpanMacHeader::SetFrameVer
void SetFrameVer(uint8_t ver)
Set the Frame version.
Definition:
lr-wpan-mac-header.cc:347
ns3::lrwpan::LrWpanMacHeader::m_secctrlSecLevel
uint8_t m_secctrlSecLevel
Auxiliary security header - Security Control field - Bit 0-2.
Definition:
lr-wpan-mac-header.h:434
ns3::lrwpan::LrWpanMacHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
lr-wpan-mac-header.cc:455
ns3::lrwpan::LrWpanMacHeader::GetFrameVer
uint8_t GetFrameVer() const
Get the Frame Version of Frame control field.
Definition:
lr-wpan-mac-header.cc:135
ns3::lrwpan::LrWpanMacHeader::SetFrmCounter
void SetFrmCounter(uint32_t frmCntr)
Set the auxiliary security header "Frame Counter" octet.
Definition:
lr-wpan-mac-header.cc:401
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrFields
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Definition:
lr-wpan-mac-header.cc:365
ns3::lrwpan::LrWpanMacHeader::m_addrExtDstAddr
Mac64Address m_addrExtDstAddr
Dst Ext addr (0 or 8 Octets)
Definition:
lr-wpan-mac-header.h:424
ns3::lrwpan::LrWpanMacHeader::m_fctrlDstAddrMode
uint8_t m_fctrlDstAddrMode
Frame Control field Bit 10-11 = 0 - No DstAddr, 2 - ShtDstAddr, 3 - ExtDstAddr.
Definition:
lr-wpan-mac-header.h:412
ns3::lrwpan::LrWpanMacHeader::m_addrExtSrcAddr
Mac64Address m_addrExtSrcAddr
Src Ext addr (0 or 8 Octets)
Definition:
lr-wpan-mac-header.h:427
ns3::lrwpan::LrWpanMacHeader::IsFrmPend
bool IsFrmPend() const
Check if Frame Pending bit of Frame Control is enabled.
Definition:
lr-wpan-mac-header.cc:105
ns3::lrwpan::LrWpanMacHeader::LrWpanMacHeader
LrWpanMacHeader()
Definition:
lr-wpan-mac-header.cc:32
ns3::lrwpan::LrWpanMacHeader::m_secctrlReserved
uint8_t m_secctrlReserved
Auxiliary security header - Security Control field - Bit 5-7.
Definition:
lr-wpan-mac-header.h:443
ns3::lrwpan::LrWpanMacHeader::GetSrcPanId
uint16_t GetSrcPanId() const
Get the Source PAN ID.
Definition:
lr-wpan-mac-header.cc:171
ns3::lrwpan::LrWpanMacHeader::SetNoPanIdComp
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
Definition:
lr-wpan-mac-header.cc:329
ns3::lrwpan::LrWpanMacHeader::m_fctrlSrcAddrMode
uint8_t m_fctrlSrcAddrMode
Frame Control field Bit 14-15 = 0 - No SrcAddr, 2 - ShtSrcAddr, 3 - ExtSrcAddr.
Definition:
lr-wpan-mac-header.h:415
ns3::lrwpan::LrWpanMacHeader::GetDstPanId
uint16_t GetDstPanId() const
Get the Destination PAN ID.
Definition:
lr-wpan-mac-header.cc:153
ns3::lrwpan::LrWpanMacHeader::m_fctrlFrmPending
uint8_t m_fctrlFrmPending
Frame Control field Bit 4.
Definition:
lr-wpan-mac-header.h:407
ns3::lrwpan::LrWpanMacHeader::m_fctrlPanIdComp
uint8_t m_fctrlPanIdComp
Frame Control field Bit 6 = 0 - no compression, 1 - using only DstPanId for both Src and DstPanId.
Definition:
lr-wpan-mac-header.h:409
ns3::lrwpan::LrWpanMacHeader::m_fctrlFrmVer
uint8_t m_fctrlFrmVer
Frame Control field Bit 12-13.
Definition:
lr-wpan-mac-header.h:414
ns3::lrwpan::LrWpanMacHeader::m_fctrlAckReq
uint8_t m_fctrlAckReq
Frame Control field Bit 5.
Definition:
lr-wpan-mac-header.h:408
ns3::lrwpan::LrWpanMacHeader::SetNoFrmPend
void SetNoFrmPend()
Set the Frame Control field "Frame Pending" bit to false.
Definition:
lr-wpan-mac-header.cc:305
ns3::lrwpan::LrWpanMacHeader::m_auxFrmCntr
uint32_t m_auxFrmCntr
Auxiliary security header - Frame Counter (4 Octets)
Definition:
lr-wpan-mac-header.h:431
ns3::lrwpan::LrWpanMacHeader::SetAckReq
void SetAckReq()
Set the Frame Control field "Ack. Request" bit to true.
Definition:
lr-wpan-mac-header.cc:311
ns3::lrwpan::LrWpanMacHeader::IsAckReq
bool IsAckReq() const
Check if Ack.
Definition:
lr-wpan-mac-header.cc:111
ns3::lrwpan::LrWpanMacHeader::GetDstAddrMode
uint8_t GetDstAddrMode() const
Get the Dest.
Definition:
lr-wpan-mac-header.cc:129
ns3::lrwpan::LrWpanMacHeader::m_fctrlSecU
uint8_t m_fctrlSecU
Frame Control field Bit 3 = 0 - no AuxSecHdr , 1 - security enabled AuxSecHdr present.
Definition:
lr-wpan-mac-header.h:405
ns3::lrwpan::LrWpanMacHeader::SetSecEnable
void SetSecEnable()
Set the Frame Control field "Security Enabled" bit to true.
Definition:
lr-wpan-mac-header.cc:287
ns3::lrwpan::LrWpanMacHeader::SetSecDisable
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
Definition:
lr-wpan-mac-header.cc:293
ns3::lrwpan::LrWpanMacHeader::GetExtDstAddr
Mac64Address GetExtDstAddr() const
Get the Destination Extended address.
Definition:
lr-wpan-mac-header.cc:165
ns3::lrwpan::LrWpanMacHeader::IsAcknowledgment
bool IsAcknowledgment() const
Returns true if the header is an ack.
Definition:
lr-wpan-mac-header.cc:255
ns3::lrwpan::LrWpanMacHeader::GetSrcAddrMode
uint8_t GetSrcAddrMode() const
Get the Source Addressing Mode of Frame control field.
Definition:
lr-wpan-mac-header.cc:141
ns3::lrwpan::LrWpanMacHeader::IsPanIdComp
bool IsPanIdComp() const
Check if PAN ID Compression bit of Frame Control is enabled.
Definition:
lr-wpan-mac-header.cc:117
ns3::lrwpan::LrWpanMacHeader::SetSeqNum
void SetSeqNum(uint8_t seqNum)
Set the Sequence number.
Definition:
lr-wpan-mac-header.cc:359
ns3::lrwpan::LrWpanMacHeader::GetFrmCtrlRes
uint8_t GetFrmCtrlRes() const
Get the Reserved bits of Frame control field.
Definition:
lr-wpan-mac-header.cc:123
ns3::lrwpan::LrWpanMacHeader::SetKeyIdMode
void SetKeyIdMode(uint8_t keyIdMode)
Set the Security Control field "Key Identifier Mode" bits (2 bits)
Definition:
lr-wpan-mac-header.cc:413
uint32_t
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
lr-wpan-mac-header.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WriteTo
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Definition:
address-utils.cc:32
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition:
address-utils.cc:85
src
lr-wpan
model
lr-wpan-mac-header.cc
Generated on Tue May 28 2024 23:36:52 for ns-3 by
1.9.6