Loading...
Searching...
No Matches
DSMEPlatform.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 HAW Hamburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
20
21#include <stdint.h>
22#include <stdlib.h>
23
24#include <string>
25#include "random.h"
26
27#include "byteorder.h"
28#include "dsmeAdaptionLayer/DSMEAdaptionLayer.h"
29#include "dsmeLayer/DSMELayer.h"
30#include "helper/DSMEDelegate.h"
31#include "interfaces/IDSMEPlatform.h"
32#include "mac_services/dataStructures/IEEE802154MacAddress.h"
33#include "mac_services/mcps_sap/MCPS_SAP.h"
34#include "mac_services/mlme_sap/MLME_SAP.h"
35#include "mac_services/pib/MAC_PIB.h"
36#include "mac_services/pib/PHY_PIB.h"
37#include "mac_services/pib/dsme_phy_constants.h"
38#include "mac_services/DSME_Common.h"
39#include "net/gnrc/netif.h"
40#include "net/ieee802154/radio.h"
43#include "ztimer.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49namespace dsme {
50
51struct DSMESettings;
52class DSMELayer;
53class DSMEAdaptionLayer;
54
58class DSMEPlatform : public IDSMEPlatform {
59public:
68
73
77 void initialize(bool pan_coord);
78
82 void sendFrame(uint16_t addr, iolist_t *pkt);
83
87 void start();
88
92 DSMELayer& getDSME() {
93 return dsme;
94 }
95
100
101#if IS_ACTIVE(CONFIG_IEEE802154_DSME_STATIC_GTS) || DOXYGEN
105 void allocateGTS(uint8_t superframeID, uint8_t slotID, uint8_t channelID,
106 Direction direction, uint16_t address);
107#endif
108
113
117 void setGTSTransmission(bool gts);
118
122 void setAckReq(bool ackReq);
123
128
133
138
143
148
153
157 void setPlatformState(uint8_t state) {
158 this->state = state;
159 }
160
165
170
175
180
185 this->netif = netif;
186 }
187
191 enum {
192 STATE_READY = 0, STATE_CCA_WAIT = 1, STATE_SEND = 2,
193 };
194
195 /*********** IDSMEPlatform implementation ***********/
196
200 uint8_t getChannelNumber() override;
201
205 bool setChannelNumber(uint8_t k) override;
206
212 bool sendNow() override;
213
217 bool prepareSendingCopy(IDSMEMessage* msg, Delegate<void(bool)> txEndCallback) override;
218
222 bool prepareSendingCopy(DSMEMessage* msg, Delegate<void(bool)> txEndCallback);
223
228
232 bool sendDelayedAck(IDSMEMessage *ackMsg, IDSMEMessage *receivedMsg,
233 Delegate<void(bool)> txEndCallback) override;
237 bool sendDelayedAck(DSMEMessage *ackMsg, DSMEMessage *receivedMsg,
238 Delegate<void(bool)> txEndCallback);
239
243 void setReceiveDelegate(receive_delegate_t receiveDelegate) override;
244
249
253 void handleReceivedMessageFromAckLayer(IDSMEMessage* message) override;
254
259
264
268 void releaseMessage(IDSMEMessage* msg) override;
269
274
278 bool startCCA() override;
279
283 void startTimer(uint32_t symbolCounterValue) override;
284
288 uint32_t getSymbolCounter() override;
289
293 uint16_t getRandom() override {
294 return (random_uint32() % UINT16_MAX);
295 }
296
302 void updateVisual() override;
303
307 void scheduleStartOfCFP() override;
308
313 uint8_t getMinCoordinatorLQI() override{
315 };
316
320 void turnTransceiverOn() override;
321
325 void turnTransceiverOff() override;
326
330 IEEE802154MacAddress& getAddress() {
331 return this->mac_pib.macExtendedAddress;
332 }
333
337 void signalAckedTransmissionResult(bool success, uint8_t transmissionAttempts,
338 IEEE802154MacAddress receiver) override;
339
343 void signalGTSChange(bool deallocation, IEEE802154MacAddress counterpart,
344 uint16_t superframeID, uint8_t gtSlotID, uint8_t channel,
345 Direction direction) override;
346
350 void signalQueueLength(uint32_t length) override;
351
355 void signalPacketsPerCAP(uint32_t packets) override;
356
360 void signalFailedPacketsPerCAP(uint32_t packets) override;
361
365 bool isRxEnabledOnCap() override;
366
367protected:
376
380 Delegate<void(bool)> txEndCallback;
381
386
390 virtual void signalReleasedMsg(DSMEMessage* msg) {}
391
395 void handleDataMessageFromMCPSWrapper(IDSMEMessage* msg);
396
401
405 void handleConfirmFromMCPSWrapper(IDSMEMessage* msg, DataStatus::Data_Status dataStatus);
406
410 void handleConfirmFromMCPS(DSMEMessage* msg, DataStatus::Data_Status dataStatus);
411
415 void translateMacAddress(uint16_t& from, IEEE802154MacAddress& to);
416
423
427 PHY_PIB phy_pib;
428
432 MAC_PIB mac_pib;
433
437 DSMELayer dsme;
438
442 mcps_sap::MCPS_SAP mcps_sap;
443
447 mlme_sap::MLME_SAP mlme_sap;
448
452 DSMEAdaptionLayer dsmeAdaptionLayer;
453
458
463
468
472 bool syncActive{false};
473
477 bool rx_on_cap{true};
478
482 receive_delegate_t receiveFromAckLayerDelegate;
483
488
493
497 IDSMEMessage *message;
498
502 GTSScheduling* scheduling = nullptr;
503
507 uint32_t rx_sfd;
508
513
517 uint8_t state;
518
523
528
533};
534
535}
536
537#ifdef __cplusplus
538}
539#endif
540
DSME Message interface implementation for GNRC.
Functions to work with different byte orders.
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
Definition byteorder.h:92
DSME Message interface implementation for GNRC.
Definition DSMEMessage.h:46
bool setChannelNumber(uint8_t k) override
set channel number
bool scanOrSyncInProgress
whether there is a scan or sync in progress
bool startCCA() override
start CCA procedure
void updateVisual() override
update visual components of openDSME
DSMEMessage * getEmptyMessage() override
get an empty message
IEEE802154MacAddress & getAddress()
get extended address
static DSMEPlatform * instance
pointer to the DSME instance
~DSMEPlatform()
DSMEPlatform destructor.
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
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
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
void offloadRXDoneEvent()
request to offload RX Done event
MAC_PIB mac_pib
holds the MAC Information Base
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
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
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
bool isAssociated()
check whether the node associated
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
void handleReceivedMessageFromAckLayer(IDSMEMessage *message) override
handle reception of frames from ACK Layer
void setPlatformState(uint8_t state)
set the platform state
gnrc_netif_t * netif
pointer to the GNRC interface
DSMEPlatform & operator=(const DSMEPlatform &)
Assignment operator is not allowed.
ztimer_t acktimer
timer used for ACK timeout events
uint8_t state
state of the platform layer
void offloadCCAEvent()
request to offload the CCA Done event
bool syncActive
whether the MAC is synchronized
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
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
uint8_t getMinCoordinatorLQI() override
Get the minimum LQI.
DSMEAdaptionLayer dsmeAdaptionLayer
descriptor of the DSME Adaption Layer
void releaseMessage(DSMEMessage *msg)
release a message
event_queue_t * getEventQueue()
get the event queue of the MAC
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
IDSMEMessage * message
used to hold an incoming message before passing it to the MAC
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
void signalGTSChange(bool deallocation, IEEE802154MacAddress counterpart, uint16_t superframeID, uint8_t gtSlotID, uint8_t channel, Direction direction) override
signal a change in GTS status
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
uint32_t rx_sfd
timestamp (in number of symbols) of the last received preamble
void setGTSTransmission(bool gts)
set GTS or CAP transmission
void turnTransceiverOn() override
turn on transceiver
bool initialized
whether the MAC is initialized
DSMELayer dsme
descriptor of the DSME MAC
bool rx_on_cap
whether the MAC keeps the receiver on during CAP
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
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
DSMELayer & getDSME()
get the DSME layer
void processCCAEvent()
process the CCA Done event
uint32_t getSymbolCounter() override
get elapsed number of symbols since initialization
Definition for GNRC's network interfaces.
struct ieee802154_dev ieee802154_dev_t
Forward declaration of the IEEE802.15.4 device descriptor.
Definition radio.h:415
#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW
Index of the low priority queue.
Definition netif.h:92
#define CONFIG_IEEE802154_DSME_MIN_COORD_LQI
Set the minimum LQI to consider a beacon from a coordinator valid.
Definition ieee802154.h:556
struct PTRTAG event_queue_t
event queue structure
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:30
uint32_t random_uint32(void)
generates a random number on [0,0xffffffff]-interval
Common interface to the software PRNG.
Representation of a network interface.
Definition netif.h:137
ztimer structure
Definition ztimer.h:316
ztimer API