pamoja_lorawan/defaults.rs
1//! The timing and counting defaults every region shares.
2//!
3//! The link layer specification names these and leaves their values to the regional
4//! parameters, and RP002-1.0.5 section 3.3 gives one set recommended for all regions. A
5//! device that uses different ones has to tell its network out of band when it is
6//! commissioned, so these are the values both sides assume unless told otherwise.
7//!
8//! Times are in microseconds, the unit a link's airtime is counted in.
9
10/// The delay from the end of an uplink to the opening of the first receive window.
11pub const RECEIVE_DELAY1_US: u32 = 1_000_000;
12
13/// The delay to the second receive window, which RP002-1.0.5 fixes at one second after the
14/// first.
15pub const RECEIVE_DELAY2_US: u32 = RECEIVE_DELAY1_US + 1_000_000;
16
17/// The delay from the end of a join request to the first window a join accept may arrive
18/// in.
19pub const JOIN_ACCEPT_DELAY1_US: u32 = 5_000_000;
20
21/// The delay to the second join accept window.
22pub const JOIN_ACCEPT_DELAY2_US: u32 = 6_000_000;
23
24/// How far either side of the nominal opening a receive window may start.
25///
26/// LoRaWAN 1.0.3 section 3.3.1 opens each window within 20 microseconds of its delay.
27pub const RECEIVE_WINDOW_TOLERANCE_US: u32 = 20;
28
29/// How far ahead of the last counter it accepted a receiver follows a sender.
30///
31/// RP002-1.0.5 lists it for LoRaWAN 1.0.3 and earlier and notes it was removed from 1.0.4.
32/// A frame further ahead than this is refused, which is what stops a captured frame being
33/// replayed at a counter the sender has not reached yet.
34pub const MAX_FCNT_GAP: u32 = 16_384;
35
36/// How many uplinks go unanswered before a device asks the network to say something.
37pub const ADR_ACK_LIMIT: u32 = 64;
38
39/// How many more go unanswered before a device steps its data rate down, and between each
40/// step after that.
41pub const ADR_ACK_DELAY: u32 = 32;
42
43/// The shortest wait before a confirmed uplink with no acknowledgment is sent again.
44///
45/// RP002-1.0.5 gives the timeout as two seconds either way of one, drawn at random, so two
46/// devices that missed the same answer do not retry into each other.
47pub const RETRANSMIT_TIMEOUT_MIN_US: u32 = 1_000_000;
48
49/// The longest wait before that retry.
50pub const RETRANSMIT_TIMEOUT_MAX_US: u32 = 3_000_000;
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn the_values_are_the_ones_the_regional_parameters_print() {
58 // RP002-1.0.5 section 3.3, Default Settings: RECEIVE_DELAY1 1s, RECEIVE_DELAY2 2s
59 // (RECEIVE_DELAY1 + 1s), JOIN_ACCEPT_DELAY1 5s, JOIN_ACCEPT_DELAY2 6s, MAX_FCNT_GAP
60 // 16384, ADR_ACK_LIMIT 64, ADR_ACK_DELAY 32, RETRANSMIT_TIMEOUT 2s +/- 1s.
61 assert_eq!(RECEIVE_DELAY1_US, 1_000_000);
62 assert_eq!(RECEIVE_DELAY2_US, 2_000_000);
63 assert_eq!(JOIN_ACCEPT_DELAY1_US, 5_000_000);
64 assert_eq!(JOIN_ACCEPT_DELAY2_US, 6_000_000);
65 assert_eq!(MAX_FCNT_GAP, 16_384);
66 assert_eq!(ADR_ACK_LIMIT, 64);
67 assert_eq!(ADR_ACK_DELAY, 32);
68 assert_eq!(RETRANSMIT_TIMEOUT_MIN_US, 1_000_000);
69 assert_eq!(RETRANSMIT_TIMEOUT_MAX_US, 3_000_000);
70
71 // LoRaWAN 1.0.3 section 3.3.1: +/- 20 microseconds.
72 assert_eq!(RECEIVE_WINDOW_TOLERANCE_US, 20);
73 }
74}