Expand description
LoRaWAN 1.0.x MAC framing for the pamoja SDK.
LoRaWAN is how a low-power node reaches a network kilometres away over a license-free
radio, which is why it is the SDK’s first-class answer for rural and remote reach. The
pamoja-lora crate gives the link budget, the exact
time a transmission spends on air; this crate gives the bytes that go in it: the
secured LoRaWAN frame.
A LoRaWAN frame is not just a payload with an address. The standard wraps every frame in two cryptographic guarantees, because a long-range public-band link is wide open: a message integrity code keyed to the network proves the frame is authentic and intact, and the payload is encrypted to the application so only its owner can read it. This crate builds and verifies exactly that, with no radio and no allocation:
Session- an activated device’s address and session keys. It encodes an uplink or downlink data frame, encrypting the payload and appending the MIC, and decodes one received, verifying the MIC before decrypting.UplinkandDownlink- the data frame to send, built up from the fields a sender sets (confirmed, adaptive data rate, acknowledgement, frame options).RxData- a decoded frame: its header fields and its recovered payload.Device- the root credentials for over-the-air activation: it builds the join-request a device broadcasts and turns the network’s join-accept into a readySession, deriving the session keys the spec prescribes.JoinRequestandJoinGrant- the other half of that exchange, so a deployment can run its own network instead of joining someone else’s: verify the request a device sent, then grant it an address and sign the reply. Both sides derive the same session keys from the same nonces, with no key ever on the air.FrameHeader- what a frame says about itself before any key is involved: its message type, the device address, and the counter. A receiver holding many sessions reads this first to find the one a frame belongs to, then decodes.
The cryptography is the LoRaWAN construction over AES-128: an AES-CMAC MIC and an AES keystream for the payload, with the device address and frame counter folded into both so a frame cannot be lifted out of its place in the stream. Driving the radio arrives with the hardware-I/O layer; this is the secured-packet half ahead of it.
§Examples
use pamoja_lorawan::{Session, Uplink};
// A node activated with a device address and its two session keys.
let session = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
// Encode a confirmed uplink reading; the payload is encrypted and the MIC appended.
let frame = session
.encode_uplink(&Uplink::new(42, 1, b"temp=4.8").confirmed())
.unwrap();
// The network, holding the same session, verifies and decrypts it.
let rx = session.decode(frame.as_bytes(), 42).unwrap();
assert!(rx.confirmed());
assert_eq!(rx.payload(), b"temp=4.8");Structs§
- Device
- An end device’s root credentials for over-the-air activation.
- Downlink
- A downlink data frame to encode, built up from the fields a sender sets.
- Frame
Header - A frame read only as far as its unencrypted header.
- Join
Accept - A successful activation: the session to use, plus the network parameters the accept carried.
- Join
Grant - What a network grants a device that joined: an address, and the settings to answer on.
- Join
Request - A join-request a device broadcast, with its integrity already verified.
- PhyPayload
- An encoded LoRaWAN frame, the bytes that go on the air.
- RxData
- A decoded data frame, with its payload decrypted.
- Session
- An activated LoRaWAN session: a device address and the two session keys.
- Uplink
- An uplink data frame to encode, built up from the fields a sender sets.
Enums§
- Direction
- The direction a frame travels, which the MIC and the payload encryption both fold in.
- Lorawan
Error - What can go wrong building or reading a LoRaWAN frame.
- Message
Type - What kind of message a frame is, read from its header.
Constants§
- MAX_
FRAME - The largest PHYPayload, in bytes, this crate builds or accepts.
- MAX_
PAYLOAD - The largest application payload, in bytes, a single frame can carry (with no frame options present).