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

Commit 137d7987 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

floss: Implement IBluetoothGatt::ReadPhy

Bug: 193685325
Tag: #floss
Test: Build floss on Linux and AOSP

Change-Id: Ibbb98fa010ea548639646d82db92b6af54ad111c
parent 69960a9c
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
use bt_topshim::profiles::gatt::GattStatus;

use btstack::bluetooth_gatt::{
    IBluetoothGatt, IBluetoothGattCallback, IScannerCallback, RSSISettings, ScanFilter,
    IBluetoothGatt, IBluetoothGattCallback, IScannerCallback, LePhy, RSSISettings, ScanFilter,
    ScanSettings, ScanType,
};
use btstack::RPCProxy;
@@ -37,6 +39,9 @@ impl IBluetoothGattCallback for BluetoothGattCallbackDBus {
        addr: String,
    ) {
    }

    #[dbus_method("OnPhyRead")]
    fn on_phy_read(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus) {}
}

#[allow(dead_code)]
@@ -62,6 +67,8 @@ struct ScanSettingsDBus {
    rssi_settings: RSSISettings,
}

impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(ScanType);

#[dbus_propmap(ScanFilter)]
@@ -110,4 +117,7 @@ impl IBluetoothGatt for IBluetoothGattDBus {

    #[dbus_method("ClientDisconnect")]
    fn client_disconnect(&self, client_id: i32, addr: String) {}

    #[dbus_method("ClientReadPhy")]
    fn client_read_phy(&mut self, client_id: i32, addr: String) {}
}
+49 −0
Original line number Diff line number Diff line
@@ -124,6 +124,9 @@ pub trait IBluetoothGatt {

    /// Disconnects a GATT connection.
    fn client_disconnect(&self, client_id: i32, addr: String);

    /// Reads the PHY used by a peer.
    fn client_read_phy(&mut self, client_id: i32, addr: String);
}

/// Callback for GATT Client API.
@@ -139,6 +142,9 @@ pub trait IBluetoothGattCallback: RPCProxy {
        connected: bool,
        addr: String,
    );

    /// The completion of IBluetoothGatt::read_phy.
    fn on_phy_read(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus);
}

/// Interface for scanner callbacks to clients, passed to `IBluetoothGatt::register_scanner`.
@@ -147,6 +153,16 @@ pub trait IScannerCallback {
    fn on_scanner_registered(&self, status: i32, scanner_id: i32);
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[repr(u8)]
/// Represents LE PHY.
pub enum LePhy {
    Invalid = 0,
    Phy1m = 1,
    Phy2m = 2,
    PhyCoded = 3,
}

#[derive(Debug, FromPrimitive, ToPrimitive)]
#[repr(i32)]
/// Scan type configuration.
@@ -310,6 +326,15 @@ impl IBluetoothGatt for BluetoothGatt {
            conn_id.unwrap(),
        );
    }

    fn client_read_phy(&mut self, client_id: i32, addr: String) {
        let address = match RawAddress::from_string(addr.clone()) {
            None => return,
            Some(addr) => addr,
        };

        self.gatt.as_mut().unwrap().client.read_phy(client_id, &address);
    }
}

#[btif_callbacks_dispatcher(BluetoothGatt, dispatch_gatt_client_callbacks, GattClientCallbacks)]
@@ -320,6 +345,9 @@ pub(crate) trait BtifGattClientCallbacks {
    #[btif_callback(Connect)]
    fn connect_cb(&mut self, conn_id: i32, status: i32, client_id: i32, addr: RawAddress);

    #[btif_callback(ReadPhy)]
    fn read_phy_cb(&mut self, client_id: i32, addr: RawAddress, tx_phy: u8, rx_phy: u8, status: u8);

    // TODO(b/193685325): Define all callbacks.
}

@@ -357,6 +385,27 @@ impl BtifGattClientCallbacks for BluetoothGatt {
            addr.to_string(),
        );
    }

    fn read_phy_cb(
        &mut self,
        client_id: i32,
        addr: RawAddress,
        tx_phy: u8,
        rx_phy: u8,
        status: u8,
    ) {
        let client = self.context_map.get_by_client_id(client_id);
        if client.is_none() {
            return;
        }

        client.unwrap().callback.on_phy_read(
            addr.to_string(),
            LePhy::from_u8(tx_phy).unwrap(),
            LePhy::from_u8(rx_phy).unwrap(),
            GattStatus::from_u8(status).unwrap(),
        );
    }
}

#[cfg(test)]
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ pub mod ffi {
    }
}

#[derive(Debug, FromPrimitive, PartialEq, PartialOrd)]
#[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, PartialOrd)]
#[repr(u32)]
pub enum GattStatus {
    Success = 0x00,