Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe wrappers for wifi promiscuous #536

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow using esp timer with skip_unhandled_events (#526)
- OTA - Implements a new type `EspFirmwareInfoLoad` that has a reduced memory consumption (#531)
- Added set_promiscuous function in EthDriver (#246)
- Added set_promiscuous, get_promiscuous functions in WifiDriver (#246)

### Fixed
- The alloc::Vec version stomps the scan state from Done to Idle. (#459)
Expand Down
2 changes: 1 addition & 1 deletion src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ impl<'d, T> EthDriver<'d, T> {
Ok(())
}

/// Enables or disables promiscuous mode for the Ethernet driver.
/// Enables or disables promiscuous mode for the [`EthDriver`].
///
/// When promiscuous mode is enabled, the driver captures all Ethernet frames
/// on the network, regardless of their destination MAC address. This is useful for
Expand Down
31 changes: 31 additions & 0 deletions src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,37 @@ impl<'d> WifiDriver<'d> {
Ok(())
}

/// Enables or disables promiscuous mode for the [`WifiDriver`].
///
/// When promiscuous mode is enabled, the driver captures all Wifi frames
/// on the network, regardless of their destination MAC address. This is useful for
/// debugging or monitoring purposes.
pub fn set_promiscuous(&mut self, state: bool) -> Result<(), EspError> {
esp!(unsafe { esp_wifi_set_promiscuous(state) })?;

if state {
log::info!("Driver set in promiscuous mode");
} else {
log::info!("Driver set in non-promiscuous mode");
}

Ok(())
}

/// Gets the state of the promiscuous mode for the [`WifiDriver`].
pub fn get_promiscuous(&self) -> Result<bool, EspError> {
indexds marked this conversation as resolved.
Show resolved Hide resolved
let mut en: bool = false;

esp!(unsafe { esp_wifi_get_promiscuous(&mut en) })?;

Ok(en)
}

//TODO: add safe wrappers for these three functions
//https://docs.esp-rs.org/esp-idf-sys/esp_idf_sys/fn.esp_wifi_set_promiscuous_ctrl_filter.html
//https://docs.esp-rs.org/esp-idf-sys/esp_idf_sys/fn.esp_wifi_set_promiscuous_filter.html
//https://docs.esp-rs.org/esp-idf-sys/esp_idf_sys/fn.esp_wifi_set_promiscuous_rx_cb.html

/// Gets the WPS status as a [`WPS Event`] and disables WPS.
fn stop_wps(&mut self) -> Result<WpsStatus, EspError> {
let mut status = self.status.lock();
Expand Down
Loading