Skip to main content

Network

Struct Network 

Source
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

Source

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.

Source

pub fn with_windows(self, windows: Windows) -> Network

Sets the windows this network answers in.

§Arguments
  • windows - the delays, offset, and channels.
§Returns

The updated network, for chaining.

Source

pub fn with_first_dev_addr(self, dev_addr: u32) -> Network

Sets the first address this network grants; later joins take the ones after it.

§Arguments
  • dev_addr - the address to grant next.
§Returns

The updated network, for chaining.

Source

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

pub const fn windows(&self) -> Windows

Returns the windows this network answers in.

§Returns

The windows.

Source

pub fn session(&self, dev_addr: u32) -> Option<Session>

Returns the session granted to an address, once a device has joined.

§Arguments
  • dev_addr - the address.
§Returns

The session, or None if no device holds that address here.

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.