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

Commit b45e663d authored by Katherine Lai's avatar Katherine Lai
Browse files

Floss: Implement remaining GATT Server callbacks

This implements IBluetoothGattServerCallback OnMtuChanged,
OnConnectionUpdated, and OnSubrateChange.

Bug: 193685791
Tag: #floss
Test: emerge-dedede floss and manual test
Change-Id: I20aa46dc7577f2c5f08ab6cc29c36c65908b4bd1
parent 8a8b663d
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -879,6 +879,10 @@ impl IBluetoothGattServerCallback for BtGattServerCallback {
        );
    }

    fn on_mtu_changed(&self, addr: String, mtu: i32) {
        print_info!("GATT server MTU changed for addr = {}, mtu = {}", addr, mtu);
    }

    fn on_phy_update(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus) {
        print_info!(
            "GATT server phy updated for addr = {}: tx_phy = {:?}, rx_phy = {:?}, status = {}",
@@ -898,6 +902,44 @@ impl IBluetoothGattServerCallback for BtGattServerCallback {
            status
        );
    }

    fn on_connection_updated(
        &self,
        addr: String,
        interval: i32,
        latency: i32,
        timeout: i32,
        status: GattStatus,
    ) {
        print_info!(
            "GATT server connection updated for addr = {}, interval = {}, latency = {}, timeout = {}, status = {}",
            addr,
            interval,
            latency,
            timeout,
            status
        );
    }

    fn on_subrate_change(
        &self,
        addr: String,
        subrate_factor: i32,
        latency: i32,
        cont_num: i32,
        timeout: i32,
        status: GattStatus,
    ) {
        print_info!(
            "GATT server subrate changed for addr = {}, subrate_factor = {}, latency = {}, cont_num = {}, timeout = {}, status = {}",
            addr,
            subrate_factor,
            latency,
            cont_num,
            timeout,
            status
        );
    }
}

impl RPCProxy for BtGattServerCallback {
+26 −0
Original line number Diff line number Diff line
@@ -1539,11 +1539,37 @@ impl IBluetoothGattServerCallback for IBluetoothGattCallbackDBus {
    #[dbus_method("OnNotificationSent")]
    fn on_notification_sent(&self, addr: String, status: GattStatus) {}

    #[dbus_method("OnMtuChanged")]
    fn on_mtu_changed(&self, addr: String, mtu: i32) {}

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

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

    #[dbus_method("OnConnectionUpdated")]
    fn on_connection_updated(
        &self,
        addr: String,
        interval: i32,
        latency: i32,
        timeout: i32,
        status: GattStatus,
    ) {
    }

    #[dbus_method("OnSubrateChange")]
    fn on_subrate_change(
        &self,
        addr: String,
        subrate_factor: i32,
        latency: i32,
        cont_num: i32,
        timeout: i32,
        status: GattStatus,
    ) {
    }
}

#[dbus_propmap(BluetoothServerSocket)]
+30 −0
Original line number Diff line number Diff line
@@ -220,6 +220,11 @@ impl IBluetoothGattServerCallback for BluetoothGattServerCallbackDBus {
        dbus_generated!()
    }

    #[dbus_method("OnMtuChanged")]
    fn on_mtu_changed(&self, addr: String, mtu: i32) {
        dbus_generated!()
    }

