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

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

Merge changes Ifa5eec54,I11e7d4cc,Ib11b2c71

* changes:
  Floss: Implement SendNotification for GATT Server
  Floss: Implement read/write request CBs for GATT Server
  Floss: Implement Add/Remove/Clear Service for GATT Server
parents 1fe3a5f5 f7bd31bc
Loading
Loading
Loading
Loading
+111 −4
Original line number Diff line number Diff line
@@ -763,12 +763,119 @@ impl IBluetoothGattServerCallback for BtGattServerCallback {
        print_info!("GATT Server registered status = {}, server_id = {}", status, server_id);
    }

    fn on_server_connection_state(&self, _server_id: i32, _connected: bool, _addr: String) {
    fn on_server_connection_state(&self, server_id: i32, connected: bool, addr: String) {
        print_info!(
            "GATT server connection with server_id = {}, connected = {}, addr = {}",
            _server_id,
            _connected,
            _addr
            server_id,
            connected,
            addr
        );
    }

    fn on_service_added(&self, status: GattStatus, service: BluetoothGattService) {
        print_info!("GATT service added with status = {}, service = {:?}", status, service)
    }

    fn on_characteristic_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
        print_info!(
            "GATT characteristic read request for addr = {}, trans_id = {}, offset = {}, is_long = {}, handle = {}",
            addr,
            trans_id,
            offset,
            is_long,
            handle
        );
    }

    fn on_descriptor_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
        print_info!(
            "GATT descriptor read request for addr = {}, trans_id = {}, offset = {}, is_long = {}, handle = {}",
            addr,
            trans_id,
            offset,
            is_long,
            handle
        );
    }

    fn on_characteristic_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
        print_info!(
            "GATT characteristic write request for \
                addr = {}, trans_id = {}, offset = {}, len = {}, is_prep = {}, need_rsp = {}, handle = {}, value = {:?}",
            addr,
            trans_id,
            offset,
            len,
            is_prep,
            need_rsp,
            handle,
            value
        );
    }

    fn on_descriptor_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
        print_info!(
            "GATT descriptor write request for \
                addr = {}, trans_id = {}, offset = {}, len = {}, is_prep = {}, need_rsp = {}, handle = {}, value = {:?}",
            addr,
            trans_id,
            offset,
            len,
            is_prep,
            need_rsp,
            handle,
            value
        );
    }

    fn on_execute_write(&self, addr: String, trans_id: i32, exec_write: bool) {
        print_info!(
            "GATT executed write for addr = {}, trans_id = {}, exec_write = {}",
            addr,
            trans_id,
            exec_write
        );
    }

    fn on_notification_sent(&self, addr: String, status: GattStatus) {
        print_info!(
            "GATT notification/indication sent for addr = {} with status = {}",
            addr,
            status
        );
    }
}
+99 −0
Original line number Diff line number Diff line
@@ -1327,6 +1327,46 @@ impl IBluetoothGatt for BluetoothGattDBus {
    fn server_disconnect(&self, server_id: i32, addr: String) -> bool {
        dbus_generated!()
    }

    #[dbus_method("AddService")]
    fn add_service(&self, server_id: i32, service: BluetoothGattService) {
        dbus_generated!()
    }

    #[dbus_method("RemoveService")]
    fn remove_service(&self, server_id: i32, handle: i32) {
        dbus_generated!()
    }

    #[dbus_method("ClearServices")]
    fn clear_services(&self, server_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("SendResponse")]
    fn send_response(
        &self,
        server_id: i32,
        addr: String,
        request_id: i32,
        status: GattStatus,
        offset: i32,
        value: Vec<u8>,
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SendNotification")]
    fn send_notification(
        &self,
        server_id: i32,
        addr: String,
        handle: i32,
        confirm: bool,
        value: Vec<u8>,
    ) -> bool {
        dbus_generated!()
    }
}

struct IBluetoothGattCallbackDBus {}
@@ -1422,6 +1462,65 @@ impl IBluetoothGattServerCallback for IBluetoothGattCallbackDBus {

    #[dbus_method("OnServerConnectionState")]
    fn on_server_connection_state(&self, server_id: i32, connected: bool, addr: String) {}

    #[dbus_method("OnServiceAdded")]
    fn on_service_added(&self, status: GattStatus, service: BluetoothGattService) {}

    #[dbus_method("OnCharacteristicReadRequest")]
    fn on_characteristic_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
    }

    #[dbus_method("OnDescriptorReadRequest")]
    fn on_descriptor_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
    }

    #[dbus_method("OnCharacteristicWriteRequest")]
    fn on_characteristic_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
    }

    #[dbus_method("OnDescriptorWriteRequest")]
    fn on_descriptor_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
    }

    #[dbus_method("OnExecuteWrite")]
    fn on_execute_write(&self, addr: String, trans_id: i32, exec_write: bool) {}

    #[dbus_method("OnNotificationSent")]
    fn on_notification_sent(&self, addr: String, status: GattStatus) {}
}

