wifi: Move setup to radio module
This commit is contained in:
parent
d7eeb67538
commit
055b03850b
2 changed files with 7 additions and 13 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -112,7 +112,8 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Setup WiFi
|
// 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,
|
peripherals.WIFI,
|
||||||
esp_radio::wifi::ControllerConfig::default(),
|
esp_radio::wifi::ControllerConfig::default(),
|
||||||
)
|
)
|
||||||
|
|
@ -124,9 +125,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
critical_section::with(|cs| {
|
critical_section::with(|cs| {
|
||||||
WIFI_RX_QUEUE.borrow(cs).replace(Some(ArrayQueue::new(2)));
|
WIFI_RX_QUEUE.borrow(cs).replace(Some(ArrayQueue::new(2)));
|
||||||
});
|
});
|
||||||
|
radio::setup_wifi_sniffer(WIFI_CHANNEL, &mut interfaces.sniffer, handle_frame)
|
||||||
let mut sniffer = interfaces.sniffer;
|
|
||||||
radio::setup_wifi_sniffer(WIFI_CHANNEL, &mut sniffer, handle_frame)
|
|
||||||
.expect("Fatal error initializing 802.11p sniffer");
|
.expect("Fatal error initializing 802.11p sniffer");
|
||||||
|
|
||||||
info!("WiFi promiscuous mode on channel {WIFI_CHANNEL} running");
|
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);
|
warn!("Received frame has RX error: {}", frame.rx_cntl.rx_state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !radio::PromiscuousPktType::Data.matches(frame.frame_type) {
|
if !radio::PromiscuousPktType::Data.matches(frame.frame_type) {
|
||||||
debug!("Received frame is not a DATA frame: {}", frame.frame_type);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,7 +293,7 @@ fn handle_frame(frame: wifi::sniffer::PromiscuousPkt<'_>) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Received frame with {} bytes", frame.len);
|
// info!("Received frame with {} bytes", frame.len);
|
||||||
|
|
||||||
// Send data to main thread
|
// Send data to main thread
|
||||||
critical_section::with(|cs| {
|
critical_section::with(|cs| {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
//! IEEE 802.11p C-ITS Capture with ESP32-C5
|
//! IEEE 802.11p C-ITS Capture with ESP32-C5
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
#[cfg(feature = "esp")]
|
|
||||||
use esp_radio::wifi::sniffer;
|
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// missing interface definitions
|
// missing interface definitions
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
@ -77,8 +74,8 @@ impl PromiscuousPktType {
|
||||||
/// Configure WiFi Sniffer to a certain 802.11p channel
|
/// Configure WiFi Sniffer to a certain 802.11p channel
|
||||||
pub fn setup_wifi_sniffer(
|
pub fn setup_wifi_sniffer(
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
sniffer: &mut sniffer::Sniffer,
|
sniffer: &mut esp_radio::wifi::sniffer::Sniffer,
|
||||||
callback: fn(sniffer::PromiscuousPkt<'_>),
|
callback: fn(esp_radio::wifi::sniffer::PromiscuousPkt<'_>),
|
||||||
) -> Result<(), alloc::string::String> {
|
) -> Result<(), alloc::string::String> {
|
||||||
sniffer
|
sniffer
|
||||||
.set_promiscuous_mode(true)
|
.set_promiscuous_mode(true)
|
||||||
|
|
@ -106,7 +103,7 @@ pub fn setup_wifi_sniffer(
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Fails when MAC is not the right size or returns frame send error
|
/// Fails when MAC is not the right size or returns frame send error
|
||||||
pub fn send_80211_bcast_frame(
|
pub fn send_80211_bcast_frame(
|
||||||
sniffer: &mut sniffer::Sniffer,
|
sniffer: &mut esp_radio::wifi::sniffer::Sniffer,
|
||||||
mac_addr: &[u8],
|
mac_addr: &[u8],
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<(), alloc::string::String> {
|
) -> Result<(), alloc::string::String> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue