diff --git a/Readme.md b/Readme.md index daa1439..b0d5ef7 100644 --- a/Readme.md +++ b/Readme.md @@ -9,6 +9,7 @@ - [network](https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/doc/network-api.txt) - [station](https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/doc/station-api.txt) - [access point](https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/doc/access-point-api.txt) +- [access point diagnostics](https://git.kernel.org/pub/scm/network/wireless/iwd.git/tree/doc/access-point-diagnostic-api.txt) ## Getting started diff --git a/src/access_point.rs b/src/access_point.rs index 7444275..912bdf7 100644 --- a/src/access_point.rs +++ b/src/access_point.rs @@ -104,3 +104,46 @@ impl AccessPoint { Ok(proxy.get_property("GroupCipher").await.ok()) } } + +#[derive(Debug, Clone)] +pub struct AccessPointDiagnostic { + pub(crate) connection: Arc, + pub(crate) dbus_path: OwnedObjectPath, +} + +impl AccessPointDiagnostic { + pub(crate) fn new(connection: Arc, dbus_path: OwnedObjectPath) -> Self { + Self { + connection, + dbus_path, + } + } + + pub(crate) async fn proxy<'a>(&self) -> Result, zbus::Error> { + Proxy::new( + &self.connection, + "net.connman.iwd", + self.dbus_path.clone(), + "net.connman.iwd.AccessPointDiagnostic", + ) + .await + } + + pub async fn get(&self) -> Result>> { + let proxy = self.proxy().await?; + let diagnostic = proxy.call_method("GetDiagnostics", &()).await?; + + let body = diagnostic.body(); + let body: Vec> = body.deserialize()?; + let body = body + .into_iter() + .map(|map| { + map.into_iter() + .map(|(k, v)| (k, v.to_string())) + .collect::>() + }) + .collect::>>(); + + Ok(body) + } +} diff --git a/src/session.rs b/src/session.rs index 382413f..bc5c69d 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,5 +1,5 @@ use crate::{ - access_point::AccessPoint, + access_point::{AccessPoint, AccessPointDiagnostic}, adapter::Adapter, agent::{Agent, AgentManager}, device::Device, @@ -96,6 +96,22 @@ impl Session { access_point } + pub fn access_point_diagnostic(&self) -> Option { + let access_point_diagnostic: Option = self + .objects + .iter() + .flat_map(|(path, interfaces)| { + interfaces + .iter() + .filter(|(interface, _)| { + interface.as_str() == "net.connman.iwd.AccessPointDiagnostic" + }) + .map(|_| AccessPointDiagnostic::new(self.connection.clone(), path.clone())) + }) + .next(); + access_point_diagnostic + } + pub async fn register_agent(&self, agent: Agent) -> Result { let path = OwnedObjectPath::try_from(format!("/iwdrs/agent/{}", Uuid::new_v4().as_simple()))?;