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 }FCntIdentifier_t;
668 
669 /*!
670  * LoRaMac Key identifier
671  */
672 typedef enum eKeyIdentifier
673 {
674     /*!
675      * Application root key
676      */
677     APP_KEY = 0,
678     /*!
679      * Network root key
680      */
681     NWK_KEY,
682     /*!
683      * Join session integrity key
684      */
685     J_S_INT_KEY,
686     /*!
687      * Join session encryption key
688      */
689     J_S_ENC_KEY,
690     /*!
691      * Forwarding Network session integrity key
692      */
693     F_NWK_S_INT_KEY,
694     /*!
695      * Serving Network session integrity key
696      */
697     S_NWK_S_INT_KEY,
698     /*!
699      * Network session encryption key
700      */
701     NWK_S_ENC_KEY,
702     /*!
703      * Application session key
704      */
705     APP_S_KEY,
706     /*!
707      * Multicast root key
708      */
709     MC_ROOT_KEY,
710     /*!
711      * Multicast key encryption key
712      */
713     MC_KE_KEY = LORAMAC_CRYPTO_MULTICAST_KEYS,
714     /*!
715      * Multicast root key index 0
716      */
717     MC_KEY_0,
718     /*!
719      * Multicast Application session key index 0
720      */
721     MC_APP_S_KEY_0,
722     /*!
723      * Multicast Network session key index 0
724      */
725     MC_NWK_S_KEY_0,
726     /*!
727      * Multicast root key index 1
728      */
729     MC_KEY_1,
730     /*!
731      * Multicast Application session key index 1
732      */
733     MC_APP_S_KEY_1,
734     /*!
735      * Multicast Network session key index 1
736      */
737     MC_NWK_S_KEY_1,
738     /*!
739      * Multicast root key index 2
740      */
741     MC_KEY_2,
742     /*!
743      * Multicast Application session key index 2
744      */
745     MC_APP_S_KEY_2,
746     /*!
747      * Multicast Network session key index 2
748      */
749     MC_NWK_S_KEY_2,
750     /*!
751      * Multicast root key index 3
752      */
753     MC_KEY_3,
754     /*!
755      * Multicast Application session key index 3
756      */
757     MC_APP_S_KEY_3,
758     /*!
759      * Multicast Network session key index 3
760      */
761     MC_NWK_S_KEY_3,
762     /*!
763      * Zero key for slot randomization in class B
764      */
765     SLOT_RAND_ZERO_KEY,
766     /*!
767      * No Key
768      */
769     NO_KEY,
770 }KeyIdentifier_t;
771 
772 /*!
773  * LoRaMac Crypto address identifier
774  */
775 typedef enum eAddressIdentifier
776 {
777     /*!
778      * Multicast Address for index 0
779      */
780     MULTICAST_0_ADDR = 0,
781     /*!
782      * Multicast Address for index 1
783      */
784     MULTICAST_1_ADDR = 1,
785     /*!
786      * Multicast Address for index 2
787      */
788     MULTICAST_2_ADDR = 2,
789     /*!
790      * Multicast Address for index 3
791      */
792     MULTICAST_3_ADDR = 3,
793     /*!
794      * Unicast End-device address
795      */
796     UNICAST_DEV_ADDR = 4,
797 }AddressIdentifier_t;
798 
799 /*
800  * Multicast Rx window parameters
801  */
802 typedef union uMcRxParams
803 {
804     struct
805     {
806         /*!
807             * Reception frequency of the ping slot windows
808             */
809         uint32_t Frequency;
810         /*!
811             * Datarate of the ping slot
812             */
813         int8_t Datarate;
814         /*!
815             * This parameter is necessary for class B operation. It defines the
816             * periodicity of the multicast downlink slots
817             */
818         uint16_t Periodicity;
819     }ClassB;
820     struct
821     {
822         /*!
823         * Reception frequency of the ping slot windows
824         */
825         uint32_t Frequency;
826         /*!
827         * Datarate of the ping slot
828         */
829         int8_t Datarate;
830     }ClassC;
831 }McRxParams_t;
832 
833 /*!
834  * Multicast channel
835  */
836 typedef struct sMcChannelParams
837 {
838     /*!
839      * Indicate if the multicast channel is being setup remotely or locally.
840      * Indicates which set of keys are to be used. \ref uMcKeys
841      */
842     bool IsRemotelySetup;
843     /*!
844      * Multicats channel LoRaWAN class B or C
845      */
846     DeviceClass_t Class;
847     /*!
848      * True if the entry is active
849      */
850     bool IsEnabled;
851     /*
852      * Address identifier
853      */
854     AddressIdentifier_t GroupID;
855     /*!
856      * Address
857      */
858     uint32_t Address;
859     /*!
860      * Multicast keys
861      */
862     union uMcKeys
863     {
864         /*!
865          * Encrypted multicast key - Used when IsRemotelySetup equals `true`.
866          * MC_KEY is decrypted and then the session keys ar derived.
867          */
868         uint8_t *McKeyE;
869         /*!
870          * Multicast Session keys - Used when IsRemotelySetup equals `false`
871          */
872         struct
873         {
874             /*!
875              * Multicast application session key
876              */
877             uint8_t *McAppSKey;
878             /*!
879              * Multicast network session key
880              */
881             uint8_t *McNwkSKey;
882         }Session;
883     }McKeys;
884     /*!
885      * Minimum multicast frame counter value
886      */
887     uint32_t FCountMin;
888     /*!
889      * Maximum multicast frame counter value
890      */
891     uint32_t FCountMax;
892     /*!
893      * Multicast reception parameters
894      */
895     McRxParams_t RxParams;
896 }McChannelParams_t;
897 
898 /*!
899  * Multicast context
900  */
901 typedef struct sMulticastCtx
902 {
903     /*!
904      * Multicast channel parameters
905      */
906     McChannelParams_t ChannelParams;
907     /*!
908      * Downlink counter
909      */
910     uint32_t* DownLinkCounter;
911     /*
912      * Following parameters are only used for ClassB multicast channels
913      */
914     /*!
915      * Number of multicast slots. The variable can be
916      * calculated as follows:
917      * PingNb = 128 / ( 1 << periodicity ), where
918      * 0 <= periodicity <= 7
919      */
920     uint8_t PingNb;
921     /*!
922      * Period of the multicast slots. The variable can be
923      * calculated as follows:
924      * PingPeriod = 4096 / PingNb
925      */
926     uint16_t PingPeriod;
927     /*!
928      * Ping offset of the multicast channel for Class B
929      */
930     uint16_t PingOffset;
931     /*!
932      * Set to 1, if the FPending bit is set
933      */
934     uint8_t FPendingSet;
935 }MulticastCtx_t;
936 
937 /*!
938  * LoRaMac join-request / rejoin type identifier
939  */
940 typedef enum eJoinReqIdentifier
941 {
942     /*!
943      * Rejoin type 0
944      */
945     REJOIN_REQ_0 = 0x00,
946     /*!
947      * Rejoin type 1
948      */
949     REJOIN_REQ_1 = 0x01,
950     /*!
951      * Rejoin type 2
952      */
953     REJOIN_REQ_2 = 0x02,
954     /*!
955      * Join-request
956      */
957     JOIN_REQ = 0xFF,
958 }JoinReqIdentifier_t;
959 
960 /*!
961  * LoRaMAC mote MAC commands
962  *
963  * LoRaWAN Specification V1.1.0, chapter 5, table 4
964  */
965 typedef enum eLoRaMacMoteCmd
966 {
967     /*!
968      * LinkCheckReq
969      */
970     MOTE_MAC_LINK_CHECK_REQ          = 0x02,
971     /*!
972      * LinkADRAns
973      */
974     MOTE_MAC_LINK_ADR_ANS            = 0x03,
975     /*!
976      * DutyCycleAns
977      */
978     MOTE_MAC_DUTY_CYCLE_ANS          = 0x04,
979     /*!
980      * RXParamSetupAns
981      */
982     MOTE_MAC_RX_PARAM_SETUP_ANS      = 0x05,
983     /*!
984      * DevStatusAns
985      */
986     MOTE_MAC_DEV_STATUS_ANS          = 0x06,
987     /*!
988      * NewChannelAns
989      */
990     MOTE_MAC_NEW_CHANNEL_ANS         = 0x07,
991     /*!
992      * RXTimingSetupAns
993      */
994     MOTE_MAC_RX_TIMING_SETUP_ANS     = 0x08,
995     /*!
996      * TXParamSetupAns
997      */
998     MOTE_MAC_TX_PARAM_SETUP_ANS      = 0x09,
999     /*!
1000      * DlChannelAns
1001      */
1002     MOTE_MAC_DL_CHANNEL_ANS          = 0x0A,
1003     /*!
1004      * DeviceTimeReq
1005      */
1006     MOTE_MAC_DEVICE_TIME_REQ         = 0x0D,
1007     /*!
1008      * PingSlotInfoReq
1009      */
1010     MOTE_MAC_PING_SLOT_INFO_REQ      = 0x10,
1011     /*!
1012      * PingSlotFreqAns
1013      */
1014     MOTE_MAC_PING_SLOT_CHANNEL_ANS   = 0x11,
1015     /*!
1016      * BeaconTimingReq
1017      */
1018     MOTE_MAC_BEACON_TIMING_REQ       = 0x12,
1019     /*!
1020      * BeaconFreqAns
1021      */
1022     MOTE_MAC_BEACON_FREQ_ANS         = 0x13,
1023 }LoRaMacMoteCmd_t;
1024 
1025 /*!
1026  * LoRaMAC server MAC commands
1027  *
1028  * LoRaWAN Specification V1.1.0 chapter 5, table 4
1029  */
1030 typedef enum eLoRaMacSrvCmd
1031 {
1032     /*!
1033      * ResetInd
1034      */
1035     SRV_MAC_RESET_CONF               = 0x01,
1036     /*!
1037      * LinkCheckAns
1038      */
1039     SRV_MAC_LINK_CHECK_ANS           = 0x02,
1040     /*!
1041      * LinkADRReq
1042      */
1043     SRV_MAC_LINK_ADR_REQ             = 0x03,
1044     /*!
1045      * DutyCycleReq
1046      */
1047     SRV_MAC_DUTY_CYCLE_REQ           = 0x04,
1048     /*!
1049      * RXParamSetupReq
1050      */
1051     SRV_MAC_RX_PARAM_SETUP_REQ       = 0x05,
1052     /*!
1053      * DevStatusReq
1054      */
1055     SRV_MAC_DEV_STATUS_REQ           = 0x06,
1056     /*!
1057      * NewChannelReq
1058      */
1059     SRV_MAC_NEW_CHANNEL_REQ          = 0x07,
1060     /*!
1061      * RXTimingSetupReq
1062      */
1063     SRV_MAC_RX_TIMING_SETUP_REQ      = 0x08,
1064     /*!
1065      * NewChannelReq
1066      */
1067     SRV_MAC_TX_PARAM_SETUP_REQ       = 0x09,
1068     /*!
1069      * DlChannelReq
1070      */
1071     SRV_MAC_DL_CHANNEL_REQ           = 0x0A,
1072     /*!
1073      * DeviceTimeAns
1074      */
1075     SRV_MAC_DEVICE_TIME_ANS          = 0x0D,
1076     /*!
1077      * PingSlotInfoAns
1078      */
1079     SRV_MAC_PING_SLOT_INFO_ANS       = 0x10,
1080     /*!
1081      * PingSlotChannelReq
1082      */
1083     SRV_MAC_PING_SLOT_CHANNEL_REQ    = 0x11,
1084     /*!
1085      * BeaconTimingAns
1086      */
1087     SRV_MAC_BEACON_TIMING_ANS        = 0x12,
1088     /*!
1089      * BeaconFreqReq
1090      */
1091     SRV_MAC_BEACON_FREQ_REQ          = 0x13,
1092 }LoRaMacSrvCmd_t;
1093 
1094 /*!
1095  * LoRaMAC band parameters definition
1096  */
1097 typedef struct sBand
1098 {
1099     /*!
1100      * Duty cycle
1101      */
1102     uint16_t DCycle;
1103     /*!
1104      * Maximum Tx power
1105      */
1106     int8_t TxMaxPower;
1107     /*!
1108      * The last time the band has been
1109      * synchronized with the current time
1110      */
1111     TimerTime_t LastBandUpdateTime;
1112     /*!
1113      * The last time we have assigned the max
1114      * credits for the 24h interval.
1115      */
1116     TimerTime_t LastMaxCreditAssignTime;
1117     /*!
1118      * Current time credits which are available. This
1119      * is a value in ms
1120      */
1121     TimerTime_t TimeCredits;
1122     /*!
1123      * Maximum time credits which are available. This
1124      * is a value in ms
1125      */
1126     TimerTime_t MaxTimeCredits;
1127     /*!
1128      * Set to true when the band is ready for use.
1129      */
1130     bool ReadyForTransmission;
1131 }Band_t;
1132 
1133 /*!
1134  * LoRaMAC channels parameters definition
1135  */
1136 typedef union uDrRange
1137 {
1138     /*!
1139      * Byte-access to the bits
1140      */
1141     int8_t Value;
1142     /*!
1143      * Structure to store the minimum and the maximum datarate
1144      */
1145     struct sFields
1146     {
1147         /*!
1148          * Minimum data rate
1149          *
1150          * LoRaWAN Regional Parameters V1.0.2rB
1151          *
1152          * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
1153          */
1154         int8_t Min : 4;
1155         /*!
1156          * Maximum data rate
1157          *
1158          * LoRaWAN Regional Parameters V1.0.2rB
1159          *
1160          * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
1161          */
1162         int8_t Max : 4;
1163     }Fields;
1164 }DrRange_t;
1165 
1166 /*!
1167  * LoRaMAC channel definition
1168  */
1169 typedef struct sChannelParams
1170 {
1171     /*!
1172      * Frequency in Hz
1173      */
1174     uint32_t Frequency;
1175     /*!
1176      * Alternative frequency for RX window 1
1177      */
1178     uint32_t Rx1Frequency;
1179     /*!
1180      * Data rate definition
1181      */
1182     DrRange_t DrRange;
1183     /*!
1184      * Band index
1185      */
1186     uint8_t Band;
1187 }ChannelParams_t;
1188 
1189 /*!
1190  * LoRaMAC frame types
1191  *
1192  * LoRaWAN Specification V1.0.2, chapter 4.2.1, table 1
1193  */
1194 typedef enum eLoRaMacFrameType
1195 {
1196     /*!
1197      * LoRaMAC join request frame
1198      */
1199     FRAME_TYPE_JOIN_REQ              = 0x00,
1200     /*!
1201      * LoRaMAC join accept frame
1202      */
1203     FRAME_TYPE_JOIN_ACCEPT           = 0x01,
1204     /*!
1205      * LoRaMAC unconfirmed up-link frame
1206      */
1207     FRAME_TYPE_DATA_UNCONFIRMED_UP   = 0x02,
1208     /*!
1209      * LoRaMAC unconfirmed down-link frame
1210      */
1211     FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
1212     /*!
1213      * LoRaMAC confirmed up-link frame
1214      */
1215     FRAME_TYPE_DATA_CONFIRMED_UP     = 0x04,
1216     /*!
1217      * LoRaMAC confirmed down-link frame
1218      */
1219     FRAME_TYPE_DATA_CONFIRMED_DOWN   = 0x05,
1220     /*!
1221      * LoRaMAC proprietary frame
1222      */
1223     FRAME_TYPE_PROPRIETARY           = 0x07,
1224 }LoRaMacFrameType_t;
1225 
1226 /*!
1227  * LoRaMAC Battery level indicator
1228  */
1229 typedef enum eLoRaMacBatteryLevel
1230 {
1231     /*!
1232      * External power source
1233      */
1234     BAT_LEVEL_EXT_SRC                = 0x00,
1235     /*!
1236      * Battery level empty
1237      */
1238     BAT_LEVEL_EMPTY                  = 0x01,
1239     /*!
1240      * Battery level full
1241      */
1242     BAT_LEVEL_FULL                   = 0xFE,
1243     /*!
1244      * Battery level - no measurement available
1245      */
1246     BAT_LEVEL_NO_MEASURE             = 0xFF,
1247 }LoRaMacBatteryLevel_t;
1248 
1249 #ifdef __cplusplus
1250 }
1251 #endif
1252 
1253 #endif // __LORAMAC_TYPES_H__
1254 
1255