20171208

Fork of LoRaWAN-lib by Semtech

Committer:
mluis
Date:
Tue Oct 20 13:21:26 2015 +0000
Revision:
0:91d1a7783bb9
Child:
1:91e4e6c60d1e
Library creation synchronized with GitHub LoRaMac-node v3.4 (https://github.com/Lora-net/LoRaMac-node)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mluis 0:91d1a7783bb9 1 /*
mluis 0:91d1a7783bb9 2 / _____) _ | |
mluis 0:91d1a7783bb9 3 ( (____ _____ ____ _| |_ _____ ____| |__
mluis 0:91d1a7783bb9 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
mluis 0:91d1a7783bb9 5 _____) ) ____| | | || |_| ____( (___| | | |
mluis 0:91d1a7783bb9 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 0:91d1a7783bb9 7 (C)2013 Semtech
mluis 0:91d1a7783bb9 8
mluis 0:91d1a7783bb9 9 Description: LoRa MAC layer implementation
mluis 0:91d1a7783bb9 10
mluis 0:91d1a7783bb9 11 License: Revised BSD License, see LICENSE.TXT file include in the project
mluis 0:91d1a7783bb9 12
mluis 0:91d1a7783bb9 13 Maintainer: Miguel Luis and Gregory Cristian
mluis 0:91d1a7783bb9 14 */
mluis 0:91d1a7783bb9 15 #ifndef __LORAMAC_H__
mluis 0:91d1a7783bb9 16 #define __LORAMAC_H__
mluis 0:91d1a7783bb9 17
mluis 0:91d1a7783bb9 18 // Includes board dependent definitions such as channels frequencies
mluis 0:91d1a7783bb9 19 #include "LoRaMac-board.h"
mluis 0:91d1a7783bb9 20
mluis 0:91d1a7783bb9 21 /*!
mluis 0:91d1a7783bb9 22 * Beacon interval in us
mluis 0:91d1a7783bb9 23 */
mluis 0:91d1a7783bb9 24 #define BEACON_INTERVAL 128000000
mluis 0:91d1a7783bb9 25
mluis 0:91d1a7783bb9 26 /*!
mluis 0:91d1a7783bb9 27 * Class A&B receive delay in us
mluis 0:91d1a7783bb9 28 */
mluis 0:91d1a7783bb9 29 #define RECEIVE_DELAY1 1000000
mluis 0:91d1a7783bb9 30 #define RECEIVE_DELAY2 2000000
mluis 0:91d1a7783bb9 31
mluis 0:91d1a7783bb9 32 /*!
mluis 0:91d1a7783bb9 33 * Join accept receive delay in us
mluis 0:91d1a7783bb9 34 */
mluis 0:91d1a7783bb9 35 #define JOIN_ACCEPT_DELAY1 5000000
mluis 0:91d1a7783bb9 36 #define JOIN_ACCEPT_DELAY2 6000000
mluis 0:91d1a7783bb9 37
mluis 0:91d1a7783bb9 38 /*!
mluis 0:91d1a7783bb9 39 * Class A&B maximum receive window delay in us
mluis 0:91d1a7783bb9 40 */
mluis 0:91d1a7783bb9 41 #define MAX_RX_WINDOW 3000000
mluis 0:91d1a7783bb9 42
mluis 0:91d1a7783bb9 43 /*!
mluis 0:91d1a7783bb9 44 * Maximum allowed gap for the FCNT field
mluis 0:91d1a7783bb9 45 */
mluis 0:91d1a7783bb9 46 #define MAX_FCNT_GAP 16384
mluis 0:91d1a7783bb9 47
mluis 0:91d1a7783bb9 48 /*!
mluis 0:91d1a7783bb9 49 * ADR acknowledgement counter limit
mluis 0:91d1a7783bb9 50 */
mluis 0:91d1a7783bb9 51 #define ADR_ACK_LIMIT 64
mluis 0:91d1a7783bb9 52
mluis 0:91d1a7783bb9 53 /*!
mluis 0:91d1a7783bb9 54 * Number of ADR acknowledgement requests before returning to default datarate
mluis 0:91d1a7783bb9 55 */
mluis 0:91d1a7783bb9 56 #define ADR_ACK_DELAY 32
mluis 0:91d1a7783bb9 57
mluis 0:91d1a7783bb9 58 /*!
mluis 0:91d1a7783bb9 59 * Number of seconds after the start of the second reception window without
mluis 0:91d1a7783bb9 60 * receiving an acknowledge.
mluis 0:91d1a7783bb9 61 * AckTimeout = ACK_TIMEOUT + Random( -ACK_TIMEOUT_RND, ACK_TIMEOUT_RND )
mluis 0:91d1a7783bb9 62 */
mluis 0:91d1a7783bb9 63 #define ACK_TIMEOUT 2000000
mluis 0:91d1a7783bb9 64
mluis 0:91d1a7783bb9 65 /*!
mluis 0:91d1a7783bb9 66 * Random number of seconds after the start of the second reception window without
mluis 0:91d1a7783bb9 67 * receiving an acknowledge
mluis 0:91d1a7783bb9 68 * AckTimeout = ACK_TIMEOUT + Random( -ACK_TIMEOUT_RND, ACK_TIMEOUT_RND )
mluis 0:91d1a7783bb9 69 */
mluis 0:91d1a7783bb9 70 #define ACK_TIMEOUT_RND 1000000
mluis 0:91d1a7783bb9 71
mluis 0:91d1a7783bb9 72 /*!
mluis 0:91d1a7783bb9 73 * Check the Mac layer state every MAC_STATE_CHECK_TIMEOUT
mluis 0:91d1a7783bb9 74 */
mluis 0:91d1a7783bb9 75 #define MAC_STATE_CHECK_TIMEOUT 1000000
mluis 0:91d1a7783bb9 76
mluis 0:91d1a7783bb9 77 /*!
mluis 0:91d1a7783bb9 78 * Maximum number of times the MAC layer tries to get an acknowledge.
mluis 0:91d1a7783bb9 79 */
mluis 0:91d1a7783bb9 80 #define MAX_ACK_RETRIES 8
mluis 0:91d1a7783bb9 81
mluis 0:91d1a7783bb9 82 /*!
mluis 0:91d1a7783bb9 83 * RSSI free threshold
mluis 0:91d1a7783bb9 84 */
mluis 0:91d1a7783bb9 85 #define RSSI_FREE_TH ( int8_t )( -90 ) // [dBm]
mluis 0:91d1a7783bb9 86
mluis 0:91d1a7783bb9 87 /*!
mluis 0:91d1a7783bb9 88 * Frame direction definition
mluis 0:91d1a7783bb9 89 */
mluis 0:91d1a7783bb9 90 #define UP_LINK 0
mluis 0:91d1a7783bb9 91 #define DOWN_LINK 1
mluis 0:91d1a7783bb9 92
mluis 0:91d1a7783bb9 93 /*!
mluis 0:91d1a7783bb9 94 * Sets the length of the LoRaMAC footer field.
mluis 0:91d1a7783bb9 95 * Mainly indicates the MIC field length
mluis 0:91d1a7783bb9 96 */
mluis 0:91d1a7783bb9 97 #define LORAMAC_MFR_LEN 4
mluis 0:91d1a7783bb9 98
mluis 0:91d1a7783bb9 99 /*!
mluis 0:91d1a7783bb9 100 * Syncword for Private LoRa networks
mluis 0:91d1a7783bb9 101 */
mluis 0:91d1a7783bb9 102 #define LORA_MAC_PRIVATE_SYNCWORD 0x12
mluis 0:91d1a7783bb9 103
mluis 0:91d1a7783bb9 104 /*!
mluis 0:91d1a7783bb9 105 * Syncword for Public LoRa networks
mluis 0:91d1a7783bb9 106 */
mluis 0:91d1a7783bb9 107 #define LORA_MAC_PUBLIC_SYNCWORD 0x34
mluis 0:91d1a7783bb9 108
mluis 0:91d1a7783bb9 109 /*!
mluis 0:91d1a7783bb9 110 * LoRaWAN devices classes definition
mluis 0:91d1a7783bb9 111 */
mluis 0:91d1a7783bb9 112 typedef enum
mluis 0:91d1a7783bb9 113 {
mluis 0:91d1a7783bb9 114 CLASS_A,
mluis 0:91d1a7783bb9 115 CLASS_B,
mluis 0:91d1a7783bb9 116 CLASS_C,
mluis 0:91d1a7783bb9 117 }DeviceClass_t;
mluis 0:91d1a7783bb9 118
mluis 0:91d1a7783bb9 119 /*!
mluis 0:91d1a7783bb9 120 * LoRaMAC channels parameters definition
mluis 0:91d1a7783bb9 121 */
mluis 0:91d1a7783bb9 122 typedef union
mluis 0:91d1a7783bb9 123 {
mluis 0:91d1a7783bb9 124 int8_t Value;
mluis 0:91d1a7783bb9 125 struct
mluis 0:91d1a7783bb9 126 {
mluis 0:91d1a7783bb9 127 int8_t Min : 4;
mluis 0:91d1a7783bb9 128 int8_t Max : 4;
mluis 0:91d1a7783bb9 129 }Fields;
mluis 0:91d1a7783bb9 130 }DrRange_t;
mluis 0:91d1a7783bb9 131
mluis 0:91d1a7783bb9 132 typedef struct
mluis 0:91d1a7783bb9 133 {
mluis 0:91d1a7783bb9 134 uint16_t DCycle;
mluis 0:91d1a7783bb9 135 int8_t TxMaxPower;
mluis 0:91d1a7783bb9 136 uint64_t LastTxDoneTime;
mluis 0:91d1a7783bb9 137 uint64_t TimeOff;
mluis 0:91d1a7783bb9 138 }Band_t;
mluis 0:91d1a7783bb9 139
mluis 0:91d1a7783bb9 140 typedef struct
mluis 0:91d1a7783bb9 141 {
mluis 0:91d1a7783bb9 142 uint32_t Frequency; // Hz
mluis 0:91d1a7783bb9 143 DrRange_t DrRange; // Max datarate [0: SF12, 1: SF11, 2: SF10, 3: SF9, 4: SF8, 5: SF7, 6: SF7, 7: FSK]
mluis 0:91d1a7783bb9 144 // Min datarate [0: SF12, 1: SF11, 2: SF10, 3: SF9, 4: SF8, 5: SF7, 6: SF7, 7: FSK]
mluis 0:91d1a7783bb9 145 uint8_t Band; // Band index
mluis 0:91d1a7783bb9 146 }ChannelParams_t;
mluis 0:91d1a7783bb9 147
mluis 0:91d1a7783bb9 148 typedef struct
mluis 0:91d1a7783bb9 149 {
mluis 0:91d1a7783bb9 150 uint32_t Frequency; // Hz
mluis 0:91d1a7783bb9 151 uint8_t Datarate; // [0: SF12, 1: SF11, 2: SF10, 3: SF9, 4: SF8, 5: SF7, 6: SF7, 7: FSK]
mluis 0:91d1a7783bb9 152 }Rx2ChannelParams_t;
mluis 0:91d1a7783bb9 153
mluis 0:91d1a7783bb9 154 typedef struct MulticastParams_s
mluis 0:91d1a7783bb9 155 {
mluis 0:91d1a7783bb9 156 uint32_t Address;
mluis 0:91d1a7783bb9 157 uint8_t NwkSKey[16];
mluis 0:91d1a7783bb9 158 uint8_t AppSKey[16];
mluis 0:91d1a7783bb9 159 uint32_t DownLinkCounter;
mluis 0:91d1a7783bb9 160 struct MulticastParams_s *Next;
mluis 0:91d1a7783bb9 161 }MulticastParams_t;
mluis 0:91d1a7783bb9 162
mluis 0:91d1a7783bb9 163 /*!
mluis 0:91d1a7783bb9 164 * LoRaMAC frame types
mluis 0:91d1a7783bb9 165 */
mluis 0:91d1a7783bb9 166 typedef enum
mluis 0:91d1a7783bb9 167 {
mluis 0:91d1a7783bb9 168 FRAME_TYPE_JOIN_REQ = 0x00,
mluis 0:91d1a7783bb9 169 FRAME_TYPE_JOIN_ACCEPT = 0x01,
mluis 0:91d1a7783bb9 170 FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02,
mluis 0:91d1a7783bb9 171 FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
mluis 0:91d1a7783bb9 172 FRAME_TYPE_DATA_CONFIRMED_UP = 0x04,
mluis 0:91d1a7783bb9 173 FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05,
mluis 0:91d1a7783bb9 174 FRAME_TYPE_RFU = 0x06,
mluis 0:91d1a7783bb9 175 FRAME_TYPE_PROPRIETARY = 0x07,
mluis 0:91d1a7783bb9 176 }LoRaMacFrameType_t;
mluis 0:91d1a7783bb9 177
mluis 0:91d1a7783bb9 178 /*!
mluis 0:91d1a7783bb9 179 * LoRaMAC mote MAC commands
mluis 0:91d1a7783bb9 180 */
mluis 0:91d1a7783bb9 181 typedef enum
mluis 0:91d1a7783bb9 182 {
mluis 0:91d1a7783bb9 183 MOTE_MAC_LINK_CHECK_REQ = 0x02,
mluis 0:91d1a7783bb9 184 MOTE_MAC_LINK_ADR_ANS = 0x03,
mluis 0:91d1a7783bb9 185 MOTE_MAC_DUTY_CYCLE_ANS = 0x04,
mluis 0:91d1a7783bb9 186 MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05,
mluis 0:91d1a7783bb9 187 MOTE_MAC_DEV_STATUS_ANS = 0x06,
mluis 0:91d1a7783bb9 188 MOTE_MAC_NEW_CHANNEL_ANS = 0x07,
mluis 0:91d1a7783bb9 189 MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08,
mluis 0:91d1a7783bb9 190 }LoRaMacMoteCmd_t;
mluis 0:91d1a7783bb9 191
mluis 0:91d1a7783bb9 192 /*!
mluis 0:91d1a7783bb9 193 * LoRaMAC server MAC commands
mluis 0:91d1a7783bb9 194 */
mluis 0:91d1a7783bb9 195 typedef enum
mluis 0:91d1a7783bb9 196 {
mluis 0:91d1a7783bb9 197 SRV_MAC_LINK_CHECK_ANS = 0x02,
mluis 0:91d1a7783bb9 198 SRV_MAC_LINK_ADR_REQ = 0x03,
mluis 0:91d1a7783bb9 199 SRV_MAC_DUTY_CYCLE_REQ = 0x04,
mluis 0:91d1a7783bb9 200 SRV_MAC_RX_PARAM_SETUP_REQ = 0x05,
mluis 0:91d1a7783bb9 201 SRV_MAC_DEV_STATUS_REQ = 0x06,
mluis 0:91d1a7783bb9 202 SRV_MAC_NEW_CHANNEL_REQ = 0x07,
mluis 0:91d1a7783bb9 203 SRV_MAC_RX_TIMING_SETUP_REQ = 0x08,
mluis 0:91d1a7783bb9 204 }LoRaMacSrvCmd_t;
mluis 0:91d1a7783bb9 205
mluis 0:91d1a7783bb9 206 /*!
mluis 0:91d1a7783bb9 207 * LoRaMAC Battery level indicator
mluis 0:91d1a7783bb9 208 */
mluis 0:91d1a7783bb9 209 typedef enum
mluis 0:91d1a7783bb9 210 {
mluis 0:91d1a7783bb9 211 BAT_LEVEL_EXT_SRC = 0x00,
mluis 0:91d1a7783bb9 212 BAT_LEVEL_EMPTY = 0x01,
mluis 0:91d1a7783bb9 213 BAT_LEVEL_FULL = 0xFE,
mluis 0:91d1a7783bb9 214 BAT_LEVEL_NO_MEASURE = 0xFF,
mluis 0:91d1a7783bb9 215 }LoRaMacBatteryLevel_t;
mluis 0:91d1a7783bb9 216
mluis 0:91d1a7783bb9 217 /*!
mluis 0:91d1a7783bb9 218 * LoRaMAC header field definition
mluis 0:91d1a7783bb9 219 */
mluis 0:91d1a7783bb9 220 typedef union
mluis 0:91d1a7783bb9 221 {
mluis 0:91d1a7783bb9 222 uint8_t Value;
mluis 0:91d1a7783bb9 223 struct
mluis 0:91d1a7783bb9 224 {
mluis 0:91d1a7783bb9 225 uint8_t Major : 2;
mluis 0:91d1a7783bb9 226 uint8_t RFU : 3;
mluis 0:91d1a7783bb9 227 uint8_t MType : 3;
mluis 0:91d1a7783bb9 228 }Bits;
mluis 0:91d1a7783bb9 229 }LoRaMacHeader_t;
mluis 0:91d1a7783bb9 230
mluis 0:91d1a7783bb9 231 /*!
mluis 0:91d1a7783bb9 232 * LoRaMAC frame header field definition
mluis 0:91d1a7783bb9 233 */
mluis 0:91d1a7783bb9 234 typedef union
mluis 0:91d1a7783bb9 235 {
mluis 0:91d1a7783bb9 236 uint8_t Value;
mluis 0:91d1a7783bb9 237 struct
mluis 0:91d1a7783bb9 238 {
mluis 0:91d1a7783bb9 239 uint8_t FOptsLen : 4;
mluis 0:91d1a7783bb9 240 uint8_t FPending : 1;
mluis 0:91d1a7783bb9 241 uint8_t Ack : 1;
mluis 0:91d1a7783bb9 242 uint8_t AdrAckReq : 1;
mluis 0:91d1a7783bb9 243 uint8_t Adr : 1;
mluis 0:91d1a7783bb9 244 }Bits;
mluis 0:91d1a7783bb9 245 }LoRaMacFrameCtrl_t;
mluis 0:91d1a7783bb9 246
mluis 0:91d1a7783bb9 247 /*!
mluis 0:91d1a7783bb9 248 * LoRaMAC event flags
mluis 0:91d1a7783bb9 249 */
mluis 0:91d1a7783bb9 250 typedef union
mluis 0:91d1a7783bb9 251 {
mluis 0:91d1a7783bb9 252 uint8_t Value;
mluis 0:91d1a7783bb9 253 struct
mluis 0:91d1a7783bb9 254 {
mluis 0:91d1a7783bb9 255 uint8_t Tx : 1;
mluis 0:91d1a7783bb9 256 uint8_t Rx : 1;
mluis 0:91d1a7783bb9 257 uint8_t RxData : 1;
mluis 0:91d1a7783bb9 258 uint8_t Multicast : 1;
mluis 0:91d1a7783bb9 259 uint8_t RxSlot : 2;
mluis 0:91d1a7783bb9 260 uint8_t LinkCheck : 1;
mluis 0:91d1a7783bb9 261 uint8_t JoinAccept : 1;
mluis 0:91d1a7783bb9 262 }Bits;
mluis 0:91d1a7783bb9 263 }LoRaMacEventFlags_t;
mluis 0:91d1a7783bb9 264
mluis 0:91d1a7783bb9 265 typedef enum
mluis 0:91d1a7783bb9 266 {
mluis 0:91d1a7783bb9 267 LORAMAC_EVENT_INFO_STATUS_OK = 0,
mluis 0:91d1a7783bb9 268 LORAMAC_EVENT_INFO_STATUS_ERROR,
mluis 0:91d1a7783bb9 269 LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT,
mluis 0:91d1a7783bb9 270 LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT,
mluis 0:91d1a7783bb9 271 LORAMAC_EVENT_INFO_STATUS_RX2_ERROR,
mluis 0:91d1a7783bb9 272 LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
mluis 0:91d1a7783bb9 273 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL,
mluis 0:91d1a7783bb9 274 LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL,
mluis 0:91d1a7783bb9 275 LORAMAC_EVENT_INFO_STATUS_MIC_FAIL,
mluis 0:91d1a7783bb9 276 }LoRaMacEventInfoStatus_t;
mluis 0:91d1a7783bb9 277
mluis 0:91d1a7783bb9 278 /*!
mluis 0:91d1a7783bb9 279 * LoRaMAC event information
mluis 0:91d1a7783bb9 280 */
mluis 0:91d1a7783bb9 281 typedef struct
mluis 0:91d1a7783bb9 282 {
mluis 0:91d1a7783bb9 283 LoRaMacEventInfoStatus_t Status;
mluis 0:91d1a7783bb9 284 bool TxAckReceived;
mluis 0:91d1a7783bb9 285 uint8_t TxNbRetries;
mluis 0:91d1a7783bb9 286 uint8_t TxDatarate;
mluis 0:91d1a7783bb9 287 uint8_t RxPort;
mluis 0:91d1a7783bb9 288 uint8_t *RxBuffer;
mluis 0:91d1a7783bb9 289 uint8_t RxBufferSize;
mluis 0:91d1a7783bb9 290 int16_t RxRssi;
mluis 0:91d1a7783bb9 291 uint8_t RxSnr;
mluis 0:91d1a7783bb9 292 uint16_t Energy;
mluis 0:91d1a7783bb9 293 uint8_t DemodMargin;
mluis 0:91d1a7783bb9 294 uint8_t NbGateways;
mluis 0:91d1a7783bb9 295 }LoRaMacEventInfo_t;
mluis 0:91d1a7783bb9 296
mluis 0:91d1a7783bb9 297 /*!
mluis 0:91d1a7783bb9 298 * LoRaMAC events structure
mluis 0:91d1a7783bb9 299 * Used to notify upper layers of MAC events
mluis 0:91d1a7783bb9 300 */
mluis 0:91d1a7783bb9 301 typedef struct sLoRaMacEvent
mluis 0:91d1a7783bb9 302 {
mluis 0:91d1a7783bb9 303 /*!
mluis 0:91d1a7783bb9 304 * MAC layer event callback prototype.
mluis 0:91d1a7783bb9 305 *
mluis 0:91d1a7783bb9 306 * \param [IN] flags Bit field indicating the MAC events occurred
mluis 0:91d1a7783bb9 307 * \param [IN] info Details about MAC events occurred
mluis 0:91d1a7783bb9 308 */
mluis 0:91d1a7783bb9 309 void ( *MacEvent )( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info );
mluis 0:91d1a7783bb9 310 }LoRaMacEvent_t;
mluis 0:91d1a7783bb9 311
mluis 0:91d1a7783bb9 312 /*!
mluis 0:91d1a7783bb9 313 * LoRaMAC layer initialization
mluis 0:91d1a7783bb9 314 *
mluis 0:91d1a7783bb9 315 * \param [IN] events Pointer to a structure defining the LoRaMAC
mluis 0:91d1a7783bb9 316 * callback functions.
mluis 0:91d1a7783bb9 317 * \param [IN] getBatteryLevel Function callback to get the current
mluis 0:91d1a7783bb9 318 * battery level
mluis 0:91d1a7783bb9 319 */
mluis 0:91d1a7783bb9 320 void LoRaMacInit( LoRaMacEvent_t *events, uint8_t ( *getBatteryLevel )( ) );
mluis 0:91d1a7783bb9 321
mluis 0:91d1a7783bb9 322 /*!
mluis 0:91d1a7783bb9 323 * Enables/Disables the ADR (Adaptive Data Rate)
mluis 0:91d1a7783bb9 324 *
mluis 0:91d1a7783bb9 325 * \param [IN] enable [true: ADR ON, false: ADR OFF]
mluis 0:91d1a7783bb9 326 */
mluis 0:91d1a7783bb9 327 void LoRaMacSetAdrOn( bool enable );
mluis 0:91d1a7783bb9 328
mluis 0:91d1a7783bb9 329 /*!
mluis 0:91d1a7783bb9 330 * Initializes the network IDs. Device address,
mluis 0:91d1a7783bb9 331 * network session AES128 key and application session AES128 key.
mluis 0:91d1a7783bb9 332 *
mluis 0:91d1a7783bb9 333 * \remark To be only used when Over-the-Air activation isn't used.
mluis 0:91d1a7783bb9 334 *
mluis 0:91d1a7783bb9 335 * \param [IN] netID 24 bits network identifier
mluis 0:91d1a7783bb9 336 * ( provided by network operator )
mluis 0:91d1a7783bb9 337 * \param [IN] devAddr 32 bits device address on the network
mluis 0:91d1a7783bb9 338 * (must be unique to the network)
mluis 0:91d1a7783bb9 339 * \param [IN] nwkSKey Pointer to the network session AES128 key array
mluis 0:91d1a7783bb9 340 * ( 16 bytes )
mluis 0:91d1a7783bb9 341 * \param [IN] appSKey Pointer to the application session AES128 key array
mluis 0:91d1a7783bb9 342 * ( 16 bytes )
mluis 0:91d1a7783bb9 343 */
mluis 0:91d1a7783bb9 344 void LoRaMacInitNwkIds( uint32_t netID, uint32_t devAddr, uint8_t *nwkSKey, uint8_t *appSKey );
mluis 0:91d1a7783bb9 345
mluis 0:91d1a7783bb9 346 /*
mluis 0:91d1a7783bb9 347 * TODO: Add documentation
mluis 0:91d1a7783bb9 348 */
mluis 0:91d1a7783bb9 349 void LoRaMacMulticastChannelAdd( MulticastParams_t *channelParam );
mluis 0:91d1a7783bb9 350
mluis 0:91d1a7783bb9 351 /*
mluis 0:91d1a7783bb9 352 * TODO: Add documentation
mluis 0:91d1a7783bb9 353 */
mluis 0:91d1a7783bb9 354 void LoRaMacMulticastChannelRemove( MulticastParams_t *channelParam );
mluis 0:91d1a7783bb9 355
mluis 0:91d1a7783bb9 356 /*!
mluis 0:91d1a7783bb9 357 * Initiates the Over-the-Air activation
mluis 0:91d1a7783bb9 358 *
mluis 0:91d1a7783bb9 359 * \param [IN] devEui Pointer to the device EUI array ( 8 bytes )
mluis 0:91d1a7783bb9 360 * \param [IN] appEui Pointer to the application EUI array ( 8 bytes )
mluis 0:91d1a7783bb9 361 * \param [IN] appKey Pointer to the application AES128 key array ( 16 bytes )
mluis 0:91d1a7783bb9 362 *
mluis 0:91d1a7783bb9 363 * \retval status [0: OK, 1: Tx error, 2: Already joined a network]
mluis 0:91d1a7783bb9 364 */
mluis 0:91d1a7783bb9 365 uint8_t LoRaMacJoinReq( uint8_t *devEui, uint8_t *appEui, uint8_t *appKey );
mluis 0:91d1a7783bb9 366
mluis 0:91d1a7783bb9 367 /*!
mluis 0:91d1a7783bb9 368 * Sends a LinkCheckReq MAC command on the next uplink frame
mluis 0:91d1a7783bb9 369 *
mluis 0:91d1a7783bb9 370 * \retval status Function status [0: OK, 1: Busy]
mluis 0:91d1a7783bb9 371 */
mluis 0:91d1a7783bb9 372 uint8_t LoRaMacLinkCheckReq( void );
mluis 0:91d1a7783bb9 373
mluis 0:91d1a7783bb9 374 /*!
mluis 0:91d1a7783bb9 375 * LoRaMAC layer send frame
mluis 0:91d1a7783bb9 376 *
mluis 0:91d1a7783bb9 377 * \param [IN] fPort MAC payload port (must be > 0)
mluis 0:91d1a7783bb9 378 * \param [IN] fBuffer MAC data buffer to be sent
mluis 0:91d1a7783bb9 379 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 380 *
mluis 0:91d1a7783bb9 381 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 0:91d1a7783bb9 382 * 3: Length or port error, 4: Unknown MAC command
mluis 0:91d1a7783bb9 383 * 5: Unable to find a free channel
mluis 0:91d1a7783bb9 384 * 6: Device switched off]
mluis 0:91d1a7783bb9 385 */
mluis 0:91d1a7783bb9 386 uint8_t LoRaMacSendFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 0:91d1a7783bb9 387
mluis 0:91d1a7783bb9 388 /*!
mluis 0:91d1a7783bb9 389 * LoRaMAC layer send frame
mluis 0:91d1a7783bb9 390 *
mluis 0:91d1a7783bb9 391 * \param [IN] fPort MAC payload port (must be > 0)
mluis 0:91d1a7783bb9 392 * \param [IN] fBuffer MAC data buffer to be sent
mluis 0:91d1a7783bb9 393 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 394 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 395 * \param [IN] nbRetries Number of retries to receive the acknowledgement
mluis 0:91d1a7783bb9 396 *
mluis 0:91d1a7783bb9 397 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 0:91d1a7783bb9 398 * 3: Length or port error, 4: Unknown MAC command
mluis 0:91d1a7783bb9 399 * 5: Unable to find a free channel
mluis 0:91d1a7783bb9 400 * 6: Device switched off]
mluis 0:91d1a7783bb9 401 */
mluis 0:91d1a7783bb9 402 uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries );
mluis 0:91d1a7783bb9 403
mluis 0:91d1a7783bb9 404 /*!
mluis 0:91d1a7783bb9 405 * ============================================================================
mluis 0:91d1a7783bb9 406 * = LoRaMac test functions =
mluis 0:91d1a7783bb9 407 * ============================================================================
mluis 0:91d1a7783bb9 408 */
mluis 0:91d1a7783bb9 409
mluis 0:91d1a7783bb9 410 /*!
mluis 0:91d1a7783bb9 411 * LoRaMAC layer generic send frame
mluis 0:91d1a7783bb9 412 *
mluis 0:91d1a7783bb9 413 * \param [IN] macHdr MAC header field
mluis 0:91d1a7783bb9 414 * \param [IN] fOpts MAC commands buffer
mluis 0:91d1a7783bb9 415 * \param [IN] fPort MAC payload port
mluis 0:91d1a7783bb9 416 * \param [IN] fBuffer MAC data buffer to be sent
mluis 0:91d1a7783bb9 417 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 418 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 0:91d1a7783bb9 419 * 3: Length or port error, 4: Unknown MAC command
mluis 0:91d1a7783bb9 420 * 5: Unable to find a free channel
mluis 0:91d1a7783bb9 421 * 6: Device switched off]
mluis 0:91d1a7783bb9 422 */
mluis 0:91d1a7783bb9 423 uint8_t LoRaMacSend( LoRaMacHeader_t *macHdr, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 0:91d1a7783bb9 424
mluis 0:91d1a7783bb9 425 /*!
mluis 0:91d1a7783bb9 426 * LoRaMAC layer frame buffer initialization.
mluis 0:91d1a7783bb9 427 *
mluis 0:91d1a7783bb9 428 * \param [IN] channel Channel parameters
mluis 0:91d1a7783bb9 429 * \param [IN] macHdr MAC header field
mluis 0:91d1a7783bb9 430 * \param [IN] fCtrl MAC frame control field
mluis 0:91d1a7783bb9 431 * \param [IN] fOpts MAC commands buffer
mluis 0:91d1a7783bb9 432 * \param [IN] fPort MAC payload port
mluis 0:91d1a7783bb9 433 * \param [IN] fBuffer MAC data buffer to be sent
mluis 0:91d1a7783bb9 434 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 435 * \retval status [0: OK, 1: N/A, 2: No network joined,
mluis 0:91d1a7783bb9 436 * 3: Length or port error, 4: Unknown MAC command]
mluis 0:91d1a7783bb9 437 */
mluis 0:91d1a7783bb9 438 uint8_t LoRaMacPrepareFrame( ChannelParams_t channel,LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 0:91d1a7783bb9 439
mluis 0:91d1a7783bb9 440 /*!
mluis 0:91d1a7783bb9 441 * LoRaMAC layer prepared frame buffer transmission with channel specification
mluis 0:91d1a7783bb9 442 *
mluis 0:91d1a7783bb9 443 * \remark LoRaMacPrepareFrame must be called at least once before calling this
mluis 0:91d1a7783bb9 444 * function.
mluis 0:91d1a7783bb9 445 *
mluis 0:91d1a7783bb9 446 * \param [IN] channel Channel parameters
mluis 0:91d1a7783bb9 447 * \retval status [0: OK, 1: Busy]
mluis 0:91d1a7783bb9 448 */
mluis 0:91d1a7783bb9 449 uint8_t LoRaMacSendFrameOnChannel( ChannelParams_t channel );
mluis 0:91d1a7783bb9 450
mluis 0:91d1a7783bb9 451 /*!
mluis 0:91d1a7783bb9 452 * LoRaMAC layer generic send frame with channel specification
mluis 0:91d1a7783bb9 453 *
mluis 0:91d1a7783bb9 454 * \param [IN] channel Channel parameters
mluis 0:91d1a7783bb9 455 * \param [IN] macHdr MAC header field
mluis 0:91d1a7783bb9 456 * \param [IN] fCtrl MAC frame control field
mluis 0:91d1a7783bb9 457 * \param [IN] fOpts MAC commands buffer
mluis 0:91d1a7783bb9 458 * \param [IN] fPort MAC payload port
mluis 0:91d1a7783bb9 459 * \param [IN] fBuffer MAC data buffer to be sent
mluis 0:91d1a7783bb9 460 * \param [IN] fBufferSize MAC data buffer size
mluis 0:91d1a7783bb9 461 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 0:91d1a7783bb9 462 * 3: Length or port error, 4: Unknown MAC command]
mluis 0:91d1a7783bb9 463 */
mluis 0:91d1a7783bb9 464 uint8_t LoRaMacSendOnChannel( ChannelParams_t channel, LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 0:91d1a7783bb9 465
mluis 0:91d1a7783bb9 466 /*!
mluis 0:91d1a7783bb9 467 * ============================================================================
mluis 0:91d1a7783bb9 468 * = LoRaMac setup functions =
mluis 0:91d1a7783bb9 469 * ============================================================================
mluis 0:91d1a7783bb9 470 */
mluis 0:91d1a7783bb9 471
mluis 0:91d1a7783bb9 472 /*
mluis 0:91d1a7783bb9 473 * TODO: Add documentation
mluis 0:91d1a7783bb9 474 */
mluis 0:91d1a7783bb9 475 void LoRaMacSetDeviceClass( DeviceClass_t deviceClass );
mluis 0:91d1a7783bb9 476
mluis 0:91d1a7783bb9 477 /*
mluis 0:91d1a7783bb9 478 * TODO: Add documentation
mluis 0:91d1a7783bb9 479 */
mluis 0:91d1a7783bb9 480 void LoRaMacSetPublicNetwork( bool enable );
mluis 0:91d1a7783bb9 481
mluis 0:91d1a7783bb9 482 /*
mluis 0:91d1a7783bb9 483 * TODO: Add documentation
mluis 0:91d1a7783bb9 484 */
mluis 0:91d1a7783bb9 485 void LoRaMacSetChannel( uint8_t id, ChannelParams_t params );
mluis 0:91d1a7783bb9 486
mluis 0:91d1a7783bb9 487 /*
mluis 0:91d1a7783bb9 488 * TODO: Add documentation
mluis 0:91d1a7783bb9 489 */
mluis 0:91d1a7783bb9 490 void LoRaMacSetRx2Channel( Rx2ChannelParams_t param );
mluis 0:91d1a7783bb9 491
mluis 0:91d1a7783bb9 492 /*!
mluis 0:91d1a7783bb9 493 * Sets channels tx output power
mluis 0:91d1a7783bb9 494 *
mluis 0:91d1a7783bb9 495 * \param [IN] txPower [TX_POWER_20_DBM, TX_POWER_14_DBM,
mluis 0:91d1a7783bb9 496 TX_POWER_11_DBM, TX_POWER_08_DBM,
mluis 0:91d1a7783bb9 497 TX_POWER_05_DBM, TX_POWER_02_DBM]
mluis 0:91d1a7783bb9 498 */
mluis 0:91d1a7783bb9 499 void LoRaMacSetChannelsTxPower( int8_t txPower );
mluis 0:91d1a7783bb9 500
mluis 0:91d1a7783bb9 501 /*!
mluis 0:91d1a7783bb9 502 * Sets channels datarate
mluis 0:91d1a7783bb9 503 *
mluis 0:91d1a7783bb9 504 * \param [IN] datarate eu868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
mluis 0:91d1a7783bb9 505 * us915 - [DR_0, DR_1, DR_2, DR_3, DR_4]
mluis 0:91d1a7783bb9 506 */
mluis 0:91d1a7783bb9 507 void LoRaMacSetChannelsDatarate( int8_t datarate );
mluis 0:91d1a7783bb9 508
mluis 0:91d1a7783bb9 509 /*
mluis 0:91d1a7783bb9 510 * TODO: Add documentation
mluis 0:91d1a7783bb9 511 */
mluis 0:91d1a7783bb9 512 void LoRaMacSetChannelsMask( uint16_t *mask );
mluis 0:91d1a7783bb9 513
mluis 0:91d1a7783bb9 514 /*
mluis 0:91d1a7783bb9 515 * TODO: Add documentation
mluis 0:91d1a7783bb9 516 */
mluis 0:91d1a7783bb9 517 void LoRaMacSetChannelsNbRep( uint8_t nbRep );
mluis 0:91d1a7783bb9 518
mluis 0:91d1a7783bb9 519 /*
mluis 0:91d1a7783bb9 520 * TODO: Add documentation
mluis 0:91d1a7783bb9 521 */
mluis 0:91d1a7783bb9 522 void LoRaMacSetMaxRxWindow( uint32_t delay );
mluis 0:91d1a7783bb9 523
mluis 0:91d1a7783bb9 524 /*
mluis 0:91d1a7783bb9 525 * TODO: Add documentation
mluis 0:91d1a7783bb9 526 */
mluis 0:91d1a7783bb9 527 void LoRaMacSetReceiveDelay1( uint32_t delay );
mluis 0:91d1a7783bb9 528
mluis 0:91d1a7783bb9 529 /*
mluis 0:91d1a7783bb9 530 * TODO: Add documentation
mluis 0:91d1a7783bb9 531 */
mluis 0:91d1a7783bb9 532 void LoRaMacSetReceiveDelay2( uint32_t delay );
mluis 0:91d1a7783bb9 533
mluis 0:91d1a7783bb9 534 /*
mluis 0:91d1a7783bb9 535 * TODO: Add documentation
mluis 0:91d1a7783bb9 536 */
mluis 0:91d1a7783bb9 537 void LoRaMacSetJoinAcceptDelay1( uint32_t delay );
mluis 0:91d1a7783bb9 538
mluis 0:91d1a7783bb9 539 /*
mluis 0:91d1a7783bb9 540 * TODO: Add documentation
mluis 0:91d1a7783bb9 541 */
mluis 0:91d1a7783bb9 542 void LoRaMacSetJoinAcceptDelay2( uint32_t delay );
mluis 0:91d1a7783bb9 543
mluis 0:91d1a7783bb9 544 /*
mluis 0:91d1a7783bb9 545 * TODO: Add documentation
mluis 0:91d1a7783bb9 546 */
mluis 0:91d1a7783bb9 547 uint32_t LoRaMacGetUpLinkCounter( void );
mluis 0:91d1a7783bb9 548
mluis 0:91d1a7783bb9 549 /*
mluis 0:91d1a7783bb9 550 * TODO: Add documentation
mluis 0:91d1a7783bb9 551 */
mluis 0:91d1a7783bb9 552 uint32_t LoRaMacGetDownLinkCounter( void );
mluis 0:91d1a7783bb9 553
mluis 0:91d1a7783bb9 554 /*
mluis 0:91d1a7783bb9 555 * ============================================================================
mluis 0:91d1a7783bb9 556 * = LoRaMac test functions =
mluis 0:91d1a7783bb9 557 * ============================================================================
mluis 0:91d1a7783bb9 558 */
mluis 0:91d1a7783bb9 559
mluis 0:91d1a7783bb9 560 /*!
mluis 0:91d1a7783bb9 561 * Disables/Enables the duty cycle enforcement (EU868)
mluis 0:91d1a7783bb9 562 *
mluis 0:91d1a7783bb9 563 * \param [IN] enable - Enabled or disables the duty cycle
mluis 0:91d1a7783bb9 564 */
mluis 0:91d1a7783bb9 565 void LoRaMacTestSetDutyCycleOn( bool enable );
mluis 0:91d1a7783bb9 566
mluis 0:91d1a7783bb9 567 /*!
mluis 0:91d1a7783bb9 568 * Disables/Enables the reception windows opening
mluis 0:91d1a7783bb9 569 *
mluis 0:91d1a7783bb9 570 * \param [IN] enable [true: enable, false: disable]
mluis 0:91d1a7783bb9 571 */
mluis 0:91d1a7783bb9 572 void LoRaMacTestRxWindowsOn( bool enable );
mluis 0:91d1a7783bb9 573
mluis 0:91d1a7783bb9 574 /*!
mluis 0:91d1a7783bb9 575 * Enables the MIC field test
mluis 0:91d1a7783bb9 576 *
mluis 0:91d1a7783bb9 577 * \param [IN] upLinkCounter Fixed Tx packet counter value
mluis 0:91d1a7783bb9 578 */
mluis 0:91d1a7783bb9 579 void LoRaMacTestSetMic( uint16_t upLinkCounter );
mluis 0:91d1a7783bb9 580
mluis 0:91d1a7783bb9 581 #endif // __LORAMAC_H__