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.