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

Commit b492ef89 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

LE Audio: Prefer bonding using LE transport.

When LE Audio capable device advertises using same address on both LE
and Classic transport, prefer connecting and initial bond establishment
using LE transport.

This is helping with devices that can't do CTKD from classic to LE -
such devices are mandated by BAP specification to use same address on
both transports.

It also simplifies the service discovery handling, which will be further
improved in upcoming patches.

Bug: 246560805
Test: manual, pair with LE Audio capable device that can't CTKD
Change-Id: I91ce850e67548169b6ff645a589defee1d2509ab
parent 9e292d6d
Loading
Loading
Loading
Loading
+38 −3
Original line number Original line Diff line number Diff line
@@ -101,8 +101,6 @@ const Uuid UUID_BASS = Uuid::FromString("184F");
const Uuid UUID_BATTERY = Uuid::FromString("180F");
const Uuid UUID_BATTERY = Uuid::FromString("180F");
const bool enable_address_consolidate = true;  // TODO remove
const bool enable_address_consolidate = true;  // TODO remove


#define COD_MASK 0x07FF

#define COD_UNCLASSIFIED ((0x1F) << 8)
#define COD_UNCLASSIFIED ((0x1F) << 8)
#define COD_HID_KEYBOARD 0x0540
#define COD_HID_KEYBOARD 0x0540
#define COD_HID_POINTING 0x0580
#define COD_HID_POINTING 0x0580
@@ -115,6 +113,8 @@ const bool enable_address_consolidate = true; // TODO remove
#define COD_AV_PORTABLE_AUDIO 0x041C
#define COD_AV_PORTABLE_AUDIO 0x041C
#define COD_AV_HIFI_AUDIO 0x0428
#define COD_AV_HIFI_AUDIO 0x0428


#define COD_CLASS_LE_AUDIO (1 << 14)

#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2


#ifndef PROPERTY_CLASS_OF_DEVICE
#ifndef PROPERTY_CLASS_OF_DEVICE
@@ -470,7 +470,7 @@ static uint32_t get_cod(const RawAddress* remote_bdaddr) {
  if (btif_storage_get_remote_device_property(
  if (btif_storage_get_remote_device_property(
          (RawAddress*)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) {
          (RawAddress*)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) {
    LOG_INFO("%s remote_cod = 0x%08x", __func__, remote_cod);
    LOG_INFO("%s remote_cod = 0x%08x", __func__, remote_cod);
    return remote_cod & COD_MASK;
    return remote_cod;
  }
  }


  return 0;
  return 0;
@@ -488,6 +488,9 @@ bool check_cod_hid(const RawAddress& bd_addr) {
  return (get_cod(&bd_addr) & COD_HID_MASK) == COD_HID_MAJOR;
  return (get_cod(&bd_addr) & COD_HID_MASK) == COD_HID_MAJOR;
}
}


bool check_cod_le_audio(const RawAddress& bd_addr) {
  return (get_cod(&bd_addr) & COD_CLASS_LE_AUDIO) == COD_CLASS_LE_AUDIO;
}
/*****************************************************************************
/*****************************************************************************
 *
 *
 * Function        check_sdp_bl
 * Function        check_sdp_bl
@@ -682,6 +685,33 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
                                     properties);
                                     properties);
}
}


/* If device is LE Audio capable, we prefer LE connection first, this speeds
 * up LE profile connection, and limits all possible service discovery
 * ordering issues (first Classic, GATT over SDP, etc) */
static bool is_device_le_audio_capable(const RawAddress bd_addr) {
  if (!LeAudioClient::IsLeAudioClientRunning() ||
      !check_cod_le_audio(bd_addr)) {
    return false;
  }

  tBT_DEVICE_TYPE tmp_dev_type;
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &addr_type);
  if (tmp_dev_type & BT_DEVICE_TYPE_BLE) {
    return true;
  }

  int device_type = 0;
  std::string addrstr = bd_addr.ToString();
  const char* bdstr = addrstr.c_str();
  btif_config_get_int(bdstr, "DevType", &device_type);
  if ((device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) {
    return true;
  }

  return false;
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         btif_dm_cb_create_bond
 * Function         btif_dm_cb_create_bond
@@ -697,6 +727,11 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
  bool is_hid = check_cod(&bd_addr, COD_HID_POINTING);
  bool is_hid = check_cod(&bd_addr, COD_HID_POINTING);
  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);


  if (transport == BT_TRANSPORT_AUTO && is_device_le_audio_capable(bd_addr)) {
    LOG_INFO("LE Audio && advertising over LE, use LE transport for Bonding");
    transport = BT_TRANSPORT_LE;
  }

  int device_type = 0;
  int device_type = 0;
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  std::string addrstr = bd_addr.ToString();
  std::string addrstr = bd_addr.ToString();