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
9#pragma once
10
23
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"
46#include "ztimer.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52namespace dsme {
53
54struct DSMESettings;
55class DSMELayer;
56class DSMEAdaptionLayer;
57
61class DSMEPlatform : public IDSMEPlatform {
62public:
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
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
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
370protected:
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
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
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.
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
Definition byteorder.h:107
DSME Message interface implementation for GNRC.
Definition DSMEMessage.h:49
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:407
#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
struct PTRTAG event_queue_t
event queue structure
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:33
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:132
ztimer structure
Definition ztimer.h:319
ztimer API