use std::fs;
use std::path::Path;
#[derive(Debug, Clone, Copy, Default)]
pub(crate) struct RfkillSnapshot {
pub wlan_hard_block: bool,
pub wwan_hard_block: bool,
pub bluetooth_hard_block: bool,
}
pub(crate) fn read_rfkill() -> RfkillSnapshot {
let rfkill_dir = Path::new("/sys/class/rfkill");
let entries = match fs::read_dir(rfkill_dir) {
Ok(e) => e,
Err(_) => return RfkillSnapshot::default(),
};
let mut snapshot = RfkillSnapshot::default();
for entry in entries.flatten() {
let path = entry.path();
let type_str = match fs::read_to_string(path.join("type")) {
Ok(s) => s.trim().to_string(),
Err(_) => continue,
};
let hard_blocked = match fs::read_to_string(path.join("hard")) {
Ok(s) => s.trim() == "1",
Err(_) => false,
};
if hard_blocked {
match type_str.as_str() {
"wlan" => snapshot.wlan_hard_block = true,
"wwan" => snapshot.wwan_hard_block = true,
"bluetooth" => snapshot.bluetooth_hard_block = true,
_ => {}
}
}
}
snapshot
}