this is avaiable project

Dependents:   LoRaWAN_MBED

Fork of LoRaMacLib by LoRa All

Committer:
Alliance
Date:
Wed Sep 23 08:11:26 2015 +0000
Revision:
5:50aab2960e8c
Parent:
3:675d14219ad5
Child:
7:7d7f3b88c8a6
Demo version

Who changed what in which revision?

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