|
@@ -405,12 +405,38 @@ pub mod frag {
|
|
|
|
|
|
/// A high-level representation of a 6LoWPAN Fragment header.
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
- #[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
pub enum Repr {
|
|
|
FirstFragment { size: u16, tag: u16 },
|
|
|
Fragment { size: u16, tag: u16, offset: u8 },
|
|
|
}
|
|
|
|
|
|
+ impl core::fmt::Display for Repr {
|
|
|
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
+ match self {
|
|
|
+ Repr::FirstFragment { size, tag } => {
|
|
|
+ write!(f, "FirstFrag size={size} tag={tag}")
|
|
|
+ }
|
|
|
+ Repr::Fragment { size, tag, offset } => {
|
|
|
+ write!(f, "NthFrag size={size} tag={tag} offset={offset}")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #[cfg(feature = "defmt")]
|
|
|
+ impl defmt::Format for Repr {
|
|
|
+ fn format(&self, fmt: defmt::Formatter) {
|
|
|
+ match self {
|
|
|
+ Repr::FirstFragment { size, tag } => {
|
|
|
+ defmt::write!(fmt, "FirstFrag size={} tag={}", size, tag);
|
|
|
+ }
|
|
|
+ Repr::Fragment { size, tag, offset } => {
|
|
|
+ defmt::write!(fmt, "NthFrag size={} tag={} offset={}", size, tag, offset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
impl Repr {
|
|
|
/// Parse a 6LoWPAN Fragment header.
|
|
|
pub fn parse<T: AsRef<[u8]>>(packet: &Packet<T>) -> Result<Self> {
|
|
@@ -456,12 +482,30 @@ pub mod frag {
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
-#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
pub enum NextHeader {
|
|
|
Compressed,
|
|
|
Uncompressed(IpProtocol),
|
|
|
}
|
|
|
|
|
|
+impl core::fmt::Display for NextHeader {
|
|
|
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
+ match self {
|
|
|
+ NextHeader::Compressed => write!(f, "compressed"),
|
|
|
+ NextHeader::Uncompressed(protocol) => write!(f, "{protocol}"),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[cfg(feature = "defmt")]
|
|
|
+impl defmt::Format for NextHeader {
|
|
|
+ fn format(&self, fmt: defmt::Formatter) {
|
|
|
+ match self {
|
|
|
+ NextHeader::Compressed => defmt::write!(fmt, "compressed"),
|
|
|
+ NextHeader::Uncompressed(protocol) => defmt::write!(fmt, "{}", protocol),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
pub mod iphc {
|
|
|
//! Implementation of IP Header Compression from [RFC 6282 § 3.1].
|
|
|
//! It defines the compression of IPv6 headers.
|
|
@@ -1145,7 +1189,6 @@ pub mod iphc {
|
|
|
|
|
|
/// A high-level representation of a 6LoWPAN IPHC header.
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
|
|
- #[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
pub struct Repr {
|
|
|
pub src_addr: ipv6::Address,
|
|
|
pub ll_src_addr: Option<LlAddress>,
|
|
@@ -1159,6 +1202,30 @@ pub mod iphc {
|
|
|
pub flow_label: Option<u16>,
|
|
|
}
|
|
|
|
|
|
+ impl core::fmt::Display for Repr {
|
|
|
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
+ write!(
|
|
|
+ f,
|
|
|
+ "IPHC src={} dst={} nxt-hdr={} hop-limit={}",
|
|
|
+ self.src_addr, self.dst_addr, self.next_header, self.hop_limit
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #[cfg(feature = "defmt")]
|
|
|
+ impl defmt::Format for Repr {
|
|
|
+ fn format(&self, fmt: defmt::Formatter) {
|
|
|
+ defmt::write!(
|
|
|
+ fmt,
|
|
|
+ "IPHC src={} dst={} nxt-hdr={} hop-limit={}",
|
|
|
+ self.src_addr,
|
|
|
+ self.dst_addr,
|
|
|
+ self.next_header,
|
|
|
+ self.hop_limit
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
impl Repr {
|
|
|
/// Parse a 6LoWPAN IPHC header and return a high-level representation.
|
|
|
///
|