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

Commit 3d8ff7ed authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Android (Google) Code Review
Browse files

Merge changes Id97aa338,Iacefcd04,I91ce850e into tm-qpr-dev

* changes:
  CTKD from LE to Classic stability fix
  Replace CTKD detection with information from lower layers
  LE Audio: Prefer bonding using LE transport.
parents 96484cd4 43709a1e
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -87,7 +87,8 @@ static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class,
static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr,
                                         DEV_CLASS dev_class,
                                         tBTM_BD_NAME bd_name,
                                         const LinkKey& key, uint8_t key_type);
                                         const LinkKey& key, uint8_t key_type,
                                         bool is_ctkd);
static void bta_dm_authentication_complete_cback(const RawAddress& bd_addr,
                                                 DEV_CLASS dev_class,
                                                 tBTM_BD_NAME bd_name,
@@ -2075,7 +2076,8 @@ static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class,
static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr,
                                         UNUSED_ATTR DEV_CLASS dev_class,
                                         tBTM_BD_NAME bd_name,
                                         const LinkKey& key, uint8_t key_type) {
                                         const LinkKey& key, uint8_t key_type,
                                         bool is_ctkd) {
  tBTA_DM_SEC sec_event;
  tBTA_DM_AUTH_CMPL* p_auth_cmpl;
  tBTA_DM_SEC_EVT event = BTA_DM_AUTH_CMPL_EVT;
@@ -2092,6 +2094,8 @@ static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr,
  p_auth_cmpl->key_type = key_type;
  p_auth_cmpl->success = true;
  p_auth_cmpl->key = key;
  p_auth_cmpl->is_ctkd = is_ctkd;

  sec_event.auth_cmpl.fail_reason = HCI_SUCCESS;

  // Report the BR link key based on the BR/EDR address and type
+1 −0
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ typedef struct {
      fail_reason; /* The HCI reason/error code for when success=false */
  tBLE_ADDR_TYPE addr_type; /* Peer device address type */
  tBT_DEVICE_TYPE dev_type;
  bool is_ctkd; /* True if key is derived using CTKD procedure */
} tBTA_DM_AUTH_CMPL;

/* Structure associated with BTA_DM_LINK_UP_EVT */
+40 −7
Original line number Diff line number Diff line
@@ -109,8 +109,6 @@ const Uuid UUID_BASS = Uuid::FromString("184F");
const Uuid UUID_BATTERY = Uuid::FromString("180F");
const bool enable_address_consolidate = true;  // TODO remove

#define COD_MASK 0x07FF

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

#define COD_CLASS_LE_AUDIO (1 << 14)

#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2

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

  return 0;
@@ -463,6 +463,9 @@ bool check_cod_hid(const RawAddress& bd_addr) {
  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
@@ -657,6 +660,33 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
                                     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
@@ -672,6 +702,11 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
  bool is_hid = check_cod(&bd_addr, COD_HID_POINTING);
  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;
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  std::string addrstr = bd_addr.ToString();
@@ -1044,8 +1079,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
    }

    bool is_crosskey = false;
    if (pairing_cb.state == BT_BOND_STATE_BONDING &&
        p_auth_cmpl->bd_addr != pairing_cb.bd_addr) {
    if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->is_ctkd) {
      LOG_INFO("bonding initiated due to cross key pairing");
      is_crosskey = true;
    }
@@ -1078,8 +1112,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
      invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1, &prop);
    } else {
      /* If bonded due to cross-key, save the static address too*/
      if (pairing_cb.state == BT_BOND_STATE_BONDING &&
          p_auth_cmpl->bd_addr != pairing_cb.bd_addr) {
      if (is_crosskey) {
        BTIF_TRACE_DEBUG(
            "%s: bonding initiated due to cross key, adding static address",
            __func__);
+1 −1
Original line number Diff line number Diff line
@@ -460,7 +460,7 @@ class ShimBondListener : public bluetooth::security::ISecurityManagerListener {
        LinkKey key;  // Never want to send the key to the stack
        (*bta_callbacks_->p_link_key_callback)(
            bluetooth::ToRawAddress(device.GetAddress()), 0, name, key,
            BTM_LKEY_TYPE_COMBINATION);
            BTM_LKEY_TYPE_COMBINATION, false /* is_ctkd */);
      }
      if (*bta_callbacks_->p_auth_complete_callback) {
        (*bta_callbacks_->p_auth_complete_callback)(
+7 −7
Original line number Diff line number Diff line
@@ -3941,9 +3941,9 @@ void btm_sec_link_key_notification(const RawAddress& p_bda,
    if (btm_cb.api.p_link_key_callback) {
      BTM_TRACE_DEBUG("%s() Save LTK derived LK (key_type = %d)", __func__,
                      p_dev_rec->link_key_type);
      (*btm_cb.api.p_link_key_callback)(p_bda, p_dev_rec->dev_class,
                                        p_dev_rec->sec_bd_name, link_key,
                                        p_dev_rec->link_key_type);
      (*btm_cb.api.p_link_key_callback)(
          p_bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, link_key,
          p_dev_rec->link_key_type, true /* is_ctkd */);
    }
  } else {
    if ((p_dev_rec->link_key_type == BTM_LKEY_TYPE_UNAUTH_COMB_P_256) ||
@@ -3991,9 +3991,9 @@ void btm_sec_link_key_notification(const RawAddress& p_bda,
            " (key_type = %d)",
            p_dev_rec->link_key_type);
      } else {
        (*btm_cb.api.p_link_key_callback)(p_bda, p_dev_rec->dev_class,
                                          p_dev_rec->sec_bd_name, link_key,
                                          p_dev_rec->link_key_type);
        (*btm_cb.api.p_link_key_callback)(
            p_bda, p_dev_rec->dev_class, p_dev_rec->sec_bd_name, link_key,
            p_dev_rec->link_key_type, false /* is_ctkd */);
      }
    }
  }
@@ -4579,7 +4579,7 @@ static void btm_send_link_key_notif(tBTM_SEC_DEV_REC* p_dev_rec) {
  if (btm_cb.api.p_link_key_callback)
    (*btm_cb.api.p_link_key_callback)(
        p_dev_rec->bd_addr, p_dev_rec->dev_class, p_dev_rec->sec_bd_name,
        p_dev_rec->link_key, p_dev_rec->link_key_type);
        p_dev_rec->link_key, p_dev_rec->link_key_type, false);
}

/*******************************************************************************
Loading