Table of Contents

Class LorawanPackages

Namespace
Pamoja.Lorawan
Assembly
Pamoja.Lorawan.dll

The four LoRaWAN application layer packages: clock synchronization TS003-2.0.0, fragmented data block transport TS004-2.0.0, remote multicast setup TS005-2.0.0 and firmware management TS006-1.0.0.

public static class LorawanPackages
Inheritance
LorawanPackages
Inherited Members

Remarks

The key derivations and the parity matrix are functions of their arguments and live here. What has to remember something is a class: LorawanClockSync, LorawanFirmware, LorawanDefragmenter and LorawanBlockMic. One command of any of the four is LorawanPackageCommand.

Fields

ClockPort

The port clock synchronization is spoken on.

public const byte ClockPort = 202

Field Value

byte

FirmwarePort

The port firmware management is spoken on.

public const byte FirmwarePort = 203

Field Value

byte

FragmentPort

The port fragmented data block transport is spoken on.

public const byte FragmentPort = 201

Field Value

byte

MaxFragments

The most fragments one session carries.

public const ushort MaxFragments = 16383

Field Value

ushort

MulticastPort

The port remote multicast setup is spoken on.

public const byte MulticastPort = 200

Field Value

byte

Methods

DataBlockIntKey(ReadOnlySpan<byte>)

Derives the key that signs a data block, TS004-2.0.0 section 3.3.

public static byte[] DataBlockIntKey(ReadOnlySpan<byte> rootKey)

Parameters

rootKey ReadOnlySpan<byte>

The device's root key.

Returns

byte[]

The sixteen-byte DataBlockIntKey.

Exceptions

ArgumentException

The key was not sixteen bytes.

FragFragment(ReadOnlySpan<byte>, byte, ushort)

Builds one fragment of a session out of a block held whole.

public static byte[] FragFragment(ReadOnlySpan<byte> block, byte fragSize, ushort n)

Parameters

block ReadOnlySpan<byte>

The block, padding and all.

fragSize byte

How many bytes each fragment carries.

n ushort

Which fragment, counting from one.

Returns

byte[]

Its bytes.

Remarks

Up to the session's fragment count the fragment is a piece of the block; past that it is a coded fragment, the exclusive-or of a pseudo-random half of the pieces.

Exceptions

PamojaException

The fragment is not one of this session.

FragParityLine(ushort, ushort)

Lists the uncoded fragments one coded fragment is made of.

public static ushort[] FragParityLine(ushort coded, ushort nbFrag)

Parameters

coded ushort

Which coded fragment, counting from one past the uncoded ones.

nbFrag ushort

How many uncoded fragments the session carries.

Returns

ushort[]

The fragments it is the exclusive-or of, counting from zero.

Exceptions

PamojaException

The session is not one this build runs.

FragPrbs23(uint)

Steps the pseudo-random sequence the parity matrix is drawn from.

public static uint FragPrbs23(uint x)

Parameters

x uint

The current state.

Returns

uint

The next one.

FragSession(int, byte)

Says how many fragments a block takes, and how much padding the last one needs.

public static LorawanFragSession FragSession(int blockLen, byte fragSize)

Parameters

blockLen int

The block's length in bytes.

fragSize byte

How many bytes each fragment carries.

Returns

LorawanFragSession

The shape of the session.

Exceptions

PamojaException

The block does not fit a session this build runs.

McAppSKey(ReadOnlySpan<byte>, uint)

Derives the key that reads a multicast group's payloads.

public static byte[] McAppSKey(ReadOnlySpan<byte> mcKey, uint mcAddr)

Parameters

mcKey ReadOnlySpan<byte>

The group key.

mcAddr uint

The address the group answers to.

Returns

byte[]

The group's McAppSKey.

Exceptions

ArgumentException

The key was not sixteen bytes.

McKeKey(ReadOnlySpan<byte>)

Derives the key a multicast group's key travels under.

public static byte[] McKeKey(ReadOnlySpan<byte> mcRootKey)

Parameters

mcRootKey ReadOnlySpan<byte>

What McRootKey(ReadOnlySpan<byte>, bool) derived.

Returns

byte[]

The sixteen-byte McKEKey.

Exceptions

ArgumentException

The key was not sixteen bytes.

McKey(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Unwraps the group key a setup command carried.

public static byte[] McKey(ReadOnlySpan<byte> mcKeKey, ReadOnlySpan<byte> wrapped)

Parameters

mcKeKey ReadOnlySpan<byte>

What McKeKey(ReadOnlySpan<byte>) derived.

wrapped ReadOnlySpan<byte>

The wrapped key the command carried.

Returns

byte[]

The group key.

Exceptions

ArgumentException

Either value was not sixteen bytes.

McNwkSKey(ReadOnlySpan<byte>, uint)

Derives the key that verifies a multicast group's frames.

public static byte[] McNwkSKey(ReadOnlySpan<byte> mcKey, uint mcAddr)

Parameters

mcKey ReadOnlySpan<byte>

The group key.

mcAddr uint

The address the group answers to.

Returns

byte[]

The group's McNwkSKey.

Exceptions

ArgumentException

The key was not sixteen bytes.

McRootKey(ReadOnlySpan<byte>, bool)

Derives a device's multicast root key, TS005-2.0.0 section 4.3.

public static byte[] McRootKey(ReadOnlySpan<byte> rootKey, bool lorawan11 = false)

Parameters

rootKey ReadOnlySpan<byte>

The device's GenAppKey on 1.0.x, or its AppKey on 1.1.

lorawan11 bool

Whether to use the 1.1 scheme, which starts from another constant.

Returns

byte[]

The sixteen-byte McRootKey.

Exceptions

ArgumentException

The key was not sixteen bytes.

WrapMcKey(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Wraps a group key for a device, which is what a server does before sending it.

public static byte[] WrapMcKey(ReadOnlySpan<byte> mcKeKey, ReadOnlySpan<byte> mcKey)

Parameters

mcKeKey ReadOnlySpan<byte>

The device's key encryption key.

mcKey ReadOnlySpan<byte>

The group key to wrap.

Returns

byte[]

The wrapped key a setup command carries.

Exceptions

ArgumentException

Either key was not sixteen bytes.