diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd1df1993e..436dd0fdce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/eth.rs b/src/eth.rs index 1e6ccd9006c..6ef219c001d 100644 --- a/src/eth.rs +++ b/src/eth.rs @@ -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 diff --git a/src/wifi.rs b/src/wifi.rs index 551365459dc..27f6b8898ad 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -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 { + 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 { let mut status = self.status.lock();