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 <jeremy.whiting@collabora.com>
This commit is contained in:
Jeremy Whiting 2024-01-23 10:48:31 -07:00
parent 78d0d6e458
commit cd241445b4
2 changed files with 85 additions and 2 deletions

View file

@ -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 // 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 // level things. It implements com.steampowered.SteamOSManager1 interface
let manager = manager::SMManager {}; let manager = manager::SMManager::new();
let _system_connection = ConnectionBuilder::system()? let _system_connection = ConnectionBuilder::system()?
.name("com.steampowered.SteamOSManager1")? .name("com.steampowered.SteamOSManager1")?

View file

@ -30,7 +30,35 @@ use std::{
use tokio::{fs::File, io::AsyncWriteExt, process::Command}; use tokio::{fs::File, io::AsyncWriteExt, process::Command};
use zbus::zvariant::OwnedFd; use zbus::zvariant::OwnedFd;
use zbus_macros::dbus_interface; 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( async fn script_exit_code(
executable: &str, executable: &str,
@ -73,6 +101,35 @@ async fn script_output(
Ok(s.to_string()) 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")] #[dbus_interface(name = "com.steampowered.SteamOSManager1")]
impl SMManager { impl SMManager {
const API_VERSION: u32 = 1; 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. /// A version property.
#[dbus_interface(property)] #[dbus_interface(property)]
async fn version(&self) -> u32 { async fn version(&self) -> u32 {