Skip to content

Commit

Permalink
Add ap diagnostic api
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Jun 16, 2024
1 parent b1bbcc4 commit 9012eb0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 43 additions & 0 deletions src/access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,46 @@ impl AccessPoint {
Ok(proxy.get_property("GroupCipher").await.ok())
}
}

#[derive(Debug, Clone)]
pub struct AccessPointDiagnostic {
pub(crate) connection: Arc<Connection>,
pub(crate) dbus_path: OwnedObjectPath,
}

impl AccessPointDiagnostic {
pub(crate) fn new(connection: Arc<Connection>, dbus_path: OwnedObjectPath) -> Self {
Self {
connection,
dbus_path,
}
}

pub(crate) async fn proxy<'a>(&self) -> Result<zbus::Proxy<'a>, zbus::Error> {
Proxy::new(
&self.connection,
"net.connman.iwd",
self.dbus_path.clone(),
"net.connman.iwd.AccessPointDiagnostic",
)
.await
}

pub async fn get(&self) -> Result<Vec<HashMap<String, String>>> {
let proxy = self.proxy().await?;
let diagnostic = proxy.call_method("GetDiagnostics", &()).await?;

let body = diagnostic.body();
let body: Vec<HashMap<String, Value>> = body.deserialize()?;
let body = body
.into_iter()
.map(|map| {
map.into_iter()
.map(|(k, v)| (k, v.to_string()))
.collect::<HashMap<String, String>>()
})
.collect::<Vec<HashMap<String, String>>>();

Ok(body)
}
}
18 changes: 17 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
access_point::AccessPoint,
access_point::{AccessPoint, AccessPointDiagnostic},
adapter::Adapter,
agent::{Agent, AgentManager},
device::Device,
Expand Down Expand Up @@ -96,6 +96,22 @@ impl Session {
access_point
}

pub fn access_point_diagnostic(&self) -> Option<AccessPointDiagnostic> {
let access_point_diagnostic: Option<AccessPointDiagnostic> = 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<AgentManager> {
let path =
OwnedObjectPath::try_from(format!("/iwdrs/agent/{}", Uuid::new_v4().as_simple()))?;
Expand Down

0 comments on commit 9012eb0

Please sign in to comment.