Skip to content

Commit

Permalink
Safe wrappers for wifi promiscuous (#536)
Browse files Browse the repository at this point in the history
* add wifi promiscuous wrappers

* add changes

* fix typo

* get_promiscuous->is_promiscuous

* fix
  • Loading branch information
indexds authored Jan 1, 2025
1 parent 229f314 commit 1c5d574
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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, is_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 is_promiscuous(&self) -> Result<bool, EspError> {
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

0 comments on commit 1c5d574

Please sign in to comment.