Skip to main content

FrameHeader

Struct FrameHeader 

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

A frame read only as far as its unencrypted header.

§Examples

use pamoja_lorawan::{FrameHeader, MessageType, Session, Uplink};

let session = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
let frame = session.encode_uplink(&Uplink::new(42, 1, b"temp=4.8"))?;

// A gateway reads the address out of the frame to find the right session.
let header = FrameHeader::parse(frame.as_bytes())?;
assert_eq!(header.message_type(), MessageType::UnconfirmedUp);
assert_eq!(header.dev_addr(), Some(0x2601_1BDA));
assert_eq!(header.fcnt(), Some(42));
assert_eq!(header.fport(), Some(1));

// Only then can it verify and decrypt.
let rx = session.decode(frame.as_bytes(), 42)?;
assert_eq!(rx.payload(), b"temp=4.8");

Implementations§

Source§

impl FrameHeader

Source

pub fn parse(bytes: &[u8]) -> Result<FrameHeader, LorawanError>

Reads a frame far enough to route it, without any key.

§Arguments
  • bytes - the raw frame as it came off the radio.
§Returns

What the header says the frame is.

§Errors

Returns LorawanError::FrameTooShort if the frame is empty or shorter than the header and MIC a data frame needs, LorawanError::UnsupportedMType if the message type is one this crate does not read, or LorawanError::MalformedFrame if the frame options run past the end of the frame.

Source

pub fn message_type(&self) -> MessageType

Returns what kind of message the frame is.

§Returns

The message type.

Source

pub fn direction(&self) -> Option<Direction>

Returns the direction the frame travels.

§Returns

The direction, or None for a join-accept.

Source

pub fn dev_addr(&self) -> Option<u32>

Returns the device address the frame carries.

This is what a receiver looks a session up by.

§Returns

The address, or None for a join frame, which carries none.

Source

pub fn fcnt(&self) -> Option<u16>

Returns the low 16 bits of the frame counter.

§Returns

The counter, or None for a join frame.

Source

pub fn fport(&self) -> Option<u8>

Returns the port the frame was sent on.

§Returns

The port, or None for a join frame or a data frame carrying only frame options.

Source

pub fn confirmed(&self) -> bool

Reports whether the frame asks to be acknowledged.

§Returns

true for a confirmed data frame.

Source

pub fn adr(&self) -> bool

Reports whether the frame takes part in adaptive data rate.

§Returns

The ADR bit.

Source

pub fn ack(&self) -> bool

Reports whether the frame acknowledges the last confirmed one.

§Returns

The ACK bit.

Source

pub fn fpending(&self) -> bool

Reports whether the network has more downlink data waiting.

§Returns

The frame-pending bit.

Source

pub fn fopts_len(&self) -> usize

Returns how many bytes of frame options the header carries.

§Returns

The length, from 0 to 15.

Source

pub fn payload_len(&self) -> usize

Returns the length of the still-encrypted payload.

§Returns

The payload length in bytes, which is 0 when the frame carries only options.

Trait Implementations§

Source§

impl Clone for FrameHeader

Source§

fn clone(&self) -> FrameHeader

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 FrameHeader

Source§

impl Debug for FrameHeader

Source§

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

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

impl Eq for FrameHeader

Source§

impl PartialEq for FrameHeader

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FrameHeader

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.