LoRaWAN end device MAC layer for SX1272 and SX1276. Supports LoRaWAN-1.0 and LoRaWAN-1.1

Dependencies:   sx12xx_hal

Dependents:   LoRaWAN-SanJose_Bootcamp LoRaWAN-grove-cayenne LoRaWAN-classC-demo LoRaWAN-grove-cayenne ... more

radio chip selection

Radio chip driver is not included, because two options are available.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

application project requirements

This library requires mbed TLS to be enabled.
The file mbed_app.json must be present in the project using this library:

{
    "macros": [ "MBEDTLS_CMAC_C" ]
}

regional PHY selection

All end device configuration is done in Commissioning.h, define desired radio frequency band of operation in this header file.
Commissioning.h is located in the application using this library.

end device provisioning

End device is provisioned by editing Commissioning.h in the application which is using this library
To use LoRaWAN-1.0 OTA: make sure LORAWAN_ROOT_APPKEY is undefined.
To use LoRaWAN-1.1 OTA, define LORAWAN_ROOT_APPKEY.
To select OTA operation, define LORAWAN_JOIN_EUI, then LORAWAN_DEVICE_EUI must be defined, along with root key(s).
To select ABP operation, undefine LORAWAN_JOIN_EUI: then define session keys

LoRaWAN 1.0 nameLoRaWAN 1.1 nameComissioning.h defnedescription
OTADevEUIDevEUILORAWAN_DEVICE_EUIuniquely identifies end device
OTAAppEUIJoinEUILORAWAN_JOIN_EUI
OTAAppKeyNwkKeyLORAWAN_ROOT_NWKKEYroot key for network server
OTA(note 1)AppKeyLORAWAN_ROOT_APPKEYroot key for application server
ABPNwkSKey(note 3)LORAWAN_FNwkSIntKeynetwork session key
ABP(note 2)SNwkSIntKeyLORAWAN_SNwkSIntKeymac layer network integrity key
ABP(note 2)NwkSEncKeyLORAWAN_NwkSEncKeynetwork session encryption key
ABP(note 2)FNwkSIntKeyLORAWAN_FNwkSIntKeyforwarding network session integrity key
ABPAppSKeyAppSKeyLORAWAN_APPSKEYapplication session encryption key

(note 1): LoRaWAN-1.0 OTA uses a single root key for both network server and application server.

In LoRaWAN-1.0 OTA: the single root AppKey is used to generate NwkSkey and AppSKey.
(note 2): In LoRaWAN-1.0 (both OTA and ABP) SNwkSIntKey, NwkSEncKey. FNwkSIntKey are of same value and are collectively known as NwkSKey.
(note 3): LoRaWAN-1.0 uses single network session key, LoRaWAN-1.1 uses 3 network session keys. Both use a unique application session key.


In LoRaWAN-1.1 OTA: the root NwkKey is used to generate SNwkSIntKey, NwkSEncKey, FNwkSIntKey
In LoRaWAN-1.1 OTA: the root AppKey is used to generate AppSKey


in ABP mode, the DevAddr, and session keys are fixed (never change), and frame counters never reset to zero.
ABP operation has no concept of: root keys, or DevEUI or JoinEUI/AppEUI.
in OTA mode, the DevAddr and session keys are assigned at join procedure, and frame counters reset at join.

eeprom

This library includes eeprom driver to support non-volatile storage required by LoRaWAN specification.
Currently eeprom is implemented for STM32L1 family and STM32L0 family.
Writing of values are wear-leveled to increase endurance; each write operation circulates across several memory locations. A read operation returns the highest value found. This simple method is used for sequence numbers which only increase.

value nameused in
DevNonceOTAfor Join request (note 1)
RJcount1OTAfor ReJoin Type 1 request
FCntUpABPuplink frame counter
NFCntDownABPdownlink frame counter
AFCntDownABPdownlink frame counter

