Expand description
A LoRaWAN relay, TS011-1.0.1: what an end device and a relay say to each other.
A relay is an end device that listens on behalf of others. It sleeps, waking every
CadPeriodicity to scan a channel for radio activity. An end device out of a gateway’s
reach first sends a wake-on-radio (WOR) frame with a preamble long enough to span that
sleep, which says where and how fast its LoRaWAN uplink will follow. The relay may answer
with a WOR ACK describing its own timing, so the next WOR frame can be short, then
listens for the uplink and forwards it to the network on port LA_FPORT_RELAY over its
own session. A downlink for the end device comes back the same way and goes out in the
device’s RXR window.
This module holds the frames and the arithmetic, sans IO like device:
WorKeys: the integrity and encryption keys an end device and a relay share, from the root keyroot_wor_s_keyderives out of the network session key, section 4.Wor: the two WOR frames,wor_join_requestandwor_uplink, section 5.3.wor_ackandopen_wor_ackwithStateSync: the acknowledgment, section 6.2.ForwardedUplink: an uplink a relay forwards and its metadata, section 9.1.Synchronization,unsynchronized_preamble_symbolsandt_offset_ms: how long a WOR preamble must be and when it goes out, section 5.2 and appendix 1.Relay: the relay itself, an end device that scans for those frames, answers them, forwards the uplinks behind them and sends the network’s answers on, chapters 3, 7 and 8. It keeps the tables its network configures, aJoinFilter, itsTrustedDevicesand itsForwardLimits, each usable on its own.
The relay commands a network configures both sides with are
MacCommand variants, and each region’s default WOR channels
are ChannelPlan::relay_channels.
§Examples
An end device wakes a relay, which checks the frame and acknowledges it:
use pamoja_lorawan::relay::{
open_wor_ack, wor_ack, wor_uplink, CadPeriodicity, CadToRx, Carrier, Forward, StateSync,
Wor, XtalAccuracy,
};
use pamoja_lorawan::Session;
let session = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
let keys = session.wor_keys();
let wor = Carrier::new(865_100_000, 3);
let ack = Carrier::new(865_300_000, 3);
let uplink = Carrier::new(868_100_000, 5);
// The end device says its next uplink goes out on 868.1 MHz at DR5.
let frame = wor_uplink(&keys, session.dev_addr(), 1, uplink, wor)?;
// The relay, holding the same keys, reads it back.
let Wor::Uplink(sealed) = Wor::parse(&frame)? else { unreachable!() };
assert_eq!(sealed.open(&keys, 1, wor)?, uplink);
// And tells the device how it scans.
let state = StateSync {
cad_to_rx: CadToRx::Symbols4,
forward: Forward::Available,
relay_data_rate: 5,
xtal_accuracy: XtalAccuracy::Ppm30,
cad_periodicity: CadPeriodicity::Ms500,
t_offset_ms: 892,
};
let answer = wor_ack(&keys, session.dev_addr(), 1, ack, uplink, state)?;
assert_eq!(open_wor_ack(&answer, &keys, session.dev_addr(), 1, ack, uplink)?, state);Structs§
- Acknowledgment
- A WOR ACK to send.
- Carrier
- Where a frame goes and how fast: a frequency and a data rate.
- Filter
Rule - One rule of a join request filter: the leading bytes of JoinEUI then DevEUI it matches, and what it does with a match.
- Forward
Limits - A relay’s four relay-wide limits, TS011-1.0.1 tables 23 and 24.
- Forwarded
Uplink - An end device’s uplink as a relay forwards it: the payload of a relay uplink on
LA_FPORT_RELAY. - Join
Filter - A relay’s join request filter: a default action and up to fifteen rules, decided by the longest prefix that matches, TS011-1.0.1 section 8.6.
- Listen
- When and where to listen for the uplink a wake-on-radio frame announced.
- Relay
- A LoRaWAN relay: an end device that scans for wake-on-radio frames, acknowledges and forwards the uplinks behind them, and sends the network’s answers on in each end device’s RXR window.
- Relay
Config - Which channels a relay scans and how often, as
RelayConfReqsets them, TS011-1.0.1 section 10.1. - Relay
Settings - What a relay’s radio can do, which every WOR ACK it sends reports.
- RxrDownlink
- A downlink for an end device, to send in its RXR window, TS011-1.0.1 chapter 7.
- Scan
- A scan for wake-on-radio frames, due next.
- Sealed
Wor - A wake-on-radio frame ahead of a Class A uplink, before its integrity code is checked.
- State
Sync - What a relay tells an end device about itself in a WOR ACK, TS011-1.0.1 table 14.
- Synchronization
- What an end device knows of a relay’s scans once a WOR ACK has arrived, TS011-1.0.1 section 3.9 and appendix 1.
- Token
Bucket - A token bucket: it earns a number of tokens an hour up to its size, and a relay spends one on each message it lets through.
- Trusted
Device - An end device a relay trusts: its keys, the WOR frame counter it expects next, and how much of it the relay forwards.
- Trusted
Devices - The end devices a relay trusts,
TRUSTED_ED_NUMBERof them, each at the index the network gave it. - Uplink
Metadata - What a relay heard of an uplink, TS011-1.0.1 table 27.
- WorKeys
- The integrity and encryption keys of one end device’s wake-on-radio frames.
- WorSlot
- When a synchronized end device’s next WOR frame goes out, and with how long a preamble.
Enums§
- CadPeriodicity
- How often a relay scans a channel for a wake-on-radio preamble, TS011-1.0.1 table 18.
- CadToRx
- How many symbols a relay takes from detecting activity to receiving, TS011-1.0.1 table 15.
- Counter
Reset - What
ConfigureFwdLimitReqdoes to the token counters, TS011-1.0.1 table 63. - Filter
Action - What a filter rule does with the join requests it matches, TS011-1.0.1 table 48.
- Forward
- Whether a relay will forward the uplink after a WOR frame, TS011-1.0.1 table 16.
- Relay
Activation - How an end device manages its relay mode, TS011-1.0.1 table 40.
- Relay
Error - Why a relay did not do what a frame or a call asked.
- Relay
Heard - What a frame a relay’s own device heard turned out to be.
- Relay
Sync - What an end device knows about when its relay listens, TS011-1.0.1 section 3.9.
- Wake
- What a wake-on-radio frame led a relay to do.
- Wor
- A wake-on-radio frame, as a relay reads it.
- WorChannel
- Which of a relay’s channels a WOR frame arrived on, TS011-1.0.1 table 28.
- Xtal
Accuracy - How accurate a relay’s crystal is, TS011-1.0.1 table 17.
Constants§
- FILTER_
RULES - How many rules a relay’s join request filter holds, rule 0 being the default, TS011-1.0.1 section 8.6.
- FORWARD_
OVERHEAD - The bytes
ForwardUplinkReqadds in front of the end device’s frame: three of metadata and three of frequency. - LA_
FPORT_ RELAY - The port every message between a relay and its network uses, TS011-1.0.1 section 9.
- MIN_
WOR_ PREAMBLE_ SYMBOLS - The shortest WOR preamble, in symbols, TS011-1.0.1 appendix 1.
- RELAY_
FWD_ DELAY_ US - The gap between a relay hearing an uplink and forwarding it, in microseconds.
- RELOAD_
PERIOD_ US - How often every bucket earns its reload rate, in microseconds: an hour.
- RXR_
DELAY_ US - How long after an uplink an end device’s RXR window opens at the latest, in microseconds.
- TRUSTED_
ED_ NUMBER - How many end devices a relay verifies wake-on-radio frames for, RP002-1.0.5 section 5.4.5.
- UNLIMITED_
DEVICE_ RATE - The reload rate a trusted end device’s bucket is coded with to mean no limit, TS011-1.0.1 table 54.
- UNLIMITED_
RELAY_ RATE - The reload rate a relay-wide bucket is coded with to mean no limit, TS011-1.0.1 table 64.
- WOR_
ACK_ DELAY_ US - The gap between a WOR frame and its acknowledgment, in microseconds.
- WOR_
ACK_ LEN - The length of a WOR ACK.
- WOR_
ATTEMPTS_ WO_ ACK - How many WOR frames an end device sends without an acknowledgment before its uplink goes out anyway, by default, RP002-1.0.5 section 5.4.5.
- WOR_
DATA_ DELAY_ US - The gap between a WOR frame, or its acknowledgment, and the LoRaWAN frame after it, in microseconds.
- WOR_
JOIN_ REQUEST_ LEN - The length of a WOR frame ahead of a join request: its header and five bytes.
- WOR_
UPLINK_ LEN - The length of a WOR frame ahead of a Class A uplink.
Functions§
- open_
wor_ ack - Checks and reads a WOR ACK, TS011-1.0.1 section 6.2.
- root_
wor_ s_ key - Derives the root relay session key of an end device, TS011-1.0.1 section 4.4.
- smart_
enable_ uplinks - How many uplinks may go unanswered before a device in
RelayActivation::Dynamicmode starts using a relay, TS011-1.0.1 table 41. - t_
offset_ ms - The milliseconds a relay reports from the start of its scan to the end of the WOR preamble, rounded up, TS011-1.0.1 appendix 1.
- unsynchronized_
preamble_ symbols - The preamble length of an end device that does not know when the relay scans, TS011-1.0.1 section 5.2.
- wor_ack
- Builds a relay’s WOR ACK, TS011-1.0.1 section 6.2.
- wor_
join_ request - Builds the wake-on-radio frame ahead of a join request, TS011-1.0.1 section 5.3.1.
- wor_
uplink - Builds the wake-on-radio frame ahead of a Class A uplink, TS011-1.0.1 section 5.3.2.