Skip to content

Commit

Permalink
add wifi promiscuous wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
indexds committed Dec 27, 2024
1 parent 183dcdf commit 50332f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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_promisucous(&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> {
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 50332f6

Please sign in to comment.