Loading system/btcore/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ static_library("btcore") { deps = [ "//bt/gd/rust/shim:init_flags_bridge_header", "//bt/gd/rust/shim:libbluetooth_rust_interop", "//bt/gd/rust/shim:message_loop_thread_bridge_header", ] } Loading system/gd/rust/linux/client/src/dbus_iface.rs +13 −0 Original line number Diff line number Diff line //! D-Bus proxy implementations of the APIs. use bt_topshim::btif::BtSspVariant; use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback}; use btstack::RPCProxy; Loading @@ -19,6 +21,7 @@ use std::sync::{Arc, Mutex}; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); #[dbus_propmap(BluetoothDevice)] pub struct BluetoothDeviceDBus { Loading Loading @@ -98,6 +101,16 @@ impl IBluetoothCallback for IBluetoothCallbackDBus { #[dbus_method("OnDiscoveringChanged")] fn on_discovering_changed(&self, discovering: bool) {} #[dbus_method("OnSspRequest")] fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ) { } } // TODO: These are boilerplate codes, consider creating a macro to generate. Loading system/gd/rust/linux/client/src/main.rs +22 −0 Original line number Diff line number Diff line use bt_topshim::btif::BtSspVariant; use bt_topshim::topstack; use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothCallback}; Loading Loading @@ -43,6 +44,27 @@ impl IBluetoothCallback for BtCallback { fn on_discovering_changed(&self, discovering: bool) { print_info!("Discovering: {}", discovering); } fn on_ssp_request( &self, remote_device: BluetoothDevice, _cod: u32, variant: BtSspVariant, passkey: u32, ) { if variant == BtSspVariant::PasskeyNotification { print_info!( "device {}{} would like to pair, enter passkey on remote device: {:06}", remote_device.address.to_string(), if remote_device.name.len() > 0 { format!(" ({})", remote_device.name) } else { String::from("") }, passkey ); } } } impl RPCProxy for BtCallback { Loading system/gd/rust/linux/service/src/iface_bluetooth.rs +12 −0 Original line number Diff line number Diff line extern crate bt_shim; use bt_topshim::btif::BtSspVariant; use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback}; use btstack::RPCProxy; Loading Loading @@ -37,9 +39,19 @@ impl IBluetoothCallback for BluetoothCallbackDBus { fn on_device_found(&self, remote_device: BluetoothDevice) {} #[dbus_method("OnDiscoveringChanged")] fn on_discovering_changed(&self, discovering: bool) {} #[dbus_method("OnSspRequest")] fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ) { } } impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); #[allow(dead_code)] struct IBluetoothDBus {} Loading system/gd/rust/linux/stack/src/bluetooth.rs +26 −3 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ pub trait IBluetoothCallback: RPCProxy { /// When the discovery state is changed. fn on_discovering_changed(&self, discovering: bool); /// When there is a pairing/bonding process and requires agent to display the event to UI. fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ); } /// Implementation of the adapter API. Loading Loading @@ -242,14 +251,28 @@ impl BtifBluetoothCallbacks for Bluetooth { fn ssp_request( &mut self, remote_addr: RawAddress, _remote_name: String, _cod: u32, remote_name: String, cod: u32, variant: BtSspVariant, passkey: u32, ) { // Currently this supports many agent because we accept many callbacks. // TODO: We need a way to select the default agent. self.for_all_callbacks(|callback| { callback.on_ssp_request( BluetoothDevice { address: BDAddr::from_byte_vec(&remote_addr.address.to_vec()) .unwrap() .to_string(), name: remote_name.clone(), }, cod, variant.clone(), passkey, ); }); // Immediately accept the pairing. // TODO: Delegate the pairing confirmation to agent. // TODO: Implement other pairing confirmations (passkey, passcode, etc); self.intf.lock().unwrap().ssp_reply(&remote_addr, variant, 1, passkey); } Loading Loading
system/btcore/BUILD.gn +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ static_library("btcore") { deps = [ "//bt/gd/rust/shim:init_flags_bridge_header", "//bt/gd/rust/shim:libbluetooth_rust_interop", "//bt/gd/rust/shim:message_loop_thread_bridge_header", ] } Loading
system/gd/rust/linux/client/src/dbus_iface.rs +13 −0 Original line number Diff line number Diff line //! D-Bus proxy implementations of the APIs. use bt_topshim::btif::BtSspVariant; use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback}; use btstack::RPCProxy; Loading @@ -19,6 +21,7 @@ use std::sync::{Arc, Mutex}; use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust}; impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); #[dbus_propmap(BluetoothDevice)] pub struct BluetoothDeviceDBus { Loading Loading @@ -98,6 +101,16 @@ impl IBluetoothCallback for IBluetoothCallbackDBus { #[dbus_method("OnDiscoveringChanged")] fn on_discovering_changed(&self, discovering: bool) {} #[dbus_method("OnSspRequest")] fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ) { } } // TODO: These are boilerplate codes, consider creating a macro to generate. Loading
system/gd/rust/linux/client/src/main.rs +22 −0 Original line number Diff line number Diff line use bt_topshim::btif::BtSspVariant; use bt_topshim::topstack; use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothCallback}; Loading Loading @@ -43,6 +44,27 @@ impl IBluetoothCallback for BtCallback { fn on_discovering_changed(&self, discovering: bool) { print_info!("Discovering: {}", discovering); } fn on_ssp_request( &self, remote_device: BluetoothDevice, _cod: u32, variant: BtSspVariant, passkey: u32, ) { if variant == BtSspVariant::PasskeyNotification { print_info!( "device {}{} would like to pair, enter passkey on remote device: {:06}", remote_device.address.to_string(), if remote_device.name.len() > 0 { format!(" ({})", remote_device.name) } else { String::from("") }, passkey ); } } } impl RPCProxy for BtCallback { Loading
system/gd/rust/linux/service/src/iface_bluetooth.rs +12 −0 Original line number Diff line number Diff line extern crate bt_shim; use bt_topshim::btif::BtSspVariant; use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback}; use btstack::RPCProxy; Loading Loading @@ -37,9 +39,19 @@ impl IBluetoothCallback for BluetoothCallbackDBus { fn on_device_found(&self, remote_device: BluetoothDevice) {} #[dbus_method("OnDiscoveringChanged")] fn on_discovering_changed(&self, discovering: bool) {} #[dbus_method("OnSspRequest")] fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ) { } } impl_dbus_arg_enum!(BluetoothTransport); impl_dbus_arg_enum!(BtSspVariant); #[allow(dead_code)] struct IBluetoothDBus {} Loading
system/gd/rust/linux/stack/src/bluetooth.rs +26 −3 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ pub trait IBluetoothCallback: RPCProxy { /// When the discovery state is changed. fn on_discovering_changed(&self, discovering: bool); /// When there is a pairing/bonding process and requires agent to display the event to UI. fn on_ssp_request( &self, remote_device: BluetoothDevice, cod: u32, variant: BtSspVariant, passkey: u32, ); } /// Implementation of the adapter API. Loading Loading @@ -242,14 +251,28 @@ impl BtifBluetoothCallbacks for Bluetooth { fn ssp_request( &mut self, remote_addr: RawAddress, _remote_name: String, _cod: u32, remote_name: String, cod: u32, variant: BtSspVariant, passkey: u32, ) { // Currently this supports many agent because we accept many callbacks. // TODO: We need a way to select the default agent. self.for_all_callbacks(|callback| { callback.on_ssp_request( BluetoothDevice { address: BDAddr::from_byte_vec(&remote_addr.address.to_vec()) .unwrap() .to_string(), name: remote_name.clone(), }, cod, variant.clone(), passkey, ); }); // Immediately accept the pairing. // TODO: Delegate the pairing confirmation to agent. // TODO: Implement other pairing confirmations (passkey, passcode, etc); self.intf.lock().unwrap().ssp_reply(&remote_addr, variant, 1, passkey); } Loading