From e6de0926324894105f34c075623ecb0ae327c317 Mon Sep 17 00:00:00 2001 From: Abhishek Pandit-Subedi Date: Tue, 8 Feb 2022 14:13:32 -0800 Subject: floss: Update rustdocs in topshim + stack Bug: 218551688 Tag: #floss Test: ./build.py --target test && ./build.py --target docs Change-Id: Idc9e8afdf5d7e0a5ba95180ce5dabc9f02bceb9f --- system/gd/rust/linux/stack/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system/gd/rust/linux/stack/src') diff --git a/system/gd/rust/linux/stack/src/lib.rs b/system/gd/rust/linux/stack/src/lib.rs index 160363e88a..ad21e6e617 100644 --- a/system/gd/rust/linux/stack/src/lib.rs +++ b/system/gd/rust/linux/stack/src/lib.rs @@ -1,7 +1,7 @@ -//! Fluoride/GD Bluetooth stack. +//! Floss Bluetooth stack. //! -//! This crate provides the API implementation of the Fluoride/GD Bluetooth stack, independent of -//! any RPC projection. +//! This crate provides the API implementation of the Fluoride/GD Bluetooth +//! stack, independent of any RPC projection. #[macro_use] extern crate num_derive; @@ -27,9 +27,6 @@ use bt_topshim::{ }, }; -/// Represents a Bluetooth address. -// TODO: Add support for LE random addresses. - #[derive(Clone, Debug)] pub enum BluetoothCallbackType { Adapter, -- cgit v1.2.3 From 285f4f34e527d531c4ba0ba5bd824b7d441e96a2 Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Mon, 14 Feb 2022 18:46:16 +0000 Subject: floss: Rename AdapterDiscoveryTimeout to AdapterDiscoverableTimeout Update get_discovery_end_millis since it was using an incorrect adapater property Bug: 196885534 Tag: #floss Test: None Change-Id: I0fe282448be8d321a0159006131588c07880bcca --- system/gd/rust/linux/stack/src/bluetooth.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'system/gd/rust/linux/stack/src') diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs index ee0578c958..1766525613 100644 --- a/system/gd/rust/linux/stack/src/bluetooth.rs +++ b/system/gd/rust/linux/stack/src/bluetooth.rs @@ -25,6 +25,8 @@ use crate::bluetooth_media::{BluetoothMedia, IBluetoothMedia, MediaActions}; use crate::uuid::{Profile, UuidHelper}; use crate::{BluetoothCallbackType, Message, RPCProxy}; +const DEFAULT_DISCOVERY_TIMEOUT_MS: u64 = 12800; + /// Defines the adapter API. pub trait IBluetooth { /// Adds a callback from a client who wishes to observe adapter events. @@ -803,20 +805,11 @@ impl IBluetooth for Bluetooth { return 0; } - match self.properties.get(&BtPropertyType::AdapterDiscoveryTimeout) { - Some(variant) => match variant { - BluetoothProperty::AdapterDiscoveryTimeout(timeout) => { - let seconds: u64 = (*timeout).into(); - let elapsed = self.discovering_started.elapsed(); - if elapsed.as_secs() >= seconds { - 0 - } else { - seconds * 1000 - elapsed.as_millis() as u64 - } - } - _ => 0, - }, - _ => 0, + let elapsed_ms = self.discovering_started.elapsed().as_millis() as u64; + if elapsed_ms >= DEFAULT_DISCOVERY_TIMEOUT_MS { + 0 + } else { + DEFAULT_DISCOVERY_TIMEOUT_MS - elapsed_ms } } -- cgit v1.2.3 From 0f30a7012de865efde1cc923c43283d94e6d6e3b Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Fri, 11 Feb 2022 01:54:14 +0000 Subject: floss: Add Get/SetConnectable and Get/SetDiscoverable adapter APIs Bug: 196885534 Tag: #floss Test: SetDiscoverable on/off using btclient Change-Id: Ib080cfab9d3421edc8eee57bda5ef4076fb46370 --- system/gd/rust/linux/stack/src/bluetooth.rs | 66 ++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'system/gd/rust/linux/stack/src') diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs index 1766525613..8eb3d99e9f 100644 --- a/system/gd/rust/linux/stack/src/bluetooth.rs +++ b/system/gd/rust/linux/stack/src/bluetooth.rs @@ -2,8 +2,8 @@ use bt_topshim::btif::{ BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtAclState, - BtBondState, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtSspVariant, - BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, + BtBondState, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, + BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, }; use bt_topshim::{ profiles::hid_host::{HHCallbacksDispatcher, HidHost}, @@ -69,6 +69,12 @@ pub trait IBluetooth { /// Sets the bluetooth class. fn set_bluetooth_class(&self, cod: u32) -> bool; + /// Returns whether the adapter is discoverable. + fn get_discoverable(&self) -> bool; + + /// Sets discoverability. If discoverable, limits the duration with given value. + fn set_discoverable(&self, mode: bool, duration: u32) -> bool; + /// Starts BREDR Inquiry. fn start_discovery(&self) -> bool; @@ -245,6 +251,7 @@ pub struct Bluetooth { state: BtState, tx: Sender, uuid_helper: UuidHelper, + is_connectable: bool, } impl Bluetooth { @@ -271,6 +278,7 @@ impl Bluetooth { state: BtState::Off, tx, uuid_helper: UuidHelper::new(), + is_connectable: false, } } @@ -324,6 +332,29 @@ impl Bluetooth { } } + fn get_connectable(&self) -> bool { + match self.properties.get(&BtPropertyType::AdapterScanMode) { + Some(prop) => match prop { + BluetoothProperty::AdapterScanMode(mode) => match *mode { + BtScanMode::Connectable | BtScanMode::ConnectableDiscoverable => true, + _ => false, + }, + _ => false, + }, + _ => false, + } + } + + fn set_connectable(&mut self, mode: bool) -> bool { + self.is_connectable = mode; + if mode && self.get_discoverable() { + return true; + } + self.intf.lock().unwrap().set_adapter_property(BluetoothProperty::AdapterScanMode( + if mode { BtScanMode::Connectable } else { BtScanMode::None_ }, + )) == 0 + } + pub(crate) fn callback_disconnected(&mut self, id: u32, cb_type: BluetoothCallbackType) { match cb_type { BluetoothCallbackType::Adapter => { @@ -788,6 +819,37 @@ impl IBluetooth for Bluetooth { self.intf.lock().unwrap().set_adapter_property(BluetoothProperty::ClassOfDevice(cod)) == 0 } + fn get_discoverable(&self) -> bool { + match self.properties.get(&BtPropertyType::AdapterScanMode) { + Some(prop) => match prop { + BluetoothProperty::AdapterScanMode(mode) => match mode { + BtScanMode::ConnectableDiscoverable => true, + _ => false, + }, + _ => false, + }, + _ => false, + } + } + + fn set_discoverable(&self, mode: bool, duration: u32) -> bool { + self.intf + .lock() + .unwrap() + .set_adapter_property(BluetoothProperty::AdapterDiscoverableTimeout(duration)); + self.intf.lock().unwrap().set_adapter_property(BluetoothProperty::AdapterScanMode( + if mode { + BtScanMode::ConnectableDiscoverable + } else { + if self.is_connectable { + BtScanMode::Connectable + } else { + BtScanMode::None_ + } + }, + )) == 0 + } + fn start_discovery(&self) -> bool { self.intf.lock().unwrap().start_discovery() == 0 } -- cgit v1.2.3 From 5b78f06fbe1ec2dc4bea05ab89ae742f052feecb Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Wed, 16 Feb 2022 22:00:37 +0000 Subject: floss: Add advertising support adpater APIs Bug: 196886384 Tag: #floss Test: Verify API output with btclient Change-Id: I4844ab645b4abafeda184153d993b996ea1355b6 --- system/gd/rust/linux/stack/src/bluetooth.rs | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'system/gd/rust/linux/stack/src') diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs index 8eb3d99e9f..c3b1d3218f 100644 --- a/system/gd/rust/linux/stack/src/bluetooth.rs +++ b/system/gd/rust/linux/stack/src/bluetooth.rs @@ -2,8 +2,8 @@ use bt_topshim::btif::{ BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtAclState, - BtBondState, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, - BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, + BtBondState, BtDiscoveryState, BtHciErrorCode, BtLocalLeFeatures, BtPinCode, BtPropertyType, + BtScanMode, BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, }; use bt_topshim::{ profiles::hid_host::{HHCallbacksDispatcher, HidHost}, @@ -26,6 +26,7 @@ use crate::uuid::{Profile, UuidHelper}; use crate::{BluetoothCallbackType, Message, RPCProxy}; const DEFAULT_DISCOVERY_TIMEOUT_MS: u64 = 12800; +const MIN_ADV_INSTANCES_FOR_MULTI_ADV: u8 = 5; /// Defines the adapter API. pub trait IBluetooth { @@ -75,6 +76,13 @@ pub trait IBluetooth { /// Sets discoverability. If discoverable, limits the duration with given value. fn set_discoverable(&self, mode: bool, duration: u32) -> bool; + /// Returns whether multi-advertisement is supported. + /// A minimum number of 5 advertising instances is required for multi-advertisment support. + fn is_multi_advertisement_supported(&self) -> bool; + + /// Returns whether LE extended advertising is supported. + fn is_le_extended_advertising_supported(&self) -> bool; + /// Starts BREDR Inquiry. fn start_discovery(&self) -> bool; @@ -850,6 +858,28 @@ impl IBluetooth for Bluetooth { )) == 0 } + fn is_multi_advertisement_supported(&self) -> bool { + match self.properties.get(&BtPropertyType::LocalLeFeatures) { + Some(prop) => match prop { + BluetoothProperty::LocalLeFeatures(llf) => { + llf.max_adv_instance >= MIN_ADV_INSTANCES_FOR_MULTI_ADV + } + _ => false, + }, + _ => false, + } + } + + fn is_le_extended_advertising_supported(&self) -> bool { + match self.properties.get(&BtPropertyType::LocalLeFeatures) { + Some(prop) => match prop { + BluetoothProperty::LocalLeFeatures(llf) => llf.le_extended_advertising_supported, + _ => false, + }, + _ => false, + } + } + fn start_discovery(&self) -> bool { self.intf.lock().unwrap().start_discovery() == 0 } -- cgit v1.2.3