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