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

Commit 10150b3f authored by Yun-Hao Chung's avatar Yun-Hao Chung Committed by Yun-hao Chung
Browse files

Floss: Expose DBus method to get remote RSSI

This exposes a DBus method to get remote RSSI from libbluetooth.

Bug: 227405934
Test: get rssi from the remote device.
Test: mma -j

Change-Id: Iffc993baa351dc1b4b96d995b619fca2c1d59ff6
parent f20d1bc5
Loading
Loading
Loading
Loading
+23 −1
Original line number Original line Diff line number Diff line
@@ -9,7 +9,7 @@ use crate::bt_gatt::AuthReq;
use crate::callbacks::{BtGattCallback, BtGattServerCallback};
use crate::callbacks::{BtGattCallback, BtGattServerCallback};
use crate::ClientContext;
use crate::ClientContext;
use crate::{console_red, console_yellow, print_error, print_info};
use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::{BtConnectionState, BtDiscMode, BtStatus, BtTransport};
use bt_topshim::btif::{BtConnectionState, BtDiscMode, BtStatus, BtTransport, INVALID_RSSI};
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::sdp::{BtSdpMpsRecord, BtSdpRecord};
use bt_topshim::profiles::sdp::{BtSdpMpsRecord, BtSdpRecord};
use bt_topshim::profiles::{gatt::LePhy, ProfileConnectionState};
use bt_topshim::profiles::{gatt::LePhy, ProfileConnectionState};
@@ -155,6 +155,7 @@ fn build_commands() -> HashMap<String, CommandOption> {
                String::from("device set-pairing-pin <address> <pin|reject>"),
                String::from("device set-pairing-pin <address> <pin|reject>"),
                String::from("device set-pairing-passkey <address> <passkey|reject>"),
                String::from("device set-pairing-passkey <address> <passkey|reject>"),
                String::from("device set-alias <address> <new-alias>"),
                String::from("device set-alias <address> <new-alias>"),
                String::from("device get-rssi <address>"),
            ],
            ],
            description: String::from("Take action on a remote device. (i.e. info)"),
            description: String::from("Take action on a remote device. (i.e. info)"),
            function_pointer: CommandHandler::cmd_device,
            function_pointer: CommandHandler::cmd_device,
@@ -896,6 +897,27 @@ impl CommandHandler {
                    passkey,
                    passkey,
                );
                );
            }
            }
            "get-rssi" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    name: String::from(""),
                };

                match self
                    .lock_context()
                    .adapter_dbus
                    .as_mut()
                    .unwrap()
                    .get_remote_rssi(device.clone())
                {
                    INVALID_RSSI => {
                        println!("Invalid RSSI");
                    }
                    rssi => {
                        println!("RSSI: {}", rssi);
                    }
                };
            }
            other => {
            other => {
                println!("Invalid argument '{}'", other);
                println!("Invalid argument '{}'", other);
            }
            }
+5 −0
Original line number Original line Diff line number Diff line
@@ -929,6 +929,11 @@ impl IBluetooth for BluetoothDBus {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("GetRemoteRSSI")]
    fn get_remote_rssi(&self, device: BluetoothDevice) -> i8 {
        dbus_generated!()
    }

    #[dbus_method("GetConnectedDevices")]
    #[dbus_method("GetConnectedDevices")]
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        dbus_generated!()
        dbus_generated!()
+5 −0
Original line number Original line Diff line number Diff line
@@ -642,6 +642,11 @@ impl IBluetooth for IBluetoothDBus {
        dbus_generated!()
        dbus_generated!()
    }
    }


    #[dbus_method("GetRemoteRSSI", DBusLog::Disable)]
    fn get_remote_rssi(&self, device: BluetoothDevice) -> i8 {
        dbus_generated!()
    }

    #[dbus_method("GetConnectedDevices", DBusLog::Disable)]
    #[dbus_method("GetConnectedDevices", DBusLog::Disable)]
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        dbus_generated!()
        dbus_generated!()
+11 −1
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@ use bt_topshim::btif::{
    BtAddrType, BtBondState, BtConnectionDirection, BtConnectionState, BtDeviceType, BtDiscMode,
    BtAddrType, BtBondState, BtConnectionDirection, BtConnectionState, BtDeviceType, BtDiscMode,
    BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, BtSspVariant, BtState,
    BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, BtSspVariant, BtState,
    BtStatus, BtThreadEvent, BtTransport, BtVendorProductInfo, DisplayAddress, RawAddress,
    BtStatus, BtThreadEvent, BtTransport, BtVendorProductInfo, DisplayAddress, RawAddress,
    ToggleableProfile, Uuid, Uuid128Bit,
    ToggleableProfile, Uuid, Uuid128Bit, INVALID_RSSI,
};
};
use bt_topshim::{
use bt_topshim::{
    metrics,
    metrics,
@@ -197,6 +197,9 @@ pub trait IBluetooth {
    /// Get the address type of the remote device.
    /// Get the address type of the remote device.
    fn get_remote_address_type(&self, device: BluetoothDevice) -> BtAddrType;
    fn get_remote_address_type(&self, device: BluetoothDevice) -> BtAddrType;


    /// Get the RSSI of the remote device.
    fn get_remote_rssi(&self, device: BluetoothDevice) -> i8;

    /// Returns a list of connected devices.
    /// Returns a list of connected devices.
    fn get_connected_devices(&self) -> Vec<BluetoothDevice>;
    fn get_connected_devices(&self) -> Vec<BluetoothDevice>;


@@ -2381,6 +2384,13 @@ impl IBluetooth for Bluetooth {
        }
        }
    }
    }


    fn get_remote_rssi(&self, device: BluetoothDevice) -> i8 {
        match self.get_remote_device_property(&device, &BtPropertyType::RemoteRssi) {
            Some(BluetoothProperty::RemoteRssi(rssi)) => rssi,
            _ => INVALID_RSSI,
        }
    }

    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
    fn get_connected_devices(&self) -> Vec<BluetoothDevice> {
        let bonded_connected: HashMap<String, BluetoothDevice> = self
        let bonded_connected: HashMap<String, BluetoothDevice> = self
            .bonded_devices
            .bonded_devices
+7 −0
Original line number Original line Diff line number Diff line
@@ -502,6 +502,13 @@ pub enum BluetoothProperty {
    Unknown(),
    Unknown(),
}
}


/// Unknown or invalid RSSI value.
/// Per Core v5.3, Vol 4, E, 7.5.4. Valid RSSI is represent in 1-byte with the range:
/// BR/EDR: -128 to 127
/// LE: -127 to 20, 127
/// Set 127 as invalid value also aligns with bluez.
pub const INVALID_RSSI: i8 = 127;

/// Wherever names are sent in bindings::bt_property_t, the size of the character
/// Wherever names are sent in bindings::bt_property_t, the size of the character
/// arrays are 256. Keep one extra byte for null termination.
/// arrays are 256. Keep one extra byte for null termination.
const PROPERTY_NAME_MAX: usize = 255;
const PROPERTY_NAME_MAX: usize = 255;