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

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

Merge "AOSP: Correct device type for dual mode peers"

parents dc1b005c 6e04a77d
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -689,7 +689,11 @@ static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
  int dev_type;

  /* Remote properties update */
  if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type)) {
  if (BTM_GetPeerDeviceTypeFromFeatures(p_pin_req->bd_addr) ==
      BT_DEVICE_TYPE_DUMO) {
    dev_type = BT_DEVICE_TYPE_DUMO;
  } else if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type)) {
    // Failed to get device type, defaulting to BR/EDR.
    dev_type = BT_DEVICE_TYPE_BREDR;
  }
  btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
@@ -777,7 +781,11 @@ static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ* p_ssp_cfm_req) {
  BTIF_TRACE_DEBUG("%s", __func__);

  /* Remote properties update */
  if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type)) {
  if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_cfm_req->bd_addr) ==
      BT_DEVICE_TYPE_DUMO) {
    dev_type = BT_DEVICE_TYPE_DUMO;
  } else if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type)) {
    // Failed to get device type, defaulting to BR/EDR.
    dev_type = BT_DEVICE_TYPE_BREDR;
  }
  btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
@@ -853,7 +861,11 @@ static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
  BTIF_TRACE_DEBUG("%s", __func__);

  /* Remote properties update */
  if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) {
  if (BTM_GetPeerDeviceTypeFromFeatures(p_ssp_key_notif->bd_addr) ==
      BT_DEVICE_TYPE_DUMO) {
    dev_type = BT_DEVICE_TYPE_DUMO;
  } else if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) {
    // Failed to get device type, defaulting to BR/EDR.
    dev_type = BT_DEVICE_TYPE_BREDR;
  }
  btif_update_remote_properties(
@@ -945,8 +957,15 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
    if (!bluetooth::shim::is_gd_security_enabled()) {
      btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
    }

    int dev_type;
    if (BTM_GetPeerDeviceTypeFromFeatures(bd_addr) == BT_DEVICE_TYPE_DUMO) {
      dev_type = BT_DEVICE_TYPE_DUMO;
    } else {
      dev_type = p_auth_cmpl->dev_type;
    }
    btif_update_remote_properties(p_auth_cmpl->bd_addr, p_auth_cmpl->bd_name,
                                  NULL, p_auth_cmpl->dev_type);
                                  NULL, dev_type);
    pairing_cb.timeout_retries = 0;
    status = BT_STATUS_SUCCESS;
    state = BT_BOND_STATE_BONDED;
+17 −0
Original line number Diff line number Diff line
@@ -1689,6 +1689,23 @@ bool BTM_BothEndsSupportSecureConnections(const RawAddress& bd_addr);
 ******************************************************************************/
bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr);

/*******************************************************************************
 *
 * Function         BTM_GetPeerDeviceTypeFromFeatures
 *
 * Description      This function is called to retrieve the peer device type
 *                  by referencing the remote features.
 *
 * Parameters:      bd_addr - address of the peer
 *
 * Returns          BT_DEVICE_TYPE_DUMO if both BR/EDR and BLE transports are
 *                  supported by the peer,
 *                  BT_DEVICE_TYPE_BREDR if only BR/EDR transport is supported,
 *                  BT_DEVICE_TYPE_BLE if only BLE transport is supported.
 *
 ******************************************************************************/
tBT_DEVICE_TYPE BTM_GetPeerDeviceTypeFromFeatures(const RawAddress& bd_addr);

/*******************************************************************************
 *
 * Function         BTM_SecReadDevName
+13 −1
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ using namespace bluetooth::l2cap;

namespace {
uint16_t classic_cid_token_counter_ = 0x41;
constexpr uint64_t kBrEdrNotSupportedMask = 0x0000002000000000;      // Bit 37
constexpr uint64_t kLeSupportedControllerMask = 0x0000004000000000;  // Bit 38
constexpr uint64_t kLeSupportedHostMask = 0x0000000000000002;        // Bit 1

std::unordered_map<uint16_t /* token */, uint16_t /* psm */>
    classic_cid_token_to_channel_map_;
