Skip to main content

JoinGrant

Struct JoinGrant 

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

What a network grants a device that joined: an address, and the settings to answer on.

Build one, then accept it into the frame to transmit and take the matching session to secure traffic with. Both sides derive the same keys from the same nonces, so the session here and the one the device computes agree without either sending a key.

§Examples

use pamoja_lorawan::{Device, JoinGrant, JoinRequest, Uplink};

const APP_KEY: [u8; 16] = [0xAB; 16];
let device = Device::new([0x11; 8], [0x22; 8], APP_KEY);
let request = JoinRequest::parse(device.join_request(0x1234).as_bytes(), &APP_KEY)?;

// The network assigns an address and replies.
let grant = JoinGrant::new(0x0003_0201, 0x0006_0504, 0x2601_1BDA);
let reply = grant.accept(&APP_KEY, request.dev_nonce());

// The device activates, and the two sessions agree.
let activated = device.accept_join(reply.as_bytes(), 0x1234)?;
assert_eq!(activated.dev_addr(), 0x2601_1BDA);

let uplink = activated.session().encode_uplink(&Uplink::new(1, 1, b"joined"))?;
let heard = grant.session(&APP_KEY, 0x1234).decode(uplink.as_bytes(), 1)?;
assert_eq!(heard.payload(), b"joined");

Implementations§

Source§

impl JoinGrant

Source

pub fn new(app_nonce: u32, net_id: u32, dev_addr: u32) -> Self

Creates a grant with no channel list and the default downlink settings.

§Arguments
  • app_nonce - a nonce this network must not reuse for the device, since the session keys are derived from it; only the low 24 bits are carried.
  • net_id - the network identifier; only the low 24 bits are carried.
  • dev_addr - the address to assign the device.
§Returns

The grant.

Source

pub fn with_dl_settings(self, dl_settings: u8) -> Self

Sets the downlink settings byte, which selects the downlink data rates.

§Arguments
  • dl_settings - the DLSettings byte.
§Returns

The updated grant, for chaining.

Source

pub fn with_rx_delay(self, rx_delay: u8) -> Self

Sets the delay, in seconds, before the first receive window.

§Arguments
  • rx_delay - the RxDelay value.
§Returns

The updated grant, for chaining.

Source

pub fn with_cflist(self, cflist: [u8; 16]) -> Self

Attaches the optional channel list, which tells the device where else to transmit.

§Arguments
  • cflist - the 16-byte CFList, whose meaning is regional.
§Returns

The updated grant, for chaining. The accept it builds is 33 bytes rather than 17.

Source

pub fn dev_addr(&self) -> u32

Returns the address this grant assigns.

§Returns

The device address.

Source

pub fn net_id(&self) -> u32

Returns the network identifier this grant carries.

§Returns

The NetID, in its low 24 bits.

Source

pub fn accept(&self, app_key: &[u8; 16], dev_nonce: u16) -> PhyPayload

Builds the signed join-accept to transmit.

§Arguments
  • app_key - the application root key the device shares with this network.
  • dev_nonce - the nonce the matching JoinRequest carried.
§Returns

The join-accept frame, encrypted and with its MIC in place.

Source

pub fn session(&self, app_key: &[u8; 16], dev_nonce: u16) -> Session

Derives the session this grant activates, the same one the device computes.

§Arguments
  • app_key - the application root key the device shares with this network.
  • dev_nonce - the nonce the matching JoinRequest carried.
§Returns

The Session to secure this device’s traffic with.

Trait Implementations§

Source§

impl Clone for JoinGrant

Source§

fn clone(&self) -> JoinGrant

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for JoinGrant

Source§

impl Debug for JoinGrant

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for JoinGrant

Source§

impl PartialEq for JoinGrant

Source§

fn eq(&self, other: &JoinGrant) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for JoinGrant

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.