diff --git a/src/bin/steamosctl.rs b/src/bin/steamosctl.rs index 37e12f7..c9fc26d 100644 --- a/src/bin/steamosctl.rs +++ b/src/bin/steamosctl.rs @@ -8,6 +8,7 @@ use anyhow::Result; use clap::{Parser, Subcommand}; use itertools::Itertools; +use std::collections::HashMap; use std::ops::Deref; use steamos_manager::cec::HdmiCecState; use steamos_manager::hardware::FanControlState; @@ -15,7 +16,7 @@ use steamos_manager::power::{CPUScalingGovernor, GPUPerformanceLevel, GPUPowerPr use steamos_manager::proxy::{ AmbientLightSensor1Proxy, CpuScaling1Proxy, FactoryReset1Proxy, FanControl1Proxy, GpuPerformanceLevel1Proxy, GpuPowerProfile1Proxy, HdmiCec1Proxy, Manager2Proxy, ManagerProxy, - Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy, WifiPowerManagement1Proxy, + Storage1Proxy, UpdateBios1Proxy, UpdateDock1Proxy, WifiDebug1Proxy, WifiPowerManagement1Proxy, }; use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement}; use zbus::fdo::PropertiesProxy; @@ -129,8 +130,7 @@ enum Commands { /// Valid modes are on, off mode: WifiDebugMode, /// The size of the debug buffer, in bytes - #[arg(default_value_t = 20000)] - buffer: u32, + buffer: Option, }, /// Get wifi debug mode @@ -327,19 +327,29 @@ async fn main() -> Result<()> { println!("TDP limit min: {value}"); } Commands::SetWifiBackend { backend } => { - proxy.set_wifi_backend(*backend as u32).await?; + let proxy = WifiDebug1Proxy::new(&conn).await?; + proxy.set_wifi_backend(backend.to_string().as_str()).await?; } Commands::GetWifiBackend => { + let proxy = WifiDebug1Proxy::new(&conn).await?; let backend = proxy.wifi_backend().await?; - match WifiBackend::try_from(backend) { + match WifiBackend::try_from(backend.as_str()) { Ok(be) => println!("Wifi backend: {}", be), Err(_) => println!("Got unknown value {backend} from backend"), } } Commands::SetWifiDebugMode { mode, buffer } => { - proxy.set_wifi_debug_mode(*mode as u32, *buffer).await?; + let proxy = WifiDebug1Proxy::new(&conn).await?; + let mut options = HashMap::<&str, &zvariant::Value<'_>>::new(); + let buffer_size; + if let Some(size) = buffer { + buffer_size = Some(zvariant::Value::U32(*size)); + options.insert("buffer_size", buffer_size.as_ref().unwrap()); + } + proxy.set_wifi_debug_mode(*mode as u32, options).await?; } Commands::GetWifiDebugMode => { + let proxy = WifiDebug1Proxy::new(&conn).await?; let mode = proxy.wifi_debug_mode_state().await?; match WifiDebugMode::try_from(mode) { Ok(m) => println!("Wifi debug mode: {}", m), diff --git a/src/manager/root.rs b/src/manager/root.rs index 9e08be1..24a9319 100644 --- a/src/manager/root.rs +++ b/src/manager/root.rs @@ -7,6 +7,7 @@ */ use anyhow::Result; +use std::collections::HashMap; use std::ffi::OsStr; use tokio::fs::File; use tokio::sync::mpsc::Sender; @@ -231,7 +232,7 @@ impl SteamOSManager { async fn set_wifi_debug_mode( &mut self, mode: u32, - buffer_size: u32, + options: HashMap<&str, zvariant::Value<'_>>, #[zbus(signal_context)] ctx: SignalContext<'_>, ) -> fdo::Result<()> { // Set the wifi debug mode to mode, using an int for flexibility going forward but only @@ -240,6 +241,11 @@ impl SteamOSManager { Ok(mode) => mode, Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())), }; + let buffer_size = match options.get("buffer_size").map(|v| v.downcast_ref::()) { + Some(Ok(v)) => v, + None => 20000, + Some(Err(e)) => return Err(fdo::Error::InvalidArgs(e.to_string())), + }; match set_wifi_debug_mode( wanted_mode, buffer_size, diff --git a/src/manager/user.rs b/src/manager/user.rs index 9c42ded..c69b35e 100644 --- a/src/manager/user.rs +++ b/src/manager/user.rs @@ -7,6 +7,7 @@ */ use anyhow::Result; +use std::collections::HashMap; use tokio::sync::mpsc::{Sender, UnboundedSender}; use tokio::sync::oneshot; use tracing::error; @@ -142,6 +143,10 @@ struct UpdateDock1 { job_manager: UnboundedSender, } +struct WifiDebug1 { + proxy: Proxy<'static>, +} + struct WifiPowerManagement1 { proxy: Proxy<'static>, } @@ -462,6 +467,43 @@ impl UpdateDock1 { } } +#[interface(name = "com.steampowered.SteamOSManager1.WifiDebug1")] +impl WifiDebug1 { + #[zbus(property)] + async fn wifi_debug_mode_state(&self) -> fdo::Result { + getter!(self, "WifiDebugModeState") + } + + async fn set_wifi_debug_mode( + &self, + mode: u32, + options: HashMap<&str, zvariant::Value<'_>>, + #[zbus(signal_context)] ctx: SignalContext<'_>, + ) -> fdo::Result<()> { + method!(self, "SetWifiDebugMode", mode, options)?; + self.wifi_debug_mode_state_changed(&ctx) + .await + .map_err(zbus_to_zbus_fdo)?; + Ok(()) + } + + #[zbus(property(emits_changed_signal = "false"))] + async fn wifi_backend(&self) -> fdo::Result { + match get_wifi_backend().await { + Ok(backend) => Ok(backend.to_string()), + Err(e) => Err(to_zbus_fdo_error(e)), + } + } + + #[zbus(property)] + async fn set_wifi_backend(&self, backend: &str) -> zbus::Result<()> { + self.proxy + .call("SetWifiBackend", &(backend)) + .await + .map_err(to_zbus_error) + } +} + #[interface(name = "com.steampowered.SteamOSManager1.WifiPowerManagement1")] impl WifiPowerManagement1 { #[zbus(property(emits_changed_signal = "false"))] @@ -532,6 +574,9 @@ pub(crate) async fn create_interfaces( proxy: proxy.clone(), job_manager: job_manager.clone(), }; + let wifi_debug = WifiDebug1 { + proxy: proxy.clone(), + }; let wifi_power_management = WifiPowerManagement1 { proxy: proxy.clone(), }; @@ -551,6 +596,7 @@ pub(crate) async fn create_interfaces( object_server.at(MANAGER_PATH, storage).await?; object_server.at(MANAGER_PATH, update_bios).await?; object_server.at(MANAGER_PATH, update_dock).await?; + object_server.at(MANAGER_PATH, wifi_debug).await?; object_server .at(MANAGER_PATH, wifi_power_management) .await?; @@ -733,4 +779,13 @@ mod test { .unwrap() ); } + + #[tokio::test] + async fn interface_matches_wifi_debug() { + let test = start().await.expect("start"); + + assert!(test_interface_matches::(&test.connection) + .await + .unwrap()); + } }