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
impl FrameHeader
Sourcepub fn parse(bytes: &[u8]) -> Result<FrameHeader, LorawanError>
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.
Sourcepub fn message_type(&self) -> MessageType
pub fn message_type(&self) -> MessageType
Sourcepub fn adr_ack_req(&self) -> bool
pub fn adr_ack_req(&self) -> bool
Reports whether an uplink asks the network to send something back.
§Returns
An uplink’s ADRACKReq bit, and false for any other frame, since a downlink has a
reserved bit in its place.
Sourcepub fn fpending(&self) -> bool
pub fn fpending(&self) -> bool
Reports whether the network has more downlink data waiting.
§Returns
A downlink’s FPending bit, and false for any other frame, since an uplink carries
its ClassB bit in that place.
Sourcepub fn class_b(&self) -> bool
pub fn class_b(&self) -> bool
Reports whether an uplink says its device has Class B enabled.
§Returns
An uplink’s ClassB bit, and false for any other frame.
Sourcepub fn payload_len(&self) -> usize
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
impl Clone for FrameHeader
Source§fn clone(&self) -> FrameHeader
fn clone(&self) -> FrameHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more