mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-15 10:46:41 -04:00
Add support to get/set WiFi back-end
This change implements the ability to get and set the WiFi back-end, by leveraging a new script created for that purpose. The idea is to be able to use 'wpa_supplicant' (which is the default back-end in NetworkManager upstream) when 'iwd' (the default in SteamOS) does not work for some reason. This change interacts with another feature of steamos-manager, which is to set debug mode for WiFi. Handling debug mode complicates things substantially because those methods write config for 'iwd' and restart the daemons/systemd units, with many interdependencies. Instead of trying to implement all at once and attempt feature-parity between back-ends on this aspect from the start, as a first step the operations are just declared incompatible. As a result, if WifiDebugMode=on the back-end cannot be changed, and conversely the WifiDebugMode cannot be turned on when the back-end is 'wpa_supplicant'. Co-authored-by: Manuel A. Fernandez Montecelo <mafm@igalia.com>
This commit is contained in:
parent
452690adee
commit
b0628fc7b9
3 changed files with 125 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright © 2023 Collabora Ltd.
|
||||
* Copyright © 2024 Valve Software
|
||||
* Copyright © 2024 Igalia S.L.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
@ -17,7 +18,10 @@ use crate::power::{
|
|||
GPUPerformanceLevel,
|
||||
};
|
||||
use crate::process::{run_script, script_output, SYSTEMCTL_PATH};
|
||||
use crate::wifi::{set_wifi_debug_mode, WifiDebugMode, WifiPowerManagement};
|
||||
use crate::wifi::{
|
||||
get_wifi_backend_from_conf, get_wifi_backend_from_script, set_wifi_backend,
|
||||
set_wifi_debug_mode, WifiBackend, WifiDebugMode, WifiPowerManagement,
|
||||
};
|
||||
use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo};
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
|
@ -55,6 +59,7 @@ impl fmt::Display for FanControl {
|
|||
}
|
||||
|
||||
pub struct SteamOSManager {
|
||||
wifi_backend: WifiBackend,
|
||||
wifi_debug_mode: WifiDebugMode,
|
||||
// Whether we should use trace-cmd or not.
|
||||
// True on galileo devices, false otherwise
|
||||
|
@ -64,6 +69,7 @@ pub struct SteamOSManager {
|
|||
impl SteamOSManager {
|
||||
pub async fn new() -> Result<Self> {
|
||||
Ok(SteamOSManager {
|
||||
wifi_backend: get_wifi_backend_from_conf().await?,
|
||||
wifi_debug_mode: WifiDebugMode::Off,
|
||||
should_trace: variant().await? == HardwareVariant::Galileo,
|
||||
})
|
||||
|
@ -263,6 +269,35 @@ impl SteamOSManager {
|
|||
self.wifi_debug_mode as u32
|
||||
}
|
||||
|
||||
/// WifiBackend property.
|
||||
#[zbus(property)]
|
||||
async fn wifi_backend(&self) -> u32 {
|
||||
self.wifi_backend as u32
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_wifi_backend(&mut self, backend: u32) -> zbus::fdo::Result<()> {
|
||||
if self.wifi_debug_mode == WifiDebugMode::On {
|
||||
return Err(zbus::fdo::Error::Failed(String::from(
|
||||
"operation not supported when wifi_debug_mode=on",
|
||||
)));
|
||||
}
|
||||
let backend = match WifiBackend::try_from(backend) {
|
||||
Ok(backend) => backend,
|
||||
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
|
||||
};
|
||||
match set_wifi_backend(backend).await {
|
||||
Ok(()) => {
|
||||
self.wifi_backend = backend;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Setting wifi backend failed: {e}");
|
||||
Err(anyhow_to_zbus_fdo(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_wifi_debug_mode(
|
||||
&mut self,
|
||||
mode: u32,
|
||||
|
@ -271,6 +306,15 @@ impl SteamOSManager {
|
|||
// 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
|
||||
match get_wifi_backend_from_script().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) {
|
||||
Ok(mode) => mode,
|
||||
|
@ -319,6 +363,12 @@ mod test {
|
|||
write(crate::path("/sys/class/dmi/id/board_name"), "Jupiter\n")
|
||||
.await
|
||||
.expect("write");
|
||||
create_dir_all(crate::path("/etc/NetworkManager/conf.d"))
|
||||
.await
|
||||
.expect("create_dir_all");
|
||||
write(crate::path("/etc/NetworkManager/conf.d/wifi_backend.conf"), "wifi.backend=iwd\n")
|
||||
.await
|
||||
.expect("write");
|
||||
|
||||
let manager = SteamOSManager::new().await.unwrap();
|
||||
let connection = ConnectionBuilder::session()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue