From 01b0af5a84409a13264d799a8156bb965ad7989f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 10 Jan 2024 14:06:15 +0100 Subject: [PATCH] net: add packet-trace feature. --- ci.sh | 2 +- embassy-net/Cargo.toml | 3 +++ embassy-net/src/device.rs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ci.sh b/ci.sh index dd028ddda..9c6f58f9f 100755 --- a/ci.sh +++ b/ci.sh @@ -35,7 +35,7 @@ cargo batch \ --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread,integrated-timers \ --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \ --- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,generic-queue-8,mock-driver \ - --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ + --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet,packet-trace \ --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,igmp,medium-ethernet \ --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,dhcpv4-hostname \ diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 67f0bd028..864956616 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -28,6 +28,9 @@ std = [] ## Enable defmt defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"] +## Trace all raw received and transmitted packets using defmt or log. +packet-trace = [] + #! Many of the following feature flags are re-exports of smoltcp feature flags. See #! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags) #! for more details diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 54a0c47e8..3b1d3c47c 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -76,7 +76,11 @@ where where F: FnOnce(&mut [u8]) -> R, { - self.0.consume(|buf| f(buf)) + self.0.consume(|buf| { + #[cfg(feature = "packet-trace")] + trace!("rx: {:?}", buf); + f(buf) + }) } } @@ -92,6 +96,11 @@ where where F: FnOnce(&mut [u8]) -> R, { - self.0.consume(len, |buf| f(buf)) + self.0.consume(len, |buf| { + let r = f(buf); + #[cfg(feature = "packet-trace")] + trace!("tx: {:?}", buf); + r + }) } }