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

Commit 663489c8 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

acl_create_le_connection_with_id -> create_le_connection

create_le_connection is adding device directly to AclManager, and relying on it's "direct
connect" implementation.
direct_connect_add method is doing multiplexing of apps request, and
sending the request to AclManager, but it lacks some extra checks and lookups.

Currently these methods are exclusive, if you try to use both you will
get some bad behavior. These should be merged into one.

This patch is moving both methods into same location, so it's easier to
merge them into one under a flag.

Test: mma -j32
Bug: 372202918
Flag: EXEMPT, just renaming/moving code
Change-Id: I9166cca63dff9ada1ed4962ca805962c765f84d7
parent bc596602
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2067,6 +2067,7 @@ cc_test {
        ":TestMockMainShimEntry",
        ":TestMockStackAcl",
        ":TestMockStackBtm",
        ":TestMockStackGatt",
        ":TestMockStackHcic",
        ":TestMockStackSdp",
        ":TestMockStackSmp",
+0 −44
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ using bluetooth::legacy::hci::GetInterface;
void BTM_update_version_info(const RawAddress& bd_addr,
                             const remote_version_info& remote_version_info);

static void find_in_device_record(const RawAddress& bd_addr, tBLE_BD_ADDR* address_with_type);
void l2c_link_hci_conn_comp(tHCI_STATUS status, uint16_t handle, const RawAddress& p_bda);

void BTM_db_reset(void);
@@ -2462,31 +2461,6 @@ void acl_write_automatic_flush_timeout(const RawAddress& bd_addr, uint16_t flush
  btsnd_hcic_write_auto_flush_tout(p_acl->hci_handle, flush_timeout_in_ticks);
}

bool acl_create_le_connection_with_id(uint8_t /* id */, const RawAddress& bd_addr,
                                      tBLE_ADDR_TYPE addr_type) {
  tBLE_BD_ADDR address_with_type{
          .type = addr_type,
          .bda = bd_addr,
  };

  find_in_device_record(bd_addr, &address_with_type);

  log::debug("Creating le direct connection to:{} type:{} (initial type: {})", address_with_type,
             AddressTypeText(address_with_type.type), AddressTypeText(addr_type));

  if (address_with_type.type == BLE_ADDR_ANONYMOUS) {
    log::warn(
            "Creating le direct connection to:{}, address type 'anonymous' is "
            "invalid",
            address_with_type);
    return false;
  }

  bluetooth::shim::ACL_AcceptLeConnectionFrom(address_with_type,
                                              /* is_direct */ true);
  return true;
}

void acl_rcv_acl_data(BT_HDR* p_msg) {
  acl_header_t acl_header{
          .handle = HCI_INVALID_HANDLE,
@@ -2583,24 +2557,6 @@ tACL_CONN* btm_acl_for_bda(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
  return p_acl;
}

void find_in_device_record(const RawAddress& bd_addr, tBLE_BD_ADDR* address_with_type) {
  const tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == nullptr) {
    return;
  }

  if (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
    if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
      *address_with_type = {.type = p_dev_rec->ble.AddressType(), .bda = bd_addr};
      return;
    }
    *address_with_type = p_dev_rec->ble.identity_address_with_type;
    return;
  }
  *address_with_type = {.type = BLE_ADDR_PUBLIC, .bda = bd_addr};
  return;
}

/*******************************************************************************
 *
 * Function         btm_acl_flush
+7 −5
Original line number Diff line number Diff line
@@ -95,15 +95,18 @@ void SnoopLogger::SetL2capChannelOpen(uint16_t, uint16_t, uint16_t, uint16_t, bo
}  // namespace hal
}  // namespace bluetooth

namespace connection_manager {
bool create_le_connection(uint8_t /* id */, const RawAddress& /* bd_addr */,
                          tBLE_ADDR_TYPE /* addr_type */) {
  return true;
}
}  // namespace connection_manager

namespace {

class FakeBtStack {
public:
  FakeBtStack() {
    test::mock::stack_acl::acl_create_le_connection_with_id.body =
            [](uint8_t /* id */, const RawAddress& /* bd_addr */, tBLE_ADDR_TYPE /* addr_type */) {
              return true;
            };
    test::mock::stack_acl::acl_send_data_packet_br_edr.body = [](const RawAddress& /*bd_addr*/,
                                                                 BT_HDR* hdr) {
      ConsumeData((const uint8_t*)hdr, hdr->offset + hdr->len);
@@ -132,7 +135,6 @@ public:
  }

  ~FakeBtStack() {
    test::mock::stack_acl::acl_create_le_connection_with_id = {};
    test::mock::stack_acl::acl_send_data_packet_br_edr = {};
    test::mock::stack_acl::acl_send_data_packet_ble = {};
    bluetooth::hci::testing::mock_controller_ = nullptr;
+42 −0
Original line number Diff line number Diff line
@@ -440,6 +440,48 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) {
  direct_connect_remove(app_id, address, true);
}

static void find_in_device_record(const RawAddress& bd_addr, tBLE_BD_ADDR* address_with_type) {
  const tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == nullptr) {
    return;
  }

  if (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
    if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
      *address_with_type = {.type = p_dev_rec->ble.AddressType(), .bda = bd_addr};
      return;
    }
    *address_with_type = p_dev_rec->ble.identity_address_with_type;
    return;
  }
  *address_with_type = {.type = BLE_ADDR_PUBLIC, .bda = bd_addr};
  return;
}

bool create_le_connection(uint8_t /* id */, const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type) {
  tBLE_BD_ADDR address_with_type{
          .type = addr_type,
          .bda = bd_addr,
  };

  find_in_device_record(bd_addr, &address_with_type);

  log::debug("Creating le direct connection to:{} type:{} (initial type: {})", address_with_type,
             AddressTypeText(address_with_type.type), AddressTypeText(addr_type));

  if (address_with_type.type == BLE_ADDR_ANONYMOUS) {
    log::warn(
            "Creating le direct connection to:{}, address type 'anonymous' is "
            "invalid",
            address_with_type);
    return false;
  }

  bluetooth::shim::ACL_AcceptLeConnectionFrom(address_with_type,
                                              /* is_direct */ true);
  return true;
}

/** Add a device to the direct connection list. Returns true if device
 * added to the list, false otherwise */
bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <set>

#include "ble_address_with_type.h"
#include "types/raw_address.h"

/* connection_manager takes care of all the low-level details of LE connection
@@ -49,6 +50,14 @@ void on_connection_complete(const RawAddress& address);

std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& remote_bda);

/* create_le_connection is adding device directly to AclManager, and relying on it's "direct
 * connect" implementation.
 * direct_connect_add method is doing multiplexing of apps request, and
 * sending the request to AclManager, but it lacks some extra checks and lookups. Currently these
 * methods are exclusive, if you try to use both you will get some bad behavior. These should be
 * merged into one. */
bool create_le_connection(uint8_t /* id */, const RawAddress& bd_addr,
                          tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC);
bool direct_connect_add(tAPP_ID app_id, const RawAddress& address);
bool direct_connect_remove(tAPP_ID app_id, const RawAddress& address,
                           bool connection_timeout = false);
Loading