A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-fields.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Ritsumeikan University, Shiga, Japan.
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: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
18 */
19
20#include "lr-wpan-fields.h"
21
22#include <ns3/address-utils.h>
23#include <ns3/log.h>
24
25namespace ns3
26{
27
29{
33 SetBattLifeExt(false);
34 SetPanCoor(false);
35 SetAssocPermit(false);
36}
37
38void
39SuperframeField::SetSuperframe(uint16_t superFrmSpec)
40{
41 m_sspecBcnOrder = (superFrmSpec) & (0x0F); // Bits 0-3
42 m_sspecSprFrmOrder = (superFrmSpec >> 4) & (0x0F); // Bits 4-7
43 m_sspecFnlCapSlot = (superFrmSpec >> 8) & (0x0F); // Bits 8-11
44 m_sspecBatLifeExt = (superFrmSpec >> 12) & (0x01); // Bit 12
45 // Bit 13 (Reserved)
46 m_sspecPanCoor = (superFrmSpec >> 14) & (0x01); // Bit 14
47 m_sspecAssocPermit = (superFrmSpec >> 15) & (0x01); // Bit 15
48}
49
50void
52{
53 if (bcnOrder > 15)
54 {
55 NS_ABORT_MSG("SuperframeField Beacon Order value must be 15 or less");
56 }
57 else
58 {
59 m_sspecBcnOrder = bcnOrder;
60 }
61}
62
63void
65{
66 if (frmOrder > 15)
67 {
68 NS_ABORT_MSG("SuperframeField Frame Order value must be 15 or less");
69 }
70 else
71 {
72 m_sspecSprFrmOrder = frmOrder;
73 }
74}
75
76void
78{
79 if (capSlot > 15)
80 {
81 NS_ABORT_MSG("The final slot cannot be greater than the slots in a CAP (15)");
82 }
83 else
84 {
85 m_sspecFnlCapSlot = capSlot;
86 }
87}
88
89void
91{
92 m_sspecBatLifeExt = battLifeExt;
93}
94
95void
97{
98 m_sspecPanCoor = panCoor;
99}
100
101void
103{
104 m_sspecAssocPermit = assocPermit;
105}
106
107uint8_t
109{
110 return m_sspecBcnOrder;
111}
112
113uint8_t
115{
116 return m_sspecSprFrmOrder;
117}
118
119uint8_t
121{
122 return m_sspecFnlCapSlot;
123}
124
125bool
127{
128 return m_sspecBatLifeExt;
129}
130
131bool
133{
134 return m_sspecPanCoor;
135}
136
137bool
139{
140 return m_sspecAssocPermit;
141}
142
143uint16_t
145{
146 uint16_t superframe;
147
148 superframe = m_sspecBcnOrder & (0x0F); // Bits 0-3
149 superframe |= (m_sspecSprFrmOrder << 4) & (0x0F << 4); // Bits 4-7
150 superframe |= (m_sspecFnlCapSlot << 8) & (0x0F << 8); // Bits 8-11
151 superframe |= (m_sspecBatLifeExt << 12) & (0x01 << 12); // Bit 12
152 // Bit 13 (Reserved)
153 superframe |= (m_sspecPanCoor << 14) & (0x01 << 14); // Bit 14
154 superframe |= (m_sspecAssocPermit << 15) & (0x01 << 15); // Bit 15
155
156 return superframe;
157}
158
161{
162 return 2; // 2 Octets (superframeSpec)
163}
164
167{
169 return i;
170}
171
174{
175 uint16_t superframe = i.ReadLsbtohU16();
176 SetSuperframe(superframe);
177
178 return i;
179}
180
181std::ostream&
182operator<<(std::ostream& os, const SuperframeField& superframeField)
183{
184 os << " Beacon Order = " << uint32_t(superframeField.GetBeaconOrder())
185 << ", Frame Order = " << uint32_t(superframeField.GetFrameOrder())
186 << ", Final CAP slot = " << uint32_t(superframeField.GetFinalCapSlot())
187 << ", Battery Life Ext = " << bool(superframeField.IsBattLifeExt())
188 << ", PAN Coordinator = " << bool(superframeField.IsPanCoor())
189 << ", Association Permit = " << bool(superframeField.IsAssocPermit());
190 return os;
191}
192
193/***********************************************************
194 * Guaranteed Time Slots (GTS) Fields
195 ***********************************************************/
196
198{
199 // GTS Specification Field
201 m_gtsSpecPermit = 0;
202 // GTS Direction Field
203 m_gtsDirMask = 0;
204}
205
206uint8_t
208{
209 uint8_t gtsSpecField;
210
211 gtsSpecField = m_gtsSpecDescCount & (0x07); // Bits 0-2
212 // Bits 3-6 (Reserved)
213 gtsSpecField |= (m_gtsSpecPermit << 7) & (0x01 << 7); // Bit 7
214
215 return gtsSpecField;
216}
217
218uint8_t
220{
221 uint8_t gtsDirectionField;
222
223 gtsDirectionField = m_gtsDirMask & (0x7F); // Bit 0-6
224 // Bit 7 (Reserved)
225 return gtsDirectionField;
226}
227
228void
230{
231 m_gtsSpecDescCount = (gtsSpec) & (0x07); // Bits 0-2
232 // Bits 3-6 (Reserved)
233 m_gtsSpecPermit = (gtsSpec >> 7) & (0x01); // Bit 7
234}
235
236void
238{
239 m_gtsDirMask = (gtsDir) & (0x7F); // Bits 0-6
240 // Bit 7 (Reserved)
241}
242
243bool
245{
246 return m_gtsSpecPermit;
247}
248
251{
252 uint32_t size;
253
254 size = 1; // 1 octet GTS Specification Field
255 if (m_gtsSpecDescCount > 0)
256 {
257 size += 1; // 1 octet GTS Direction Field
258 size += (m_gtsSpecDescCount * 3); // 3 octets per GTS descriptor
259 }
260
261 return size;
262}
263
266{
268
269 if (m_gtsSpecDescCount > 0)
270 {
271 uint8_t gtsDescStartAndLength;
273
274 for (int j = 0; j < m_gtsSpecDescCount; j++)
275 {
276 WriteTo(i, m_gtsList[j].m_gtsDescDevShortAddr);
277
278 gtsDescStartAndLength =
279 (m_gtsList[j].m_gtsDescStartSlot & 0x0F) | // GTS descriptor bits 16-19
280 (m_gtsList[j].m_gtsDescLength & 0xF0); // GTS descriptor bits 20-23
281
282 i.WriteU8(gtsDescStartAndLength);
283 }
284 }
285 return i;
286}
287
290{
291 uint8_t gtsSpecField = i.ReadU8();
292 SetGtsSpecField(gtsSpecField);
293
294 if (m_gtsSpecDescCount > 0)
295 {
296 uint8_t gtsDirectionField = i.ReadU8();
297 SetGtsDirectionField(gtsDirectionField);
298
299 uint8_t gtsDescStartAndLength;
300 for (int j = 0; j < m_gtsSpecDescCount; j++)
301 {
302 ReadFrom(i, m_gtsList[j].m_gtsDescDevShortAddr);
303
304 gtsDescStartAndLength = i.ReadU8();
305 m_gtsList[j].m_gtsDescStartSlot = (gtsDescStartAndLength) & (0x0F);
306 m_gtsList[j].m_gtsDescLength = (gtsDescStartAndLength >> 4) & (0x0F);
307 }
308 }
309 return i;
310}
311
312std::ostream&
313operator<<(std::ostream& os, const GtsFields& gtsFields)
314{
315 os << " GTS specification = " << uint32_t(gtsFields.GetGtsSpecField())
316 << ", GTS direction = " << uint32_t(gtsFields.GetGtsDirectionField());
317 return os;
318}
319
320/***********************************************************
321 * Pending Address Fields
322 ***********************************************************/
323
325{
328}
329
330uint8_t
332{
334}
335
336uint8_t
338{
340}
341
342uint8_t
344{
345 uint8_t pndAddrSpecField;
346
347 pndAddrSpecField = m_pndAddrSpecNumShortAddr & (0x07); // Bits 0-2
348 // Bit 3 (Reserved)
349 pndAddrSpecField |= (m_pndAddrSpecNumExtAddr << 4) & (0x07 << 4); // Bits 4-6
350 // Bit 7 (Reserved)
351
352 return pndAddrSpecField;
353}
354
355void
357{
358 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
359
360 if (totalPendAddr == 7)
361 {
362 return;
363 }
364 else
365 {
368 }
369}
370
371void
373{
374 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
375
376 if (totalPendAddr == 7)
377 {
378 return;
379 }
380 else
381 {
384 }
385}
386
387bool
389{
390 for (int j = 0; j <= m_pndAddrSpecNumShortAddr; j++)
391 {
392 if (shortAddr == m_shortAddrList[j])
393 {
394 return true;
395 }
396 }
397
398 return false;
399}
400
401bool
403{
404 for (int j = 0; j <= m_pndAddrSpecNumExtAddr; j++)
405 {
406 if (extAddr == m_extAddrList[j])
407 {
408 return true;
409 }
410 }
411
412 return false;
413}
414
415void
417{
418 m_pndAddrSpecNumShortAddr = (pndAddrSpecField) & (0x07); // Bit 0-2
419 // Bit 3
420 m_pndAddrSpecNumExtAddr = (pndAddrSpecField >> 4) & (0x07); // Bit 4-6
421 // Bit 7
422}
423
426{
427 uint32_t size;
428
429 size = 1; // 1 octet (Pending Address Specification Field)
430 size = size + (m_pndAddrSpecNumShortAddr * 2); // X octets (Short Pending Address List)
431 size = size + (m_pndAddrSpecNumExtAddr * 8); // X octets (Extended Pending Address List)
432
433 return size;
434}
435
438{
440
441 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
442 {
444 }
445
446 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
447 {
448 WriteTo(i, m_extAddrList[k]);
449 }
450
451 return i;
452}
453
456{
457 uint8_t pndAddrSpecField = i.ReadU8();
458
459 SetPndAddrSpecField(pndAddrSpecField);
460
461 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
462 {
464 }
465
466 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
467 {
468 ReadFrom(i, m_extAddrList[k]);
469 }
470
471 return i;
472}
473
474std::ostream&
475operator<<(std::ostream& os, const PendingAddrFields& pendingAddrFields)
476{
477 os << " Num. Short Addr = " << uint32_t(pendingAddrFields.GetNumShortAddr())
478 << ", Num. Ext Addr = " << uint32_t(pendingAddrFields.GetNumExtAddr());
479 return os;
480}
481
482/***********************************************************
483 * Capability Information Field
484 ***********************************************************/
485
487{
488 m_deviceType = true;
489 m_powerSource = false;
491 m_securityCap = false;
492 m_allocAddr = true;
493}
494
497{
498 return 1;
499}
500
503{
504 uint8_t capability;
505
506 capability = 0;
507 capability = (m_deviceType << 1) & (0x01 << 1);
508 capability |= (m_powerSource << 2) & (0x01 << 2);
509 capability |= (m_receiverOnWhenIdle << 3) & (0x01 << 3);
511 capability |= (m_securityCap << 6) & (0x01 << 6);
512 capability |= (m_allocAddr << 7) & (0x01 << 7);
513 i.WriteU8(capability);
514 return i;
515}
516
519{
520 uint8_t capability = i.ReadU8();
522 m_deviceType = (capability >> 1) & (0x01);
523 m_powerSource = (capability >> 2) & (0x01);
524 m_receiverOnWhenIdle = (capability >> 3) & (0x01);
526 m_securityCap = (capability >> 6) & (0x01);
527 m_allocAddr = (capability >> 7) & (0x01);
528
529 return i;
530}
531
532bool
534{
535 return m_deviceType;
536}
537
538bool
540{
541 return m_powerSource;
542}
543
544bool
546{
548}
549
550bool
552{
553 return m_securityCap;
554}
555
556bool
558{
559 return m_allocAddr;
560}
561
562void
564{
565 m_deviceType = devType;
566}
567
568void
570{
571 m_powerSource = pow;
572}
573
574void
576{
577 m_receiverOnWhenIdle = rxIdle;
578}
579
580void
582{
583 m_securityCap = sec;
584}
585
586void
588{
589 m_allocAddr = addrAlloc;
590}
591
600std::ostream&
601operator<<(std::ostream& os, const CapabilityField& capabilityField)
602{
603 os << " FFD device capable = " << bool(capabilityField.IsDeviceTypeFfd())
604 << ", Alternate Power Current Available = " << bool(capabilityField.IsPowSrcAvailable())
605 << ", Receiver On When Idle = " << bool(capabilityField.IsReceiverOnWhenIdle())
606 << ", Security Capable = " << bool(capabilityField.IsSecurityCapability())
607 << ", Coordinator Allocate Short Address = " << bool(capabilityField.IsShortAddrAllocOn());
608 return os;
609}
610
611} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:908
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1070
Represent the Capability Information Field.
bool m_securityCap
Capability Information Field, Security Capability (bit 6)
bool m_allocAddr
Capability Information Field, Allocate Address (bit 7)
void SetPowSrcAvailable(bool pow)
Set the Power Source available flag in the Capability Information Field.
void SetShortAddrAllocOn(bool addrAlloc)
Set the Short Address Flag in the Capability Information Field.
bool IsDeviceTypeFfd() const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
void SetSecurityCap(bool sec)
Set the Security Capability flag in the Capability Information Field.
bool IsSecurityCapability() const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
bool IsPowSrcAvailable() const
True if the device is receiving power from alternating current mains.
void SetRxOnWhenIdle(bool rxIdle)
Indicate if the receiver is On on Idle.
bool IsReceiverOnWhenIdle() const
True if the device does not disable its receiver to conserve power during idle periods.
bool IsShortAddrAllocOn() const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
bool m_deviceType
Capability Information Field, Device Type (bit 1)
uint32_t GetSerializedSize() const
Get the size of the serialized Capability Information Field.
bool m_powerSource
Capability Information Field, Power Source (bit 2)
void SetFfdDevice(bool devType)
Set the Device type in the Capability Information Field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire Capability Information Field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Capability Information Field.
bool m_receiverOnWhenIdle
Capability Information Field, Receiver On When Idle (bit 3)
Represent the GTS information fields.
void SetGtsSpecField(uint8_t gtsSpec)
Set the GTS Specification Field to the GTS Fields.
void SetGtsDirectionField(uint8_t gtsDir)
Set the GTS direction field to the GTS Fields.
GtsDescriptor m_gtsList[7]
GTS List field (maximum descriptors stored == 7)
bool GetGtsPermit() const
Get the GTS Specification Permit.
uint8_t m_gtsSpecPermit
GTS specification field GTS Permit (Bit 7)
uint8_t m_gtsSpecDescCount
GTS specification field Descriptor Count (Bit 0-2)
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
uint32_t GetSerializedSize() const
Get the size of the serialized GTS fields.
uint8_t GetGtsDirectionField() const
Get the GTS Direction Field from the GTS Fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
uint8_t m_gtsDirMask
GTS Direction field Directions Mask (Bit 0-6)
uint8_t GetGtsSpecField() const
Get the GTS Specification Field from the GTS Fields.
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
an EUI-64 address
Definition: mac64-address.h:46
Represent the Pending Address Specification field.
std::array< Mac64Address, 7 > m_extAddrList
Pending Extended Address List.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
uint8_t GetNumExtAddr() const
Get the number of Extended Pending Address indicated in the Pending Address Specification Field.
uint32_t GetSerializedSize() const
Get the size of the serialized Pending Address Fields.
uint8_t GetPndAddrSpecField() const
Get the whole Pending Address Specification Field from the Pending Address Fields.
uint8_t m_pndAddrSpecNumShortAddr
Pending Address Specification field Number of Short Address (Bits 0-2) Pending Address Specification ...
uint8_t m_pndAddrSpecNumExtAddr
Pending Address Specification field Number of Extended Address (Bits 4-6) Pending Address Specificati...
std::array< Mac16Address, 7 > m_shortAddrList
Pending Short Address List.
bool SearchAddress(Mac16Address shortAddr)
Search for the short Pending Address in the Address List.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
void AddAddress(Mac16Address shortAddr)
Add a short Pending Address to the Address List.
uint8_t GetNumShortAddr() const
Get the number of Short Pending Address indicated in the Pending Address Specification Field.
void SetPndAddrSpecField(uint8_t pndAddrSpecField)
Set the whole Pending Address Specification field.
Represent the Superframe Specification information field.
bool m_sspecBatLifeExt
Superframe Specification field Battery Life Extension (Bit 12)
bool m_sspecAssocPermit
Superframe Specification field Association Permit (Bit 15)
uint8_t GetFinalCapSlot() const
Get the the Final CAP Slot.
uint16_t GetSuperframe() const
Get the Superframe specification information field.
bool m_sspecPanCoor
Superframe Specification field PAN Coordinator (Bit 14)
uint8_t m_sspecFnlCapSlot
Superframe Specification field Final CAP slot (Bit 8-11)
void SetAssocPermit(bool assocPermit)
Set the Superframe Specification Association Permit field.
uint8_t m_sspecBcnOrder
Superframe Specification field Beacon Order (Bit 0-3)
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
uint8_t GetBeaconOrder() const
Get the Superframe Specification Beacon Order field.
uint8_t m_sspecSprFrmOrder
Superframe Specification field Superframe Order (Bit 4-7)
bool IsBattLifeExt() const
Check if the Battery Life Extension bit is enabled.
void SetFinalCapSlot(uint8_t capSlot)
Set the superframe specification Final CAP slot field.
void SetSuperframeOrder(uint8_t frmOrder)
Set the superframe specification Superframe Order field.
void SetPanCoor(bool panCoor)
Set the Superframe Specification PAN coordinator field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire superframe specification field.
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
bool IsPanCoor() const
Check if the PAN Coordinator bit is enabled.
bool IsAssocPermit() const
Check if the Association Permit bit is enabled.
uint8_t GetFrameOrder() const
Get the Superframe Specification Frame Order field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
void SetSuperframe(uint16_t superFrm)
Set the whole Superframe Specification Information field.
uint32_t GetSerializedSize() const
Get the size of the serialized Superframe specification information field.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
uint8_t m_gtsDescLength
GTS Descriptor GTS Length (Bit 20-23)
uint8_t m_gtsDescStartSlot
GTS Descriptor GTS Starting Slot(Bit 16-19)