![]() |
SX126x-Arduino
2.0.1
|
#include "boards/mcu/board.h"
#include "system/utilities.h"
#include "LoRaMac.h"
#include "region/Region.h"
#include "LoRaMacCrypto.h"
#include "LoRaMacTest.h"
Macros | |
#define | LORAMAC_PHY_MAXPAYLOAD 255 |
#define | LORA_MAC_COMMAND_MAX_LENGTH 128 |
#define | LORA_MAC_COMMAND_MAX_FOPTS_LENGTH 15 |
#define | BACKOFF_DC_1_HOUR 100 |
#define | BACKOFF_DC_10_HOURS 1000 |
#define | BACKOFF_DC_24_HOURS 10000 |
Enumerations | |
enum | eLoRaMacState { LORAMAC_IDLE = 0x00000000, LORAMAC_TX_RUNNING = 0x00000001, LORAMAC_RX = 0x00000002, LORAMAC_ACK_REQ = 0x00000004, LORAMAC_ACK_RETRY = 0x00000008, LORAMAC_TX_DELAYED = 0x00000010, LORAMAC_TX_CONFIG = 0x00000020, LORAMAC_RX_ABORT = 0x00000040 } |
Functions | |
static void | OnRadioTxDone (void) |
Function to be executed on Radio Tx Done event. More... | |
static void | PrepareRxDoneAbort (void) |
This function prepares the MAC to abort the execution of function OnRadioRxDone in case of a reception error. More... | |
static void | OnRadioRxDone (uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) |
Function to be executed on Radio Rx Done event. More... | |
static void | OnRadioTxTimeout (void) |
Function executed on Radio Tx Timeout event. More... | |
static void | OnRadioRxError (void) |
Function executed on Radio Rx error event. More... | |
static void | OnRadioRxTimeout (void) |
Function executed on Radio Rx Timeout event. More... | |
static void | OnMacStateCheckTimerEvent (void) |
Function executed on Resend Frame timer event. More... | |
static void | OnTxDelayedTimerEvent (void) |
Function executed on duty cycle delayed Tx timer event. More... | |
static void | OnRxWindow1TimerEvent (void) |
Function executed on first Rx window timer event. More... | |
static void | OnRxWindow2TimerEvent (void) |
Function executed on second Rx window timer event. More... | |
static void | OnAckTimeoutTimerEvent (void) |
Function executed on AckTimeout timer event. More... | |
static void | RxWindowSetup (bool rxContinuous, uint32_t maxRxWindow) |
Initializes and opens the reception window. More... | |
static LoRaMacStatus_t | AddMacCommand (uint8_t cmd, uint8_t p1, uint8_t p2) |
Adds a new MAC command to be sent. More... | |
static uint8_t | ParseMacCommandsToRepeat (uint8_t *cmdBufIn, uint8_t length, uint8_t *cmdBufOut) |
Parses the MAC commands which must be repeated. More... | |
static bool | ValidatePayloadLength (uint8_t lenN, int8_t datarate, uint8_t fOptsLen) |
Validates if the payload fits into the frame, taking the datarate into account. More... | |
static void | ProcessMacCommands (uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr) |
Decodes MAC commands in the fOpts field and in the payload. More... | |
LoRaMacStatus_t | Send (LoRaMacHeader_t *macHdr, uint8_t fPort, void *fBuffer, uint16_t fBufferSize) |
LoRaMAC layer generic send frame. More... | |
LoRaMacStatus_t | PrepareFrame (LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort, void *fBuffer, uint16_t fBufferSize) |
LoRaMAC layer frame buffer initialization. More... | |
static LoRaMacStatus_t | ScheduleTx (void) |
static void | CalculateBackOff (uint8_t channel) |
LoRaMacStatus_t | SendFrameOnChannel (uint8_t channel) |
LoRaMAC layer prepared frame buffer transmission with channel specification. More... | |
LoRaMacStatus_t | SetTxContinuousWave (uint16_t timeout) |
Sets the radio in continuous transmission mode. More... | |
LoRaMacStatus_t | SetTxContinuousWave1 (uint16_t timeout, uint32_t frequency, uint8_t power) |
Sets the radio in continuous transmission mode. More... | |
static void | ResetMacParameters (void) |
Resets MAC specific parameters to default. More... | |
LoRaMacStatus_t | LoRaMacInitialization (LoRaMacPrimitives_t *primitives, LoRaMacCallback_t *callbacks, LoRaMacRegion_t region, eDeviceClass nodeClass) |
LoRaMAC layer initialization. More... | |
LoRaMacStatus_t | LoRaMacQueryTxPossible (uint8_t size, LoRaMacTxInfo_t *txInfo) |
Queries the LoRaMAC if it is possible to send the next frame with a given payload size. The LoRaMAC takes scheduled MAC commands into account and reports, when the frame can be send or not. More... | |
LoRaMacStatus_t | LoRaMacMibGetRequestConfirm (MibRequestConfirm_t *mibGet) |
LoRaMAC MIB-Get. More... | |
LoRaMacStatus_t | LoRaMacMibSetRequestConfirm (MibRequestConfirm_t *mibSet) |
LoRaMAC MIB-Set. More... | |
LoRaMacStatus_t | LoRaMacChannelAdd (uint8_t id, ChannelParams_t params) |
LoRaMAC channel add service. More... | |
LoRaMacStatus_t | LoRaMacChannelRemove (uint8_t id) |
LoRaMAC channel remove service. More... | |
LoRaMacStatus_t | LoRaMacMulticastChannelLink (MulticastParams_t *channelParam) |
LoRaMAC multicast channel link service. More... | |
LoRaMacStatus_t | LoRaMacMulticastChannelUnlink (MulticastParams_t *channelParam) |
LoRaMAC multicast channel unlink service. More... | |
LoRaMacStatus_t | LoRaMacMlmeRequest (MlmeReq_t *mlmeRequest) |
LoRaMAC MLME-Request. More... | |
LoRaMacStatus_t | LoRaMacMcpsRequest (McpsReq_t *mcpsRequest) |
LoRaMAC MCPS-Request. More... | |
void | LoRaMacTestRxWindowsOn (bool enable) |
Enabled or disables the reception windows. More... | |
void | LoRaMacTestSetMic (uint16_t txPacketCounter) |
Enables the MIC field test. More... | |
void | LoRaMacTestSetDutyCycleOn (bool enable) |
Enabled or disables the duty cycle. More... | |
void | LoRaMacTestSetChannel (uint8_t channel) |
Sets the channel index. More... | |
uint32_t | LoRaMacGetOTAADevId (void) |
Returns the Device Address set by the LoRaWan server after OTAA join was successful. More... | |
#define LORAMAC_PHY_MAXPAYLOAD 255 |
Maximum PHY layer payload size
#define LORA_MAC_COMMAND_MAX_LENGTH 128 |
Maximum MAC commands buffer size
#define LORA_MAC_COMMAND_MAX_FOPTS_LENGTH 15 |
Maximum length of the fOpts field
#define BACKOFF_DC_1_HOUR 100 |
LoRaMac duty cycle for the back-off procedure during the first hour.
#define BACKOFF_DC_10_HOURS 1000 |
LoRaMac duty cycle for the back-off procedure during the next 10 hours.
#define BACKOFF_DC_24_HOURS 10000 |
LoRaMac duty cycle for the back-off procedure during the next 24 hours.
enum eLoRaMacState |
|
static |
Function to be executed on Radio Tx Done event.
|
static |
This function prepares the MAC to abort the execution of function OnRadioRxDone in case of a reception error.
|
static |
Function to be executed on Radio Rx Done event.
|
static |
Function executed on Radio Tx Timeout event.
|
static |
Function executed on Radio Rx error event.
|
static |
Function executed on Radio Rx Timeout event.
|
static |
Function executed on Resend Frame timer event.
|
static |
Function executed on duty cycle delayed Tx timer event.
|
static |
Function executed on first Rx window timer event.
|
static |
Function executed on second Rx window timer event.
|
static |
Function executed on AckTimeout timer event.
|
static |
Initializes and opens the reception window.
rxContinuous | Set to true, if the RX is in continuous mode |
maxRxWindow | Maximum RX window timeout |
|
static |
Adds a new MAC command to be sent.
cmd | MAC command to be added [MOTE_MAC_LINK_CHECK_REQ, MOTE_MAC_LINK_ADR_ANS, MOTE_MAC_DUTY_CYCLE_ANS, MOTE_MAC_RX2_PARAM_SET_ANS, MOTE_MAC_DEV_STATUS_ANS MOTE_MAC_NEW_CHANNEL_ANS] |
p1 | 1st parameter ( optional depends on the command ) |
p2 | 2nd parameter ( optional depends on the command ) |
status | Function status [0: OK, 1: Unknown command, 2: Buffer full] |
|
static |
Parses the MAC commands which must be repeated.
cmdBufIn | Buffer which stores the MAC commands to send |
length | Length of the input buffer to parse |
cmdBufOut | Buffer which stores the MAC commands which must be repeated. |
Size | of the MAC commands to repeat. |
|
static |
Validates if the payload fits into the frame, taking the datarate into account.
Refer to chapter 4.3.2 of the LoRaWAN specification, v1.0
lenN | Length of the application payload. The length depends on the datarate and is region specific |
datarate | Current datarate |
fOptsLen | Length of the fOpts field |
[false | payload does not fit into the frame, true: payload fits into the frame] |
|
static |
Decodes MAC commands in the fOpts field and in the payload.
LoRaMacStatus_t Send | ( | LoRaMacHeader_t * | macHdr, |
uint8_t | fPort, | ||
void * | fBuffer, | ||
uint16_t | fBufferSize | ||
) |
LoRaMAC layer generic send frame.
macHdr | MAC header field |
fPort | MAC payload port |
fBuffer | MAC data buffer to be sent |
fBufferSize | MAC data buffer size |
status | Status of the operation. |
LoRaMacStatus_t PrepareFrame | ( | LoRaMacHeader_t * | macHdr, |
LoRaMacFrameCtrl_t * | fCtrl, | ||
uint8_t | fPort, | ||
void * | fBuffer, | ||
uint16_t | fBufferSize | ||
) |
LoRaMAC layer frame buffer initialization.
macHdr | MAC header field |
fCtrl | MAC frame control field |
fPort | MAC payload port |
fBuffer | MAC data buffer to be sent |
fBufferSize | MAC data buffer size |
status | Status of the operation. |
|
static |
|
static |
LoRaMacStatus_t SendFrameOnChannel | ( | uint8_t | channel | ) |
LoRaMAC layer prepared frame buffer transmission with channel specification.
channel | Channel to transmit on |
status | Status of the operation. |
LoRaMacStatus_t SetTxContinuousWave | ( | uint16_t | timeout | ) |
Sets the radio in continuous transmission mode.
timeout | Time in seconds while the radio is kept in continuous wave mode |
status | Status of the operation. |
LoRaMacStatus_t SetTxContinuousWave1 | ( | uint16_t | timeout, |
uint32_t | frequency, | ||
uint8_t | power | ||
) |
Sets the radio in continuous transmission mode.
timeout | Time in seconds while the radio is kept in continuous wave mode |
frequency | RF frequency to be set. |
power | RF output power to be set. |
status | Status of the operation. |
|
static |
Resets MAC specific parameters to default.
bool lmh_mac_is_busy |
bool singleChannelGateway |
Flag if connection is to a single channel gateway
uint8_t singleChannelSelected |
Channel to be used to communicate with a single channel gateway
int8_t singleChannelDatarate |
Datarate to be used to communicate with a single channel gateway
|
static |
Device IEEE EUI
|
static |
Application IEEE EUI
|
static |
AES encryption/decryption cipher application key
|
static |
AES encryption/decryption cipher network session key
|
static |
AES encryption/decryption cipher application session key
|
static |
Device nonce is a random value extracted by issuing a sequence of RSSI measurements
|
static |
Network ID ( 3 bytes )
|
static |
Mote Address
|
static |
Multicast channels linked list
|
static |
Actual device class
|
static |
Indicates if the node is connected to a private or public network
|
static |
Indicates if the node supports repeaters
|
static |
Buffer containing the data to be sent or received.
|
static |
Length of packet in LoRaMacBuffer
|
static |
Length of the payload in LoRaMacBuffer
|
static |
Buffer containing the upper layer data.
|
static |
LoRaMAC frame counter. Each time a packet is sent the counter is incremented. Only the 16 LSB bits are sent
|
static |
LoRaMAC frame counter. Each time a packet is received the counter is incremented. Only the 16 LSB bits are received
|
static |
IsPacketCounterFixed enables the MIC field tests by fixing the UpLinkCounter value
|
static |
Used for test purposes. Disables the opening of the reception windows.
eJoinStatus_t IsLoRaMacNetworkJoined = JOIN_NOT_START |
Indicates if the MAC layer has already joined a network.
|
static |
LoRaMac ADR control status
|
static |
Counts the number of missed ADR acknowledgements
|
static |
If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates if the nodes needs to manage the server acknowledgement.
|
static |
If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates if the ACK bit must be set for the next transmission
|
static |
Indicates if the MAC layer wants to send MAC commands
|
static |
Contains the current MacCommandsBuffer index
|
static |
Contains the current MacCommandsBuffer index for MAC commands to repeat
|
static |
Buffer containing the MAC layer commands
|
static |
Buffer containing the MAC layer commands which must be repeated
LoRaMacParams_t LoRaMacParams |
LoRaMac parameters
LoRaMacParams_t LoRaMacParamsDefaults |
LoRaMac default parameters
|
static |
Uplink messages repetitions counter
|
static |
Maximum duty cycle
|
static |
Aggregated duty cycle management
|
static |
|
static |
|
static |
Enables/Disables duty cycle management (Test only)
|
static |
Current channel index
|
static |
Current channel index
|
static |
Set to true, if the last uplink was a join request
|
static |
Stores the time at LoRaMac initialization.
uint32_t LoRaMacState = LORAMAC_IDLE |
LoRaMac internal state
|
static |
LoRaMac timer used to check the LoRaMacState (runs every second)
|
static |
LoRaMac upper layer event functions
|
static |
LoRaMac upper layer callback functions
|
static |
Radio events function pointer
|
static |
LoRaMac duty cycle delayed Tx timer
|
static |
LoRaMac reception windows timers
|
static |
|
static |
LoRaMac reception windows delay
|
static |
|
static |
LoRaMac Rx windows configuration
|
static |
|
static |
Acknowledge timeout timer. Used for packet retransmissions.
|
static |
Number of trials to get a frame acknowledged
|
static |
Number of trials to get a frame acknowledged
|
static |
Indicates if the AckTimeout timer has expired or not
TimerTime_t TxTimeOnAir = 0 |
Last transmission time on air
|
static |
Number of trials for the Join Request
|
static |
Maximum number of trials for the Join Request
|
static |
Structure to hold an MCPS indication data.
|
static |
Structure to hold MCPS confirm data.
|
static |
Structure to hold MLME confirm data.
|
static |
Holds the current rx window slot
LoRaMacFlags_t LoRaMacFlags |
LoRaMac tx/rx operation state