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

Commit 619dfe69 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Floss: Implement GATT client commands"

parents 32fb43dd b87d1901
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ num-traits = "*"
tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'memchr', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }

clap = "2.33.3"
bitflags = "1.2"
hex = "0.4.3"
[build-dependencies]
pkg-config = "0.3.19"

+44 −0
Original line number Diff line number Diff line
use bitflags::bitflags;
use bt_topshim::btif::BtTransport;
use bt_topshim::profiles::gatt::LePhy;

bitflags! {
    pub(crate) struct AuthReq: i32 {
        // reference to system/stack/include/gatt_api.h
        const MITM   = 0x01;
        const SIGNED = 0x10;
    }
}

/// User preferenece of GATT operations
pub(crate) struct GattClientContext {
    /// If set, the registered GATT client id. None otherwise.
    pub(crate) client_id: Option<i32>,
    /// Type of authentication requirement
    pub(crate) auth_req: AuthReq,
    /// Is connection going to be directed?
    pub(crate) is_connect_direct: bool,
    /// Transport of connection
    pub(crate) connect_transport: BtTransport,
    /// Is connection going to be opportunistic?
    pub(crate) connect_opportunistic: bool,
    /// Type of connect phy
    pub(crate) connect_phy: LePhy,
}

impl GattClientContext {
    pub(crate) fn new() -> Self {
        GattClientContext {
            client_id: None,
            auth_req: AuthReq::empty(),
            is_connect_direct: false,
            connect_transport: BtTransport::Le,
            connect_opportunistic: false,
            connect_phy: LePhy::Phy1m,
        }
    }

    pub(crate) fn get_auth_req_bits(&self) -> i32 {
        self.auth_req.bits()
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -579,7 +579,7 @@ impl BtGattCallback {
impl IBluetoothGattCallback for BtGattCallback {
    fn on_client_registered(&self, status: GattStatus, client_id: i32) {
        print_info!("GATT Client registered status = {}, client_id = {}", status, client_id);
        self.context.lock().unwrap().gatt_client_id = Some(client_id);
        self.context.lock().unwrap().gatt_client_context.client_id = Some(client_id);
    }

    fn on_client_connection_state(
+225 −80

File changed.

Preview size limit exceeded, changes collapsed.

+6 −4
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ use dbus_crossroads::Crossroads;
use tokio::sync::mpsc;

use crate::bt_adv::AdvSet;
use crate::bt_gatt::GattClientContext;
use crate::callbacks::{
    AdminCallback, AdvertisingSetCallback, BtCallback, BtConnectionCallback, BtManagerCallback,
    BtSocketManagerCallback, ScannerCallback, SuspendCallback,
@@ -28,6 +29,7 @@ use btstack::suspend::ISuspend;
use manager_service::iface_bluetooth_manager::IBluetoothManager;

mod bt_adv;
mod bt_gatt;
mod callbacks;
mod command_handler;
mod console;
@@ -68,9 +70,6 @@ pub(crate) struct ClientContext {
    /// List of bonded devices.
    pub(crate) bonded_devices: HashMap<String, BluetoothDevice>,

    /// If set, the registered GATT client id. None otherwise.
    pub(crate) gatt_client_id: Option<i32>,

    /// Proxy for manager interface.
    pub(crate) manager_dbus: BluetoothManagerDBus,

@@ -121,6 +120,9 @@ pub(crate) struct ClientContext {

    /// Is btclient running in restricted mode?
    is_restricted: bool,

    /// Data of GATT client preference.
    gatt_client_context: GattClientContext,
}

impl ClientContext {
@@ -144,7 +146,6 @@ impl ClientContext {
            discovering_state: false,
            found_devices: HashMap::new(),
            bonded_devices: HashMap::new(),
            gatt_client_id: None,
            manager_dbus,
            adapter_dbus: None,
            qa_dbus: None,
@@ -162,6 +163,7 @@ impl ClientContext {
            adv_sets: HashMap::new(),
            socket_manager_callback_id: None,
            is_restricted,
            gatt_client_context: GattClientContext::new(),
        }
    }

Loading