Espotel / Mbed 2 deprecated LoRaWAN_Semtech_stack

Dependencies:   SX1272lib mbed

Committer:
mleksio
Date:
Wed Dec 16 14:25:16 2015 +0000
Revision:
0:c58229885f95
first commit

Who changed what in which revision?

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