Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c93fe9f4 authored by Katherine Lai's avatar Katherine Lai Committed by Gerrit Code Review
Browse files

Merge "floss: Add GetSupportedRoles API" into main

parents ec330b88 6bec5b7a
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ use bt_topshim::profiles::ProfileConnectionState;

use btstack::battery_manager::{Battery, BatterySet, IBatteryManager, IBatteryManagerCallback};
use btstack::bluetooth::{
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    BluetoothDevice, BtAdapterRole, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    IBluetoothQALegacy,
};
use btstack::bluetooth_admin::{IBluetoothAdmin, IBluetoothAdminPolicyCallback, PolicyEffect};
@@ -96,6 +96,7 @@ impl_dbus_arg_enum!(SuspendMode);
impl_dbus_arg_enum!(SuspendType);
impl_dbus_arg_from_into!(Uuid, Vec<u8>);
impl_dbus_arg_enum!(BthhReportType);
impl_dbus_arg_enum!(BtAdapterRole);

impl RefArgToRust for Uuid {
    type RustType = Vec<u8>;
@@ -995,6 +996,11 @@ impl IBluetooth for BluetoothDBus {
    fn is_swb_supported(&self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetSupportedRoles")]
    fn get_supported_roles(&self) -> Vec<BtAdapterRole> {
        dbus_generated!()
    }
}

pub(crate) struct BluetoothQALegacyDBus {
+8 −2
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@ use bt_topshim::profiles::sdp::{
};

use btstack::bluetooth::{
    Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    IBluetoothQALegacy,
    Bluetooth, BluetoothDevice, BtAdapterRole, IBluetooth, IBluetoothCallback,
    IBluetoothConnectionCallback, IBluetoothQALegacy,
};
use btstack::socket_manager::{
    BluetoothServerSocket, BluetoothSocket, BluetoothSocketManager, CallbackId,
@@ -162,6 +162,7 @@ impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtSspVariant);
impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_enum!(ProfileConnectionState);
impl_dbus_arg_enum!(BtAdapterRole);

#[allow(dead_code)]
struct BluetoothConnectionCallbackDBus {}
@@ -706,6 +707,11 @@ impl IBluetooth for IBluetoothDBus {
    fn is_swb_supported(&self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetSupportedRoles", DBusLog::Disable)]
    fn get_supported_roles(&self) -> Vec<BtAdapterRole> {
        dbus_generated!()
    }
}

impl_dbus_arg_enum!(SocketType);
+33 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use bt_topshim::btif::{
    ToggleableProfile, Uuid, Uuid128Bit, INVALID_RSSI,
};
use bt_topshim::{
    metrics,
    controller, metrics,
    profiles::gatt::GattStatus,
    profiles::hid_host::{
        BthhConnectionState, BthhHidInfo, BthhProtocolMode, BthhReportType, BthhStatus,
@@ -25,6 +25,7 @@ use bt_utils::uhid::{UHid, BD_ADDR_DEFAULT};
use btif_macros::{btif_callback, btif_callbacks_dispatcher};

use log::{debug, warn};
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::cast::ToPrimitive;
use num_traits::pow;
use std::collections::{HashMap, HashSet};
@@ -66,6 +67,14 @@ const BTM_SUCCESS: i32 = 0;

const PID_DIR: &str = "/var/run/bluetooth";

/// Represents various roles the adapter supports.
#[derive(Debug, FromPrimitive, ToPrimitive)]
#[repr(u32)]
pub enum BtAdapterRole {
    Central = 0,
    Peripheral,
    CentralPeripheral,
}
/// Defines the adapter API.
pub trait IBluetooth {
    /// Adds a callback from a client who wishes to observe adapter events.
@@ -239,6 +248,9 @@ pub trait IBluetooth {

    /// Returns whether SWB is supported.
    fn is_swb_supported(&self) -> bool;

    /// Returns a list of all the roles that are supported.
    fn get_supported_roles(&self) -> Vec<BtAdapterRole>;
}

/// Adapter API for Bluetooth qualification and verification.
@@ -522,6 +534,7 @@ pub struct Bluetooth {
    discoverable_timeout: Option<JoinHandle<()>>,
    cancelling_devices: HashSet<RawAddress>,
    active_pairing_address: Option<RawAddress>,
    le_supported_states: u64,

    /// Used to notify signal handler that we have turned off the stack.
    sig_notifier: Arc<SigData>,
@@ -579,6 +592,7 @@ impl Bluetooth {
            discoverable_timeout: None,
            cancelling_devices: HashSet::new(),
            active_pairing_address: None,
            le_supported_states: 0u64,
            sig_notifier,
            uhid_wakeup_source: UHid::new(),
        }
@@ -1312,6 +1326,7 @@ impl BtifBluetoothCallbacks for Bluetooth {

                // Also need to manually request some properties
                self.intf.lock().unwrap().get_adapter_property(BtPropertyType::ClassOfDevice);
                self.le_supported_states = controller::Controller::new().get_ble_supported_states();

                // Initialize the BLE scanner for discovery.
                let callback_id = self.bluetooth_gatt.lock().unwrap().register_scanner_callback(
@@ -2765,6 +2780,23 @@ impl IBluetooth for Bluetooth {
    fn is_swb_supported(&self) -> bool {
        self.intf.lock().unwrap().get_swb_supported()
    }

    fn get_supported_roles(&self) -> Vec<BtAdapterRole> {
        let mut roles: Vec<BtAdapterRole> = vec![];

        // See Core 5.3, Vol 4, Part E, 7.8.27 for detailed state information
        if self.le_supported_states >> 35 & 1 == 1u64 {
            roles.push(BtAdapterRole::Central);
        }
        if self.le_supported_states >> 38 & 1 == 1u64 {
            roles.push(BtAdapterRole::Peripheral);
        }
        if self.le_supported_states >> 28 & 1 == 1u64 {
            roles.push(BtAdapterRole::CentralPeripheral);
        }

        roles
    }
}

impl BtifSdpCallbacks for Bluetooth {
+7 −0
Original line number Diff line number Diff line
@@ -43,6 +43,13 @@ RawAddress ControllerIntf::read_local_addr() const {
  return *controller_->get_address();
}

uint64_t ControllerIntf::get_ble_supported_states() const {
  if (!controller_) std::abort();
  uint64_t states;
  memcpy(&states, controller_->get_ble_supported_states(), sizeof(uint64_t));
  return states;
}

}  // namespace rust
}  // namespace topshim
}  // namespace bluetooth
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class ControllerIntf {
  ~ControllerIntf();

  RawAddress read_local_addr() const;
  uint64_t get_ble_supported_states() const;

 private:
  const controller_t* controller_;
Loading