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

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

Merge changes I20aa46dc,I4b88b7cc,Ic4924f8f

* changes:
  Floss: Implement remaining GATT Server callbacks
  Floss: Implement Phy APIs for GATT Server
  Floss: Add server_read_phy topshim in GattServer
parents 369b4fe7 b45e663d
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -878,6 +878,68 @@ impl IBluetoothGattServerCallback for BtGattServerCallback {
            status
        );
    }

    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 = {}",
            addr,
            tx_phy,
            rx_phy,
            status
        );
    }

    fn on_phy_read(&self, addr: String, tx_phy: LePhy, rx_phy: LePhy, status: GattStatus) {
        print_info!(
            "GATT server phy read for addr = {}: tx_phy = {:?}, rx_phy = {:?}, status = {}",
            addr,
            tx_phy,
            rx_phy,
            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 {
+49 −0
Original line number Diff line number Diff line
@@ -1367,6 +1367,23 @@ impl IBluetoothGatt for BluetoothGattDBus {
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("ServerSetPreferredPhy")]
    fn server_set_preferred_phy(
        &self,
        server_id: i32,
        addr: String,
        tx_phy: LePhy,
        rx_phy: LePhy,
        phy_options: i32,
    ) {
        dbus_generated!()
    }

    #[dbus_method("ServerReadPhy")]
    fn server_read_phy(&self, server_id: i32, addr: String) {
        dbus_generated!()
    }
}

struct IBluetoothGattCallbackDBus {}
@@ -1521,6 +1538,38 @@ 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)]
+57 −0
Original line number Diff line number Diff line
@@ -219,6 +219,46 @@ impl IBluetoothGattServerCallback for BluetoothGattServerCallbackDBus {
    fn on_notification_sent(&self, addr: String, status: GattStatus) {
        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!()
    }

    #[dbus_method("OnPhyRead")]
    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.
@@ -910,4 +950,21 @@ impl IBluetoothGatt for IBluetoothGattDBus {
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("ServerSetPreferredPhy")]
    fn server_set_preferred_phy(
        &self,
        server_id: i32,
        addr: String,
        tx_phy: LePhy,
        rx_phy: LePhy,
        phy_options: i32,
    ) {
        dbus_generated!()
    }

    #[dbus_method("ServerReadPhy")]
    fn server_read_phy(&self, server_id: i32, addr: String) {
        dbus_generated!()
    }
}
+215 −0
Original line number Diff line number Diff line
@@ -658,6 +658,19 @@ pub trait IBluetoothGatt {
        confirm: bool,
        value: Vec<u8>,
    ) -> bool;

    /// Sets preferred PHY.
    fn server_set_preferred_phy(
        &self,
        server_id: i32,
        addr: String,
        tx_phy: LePhy,
        rx_phy: LePhy,
        phy_options: i32,
    );

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

#[derive(Debug, Default, Clone)]
@@ -1007,6 +1020,36 @@ 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
@@ -2454,6 +2497,34 @@ impl IBluetoothGatt for BluetoothGatt {

        true
    }

    fn server_set_preferred_phy(
        &self,
        server_id: i32,
        addr: String,
        tx_phy: LePhy,
        rx_phy: LePhy,
        phy_options: i32,
    ) {
        (|| {
            let address = RawAddress::from_string(addr)?;

            self.gatt.as_ref().unwrap().lock().unwrap().server.set_preferred_phy(
                &address,
                tx_phy.to_u8().unwrap_or_default(),
                rx_phy.to_u8().unwrap_or_default(),
                phy_options as u16,
            );

            Some(())
        })();
    }

    fn server_read_phy(&self, server_id: i32, addr: String) {
        if let Some(address) = RawAddress::from_string(addr.clone()) {
            self.gatt.as_ref().unwrap().lock().unwrap().server.read_phy(server_id, &address);
        }
    }
}

#[btif_callbacks_dispatcher(dispatch_gatt_client_callbacks, GattClientCallbacks)]
@@ -3079,6 +3150,43 @@ 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);

    #[btif_callback(ReadPhy)]
    fn read_phy_cb(
        &mut self,
        server_id: i32,
        addr: RawAddress,
        tx_phy: u8,
        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 {
@@ -3316,6 +3424,113 @@ 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)?;
            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_phy_update(
                    address,
                    LePhy::from_u8(tx_phy).unwrap_or_default(),
                    LePhy::from_u8(rx_phy).unwrap_or_default(),
                    status,
                );
            }

            Some(())
        })();
    }

    fn read_phy_cb(
        &mut self,
        server_id: i32,
        addr: RawAddress,
        tx_phy: u8,
        rx_phy: u8,
        status: GattStatus,
    ) {
        if let Some(cbid) =
            self.server_context_map.get_by_server_id(server_id).map(|server| server.cbid)
        {
            if let Some(cb) = self.server_context_map.get_callback_from_callback_id(cbid) {
                cb.on_phy_read(
                    addr.to_string(),
                    LePhy::from_u8(tx_phy).unwrap_or_default(),
                    LePhy::from_u8(rx_phy).unwrap_or_default(),
                    status,
                );
            }
        }
    }

    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)]
+15 −0
Original line number Diff line number Diff line
@@ -32,6 +32,11 @@ void ReadPhyCallback(int client_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_
  bluetooth::topshim::rust::read_phy_callback(client_if, addr, tx_phy, rx_phy, status);
}

void ServerReadPhyCallback(
    int server_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy, uint8_t status) {
  bluetooth::topshim::rust::server_read_phy_callback(server_if, addr, tx_phy, rx_phy, status);
}

}  // namespace internal

int GattClientIntf::read_phy(int client_if, RawAddress addr) {
@@ -42,6 +47,16 @@ std::unique_ptr<GattClientIntf> GetGattClientProfile(const unsigned char* gatt_i
  return std::make_unique<GattClientIntf>(reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->client);
}

int GattServerIntf::server_read_phy(int server_if, RawAddress addr) {
  return server_intf_->read_phy(
      addr, base::Bind(&internal::ServerReadPhyCallback, server_if, addr));
}

std::unique_ptr<GattServerIntf> GetGattServerProfile(const unsigned char* gatt_intf) {
  return std::make_unique<GattServerIntf>(
      reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->server);
}

}  // namespace rust
}  // namespace topshim
}  // namespace bluetooth
Loading