Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

An end device’s root credentials for over-the-air activation.

Where a Session is the state of an already-activated device, a Device holds what it takes to activate: the device and application identifiers and the application root key. It builds the join_request a device broadcasts and turns the network’s reply into a ready Session with accept_join, deriving the session keys the spec prescribes.

The 8-byte identifiers are given most-significant byte first, as they are written; the join-request transmits them little-endian, as the spec requires.

Implementations§

Source§

impl Device

Source

pub fn new(dev_eui: [u8; 8], app_eui: [u8; 8], app_key: [u8; 16]) -> Self

Creates a device from its identifiers and application root key.

§Arguments
  • dev_eui - the device identifier, most-significant byte first.
  • app_eui - the application (join) identifier, most-significant byte first.
  • app_key - the application root key.
§Returns

The device.

Source

pub fn join_request(&self, dev_nonce: u16) -> PhyPayload

Builds a join-request to broadcast.

§Arguments
  • dev_nonce - a nonce the device must not reuse; keep it for the matching accept_join, which needs it to derive the keys.
§Returns

The join-request frame.

Source

pub fn accept_join( &self, bytes: &[u8], dev_nonce: u16, ) -> Result<JoinAccept, LorawanError>

Accepts a join-accept, deriving the activated session.

Decrypts the reply, verifies its MIC against the application root key, and derives the network and application session keys from the nonces it carries.

§Arguments
  • bytes - the raw join-accept as it came off the radio.
  • dev_nonce - the same nonce passed to the join_request this reply answers.
§Returns

The activation, including the ready-to-use Session.

§Errors

Returns LorawanError::FrameTooShort or LorawanError::MalformedFrame if the reply is not a valid join-accept shape, LorawanError::UnsupportedMType if it is not a join-accept, or LorawanError::MicMismatch if its MIC does not verify.

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.