From 055b03850b1006c96b2910e0f9e0ca403de68647 Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Mon, 20 Jul 2026 11:48:15 +0200 Subject: [PATCH] wifi: Move setup to radio module --- src/main.rs | 11 ++++------- src/radio.rs | 9 +++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 76557b1..77dfeaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,7 +112,8 @@ async fn main(spawner: Spawner) -> ! { }; // Setup WiFi - let (mut wifi_controller, interfaces) = esp_radio::wifi::new( + // sadly, it doesn't work any more when we move `esp_radio::wifi::new` to `setup_wifi_sniffer` + let (mut wifi_controller, mut interfaces) = esp_radio::wifi::new( peripherals.WIFI, esp_radio::wifi::ControllerConfig::default(), ) @@ -124,9 +125,7 @@ async fn main(spawner: Spawner) -> ! { critical_section::with(|cs| { WIFI_RX_QUEUE.borrow(cs).replace(Some(ArrayQueue::new(2))); }); - - let mut sniffer = interfaces.sniffer; - radio::setup_wifi_sniffer(WIFI_CHANNEL, &mut sniffer, handle_frame) + radio::setup_wifi_sniffer(WIFI_CHANNEL, &mut interfaces.sniffer, handle_frame) .expect("Fatal error initializing 802.11p sniffer"); info!("WiFi promiscuous mode on channel {WIFI_CHANNEL} running"); @@ -276,9 +275,7 @@ fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) { warn!("Received frame has RX error: {}", frame.rx_cntl.rx_state); return; } - if !radio::PromiscuousPktType::Data.matches(frame.frame_type) { - debug!("Received frame is not a DATA frame: {}", frame.frame_type); return; } @@ -296,7 +293,7 @@ fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) { return; } - debug!("Received frame with {} bytes", frame.len); + // info!("Received frame with {} bytes", frame.len); // Send data to main thread critical_section::with(|cs| { diff --git a/src/radio.rs b/src/radio.rs index 325cbf0..46cd72a 100644 --- a/src/radio.rs +++ b/src/radio.rs @@ -1,9 +1,6 @@ //! IEEE 802.11p C-ITS Capture with ESP32-C5 #![allow(unused)] -#[cfg(feature = "esp")] -use esp_radio::wifi::sniffer; - // ----------------------------- // missing interface definitions // ----------------------------- @@ -77,8 +74,8 @@ impl PromiscuousPktType { /// Configure WiFi Sniffer to a certain 802.11p channel pub fn setup_wifi_sniffer( channel: Channel, - sniffer: &mut sniffer::Sniffer, - callback: fn(sniffer::PromiscuousPkt<'_>), + sniffer: &mut esp_radio::wifi::sniffer::Sniffer, + callback: fn(esp_radio::wifi::sniffer::PromiscuousPkt<'_>), ) -> Result<(), alloc::string::String> { sniffer .set_promiscuous_mode(true) @@ -106,7 +103,7 @@ pub fn setup_wifi_sniffer( /// # Errors /// Fails when MAC is not the right size or returns frame send error pub fn send_80211_bcast_frame( - sniffer: &mut sniffer::Sniffer, + sniffer: &mut esp_radio::wifi::sniffer::Sniffer, mac_addr: &[u8], data: &[u8], ) -> Result<(), alloc::string::String> {