DSMEPlatform.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include <string>
28 #include "random.h"
29 
30 #include "byteorder.h"
31 #include "dsmeAdaptionLayer/DSMEAdaptionLayer.h"
32 #include "dsmeLayer/DSMELayer.h"
33 #include "helper/DSMEDelegate.h"
34 #include "interfaces/IDSMEPlatform.h"
35 #include "mac_services/dataStructures/IEEE802154MacAddress.h"
36 #include "mac_services/mcps_sap/MCPS_SAP.h"
37 #include "mac_services/mlme_sap/MLME_SAP.h"
38 #include "mac_services/pib/MAC_PIB.h"
39 #include "mac_services/pib/PHY_PIB.h"
40 #include "mac_services/pib/dsme_phy_constants.h"
41 #include "mac_services/DSME_Common.h"
42 #include "net/gnrc/netif.h"
43 #include "net/ieee802154/radio.h"
44 #include "opendsme/dsme_settings.h"
45 #include "opendsme/DSMEMessage.h"
46 #include "ztimer.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 namespace dsme {
53 
54 struct DSMESettings;
55 class DSMELayer;
56 class DSMEAdaptionLayer;
57 
61 class DSMEPlatform : public IDSMEPlatform {
62 public:
71 
76 
80  void initialize(bool pan_coord);
81 
85  void sendFrame(uint16_t addr, iolist_t *pkt);
86 
90  void start();
91 
95  DSMELayer& getDSME() {
96  return dsme;
97  }
98 
102  bool isAssociated();
103 
104 #if IS_ACTIVE(CONFIG_IEEE802154_DSME_STATIC_GTS) || DOXYGEN
108  void allocateGTS(uint8_t superframeID, uint8_t slotID, uint8_t channelID,
109  Direction direction, uint16_t address);
110 #endif
111 
116 
120  void setGTSTransmission(bool gts);
121 
125  void setAckReq(bool ackReq);
126 
131 
136 
141 
146 
151 
156 
160  void setPlatformState(uint8_t state) {
161  this->state = state;
162  }
163 
168 
173 
178 
183 
188  this->netif = netif;
189  }
190 
194  enum {
195  STATE_READY = 0, STATE_CCA_WAIT = 1, STATE_SEND = 2,
196  };
197 
198  /*********** IDSMEPlatform implementation ***********/
199 
203  uint8_t getChannelNumber() override;
204 
208  bool setChannelNumber(uint8_t k) override;
209 
215  bool sendNow() override;
216 
220  bool prepareSendingCopy(IDSMEMessage* msg, Delegate<void(bool)> txEndCallback) override;
221 
225  bool prepareSendingCopy(DSMEMessage* msg, Delegate<void(bool)> txEndCallback);
226 
230  void abortPreparedTransmission() override;
231 
235  bool sendDelayedAck(IDSMEMessage *ackMsg, IDSMEMessage *receivedMsg,
236  Delegate<void(bool)> txEndCallback) override;
240  bool sendDelayedAck(DSMEMessage *ackMsg, DSMEMessage *receivedMsg,
241  Delegate<void(bool)> txEndCallback);
242 
246  void setReceiveDelegate(receive_delegate_t receiveDelegate) override;
247 
252 
256  void handleReceivedMessageFromAckLayer(IDSMEMessage* message) override;
257 
262 
267 
271  void releaseMessage(IDSMEMessage* msg) override;
272 
277 
281  bool startCCA() override;
282 
286  void startTimer(uint32_t symbolCounterValue) override;
287 
291  uint32_t getSymbolCounter() override;
292 
296  uint16_t getRandom() override {
297  return (random_uint32() % UINT16_MAX);
298  }
299 
305  void updateVisual() override;
306 
310  void scheduleStartOfCFP() override;
311 
316  uint8_t getMinCoordinatorLQI() override{
318  };
319 
323  void turnTransceiverOn() override;
324 
328  void turnTransceiverOff() override;
329 
333  IEEE802154MacAddress& getAddress() {
334  return this->mac_pib.macExtendedAddress;
335  }
336 
340  void signalAckedTransmissionResult(bool success, uint8_t transmissionAttempts,
341  IEEE802154MacAddress receiver) override;
342 
346  void signalGTSChange(bool deallocation, IEEE802154MacAddress counterpart,
347  uint16_t superframeID, uint8_t gtSlotID, uint8_t channel,
348  Direction direction) override;
349 
353  void signalQueueLength(uint32_t length) override;
354 
358  void signalPacketsPerCAP(uint32_t packets) override;
359 
363  void signalFailedPacketsPerCAP(uint32_t packets) override;
364 
368  bool isRxEnabledOnCap() override;
369 
370 protected:
379 
383  Delegate<void(bool)> txEndCallback;
384 
389 
393  virtual void signalReleasedMsg(DSMEMessage* msg) {}
394 
398  void handleDataMessageFromMCPSWrapper(IDSMEMessage* msg);
399 
404 
408  void handleConfirmFromMCPSWrapper(IDSMEMessage* msg, DataStatus::Data_Status dataStatus);
409 
413  void handleConfirmFromMCPS(DSMEMessage* msg, DataStatus::Data_Status dataStatus);
414 
418  void translateMacAddress(uint16_t& from, IEEE802154MacAddress& to);
419 
424  return &this->netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW];
425  }
426 
430  PHY_PIB phy_pib;
431 
435  MAC_PIB mac_pib;
436 
440  DSMELayer dsme;
441 
445  mcps_sap::MCPS_SAP mcps_sap;
446 
450  mlme_sap::MLME_SAP mlme_sap;
451 
455  DSMEAdaptionLayer dsmeAdaptionLayer;
456 
461 
465  bool scanOrSyncInProgress{false};
466 
471 
475  bool syncActive{false};
476 
480  bool rx_on_cap{true};
481 
485  receive_delegate_t receiveFromAckLayerDelegate;
486 
491 
496 
500  IDSMEMessage *message;
501 
505  GTSScheduling* scheduling = nullptr;
506 
510  uint32_t rx_sfd;
511 
516 
520  uint8_t state;
521 
526 
531 
536 };
537 
538 }
539 
540 #ifdef __cplusplus
541 }
542 #endif
543 
DSME Message interface implementation for GNRC.
Functions to work with different byte orders.
DSME Message interface implementation for GNRC.
Definition: DSMEMessage.h:49
DSMEPlatform interface implementation for GNRC.
Definition: DSMEPlatform.h:61
bool setChannelNumber(uint8_t k) override
set channel number
bool scanOrSyncInProgress
whether there is a scan or sync in progress
Definition: DSMEPlatform.h:465
bool startCCA() override
start CCA procedure
void updateVisual() override
update visual components of openDSME
static DSMEPlatform * instance
pointer to the DSME instance
Definition: DSMEPlatform.h:75
~DSMEPlatform()
DSMEPlatform destructor.
DSMEMessage * getEmptyMessage() override
get an empty message
void handleConfirmFromMCPSWrapper(IDSMEMessage *msg, DataStatus::Data_Status dataStatus)
dSMEAdaptionLayer wrapper for MCPS Confirm callbacks
void processRxOffload()
process the offload event of received frame
bool sendDelayedAck(DSMEMessage *ackMsg, DSMEMessage *receivedMsg, Delegate< void(bool)> txEndCallback)
send an ACK message, delay until aTurnaRoundTime after reception_time has expired
PHY_PIB phy_pib
holds the PHY Information Base
Definition: DSMEPlatform.h:430
bool sendNow() override
Directly send packet without delay and without CSMA but keep the message (the caller has to ensure th...
void setAckReq(bool ackReq)
set ACK_REQ bit
void handleDataMessageFromMCPS(DSMEMessage *msg)
dSMEAdaptionLayer wrapper for MCPS Indication callbacks
Delegate< void(bool)> txEndCallback
delegate callback for TX end
Definition: DSMEPlatform.h:383
void offloadTXDoneEvent()
request to offload the TX Done event
void releaseMessage(IDSMEMessage *msg) override
release a message
void handleDataMessageFromMCPSWrapper(IDSMEMessage *msg)
dSMEAdaptionLayer wrapper for MCPS Indication callbacks
mcps_sap::MCPS_SAP mcps_sap
descriptor of the MCPS Service Access Point
Definition: DSMEPlatform.h:445
DSMELayer & getDSME()
get the DSME layer
Definition: DSMEPlatform.h:95
void offloadRXDoneEvent()
request to offload RX Done event
MAC_PIB mac_pib
holds the MAC Information Base
Definition: DSMEPlatform.h:435
void signalAckedTransmissionResult(bool success, uint8_t transmissionAttempts, IEEE802154MacAddress receiver) override
signal finish of ACK'd transmission
void scheduleStartOfCFP() override
callback to offload the start of CFP
void offloadTimerEvent()
request to offload Timer event
ieee802154_dev_t * radio
pointer to the IEEE 802.15.4 HAL descriptor
Definition: DSMEPlatform.h:535
void signalPacketsPerCAP(uint32_t packets) override
signal the number of packets transmitted during the last CAP
bool isReceptionFromAckLayerPossible() override
check whether the ACK layer is busy
void abortPreparedTransmission() override
abort an already prepared transmission
bool prepareSendingCopy(IDSMEMessage *msg, Delegate< void(bool)> txEndCallback) override
prepare the next transmission
GTSScheduling * scheduling
pointer to the scheduler
Definition: DSMEPlatform.h:505
bool sendDelayedAck(IDSMEMessage *ackMsg, IDSMEMessage *receivedMsg, Delegate< void(bool)> txEndCallback) override
send an ACK message, delay until aTurnaRoundTime after reception_time has expired
virtual void signalReleasedMsg(DSMEMessage *msg)
signal release of message
Definition: DSMEPlatform.h:393
bool isAssociated()
check whether the node associated
IEEE802154MacAddress & getAddress()
get extended address
Definition: DSMEPlatform.h:333
void startTimer(uint32_t symbolCounterValue) override
start timer
void processRxDone()
process the RX Done event from radio
void offloadACKTimer()
request to offload ACK Timer event
receive_delegate_t receiveFromAckLayerDelegate
delegate callback for passing frames to the ACK layer
Definition: DSMEPlatform.h:485
void handleReceivedMessageFromAckLayer(IDSMEMessage *message) override
handle reception of frames from ACK Layer
void setPlatformState(uint8_t state)
set the platform state
Definition: DSMEPlatform.h:160
gnrc_netif_t * netif
pointer to the GNRC interface
Definition: DSMEPlatform.h:490
ztimer_t acktimer
timer used for ACK timeout events
Definition: DSMEPlatform.h:515
uint8_t state
state of the platform layer
Definition: DSMEPlatform.h:520
void offloadCCAEvent()
request to offload the CCA Done event
event_queue_t * getEventQueue()
get the event queue of the MAC
Definition: DSMEPlatform.h:423
bool syncActive
whether the MAC is synchronized
Definition: DSMEPlatform.h:475
DSMEPlatform()
DSMEPlatform constructor.
void signalNewMsg(DSMEMessage *msg)
signal creation of new message
bool isRxEnabledOnCap() override
callback to check where RX is on during CAP
bool associationInProgress
whether the association is in progress
Definition: DSMEPlatform.h:470
void getShortAddress(network_uint16_t *addr)
get short address
DSMEPlatform(const DSMEPlatform &)
Copy constructor is not allowed.
void handleReceivedMessageFromAckLayer(DSMEMessage *message)
handle reception of frames from ACK Layer
void setGNRCNetif(gnrc_netif_t *netif)
set the GNRC netif
Definition: DSMEPlatform.h:187
uint8_t getMinCoordinatorLQI() override
Get the minimum LQI.
Definition: DSMEPlatform.h:316
DSMEAdaptionLayer dsmeAdaptionLayer
descriptor of the DSME Adaption Layer
Definition: DSMEPlatform.h:455
void releaseMessage(DSMEMessage *msg)
release a message
uint8_t getChannelNumber() override
get channel number
void signalQueueLength(uint32_t length) override
signal a change in queue length
void setReceiveDelegate(receive_delegate_t receiveDelegate) override
set the receive callback
void start()
start DSME
ztimer_t timer
timer used for the MAC
Definition: DSMEPlatform.h:495
IDSMEMessage * message
used to hold an incoming message before passing it to the MAC
Definition: DSMEPlatform.h:500
void initialize(bool pan_coord)
initialize MAC with a role (PAN coordinator, child)
void allocateGTS(uint8_t superframeID, uint8_t slotID, uint8_t channelID, Direction direction, uint16_t address)
allocate a GTS slot
uint16_t getRandom() override
get a uint16_t random number
Definition: DSMEPlatform.h:296
void signalGTSChange(bool deallocation, IEEE802154MacAddress counterpart, uint16_t superframeID, uint8_t gtSlotID, uint8_t channel, Direction direction) override
signal a change in GTS status
DSMEPlatform & operator=(const DSMEPlatform &)
Assignment operator is not allowed.
void sendFrame(uint16_t addr, iolist_t *pkt)
to be called by the upper layer in order to send a frame
void turnTransceiverOff() override
turn off transceiver
void processTXDoneEvent()
process the TX Done event
bool wait_for_ack
whether the MAC expects an ACK frame
Definition: DSMEPlatform.h:525
uint32_t rx_sfd
timestamp (in number of symbols) of the last received preamble
Definition: DSMEPlatform.h:510
void setGTSTransmission(bool gts)
set GTS or CAP transmission
void turnTransceiverOn() override
turn on transceiver
bool initialized
whether the MAC is initialized
Definition: DSMEPlatform.h:460
DSMELayer dsme
descriptor of the DSME MAC
Definition: DSMEPlatform.h:440
bool rx_on_cap
whether the MAC keeps the receiver on during CAP
Definition: DSMEPlatform.h:480
bool prepareSendingCopy(DSMEMessage *msg, Delegate< void(bool)> txEndCallback)
prepare the next transmission
void handleConfirmFromMCPS(DSMEMessage *msg, DataStatus::Data_Status dataStatus)
dSMEAdaptionLayer wrapper for MCPS Confirm callbacks
bool pending_tx
whether there is a pending TX frame
Definition: DSMEPlatform.h:530
void signalFailedPacketsPerCAP(uint32_t packets) override
signal the number of failed packets transmitted during the last CAP
void indicateRxStart()
indicate the MAC layer that the reception started
void translateMacAddress(uint16_t &from, IEEE802154MacAddress &to)
translate MAC Address representation
mlme_sap::MLME_SAP mlme_sap
descriptor of the MLME Service Access Point
Definition: DSMEPlatform.h:450
void processCCAEvent()
process the CCA Done event
uint32_t getSymbolCounter() override
get elapsed number of symbols since initialization
Definition for GNRC's network interfaces.
#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW
Index of the low priority queue.
Definition: netif.h:87
#define CONFIG_IEEE802154_DSME_MIN_COORD_LQI
Set the minimum LQI to consider a beacon from a coordinator valid.
Definition: ieee802154.h:566
uint32_t random_uint32(void)
generates a random number on [0,0xffffffff]-interval
Common interface to the software PRNG.
event queue structure
Definition: event.h:153
Representation of a network interface.
Definition: netif.h:132
event_queue_t evq[GNRC_NETIF_EVQ_NUMOF]
Event queue for asynchronous events.
Definition: netif.h:158
the IEEE802.15.4 device descriptor
Definition: radio.h:421
iolist structure definition
Definition: iolist.h:38
ztimer structure
Definition: ztimer.h:319
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:73
ztimer API