    #[dbus_method("OnPhyUpdate")]
    fn on_phy_update(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus) {
        dbus_generated!()
@@ -229,6 +234,31 @@ impl IBluetoothGattServerCallback for BluetoothGattServerCallbackDBus {
    fn on_phy_read(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnConnectionUpdated")]
    fn on_connection_updated(
        &self,
        addr: String,
        interval: i32,
        latency: i32,
        timeout: i32,
        status: GattStatus,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnSubrateChange")]
    fn on_subrate_change(
        &self,
        addr: String,
        subrate_factor: i32,
        latency: i32,
        cont_num: i32,
        timeout: i32,
        status: GattStatus,
    ) {
        dbus_generated!()
    }
}

// Represents Uuid128Bit as an array in D-Bus.
+115 −0
Original line number Diff line number Diff line
@@ -1021,11 +1021,35 @@ pub trait IBluetoothGattServerCallback: RPCProxy {
    /// When a notification or indication has been sent to a remote device.
    fn on_notification_sent(&self, _addr: String, _status: GattStatus);

    /// When the MTU for a given connection changes
    fn on_mtu_changed(&self, addr: String, mtu: i32);

    /// When there is a change of PHY.
    fn on_phy_update(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus);

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

    /// When the connection parameters for a given connection changes.
    fn on_connection_updated(
        &self,
        addr: String,
        interval: i32,
        latency: i32,
        timeout: i32,
        status: GattStatus,
    );

    /// When the subrate change event for a given connection is received.
    fn on_subrate_change(
        &self,
        addr: String,
        subrate_factor: i32,
        latency: i32,
        cont_num: i32,
        timeout: i32,
        status: GattStatus,
    );
}

/// Interface for scanner callbacks to clients, passed to
@@ -3127,6 +3151,9 @@ pub(crate) trait BtifGattServerCallbacks {
    #[btif_callback(Congestion)]
    fn congestion_cb(&mut self, conn_id: i32, congested: bool);

    #[btif_callback(MtuChanged)]
    fn mtu_changed_cb(&mut self, conn_id: i32, mtu: i32);

    #[btif_callback(PhyUpdated)]
    fn phy_updated_cb(&mut self, conn_id: i32, tx_phy: u8, rx_phy: u8, status: GattStatus);

@@ -3139,6 +3166,27 @@ pub(crate) trait BtifGattServerCallbacks {
        rx_phy: u8,
        status: GattStatus,
    );

    #[btif_callback(ConnUpdated)]
    fn conn_updated_cb(
        &mut self,
        conn_id: i32,
        interval: u16,
        latency: u16,
        timeout: u16,
        status: GattStatus,
    );

    #[btif_callback(SubrateChanged)]
    fn subrate_chg_cb(
        &mut self,
        conn_id: i32,
        subrate_factor: u16,
        latency: u16,
        cont_num: u16,
        timeout: u16,
        status: GattStatus,
    );
}

impl BtifGattServerCallbacks for BluetoothGatt {
@@ -3377,6 +3425,19 @@ impl BtifGattServerCallbacks for BluetoothGatt {
        }
    }

    fn mtu_changed_cb(&mut self, conn_id: i32, mtu: i32) {
        (|| {
            let address = self.server_context_map.get_address_from_conn_id(conn_id)?;
            let server_cbid = self.server_context_map.get_by_conn_id(conn_id)?.cbid;

            if let Some(cb) = self.server_context_map.get_callback_from_callback_id(server_cbid) {
                cb.on_mtu_changed(address, mtu);
            }

            Some(())
        })();
    }

    fn phy_updated_cb(&mut self, conn_id: i32, tx_phy: u8, rx_phy: u8, status: GattStatus) {
        (|| {
            let address = self.server_context_map.get_address_from_conn_id(conn_id)?;
@@ -3416,6 +3477,60 @@ impl BtifGattServerCallbacks for BluetoothGatt {
            }
        }
    }

    fn conn_updated_cb(
        &mut self,
        conn_id: i32,
        interval: u16,
        latency: u16,
        timeout: u16,
        status: GattStatus,
    ) {
        (|| {
            let address = self.server_context_map.get_address_from_conn_id(conn_id)?;
            let server_cbid = self.server_context_map.get_by_conn_id(conn_id)?.cbid;

            if let Some(cb) = self.server_context_map.get_callback_from_callback_id(server_cbid) {
                cb.on_connection_updated(
                    address,
                    interval as i32,
                    latency as i32,
                    timeout as i32,
                    status,
                );
            }

            Some(())
        })();
    }

    fn subrate_chg_cb(
        &mut self,
        conn_id: i32,
        subrate_factor: u16,
        latency: u16,
        cont_num: u16,
        timeout: u16,
        status: GattStatus,
    ) {
        (|| {
            let address = self.server_context_map.get_address_from_conn_id(conn_id)?;
            let server_cbid = self.server_context_map.get_by_conn_id(conn_id)?.cbid;

            if let Some(cb) = self.server_context_map.get_callback_from_callback_id(server_cbid) {
                cb.on_subrate_change(
                    address,
                    subrate_factor as i32,
                    latency as i32,
                    cont_num as i32,
                    timeout as i32,
                    status,
                );
            }

            Some(())
        })();
    }
}

#[btif_callbacks_dispatcher(dispatch_le_scanner_callbacks, GattScannerCallbacks)]
+10 −3
Original line number Diff line number Diff line
@@ -616,8 +616,9 @@ pub enum GattServerCallbacks {
    Congestion(i32, bool),
    MtuChanged(i32, i32),
    PhyUpdated(i32, u8, u8, GattStatus),
    ConnUpdated(i32, u16, u16, u16, u8),
    ConnUpdated(i32, u16, u16, u16, GattStatus),
    ReadPhy(i32, RawAddress, u8, u8, GattStatus),
    SubrateChanged(i32, u16, u16, u16, u16, GattStatus),
}

pub struct GattClientCallbacksDispatcher {
@@ -871,7 +872,7 @@ cb_variant!(
cb_variant!(
    GattServerCb,
    gs_conn_updated_cb -> GattServerCallbacks::ConnUpdated,
    i32, u16, u16, u16, u8, {}
    i32, u16, u16, u16, u8 -> GattStatus, {}
);

cb_variant!(
@@ -879,6 +880,12 @@ cb_variant!(
    server_read_phy_callback -> GattServerCallbacks::ReadPhy,
    i32, RawAddress, u8, u8, u8 -> GattStatus);

cb_variant!(
    GattServerCb,
    gs_subrate_chg_cb -> GattServerCallbacks::SubrateChanged,
    i32, u16, u16, u16, u16, u8 -> GattStatus, {}
);

/// Scanning callbacks used by the GD implementation of BleScannerInterface.
/// These callbacks should be registered using |RegisterCallbacks| on
/// `BleScannerInterface`.
@@ -1851,7 +1858,7 @@ impl Gatt {
            mtu_changed_cb: Some(gs_mtu_changed_cb),
            phy_updated_cb: Some(gs_phy_updated_cb),
            conn_updated_cb: Some(gs_conn_updated_cb),
            subrate_chg_cb: None,
            subrate_chg_cb: Some(gs_subrate_chg_cb),
        });

        let gatt_scanner_callbacks = Box::new(btgatt_scanner_callbacks_t {