LoRaWAN end device MAC layer for SX1272 and SX1276. Supports LoRaWAN-1.0 and LoRaWAN-1.1
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 name | LoRaWAN 1.1 name | Comissioning.h defne | description | |
---|---|---|---|---|
OTA | DevEUI | DevEUI | LORAWAN_DEVICE_EUI | uniquely identifies end device |
OTA | AppEUI | JoinEUI | LORAWAN_JOIN_EUI | |
OTA | AppKey | NwkKey | LORAWAN_ROOT_NWKKEY | root key for network server |
OTA | (note 1) | AppKey | LORAWAN_ROOT_APPKEY | root key for application server |
ABP | NwkSKey | (note 3) | LORAWAN_FNwkSIntKey | network session key |
ABP | (note 2) | SNwkSIntKey | LORAWAN_SNwkSIntKey | mac layer network integrity key |
ABP | (note 2) | NwkSEncKey | LORAWAN_NwkSEncKey | network session encryption key |
ABP | (note 2) | FNwkSIntKey | LORAWAN_FNwkSIntKey | forwarding network session integrity key |
ABP | AppSKey | AppSKey | LORAWAN_APPSKEY | application 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 name | used in | |
---|---|---|
DevNonce | OTA | for Join request (note 1) |
RJcount1 | OTA | for ReJoin Type 1 request |
FCntUp | ABP | uplink frame counter |
NFCntDown | ABP | downlink frame counter |
AFCntDown | ABP | downlink 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 } } }
mac/LoRaMacPrivate.h@9:fe8e08792ae9, 2018-06-11 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Mon Jun 11 14:09:16 2018 -0700
- Revision:
- 9:fe8e08792ae9
- Parent:
- 7:4b6f960dcca2
sx126x: update xfer() calls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:6b3ac9c5a042 | 1 | #ifndef _LORAMACPRIVATE_H_ |
Wayne Roberts |
0:6b3ac9c5a042 | 2 | #define _LORAMACPRIVATE_H_ |
dudmuck | 6:babd601c6392 | 3 | #include "LoRaMac1v1.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 4 | |
Wayne Roberts |
0:6b3ac9c5a042 | 5 | typedef struct sBand |
Wayne Roberts |
0:6b3ac9c5a042 | 6 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 7 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 8 | * Duty cycle |
Wayne Roberts |
0:6b3ac9c5a042 | 9 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 10 | uint16_t DCycle; |
Wayne Roberts |
0:6b3ac9c5a042 | 11 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 12 | * Maximum Tx power |
Wayne Roberts |
0:6b3ac9c5a042 | 13 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 14 | int8_t TxMaxPower; |
Wayne Roberts |
0:6b3ac9c5a042 | 15 | #ifdef DUTY_ENABLE |
Wayne Roberts |
0:6b3ac9c5a042 | 16 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 17 | * Time stamp of the last Tx frame |
Wayne Roberts |
0:6b3ac9c5a042 | 18 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 19 | us_timestamp_t LastTxDoneTime; |
Wayne Roberts |
0:6b3ac9c5a042 | 20 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 21 | * Holds the time where the device is off |
Wayne Roberts |
0:6b3ac9c5a042 | 22 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 23 | us_timestamp_t TimeOff; |
Wayne Roberts |
0:6b3ac9c5a042 | 24 | #endif /* DUTY_ENABLE */ |
Wayne Roberts |
0:6b3ac9c5a042 | 25 | } Band_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 26 | |
Wayne Roberts |
0:6b3ac9c5a042 | 27 | #ifdef USE_BAND_ARIB_8CH |
Wayne Roberts |
0:6b3ac9c5a042 | 28 | #include "region_arib8ch_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 29 | #elif defined(USE_BAND_780) |
Wayne Roberts |
0:6b3ac9c5a042 | 30 | #include "region_cn780_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 31 | #elif defined(USE_BAND_470) |
Wayne Roberts |
0:6b3ac9c5a042 | 32 | #include "region_cn470_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 33 | #elif defined(USE_BAND_433) |
Wayne Roberts |
0:6b3ac9c5a042 | 34 | #include "region_433_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 35 | #elif defined(USE_BAND_868) |
Wayne Roberts |
0:6b3ac9c5a042 | 36 | #include "region_eu868_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 37 | #elif defined(USE_BAND_915_HYBRID) || defined(USE_BAND_915) |
Wayne Roberts |
0:6b3ac9c5a042 | 38 | #include "region_us915_private.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 39 | #else |
Wayne Roberts |
0:6b3ac9c5a042 | 40 | #error define USE_BAND_* |
Wayne Roberts |
0:6b3ac9c5a042 | 41 | #endif |
Wayne Roberts |
0:6b3ac9c5a042 | 42 | |
Wayne Roberts |
0:6b3ac9c5a042 | 43 | #include "radio.h" |
Wayne Roberts |
0:6b3ac9c5a042 | 44 | |
Wayne Roberts |
0:6b3ac9c5a042 | 45 | #define RECEIVE_DELAY1_us 1000000 |
Wayne Roberts |
0:6b3ac9c5a042 | 46 | #define MAX_RX_WINDOW_us 3000000 |
Wayne Roberts |
0:6b3ac9c5a042 | 47 | |
Wayne Roberts |
0:6b3ac9c5a042 | 48 | #define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) ) |
Wayne Roberts |
0:6b3ac9c5a042 | 49 | |
Wayne Roberts |
0:6b3ac9c5a042 | 50 | typedef struct { |
Wayne Roberts |
0:6b3ac9c5a042 | 51 | uint32_t uplink_in_progress : 4; //0,1,2,3 |
Wayne Roberts |
0:6b3ac9c5a042 | 52 | uint32_t uplink_mtype : 3; //4,5,6 |
Wayne Roberts |
0:6b3ac9c5a042 | 53 | uint32_t SrvAckRequested : 1; //8 |
Wayne Roberts |
0:6b3ac9c5a042 | 54 | uint32_t rxing : 1; //9 |
Wayne Roberts |
0:6b3ac9c5a042 | 55 | uint32_t MacCommandsInNextTx : 1; //10 |
Wayne Roberts |
0:6b3ac9c5a042 | 56 | uint32_t AdrCtrlOn : 1; //11 |
Wayne Roberts |
0:6b3ac9c5a042 | 57 | uint32_t OptNeg : 1; //12 |
Wayne Roberts |
0:6b3ac9c5a042 | 58 | uint32_t PublicNetwork : 1; //13 |
Wayne Roberts |
4:e4bfe9183f94 | 59 | uint32_t OnTxDelayed : 1; //14 |
Wayne Roberts |
0:6b3ac9c5a042 | 60 | |
Wayne Roberts |
0:6b3ac9c5a042 | 61 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
4:e4bfe9183f94 | 62 | uint32_t need_ReKeyConf : 1; //15 |
Wayne Roberts |
4:e4bfe9183f94 | 63 | uint32_t IsLoRaMacNetworkJoined: 1; //16 |
Wayne Roberts |
0:6b3ac9c5a042 | 64 | #else |
Wayne Roberts |
4:e4bfe9183f94 | 65 | uint32_t have_SNwkSIntKey : 1; // 15 |
Wayne Roberts |
4:e4bfe9183f94 | 66 | uint32_t have_NwkSEncKey : 1; // 16 |
Wayne Roberts |
4:e4bfe9183f94 | 67 | uint32_t need_ResetConf: 1; // 17 |
Wayne Roberts |
0:6b3ac9c5a042 | 68 | #endif /* !LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 69 | |
Wayne Roberts |
0:6b3ac9c5a042 | 70 | } flags_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 71 | |
Wayne Roberts |
0:6b3ac9c5a042 | 72 | extern flags_t flags; |
Wayne Roberts |
0:6b3ac9c5a042 | 73 | |
Wayne Roberts |
0:6b3ac9c5a042 | 74 | |
Wayne Roberts |
0:6b3ac9c5a042 | 75 | typedef enum eLoRaMacMoteCmd |
Wayne Roberts |
0:6b3ac9c5a042 | 76 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 77 | #ifndef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 78 | MOTE_MAC_RESET_IND = 0x01, |
Wayne Roberts |
0:6b3ac9c5a042 | 79 | #endif /* !LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 80 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 81 | * LinkCheckReq |
Wayne Roberts |
0:6b3ac9c5a042 | 82 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 83 | MOTE_MAC_LINK_CHECK_REQ = 0x02, |
Wayne Roberts |
0:6b3ac9c5a042 | 84 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 85 | * LinkADRAns |
Wayne Roberts |
0:6b3ac9c5a042 | 86 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 87 | MOTE_MAC_LINK_ADR_ANS = 0x03, |
Wayne Roberts |
0:6b3ac9c5a042 | 88 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 89 | * DutyCycleAns |
Wayne Roberts |
0:6b3ac9c5a042 | 90 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 91 | MOTE_MAC_DUTY_CYCLE_ANS = 0x04, |
Wayne Roberts |
0:6b3ac9c5a042 | 92 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 93 | * RXParamSetupAns |
Wayne Roberts |
0:6b3ac9c5a042 | 94 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 95 | MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05, |
Wayne Roberts |
0:6b3ac9c5a042 | 96 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 97 | * DevStatusAns |
Wayne Roberts |
0:6b3ac9c5a042 | 98 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 99 | MOTE_MAC_DEV_STATUS_ANS = 0x06, |
Wayne Roberts |
0:6b3ac9c5a042 | 100 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 101 | * NewChannelAns |
Wayne Roberts |
0:6b3ac9c5a042 | 102 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 103 | MOTE_MAC_NEW_CHANNEL_ANS = 0x07, |
Wayne Roberts |
0:6b3ac9c5a042 | 104 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 105 | * RXTimingSetupAns |
Wayne Roberts |
0:6b3ac9c5a042 | 106 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 107 | MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08, |
Wayne Roberts |
0:6b3ac9c5a042 | 108 | |
Wayne Roberts |
3:eb174e10afbb | 109 | SRV_MAC_ADR_PARAM_SETUP_ANS = 0x0c, |
Wayne Roberts |
0:6b3ac9c5a042 | 110 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 111 | MOTE_MAC_REKEY_IND = 0x0b, |
Wayne Roberts |
0:6b3ac9c5a042 | 112 | MOTE_MAC_REJOIN_PARAM_ANS = 0x0f, |
Wayne Roberts |
0:6b3ac9c5a042 | 113 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 114 | MOTE_MAC_DEVICE_TIME_REQ = 0x0d, |
Wayne Roberts |
0:6b3ac9c5a042 | 115 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 116 | * PingSlotInfoReq |
Wayne Roberts |
0:6b3ac9c5a042 | 117 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 118 | MOTE_MAC_PING_SLOT_INFO_REQ = 0x10, |
Wayne Roberts |
0:6b3ac9c5a042 | 119 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 120 | * PingSlotFreqAns |
Wayne Roberts |
0:6b3ac9c5a042 | 121 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 122 | MOTE_MAC_PING_SLOT_FREQ_ANS = 0x11, |
Wayne Roberts |
0:6b3ac9c5a042 | 123 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 124 | * BeaconTimingReq |
Wayne Roberts |
0:6b3ac9c5a042 | 125 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 126 | MOTE_MAC_BEACON_TIMING_REQ = 0x12, |
Wayne Roberts |
0:6b3ac9c5a042 | 127 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 128 | * BeaconFreqAns |
Wayne Roberts |
0:6b3ac9c5a042 | 129 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 130 | MOTE_MAC_BEACON_FREQ_ANS = 0x13, |
Wayne Roberts |
7:4b6f960dcca2 | 131 | |
Wayne Roberts |
7:4b6f960dcca2 | 132 | MOTE_MAC_MODE_IND = 0x20 |
Wayne Roberts |
7:4b6f960dcca2 | 133 | } LoRaMacMoteCmd_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 134 | |
Wayne Roberts |
0:6b3ac9c5a042 | 135 | #define LORA_MAC_COMMAND_MAX_LENGTH 15 |
Wayne Roberts |
0:6b3ac9c5a042 | 136 | |
Wayne Roberts |
0:6b3ac9c5a042 | 137 | |
Wayne Roberts |
0:6b3ac9c5a042 | 138 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 139 | * Global MAC layer parameters |
Wayne Roberts |
0:6b3ac9c5a042 | 140 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 141 | typedef struct sLoRaMacParams |
Wayne Roberts |
0:6b3ac9c5a042 | 142 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 143 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 144 | * Channels TX power |
Wayne Roberts |
0:6b3ac9c5a042 | 145 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 146 | int8_t ChannelsTxPower; |
Wayne Roberts |
0:6b3ac9c5a042 | 147 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 148 | * Channels data rate |
Wayne Roberts |
0:6b3ac9c5a042 | 149 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 150 | int8_t ChannelsDatarate; |
Wayne Roberts |
0:6b3ac9c5a042 | 151 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 152 | * LoRaMac maximum time a reception window stays open |
Wayne Roberts |
0:6b3ac9c5a042 | 153 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 154 | uint32_t MaxRxWindow_us; |
Wayne Roberts |
0:6b3ac9c5a042 | 155 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 156 | * Receive delay 1 |
Wayne Roberts |
0:6b3ac9c5a042 | 157 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 158 | uint32_t ReceiveDelay1_us; |
Wayne Roberts |
0:6b3ac9c5a042 | 159 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 160 | * Receive delay 2 |
Wayne Roberts |
0:6b3ac9c5a042 | 161 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 162 | uint32_t ReceiveDelay2_us; |
Wayne Roberts |
0:6b3ac9c5a042 | 163 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 164 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 165 | * Join accept delay 1 |
Wayne Roberts |
0:6b3ac9c5a042 | 166 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 167 | uint32_t JoinAcceptDelay1_us; |
Wayne Roberts |
0:6b3ac9c5a042 | 168 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 169 | * Join accept delay 1 |
Wayne Roberts |
0:6b3ac9c5a042 | 170 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 171 | uint32_t JoinAcceptDelay2_us; |
Wayne Roberts |
0:6b3ac9c5a042 | 172 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 173 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 174 | * Number of uplink messages repetitions [1:15] (unconfirmed messages only) |
Wayne Roberts |
0:6b3ac9c5a042 | 175 | */ |
Wayne Roberts |
3:eb174e10afbb | 176 | uint8_t NbTrans; |
Wayne Roberts |
0:6b3ac9c5a042 | 177 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 178 | * Datarate offset between uplink and downlink on first window |
Wayne Roberts |
0:6b3ac9c5a042 | 179 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 180 | uint8_t Rx1DrOffset; |
Wayne Roberts |
0:6b3ac9c5a042 | 181 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 182 | * LoRaMAC 2nd reception window settings |
Wayne Roberts |
0:6b3ac9c5a042 | 183 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 184 | Rx2ChannelParams_t Rx2Channel; |
Wayne Roberts |
0:6b3ac9c5a042 | 185 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 186 | * Mask indicating which channels are enabled |
Wayne Roberts |
0:6b3ac9c5a042 | 187 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 188 | uint16_t ChannelsMask[6]; |
Wayne Roberts |
3:eb174e10afbb | 189 | uint8_t NbEnabledChannels; |
Wayne Roberts |
7:4b6f960dcca2 | 190 | us_timestamp_t MaxListenTime; |
Wayne Roberts |
0:6b3ac9c5a042 | 191 | } LoRaMacParams_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 192 | |
Wayne Roberts |
0:6b3ac9c5a042 | 193 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 194 | * LoRaMAC header field definition (MHDR field) |
Wayne Roberts |
0:6b3ac9c5a042 | 195 | * |
Wayne Roberts |
0:6b3ac9c5a042 | 196 | * LoRaWAN Specification V1.0.1, chapter 4.2 |
Wayne Roberts |
0:6b3ac9c5a042 | 197 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 198 | typedef union uLoRaMacHeader |
Wayne Roberts |
0:6b3ac9c5a042 | 199 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 200 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 201 | * Byte-access to the bits |
Wayne Roberts |
0:6b3ac9c5a042 | 202 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 203 | uint8_t Value; |
Wayne Roberts |
0:6b3ac9c5a042 | 204 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 205 | * Structure containing single access to header bits |
Wayne Roberts |
0:6b3ac9c5a042 | 206 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 207 | struct sHdrBits |
Wayne Roberts |
0:6b3ac9c5a042 | 208 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 209 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 210 | * Major version |
Wayne Roberts |
0:6b3ac9c5a042 | 211 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 212 | uint8_t Major : 2; |
Wayne Roberts |
0:6b3ac9c5a042 | 213 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 214 | * RFU |
Wayne Roberts |
0:6b3ac9c5a042 | 215 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 216 | uint8_t RFU : 3; |
Wayne Roberts |
0:6b3ac9c5a042 | 217 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 218 | * Message type |
Wayne Roberts |
0:6b3ac9c5a042 | 219 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 220 | uint8_t MType : 3; |
Wayne Roberts |
0:6b3ac9c5a042 | 221 | }Bits; |
Wayne Roberts |
0:6b3ac9c5a042 | 222 | }LoRaMacHeader_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 223 | |
Wayne Roberts |
0:6b3ac9c5a042 | 224 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 225 | * LoRaMAC frame types |
Wayne Roberts |
0:6b3ac9c5a042 | 226 | * |
Wayne Roberts |
0:6b3ac9c5a042 | 227 | * LoRaWAN Specification V1.0.1, chapter 4.2.1, table 1 |
Wayne Roberts |
0:6b3ac9c5a042 | 228 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 229 | typedef enum eLoRaMacFrameType |
Wayne Roberts |
0:6b3ac9c5a042 | 230 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 231 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 232 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 233 | * LoRaMAC join request frame |
Wayne Roberts |
0:6b3ac9c5a042 | 234 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 235 | FRAME_TYPE_JOIN_REQ = 0x00, |
Wayne Roberts |
0:6b3ac9c5a042 | 236 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 237 | * LoRaMAC join accept frame |
Wayne Roberts |
0:6b3ac9c5a042 | 238 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 239 | FRAME_TYPE_JOIN_ACCEPT = 0x01, |
Wayne Roberts |
0:6b3ac9c5a042 | 240 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 241 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 242 | * LoRaMAC unconfirmed up-link frame |
Wayne Roberts |
0:6b3ac9c5a042 | 243 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 244 | FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02, |
Wayne Roberts |
0:6b3ac9c5a042 | 245 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 246 | * LoRaMAC unconfirmed down-link frame |
Wayne Roberts |
0:6b3ac9c5a042 | 247 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 248 | FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03, |
Wayne Roberts |
0:6b3ac9c5a042 | 249 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 250 | * LoRaMAC confirmed up-link frame |
Wayne Roberts |
0:6b3ac9c5a042 | 251 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 252 | FRAME_TYPE_DATA_CONFIRMED_UP = 0x04, |
Wayne Roberts |
0:6b3ac9c5a042 | 253 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 254 | * LoRaMAC confirmed down-link frame |
Wayne Roberts |
0:6b3ac9c5a042 | 255 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 256 | FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05, |
Wayne Roberts |
0:6b3ac9c5a042 | 257 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 258 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 259 | * LoRaMAC rejoin frame |
Wayne Roberts |
0:6b3ac9c5a042 | 260 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 261 | FRAME_TYPE_REJOIN_REQ = 0x06, |
Wayne Roberts |
0:6b3ac9c5a042 | 262 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 263 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 264 | * LoRaMAC proprietary frame |
Wayne Roberts |
0:6b3ac9c5a042 | 265 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 266 | FRAME_TYPE_PROPRIETARY = 0x07, |
Wayne Roberts |
0:6b3ac9c5a042 | 267 | } LoRaMacFrameType_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 268 | |
Wayne Roberts |
0:6b3ac9c5a042 | 269 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 270 | * LoRaMAC server MAC commands |
Wayne Roberts |
0:6b3ac9c5a042 | 271 | * |
Wayne Roberts |
0:6b3ac9c5a042 | 272 | * LoRaWAN Specification V1.0.1 chapter 5, table 4 |
Wayne Roberts |
0:6b3ac9c5a042 | 273 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 274 | typedef enum eLoRaMacSrvCmd |
Wayne Roberts |
0:6b3ac9c5a042 | 275 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 276 | #ifndef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 277 | SRV_MAC_RESET_CONF = 0x01, |
Wayne Roberts |
0:6b3ac9c5a042 | 278 | #endif /* !LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 279 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 280 | * LinkCheckAns |
Wayne Roberts |
0:6b3ac9c5a042 | 281 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 282 | SRV_MAC_LINK_CHECK_ANS = 0x02, |
Wayne Roberts |
0:6b3ac9c5a042 | 283 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 284 | * LinkADRReq |
Wayne Roberts |
0:6b3ac9c5a042 | 285 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 286 | SRV_MAC_LINK_ADR_REQ = 0x03, |
Wayne Roberts |
0:6b3ac9c5a042 | 287 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 288 | * DutyCycleReq |
Wayne Roberts |
0:6b3ac9c5a042 | 289 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 290 | SRV_MAC_DUTY_CYCLE_REQ = 0x04, |
Wayne Roberts |
0:6b3ac9c5a042 | 291 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 292 | * RXParamSetupReq |
Wayne Roberts |
0:6b3ac9c5a042 | 293 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 294 | SRV_MAC_RX_PARAM_SETUP_REQ = 0x05, |
Wayne Roberts |
0:6b3ac9c5a042 | 295 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 296 | * DevStatusReq |
Wayne Roberts |
0:6b3ac9c5a042 | 297 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 298 | SRV_MAC_DEV_STATUS_REQ = 0x06, |
Wayne Roberts |
0:6b3ac9c5a042 | 299 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 300 | * NewChannelReq |
Wayne Roberts |
0:6b3ac9c5a042 | 301 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 302 | SRV_MAC_NEW_CHANNEL_REQ = 0x07, |
Wayne Roberts |
0:6b3ac9c5a042 | 303 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 304 | * RXTimingSetupReq |
Wayne Roberts |
0:6b3ac9c5a042 | 305 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 306 | SRV_MAC_RX_TIMING_SETUP_REQ = 0x08, |
Wayne Roberts |
0:6b3ac9c5a042 | 307 | |
Wayne Roberts |
3:eb174e10afbb | 308 | SRV_MAC_ADR_PARAM_SETUP_REQ = 0x0c, |
Wayne Roberts |
0:6b3ac9c5a042 | 309 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
0:6b3ac9c5a042 | 310 | SRV_MAC_REKEY_CONF = 0x0b, |
Wayne Roberts |
0:6b3ac9c5a042 | 311 | SRV_MAC_FORCE_REJOIN_REQ = 0x0e, |
Wayne Roberts |
0:6b3ac9c5a042 | 312 | SRV_MAC_REJOIN_PARAM_REQ = 0x0f, |
Wayne Roberts |
0:6b3ac9c5a042 | 313 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 314 | SRV_MAC_DEVICE_TIME_ANS = 0x0d, |
Wayne Roberts |
0:6b3ac9c5a042 | 315 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 316 | * PingSlotInfoAns |
Wayne Roberts |
0:6b3ac9c5a042 | 317 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 318 | SRV_MAC_PING_SLOT_INFO_ANS = 0x10, |
Wayne Roberts |
0:6b3ac9c5a042 | 319 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 320 | * PingSlotChannelReq |
Wayne Roberts |
0:6b3ac9c5a042 | 321 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 322 | SRV_MAC_PING_SLOT_CHANNEL_REQ = 0x11, |
Wayne Roberts |
0:6b3ac9c5a042 | 323 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 324 | * BeaconTimingAns |
Wayne Roberts |
0:6b3ac9c5a042 | 325 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 326 | SRV_MAC_BEACON_TIMING_ANS = 0x12, |
Wayne Roberts |
0:6b3ac9c5a042 | 327 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 328 | * BeaconFreqReq |
Wayne Roberts |
0:6b3ac9c5a042 | 329 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 330 | SRV_MAC_BEACON_FREQ_REQ = 0x13, |
Wayne Roberts |
7:4b6f960dcca2 | 331 | |
Wayne Roberts |
7:4b6f960dcca2 | 332 | SRV_MAC_MODE_CONF = 0x20 |
Wayne Roberts |
7:4b6f960dcca2 | 333 | } LoRaMacSrvCmd_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 334 | |
Wayne Roberts |
0:6b3ac9c5a042 | 335 | typedef union uLoRaMacFrameCtrl |
Wayne Roberts |
0:6b3ac9c5a042 | 336 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 337 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 338 | * Byte-access to the bits |
Wayne Roberts |
0:6b3ac9c5a042 | 339 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 340 | uint8_t Value; |
Wayne Roberts |
0:6b3ac9c5a042 | 341 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 342 | * Structure containing single access to bits |
Wayne Roberts |
0:6b3ac9c5a042 | 343 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 344 | struct sCtrlBits |
Wayne Roberts |
0:6b3ac9c5a042 | 345 | { |
Wayne Roberts |
0:6b3ac9c5a042 | 346 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 347 | * Frame options length |
Wayne Roberts |
0:6b3ac9c5a042 | 348 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 349 | uint8_t FOptsLen : 4; |
Wayne Roberts |
0:6b3ac9c5a042 | 350 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 351 | * Frame pending bit |
Wayne Roberts |
0:6b3ac9c5a042 | 352 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 353 | uint8_t FPending : 1; |
Wayne Roberts |
0:6b3ac9c5a042 | 354 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 355 | * Message acknowledge bit |
Wayne Roberts |
0:6b3ac9c5a042 | 356 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 357 | uint8_t Ack : 1; |
Wayne Roberts |
0:6b3ac9c5a042 | 358 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 359 | * ADR acknowledgment request bit |
Wayne Roberts |
0:6b3ac9c5a042 | 360 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 361 | uint8_t AdrAckReq : 1; |
Wayne Roberts |
0:6b3ac9c5a042 | 362 | /*! |
Wayne Roberts |
0:6b3ac9c5a042 | 363 | * ADR control in frame header |
Wayne Roberts |
0:6b3ac9c5a042 | 364 | */ |
Wayne Roberts |
0:6b3ac9c5a042 | 365 | uint8_t Adr : 1; |
Wayne Roberts |
0:6b3ac9c5a042 | 366 | }Bits; |
Wayne Roberts |
0:6b3ac9c5a042 | 367 | } LoRaMacFrameCtrl_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 368 | |
Wayne Roberts |
0:6b3ac9c5a042 | 369 | typedef struct { |
Wayne Roberts |
0:6b3ac9c5a042 | 370 | uint16_t channelsMask[6]; |
Wayne Roberts |
0:6b3ac9c5a042 | 371 | uint16_t chMask; |
Wayne Roberts |
0:6b3ac9c5a042 | 372 | uint8_t status; |
Wayne Roberts |
0:6b3ac9c5a042 | 373 | uint8_t chMaskCntl; |
Wayne Roberts |
0:6b3ac9c5a042 | 374 | int8_t datarate; |
Wayne Roberts |
0:6b3ac9c5a042 | 375 | } adr_t; |
Wayne Roberts |
0:6b3ac9c5a042 | 376 | |
Wayne Roberts |
0:6b3ac9c5a042 | 377 | /* from region: */ |
Wayne Roberts |
0:6b3ac9c5a042 | 378 | extern const int8_t TxPowers[]; |
Wayne Roberts |
0:6b3ac9c5a042 | 379 | extern const uint8_t MaxPayloadOfDatarate[]; |
Wayne Roberts |
0:6b3ac9c5a042 | 380 | extern ChannelParams_t Channels[]; |
Wayne Roberts |
0:6b3ac9c5a042 | 381 | extern const uint8_t Datarates[]; |
Wayne Roberts |
0:6b3ac9c5a042 | 382 | LoRaMacStatus_t LoRaMacChannelRemove( uint8_t id ); |
Wayne Roberts |
0:6b3ac9c5a042 | 383 | LoRaMacStatus_t LoRaMacChannelAdd( uint8_t id, ChannelParams_t params ); |
Wayne Roberts |
0:6b3ac9c5a042 | 384 | |
Wayne Roberts |
3:eb174e10afbb | 385 | //void region_adr_next_dr(int8_t* dr, bool); |
Wayne Roberts |
0:6b3ac9c5a042 | 386 | void region_ScheduleTx( void ); |
Wayne Roberts |
0:6b3ac9c5a042 | 387 | uint32_t region_GetRxBandwidth( int8_t datarate ); |
Wayne Roberts |
0:6b3ac9c5a042 | 388 | uint16_t region_GetRxSymbolTimeout( int8_t datarate ); |
Wayne Roberts |
0:6b3ac9c5a042 | 389 | void region_mac_init(void); |
Wayne Roberts |
0:6b3ac9c5a042 | 390 | void region_rx1_setup(uint8_t channel); |
Wayne Roberts |
0:6b3ac9c5a042 | 391 | void region_adr_request(adr_t*); |
Wayne Roberts |
0:6b3ac9c5a042 | 392 | void region_tx_setup(int8_t dbm, uint8_t pkt_len); |
Wayne Roberts |
0:6b3ac9c5a042 | 393 | void region_session_start(LoRaMacEventInfoStatus_t); |
Wayne Roberts |
3:eb174e10afbb | 394 | int8_t region_LimitTxPower( int8_t txPower ); |
Wayne Roberts |
3:eb174e10afbb | 395 | uint8_t region_CountNbEnabledChannels(void); |
Wayne Roberts |
3:eb174e10afbb | 396 | #ifdef LORAWAN_JOIN_EUI |
Wayne Roberts |
3:eb174e10afbb | 397 | int8_t region_AlternateDatarate( uint16_t nbTrials ); |
Wayne Roberts |
3:eb174e10afbb | 398 | #endif /* LORAWAN_JOIN_EUI */ |
Wayne Roberts |
0:6b3ac9c5a042 | 399 | |
Wayne Roberts |
0:6b3ac9c5a042 | 400 | /* from LoRaMac.cpp: */ |
Wayne Roberts |
0:6b3ac9c5a042 | 401 | extern LoRaMacParams_t LoRaMacParams; |
Wayne Roberts |
3:eb174e10afbb | 402 | extern const LoRaMacParams_t LoRaMacParamsDefaults; |
Wayne Roberts |
0:6b3ac9c5a042 | 403 | extern uint8_t Channel; |
Wayne Roberts |
0:6b3ac9c5a042 | 404 | void SendFrameOnChannel( uint8_t ch_num ); |
Wayne Roberts |
0:6b3ac9c5a042 | 405 | void RxWindowSetup( unsigned freq, int8_t datarate, unsigned bandwidth, uint16_t timeout); |
Wayne Roberts |
0:6b3ac9c5a042 | 406 | uint8_t CountBits( uint16_t mask, uint8_t nbBits ); |
Wayne Roberts |
0:6b3ac9c5a042 | 407 | LoRaMacStatus_t AddMacCommand( uint8_t cmd, uint8_t p1, uint8_t p2 ); |
Wayne Roberts |
7:4b6f960dcca2 | 408 | void OnTxDelayedIsr(void); |
Wayne Roberts |
0:6b3ac9c5a042 | 409 | extern LowPowerTimeout TxDelayedEvent; |
Wayne Roberts |
7:4b6f960dcca2 | 410 | extern DeviceClass_t LoRaMacDeviceClass; |
Wayne Roberts |
0:6b3ac9c5a042 | 411 | |
Wayne Roberts |
0:6b3ac9c5a042 | 412 | #endif /* _LORAMACPRIVATE_H_ */ |