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.

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.