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
impl JoinGrant
Sourcepub fn new(app_nonce: u32, net_id: u32, dev_addr: u32) -> Self
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.
Sourcepub fn with_dl_settings(self, dl_settings: u8) -> Self
pub fn with_dl_settings(self, dl_settings: u8) -> Self
Sourcepub fn with_rx_delay(self, rx_delay: u8) -> Self
pub fn with_rx_delay(self, rx_delay: u8) -> Self
Sourcepub fn with_cflist(self, cflist: [u8; 16]) -> Self
pub fn with_cflist(self, cflist: [u8; 16]) -> Self
Sourcepub fn accept(&self, app_key: &[u8; 16], dev_nonce: u16) -> PhyPayload
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 matchingJoinRequestcarried.
§Returns
The join-accept frame, encrypted and with its MIC in place.
Sourcepub fn session(&self, app_key: &[u8; 16], dev_nonce: u16) -> Session
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 matchingJoinRequestcarried.
§Returns
The Session to secure this device’s traffic with.
Trait Implementations§
impl Copy for JoinGrant
impl Eq for JoinGrant
impl StructuralPartialEq for JoinGrant
Auto Trait Implementations§
impl Freeze for JoinGrant
impl RefUnwindSafe for JoinGrant
impl Send for JoinGrant
impl Sync for JoinGrant
impl Unpin for JoinGrant
impl UnsafeUnpin for JoinGrant
impl UnwindSafe for JoinGrant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more