Loading...
Searching...
No Matches
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"
47#include "ztimer.h"
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53namespace dsme {
54
55struct DSMESettings;
56class DSMELayer;
57class DSMEAdaptionLayer;
58
62class DSMEPlatform : public IDSMEPlatform {
63public:
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
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
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
371protected:
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
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
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.
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.
#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:437
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:318
A 16 bit integer in big endian aka network byte order.
Definition byteorder.h:74
ztimer API