pub struct Network { /* private fields */ }Expand description
The network side of one site.
It admits the devices it is told about, grants sessions, follows frame counters, and
decides where an answer goes. Everything it needs about the band comes from the
[ChannelPlan] it is built with, so the same type serves any region.
Implementations§
Source§impl Network
impl Network
Sourcepub fn new(plan: &ChannelPlan<'_>, net_id: u32) -> Network
pub fn new(plan: &ChannelPlan<'_>, net_id: u32) -> Network
Builds a network on a channel plan.
The plan is copied into the network, so one holds its band for as long as it runs rather than borrowing a table that lives somewhere else.
§Arguments
plan- the band this site operates in.net_id- the network identifier granted addresses carry; only its low 24 bits travel.
§Returns
The network, with the recommended windows and no devices registered.
Sourcepub fn with_windows(self, windows: Windows) -> Network
pub fn with_windows(self, windows: Windows) -> Network
Sourcepub fn with_first_dev_addr(self, dev_addr: u32) -> Network
pub fn with_first_dev_addr(self, dev_addr: u32) -> Network
Sourcepub fn register(&mut self, registration: Registration)
pub fn register(&mut self, registration: Registration)
Admits a device, so a join request signed with its key is accepted.
§Arguments
registration- the device and its root key.
Sourcepub fn uplink(&mut self, heard: &Rxpk) -> Result<Event, NetworkError>
pub fn uplink(&mut self, heard: &Rxpk) -> Result<Event, NetworkError>
Reads a packet the gateway forwarded.
A join request is verified against every registered key, granted an address and a session, and answered with an accept timed for the join window. A data frame is routed by its address, checked against the counter last seen, and decrypted. A frame for an address this network has not granted is reported rather than refused, because a gateway hears every network in range.
§Arguments
heard- the packet as the gateway reported it.
§Returns
What the packet turned out to be.
§Errors
Returns NetworkError::NotLora for an FSK packet, NetworkError::Frame if the
frame does not parse or its MIC does not verify, NetworkError::UnknownDevice if
no registered key verifies a join request, NetworkError::Replayed or
NetworkError::CounterGap if the counter is not one this network will follow, and
NetworkError::UnknownDataRate or NetworkError::NoWindow if the plan does not
describe where to answer.
Sourcepub fn answer(
&mut self,
dev_addr: u32,
slot: Slot,
fport: u8,
payload: &[u8],
) -> Result<Txpk, NetworkError>
pub fn answer( &mut self, dev_addr: u32, slot: Slot, fport: u8, payload: &[u8], ) -> Result<Txpk, NetworkError>
Builds a downlink for a device, encrypted with its session.
§Arguments
dev_addr- the device to answer.slot- where and when to transmit, from the event that reported the uplink.fport- the port to answer on.payload- what to send.
§Returns
The packet to put in a PULL_RESP, with the inverted polarity a device listens for.
§Errors
Returns NetworkError::NoSession if no device holds that address here, or
NetworkError::Frame if the payload does not fit a single frame.
Sourcepub fn command(
&mut self,
dev_addr: u32,
slot: Slot,
commands: &[MacCommand],
) -> Result<Txpk, NetworkError>
pub fn command( &mut self, dev_addr: u32, slot: Slot, commands: &[MacCommand], ) -> Result<Txpk, NetworkError>
Builds a downlink carrying MAC commands, which is how a network configures a relay, TS011-1.0.1 chapter 10.
The commands ride in the frame options where they fit, and in a frame of their own on port 0 where they do not.
§Arguments
dev_addr- the device to send to, a relay for the relay commands.slot- where and when to transmit, from the event that reported its uplink.commands- the commands, in the order they should be read.
§Returns
The packet to put in a PULL_RESP.
§Errors
Returns NetworkError::NoSession if no device holds that address here, and
NetworkError::Frame if the commands do not fit one frame.
Sourcepub fn trust_command(
&self,
dev_addr: u32,
index: u8,
reload_rate: u8,
bucket_size: u8,
) -> Result<MacCommand, NetworkError>
pub fn trust_command( &self, dev_addr: u32, index: u8, reload_rate: u8, bucket_size: u8, ) -> Result<MacCommand, NetworkError>
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.
§Arguments
dev_addr- the end device to trust.index- which of the relay’s sixteen entries to put it in.reload_rate- how many of its uplinks the relay forwards an hour, 63 for no limit.bucket_size- the coded bucket size multiplier, table 55.
§Returns
The UpdateUplinkListReq to send to the relay with command.
§Errors
Returns NetworkError::NoSession if no device holds that address here.
Sourcepub fn notices(&mut self) -> Vec<Notice>
pub fn notices(&mut self) -> Vec<Notice>
Takes the devices relays have reported hearing and could not verify, TS011-1.0.1 section 10.7.
A relay carries these in the MAC commands of its own uplinks, alongside whatever else that uplink was for, so they wait here until they are read.
§Returns
Every notice since the last call, in the order they arrived.
Sourcepub fn notice_count(&self) -> usize
pub fn notice_count(&self) -> usize
Counts the notices waiting to be read, without taking them.
§Returns
How many Notices the next call to Network::notices would return.