dot15d4-frame 0.1.0

Frame parsing and building for the dot15d4 crate
Documentation

Zero-copy read and write structures for handling IEEE 802.15.4 MAC frames.

Each reader contains the following functions:

  • new: Create a new reader.
  • check_len: Check if the buffer is long enough to contain a valid frame.
  • new_unchecked: Create a new reader without checking the buffer length.

The most important reader is the [Frame] reader, which is used to read a full IEEE 802.15.4 frame. The reader provides the following functions:

Reading a frame

For an incoming frame, use the [Frame] structure to read its content.

# use dot15d4_frame::{
#   Frame,
#   FrameControl,
#   FrameType,
#   AddressingFields,
#   NestedInformationElementsIterator,
#   PayloadGroupId,
#   NestedSubId,
#   NestedSubIdShort,
#   TschTimeslot,
# };
# let frame: [u8; 35] = [
#     0x40, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
#     0x00, 0x3f, 0x11, 0x88, 0x06, 0x1a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c,
#     0x00, 0x01, 0xc8, 0x00, 0x01, 0x1b, 0x00,
# ];
let frame = Frame::new(&frame).unwrap();
let fc = frame.frame_control();
let src_addr = frame.addressing().unwrap().src_address();
let dst_addr = frame.addressing().unwrap().dst_address();

assert_eq!(fc.frame_type(), FrameType::Beacon);

let Some(ie) = frame.information_elements() else { return; };

for payload in ie.payload_information_elements() {
if matches!(payload.group_id(), PayloadGroupId::Mlme) {
for nested in payload.nested_information_elements() {
match nested.sub_id() {
NestedSubId::Short(NestedSubIdShort::TschTimeslot) => {
let time_slot = TschTimeslot::new(nested.content()).unwrap();
assert_eq!(time_slot.id(), 0);
}
_ => (),
}
}
}
}

Writing a frame

Work in progress!

Information Elements

The IEEE 802.15.4 standard defines a set of Information Elements (IEs) that can be included in the frame. These IEs are used to provide additional information about the frame, such as timestamping, channel hopping, and more. The IEs are divided into two groups: Header IEs and Payload IEs. Calling information_elements on a [Frame] reader returns an [InformationElements] reader. The reader provides access to the Header and Payload IEs, via the header_information_elements and payload_information_elements functions.

Header Information Elements

The Header IEs are located in the frame header, and are used to provide information about the frame itself. The following IEs are defined in the standard:

  • [VendorSpecific]
  • [Csl]
  • [Rit]
  • DsmePanDescriptor
  • [RendezvousTime]
  • [TimeCorrection]
  • ExtededDsmePanDescriptor
  • FragmentSequencecontextDescription
  • [SimplifiedSuperframeSpecification]
  • SimplifiedGtsSpecification
  • LecimCapabilities
  • TrleDescriptor
  • RccCapabilities
  • RccnDescriptor
  • GlobalTime
  • Da
  • HeaderTermination1
  • HeaderTermination2

Payload Information Elements

The Payload IEs are located in the frame payload, and are used to provide information about the payload itself. The following IEs are defined in the standard:

  • Esdu
  • Mlme: The MLME group contains a set of nested IEs. Call nested_information_elements to get an iterator over the nested IEs.
  • VendorSpecific
  • PayloadTermination

Nested Information Elements

Some IEs contain nested IEs. The [NestedInformationElementsIterator] provides an iterator over the nested IEs. The iterator is used to parse the nested IEs.

The Nested IEs are split into two groups: Short and Long. The following short IEs are defined in the standard:

  • [TschSynchronization]
  • [TschSlotframeAndLink]
  • [TschTimeslot]
  • HoppingTiming
  • EnhancedBeaconFilter
  • MacMetrics
  • AllMacMetrics
  • CoexistenceSpecification
  • SunDeviceCapabilities
  • SunFskGenericPhy
  • ModeSwitchParameter
  • PhyParameterChange
  • OQpskPhyMode
  • PcaAllocation
  • LecimDsssOperatingMode
  • LecimFskOperatingMode
  • TvwsPhyOperatingMode
  • TvwsDeviceCapabilities
  • TvwsDeviceCategory
  • TvwsDeviceIdentification
  • TvwsDeviceLocation
  • TvwsChannelInformationQuery
  • TvwsChannelInformationSource
  • Ctm
  • Timestamp
  • TimestampDifference
  • TmctpSpecification
  • RccPhyOperatingMode
  • LinkMargin
  • RsGfskDeviceCapabilities
  • MultiPhy
  • VendorSpecific
  • Srm

The following long IEs are defined in the standard:

  • VendorSpecificNested
  • [ChannelHopping]