Class GatewayNetwork
The network side of one site: what a server does with what a gateway forwarded.
public sealed class GatewayNetwork : IDisposable
- Inheritance
-
GatewayNetwork
- Implements
- Inherited Members
Remarks
A gateway forwards packets without reading them, because it holds no keys. This is the other half: it holds the devices it admits, the sessions it has granted and the counters it has seen, so a packet handed to it comes back as one of three things. A device joined and its accept is ready to transmit, a session frame arrived and was decrypted, or the frame belongs to a network this site never granted, which a gateway hears all the time and is not an error.
Constructors
GatewayNetwork(LoraChannelPlan, uint, GatewayNetworkWindows?, uint)
Opens the network side of a site on a channel plan.
public GatewayNetwork(LoraChannelPlan plan, uint netId, GatewayNetworkWindows? windows = null, uint firstDevAddr = 1)
Parameters
planLoraChannelPlanThe band this site operates in, which is copied into the network.
netIduintThe network identifier granted addresses carry.
windowsGatewayNetworkWindowsWhen and where to answer, or null for the recommended values.
firstDevAddruintThe first address to grant.
Exceptions
- PamojaException
The native core could not open a network.
Methods
Answer(uint, GatewaySlot, byte, ReadOnlySpan<byte>)
Builds a downlink for a device, encrypted with its session.
public GatewayTxpk Answer(uint devAddr, GatewaySlot slot, byte fport, ReadOnlySpan<byte> payload)
Parameters
devAddruintThe device to answer.
slotGatewaySlotWhere and when to transmit, from the event that reported the uplink.
fportbyteThe port to answer on.
payloadReadOnlySpan<byte>What to send.
Returns
- GatewayTxpk
The packet to put in a PULL_RESP.
Exceptions
- PamojaException
No session is held for the address.
Command(uint, GatewaySlot, IReadOnlyList<LorawanMacCommand>)
Builds a downlink carrying MAC commands, which is how a network configures a relay.
public GatewayTxpk Command(uint devAddr, GatewaySlot slot, IReadOnlyList<LorawanMacCommand> commands)
Parameters
devAddruintThe device to configure.
slotGatewaySlotWhere and when to transmit, from the event that reported its uplink.
commandsIReadOnlyList<LorawanMacCommand>The commands to send.
Returns
- GatewayTxpk
The packet to put in a PULL_RESP.
Remarks
The commands ride in the frame options where they fit, and in a frame of their own on port 0 where they do not.
Exceptions
- PamojaException
No session is held for the address, or a command is not one this build writes.
Dispose()
Releases the network.
public void Dispose()
Notices()
Takes the devices relays have reported hearing and could not verify.
public IReadOnlyList<GatewayNotice> Notices()
Returns
- IReadOnlyList<GatewayNotice>
Every notice since the last call, in the order they arrived.
Remarks
A relay carries these in the MAC commands of its own uplinks, TS011-1.0.1 section 10.7, alongside whatever else that uplink was for, so they wait here until they are read.
Register(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, LorawanVersion)
Admits a device, so a join request signed with its key is accepted.
public void Register(ReadOnlySpan<byte> devEui, ReadOnlySpan<byte> appEui, ReadOnlySpan<byte> appKey, LorawanVersion version = LorawanVersion.V1_0_4)
Parameters
devEuiReadOnlySpan<byte>The device identifier, eight bytes.
appEuiReadOnlySpan<byte>The application identifier, eight bytes.
appKeyReadOnlySpan<byte>The root key, sixteen bytes.
versionLorawanVersionThe link layer revision the device follows. A 1.0.3 device's frames are refused once their counter runs MAX_FCNT_GAP ahead of the last one accepted, which TS001-1.0.4 no longer asks.
Exceptions
- ArgumentException
An identifier or the key is the wrong length.
- ArgumentOutOfRangeException
versionis not one of the LorawanVersion values.
TrustCommand(uint, byte, byte, byte)
Builds the command that tells a relay to trust a device, with the key that lets it verify the device's wake-on-radio frames, TS011-1.0.1 section 10.4.
public LorawanMacCommand TrustCommand(uint devAddr, byte index, byte reloadRate = 63, byte bucketSize = 0)
Parameters
devAddruintThe device the relay should forward for.
indexbyteThe entry in the relay's list, 0 to 15.
reloadRatebyteHow many of its uplinks the relay forwards an hour, 63 for no limit.
bucketSizebyteThe coded bucket size multiplier, table 55.
Returns
- LorawanMacCommand
The command, to send with Command(uint, GatewaySlot, IReadOnlyList<LorawanMacCommand>).
Exceptions
- PamojaException
No session is held for the address.
Uplink(GatewayRxpk)
Reads a packet the gateway forwarded.
public GatewayNetworkEvent Uplink(GatewayRxpk heard)
Parameters
heardGatewayRxpkThe packet as the gateway reported it.
Returns
- GatewayNetworkEvent
What it turned out to be, and where its answer goes.
Exceptions
- PamojaException
The frame was refused, with the reason.