pub struct JoinAccept {
pub join_nonce: AppNonce,
pub net_id: NetId,
pub dev_addr: DevAddr,
pub dl_settings: DlSettings,
pub rx_delay: u8,
pub cf_list: Option<[u8; 16]>,
pub join_req_type: Option<u8>,
}Expand description
Fields of a Join Accept (plaintext, after decrypt).
On the wire, the body of a Join Accept is AES-ECB encrypted. Use
JoinAccept::decrypt_from_wire to turn wire bytes into this struct,
or JoinAccept::encrypt_for_wire to go the other direction (server
side).
Fields§
§join_nonce: AppNonceServer-generated random nonce (AppNonce in 1.0, JoinNonce in 1.1).
net_id: NetIdNetwork ID.
dev_addr: DevAddrDevAddr assigned to the device.
dl_settings: DlSettingsDownlink settings (RX1 offset, RX2 data rate, OptNeg).
rx_delay: u8RX1 delay, in seconds.
cf_list: Option<[u8; 16]>Optional Channel-Frequency List (16 bytes); only present in some regional plans.
join_req_type: Option<u8>1.1 only: JoinReqType byte threaded into the 1.1 Join Accept MIC.
None on parsed packets; set explicitly when re-signing a 1.1 frame.
Implementations§
Source§impl JoinAccept
impl JoinAccept
Sourcepub fn from_plaintext(bytes: &[u8]) -> Result<Self>
pub fn from_plaintext(bytes: &[u8]) -> Result<Self>
Parse an already-decrypted Join Accept (MHDR + body + MIC).
Most callers start with encrypted wire bytes; use
JoinAccept::decrypt_from_wire to decrypt first, then pass the
resulting plaintext bytes here.
Accepts both single-block (17 bytes total) and CFList (33 bytes
total) Join Accept formats.
§Errors
crate::Error::TooShort if the total length is below 17 or the body
length is neither 12 (no CFList) nor 28 bytes (with CFList).
Source§impl JoinAccept
impl JoinAccept
Sourcepub fn decrypt_from_wire(ciphertext: &[u8], app_key: &AppKey) -> Result<Vec<u8>>
pub fn decrypt_from_wire(ciphertext: &[u8], app_key: &AppKey) -> Result<Vec<u8>>
Decrypt a wire-format Join Accept (MHDR + ciphertext body + MIC) on
the device side.
LoRaWAN Join Accept uses an unusual trick: the server applies
AES-ECB-decrypt to the body so that the device can use only the
AES-ECB-encrypt primitive (smaller code on constrained MCUs). This
helper inverts that: encrypt on the device side gives back the
plaintext bytes.
The MHDR (first byte) passes through unchanged. The total length
must be 17 (one block, no CFList) or 33 (two blocks, with CFList).
§Errors
crate::Error::InvalidJoinAcceptLength when the total length is
outside {17, 33}.
§Examples
use lora_packet::{JoinAccept, AppKey};
let app_key = AppKey::new([0u8; 16]);
let encrypted = hex::decode("20e3de108795f776b8037610ef7869b5b3")?;
let plaintext = JoinAccept::decrypt_from_wire(&encrypted, &app_key)?;
// plaintext is now MHDR || JoinAcceptBody || MIC
assert_eq!(plaintext.len(), 17);Sourcepub fn encrypt_for_wire(plaintext: &[u8], app_key: &AppKey) -> Result<Vec<u8>>
pub fn encrypt_for_wire(plaintext: &[u8], app_key: &AppKey) -> Result<Vec<u8>>
Encrypt a plaintext Join Accept on the server side.
Applies AES-ECB-decrypt to the body (the inverse of what
Self::decrypt_from_wire does on the device). The MHDR is left
as-is. Use when assembling a Join Accept to send to a device.
The total length must be 17 (one block) or 33 (two blocks).
§Errors
crate::Error::InvalidJoinAcceptLength when the total length is
outside {17, 33}.
Trait Implementations§
Source§impl Clone for JoinAccept
impl Clone for JoinAccept
Source§fn clone(&self) -> JoinAccept
fn clone(&self) -> JoinAccept
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JoinAccept
impl Debug for JoinAccept
Source§impl<'de> Deserialize<'de> for JoinAccept
impl<'de> Deserialize<'de> for JoinAccept
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for JoinAccept
impl PartialEq for JoinAccept
Source§fn eq(&self, other: &JoinAccept) -> bool
fn eq(&self, other: &JoinAccept) -> bool
self and other values to be equal, and is used by ==.