[][src]Struct ieee802154::mac::frame::header::Header

pub struct Header {
    pub frame_type: FrameType,
    pub security: Security,
    pub frame_pending: bool,
    pub ack_request: bool,
    pub pan_id_compress: bool,
    pub version: FrameVersion,
    pub seq: u8,
    pub destination: Option<Address>,
    pub source: Option<Address>,
}

MAC frame header

External documentation for MAC frame format start at 5.2

Fields

frame_type: FrameType

Frame Type

security: Security

Auxiliary Security header

frame_pending: bool

Frame Pending

The Frame Pending field shall be set to true if the device sending the frame has more data for the recipient,as described in 5.1.6.3. This field shall be set to false otherwise.

ack_request: bool

Acknowledgement Request

The AR field specifies whether an acknowledgment is required from the recipient device on receipt of a data or MAC command frame. If this field is set to true, the recipient device shall send an acknowledgment frame only if, upon reception, the frame passes the filtering described in 5.1.6.2. If this field is set to false, the recipient device shall not send an acknowledgment frame.

pan_id_compress: bool

PAN ID Compress

The PAN ID Compression field specifies whether the MAC frame is to be sent containing only one of the PAN identifier fields when both src and destination addresses are present. If this field is set to true and both the src and destination addresses are present, the frame shall contain only the Destination PAN Identifier field, and the Source PAN Identifier field shall be assumed equal to that of the destination. If this field is set to false, then the PAN Identifier field shall be present if and only if the corresponding address is present.

version: FrameVersion

Frame version

seq: u8

Sequence Number

destination: Option<Address>

Destination Address

source: Option<Address>

Source Address

Implementations

impl Header[src]

pub fn decode(buf: &mut dyn Buf) -> Result<Self, DecodeError>[src]

Decodes a mac header from a byte buffer.

This method is used by Frame::decode to decode the mac header. Unless you decide to write your own code for decoding frames, there should be no reason to call this method directly.

Errors

This function returns an error, if the bytes either don't encode a valid IEEE 802.15.4 frame header, or encode a frame header that is not fully supported by this implementation. Please refer to DecodeError for details.

Example

use ieee802154::mac::{
    Address,
    ShortAddress,
    FrameType,
    Header,
    PanId,
    Security,
};

// Construct a simple header.
let mut bytes = &[
    0x01, 0x98,             // frame control
    0x00,                   // sequence number
    0x12, 0x34, 0x56, 0x78, // PAN identifier and address of destination
    0x12, 0x34, 0x9a, 0xbc, // PAN identifier and address of source
][..];

let header = Header::decode(&mut bytes)?;

assert_eq!(header.frame_type,      FrameType::Data);
assert_eq!(header.security,        Security::None);
assert_eq!(header.frame_pending,   false);
assert_eq!(header.ack_request,     false);
assert_eq!(header.pan_id_compress, false);
assert_eq!(header.seq,             0x00);

assert_eq!(
    header.destination,
    Some(Address::Short(PanId(0x3412), ShortAddress(0x7856)))
);
assert_eq!(
    header.source,
    Some(Address::Short(PanId(0x3412), ShortAddress(0xbc9a)))
);

pub fn encode(&self, buf: &mut dyn BufMut)[src]

Encodes the header into a buffer

The header length depends on the options chosen and varies between 3 and 30 octets.

Example

use bytes::BytesMut;
use ieee802154::mac::{
    Address,
    AddressMode,
    ShortAddress,
    FrameType,
    FrameVersion,
    Header,
    PanId,
    Security,
};

let header = Header {
    frame_type:      FrameType::Data,
    security:        Security::None,
    frame_pending:   false,
    ack_request:     false,
    pan_id_compress: false,
    version:         FrameVersion::Ieee802154_2006,
    seq:             0x00,

    destination: Some(Address::Short(PanId(0x1234), ShortAddress(0x5678))),
    source:      Some(Address::Short(PanId(0x1234), ShortAddress(0x9abc))),
};

let mut bytes = BytesMut::with_capacity(11);

header.encode(&mut bytes);
let encoded_bytes = bytes.split().freeze();

let expected_bytes = [
    0x01, 0x98,             // frame control
    0x00,                   // sequence number
    0x34, 0x12, 0x78, 0x56, // PAN identifier and address of destination
    0x34, 0x12, 0xbc, 0x9a, // PAN identifier and address of source
];
assert_eq!(encoded_bytes, expected_bytes[..]);

Trait Implementations

impl Clone for Header[src]

impl Copy for Header[src]

impl Debug for Header[src]

impl Eq for Header[src]

impl Hash for Header[src]

impl PartialEq<Header> for Header[src]

impl StructuralEq for Header[src]

impl StructuralPartialEq for Header[src]

Auto Trait Implementations

impl Send for Header

impl Sync for Header

impl Unpin for Header

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.