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 
22 #ifndef OPENDSME_DSMEPLATFORM_H
23 #define OPENDSME_DSMEPLATFORM_H
24 
25 #include <stdint.h>
26 #include <stdlib.h>
27 
28 #include <string>
29 #include "random.h"
30 
31 #include "byteorder.h"
32 #include "dsmeAdaptionLayer/DSMEAdaptionLayer.h"
33 #include "dsmeLayer/DSMELayer.h"
34 #include "helper/DSMEDelegate.h"
35 #include "interfaces/IDSMEPlatform.h"
36 #include "mac_services/dataStructures/IEEE802154MacAddress.h"
37 #include "mac_services/mcps_sap/MCPS_SAP.h"
38 #include "mac_services/mlme_sap/MLME_SAP.h"
39 #include "mac_services/pib/MAC_PIB.h"
40 #include "mac_services/pib/PHY_PIB.h"
41 #include "mac_services/pib/dsme_phy_constants.h"
42 #include "mac_services/DSME_Common.h"
43 #include "net/gnrc/netif.h"
44 #include "net/ieee802154/radio.h"
45 #include "opendsme/dsme_settings.h"
46 #include "opendsme/DSMEMessage.h"
47 #include "ztimer.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 namespace dsme {
54 
55 struct DSMESettings;
56 class DSMELayer;
57 class DSMEAdaptionLayer;
58 
62 class DSMEPlatform : public IDSMEPlatform {
63 public:
72 
77 
81  void initialize(bool pan_coord);
82 
86  void sendFrame(uint16_t addr, iolist_t *pkt);
87 
91  void start();
92 
96  DSMELayer& getDSME() {
97  return dsme;
98  }
99 
103  bool isAssociated();
104 
105 #if IS_ACTIVE(CONFIG_IEEE802154_DSME_STATIC_GTS) || DOXYGEN
109  void allocateGTS(uint8_t superframeID, uint8_t slotID, uint8_t channelID,
110  Direction direction, uint16_t address);
111 #endif
112 
117 
121  void setGTSTransmission(bool gts);
122 
126  void setAckReq(bool ackReq);
127 
132 
137 
142 
147 
152 
157 
161  void setPlatformState(uint8_t state) {
162  this->state = state;
163  }
164 
169 
174 
179 
184 
189  this->netif = netif;
190  }
191 
195  enum {
196  STATE_READY = 0, STATE_CCA_WAIT = 1, STATE_SEND = 2,
197  };
198 
199  /*********** IDSMEPlatform implementation ***********/
200 
204  uint8_t getChannelNumber() override;
205 
209  bool setChannelNumber(uint8_t k) override;
210 
216  bool sendNow() override;
217 
221  bool prepareSendingCopy(IDSMEMessage* msg, Delegate<void(bool)> txEndCallback) override;
222 
226  bool prepareSendingCopy(DSMEMessage* msg, Delegate<void(bool)> txEndCallback);
227 
231  void abortPreparedTransmission() override;
232 
236  bool sendDelayedAck(IDSMEMessage *ackMsg, IDSMEMessage *receivedMsg,
237  Delegate<void(bool)> txEndCallback) override;
241  bool sendDelayedAck(DSMEMessage *ackMsg, DSMEMessage *receivedMsg,
242  Delegate<void(bool)> txEndCallback);
243 
247  void setReceiveDelegate(receive_delegate_t receiveDelegate) override;
248 
253 
257  void handleReceivedMessageFromAckLayer(IDSMEMessage* message) override;
258 
263 
268 
272  void releaseMessage(IDSMEMessage* msg) override;
273 
278 
282  bool startCCA() override;
283 
287  void startTimer(uint32_t symbolCounterValue) override;
288 
292  uint32_t getSymbolCounter() override;
293 
297  uint16_t getRandom() override {
298  return (random_uint32() % UINT16_MAX);
299  }
300 
306  void updateVisual() override;
307 
311  void scheduleStartOfCFP() override;
312 
317  uint8_t getMinCoordinatorLQI() override{
319  };
320 
324  void turnTransceiverOn() override;
325 
329  void turnTransceiverOff() override;
330 
334  IEEE802154MacAddress& getAddress() {
335  return this->mac_pib.macExtendedAddress;
336  }
337 
341  void signalAckedTransmissionResult(bool success, uint8_t transmissionAttempts,
342  IEEE802154MacAddress receiver) override;
343 
347  void signalGTSChange(bool deallocation, IEEE802154MacAddress counterpart,
348  uint16_t superframeID, uint8_t gtSlotID, uint8_t channel,
349  Direction direction) override;
350 
354  void signalQueueLength(uint32_t length) override;
355 
359  void signalPacketsPerCAP(uint32_t packets) override;
360 
364  void signalFailedPacketsPerCAP(uint32_t packets) override;
365 
369  bool isRxEnabledOnCap() override;
370 
371 protected:
380 
384  Delegate<void(bool)> txEndCallback;
385 
390 
394  virtual void signalReleasedMsg(DSMEMessage* msg) {}
395 
399  void handleDataMessageFromMCPSWrapper(IDSMEMessage* msg);
400 
405 
409  void handleConfirmFromMCPSWrapper(IDSMEMessage* msg, DataStatus::Data_Status dataStatus);
410 
414  void handleConfirmFromMCPS(DSMEMessage* msg, DataStatus::Data_Status dataStatus);
415 
419  void translateMacAddress(uint16_t& from, IEEE802154MacAddress& to);
420 
425  return &this->netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW];
426  }
427 
431  PHY_PIB phy_pib;
432 
436  MAC_PIB mac_pib;
437 
441  DSMELayer dsme;
442 
446  mcps_sap::MCPS_SAP mcps_sap;
447 
451  mlme_sap::MLME_SAP mlme_sap;
452 
456  DSMEAdaptionLayer dsmeAdaptionLayer;
457 
462 
466  bool scanOrSyncInProgress{false};
467 
472 
476  bool syncActive{false};
477 
481  bool rx_on_cap{true};
482 
486  receive_delegate_t receiveFromAckLayerDelegate;
487 
492 
497 
501  IDSMEMessage *message;
502 
506  GTSScheduling* scheduling = nullptr;
507 
511  uint32_t rx_sfd;
512 
517 
521  uint8_t state;
522 
527 
532 
537 };
538 
539 }
540 
541 #ifdef __cplusplus
542 }
543 #endif
544 
545 #endif /* OPENDSME_DSMEPLATFORM_H */
DSME Message interface implementation for GNRC.
Functions to work with different byte orders.
DSME Message interface implementation for GNRC.
Definition: DSMEMessage.h:50
DSMEPlatform interface implementation for GNRC.
Definition: DSMEPlatform.h:62
bool setChannelNumber(uint8_t k) override
set channel number
bool scanOrSyncInProgress
whether there is a scan or sync in progress
Definition: DSMEPlatform.h:466
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:76
~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:431
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:384
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:446
DSMELayer & getDSME()
get the DSME layer
Definition: DSMEPlatform.h:96
void offloadRXDoneEvent()
request to offload RX Done event
MAC_PIB mac_pib
holds the MAC Information Base
Definition: DSMEPlatform.h:436
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:536
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:506
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:394
bool isAssociated()
check whether the node associated
IEEE802154MacAddress & getAddress()
get extended address
Definition: DSMEPlatform.h:334
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:486
void handleReceivedMessageFromAckLayer(IDSMEMessage *message) override
handle reception of frames from ACK Layer
void setPlatformState(uint8_t state)
set the platform state
Definition: DSMEPlatform.h:161
gnrc_netif_t * netif
pointer to the GNRC interface
Definition: DSMEPlatform.h:491
ztimer_t acktimer
timer used for ACK timeout events
Definition: DSMEPlatform.h:516
uint8_t state
state of the platform layer
Definition: DSMEPlatform.h:521
void offloadCCAEvent()
request to offload the CCA Done event
event_queue_t * getEventQueue()
get the event queue of the MAC
Definition: DSMEPlatform.h:424
bool syncActive
whether the MAC is synchronized
Definition: DSMEPlatform.h:476
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:471
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:188
uint8_t getMinCoordinatorLQI() override
Get the minimum LQI.
Definition: DSMEPlatform.h:317
DSMEAdaptionLayer dsmeAdaptionLayer
descriptor of the DSME Adaption Layer
Definition: DSMEPlatform.h:456
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:496
IDSMEMessage * message
used to hold an incoming message before passing it to the MAC
Definition: DSMEPlatform.h:501
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:297
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:526
uint32_t rx_sfd
timestamp (in number of symbols) of the last received preamble
Definition: DSMEPlatform.h:511
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:461
DSMELayer dsme
descriptor of the DSME MAC
Definition: DSMEPlatform.h:441
bool rx_on_cap
whether the MAC keeps the receiver on during CAP
Definition: DSMEPlatform.h:481
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:531
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:451
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:90
#define CONFIG_IEEE802154_DSME_MIN_COORD_LQI
Set the minimum LQI to consider a beacon from a coordinator valid.
Definition: ieee802154.h:567
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:156
Representation of a network interface.
Definition: netif.h:135
event_queue_t evq[GNRC_NETIF_EVQ_NUMOF]
Event queue for asynchronous events.
Definition: netif.h:164
the IEEE802.15.4 device descriptor
Definition: radio.h:415
iolist structure definition
Definition: iolist.h:39
ztimer structure
Definition: ztimer.h:319
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:74
ztimer API