From cd241445b45cf2d8bea9301f15e099e4b01c5b50 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 23 Jan 2024 10:48:31 -0700 Subject: [PATCH 1/7] wifidebug: Add some iwd override and a way to enable/disable. Adds set_wifi_debug_mode to enable or disable wifi debug mode. Parameters are mode (0 for off, 1 for on for now, expandable in the future if more modes are needed). buffer_size: a size in kilobytes per cpu (so 16 on the deck) for the ring buffer that debug messages will get written into. For now just adds or removes a iwd debug mode override and restarts iwd. next will add some trace-cmd commands to write the debug messages to a file on disk. Signed-off-by: Jeremy Whiting --- src/main.rs | 2 +- src/manager.rs | 85 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e5c2ec4..bed6c57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<()> { // This daemon is responsible for creating a dbus api that steam client can use to do various OS // level things. It implements com.steampowered.SteamOSManager1 interface - let manager = manager::SMManager {}; + let manager = manager::SMManager::new(); let _system_connection = ConnectionBuilder::system()? .name("com.steampowered.SteamOSManager1")? diff --git a/src/manager.rs b/src/manager.rs index ea78a17..3840fcf 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -30,7 +30,35 @@ use std::{ use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use zbus::zvariant::OwnedFd; use zbus_macros::dbus_interface; -pub struct SMManager {} + +pub struct SMManager { + wifi_debug_mode: u32, +} + +impl SMManager +{ + pub fn new() -> Self + { + SMManager { wifi_debug_mode: 0 } + } +} + +impl Default for SMManager +{ + fn default() -> Self + { + SMManager::new() + } + +} + +const OVERRIDE_CONTENTS: &str = +"[Service] +ExecStart= +ExecStart=/usr/lib/iwd/iwd -d +"; +const OVERRIDE_FOLDER: &str = "/etc/systemd/system/iwd.service.d"; +const OVERRIDE_PATH: &str = "/etc/systemd/system/iwd.service.d/override.conf"; async fn script_exit_code( executable: &str, @@ -73,6 +101,35 @@ async fn script_output( Ok(s.to_string()) } +async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> +{ + // Copy override.conf file into place or out of place depending + // on install value + + if want_override { + // Copy it in + // Make sure the folder exists + tokio::fs::create_dir(OVERRIDE_FOLDER).await?; + // Then write the contents into the file + tokio::fs::write(OVERRIDE_PATH, OVERRIDE_CONTENTS).await + } else { + // Delete it + tokio::fs::remove_file(OVERRIDE_PATH).await + } +} + +async fn reload_systemd() -> bool +{ + // Reload systemd so it will see our add or removal of changed files + run_script("reload systemd", "systemctl", &["daemon-reload"]).await +} + +async fn restart_iwd() -> bool +{ + // Restart the iwd service by running "systemctl restart iwd" + run_script("restart iwd", "systemctl", &["restart", "iwd"]).await +} + #[dbus_interface(name = "com.steampowered.SteamOSManager1")] impl SMManager { const API_VERSION: u32 = 1; @@ -333,6 +390,32 @@ impl SMManager { } } + async fn set_wifi_debug_mode(&mut self, mode: u32, buffer_size: u32) -> bool { + // Set the wifi debug mode to mode, using an int for flexibility going forward but only + // doing things on 0 or 1 for now + // Return false on error + + // If mode is 0 disable wifi debug mode + if mode == 0 { + let _ = setup_iwd_config(false).await; + reload_systemd().await; + restart_iwd().await; + } + // If mode is 1 enable wifi debug mode + else if mode == 1 { + let _ = setup_iwd_config(true).await; + reload_systemd().await; + restart_iwd().await; + } + else { + // Invalid mode requested, more coming later, but add this catch-all for now + println!("Invalid wifi debug mode {mode} requested"); + } + self.wifi_debug_mode = mode; + + true + } + /// A version property. #[dbus_interface(property)] async fn version(&self) -> u32 { From 07e3843c3f5ab6aa011e0cd2cb296030f0477751 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 23 Jan 2024 11:00:35 -0700 Subject: [PATCH 2/7] wifidebug: Add trace-cmd usage to start and stop gathering data. When wifi debug mode is started trace-cmd start is executed with the given buffer_size parameter. Later when wifi debug mode is stopped, trace-cmd stop is executed as well as trace-cmd extract to write the data to a file on disk. In this way the steam client (or any dbus users...) can decide how long to run trace-cmd for. Change to create_dir_all so we don't get errors if it exists. Signed-off-by: Jeremy Whiting --- src/manager.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/manager.rs b/src/manager.rs index 3840fcf..d7dadb3 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -59,6 +59,10 @@ ExecStart=/usr/lib/iwd/iwd -d "; const OVERRIDE_FOLDER: &str = "/etc/systemd/system/iwd.service.d"; const OVERRIDE_PATH: &str = "/etc/systemd/system/iwd.service.d/override.conf"; +// Only use one path for output for now. If needed we can add a timestamp later +// to have multiple files, etc. +const OUTPUT_FILE: &str = "/var/log/wifitrace.dat"; +const MIN_BUFFER_SIZE: u32 = 100; async fn script_exit_code( executable: &str, @@ -109,7 +113,7 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> if want_override { // Copy it in // Make sure the folder exists - tokio::fs::create_dir(OVERRIDE_FOLDER).await?; + tokio::fs::create_dir_all(OVERRIDE_FOLDER).await?; // Then write the contents into the file tokio::fs::write(OVERRIDE_PATH, OVERRIDE_CONTENTS).await } else { @@ -130,6 +134,20 @@ async fn restart_iwd() -> bool run_script("restart iwd", "systemctl", &["restart", "iwd"]).await } +async fn stop_tracing() -> bool +{ + // Stop tracing and extract ring buffer to disk for capture + run_script("stop tracing", "trace-cmd", &["stop"]).await; + run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await +} + +async fn start_tracing(buffer_size:u32) -> bool +{ + // Start tracing + let size_str = format!("{}", buffer_size); + run_script("start tracing", "trace-cmd", &["start", "-e", "ath11k_wmi_diag", "-b", &size_str]).await +} + #[dbus_interface(name = "com.steampowered.SteamOSManager1")] impl SMManager { const API_VERSION: u32 = 1; @@ -397,15 +415,22 @@ impl SMManager { // If mode is 0 disable wifi debug mode if mode == 0 { + // Stop any existing trace and flush to disk. + stop_tracing().await; let _ = setup_iwd_config(false).await; reload_systemd().await; restart_iwd().await; } // If mode is 1 enable wifi debug mode else if mode == 1 { + if buffer_size < MIN_BUFFER_SIZE { + return false; + } + let _ = setup_iwd_config(true).await; reload_systemd().await; restart_iwd().await; + start_tracing(buffer_size).await; } else { // Invalid mode requested, more coming later, but add this catch-all for now From 40d25971c90f6ffdde0e909ffeaf80d9c9d61b66 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 30 Jan 2024 19:23:11 -0700 Subject: [PATCH 3/7] wifidebug: Make WifiDebugMode a real enum with parsing from u32 for dbus. Changed mode parameter from i32 to u32 as well. Change from Result> to std::io::Result Adjust the xml to add the new method. Make all private api use Result<()> types so we can do error checking. Signed-off-by: Jeremy Whiting --- com.steampowered.SteamOSManager1.xml | 13 +++ src/manager.rs | 168 ++++++++++++++++++--------- 2 files changed, 126 insertions(+), 55 deletions(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index 2a87afb..1c1748b 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -182,6 +182,19 @@ + + + + + + diff --git a/src/manager.rs b/src/manager.rs index d7dadb3..71ca16b 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -23,23 +23,50 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use std::{ - ffi::OsStr, - os::fd::{FromRawFd, IntoRawFd}, -}; +use std::{ ffi::OsStr, fmt, os::fd::{FromRawFd, IntoRawFd} }; use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use zbus::zvariant::OwnedFd; use zbus_macros::dbus_interface; +#[derive(PartialEq, Debug)] +#[repr(u32)] +enum WifiDebugMode { + Off, + On, +} + +impl TryFrom for WifiDebugMode { + type Error = &'static str; + fn try_from(v: u32) -> Result + { + match v { + x if x == WifiDebugMode::Off as u32 => Ok(WifiDebugMode::Off), + x if x == WifiDebugMode::On as u32 => Ok(WifiDebugMode::On), + _ => { Err("No enum match for value {v}") }, + } + + } + +} + +impl fmt::Display for WifiDebugMode { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + WifiDebugMode::Off => write!(f, "Off"), + WifiDebugMode::On => write!(f, "On"), + } + } +} + pub struct SMManager { - wifi_debug_mode: u32, + wifi_debug_mode: WifiDebugMode, } impl SMManager { pub fn new() -> Self { - SMManager { wifi_debug_mode: 0 } + SMManager { wifi_debug_mode: WifiDebugMode::Off } } } @@ -67,24 +94,23 @@ const MIN_BUFFER_SIZE: u32 = 100; async fn script_exit_code( executable: &str, args: &[impl AsRef], -) -> Result> { +) -> std::io::Result { // Run given script and return true on success let mut child = Command::new(executable) .args(args) - .spawn() - .expect("Failed to spawn {executable}"); + .spawn()?; let status = child.wait().await?; Ok(status.success()) } -async fn run_script(name: &str, executable: &str, args: &[impl AsRef]) -> bool { +async fn run_script(name: &str, executable: &str, args: &[impl AsRef]) -> std::io::Result { // Run given script to get exit code and return true on success. // Return false on failure, but also print an error if needed match script_exit_code(executable, args).await { - Ok(value) => value, + Ok(value) => Ok(value), Err(err) => { println!("Error running {} {}", name, err); - false + Err(err) } } } @@ -122,26 +148,26 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> } } -async fn reload_systemd() -> bool +async fn reload_systemd() -> std::io::Result { // Reload systemd so it will see our add or removal of changed files run_script("reload systemd", "systemctl", &["daemon-reload"]).await } -async fn restart_iwd() -> bool +async fn restart_iwd() -> std::io::Result { // Restart the iwd service by running "systemctl restart iwd" run_script("restart iwd", "systemctl", &["restart", "iwd"]).await } -async fn stop_tracing() -> bool +async fn stop_tracing() -> std::io::Result { // Stop tracing and extract ring buffer to disk for capture - run_script("stop tracing", "trace-cmd", &["stop"]).await; + run_script("stop tracing", "trace-cmd", &["stop"]).await?; run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await } -async fn start_tracing(buffer_size:u32) -> bool +async fn start_tracing(buffer_size:u32) -> std::io::Result { // Start tracing let size_str = format!("{}", buffer_size); @@ -158,42 +184,57 @@ impl SMManager { async fn factory_reset(&self) -> bool { // Run steamos factory reset script and return true on success - run_script("factory reset", "steamos-factory-reset-config", &[""]).await + match run_script("factory reset", "steamos-factory-reset-config", &[""]).await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn disable_wifi_power_management(&self) -> bool { // Run polkit helper script and return true on success - run_script( + match run_script( "disable wifi power management", "/usr/bin/steamos-polkit-helpers/steamos-disable-wireless-power-management", &[""], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn enable_fan_control(&self, enable: bool) -> bool { // Run what steamos-polkit-helpers/jupiter-fan-control does if enable { - run_script( + match run_script( "enable fan control", "systemcltl", &["start", "jupiter-fan-control-service"], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } else { - run_script( + match run_script( "disable fan control", "systemctl", &["stop", "jupiter-fan-control.service"], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } } async fn hardware_check_support(&self) -> bool { // Run jupiter-check-support note this script does exit 1 for "Support: No" case // so no need to parse output, etc. - run_script("check hardware support", "jupiter-check-support", &[""]).await + match run_script("check hardware support", "jupiter-check-support", &[""]).await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn read_als_calibration(&self) -> f32 { @@ -215,45 +256,57 @@ impl SMManager { async fn update_bios(&self) -> bool { // Update the bios as needed // Return true if the script was successful (though that might mean no update was needed), false otherwise - run_script( + match run_script( "update bios", "/usr/bin/steamos-potlkit-helpers/jupiter-biosupdate", &["--auto"], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn update_dock(&self) -> bool { // Update the dock firmware as needed // Retur true if successful, false otherwise - run_script( + match run_script( "update dock firmware", "/usr/bin/steamos-polkit-helpers/jupiter-dock-updater", &[""], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn trim_devices(&self) -> bool { // Run steamos-trim-devices script // return true on success, false otherwise - run_script( + match run_script( "trim devices", "/usr/bin/steamos-polkit-helpers/steamos-trim-devices", &[""], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn format_sdcard(&self) -> bool { // Run steamos-format-sdcard script // return true on success, false otherwise - run_script( + match run_script( "format sdcard", "/usr/bin/steamos-polkit-helpers/steamos-format-sdcard", &[""], ) - .await + .await { + Ok(value) => { value }, + Err(_) => { false } + } } async fn set_gpu_performance_level(&self, level: i32) -> bool { @@ -413,30 +466,35 @@ impl SMManager { // doing things on 0 or 1 for now // Return false on error - // If mode is 0 disable wifi debug mode - if mode == 0 { - // Stop any existing trace and flush to disk. - stop_tracing().await; - let _ = setup_iwd_config(false).await; - reload_systemd().await; - restart_iwd().await; - } - // If mode is 1 enable wifi debug mode - else if mode == 1 { - if buffer_size < MIN_BUFFER_SIZE { - return false; - } + let wanted_mode = WifiDebugMode::try_from(mode); + match wanted_mode { + Ok(WifiDebugMode::Off) => { + // If mode is 0 disable wifi debug mode + // Stop any existing trace and flush to disk. + stop_tracing().await.expect("stop_tracing command failed somehow"); + setup_iwd_config(false).await.expect("setup_iwd_config false command failed somehow"); + reload_systemd().await.expect("reload_systemd command failed somehow"); + restart_iwd().await.expect("restart_iwd command failed somehow"); + self.wifi_debug_mode = WifiDebugMode::Off; + }, + Ok(WifiDebugMode::On) => { + // If mode is 1 enable wifi debug mode + if buffer_size < MIN_BUFFER_SIZE { + return false; + } - let _ = setup_iwd_config(true).await; - reload_systemd().await; - restart_iwd().await; - start_tracing(buffer_size).await; + setup_iwd_config(true).await.expect("setup_iwd_config true failed somehow"); + reload_systemd().await.expect("reload_systemd command failed somehow"); + restart_iwd().await.expect("restart_iwd command failed somehow"); + start_tracing(buffer_size).await.expect("start tracing command failed somehow"); + self.wifi_debug_mode = WifiDebugMode::On; + }, + Err(_) => { + // Invalid mode requested, more coming later, but add this catch-all for now + println!("Invalid wifi debug mode {mode} requested"); + return false; + }, } - else { - // Invalid mode requested, more coming later, but add this catch-all for now - println!("Invalid wifi debug mode {mode} requested"); - } - self.wifi_debug_mode = mode; true } From c1d195177373c2208aa875fc867dc2c9f52ad770 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Mon, 5 Feb 2024 10:58:11 -0700 Subject: [PATCH 4/7] wifidebug: Add error checking with println! statements on all failures. Signed-off-by: Jeremy Whiting --- src/manager.rs | 116 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 18 deletions(-) diff --git a/src/manager.rs b/src/manager.rs index 71ca16b..d3b0ee6 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -148,22 +148,33 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> } } -async fn reload_systemd() -> std::io::Result -{ - // Reload systemd so it will see our add or removal of changed files - run_script("reload systemd", "systemctl", &["daemon-reload"]).await -} - async fn restart_iwd() -> std::io::Result { - // Restart the iwd service by running "systemctl restart iwd" - run_script("restart iwd", "systemctl", &["restart", "iwd"]).await + // First reload systemd since we modified the config most likely + // othorwise we wouldn't be restarting iwd. + match run_script("reload systemd", "systemctl", &["daemon-reload"]).await { + Ok(value) => { + if value { + // worked, now restart iwd + run_script("restart iwd", "systemctl", &["restart", "iwd"]).await + } else { + // reload failed + println!("restart_iwd: reload systemd failed somehow"); + Ok(false) + } + }, + Err(message) => { + println!("restart_iwd: reload systemd got an error {message}"); + Err(message) + } + } } async fn stop_tracing() -> std::io::Result { // Stop tracing and extract ring buffer to disk for capture run_script("stop tracing", "trace-cmd", &["stop"]).await?; + // stop tracing worked run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await } @@ -471,11 +482,46 @@ impl SMManager { Ok(WifiDebugMode::Off) => { // If mode is 0 disable wifi debug mode // Stop any existing trace and flush to disk. - stop_tracing().await.expect("stop_tracing command failed somehow"); - setup_iwd_config(false).await.expect("setup_iwd_config false command failed somehow"); - reload_systemd().await.expect("reload_systemd command failed somehow"); - restart_iwd().await.expect("restart_iwd command failed somehow"); - self.wifi_debug_mode = WifiDebugMode::Off; + match stop_tracing().await { + Ok(result) => { + if result { + // Stop_tracing was successful + match setup_iwd_config(false).await { + Ok(_) => { + // setup_iwd_config false worked + match restart_iwd().await { + Ok(value) => { + if value { + // restart iwd worked + self.wifi_debug_mode = WifiDebugMode::Off; + } else { + // restart_iwd failed + println!("restart_iwd failed somehow, check log above"); + return false; + } + }, + Err(message) => { + println!("restart_iwd got an error {message}"); + return false; + } + } + }, + Err(message) => { + println!("setup_iwd_config false got an error somehow {message}"); + return false; + } + } + } else { + println!("stop_tracing command failed somehow, bailing"); + return false; + + } + }, + Err(message) => { + println!("stop_tracing command had an error {message}"); + return false; + } + } }, Ok(WifiDebugMode::On) => { // If mode is 1 enable wifi debug mode @@ -483,11 +529,45 @@ impl SMManager { return false; } - setup_iwd_config(true).await.expect("setup_iwd_config true failed somehow"); - reload_systemd().await.expect("reload_systemd command failed somehow"); - restart_iwd().await.expect("restart_iwd command failed somehow"); - start_tracing(buffer_size).await.expect("start tracing command failed somehow"); - self.wifi_debug_mode = WifiDebugMode::On; + match setup_iwd_config(true).await { + Ok(_) => { + // setup_iwd_config worked + match restart_iwd().await { + Ok(value) => { + if value { + // restart_iwd worked + match start_tracing(buffer_size).await { + Ok(value) => { + if value { + // start_tracing worked + self.wifi_debug_mode = WifiDebugMode::On; + } else { + // start_tracing failed + println!("start_tracing failed somehow"); + return false; + } + }, + Err(message) => { + println!("start_tracing got an error {message}"); + return false; + } + } + } else { + println!("restart_iwd failed somehow"); + return false; + } + }, + Err(message) => { + println!("restart_iwd got an error {message}"); + return false; + } + } + }, + Err(message) => { + println!("setup_iwd_config true got an error somehow {message}"); + return false; + } + } }, Err(_) => { // Invalid mode requested, more coming later, but add this catch-all for now From 97a79c6713c57d6dad99cba319e6a2b5d26fcd58 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 6 Feb 2024 10:14:47 -0700 Subject: [PATCH 5/7] general: Use SMManager::default() instead of ::new() in main. Signed-off-by: Jeremy Whiting --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bed6c57..0336182 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<()> { // This daemon is responsible for creating a dbus api that steam client can use to do various OS // level things. It implements com.steampowered.SteamOSManager1 interface - let manager = manager::SMManager::new(); + let manager = manager::SMManager::default(); let _system_connection = ConnectionBuilder::system()? .name("com.steampowered.SteamOSManager1")? From ec819e6d0030b0e8f9354c26dc6aa10e0eeeaf94 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 6 Feb 2024 10:16:03 -0700 Subject: [PATCH 6/7] wifidebug: Only run trace-cmd commands on Galileo devices. Differentiate Galileo devices from others by checking the contents of /sys/class/drm/id/board_name. Signed-off-by: Jeremy Whiting --- src/manager.rs | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/manager.rs b/src/manager.rs index d3b0ee6..345fdbf 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -23,7 +23,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use std::{ ffi::OsStr, fmt, os::fd::{FromRawFd, IntoRawFd} }; +use std::{ fs, ffi::OsStr, fmt, os::fd::{FromRawFd, IntoRawFd} }; use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use zbus::zvariant::OwnedFd; use zbus_macros::dbus_interface; @@ -60,13 +60,19 @@ impl fmt::Display for WifiDebugMode { pub struct SMManager { wifi_debug_mode: WifiDebugMode, + // Whether we should use trace-cmd or not. + // True on galileo devices, false otherwise + should_trace: bool, } impl SMManager { pub fn new() -> Self { - SMManager { wifi_debug_mode: WifiDebugMode::Off } + SMManager { + wifi_debug_mode: WifiDebugMode::Off, + should_trace: is_galileo().unwrap(), + } } } @@ -91,6 +97,18 @@ const OVERRIDE_PATH: &str = "/etc/systemd/system/iwd.service.d/override.conf"; const OUTPUT_FILE: &str = "/var/log/wifitrace.dat"; const MIN_BUFFER_SIZE: u32 = 100; +const BOARD_NAME_PATH: &str = "/sys/class/dmi/id/board_name"; +const GALILEO_NAME: &str = "Galileo"; + +fn is_galileo() -> std::io::Result +{ + let mut board_name = fs::read_to_string(BOARD_NAME_PATH)?; + board_name = board_name.trim().to_string(); + + let matches = board_name == GALILEO_NAME; + Ok(matches) +} + async fn script_exit_code( executable: &str, args: &[impl AsRef], @@ -170,16 +188,24 @@ async fn restart_iwd() -> std::io::Result } } -async fn stop_tracing() -> std::io::Result +async fn stop_tracing(should_trace: bool) -> std::io::Result { + if !should_trace { + return Ok(true); + } + // Stop tracing and extract ring buffer to disk for capture run_script("stop tracing", "trace-cmd", &["stop"]).await?; // stop tracing worked run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await } -async fn start_tracing(buffer_size:u32) -> std::io::Result +async fn start_tracing(buffer_size:u32, should_trace: bool) -> std::io::Result { + if !should_trace { + return Ok(true); + } + // Start tracing let size_str = format!("{}", buffer_size); run_script("start tracing", "trace-cmd", &["start", "-e", "ath11k_wmi_diag", "-b", &size_str]).await @@ -482,7 +508,7 @@ impl SMManager { Ok(WifiDebugMode::Off) => { // If mode is 0 disable wifi debug mode // Stop any existing trace and flush to disk. - match stop_tracing().await { + match stop_tracing(self.should_trace).await { Ok(result) => { if result { // Stop_tracing was successful @@ -536,7 +562,7 @@ impl SMManager { Ok(value) => { if value { // restart_iwd worked - match start_tracing(buffer_size).await { + match start_tracing(buffer_size, self.should_trace).await { Ok(value) => { if value { // start_tracing worked From ce95a53ee85862b7fa9fd4271b9a8712d5ad9678 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Wed, 7 Feb 2024 14:23:31 -0700 Subject: [PATCH 7/7] wifidebug: Add GetWifiDebugMode to get the current wifi debug mode. This may be useful in cases where SetWifiDebugMode has failed to check what the current state/setting is. Though if SetWifiDebugMode has failed we may be in weird state so logs of steamos-manager should be checked to see what failed. Signed-off-by: Jeremy Whiting --- com.steampowered.SteamOSManager1.xml | 10 ++++++++++ src/manager.rs | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/com.steampowered.SteamOSManager1.xml b/com.steampowered.SteamOSManager1.xml index 1c1748b..f1194d6 100644 --- a/com.steampowered.SteamOSManager1.xml +++ b/com.steampowered.SteamOSManager1.xml @@ -195,6 +195,16 @@ + + + + + diff --git a/src/manager.rs b/src/manager.rs index 345fdbf..513c406 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -28,7 +28,7 @@ use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use zbus::zvariant::OwnedFd; use zbus_macros::dbus_interface; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] enum WifiDebugMode { Off, @@ -498,6 +498,11 @@ impl SMManager { } } + async fn get_wifi_debug_mode(&mut self) -> u32 { + // Get the wifi debug mode + self.wifi_debug_mode as u32 + } + async fn set_wifi_debug_mode(&mut self, mode: u32, buffer_size: u32) -> bool { // Set the wifi debug mode to mode, using an int for flexibility going forward but only // doing things on 0 or 1 for now