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

Commit 4453ed37 authored by Chris Manton's avatar Chris Manton
Browse files

Introduce bluetooth::legacy::hci::Interface

Migrate away from globals which allow any module
anywhere to bypass design intent which may
potentially introduce unintended code paths and
possible instability in module relationships.

Also towards testable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: I78a06be73906973e0bbdaba78cc7fbf27d9b27cb
parent ccff83be
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -83,6 +83,10 @@ struct StackAclBtmAcl {

namespace {
StackAclBtmAcl internal_;

const bluetooth::legacy::hci::Interface& GetLegacyHciInterface() {
  return bluetooth::legacy::hci::GetInterface();
}
}

typedef struct {
@@ -171,7 +175,8 @@ static void hci_btsnd_hcic_disconnect(tACL_CONN& p_acl, tHCI_STATUS reason) {
    return bluetooth::shim::ACL_Disconnect(p_acl.hci_handle,
                                           p_acl.is_transport_br_edr(), reason);
  } else {
    btsnd_hcic_disconnect(p_acl.hci_handle, reason);
    GetLegacyHciInterface().Disconnect(p_acl.hci_handle,
                                       static_cast<uint16_t>(reason));
  }
}

@@ -2822,7 +2827,7 @@ void acl_disconnect_after_role_switch(uint16_t conn_handle,
  tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(conn_handle);
  if (p_acl == nullptr) {
    LOG_ERROR("Sending disconnect for unknown acl PLEASE FIX");
    btsnd_hcic_disconnect(conn_handle, reason);
    GetLegacyHciInterface().Disconnect(conn_handle, reason);
    return;
  }

+2 −1
Original line number Diff line number Diff line
@@ -222,7 +222,8 @@ struct iso_impl {
    auto cis = GetCisIfKnown(cis_handle);
    LOG_ASSERT(cis) << "No such cis";
    LOG_ASSERT(cis->state_flags & kStateFlagIsConnected) << "Not connected";
    btsnd_hcic_disconnect(cis_handle, reason);
    bluetooth::legacy::hci::GetInterface().Disconnect(
        cis_handle, static_cast<tHCI_STATUS>(reason));
  }

  void on_setup_iso_data_path(uint8_t* stream, uint16_t len) {
+10 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ void btsnd_hcic_create_conn(const RawAddress& dest, uint16_t packet_types,
  btm_acl_paging(p, dest);
}

void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
static void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
  BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  uint8_t* pp = (uint8_t*)(p + 1);

@@ -1433,3 +1433,12 @@ void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,

  btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

bluetooth::legacy::hci::Interface interface_ = {
    .Disconnect = btsnd_hcic_disconnect,
};

const bluetooth::legacy::hci::Interface&
bluetooth::legacy::hci::GetInterface() {
  return interface_;
}
+10 −1
Original line number Diff line number Diff line
@@ -81,7 +81,16 @@ extern void btsnd_hcic_create_conn(const RawAddress& dest,
/* Create Connection */

/* Disconnect */
extern void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason);
namespace bluetooth {
namespace legacy {
namespace hci {
struct Interface {
  void (*Disconnect)(uint16_t handle, uint8_t reason);
};
const Interface& GetInterface();
}  // namespace hci
}  // namespace legacy
}  // namespace bluetooth

#define HCIC_PARAM_SIZE_DISCONNECT 3

+10 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ void btsnd_hcic_delete_stored_key(const RawAddress& bd_addr,
                                  bool delete_all_flag) {
  mock_function_count_map[__func__]++;
}
void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
static void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
  mock_function_count_map[__func__]++;
}
void btsnd_hcic_enable_test_mode(void) { mock_function_count_map[__func__]++; }
@@ -293,3 +293,12 @@ void btsnd_hcic_write_scan_enable(uint8_t flag) {
void btsnd_hcic_write_voice_settings(uint16_t flags) {
  mock_function_count_map[__func__]++;
}

bluetooth::legacy::hci::Interface interface_ = {
    .Disconnect = btsnd_hcic_disconnect,
};

const bluetooth::legacy::hci::Interface&
bluetooth::legacy::hci::GetInterface() {
  return interface_;
}
Loading