AFCntDown is only used in LoRaWAN-1.1 when application payload is present in downlink and FPort > 0.
NFCntDown is used in LoRaWAN-1.1 when FPort is zero in downlink or application payload not present.
NFCntDown is the only downlink frame counter used in LoRaWAN-1.0
(note 1) OTA DevNonce is random number in LoRaWAN-1.0, therefore not stored in eeprom. DevNonce in LoRaWAN-1.1 is forever increasing (non-volatile) number upon each join request,.
RJcount0 is only stored in RAM because the value resets upon new session from JoinAccept, therefore not stored in eeprom.
Frame counters in OTA mode reset upon new session in join request, therefore are stored in RAM instead of eeprom for OTA.

radio driver support

When SX127x driver is used, both SX1272 and SX1276 are supported without defining at compile time. The chip is detected at start-up.
Supported radio platforms:


Alternately, when SX126x driver is imported, the SX126xDVK1xAS board is used.

low-speed clock oscillator selection

LoRaWAN uses 32768Hz crystal to permit low-power operation.
However, some mbed targets might revert to low-speed internal oscillator, which is not accurate enough for LoRaWAN operation.
An oscillator check is performed at initialization; program will not start if internal oscillator is used.
To force LSE watch crystal, add to mbed_app.json

{
    "macros": [ "MBEDTLS_CMAC_C" ],
    "target_overrides": {
        "<your-target>": {
            "target.lse_available": true
        }
    }
}
Committer:
Wayne Roberts
Date:
Mon Aug 20 14:09:49 2018 -0700
Revision:
12:0f28f2e7c35e
Parent:
11:ce1317758488
add 8 hybrid channel sets for us915 band

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dudmuck 6:babd601c6392 1 #ifndef _LORAMAC_H_
dudmuck 6:babd601c6392 2 #define _LORAMAC_H_
dudmuck 6:babd601c6392 3
dudmuck 6:babd601c6392 4 #include "Commissioning.h"
dudmuck 6:babd601c6392 5
dudmuck 6:babd601c6392 6 typedef enum {
Wayne Roberts 7:4b6f960dcca2 7 /* 0 */ LORAMAC_STATUS_OK = 0,
Wayne Roberts 7:4b6f960dcca2 8 /* 1 */ LORAMAC_STATUS_LSE,
Wayne Roberts 7:4b6f960dcca2 9 /* 2 */ LORAMAC_STATUS_WAITING_FOR_TXSTART,
Wayne Roberts 7:4b6f960dcca2 10 /* 3 */ LORAMAC_STATUS_WAITING_FOR_TXDONE,
Wayne Roberts 7:4b6f960dcca2 11 /* 4 */ LORAMAC_STATUS_WAITING_FOR_RX1,
Wayne Roberts 7:4b6f960dcca2 12 /* 5 */ LORAMAC_STATUS_WAITING_FOR_RX2,
Wayne Roberts 7:4b6f960dcca2 13 /* 6 */ LORAMAC_STATUS_BUSY_UPCONF,
Wayne Roberts 7:4b6f960dcca2 14 /* 7 */ LORAMAC_STATUS_SERVICE_UNKNOWN,
Wayne Roberts 7:4b6f960dcca2 15 /* 8 */ LORAMAC_STATUS_PARAMETER_INVALID,
Wayne Roberts 7:4b6f960dcca2 16 /* 9 */ LORAMAC_STATUS_DATARATE_INVALID,
Wayne Roberts 7:4b6f960dcca2 17 /* 10 */ LORAMAC_STATUS_FREQUENCY_INVALID,
Wayne Roberts 7:4b6f960dcca2 18 /* 11 */ LORAMAC_STATUS_LENGTH_ERROR,
Wayne Roberts 7:4b6f960dcca2 19 /* 12 */ LORAMAC_STATUS_DEVICE_OFF,
Wayne Roberts 7:4b6f960dcca2 20 /* 13 */ LORAMAC_STATUS_FREQ_AND_DR_INVALID,
Wayne Roberts 7:4b6f960dcca2 21 /* 14 */ LORAMAC_STATUS_EEPROM_FAIL,
Wayne Roberts 7:4b6f960dcca2 22 /* 15 */ LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR,
dudmuck 6:babd601c6392 23 #ifdef LORAWAN_JOIN_EUI
Wayne Roberts 7:4b6f960dcca2 24 /* 16 */ LORAMAC_STATUS_NO_NETWORK_JOINED
dudmuck 6:babd601c6392 25 #endif
dudmuck 6:babd601c6392 26 } LoRaMacStatus_t;
dudmuck 6:babd601c6392 27
dudmuck 6:babd601c6392 28 typedef enum {
dudmuck 6:babd601c6392 29 LORAMAC_EVENT_INFO_STATUS_OK,
dudmuck 6:babd601c6392 30 LORAMAC_EVENT_INFO_STATUS_INCR_FAIL,
dudmuck 6:babd601c6392 31 LORAMAC_EVENT_INFO_STATUS_MLMEREQ,
dudmuck 6:babd601c6392 32 LORAMAC_EVENT_INFO_STATUS_UNKNOWN_MTYPE,
dudmuck 6:babd601c6392 33 LORAMAC_EVENT_INFO_STATUS_SENDING,
dudmuck 6:babd601c6392 34 LORAMAC_EVENT_INFO_STATUS_MCPSREQ,
dudmuck 6:babd601c6392 35 LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT,
dudmuck 6:babd601c6392 36 LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT,
dudmuck 6:babd601c6392 37 LORAMAC_EVENT_INFO_STATUS_RX2_ERROR,
dudmuck 6:babd601c6392 38 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED,
dudmuck 6:babd601c6392 39 LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
dudmuck 6:babd601c6392 40 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
dudmuck 6:babd601c6392 41 LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL,
dudmuck 6:babd601c6392 42 LORAMAC_EVENT_INFO_STATUS_MIC_FAIL,
dudmuck 6:babd601c6392 43 LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL,
dudmuck 6:babd601c6392 44 LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED,
dudmuck 6:babd601c6392 45 LORAMAC_EVENT_INFO_STATUS_BEACON_LOST,
dudmuck 6:babd601c6392 46 LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND,
dudmuck 6:babd601c6392 47 LORAMAC_EVENT_INFO_STATUS_NO_APPKEY,
dudmuck 6:babd601c6392 48 LORAMAC_EVENT_INFO_BAD_RX_DELAY,
Wayne Roberts 7:4b6f960dcca2 49 LORAMAC_EVENT_INFO_STATUS_CHANNEL_BUSY,
dudmuck 6:babd601c6392 50 #ifdef LORAWAN_JOIN_EUI
dudmuck 6:babd601c6392 51 LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
dudmuck 6:babd601c6392 52 LORAMAC_EVENT_INFO_STATUS_JOINNONCE
dudmuck 6:babd601c6392 53 #endif
dudmuck 6:babd601c6392 54 } LoRaMacEventInfoStatus_t;
dudmuck 6:babd601c6392 55
dudmuck 6:babd601c6392 56 typedef enum {
dudmuck 6:babd601c6392 57 MCPS_NONE,
dudmuck 6:babd601c6392 58 MCPS_UNCONFIRMED,
dudmuck 6:babd601c6392 59 MCPS_CONFIRMED,
dudmuck 6:babd601c6392 60 MCPS_MULTICAST,
dudmuck 6:babd601c6392 61 MCPS_PROPRIETARY
dudmuck 6:babd601c6392 62 } Mcps_t;
dudmuck 6:babd601c6392 63
dudmuck 6:babd601c6392 64 #include <stdint.h>
dudmuck 6:babd601c6392 65 typedef struct {
dudmuck 6:babd601c6392 66 LoRaMacEventInfoStatus_t Status;
dudmuck 6:babd601c6392 67 Mcps_t McpsRequest;
dudmuck 6:babd601c6392 68 uint8_t NbRetries;
dudmuck 6:babd601c6392 69 bool AckReceived;
dudmuck 6:babd601c6392 70 uint32_t UpLinkCounter;
dudmuck 6:babd601c6392 71 uint8_t Datarate;
dudmuck 6:babd601c6392 72 int8_t TxPower;
dudmuck 6:babd601c6392 73 uint32_t UpLinkFreqHz;
dudmuck 6:babd601c6392 74 //us_timestamp_t TxTimeOnAir;
dudmuck 6:babd601c6392 75 } McpsConfirm_t;
dudmuck 6:babd601c6392 76
dudmuck 6:babd601c6392 77 typedef struct {
dudmuck 6:babd601c6392 78 uint8_t Snr;
dudmuck 6:babd601c6392 79 int16_t Rssi;
dudmuck 6:babd601c6392 80 int8_t RxSlot;
dudmuck 6:babd601c6392 81 LoRaMacEventInfoStatus_t Status;
dudmuck 6:babd601c6392 82 Mcps_t McpsIndication;
dudmuck 6:babd601c6392 83 bool RxData;
dudmuck 6:babd601c6392 84 uint8_t RxDatarate;
dudmuck 6:babd601c6392 85 uint8_t Port;
dudmuck 6:babd601c6392 86 uint8_t BufferSize;
dudmuck 6:babd601c6392 87 uint8_t *Buffer;
dudmuck 6:babd601c6392 88 uint8_t FramePending;
dudmuck 6:babd601c6392 89 bool AckReceived;
dudmuck 6:babd601c6392 90 uint32_t expectedFCntDown;
dudmuck 6:babd601c6392 91 uint16_t receivedFCntDown;
dudmuck 6:babd601c6392 92 uint16_t ADR_ACK_CNT;
dudmuck 6:babd601c6392 93 } McpsIndication_t;
dudmuck 6:babd601c6392 94
dudmuck 6:babd601c6392 95 typedef enum {
dudmuck 6:babd601c6392 96 MLME_NONE = 0,
dudmuck 6:babd601c6392 97 MLME_LINK_CHECK,
dudmuck 6:babd601c6392 98 MLME_SWITCH_CLASS,
dudmuck 6:babd601c6392 99 MLME_PING_SLOT_INFO,
dudmuck 6:babd601c6392 100 MLME_BEACON_TIMING,
dudmuck 6:babd601c6392 101 MLME_BEACON_ACQUISITION,
dudmuck 6:babd601c6392 102 MLME_TIME_REQ,
dudmuck 6:babd601c6392 103 MLME_BEACON,
dudmuck 6:babd601c6392 104 MLME_TXCW,
dudmuck 6:babd601c6392 105 #ifdef LORAWAN_JOIN_EUI
dudmuck 6:babd601c6392 106 MLME_JOIN,
dudmuck 6:babd601c6392 107 MLME_REJOIN_0,
dudmuck 6:babd601c6392 108 MLME_REJOIN_1,
dudmuck 6:babd601c6392 109 MLME_REJOIN_2
dudmuck 6:babd601c6392 110 #endif
dudmuck 6:babd601c6392 111 } Mlme_t;
dudmuck 6:babd601c6392 112
Wayne Roberts 11:ce1317758488 113 #include "lorawan_board.h"
dudmuck 6:babd601c6392 114
dudmuck 6:babd601c6392 115 #define DR_0 0
dudmuck 6:babd601c6392 116 #define DR_1 1
dudmuck 6:babd601c6392 117 #define DR_2 2
dudmuck 6:babd601c6392 118 #define DR_3 3
dudmuck 6:babd601c6392 119 #define DR_4 4
dudmuck 6:babd601c6392 120 #define DR_5 5
dudmuck 6:babd601c6392 121 #define DR_6 6
dudmuck 6:babd601c6392 122 #define DR_7 7
dudmuck 6:babd601c6392 123 #define DR_8 8
dudmuck 6:babd601c6392 124 #define DR_9 9
dudmuck 6:babd601c6392 125 #define DR_10 10
dudmuck 6:babd601c6392 126 #define DR_11 11
dudmuck 6:babd601c6392 127 #define DR_12 12
dudmuck 6:babd601c6392 128 #define DR_13 13
dudmuck 6:babd601c6392 129 #define DR_14 14
dudmuck 6:babd601c6392 130 #define DR_15 15
dudmuck 6:babd601c6392 131
dudmuck 6:babd601c6392 132
dudmuck 6:babd601c6392 133 typedef union {
dudmuck 6:babd601c6392 134 uint8_t Value;
dudmuck 6:babd601c6392 135
dudmuck 6:babd601c6392 136 struct {
dudmuck 6:babd601c6392 137 int8_t Min : 4;
dudmuck 6:babd601c6392 138 int8_t Max : 4;
dudmuck 6:babd601c6392 139 } Fields;
dudmuck 6:babd601c6392 140 } DrRange_t;
dudmuck 6:babd601c6392 141
dudmuck 6:babd601c6392 142 typedef struct {
dudmuck 6:babd601c6392 143 uint32_t FreqHz;
dudmuck 6:babd601c6392 144 DrRange_t DrRange;
dudmuck 6:babd601c6392 145 uint8_t Band;
dudmuck 6:babd601c6392 146 } ChannelParams_t;
dudmuck 6:babd601c6392 147
dudmuck 6:babd601c6392 148
dudmuck 6:babd601c6392 149 typedef struct {
dudmuck 6:babd601c6392 150 Mcps_t Type;
dudmuck 6:babd601c6392 151 struct {
dudmuck 6:babd601c6392 152 void *fBuffer;
dudmuck 6:babd601c6392 153 uint16_t fBufferSize;
dudmuck 6:babd601c6392 154 uint8_t Datarate;
dudmuck 6:babd601c6392 155 uint8_t fPort;
dudmuck 6:babd601c6392 156 } Req;
dudmuck 6:babd601c6392 157 } McpsReq_t;
dudmuck 6:babd601c6392 158
dudmuck 6:babd601c6392 159 typedef struct {
dudmuck 6:babd601c6392 160 uint8_t MaxPossiblePayload;
dudmuck 6:babd601c6392 161 uint8_t CurrentPayloadSize;
dudmuck 6:babd601c6392 162 } LoRaMacTxInfo_t;
dudmuck 6:babd601c6392 163
dudmuck 6:babd601c6392 164 typedef enum {
dudmuck 6:babd601c6392 165 MIB_DEV_ADDR,
dudmuck 6:babd601c6392 166 MIB_DEVICE_CLASS,
dudmuck 6:babd601c6392 167 MIB_ADR,
dudmuck 6:babd601c6392 168 MIB_PUBLIC_NETWORK,
dudmuck 6:babd601c6392 169 MIB_RX2_CHANNEL,
dudmuck 6:babd601c6392 170 MIB_CHANNELS_MASK,
dudmuck 6:babd601c6392 171 MIB_FNwkSIntKey,
dudmuck 6:babd601c6392 172 MIB_APP_SKEY,
dudmuck 6:babd601c6392 173 MIB_SNwkSIntKey,
dudmuck 6:babd601c6392 174 MIB_NwkSEncKey,
dudmuck 6:babd601c6392 175 MIB_NwkSKey, /* lorawan 1.0 */
Wayne Roberts 7:4b6f960dcca2 176 MIB_MAX_LISTEN_TIME,
dudmuck 6:babd601c6392 177 #ifdef LORAWAN_JOIN_EUI
dudmuck 6:babd601c6392 178 MIB_NETWORK_JOINED
dudmuck 6:babd601c6392 179 #endif
dudmuck 6:babd601c6392 180 } Mib_t;
dudmuck 6:babd601c6392 181
dudmuck 6:babd601c6392 182 typedef enum {
Wayne Roberts 7:4b6f960dcca2 183 CLASS_A = 0,
dudmuck 6:babd601c6392 184 CLASS_B,
dudmuck 6:babd601c6392 185 CLASS_C
dudmuck 6:babd601c6392 186 } DeviceClass_t;
dudmuck 6:babd601c6392 187
dudmuck 6:babd601c6392 188 typedef struct {
dudmuck 6:babd601c6392 189 uint32_t FrequencyHz;
dudmuck 6:babd601c6392 190 uint8_t Datarate;
dudmuck 6:babd601c6392 191 } Rx2ChannelParams_t;
dudmuck 6:babd601c6392 192
dudmuck 6:babd601c6392 193 typedef union {
dudmuck 6:babd601c6392 194 uint32_t DevAddr;
dudmuck 6:babd601c6392 195 bool AdrEnable;
dudmuck 6:babd601c6392 196 DeviceClass_t Class;
dudmuck 6:babd601c6392 197 bool IsNetworkJoined;
dudmuck 6:babd601c6392 198 bool EnablePublicNetwork;
dudmuck 6:babd601c6392 199 uint16_t* ChannelsMask;
dudmuck 6:babd601c6392 200 const uint8_t* key;
dudmuck 6:babd601c6392 201 Rx2ChannelParams_t Rx2Channel;
Wayne Roberts 7:4b6f960dcca2 202 us_timestamp_t MaxListenTime;
dudmuck 6:babd601c6392 203 } MibParam_t;
dudmuck 6:babd601c6392 204
dudmuck 6:babd601c6392 205 typedef struct {
dudmuck 6:babd601c6392 206 Mib_t Type;
dudmuck 6:babd601c6392 207 MibParam_t Param;
dudmuck 6:babd601c6392 208 } MibRequestConfirm_t;
dudmuck 6:babd601c6392 209
dudmuck 6:babd601c6392 210
dudmuck 6:babd601c6392 211
dudmuck 6:babd601c6392 212 typedef struct {
dudmuck 6:babd601c6392 213 Mlme_t Type;
dudmuck 6:babd601c6392 214
dudmuck 6:babd601c6392 215 union {
dudmuck 6:babd601c6392 216 struct {
dudmuck 6:babd601c6392 217 DeviceClass_t Class;
dudmuck 6:babd601c6392 218 } SwitchClass;
dudmuck 6:babd601c6392 219
dudmuck 6:babd601c6392 220 union {
dudmuck 6:babd601c6392 221 uint8_t Value;
dudmuck 6:babd601c6392 222 struct sInfoFields {
dudmuck 6:babd601c6392 223 uint8_t Periodicity : 3;
dudmuck 6:babd601c6392 224 uint8_t RFU : 5;
dudmuck 6:babd601c6392 225 } Fields;
dudmuck 6:babd601c6392 226 } PingSlotInfo;
dudmuck 6:babd601c6392 227
dudmuck 6:babd601c6392 228 #ifdef LORAWAN_JOIN_EUI
dudmuck 6:babd601c6392 229 struct {
dudmuck 6:babd601c6392 230 const uint8_t *DevEui;
dudmuck 6:babd601c6392 231 const uint8_t *JoinEui;
dudmuck 6:babd601c6392 232 const uint8_t *NwkKey;
dudmuck 6:babd601c6392 233 const uint8_t *AppKey;
dudmuck 6:babd601c6392 234 uint8_t NbTrials;
dudmuck 6:babd601c6392 235 } Join;
dudmuck 6:babd601c6392 236 #endif /* LORAWAN_JOIN_EUI */
dudmuck 6:babd601c6392 237
dudmuck 6:babd601c6392 238 struct {
dudmuck 6:babd601c6392 239 uint16_t Timeout;
dudmuck 6:babd601c6392 240 } TxCw;
dudmuck 6:babd601c6392 241 } Req;
dudmuck 6:babd601c6392 242 } MlmeReq_t;
dudmuck 6:babd601c6392 243
dudmuck 6:babd601c6392 244
dudmuck 6:babd601c6392 245 typedef struct {
dudmuck 6:babd601c6392 246 LoRaMacEventInfoStatus_t Status;
dudmuck 6:babd601c6392 247 Mlme_t MlmeRequest;
dudmuck 6:babd601c6392 248 union {
dudmuck 6:babd601c6392 249 struct {
dudmuck 6:babd601c6392 250 uint8_t DemodMargin;
dudmuck 6:babd601c6392 251 uint8_t NbGateways;
dudmuck 6:babd601c6392 252 } link;
dudmuck 6:babd601c6392 253 struct {
dudmuck 6:babd601c6392 254 uint32_t Seconds; // seconds since epoch
dudmuck 6:babd601c6392 255 uint32_t uSeconds; // fractional part
dudmuck 6:babd601c6392 256 } time;
dudmuck 6:babd601c6392 257 struct {
dudmuck 6:babd601c6392 258 uint32_t rxJoinNonce;
dudmuck 6:babd601c6392 259 uint32_t myJoinNonce;
dudmuck 6:babd601c6392 260 } join;
dudmuck 6:babd601c6392 261 } fields;
dudmuck 6:babd601c6392 262 //us_timestamp_t TxTimeOnAir;
dudmuck 6:babd601c6392 263 } MlmeConfirm_t;
dudmuck 6:babd601c6392 264
dudmuck 6:babd601c6392 265
dudmuck 6:babd601c6392 266 typedef struct {
dudmuck 6:babd601c6392 267 Mlme_t MlmeIndication;
dudmuck 6:babd601c6392 268 LoRaMacEventInfoStatus_t Status;
dudmuck 6:babd601c6392 269 uint32_t freqHz;
dudmuck 6:babd601c6392 270 #ifdef LORAWAN_JOIN_EUI
dudmuck 6:babd601c6392 271 uint8_t JoinRequestTrials;
dudmuck 6:babd601c6392 272 #endif /* LORAWAN_JOIN_EUI */
dudmuck 6:babd601c6392 273 } MlmeIndication_t;
dudmuck 6:babd601c6392 274
dudmuck 6:babd601c6392 275
dudmuck 6:babd601c6392 276 /*!
dudmuck 6:babd601c6392 277 * LoRaMAC events structure
dudmuck 6:babd601c6392 278 * Used to notify upper layers of MAC events
dudmuck 6:babd601c6392 279 */
dudmuck 6:babd601c6392 280 typedef struct sLoRaMacPrimitives
dudmuck 6:babd601c6392 281 {
dudmuck 6:babd601c6392 282 /*!
dudmuck 6:babd601c6392 283 * \brief MCPS-Confirm primitive
dudmuck 6:babd601c6392 284 *
dudmuck 6:babd601c6392 285 * \param [OUT] MCPS-Confirm parameters
dudmuck 6:babd601c6392 286 */
dudmuck 6:babd601c6392 287 void (* const MacMcpsConfirm )( const McpsConfirm_t *McpsConfirm );
dudmuck 6:babd601c6392 288 /*!
dudmuck 6:babd601c6392 289 * \brief MCPS-Indication primitive
dudmuck 6:babd601c6392 290 *
dudmuck 6:babd601c6392 291 * \param [OUT] MCPS-Indication parameters
dudmuck 6:babd601c6392 292 */
dudmuck 6:babd601c6392 293 void (* const MacMcpsIndication )( const McpsIndication_t *McpsIndication );
dudmuck 6:babd601c6392 294 /*!
dudmuck 6:babd601c6392 295 * \brief MLME-Confirm primitive
dudmuck 6:babd601c6392 296 *
dudmuck 6:babd601c6392 297 * \param [OUT] MLME-Confirm parameters
dudmuck 6:babd601c6392 298 */
dudmuck 6:babd601c6392 299 void (* const MacMlmeConfirm )( const MlmeConfirm_t *MlmeConfirm );
dudmuck 6:babd601c6392 300 /*!
dudmuck 6:babd601c6392 301 * \brief MLME-Indication primitive
dudmuck 6:babd601c6392 302 *
dudmuck 6:babd601c6392 303 * \param [OUT] MLME-Indication parameters
dudmuck 6:babd601c6392 304 */
dudmuck 6:babd601c6392 305 void (* const MacMlmeIndication )( const MlmeIndication_t *MlmeIndication );
dudmuck 6:babd601c6392 306 } LoRaMacPrimitives_t;
dudmuck 6:babd601c6392 307
dudmuck 6:babd601c6392 308 typedef struct sLoRaMacCallback
dudmuck 6:babd601c6392 309 {
dudmuck 6:babd601c6392 310 /*!
dudmuck 6:babd601c6392 311 * \brief Measures the battery level
dudmuck 6:babd601c6392 312 *
dudmuck 6:babd601c6392 313 * \retval Battery level [0: node is connected to an external
dudmuck 6:babd601c6392 314 * power source, 1..254: battery level, where 1 is the minimum
dudmuck 6:babd601c6392 315 * and 254 is the maximum value, 255: the node was not able
dudmuck 6:babd601c6392 316 * to measure the battery level]
dudmuck 6:babd601c6392 317 */
dudmuck 6:babd601c6392 318 uint8_t (* const GetBatteryLevel )( void );
dudmuck 6:babd601c6392 319 /*!
dudmuck 6:babd601c6392 320 * \brief Measures the temperature level
dudmuck 6:babd601c6392 321 *
dudmuck 6:babd601c6392 322 * \retval Temperature level
dudmuck 6:babd601c6392 323 */
dudmuck 6:babd601c6392 324 float (* const GetTemperatureLevel )( void );
dudmuck 6:babd601c6392 325 } LoRaMacCallback_t;
dudmuck 6:babd601c6392 326
dudmuck 6:babd601c6392 327 LoRaMacStatus_t LoRaMacInitialization( const LoRaMacPrimitives_t *primitives, const LoRaMacCallback_t *callbacks );
dudmuck 6:babd601c6392 328 us_timestamp_t LoRaMacReadTimer(void);
dudmuck 6:babd601c6392 329 LoRaMacStatus_t LoRaMacQueryTxPossible(uint8_t size, LoRaMacTxInfo_t* txInfo);
dudmuck 6:babd601c6392 330 LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest );
dudmuck 6:babd601c6392 331 LoRaMacStatus_t LoRaMacMibGetRequestConfirm( MibRequestConfirm_t *mibGet );
dudmuck 6:babd601c6392 332 LoRaMacStatus_t LoRaMacMlmeRequest( const MlmeReq_t *mlmeRequest );
dudmuck 6:babd601c6392 333 LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t *mibSet );
dudmuck 6:babd601c6392 334 LoRaMacStatus_t LoRaMacChannelAdd( uint8_t id, ChannelParams_t params );
dudmuck 6:babd601c6392 335 void LoRaMacPrintStatus(void);
dudmuck 6:babd601c6392 336 uint32_t get_fcntdwn(bool);
dudmuck 6:babd601c6392 337 int8_t LoRaMacGetRxSlot(void);
dudmuck 6:babd601c6392 338 void LoRaMacUserContext(void);
dudmuck 6:babd601c6392 339
dudmuck 6:babd601c6392 340 #endif /* _LORAMAC_H_ */