Class LorawanSession
An activated LoRaWAN session: a device address and its two session keys.
public sealed class LorawanSession : IDisposable
- Inheritance
-
LorawanSession
- Implements
- Inherited Members
Remarks
A long-range public-band link is wide open, so LoRaWAN wraps every frame in two guarantees: 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. The keys are held natively and never come back out.
Constructors
LorawanSession(uint, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Creates a session from a device address and its two session keys.
public LorawanSession(uint devAddr, ReadOnlySpan<byte> nwkSKey, ReadOnlySpan<byte> appSKey)
Parameters
devAddruintThe device address the network assigned.
nwkSKeyReadOnlySpan<byte>The 16-byte network session key, which authenticates frames.
appSKeyReadOnlySpan<byte>The 16-byte application session key, which encrypts payloads.
Exceptions
- PamojaException
Either key is not 16 bytes.
Properties
DevAddr
The device address this session is bound to.
public uint DevAddr { get; }
Property Value
Methods
Decode(ReadOnlySpan<byte>, uint)
Verifies a received frame, then decrypts it.
public LorawanRxData Decode(ReadOnlySpan<byte> bytes, uint fcnt)
Parameters
bytesReadOnlySpan<byte>The frame exactly as it came off the radio.
fcntuintThe full 32-bit counter expected for this frame; its low 16 bits must match the counter the frame carries.
Returns
- LorawanRxData
The decoded frame.
Exceptions
- PamojaException
The MIC does not verify, the counter does not match, or the frame is not a data frame.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
EncodeDownlink(uint, byte, ReadOnlySpan<byte>, LorawanOptions?)
Encodes a downlink, encrypting the payload and appending the MIC.
public byte[] EncodeDownlink(uint fcnt, byte fport, ReadOnlySpan<byte> payload, LorawanOptions? options = null)
Parameters
fcntuintThe frame counter for this downlink.
fportbyteThe port; 0 for MAC commands, otherwise an application port.
payloadReadOnlySpan<byte>The application payload to carry.
optionsLorawanOptionsThe header flags and frame options to set.
Returns
- byte[]
The frame to transmit.
Exceptions
- PamojaException
The payload and options do not fit a single frame.
EncodeUplink(uint, byte, ReadOnlySpan<byte>, LorawanOptions?)
Encodes an uplink, encrypting the payload and appending the MIC.
public byte[] EncodeUplink(uint fcnt, byte fport, ReadOnlySpan<byte> payload, LorawanOptions? options = null)
Parameters
fcntuintThe frame counter for this uplink.
fportbyteThe port; 0 for MAC commands, otherwise an application port.
payloadReadOnlySpan<byte>The application payload to carry.
optionsLorawanOptionsThe header flags and frame options to set.
Returns
- byte[]
The frame to transmit.
Exceptions
- PamojaException
The payload and options do not fit a single frame.