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

Commit 0d32ddd5 authored by JohnLai's avatar JohnLai
Browse files

floss: Add LE discoverable mode

Support a new advertising parameter: LeDiscMode. The default mode of
a started advertisement is general discoverable mode.

Bug: 331693399
Tag: #floss
Test: m Bluetooth
Flag: EXEMPT floss only changes
Change-Id: Ie541a19948429edb988a7542ad95d722bc650e42
parent 1ced6883
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ use crate::ClientContext;
use crate::{console_yellow, print_info};

use bt_topshim::btif::Uuid;
use bt_topshim::profiles::gatt::LePhy;
use bt_topshim::profiles::gatt::{LeDiscMode, LePhy};
use btstack::bluetooth_adv::{AdvertiseData, AdvertiserId, AdvertisingSetParameters};
use btstack::bluetooth_gatt::IBluetoothGatt;

@@ -28,6 +28,7 @@ pub(crate) struct AdvSet {
impl AdvSet {
    pub(crate) fn new(is_legacy: bool) -> Self {
        let params = AdvertisingSetParameters {
            discoverable: LeDiscMode::GeneralDiscoverable,
            connectable: false,
            scannable: false,
            is_legacy,
+3 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ use bt_topshim::profiles::a2dp::{
    A2dpCodecSampleRate, PresentationPosition,
};
use bt_topshim::profiles::avrcp::PlayerMetadata;
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy};
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LeDiscMode, LePhy};
use bt_topshim::profiles::hfp::{EscoCodingFormat, HfpCodecBitId, HfpCodecFormat};
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::sdp::{
@@ -88,6 +88,7 @@ impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(GattWriteType);
impl_dbus_arg_enum!(LeDiscMode);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(ProfileConnectionState);
impl_dbus_arg_enum!(ScanType);
@@ -1267,6 +1268,7 @@ impl IAdvertisingSetCallback for IAdvertisingSetCallbackDBus {

#[dbus_propmap(AdvertisingSetParameters)]
struct AdvertisingSetParametersDBus {
    discoverable: LeDiscMode,
    connectable: bool,
    scannable: bool,
    is_legacy: bool,
+3 −1
Original line number Diff line number Diff line
use bt_topshim::btif::{BtStatus, BtTransport, Uuid, Uuid128Bit};
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy};
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LeDiscMode, LePhy};

use btstack::bluetooth_adv::{
    AdvertiseData, AdvertisingSetParameters, IAdvertisingSetCallback, ManfId,
@@ -381,6 +381,7 @@ impl_dbus_arg_enum!(AdvertisingStatus);
impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(GattWriteType);
impl_dbus_arg_enum!(LeDiscMode);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(ScanType);
impl_dbus_arg_enum!(SuspendMode);
@@ -570,6 +571,7 @@ impl IAdvertisingSetCallback for AdvertisingSetCallbackDBus {

#[dbus_propmap(AdvertisingSetParameters)]
struct AdvertisingSetParametersDBus {
    discoverable: LeDiscMode,
    connectable: bool,
    scannable: bool,
    is_legacy: bool,
+10 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
use btif_macros::{btif_callback, btif_callbacks_dispatcher};

use bt_topshim::btif::{RawAddress, Uuid};
use bt_topshim::profiles::gatt::{AdvertisingStatus, Gatt, GattAdvCallbacks, LePhy};
use bt_topshim::profiles::gatt::{AdvertisingStatus, Gatt, GattAdvCallbacks, LeDiscMode, LePhy};

use itertools::Itertools;
use log::{debug, error, info, warn};
@@ -28,6 +28,8 @@ pub type ManfId = u16;
/// Advertising parameters for each BLE advertising set.
#[derive(Debug, Default, Clone)]
pub struct AdvertisingSetParameters {
    /// Discoverable modes.
    pub discoverable: LeDiscMode,
    /// Whether the advertisement will be connectable.
    pub connectable: bool,
    /// Whether the advertisement will be scannable.
@@ -228,6 +230,13 @@ impl Into<bt_topshim::profiles::gatt::AdvertiseParameters> for AdvertisingSetPar
            props |= 0x40;
        }

        match self.discoverable {
            LeDiscMode::GeneralDiscoverable => {
                props |= 0x04;
            }
            _ => {}
        }

        let interval = clamp(self.interval, INTERVAL_MIN, INTERVAL_MAX - INTERVAL_DELTA);

        bt_topshim::profiles::gatt::AdvertiseParameters {
+28 −0
Original line number Diff line number Diff line
@@ -547,6 +547,34 @@ impl Display for GattStatus {
    }
}

#[derive(Debug, FromPrimitive, ToPrimitive, Clone, Copy)]
#[repr(u32)]
/// LE Discoverable modes.
pub enum LeDiscMode {
    Invalid = 0,
    NonDiscoverable,
    LimitedDiscoverable,
    GeneralDiscoverable,
}

impl From<u32> for LeDiscMode {
    fn from(num: u32) -> Self {
        LeDiscMode::from_u32(num).unwrap_or(LeDiscMode::Invalid)
    }
}

impl Into<u32> for LeDiscMode {
    fn into(self) -> u32 {
        self.to_u32().unwrap_or(0)
    }
}

impl Default for LeDiscMode {
    fn default() -> Self {
        LeDiscMode::Invalid
    }
}

#[derive(Debug, FromPrimitive, ToPrimitive, Clone, Copy)]
#[repr(u8)]
/// Represents LE PHY.