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

Commit d41c1496 authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Gerrit Code Review
Browse files

Merge changes I6b0b3ac1,Ie5b73394

* changes:
  Forward SspRequest pairing event to callback
  Add a missing dependency
parents 318973d4 da692fb4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ static_library("btcore") {

  deps = [
    "//bt/gd/rust/shim:init_flags_bridge_header",
    "//bt/gd/rust/shim:libbluetooth_rust_interop",
    "//bt/gd/rust/shim:message_loop_thread_bridge_header",
  ]
}
+13 −0
Original line number Diff line number Diff line
//! D-Bus proxy implementations of the APIs.

use bt_topshim::btif::BtSspVariant;

use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback};
use btstack::RPCProxy;

@@ -19,6 +21,7 @@ use std::sync::{Arc, Mutex};
use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust};

impl_dbus_arg_enum!(BluetoothTransport);
impl_dbus_arg_enum!(BtSspVariant);

#[dbus_propmap(BluetoothDevice)]
pub struct BluetoothDeviceDBus {
@@ -98,6 +101,16 @@ impl IBluetoothCallback for IBluetoothCallbackDBus {

    #[dbus_method("OnDiscoveringChanged")]
    fn on_discovering_changed(&self, discovering: bool) {}

    #[dbus_method("OnSspRequest")]
    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
    }
}

// TODO: These are boilerplate codes, consider creating a macro to generate.
+22 −0
Original line number Diff line number Diff line
use bt_topshim::btif::BtSspVariant;
use bt_topshim::topstack;

use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothCallback};
@@ -43,6 +44,27 @@ impl IBluetoothCallback for BtCallback {
    fn on_discovering_changed(&self, discovering: bool) {
        print_info!("Discovering: {}", discovering);
    }

    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        _cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
        if variant == BtSspVariant::PasskeyNotification {
            print_info!(
                "device {}{} would like to pair, enter passkey on remote device: {:06}",
                remote_device.address.to_string(),
                if remote_device.name.len() > 0 {
                    format!(" ({})", remote_device.name)
                } else {
                    String::from("")
                },
                passkey
            );
        }
    }
}

impl RPCProxy for BtCallback {
+12 −0
Original line number Diff line number Diff line
extern crate bt_shim;

use bt_topshim::btif::BtSspVariant;

use btstack::bluetooth::{BluetoothDevice, BluetoothTransport, IBluetooth, IBluetoothCallback};
use btstack::RPCProxy;

@@ -37,9 +39,19 @@ impl IBluetoothCallback for BluetoothCallbackDBus {
    fn on_device_found(&self, remote_device: BluetoothDevice) {}
    #[dbus_method("OnDiscoveringChanged")]
    fn on_discovering_changed(&self, discovering: bool) {}
    #[dbus_method("OnSspRequest")]
    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
    }
}

impl_dbus_arg_enum!(BluetoothTransport);
impl_dbus_arg_enum!(BtSspVariant);

#[allow(dead_code)]
struct IBluetoothDBus {}
+26 −3
Original line number Diff line number Diff line
@@ -96,6 +96,15 @@ pub trait IBluetoothCallback: RPCProxy {

    /// When the discovery state is changed.
    fn on_discovering_changed(&self, discovering: bool);

    /// When there is a pairing/bonding process and requires agent to display the event to UI.
    fn on_ssp_request(
        &self,
        remote_device: BluetoothDevice,
        cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    );
}

/// Implementation of the adapter API.
@@ -242,14 +251,28 @@ impl BtifBluetoothCallbacks for Bluetooth {
    fn ssp_request(
        &mut self,
        remote_addr: RawAddress,
        _remote_name: String,
        _cod: u32,
        remote_name: String,
        cod: u32,
        variant: BtSspVariant,
        passkey: u32,
    ) {
        // Currently this supports many agent because we accept many callbacks.
        // TODO: We need a way to select the default agent.
        self.for_all_callbacks(|callback| {
            callback.on_ssp_request(
                BluetoothDevice {
                    address: BDAddr::from_byte_vec(&remote_addr.address.to_vec())
                        .unwrap()
                        .to_string(),
                    name: remote_name.clone(),
                },
                cod,
                variant.clone(),
                passkey,
            );
        });
        // Immediately accept the pairing.
        // TODO: Delegate the pairing confirmation to agent.
        // TODO: Implement other pairing confirmations (passkey, passcode, etc);
        self.intf.lock().unwrap().ssp_reply(&remote_addr, variant, 1, passkey);
    }

Loading