aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-01-10 14:06:15 +0100
committerDario Nieuwenhuis <[email protected]>2024-01-10 14:06:15 +0100
commit01b0af5a84409a13264d799a8156bb965ad7989f (patch)
treebe6018abc7ac2924bf4793a6e49d016110ac4280
parent0027a76bb61f19fcae1fe588ba3ff62660d7f7e3 (diff)
net: add packet-trace feature.
-rwxr-xr-xci.sh2
-rw-r--r--embassy-net/Cargo.toml3
-rw-r--r--embassy-net/src/device.rs13
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 \
35 --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread,integrated-timers \ 35 --- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread,integrated-timers \
36 --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \ 36 --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \
37 --- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,generic-queue-8,mock-driver \ 37 --- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,generic-queue-8,mock-driver \
38 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ 38 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet,packet-trace \
39 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,igmp,medium-ethernet \ 39 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,igmp,medium-ethernet \
40 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ 40 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
41 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,dhcpv4-hostname \ 41 --- 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 = []
28## Enable defmt 28## Enable defmt
29defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"] 29defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"]
30 30
31## Trace all raw received and transmitted packets using defmt or log.
32packet-trace = []
33
31#! Many of the following feature flags are re-exports of smoltcp feature flags. See 34#! Many of the following feature flags are re-exports of smoltcp feature flags. See
32#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags) 35#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags)
33#! for more details 36#! 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
76 where 76 where
77 F: FnOnce(&mut [u8]) -> R, 77 F: FnOnce(&mut [u8]) -> R,
78 { 78 {
79 self.0.consume(|buf| f(buf)) 79 self.0.consume(|buf| {
80 #[cfg(feature = "packet-trace")]
81 trace!("rx: {:?}", buf);
82 f(buf)
83 })
80 } 84 }
81} 85}
82 86
@@ -92,6 +96,11 @@ where
92 where 96 where
93 F: FnOnce(&mut [u8]) -> R, 97 F: FnOnce(&mut [u8]) -> R,
94 { 98 {
95 self.0.consume(len, |buf| f(buf)) 99 self.0.consume(len, |buf| {
100 let r = f(buf);
101 #[cfg(feature = "packet-trace")]
102 trace!("tx: {:?}", buf);
103 r
104 })
96 } 105 }
97} 106}