RadioLib Universal wireless communication library for Arduino

LoRaWAN.h
1 #if !defined(_RADIOLIB_LORAWAN_H) && !RADIOLIB_EXCLUDE_LORAWAN
2 #define _RADIOLIB_LORAWAN_H
3
4 #include "../../TypeDef.h"
5 #include "../PhysicalLayer/PhysicalLayer.h"
6 #include "../../utils/Cryptography.h"
7
8 // activation mode
9 #define RADIOLIB_LORAWAN_MODE_OTAA (0x07AA)
10 #define RADIOLIB_LORAWAN_MODE_ABP (0x0AB9)
11 #define RADIOLIB_LORAWAN_MODE_NONE (0x0000)
12
13 // operation mode
14 #define RADIOLIB_LORAWAN_CLASS_A (0x0A)
15 #define RADIOLIB_LORAWAN_CLASS_B (0x0B)
16 #define RADIOLIB_LORAWAN_CLASS_C (0x0C)
17
18 // preamble format
19 #define RADIOLIB_LORAWAN_LORA_SYNC_WORD (0x34)
20 #define RADIOLIB_LORAWAN_LORA_PREAMBLE_LEN (8)
21 #define RADIOLIB_LORAWAN_GFSK_SYNC_WORD (0xC194C1)
22 #define RADIOLIB_LORAWAN_GFSK_PREAMBLE_LEN (5)
23
24 // MAC header field encoding MSB LSB DESCRIPTION
25 #define RADIOLIB_LORAWAN_MHDR_MTYPE_JOIN_REQUEST (0x00 << 5) // 7 5 message type: join request
26 #define RADIOLIB_LORAWAN_MHDR_MTYPE_JOIN_ACCEPT (0x01 << 5) // 7 5 join accept
27 #define RADIOLIB_LORAWAN_MHDR_MTYPE_UNCONF_DATA_UP (0x02 << 5) // 7 5 unconfirmed data up
28 #define RADIOLIB_LORAWAN_MHDR_MTYPE_UNCONF_DATA_DOWN (0x03 << 5) // 7 5 unconfirmed data down
29 #define RADIOLIB_LORAWAN_MHDR_MTYPE_CONF_DATA_UP (0x04 << 5) // 7 5 confirmed data up
30 #define RADIOLIB_LORAWAN_MHDR_MTYPE_CONF_DATA_DOWN (0x05 << 5) // 7 5 confirmed data down
31 #define RADIOLIB_LORAWAN_MHDR_MTYPE_PROPRIETARY (0x07 << 5) // 7 5 proprietary
32 #define RADIOLIB_LORAWAN_MHDR_MTYPE_MASK (0x07 << 5) // 7 5 bitmask of all possible options
33 #define RADIOLIB_LORAWAN_MHDR_MAJOR_R1 (0x00 << 0) // 1 0 major version: LoRaWAN R1
34
35 // frame control field encoding
36 #define RADIOLIB_LORAWAN_FCTRL_ADR_ENABLED (0x01 << 7) // 7 7 adaptive data rate: enabled
37 #define RADIOLIB_LORAWAN_FCTRL_ADR_DISABLED (0x00 << 7) // 7 7 disabled
38 #define RADIOLIB_LORAWAN_FCTRL_ADR_ACK_REQ (0x01 << 6) // 6 6 adaptive data rate ACK request
39 #define RADIOLIB_LORAWAN_FCTRL_ACK (0x01 << 5) // 5 5 confirmed message acknowledge
40 #define RADIOLIB_LORAWAN_FCTRL_FRAME_PENDING (0x01 << 4) // 4 4 downlink frame is pending
41
42 // port field
43 #define RADIOLIB_LORAWAN_FPORT_MAC_COMMAND (0x00 << 0) // 7 0 payload contains MAC commands only
44 #define RADIOLIB_LORAWAN_FPORT_RESERVED (0xE0 << 0) // 7 0 reserved port values
45
46 // MAC commands - only those sent from end-device to gateway
47 #define RADIOLIB_LORAWAN_LINK_CHECK_REQ (0x02 << 0) // 7 0 MAC command: request to check connectivity to network
48 #define RADIOLIB_LORAWAN_LINK_ADR_ANS (0x03 << 0) // 7 0 answer to ADR change
49 #define RADIOLIB_LORAWAN_DUTY_CYCLE_ANS (0x04 << 0) // 7 0 answer to duty cycle change
50 #define RADIOLIB_LORAWAN_RX_PARAM_SETUP_ANS (0x05 << 0) // 7 0 answer to reception slot setup request
51 #define RADIOLIB_LORAWAN_DEV_STATUS_ANS (0x06 << 0) // 7 0 device status information
52 #define RADIOLIB_LORAWAN_NEW_CHANNEL_ANS (0x07 << 0) // 7 0 acknowledges change of a radio channel
53 #define RADIOLIB_LORAWAN_RX_TIMING_SETUP_ANS (0x08 << 0) // 7 0 acknowledges change of a reception slots timing
54
55 #define RADIOLIB_LORAWAN_NOPTS_LEN (8)
56
57 // data rate encoding
58 #define RADIOLIB_LORAWAN_DATA_RATE_FSK_50_K (0x01 << 7) // 7 7 FSK @ 50 kbps
59 #define RADIOLIB_LORAWAN_DATA_RATE_SF_12 (0x06 << 4) // 6 4 LoRa spreading factor: SF12
60 #define RADIOLIB_LORAWAN_DATA_RATE_SF_11 (0x05 << 4) // 6 4 SF11
61 #define RADIOLIB_LORAWAN_DATA_RATE_SF_10 (0x04 << 4) // 6 4 SF10
62 #define RADIOLIB_LORAWAN_DATA_RATE_SF_9 (0x03 << 4) // 6 4 SF9
63 #define RADIOLIB_LORAWAN_DATA_RATE_SF_8 (0x02 << 4) // 6 4 SF8
64 #define RADIOLIB_LORAWAN_DATA_RATE_SF_7 (0x01 << 4) // 6 4 SF7
65 #define RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ (0x00 << 2) // 3 2 LoRa bandwidth: 500 kHz
66 #define RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ (0x01 << 2) // 3 2 250 kHz
67 #define RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ (0x02 << 2) // 3 2 125 kHz
68 #define RADIOLIB_LORAWAN_DATA_RATE_BW_RESERVED (0x03 << 2) // 3 2 reserved value
69 #define RADIOLIB_LORAWAN_DATA_RATE_CR_4_5 (0x00 << 0) // 1 0 LoRa coding rate: 4/5
70 #define RADIOLIB_LORAWAN_DATA_RATE_CR_4_6 (0x01 << 0) // 1 0 4/6
71 #define RADIOLIB_LORAWAN_DATA_RATE_CR_4_7 (0x02 << 0) // 1 0 4/7
72 #define RADIOLIB_LORAWAN_DATA_RATE_CR_4_8 (0x03 << 0) // 1 0 4/8
73 #define RADIOLIB_LORAWAN_DATA_RATE_UNUSED (0xFF << 0) // 7 0 unused data rate
74
75 #define RADIOLIB_LORAWAN_CHANNEL_DIR_UPLINK (0x00 << 0)
76 #define RADIOLIB_LORAWAN_CHANNEL_DIR_DOWNLINK (0x01 << 0)
77 #define RADIOLIB_LORAWAN_CHANNEL_DIR_BOTH (0x02 << 0)
78 #define RADIOLIB_LORAWAN_CHANNEL_DIR_NONE (0x03 << 0)
79 #define RADIOLIB_LORAWAN_BAND_DYNAMIC (0)
80 #define RADIOLIB_LORAWAN_BAND_FIXED (1)
81 #define RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES (15)
82 #define RADIOLIB_LORAWAN_CHANNEL_INDEX_NONE (0xFF >> 0)
83
84 // recommended default settings
85 #define RADIOLIB_LORAWAN_RECEIVE_DELAY_1_MS (1000)
86 #define RADIOLIB_LORAWAN_RECEIVE_DELAY_2_MS ((RADIOLIB_LORAWAN_RECEIVE_DELAY_1_MS) + 1000)
87 #define RADIOLIB_LORAWAN_RX1_DR_OFFSET (0)
88 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_1_MS (5000)
89 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_2_MS (6000)
90 #define RADIOLIB_LORAWAN_MAX_FCNT_GAP (16384)
91 #define RADIOLIB_LORAWAN_ADR_ACK_LIMIT_EXP (0x06)
92 #define RADIOLIB_LORAWAN_ADR_ACK_DELAY_EXP (0x05)
93 #define RADIOLIB_LORAWAN_RETRANSMIT_TIMEOUT_MIN_MS (1000)
94 #define RADIOLIB_LORAWAN_RETRANSMIT_TIMEOUT_MAX_MS (3000)
95 #define RADIOLIB_LORAWAN_POWER_STEP_SIZE_DBM (-2)
96 #define RADIOLIB_LORAWAN_REJOIN_MAX_COUNT_N (10) // send rejoin request 16384 uplinks
97 #define RADIOLIB_LORAWAN_REJOIN_MAX_TIME_N (15) // once every year, not actually implemented
98
99 // join request message layout
100 #define RADIOLIB_LORAWAN_JOIN_REQUEST_LEN (23)
101 #define RADIOLIB_LORAWAN_JOIN_REQUEST_JOIN_EUI_POS (1)
102 #define RADIOLIB_LORAWAN_JOIN_REQUEST_DEV_EUI_POS (9)
103 #define RADIOLIB_LORAWAN_JOIN_REQUEST_DEV_NONCE_POS (17)
104 #define RADIOLIB_LORAWAN_JOIN_REQUEST_TYPE (0xFF)
105 #define RADIOLIB_LORAWAN_JOIN_REQUEST_TYPE_0 (0x00)
106 #define RADIOLIB_LORAWAN_JOIN_REQUEST_TYPE_1 (0x01)
107 #define RADIOLIB_LORAWAN_JOIN_REQUEST_TYPE_2 (0x02)
108
109 // join accept message layout
110 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_MAX_LEN (33)
111 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_JOIN_NONCE_POS (1)
112 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_HOME_NET_ID_POS (4)
113 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_DEV_ADDR_POS (7)
114 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_JOIN_EUI_POS (4)
115 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_DL_SETTINGS_POS (11)
116 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_RX_DELAY_POS (12)
117 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_DEV_NONCE_POS (12)
118 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_CFLIST_POS (13)
119 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_CFLIST_LEN (16)
120 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_CFLIST_TYPE_POS (RADIOLIB_LORAWAN_JOIN_ACCEPT_CFLIST_POS + RADIOLIB_LORAWAN_JOIN_ACCEPT_CFLIST_LEN - 1)
121
122 // join accept message variables
123 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_R_1_0 (0x00 << 7) // 7 7 LoRaWAN revision: 1.0
124 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_R_1_1 (0x01 << 7) // 7 7 1.1
125 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_F_NWK_S_INT_KEY (0x01)
126 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_APP_S_KEY (0x02)
127 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_S_NWK_S_INT_KEY (0x03)
128 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_NWK_S_ENC_KEY (0x04)
129 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_JS_ENC_KEY (0x05)
130 #define RADIOLIB_LORAWAN_JOIN_ACCEPT_JS_INT_KEY (0x06)
131
132 // frame header layout
133 #define RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS (16)
134 #define RADIOLIB_LORAWAN_FHDR_DEV_ADDR_POS (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 1)
135 #define RADIOLIB_LORAWAN_FHDR_FCTRL_POS (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 5)
136 #define RADIOLIB_LORAWAN_FHDR_FCNT_POS (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 6)
137 #define RADIOLIB_LORAWAN_FHDR_FOPTS_POS (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 8)
138 #define RADIOLIB_LORAWAN_FHDR_FOPTS_LEN_MASK (0x0F)
139 #define RADIOLIB_LORAWAN_FHDR_FOPTS_MAX_LEN (15)
140 #define RADIOLIB_LORAWAN_FHDR_FPORT_POS(FOPTS) (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 8 + (FOPTS))
141 #define RADIOLIB_LORAWAN_FRAME_PAYLOAD_POS(FOPTS) (RADIOLIB_LORAWAN_FHDR_LEN_START_OFFS + 9 + (FOPTS))
142 #define RADIOLIB_LORAWAN_FRAME_LEN(PAYLOAD, FOPTS) (16 + 13 + (PAYLOAD) + (FOPTS))
143
144 // payload encryption/MIC blocks common layout
145 #define RADIOLIB_LORAWAN_BLOCK_MAGIC_POS (0)
146 #define RADIOLIB_LORAWAN_BLOCK_CONF_FCNT_POS (1)
147 #define RADIOLIB_LORAWAN_BLOCK_DIR_POS (5)
148 #define RADIOLIB_LORAWAN_BLOCK_DEV_ADDR_POS (6)
149 #define RADIOLIB_LORAWAN_BLOCK_FCNT_POS (10)
150
151 // payload encryption block layout
152 #define RADIOLIB_LORAWAN_ENC_BLOCK_MAGIC (0x01)
153 #define RADIOLIB_LORAWAN_ENC_BLOCK_COUNTER_ID_POS (4)
154 #define RADIOLIB_LORAWAN_ENC_BLOCK_COUNTER_POS (15)
155
156 // payload MIC blocks layout
157 #define RADIOLIB_LORAWAN_MIC_BLOCK_MAGIC (0x49)
158 #define RADIOLIB_LORAWAN_MIC_BLOCK_LEN_POS (15)
159 #define RADIOLIB_LORAWAN_MIC_DATA_RATE_POS (3)
160 #define RADIOLIB_LORAWAN_MIC_CH_INDEX_POS (4)
161
162 // MAC commands
163 #define RADIOLIB_LORAWAN_NUM_MAC_COMMANDS (16)
164
165 #define RADIOLIB_LORAWAN_MAC_RESET (0x01)
166 #define RADIOLIB_LORAWAN_MAC_LINK_CHECK (0x02)
167 #define RADIOLIB_LORAWAN_MAC_LINK_ADR (0x03)
168 #define RADIOLIB_LORAWAN_MAC_DUTY_CYCLE (0x04)
169 #define RADIOLIB_LORAWAN_MAC_RX_PARAM_SETUP (0x05)
170 #define RADIOLIB_LORAWAN_MAC_DEV_STATUS (0x06)
171 #define RADIOLIB_LORAWAN_MAC_NEW_CHANNEL (0x07)
172 #define RADIOLIB_LORAWAN_MAC_RX_TIMING_SETUP (0x08)
173 #define RADIOLIB_LORAWAN_MAC_TX_PARAM_SETUP (0x09)
174 #define RADIOLIB_LORAWAN_MAC_DL_CHANNEL (0x0A)
175 #define RADIOLIB_LORAWAN_MAC_REKEY (0x0B)
176 #define RADIOLIB_LORAWAN_MAC_ADR_PARAM_SETUP (0x0C)
177 #define RADIOLIB_LORAWAN_MAC_DEVICE_TIME (0x0D)
178 #define RADIOLIB_LORAWAN_MAC_FORCE_REJOIN (0x0E)
179 #define RADIOLIB_LORAWAN_MAC_REJOIN_PARAM_SETUP (0x0F)
180 #define RADIOLIB_LORAWAN_MAC_PROPRIETARY (0x80)
181
182 // maximum allowed dwell time on bands that implement dwell time limitations
183 #define RADIOLIB_LORAWAN_DWELL_TIME (400)
184
185 // unused LoRaWAN version
186 #define RADIOLIB_LORAWAN_VERSION_NONE (0xFF)
187
188 // unused frame counter value
189 #define RADIOLIB_LORAWAN_FCNT_NONE (0xFFFFFFFF)
190
191 // the length of internal MAC command queue - hopefully this is enough for most use cases
192 #define RADIOLIB_LORAWAN_MAC_COMMAND_QUEUE_SIZE (9)
193
194 // the maximum number of simultaneously available channels
195 #define RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS (16)
196
197 // maximum MAC command sizes
198 #define RADIOLIB_LORAWAN_MAX_MAC_COMMAND_LEN_DOWN (5)
199 #define RADIOLIB_LORAWAN_MAX_MAC_COMMAND_LEN_UP (2)
200 #define RADIOLIB_LORAWAN_MAX_NUM_ADR_COMMANDS (8)
201
206 struct LoRaWANMacSpec_t {
208 const uint8_t cid;
209
211 const uint8_t lenDn;
212
214 const uint8_t lenUp;
215
217 const bool user;
218 };
219
220 const LoRaWANMacSpec_t MacTable[RADIOLIB_LORAWAN_NUM_MAC_COMMANDS + 1] = {
221 { 0x00, 0, 0, false }, // not an actual MAC command, exists for index offsetting
222 { RADIOLIB_LORAWAN_MAC_RESET, 1, 1, false },
223 { RADIOLIB_LORAWAN_MAC_LINK_CHECK, 2, 0, true },
224 { RADIOLIB_LORAWAN_MAC_LINK_ADR, 4, 1, false },
225 { RADIOLIB_LORAWAN_MAC_DUTY_CYCLE, 1, 0, false },
226 { RADIOLIB_LORAWAN_MAC_RX_PARAM_SETUP, 4, 1, false },
227 { RADIOLIB_LORAWAN_MAC_DEV_STATUS, 0, 2, false },
228 { RADIOLIB_LORAWAN_MAC_NEW_CHANNEL, 5, 1, false },
229 { RADIOLIB_LORAWAN_MAC_RX_TIMING_SETUP, 1, 0, false },
230 { RADIOLIB_LORAWAN_MAC_TX_PARAM_SETUP, 1, 0, false },
231 { RADIOLIB_LORAWAN_MAC_DL_CHANNEL, 4, 1, false },
232 { RADIOLIB_LORAWAN_MAC_REKEY, 1, 1, false },
233 { RADIOLIB_LORAWAN_MAC_ADR_PARAM_SETUP, 1, 0, false },
234 { RADIOLIB_LORAWAN_MAC_DEVICE_TIME, 5, 0, true },
235 { RADIOLIB_LORAWAN_MAC_FORCE_REJOIN, 2, 0, false },
236 { RADIOLIB_LORAWAN_MAC_REJOIN_PARAM_SETUP, 1, 1, false },
237 { RADIOLIB_LORAWAN_MAC_PROPRIETARY, 5, 0, true }
238 };
239
240 #define RADIOLIB_LORAWAN_NONCES_VERSION_VAL (0x0001)
241
242 enum LoRaWANSchemeBase_t {
243 RADIOLIB_LORAWAN_NONCES_VERSION = 0x00, // 2 bytes
244 RADIOLIB_LORAWAN_NONCES_MODE = 0x02, // 2 bytes
245 RADIOLIB_LORAWAN_NONCES_CLASS = 0x04, // 1 byte
246 RADIOLIB_LORAWAN_NONCES_PLAN = 0x05, // 1 byte
247 RADIOLIB_LORAWAN_NONCES_CHECKSUM = 0x06, // 2 bytes
248 RADIOLIB_LORAWAN_NONCES_DEV_NONCE = 0x08, // 2 bytes
249 RADIOLIB_LORAWAN_NONCES_JOIN_NONCE = 0x0A, // 3 bytes
250 RADIOLIB_LORAWAN_NONCES_ACTIVE = 0x0D, // 1 byte
251 RADIOLIB_LORAWAN_NONCES_SIGNATURE = 0x0E, // 2 bytes
252 RADIOLIB_LORAWAN_NONCES_BUF_SIZE = 0x10 // = 16 bytes
253 };
254
255 enum LoRaWANSchemeSession_t {
256 RADIOLIB_LORAWAN_SESSION_NWK_SENC_KEY = 0x00, // 16 bytes
257 RADIOLIB_LORAWAN_SESSION_APP_SKEY = 0x10, // 16 bytes
258 RADIOLIB_LORAWAN_SESSION_FNWK_SINT_KEY = 0x20, // 16 bytes
259 RADIOLIB_LORAWAN_SESSION_SNWK_SINT_KEY = 0x30, // 16 bytes
260 RADIOLIB_LORAWAN_SESSION_DEV_ADDR = 0x40, // 4 bytes
261 RADIOLIB_LORAWAN_SESSION_NONCES_SIGNATURE = 0x44, // 2 bytes
262 RADIOLIB_LORAWAN_SESSION_A_FCNT_DOWN = 0x46, // 4 bytes
263 RADIOLIB_LORAWAN_SESSION_CONF_FCNT_UP = 0x4A, // 4 bytes
264 RADIOLIB_LORAWAN_SESSION_CONF_FCNT_DOWN = 0x4E, // 4 bytes
265 RADIOLIB_LORAWAN_SESSION_RJ_COUNT0 = 0x52, // 2 bytes
266 RADIOLIB_LORAWAN_SESSION_RJ_COUNT1 = 0x54, // 2 bytes
267 RADIOLIB_LORAWAN_SESSION_HOMENET_ID = 0x56, // 4 bytes
268 RADIOLIB_LORAWAN_SESSION_VERSION = 0x5A, // 1 byte
269 RADIOLIB_LORAWAN_SESSION_DUTY_CYCLE = 0x5B, // 1 byte
270 RADIOLIB_LORAWAN_SESSION_RX_PARAM_SETUP = 0x5C, // 4 bytes
271 RADIOLIB_LORAWAN_SESSION_RX_TIMING_SETUP = 0x60, // 1 byte
272 RADIOLIB_LORAWAN_SESSION_TX_PARAM_SETUP = 0x61, // 1 byte
273 RADIOLIB_LORAWAN_SESSION_ADR_PARAM_SETUP = 0x62, // 1 byte
274 RADIOLIB_LORAWAN_SESSION_REJOIN_PARAM_SETUP = 0x63, // 1 byte
275 RADIOLIB_LORAWAN_SESSION_BEACON_FREQ = 0x64, // 3 bytes
276 RADIOLIB_LORAWAN_SESSION_PING_SLOT_CHANNEL = 0x67, // 4 bytes
277 RADIOLIB_LORAWAN_SESSION_PERIODICITY = 0x6B, // 1 byte
278 RADIOLIB_LORAWAN_SESSION_LAST_TIME = 0x6C, // 4 bytes
279 RADIOLIB_LORAWAN_SESSION_UL_CHANNELS = 0x70, // 16*8 bytes
280 RADIOLIB_LORAWAN_SESSION_DL_CHANNELS = 0xF0, // 16*4 bytes
281 RADIOLIB_LORAWAN_SESSION_MAC_QUEUE_UL = 0x0130, // 9*8+2 bytes
282 RADIOLIB_LORAWAN_SESSION_N_FCNT_DOWN = 0x017A, // 4 bytes
283 RADIOLIB_LORAWAN_SESSION_ADR_FCNT = 0x017E, // 4 bytes
284 RADIOLIB_LORAWAN_SESSION_LINK_ADR = 0x0182, // 4 bytes
285 RADIOLIB_LORAWAN_SESSION_FCNT_UP = 0x0186, // 4 bytes
286 RADIOLIB_LORAWAN_SESSION_SIGNATURE = 0x018A, // 2 bytes
287 RADIOLIB_LORAWAN_SESSION_BUF_SIZE = 0x018C // 396 bytes
288 };
289
295 struct LoRaWANChannel_t {
297 bool enabled;
298
300 uint8_t idx;
301
303 float freq;
304
306 uint8_t drMin;
307
309 uint8_t drMax;
310 };
311
312 // alias for unused channel
313 #define RADIOLIB_LORAWAN_CHANNEL_NONE { .enabled = false, .idx = RADIOLIB_LORAWAN_CHANNEL_INDEX_NONE, .freq = 0, .drMin = 0, .drMax = 0 }
314
320 struct LoRaWANChannelSpan_t {
322 uint8_t numChannels;
323
325 float freqStart;
326
328 float freqStep;
329
331 uint8_t drMin;
332
334 uint8_t drMax;
335
337 uint8_t joinRequestDataRate;
338 };
339
340 // alias for unused channel span
341 #define RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE { .numChannels = 0, .freqStart = 0, .freqStep = 0, .drMin = 0, .drMax = 0, .joinRequestDataRate = RADIOLIB_LORAWAN_DATA_RATE_UNUSED }
342
347 struct LoRaWANBand_t {
349 uint8_t bandNum;
350
352 uint8_t bandType;
353
355 uint8_t payloadLenMax[RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES];
356
358 int8_t powerMax;
359
361 int8_t powerNumSteps;
362
364 uint32_t dutyCycle;
365
367 uint32_t dwellTimeUp;
368
370 uint32_t dwellTimeDn;
371
373 LoRaWANChannel_t txFreqs[3];
374
376 LoRaWANChannel_t txJoinReq[3];
377
379 uint8_t numTxSpans;
380
382 LoRaWANChannelSpan_t txSpans[2];
383
385 LoRaWANChannelSpan_t rx1Span;
386
388 uint8_t rx1DataRateBase;
389
391 LoRaWANChannel_t rx2;
392
394 uint8_t dataRates[RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES];
395 };
396
397 // supported bands
398 extern const LoRaWANBand_t EU868;
399 extern const LoRaWANBand_t US915;
400 extern const LoRaWANBand_t CN780;
401 extern const LoRaWANBand_t EU433;
402 extern const LoRaWANBand_t AU915;
403 extern const LoRaWANBand_t CN500;
404 extern const LoRaWANBand_t AS923;
405 extern const LoRaWANBand_t KR920;
406 extern const LoRaWANBand_t IN865;
407
412 enum LoRaWANBandNum_t {
413 BandEU868,
414 BandUS915,
415 BandCN780,
416 BandEU433,
417 BandAU915,
418 BandCN500,
419 BandAS923,
420 BandKR920,
421 BandIN865,
422 BandLast
423 };
424
425 // provide easy access to the number of currently supported bands
426 #define RADIOLIB_LORAWAN_NUM_SUPPORTED_BANDS (BandLast - BandEU868)
427
428 // array of currently supported bands
429 extern const LoRaWANBand_t* LoRaWANBands[];
430
435 struct LoRaWANMacCommand_t {
437 uint8_t cid;
438
440 uint8_t payload[5];
441
443 uint8_t len;
444
446 uint8_t repeat;
447 };
452 struct LoRaWANMacCommandQueue_t {
454 uint8_t numCommands;
455
457 uint8_t len;
458
460 LoRaWANMacCommand_t commands[RADIOLIB_LORAWAN_MAC_COMMAND_QUEUE_SIZE];
461 };
462
467 struct LoRaWANEvent_t {
469 uint8_t dir;
470
472 bool confirmed;
473
476 bool confirming;
477
479 uint8_t datarate;
480
482 float freq;
483
485 int16_t power;
486
488 uint32_t fcnt;
489
491 uint8_t port;
492 };
493
498 class LoRaWANNode {
499 public:
500
502 uint8_t rx1DrOffset = 0;
503
505 LoRaWANChannel_t rx2;
506
513 LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band, uint8_t subBand = 0);
514
519 void wipe();
520
525 uint8_t* getBufferNonces();
526
532 int16_t setBufferNonces(uint8_t* persistentBuffer);
533
538 uint8_t* getBufferSession();
539
545 int16_t setBufferSession(uint8_t* persistentBuffer);
546
551 int16_t restore(uint16_t checkSum, uint16_t lwMode, uint8_t lwClass, uint8_t freqPlan);
552
564 int16_t beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKey, uint8_t* appKey, bool force = false, uint8_t joinDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
565
578 int16_t beginABP(uint32_t addr, uint8_t* nwkSKey, uint8_t* appSKey, uint8_t* fNwkSIntKey = NULL, uint8_t* sNwkSIntKey = NULL, bool force = false, uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
579
581 bool isJoined();
582
587 int16_t saveSession();
588
596 bool sendMacCommandReq(uint8_t cid);
597
598 #if defined(RADIOLIB_BUILD_ARDUINO)
608 int16_t uplink(String& str, uint8_t port, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
609 #endif
610
620 int16_t uplink(const char* str, uint8_t port, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
621
632 int16_t uplink(uint8_t* data, size_t len, uint8_t port, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
633
634 #if defined(RADIOLIB_BUILD_ARDUINO)
642 int16_t downlink(String& str, LoRaWANEvent_t* event = NULL);
643 #endif
644
653 int16_t downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event = NULL);
654
661 int16_t downlink(LoRaWANEvent_t* event = NULL);
662
663 #if defined(RADIOLIB_BUILD_ARDUINO)
676 int16_t sendReceive(String& strUp, uint8_t port, String& strDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
677 #endif
678
692 int16_t sendReceive(const char* strUp, uint8_t port, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
693
708 int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t port, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
709
722 int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t port = 1, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
723
729 void setDeviceStatus(uint8_t battLevel);
730
735 uint32_t getFcntUp();
736
741 uint32_t getNFcntDown();
742
747 uint32_t getAFcntDown();
748
754 void resetFcntDown();
755
761 int16_t setDatarate(uint8_t drUp);
762
767 void setADR(bool enable = true);
768
775 void setDutyCycle(bool enable = true, uint32_t msPerHour = 0);
776
784 uint32_t dutyCycleInterval(uint32_t msPerHour, uint32_t airtime);
785
787 uint32_t timeUntilUplink();
788
795 void setDwellTime(bool enable, uint32_t msPerUplink = 0);
796
802 uint8_t maxPayloadDwellTime();
803
809 int16_t setTxPower(int8_t txPower);
810
819 int16_t getMacLinkCheckAns(uint8_t* margin, uint8_t* gwCnt);
820
830 int16_t getMacDeviceTimeAns(uint32_t* gpsEpoch, uint8_t* fraction, bool returnUnix = true);
831
836 uint64_t getDevAddr();
837
838 #if !RADIOLIB_GODMODE
839 private:
840 #endif
841 PhysicalLayer* phyLayer = NULL;
842 const LoRaWANBand_t* band = NULL;
843
844 static int16_t checkBufferCommon(uint8_t *buffer, uint16_t size);
845
846 void beginCommon(uint8_t initialDr);
847
848 // a buffer that holds all LW base parameters that should persist at all times!
849 uint8_t bufferNonces[RADIOLIB_LORAWAN_NONCES_BUF_SIZE] = { 0 };
850
851 // a buffer that holds all LW session parameters that preferably persist, but can be afforded to get lost
852 uint8_t bufferSession[RADIOLIB_LORAWAN_SESSION_BUF_SIZE] = { 0 };
853
854 LoRaWANMacCommandQueue_t commandsUp = {
855 .numCommands = 0,
856 .len = 0,
857 .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
858 };
859 LoRaWANMacCommandQueue_t commandsDown = {
860 .numCommands = 0,
861 .len = 0,
862 .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
863 };
864
865 // the following is either provided by the network server (OTAA)
866 // or directly entered by the user (ABP)
867 uint32_t devAddr = 0;
868 uint8_t appSKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
869 uint8_t fNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
870 uint8_t sNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
871 uint8_t nwkSEncKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
872 uint8_t jSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
873
874 // device-specific parameters, persistent through sessions
875 uint16_t devNonce = 0;
876 uint32_t joinNonce = 0;
877
878 // session-specific parameters
879 uint32_t homeNetId = 0;
880 uint8_t adrLimitExp = RADIOLIB_LORAWAN_ADR_ACK_LIMIT_EXP;
881 uint8_t adrDelayExp = RADIOLIB_LORAWAN_ADR_ACK_DELAY_EXP;
882 uint8_t nbTrans = 1; // Number of allowed frame retransmissions
883 uint8_t txPowerCur = 0;
884 uint8_t txPowerMax = 0;
885 uint32_t fcntUp = 0;
886 uint32_t aFcntDown = 0;
887 uint32_t nFcntDown = 0;
888 uint32_t confFcntUp = RADIOLIB_LORAWAN_FCNT_NONE;
889 uint32_t confFcntDown = RADIOLIB_LORAWAN_FCNT_NONE;
890 uint32_t adrFcnt = 0;
891
892 // whether the current configured channel is in FSK mode
893 bool FSK = false;
894
895 // flag that shows whether the device is joined and there is an ongoing session (none, ABP or OTAA)
896 uint16_t activeMode = RADIOLIB_LORAWAN_MODE_NONE;
897
898 // ADR is enabled by default
899 bool adrEnabled = true;
900
901 // duty cycle is set upon initialization and activated in regions that impose this
902 bool dutyCycleEnabled = false;
903 uint32_t dutyCycle = 0;
904
905 // dwell time is set upon initialization and activated in regions that impose this
906 bool dwellTimeEnabledUp = false;
907 uint16_t dwellTimeUp = 0;
908 bool dwellTimeEnabledDn = false;
909 uint16_t dwellTimeDn = 0;
910
911 // enable/disable CSMA for LoRaWAN
912 bool enableCSMA;
913
914 // number of backoff slots to be decremented after DIFS phase. 0 to disable BO.
915 // A random BO avoids collisions in the case where two or more nodes start the CSMA
916 // process at the same time.
917 uint8_t backoffMax;
918
919 // number of CADs to estimate a clear CH
920 uint8_t difsSlots;
921
922 // available channel frequencies from list passed during OTA activation
923 LoRaWANChannel_t availableChannels[2][RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS];
924
925 // currently configured channels for TX and RX1
926 LoRaWANChannel_t currentChannels[2] = { RADIOLIB_LORAWAN_CHANNEL_NONE, RADIOLIB_LORAWAN_CHANNEL_NONE };
927
928 // currently configured datarates for TX and RX1
929 uint8_t dataRates[2] = { RADIOLIB_LORAWAN_DATA_RATE_UNUSED, RADIOLIB_LORAWAN_DATA_RATE_UNUSED };
930
931 // LoRaWAN revision (1.0 vs 1.1)
932 uint8_t rev = 0;
933
934 // Time on Air of last uplink
935 uint32_t lastToA = 0;
936
937 // timestamp to measure the RX1/2 delay (from uplink end)
938 uint32_t rxDelayStart = 0;
939
940 // timestamp when the Rx1/2 windows were closed (timeout or uplink received)
941 uint32_t rxDelayEnd = 0;
942
943 // delays between the uplink and RX1/2 windows
944 uint32_t rxDelays[2] = { RADIOLIB_LORAWAN_RECEIVE_DELAY_1_MS, RADIOLIB_LORAWAN_RECEIVE_DELAY_2_MS };
945
946 // device status - battery level
947 uint8_t battLevel = 0xFF;
948
949 // indicates whether an uplink has MAC commands as payload
950 bool isMACPayload = false;
951
952 // save the selected sub-band in case this must be restored in ADR control
953 uint8_t subBand = 0;
954
955 // wait for, open and listen during Rx1 and Rx2 windows; only performs listening
956 int16_t downlinkCommon();
957
958 // method to generate message integrity code
959 uint32_t generateMIC(uint8_t* msg, size_t len, uint8_t* key);
960
961 // method to verify message integrity code
962 // it assumes that the MIC is the last 4 bytes of the message
963 bool verifyMIC(uint8_t* msg, size_t len, uint8_t* key);
964
965 // configure the common physical layer properties (preamble, sync word etc.)
966 // channels must be configured separately by setupChannelsDyn()!
967 int16_t setPhyProperties();
968
969 // setup uplink/downlink channel data rates and frequencies
970 // for dynamic channels, there is a small set of predefined channels
971 // in case of JoinRequest, add some optional extra frequencies
972 int16_t setupChannelsDyn(bool joinRequest = false);
973
974 // setup uplink/downlink channel data rates and frequencies
975 // for fixed bands, we only allow one sub-band at a time to be selected
976 int16_t setupChannelsFix(uint8_t subBand);
977
978 // a join-accept can piggy-back a set of channels or channel masks
979 int16_t processCFList(uint8_t* cfList);
980
981 // select a set of random TX/RX channels for up- and downlink
982 int16_t selectChannels();
983
984 // find the first usable data rate for the given band
985 int16_t findDataRate(uint8_t dr, DataRate_t* dataRate);
986
987 // configure channel based on cached data rate ID and frequency
988 int16_t configureChannel(uint8_t dir);
989
990 // restore all available channels from persistent storage
991 int16_t restoreChannels();
992
993 // push MAC command to queue, done by copy
994 int16_t pushMacCommand(LoRaWANMacCommand_t* cmd, LoRaWANMacCommandQueue_t* queue);
995
996 // delete a specific MAC command from queue, indicated by the command ID
997 // if a payload pointer is supplied, this returns the payload of the MAC command
998 int16_t deleteMacCommand(uint8_t cid, LoRaWANMacCommandQueue_t* queue, uint8_t* payload = NULL);
999
1000 // execute mac command, return the number of processed bytes for sequential processing
1001 bool execMacCommand(LoRaWANMacCommand_t* cmd);
1002
1003 // apply a channel mask to a set of readily defined channels (dynamic bands only)
1004 bool applyChannelMaskDyn(uint8_t chMaskCntl, uint16_t chMask);
1005
1006 // define or delete channels from a fixed set of channels (fixed bands only)
1007 bool applyChannelMaskFix(uint8_t chMaskCntl, uint16_t chMask);
1008
1009 // get the payload length for a specific MAC command
1010 uint8_t getMacPayloadLength(uint8_t cid);
1011
1018 void setCSMA(uint8_t backoffMax, uint8_t difsSlots, bool enableCSMA = false);
1019
1020 // Performs CSMA as per LoRa Alliance Technical Recommendation 13 (TR-013).
1021 void performCSMA();
1022
1023 // perform a single CAD operation for the under SF/CH combination. Returns either busy or otherwise.
1024 bool performCAD();
1025
1026 // function to encrypt and decrypt payloads
1027 void processAES(uint8_t* in, size_t len, uint8_t* key, uint8_t* out, uint32_t fcnt, uint8_t dir, uint8_t ctrId, bool counter);
1028
1029 // 16-bit checksum method that takes a uint8_t array of even length and calculates the checksum
1030 static uint16_t checkSum16(uint8_t *key, uint16_t keyLen);
1031
1032 // network-to-host conversion method - takes data from network packet and converts it to the host endians
1033 template<typename T>
1034 static T ntoh(uint8_t* buff, size_t size = 0);
1035
1036 // host-to-network conversion method - takes data from host variable and and converts it to network packet endians
1037 template<typename T>
1038 static void hton(uint8_t* buff, T val, size_t size = 0);
1039 };
1040
1041 #endif
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:498
LoRaWANNode::uplink
int16_t uplink(const char *str, uint8_t port, bool isConfirmed=false, LoRaWANEvent_t *event=NULL)
Send a message to the server.
Definition: LoRaWAN.cpp:860
LoRaWANNode::setBufferNonces
int16_t setBufferNonces(uint8_t *persistentBuffer)
Fill the internal buffer that holds the LW base parameters with a supplied buffer.
Definition: LoRaWAN.cpp:56
LoRaWANNode::setDatarate
int16_t setDatarate(uint8_t drUp)
Set uplink datarate. This should not be used when ADR is enabled.
Definition: LoRaWAN.cpp:1904
LoRaWANNode::sendReceive
int16_t sendReceive(const char *strUp, uint8_t port, uint8_t *dataDown, size_t *lenDown, bool isConfirmed=false, LoRaWANEvent_t *eventUp=NULL, LoRaWANEvent_t *eventDown=NULL)
Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.
Definition: LoRaWAN.cpp:1613
LoRaWANNode::beginOTAA
int16_t beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t *nwkKey, uint8_t *appKey, bool force=false, uint8_t joinDr=RADIOLIB_LORAWAN_DATA_RATE_UNUSED)
Join network by performing over-the-air activation. By this procedure, the device will perform an exc...
Definition: LoRaWAN.cpp:455
LoRaWANNode::maxPayloadDwellTime
uint8_t maxPayloadDwellTime()
Returns the maximum payload given the currently present dwell time limits. WARNING: the addition of M...
Definition: LoRaWAN.cpp:1984
LoRaWANNode::setDwellTime
void setDwellTime(bool enable, uint32_t msPerUplink=0)
Toggle adherence to dwellTime limits to on or off.
Definition: LoRaWAN.cpp:1975
LoRaWANNode::getFcntUp
uint32_t getFcntUp()
Returns the last uplink's frame counter; also 0 if no uplink occured yet.
Definition: LoRaWAN.cpp:1638
LoRaWANNode::setDeviceStatus
void setDeviceStatus(uint8_t battLevel)
Set device status.
Definition: LoRaWAN.cpp:1633
LoRaWANNode::beginABP
int16_t beginABP(uint32_t addr, uint8_t *nwkSKey, uint8_t *appSKey, uint8_t *fNwkSIntKey=NULL, uint8_t *sNwkSIntKey=NULL, bool force=false, uint8_t initialDr=RADIOLIB_LORAWAN_DATA_RATE_UNUSED)
Join network by performing activation by personalization. In this procedure, all necessary configurat...
Definition: LoRaWAN.cpp:735
LoRaWANNode::dutyCycleInterval
uint32_t dutyCycleInterval(uint32_t msPerHour, uint32_t airtime)
Calculate the minimum interval to adhere to a certain dutyCycle. This interval is based on the ToA of...
Definition: LoRaWAN.cpp:1956
LoRaWANNode::resetFcntDown
void resetFcntDown()
Reset the downlink frame counters (application and network) This is unsafe and can possibly allow rep...
Definition: LoRaWAN.cpp:1653
LoRaWANNode::restore
int16_t restore(uint16_t checkSum, uint16_t lwMode, uint8_t lwClass, uint8_t freqPlan)
Restore session by loading information from persistent storage.
Definition: LoRaWAN.cpp:129
LoRaWANNode::sendMacCommandReq
bool sendMacCommandReq(uint8_t cid)
Add a MAC command to the uplink queue. Only LinkCheck and DeviceTime are available to the user....
Definition: LoRaWAN.cpp:2094
LoRaWANNode::saveSession
int16_t saveSession()
Save the current state of the session to the session buffer.
Definition: LoRaWAN.cpp:820
LoRaWANNode::getBufferNonces
uint8_t * getBufferNonces()
Returns the pointer to the internal buffer that holds the LW base parameters.
Definition: LoRaWAN.cpp:52
LoRaWANNode::getNFcntDown
uint32_t getNFcntDown()
Returns the last network downlink's frame counter; also 0 if no network downlink occured yet.
Definition: LoRaWAN.cpp:1645
LoRaWANNode::getAFcntDown
uint32_t getAFcntDown()
Returns the last application downlink's frame counter; also 0 if no application downlink occured yet.
Definition: LoRaWAN.cpp:1649
LoRaWANNode::getBufferSession
uint8_t * getBufferSession()
Returns the pointer to the internal buffer that holds the LW session parameters.
Definition: LoRaWAN.cpp:74
LoRaWANNode::wipe
void wipe()
Wipe internal persistent parameters. This will reset all counters and saved variables,...
Definition: LoRaWAN.cpp:47
LoRaWANNode::setTxPower
int16_t setTxPower(int8_t txPower)
Configure TX power of the radio module.
Definition: LoRaWAN.cpp:2004
LoRaWANNode::getMacDeviceTimeAns
int16_t getMacDeviceTimeAns(uint32_t *gpsEpoch, uint8_t *fraction, bool returnUnix=true)
Returns the network time after requesting a DeviceTime MAC command. Returns 'true' if a network respo...
Definition: LoRaWAN.cpp:2780
LoRaWANNode::getDevAddr
uint64_t getDevAddr()
Returns the DevAddr of the device, regardless of OTAA or ABP mode.
Definition: LoRaWAN.cpp:2797
LoRaWANNode::downlink
int16_t downlink(uint8_t *data, size_t *len, LoRaWANEvent_t *event=NULL)
Wait for downlink from the server in either RX1 or RX2 window.
Definition: LoRaWAN.cpp:1287
LoRaWANNode::setBufferSession
int16_t setBufferSession(uint8_t *persistentBuffer)
Fill the internal buffer that holds the LW session parameters with a supplied buffer.
Definition: LoRaWAN.cpp:81
LoRaWANNode::LoRaWANNode
LoRaWANNode(PhysicalLayer *phy, const LoRaWANBand_t *band, uint8_t subBand=0)
Default constructor.
Definition: LoRaWAN.cpp:30
LoRaWANNode::setDutyCycle
void setDutyCycle(bool enable=true, uint32_t msPerHour=0)
Toggle adherence to dutyCycle limits to on or off.
Definition: LoRaWAN.cpp:1945
LoRaWANNode::timeUntilUplink
uint32_t timeUntilUplink()
Returns time in milliseconds until next uplink is available under dutyCycle limits.
Definition: LoRaWAN.cpp:1966
LoRaWANNode::rx1DrOffset
uint8_t rx1DrOffset
Offset between TX and RX1 (such that RX1 has equal or lower DR)
Definition: LoRaWAN.h:502
LoRaWANNode::getMacLinkCheckAns
int16_t getMacLinkCheckAns(uint8_t *margin, uint8_t *gwCnt)
Returns the quality of connectivity after requesting a LinkCheck MAC command. Returns 'true' if a net...
Definition: LoRaWAN.cpp:2769
LoRaWANNode::setADR
void setADR(bool enable=true)
Toggle ADR to on or off.
Definition: LoRaWAN.cpp:1941
LoRaWANNode::rx2
LoRaWANChannel_t rx2
RX2 channel properties - may be changed by MAC command.
Definition: LoRaWAN.h:505
LoRaWANNode::isJoined
bool isJoined()
Whether there is an ongoing session active.
Definition: LoRaWAN.cpp:816
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:54
LoRaWANBand_t
Structure to save information about LoRaWAN band.
Definition: LoRaWAN.h:347
LoRaWANBand_t::dwellTimeUp
uint32_t dwellTimeUp
Maximum dwell time per uplink message in milliseconds.
Definition: LoRaWAN.h:367
LoRaWANBand_t::dwellTimeDn
uint32_t dwellTimeDn
Maximum dwell time per downlink message in milliseconds.
Definition: LoRaWAN.h:370
LoRaWANBand_t::powerMax
int8_t powerMax
Maximum allowed output power in this band in dBm.
Definition: LoRaWAN.h:358
LoRaWANBand_t::dataRates
uint8_t dataRates[RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES]
The corresponding datarates, bandwidths and coding rates for DR index.
Definition: LoRaWAN.h:394
LoRaWANBand_t::payloadLenMax
uint8_t payloadLenMax[RADIOLIB_LORAWAN_CHANNEL_NUM_DATARATES]
Array of allowed maximum payload lengths for each data rate.
Definition: LoRaWAN.h:355
LoRaWANBand_t::txFreqs
LoRaWANChannel_t txFreqs[3]
A set of default uplink (TX) channels for frequency-type bands.
Definition: LoRaWAN.h:373
LoRaWANBand_t::txJoinReq
LoRaWANChannel_t txJoinReq[3]
A set of possible extra channels for the Join-Request message for frequency-type bands.
Definition: LoRaWAN.h:376
LoRaWANBand_t::powerNumSteps
int8_t powerNumSteps
Number of power steps in this band.
Definition: LoRaWAN.h:361
LoRaWANBand_t::txSpans
LoRaWANChannelSpan_t txSpans[2]
Default uplink (TX) channel spans for mask-type bands, including Join-Request parameters.
Definition: LoRaWAN.h:382
LoRaWANBand_t::rx1DataRateBase
uint8_t rx1DataRateBase
The base downlink data rate. Used to calculate data rate changes for adaptive data rate.
Definition: LoRaWAN.h:388
LoRaWANBand_t::bandNum
uint8_t bandNum
Identier for this band.
Definition: LoRaWAN.h:349
LoRaWANBand_t::bandType
uint8_t bandType
Whether the channels are fixed per specification, or dynamically allocated through the network (plus ...
Definition: LoRaWAN.h:352
LoRaWANBand_t::rx2
LoRaWANChannel_t rx2
Backup channel for downlink (RX2) window.
Definition: LoRaWAN.h:391
LoRaWANBand_t::numTxSpans
uint8_t numTxSpans
The number of TX channel spans for mask-type bands.
Definition: LoRaWAN.h:379
LoRaWANBand_t::rx1Span
LoRaWANChannelSpan_t rx1Span
Default downlink (RX1) channel span for mask-type bands.
Definition: LoRaWAN.h:385
LoRaWANBand_t::dutyCycle
uint32_t dutyCycle
Number of milliseconds per hour of allowed Time-on-Air.
Definition: LoRaWAN.h:364
LoRaWANBandNum_t
IDs of all currently supported bands.
LoRaWANChannel_t
Structure to save information about LoRaWAN channels. To save space, adjacent channels are saved in "...
Definition: LoRaWAN.h:295
LoRaWANChannel_t::freq
float freq
The channel frequency.
Definition: LoRaWAN.h:303
LoRaWANChannel_t::idx
uint8_t idx
The channel number, as specified by defaults or the network.
Definition: LoRaWAN.h:300
LoRaWANChannel_t::drMin
uint8_t drMin
Minimum allowed datarate for this channel.
Definition: LoRaWAN.h:306
LoRaWANChannel_t::enabled
bool enabled
Whether this channel is enabled (can be used) or is disabled.
Definition: LoRaWAN.h:297
LoRaWANChannel_t::drMax
uint8_t drMax
Maximum allowed datarate for this channel (inclusive)
Definition: LoRaWAN.h:309
LoRaWANChannelSpan_t
Structure to save information about LoRaWAN channels. To save space, adjacent channels are saved in "...
Definition: LoRaWAN.h:320
LoRaWANChannelSpan_t::joinRequestDataRate
uint8_t joinRequestDataRate
Allowed data rates for a join request message.
Definition: LoRaWAN.h:337
LoRaWANChannelSpan_t::freqStart
float freqStart
Center frequency of the first channel in span.
Definition: LoRaWAN.h:325
LoRaWANChannelSpan_t::numChannels
uint8_t numChannels
Total number of channels in the span.
Definition: LoRaWAN.h:322
LoRaWANChannelSpan_t::drMax
uint8_t drMax
Maximum allowed datarate for all channels in this span (inclusive)
Definition: LoRaWAN.h:334
LoRaWANChannelSpan_t::freqStep
float freqStep
Frequency step between adjacent channels.
Definition: LoRaWAN.h:328
LoRaWANChannelSpan_t::drMin
uint8_t drMin
Minimum allowed datarate for all channels in this span.
Definition: LoRaWAN.h:331
LoRaWANEvent_t
Structure to save extra information about uplink/downlink event.
Definition: LoRaWAN.h:467
LoRaWANEvent_t::freq
float freq
Frequency in MHz.
Definition: LoRaWAN.h:482
LoRaWANEvent_t::confirmed
bool confirmed
Whether the event is confirmed or not (e.g., confirmed uplink sent by user application)
Definition: LoRaWAN.h:472
LoRaWANEvent_t::power
int16_t power
Transmit power in dBm for uplink, or RSSI for downlink.
Definition: LoRaWAN.h:485
LoRaWANEvent_t::confirming
bool confirming
Whether the event is confirming a previous request (e.g., server downlink reply to confirmed uplink s...
Definition: LoRaWAN.h:476
LoRaWANEvent_t::datarate
uint8_t datarate
Datarate.
Definition: LoRaWAN.h:479
LoRaWANEvent_t::dir
uint8_t dir
Event direction, one of RADIOLIB_LORAWAN_CHANNEL_DIR_*.
Definition: LoRaWAN.h:469
LoRaWANEvent_t::fcnt
uint32_t fcnt
The appropriate frame counter - for different events, different frame counters will be reported!
Definition: LoRaWAN.h:488
LoRaWANEvent_t::port
uint8_t port
Port number.
Definition: LoRaWAN.h:491
LoRaWANMacCommand_t
Structure to save information about MAC command.
Definition: LoRaWAN.h:435
LoRaWANMacCommand_t::len
uint8_t len
Length of the payload.
Definition: LoRaWAN.h:443
LoRaWANMacCommand_t::cid
uint8_t cid
The command ID.
Definition: LoRaWAN.h:437
LoRaWANMacCommand_t::repeat
uint8_t repeat
Repetition counter (the command will be uplinked repeat + 1 times)
Definition: LoRaWAN.h:446
LoRaWANMacCommand_t::payload
uint8_t payload[5]
Payload buffer (5 bytes is the longest possible)
Definition: LoRaWAN.h:440
LoRaWANMacCommandQueue_t
Structure to hold information about a queue of MAC commands.
Definition: LoRaWAN.h:452
LoRaWANMacCommandQueue_t::commands
LoRaWANMacCommand_t commands[RADIOLIB_LORAWAN_MAC_COMMAND_QUEUE_SIZE]
MAC command buffer.
Definition: LoRaWAN.h:460
LoRaWANMacCommandQueue_t::numCommands
uint8_t numCommands
Number of commands in the queue.
Definition: LoRaWAN.h:454
LoRaWANMacCommandQueue_t::len
uint8_t len
Total length of the queue.
Definition: LoRaWAN.h:457
LoRaWANMacSpec_t
MAC command specification structure.
Definition: LoRaWAN.h:206
LoRaWANMacSpec_t::cid
const uint8_t cid
Command ID.
Definition: LoRaWAN.h:208
LoRaWANMacSpec_t::lenDn
const uint8_t lenDn
Uplink message length.
Definition: LoRaWAN.h:211
LoRaWANMacSpec_t::lenUp
const uint8_t lenUp
Downlink message length.
Definition: LoRaWAN.h:214
LoRaWANMacSpec_t::user
const bool user
Whether this MAC command can be issued by the user or not.
Definition: LoRaWAN.h:217
DataRate_t
Common data rate structure.
Definition: PhysicalLayer.h:38