1 /*!
2  * \file      LoRaMacTypes.h
3  *
4  * \brief     LoRa MAC layer internal types definition. Please do not include in application sources.
5  *
6  * \copyright Revised BSD License, see section \ref LICENSE.
7  *
8  * \code
9  *                ______                              _
10  *               / _____)             _              | |
11  *              ( (____  _____ ____ _| |_ _____  ____| |__
12  *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
13  *               _____) ) ____| | | || |_| ____( (___| | | |
14  *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  *              (C)2013 Semtech
16  *
17  *               ___ _____ _   ___ _  _____ ___  ___  ___ ___
18  *              / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
19  *              \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
20  *              |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
21  *              embedded.connectivity.solutions===============
22  *
23  * \endcode
24  *
25  * \author    Miguel Luis ( Semtech )
26  *
27  * \author    Daniel Jaeckle ( STACKFORCE )
28  *
29  * \author    Johannes Bruder ( STACKFORCE )
30  *
31  * addtogroup LORAMAC
32  * \{
33  *
34  */
35 #ifndef __LORAMAC_TYPES_H__
36 #define __LORAMAC_TYPES_H__
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #include <stdint.h>
44 #include <stdbool.h>
45 #include "timer.h"
46 #include "systime.h"
47 
48 /*!
49  * Start value for unicast keys enumeration
50  */
51 #define LORAMAC_CRYPTO_UNICAST_KEYS                 0
52 
53 /*!
54  * Start value for multicast keys enumeration
55  */
56 #define LORAMAC_CRYPTO_MULTICAST_KEYS               127
57 
58 /*!
59  * Maximum number of multicast context
60  */
61 #define LORAMAC_MAX_MC_CTX                          4
62 
63 /*!
64  * Region       | SF
65  * ------------ | :-----:
66  * AS923        | SF12 - BW125
67  * AU915        | SF10 - BW125
68  * CN470        | SF12 - BW125
69  * CN779        | SF12 - BW125
70  * EU433        | SF12 - BW125
71  * EU868        | SF12 - BW125
72  * IN865        | SF12 - BW125
73  * KR920        | SF12 - BW125
74  * US915        | SF10 - BW125
75  * RU864        | SF12 - BW125
76  */
77 #define DR_0                                        0
78 
79 /*!
80  * Region       | SF
81  * ------------ | :-----:
82  * AS923        | SF11 - BW125
83  * AU915        | SF9  - BW125
84  * CN470        | SF11 - BW125
85  * CN779        | SF11 - BW125
86  * EU433        | SF11 - BW125
87  * EU868        | SF11 - BW125
88  * IN865        | SF11 - BW125
89  * KR920        | SF11 - BW125
90  * US915        | SF9  - BW125
91  * RU864        | SF11 - BW125
92  */
93 #define DR_1                                        1
94 
95 /*!
96  * Region       | SF
97  * ------------ | :-----:
98  * AS923        | SF10 - BW125
99  * AU915        | SF8  - BW125
100  * CN470        | SF10 - BW125
101  * CN779        | SF10 - BW125
102  * EU433        | SF10 - BW125
103  * EU868        | SF10 - BW125
104  * IN865        | SF10 - BW125
105  * KR920        | SF10 - BW125
106  * US915        | SF8  - BW125
107  * RU864        | SF10 - BW125
108  */
109 #define DR_2                                        2
110 
111 /*!
112  * Region       | SF
113  * ------------ | :-----:
114  * AS923        | SF9  - BW125
115  * AU915        | SF7  - BW125
116  * CN470        | SF9  - BW125
117  * CN779        | SF9  - BW125
118  * EU433        | SF9  - BW125
119  * EU868        | SF9  - BW125
120  * IN865        | SF9  - BW125
121  * KR920        | SF9  - BW125
122  * US915        | SF7  - BW125
123  * RU864        | SF9  - BW125
124  */
125 #define DR_3                                        3
126 
127 /*!
128  * Region       | SF
129  * ------------ | :-----:
130  * AS923        | SF8  - BW125
131  * AU915        | SF8  - BW500
132  * CN470        | SF8  - BW125
133  * CN779        | SF8  - BW125
134  * EU433        | SF8  - BW125
135  * EU868        | SF8  - BW125
136  * IN865        | SF8  - BW125
137  * KR920        | SF8  - BW125
138  * US915        | SF8  - BW500
139  * RU864        | SF8  - BW125
140  */
141 #define DR_4                                        4
142 
143 /*!
144  * Region       | SF
145  * ------------ | :-----:
146  * AS923        | SF7  - BW125
147  * AU915        | RFU
148  * CN470        | SF7  - BW125
149  * CN779        | SF7  - BW125
150  * EU433        | SF7  - BW125
151  * EU868        | SF7  - BW125
152  * IN865        | SF7  - BW125
153  * KR920        | SF7  - BW125
154  * US915        | RFU
155  * RU864        | SF7  - BW125
156  */
157 #define DR_5                                        5
158 
159 /*!
160  * Region       | SF
161  * ------------ | :-----:
162  * AS923        | SF7  - BW250
163  * AU915        | RFU
164  * CN470        | SF12 - BW125
165  * CN779        | SF7  - BW250
166  * EU433        | SF7  - BW250
167  * EU868        | SF7  - BW250
168  * IN865        | SF7  - BW250
169  * KR920        | RFU
170  * US915        | RFU
171  * RU864        | SF7  - BW250
172  */
173 #define DR_6                                        6
174 
175 /*!
176  * Region       | SF
177  * ------------ | :-----:
178  * AS923        | FSK
179  * AU915        | RFU
180  * CN470        | SF12 - BW125
181  * CN779        | FSK
182  * EU433        | FSK
183  * EU868        | FSK
184  * IN865        | FSK
185  * KR920        | RFU
186  * US915        | RFU
187  * RU864        | FSK
188  */
189 #define DR_7                                        7
190 
191 /*!
192  * Region       | SF
193  * ------------ | :-----:
194  * AS923        | RFU
195  * AU915        | SF12 - BW500
196  * CN470        | RFU
197  * CN779        | RFU
198  * EU433        | RFU
199  * EU868        | RFU
200  * IN865        | RFU
201  * KR920        | RFU
202  * US915        | SF12 - BW500
203  * RU864        | RFU
204  */
205 #define DR_8                                        8
206 
207 /*!
208  * Region       | SF
209  * ------------ | :-----:
210  * AS923        | RFU
211  * AU915        | SF11 - BW500
212  * CN470        | RFU
213  * CN779        | RFU
214  * EU433        | RFU
215  * EU868        | RFU
216  * IN865        | RFU
217  * KR920        | RFU
218  * US915        | SF11 - BW500
219  * RU864        | RFU
220  */
221 #define DR_9                                        9
222 
223 /*!
224  * Region       | SF
225  * ------------ | :-----:
226  * AS923        | RFU
227  * AU915        | SF10 - BW500
228  * CN470        | RFU
229  * CN779        | RFU
230  * EU433        | RFU
231  * EU868        | RFU
232  * IN865        | RFU
233  * KR920        | RFU
234  * US915        | SF10 - BW500
235  * RU864        | RFU
236  */
237 #define DR_10                                       10
238 
239 /*!
240  * Region       | SF
241  * ------------ | :-----:
242  * AS923        | RFU
243  * AU915        | SF9  - BW500
244  * CN470        | RFU
245  * CN779        | RFU
246  * EU433        | RFU
247  * EU868        | RFU
248  * IN865        | RFU
249  * KR920        | RFU
250  * US915        | SF9  - BW500
251  * RU864        | RFU
252  */
253 #define DR_11                                       11
254 
255 /*!
256  * Region       | SF
257  * ------------ | :-----:
258  * AS923        | RFU
259  * AU915        | SF8  - BW500
260  * CN470        | RFU
261  * CN779        | RFU
262  * EU433        | RFU
263  * EU868        | RFU
264  * IN865        | RFU
265  * KR920        | RFU
266  * US915        | SF8  - BW500
267  * RU864        | RFU
268  */
269 #define DR_12                                       12
270 
271 /*!
272  * Region       | SF
273  * ------------ | :-----:
274  * AS923        | RFU
275  * AU915        | SF7  - BW500
276  * CN470        | RFU
277  * CN779        | RFU
278  * EU433        | RFU
279  * EU868        | RFU
280  * IN865        | RFU
281  * KR920        | RFU
282  * US915        | SF7  - BW500
283  * RU864        | RFU
284  */
285 #define DR_13                                       13
286 
287 /*!
288  * Region       | SF
289  * ------------ | :-----:
290  * AS923        | RFU
291  * AU915        | RFU
292  * CN470        | RFU
293  * CN779        | RFU
294  * EU433        | RFU
295  * EU868        | RFU
296  * IN865        | RFU
297  * KR920        | RFU
298  * US915        | RFU
299  * RU864        | RFU
300  */
301 #define DR_14                                       14
302 
303 /*!
304  * Region       | SF
305  * ------------ | :-----:
306  * AS923        | RFU
307  * AU915        | RFU
308  * CN470        | RFU
309  * CN779        | RFU
310  * EU433        | RFU
311  * EU868        | RFU
312  * IN865        | RFU
313  * KR920        | RFU
314  * US915        | RFU
315  * RU864        | RFU
316  */
317 #define DR_15                                       15
318 
319 
320 
321 /*!
322  * Region       | dBM
323  * ------------ | :-----:
324  * AS923        | Max EIRP
325  * AU915        | Max EIRP
326  * CN470        | Max EIRP
327  * CN779        | Max EIRP
328  * EU433        | Max EIRP
329  * EU868        | Max EIRP
330  * IN865        | Max EIRP
331  * KR920        | Max EIRP
332  * US915        | Max ERP
333  * RU864        | Max EIRP
334  */
335 #define TX_POWER_0                                  0
336 
337 /*!
338  * Region       | dBM
339  * ------------ | :-----:
340  * AS923        | Max EIRP - 2
341  * AU915        | Max EIRP - 2
342  * CN470        | Max EIRP - 2
343  * CN779        | Max EIRP - 2
344  * EU433        | Max EIRP - 2
345  * EU868        | Max EIRP - 2
346  * IN865        | Max EIRP - 2
347  * KR920        | Max EIRP - 2
348  * US915        | Max ERP - 2
349  * RU864        | Max EIRP - 2
350  */
351 #define TX_POWER_1                                  1
352 
353 /*!
354  * Region       | dBM
355  * ------------ | :-----:
356  * AS923        | Max EIRP - 4
357  * AU915        | Max EIRP - 4
358  * CN470        | Max EIRP - 4
359  * CN779        | Max EIRP - 4
360  * EU433        | Max EIRP - 4
361  * EU868        | Max EIRP - 4
362  * IN865        | Max EIRP - 4
363  * KR920        | Max EIRP - 4
364  * US915        | Max ERP - 4
365  * RU864        | Max EIRP - 4
366  */
367 #define TX_POWER_2                                  2
368 
369 /*!
370  * Region       | dBM
371  * ------------ | :-----:
372  * AS923        | Max EIRP - 6
373  * AU915        | Max EIRP - 6
374  * CN470        | Max EIRP - 6
375  * CN779        | Max EIRP - 6
376  * EU433        | Max EIRP - 6
377  * EU868        | Max EIRP - 6
378  * IN865        | Max EIRP - 6
379  * KR920        | Max EIRP - 6
380  * US915        | Max ERP - 6
381  * RU864        | Max EIRP - 6
382  */
383 #define TX_POWER_3                                  3
384 
385 /*!
386  * Region       | dBM
387  * ------------ | :-----:
388  * AS923        | Max EIRP - 8
389  * AU915        | Max EIRP - 8
390  * CN470        | Max EIRP - 8
391  * CN779        | Max EIRP - 8
392  * EU433        | Max EIRP - 8
393  * EU868        | Max EIRP - 8
394  * IN865        | Max EIRP - 8
395  * KR920        | Max EIRP - 8
396  * US915        | Max ERP - 8
397  * RU864        | Max EIRP - 8
398  */
399 #define TX_POWER_4                                  4
400 
401 /*!
402  * Region       | dBM
403  * ------------ | :-----:
404  * AS923        | Max EIRP - 10
405  * AU915        | Max EIRP - 10
406  * CN470        | Max EIRP - 10
407  * CN779        | Max EIRP - 10
408  * EU433        | Max EIRP - 10
409  * EU868        | Max EIRP - 10
410  * IN865        | Max EIRP - 10
411  * KR920        | Max EIRP - 10
412  * US915        | Max ERP - 10
413  * RU864        | Max EIRP - 10
414  */
415 #define TX_POWER_5                                  5
416 
417 /*!
418  * Region       | dBM
419  * ------------ | :-----:
420  * AS923        | Max EIRP - 12
421  * AU915        | Max EIRP - 12
422  * CN470        | Max EIRP - 12
423  * CN779        | -
424  * EU433        | -
425  * EU868        | Max EIRP - 12
426  * IN865        | Max EIRP - 12
427  * KR920        | Max EIRP - 12
428  * US915        | Max ERP - 12
429  * RU864        | Max EIRP - 12
430  */
431 #define TX_POWER_6                                  6
432 
433 /*!
434  * Region       | dBM
435  * ------------ | :-----:
436  * AS923        | Max EIRP - 14
437  * AU915        | Max EIRP - 14
438  * CN470        | Max EIRP - 14
439  * CN779        | -
440  * EU433        | -
441  * EU868        | Max EIRP - 14
442  * IN865        | Max EIRP - 14
443  * KR920        | Max EIRP - 14
444  * US915        | Max ERP - 14
445  * RU864        | Max EIRP - 14
446  */
447 #define TX_POWER_7                                  7
448 
449 /*!
450  * Region       | dBM
451  * ------------ | :-----:
452  * AS923        | -
453  * AU915        | Max EIRP - 16
454  * CN470        | -
455  * CN779        | -
456  * EU433        | -
457  * EU868        | -
458  * IN865        | Max EIRP - 16
459  * KR920        | -
460  * US915        | Max ERP - 16
461  * RU864        | -
462  */
463 #define TX_POWER_8                                  8
464 
465 /*!
466  * Region       | dBM
467  * ------------ | :-----:
468  * AS923        | -
469  * AU915        | Max EIRP - 18
470  * CN470        | -
471  * CN779        | -
472  * EU433        | -
473  * EU868        | -
474  * IN865        | Max EIRP - 18
475  * KR920        | -
476  * US915        | Max ERP - 18
477  * RU864        | -
478  */
479 #define TX_POWER_9                                  9
480 
481 /*!
482  * Region       | dBM
483  * ------------ | :-----:
484  * AS923        | -
485  * AU915        | Max EIRP - 20
486  * CN470        | -
487  * CN779        | -
488  * EU433        | -
489  * EU868        | -
490  * IN865        | Max EIRP - 20
491  * KR920        | -
492  * US915        | Max ERP - 20
493  * RU864        | -
494  */
495 #define TX_POWER_10                                 10
496 
497 /*!
498  * Region       | dBM
499  * ------------ | :-----:
500  * AS923        | -
501  * AU915        | Max EIRP - 22
502  * CN470        | -
503  * CN779        | -
504  * EU433        | -
505  * EU868        | -
506  * IN865        | -
507  * KR920        | -
508  * US915        | Max ERP - 22
509  * RU864        | -
510  */
511 #define TX_POWER_11                                 11
512 
513 /*!
514  * Region       | dBM
515  * ------------ | :-----:
516  * AS923        | -
517  * AU915        | Max EIRP - 24
518  * CN470        | -
519  * CN779        | -
520  * EU433        | -
521  * EU868        | -
522  * IN865        | -
523  * KR920        | -
524  * US915        | Max ERP - 24
525  * RU864        | -
526  */
527 #define TX_POWER_12                                 12
528 
529 /*!
530  * Region       | dBM
531  * ------------ | :-----:
532  * AS923        | -
533  * AU915        | Max EIRP - 26
534  * CN470        | -
535  * CN779        | -
536  * EU433        | -
537  * EU868        | -
538  * IN865        | -
539  * KR920        | -
540  * US915        | Max ERP - 26
541  * RU864        | -
542  */
543 #define TX_POWER_13                                 13
544 
545 /*!
546  * Region       | dBM
547  * ------------ | :-----:
548  * AS923        | -
549  * AU915        | Max EIRP - 28
550  * CN470        | -
551  * CN779        | -
552  * EU433        | -
553  * EU868        | -
554  * IN865        | -
555  * KR920        | -
556  * US915        | Max ERP - 28
557  * RU864        | -
558  */
559 #define TX_POWER_14                                 14
560 
561 /*!
562  * RFU
563  */
564 #define TX_POWER_15                                 15
565 
566 /*!
567  * LoRaWAN devices classes definition
568  *
569  * LoRaWAN Specification V1.0.2, chapter 2.1
570  */
571 typedef enum DeviceClass_e
572 {
573     /*!
574      * LoRaWAN device class A
575      *
576      * LoRaWAN Specification V1.0.2, chapter 3
577      */
578     CLASS_A = 0x00,
579     /*!
580      * LoRaWAN device class B
581      *
582      * LoRaWAN Specification V1.0.2, chapter 8
583      */
584     CLASS_B = 0x01,
585     /*!
586      * LoRaWAN device class C
587      *
588      * LoRaWAN Specification V1.0.2, chapter 17
589      */
590     CLASS_C = 0x02,
591 }DeviceClass_t;
592 
593 /*!
594  * LoRaWAN Frame type enumeration to differ between the possible data up/down frame configurations.
595  *
596  * Note: The naming is implementation specific since there is no definition
597  *       in the LoRaWAN specification included.
598  */
599 typedef enum eFType
600 {
601     /*!
602      * Frame type A
603      *
604      * FOptsLen > 0, Fopt present, FPort > 0, FRMPayload present
605      */
606     FRAME_TYPE_A,
607     /*!
608      * Frame type B
609      *
610      * FOptsLen > 0, Fopt present, FPort not present, FRMPayload not present
611      */
612     FRAME_TYPE_B,
613     /*!
614      * Frame type C
615      *
616      * FOptsLen = 0, Fopt not present, FPort = 0 , FRMPayload containing MAC commands
617      */
618     FRAME_TYPE_C,
619     /*!
620      * Frame type D
621      *
622      * FOptsLen = 0, Fopt not present, FPort > 0 , FRMPayload present
623      */
624     FRAME_TYPE_D,
625 }FType_t;
626 
627 /*!
628  * LoRaWAN Frame counter identifier.
629  */
630 typedef enum eFCntIdentifier
631 {
632     /*!
633      * Uplink frame counter which is incremented with each uplink.
634      */
635     FCNT_UP = 0,
636     /*!
637      * Network downlink frame counter which is incremented with each downlink on FPort 0
638      * or when the FPort field is missing.
639      */
640     N_FCNT_DOWN,
641     /*!
642      * Application downlink frame counter which is incremented with each downlink
643      * on a port different than 0.
644      */
645     A_FCNT_DOWN,
646     /*!
647      * In case if the device is connected to a LoRaWAN 1.0 Server,
648      * this counter is used for every kind of downlink frame.
649      */
650     FCNT_DOWN,
651     /*!
652      * Multicast downlink counter for index 0
653      */
654     MC_FCNT_DOWN_0,
655     /*!
656      * Multicast downlink counter for index 1
657      */
658     MC_FCNT_DOWN_1,
659     /*!
660      * Multicast downlink counter for index 2
661      */
662     MC_FCNT_DOWN_2,
663     /*!
664      * Multicast downlink counter for index 3
665      */
666     MC_FCNT_DOWN_3,
667     /*!
668      * RJcount1 is a counter incremented with every transmitted  Type 1 Rejoin request.
669      */
670     RJ_COUNT_0,
671     /*!
672      * RJcount0 is a counter incremented with every transmitted Type 0 or 2 Rejoin request.
673      */
674     RJ_COUNT_1,
675 }FCntIdentifier_t;
676 
677 /*!
678  * LoRaMac Key identifier
679  */
680 typedef enum eKeyIdentifier
681 {
682     /*!
683      * Application root key
684      */
685     APP_KEY = 0,
686     /*!
687      * Network root key
688      */
689     NWK_KEY,
690     /*!
691      * Join session integrity key
692      */
693     J_S_INT_KEY,
694     /*!
695      * Join session encryption key
696      */
697     J_S_ENC_KEY,
698     /*!
699      * Forwarding Network session integrity key
700      */
701     F_NWK_S_INT_KEY,
702     /*!
703      * Serving Network session integrity key
704      */
705     S_NWK_S_INT_KEY,
706     /*!
707      * Network session encryption key
708      */
709     NWK_S_ENC_KEY,
710     /*!
711      * Application session key
712      */
713     APP_S_KEY,
714     /*!
715      * Multicast root key
716      */
717     MC_ROOT_KEY,
718     /*!
719      * Multicast key encryption key
720      */
721     MC_KE_KEY = LORAMAC_CRYPTO_MULTICAST_KEYS,
722     /*!
723      * Multicast root key index 0
724      */
725     MC_KEY_0,
726     /*!
727      * Multicast Application session key index 0
728      */
729     MC_APP_S_KEY_0,
730     /*!
731      * Multicast Network session key index 0
732      */
733     MC_NWK_S_KEY_0,
734     /*!
735      * Multicast root key index 1
736      */
737     MC_KEY_1,
738     /*!
739      * Multicast Application session key index 1
740      */
741     MC_APP_S_KEY_1,
742     /*!
743      * Multicast Network session key index 1
744      */
745     MC_NWK_S_KEY_1,
746     /*!
747      * Multicast root key index 2
748      */
749     MC_KEY_2,
750     /*!
751      * Multicast Application session key index 2
752      */
753     MC_APP_S_KEY_2,
754     /*!
755      * Multicast Network session key index 2
756      */
757     MC_NWK_S_KEY_2,
758     /*!
759      * Multicast root key index 3
760      */
761     MC_KEY_3,
762     /*!
763      * Multicast Application session key index 3
764      */
765     MC_APP_S_KEY_3,
766     /*!
767      * Multicast Network session key index 3
768      */
769     MC_NWK_S_KEY_3,
770     /*!
771      * Zero key for slot randomization in class B
772      */
773     SLOT_RAND_ZERO_KEY,
774     /*!
775      * No Key
776      */
777     NO_KEY,
778 }KeyIdentifier_t;
779 
780 /*!
781  * LoRaMac Crypto address identifier
782  */
783 typedef enum eAddressIdentifier
784 {
785     /*!
786      * Multicast Address for index 0
787      */
788     MULTICAST_0_ADDR = 0,
789     /*!
790      * Multicast Address for index 1
791      */
792     MULTICAST_1_ADDR = 1,
793     /*!
794      * Multicast Address for index 2
795      */
796     MULTICAST_2_ADDR = 2,
797     /*!
798      * Multicast Address for index 3
799      */
800     MULTICAST_3_ADDR = 3,
801     /*!
802      * Unicast End-device address
803      */
804     UNICAST_DEV_ADDR = 4,
805 }AddressIdentifier_t;
806 
807 /*
808  * Multicast Rx window parameters
809  */
810 typedef struct sMcRxParams
811 {
812     /*!
813      * Multicats channel LoRaWAN class B or C
814      */
815     DeviceClass_t Class;
816     union
817     {
818         struct
819         {
820             /*!
821              * Reception frequency of the ping slot windows
822              */
823             uint32_t Frequency;
824             /*!
825              * Datarate of the ping slot
826              */
827             int8_t Datarate;
828             /*!
829              * This parameter is necessary for class B operation. It defines the
830              * periodicity of the multicast downlink slots
831              */
832             uint16_t Periodicity;
833         }ClassB;
834         struct
835         {
836             /*!
837              * Reception frequency of the ping slot windows
838              */
839             uint32_t Frequency;
840             /*!
841              * Datarate of the ping slot
842              */
843             int8_t Datarate;
844         }ClassC;
845     }Params;
846 }McRxParams_t;
847 
848 /*!
849  * Multicast channel
850  */
851 typedef struct sMcChannelParams
852 {
853     /*!
854      * Indicate if the multicast channel is being setup remotely or locally.
855      * Indicates which set of keys are to be used. \ref uMcKeys
856      */
857     bool IsRemotelySetup;
858     /*!
859      * True if the entry is active
860      */
861     bool IsEnabled;
862     /*
863      * Address identifier
864      */
865     AddressIdentifier_t GroupID;
866     /*!
867      * Address
868      */
869     uint32_t Address;
870     /*!
871      * Multicast keys
872      */
873     union uMcKeys
874     {
875         /*!
876          * Encrypted multicast key - Used when IsRemotelySetup equals `true`.
877          * MC_KEY is decrypted and then the session keys ar derived.
878          */
879         uint8_t *McKeyE;
880         /*!
881          * Multicast Session keys - Used when IsRemotelySetup equals `false`
882          */
883         struct
884         {
885             /*!
886              * Multicast application session key
887              */
888             uint8_t *McAppSKey;
889             /*!
890              * Multicast network session key
891              */
892             uint8_t *McNwkSKey;
893         }Session;
894     }McKeys;
895     /*!
896      * Minimum multicast frame counter value
897      */
898     uint32_t FCountMin;
899     /*!
900      * Maximum multicast frame counter value
901      */
902     uint32_t FCountMax;
903     /*!
904      * Multicast reception parameters
905      */
906     McRxParams_t RxParams;
907 }McChannelParams_t;
908 
909 /*!
910  * Multicast context
911  */
912 typedef struct sMulticastCtx
913 {
914     /*!
915      * Multicast channel parameters
916      */
917     McChannelParams_t ChannelParams;
918     /*!
919      * Downlink counter
920      */
921     uint32_t* DownLinkCounter;
922     /*
923      * Following parameters are only used for ClassB multicast channels
924      */
925     /*!
926      * Number of multicast slots. The variable can be
927      * calculated as follows:
928      * PingNb = 128 / ( 1 << periodicity ), where
929      * 0 <= periodicity <= 7
930      */
931     uint8_t PingNb;
932     /*!
933      * Period of the multicast slots. The variable can be
934      * calculated as follows:
935      * PingPeriod = 4096 / PingNb
936      */
937     uint16_t PingPeriod;
938     /*!
939      * Ping offset of the multicast channel for Class B
940      */
941     uint16_t PingOffset;
942     /*!
943      * Set to 1, if the FPending bit is set
944      */
945     uint8_t FPendingSet;
946 }MulticastCtx_t;
947 
948 /*!
949  * LoRaMac join-request / rejoin type identifier
950  */
951 typedef enum eJoinReqIdentifier
952 {
953     /*!
954      * Rejoin type 0
955      */
956     REJOIN_REQ_0 = 0x00,
957     /*!
958      * Rejoin type 1
959      */
960     REJOIN_REQ_1 = 0x01,
961     /*!
962      * Rejoin type 2
963      */
964     REJOIN_REQ_2 = 0x02,
965     /*!
966      * Join-request
967      */
968     JOIN_REQ = 0xFF,
969 }JoinReqIdentifier_t;
970 
971 /*!
972  * LoRaMAC mote MAC commands
973  *
974  * LoRaWAN Specification V1.1.0, chapter 5, table 4
975  */
976 typedef enum eLoRaMacMoteCmd
977 {
978     /*!
979      * ResetInd
980      */
981     MOTE_MAC_RESET_IND               = 0x01,
982     /*!
983      * LinkCheckReq
984      */
985     MOTE_MAC_LINK_CHECK_REQ          = 0x02,
986     /*!
987      * LinkADRAns
988      */
989     MOTE_MAC_LINK_ADR_ANS            = 0x03,
990     /*!
991      * DutyCycleAns
992      */
993     MOTE_MAC_DUTY_CYCLE_ANS          = 0x04,
994     /*!
995      * RXParamSetupAns
996      */
997     MOTE_MAC_RX_PARAM_SETUP_ANS      = 0x05,
998     /*!
999      * DevStatusAns
1000      */
1001     MOTE_MAC_DEV_STATUS_ANS          = 0x06,
1002     /*!
1003      * NewChannelAns
1004      */
1005     MOTE_MAC_NEW_CHANNEL_ANS         = 0x07,
1006     /*!
1007      * RXTimingSetupAns
1008      */
1009     MOTE_MAC_RX_TIMING_SETUP_ANS     = 0x08,
1010     /*!
1011      * TXParamSetupAns
1012      */
1013     MOTE_MAC_TX_PARAM_SETUP_ANS      = 0x09,
1014     /*!
1015      * DlChannelAns
1016      */
1017     MOTE_MAC_DL_CHANNEL_ANS          = 0x0A,
1018     /*!
1019      * RekeyInd
1020      */
1021     MOTE_MAC_REKEY_IND               = 0x0B,
1022     /*!
1023      * DeviceTimeReq
1024      */
1025     MOTE_MAC_DEVICE_TIME_REQ         = 0x0D,
1026     /*!
1027      * ADRParamSetupAns
1028      */
1029     MOTE_MAC_ADR_PARAM_SETUP_ANS     = 0x0C,
1030     /*!
1031      * RejoinParamSetupAns
1032      */
1033     MOTE_MAC_REJOIN_PARAM_ANS        = 0x0F,
1034     /*!
1035      * DeviceModeInd ( Class C only )
1036      */
1037     MOTE_MAC_DEVICE_MODE_IND         = 0x20,
1038     /*!
1039      * PingSlotInfoReq
1040      */
1041     MOTE_MAC_PING_SLOT_INFO_REQ      = 0x10,
1042     /*!
1043      * PingSlotFreqAns
1044      */
1045     MOTE_MAC_PING_SLOT_CHANNEL_ANS   = 0x11,
1046     /*!
1047      * BeaconTimingReq
1048      */
1049     MOTE_MAC_BEACON_TIMING_REQ       = 0x12,
1050     /*!
1051      * BeaconFreqAns
1052      */
1053     MOTE_MAC_BEACON_FREQ_ANS         = 0x13,
1054 }LoRaMacMoteCmd_t;
1055 
1056 /*!
1057  * LoRaMAC server MAC commands
1058  *
1059  * LoRaWAN Specification V1.1.0 chapter 5, table 4
1060  */
1061 typedef enum eLoRaMacSrvCmd
1062 {
1063     /*!
1064      * ResetInd
1065      */
1066     SRV_MAC_RESET_CONF               = 0x01,
1067     /*!
1068      * LinkCheckAns
1069      */
1070     SRV_MAC_LINK_CHECK_ANS           = 0x02,
1071     /*!
1072      * LinkADRReq
1073      */
1074     SRV_MAC_LINK_ADR_REQ             = 0x03,
1075     /*!
1076      * DutyCycleReq
1077      */
1078     SRV_MAC_DUTY_CYCLE_REQ           = 0x04,
1079     /*!
1080      * RXParamSetupReq
1081      */
1082     SRV_MAC_RX_PARAM_SETUP_REQ       = 0x05,
1083     /*!
1084      * DevStatusReq
1085      */
1086     SRV_MAC_DEV_STATUS_REQ           = 0x06,
1087     /*!
1088      * NewChannelReq
1089      */
1090     SRV_MAC_NEW_CHANNEL_REQ          = 0x07,
1091     /*!
1092      * RXTimingSetupReq
1093      */
1094     SRV_MAC_RX_TIMING_SETUP_REQ      = 0x08,
1095     /*!
1096      * NewChannelReq
1097      */
1098     SRV_MAC_TX_PARAM_SETUP_REQ       = 0x09,
1099     /*!
1100      * DlChannelReq
1101      */
1102     SRV_MAC_DL_CHANNEL_REQ           = 0x0A,
1103     /*!
1104      * RekeyConf
1105      */
1106     SRV_MAC_REKEY_CONF               = 0x0B,
1107     /*!
1108      * ADRParamSetupReq
1109      */
1110     SRV_MAC_ADR_PARAM_SETUP_REQ      = 0x0C,
1111     /*!
1112      * ForceRejoinReq
1113      */
1114     SRV_MAC_FORCE_REJOIN_REQ         = 0x0E,
1115     /*!
1116      * RejoinParamSetupReq
1117      */
1118     SRV_MAC_REJOIN_PARAM_REQ         = 0x0F,
1119     /*!
1120      * DeviceModeConf ( Class C only )
1121      */
1122     SRV_MAC_DEVICE_MODE_CONF         = 0x20,
1123     /*!
1124      * DeviceTimeAns
1125      */
1126     SRV_MAC_DEVICE_TIME_ANS          = 0x0D,
1127     /*!
1128      * PingSlotInfoAns
1129      */
1130     SRV_MAC_PING_SLOT_INFO_ANS       = 0x10,
1131     /*!
1132      * PingSlotChannelReq
1133      */
1134     SRV_MAC_PING_SLOT_CHANNEL_REQ    = 0x11,
1135     /*!
1136      * BeaconTimingAns
1137      */
1138     SRV_MAC_BEACON_TIMING_ANS        = 0x12,
1139     /*!
1140      * BeaconFreqReq
1141      */
1142     SRV_MAC_BEACON_FREQ_REQ          = 0x13,
1143 }LoRaMacSrvCmd_t;
1144 
1145 /*!
1146  * LoRaMAC band parameters definition
1147  */
1148 typedef struct sBand
1149 {
1150     /*!
1151      * Duty cycle
1152      */
1153     uint16_t DCycle;
1154     /*!
1155      * Maximum Tx power
1156      */
1157     int8_t TxMaxPower;
1158     /*!
1159      * The last time the band has been
1160      * synchronized with the current time
1161      */
1162     TimerTime_t LastBandUpdateTime;
1163     /*!
1164      * The last time we have assigned the max
1165      * credits for the 24h interval.
1166      */
1167     TimerTime_t LastMaxCreditAssignTime;
1168     /*!
1169      * Current time credits which are available. This
1170      * is a value in ms
1171      */
1172     TimerTime_t TimeCredits;
1173     /*!
1174      * Maximum time credits which are available. This
1175      * is a value in ms
1176      */
1177     TimerTime_t MaxTimeCredits;
1178     /*!
1179      * Set to true when the band is ready for use.
1180      */
1181     bool ReadyForTransmission;
1182 }Band_t;
1183 
1184 /*!
1185  * LoRaMAC channels parameters definition
1186  */
1187 typedef union uDrRange
1188 {
1189     /*!
1190      * Byte-access to the bits
1191      */
1192     int8_t Value;
1193     /*!
1194      * Structure to store the minimum and the maximum datarate
1195      */
1196     struct sFields
1197     {
1198         /*!
1199          * Minimum data rate
1200          *
1201          * LoRaWAN Regional Parameters V1.0.2rB
1202          *
1203          * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
1204          */
1205         int8_t Min : 4;
1206         /*!
1207          * Maximum data rate
1208          *
1209          * LoRaWAN Regional Parameters V1.0.2rB
1210          *
1211          * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
1212          */
1213         int8_t Max : 4;
1214     }Fields;
1215 }DrRange_t;
1216 
1217 /*!
1218  * LoRaMAC channel definition
1219  */
1220 typedef struct sChannelParams
1221 {
1222     /*!
1223      * Frequency in Hz
1224      */
1225     uint32_t Frequency;
1226     /*!
1227      * Alternative frequency for RX window 1
1228      */
1229     uint32_t Rx1Frequency;
1230     /*!
1231      * Data rate definition
1232      */
1233     DrRange_t DrRange;
1234     /*!
1235      * Band index
1236      */
1237     uint8_t Band;
1238 }ChannelParams_t;
1239 
1240 /*!
1241  * LoRaMAC frame types
1242  *
1243  * LoRaWAN Specification V1.0.2, chapter 4.2.1, table 1
1244  */
1245 typedef enum eLoRaMacFrameType
1246 {
1247     /*!
1248      * LoRaMAC join request frame
1249      */
1250     FRAME_TYPE_JOIN_REQ              = 0x00,
1251     /*!
1252      * LoRaMAC join accept frame
1253      */
1254     FRAME_TYPE_JOIN_ACCEPT           = 0x01,
1255     /*!
1256      * LoRaMAC unconfirmed up-link frame
1257      */
1258     FRAME_TYPE_DATA_UNCONFIRMED_UP   = 0x02,
1259     /*!
1260      * LoRaMAC unconfirmed down-link frame
1261      */
1262     FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
1263     /*!
1264      * LoRaMAC confirmed up-link frame
1265      */
1266     FRAME_TYPE_DATA_CONFIRMED_UP     = 0x04,
1267     /*!
1268      * LoRaMAC confirmed down-link frame
1269      */
1270     FRAME_TYPE_DATA_CONFIRMED_DOWN   = 0x05,
1271     /*!
1272      * LoRaMAC Rejoin Request
1273      */
1274     FRAME_TYPE_REJOIN                = 0x06,
1275     /*!
1276      * LoRaMAC proprietary frame
1277      */
1278     FRAME_TYPE_PROPRIETARY           = 0x07,
1279 }LoRaMacFrameType_t;
1280 
1281 /*!
1282  * LoRaMAC Battery level indicator
1283  */
1284 typedef enum eLoRaMacBatteryLevel
1285 {
1286     /*!
1287      * External power source
1288      */
1289     BAT_LEVEL_EXT_SRC                = 0x00,
1290     /*!
1291      * Battery level empty
1292      */
1293     BAT_LEVEL_EMPTY                  = 0x01,
1294     /*!
1295      * Battery level full
1296      */
1297     BAT_LEVEL_FULL                   = 0xFE,
1298     /*!
1299      * Battery level - no measurement available
1300      */
1301     BAT_LEVEL_NO_MEASURE             = 0xFF,
1302 }LoRaMacBatteryLevel_t;
1303 
1304 #ifdef __cplusplus
1305 }
1306 #endif
1307 
1308 #endif // __LORAMAC_TYPES_H__
1309 
1310