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

Commit 38bdd242 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge changes Ia47a912c,Iea59ec9b into main

* changes:
  Populate remote device name from properties if available
  Read device name on connection with new LE devices
parents 5bd32d94 dda890e2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@
#include "rust/src/core/ffi/types.h"
#include "stack/acl/acl.h"
#include "stack/acl/peer_packet_types.h"
#include "stack/btm/btm_ble_int.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/btm_sco.h"
@@ -1003,6 +1004,8 @@ void StackAclBtmAcl::btm_establish_continue(tACL_CONN* p_acl) {
                 default_packet_type_mask, p_acl->RemoteAddress());
    }
    btm_set_link_policy(p_acl, btm_cb.acl_cb_.DefaultLinkPolicy());
  } else if (p_acl->is_transport_ble()) {
    btm_ble_connection_established(p_acl->remote_addr);
  }
  NotifyAclLinkUp(*p_acl);
}
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ void btm_ble_free();
void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode, uint8_t role,
                       tBLE_ADDR_TYPE addr_type, bool addr_matched,
                       bool can_read_discoverable_characteristics);
void btm_ble_connection_established(const RawAddress& bda);

/* acceptlist function */
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
+33 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <android_bluetooth_sysprop.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <cstddef>
#include <cstdint>
@@ -65,6 +66,7 @@ using namespace bluetooth;
extern tBTM_CB btm_cb;

bool btm_ble_init_pseudo_addr(tBTM_SEC_DEV_REC* p_dev_rec, const RawAddress& new_pseudo_addr);
tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda, tBTM_NAME_CMPL_CB* p_cb);

namespace {
constexpr char kBtmLogTag[] = "SEC";
@@ -98,9 +100,17 @@ void BTM_SecAddBleDevice(const RawAddress& bd_addr, tBT_DEVICE_TYPE dev_type,

    log::debug("Device added, handle=0x{:x}, p_dev_rec={}, bd_addr={}", p_dev_rec->ble_hci_handle,
               fmt::ptr(p_dev_rec), bd_addr);

    if (com::android::bluetooth::flags::name_discovery_for_le_pairing() &&
        btif_storage_get_stored_remote_name(bd_addr,
                                            reinterpret_cast<char*>(&p_dev_rec->sec_bd_name))) {
      p_dev_rec->sec_rec.sec_flags |= BTM_SEC_NAME_KNOWN;
    }
  }

  memset(p_dev_rec->sec_bd_name, 0, sizeof(BD_NAME));
  if (!com::android::bluetooth::flags::name_discovery_for_le_pairing()) {
    bd_name_clear(p_dev_rec->sec_bd_name);
  }

  p_dev_rec->device_type |= dev_type;
  if (is_ble_addr_type_known(addr_type)) {
@@ -1481,8 +1491,7 @@ static tBTM_STATUS btm_ble_br_keys_req(tBTM_SEC_DEV_REC* p_dev_rec, tBTM_LE_IO_R
 *
 * Function         btm_ble_connected
 *
 * Description      This function is when a LE connection to the peer device is
 *                  establsihed
 * Description      This function is called on LE connection
 *
 * Returns          void
 *
@@ -1517,6 +1526,27 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t /* enc_mo
  btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_ADV_IND_EVT;
}

/*******************************************************************************
 *
 * Function         btm_ble_connection_established
 *
 * Description      This function when LE connection is established
 *
 * Returns          void
 *
 ******************************************************************************/
void btm_ble_connection_established(const RawAddress& bda) {
  if (!com::android::bluetooth::flags::name_discovery_for_le_pairing()) {
    return;
  }

  // Read device name if it is not known already, we may need it for pairing
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
  if (p_dev_rec != nullptr && !p_dev_rec->sec_rec.is_name_known()) {
    btm_ble_read_remote_name(bda, nullptr);
  }
}

/*****************************************************************************
 *  Function        btm_proc_smp_cback
 *
+11 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include <string>

#include "btif/include/btif_storage.h"
#include "btm_api.h"
#include "btm_int_types.h"
#include "btm_sec_api.h"
@@ -83,6 +84,7 @@ static void wipe_secrets_and_remove(tBTM_SEC_DEV_REC* p_dev_rec) {
void BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class, LinkKey link_key,
                      uint8_t key_type, uint8_t pin_length) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);

  if (!p_dev_rec) {
    p_dev_rec = btm_sec_allocate_dev_rec();
    log::info(
@@ -97,6 +99,12 @@ void BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class, LinkKey li
    /* use default value for background connection params */
    /* update conn params, use default value for background connection params */
    memset(&p_dev_rec->conn_params, 0xff, sizeof(tBTM_LE_CONN_PRAMS));

    if (com::android::bluetooth::flags::name_discovery_for_le_pairing() &&
        btif_storage_get_stored_remote_name(bd_addr,
                                            reinterpret_cast<char*>(&p_dev_rec->sec_bd_name))) {
      p_dev_rec->sec_rec.sec_flags |= BTM_SEC_NAME_KNOWN;
    }
  } else {
    log::info(
            "Caching existing record from config file device: {}, dev_class: "
@@ -119,7 +127,9 @@ void BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class, LinkKey li
    p_dev_rec->dev_class = dev_class;
  }

  memset(p_dev_rec->sec_bd_name, 0, sizeof(BD_NAME));
  if (!com::android::bluetooth::flags::name_discovery_for_le_pairing()) {
    bd_name_clear(p_dev_rec->sec_bd_name);
  }

  p_dev_rec->sec_rec.sec_flags |= BTM_SEC_LINK_KEY_KNOWN;
  p_dev_rec->sec_rec.link_key = link_key;
+5 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ struct BTM_SecAddBleDevice BTM_SecAddBleDevice;
struct BTM_SecAddBleKey BTM_SecAddBleKey;
struct BTM_SecurityGrant BTM_SecurityGrant;
struct btm_ble_connected btm_ble_connected;
struct btm_ble_connection_established btm_ble_connection_established;
struct btm_ble_get_acl_remote_addr btm_ble_get_acl_remote_addr;
struct btm_ble_get_enc_key_type btm_ble_get_enc_key_type;
struct btm_ble_link_encrypted btm_ble_link_encrypted;
@@ -198,6 +199,10 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
  test::mock::stack_btm_ble::btm_ble_connected(bda, handle, enc_mode, role, addr_type, addr_matched,
                                               can_read_discoverable_characteristics);
}
void btm_ble_connection_established(const RawAddress& bda) {
  inc_func_call_count(__func__);
  test::mock::stack_btm_ble::btm_ble_connection_established(bda);
}
bool btm_ble_get_acl_remote_addr(uint16_t hci_handle, RawAddress& conn_addr,
                                 tBLE_ADDR_TYPE* p_addr_type) {
  inc_func_call_count(__func__);
Loading