mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 18:02:00 -04:00
wifi: Move more logic out of the manager
This commit is contained in:
parent
5b612fb7a2
commit
f3d8e97633
2 changed files with 35 additions and 35 deletions
|
@ -21,8 +21,8 @@ use crate::power::{
|
||||||
use crate::process::{run_script, script_output};
|
use crate::process::{run_script, script_output};
|
||||||
use crate::systemd::SystemdUnit;
|
use crate::systemd::SystemdUnit;
|
||||||
use crate::wifi::{
|
use crate::wifi::{
|
||||||
get_wifi_backend, set_wifi_backend, set_wifi_debug_mode, WifiBackend, WifiDebugMode,
|
get_wifi_backend, get_wifi_power_management_state, set_wifi_backend, set_wifi_debug_mode,
|
||||||
WifiPowerManagement,
|
set_wifi_power_management_state, WifiBackend, WifiDebugMode, WifiPowerManagement,
|
||||||
};
|
};
|
||||||
use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo};
|
use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo};
|
||||||
|
|
||||||
|
@ -95,19 +95,10 @@ impl SteamOSManager {
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "false"))]
|
#[zbus(property(emits_changed_signal = "false"))]
|
||||||
async fn wifi_power_management_state(&self) -> zbus::fdo::Result<u32> {
|
async fn wifi_power_management_state(&self) -> zbus::fdo::Result<u32> {
|
||||||
let output = script_output("/usr/bin/iwconfig", &["wlan0"])
|
match get_wifi_power_management_state().await {
|
||||||
.await
|
Ok(state) => Ok(state as u32),
|
||||||
.map_err(anyhow_to_zbus_fdo)?;
|
Err(e) => Err(anyhow_to_zbus_fdo(e)),
|
||||||
for line in output.lines() {
|
|
||||||
return Ok(match line.trim() {
|
|
||||||
"Power Management:on" => WifiPowerManagement::Enabled as u32,
|
|
||||||
"Power Management:off" => WifiPowerManagement::Disabled as u32,
|
|
||||||
_ => continue,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(zbus::fdo::Error::Failed(String::from(
|
|
||||||
"Failed to query power management state",
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
|
@ -116,14 +107,8 @@ impl SteamOSManager {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()),
|
Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()),
|
||||||
};
|
};
|
||||||
let state = match state {
|
set_wifi_power_management_state(state)
|
||||||
WifiPowerManagement::Disabled => "off",
|
|
||||||
WifiPowerManagement::Enabled => "on",
|
|
||||||
};
|
|
||||||
|
|
||||||
run_script("/usr/bin/iwconfig", &["wlan0", "power", state])
|
|
||||||
.await
|
.await
|
||||||
.inspect_err(|message| error!("Error setting wifi power management state: {message}"))
|
|
||||||
.map_err(anyhow_to_zbus)
|
.map_err(anyhow_to_zbus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,16 +314,6 @@ impl SteamOSManager {
|
||||||
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
||||||
// doing things on 0 or 1 for now
|
// doing things on 0 or 1 for now
|
||||||
// Return false on error
|
// Return false on error
|
||||||
match get_wifi_backend().await {
|
|
||||||
Ok(WifiBackend::Iwd) => (),
|
|
||||||
Ok(backend) => {
|
|
||||||
return Err(zbus::fdo::Error::Failed(format!(
|
|
||||||
"Setting wifi debug mode not supported when backend is {backend}",
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Err(e) => return Err(anyhow_to_zbus_fdo(e)),
|
|
||||||
}
|
|
||||||
|
|
||||||
let wanted_mode = match WifiDebugMode::try_from(mode) {
|
let wanted_mode = match WifiDebugMode::try_from(mode) {
|
||||||
Ok(mode) => mode,
|
Ok(mode) => mode,
|
||||||
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
|
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
|
||||||
|
|
33
src/wifi.rs
33
src/wifi.rs
|
@ -13,7 +13,7 @@ use tracing::error;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
use crate::path;
|
use crate::path;
|
||||||
use crate::process::run_script;
|
use crate::process::{run_script, script_output};
|
||||||
use crate::systemd::{daemon_reload, SystemdUnit};
|
use crate::systemd::{daemon_reload, SystemdUnit};
|
||||||
|
|
||||||
const OVERRIDE_CONTENTS: &str = "[Service]
|
const OVERRIDE_CONTENTS: &str = "[Service]
|
||||||
|
@ -180,9 +180,11 @@ pub async fn set_wifi_debug_mode(
|
||||||
should_trace: bool,
|
should_trace: bool,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Set the wifi debug mode to mode, using an int for flexibility going forward but only
|
match get_wifi_backend().await {
|
||||||
// doing things on 0 or 1 for now
|
Ok(WifiBackend::Iwd) => (),
|
||||||
// Return false on error
|
Ok(backend) => bail!("Setting wifi debug mode not supported when backend is {backend}"),
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
WifiDebugMode::Off => {
|
WifiDebugMode::Off => {
|
||||||
|
@ -242,6 +244,29 @@ pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> {
|
||||||
run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await
|
run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
||||||
|
let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?;
|
||||||
|
for line in output.lines() {
|
||||||
|
return Ok(match line.trim() {
|
||||||
|
"Power Management:on" => WifiPowerManagement::Enabled,
|
||||||
|
"Power Management:off" => WifiPowerManagement::Disabled,
|
||||||
|
_ => continue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
bail!("Failed to query power management state")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> {
|
||||||
|
let state = match state {
|
||||||
|
WifiPowerManagement::Disabled => "off",
|
||||||
|
WifiPowerManagement::Enabled => "on",
|
||||||
|
};
|
||||||
|
|
||||||
|
run_script("/usr/bin/iwconfig", &["wlan0", "power", state])
|
||||||
|
.await
|
||||||
|
.inspect_err(|message| error!("Error setting wifi power management state: {message}"))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue