mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-10 00:20:29 -04:00
wifi: Switch from iwconfig to iw, don't hardcode interfaces
This commit is contained in:
parent
a41264635b
commit
90582f5eb6
1 changed files with 32 additions and 10 deletions
44
src/wifi.rs
44
src/wifi.rs
|
@ -227,16 +227,32 @@ pub(crate) 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(crate) async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
pub(crate) async fn list_wifi_interfaces() -> Result<Vec<String>> {
|
||||||
let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?;
|
let output = script_output("/usr/bin/iw", &["dev"]).await?;
|
||||||
for line in output.lines() {
|
Ok(output
|
||||||
return Ok(match line.trim() {
|
.lines()
|
||||||
"Power Management:on" => WifiPowerManagement::Enabled,
|
.filter_map(|line| match line.trim().split_once(' ') {
|
||||||
"Power Management:off" => WifiPowerManagement::Disabled,
|
Some(("Interface", name)) => Some(name.to_string()),
|
||||||
_ => continue,
|
_ => None,
|
||||||
});
|
})
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
bail!("Failed to query power management state")
|
|
||||||
|
pub(crate) async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
|
||||||
|
let mut found_any = false;
|
||||||
|
for iface in list_wifi_interfaces().await? {
|
||||||
|
let output =
|
||||||
|
script_output("/usr/bin/iw", &["dev", iface.as_str(), "get", "power_save"]).await?;
|
||||||
|
for line in output.lines() {
|
||||||
|
match line.trim() {
|
||||||
|
"Power save: on" => return Ok(WifiPowerManagement::Enabled),
|
||||||
|
"Power save: off" => found_any = true,
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensure!(found_any, "No interfaces found");
|
||||||
|
Ok(WifiPowerManagement::Disabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> {
|
pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> {
|
||||||
|
@ -245,9 +261,15 @@ pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement)
|
||||||
WifiPowerManagement::Enabled => "on",
|
WifiPowerManagement::Enabled => "on",
|
||||||
};
|
};
|
||||||
|
|
||||||
run_script("/usr/bin/iwconfig", &["wlan0", "power", state])
|
for iface in list_wifi_interfaces().await? {
|
||||||
|
run_script(
|
||||||
|
"/usr/bin/iw",
|
||||||
|
&["dev", iface.as_str(), "set", "power_save", state],
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.inspect_err(|message| error!("Error setting wifi power management state: {message}"))
|
.inspect_err(|message| error!("Error setting wifi power management state: {message}"))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue