forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloramac.h
1126 lines (1043 loc) · 36.8 KB
/
loramac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2017 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_loramac LoRaMAC
* @ingroup net
* @brief LoRaMAC definitions
*
* @{
*
* @file
* @brief LoRaMAC header definitions
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/
#ifndef NET_LORAMAC_H
#define NET_LORAMAC_H
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include "modules.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup net_loramac_conf LoRaMAC compile configurations
* @ingroup config
* @{
*/
/**
* @brief Default device EUI
*
* 8 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_DEV_EUI_DEFAULT
#define CONFIG_LORAMAC_DEV_EUI_DEFAULT "0000000000000000"
#endif
/**
* @brief Default join EUI
*
* 8 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_JOIN_EUI_DEFAULT
#define CONFIG_LORAMAC_JOIN_EUI_DEFAULT "0000000000000000"
#endif
/**
* @brief Default application EUI
*
* 8 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_APP_EUI_DEFAULT
#define CONFIG_LORAMAC_APP_EUI_DEFAULT "0000000000000000"
#endif
/**
* @brief Default application key
*
* 16 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_APP_KEY_DEFAULT
#define CONFIG_LORAMAC_APP_KEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default network key
*
* 16 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_NWK_KEY_DEFAULT
#define CONFIG_LORAMAC_NWK_KEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default application session key
*
* 16 bytes key, only required for ABP join procedure type
*/
#ifndef CONFIG_LORAMAC_APP_SKEY_DEFAULT
#define CONFIG_LORAMAC_APP_SKEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default network session key
*
* 16 bytes key, only required for ABP join procedure type.
*/
#ifndef CONFIG_LORAMAC_NWK_SKEY_DEFAULT
#define CONFIG_LORAMAC_NWK_SKEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default network session integrity key
*
* 16 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_FNWKSINT_KEY_DEFAULT
#define CONFIG_LORAMAC_FNWKSINT_KEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default serving network session integrity key
*
* 16 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_SNWKSINT_KEY_DEFAULT
#define CONFIG_LORAMAC_SNWKSINT_KEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default network session encryption key
*
* 16 bytes key, required for join procedure
*/
#ifndef CONFIG_LORAMAC_NWKSENC_KEY_DEFAULT
#define CONFIG_LORAMAC_NWKSENC_KEY_DEFAULT "00000000000000000000000000000000"
#endif
/**
* @brief Default device address
*/
#ifndef CONFIG_LORAMAC_DEV_ADDR_DEFAULT
#define CONFIG_LORAMAC_DEV_ADDR_DEFAULT "00000000"
#endif
/**
* @brief Default LoRaWAN region
*/
#if !IS_ACTIVE(CONFIG_LORAMAC_REGION_EU_868) \
&& !IS_ACTIVE(CONFIG_LORAMAC_REGION_IN_865)
#define CONFIG_LORAMAC_REGION_EU_868 1
#endif
/**
* @brief Default device class (A, B or C)
*
* Configure the class of device. LoRaWAN supports three classes of operation
* for end nodes namely Class A, B and C. All LoRaWAN devices are expected to
* implement Class A, whereas Class B and Class C can be considered as
* extensions to the specification of Class A devices.
*
* @see [LoRaWAN Classes by TTN](https://www.thethingsnetwork.org/docs/lorawan/classes.html)
*
* @note GNRC LoRaWAN only supports Class A
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS_A)
#define CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS (LORAMAC_CLASS_A)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS_B)
#define CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS (LORAMAC_CLASS_B)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS_C)
#define CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS (LORAMAC_CLASS_C)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS
#define CONFIG_LORAMAC_DEFAULT_DEVICE_CLASS (LORAMAC_CLASS_A)
#endif
/**
* @brief Default NetID (only valid with ABP join procedure)
*
* NETID is used by networks for assigning network-specific addresses to their
* end-devices (i.e., DevAddr) so that uplink frames sent by those devices even
* when they are roaming outside their home network can be forwarded to their
* home network.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_NETID
#define CONFIG_LORAMAC_DEFAULT_NETID (1U)
#endif
/**
* @brief Toggle network type (public or private)
*
* Set "1" to enable private network, set "0" to enable public network.
* This configuration sets the sync word for LoRaWAN communication. This should
* be in concordance with the gateway configuration. Public networks use `0x34`
* while private networks use `0x12` as sync word.
*/
#ifdef DOXYGEN
#define CONFIG_LORAMAC_DEFAULT_PRIVATE_NETWORK
#endif
/**
* @brief Default datarate index
*
* Data rate combines two aspects, Bandwidth (BW) and Spreading Factor (SF). BW
* depends on the region while SF contributes to the dwell time in any given
* band which is limited by region. DR hence signifies difference combination on
* BW and SF for different regions. Refer LoRaWAN 1.0.3 Regional Parameters for
* more information.
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_0)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_0)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_1)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_1)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_2)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_2)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_3)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_3)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_4)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_4)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_5)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_5)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_6)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_6)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_7)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_7)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_8)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_8)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_9)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_9)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_10)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_10)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_11)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_11)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_12)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_12)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_13)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_13)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_14)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_14)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_DR_15)
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_15)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_DR
#define CONFIG_LORAMAC_DEFAULT_DR (LORAMAC_DR_0)
#endif
/**
* @brief Default MAC TX power index
*
* TXPower index indicates power levels relative to the max EIRP level of the
* end-device. Refer LoRaWAN 1.0.3 Regional Parameters for more information.
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_0)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_0)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_1)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_1)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_2)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_2)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_3)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_3)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_4)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_4)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_5)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_5)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_6)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_6)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_7)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_7)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_8)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_8)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_9)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_9)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_10)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_10)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_11)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_11)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_12)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_12)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_13)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_13)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_14)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_14)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_POWER_15)
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_15)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_TX_POWER
#define CONFIG_LORAMAC_DEFAULT_TX_POWER (LORAMAC_TX_PWR_1)
#endif
/**
* @brief Default MAC TX port (from 1 to 223)
*
* The TX port denotes the port field `FPort` in the payload and is commonly
* used on the destination side (Application Server) to distinguish different
* payload formats. For example it can be used to identify different sensor
* types/values from the same end-node and hence different payload formats can
* be assigned to the different values based on value of port.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_TX_PORT
#define CONFIG_LORAMAC_DEFAULT_TX_PORT (2U)
#endif
/**
* @brief Default MAC TX mode (confirmable or unconfirmable)
*
* A confirmed uplink will expect an acknowledgment from the network server;
* otherwise, the message will be retransmitted by the number indicated by
* @ref CONFIG_LORAMAC_DEFAULT_RETX , whereas an unconfirmed message will not
* expect any acknowledgment back from the network server.
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_MODE_CNF)
#define CONFIG_LORAMAC_DEFAULT_TX_MODE (LORAMAC_TX_CNF)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_TX_MODE_UNCNF)
#define CONFIG_LORAMAC_DEFAULT_TX_MODE (LORAMAC_TX_UNCNF)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_TX_MODE
#define CONFIG_LORAMAC_DEFAULT_TX_MODE (LORAMAC_TX_CNF)
#endif
/**
* @brief Default redundancy for unconfirmed uplink
*
* This corresponds to the number of unconfirmed uplink retransmissions when
* using ADR. This configuration does not affect confirmed uplinks. By
* default, uplinks are sent without retransmissions (this means, the device
* sends only one uplink packet)
*
* @note This value MUST NOT be greater than 14, since the LinkADRCommand it's
* already limited by a 4 bit value (therefore, 15 uplink transmissions)
*/
#ifndef CONFIG_LORAMAC_DEFAULT_REDUNDANCY
#define CONFIG_LORAMAC_DEFAULT_REDUNDANCY (0U)
#endif
/**
* @brief Enable/disable adaptive datarate state
*
* If enabled the end node will inform the network server about the status of
* ADR using the ADR field in uplink data packet. The network server will then
* optimize the data rate and the transmission power of the end node based on
* the information collected from the network.
*/
#ifdef DOXYGEN
#define CONFIG_LORAMAC_DEFAULT_ADR
#endif
/**
* @brief Default uplink retransmission
*
* Maximum number of retransmissions to be used for a confirmed uplink packet,
* if no downlink acknowledgment is received from the network.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_RETX
#define CONFIG_LORAMAC_DEFAULT_RETX (5U)
#endif
/**
* @brief Default link check interval (in seconds)
*
* 0 means the link check process is disabled. The link check process is used by
* an end-device to validate its connectivity with the network. The frame has
* no payload. When a `LinkCheckReq` is received by the network server via one
* or multiple gateways, it responds with a `LinkCheckAns` MAC command.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_LINKCHK
#define CONFIG_LORAMAC_DEFAULT_LINKCHK (0U)
#endif
/**
* @brief Default first RX window delay (in ms)
*
* This configuration specifies the delay in seconds to open the RX1 window
* after the end of uplink modulation on the end-node.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_RX1_DELAY
#define CONFIG_LORAMAC_DEFAULT_RX1_DELAY (1000U)
#endif
/**
* @brief Default second RX (RX2) window datarate index
*
* This may be changed only if the network server can be configured with the
* same datarate.
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_0)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_0)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_1)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_1)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_2)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_2)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_3)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_3)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_4)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_4)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_5)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_5)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_6)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_6)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_7)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_7)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_8)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_8)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_9)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_9)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_10)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_10)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_11)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_11)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_12)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_12)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_13)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_13)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_14)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_14)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_RX2_DR_15)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_15)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_RX2_DR
#if IS_ACTIVE(CONFIG_LORAMAC_REGION_EU_868)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_0)
#elif IS_ACTIVE(CONFIG_LORAMAC_REGION_IN_865)
#define CONFIG_LORAMAC_DEFAULT_RX2_DR (LORAMAC_DR_2)
#endif
#endif
/**
* @brief Default second RX (RX2) window frequency (in Hz)
*/
#ifndef CONFIG_LORAMAC_DEFAULT_RX2_FREQ
#if IS_ACTIVE(CONFIG_LORAMAC_REGION_EU_868)
#define CONFIG_LORAMAC_DEFAULT_RX2_FREQ (869525000UL)
#elif IS_ACTIVE(CONFIG_LORAMAC_REGION_IN_865)
#define CONFIG_LORAMAC_DEFAULT_RX2_FREQ (866550000UL)
#endif
#endif
/**
* @brief Default LoRaMAC join procedure
*
* There are two options, Over The Air Activation (OTAA) results in device
* sending join request to the network whereas in the case of Activation By
* Personalization (ABP) the user enters the activation keys manually. OTAA is
* the preferred and most secure way to connect to a LoRaWAN network. For quick
* testing ABP is preferred as the device can transmit right away without
* waiting for the network to provision the keys.
*/
#if IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE_OTAA)
#define CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE (LORAMAC_JOIN_OTAA)
#elif IS_ACTIVE(CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE_ABP)
#define CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE (LORAMAC_JOIN_ABP)
#endif
#ifndef CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE
#define CONFIG_LORAMAC_DEFAULT_JOIN_PROCEDURE (LORAMAC_JOIN_OTAA)
#endif
/**
* @brief Default LoRaMAC join accept delay 1 (in seconds)
*
* Maximum wait time in end node to receive the `join-accept` message sent by
* the network in the first receive window. This is similar to the operation of
* RX1 window.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_JOIN_DELAY1
#define CONFIG_LORAMAC_DEFAULT_JOIN_DELAY1 (5U)
#endif
/**
* @brief Default LoRaMAC join accept delay 2
*
* Maximum wait time in end node to receive the `join-accept` message sent by
* the network in the second receive window. This is similar to the operation of
* RX2 window.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_JOIN_DELAY2
#define CONFIG_LORAMAC_DEFAULT_JOIN_DELAY2 (6U)
#endif
/**
* @brief Default max FCNT gap
*
* Frame counter deviation is the difference between the frame counter values
* transmitted by the End Node and the value stored in Network Server (NS).
*/
#ifndef CONFIG_LORAMAC_DEFAULT_MAX_FCNT_GAP
#define CONFIG_LORAMAC_DEFAULT_MAX_FCNT_GAP (16384U)
#endif
/**
* @brief Default maximum system overall timing error
*
* This configuration is used to increase the RX window to account for timer
* drift. This may be decreased if the system clock is accurate, for eg: if the
* system clock is from a TCXO.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_SYSTEM_MAX_RX_ERROR
#define CONFIG_LORAMAC_DEFAULT_SYSTEM_MAX_RX_ERROR (50)
#endif
/**
* @brief Default minimum RX symbols to detect a frame
*
* This configuration is used to arrive at `T_RX_late` which is used in RX
* window calculation. This may be increased to account for inaccuracies in
* system timer. Refer SX1276_settings_for_LoRaWAN_v2p2.pdf (AN1200.24)
* from Semtech for more information.
*/
#ifndef CONFIG_LORAMAC_DEFAULT_MIN_RX_SYMBOLS
#define CONFIG_LORAMAC_DEFAULT_MIN_RX_SYMBOLS (12)
#endif
/**
* @}
*/
/**
* @brief Default adaptive datarate ACK limit (in s)
*
* @note This feature is not yet supported.
*/
#ifndef LORAMAC_DEFAULT_ADR_ACK_LIMIT
#define LORAMAC_DEFAULT_ADR_ACK_LIMIT (64U)
#endif
/**
* @brief Default adaptive datarate ACK delay (in s)
*
* @note This feature is not yet supported.
*/
#ifndef LORAMAC_DEFAULT_ADR_ACK_DELAY
#define LORAMAC_DEFAULT_ADR_ACK_DELAY (32U)
#endif
/**
* @brief Default adaptive datarate timeout
*
* @note This feature is not yet supported.
*/
#ifndef LORAMAC_DEFAULT_ADR_TIMEOUT
#define LORAMAC_DEFAULT_ADR_TIMEOUT (3U)
#endif
/**
* @brief Default second RX window delay (in ms)
*/
#define LORAMAC_DEFAULT_RX2_DELAY (1000U + CONFIG_LORAMAC_DEFAULT_RX1_DELAY)
/**
* @name LoRaMAC constants
* @{
*/
/**
* @brief Device EUI length in bytes
*/
#define LORAMAC_DEVEUI_LEN (8U)
/**
* @brief Device address length in bytes
*/
#define LORAMAC_DEVADDR_LEN (4U)
/**
* @brief Application EUI length in bytes
*/
#define LORAMAC_APPEUI_LEN (8U)
/**
* @brief Join EUI length in bytes
*/
#define LORAMAC_JOINEUI_LEN (8U)
/**
* @brief Application key length in bytes
*/
#define LORAMAC_APPKEY_LEN (16U)
/**
* @brief Network key length in bytes
*/
#define LORAMAC_NWKKEY_LEN (16U)
/**
* @brief Application session key length in bytes
*/
#define LORAMAC_APPSKEY_LEN (16U)
/**
* @brief Network session key length in bytes
*/
#define LORAMAC_NWKSKEY_LEN (16U)
/**
* @brief Forwarding Network session integrity key length in bytes
*/
#define LORAMAC_FNWKSINTKEY_LEN (16U)
/**
* @brief Serving Network session integrity key length in bytes
*/
#define LORAMAC_SNWKSINTKEY_LEN (16U)
/**
* @brief Network session encryption key length in bytes
*/
#define LORAMAC_NWKSENCKEY_LEN (16U)
/**
* @brief Join session integrity key length in bytes
*/
#define LORAMAC_JSINTKEY_LEN (16U)
/**
* @brief Join session encryption key length in bytes
*/
#define LORAMAC_JSENCKEY_LEN (16U)
/**
* @brief Network session encryption key length in bytes
*/
#define LORAMAC_JSINTKEY_LEN (16U)
/**
* @brief Minimum port value
*/
#define LORAMAC_PORT_MIN (1U)
/**
* @brief Maximum port value
*/
#define LORAMAC_PORT_MAX (223U)
/**
* @brief Application Nonce length in bytes
*/
#define LORAMAC_APP_NONCE_LEN (3U)
/**
* @brief Join nonce length in bytes
*/
#define LORAMAC_JOIN_NONCE_LEN (3U)
/**
* @brief Network ID length in bytes
*/
#define LORAMAC_NETWORK_ID_LEN (3U)
/**
* @brief Channel mask length
*
* Must match CHANNELS_MASK_SIZE in src/mac/region/RegionXXYYY.c
*/
#if defined(REGION_AU915) || defined(REGION_CN470) || defined(REGION_US915) || defined(REGION_US915_HYBRID) || defined(REGION_AS923)
#define LORAMAC_CHANNELS_MASK_LEN (6U)
#else
#define LORAMAC_CHANNELS_MASK_LEN (1U)
#endif
/** @} */
/**
* @name LoRaMAC parameters indexes
* @{
*/
/**
* @brief Device class
*/
typedef enum {
LORAMAC_CLASS_A, /**< Class A device */
LORAMAC_CLASS_B, /**< Class B device */
LORAMAC_CLASS_C, /**< Class C device */
} loramac_class_t;
/**
* @brief LoRaMAC network join procedure type
*/
typedef enum {
LORAMAC_JOIN_OTAA, /**< Other-the-air activation */
LORAMAC_JOIN_ABP, /**< Activation by personnalization */
} loramac_join_mode_t;
/**
* @brief LoRaMAC transmission mode
*/
typedef enum {
LORAMAC_TX_CNF, /**< Confirmable transmission mode */
LORAMAC_TX_UNCNF, /**< Unconfirmable transmission mode */
} loramac_tx_mode_t;
/**
* @brief LoRaMAC datarate indexes
*
* Each index corresponds to a different modulation, spreading factor
* and bandwidth depending on the regions.
*/
typedef enum {
/**
* - ISM EU863-870: LoRa modulation, SF12, BW125 (250bit/s)
* - ISM US902-928: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM CN779-787: LoRa modulation, SF12, BW125 (250bit/s)
* - ISM EU433: LoRa modulation, SF12, BW125 (250bit/s)
* - ISM AU915-928: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM CN470-510: LoRa modulation, SF12, BW125 (250bit/s)
* - ISM AS923: LoRa modulation, SF12, BW125 (250bit/s)
* - ISM KR920-923: LoRa modulation, SF12, BW125 (250bit/s)
*
* Default value used.
*/
LORAMAC_DR_0 = 0,
/**
* - ISM EU863-870: LoRa modulation, SF11, BW125 (440bit/s)
* - ISM US902-928: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM CN779-787: LoRa modulation, SF11, BW125 (440bit/s)
* - ISM EU433: LoRa modulation, SF11, BW125 (440bit/s)
* - ISM AU915-928: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM CN470-510: LoRa modulation, SF11, BW125 (440bit/s)
* - ISM AS923: LoRa modulation, SF11, BW125 (440bit/s)
* - ISM KR920-923: LoRa modulation, SF11, BW125 (440bit/s)
*/
LORAMAC_DR_1,
/**
* - ISM EU863-870: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM US902-928: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM CN779-787: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM EU433: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM AU915-928: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM CN470-510: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM AS923: LoRa modulation, SF10, BW125 (980bit/s)
* - ISM KR920-923: LoRa modulation, SF10, BW125 (980bit/s)
*/
LORAMAC_DR_2,
/**
* - ISM EU863-870: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM US902-928: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM CN779-787: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM EU433: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM AU915-928: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM CN470-510: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM AS923: LoRa modulation, SF9, BW125 (1760bit/s)
* - ISM KR920-923: LoRa modulation, SF9, BW125 (1760bit/s)
*/
LORAMAC_DR_3,
/**
* - ISM EU863-870: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM US902-928: LoRa modulation, SF8, BW500 (12500bit/s)
* - ISM CN779-787: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM EU433: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM AU915-928: LoRa modulation, SF8, BW500 (12500bit/s)
* - ISM CN470-510: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM AS923: LoRa modulation, SF8, BW125 (3125bit/s)
* - ISM KR920-923: LoRa modulation, SF8, BW125 (3125bit/s)
*/
LORAMAC_DR_4,
/**
* - ISM EU863-870: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM US902-928: reserved for future use
* - ISM CN779-787: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM EU433: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM AU915-928: reserved for future use
* - ISM CN470-510: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM AS923: LoRa modulation, SF7, BW125 (5470bit/s)
* - ISM KR920-923: LoRa modulation, SF7, BW125 (5470bit/s)
*/
LORAMAC_DR_5,
/**
* - ISM EU863-870: LoRa modulation, SF7, BW250 (11000bit/s)
* - ISM US902-928: reserved for future use
* - ISM CN779-787: LoRa modulation, SF7, BW250 (11000bit/s)
* - ISM EU433 : LoRa modulation, SF7, BW250 (11000bit/s)
* - ISM AU915-928: reserved for future use
* - ISM CN470-510: reserved for future use
* - ISM AS923: LoRa modulation, SF7, BW250 (11000bit/s)
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_6,
/**
* - ISM EU863-870: FSK modulation (50000bit/s)
* - ISM US902-928: reserved for future use
* - ISM CN779-787: FSK modulation (50000bit/s)
* - ISM EU433: FSK modulation (50000bit/s)
* - ISM AU915-928: reserved for future use
* - ISM CN470-510: reserved for future use
* - ISM AS923: FSK modulation (50000bit/s)
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_7,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF12, BW500 (980bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF12, BW500 (980bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_8,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF11, BW500 (1760bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF11, BW500 (1760bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_9,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF10, BW500 (3900bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF10, BW500 (3900bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_10,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF9, BW500 (7000bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF9, BW500 (7000bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_11,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF8, BW500 (12500bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF8, BW500 (12500bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_12,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: LoRa modulation, SF7, BW500 (21900bit/s)
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: LoRa modulation, SF7, BW500 (21900bit/s)
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_13,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: reserved for future use
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: reserved for future use
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_14,
/**
* - ISM EU863-870: reserved for future use
* - ISM US902-928: reserved for future use
* - ISM CN779-787: reserved for future use
* - ISM EU433: reserved for future use
* - ISM AU915-928: reserved for future use
* - ISM CN470-510: reserved for future use
* - ISM AS923: reserved for future use
* - ISM KR920-923: reserved for future use
*/
LORAMAC_DR_15,
} loramac_dr_idx_t;
/**
* @brief LoRaMAC transmission power indexes
*
* Each index corresponds to a different modulation, spreading factor
* and bandwidth depending on the regions.
*/
typedef enum {
/**
* - EU863-870: 20dBm (if supported)
* - US902-928: 30dBm (if supported)
* - CN779-787: 10dBm
* - EU433: 10dBm
* - AU915-928: 30dBm
* - CN470-510: 17dBm
* - ISM AS923: 14dBm
* - ISM KR920-923: 20dBm
*/
LORAMAC_TX_PWR_0 = 0,
/**
* - EU863-870: 14dBm
* - US902-928: 28dBm
* - CN779-787: 7dBm
* - EU433: 7dBm
* - AU915-928: 28dBm
* - CN470-510: 16dBm
* - ISM AS923: 12dBm
* - ISM KR920-923: 14dBm
*
* Default value used
*/
LORAMAC_TX_PWR_1,
/**
* - EU863-870: 11dBm
* - US902-928: 26dBm
* - CN779-787: 4dBm
* - EU433: 4dBm
* - AU915-928: 26dBm
* - CN470-510: 14dBm
* - ISM AS923: 10dBm
* - ISM KR920-923: 10dBm
*/
LORAMAC_TX_PWR_2,
/**
* - EU863-870: 8dBm
* - US902-928: 24dBm
* - CN779-787: 1dBm
* - EU433: 1dBm
* - AU915-928: 24dBm
* - CN470-510: 12dBm
* - ISM AS923: 8dBm
* - ISM KR920-923: 8dBm
*/
LORAMAC_TX_PWR_3,
/**
* - EU863-870: 5dBm
* - US902-928: 22dBm
* - CN779-787: -2dBm
* - EU433: -2dBm
* - AU915-928: 22dBm
* - CN470-510: 10dBm
* - ISM AS923: 6dBm
* - ISM KR920-923: 5dBm
*/
LORAMAC_TX_PWR_4,
/**
* - EU863-870: 2dBm
* - US902-928: 20dBm
* - CN779-787: -5dBm
* - EU433: -5dBm
* - AU915-928: 20dBm
* - CN470-510: 7dBm
* - ISM AS923: 4dBm
* - ISM KR920-923: 2dBm
*/
LORAMAC_TX_PWR_5,
/**
* - EU863-870: Reserved for future use
* - US902-928: 18dBm
* - CN779-787: Reserved for future use
* - EU433: Reserved for future use
* - AU915-928: 18dBm
* - CN470-510: 5dBm
* - ISM AS923: Reserved for future use
* - ISM KR920-923: 0dBm
*/
LORAMAC_TX_PWR_6,
/**
* - EU863-870: Reserved for future use
* - US902-928: 16dBm
* - CN779-787: Reserved for future use
* - EU433: Reserved for future use
* - AU915-928: 16dBm
* - CN470-510: 2dBm
* - ISM AS923: Reserved for future use
* - ISM KR920-923: Reserved for future use
*/
LORAMAC_TX_PWR_7,
/**
* - EU863-870: Reserved for future use
* - US902-928: 14dBm
* - CN779-787: Reserved for future use
* - EU433: Reserved for future use
* - AU915-928: 14dBm
* - CN470-510: Reserved for future use
* - ISM AS923: Reserved for future use
* - ISM KR920-923: Reserved for future use
*/
LORAMAC_TX_PWR_8,
/**
* - EU863-870: Reserved for future use
* - US902-928: 12dBm
* - CN779-787: Reserved for future use
* - EU433: Reserved for future use
* - AU915-928: 12dBm
* - CN470-510: Reserved for future use
* - ISM AS923: Reserved for future use
* - ISM KR920-923: Reserved for future use
*/
LORAMAC_TX_PWR_9,
/**
* - EU863-870: Reserved for future use
* - US902-928: 10dBm
* - CN779-787: Reserved for future use
* - EU433: Reserved for future use
* - AU915-928: 10dBm
* - CN470-510: Reserved for future use
* - ISM AS923: Reserved for future use
* - ISM KR920-923: Reserved for future use
*/