Add defmt logging support

master
Dario Nieuwenhuis 2021-04-01 01:30:47 +02:00
parent 5947c5947e
commit d64c8593f0
41 changed files with 152 additions and 1 deletions

View File

@ -21,6 +21,7 @@ byteorder = { version = "1.0", default-features = false }
log = { version = "0.4.4", default-features = false, optional = true } log = { version = "0.4.4", default-features = false, optional = true }
libc = { version = "0.2.18", optional = true } libc = { version = "0.2.18", optional = true }
bitflags = { version = "1.0", default-features = false } bitflags = { version = "1.0", default-features = false }
defmt = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
env_logger = "0.5" env_logger = "0.5"
@ -46,6 +47,13 @@ verbose = []
"socket-tcp" = ["socket"] "socket-tcp" = ["socket"]
"socket-icmp" = ["socket"] "socket-icmp" = ["socket"]
"async" = [] "async" = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
default = [ default = [
"std", "log", # needed for `cargo test --no-default-features --features default` :/ "std", "log", # needed for `cargo test --no-default-features --features default` :/
"medium-ethernet", "medium-ip", "medium-ethernet", "medium-ip",

View File

@ -21,6 +21,7 @@ mod mock {
use core::cell::Cell; use core::cell::Cell;
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Clock(Cell<Instant>); pub struct Clock(Cell<Instant>);
impl Clock { impl Clock {
@ -46,6 +47,7 @@ mod mock {
// should be AtomicU64 but that's unstable // should be AtomicU64 but that's unstable
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Clock(Arc<AtomicUsize>); pub struct Clock(Arc<AtomicUsize>);
impl Clock { impl Clock {

View File

@ -24,6 +24,7 @@ mod mock {
// should be AtomicU64 but that's unstable // should be AtomicU64 but that's unstable
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Clock(Arc<AtomicUsize>); pub struct Clock(Arc<AtomicUsize>);
impl Clock { impl Clock {

View File

@ -22,6 +22,7 @@ const PARAMETER_REQUEST_LIST: &[u8] = &[
/// IPv4 configuration data returned by `client.poll()` /// IPv4 configuration data returned by `client.poll()`
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Config { pub struct Config {
pub address: Option<Ipv4Cidr>, pub address: Option<Ipv4Cidr>,
pub router: Option<Ipv4Address>, pub router: Option<Ipv4Address>,
@ -29,6 +30,7 @@ pub struct Config {
} }
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct RequestState { struct RequestState {
retry: u16, retry: u16,
endpoint_ip: Ipv4Address, endpoint_ip: Ipv4Address,
@ -37,12 +39,14 @@ struct RequestState {
} }
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct RenewState { struct RenewState {
endpoint_ip: Ipv4Address, endpoint_ip: Ipv4Address,
server_identifier: Ipv4Address, server_identifier: Ipv4Address,
} }
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
enum ClientState { enum ClientState {
/// Discovering the DHCP server /// Discovering the DHCP server
Discovering, Discovering,

View File

@ -243,6 +243,7 @@ let iface = InterfaceBuilder::new(device)
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg(feature = "medium-ethernet")] #[cfg(feature = "medium-ethernet")]
enum EthernetPacket<'a> { enum EthernetPacket<'a> {
#[cfg(feature = "proto-ipv4")] #[cfg(feature = "proto-ipv4")]
@ -251,6 +252,7 @@ enum EthernetPacket<'a> {
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub(crate) enum IpPacket<'a> { pub(crate) enum IpPacket<'a> {
#[cfg(feature = "proto-ipv4")] #[cfg(feature = "proto-ipv4")]
Icmpv4((Ipv4Repr, Icmpv4Repr<'a>)), Icmpv4((Ipv4Repr, Icmpv4Repr<'a>)),
@ -591,6 +593,7 @@ impl<'a, DeviceT> Interface<'a, DeviceT>
Medium::Ethernet => { Medium::Ethernet => {
inner.process_ethernet(sockets, timestamp, &frame).map_err(|err| { inner.process_ethernet(sockets, timestamp, &frame).map_err(|err| {
net_debug!("cannot process ingress packet: {}", err); net_debug!("cannot process ingress packet: {}", err);
#[cfg(not(feature = "defmt"))]
net_debug!("packet dump follows:\n{}", net_debug!("packet dump follows:\n{}",
PrettyPrinter::<EthernetFrame<&[u8]>>::new("", &frame)); PrettyPrinter::<EthernetFrame<&[u8]>>::new("", &frame));
err err
@ -1844,6 +1847,7 @@ mod test {
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct MockTxToken; struct MockTxToken;
impl TxToken for MockTxToken { impl TxToken for MockTxToken {

View File

@ -11,6 +11,7 @@ use crate::time::{Duration, Instant};
/// A neighbor mapping translates from a protocol address to a hardware address, /// A neighbor mapping translates from a protocol address to a hardware address,
/// and contains the timestamp past which the mapping should be discarded. /// and contains the timestamp past which the mapping should be discarded.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Neighbor { pub struct Neighbor {
hardware_addr: EthernetAddress, hardware_addr: EthernetAddress,
expires_at: Instant, expires_at: Instant,
@ -18,6 +19,7 @@ pub struct Neighbor {
/// An answer to a neighbor cache lookup. /// An answer to a neighbor cache lookup.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub(crate) enum Answer { pub(crate) enum Answer {
/// The neighbor address is in the cache and not expired. /// The neighbor address is in the cache and not expired.
Found(EthernetAddress), Found(EthernetAddress),

View File

@ -11,6 +11,7 @@ use crate::wire::{Ipv6Address, Ipv6Cidr};
/// A prefix of addresses that should be routed via a router /// A prefix of addresses that should be routed via a router
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Route { pub struct Route {
pub via_router: IpAddress, pub via_router: IpAddress,
/// `None` means "forever". /// `None` means "forever".

View File

@ -97,6 +97,9 @@ compile_error!("You must enable at least one of the following features: proto-ip
))] ))]
compile_error!("If you enable the socket feature, you must enable at least one of the following features: socket-raw, socket-udp, socket-tcp, socket-icmp"); compile_error!("If you enable the socket feature, you must enable at least one of the following features: socket-raw, socket-udp, socket-tcp, socket-icmp");
#[cfg(all(feature = "defmt", feature = "log"))]
compile_error!("You must enable at most one of the following features: defmt, log");
use core::fmt; use core::fmt;
#[macro_use] #[macro_use]
@ -116,6 +119,7 @@ pub mod dhcp;
/// The error type for the networking stack. /// The error type for the networking stack.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error { pub enum Error {
/// An operation cannot proceed because a buffer is empty or full. /// An operation cannot proceed because a buffer is empty or full.
Exhausted, Exhausted,

View File

@ -5,7 +5,13 @@ macro_rules! net_log {
(debug, $($arg:expr),*) => { log::debug!($($arg),*); }; (debug, $($arg:expr),*) => { log::debug!($($arg),*); };
} }
#[cfg(not(feature = "log"))] #[cfg(feature = "defmt")]
macro_rules! net_log {
(trace, $($arg:expr),*) => { defmt::trace!($($arg),*); };
(debug, $($arg:expr),*) => { defmt::debug!($($arg),*); };
}
#[cfg(not(any(feature = "log", feature = "defmt")))]
#[macro_use] #[macro_use]
macro_rules! net_log { macro_rules! net_log {
($level:ident, $($arg:expr),*) => { $( let _ = $arg; )* } ($level:ident, $($arg:expr),*) => { $( let _ = $arg; )* }
@ -30,6 +36,7 @@ macro_rules! enum_with_unknown {
} }
) => { ) => {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
$( #[$enum_attr] )* $( #[$enum_attr] )*
pub enum $name { pub enum $name {
$( $(

View File

@ -19,6 +19,7 @@ fn xorshift32(state: &mut u32) -> u32 {
const MTU: usize = 1536; const MTU: usize = 1536;
#[derive(Debug, Default, Clone, Copy)] #[derive(Debug, Default, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct Config { struct Config {
corrupt_pct: u8, corrupt_pct: u8,
drop_pct: u8, drop_pct: u8,
@ -30,6 +31,7 @@ struct Config {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct State { struct State {
rng_seed: u32, rng_seed: u32,
refilled_at: Instant, refilled_at: Instant,

View File

@ -18,6 +18,7 @@ pub trait Fuzzer {
/// smoltcp, and is not for production use. /// smoltcp, and is not for production use.
#[allow(unused)] #[allow(unused)]
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FuzzInjector<D: for<'a> Device<'a>, FTx: Fuzzer, FRx: Fuzzer> { pub struct FuzzInjector<D: for<'a> Device<'a>, FTx: Fuzzer, FRx: Fuzzer> {
inner: D, inner: D,
fuzz_tx: FTx, fuzz_tx: FTx,

View File

@ -119,6 +119,7 @@ pub use self::tuntap_interface::TunTapInterface;
/// A description of checksum behavior for a particular protocol. /// A description of checksum behavior for a particular protocol.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Checksum { pub enum Checksum {
/// Verify checksum when receiving and compute checksum when sending. /// Verify checksum when receiving and compute checksum when sending.
Both, Both,
@ -156,6 +157,7 @@ impl Checksum {
/// A description of checksum behavior for every supported protocol. /// A description of checksum behavior for every supported protocol.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub struct ChecksumCapabilities { pub struct ChecksumCapabilities {
pub ipv4: Checksum, pub ipv4: Checksum,
@ -188,6 +190,7 @@ impl ChecksumCapabilities {
/// Higher-level protocols may achieve higher throughput or lower latency if they consider /// Higher-level protocols may achieve higher throughput or lower latency if they consider
/// the bandwidth or packet size limitations. /// the bandwidth or packet size limitations.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub struct DeviceCapabilities { pub struct DeviceCapabilities {
/// Medium of the device. /// Medium of the device.
@ -229,6 +232,7 @@ pub struct DeviceCapabilities {
/// Type of medium of a device. /// Type of medium of a device.
#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Medium { pub enum Medium {
/// Ethernet medium. Devices of this type send and receive Ethernet frames, /// Ethernet medium. Devices of this type send and receive Ethernet frames,
/// and interfaces using it must do neighbor discovery via ARP or NDISC. /// and interfaces using it must do neighbor discovery via ARP or NDISC.

View File

@ -21,6 +21,7 @@ enum_with_unknown! {
/// Packet capture mode. /// Packet capture mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PcapMode { pub enum PcapMode {
/// Capture both received and transmitted packets. /// Capture both received and transmitted packets.
Both, Both,
@ -118,6 +119,7 @@ impl<T: Write> PcapSink for RefCell<T> {
/// [libpcap]: https://wiki.wireshark.org/Development/LibpcapFileFormat /// [libpcap]: https://wiki.wireshark.org/Development/LibpcapFileFormat
/// [sink]: trait.PcapSink.html /// [sink]: trait.PcapSink.html
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PcapWriter<D, S> pub struct PcapWriter<D, S>
where D: for<'a> Device<'a>, where D: for<'a> Device<'a>,
S: PcapSink + Clone, S: PcapSink + Clone,

View File

@ -22,6 +22,7 @@ use crate::wire::{IpAddress, IpEndpoint, IpProtocol, IpRepr};
/// ///
/// [IcmpSocket::bind]: struct.IcmpSocket.html#method.bind /// [IcmpSocket::bind]: struct.IcmpSocket.html#method.bind
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Endpoint { pub enum Endpoint {
Unspecified, Unspecified,
Ident(u16), Ident(u16),

View File

@ -7,6 +7,7 @@ use crate::time::{Duration, Instant};
/// This enum tracks whether the socket should be polled based on the neighbor it is /// This enum tracks whether the socket should be polled based on the neighbor it is
/// going to send packets to. /// going to send packets to.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
enum NeighborState { enum NeighborState {
/// Socket can be polled immediately. /// Socket can be polled immediately.
Active, Active,
@ -29,6 +30,7 @@ impl Default for NeighborState {
/// This includes things that only external (to the socket, that is) code /// This includes things that only external (to the socket, that is) code
/// is interested in, but which are more conveniently stored inside the socket itself. /// is interested in, but which are more conveniently stored inside the socket itself.
#[derive(Debug, Default)] #[derive(Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Meta { pub struct Meta {
/// Handle of this socket within its enclosing `SocketSet`. /// Handle of this socket within its enclosing `SocketSet`.
/// Mainly useful for debug output. /// Mainly useful for debug output.

View File

@ -61,6 +61,7 @@ pub(crate) use self::ref_::Session as SocketSession;
/// Gives an indication on the next time the socket should be polled. /// Gives an indication on the next time the socket should be polled.
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub(crate) enum PollAt { pub(crate) enum PollAt {
/// The socket needs to be polled immidiately. /// The socket needs to be polled immidiately.
Now, Now,

View File

@ -17,6 +17,7 @@ pub struct Item<'a> {
/// A handle, identifying a socket in a set. /// A handle, identifying a socket in a set.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Handle(usize); pub struct Handle(usize);
impl fmt::Display for Handle { impl fmt::Display for Handle {

View File

@ -21,6 +21,7 @@ pub type SocketBuffer<'a> = RingBuffer<'a, u8>;
/// ///
/// [RFC 793]: https://tools.ietf.org/html/rfc793 /// [RFC 793]: https://tools.ietf.org/html/rfc793
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum State { pub enum State {
Closed, Closed,
Listen, Listen,
@ -147,6 +148,7 @@ impl RttEstimator {
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
enum Timer { enum Timer {
Idle { Idle {
keep_alive_at: Option<Instant>, keep_alive_at: Option<Instant>,

View File

@ -5,6 +5,7 @@ pub struct TooManyHolesError;
/// A contiguous chunk of absent data, followed by a contiguous chunk of present data. /// A contiguous chunk of absent data, followed by a contiguous chunk of present data.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
struct Contig { struct Contig {
hole_size: usize, hole_size: usize,
data_size: usize data_size: usize
@ -80,6 +81,7 @@ const CONTIG_COUNT: usize = 4;
/// Currently, up to a hardcoded limit of 4 or 32 holes can be tracked in the buffer. /// Currently, up to a hardcoded limit of 4 or 32 holes can be tracked in the buffer.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(test, derive(PartialEq, Eq, Clone))] #[cfg_attr(test, derive(PartialEq, Eq, Clone))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Assembler { pub struct Assembler {
#[cfg(not(any(feature = "std", feature = "alloc")))] #[cfg(not(any(feature = "std", feature = "alloc")))]
contigs: [Contig; CONTIG_COUNT], contigs: [Contig; CONTIG_COUNT],

View File

@ -5,6 +5,7 @@ use crate::storage::RingBuffer;
/// Size and header of a packet. /// Size and header of a packet.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PacketMetadata<H> { pub struct PacketMetadata<H> {
size: usize, size: usize,
header: Option<H> header: Option<H>

View File

@ -22,6 +22,7 @@ use core::{ops, fmt};
/// * A value less than `0` indicates a time before the starting /// * A value less than `0` indicates a time before the starting
/// point. /// point.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Instant { pub struct Instant {
pub millis: i64, pub millis: i64,
} }
@ -135,6 +136,7 @@ impl ops::Sub<Instant> for Instant {
/// A relative amount of time. /// A relative amount of time.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Duration { pub struct Duration {
pub millis: u64, pub millis: u64,
} }

View File

@ -22,6 +22,7 @@ enum_with_unknown! {
/// A read/write wrapper around an Address Resolution Protocol packet buffer. /// A read/write wrapper around an Address Resolution Protocol packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -253,6 +254,7 @@ use crate::wire::{EthernetAddress, Ipv4Address};
/// A high-level representation of an Address Resolution Protocol packet. /// A high-level representation of an Address Resolution Protocol packet.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr { pub enum Repr {
/// An Ethernet and IPv4 Address Resolution Protocol packet. /// An Ethernet and IPv4 Address Resolution Protocol packet.

View File

@ -43,6 +43,7 @@ impl MessageType {
/// A representation of a single DHCP option. /// A representation of a single DHCP option.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DhcpOption<'a> { pub enum DhcpOption<'a> {
EndOfList, EndOfList,
Pad, Pad,
@ -200,6 +201,7 @@ impl<'a> DhcpOption<'a> {
/// A read/write wrapper around a Dynamic Host Configuration Protocol packet buffer. /// A read/write wrapper around a Dynamic Host Configuration Protocol packet buffer.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -624,6 +626,7 @@ impl<'a, T: AsRef<[u8]> + AsMut<[u8]> + ?Sized> Packet<&'a mut T> {
/// ///
/// The `options` field has a variable length. /// The `options` field has a variable length.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr<'a> { pub struct Repr<'a> {
/// This field is also known as `op` in the RFC. It indicates the type of DHCP message this /// This field is also known as `op` in the RFC. It indicates the type of DHCP message this
/// packet represents. /// packet represents.

View File

@ -25,6 +25,7 @@ impl fmt::Display for EtherType {
/// A six-octet Ethernet II address. /// A six-octet Ethernet II address.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Address(pub [u8; 6]); pub struct Address(pub [u8; 6]);
impl Address { impl Address {
@ -78,6 +79,7 @@ impl fmt::Display for Address {
/// A read/write wrapper around an Ethernet II frame buffer. /// A read/write wrapper around an Ethernet II frame buffer.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Frame<T: AsRef<[u8]>> { pub struct Frame<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -246,6 +248,7 @@ impl<T: AsRef<[u8]>> PrettyPrint for Frame<T> {
/// A high-level representation of an Internet Protocol version 4 packet header. /// A high-level representation of an Internet Protocol version 4 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr { pub struct Repr {
pub src_addr: Address, pub src_addr: Address,
pub dst_addr: Address, pub dst_addr: Address,

View File

@ -4,6 +4,7 @@ use crate::wire::icmpv4;
use crate::wire::icmpv6; use crate::wire::icmpv6;
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Repr<'a> { pub enum Repr<'a> {
#[cfg(feature = "proto-ipv4")] #[cfg(feature = "proto-ipv4")]
Ipv4(icmpv4::Repr<'a>), Ipv4(icmpv4::Repr<'a>),

View File

@ -167,6 +167,7 @@ enum_with_unknown! {
/// A read/write wrapper around an Internet Control Message Protocol version 4 packet buffer. /// A read/write wrapper around an Internet Control Message Protocol version 4 packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -366,6 +367,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A high-level representation of an Internet Control Message Protocol version 4 packet header. /// A high-level representation of an Internet Control Message Protocol version 4 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr<'a> { pub enum Repr<'a> {
EchoRequest { EchoRequest {

View File

@ -191,6 +191,7 @@ impl fmt::Display for TimeExceeded {
/// A read/write wrapper around an Internet Control Message Protocol version 6 packet buffer. /// A read/write wrapper around an Internet Control Message Protocol version 6 packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
pub(super) buffer: T pub(super) buffer: T
} }
@ -503,6 +504,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A high-level representation of an Internet Control Message Protocol version 6 packet header. /// A high-level representation of an Internet Control Message Protocol version 6 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr<'a> { pub enum Repr<'a> {
DstUnreachable { DstUnreachable {

View File

@ -23,6 +23,7 @@ enum_with_unknown! {
/// A read/write wrapper around an Internet Group Management Protocol v1/v2 packet buffer. /// A read/write wrapper around an Internet Group Management Protocol v1/v2 packet buffer.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T, buffer: T,
} }
@ -171,6 +172,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
/// A high-level representation of an Internet Group Management Protocol v1/v2 header. /// A high-level representation of an Internet Group Management Protocol v1/v2 header.
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Repr { pub enum Repr {
MembershipQuery { MembershipQuery {
max_resp_time: Duration, max_resp_time: Duration,
@ -188,6 +190,7 @@ pub enum Repr {
/// Type of IGMP membership report version /// Type of IGMP membership report version
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum IgmpVersion { pub enum IgmpVersion {
/// IGMPv1 /// IGMPv1
Version1, Version1,

View File

@ -10,6 +10,7 @@ use crate::wire::{Ipv6Address, Ipv6Cidr, Ipv6Packet, Ipv6Repr};
/// Internet protocol version. /// Internet protocol version.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Version { pub enum Version {
Unspecified, Unspecified,
@ -260,6 +261,19 @@ impl fmt::Display for Address {
} }
} }
#[cfg(feature = "defmt")]
impl defmt::Format for Address {
fn format(&self, f: defmt::Formatter) {
match self {
&Address::Unspecified => defmt::write!(f, "{:?}", "*"),
#[cfg(feature = "proto-ipv4")]
&Address::Ipv4(addr) => defmt::write!(f, "{:?}", addr),
#[cfg(feature = "proto-ipv6")]
&Address::Ipv6(addr) => defmt::write!(f, "{:?}", addr),
}
}
}
/// A specification of a CIDR block, containing an address and a variable-length /// A specification of a CIDR block, containing an address and a variable-length
/// subnet masking prefix length. /// subnet masking prefix length.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
@ -370,6 +384,18 @@ impl fmt::Display for Cidr {
} }
} }
#[cfg(feature = "defmt")]
impl defmt::Format for Cidr {
fn format(&self, f: defmt::Formatter) {
match self {
#[cfg(feature = "proto-ipv4")]
&Cidr::Ipv4(cidr) => defmt::write!(f, "{:?}", cidr),
#[cfg(feature = "proto-ipv6")]
&Cidr::Ipv6(cidr) => defmt::write!(f, "{:?}", cidr),
}
}
}
/// An internet endpoint address. /// An internet endpoint address.
/// ///
/// An endpoint can be constructed from a port, in which case the address is unspecified. /// An endpoint can be constructed from a port, in which case the address is unspecified.
@ -430,6 +456,13 @@ impl fmt::Display for Endpoint {
} }
} }
#[cfg(feature = "defmt")]
impl defmt::Format for Endpoint {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{:?}:{=u16}", self.addr, self.port);
}
}
impl From<u16> for Endpoint { impl From<u16> for Endpoint {
fn from(port: u16) -> Endpoint { fn from(port: u16) -> Endpoint {
Endpoint { addr: Address::Unspecified, port } Endpoint { addr: Address::Unspecified, port }
@ -448,6 +481,7 @@ impl<T: Into<Address>> From<(T, u16)> for Endpoint {
/// high-level representation for some IP protocol version, or an unspecified representation, /// high-level representation for some IP protocol version, or an unspecified representation,
/// which permits the `IpAddress::Unspecified` addresses. /// which permits the `IpAddress::Unspecified` addresses.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr { pub enum Repr {
Unspecified { Unspecified {

View File

@ -112,6 +112,13 @@ impl fmt::Display for Address {
} }
} }
#[cfg(feature = "defmt")]
impl defmt::Format for Address {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{=u8}.{=u8}.{=u8}.{=u8}", self.0[0], self.0[1], self.0[2], self.0[3])
}
}
/// A specification of an IPv4 CIDR block, containing an address and a variable-length /// A specification of an IPv4 CIDR block, containing an address and a variable-length
/// subnet masking prefix length. /// subnet masking prefix length.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
@ -227,8 +234,16 @@ impl fmt::Display for Cidr {
} }
} }
#[cfg(feature = "defmt")]
impl defmt::Format for Cidr {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{:?}/{=u8}", self.address, self.prefix_len);
}
}
/// A read/write wrapper around an Internet Protocol version 4 packet buffer. /// A read/write wrapper around an Internet Protocol version 4 packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -552,6 +567,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A high-level representation of an Internet Protocol version 4 packet header. /// A high-level representation of an Internet Protocol version 4 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr { pub struct Repr {
pub src_addr: Address, pub src_addr: Address,
pub dst_addr: Address, pub dst_addr: Address,

View File

@ -17,6 +17,7 @@ pub const MIN_MTU: usize = 1280;
/// A sixteen-octet IPv6 address. /// A sixteen-octet IPv6 address.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Address(pub [u8; 16]); pub struct Address(pub [u8; 16]);
impl Address { impl Address {
@ -267,6 +268,7 @@ impl From<ipv4::Address> for Address {
/// A specification of an IPv6 CIDR block, containing an address and a variable-length /// A specification of an IPv6 CIDR block, containing an address and a variable-length
/// subnet masking prefix length. /// subnet masking prefix length.
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)] #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Cidr { pub struct Cidr {
address: Address, address: Address,
prefix_len: u8, prefix_len: u8,
@ -328,6 +330,7 @@ impl fmt::Display for Cidr {
/// A read/write wrapper around an Internet Protocol version 6 packet buffer. /// A read/write wrapper around an Internet Protocol version 6 packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -593,6 +596,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A high-level representation of an Internet Protocol version 6 packet header. /// A high-level representation of an Internet Protocol version 6 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr { pub struct Repr {
/// IPv6 address of the source node. /// IPv6 address of the source node.
pub src_addr: Address, pub src_addr: Address,

View File

@ -7,6 +7,7 @@ pub use super::IpProtocol as Protocol;
/// A read/write wrapper around an IPv6 Fragment Header. /// A read/write wrapper around an IPv6 Fragment Header.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Header<T: AsRef<[u8]>> { pub struct Header<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -158,6 +159,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Header<&'a T> {
/// A high-level representation of an IPv6 Fragment header. /// A high-level representation of an IPv6 Fragment header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr { pub struct Repr {
/// The type of header immediately following the Fragment header. /// The type of header immediately following the Fragment header.
pub next_header: Protocol, pub next_header: Protocol,

View File

@ -6,6 +6,7 @@ pub use super::IpProtocol as Protocol;
/// A read/write wrapper around an IPv6 Hop-by-Hop Options Header. /// A read/write wrapper around an IPv6 Hop-by-Hop Options Header.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Header<T: AsRef<[u8]>> { pub struct Header<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -157,6 +158,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Header<&'a T> {
/// A high-level representation of an IPv6 Hop-by-Hop Options header. /// A high-level representation of an IPv6 Hop-by-Hop Options header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr<'a> { pub struct Repr<'a> {
/// The type of header immediately following the Hop-by-Hop Options header. /// The type of header immediately following the Hop-by-Hop Options header.
pub next_header: Protocol, pub next_header: Protocol,

View File

@ -58,6 +58,7 @@ impl From<Type> for FailureType {
/// A read/write wrapper around an IPv6 Extension Header Option. /// A read/write wrapper around an IPv6 Extension Header Option.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ipv6Option<T: AsRef<[u8]>> { pub struct Ipv6Option<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -214,6 +215,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Ipv6Option<&'a T> {
/// A high-level representation of an IPv6 Extension Header Option. /// A high-level representation of an IPv6 Extension Header Option.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr<'a> { pub enum Repr<'a> {
Pad1, Pad1,
@ -278,6 +280,7 @@ impl<'a> Repr<'a> {
/// A iterator for IPv6 options. /// A iterator for IPv6 options.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ipv6OptionsIterator<'a> { pub struct Ipv6OptionsIterator<'a> {
pos: usize, pos: usize,
length: usize, length: usize,

View File

@ -51,6 +51,7 @@ impl fmt::Display for Type {
/// A read/write wrapper around an IPv6 Routing Header buffer. /// A read/write wrapper around an IPv6 Routing Header buffer.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Header<T: AsRef<[u8]>> { pub struct Header<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -389,6 +390,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for Header<&'a T> {
/// A high-level representation of an IPv6 Routing Header. /// A high-level representation of an IPv6 Routing Header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive] #[non_exhaustive]
pub enum Repr<'a> { pub enum Repr<'a> {
Type2 { Type2 {

View File

@ -166,6 +166,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
/// A read/write wrapper around an MLDv2 Listener Report Message Address Record. /// A read/write wrapper around an MLDv2 Listener Report Message Address Record.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct AddressRecord<T: AsRef<[u8]>> { pub struct AddressRecord<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -295,6 +296,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> AddressRecord<T> {
/// A high-level representation of an MLDv2 packet header. /// A high-level representation of an MLDv2 packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Repr<'a> { pub enum Repr<'a> {
Query { Query {
max_resp_code: u16, max_resp_code: u16,

View File

@ -10,6 +10,7 @@ use crate::time::Duration;
use crate::wire::Ipv6Address; use crate::wire::Ipv6Address;
bitflags! { bitflags! {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RouterFlags: u8 { pub struct RouterFlags: u8 {
const MANAGED = 0b10000000; const MANAGED = 0b10000000;
const OTHER = 0b01000000; const OTHER = 0b01000000;
@ -17,6 +18,7 @@ bitflags! {
} }
bitflags! { bitflags! {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NeighborFlags: u8 { pub struct NeighborFlags: u8 {
const ROUTER = 0b10000000; const ROUTER = 0b10000000;
const SOLICITED = 0b01000000; const SOLICITED = 0b01000000;
@ -189,6 +191,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
/// A high-level representation of an Neighbor Discovery packet header. /// A high-level representation of an Neighbor Discovery packet header.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Repr<'a> { pub enum Repr<'a> {
RouterSolicit { RouterSolicit {
lladdr: Option<EthernetAddress> lladdr: Option<EthernetAddress>

View File

@ -36,6 +36,7 @@ impl fmt::Display for Type {
} }
bitflags! { bitflags! {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PrefixInfoFlags: u8 { pub struct PrefixInfoFlags: u8 {
const ON_LINK = 0b10000000; const ON_LINK = 0b10000000;
const ADDRCONF = 0b01000000; const ADDRCONF = 0b01000000;
@ -46,6 +47,7 @@ bitflags! {
/// ///
/// [NDISC Option]: https://tools.ietf.org/html/rfc4861#section-4.6 /// [NDISC Option]: https://tools.ietf.org/html/rfc4861#section-4.6
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NdiscOption<T: AsRef<[u8]>> { pub struct NdiscOption<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -393,6 +395,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> fmt::Display for NdiscOption<&'a T> {
} }
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PrefixInformation { pub struct PrefixInformation {
pub prefix_len: u8, pub prefix_len: u8,
pub flags: PrefixInfoFlags, pub flags: PrefixInfoFlags,
@ -402,6 +405,7 @@ pub struct PrefixInformation {
} }
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RedirectedHeader<'a> { pub struct RedirectedHeader<'a> {
pub header: Ipv6Repr, pub header: Ipv6Repr,
pub data: &'a [u8] pub data: &'a [u8]
@ -409,6 +413,7 @@ pub struct RedirectedHeader<'a> {
/// A high-level representation of an NDISC Option. /// A high-level representation of an NDISC Option.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Repr<'a> { pub enum Repr<'a> {
SourceLinkLayerAddr(EthernetAddress), SourceLinkLayerAddr(EthernetAddress),
TargetLinkLayerAddr(EthernetAddress), TargetLinkLayerAddr(EthernetAddress),

View File

@ -34,6 +34,7 @@ use core::marker::PhantomData;
/// Indentation state. /// Indentation state.
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PrettyIndent { pub struct PrettyIndent {
prefix: &'static str, prefix: &'static str,
level: usize level: usize

View File

@ -11,6 +11,7 @@ use crate::wire::ip::checksum;
/// A sequence number is a monotonically advancing integer modulo 2<sup>32</sup>. /// A sequence number is a monotonically advancing integer modulo 2<sup>32</sup>.
/// Sequence numbers do not have a discontiguity when compared pairwise across a signed overflow. /// Sequence numbers do not have a discontiguity when compared pairwise across a signed overflow.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)] #[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SeqNumber(pub i32); pub struct SeqNumber(pub i32);
impl fmt::Display for SeqNumber { impl fmt::Display for SeqNumber {
@ -67,6 +68,7 @@ impl cmp::PartialOrd for SeqNumber {
/// A read/write wrapper around a Transmission Control Protocol packet buffer. /// A read/write wrapper around a Transmission Control Protocol packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -550,6 +552,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A representation of a single TCP option. /// A representation of a single TCP option.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TcpOption<'a> { pub enum TcpOption<'a> {
EndOfList, EndOfList,
NoOperation, NoOperation,
@ -702,6 +705,7 @@ impl<'a> TcpOption<'a> {
/// The possible control flags of a Transmission Control Protocol packet. /// The possible control flags of a Transmission Control Protocol packet.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Control { pub enum Control {
None, None,
Psh, Psh,
@ -731,6 +735,7 @@ impl Control {
/// A high-level representation of a Transmission Control Protocol packet. /// A high-level representation of a Transmission Control Protocol packet.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr<'a> { pub struct Repr<'a> {
pub src_port: u16, pub src_port: u16,
pub dst_port: u16, pub dst_port: u16,

View File

@ -8,6 +8,7 @@ use crate::wire::ip::checksum;
/// A read/write wrapper around an User Datagram Protocol packet buffer. /// A read/write wrapper around an User Datagram Protocol packet buffer.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Packet<T: AsRef<[u8]>> { pub struct Packet<T: AsRef<[u8]>> {
buffer: T buffer: T
} }
@ -199,6 +200,7 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T> {
/// A high-level representation of an User Datagram Protocol packet. /// A high-level representation of an User Datagram Protocol packet.
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Repr<'a> { pub struct Repr<'a> {
pub src_port: u16, pub src_port: u16,
pub dst_port: u16, pub dst_port: u16,