A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-mac.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 * Authors:
18 * Gary Pei <guangyu.pei@boeing.com>
19 * kwong yin <kwong-sang.yin@boeing.com>
20 * Tom Henderson <thomas.r.henderson@boeing.com>
21 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
22 * Erwan Livolant <erwan.livolant@inria.fr>
23 * Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
24 */
25#include "lr-wpan-mac.h"
26
27#include "lr-wpan-constants.h"
28#include "lr-wpan-csmaca.h"
29#include "lr-wpan-mac-header.h"
31#include "lr-wpan-mac-trailer.h"
32
33#include <ns3/double.h>
34#include <ns3/log.h>
35#include <ns3/node.h>
36#include <ns3/packet.h>
37#include <ns3/random-variable-stream.h>
38#include <ns3/simulator.h>
39#include <ns3/uinteger.h>
40
41#undef NS_LOG_APPEND_CONTEXT
42#define NS_LOG_APPEND_CONTEXT \
43 std::clog << "[address " << m_shortAddress << " | " << m_selfExt << "] ";
44
45namespace ns3
46{
47
48NS_LOG_COMPONENT_DEFINE("LrWpanMac");
50
51TypeId
53{
54 static TypeId tid =
55 TypeId("ns3::LrWpanMac")
57 .SetGroupName("LrWpan")
58 .AddConstructor<LrWpanMac>()
59 .AddAttribute("PanId",
60 "16-bit identifier of the associated PAN",
63 MakeUintegerChecker<uint16_t>())
64 .AddTraceSource("MacTxEnqueue",
65 "Trace source indicating a packet has been "
66 "enqueued in the transaction queue",
68 "ns3::Packet::TracedCallback")
69 .AddTraceSource("MacTxDequeue",
70 "Trace source indicating a packet has was "
71 "dequeued from the transaction queue",
73 "ns3::Packet::TracedCallback")
74 .AddTraceSource("MacIndTxEnqueue",
75 "Trace source indicating a packet has been "
76 "enqueued in the indirect transaction queue",
78 "ns3::Packet::TracedCallback")
79 .AddTraceSource("MacIndTxDequeue",
80 "Trace source indicating a packet has was "
81 "dequeued from the indirect transaction queue",
83 "ns3::Packet::TracedCallback")
84 .AddTraceSource("MacTx",
85 "Trace source indicating a packet has "
86 "arrived for transmission by this device",
88 "ns3::Packet::TracedCallback")
89 .AddTraceSource("MacTxOk",
90 "Trace source indicating a packet has been "
91 "successfully sent",
93 "ns3::Packet::TracedCallback")
94 .AddTraceSource("MacTxDrop",
95 "Trace source indicating a packet has been "
96 "dropped during transmission",
98 "ns3::Packet::TracedCallback")
99 .AddTraceSource("MacIndTxDrop",
100 "Trace source indicating a packet has been "
101 "dropped from the indirect transaction queue"
102 "(The pending transaction list)",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource("MacPromiscRx",
106 "A packet has been received by this device, "
107 "has been passed up from the physical layer "
108 "and is being forwarded up the local protocol stack. "
109 "This is a promiscuous trace,",
111 "ns3::Packet::TracedCallback")
112 .AddTraceSource("MacRx",
113 "A packet has been received by this device, "
114 "has been passed up from the physical layer "
115 "and is being forwarded up the local protocol stack. "
116 "This is a non-promiscuous trace,",
118 "ns3::Packet::TracedCallback")
119 .AddTraceSource("MacRxDrop",
120 "Trace source indicating a packet was received, "
121 "but dropped before being forwarded up the stack",
123 "ns3::Packet::TracedCallback")
124 .AddTraceSource("Sniffer",
125 "Trace source simulating a non-promiscuous "
126 "packet sniffer attached to the device",
128 "ns3::Packet::TracedCallback")
129 .AddTraceSource("PromiscSniffer",
130 "Trace source simulating a promiscuous "
131 "packet sniffer attached to the device",
133 "ns3::Packet::TracedCallback")
134 .AddTraceSource("MacStateValue",
135 "The state of LrWpan Mac",
137 "ns3::TracedValueCallback::LrWpanMacState")
138 .AddTraceSource("MacIncSuperframeStatus",
139 "The period status of the incoming superframe",
141 "ns3::TracedValueCallback::SuperframeState")
142 .AddTraceSource("MacOutSuperframeStatus",
143 "The period status of the outgoing superframe",
145 "ns3::TracedValueCallback::SuperframeState")
146 .AddTraceSource("MacState",
147 "The state of LrWpan Mac",
149 "ns3::LrWpanMac::StateTracedCallback")
150 .AddTraceSource("MacSentPkt",
151 "Trace source reporting some information about "
152 "the sent packet",
154 "ns3::LrWpanMac::SentTracedCallback")
155 .AddTraceSource("IfsEnd",
156 "Trace source reporting the end of an "
157 "Interframe space (IFS)",
159 "ns3::Packet::TracedCallback");
160 return tid;
161}
162
164{
165 // First set the state to a known value, call ChangeMacState to fire trace source.
167
169
172
173 m_macRxOnWhenIdle = true;
174 m_macPanId = 0xffff;
176 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
180 m_macPromiscuousMode = false;
184 m_txPkt = nullptr;
185 m_rxPkt = nullptr;
187 m_ifs = 0;
188
189 m_macLIFSPeriod = 40;
190 m_macSIFSPeriod = 12;
191
192 m_panCoor = false;
193 m_coor = false;
194 m_macBeaconOrder = 15;
196 m_macTransactionPersistenceTime = 500; // 0x01F5
198 m_macAutoRequest = true;
199
202 m_beaconTrackingOn = false;
204
208
211
212 m_maxTxQueueSize = m_txQueue.max_size();
214
215 Ptr<UniformRandomVariable> uniformVar = CreateObject<UniformRandomVariable>();
216 uniformVar->SetAttribute("Min", DoubleValue(0.0));
217 uniformVar->SetAttribute("Max", DoubleValue(255.0));
218 m_macDsn = SequenceNumber8(uniformVar->GetValue());
219 m_macBsn = SequenceNumber8(uniformVar->GetValue());
220 m_macBeaconPayload = nullptr;
222 m_shortAddress = Mac16Address("FF:FF"); // FF:FF = The address is not assigned.
223}
224
226{
227}
228
229void
231{
233 {
234 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
235 }
236 else
237 {
238 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TRX_OFF);
239 }
240
242}
243
244void
246{
247 if (m_csmaCa)
248 {
249 m_csmaCa->Dispose();
250 m_csmaCa = nullptr;
251 }
252 m_txPkt = nullptr;
253
254 for (uint32_t i = 0; i < m_txQueue.size(); i++)
255 {
256 m_txQueue[i]->txQPkt = nullptr;
257 m_txQueue[i]->txQMsduHandle = 0;
258 }
259 m_txQueue.clear();
260
261 for (uint32_t i = 0; i < m_indTxQueue.size(); i++)
262 {
263 m_indTxQueue[i]->txQPkt = nullptr;
264 m_indTxQueue[i]->seqNum = 0;
265 m_indTxQueue[i]->dstExtAddress = nullptr;
266 m_indTxQueue[i]->dstShortAddress = nullptr;
267 }
268 m_indTxQueue.clear();
269
270 m_phy = nullptr;
271 m_mcpsDataConfirmCallback = MakeNullCallback<void, McpsDataConfirmParams>();
272 m_mcpsDataIndicationCallback = MakeNullCallback<void, McpsDataIndicationParams, Ptr<Packet>>();
273 m_mlmeStartConfirmCallback = MakeNullCallback<void, MlmeStartConfirmParams>();
275 MakeNullCallback<void, MlmeBeaconNotifyIndicationParams>();
276 m_mlmeSyncLossIndicationCallback = MakeNullCallback<void, MlmeSyncLossIndicationParams>();
277 m_mlmePollConfirmCallback = MakeNullCallback<void, MlmePollConfirmParams>();
278 m_mlmeScanConfirmCallback = MakeNullCallback<void, MlmeScanConfirmParams>();
279 m_mlmeAssociateConfirmCallback = MakeNullCallback<void, MlmeAssociateConfirmParams>();
280 m_mlmeAssociateIndicationCallback = MakeNullCallback<void, MlmeAssociateIndicationParams>();
281 m_mlmeCommStatusIndicationCallback = MakeNullCallback<void, MlmeCommStatusIndicationParams>();
282 m_mlmeOrphanIndicationCallback = MakeNullCallback<void, MlmeOrphanIndicationParams>();
283
284 m_panDescriptorList.clear();
285 m_energyDetectList.clear();
286 m_unscannedChannels.clear();
287
292
294}
295
296bool
298{
299 return m_macRxOnWhenIdle;
300}
301
302void
304{
305 NS_LOG_FUNCTION(this << rxOnWhenIdle);
306 m_macRxOnWhenIdle = rxOnWhenIdle;
307
309 {
311 {
312 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
313 }
314 else
315 {
316 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TRX_OFF);
317 }
318 }
319}
320
321void
323{
324 NS_LOG_FUNCTION(this << address);
325 m_shortAddress = address;
326}
327
328void
330{
331 NS_LOG_FUNCTION(this << address);
332 m_selfExt = address;
333}
334
337{
338 NS_LOG_FUNCTION(this);
339 return m_shortAddress;
340}
341
344{
345 NS_LOG_FUNCTION(this);
346 return m_selfExt;
347}
348
349void
351{
352 NS_LOG_FUNCTION(this << p);
353
354 McpsDataConfirmParams confirmParams;
355 confirmParams.m_msduHandle = params.m_msduHandle;
356
357 // TODO: We need a drop trace for the case that the packet is too large or the request
358 // parameters are maleformed.
359 // The current tx drop trace is not suitable, because packets dropped using this trace
360 // carry the mac header and footer, while packets being dropped here do not have them.
361
363 m_macDsn++;
364
366 {
367 // Note, this is just testing maximum theoretical frame size per the spec
368 // The frame could still be too large once headers are put on
369 // in which case the phy will reject it instead
370 NS_LOG_ERROR(this << " packet too big: " << p->GetSize());
373 {
374 m_mcpsDataConfirmCallback(confirmParams);
375 }
376 return;
377 }
378
379 if ((params.m_srcAddrMode == NO_PANID_ADDR) && (params.m_dstAddrMode == NO_PANID_ADDR))
380 {
381 NS_LOG_ERROR(this << " Can not send packet with no Address field");
384 {
385 m_mcpsDataConfirmCallback(confirmParams);
386 }
387 return;
388 }
389 switch (params.m_srcAddrMode)
390 {
391 case NO_PANID_ADDR:
392 macHdr.SetSrcAddrMode(params.m_srcAddrMode);
393 macHdr.SetNoPanIdComp();
394 break;
396 NS_ABORT_MSG("Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
397 break;
398 case SHORT_ADDR:
399 macHdr.SetSrcAddrMode(params.m_srcAddrMode);
401 break;
402 case EXT_ADDR:
403 macHdr.SetSrcAddrMode(params.m_srcAddrMode);
405 break;
406 default:
407 NS_LOG_ERROR(this << " Can not send packet with incorrect Source Address mode = "
408 << params.m_srcAddrMode);
411 {
412 m_mcpsDataConfirmCallback(confirmParams);
413 }
414 return;
415 }
416 switch (params.m_dstAddrMode)
417 {
418 case NO_PANID_ADDR:
419 macHdr.SetDstAddrMode(params.m_dstAddrMode);
420 macHdr.SetNoPanIdComp();
421 break;
423 NS_ABORT_MSG("Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
424 break;
425 case SHORT_ADDR:
426 macHdr.SetDstAddrMode(params.m_dstAddrMode);
427 macHdr.SetDstAddrFields(params.m_dstPanId, params.m_dstAddr);
428 break;
429 case EXT_ADDR:
430 macHdr.SetDstAddrMode(params.m_dstAddrMode);
431 macHdr.SetDstAddrFields(params.m_dstPanId, params.m_dstExtAddr);
432 break;
433 default:
434 NS_LOG_ERROR(this << " Can not send packet with incorrect Destination Address mode = "
435 << params.m_dstAddrMode);
438 {
439 m_mcpsDataConfirmCallback(confirmParams);
440 }
441 return;
442 }
443
444 // IEEE 802.15.4-2006 (7.5.6.1)
445 // Src & Dst PANs are identical, PAN compression is ON
446 // only the dst PAN is serialized making the MAC header 2 bytes smaller
447 if ((params.m_dstAddrMode != NO_PANID_ADDR && params.m_srcAddrMode != NO_PANID_ADDR) &&
448 (macHdr.GetDstPanId() == macHdr.GetSrcPanId()))
449 {
450 macHdr.SetPanIdComp();
451 }
452
453 macHdr.SetSecDisable();
454 // extract the first 3 bits in TxOptions
455 int b0 = params.m_txOptions & TX_OPTION_ACK;
456 int b1 = params.m_txOptions & TX_OPTION_GTS;
457 int b2 = params.m_txOptions & TX_OPTION_INDIRECT;
458
459 if (b0 == TX_OPTION_ACK)
460 {
461 // Set AckReq bit only if the destination is not the broadcast address.
462 if (macHdr.GetDstAddrMode() == SHORT_ADDR)
463 {
464 // short address and ACK requested.
465 Mac16Address shortAddr = macHdr.GetShortDstAddr();
466 if (shortAddr.IsBroadcast() || shortAddr.IsMulticast())
467 {
468 NS_LOG_LOGIC("LrWpanMac::McpsDataRequest: requested an ACK on broadcast or "
469 "multicast destination ("
470 << shortAddr << ") - forcefully removing it.");
471 macHdr.SetNoAckReq();
472 params.m_txOptions &= ~uint8_t(TX_OPTION_ACK);
473 }
474 else
475 {
476 macHdr.SetAckReq();
477 }
478 }
479 else
480 {
481 // other address (not short) and ACK requested
482 macHdr.SetAckReq();
483 }
484 }
485 else
486 {
487 macHdr.SetNoAckReq();
488 }
489
490 if (b1 == TX_OPTION_GTS)
491 {
492 // TODO:GTS Transmission
493 }
494 else if (b2 == TX_OPTION_INDIRECT)
495 {
496 // Indirect Tx
497 // A COORDINATOR will save the packet in the pending queue and await for data
498 // requests from its associated devices. The devices are aware of pending data,
499 // from the pending bit information extracted from the received beacon.
500 // A DEVICE must be tracking beacons (MLME-SYNC.request is running) before attempting
501 // request data from the coordinator.
502
503 // Indirect Transmission can only be done by PAN coordinator or coordinators.
505 p->AddHeader(macHdr);
506
507 LrWpanMacTrailer macTrailer;
508 // Calculate FCS if the global attribute ChecksumEnabled is set.
510 {
511 macTrailer.EnableFcs(true);
512 macTrailer.SetFcs(p);
513 }
514 p->AddTrailer(macTrailer);
515
516 NS_LOG_ERROR(this << " Indirect transmissions not currently supported");
517 // Note: The current Pending transaction list should work for indirect transmissions.
518 // However, this is not tested yet. For now, we block the use of indirect transmissions.
519 // TODO: Save packet in the Pending Transaction list.
520 // EnqueueInd (p);
521 }
522 else
523 {
524 // Direct Tx
525 // From this point the packet will be pushed to a Tx queue and immediately
526 // use a slotted (beacon-enabled) or unslotted (nonbeacon-enabled) version of CSMA/CA
527 // before sending the packet, depending on whether it has previously
528 // received a valid beacon or not.
529
530 p->AddHeader(macHdr);
531
532 LrWpanMacTrailer macTrailer;
533 // Calculate FCS if the global attribute ChecksumEnabled is set.
535 {
536 macTrailer.EnableFcs(true);
537 macTrailer.SetFcs(p);
538 }
539 p->AddTrailer(macTrailer);
540
541 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
542 txQElement->txQMsduHandle = params.m_msduHandle;
543 txQElement->txQPkt = p;
544 EnqueueTxQElement(txQElement);
545 CheckQueue();
546 }
547}
548
549void
551{
552 NS_LOG_FUNCTION(this);
554
555 MlmeStartConfirmParams confirmParams;
556
557 if (GetShortAddress() == Mac16Address("ff:ff"))
558 {
559 NS_LOG_ERROR(this << " Invalid MAC short address");
560 confirmParams.m_status = MLMESTART_NO_SHORT_ADDRESS;
562 {
563 m_mlmeStartConfirmCallback(confirmParams);
564 }
565 return;
566 }
567
568 if ((params.m_bcnOrd > 15) || (params.m_sfrmOrd > params.m_bcnOrd))
569 {
572 {
573 m_mlmeStartConfirmCallback(confirmParams);
574 }
575 NS_LOG_ERROR(this << "Incorrect superframe order or beacon order.");
576 return;
577 }
578
579 // Mark primitive as pending and save the start params while the new page and channel is set.
581 m_startParams = params;
582
583 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
584 pibAttr->phyCurrentPage = m_startParams.m_logChPage;
585 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentPage, pibAttr);
586}
587
588void
590{
591 NS_LOG_FUNCTION(this);
592
593 MlmeScanConfirmParams confirmParams;
594 confirmParams.m_scanType = params.m_scanType;
595 confirmParams.m_chPage = params.m_chPage;
596
598 {
600 {
601 confirmParams.m_status = MLMESCAN_SCAN_IN_PROGRESS;
602 m_mlmeScanConfirmCallback(confirmParams);
603 }
604 NS_LOG_ERROR(this << " A channel scan is already in progress");
605 return;
606 }
607
608 if (params.m_scanDuration > 14 || params.m_scanType > MLMESCAN_ORPHAN)
609 {
611 {
612 confirmParams.m_status = MLMESCAN_INVALID_PARAMETER;
613 m_mlmeScanConfirmCallback(confirmParams);
614 }
615 NS_LOG_ERROR(this << "Invalid scan duration or unsupported scan type");
616 return;
617 }
618 // Temporary store macPanId and set macPanId to 0xFFFF to accept all beacons.
620 m_macPanId = 0xFFFF;
621
622 m_panDescriptorList.clear();
623 m_energyDetectList.clear();
624 m_unscannedChannels.clear();
625
626 // TODO: stop beacon transmission
627
628 // Cancel any ongoing CSMA/CA operations and set to unslotted mode for scan
629 m_csmaCa->Cancel();
635 m_csmaCa->SetUnSlottedCsmaCa();
636
638
639 // Mark primitive as pending and save the scan params while the new page and/or channel is set.
640 m_scanParams = params;
642
643 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
644 pibAttr->phyCurrentPage = params.m_chPage;
645 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentPage, pibAttr);
646}
647
648void
650{
651 NS_LOG_FUNCTION(this);
652
653 // Association is typically preceded by beacon reception and a MLME-SCAN.request, therefore,
654 // the values of the Associate.request params usually come from the information
655 // obtained from those operations.
657 m_associateParams = params;
658 bool invalidRequest = false;
659
660 if (params.m_coordPanId == 0xffff)
661 {
662 invalidRequest = true;
663 }
664
665 if (!invalidRequest && params.m_coordAddrMode == SHORT_ADDR)
666 {
667 if (params.m_coordShortAddr == Mac16Address("ff:ff") ||
668 params.m_coordShortAddr == Mac16Address("ff:fe"))
669 {
670 invalidRequest = true;
671 }
672 }
673 else if (!invalidRequest && params.m_coordAddrMode == EXT_ADDR)
674 {
675 if (params.m_coordExtAddr == Mac64Address("ff:ff:ff:ff:ff:ff:ff:ff") ||
676 params.m_coordExtAddr == Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed"))
677 {
678 invalidRequest = true;
679 }
680 }
681
682 if (invalidRequest)
683 {
686 NS_LOG_ERROR(this << " Invalid PAN id in Association request");
688 {
689 MlmeAssociateConfirmParams confirmParams;
690 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
692 m_mlmeAssociateConfirmCallback(confirmParams);
693 }
694 }
695 else
696 {
697 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
698 pibAttr->phyCurrentPage = params.m_chPage;
699 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentPage, pibAttr);
700 }
701}
702
703void
705{
706 // the primitive is no longer pending (channel & page are set)
708 // As described in IEEE 802.15.4-2011 (Section 5.1.3.1)
711 {
713 }
714 else
715 {
718 }
719
721}
722
723void
725{
726 // Associate Short Address (m_assocShortAddr)
727 // FF:FF = Association Request failed
728 // FF:FE = The association request is accepted, but the device should use its extended address
729 // Other = The assigned short address by the coordinator
730
731 NS_LOG_FUNCTION(this);
732
734 m_macDsn++;
735 LrWpanMacTrailer macTrailer;
736 Ptr<Packet> commandPacket = Create<Packet>();
737
738 // Mac header Assoc. Response Comm. See 802.15.4-2011 (Section 5.3.2.1)
741 macHdr.SetPanIdComp();
742 macHdr.SetDstAddrFields(m_macPanId, params.m_extDevAddr);
743 macHdr.SetSrcAddrFields(0xffff, GetExtendedAddress());
744
746 macPayload.SetShortAddr(params.m_assocShortAddr);
747 switch (params.m_status)
748 {
751 break;
754 break;
757 break;
759 NS_LOG_ERROR("Error, Associated without address");
760 break;
762 NS_LOG_ERROR("Error, device not associated");
763 break;
764 }
765
766 macHdr.SetSecDisable();
767 macHdr.SetAckReq();
768
769 commandPacket->AddHeader(macPayload);
770 commandPacket->AddHeader(macHdr);
771
772 // Calculate FCS if the global attribute ChecksumEnabled is set.
774 {
775 macTrailer.EnableFcs(true);
776 macTrailer.SetFcs(commandPacket);
777 }
778
779 commandPacket->AddTrailer(macTrailer);
780
781 // Save packet in the Pending Transaction list.
782 EnqueueInd(commandPacket);
783}
784
785void
787{
788 NS_LOG_FUNCTION(this);
789 // Mac header Coordinator realigment Command
790 // See 802.15.4-2011 (Section 6.2.7.2)
792 m_macDsn++;
793 LrWpanMacTrailer macTrailer;
794 Ptr<Packet> commandPacket = Create<Packet>();
795 macHdr.SetPanIdComp();
797 macHdr.SetDstAddrFields(0xffff, params.m_orphanAddr);
798
801 macHdr.SetSrcAddrFields(m_macPanId, Mac16Address("FF:FF"));
802
803 macHdr.SetFrameVer(0x01);
804 macHdr.SetSecDisable();
805 macHdr.SetAckReq();
806
808 macPayload.SetPanId(m_macPanId);
810 macPayload.SetChannel(m_phy->GetCurrentChannelNum());
811 macPayload.SetPage(m_phy->GetCurrentPage());
812
813 if (params.m_assocMember)
814 {
815 // The orphan device was associated with the coordinator
816
817 // Either FF:FE for extended address mode
818 // or the short address assigned by the coord.
819 macPayload.SetShortAddr(params.m_shortAddr);
820 }
821 else
822 {
823 // The orphan device was NOT associated with the coordinator
824 macPayload.SetShortAddr(Mac16Address("FF:FF"));
825 }
826
827 commandPacket->AddHeader(macPayload);
828 commandPacket->AddHeader(macHdr);
829
830 // Calculate FCS if the global attribute ChecksumEnabled is set.
832 {
833 macTrailer.EnableFcs(true);
834 macTrailer.SetFcs(commandPacket);
835 }
836
837 commandPacket->AddTrailer(macTrailer);
838
839 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
840 txQElement->txQPkt = commandPacket;
841 EnqueueTxQElement(txQElement);
842 CheckQueue();
843}
844
845void
847{
848 NS_LOG_FUNCTION(this);
849 NS_ASSERT(params.m_logCh <= 26 && m_macPanId != 0xffff);
850
851 auto symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
852 // change phy current logical channel
853 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
854 pibAttr->phyCurrentChannel = params.m_logCh;
855 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentChannel, pibAttr);
856
857 // Enable Phy receiver
858 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
859
860 uint64_t searchSymbols;
861 Time searchBeaconTime;
862
864 {
866 }
867
868 if (params.m_trackBcn)
869 {
871 // search for a beacon for a time = incomingSuperframe symbols + 960 symbols
872 searchSymbols =
874 searchBeaconTime = Seconds((double)searchSymbols / symbolRate);
875 m_beaconTrackingOn = true;
877 Simulator::Schedule(searchBeaconTime, &LrWpanMac::BeaconSearchTimeout, this);
878 }
879 else
880 {
881 m_beaconTrackingOn = false;
882 }
883}
884
885void
887{
888 NS_LOG_FUNCTION(this);
889
891 m_macBsn++;
892
894
895 Ptr<Packet> beaconPacket = Create<Packet>();
896 // TODO: complete poll request (part of indirect transmissions)
897 NS_FATAL_ERROR(this << " Poll request currently not supported");
898}
899
900void
902{
903 MlmeSetConfirmParams confirmParams;
904 confirmParams.m_status = MLMESET_SUCCESS;
905
906 switch (id)
907 {
908 case macBeaconPayload:
909 if (attribute->macBeaconPayload->GetSize() > lrwpan::aMaxBeaconPayloadLength)
910 {
911 confirmParams.m_status = MLMESET_INVALID_PARAMETER;
912 }
913 else
914 {
915 m_macBeaconPayload = attribute->macBeaconPayload;
916 m_macBeaconPayloadLength = attribute->macBeaconPayload->GetSize();
917 }
918 break;
920 confirmParams.m_status = MLMESET_INVALID_PARAMETER;
921 break;
922 case macShortAddress:
923 m_shortAddress = attribute->macShortAddress;
924 break;
926 confirmParams.m_status = MLMESET_READ_ONLY;
927 break;
928 case macPanId:
930 break;
931 default:
932 // TODO: Add support for setting other attributes
934 break;
935 }
936
938 {
939 confirmParams.id = id;
940 m_mlmeSetConfirmCallback(confirmParams);
941 }
942}
943
944void
946{
948 Ptr<LrWpanMacPibAttributes> attributes = Create<LrWpanMacPibAttributes>();
949
950 switch (id)
951 {
952 case macBeaconPayload:
953 attributes->macBeaconPayload = m_macBeaconPayload;
954 break;
956 attributes->macBeaconPayloadLength = m_macBeaconPayloadLength;
957 break;
958 case macShortAddress:
959 attributes->macShortAddress = m_shortAddress;
960 break;
962 attributes->macExtendedAddress = m_selfExt;
963 break;
964 case macPanId:
965 attributes->macPanId = m_macPanId;
966 break;
967 default:
969 break;
970 }
971
973 {
974 m_mlmeGetConfirmCallback(status, id, attributes);
975 }
976}
977
978void
980{
981 NS_LOG_FUNCTION(this);
983
985 m_macBsn++;
986 BeaconPayloadHeader macPayload;
987 Ptr<Packet> beaconPacket;
988 LrWpanMacTrailer macTrailer;
989
990 if (m_macBeaconPayload == nullptr)
991 {
992 beaconPacket = Create<Packet>();
993 }
994 else
995 {
996 beaconPacket = m_macBeaconPayload;
997 }
998
1000 macHdr.SetDstAddrFields(GetPanId(), Mac16Address("ff:ff"));
1001
1002 // see IEEE 802.15.4-2011 Section 5.1.2.4
1003 if (GetShortAddress() == Mac16Address("ff:fe"))
1004 {
1007 }
1008 else
1009 {
1012 }
1013
1014 macHdr.SetSecDisable();
1015 macHdr.SetNoAckReq();
1016
1018 macPayload.SetGtsFields(GetGtsFields());
1020
1021 beaconPacket->AddHeader(macPayload);
1022 beaconPacket->AddHeader(macHdr);
1023
1024 // Calculate FCS if the global attribute ChecksumEnabled is set.
1026 {
1027 macTrailer.EnableFcs(true);
1028 macTrailer.SetFcs(beaconPacket);
1029 }
1030
1031 beaconPacket->AddTrailer(macTrailer);
1032
1033 // Set the Beacon packet to be transmitted
1034 m_txPkt = beaconPacket;
1035
1036 if (m_csmaCa->IsSlottedCsmaCa())
1037 {
1039 NS_LOG_DEBUG("Outgoing superframe Active Portion (Beacon + CAP + CFP): "
1040 << m_superframeDuration << " symbols");
1041 }
1042
1044 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
1045}
1046
1047void
1049{
1050 NS_LOG_FUNCTION(this);
1051
1053 m_macDsn++;
1054 LrWpanMacTrailer macTrailer;
1055 Ptr<Packet> commandPacket = Create<Packet>();
1056
1057 // Beacon Request Command Mac header values See IEEE 802.15.4-2011 (Section 5.3.7)
1058 macHdr.SetNoPanIdComp();
1061
1062 // Not associated PAN, broadcast dst address
1063 macHdr.SetDstAddrFields(0xFFFF, Mac16Address("FF:FF"));
1064
1065 macHdr.SetSecDisable();
1066 macHdr.SetNoAckReq();
1067
1068 CommandPayloadHeader macPayload;
1070
1071 commandPacket->AddHeader(macPayload);
1072 commandPacket->AddHeader(macHdr);
1073
1074 // Calculate FCS if the global attribute ChecksumEnabled is set.
1076 {
1077 macTrailer.EnableFcs(true);
1078 macTrailer.SetFcs(commandPacket);
1079 }
1080
1081 commandPacket->AddTrailer(macTrailer);
1082
1083 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
1084 txQElement->txQPkt = commandPacket;
1085 EnqueueTxQElement(txQElement);
1086 CheckQueue();
1087}
1088
1089void
1091{
1093 m_macDsn++;
1094 LrWpanMacTrailer macTrailer;
1095 Ptr<Packet> commandPacket = Create<Packet>();
1096
1097 // See IEEE 802.15.4-2011 (5.3.6)
1098 macHdr.SetPanIdComp();
1099
1101 macHdr.SetSrcAddrFields(0xFFFF, GetExtendedAddress());
1102
1104 macHdr.SetDstAddrFields(0xFFFF, Mac16Address("FF:FF"));
1105
1106 macHdr.SetSecDisable();
1107 macHdr.SetNoAckReq();
1108
1109 CommandPayloadHeader macPayload;
1111
1112 commandPacket->AddHeader(macPayload);
1113 commandPacket->AddHeader(macHdr);
1114
1115 // Calculate FCS if the global attribute ChecksumEnabled is set.
1117 {
1118 macTrailer.EnableFcs(true);
1119 macTrailer.SetFcs(commandPacket);
1120 }
1121
1122 commandPacket->AddTrailer(macTrailer);
1123
1124 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
1125 txQElement->txQPkt = commandPacket;
1126 EnqueueTxQElement(txQElement);
1127 CheckQueue();
1128}
1129
1130void
1132{
1133 NS_LOG_FUNCTION(this);
1134
1136 m_macDsn++;
1137 LrWpanMacTrailer macTrailer;
1138 Ptr<Packet> commandPacket = Create<Packet>();
1139
1140 // Assoc. Req. Comm. Mac header values See IEEE 802.15.4-2011 (Section 5.3.1.1)
1142 macHdr.SetSrcAddrFields(0xffff, GetExtendedAddress());
1143
1145 {
1148 }
1149 else
1150 {
1153 }
1154
1155 macHdr.SetSecDisable();
1156 macHdr.SetAckReq();
1157
1160
1161 commandPacket->AddHeader(macPayload);
1162 commandPacket->AddHeader(macHdr);
1163
1164 // Calculate FCS if the global attribute ChecksumEnabled is set.
1166 {
1167 macTrailer.EnableFcs(true);
1168 macTrailer.SetFcs(commandPacket);
1169 }
1170
1171 commandPacket->AddTrailer(macTrailer);
1172
1173 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
1174 txQElement->txQPkt = commandPacket;
1175 EnqueueTxQElement(txQElement);
1176 CheckQueue();
1177}
1178
1179void
1181{
1182 // See IEEE 802.15.4-2011 (Section 5.3.5)
1183 // This command can be sent for 3 different situations:
1184 // a) In response to a beacon indicating that there is data for the device.
1185 // b) Triggered by MLME-POLL.request.
1186 // c) To follow an ACK of an Association Request command and continue the associate process.
1187
1188 // TODO: Implementation of a) and b) will be done when Indirect transmissions are fully
1189 // supported.
1190 // for now, only case c) is considered.
1191
1192 NS_LOG_FUNCTION(this);
1193
1195 m_macDsn++;
1196 LrWpanMacTrailer macTrailer;
1197 Ptr<Packet> commandPacket = Create<Packet>();
1198
1199 // Mac Header values (Section 5.3.5)
1201 macHdr.SetSrcAddrFields(0xffff, m_selfExt);
1202
1203 if (m_macCoordShortAddress == Mac16Address("ff:fe"))
1204 {
1207 }
1208 else
1209 {
1212 }
1213
1214 macHdr.SetSecDisable();
1215 macHdr.SetAckReq();
1216
1218
1219 commandPacket->AddHeader(macPayload);
1220 commandPacket->AddHeader(macHdr);
1221
1222 // Calculate FCS if the global attribute ChecksumEnabled is set.
1224 {
1225 macTrailer.EnableFcs(true);
1226 macTrailer.SetFcs(commandPacket);
1227 }
1228
1229 commandPacket->AddTrailer(macTrailer);
1230
1231 // Set the Command packet to be transmitted
1232 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
1233 txQElement->txQPkt = commandPacket;
1234 EnqueueTxQElement(txQElement);
1235 CheckQueue();
1236}
1237
1238void
1240{
1241 LrWpanMacHeader receivedMacHdr;
1242 rxDataReqPkt->RemoveHeader(receivedMacHdr);
1243 CommandPayloadHeader receivedMacPayload;
1244 rxDataReqPkt->RemoveHeader(receivedMacPayload);
1245
1247
1248 Ptr<IndTxQueueElement> indTxQElement = Create<IndTxQueueElement>();
1249 bool elementFound;
1250 elementFound = DequeueInd(receivedMacHdr.GetExtSrcAddr(), indTxQElement);
1251 if (elementFound)
1252 {
1253 Ptr<TxQueueElement> txQElement = Create<TxQueueElement>();
1254 txQElement->txQPkt = indTxQElement->txQPkt;
1255 m_txQueue.emplace_back(txQElement);
1256 }
1257 else
1258 {
1259 NS_LOG_DEBUG("Requested element not found in pending list");
1260 }
1261}
1262
1263void
1265{
1266 // Association response command was not received, return to default values.
1267 m_macPanId = 0xffff;
1269 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
1270
1272 {
1273 MlmeAssociateConfirmParams confirmParams;
1274 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
1275 confirmParams.m_status = MLMEASSOC_NO_DATA;
1276 m_mlmeAssociateConfirmCallback(confirmParams);
1277 }
1278}
1279
1280void
1282{
1283 NS_LOG_FUNCTION(this);
1284 // The primitive is no longer pending (Channel & Page have been set)
1286
1287 if (m_startParams.m_coorRealgn) // Coordinator Realignment
1288 {
1289 // TODO: Send realignment request command frame in CSMA/CA
1290 NS_LOG_ERROR(this << " Coordinator realignment request not supported");
1291 return;
1292 }
1293 else
1294 {
1296 {
1297 m_panCoor = true;
1298 }
1299
1300 m_coor = true;
1302
1303 NS_ASSERT(m_startParams.m_PanId != 0xffff);
1304
1306 if (m_macBeaconOrder == 15)
1307 {
1308 // Non-beacon enabled PAN
1309 // Cancel any ongoing events and CSMA-CA process
1311 m_fnlCapSlot = 15;
1312 m_beaconInterval = 0;
1313
1314 m_csmaCa->Cancel();
1323
1324 m_csmaCa->SetUnSlottedCsmaCa();
1325
1327 {
1328 MlmeStartConfirmParams confirmParams;
1329 confirmParams.m_status = MLMESTART_SUCCESS;
1330 m_mlmeStartConfirmCallback(confirmParams);
1331 }
1332
1333 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
1334 }
1335 else
1336 {
1338 m_csmaCa->SetBatteryLifeExtension(m_startParams.m_battLifeExt);
1339
1340 m_csmaCa->SetSlottedCsmaCa();
1341
1342 // TODO: Calculate the real Final CAP slot (requires GTS implementation)
1343 // FinalCapSlot = Superframe duration slots - CFP slots.
1344 // In the current implementation the value of the final cap slot is equal to
1345 // the total number of possible slots in the superframe (15).
1346 m_fnlCapSlot = 15;
1347
1350 m_superframeDuration = (static_cast<uint32_t>(1 << m_macSuperframeOrder)) *
1352
1353 // TODO: change the beacon sending according to the startTime parameter (if not PAN
1354 // coordinator)
1355
1357 }
1358 }
1359}
1360
1361void
1363{
1364 NS_LOG_FUNCTION(this);
1365
1367
1368 bool channelFound = false;
1369
1370 for (int i = m_channelScanIndex; i <= 26; i++)
1371 {
1373 {
1374 channelFound = true;
1375 break;
1376 }
1378 }
1379
1380 if (channelFound)
1381 {
1382 // Switch to the next channel in the list and restart scan
1383 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
1384 pibAttr->phyCurrentChannel = m_channelScanIndex;
1385 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentChannel, pibAttr);
1386 }
1387 else
1388 {
1389 // All channels in the list scan completed.
1390 // Return variables to the values before the scan and return the status to the next layer.
1392 m_macPanIdScan = 0;
1393
1394 // TODO: restart beacon transmissions that were active before the beginning of the scan
1395 // (i.e when a coordinator perform a scan and it was already transmitting beacons)
1396 MlmeScanConfirmParams confirmParams;
1397 confirmParams.m_chPage = m_scanParams.m_chPage;
1398 confirmParams.m_scanType = m_scanParams.m_scanType;
1399 confirmParams.m_energyDetList = {};
1400 confirmParams.m_unscannedCh = m_unscannedChannels;
1401 confirmParams.m_resultListSize = m_panDescriptorList.size();
1402
1403 // See IEEE 802.15.4-2011, Table 31 (panDescriptorList value on macAutoRequest)
1404 // and Section 6.2.10.2
1405 switch (confirmParams.m_scanType)
1406 {
1407 case MLMESCAN_PASSIVE:
1408 if (m_macAutoRequest)
1409 {
1410 confirmParams.m_panDescList = m_panDescriptorList;
1411 }
1412 confirmParams.m_status = MLMESCAN_SUCCESS;
1413 break;
1414 case MLMESCAN_ACTIVE:
1415 if (m_panDescriptorList.empty())
1416 {
1417 confirmParams.m_status = MLMESCAN_NO_BEACON;
1418 }
1419 else
1420 {
1421 if (m_macAutoRequest)
1422 {
1423 confirmParams.m_panDescList = m_panDescriptorList;
1424 }
1425 confirmParams.m_status = MLMESCAN_SUCCESS;
1426 }
1427 break;
1428 case MLMESCAN_ORPHAN:
1429 confirmParams.m_panDescList = {};
1430 confirmParams.m_status = MLMESCAN_NO_BEACON;
1431 confirmParams.m_resultListSize = 0;
1432 // The device lost track of the coordinator and was unable
1433 // to locate it, disassociate from the network.
1434 m_macPanId = 0xffff;
1435 m_shortAddress = Mac16Address("FF:FF");
1437 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
1438 break;
1439 default:
1440 NS_LOG_ERROR(this << " Invalid scan type");
1441 }
1442
1445 m_scanParams = {};
1446
1448 {
1449 m_mlmeScanConfirmCallback(confirmParams);
1450 }
1451 }
1452}
1453
1454void
1456{
1457 NS_LOG_FUNCTION(this);
1458 // Add the results of channel energy scan to the detectList
1460 m_maxEnergyLevel = 0;
1461
1463
1464 bool channelFound = false;
1465 for (int i = m_channelScanIndex; i <= 26; i++)
1466 {
1468 {
1469 channelFound = true;
1470 break;
1471 }
1473 }
1474
1475 if (channelFound)
1476 {
1477 // switch to the next channel in the list and restart scan
1478 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
1479 pibAttr->phyCurrentChannel = m_channelScanIndex;
1480 m_phy->PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier::phyCurrentChannel, pibAttr);
1481 }
1482 else
1483 {
1484 // Scan on all channels on the list completed
1485 // Return to the MAC values previous to start of the first scan.
1487 m_macPanIdScan = 0;
1488
1489 // TODO: restart beacon transmissions that were active before the beginning of the scan
1490 // (i.e when a coordinator perform a scan and it was already transmitting beacons)
1491
1492 // All channels scanned, report success
1493 MlmeScanConfirmParams confirmParams;
1494 confirmParams.m_status = MLMESCAN_SUCCESS;
1495 confirmParams.m_chPage = m_phy->GetCurrentPage();
1496 confirmParams.m_scanType = m_scanParams.m_scanType;
1497 confirmParams.m_energyDetList = m_energyDetectList;
1498 confirmParams.m_resultListSize = m_energyDetectList.size();
1499
1502 m_scanParams = {};
1503
1505 {
1506 m_mlmeScanConfirmCallback(confirmParams);
1507 }
1508 }
1509}
1510
1511void
1513{
1514 uint32_t activeSlot;
1515 uint64_t capDuration;
1516 Time endCapTime;
1517 uint64_t symbolRate;
1518
1519 symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
1520
1521 if (superframeType == OUTGOING)
1522 {
1524 activeSlot = m_superframeDuration / 16;
1525 capDuration = activeSlot * (m_fnlCapSlot + 1);
1526 endCapTime = Seconds((double)capDuration / symbolRate);
1527 // Obtain the end of the CAP by adjust the time it took to send the beacon
1528 endCapTime -= (Simulator::Now() - m_macBeaconTxTime);
1529
1530 NS_LOG_DEBUG("Outgoing superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1531 << " symbols (" << endCapTime.As(Time::S)
1532 << ")");
1533 NS_LOG_DEBUG("Active Slots duration " << activeSlot << " symbols");
1534
1535 m_capEvent =
1537 }
1538 else
1539 {
1541 activeSlot = m_incomingSuperframeDuration / 16;
1542 capDuration = activeSlot * (m_incomingFnlCapSlot + 1);
1543 endCapTime = Seconds((double)capDuration / symbolRate);
1544 // Obtain the end of the CAP by adjust the time it took to receive the beacon
1545 endCapTime -= (Simulator::Now() - m_macBeaconRxTime);
1546
1547 NS_LOG_DEBUG("Incoming superframe CAP duration " << (endCapTime.GetSeconds() * symbolRate)
1548 << " symbols (" << endCapTime.As(Time::S)
1549 << ")");
1550 NS_LOG_DEBUG("Active Slots duration " << activeSlot << " symbols");
1551
1552 m_capEvent =
1554 }
1555
1556 CheckQueue();
1557}
1558
1559void
1561{
1562 uint32_t activeSlot;
1563 uint64_t cfpDuration;
1564 Time endCfpTime;
1565 uint64_t symbolRate;
1566
1567 symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
1568
1569 if (superframeType == INCOMING)
1570 {
1571 activeSlot = m_incomingSuperframeDuration / 16;
1572 cfpDuration = activeSlot * (15 - m_incomingFnlCapSlot);
1573 endCfpTime = Seconds((double)cfpDuration / symbolRate);
1574 if (cfpDuration > 0)
1575 {
1577 }
1578
1579 NS_LOG_DEBUG("Incoming superframe CFP duration " << cfpDuration << " symbols ("
1580 << endCfpTime.As(Time::S) << ")");
1581
1584 this,
1586 }
1587 else
1588 {
1589 activeSlot = m_superframeDuration / 16;
1590 cfpDuration = activeSlot * (15 - m_fnlCapSlot);
1591 endCfpTime = Seconds((double)cfpDuration / symbolRate);
1592
1593 if (cfpDuration > 0)
1594 {
1596 }
1597
1598 NS_LOG_DEBUG("Outgoing superframe CFP duration " << cfpDuration << " symbols ("
1599 << endCfpTime.As(Time::S) << ")");
1600
1601 m_cfpEvent = Simulator::Schedule(endCfpTime,
1603 this,
1605 }
1606 // TODO: Start transmit or receive GTS here.
1607}
1608
1609void
1611{
1612 uint64_t inactiveDuration;
1613 Time endInactiveTime;
1614 uint64_t symbolRate;
1615
1616 symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
1617
1618 if (superframeType == INCOMING)
1619 {
1621 endInactiveTime = Seconds((double)inactiveDuration / symbolRate);
1622
1623 if (inactiveDuration > 0)
1624 {
1626 }
1627
1628 NS_LOG_DEBUG("Incoming superframe Inactive Portion duration "
1629 << inactiveDuration << " symbols (" << endInactiveTime.As(Time::S) << ")");
1630 m_beaconEvent = Simulator::Schedule(endInactiveTime, &LrWpanMac::AwaitBeacon, this);
1631 }
1632 else
1633 {
1634 inactiveDuration = m_beaconInterval - m_superframeDuration;
1635 endInactiveTime = Seconds((double)inactiveDuration / symbolRate);
1636
1637 if (inactiveDuration > 0)
1638 {
1640 }
1641
1642 NS_LOG_DEBUG("Outgoing superframe Inactive Portion duration "
1643 << inactiveDuration << " symbols (" << endInactiveTime.As(Time::S) << ")");
1645 }
1646}
1647
1648void
1650{
1652
1653 // TODO: If the device waits more than the expected time to receive the beacon (wait = 46
1654 // symbols for default beacon size)
1655 // it should continue with the start of the incoming CAP even if it did not receive the
1656 // beacon. At the moment, the start of the incoming CAP is only triggered if the beacon is
1657 // received. See MLME-SyncLoss for details.
1658}
1659
1660void
1662{
1663 auto symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
1664
1666 {
1667 MlmeSyncLossIndicationParams syncLossParams;
1668 // syncLossParams.m_logCh =
1669 syncLossParams.m_lossReason = MLMESYNCLOSS_BEACON_LOST;
1670 syncLossParams.m_panId = m_macPanId;
1671 m_mlmeSyncLossIndicationCallback(syncLossParams);
1672
1673 m_beaconTrackingOn = false;
1674 m_numLostBeacons = 0;
1675 }
1676 else
1677 {
1679
1680 // Search for one more beacon
1681 uint64_t searchSymbols;
1682 Time searchBeaconTime;
1683 searchSymbols =
1685 searchBeaconTime = Seconds((double)searchSymbols / symbolRate);
1687 Simulator::Schedule(searchBeaconTime, &LrWpanMac::BeaconSearchTimeout, this);
1688 }
1689}
1690
1691void
1693{
1694 NS_LOG_FUNCTION(this);
1695 // Pull a packet from the queue and start sending if we are not already sending.
1697 {
1698 if (m_csmaCa->IsUnSlottedCsmaCa() || (m_outSuperframeStatus == CAP && m_coor) ||
1700 {
1701 // check MAC is not in a IFS
1702 if (!m_ifsEvent.IsRunning())
1703 {
1704 Ptr<TxQueueElement> txQElement = m_txQueue.front();
1705 m_txPkt = txQElement->txQPkt;
1706
1709 }
1710 }
1711 }
1712}
1713
1716{
1717 SuperframeField sfrmSpec;
1718
1721 sfrmSpec.SetFinalCapSlot(m_fnlCapSlot);
1722
1723 if (m_csmaCa->GetBatteryLifeExtension())
1724 {
1725 sfrmSpec.SetBattLifeExt(true);
1726 }
1727
1728 if (m_panCoor)
1729 {
1730 sfrmSpec.SetPanCoor(true);
1731 }
1732
1733 // used to associate devices via Beacons
1735 {
1736 sfrmSpec.SetAssocPermit(true);
1737 }
1738
1739 return sfrmSpec;
1740}
1741
1744{
1745 GtsFields gtsFields;
1746
1747 // TODO: Logic to populate the GTS Fields from local information here
1748
1749 return gtsFields;
1750}
1751
1754{
1755 PendingAddrFields pndAddrFields;
1756
1757 // TODO: Logic to populate the Pending Address Fields from local information here
1758 return pndAddrFields;
1759}
1760
1761void
1763{
1764 m_csmaCa = csmaCa;
1765}
1766
1767void
1769{
1770 m_phy = phy;
1771}
1772
1775{
1776 return m_phy;
1777}
1778
1779void
1781{
1783}
1784
1785void
1787{
1789}
1790
1791void
1793{
1795}
1796
1797void
1799{
1801}
1802
1803void
1805{
1807}
1808
1809void
1811{
1813}
1814
1815void
1817{
1819}
1820
1821void
1823{
1825}
1826
1827void
1829{
1831}
1832
1833void
1835{
1837}
1838
1839void
1841{
1843}
1844
1845void
1847{
1849}
1850
1851void
1853{
1855}
1856
1857void
1859{
1862 NS_LOG_FUNCTION(this << psduLength << p << (uint16_t)lqi);
1863
1864 bool acceptFrame;
1865
1866 // from sec 7.5.6.2 Reception and rejection, Std802.15.4-2006
1867 // level 1 filtering, test FCS field and reject if frame fails
1868 // level 2 filtering if promiscuous mode pass frame to higher layer otherwise perform level 3
1869 // filtering level 3 filtering accept frame if Frame type and version is not reserved, and if
1870 // there is a dstPanId then dstPanId=m_macPanId or broadcastPanId, and if there is a
1871 // shortDstAddr then shortDstAddr =shortMacAddr or broadcastAddr, and if beacon frame then
1872 // srcPanId = m_macPanId if only srcAddr field in Data or Command frame,accept frame if
1873 // srcPanId=m_macPanId
1874
1875 Ptr<Packet> originalPkt = p->Copy(); // because we will strip headers
1876 auto symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false); // symbols per second
1877 m_promiscSnifferTrace(originalPkt);
1878
1879 m_macPromiscRxTrace(originalPkt);
1880 // XXX no rejection tracing (to macRxDropTrace) being performed below
1881
1882 LrWpanMacTrailer receivedMacTrailer;
1883 p->RemoveTrailer(receivedMacTrailer);
1885 {
1886 receivedMacTrailer.EnableFcs(true);
1887 }
1888
1889 // level 1 filtering
1890 if (!receivedMacTrailer.CheckFcs(p))
1891 {
1892 m_macRxDropTrace(originalPkt);
1893 }
1894 else
1895 {
1896 LrWpanMacHeader receivedMacHdr;
1897 p->RemoveHeader(receivedMacHdr);
1898
1900 params.m_dsn = receivedMacHdr.GetSeqNum();
1901 params.m_mpduLinkQuality = lqi;
1902 params.m_srcPanId = receivedMacHdr.GetSrcPanId();
1903 params.m_srcAddrMode = receivedMacHdr.GetSrcAddrMode();
1904 switch (params.m_srcAddrMode)
1905 {
1906 case SHORT_ADDR:
1907 params.m_srcAddr = receivedMacHdr.GetShortSrcAddr();
1908 break;
1909 case EXT_ADDR:
1910 params.m_srcExtAddr = receivedMacHdr.GetExtSrcAddr();
1911 break;
1912 default:
1913 break;
1914 }
1915 params.m_dstPanId = receivedMacHdr.GetDstPanId();
1916 params.m_dstAddrMode = receivedMacHdr.GetDstAddrMode();
1917 switch (params.m_dstAddrMode)
1918 {
1919 case SHORT_ADDR:
1920 params.m_dstAddr = receivedMacHdr.GetShortDstAddr();
1921 break;
1922 case EXT_ADDR:
1923 params.m_dstExtAddr = receivedMacHdr.GetExtDstAddr();
1924 break;
1925 default:
1926 break;
1927 }
1928
1930 {
1931 // level 2 filtering
1932 if (receivedMacHdr.GetDstAddrMode() == SHORT_ADDR)
1933 {
1934 NS_LOG_DEBUG("Packet from " << params.m_srcAddr);
1935 NS_LOG_DEBUG("Packet to " << params.m_dstAddr);
1936 }
1937 else if (receivedMacHdr.GetDstAddrMode() == EXT_ADDR)
1938 {
1939 NS_LOG_DEBUG("Packet from " << params.m_srcExtAddr);
1940 NS_LOG_DEBUG("Packet to " << params.m_dstExtAddr);
1941 }
1942
1943 // TODO: Fix here, this should trigger different Indication Callbacks
1944 // depending the type of frame received (data,command, beacon)
1946 {
1947 NS_LOG_DEBUG("promiscuous mode, forwarding up");
1949 }
1950 else
1951 {
1952 NS_LOG_ERROR(this << " Data Indication Callback not initialized");
1953 }
1954 }
1955 else
1956 {
1957 // level 3 frame filtering
1958 acceptFrame = (receivedMacHdr.GetType() != LrWpanMacHeader::LRWPAN_MAC_RESERVED);
1959
1960 if (acceptFrame)
1961 {
1962 acceptFrame = (receivedMacHdr.GetFrameVer() <= 1);
1963 }
1964
1965 if (acceptFrame && (receivedMacHdr.GetDstAddrMode() > 1))
1966 {
1967 // Accept frame if one of the following is true:
1968
1969 // 1) Have the same macPanId
1970 // 2) Is Message to all PANs
1971 // 3) Is a beacon or command frame and the macPanId is not present (bootstrap)
1972 acceptFrame = ((receivedMacHdr.GetDstPanId() == m_macPanId ||
1973 receivedMacHdr.GetDstPanId() == 0xffff) ||
1974 (m_macPanId == 0xffff && receivedMacHdr.IsBeacon())) ||
1975 (m_macPanId == 0xffff && receivedMacHdr.IsCommand());
1976 }
1977
1978 if (acceptFrame && (receivedMacHdr.GetDstAddrMode() == SHORT_ADDR))
1979 {
1980 if (receivedMacHdr.GetShortDstAddr() == m_shortAddress)
1981 {
1982 // unicast, for me
1983 acceptFrame = true;
1984 }
1985 else if (receivedMacHdr.GetShortDstAddr().IsBroadcast() ||
1986 receivedMacHdr.GetShortDstAddr().IsMulticast())
1987 {
1988 // Broadcast or multicast.
1989 // Discard broadcast/multicast with the ACK bit set.
1990 acceptFrame = !receivedMacHdr.IsAckReq();
1991 }
1992 else
1993 {
1994 acceptFrame = false;
1995 }
1996 }
1997
1998 if (acceptFrame && (receivedMacHdr.GetDstAddrMode() == EXT_ADDR))
1999 {
2000 acceptFrame = (receivedMacHdr.GetExtDstAddr() == m_selfExt);
2001 }
2002
2003 if (acceptFrame && m_scanEvent.IsRunning())
2004 {
2005 if (!receivedMacHdr.IsBeacon())
2006 {
2007 acceptFrame = false;
2008 }
2009 }
2010 else if (acceptFrame && m_scanOrphanEvent.IsRunning())
2011 {
2012 if (!receivedMacHdr.IsCommand())
2013 {
2014 acceptFrame = false;
2015 }
2016 }
2017 else if (m_scanEnergyEvent.IsRunning())
2018 {
2019 // Reject any frames if energy scan is running
2020 acceptFrame = false;
2021 }
2022
2023 // Check device is panCoor with association permit when receiving Association Request
2024 // Commands.
2025 // TODO:: Simple coordinators should also be able to receive it (currently only Pan
2026 // Coordinators are checked)
2027 if (acceptFrame && (receivedMacHdr.IsCommand() && receivedMacHdr.IsAckReq()))
2028 {
2029 CommandPayloadHeader receivedMacPayload;
2030 p->PeekHeader(receivedMacPayload);
2031
2032 if (receivedMacPayload.GetCommandFrameType() ==
2035 {
2036 acceptFrame = false;
2037 }
2038
2039 // Although ACKs do not use CSMA to to be transmitted, we need to make sure
2040 // that the transmitted ACK will not collide with the transmission of a beacon
2041 // when beacon-enabled mode is running in the coordinator.
2042 if (acceptFrame && (m_csmaCa->IsSlottedCsmaCa() && m_capEvent.IsRunning()))
2043 {
2044 Time timeLeftInCap = Simulator::GetDelayLeft(m_capEvent);
2045 uint64_t ackSymbols = lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() +
2046 ceil(6 * m_phy->GetPhySymbolsPerOctet());
2047 Time ackTime = Seconds((double)ackSymbols / symbolRate);
2048
2049 if (ackTime >= timeLeftInCap)
2050 {
2051 NS_LOG_DEBUG("Command frame received but not enough time to transmit ACK "
2052 "before the end of CAP ");
2053 acceptFrame = false;
2054 }
2055 }
2056 }
2057
2058 if (acceptFrame)
2059 {
2060 m_macRxTrace(originalPkt);
2061 // \todo: What should we do if we receive a frame while waiting for an ACK?
2062 // Especially if this frame has the ACK request bit set, should we reply with
2063 // an ACK, possibly missing the pending ACK?
2064
2065 // If the received frame is a frame with the ACK request bit set, we immediately
2066 // send back an ACK. If we are currently waiting for a pending ACK, we assume the
2067 // ACK was lost and trigger a retransmission after sending the ACK.
2068 if ((receivedMacHdr.IsData() || receivedMacHdr.IsCommand()) &&
2069 receivedMacHdr.IsAckReq() &&
2070 !(receivedMacHdr.GetDstAddrMode() == SHORT_ADDR &&
2071 (receivedMacHdr.GetShortDstAddr().IsBroadcast() ||
2072 receivedMacHdr.GetShortDstAddr().IsMulticast())))
2073 {
2074 // If this is a data or mac command frame, which is not a broadcast or
2075 // multicast, with ack req set, generate and send an ack frame. If there is a
2076 // CSMA medium access in progress we cancel the medium access for sending the
2077 // ACK frame. A new transmission attempt will be started after the ACK was send.
2079 {
2082 }
2083 else if (m_lrWpanMacState == MAC_CSMA)
2084 {
2085 // \todo: If we receive a packet while doing CSMA/CA, should we drop the
2086 // packet because of channel busy,
2087 // or should we restart CSMA/CA for the packet after sending the ACK?
2088 // Currently we simply restart CSMA/CA after sending the ACK.
2089 NS_LOG_DEBUG("Received a packet with ACK required while in CSMA. Cancel "
2090 "current CSMA-CA");
2091 m_csmaCa->Cancel();
2092 }
2093 // Cancel any pending MAC state change, ACKs have higher priority.
2096
2097 // save received packet and LQI to process the appropriate indication/response
2098 // after sending ACK (PD-DATA.confirm)
2099 m_rxPkt = originalPkt->Copy();
2100 m_lastRxFrameLqi = lqi;
2101
2102 // LOG Commands with ACK required.
2103 CommandPayloadHeader receivedMacPayload;
2104 p->PeekHeader(receivedMacPayload);
2105 switch (receivedMacPayload.GetCommandFrameType())
2106 {
2108 NS_LOG_DEBUG("Data Request Command Received; processing ACK");
2109 break;
2111 NS_LOG_DEBUG("Association Request Command Received; processing ACK");
2112 break;
2114 m_assocResCmdWaitTimeout.Cancel(); // cancel event to a lost assoc resp cmd.
2115 NS_LOG_DEBUG("Association Response Command Received; processing ACK");
2116 break;
2117 default:
2118 break;
2119 }
2120
2122 this,
2123 receivedMacHdr.GetSeqNum());
2124 }
2125
2126 if (receivedMacHdr.GetDstAddrMode() == SHORT_ADDR)
2127 {
2128 NS_LOG_DEBUG("Packet from " << params.m_srcAddr);
2129 NS_LOG_DEBUG("Packet to " << params.m_dstAddr);
2130 }
2131 else if (receivedMacHdr.GetDstAddrMode() == EXT_ADDR)
2132 {
2133 NS_LOG_DEBUG("Packet from " << params.m_srcExtAddr);
2134 NS_LOG_DEBUG("Packet to " << params.m_dstExtAddr);
2135 }
2136
2137 if (receivedMacHdr.IsBeacon())
2138 {
2139 // The received beacon size in symbols
2140 // Beacon = 5 bytes Sync Header (SHR) + 1 byte PHY header (PHR) + PSDU (default
2141 // 17 bytes)
2142 m_rxBeaconSymbols = m_phy->GetPhySHRDuration() +
2143 1 * m_phy->GetPhySymbolsPerOctet() +
2144 (originalPkt->GetSize() * m_phy->GetPhySymbolsPerOctet());
2145
2146 // The start of Rx beacon time and start of the Incoming superframe Active
2147 // Period
2149 Simulator::Now() - Seconds(double(m_rxBeaconSymbols) / symbolRate);
2150
2151 NS_LOG_DEBUG("Beacon Received; forwarding up (m_macBeaconRxTime: "
2152 << m_macBeaconRxTime.As(Time::S) << ")");
2153
2154 BeaconPayloadHeader receivedMacPayload;
2155 p->RemoveHeader(receivedMacPayload);
2156
2157 // Fill the PAN descriptor
2158 PanDescriptor panDescriptor;
2159
2160 if (receivedMacHdr.GetSrcAddrMode() == SHORT_ADDR)
2161 {
2162 panDescriptor.m_coorAddrMode = SHORT_ADDR;
2163 panDescriptor.m_coorShortAddr = receivedMacHdr.GetShortSrcAddr();
2164 }
2165 else
2166 {
2167 panDescriptor.m_coorAddrMode = EXT_ADDR;
2168 panDescriptor.m_coorExtAddr = receivedMacHdr.GetExtSrcAddr();
2169 }
2170
2171 panDescriptor.m_coorPanId = receivedMacHdr.GetSrcPanId();
2172 panDescriptor.m_gtsPermit = receivedMacPayload.GetGtsFields().GetGtsPermit();
2173 panDescriptor.m_linkQuality = lqi;
2174 panDescriptor.m_logChPage = m_phy->GetCurrentPage();
2175 panDescriptor.m_logCh = m_phy->GetCurrentChannelNum();
2176 panDescriptor.m_superframeSpec = receivedMacPayload.GetSuperframeSpecField();
2177 panDescriptor.m_timeStamp = m_macBeaconRxTime;
2178
2179 // Process beacon when device belongs to a PAN (associated device)
2180 if (!m_scanEvent.IsRunning() && m_macPanId == receivedMacHdr.GetDstPanId())
2181 {
2182 // We need to make sure to cancel any possible ongoing unslotted CSMA/CA
2183 // operations when receiving a beacon (e.g. Those taking place at the
2184 // beginning of an Association).
2185 m_csmaCa->Cancel();
2186
2187 SuperframeField incomingSuperframe;
2188 incomingSuperframe = receivedMacPayload.GetSuperframeSpecField();
2189
2190 m_incomingBeaconOrder = incomingSuperframe.GetBeaconOrder();
2191 m_incomingSuperframeOrder = incomingSuperframe.GetFrameOrder();
2192 m_incomingFnlCapSlot = incomingSuperframe.GetFinalCapSlot();
2193
2195 (static_cast<uint32_t>(1 << m_incomingBeaconOrder)) *
2199 (static_cast<uint32_t>(1 << m_incomingSuperframeOrder));
2200
2201 if (incomingSuperframe.IsBattLifeExt())
2202 {
2203 m_csmaCa->SetBatteryLifeExtension(true);
2204 }
2205 else
2206 {
2207 m_csmaCa->SetBatteryLifeExtension(false);
2208 }
2209
2210 if (m_incomingBeaconOrder < 15 && !m_csmaCa->IsSlottedCsmaCa())
2211 {
2212 m_csmaCa->SetSlottedCsmaCa();
2213 }
2214
2215 // TODO: get Incoming frame GTS Fields here
2216
2217 // Begin CAP on the current device using info from the Incoming superframe
2218 NS_LOG_DEBUG("Incoming superframe Active Portion (Beacon + CAP + CFP): "
2219 << m_incomingSuperframeDuration << " symbols");
2221 this,
2225 }
2226 else if (!m_scanEvent.IsRunning() && m_macPanId == 0xFFFF)
2227 {
2228 NS_LOG_DEBUG(this << " Device not associated, cannot process beacon");
2229 }
2230
2231 if (m_macAutoRequest)
2232 {
2233 if (p->GetSize() > 0)
2234 {
2236 {
2237 // The beacon contains payload, send the beacon notification.
2239 beaconParams.m_bsn = receivedMacHdr.GetSeqNum();
2240 beaconParams.m_panDescriptor = panDescriptor;
2241 beaconParams.m_sduLength = p->GetSize();
2242 beaconParams.m_sdu = p;
2244 }
2245 }
2246
2247 if (m_scanEvent.IsRunning())
2248 {
2249 // Channel scanning is taking place, save only unique PAN descriptors
2250 bool descriptorExists = false;
2251
2252 for (const auto& descriptor : m_panDescriptorList)
2253 {
2254 if (descriptor.m_coorAddrMode == SHORT_ADDR)
2255 {
2256 // Found a coordinator in PAN descriptor list with the same
2257 // registered short address
2258 descriptorExists =
2259 (descriptor.m_coorShortAddr ==
2260 panDescriptor.m_coorShortAddr &&
2261 descriptor.m_coorPanId == panDescriptor.m_coorPanId);
2262 }
2263 else
2264 {
2265 // Found a coordinator in PAN descriptor list with the same
2266 // registered extended address
2267 descriptorExists =
2268 (descriptor.m_coorExtAddr == panDescriptor.m_coorExtAddr &&
2269 descriptor.m_coorPanId == panDescriptor.m_coorPanId);
2270 }
2271
2272 if (descriptorExists)
2273 {
2274 break;
2275 }
2276 }
2277
2278 if (!descriptorExists)
2279 {
2280 m_panDescriptorList.emplace_back(panDescriptor);
2281 }
2282 return;
2283 }
2284 else if (m_trackingEvent.IsRunning())
2285 {
2286 // check if MLME-SYNC.request was previously issued and running
2287 // Sync. is necessary to handle pending messages (indirect
2288 // transmissions)
2290 m_numLostBeacons = 0;
2291
2293 {
2294 // if tracking option is on keep tracking the next beacon
2295 uint64_t searchSymbols;
2296 Time searchBeaconTime;
2297
2298 searchSymbols =
2299 (static_cast<uint64_t>(1 << m_incomingBeaconOrder)) +
2301 searchBeaconTime =
2302 Seconds(static_cast<double>(searchSymbols / symbolRate));
2304 Simulator::Schedule(searchBeaconTime,
2306 this);
2307 }
2308
2309 PendingAddrFields pndAddrFields;
2310 pndAddrFields = receivedMacPayload.GetPndAddrFields();
2311
2312 // TODO: Ignore pending data, and do not send data command request if
2313 // the address is in the GTS list.
2314 // If the address is not in the GTS list, then check if the
2315 // address is in the short address pending list or in the extended
2316 // address pending list and send a data command request.
2317 }
2318 }
2319 else
2320 {
2321 // m_macAutoRequest is FALSE
2322 // Data command request are not send, only the beacon notification.
2323 // see IEEE 802.15.4-2011 Section 6.2.4.1
2325 {
2327 beaconParams.m_bsn = receivedMacHdr.GetSeqNum();
2328 beaconParams.m_panDescriptor = panDescriptor;
2329 beaconParams.m_sduLength = p->GetSize();
2330 beaconParams.m_sdu = p;
2332 }
2333 }
2334 }
2335 else if (receivedMacHdr.IsCommand())
2336 {
2337 // Handle the reception of frame commands that do not require ACK
2338 // (i.e. Beacon Request, Orphan notification, Coordinator Realigment)
2339 CommandPayloadHeader receivedMacPayload;
2340 p->PeekHeader(receivedMacPayload);
2341
2342 switch (receivedMacPayload.GetCommandFrameType())
2343 {
2345 if (m_csmaCa->IsUnSlottedCsmaCa() && m_coor)
2346 {
2347 SendOneBeacon();
2348 }
2349 else
2350 {
2351 m_macRxDropTrace(originalPkt);
2352 }
2353 break;
2356 {
2357 if (m_coor)
2358 {
2359 MlmeOrphanIndicationParams orphanParams;
2360 orphanParams.m_orphanAddr = receivedMacHdr.GetExtSrcAddr();
2361 m_mlmeOrphanIndicationCallback(orphanParams);
2362 }
2363 }
2364 break;
2367 {
2368 // Coordinator located, no need to keep scanning other channels
2370
2371 m_macPanIdScan = 0;
2374
2375 // Update the device information with the received information
2376 // from the Coordinator Realigment command.
2377 m_macPanId = receivedMacPayload.GetPanId();
2378 m_shortAddress = receivedMacPayload.GetShortAddr();
2379 m_macCoordExtendedAddress = receivedMacHdr.GetExtSrcAddr();
2380 m_macCoordShortAddress = receivedMacPayload.GetCoordShortAddr();
2381
2383 {
2384 MlmeScanConfirmParams confirmParams;
2385 confirmParams.m_scanType = m_scanParams.m_scanType;
2386 confirmParams.m_chPage = m_scanParams.m_chPage;
2387 confirmParams.m_status = MLMESCAN_SUCCESS;
2388 m_mlmeScanConfirmCallback(confirmParams);
2389 }
2390 m_scanParams = {};
2391 }
2392 // TODO: handle Coordinator realignment when not
2393 // used during an orphan scan.
2394 break;
2395 default:
2396 m_macRxDropTrace(originalPkt);
2397 break;
2398 }
2399 }
2400 else if (receivedMacHdr.IsData() && !m_mcpsDataIndicationCallback.IsNull())
2401 {
2402 // If it is a data frame, push it up the stack.
2403 NS_LOG_DEBUG("Data Packet is for me; forwarding up");
2405 }
2406 else if (receivedMacHdr.IsAcknowledgment() && m_txPkt &&
2408 {
2409 LrWpanMacHeader peekedMacHdr;
2410 m_txPkt->PeekHeader(peekedMacHdr);
2411 // If it is an ACK with the expected sequence number, finish the transmission
2412 if (receivedMacHdr.GetSeqNum() == peekedMacHdr.GetSeqNum())
2413 {
2416
2417 // TODO: check if the IFS is the correct size after ACK.
2418 Time ifsWaitTime = Seconds((double)GetIfsSize() / symbolRate);
2419
2420 // We received an ACK to a command
2421 if (peekedMacHdr.IsCommand())
2422 {
2423 // check the original sent command frame which belongs to this received
2424 // ACK
2425 Ptr<Packet> pkt = m_txPkt->Copy();
2426 LrWpanMacHeader macHdr;
2427 CommandPayloadHeader cmdPayload;
2428 pkt->RemoveHeader(macHdr);
2429 pkt->RemoveHeader(cmdPayload);
2430
2431 switch (cmdPayload.GetCommandFrameType())
2432 {
2434 double symbolRate = m_phy->GetDataOrSymbolRate(false);
2435 Time waitTime = Seconds(static_cast<double>(m_macResponseWaitTime) /
2436 symbolRate);
2437 if (!m_beaconTrackingOn)
2438 {
2440 Simulator::Schedule(waitTime,
2442 this);
2443 }
2444 else
2445 {
2446 // TODO: The data must be extracted by the coordinator within
2447 // macResponseWaitTime on timeout, MLME-ASSOCIATE.confirm is set
2448 // with status NO_DATA, and this should trigger the cancellation
2449 // of the beacon tracking (MLME-SYNC.request trackBeacon
2450 // =FALSE)
2451 }
2452 break;
2453 }
2454
2456 // MLME-comm-status.Indication generated as a result of an
2457 // association response command, therefore src and dst address use
2458 // extended mode (see 5.3.2.1)
2460 {
2461 MlmeCommStatusIndicationParams commStatusParams;
2462 commStatusParams.m_panId = m_macPanId;
2463 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
2464 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
2465 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
2466 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
2467 commStatusParams.m_status =
2469 m_mlmeCommStatusIndicationCallback(commStatusParams);
2470 }
2471 // Remove element from Pending Transaction List
2473 break;
2474 }
2475
2477 // Schedule an event in case the Association Response Command never
2478 // reached this device during an association process.
2479 double symbolRate = m_phy->GetDataOrSymbolRate(false);
2480 Time waitTime = Seconds(
2481 static_cast<double>(m_assocRespCmdWaitTime) / symbolRate);
2483 Simulator::Schedule(waitTime,
2485 this);
2486
2488 {
2489 MlmePollConfirmParams pollConfirmParams;
2490 pollConfirmParams.m_status =
2492 m_mlmePollConfirmCallback(pollConfirmParams);
2493 }
2494 break;
2495 }
2496
2498 // ACK of coordinator realigment commands is not specified in the
2499 // standard, in here, we assume they are required as in other
2500 // commands.
2502 {
2503 MlmeCommStatusIndicationParams commStatusParams;
2504 commStatusParams.m_panId = m_macPanId;
2505 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
2506 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
2507 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
2508 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
2509 commStatusParams.m_status =
2511 m_mlmeCommStatusIndicationCallback(commStatusParams);
2512 }
2513 }
2514
2515 default: {
2516 // TODO: add response to other request commands (e.g. Orphan)
2517 break;
2518 }
2519 }
2520 }
2521 else
2522 {
2524 {
2525 Ptr<TxQueueElement> txQElement = m_txQueue.front();
2526 McpsDataConfirmParams confirmParams;
2527 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
2528 confirmParams.m_status = IEEE_802_15_4_SUCCESS;
2529 m_mcpsDataConfirmCallback(confirmParams);
2530 }
2531 }
2532
2533 // Ack was successfully received, wait for the Interframe Space (IFS) and
2534 // then proceed
2539 m_ifsEvent = Simulator::Schedule(ifsWaitTime,
2541 this,
2542 ifsWaitTime);
2543 }
2544 else
2545 {
2546 // If it is an ACK with an unexpected sequence number, mark the current
2547 // transmission as failed and start a retransmit. (cf 7.5.6.4.3)
2549 if (!PrepareRetransmission())
2550 {
2553 this,
2554 MAC_IDLE);
2555 }
2556 else
2557 {
2560 this,
2561 MAC_CSMA);
2562 }
2563 }
2564 }
2565 }
2566 else
2567 {
2568 m_macRxDropTrace(originalPkt);
2569 }
2570 }
2571 }
2572}
2573
2574void
2576{
2577 NS_LOG_FUNCTION(this << static_cast<uint32_t>(seqno));
2578
2580
2581 // Generate a corresponding ACK Frame.
2583 LrWpanMacTrailer macTrailer;
2584 Ptr<Packet> ackPacket = Create<Packet>(0);
2585 ackPacket->AddHeader(macHdr);
2586 // Calculate FCS if the global attribute ChecksumEnabled is set.
2588 {
2589 macTrailer.EnableFcs(true);
2590 macTrailer.SetFcs(ackPacket);
2591 }
2592 ackPacket->AddTrailer(macTrailer);
2593
2594 // Enqueue the ACK packet for further processing
2595 // when the transmitter is activated.
2596 m_txPkt = ackPacket;
2597
2598 // Switch transceiver to TX mode. Proceed sending the Ack on confirm.
2600 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
2601}
2602
2603void
2605{
2606 if (m_txQueue.size() < m_maxTxQueueSize)
2607 {
2608 m_txQueue.emplace_back(txQElement);
2609 m_macTxEnqueueTrace(txQElement->txQPkt);
2610 }
2611 else
2612 {
2614 {
2615 McpsDataConfirmParams confirmParams;
2616 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
2618 m_mcpsDataConfirmCallback(confirmParams);
2619 }
2620 NS_LOG_DEBUG("TX Queue with size " << m_txQueue.size() << " is full, dropping packet");
2621 m_macTxDropTrace(txQElement->txQPkt);
2622 }
2623}
2624
2625void
2627{
2628 Ptr<TxQueueElement> txQElement = m_txQueue.front();
2629 Ptr<const Packet> p = txQElement->txQPkt;
2630 m_numCsmacaRetry += m_csmaCa->GetNB() + 1;
2631
2632 Ptr<Packet> pkt = p->Copy();
2633 LrWpanMacHeader hdr;
2634 pkt->RemoveHeader(hdr);
2635 if (!hdr.GetShortDstAddr().IsBroadcast() && !hdr.GetShortDstAddr().IsMulticast())
2636 {
2638 }
2639
2640 txQElement->txQPkt = nullptr;
2641 txQElement = nullptr;
2642 m_txQueue.pop_front();
2643 m_txPkt = nullptr;
2644 m_retransmission = 0;
2645 m_numCsmacaRetry = 0;
2647}
2648
2649void
2651{
2652 NS_LOG_FUNCTION(this);
2653
2654 // TODO: If we are a PAN coordinator and this was an indirect transmission,
2655 // we will not initiate a retransmission. Instead we wait for the data
2656 // being extracted after a new data request command.
2657 if (!PrepareRetransmission())
2658 {
2660 }
2661 else
2662 {
2664 }
2665}
2666
2667void
2669{
2670 auto symbolRate = (uint64_t)m_phy->GetDataOrSymbolRate(false);
2671 Time lifsTime = Seconds((double)m_macLIFSPeriod / symbolRate);
2672 Time sifsTime = Seconds((double)m_macSIFSPeriod / symbolRate);
2673
2674 if (ifsTime == lifsTime)
2675 {
2676 NS_LOG_DEBUG("LIFS of " << m_macLIFSPeriod << " symbols (" << ifsTime.As(Time::S)
2677 << ") completed ");
2678 }
2679 else if (ifsTime == sifsTime)
2680 {
2681 NS_LOG_DEBUG("SIFS of " << m_macSIFSPeriod << " symbols (" << ifsTime.As(Time::S)
2682 << ") completed ");
2683 }
2684 else
2685 {
2686 NS_LOG_DEBUG("Unknown IFS size (" << ifsTime.As(Time::S) << ") completed ");
2687 }
2688
2689 m_macIfsEndTrace(ifsTime);
2690 CheckQueue();
2691}
2692
2693bool
2695{
2696 NS_LOG_FUNCTION(this);
2697
2698 // Max retransmissions reached without receiving ACK,
2699 // send the proper indication/confirmation
2700 // according to the frame type and call drop trace.
2702 {
2703 LrWpanMacHeader peekedMacHdr;
2704 m_txPkt->PeekHeader(peekedMacHdr);
2705
2706 if (peekedMacHdr.IsCommand())
2707 {
2709
2710 Ptr<Packet> pkt = m_txPkt->Copy();
2711 LrWpanMacHeader macHdr;
2712 CommandPayloadHeader cmdPayload;
2713 pkt->RemoveHeader(macHdr);
2714 pkt->RemoveHeader(cmdPayload);
2715
2716 switch (cmdPayload.GetCommandFrameType())
2717 {
2719 m_macPanId = 0xffff;
2721 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
2724 m_csmaCa->SetUnSlottedCsmaCa();
2727
2729 {
2730 MlmeAssociateConfirmParams confirmParams;
2731 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
2732 confirmParams.m_status = MLMEASSOC_NO_ACK;
2733 m_mlmeAssociateConfirmCallback(confirmParams);
2734 }
2735 break;
2736 }
2738 // IEEE 802.15.4-2006 (Section 7.1.3.3.3 and 7.1.8.2.3)
2740 {
2741 MlmeCommStatusIndicationParams commStatusParams;
2742 commStatusParams.m_panId = m_macPanId;
2743 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
2744 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
2745 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
2746 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
2748 m_mlmeCommStatusIndicationCallback(commStatusParams);
2749 }
2751 break;
2752 }
2754 // IEEE 802.15.4-2006 (Section 7.1.16.1.3)
2755 m_macPanId = 0xffff;
2757 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
2760 m_csmaCa->SetUnSlottedCsmaCa();
2763
2765 {
2766 MlmePollConfirmParams pollConfirmParams;
2768 m_mlmePollConfirmCallback(pollConfirmParams);
2769 }
2770 break;
2771 }
2772 default: {
2773 // TODO: Specify other indications according to other commands
2774 break;
2775 }
2776 }
2777 }
2778 else
2779 {
2780 // Maximum number of retransmissions has been reached.
2781 // remove the copy of the DATA packet that was just sent
2782 Ptr<TxQueueElement> txQElement = m_txQueue.front();
2783 m_macTxDropTrace(txQElement->txQPkt);
2785 {
2786 McpsDataConfirmParams confirmParams;
2787 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
2788 confirmParams.m_status = IEEE_802_15_4_NO_ACK;
2789 m_mcpsDataConfirmCallback(confirmParams);
2790 }
2791 }
2792
2794 return false;
2795 }
2796 else
2797 {
2799 m_numCsmacaRetry += m_csmaCa->GetNB() + 1;
2800 // Start next CCA process for this packet.
2801 return true;
2802 }
2803}
2804
2805void
2807{
2808 Ptr<IndTxQueueElement> indTxQElement = Create<IndTxQueueElement>();
2809 LrWpanMacHeader peekedMacHdr;
2810 p->PeekHeader(peekedMacHdr);
2811
2812 PurgeInd();
2813
2814 NS_ASSERT(peekedMacHdr.GetDstAddrMode() == SHORT_ADDR ||
2815 peekedMacHdr.GetDstAddrMode() == EXT_ADDR);
2816
2817 if (peekedMacHdr.GetDstAddrMode() == SHORT_ADDR)
2818 {
2819 indTxQElement->dstShortAddress = peekedMacHdr.GetShortDstAddr();
2820 }
2821 else
2822 {
2823 indTxQElement->dstExtAddress = peekedMacHdr.GetExtDstAddr();
2824 }
2825
2826 indTxQElement->seqNum = peekedMacHdr.GetSeqNum();
2827
2828 // See IEEE 802.15.4-2006, Table 86
2829 uint32_t unit = 0; // The persistence time in symbols
2830 if (m_macBeaconOrder == 15)
2831 {
2832 // Non-beacon enabled mode
2834 }
2835 else
2836 {
2837 // Beacon-enabled mode
2838 unit = ((static_cast<uint32_t>(1) << m_macBeaconOrder) * lrwpan::aBaseSuperframeDuration) *
2840 }
2841
2842 if (m_indTxQueue.size() < m_maxIndTxQueueSize)
2843 {
2844 double symbolRate = m_phy->GetDataOrSymbolRate(false);
2845 Time expireTime = Seconds(unit / symbolRate);
2846 expireTime += Simulator::Now();
2847 indTxQElement->expireTime = expireTime;
2848 indTxQElement->txQPkt = p;
2849 m_indTxQueue.emplace_back(indTxQElement);
2851 }
2852 else
2853 {
2855 {
2856 LrWpanMacHeader peekedMacHdr;
2857 indTxQElement->txQPkt->PeekHeader(peekedMacHdr);
2858 MlmeCommStatusIndicationParams commStatusParams;
2859 commStatusParams.m_panId = m_macPanId;
2860 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
2861 commStatusParams.m_srcExtAddr = peekedMacHdr.GetExtSrcAddr();
2862 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
2863 commStatusParams.m_dstExtAddr = peekedMacHdr.GetExtDstAddr();
2865 m_mlmeCommStatusIndicationCallback(commStatusParams);
2866 }
2868 }
2869}
2870
2871bool
2873{
2874 PurgeInd();
2875
2876 for (auto iter = m_indTxQueue.begin(); iter != m_indTxQueue.end(); iter++)
2877 {
2878 if ((*iter)->dstExtAddress == dst)
2879 {
2880 *entry = **iter;
2881 m_macIndTxDequeueTrace((*iter)->txQPkt->Copy());
2882 m_indTxQueue.erase(iter);
2883 return true;
2884 }
2885 }
2886 return false;
2887}
2888
2889void
2891{
2892 for (uint32_t i = 0; i < m_indTxQueue.size();)
2893 {
2894 if (Simulator::Now() > m_indTxQueue[i]->expireTime)
2895 {
2896 // Transaction expired, remove and send proper confirmation/indication to a higher layer
2897 LrWpanMacHeader peekedMacHdr;
2898 m_indTxQueue[i]->txQPkt->PeekHeader(peekedMacHdr);
2899
2900 if (peekedMacHdr.IsCommand())
2901 {
2902 // IEEE 802.15.4-2006 (Section 7.1.3.3.3)
2904 {
2905 MlmeCommStatusIndicationParams commStatusParams;
2906 commStatusParams.m_panId = m_macPanId;
2907 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
2908 commStatusParams.m_srcExtAddr = peekedMacHdr.GetExtSrcAddr();
2909 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
2910 commStatusParams.m_dstExtAddr = peekedMacHdr.GetExtDstAddr();
2911 commStatusParams.m_status =
2913 m_mlmeCommStatusIndicationCallback(commStatusParams);
2914 }
2915 }
2916 else if (peekedMacHdr.IsData())
2917 {
2918 // IEEE 802.15.4-2006 (Section 7.1.1.1.3)
2920 {
2921 McpsDataConfirmParams confParams;
2923 m_mcpsDataConfirmCallback(confParams);
2924 }
2925 }
2926 m_macIndTxDropTrace(m_indTxQueue[i]->txQPkt->Copy());
2927 m_indTxQueue.erase(m_indTxQueue.begin() + i);
2928 }
2929 else
2930 {
2931 i++;
2932 }
2933 }
2934}
2935
2936void
2937LrWpanMac::PrintPendingTxQueue(std::ostream& os) const
2938{
2939 LrWpanMacHeader peekedMacHdr;
2940
2941 os << "Pending Transaction List [" << GetShortAddress() << " | " << GetExtendedAddress()
2942 << "] | CurrentTime: " << Simulator::Now().As(Time::S) << "\n"
2943 << " Destination |"
2944 << " Sequence Number |"
2945 << " Frame type |"
2946 << " Expire time\n";
2947
2948 for (auto transaction : m_indTxQueue)
2949 {
2950 transaction->txQPkt->PeekHeader(peekedMacHdr);
2951 os << transaction->dstExtAddress << " "
2952 << static_cast<uint32_t>(transaction->seqNum) << " ";
2953
2954 if (peekedMacHdr.IsCommand())
2955 {
2956 os << " Command Frame ";
2957 }
2958 else if (peekedMacHdr.IsData())
2959 {
2960 os << " Data Frame ";
2961 }
2962 else
2963 {
2964 os << " Unknown Frame ";
2965 }
2966
2967 os << transaction->expireTime.As(Time::S) << "\n";
2968 }
2969}
2970
2971void
2972LrWpanMac::PrintTxQueue(std::ostream& os) const
2973{
2974 LrWpanMacHeader peekedMacHdr;
2975
2976 os << "\nTx Queue [" << GetShortAddress() << " | " << GetExtendedAddress()
2977 << "] | CurrentTime: " << Simulator::Now().As(Time::S) << "\n"
2978 << " Destination |"
2979 << " Sequence Number |"
2980 << " Dst PAN id |"
2981 << " Frame type |\n";
2982
2983 for (auto transaction : m_txQueue)
2984 {
2985 transaction->txQPkt->PeekHeader(peekedMacHdr);
2986
2987 os << "[" << peekedMacHdr.GetShortDstAddr() << "]"
2988 << ", [" << peekedMacHdr.GetExtDstAddr() << "] "
2989 << static_cast<uint32_t>(peekedMacHdr.GetSeqNum()) << " "
2990 << peekedMacHdr.GetDstPanId() << " ";
2991
2992 if (peekedMacHdr.IsCommand())
2993 {
2994 os << " Command Frame ";
2995 }
2996 else if (peekedMacHdr.IsData())
2997 {
2998 os << " Data Frame ";
2999 }
3000 else
3001 {
3002 os << " Unknown Frame ";
3003 }
3004
3005 os << "\n";
3006 }
3007 os << "\n";
3008}
3009
3010void
3012{
3013 LrWpanMacHeader peekedMacHdr;
3014 p->PeekHeader(peekedMacHdr);
3015
3016 for (auto it = m_indTxQueue.begin(); it != m_indTxQueue.end(); it++)
3017 {
3018 if (peekedMacHdr.GetDstAddrMode() == EXT_ADDR)
3019 {
3020 if (((*it)->dstExtAddress == peekedMacHdr.GetExtDstAddr()) &&
3021 ((*it)->seqNum == peekedMacHdr.GetSeqNum()))
3022 {
3024 m_indTxQueue.erase(it);
3025 break;
3026 }
3027 }
3028 else if (peekedMacHdr.GetDstAddrMode() == SHORT_ADDR)
3029 {
3030 if (((*it)->dstShortAddress == peekedMacHdr.GetShortDstAddr()) &&
3031 ((*it)->seqNum == peekedMacHdr.GetSeqNum()))
3032 {
3034 m_indTxQueue.erase(it);
3035 break;
3036 }
3037 }
3038 }
3039
3040 p = nullptr;
3041}
3042
3043void
3045{
3047 NS_LOG_FUNCTION(this << status << m_txQueue.size());
3048
3049 LrWpanMacHeader macHdr;
3050 Time ifsWaitTime;
3051 double symbolRate;
3052
3053 symbolRate = m_phy->GetDataOrSymbolRate(false); // symbols per second
3054
3055 m_txPkt->PeekHeader(macHdr);
3056
3057 if (status == IEEE_802_15_4_PHY_SUCCESS)
3058 {
3059 if (!macHdr.IsAcknowledgment())
3060 {
3061 if (macHdr.IsBeacon())
3062 {
3063 // Start CAP only if we are in beacon mode (i.e. if slotted csma-ca is running)
3064 if (m_csmaCa->IsSlottedCsmaCa())
3065 {
3066 // The Tx Beacon in symbols
3067 // Beacon = 5 bytes Sync Header (SHR) + 1 byte PHY header (PHR) + PSDU (default
3068 // 17 bytes)
3069 uint64_t beaconSymbols = m_phy->GetPhySHRDuration() +
3070 1 * m_phy->GetPhySymbolsPerOctet() +
3071 (m_txPkt->GetSize() * m_phy->GetPhySymbolsPerOctet());
3072
3073 // The beacon Tx time and start of the Outgoing superframe Active Period
3075 Simulator::Now() - Seconds(static_cast<double>(beaconSymbols) / symbolRate);
3076
3078 this,
3080 NS_LOG_DEBUG("Beacon Sent (m_macBeaconTxTime: " << m_macBeaconTxTime.As(Time::S)
3081 << ")");
3082
3084 {
3085 MlmeStartConfirmParams mlmeConfirmParams;
3086 mlmeConfirmParams.m_status = MLMESTART_SUCCESS;
3087 m_mlmeStartConfirmCallback(mlmeConfirmParams);
3088 }
3089 }
3090
3091 ifsWaitTime = Seconds(static_cast<double>(GetIfsSize()) / symbolRate);
3092 m_txPkt = nullptr;
3093 }
3094 else if (macHdr.IsAckReq()) // We have sent a regular data packet, check if we have to
3095 // wait for an ACK.
3096 {
3097 // we sent a regular data frame or command frame (e.g. AssocReq command) that
3098 // require ACK wait for the ack or the next retransmission timeout start
3099 // retransmission timer
3100 Time waitTime = Seconds(static_cast<double>(GetMacAckWaitDuration()) / symbolRate);
3106 return;
3107 }
3108 else if (macHdr.IsCommand())
3109 {
3110 // We handle commands that do not require ACK
3111 // (e.g. Coordinator realigment command in an orphan response)
3112 // Other command with ACK required are handle by the previous if statement.
3113
3114 // Check the transmitted packet command type and issue the appropriate indication.
3115 Ptr<Packet> txOriginalPkt = m_txPkt->Copy();
3116 LrWpanMacHeader txMacHdr;
3117 txOriginalPkt->RemoveHeader(txMacHdr);
3118 CommandPayloadHeader txMacPayload;
3119 txOriginalPkt->RemoveHeader(txMacPayload);
3120
3122 {
3124 {
3125 MlmeCommStatusIndicationParams commStatusParams;
3126 commStatusParams.m_panId = m_macPanId;
3127
3128 commStatusParams.m_srcAddrMode = macHdr.GetSrcAddrMode();
3129 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
3130 commStatusParams.m_srcShortAddr = macHdr.GetShortSrcAddr();
3131
3132 commStatusParams.m_dstAddrMode = macHdr.GetDstAddrMode();
3133 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
3134 commStatusParams.m_dstShortAddr = macHdr.GetShortDstAddr();
3135
3137 m_mlmeCommStatusIndicationCallback(commStatusParams);
3138 }
3139 }
3140
3141 ifsWaitTime = Seconds(static_cast<double>(GetIfsSize()) / symbolRate);
3143 }
3144 else
3145 {
3147 // remove the copy of the packet that was just sent
3149 {
3150 McpsDataConfirmParams confirmParams;
3151 NS_ASSERT_MSG(!m_txQueue.empty(), "TxQsize = 0");
3152 Ptr<TxQueueElement> txQElement = m_txQueue.front();
3153 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
3154 confirmParams.m_status = IEEE_802_15_4_SUCCESS;
3155 m_mcpsDataConfirmCallback(confirmParams);
3156 }
3157 ifsWaitTime = Seconds(static_cast<double>(GetIfsSize()) / symbolRate);
3159 }
3160 }
3161 else
3162 {
3163 // The packet sent was a successful ACK
3164
3165 // Check the received frame before the transmission of the ACK,
3166 // and send the appropriate Indication or Confirmation
3167 Ptr<Packet> recvOriginalPkt = m_rxPkt->Copy();
3168 LrWpanMacHeader receivedMacHdr;
3169 recvOriginalPkt->RemoveHeader(receivedMacHdr);
3170
3171 if (receivedMacHdr.IsCommand())
3172 {
3173 CommandPayloadHeader receivedMacPayload;
3174 recvOriginalPkt->RemoveHeader(receivedMacPayload);
3175
3176 if (receivedMacPayload.GetCommandFrameType() ==
3178 {
3180 {
3181 // NOTE: The LQI parameter is not part of the standard but found
3182 // in some implementations as is required for higher layers (See Zboss
3183 // implementation).
3184 MlmeAssociateIndicationParams associateParams;
3185 associateParams.capabilityInfo = receivedMacPayload.GetCapabilityField();
3186 associateParams.m_extDevAddr = receivedMacHdr.GetExtSrcAddr();
3187 associateParams.lqi = m_lastRxFrameLqi;
3188 m_mlmeAssociateIndicationCallback(associateParams);
3189 }
3190
3191 // Clear the packet buffer for the packet request received.
3192 m_rxPkt = nullptr;
3193 }
3194 else if (receivedMacPayload.GetCommandFrameType() ==
3196 {
3197 MlmeAssociateConfirmParams confirmParams;
3198
3199 switch (receivedMacPayload.GetAssociationStatus())
3200 {
3202 // The assigned short address by the coordinator
3203 SetShortAddress(receivedMacPayload.GetShortAddr());
3204 m_macPanId = receivedMacHdr.GetSrcPanId();
3205
3206 confirmParams.m_status =
3208 confirmParams.m_assocShortAddr = GetShortAddress();
3209 break;
3211 confirmParams.m_status =
3213 m_macPanId = 0xffff;
3215 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3218 m_csmaCa->SetUnSlottedCsmaCa();
3221 break;
3223 confirmParams.m_status =
3225 m_macPanId = 0xffff;
3227 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3230 m_csmaCa->SetUnSlottedCsmaCa();
3233 break;
3234 }
3235
3237 {
3238 m_mlmeAssociateConfirmCallback(confirmParams);
3239 }
3240 }
3241 else if (receivedMacPayload.GetCommandFrameType() == CommandPayloadHeader::DATA_REQ)
3242 {
3243 // We enqueue the the Assoc Response command frame in the Tx queue
3244 // and the packet is transmitted as soon as the PHY is free and the IFS have
3245 // taken place.
3247 }
3248 }
3249
3250 // Clear the packet buffer for the ACK packet sent.
3251 m_txPkt = nullptr;
3252 }
3253 }
3254 else if (status == IEEE_802_15_4_PHY_UNSPECIFIED)
3255 {
3256 if (!macHdr.IsAcknowledgment())
3257 {
3258 NS_ASSERT_MSG(!m_txQueue.empty(), "TxQsize = 0");
3259 Ptr<TxQueueElement> txQElement = m_txQueue.front();
3260 m_macTxDropTrace(txQElement->txQPkt);
3262 {
3263 McpsDataConfirmParams confirmParams;
3264 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
3265 confirmParams.m_status = IEEE_802_15_4_FRAME_TOO_LONG;
3266 m_mcpsDataConfirmCallback(confirmParams);
3267 }
3269 }
3270 else
3271 {
3272 NS_LOG_ERROR("Unable to send ACK");
3273 }
3274 }
3275 else
3276 {
3277 // Something went really wrong. The PHY is not in the correct state for
3278 // data transmission.
3279 NS_FATAL_ERROR("Transmission attempt failed with PHY status " << status);
3280 }
3281
3282 if (!ifsWaitTime.IsZero())
3283 {
3284 m_ifsEvent =
3285 Simulator::Schedule(ifsWaitTime, &LrWpanMac::IfsWaitTimeout, this, ifsWaitTime);
3286 }
3287
3290}
3291
3292void
3294{
3295 NS_LOG_FUNCTION(this << status);
3296 // Direct this call through the csmaCa object
3297 m_csmaCa->PlmeCcaConfirm(status);
3298}
3299
3300void
3302{
3303 NS_LOG_FUNCTION(this << status << energyLevel);
3304
3305 if (energyLevel > m_maxEnergyLevel)
3306 {
3307 m_maxEnergyLevel = energyLevel;
3308 }
3309
3311 Seconds(8.0 / m_phy->GetDataOrSymbolRate(false)))
3312 {
3313 m_phy->PlmeEdRequest();
3314 }
3315}
3316
3317void
3321{
3322 NS_LOG_FUNCTION(this << status << id << attribute);
3323}
3324
3325void
3327{
3328 NS_LOG_FUNCTION(this << status);
3329
3331 (status == IEEE_802_15_4_PHY_TX_ON || status == IEEE_802_15_4_PHY_SUCCESS))
3332 {
3334
3335 // Start sending if we are in state SENDING and the PHY transmitter was enabled.
3339 m_phy->PdDataRequest(m_txPkt->GetSize(), m_txPkt);
3340 }
3341 else if (m_lrWpanMacState == MAC_CSMA &&
3342 (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS))
3343 {
3344 // Start the CSMA algorithm as soon as the receiver is enabled.
3345 m_csmaCa->Start();
3346 }
3347 else if (m_lrWpanMacState == MAC_IDLE)
3348 {
3350 status == IEEE_802_15_4_PHY_TRX_OFF);
3351
3353 {
3354 // Kick start Energy Detection Scan
3355 m_phy->PlmeEdRequest();
3356 }
3357 else if (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS)
3358 {
3359 // Check if there is not messages to transmit when going idle
3360 CheckQueue();
3361 }
3362 }
3364 {
3366 }
3367 else
3368 {
3369 // TODO: What to do when we receive an error?
3370 // If we want to transmit a packet, but switching the transceiver on results
3371 // in an error, we have to recover somehow (and start sending again).
3372 NS_FATAL_ERROR("Error changing transceiver state");
3373 }
3374}
3375
3376void
3378{
3379 NS_LOG_FUNCTION(this << status << id);
3381 {
3383 {
3384 // get the first channel to scan from scan channel list
3385 bool channelFound = false;
3386 for (int i = m_channelScanIndex; i <= 26; i++)
3387 {
3389 {
3390 channelFound = true;
3391 break;
3392 }
3394 }
3395
3396 if (channelFound)
3397 {
3398 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
3399 pibAttr->phyCurrentChannel = m_channelScanIndex;
3401 pibAttr);
3402 }
3403 }
3404 else
3405 {
3407 {
3408 MlmeScanConfirmParams confirmParams;
3409 confirmParams.m_scanType = m_scanParams.m_scanType;
3410 confirmParams.m_chPage = m_scanParams.m_chPage;
3411 confirmParams.m_status = MLMESCAN_INVALID_PARAMETER;
3412 m_mlmeScanConfirmCallback(confirmParams);
3413 }
3414 NS_LOG_ERROR(this << "Channel Scan: Invalid channel page");
3415 }
3416 }
3419 {
3421 {
3422 auto symbolRate = static_cast<uint64_t>(m_phy->GetDataOrSymbolRate(false));
3423 Time nextScanTime;
3424
3426 {
3427 nextScanTime = Seconds(static_cast<double>(m_macResponseWaitTime) / symbolRate);
3428 }
3429 else
3430 {
3431 uint64_t scanDurationSym =
3433
3434 nextScanTime = Seconds(static_cast<double>(scanDurationSym) / symbolRate);
3435 }
3436
3437 switch (m_scanParams.m_scanType)
3438 {
3439 case MLMESCAN_ED:
3440 m_maxEnergyLevel = 0;
3443 // set phy to RX_ON and kick start the first PLME-ED.request
3444 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3445 break;
3446 case MLMESCAN_ACTIVE:
3449 break;
3450 case MLMESCAN_PASSIVE:
3452 // turn back the phy to RX_ON after setting Page/channel
3453 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3454 break;
3455 case MLMESCAN_ORPHAN:
3457 Simulator::Schedule(nextScanTime, &LrWpanMac::EndChannelScan, this);
3459 break;
3460
3461 default:
3462 MlmeScanConfirmParams confirmParams;
3463 confirmParams.m_scanType = m_scanParams.m_scanType;
3464 confirmParams.m_chPage = m_scanParams.m_chPage;
3465 confirmParams.m_status = MLMESCAN_INVALID_PARAMETER;
3467 {
3468 m_mlmeScanConfirmCallback(confirmParams);
3469 }
3470 NS_LOG_ERROR("Scan Type currently not supported");
3471 return;
3472 }
3473 }
3474 else
3475 {
3477 {
3478 MlmeScanConfirmParams confirmParams;
3479 confirmParams.m_scanType = m_scanParams.m_scanType;
3480 confirmParams.m_chPage = m_scanParams.m_chPage;
3481 confirmParams.m_status = MLMESCAN_INVALID_PARAMETER;
3482 m_mlmeScanConfirmCallback(confirmParams);
3483 }
3484 NS_LOG_ERROR("Channel " << m_channelScanIndex
3485 << " could not be set in the current page");
3486 }
3487 }
3490 {
3492 {
3493 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
3494 pibAttr->phyCurrentChannel = m_startParams.m_logCh;
3496 pibAttr);
3497 }
3498 else
3499 {
3501 {
3502 MlmeStartConfirmParams confirmParams;
3503 confirmParams.m_status = MLMESTART_INVALID_PARAMETER;
3504 m_mlmeStartConfirmCallback(confirmParams);
3505 }
3506 NS_LOG_ERROR("Invalid page parameter in MLME-start");
3507 }
3508 }
3511 {
3513 {
3515 }
3516 else
3517 {
3519 {
3520 MlmeStartConfirmParams confirmParams;
3521 confirmParams.m_status = MLMESTART_INVALID_PARAMETER;
3522 m_mlmeStartConfirmCallback(confirmParams);
3523 }
3524 NS_LOG_ERROR("Invalid channel parameter in MLME-start");
3525 }
3526 }
3529 {
3531 {
3532 Ptr<LrWpanPhyPibAttributes> pibAttr = Create<LrWpanPhyPibAttributes>();
3533 pibAttr->phyCurrentChannel = m_associateParams.m_chNum;
3535 pibAttr);
3536 }
3537 else
3538 {
3539 m_macPanId = 0xffff;
3541 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3544 m_csmaCa->SetUnSlottedCsmaCa();
3547
3549 {
3550 MlmeAssociateConfirmParams confirmParams;
3551 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
3552 confirmParams.m_status = MLMEASSOC_INVALID_PARAMETER;
3553 m_mlmeAssociateConfirmCallback(confirmParams);
3554 }
3555 NS_LOG_ERROR("Invalid page parameter in MLME-associate");
3556 }
3557 }
3560 {
3562 {
3564 }
3565 else
3566 {
3567 m_macPanId = 0xffff;
3569 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3572 m_csmaCa->SetUnSlottedCsmaCa();
3575
3577 {
3578 MlmeAssociateConfirmParams confirmParams;
3579 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
3580 confirmParams.m_status = MLMEASSOC_INVALID_PARAMETER;
3581 m_mlmeAssociateConfirmCallback(confirmParams);
3582 }
3583 NS_LOG_ERROR("Invalid channel parameter in MLME-associate");
3584 }
3585 }
3586}
3587
3588void
3590{
3591 NS_LOG_FUNCTION(this << "mac state = " << macState);
3592
3593 if (macState == MAC_IDLE)
3594 {
3597 {
3598 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3599 }
3600 else
3601 {
3602 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TRX_OFF);
3603 }
3604 }
3605 else if (macState == MAC_ACK_PENDING)
3606 {
3608 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3609 }
3610 else if (macState == MAC_CSMA)
3611 {
3614 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3615 }
3616 else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE)
3617 {
3618 // Channel is idle, set transmitter to TX_ON
3620 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TX_ON);
3621 }
3622 else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE)
3623 {
3625
3626 // Cannot find a clear channel, drop the current packet
3627 // and send the proper confirm/indication according to the packet type
3628 NS_LOG_DEBUG(this << " cannot find clear channel");
3629
3631
3632 Ptr<Packet> pkt = m_txPkt->Copy();
3633 LrWpanMacHeader macHdr;
3634 pkt->RemoveHeader(macHdr);
3635
3636 if (macHdr.IsCommand())
3637 {
3638 CommandPayloadHeader cmdPayload;
3639 pkt->RemoveHeader(cmdPayload);
3640
3641 switch (cmdPayload.GetCommandFrameType())
3642 {
3644 m_macPanId = 0xffff;
3646 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3649 m_csmaCa->SetUnSlottedCsmaCa();
3652
3654 {
3655 MlmeAssociateConfirmParams confirmParams;
3656 confirmParams.m_assocShortAddr = Mac16Address("FF:FF");
3658 m_mlmeAssociateConfirmCallback(confirmParams);
3659 }
3660 break;
3661 }
3664 {
3665 MlmeCommStatusIndicationParams commStatusParams;
3666 commStatusParams.m_panId = m_macPanId;
3667 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
3668 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
3669 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
3670 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
3671 commStatusParams.m_status =
3673 m_mlmeCommStatusIndicationCallback(commStatusParams);
3674 }
3676 break;
3677 }
3679 m_macPanId = 0xffff;
3681 m_macCoordExtendedAddress = Mac64Address("ff:ff:ff:ff:ff:ff:ff:ed");
3684 m_csmaCa->SetUnSlottedCsmaCa();
3687
3689 {
3690 MlmePollConfirmParams pollConfirmParams;
3691 pollConfirmParams.m_status =
3693 m_mlmePollConfirmCallback(pollConfirmParams);
3694 }
3695 break;
3696 }
3699 {
3700 MlmeCommStatusIndicationParams commStatusParams;
3701 commStatusParams.m_panId = m_macPanId;
3702 commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR;
3703 commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr();
3704 commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR;
3705 commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr();
3706 commStatusParams.m_status =
3708 m_mlmeCommStatusIndicationCallback(commStatusParams);
3709 }
3710 break;
3711 }
3714 {
3715 m_unscannedChannels.emplace_back(m_phy->GetCurrentChannelNum());
3716 }
3717 // TODO: Handle orphan notification command during a
3718 // channel access failure when not is not scanning.
3719 break;
3720 }
3722 if (m_scanEvent.IsRunning())
3723 {
3724 m_unscannedChannels.emplace_back(m_phy->GetCurrentChannelNum());
3725 }
3726 // TODO: Handle beacon request command during a
3727 // channel access failure when not scanning.
3728 break;
3729 }
3730 default: {
3731 // TODO: Other commands(e.g. Disassociation notification, etc)
3732 break;
3733 }
3734 }
3736 }
3737 else if (macHdr.IsData())
3738 {
3740 {
3741 McpsDataConfirmParams confirmParams;
3742 confirmParams.m_msduHandle = m_txQueue.front()->txQMsduHandle;
3744 m_mcpsDataConfirmCallback(confirmParams);
3745 }
3746 // remove the copy of the packet that was just sent
3748 }
3749 else
3750 {
3751 // TODO:: specify behavior for other packets
3752 m_txPkt = nullptr;
3753 m_retransmission = 0;
3754 m_numCsmacaRetry = 0;
3755 }
3756
3759 {
3760 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_RX_ON);
3761 }
3762 else
3763 {
3764 m_phy->PlmeSetTRXStateRequest(IEEE_802_15_4_PHY_TRX_OFF);
3765 }
3766 }
3767 else if (m_lrWpanMacState == MAC_CSMA && macState == MAC_CSMA_DEFERRED)
3768 {
3770 m_txPkt = nullptr;
3771 // The MAC is running on beacon mode and the current packet could not be sent in the
3772 // current CAP. The packet will be send on the next CAP after receiving the beacon.
3773 // The PHY state does not change from its current form. The PHY change (RX_ON) will be
3774 // triggered by the scheduled beacon event.
3775
3776 NS_LOG_DEBUG("****** PACKET DEFERRED to the next superframe *****");
3777 }
3778}
3779
3782{
3783 return m_associationStatus;
3784}
3785
3786void
3788{
3789 m_associationStatus = status;
3790}
3791
3792void
3794{
3795 m_maxTxQueueSize = queueSize;
3796}
3797
3798void
3800{
3801 m_maxIndTxQueueSize = queueSize;
3802}
3803
3804uint16_t
3806{
3807 return m_macPanId;
3808}
3809
3812{
3814}
3815
3818{
3820}
3821
3822void
3823LrWpanMac::SetPanId(uint16_t panId)
3824{
3825 m_macPanId = panId;
3826}
3827
3828void
3830{
3831 NS_LOG_LOGIC(this << " change lrwpan mac state from " << m_lrWpanMacState << " to "
3832 << newState);
3834 m_lrWpanMacState = newState;
3835}
3836
3837uint64_t
3839{
3840 return lrwpan::aUnitBackoffPeriod + lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() +
3841 ceil(6 * m_phy->GetPhySymbolsPerOctet());
3842}
3843
3844uint8_t
3846{
3847 return m_macMaxFrameRetries;
3848}
3849
3850void
3852{
3853 NS_LOG_DEBUG("Transmit Queue Size: " << m_txQueue.size());
3854}
3855
3856void
3858{
3859 m_macMaxFrameRetries = retries;
3860}
3861
3862bool
3864{
3866 LrWpanMacHeader macHdr;
3867 m_txPkt->PeekHeader(macHdr);
3868
3869 if (m_coor)
3870 {
3871 // The device is its coordinator and the packet is not to itself
3872 return false;
3873 }
3874 else if (m_macCoordShortAddress == macHdr.GetShortDstAddr() ||
3876 {
3877 return true;
3878 }
3879 else
3880 {
3881 NS_LOG_DEBUG("ERROR: Packet not for the coordinator!");
3882 return false;
3883 }
3884}
3885
3888{
3890
3892 {
3893 return m_macSIFSPeriod;
3894 }
3895 else
3896 {
3897 return m_macLIFSPeriod;
3898 }
3899}
3900
3901void
3903{
3905}
3906
3907void
3909{
3911}
3912
3913uint64_t
3915{
3917 // Sync Header (SHR) + 8 bits PHY header (PHR) + PSDU
3918 return (m_phy->GetPhySHRDuration() + 1 * m_phy->GetPhySymbolsPerOctet() +
3919 (m_txPkt->GetSize() * m_phy->GetPhySymbolsPerOctet()));
3920}
3921
3922bool
3924{
3926 LrWpanMacHeader macHdr;
3927 m_txPkt->PeekHeader(macHdr);
3928
3929 return macHdr.IsAckReq();
3930}
3931
3932} // namespace ns3
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
GtsFields GetGtsFields() const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
PendingAddrFields GetPndAddrFields() const
Get the pending address fields from the beacon payload header.
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to the beacon payload header.
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
SuperframeField GetSuperframeSpecField() const
Get the superframe specification field from the beacon payload header.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
Implements the header for the MAC payload command frame according to the IEEE 802....
void SetPage(uint8_t page)
Set the logical channel page number.
@ SUCCESSFUL
Association successful.
CapabilityField GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetPanId(uint16_t id)
Get the PAN identifier.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
void SetCapabilityField(CapabilityField cap)
Set the Capability Information Field to the command payload header (Association Request Command).
AssocStatus GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
void SetAssociationStatus(AssocStatus status)
Set status resulting from the association attempt (Association Response Command).
MacCommand GetCommandFrameType() const
Get the command frame type ID.
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ BEACON_REQ
Beacon Request (RFD true: none )
@ DATA_REQ
Data Request (RFD true: Tx)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
uint16_t GetPanId() const
Get the PAN identifier.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
void SetChannel(uint8_t channel)
Set the logical channel number.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:69
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
Represent the GTS information fields.
bool GetGtsPermit() const
Get the GTS Specification Permit.
Represent the Mac Header with the Frame Control and Sequence Number fields.
Mac16Address GetShortSrcAddr() const
Get the Source Short address.
@ 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.
bool IsCommand() const
Returns true if the header is a command.
bool IsBeacon() const
Returns true if the header is a beacon.
Mac64Address GetExtSrcAddr() const
Get the Source Extended address.
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
uint8_t GetSrcAddrMode() const
Get the Source Addressing Mode of Frame control field.
void SetPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to true.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
uint8_t GetDstAddrMode() const
Get the Dest.
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
bool IsAcknowledgment() const
Returns true if the header is an ack.
bool IsData() const
Returns true if the header is a data.
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
uint8_t GetSeqNum() const
Get the frame Sequence number.
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
void SetNoAckReq()
Set the Frame Control field "Ack. Request" bit to false.
Mac64Address GetExtDstAddr() const
Get the Destination Extended address.
LrWpanMacType GetType() const
Get the header type.
uint16_t GetDstPanId() const
Get the Destination PAN ID.
uint8_t GetFrameVer() const
Get the Frame Version of Frame control field.
void SetFrameVer(uint8_t ver)
Set the Frame version.
uint16_t GetSrcPanId() const
Get the Source PAN ID.
bool IsAckReq() const
Check if Ack.
Mac16Address GetShortDstAddr() const
Get the Destination Short address.
void SetAckReq()
Set the Frame Control field "Ack. Request" bit to true.
Class that implements the LR-WPAN MAC state machine.
Definition: lr-wpan-mac.h:841
uint32_t m_incomingBeaconInterval
Indication of the interval a node should receive a superframe expressed in symbols.
Definition: lr-wpan-mac.h:1495
uint32_t GetIfsSize()
Get the size of the Interframe Space according to MPDU size (m_txPkt).
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
Definition: lr-wpan-mac.h:2017
uint64_t m_assocRespCmdWaitTime
The maximum wait time for an association response command after the reception of data request command...
Definition: lr-wpan-mac.h:1291
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
Definition: lr-wpan-mac.h:2102
uint64_t GetMacAckWaitDuration() const
Get the macAckWaitDuration attribute value.
Time m_macBeaconRxTime
The time that the device received its last bit of the beacon frame.
Definition: lr-wpan-mac.h:1276
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
~LrWpanMac() override
Definition: lr-wpan-mac.cc:225
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:1429
bool m_macAssociationPermit
Indication of whether a coordinator is currently allowing association.
Definition: lr-wpan-mac.h:1448
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
Definition: lr-wpan-mac.h:1914
void SetMlmeBeaconNotifyIndicationCallback(MlmeBeaconNotifyIndicationCallback c)
Set the callback for the indication of an incoming beacon packet.
uint64_t m_rxBeaconSymbols
The total size of the received beacon in symbols.
Definition: lr-wpan-mac.h:1346
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:303
uint64_t GetTxPacketSymbols()
Obtain the number of symbols in the packet which is currently being sent by the MAC layer.
void MlmeGetRequest(LrWpanMacPibAttributeIdentifier id)
IEEE 802.15.4-2011, section 6.2.5.1 MLME-GET.request Request information about a given PIB attribute.
Definition: lr-wpan-mac.cc:945
bool m_panCoor
Indication of whether the current device is the PAN coordinator.
Definition: lr-wpan-mac.h:1472
void SetMlmeAssociateIndicationCallback(MlmeAssociateIndicationCallback c)
Set the callback for the indication of an incoming associate request command.
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:2222
void MlmeSyncRequest(MlmeSyncRequestParams params)
IEEE 802.15.4-2011, section 6.2.13.1 MLME-SYNC.request Request to synchronize with the coordinator by...
Definition: lr-wpan-mac.cc:846
static TypeId GetTypeId()
Get the type ID.
Definition: lr-wpan-mac.cc:52
MlmeStartConfirmCallback m_mlmeStartConfirmCallback
This callback is used to report the start of a new PAN or the begin of a new superframe configuration...
Definition: lr-wpan-mac.h:2071
uint8_t m_deviceCapability
Indication of current device capability (FFD or RFD)
Definition: lr-wpan-mac.h:1506
void AwaitBeacon()
Called after the end of an INCOMING superframe to start the moment a device waits for a new incoming ...
bool m_coor
Indicates if the current device is a coordinator type.
Definition: lr-wpan-mac.h:1477
void LostAssocRespCommand()
Called after m_assocRespCmdWaitTime timeout while waiting for an association response command.
bool isCoordDest()
Check if the packet destination is its coordinator.
EventId m_trackingEvent
Scheduler event to track the incoming beacons.
Definition: lr-wpan-mac.h:2283
void SetMlmeScanConfirmCallback(MlmeScanConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
uint32_t m_maxIndTxQueueSize
The maximum size of the indirect transmit queue (The pending transaction list).
Definition: lr-wpan-mac.h:2166
EventId m_assocResCmdWaitTimeout
Scheduler event for the lost of a association response command frame.
Definition: lr-wpan-mac.h:2243
void PurgeInd()
Purge expired transactions from the pending transactions list.
void SetMlmePollConfirmCallback(MlmePollConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission.
void PlmeEdConfirm(LrWpanPhyEnumeration status, uint8_t energyLevel)
IEEE 802.15.4-2006 section 6.2.2.4 PLME-ED.confirm status and energy level.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:1948
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
Definition: lr-wpan-mac.h:1997
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:329
void MlmeStartRequest(MlmeStartRequestParams params)
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
Definition: lr-wpan-mac.cc:550
uint32_t m_macLIFSPeriod
The minimum time forming a Long InterFrame Spacing (LIFS) period.
Definition: lr-wpan-mac.h:1435
void StartInactivePeriod(SuperframeType superframeType)
Start the Inactive Period in a beacon-enabled mode.
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
Definition: lr-wpan-mac.h:1922
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
TracedCallback< Ptr< const Packet > > m_macIndTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 indirect transmission queue (Pending ...
Definition: lr-wpan-mac.h:1898
TracedCallback< Ptr< const Packet > > m_macIndTxDropTrace
The trace source fired when packets are dropped due to indirect Tx queue overflows or expiration.
Definition: lr-wpan-mac.h:1930
void SetMlmeAssociateConfirmCallback(MlmeAssociateConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
MlmeScanConfirmCallback m_mlmeScanConfirmCallback
This callback is used to report the result of a scan on a group of channels for the selected channel ...
Definition: lr-wpan-mac.h:2050
Mac16Address GetShortAddress() const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:336
void SendDataRequestCommand()
Used to send a data request command (i.e.
void SetMlmeStartConfirmCallback(MlmeStartConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
SuperframeField GetSuperframeField()
Constructs a Superframe specification field from the local information, the superframe Specification ...
EventId m_cfpEvent
Scheduler event for the end of the outgoing superframe CFP.
Definition: lr-wpan-mac.h:2268
void PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, Ptr< LrWpanPhyPibAttributes > attribute)
IEEE 802.15.4-2006 section 6.2.2.6 PLME-GET.confirm Get attributes per definition from Table 23 in se...
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:1422
Mac64Address m_macCoordExtendedAddress
The extended address of the coordinator through which the device is associated.
Definition: lr-wpan-mac.h:1307
MlmeSyncLossIndicationCallback m_mlmeSyncLossIndicationCallback
This callback is used to indicate the loss of synchronization with a coordinator.
Definition: lr-wpan-mac.h:2043
PendingPrimitiveStatus m_pendPrimitive
Indicates the pending primitive when PLME.SET operation (page or channel switch) is called from withi...
Definition: lr-wpan-mac.h:2211
MlmePollConfirmCallback m_mlmePollConfirmCallback
This callback is used to report the status after a device send data command request to the coordinato...
Definition: lr-wpan-mac.h:2064
uint8_t GetMacMaxFrameRetries() const
Get the macMaxFrameRetries attribute value.
uint16_t m_channelScanIndex
The channel list index used to obtain the current scanned channel.
Definition: lr-wpan-mac.h:2205
uint16_t GetPanId() const
Get the PAN id used by this MAC.
PendingAddrFields GetPendingAddrFields()
Constructs Pending Address Fields from the local information, the Pending Address Fields are part of ...
std::vector< PanDescriptor > m_panDescriptorList
The list of PAN descriptors accumulated during channel scans, used to select a PAN to associate.
Definition: lr-wpan-mac.h:2172
void SendBeaconRequestCommand()
Called to send a beacon request command.
EventId m_respWaitTimeout
Scheduler event for a response to a request command frame.
Definition: lr-wpan-mac.h:2238
uint32_t m_maxTxQueueSize
The maximum size of the transmit queue.
Definition: lr-wpan-mac.h:2161
Ptr< Packet > m_macBeaconPayload
The contents of the beacon payload.
Definition: lr-wpan-mac.h:1410
std::deque< Ptr< TxQueueElement > > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:2150
SequenceNumber8 m_macBsn
Sequence number added to transmitted beacon frame, 00-ff.
Definition: lr-wpan-mac.h:1403
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:2122
Ptr< Packet > m_rxPkt
The command request packet received.
Definition: lr-wpan-mac.h:2133
TracedCallback< Ptr< const Packet > > m_macIndTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: lr-wpan-mac.h:1890
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Mac16Address m_shortAddress
The short address (16 bit address) used by this MAC.
Definition: lr-wpan-mac.h:2140
uint8_t m_macSuperframeOrder
Used by a PAN coordinator or coordinator.
Definition: lr-wpan-mac.h:1329
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
void BeaconSearchTimeout()
Called if the device is unable to locate a beacon in the time set by MLME-SYNC.request.
bool isTxAckReq()
Check if the packet to transmit requires acknowledgment.
std::vector< uint8_t > m_energyDetectList
The list of energy measurements, one for each channel searched during an ED scan.
Definition: lr-wpan-mac.h:2177
void PdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
IEEE 802.15.4-2006 section 6.2.1.3 PD-DATA.indication Indicates the transfer of an MPDU from PHY to M...
void SendOneBeacon()
Called to send a single beacon frame.
Definition: lr-wpan-mac.cc:979
Time m_macBeaconTxTime
The time that the device transmitted its last beacon frame.
Definition: lr-wpan-mac.h:1268
MlmeBeaconNotifyIndicationCallback m_mlmeBeaconNotifyIndicationCallback
This callback is used to notify incoming beacon packets to the upper layers.
Definition: lr-wpan-mac.h:2037
void EndStartRequest()
Called to end a MLME-START.request after changing the page and channel number.
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:2007
Mac64Address GetExtendedAddress() const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:343
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:2248
uint64_t m_macResponseWaitTime
The maximum time, in multiples of aBaseSuperframeDuration, a device shall wait for a response command...
Definition: lr-wpan-mac.h:1283
void EnqueueInd(Ptr< Packet > p)
Adds a packet to the pending transactions list (Indirect transmissions).
void SendAssocResponseCommand(Ptr< Packet > rxDataReqPkt)
Called to send an associate response command.
void SetMlmeSetConfirmCallback(MlmeSetConfirmCallback c)
Set the callback for the confirmation of an attempt to write an attribute.
void StartCFP(SuperframeType superframeType)
Called to begin the Contention Free Period (CFP) in a beacon-enabled mode.
EventId m_scanEnergyEvent
Scheduler event for the end of a ED channel scan.
Definition: lr-wpan-mac.h:2298
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
bool PrepareRetransmission()
Check for remaining retransmissions for the packet currently being sent.
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
void MlmeAssociateRequest(MlmeAssociateRequestParams params)
IEEE 802.15.4-2011, section 6.2.2.1 MLME-ASSOCIATE.request Request primitive used by a device to requ...
Definition: lr-wpan-mac.cc:649
void EnqueueTxQElement(Ptr< TxQueueElement > txQElement)
Add an element to the transmission queue.
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
EventId m_scanEvent
Scheduler event for the end of an ACTIVE or PASSIVE channel scan.
Definition: lr-wpan-mac.h:2288
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Definition: lr-wpan-mac.h:1977
uint8_t m_incomingBeaconOrder
The beaconOrder value of the INCOMING frame.
Definition: lr-wpan-mac.h:1358
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:1397
void SetMlmeSyncLossIndicationCallback(MlmeSyncLossIndicationCallback c)
Set the callback for the loss of synchronization with a coordinator.
void SendOrphanNotificationCommand()
Called to send a orphan notification command.
uint32_t m_ifs
The value of the necessary InterFrame Space after the transmission of a packet.
Definition: lr-wpan-mac.h:1467
uint16_t m_macTransactionPersistenceTime
The maximum time (in UNIT periods) that a transaction is stored by a coordinator and indicated in its...
Definition: lr-wpan-mac.h:1340
Mac16Address GetCoordShortAddress() const
Get the coordinator short address currently associated to this device.
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
MlmeStartRequestParams m_startParams
The parameters used during a MLME-START.request.
Definition: lr-wpan-mac.h:2194
void AckWaitTimeout()
Handle an ACK timeout with a packet retransmission, if there are retransmission left,...
void MlmeScanRequest(MlmeScanRequestParams params)
IEEE 802.15.4-2011, section 6.2.10.1 MLME-SCAN.request Request primitive used to initiate a channel s...
Definition: lr-wpan-mac.cc:589
LrWpanAssociationStatus GetAssociationStatus() const
Get the current association status.
std::vector< uint8_t > m_unscannedChannels
The list of unscanned channels during a scan operation.
Definition: lr-wpan-mac.h:2182
Mac64Address GetCoordExtAddress() const
Get the coordinator extended address currently associated to this device.
uint8_t m_macBeaconOrder
Used by a PAN coordinator or coordinator.
Definition: lr-wpan-mac.h:1321
TracedCallback< Time > m_macIfsEndTrace
The trace source is fired at the end of any Interframe Space (IFS).
Definition: lr-wpan-mac.h:1854
void SetMlmeGetConfirmCallback(MlmeGetConfirmCallback c)
Set the callback for the confirmation of an attempt to read an attribute.
TracedValue< SuperframeStatus > m_outSuperframeStatus
The current period of the outgoing superframe.
Definition: lr-wpan-mac.h:2117
void PlmeSetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id)
IEEE 802.15.4-2006 section 6.2.2.10 PLME-SET.confirm Set attributes per definition from Table 23 in s...
MlmeOrphanIndicationCallback m_mlmeOrphanIndicationCallback
This callback is used to indicate the reception of a orphan notification command.
Definition: lr-wpan-mac.h:2095
void SetMlmeCommStatusIndicationCallback(MlmeCommStatusIndicationCallback c)
Set the callback for the indication to a response primitive.
bool DequeueInd(Mac64Address dst, Ptr< IndTxQueueElement > entry)
Extracts a packet from pending transactions list (Indirect transmissions).
MlmeAssociateRequestParams m_associateParams
The parameters used during a MLME-ASSOCIATE.request.
Definition: lr-wpan-mac.h:2200
LrWpanMac()
Default constructor.
Definition: lr-wpan-mac.cc:163
void CheckQueue()
Check the transmission queue.
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h:2233
MlmeAssociateConfirmCallback m_mlmeAssociateConfirmCallback
This callback is used to report the status after a device request an association with a coordinator.
Definition: lr-wpan-mac.h:2057
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:1378
uint8_t m_fnlCapSlot
Indication of the Slot where the CAP portion of the OUTGOING Superframe ends.
Definition: lr-wpan-mac.h:1351
uint32_t m_macSIFSPeriod
The minimum time forming a Short InterFrame Spacing (SIFS) period.
Definition: lr-wpan-mac.h:1441
void IfsWaitTimeout(Time ifsTime)
After a successful transmission of a frame (beacon, data) or an ack frame reception,...
std::deque< Ptr< IndTxQueueElement > > m_indTxQueue
The indirect transmit queue used by the MAC pending messages (The pending transaction list).
Definition: lr-wpan-mac.h:2156
void PrintPendingTxQueue(std::ostream &os) const
Print the Pending transaction list.
uint32_t m_beaconInterval
Indication of the Interval used by the coordinator to transmit beacon frames expressed in symbols.
Definition: lr-wpan-mac.h:1483
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:2107
TracedCallback< Ptr< const Packet > > m_macTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: lr-wpan-mac.h:1874
EventId m_capEvent
Scheduler event for the end of the outgoing superframe CAP.
Definition: lr-wpan-mac.h:2263
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:1905
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:1385
void EndChannelScan()
Called at the end of the current channel scan (Active or Passive) for a given duration.
void DoInitialize() override
Initialize() implementation.
Definition: lr-wpan-mac.cc:230
void MlmeAssociateResponse(MlmeAssociateResponseParams params)
IEEE 802.15.4-2011, section 6.2.2.3 MLME-ASSOCIATE.response Primitive used to initiate a response to ...
Definition: lr-wpan-mac.cc:724
void PrintTxQueue(std::ostream &os) const
Print the Transmit Queue.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Definition: lr-wpan-mac.h:1957
bool m_macAutoRequest
Indication of whether a device automatically sends data request command if its address is listed in t...
Definition: lr-wpan-mac.h:1457
uint8_t m_incomingSuperframeOrder
Used by all devices that have a parent.
Definition: lr-wpan-mac.h:1366
uint16_t m_macPanIdScan
Temporally stores the value of the current m_macPanId when a MLME-SCAN.request is performed.
Definition: lr-wpan-mac.h:1391
uint32_t m_macBeaconPayloadLength
The length, in octets, of the beacon payload.
Definition: lr-wpan-mac.h:1416
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
Definition: lr-wpan-mac.h:1882
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
uint8_t m_numLostBeacons
The number of consecutive loss beacons in a beacon tracking operation.
Definition: lr-wpan-mac.h:1516
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
Definition: lr-wpan-mac.h:2127
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p)
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
Definition: lr-wpan-mac.cc:350
void SendAssocRequestCommand()
Called to send an associate request command.
uint8_t m_maxEnergyLevel
The maximum energy level detected during ED scan on the current channel.
Definition: lr-wpan-mac.h:1462
void DoDispose() override
Destructor implementation.
Definition: lr-wpan-mac.cc:245
MlmeScanRequestParams m_scanParams
The parameters used during a MLME-SCAN.request.
Definition: lr-wpan-mac.h:2188
MlmeAssociateIndicationCallback m_mlmeAssociateIndicationCallback
This callback is used to indicate the reception of an association request command.
Definition: lr-wpan-mac.h:2083
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Ptr< LrWpanPhy > GetPhy()
Get the underlying PHY of the MAC.
uint8_t m_lastRxFrameLqi
Keep track of the last received frame Link Quality Indicator.
Definition: lr-wpan-mac.h:2227
EventId m_scanOrphanEvent
Scheduler event for the end of an ORPHAN channel scan.
Definition: lr-wpan-mac.h:2293
void EndAssociateRequest()
Called to end an MLME-ASSOCIATE.request after changing the page and channel number.
Definition: lr-wpan-mac.cc:704
MlmeSetConfirmCallback m_mlmeSetConfirmCallback
This callback is used to report the result of an attribute writing request to the upper layers.
Definition: lr-wpan-mac.h:2024
Mac64Address m_selfExt
The extended 64 address (IEEE EUI-64) used by this MAC.
Definition: lr-wpan-mac.h:2145
MlmeGetConfirmCallback m_mlmeGetConfirmCallback
This callback is used to report the result of an attribute read request to the upper layers.
Definition: lr-wpan-mac.h:2031
EventId m_incCapEvent
Scheduler event for the end of the incoming superframe CAP.
Definition: lr-wpan-mac.h:2273
void SetTxQMaxSize(uint32_t queueSize)
Set the max size of the transmit queue.
void SetIndTxQMaxSize(uint32_t queueSize)
Set the max size of the indirect transmit queue (Pending Transaction list)
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:2077
bool m_beaconTrackingOn
Indication of whether the current device is tracking incoming beacons.
Definition: lr-wpan-mac.h:1511
uint32_t m_superframeDuration
Indication of the superframe duration in symbols.
Definition: lr-wpan-mac.h:1489
bool GetRxOnWhenIdle() const
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:297
Mac16Address m_macCoordShortAddress
The short address of the coordinator through which the device is associated.
Definition: lr-wpan-mac.h:1300
GtsFields GetGtsFields()
Constructs the Guaranteed Time Slots (GTS) Fields from local information.
void MlmeOrphanResponse(MlmeOrphanResponseParams params)
IEEE 802.15.4-2011, section 6.2.7.2 MLME-ORPHAN.response Primitive used to initiatte a response to an...
Definition: lr-wpan-mac.cc:786
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
Definition: lr-wpan-mac.h:2012
void EndChannelEnergyScan()
Called at the end of one ED channel scan.
void PrintTransmitQueueSize()
Print the number of elements in the packet transmit queue.
void MlmeSetRequest(LrWpanMacPibAttributeIdentifier id, Ptr< LrWpanMacPibAttributes > attribute)
IEEE 802.15.4-2011, section 6.2.11.1 MLME-SET.request Attempts to write the given value to the indica...
Definition: lr-wpan-mac.cc:901
void StartCAP(SuperframeType superframeType)
Called to begin the Contention Access Period (CAP) in a beacon-enabled mode.
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:1939
void MlmePollRequest(MlmePollRequestParams params)
IEEE 802.15.4-2011, section 6.2.14.2 MLME-POLL.request Prompts the device to request data from the co...
Definition: lr-wpan-mac.cc:886
EventId m_ifsEvent
Scheduler event for Interframe spacing wait time.
Definition: lr-wpan-mac.h:2253
EventId m_beaconEvent
Scheduler event for generation of one beacon.
Definition: lr-wpan-mac.h:2258
uint32_t m_incomingSuperframeDuration
Indication of the superframe duration in symbols (e.g.
Definition: lr-wpan-mac.h:1501
TracedCallback< Ptr< const Packet >, uint8_t, uint8_t > m_sentPktTrace
The trace source fired when packets are considered as successfully sent or the transmission has been ...
Definition: lr-wpan-mac.h:1866
void RemovePendTxQElement(Ptr< Packet > p)
Remove an element from the pending transaction list.
void SetMlmeOrphanIndicationCallback(MlmeOrphanIndicationCallback c)
Set the callback for the indication to the reception of an orphan notification.
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:322
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:2217
EventId m_incCfpEvent
Scheduler event for the end of the incoming superframe CFP.
Definition: lr-wpan-mac.h:2278
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
uint8_t m_incomingFnlCapSlot
Indication of the Slot where the CAP portion of the INCOMING Superframe ends.
Definition: lr-wpan-mac.h:1371
MlmeCommStatusIndicationCallback m_mlmeCommStatusIndicationCallback
This callback is instigated through a response primitive.
Definition: lr-wpan-mac.h:2089
TracedValue< SuperframeStatus > m_incSuperframeStatus
The current period of the incoming superframe.
Definition: lr-wpan-mac.h:2112
void SetAssociatedCoor(Mac16Address mac)
Check if the packet destination is its coordinator.
Represent the Mac Trailer with the Frame Check Sequence field.
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
bool IsMulticast() const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
bool IsBroadcast() const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
an EUI-64 address
Definition: mac64-address.h:46
static Mac64Address Allocate()
Allocate a new Mac64Address.
static bool ChecksumEnabled()
Definition: node.cc:285
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoInitialize()
Initialize() implementation.
Definition: object.cc:359
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:305
Represent the Pending Address Specification field.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:558
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:592
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:208
Represent the Superframe Specification information field.
uint8_t GetFinalCapSlot() const
Get the the Final CAP Slot.
void SetAssocPermit(bool assocPermit)
Set the Superframe Specification Association Permit field.
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
uint8_t GetBeaconOrder() const
Get the Superframe Specification Beacon Order field.
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.
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
uint8_t GetFrameOrder() const
Get the Superframe Specification Frame Order field.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:415
@ S
second
Definition: nstime.h:116
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:314
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:930
Hold an unsigned integer type.
Definition: uinteger.h:45
constexpr uint32_t aMaxSIFSFrameSize
The maximum size of an MPDU, in octets, that can be followed by a Short InterFrame Spacing (SIFS) per...
constexpr uint32_t aMaxLostBeacons
The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to decl...
constexpr uint32_t aMaxBeaconPayloadLength
The maximum size, in octets, of a beacon payload.
constexpr uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
constexpr uint32_t aUnitBackoffPeriod
Number of symbols per CSMA/CA time unit, default 20 symbols.
constexpr uint32_t aTurnaroundTime
The turnaround time in symbol periods for switching the transceiver from RX to TX or vice-versa.
constexpr uint32_t aBaseSuperframeDuration
Length of a superframe in symbols.
constexpr uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:74
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:109
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:167
SuperframeType
Superframe type.
Definition: lr-wpan-mac.h:106
LrWpanMacPibAttributeIdentifier
IEEE802.15.4-2011 MAC PIB Attribute Identifiers Table 52 in section 6.4.2.
Definition: lr-wpan-mac.h:345
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:143
LrWpanMlmeGetConfirmStatus
Table 20 of IEEE 802.15.4-2011.
Definition: lr-wpan-mac.h:333
@ MLMEPOLL_SUCCESS
Definition: lr-wpan-mac.h:302
@ MLMEPOLL_NO_ACK
Definition: lr-wpan-mac.h:304
@ MLMEPOLL_CHANNEL_ACCESS_FAILURE
Definition: lr-wpan-mac.h:303
@ CHANNEL_ACCESS_FAILURE
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:79
@ MAC_IDLE
MAC_IDLE.
Definition: lr-wpan-mac.h:75
@ MAC_CSMA_DEFERRED
MAC_CSMA_DEFERRED.
Definition: lr-wpan-mac.h:84
@ MAC_CSMA
MAC_CSMA.
Definition: lr-wpan-mac.h:76
@ CHANNEL_IDLE
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:80
@ MAC_SENDING
MAC_SENDING.
Definition: lr-wpan-mac.h:77
@ MAC_ACK_PENDING
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:78
@ FFD
Full Functional Device (FFD)
@ MLMESCAN_ED
Definition: lr-wpan-mac.h:182
@ MLMESCAN_PASSIVE
Definition: lr-wpan-mac.h:184
@ MLMESCAN_ORPHAN
Definition: lr-wpan-mac.h:185
@ MLMESCAN_ACTIVE
Definition: lr-wpan-mac.h:183
@ IEEE_802_15_4_TRANSACTION_OVERFLOW
Definition: lr-wpan-mac.h:196
@ IEEE_802_15_4_NO_ACK
Definition: lr-wpan-mac.h:201
@ IEEE_802_15_4_CHANNEL_ACCESS_FAILURE
Definition: lr-wpan-mac.h:198
@ IEEE_802_15_4_INVALID_ADDRESS
Definition: lr-wpan-mac.h:199
@ IEEE_802_15_4_SUCCESS
Definition: lr-wpan-mac.h:195
@ IEEE_802_15_4_FRAME_TOO_LONG
Definition: lr-wpan-mac.h:203
@ IEEE_802_15_4_TRANSACTION_EXPIRED
Definition: lr-wpan-mac.h:197
@ MLMESCAN_NO_BEACON
Definition: lr-wpan-mac.h:237
@ MLMESCAN_SUCCESS
Definition: lr-wpan-mac.h:235
@ MLMESCAN_SCAN_IN_PROGRESS
Definition: lr-wpan-mac.h:238
@ MLMESCAN_INVALID_PARAMETER
Definition: lr-wpan-mac.h:243
@ CFP
Contention Free Period.
Definition: lr-wpan-mac.h:96
@ INACTIVE
Inactive Period or unslotted CSMA-CA.
Definition: lr-wpan-mac.h:97
@ CAP
Contention Access Period.
Definition: lr-wpan-mac.h:95
@ BEACON
The Beacon transmission or reception Period.
Definition: lr-wpan-mac.h:94
@ IEEE_802_15_4_PHY_SUCCESS
Definition: lr-wpan-phy.h:117
@ IEEE_802_15_4_PHY_UNSPECIFIED
Definition: lr-wpan-phy.h:122
@ IEEE_802_15_4_PHY_TRX_OFF
Definition: lr-wpan-phy.h:118
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:116
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:119
@ MLMESET_INVALID_PARAMETER
Definition: lr-wpan-mac.h:324
@ MLMESET_READ_ONLY
Definition: lr-wpan-mac.h:321
@ MLMESET_SUCCESS
Definition: lr-wpan-mac.h:320
@ MLMESET_UNSUPPORTED_ATTRIBUTE
Definition: lr-wpan-mac.h:322
@ TX_OPTION_ACK
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:63
@ TX_OPTION_INDIRECT
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:65
@ TX_OPTION_GTS
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:64
@ ASSOCIATED
Definition: lr-wpan-mac.h:168
@ PAN_ACCESS_DENIED
Definition: lr-wpan-mac.h:170
@ ASSOCIATED_WITHOUT_ADDRESS
Definition: lr-wpan-mac.h:171
@ PAN_AT_CAPACITY
Definition: lr-wpan-mac.h:169
@ DISASSOCIATED
Definition: lr-wpan-mac.h:172
@ MLMESTART_INVALID_PARAMETER
Definition: lr-wpan-mac.h:220
@ MLMESTART_SUCCESS
Definition: lr-wpan-mac.h:216
@ MLMESTART_NO_SHORT_ADDRESS
Definition: lr-wpan-mac.h:217
@ MLME_SCAN_REQ
Pending MLME-SCAN.request primitive.
Definition: lr-wpan-mac.h:120
@ MLME_ASSOC_REQ
Pending MLME-ASSOCIATION.request primitive.
Definition: lr-wpan-mac.h:121
@ MLME_START_REQ
Pending MLME-START.request primitive.
Definition: lr-wpan-mac.h:119
@ MLME_NONE
No pending primitive.
Definition: lr-wpan-mac.h:118
@ SHORT_ADDR
Definition: lr-wpan-mac.h:157
@ NO_PANID_ADDR
Definition: lr-wpan-mac.h:155
@ EXT_ADDR
Definition: lr-wpan-mac.h:158
@ ADDR_MODE_RESERVED
Definition: lr-wpan-mac.h:156
@ MLMEASSOC_NO_DATA
Definition: lr-wpan-mac.h:258
@ MLMEASSOC_ACCESS_DENIED
Definition: lr-wpan-mac.h:255
@ MLMEASSOC_CHANNEL_ACCESS_FAILURE
Definition: lr-wpan-mac.h:256
@ MLMEASSOC_SUCCESS
Definition: lr-wpan-mac.h:253
@ MLMEASSOC_INVALID_PARAMETER
Definition: lr-wpan-mac.h:262
@ MLMEASSOC_NO_ACK
Definition: lr-wpan-mac.h:257
@ MLMEASSOC_FULL_CAPACITY
Definition: lr-wpan-mac.h:254
@ INCOMING
Incoming Superframe.
Definition: lr-wpan-mac.h:108
@ OUTGOING
Outgoing Superframe.
Definition: lr-wpan-mac.h:107
@ MLMECOMMSTATUS_SUCCESS
Definition: lr-wpan-mac.h:285
@ MLMECOMMSTATUS_TRANSACTION_OVERFLOW
Definition: lr-wpan-mac.h:286
@ MLMECOMMSTATUS_TRANSACTION_EXPIRED
Definition: lr-wpan-mac.h:287
@ MLMECOMMSTATUS_CHANNEL_ACCESS_FAILURE
Definition: lr-wpan-mac.h:288
@ MLMECOMMSTATUS_NO_ACK
Definition: lr-wpan-mac.h:289
@ macBeaconPayloadLength
Definition: lr-wpan-mac.h:347
@ macShortAddress
Definition: lr-wpan-mac.h:348
@ macPanId
Definition: lr-wpan-mac.h:350
@ macBeaconPayload
Definition: lr-wpan-mac.h:346
@ macExtendedAddress
Definition: lr-wpan-mac.h:349
@ phyCurrentChannel
Definition: lr-wpan-phy.h:144
@ phyCurrentPage
Definition: lr-wpan-phy.h:148
@ MLMESYNCLOSS_BEACON_LOST
Definition: lr-wpan-mac.h:274
@ MLMEGET_SUCCESS
Definition: lr-wpan-mac.h:334
@ MLMEGET_UNSUPPORTED_ATTRIBUTE
Definition: lr-wpan-mac.h:335
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
SequenceNumber< uint8_t, int8_t > SequenceNumber8
8 bit Sequence number.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1325
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:419
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:421
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:420
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:431
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:403
MLME-ASSOCIATE.confirm params.
Definition: lr-wpan-mac.h:589
LrWpanMlmeAssociateConfirmStatus m_status
The status of a MLME-associate.request.
Definition: lr-wpan-mac.h:591
Mac16Address m_assocShortAddr
The short address used in the association request.
Definition: lr-wpan-mac.h:590
MLME-ASSOCIATE.indication params.
Definition: lr-wpan-mac.h:450
uint8_t lqi
The link quality indicator of the received associate request command (Not officially supported in the...
Definition: lr-wpan-mac.h:454
Mac64Address m_extDevAddr
The extended address of the device requesting association.
Definition: lr-wpan-mac.h:451
CapabilityField capabilityInfo
The operational capabilities of the device requesting association.
Definition: lr-wpan-mac.h:452
MLME-ASSOCIATE.request params.
Definition: lr-wpan-mac.h:569
uint8_t m_chNum
The channel number on which to attempt association.
Definition: lr-wpan-mac.h:570
CapabilityField m_capabilityInfo
Specifies the operational capabilities of the associating device.
Definition: lr-wpan-mac.h:580
uint8_t m_coordAddrMode
The coordinator addressing mode for this primitive and subsequent MPDU.
Definition: lr-wpan-mac.h:572
Mac64Address m_coordExtAddr
The extended address of the coordinator with which to associate.
Definition: lr-wpan-mac.h:578
Mac16Address m_coordShortAddr
The short address of the coordinator with which to associate.
Definition: lr-wpan-mac.h:576
uint16_t m_coordPanId
The identifier of the PAN with which to associate.
Definition: lr-wpan-mac.h:574
MLME-ASSOCIATE.response params.
Definition: lr-wpan-mac.h:464
MLME-BEACON-NOTIFY.indication params.
Definition: lr-wpan-mac.h:612
uint32_t m_sduLength
The number of octets contained in the beacon payload.
Definition: lr-wpan-mac.h:615
uint8_t m_bsn
The beacon sequence number.
Definition: lr-wpan-mac.h:613
Ptr< Packet > m_sdu
The set of octets comprising the beacon payload.
Definition: lr-wpan-mac.h:616
PanDescriptor m_panDescriptor
The PAN descriptor for the received beacon.
Definition: lr-wpan-mac.h:614
MLME-COMM-STATUS.indication params.
Definition: lr-wpan-mac.h:640
Mac16Address m_srcShortAddr
The short address of the entity from which the frame causing the error originated.
Definition: lr-wpan-mac.h:644
LrWpanMlmeCommStatus m_status
The communication status.
Definition: lr-wpan-mac.h:653
Mac16Address m_dstShortAddr
The short address of the device for which the frame was intended.
Definition: lr-wpan-mac.h:649
Mac64Address m_dstExtAddr
The extended address of the device for which the frame was intended.
Definition: lr-wpan-mac.h:651
uint16_t m_panId
The PAN identifier of the device from which the frame was received or to which the frame was being se...
Definition: lr-wpan-mac.h:641
Mac64Address m_srcExtAddr
The extended address of the entity from which the frame causing the error originated.
Definition: lr-wpan-mac.h:646
uint8_t m_dstAddrMode
The destination addressing mode for this primitive.
Definition: lr-wpan-mac.h:648
uint8_t m_srcAddrMode
The source addressing mode for this primitive.
Definition: lr-wpan-mac.h:643
MLME-ORPHAN.indication params.
Definition: lr-wpan-mac.h:662
Mac64Address m_orphanAddr
The address of the orphaned device.
Definition: lr-wpan-mac.h:663
MLME-ORPHAN.response params.
Definition: lr-wpan-mac.h:672
MLME-START.confirm params.
Definition: lr-wpan-mac.h:684
LrWpanMlmePollConfirmStatus m_status
The confirmation status resulting from a MLME-poll.request.
Definition: lr-wpan-mac.h:685
MLME-POLL.request params.
Definition: lr-wpan-mac.h:514
MLME-SCAN.confirm params.
Definition: lr-wpan-mac.h:547
std::vector< PanDescriptor > m_panDescList
A list of PAN descriptor, one for each beacon found (Not valid for ED and Orphan scans).
Definition: lr-wpan-mac.h:559
LrWpanMlmeScanType m_scanType
Indicates the type of scan performed (ED,ACTIVE,PASSIVE,ORPHAN).
Definition: lr-wpan-mac.h:549
uint32_t m_chPage
The channel page on which the scan was performed.
Definition: lr-wpan-mac.h:551
std::vector< uint8_t > m_unscannedCh
A list of channels given in the request which were not scanned (Not valid for ED scans).
Definition: lr-wpan-mac.h:552
LrWpanMlmeScanConfirmStatus m_status
The status the request.
Definition: lr-wpan-mac.h:548
std::vector< uint8_t > m_energyDetList
A list of energy measurements, one for each channel searched during ED scan (Not valid for Active,...
Definition: lr-wpan-mac.h:556
uint8_t m_resultListSize
The number of elements returned in the appropriate result list.
Definition: lr-wpan-mac.h:554
MLME-SCAN.request params.
Definition: lr-wpan-mac.h:528
uint32_t m_scanChannels
The channel numbers to be scanned.
Definition: lr-wpan-mac.h:531
uint32_t m_chPage
The channel page on which to perform scan.
Definition: lr-wpan-mac.h:538
uint8_t m_scanDuration
The factor (0-14) used to calculate the length of time to spend scanning.
Definition: lr-wpan-mac.h:534
LrWpanMlmeScanType m_scanType
Indicates the type of scan performed as described in IEEE 802.15.4-2011 (5.1.2.1).
Definition: lr-wpan-mac.h:529
MLME-SET.confirm params.
Definition: lr-wpan-mac.h:696
LrWpanMlmeSetConfirmStatus m_status
The result of the request to write the PIB attribute.
Definition: lr-wpan-mac.h:697
LrWpanMacPibAttributeIdentifier id
The id of the PIB attribute that was written.
Definition: lr-wpan-mac.h:700
MLME-START.confirm params.
Definition: lr-wpan-mac.h:601
LrWpanMlmeStartConfirmStatus m_status
The status of a MLME-start.request.
Definition: lr-wpan-mac.h:602
MLME-START.request params.
Definition: lr-wpan-mac.h:478
uint32_t m_logChPage
Logical channel page on which to start using the new superframe configuration.
Definition: lr-wpan-mac.h:482
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
Definition: lr-wpan-mac.h:480
bool m_panCoor
On true this device will become coordinator.
Definition: lr-wpan-mac.h:489
bool m_coorRealgn
True if a realignment request command is to be transmitted prior changing the superframe.
Definition: lr-wpan-mac.h:492
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
Definition: lr-wpan-mac.h:486
uint16_t m_PanId
Pan Identifier used by the device.
Definition: lr-wpan-mac.h:479
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.
Definition: lr-wpan-mac.h:488
bool m_battLifeExt
Flag indicating whether or not the Battery life extension (BLE) features are used.
Definition: lr-wpan-mac.h:490
MLME-SYNC-LOSS.indication params.
Definition: lr-wpan-mac.h:625
uint16_t m_panId
The PAN identifier with which the device lost synchronization or to which it was realigned.
Definition: lr-wpan-mac.h:628
LrWpanSyncLossReason m_lossReason
The reason for the lost of synchronization.
Definition: lr-wpan-mac.h:626
MLME-SYNC.request params.
Definition: lr-wpan-mac.h:502
PAN Descriptor, Table 17 IEEE 802.15.4-2011.
Definition: lr-wpan-mac.h:376
LrWpanAddressMode m_coorAddrMode
The coordinator addressing mode corresponding to the received beacon frame.
Definition: lr-wpan-mac.h:377
Mac64Address m_coorExtAddr
The coordinator extended address as specified in the coordinator address mode.
Definition: lr-wpan-mac.h:383
Mac16Address m_coorShortAddr
The coordinator short address as specified in the coordinator address mode.
Definition: lr-wpan-mac.h:381
uint8_t m_logChPage
The current channel page occupied by the network.
Definition: lr-wpan-mac.h:386
uint16_t m_coorPanId
The PAN ID of the coordinator as specified in the received beacon frame.
Definition: lr-wpan-mac.h:379
bool m_gtsPermit
TRUE if the beacon is from the PAN coordinator that is accepting GTS requests.
Definition: lr-wpan-mac.h:389
SuperframeField m_superframeSpec
The superframe specification as specified in the received beacon frame.
Definition: lr-wpan-mac.h:387
uint8_t m_linkQuality
The LQI at which the network beacon was received.
Definition: lr-wpan-mac.h:391
Time m_timeStamp
Beacon frame reception time.
Definition: lr-wpan-mac.h:393
uint8_t m_logCh
The current channel number occupied by the network.
Definition: lr-wpan-mac.h:385