Table of Contents

Class LorawanSession

Namespace
Pamoja.Lorawan
Assembly
Pamoja.Lorawan.dll

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

devAddr uint

The device address the network assigned.

nwkSKey ReadOnlySpan<byte>

The 16-byte network session key, which authenticates frames.

appSKey ReadOnlySpan<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

uint

Methods

Decode(ReadOnlySpan<byte>, uint)

Verifies a received frame, then decrypts it.

public LorawanRxData Decode(ReadOnlySpan<byte> bytes, uint fcnt)

Parameters

bytes ReadOnlySpan<byte>

The frame exactly as it came off the radio.

fcnt uint

The 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()

Encodes a downlink, encrypting the payload and appending the MIC.

public byte[] EncodeDownlink(uint fcnt, byte fport, ReadOnlySpan<byte> payload, LorawanOptions? options = null)

Parameters

fcnt uint

The frame counter for this downlink.

fport byte

The port; 0 for MAC commands, otherwise an application port.

payload ReadOnlySpan<byte>

The application payload to carry.

options LorawanOptions

The 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.

Encodes an uplink, encrypting the payload and appending the MIC.

public byte[] EncodeUplink(uint fcnt, byte fport, ReadOnlySpan<byte> payload, LorawanOptions? options = null)

Parameters

fcnt uint

The frame counter for this uplink.

fport byte

The port; 0 for MAC commands, otherwise an application port.

payload ReadOnlySpan<byte>

The application payload to carry.

options LorawanOptions

The 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.