@@ -369,6 +372,9 @@ struct RemoteFeature {
  uint8_t raw_remote_features[8];
  bool version_info_received = false;
  bool role_switch_supported = false;
  bool br_edr_supported = false;
  bool le_supported_controller = false;
  bool le_supported_host = false;
  bool ssp_supported = false;
  bool sc_supported = false;
  bool received_page_0 = false;
@@ -409,15 +415,21 @@ struct LinkPropertyListenerShim
    if (page_number == 0) {
      entry.received_page_0 = true;
      if (features & 0x20) entry.role_switch_supported = true;
      entry.br_edr_supported = !(features & kBrEdrNotSupportedMask);
      entry.le_supported_controller = features & kLeSupportedControllerMask;
      std::memcpy(entry.raw_remote_features, &features, 8);
    }
    if (page_number == 1) {
      entry.received_page_1 = true;
      if (features & 0x01) entry.ssp_supported = true;
      entry.le_supported_host = features & kLeSupportedHostMask;
    }
    if (entry.received_page_0 && entry.received_page_1) {
      const bool le_supported =
          entry.le_supported_controller && entry.le_supported_host;
      btm_sec_set_peer_sec_caps(address_to_handle_[remote], entry.ssp_supported,
                                false, entry.role_switch_supported);
                                false, entry.role_switch_supported,
                                entry.br_edr_supported, le_supported);
    }
  }

+7 −2
Original line number Diff line number Diff line
@@ -852,9 +852,14 @@ void btm_process_remote_ext_features(tACL_CONN* p_acl_cb,
      HCI_SC_HOST_SUPPORTED(p_acl_cb->peer_lmp_feature_pages[1]);
  bool role_switch_supported =
      HCI_SWITCH_SUPPORTED(p_acl_cb->peer_lmp_feature_pages[0]);
  bool br_edr_supported =
      !HCI_BREDR_NOT_SPT_SUPPORTED(p_acl_cb->peer_lmp_feature_pages[0]);
  bool le_supported =
      HCI_LE_SPT_SUPPORTED(p_acl_cb->peer_lmp_feature_pages[0]) &&
      HCI_LE_HOST_SUPPORTED(p_acl_cb->peer_lmp_feature_pages[1]);
  btm_sec_set_peer_sec_caps(p_acl_cb->hci_handle, ssp_supported,
                            secure_connections_supported,
                            role_switch_supported);
                            secure_connections_supported, role_switch_supported,
                            br_edr_supported, le_supported);
}

/*******************************************************************************
+39 −1
Original line number Diff line number Diff line
@@ -1377,6 +1377,40 @@ bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr) {
  return (p_dev_rec->SupportsSecureConnections());
}

/*******************************************************************************
 *
 * Function         BTM_GetPeerDeviceTypeFromFeatures
 *
 * Description      This function is called to retrieve the peer device type
 *                  by referencing the remote features.
 *
 * Parameters:      bd_addr - address of the peer
 *
 * Returns          BT_DEVICE_TYPE_DUMO if both BR/EDR and BLE transports are
 *                  supported by the peer,
 *                  BT_DEVICE_TYPE_BREDR if only BR/EDR transport is supported,
 *                  BT_DEVICE_TYPE_BLE if only BLE transport is supported.
 *
 ******************************************************************************/
tBT_DEVICE_TYPE BTM_GetPeerDeviceTypeFromFeatures(const RawAddress& bd_addr) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == nullptr) {
    LOG_WARN("Unknown BDA:%s", PRIVATE_ADDRESS(bd_addr));
  } else {
    if (p_dev_rec->remote_supports_ble && p_dev_rec->remote_supports_bredr) {
      return BT_DEVICE_TYPE_DUMO;
    } else if (p_dev_rec->remote_supports_bredr) {
      return BT_DEVICE_TYPE_BREDR;
    } else if (p_dev_rec->remote_supports_ble) {
      return BT_DEVICE_TYPE_BLE;
    } else {
      LOG_WARN("Device features does not support BR/EDR and BLE:%s",
               PRIVATE_ADDRESS(bd_addr));
    }
  }
  return BT_DEVICE_TYPE_BREDR;
}

/************************************************************************
 *              I N T E R N A L     F U N C T I O N S
 ************************************************************************/
@@ -4834,7 +4868,8 @@ static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC* p_dev_rec) {
 ******************************************************************************/
void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
                               bool sc_supported,
                               bool hci_role_switch_supported) {
                               bool hci_role_switch_supported,
                               bool br_edr_supported, bool le_supported) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(hci_handle);
  if (p_dev_rec == nullptr) return;

@@ -4874,6 +4909,9 @@ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
    /* Request for remaining Security Features (if any) */
    l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr);
  }

  p_dev_rec->remote_supports_bredr = br_edr_supported;
  p_dev_rec->remote_supports_ble = le_supported;
}

// Return DEV_CLASS (uint8_t[3]) of bda. If record doesn't exist, create one.
Loading