#[dbus_propmap(BluetoothServerSocket)]
+109 −0
Original line number Diff line number Diff line
@@ -150,6 +150,75 @@ impl IBluetoothGattServerCallback for BluetoothGattServerCallbackDBus {
    fn on_server_connection_state(&self, server_id: i32, connected: bool, addr: String) {
        dbus_generated!()
    }

    #[dbus_method("OnServiceAdded")]
    fn on_service_added(&self, status: GattStatus, service: BluetoothGattService) {
        dbus_generated!()
    }

    #[dbus_method("OnCharacteristicReadRequest")]
    fn on_characteristic_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnDescriptorReadRequest")]
    fn on_descriptor_read_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        is_long: bool,
        handle: i32,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnCharacteristicWriteRequest")]
    fn on_characteristic_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnDescriptorWriteRequest")]
    fn on_descriptor_write_request(
        &self,
        addr: String,
        trans_id: i32,
        offset: i32,
        len: i32,
        is_prep: bool,
        need_rsp: bool,
        handle: i32,
        value: Vec<u8>,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnExecuteWrite")]
    fn on_execute_write(&self, addr: String, trans_id: i32, exec_write: bool) {
        dbus_generated!()
    }

    #[dbus_method("OnNotificationSent")]
    fn on_notification_sent(&self, addr: String, status: GattStatus) {
        dbus_generated!()
    }
}

// Represents Uuid128Bit as an array in D-Bus.
@@ -801,4 +870,44 @@ impl IBluetoothGatt for IBluetoothGattDBus {
    fn server_disconnect(&self, server_id: i32, addr: String) -> bool {
        dbus_generated!()
    }

    #[dbus_method("AddService")]
    fn add_service(&self, server_id: i32, service: BluetoothGattService) {
        dbus_generated!()
    }

    #[dbus_method("RemoveService")]
    fn remove_service(&self, server_id: i32, handle: i32) {
        dbus_generated!()
    }

    #[dbus_method("ClearServices")]
    fn clear_services(&self, server_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("SendResponse")]
    fn send_response(
        &self,
        server_id: i32,
        addr: String,
        request_id: i32,
        status: GattStatus,
        offset: i32,
        value: Vec<u8>,
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SendNotification")]
    fn send_notification(
        &self,
        server_id: i32,
        addr: String,
        handle: i32,
        confirm: bool,
        value: Vec<u8>,
    ) -> bool {
        dbus_generated!()
    }
}
+659 −74

File changed.

Preview size limit exceeded, changes collapsed.

+9 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ pub type BtGattNotifyParams = bindings::btgatt_notify_params_t;
pub type BtGattReadParams = bindings::btgatt_read_params_t;
pub type BtGattDbElement = bindings::btgatt_db_element_t;
pub type BtGattResponse = bindings::btgatt_response_t;
pub type BtGattValue = bindings::btgatt_value_t;
pub type BtGattTestParams = bindings::btgatt_test_params_t;

#[cxx::bridge(namespace = bluetooth::topshim::rust)]
@@ -584,16 +585,16 @@ pub enum GattClientCallbacks {
pub enum GattServerCallbacks {
    RegisterServer(GattStatus, i32, Uuid),
    Connection(i32, i32, i32, RawAddress),
    ServiceAdded(i32, i32, Vec<BtGattDbElement>, usize),
    ServiceStopped(i32, i32, i32),
    ServiceDeleted(i32, i32, i32),
    ServiceAdded(GattStatus, i32, Vec<BtGattDbElement>, usize),
    ServiceStopped(GattStatus, i32, i32),
    ServiceDeleted(GattStatus, i32, i32),
    RequestReadCharacteristic(i32, i32, RawAddress, i32, i32, bool),
    RequestReadDescriptor(i32, i32, RawAddress, i32, i32, bool),
    RequestWriteCharacteristic(i32, i32, RawAddress, i32, i32, bool, bool, Vec<u8>, usize),
    RequestWriteDescriptor(i32, i32, RawAddress, i32, i32, bool, bool, Vec<u8>, usize),
    RequestExecWrite(i32, i32, RawAddress, i32),
    ResponseConfirmation(i32, i32),
    IndicationSent(i32, i32),
    IndicationSent(i32, GattStatus),
    Congestion(i32, bool),
    MtuChanged(i32, i32),
    PhyUpdated(i32, u8, u8, u8),
@@ -759,7 +760,7 @@ cb_variant!(
cb_variant!(
    GattServerCb,
    gs_service_added_cb -> GattServerCallbacks::ServiceAdded,
    i32, i32, *const BtGattDbElement, usize, {
    i32 -> GattStatus, i32, *const BtGattDbElement, usize, {
        let _2 = ptr_to_vec(_2, _3);
    }
);
@@ -767,13 +768,13 @@ cb_variant!(
cb_variant!(
    GattServerCb,
    gs_service_stopped_cb -> GattServerCallbacks::ServiceStopped,
    i32, i32, i32, {}
    i32 -> GattStatus, i32, i32, {}
);

cb_variant!(
    GattServerCb,
    gs_service_deleted_cb -> GattServerCallbacks::ServiceDeleted,
    i32, i32, i32, {}
    i32 -> GattStatus, i32, i32, {}
);

cb_variant!(
@@ -827,7 +828,7 @@ cb_variant!(
cb_variant!(
    GattServerCb,
    gs_indication_sent_cb -> GattServerCallbacks::IndicationSent,
    i32, i32, {}
    i32, i32 -> GattStatus, {}
);

cb_variant!(