Skip to main content

JoinAccept

Struct JoinAccept 

Source
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: AppNonce

Server-generated random nonce (AppNonce in 1.0, JoinNonce in 1.1).

§net_id: NetId

Network ID.

§dev_addr: DevAddr

DevAddr assigned to the device.

§dl_settings: DlSettings

Downlink settings (RX1 offset, RX2 data rate, OptNeg).

§rx_delay: u8

RX1 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

Source

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

Source

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);
Source

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

Source§

fn clone(&self) -> JoinAccept

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 Debug for JoinAccept

Source§

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

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

impl<'de> Deserialize<'de> for JoinAccept

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for JoinAccept

Source§

fn eq(&self, other: &JoinAccept) -> 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 Serialize for JoinAccept

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for JoinAccept

Source§

impl StructuralPartialEq for JoinAccept

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,