Loading system/gd/rust/linux/mgmt/src/bin/btmanagerd/main.rs +16 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use dbus_tokio::connection; use log::LevelFilter; use manager_service::bluetooth_manager::BluetoothManager; use manager_service::powerd_suspend_manager::PowerdSuspendManager; use manager_service::{bluetooth_experimental_dbus, iface_bluetooth_manager}; use manager_service::{bluetooth_manager_dbus, config_util, state_machine}; use std::sync::{Arc, Mutex}; use syslog::{BasicLogger, Facility, Formatter3164}; Loading Loading @@ -121,12 +122,23 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> { &mut cr.lock().unwrap(), disconnect_watcher.clone(), ); cr.lock().unwrap().insert( "/org/chromium/bluetooth/Manager", &[iface], bluetooth_manager.clone(), // Let's add the "/org/chromium/bluetooth/Experimental" path, which implements // the org.chromium.bluetooth.Experimental interface, to the crossroads instance let iface_exp = bluetooth_experimental_dbus::export_bluetooth_experimental_dbus_intf( conn.clone(), &mut cr.lock().unwrap(), disconnect_watcher.clone(), ); // Create mixin object for Manager + Experimental interfaces. let mixin = Box::new(iface_bluetooth_manager::BluetoothManagerMixin { manager: bluetooth_manager.clone(), experimental: bluetooth_manager.clone(), }); cr.lock().unwrap().insert("/org/chromium/bluetooth/Manager", &[iface, iface_exp], mixin); // We add the Crossroads instance to the connection so that incoming method calls will be handled. let cr_clone = cr.clone(); conn.start_receive( Loading system/gd/rust/linux/mgmt/src/bluetooth_experimental_dbus.rs 0 → 100644 +23 −0 Original line number Diff line number Diff line use dbus_macros::{dbus_method, generate_dbus_exporter}; use dbus_projection::dbus_generated; use crate::dbus_arg::DBusArg; use crate::iface_bluetooth_experimental::IBluetoothExperimental; use crate::iface_bluetooth_manager::BluetoothManagerMixin; /// D-Bus projection of IBluetoothExperimental. struct BluetoothExperimentalDBus {} #[generate_dbus_exporter( export_bluetooth_experimental_dbus_intf, "org.chromium.bluetooth.Experimental", BluetoothManagerMixin, experimental )] impl IBluetoothExperimental for BluetoothExperimentalDBus { #[dbus_method("SetLLPrivacy")] fn set_ll_privacy(&mut self, enabled: bool) { dbus_generated!() } } system/gd/rust/linux/mgmt/src/bluetooth_manager.rs +20 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ use log::{error, info, warn}; use std::collections::HashMap; use std::process::Command; use crate::iface_bluetooth_experimental::IBluetoothExperimental; use crate::iface_bluetooth_manager::{ AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback, }; Loading Loading @@ -163,3 +164,22 @@ impl IBluetoothManager for BluetoothManager { self.proxy.set_desired_default_adapter(adapter_index); } } /// Implementation of IBluetoothExperimental impl IBluetoothExperimental for BluetoothManager { fn set_ll_privacy(&mut self, enabled: bool) { let current_status = match config_util::read_floss_ll_privacy_enabled() { Ok(true) => true, _ => false, }; if current_status == enabled { return; } if let Err(e) = config_util::write_floss_ll_privacy_enabled(enabled) { error!("Failed to write ll privacy status: {}", e); return; } } } system/gd/rust/linux/mgmt/src/bluetooth_manager_dbus.rs +7 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ use btstack::RPCProxy; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; use crate::iface_bluetooth_manager::{ AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback, AdapterWithEnabled, BluetoothManagerMixin, IBluetoothManager, IBluetoothManagerCallback, }; #[dbus_propmap(AdapterWithEnabled)] Loading @@ -20,7 +20,12 @@ pub struct AdapterWithEnabledDbus { /// D-Bus projection of IBluetoothManager. struct BluetoothManagerDBus {} #[generate_dbus_exporter(export_bluetooth_manager_dbus_intf, "org.chromium.bluetooth.Manager")] #[generate_dbus_exporter( export_bluetooth_manager_dbus_intf, "org.chromium.bluetooth.Manager", BluetoothManagerMixin, manager )] impl IBluetoothManager for BluetoothManagerDBus { #[dbus_method("Start")] fn start(&mut self, hci_interface: i32) { Loading system/gd/rust/linux/mgmt/src/config_util.rs +30 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ const BLUETOOTH_DAEMON_CURRENT: &str = "/var/lib/bluetooth/bluetooth-daemon.curr // File to store the config for BluetoothManager const BTMANAGERD_CONF: &str = "/var/lib/bluetooth/btmanagerd.json"; /// Folder to keep files which override floss configuration const FLOSS_SYSPROPS_OVERRIDE_DIR: &str = "/var/lib/bluetooth/sysprops.conf.d"; /// Key used for default adapter entry. const DEFAULT_ADAPTER_KEY: &str = "default_adapter"; Loading Loading @@ -178,6 +181,33 @@ pub fn reset_hci_device(hci: i32) -> bool { std::fs::write(path, "1").is_ok() } pub fn read_floss_ll_privacy_enabled() -> std::io::Result<bool> { let parent = Path::new(FLOSS_SYSPROPS_OVERRIDE_DIR); if !parent.is_dir() { return Ok(false); } let data = std::fs::read_to_string(format!( "{}/{}", FLOSS_SYSPROPS_OVERRIDE_DIR, "privacy_override.conf" ))?; Ok(data == "[Sysprops]\nbluetooth.core.gap.le.privacy.enabled=true\n") } pub fn write_floss_ll_privacy_enabled(enabled: bool) -> std::io::Result<()> { let parent = Path::new(FLOSS_SYSPROPS_OVERRIDE_DIR); std::fs::create_dir_all(parent)?; let data = format!( "[Sysprops]\nbluetooth.core.gap.le.privacy.enabled={}", if enabled { "true\n" } else { "false\n" } ); std::fs::write(format!("{}/{}", FLOSS_SYSPROPS_OVERRIDE_DIR, "privacy_override.conf"), data) } #[cfg(test)] mod tests { use super::*; Loading Loading
system/gd/rust/linux/mgmt/src/bin/btmanagerd/main.rs +16 −4 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use dbus_tokio::connection; use log::LevelFilter; use manager_service::bluetooth_manager::BluetoothManager; use manager_service::powerd_suspend_manager::PowerdSuspendManager; use manager_service::{bluetooth_experimental_dbus, iface_bluetooth_manager}; use manager_service::{bluetooth_manager_dbus, config_util, state_machine}; use std::sync::{Arc, Mutex}; use syslog::{BasicLogger, Facility, Formatter3164}; Loading Loading @@ -121,12 +122,23 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> { &mut cr.lock().unwrap(), disconnect_watcher.clone(), ); cr.lock().unwrap().insert( "/org/chromium/bluetooth/Manager", &[iface], bluetooth_manager.clone(), // Let's add the "/org/chromium/bluetooth/Experimental" path, which implements // the org.chromium.bluetooth.Experimental interface, to the crossroads instance let iface_exp = bluetooth_experimental_dbus::export_bluetooth_experimental_dbus_intf( conn.clone(), &mut cr.lock().unwrap(), disconnect_watcher.clone(), ); // Create mixin object for Manager + Experimental interfaces. let mixin = Box::new(iface_bluetooth_manager::BluetoothManagerMixin { manager: bluetooth_manager.clone(), experimental: bluetooth_manager.clone(), }); cr.lock().unwrap().insert("/org/chromium/bluetooth/Manager", &[iface, iface_exp], mixin); // We add the Crossroads instance to the connection so that incoming method calls will be handled. let cr_clone = cr.clone(); conn.start_receive( Loading
system/gd/rust/linux/mgmt/src/bluetooth_experimental_dbus.rs 0 → 100644 +23 −0 Original line number Diff line number Diff line use dbus_macros::{dbus_method, generate_dbus_exporter}; use dbus_projection::dbus_generated; use crate::dbus_arg::DBusArg; use crate::iface_bluetooth_experimental::IBluetoothExperimental; use crate::iface_bluetooth_manager::BluetoothManagerMixin; /// D-Bus projection of IBluetoothExperimental. struct BluetoothExperimentalDBus {} #[generate_dbus_exporter( export_bluetooth_experimental_dbus_intf, "org.chromium.bluetooth.Experimental", BluetoothManagerMixin, experimental )] impl IBluetoothExperimental for BluetoothExperimentalDBus { #[dbus_method("SetLLPrivacy")] fn set_ll_privacy(&mut self, enabled: bool) { dbus_generated!() } }
system/gd/rust/linux/mgmt/src/bluetooth_manager.rs +20 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ use log::{error, info, warn}; use std::collections::HashMap; use std::process::Command; use crate::iface_bluetooth_experimental::IBluetoothExperimental; use crate::iface_bluetooth_manager::{ AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback, }; Loading Loading @@ -163,3 +164,22 @@ impl IBluetoothManager for BluetoothManager { self.proxy.set_desired_default_adapter(adapter_index); } } /// Implementation of IBluetoothExperimental impl IBluetoothExperimental for BluetoothManager { fn set_ll_privacy(&mut self, enabled: bool) { let current_status = match config_util::read_floss_ll_privacy_enabled() { Ok(true) => true, _ => false, }; if current_status == enabled { return; } if let Err(e) = config_util::write_floss_ll_privacy_enabled(enabled) { error!("Failed to write ll privacy status: {}", e); return; } } }
system/gd/rust/linux/mgmt/src/bluetooth_manager_dbus.rs +7 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ use btstack::RPCProxy; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; use crate::iface_bluetooth_manager::{ AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback, AdapterWithEnabled, BluetoothManagerMixin, IBluetoothManager, IBluetoothManagerCallback, }; #[dbus_propmap(AdapterWithEnabled)] Loading @@ -20,7 +20,12 @@ pub struct AdapterWithEnabledDbus { /// D-Bus projection of IBluetoothManager. struct BluetoothManagerDBus {} #[generate_dbus_exporter(export_bluetooth_manager_dbus_intf, "org.chromium.bluetooth.Manager")] #[generate_dbus_exporter( export_bluetooth_manager_dbus_intf, "org.chromium.bluetooth.Manager", BluetoothManagerMixin, manager )] impl IBluetoothManager for BluetoothManagerDBus { #[dbus_method("Start")] fn start(&mut self, hci_interface: i32) { Loading
system/gd/rust/linux/mgmt/src/config_util.rs +30 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,9 @@ const BLUETOOTH_DAEMON_CURRENT: &str = "/var/lib/bluetooth/bluetooth-daemon.curr // File to store the config for BluetoothManager const BTMANAGERD_CONF: &str = "/var/lib/bluetooth/btmanagerd.json"; /// Folder to keep files which override floss configuration const FLOSS_SYSPROPS_OVERRIDE_DIR: &str = "/var/lib/bluetooth/sysprops.conf.d"; /// Key used for default adapter entry. const DEFAULT_ADAPTER_KEY: &str = "default_adapter"; Loading Loading @@ -178,6 +181,33 @@ pub fn reset_hci_device(hci: i32) -> bool { std::fs::write(path, "1").is_ok() } pub fn read_floss_ll_privacy_enabled() -> std::io::Result<bool> { let parent = Path::new(FLOSS_SYSPROPS_OVERRIDE_DIR); if !parent.is_dir() { return Ok(false); } let data = std::fs::read_to_string(format!( "{}/{}", FLOSS_SYSPROPS_OVERRIDE_DIR, "privacy_override.conf" ))?; Ok(data == "[Sysprops]\nbluetooth.core.gap.le.privacy.enabled=true\n") } pub fn write_floss_ll_privacy_enabled(enabled: bool) -> std::io::Result<()> { let parent = Path::new(FLOSS_SYSPROPS_OVERRIDE_DIR); std::fs::create_dir_all(parent)?; let data = format!( "[Sysprops]\nbluetooth.core.gap.le.privacy.enabled={}", if enabled { "true\n" } else { "false\n" } ); std::fs::write(format!("{}/{}", FLOSS_SYSPROPS_OVERRIDE_DIR, "privacy_override.conf"), data) } #[cfg(test)] mod tests { use super::*; Loading