LoRaWAN MAC layer implementation

Dependents:   LoRaWAN-demo-72_tjm LoRaWAN-demo-72_jlc LoRaWAN-demo-elmo frdm_LoRa_Connect_Woodstream_Demo_tjm ... more

LoRAWAN-lib is a port of the GitHub LoRaMac-node LoRaWAN MAC layer implementation.

This library depends on the SX1276Lib or SX1272Lib radio drivers depending on the used mbed component shield.

This library depends also on some cryptographic helper functions as well as helper functions for the timers management. These can be found on the example projects under the system directory.

The example projects are:

  1. LoRaWAN-demo-72
  2. LoRaWAN-demo-76
  3. LoRaWAN-demo-NAMote72

The LoRaWAN specification specifies different ISM bands operating parameters. These are all implemented under the LoRaMac-board.h file.

In order to select which band to use, please change line 24 of board.h file provided on the examples projects as follows:


EU868

board.h

#define USE_BAND_868


US915

board.h

#define USE_BAND_915


US915 - Hybrid

board.h

#define USE_BAND_915_HYBRID


CN780

board.h

#define USE_BAND_780


EU433

board.h

#define USE_BAND_433
Committer:
mluis
Date:
Tue Jan 05 16:41:54 2016 +0000
Revision:
2:14a5d6ad92d5
Child:
4:37c12dbc8dc7
Synchronized with https://github.com/Lora-net/LoRaMac-node git revision a2226468d470eceb251338e1acfb24cfd121effa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mluis 2:14a5d6ad92d5 1 /*!
mluis 2:14a5d6ad92d5 2 * \file LoRaMac-api-v3.h
mluis 2:14a5d6ad92d5 3 *
mluis 2:14a5d6ad92d5 4 * \brief LoRa MAC wrapper layer implementation
mluis 2:14a5d6ad92d5 5 *
mluis 2:14a5d6ad92d5 6 * \copyright Revised BSD License, see section \ref LICENSE.
mluis 2:14a5d6ad92d5 7 *
mluis 2:14a5d6ad92d5 8 * \code
mluis 2:14a5d6ad92d5 9 * ______ _
mluis 2:14a5d6ad92d5 10 * / _____) _ | |
mluis 2:14a5d6ad92d5 11 * ( (____ _____ ____ _| |_ _____ ____| |__
mluis 2:14a5d6ad92d5 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \
mluis 2:14a5d6ad92d5 13 * _____) ) ____| | | || |_| ____( (___| | | |
mluis 2:14a5d6ad92d5 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 2:14a5d6ad92d5 15 * (C)2013 Semtech
mluis 2:14a5d6ad92d5 16 *
mluis 2:14a5d6ad92d5 17 * ___ _____ _ ___ _ _____ ___ ___ ___ ___
mluis 2:14a5d6ad92d5 18 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
mluis 2:14a5d6ad92d5 19 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
mluis 2:14a5d6ad92d5 20 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
mluis 2:14a5d6ad92d5 21 * embedded.connectivity.solutions===============
mluis 2:14a5d6ad92d5 22 *
mluis 2:14a5d6ad92d5 23 * \endcode
mluis 2:14a5d6ad92d5 24 *
mluis 2:14a5d6ad92d5 25 * \author Miguel Luis ( Semtech )
mluis 2:14a5d6ad92d5 26 *
mluis 2:14a5d6ad92d5 27 * \author Gregory Cristian ( Semtech )
mluis 2:14a5d6ad92d5 28 *
mluis 2:14a5d6ad92d5 29 * \author Daniel Jäckle ( STACKFORCE )
mluis 2:14a5d6ad92d5 30 */
mluis 2:14a5d6ad92d5 31 #ifndef __LORAMAC_API_V3_H__
mluis 2:14a5d6ad92d5 32 #define __LORAMAC_API_V3_H__
mluis 2:14a5d6ad92d5 33
mluis 2:14a5d6ad92d5 34 // Includes board dependent definitions such as channels frequencies
mluis 2:14a5d6ad92d5 35 #include "LoRaMac.h"
mluis 2:14a5d6ad92d5 36 #include "LoRaMac-board.h"
mluis 2:14a5d6ad92d5 37
mluis 2:14a5d6ad92d5 38 /*!
mluis 2:14a5d6ad92d5 39 * Beacon interval in us
mluis 2:14a5d6ad92d5 40 */
mluis 2:14a5d6ad92d5 41 #define BEACON_INTERVAL 128000000
mluis 2:14a5d6ad92d5 42
mluis 2:14a5d6ad92d5 43 /*!
mluis 2:14a5d6ad92d5 44 * Class A&B receive delay in us
mluis 2:14a5d6ad92d5 45 */
mluis 2:14a5d6ad92d5 46 #define RECEIVE_DELAY1 1000000
mluis 2:14a5d6ad92d5 47 #define RECEIVE_DELAY2 2000000
mluis 2:14a5d6ad92d5 48
mluis 2:14a5d6ad92d5 49 /*!
mluis 2:14a5d6ad92d5 50 * Join accept receive delay in us
mluis 2:14a5d6ad92d5 51 */
mluis 2:14a5d6ad92d5 52 #define JOIN_ACCEPT_DELAY1 5000000
mluis 2:14a5d6ad92d5 53 #define JOIN_ACCEPT_DELAY2 6000000
mluis 2:14a5d6ad92d5 54
mluis 2:14a5d6ad92d5 55 /*!
mluis 2:14a5d6ad92d5 56 * Class A&B maximum receive window delay in us
mluis 2:14a5d6ad92d5 57 */
mluis 2:14a5d6ad92d5 58 #define MAX_RX_WINDOW 3000000
mluis 2:14a5d6ad92d5 59
mluis 2:14a5d6ad92d5 60 /*!
mluis 2:14a5d6ad92d5 61 * Maximum allowed gap for the FCNT field
mluis 2:14a5d6ad92d5 62 */
mluis 2:14a5d6ad92d5 63 #define MAX_FCNT_GAP 16384
mluis 2:14a5d6ad92d5 64
mluis 2:14a5d6ad92d5 65 /*!
mluis 2:14a5d6ad92d5 66 * ADR acknowledgement counter limit
mluis 2:14a5d6ad92d5 67 */
mluis 2:14a5d6ad92d5 68 #define ADR_ACK_LIMIT 64
mluis 2:14a5d6ad92d5 69
mluis 2:14a5d6ad92d5 70 /*!
mluis 2:14a5d6ad92d5 71 * Number of ADR acknowledgement requests before returning to default datarate
mluis 2:14a5d6ad92d5 72 */
mluis 2:14a5d6ad92d5 73 #define ADR_ACK_DELAY 32
mluis 2:14a5d6ad92d5 74
mluis 2:14a5d6ad92d5 75 /*!
mluis 2:14a5d6ad92d5 76 * Number of seconds after the start of the second reception window without
mluis 2:14a5d6ad92d5 77 * receiving an acknowledge.
mluis 2:14a5d6ad92d5 78 * AckTimeout = ACK_TIMEOUT + Random( -ACK_TIMEOUT_RND, ACK_TIMEOUT_RND )
mluis 2:14a5d6ad92d5 79 */
mluis 2:14a5d6ad92d5 80 #define ACK_TIMEOUT 2000000
mluis 2:14a5d6ad92d5 81
mluis 2:14a5d6ad92d5 82 /*!
mluis 2:14a5d6ad92d5 83 * Random number of seconds after the start of the second reception window without
mluis 2:14a5d6ad92d5 84 * receiving an acknowledge
mluis 2:14a5d6ad92d5 85 * AckTimeout = ACK_TIMEOUT + Random( -ACK_TIMEOUT_RND, ACK_TIMEOUT_RND )
mluis 2:14a5d6ad92d5 86 */
mluis 2:14a5d6ad92d5 87 #define ACK_TIMEOUT_RND 1000000
mluis 2:14a5d6ad92d5 88
mluis 2:14a5d6ad92d5 89 /*!
mluis 2:14a5d6ad92d5 90 * Check the Mac layer state every MAC_STATE_CHECK_TIMEOUT
mluis 2:14a5d6ad92d5 91 */
mluis 2:14a5d6ad92d5 92 #define MAC_STATE_CHECK_TIMEOUT 1000000
mluis 2:14a5d6ad92d5 93
mluis 2:14a5d6ad92d5 94 /*!
mluis 2:14a5d6ad92d5 95 * Maximum number of times the MAC layer tries to get an acknowledge.
mluis 2:14a5d6ad92d5 96 */
mluis 2:14a5d6ad92d5 97 #define MAX_ACK_RETRIES 8
mluis 2:14a5d6ad92d5 98
mluis 2:14a5d6ad92d5 99 /*!
mluis 2:14a5d6ad92d5 100 * RSSI free threshold
mluis 2:14a5d6ad92d5 101 */
mluis 2:14a5d6ad92d5 102 #define RSSI_FREE_TH ( int8_t )( -90 ) // [dBm]
mluis 2:14a5d6ad92d5 103
mluis 2:14a5d6ad92d5 104 /*!
mluis 2:14a5d6ad92d5 105 * Frame direction definition
mluis 2:14a5d6ad92d5 106 */
mluis 2:14a5d6ad92d5 107 #define UP_LINK 0
mluis 2:14a5d6ad92d5 108 #define DOWN_LINK 1
mluis 2:14a5d6ad92d5 109
mluis 2:14a5d6ad92d5 110 /*!
mluis 2:14a5d6ad92d5 111 * Sets the length of the LoRaMAC footer field.
mluis 2:14a5d6ad92d5 112 * Mainly indicates the MIC field length
mluis 2:14a5d6ad92d5 113 */
mluis 2:14a5d6ad92d5 114 #define LORAMAC_MFR_LEN 4
mluis 2:14a5d6ad92d5 115
mluis 2:14a5d6ad92d5 116 /*!
mluis 2:14a5d6ad92d5 117 * Syncword for Private LoRa networks
mluis 2:14a5d6ad92d5 118 */
mluis 2:14a5d6ad92d5 119 #define LORA_MAC_PRIVATE_SYNCWORD 0x12
mluis 2:14a5d6ad92d5 120
mluis 2:14a5d6ad92d5 121 /*!
mluis 2:14a5d6ad92d5 122 * Syncword for Public LoRa networks
mluis 2:14a5d6ad92d5 123 */
mluis 2:14a5d6ad92d5 124 #define LORA_MAC_PUBLIC_SYNCWORD 0x34
mluis 2:14a5d6ad92d5 125
mluis 2:14a5d6ad92d5 126 /*!
mluis 2:14a5d6ad92d5 127 * LoRaMAC event flags
mluis 2:14a5d6ad92d5 128 */
mluis 2:14a5d6ad92d5 129 typedef union
mluis 2:14a5d6ad92d5 130 {
mluis 2:14a5d6ad92d5 131 uint8_t Value;
mluis 2:14a5d6ad92d5 132 struct
mluis 2:14a5d6ad92d5 133 {
mluis 2:14a5d6ad92d5 134 uint8_t Tx : 1;
mluis 2:14a5d6ad92d5 135 uint8_t Rx : 1;
mluis 2:14a5d6ad92d5 136 uint8_t RxData : 1;
mluis 2:14a5d6ad92d5 137 uint8_t Multicast : 1;
mluis 2:14a5d6ad92d5 138 uint8_t RxSlot : 2;
mluis 2:14a5d6ad92d5 139 uint8_t LinkCheck : 1;
mluis 2:14a5d6ad92d5 140 uint8_t JoinAccept : 1;
mluis 2:14a5d6ad92d5 141 }Bits;
mluis 2:14a5d6ad92d5 142 }LoRaMacEventFlags_t;
mluis 2:14a5d6ad92d5 143
mluis 2:14a5d6ad92d5 144 /*!
mluis 2:14a5d6ad92d5 145 * LoRaMAC event information
mluis 2:14a5d6ad92d5 146 */
mluis 2:14a5d6ad92d5 147 typedef struct
mluis 2:14a5d6ad92d5 148 {
mluis 2:14a5d6ad92d5 149 LoRaMacEventInfoStatus_t Status;
mluis 2:14a5d6ad92d5 150 bool TxAckReceived;
mluis 2:14a5d6ad92d5 151 uint8_t TxNbRetries;
mluis 2:14a5d6ad92d5 152 uint8_t TxDatarate;
mluis 2:14a5d6ad92d5 153 uint8_t RxPort;
mluis 2:14a5d6ad92d5 154 uint8_t *RxBuffer;
mluis 2:14a5d6ad92d5 155 uint8_t RxBufferSize;
mluis 2:14a5d6ad92d5 156 int16_t RxRssi;
mluis 2:14a5d6ad92d5 157 uint8_t RxSnr;
mluis 2:14a5d6ad92d5 158 uint16_t Energy;
mluis 2:14a5d6ad92d5 159 uint8_t DemodMargin;
mluis 2:14a5d6ad92d5 160 uint8_t NbGateways;
mluis 2:14a5d6ad92d5 161 }LoRaMacEventInfo_t;
mluis 2:14a5d6ad92d5 162
mluis 2:14a5d6ad92d5 163 /*!
mluis 2:14a5d6ad92d5 164 * LoRaMAC events structure
mluis 2:14a5d6ad92d5 165 * Used to notify upper layers of MAC events
mluis 2:14a5d6ad92d5 166 */
mluis 2:14a5d6ad92d5 167 typedef struct sLoRaMacCallbacks
mluis 2:14a5d6ad92d5 168 {
mluis 2:14a5d6ad92d5 169 /*!
mluis 2:14a5d6ad92d5 170 * MAC layer event callback prototype.
mluis 2:14a5d6ad92d5 171 *
mluis 2:14a5d6ad92d5 172 * \param [IN] flags Bit field indicating the MAC events occurred
mluis 2:14a5d6ad92d5 173 * \param [IN] info Details about MAC events occurred
mluis 2:14a5d6ad92d5 174 */
mluis 2:14a5d6ad92d5 175 void ( *MacEvent )( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info );
mluis 2:14a5d6ad92d5 176 /*!
mluis 2:14a5d6ad92d5 177 * Function callback to get the current battery level
mluis 2:14a5d6ad92d5 178 *
mluis 2:14a5d6ad92d5 179 * \retval batteryLevel Current battery level
mluis 2:14a5d6ad92d5 180 */
mluis 2:14a5d6ad92d5 181 uint8_t ( *GetBatteryLevel )( void );
mluis 2:14a5d6ad92d5 182 }LoRaMacCallbacks_t;
mluis 2:14a5d6ad92d5 183
mluis 2:14a5d6ad92d5 184 /*!
mluis 2:14a5d6ad92d5 185 * LoRaMAC layer initialization
mluis 2:14a5d6ad92d5 186 *
mluis 2:14a5d6ad92d5 187 * \param [IN] callbacks Pointer to a structure defining the LoRaMAC
mluis 2:14a5d6ad92d5 188 * callback functions.
mluis 2:14a5d6ad92d5 189 */
mluis 2:14a5d6ad92d5 190 void LoRaMacInit( LoRaMacCallbacks_t *callbacks );
mluis 2:14a5d6ad92d5 191
mluis 2:14a5d6ad92d5 192 /*!
mluis 2:14a5d6ad92d5 193 * Enables/Disables the ADR (Adaptive Data Rate)
mluis 2:14a5d6ad92d5 194 *
mluis 2:14a5d6ad92d5 195 * \param [IN] enable [true: ADR ON, false: ADR OFF]
mluis 2:14a5d6ad92d5 196 */
mluis 2:14a5d6ad92d5 197 void LoRaMacSetAdrOn( bool enable );
mluis 2:14a5d6ad92d5 198
mluis 2:14a5d6ad92d5 199 /*!
mluis 2:14a5d6ad92d5 200 * Initializes the network IDs. Device address,
mluis 2:14a5d6ad92d5 201 * network session AES128 key and application session AES128 key.
mluis 2:14a5d6ad92d5 202 *
mluis 2:14a5d6ad92d5 203 * \remark To be only used when Over-the-Air activation isn't used.
mluis 2:14a5d6ad92d5 204 *
mluis 2:14a5d6ad92d5 205 * \param [IN] netID 24 bits network identifier
mluis 2:14a5d6ad92d5 206 * ( provided by network operator )
mluis 2:14a5d6ad92d5 207 * \param [IN] devAddr 32 bits device address on the network
mluis 2:14a5d6ad92d5 208 * (must be unique to the network)
mluis 2:14a5d6ad92d5 209 * \param [IN] nwkSKey Pointer to the network session AES128 key array
mluis 2:14a5d6ad92d5 210 * ( 16 bytes )
mluis 2:14a5d6ad92d5 211 * \param [IN] appSKey Pointer to the application session AES128 key array
mluis 2:14a5d6ad92d5 212 * ( 16 bytes )
mluis 2:14a5d6ad92d5 213 */
mluis 2:14a5d6ad92d5 214 void LoRaMacInitNwkIds( uint32_t netID, uint32_t devAddr, uint8_t *nwkSKey, uint8_t *appSKey );
mluis 2:14a5d6ad92d5 215
mluis 2:14a5d6ad92d5 216 /*
mluis 2:14a5d6ad92d5 217 * Wrapper function which calls \ref LoRaMacMulticastChannelLink.
mluis 2:14a5d6ad92d5 218 */
mluis 2:14a5d6ad92d5 219 void LoRaMacMulticastChannelAdd( MulticastParams_t *channelParam );
mluis 2:14a5d6ad92d5 220
mluis 2:14a5d6ad92d5 221 /*
mluis 2:14a5d6ad92d5 222 * Wrapper function which calls \ref LoRaMacMulticastChannelUnlink.
mluis 2:14a5d6ad92d5 223 */
mluis 2:14a5d6ad92d5 224 void LoRaMacMulticastChannelRemove( MulticastParams_t *channelParam );
mluis 2:14a5d6ad92d5 225
mluis 2:14a5d6ad92d5 226 /*!
mluis 2:14a5d6ad92d5 227 * Initiates the Over-the-Air activation
mluis 2:14a5d6ad92d5 228 *
mluis 2:14a5d6ad92d5 229 * \param [IN] devEui Pointer to the device EUI array ( 8 bytes )
mluis 2:14a5d6ad92d5 230 * \param [IN] appEui Pointer to the application EUI array ( 8 bytes )
mluis 2:14a5d6ad92d5 231 * \param [IN] appKey Pointer to the application AES128 key array ( 16 bytes )
mluis 2:14a5d6ad92d5 232 *
mluis 2:14a5d6ad92d5 233 * \retval status [0: OK, 1: Tx error, 2: Already joined a network]
mluis 2:14a5d6ad92d5 234 */
mluis 2:14a5d6ad92d5 235 uint8_t LoRaMacJoinReq( uint8_t *devEui, uint8_t *appEui, uint8_t *appKey );
mluis 2:14a5d6ad92d5 236
mluis 2:14a5d6ad92d5 237 /*!
mluis 2:14a5d6ad92d5 238 * Sends a LinkCheckReq MAC command on the next uplink frame
mluis 2:14a5d6ad92d5 239 *
mluis 2:14a5d6ad92d5 240 * \retval status Function status [0: OK, 1: Busy]
mluis 2:14a5d6ad92d5 241 */
mluis 2:14a5d6ad92d5 242 uint8_t LoRaMacLinkCheckReq( void );
mluis 2:14a5d6ad92d5 243
mluis 2:14a5d6ad92d5 244 /*!
mluis 2:14a5d6ad92d5 245 * LoRaMAC layer send frame
mluis 2:14a5d6ad92d5 246 *
mluis 2:14a5d6ad92d5 247 * \param [IN] fPort MAC payload port (must be > 0)
mluis 2:14a5d6ad92d5 248 * \param [IN] fBuffer MAC data buffer to be sent
mluis 2:14a5d6ad92d5 249 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 250 *
mluis 2:14a5d6ad92d5 251 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 2:14a5d6ad92d5 252 * 3: Length or port error, 4: Unknown MAC command
mluis 2:14a5d6ad92d5 253 * 5: Unable to find a free channel
mluis 2:14a5d6ad92d5 254 * 6: Device switched off]
mluis 2:14a5d6ad92d5 255 */
mluis 2:14a5d6ad92d5 256 uint8_t LoRaMacSendFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 2:14a5d6ad92d5 257
mluis 2:14a5d6ad92d5 258 /*!
mluis 2:14a5d6ad92d5 259 * LoRaMAC layer send frame
mluis 2:14a5d6ad92d5 260 *
mluis 2:14a5d6ad92d5 261 * \param [IN] fPort MAC payload port (must be > 0)
mluis 2:14a5d6ad92d5 262 * \param [IN] fBuffer MAC data buffer to be sent
mluis 2:14a5d6ad92d5 263 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 264 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 265 * \param [IN] nbRetries Number of retries to receive the acknowledgement
mluis 2:14a5d6ad92d5 266 *
mluis 2:14a5d6ad92d5 267 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 2:14a5d6ad92d5 268 * 3: Length or port error, 4: Unknown MAC command
mluis 2:14a5d6ad92d5 269 * 5: Unable to find a free channel
mluis 2:14a5d6ad92d5 270 * 6: Device switched off]
mluis 2:14a5d6ad92d5 271 */
mluis 2:14a5d6ad92d5 272 uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries );
mluis 2:14a5d6ad92d5 273
mluis 2:14a5d6ad92d5 274 /*!
mluis 2:14a5d6ad92d5 275 * ============================================================================
mluis 2:14a5d6ad92d5 276 * = LoRaMac test functions =
mluis 2:14a5d6ad92d5 277 * ============================================================================
mluis 2:14a5d6ad92d5 278 */
mluis 2:14a5d6ad92d5 279
mluis 2:14a5d6ad92d5 280 /*!
mluis 2:14a5d6ad92d5 281 * LoRaMAC layer generic send frame
mluis 2:14a5d6ad92d5 282 *
mluis 2:14a5d6ad92d5 283 * \param [IN] macHdr MAC header field
mluis 2:14a5d6ad92d5 284 * \param [IN] fOpts MAC commands buffer
mluis 2:14a5d6ad92d5 285 * \param [IN] fPort MAC payload port
mluis 2:14a5d6ad92d5 286 * \param [IN] fBuffer MAC data buffer to be sent
mluis 2:14a5d6ad92d5 287 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 288 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 2:14a5d6ad92d5 289 * 3: Length or port error, 4: Unknown MAC command
mluis 2:14a5d6ad92d5 290 * 5: Unable to find a free channel
mluis 2:14a5d6ad92d5 291 * 6: Device switched off]
mluis 2:14a5d6ad92d5 292 */
mluis 2:14a5d6ad92d5 293 uint8_t LoRaMacSend( LoRaMacHeader_t *macHdr, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 2:14a5d6ad92d5 294
mluis 2:14a5d6ad92d5 295 /*!
mluis 2:14a5d6ad92d5 296 * LoRaMAC layer frame buffer initialization.
mluis 2:14a5d6ad92d5 297 *
mluis 2:14a5d6ad92d5 298 * \param [IN] channel Channel parameters
mluis 2:14a5d6ad92d5 299 * \param [IN] macHdr MAC header field
mluis 2:14a5d6ad92d5 300 * \param [IN] fCtrl MAC frame control field
mluis 2:14a5d6ad92d5 301 * \param [IN] fOpts MAC commands buffer
mluis 2:14a5d6ad92d5 302 * \param [IN] fPort MAC payload port
mluis 2:14a5d6ad92d5 303 * \param [IN] fBuffer MAC data buffer to be sent
mluis 2:14a5d6ad92d5 304 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 305 * \retval status [0: OK, 1: N/A, 2: No network joined,
mluis 2:14a5d6ad92d5 306 * 3: Length or port error, 4: Unknown MAC command]
mluis 2:14a5d6ad92d5 307 */
mluis 2:14a5d6ad92d5 308 uint8_t LoRaMacPrepareFrame( ChannelParams_t channel,LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 2:14a5d6ad92d5 309
mluis 2:14a5d6ad92d5 310 /*!
mluis 2:14a5d6ad92d5 311 * LoRaMAC layer prepared frame buffer transmission with channel specification
mluis 2:14a5d6ad92d5 312 *
mluis 2:14a5d6ad92d5 313 * \remark LoRaMacPrepareFrame must be called at least once before calling this
mluis 2:14a5d6ad92d5 314 * function.
mluis 2:14a5d6ad92d5 315 *
mluis 2:14a5d6ad92d5 316 * \param [IN] channel Channel parameters
mluis 2:14a5d6ad92d5 317 * \retval status [0: OK, 1: Busy]
mluis 2:14a5d6ad92d5 318 */
mluis 2:14a5d6ad92d5 319 uint8_t LoRaMacSendFrameOnChannel( ChannelParams_t channel );
mluis 2:14a5d6ad92d5 320
mluis 2:14a5d6ad92d5 321 /*!
mluis 2:14a5d6ad92d5 322 * LoRaMAC layer generic send frame with channel specification
mluis 2:14a5d6ad92d5 323 *
mluis 2:14a5d6ad92d5 324 * \param [IN] channel Channel parameters
mluis 2:14a5d6ad92d5 325 * \param [IN] macHdr MAC header field
mluis 2:14a5d6ad92d5 326 * \param [IN] fCtrl MAC frame control field
mluis 2:14a5d6ad92d5 327 * \param [IN] fOpts MAC commands buffer
mluis 2:14a5d6ad92d5 328 * \param [IN] fPort MAC payload port
mluis 2:14a5d6ad92d5 329 * \param [IN] fBuffer MAC data buffer to be sent
mluis 2:14a5d6ad92d5 330 * \param [IN] fBufferSize MAC data buffer size
mluis 2:14a5d6ad92d5 331 * \retval status [0: OK, 1: Busy, 2: No network joined,
mluis 2:14a5d6ad92d5 332 * 3: Length or port error, 4: Unknown MAC command]
mluis 2:14a5d6ad92d5 333 */
mluis 2:14a5d6ad92d5 334 uint8_t LoRaMacSendOnChannel( ChannelParams_t channel, LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
mluis 2:14a5d6ad92d5 335
mluis 2:14a5d6ad92d5 336 /*!
mluis 2:14a5d6ad92d5 337 * ============================================================================
mluis 2:14a5d6ad92d5 338 * = LoRaMac setup functions =
mluis 2:14a5d6ad92d5 339 * ============================================================================
mluis 2:14a5d6ad92d5 340 */
mluis 2:14a5d6ad92d5 341
mluis 2:14a5d6ad92d5 342 /*
mluis 2:14a5d6ad92d5 343 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 344 * set the LoRaWan device class.
mluis 2:14a5d6ad92d5 345 */
mluis 2:14a5d6ad92d5 346 void LoRaMacSetDeviceClass( DeviceClass_t deviceClass );
mluis 2:14a5d6ad92d5 347
mluis 2:14a5d6ad92d5 348 /*
mluis 2:14a5d6ad92d5 349 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 350 * set the network type to public or private.
mluis 2:14a5d6ad92d5 351 */
mluis 2:14a5d6ad92d5 352 void LoRaMacSetPublicNetwork( bool enable );
mluis 2:14a5d6ad92d5 353
mluis 2:14a5d6ad92d5 354 /*
mluis 2:14a5d6ad92d5 355 * Wrapper function which calls \ref LoRaMacChannelAdd.
mluis 2:14a5d6ad92d5 356 */
mluis 2:14a5d6ad92d5 357 void LoRaMacSetChannel( uint8_t id, ChannelParams_t params );
mluis 2:14a5d6ad92d5 358
mluis 2:14a5d6ad92d5 359 /*
mluis 2:14a5d6ad92d5 360 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 361 * set the receive window 2 channel.
mluis 2:14a5d6ad92d5 362 */
mluis 2:14a5d6ad92d5 363 void LoRaMacSetRx2Channel( Rx2ChannelParams_t param );
mluis 2:14a5d6ad92d5 364
mluis 2:14a5d6ad92d5 365 /*!
mluis 2:14a5d6ad92d5 366 * Sets channels tx output power
mluis 2:14a5d6ad92d5 367 *
mluis 2:14a5d6ad92d5 368 * \param [IN] txPower [TX_POWER_20_DBM, TX_POWER_14_DBM,
mluis 2:14a5d6ad92d5 369 TX_POWER_11_DBM, TX_POWER_08_DBM,
mluis 2:14a5d6ad92d5 370 TX_POWER_05_DBM, TX_POWER_02_DBM]
mluis 2:14a5d6ad92d5 371 */
mluis 2:14a5d6ad92d5 372 void LoRaMacSetChannelsTxPower( int8_t txPower );
mluis 2:14a5d6ad92d5 373
mluis 2:14a5d6ad92d5 374 /*!
mluis 2:14a5d6ad92d5 375 * Sets channels datarate
mluis 2:14a5d6ad92d5 376 *
mluis 2:14a5d6ad92d5 377 * \param [IN] datarate eu868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
mluis 2:14a5d6ad92d5 378 * us915 - [DR_0, DR_1, DR_2, DR_3, DR_4]
mluis 2:14a5d6ad92d5 379 */
mluis 2:14a5d6ad92d5 380 void LoRaMacSetChannelsDatarate( int8_t datarate );
mluis 2:14a5d6ad92d5 381
mluis 2:14a5d6ad92d5 382 /*
mluis 2:14a5d6ad92d5 383 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 384 * set the channels mask.
mluis 2:14a5d6ad92d5 385 */
mluis 2:14a5d6ad92d5 386 void LoRaMacSetChannelsMask( uint16_t *mask );
mluis 2:14a5d6ad92d5 387
mluis 2:14a5d6ad92d5 388 /*
mluis 2:14a5d6ad92d5 389 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 390 * set the number of repetitions on a channel.
mluis 2:14a5d6ad92d5 391 */
mluis 2:14a5d6ad92d5 392 void LoRaMacSetChannelsNbRep( uint8_t nbRep );
mluis 2:14a5d6ad92d5 393
mluis 2:14a5d6ad92d5 394 /*
mluis 2:14a5d6ad92d5 395 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 396 * set the maximum receive window duration in [us].
mluis 2:14a5d6ad92d5 397 */
mluis 2:14a5d6ad92d5 398 void LoRaMacSetMaxRxWindow( uint32_t delay );
mluis 2:14a5d6ad92d5 399
mluis 2:14a5d6ad92d5 400 /*
mluis 2:14a5d6ad92d5 401 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 402 * set the receive delay 1 in [us].
mluis 2:14a5d6ad92d5 403 */
mluis 2:14a5d6ad92d5 404 void LoRaMacSetReceiveDelay1( uint32_t delay );
mluis 2:14a5d6ad92d5 405
mluis 2:14a5d6ad92d5 406 /*
mluis 2:14a5d6ad92d5 407 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 408 * set the receive delay 2 in [us].
mluis 2:14a5d6ad92d5 409 */
mluis 2:14a5d6ad92d5 410 void LoRaMacSetReceiveDelay2( uint32_t delay );
mluis 2:14a5d6ad92d5 411
mluis 2:14a5d6ad92d5 412 /*
mluis 2:14a5d6ad92d5 413 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 414 * set the join accept delay 1 in [us].
mluis 2:14a5d6ad92d5 415 */
mluis 2:14a5d6ad92d5 416 void LoRaMacSetJoinAcceptDelay1( uint32_t delay );
mluis 2:14a5d6ad92d5 417
mluis 2:14a5d6ad92d5 418 /*
mluis 2:14a5d6ad92d5 419 * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
mluis 2:14a5d6ad92d5 420 * set the join accept delay 2 in [us].
mluis 2:14a5d6ad92d5 421 */
mluis 2:14a5d6ad92d5 422 void LoRaMacSetJoinAcceptDelay2( uint32_t delay );
mluis 2:14a5d6ad92d5 423
mluis 2:14a5d6ad92d5 424 /*
mluis 2:14a5d6ad92d5 425 * Wrapper function which calls \ref LoRaMacMibGetRequestConfirm to
mluis 2:14a5d6ad92d5 426 * get the up-link counter.
mluis 2:14a5d6ad92d5 427 */
mluis 2:14a5d6ad92d5 428 uint32_t LoRaMacGetUpLinkCounter( void );
mluis 2:14a5d6ad92d5 429
mluis 2:14a5d6ad92d5 430 /*
mluis 2:14a5d6ad92d5 431 * Wrapper function which calls \ref LoRaMacMibGetRequestConfirm to
mluis 2:14a5d6ad92d5 432 * get the down-link counter.
mluis 2:14a5d6ad92d5 433 */
mluis 2:14a5d6ad92d5 434 uint32_t LoRaMacGetDownLinkCounter( void );
mluis 2:14a5d6ad92d5 435
mluis 2:14a5d6ad92d5 436 /*
mluis 2:14a5d6ad92d5 437 * ============================================================================
mluis 2:14a5d6ad92d5 438 * = LoRaMac test functions =
mluis 2:14a5d6ad92d5 439 * ============================================================================
mluis 2:14a5d6ad92d5 440 */
mluis 2:14a5d6ad92d5 441
mluis 2:14a5d6ad92d5 442 /*!
mluis 2:14a5d6ad92d5 443 * Disables/Enables the duty cycle enforcement (EU868)
mluis 2:14a5d6ad92d5 444 *
mluis 2:14a5d6ad92d5 445 * \param [IN] enable - Enabled or disables the duty cycle
mluis 2:14a5d6ad92d5 446 */
mluis 2:14a5d6ad92d5 447 void LoRaMacTestSetDutyCycleOn( bool enable );
mluis 2:14a5d6ad92d5 448
mluis 2:14a5d6ad92d5 449 /*!
mluis 2:14a5d6ad92d5 450 * Disables/Enables the reception windows opening
mluis 2:14a5d6ad92d5 451 *
mluis 2:14a5d6ad92d5 452 * \param [IN] enable [true: enable, false: disable]
mluis 2:14a5d6ad92d5 453 */
mluis 2:14a5d6ad92d5 454 void LoRaMacTestRxWindowsOn( bool enable );
mluis 2:14a5d6ad92d5 455
mluis 2:14a5d6ad92d5 456 /*!
mluis 2:14a5d6ad92d5 457 * Enables the MIC field test
mluis 2:14a5d6ad92d5 458 *
mluis 2:14a5d6ad92d5 459 * \param [IN] upLinkCounter Fixed Tx packet counter value
mluis 2:14a5d6ad92d5 460 */
mluis 2:14a5d6ad92d5 461 void LoRaMacTestSetMic( uint16_t upLinkCounter );
mluis 2:14a5d6ad92d5 462
mluis 2:14a5d6ad92d5 463 #endif /* __LORAMAC_API_V3_H__ */