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