Add AccessPoint bindings

This commit is contained in:
Lucy 2022-01-13 12:06:00 -05:00
parent 29550a9658
commit 02c744a119
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
7 changed files with 162 additions and 794 deletions

View file

@ -0,0 +1,52 @@
// SPDX-License-Identifier: MPL-2.0
use crate::interface::{
access_point::AccessPointProxy,
enums::{ApFlags, ApSecurityFlags},
};
use std::ops::Deref;
use zbus::Result;
pub struct AccessPoint<'a>(AccessPointProxy<'a>);
impl<'a> AccessPoint<'a> {
/* TODO: figure out how to convert CLOCK_BOOTTIME to SystemTime, as CLOCK_BOOTTIME's starting point is arbritary and not guaranteed to match up with the UNIX Epoch
pub async fn last_seen(&self) -> Result<Option<SystemTime>> {
let last_seen = self.0.last_seen().await?;
if !last_seen.is_positive() {
return Ok(None);
}
}*/
pub async fn flags(&self) -> Result<ApFlags> {
self.0.flags().await.map(ApFlags::from_bits_truncate)
}
pub async fn rsn_flags(&self) -> Result<ApSecurityFlags> {
self.0
.rsn_flags()
.await
.map(ApSecurityFlags::from_bits_truncate)
}
pub async fn wpa_flags(&self) -> Result<ApSecurityFlags> {
self.0
.wpa_flags()
.await
.map(ApSecurityFlags::from_bits_truncate)
}
}
impl<'a> Deref for AccessPoint<'a> {
type Target = AccessPointProxy<'a>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a> From<AccessPointProxy<'a>> for AccessPoint<'a> {
fn from(access_point: AccessPointProxy<'a>) -> Self {
AccessPoint(access_point)
}
}

View file

@ -1,9 +1,13 @@
// SPDX-License-Identifier: MPL-2.0
use super::Device;
use crate::interface::{
device::{wireless::WirelessDeviceProxy, DeviceProxy},
enums::WifiCapabilities,
use crate::{
access_point::AccessPoint,
interface::{
access_point::AccessPointProxy,
device::{wireless::WirelessDeviceProxy, DeviceProxy},
enums::{WifiCapabilities, WifiMode},
},
};
use std::ops::Deref;
use zbus::Result;
@ -11,6 +15,53 @@ use zbus::Result;
pub struct WirelessDevice<'a>(WirelessDeviceProxy<'a>);
impl<'a> WirelessDevice<'a> {
pub async fn get_access_points(&self) -> Result<Vec<AccessPoint<'a>>> {
let access_points = self.0.get_access_points().await?;
let mut out = Vec::with_capacity(access_points.len());
for access_point in access_points {
let access_point = AccessPointProxy::builder(self.0.connection())
.path(access_point)?
.build()
.await?;
out.push(access_point.into());
}
Ok(out)
}
pub async fn get_all_access_points(&self) -> Result<Vec<AccessPoint<'a>>> {
let access_points = self.0.get_all_access_points().await?;
let mut out = Vec::with_capacity(access_points.len());
for access_point in access_points {
let access_point = AccessPointProxy::builder(self.0.connection())
.path(access_point)?
.build()
.await?;
out.push(access_point.into());
}
Ok(out)
}
pub async fn access_points(&self) -> Result<Vec<AccessPoint<'a>>> {
let access_points = self.0.access_points().await?;
let mut out = Vec::with_capacity(access_points.len());
for access_point in access_points {
let access_point = AccessPointProxy::builder(self.0.connection())
.path(access_point)?
.build()
.await?;
out.push(access_point.into());
}
Ok(out)
}
pub async fn active_access_point(&self) -> Result<AccessPoint<'a>> {
AccessPointProxy::builder(self.0.connection())
.path(self.0.active_access_point().await?)?
.build()
.await
.map(AccessPoint::from)
}
pub async fn upcast(&'a self) -> Result<Device<'a>> {
DeviceProxy::builder(self.0.connection())
.path(self.0.path())?
@ -18,9 +69,11 @@ impl<'a> WirelessDevice<'a> {
.await
.map(Device::from)
}
}
impl<'a> WirelessDevice<'a> {
pub async fn mode(&self) -> Result<WifiMode> {
self.0.mode().await.map(WifiMode::from)
}
pub async fn wireless_capabilities(&self) -> Result<WifiCapabilities> {
self.0
.wireless_capabilities()

View file

@ -105,6 +105,26 @@ impl From<u32> for DeviceState {
}
}
pub enum WifiMode {
AdHoc,
Infra,
Ap,
Mesh,
Unknown,
}
impl From<u32> for WifiMode {
fn from(mode: u32) -> Self {
match mode {
1 => WifiMode::AdHoc,
2 => WifiMode::Infra,
3 => WifiMode::Ap,
4 => WifiMode::Mesh,
_ => WifiMode::Unknown,
}
}
}
bitflags! {
pub struct DeviceCapabilities: u32 {
const SUPPORTED = 0x00000001;
@ -144,3 +164,31 @@ bitflags! {
const EXTERNAL = 0x80;
}
}
bitflags! {
pub struct ApFlags: u32 {
const PRIVACY = 0x1;
const WPS = 0x2;
const WPS_PBC = 0x4;
const WPS_PIN = 0x8;
}
}
bitflags! {
pub struct ApSecurityFlags: u32 {
const WEP40 = 0x1;
const WEP104 = 0x2;
const TKIP = 0x4;
const CCMP = 0x8;
const GROUP_WEP40 = 0x10;
const GROUP_WEP104 = 0x20;
const GROUP_TKIP = 0x40;
const GROUP_CCMP = 0x80;
const KEY_MGMTPSK = 0x100;
const KEY_MGMT_802_1X = 0x200;
const KEY_MGMT_SAE = 0x400;
const KEY_MGMT_OWE = 0x800;
const KEY_MGMT_OWE_TM = 0x1000;
const KEY_MGMT_EAP_SUITE_B_192 = 0x2000;
}
}

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
pub mod access_point;
pub mod active_connection;
pub mod config;
pub mod device;