A Discrete-Event Network Simulator
API
lr-wpan-fields.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2019 Ritsumeikan University, Shiga, Japan.
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: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
19 */
20
21
22
23#include "lr-wpan-fields.h"
24#include <ns3/log.h>
25#include <ns3/address-utils.h>
26
27namespace ns3 {
28
30{
31 SetBeaconOrder (15);
34 SetBattLifeExt (false);
35 SetPanCoor (false);
36 SetAssocPermit (false);
37}
38
39void
40SuperframeField::SetSuperframe (uint16_t superFrmSpec)
41{
42 m_sspecBcnOrder = (superFrmSpec) & (0x0F); //Bits 0-3
43 m_sspecSprFrmOrder = (superFrmSpec >> 4) & (0x0F); //Bits 4-7
44 m_sspecFnlCapSlot = (superFrmSpec >> 8) & (0x0F); //Bits 8-11
45 m_sspecBatLifeExt = (superFrmSpec >> 12) & (0x01); //Bit 12
46 //Bit 13 (Reserved)
47 m_sspecPanCoor = (superFrmSpec >> 14) & (0x01); //Bit 14
48 m_sspecAssocPermit = (superFrmSpec >> 15) & (0x01); //Bit 15
49}
50
51void
53{
54 if (bcnOrder > 15)
55 {
56 std::cout << "SuperframeField Beacon Order value must be 15 or less\n";
57 }
58 else
59 {
60 m_sspecBcnOrder = bcnOrder;
61 }
62}
63
64void
66{
67 if (frmOrder > 15)
68 {
69 std::cout << "SuperframeField Frame Order value must be 15 or less\n";
70 }
71 else
72 {
73 m_sspecSprFrmOrder = frmOrder;
74 }
75}
76
77void
79{
80 if (capSlot > 15)
81 {
82 std::cout << "The final slot cannot greater than the slots in a CAP (15)\n";
83 }
84 else
85 {
86 m_sspecFnlCapSlot = capSlot;
87 }
88}
89
90void
92{
93 m_sspecBatLifeExt = battLifeExt;
94}
95
96void
98{
99 m_sspecPanCoor = panCoor;
100}
101
102void
104{
105 m_sspecAssocPermit = assocPermit;
106}
107
108uint8_t
110{
111 return m_sspecBcnOrder;
112}
113
114uint8_t
116{
117 return m_sspecSprFrmOrder;
118}
119
120uint8_t
122{
123 return m_sspecFnlCapSlot;
124}
125
126bool
128{
129 return m_sspecBatLifeExt;
130}
131
132bool
134{
135 return m_sspecPanCoor;
136}
137
138bool
140{
141 return m_sspecAssocPermit;
142}
143
144uint16_t
146{
147 uint16_t superframe;
148
149 superframe = m_sspecBcnOrder & (0x0F); // Bits 0-3
150 superframe |= (m_sspecSprFrmOrder << 4) & (0x0F << 4); // Bits 4-7
151 superframe |= (m_sspecFnlCapSlot << 8) & (0x0F << 8); // Bits 8-11
152 superframe |= (m_sspecBatLifeExt << 12) & (0x01 << 12); // Bit 12
153 // Bit 13 (Reserved)
154 superframe |= (m_sspecPanCoor << 14) & (0x01 << 14); // Bit 14
155 superframe |= (m_sspecAssocPermit << 15) & (0x01 << 15); // Bit 15
156
157 return superframe;
158}
159
162{
163 return 2; // 2 Octets (superframeSpec)
164}
165
168{
170 return i;
171}
172
175{
176 uint16_t superframe = i.ReadLsbtohU16 ();
177 SetSuperframe (superframe);
178
179 return i;
180}
181
182std::ostream &
183operator << (std::ostream &os, const SuperframeField &superframeField)
184{
185 os << " Beacon Order = " << uint32_t (superframeField.GetBeaconOrder ())
186 << ", Frame Order = " << uint32_t (superframeField.GetFrameOrder ())
187 << ", Final CAP slot = " << uint32_t (superframeField.GetFinalCapSlot ())
188 << ", Battery Life Ext = " << bool (superframeField.IsBattLifeExt ())
189 << ", PAN Coordinator = " << bool (superframeField.IsPanCoor ())
190 << ", Association Permit = " << bool (superframeField.IsAssocPermit ());
191 return os;
192}
193
194/***********************************************************
195 * Guaranteed Time Slots (GTS) Fields
196 ***********************************************************/
197
199{
200 // GTS Specification Field
202 m_gtsSpecPermit = 0;
203 // GTS Direction Field
204 m_gtsDirMask = 0;
205}
206
207uint8_t
209{
210 uint8_t gtsSpecField;
211
212 gtsSpecField = m_gtsSpecDescCount & (0x07); // Bits 0-2
213 // Bits 3-6 (Reserved)
214 gtsSpecField |= (m_gtsSpecPermit << 7) & (0x01 << 7); // Bit 7
215
216 return gtsSpecField;
217}
218
219uint8_t
221{
222 uint8_t gtsDirectionField;
223
224 gtsDirectionField = m_gtsDirMask & (0x7F); // Bit 0-6
225 // Bit 7 (Reserved)
226 return gtsDirectionField;
227}
228
229void
231{
232 m_gtsSpecDescCount = (gtsSpec) & (0x07); // Bits 0-2
233 // Bits 3-6 (Reserved)
234 m_gtsSpecPermit = (gtsSpec >> 7) & (0x01); // Bit 7
235}
236
237void
239{
240 m_gtsDirMask = (gtsDir) & (0x7F); // Bits 0-6
241 // Bit 7 (Reserved)
242}
243
244bool
246{
247 return m_gtsSpecPermit;
248}
249
252{
253 uint32_t size;
254
255 size = 1; // 1 octet GTS Specification Field
256 if (m_gtsSpecDescCount > 0)
257 {
258 size += 1; // 1 octet GTS Direction Field
259 size += (m_gtsSpecDescCount * 3); // 3 octets per GTS descriptor
260 }
261
262 return size;
263}
264
267{
269
270 if (m_gtsSpecDescCount > 0)
271 {
272 uint8_t gtsDescStartAndLenght;
274
275 for (int j = 0; j < m_gtsSpecDescCount; j++)
276 {
277 WriteTo (i, m_gtsList[j].m_gtsDescDevShortAddr);
278
279 gtsDescStartAndLenght = (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 (gtsDescStartAndLenght);
283 }
284 }
285 return i;
286}
287
290{
291
292 uint8_t gtsSpecField = i.ReadU8 ();
293 SetGtsSpecField (gtsSpecField);
294
295 if (m_gtsSpecDescCount > 0)
296 {
297 uint8_t gtsDirectionField = i.ReadU8 ();
298 SetGtsDirectionField (gtsDirectionField);
299
300 uint8_t gtsDescStartAndLenght;
301 for (int j = 0; j < m_gtsSpecDescCount; j++)
302 {
303 ReadFrom (i, m_gtsList[j].m_gtsDescDevShortAddr);
304
305 gtsDescStartAndLenght = i.ReadU8 ();
306 m_gtsList[j].m_gtsDescStartSlot = (gtsDescStartAndLenght) & (0x0F);
307 m_gtsList[j].m_gtsDescLength = (gtsDescStartAndLenght >> 4) & (0x0F);
308 }
309 }
310 return i;
311}
312
313std::ostream &
314operator << (std::ostream &os, const GtsFields &gtsFields)
315{
316 os << " GTS specification = " << uint32_t (gtsFields.GetGtsSpecField ())
317 << ", GTS direction = " << uint32_t (gtsFields.GetGtsDirectionField ());
318 return os;
319}
320
321/***********************************************************
322 * Pending Address Fields
323 ***********************************************************/
324
326{
329}
330
331
332uint8_t
334{
336}
337
338
339uint8_t
341{
343}
344
345uint8_t
347{
348 uint8_t pndAddrSpecField;
349
350 pndAddrSpecField = m_pndAddrSpecNumShortAddr & (0x07); // Bits 0-2
351 // Bit 3 (Reserved)
352 pndAddrSpecField |= (m_pndAddrSpecNumExtAddr << 4) & (0x07 << 4); // Bits 4-6
353 // Bit 7 (Reserved)
354
355 return pndAddrSpecField;
356}
357
358void
360{
361 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
362
363 if (totalPendAddr == 7)
364 {
365 return;
366 }
367 else
368 {
371 }
372}
373
374void
376{
377 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
378
379 if (totalPendAddr == 7)
380 {
381 return;
382 }
383 else
384 {
387 }
388}
389
390bool
392{
393 for (int j = 0; j <= m_pndAddrSpecNumShortAddr; j++)
394 {
395 if (shortAddr == m_shortAddrList[j])
396 {
397 return true;
398 }
399 }
400
401 return false;
402}
403
404
405bool
407{
408 for (int j = 0; j <= m_pndAddrSpecNumExtAddr; j++)
409 {
410 if (extAddr == m_extAddrList[j])
411 {
412 return true;
413 }
414 }
415
416 return false;
417}
418
419
420void
422{
423 m_pndAddrSpecNumShortAddr = (pndAddrSpecField) & (0x07); // Bit 0-2
424 // Bit 3
425 m_pndAddrSpecNumExtAddr = (pndAddrSpecField >> 4) & (0x07); // Bit 4-6
426 // Bit 7
427}
428
429
432{
433 uint32_t size;
434
435 size = 1; // 1 octet (Pending Address Specification Field)
436 size = size + (m_pndAddrSpecNumShortAddr * 2); // X octets (Short Pending Address List)
437 size = size + (m_pndAddrSpecNumExtAddr * 8); // X octets (Extended Pending Address List)
438
439 return size;
440}
441
444{
446
447 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
448 {
450 }
451
452 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++ )
453 {
455 }
456
457 return i;
458}
459
462{
463 uint8_t pndAddrSpecField = i.ReadU8 ();
464
465 SetPndAddrSpecField (pndAddrSpecField);
466
467 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
468 {
470 }
471
472 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
473 {
475 }
476
477 return i;
478}
479
480std::ostream &
481operator << (std::ostream &os, const PendingAddrFields &pendingAddrFields)
482{
483 os << " Num. Short Addr = " << uint32_t (pendingAddrFields.GetNumShortAddr ())
484 << ", Num. Ext Addr = " << uint32_t (pendingAddrFields.GetNumExtAddr ());
485 return os;
486}
487
488/***********************************************************
489 * Capability Information Field
490 ***********************************************************/
491
493{
494 m_deviceType = true;
495 m_powerSource = false;
497 m_securityCap = false;
498 m_allocAddr = true;
499}
500
503{
504 return 1;
505}
506
509{
510 uint8_t capability;
511
512 capability = 0;
513 capability = (m_deviceType << 1) & (0x01 << 1);
514 capability |= (m_powerSource << 2) & (0x01 << 2);
515 capability |= (m_receiverOnWhenIdle << 3) & (0x01 << 3);
517 capability |= (m_securityCap << 6) & (0x01 << 6);
518 capability |= (m_allocAddr << 7) & (0x01 << 7);
519 i.WriteU8 (capability);
520 return i;
521}
522
525{
526 uint8_t capability = i.ReadU8 ();
528 m_deviceType = (capability >> 1) & (0x01);
529 m_powerSource = (capability >> 2) & (0x01);
530 m_receiverOnWhenIdle = (capability >> 3) & (0x01);
532 m_securityCap = (capability >> 6) & (0x01);
533 m_allocAddr = (capability >> 7) & (0x01);
534
535 return i;
536}
537
538bool
540{
541 return m_deviceType;
542}
543
544bool
546{
547 return m_powerSource;
548}
549
550bool
552{
554}
555
556
557bool
559{
560 return m_securityCap;
561}
562
563bool
565{
566 return m_allocAddr;
567}
568
569void
571{
572 m_deviceType = devType;
573}
574
575void
577{
578 m_powerSource = pow;
579}
580
581void
583{
584 m_receiverOnWhenIdle = rxIdle;
585}
586
587void
589{
590 m_securityCap = sec;
591}
592
593void
595{
596 m_allocAddr = addrAlloc;
597}
598
607std::ostream &
608operator << (std::ostream &os, const CapabilityField &capabilityField)
609{
610 os << " FFD device capable = " << bool (capabilityField.IsDeviceTypeFfd ())
611 << ", Alternate Power Current Available = " << bool (capabilityField.IsPowSrcAvailable ())
612 << ", Receiver On When Idle = " << bool (capabilityField.IsReceiverOnWhenIdle ())
613 << ", Security Capable = " << bool (capabilityField.IsSecurityCapability ())
614 << ", Coordinator Allocate Short Address = " << bool (capabilityField.IsShortAddrAllocOn ());
615 return os;
616}
617
618} // ns-3 namespace
iterator in a Buffer instance
Definition: buffer.h:99
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:911
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1066
Represent the Capability Information Field.
bool IsDeviceTypeFfd(void) const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
uint32_t GetSerializedSize(void) const
Get the size of the serialized Capability Information Field.
bool m_securityCap
Capability Information Field, Security Capability (bit 6)
bool IsSecurityCapability(void) const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
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 IsShortAddrAllocOn(void) const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
void SetSecurityCap(bool sec)
Set the Security Capability flag in the Capability Information Field.
bool IsPowSrcAvailable(void) 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 m_deviceType
Capability Information Field, Device Type (bit 1)
bool m_powerSource
Capability Information Field, Power Source (bit 2)
bool IsReceiverOnWhenIdle(void) const
True if the device does not disable its receiver to conserve power during idle periods.
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.
uint8_t GetGtsSpecField(void) const
Get the GTS Specification Field from 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)
uint32_t GetSerializedSize(void) const
Get the size of the serialized GTS fields.
uint8_t GetGtsDirectionField(void) const
Get the GTS Direction Field from the GTS Fields.
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.
bool GetGtsPermit(void) const
Get the GTS Specification Permit.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
uint8_t m_gtsDirMask
GTS Direction field Directions Mask (Bit 0-6)
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
an EUI-64 address
Definition: mac64-address.h:44
Represent the Pending Address Specification field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
std::array< Mac16Address, 7 > m_shortAddrList
Pending Short Address List.
uint8_t GetNumExtAddr(void) const
Get the number of Extended Pending Address indicated in the Pending Address Specification Field.
std::array< Mac64Address, 7 > m_extAddrList
Pending Extended Address List.
uint32_t GetSerializedSize(void) const
Get the size of the serialized 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...
bool SearchAddress(Mac16Address shortAddr)
Search for the short Pending Address in the Address List.
uint8_t GetNumShortAddr(void) const
Get the number of Short Pending Address indicated in the Pending Address Specification Field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
uint8_t GetPndAddrSpecField(void) const
Get the whole Pending Address Specification Field from the Pending Address Fields.
void AddAddress(Mac16Address shortAddr)
Add a short Pending Address to the Address List.
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) Superframe Specification field Reserve...
bool m_sspecAssocPermit
Superframe Specification field Association Permit (Bit 15)
bool IsBattLifeExt(void) const
Check if the Battery Life Extension bit is enabled.
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 GetFinalCapSlot(void) const
Get the the Final CAP Slot.
uint8_t m_sspecSprFrmOrder
Superframe Specification field Superframe Order (Bit 4-7)
uint32_t GetSerializedSize(void) const
Get the size of the serialized Superframe specification information field.
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.
uint16_t GetSuperframe(void) const
Get the Superframe specification information 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 IsAssocPermit(void) const
Check if the Association Permit bit is enabled.
uint8_t GetBeaconOrder(void) const
Get the Superframe Specification Beacon Order field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
uint8_t GetFrameOrder(void) const
Get the Superframe Specification Frame Order field.
void SetSuperframe(uint16_t superFrm)
Set the whole Superframe Specification Information field.
bool IsPanCoor(void) const
Check if the PAN Coordinator bit is enabled.
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:139
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)