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

Commit 5b674174 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "Device consolidation in control blocks after bonding" am: d5177caf

parents f9e3cd3f d5177caf
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -496,6 +496,18 @@ void bta_dm_disable() {
  }
}

void bta_dm_consolidate(const RawAddress& identity_addr,
                        const RawAddress& rpa) {
  for (auto i = 0; i < bta_dm_cb.device_list.count; i++) {
    if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr != rpa) continue;

    LOG_INFO("consolidating bda_dm_cb record %s -> %s",
             ADDRESS_TO_LOGGABLE_CSTR(rpa),
             ADDRESS_TO_LOGGABLE_CSTR(identity_addr));
    bta_dm_cb.device_list.peer_device[i].peer_bdaddr = identity_addr;
  }
}

/*******************************************************************************
 *
 * Function         bta_dm_wait_for_all_acl_to_drain
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ void BTA_dm_init() {
  /* if UUID list is not provided as static data */
  bta_sys_eir_register(bta_dm_eir_update_uuid);
  bta_sys_cust_eir_register(bta_dm_eir_update_cust_uuid);
  BTM_SetConsolidationCallback(bta_dm_consolidate);
}

/** This function sets the Bluetooth name of local device */
+2 −0
Original line number Diff line number Diff line
@@ -608,6 +608,8 @@ void bta_dm_eir_update_cust_uuid(const tBTA_CUSTOM_UUID &curr, bool adding);
void bta_dm_ble_subrate_request(const RawAddress& bd_addr, uint16_t subrate_min,
                                uint16_t subrate_max, uint16_t max_latency,
                                uint16_t cont_num, uint16_t timeout);
extern void bta_dm_consolidate(const RawAddress& identity_addr,
                               const RawAddress& rpa);

#undef CASE_RETURN_TEXT
#endif /* BTA_DM_INT_H */
+22 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ struct StackAclBtmAcl {
  void set_default_packet_types_supported(uint16_t packet_types_supported) {
    btm_cb.acl_cb_.btm_acl_pkt_types_supported = packet_types_supported;
  }
  void btm_acl_consolidate(const RawAddress& identity_addr,
                           const RawAddress& rpa);
};

struct RoleChangeView {
@@ -310,6 +312,26 @@ tACL_CONN* acl_get_connection_from_address(const RawAddress& bd_addr,
  return internal_.btm_bda_to_acl(bd_addr, transport);
}

void StackAclBtmAcl::btm_acl_consolidate(const RawAddress& identity_addr,
                                         const RawAddress& rpa) {
  tACL_CONN* p_acl = &btm_cb.acl_cb_.acl_db[0];
  for (uint8_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl++) {
    if (!p_acl->in_use) continue;

    if (p_acl->remote_addr == rpa) {
      LOG_INFO("consolidate %s -> %s", ADDRESS_TO_LOGGABLE_CSTR(rpa),
               ADDRESS_TO_LOGGABLE_CSTR(identity_addr));
      p_acl->remote_addr = identity_addr;
      return;
    }
  }
}

void btm_acl_consolidate(const RawAddress& identity_addr,
                         const RawAddress& rpa) {
  return internal_.btm_acl_consolidate(identity_addr, rpa);
}

/*******************************************************************************
 *
 * Function         btm_handle_to_acl_index
+14 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#include "types/raw_address.h"

extern tBTM_CB btm_cb;
extern void gatt_consolidate(const RawAddress& identity_addr,
                             const RawAddress& rpa);

namespace {

@@ -467,6 +469,12 @@ void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec) {
  }
}

BTM_CONSOLIDATION_CB* btm_consolidate_cb = nullptr;

void BTM_SetConsolidationCallback(BTM_CONSOLIDATION_CB* cb) {
  btm_consolidate_cb = cb;
}

/* combine security records of established LE connections after Classic pairing
 * succeeded. */
void btm_dev_consolidate_existing_connections(const RawAddress& bd_addr) {
@@ -513,11 +521,16 @@ void btm_dev_consolidate_existing_connections(const RawAddress& bd_addr) {
      /* remove the old LE record */
      wipe_secrets_and_remove(p_dev_rec);

      btm_acl_consolidate(bd_addr, ble_conn_addr);
      L2CA_Consolidate(bd_addr, ble_conn_addr);
      gatt_consolidate(bd_addr, ble_conn_addr);
      if (btm_consolidate_cb) btm_consolidate_cb(bd_addr, ble_conn_addr);

      /* To avoid race conditions between central/peripheral starting encryption
       * at same time, initiate it just from central. */
      if (L2CA_GetBleConnRole(ble_conn_addr) == HCI_ROLE_CENTRAL) {
        LOG_INFO("Will encrypt existing connection");
        BTM_SetEncryption(ble_conn_addr, BT_TRANSPORT_LE, nullptr, nullptr,
        BTM_SetEncryption(bd_addr, BT_TRANSPORT_LE, nullptr, nullptr,
                          BTM_BLE_SEC_ENCRYPT);
      }
    }
Loading